@factoidal/core 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/CHANGELOG.md +121 -0
  2. package/LICENSE +201 -0
  3. package/README.md +514 -0
  4. package/browser-wasm.js +872 -0
  5. package/browser.d.ts +514 -0
  6. package/browser.js +2276 -0
  7. package/factoidal-npm-entry.js +32609 -0
  8. package/factoidal-npm-entry.wasm.assets/code-7ac046580f1bbdda8dc6.wasm +0 -0
  9. package/factoidal-npm-entry.wasm.js +455 -0
  10. package/factoidal.js +27560 -0
  11. package/factoidal.wasm.assets/code-bbe6099bfb5b10c4c3ab.wasm +0 -0
  12. package/factoidal.wasm.js +457 -0
  13. package/fn.d.ts +519 -0
  14. package/fn.js +916 -0
  15. package/hacl-init.js +92 -0
  16. package/hacl-wasm/FStar.wasm +0 -0
  17. package/hacl-wasm/Hacl_Bignum.wasm +0 -0
  18. package/hacl-wasm/Hacl_Bignum25519_51.wasm +0 -0
  19. package/hacl-wasm/Hacl_Bignum_Base.wasm +0 -0
  20. package/hacl-wasm/Hacl_Curve25519_51.wasm +0 -0
  21. package/hacl-wasm/Hacl_Ed25519.wasm +0 -0
  22. package/hacl-wasm/Hacl_Ed25519_PrecompTable.wasm +0 -0
  23. package/hacl-wasm/Hacl_Hash_Base.wasm +0 -0
  24. package/hacl-wasm/Hacl_Hash_SHA2.wasm +0 -0
  25. package/hacl-wasm/Hacl_IntTypes_Intrinsics.wasm +0 -0
  26. package/hacl-wasm/LowStar_Endianness.wasm +0 -0
  27. package/hacl-wasm/WasmSupport.wasm +0 -0
  28. package/hacl-wasm/api.js +775 -0
  29. package/hacl-wasm/api.json +3787 -0
  30. package/hacl-wasm/layouts.json +1 -0
  31. package/hacl-wasm/loader.js +568 -0
  32. package/hacl-wasm/shell.js +12 -0
  33. package/index.d.ts +1068 -0
  34. package/index.js +237 -0
  35. package/index.mjs +85 -0
  36. package/lib/api.js +2140 -0
  37. package/lib/engine-js.js +165 -0
  38. package/lib/engine-wasm.js +300 -0
  39. package/package.json +101 -0
  40. package/rdfjs.js +540 -0
  41. package/version.json +101 -0
  42. package/wasm.d.ts +130 -0
  43. package/wasm.js +158 -0
