Skip to content

Commit e84ebd4

Browse files
committed
fix: Correct WASM path in docs workflow and gitignore
1 parent bebaf22 commit e84ebd4

3 files changed

Lines changed: 150 additions & 4 deletions

File tree

.github/workflows/docs.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ jobs:
4040

4141
- name: Copy WASM to docs
4242
run: |
43-
mkdir -p docs/src/wasm-pkg
44-
cp wasm/pkg/dataflow_wasm.js docs/src/wasm-pkg/
45-
cp wasm/pkg/dataflow_wasm_bg.wasm docs/src/wasm-pkg/
43+
mkdir -p docs/src/wasm
44+
cp wasm/pkg/dataflow_wasm.js docs/src/wasm/
45+
cp wasm/pkg/dataflow_wasm_bg.wasm docs/src/wasm/
4646
4747
- name: Setup mdBook
4848
uses: peaceiris/actions-mdbook@v2

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,7 @@ Cargo.lock
2828

2929
# mdBook documentation
3030
docs/book/
31-
docs/src/wasm/
31+
32+
# WASM build artifacts (but not docs)
33+
docs/src/wasm/*.js
34+
docs/src/wasm/*.wasm

docs/src/wasm/overview.md

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
# WebAssembly Package
2+
3+
The `@goplasmatic/dataflow-wasm` package provides WebAssembly bindings for dataflow-rs, enabling you to run the same workflow engine in the browser that powers your Rust backend.
4+
5+
## Installation
6+
7+
```bash
8+
npm install @goplasmatic/dataflow-wasm
9+
```
10+
11+
## Quick Start
12+
13+
```typescript
14+
import init, { WasmEngine } from '@goplasmatic/dataflow-wasm';
15+
16+
// Initialize the WASM module (required once)
17+
await init();
18+
19+
// Define your workflows
20+
const workflows = [
21+
{
22+
id: 'my-workflow',
23+
name: 'My Workflow',
24+
tasks: [
25+
{
26+
id: 'transform',
27+
name: 'Transform Data',
28+
function: {
29+
name: 'map',
30+
input: {
31+
mappings: [
32+
{ path: 'data.output', logic: { var: 'data.input' } }
33+
]
34+
}
35+
}
36+
}
37+
]
38+
}
39+
];
40+
41+
// Create the engine
42+
const engine = new WasmEngine(workflows);
43+
44+
// Process a message
45+
const message = {
46+
data: { input: 'hello world' },
47+
metadata: {}
48+
};
49+
50+
const result = await engine.process(message);
51+
console.log(result.data.output); // 'hello world'
52+
```
53+
54+
## API Reference
55+
56+
### WasmEngine
57+
58+
The main class for executing workflows.
59+
60+
```typescript
61+
class WasmEngine {
62+
constructor(workflows: Workflow[]);
63+
64+
// Process a message through all matching workflows
65+
process(message: Message): Promise<Message>;
66+
67+
// Process with execution trace for debugging
68+
processWithTrace(message: Message): Promise<ExecutionTrace>;
69+
}
70+
```
71+
72+
### Types
73+
74+
```typescript
75+
interface Workflow {
76+
id: string;
77+
name: string;
78+
condition?: JsonLogicValue; // Optional condition to run this workflow
79+
tasks: Task[];
80+
}
81+
82+
interface Task {
83+
id: string;
84+
name: string;
85+
condition?: JsonLogicValue; // Optional condition to run this task
86+
function: FunctionConfig;
87+
}
88+
89+
interface FunctionConfig {
90+
name: string; // 'map' or 'validation'
91+
input: object;
92+
}
93+
94+
interface Message {
95+
data: object;
96+
metadata: object;
97+
payload?: object;
98+
temp_data?: object;
99+
}
100+
```
101+
102+
## Execution Tracing
103+
104+
For debugging, use `processWithTrace` to get step-by-step execution details:
105+
106+
```typescript
107+
const trace = await engine.processWithTrace(message);
108+
109+
console.log('Steps executed:', trace.steps.length);
110+
console.log('Initial message:', trace.initial_message);
111+
console.log('Final message:', trace.final_message);
112+
113+
for (const step of trace.steps) {
114+
console.log(`Task: ${step.task_name}`);
115+
console.log(`Changes: ${step.changes.length}`);
116+
}
117+
```
118+
119+
## Building from Source
120+
121+
Requirements:
122+
- Rust 1.70+
123+
- wasm-pack
124+
125+
```bash
126+
cd wasm
127+
wasm-pack build --target web --out-dir pkg
128+
```
129+
130+
The output will be in `wasm/pkg/`.
131+
132+
## Browser Compatibility
133+
134+
The WASM package works in all modern browsers that support WebAssembly:
135+
- Chrome 57+
136+
- Firefox 52+
137+
- Safari 11+
138+
- Edge 16+
139+
140+
## Next Steps
141+
142+
- [UI Package](../ui/overview.md) - React visualization components
143+
- [Built-in Functions](../built-in-functions/overview.md) - Map and validation functions

0 commit comments

Comments
 (0)