@nodora/js 0.0.5 → 0.0.6
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 +20 -20
- package/README.md +2 -2
- package/lib/index.d.ts +89 -89
- package/lib/index.js +141 -141
- package/lib/nodora.wasm.gz +0 -0
- package/lib/wasm.browser.js +13 -8
- package/lib/wasm.node.js +13 -6
- package/lib/wasm_exec.js +1 -1
- package/package.json +45 -41
- package/lib/nodora.wasm +0 -0
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Nodora
|
|
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
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nodora
|
|
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
21
|
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
# @nodora/js
|
|
2
|
-
|
|
1
|
+
# @nodora/js
|
|
2
|
+
|
|
3
3
|
JS bindings for the Nodora rule engine. This library allows you to compile and evaluate Nodora rules.
|
package/lib/index.d.ts
CHANGED
|
@@ -1,89 +1,89 @@
|
|
|
1
|
-
export type EmittedSignal = {
|
|
2
|
-
name: string;
|
|
3
|
-
args: any[];
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
export type EvaluationResult = {
|
|
7
|
-
outputs: Record<string, any>;
|
|
8
|
-
emitted_signals: EmittedSignal[];
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export interface Evaluator {
|
|
12
|
-
/**
|
|
13
|
-
* Get evaluator id
|
|
14
|
-
*/
|
|
15
|
-
getId(): number;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Register a callback for a signal
|
|
19
|
-
* @param signalName - Name of the signal to listen for
|
|
20
|
-
* @param callback - Callback function to invoke when signal is emitted
|
|
21
|
-
* @returns Evaluator instance for chaining
|
|
22
|
-
*/
|
|
23
|
-
on(signalName: string, callback: (...args: any[]) => void): Evaluator;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Evaluates a rule with the given input
|
|
27
|
-
* @param ruleName - Name of the rule to evaluate
|
|
28
|
-
* @param input - Input values for the rule
|
|
29
|
-
* @returns Evaluation result
|
|
30
|
-
*/
|
|
31
|
-
evaluate(ruleName: string, input?: Record<string, any>): EvaluationResult;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Asynchronously evaluates a rule with the given input
|
|
35
|
-
* @param ruleName - Name of the rule to evaluate
|
|
36
|
-
* @param input - Input values for the rule
|
|
37
|
-
* @returns Promise resolving to the evaluation result
|
|
38
|
-
*/
|
|
39
|
-
evaluateAsync(
|
|
40
|
-
ruleName: string,
|
|
41
|
-
input?: Record<string, any>,
|
|
42
|
-
): Promise<EvaluationResult>;
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Clean up evaluator resources
|
|
46
|
-
*/
|
|
47
|
-
destroy(): void;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Create a new evaluator
|
|
52
|
-
* @param programJSON - JSON string containing the compiled NIR program
|
|
53
|
-
* @returns Promise resolving to an Evaluator instance
|
|
54
|
-
*/
|
|
55
|
-
export function createEvaluator(programJSON: string): Promise<Evaluator>;
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Compile a rule
|
|
59
|
-
* @param src - Source code
|
|
60
|
-
* @returns Promise resolving to a JSON string containing the compiled NIR program
|
|
61
|
-
*/
|
|
62
|
-
export function compile(src: string): Promise<string>;
|
|
63
|
-
|
|
64
|
-
type BaseType = "string" | "number" | "bool" | "object" | "any";
|
|
65
|
-
type ArrayType = `array<${string}>`;
|
|
66
|
-
type UnionType = `${string}|${string}`;
|
|
67
|
-
export type Type = BaseType | ArrayType | UnionType;
|
|
68
|
-
|
|
69
|
-
export interface FunctionArgSpec {
|
|
70
|
-
name: string;
|
|
71
|
-
type: Type;
|
|
72
|
-
required?: boolean;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export interface RegisterFunctionOptions {
|
|
76
|
-
name: string;
|
|
77
|
-
namespace?: string;
|
|
78
|
-
args?: FunctionArgSpec[];
|
|
79
|
-
returnType: Type;
|
|
80
|
-
fn: (...args: any[]) => any;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Register a custom function in the registry. Must be called before compilation or evaluation.
|
|
85
|
-
* @param options - Function specification and implementation
|
|
86
|
-
*/
|
|
87
|
-
export function registerFunction(
|
|
88
|
-
options: RegisterFunctionOptions,
|
|
89
|
-
): Promise<void>;
|
|
1
|
+
export type EmittedSignal = {
|
|
2
|
+
name: string;
|
|
3
|
+
args: any[];
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
export type EvaluationResult = {
|
|
7
|
+
outputs: Record<string, any>;
|
|
8
|
+
emitted_signals: EmittedSignal[];
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export interface Evaluator {
|
|
12
|
+
/**
|
|
13
|
+
* Get evaluator id
|
|
14
|
+
*/
|
|
15
|
+
getId(): number;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Register a callback for a signal
|
|
19
|
+
* @param signalName - Name of the signal to listen for
|
|
20
|
+
* @param callback - Callback function to invoke when signal is emitted
|
|
21
|
+
* @returns Evaluator instance for chaining
|
|
22
|
+
*/
|
|
23
|
+
on(signalName: string, callback: (...args: any[]) => void): Evaluator;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Evaluates a rule with the given input
|
|
27
|
+
* @param ruleName - Name of the rule to evaluate
|
|
28
|
+
* @param input - Input values for the rule
|
|
29
|
+
* @returns Evaluation result
|
|
30
|
+
*/
|
|
31
|
+
evaluate(ruleName: string, input?: Record<string, any>): EvaluationResult;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Asynchronously evaluates a rule with the given input
|
|
35
|
+
* @param ruleName - Name of the rule to evaluate
|
|
36
|
+
* @param input - Input values for the rule
|
|
37
|
+
* @returns Promise resolving to the evaluation result
|
|
38
|
+
*/
|
|
39
|
+
evaluateAsync(
|
|
40
|
+
ruleName: string,
|
|
41
|
+
input?: Record<string, any>,
|
|
42
|
+
): Promise<EvaluationResult>;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Clean up evaluator resources
|
|
46
|
+
*/
|
|
47
|
+
destroy(): void;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Create a new evaluator
|
|
52
|
+
* @param programJSON - JSON string containing the compiled NIR program
|
|
53
|
+
* @returns Promise resolving to an Evaluator instance
|
|
54
|
+
*/
|
|
55
|
+
export function createEvaluator(programJSON: string): Promise<Evaluator>;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Compile a rule
|
|
59
|
+
* @param src - Source code
|
|
60
|
+
* @returns Promise resolving to a JSON string containing the compiled NIR program
|
|
61
|
+
*/
|
|
62
|
+
export function compile(src: string): Promise<string>;
|
|
63
|
+
|
|
64
|
+
type BaseType = "string" | "number" | "bool" | "object" | "any";
|
|
65
|
+
type ArrayType = `array<${string}>`;
|
|
66
|
+
type UnionType = `${string}|${string}`;
|
|
67
|
+
export type Type = BaseType | ArrayType | UnionType;
|
|
68
|
+
|
|
69
|
+
export interface FunctionArgSpec {
|
|
70
|
+
name: string;
|
|
71
|
+
type: Type;
|
|
72
|
+
required?: boolean;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface RegisterFunctionOptions {
|
|
76
|
+
name: string;
|
|
77
|
+
namespace?: string;
|
|
78
|
+
args?: FunctionArgSpec[];
|
|
79
|
+
returnType: Type;
|
|
80
|
+
fn: (...args: any[]) => any;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Register a custom function in the registry. Must be called before compilation or evaluation.
|
|
85
|
+
* @param options - Function specification and implementation
|
|
86
|
+
*/
|
|
87
|
+
export function registerFunction(
|
|
88
|
+
options: RegisterFunctionOptions,
|
|
89
|
+
): Promise<void>;
|
package/lib/index.js
CHANGED
|
@@ -1,141 +1,141 @@
|
|
|
1
|
-
import "./wasm_exec.js";
|
|
2
|
-
import { loadWasmBinary } from "#wasm-loader";
|
|
3
|
-
|
|
4
|
-
let wasmInstance = null;
|
|
5
|
-
let initPromise = null;
|
|
6
|
-
|
|
7
|
-
async function init() {
|
|
8
|
-
if (initPromise) return initPromise;
|
|
9
|
-
initPromise = (async () => {
|
|
10
|
-
let GoClass = globalThis.Go;
|
|
11
|
-
if (!GoClass) {
|
|
12
|
-
throw new Error("wasm_exec.js did not define Go class");
|
|
13
|
-
}
|
|
14
|
-
const go = new GoClass();
|
|
15
|
-
const wasmBytes = await loadWasmBinary();
|
|
16
|
-
|
|
17
|
-
const result = await WebAssembly.instantiate(wasmBytes, go.importObject);
|
|
18
|
-
wasmInstance = result.instance;
|
|
19
|
-
go.run(wasmInstance);
|
|
20
|
-
|
|
21
|
-
return wasmInstance;
|
|
22
|
-
})();
|
|
23
|
-
|
|
24
|
-
try {
|
|
25
|
-
return await initPromise;
|
|
26
|
-
} catch (error) {
|
|
27
|
-
initPromise = null;
|
|
28
|
-
wasmInstance = null;
|
|
29
|
-
throw new Error(`init() failed: ${error.message}`);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
class Evaluator {
|
|
34
|
-
constructor(evaluatorId) {
|
|
35
|
-
this.evaluatorId = evaluatorId;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
getId() {
|
|
39
|
-
return this.evaluatorId;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
evaluate(ruleName, input = {}) {
|
|
43
|
-
const result = globalThis.__nodoraEvaluate(
|
|
44
|
-
this.evaluatorId,
|
|
45
|
-
ruleName,
|
|
46
|
-
input,
|
|
47
|
-
);
|
|
48
|
-
if (result.error) throw new Error(result.error);
|
|
49
|
-
return result;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
async evaluateAsync(ruleName, input = {}) {
|
|
53
|
-
return this.evaluate(ruleName, input);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
on(signalName, callback) {
|
|
57
|
-
if (typeof callback !== "function") {
|
|
58
|
-
throw new Error("callback must be a function");
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
globalThis.__nodoraOnSignal(this.evaluatorId, signalName, callback);
|
|
62
|
-
return this;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
destroy() {
|
|
66
|
-
globalThis.__nodoraDestroy(this.evaluatorId);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
async function createEvaluator(programJSON) {
|
|
71
|
-
if (!wasmInstance) {
|
|
72
|
-
await init();
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const result = globalThis.__nodoraCreateEvaluator(programJSON);
|
|
76
|
-
if (result.error) {
|
|
77
|
-
throw new Error(result.error);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return new Evaluator(result);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
async function compile(src) {
|
|
84
|
-
if (!wasmInstance) {
|
|
85
|
-
await init();
|
|
86
|
-
}
|
|
87
|
-
const result = globalThis.__nodoraCompile(src);
|
|
88
|
-
if (result.error) throw result.error;
|
|
89
|
-
return result;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function assertType(x, type, err) {
|
|
93
|
-
if (!x || typeof x !== type) {
|
|
94
|
-
throw new Error(err);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
async function registerFunction({ name, namespace, args, returnType, fn }) {
|
|
99
|
-
if (!wasmInstance) await init();
|
|
100
|
-
|
|
101
|
-
assertType(name, "string", "name is required and must be a string");
|
|
102
|
-
assertType(
|
|
103
|
-
returnType,
|
|
104
|
-
"string",
|
|
105
|
-
"returnType is required and must be a string",
|
|
106
|
-
);
|
|
107
|
-
assertType(fn, "function", "fn is required and must be a function");
|
|
108
|
-
|
|
109
|
-
args = (args || []).map((arg, i) => {
|
|
110
|
-
assertType(arg, "object", `args[${i}] must be an object`);
|
|
111
|
-
assertType(
|
|
112
|
-
arg.name,
|
|
113
|
-
"string",
|
|
114
|
-
`args[${i}].name is required and must be a string`,
|
|
115
|
-
);
|
|
116
|
-
assertType(
|
|
117
|
-
arg.type,
|
|
118
|
-
"string",
|
|
119
|
-
`args[${i}].type is required and must be a string`,
|
|
120
|
-
);
|
|
121
|
-
|
|
122
|
-
return {
|
|
123
|
-
name: arg.name,
|
|
124
|
-
type: arg.type,
|
|
125
|
-
required: !!(arg.required ?? true),
|
|
126
|
-
};
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
namespace = typeof namespace === "string" ? namespace : "";
|
|
130
|
-
const spec = {
|
|
131
|
-
name,
|
|
132
|
-
namespace,
|
|
133
|
-
args: args,
|
|
134
|
-
returnType,
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
const result = globalThis.__nodoraRegisterFunction(spec, fn);
|
|
138
|
-
if (result && result.error) throw new Error(result.error);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
export { compile, createEvaluator, Evaluator, registerFunction };
|
|
1
|
+
import "./wasm_exec.js";
|
|
2
|
+
import { loadWasmBinary } from "#wasm-loader";
|
|
3
|
+
|
|
4
|
+
let wasmInstance = null;
|
|
5
|
+
let initPromise = null;
|
|
6
|
+
|
|
7
|
+
async function init() {
|
|
8
|
+
if (initPromise) return initPromise;
|
|
9
|
+
initPromise = (async () => {
|
|
10
|
+
let GoClass = globalThis.Go;
|
|
11
|
+
if (!GoClass) {
|
|
12
|
+
throw new Error("wasm_exec.js did not define Go class");
|
|
13
|
+
}
|
|
14
|
+
const go = new GoClass();
|
|
15
|
+
const wasmBytes = await loadWasmBinary();
|
|
16
|
+
|
|
17
|
+
const result = await WebAssembly.instantiate(wasmBytes, go.importObject);
|
|
18
|
+
wasmInstance = result.instance;
|
|
19
|
+
go.run(wasmInstance);
|
|
20
|
+
|
|
21
|
+
return wasmInstance;
|
|
22
|
+
})();
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
return await initPromise;
|
|
26
|
+
} catch (error) {
|
|
27
|
+
initPromise = null;
|
|
28
|
+
wasmInstance = null;
|
|
29
|
+
throw new Error(`init() failed: ${error.message}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
class Evaluator {
|
|
34
|
+
constructor(evaluatorId) {
|
|
35
|
+
this.evaluatorId = evaluatorId;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
getId() {
|
|
39
|
+
return this.evaluatorId;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
evaluate(ruleName, input = {}) {
|
|
43
|
+
const result = globalThis.__nodoraEvaluate(
|
|
44
|
+
this.evaluatorId,
|
|
45
|
+
ruleName,
|
|
46
|
+
input,
|
|
47
|
+
);
|
|
48
|
+
if (result.error) throw new Error(result.error);
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async evaluateAsync(ruleName, input = {}) {
|
|
53
|
+
return this.evaluate(ruleName, input);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
on(signalName, callback) {
|
|
57
|
+
if (typeof callback !== "function") {
|
|
58
|
+
throw new Error("callback must be a function");
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
globalThis.__nodoraOnSignal(this.evaluatorId, signalName, callback);
|
|
62
|
+
return this;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
destroy() {
|
|
66
|
+
globalThis.__nodoraDestroy(this.evaluatorId);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async function createEvaluator(programJSON) {
|
|
71
|
+
if (!wasmInstance) {
|
|
72
|
+
await init();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const result = globalThis.__nodoraCreateEvaluator(programJSON);
|
|
76
|
+
if (result.error) {
|
|
77
|
+
throw new Error(result.error);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return new Evaluator(result);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async function compile(src) {
|
|
84
|
+
if (!wasmInstance) {
|
|
85
|
+
await init();
|
|
86
|
+
}
|
|
87
|
+
const result = globalThis.__nodoraCompile(src);
|
|
88
|
+
if (result.error) throw result.error;
|
|
89
|
+
return result;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function assertType(x, type, err) {
|
|
93
|
+
if (!x || typeof x !== type) {
|
|
94
|
+
throw new Error(err);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async function registerFunction({ name, namespace, args, returnType, fn }) {
|
|
99
|
+
if (!wasmInstance) await init();
|
|
100
|
+
|
|
101
|
+
assertType(name, "string", "name is required and must be a string");
|
|
102
|
+
assertType(
|
|
103
|
+
returnType,
|
|
104
|
+
"string",
|
|
105
|
+
"returnType is required and must be a string",
|
|
106
|
+
);
|
|
107
|
+
assertType(fn, "function", "fn is required and must be a function");
|
|
108
|
+
|
|
109
|
+
args = (args || []).map((arg, i) => {
|
|
110
|
+
assertType(arg, "object", `args[${i}] must be an object`);
|
|
111
|
+
assertType(
|
|
112
|
+
arg.name,
|
|
113
|
+
"string",
|
|
114
|
+
`args[${i}].name is required and must be a string`,
|
|
115
|
+
);
|
|
116
|
+
assertType(
|
|
117
|
+
arg.type,
|
|
118
|
+
"string",
|
|
119
|
+
`args[${i}].type is required and must be a string`,
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
return {
|
|
123
|
+
name: arg.name,
|
|
124
|
+
type: arg.type,
|
|
125
|
+
required: !!(arg.required ?? true),
|
|
126
|
+
};
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
namespace = typeof namespace === "string" ? namespace : "";
|
|
130
|
+
const spec = {
|
|
131
|
+
name,
|
|
132
|
+
namespace,
|
|
133
|
+
args: args,
|
|
134
|
+
returnType,
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const result = globalThis.__nodoraRegisterFunction(spec, fn);
|
|
138
|
+
if (result && result.error) throw new Error(result.error);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export { compile, createEvaluator, Evaluator, registerFunction };
|
|
Binary file
|
package/lib/wasm.browser.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
export async function loadWasmBinary() {
|
|
2
|
-
const wasmUrl = new URL("./nodora.wasm", import.meta.url);
|
|
3
|
-
const response = await fetch(wasmUrl.href);
|
|
4
|
-
if (!response.ok) {
|
|
5
|
-
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
export async function loadWasmBinary() {
|
|
2
|
+
const wasmUrl = new URL("./nodora.wasm.gz", import.meta.url);
|
|
3
|
+
const response = await fetch(wasmUrl.href);
|
|
4
|
+
if (!response.ok) {
|
|
5
|
+
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
6
|
+
}
|
|
7
|
+
if (response.headers.get("Content-Encoding")?.includes("gzip")) {
|
|
8
|
+
return response.arrayBuffer();
|
|
9
|
+
}
|
|
10
|
+
const ds = new DecompressionStream("gzip");
|
|
11
|
+
const decompressed = response.body.pipeThrough(ds);
|
|
12
|
+
return await new Response(decompressed).arrayBuffer();
|
|
13
|
+
}
|
package/lib/wasm.node.js
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
import { readFile } from "fs/promises";
|
|
2
|
-
import { fileURLToPath } from "url";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { readFile } from "fs/promises";
|
|
2
|
+
import { fileURLToPath } from "url";
|
|
3
|
+
import { gunzip } from "zlib";
|
|
4
|
+
import { promisify } from "util";
|
|
5
|
+
|
|
6
|
+
const gunzipAsync = promisify(gunzip);
|
|
7
|
+
|
|
8
|
+
export async function loadWasmBinary() {
|
|
9
|
+
const compressed = await readFile(
|
|
10
|
+
fileURLToPath(new URL("./nodora.wasm.gz", import.meta.url))
|
|
11
|
+
);
|
|
12
|
+
return gunzipAsync(compressed);
|
|
13
|
+
}
|
package/lib/wasm_exec.js
CHANGED
package/package.json
CHANGED
|
@@ -1,41 +1,45 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@nodora/js",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "JS bindings for Nodora rule engine",
|
|
5
|
-
"main": "lib/index.js",
|
|
6
|
-
"types": "lib/index.d.ts",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"build": "make build",
|
|
9
|
-
"clean": "make clean",
|
|
10
|
-
"test": "make test",
|
|
11
|
-
"prepublishOnly": "bun run build"
|
|
12
|
-
},
|
|
13
|
-
"files": [
|
|
14
|
-
"lib"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@nodora/js",
|
|
3
|
+
"version": "0.0.6",
|
|
4
|
+
"description": "JS bindings for Nodora rule engine",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"types": "lib/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "make build",
|
|
9
|
+
"clean": "make clean",
|
|
10
|
+
"test": "make test",
|
|
11
|
+
"prepublishOnly": "bun run build"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"lib/**/*.js",
|
|
15
|
+
"lib/**/*.d.ts",
|
|
16
|
+
"lib/**/*.wasm.gz",
|
|
17
|
+
"LICENSE",
|
|
18
|
+
"README.md"
|
|
19
|
+
],
|
|
20
|
+
"keywords": [
|
|
21
|
+
"nodora",
|
|
22
|
+
"rule",
|
|
23
|
+
"policy",
|
|
24
|
+
"engine"
|
|
25
|
+
],
|
|
26
|
+
"author": "Nodora",
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://github.com/nodora-org/nodora.git"
|
|
31
|
+
},
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"types": "./lib/index.d.ts",
|
|
35
|
+
"import": "./lib/index.js",
|
|
36
|
+
"require": "./lib/index.js"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"imports": {
|
|
40
|
+
"#wasm-loader": {
|
|
41
|
+
"browser": "./lib/wasm.browser.js",
|
|
42
|
+
"default": "./lib/wasm.node.js"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
package/lib/nodora.wasm
DELETED
|
Binary file
|