@pgflow/core 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.
Files changed (38) hide show
  1. package/README.md +1 -7
  2. package/package.json +2 -2
  3. package/dist/ATLAS.md +0 -32
  4. package/dist/CHANGELOG.md +0 -645
  5. package/dist/PLAN_race_condition_testing.md +0 -176
  6. package/dist/PgflowSqlClient.d.ts +0 -17
  7. package/dist/PgflowSqlClient.d.ts.map +0 -1
  8. package/dist/PgflowSqlClient.js +0 -70
  9. package/dist/README.md +0 -399
  10. package/dist/database-types.d.ts +0 -832
  11. package/dist/database-types.d.ts.map +0 -1
  12. package/dist/database-types.js +0 -8
  13. package/dist/index.d.ts +0 -4
  14. package/dist/index.d.ts.map +0 -1
  15. package/dist/index.js +0 -2
  16. package/dist/package.json +0 -32
  17. package/dist/supabase/migrations/20250429164909_pgflow_initial.sql +0 -579
  18. package/dist/supabase/migrations/20250517072017_pgflow_fix_poll_for_tasks_to_use_separate_statement_for_polling.sql +0 -101
  19. package/dist/supabase/migrations/20250609105135_pgflow_add_start_tasks_and_started_status.sql +0 -371
  20. package/dist/supabase/migrations/20250610180554_pgflow_add_set_vt_batch_and_use_it_in_start_tasks.sql +0 -127
  21. package/dist/supabase/migrations/20250614124241_pgflow_add_realtime.sql +0 -501
  22. package/dist/supabase/migrations/20250619195327_pgflow_fix_fail_task_missing_realtime_event.sql +0 -185
  23. package/dist/supabase/migrations/20250627090700_pgflow_fix_function_search_paths.sql +0 -6
  24. package/dist/supabase/migrations/20250707210212_pgflow_add_opt_start_delay.sql +0 -103
  25. package/dist/supabase/migrations/20250719205006_pgflow_worker_deprecation.sql +0 -2
  26. package/dist/supabase/migrations/20250912075001_pgflow_temp_pr1_schema.sql +0 -185
  27. package/dist/supabase/migrations/20250912080800_pgflow_temp_pr2_root_maps.sql +0 -95
  28. package/dist/supabase/migrations/20250912125339_pgflow_TEMP_task_spawning_optimization.sql +0 -146
  29. package/dist/supabase/migrations/20250916093518_pgflow_temp_add_cascade_complete.sql +0 -321
  30. package/dist/supabase/migrations/20250916142327_pgflow_temp_make_initial_tasks_nullable.sql +0 -624
  31. package/dist/supabase/migrations/20250916203905_pgflow_temp_handle_arrays_in_start_tasks.sql +0 -157
  32. package/dist/supabase/migrations/20250918042753_pgflow_temp_handle_map_output_aggregation.sql +0 -489
  33. package/dist/supabase/migrations/20250919101802_pgflow_temp_orphaned_messages_index.sql +0 -688
  34. package/dist/supabase/migrations/20250919135211_pgflow_temp_return_task_index_in_start_tasks.sql +0 -178
  35. package/dist/tsconfig.lib.tsbuildinfo +0 -1
  36. package/dist/types.d.ts +0 -95
  37. package/dist/types.d.ts.map +0 -1
  38. package/dist/types.js +0 -1
