TypeScript / JavaScript
Querying
Check membership, enumerate IDB facts and request explanations.Query only after a successful solve(). Membership, enumeration and
explanations answer different questions; a negative membership answer is not
an API error. See Querying for their meaning.
Ground queries
query(predicate, terms) returns a boolean using the typed terms described
in Runtime EDB. It can find query-authorized EDB,
policy and derived facts. An unknown symbol returns false without interning.
Invalid predicates, permissions or arity remain native errors, never a
fabricated false.
const allowed: boolean = pg.query('allow', ['alice'])Enumerating derived IDB facts
enumerate(predicate, arity) returns resolved and copied rows:
const rows: (string | bigint | boolean)[][] = pg.enumerate('event_result', 4)It enumerates only derived IDB facts of the authorized predicate. No native
symbol ID, pointer or borrowed view escapes. Display integers with String();
plain JSON.stringify cannot serialize bigint.
Why-true explanations
explainTrue(predicate, terms) returns the canonical engine text. It returns
status=not-derived if there is no derived witness, including when a query
found an EDB or policy fact. A truncated document remains a successfully
returned, explicitly bounded document. Unknown symbols raise NOT_FOUND.
Why-false explanations
explainFalse(predicate, terms) explains absence when the terms are known.
A present fact gives status=not-applicable. An unknown symbol gives
NOT_FOUND, even though the corresponding query returns false.
status=truncated means the search was incomplete; it is not a complete proof
of non-derivability. Both explanations are requested explicitly; the playground
computes them only when their disclosure is opened.
const present = pg.query('allow', ['alice'])
const explanation = present
? pg.explainTrue('allow', ['alice'])
: pg.explainFalse('allow', ['alice'])The explanation is text; inspect its document and status fields rather
than treating its mere presence as authorization.