TypeScript / JavaScript
Edb
Edb class, methods and runtime fact types.The examples use the loaded documents ruleset from the full program. Each input is created before an EDB method is called.
| Used by | Ruleset.solve · Session.solve |
|---|
Class: Edb
No public constructor.
- returned by
Ruleset.edb()Reserve a reusable bounded input buffer owned by this ruleset.
- Edb.addFact()Append one typed fact to mutable input.
- Edb.addFacts()Stage a whole batch and append it atomically; rejection preserves existing input.
- Edb.clear()Empty mutable input while retaining its storage.
- Edb.close()Release this resource and its owned descendants. Closing is idempotent.
- Edb.reset()Empty and unfreeze input for a new request; existing results retain their snapshots.
- using edbLeave the scope to close this input buffer; its Ruleset remains open.
Methods
Edb.addFact
Edb.addFact(
predicate: string,
terms: readonly InputValue[]
): voidvoidReturns nothing on success. Invalid JavaScript inputs throw TypeError or RangeError; native failures carry MaelysDatalogError and a diagnostic.
const input = ruleset.edb()
try {
input.addFact('user', ['alice'])
input.addFact('owns', ['alice', 'roadmap.pdf'])
console.log('facts:', input.count)
} finally { input.close() }facts: 2
Edb.addFacts
Edb.addFacts(
facts: Iterable<Fact>
): voidvoidReturns nothing on success. Invalid JavaScript inputs throw TypeError or RangeError; native failures carry MaelysDatalogError and a diagnostic.
const input = ruleset.edb({ factCapacity: 7 })
try {
input.addFacts([
{ predicate: 'user', terms: ['alice'] },
{ predicate: 'owns', terms: ['alice', 'roadmap.pdf'] },
])
console.log('facts:', input.usage.facts)
} finally { input.close() }facts: 2
Edb.clear
Edb.clear(): voidvoidReturns nothing. A frozen input rejects clear with INVALID_STATE; use reset for a new request.
const input = ruleset.edb()
try {
input.addFact('user', ['alice'])
input.clear() // Mutable input becomes empty; storage is retained.
console.log('facts after clear:', input.count)
input.addFact('user', ['bob'])
console.log('facts after add:', input.count)
} finally { input.close() }facts after clear: 0 facts after add: 1
Edb.close
Edb.close(): voidvoidReturns nothing. Repeated closing succeeds; operational calls after closing fail with INVALID_STATE.
const input = ruleset.edb()
try { input.addFact('user', ['alice']) }
finally { input.close() }
console.log('input: closed')input: closed
Edb.reset
Edb.reset(): voidvoidReturns nothing on success. Invalid JavaScript inputs throw TypeError or RangeError; native failures carry MaelysDatalogError and a diagnostic.
const input = ruleset.edb()
try {
input.addFact('user', ['alice'])
const result = ruleset.solve(input)
result.close()
input.reset() // Clears and unfreezes the input for another request.
console.log('facts after clear:', input.count)
input.addFact('user', ['bob'])
console.log('facts after add:', input.count)
} finally { input.close() }facts after clear: 0 facts after add: 1
Protocols
using edb
Exiting the using scope disposes the resource, including on exceptional exit. Cleanup delegates to close() and is idempotent.
{
using edb = ruleset.edb()
edb.addFact('user', ['alice'])
using result = ruleset.solve(edb)
console.log('derived facts:', result.derivedFactCount())
}derived facts: 0
Perform the same operations with explicit cleanup in a finally block.
const edb = ruleset.edb()
try {
edb.addFact('user', ['alice'])
const result = ruleset.solve(edb)
try {
console.log('derived facts:', result.derivedFactCount())
} finally {
result.close()
}
} finally {
edb[Symbol.dispose]()
}derived facts: 0
Interfaces
Fact · EdbOptions · EdbUsage.
Fact
const userFact: Fact = { predicate: 'user', terms: ['alice'] }
console.log('predicate:', userFact.predicate)
console.log('terms:', userFact.terms)predicate: user terms: [ 'alice' ]
| Used by | SessionInputs.apply · SessionInputs.replace |
|---|
EdbOptions
| Used by | Ruleset.edb |
|---|
EdbUsage
- read from
edb.usageRead the current fact and text occupancy and the fixed capacities of this input buffer.
Type aliases
InputValue · Value.
InputValue
export type InputValue = string | bigint | number | boolean;Value
export type Value = string | bigint | boolean;- returned by
ResultTerm.resolve()Copy the typed value from this result-bound term.
- returned by
SolveResult.enumeratePredicateFacts()Copy resolved values for one queryable predicate and arity.
- returned by
SolveResult.resolveTerm()Resolve a term owned by this same live result into a copied value.
Usage guides
The examples are now in the EDB and input facts guide.