logic-mesh 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/index.d.ts CHANGED
@@ -31,12 +31,13 @@ export type JsBlock = {
31
31
  * The block description
32
32
  */
33
33
  desc: BlockDesc
34
+
34
35
  /**
35
- * The block function
36
+ * An optional block function that is called when the block is executed.
36
37
  * @param inputs The block inputs that have been set
37
38
  * @returns The block outputs that have to be set
38
39
  */
39
- function: (inputs: unknown[]) => Promise<unknown[]>
40
+ function?: (inputs: unknown[]) => Promise<unknown[]>
40
41
  }
41
42
 
42
43
  /**
@@ -49,17 +50,24 @@ export interface BlockPin {
49
50
  * The pin name
50
51
  */
51
52
  name: string
53
+
52
54
  /**
53
55
  * The pin kind
54
56
  * Must be a valid haystack type kind.
55
57
  * See https://project-haystack.org/doc/docHaystack/Kinds
56
58
  */
57
59
  kind: Kind
60
+
58
61
  /**
59
62
  * The pin value
60
63
  * Value is a Haystack value encoded as JSON.
61
64
  */
62
65
  value?: unknown
66
+
67
+ /**
68
+ * True if the pin is connected to another pin.
69
+ */
70
+ isConnected?: boolean
63
71
  }
64
72
 
65
73
  /**
@@ -70,34 +78,42 @@ export interface BlockDesc {
70
78
  * The block name
71
79
  */
72
80
  name: string
81
+
73
82
  /**
74
83
  * The block display name
75
84
  */
76
85
  dis: string
86
+
77
87
  /**
78
88
  * The block library name
79
89
  */
80
90
  lib: string
91
+
81
92
  /**
82
93
  * The block library version
83
94
  */
84
95
  ver: string
96
+
85
97
  /**
86
98
  * The block category
87
99
  */
88
100
  category: string
101
+
89
102
  /**
90
103
  * The block documentation
91
104
  */
92
105
  doc: string
106
+
93
107
  /**
94
108
  * The block implementation
95
109
  */
96
110
  implementation: 'native' | 'external'
111
+
97
112
  /**
98
113
  * The block inputs
99
114
  */
100
115
  inputs: BlockPin[]
116
+
101
117
  /**
102
118
  * The block outputs
103
119
  */
@@ -131,3 +147,79 @@ export interface BlockNotification {
131
147
  value: {}
132
148
  }[]
