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

TypeScript · classSince v0.17.0
InputBase
Declaration
export class InputBase {
    constructor(incarnation: bigint | number, generation: bigint | number);
    readonly incarnation: bigint;
    readonly generation: bigint;
}
An exact unsigned 64-bit incarnation and generation token for retained input.
Creation and access
Attributes
incarnationbigintreadonly field
Identifies this retained-input attachment.
generationbigintreadonly field
Identifies its current committed input generation.
Example
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()

TypeScript · constructorSince v0.17.0
InputBase.constructor
new InputBase(
incarnation: bigint | number,
generation: bigint | number
): InputBase
Construct an exact retained-input base token from its two unsigned 64-bit components.
Arguments
incarnationbigint | number
Unsigned 64-bit incarnation component.
generationbigint | number
Unsigned 64-bit generation component.
Return value
InputBase

Returns an immutable InputBase. An invalid unsigned 64-bit component throws RangeError.

Example
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

TypeScript · interfaceSince v0.17.0
InputOptions
Optional fixed capacities and additional vocabulary for retained input storage, independent of session quotas.
Fields
factCapacity?numberfield
Maximum retained input facts; defaults to the session input-fact quota.
additionCapacity?numberfield
Maximum raw additions per apply call; defaults to factCapacity.
removalCapacity?numberfield
Maximum raw removals per apply call; defaults to factCapacity.
symbols?Iterable<string>field
Additional strings admitted to the immutable program vocabulary.
Example
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() }

Class: SessionInputs

TypeScript · classSince v0.17.0
SessionInputs
Retained dynamic input attached to a prepared session; compiled policy facts remain separate.
Creation and access

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.

Attributes
baseInputBasereadonly field
Current committed retained-input base token.
Methods
Protocols
  • using retainedLeave the scope to close retained input after its live result has been closed.
Example
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() }

Methods

SessionInputs.apply

TypeScript · methodSince v0.17.0
SessionInputs.apply
SessionInputs.apply(
base: InputBase,
changes?: { added?: Iterable<Fact>; removed?: Iterable<Fact> }
): SolveResult
Apply retained-input changes and return their solved snapshot.
Arguments
Current base token read from this retained input.
changes?{ added?: Iterable<Fact>; removed?: Iterable<Fact> }
Optional added and removed facts; each raw batch has its own configured bound. Additions win; absent removals are no-ops after validation.
Return value
SolveResult

Returns 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.

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

SessionInputs.close

TypeScript · methodSince v0.17.0
SessionInputs.close
SessionInputs.close(): void
Release retained input after closing its live result.
Return value
void

Returns void. Closing is idempotent; a live result prevents closing this attachment.

Example
const retained = session.inputs()
retained.close()
retained.close()
console.log('retained input: closed')

SessionInputs.replace

TypeScript · methodSince v0.17.0
SessionInputs.replace
SessionInputs.replace(
base: InputBase,
facts: Iterable<Fact>
): SolveResult
Replace all retained input and return its solved snapshot.
Arguments
Current base token read from this retained input.
factsIterable<Fact>
Complete replacement input facts.
Return value
SolveResult

Returns 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.

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

Protocols

using retained

TypeScript · protocolSince v0.17.0
using retained
Leave the scope to close retained input after its live result has been closed.
Behavior

Uses the same close operation as explicit cleanup.

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

Usage guides