@pgflow/client 0.7.2 → 0.7.3

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 (32) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/client/src/browser.d.ts.map +1 -0
  3. package/dist/client/src/index.d.ts.map +1 -0
  4. package/dist/client/src/lib/FlowRun.d.ts.map +1 -0
  5. package/dist/client/src/lib/FlowStep.d.ts.map +1 -0
  6. package/dist/{src → client/src}/lib/PgflowClient.d.ts +5 -1
  7. package/dist/client/src/lib/PgflowClient.d.ts.map +1 -0
  8. package/dist/{src → client/src}/lib/SupabaseBroadcastAdapter.d.ts +1 -0
  9. package/dist/client/src/lib/SupabaseBroadcastAdapter.d.ts.map +1 -0
  10. package/dist/client/src/lib/eventAdapters.d.ts.map +1 -0
  11. package/dist/client/src/lib/types.d.ts.map +1 -0
  12. package/dist/index.d.ts +1 -1
  13. package/dist/index.js +221 -216
  14. package/dist/index.js.map +1 -1
  15. package/dist/package.json +2 -1
  16. package/dist/pgflow-client.browser.js +1 -1
  17. package/dist/pgflow-client.browser.js.map +1 -1
  18. package/package.json +5 -4
  19. package/dist/src/browser.d.ts.map +0 -1
  20. package/dist/src/index.d.ts.map +0 -1
  21. package/dist/src/lib/FlowRun.d.ts.map +0 -1
  22. package/dist/src/lib/FlowStep.d.ts.map +0 -1
  23. package/dist/src/lib/PgflowClient.d.ts.map +0 -1
  24. package/dist/src/lib/SupabaseBroadcastAdapter.d.ts.map +0 -1
  25. package/dist/src/lib/eventAdapters.d.ts.map +0 -1
  26. package/dist/src/lib/types.d.ts.map +0 -1
  27. /package/dist/{src → client/src}/browser.d.ts +0 -0
  28. /package/dist/{src → client/src}/index.d.ts +0 -0
  29. /package/dist/{src → client/src}/lib/FlowRun.d.ts +0 -0
  30. /package/dist/{src → client/src}/lib/FlowStep.d.ts +0 -0
  31. /package/dist/{src → client/src}/lib/eventAdapters.d.ts +0 -0
  32. /package/dist/{src → client/src}/lib/types.d.ts +0 -0
