logic-mesh 0.9.0 → 1.0.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/README.md CHANGED
@@ -1,21 +1,26 @@
1
1
  # Logic Mesh
2
+
2
3
  A logic engine that is fully async, dynamic, and reactive written in Rust.
3
4
  The engine is compiled to WebAssembly and can be used in the browser, or in a Node.js environment.
4
5
 
5
6
  ## Applications
7
+
6
8
  - Low code editors
7
9
  - Interactive visualizations
8
10
 
9
11
  ## Features
12
+
10
13
  - Fully async and reactive
11
14
  - Extensible with custom blocks, either in Rust or JavaScript when running in a WASM environment
12
15
 
13
16
  ## UI Editor
17
+
14
18
  There is a sample low code editor that is built on top of Logic Mesh, which can be found [here](https://rracariu.github.io/logic-mesh/). It serves as an example of how Logic Mesh can be used, and as a simple way to experiment with the Logic Mesh engine.
15
19
 
16
20
  ## Examples
17
21
 
18
22
  ### List all registered blocks
23
+
19
24
  ```ts
20
25
  import { initEngine } from 'logic-mesh';
21
26
 
@@ -27,6 +32,7 @@ const blocks = engine.listBlocks();
27
32
  ```
28
33
 
29
34
  ### Add block and wire them together
35
+
30
36
  ```ts
31
37
  import { initEngine } from 'logic-mesh';
32
38
 
@@ -37,18 +43,19 @@ const engine = initEngine();
37
43
  const command = engine.engineCommand();
38
44
 
39
45
  // Add a SineWave block
40
- const sineWaveId = await command.addBlock('SineWave')
46
+ const sineWaveId = await command.addBlock('SineWave');
41
47
  // Add a StrLen block
42
- const strLenId = await command.addBlock('StrLen')
48
+ const strLenId = await command.addBlock('StrLen');
43
49
 
44
50
  // Connect the blocks, sineWave -> strLen (sineWave's out port to strLen's in port)
45
- command.createLink(sineWaveId, strLenId, 'out', 'in')
51
+ command.createLink(sineWaveId, strLenId, 'out', 'in');
46
52
 
47
53
  // Start the engine (this is async)
48
- engine.run()
54
+ engine.run();
49
55
  ```
50
56
 
51
57
  ### Watch for block changes
58
+
52
59
  ```ts
53
60
  import { initEngine } from 'logic-mesh';
54
61
 
@@ -59,19 +66,20 @@ const engine = initEngine();
59
66
  const command = engine.engineCommand();
60
67
 
61
68
  // Add a SineWave block
62
- const sineWave = await command.addBlock('SineWave')
69
+ const sineWave = await command.addBlock('SineWave');
63
70
 
64
71
  // Create a new command instance for the watcher
65
- const watchCommand = engine.engineCommand()
72
+ const watchCommand = engine.engineCommand();
66
73
  // Register a callback that will be called when the block changes
67
74
  watchCommand.createWatch((notification) => {
68
- console.log('Block changed', JSON.stringify(notification))
69
- })
75
+ console.log('Block changed', JSON.stringify(notification));
76
+ });
70
77
 
71
- engine.run()
78
+ engine.run();
72
79
  ```
73
80
 
74
81
  ### Add a custom JavaScript block
82
+
75
83
  ```ts
76
84
  import { initEngine, JsBlock } from 'logic-mesh';
77
85
 
@@ -82,26 +90,28 @@ const engine = initEngine();
82
90
  * Defines a block that is implemented in JS
83
91
  */
84
92
  const JsAddBlock = {
85
- // The block description
86
- desc: {
87
- name: 'AddBlock',
88
- dis: 'JS Add block',
89
- lib: 'examples',
90
- ver: '0.0.1',
91
- category: 'Docs',
92
- doc: 'Adds two numbers',
93
- implementation: 'external',
94
- inputs: [{ name: 'in1', kind: 'Number' }, { name: 'in2', kind: 'Number' }],
95
- outputs: [{ name: 'out', kind: 'Number' }],
96
- } satisfies BlockDesc,
97
- // The block implementation
98
- function: async (inputs: unknown[]) => {
99
- return (inputs[0] as number) + (inputs[1] as number)
100
- },
101
- } satisfies JsBlock
102
-
103
- engine.registerBlock(JsAddBlock.desc, JsAddBlock.function)
104
-
105
- engine.run()
93
+ // The block description
94
+ desc: {
95
+ name: 'AddBlock',
96
+ dis: 'JS Add block',
97
+ lib: 'examples',
98
+ ver: '0.0.1',
99
+ category: 'Docs',
100
+ doc: 'Adds two numbers',
101
+ implementation: 'external',
102
+ inputs: [
103
+ { name: 'in1', kind: 'Number' },
104
+ { name: 'in2', kind: 'Number' },
105
+ ],
106
+ outputs: [{ name: 'out', kind: 'Number' }],
107
+ } satisfies BlockDesc,
108
+ // The block implementation
109
+ function: async (inputs: unknown[]) => {
110
+ return (inputs[0] as number) + (inputs[1] as number);
111
+ },
112
+ } satisfies JsBlock;
113
+
114
+ engine.registerBlock(JsAddBlock.desc, JsAddBlock.function);
115
+
116
+ engine.run();
106
117
  ```
107
-
@@ -1,11 +1,11 @@
1
- import type { BlockDesc, Kind } from "./index";
2
- import type { BlocksEngine } from "./logic_mesh";
3
- import { z, type ZodType } from "zod";
1
+ import type { BlockDesc, Kind } from './index';
2
+ import type { BlocksEngine } from './logic_mesh';
3
+ import { z, type ZodType } from 'zod';
4
4
  type InferType<T> = {
5
5
  -readonly [K in keyof T]: z.infer<ExtractZodType<T[K]>>;
6
6
  };
7
7
  type ExtractZodType<T> = T extends readonly [string, infer U extends ZodType] ? U : never;
8
- type BlockDetails = Omit<BlockDesc, "inputs" | "outputs" | "implementation">;
8
+ type BlockDetails = Omit<BlockDesc, 'inputs' | 'outputs' | 'implementation'>;
9
9
  type TupleType = readonly (readonly [string, ZodType])[];
10
10
  /**
11
11
  * Defines a new block type with the specified configuration.
@@ -1,4 +1,4 @@
1
- import { ZodArray, ZodBoolean, ZodDefault, ZodEnum, ZodNumber, ZodObject, ZodOptional, ZodString, ZodUnknown, } from "zod";
1
+ import { ZodArray, ZodBoolean, ZodDefault, ZodEnum, ZodNumber, ZodObject, ZodOptional, ZodString, ZodUnknown, } from 'zod';
2
2
  /**
3
3
  * Defines a new block type with the specified configuration.
4
4
  * @param config - The block configuration, including description, input/output types, and execution logic.
@@ -13,10 +13,16 @@ export function defineBlock(config) {
13
13
  execute(inputs) {
14
14
  if (executeFn)
15
15
  return executeFn(inputs);
16
- throw new Error("Not implemented");
16
+ throw new Error('Not implemented');
17
17
  }
18
18
  static register(engine) {
19
- const executor = new this();
19
+ // `this` here is the anonymous class produced by `defineBlock`.
20
+ // Cast to its construct signature so we can `new` it without
21
+ // falling back to `any` — the runtime shape matches the
22
+ // `TypedBlock<I, O>` instance type by construction (we just
23
+ // declared the class as `class extends TypedBlock<I, O>`).
24
+ const Ctor = this;
25
+ const executor = new Ctor();
20
26
  if (executeFn) {
21
27
  engine.registerBlock(executor.desc, () => executor.executeImpl.bind(executor));
22
28
  }
@@ -38,7 +44,7 @@ export class TypedBlock {
38
44
  this.outputs = outputs.map(([name, _]) => name);
39
45
  this.outputTypes = outputs.map(([, type]) => type);
40
46
  const blockDescription = desc;
41
- blockDescription.implementation = "external";
47
+ blockDescription.implementation = 'external';
42
48
  blockDescription.inputs = this.inputs.map((name, i) => ({
43
49
  name,
44
50
  kind: this.zodToKind(this.inputTypes.at(i)),
@@ -50,15 +56,15 @@ export class TypedBlock {
50
56
  this.desc = blockDescription;
51
57
  }
52
58
  execute([..._inputs]) {
53
- throw new Error("Not implemented");
59
+ throw new Error('Not implemented');
54
60
  }
55
61
  static register(_engine) {
56
- throw new Error("Not implemented");
62
+ throw new Error('Not implemented');
57
63
  }
58
64
  async executeImpl(inputs) {
59
65
  // Validate inputs
60
66
  if (inputs.length !== this.inputs.length) {
61
- throw new Error("Invalid number of inputs");
67
+ throw new Error('Invalid number of inputs');
62
68
  }
63
69
  this.inputs.map((_, i) => {
64
70
  const val = inputs.at(i);
@@ -71,7 +77,7 @@ export class TypedBlock {
71
77
  }
72
78
  // Validate outputs
73
79
  if (res.length !== this.outputs.length) {
74
- throw new Error("Invalid number of outputs");
80
+ throw new Error('Invalid number of outputs');
75
81
  }
76
82
  this.outputs.forEach((_, i) => {
77
83
  const val = res.at(i);
@@ -82,31 +88,31 @@ export class TypedBlock {
82
88
  }
83
89
  zodToKind(kind) {
84
90
  if (kind === undefined) {
85
- throw new Error("Unspecified kind");
91
+ throw new Error('Unspecified kind');
86
92
  }
87
93
  if (kind instanceof ZodOptional) {
88
94
  kind = kind.def.innerType;
89
95
  }
90
96
  if (kind instanceof ZodBoolean) {
91
- return "bool";
97
+ return 'bool';
92
98
  }
93
99
  else if (kind instanceof ZodNumber) {
94
- return "number";
100
+ return 'number';
95
101
  }
96
102
  else if (kind instanceof ZodString) {
97
- return "str";
103
+ return 'str';
98
104
  }
99
105
  else if (kind instanceof ZodEnum) {
100
- return "str";
106
+ return 'str';
101
107
  }
102
108
  else if (kind instanceof ZodArray) {
103
- return "list";
109
+ return 'list';
104
110
  }
105
111
  else if (kind instanceof ZodObject) {
106
- return "dict";
112
+ return 'dict';
107
113
  }
108
114
  else if (kind instanceof ZodUnknown) {
109
- return "null";
115
+ return 'null';
110
116
  }
111
117
  else if (kind instanceof ZodDefault) {
112
118
  return this.zodToKind(kind.def.innerType);
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- export { BlocksEngine, initEngine, EngineCommand } from "./logic_mesh.js";
2
- export { defineBlock, TypedBlock } from "./TypedBlock";
1
+ export { BlocksEngine, initEngine, EngineCommand } from './logic_mesh.js';
2
+ export { defineBlock, TypedBlock } from './TypedBlock';
3
3
  /**
4
4
  * The kind of the block pin.
5
5
  */
6
- export type Kind = "null" | "remove" | "marker" | "na" | "bool" | "number" | "str" | "uri" | "ref" | "symbol" | "date" | "time" | "dateTime" | "coord" | "xstr" | "list" | "dict" | "grid";
6
+ export type Kind = 'null' | 'remove' | 'marker' | 'na' | 'bool' | 'number' | 'str' | 'uri' | 'ref' | 'symbol' | 'date' | 'time' | 'dateTime' | 'coord' | 'xstr' | 'list' | 'dict' | 'grid';
7
7
  /**
8
8
  * A block that is implemented in JS
9
9
  */
@@ -80,7 +80,7 @@ export interface BlockDesc {
80
80
  /**
81
81
  * The block implementation
82
82
  */
83
- implementation: "native" | "external";
83
+ implementation: 'native' | 'external';
84
84
  /**
85
85
  * The block inputs
86
86
  */
@@ -97,7 +97,7 @@ export interface BlockDesc {
97
97
  *
98
98
  * Default: 'change'
99
99
  */
100
- runCondition?: "change" | "always";
100
+ runCondition?: 'change' | 'always';
101
101
  }
102
102
  /**
103
103
  * Notification on a block change
@@ -120,15 +120,17 @@ export interface BlockNotification {
120
120
  */
121
121
  source: string;
122
122
  /**
123
- * The value that was changed on this pin
123
+ * The value that was changed on this pin. The shape is
124
+ * Haystack-encoded JSON; consumers narrow as needed (e.g.
125
+ * `typeof value === 'number'` for a numeric pin).
124
126
  */
125
- value: {};
127
+ value: unknown;
126
128
  }[];
127
129
  /**
128
130
  * The block's operational state at the time of the notification.
129
131
  * Drives fault visualization on the UI.
130
132
  */
131
- state: "running" | "fault" | "disabled" | "terminated";
133
+ state: 'running' | 'fault' | 'disabled' | 'terminated';
132
134
  /**
133
135
  * Optional reason associated with `state === "fault"`.
134
136
  */
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export { BlocksEngine, initEngine, EngineCommand } from "./logic_mesh.js";
2
- export { defineBlock, TypedBlock } from "./TypedBlock";
1
+ export { BlocksEngine, initEngine, EngineCommand } from './logic_mesh.js';
2
+ export { defineBlock, TypedBlock } from './TypedBlock';
@@ -597,7 +597,7 @@ export function __wbg_new_d8dfd33fa007511d(arg0, arg1) {
597
597
  const a = state0.a;
598
598
  state0.a = 0;
599
599
  try {
600
- return __wasm_bindgen_func_elem_11010(a, state0.b, arg0, arg1);
600
+ return __wasm_bindgen_func_elem_10966(a, state0.b, arg0, arg1);
601
601
  } finally {
602
602
  state0.a = a;
603
603
  }
@@ -615,7 +615,7 @@ export function __wbg_new_typed_c072c4ce9a2a0cdf(arg0, arg1) {
615
615
  const a = state0.a;
616
616
  state0.a = 0;
617
617
  try {
618
- return __wasm_bindgen_func_elem_11010(a, state0.b, arg0, arg1);
618
+ return __wasm_bindgen_func_elem_10966(a, state0.b, arg0, arg1);
619
619
  } finally {
620
620
  state0.a = a;
621
621
  }
@@ -656,7 +656,7 @@ export function __wbg_resolve_d17db9352f5a220e(arg0) {
656
656
  const ret = Promise.resolve(getObject(arg0));
657
657
  return addHeapObject(ret);
658
658
  }
659
- export function __wbg_setTimeout_13f9945f0b4d57b2(arg0, arg1) {
659
+ export function __wbg_setTimeout_8c38500cf1446a8c(arg0, arg1) {
660
660
  setTimeout(getObject(arg0), arg1);
661
661
  }
662
662
  export function __wbg_set_6be42768c690e380(arg0, arg1, arg2) {
@@ -708,8 +708,8 @@ export function __wbg_warn_0a0181da0201bf15(arg0, arg1) {
708
708
  console.warn(getStringFromWasm0(arg0, arg1));
709
709
  }
710
710
  export function __wbindgen_cast_0000000000000001(arg0, arg1) {
711
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 2012, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
712
- const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_11016);
711
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 2025, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
712
+ const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_10972);
713
713
  return addHeapObject(ret);
714
714
  }
715
715
  export function __wbindgen_cast_0000000000000002(arg0) {
@@ -739,10 +739,10 @@ export function __wbindgen_object_clone_ref(arg0) {
739
739
  export function __wbindgen_object_drop_ref(arg0) {
740
740
  takeObject(arg0);
741
741
  }
742
- function __wasm_bindgen_func_elem_11016(arg0, arg1, arg2) {
742
+ function __wasm_bindgen_func_elem_10972(arg0, arg1, arg2) {
743
743
  try {
744
744
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
745
- wasm.__wasm_bindgen_func_elem_11016(retptr, arg0, arg1, addHeapObject(arg2));
745
+ wasm.__wasm_bindgen_func_elem_10972(retptr, arg0, arg1, addHeapObject(arg2));
746
746
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
747
747
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
748
748
  if (r1) {
@@ -753,8 +753,8 @@ function __wasm_bindgen_func_elem_11016(arg0, arg1, arg2) {
753
753
  }
754
754
  }
755
755
 
756
- function __wasm_bindgen_func_elem_11010(arg0, arg1, arg2, arg3) {
757
- wasm.__wasm_bindgen_func_elem_11010(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
756
+ function __wasm_bindgen_func_elem_10966(arg0, arg1, arg2, arg3) {
757
+ wasm.__wasm_bindgen_func_elem_10966(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
758
758
  }
759
759
 
760
760
  const BlocksEngineFinalization = (typeof FinalizationRegistry === 'undefined')
Binary file
@@ -26,8 +26,8 @@ export const enginecommand_writeBlockOutput: (a: number, b: number, c: number, d
26
26
  export const initEngine: (a: number) => number;
27
27
  export const start: () => void;
28
28
  export const init_panic_hook: () => void;
29
- export const __wasm_bindgen_func_elem_11016: (a: number, b: number, c: number, d: number) => void;
30
- export const __wasm_bindgen_func_elem_11010: (a: number, b: number, c: number, d: number) => void;
29
+ export const __wasm_bindgen_func_elem_10972: (a: number, b: number, c: number, d: number) => void;
30
+ export const __wasm_bindgen_func_elem_10966: (a: number, b: number, c: number, d: number) => void;
31
31
  export const __wbindgen_export: (a: number, b: number) => number;
32
32
  export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
33
33
  export const __wbindgen_export3: (a: number) => void;
package/package.json CHANGED
@@ -1,49 +1,59 @@
1
1
  {
2
- "name": "logic-mesh",
3
- "collaborators": [
4
- "Radu Racariu <radu.racariu@gmail.com>"
5
- ],
6
- "description": "Control logic engine using event based and reactive blocks written in Rust.",
7
- "version": "0.9.0",
8
- "license": "BSD-3-Clause",
9
- "repository": {
10
- "type": "git",
11
- "url": "https://github.com/rracariu/logic-mesh"
12
- },
13
- "scripts": {
14
- "build": "wasm-pack build --release --out-dir web/packages/logic-mesh/pkg ../../.. && npm run build:prepare && tsc",
15
- "build:dev": "wasm-pack build --dev --out-dir web/packages/logic-mesh/pkg ../../.. && npm run build:prepare && tsc",
16
- "build:prepare": "mkdir -p dist && mv ./pkg/*.js ./pkg/*.ts ./pkg/*.wasm ./dist/ && npm version $(node -p \"require('./pkg/package.json').version\") --allow-same-version && rm -rf ./pkg",
17
- "test": "vitest run",
18
- "test:watch": "vitest"
19
- },
20
- "files": [
21
- "dist/"
22
- ],
23
- "module": "dist/index.js",
24
- "types": "./dist/index.d.ts",
25
- "exports": {
26
- ".": {
27
- "types": "./dist/index.d.ts",
28
- "import": "./dist/index.js"
29
- }
30
- },
31
- "sideEffects": [
32
- "./dist/index.js",
33
- "./dist/logic_mesh.js"
34
- ],
35
- "dependencies": {
36
- "zod": "^4.4.3"
37
- },
38
- "devDependencies": {
39
- "typescript": "^6.0.3",
40
- "vitest": "^4.1.6"
41
- },
42
- "keywords": [
43
- "dataflow",
44
- "control",
45
- "reactive",
46
- "wasm",
47
- "low-code"
48
- ]
2
+ "name": "logic-mesh",
3
+ "collaborators": [
4
+ "Radu Racariu <radu.racariu@gmail.com>"
5
+ ],
6
+ "description": "Control logic engine using event based and reactive blocks written in Rust.",
7
+ "version": "1.0.0",
8
+ "type": "module",
9
+ "license": "BSD-3-Clause",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/rracariu/logic-mesh"
13
+ },
14
+ "scripts": {
15
+ "build": "wasm-pack build --release --out-dir web/packages/logic-mesh/pkg ../../.. && npm run build:prepare && tsc",
16
+ "build:dev": "wasm-pack build --dev --out-dir web/packages/logic-mesh/pkg ../../.. && npm run build:prepare && tsc",
17
+ "build:prepare": "mkdir -p dist && mv ./pkg/*.js ./pkg/*.ts ./pkg/*.wasm ./dist/ && npm version $(node -p \"require('./pkg/package.json').version\") --allow-same-version && rm -rf ./pkg",
18
+ "lint": "eslint .",
19
+ "format": "prettier --write .",
20
+ "format:check": "prettier --check .",
21
+ "test": "vitest run",
22
+ "test:watch": "vitest"
23
+ },
24
+ "files": [
25
+ "dist/"
26
+ ],
27
+ "module": "dist/index.js",
28
+ "types": "./dist/index.d.ts",
29
+ "exports": {
30
+ ".": {
31
+ "types": "./dist/index.d.ts",
32
+ "import": "./dist/index.js"
33
+ }
34
+ },
35
+ "sideEffects": [
36
+ "./dist/index.js",
37
+ "./dist/logic_mesh.js"
38
+ ],
39
+ "dependencies": {
40
+ "zod": "^4.4.3"
41
+ },
42
+ "devDependencies": {
43
+ "@eslint/js": "^10.0.1",
44
+ "eslint": "^10.4.0",
45
+ "eslint-config-prettier": "^9",
46
+ "globals": "^15",
47
+ "prettier": "^3",
48
+ "typescript": "^6.0.3",
49
+ "typescript-eslint": "^8",
50
+ "vitest": "^4.1.6"
51
+ },
52
+ "keywords": [
53
+ "dataflow",
54
+ "control",
55
+ "reactive",
56
+ "wasm",
57
+ "low-code"
58
+ ]
49
59
  }