TypeScript / JavaScript
Registries
Declare predicates and policy-source atoms for a Wasm module.The domain declaration fixes the names, arities and roles that a policy may use. This is the JavaScript counterpart of the registry concept, not a separate place to add facts for each request.
Domain definition
registerDomain({name, predicates, atoms}) submits a complete declaration.
The engine copies predicate names and policy atoms at registration. Repeated
compatible registrations follow the C registry contract; close() does not
promise to unregister a domain.
The shipped TypeScript declaration describes the input as Domain:
interface Domain {
name: string
predicates: { name: string; arity: number; flags: number }[]
atoms?: string[]
}Predicate kind flags
PredKind.EDB, IDB, QUERY, and POLICY_FACT describe the same origins and
query permission as the public C API. Combine an origin with QUERY when it
may be queried. A rule head must be IDB. Source facts require POLICY_FACT.
The explicit atoms list authorizes quoted constants written in policy source.
A string supplied only through EDB input needs no atom declaration. The wrapper
never infers atoms or enables permissive loading silently.
Example — document access
pg.registerDomain({
name: 'access',
predicates: [
{ name: 'safe', arity: 1, flags: PredKind.EDB },
{ name: 'allow', arity: 1, flags: PredKind.IDB | PredKind.QUERY },
],
atoms: [],
})safe/1 receives request facts, while the policy derives allow/1. The
policy allow(X) :- safe(X). uses no quoted source constant, so its atoms
list is empty. A value such as 'alice' passed later to addFacts() remains
runtime data; it does not have to appear here.