133
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/logic_mesh.d.ts CHANGED
@@ -32,16 +32,17 @@ export class BlocksEngine {
32
32
  *
33
33
  * # Arguments
34
34
  * * `desc` - The description of the block
35
- * * `func` - The function that implements the block
35
+ * * `func` - Optional function that implements the block
36
+ * logic. If not provided, the block would do nothing.
36
37
  *
37
38
  * # Returns
38
39
  * The name of the block
39
40
  *
40
41
  * @param {any} desc
41
- * @param {Function} func
42
+ * @param {Function | undefined} func
42
43
  * @returns {string}
43
44
  */
44
- registerBlock(desc: any, func: Function): string;
45
+ registerBlock(desc: any, func?: Function): string;
45
46
  /**
46
47
  * @returns {EngineCommand}
47
48
  */
@@ -63,9 +64,10 @@ export class EngineCommand {
63
64
  * Adds a block instance to the engine
64
65
  * to be immediately scheduled for execution
65
66
  * @param {string} block_name
67
+ * @param {string | undefined} block_uuid
66
68
  * @returns {Promise<string>}
67
69
  */
68
- addBlock(block_name: string): Promise<string>;
70
+ addBlock(block_name: string, block_uuid?: string): Promise<string>;
69
71
  /**
70
72
  * Removes a block instance from the engine
71
73
  * to be immediately unscheduled for execution
@@ -131,6 +133,22 @@ export class EngineCommand {
131
133
  */
132
134
  writeBlockOutput(block_uuid: string, output_name: string, value: any): Promise<any>;
133
135
  /**
136
+ * Writes the given block input with a value
137
+ *
138
+ * # Arguments
139
+ * * `block_uuid` - The UUID of the block to write to
140
+ * * `input_name` - The name of the input to write to
141
+ * * `value` - The value to write
142
+ *
143
+ * # Returns
144
+ * The previous value of the input
145
+ * @param {string} block_uuid
146
+ * @param {string} input_name
147
+ * @param {any} value
148
+ * @returns {Promise<any>}
149
+ */
150
+ writeBlockInput(block_uuid: string, input_name: string, value: any): Promise<any>;
151
+ /**
134
152
  * Get the current running engine program.
135
153
  * The program contains the scheduled blocks, their properties, and their links.
136
154
  * @returns {Promise<any>}
@@ -148,4 +166,21 @@ export class EngineCommand {
148
166
  * @returns {Promise<any>}
149
167
  */
150
168
  createWatch(callback: Function): Promise<any>;
169
+ /**
170
+ * Pauses the execution of the engine
171
+ * If the engine is already paused, this does nothing
172
+ * @returns {Promise<void>}
173
+ */
174
+ pauseExecution(): Promise<void>;
175
+ /**
176
+ * Resumes the execution of the engine
177
+ * If the engine is not paused, this does nothing
178
+ * @returns {Promise<void>}
179
+ */
180
+ resumeExecution(): Promise<void>;
181
+ /**
182
+ * Resets the engine state, clears all blocks and links
183
+ * @returns {Promise<void>}
184
+ */
185
+ resetEngine(): Promise<void>;
151
186
  }
package/logic_mesh_bg.js CHANGED
@@ -24,6 +24,35 @@ function takeObject(idx) {
24
24
  return ret;
25
25
  }
26
26
 
27
+ const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder;
28
+
29
+ let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true });
30
+
31
+ cachedTextDecoder.decode();
32
+
33
+ let cachedUint8Memory0 = null;
34
+
35
+ function getUint8Memory0() {
36
+ if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) {
37
+ cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
38
+ }
39
+ return cachedUint8Memory0;
40
+ }
41
+
42
+ function getStringFromWasm0(ptr, len) {
43
+ ptr = ptr >>> 0;
44
+ return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
45
+ }
46
+
47
+ function addHeapObject(obj) {
48
+ if (heap_next === heap.length) heap.push(heap.length + 1);
49
+ const idx = heap_next;
50
+ heap_next = heap[idx];
51
+
52
+ heap[idx] = obj;
53
+ return idx;
54
+ }
55
+
27
56
  function isLikeNone(x) {
28
57
  return x === undefined || x === null;
29
58
  }
@@ -46,26 +75,8 @@ function getInt32Memory0() {
46
75
  return cachedInt32Memory0;
47
76
  }
48
77
 
49
- function addHeapObject(obj) {
50
- if (heap_next === heap.length) heap.push(heap.length + 1);
51
- const idx = heap_next;
52
- heap_next = heap[idx];
53
-
54
- heap[idx] = obj;
55
- return idx;
56
- }
57
-
58
78
  let WASM_VECTOR_LEN = 0;
59
79
 
60
- let cachedUint8Memory0 = null;
61
-
62
- function getUint8Memory0() {
63
- if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) {
64
- cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
65
- }
66
- return cachedUint8Memory0;
67
- }
68
-
69
80
  const lTextEncoder = typeof TextEncoder === 'undefined' ? (0, module.require)('util').TextEncoder : TextEncoder;
70
81
 
71
82
  let cachedTextEncoder = new lTextEncoder('utf-8');
@@ -121,17 +132,6 @@ function passStringToWasm0(arg, malloc, realloc) {
121
132
  return ptr;
122
133
  }
123
134
 
124
- const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder;
125
-
126
- let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true });
127
-
128
- cachedTextDecoder.decode();
129
-
130
- function getStringFromWasm0(ptr, len) {
131
- ptr = ptr >>> 0;
132
- return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
133
- }
134
-
135
135
  let cachedBigInt64Memory0 = null;
136
136
 
137
137
  function getBigInt64Memory0() {
@@ -261,7 +261,7 @@ function handleError(f, args) {
261
261
  wasm.__wbindgen_export_5(addHeapObject(e));
262
262
  }
263
263
  }
