@voltro/client 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +52 -0
- package/LICENSE +57 -0
- package/README.md +26 -0
- package/SECURITY.md +56 -0
- package/THIRD-PARTY-NOTICES.md +347 -0
- package/dist/index.d.ts +1882 -0
- package/dist/index.js +2037 -0
- package/package.json +44 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,2037 @@
|
|
|
1
|
+
import { createContext as e, createElement as t, useCallback as n, useContext as r, useEffect as i, useMemo as a, useRef as o, useState as s, useSyncExternalStore as c } from "react";
|
|
2
|
+
import { Cause as l, Duration as u, Effect as d, Exit as f, Fiber as p, JSONSchema as m, Schema as h, Stream as g } from "effect";
|
|
3
|
+
import { applyRowPatch as _ } from "@voltro/protocol";
|
|
4
|
+
import { jsx as v } from "react/jsx-runtime";
|
|
5
|
+
import { ArrayFormatter as y } from "effect/ParseResult";
|
|
6
|
+
//#region src/traceBus.ts
|
|
7
|
+
var b = /* @__PURE__ */ new Set(), x = (e) => {
|
|
8
|
+
for (let t of b) try {
|
|
9
|
+
t(e);
|
|
10
|
+
} catch {}
|
|
11
|
+
}, S = (e) => (b.add(e), () => {
|
|
12
|
+
b.delete(e);
|
|
13
|
+
}), C = (e) => {
|
|
14
|
+
let t = (e) => e == null ? "null" : typeof e == "string" ? JSON.stringify(e) : typeof e == "number" || typeof e == "boolean" ? String(e) : Array.isArray(e) ? `[${e.map(t).join(",")}]` : typeof e == "object" ? `{${Object.keys(e).sort().map((n) => `${JSON.stringify(n)}:${t(e[n])}`).join(",")}}` : String(e);
|
|
15
|
+
return t(e);
|
|
16
|
+
}, w = Object.freeze({
|
|
17
|
+
data: void 0,
|
|
18
|
+
revision: -1,
|
|
19
|
+
emittedAt: void 0,
|
|
20
|
+
error: void 0,
|
|
21
|
+
pendingPatches: 0
|
|
22
|
+
}), T = 5e3, E = 0, ee = () => `patch_${++E}`, te = (e, t, n) => {
|
|
23
|
+
switch (e.op) {
|
|
24
|
+
case "insert": {
|
|
25
|
+
let r = e.shape ? {
|
|
26
|
+
id: n,
|
|
27
|
+
...e.shape(t, n),
|
|
28
|
+
optimistic: !0
|
|
29
|
+
} : {
|
|
30
|
+
id: n,
|
|
31
|
+
...t,
|
|
32
|
+
optimistic: !0
|
|
33
|
+
}, i = e.order ?? "prepend";
|
|
34
|
+
return (e) => {
|
|
35
|
+
let t = Array.isArray(e) ? e : [];
|
|
36
|
+
return i === "append" ? [...t, r] : [r, ...t];
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
case "update": {
|
|
40
|
+
let n = e.identify ? e.identify(t) : typeof t.id == "string" ? t.id : void 0;
|
|
41
|
+
if (n === void 0) return null;
|
|
42
|
+
let r = e.shape, i = r ? (e) => ({
|
|
43
|
+
...r(t, e),
|
|
44
|
+
id: n,
|
|
45
|
+
optimistic: !0
|
|
46
|
+
}) : (e) => ({
|
|
47
|
+
...e,
|
|
48
|
+
...t,
|
|
49
|
+
optimistic: !0
|
|
50
|
+
});
|
|
51
|
+
return (e) => (Array.isArray(e) ? e : []).map((e) => {
|
|
52
|
+
let t = e;
|
|
53
|
+
return t.id === n ? i(t) : t;
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
case "delete": {
|
|
57
|
+
let n = e.identify ? e.identify(t) : typeof t.id == "string" ? t.id : void 0;
|
|
58
|
+
return n === void 0 ? null : (e) => (Array.isArray(e) ? e : []).filter((e) => e.id !== n);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}, ne = 5e3, re = class {
|
|
62
|
+
entries = /* @__PURE__ */ new Map();
|
|
63
|
+
inactiveTtlMs;
|
|
64
|
+
onChangeHook;
|
|
65
|
+
errorBus;
|
|
66
|
+
constructor(e = {}) {
|
|
67
|
+
this.inactiveTtlMs = e.inactiveTtlMs ?? ne, this.onChangeHook = e.onChange, this.errorBus = e.errorBus;
|
|
68
|
+
}
|
|
69
|
+
subscribe(e, t, n, r, i = {}) {
|
|
70
|
+
let a = C(e), o = typeof e[0] == "string" ? e[0] : void 0, s = this.entries.get(a);
|
|
71
|
+
return s && s.evictionTimer !== null && (clearTimeout(s.evictionTimer), s.evictionTimer = null), s ? (s.fiber === null && (s.fetch = t, this.startFiber(s, t, n)), s.source === void 0 && i.source !== void 0 && (s.source = i.source)) : s = this.create(a, o, t, n, i.source), s.subscribers.add(r), {
|
|
72
|
+
getSnapshot: () => this.getSnapshot(a),
|
|
73
|
+
unsubscribe: () => this.unsubscribe(a, r)
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
update(e, t, n) {
|
|
77
|
+
let r = C(e), i = typeof e[0] == "string" ? e[0] : void 0, a = this.entries.get(r);
|
|
78
|
+
a ||= this.createStub(r, i);
|
|
79
|
+
let o = {
|
|
80
|
+
id: ee(),
|
|
81
|
+
mutationId: n,
|
|
82
|
+
reducer: t
|
|
83
|
+
};
|
|
84
|
+
return a.state.patches.push(o), this.invalidate(a), {
|
|
85
|
+
patchId: o.id,
|
|
86
|
+
revert: () => this.revertPatch(r, o.id)
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
forTag(e, t, n) {
|
|
90
|
+
let r = 0;
|
|
91
|
+
for (let i of this.entries.values()) {
|
|
92
|
+
if (i.tag !== e) continue;
|
|
93
|
+
let a = {
|
|
94
|
+
id: `forTag-${++E}`,
|
|
95
|
+
mutationId: n,
|
|
96
|
+
reducer: t
|
|
97
|
+
};
|
|
98
|
+
i.state.patches.push(a), this.invalidate(i), r++;
|
|
99
|
+
}
|
|
100
|
+
return { patchedCount: r };
|
|
101
|
+
}
|
|
102
|
+
revertByMutation(e) {
|
|
103
|
+
for (let t of this.entries.values()) {
|
|
104
|
+
let n = t.state.patches.length;
|
|
105
|
+
t.state.patches = t.state.patches.filter((t) => t.mutationId !== e), t.state.patches.length !== n && this.invalidate(t);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
confirmByMutation(e) {
|
|
109
|
+
let t = !1;
|
|
110
|
+
for (let n of this.entries.values()) for (let r of n.state.patches) r.mutationId === e && r.confirmed !== !0 && (r.confirmed = !0, t = !0);
|
|
111
|
+
t && setTimeout(() => this.revertByMutation(e), T);
|
|
112
|
+
}
|
|
113
|
+
autoApply(e, t, n) {
|
|
114
|
+
let r = `optimistic-${n}-${++E}`;
|
|
115
|
+
for (let i of e) for (let e of this.entries.values()) {
|
|
116
|
+
if (!(Array.isArray(e.source) ? e.source.includes(i.table) : e.source === i.table) || e.computed && i.op === "insert") continue;
|
|
117
|
+
let a = te(i, t, r);
|
|
118
|
+
if (a === null) continue;
|
|
119
|
+
let o = {
|
|
120
|
+
id: `${r}-${e.key}`,
|
|
121
|
+
mutationId: n,
|
|
122
|
+
reducer: a
|
|
123
|
+
};
|
|
124
|
+
e.state.patches.push(o), this.invalidate(e);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
revertPatch(e, t) {
|
|
128
|
+
let n = this.entries.get(e);
|
|
129
|
+
if (!n) return;
|
|
130
|
+
let r = n.state.patches.length;
|
|
131
|
+
n.state.patches = n.state.patches.filter((e) => e.id !== t), n.state.patches.length !== r && this.invalidate(n);
|
|
132
|
+
}
|
|
133
|
+
peek(e) {
|
|
134
|
+
return this.getSnapshot(C(e));
|
|
135
|
+
}
|
|
136
|
+
getEntry(e) {
|
|
137
|
+
return this.entries.get(C(e));
|
|
138
|
+
}
|
|
139
|
+
size() {
|
|
140
|
+
return this.entries.size;
|
|
141
|
+
}
|
|
142
|
+
peekAll() {
|
|
143
|
+
let e = [];
|
|
144
|
+
for (let t of this.entries.values()) e.push({
|
|
145
|
+
key: t.key,
|
|
146
|
+
tag: t.tag,
|
|
147
|
+
source: t.source,
|
|
148
|
+
subscriberCount: t.subscribers.size,
|
|
149
|
+
hasFiber: t.fiber !== null,
|
|
150
|
+
evicting: t.evictionTimer !== null,
|
|
151
|
+
snapshot: this.getSnapshot(t.key)
|
|
152
|
+
});
|
|
153
|
+
return e;
|
|
154
|
+
}
|
|
155
|
+
destroy(e) {
|
|
156
|
+
for (let t of this.entries.values()) t.evictionTimer !== null && clearTimeout(t.evictionTimer), t.fiber && e.runFork(p.interrupt(t.fiber));
|
|
157
|
+
this.entries.clear();
|
|
158
|
+
}
|
|
159
|
+
refreshAll(e) {
|
|
160
|
+
for (let t of this.entries.values()) {
|
|
161
|
+
if (!t.fetch) continue;
|
|
162
|
+
t.fiber && e.runFork(p.interrupt(t.fiber)), t.fiber = null;
|
|
163
|
+
let n = t.state.patches;
|
|
164
|
+
t.state = this.freshState(), t.state.patches = n, this.startFiber(t, t.fetch, e);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
create(e, t, n, r, i) {
|
|
168
|
+
let a = {
|
|
169
|
+
key: e,
|
|
170
|
+
tag: t,
|
|
171
|
+
state: this.freshState(),
|
|
172
|
+
subscribers: /* @__PURE__ */ new Set(),
|
|
173
|
+
fiber: null,
|
|
174
|
+
evictionTimer: null,
|
|
175
|
+
source: i,
|
|
176
|
+
computed: !1,
|
|
177
|
+
fetch: n
|
|
178
|
+
};
|
|
179
|
+
return this.entries.set(e, a), this.startFiber(a, n, r), a;
|
|
180
|
+
}
|
|
181
|
+
createStub(e, t) {
|
|
182
|
+
let n = {
|
|
183
|
+
key: e,
|
|
184
|
+
tag: t,
|
|
185
|
+
state: this.freshState(),
|
|
186
|
+
subscribers: /* @__PURE__ */ new Set(),
|
|
187
|
+
fiber: null,
|
|
188
|
+
evictionTimer: null,
|
|
189
|
+
source: void 0,
|
|
190
|
+
computed: !1,
|
|
191
|
+
fetch: null
|
|
192
|
+
};
|
|
193
|
+
return this.entries.set(e, n), n;
|
|
194
|
+
}
|
|
195
|
+
freshState() {
|
|
196
|
+
return {
|
|
197
|
+
base: void 0,
|
|
198
|
+
baseRevision: -1,
|
|
199
|
+
baseEmittedAt: void 0,
|
|
200
|
+
baseError: void 0,
|
|
201
|
+
patches: [],
|
|
202
|
+
cachedSnapshot: null
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
startFiber(e, t, n) {
|
|
206
|
+
let r = e.tag ?? e.key, i = t(), a = g.unwrapScoped(d.currentSpan.pipe(d.catchAll(() => d.succeed(void 0)), d.map((t) => (t && (e.traceId = t.traceId, x({
|
|
207
|
+
traceId: t.traceId,
|
|
208
|
+
spanId: t.spanId,
|
|
209
|
+
source: "subscription",
|
|
210
|
+
tag: r
|
|
211
|
+
})), i)))).pipe(g.withSpan(`client.subscription.${r}`, { attributes: { "rpc.tag": r } }));
|
|
212
|
+
e.fiber = n.runFork(a.pipe(g.runForEach((t) => d.sync(() => {
|
|
213
|
+
if (t._tag === "snapshot") e.state.base = t.data, e.state.baseRevision = t.revision, e.state.baseEmittedAt = void 0, e.state.baseError = void 0, t.computed === !0 && (e.computed = !0);
|
|
214
|
+
else if (t._tag === "error") e.state.baseError = l.fail(t.error), typeof t.revision == "number" && (e.state.baseRevision = t.revision);
|
|
215
|
+
else {
|
|
216
|
+
let n = e.state.base;
|
|
217
|
+
Array.isArray(n) && (e.state.base = _(n, t.patch)), e.state.baseRevision = t.revision, e.state.baseEmittedAt = t.emittedAt, e.state.baseError = void 0;
|
|
218
|
+
}
|
|
219
|
+
e.state.patches.some((e) => e.confirmed === !0) && (e.state.patches = e.state.patches.filter((e) => e.confirmed !== !0)), this.invalidate(e);
|
|
220
|
+
})))), e.fiber.addObserver((t) => {
|
|
221
|
+
if (f.isFailure(t) && !f.isInterrupted(t) && (e.state.baseRevision === -1 && (e.state.baseError = t.cause, this.invalidate(e)), this.errorBus)) {
|
|
222
|
+
let n = l.squash(t.cause);
|
|
223
|
+
this.errorBus.emit({
|
|
224
|
+
source: "subscription",
|
|
225
|
+
tag: e.tag ?? e.key,
|
|
226
|
+
error: n,
|
|
227
|
+
...e.traceId === void 0 ? {} : { traceId: e.traceId }
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
invalidate(e) {
|
|
233
|
+
e.state.cachedSnapshot = null;
|
|
234
|
+
for (let t of e.subscribers) t();
|
|
235
|
+
this.onChangeHook?.(e.key);
|
|
236
|
+
}
|
|
237
|
+
getSnapshot(e) {
|
|
238
|
+
let t = this.entries.get(e);
|
|
239
|
+
if (!t) return w;
|
|
240
|
+
if (t.state.cachedSnapshot !== null) return t.state.cachedSnapshot;
|
|
241
|
+
let n = t.state.base;
|
|
242
|
+
if (n !== void 0 && t.state.patches.length > 0) for (let e of t.state.patches) n = e.reducer(n);
|
|
243
|
+
let r = {
|
|
244
|
+
data: n,
|
|
245
|
+
revision: t.state.baseRevision,
|
|
246
|
+
emittedAt: t.state.baseEmittedAt,
|
|
247
|
+
error: t.state.baseError,
|
|
248
|
+
pendingPatches: t.state.patches.length
|
|
249
|
+
};
|
|
250
|
+
return t.state.cachedSnapshot = r, r;
|
|
251
|
+
}
|
|
252
|
+
unsubscribe(e, t) {
|
|
253
|
+
let n = this.entries.get(e);
|
|
254
|
+
n && (n.subscribers.delete(t), !(n.subscribers.size > 0) && (n.evictionTimer !== null && clearTimeout(n.evictionTimer), n.evictionTimer = setTimeout(() => {
|
|
255
|
+
let t = this.entries.get(e);
|
|
256
|
+
t && t.subscribers.size === 0 && (t.fiber && d.runFork(p.interrupt(t.fiber)), this.entries.delete(e));
|
|
257
|
+
}, this.inactiveTtlMs)));
|
|
258
|
+
}
|
|
259
|
+
}, ie = class extends re {
|
|
260
|
+
subscribe(e, t, n, r, i = {}) {
|
|
261
|
+
return {
|
|
262
|
+
getSnapshot: () => this.peek(e),
|
|
263
|
+
unsubscribe: () => {}
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
}, ae = class {
|
|
267
|
+
#e = /* @__PURE__ */ new Set();
|
|
268
|
+
on(e) {
|
|
269
|
+
return this.#e.add(e), () => {
|
|
270
|
+
this.#e.delete(e);
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
emit(e) {
|
|
274
|
+
for (let t of this.#e) try {
|
|
275
|
+
t(e);
|
|
276
|
+
} catch {}
|
|
277
|
+
}
|
|
278
|
+
}, oe = (e) => {
|
|
279
|
+
if (typeof e != "object" || !e) return;
|
|
280
|
+
let t = e._tag;
|
|
281
|
+
return typeof t == "string" ? t : void 0;
|
|
282
|
+
}, D = e(null), se = () => {
|
|
283
|
+
throw Error("Voltro: rpc / cache calls are not invokable on a not-yet-resolved api — either during SSR, or in the client boot window before the api client resolves");
|
|
284
|
+
}, O = new Proxy(() => se(), {
|
|
285
|
+
get: (e, t) => O,
|
|
286
|
+
has: () => !0,
|
|
287
|
+
apply: () => se()
|
|
288
|
+
}), ce = {
|
|
289
|
+
runtime: { runPromise: () => Promise.reject(/* @__PURE__ */ Error("Voltro: mutations are not invokable during SSR")) },
|
|
290
|
+
cache: new ie(),
|
|
291
|
+
client: O,
|
|
292
|
+
descriptors: {},
|
|
293
|
+
inspectBaseUrl: "",
|
|
294
|
+
errorBus: new ae()
|
|
295
|
+
}, le = {
|
|
296
|
+
get: () => ce,
|
|
297
|
+
names: []
|
|
298
|
+
}, k = !1, A = !1, j = null, ue = () => {
|
|
299
|
+
k = !1, A = !1, j !== null && (clearTimeout(j), j = null);
|
|
300
|
+
}, de = () => {
|
|
301
|
+
let e = r(D);
|
|
302
|
+
return e ? (A || (A = !0, j !== null && (clearTimeout(j), j = null)), e) : (typeof window < "u" && !k && !A && j === null && process.env.NODE_ENV !== "production" && (j = setTimeout(() => {
|
|
303
|
+
j = null, !(k || A) && (k = !0, console.warn("useFrameworkRuntimes: no <FrameworkRuntimesProvider> in the tree — returning a loading baseline (subscriptions read `undefined`, mutations are no-ops). If this is not an intentional lazy/conditional mount, mount your app via @voltro/web mount() or wrap the subtree in <VoltroRuntimeProvider>."));
|
|
304
|
+
}, 0)), le);
|
|
305
|
+
}, M = (e) => de().get(e), fe = ({ apis: e, children: t }) => {
|
|
306
|
+
let n = a(() => ({
|
|
307
|
+
get: (t) => {
|
|
308
|
+
let n = e.get(t);
|
|
309
|
+
if (!n) {
|
|
310
|
+
let n = Array.from(e.keys()).join(", ") || "(none mounted)";
|
|
311
|
+
throw Error(`@voltro/client: no api named ${JSON.stringify(t)}. Known apis: ${n}`);
|
|
312
|
+
}
|
|
313
|
+
return n;
|
|
314
|
+
},
|
|
315
|
+
names: Array.from(e.keys())
|
|
316
|
+
}), [e]);
|
|
317
|
+
return /* @__PURE__ */ v(D.Provider, {
|
|
318
|
+
value: n,
|
|
319
|
+
children: t
|
|
320
|
+
});
|
|
321
|
+
}, N = (e, t) => {
|
|
322
|
+
let n = t.split("."), r = e;
|
|
323
|
+
for (let e = 0; e < n.length; e++) {
|
|
324
|
+
let i = n[e];
|
|
325
|
+
if (r === null || typeof r != "object" && typeof r != "function") throw Error(`@voltro/client: rpc tag ${JSON.stringify(t)} not reachable on client. Stopped at segment ${JSON.stringify(i)}. The api's descriptor map is likely out of sync with the rpc group; restart \`voltro dev\` to regenerate.`);
|
|
326
|
+
let a = r;
|
|
327
|
+
if (i in a) {
|
|
328
|
+
r = a[i];
|
|
329
|
+
continue;
|
|
330
|
+
}
|
|
331
|
+
let o = n.slice(e).join(".");
|
|
332
|
+
if (o in a) {
|
|
333
|
+
r = a[o];
|
|
334
|
+
break;
|
|
335
|
+
}
|
|
336
|
+
throw Error(`@voltro/client: rpc tag ${JSON.stringify(t)} not reachable on client. Stopped at segment ${JSON.stringify(i)}. The api's descriptor map is likely out of sync with the rpc group; restart \`voltro dev\` to regenerate.`);
|
|
337
|
+
}
|
|
338
|
+
if (typeof r != "function") throw Error(`@voltro/client: rpc tag ${JSON.stringify(t)} did not resolve to a callable method.`);
|
|
339
|
+
return r;
|
|
340
|
+
}, pe = Object.freeze({
|
|
341
|
+
data: void 0,
|
|
342
|
+
revision: -1,
|
|
343
|
+
emittedAt: void 0,
|
|
344
|
+
error: void 0,
|
|
345
|
+
pendingPatches: 0
|
|
346
|
+
}), me = () => pe, P = (e, t, r = {}, i = {}) => {
|
|
347
|
+
let s = i.skip === !0, { runtime: l, cache: u, client: d, descriptors: f } = M(e), p = f[t]?.source, m = o(r);
|
|
348
|
+
m.current = r;
|
|
349
|
+
let h = o(d);
|
|
350
|
+
h.current = d;
|
|
351
|
+
let g = o(() => N(h.current, t)(m.current)), _ = a(() => [t, m.current], [t, a(() => JSON.stringify(Object.entries(r).sort(([e], [t]) => e.localeCompare(t))), [r])]), v = c(n((e) => s ? () => {} : u.subscribe(_, g.current, l, e, p === void 0 ? {} : { source: p }).unsubscribe, [
|
|
352
|
+
u,
|
|
353
|
+
l,
|
|
354
|
+
p,
|
|
355
|
+
s,
|
|
356
|
+
_
|
|
357
|
+
]), n(() => s ? pe : u.peek(_), [
|
|
358
|
+
u,
|
|
359
|
+
s,
|
|
360
|
+
_
|
|
361
|
+
]), me);
|
|
362
|
+
return {
|
|
363
|
+
data: v.data,
|
|
364
|
+
revision: v.revision,
|
|
365
|
+
emittedAt: v.emittedAt,
|
|
366
|
+
error: v.error,
|
|
367
|
+
pendingPatches: v.pendingPatches
|
|
368
|
+
};
|
|
369
|
+
}, he = 100, F = [], I = /* @__PURE__ */ new Set(), ge = [], _e = () => {
|
|
370
|
+
ge = F.slice();
|
|
371
|
+
}, L = () => {
|
|
372
|
+
_e();
|
|
373
|
+
for (let e of I) try {
|
|
374
|
+
e();
|
|
375
|
+
} catch {}
|
|
376
|
+
}, R = (e) => {
|
|
377
|
+
let t = {
|
|
378
|
+
...e,
|
|
379
|
+
status: "pending",
|
|
380
|
+
startedAt: Date.now()
|
|
381
|
+
};
|
|
382
|
+
F.unshift(t), F.length > he && (F.length = he), L();
|
|
383
|
+
}, z = (e, t) => {
|
|
384
|
+
let n = F.findIndex((t) => t.id === e);
|
|
385
|
+
if (n === -1) return;
|
|
386
|
+
let r = F[n], i = Date.now();
|
|
387
|
+
F[n] = t.status === "success" ? {
|
|
388
|
+
...r,
|
|
389
|
+
status: "success",
|
|
390
|
+
output: t.output,
|
|
391
|
+
settledAt: i,
|
|
392
|
+
durationMs: i - r.startedAt
|
|
393
|
+
} : {
|
|
394
|
+
...r,
|
|
395
|
+
status: "error",
|
|
396
|
+
error: t.error,
|
|
397
|
+
settledAt: i,
|
|
398
|
+
durationMs: i - r.startedAt
|
|
399
|
+
}, L();
|
|
400
|
+
}, ve = () => ge, ye = (e) => (I.add(e), () => {
|
|
401
|
+
I.delete(e);
|
|
402
|
+
}), be = () => {
|
|
403
|
+
F.length !== 0 && (F.length = 0, L());
|
|
404
|
+
}, xe = (e, t) => {
|
|
405
|
+
if (t === void 0 || typeof e != "object" || !e) return e;
|
|
406
|
+
try {
|
|
407
|
+
Object.defineProperty(e, "__voltroTraceId", {
|
|
408
|
+
value: t,
|
|
409
|
+
enumerable: !1,
|
|
410
|
+
configurable: !0
|
|
411
|
+
});
|
|
412
|
+
} catch {}
|
|
413
|
+
return e;
|
|
414
|
+
}, Se = 0, Ce = () => `mut_${++Se}`, we = (e, t) => ({
|
|
415
|
+
update: (n, r) => {
|
|
416
|
+
e.update(n, r, t);
|
|
417
|
+
},
|
|
418
|
+
forTag: (n, r) => e.forTag(n, r, t)
|
|
419
|
+
}), B = (e, t) => {
|
|
420
|
+
let { runtime: r, cache: i, client: c, descriptors: l, errorBus: u } = M(e), f = l[t], p = f?.targets;
|
|
421
|
+
if (process.env.NODE_ENV !== "production") {
|
|
422
|
+
let n = f?.kind;
|
|
423
|
+
n !== void 0 && n !== "mutation" && console.error(`[@voltro/client] useMutation('${e}', '${t}') targets a ${n}, not a mutation. Use ${n === "action" ? "useAction" : n === "workflow" ? "useWorkflow" : `the ${n} hook`} instead.`);
|
|
424
|
+
}
|
|
425
|
+
let [m, h] = s(!1), [g, _] = s(void 0), [v, y] = s(void 0), b = o(null), S = o(!1), C = n(async (n) => {
|
|
426
|
+
h(!0), _(void 0);
|
|
427
|
+
let a = Ce();
|
|
428
|
+
R({
|
|
429
|
+
id: a,
|
|
430
|
+
apiName: e,
|
|
431
|
+
tag: t,
|
|
432
|
+
input: n
|
|
433
|
+
});
|
|
434
|
+
let o = b.current, s = S.current;
|
|
435
|
+
if (o) try {
|
|
436
|
+
o(we(i, a), n);
|
|
437
|
+
} catch (e) {
|
|
438
|
+
throw _(e), h(!1), i.revertByMutation(a), z(a, {
|
|
439
|
+
status: "error",
|
|
440
|
+
error: e
|
|
441
|
+
}), e;
|
|
442
|
+
}
|
|
443
|
+
else !s && p && p.length > 0 && i.autoApply(p, n, a);
|
|
444
|
+
let l;
|
|
445
|
+
try {
|
|
446
|
+
let o = N(c, t), s = d.currentSpan.pipe(d.tap((e) => d.sync(() => {
|
|
447
|
+
l = e.traceId, x({
|
|
448
|
+
traceId: e.traceId,
|
|
449
|
+
spanId: e.spanId,
|
|
450
|
+
source: "mutation",
|
|
451
|
+
tag: t
|
|
452
|
+
});
|
|
453
|
+
})), d.catchAll(() => d.void), d.zipRight(o(n))).pipe(d.withSpan(`client.mutation.${t}`, { attributes: {
|
|
454
|
+
"voltro.api": e,
|
|
455
|
+
"voltro.mutationId": a,
|
|
456
|
+
"rpc.tag": t
|
|
457
|
+
} })), u = await r.runPromise(s);
|
|
458
|
+
return y(u), z(a, {
|
|
459
|
+
status: "success",
|
|
460
|
+
output: u
|
|
461
|
+
}), i.confirmByMutation(a), u;
|
|
462
|
+
} catch (e) {
|
|
463
|
+
let n = xe(e, l);
|
|
464
|
+
throw _(n), z(a, {
|
|
465
|
+
status: "error",
|
|
466
|
+
error: n
|
|
467
|
+
}), i.revertByMutation(a), u.emit({
|
|
468
|
+
source: "mutation",
|
|
469
|
+
tag: t,
|
|
470
|
+
error: n,
|
|
471
|
+
...l === void 0 ? {} : { traceId: l }
|
|
472
|
+
}), n;
|
|
473
|
+
} finally {
|
|
474
|
+
h(!1);
|
|
475
|
+
}
|
|
476
|
+
}, [
|
|
477
|
+
r,
|
|
478
|
+
i,
|
|
479
|
+
c,
|
|
480
|
+
e,
|
|
481
|
+
t,
|
|
482
|
+
p
|
|
483
|
+
]);
|
|
484
|
+
return a(() => {
|
|
485
|
+
let e = {
|
|
486
|
+
mutate: C,
|
|
487
|
+
pending: m,
|
|
488
|
+
error: g,
|
|
489
|
+
data: v,
|
|
490
|
+
withOptimistic: (t) => (b.current = t, e),
|
|
491
|
+
withoutOptimistic: () => (S.current = !0, e)
|
|
492
|
+
};
|
|
493
|
+
return e;
|
|
494
|
+
}, [
|
|
495
|
+
C,
|
|
496
|
+
m,
|
|
497
|
+
g,
|
|
498
|
+
v
|
|
499
|
+
]);
|
|
500
|
+
}, Te = (e, t) => {
|
|
501
|
+
if (t === void 0 || typeof e != "object" || !e) return e;
|
|
502
|
+
try {
|
|
503
|
+
Object.defineProperty(e, "__voltroTraceId", {
|
|
504
|
+
value: t,
|
|
505
|
+
enumerable: !1,
|
|
506
|
+
configurable: !0
|
|
507
|
+
});
|
|
508
|
+
} catch {}
|
|
509
|
+
return e;
|
|
510
|
+
}, Ee = 0, De = () => `act_${++Ee}`, V = (e, t) => {
|
|
511
|
+
let { runtime: r, client: i, descriptors: o, errorBus: c } = M(e);
|
|
512
|
+
if (process.env.NODE_ENV !== "production") {
|
|
513
|
+
let n = o[t]?.kind;
|
|
514
|
+
n !== void 0 && n !== "action" && console.error(`[@voltro/client] useAction('${e}', '${t}') targets a ${n}, not an action. Use ${n === "mutation" ? "useMutation" : n === "workflow" ? "useWorkflow" : `the ${n} hook`} instead.`);
|
|
515
|
+
}
|
|
516
|
+
let [l, u] = s(!1), [f, p] = s(void 0), [m, h] = s(void 0), g = n(async (n) => {
|
|
517
|
+
u(!0), p(void 0);
|
|
518
|
+
let a = De();
|
|
519
|
+
R({
|
|
520
|
+
id: a,
|
|
521
|
+
apiName: e,
|
|
522
|
+
tag: t,
|
|
523
|
+
input: n
|
|
524
|
+
});
|
|
525
|
+
let o;
|
|
526
|
+
try {
|
|
527
|
+
let s = N(i, t), c = d.currentSpan.pipe(d.tap((e) => d.sync(() => {
|
|
528
|
+
o = e.traceId, x({
|
|
529
|
+
traceId: e.traceId,
|
|
530
|
+
spanId: e.spanId,
|
|
531
|
+
source: "action",
|
|
532
|
+
tag: t
|
|
533
|
+
});
|
|
534
|
+
})), d.catchAll(() => d.void), d.zipRight(s(n))).pipe(d.withSpan(`client.action.${t}`, { attributes: {
|
|
535
|
+
"voltro.api": e,
|
|
536
|
+
"voltro.actionId": a,
|
|
537
|
+
"rpc.tag": t
|
|
538
|
+
} })), l = await r.runPromise(c);
|
|
539
|
+
return h(l), z(a, {
|
|
540
|
+
status: "success",
|
|
541
|
+
output: l
|
|
542
|
+
}), l;
|
|
543
|
+
} catch (e) {
|
|
544
|
+
let n = Te(e, o);
|
|
545
|
+
throw p(n), z(a, {
|
|
546
|
+
status: "error",
|
|
547
|
+
error: n
|
|
548
|
+
}), c.emit({
|
|
549
|
+
source: "action",
|
|
550
|
+
tag: t,
|
|
551
|
+
error: n,
|
|
552
|
+
...o === void 0 ? {} : { traceId: o }
|
|
553
|
+
}), n;
|
|
554
|
+
} finally {
|
|
555
|
+
u(!1);
|
|
556
|
+
}
|
|
557
|
+
}, [
|
|
558
|
+
r,
|
|
559
|
+
i,
|
|
560
|
+
e,
|
|
561
|
+
t,
|
|
562
|
+
c
|
|
563
|
+
]);
|
|
564
|
+
return a(() => ({
|
|
565
|
+
run: g,
|
|
566
|
+
pending: l,
|
|
567
|
+
error: f,
|
|
568
|
+
lastResult: m
|
|
569
|
+
}), [
|
|
570
|
+
g,
|
|
571
|
+
l,
|
|
572
|
+
f,
|
|
573
|
+
m
|
|
574
|
+
]);
|
|
575
|
+
}, H = "storage.mintUploadTicket", Oe = "storage.mintPresignedUpload", ke = "storage.finalizeUpload", Ae = "storage.beginResumableUpload", je = "storage.beginMultipartUpload", Me = "storage.signMultipartPart", Ne = "storage.completeMultipartUpload", Pe = "storage.abortMultipartUpload", Fe = (e, t, n, r) => new Promise((i, a) => {
|
|
576
|
+
let o = new XMLHttpRequest();
|
|
577
|
+
if (o.open("PUT", e), o.upload.onprogress = (e) => {
|
|
578
|
+
e.lengthComputable && n(e.loaded / e.total);
|
|
579
|
+
}, o.onload = () => {
|
|
580
|
+
if (o.status >= 200 && o.status < 300) {
|
|
581
|
+
let e = o.getResponseHeader("ETag") ?? o.getResponseHeader("etag");
|
|
582
|
+
e ? i(e) : a(/* @__PURE__ */ Error("multipart part: response carried no ETag (the bucket CORS must expose the ETag header)"));
|
|
583
|
+
} else a(Error(`multipart part failed (${o.status}): ${o.responseText || o.statusText}`.trim()));
|
|
584
|
+
}, o.onerror = () => a(/* @__PURE__ */ Error("multipart part: network error")), o.onabort = () => a(new DOMException("upload aborted", "AbortError")), r.aborted) {
|
|
585
|
+
o.abort();
|
|
586
|
+
return;
|
|
587
|
+
}
|
|
588
|
+
r.addEventListener("abort", () => o.abort(), { once: !0 }), o.send(t);
|
|
589
|
+
}), Ie = (e, t, n, r, i, a) => new Promise((o, s) => {
|
|
590
|
+
let c = new XMLHttpRequest();
|
|
591
|
+
if (c.open("POST", e), c.setRequestHeader("content-type", t), c.upload.onprogress = (e) => {
|
|
592
|
+
e.lengthComputable && r(e.loaded / e.total);
|
|
593
|
+
}, c.onload = () => {
|
|
594
|
+
if (c.status >= 200 && c.status < 300) {
|
|
595
|
+
if (!a) return o(null);
|
|
596
|
+
try {
|
|
597
|
+
o(JSON.parse(c.responseText));
|
|
598
|
+
} catch {
|
|
599
|
+
s(/* @__PURE__ */ Error("resumable upload: malformed final response"));
|
|
600
|
+
}
|
|
601
|
+
} else s(Error(`resumable chunk failed (${c.status}): ${c.responseText || c.statusText}`.trim()));
|
|
602
|
+
}, c.onerror = () => s(/* @__PURE__ */ Error("resumable chunk: network error")), c.onabort = () => s(new DOMException("upload aborted", "AbortError")), i.aborted) {
|
|
603
|
+
c.abort();
|
|
604
|
+
return;
|
|
605
|
+
}
|
|
606
|
+
i.addEventListener("abort", () => c.abort(), { once: !0 }), c.send(n);
|
|
607
|
+
}), Le = (e, t, n, r, i) => new Promise((a, o) => {
|
|
608
|
+
let s = new XMLHttpRequest();
|
|
609
|
+
if (s.open("PUT", e), s.setRequestHeader("content-type", t), s.upload.onprogress = (e) => {
|
|
610
|
+
e.lengthComputable && r(e.loaded / e.total);
|
|
611
|
+
}, s.onload = () => {
|
|
612
|
+
s.status >= 200 && s.status < 300 ? a() : o(Error(`direct upload failed (${s.status}): ${s.responseText || s.statusText}`.trim()));
|
|
613
|
+
}, s.onerror = () => o(/* @__PURE__ */ Error("direct upload: network error")), s.onabort = () => o(new DOMException("upload aborted", "AbortError")), i.aborted) {
|
|
614
|
+
s.abort();
|
|
615
|
+
return;
|
|
616
|
+
}
|
|
617
|
+
i.addEventListener("abort", () => s.abort(), { once: !0 }), s.send(n);
|
|
618
|
+
}), Re = (e, t, n, r, i) => new Promise((a, o) => {
|
|
619
|
+
let s = new XMLHttpRequest();
|
|
620
|
+
if (s.open("POST", e), s.setRequestHeader("content-type", t), s.upload.onprogress = (e) => {
|
|
621
|
+
e.lengthComputable && r(e.loaded / e.total);
|
|
622
|
+
}, s.onload = () => {
|
|
623
|
+
if (s.status >= 200 && s.status < 300) try {
|
|
624
|
+
a(JSON.parse(s.responseText));
|
|
625
|
+
} catch {
|
|
626
|
+
o(/* @__PURE__ */ Error("storage upload: malformed response"));
|
|
627
|
+
}
|
|
628
|
+
else o(Error(`storage upload failed (${s.status}): ${s.responseText || s.statusText}`.trim()));
|
|
629
|
+
}, s.onerror = () => o(/* @__PURE__ */ Error("storage upload: network error")), s.onabort = () => o(new DOMException("upload aborted", "AbortError")), i.aborted) {
|
|
630
|
+
s.abort();
|
|
631
|
+
return;
|
|
632
|
+
}
|
|
633
|
+
i.addEventListener("abort", () => s.abort(), { once: !0 }), s.send(n);
|
|
634
|
+
}), ze = (e, t = {}) => {
|
|
635
|
+
let { runtime: r, client: i, inspectBaseUrl: c, errorBus: l } = M(e), [u, d] = s(0), [f, p] = s("idle"), [m, h] = s(void 0), g = o(null), _ = n(() => {
|
|
636
|
+
d(0), p("idle"), h(void 0);
|
|
637
|
+
}, []), v = n(() => {
|
|
638
|
+
g.current?.abort();
|
|
639
|
+
}, []), y = n((e) => /^https?:\/\//.test(e) ? e : `${c}${e}`, [c]), b = n(async (e, n, a, o) => {
|
|
640
|
+
let s = Math.max(0, n.retries ?? t.retries ?? 1), c = (e instanceof File, e.type) || "application/octet-stream", l = e instanceof File ? e.name : "blob", u = n.visibility ?? t.visibility, d = n.key ?? t.key, f = n.folder ?? t.folder, p = n.tags ?? t.tags, m = {
|
|
641
|
+
...u ? { visibility: u } : {},
|
|
642
|
+
...f ? { folder: f } : {},
|
|
643
|
+
...p ? { tags: p } : {},
|
|
644
|
+
...n.alt ? { alt: n.alt } : {},
|
|
645
|
+
...n.caption ? { caption: n.caption } : {}
|
|
646
|
+
}, h = (e) => ({
|
|
647
|
+
id: e.id,
|
|
648
|
+
url: y(e.url),
|
|
649
|
+
name: l,
|
|
650
|
+
mime: e.contentType,
|
|
651
|
+
size: e.size,
|
|
652
|
+
...e.width === void 0 ? {} : { width: e.width },
|
|
653
|
+
...e.height === void 0 ? {} : { height: e.height }
|
|
654
|
+
}), g = async () => {
|
|
655
|
+
let s = n.mintTag ?? t.mintTag ?? H, l = N(i, s), u = await r.runPromise(l({
|
|
656
|
+
contentType: c,
|
|
657
|
+
...m,
|
|
658
|
+
...d ? { key: d } : {}
|
|
659
|
+
})), f = await Re(y(u.uploadUrl), c, e, o, a);
|
|
660
|
+
return h(f);
|
|
661
|
+
}, _ = async () => {
|
|
662
|
+
let s = n.presignMintTag ?? t.presignMintTag ?? Oe, l = n.finalizeTag ?? t.finalizeTag ?? ke, u;
|
|
663
|
+
try {
|
|
664
|
+
let e = N(i, s);
|
|
665
|
+
u = await r.runPromise(e({
|
|
666
|
+
contentType: c,
|
|
667
|
+
...m
|
|
668
|
+
}));
|
|
669
|
+
} catch {
|
|
670
|
+
return null;
|
|
671
|
+
}
|
|
672
|
+
await Le(u.uploadUrl, c, e, o, a);
|
|
673
|
+
let d = N(i, l), f = await r.runPromise(d({ finalizeToken: u.finalizeToken }));
|
|
674
|
+
return h(f);
|
|
675
|
+
}, v = async () => {
|
|
676
|
+
let s = n.beginResumableTag ?? t.beginResumableTag ?? Ae, l = N(i, s), u = e.size, d = n.chunkSize ?? t.chunkSize, f = await r.runPromise(l({
|
|
677
|
+
contentType: c,
|
|
678
|
+
size: u,
|
|
679
|
+
...m,
|
|
680
|
+
...d ? { chunkSize: d } : {}
|
|
681
|
+
})), p = y(f.uploadUrl), g = Math.max(1, f.chunkSize), _ = Math.max(1, Math.ceil(u / g)), v = Math.max(0, n.retries ?? t.retries ?? 1), b = 0, x = null;
|
|
682
|
+
for (let t = 0; t < _; t++) {
|
|
683
|
+
let n = t * g, r = Math.min(u, n + g), i = e.slice(n, r), s = t === _ - 1, l = r - n, d = 0;
|
|
684
|
+
for (;;) {
|
|
685
|
+
if (a.aborted) throw new DOMException("upload aborted", "AbortError");
|
|
686
|
+
try {
|
|
687
|
+
let e = await Ie(`${p}?${`token=${encodeURIComponent(f.resumableToken)}&index=${t}${s ? "&final=1" : ""}`}`, c, i, (e) => o((b + e * l) / u), a, s);
|
|
688
|
+
s && (x = e);
|
|
689
|
+
break;
|
|
690
|
+
} catch (e) {
|
|
691
|
+
if (e instanceof DOMException && e.name === "AbortError" || d++ >= v) throw e;
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
b += l, o(b / u);
|
|
695
|
+
}
|
|
696
|
+
if (!x) throw Error("resumable upload produced no final reply");
|
|
697
|
+
return h(x);
|
|
698
|
+
}, b = async () => {
|
|
699
|
+
let s = n.multipartBeginTag ?? t.multipartBeginTag ?? je, u = n.multipartSignTag ?? t.multipartSignTag ?? Me, d = n.multipartCompleteTag ?? t.multipartCompleteTag ?? Ne, f = n.multipartAbortTag ?? t.multipartAbortTag ?? Pe, p = e.size, h = n.chunkSize ?? t.chunkSize, g;
|
|
700
|
+
try {
|
|
701
|
+
let e = N(i, s);
|
|
702
|
+
g = await r.runPromise(e({
|
|
703
|
+
contentType: c,
|
|
704
|
+
size: p,
|
|
705
|
+
...m,
|
|
706
|
+
...h ? { partSize: h } : {}
|
|
707
|
+
}));
|
|
708
|
+
} catch {
|
|
709
|
+
return null;
|
|
710
|
+
}
|
|
711
|
+
let _ = N(i, u), v = N(i, d), b = N(i, f), x = Math.max(1, g.partSize), S = Math.max(1, Math.ceil(p / x)), C = Math.max(0, n.retries ?? t.retries ?? 1), w = [], T = 0;
|
|
712
|
+
try {
|
|
713
|
+
for (let t = 0; t < S; t++) {
|
|
714
|
+
let n = t * x, i = Math.min(p, n + x), s = e.slice(n, i), c = t + 1, l = i - n, u = 0;
|
|
715
|
+
for (;;) {
|
|
716
|
+
if (a.aborted) throw new DOMException("upload aborted", "AbortError");
|
|
717
|
+
try {
|
|
718
|
+
let { url: e } = await r.runPromise(_({
|
|
719
|
+
multipartToken: g.multipartToken,
|
|
720
|
+
partNumber: c
|
|
721
|
+
})), t = await Fe(e, s, (e) => o((T + e * l) / p), a);
|
|
722
|
+
w.push({
|
|
723
|
+
partNumber: c,
|
|
724
|
+
etag: t
|
|
725
|
+
});
|
|
726
|
+
break;
|
|
727
|
+
} catch (e) {
|
|
728
|
+
if (e instanceof DOMException && e.name === "AbortError" || u++ >= C) throw e;
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
T += l, o(T / p);
|
|
732
|
+
}
|
|
733
|
+
let t = await r.runPromise(v({
|
|
734
|
+
multipartToken: g.multipartToken,
|
|
735
|
+
parts: w
|
|
736
|
+
}));
|
|
737
|
+
return {
|
|
738
|
+
id: t.id,
|
|
739
|
+
url: y(t.url),
|
|
740
|
+
name: l,
|
|
741
|
+
mime: c,
|
|
742
|
+
size: t.size
|
|
743
|
+
};
|
|
744
|
+
} catch (e) {
|
|
745
|
+
try {
|
|
746
|
+
await r.runPromise(b({ multipartToken: g.multipartToken }));
|
|
747
|
+
} catch {}
|
|
748
|
+
throw e;
|
|
749
|
+
}
|
|
750
|
+
};
|
|
751
|
+
if ((n.prefer ?? t.prefer) === "multipart") return await b() || await v();
|
|
752
|
+
if ((n.prefer ?? t.prefer) === "resumable") return await v();
|
|
753
|
+
let x = (n.prefer ?? t.prefer) === "presign", S;
|
|
754
|
+
for (let e = 0; e <= s; e++) {
|
|
755
|
+
if (a.aborted) throw new DOMException("upload aborted", "AbortError");
|
|
756
|
+
try {
|
|
757
|
+
if (x) {
|
|
758
|
+
let e = await _();
|
|
759
|
+
if (e) return e;
|
|
760
|
+
}
|
|
761
|
+
return await g();
|
|
762
|
+
} catch (t) {
|
|
763
|
+
if (t instanceof DOMException && t.name === "AbortError" || (S = t, e === s)) throw t;
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
throw S;
|
|
767
|
+
}, [
|
|
768
|
+
r,
|
|
769
|
+
i,
|
|
770
|
+
y,
|
|
771
|
+
t.mintTag,
|
|
772
|
+
t.presignMintTag,
|
|
773
|
+
t.finalizeTag,
|
|
774
|
+
t.beginResumableTag,
|
|
775
|
+
t.multipartBeginTag,
|
|
776
|
+
t.multipartSignTag,
|
|
777
|
+
t.multipartCompleteTag,
|
|
778
|
+
t.multipartAbortTag,
|
|
779
|
+
t.chunkSize,
|
|
780
|
+
t.prefer,
|
|
781
|
+
t.visibility,
|
|
782
|
+
t.key,
|
|
783
|
+
t.folder,
|
|
784
|
+
t.tags,
|
|
785
|
+
t.retries
|
|
786
|
+
]), x = n(async (e, n = {}) => {
|
|
787
|
+
let r = new AbortController();
|
|
788
|
+
g.current = r, p("uploading"), h(void 0), d(0);
|
|
789
|
+
try {
|
|
790
|
+
let t = await b(e, n, r.signal, d);
|
|
791
|
+
return d(1), p("success"), t;
|
|
792
|
+
} catch (e) {
|
|
793
|
+
throw p("error"), h(e), e instanceof DOMException && e.name === "AbortError" || l.emit({
|
|
794
|
+
source: "action",
|
|
795
|
+
tag: n.mintTag ?? t.mintTag ?? H,
|
|
796
|
+
error: e
|
|
797
|
+
}), e;
|
|
798
|
+
}
|
|
799
|
+
}, [
|
|
800
|
+
b,
|
|
801
|
+
l,
|
|
802
|
+
t.mintTag
|
|
803
|
+
]), S = n(async (e, n = {}) => {
|
|
804
|
+
if (e.length === 0) return [];
|
|
805
|
+
let r = new AbortController();
|
|
806
|
+
g.current = r, p("uploading"), h(void 0), d(0);
|
|
807
|
+
let i = Math.max(1, n.concurrency ?? t.concurrency ?? 3), a = Array(e.length), o = Array(e.length).fill(0), s = () => d(o.reduce((e, t) => e + t, 0) / e.length), c = 0, u = async () => {
|
|
808
|
+
for (;;) {
|
|
809
|
+
let t = c++;
|
|
810
|
+
if (t >= e.length) return;
|
|
811
|
+
a[t] = await b(e[t], n, r.signal, (e) => {
|
|
812
|
+
o[t] = e, s();
|
|
813
|
+
}), o[t] = 1, s();
|
|
814
|
+
}
|
|
815
|
+
};
|
|
816
|
+
try {
|
|
817
|
+
return await Promise.all(Array.from({ length: Math.min(i, e.length) }, () => u())), d(1), p("success"), a;
|
|
818
|
+
} catch (e) {
|
|
819
|
+
throw r.abort(), p("error"), h(e), e instanceof DOMException && e.name === "AbortError" || l.emit({
|
|
820
|
+
source: "action",
|
|
821
|
+
tag: n.mintTag ?? t.mintTag ?? H,
|
|
822
|
+
error: e
|
|
823
|
+
}), e;
|
|
824
|
+
}
|
|
825
|
+
}, [
|
|
826
|
+
b,
|
|
827
|
+
l,
|
|
828
|
+
t.concurrency,
|
|
829
|
+
t.mintTag
|
|
830
|
+
]), C = n((e, t = {}) => {
|
|
831
|
+
e.preventDefault();
|
|
832
|
+
let n = e.dataTransfer ? Array.from(e.dataTransfer.files) : [];
|
|
833
|
+
return n.length ? S(n, t) : Promise.resolve([]);
|
|
834
|
+
}, [S]), w = n((e, t = {}) => {
|
|
835
|
+
let n = e.clipboardData ? Array.from(e.clipboardData.files) : [];
|
|
836
|
+
return n.length ? S(n, t) : Promise.resolve([]);
|
|
837
|
+
}, [S]), T = a(() => ({
|
|
838
|
+
onDragOver: (e) => e.preventDefault(),
|
|
839
|
+
onDrop: (e) => {
|
|
840
|
+
C(e);
|
|
841
|
+
}
|
|
842
|
+
}), [C]);
|
|
843
|
+
return a(() => ({
|
|
844
|
+
upload: x,
|
|
845
|
+
uploadMany: S,
|
|
846
|
+
progress: u,
|
|
847
|
+
status: f,
|
|
848
|
+
error: m,
|
|
849
|
+
cancel: v,
|
|
850
|
+
reset: _,
|
|
851
|
+
onDrop: C,
|
|
852
|
+
onPaste: w,
|
|
853
|
+
dropzoneProps: T
|
|
854
|
+
}), [
|
|
855
|
+
x,
|
|
856
|
+
S,
|
|
857
|
+
u,
|
|
858
|
+
f,
|
|
859
|
+
m,
|
|
860
|
+
v,
|
|
861
|
+
_,
|
|
862
|
+
C,
|
|
863
|
+
w,
|
|
864
|
+
T
|
|
865
|
+
]);
|
|
866
|
+
}, U = async (e) => {
|
|
867
|
+
let t = N(e.client, e.tag), n = d.currentSpan.pipe(d.tap((t) => d.sync(() => {
|
|
868
|
+
x({
|
|
869
|
+
traceId: t.traceId,
|
|
870
|
+
spanId: t.spanId,
|
|
871
|
+
source: "mutation",
|
|
872
|
+
tag: e.tag
|
|
873
|
+
});
|
|
874
|
+
})), d.catchAll(() => d.void), d.zipRight(t(e.input)), d.withSpan(`${e.spanPrefix}.${e.tag}`, { attributes: {
|
|
875
|
+
"voltro.api": e.apiName,
|
|
876
|
+
"rpc.tag": e.tag
|
|
877
|
+
} }));
|
|
878
|
+
return e.runtime.runPromise(n);
|
|
879
|
+
}, Be = (e, t) => {
|
|
880
|
+
let { runtime: r, client: i, descriptors: o } = M(e);
|
|
881
|
+
if (process.env.NODE_ENV !== "production") {
|
|
882
|
+
let n = o[t]?.kind;
|
|
883
|
+
n !== void 0 && n !== "workflow" && console.error(`[@voltro/client] useWorkflow('${e}', '${t}') targets a ${n}, not a workflow. Use ${n === "mutation" ? "useMutation" : n === "action" ? "useAction" : `the ${n} hook`} instead.`);
|
|
884
|
+
}
|
|
885
|
+
let [c, l] = s(!1), [u, d] = s(void 0), [f, p] = s(void 0), m = n(async (n) => {
|
|
886
|
+
l(!0), d(void 0);
|
|
887
|
+
try {
|
|
888
|
+
let a = await U({
|
|
889
|
+
apiName: e,
|
|
890
|
+
runtime: r,
|
|
891
|
+
client: i,
|
|
892
|
+
tag: t,
|
|
893
|
+
input: n,
|
|
894
|
+
spanPrefix: "client.workflow.start"
|
|
895
|
+
});
|
|
896
|
+
return p(a), a;
|
|
897
|
+
} catch (e) {
|
|
898
|
+
throw d(e), e;
|
|
899
|
+
} finally {
|
|
900
|
+
l(!1);
|
|
901
|
+
}
|
|
902
|
+
}, [
|
|
903
|
+
e,
|
|
904
|
+
r,
|
|
905
|
+
i,
|
|
906
|
+
t
|
|
907
|
+
]), h = n(async (t) => {
|
|
908
|
+
await U({
|
|
909
|
+
apiName: e,
|
|
910
|
+
runtime: r,
|
|
911
|
+
client: i,
|
|
912
|
+
tag: "__voltro.workflow.cancel",
|
|
913
|
+
input: t,
|
|
914
|
+
spanPrefix: "client.workflow.cancel"
|
|
915
|
+
});
|
|
916
|
+
}, [
|
|
917
|
+
e,
|
|
918
|
+
r,
|
|
919
|
+
i
|
|
920
|
+
]), g = n(async (t) => {
|
|
921
|
+
await U({
|
|
922
|
+
apiName: e,
|
|
923
|
+
runtime: r,
|
|
924
|
+
client: i,
|
|
925
|
+
tag: "__voltro.workflow.resume",
|
|
926
|
+
input: t,
|
|
927
|
+
spanPrefix: "client.workflow.resume"
|
|
928
|
+
});
|
|
929
|
+
}, [
|
|
930
|
+
e,
|
|
931
|
+
r,
|
|
932
|
+
i
|
|
933
|
+
]), _ = n(async (t, n, a) => U({
|
|
934
|
+
apiName: e,
|
|
935
|
+
runtime: r,
|
|
936
|
+
client: i,
|
|
937
|
+
tag: "__voltro.workflow.signal",
|
|
938
|
+
input: {
|
|
939
|
+
id: t.id,
|
|
940
|
+
signalName: n,
|
|
941
|
+
...a === void 0 ? {} : { payload: a }
|
|
942
|
+
},
|
|
943
|
+
spanPrefix: "client.workflow.signal"
|
|
944
|
+
}), [
|
|
945
|
+
e,
|
|
946
|
+
r,
|
|
947
|
+
i
|
|
948
|
+
]), v = n(async (t, n, a, o) => U({
|
|
949
|
+
apiName: e,
|
|
950
|
+
runtime: r,
|
|
951
|
+
client: i,
|
|
952
|
+
tag: "__voltro.workflow.update",
|
|
953
|
+
input: {
|
|
954
|
+
id: t.id,
|
|
955
|
+
updateName: n,
|
|
956
|
+
...a === void 0 ? {} : { payload: a },
|
|
957
|
+
...o?.timeoutMs === void 0 ? {} : { timeoutMs: o.timeoutMs }
|
|
958
|
+
},
|
|
959
|
+
spanPrefix: "client.workflow.update"
|
|
960
|
+
}), [
|
|
961
|
+
e,
|
|
962
|
+
r,
|
|
963
|
+
i
|
|
964
|
+
]);
|
|
965
|
+
return a(() => ({
|
|
966
|
+
start: m,
|
|
967
|
+
cancel: h,
|
|
968
|
+
resume: g,
|
|
969
|
+
signal: _,
|
|
970
|
+
update: v,
|
|
971
|
+
pending: c,
|
|
972
|
+
error: u,
|
|
973
|
+
data: f
|
|
974
|
+
}), [
|
|
975
|
+
m,
|
|
976
|
+
h,
|
|
977
|
+
g,
|
|
978
|
+
_,
|
|
979
|
+
v,
|
|
980
|
+
c,
|
|
981
|
+
u,
|
|
982
|
+
f
|
|
983
|
+
]);
|
|
984
|
+
}, Ve = (e) => {
|
|
985
|
+
let { runtime: t, client: r } = M(e), [i, o] = s(!1), [c, l] = s(void 0), [u, d] = s(void 0), f = n(async (n, i, a) => {
|
|
986
|
+
o(!0), l(void 0);
|
|
987
|
+
try {
|
|
988
|
+
let o = await U({
|
|
989
|
+
apiName: e,
|
|
990
|
+
runtime: t,
|
|
991
|
+
client: r,
|
|
992
|
+
tag: "__voltro.workflow.signal",
|
|
993
|
+
input: {
|
|
994
|
+
id: n.id,
|
|
995
|
+
signalName: i,
|
|
996
|
+
...a === void 0 ? {} : { payload: a }
|
|
997
|
+
},
|
|
998
|
+
spanPrefix: "client.workflow.signal"
|
|
999
|
+
});
|
|
1000
|
+
return d(o), o;
|
|
1001
|
+
} catch (e) {
|
|
1002
|
+
throw l(e), e;
|
|
1003
|
+
} finally {
|
|
1004
|
+
o(!1);
|
|
1005
|
+
}
|
|
1006
|
+
}, [
|
|
1007
|
+
e,
|
|
1008
|
+
t,
|
|
1009
|
+
r
|
|
1010
|
+
]);
|
|
1011
|
+
return a(() => ({
|
|
1012
|
+
signal: f,
|
|
1013
|
+
pending: i,
|
|
1014
|
+
error: c,
|
|
1015
|
+
data: u
|
|
1016
|
+
}), [
|
|
1017
|
+
f,
|
|
1018
|
+
i,
|
|
1019
|
+
c,
|
|
1020
|
+
u
|
|
1021
|
+
]);
|
|
1022
|
+
}, He = (e) => {
|
|
1023
|
+
let { runtime: t, client: r } = M(e), [i, o] = s(!1), [c, l] = s(void 0), [u, d] = s(void 0), f = n(async (n, i, a, s) => {
|
|
1024
|
+
o(!0), l(void 0);
|
|
1025
|
+
try {
|
|
1026
|
+
let o = await U({
|
|
1027
|
+
apiName: e,
|
|
1028
|
+
runtime: t,
|
|
1029
|
+
client: r,
|
|
1030
|
+
tag: "__voltro.workflow.update",
|
|
1031
|
+
input: {
|
|
1032
|
+
id: n.id,
|
|
1033
|
+
updateName: i,
|
|
1034
|
+
...a === void 0 ? {} : { payload: a },
|
|
1035
|
+
...s?.timeoutMs === void 0 ? {} : { timeoutMs: s.timeoutMs }
|
|
1036
|
+
},
|
|
1037
|
+
spanPrefix: "client.workflow.update"
|
|
1038
|
+
});
|
|
1039
|
+
return d(o), o;
|
|
1040
|
+
} catch (e) {
|
|
1041
|
+
throw l(e), e;
|
|
1042
|
+
} finally {
|
|
1043
|
+
o(!1);
|
|
1044
|
+
}
|
|
1045
|
+
}, [
|
|
1046
|
+
e,
|
|
1047
|
+
t,
|
|
1048
|
+
r
|
|
1049
|
+
]);
|
|
1050
|
+
return a(() => ({
|
|
1051
|
+
update: f,
|
|
1052
|
+
pending: i,
|
|
1053
|
+
error: c,
|
|
1054
|
+
data: u
|
|
1055
|
+
}), [
|
|
1056
|
+
f,
|
|
1057
|
+
i,
|
|
1058
|
+
c,
|
|
1059
|
+
u
|
|
1060
|
+
]);
|
|
1061
|
+
}, Ue = (e, t) => {
|
|
1062
|
+
let n = P(e, "__voltro.workflow.run", t ? { id: t } : {}, { skip: t === void 0 });
|
|
1063
|
+
return {
|
|
1064
|
+
...n,
|
|
1065
|
+
run: n.data?.[0]
|
|
1066
|
+
};
|
|
1067
|
+
}, We = (e, t = {}, n = {}) => {
|
|
1068
|
+
let r = P(e, "__voltro.workflow.runs", t, n);
|
|
1069
|
+
return {
|
|
1070
|
+
...r,
|
|
1071
|
+
runs: r.data ?? []
|
|
1072
|
+
};
|
|
1073
|
+
}, Ge = (e, t) => {
|
|
1074
|
+
let n = P(e, "__voltro.workflow.run.steps", t ? { runId: t } : {}, { skip: t === void 0 });
|
|
1075
|
+
return {
|
|
1076
|
+
...n,
|
|
1077
|
+
steps: n.data ?? []
|
|
1078
|
+
};
|
|
1079
|
+
}, W = (e, t) => {
|
|
1080
|
+
let n = P(e, "__voltro.workflow.run.events", t ? { runId: t } : {}, { skip: t === void 0 });
|
|
1081
|
+
return {
|
|
1082
|
+
...n,
|
|
1083
|
+
events: n.data ?? []
|
|
1084
|
+
};
|
|
1085
|
+
}, Ke = W, qe = (e, t = {}, n = {}) => {
|
|
1086
|
+
let r = P(e, "__voltro.workflow.domainEvents", t, n);
|
|
1087
|
+
return {
|
|
1088
|
+
...r,
|
|
1089
|
+
events: r.data ?? []
|
|
1090
|
+
};
|
|
1091
|
+
}, Je = (e, t) => {
|
|
1092
|
+
let n = P(e, "__voltro.workflow.event.deliveries", t ? { eventId: t } : {}, { skip: t === void 0 });
|
|
1093
|
+
return {
|
|
1094
|
+
...n,
|
|
1095
|
+
deliveries: n.data ?? []
|
|
1096
|
+
};
|
|
1097
|
+
}, G = (e, t) => {
|
|
1098
|
+
let n = e.payload;
|
|
1099
|
+
if (!n || typeof n != "object") return;
|
|
1100
|
+
let r = n[t];
|
|
1101
|
+
return typeof r == "string" ? r : void 0;
|
|
1102
|
+
}, Ye = (e) => {
|
|
1103
|
+
let t = e.payload;
|
|
1104
|
+
if (!t || typeof t != "object") return;
|
|
1105
|
+
let n = t.updateId;
|
|
1106
|
+
return typeof n == "string" ? n : void 0;
|
|
1107
|
+
}, Xe = (e) => {
|
|
1108
|
+
let t = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set();
|
|
1109
|
+
for (let r of e) if (r.eventType === "signal-received") {
|
|
1110
|
+
let e = G(r, "signalName");
|
|
1111
|
+
e && t.add(e);
|
|
1112
|
+
} else if (r.eventType === "update-completed" || r.eventType === "update-failed") {
|
|
1113
|
+
let e = Ye(r);
|
|
1114
|
+
e && n.add(e);
|
|
1115
|
+
}
|
|
1116
|
+
for (let r = e.length - 1; r >= 0; --r) {
|
|
1117
|
+
let i = e[r];
|
|
1118
|
+
if (i.eventType === "signal-awaited") {
|
|
1119
|
+
let e = G(i, "signalName");
|
|
1120
|
+
if (e && !t.has(e)) return {
|
|
1121
|
+
name: e,
|
|
1122
|
+
kind: "signal"
|
|
1123
|
+
};
|
|
1124
|
+
} else if (i.eventType === "update-requested") {
|
|
1125
|
+
let e = Ye(i), t = G(i, "updateName");
|
|
1126
|
+
if (t && (!e || !n.has(e))) return {
|
|
1127
|
+
name: t,
|
|
1128
|
+
kind: "update"
|
|
1129
|
+
};
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
}, Ze = (e) => e.find((e) => e.status === "running") || (e.length > 0 ? e[e.length - 1] : void 0), Qe = (e, t) => {
|
|
1133
|
+
if (!e || e.status !== "failed") return;
|
|
1134
|
+
let n = t.find((e) => e.status === "failed");
|
|
1135
|
+
return {
|
|
1136
|
+
tag: e.errorTag,
|
|
1137
|
+
message: e.errorMessage,
|
|
1138
|
+
step: n?.stepName
|
|
1139
|
+
};
|
|
1140
|
+
}, $e = (e, t) => {
|
|
1141
|
+
let r = Ue(e, t), i = Ge(e, t), o = W(e, t), s = Be(e, r.run?.tag ?? ""), c = r.run, l = i.steps, u = o.events, d = n(async () => {
|
|
1142
|
+
if (!c) throw Error("useWorkflowRunState: no run loaded — cannot cancel");
|
|
1143
|
+
await s.cancel({
|
|
1144
|
+
workflowName: c.tag,
|
|
1145
|
+
executionId: c.executionId
|
|
1146
|
+
});
|
|
1147
|
+
}, [s, c]), f = n(async () => {
|
|
1148
|
+
if (!c) throw Error("useWorkflowRunState: no run loaded — cannot resume");
|
|
1149
|
+
await s.resume({
|
|
1150
|
+
workflowName: c.tag,
|
|
1151
|
+
executionId: c.executionId
|
|
1152
|
+
});
|
|
1153
|
+
}, [s, c]), p = n((e, n) => {
|
|
1154
|
+
if (t === void 0) throw Error("useWorkflowRunState: no run id — cannot signal");
|
|
1155
|
+
return s.signal({ id: t }, e, n);
|
|
1156
|
+
}, [s, t]), m = n((e, n, r) => {
|
|
1157
|
+
if (t === void 0) throw Error("useWorkflowRunState: no run id — cannot update");
|
|
1158
|
+
return s.update({ id: t }, e, n, r);
|
|
1159
|
+
}, [s, t]);
|
|
1160
|
+
return a(() => ({
|
|
1161
|
+
run: c,
|
|
1162
|
+
status: c?.status,
|
|
1163
|
+
steps: l,
|
|
1164
|
+
events: u,
|
|
1165
|
+
currentStep: Ze(l),
|
|
1166
|
+
waitingFor: c?.status === "suspended" ? Xe(u) : void 0,
|
|
1167
|
+
error: Qe(c, l),
|
|
1168
|
+
traceId: c?.traceId,
|
|
1169
|
+
loading: r.data === void 0,
|
|
1170
|
+
cancel: d,
|
|
1171
|
+
resume: f,
|
|
1172
|
+
signal: p,
|
|
1173
|
+
update: m
|
|
1174
|
+
}), [
|
|
1175
|
+
c,
|
|
1176
|
+
l,
|
|
1177
|
+
u,
|
|
1178
|
+
r.data,
|
|
1179
|
+
d,
|
|
1180
|
+
f,
|
|
1181
|
+
p,
|
|
1182
|
+
m
|
|
1183
|
+
]);
|
|
1184
|
+
}, et = (e, t) => {
|
|
1185
|
+
let { runtime: r, client: i } = M(e), [a, c] = s([]), [u, f] = s("idle"), [m, h] = s(void 0), _ = o(null), v = n(() => {
|
|
1186
|
+
let e = _.current;
|
|
1187
|
+
e && (_.current = null, r.runFork(p.interrupt(e)), f((e) => e === "streaming" ? "idle" : e));
|
|
1188
|
+
}, [r]);
|
|
1189
|
+
return {
|
|
1190
|
+
events: a,
|
|
1191
|
+
status: u,
|
|
1192
|
+
error: m,
|
|
1193
|
+
start: n((e = {}) => {
|
|
1194
|
+
let n = _.current;
|
|
1195
|
+
n && r.runFork(p.interrupt(n)), c([]), h(void 0), f("streaming");
|
|
1196
|
+
let a = N(i, t)(e), o = g.runForEach(a, (e) => d.sync(() => c((t) => [...t, e]))).pipe(d.matchCause({
|
|
1197
|
+
onSuccess: () => {
|
|
1198
|
+
f("done");
|
|
1199
|
+
},
|
|
1200
|
+
onFailure: (e) => {
|
|
1201
|
+
l.isInterruptedOnly(e) || (h(l.squash(e)), f("error"));
|
|
1202
|
+
}
|
|
1203
|
+
}));
|
|
1204
|
+
_.current = r.runFork(o);
|
|
1205
|
+
}, [
|
|
1206
|
+
r,
|
|
1207
|
+
i,
|
|
1208
|
+
t
|
|
1209
|
+
]),
|
|
1210
|
+
cancel: v
|
|
1211
|
+
};
|
|
1212
|
+
}, tt = (e, t, n, r) => {
|
|
1213
|
+
let i = 0, a = !1, o = (e) => d.sync(() => {
|
|
1214
|
+
e.seq <= i || (i = e.seq, n.onEvent(e.event), r.isTerminal(e.event) && (a = !0));
|
|
1215
|
+
}), s = (e, t, a) => {
|
|
1216
|
+
let o = i > t ? 0 : e + 1;
|
|
1217
|
+
if (o > r.maxReconnects) return d.sync(() => {
|
|
1218
|
+
n.onError(a ?? /* @__PURE__ */ Error("stream connection lost")), n.onStatus("error");
|
|
1219
|
+
});
|
|
1220
|
+
let s = Math.min(r.maxBackoffMs, r.backoffMs * 2 ** Math.max(0, o - 1));
|
|
1221
|
+
return d.sync(() => {
|
|
1222
|
+
n.onStatus("reconnecting"), n.onReconnect();
|
|
1223
|
+
}).pipe(d.zipRight(d.sleep(u.millis(s))), d.zipRight(d.sync(() => n.onStatus("streaming"))), d.zipRight(c(o)));
|
|
1224
|
+
}, c = (r) => d.suspend(() => {
|
|
1225
|
+
let c = i, u = e({
|
|
1226
|
+
...t,
|
|
1227
|
+
fromSeq: c
|
|
1228
|
+
});
|
|
1229
|
+
return g.runForEach(u, o).pipe(d.matchCauseEffect({
|
|
1230
|
+
onSuccess: () => a ? d.sync(() => n.onStatus("done")) : s(r, c, void 0),
|
|
1231
|
+
onFailure: (e) => l.isInterruptedOnly(e) ? d.void : a ? d.sync(() => n.onStatus("done")) : s(r, c, l.squash(e))
|
|
1232
|
+
}));
|
|
1233
|
+
});
|
|
1234
|
+
return c(0);
|
|
1235
|
+
}, nt = (e) => {
|
|
1236
|
+
let t = e?._tag;
|
|
1237
|
+
return t === "done" || t === "error";
|
|
1238
|
+
}, rt = (e, t, r = {}) => {
|
|
1239
|
+
let { runtime: i, client: a } = M(e), [c, l] = s([]), [u, d] = s("idle"), [f, m] = s(0), [h, g] = s(void 0), _ = o(null), v = {
|
|
1240
|
+
maxReconnects: r.maxReconnects ?? 6,
|
|
1241
|
+
backoffMs: r.backoffMs ?? 400,
|
|
1242
|
+
maxBackoffMs: r.maxBackoffMs ?? 8e3,
|
|
1243
|
+
isTerminal: r.isTerminal ?? nt
|
|
1244
|
+
}, y = n(() => {
|
|
1245
|
+
let e = _.current;
|
|
1246
|
+
e && (_.current = null, i.runFork(p.interrupt(e)), d((e) => e === "streaming" || e === "reconnecting" ? "idle" : e));
|
|
1247
|
+
}, [i]);
|
|
1248
|
+
return {
|
|
1249
|
+
events: c,
|
|
1250
|
+
status: u,
|
|
1251
|
+
reconnects: f,
|
|
1252
|
+
error: h,
|
|
1253
|
+
start: n((e = {}) => {
|
|
1254
|
+
let n = _.current;
|
|
1255
|
+
n && i.runFork(p.interrupt(n)), l([]), g(void 0), m(0), d("streaming");
|
|
1256
|
+
let r = N(a, t), o = {
|
|
1257
|
+
onEvent: (e) => l((t) => [...t, e]),
|
|
1258
|
+
onStatus: d,
|
|
1259
|
+
onReconnect: () => m((e) => e + 1),
|
|
1260
|
+
onError: g
|
|
1261
|
+
};
|
|
1262
|
+
_.current = i.runFork(tt(r, e, o, v));
|
|
1263
|
+
}, [
|
|
1264
|
+
i,
|
|
1265
|
+
a,
|
|
1266
|
+
t,
|
|
1267
|
+
v.maxReconnects,
|
|
1268
|
+
v.backoffMs,
|
|
1269
|
+
v.maxBackoffMs,
|
|
1270
|
+
v.isTerminal
|
|
1271
|
+
]),
|
|
1272
|
+
cancel: y
|
|
1273
|
+
};
|
|
1274
|
+
}, it = (e, t) => e.order - t.order || (e.stepOrder ?? 0) - (t.stepOrder ?? 0), at = (e) => {
|
|
1275
|
+
for (let t = e.length - 1; t >= 0; --t) {
|
|
1276
|
+
let n = e[t];
|
|
1277
|
+
if (n.role === "user" && n.content) return n.content;
|
|
1278
|
+
}
|
|
1279
|
+
}, ot = (e, t, r) => {
|
|
1280
|
+
let { threadId: i } = r, o = P(e, `${t}.messages`, { threadId: i }), s = V(e, `${t}.send`), c = a(() => [...o.data ?? []].sort(it), [o.data]), l = n((e, t = {}) => s.run({
|
|
1281
|
+
threadId: i,
|
|
1282
|
+
order: o.data?.length ?? 0,
|
|
1283
|
+
prompt: e,
|
|
1284
|
+
...t
|
|
1285
|
+
}), [
|
|
1286
|
+
s,
|
|
1287
|
+
i,
|
|
1288
|
+
o.data
|
|
1289
|
+
]), u = n(() => {
|
|
1290
|
+
let e = at(c);
|
|
1291
|
+
return e === void 0 ? void 0 : l(e);
|
|
1292
|
+
}, [c, l]);
|
|
1293
|
+
return a(() => ({
|
|
1294
|
+
messages: c,
|
|
1295
|
+
streaming: c.some((e) => e.streaming),
|
|
1296
|
+
loading: o.data === void 0,
|
|
1297
|
+
error: o.error ?? s.error,
|
|
1298
|
+
send: l,
|
|
1299
|
+
regenerate: u,
|
|
1300
|
+
sending: s.pending
|
|
1301
|
+
}), [
|
|
1302
|
+
c,
|
|
1303
|
+
o.data,
|
|
1304
|
+
o.error,
|
|
1305
|
+
s.error,
|
|
1306
|
+
s.pending,
|
|
1307
|
+
l,
|
|
1308
|
+
u
|
|
1309
|
+
]);
|
|
1310
|
+
}, st = (e, t) => {
|
|
1311
|
+
let { events: r, status: c, error: l, start: u, cancel: d } = et(e, t), [f, p] = s([]), m = o(null), h = a(() => r.filter((e) => e._tag === "token").map((e) => e.text ?? "").join(""), [r]);
|
|
1312
|
+
return i(() => {
|
|
1313
|
+
if (c !== "done" || m.current === null) return;
|
|
1314
|
+
let e = m.current;
|
|
1315
|
+
m.current = null, p((t) => [
|
|
1316
|
+
...t,
|
|
1317
|
+
{
|
|
1318
|
+
role: "user",
|
|
1319
|
+
content: e
|
|
1320
|
+
},
|
|
1321
|
+
{
|
|
1322
|
+
role: "assistant",
|
|
1323
|
+
content: h
|
|
1324
|
+
}
|
|
1325
|
+
]);
|
|
1326
|
+
}, [c, h]), {
|
|
1327
|
+
tokens: h,
|
|
1328
|
+
history: f,
|
|
1329
|
+
status: c,
|
|
1330
|
+
error: l,
|
|
1331
|
+
send: n((e = {}) => {
|
|
1332
|
+
let t = e.message;
|
|
1333
|
+
m.current = typeof t == "string" ? t : "", u(e);
|
|
1334
|
+
}, [u]),
|
|
1335
|
+
cancel: d
|
|
1336
|
+
};
|
|
1337
|
+
}, ct = (e, t) => {
|
|
1338
|
+
let r = V(e, t), [i, o] = s(void 0), c = n(async (e) => {
|
|
1339
|
+
let t = await r.run({ question: e });
|
|
1340
|
+
return o(t), t;
|
|
1341
|
+
}, [r]), l = n(() => o(void 0), []);
|
|
1342
|
+
return a(() => ({
|
|
1343
|
+
ask: c,
|
|
1344
|
+
answer: i,
|
|
1345
|
+
pending: r.pending,
|
|
1346
|
+
error: r.error,
|
|
1347
|
+
reset: l
|
|
1348
|
+
}), [
|
|
1349
|
+
c,
|
|
1350
|
+
i,
|
|
1351
|
+
r.pending,
|
|
1352
|
+
r.error,
|
|
1353
|
+
l
|
|
1354
|
+
]);
|
|
1355
|
+
}, lt = (e) => {
|
|
1356
|
+
let { cache: t, runtime: r } = M(e);
|
|
1357
|
+
return n(() => {
|
|
1358
|
+
t.refreshAll(r);
|
|
1359
|
+
}, [t, r]);
|
|
1360
|
+
}, K = /* @__PURE__ */ new Set(), ut = (e) => {
|
|
1361
|
+
for (let t of K) try {
|
|
1362
|
+
t(e);
|
|
1363
|
+
} catch {}
|
|
1364
|
+
}, dt = (e) => (K.add(e), () => {
|
|
1365
|
+
K.delete(e);
|
|
1366
|
+
}), ft = (e, t) => {
|
|
1367
|
+
ut({
|
|
1368
|
+
error: e,
|
|
1369
|
+
source: "manual",
|
|
1370
|
+
...t ? { context: t } : {}
|
|
1371
|
+
});
|
|
1372
|
+
}, pt = (e, t) => {
|
|
1373
|
+
let { errorBus: n } = M(e);
|
|
1374
|
+
i(() => n.on(t), [n, t]);
|
|
1375
|
+
}, mt = "#/$defs/", ht = (e) => e.replace(/[_-]+/g, " ").replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/\s+/g, " ").trim().replace(/^./, (e) => e.toUpperCase()), q = (e, t) => {
|
|
1376
|
+
let n = e;
|
|
1377
|
+
for (let e = 0; e < 8; e += 1) {
|
|
1378
|
+
let e = n.$ref;
|
|
1379
|
+
if (typeof e != "string" || !e.startsWith(mt)) return n;
|
|
1380
|
+
let r = t[e.slice(8)];
|
|
1381
|
+
if (!r || typeof r != "object") return n;
|
|
1382
|
+
n = r;
|
|
1383
|
+
}
|
|
1384
|
+
return n;
|
|
1385
|
+
}, gt = (e) => {
|
|
1386
|
+
if (!e || typeof e != "object") return !1;
|
|
1387
|
+
let t = e;
|
|
1388
|
+
if (t.type === "null" || t.const === null) return !0;
|
|
1389
|
+
let n = t.enum;
|
|
1390
|
+
return Array.isArray(n) && n.length === 1 && n[0] === null;
|
|
1391
|
+
}, _t = (e, t) => {
|
|
1392
|
+
let n = e.type;
|
|
1393
|
+
if (Array.isArray(n) && n.includes("null")) {
|
|
1394
|
+
let t = n.filter((e) => e !== "null");
|
|
1395
|
+
return {
|
|
1396
|
+
node: {
|
|
1397
|
+
...e,
|
|
1398
|
+
type: t.length === 1 ? t[0] : t
|
|
1399
|
+
},
|
|
1400
|
+
nullable: !0
|
|
1401
|
+
};
|
|
1402
|
+
}
|
|
1403
|
+
for (let n of ["anyOf", "oneOf"]) {
|
|
1404
|
+
let r = e[n];
|
|
1405
|
+
if (!Array.isArray(r)) continue;
|
|
1406
|
+
let i = r.filter((e) => !gt(e));
|
|
1407
|
+
if (i.length !== r.length) return i.length === 1 ? {
|
|
1408
|
+
node: q(i[0], t),
|
|
1409
|
+
nullable: !0
|
|
1410
|
+
} : {
|
|
1411
|
+
node: {
|
|
1412
|
+
...e,
|
|
1413
|
+
[n]: i
|
|
1414
|
+
},
|
|
1415
|
+
nullable: !0
|
|
1416
|
+
};
|
|
1417
|
+
}
|
|
1418
|
+
return {
|
|
1419
|
+
node: e,
|
|
1420
|
+
nullable: !1
|
|
1421
|
+
};
|
|
1422
|
+
}, vt = (e) => e.map((e) => ({
|
|
1423
|
+
value: String(e),
|
|
1424
|
+
label: ht(String(e))
|
|
1425
|
+
})), yt = (e) => {
|
|
1426
|
+
let t = e.enum;
|
|
1427
|
+
if (Array.isArray(t) && t.length > 0) return {
|
|
1428
|
+
widget: "select",
|
|
1429
|
+
options: vt(t)
|
|
1430
|
+
};
|
|
1431
|
+
let n = e.type, r = Array.isArray(n) ? n.find((e) => e !== "null") : n, i = e.format;
|
|
1432
|
+
switch (r) {
|
|
1433
|
+
case "string": return i === "date" ? { widget: "date" } : i === "date-time" ? { widget: "datetime" } : { widget: "text" };
|
|
1434
|
+
case "integer":
|
|
1435
|
+
case "number": return { widget: "number" };
|
|
1436
|
+
case "boolean": return { widget: "checkbox" };
|
|
1437
|
+
case "array": return { widget: "multi-select" };
|
|
1438
|
+
default: return { widget: "custom" };
|
|
1439
|
+
}
|
|
1440
|
+
}, bt = (e, t, n) => Object.entries(e).map(([e, r]) => {
|
|
1441
|
+
let { node: i, nullable: a } = _t(q(r, n), n), o = q(i, n), { widget: s, options: c } = yt(o);
|
|
1442
|
+
return {
|
|
1443
|
+
name: e,
|
|
1444
|
+
label: ht(e),
|
|
1445
|
+
widget: s,
|
|
1446
|
+
required: t.has(e),
|
|
1447
|
+
nullable: a,
|
|
1448
|
+
...c ? { options: c } : {},
|
|
1449
|
+
jsonSchema: o
|
|
1450
|
+
};
|
|
1451
|
+
}), xt = (e) => {
|
|
1452
|
+
try {
|
|
1453
|
+
return m.make(e);
|
|
1454
|
+
} catch {
|
|
1455
|
+
return;
|
|
1456
|
+
}
|
|
1457
|
+
}, J = (e) => {
|
|
1458
|
+
let t = xt(e);
|
|
1459
|
+
if (t === void 0) return [];
|
|
1460
|
+
let n = t.$defs ?? {}, r = q(t, n), i = r.properties;
|
|
1461
|
+
return i ? bt(i, new Set(Array.isArray(r.required) ? r.required : []), n) : [];
|
|
1462
|
+
}, Y = (e) => {
|
|
1463
|
+
let t = xt(e);
|
|
1464
|
+
if (t === void 0) return [];
|
|
1465
|
+
let n = t.$defs ?? {}, r = q(t, n);
|
|
1466
|
+
if (r.type !== "array") return [];
|
|
1467
|
+
let i = r.items;
|
|
1468
|
+
if (!i || typeof i != "object") return [];
|
|
1469
|
+
let a = q(i, n), o = a.properties;
|
|
1470
|
+
return o ? bt(o, new Set(Array.isArray(a.required) ? a.required : []), n) : [];
|
|
1471
|
+
}, X = (e, t) => {
|
|
1472
|
+
let n = h.decodeUnknownEither(e, { errors: "all" })(t);
|
|
1473
|
+
if (n._tag === "Right") return {
|
|
1474
|
+
valid: !0,
|
|
1475
|
+
errors: {}
|
|
1476
|
+
};
|
|
1477
|
+
let r = {};
|
|
1478
|
+
for (let e of y.formatErrorSync(n.left)) {
|
|
1479
|
+
let t = e.path.length === 0 ? "" : String(e.path[0]);
|
|
1480
|
+
t !== "" && !(t in r) && (r[t] = e.message);
|
|
1481
|
+
}
|
|
1482
|
+
return {
|
|
1483
|
+
valid: !1,
|
|
1484
|
+
errors: r
|
|
1485
|
+
};
|
|
1486
|
+
}, St = (e, t, r) => {
|
|
1487
|
+
let i = M(e), c = B(e, t), l = r.schema ?? i.descriptors[t]?.input;
|
|
1488
|
+
process.env.NODE_ENV !== "production" && l === void 0 && console.error(`[@voltro/client] useFormBinding('${e}', '${t}'): no input schema. Pass options.schema, or mount the descriptor so its input reaches the client. Rendering no fields; submit skips client-side validation.`);
|
|
1489
|
+
let u = a(() => l ? J(l) : [], [l]), d = o(r.defaults ?? {}), [f, p] = s(d.current), [m, h] = s({}), g = n((e, t) => {
|
|
1490
|
+
p((n) => ({
|
|
1491
|
+
...n,
|
|
1492
|
+
[e]: t
|
|
1493
|
+
}));
|
|
1494
|
+
}, []), _ = n((e) => {
|
|
1495
|
+
p((t) => ({
|
|
1496
|
+
...t,
|
|
1497
|
+
...e
|
|
1498
|
+
}));
|
|
1499
|
+
}, []), v = n(() => {
|
|
1500
|
+
p(d.current), h({});
|
|
1501
|
+
}, []), y = n(async () => {
|
|
1502
|
+
if (l !== void 0) {
|
|
1503
|
+
let e = X(l, f);
|
|
1504
|
+
if (h(e.errors), !e.valid) return;
|
|
1505
|
+
}
|
|
1506
|
+
return c.mutate(f);
|
|
1507
|
+
}, [
|
|
1508
|
+
l,
|
|
1509
|
+
f,
|
|
1510
|
+
c
|
|
1511
|
+
]);
|
|
1512
|
+
return {
|
|
1513
|
+
fields: u,
|
|
1514
|
+
values: f,
|
|
1515
|
+
errors: m,
|
|
1516
|
+
isValid: a(() => l === void 0 || X(l, f).valid, [l, f]),
|
|
1517
|
+
pending: c.pending,
|
|
1518
|
+
submitError: c.error,
|
|
1519
|
+
data: c.data,
|
|
1520
|
+
setValue: g,
|
|
1521
|
+
setValues: _,
|
|
1522
|
+
reset: v,
|
|
1523
|
+
submit: y
|
|
1524
|
+
};
|
|
1525
|
+
}, Z = (e, t, n) => e.map((e) => {
|
|
1526
|
+
let r = String(e[n] ?? ""), i = e[t];
|
|
1527
|
+
return {
|
|
1528
|
+
value: r,
|
|
1529
|
+
label: i == null ? r : String(i)
|
|
1530
|
+
};
|
|
1531
|
+
}), Ct = (e, t, r = {}) => {
|
|
1532
|
+
let o = r.debounceMs ?? 200, c = r.labelField ?? "name", l = r.valueField ?? "id", u = r.input ?? ((e) => ({ q: e })), [d, f] = s(r.initialTerm ?? ""), [p, m] = s(d);
|
|
1533
|
+
i(() => {
|
|
1534
|
+
if (d === p) return;
|
|
1535
|
+
let e = setTimeout(() => m(d), o);
|
|
1536
|
+
return () => clearTimeout(e);
|
|
1537
|
+
}, [
|
|
1538
|
+
d,
|
|
1539
|
+
p,
|
|
1540
|
+
o
|
|
1541
|
+
]);
|
|
1542
|
+
let h = r.skipUntilTerm === !0 && p.trim() === "", g = P(e, t, a(() => u(p), [u, p]), { skip: h }), _ = a(() => Z(g.data ?? [], c, l), [
|
|
1543
|
+
g.data,
|
|
1544
|
+
c,
|
|
1545
|
+
l
|
|
1546
|
+
]), v = n((e) => f(e), []);
|
|
1547
|
+
return {
|
|
1548
|
+
options: _,
|
|
1549
|
+
loading: !h && g.data === void 0,
|
|
1550
|
+
term: d,
|
|
1551
|
+
search: v
|
|
1552
|
+
};
|
|
1553
|
+
}, wt = (e, t) => e === t ? 0 : e == null ? 1 : t == null || e < t ? -1 : 1, Tt = (e, t, r = {}) => {
|
|
1554
|
+
let i = M(e), [o, c] = s(r.pageSize), l = P(e, t, a(() => o === void 0 ? r.input ?? {} : {
|
|
1555
|
+
...r.input,
|
|
1556
|
+
limit: o
|
|
1557
|
+
}, [r.input, o])), u = i.descriptors[t]?.output, d = n(() => {
|
|
1558
|
+
r.pageSize !== void 0 && c((e) => (e ?? r.pageSize) + r.pageSize);
|
|
1559
|
+
}, [r.pageSize]), f = a(() => r.columns ?? (u === void 0 ? [] : Y(u)), [r.columns, u]), [p, m] = s(r.initialSort), h = n((e) => {
|
|
1560
|
+
m((t) => t?.column === e ? {
|
|
1561
|
+
column: e,
|
|
1562
|
+
direction: t.direction === "asc" ? "desc" : "asc"
|
|
1563
|
+
} : {
|
|
1564
|
+
column: e,
|
|
1565
|
+
direction: "asc"
|
|
1566
|
+
});
|
|
1567
|
+
}, []);
|
|
1568
|
+
return {
|
|
1569
|
+
columns: f,
|
|
1570
|
+
rows: a(() => {
|
|
1571
|
+
let e = l.data ?? [];
|
|
1572
|
+
if (p === void 0) return e;
|
|
1573
|
+
let t = p.direction === "asc" ? 1 : -1;
|
|
1574
|
+
return [...e].sort((e, n) => wt(e[p.column], n[p.column]) * t);
|
|
1575
|
+
}, [l.data, p]),
|
|
1576
|
+
loading: l.data === void 0,
|
|
1577
|
+
error: l.error,
|
|
1578
|
+
sort: p,
|
|
1579
|
+
toggleSort: h,
|
|
1580
|
+
loadMore: d,
|
|
1581
|
+
hasMore: o !== void 0 && (l.data?.length ?? 0) >= o
|
|
1582
|
+
};
|
|
1583
|
+
}, Et = (e, t, n, r) => {
|
|
1584
|
+
let i = e.replace(/\/$/, ""), a = new URLSearchParams({
|
|
1585
|
+
table: t,
|
|
1586
|
+
id: n
|
|
1587
|
+
});
|
|
1588
|
+
return r !== void 0 && a.set("column", r), `${i}/_voltro/inspect/provenance?${a.toString()}`;
|
|
1589
|
+
}, Dt = Et, Ot = (e, t, n, r) => {
|
|
1590
|
+
let { inspectBaseUrl: a } = M(e), [o, c] = s({
|
|
1591
|
+
data: void 0,
|
|
1592
|
+
loading: !0,
|
|
1593
|
+
error: void 0
|
|
1594
|
+
});
|
|
1595
|
+
return i(() => {
|
|
1596
|
+
let e = !1;
|
|
1597
|
+
c({
|
|
1598
|
+
data: void 0,
|
|
1599
|
+
loading: !0,
|
|
1600
|
+
error: void 0
|
|
1601
|
+
});
|
|
1602
|
+
let i = Et(a ?? "", t, n, r);
|
|
1603
|
+
return fetch(i).then(async (e) => {
|
|
1604
|
+
if (!e.ok) throw Error(`provenance fetch failed: HTTP ${e.status}`);
|
|
1605
|
+
return await e.json();
|
|
1606
|
+
}).then((t) => {
|
|
1607
|
+
e || c({
|
|
1608
|
+
data: t,
|
|
1609
|
+
loading: !1,
|
|
1610
|
+
error: void 0
|
|
1611
|
+
});
|
|
1612
|
+
}).catch((t) => {
|
|
1613
|
+
e || c({
|
|
1614
|
+
data: void 0,
|
|
1615
|
+
loading: !1,
|
|
1616
|
+
error: t
|
|
1617
|
+
});
|
|
1618
|
+
}), () => {
|
|
1619
|
+
e = !0;
|
|
1620
|
+
};
|
|
1621
|
+
}, [
|
|
1622
|
+
e,
|
|
1623
|
+
a,
|
|
1624
|
+
t,
|
|
1625
|
+
n,
|
|
1626
|
+
r
|
|
1627
|
+
]), o;
|
|
1628
|
+
}, kt = (e) => `${e.replace(/\/$/, "")}/_voltro/inspect/manifest`, At = (e) => {
|
|
1629
|
+
let { inspectBaseUrl: t } = M(e), [n, r] = s({
|
|
1630
|
+
manifest: void 0,
|
|
1631
|
+
loading: !0,
|
|
1632
|
+
error: void 0
|
|
1633
|
+
});
|
|
1634
|
+
return i(() => {
|
|
1635
|
+
let e = !1;
|
|
1636
|
+
return r({
|
|
1637
|
+
manifest: void 0,
|
|
1638
|
+
loading: !0,
|
|
1639
|
+
error: void 0
|
|
1640
|
+
}), fetch(kt(t ?? "")).then(async (e) => {
|
|
1641
|
+
if (!e.ok) throw Error(`manifest fetch failed: HTTP ${e.status}`);
|
|
1642
|
+
return await e.json();
|
|
1643
|
+
}).then((t) => {
|
|
1644
|
+
e || r({
|
|
1645
|
+
manifest: t,
|
|
1646
|
+
loading: !1,
|
|
1647
|
+
error: void 0
|
|
1648
|
+
});
|
|
1649
|
+
}).catch((t) => {
|
|
1650
|
+
e || r({
|
|
1651
|
+
manifest: void 0,
|
|
1652
|
+
loading: !1,
|
|
1653
|
+
error: t
|
|
1654
|
+
});
|
|
1655
|
+
}), () => {
|
|
1656
|
+
e = !0;
|
|
1657
|
+
};
|
|
1658
|
+
}, [e, t]), n;
|
|
1659
|
+
}, jt = (e, t) => Array.isArray(e) ? e.includes(t) : e === t, Q = (e, t, n) => e.targets?.some((e) => e.table === t && e.op === n) ?? !1, Mt = (e) => e.tables.filter((e) => !e.framework).map((t) => {
|
|
1660
|
+
let n = e.procedures.find((e) => e.kind === "query" && jt(e.source, t.name)), r = e.procedures.find((e) => e.kind === "mutation" && Q(e, t.name, "insert")), i = e.procedures.find((e) => e.kind === "mutation" && Q(e, t.name, "update")), a = e.procedures.find((e) => e.kind === "mutation" && Q(e, t.name, "delete"));
|
|
1661
|
+
return {
|
|
1662
|
+
table: t.name,
|
|
1663
|
+
columns: t.columns,
|
|
1664
|
+
reactive: t.reactive,
|
|
1665
|
+
...n === void 0 ? {} : { listTag: n.tag },
|
|
1666
|
+
...r === void 0 ? {} : { createTag: r.tag },
|
|
1667
|
+
...i === void 0 ? {} : { updateTag: i.tag },
|
|
1668
|
+
...a === void 0 ? {} : { deleteTag: a.tag },
|
|
1669
|
+
createScope: `${t.name}:create`,
|
|
1670
|
+
writeScope: `${t.name}:write`,
|
|
1671
|
+
deleteScope: `${t.name}:delete`
|
|
1672
|
+
};
|
|
1673
|
+
}), Nt = (e) => {
|
|
1674
|
+
let [t, r] = s([]), [i, o] = s([]), c = n((e) => {
|
|
1675
|
+
r((t) => [...t, e]), o([]);
|
|
1676
|
+
}, []), l = n(async () => {
|
|
1677
|
+
let n = t[t.length - 1];
|
|
1678
|
+
n === void 0 || n.blockedBy !== void 0 || (await e.onUndo(n.invocationId), r((e) => e.slice(0, -1)), o((e) => [...e, n]));
|
|
1679
|
+
}, [t, e]), u = n(async () => {
|
|
1680
|
+
let t = i[i.length - 1];
|
|
1681
|
+
t !== void 0 && (await e.onRedo(t.invocationId), o((e) => e.slice(0, -1)), r((e) => [...e, t]));
|
|
1682
|
+
}, [i, e]);
|
|
1683
|
+
return a(() => {
|
|
1684
|
+
let e = t[t.length - 1];
|
|
1685
|
+
return {
|
|
1686
|
+
record: c,
|
|
1687
|
+
undo: l,
|
|
1688
|
+
redo: u,
|
|
1689
|
+
canUndo: t.length > 0 && e?.blockedBy === void 0,
|
|
1690
|
+
canRedo: i.length > 0,
|
|
1691
|
+
stack: t,
|
|
1692
|
+
nextBlockedBy: e?.blockedBy
|
|
1693
|
+
};
|
|
1694
|
+
}, [
|
|
1695
|
+
t,
|
|
1696
|
+
i,
|
|
1697
|
+
c,
|
|
1698
|
+
l,
|
|
1699
|
+
u
|
|
1700
|
+
]);
|
|
1701
|
+
}, Pt = "__voltro.undo.log", Ft = "__voltro.undo.apply", It = "__voltro.undo.redo", Lt = (e, t) => {
|
|
1702
|
+
let r = t?.limit, { data: i } = P(e, Pt, r === void 0 ? {} : { limit: r }), a = B(e, Ft), o = B(e, It), s = i ?? [], c = s.find((e) => !e.undone && !e.crossesAction), l = s.find((e) => e.undone), u = n(async (e) => {
|
|
1703
|
+
await a.mutate({ invocationId: e });
|
|
1704
|
+
}, [a]), d = n(async (e) => {
|
|
1705
|
+
await o.mutate({ invocationId: e });
|
|
1706
|
+
}, [o]), f = n(async () => {
|
|
1707
|
+
c && await u(c.id);
|
|
1708
|
+
}, [c, u]), p = n(async () => {
|
|
1709
|
+
l && await d(l.id);
|
|
1710
|
+
}, [l, d]);
|
|
1711
|
+
return {
|
|
1712
|
+
entries: s,
|
|
1713
|
+
loading: i === void 0,
|
|
1714
|
+
canUndo: c !== void 0,
|
|
1715
|
+
canRedo: l !== void 0,
|
|
1716
|
+
undo: u,
|
|
1717
|
+
redo: d,
|
|
1718
|
+
undoLast: f,
|
|
1719
|
+
redoLast: p
|
|
1720
|
+
};
|
|
1721
|
+
}, Rt = (e, t) => ({
|
|
1722
|
+
name: e,
|
|
1723
|
+
map: t
|
|
1724
|
+
}), $ = (e, t) => e === void 0 ? null : typeof e == "string" ? { event: e } : e(t), zt = /* @__PURE__ */ new Set(["onMount", "onUnmount"]), Bt = (e, t, n) => {
|
|
1725
|
+
let r = { ...t };
|
|
1726
|
+
for (let [i, a] of Object.entries(e.map)) {
|
|
1727
|
+
if (zt.has(i) || a === void 0) continue;
|
|
1728
|
+
let e = t[i];
|
|
1729
|
+
r[i] = (...r) => {
|
|
1730
|
+
let i = $(a, t);
|
|
1731
|
+
if (i !== null && n(i), typeof e == "function") return e(...r);
|
|
1732
|
+
};
|
|
1733
|
+
}
|
|
1734
|
+
return r;
|
|
1735
|
+
}, Vt = (e, t, n) => {
|
|
1736
|
+
let r = o({
|
|
1737
|
+
spec: e,
|
|
1738
|
+
props: t,
|
|
1739
|
+
sink: n
|
|
1740
|
+
});
|
|
1741
|
+
return r.current = {
|
|
1742
|
+
spec: e,
|
|
1743
|
+
props: t,
|
|
1744
|
+
sink: n
|
|
1745
|
+
}, i(() => {
|
|
1746
|
+
let e = r.current, t = $(e.spec.map.onMount, e.props);
|
|
1747
|
+
return t !== null && e.sink(t), () => {
|
|
1748
|
+
let e = r.current, t = $(e.spec.map.onUnmount, e.props);
|
|
1749
|
+
t !== null && e.sink(t);
|
|
1750
|
+
};
|
|
1751
|
+
}, []), a(() => Bt(e, t, n), [
|
|
1752
|
+
e,
|
|
1753
|
+
t,
|
|
1754
|
+
n
|
|
1755
|
+
]);
|
|
1756
|
+
}, Ht = (e, t) => {
|
|
1757
|
+
let n = M(e).descriptors[t]?.input;
|
|
1758
|
+
return a(() => n === void 0 ? [] : J(n), [n]);
|
|
1759
|
+
}, Ut = (e, t) => {
|
|
1760
|
+
let n = M(e).descriptors[t]?.output;
|
|
1761
|
+
return a(() => n === void 0 ? [] : Y(n), [n]);
|
|
1762
|
+
}, Wt = (e, t) => {
|
|
1763
|
+
if (e === t) return !0;
|
|
1764
|
+
if (e.length !== t.length) return !1;
|
|
1765
|
+
for (let n = 0; n < e.length; n += 1) if (!Object.is(e[n], t[n])) return !1;
|
|
1766
|
+
return !0;
|
|
1767
|
+
}, Gt = (e) => Object.keys(e).sort().map((t) => e[t]), Kt = (e, t) => {
|
|
1768
|
+
let n = o(null), r = Gt(e);
|
|
1769
|
+
return (n.current === null || !Wt(n.current.key, r)) && (n.current = {
|
|
1770
|
+
key: r,
|
|
1771
|
+
value: t(e)
|
|
1772
|
+
}), n.current.value;
|
|
1773
|
+
}, qt = "admin:full", Jt = (e, t) => e.includes("admin:full") ? !0 : (typeof t == "string" ? [t] : t).every((t) => e.includes(t)), Yt = e({ scopes: [] });
|
|
1774
|
+
function Xt(e) {
|
|
1775
|
+
return t(Yt.Provider, { value: { scopes: e.scopes } }, e.children);
|
|
1776
|
+
}
|
|
1777
|
+
var Zt = () => r(Yt), Qt = (e) => Jt(Zt().scopes, e), $t = (e, t, n, r = {}) => {
|
|
1778
|
+
let i = P(e, t, { ...n }, r);
|
|
1779
|
+
return a(() => ({
|
|
1780
|
+
allowed: i.data?.allowed === !0,
|
|
1781
|
+
pending: i.data === void 0
|
|
1782
|
+
}), [i.data]);
|
|
1783
|
+
}, en = (e, t, n, r = {}) => {
|
|
1784
|
+
let i = P(e, t, { ...n }, r);
|
|
1785
|
+
return a(() => ({
|
|
1786
|
+
allowedIds: new Set(i.data?.allowedIds ?? []),
|
|
1787
|
+
pending: i.data === void 0
|
|
1788
|
+
}), [i.data]);
|
|
1789
|
+
}, tn = (e) => {
|
|
1790
|
+
switch (e) {
|
|
1791
|
+
case "select":
|
|
1792
|
+
case "radio":
|
|
1793
|
+
case "async-select": return "select";
|
|
1794
|
+
case "multi-select": return "multi-select";
|
|
1795
|
+
case "text":
|
|
1796
|
+
case "textarea": return "text";
|
|
1797
|
+
case "number": return "number-range";
|
|
1798
|
+
case "date":
|
|
1799
|
+
case "datetime":
|
|
1800
|
+
case "daterange": return "date-range";
|
|
1801
|
+
case "checkbox":
|
|
1802
|
+
case "switch": return "boolean";
|
|
1803
|
+
default: return null;
|
|
1804
|
+
}
|
|
1805
|
+
}, nn = (e) => J(e).map((e) => {
|
|
1806
|
+
let t = tn(e.widget);
|
|
1807
|
+
return t === null ? null : {
|
|
1808
|
+
name: e.name,
|
|
1809
|
+
label: e.label,
|
|
1810
|
+
kind: t,
|
|
1811
|
+
...e.options ? { options: e.options } : {}
|
|
1812
|
+
};
|
|
1813
|
+
}).filter((e) => e !== null), rn = (e) => {
|
|
1814
|
+
let t = {};
|
|
1815
|
+
for (let [n, r] of Object.entries(e)) r === void 0 || r === "" || Array.isArray(r) && r.length === 0 || (t[n] = r);
|
|
1816
|
+
return t;
|
|
1817
|
+
}, an = (e, t, r = {}) => {
|
|
1818
|
+
let i = M(e).descriptors[t]?.input, o = a(() => i === void 0 ? [] : nn(i), [i]), [c, l] = s(r.initial ?? {}), u = n((e, t) => {
|
|
1819
|
+
l((n) => rn({
|
|
1820
|
+
...n,
|
|
1821
|
+
[e]: t
|
|
1822
|
+
}));
|
|
1823
|
+
}, []), d = n(() => l({}), []), f = P(e, t, a(() => rn(c), [c]));
|
|
1824
|
+
return {
|
|
1825
|
+
filters: o,
|
|
1826
|
+
values: c,
|
|
1827
|
+
setFilter: u,
|
|
1828
|
+
clear: d,
|
|
1829
|
+
rows: f.data ?? [],
|
|
1830
|
+
count: f.data?.length,
|
|
1831
|
+
loading: f.data === void 0,
|
|
1832
|
+
error: f.error
|
|
1833
|
+
};
|
|
1834
|
+
}, on = (e, t, n = {}) => {
|
|
1835
|
+
let r = P(e, t, n), i = r.data;
|
|
1836
|
+
return {
|
|
1837
|
+
record: Array.isArray(i) ? i[0] : i,
|
|
1838
|
+
loading: i === void 0,
|
|
1839
|
+
error: r.error
|
|
1840
|
+
};
|
|
1841
|
+
}, sn = (e, t = 300) => {
|
|
1842
|
+
let [n, r] = s(e);
|
|
1843
|
+
return i(() => {
|
|
1844
|
+
let n = setTimeout(() => r(e), t);
|
|
1845
|
+
return () => clearTimeout(n);
|
|
1846
|
+
}, [e, t]), n;
|
|
1847
|
+
}, cn = (e) => {
|
|
1848
|
+
let { value: t, debouncedValue: n, data: r, interpret: i, skipEmpty: a = !0 } = e;
|
|
1849
|
+
if (a && t.trim() === "") return {
|
|
1850
|
+
status: "idle",
|
|
1851
|
+
valid: void 0,
|
|
1852
|
+
message: void 0
|
|
1853
|
+
};
|
|
1854
|
+
if (t !== n || r === void 0) return {
|
|
1855
|
+
status: "checking",
|
|
1856
|
+
valid: void 0,
|
|
1857
|
+
message: void 0
|
|
1858
|
+
};
|
|
1859
|
+
let o = i(r);
|
|
1860
|
+
return {
|
|
1861
|
+
status: o.valid ? "valid" : "invalid",
|
|
1862
|
+
valid: o.valid,
|
|
1863
|
+
message: o.message
|
|
1864
|
+
};
|
|
1865
|
+
}, ln = (e, t, n, r) => {
|
|
1866
|
+
let { input: i, interpret: o, debounceMs: s = 300, skipEmpty: c = !0 } = r, l = sn(n, s), u = c && l.trim() === "", d = P(e, t, a(() => i ? i(l) : { value: l }, [i, l]), { skip: u });
|
|
1867
|
+
return cn({
|
|
1868
|
+
value: n,
|
|
1869
|
+
debouncedValue: l,
|
|
1870
|
+
data: u ? null : d.data,
|
|
1871
|
+
interpret: o,
|
|
1872
|
+
skipEmpty: c
|
|
1873
|
+
});
|
|
1874
|
+
}, un = (e, t) => ({
|
|
1875
|
+
name: e,
|
|
1876
|
+
payload: t
|
|
1877
|
+
}), dn = (e, t) => {
|
|
1878
|
+
let n = h.decodeUnknownEither(e.payload, { errors: "all" })(t);
|
|
1879
|
+
if (n._tag === "Right") return {
|
|
1880
|
+
valid: !0,
|
|
1881
|
+
errors: {}
|
|
1882
|
+
};
|
|
1883
|
+
let r = {};
|
|
1884
|
+
for (let e of y.formatErrorSync(n.left)) r[e.path.join(".") || "(root)"] = e.message;
|
|
1885
|
+
return {
|
|
1886
|
+
valid: !1,
|
|
1887
|
+
errors: r
|
|
1888
|
+
};
|
|
1889
|
+
}, fn = (e) => {
|
|
1890
|
+
let t = new Map(e.map((e) => [e.name, e]));
|
|
1891
|
+
return {
|
|
1892
|
+
names: [...t.keys()].sort(),
|
|
1893
|
+
get: (e) => t.get(e),
|
|
1894
|
+
events: e
|
|
1895
|
+
};
|
|
1896
|
+
}, pn = (e, t) => {
|
|
1897
|
+
let n = fn(e);
|
|
1898
|
+
return {
|
|
1899
|
+
track: (e, r) => {
|
|
1900
|
+
let i = n.get(e);
|
|
1901
|
+
if (i === void 0) {
|
|
1902
|
+
process.env.NODE_ENV !== "production" && console.error(`[@voltro/client] analytics.track: unknown event '${e}' (not in the catalog)`);
|
|
1903
|
+
return;
|
|
1904
|
+
}
|
|
1905
|
+
if (process.env.NODE_ENV !== "production") {
|
|
1906
|
+
let t = dn(i, r);
|
|
1907
|
+
t.valid || console.error(`[@voltro/client] analytics.track('${e}'): payload failed its schema`, t.errors);
|
|
1908
|
+
}
|
|
1909
|
+
t({
|
|
1910
|
+
event: e,
|
|
1911
|
+
...r
|
|
1912
|
+
});
|
|
1913
|
+
},
|
|
1914
|
+
names: n.names,
|
|
1915
|
+
catalog: n
|
|
1916
|
+
};
|
|
1917
|
+
}, mn = (e, t) => {
|
|
1918
|
+
let r = V(e, t);
|
|
1919
|
+
return {
|
|
1920
|
+
preview: n((e) => r.run(e), [r]),
|
|
1921
|
+
diff: r.lastResult,
|
|
1922
|
+
pending: r.pending,
|
|
1923
|
+
error: r.error
|
|
1924
|
+
};
|
|
1925
|
+
}, hn = (e, t, n, r) => [...e, {
|
|
1926
|
+
id: t,
|
|
1927
|
+
tag: n,
|
|
1928
|
+
input: r,
|
|
1929
|
+
status: "pending",
|
|
1930
|
+
attempts: 0
|
|
1931
|
+
}], gn = (e, t, n) => e.map((e) => e.id === t ? {
|
|
1932
|
+
...e,
|
|
1933
|
+
...n
|
|
1934
|
+
} : e), _n = (e, t) => gn(e, t, { status: "sent" }), vn = (e, t, n) => e.map((e) => e.id === t ? {
|
|
1935
|
+
...e,
|
|
1936
|
+
status: "failed",
|
|
1937
|
+
error: n,
|
|
1938
|
+
attempts: e.attempts + 1
|
|
1939
|
+
} : e), yn = (e, t, n) => gn(e, t, {
|
|
1940
|
+
status: "conflict",
|
|
1941
|
+
error: n
|
|
1942
|
+
}), bn = (e) => e.filter((e) => e.status !== "sent"), xn = (e) => {
|
|
1943
|
+
let t = [];
|
|
1944
|
+
for (let n of e) {
|
|
1945
|
+
if (n.status === "conflict") break;
|
|
1946
|
+
(n.status === "pending" || n.status === "failed") && t.push(n);
|
|
1947
|
+
}
|
|
1948
|
+
return t;
|
|
1949
|
+
}, Sn = (e) => {
|
|
1950
|
+
let t = e;
|
|
1951
|
+
return t?.conflict === !0 || t?._tag === "UndoBoundaryError" && t?.boundary === "conflict";
|
|
1952
|
+
}, Cn = (e) => {
|
|
1953
|
+
let [t, n] = s(e ?? (typeof navigator < "u" ? navigator.onLine : !0));
|
|
1954
|
+
return i(() => {
|
|
1955
|
+
if (e !== void 0) {
|
|
1956
|
+
n(e);
|
|
1957
|
+
return;
|
|
1958
|
+
}
|
|
1959
|
+
if (typeof window > "u") return;
|
|
1960
|
+
let t = () => n(!0), r = () => n(!1);
|
|
1961
|
+
return window.addEventListener("online", t), window.addEventListener("offline", r), () => {
|
|
1962
|
+
window.removeEventListener("online", t), window.removeEventListener("offline", r);
|
|
1963
|
+
};
|
|
1964
|
+
}, [e]), t;
|
|
1965
|
+
}, wn = (e) => {
|
|
1966
|
+
let { send: t, isConflict: r = Sn, idFor: a } = e, [c, l] = s([]), u = Cn(e.online), d = o(c);
|
|
1967
|
+
d.current = c;
|
|
1968
|
+
let f = o(0), p = n((e, t) => {
|
|
1969
|
+
let n = a?.() ?? `obx_${f.current++}_${e}`;
|
|
1970
|
+
l((r) => hn(r, n, e, t));
|
|
1971
|
+
}, [a]), m = n(async () => {
|
|
1972
|
+
for (let e of xn(d.current)) try {
|
|
1973
|
+
await t(e), l((t) => _n(t, e.id));
|
|
1974
|
+
} catch (t) {
|
|
1975
|
+
if (r(t)) {
|
|
1976
|
+
l((n) => yn(n, e.id, t));
|
|
1977
|
+
break;
|
|
1978
|
+
}
|
|
1979
|
+
l((n) => vn(n, e.id, t));
|
|
1980
|
+
}
|
|
1981
|
+
}, [t, r]);
|
|
1982
|
+
return i(() => {
|
|
1983
|
+
u && m();
|
|
1984
|
+
}, [u, m]), {
|
|
1985
|
+
queue: c,
|
|
1986
|
+
enqueue: p,
|
|
1987
|
+
replay: m,
|
|
1988
|
+
online: u,
|
|
1989
|
+
pending: c.filter((e) => e.status === "pending" || e.status === "failed").length,
|
|
1990
|
+
conflicts: c.filter((e) => e.status === "conflict")
|
|
1991
|
+
};
|
|
1992
|
+
}, Tn = (e) => {
|
|
1993
|
+
let { scrollTop: t, viewportHeight: n, rowHeight: r, overscan: i = 5, total: a } = e, o = r > 0 ? r : 1, s = Math.max(0, Math.floor(t / o)), c = Math.ceil(n / o), l = Math.max(0, s - i), u = s + c + i, d = a === void 0 ? u : Math.min(u, a);
|
|
1994
|
+
return {
|
|
1995
|
+
startIndex: l,
|
|
1996
|
+
endIndex: d,
|
|
1997
|
+
offset: l,
|
|
1998
|
+
limit: Math.max(0, d - l),
|
|
1999
|
+
topSpacer: l * r,
|
|
2000
|
+
bottomSpacer: a === void 0 ? 0 : Math.max(0, (a - d) * r)
|
|
2001
|
+
};
|
|
2002
|
+
}, En = (e, t, r) => {
|
|
2003
|
+
let { rowHeight: i, viewportHeight: o, overscan: c, total: l, input: u } = r, [d, f] = s(0), p = a(() => Tn({
|
|
2004
|
+
scrollTop: d,
|
|
2005
|
+
viewportHeight: o,
|
|
2006
|
+
rowHeight: i,
|
|
2007
|
+
...c === void 0 ? {} : { overscan: c },
|
|
2008
|
+
...l === void 0 ? {} : { total: l }
|
|
2009
|
+
}), [
|
|
2010
|
+
d,
|
|
2011
|
+
o,
|
|
2012
|
+
i,
|
|
2013
|
+
c,
|
|
2014
|
+
l
|
|
2015
|
+
]), m = P(e, t, a(() => ({
|
|
2016
|
+
...u,
|
|
2017
|
+
offset: p.offset,
|
|
2018
|
+
limit: p.limit
|
|
2019
|
+
}), [
|
|
2020
|
+
u,
|
|
2021
|
+
p.offset,
|
|
2022
|
+
p.limit
|
|
2023
|
+
])), h = n((e) => {
|
|
2024
|
+
f(e.currentTarget.scrollTop);
|
|
2025
|
+
}, []);
|
|
2026
|
+
return {
|
|
2027
|
+
rows: m.data ?? [],
|
|
2028
|
+
window: p,
|
|
2029
|
+
onScroll: h,
|
|
2030
|
+
topSpacer: p.topSpacer,
|
|
2031
|
+
bottomSpacer: p.bottomSpacer,
|
|
2032
|
+
loading: m.data === void 0,
|
|
2033
|
+
error: m.error
|
|
2034
|
+
};
|
|
2035
|
+
}, Dn = "framework-client";
|
|
2036
|
+
//#endregion
|
|
2037
|
+
export { qt as ADMIN_SCOPE, Dn as CLIENT_NAME, D as FrameworkRuntimesContext, fe as FrameworkRuntimesProvider, ie as LoadingSubscriptionCache, Xt as PermissionProvider, ae as RpcErrorBus, re as SubscriptionCache, Ft as UNDO_APPLY_TAG, Pt as UNDO_LOG_TAG, It as UNDO_REDO_TAG, ue as _resetFrameworkRuntimesWarning, Jt as canCall, be as clearMutations, bn as clearSent, Tn as computeWindow, pn as createAnalytics, un as defineEvent, Rt as defineTracking, Mt as deriveEntityAdmins, hn as enqueueEntry, oe as errorTag, fn as eventCatalog, nn as filtersFromSchema, ve as getMutations, kt as manifestUrl, yn as markConflict, vn as markFailed, _n as markSent, Dt as provenanceUrl, ut as publishClientError, x as publishClientTrace, xn as replayable, ft as reportClientError, N as resolveByTag, $ as resolveTrackingEvent, tt as resumableConsumeProgram, Z as rowsToOptions, Y as schemaToColumns, J as schemaToFields, z as settleMutation, Wt as shallowArrayEqual, Gt as sourceValues, O as ssrClientProxy, ce as ssrStubHandle, C as stableKey, R as startMutation, dt as subscribeClientErrors, S as subscribeClientTraces, ye as subscribeMutations, V as useAction, st as useAgent, ot as useAgentChat, et as useAgentStream, ln as useAsyncValidation, Qt as useCan, At as useCapabilityManifest, ct as useDataCopilot, Tt as useDataTable, sn as useDebounced, Kt as useDerived, St as useFormBinding, Ht as useFormSkeleton, M as useFrameworkApi, de as useFrameworkRuntimes, B as useMutation, pt as useOnRpcError, wn as useOutbox, Zt as usePermissions, mn as usePreview, Ot as useProvenance, Ct as useQueryField, an as useQueryFilters, on as useRecord, lt as useRefreshSubscriptions, $t as useResourceCan, en as useResourceCans, rt as useResumableAgentStream, P as useSubscription, Ut as useTableSkeleton, Vt as useTracking, Nt as useUndo, Lt as useUndoLog, ze as useUpload, En as useWindowedSubscription, Be as useWorkflow, qe as useWorkflowDomainEvents, Je as useWorkflowEventDeliveries, Ke as useWorkflowEvents, Ue as useWorkflowRun, W as useWorkflowRunEvents, $e as useWorkflowRunState, Ge as useWorkflowRunSteps, We as useWorkflowRuns, Ve as useWorkflowSignal, He as useWorkflowUpdate, dn as validateEventPayload, X as validateFields, cn as validationStatus, Bt as wrapTrackedCallbacks };
|