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
| Responsibility | Page | Main operation |
|---|---|---|
| Declare a domain | Registries | registerDomain() |
| Choose a loading path | Manifests | Inline-only boundary |
| Load policy source | Rulesets | loadPolicy() |
| Provide request facts | Runtime EDB | addFacts() |
| Evaluate and reuse | Solving | solve(), freeResult() |
| Inspect answers | Querying | query(), enumerate(), explanations |
| Handle failure | Errors | DatalogError, buildLimits() |
| Put it together | Full program | Browser 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:
<script src="/wasm/maelys_datalog_dynamic.js"></script>
<script src="/wasm/maelys_playground.js"></script>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 surface | Current surface |
|---|---|
| Domain builder begin/add/commit/abort | One registerDomain declaration, including atoms |
loadRuleset | loadPolicy |
edbBegin | freeResult() if needed, then clearFacts() |
| Symbol helpers and arity-specific insertions | Typed, heterogeneous addFacts |
| ID insertion/interning and native ruleset pointer | Removed; use typed values |
| Arity-specific queries | query(predicate, terms) |
Raw ID enumeration and symbolText | Resolved enumerate |
explainFactText | explainTrue and explainFalse; named native errors |
| Separate mutable diagnostic accessors | Error-owned diagnostic snapshot |
| Implicit module lifetime | Explicit close() |
No compatibility aliases are retained. The exported functions of the final Wasm artifact and the consumer API/transport versions are checked before use.