@aml-org/amf-custom-validator 1.8.0-SNAPSHOT.3 → 2.0.0-alpha.1

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.
@@ -0,0 +1,245 @@
1
+ 'use strict';
2
+
3
+ var node_wasi = require('node:wasi');
4
+ var fs = require('node:fs');
5
+ var node_url = require('node:url');
6
+ var path = require('node:path');
7
+ var node_zlib = require('node:zlib');
8
+
9
+ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
10
+ function _interopNamespaceDefault(e) {
11
+ var n = Object.create(null);
12
+ if (e) {
13
+ Object.keys(e).forEach(function (k) {
14
+ if (k !== 'default') {
15
+ var d = Object.getOwnPropertyDescriptor(e, k);
16
+ Object.defineProperty(n, k, d.get ? d : {
17
+ enumerable: true,
18
+ get: function () { return e[k]; }
19
+ });
20
+ }
21
+ });
22
+ }
23
+ n.default = e;
24
+ return Object.freeze(n);
25
+ }
26
+
27
+ var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
28
+ var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
29
+
30
+ const textEncoder = new TextEncoder();
31
+ const textDecoder = new TextDecoder();
32
+ class CustomValidator {
33
+ exports;
34
+ constructor(exports$1) {
35
+ this.exports = exports$1;
36
+ }
37
+ validateCustomProfile(profile, data, debug = false) {
38
+ const exp = this.requireExports();
39
+ const p = this.writeString(profile);
40
+ const d = this.writeString(data);
41
+ try {
42
+ const packed = exp.acv_validate(p.ptr, p.len, d.ptr, d.len, debug ? 1 : 0);
43
+ return this.readResult(packed);
44
+ }
45
+ finally {
46
+ this.free(p.ptr);
47
+ this.free(d.ptr);
48
+ }
49
+ }
50
+ validateWithReportConfiguration(profile, data, debug, reportConfig) {
51
+ const exp = this.requireExports();
52
+ const p = this.writeString(profile);
53
+ const d = this.writeString(data);
54
+ const cfg = this.writeString(reportConfig == null ? "" : JSON.stringify(reportConfig));
55
+ try {
56
+ const packed = exp.acv_validate_with_configuration(p.ptr, p.len, d.ptr, d.len, debug ? 1 : 0, cfg.ptr, cfg.len);
57
+ return this.readResult(packed);
58
+ }
59
+ finally {
60
+ this.free(p.ptr);
61
+ this.free(d.ptr);
62
+ this.free(cfg.ptr);
63
+ }
64
+ }
65
+ generateRego(profile) {
66
+ const exp = this.requireExports();
67
+ const p = this.writeString(profile);
68
+ try {
69
+ return this.readResult(exp.acv_generate_rego(p.ptr, p.len));
70
+ }
71
+ finally {
72
+ this.free(p.ptr);
73
+ }
74
+ }
75
+ normalizeInput(data) {
76
+ const exp = this.requireExports();
77
+ const d = this.writeString(data);
78
+ try {
79
+ return this.readResult(exp.acv_normalize_input(d.ptr, d.len));
80
+ }
81
+ finally {
82
+ this.free(d.ptr);
83
+ }
84
+ }
85
+ /**
86
+ * Compiles a profile into a handle consumers can re-use against many
87
+ * payloads. ~13× faster than validateCustomProfile per-call when the
88
+ * same profile is validated repeatedly.
89
+ *
90
+ * The consumer owns the returned handle's lifetime: call release() (or
91
+ * use `using` with Symbol.dispose) to free it. validator.exit() does NOT
92
+ * release outstanding profiles because the consumer may still hold
93
+ * references.
94
+ */
95
+ compileProfile(profile) {
96
+ const exp = this.requireExports();
97
+ const p = this.writeString(profile);
98
+ try {
99
+ const handle = exp.acv_compile_profile(p.ptr, p.len);
100
+ if (handle === 0)
101
+ throw new Error(this.readLastError());
102
+ return new CompiledProfile(this, handle);
103
+ }
104
+ finally {
105
+ this.free(p.ptr);
106
+ }
107
+ }
108
+ exit() {
109
+ this.exports = null;
110
+ }
111
+ /** @internal */
112
+ _validateCompiled(handle, data, options) {
113
+ const exp = this.requireExports();
114
+ const debug = options.debug ? 1 : 0;
115
+ const d = this.writeString(data);
116
+ try {
117
+ if (options.reportConfig == null) {
118
+ const packed = exp.acv_validate_compiled(handle, d.ptr, d.len, debug);
119
+ if (packed === 0n)
120
+ throw new Error(this.readLastError());
121
+ return this.readResult(packed);
122
+ }
123
+ const cfg = this.writeString(JSON.stringify(options.reportConfig));
124
+ try {
125
+ const packed = exp.acv_validate_compiled_with_configuration(handle, d.ptr, d.len, debug, cfg.ptr, cfg.len);
126
+ if (packed === 0n)
127
+ throw new Error(this.readLastError());
128
+ return this.readResult(packed);
129
+ }
130
+ finally {
131
+ this.free(cfg.ptr);
132
+ }
133
+ }
134
+ finally {
135
+ this.free(d.ptr);
136
+ }
137
+ }
138
+ /** @internal */
139
+ _releaseProfile(handle) {
140
+ if (this.exports !== null)
141
+ this.exports.acv_release_profile(handle);
142
+ }
143
+ readLastError() {
144
+ const exp = this.requireExports();
145
+ return this.readResult(exp.acv_last_error());
146
+ }
147
+ requireExports() {
148
+ if (this.exports === null) {
149
+ throw new Error("Validator has been exited");
150
+ }
151
+ return this.exports;
152
+ }
153
+ writeString(str) {
154
+ const bytes = textEncoder.encode(str);
155
+ if (bytes.length === 0)
156
+ return { ptr: 0, len: 0 };
157
+ const exp = this.requireExports();
158
+ const ptr = exp.acv_malloc(bytes.length);
159
+ new Uint8Array(exp.memory.buffer, ptr, bytes.length).set(bytes);
160
+ return { ptr, len: bytes.length };
161
+ }
162
+ readResult(packed) {
163
+ const big = BigInt.asUintN(64, packed);
164
+ const ptr = Number(big >> 32n);
165
+ const len = Number(big & 0xffffffffn);
166
+ if (len === 0)
167
+ return "";
168
+ const exp = this.requireExports();
169
+ const copy = new Uint8Array(exp.memory.buffer, ptr, len).slice();
170
+ const out = textDecoder.decode(copy);
171
+ exp.acv_free(ptr);
172
+ return out;
173
+ }
174
+ free(ptr) {
175
+ if (ptr !== 0 && this.exports !== null)
176
+ this.exports.acv_free(ptr);
177
+ }
178
+ }
179
+ /**
180
+ * Opaque handle to a compiled profile. Call validate() to evaluate data
181
+ * against it; call release() (or use `using`) when done to free the Go-side
182
+ * resources. Never share a handle across validators — handles are indexed
183
+ * into one specific WASM instance's handle table and would read garbage
184
+ * in another.
185
+ */
186
+ class CompiledProfile {
187
+ validator;
188
+ handle;
189
+ released = false;
190
+ constructor(validator, handle) {
191
+ this.validator = validator;
192
+ this.handle = handle;
193
+ }
194
+ validate(data, options = {}) {
195
+ if (this.released)
196
+ throw new Error("CompiledProfile has been released");
197
+ const opts = typeof options === "boolean" ? { debug: options } : options;
198
+ return this.validator._validateCompiled(this.handle, data, opts);
199
+ }
200
+ release() {
201
+ if (this.released)
202
+ return;
203
+ this.released = true;
204
+ this.validator._releaseProfile(this.handle);
205
+ }
206
+ [Symbol.dispose]() {
207
+ this.release();
208
+ }
209
+ }
210
+
211
+ // Module-scope cache: decompress + WebAssembly.compile runs once per process.
212
+ // Subsequent create() calls only re-instantiate, which is ~10 ms vs ~150 ms.
213
+ let compiledModulePromise = null;
214
+ // ESM-compatible path resolution. Rollup emits both ESM and CJS bundles; in
215
+ // CJS `__dirname` is defined by Node directly, but in ESM we need import.meta.
216
+ // Referencing `import.meta.url` here is safe because Rollup replaces it at
217
+ // bundle time for the CJS output.
218
+ function thisDir() {
219
+ const url = (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))
220
+ ?? (typeof __filename !== "undefined" ? `file://${__filename}` : undefined);
221
+ return url ? path__namespace.dirname(node_url.fileURLToPath(url)) : __dirname;
222
+ }
223
+ function getCompiledModule() {
224
+ if (compiledModulePromise === null) {
225
+ const wasmPath = path__namespace.join(thisDir(), "..", "..", "lib", "main.wasm.gz");
226
+ const compressed = fs__namespace.readFileSync(wasmPath);
227
+ const wasm = node_zlib.gunzipSync(compressed);
228
+ compiledModulePromise = WebAssembly.compile(wasm);
229
+ }
230
+ return compiledModulePromise;
231
+ }
232
+ class CustomValidatorFactory {
233
+ static async create() {
234
+ const wasi = new node_wasi.WASI({ version: "preview1", args: [], env: {} });
235
+ const module = await getCompiledModule();
236
+ const instance = await WebAssembly.instantiate(module, wasi.getImportObject());
237
+ wasi.initialize(instance); // reactor mode
238
+ return new CustomValidator(instance.exports);
239
+ }
240
+ }
241
+
242
+ exports.CompiledProfile = CompiledProfile;
243
+ exports.CustomValidator = CustomValidator;
244
+ exports.CustomValidatorFactory = CustomValidatorFactory;
245
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":["../../../src/core/validator.ts","../../../src/platforms/node.ts"],"sourcesContent":[null,null],"names":["exports","path","fileURLToPath","fs","gunzipSync","WASI"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE;AACrC,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE;MAExB,eAAe,CAAA;AAChB,IAAA,OAAO;AAEf,IAAA,WAAA,CAAYA,SAAoB,EAAA;AAC5B,QAAA,IAAI,CAAC,OAAO,GAAGA,SAAO;IAC1B;AAEA,IAAA,qBAAqB,CAAC,OAAe,EAAE,IAAY,EAAE,QAAiB,KAAK,EAAA;AACvE,QAAA,MAAM,GAAG,GAAG,IAAI,CAAC,cAAc,EAAE;QACjC,MAAM,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC;QACnC,MAAM,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;AAChC,QAAA,IAAI;AACA,YAAA,MAAM,MAAM,GAAG,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC;AAC1E,YAAA,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC;QAClC;gBAAU;AACN,YAAA,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC;AAChB,YAAA,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC;QACpB;IACJ;AAEA,IAAA,+BAA+B,CAC3B,OAAe,EACf,IAAY,EACZ,KAAc,EACd,YAAoD,E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AW,GAAG,CAAA,OAAA,EAAU,UAAU,EAAE,GAAG,SAAS,CAAC;AAC/E,IAAA,OAAO,GAAG,GAAGC,eAAI,CAAC,OAAO,CAACC,sBAAa,CAAC,GAAG,CAAC,CAAC,GAAG,SAAS;AAC7D;AAEA,SAAS,iBAAiB,GAAA;AACtB,IAAA,IAAI,qBAAqB,KAAK,IAAI,EAAE;AAChC,QAAA,MAAM,QAAQ,GAAGD,eAAI,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,cAAc,CAAC;QACxE,MAAM,UAAU,GAAGE,aAAE,CAAC,YAAY,CAAC,QAAQ,CAAC;AAC5C,QAAA,MAAM,IAAI,GAAGC,oBAAU,CAAC,UAAU,CAAC;AACnC,QAAA,qBAAqB,GAAG,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC;IACrD;AACA,IAAA,OAAO,qBAAqB;AAChC;MAEa,sBAAsB,CAAA;IAC/B,aAAa,MAAM,GAAA;AACf,QAAA,MAAM,IAAI,GAAG,IAAIC,cAAI,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC;AACjE,QAAA,MAAM,MAAM,GAAG,MAAM,iBAAiB,EAAE;AACxC,QAAA,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC,eAAe,EAAyB,CAAC;AACrG,QAAA,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;AAC1B,QAAA,OAAO,IAAI,eAAe,CAAC,QAAQ,CAAC,OAAiC,CAAC;IAC1E;AACH;;;;;;"}
@@ -0,0 +1,77 @@
1
+ interface ReportConfiguration {
2
+ IncludeReportCreationTime: boolean;
3
+ ReportSchemaIri: string;
4
+ LexicalSchemaIri: string;
5
+ BaseIri?: string;
6
+ }
7
+ interface ValidateOptions {
8
+ debug?: boolean;
9
+ reportConfig?: ReportConfiguration | null;
10
+ }
11
+ interface WasmExports {
12
+ memory: WebAssembly.Memory;
13
+ acv_malloc(size: number): number;
14
+ acv_free(ptr: number): void;
15
+ acv_validate(profilePtr: number, profileLen: number, dataPtr: number, dataLen: number, debug: number): bigint;
16
+ acv_validate_with_configuration(profilePtr: number, profileLen: number, dataPtr: number, dataLen: number, debug: number, cfgPtr: number, cfgLen: number): bigint;
17
+ acv_generate_rego(profilePtr: number, profileLen: number): bigint;
18
+ acv_normalize_input(dataPtr: number, dataLen: number): bigint;
19
+ acv_compile_profile(profilePtr: number, profileLen: number): number;
20
+ acv_validate_compiled(handle: number, dataPtr: number, dataLen: number, debug: number): bigint;
21
+ acv_validate_compiled_with_configuration(handle: number, dataPtr: number, dataLen: number, debug: number, cfgPtr: number, cfgLen: number): bigint;
22
+ acv_release_profile(handle: number): void;
23
+ acv_last_error(): bigint;
24
+ }
25
+
26
+ declare class CustomValidator {
27
+ private exports;
28
+ constructor(exports: WasmExports);
29
+ validateCustomProfile(profile: string, data: string, debug?: boolean): string;
30
+ validateWithReportConfiguration(profile: string, data: string, debug: boolean, reportConfig: ReportConfiguration | null | undefined): string;
31
+ generateRego(profile: string): string;
32
+ normalizeInput(data: string): string;
33
+ /**
34
+ * Compiles a profile into a handle consumers can re-use against many
35
+ * payloads. ~13× faster than validateCustomProfile per-call when the
36
+ * same profile is validated repeatedly.
37
+ *
38
+ * The consumer owns the returned handle's lifetime: call release() (or
39
+ * use `using` with Symbol.dispose) to free it. validator.exit() does NOT
40
+ * release outstanding profiles because the consumer may still hold
41
+ * references.
42
+ */
43
+ compileProfile(profile: string): CompiledProfile;
44
+ exit(): void;
45
+ /** @internal */
46
+ _validateCompiled(handle: number, data: string, options: ValidateOptions): string;
47
+ /** @internal */
48
+ _releaseProfile(handle: number): void;
49
+ private readLastError;
50
+ private requireExports;
51
+ private writeString;
52
+ private readResult;
53
+ private free;
54
+ }
55
+ /**
56
+ * Opaque handle to a compiled profile. Call validate() to evaluate data
57
+ * against it; call release() (or use `using`) when done to free the Go-side
58
+ * resources. Never share a handle across validators — handles are indexed
59
+ * into one specific WASM instance's handle table and would read garbage
60
+ * in another.
61
+ */
62
+ declare class CompiledProfile {
63
+ private readonly validator;
64
+ readonly handle: number;
65
+ private released;
66
+ constructor(validator: CustomValidator, handle: number);
67
+ validate(data: string, options?: ValidateOptions | boolean): string;
68
+ release(): void;
69
+ [Symbol.dispose](): void;
70
+ }
71
+
72
+ declare class CustomValidatorFactory {
73
+ static create(): Promise<CustomValidator>;
74
+ }
75
+
76
+ export { CompiledProfile, CustomValidator, CustomValidatorFactory };
77
+ export type { ReportConfiguration, ValidateOptions };
@@ -0,0 +1,220 @@
1
+ import { WASI } from 'node:wasi';
2
+ import * as fs from 'node:fs';
3
+ import { fileURLToPath } from 'node:url';
4
+ import * as path from 'node:path';
5
+ import { gunzipSync } from 'node:zlib';
6
+
7
+ const textEncoder = new TextEncoder();
8
+ const textDecoder = new TextDecoder();
9
+ class CustomValidator {
10
+ exports;
11
+ constructor(exports$1) {
12
+ this.exports = exports$1;
13
+ }
14
+ validateCustomProfile(profile, data, debug = false) {
15
+ const exp = this.requireExports();
16
+ const p = this.writeString(profile);
17
+ const d = this.writeString(data);
18
+ try {
19
+ const packed = exp.acv_validate(p.ptr, p.len, d.ptr, d.len, debug ? 1 : 0);
20
+ return this.readResult(packed);
21
+ }
22
+ finally {
23
+ this.free(p.ptr);
24
+ this.free(d.ptr);
25
+ }
26
+ }
27
+ validateWithReportConfiguration(profile, data, debug, reportConfig) {
28
+ const exp = this.requireExports();
29
+ const p = this.writeString(profile);
30
+ const d = this.writeString(data);
31
+ const cfg = this.writeString(reportConfig == null ? "" : JSON.stringify(reportConfig));
32
+ try {
33
+ const packed = exp.acv_validate_with_configuration(p.ptr, p.len, d.ptr, d.len, debug ? 1 : 0, cfg.ptr, cfg.len);
34
+ return this.readResult(packed);
35
+ }
36
+ finally {
37
+ this.free(p.ptr);
38
+ this.free(d.ptr);
39
+ this.free(cfg.ptr);
40
+ }
41
+ }
42
+ generateRego(profile) {
43
+ const exp = this.requireExports();
44
+ const p = this.writeString(profile);
45
+ try {
46
+ return this.readResult(exp.acv_generate_rego(p.ptr, p.len));
47
+ }
48
+ finally {
49
+ this.free(p.ptr);
50
+ }
51
+ }
52
+ normalizeInput(data) {
53
+ const exp = this.requireExports();
54
+ const d = this.writeString(data);
55
+ try {
56
+ return this.readResult(exp.acv_normalize_input(d.ptr, d.len));
57
+ }
58
+ finally {
59
+ this.free(d.ptr);
60
+ }
61
+ }
62
+ /**
63
+ * Compiles a profile into a handle consumers can re-use against many
64
+ * payloads. ~13× faster than validateCustomProfile per-call when the
65
+ * same profile is validated repeatedly.
66
+ *
67
+ * The consumer owns the returned handle's lifetime: call release() (or
68
+ * use `using` with Symbol.dispose) to free it. validator.exit() does NOT
69
+ * release outstanding profiles because the consumer may still hold
70
+ * references.
71
+ */
72
+ compileProfile(profile) {
73
+ const exp = this.requireExports();
74
+ const p = this.writeString(profile);
75
+ try {
76
+ const handle = exp.acv_compile_profile(p.ptr, p.len);
77
+ if (handle === 0)
78
+ throw new Error(this.readLastError());
79
+ return new CompiledProfile(this, handle);
80
+ }
81
+ finally {
82
+ this.free(p.ptr);
83
+ }
84
+ }
85
+ exit() {
86
+ this.exports = null;
87
+ }
88
+ /** @internal */
89
+ _validateCompiled(handle, data, options) {
90
+ const exp = this.requireExports();
91
+ const debug = options.debug ? 1 : 0;
92
+ const d = this.writeString(data);
93
+ try {
94
+ if (options.reportConfig == null) {
95
+ const packed = exp.acv_validate_compiled(handle, d.ptr, d.len, debug);
96
+ if (packed === 0n)
97
+ throw new Error(this.readLastError());
98
+ return this.readResult(packed);
99
+ }
100
+ const cfg = this.writeString(JSON.stringify(options.reportConfig));
101
+ try {
102
+ const packed = exp.acv_validate_compiled_with_configuration(handle, d.ptr, d.len, debug, cfg.ptr, cfg.len);
103
+ if (packed === 0n)
104
+ throw new Error(this.readLastError());
105
+ return this.readResult(packed);
106
+ }
107
+ finally {
108
+ this.free(cfg.ptr);
109
+ }
110
+ }
111
+ finally {
112
+ this.free(d.ptr);
113
+ }
114
+ }
115
+ /** @internal */
116
+ _releaseProfile(handle) {
117
+ if (this.exports !== null)
118
+ this.exports.acv_release_profile(handle);
119
+ }
120
+ readLastError() {
121
+ const exp = this.requireExports();
122
+ return this.readResult(exp.acv_last_error());
123
+ }
124
+ requireExports() {
125
+ if (this.exports === null) {
126
+ throw new Error("Validator has been exited");
127
+ }
128
+ return this.exports;
129
+ }
130
+ writeString(str) {
131
+ const bytes = textEncoder.encode(str);
132
+ if (bytes.length === 0)
133
+ return { ptr: 0, len: 0 };
134
+ const exp = this.requireExports();
135
+ const ptr = exp.acv_malloc(bytes.length);
136
+ new Uint8Array(exp.memory.buffer, ptr, bytes.length).set(bytes);
137
+ return { ptr, len: bytes.length };
138
+ }
139
+ readResult(packed) {
140
+ const big = BigInt.asUintN(64, packed);
141
+ const ptr = Number(big >> 32n);
142
+ const len = Number(big & 0xffffffffn);
143
+ if (len === 0)
144
+ return "";
145
+ const exp = this.requireExports();
146
+ const copy = new Uint8Array(exp.memory.buffer, ptr, len).slice();
147
+ const out = textDecoder.decode(copy);
148
+ exp.acv_free(ptr);
149
+ return out;
150
+ }
151
+ free(ptr) {
152
+ if (ptr !== 0 && this.exports !== null)
153
+ this.exports.acv_free(ptr);
154
+ }
155
+ }
156
+ /**
157
+ * Opaque handle to a compiled profile. Call validate() to evaluate data
158
+ * against it; call release() (or use `using`) when done to free the Go-side
159
+ * resources. Never share a handle across validators — handles are indexed
160
+ * into one specific WASM instance's handle table and would read garbage
161
+ * in another.
162
+ */
163
+ class CompiledProfile {
164
+ validator;
165
+ handle;
166
+ released = false;
167
+ constructor(validator, handle) {
168
+ this.validator = validator;
169
+ this.handle = handle;
170
+ }
171
+ validate(data, options = {}) {
172
+ if (this.released)
173
+ throw new Error("CompiledProfile has been released");
174
+ const opts = typeof options === "boolean" ? { debug: options } : options;
175
+ return this.validator._validateCompiled(this.handle, data, opts);
176
+ }
177
+ release() {
178
+ if (this.released)
179
+ return;
180
+ this.released = true;
181
+ this.validator._releaseProfile(this.handle);
182
+ }
183
+ [Symbol.dispose]() {
184
+ this.release();
185
+ }
186
+ }
187
+
188
+ // Module-scope cache: decompress + WebAssembly.compile runs once per process.
189
+ // Subsequent create() calls only re-instantiate, which is ~10 ms vs ~150 ms.
190
+ let compiledModulePromise = null;
191
+ // ESM-compatible path resolution. Rollup emits both ESM and CJS bundles; in
192
+ // CJS `__dirname` is defined by Node directly, but in ESM we need import.meta.
193
+ // Referencing `import.meta.url` here is safe because Rollup replaces it at
194
+ // bundle time for the CJS output.
195
+ function thisDir() {
196
+ const url = import.meta.url
197
+ ?? (typeof __filename !== "undefined" ? `file://${__filename}` : undefined);
198
+ return url ? path.dirname(fileURLToPath(url)) : __dirname;
199
+ }
200
+ function getCompiledModule() {
201
+ if (compiledModulePromise === null) {
202
+ const wasmPath = path.join(thisDir(), "..", "..", "lib", "main.wasm.gz");
203
+ const compressed = fs.readFileSync(wasmPath);
204
+ const wasm = gunzipSync(compressed);
205
+ compiledModulePromise = WebAssembly.compile(wasm);
206
+ }
207
+ return compiledModulePromise;
208
+ }
209
+ class CustomValidatorFactory {
210
+ static async create() {
211
+ const wasi = new WASI({ version: "preview1", args: [], env: {} });
212
+ const module = await getCompiledModule();
213
+ const instance = await WebAssembly.instantiate(module, wasi.getImportObject());
214
+ wasi.initialize(instance); // reactor mode
215
+ return new CustomValidator(instance.exports);
216
+ }
217
+ }
218
+
219
+ export { CompiledProfile, CustomValidator, CustomValidatorFactory };
220
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../src/core/validator.ts","../../../src/platforms/node.ts"],"sourcesContent":[null,null],"names":["exports"],"mappings":";;;;;;AAEA,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE;AACrC,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE;MAExB,eAAe,CAAA;AAChB,IAAA,OAAO;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AC,QAAQ,CAAC;AAC5C,QAAA,MAAM,IAAI,GAAG,UAAU,CAAC,UAAU,CAAC;AACnC,QAAA,qBAAqB,GAAG,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC;IACrD;AACA,IAAA,OAAO,qBAAqB;AAChC;MAEa,sBAAsB,CAAA;IAC/B,aAAa,MAAM,GAAA;AACf,QAAA,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC;AACjE,QAAA,MAAM,MAAM,GAAG,MAAM,iBAAiB,EAAE;AACxC,QAAA,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC,eAAe,EAAyB,CAAC;AACrG,QAAA,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;AAC1B,QAAA,OAAO,IAAI,eAAe,CAAC,QAAQ,CAAC,OAAiC,CAAC;IAC1E;AACH;;;;"}
package/lib/main.wasm.gz CHANGED
Binary file
package/package.json CHANGED
@@ -1,20 +1,58 @@
1
1
  {
2
2
  "name": "@aml-org/amf-custom-validator",
3
- "version": "1.8.0-SNAPSHOT.3",
4
- "description": "AMF validator backed by OPA Rego",
5
- "main": "index.js",
3
+ "version": "2.0.0-alpha.1",
4
+ "description": "AMF validator backed by OPA Rego — Node and browser in one package",
5
+ "type": "module",
6
+ "main": "dist/node/index.cjs",
7
+ "module": "dist/node/index.js",
8
+ "browser": "dist/browser/index.js",
9
+ "types": "dist/node/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "node": {
13
+ "types": "./dist/node/index.d.ts",
14
+ "import": "./dist/node/index.js",
15
+ "require": "./dist/node/index.cjs"
16
+ },
17
+ "browser": {
18
+ "types": "./dist/browser/index.d.ts",
19
+ "import": "./dist/browser/index.js"
20
+ },
21
+ "default": "./dist/node/index.cjs"
22
+ },
23
+ "./package.json": "./package.json"
24
+ },
25
+ "files": [
26
+ "dist",
27
+ "lib/main.wasm.gz"
28
+ ],
6
29
  "scripts": {
7
- "test": "mocha -t 12000"
30
+ "build": "rollup -c",
31
+ "prepublishOnly": "npm run build",
32
+ "pretest": "npm run build",
33
+ "test": "npm run test:node",
34
+ "test:node": "mocha -t 12000 test/node/simple.cjs",
35
+ "test:browser": "cypress run --config-file ./test/browser/cypress.config.cjs"
8
36
  },
