@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 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 programJSON - JSON string containing the compiled NIR program
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(programJSON: string): Promise<Evaluator>;
61
+ export function createEvaluator(ruleset: Ruleset | string): Promise<Evaluator>;
56
62
 
57
63
  /**
58
- * Compile a rule
64
+ * Compile a ruleset
59
65
  * @param src - Source code
60
- * @returns Promise resolving to a JSON string containing the compiled NIR program
66
+ * @returns Promise resolving to the compiled ruleset
61
67
  */
62
- export function compile(src: string): Promise<string>;
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(programJSON) {
70
+ async function createEvaluator(ruleset) {
71
71
  if (!wasmInstance) {
72
72
  await init();
73
73
  }
74
74
 
75
- const result = globalThis.__nodoraCreateEvaluator(programJSON);
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
  }
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nodora/js",
3
- "version": "0.1.3",
3
+ "version": "0.2.0",
4
4
  "description": "JS bindings for Nodora rule engine",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",