@pgflow/client 0.13.3 → 0.14.0

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