@pgflow/dsl 0.0.0-test-snapshot-releases2-8d5d9bc1-20250922101158 → 0.0.0-update-supabase-868977e5-20251119071021

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
@@ -73,6 +73,144 @@ This design ensures:
73
73
  - Data doesn't need to be manually forwarded through intermediate steps
74
74
  - Steps can combine original input with processed data from previous steps
75
75
 
76
+ ### Step Methods
77
+
78
+ The Flow DSL provides three methods for defining steps in your workflow:
79
+
80
+ #### `.step()` - Regular Steps
81
+
82
+ The standard method for adding steps to a flow. Each step processes input and returns output.
83
+
84
+ ```typescript
85
+ .step(
86
+ { slug: 'process', dependsOn: ['previous'] },
87
+ async (input) => {
88
+ // Access input.run and input.previous
89
+ return { result: 'processed' };
90
+ }
91
+ )
92
+ ```
93
+
94
+ #### `.array()` - Array-Returning Steps
95
+
96
+ A semantic wrapper around `.step()` that provides type enforcement for steps that return arrays. Useful for data fetching or collection steps that will be processed by map steps.
97
+
98
+ ```typescript
99
+ // Fetch an array of items to be processed
100
+ .array(
101
+ { slug: 'fetch_items' },
102
+ async () => [1, 2, 3, 4, 5]
103
+ )
104
+
105
+ // With dependencies - combining data from multiple sources
106
+ .array(
107
+ { slug: 'combine_results', dependsOn: ['source1', 'source2'] },
108
+ async (input) => [...input.source1, ...input.source2]
109
+ )
110
+ ```
111
+
112
+ **Key Points:**
113
+ - Return type is enforced to be an array at compile time
114
+ - Commonly used as input for subsequent map steps
115
+ - Can depend on other steps just like regular steps
116
+
117
+ #### `.map()` - Array Processing Steps
118
+
119
+ Processes arrays element-by-element, similar to JavaScript's `Array.map()`. The handler receives individual items instead of the full input object.
120
+
121
+ **Two Modes of Operation:**
122
+
123
+ 1. **Root Map** (no `array:` property): Processes the flow's input array directly
124
+ - The flow input MUST be an array when using root maps
125
+ - Omitting the `array:` property tells pgflow to use the flow input
126
+
127
+ 2. **Dependent Map** (with `array:` property): Processes another step's array output
128
+ - The `array:` property specifies which step's output to process
129
+ - That step must return an array
130
+
131
+ ```typescript
132
+ // ROOT MAP - No array: property means use flow input
133
+ // Flow input MUST be an array (e.g., ["hello", "world"])
134
+ new Flow<string[]>({ slug: 'process_strings' })
135
+ .map(
136
+ { slug: 'uppercase' }, // No array: property!
137
+ (item) => item.toUpperCase()
138
+ );
139
+ // Each string in the input array gets uppercased in parallel
140
+
141
+ // DEPENDENT MAP - array: property specifies the source step
142
+ new Flow<{}>({ slug: 'data_pipeline' })
143
+ .array({ slug: 'numbers' }, () => [1, 2, 3])
144
+ .map(
145
+ { slug: 'double', array: 'numbers' }, // Processes 'numbers' output
146
+ (n) => n * 2
147
+ )
148
+ .map(
149
+ { slug: 'square', array: 'double' }, // Chains from 'double'
150
+ (n) => n * n
151
+ );
152
+ // Results: numbers: [1,2,3] → double: [2,4,6] → square: [4,16,36]
153
+ ```
154
+
155
+ **Key differences from regular steps:**
156
+ - Uses `array:` to specify dependency (not `dependsOn:`)
157
+ - When `array:` is omitted, uses flow input array (root map)
158
+ - Handler signature is `(item, context) => result` instead of `(input, context) => result`
159
+ - Return type is always an array
160
+ - Map steps can have at most one dependency (the array source)
161
+ - Generates SQL with `step_type => 'map'` parameter for pgflow's map processing
162
+
163
+ **Type Safety:**
164
+ The `.map()` method provides full TypeScript type inference for array elements:
165
+
166
+ ```typescript
167
+ type User = { id: number; name: string };
168
+
169
+ new Flow<{}>({ slug: 'user_flow' })
170
+ .array({ slug: 'users' }, (): User[] => [
171
+ { id: 1, name: 'Alice' },
172
+ { id: 2, name: 'Bob' }
173
+ ])
174
+ .map({ slug: 'greet', array: 'users' }, (user) => {
175
+ // TypeScript knows user is of type User
176
+ return `Hello, ${user.name} (ID: ${user.id})`;
177
+ });
178
+ ```
179
+
180
+ **Common Patterns:**
181
+
182
+ ```typescript
183
+ // Batch processing - process multiple items in parallel
184
+ new Flow<number[]>({ slug: 'batch_processor' })
185
+ .map({ slug: 'validate' }, (item) => {
186
+ if (item < 0) throw new Error('Invalid item');
187
+ return item;
188
+ })
189
+ .map({ slug: 'process', array: 'validate' }, async (item) => {
190
+ // Each item processed in its own task
191
+ return await expensiveOperation(item);
192
+ });
193
+
194
+ // Data transformation pipeline
195
+ new Flow<{}>({ slug: 'etl_pipeline' })
196
+ .step({ slug: 'fetch_urls' }, () => ['url1', 'url2', 'url3'])
197
+ .map({ slug: 'scrape', array: 'fetch_urls' }, async (url) => {
198
+ return await fetchContent(url);
199
+ })
200
+ .map({ slug: 'extract', array: 'scrape' }, (html) => {
201
+ return extractData(html);
202
+ })
203
+ .step({ slug: 'aggregate', dependsOn: ['extract'] }, (input) => {
204
+ // input.extract is the aggregated array from all map tasks
205
+ return consolidateResults(input.extract);
206
+ });
207
+ ```
208
+
209
+ **Limitations:**
210
+ - Can only depend on a single array-returning step
211
+ - TypeScript may not track type transformations between chained maps (use type assertions if needed)
212
+ - Root maps require the entire flow input to be an array
213
+
76
214
  ### Context Object