@@ -1,178 +0,0 @@
1
- -- Modify "step_task_record" composite type
2
- ALTER TYPE "pgflow"."step_task_record" ADD ATTRIBUTE "task_index" integer;
3
- -- Modify "start_tasks" function
4
- CREATE OR REPLACE FUNCTION "pgflow"."start_tasks" ("flow_slug" text, "msg_ids" bigint[], "worker_id" uuid) RETURNS SETOF "pgflow"."step_task_record" LANGUAGE sql SET "search_path" = '' AS $$
5
- with tasks as (
6
- select
7
- task.flow_slug,
8
- task.run_id,
9
- task.step_slug,
10
- task.task_index,
11
- task.message_id
12
- from pgflow.step_tasks as task
13
- join pgflow.runs r on r.run_id = task.run_id
14
- where task.flow_slug = start_tasks.flow_slug
15
- and task.message_id = any(msg_ids)
16
- and task.status = 'queued'
17
- -- MVP: Don't start tasks on failed runs
18
- and r.status != 'failed'
19
- ),
20
- start_tasks_update as (
21
- update pgflow.step_tasks
22
- set
23
- attempts_count = attempts_count + 1,
24
- status = 'started',
25
- started_at = now(),
26
- last_worker_id = worker_id
27
- from tasks
28
- where step_tasks.message_id = tasks.message_id
29
- and step_tasks.flow_slug = tasks.flow_slug
30
- and step_tasks.status = 'queued'
31
- ),
32
- runs as (
33
- select
34
- r.run_id,
35
- r.input
36
- from pgflow.runs r
37
- where r.run_id in (select run_id from tasks)
38
- ),
39
- deps as (
40
- select
41
- st.run_id,
42
- st.step_slug,
43
- dep.dep_slug,
44
- -- Aggregate map outputs or use single output
45
- CASE
46
- WHEN dep_step.step_type = 'map' THEN
47
- -- Aggregate all task outputs ordered by task_index
48
- -- Use COALESCE to return empty array if no tasks
49
- (SELECT COALESCE(jsonb_agg(dt.output ORDER BY dt.task_index), '[]'::jsonb)
50
- FROM pgflow.step_tasks dt
51
- WHERE dt.run_id = st.run_id
52
- AND dt.step_slug = dep.dep_slug
53
- AND dt.status = 'completed')
54
- ELSE
55
- -- Single step: use the single task output
56
- dep_task.output
57
- END as dep_output
58
- from tasks st
59
- join pgflow.deps dep on dep.flow_slug = st.flow_slug and dep.step_slug = st.step_slug
60
- join pgflow.steps dep_step on dep_step.flow_slug = dep.flow_slug and dep_step.step_slug = dep.dep_slug
61
- left join pgflow.step_tasks dep_task on
62
- dep_task.run_id = st.run_id and
63
- dep_task.step_slug = dep.dep_slug and
64
- dep_task.status = 'completed'
65
- and dep_step.step_type = 'single' -- Only join for single steps
66
- ),
67
- deps_outputs as (
68
- select
69
- d.run_id,
70
- d.step_slug,
71
- jsonb_object_agg(d.dep_slug, d.dep_output) as deps_output,
72
- count(*) as dep_count
73
- from deps d
74
- group by d.run_id, d.step_slug
75
- ),
76
- timeouts as (
77
- select
78
- task.message_id,
79
- task.flow_slug,
80
- coalesce(step.opt_timeout, flow.opt_timeout) + 2 as vt_delay
81
- from tasks task
82
- join pgflow.flows flow on flow.flow_slug = task.flow_slug
83
- join pgflow.steps step on step.flow_slug = task.flow_slug and step.step_slug = task.step_slug
84
- ),
85
- -- Batch update visibility timeouts for all messages
86
- set_vt_batch as (
87
- select pgflow.set_vt_batch(
88
- start_tasks.flow_slug,
89
- array_agg(t.message_id order by t.message_id),
90
- array_agg(t.vt_delay order by t.message_id)
91
- )
92
- from timeouts t
93
- )
94
- select
95
- st.flow_slug,
96
- st.run_id,
97
- st.step_slug,
98
- -- ==========================================
99
- -- INPUT CONSTRUCTION LOGIC
100
- -- ==========================================
101
- -- This nested CASE statement determines how to construct the input
102
- -- for each task based on the step type (map vs non-map).
103
- --
104
- -- The fundamental difference:
105
- -- - Map steps: Receive RAW array elements (e.g., just 42 or "hello")
106
- -- - Non-map steps: Receive structured objects with named keys
107
- -- (e.g., {"run": {...}, "dependency1": {...}})
108
- -- ==========================================
109
- CASE
110
- -- -------------------- MAP STEPS --------------------
111
- -- Map steps process arrays element-by-element.
112
- -- Each task receives ONE element from the array at its task_index position.
113
- WHEN step.step_type = 'map' THEN
114
- -- Map steps get raw array elements without any wrapper object
115
- CASE
116
- -- ROOT MAP: Gets array from run input
117
- -- Example: run input = [1, 2, 3]
118
- -- task 0 gets: 1
119
- -- task 1 gets: 2
120
- -- task 2 gets: 3
121
- WHEN step.deps_count = 0 THEN
122
- -- Root map (deps_count = 0): no dependencies, reads from run input.
123
- -- Extract the element at task_index from the run's input array.
124
- -- Note: If run input is not an array, this will return NULL
125
- -- and the flow will fail (validated in start_flow).
126
- jsonb_array_element(r.input, st.task_index)
127
-
128
- -- DEPENDENT MAP: Gets array from its single dependency
129
- -- Example: dependency output = ["a", "b", "c"]
130
- -- task 0 gets: "a"
131
- -- task 1 gets: "b"
132
- -- task 2 gets: "c"
133
- ELSE
134
- -- Has dependencies (should be exactly 1 for map steps).
135
- -- Extract the element at task_index from the dependency's output array.
136
- --
137
- -- Why the subquery with jsonb_each?
138
- -- - The dependency outputs a raw array: [1, 2, 3]
139
- -- - deps_outputs aggregates it into: {"dep_name": [1, 2, 3]}
140
- -- - We need to unwrap and get just the array value
141
- -- - Map steps have exactly 1 dependency (enforced by add_step)
142
- -- - So jsonb_each will return exactly 1 row
143
- -- - We extract the 'value' which is the raw array [1, 2, 3]
144
- -- - Then get the element at task_index from that array
145
- (SELECT jsonb_array_element(value, st.task_index)
146
- FROM jsonb_each(dep_out.deps_output)
147
- LIMIT 1)
148
- END
149
-
150
- -- -------------------- NON-MAP STEPS --------------------
151
- -- Regular (non-map) steps receive ALL inputs as a structured object.
152
- -- This includes the original run input plus all dependency outputs.
153
- ELSE
154
- -- Non-map steps get structured input with named keys
155
- -- Example output: {
156
- -- "run": {"original": "input"},
157
- -- "step1": {"output": "from_step1"},
158
- -- "step2": {"output": "from_step2"}
159
- -- }
160
- --
161
- -- Build object with 'run' key containing original input
162
- jsonb_build_object('run', r.input) ||
163
- -- Merge with deps_output which already has dependency outputs
164
- -- deps_output format: {"dep1": output1, "dep2": output2, ...}
165
- -- If no dependencies, defaults to empty object
166
- coalesce(dep_out.deps_output, '{}'::jsonb)
167
- END as input,
168
- st.message_id as msg_id,
169
- st.task_index as task_index
170
- from tasks st
171
- join runs r on st.run_id = r.run_id
172
- join pgflow.steps step on
173
- step.flow_slug = st.flow_slug and
174
- step.step_slug = st.step_slug
175
- left join deps_outputs dep_out on
176
- dep_out.run_id = st.run_id and
177
- dep_out.step_slug = st.step_slug
178
- $$;
@@ -1 +0,0 @@
1
- {"version":"5.8.3"}
package/dist/types.d.ts DELETED
@@ -1,95 +0,0 @@
1
- import type { ExtractFlowSteps, StepInput, Simplify, AnyFlow, ExtractFlowInput } from '@pgflow/dsl';
2
- import type { Database } from './database-types.js';
3
- export type Json = string | number | boolean | null | {
4
- [key: string]: Json | undefined;
5
- } | Json[];
6
- /**
7
- * Record representing a task from pgflow.start_tasks
8
- *
9
- * Same as pgflow.step_task_record type, but with not-null fields and type argument for payload.
10
- * The input type is automatically inferred based on the step_slug using a discriminated union.
11
- * This ensures that each step only receives inputs from its declared dependencies and the flow's run input.
12
- */
13
- export type StepTaskRecord<TFlow extends AnyFlow> = {
14
- [StepSlug in Extract<keyof ExtractFlowSteps<TFlow>, string>]: {
15
- flow_slug: string;
16
- run_id: string;
17
- step_slug: StepSlug;
18
- task_index: number;
19
- input: Simplify<StepInput<TFlow, StepSlug>>;
20
- msg_id: number;
21
- };
22
- }[Extract<keyof ExtractFlowSteps<TFlow>, string>];
23
- /**
24
- * Composite key that is enough to find a particular step task
25
- * Contains only the minimum fields needed to identify a task
26
- */
27
- export type StepTaskKey = Pick<StepTaskRecord<any>, 'run_id' | 'step_slug' | 'task_index'>;
28
- /**
29
- * Record representing a message from queue polling
30
- */
31
- export type MessageRecord = {
32
- msg_id: number;
33
- read_ct: number;
34
- enqueued_at: string;
35
- vt: string;
36
- message: Json;
37
- };
38
- /**
39
- * Interface for interacting with pgflow database functions
40
- */
41
- export interface IPgflowClient<TFlow extends AnyFlow = AnyFlow> {
42
- /**
43
- * Start a flow with optional run_id
44
- */
45
- startFlow<TFlow extends AnyFlow>(flow_slug: string, input: ExtractFlowInput<TFlow>, run_id?: string): Promise<RunRow>;
46
- /**
47
- * Reads messages from queue without starting tasks (phase 1 of two-phase approach)
48
- * @param queueName - Name of the queue
49
- * @param visibilityTimeout - Visibility timeout for messages
50
- * @param batchSize - Number of messages to fetch
51
- * @param maxPollSeconds - Maximum time to poll for messages
52
- * @param pollIntervalMs - Poll interval in milliseconds
53
- */
54
- readMessages(queueName: string, visibilityTimeout: number, batchSize: number, maxPollSeconds?: number, pollIntervalMs?: number): Promise<MessageRecord[]>;
55
- /**
56
- * Starts tasks for given message IDs (phase 2 of two-phase approach)
57
- * @param flowSlug - The flow slug to start tasks from
58
- * @param msgIds - Array of message IDs from readMessages
59
- * @param workerId - ID of the worker starting the tasks
60
- */
61
- startTasks(flowSlug: string, msgIds: number[], workerId: string): Promise<StepTaskRecord<TFlow>[]>;
62
- /**
63
- * Mark a task as completed with output
64
- */
65
- completeTask(stepTask: StepTaskKey, output?: Json): Promise<void>;
66
- /**
67
- * Mark a task as failed with error
68
- */
69
- failTask(stepTask: StepTaskKey, error: unknown): Promise<void>;
70
- }
71
- /**
72
- * Record representing a flow from pgflow.flows
73
- */
74
- export type FlowRow = Database['pgflow']['Tables']['flows']['Row'];
75
- /**
76
- * Record representing a step from pgflow.steps
77
- */
78
- export type StepRow = Database['pgflow']['Tables']['steps']['Row'];
79
- /**
80
- * Record representing a step from pgflow.deps
81
- */
82
- export type DepRow = Database['pgflow']['Tables']['deps']['Row'];
83
- /**
84
- * Record representing a step from pgflow.queues
85
- */
86
- export type RunRow = Database['pgflow']['Tables']['runs']['Row'];
87
- /**
88
- * Record representing a step from pgflow.step_states
89
- */
90
- export type StepStateRow = Database['pgflow']['Tables']['step_states']['Row'];
91
- /**
92
- * Record representing a step from pgflow.step_tasks
93
- */
94
- export type StepTaskRow = Database['pgflow']['Tables']['step_tasks']['Row'];
95
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,SAAS,EACT,QAAQ,EACR,OAAO,EACP,gBAAgB,EACjB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAEpD,MAAM,MAAM,IAAI,GACZ,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAA;CAAE,GACnC,IAAI,EAAE,CAAC;AAEX;;;;;;GAMG;AACH,MAAM,MAAM,cAAc,CAAC,KAAK,SAAS,OAAO,IAAI;KACjD,QAAQ,IAAI,OAAO,CAAC,MAAM,gBAAgB,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,GAAG;QAC5D,SAAS,EAAE,MAAM,CAAC;QAClB,MAAM,EAAE,MAAM,CAAC;QACf,SAAS,EAAE,QAAQ,CAAC;QACpB,UAAU,EAAE,MAAM,CAAC;QACnB,KAAK,EAAE,QAAQ,CAAC,SAAS,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC;QAC5C,MAAM,EAAE,MAAM,CAAC;KAChB;CACF,CAAC,OAAO,CAAC,MAAM,gBAAgB,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC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