shacl-wasm-node 0.1.7

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.
package/LICENSE-APACHE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2026 Peter Winstanley
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/LICENSE-MIT ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 pwin (Peter Winstanley)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,137 @@
1
+ # shacl-wasm
2
+
3
+ WebAssembly bindings for the `shacl` validation engine, for JavaScript hosts:
4
+ Node, VS Code extensions, bundlers, and browsers.
5
+
6
+ Dual-licensed under [MIT](LICENSE-MIT) or [Apache-2.0](LICENSE-APACHE), at your
7
+ option. Copyright 2026 Peter Winstanley.
8
+
9
+ ## Why
10
+
11
+ The JavaScript SHACL landscape thins out sharply once shapes use SHACL-SPARQL
12
+ (`sh:sparql` constraints, `sh:target [ a sh:SPARQLTarget ]`). `rdf-validate-shacl`
13
+ implements SHACL Core only and reports `conforms: true` against such shapes
14
+ rather than failing loudly. `shacl-engine` does implement them, but has two
15
+ behaviours that matter in practice:
16
+
17
+ - some `sh:sparql` shapes make it throw
18
+ `Tried to bind variable ?this in a GROUP BY operator`, taking out every check
19
+ in that shapes file; and
20
+ - it silently drops an `sh:severity` declared *inside* an `sh:sparql` block,
21
+ reporting every such result as `sh:Violation` whatever the shape says.
22
+
23
+ This build has neither. `crates/shacl-wasm/verify.js` checks both against real
24
+ shapes, including the ones that defeat `shacl-engine`.
25
+
26
+ ## Install / build
27
+
28
+ There is no published npm package yet; build it from this repo:
29
+
30
+ ```sh
31
+ cd crates/shacl-wasm
32
+ node build.mjs # both targets
33
+ node build.mjs nodejs # just pkg-node/
34
+ ```
35
+
36
+ Outputs:
37
+
38
+ | Directory | `--target` | For |
39
+ |---------------|-------------|--------------------------------------------------|
40
+ | `pkg-node` | `nodejs` | `require()` consumers: Node, VS Code extension host |
41
+ | `pkg-bundler` | `bundler` | webpack / vite / rollup (ESM + separate `.wasm`) |
42
+
43
+ Prerequisites: the `wasm32-unknown-unknown` target
44
+ (`rustup target add wasm32-unknown-unknown`) and
45
+ [`wasm-pack`](https://drager.github.io/wasm-pack/) (`cargo install wasm-pack`).
46
+
47
+ `build.mjs` wraps `wasm-pack` to add what it cannot express itself: the two
48
+ licence files (wasm-pack copies them into the output, but the `package.json` it
49
+ generates has an explicit `files` array and npm's "always include a licence"
50
+ rule does not match the suffixed `LICENSE-MIT`/`LICENSE-APACHE` names — verified
51
+ with `npm pack --dry-run`), and the `repository` field.
52
+
53
+ ## Use
54
+
55
+ ```js
56
+ const { Validator } = require('./pkg-node/shacl_wasm.js');
57
+
58
+ // Compiling shapes is the expensive half, so compile once and reuse.
59
+ const validator = Validator.fromTurtle(shapesTurtle, 'http://example.org/');
60
+
61
+ const report = validator.validateTurtle(dataTurtle, 'http://example.org/');
62
+
63
+ report.conforms; // false when anything has a conformance-blocking severity
64
+ report.length; // number of results
65
+ report.results; // array of plain objects, see below
66
+ report.toTurtle(); // the full SHACL report as a Turtle graph
67
+ ```
68
+
69
+ Each entry of `report.results`:
70
+
71
+ ```js
72
+ {
73
+ focusNode: 'http://example.org/bob',
74
+ path: 'http://example.org/name', // null for node-level findings
75
+ value: null, // null for sh:minCount / sh:closed
76
+ severity: 'http://www.w3.org/ns/shacl#Warning',
77
+ sourceShape: 'http://example.org/PersonShape',
78
+ component: 'http://www.w3.org/ns/shacl#MinCountConstraintComponent',
79
+ message: 'Less than 1 values',
80
+ }
81
+ ```
82
+
83
+ Terms render the way RDF/JS's `.value` does — an IRI bare, a blank node as
84
+ `_:label`, a literal as its lexical form — so this drops into code already
85
+ written against an RDF/JS SHACL engine.
86
+
87
+ Other entry points:
88
+
89
+ ```js
90
+ Validator.fromText(text, format, base) // turtle|ntriples|nquads|trig|rdfxml|jsonld
91
+ validator.validateText(text, format, base, inference) // inference: "none" (default) | "rdfs"
92
+ validator.shapeCount // shapes compiled
93
+
94
+ const { validateTurtle } = require('./pkg-node/shacl_wasm.js');
95
+ validateTurtle(shapesTurtle, dataTurtle, base); // one-shot, no reuse
96
+ ```
97
+
98
+ `inference: "rdfs"` validates against the RDFS closure of the data, so a finding
99
+ can depend on an entailed `rdf:type` rather than only an asserted one.
100
+
101
+ ## Notes on the wasm32 build
102
+
103
+ Three things differ from a native build, each handled in this crate rather than
104
+ asked of the caller:
105
+
106
+ - **No threads.** The engine's Turtle parse splits across cores with rayon,
107
+ which cannot build for `wasm32-unknown-unknown`. This crate depends on
108
+ `shacl` with `default-features = false`, dropping the `parallel` feature; the
109
+ loader then takes the sequential whole-document path it already falls back to
110
+ whenever a document cannot be chunked safely. The two produce an identical
111
+ graph — `parallel_matches_sequential` in the engine pins that.
112
+ - **No system clock.** SPARQL's `NOW()` reaches `oxsdatatypes`, whose default
113
+ clock is `std::time::SystemTime` — unimplemented on this target, so evaluating
114
+ any `sh:sparql` constraint panicked with `time not implemented on this
115
+ platform`. `oxsdatatypes` provides for this with a `js` feature that switches
116
+ to `js_sys::Date::now()`; this crate enables it for wasm32 only.
117
+ - **No system entropy.** `oxrdf` mints blank node identifiers via `rand`, which
118
+ reaches `getrandom`. getrandom 0.3 has no default source on
119
+ `wasm32-unknown-unknown` and needs both its `wasm_js` feature (set here) and
120
+ the `getrandom_backend="wasm_js"` cfg (set for this target in the workspace
121
+ `.cargo/config.toml`) — its own `compile_error!` is explicit that the feature
122
+ alone is not enough.
123
+
124
+ Native builds — the CLI, the Python extension module, the test suite — are
125
+ unaffected by all three: `parallel` is still a default feature, and the other
126
+ two are `cfg(target_arch = "wasm32")`-gated.
127
+
128
+ ## Verifying
129
+
130
+ ```sh
131
+ node build.mjs nodejs && node verify.js
132
+ ```
133
+
134
+ `verify.js` covers a basic `sh:minCount` violation, compiling all six shapes
135
+ files from the Ontology Development Suite's check registry (including the two
136
+ that crash `shacl-engine`), an `sh:severity` declared inside an `sh:sparql`
137
+ block, and Turtle serialisation of the report.
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "shacl-wasm-node",
3
+ "description": "WebAssembly bindings for the shacl validation engine (CommonJS, for Node and require())",
4
+ "version": "0.1.7",
5
+ "license": "MIT OR Apache-2.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/pwin/SHACL_Engine.git"
9
+ },
10
+ "files": [
11
+ "shacl_wasm_bg.wasm",
12
+ "shacl_wasm.js",
13
+ "shacl_wasm.d.ts",
14
+ "LICENSE-APACHE",
15
+ "LICENSE-MIT"
16
+ ],
17
+ "main": "shacl_wasm.js",
18
+ "types": "shacl_wasm.d.ts",
19
+ "homepage": "https://github.com/pwin/SHACL_Engine"
20
+ }
@@ -0,0 +1,88 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * The outcome of one validation run.
6
+ */
7
+ export class Report {
8
+ private constructor();
9
+ free(): void;
10
+ [Symbol.dispose](): void;
11
+ /**
12
+ * The full SHACL validation report as a Turtle graph -- what a SHACL
13
+ * processor is formally meant to return, for querying or diffing.
14
+ */
15
+ toTurtle(): string;
16
+ /**
17
+ * True when nothing in the report has a conformance-blocking severity
18
+ * (`sh:Violation`).
19
+ */
20
+ readonly conforms: boolean;
21
+ /**
22
+ * Number of results, blocking or not.
23
+ */
24
+ readonly length: number;
25
+ /**
26
+ * The results as an array of plain objects.
27
+ */
28
+ readonly results: any;
29
+ }
30
+
31
+ /**
32
+ * A compiled shapes graph, ready to validate data graphs against.
33
+ *
34
+ * `store` is the term store as it stood once the shapes were compiled, and is
35
+ * never mutated afterwards: each validation run clones it and grows its own
36
+ * copy. That is the pattern `TermStore`'s own documentation describes, and
37
+ * following it is what makes reuse actually pay.
38
+ *
39
+ * Parsing each data graph into one shared store instead — which this did at
40
+ * first — leaves every earlier run's terms behind, so the store grows without
41
+ * bound and the advertised path (compile once, validate many) is precisely the
42
+ * one that degrades. Measured on 100k instances / 400k triples: 23.7s sharing
43
+ * one store against 6.5s cloning per run, and the gap widens with every run.
44
+ */
45
+ export class Validator {
46
+ private constructor();
47
+ free(): void;
48
+ [Symbol.dispose](): void;
49
+ /**
50
+ * Compiles a shapes graph in any format the engine can read: `turtle`,
51
+ * `ntriples`, `nquads`, `trig`, `rdfxml`, `jsonld`.
52
+ */
53
+ static fromText(text: string, format: string, base?: string | null): Validator;
54
+ /**
55
+ * Compiles a shapes graph given as Turtle.
56
+ */
57
+ static fromTurtle(text: string, base?: string | null): Validator;
58
+ /**
59
+ * Validates a data graph in any supported format.
60
+ *
61
+ * `inference` is `"none"` (default) or `"rdfs"`; the latter validates
62
+ * against the RDFS closure of the data, so a finding can depend on an
63
+ * entailed `rdf:type` rather than only an asserted one.
64
+ */
65
+ validateText(text: string, format: string, base?: string | null, inference?: string | null): Report;
66
+ /**
67
+ * Validates a data graph given as Turtle.
68
+ */
69
+ validateTurtle(text: string, base?: string | null, inference?: string | null): Report;
70
+ /**
71
+ * How many shapes were compiled. Zero usually means the shapes graph
72
+ * parsed but declared nothing the engine recognises as a shape.
73
+ */
74
+ readonly shapeCount: number;
75
+ }
76
+
77
+ /**
78
+ * Improves panic reporting from a bare `RuntimeError: unreachable` to the real
79
+ * Rust panic message and stack on `console.error`. Runs automatically on module
80
+ * load; the alternative is a genuinely undebuggable failure mode.
81
+ */
82
+ export function start(): void;
83
+
84
+ /**
85
+ * One-shot validation, for a caller with a single data graph that gains
86
+ * nothing from holding a compiled [`Validator`].
87
+ */
88
+ export function validateTurtle(shapes: string, data: string, base?: string | null): Report;
package/shacl_wasm.js ADDED
@@ -0,0 +1,495 @@
1
+ /* @ts-self-types="./shacl_wasm.d.ts" */
2
+
3
+ /**
4
+ * The outcome of one validation run.
5
+ */
6
+ class Report {
7
+ static __wrap(ptr) {
8
+ const obj = Object.create(Report.prototype);
9
+ obj.__wbg_ptr = ptr;
10
+ ReportFinalization.register(obj, obj.__wbg_ptr, obj);
11
+ return obj;
12
+ }
13
+ __destroy_into_raw() {
14
+ const ptr = this.__wbg_ptr;
15
+ this.__wbg_ptr = 0;
16
+ ReportFinalization.unregister(this);
17
+ return ptr;
18
+ }
19
+ free() {
20
+ const ptr = this.__destroy_into_raw();
21
+ wasm.__wbg_report_free(ptr, 0);
22
+ }
23
+ /**
24
+ * True when nothing in the report has a conformance-blocking severity
25
+ * (`sh:Violation`).
26
+ * @returns {boolean}
27
+ */
28
+ get conforms() {
29
+ const ret = wasm.report_conforms(this.__wbg_ptr);
30
+ return ret !== 0;
31
+ }
32
+ /**
33
+ * Number of results, blocking or not.
34
+ * @returns {number}
35
+ */
36
+ get length() {
37
+ const ret = wasm.report_length(this.__wbg_ptr);
38
+ return ret >>> 0;
39
+ }
40
+ /**
41
+ * The results as an array of plain objects.
42
+ * @returns {any}
43
+ */
44
+ get results() {
45
+ try {
46
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
47
+ wasm.report_results(retptr, this.__wbg_ptr);
48
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
49
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
50
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
51
+ if (r2) {
52
+ throw takeObject(r1);
53
+ }
54
+ return takeObject(r0);
55
+ } finally {
56
+ wasm.__wbindgen_add_to_stack_pointer(16);
57
+ }
58
+ }
59
+ /**
60
+ * The full SHACL validation report as a Turtle graph -- what a SHACL
61
+ * processor is formally meant to return, for querying or diffing.
62
+ * @returns {string}
63
+ */
64
+ toTurtle() {
65
+ let deferred1_0;
66
+ let deferred1_1;
67
+ try {
68
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
69
+ wasm.report_toTurtle(retptr, this.__wbg_ptr);
70
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
71
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
72
+ deferred1_0 = r0;
73
+ deferred1_1 = r1;
74
+ return getStringFromWasm0(r0, r1);
75
+ } finally {
76
+ wasm.__wbindgen_add_to_stack_pointer(16);
77
+ wasm.__wbindgen_export3(deferred1_0, deferred1_1, 1);
78
+ }
79
+ }
80
+ }
81
+ if (Symbol.dispose) Report.prototype[Symbol.dispose] = Report.prototype.free;
82
+ exports.Report = Report;
83
+
84
+ /**
85
+ * A compiled shapes graph, ready to validate data graphs against.
86
+ *
87
+ * `store` is the term store as it stood once the shapes were compiled, and is
88
+ * never mutated afterwards: each validation run clones it and grows its own
89
+ * copy. That is the pattern `TermStore`'s own documentation describes, and
90
+ * following it is what makes reuse actually pay.
91
+ *
92
+ * Parsing each data graph into one shared store instead — which this did at
93
+ * first — leaves every earlier run's terms behind, so the store grows without
94
+ * bound and the advertised path (compile once, validate many) is precisely the
95
+ * one that degrades. Measured on 100k instances / 400k triples: 23.7s sharing
96
+ * one store against 6.5s cloning per run, and the gap widens with every run.
97
+ */
98
+ class Validator {
99
+ static __wrap(ptr) {
100
+ const obj = Object.create(Validator.prototype);
101
+ obj.__wbg_ptr = ptr;
102
+ ValidatorFinalization.register(obj, obj.__wbg_ptr, obj);
103
+ return obj;
104
+ }
105
+ __destroy_into_raw() {
106
+ const ptr = this.__wbg_ptr;
107
+ this.__wbg_ptr = 0;
108
+ ValidatorFinalization.unregister(this);
109
+ return ptr;
110
+ }
111
+ free() {
112
+ const ptr = this.__destroy_into_raw();
113
+ wasm.__wbg_validator_free(ptr, 0);
114
+ }
115
+ /**
116
+ * Compiles a shapes graph in any format the engine can read: `turtle`,
117
+ * `ntriples`, `nquads`, `trig`, `rdfxml`, `jsonld`.
118
+ * @param {string} text
119
+ * @param {string} format
120
+ * @param {string | null} [base]
121
+ * @returns {Validator}
122
+ */
123
+ static fromText(text, format, base) {
124
+ try {
125
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
126
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_export, wasm.__wbindgen_export2);
127
+ const len0 = WASM_VECTOR_LEN;
128
+ const ptr1 = passStringToWasm0(format, wasm.__wbindgen_export, wasm.__wbindgen_export2);
129
+ const len1 = WASM_VECTOR_LEN;
130
+ var ptr2 = isLikeNone(base) ? 0 : passStringToWasm0(base, wasm.__wbindgen_export, wasm.__wbindgen_export2);
131
+ var len2 = WASM_VECTOR_LEN;
132
+ wasm.validator_fromText(retptr, ptr0, len0, ptr1, len1, ptr2, len2);
133
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
134
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
135
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
136
+ if (r2) {
137
+ throw takeObject(r1);
138
+ }
139
+ return Validator.__wrap(r0);
140
+ } finally {
141
+ wasm.__wbindgen_add_to_stack_pointer(16);
142
+ }
143
+ }
144
+ /**
145
+ * Compiles a shapes graph given as Turtle.
146
+ * @param {string} text
147
+ * @param {string | null} [base]
148
+ * @returns {Validator}
149
+ */
150
+ static fromTurtle(text, base) {
151
+ try {
152
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
153
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_export, wasm.__wbindgen_export2);
154
+ const len0 = WASM_VECTOR_LEN;
155
+ var ptr1 = isLikeNone(base) ? 0 : passStringToWasm0(base, wasm.__wbindgen_export, wasm.__wbindgen_export2);
156
+ var len1 = WASM_VECTOR_LEN;
157
+ wasm.validator_fromTurtle(retptr, ptr0, len0, ptr1, len1);
158
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
159
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
160
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
161
+ if (r2) {
162
+ throw takeObject(r1);
163
+ }
164
+ return Validator.__wrap(r0);
165
+ } finally {
166
+ wasm.__wbindgen_add_to_stack_pointer(16);
167
+ }
168
+ }
169
+ /**
170
+ * How many shapes were compiled. Zero usually means the shapes graph
171
+ * parsed but declared nothing the engine recognises as a shape.
172
+ * @returns {number}
173
+ */
174
+ get shapeCount() {
175
+ const ret = wasm.validator_shapeCount(this.__wbg_ptr);
176
+ return ret >>> 0;
177
+ }
178
+ /**
179
+ * Validates a data graph in any supported format.
180
+ *
181
+ * `inference` is `"none"` (default) or `"rdfs"`; the latter validates
182
+ * against the RDFS closure of the data, so a finding can depend on an
183
+ * entailed `rdf:type` rather than only an asserted one.
184
+ * @param {string} text
185
+ * @param {string} format
186
+ * @param {string | null} [base]
187
+ * @param {string | null} [inference]
188
+ * @returns {Report}
189
+ */
190
+ validateText(text, format, base, inference) {
191
+ try {
192
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
193
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_export, wasm.__wbindgen_export2);
194
+ const len0 = WASM_VECTOR_LEN;
195
+ const ptr1 = passStringToWasm0(format, wasm.__wbindgen_export, wasm.__wbindgen_export2);
196
+ const len1 = WASM_VECTOR_LEN;
197
+ var ptr2 = isLikeNone(base) ? 0 : passStringToWasm0(base, wasm.__wbindgen_export, wasm.__wbindgen_export2);
198
+ var len2 = WASM_VECTOR_LEN;
199
+ var ptr3 = isLikeNone(inference) ? 0 : passStringToWasm0(inference, wasm.__wbindgen_export, wasm.__wbindgen_export2);
200
+ var len3 = WASM_VECTOR_LEN;
201
+ wasm.validator_validateText(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
202
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
203
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
204
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
205
+ if (r2) {
206
+ throw takeObject(r1);
207
+ }
208
+ return Report.__wrap(r0);
209
+ } finally {
210
+ wasm.__wbindgen_add_to_stack_pointer(16);
211
+ }
212
+ }
213
+ /**
214
+ * Validates a data graph given as Turtle.
215
+ * @param {string} text
216
+ * @param {string | null} [base]
217
+ * @param {string | null} [inference]
218
+ * @returns {Report}
219
+ */
220
+ validateTurtle(text, base, inference) {
221
+ try {
222
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
223
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_export, wasm.__wbindgen_export2);
224
+ const len0 = WASM_VECTOR_LEN;
225
+ var ptr1 = isLikeNone(base) ? 0 : passStringToWasm0(base, wasm.__wbindgen_export, wasm.__wbindgen_export2);
226
+ var len1 = WASM_VECTOR_LEN;
227
+ var ptr2 = isLikeNone(inference) ? 0 : passStringToWasm0(inference, wasm.__wbindgen_export, wasm.__wbindgen_export2);
228
+ var len2 = WASM_VECTOR_LEN;
229
+ wasm.validator_validateTurtle(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2);
230
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
231
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
232
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
233
+ if (r2) {
234
+ throw takeObject(r1);
235
+ }
236
+ return Report.__wrap(r0);
237
+ } finally {
238
+ wasm.__wbindgen_add_to_stack_pointer(16);
239
+ }
240
+ }
241
+ }
242
+ if (Symbol.dispose) Validator.prototype[Symbol.dispose] = Validator.prototype.free;
243
+ exports.Validator = Validator;
244
+
245
+ /**
246
+ * Improves panic reporting from a bare `RuntimeError: unreachable` to the real
247
+ * Rust panic message and stack on `console.error`. Runs automatically on module
248
+ * load; the alternative is a genuinely undebuggable failure mode.
249
+ */
250
+ function start() {
251
+ wasm.start();
252
+ }
253
+ exports.start = start;
254
+
255
+ /**
256
+ * One-shot validation, for a caller with a single data graph that gains
257
+ * nothing from holding a compiled [`Validator`].
258
+ * @param {string} shapes
259
+ * @param {string} data
260
+ * @param {string | null} [base]
261
+ * @returns {Report}
262
+ */
263
+ function validateTurtle(shapes, data, base) {
264
+ try {
265
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
266
+ const ptr0 = passStringToWasm0(shapes, wasm.__wbindgen_export, wasm.__wbindgen_export2);
267
+ const len0 = WASM_VECTOR_LEN;
268
+ const ptr1 = passStringToWasm0(data, wasm.__wbindgen_export, wasm.__wbindgen_export2);
269
+ const len1 = WASM_VECTOR_LEN;
270
+ var ptr2 = isLikeNone(base) ? 0 : passStringToWasm0(base, wasm.__wbindgen_export, wasm.__wbindgen_export2);
271
+ var len2 = WASM_VECTOR_LEN;
272
+ wasm.validateTurtle(retptr, ptr0, len0, ptr1, len1, ptr2, len2);
273
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
274
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
275
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
276
+ if (r2) {
277
+ throw takeObject(r1);
278
+ }
279
+ return Report.__wrap(r0);
280
+ } finally {
281
+ wasm.__wbindgen_add_to_stack_pointer(16);
282
+ }
283
+ }
284
+ exports.validateTurtle = validateTurtle;
285
+ function __wbg_get_imports() {
286
+ const import0 = {
287
+ __proto__: null,
288
+ __wbg_String_8564e559799eccda: function(arg0, arg1) {
289
+ const ret = String(getObject(arg1));
290
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
291
+ const len1 = WASM_VECTOR_LEN;
292
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
293
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
294
+ },
295
+ __wbg___wbindgen_throw_bb96b2010945f0bc: function(arg0, arg1) {
296
+ throw new Error(getStringFromWasm0(arg0, arg1));
297
+ },
298
+ __wbg_error_757e9472f8410341: function(arg0, arg1) {
299
+ let deferred0_0;
300
+ let deferred0_1;
301
+ try {
302
+ deferred0_0 = arg0;
303
+ deferred0_1 = arg1;
304
+ console.error(getStringFromWasm0(arg0, arg1));
305
+ } finally {
306
+ wasm.__wbindgen_export3(deferred0_0, deferred0_1, 1);
307
+ }
308
+ },
309
+ __wbg_getRandomValues_a608c4436c19407a: function() { return handleError(function (arg0, arg1) {
310
+ globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
311
+ }, arguments); },
312
+ __wbg_new_116be93542d39019: function() {
313
+ const ret = new Array();
314
+ return addHeapObject(ret);
315
+ },
316
+ __wbg_new_227d7c05414eb861: function() {
317
+ const ret = new Error();
318
+ return addHeapObject(ret);
319
+ },
320
+ __wbg_new_ebe3e0f6837f0879: function() {
321
+ const ret = new Object();
322
+ return addHeapObject(ret);
323
+ },
324
+ __wbg_now_8b265300afd5f2b9: function() {
325
+ const ret = Date.now();
326
+ return ret;
327
+ },
328
+ __wbg_set_6be42768c690e380: function(arg0, arg1, arg2) {
329
+ getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
330
+ },
331
+ __wbg_set_a80955eb93b145c6: function(arg0, arg1, arg2) {
332
+ getObject(arg0)[arg1 >>> 0] = takeObject(arg2);
333
+ },
334
+ __wbg_stack_3b0d974bbf31e44f: function(arg0, arg1) {
335
+ const ret = getObject(arg1).stack;
336
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
337
+ const len1 = WASM_VECTOR_LEN;
338
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
339
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
340
+ },
341
+ __wbindgen_cast_0000000000000001: function(arg0, arg1) {
342
+ // Cast intrinsic for `Ref(String) -> Externref`.
343
+ const ret = getStringFromWasm0(arg0, arg1);
344
+ return addHeapObject(ret);
345
+ },
346
+ __wbindgen_object_clone_ref: function(arg0) {
347
+ const ret = getObject(arg0);
348
+ return addHeapObject(ret);
349
+ },
350
+ __wbindgen_object_drop_ref: function(arg0) {
351
+ takeObject(arg0);
352
+ },
353
+ };
354
+ return {
355
+ __proto__: null,
356
+ "./shacl_wasm_bg.js": import0,
357
+ };
358
+ }
359
+
360
+ const ReportFinalization = (typeof FinalizationRegistry === 'undefined')
361
+ ? { register: () => {}, unregister: () => {} }
362
+ : new FinalizationRegistry(ptr => wasm.__wbg_report_free(ptr, 1));
363
+ const ValidatorFinalization = (typeof FinalizationRegistry === 'undefined')
364
+ ? { register: () => {}, unregister: () => {} }
365
+ : new FinalizationRegistry(ptr => wasm.__wbg_validator_free(ptr, 1));
366
+
367
+ function addHeapObject(obj) {
368
+ if (heap_next === heap.length) heap.push(heap.length + 1);
369
+ const idx = heap_next;
370
+ heap_next = heap[idx];
371
+
372
+ heap[idx] = obj;
373
+ return idx;
374
+ }
375
+
376
+ function dropObject(idx) {
377
+ if (idx < 1028) return;
378
+ heap[idx] = heap_next;
379
+ heap_next = idx;
380
+ }
381
+
382
+ function getArrayU8FromWasm0(ptr, len) {
383
+ ptr = ptr >>> 0;
384
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
385
+ }
386
+
387
+ let cachedDataViewMemory0 = null;
388
+ function getDataViewMemory0() {
389
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
390
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
391
+ }
392
+ return cachedDataViewMemory0;
393
+ }
394
+
395
+ function getStringFromWasm0(ptr, len) {
396
+ return decodeText(ptr >>> 0, len);
397
+ }
398
+
399
+ let cachedUint8ArrayMemory0 = null;
400
+ function getUint8ArrayMemory0() {
401
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
402
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
403
+ }
404
+ return cachedUint8ArrayMemory0;
405
+ }
406
+
407
+ function getObject(idx) { return heap[idx]; }
408
+
409
+ function handleError(f, args) {
410
+ try {
411
+ return f.apply(this, args);
412
+ } catch (e) {
413
+ wasm.__wbindgen_export4(addHeapObject(e));
414
+ }
415
+ }
416
+
417
+ let heap = new Array(1024).fill(undefined);
418
+ heap.push(undefined, null, true, false);
419
+
420
+ let heap_next = heap.length;
421
+
422
+ function isLikeNone(x) {
423
+ return x === undefined || x === null;
424
+ }
425
+
426
+ function passStringToWasm0(arg, malloc, realloc) {
427
+ if (realloc === undefined) {
428
+ const buf = cachedTextEncoder.encode(arg);
429
+ const ptr = malloc(buf.length, 1) >>> 0;
430
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
431
+ WASM_VECTOR_LEN = buf.length;
432
+ return ptr;
433
+ }
434
+
435
+ let len = arg.length;
436
+ let ptr = malloc(len, 1) >>> 0;
437
+
438
+ const mem = getUint8ArrayMemory0();
439
+
440
+ let offset = 0;
441
+
442
+ for (; offset < len; offset++) {
443
+ const code = arg.charCodeAt(offset);
444
+ if (code > 0x7F) break;
445
+ mem[ptr + offset] = code;
446
+ }
447
+ if (offset !== len) {
448
+ if (offset !== 0) {
449
+ arg = arg.slice(offset);
450
+ }
451
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
452
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
453
+ const ret = cachedTextEncoder.encodeInto(arg, view);
454
+
455
+ offset += ret.written;
456
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
457
+ }
458
+
459
+ WASM_VECTOR_LEN = offset;
460
+ return ptr;
461
+ }
462
+
463
+ function takeObject(idx) {
464
+ const ret = getObject(idx);
465
+ dropObject(idx);
466
+ return ret;
467
+ }
468
+
469
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
470
+ cachedTextDecoder.decode();
471
+ function decodeText(ptr, len) {
472
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
473
+ }
474
+
475
+ const cachedTextEncoder = new TextEncoder();
476
+
477
+ if (!('encodeInto' in cachedTextEncoder)) {
478
+ cachedTextEncoder.encodeInto = function (arg, view) {
479
+ const buf = cachedTextEncoder.encode(arg);
480
+ view.set(buf);
481
+ return {
482
+ read: arg.length,
483
+ written: buf.length
484
+ };
485
+ };
486
+ }
487
+
488
+ let WASM_VECTOR_LEN = 0;
489
+
490
+ const wasmPath = `${__dirname}/shacl_wasm_bg.wasm`;
491
+ const wasmBytes = require('fs').readFileSync(wasmPath);
492
+ const wasmModule = new WebAssembly.Module(wasmBytes);
493
+ let wasmInstance = new WebAssembly.Instance(wasmModule, __wbg_get_imports());
494
+ let wasm = wasmInstance.exports;
495
+ wasm.__wbindgen_start();
Binary file