77
215
 
78
216
  Step handlers can optionally receive a second parameter - the **context object** - which provides access to platform resources and runtime information.
@@ -114,6 +252,11 @@ All platforms provide these core resources:
114
252
  msg_id: number;
115
253
  }
116
254
  ```
255
+ - **`context.workerConfig`** - Resolved worker configuration with all defaults applied
256
+ ```typescript
257
+ // Provides access to worker settings like retry limits
258
+ const isLastAttempt = context.rawMessage.read_ct >= context.workerConfig.retry.limit;
259
+ ```
117
260
 
118
261
  #### Supabase Platform Resources
119
262
 
@@ -0,0 +1,463 @@
1
+ # @pgflow/dsl
2
+
3
+ ## 0.0.0-update-supabase-868977e5-20251119071021
4
+
5
+ ## 0.7.3
6
+
7
+ ## 0.7.2
8
+
9
+ ## 0.7.1
10
+
11
+ ## 0.7.0
12
+
13
+ ### Minor Changes
14
+
15
+ - 524db03: Add `.array()` method for type-safe array step creation
16
+
17
+ Introduces a new `.array()` method that provides compile-time type safety for array-returning handlers with zero runtime overhead.
18
+
19
+ - Enforces array return types at compile time
20
+ - Pure delegation to existing `.step()` method
21
+ - Full support for dependencies and runtime options
22
+ - Backward compatible
23
+
24
+ ```typescript
25
+ flow.array({ slug: 'items' }, () => [1, 2, 3]); // ✅ Valid
26
+ flow.array({ slug: 'invalid' }, () => 42); // ❌ Compile error
27
+ ```
28
+
29
+ - 524db03: Add `.map()` method to Flow DSL for defining map-type steps
30
+
31
+ The new `.map()` method enables defining steps that process arrays element-by-element, complementing the existing SQL Core map infrastructure. Key features:
32
+
33
+ - **Root maps**: Process flow input arrays directly by omitting the `array` property
34
+ - **Dependent maps**: Process another step's array output using `array: 'stepSlug'`
35
+ - **Type-safe**: Enforces Json-compatible types with full TypeScript inference
36
+ - **Compile-time duplicate slug detection**: TypeScript now prevents duplicate step slugs at compile-time
37
+ - **Different handler signature**: Receives individual items `(item, context)` instead of full input object
38
+ - **Always returns arrays**: Return type is `HandlerReturnType[]`
39
+ - **SQL generation**: Correctly adds `step_type => 'map'` parameter to `pgflow.add_step()`
40
+
41
+ Example usage:
42
+
43
+ ```typescript
44
+ // Root map - processes array input
45
+ new Flow<string[]>({ slug: 'process' }).map({ slug: 'uppercase' }, (item) =>
46
+ item.toUpperCase()
47
+ );
48
+
49
+ // Dependent map - processes another step's output
50
+ new Flow<{}>({ slug: 'workflow' })
51
+ .array({ slug: 'items' }, () => [1, 2, 3])
52
+ .map({ slug: 'double', array: 'items' }, (n) => n * 2);
53
+ ```
54
+
55
+ ## 0.6.1
56
+
57
+ ## 0.6.0
58
+
59
+ ### Minor Changes
60
+
61
+ - a67bf27: 🚨 **BREAKING**: Remove `anonSupabase` and `serviceSupabase` from context, replaced with single `supabase` client (initialized with service role key)
62
+
63
+ The dual-client approach was unnecessary complexity. Edge Functions run in a trusted environment with service role access, so a single client is sufficient.
64
+
65
+ **Migration guide**:
66
+
67
+ ```typescript
68
+ // Before
69
+ const { data } = await context.serviceSupabase.from('users').select();
70
+ const { data: publicData } = await context.anonSupabase
71
+ .from('posts')
72
+ .select();
73
+
74
+ // After
75
+ const { data } = await context.supabase.from('users').select();
76
+ // For RLS-respecting queries, implement proper policies in your database
77
+ ```
78
+
79
+ ⚠️ **Breaking changes**:
80
+
81
+ - Removed `anonSupabase` from context interface
82
+ - Removed `serviceSupabase` from context interface
83
+ - Added `supabase` field (initialized with service role key)
84
+ - Removed `createAnonSupabaseClient` function
85
+
86
+ ## 0.5.4
87
+
88
+ ### Patch Changes
89
+
90
+ - 9f219a4: Add context object as second parameter to handlers
91
+
92
+ Queue and flow handlers now receive an optional context parameter that provides platform resources like database connections, environment variables, and Supabase clients - eliminating boilerplate and connection management.
93
+
94
+ ```typescript
95
+ // Queue handler
96
+ EdgeWorker.start(async (payload, context) => {
97
+ await context.sql`INSERT INTO tasks (data) VALUES (${payload})`;
98
+ });
99
+
100
+ // Flow step handler
101
+ .step({ slug: 'process' }, async (input, context) => {
102
+ const result = await context.serviceSupabase.from('users').select();
103
+ })
104
+ ```
105
+
106
+ **Core resources** (always available):
107
+
108
+ - `context.env` - Environment variables
109
+ - `context.shutdownSignal` - AbortSignal for graceful shutdown
110
+ - `context.rawMessage` - Original pgmq message with metadata
111
+ - `context.stepTask` - Current step task details (flow handlers only)
112
+
113
+ **Supabase platform resources**:
114
+
115
+ - `context.sql` - PostgreSQL client (postgres.js)
116
+ - `context.anonSupabase` - Supabase client with anonymous key
117
+ - `context.serviceSupabase` - Supabase client with service role key
118
+
119
+ To use Supabase resources in flows, import from the Supabase preset:
120
+
121
+ ```typescript
122
+ import { Flow } from '@pgflow/dsl/supabase';
123
+ ```
124
+
125
+ The context parameter is optional for backward compatibility - existing single-parameter handlers continue to work unchanged.
126
+
127
+ ## 0.5.3
128
+
129
+ ### Patch Changes
130
+
131
+ - af787ff: Add `startDelay` option for workflow steps
132
+
133
+ Introduces the ability to delay a step's **initial execution** by a specified number of seconds, enabling multi-day workflows and scheduled tasks within pgflow.
134
+
135
+ **Important**: `startDelay` only applies to the first execution attempt. Retries use the standard exponential backoff mechanism based on `baseDelay`, not `startDelay`.
136
+
137
+ ### Core Changes (@pgflow/core)
138
+
139
+ - Added `opt_start_delay` column (integer, nullable, CHECK >= 0) to `pgflow.steps` table
140
+ - Updated `add_step` function to accept and validate the new `start_delay` parameter
141
+ - Modified `start_ready_steps` to schedule initial task execution with delay via `pgmq.send(queue, message, delay)`
142
+ - Requires pgmq >= 0.40 for delay support
143
+ - Migration: `20250707210212_pgflow_add_opt_start_delay.sql`
144
+ - Added comprehensive PgTAP tests for validation and scheduling behavior
145
+
146
+ ### DSL Changes (@pgflow/dsl)
147
+
148
+ - Extended `StepOptions` and `StepRuntimeOptions` interfaces with optional `startDelay` (in seconds)
149
+ - Updated `compileFlow()` to emit `start_delay => value` in generated SQL
150
+ - Added validation: `startDelay` is only allowed at step level, not flow level (prevents cascading delays)
151
+ - Valid range: 0 to 2,147,483,647 seconds (~68 years)
152
+ - Added unit tests for compilation and validation
153
+
154
+ ### Documentation Updates (@pgflow/website)
155
+
156
+ - Added `startDelay` section in configuration guide with detailed explanation
157
+ - Created multi-day workflow example (onboarding email sequence)
158
+ - Updated "Update Flow Options" to include `opt_start_delay`
159
+ - Enhanced VS comparison pages to mention "Native step delays" capability
160
+ - Documented why `startDelay` is step-level only
161
+
162
+ ### Example Usage
163
+
164
+ ```typescript
165
+ new Flow({
166
+ slug: 'user_onboarding',
167
+ maxAttempts: 3,
168
+ baseDelay: 5, // Retry delay (not initial delay)
169
+ timeout: 60,
170
+ })
171
+ .step(
172
+ {
173
+ slug: 'send_welcome_email',
174
+ // Executes immediately when step becomes ready
175
+ },
176
+ sendWelcomeHandler
177
+ )
178
+ .step(
179
+ {
180
+ slug: 'send_day_3_tips',
181
+ startDelay: 259200, // Wait 3 days before first execution
182
+ timeout: 120,
183
+ },
184
+ sendTipsHandler
185
+ )
186
+ .step(
187
+ {
188
+ slug: 'send_week_review',
189
+ startDelay: 604800, // Wait 7 days after dependencies complete
190
+ timeout: 120,
191
+ },
192
+ sendReviewHandler
193
+ );
194
+ ```
195
+
196
+ ### Use Cases
197
+
198
+ - **Multi-day workflows**: Onboarding sequences, follow-up reminders
199
+ - **Scheduled notifications**: Send reports or alerts at specific intervals
200
+ - **Rate limiting**: Enforce minimum time between API calls
201
+ - **Compliance delays**: Cooling-off periods before actions
202
+
203
+ ### Technical Notes
204
+
205
+ - Non-breaking, additive change (hence minor version bump)
206
+ - No changes required in `@pgflow/edge-worker` - delays handled by pgmq
207
+ - `startDelay` does not affect retry timing - only the initial execution
208
+ - Delays are reliable even across worker restarts (persisted in queue)
209
+
210
+ ## 0.5.2
211
+
212
+ ## 0.5.1
213
+
214
+ ## 0.5.0
215
+
216
+ ## 0.4.3
217
+
218
+ ## 0.4.2
219
+
220
+ ## 0.4.1
221
+
222
+ ## 0.4.0
223
+
224
+ ### Patch Changes
225
+
226
+ - 98556d3: Add TypeScript client library for pgflow workflow management
227
+
228
+ ## @pgflow/client
229
+
230
+ Introduces a new TypeScript client library that provides both event-based and promise-based APIs for interacting with pgflow workflows:
231
+
232
+ ### Features
233
+
234
+ - **Type-safe workflow management** with full TypeScript support and automatic type inference from flow definitions
235
+ - **Dual API approach**: Choose between event-based subscriptions or promise-based async/await patterns
236
+ - **Real-time monitoring** via Supabase broadcasts with granular event subscriptions
237
+ - **Resource management** with automatic cleanup and disposal
238
+ - **Comprehensive error handling** and recovery mechanisms
239
+
240
+ ### Core Components
241
+
242
+ - `PgflowClient` - Main client for starting and managing workflow runs
243
+ - `FlowRun` - Monitor and interact with workflow executions
244
+ - `FlowStep` - Track individual step progress and outputs
245
+
246
+ ### Example Usage
247
+
248
+ ```typescript
249
+ // Start a workflow
250
+ const pgflow = new PgflowClient(supabase);
251
+ const run = await pgflow.startFlow('analyze_website', {
252
+ url: 'https://example.com',
253
+ });
254
+
255
+ // Event-based monitoring
256
+ run.on('completed', (event) => {
257
+ console.log('Workflow completed:', event.output);
258
+ });
259
+
260
+ // Promise-based monitoring
261
+ const completed = await run.waitForStatus(FlowRunStatus.Completed, {
262
+ timeoutMs: 30000,
263
+ });
264
+ ```
265
+
266
+ ## @pgflow/core
267
+
268
+ ### Database Enhancements
269
+
270
+ - Add `start_flow_with_states()` function to start flows and return complete initial state
271
+ - Add `get_run_with_states()` function to retrieve runs with all step states efficiently
272
+ - Implement `SECURITY DEFINER` functions for secure API access
273
+ - Add real-time broadcast support for workflow state changes
274
+
275
+ ## @pgflow/edge-worker
276
+
277
+ ### Test Infrastructure Updates
278
+
279
+ - Update test database configuration to use standard PostgreSQL credentials
280
+ - Improve test helper functions for database transactions
281
+ - Update Docker Compose configuration for test environment
282
+
283
+ ## @pgflow/dsl
284
+
285
+ ### Build Configuration
286
+
287
+ - Add TypeScript references to tsconfig.spec.json for improved type checking in tests
288
+
289
+ ## 0.3.1
290
+
291
+ ## 0.3.0
292
+
293
+ ## 0.2.6
294
+
295
+ ## 0.2.5
296
+
297
+ ## 0.2.4
298
+
299
+ ## 0.2.3
300
+
301
+ ## 0.2.2
302
+
303
+ ## 0.2.1
304
+
305
+ ### Patch Changes
306
+
307
+ - 3f3174e: Update the README's
308
+
309
+ ## 0.2.0
310
+
311
+ ## 0.1.23
312
+
313
+ ## 0.1.22
314
+
315
+ ### Patch Changes
316
+
317
+ - 8f6eb3d: Added ExtractFlowLeafSteps and ExtractFlowOutput utility types
318
+
319
+ ## 0.1.21
320
+
321
+ ## 0.1.20
322
+
323
+ ## 0.1.19
324
+
325
+ ## 0.1.18
326
+
327
+ ### Patch Changes
328
+
329
+ - 3a7e132: Do not build edge-worker for npm
330
+
331
+ ## 0.1.17
332
+
333
+ ### Patch Changes
334
+
335
+ - d215ed2: Trigger version change
336
+
337
+ ## 0.1.16
338
+
339
+ ### Patch Changes
340
+
341
+ - cc7c431: Test release to verify combined publishing of both npm and jsr packages
342
+
343
+ ## 0.1.15
344
+
345
+ ### Patch Changes
346
+
347
+ - ce34a2c: Update release pipeline to publish to jsr
348
+
349
+ ## 0.1.14
350
+
351
+ ## 0.1.13
352
+
353
+ ## 0.1.12
354
+
355
+ ### Patch Changes
356
+
357
+ - 7b1328e: Include invalid slug in validateSlug error message
358
+
359
+ ## 0.1.11
360
+
361
+ ## 0.1.10
362
+
363
+ ### Patch Changes
364
+
365
+ - bafe767: Fix deno/ folder for cli being missing
366
+
367
+ ## 0.1.9
368
+
369
+ ### Patch Changes
370
+
371
+ - 1a30c6c: Make sure to tag and push tags
372
+
373
+ ## 0.1.8
374
+
375
+ ### Patch Changes
376
+
377
+ - 05f5bd8: Update release script
378
+
379
+ ## 0.1.7
380
+
381
+ ## 0.1.6
382
+
383
+ ### Patch Changes
384
+
385
+ - Test release to verify problem with bumping edge-worker
386
+
387
+ ## 0.1.5
388
+
389
+ ### Patch Changes
390
+
391
+ - 5820e7a: Bump version for tests
392
+
393
+ ## 0.1.4
394
+
395
+ ## 0.1.3
396
+
397
+ ## 0.1.2
398
+
399
+ ## 0.1.1
400
+
401
+ ### Patch Changes
402
+
403
+ - b362364: Add compileFlow function
404
+
405
+ ## 0.1.0
406
+
407
+ ## 0.0.23
408
+
409
+ ## 0.0.22
410
+
411
+ ## 0.0.21
412
+
413
+ ## 0.0.20
414
+
415
+ ## 0.0.19
416
+
417
+ ## 0.0.18
418
+
419
+ ### Patch Changes
420
+
421
+ - 53abf4a: Fix pnpm issues with linking to dist/
422
+
423
+ ## 0.0.17
424
+
425
+ ## 0.0.16
426
+
427
+ ## 0.0.15
428
+
429
+ ## 0.0.14
430
+
431
+ ## 0.0.13
432
+
433
+ ## 0.0.12
434
+
435
+ ## 0.0.11
436
+
437
+ ### Patch Changes
438
+
439
+ - 17937e3: Update changesets action and comment out custom publish
440
+
441
+ ## 0.0.10
442
+
443
+ ## 0.0.9
444
+
445
+ ### Patch Changes
446
+
447
+ - 70d3f2d: Tweak extension setting in tsconfig.base.json
448
+
449
+ ## 0.0.8
450
+
451
+ ## 0.0.7
452
+
453
+ ### Patch Changes
454
+
455
+ - 7c83db9: Add release-related options to package.json files
456
+
457
+ ## 0.0.6
458
+
459
+ ## 0.0.5
460
+
461
+ ### Patch Changes
462
+
463
+ - b4b0809: test changesets