TypeScript / JavaScript

TypeScript API

Use the typed JavaScript wrapper over the published WebAssembly engine.

The JavaScript binding consumes the installed public C SDK. It exposes typed facts and queries, canonical explanations and structured diagnostics through MaelysPlayground. Its TypeScript declaration ships with the engine artifact; the site does not generate a competing declaration.

This is the consumer API introduced with 0.10.0. The wrapper, Emscripten glue, Wasm binary and declaration must be promoted together from the same release. The .d.ts describes the calls for TypeScript; the runtime is JavaScript and works from JavaScript without a TypeScript compiler.

Reference by topic

ResponsibilityPageMain operation
Declare a domainRegistriesregisterDomain()
Choose a loading pathManifestsInline-only boundary
Load policy sourceRulesetsloadPolicy()
Provide request factsRuntime EDBaddFacts()
Evaluate and reuseSolvingsolve(), freeResult()
Inspect answersQueryingquery(), enumerate(), explanations
Handle failureErrorsDatalogError, buildLimits()
Put it togetherFull programBrowser example

Factory and module ownership

The distributed target is maelys_datalog_dynamic.js, with factory MaelysDatalogDynamic. The historical core/examples JavaScript targets are removed. Load the factory and wrapper as classic scripts, then create a module:

CODE
<script src="/wasm/maelys_datalog_dynamic.js"></script>
<script src="/wasm/maelys_playground.js"></script>
CODE
const pg = await MaelysPlayground.create(
  MaelysDatalogDynamic, '/wasm/maelys_datalog_dynamic.wasm'
)

Each factory call creates a separate module with its own registry and linear memory. Sharing one module between two wrappers is rejected. Always call close(); garbage collection is not a native-handle release contract. The full program shows the complete try/finally around this call.

Allocation contract

Opening the adapter reserves one reusable conversion scratch and one public input buffer. The adapter makes no per-fact native allocation. Policy/session creation and direct-text explanations may allocate. JavaScript objects, UTF-8 conversion and transport buffers also allocate; this binding is not zero-malloc.

Migration

Previous surfaceCurrent surface
Domain builder begin/add/commit/abortOne registerDomain declaration, including atoms
loadRulesetloadPolicy
edbBeginfreeResult() if needed, then clearFacts()
Symbol helpers and arity-specific insertionsTyped, heterogeneous addFacts
ID insertion/interning and native ruleset pointerRemoved; use typed values
Arity-specific queriesquery(predicate, terms)
Raw ID enumeration and symbolTextResolved enumerate
explainFactTextexplainTrue and explainFalse; named native errors
Separate mutable diagnostic accessorsError-owned diagnostic snapshot
Implicit module lifetimeExplicit close()

No compatibility aliases are retained. The exported functions of the final Wasm artifact and the consumer API/transport versions are checked before use.