@voltro/client 0.84.0 → 0.86.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 +1215 -0
- package/THIRD-PARTY-NOTICES.md +5 -89
- package/dist/analyticsCatalog.js +47 -0
- package/dist/apiConnectivity.js +33 -0
- package/dist/apiRuntime.js +135 -0
- package/dist/apiSupervisor.js +125 -0
- package/dist/authRefresh.js +20 -0
- package/dist/awaitResolvedApi.js +23 -0
- package/dist/bootstrap.d.ts +1144 -0
- package/dist/bootstrap.js +8 -0
- package/dist/cellMerger.js +6 -0
- package/dist/clientDiagnostics.js +94 -0
- package/dist/clientErrorBus.js +16 -0
- package/dist/clientScheduler.js +31 -0
- package/dist/connectionPrerequisite.js +70 -0
- package/dist/connectionScope.js +35 -0
- package/dist/connectionSetupController.js +206 -0
- package/dist/createHooks.js +15 -0
- package/dist/deepLink.js +69 -0
- package/dist/filters.js +58 -0
- package/dist/form.d.ts +8 -11
- package/dist/form.js +5 -2
- package/dist/formBinding.js +325 -0
- package/dist/formData.js +65 -0
- package/dist/formFlashId.js +4 -0
- package/dist/frameworkRuntimesContext.js +8 -0
- package/dist/globalContext.js +10 -0
- package/dist/index.d.ts +285 -279
- package/dist/index.js +83 -3686
- package/dist/liveRowSort.js +66 -0
- package/dist/mutationConnectionSetup.js +16 -0
- package/dist/mutationIdentity.js +10 -0
- package/dist/mutationSerialExecution.js +53 -0
- package/dist/mutationsBus.js +40 -0
- package/dist/onlineSource.js +13 -0
- package/dist/outbox.js +213 -0
- package/dist/outboxHttp.js +104 -0
- package/dist/outboxState.js +43 -0
- package/dist/permissions.js +20 -0
- package/dist/platform.js +121 -0
- package/dist/preloadSeed.js +47 -0
- package/dist/provider.js +22 -0
- package/dist/query.js +12 -2
- package/dist/recoveryCoordinator.js +195 -0
- package/dist/recoveryRetry.js +24 -0
- package/dist/richText.js +176 -0
- package/dist/rpcErrorBus.js +39 -0
- package/dist/rpcErrorKind.js +13 -0
- package/dist/runRpc.js +12 -0
- package/dist/runtime.d.ts +79 -15
- package/dist/runtime.js +16 -129
- package/dist/runtimeCapabilities.js +44 -0
- package/dist/runtimeContext.js +49 -0
- package/dist/schemaFields.js +219 -0
- package/dist/scopeMembership.js +12 -0
- package/dist/seedResolvers.js +7 -0
- package/dist/sequence.js +65 -0
- package/dist/serverRequest.js +24 -0
- package/dist/serviceClient.js +128 -0
- package/dist/squashRpcCause.js +8 -0
- package/dist/stableKey.js +21 -0
- package/dist/store.js +288 -0
- package/dist/storeStorage.js +28 -0
- package/dist/subscriptionCache.js +724 -0
- package/dist/tagWalk.js +23 -0
- package/dist/traceBus.js +10 -0
- package/dist/tracking.js +40 -0
- package/dist/uploadProgress.js +21 -0
- package/dist/useAction.js +101 -0
- package/dist/useAgent.js +53 -0
- package/dist/useAgentChat.js +43 -0
- package/dist/useAgentStream.js +64 -0
- package/dist/useApiOnline.js +14 -0
- package/dist/useCapabilityManifest.js +101 -0
- package/dist/useConnectionSetup.js +28 -0
- package/dist/useConnectionStatus.js +38 -0
- package/dist/useConnections.js +107 -0
- package/dist/useDataCopilot.js +24 -0
- package/dist/useDataTable.js +34 -0
- package/dist/useDerived.js +22 -0
- package/dist/useEvent.js +88 -0
- package/dist/useFormBinding.js +476 -0
- package/dist/useLocalQuery.js +59 -0
- package/dist/useMutation.js +214 -0
- package/dist/useOnRpcError.js +13 -0
- package/dist/usePreloadedSubscription.js +18 -0
- package/dist/usePreview.js +14 -0
- package/dist/useProvenance.js +51 -0
- package/dist/useQueryField.js +34 -0
- package/dist/useRecord.js +12 -0
- package/dist/useRefreshSubscriptions.js +22 -0
- package/dist/useResourceCan.js +18 -0
- package/dist/useResumableAgentStream.js +75 -0
- package/dist/useSequence.js +25 -0
- package/dist/useSkeleton.js +13 -0
- package/dist/useSubscription.js +89 -0
- package/dist/useSubscriptionHealth.js +32 -0
- package/dist/useTranscription.js +51 -0
- package/dist/useUndo.js +33 -0
- package/dist/useUndoLog.js +44 -0
- package/dist/useUpload.js +296 -0
- package/dist/useWindowedSubscription.js +65 -0
- package/dist/useWorkflow.js +284 -0
- package/dist/useWorkflowRunState.js +93 -0
- package/dist/validation.js +39 -0
- package/dist/validationMessages.js +5 -0
- package/package.json +8 -5
- package/dist/authRefresh-C4Ow8HH7.js +0 -346
- package/dist/formData-dGz5aoUR.js +0 -649
- package/dist/queryOnce-CvdopzOj.js +0 -55
- package/dist/runRpc-DvHpFZAZ.js +0 -1034
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
//#region src/liveRowSort.ts
|
|
2
|
+
var e = (e, t) => e === t ? 0 : e == null ? 1 : t == null || e < t ? -1 : 1, t = (t, n) => [...t].sort((t, r) => e(t[n.column], r[n.column]) * (n.direction === "asc" ? 1 : -1)), n = () => {
|
|
3
|
+
let n;
|
|
4
|
+
return (r, i) => {
|
|
5
|
+
if (i === void 0) return n = void 0, r;
|
|
6
|
+
let a = () => (n = void 0, t(r, i));
|
|
7
|
+
if (r.length < 2048 || Object.getPrototypeOf(r) !== Array.prototype || Object.getOwnPropertySymbols(r).length > 0) return a();
|
|
8
|
+
for (let e = 0; e < r.length; e++) {
|
|
9
|
+
let t = Object.getOwnPropertyDescriptor(r, String(e));
|
|
10
|
+
if (t === void 0 || !("value" in t)) return a();
|
|
11
|
+
}
|
|
12
|
+
let o = [], s, c;
|
|
13
|
+
for (let e = 0; e < r.length; e++) {
|
|
14
|
+
let t = r[e];
|
|
15
|
+
if (typeof t != "object" || !t) return a();
|
|
16
|
+
let l;
|
|
17
|
+
if (n?.sort.column === i.column && n.rows[e] === t) l = n.keys[e];
|
|
18
|
+
else {
|
|
19
|
+
let e = Object.getPrototypeOf(t);
|
|
20
|
+
if (e !== Object.prototype && e !== null) return a();
|
|
21
|
+
let n = Object.getOwnPropertyDescriptor(t, i.column);
|
|
22
|
+
if (n !== void 0 && !("value" in n) || n === void 0 && i.column in t) return a();
|
|
23
|
+
l = n?.value;
|
|
24
|
+
}
|
|
25
|
+
if (l == null) {
|
|
26
|
+
let e = l === null ? "null" : "undefined";
|
|
27
|
+
if (c !== void 0 && e !== c) return a();
|
|
28
|
+
c = e;
|
|
29
|
+
} else {
|
|
30
|
+
let e = typeof l;
|
|
31
|
+
if (e !== "string" && e !== "number" && e !== "boolean" && e !== "bigint" || e === "number" && !Number.isFinite(l) || s !== void 0 && e !== s) return a();
|
|
32
|
+
s = e;
|
|
33
|
+
}
|
|
34
|
+
o.push(l);
|
|
35
|
+
}
|
|
36
|
+
let l = i.direction === "asc" ? 1 : -1, u = (t, n) => e(o[t], o[n]) * l || t - n, d = n !== void 0 && n.rows.length === r.length && n.sort.column === i.column && n.sort.direction === i.direction, f;
|
|
37
|
+
if (d) {
|
|
38
|
+
let e = n, t = [], i = !0;
|
|
39
|
+
for (let n = 0; n < r.length; n++) r[n] !== e.rows[n] && (i = !1), Object.is(o[n], e.keys[n]) || t.push(n);
|
|
40
|
+
if (i && t.length === 0) return e.result;
|
|
41
|
+
if (t.length === 0) f = e.order;
|
|
42
|
+
else if (t.length <= 8) {
|
|
43
|
+
let n = new Set(t);
|
|
44
|
+
f = e.order.filter((e) => !n.has(e));
|
|
45
|
+
for (let e of t) {
|
|
46
|
+
let t = 0, n = f.length;
|
|
47
|
+
for (; t < n;) {
|
|
48
|
+
let r = t + n >>> 1;
|
|
49
|
+
u(f[r], e) < 0 ? t = r + 1 : n = r;
|
|
50
|
+
}
|
|
51
|
+
f.splice(t, 0, e);
|
|
52
|
+
}
|
|
53
|
+
} else f = Array.from({ length: r.length }, (e, t) => t).sort(u);
|
|
54
|
+
} else f = Array.from({ length: r.length }, (e, t) => t).sort(u);
|
|
55
|
+
let p = f.map((e) => r[e]);
|
|
56
|
+
return n = {
|
|
57
|
+
rows: r,
|
|
58
|
+
sort: { ...i },
|
|
59
|
+
keys: o,
|
|
60
|
+
order: f,
|
|
61
|
+
result: p
|
|
62
|
+
}, p;
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
//#endregion
|
|
66
|
+
export { n as createLiveRowSorter };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region src/mutationConnectionSetup.ts
|
|
2
|
+
var e = /* @__PURE__ */ new WeakMap(), t = (t, n) => {
|
|
3
|
+
let r = Object.freeze({
|
|
4
|
+
apiName: t,
|
|
5
|
+
kind: "connection-setup"
|
|
6
|
+
});
|
|
7
|
+
return e.set(r, n), r;
|
|
8
|
+
}, n = (t, n) => {
|
|
9
|
+
let r = e.get(t);
|
|
10
|
+
if (r === void 0 || t.apiName !== n) throw Error(`Voltro: connection setup must belong to api "${n}"`);
|
|
11
|
+
return r;
|
|
12
|
+
}, r = /* @__PURE__ */ new WeakMap(), i = (e, t) => {
|
|
13
|
+
r.set(e, t);
|
|
14
|
+
}, a = (e) => r.get(e)?.capture();
|
|
15
|
+
//#endregion
|
|
16
|
+
export { i as bindMutationConnectionSetup, a as captureMutationConnectionSetup, n as connectionSetupOwner, t as createConnectionSetupHandle };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Effect as e } from "effect";
|
|
2
|
+
import * as t from "effect/http/Headers";
|
|
3
|
+
import { RpcClient as n } from "effect/rpc";
|
|
4
|
+
//#region src/mutationIdentity.ts
|
|
5
|
+
var r = 0, i = () => {
|
|
6
|
+
let e = typeof crypto < "u" ? crypto : void 0;
|
|
7
|
+
return e && typeof e.randomUUID == "function" ? e.randomUUID() : `idem_${Date.now().toString(36)}_${r += 1}`;
|
|
8
|
+
}, a = (r, i) => r.pipe(e.updateService(n.CurrentHeaders, (e) => t.set(e, "idempotency-key", i)));
|
|
9
|
+
//#endregion
|
|
10
|
+
export { i as freshIdempotencyKey, a as withIdempotencyKey };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Effect as e, Semaphore as t } from "effect";
|
|
2
|
+
//#region src/mutationSerialExecution.ts
|
|
3
|
+
var n = class extends Error {
|
|
4
|
+
reason;
|
|
5
|
+
_tag = "MutationSerialExecutionError";
|
|
6
|
+
constructor(e) {
|
|
7
|
+
super(`Serial mutation cannot start: ${e}`), this.reason = e, this.name = "MutationSerialExecutionError";
|
|
8
|
+
}
|
|
9
|
+
}, r = (r = 32) => {
|
|
10
|
+
if (!Number.isSafeInteger(r) || r < 1) throw RangeError("maxPending must be a positive safe integer");
|
|
11
|
+
let i = /* @__PURE__ */ new WeakMap(), a = 0;
|
|
12
|
+
return { reserve(o, s) {
|
|
13
|
+
if (typeof o != "string" || o.length === 0) throw new n("invalid-key");
|
|
14
|
+
if (s.aborted) throw new n("scope-changed");
|
|
15
|
+
let c = i.get(s);
|
|
16
|
+
c === void 0 && (c = /* @__PURE__ */ new Map(), i.set(s, c));
|
|
17
|
+
let l = c, u = c.get(o);
|
|
18
|
+
if (u?.blocked.signal.aborted) throw new n("unknown-predecessor");
|
|
19
|
+
if (a >= r) throw new n("capacity");
|
|
20
|
+
u === void 0 && (u = {
|
|
21
|
+
semaphore: t.makeUnsafe(1),
|
|
22
|
+
calls: 0,
|
|
23
|
+
blocked: new AbortController()
|
|
24
|
+
}, c.set(o, u));
|
|
25
|
+
let d = u;
|
|
26
|
+
a += 1, d.calls += 1;
|
|
27
|
+
let f = new AbortController(), p = () => f.abort();
|
|
28
|
+
s.addEventListener("abort", p, { once: !0 }), d.blocked.signal.addEventListener("abort", p, { once: !0 });
|
|
29
|
+
let m = () => {
|
|
30
|
+
if (s.aborted) throw new n("scope-changed");
|
|
31
|
+
if (d.blocked.signal.aborted) throw new n("unknown-predecessor");
|
|
32
|
+
}, h = e.runPromise(d.semaphore.take(1), { signal: f.signal }), g = h.then(() => {
|
|
33
|
+
m();
|
|
34
|
+
}, (e) => {
|
|
35
|
+
throw m(), e;
|
|
36
|
+
});
|
|
37
|
+
g.catch(() => {});
|
|
38
|
+
let _ = !1;
|
|
39
|
+
return {
|
|
40
|
+
ready: g,
|
|
41
|
+
assertActive: m,
|
|
42
|
+
release(t) {
|
|
43
|
+
_ || (_ = !0, t === "unknown" && d.blocked.abort(), h.then(() => {
|
|
44
|
+
e.runSync(d.semaphore.release(1));
|
|
45
|
+
}, () => {}).finally(() => {
|
|
46
|
+
s.removeEventListener("abort", p), d.blocked.signal.removeEventListener("abort", p), --a, --d.calls, d.calls === 0 && !d.blocked.signal.aborted && l.delete(o);
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
} };
|
|
51
|
+
};
|
|
52
|
+
//#endregion
|
|
53
|
+
export { n as MutationSerialExecutionError, r as makeMutationSerialExecution };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
//#region src/mutationsBus.ts
|
|
2
|
+
var e = [], t = /* @__PURE__ */ new Set(), n = [], r = () => {
|
|
3
|
+
n = e.slice();
|
|
4
|
+
}, i = () => {
|
|
5
|
+
r();
|
|
6
|
+
for (let e of t) try {
|
|
7
|
+
e();
|
|
8
|
+
} catch {}
|
|
9
|
+
}, a = (t) => {
|
|
10
|
+
let n = {
|
|
11
|
+
...t,
|
|
12
|
+
kind: t.kind ?? "mutation",
|
|
13
|
+
status: "pending",
|
|
14
|
+
startedAt: Date.now()
|
|
15
|
+
};
|
|
16
|
+
e.unshift(n), e.length > 100 && (e.length = 100), i();
|
|
17
|
+
}, o = (t, n) => {
|
|
18
|
+
let r = e.findIndex((e) => e.id === t);
|
|
19
|
+
if (r === -1) return;
|
|
20
|
+
let a = e[r], o = Date.now();
|
|
21
|
+
e[r] = n.status === "success" ? {
|
|
22
|
+
...a,
|
|
23
|
+
status: "success",
|
|
24
|
+
output: n.output,
|
|
25
|
+
settledAt: o,
|
|
26
|
+
durationMs: o - a.startedAt
|
|
27
|
+
} : {
|
|
28
|
+
...a,
|
|
29
|
+
status: "error",
|
|
30
|
+
error: n.error,
|
|
31
|
+
settledAt: o,
|
|
32
|
+
durationMs: o - a.startedAt
|
|
33
|
+
}, i();
|
|
34
|
+
}, s = () => n, c = (e) => (t.add(e), () => {
|
|
35
|
+
t.delete(e);
|
|
36
|
+
}), l = () => {
|
|
37
|
+
e.length !== 0 && (e.length = 0, i());
|
|
38
|
+
};
|
|
39
|
+
//#endregion
|
|
40
|
+
export { l as clearMutations, s as getMutations, o as settleMutation, a as startMutation, c as subscribeMutations };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region src/onlineSource.ts
|
|
2
|
+
var e = {
|
|
3
|
+
read: () => typeof navigator > "u" || navigator.onLine,
|
|
4
|
+
subscribe: (e) => {
|
|
5
|
+
if (typeof window > "u") return () => {};
|
|
6
|
+
let t = () => e(!0), n = () => e(!1);
|
|
7
|
+
return window.addEventListener("online", t), window.addEventListener("offline", n), () => {
|
|
8
|
+
window.removeEventListener("online", t), window.removeEventListener("offline", n);
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
//#endregion
|
|
13
|
+
export { e as browserOnlineSource };
|
package/dist/outbox.js
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { recoveryCoordinatorFor as e } from "./recoveryCoordinator.js";
|
|
2
|
+
import { FrameworkRuntimesContext as t, isUnresolvedApi as n } from "./frameworkRuntimesContext.js";
|
|
3
|
+
import { resolveByTag as r } from "./tagWalk.js";
|
|
4
|
+
import { runRpcPromise as i } from "./runRpc.js";
|
|
5
|
+
import { awaitResolvedApi as a } from "./awaitResolvedApi.js";
|
|
6
|
+
import { withIdempotencyKey as o } from "./mutationIdentity.js";
|
|
7
|
+
import { useApiOnline as s } from "./useApiOnline.js";
|
|
8
|
+
import { OutboxState as c } from "./outboxState.js";
|
|
9
|
+
import { useCallback as l, useContext as u, useEffect as d, useMemo as f, useRef as p, useState as m } from "react";
|
|
10
|
+
//#region src/outbox.ts
|
|
11
|
+
var h = (e, t, n, r, i) => [...e, {
|
|
12
|
+
id: t,
|
|
13
|
+
tag: n,
|
|
14
|
+
input: r,
|
|
15
|
+
status: "pending",
|
|
16
|
+
attempts: 0,
|
|
17
|
+
...i === void 0 ? {} : { stamp: i }
|
|
18
|
+
}], g = (e, t, n) => e.map((e) => e.id === t ? {
|
|
19
|
+
...e,
|
|
20
|
+
...n
|
|
21
|
+
} : e), _ = (e, t) => g(e, t, { status: "sent" }), v = (e, t, n) => e.map((e) => e.id === t ? {
|
|
22
|
+
...e,
|
|
23
|
+
status: "failed",
|
|
24
|
+
error: n,
|
|
25
|
+
attempts: e.attempts + 1
|
|
26
|
+
} : e), y = (e, t, n) => g(e, t, {
|
|
27
|
+
status: "conflict",
|
|
28
|
+
error: n
|
|
29
|
+
}), b = (e, t, n) => e.map((e) => e.id === t && e.status === "conflict" ? {
|
|
30
|
+
...e,
|
|
31
|
+
input: n,
|
|
32
|
+
status: "pending",
|
|
33
|
+
error: void 0
|
|
34
|
+
} : e), x = (e) => e.filter((e) => e.status !== "sent"), S = (e) => {
|
|
35
|
+
let t = [];
|
|
36
|
+
for (let n of e) {
|
|
37
|
+
if (n.status === "conflict") break;
|
|
38
|
+
(n.status === "pending" || n.status === "failed") && t.push(n);
|
|
39
|
+
}
|
|
40
|
+
return t;
|
|
41
|
+
}, ee = (e) => {
|
|
42
|
+
let t = e;
|
|
43
|
+
return t?.conflict === !0 || t?._tag === "UndoBoundaryError" && t?.boundary === "conflict";
|
|
44
|
+
}, C = (e) => {
|
|
45
|
+
let t = Math.min(3e4, 1e3 * 2 ** Math.max(0, e - 1));
|
|
46
|
+
return t / 2 + t / 2 * Math.random();
|
|
47
|
+
}, w = (h) => {
|
|
48
|
+
let { persistence: g, isConflict: _ = ee, idFor: v, api: y } = h;
|
|
49
|
+
if (h.send === void 0 && y === void 0) throw Error("useOutbox: pass `send`, or `api` to send through that api's own mutations.");
|
|
50
|
+
let b = u(t), S = b?.demand;
|
|
51
|
+
d(() => {
|
|
52
|
+
y !== void 0 && S?.(y);
|
|
53
|
+
}, [S, y]);
|
|
54
|
+
let w = y === void 0 || b === null ? void 0 : b.get(y), T = p(w);
|
|
55
|
+
T.current = w;
|
|
56
|
+
let [E, D] = m(0), [O, k] = m(0), A = s(y), j = h.online ?? A, M = p(void 0);
|
|
57
|
+
M.current === void 0 && (M.current = new c());
|
|
58
|
+
let N = f(() => M.current.snapshot(), [E]), P = l((e) => {
|
|
59
|
+
e(M.current), D((e) => e + 1);
|
|
60
|
+
}, []), F = p(h.retryDelay ?? C);
|
|
61
|
+
F.current = h.retryDelay ?? C;
|
|
62
|
+
let I = p(h.stamp);
|
|
63
|
+
I.current = h.stamp;
|
|
64
|
+
let L = p(async () => void 0);
|
|
65
|
+
L.current = h.send ?? (async (e) => {
|
|
66
|
+
if (T.current === void 0) throw Error(`useOutbox: no mounted api '${y}' — render it inside the framework's runtime provider.`);
|
|
67
|
+
let t = await a(T, y, e.tag), n = r(t.client, e.tag);
|
|
68
|
+
await i(t.runtime, o(n(e.input), e.id));
|
|
69
|
+
});
|
|
70
|
+
let R = p(_);
|
|
71
|
+
R.current = _;
|
|
72
|
+
let z = p(void 0), B = p(!1), V = p(!0);
|
|
73
|
+
d(() => (V.current = !0, () => {
|
|
74
|
+
V.current = !1;
|
|
75
|
+
}), []);
|
|
76
|
+
let H = p(0), U = p(Math.random().toString(36).slice(2, 8)), W = p(g === void 0), [G, K] = m(0), q = w === void 0 ? void 0 : w.recovery ?? e(w.errorBus, y);
|
|
77
|
+
d(() => {
|
|
78
|
+
if (q === void 0) return;
|
|
79
|
+
let e = q.subjectSignal;
|
|
80
|
+
if (e.aborted) return;
|
|
81
|
+
let t = () => {
|
|
82
|
+
M.current.reset(), D((e) => e + 1), W.current = g === void 0, B.current = !1, K((e) => e + 1);
|
|
83
|
+
};
|
|
84
|
+
return e.addEventListener("abort", t, { once: !0 }), () => {
|
|
85
|
+
e.removeEventListener("abort", t);
|
|
86
|
+
};
|
|
87
|
+
}, [
|
|
88
|
+
q,
|
|
89
|
+
g,
|
|
90
|
+
G
|
|
91
|
+
]), d(() => {
|
|
92
|
+
if (g === void 0) return;
|
|
93
|
+
let e = !1;
|
|
94
|
+
return W.current = !1, g.load().then((t) => {
|
|
95
|
+
e || (W.current = !0, t.length > 0 && P((e) => e.prepend(t)), k((e) => e + 1));
|
|
96
|
+
}, () => {
|
|
97
|
+
e || (W.current = !0, k((e) => e + 1));
|
|
98
|
+
}), () => {
|
|
99
|
+
e = !0;
|
|
100
|
+
};
|
|
101
|
+
}, [
|
|
102
|
+
g,
|
|
103
|
+
P,
|
|
104
|
+
G
|
|
105
|
+
]), d(() => {
|
|
106
|
+
g !== void 0 && W.current && g.save(x(N)).catch(() => {});
|
|
107
|
+
}, [
|
|
108
|
+
g,
|
|
109
|
+
N,
|
|
110
|
+
O
|
|
111
|
+
]);
|
|
112
|
+
let J = p(/* @__PURE__ */ new Set()), Y = w === void 0 || n(w) ? void 0 : w.cache;
|
|
113
|
+
d(() => {
|
|
114
|
+
if (Y !== void 0 && w !== void 0) for (let e of N) {
|
|
115
|
+
let t = w.descriptors[e.tag]?.targets;
|
|
116
|
+
if (e.status === "pending" || e.status === "failed") {
|
|
117
|
+
if (J.current.delete(e.id), t === void 0 || t.length === 0 || Y.hasIntent(e.id) || typeof e.input != "object" || e.input === null) continue;
|
|
118
|
+
Y.autoApply(t, e.input, e.id, { standing: !0 });
|
|
119
|
+
} else J.current.has(e.id) || (J.current.add(e.id), e.status === "sent" ? Y.confirmByMutation(e.id) : Y.revertByMutation(e.id));
|
|
120
|
+
}
|
|
121
|
+
}, [
|
|
122
|
+
Y,
|
|
123
|
+
w,
|
|
124
|
+
N
|
|
125
|
+
]);
|
|
126
|
+
let te = l((e, t) => {
|
|
127
|
+
let n = v?.() ?? `obx_${U.current}_${H.current++}_${e}`;
|
|
128
|
+
P((r) => r.append({
|
|
129
|
+
id: n,
|
|
130
|
+
tag: e,
|
|
131
|
+
input: t,
|
|
132
|
+
status: "pending",
|
|
133
|
+
attempts: 0,
|
|
134
|
+
...I.current === void 0 ? {} : { stamp: I.current() }
|
|
135
|
+
})), k((e) => e + 1);
|
|
136
|
+
}, [v, P]), X = p(void 0), Z = l(() => {
|
|
137
|
+
X.current !== void 0 && clearTimeout(X.current), X.current = void 0;
|
|
138
|
+
}, []);
|
|
139
|
+
d(() => Z, [Z]);
|
|
140
|
+
let Q = l(() => {
|
|
141
|
+
if (!W.current || !V.current) return Promise.resolve();
|
|
142
|
+
if (z.current !== void 0) return z.current;
|
|
143
|
+
B.current = !1, Z();
|
|
144
|
+
let e = Promise.resolve().then(async () => {
|
|
145
|
+
for (; V.current;) {
|
|
146
|
+
let e = M.current.next();
|
|
147
|
+
if (e === void 0) break;
|
|
148
|
+
try {
|
|
149
|
+
if (await L.current(e), !V.current) break;
|
|
150
|
+
P((t) => t.update(e.id, (e) => ({
|
|
151
|
+
...e,
|
|
152
|
+
status: "sent"
|
|
153
|
+
})));
|
|
154
|
+
} catch (t) {
|
|
155
|
+
if (!V.current) break;
|
|
156
|
+
let n = R.current(t);
|
|
157
|
+
P((r) => r.update(e.id, (e) => n ? {
|
|
158
|
+
...e,
|
|
159
|
+
status: "conflict",
|
|
160
|
+
error: t
|
|
161
|
+
} : {
|
|
162
|
+
...e,
|
|
163
|
+
status: "failed",
|
|
164
|
+
error: t,
|
|
165
|
+
attempts: e.attempts + 1
|
|
166
|
+
})), B.current = !0, n || (X.current = setTimeout(() => {
|
|
167
|
+
X.current = void 0, $.current();
|
|
168
|
+
}, F.current(e.attempts + 1)));
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}).finally(() => {
|
|
173
|
+
z.current === e && (z.current = void 0);
|
|
174
|
+
});
|
|
175
|
+
return z.current = e, e;
|
|
176
|
+
}, [P, Z]), $ = p(Q);
|
|
177
|
+
$.current = Q, d(() => {
|
|
178
|
+
j ? Q() : Z();
|
|
179
|
+
}, [
|
|
180
|
+
j,
|
|
181
|
+
Q,
|
|
182
|
+
Z
|
|
183
|
+
]), d(() => {
|
|
184
|
+
j && !B.current && Q();
|
|
185
|
+
}, [
|
|
186
|
+
O,
|
|
187
|
+
j,
|
|
188
|
+
Q
|
|
189
|
+
]);
|
|
190
|
+
let ne = l((e, t) => {
|
|
191
|
+
P((n) => n.update(e, (e) => e.status === "conflict" ? {
|
|
192
|
+
...e,
|
|
193
|
+
input: t,
|
|
194
|
+
status: "pending",
|
|
195
|
+
error: void 0
|
|
196
|
+
} : e)), j && Q();
|
|
197
|
+
}, [
|
|
198
|
+
j,
|
|
199
|
+
Q,
|
|
200
|
+
P
|
|
201
|
+
]);
|
|
202
|
+
return {
|
|
203
|
+
queue: N,
|
|
204
|
+
enqueue: te,
|
|
205
|
+
replay: Q,
|
|
206
|
+
online: j,
|
|
207
|
+
pending: N.reduce((e, t) => e + +(t.status === "pending" || t.status === "failed"), 0),
|
|
208
|
+
conflicts: N.filter((e) => e.status === "conflict"),
|
|
209
|
+
resolveConflict: ne
|
|
210
|
+
};
|
|
211
|
+
};
|
|
212
|
+
//#endregion
|
|
213
|
+
export { x as clearSent, C as defaultOutboxRetryDelay, h as enqueueEntry, y as markConflict, v as markFailed, _ as markSent, S as replayable, b as resolveConflictEntry, w as useOutbox };
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { markConflict as e, markFailed as t, markSent as n, replayable as r } from "./outbox.js";
|
|
2
|
+
//#region src/outboxHttp.ts
|
|
3
|
+
var i = (e) => {
|
|
4
|
+
let t = e;
|
|
5
|
+
return t?.conflict === !0 || t?._tag === "UndoBoundaryError" && t?.boundary === "conflict";
|
|
6
|
+
}, a = (e) => {
|
|
7
|
+
let t = (Array.isArray(e) ? e : [e]).filter((e) => typeof e == "object" && !!e);
|
|
8
|
+
for (let e of t) {
|
|
9
|
+
if (e._tag === "Chunk") {
|
|
10
|
+
for (let t of e.values ?? []) if (t._tag === "error") return {
|
|
11
|
+
ok: !1,
|
|
12
|
+
error: t.error
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
if (e._tag === "Exit" && e.exit?._tag === "Failure") return {
|
|
16
|
+
ok: !1,
|
|
17
|
+
error: e.exit.cause
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
return { ok: !0 };
|
|
21
|
+
}, o = async (o) => {
|
|
22
|
+
let s = o.fetch ?? ((e, t) => fetch(e, t)), c = o.isConflict ?? i, l = o.queue, u = 0, d = 0, f = 0;
|
|
23
|
+
for (let i of r(o.queue)) {
|
|
24
|
+
let r;
|
|
25
|
+
try {
|
|
26
|
+
let e = await s(o.url, {
|
|
27
|
+
method: "POST",
|
|
28
|
+
headers: {
|
|
29
|
+
"content-type": "application/json",
|
|
30
|
+
...o.headers
|
|
31
|
+
},
|
|
32
|
+
body: JSON.stringify({
|
|
33
|
+
_tag: "Request",
|
|
34
|
+
id: i.id,
|
|
35
|
+
tag: i.tag,
|
|
36
|
+
payload: i.input,
|
|
37
|
+
headers: [["idempotency-key", i.id]]
|
|
38
|
+
})
|
|
39
|
+
});
|
|
40
|
+
r = e.ok ? a(await e.json().catch(() => null)) : {
|
|
41
|
+
ok: !1,
|
|
42
|
+
error: { status: e.status }
|
|
43
|
+
};
|
|
44
|
+
} catch (e) {
|
|
45
|
+
r = {
|
|
46
|
+
ok: !1,
|
|
47
|
+
error: e
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
if (r.ok) l = n(l, i.id), u++;
|
|
51
|
+
else if (c(r.error)) l = e(l, i.id, r.error), f++;
|
|
52
|
+
else {
|
|
53
|
+
l = t(l, i.id, r.error), d++;
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
queue: l,
|
|
59
|
+
sent: u,
|
|
60
|
+
failed: d,
|
|
61
|
+
conflicts: f
|
|
62
|
+
};
|
|
63
|
+
}, s = "voltro-outbox", c = "outbox", l = "queue", u = (e, t) => new Promise((n, r) => {
|
|
64
|
+
let i = e.open(t, 1);
|
|
65
|
+
i.onupgradeneeded = () => {
|
|
66
|
+
i.result.objectStoreNames.contains(c) || i.result.createObjectStore(c);
|
|
67
|
+
}, i.onsuccess = () => n(i.result), i.onerror = () => r(i.error ?? /* @__PURE__ */ Error("indexedDB open failed"));
|
|
68
|
+
}), d = (e) => new Promise((t, n) => {
|
|
69
|
+
e.onsuccess = () => t(e.result), e.onerror = () => n(e.error ?? /* @__PURE__ */ Error("indexedDB request failed"));
|
|
70
|
+
}), f = (e = {}) => {
|
|
71
|
+
let t = e.name ?? "voltro-outbox", n = () => {
|
|
72
|
+
let t = e.indexedDB ?? globalThis.indexedDB;
|
|
73
|
+
if (t === void 0) throw Error("indexedDbOutboxPersistence: no indexedDB in this environment");
|
|
74
|
+
return t;
|
|
75
|
+
};
|
|
76
|
+
return {
|
|
77
|
+
load: async () => {
|
|
78
|
+
let e = await u(n(), t);
|
|
79
|
+
try {
|
|
80
|
+
let t = await d(e.transaction(c, "readonly").objectStore(c).get(l));
|
|
81
|
+
return Array.isArray(t) ? t : [];
|
|
82
|
+
} finally {
|
|
83
|
+
e.close();
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
save: async (e) => {
|
|
87
|
+
let r = await u(n(), t);
|
|
88
|
+
try {
|
|
89
|
+
await d(r.transaction(c, "readwrite").objectStore(c).put(e, l));
|
|
90
|
+
} finally {
|
|
91
|
+
r.close();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}, p = "voltro:outbox", m = async (e) => {
|
|
96
|
+
let t = e.persistence ?? f(), n = await t.load(), r = await o({
|
|
97
|
+
url: e.url,
|
|
98
|
+
queue: n,
|
|
99
|
+
...e.headers ? { headers: e.headers } : {}
|
|
100
|
+
});
|
|
101
|
+
return r.sent + r.failed + r.conflicts > 0 && await t.save(r.queue), r;
|
|
102
|
+
};
|
|
103
|
+
//#endregion
|
|
104
|
+
export { s as OUTBOX_DB_NAME, p as OUTBOX_SYNC_TAG, m as drainOutboxInWorker, o as drainOutboxOverHttp, f as indexedDbOutboxPersistence, a as rpcHttpOutcome };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
//#region src/outboxState.ts
|
|
2
|
+
var e = class {
|
|
3
|
+
entries = [];
|
|
4
|
+
positions = /* @__PURE__ */ new Map();
|
|
5
|
+
cursor = 0;
|
|
6
|
+
cached;
|
|
7
|
+
snapshot() {
|
|
8
|
+
return this.cached ??= [...this.entries];
|
|
9
|
+
}
|
|
10
|
+
append(e) {
|
|
11
|
+
let t = this.entries.length;
|
|
12
|
+
this.entries.push(e);
|
|
13
|
+
let n = this.positions.get(e.id);
|
|
14
|
+
n === void 0 ? this.positions.set(e.id, [t]) : n.push(t), this.cached = void 0;
|
|
15
|
+
}
|
|
16
|
+
prepend(e) {
|
|
17
|
+
this.entries = [...e, ...this.entries], this.positions.clear();
|
|
18
|
+
for (let e = 0; e < this.entries.length; e++) {
|
|
19
|
+
let t = this.entries[e].id, n = this.positions.get(t);
|
|
20
|
+
n === void 0 ? this.positions.set(t, [e]) : n.push(e);
|
|
21
|
+
}
|
|
22
|
+
this.cursor = 0, this.cached = void 0;
|
|
23
|
+
}
|
|
24
|
+
reset() {
|
|
25
|
+
this.entries = [], this.positions.clear(), this.cursor = 0, this.cached = void 0;
|
|
26
|
+
}
|
|
27
|
+
update(e, t) {
|
|
28
|
+
for (let n of this.positions.get(e) ?? []) {
|
|
29
|
+
let e = this.entries[n], r = t(e);
|
|
30
|
+
e !== r && (this.entries[n] = r, r.status !== "sent" && n < this.cursor && (this.cursor = n), this.cached = void 0);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
next() {
|
|
34
|
+
for (; this.cursor < this.entries.length;) {
|
|
35
|
+
let e = this.entries[this.cursor];
|
|
36
|
+
if (e.status === "conflict") return;
|
|
37
|
+
if (e.status !== "sent") return e;
|
|
38
|
+
this.cursor++;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
//#endregion
|
|
43
|
+
export { e as OutboxState };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { scopeMembership as e } from "./scopeMembership.js";
|
|
2
|
+
import { createContext as t, createElement as n, useContext as r } from "react";
|
|
3
|
+
//#region src/permissions.tsx
|
|
4
|
+
var i = "admin:full", a = (e, t) => e.includes("admin:full") ? !0 : typeof t == "string" ? e.includes(t) : t.every((t) => e.includes(t)), o = (e, t) => t.length === 0 || e.includes("admin:full") ? !0 : t.some((t) => e.includes(t)), s = t({ scopes: [] });
|
|
5
|
+
function c(t) {
|
|
6
|
+
let r = e(t.scopes), i = r === void 0 ? { scopes: t.scopes } : {
|
|
7
|
+
scopes: t.scopes,
|
|
8
|
+
membership: r
|
|
9
|
+
};
|
|
10
|
+
return n(s.Provider, { value: i }, t.children);
|
|
11
|
+
}
|
|
12
|
+
var l = () => r(s), u = (e) => {
|
|
13
|
+
let t = r(s);
|
|
14
|
+
return t.membership === void 0 ? a(t.scopes, e) : t.membership.has("admin:full") ? !0 : typeof e == "string" ? t.membership.has(e) : e.every((e) => t.membership.has(e));
|
|
15
|
+
}, d = (e) => {
|
|
16
|
+
let t = r(s);
|
|
17
|
+
return t.membership === void 0 ? o(t.scopes, e) : e.length === 0 || t.membership.has("admin:full") || e.some((e) => t.membership.has(e));
|
|
18
|
+
};
|
|
19
|
+
//#endregion
|
|
20
|
+
export { i as ADMIN_SCOPE, c as PermissionProvider, a as canCall, o as canCallAny, u as useCan, d as useCanAny, l as usePermissions };
|