logic-mesh 0.1.1 → 0.1.3

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,64 +1,107 @@
1
- [![GitHub CI](https://github.com/rracariu/logic-mesh/actions/workflows/main.yml/badge.svg)](https://github.com/rracariu/logic-mesh/actions/workflows/main.yml)
2
- [![License](https://img.shields.io/badge/License-BSD_3--Clause-blue.svg)](https://github.com/rracariu/logic-mesh/blob/master/LICENSE)
3
- [![crates.io](https://img.shields.io/crates/v/logic-mesh.svg)](https://crates.io/crates/logic-mesh)
4
-
5
1
  # Logic Mesh
6
2
  A logic engine that is fully async, dynamic, and reactive written in Rust.
3
+ The engine is compiled to WebAssembly and can be used in the browser, or in a Node.js environment.
7
4
 
8
- ## Possible applications
9
- Logic Mesh started as a hardware control engine, but the scope expanded to anything that requires a reactive and dynamic evaluation engine.
10
- It is designed to be used in a variety of applications, from hardware controls, games to web servers. It is designed to be fast, efficient, and easy to use.
11
-
12
- The included WASM support allows it to be used in web applications, with the option to use the same codebase for both the frontend and backend.
5
+ ## Applications
6
+ - Low code editors
7
+ - Interactive visualizations
13
8
 
14
9
  ## Features
15
10
  - Fully async and reactive
16
- - WASM support
17
- - Uses Tokio for async runtime
18
- - The API is simple enough to be used in a variety of applications
19
- - A low code editor is included as an example of how Logic Mesh can be used
20
- - A growing library of built-in blocks
21
11
  - Extensible with custom blocks, either in Rust or JavaScript when running in a WASM environment
22
12
 
23
13
  ## UI Editor
24
- 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
25
- a simple way to experiment with the Logic Mesh engine.
14
+ 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.
26
15
 
27
16
  ## Examples
28
17
 
29
- The following examples are written in Rust.
18
+ ### List all registered blocks
19
+ ```ts
20
+ import { initEngine } from 'logic-mesh';
21
+
22
+ // Initialize the engine
23
+ const engine = initEngine();
24
+
25
+ // List all registered blocks
26
+ const blocks = engine.listBlocks();
27
+ ```
28
+
29
+ ### Add block and wire them together
30
+ ```ts
31
+ import { initEngine } from 'logic-mesh';
32
+
33
+ // Initialize the engine
34
+ const engine = initEngine();
35
+
36
+ // Get a command instance for the engine
37
+ const command = engine.engineCommand();
38
+
39
+ // Add a SineWave block
40
+ const sineWaveId = await command.addBlock('SineWave')
41
+ // Add a StrLen block
42
+ const strLenId = await command.addBlock('StrLen')
30
43
 
31
- ```rust
32
- // Init a Add block
33
- let mut add1 = Add::new();
34
- // Init a SineWave block
35
- let mut sine1 = SineWave::new();
44
+ // Connect the blocks, sineWave -> strLen (sineWave's out port to strLen's in port)
45
+ command.createLink(sineWaveId, strLenId, 'out', 'in')
36
46
 
37
- // Se the amplitude and frequency of the sine wave
38
- sine1.amplitude.val = Some(3.into());
39
- sine1.freq.val = Some(200.into());
40
- // Connect the output of the sine wave to the first input of the add block
41
- connect_output(&mut sine1.out, add1.inputs_mut()[0]).expect("Connected");
47
+ // Start the engine (this is async)
48
+ engine.run()
49
+ ```
50
+
51
+ ### Watch for block changes
52
+ ```ts
53
+ import { initEngine } from 'logic-mesh';
54
+
55
+ // Initialize the engine
56
+ const engine = initEngine();
57
+
58
+ // Get a command instance for the engine
59
+ const command = engine.engineCommand();
60
+
61
+ // Add a SineWave block
62
+ const sineWave = await command.addBlock('SineWave')
63
+
64
+ // Create a new command instance for the watcher
65
+ const watchCommand = engine.engineCommand()
66
+ // Register a callback that will be called when the block changes
67
+ watchCommand.createWatch((notification) => {
68
+ console.log('Block changed', JSON.stringify(notification))
69
+ })
70
+
71
+ engine.run()
72
+ ```
42
73
 
43
- // Init another SineWave block
44
- let mut sine2 = SineWave::new();
45
- sine2.amplitude.val = Some(7.into());
46
- sine2.freq.val = Some(400.into());
74
+ ### Add a custom JavaScript block
75
+ ```ts
76
+ import { initEngine, JsBlock } from 'logic-mesh';
47
77
 
48
- // Connect the output of the sine wave to the second input of the add block
49
- sine2
50
- .connect_output("out", add1.inputs_mut()[1])
51
- .expect("Connected");
78
+ // Initialize the engine
79
+ const engine = initEngine();
52
80
 
53
- // Init a single threaded engine
54
- let mut engine = SingleThreadedEngine::new();
81
+ /**
82
+ * Defines a block that is implemented in JS
83
+ */
84
+ 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
55
102
 
56
- // Schedule the blocks to be run
57
- engine.schedule(add1);
58
- engine.schedule(sine1);
59
- engine.schedule(sine2);
103
+ engine.registerBlock(JsAddBlock.desc, JsAddBlock.function)
60
104
 
61
- // Run the engine
62
- engine.run().await;
105
+ engine.run()
63
106
  ```
64
107
 
package/index.d.ts ADDED
@@ -0,0 +1,225 @@
1
+ export { BlocksEngine, initEngine, EngineCommand } from './logic_mesh'
2
+
3
+ /**
4
+ * The kind of the block pin.
5
+ */
6
+ export type Kind =
7
+ | 'null'
8
+ | 'remove'
9
+ | 'marker'
10
+ | 'na'
11
+ | 'bool'
12
+ | 'number'
13
+ | 'str'
14
+ | 'uri'
15
+ | 'ref'
16
+ | 'symbol'
17
+ | 'date'
18
+ | 'time'
19
+ | 'dateTime'
20
+ | 'coord'
21
+ | 'xstr'
22
+ | 'list'
23
+ | 'dict'
24
+ | 'grid'
25
+
26
+ /**
27
+ * A block that is implemented in JS
28
+ */
29
+ export type JsBlock = {
30
+ /**
31
+ * The block description
32
+ */
33
+ desc: BlockDesc
34
+
35
+ /**
36
+ * The block function
37
+ * @param inputs The block inputs that have been set
38
+ * @returns The block outputs that have to be set
39
+ */
40
+ function: (inputs: unknown[]) => Promise<unknown[]>
41
+ }
42
+
43
+ /**
44
+ * A block pin.
45
+ *
46
+ * Pins are the inputs and outputs of a block.
47
+ */
48
+ export interface BlockPin {
49
+ /**
50
+ * The pin name
51
+ */
52
+ name: string
53
+
54
+ /**
55
+ * The pin kind
56
+ * Must be a valid haystack type kind.
57
+ * See https://project-haystack.org/doc/docHaystack/Kinds
58
+ */
59
+ kind: Kind
60
+
61
+ /**
62
+ * The pin value
63
+ * Value is a Haystack value encoded as JSON.
64
+ */
65
+ value?: unknown
66
+
67
+ /**
68
+ * True if the pin is connected to another pin.
69
+ */
70
+ isConnected?: boolean
71
+ }
72
+
73
+ /**
74
+ * Describe a block that is available in block library.
75
+ */
76
+ export interface BlockDesc {
77
+ /**
78
+ * The block name
79
+ */
80
+ name: string
81
+
82
+ /**
83
+ * The block display name
84
+ */
85
+ dis: string
86
+
87
+ /**
88
+ * The block library name
89
+ */
90
+ lib: string
91
+
92
+ /**
93
+ * The block library version
94
+ */
95
+ ver: string
96
+
97
+ /**
98
+ * The block category
99
+ */
100
+ category: string
101
+
102
+ /**
103
+ * The block documentation
104
+ */
105
+ doc: string
106
+
107
+ /**
108
+ * The block implementation
109
+ */
110
+ implementation: 'native' | 'external'
111
+
112
+ /**
113
+ * The block inputs
114
+ */
115
+ inputs: BlockPin[]
116
+
117
+ /**
118
+ * The block outputs
119
+ */
120
+ outputs: BlockPin[]
121
+ }
122
+
123
+ /**
124
+ * Notification on a block change
125
+ */
126
+ export interface BlockNotification {
127
+ /**
128
+ * The block id
129
+ */
130
+ id: string
131
+
132
+ /**
133
+ * The changes
134
+ */
135
+ changes: {
136
+ /**
137
+ * The block pin name
138
+ */
139
+ name: string
140
+ /**
141
+ * The block pin source
142
+ */
143
+ source: string
144
+ /**
145
+ * The value that was changed on this pin
146
+ */
147
+ value: {}
148
+ }[]
149
+ }
150
+
151
+ export interface LinkData {
152
+ /**
153
+ * The link id
154
+ */
155
+ id?: string
156
+
157
+ /**
158
+ * The link source block pin name
159
+ */
160
+ sourceBlockPinName: string
161
+
162
+ /**
163
+ * The link source block uuid
164
+ */
165
+ sourceBlockUuid: string
166
+
167
+ /**
168
+ * The link target block pin name
169
+ */
170
+ targetBlockPinName: string
171
+
172
+ /**
173
+ * The link target block uuid
174
+ */
175
+ targetBlockUuid: string
176
+ }
177
+
178
+ /**
179
+ * Describes a program that would be loaded in the engine.
180
+ *
181
+ * The program is a set of blocks and links between them.
182
+ * The program and the blocks have meta data that would be used in the editor
183
+ * for example to position the blocks.
184
+ */
185
+ export interface Program {
186
+ /**
187
+ * The program name
188
+ */
189
+ name: string
190
+
191
+ /**
192
+ * Optional program description
193
+ */
194
+ description?: string
195
+
196
+ /**
197
+ * Blocks used in the program
198
+ */
199
+ blocks: {
200
+ [blockUuid: string]: {
201
+ name: string
202
+ lib: string
203
+
204
+ positions: {
205
+ x: number
206
+ y: number
207
+ }
208
+
209
+ inputs?: {
210
+ [pinName: string]: { value?: unknown; isConnected?: boolean }
211
+ }
212
+
213
+ outputs?: {
214
+ [pinName: string]: { value?: unknown }
215
+ }
216
+ }
217
+ }
218
+
219
+ /**
220
+ * Links between blocks
221
+ */
222
+ links: {
223
+ [linkUuid: string]: LinkData
224
+ }
225
+ }
package/index.js ADDED
@@ -0,0 +1 @@
1
+ export { BlocksEngine, EngineCommand, initEngine } from "./logic_mesh.js";
package/logic_mesh.d.ts CHANGED
@@ -27,6 +27,22 @@ export class BlocksEngine {
27
27
  */
28
28
  listBlocks(): Array<any>;
29
29
  /**
30
+ * Register a new JS block in the registry
31
+ * The block is described by a JsBlockDesc object
32
+ *
33
+ * # Arguments
34
+ * * `desc` - The description of the block
35
+ * * `func` - The function that implements the block
36
+ *
37
+ * # Returns
38
+ * The name of the block
39
+ *
40
+ * @param {any} desc
41
+ * @param {Function} func
42
+ * @returns {string}
43
+ */
44
+ registerBlock(desc: any, func: Function): string;
45
+ /**
30
46
  * @returns {EngineCommand}
31
47
  */
32
48
  engineCommand(): EngineCommand;
@@ -47,9 +63,10 @@ export class EngineCommand {
47
63
  * Adds a block instance to the engine
48
64
  * to be immediately scheduled for execution
49
65
  * @param {string} block_name
50
- * @returns {Promise<string | undefined>}
66
+ * @param {string | undefined} block_uuid
67
+ * @returns {Promise<string>}
51
68
  */
52
- addBlock(block_name: string): Promise<string | undefined>;
69
+ addBlock(block_name: string, block_uuid?: string): Promise<string>;
53
70
  /**
54
71
  * Removes a block instance from the engine
55
72
  * to be immediately unscheduled for execution
@@ -61,9 +78,9 @@ export class EngineCommand {
61
78
  * # Returns
62
79
  * The UUID of the removed block
63
80
  * @param {string} block_uuid
64
- * @returns {Promise<string | undefined>}
81
+ * @returns {Promise<string>}
65
82
  */
66
- removeBlock(block_uuid: string): Promise<string | undefined>;
83
+ removeBlock(block_uuid: string): Promise<string>;
67
84
  /**
68
85
  * Creates a link between two blocks
69
86
  *
@@ -99,6 +116,38 @@ export class EngineCommand {
99
116
  */
100
117
  removeLink(link_uuid: string): Promise<boolean>;
101
118
  /**
119
+ * Writes the given block out with a value
120
+ *
121
+ * # Arguments
122
+ * * `block_uuid` - The UUID of the block to write to
123
+ * * `output_name` - The name of the output to write to
124
+ * * `value` - The value to write
125
+ *
126
+ * # Returns
127
+ * The block data
128
+ * @param {string} block_uuid
129
+ * @param {string} output_name
130
+ * @param {any} value
131
+ * @returns {Promise<any>}
132
+ */
133
+ writeBlockOutput(block_uuid: string, output_name: string, value: any): Promise<any>;
134
+ /**
135
+ * Writes the given block input with a value
136
+ *
137
+ * # Arguments
138
+ * * `block_uuid` - The UUID of the block to write to
139
+ * * `input_name` - The name of the input to write to
140
+ * * `value` - The value to write
141
+ *
142
+ * # Returns
143
+ * The previous value of the input
144
+ * @param {string} block_uuid
145
+ * @param {string} input_name
146
+ * @param {any} value
147
+ * @returns {Promise<any>}
148
+ */
149
+ writeBlockInput(block_uuid: string, input_name: string, value: any): Promise<any>;
150
+ /**
102
151
  * Get the current running engine program.
103
152
  * The program contains the scheduled blocks, their properties, and their links.
104
153
  * @returns {Promise<any>}
@@ -116,4 +165,21 @@ export class EngineCommand {
116
165
  * @returns {Promise<any>}
117
166
  */
118
167
  createWatch(callback: Function): Promise<any>;
168
+ /**
169
+ * Pauses the execution of the engine
170
+ * If the engine is already paused, this does nothing
171
+ * @returns {Promise<void>}
172
+ */
173
+ pauseExecution(): Promise<void>;
174
+ /**
175
+ * Resumes the execution of the engine
176
+ * If the engine is not paused, this does nothing
177
+ * @returns {Promise<void>}
178
+ */
179
+ resumeExecution(): Promise<void>;
180
+ /**
181
+ * Resets the engine state, clears all blocks and links
182
+ * @returns {Promise<void>}
183
+ */
184
+ resetEngine(): Promise<void>;
119
185
  }
package/logic_mesh_bg.js CHANGED
@@ -53,69 +53,26 @@ function addHeapObject(obj) {
53
53
  return idx;
54
54
  }
55
55
 
56
- function debugString(val) {
57
- // primitive types
58
- const type = typeof val;
59
- if (type == 'number' || type == 'boolean' || val == null) {
60
- return `${val}`;
61
- }
62
- if (type == 'string') {
63
- return `"${val}"`;
64
- }
65
- if (type == 'symbol') {
66
- const description = val.description;
67
- if (description == null) {
68
- return 'Symbol';
69
- } else {
70
- return `Symbol(${description})`;
71
- }
72
- }
73
- if (type == 'function') {
74
- const name = val.name;
75
- if (typeof name == 'string' && name.length > 0) {
76
- return `Function(${name})`;
77
- } else {
78
- return 'Function';
79
- }
80
- }
81
- // objects
82
- if (Array.isArray(val)) {
83
- const length = val.length;
84
- let debug = '[';
85
- if (length > 0) {
86
- debug += debugString(val[0]);
87
- }
88
- for(let i = 1; i < length; i++) {
89
- debug += ', ' + debugString(val[i]);
90
- }
91
- debug += ']';
92
- return debug;
93
- }
94
- // Test for built-in
95
- const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
96
- let className;
97
- if (builtInMatches.length > 1) {
98
- className = builtInMatches[1];
99
- } else {
100
- // Failed to match the standard '[object ClassName]'
101
- return toString.call(val);
102
- }
103
- if (className == 'Object') {
104
- // we're a user defined class or Object
105
- // JSON.stringify avoids problems with cycles, and is generally much
106
- // easier than looping through ownProperties of `val`.
107
- try {
108
- return 'Object(' + JSON.stringify(val) + ')';
109
- } catch (_) {
110
- return 'Object';
111
- }
56
+ function isLikeNone(x) {
57
+ return x === undefined || x === null;
58
+ }
59
+
60
+ let cachedFloat64Memory0 = null;
61
+
62
+ function getFloat64Memory0() {
63
+ if (cachedFloat64Memory0 === null || cachedFloat64Memory0.byteLength === 0) {
64
+ cachedFloat64Memory0 = new Float64Array(wasm.memory.buffer);
112
65
  }
113
- // errors
114
- if (val instanceof Error) {
115
- return `${val.name}: ${val.message}\n${val.stack}`;
66
+ return cachedFloat64Memory0;
67
+ }
68
+
69
+ let cachedInt32Memory0 = null;
70
+
71
+ function getInt32Memory0() {
72
+ if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) {
73
+ cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);
116
74
  }
117
- // TODO we could test for more things here, like `Set`s and `Map`s.
118
- return className;
75
+ return cachedInt32Memory0;
119
76
  }
120
77
 
121
78
  let WASM_VECTOR_LEN = 0;
@@ -175,13 +132,78 @@ function passStringToWasm0(arg, malloc, realloc) {
175
132
  return ptr;
176
133
  }
177
134
 
178
- let cachedInt32Memory0 = null;
135
+ let cachedBigInt64Memory0 = null;
179
136
 
180
- function getInt32Memory0() {
181
- if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) {
182
- cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);
137
+ function getBigInt64Memory0() {
138
+ if (cachedBigInt64Memory0 === null || cachedBigInt64Memory0.byteLength === 0) {
139
+ cachedBigInt64Memory0 = new BigInt64Array(wasm.memory.buffer);
183
140
  }
184
- return cachedInt32Memory0;
141
+ return cachedBigInt64Memory0;
142
+ }
143
+
144
+ function debugString(val) {
145
+ // primitive types
146
+ const type = typeof val;
147
+ if (type == 'number' || type == 'boolean' || val == null) {
148
+ return `${val}`;
149
+ }
150
+ if (type == 'string') {
151
+ return `"${val}"`;
152
+ }
153
+ if (type == 'symbol') {
154
+ const description = val.description;
155
+ if (description == null) {
156
+ return 'Symbol';
157
+ } else {
158
+ return `Symbol(${description})`;
159
+ }
160
+ }
161
+ if (type == 'function') {
162
+ const name = val.name;
163
+ if (typeof name == 'string' && name.length > 0) {
164
+ return `Function(${name})`;
165
+ } else {
166
+ return 'Function';
167
+ }
168
+ }
169
+ // objects
170
+ if (Array.isArray(val)) {
171
+ const length = val.length;
172
+ let debug = '[';
173
+ if (length > 0) {
174
+ debug += debugString(val[0]);
175
+ }
176
+ for(let i = 1; i < length; i++) {
177
+ debug += ', ' + debugString(val[i]);
178
+ }
179
+ debug += ']';
180
+ return debug;
181
+ }
182
+ // Test for built-in
183
+ const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
184
+ let className;
185
+ if (builtInMatches.length > 1) {
186
+ className = builtInMatches[1];
187
+ } else {
188
+ // Failed to match the standard '[object ClassName]'
189
+ return toString.call(val);
190
+ }
191
+ if (className == 'Object') {
192
+ // we're a user defined class or Object
193
+ // JSON.stringify avoids problems with cycles, and is generally much
194
+ // easier than looping through ownProperties of `val`.
195
+ try {
196
+ return 'Object(' + JSON.stringify(val) + ')';
197
+ } catch (_) {
198
+ return 'Object';
199
+ }
200
+ }
201
+ // errors
202
+ if (val instanceof Error) {
203
+ return `${val.name}: ${val.message}\n${val.stack}`;
204
+ }
205
+ // TODO we could test for more things here, like `Set`s and `Map`s.
206
+ return className;
185
207
  }
186
208
 
187
209
  function makeMutClosure(arg0, arg1, dtor, f) {
@@ -208,7 +230,7 @@ function makeMutClosure(arg0, arg1, dtor, f) {
208
230
 
209
231
  return real;
210
232
  }
211
- function __wbg_adapter_30(arg0, arg1, arg2) {
233
+ function __wbg_adapter_50(arg0, arg1, arg2) {
212
234
  wasm.__wbindgen_export_3(arg0, arg1, addHeapObject(arg2));
213
235
  }
214
236
 
@@ -239,7 +261,7 @@ function handleError(f, args) {
239
261
  wasm.__wbindgen_export_5(addHeapObject(e));
240
262
  }
241
263
  }
242
- function __wbg_adapter_97(arg0, arg1, arg2, arg3) {
264
+ function __wbg_adapter_149(arg0, arg1, arg2, arg3) {
243
265
  wasm.__wbindgen_export_6(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
244
266
  }
245
267
 
@@ -285,6 +307,45 @@ export class BlocksEngine {
285
307
  return takeObject(ret);
286
308
  }
287
309
  /**
310
+ * Register a new JS block in the registry
311
+ * The block is described by a JsBlockDesc object
312
+ *
313
+ * # Arguments
314
+ * * `desc` - The description of the block
315
+ * * `func` - The function that implements the block
316
+ *
317
+ * # Returns
318
+ * The name of the block
319
+ *
320
+ * @param {any} desc
321
+ * @param {Function} func
322
+ * @returns {string}
323
+ */
324
+ registerBlock(desc, func) {
325
+ let deferred2_0;
326
+ let deferred2_1;
327
+ try {
328
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
329
+ wasm.blocksengine_registerBlock(retptr, this.__wbg_ptr, addHeapObject(desc), addHeapObject(func));
330
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
331
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
332
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
333
+ var r3 = getInt32Memory0()[retptr / 4 + 3];
334
+ var ptr1 = r0;
335
+ var len1 = r1;
336
+ if (r3) {
337
+ ptr1 = 0; len1 = 0;
338
+ throw takeObject(r2);
339
+ }
340
+ deferred2_0 = ptr1;
341
+ deferred2_1 = len1;
342
+ return getStringFromWasm0(ptr1, len1);
343
+ } finally {
344
+ wasm.__wbindgen_add_to_stack_pointer(16);
345
+ wasm.__wbindgen_export_4(deferred2_0, deferred2_1, 1);
346
+ }
347
+ }
348
+ /**
288
349
  * @returns {EngineCommand}
289
350
  */
290
351
  engineCommand() {
@@ -330,12 +391,15 @@ export class EngineCommand {
330
391
  * Adds a block instance to the engine
331
392
  * to be immediately scheduled for execution
332
393
  * @param {string} block_name
333
- * @returns {Promise<string | undefined>}
394
+ * @param {string | undefined} block_uuid
395
+ * @returns {Promise<string>}
334
396
  */
335
- addBlock(block_name) {
397
+ addBlock(block_name, block_uuid) {
336
398
  const ptr0 = passStringToWasm0(block_name, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
337
399
  const len0 = WASM_VECTOR_LEN;
338
- const ret = wasm.enginecommand_addBlock(this.__wbg_ptr, ptr0, len0);
400
+ var ptr1 = isLikeNone(block_uuid) ? 0 : passStringToWasm0(block_uuid, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
401
+ var len1 = WASM_VECTOR_LEN;
402
+ const ret = wasm.enginecommand_addBlock(this.__wbg_ptr, ptr0, len0, ptr1, len1);
339
403
  return takeObject(ret);
340
404
  }
341
405
  /**
@@ -349,7 +413,7 @@ export class EngineCommand {
349
413
  * # Returns
350
414
  * The UUID of the removed block
351
415
  * @param {string} block_uuid
352
- * @returns {Promise<string | undefined>}
416
+ * @returns {Promise<string>}
353
417
  */
354
418
  removeBlock(block_uuid) {
355
419
  const ptr0 = passStringToWasm0(block_uuid, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
@@ -408,6 +472,52 @@ export class EngineCommand {
408
472
  return takeObject(ret);
409
473
  }
410
474
  /**
475
+ * Writes the given block out with a value
476
+ *
477
+ * # Arguments
478
+ * * `block_uuid` - The UUID of the block to write to
479
+ * * `output_name` - The name of the output to write to
480
+ * * `value` - The value to write
481
+ *
482
+ * # Returns
483
+ * The block data
484
+ * @param {string} block_uuid
485
+ * @param {string} output_name
486
+ * @param {any} value
487
+ * @returns {Promise<any>}
488
+ */
489
+ writeBlockOutput(block_uuid, output_name, value) {
490
+ const ptr0 = passStringToWasm0(block_uuid, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
491
+ const len0 = WASM_VECTOR_LEN;
492
+ const ptr1 = passStringToWasm0(output_name, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
493
+ const len1 = WASM_VECTOR_LEN;
494
+ const ret = wasm.enginecommand_writeBlockOutput(this.__wbg_ptr, ptr0, len0, ptr1, len1, addHeapObject(value));
495
+ return takeObject(ret);
496
+ }
497
+ /**
498
+ * Writes the given block input with a value
499
+ *
500
+ * # Arguments
501
+ * * `block_uuid` - The UUID of the block to write to
502
+ * * `input_name` - The name of the input to write to
503
+ * * `value` - The value to write
504
+ *
505
+ * # Returns
506
+ * The previous value of the input
507
+ * @param {string} block_uuid
508
+ * @param {string} input_name
509
+ * @param {any} value
510
+ * @returns {Promise<any>}
511
+ */
512
+ writeBlockInput(block_uuid, input_name, value) {
513
+ const ptr0 = passStringToWasm0(block_uuid, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
514
+ const len0 = WASM_VECTOR_LEN;
515
+ const ptr1 = passStringToWasm0(input_name, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
516
+ const len1 = WASM_VECTOR_LEN;
517
+ const ret = wasm.enginecommand_writeBlockInput(this.__wbg_ptr, ptr0, len0, ptr1, len1, addHeapObject(value));
518
+ return takeObject(ret);
519
+ }
520
+ /**
411
521
  * Get the current running engine program.
412
522
  * The program contains the scheduled blocks, their properties, and their links.
413
523
  * @returns {Promise<any>}
@@ -436,15 +546,41 @@ export class EngineCommand {
436
546
  const ret = wasm.enginecommand_createWatch(this.__wbg_ptr, addHeapObject(callback));
437
547
  return takeObject(ret);
438
548
  }
549
+ /**
550
+ * Pauses the execution of the engine
551
+ * If the engine is already paused, this does nothing
552
+ * @returns {Promise<void>}
553
+ */
554
+ pauseExecution() {
555
+ const ret = wasm.enginecommand_pauseExecution(this.__wbg_ptr);
556
+ return takeObject(ret);
557
+ }
558
+ /**
559
+ * Resumes the execution of the engine
560
+ * If the engine is not paused, this does nothing
561
+ * @returns {Promise<void>}
562
+ */
563
+ resumeExecution() {
564
+ const ret = wasm.enginecommand_resumeExecution(this.__wbg_ptr);
565
+ return takeObject(ret);
566
+ }
567
+ /**
568
+ * Resets the engine state, clears all blocks and links
569
+ * @returns {Promise<void>}
570
+ */
571
+ resetEngine() {
572
+ const ret = wasm.enginecommand_resetEngine(this.__wbg_ptr);
573
+ return takeObject(ret);
574
+ }
439
575
  }
440
576
 
441
577
  export function __wbindgen_object_drop_ref(arg0) {
442
578
  takeObject(arg0);
443
579
  };
444
580
 
445
- export function __wbindgen_error_new(arg0, arg1) {
446
- const ret = new Error(getStringFromWasm0(arg0, arg1));
447
- return addHeapObject(ret);
581
+ export function __wbindgen_is_array(arg0) {
582
+ const ret = Array.isArray(getObject(arg0));
583
+ return ret;
448
584
  };
449
585
 
450
586
  export function __wbindgen_string_new(arg0, arg1) {
@@ -452,24 +588,94 @@ export function __wbindgen_string_new(arg0, arg1) {
452
588
  return addHeapObject(ret);
453
589
  };
454
590
 
591
+ export function __wbindgen_error_new(arg0, arg1) {
592
+ const ret = new Error(getStringFromWasm0(arg0, arg1));
593
+ return addHeapObject(ret);
594
+ };
595
+
455
596
  export function __wbindgen_object_clone_ref(arg0) {
456
597
  const ret = getObject(arg0);
457
598
  return addHeapObject(ret);
458
599
  };
459
600
 
601
+ export function __wbindgen_is_undefined(arg0) {
602
+ const ret = getObject(arg0) === undefined;
603
+ return ret;
604
+ };
605
+
606
+ export function __wbindgen_in(arg0, arg1) {
607
+ const ret = getObject(arg0) in getObject(arg1);
608
+ return ret;
609
+ };
610
+
611
+ export function __wbindgen_boolean_get(arg0) {
612
+ const v = getObject(arg0);
613
+ const ret = typeof(v) === 'boolean' ? (v ? 1 : 0) : 2;
614
+ return ret;
615
+ };
616
+
617
+ export function __wbindgen_is_bigint(arg0) {
618
+ const ret = typeof(getObject(arg0)) === 'bigint';
619
+ return ret;
620
+ };
621
+
622
+ export function __wbindgen_number_get(arg0, arg1) {
623
+ const obj = getObject(arg1);
624
+ const ret = typeof(obj) === 'number' ? obj : undefined;
625
+ getFloat64Memory0()[arg0 / 8 + 1] = isLikeNone(ret) ? 0 : ret;
626
+ getInt32Memory0()[arg0 / 4 + 0] = !isLikeNone(ret);
627
+ };
628
+
629
+ export function __wbindgen_bigint_from_i64(arg0) {
630
+ const ret = arg0;
631
+ return addHeapObject(ret);
632
+ };
633
+
634
+ export function __wbindgen_jsval_eq(arg0, arg1) {
635
+ const ret = getObject(arg0) === getObject(arg1);
636
+ return ret;
637
+ };
638
+
639
+ export function __wbindgen_string_get(arg0, arg1) {
640
+ const obj = getObject(arg1);
641
+ const ret = typeof(obj) === 'string' ? obj : undefined;
642
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
643
+ var len1 = WASM_VECTOR_LEN;
644
+ getInt32Memory0()[arg0 / 4 + 1] = len1;
645
+ getInt32Memory0()[arg0 / 4 + 0] = ptr1;
646
+ };
647
+
460
648
  export function __wbindgen_is_object(arg0) {
461
649
  const val = getObject(arg0);
462
650
  const ret = typeof(val) === 'object' && val !== null;
463
651
  return ret;
464
652
  };
465
653
 
654
+ export function __wbindgen_bigint_from_u64(arg0) {
655
+ const ret = BigInt.asUintN(64, arg0);
656
+ return addHeapObject(ret);
657
+ };
658
+
659
+ export function __wbindgen_jsval_loose_eq(arg0, arg1) {
660
+ const ret = getObject(arg0) == getObject(arg1);
661
+ return ret;
662
+ };
663
+
664
+ export function __wbg_String_88810dfeb4021902(arg0, arg1) {
665
+ const ret = String(getObject(arg1));
666
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
667
+ const len1 = WASM_VECTOR_LEN;
668
+ getInt32Memory0()[arg0 / 4 + 1] = len1;
669
+ getInt32Memory0()[arg0 / 4 + 0] = ptr1;
670
+ };
671
+
466
672
  export function __wbindgen_number_new(arg0) {
467
673
  const ret = arg0;
468
674
  return addHeapObject(ret);
469
675
  };
470
676
 
471
- export function __wbindgen_bigint_from_i64(arg0) {
472
- const ret = arg0;
677
+ export function __wbg_getwithrefkey_5e6d9547403deab8(arg0, arg1) {
678
+ const ret = getObject(arg0)[getObject(arg1)];
473
679
  return addHeapObject(ret);
474
680
  };
475
681
 
@@ -583,6 +789,16 @@ export function __wbg_getRandomValues_37fa2ca9e4e07fab() { return handleError(fu
583
789
  getObject(arg0).getRandomValues(getObject(arg1));
584
790
  }, arguments) };
585
791
 
792
+ export function __wbg_get_44be0491f933a435(arg0, arg1) {
793
+ const ret = getObject(arg0)[arg1 >>> 0];
794
+ return addHeapObject(ret);
795
+ };
796
+
797
+ export function __wbg_length_fff51ee6522a1a18(arg0) {
798
+ const ret = getObject(arg0).length;
799
+ return ret;
800
+ };
801
+
586
802
  export function __wbg_new_898a68150f225f2e() {
587
803
  const ret = new Array();
588
804
  return addHeapObject(ret);
@@ -603,6 +819,36 @@ export function __wbg_new_56693dbed0c32988() {
603
819
  return addHeapObject(ret);
604
820
  };
605
821
 
822
+ export function __wbg_next_526fc47e980da008(arg0) {
823
+ const ret = getObject(arg0).next;
824
+ return addHeapObject(ret);
825
+ };
826
+
827
+ export function __wbg_next_ddb3312ca1c4e32a() { return handleError(function (arg0) {
828
+ const ret = getObject(arg0).next();
829
+ return addHeapObject(ret);
830
+ }, arguments) };
831
+
832
+ export function __wbg_done_5c1f01fb660d73b5(arg0) {
833
+ const ret = getObject(arg0).done;
834
+ return ret;
835
+ };
836
+
837
+ export function __wbg_value_1695675138684bd5(arg0) {
838
+ const ret = getObject(arg0).value;
839
+ return addHeapObject(ret);
840
+ };
841
+
842
+ export function __wbg_iterator_97f0c81209c6c35a() {
843
+ const ret = Symbol.iterator;
844
+ return addHeapObject(ret);
845
+ };
846
+
847
+ export function __wbg_get_97b561fb56f034b5() { return handleError(function (arg0, arg1) {
848
+ const ret = Reflect.get(getObject(arg0), getObject(arg1));
849
+ return addHeapObject(ret);
850
+ }, arguments) };
851
+
606
852
  export function __wbg_call_cb65541d95d71282() { return handleError(function (arg0, arg1) {
607
853
  const ret = getObject(arg0).call(getObject(arg1));
608
854
  return addHeapObject(ret);
@@ -633,20 +879,31 @@ export function __wbg_global_651f05c6a0944d1c() { return handleError(function ()
633
879
  return addHeapObject(ret);
634
880
  }, arguments) };
635
881
 
636
- export function __wbindgen_is_undefined(arg0) {
637
- const ret = getObject(arg0) === undefined;
638
- return ret;
639
- };
640
-
641
882
  export function __wbg_set_502d29070ea18557(arg0, arg1, arg2) {
642
883
  getObject(arg0)[arg1 >>> 0] = takeObject(arg2);
643
884
  };
644
885
 
886
+ export function __wbg_isArray_4c24b343cb13cfb1(arg0) {
887
+ const ret = Array.isArray(getObject(arg0));
888
+ return ret;
889
+ };
890
+
645
891
  export function __wbg_push_ca1c26067ef907ac(arg0, arg1) {
646
892
  const ret = getObject(arg0).push(getObject(arg1));
647
893
  return ret;
648
894
  };
649
895
 
896
+ export function __wbg_instanceof_ArrayBuffer_39ac22089b74fddb(arg0) {
897
+ let result;
898
+ try {
899
+ result = getObject(arg0) instanceof ArrayBuffer;
900
+ } catch {
901
+ result = false;
902
+ }
903
+ const ret = result;
904
+ return ret;
905
+ };
906
+
650
907
  export function __wbg_call_01734de55d61e11d() { return handleError(function (arg0, arg1, arg2) {
651
908
  const ret = getObject(arg0).call(getObject(arg1), getObject(arg2));
652
909
  return addHeapObject(ret);
@@ -657,6 +914,16 @@ export function __wbg_set_bedc3d02d0f05eb0(arg0, arg1, arg2) {
657
914
  return addHeapObject(ret);
658
915
  };
659
916
 
917
+ export function __wbg_isSafeInteger_bb8e18dd21c97288(arg0) {
918
+ const ret = Number.isSafeInteger(getObject(arg0));
919
+ return ret;
920
+ };
921
+
922
+ export function __wbg_entries_e51f29c7bba0c054(arg0) {
923
+ const ret = Object.entries(getObject(arg0));
924
+ return addHeapObject(ret);
925
+ };
926
+
660
927
  export function __wbg_new_43f1b47c28813cbd(arg0, arg1) {
661
928
  try {
662
929
  var state0 = {a: arg0, b: arg1};
@@ -664,7 +931,7 @@ export function __wbg_new_43f1b47c28813cbd(arg0, arg1) {
664
931
  const a = state0.a;
665
932
  state0.a = 0;
666
933
  try {
667
- return __wbg_adapter_97(a, state0.b, arg0, arg1);
934
+ return __wbg_adapter_149(a, state0.b, arg0, arg1);
668
935
  } finally {
669
936
  state0.a = a;
670
937
  }
@@ -710,6 +977,22 @@ export function __wbg_set_5cf90238115182c3(arg0, arg1, arg2) {
710
977
  getObject(arg0).set(getObject(arg1), arg2 >>> 0);
711
978
  };
712
979
 
980
+ export function __wbg_length_72e2208bbc0efc61(arg0) {
981
+ const ret = getObject(arg0).length;
982
+ return ret;
983
+ };
984
+
985
+ export function __wbg_instanceof_Uint8Array_d8d9cb2b8e8ac1d4(arg0) {
986
+ let result;
987
+ try {
988
+ result = getObject(arg0) instanceof Uint8Array;
989
+ } catch {
990
+ result = false;
991
+ }
992
+ const ret = result;
993
+ return ret;
994
+ };
995
+
713
996
  export function __wbg_newwithlength_e5d69174d6984cd7(arg0) {
714
997
  const ret = new Uint8Array(arg0 >>> 0);
715
998
  return addHeapObject(ret);
@@ -720,6 +1003,13 @@ export function __wbg_subarray_13db269f57aa838d(arg0, arg1, arg2) {
720
1003
  return addHeapObject(ret);
721
1004
  };
722
1005
 
1006
+ export function __wbindgen_bigint_get_as_i64(arg0, arg1) {
1007
+ const v = getObject(arg1);
1008
+ const ret = typeof(v) === 'bigint' ? v : undefined;
1009
+ getBigInt64Memory0()[arg0 / 8 + 1] = isLikeNone(ret) ? BigInt(0) : ret;
1010
+ getInt32Memory0()[arg0 / 4 + 0] = !isLikeNone(ret);
1011
+ };
1012
+
723
1013
  export function __wbindgen_debug_string(arg0, arg1) {
724
1014
  const ret = debugString(getObject(arg1));
725
1015
  const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
@@ -737,8 +1027,8 @@ export function __wbindgen_memory() {
737
1027
  return addHeapObject(ret);
738
1028
  };
739
1029
 
740
- export function __wbindgen_closure_wrapper1887(arg0, arg1, arg2) {
741
- const ret = makeMutClosure(arg0, arg1, 598, __wbg_adapter_30);
1030
+ export function __wbindgen_closure_wrapper2599(arg0, arg1, arg2) {
1031
+ const ret = makeMutClosure(arg0, arg1, 966, __wbg_adapter_50);
742
1032
  return addHeapObject(ret);
743
1033
  };
744
1034
 
Binary file
package/package.json CHANGED
@@ -1,32 +1,35 @@
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.1.1",
8
- "license": "BSD-3-Clause",
9
- "repository": {
10
- "type": "git",
11
- "url": "https://github.com/rracariu/logic-mesh"
12
- },
13
- "files": [
14
- "logic_mesh_bg.wasm",
15
- "logic_mesh.js",
16
- "logic_mesh_bg.js",
17
- "logic_mesh.d.ts"
18
- ],
19
- "module": "logic_mesh.js",
20
- "types": "logic_mesh.d.ts",
21
- "sideEffects": [
22
- "./logic_mesh.js",
23
- "./snippets/*"
24
- ],
25
- "keywords": [
26
- "logic",
27
- "control",
28
- "reactive",
29
- "wasm",
30
- "low-code"
31
- ]
32
- }
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.1.3",
8
+ "license": "BSD-3-Clause",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/rracariu/logic-mesh"
12
+ },
13
+ "files": [
14
+ "index.js",
15
+ "index.d.ts",
16
+ "logic_mesh_bg.wasm",
17
+ "logic_mesh.js",
18
+ "logic_mesh_bg.js",
19
+ "logic_mesh.d.ts"
20
+ ],
21
+ "module": "index.js",
22
+ "types": "index.d.ts",
23
+ "sideEffects": [
24
+ "./index.js",
25
+ "./logic_mesh.js",
26
+ "./snippets/*"
27
+ ],
28
+ "keywords": [
29
+ "logic",
30
+ "control",
31
+ "reactive",
32
+ "wasm",
33
+ "low-code"
34
+ ]
35
+ }
package/LICENSE DELETED
@@ -1,11 +0,0 @@
1
- Copyright 2023 Radu Racariu
2
-
3
- Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
-
5
- 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6
-
7
- 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8
-
9
- 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10
-
11
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.