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