@pgflow/dsl 0.0.0-add-workerconfig-to-context--20250905094004-b98e1fec-20250905074005 → 0.0.0-test-snapshot-releases-8d5d9bc1-20250922101013

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pgflow/dsl",
3
- "version": "0.0.0-add-workerconfig-to-context--20250905094004-b98e1fec-20250905074005",
3
+ "version": "0.0.0-test-snapshot-releases-8d5d9bc1-20250922101013",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
package/dist/CHANGELOG.md DELETED
@@ -1,409 +0,0 @@
1
- # @pgflow/dsl
2
-
3
- ## 0.6.0
4
-
5
- ### Minor Changes
6
-
7
- - a67bf27: 🚨 **BREAKING**: Remove `anonSupabase` and `serviceSupabase` from context, replaced with single `supabase` client (initialized with service role key)
8
-
9
- The dual-client approach was unnecessary complexity. Edge Functions run in a trusted environment with service role access, so a single client is sufficient.
10
-
11
- **Migration guide**:
12
-
13
- ```typescript
14
- // Before
15
- const { data } = await context.serviceSupabase.from('users').select();
16
- const { data: publicData } = await context.anonSupabase
17
- .from('posts')
18
- .select();
19
-
20
- // After
21
- const { data } = await context.supabase.from('users').select();
22
- // For RLS-respecting queries, implement proper policies in your database
23
- ```
24
-
25
- ⚠️ **Breaking changes**:
26
-
27
- - Removed `anonSupabase` from context interface
28
- - Removed `serviceSupabase` from context interface
29
- - Added `supabase` field (initialized with service role key)
30
- - Removed `createAnonSupabaseClient` function
31
-
32
- ## 0.5.4
33
-
34
- ### Patch Changes
35
-
36
- - 9f219a4: Add context object as second parameter to handlers
37
-
38
- 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.
39
-
40
- ```typescript
41
- // Queue handler
42
- EdgeWorker.start(async (payload, context) => {
43
- await context.sql`INSERT INTO tasks (data) VALUES (${payload})`;
44
- });
45
-
46
- // Flow step handler
47
- .step({ slug: 'process' }, async (input, context) => {
48
- const result = await context.serviceSupabase.from('users').select();
49
- })
50
- ```
51
-
52
- **Core resources** (always available):
53
-
54
- - `context.env` - Environment variables
55
- - `context.shutdownSignal` - AbortSignal for graceful shutdown
56
- - `context.rawMessage` - Original pgmq message with metadata
57
- - `context.stepTask` - Current step task details (flow handlers only)
58
-
59
- **Supabase platform resources**:
60
-
61
- - `context.sql` - PostgreSQL client (postgres.js)
62
- - `context.anonSupabase` - Supabase client with anonymous key
63
- - `context.serviceSupabase` - Supabase client with service role key
64
-
65
- To use Supabase resources in flows, import from the Supabase preset:
66
-
67
- ```typescript
68
- import { Flow } from '@pgflow/dsl/supabase';
69
- ```
70
-
71
- The context parameter is optional for backward compatibility - existing single-parameter handlers continue to work unchanged.
72
-
73
- ## 0.5.3
74
-
75
- ### Patch Changes
76
-
77
- - af787ff: Add `startDelay` option for workflow steps
78
-
79
- 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.
80
-
81
- **Important**: `startDelay` only applies to the first execution attempt. Retries use the standard exponential backoff mechanism based on `baseDelay`, not `startDelay`.
82
-
83
- ### Core Changes (@pgflow/core)
84
-
85
- - Added `opt_start_delay` column (integer, nullable, CHECK >= 0) to `pgflow.steps` table
86
- - Updated `add_step` function to accept and validate the new `start_delay` parameter
87
- - Modified `start_ready_steps` to schedule initial task execution with delay via `pgmq.send(queue, message, delay)`
88
- - Requires pgmq >= 0.40 for delay support
89
- - Migration: `20250707210212_pgflow_add_opt_start_delay.sql`
90
- - Added comprehensive PgTAP tests for validation and scheduling behavior
91
-
92
- ### DSL Changes (@pgflow/dsl)
93
-
94
- - Extended `StepOptions` and `StepRuntimeOptions` interfaces with optional `startDelay` (in seconds)
95
- - Updated `compileFlow()` to emit `start_delay => value` in generated SQL
96
- - Added validation: `startDelay` is only allowed at step level, not flow level (prevents cascading delays)
97
- - Valid range: 0 to 2,147,483,647 seconds (~68 years)
98
- - Added unit tests for compilation and validation
99
-
100
- ### Documentation Updates (@pgflow/website)
101
-
102
- - Added `startDelay` section in configuration guide with detailed explanation
103
- - Created multi-day workflow example (onboarding email sequence)
104
- - Updated "Update Flow Options" to include `opt_start_delay`
105
- - Enhanced VS comparison pages to mention "Native step delays" capability
106
- - Documented why `startDelay` is step-level only
107
-
108
- ### Example Usage
109
-
110
- ```typescript
111
- new Flow({
112
- slug: 'user_onboarding',
113
- maxAttempts: 3,
114
- baseDelay: 5, // Retry delay (not initial delay)
115
- timeout: 60,
116
- })
117
- .step(
118
- {
119
- slug: 'send_welcome_email',
120
- // Executes immediately when step becomes ready
121
- },
122
- sendWelcomeHandler
123
- )
124
- .step(
125
- {
126
- slug: 'send_day_3_tips',
127
- startDelay: 259200, // Wait 3 days before first execution
128
- timeout: 120,
129
- },
130
- sendTipsHandler
131
- )
132
- .step(
133
- {
134
- slug: 'send_week_review',
135
- startDelay: 604800, // Wait 7 days after dependencies complete
136
- timeout: 120,
137
- },
138
- sendReviewHandler
139
- );
140
- ```
141
-
142
- ### Use Cases
143
-
144
- - **Multi-day workflows**: Onboarding sequences, follow-up reminders
145
- - **Scheduled notifications**: Send reports or alerts at specific intervals
146
- - **Rate limiting**: Enforce minimum time between API calls
147
- - **Compliance delays**: Cooling-off periods before actions
148
-
149
- ### Technical Notes
150
-
151
- - Non-breaking, additive change (hence minor version bump)
152
- - No changes required in `@pgflow/edge-worker` - delays handled by pgmq
153
- - `startDelay` does not affect retry timing - only the initial execution
154
- - Delays are reliable even across worker restarts (persisted in queue)
155
-
156
- ## 0.5.2
157
-
158
- ## 0.5.1
159
-
160
- ## 0.5.0
161
-
162
- ## 0.4.3
163
-
164
- ## 0.4.2
165
-
166
- ## 0.4.1
167
-
168
- ## 0.4.0
169
-
170
- ### Patch Changes
171
-
172
- - 98556d3: Add TypeScript client library for pgflow workflow management
173
-
174
- ## @pgflow/client
175
-
176
- Introduces a new TypeScript client library that provides both event-based and promise-based APIs for interacting with pgflow workflows:
177
-
178
- ### Features
179
-
180
- - **Type-safe workflow management** with full TypeScript support and automatic type inference from flow definitions
181
- - **Dual API approach**: Choose between event-based subscriptions or promise-based async/await patterns
182
- - **Real-time monitoring** via Supabase broadcasts with granular event subscriptions
183
- - **Resource management** with automatic cleanup and disposal
184
- - **Comprehensive error handling** and recovery mechanisms
185
-
186
- ### Core Components
187
-
188
- - `PgflowClient` - Main client for starting and managing workflow runs
189
- - `FlowRun` - Monitor and interact with workflow executions
190
- - `FlowStep` - Track individual step progress and outputs
191
-
192
- ### Example Usage
193
-
194
- ```typescript
195
- // Start a workflow
196
- const pgflow = new PgflowClient(supabase);
197
- const run = await pgflow.startFlow('analyze_website', {
198
- url: 'https://example.com',
199
- });
200
-
201
- // Event-based monitoring
202
- run.on('completed', (event) => {
203
- console.log('Workflow completed:', event.output);
204
- });
205
-
206
- // Promise-based monitoring
207
- const completed = await run.waitForStatus(FlowRunStatus.Completed, {
208
- timeoutMs: 30000,
209
- });
210
- ```
211
-
212
- ## @pgflow/core
213
-
214
- ### Database Enhancements
215
-
216
- - Add `start_flow_with_states()` function to start flows and return complete initial state
217
- - Add `get_run_with_states()` function to retrieve runs with all step states efficiently
218
- - Implement `SECURITY DEFINER` functions for secure API access
219
- - Add real-time broadcast support for workflow state changes
220
-
221
- ## @pgflow/edge-worker
222
-
223
- ### Test Infrastructure Updates
224
-
225
- - Update test database configuration to use standard PostgreSQL credentials
226
- - Improve test helper functions for database transactions
227
- - Update Docker Compose configuration for test environment
228
-
229
- ## @pgflow/dsl
230
-
231
- ### Build Configuration
232
-
233
- - Add TypeScript references to tsconfig.spec.json for improved type checking in tests
234
-
235
- ## 0.3.1
236
-
237
- ## 0.3.0
238
-
239
- ## 0.2.6
240
-
241
- ## 0.2.5
242
-
243
- ## 0.2.4
244
-
245
- ## 0.2.3
246
-
247
- ## 0.2.2
248
-
249
- ## 0.2.1
250
-
251
- ### Patch Changes
252
-
253
- - 3f3174e: Update the README's
254
-
255
- ## 0.2.0
256
-
257
- ## 0.1.23
258
-
259
- ## 0.1.22
260
-
261
- ### Patch Changes
262
-
263
- - 8f6eb3d: Added ExtractFlowLeafSteps and ExtractFlowOutput utility types
264
-
265
- ## 0.1.21
266
-
267
- ## 0.1.20
268
-
269
- ## 0.1.19
270
-
271
- ## 0.1.18
272
-
273
- ### Patch Changes
274
-
275
- - 3a7e132: Do not build edge-worker for npm
276
-
277
- ## 0.1.17
278
-
279
- ### Patch Changes
280
-
281
- - d215ed2: Trigger version change
282
-
283
- ## 0.1.16
284
-
285
- ### Patch Changes
286
-
287
- - cc7c431: Test release to verify combined publishing of both npm and jsr packages
288
-
289
- ## 0.1.15
290
-
291
- ### Patch Changes
292
-
293
- - ce34a2c: Update release pipeline to publish to jsr
294
-
295
- ## 0.1.14
296
-
297
- ## 0.1.13
298
-
299
- ## 0.1.12
300
-
301
- ### Patch Changes
302
-
303
- - 7b1328e: Include invalid slug in validateSlug error message
304
-
305
- ## 0.1.11
306
-
307
- ## 0.1.10
308
-
309
- ### Patch Changes
310
-
311
- - bafe767: Fix deno/ folder for cli being missing
312
-
313
- ## 0.1.9
314
-
315
- ### Patch Changes
316
-
317
- - 1a30c6c: Make sure to tag and push tags
318
-
319
- ## 0.1.8
320
-
321
- ### Patch Changes
322
-
323
- - 05f5bd8: Update release script
324
-
325
- ## 0.1.7
326
-
327
- ## 0.1.6
328
-
329
- ### Patch Changes
330
-
331
- - Test release to verify problem with bumping edge-worker
332
-
333
- ## 0.1.5
334
-
335
- ### Patch Changes
336
-
337
- - 5820e7a: Bump version for tests
338
-
339
- ## 0.1.4
340
-
341
- ## 0.1.3
342
-
343
- ## 0.1.2
344
-
345
- ## 0.1.1
346
-
347
- ### Patch Changes
348
-
349
- - b362364: Add compileFlow function
350
-
351
- ## 0.1.0
352
-
353
- ## 0.0.23
354
-
355
- ## 0.0.22
356
-
357
- ## 0.0.21
358
-
359
- ## 0.0.20
360
-
361
- ## 0.0.19
362
-
363
- ## 0.0.18
364
-
365
- ### Patch Changes
366
-
367
- - 53abf4a: Fix pnpm issues with linking to dist/
368
-
369
- ## 0.0.17
370
-
371
- ## 0.0.16
372
-
373
- ## 0.0.15
374
-
375
- ## 0.0.14
376
-
377
- ## 0.0.13
378
-
379
- ## 0.0.12
380
-
381
- ## 0.0.11
382
-
383
- ### Patch Changes
384
-
385
- - 17937e3: Update changesets action and comment out custom publish
386
-
387
- ## 0.0.10
388
-
389
- ## 0.0.9
390
-
391
- ### Patch Changes
392
-
393
- - 70d3f2d: Tweak extension setting in tsconfig.base.json
394
-
395
- ## 0.0.8
396
-
397
- ## 0.0.7
398
-
399
- ### Patch Changes
400
-
401
- - 7c83db9: Add release-related options to package.json files
402
-
403
- ## 0.0.6
404
-
405
- ## 0.0.5
406
-
407
- ### Patch Changes
408
-
409
- - b4b0809: test changesets
package/dist/README.md DELETED
@@ -1,203 +0,0 @@
1
- # @pgflow/dsl
2
-
3
- The TypeScript Domain Specific Language (DSL) for defining type-safe workflow definitions in pgflow.
4
-
5
- > [!NOTE]
6
- > This project and all its components are licensed under [Apache 2.0](./LICENSE) license.
7
-
8
- ## Overview
9
-
10
- `@pgflow/dsl` provides a type-safe, fluent interface for defining data-driven workflows with explicit dependencies. The DSL ensures that data flows correctly between steps and maintains type safety throughout the entire workflow definition.
11
-
12
- Key features:
13
-
14
- - **Type Safety** - Complete TypeScript type checking from flow inputs to outputs
15
- - **Fluent Interface** - Chainable method calls for defining steps and dependencies
16
- - **Functional Approach** - Clean separation between task implementation and flow orchestration
17
- - **JSON-Compatible** - All inputs and outputs are JSON-serializable for database storage
18
- - **Immutable Flow Definitions** - Each step operation returns a new Flow instance
19
-
20
- ## Usage
21
-
22
- ### Basic Example
23
-
24
- ```typescript
25
- import { Flow } from '@pgflow/dsl';
26
-
27
- // Define input type for the flow
28
- type Input = {
29
- url: string;
30
- };
31
-
32
- // Define a flow with steps and dependencies
33
- export const AnalyzeWebsite = new Flow<Input>({
34
- slug: 'analyze_website',
35
- maxAttempts: 3,
36
- baseDelay: 5,
37
- timeout: 10,
38
- })
39
- .step(
40
- { slug: 'website' },
41
- async (input) => await scrapeWebsite(input.run.url)
42
- )
43
- .step(
44
- { slug: 'sentiment', dependsOn: ['website'] },
45
- async (input) => await analyzeSentiment(input.website.content)
46
- )
47
- .step(
48
- { slug: 'summary', dependsOn: ['website'] },
49
- async (input) => await summarizeWithAI(input.website.content)
50
- )
51
- .step(
52
- { slug: 'saveToDb', dependsOn: ['sentiment', 'summary'] },
53
- async (input) => {
54
- return await saveToDb({
55
- websiteUrl: input.run.url,
56
- sentiment: input.sentiment.score,
57
- summary: input.summary.aiSummary,
58
- });
59
- }
60
- );
61
- ```
62
-
63
- ### Understanding Data Flow
64
-
65
- In pgflow, each step receives an `input` object that contains:
66
-
67
- 1. **`input.run`** - The original flow input (available to all steps)
68
- 2. **`input.{stepName}`** - Outputs from dependency steps
69
-
70
- This design ensures:
71
-
72
- - Original flow parameters are accessible throughout the entire flow
73
- - Data doesn't need to be manually forwarded through intermediate steps
74
- - Steps can combine original input with processed data from previous steps
75
-
76
- ### Context Object
77
-
78
- Step handlers can optionally receive a second parameter - the **context object** - which provides access to platform resources and runtime information.
79
-
80
- ```typescript
81
- .step(
82
- { slug: 'saveToDb' },
83
- async (input, context) => {
84
- // Access platform resources through context
85
- const result = await context.sql`SELECT * FROM users WHERE id = ${input.userId}`;
86
- return result[0];
87
- }
88
- )
89
- ```
90
-
91
- #### Core Context Resources
92
-
93
- All platforms provide these core resources:
94
-
95
- - **`context.env`** - Environment variables (`Record<string, string | undefined>`)
96
- - **`context.shutdownSignal`** - AbortSignal for graceful shutdown handling
97
- - **`context.rawMessage`** - Original pgmq message with metadata
98
- ```typescript
99
- interface PgmqMessageRecord<T> {
100
- msg_id: number;
101
- read_ct: number;
102
- enqueued_at: Date;
103
- vt: Date;
104
- message: T; // <-- this is your 'input'
105
- }
106
- ```
107
- - **`context.stepTask`** - Current step task details (flow handlers only)
108
- ```typescript
109
- interface StepTaskRecord<TFlow> {
110
- flow_slug: string;
111
- run_id: string;
112
- step_slug: string;
113
- input: StepInput<TFlow, StepSlug>; // <-- this is handler 'input'
114
- msg_id: number;
115
- }
116
- ```
117
-
118
- #### Supabase Platform Resources
119
-
120
- When using the Supabase platform with EdgeWorker, additional resources are available:
121
-
122
- - **`context.sql`** - PostgreSQL client (postgres.js)
123
- - **`context.supabase`** - Supabase client with service role key for full database access
124
-
125
- To use Supabase resources, import the `Flow` class from the Supabase preset:
126
-
127
- ```typescript
128
- import { Flow } from '@pgflow/dsl/supabase';
129
-
130
- const MyFlow = new Flow<{ userId: string }>({
131
- slug: 'my_flow',
132
- }).step({ slug: 'process' }, async (input, context) => {
133
- // TypeScript knows context includes Supabase resources
134
- const { data } = await context.supabase
135
- .from('users')
136
- .select('*')
137
- .eq('id', input.userId);
138
-
139
- // Use SQL directly
140
- const stats = await context.sql`
141
- SELECT COUNT(*) as total FROM events
142
- WHERE user_id = ${input.userId}
143
- `;
144
-
145
- return { user: data[0], eventCount: stats[0].total };
146
- });
147
- ```
148
-
149
- > [!NOTE]
150
- > Context is optional - handlers that don't need platform resources can omit the second parameter for backward compatibility.
151
-
152
- For more details on available resources and platform configuration, see the [@pgflow/edge-worker documentation](https://github.com/pgflow-org/pgflow/tree/main/pkgs/edge-worker#context-resources).
153
-
154
- ### Flow Configuration
155
-
156
- Configure flows and steps with runtime options:
157
-
158
- ```typescript
159
- new Flow<Input>({
160
- slug: 'my_flow', // Required: Unique flow identifier
161
- maxAttempts: 3, // Optional: Maximum retry attempts (default: 1)
162
- baseDelay: 5, // Optional: Base delay in seconds for retries (default: 1)
163
- timeout: 10, // Optional: Task timeout in seconds (default: 30)
164
- });
165
- ```
166
-
167
- ## Compiling Flows
168
-
169
- Use the `compileFlow` utility to convert a flow definition into SQL statements:
170
-
171
- ```typescript
172
- import { compileFlow } from '@pgflow/dsl';
173
-
174
- const sqlStatements = compileFlow(MyFlow);
175
- console.log(sqlStatements.join('\n'));
176
- ```
177
-
178
- Alternatively, use the pgflow CLI to compile flows directly to migration files:
179
-
180
- ```bash
181
- npx pgflow compile path/to/flow.ts
182
- ```
183
-
184
- ## Requirements
185
-
186
- - All step inputs and outputs MUST be JSON-serializable
187
- - Use only: primitive types, plain objects, and arrays
188
- - Convert dates to ISO strings (`new Date().toISOString()`)
189
- - Avoid: class instances, functions, symbols, undefined values, and circular references
190
-
191
- ## Building
192
-
193
- Run `nx build dsl` to build the library.
194
-
195
- ## Running unit tests
196
-
197
- Run `nx test dsl` to execute the unit tests via [Vitest](https://vitest.dev/).
198
-
199
- ## Documentation
200
-
201
- For detailed documentation on the Flow DSL, visit:
202
-
203
- - [Understanding the Flow DSL](https://pgflow.dev/explanations/flow-dsl/)
@@ -1,10 +0,0 @@
1
- import { AnyFlow } from './dsl.js';
2
- /**
3
- * Compiles a Flow object into an array of SQL statements
4
- * that can be executed to create the flow and its steps in PostgreSQL
5
- *
6
- * @param flow The Flow object to compile
7
- * @returns Array of SQL statements
8
- */
9
- export declare function compileFlow(flow: AnyFlow): string[];
10
- //# sourceMappingURL=compile-flow.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"compile-flow.d.ts","sourceRoot":"","sources":["../src/compile-flow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAsC,MAAM,UAAU,CAAC;AAEvE;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,EAAE,CAyBnD"}
@@ -1,45 +0,0 @@
1
- /**
2
- * Compiles a Flow object into an array of SQL statements
3
- * that can be executed to create the flow and its steps in PostgreSQL
4
- *
5
- * @param flow The Flow object to compile
6
- * @returns Array of SQL statements
7
- */
8
- export function compileFlow(flow) {
9
- const statements = [];
10
- // Create the flow
11
- const flowOptions = formatRuntimeOptions(flow.options);
12
- statements.push(`SELECT pgflow.create_flow('${flow.slug}'${flowOptions});`);
13
- // Add steps in the order they were defined
14
- for (const stepSlug of flow.stepOrder) {
15
- const step = flow.getStepDefinition(stepSlug);
16
- const stepOptions = formatRuntimeOptions(step.options);
17
- // Format dependencies array if it exists
18
- let depsClause = '';
19
- if (step.dependencies.length > 0) {
20
- const depsArray = step.dependencies.map((dep) => `'${dep}'`).join(', ');
21
- depsClause = `, ARRAY[${depsArray}]`;
22
- }
23
- statements.push(`SELECT pgflow.add_step('${flow.slug}', '${step.slug}'${depsClause}${stepOptions});`);
24
- }
25
- return statements;
26
- }
27
- /**
28
- * Formats runtime options into SQL parameter string
29
- */
30
- function formatRuntimeOptions(options) {
31
- const parts = [];
32
- if (options.maxAttempts !== undefined) {
33
- parts.push(`max_attempts => ${options.maxAttempts}`);
34
- }
35
- if (options.baseDelay !== undefined) {
36
- parts.push(`base_delay => ${options.baseDelay}`);
37
- }
38
- if (options.timeout !== undefined) {
39
- parts.push(`timeout => ${options.timeout}`);
40
- }
41
- if ('startDelay' in options && options.startDelay !== undefined) {
42
- parts.push(`start_delay => ${options.startDelay}`);
43
- }
44
- return parts.length > 0 ? `, ${parts.join(', ')}` : '';
45
- }
package/dist/dsl.d.ts DELETED
@@ -1,149 +0,0 @@
1
- export type Json = string | number | boolean | null | Json[] | {
2
- [key: string]: Json | undefined;
3
- };
4
- export type Simplify<T> = {
5
- [KeyType in keyof T]: T[KeyType];
6
- } & {};
7
- type AwaitedReturn<T> = T extends (...args: any[]) => Promise<infer R> ? R : T extends (...args: any[]) => infer R ? R : never;
8
- export interface Env {
9
- [key: string]: string | undefined;
10
- }
11
- export type ValidEnv<T> = T extends Env ? T : never;
12
- export interface UserEnv extends Env {
13
- }
14
- export type AnyInput = Json;
15
- export type AnyOutput = Json;
16
- export type EmptySteps = Record<never, never>;
17
- export type AnySteps = Record<string, AnyOutput>;
18
- export type EmptyDeps = Record<never, never[]>;
19
- export type DefaultDeps = Record<string, string[]>;
20
- export type AnyDeps = Record<string, string[]>;
21
- /**
22
- * Represents a Flow that has not steps nor deps defined yet
23
- */
24
- export type EmptyFlow = Flow<AnyInput, BaseContext, EmptySteps, EmptyDeps>;
25
- /**
26
- * Represents any Flow with flexible input, context, steps, and dependencies.
27
- * This type is intentionally more permissive to allow for better type inference
28
- * in utility types like StepOutput.
29
- */
30
- export type AnyFlow = Flow<any, any, any, any>;
31
- /**
32
- * Extracts the input type from a Flow
33
- * @template TFlow - The Flow type to extract from
34
- */
35
- export type ExtractFlowInput<TFlow extends AnyFlow> = TFlow extends Flow<infer TI, infer _TC, infer _TS, infer _TD> ? TI : never;
36
- /**
37
- * Utility type to extract all possible step inputs from a flow
38
- * This creates a union of all step input types
39
- */
40
- export type AllStepInputs<TFlow extends AnyFlow> = {
41
- [K in keyof ExtractFlowSteps<TFlow> & string]: StepInput<TFlow, K>;
42
- }[keyof ExtractFlowSteps<TFlow> & string];
43
- /**
44
- * Extracts the output type from a Flow
45
- * @template TFlow - The Flow type to extract from
46
- */
47
- export type ExtractFlowOutput<TFlow extends AnyFlow> = TFlow extends Flow<infer _TI, infer _TC, infer _TS, infer _TD> ? {
48
- [K in keyof ExtractFlowLeafSteps<TFlow> as K extends string ? K : never]: StepOutput<TFlow, K & string>;
49
- } : never;
50
- /**
51
- * Extracts the steps type from a Flow
52
- * @template TFlow - The Flow type to extract from
53
- */
54
- export type ExtractFlowSteps<TFlow extends AnyFlow> = TFlow extends Flow<infer _TI, infer _TC, infer TS, infer _TD> ? TS : never;
55
- /**
56
- * Extracts the dependencies type from a Flow
57
- * @template TFlow - The Flow type to extract from
58
- */
59
- export type ExtractFlowDeps<TFlow extends AnyFlow> = TFlow extends Flow<infer _TI, infer _TC, infer _TS, infer TD> ? TD : never;
60
- /**
61
- * Extracts the context type from a Flow
62
- * @template TFlow - The Flow type to extract from
63
- */
64
- export type ExtractFlowContext<TFlow extends AnyFlow> = TFlow extends Flow<infer _TI, infer TC, infer _TS, infer _TD> ? TC : never;
65
- /**
66
- * Extracts the dependencies type from a Flow
67
- * @template TFlow - The Flow type to extract from
68
- */
69
- type StepDepsOf<TFlow extends AnyFlow, TStepSlug extends string> = TStepSlug extends keyof ExtractFlowDeps<TFlow> ? ExtractFlowDeps<TFlow>[TStepSlug][number] : never;
70
- /**
71
- * Extracts only the leaf steps from a Flow (steps that are not dependencies of any other steps)
72
- * @template TFlow - The Flow type to extract from
73
- */
74
- export type ExtractFlowLeafSteps<TFlow extends AnyFlow> = {
75
- [K in keyof ExtractFlowSteps<TFlow> as K extends string ? K extends ExtractFlowDeps<TFlow>[keyof ExtractFlowDeps<TFlow>][number] ? never : K : never]: ExtractFlowSteps<TFlow>[K];
76
- };
77
- export type StepOutput<TFlow extends AnyFlow, TStepSlug extends string> = TStepSlug extends keyof ExtractFlowSteps<TFlow> ? ExtractFlowSteps<TFlow>[TStepSlug] : never;
78
- /**
79
- * This ensures that:
80
- * 1. The run input is always included
81
- * 2. Only declared dependencies are included
82
- * 3. No extra properties are allowed
83
- * Utility type to extract the input type for a specific step in a flow
84
- */
85
- export type StepInput<TFlow extends AnyFlow, TStepSlug extends string> = {
86
- run: ExtractFlowInput<TFlow>;
87
- } & {
88
- [K in Extract<keyof ExtractFlowSteps<TFlow>, StepDepsOf<TFlow, TStepSlug>>]: ExtractFlowSteps<TFlow>[K];
89
- };
90
- export interface RuntimeOptions {
91
- maxAttempts?: number;
92
- baseDelay?: number;
93
- timeout?: number;
94
- }
95
- export interface BaseContext {
96
- env: Env & ValidEnv<UserEnv>;
97
- shutdownSignal: AbortSignal;
98
- }
99
- export type Context<T extends Record<string, unknown> = Record<string, never>> = BaseContext & T;
100
- type ExtractHandlerContext<T> = T extends (input: any, context: infer C) => any ? C : never;
101
- export interface StepRuntimeOptions extends RuntimeOptions {
102
- startDelay?: number;
103
- }
104
- export interface StepDefinition<TInput extends AnyInput, TOutput extends AnyOutput, TContext = BaseContext> {
105
- slug: string;
106
- handler: (input: TInput, context: TContext) => TOutput | Promise<TOutput>;
107
- dependencies: string[];
108
- options: StepRuntimeOptions;
109
- }
110
- export declare class Flow<TFlowInput extends AnyInput = AnyInput, TContext = BaseContext, // Accumulated context requirements (starts with BaseContext)
111
- Steps extends AnySteps = EmptySteps, StepDependencies extends AnyDeps = EmptyDeps> {
112
- /**
113
- * Store step definitions with their proper types
114
- *
115
- * This is typed as a generic record because TypeScript cannot track the exact relationship
116
- * between step slugs and their corresponding input/output types at the container level.
117
- * Type safety is enforced at the method level when adding or retrieving steps.
118
- */
119
- private stepDefinitions;
120
- readonly stepOrder: string[];
121
- readonly slug: string;
122
- readonly options: RuntimeOptions;
123
- constructor(config: Simplify<{
124
- slug: string;
125
- } & RuntimeOptions>, stepDefinitions?: Record<string, StepDefinition<AnyInput, AnyOutput>>, stepOrder?: string[]);
126
- /**
127
- * Get a specific step definition by slug with proper typing
128
- * @throws Error if the step with the given slug doesn't exist
129
- */
130
- getStepDefinition<SlugType extends keyof Steps & keyof StepDependencies>(slug: SlugType): StepDefinition<Simplify<{
131
- run: TFlowInput;
132
- } & {
133
- [K in StepDependencies[SlugType][number]]: K extends keyof Steps ? Steps[K] : never;
134
- }>, Steps[SlugType]>;
135
- step<Slug extends string, THandler extends (input: Simplify<{
136
- run: TFlowInput;
137
- } & {
138
- [K in Deps]: K extends keyof Steps ? Steps[K] : never;
139
- }>, context: BaseContext & TContext) => any, Deps extends Extract<keyof Steps, string> = never>(opts: Simplify<{
140
- slug: Slug;
141
- dependsOn?: Deps[];
142
- } & StepRuntimeOptions>, handler: THandler): Flow<TFlowInput, TContext & BaseContext & ExtractHandlerContext<THandler>, Steps & {
143
- [K in Slug]: AwaitedReturn<THandler>;
144
- }, StepDependencies & {
145
- [K in Slug]: Deps[];
146
- }>;
147
- }
148
- export {};
149
- //# sourceMappingURL=dsl.d.ts.map
package/dist/dsl.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"dsl.d.ts","sourceRoot":"","sources":["../src/dsl.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,IAAI,GACZ,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,IAAI,EAAE,GACN;IAAE,CAAC,GAAG,EAAE,MAAM,GAA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AAW,GAAG,qBAAqB,CAAC,QAAQ,CAAC,EACxD,KAAK,GAAG;SAAG,CAAC,IAAI,IAAI,GAAG,aAAa,CAAC,QAAQ,CAAC;KAAE,EAChD,gBAAgB,GAAG;SAAG,CAAC,IAAI,IAAI,GAAG,IAAI,EAAE;KAAE,CAC3C;CAyEF"}
package/dist/dsl.js DELETED
@@ -1,90 +0,0 @@
1
- import { validateRuntimeOptions, validateSlug } from './utils.js';
2
- // Flow class definition
3
- export class Flow {
4
- /**
5
- * Store step definitions with their proper types
6
- *
7
- * This is typed as a generic record because TypeScript cannot track the exact relationship
8
- * between step slugs and their corresponding input/output types at the container level.
9
- * Type safety is enforced at the method level when adding or retrieving steps.
10
- */
11
- stepDefinitions;
12
- stepOrder;
13
- slug;
14
- options;
15
- constructor(config, stepDefinitions = {}, stepOrder = []) {
16
- // Extract slug and options separately
17
- const { slug, ...options } = config;
18
- // Validate the slug
19
- validateSlug(slug);
20
- // Validate runtime options (optional for Flow level)
21
- validateRuntimeOptions(options, { optional: true });
22
- this.slug = slug;
23
- this.options = options;
24
- this.stepDefinitions = stepDefinitions;
25
- // Defensive copy of stepOrder
26
- this.stepOrder = [...stepOrder];
27
- }
28
- /**
29
- * Get a specific step definition by slug with proper typing
30
- * @throws Error if the step with the given slug doesn't exist
31
- */
32
- getStepDefinition(slug) {
33
- // Check if the slug exists in stepDefinitions using a more explicit pattern
34
- if (!(slug in this.stepDefinitions)) {
35
- throw new Error(`Step "${String(slug)}" does not exist in flow "${this.slug}"`);
36
- }
37
- // Use a type assertion directive to tell TypeScript that this is safe
38
- // @ts-expect-error The type system cannot track that this.stepDefinitions[slug] has the correct type
39
- // but we know it's safe because we only add steps through the strongly-typed `step` method
40
- return this.stepDefinitions[slug];
41
- }
42
- // SlugType extends keyof Steps & keyof StepDependencies
43
- step(opts, handler) {
44
- const slug = opts.slug;
45
- // Validate the step slug
46
- validateSlug(slug);
47
- if (this.stepDefinitions[slug]) {
48
- throw new Error(`Step "${slug}" already exists in flow "${this.slug}"`);
49
- }
50
- const dependencies = opts.dependsOn || [];
51
- // Validate dependencies - check if all referenced steps exist
52
- if (dependencies.length > 0) {
53
- for (const dep of dependencies) {
54
- if (!this.stepDefinitions[dep]) {
55
- throw new Error(`Step "${slug}" depends on undefined step "${dep}"`);
56
- }
57
- }
58
- }
59
- // Extract RuntimeOptions from opts
60
- const options = {};
61
- if (opts.maxAttempts !== undefined)
62
- options.maxAttempts = opts.maxAttempts;
63
- if (opts.baseDelay !== undefined)
64
- options.baseDelay = opts.baseDelay;
65
- if (opts.timeout !== undefined)
66
- options.timeout = opts.timeout;
67
- if (opts.startDelay !== undefined)
68
- options.startDelay = opts.startDelay;
69
- // Validate runtime options (optional for step level)
70
- validateRuntimeOptions(options, { optional: true });
71
- // Preserve the exact type of the handler
72
- const newStepDefinition = {
73
- slug,
74
- handler: handler, // Type assertion needed due to complex generic constraints
75
- dependencies: dependencies,
76
- options,
77
- };
78
- const newStepDefinitions = {
79
- ...this.stepDefinitions,
80
- [slug]: newStepDefinition,
81
- };
82
- // Create a new stepOrder array with the new slug appended
83
- const newStepOrder = [...this.stepOrder, slug];
84
- // Create a new flow with the same slug and options but with updated type parameters
85
- // We need to use type assertions here because TypeScript cannot track the exact relationship
86
- // between the specific step definition types and the generic Flow type parameters
87
- // This is safe because we're constructing the newStepDefinitions in a type-safe way above
88
- return new Flow({ slug: this.slug, ...this.options }, newStepDefinitions, newStepOrder);
89
- }
90
- }
@@ -1,29 +0,0 @@
1
- import { Flow } from './dsl.js';
2
- type Input = {
3
- url: string;
4
- };
5
- export declare const AnalyzeWebsite: Flow<Input, import("./dsl.js").BaseContext, import("./dsl.js").EmptySteps & {
6
- website: {
7
- content: string;
8
- };
9
- } & {
10
- sentiment: {
11
- score: number;
12
- };
13
- } & {
14
- summary: {
15
- aiSummary: string;
16
- };
17
- } & {
18
- saveToDb: string;
19
- }, import("./dsl.js").EmptyDeps & {
20
- website: never[];
21
- } & {
22
- sentiment: "website"[];
23
- } & {
24
- summary: "website"[];
25
- } & {
26
- saveToDb: ("sentiment" | "summary")[];
27
- }>;
28
- export {};
29
- //# sourceMappingURL=example-flow.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"example-flow.d.ts","sourceRoot":"","sources":["../src/example-flow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAGhC,KAAK,KAAK,GAAG;IACX,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;EA4BxB,CAAC"}
@@ -1,41 +0,0 @@
1
- import { Flow } from './dsl.js';
2
- export const AnalyzeWebsite = new Flow({
3
- slug: 'analyze_website',
4
- maxAttempts: 3,
5
- baseDelay: 5,
6
- timeout: 10,
7
- })
8
- .step({ slug: 'website' }, async (input) => await scrapeWebsite(input.run.url))
9
- .step({ slug: 'sentiment', dependsOn: ['website'], timeout: 30, maxAttempts: 5 }, async (input) => await analyzeSentiment(input.website.content))
10
- .step({ slug: 'summary', dependsOn: ['website'] }, async (input) => await summarizeWithAI(input.website.content))
11
- .step({ slug: 'saveToDb', dependsOn: ['sentiment', 'summary'] }, async (input) => {
12
- const results = await saveToDb({
13
- websiteUrl: input.run.url,
14
- sentiment: input.sentiment.score,
15
- summary: input.summary.aiSummary,
16
- });
17
- return results.status;
18
- });
19
- /***********************************************************************
20
- ****** functions *******************************************************
21
- ***********************************************************************/
22
- async function scrapeWebsite(url) {
23
- return {
24
- content: `Lorem ipsum ${url.length}`,
25
- };
26
- }
27
- const analyzeSentiment = async (_content) => {
28
- return {
29
- score: Math.random(),
30
- };
31
- };
32
- const summarizeWithAI = async (content) => {
33
- return {
34
- aiSummary: `Lorem ipsum ${content.length}`,
35
- };
36
- };
37
- const saveToDb = async (_input) => {
38
- return {
39
- status: 'success',
40
- };
41
- };
package/dist/index.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from './dsl.js';
2
- export * from './compile-flow.js';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,mBAAmB,CAAC"}
package/dist/index.js DELETED
@@ -1,2 +0,0 @@
1
- export * from './dsl.js';
2
- export * from './compile-flow.js';
package/dist/package.json DELETED
@@ -1,35 +0,0 @@
1
- {
2
- "name": "@pgflow/dsl",
3
- "version": "0.6.0",
4
- "type": "module",
5
- "main": "./dist/index.js",
6
- "module": "./dist/index.js",
7
- "types": "./dist/index.d.ts",
8
- "files": [
9
- "dist"
10
- ],
11
- "private": false,
12
- "exports": {
13
- "./package.json": "./package.json",
14
- ".": {
15
- "types": "./dist/index.d.ts",
16
- "import": "./dist/index.js"
17
- },
18
- "./platforms": {
19
- "types": "./dist/platforms/index.d.ts",
20
- "import": "./dist/platforms/index.js"
21
- },
22
- "./supabase": {
23
- "types": "./dist/platforms/supabase.d.ts",
24
- "import": "./dist/platforms/supabase.js"
25
- }
26
- },
27
- "publishConfig": {
28
- "access": "public"
29
- },
30
- "devDependencies": {
31
- "@types/node": "^22.14.1",
32
- "postgres": "^3.4.5",
33
- "@supabase/supabase-js": "^2.47.10"
34
- }
35
- }
@@ -1,2 +0,0 @@
1
- export type { BaseContext, Context } from '../index.js';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/platforms/index.ts"],"names":[],"mappings":"AACA,YAAY,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- // Future: utility types for platform implementations can go here
@@ -1,32 +0,0 @@
1
- import type { Sql } from 'postgres';
2
- import type { SupabaseClient } from '@supabase/supabase-js';
3
- import { Flow as CoreFlow, type AnyInput, type AnySteps, type AnyDeps, EmptySteps, EmptyDeps, type Env, type UserEnv, type ValidEnv, type AnyFlow, type Json, type BaseContext } from '../index.js';
4
- export interface SupabaseResources extends Record<string, unknown> {
5
- sql: Sql;
6
- /**
7
- * Supabase client with service role key for full database access
8
- */
9
- supabase: SupabaseClient;
10
- }
11
- export interface SupabaseEnv extends Env {
12
- EDGE_WORKER_DB_URL: string;
13
- SUPABASE_URL: string;
14
- SUPABASE_ANON_KEY: string;
15
- SUPABASE_SERVICE_ROLE_KEY: string;
16
- SB_EXECUTION_ID: string;
17
- EDGE_WORKER_LOG_LEVEL?: string;
18
- }
19
- export type SupabasePlatformContext = BaseContext & SupabaseResources & {
20
- env: SupabaseEnv & ValidEnv<UserEnv>;
21
- };
22
- export type SupabaseMessageContext<T extends Json = Json> = SupabasePlatformContext & {
23
- rawMessage: any;
24
- };
25
- export type SupabaseStepTaskContext<F extends AnyFlow = AnyFlow> = SupabasePlatformContext & {
26
- rawMessage: any;
27
- stepTask: any;
28
- };
29
- export declare class Flow<I extends AnyInput = AnyInput, ExtraCtx extends Record<string, unknown> = Record<string, never>, S extends AnySteps = EmptySteps, D extends AnyDeps = EmptyDeps> extends CoreFlow<I, SupabasePlatformContext & ExtraCtx, // <── full ctx in handlers
30
- S, D> {
31
- }
32
- //# sourceMappingURL=supabase.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"supabase.d.ts","sourceRoot":"","sources":["../../src/platforms/supabase.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EACL,IAAI,IAAI,QAAQ,EAChB,KAAK,QAAQ,EAAE,KAAK,QAAQ,EAAE,KAAK,OAAO,EAC1C,UAAU,EAAE,SAAS,EAAE,KAAK,GAAG,EAAE,KAAK,OAAO,EAAE,KAAK,QAAQ,EAC5D,KAAK,OAAO,EAAE,KAAK,IAAI,EAAE,KAAK,WAAW,EAC1C,MAAM,aAAa,CAAC;AAGrB,MA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class Flow extends CoreFlow {
4
- }
@@ -1,2 +0,0 @@
1
- export * from './platforms/supabase.js';
2
- //# sourceMappingURL=supabase.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"supabase.d.ts","sourceRoot":"","sources":["../src/supabase.ts"],"names":[],"mappings":"AACA,cAAc,yBAAyB,CAAC"}
package/dist/supabase.js DELETED
@@ -1,2 +0,0 @@
1
- // Re-export everything from platforms/supabase
2
- export * from './platforms/supabase.js';
@@ -1 +0,0 @@
1
- {"version":"5.8.3"}
package/dist/utils.d.ts DELETED
@@ -1,37 +0,0 @@
1
- /**
2
- * Validates a slug string according to the following rules:
3
- * - Cannot start with a number
4
- * - Cannot start with an underscore
5
- * - Cannot contain spaces
6
- * - Cannot contain special characters like /, :, ?, #
7
- * - Cannot be longer than 128 characters
8
- *
9
- * @param slug The slug string to validate
10
- * @throws Error if the slug is invalid
11
- */
12
- export declare function validateSlug(slug: string): void;
13
- /**
14
- * Options for validating runtime options
15
- */
16
- export interface ValidateRuntimeOptionsOpts {
17
- optional?: boolean;
18
- }
19
- /**
20
- * Validates runtime options according to the following rules:
21
- * - maxAttempts should be >= 1
22
- * - baseDelay should be >= 1
23
- * - timeout should be >= 3
24
- * - startDelay should be >= 0
25
- *
26
- * @param options The runtime options to validate
27
- * @param opts Configuration options for validation
28
- * @param opts.optional If true, allows options to be null or undefined
29
- * @throws Error if any runtime option is invalid
30
- */
31
- export declare function validateRuntimeOptions(options: {
32
- maxAttempts?: number;
33
- baseDelay?: number;
34
- timeout?: number;
35
- startDelay?: number;
36
- }, opts?: ValidateRuntimeOptionsOpts): void;
37
- //# sourceMappingURL=utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAsB/C;AAED;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE;IAAE,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,EAC5F,IAAI,GAAE,0BAAgD,GACrD,IAAI,CAiCN"}
package/dist/utils.js DELETED
@@ -1,73 +0,0 @@
1
- /**
2
- * Validates a slug string according to the following rules:
3
- * - Cannot start with a number
4
- * - Cannot start with an underscore
5
- * - Cannot contain spaces
6
- * - Cannot contain special characters like /, :, ?, #
7
- * - Cannot be longer than 128 characters
8
- *
9
- * @param slug The slug string to validate
10
- * @throws Error if the slug is invalid
11
- */
12
- export function validateSlug(slug) {
13
- if (slug.length > 128) {
14
- throw new Error(`Slug '${slug}' cannot be longer than 128 characters`);
15
- }
16
- if (/^\d/.test(slug)) {
17
- throw new Error(`Slug '${slug}' cannot start with a number`);
18
- }
19
- if (/^_/.test(slug)) {
20
- throw new Error(`Slug '${slug}' cannot start with an underscore`);
21
- }
22
- if (/\s/.test(slug)) {
23
- throw new Error(`Slug '${slug}' cannot contain spaces`);
24
- }
25
- if (/[/:#\-?]/.test(slug)) {
26
- throw new Error(`Slug '${slug}' cannot contain special characters like /, :, ?, #, -`);
27
- }
28
- }
29
- /**
30
- * Validates runtime options according to the following rules:
31
- * - maxAttempts should be >= 1
32
- * - baseDelay should be >= 1
33
- * - timeout should be >= 3
34
- * - startDelay should be >= 0
35
- *
36
- * @param options The runtime options to validate
37
- * @param opts Configuration options for validation
38
- * @param opts.optional If true, allows options to be null or undefined
39
- * @throws Error if any runtime option is invalid
40
- */
41
- export function validateRuntimeOptions(options, opts = { optional: false }) {
42
- const { maxAttempts, baseDelay, timeout, startDelay } = options;
43
- // If optional is true, skip validation for undefined/null values
44
- if (maxAttempts !== undefined && maxAttempts !== null) {
45
- if (maxAttempts < 1) {
46
- throw new Error('maxAttempts must be greater than or equal to 1');
47
- }
48
- }
49
- else if (!opts.optional) {
50
- throw new Error('maxAttempts is required');
51
- }
52
- if (baseDelay !== undefined && baseDelay !== null) {
53
- if (baseDelay < 1) {
54
- throw new Error('baseDelay must be greater than or equal to 1');
55
- }
56
- }
57
- else if (!opts.optional) {
58
- throw new Error('baseDelay is required');
59
- }
60
- if (timeout !== undefined && timeout !== null) {
61
- if (timeout < 3) {
62
- throw new Error('timeout must be greater than or equal to 3');
63
- }
64
- }
65
- else if (!opts.optional) {
66
- throw new Error('timeout is required');
67
- }
68
- if (startDelay !== undefined && startDelay !== null) {
69
- if (startDelay < 0) {
70
- throw new Error('startDelay must be greater than or equal to 0');
71
- }
72
- }
73
- }