package/dist/index.js CHANGED
@@ -1,61 +1,62 @@
1
- var N = (s) => {
1
+ var Q = (s) => {
2
2
  throw TypeError(s);
3
3
  };
4
- var O = (s, t, r) => t.has(s) || N("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) ? N("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(s) : t.set(s, r), _ = (s, t, r, n) => (O(s, t, "write to private field"), n ? n.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, n) => ({
7
- set _(i) {
8
- _(s, t, i, r);
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) => ({
7
+ set _(n) {
8
+ f(s, t, n, r);
9
9
  },
10
10
  get _() {
11
- return e(s, t, n);
11
+ return e(s, t, i);
12
12
  }
13
13
  });
14
- import { v4 as et } from "uuid";
14
+ import { v4 as st } from "uuid";
15
15
  import { createNanoEvents as L } from "nanoevents";
16
- var c = /* @__PURE__ */ ((s) => (s.Started = "started", s.Completed = "completed", s.Failed = "failed", s))(c || {});
17
- function lt(s) {
16
+ var p = /* @__PURE__ */ ((s) => (s.Started = "started", s.Completed = "completed", s.Failed = "failed", s))(p || {});
17
+ function dt(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 dt(s) {
20
+ function ct(s) {
21
21
  return s.status === "started";
22
22
  }
23
- function ct(s) {
23
+ function pt(s) {
24
24
  return s.status === "completed";
25
25
  }
26
- function pt(s) {
26
+ function ht(s) {
27
27
  return s.status === "failed";
28
28
  }
29
29
  var h = /* @__PURE__ */ ((s) => (s.Created = "created", s.Started = "started", s.Completed = "completed", s.Failed = "failed", s))(h || {});
30
- function K(s) {
30
+ function N(s) {
31
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
32
  }
33
- function ht(s) {
34
- return K(s) && s.status === "started" && "event_type" in s && s.event_type === "step:started";
35
- }
36
33
  function ft(s) {
37
- return K(s) && s.status === "completed" && "event_type" in s && s.event_type === "step:completed";
34
+ return N(s) && s.status === "started" && "event_type" in s && s.event_type === "step:started";
38
35
  }
39
36
  function _t(s) {
40
- return K(s) && s.status === "failed" && "event_type" in s && s.event_type === "step:failed";
37
+ return N(s) && s.status === "completed" && "event_type" in s && s.event_type === "step:completed";
41
38
  }
42
- var S, C, F, U, I, f, j, V, z, X, Y, Z, k, G;
43
- class st {
39
+ function mt(s) {
40
+ return N(s) && s.status === "failed" && "event_type" in s && s.event_type === "step:failed";
41
+ }
42
+ var S, C, F, I, W, M, _, j, X, G, Y, Z, v, k, K;
43
+ class rt {
44
44
  /**
45
45
  * Creates a new instance of SupabaseBroadcastAdapter
46
46
  *
47
47
  * @param supabase - Supabase client instance
48
48
  */
49
49
  constructor(t, r = {}) {
50
- d(this, f);
50
+ d(this, _);
51
51
  d(this, S);
52
52
  d(this, C, /* @__PURE__ */ new Map());
53
53
  d(this, F, L());
54
- d(this, U);
55
54
  d(this, I);
55
+ d(this, W);
56
+ d(this, M);
56
57
  // Store unsubscribe functions per run ID for reference equality
57
58
  d(this, k, /* @__PURE__ */ new Map());
58
- _(this, S, t), _(this, U, r.reconnectDelayMs ?? 2e3), _(this, I, r.schedule ?? setTimeout);
59
+ f(this, S, t), f(this, I, r.reconnectDelayMs ?? 2e3), f(this, W, r.stabilizationDelayMs ?? 300), f(this, M, r.schedule ?? setTimeout);
59
60
  }
60
61
  /**
61
62
  * Fetches flow definition metadata from the database
@@ -63,17 +64,17 @@ class st {
63
64
  * @param flow_slug - Flow slug to fetch
64
65
  */
65
66
  async fetchFlowDefinition(t) {
66
- const [r, n] = await Promise.all([
67
+ const [r, i] = await Promise.all([
67
68
  e(this, S).schema("pgflow").from("flows").select("*").eq("flow_slug", t).single(),
68
69
  e(this, S).schema("pgflow").from("steps").select("*").eq("flow_slug", t).order("step_index", { ascending: !0 })
69
70
  ]);
70
71
  if (r.error) throw r.error;
71
72
  if (!r.data) throw new Error(`Flow "${t}" not found`);
72
- if (n.error) throw n.error;
73
- const i = Array.isArray(n.data) ? n.data : [];
73
+ if (i.error) throw i.error;
74
+ const n = Array.isArray(i.data) ? i.data : [];
74
75
  return {
75
76
  flow: r.data,
76
- steps: i
77
+ steps: n
77
78
  };
78
79
  }
79
80
  /**
@@ -87,8 +88,8 @@ class st {
87
88
  return () => {
88
89
  try {
89
90
  r();
90
- } catch (n) {
91
- console.warn("Could not unsubscribe from run event - emitter may have been disposed", n);
91
+ } catch (i) {
92
+ console.warn("Could not unsubscribe from run event - emitter may have been disposed", i);
92
93
  }
93
94
  };
94
95
  }
@@ -103,8 +104,8 @@ class st {
103
104
  return () => {
104
105
  try {
105
106
  r();
106
- } catch (n) {
107
- console.warn("Could not unsubscribe from step event - emitter may have been disposed", n);
107
+ } catch (i) {
108
+ console.warn("Could not unsubscribe from step event - emitter may have been disposed", i);
108
109
  }
109
110
  };
110
111
  }
@@ -117,26 +118,26 @@ class st {
117
118
  async subscribeToRun(t) {
118
119
  const r = `pgflow:run:${t}`;
119
120
  if (e(this, C).has(t)) {
120
- const p = e(this, k).get(t);
121
- if (p)
122
- return p;
123
- m(this, f, G).call(this, t);
121
+ const c = e(this, k).get(t);
122
+ if (c)
123
+ return c;
124
+ m(this, _, K).call(this, t);
124
125
  }
125
- const n = e(this, S).channel(r);
126
- n.on("broadcast", { event: "*" }, m(this, f, j).bind(this)), n.on("system", { event: "closed" }, () => {
126
+ const i = e(this, S).channel(r);
127
+ i.on("broadcast", { event: "*" }, m(this, _, j).bind(this)), i.on("system", { event: "closed" }, () => {
127
128
  console.log(`Channel ${r} closed`);
128
- }), n.on("system", { event: "error" }, (p) => {
129
- console.log(`Channel ${r} error:`, p), m(this, f, z).call(this, t, r, n, p.error);
130
- }), console.log(`Subscribing to channel ${r}...`), await new Promise((p, u) => {
129
+ }), 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) => {
131
132
  const l = setTimeout(() => {
132
133
  u(new Error(`Subscription timeout for channel ${r}`));
133
134
  }, 2e4);
134
- n.subscribe((b) => {
135
- console.log(`Channel ${r} subscription status:`, b), b === "SUBSCRIBED" && (clearTimeout(l), p());
135
+ i.subscribe((b) => {
136
+ console.log(`Channel ${r} subscription status:`, b), b === "SUBSCRIBED" && (clearTimeout(l), c());
136
137
  });
137
- }), e(this, C).set(t, n);
138
- const w = () => this.unsubscribe(t);
139
- return e(this, k).set(t, w), w;
138
+ }), await new Promise((c) => e(this, M).call(this, c, e(this, W))), e(this, C).set(t, i);
139
+ const g = () => this.unsubscribe(t);
140
+ return e(this, k).set(t, g), g;
140
141
  }
141
142
  /**
142
143
  * Unsubscribes from a run's events
@@ -144,7 +145,7 @@ class st {
144
145
  * @param run_id - Run ID to unsubscribe from
145
146
  */
146
147
  unsubscribe(t) {
147
- m(this, f, G).call(this, t);
148
+ m(this, _, K).call(this, t);
148
149
  }
149
150
  /**
150
151
  * Fetches current state of a run and its steps
@@ -152,24 +153,24 @@ class st {
152
153
  * @param run_id - Run ID to fetch
153
154
  */
154
155
  async getRunWithStates(t) {
155
- const { data: r, error: n } = await e(this, S).schema("pgflow").rpc("get_run_with_states", { run_id: t });
156
- if (n) throw n;
156
+ const { data: r, error: i } = await e(this, S).schema("pgflow").rpc("get_run_with_states", { run_id: t });
157
+ if (i) throw i;
157
158
  if (!r) throw new Error(`No data returned for run ${t}`);
158
159
  return r;
159
160
  }
160
161
  }
161
- S = new WeakMap(), C = new WeakMap(), F = new WeakMap(), U = new WeakMap(), I = new WeakMap(), f = new WeakSet(), /**
162
+ S = new WeakMap(), C = new WeakMap(), F = new WeakMap(), I = new WeakMap(), W = new WeakMap(), M = new WeakMap(), _ = new WeakSet(), /**
162
163
  * Handle broadcast messages from Supabase
163
164
  * @param payload - The message payload
164
165
  */
165
166
  j = function(t) {
166
- const { event: r, payload: n } = t, i = n;
167
- m(this, f, V).call(this, i), r.startsWith("run:") ? e(this, F).emit("runEvent", i) : r.startsWith("step:") && e(this, F).emit("stepEvent", i);
167
+ 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);
168
169
  }, /**
169
170
  * Parse JSON string fields in broadcast event data
170
171
  * @param eventData - The event data object to parse
171
172
  */
172
- V = function(t) {
173
+ X = function(t) {
173
174
  if ("output" in t && typeof t.output == "string")
174
175
  try {
175
176
  t.output = JSON.parse(t.output);
@@ -180,67 +181,67 @@ V = function(t) {
180
181
  t.input = JSON.parse(t.input);
181
182
  } catch {
182
183
  }
183
- }, z = async function(t, r, n, i) {
184
- console.error(`Channel ${r} error:`, i), e(this, I).call(this, async () => {
185
- e(this, C).has(t) && await m(this, f, Y).call(this, t, r);
186
- }, e(this, U));
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
+ }, e(this, I));
187
188
  }, /**
188
189
  * Creates and configures a channel for a run
189
190
  * @param run_id - The run ID
190
191
  * @param channelName - The channel name
191
192
  * @returns The configured RealtimeChannel
192
193
  */
193
- X = function(t, r) {
194
- const n = e(this, S).channel(r);
195
- return n.on("broadcast", { event: "*" }, m(this, f, j).bind(this)), n;
196
- }, Y = async function(t, r) {
194
+ Y = function(t, r) {
195
+ const i = e(this, S).channel(r);
196
+ return i.on("broadcast", { event: "*" }, m(this, _, j).bind(this)), i;
197
+ }, Z = async function(t, r) {
197
198
  console.log(`Attempting to reconnect to ${r}`);
198
199
  try {
199
- const n = await this.getRunWithStates(t);
200
- m(this, f, Z).call(this, t, n);
201
- const i = m(this, f, X).call(this, t, r);
202
- i.on("system", { event: "subscribed" }, () => {
200
+ const i = await this.getRunWithStates(t);
201
+ m(this, _, v).call(this, t, i);
202
+ const n = m(this, _, Y).call(this, t, r);
203
+ n.on("system", { event: "subscribed" }, () => {
203
204
  console.log(`Reconnected and subscribed to channel ${r}`);
204
- }), i.on("system", { event: "closed" }, () => {
205
+ }), n.on("system", { event: "closed" }, () => {
205
206
  console.log(`Reconnected channel ${r} closed`);
206
- }), i.on(
207
+ }), n.on(
207
208
  "system",
208
209
  { event: "error" },
209
- (w) => m(this, f, z).call(this, t, r, i, w.error)
210
- ), i.subscribe(), e(this, C).set(t, i);
211
- } catch (n) {
212
- console.error(`Failed to reconnect to ${r}:`, n);
210
+ (g) => m(this, _, G).call(this, t, r, n, g.error)
211
+ ), n.subscribe(), e(this, C).set(t, n);
212
+ } catch (i) {
213
+ console.error(`Failed to reconnect to ${r}:`, i);
213
214
  }
214
215
  }, /**
215
216
  * Refresh client state from a state snapshot
216
217
  * @param run_id - The run ID
217
218
  * @param state - The state snapshot
218
219
  */
219
- Z = function(t, r) {
220
+ v = function(t, r) {
220
221
  if (!r || !r.run) return;
221
- const n = {
222
+ const i = {
222
223
  event_type: `run:${r.run.status}`,
223
224
  ...r.run
224
225
  };
225
- if (e(this, F).emit("runEvent", n), r.steps && Array.isArray(r.steps))
226
- for (const i of r.steps) {
227
- const w = {
228
- event_type: `step:${i.status}`,
229
- ...i
226
+ if (e(this, F).emit("runEvent", i), r.steps && Array.isArray(r.steps))
227
+ for (const n of r.steps) {
228
+ const g = {
229
+ event_type: `step:${n.status}`,
230
+ ...n
230
231
  };
231
- e(this, F).emit("stepEvent", w);
232
+ e(this, F).emit("stepEvent", g);
232
233
  }
233
234
  }, k = new WeakMap(), /**
234
235
  * Unsubscribes from a run's events
235
236
  *
236
237
  * @param run_id - Run ID to unsubscribe from
237
238
  */
238
- G = function(t) {
239
+ K = function(t) {
239
240
  const r = e(this, C).get(t);
240
241
  r && (r.unsubscribe(), e(this, C).delete(t), e(this, k).delete(t));
241
242
  };
242
- var o, $, W, J, v;
243
- class rt {
243
+ var o, $, x, J, tt;
244
+ class it {
244
245
  /**
245
246
  * Creates a new FlowStep instance
246
247
  *
@@ -250,13 +251,13 @@ class rt {
250
251
  d(this, J);
251
252
  d(this, o);
252
253
  d(this, $, L());
253
- d(this, W, {
254
+ d(this, x, {
254
255
  [h.Created]: 0,
255
256
  [h.Started]: 1,
256
257
  [h.Completed]: 2,
257
258
  [h.Failed]: 3
258
259
  });
259
- _(this, o, t);
260
+ f(this, o, t);
260
261
  }
261
262
  /**
262
263
  * Get the run ID this step belongs to
@@ -330,25 +331,25 @@ class rt {
330
331
  * @returns Promise that resolves with the step instance when the status is reached
331
332
  */
332
333
  waitForStatus(t, r) {
333
- const n = (r == null ? void 0 : r.timeoutMs) ?? 3e5, { signal: i } = r || {};
334
- return this.status === t ? Promise.resolve(this) : new Promise((w, p) => {
334
+ const i = (r == null ? void 0 : r.timeoutMs) ?? 3e5, { signal: n } = r || {};
335
+ return this.status === t ? Promise.resolve(this) : new Promise((g, c) => {
335
336
  let u, l = !1;
336
- n > 0 && (u = setTimeout(() => {
337
- l || (l = !0, T(), p(new Error(`Timeout waiting for step ${this.step_slug} to reach status '${t}'`)));
338
- }, n));
337
+ i > 0 && (u = setTimeout(() => {
338
+ l || (l = !0, P(), c(new Error(`Timeout waiting for step ${this.step_slug} to reach status '${t}'`)));
339
+ }, i));
339
340
  let b;
340
- if (i) {
341
+ if (n) {
341
342
  const E = () => {
342
- l || (l = !0, u && clearTimeout(u), T(), p(new Error(`Aborted waiting for step ${this.step_slug} to reach status '${t}'`)));
343
+ l || (l = !0, u && clearTimeout(u), P(), c(new Error(`Aborted waiting for step ${this.step_slug} to reach status '${t}'`)));
343
344
  };
344
- i.addEventListener("abort", E), b = () => {
345
- i.removeEventListener("abort", E);
345
+ n.addEventListener("abort", E), b = () => {
346
+ n.removeEventListener("abort", E);
346
347
  };
347
348
  }
348
- const T = this.on("*", (E) => {
349
+ const P = this.on("*", (E) => {
349
350
  if (E.status === t) {
350
351
  if (l) return;
351
- l = !0, u && clearTimeout(u), b && b(), T(), w(this);
352
+ l = !0, u && clearTimeout(u), b && b(), P(), g(this);
352
353
  }
353
354
  });
354
355
  });
@@ -374,18 +375,18 @@ class rt {
374
375
  * with event emission instead of direct state manipulation.
375
376
  */
376
377
  updateState(t) {
377
- if (t.step_slug !== e(this, o).step_slug || t.run_id !== e(this, o).run_id || !m(this, J, v).call(this, e(this, o).status, t.status))
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))
378
379
  return !1;
379
380
  switch (t.status) {
380
381
  case h.Started:
381
- _(this, o, {
382
+ f(this, o, {
382
383
  ...e(this, o),
383
384
  status: h.Started,
384
385
  started_at: typeof t.started_at == "string" ? new Date(t.started_at) : /* @__PURE__ */ new Date()
385
386
  }), e(this, $).emit("started", t);
386
387
  break;
387
388
  case h.Completed:
388
- _(this, o, {
389
+ f(this, o, {
389
390
  ...e(this, o),
390
391
  status: h.Completed,
391
392
  completed_at: typeof t.completed_at == "string" ? new Date(t.completed_at) : /* @__PURE__ */ new Date(),
@@ -393,7 +394,7 @@ class rt {
393
394
  }), e(this, $).emit("completed", t);
394
395
  break;
395
396
  case h.Failed:
396
- _(this, o, {
397
+ f(this, o, {
397
398
  ...e(this, o),
398
399
  status: h.Failed,
399
400
  failed_at: typeof t.failed_at == "string" ? new Date(t.failed_at) : /* @__PURE__ */ new Date(),
@@ -407,21 +408,21 @@ class rt {
407
408
  return e(this, $).emit("*", t), !0;
408
409
  }
409
410
  }
410
- o = new WeakMap(), $ = new WeakMap(), W = new WeakMap(), J = new WeakSet(), /**
411
+ o = new WeakMap(), $ = new WeakMap(), x = new WeakMap(), J = new WeakSet(), /**
411
412
  * Determines if a status should be updated based on precedence
412
413
  *
413
414
  * @param currentStatus - Current status
414
415
  * @param newStatus - New status
415
416
  * @returns true if the status should be updated, false otherwise
416
417
  */
417
- v = function(t, r) {
418
+ tt = function(t, r) {
418
419
  if (t === h.Completed || t === h.Failed)
419
420
  return !1;
420
- const n = e(this, W)[t];
421
- return e(this, W)[r] > n;
421
+ const i = e(this, x)[t];
422
+ return e(this, x)[r] > i;
422
423
  };
423
- var a, R, A, x, M, P, D, B, tt;
424
- class Q {
424
+ var a, R, T, q, U, A, D, B, et;
425
+ class V {
425
426
  /**
426
427
  * Creates a new FlowRun instance
427
428
  *
@@ -431,16 +432,16 @@ class Q {
431
432
  d(this, D);
432
433
  d(this, a);
433
434
  d(this, R, L());
434
- d(this, A, /* @__PURE__ */ new Map());
435
- d(this, x, {
436
- [c.Started]: 0,
437
- [c.Completed]: 1,
438
- [c.Failed]: 2
435
+ d(this, T, /* @__PURE__ */ new Map());
436
+ d(this, q, {
437
+ [p.Started]: 0,
438
+ [p.Completed]: 1,
439
+ [p.Failed]: 2
439
440
  });
440
- d(this, M, !1);
441
+ d(this, U, !1);
441
442
  // Track number of listeners
442
- d(this, P, 0);
443
- _(this, a, t);
443
+ d(this, A, 0);
444
+ f(this, a, t);
444
445
  }
445
446
  /**
446
447
  * Get the run ID
@@ -516,10 +517,10 @@ class Q {
516
517
  * @returns Function to unsubscribe from the event
517
518
  */
518
519
  on(t, r) {
519
- H(this, P)._++;
520
- const n = e(this, R).on(t, r);
520
+ H(this, A)._++;
521
+ const i = e(this, R).on(t, r);
521
522
  return () => {
522
- n(), H(this, P)._--, m(this, D, B).call(this);
523
+ i(), H(this, A)._--, m(this, D, B).call(this);
523
524
  };
524
525
  }
525
526
  /**
@@ -529,10 +530,10 @@ class Q {
529
530
  * @returns FlowStep instance for the specified step
530
531
  */
531
532
  step(t) {
532
- const r = e(this, A).get(t);
533
+ const r = e(this, T).get(t);
533
534
  if (r)
534
535
  return r;
535
- const n = new rt({
536
+ const i = new it({
536
537
  run_id: this.run_id,
537
538
  step_slug: t,
538
539
  status: h.Created,
@@ -543,10 +544,10 @@ class Q {
543
544
  completed_at: null,
544
545
  failed_at: null
545
546
  });
546
- return e(this, A).set(
547
+ return e(this, T).set(
547
548
  t,
548
- n
549
- ), n;
549
+ i
550
+ ), i;
550
551
  }
551
552
  /**
552
553
  * Check if this run has a specific step
@@ -555,7 +556,7 @@ class Q {
555
556
  * @returns true if the step exists, false otherwise
556
557
  */
557
558
  hasStep(t) {
558
- return e(this, A).has(t);
559
+ return e(this, T).has(t);
559
560
  }
560
561
  /**
561
562
  * Wait for the run to reach a specific status
@@ -565,33 +566,33 @@ class Q {
565
566
  * @returns Promise that resolves with the run instance when the status is reached
566
567
  */
567
568
  waitForStatus(t, r) {
568
- const n = (r == null ? void 0 : r.timeoutMs) ?? 3e5, { signal: i } = r || {};
569
- return this.status === t ? Promise.resolve(this) : new Promise((w, p) => {
569
+ const i = (r == null ? void 0 : r.timeoutMs) ?? 3e5, { signal: n } = r || {};
570
+ return this.status === t ? Promise.resolve(this) : new Promise((g, c) => {
570
571
  let u, l = !1;
571
- n > 0 && (u = setTimeout(() => {
572
- l || (l = !0, T(), p(
572
+ i > 0 && (u = setTimeout(() => {
573
+ l || (l = !0, P(), c(
573
574
  new Error(
574
575
  `Timeout waiting for run ${this.run_id} to reach status '${t}'`
575
576
  )
576
577
  ));
577
- }, n));
578
+ }, i));
578
579
  let b;
579
- if (i) {
580
+ if (n) {
580
581
  const E = () => {
581
- l || (l = !0, u && clearTimeout(u), T(), p(
582
+ l || (l = !0, u && clearTimeout(u), P(), c(
582
583
  new Error(
583
584
  `Aborted waiting for run ${this.run_id} to reach status '${t}'`
584
585
  )
585
586
  ));
586
587
  };
587
- i.addEventListener("abort", E), b = () => {
588
- i.removeEventListener("abort", E);
588
+ n.addEventListener("abort", E), b = () => {
589
+ n.removeEventListener("abort", E);
589
590
  };
590
591
  }
591
- const T = this.on("*", (E) => {
592
+ const P = this.on("*", (E) => {
592
593
  if (E.status === t) {
593
594
  if (l) return;
594
- l = !0, u && clearTimeout(u), b && b(), T(), w(this);
595
+ l = !0, u && clearTimeout(u), b && b(), P(), g(this);
595
596
  }
596
597
  });
597
598
  });
@@ -617,30 +618,30 @@ class Q {
617
618
  * with event emission instead of direct state manipulation.
618
619
  */
619
620
  updateState(t) {
620
- if (t.run_id !== e(this, a).run_id || !m(this, D, tt).call(this, e(this, a).status, t.status))
621
+ if (t.run_id !== e(this, a).run_id || !m(this, D, et).call(this, e(this, a).status, t.status))
621
622
  return !1;
622
623
  switch (t.status) {
623
- case c.Started:
624
- _(this, a, {
624
+ case p.Started:
625
+ f(this, a, {
625
626
  ...e(this, a),
626
- status: c.Started,
627
+ status: p.Started,
627
628
  started_at: typeof t.started_at == "string" ? new Date(t.started_at) : /* @__PURE__ */ new Date(),
628
629
  remaining_steps: "remaining_steps" in t ? Number(t.remaining_steps) : e(this, a).remaining_steps
629
630
  }), e(this, R).emit("started", t);
630
631
  break;
631
- case c.Completed:
632
- _(this, a, {
632
+ case p.Completed:
633
+ f(this, a, {
633
634
  ...e(this, a),
634
- status: c.Completed,
635
+ status: p.Completed,
635
636
  completed_at: typeof t.completed_at == "string" ? new Date(t.completed_at) : /* @__PURE__ */ new Date(),
636
637
  output: t.output,
637
638
  remaining_steps: 0
638
639
  }), e(this, R).emit("completed", t), m(this, D, B).call(this);
639
640
  break;
640
- case c.Failed:
641
- _(this, a, {
641
+ case p.Failed:
642
+ f(this, a, {
642
643
  ...e(this, a),
643
- status: c.Failed,
644
+ status: p.Failed,
644
645
  failed_at: typeof t.failed_at == "string" ? new Date(t.failed_at) : /* @__PURE__ */ new Date(),
645
646
  error_message: typeof t.error_message == "string" ? t.error_message : "Unknown error",
646
647
  error: new Error(
@@ -667,14 +668,14 @@ class Q {
667
668
  * Clean up all resources held by this run
668
669
  */
669
670
  dispose() {
670
- e(this, M) || (e(this, A).clear(), _(this, R, L()), _(this, P, 0), _(this, M, !0));
671
+ e(this, U) || (e(this, T).clear(), f(this, R, L()), f(this, A, 0), f(this, U, !0));
671
672
  }
672
673
  }
673
- a = new WeakMap(), R = new WeakMap(), A = new WeakMap(), x = new WeakMap(), M = new WeakMap(), P = new WeakMap(), D = new WeakSet(), /**
674
+ a = new WeakMap(), R = new WeakMap(), T = new WeakMap(), q = new WeakMap(), U = new WeakMap(), A = new WeakMap(), D = new WeakSet(), /**
674
675
  * Checks if auto-dispose should be triggered (when in terminal state with no listeners)
675
676
  */
676
677
  B = function() {
677
- e(this, M) || this.status !== c.Completed && this.status !== c.Failed || e(this, P) === 0 && this.dispose();
678
+ e(this, U) || this.status !== p.Completed && this.status !== p.Failed || e(this, A) === 0 && this.dispose();
678
679
  }, /**
679
680
  * Determines if a status should be updated based on precedence
680
681
  *
@@ -682,45 +683,45 @@ B = function() {
682
683
  * @param newStatus - New status
683
684
  * @returns true if the status should be updated, false otherwise
684
685
  */
685
- tt = function(t, r) {
686
- if (t === c.Completed || t === c.Failed)
686
+ et = function(t, r) {
687
+ if (t === p.Completed || t === p.Failed)
687
688
  return !1;
688
- const n = e(this, x)[t];
689
- return e(this, x)[r] > n;
689
+ const i = e(this, q)[t];
690
+ return e(this, q)[r] > i;
690
691
  };
691
692
  function nt(s) {
692
693
  switch (s.status) {
693
- case c.Started:
694
+ case p.Started:
694
695
  return {
695
696
  event_type: "run:started",
696
697
  run_id: s.run_id,
697
698
  flow_slug: s.flow_slug,
698
- status: c.Started,
699
+ status: p.Started,
699
700
  started_at: s.started_at,
700
701
  remaining_steps: s.remaining_steps,
701
702
  input: s.input
702
703
  };
703
- case c.Completed:
704
+ case p.Completed:
704
705
  return {
705
706
  event_type: "run:completed",
706
707
  run_id: s.run_id,
707
708
  flow_slug: s.flow_slug,
708
- status: c.Completed,
709
+ status: p.Completed,
709
710
  completed_at: s.completed_at,
710
711
  output: s.output
711
712
  };
712
- case c.Failed:
713
+ case p.Failed:
713
714
  return {
714
715
  event_type: "run:failed",
715
716
  run_id: s.run_id,
716
717
  flow_slug: s.flow_slug,
717
- status: c.Failed,
718
+ status: p.Failed,
718
719
  failed_at: s.failed_at,
719
720
  error_message: s.error_message
720
721
  };
721
722
  }
722
723
  }
723
- function it(s) {
724
+ function at(s) {
724
725
  switch (s.status) {
725
726
  case h.Started:
726
727
  return {
@@ -750,27 +751,31 @@ function it(s) {
750
751
  };
751
752
  }
752
753
  }
753
- var q, g, y;
754
- class mt {
754
+ var z, w, y;
755
+ class gt {
755
756
  /**
756
757
  * Creates a new PgflowClient instance
757
758
  *
758
759
  * @param supabaseClient - Supabase client instance
760
+ * @param opts - Optional configuration
759
761
  */
760
- constructor(t) {
761
- d(this, q);
762
- d(this, g);
762
+ constructor(t, r = {}) {
763
+ d(this, z);
764
+ d(this, w);
763
765
  // Use the widest event type - keeps the compiler happy but
764
766
  // still provides the structural API we need (updateState/step/...)
765
767
  d(this, y, /* @__PURE__ */ new Map());
766
- _(this, q, t), _(this, g, new st(t)), e(this, g).onRunEvent((r) => {
767
- const n = e(this, y).get(r.run_id);
768
- n && n.updateState(nt(r));
769
- }), e(this, g).onStepEvent((r) => {
770
- const n = e(this, y).get(r.run_id);
768
+ f(this, z, t), f(this, w, new rt(t, {
769
+ stabilizationDelayMs: r.realtimeStabilizationDelayMs,
770
+ schedule: r.schedule
771
+ })), e(this, w).onRunEvent((i) => {
772
+ const n = e(this, y).get(i.run_id);
773
+ n && n.updateState(nt(i));
774
+ }), e(this, w).onStepEvent((i) => {
775
+ const n = e(this, y).get(i.run_id);
771
776
  if (n) {
772
- const i = r.step_slug;
773
- n.step(i).updateState(it(r));
777
+ const g = i.step_slug;
778
+ n.step(g).updateState(at(i));
774
779
  }
775
780
  });
776
781
  }
@@ -782,11 +787,11 @@ class mt {
782
787
  * @param run_id - Optional run ID (will be generated if not provided)
783
788
  * @returns Promise that resolves with the FlowRun instance
784
789
  */
785
- async startFlow(t, r, n) {
786
- const i = n || et(), w = {
787
- run_id: i,
790
+ async startFlow(t, r, i) {
791
+ const n = i || st(), g = {
792
+ run_id: n,
788
793
  flow_slug: t,
789
- status: c.Started,
794
+ status: p.Started,
790
795
  input: r,
791
796
  output: null,
792
797
  error: null,
@@ -796,19 +801,19 @@ class mt {
796
801
  failed_at: null,
797
802
  remaining_steps: -1
798
803
  // Use -1 to indicate unknown until first snapshot arrives
799
- }, p = new Q(w);
800
- e(this, y).set(i, p), await e(this, g).subscribeToRun(i);
801
- const { data: u, error: l } = await e(this, q).schema("pgflow").rpc("start_flow_with_states", {
804
+ }, c = new V(g);
805
+ 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", {
802
807
  flow_slug: t,
803
808
  input: r,
804
- run_id: i
809
+ run_id: n
805
810
  });
806
811
  if (l)
807
- throw this.dispose(i), l;
808
- if (u.run && p.applySnapshot(u.run), u.steps && Array.isArray(u.steps))
812
+ throw this.dispose(n), l;
813
+ if (u.run && c.applySnapshot(u.run), u.steps && Array.isArray(u.steps))
809
814
  for (const b of u.steps)
810
- p.step(b.step_slug).applySnapshot(b);
811
- return p;
815
+ c.step(b.step_slug).applySnapshot(b);
816
+ return c;
812
817
  }
813
818
  /**
814
819
  * Dispose a specific flow run
@@ -817,7 +822,7 @@ class mt {
817
822
  */
818
823
  dispose(t) {
819
824
  const r = e(this, y).get(t);
820
- r && (e(this, g).unsubscribe(t), r.dispose(), e(this, y).delete(t));
825
+ r && (e(this, w).unsubscribe(t), r.dispose(), e(this, y).delete(t));
821
826
  }
822
827
  /**
823
828
  * Dispose all flow runs
@@ -831,33 +836,33 @@ class mt {
831
836
  * Fetch flow definition metadata
832
837
  */
833
838
  async fetchFlowDefinition(t) {
834
- return e(this, g).fetchFlowDefinition(t);
839
+ return e(this, w).fetchFlowDefinition(t);
835
840
  }
836
841
  /**
837
842
  * Register a callback for run events
838
843
  * @returns Function to unsubscribe from the event
839
844
  */
840
845
  onRunEvent(t) {
841
- return e(this, g).onRunEvent(t);
846
+ return e(this, w).onRunEvent(t);
842
847
  }
843
848
  /**
844
849
  * Register a callback for step events
845
850
  * @returns Function to unsubscribe from the event
846
851
  */
847
852
  onStepEvent(t) {
848
- return e(this, g).onStepEvent(t);
853
+ return e(this, w).onStepEvent(t);
849
854
  }
850
855
  /**
851
856
  * Subscribe to a flow run's events
852
857
  */
853
858
  async subscribeToRun(t) {
854
- return await e(this, g).subscribeToRun(t);
859
+ return await e(this, w).subscribeToRun(t);
855
860
  }
856
861
  /**
857
862
  * Fetch current state of a run and its steps
858
863
  */
859
864
  async getRunWithStates(t) {
860
- return e(this, g).getRunWithStates(t);
865
+ return e(this, w).getRunWithStates(t);
861
866
  }
862
867
  /**
863
868
  * Get a flow run by ID
@@ -870,18 +875,18 @@ class mt {
870
875
  if (r)
871
876
  return r;
872
877
  try {
873
- const { run: n, steps: i } = await this.getRunWithStates(t);
874
- if (!n)
878
+ const { run: i, steps: n } = await this.getRunWithStates(t);
879
+ if (!i)
875
880
  return null;
876
- if (!n.run_id || !n.flow_slug || !n.status)
881
+ if (!i.run_id || !i.flow_slug || !i.status)
877
882
  throw new Error("Invalid run data: missing required fields");
878
- if (!Object.values(c).includes(n.status))
879
- throw new Error(`Invalid run data: invalid status '${n.status}'`);
880
- const p = {
881
- run_id: n.run_id,
882
- flow_slug: n.flow_slug,
883
- status: n.status,
884
- input: n.input,
883
+ if (!Object.values(p).includes(i.status))
884
+ throw new Error(`Invalid run data: invalid status '${i.status}'`);
885
+ const c = {
886
+ run_id: i.run_id,
887
+ flow_slug: i.flow_slug,
888
+ status: i.status,
889
+ input: i.input,
885
890
  output: null,
886
891
  error: null,
887
892
  error_message: null,
@@ -889,35 +894,35 @@ class mt {
889
894
  completed_at: null,
890
895
  failed_at: null,
891
896
  remaining_steps: 0
892
- }, u = new Q(p);
893
- if (u.applySnapshot(n), e(this, y).set(t, u), await e(this, g).subscribeToRun(t), i && Array.isArray(i))
894
- for (const l of i) {
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) {
895
900
  if (!l.step_slug || !l.status)
896
901
  throw new Error("Invalid step data: missing required fields");
897
902
  u.step(l.step_slug).applySnapshot(l);
898
903
  }
899
904
  return u;
900
- } catch (n) {
901
- if (console.error("Error getting run:", n), n instanceof Error && (n.message.includes("Invalid run data") || n.message.includes("Invalid step data")))
902
- throw n;
905
+ } catch (i) {
906
+ if (console.error("Error getting run:", i), i instanceof Error && (i.message.includes("Invalid run data") || i.message.includes("Invalid step data")))
907
+ throw i;
903
908
  return null;
904
909
  }
905
910
  }
906
911
  }
907
- q = new WeakMap(), g = new WeakMap(), y = new WeakMap();
912
+ z = new WeakMap(), w = new WeakMap(), y = new WeakMap();
908
913
  export {
909
- Q as FlowRun,
910
- c as FlowRunStatus,
911
- rt as FlowStep,
914
+ V as FlowRun,
915
+ p as FlowRunStatus,
916
+ it as FlowStep,
912
917
  h as FlowStepStatus,
913
- mt as PgflowClient,
914
- ct as isFlowRunCompletedEvent,
915
- lt as isFlowRunEvent,
916
- pt as isFlowRunFailedEvent,
917
- dt as isFlowRunStartedEvent,
918
- ft as isStepCompletedEvent,
919
- K as isStepEvent,
920
- _t as isStepFailedEvent,
921
- ht as isStepStartedEvent
918
+ gt as PgflowClient,
919
+ pt as isFlowRunCompletedEvent,
920
+ dt as isFlowRunEvent,
921
+ ht as isFlowRunFailedEvent,
922
+ ct as isFlowRunStartedEvent,
923
+ _t as isStepCompletedEvent,
924
+ N as isStepEvent,
925
+ mt as isStepFailedEvent,
926
+ ft as isStepStartedEvent
922
927
  };
923
928
  //# sourceMappingURL=index.js.map