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.

Class: Edb

TypeScript · classSince v0.15.0
Edb
Reusable bounded runtime input belonging to one ruleset.
Creation and access

No public constructor.

  • returned by
    Ruleset.edb()

    Reserve a reusable bounded input buffer owned by this ruleset.

Attributes
countnumberreadonly field
Number of raw facts stored in this EDB.
usageReadonly<EdbUsage>readonly field
Current input fact and text occupancy.
Methods
  • 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.
Protocols
  • using edbLeave the scope to close this input buffer; its Ruleset remains open.

Methods

Edb.addFact

TypeScript · methodSince v0.15.0
Edb.addFact
Edb.addFact(
predicate: string,
terms: readonly InputValue[]
): void
Append one typed fact to mutable input.
Arguments
predicatestring
Name of the predicate to append.
termsreadonly InputValue[]
Ordered typed terms matching its arity.
Return value
void

Returns nothing on success. Invalid JavaScript inputs throw TypeError or RangeError; native failures carry MaelysDatalogError and a diagnostic.

Example
const input = ruleset.edb()
try {
  input.addFact('user', ['alice'])
  input.addFact('owns', ['alice', 'roadmap.pdf'])
  console.log('facts:', input.count)
} finally { input.close() }

Edb.addFacts

TypeScript · methodSince v0.15.0
Edb.addFacts
Edb.addFacts(
facts: Iterable<Fact>
): void
Stage a whole batch and append it atomically; rejection preserves existing input.
Arguments
factsIterable<Fact>
Finite iterable of facts staged as one atomic batch.
Return value
void

Returns nothing on success. Invalid JavaScript inputs throw TypeError or RangeError; native failures carry MaelysDatalogError and a diagnostic.

Example
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() }

Edb.clear

TypeScript · methodSince v0.15.0
Edb.clear
Edb.clear(): void
Empty mutable input while retaining its storage.
Return value
void

Returns nothing. A frozen input rejects clear with INVALID_STATE; use reset for a new request.

Example
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

TypeScript · methodSince v0.15.0
Edb.close
Edb.close(): void
Release this resource and its owned descendants. Closing is idempotent.
Return value
void

Returns nothing. Repeated closing succeeds; operational calls after closing fail with INVALID_STATE.

Example
const input = ruleset.edb()
try { input.addFact('user', ['alice']) }
finally { input.close() }
console.log('input: closed')

Edb.reset

TypeScript · methodSince v0.15.0
Edb.reset
Edb.reset(): void
Empty and unfreeze input for a new request; existing results retain their snapshots.
Return value
void

Returns nothing on success. Invalid JavaScript inputs throw TypeError or RangeError; native failures carry MaelysDatalogError and a diagnostic.

Example
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

TypeScript · protocolSince v0.15.0
using edb
Leave the scope to close this input buffer; its Ruleset remains open.
Behavior

Exiting the using scope disposes the resource, including on exceptional exit. Cleanup delegates to close() and is idempotent.

Example
{
  using edb = ruleset.edb()
  edb.addFact('user', ['alice'])
  using result = ruleset.solve(edb)
  console.log('derived facts:', result.derivedFactCount())
}
Explicit form

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]()
}

Interfaces

Fact · EdbOptions · EdbUsage.

Fact

TypeScript · interfaceSince v0.10.0
Fact
One predicate and its ordered input terms, staged atomically with its batch.
Fields
predicatestringreadonly field
Predicate name for this input fact.
termsreadonly InputValue[]readonly field
Ordered input values; integer numbers must be safe integers.
Example
const userFact: Fact = { predicate: 'user', terms: ['alice'] }
console.log('predicate:', userFact.predicate)
console.log('terms:', userFact.terms)
predicate: user
terms: [ 'alice' ]

EdbOptions

TypeScript · interfaceSince v0.15.0
EdbOptions
Fixed input fact and text bounds, independent of the prepared session quotas.
Fields
factCapacity?numberfield
Maximum raw facts stored in the EDB, including repeated facts.
textCapacity?numberfield
Reserved bytes for interned input text including terminators.

EdbUsage

TypeScript · interfaceSince v0.15.0
EdbUsage
Current input occupancy and its reserved text capacity.
Creation and access
  • read from
    edb.usage

    Read the current fact and text occupancy and the fixed capacities of this input buffer.

Fields
factsnumberreadonly field
Number of raw facts currently stored.
textBytesnumberreadonly field
Used text bytes, or the explicit session text quota in capacity options.
textCapacitynumberreadonly field
Reserved bytes for interned input text including terminators.

InputValue · Value.

InputValue

TypeScript · typeSince v0.10.0
InputValue
Declaration
export type InputValue = string | bigint | number | boolean;
A runtime input symbol, exact signed 64-bit integer, or boolean. Unsafe numeric inputs are rejected.

Value

TypeScript · typeSince v0.10.0
Value
Declaration
export type Value = string | bigint | boolean;
A resolved output value; integers always use bigint.
Creation and access

Usage guides

The examples are now in the EDB and input facts guide.