42 ms·
How about representing the logic as a JavaScript expression: (credentialData.rapidSarsCov2PCRTest.testResult==='negative') || credentialData.covid19V
by goto11 5y ago
How about representing the logic as a JavaScript expression:
(credentialData.rapidSarsCov2PCRTest.testResult==='negative')
|| credentialData.covid19Vaccination.hasVaccination)
? 'valid' : 'invalid'
Seem easier to read and maintain to me.
- sebmellen 5y agoI'd love to do this, the only problem there is we're sharing this data between systems which use different runtimes. A client who runs a Python environment might not easily be able to make use of that logic. With JsonLogic, that would theoretically be possible.
- goto11 5y agoYou can easily write a parser for this in Python. As long as you only support expressions it should be pretty straightforward.
- sebmellen 5y agoI see your angle. I'll consider this. Thanks for the ideas!
- adamkl 5y agoI posted this in another thread, but it seems relevant to what you are looking for: https://stopa.io/post/265 https://stopa.io/post/265 It walks through the process of building a Lisp in JSON and the associated parser in JavaScript. It could be a good starting point to build out a cross-platform approach to sending logic over the wire.
- sebmellen 5y agoNice, looks quite neat. I'll dive into it a bit deeper!
- chousuke 5y agoI can't help but think that at the end of this road is yet another Lisp waiting to be discovered.
- goto11 5y agoWell JsonLogic is basically Lisp expressions in Json syntax which is kind of the worst of both worlds IMHO. It seems weird to me to pass a syntax tree over the network rather than just the syntax. But if the expression is not supposed to be viewed or edited as code at all, but only in some kind of GUI expression builder, then it might make sense. Lisp is at least human-writable, but if it is supposed to be written by humans why not just use straightforward expression syntax like "a + b".
- goto11 5y agoBtw google have something almost exactly like this: https://github.com/google/cel-spec https://github.com/google/cel-spec