The objective is to create a system that can establish certain constraints, similar to the way Notion handles filter properties.
https://i.sstatic.net/plctW.png
System A sets up the constraints and System C evaluates them, both using Typescript. However, the constraints are stored in a Rust environment (System B). The system should undergo minimal modifications. The data flow is as follows:
System A (TS) -> System B (Rust) -> System C (TS)
Both System A and C are aware of the data structures, but only System C knows the actual values being assessed. Therefore, System A must define these constraints abstractly.
Current Solution:
- Store the constraints as JS expressions in the form of strings. For example, System A produces the following constraint:
const expression = "'${NAME}' === 'Zurich'"
System B can easily store the constraint in its current string form.
System C takes the input, replaces placeholders like ${NAME}, and uses the
eval()
function to evaluate the expressions.
Questions:
- What is the technical term for this problem? Is it similar to a query language?
- Do you foresee any issues with the approach of storing strings and using
eval()
? - Any suggestions for improving this process?
- Are there any libraries available to assist with more complex constraints?
Background: Understanding the real-world application:
- System A functions as the voting authority, setting up ballots and voter eligibility.
- This information is stored in System B, a public ledger.
- System C generates access tokens for eligible voters, requiring proof such as a passport signed by a valid authority. These constraints are extracted directly from the ballot configuration on the blockchain.