264
- function __wbg_adapter_145(arg0, arg1, arg2, arg3) {
264
+ function __wbg_adapter_149(arg0, arg1, arg2, arg3) {
265
265
  wasm.__wbindgen_export_6(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
266
266
  }
267
267
 
@@ -312,13 +312,14 @@ export class BlocksEngine {
312
312
  *
313
313
  * # Arguments
314
314
  * * `desc` - The description of the block
315
- * * `func` - The function that implements the block
315
+ * * `func` - Optional function that implements the block
316
+ * logic. If not provided, the block would do nothing.
316
317
  *
317
318
  * # Returns
318
319
  * The name of the block
319
320
  *
320
321
  * @param {any} desc
321
- * @param {Function} func
322
+ * @param {Function | undefined} func
322
323
  * @returns {string}
323
324
  */
324
325
  registerBlock(desc, func) {
@@ -326,7 +327,7 @@ export class BlocksEngine {
326
327
  let deferred2_1;
327
328
  try {
328
329
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
329
- wasm.blocksengine_registerBlock(retptr, this.__wbg_ptr, addHeapObject(desc), addHeapObject(func));
330
+ wasm.blocksengine_registerBlock(retptr, this.__wbg_ptr, addHeapObject(desc), isLikeNone(func) ? 0 : addHeapObject(func));
330
331
  var r0 = getInt32Memory0()[retptr / 4 + 0];
331
332
  var r1 = getInt32Memory0()[retptr / 4 + 1];
332
333
  var r2 = getInt32Memory0()[retptr / 4 + 2];
@@ -391,12 +392,15 @@ export class EngineCommand {
391
392
  * Adds a block instance to the engine
392
393
  * to be immediately scheduled for execution
393
394
  * @param {string} block_name
395
+ * @param {string | undefined} block_uuid
394
396
  * @returns {Promise<string>}
395
397
  */
396
- addBlock(block_name) {
398
+ addBlock(block_name, block_uuid) {
397
399
  const ptr0 = passStringToWasm0(block_name, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
398
400
  const len0 = WASM_VECTOR_LEN;
399
- const ret = wasm.enginecommand_addBlock(this.__wbg_ptr, ptr0, len0);
401
+ var ptr1 = isLikeNone(block_uuid) ? 0 : passStringToWasm0(block_uuid, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
402
+ var len1 = WASM_VECTOR_LEN;
403
+ const ret = wasm.enginecommand_addBlock(this.__wbg_ptr, ptr0, len0, ptr1, len1);
400
404
  return takeObject(ret);
401
405
  }
402
406
  /**
@@ -492,6 +496,29 @@ export class EngineCommand {
492
496
  return takeObject(ret);
493
497
  }
494
498
  /**
499
+ * Writes the given block input with a value
500
+ *
501
+ * # Arguments
502
+ * * `block_uuid` - The UUID of the block to write to
503
+ * * `input_name` - The name of the input to write to
504
+ * * `value` - The value to write
505
+ *
506
+ * # Returns
507
+ * The previous value of the input
508
+ * @param {string} block_uuid
509
+ * @param {string} input_name
510
+ * @param {any} value
511
+ * @returns {Promise<any>}
512
+ */
513
+ writeBlockInput(block_uuid, input_name, value) {
514
+ const ptr0 = passStringToWasm0(block_uuid, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
515
+ const len0 = WASM_VECTOR_LEN;
516
+ const ptr1 = passStringToWasm0(input_name, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
517
+ const len1 = WASM_VECTOR_LEN;
518
+ const ret = wasm.enginecommand_writeBlockInput(this.__wbg_ptr, ptr0, len0, ptr1, len1, addHeapObject(value));
519
+ return takeObject(ret);
520
+ }
521
+ /**
495
522
  * Get the current running engine program.
496
523
  * The program contains the scheduled blocks, their properties, and their links.
497
524
  * @returns {Promise<any>}
@@ -520,6 +547,32 @@ export class EngineCommand {
520
547
  const ret = wasm.enginecommand_createWatch(this.__wbg_ptr, addHeapObject(callback));
521
548
  return takeObject(ret);
522
549
  }
550
+ /**
551
+ * Pauses the execution of the engine
552
+ * If the engine is already paused, this does nothing
553
+ * @returns {Promise<void>}
554
+ */
555
+ pauseExecution() {
556
+ const ret = wasm.enginecommand_pauseExecution(this.__wbg_ptr);
557
+ return takeObject(ret);
558
+ }
559
+ /**
560
+ * Resumes the execution of the engine
561
+ * If the engine is not paused, this does nothing
562
+ * @returns {Promise<void>}
563
+ */
564
+ resumeExecution() {
565
+ const ret = wasm.enginecommand_resumeExecution(this.__wbg_ptr);
566
+ return takeObject(ret);
567
+ }
568
+ /**
569
+ * Resets the engine state, clears all blocks and links
570
+ * @returns {Promise<void>}
571
+ */
572
+ resetEngine() {
573
+ const ret = wasm.enginecommand_resetEngine(this.__wbg_ptr);
574
+ return takeObject(ret);
575
+ }
523
576
  }
524
577
 
525
578
  export function __wbindgen_object_drop_ref(arg0) {
@@ -531,6 +584,21 @@ export function __wbindgen_is_array(arg0) {
531
584
  return ret;
532
585
  };
533
586
 
587
+ export function __wbindgen_string_new(arg0, arg1) {
588
+ const ret = getStringFromWasm0(arg0, arg1);
589
+ return addHeapObject(ret);
590
+ };
591
+
592
+ export function __wbindgen_error_new(arg0, arg1) {
593
+ const ret = new Error(getStringFromWasm0(arg0, arg1));
594
+ return addHeapObject(ret);
595
+ };
596
+
597
+ export function __wbindgen_object_clone_ref(arg0) {
598
+ const ret = getObject(arg0);
599
+ return addHeapObject(ret);
600
+ };
601
+
534
602
  export function __wbindgen_is_undefined(arg0) {
535
603
  const ret = getObject(arg0) === undefined;
536
604
  return ret;
@@ -589,21 +657,6 @@ export function __wbindgen_bigint_from_u64(arg0) {
589
657
  return addHeapObject(ret);
590
658
  };
591
659
 
592
- export function __wbindgen_error_new(arg0, arg1) {
593
- const ret = new Error(getStringFromWasm0(arg0, arg1));
594
- return addHeapObject(ret);
595
- };
596
-
597
- export function __wbindgen_string_new(arg0, arg1) {
598
- const ret = getStringFromWasm0(arg0, arg1);
599
- return addHeapObject(ret);
600
- };
601
-
602
- export function __wbindgen_object_clone_ref(arg0) {
603
- const ret = getObject(arg0);
604
- return addHeapObject(ret);
605
- };
606
-
607
660
  export function __wbindgen_jsval_loose_eq(arg0, arg1) {
608
661
  const ret = getObject(arg0) == getObject(arg1);
609
662
  return ret;
@@ -879,7 +932,7 @@ export function __wbg_new_43f1b47c28813cbd(arg0, arg1) {
879
932
  const a = state0.a;
880
933
  state0.a = 0;
881
934
  try {
882
- return __wbg_adapter_145(a, state0.b, arg0, arg1);
935
+ return __wbg_adapter_149(a, state0.b, arg0, arg1);
883
936
  } finally {
884
937
  state0.a = a;
885
938
  }
@@ -975,8 +1028,8 @@ export function __wbindgen_memory() {
975
1028
  return addHeapObject(ret);
976
1029
  };
977
1030
 
978
- export function __wbindgen_closure_wrapper2525(arg0, arg1, arg2) {
979
- const ret = makeMutClosure(arg0, arg1, 889, __wbg_adapter_50);
1031
+ export function __wbindgen_closure_wrapper2705(arg0, arg1, arg2) {
1032
+ const ret = makeMutClosure(arg0, arg1, 983, __wbg_adapter_50);
980
1033
  return addHeapObject(ret);
981
1034
  };
982
1035
 
Binary file
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "Radu Racariu <radu.racariu@gmail.com>"
5
5
  ],
6
6
  "description": "Control logic engine using event based and reactive blocks written in Rust.",
7
- "version": "0.1.2",
7
+ "version": "0.1.4",
8
8
  "license": "BSD-3-Clause",
9
9
  "repository": {
10
10
  "type": "git",