You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Export filter expression evaluation from structured-context/api #132
Filter expressions (WHERE … / SELECT … WHERE …, JSONata over nodes augmented with ancestors[] / descendants[]) are only reachable via the CLI today. filterNodes and the per-node evaluation it builds on (src/filter/) are not exported from structured-context/api.
Use case
Library consumers want to reuse the same predicate language rather than reinvent it, e.g.:
selecting a subset of a space graph by a named filter view or inline expression (filterNodes(expression, graph)), and
evaluating a WHERE predicate against individual nodes without filtering the graph, e.g. to flag or style matching nodes in a UI.
Proposal
Export filterNodes from structured-context/api.
Export a per-node predicate evaluator, e.g. compileNodePredicate(expression, graph) => (node) => Promise<boolean>, reusing the existing augmentation and expression cache.
Export a helper to resolve a filter view name from space config to its expression (or document how to do it).
Findings from trying this for a browser consumer (a UI that receives space data as JSON and wants to evaluate filters client-side):
The filter code itself is browser-safe.src/filter/ imports only jsonata plus type-only and pure modules. Bundled with esbuild (--platform=browser), filterNodes over buildSpaceGraph(nodes, hierarchy) runs in Chrome and matches sctx dump --filter on a real space (three expressions, including an ancestors[] predicate and a SELECT descendants … WHERE). Cost: ~28 KB gzipped, almost all jsonata.
bun build --target=browser breaks it:jsonata.js is a browserify bundle that probes for require, and bun leaves __require undefined in the output. esbuild handles it.
Exporting from structured-context/api won't serve browser consumers. Importing anything from /api, even a constant, fails a browser bundle on node:fs, node:path, node:os and node:module. Bundlers resolve these before they can drop unused code.
So the proposal here probably needs a runtime-agnostic entry point rather than /api alone. That ties into how the public API divides into areas (runtime-agnostic, plugin development, filesystem and config loading), the same open question #138 defers. Worth deciding the two together.
Activity
mindsocket commentedon Oct 6, 2026
Findings from trying this for a browser consumer (a UI that receives space data as JSON and wants to evaluate filters client-side):
src/filter/imports onlyjsonataplus type-only and pure modules. Bundled with esbuild (--platform=browser),filterNodesoverbuildSpaceGraph(nodes, hierarchy)runs in Chrome and matchessctx dump --filteron a real space (three expressions, including anancestors[]predicate and aSELECT descendants … WHERE). Cost: ~28 KB gzipped, almost alljsonata.bun build --target=browserbreaks it:jsonata.jsis a browserify bundle that probes forrequire, and bun leaves__requireundefined in the output. esbuild handles it.structured-context/apiwon't serve browser consumers. Importing anything from/api, even a constant, fails a browser bundle onnode:fs,node:path,node:osandnode:module. Bundlers resolve these before they can drop unused code.So the proposal here probably needs a runtime-agnostic entry point rather than
/apialone. That ties into how the public API divides into areas (runtime-agnostic, plugin development, filesystem and config loading), the same open question #138 defers. Worth deciding the two together.