package/wasm.d.ts ADDED
@@ -0,0 +1,130 @@
1
+ // TypeScript declarations for 'factoidal/wasm' — same API as the main
2
+ // entry, backed by the wasm_of_ocaml engine bundle (Node >= 22).
3
+
4
+ import {
5
+ DataFactory,
6
+ DataInput,
7
+ DataFormat,
8
+ Dataset,
9
+ ParseOptions,
10
+ QueryOptions,
11
+ SerializeOptions,
12
+ Bindings,
13
+ } from './index';
14
+
15
+ export {
16
+ Dataset,
17
+ DataFactory,
18
+ DataInput,
19
+ DataFormat,
20
+ ParseOptions,
21
+ QueryOptions,
22
+ SerializeOptions,
23
+ Bindings,
24
+ };
25
+
26
+ export {
27
+ ExtensionTerm,
28
+ registerExtensionFunction,
29
+ unregisterExtensionFunction,
30
+ clearExtensionFunctions,
31
+ } from './index';
32
+
33
+ export function parse(text: string, options?: ParseOptions): Promise<Dataset>;
34
+ export function query(
35
+ data: DataInput,
36
+ sparql: string,
37
+ options?: QueryOptions
38
+ ): Promise<Bindings[] | boolean | Dataset>;
39
+ export function update(
40
+ data: DataInput,
41
+ updateText: string,
42
+ options?: { format?: DataFormat }
43
+ ): Promise<Dataset>;
44
+ export function serialize(
45
+ data: DataInput,
46
+ options?: SerializeOptions
47
+ ): Promise<string>;
48
+ export function canonicalize(
49
+ data: DataInput,
50
+ options?: { format?: DataFormat }
51
+ ): Promise<string>;
52
+
53
+ /**
54
+ * The CERTIFIED core-RDFS closure (ρdf; see index.d.ts for the full
55
+ * doc comment). Needs the npm-entry engine bundle.
56
+ */
57
+ export function coreRdfsClosure(
58
+ data: DataInput,
59
+ options?: { format?: DataFormat }
60
+ ): Promise<{ ok: boolean; ntriples: string }>;
61
+
62
+ /** Decidable core-RDFS fragment check — the regime theorems' fragment hypothesis. */
63
+ export function coreRdfsCheck(
64
+ data: DataInput,
65
+ options?: { format?: DataFormat }
66
+ ): Promise<{ ok: boolean; fragment: boolean }>;
67
+
68
+ /** Literature-name alias for coreRdfsClosure (ρdf). */
69
+ export function rhoDfClosure(
70
+ data: DataInput,
71
+ options?: { format?: DataFormat }
72
+ ): Promise<{ ok: boolean; ntriples: string }>;
73
+
74
+ /** Literature-name alias for coreRdfsCheck (ρdf). */
75
+ export function rhoDfFragmentCheck(
76
+ data: DataInput,
77
+ options?: { format?: DataFormat }
78
+ ): Promise<{ ok: boolean; fragment: boolean }>;
79
+
80
+ /** RDFS-Plus closure (RDFS + practical OWL subset; see index.d.ts). */
81
+ export function rdfsPlusClosure(
82
+ data: DataInput,
83
+ options?: { format?: DataFormat }
84
+ ): Promise<{ ok: boolean; ntriples: string; rounds: number }>;
85
+
86
+ /**
87
+ * OWL DL consistency verdict via the verified clash-detecting tableau.
88
+ * `consistent` is three-valued (`true`/`false`/`null` budget-out; see
89
+ * index.d.ts). Needs the npm-entry engine bundle.
90
+ */
91
+ export function owlIsConsistent(
92
+ data: DataInput,
93
+ options?: { format?: DataFormat; fuel?: number | string }
94
+ ): Promise<{ consistent: boolean | null; reason?: string }>;
95
+
96
+ /**
97
+ * OWL entailment check: does `premise` entail `conclusion`? See
98
+ * index.d.ts for the full doc comment. Needs the npm-entry engine
99
+ * bundle.
100
+ */
101
+ export function owlEntails(
102
+ premise: DataInput,
103
+ conclusion: DataInput,
104
+ options?: { format?: DataFormat; fuel?: number | string }
105
+ ): Promise<{ entailed: boolean | null; via: 'closure' | 'refutation'; reason?: string }>;
106
+
107
+ export function capabilities(): Promise<{
108
+ entry: boolean;
109
+ construct: boolean;
110
+ update: boolean;
111
+ canonicalize: boolean;
112
+ }>;
113
+ export const dataFactory: DataFactory;
114
+ /** True if the wasm loader + .wasm asset are present. */
115
+ export function wasmAvailable(): boolean;
116
+ export const version: string;
117
+
118
+ declare const _default: {
119
+ parse: typeof parse;
120
+ query: typeof query;
121
+ update: typeof update;
122
+ serialize: typeof serialize;
123
+ canonicalize: typeof canonicalize;
124
+ capabilities: typeof capabilities;
125
+ Dataset: typeof Dataset;
126
+ dataFactory: DataFactory;
127
+ wasmAvailable: typeof wasmAvailable;
128
+ version: string;
129
+ };
130
+ export default _default;
package/wasm.js ADDED
@@ -0,0 +1,158 @@
1
+ // factoidal — Node entry point for the **wasm** engine.
2
+ //
3
+ // Same public API as index.js (parse / query / update / serialize /
4
+ // canonicalize / graphs / canonicalHash / dataFactory / Dataset),
5
+ // backed by the wasm_of_ocaml
6
+ // bundle (factoidal.wasm.js + factoidal.wasm.assets/). Requires a
7
+ // WasmGC-capable runtime: Node >= 22.
8
+ //
9
+ // const factoidal = require('factoidal/wasm');
10
+ // const ds = await factoidal.parse('<a> <b> "c" .', { format: 'ntriples',
11
+ // baseIRI: 'http://example.org/' });
12
+ //
13
+ // All calls are async (wasm instantiation happens per invocation on
14
+ // the CLI path). For browsers, see browser-wasm.js.
15
+
16
+ 'use strict';
17
+
18
+ const fs = require('node:fs');
19
+ const path = require('node:path');
20
+
21
+ const engine = require('./lib/engine-wasm.js');
22
+ const { buildApi } = require('./lib/api.js');
23
+ const rdfjs = require('./rdfjs.js');
24
+
25
+ const pkg = require('./package.json');
26
+ const version = pkg.version;
27
+
28
+ // ---------------------------------------------------------------------
29
+ // npm-entry ABI loader (wasm flavor). The wasm entry bundle
30
+ // (factoidal-npm-entry.wasm.js) is an async IIFE like the CLI wasm
31
+ // loader; we capture its Promise via the same one-marker rewrite,
32
+ // await initialization once, and cache the exported ABI object.
33
+ // ---------------------------------------------------------------------
34
+
35
+ // The bundle's entry is an immediately-invoked async factory:
36
+ // ;(<param>=>async <arg>=>{...})(...)
37
+ // wasm_of_ocaml minifies <param> differently across versions ('$'
38
+ // before mid-2026, 'ag' in 6.4.1) - match the shape, not a fixed
39
+ // name, and splice the __fwPromise capture in after the leading ';'.
40
+ const IIFE_RE = /;\((\$|[A-Za-z_$][\w$]*)=>async /;
41
+ const IIFE_CAPTURE = ';globalThis.__fwPromise=';
42
+
43
+ function entryCandidates() {
44
+ const c = [];
45
+ if (process.env.FACTOIDAL_NPM_ENTRY_WASM) {
46
+ c.push(process.env.FACTOIDAL_NPM_ENTRY_WASM);
47
+ }
48
+ c.push(path.join(__dirname, 'factoidal-npm-entry.wasm.js'));
49
+ c.push(path.resolve(
50
+ __dirname, '..', '..', 'docs', 'fstar-extracted',
51
+ 'factoidal-npm-entry.wasm.js'));
52
+ return c;
53
+ }
54
+
55
+ let entryPromise = null;
56
+
57
+ async function loadEntry() {
58
+ if (entryPromise) return entryPromise;
59
+ entryPromise = (async () => {
60
+ for (const p of entryCandidates()) {
61
+ if (!p || !fs.existsSync(p)) continue;
62
+ const raw = fs.readFileSync(p, 'utf8');
63
+ const m = IIFE_RE.exec(raw);
64
+ if (!m) continue;
65
+ const src = raw.slice(0, m.index) + IIFE_CAPTURE + raw.slice(m.index + 1);
66
+ const module_ = { exports: {} };
67
+ const prevFw = globalThis.__fwPromise;
68
+ delete globalThis.__fwPromise;
69
+ try {
70
+ // The entry bundle has no CLI main — it only registers exports
71
+ // — so no argv/exit shimming is needed. Real fs is fine: the
72
+ // loader reads its .wasm asset relative to module paths BUT
73
+ // does so via `require.main.filename` (not the `__filename`
74
+ // param above) to find `factoidal-npm-entry.wasm.assets/`.
75
+ // When this file is loaded from a consumer whose own
76
+ // require.main lives elsewhere (any test/ subdirectory, any
77
+ // downstream package), the real require.main points at the
78
+ // wrong directory and the asset read throws ENOENT deep
79
+ // inside the wasm loader's init — silently caught below and
80
+ // misreported as "entry bundle unavailable" (this is what
81
+ // made capabilities() report entry:false for the wasm engine
82
+ // even though the bundle was present and valid). Wrap `require`
83
+ // so `.main.filename` points at the bundle itself, which sits
84
+ // next to its own `.wasm.assets/` directory.
85
+ const fakeRequire = Object.assign(
86
+ (name) => require(name), { main: { filename: p } });
87
+ (new Function('module', 'exports', 'require', '__filename',
88
+ '__dirname', src))(
89
+ module_, module_.exports, fakeRequire, p, path.dirname(p));
90
+ const fw = globalThis.__fwPromise;
91
+ if (fw && typeof fw.then === 'function') await fw;
92
+ const abi = module_.exports.factoidalNpmEntry ||
93
+ (globalThis.jsoo_exports && globalThis.jsoo_exports.factoidalNpmEntry) ||
94
+ globalThis.factoidalNpmEntry;
95
+ if (abi && typeof abi.queryDataset === 'function') return abi;
96
+ } catch (_) {
97
+ // Fall through to the next candidate / CLI fallback.
98
+ } finally {
99
+ if (prevFw === undefined) delete globalThis.__fwPromise;
100
+ else globalThis.__fwPromise = prevFw;
101
+ }
102
+ }
103
+ return null;
104
+ })();
105
+ return entryPromise;
106
+ }
107
+
108
+ const api = buildApi({
109
+ engineName: 'wasm',
110
+ runCli: engine.runCli,
111
+ loadEntry,
112
+ });
113
+
114
+ module.exports = {
115
+ parse: api.parse,
116
+ query: api.query,
117
+ registerExtensionFunction: api.registerExtensionFunction,
118
+ unregisterExtensionFunction: api.unregisterExtensionFunction,
119
+ clearExtensionFunctions: api.clearExtensionFunctions,
120
+ registerServiceEndpoint: api.registerServiceEndpoint,
121
+ clearServiceEndpoints: api.clearServiceEndpoints,
122
+ update: api.update,
123
+ serialize: api.serialize,
124
+ canonicalize: api.canonicalize,
125
+ graphs: api.graphs,
126
+ canonicalHash: api.canonicalHash,
127
+ shaclValidate: api.shaclValidate,
128
+ shexValidate: api.shexValidate,
129
+ owlClosure: api.owlClosure,
130
+ coreRdfsClosure: api.coreRdfsClosure,
131
+ coreRdfsCheck: api.coreRdfsCheck,
132
+ rhoDfClosure: api.rhoDfClosure,
133
+ rhoDfFragmentCheck: api.rhoDfFragmentCheck,
134
+ rdfsPlusClosure: api.rdfsPlusClosure,
135
+ tableauMaterialise: api.tableauMaterialise,
136
+ tableauDlInconsistent: api.tableauDlInconsistent,
137
+ owlIsConsistent: api.owlIsConsistent,
138
+ owlEntails: api.owlEntails,
139
+ rmlMap: api.rmlMap,
140
+ csvwToRdf: api.csvwToRdf,
141
+ jsonldToRdf: api.jsonldToRdf,
142
+ rifEval: api.rifEval,
143
+ openCottas: api.openCottas,
144
+ queryCottas: api.queryCottas,
145
+ closeCottas: api.closeCottas,
146
+ toCottas: api.toCottas,
147
+ capabilities: api.capabilities,
148
+ Dataset: rdfjs.Dataset,
149
+ dataFactory: rdfjs.dataFactory,
150
+ wasmAvailable: engine.wasmAvailable,
151
+ version,
152
+ // Test-only hook: the raw npm-entry ABI object (deltaBatchToHex,
153
+ // deltaMergeApplyBrowser, shaclValidate, ...) loaded straight off
154
+ // the wasm bundle, bypassing buildApi()'s Dataset-shaped surface.
155
+ // Mirrors browser-wasm.js's _setFactoidalWasmSource/
156
+ // _setWasmAssetFallback test hooks. Not part of the public API.
157
+ _loadEntryForTest: loadEntry,
158
+ };