TypeScript / JavaScript
Session inputs
Retained dynamic input, fixed storage options and exact base tokens.The examples use a prepared session, two document-access facts and the binding imports from the page reference context. Each example closes its live result before closing retained input.
Class: InputBase
export class InputBase {
constructor(incarnation: bigint | number, generation: bigint | number);
readonly incarnation: bigint;
readonly generation: bigint;
}- constructor
new InputBase(incarnation, generation)Construct an exact retained-input base token from its two unsigned 64-bit components.
- read from
sessionInputs.baseRead the current committed base of this retained input.
const retained = session.inputs()
try {
const base = retained.base
console.log('incarnation type:', typeof base.incarnation)
console.log('generation type:', typeof base.generation)
} finally { retained.close() }incarnation type: bigint generation type: bigint
Constructor: InputBase()
new InputBase(
incarnation: bigint | number,
generation: bigint | number
): InputBaseInputBaseReturns an immutable InputBase. An invalid unsigned 64-bit component throws RangeError.
const retained = session.inputs()
try {
const base = retained.base
const copy = new InputBase(base.incarnation, base.generation)
console.log('same incarnation:', copy.incarnation === base.incarnation)
console.log('same generation:', copy.generation === base.generation)
} finally { retained.close() }same incarnation: true same generation: true
Interface: InputOptions
const options: InputOptions = {
factCapacity: 2, additionCapacity: 2, removalCapacity: 2,
symbols: ['alice', 'roadmap.pdf'],
}
const retained = session.inputs(options)
try { console.log('base type:', retained.base instanceof InputBase) }
finally { retained.close() }base type: true
| Used by | Session.inputs |
|---|
Class: SessionInputs
No public constructor.
- returned by
Session.inputs()Attach retained dynamic input before this session's first successful solve. The binding allocates its storage; ordinary solve is unavailable while it remains attached.
- SessionInputs.apply()Apply retained-input changes and return their solved snapshot.
- SessionInputs.close()Release retained input after closing its live result.
- SessionInputs.replace()Replace all retained input and return its solved snapshot.
- using retainedLeave the scope to close retained input after its live result has been closed.
const retained = session.inputs({ factCapacity: 2, symbols: ['alice', 'roadmap.pdf'] })
try {
const result = retained.replace(retained.base, facts)
try { console.log('allowed:', result.containsFact('allow', ['alice', 'roadmap.pdf'])) } finally { result.close() }
} finally { retained.close() }allowed: true
Methods
SessionInputs.apply
SessionInputs.apply(
base: InputBase,
changes?: { added?: Iterable<Fact>; removed?: Iterable<Fact> }
): SolveResultSolveResultReturns a live SolveResult that must be closed before another retained-input operation. Every success advances the base, including a set no-op. Failure preserves the committed facts and base.
const retained = session.inputs({ factCapacity: 2, symbols: ['alice', 'roadmap.pdf'] })
try {
const result = retained.apply(retained.base, { added: facts })
try { console.log('allowed:', result.containsFact('allow', ['alice', 'roadmap.pdf'])) } finally { result.close() }
} finally { retained.close() }allowed: true
SessionInputs.close
SessionInputs.close(): voidvoidReturns void. Closing is idempotent; a live result prevents closing this attachment.
const retained = session.inputs()
retained.close()
retained.close()
console.log('retained input: closed')retained input: closed
SessionInputs.replace
SessionInputs.replace(
base: InputBase,
facts: Iterable<Fact>
): SolveResultSolveResultReturns a live SolveResult that must be closed before another retained-input operation. Failure preserves the committed facts and base; invalid inputs are rejected by the binding or reported as MaelysDatalogError.
const retained = session.inputs({ factCapacity: 2, symbols: ['alice', 'roadmap.pdf'] })
try {
const result = retained.replace(retained.base, facts)
try { console.log('allowed:', result.containsFact('allow', ['alice', 'roadmap.pdf'])) } finally { result.close() }
} finally { retained.close() }allowed: true
Protocols
using retained
Uses the same close operation as explicit cleanup.
{
using retained = session.inputs({ factCapacity: 2, symbols: ['alice', 'roadmap.pdf'] })
const result = retained.replace(retained.base, facts)
try { console.log('allowed:', result.containsFact('allow', ['alice', 'roadmap.pdf'])) }
finally { result.close() }
}allowed: true