@pgflow/client 0.0.0-array-map-steps-cd94242a-20251008042921 → 0.0.0-compatible-flow-86a8ccf0-20260319203539

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 (48) hide show
  1. package/CHANGELOG.md +171 -3
  2. package/README.md +6 -2
  3. package/dist/client/src/browser.d.ts +7 -0
  4. package/dist/client/src/browser.d.ts.map +1 -0
  5. package/dist/client/src/index.d.ts +6 -0
  6. package/dist/client/src/index.d.ts.map +1 -0
  7. package/dist/client/src/lib/FlowRun.d.ts +125 -0
  8. package/dist/client/src/lib/FlowRun.d.ts.map +1 -0
  9. package/dist/client/src/lib/FlowStep.d.ts +98 -0
  10. package/dist/client/src/lib/FlowStep.d.ts.map +1 -0
  11. package/dist/client/src/lib/PgflowClient.d.ts +76 -0
  12. package/dist/client/src/lib/PgflowClient.d.ts.map +1 -0
  13. package/dist/client/src/lib/SupabaseBroadcastAdapter.d.ts +66 -0
  14. package/dist/client/src/lib/SupabaseBroadcastAdapter.d.ts.map +1 -0
  15. package/dist/client/src/lib/eventAdapters.d.ts +21 -0
  16. package/dist/client/src/lib/eventAdapters.d.ts.map +1 -0
  17. package/dist/client/src/lib/types.d.ts +337 -0
  18. package/dist/client/src/lib/types.d.ts.map +1 -0
  19. package/dist/index.d.ts +1 -1
  20. package/dist/index.js +455 -454
  21. package/dist/index.js.map +1 -1
  22. package/dist/package.json +8 -3
  23. package/dist/pgflow-client.browser.js +1 -1
  24. package/dist/pgflow-client.browser.js.map +1 -1
  25. package/dist/src/browser.d.ts +3 -3
  26. package/dist/src/browser.d.ts.map +1 -1
  27. package/dist/src/browser.js +10 -0
  28. package/dist/src/index.js +7 -0
  29. package/dist/src/lib/FlowRun.d.ts +11 -3
  30. package/dist/src/lib/FlowRun.d.ts.map +1 -1
  31. package/dist/src/lib/FlowRun.js +372 -0
  32. package/dist/src/lib/FlowStep.d.ts +20 -4
  33. package/dist/src/lib/FlowStep.d.ts.map +1 -1
  34. package/dist/src/lib/FlowStep.js +284 -0
  35. package/dist/src/lib/PgflowClient.d.ts +12 -10
  36. package/dist/src/lib/PgflowClient.d.ts.map +1 -1
  37. package/dist/src/lib/PgflowClient.js +227 -0
  38. package/dist/src/lib/SupabaseBroadcastAdapter.d.ts +4 -4
  39. package/dist/src/lib/SupabaseBroadcastAdapter.d.ts.map +1 -1
  40. package/dist/src/lib/SupabaseBroadcastAdapter.js +332 -0
  41. package/dist/src/lib/eventAdapters.d.ts +3 -4
  42. package/dist/src/lib/eventAdapters.d.ts.map +1 -1
  43. package/dist/src/lib/eventAdapters.js +160 -0
  44. package/dist/src/lib/types.d.ts +34 -6
  45. package/dist/src/lib/types.d.ts.map +1 -1
  46. package/dist/src/lib/types.js +102 -0
  47. package/dist/tsconfig.lib.tsbuildinfo +1 -0
  48. package/package.json +10 -5
