@ironflow/node 0.1.0-test.2 → 0.2.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,6 +1,6 @@
1
1
  # @ironflow/node
2
2
 
3
- Node.js SDK for [Ironflow](https://github.com/anthropics/ironflow) workflow engine. Provides workers, serve handlers, and step execution for serverless and long-running functions.
3
+ Node.js SDK for [Ironflow](https://github.com/sahina/ironflow), an event-driven backend platform. Provides workers, serve handlers, and step execution for serverless and long-running functions.
4
4
 
5
5
  ## Installation
6
6
 
@@ -56,7 +56,7 @@ import { createWorker } from '@ironflow/node';
56
56
  const worker = createWorker({
57
57
  serverUrl: 'http://localhost:9123',
58
58
  functions: [processOrder],
59
- maxConcurrentJobs: 4,
59
+ maxConcurrentJobs: 10,
60
60
  });
61
61
 
62
62
  await worker.start();
@@ -80,8 +80,8 @@ await worker.start();
80
80
  | `step.run(id, fn)` | Execute memoized step |
81
81
  | `step.sleep(id, duration)` | Durable sleep |
82
82
  | `step.waitForEvent(id, options)` | Wait for external event |
83
- | `step.parallel(steps)` | Execute steps in parallel |
84
- | `step.map(id, items, fn)` | Map over items in parallel |
83
+ | `step.parallel(name, branches, options?)` | Execute branches in parallel |
84
+ | `step.map(name, items, fn, options?)` | Map over items in parallel |
85
85
 
86
86
  ## Environment Variables
87
87
 
@@ -0,0 +1,296 @@
1
+ /**
2
+ * Ironflow Node.js Client
3
+ *
4
+ * HTTP client for interacting with the Ironflow server.
5
+ * Provides methods for registering functions, triggering events, and managing runs.
6
+ */
7
+ import { type RunStatus, type Trigger, type ExecutionMode, type RetryConfig, type ConcurrencyConfig, type AppendEventInput, type AppendOptions, type AppendResult, type ReadStreamOptions, type StreamEvent, type StreamInfo } from "@ironflow/core";
8
+ import { KVClient } from "./kv.js";
9
+ import { ConfigClient } from "./config-client.js";
10
+ /**
11
+ * Configuration for the Ironflow client
12
+ */
13
+ export interface IronflowClientConfig {
14
+ /** Server URL (default: http://localhost:9123 or IRONFLOW_SERVER_URL env var) */
15
+ serverUrl?: string;
16
+ /** API key for authentication (optional for local dev) */
17
+ apiKey?: string;
18
+ /** Request timeout in milliseconds (default: 30000) */
19
+ timeout?: number;
20
+ }
21
+ /**
22
+ * Function registration request
23
+ */
24
+ export interface RegisterFunctionRequest {
25
+ /** Unique function identifier */
26
+ id: string;
27
+ /** Display name */
28
+ name?: string;
29
+ /** Description */
30
+ description?: string;
31
+ /** Event triggers */
32
+ triggers?: Trigger[];
33
+ /** Retry configuration */
34
+ retry?: RetryConfig;
35
+ /** Timeout in milliseconds */
36
+ timeoutMs?: number;
37
+ /** Concurrency configuration */
38
+ concurrency?: ConcurrencyConfig;
39
+ /** Preferred execution mode */
40
+ preferredMode?: ExecutionMode;
41
+ /** Endpoint URL for push mode */
42
+ endpointUrl?: string;
43
+ /** Actor key for sticky routing */
44
+ actorKey?: string;
45
+ }
46
+ /**
47
+ * Result from registering a function
48
+ */
49
+ export interface RegisterFunctionResult {
50
+ /** Whether the function was newly created (vs updated) */
51
+ created: boolean;
52
+ }
53
+ /**
54
+ * Result from emitting an event
55
+ */
56
+ export interface EmitResult {
57
+ /** IDs of runs created by this event */
58
+ runIds: string[];
59
+ /** ID of the stored event */
60
+ eventId: string;
61
+ }
62
+ /**
63
+ * Options for emitting an event
64
+ */
65
+ export interface EmitOptions {
66
+ /** Event schema version (default 1) */
67
+ version?: number;
68
+ /** Idempotency key to prevent duplicate processing */
69
+ idempotencyKey?: string;
70
+ /** Additional metadata */
71
+ metadata?: Record<string, unknown>;
72
+ }
73
+ /**
74
+ * Run information
75
+ */
76
+ export interface Run {
77
+ /** Run ID */
78
+ id: string;
79
+ /** Function ID */
80
+ functionId: string;
81
+ /** Event ID that triggered this run */
82
+ eventId: string;
83
+ /** Current status */
84
+ status: RunStatus;
85
+ /** Current attempt number */
86
+ attempt: number;
87
+ /** Maximum attempts allowed */
88
+ maxAttempts: number;
89
+ /** Input data */
90
+ input?: unknown;
91
+ /** Output data (if completed) */
92
+ output?: unknown;
93
+ /** Error information (if failed) */
94
+ error?: {
95
+ message: string;
96
+ code: string;
97
+ };
98
+ /** When the run started */
99
+ startedAt?: string;
100
+ /** When the run ended */
101
+ endedAt?: string;
102
+ /** When the run was created */
103
+ createdAt: string;
104
+ /** When the run was last updated */
105
+ updatedAt: string;
106
+ }
107
+ /**
108
+ * Options for listing runs
109
+ */
110
+ export interface ListRunsOptions {
111
+ /** Filter by function ID */
112
+ functionId?: string;
113
+ /** Filter by status */
114
+ status?: RunStatus;
115
+ /** Maximum number of results */
116
+ limit?: number;
117
+ /** Pagination cursor */
118
+ cursor?: string;
119
+ }
120
+ /**
121
+ * Result from listing runs
122
+ */
123
+ export interface ListRunsResult {
124
+ /** List of runs */
125
+ runs: Run[];
126
+ /** Cursor for next page */
127
+ nextCursor?: string;
128
+ /** Total count of matching runs */
129
+ totalCount: number;
130
+ }
131
+ /**
132
+ * Ironflow client for server-side operations
133
+ *
134
+ * @example
135
+ * ```typescript
136
+ * import { createClient } from "@ironflow/node";
137
+ *
138
+ * const client = createClient({
139
+ * serverUrl: "http://localhost:9123",
140
+ * });
141
+ *
142
+ * // Register a function
143
+ * await client.registerFunction({
144
+ * id: "my-function",
145
+ * name: "My Function",
146
+ * triggers: [{ event: "my.event" }],
147
+ * endpointUrl: "http://localhost:3000/api/ironflow",
148
+ * preferredMode: "push",
149
+ * });
150
+ *
151
+ * // Emit an event
152
+ * const result = await client.emit("my.event", { data: "value" });
153
+ * console.log("Created runs:", result.runIds);
154
+ * ```
155
+ */
156
+ export declare class IronflowClient {
157
+ private readonly serverUrl;
158
+ private readonly apiKey?;
159
+ private readonly timeout;
160
+ constructor(config?: IronflowClientConfig);
161
+ /**
162
+ * Register a function with the Ironflow server
163
+ */
164
+ registerFunction(request: RegisterFunctionRequest): Promise<RegisterFunctionResult>;
165
+ /**
166
+ * Emit an event to trigger workflows
167
+ *
168
+ * @example
169
+ * ```typescript
170
+ * const result = await client.emit("order.placed", {
171
+ * orderId: "123",
172
+ * total: 99.99,
173
+ * });
174
+ * console.log("Created runs:", result.runIds);
175
+ * ```
176
+ */
177
+ emit(eventName: string, data: unknown, options?: EmitOptions): Promise<EmitResult>;
178
+ /**
179
+ * Trigger an event (alias for emit)
180
+ * @deprecated Use emit() instead
181
+ */
182
+ trigger(eventName: string, data: unknown, options?: EmitOptions): Promise<EmitResult>;
183
+ /**
184
+ * Get a run by ID
185
+ */
186
+ getRun(runId: string): Promise<Run>;
187
+ /**
188
+ * List runs with optional filtering
189
+ */
190
+ listRuns(options?: ListRunsOptions): Promise<ListRunsResult>;
191
+ /**
192
+ * Cancel a running workflow
193
+ */
194
+ cancelRun(runId: string, reason?: string): Promise<Run>;
195
+ /**
196
+ * Retry a failed run
197
+ */
198
+ retryRun(runId: string, fromStep?: string): Promise<Run>;
199
+ /**
200
+ * Health check
201
+ */
202
+ health(): Promise<string>;
203
+ /**
204
+ * Entity stream operations
205
+ *
206
+ * @example
207
+ * ```typescript
208
+ * // Append an event to a stream
209
+ * const result = await client.streams.append("order-123", {
210
+ * name: "order.created",
211
+ * data: { total: 100 },
212
+ * entityType: "order",
213
+ * });
214
+ *
215
+ * // Read events from a stream
216
+ * const { events } = await client.streams.read("order-123", { limit: 10 });
217
+ *
218
+ * // Get stream info
219
+ * const info = await client.streams.getInfo("order-123");
220
+ * ```
221
+ */
222
+ streams: {
223
+ /**
224
+ * Append an event to an entity stream
225
+ */
226
+ append: (entityId: string, input: AppendEventInput, options?: AppendOptions) => Promise<AppendResult>;
227
+ /**
228
+ * Read events from an entity stream
229
+ */
230
+ read: (entityId: string, options?: ReadStreamOptions) => Promise<{
231
+ events: StreamEvent[];
232
+ totalCount: number;
233
+ }>;
234
+ /**
235
+ * Get information about an entity stream
236
+ */
237
+ getInfo: (entityId: string) => Promise<StreamInfo>;
238
+ };
239
+ /**
240
+ * KV store operations
241
+ *
242
+ * @example
243
+ * ```typescript
244
+ * const kv = client.kv();
245
+ * const bucket = await kv.createBucket({ name: "sessions", ttlSeconds: 3600 });
246
+ * const handle = kv.bucket("sessions");
247
+ * const { revision } = await handle.put("user.123", { token: "abc" });
248
+ * const entry = await handle.get("user.123");
249
+ * ```
250
+ */
251
+ kv(): KVClient;
252
+ /**
253
+ * Config management operations
254
+ *
255
+ * @example
256
+ * ```typescript
257
+ * const config = client.config();
258
+ * await config.set("app", { featureX: true });
259
+ * const { data } = await config.get("app");
260
+ * await config.patch("app", { maxRetries: 5 });
261
+ * const configs = await config.list();
262
+ * await config.delete("app");
263
+ * ```
264
+ */
265
+ config(): ConfigClient;
266
+ /**
267
+ * Patch a step's output (hot patching)
268
+ */
269
+ patchStep(stepId: string, output: Record<string, unknown>, reason?: string): Promise<void>;
270
+ /**
271
+ * Resume a paused or failed run
272
+ */
273
+ resumeRun(runId: string, fromStep?: string): Promise<Run>;
274
+ /**
275
+ * List registered functions
276
+ */
277
+ listFunctions(): Promise<unknown[]>;
278
+ /**
279
+ * List connected workers
280
+ */
281
+ listWorkers(): Promise<unknown[]>;
282
+ /**
283
+ * Make an HTTP request to the server
284
+ */
285
+ private request;
286
+ }
287
+ /**
288
+ * Create a new Ironflow client
289
+ *
290
+ * @example
291
+ * ```typescript
292
+ * const client = createClient({ serverUrl: "http://localhost:9123" });
293
+ * ```
294
+ */
295
+ export declare function createClient(config?: IronflowClientConfig): IronflowClient;
296
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAIL,KAAK,SAAS,EACd,KAAK,OAAO,EACZ,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,UAAU,EAChB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,QAAQ,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