// Shared imports, document-access declarations and resource cleanup. // This file is concatenated before the selected page extension. import { createHash } from 'node:crypto' import { Engine, Predicate, SessionCapacities, Capability, ExplanationKind, MaelysDatalogError, Status, PRED_EDB, PRED_IDB, PRED_QUERY, PRED_POLICY_FACT, type Fact, type CapacityOptions, type SessionOptions, type EngineOptions, type ManifestOptions, type ManifestInput, type WasmModule } from '@maelys-dev/datalog/wasm' const documentDomain = 'documents' const documentPolicy = 'allow(User, Doc) :- owns(User, Doc), not(blocked(User)).' // The manifest/ruleset examples use the one-argument policy from their guides. const userPolicy = 'allow(User) :- user(User).' function registerDocuments(engine: Engine) { engine.registerDomain(documentDomain, [ Predicate.edb('user', 1), Predicate.edb('owns', 2), Predicate.edb('blocked', 1), Predicate.idbQuery('allow', 2), ], []) } function registerUsers(engine: Engine) { engine.registerDomain(documentDomain, [Predicate.edb('user', 1), Predicate.idbQuery('allow', 1)], []) } const engines: Engine[] = [] function keepEngine(engine: Engine): Engine { engines.push(engine) return engine } function closeEngines() { let failure: unknown for (const engine of engines.reverse()) { try { engine.close() } catch (error) { failure ??= error } } if (failure) throw failure }