@pgflow/dsl 0.0.0-array-map-steps-302d00a8-20250922101336 → 0.0.0-test-snapshot-releases2-8d5d9bc1-20250922101158

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/dist/dsl.js DELETED
@@ -1,159 +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
- /**
91
- * Add an array-returning step to the flow with compile-time type safety
92
- *
93
- * This method provides semantic clarity and type enforcement for steps that return arrays,
94
- * while maintaining full compatibility with the existing step system by delegating to `.step()`.
95
- *
96
- * @template Slug - The unique identifier for this step
97
- * @template THandler - The handler function that must return an array or Promise<array>
98
- * @template Deps - The step dependencies (must be existing step slugs)
99
- * @param opts - Step configuration including slug, dependencies, and runtime options
100
- * @param handler - Function that processes input and returns an array
101
- * @returns A new Flow instance with the array step added
102
- */
103
- array(opts, handler) {
104
- // Delegate to existing .step() method for maximum code reuse
105
- return this.step(opts, handler);
106
- }
107
- // Implementation
108
- map(opts, handler) {
109
- const slug = opts.slug;
110
- // Validate the step slug
111
- validateSlug(slug);
112
- if (this.stepDefinitions[slug]) {
113
- throw new Error(`Step "${slug}" already exists in flow "${this.slug}"`);
114
- }
115
- // Determine dependencies based on whether array is specified
116
- let dependencies = [];
117
- const arrayDep = opts.array;
118
- if (arrayDep) {
119
- // Dependent map - validate single dependency exists and returns array
120
- if (!this.stepDefinitions[arrayDep]) {
121
- throw new Error(`Step "${slug}" depends on undefined step "${arrayDep}"`);
122
- }
123
- dependencies = [arrayDep];
124
- }
125
- else {
126
- // Root map - flow input must be an array (type system enforces this)
127
- dependencies = [];
128
- }
129
- // Extract runtime options
130
- const options = {};
131
- if (opts.maxAttempts !== undefined)
132
- options.maxAttempts = opts.maxAttempts;
133
- if (opts.baseDelay !== undefined)
134
- options.baseDelay = opts.baseDelay;
135
- if (opts.timeout !== undefined)
136
- options.timeout = opts.timeout;
137
- if (opts.startDelay !== undefined)
138
- options.startDelay = opts.startDelay;
139
- // Validate runtime options
140
- validateRuntimeOptions(options, { optional: true });
141
- // Create the map step definition with stepType
142
- // Note: We use AnyInput/AnyOutput here because the actual types are handled at the type level via overloads
143
- const newStepDefinition = {
144
- slug,
145
- handler: handler, // Type assertion needed due to complex generic constraints
146
- dependencies,
147
- options,
148
- stepType: 'map', // Mark this as a map step
149
- };
150
- const newStepDefinitions = {
151
- ...this.stepDefinitions,
152
- [slug]: newStepDefinition,
153
- };
154
- // Create a new stepOrder array with the new slug appended
155
- const newStepOrder = [...this.stepOrder, slug];
156
- // Create and return new Flow instance with updated types
157
- return new Flow({ slug: this.slug, ...this.options }, newStepDefinitions, newStepOrder); // Type assertion handled by overloads
158
- }
159
- }
@@ -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.1",
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,E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,GAAG,QAAQ,EAAI,2BAA2B;AACjE,CAAC,EAAE,CAAC,CACL;CAAG"}
@@ -1,4 +0,0 @@
1
- import { Flow as CoreFlow } from '../index.js';
2
- /* ---------- 5. pre-wired Flow helper -------------------------------- */
3
- export 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
- }