@nodora/js 0.1.3 → 0.2.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.
- package/lib/index.d.ts +11 -5
- package/lib/index.js +5 -2
- package/lib/nodora.wasm.gz +0 -0
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -8,6 +8,11 @@ export type EvaluationResult = {
|
|
|
8
8
|
emitted_signals: EmittedSignal[];
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* A compiled Nodora ruleset, as returned by compile().
|
|
13
|
+
*/
|
|
14
|
+
export type Ruleset = Record<string, any>;
|
|
15
|
+
|
|
11
16
|
export interface Evaluator {
|
|
12
17
|
/**
|
|
13
18
|
* Get evaluator id
|
|
@@ -49,17 +54,18 @@ export interface Evaluator {
|
|
|
49
54
|
|
|
50
55
|
/**
|
|
51
56
|
* Create a new evaluator
|
|
52
|
-
* @param
|
|
57
|
+
* @param ruleset - The compiled ruleset, either as the object returned by
|
|
58
|
+
* compile() or as a JSON string
|
|
53
59
|
* @returns Promise resolving to an Evaluator instance
|
|
54
60
|
*/
|
|
55
|
-
export function createEvaluator(
|
|
61
|
+
export function createEvaluator(ruleset: Ruleset | string): Promise<Evaluator>;
|
|
56
62
|
|
|
57
63
|
/**
|
|
58
|
-
* Compile a
|
|
64
|
+
* Compile a ruleset
|
|
59
65
|
* @param src - Source code
|
|
60
|
-
* @returns Promise resolving to
|
|
66
|
+
* @returns Promise resolving to the compiled ruleset
|
|
61
67
|
*/
|
|
62
|
-
export function compile(src: string): Promise<
|
|
68
|
+
export function compile(src: string): Promise<Ruleset>;
|
|
63
69
|
|
|
64
70
|
type BaseType = "string" | "number" | "bool" | "object" | "any";
|
|
65
71
|
type ArrayType = `array<${string}>`;
|
package/lib/index.js
CHANGED
|
@@ -67,12 +67,15 @@ class Evaluator {
|
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
async function createEvaluator(
|
|
70
|
+
async function createEvaluator(ruleset) {
|
|
71
71
|
if (!wasmInstance) {
|
|
72
72
|
await init();
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
const
|
|
75
|
+
const rulesetJSON =
|
|
76
|
+
typeof ruleset === "string" ? ruleset : JSON.stringify(ruleset);
|
|
77
|
+
|
|
78
|
+
const result = globalThis.__nodoraCreateEvaluator(rulesetJSON);
|
|
76
79
|
if (result.error) {
|
|
77
80
|
throw new Error(result.error);
|
|
78
81
|
}
|
package/lib/nodora.wasm.gz
CHANGED
|
Binary file
|