9
37
  "author": "Antonio Garrote",
10
38
  "license": "ISC",
11
39
  "engines": {
12
- "node": ">=16.0.0"
40
+ "node": ">=20.0.0"
13
41
  },
14
42
  "devDependencies": {
15
- "mocha": "^10.2.0"
43
+ "@rollup/plugin-commonjs": "^25.0.7",
44
+ "@rollup/plugin-node-resolve": "^15.2.3",
45
+ "@rollup/plugin-typescript": "^11.1.6",
46
+ "@types/node": "^20.11.0",
47
+ "cypress": "13.6.3",
48
+ "express": "^4.19.2",
49
+ "mocha": "^10.2.0",
50
+ "rollup": "^4.9.0",
51
+ "rollup-plugin-dts": "^6.1.0",
52
+ "tslib": "^2.6.2",
53
+ "typescript": "^5.3.3"
16
54
  },
17
55
  "dependencies": {
18
- "pako": "^2.1.0"
56
+ "@bjorn3/browser_wasi_shim": "^0.4.2"
19
57
  }
20
58
  }
package/cli.js DELETED
@@ -1,15 +0,0 @@
1
- const validator = require("./index.js");
2
- const fs = require("fs");
3
-
4
- const args = process.argv.slice(2);
5
-
6
- const profile = fs.readFileSync(process.cwd() + "/" + args[0]).toString();
7
- const data = fs.readFileSync(process.cwd() + "/" + args[1]).toString();
8
- const debug = args[2] === 'true';
9
-
10
- validator.initialize((any) => validator.validate(profile, data, debug, (result, other) => {
11
- console.log(result);
12
- validator.exit();
13
- })
14
- )
15
-