package/dist/index.js CHANGED
@@ -1,61 +1,65 @@
1
- var N = (e) => {
2
- throw TypeError(e);
1
+ var Q = (s) => {
2
+ throw TypeError(s);
3
3
  };
4
- var O = (e, t, s) => t.has(e) || N("Cannot " + s);
5
- var r = (e, t, s) => (O(e, t, "read from private field"), s ? s.call(e) : t.get(e)), c = (e, t, s) => t.has(e) ? N("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, s), g = (e, t, s, n) => (O(e, t, "write to private field"), n ? n.call(e, s) : t.set(e, s), s), w = (e, t, s) => (O(e, t, "access private method"), s);
6
- var H = (e, t, s, n) => ({
7
- set _(i) {
8
- g(e, t, i, s);
4
+ var H = (s, t, r) => t.has(s) || Q("Cannot " + r);
5
+ var e = (s, t, r) => (H(s, t, "read from private field"), r ? r.call(s) : t.get(s)), d = (s, t, r) => t.has(s) ? Q("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(s) : t.set(s, r), _ = (s, t, r, i) => (H(s, t, "write to private field"), i ? i.call(s, r) : t.set(s, r), r), m = (s, t, r) => (H(s, t, "access private method"), r);
6
+ var j = (s, t, r, i) => ({
7
+ set _(n) {
8
+ _(s, t, n, r);
9
9
  },
10
10
  get _() {
11
- return r(e, t, n);
11
+ return e(s, t, i);
12
12
  }
13
13
  });
14
14
  import { v4 as st } from "uuid";
15
15
  import { createNanoEvents as L } from "nanoevents";
16
- var u = /* @__PURE__ */ ((e) => (e.Started = "started", e.Completed = "completed", e.Failed = "failed", e))(u || {});
17
- function ct(e) {
18
- return !!e && typeof e == "object" && "run_id" in e && "flow_slug" in e && !("step_slug" in e) && "status" in e && (e.status === "started" || e.status === "completed" || e.status === "failed");
16
+ var h = /* @__PURE__ */ ((s) => (s.Started = "started", s.Completed = "completed", s.Failed = "failed", s))(h || {});
17
+ function pt(s) {
18
+ return !!s && typeof s == "object" && "run_id" in s && "flow_slug" in s && !("step_slug" in s) && "status" in s && (s.status === "started" || s.status === "completed" || s.status === "failed");
19
19
  }
20
- function pt(e) {
21
- return e.status === "started";
20
+ function dt(s) {
21
+ return s.status === "started";
22
22
  }
23
- function ht(e) {
24
- return e.status === "completed";
23
+ function ct(s) {
24
+ return s.status === "completed";
25
25
  }
26
- function _t(e) {
27
- return e.status === "failed";
26
+ function ht(s) {
27
+ return s.status === "failed";
28
28
  }
29
- var l = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Completed = "completed", e.Failed = "failed", e))(l || {});
30
- function K(e) {
31
- return !!e && typeof e == "object" && "run_id" in e && "step_slug" in e && "status" in e && (e.status === "started" || e.status === "completed" || e.status === "failed");
29
+ var u = /* @__PURE__ */ ((s) => (s.Created = "created", s.Started = "started", s.Completed = "completed", s.Failed = "failed", s.Skipped = "skipped", s))(u || {});
30
+ function O(s) {
31
+ return !!s && typeof s == "object" && "run_id" in s && "step_slug" in s && "status" in s && (s.status === "started" || s.status === "completed" || s.status === "failed" || s.status === "skipped");
32
32
  }
33
- function ft(e) {
34
- return K(e) && e.status === "started" && "event_type" in e && e.event_type === "step:started";
33
+ function _t(s) {
34
+ return O(s) && s.status === "started" && "event_type" in s && s.event_type === "step:started";
35
35
  }
36
- function mt(e) {
37
- return K(e) && e.status === "completed" && "event_type" in e && e.event_type === "step:completed";
36
+ function ft(s) {
37
+ return O(s) && s.status === "completed" && "event_type" in s && s.event_type === "step:completed";
38
38
  }
39
- function gt(e) {
40
- return K(e) && e.status === "failed" && "event_type" in e && e.event_type === "step:failed";
39
+ function mt(s) {
40
+ return O(s) && s.status === "failed" && "event_type" in s && s.event_type === "step:failed";
41
41
  }
42
- var S, C, F, M, I, f, j, X, z, Y, Z, v, k, G;
42
+ function gt(s) {
43
+ return O(s) && s.status === "skipped" && "event_type" in s && s.event_type === "step:skipped";
44
+ }
45
+ var E, k, C, I, W, A, f, G, X, K, Y, Z, v, M, N;
43
46
  class rt {
44
47
  /**
45
48
  * Creates a new instance of SupabaseBroadcastAdapter
46
49
  *
47
50
  * @param supabase - Supabase client instance
48
51
  */
49
- constructor(t, s = {}) {
50
- c(this, f);
51
- c(this, S);
52
- c(this, C, /* @__PURE__ */ new Map());
53
- c(this, F, L());
54
- c(this, M);
55
- c(this, I);
52
+ constructor(t, r = {}) {
53
+ d(this, f);
54
+ d(this, E);
55
+ d(this, k, /* @__PURE__ */ new Map());
56
+ d(this, C, L());
57
+ d(this, I);
58
+ d(this, W);
59
+ d(this, A);
56
60
  // Store unsubscribe functions per run ID for reference equality
57
- c(this, k, /* @__PURE__ */ new Map());
58
- g(this, S, t), g(this, M, s.reconnectDelayMs ?? 2e3), g(this, I, s.schedule ?? setTimeout);
61
+ d(this, M, /* @__PURE__ */ new Map());
62
+ _(this, E, t), _(this, I, r.reconnectDelayMs ?? 2e3), _(this, W, r.stabilizationDelayMs ?? 300), _(this, A, r.schedule ?? setTimeout.bind(globalThis));
59
63
  }
60
64
  /**
61
65
  * Fetches flow definition metadata from the database
@@ -63,17 +67,17 @@ class rt {
63
67
  * @param flow_slug - Flow slug to fetch
64
68
  */
65
69
  async fetchFlowDefinition(t) {
66
- const [s, n] = await Promise.all([
67
- r(this, S).schema("pgflow").from("flows").select("*").eq("flow_slug", t).single(),
68
- r(this, S).schema("pgflow").from("steps").select("*").eq("flow_slug", t).order("step_index", { ascending: !0 })
70
+ const [r, i] = await Promise.all([
71
+ e(this, E).schema("pgflow").from("flows").select("*").eq("flow_slug", t).single(),
72
+ e(this, E).schema("pgflow").from("steps").select("*").eq("flow_slug", t).order("step_index", { ascending: !0 })
69
73
  ]);
70
- if (s.error) throw s.error;
71
- if (!s.data) throw new Error(`Flow "${t}" not found`);
72
- if (n.error) throw n.error;
73
- const i = Array.isArray(n.data) ? n.data : [];
74
+ if (r.error) throw r.error;
75
+ if (!r.data) throw new Error(`Flow "${t}" not found`);
76
+ if (i.error) throw i.error;
77
+ const n = Array.isArray(i.data) ? i.data : [];
74
78
  return {
75
- flow: s.data,
76
- steps: i
79
+ flow: r.data,
80
+ steps: n
77
81
  };
78
82
  }
79
83
  /**
@@ -83,12 +87,12 @@ class rt {
83
87
  * @returns Function to unsubscribe from the event
84
88
  */
85
89
  onRunEvent(t) {
86
- const s = r(this, F).on("runEvent", t);
90
+ const r = e(this, C).on("runEvent", t);
87
91
  return () => {
88
92
  try {
89
- s();
90
- } catch (n) {
91
- console.warn("Could not unsubscribe from run event - emitter may have been disposed", n);
93
+ r();
94
+ } catch (i) {
95
+ console.warn("Could not unsubscribe from run event - emitter may have been disposed", i);
92
96
  }
93
97
  };
94
98
  }
@@ -99,12 +103,12 @@ class rt {
99
103
  * @returns Function to unsubscribe from the event
100
104
  */
101
105
  onStepEvent(t) {
102
- const s = r(this, F).on("stepEvent", t);
106
+ const r = e(this, C).on("stepEvent", t);
103
107
  return () => {
104
108
  try {
105
- s();
106
- } catch (n) {
107
- console.warn("Could not unsubscribe from step event - emitter may have been disposed", n);
109
+ r();
110
+ } catch (i) {
111
+ console.warn("Could not unsubscribe from step event - emitter may have been disposed", i);
108
112
  }
109
113
  };
110
114
  }
@@ -115,28 +119,28 @@ class rt {
115
119
  * @returns Function to unsubscribe
116
120
  */
117
121
  async subscribeToRun(t) {
118
- const s = `pgflow:run:${t}`;
119
- if (r(this, C).has(t)) {
120
- const _ = r(this, k).get(t);
121
- if (_)
122
- return _;
123
- w(this, f, G).call(this, t);
122
+ const r = `pgflow:run:${t}`;
123
+ if (e(this, k).has(t)) {
124
+ const c = e(this, M).get(t);
125
+ if (c)
126
+ return c;
127
+ m(this, f, N).call(this, t);
124
128
  }
125
- const n = r(this, S).channel(s);
126
- n.on("broadcast", { event: "*" }, w(this, f, j).bind(this)), n.on("system", { event: "closed" }, () => {
127
- console.log(`Channel ${s} closed`);
128
- }), n.on("system", { event: "error" }, (_) => {
129
- console.log(`Channel ${s} error:`, _), w(this, f, z).call(this, t, s, n, _.error);
130
- }), console.log(`Subscribing to channel ${s}...`), await new Promise((_, h) => {
131
- const d = setTimeout(() => {
132
- h(new Error(`Subscription timeout for channel ${s}`));
129
+ const i = e(this, E).channel(r);
130
+ i.on("broadcast", { event: "*" }, m(this, f, G).bind(this)), i.on("system", { event: "closed" }, () => {
131
+ console.log(`Channel ${r} closed`);
132
+ }), i.on("system", { event: "error" }, (c) => {
133
+ console.log(`Channel ${r} error:`, c), m(this, f, K).call(this, t, r, i, c.error);
134
+ }), console.log(`Subscribing to channel ${r}...`), await new Promise((c, l) => {
135
+ const p = setTimeout(() => {
136
+ l(new Error(`Subscription timeout for channel ${r}`));
133
137
  }, 2e4);
134
- n.subscribe((m) => {
135
- console.log(`Channel ${s} subscription status:`, m), m === "SUBSCRIBED" && (clearTimeout(d), _());
138
+ i.subscribe((b) => {
139
+ console.log(`Channel ${r} subscription status:`, b), b === "SUBSCRIBED" && (clearTimeout(p), c());
136
140
  });
137
- }), r(this, C).set(t, n);
138
- const a = () => this.unsubscribe(t);
139
- return r(this, k).set(t, a), a;
141
+ }), await new Promise((c) => e(this, A).call(this, c, e(this, W))), e(this, k).set(t, i);
142
+ const g = () => this.unsubscribe(t);
143
+ return e(this, M).set(t, g), g;
140
144
  }
141
145
  /**
142
146
  * Unsubscribes from a run's events
@@ -144,7 +148,7 @@ class rt {
144
148
  * @param run_id - Run ID to unsubscribe from
145
149
  */
146
150
  unsubscribe(t) {
147
- w(this, f, G).call(this, t);
151
+ m(this, f, N).call(this, t);
148
152
  }
149
153
  /**
150
154
  * Fetches current state of a run and its steps
@@ -152,19 +156,19 @@ class rt {
152
156
  * @param run_id - Run ID to fetch
153
157
  */
154
158
  async getRunWithStates(t) {
155
- const { data: s, error: n } = await r(this, S).schema("pgflow").rpc("get_run_with_states", { run_id: t });
156
- if (n) throw n;
157
- if (!s) throw new Error(`No data returned for run ${t}`);
158
- return s;
159
+ const { data: r, error: i } = await e(this, E).schema("pgflow").rpc("get_run_with_states", { run_id: t });
160
+ if (i) throw i;
161
+ if (!r) throw new Error(`No data returned for run ${t}`);
162
+ return r;
159
163
  }
160
164
  }
161
- S = new WeakMap(), C = new WeakMap(), F = new WeakMap(), M = new WeakMap(), I = new WeakMap(), f = new WeakSet(), /**
165
+ E = new WeakMap(), k = new WeakMap(), C = new WeakMap(), I = new WeakMap(), W = new WeakMap(), A = new WeakMap(), f = new WeakSet(), /**
162
166
  * Handle broadcast messages from Supabase
163
167
  * @param payload - The message payload
164
168
  */
165
- j = function(t) {
166
- const { event: s, payload: n } = t, i = n;
167
- w(this, f, X).call(this, i), s.startsWith("run:") ? r(this, F).emit("runEvent", i) : s.startsWith("step:") && r(this, F).emit("stepEvent", i);
169
+ G = function(t) {
170
+ const { event: r, payload: i } = t, n = i;
171
+ m(this, f, X).call(this, n), r.startsWith("run:") ? e(this, C).emit("runEvent", n) : r.startsWith("step:") && e(this, C).emit("stepEvent", n);
168
172
  }, /**
169
173
  * Parse JSON string fields in broadcast event data
170
174
  * @param eventData - The event data object to parse
@@ -180,323 +184,364 @@ X = function(t) {
180
184
  t.input = JSON.parse(t.input);
181
185
  } catch {
182
186
  }
183
- }, z = async function(t, s, n, i) {
184
- console.error(`Channel ${s} error:`, i), r(this, I).call(this, async () => {
185
- r(this, C).has(t) && await w(this, f, Z).call(this, t, s);
186
- }, r(this, M));
187
+ }, K = async function(t, r, i, n) {
188
+ console.error(`Channel ${r} error:`, n), e(this, A).call(this, async () => {
189
+ e(this, k).has(t) && await m(this, f, Z).call(this, t, r);
190
+ }, e(this, I));
187
191
  }, /**
188
192
  * Creates and configures a channel for a run
189
193
  * @param run_id - The run ID
190
194
  * @param channelName - The channel name
191
195
  * @returns The configured RealtimeChannel
192
196
  */
193
- Y = function(t, s) {
194
- const n = r(this, S).channel(s);
195
- return n.on("broadcast", { event: "*" }, w(this, f, j).bind(this)), n;
196
- }, Z = async function(t, s) {
197
- console.log(`Attempting to reconnect to ${s}`);
197
+ Y = function(t, r) {
198
+ const i = e(this, E).channel(r);
199
+ return i.on("broadcast", { event: "*" }, m(this, f, G).bind(this)), i;
200
+ }, Z = async function(t, r) {
201
+ console.log(`Attempting to reconnect to ${r}`);
198
202
  try {
199
- const n = await this.getRunWithStates(t);
200
- w(this, f, v).call(this, t, n);
201
- const i = w(this, f, Y).call(this, t, s);
202
- i.on("system", { event: "subscribed" }, () => {
203
- console.log(`Reconnected and subscribed to channel ${s}`);
204
- }), i.on("system", { event: "closed" }, () => {
205
- console.log(`Reconnected channel ${s} closed`);
206
- }), i.on(
203
+ const i = await this.getRunWithStates(t);
204
+ m(this, f, v).call(this, t, i);
205
+ const n = m(this, f, Y).call(this, t, r);
206
+ n.on("system", { event: "subscribed" }, () => {
207
+ console.log(`Reconnected and subscribed to channel ${r}`);
208
+ }), n.on("system", { event: "closed" }, () => {
209
+ console.log(`Reconnected channel ${r} closed`);
210
+ }), n.on(
207
211
  "system",
208
212
  { event: "error" },
209
- (a) => w(this, f, z).call(this, t, s, i, a.error)
210
- ), i.subscribe(), r(this, C).set(t, i);
211
- } catch (n) {
212
- console.error(`Failed to reconnect to ${s}:`, n);
213
+ (g) => m(this, f, K).call(this, t, r, n, g.error)
214
+ ), n.subscribe(), e(this, k).set(t, n);
215
+ } catch (i) {
216
+ console.error(`Failed to reconnect to ${r}:`, i);
213
217
  }
214
218
  }, /**
215
219
  * Refresh client state from a state snapshot
216
220
  * @param run_id - The run ID
217
221
  * @param state - The state snapshot
218
222
  */
219
- v = function(t, s) {
220
- if (!s || !s.run) return;
221
- const n = {
222
- event_type: `run:${s.run.status}`,
223
- ...s.run
223
+ v = function(t, r) {
224
+ if (!r || !r.run) return;
225
+ const i = {
226
+ event_type: `run:${r.run.status}`,
227
+ ...r.run
224
228
  };
225
- if (r(this, F).emit("runEvent", n), s.steps && Array.isArray(s.steps))
226
- for (const i of s.steps) {
227
- const a = {
228
- event_type: `step:${i.status}`,
229
- ...i
229
+ if (e(this, C).emit("runEvent", i), r.steps && Array.isArray(r.steps))
230
+ for (const n of r.steps) {
231
+ const g = {
232
+ event_type: `step:${n.status}`,
233
+ ...n
230
234
  };
231
- r(this, F).emit("stepEvent", a);
235
+ e(this, C).emit("stepEvent", g);
232
236
  }
233
- }, k = new WeakMap(), /**
237
+ }, M = new WeakMap(), /**
234
238
  * Unsubscribes from a run's events
235
239
  *
236
240
  * @param run_id - Run ID to unsubscribe from
237
241
  */
238
- G = function(t) {
239
- const s = r(this, C).get(t);
240
- s && (s.unsubscribe(), r(this, C).delete(t), r(this, k).delete(t));
242
+ N = function(t) {
243
+ const r = e(this, k).get(t);
244
+ r && (r.unsubscribe(), e(this, k).delete(t), e(this, M).delete(t));
241
245
  };
242
- var p, $, W, J, tt;
243
- class nt {
246
+ var a, F, x, J, tt;
247
+ class it {
244
248
  /**
245
249
  * Creates a new FlowStep instance
246
- *
250
+ *
247
251
  * @param initialState - Initial state for the step
248
252
  */
249
253
  constructor(t) {
250
- c(this, J);
251
- c(this, p);
252
- c(this, $, L());
253
- c(this, W, {
254
- [l.Created]: 0,
255
- [l.Started]: 1,
256
- [l.Completed]: 2,
257
- [l.Failed]: 3
254
+ d(this, J);
255
+ d(this, a);
256
+ d(this, F, L());
257
+ d(this, x, {
258
+ [u.Created]: 0,
259
+ [u.Started]: 1,
260
+ [u.Completed]: 2,
261
+ [u.Failed]: 3,
262
+ [u.Skipped]: 4
258
263
  });
259
- g(this, p, t);
264
+ _(this, a, t);
260
265
  }
261
266
  /**
262
267
  * Get the run ID this step belongs to
263
268
  */
264
269
  get run_id() {
265
- return r(this, p).run_id;
270
+ return e(this, a).run_id;
266
271
  }
267
272
  /**
268
273
  * Get the step slug
269
274
  */
270
275
  get step_slug() {
271
- return r(this, p).step_slug;
276
+ return e(this, a).step_slug;
272
277
  }
273
278
  /**
274
279
  * Get the current status
275
280
  */
276
281
  get status() {
277
- return r(this, p).status;
282
+ return e(this, a).status;
278
283
  }
279
284
  /**
280
285
  * Get the started_at timestamp
281
286
  */
282
287
  get started_at() {
283
- return r(this, p).started_at;
288
+ return e(this, a).started_at;
284
289
  }
285
290
  /**
286
291
  * Get the completed_at timestamp
287
292
  */
288
293
  get completed_at() {
289
- return r(this, p).completed_at;
294
+ return e(this, a).completed_at;
290
295
  }
291
296
  /**
292
297
  * Get the failed_at timestamp
293
298
  */
294
299
  get failed_at() {
295
- return r(this, p).failed_at;
300
+ return e(this, a).failed_at;
301
+ }
302
+ /**
303
+ * Get the skipped_at timestamp
304
+ */
305
+ get skipped_at() {
306
+ return e(this, a).skipped_at;
307
+ }
308
+ /**
309
+ * Get the skip reason
310
+ */
311
+ get skip_reason() {
312
+ return e(this, a).skip_reason;
296
313
  }
297
314
  /**
298
315
  * Get the step output
299
316
  */
300
317
  get output() {
301
- return r(this, p).output;
318
+ return e(this, a).output;
302
319
  }
303
320
  /**
304
321
  * Get the error object
305
322
  */
306
323
  get error() {
307
- return r(this, p).error;
324
+ return e(this, a).error;
308
325
  }
309
326
  /**
310
327
  * Get the error message
311
328
  */
312
329
  get error_message() {
313
- return r(this, p).error_message;
330
+ return e(this, a).error_message;
314
331
  }
315
332
  /**
316
333
  * Register an event handler for a step event
317
- *
334
+ *
318
335
  * @param event - Event type to listen for
319
336
  * @param callback - Callback function to execute when event is emitted
320
337
  * @returns Function to unsubscribe from the event
321
338
  */
322
- on(t, s) {
323
- return r(this, $).on(t, s);
339
+ on(t, r) {
340
+ return e(this, F).on(t, r);
324
341
  }
325
342
  /**
326
343
  * Wait for the step to reach a specific status
327
- *
344
+ *
328
345
  * @param targetStatus - The status to wait for
329
346
  * @param options - Optional timeout and abort signal
330
347
  * @returns Promise that resolves with the step instance when the status is reached
331
348
  */
332
- waitForStatus(t, s) {
333
- const n = (s == null ? void 0 : s.timeoutMs) ?? 3e5, { signal: i } = s || {};
334
- return this.status === t ? Promise.resolve(this) : new Promise((a, _) => {
335
- let h, d = !1;
336
- n > 0 && (h = setTimeout(() => {
337
- d || (d = !0, A(), _(new Error(`Timeout waiting for step ${this.step_slug} to reach status '${t}'`)));
338
- }, n));
339
- let m;
340
- if (i) {
341
- const E = () => {
342
- d || (d = !0, h && clearTimeout(h), A(), _(new Error(`Aborted waiting for step ${this.step_slug} to reach status '${t}'`)));
349
+ waitForStatus(t, r) {
350
+ const i = (r == null ? void 0 : r.timeoutMs) ?? 3e5, { signal: n } = r || {};
351
+ return this.status === t ? Promise.resolve(this) : new Promise((g, c) => {
352
+ let l, p = !1;
353
+ i > 0 && (l = setTimeout(() => {
354
+ p || (p = !0, $(), c(
355
+ new Error(
356
+ `Timeout waiting for step ${this.step_slug} to reach status '${t}'`
357
+ )
358
+ ));
359
+ }, i));
360
+ let b;
361
+ if (n) {
362
+ const S = () => {
363
+ p || (p = !0, l && clearTimeout(l), $(), c(
364
+ new Error(
365
+ `Aborted waiting for step ${this.step_slug} to reach status '${t}'`
366
+ )
367
+ ));
343
368
  };
344
- i.addEventListener("abort", E), m = () => {
345
- i.removeEventListener("abort", E);
369
+ n.addEventListener("abort", S), b = () => {
370
+ n.removeEventListener("abort", S);
346
371
  };
347
372
  }
348
- const A = this.on("*", (E) => {
349
- if (E.status === t) {
350
- if (d) return;
351
- d = !0, h && clearTimeout(h), m && m(), A(), a(this);
373
+ const $ = this.on("*", (S) => {
374
+ if (S.status === t) {
375
+ if (p) return;
376
+ p = !0, l && clearTimeout(l), b && b(), $(), g(this);
352
377
  }
353
378
  });
354
379
  });
355
380
  }
381
+ /**
382
+ * Apply state from database snapshot (no events emitted)
383
+ * Used when initializing state from start_flow_with_states() or get_run_with_states()
384
+ *
385
+ * @internal This method is only intended for use by PgflowClient.
386
+ * Applications should not call this directly.
387
+ */
388
+ applySnapshot(t) {
389
+ e(this, a).status = t.status, e(this, a).started_at = t.started_at ? new Date(t.started_at) : null, e(this, a).completed_at = t.completed_at ? new Date(t.completed_at) : null, e(this, a).failed_at = t.failed_at ? new Date(t.failed_at) : null, e(this, a).error_message = t.error_message, e(this, a).error = t.error_message ? new Error(t.error_message) : null, e(this, a).skipped_at = t.skipped_at ? new Date(t.skipped_at) : null, e(this, a).skip_reason = t.skip_reason;
390
+ }
356
391
  /**
357
392
  * Updates the step state based on an event
358
- *
393
+ *
359
394
  * @internal This method is only intended for use by FlowRun and tests.
360
395
  * Applications should not call this directly - state updates should come from
361
396
  * database events through the PgflowClient.
362
- *
397
+ *
363
398
  * TODO: After v1.0, make this method private and refactor tests to use PgflowClient
364
399
  * with event emission instead of direct state manipulation.
365
400
  */
366
401
  updateState(t) {
367
- if (t.step_slug !== r(this, p).step_slug || t.run_id !== r(this, p).run_id || !w(this, J, tt).call(this, r(this, p).status, t.status))
402
+ if (t.step_slug !== e(this, a).step_slug || t.run_id !== e(this, a).run_id || !m(this, J, tt).call(this, e(this, a).status, t.status))
368
403
  return !1;
369
404
  switch (t.status) {
370
- case l.Started:
371
- g(this, p, {
372
- ...r(this, p),
373
- status: l.Started,
405
+ case u.Started:
406
+ _(this, a, {
407
+ ...e(this, a),
408
+ status: u.Started,
374
409
  started_at: typeof t.started_at == "string" ? new Date(t.started_at) : /* @__PURE__ */ new Date()
375
- }), r(this, $).emit("started", t);
410
+ }), e(this, F).emit("started", t);
376
411
  break;
377
- case l.Completed:
378
- g(this, p, {
379
- ...r(this, p),
380
- status: l.Completed,
412
+ case u.Completed:
413
+ _(this, a, {
414
+ ...e(this, a),
415
+ status: u.Completed,
381
416
  completed_at: typeof t.completed_at == "string" ? new Date(t.completed_at) : /* @__PURE__ */ new Date(),
382
417
  output: t.output
383
- }), r(this, $).emit("completed", t);
418
+ }), e(this, F).emit("completed", t);
384
419
  break;
385
- case l.Failed:
386
- g(this, p, {
387
- ...r(this, p),
388
- status: l.Failed,
420
+ case u.Failed:
421
+ _(this, a, {
422
+ ...e(this, a),
423
+ status: u.Failed,
389
424
  failed_at: typeof t.failed_at == "string" ? new Date(t.failed_at) : /* @__PURE__ */ new Date(),
390
425
  error_message: typeof t.error_message == "string" ? t.error_message : "Unknown error",
391
- error: new Error(typeof t.error_message == "string" ? t.error_message : "Unknown error")
392
- }), r(this, $).emit("failed", t);
426
+ error: new Error(
427
+ typeof t.error_message == "string" ? t.error_message : "Unknown error"
428
+ )
429
+ }), e(this, F).emit("failed", t);
430
+ break;
431
+ case u.Skipped:
432
+ _(this, a, {
433
+ ...e(this, a),
434
+ status: u.Skipped,
435
+ skipped_at: typeof t.skipped_at == "string" ? new Date(t.skipped_at) : /* @__PURE__ */ new Date(),
436
+ skip_reason: t.skip_reason
437
+ }), e(this, F).emit("skipped", t);
393
438
  break;
394
439
  default:
395
440
  return !1;
396
441
  }
397
- return r(this, $).emit("*", t), !0;
442
+ return e(this, F).emit("*", t), !0;
398
443
  }
399
444
  }
400
- p = new WeakMap(), $ = new WeakMap(), W = new WeakMap(), J = new WeakSet(), /**
445
+ a = new WeakMap(), F = new WeakMap(), x = new WeakMap(), J = new WeakSet(), /**
401
446
  * Determines if a status should be updated based on precedence
402
- *
447
+ *
403
448
  * @param currentStatus - Current status
404
449
  * @param newStatus - New status
405
450
  * @returns true if the status should be updated, false otherwise
406
451
  */
407
- tt = function(t, s) {
408
- if (t === l.Completed || t === l.Failed)
452
+ tt = function(t, r) {
453
+ if (t === u.Completed || t === u.Failed || t === u.Skipped)
409
454
  return !1;
410
- const n = r(this, W)[t];
411
- return r(this, W)[s] > n;
455
+ const i = e(this, x)[t];
456
+ return e(this, x)[r] > i;
412
457
  };
413
- var o, R, D, x, U, P, T, B, et;
414
- class Q {
458
+ var o, D, T, q, U, P, R, B, et;
459
+ class V {
415
460
  /**
416
461
  * Creates a new FlowRun instance
417
462
  *
418
463
  * @param initialState - Initial state for the run
419
464
  */
420
465
  constructor(t) {
421
- c(this, T);
422
- c(this, o);
423
- c(this, R, L());
424
- c(this, D, /* @__PURE__ */ new Map());
425
- c(this, x, {
426
- [u.Started]: 0,
427
- [u.Completed]: 1,
428
- [u.Failed]: 2
466
+ d(this, R);
467
+ d(this, o);
468
+ d(this, D, L());
469
+ d(this, T, /* @__PURE__ */ new Map());
470
+ d(this, q, {
471
+ [h.Started]: 0,
472
+ [h.Completed]: 1,
473
+ [h.Failed]: 2
429
474
  });
430
- c(this, U, !1);
475
+ d(this, U, !1);
431
476
  // Track number of listeners
432
- c(this, P, 0);
433
- g(this, o, t);
477
+ d(this, P, 0);
478
+ _(this, o, t);
434
479
  }
435
480
  /**
436
481
  * Get the run ID
437
482
  */
438
483
  get run_id() {
439
- return r(this, o).run_id;
484
+ return e(this, o).run_id;
440
485
  }
441
486
  /**
442
487
  * Get the flow slug
443
488
  */
444
489
  get flow_slug() {
445
- return r(this, o).flow_slug;
490
+ return e(this, o).flow_slug;
446
491
  }
447
492
  /**
448
493
  * Get the current status
449
494
  */
450
495
  get status() {
451
- return r(this, o).status;
496
+ return e(this, o).status;
452
497
  }
453
498
  /**
454
499
  * Get the started_at timestamp
455
500
  */
456
501
  get started_at() {
457
- return r(this, o).started_at;
502
+ return e(this, o).started_at;
458
503
  }
459
504
  /**
460
505
  * Get the completed_at timestamp
461
506
  */
462
507
  get completed_at() {
463
- return r(this, o).completed_at;
508
+ return e(this, o).completed_at;
464
509
  }
465
510
  /**
466
511
  * Get the failed_at timestamp
467
512
  */
468
513
  get failed_at() {
469
- return r(this, o).failed_at;
514
+ return e(this, o).failed_at;
470
515
  }
471
516
  /**
472
517
  * Get the flow input
473
518
  */
474
519
  get input() {
475
- return r(this, o).input;
520
+ return e(this, o).input;
476
521
  }
477
522
  /**
478
523
  * Get the flow output
479
524
  */
480
525
  get output() {
481
- return r(this, o).output;
526
+ return e(this, o).output;
482
527
  }
483
528
  /**
484
529
  * Get the error object
485
530
  */
486
531
  get error() {
487
- return r(this, o).error;
532
+ return e(this, o).error;
488
533
  }
489
534
  /**
490
535
  * Get the error message
491
536
  */
492
537
  get error_message() {
493
- return r(this, o).error_message;
538
+ return e(this, o).error_message;
494
539
  }
495
540
  /**
496
541
  * Get the number of remaining steps
497
542
  */
498
543
  get remaining_steps() {
499
- return r(this, o).remaining_steps;
544
+ return e(this, o).remaining_steps;
500
545
  }
501
546
  /**
502
547
  * Register an event handler for a run event
@@ -505,11 +550,11 @@ class Q {
505
550
  * @param callback - Callback function to execute when event is emitted
506
551
  * @returns Function to unsubscribe from the event
507
552
  */
508
- on(t, s) {
509
- H(this, P)._++;
510
- const n = r(this, R).on(t, s);
553
+ on(t, r) {
554
+ j(this, P)._++;
555
+ const i = e(this, D).on(t, r);
511
556
  return () => {
512
- n(), H(this, P)._--, w(this, T, B).call(this);
557
+ i(), j(this, P)._--, m(this, R, B).call(this);
513
558
  };
514
559
  }
515
560
  /**
@@ -519,24 +564,26 @@ class Q {
519
564
  * @returns FlowStep instance for the specified step
520
565
  */
521
566
  step(t) {
522
- const s = r(this, D).get(t);
523
- if (s)
524
- return s;
525
- const n = new nt({
567
+ const r = e(this, T).get(t);
568
+ if (r)
569
+ return r;
570
+ const i = new it({
526
571
  run_id: this.run_id,
527
572
  step_slug: t,
528
- status: l.Created,
573
+ status: u.Created,
529
574
  output: null,
530
575
  error: null,
531
576
  error_message: null,
532
577
  started_at: null,
533
578
  completed_at: null,
534
- failed_at: null
579
+ failed_at: null,
580
+ skipped_at: null,
581
+ skip_reason: null
535
582
  });
536
- return r(this, D).set(
583
+ return e(this, T).set(
537
584
  t,
538
- n
539
- ), n;
585
+ i
586
+ ), i;
540
587
  }
541
588
  /**
542
589
  * Check if this run has a specific step
@@ -545,7 +592,7 @@ class Q {
545
592
  * @returns true if the step exists, false otherwise
546
593
  */
547
594
  hasStep(t) {
548
- return r(this, D).has(t);
595
+ return e(this, T).has(t);
549
596
  }
550
597
  /**
551
598
  * Wait for the run to reach a specific status
@@ -554,84 +601,94 @@ class Q {
554
601
  * @param options - Optional timeout and abort signal
555
602
  * @returns Promise that resolves with the run instance when the status is reached
556
603
  */
557
- waitForStatus(t, s) {
558
- const n = (s == null ? void 0 : s.timeoutMs) ?? 3e5, { signal: i } = s || {};
559
- return this.status === t ? Promise.resolve(this) : new Promise((a, _) => {
560
- let h, d = !1;
561
- n > 0 && (h = setTimeout(() => {
562
- d || (d = !0, A(), _(
604
+ waitForStatus(t, r) {
605
+ const i = (r == null ? void 0 : r.timeoutMs) ?? 3e5, { signal: n } = r || {};
606
+ return this.status === t ? Promise.resolve(this) : new Promise((g, c) => {
607
+ let l, p = !1;
608
+ i > 0 && (l = setTimeout(() => {
609
+ p || (p = !0, $(), c(
563
610
  new Error(
564
611
  `Timeout waiting for run ${this.run_id} to reach status '${t}'`
565
612
  )
566
613
  ));
567
- }, n));
568
- let m;
569
- if (i) {
570
- const E = () => {
571
- d || (d = !0, h && clearTimeout(h), A(), _(
614
+ }, i));
615
+ let b;
616
+ if (n) {
617
+ const S = () => {
618
+ p || (p = !0, l && clearTimeout(l), $(), c(
572
619
  new Error(
573
620
  `Aborted waiting for run ${this.run_id} to reach status '${t}'`
574
621
  )
575
622
  ));
576
623
  };
577
- i.addEventListener("abort", E), m = () => {
578
- i.removeEventListener("abort", E);
624
+ n.addEventListener("abort", S), b = () => {
625
+ n.removeEventListener("abort", S);
579
626
  };
580
627
  }
581
- const A = this.on("*", (E) => {
582
- if (E.status === t) {
583
- if (d) return;
584
- d = !0, h && clearTimeout(h), m && m(), A(), a(this);
628
+ const $ = this.on("*", (S) => {
629
+ if (S.status === t) {
630
+ if (p) return;
631
+ p = !0, l && clearTimeout(l), b && b(), $(), g(this);
585
632
  }
586
633
  });
587
634
  });
588
635
  }
636
+ /**
637
+ * Apply state from database snapshot (no events emitted)
638
+ * Used when initializing state from start_flow_with_states() or get_run_with_states()
639
+ *
640
+ * @internal This method is only intended for use by PgflowClient.
641
+ * Applications should not call this directly.
642
+ */
643
+ applySnapshot(t) {
644
+ e(this, o).status = t.status, e(this, o).input = t.input, e(this, o).output = t.output, e(this, o).started_at = t.started_at ? new Date(t.started_at) : null, e(this, o).completed_at = t.completed_at ? new Date(t.completed_at) : null, e(this, o).failed_at = t.failed_at ? new Date(t.failed_at) : null, e(this, o).remaining_steps = t.remaining_steps, e(this, o).error_message = null, e(this, o).error = null;
645
+ }
589
646
  /**
590
647
  * Updates the run state based on an event
591
- *
648
+ *
592
649
  * @internal This method is only intended for use by PgflowClient and tests.
593
650
  * Applications should not call this directly - state updates should come from
594
651
  * database events through the PgflowClient.
595
- *
652
+ *
596
653
  * TODO: After v1.0, make this method private and refactor tests to use PgflowClient
597
654
  * with event emission instead of direct state manipulation.
598
655
  */
599
656
  updateState(t) {
600
- if (t.run_id !== r(this, o).run_id || !w(this, T, et).call(this, r(this, o).status, t.status))
657
+ if (t.run_id !== e(this, o).run_id || !m(this, R, et).call(this, e(this, o).status, t.status))
601
658
  return !1;
602
659
  switch (t.status) {
603
- case u.Started:
604
- g(this, o, {
605
- ...r(this, o),
606
- status: u.Started,
660
+ case h.Started:
661
+ _(this, o, {
662
+ ...e(this, o),
663
+ status: h.Started,
607
664
  started_at: typeof t.started_at == "string" ? new Date(t.started_at) : /* @__PURE__ */ new Date(),
608
- remaining_steps: "remaining_steps" in t ? Number(t.remaining_steps) : r(this, o).remaining_steps
609
- }), r(this, R).emit("started", t);
665
+ remaining_steps: "remaining_steps" in t ? Number(t.remaining_steps) : e(this, o).remaining_steps
666
+ }), e(this, D).emit("started", t);
610
667
  break;
611
- case u.Completed:
612
- g(this, o, {
613
- ...r(this, o),
614
- status: u.Completed,
668
+ case h.Completed:
669
+ _(this, o, {
670
+ ...e(this, o),
671
+ status: h.Completed,
615
672
  completed_at: typeof t.completed_at == "string" ? new Date(t.completed_at) : /* @__PURE__ */ new Date(),
616
673
  output: t.output,
617
674
  remaining_steps: 0
618
- }), r(this, R).emit("completed", t), w(this, T, B).call(this);
675
+ }), e(this, D).emit("completed", t), m(this, R, B).call(this);
619
676
  break;
620
- case u.Failed:
621
- g(this, o, {
622
- ...r(this, o),
623
- status: u.Failed,
677
+ case h.Failed:
678
+ _(this, o, {
679
+ ...e(this, o),
680
+ status: h.Failed,
624
681
  failed_at: typeof t.failed_at == "string" ? new Date(t.failed_at) : /* @__PURE__ */ new Date(),
625
682
  error_message: typeof t.error_message == "string" ? t.error_message : "Unknown error",
626
683
  error: new Error(
627
684
  typeof t.error_message == "string" ? t.error_message : "Unknown error"
628
685
  )
629
- }), r(this, R).emit("failed", t), w(this, T, B).call(this);
686
+ }), e(this, D).emit("failed", t), m(this, R, B).call(this);
630
687
  break;
631
688
  default:
632
689
  return !1;
633
690
  }
634
- return r(this, R).emit("*", t), !0;
691
+ return e(this, D).emit("*", t), !0;
635
692
  }
636
693
  /**
637
694
  * Updates a step state based on an event
@@ -640,21 +697,21 @@ class Q {
640
697
  * @param event - Event data to update the step with
641
698
  * @returns true if the state was updated, false otherwise
642
699
  */
643
- updateStepState(t, s) {
644
- return this.step(t).updateState(s);
700
+ updateStepState(t, r) {
701
+ return this.step(t).updateState(r);
645
702
  }
646
703
  /**
647
704
  * Clean up all resources held by this run
648
705
  */
649
706
  dispose() {
650
- r(this, U) || (r(this, D).clear(), g(this, R, L()), g(this, P, 0), g(this, U, !0));
707
+ e(this, U) || (e(this, T).clear(), _(this, D, L()), _(this, P, 0), _(this, U, !0));
651
708
  }
652
709
  }
653
- o = new WeakMap(), R = new WeakMap(), D = new WeakMap(), x = new WeakMap(), U = new WeakMap(), P = new WeakMap(), T = new WeakSet(), /**
710
+ o = new WeakMap(), D = new WeakMap(), T = new WeakMap(), q = new WeakMap(), U = new WeakMap(), P = new WeakMap(), R = new WeakSet(), /**
654
711
  * Checks if auto-dispose should be triggered (when in terminal state with no listeners)
655
712
  */
656
713
  B = function() {
657
- r(this, U) || this.status !== u.Completed && this.status !== u.Failed || r(this, P) === 0 && this.dispose();
714
+ e(this, U) || this.status !== h.Completed && this.status !== h.Failed || e(this, P) === 0 && this.dispose();
658
715
  }, /**
659
716
  * Determines if a status should be updated based on precedence
660
717
  *
@@ -662,164 +719,108 @@ B = function() {
662
719
  * @param newStatus - New status
663
720
  * @returns true if the status should be updated, false otherwise
664
721
  */
665
- et = function(t, s) {
666
- if (t === u.Completed || t === u.Failed)
722
+ et = function(t, r) {
723
+ if (t === h.Completed || t === h.Failed)
667
724
  return !1;
668
- const n = r(this, x)[t];
669
- return r(this, x)[s] > n;
725
+ const i = e(this, q)[t];
726
+ return e(this, q)[r] > i;
670
727
  };
671
- function it(e) {
672
- switch (e.status) {
673
- case u.Started:
728
+ function nt(s) {
729
+ switch (s.status) {
730
+ case h.Started:
674
731
  return {
675
732
  event_type: "run:started",
676
- run_id: e.run_id,
677
- flow_slug: e.flow_slug,
678
- status: u.Started,
679
- started_at: e.started_at,
680
- remaining_steps: e.remaining_steps,
681
- input: e.input
733
+ run_id: s.run_id,
734
+ flow_slug: s.flow_slug,
735
+ status: h.Started,
736
+ started_at: s.started_at,
737
+ remaining_steps: s.remaining_steps,
738
+ input: s.input
682
739
  };
683
- case u.Completed:
740
+ case h.Completed:
684
741
  return {
685
742
  event_type: "run:completed",
686
- run_id: e.run_id,
687
- flow_slug: e.flow_slug,
688
- status: u.Completed,
689
- completed_at: e.completed_at,
690
- output: e.output
743
+ run_id: s.run_id,
744
+ flow_slug: s.flow_slug,
745
+ status: h.Completed,
746
+ completed_at: s.completed_at,
747
+ output: s.output
691
748
  };
692
- case u.Failed:
749
+ case h.Failed:
693
750
  return {
694
751
  event_type: "run:failed",
695
- run_id: e.run_id,
696
- flow_slug: e.flow_slug,
697
- status: u.Failed,
698
- failed_at: e.failed_at,
699
- error_message: e.error_message
752
+ run_id: s.run_id,
753
+ flow_slug: s.flow_slug,
754
+ status: h.Failed,
755
+ failed_at: s.failed_at,
756
+ error_message: s.error_message
700
757
  };
701
758
  }
702
759
  }
703
- function at(e) {
704
- switch (e.status) {
705
- case l.Started:
760
+ function at(s) {
761
+ switch (s.status) {
762
+ case u.Started:
706
763
  return {
707
764
  event_type: "step:started",
708
- run_id: e.run_id,
709
- step_slug: e.step_slug,
710
- status: l.Started,
711
- started_at: e.started_at
712
- };
713
- case l.Completed:
714
- return {
715
- event_type: "step:completed",
716
- run_id: e.run_id,
717
- step_slug: e.step_slug,
718
- status: l.Completed,
719
- completed_at: e.completed_at,
720
- output: e.output
721
- };
722
- case l.Failed:
723
- return {
724
- event_type: "step:failed",
725
- run_id: e.run_id,
726
- step_slug: e.step_slug,
727
- status: l.Failed,
728
- failed_at: e.failed_at,
729
- error_message: e.error_message
730
- };
731
- }
732
- }
733
- function ut(e) {
734
- switch (e.status) {
735
- case "started":
736
- return {
737
- event_type: "run:started",
738
- run_id: e.run_id,
739
- flow_slug: e.flow_slug,
765
+ run_id: s.run_id,
766
+ step_slug: s.step_slug,
740
767
  status: u.Started,
741
- started_at: e.started_at,
742
- remaining_steps: e.remaining_steps,
743
- input: e.input
768
+ started_at: s.started_at
744
769
  };
745
- case "completed":
770
+ case u.Completed:
746
771
  return {
747
- event_type: "run:completed",
748
- run_id: e.run_id,
749
- flow_slug: e.flow_slug,
772
+ event_type: "step:completed",
773
+ run_id: s.run_id,
774
+ step_slug: s.step_slug,
750
775
  status: u.Completed,
751
- completed_at: e.completed_at,
752
- output: e.output
776
+ completed_at: s.completed_at,
777
+ output: s.output
753
778
  };
754
- case "failed":
779
+ case u.Failed:
755
780
  return {
756
- event_type: "run:failed",
757
- run_id: e.run_id,
758
- flow_slug: e.flow_slug,
781
+ event_type: "step:failed",
782
+ run_id: s.run_id,
783
+ step_slug: s.step_slug,
759
784
  status: u.Failed,
760
- failed_at: e.failed_at,
761
- error_message: "Flow failed"
762
- // Database doesn't have error_message for runs
785
+ failed_at: s.failed_at,
786
+ error_message: s.error_message
763
787
  };
764
- default:
765
- throw new Error(`Unknown run status: ${e.status}`);
766
- }
767
- }
768
- function V(e) {
769
- switch (e.status) {
770
- case "created":
771
- case "started":
788
+ case u.Skipped:
772
789
  return {
773
- event_type: "step:started",
774
- run_id: e.run_id,
775
- step_slug: e.step_slug,
776
- status: l.Started,
777
- started_at: e.started_at
790
+ event_type: "step:skipped",
791
+ run_id: s.run_id,
792
+ step_slug: s.step_slug,
793
+ status: u.Skipped,
794
+ skipped_at: s.skipped_at,
795
+ skip_reason: s.skip_reason
778
796
  };
779
- case "completed":
780
- return {
781
- event_type: "step:completed",
782
- run_id: e.run_id,
783
- step_slug: e.step_slug,
784
- status: l.Completed,
785
- completed_at: e.completed_at,
786
- output: {}
787
- // Database doesn't have output in step_states
788
- };
789
- case "failed":
790
- return {
791
- event_type: "step:failed",
792
- run_id: e.run_id,
793
- step_slug: e.step_slug,
794
- status: l.Failed,
795
- failed_at: e.failed_at,
796
- error_message: e.error_message || "Step failed"
797
- };
798
- default:
799
- throw new Error(`Unknown step status: ${e.status}`);
800
797
  }
801
798
  }
802
- var q, b, y;
799
+ var z, w, y;
803
800
  class wt {
804
801
  /**
805
802
  * Creates a new PgflowClient instance
806
803
  *
807
804
  * @param supabaseClient - Supabase client instance
805
+ * @param opts - Optional configuration
808
806
  */
809
- constructor(t) {
810
- c(this, q);
811
- c(this, b);
807
+ constructor(t, r = {}) {
808
+ d(this, z);
809
+ d(this, w);
812
810
  // Use the widest event type - keeps the compiler happy but
813
811
  // still provides the structural API we need (updateState/step/...)
814
- c(this, y, /* @__PURE__ */ new Map());
815
- g(this, q, t), g(this, b, new rt(t)), r(this, b).onRunEvent((s) => {
816
- const n = r(this, y).get(s.run_id);
817
- n && n.updateState(it(s));
818
- }), r(this, b).onStepEvent((s) => {
819
- const n = r(this, y).get(s.run_id);
812
+ d(this, y, /* @__PURE__ */ new Map());
813
+ _(this, z, t), _(this, w, new rt(t, {
814
+ stabilizationDelayMs: r.realtimeStabilizationDelayMs,
815
+ schedule: r.schedule
816
+ })), e(this, w).onRunEvent((i) => {
817
+ const n = e(this, y).get(i.run_id);
818
+ n && n.updateState(nt(i));
819
+ }), e(this, w).onStepEvent((i) => {
820
+ const n = e(this, y).get(i.run_id);
820
821
  if (n) {
821
- const i = s.step_slug;
822
- n.step(i).updateState(at(s));
822
+ const g = i.step_slug;
823
+ n.step(g).updateState(at(i));
823
824
  }
824
825
  });
825
826
  }
@@ -831,12 +832,12 @@ class wt {
831
832
  * @param run_id - Optional run ID (will be generated if not provided)
832
833
  * @returns Promise that resolves with the FlowRun instance
833
834
  */
834
- async startFlow(t, s, n) {
835
- const i = n || st(), a = {
836
- run_id: i,
835
+ async startFlow(t, r, i) {
836
+ const n = i || st(), g = {
837
+ run_id: n,
837
838
  flow_slug: t,
838
- status: u.Started,
839
- input: s,
839
+ status: h.Started,
840
+ input: r,
840
841
  output: null,
841
842
  error: null,
842
843
  error_message: null,
@@ -845,19 +846,19 @@ class wt {
845
846
  failed_at: null,
846
847
  remaining_steps: -1
847
848
  // Use -1 to indicate unknown until first snapshot arrives
848
- }, _ = new Q(a);
849
- r(this, y).set(i, _), await r(this, b).subscribeToRun(i);
850
- const { data: h, error: d } = await r(this, q).schema("pgflow").rpc("start_flow_with_states", {
849
+ }, c = new V(g);
850
+ e(this, y).set(n, c), await e(this, w).subscribeToRun(n);
851
+ const { data: l, error: p } = await e(this, z).schema("pgflow").rpc("start_flow_with_states", {
851
852
  flow_slug: t,
852
- input: s,
853
- run_id: i
853
+ input: r,
854
+ run_id: n
854
855
  });
855
- if (d)
856
- throw this.dispose(i), d;
857
- if (h.run && _.updateState(ut(h.run)), h.steps && Array.isArray(h.steps))
858
- for (const m of h.steps)
859
- _.step(m.step_slug).updateState(V(m));
860
- return _;
856
+ if (p)
857
+ throw this.dispose(n), p;
858
+ if (l.run && c.applySnapshot(l.run), l.steps && Array.isArray(l.steps))
859
+ for (const b of l.steps)
860
+ c.step(b.step_slug).applySnapshot(b);
861
+ return c;
861
862
  }
862
863
  /**
863
864
  * Dispose a specific flow run
@@ -865,14 +866,14 @@ class wt {
865
866
  * @param runId - Run ID to dispose
866
867
  */
867
868
  dispose(t) {
868
- const s = r(this, y).get(t);
869
- s && (r(this, b).unsubscribe(t), s.dispose(), r(this, y).delete(t));
869
+ const r = e(this, y).get(t);
870
+ r && (e(this, w).unsubscribe(t), r.dispose(), e(this, y).delete(t));
870
871
  }
871
872
  /**
872
873
  * Dispose all flow runs
873
874
  */
874
875
  disposeAll() {
875
- for (const t of r(this, y).keys())
876
+ for (const t of e(this, y).keys())
876
877
  this.dispose(t);
877
878
  }
878
879
  // Delegate IFlowRealtime methods to the adapter
@@ -880,33 +881,33 @@ class wt {
880
881
  * Fetch flow definition metadata
881
882
  */
882
883
  async fetchFlowDefinition(t) {
883
- return r(this, b).fetchFlowDefinition(t);
884
+ return e(this, w).fetchFlowDefinition(t);
884
885
  }
885
886
  /**
886
887
  * Register a callback for run events
887
888
  * @returns Function to unsubscribe from the event
888
889
  */
889
890
  onRunEvent(t) {
890
- return r(this, b).onRunEvent(t);
891
+ return e(this, w).onRunEvent(t);
891
892
  }
892
893
  /**
893
894
  * Register a callback for step events
894
895
  * @returns Function to unsubscribe from the event
895
896
  */
896
897
  onStepEvent(t) {
897
- return r(this, b).onStepEvent(t);
898
+ return e(this, w).onStepEvent(t);
898
899
  }
899
900
  /**
900
901
  * Subscribe to a flow run's events
901
902
  */
902
903
  async subscribeToRun(t) {
903
- return await r(this, b).subscribeToRun(t);
904
+ return await e(this, w).subscribeToRun(t);
904
905
  }
905
906
  /**
906
907
  * Fetch current state of a run and its steps
907
908
  */
908
909
  async getRunWithStates(t) {
909
- return r(this, b).getRunWithStates(t);
910
+ return e(this, w).getRunWithStates(t);
910
911
  }
911
912
  /**
912
913
  * Get a flow run by ID
@@ -915,59 +916,59 @@ class wt {
915
916
  * @returns Promise that resolves with the FlowRun instance or null if not found
916
917
  */
917
918
  async getRun(t) {
918
- const s = r(this, y).get(t);
919
- if (s)
920
- return s;
919
+ const r = e(this, y).get(t);
920
+ if (r)
921
+ return r;
921
922
  try {
922
- const { run: n, steps: i } = await this.getRunWithStates(t);
923
- if (!n)
923
+ const { run: i, steps: n } = await this.getRunWithStates(t);
924
+ if (!i)
924
925
  return null;
925
- const a = n;
926
- if (!a.run_id || !a.flow_slug || !a.status)
926
+ if (!i.run_id || !i.flow_slug || !i.status)
927
927
  throw new Error("Invalid run data: missing required fields");
928
- if (!Object.values(u).includes(a.status))
929
- throw new Error(`Invalid run data: invalid status '${a.status}'`);
930
- const h = {
931
- run_id: a.run_id,
932
- flow_slug: a.flow_slug,
933
- status: a.status,
934
- input: a.input,
935
- output: a.output,
936
- error: a.error_message ? new Error(a.error_message) : null,
937
- error_message: a.error_message || null,
938
- started_at: a.started_at ? new Date(a.started_at) : null,
939
- completed_at: a.completed_at ? new Date(a.completed_at) : null,
940
- failed_at: a.failed_at ? new Date(a.failed_at) : null,
941
- remaining_steps: a.remaining_steps || 0
942
- }, d = new Q(h);
943
- if (r(this, y).set(t, d), await r(this, b).subscribeToRun(t), i && Array.isArray(i))
944
- for (const m of i) {
945
- if (!m.step_slug || !m.status)
928
+ if (!Object.values(h).includes(i.status))
929
+ throw new Error(`Invalid run data: invalid status '${i.status}'`);
930
+ const c = {
931
+ run_id: i.run_id,
932
+ flow_slug: i.flow_slug,
933
+ status: i.status,
934
+ input: i.input,
935
+ output: null,
936
+ error: null,
937
+ error_message: null,
938
+ started_at: null,
939
+ completed_at: null,
940
+ failed_at: null,
941
+ remaining_steps: 0
942
+ }, l = new V(c);
943
+ if (l.applySnapshot(i), e(this, y).set(t, l), await e(this, w).subscribeToRun(t), n && Array.isArray(n))
944
+ for (const p of n) {
945
+ if (!p.step_slug || !p.status)
946
946
  throw new Error("Invalid step data: missing required fields");
947
- d.step(m.step_slug).updateState(V(m));
947
+ l.step(p.step_slug).applySnapshot(p);
948
948
  }
949
- return d;
950
- } catch (n) {
951
- if (console.error("Error getting run:", n), n instanceof Error && (n.message.includes("Invalid run data") || n.message.includes("Invalid step data")))
952
- throw n;
949
+ return l;
950
+ } catch (i) {
951
+ if (console.error("Error getting run:", i), i instanceof Error && (i.message.includes("Invalid run data") || i.message.includes("Invalid step data")))
952
+ throw i;
953
953
  return null;
954
954
  }
955
955
  }
956
956
  }
957
- q = new WeakMap(), b = new WeakMap(), y = new WeakMap();
957
+ z = new WeakMap(), w = new WeakMap(), y = new WeakMap();
958
958
  export {
959
- Q as FlowRun,
960
- u as FlowRunStatus,
961
- nt as FlowStep,
962
- l as FlowStepStatus,
959
+ V as FlowRun,
960
+ h as FlowRunStatus,
961
+ it as FlowStep,
962
+ u as FlowStepStatus,
963
963
  wt as PgflowClient,
964
- ht as isFlowRunCompletedEvent,
965
- ct as isFlowRunEvent,
966
- _t as isFlowRunFailedEvent,
967
- pt as isFlowRunStartedEvent,
968
- mt as isStepCompletedEvent,
969
- K as isStepEvent,
970
- gt as isStepFailedEvent,
971
- ft as isStepStartedEvent
964
+ ct as isFlowRunCompletedEvent,
965
+ pt as isFlowRunEvent,
966
+ ht as isFlowRunFailedEvent,
967
+ dt as isFlowRunStartedEvent,
968
+ ft as isStepCompletedEvent,
969
+ O as isStepEvent,
970
+ mt as isStepFailedEvent,
971
+ gt as isStepSkippedEvent,
972
+ _t as isStepStartedEvent
972
973
  };
973
974
  //# sourceMappingURL=index.js.map