TypeScript / JavaScript
Full program
Run the published Wasm wrapper from a browser page.This example puts the registration, inline policy, runtime facts, solve, query and cleanup in one place. The script URLs are illustrative deployment paths; serve the three files from one coherent published Wasm release.
Complete browser example
<!doctype html>
<html lang="en">
<head><meta charset="utf-8"><title>Document access</title></head>
<body>
<script src="/wasm/maelys_datalog_dynamic.js"></script>
<script src="/wasm/maelys_playground.js"></script>
<script type="module">
const pg = await MaelysPlayground.create(
MaelysDatalogDynamic, '/wasm/maelys_datalog_dynamic.wasm'
)
try {
pg.registerDomain({
name: 'access',
predicates: [
{ name: 'safe', arity: 1, flags: PredKind.EDB },
{ name: 'allow', arity: 1, flags: PredKind.IDB | PredKind.QUERY },
],
atoms: [],
})
pg.loadPolicy('access', 'access.main', 'allow(X) :- safe(X).')
pg.addFacts([{ predicate: 'safe', terms: ['alice'] }]).solve()
console.log(pg.query('allow', ['alice']))
console.log(pg.explainTrue('allow', ['alice']))
} finally {
pg.close()
}
</script>
</body>
</html>The source has no quoted constant, so the domain declares no policy atoms.
'alice' is supplied as a request fact. The finally block releases all
native handles even if loading, solving or querying throws.
The module script permits await while the two distributed scripts remain
classic scripts that install their browser globals.
For the meaning and constraints of each call, follow the topic pages from Registries through Querying.