@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.
- package/CHANGELOG.md +171 -3
- package/README.md +6 -2
- package/dist/client/src/browser.d.ts +7 -0
- package/dist/client/src/browser.d.ts.map +1 -0
- package/dist/client/src/index.d.ts +6 -0
- package/dist/client/src/index.d.ts.map +1 -0
- package/dist/client/src/lib/FlowRun.d.ts +125 -0
- package/dist/client/src/lib/FlowRun.d.ts.map +1 -0
- package/dist/client/src/lib/FlowStep.d.ts +98 -0
- package/dist/client/src/lib/FlowStep.d.ts.map +1 -0
- package/dist/client/src/lib/PgflowClient.d.ts +76 -0
- package/dist/client/src/lib/PgflowClient.d.ts.map +1 -0
- package/dist/client/src/lib/SupabaseBroadcastAdapter.d.ts +66 -0
- package/dist/client/src/lib/SupabaseBroadcastAdapter.d.ts.map +1 -0
- package/dist/client/src/lib/eventAdapters.d.ts +21 -0
- package/dist/client/src/lib/eventAdapters.d.ts.map +1 -0
- package/dist/client/src/lib/types.d.ts +337 -0
- package/dist/client/src/lib/types.d.ts.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +455 -454
- package/dist/index.js.map +1 -1
- package/dist/package.json +8 -3
- package/dist/pgflow-client.browser.js +1 -1
- package/dist/pgflow-client.browser.js.map +1 -1
- package/dist/src/browser.d.ts +3 -3
- package/dist/src/browser.d.ts.map +1 -1
- package/dist/src/browser.js +10 -0
- package/dist/src/index.js +7 -0
- package/dist/src/lib/FlowRun.d.ts +11 -3
- package/dist/src/lib/FlowRun.d.ts.map +1 -1
- package/dist/src/lib/FlowRun.js +372 -0
- package/dist/src/lib/FlowStep.d.ts +20 -4
- package/dist/src/lib/FlowStep.d.ts.map +1 -1
- package/dist/src/lib/FlowStep.js +284 -0
- package/dist/src/lib/PgflowClient.d.ts +12 -10
- package/dist/src/lib/PgflowClient.d.ts.map +1 -1
- package/dist/src/lib/PgflowClient.js +227 -0
- package/dist/src/lib/SupabaseBroadcastAdapter.d.ts +4 -4
- package/dist/src/lib/SupabaseBroadcastAdapter.d.ts.map +1 -1
- package/dist/src/lib/SupabaseBroadcastAdapter.js +332 -0
- package/dist/src/lib/eventAdapters.d.ts +3 -4
- package/dist/src/lib/eventAdapters.d.ts.map +1 -1
- package/dist/src/lib/eventAdapters.js +160 -0
- package/dist/src/lib/types.d.ts +34 -6
- package/dist/src/lib/types.d.ts.map +1 -1
- package/dist/src/lib/types.js +102 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -0
- package/package.json +10 -5
package/dist/index.js
CHANGED
|
@@ -1,61 +1,65 @@
|
|
|
1
|
-
var
|
|
2
|
-
throw TypeError(
|
|
1
|
+
var Q = (s) => {
|
|
2
|
+
throw TypeError(s);
|
|
3
3
|
};
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
set _(
|
|
8
|
-
|
|
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
|
|
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
|
|
17
|
-
function
|
|
18
|
-
return !!
|
|
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
|
|
21
|
-
return
|
|
20
|
+
function dt(s) {
|
|
21
|
+
return s.status === "started";
|
|
22
22
|
}
|
|
23
|
-
function
|
|
24
|
-
return
|
|
23
|
+
function ct(s) {
|
|
24
|
+
return s.status === "completed";
|
|
25
25
|
}
|
|
26
|
-
function
|
|
27
|
-
return
|
|
26
|
+
function ht(s) {
|
|
27
|
+
return s.status === "failed";
|
|
28
28
|
}
|
|
29
|
-
var
|
|
30
|
-
function
|
|
31
|
-
return !!
|
|
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
|
|
34
|
-
return
|
|
33
|
+
function _t(s) {
|
|
34
|
+
return O(s) && s.status === "started" && "event_type" in s && s.event_type === "step:started";
|
|
35
35
|
}
|
|
36
|
-
function
|
|
37
|
-
return
|
|
36
|
+
function ft(s) {
|
|
37
|
+
return O(s) && s.status === "completed" && "event_type" in s && s.event_type === "step:completed";
|
|
38
38
|
}
|
|
39
|
-
function
|
|
40
|
-
return
|
|
39
|
+
function mt(s) {
|
|
40
|
+
return O(s) && s.status === "failed" && "event_type" in s && s.event_type === "step:failed";
|
|
41
41
|
}
|
|
42
|
-
|
|
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,
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
|
|
58
|
-
|
|
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 [
|
|
67
|
-
|
|
68
|
-
|
|
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 (
|
|
71
|
-
if (!
|
|
72
|
-
if (
|
|
73
|
-
const
|
|
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:
|
|
76
|
-
steps:
|
|
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
|
|
90
|
+
const r = e(this, C).on("runEvent", t);
|
|
87
91
|
return () => {
|
|
88
92
|
try {
|
|
89
|
-
|
|
90
|
-
} catch (
|
|
91
|
-
console.warn("Could not unsubscribe from run event - emitter may have been disposed",
|
|
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
|
|
106
|
+
const r = e(this, C).on("stepEvent", t);
|
|
103
107
|
return () => {
|
|
104
108
|
try {
|
|
105
|
-
|
|
106
|
-
} catch (
|
|
107
|
-
console.warn("Could not unsubscribe from step event - emitter may have been disposed",
|
|
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
|
|
119
|
-
if (
|
|
120
|
-
const
|
|
121
|
-
if (
|
|
122
|
-
return
|
|
123
|
-
|
|
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
|
|
126
|
-
|
|
127
|
-
console.log(`Channel ${
|
|
128
|
-
}),
|
|
129
|
-
console.log(`Channel ${
|
|
130
|
-
}), console.log(`Subscribing to channel ${
|
|
131
|
-
const
|
|
132
|
-
|
|
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
|
-
|
|
135
|
-
console.log(`Channel ${
|
|
138
|
+
i.subscribe((b) => {
|
|
139
|
+
console.log(`Channel ${r} subscription status:`, b), b === "SUBSCRIBED" && (clearTimeout(p), c());
|
|
136
140
|
});
|
|
137
|
-
}),
|
|
138
|
-
const
|
|
139
|
-
return
|
|
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
|
-
|
|
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:
|
|
156
|
-
if (
|
|
157
|
-
if (!
|
|
158
|
-
return
|
|
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
|
-
|
|
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
|
-
|
|
166
|
-
const { event:
|
|
167
|
-
|
|
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
|
-
},
|
|
184
|
-
console.error(`Channel ${
|
|
185
|
-
|
|
186
|
-
},
|
|
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,
|
|
194
|
-
const
|
|
195
|
-
return
|
|
196
|
-
}, Z = async function(t,
|
|
197
|
-
console.log(`Attempting to reconnect to ${
|
|
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
|
|
200
|
-
|
|
201
|
-
const
|
|
202
|
-
|
|
203
|
-
console.log(`Reconnected and subscribed to channel ${
|
|
204
|
-
}),
|
|
205
|
-
console.log(`Reconnected channel ${
|
|
206
|
-
}),
|
|
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
|
-
(
|
|
210
|
-
),
|
|
211
|
-
} catch (
|
|
212
|
-
console.error(`Failed to reconnect to ${
|
|
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,
|
|
220
|
-
if (!
|
|
221
|
-
const
|
|
222
|
-
event_type: `run:${
|
|
223
|
-
...
|
|
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 (
|
|
226
|
-
for (const
|
|
227
|
-
const
|
|
228
|
-
event_type: `step:${
|
|
229
|
-
...
|
|
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
|
-
|
|
235
|
+
e(this, C).emit("stepEvent", g);
|
|
232
236
|
}
|
|
233
|
-
},
|
|
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
|
-
|
|
239
|
-
const
|
|
240
|
-
|
|
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
|
|
243
|
-
class
|
|
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
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
[
|
|
255
|
-
[
|
|
256
|
-
[
|
|
257
|
-
[
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
318
|
+
return e(this, a).output;
|
|
302
319
|
}
|
|
303
320
|
/**
|
|
304
321
|
* Get the error object
|
|
305
322
|
*/
|
|
306
323
|
get error() {
|
|
307
|
-
return
|
|
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
|
|
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,
|
|
323
|
-
return
|
|
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,
|
|
333
|
-
const
|
|
334
|
-
return this.status === t ? Promise.resolve(this) : new Promise((
|
|
335
|
-
let
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
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
|
-
|
|
345
|
-
|
|
369
|
+
n.addEventListener("abort", S), b = () => {
|
|
370
|
+
n.removeEventListener("abort", S);
|
|
346
371
|
};
|
|
347
372
|
}
|
|
348
|
-
const
|
|
349
|
-
if (
|
|
350
|
-
if (
|
|
351
|
-
|
|
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 !==
|
|
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
|
|
371
|
-
|
|
372
|
-
...
|
|
373
|
-
status:
|
|
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
|
-
}),
|
|
410
|
+
}), e(this, F).emit("started", t);
|
|
376
411
|
break;
|
|
377
|
-
case
|
|
378
|
-
|
|
379
|
-
...
|
|
380
|
-
status:
|
|
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
|
-
}),
|
|
418
|
+
}), e(this, F).emit("completed", t);
|
|
384
419
|
break;
|
|
385
|
-
case
|
|
386
|
-
|
|
387
|
-
...
|
|
388
|
-
status:
|
|
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(
|
|
392
|
-
|
|
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
|
|
442
|
+
return e(this, F).emit("*", t), !0;
|
|
398
443
|
}
|
|
399
444
|
}
|
|
400
|
-
|
|
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,
|
|
408
|
-
if (t ===
|
|
452
|
+
tt = function(t, r) {
|
|
453
|
+
if (t === u.Completed || t === u.Failed || t === u.Skipped)
|
|
409
454
|
return !1;
|
|
410
|
-
const
|
|
411
|
-
return
|
|
455
|
+
const i = e(this, x)[t];
|
|
456
|
+
return e(this, x)[r] > i;
|
|
412
457
|
};
|
|
413
|
-
var o,
|
|
414
|
-
class
|
|
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
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
[
|
|
427
|
-
[
|
|
428
|
-
[
|
|
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
|
-
|
|
475
|
+
d(this, U, !1);
|
|
431
476
|
// Track number of listeners
|
|
432
|
-
|
|
433
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
520
|
+
return e(this, o).input;
|
|
476
521
|
}
|
|
477
522
|
/**
|
|
478
523
|
* Get the flow output
|
|
479
524
|
*/
|
|
480
525
|
get output() {
|
|
481
|
-
return
|
|
526
|
+
return e(this, o).output;
|
|
482
527
|
}
|
|
483
528
|
/**
|
|
484
529
|
* Get the error object
|
|
485
530
|
*/
|
|
486
531
|
get error() {
|
|
487
|
-
return
|
|
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
|
|
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
|
|
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,
|
|
509
|
-
|
|
510
|
-
const
|
|
553
|
+
on(t, r) {
|
|
554
|
+
j(this, P)._++;
|
|
555
|
+
const i = e(this, D).on(t, r);
|
|
511
556
|
return () => {
|
|
512
|
-
|
|
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
|
|
523
|
-
if (
|
|
524
|
-
return
|
|
525
|
-
const
|
|
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:
|
|
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
|
|
583
|
+
return e(this, T).set(
|
|
537
584
|
t,
|
|
538
|
-
|
|
539
|
-
),
|
|
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
|
|
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,
|
|
558
|
-
const
|
|
559
|
-
return this.status === t ? Promise.resolve(this) : new Promise((
|
|
560
|
-
let
|
|
561
|
-
|
|
562
|
-
|
|
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
|
-
},
|
|
568
|
-
let
|
|
569
|
-
if (
|
|
570
|
-
const
|
|
571
|
-
|
|
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
|
-
|
|
578
|
-
|
|
624
|
+
n.addEventListener("abort", S), b = () => {
|
|
625
|
+
n.removeEventListener("abort", S);
|
|
579
626
|
};
|
|
580
627
|
}
|
|
581
|
-
const
|
|
582
|
-
if (
|
|
583
|
-
if (
|
|
584
|
-
|
|
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 !==
|
|
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
|
|
604
|
-
|
|
605
|
-
...
|
|
606
|
-
status:
|
|
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) :
|
|
609
|
-
}),
|
|
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
|
|
612
|
-
|
|
613
|
-
...
|
|
614
|
-
status:
|
|
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
|
-
}),
|
|
675
|
+
}), e(this, D).emit("completed", t), m(this, R, B).call(this);
|
|
619
676
|
break;
|
|
620
|
-
case
|
|
621
|
-
|
|
622
|
-
...
|
|
623
|
-
status:
|
|
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
|
-
}),
|
|
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
|
|
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,
|
|
644
|
-
return this.step(t).updateState(
|
|
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
|
-
|
|
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(),
|
|
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
|
-
|
|
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,
|
|
666
|
-
if (t ===
|
|
722
|
+
et = function(t, r) {
|
|
723
|
+
if (t === h.Completed || t === h.Failed)
|
|
667
724
|
return !1;
|
|
668
|
-
const
|
|
669
|
-
return
|
|
725
|
+
const i = e(this, q)[t];
|
|
726
|
+
return e(this, q)[r] > i;
|
|
670
727
|
};
|
|
671
|
-
function
|
|
672
|
-
switch (
|
|
673
|
-
case
|
|
728
|
+
function nt(s) {
|
|
729
|
+
switch (s.status) {
|
|
730
|
+
case h.Started:
|
|
674
731
|
return {
|
|
675
732
|
event_type: "run:started",
|
|
676
|
-
run_id:
|
|
677
|
-
flow_slug:
|
|
678
|
-
status:
|
|
679
|
-
started_at:
|
|
680
|
-
remaining_steps:
|
|
681
|
-
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
|
|
740
|
+
case h.Completed:
|
|
684
741
|
return {
|
|
685
742
|
event_type: "run:completed",
|
|
686
|
-
run_id:
|
|
687
|
-
flow_slug:
|
|
688
|
-
status:
|
|
689
|
-
completed_at:
|
|
690
|
-
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
|
|
749
|
+
case h.Failed:
|
|
693
750
|
return {
|
|
694
751
|
event_type: "run:failed",
|
|
695
|
-
run_id:
|
|
696
|
-
flow_slug:
|
|
697
|
-
status:
|
|
698
|
-
failed_at:
|
|
699
|
-
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(
|
|
704
|
-
switch (
|
|
705
|
-
case
|
|
760
|
+
function at(s) {
|
|
761
|
+
switch (s.status) {
|
|
762
|
+
case u.Started:
|
|
706
763
|
return {
|
|
707
764
|
event_type: "step:started",
|
|
708
|
-
run_id:
|
|
709
|
-
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:
|
|
742
|
-
remaining_steps: e.remaining_steps,
|
|
743
|
-
input: e.input
|
|
768
|
+
started_at: s.started_at
|
|
744
769
|
};
|
|
745
|
-
case
|
|
770
|
+
case u.Completed:
|
|
746
771
|
return {
|
|
747
|
-
event_type: "
|
|
748
|
-
run_id:
|
|
749
|
-
|
|
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:
|
|
752
|
-
output:
|
|
776
|
+
completed_at: s.completed_at,
|
|
777
|
+
output: s.output
|
|
753
778
|
};
|
|
754
|
-
case
|
|
779
|
+
case u.Failed:
|
|
755
780
|
return {
|
|
756
|
-
event_type: "
|
|
757
|
-
run_id:
|
|
758
|
-
|
|
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:
|
|
761
|
-
error_message:
|
|
762
|
-
// Database doesn't have error_message for runs
|
|
785
|
+
failed_at: s.failed_at,
|
|
786
|
+
error_message: s.error_message
|
|
763
787
|
};
|
|
764
|
-
|
|
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:
|
|
774
|
-
run_id:
|
|
775
|
-
step_slug:
|
|
776
|
-
status:
|
|
777
|
-
|
|
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
|
|
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
|
-
|
|
811
|
-
|
|
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
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
}),
|
|
819
|
-
const n =
|
|
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
|
|
822
|
-
n.step(
|
|
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,
|
|
835
|
-
const
|
|
836
|
-
run_id:
|
|
835
|
+
async startFlow(t, r, i) {
|
|
836
|
+
const n = i || st(), g = {
|
|
837
|
+
run_id: n,
|
|
837
838
|
flow_slug: t,
|
|
838
|
-
status:
|
|
839
|
-
input:
|
|
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
|
-
},
|
|
849
|
-
|
|
850
|
-
const { data:
|
|
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:
|
|
853
|
-
run_id:
|
|
853
|
+
input: r,
|
|
854
|
+
run_id: n
|
|
854
855
|
});
|
|
855
|
-
if (
|
|
856
|
-
throw this.dispose(
|
|
857
|
-
if (
|
|
858
|
-
for (const
|
|
859
|
-
|
|
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
|
|
869
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
919
|
-
if (
|
|
920
|
-
return
|
|
919
|
+
const r = e(this, y).get(t);
|
|
920
|
+
if (r)
|
|
921
|
+
return r;
|
|
921
922
|
try {
|
|
922
|
-
const { run:
|
|
923
|
-
if (!
|
|
923
|
+
const { run: i, steps: n } = await this.getRunWithStates(t);
|
|
924
|
+
if (!i)
|
|
924
925
|
return null;
|
|
925
|
-
|
|
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(
|
|
929
|
-
throw new Error(`Invalid run data: invalid status '${
|
|
930
|
-
const
|
|
931
|
-
run_id:
|
|
932
|
-
flow_slug:
|
|
933
|
-
status:
|
|
934
|
-
input:
|
|
935
|
-
output:
|
|
936
|
-
error:
|
|
937
|
-
error_message:
|
|
938
|
-
started_at:
|
|
939
|
-
completed_at:
|
|
940
|
-
failed_at:
|
|
941
|
-
remaining_steps:
|
|
942
|
-
},
|
|
943
|
-
if (
|
|
944
|
-
for (const
|
|
945
|
-
if (!
|
|
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
|
-
|
|
947
|
+
l.step(p.step_slug).applySnapshot(p);
|
|
948
948
|
}
|
|
949
|
-
return
|
|
950
|
-
} catch (
|
|
951
|
-
if (console.error("Error getting run:",
|
|
952
|
-
throw
|
|
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
|
-
|
|
957
|
+
z = new WeakMap(), w = new WeakMap(), y = new WeakMap();
|
|
958
958
|
export {
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
959
|
+
V as FlowRun,
|
|
960
|
+
h as FlowRunStatus,
|
|
961
|
+
it as FlowStep,
|
|
962
|
+
u as FlowStepStatus,
|
|
963
963
|
wt as PgflowClient,
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
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
|