@nodora/js 0.1.2 → 0.1.4
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 +10 -4
- package/lib/index.js +4 -1
- 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 program, as returned by compile().
|
|
13
|
+
*/
|
|
14
|
+
export type Program = 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 program - The compiled program, 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(program: Program | string): Promise<Evaluator>;
|
|
56
62
|
|
|
57
63
|
/**
|
|
58
64
|
* Compile a rule
|
|
59
65
|
* @param src - Source code
|
|
60
|
-
* @returns Promise resolving to
|
|
66
|
+
* @returns Promise resolving to the compiled program
|
|
61
67
|
*/
|
|
62
|
-
export function compile(src: string): Promise<
|
|
68
|
+
export function compile(src: string): Promise<Program>;
|
|
63
69
|
|
|
64
70
|
type BaseType = "string" | "number" | "bool" | "object" | "any";
|
|
65
71
|
type ArrayType = `array<${string}>`;
|
package/lib/index.js
CHANGED
|
@@ -67,11 +67,14 @@ class Evaluator {
|
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
async function createEvaluator(
|
|
70
|
+
async function createEvaluator(program) {
|
|
71
71
|
if (!wasmInstance) {
|
|
72
72
|
await init();
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
const programJSON =
|
|
76
|
+
typeof program === "string" ? program : JSON.stringify(program);
|
|
77
|
+
|
|
75
78
|
const result = globalThis.__nodoraCreateEvaluator(programJSON);
|
|
76
79
|
if (result.error) {
|
|
77
80
|
throw new Error(result.error);
|
package/lib/nodora.wasm.gz
CHANGED
|
Binary file
|