This is a different JavaScript API than what we are using for ddsa, and we want to provide a compatibility layer to ease the transition/refactoring of rules to the new ddsa API.
What is your solution?
Earlier, we partially addressed the object-style access of captures with with this commit in #393.
This PR furthers that effort by fully implementing the Stella API listed in the "Problem" section by using JavaScript Proxies.
Benefits of using Proxy:
Clear encapsulation -- the compatibility layer is distinct from the base implementation. Deprecating it completely after changing rule syntax is very straightforward.
Performance: by trapping property access, we can lazily compute and return only requested data. For example, if a rule never accesses capturesList, we avoid eagerly allocating/creating the capturesList object exactly like Stella does).
It's worth noting that this compatibility layer necessarily introduces a performance overhead. To avoid this, rules should be refactored use the native ddsa API.
What problem are you trying to solve?
The stella library attaches "captures", "capturesList", and "context" to the query match object. As a TypeScript interface, this would be
And thus, current rules have syntax like:
This is a different JavaScript API than what we are using for ddsa, and we want to provide a compatibility layer to ease the transition/refactoring of rules to the new ddsa API.
What is your solution?
Earlier, we partially addressed the object-style access of captures with with this commit in #393.
This PR furthers that effort by fully implementing the Stella API listed in the "Problem" section by using JavaScript Proxies.
Benefits of using
Proxy
:capturesList
, we avoid eagerly allocating/creating thecapturesList
object exactly like Stella does).It's worth noting that this compatibility layer necessarily introduces a performance overhead. To avoid this, rules should be refactored use the native ddsa API.
Alternatives considered
What the reviewer should know