@goplasmatic/dataflow-wasm 2.0.4 → 2.0.14

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
@@ -16,9 +16,10 @@ WebAssembly bindings for [dataflow-rs](https://github.com/GoPlasmatic/dataflow-r
16
16
  ## Features
17
17
 
18
18
  - **Browser Execution** - Run dataflow-rs workflows directly in the browser
19
- - **Full Feature Parity** - Same workflow engine as the native Rust version
19
+ - **Full Feature Parity** - Same workflow engine as the native Rust version including all built-in functions
20
+ - **Built-in Functions** - parse, map, validation, publish
20
21
  - **TypeScript Support** - Full type definitions included
21
- - **Execution Tracing** - Debug workflows with step-by-step execution traces
22
+ - **Execution Tracing** - Debug workflows with step-by-step execution traces and message snapshots
22
23
 
23
24
  ## Installation
24
25
 
@@ -40,6 +41,15 @@ const workflows = [
40
41
  id: 'my-workflow',
41
42
  name: 'My Workflow',
42
43
  tasks: [
44
+ {
45
+ // Parse the raw payload string into data
46
+ id: 'parse-payload',
47
+ name: 'Parse Payload',
48
+ function: {
49
+ name: 'parse',
50
+ input: {}
51
+ }
52
+ },
43
53
  {
44
54
  id: 'task-1',
45
55
  name: 'Transform Data',
@@ -57,12 +67,13 @@ const workflows = [
57
67
  ];
58
68
 
59
69
  // Create engine
60
- const engine = new WasmEngine(workflows);
70
+ const engine = new WasmEngine(JSON.stringify(workflows));
61
71
 
62
- // Process a message
63
- const message = { data: { input: 'hello' }, metadata: {} };
64
- const result = await engine.process(message);
65
- console.log(result); // { data: { input: 'hello', output: 'hello' }, ... }
72
+ // Process a payload (raw string - parsed by the parse plugin)
73
+ const payload = '{"input": "hello"}';
74
+ const result = await engine.process(payload);
75
+ const parsed = JSON.parse(result);
76
+ console.log(parsed.context.data); // { input: 'hello', output: 'hello' }
66
77
  ```
67
78
 
68
79
  ## API
@@ -71,44 +82,66 @@ console.log(result); // { data: { input: 'hello', output: 'hello' }, ... }
71
82
 
72
83
  ```typescript
73
84
  class WasmEngine {
74
- constructor(workflows: Workflow[]);
85
+ // Create engine from JSON string of workflow definitions
86
+ constructor(workflows_json: string);
75
87
 
76
- // Process a message through all workflows
77
- process(message: Message): Promise<Message>;
88
+ // Process a raw payload string through all workflows
89
+ // The payload is stored as-is and should be parsed by the parse plugin
90
+ process(payload: string): Promise<string>;
78
91
 
79
92
  // Process with execution trace for debugging
80
- processWithTrace(message: Message): Promise<ExecutionTrace>;
93
+ process_with_trace(payload: string): Promise<string>;
94
+
95
+ // Get number of registered workflows
96
+ workflow_count(): number;
97
+
98
+ // Get list of workflow IDs as JSON array string
99
+ workflow_ids(): string;
81
100
  }
82
101
  ```
83
102
 
84
- ### Types
103
+ ### Standalone Function
85
104
 
86
105
  ```typescript
87
- interface Workflow {
88
- id: string;
89
- name: string;
90
- condition?: JsonLogicValue;
91
- tasks: Task[];
92
- }
106
+ // Process a payload through a one-off engine (convenience function)
107
+ // Use WasmEngine class for better performance when processing multiple payloads
108
+ function process_message(workflows_json: string, payload: string): Promise<string>;
109
+ ```
93
110
 
94
- interface Task {
95
- id: string;
96
- name: string;
97
- condition?: JsonLogicValue;
98
- function: FunctionConfig;
99
- }
111
+ ### Payload Handling
100
112
 
101
- interface Message {
102
- data: object;
103
- metadata: object;
104
- payload?: object;
105
- temp_data?: object;
113
+ The payload is stored as a **raw string** and is not automatically parsed. Use the `parse` plugin as the first task in your workflow to parse JSON/XML payloads into `context.data`:
114
+
115
+ ```typescript
116
+ {
117
+ id: 'parse-payload',
118
+ name: 'Parse Payload',
119
+ function: {
120
+ name: 'parse',
121
+ input: {
122
+ source: 'payload', // default
123
+ target: 'data', // default
124
+ format: 'json' // default, or 'xml'
125
+ }
126
+ }
106
127
  }
128
+ ```
107
129
 
108
- interface ExecutionTrace {
109
- steps: ExecutionStep[];
110
- initial_message: Message;
111
- final_message: Message;
130
+ ### Message Structure
131
+
132
+ The processed message has the following structure:
133
+
134
+ ```typescript
135
+ interface Message {
136
+ id: string;
137
+ payload: string; // Raw payload string
138
+ context: {
139
+ data: object; // Parsed data (populated by parse plugin)
140
+ metadata: object; // Workflow metadata
141
+ temp_data: object; // Temporary data during processing
142
+ };
143
+ audit_trail: AuditEntry[]; // Execution history
144
+ errors: ErrorInfo[]; // Any errors that occurred
112
145
  }
113
146
  ```
114
147
 
@@ -32,44 +32,47 @@ export class WasmEngine {
32
32
  * Process a payload through the engine's workflows.
33
33
  *
34
34
  * This is an async operation that returns a Promise.
35
+ * The payload is stored as a raw string and should be parsed by a parse plugin
36
+ * in the workflow if JSON parsing is needed.
35
37
  *
36
38
  * # Arguments
37
- * * `payload_json` - JSON string of the payload to process
39
+ * * `payload` - Raw string payload to process (not parsed by the engine)
38
40
  *
39
41
  * # Returns
40
42
  * A Promise that resolves to the processed message as a JSON string
41
43
  *
42
44
  * # Example
43
45
  * ```javascript
44
- * const payload = JSON.stringify({ name: "John", email: "john@example.com" });
46
+ * const payload = '{"name": "John", "email": "john@example.com"}';
45
47
  * const result = await engine.process(payload);
46
48
  * const processed = JSON.parse(result);
47
49
  * console.log(processed.context.data);
48
50
  * ```
49
51
  */
50
- process(payload_json: string): Promise<any>;
52
+ process(payload: string): Promise<any>;
51
53
  /**
52
54
  * Process a payload with step-by-step execution tracing.
53
55
  *
54
56
  * This is an async operation that returns a Promise with the execution trace.
55
57
  * The trace contains message snapshots after each step, including which
56
58
  * workflows/tasks were executed or skipped.
59
+ * The payload is stored as a raw string and should be parsed by a parse plugin.
57
60
  *
58
61
  * # Arguments
59
- * * `payload_json` - JSON string of the payload to process
62
+ * * `payload` - Raw string payload to process (not parsed by the engine)
60
63
  *
61
64
  * # Returns
62
65
  * A Promise that resolves to the execution trace as a JSON string
63
66
  *
64
67
  * # Example
65
68
  * ```javascript
66
- * const payload = JSON.stringify({ name: "John", email: "john@example.com" });
69
+ * const payload = '{"name": "John", "email": "john@example.com"}';
67
70
  * const trace = await engine.process_with_trace(payload);
68
71
  * const traceData = JSON.parse(trace);
69
72
  * console.log(traceData.steps); // Array of execution steps
70
73
  * ```
71
74
  */
72
- process_with_trace(payload_json: string): Promise<any>;
75
+ process_with_trace(payload: string): Promise<any>;
73
76
  /**
74
77
  * Get the number of workflows registered in the engine.
75
78
  */
@@ -83,24 +86,6 @@ export class WasmEngine {
83
86
  workflow_ids(): string;
84
87
  }
85
88
 
86
- /**
87
- * Create a message JSON string from data and metadata.
88
- *
89
- * # Arguments
90
- * * `data` - JSON string containing the message data (goes to context.data)
91
- * * `metadata` - JSON string containing the message metadata (goes to context.metadata)
92
- *
93
- * # Returns
94
- * JSON string representing the complete message, or an error message
95
- *
96
- * # Example
97
- * ```javascript
98
- * const message = create_message('{"name": "John"}', '{"type": "user"}');
99
- * const result = await engine.process(message);
100
- * ```
101
- */
102
- export function create_message(data: string, metadata: string): string;
103
-
104
89
  /**
105
90
  * Initialize the WASM module.
106
91
  *
@@ -114,29 +99,29 @@ export function init(): void;
114
99
  *
115
100
  * Creates an engine with the given workflows and processes a single payload.
116
101
  * Use WasmEngine class for better performance when processing multiple payloads.
102
+ * The payload is stored as a raw string and should be parsed by a parse plugin.
117
103
  *
118
104
  * # Arguments
119
105
  * * `workflows_json` - JSON string containing an array of workflow definitions
120
- * * `payload_json` - JSON string of the payload to process
106
+ * * `payload` - Raw string payload to process (not parsed by the engine)
121
107
  *
122
108
  * # Returns
123
109
  * A Promise that resolves to the processed message as a JSON string
124
110
  *
125
111
  * # Example
126
112
  * ```javascript
127
- * const payload = JSON.stringify({ name: "John", email: "john@example.com" });
113
+ * const payload = '{"name": "John", "email": "john@example.com"}';
128
114
  * const result = await process_message(workflowsJson, payload);
129
115
  * console.log(JSON.parse(result));
130
116
  * ```
131
117
  */
132
- export function process_message(workflows_json: string, payload_json: string): Promise<any>;
118
+ export function process_message(workflows_json: string, payload: string): Promise<any>;
133
119
 
134
120
  export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
135
121
 
136
122
  export interface InitOutput {
137
123
  readonly memory: WebAssembly.Memory;
138
124
  readonly __wbg_wasmengine_free: (a: number, b: number) => void;
139
- readonly create_message: (a: number, b: number, c: number, d: number) => [number, number, number, number];
140
125
  readonly init: () => void;
141
126
  readonly process_message: (a: number, b: number, c: number, d: number) => any;
142
127
  readonly wasmengine_new: (a: number, b: number) => [number, number, number];
@@ -144,9 +129,9 @@ export interface InitOutput {
144
129
  readonly wasmengine_process_with_trace: (a: number, b: number, c: number) => any;
145
130
  readonly wasmengine_workflow_count: (a: number) => number;
146
131
  readonly wasmengine_workflow_ids: (a: number) => [number, number];
147
- readonly wasm_bindgen__closure__destroy__h6c21e3ac8818b8da: (a: number, b: number) => void;
148
- readonly wasm_bindgen__convert__closures_____invoke__h6a4d7bdc6e47fe09: (a: number, b: number, c: any, d: any) => void;
149
- readonly wasm_bindgen__convert__closures_____invoke__ha914c30c59f13cef: (a: number, b: number, c: any) => void;
132
+ readonly wasm_bindgen__closure__destroy__h986238a7f20e7074: (a: number, b: number) => void;
133
+ readonly wasm_bindgen__convert__closures_____invoke__h019b9b7d5351973d: (a: number, b: number, c: any, d: any) => void;
134
+ readonly wasm_bindgen__convert__closures_____invoke__hd0a577b47a103e40: (a: number, b: number, c: any) => void;
150
135
  readonly __wbindgen_exn_store: (a: number) => void;
151
136
  readonly __externref_table_alloc: () => number;
152
137
  readonly __wbindgen_externrefs: WebAssembly.Table;
package/dataflow_wasm.js CHANGED
@@ -50,25 +50,27 @@ export class WasmEngine {
50
50
  * Process a payload through the engine's workflows.
51
51
  *
52
52
  * This is an async operation that returns a Promise.
53
+ * The payload is stored as a raw string and should be parsed by a parse plugin
54
+ * in the workflow if JSON parsing is needed.
53
55
  *
54
56
  * # Arguments
55
- * * `payload_json` - JSON string of the payload to process
57
+ * * `payload` - Raw string payload to process (not parsed by the engine)
56
58
  *
57
59
  * # Returns
58
60
  * A Promise that resolves to the processed message as a JSON string
59
61
  *
60
62
  * # Example
61
63
  * ```javascript
62
- * const payload = JSON.stringify({ name: "John", email: "john@example.com" });
64
+ * const payload = '{"name": "John", "email": "john@example.com"}';
63
65
  * const result = await engine.process(payload);
64
66
  * const processed = JSON.parse(result);
65
67
  * console.log(processed.context.data);
66
68
  * ```
67
- * @param {string} payload_json
69
+ * @param {string} payload
68
70
  * @returns {Promise<any>}
69
71
  */
70
- process(payload_json) {
71
- const ptr0 = passStringToWasm0(payload_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
72
+ process(payload) {
73
+ const ptr0 = passStringToWasm0(payload, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
72
74
  const len0 = WASM_VECTOR_LEN;
73
75
  const ret = wasm.wasmengine_process(this.__wbg_ptr, ptr0, len0);
74
76
  return ret;
@@ -79,25 +81,26 @@ export class WasmEngine {
79
81
  * This is an async operation that returns a Promise with the execution trace.
80
82
  * The trace contains message snapshots after each step, including which
81
83
  * workflows/tasks were executed or skipped.
84
+ * The payload is stored as a raw string and should be parsed by a parse plugin.
82
85
  *
83
86
  * # Arguments
84
- * * `payload_json` - JSON string of the payload to process
87
+ * * `payload` - Raw string payload to process (not parsed by the engine)
85
88
  *
86
89
  * # Returns
87
90
  * A Promise that resolves to the execution trace as a JSON string
88
91
  *
89
92
  * # Example
90
93
  * ```javascript
91
- * const payload = JSON.stringify({ name: "John", email: "john@example.com" });
94
+ * const payload = '{"name": "John", "email": "john@example.com"}';
92
95
  * const trace = await engine.process_with_trace(payload);
93
96
  * const traceData = JSON.parse(trace);
94
97
  * console.log(traceData.steps); // Array of execution steps
95
98
  * ```
96
- * @param {string} payload_json
99
+ * @param {string} payload
97
100
  * @returns {Promise<any>}
98
101
  */
99
- process_with_trace(payload_json) {
100
- const ptr0 = passStringToWasm0(payload_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
102
+ process_with_trace(payload) {
103
+ const ptr0 = passStringToWasm0(payload, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
101
104
  const len0 = WASM_VECTOR_LEN;
102
105
  const ret = wasm.wasmengine_process_with_trace(this.__wbg_ptr, ptr0, len0);
103
106
  return ret;
@@ -132,48 +135,6 @@ export class WasmEngine {
132
135
  }
133
136
  if (Symbol.dispose) WasmEngine.prototype[Symbol.dispose] = WasmEngine.prototype.free;
134
137
 
135
- /**
136
- * Create a message JSON string from data and metadata.
137
- *
138
- * # Arguments
139
- * * `data` - JSON string containing the message data (goes to context.data)
140
- * * `metadata` - JSON string containing the message metadata (goes to context.metadata)
141
- *
142
- * # Returns
143
- * JSON string representing the complete message, or an error message
144
- *
145
- * # Example
146
- * ```javascript
147
- * const message = create_message('{"name": "John"}', '{"type": "user"}');
148
- * const result = await engine.process(message);
149
- * ```
150
- * @param {string} data
151
- * @param {string} metadata
152
- * @returns {string}
153
- */
154
- export function create_message(data, metadata) {
155
- let deferred4_0;
156
- let deferred4_1;
157
- try {
158
- const ptr0 = passStringToWasm0(data, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
159
- const len0 = WASM_VECTOR_LEN;
160
- const ptr1 = passStringToWasm0(metadata, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
161
- const len1 = WASM_VECTOR_LEN;
162
- const ret = wasm.create_message(ptr0, len0, ptr1, len1);
163
- var ptr3 = ret[0];
164
- var len3 = ret[1];
165
- if (ret[3]) {
166
- ptr3 = 0; len3 = 0;
167
- throw takeFromExternrefTable0(ret[2]);
168
- }
169
- deferred4_0 = ptr3;
170
- deferred4_1 = len3;
171
- return getStringFromWasm0(ptr3, len3);
172
- } finally {
173
- wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
174
- }
175
- }
176
-
177
138
  /**
178
139
  * Initialize the WASM module.
179
140
  *
@@ -189,28 +150,29 @@ export function init() {
189
150
  *
190
151
  * Creates an engine with the given workflows and processes a single payload.
191
152
  * Use WasmEngine class for better performance when processing multiple payloads.
153
+ * The payload is stored as a raw string and should be parsed by a parse plugin.
192
154
  *
193
155
  * # Arguments
194
156
  * * `workflows_json` - JSON string containing an array of workflow definitions
195
- * * `payload_json` - JSON string of the payload to process
157
+ * * `payload` - Raw string payload to process (not parsed by the engine)
196
158
  *
197
159
  * # Returns
198
160
  * A Promise that resolves to the processed message as a JSON string
199
161
  *
200
162
  * # Example
201
163
  * ```javascript
202
- * const payload = JSON.stringify({ name: "John", email: "john@example.com" });
164
+ * const payload = '{"name": "John", "email": "john@example.com"}';
203
165
  * const result = await process_message(workflowsJson, payload);
204
166
  * console.log(JSON.parse(result));
205
167
  * ```
206
168
  * @param {string} workflows_json
207
- * @param {string} payload_json
169
+ * @param {string} payload
208
170
  * @returns {Promise<any>}
209
171
  */
210
- export function process_message(workflows_json, payload_json) {
172
+ export function process_message(workflows_json, payload) {
211
173
  const ptr0 = passStringToWasm0(workflows_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
212
174
  const len0 = WASM_VECTOR_LEN;
213
- const ptr1 = passStringToWasm0(payload_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
175
+ const ptr1 = passStringToWasm0(payload, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
214
176
  const len1 = WASM_VECTOR_LEN;
215
177
  const ret = wasm.process_message(ptr0, len0, ptr1, len1);
216
178
  return ret;
@@ -274,7 +236,7 @@ function __wbg_get_imports() {
274
236
  const a = state0.a;
275
237
  state0.a = 0;
276
238
  try {
277
- return wasm_bindgen__convert__closures_____invoke__h6a4d7bdc6e47fe09(a, state0.b, arg0, arg1);
239
+ return wasm_bindgen__convert__closures_____invoke__h019b9b7d5351973d(a, state0.b, arg0, arg1);
278
240
  } finally {
279
241
  state0.a = a;
280
242
  }
@@ -328,8 +290,8 @@ function __wbg_get_imports() {
328
290
  return ret;
329
291
  },
330
292
  __wbindgen_cast_0000000000000001: function(arg0, arg1) {
331
- // Cast intrinsic for `Closure(Closure { dtor_idx: 55, function: Function { arguments: [Externref], shim_idx: 61, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
332
- const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__h6c21e3ac8818b8da, wasm_bindgen__convert__closures_____invoke__ha914c30c59f13cef);
293
+ // Cast intrinsic for `Closure(Closure { dtor_idx: 49, function: Function { arguments: [Externref], shim_idx: 50, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
294
+ const ret = makeMutClosure(arg0, arg1, wasm.wasm_bindgen__closure__destroy__h986238a7f20e7074, wasm_bindgen__convert__closures_____invoke__hd0a577b47a103e40);
333
295
  return ret;
334
296
  },
335
297
  __wbindgen_cast_0000000000000002: function(arg0, arg1) {
@@ -353,12 +315,12 @@ function __wbg_get_imports() {
353
315
  };
354
316
  }
355
317
 
356
- function wasm_bindgen__convert__closures_____invoke__ha914c30c59f13cef(arg0, arg1, arg2) {
357
- wasm.wasm_bindgen__convert__closures_____invoke__ha914c30c59f13cef(arg0, arg1, arg2);
318
+ function wasm_bindgen__convert__closures_____invoke__hd0a577b47a103e40(arg0, arg1, arg2) {
319
+ wasm.wasm_bindgen__convert__closures_____invoke__hd0a577b47a103e40(arg0, arg1, arg2);
358
320
  }
359
321
 
360
- function wasm_bindgen__convert__closures_____invoke__h6a4d7bdc6e47fe09(arg0, arg1, arg2, arg3) {
361
- wasm.wasm_bindgen__convert__closures_____invoke__h6a4d7bdc6e47fe09(arg0, arg1, arg2, arg3);
322
+ function wasm_bindgen__convert__closures_____invoke__h019b9b7d5351973d(arg0, arg1, arg2, arg3) {
323
+ wasm.wasm_bindgen__convert__closures_____invoke__h019b9b7d5351973d(arg0, arg1, arg2, arg3);
362
324
  }
363
325
 
364
326
  const WasmEngineFinalization = (typeof FinalizationRegistry === 'undefined')
Binary file
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "type": "module",
4
4
  "author": "Plasmatic Engineering <shankar@goplasmatic.io>",
5
5
  "description": "WebAssembly bindings for dataflow-rs workflow engine",
6
- "version": "2.0.4",
6
+ "version": "2.0.14",
7
7
  "license": "Apache-2.0",
8
8
  "homepage": "https://github.com/GoPlasmatic/dataflow-rs",
9
9
  "repository": {
@@ -25,12 +25,5 @@
25
25
  "sideEffects": [
26
26
  "./snippets/*"
27
27
  ],
28
- "keywords": [
29
- "workflow",
30
- "engine",
31
- "wasm",
32
- "webassembly",
33
- "dataflow",
34
- "rust"
35
- ]
28
+ "keywords": ["workflow", "engine", "wasm", "webassembly", "dataflow", "rust"]
36
29
  }