TypeScript / JavaScript
EDB and input facts guide
Examples and practical guidance for the JavaScript and TypeScript Edb API.The Edb reference contains the complete class and method cards.
Usage and examples
Give each request an explicit input buffer
With an open rules returned by the Ruleset API, collect the seven request facts for document access:
const input = rules.edb({ factCapacity: 7, textCapacity: 256 })
input.addFacts([
{ predicate: 'user', terms: ['alice'] },
{ predicate: 'user', terms: ['bob'] },
{ predicate: 'user', terms: ['mallory'] },
{ predicate: 'owns', terms: ['alice', 'roadmap.pdf'] },
{ predicate: 'delegated', terms: ['bob', 'roadmap.pdf'] },
{ predicate: 'owns', terms: ['mallory', 'roadmap.pdf'] },
{ predicate: 'blocked', terms: ['mallory'] },
])
console.log(input.count, input.usage.textBytes, input.usage.textCapacity)addFact(predicate, terms) adds one fact. addFacts(iterable) stages an entire
batch before appending it: invalid values, exhausted input capacity or an
iterator failure preserve the input already stored. It does not split a batch
into partially committed chunks. Use finite iterables and do not reset, close
or solve the input from inside an iterator used to supply that input.
The EDB's fact/text capacities bound collection. Session capacities separately
bound evaluation; successful collection is not a guarantee that a solve fits.
Read the active profile through engine.limits and actual occupancy through
input.usage, rather than treating the example's sizes as general defaults.
Clear, reset and result snapshots
| State or operation | Meaning |
|---|---|
| Newly created EDB | Empty and mutable |
input.clear() | Clears mutable input while keeping its storage |
| Successful solve | Freezes append and clear on this EDB |
input.reset() | Clears and unfreezes it for a new request |
input.close() | Releases its storage; later use fails |
Closing the result releases the session's result lease; it does not unfreeze
the EDB. Use reset() before replacing a successful request. Reset does not
rewrite a result that is still alive: that result retains its solved snapshot.
Strings remain symbols, booleans remain booleans, and integer results are
bigint. A number input must be a safe integer; signed int64 bounds still
apply. UTF-8 conversion and JavaScript objects allocate even though the native
input storage is bounded and reusable.