@voltro/client 0.85.0 → 0.87.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 +5987 -0
- package/THIRD-PARTY-NOTICES.md +1125 -34
- package/dist/analyticsCatalog.js +47 -0
- package/dist/apiConnectivity.js +33 -0
- package/dist/apiRoleTransports.js +48 -0
- package/dist/apiRuntime.js +145 -0
- package/dist/apiSocketTracker.js +21 -0
- package/dist/apiSupervisor.js +136 -0
- package/dist/authRefresh.js +20 -0
- package/dist/awaitResolvedApi.js +23 -0
- package/dist/bootstrap.d.ts +1153 -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 +47 -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 +37 -4
- package/dist/form.js +7 -2
- package/dist/formBinding.js +325 -0
- package/dist/formData.js +127 -0
- package/dist/formFlashId.js +4 -0
- package/dist/formRejection.js +23 -0
- package/dist/formSource.js +13 -0
- package/dist/frameworkRuntimesContext.js +8 -0
- package/dist/globalContext.js +10 -0
- package/dist/index.d.ts +152 -27
- package/dist/index.js +87 -4121
- 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 +49 -3
- package/dist/runtime.js +16 -126
- 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 +28 -0
- package/dist/serviceClient.js +129 -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 +105 -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 +98 -0
- package/dist/useFormBinding.js +478 -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/useRpcCaller.js +17 -0
- package/dist/useSequence.js +25 -0
- package/dist/useSkeleton.js +13 -0
- package/dist/useSubscription.js +98 -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 +7 -2
- package/dist/authRefresh-DmfSoCca.js +0 -360
- package/dist/formData-BfpBt7BQ.js +0 -769
- package/dist/queryOnce-D5Y4V1SB.js +0 -55
- package/dist/runRpc-Zfz3w709.js +0 -1172
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { useAction as e } from "./useAction.js";
|
|
2
|
+
import { useUpload as t } from "./useUpload.js";
|
|
3
|
+
import { useCallback as n, useMemo as r, useRef as i, useState as a } from "react";
|
|
4
|
+
//#region src/useTranscription.ts
|
|
5
|
+
var o = (o, s) => {
|
|
6
|
+
let c = t(o), l = e(o, s.action), [u, d] = a("idle"), [f, p] = a(void 0), [m, h] = a(void 0), g = i(s.extra);
|
|
7
|
+
g.current = s.extra;
|
|
8
|
+
let _ = n(async (e) => {
|
|
9
|
+
h(void 0), p(void 0), d("uploading");
|
|
10
|
+
let t;
|
|
11
|
+
try {
|
|
12
|
+
t = await c.upload(e);
|
|
13
|
+
} catch (e) {
|
|
14
|
+
throw d("error"), h(e), e;
|
|
15
|
+
}
|
|
16
|
+
d("transcribing");
|
|
17
|
+
try {
|
|
18
|
+
let e = await l.run({
|
|
19
|
+
storageRef: t.id,
|
|
20
|
+
...g.current ?? {}
|
|
21
|
+
});
|
|
22
|
+
return p(e), d("done"), e;
|
|
23
|
+
} catch (e) {
|
|
24
|
+
throw d("error"), h(e), e;
|
|
25
|
+
}
|
|
26
|
+
}, [c, l]), v = n(() => {
|
|
27
|
+
c.cancel(), d("idle");
|
|
28
|
+
}, [c]), y = n(() => {
|
|
29
|
+
c.reset(), d("idle"), p(void 0), h(void 0);
|
|
30
|
+
}, [c]);
|
|
31
|
+
return r(() => ({
|
|
32
|
+
phase: u,
|
|
33
|
+
progress: u === "uploading" ? c.progress : void 0,
|
|
34
|
+
result: f,
|
|
35
|
+
error: m ?? c.error,
|
|
36
|
+
transcribe: _,
|
|
37
|
+
cancel: v,
|
|
38
|
+
reset: y
|
|
39
|
+
}), [
|
|
40
|
+
u,
|
|
41
|
+
c.progress,
|
|
42
|
+
c.error,
|
|
43
|
+
f,
|
|
44
|
+
m,
|
|
45
|
+
_,
|
|
46
|
+
v,
|
|
47
|
+
y
|
|
48
|
+
]);
|
|
49
|
+
};
|
|
50
|
+
//#endregion
|
|
51
|
+
export { o as useTranscription };
|
package/dist/useUndo.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { useCallback as e, useMemo as t, useState as n } from "react";
|
|
2
|
+
//#region src/useUndo.ts
|
|
3
|
+
var r = (r) => {
|
|
4
|
+
let [i, a] = n([]), [o, s] = n([]), c = e((e) => {
|
|
5
|
+
a((t) => [...t, e]), s([]);
|
|
6
|
+
}, []), l = e(async () => {
|
|
7
|
+
let e = i[i.length - 1];
|
|
8
|
+
e !== void 0 && e.blockedBy === void 0 && (await r.onUndo(e.invocationId), a((e) => e.slice(0, -1)), s((t) => [...t, e]));
|
|
9
|
+
}, [i, r]), u = e(async () => {
|
|
10
|
+
let e = o[o.length - 1];
|
|
11
|
+
e !== void 0 && (await r.onRedo(e.invocationId), s((e) => e.slice(0, -1)), a((t) => [...t, e]));
|
|
12
|
+
}, [o, r]);
|
|
13
|
+
return t(() => {
|
|
14
|
+
let e = i[i.length - 1];
|
|
15
|
+
return {
|
|
16
|
+
record: c,
|
|
17
|
+
undo: l,
|
|
18
|
+
redo: u,
|
|
19
|
+
canUndo: i.length > 0 && e?.blockedBy === void 0,
|
|
20
|
+
canRedo: o.length > 0,
|
|
21
|
+
stack: i,
|
|
22
|
+
nextBlockedBy: e?.blockedBy
|
|
23
|
+
};
|
|
24
|
+
}, [
|
|
25
|
+
i,
|
|
26
|
+
o,
|
|
27
|
+
c,
|
|
28
|
+
l,
|
|
29
|
+
u
|
|
30
|
+
]);
|
|
31
|
+
};
|
|
32
|
+
//#endregion
|
|
33
|
+
export { r as useUndo };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { useSubscription as e } from "./useSubscription.js";
|
|
2
|
+
import { useMutation as t } from "./useMutation.js";
|
|
3
|
+
import { useCallback as n, useMemo as r } from "react";
|
|
4
|
+
//#region src/useUndoLog.ts
|
|
5
|
+
var i = "__voltro.undo.log", a = "__voltro.undo.apply", o = "__voltro.undo.redo", s = (e) => {
|
|
6
|
+
if (e.length < 32 || Object.getPrototypeOf(e) !== Array.prototype || Object.hasOwn(e, "find")) return;
|
|
7
|
+
let t, n;
|
|
8
|
+
for (let r = 0; r < e.length; r += 1) {
|
|
9
|
+
let i = Object.getOwnPropertyDescriptor(e, String(r)), a = i !== void 0 && "value" in i ? i.value : void 0;
|
|
10
|
+
if (typeof a != "object" || !a) return;
|
|
11
|
+
let o = Object.getOwnPropertyDescriptor(a, "undone"), s = Object.getOwnPropertyDescriptor(a, "crossesAction");
|
|
12
|
+
if (o === void 0 || !("value" in o) || typeof o.value != "boolean" || s === void 0 || !("value" in s) || typeof s.value != "boolean") return;
|
|
13
|
+
if (!o.value && !s.value && (t ??= a), o.value && (n ??= a), t !== void 0 && n !== void 0) return r < 32 ? void 0 : {
|
|
14
|
+
nextUndo: t,
|
|
15
|
+
nextRedo: n
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
nextUndo: t,
|
|
20
|
+
nextRedo: n
|
|
21
|
+
};
|
|
22
|
+
}, c = (c, l) => {
|
|
23
|
+
let u = l?.limit, { data: d } = e(c, i, u === void 0 ? {} : { limit: u }), f = t(c, a), p = t(c, o), m = d ?? [], h = r(() => s(m), [m]), g = h === void 0 ? m.find((e) => !e.undone && !e.crossesAction) : h.nextUndo, _ = h === void 0 ? m.find((e) => e.undone) : h.nextRedo, v = n(async (e) => {
|
|
24
|
+
await f.mutate({ invocationId: e });
|
|
25
|
+
}, [f]), y = n(async (e) => {
|
|
26
|
+
await p.mutate({ invocationId: e });
|
|
27
|
+
}, [p]), b = n(async () => {
|
|
28
|
+
g && await v(g.id);
|
|
29
|
+
}, [g, v]), x = n(async () => {
|
|
30
|
+
_ && await y(_.id);
|
|
31
|
+
}, [_, y]);
|
|
32
|
+
return {
|
|
33
|
+
entries: m,
|
|
34
|
+
loading: d === void 0,
|
|
35
|
+
canUndo: g !== void 0,
|
|
36
|
+
canRedo: _ !== void 0,
|
|
37
|
+
undo: v,
|
|
38
|
+
redo: y,
|
|
39
|
+
undoLast: b,
|
|
40
|
+
redoLast: x
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
//#endregion
|
|
44
|
+
export { a as UNDO_APPLY_TAG, i as UNDO_LOG_TAG, o as UNDO_REDO_TAG, c as useUndoLog };
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import { rememberRpcErrorKind as e, rpcErrorKind as t } from "./rpcErrorKind.js";
|
|
2
|
+
import { useFrameworkApi as n } from "./runtimeContext.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 { createUploadProgress as o } from "./uploadProgress.js";
|
|
7
|
+
import { useCallback as s, useMemo as c, useRef as l, useState as u } from "react";
|
|
8
|
+
import { pluginTag as d } from "@voltro/protocol";
|
|
9
|
+
//#region src/useUpload.ts
|
|
10
|
+
var f = "@voltro/plugin-storage", p = (e) => d(f, e), m = (e, t, n, r) => new Promise((i, a) => {
|
|
11
|
+
let o = new XMLHttpRequest();
|
|
12
|
+
o.open("PUT", e), o.upload.onprogress = (e) => {
|
|
13
|
+
e.lengthComputable && n(e.loaded / e.total);
|
|
14
|
+
}, o.onload = () => {
|
|
15
|
+
if (o.status >= 200 && o.status < 300) {
|
|
16
|
+
let e = o.getResponseHeader("ETag") ?? o.getResponseHeader("etag");
|
|
17
|
+
e ? i(e) : a(/* @__PURE__ */ Error("multipart part: response carried no ETag (the bucket CORS must expose the ETag header)"));
|
|
18
|
+
} else a(Error(`multipart part failed (${o.status}): ${o.responseText || o.statusText}`.trim()));
|
|
19
|
+
}, o.onerror = () => a(/* @__PURE__ */ Error("multipart part: network error")), o.onabort = () => a(new DOMException("upload aborted", "AbortError")), r.aborted ? o.abort() : (r.addEventListener("abort", () => o.abort(), { once: !0 }), o.send(t));
|
|
20
|
+
}), h = (e, t, n, r, i, a) => new Promise((o, s) => {
|
|
21
|
+
let c = new XMLHttpRequest();
|
|
22
|
+
c.open("POST", e), c.setRequestHeader("content-type", t), c.upload.onprogress = (e) => {
|
|
23
|
+
e.lengthComputable && r(e.loaded / e.total);
|
|
24
|
+
}, c.onload = () => {
|
|
25
|
+
if (c.status >= 200 && c.status < 300) {
|
|
26
|
+
if (!a) return o(null);
|
|
27
|
+
try {
|
|
28
|
+
o(JSON.parse(c.responseText));
|
|
29
|
+
} catch {
|
|
30
|
+
s(/* @__PURE__ */ Error("resumable upload: malformed final response"));
|
|
31
|
+
}
|
|
32
|
+
} else s(Error(`resumable chunk failed (${c.status}): ${c.responseText || c.statusText}`.trim()));
|
|
33
|
+
}, c.onerror = () => s(/* @__PURE__ */ Error("resumable chunk: network error")), c.onabort = () => s(new DOMException("upload aborted", "AbortError")), i.aborted ? c.abort() : (i.addEventListener("abort", () => c.abort(), { once: !0 }), c.send(n));
|
|
34
|
+
}), g = (e, t, n, r, i) => new Promise((a, o) => {
|
|
35
|
+
let s = new XMLHttpRequest();
|
|
36
|
+
s.open("PUT", e), s.setRequestHeader("content-type", t), s.upload.onprogress = (e) => {
|
|
37
|
+
e.lengthComputable && r(e.loaded / e.total);
|
|
38
|
+
}, s.onload = () => {
|
|
39
|
+
s.status >= 200 && s.status < 300 ? a() : o(Error(`direct upload failed (${s.status}): ${s.responseText || s.statusText}`.trim()));
|
|
40
|
+
}, s.onerror = () => o(/* @__PURE__ */ Error("direct upload: network error")), s.onabort = () => o(new DOMException("upload aborted", "AbortError")), i.aborted ? s.abort() : (i.addEventListener("abort", () => s.abort(), { once: !0 }), s.send(n));
|
|
41
|
+
}), _ = (e, t, n, r, i) => new Promise((a, o) => {
|
|
42
|
+
let s = new XMLHttpRequest();
|
|
43
|
+
s.open("POST", e), s.setRequestHeader("content-type", t), s.upload.onprogress = (e) => {
|
|
44
|
+
e.lengthComputable && r(e.loaded / e.total);
|
|
45
|
+
}, s.onload = () => {
|
|
46
|
+
if (s.status >= 200 && s.status < 300) try {
|
|
47
|
+
a(JSON.parse(s.responseText));
|
|
48
|
+
} catch {
|
|
49
|
+
o(/* @__PURE__ */ Error("storage upload: malformed response"));
|
|
50
|
+
}
|
|
51
|
+
else o(Error(`storage upload failed (${s.status}): ${s.responseText || s.statusText}`.trim()));
|
|
52
|
+
}, s.onerror = () => o(/* @__PURE__ */ Error("storage upload: network error")), s.onabort = () => o(new DOMException("upload aborted", "AbortError")), i.aborted ? s.abort() : (i.addEventListener("abort", () => s.abort(), { once: !0 }), s.send(n));
|
|
53
|
+
}), v = (d, f = {}) => {
|
|
54
|
+
let v = n(d), { inspectBaseUrl: y } = v, b = l(v);
|
|
55
|
+
b.current = v;
|
|
56
|
+
let [x, S] = u(0), [C, w] = u("idle"), [T, E] = u(void 0), D = l(null), O = s(() => {
|
|
57
|
+
S(0), w("idle"), E(void 0);
|
|
58
|
+
}, []), k = s(() => {
|
|
59
|
+
D.current?.abort();
|
|
60
|
+
}, []), A = s((e) => /^https?:\/\//.test(e) ? e : `${y}${e}`, [y]), j = s(async (t, n, o, s) => {
|
|
61
|
+
let { runtime: c, client: l } = await a(b, d, "storage.upload").catch((t) => {
|
|
62
|
+
throw e(t, "client");
|
|
63
|
+
}), u = Math.max(0, n.retries ?? f.retries ?? 1), v = (t instanceof File, t.type || "application/octet-stream"), y = t instanceof File ? t.name : "blob", x = n.visibility ?? f.visibility, S = n.access ?? f.access, C = n.key ?? f.key, w = n.folder ?? f.folder, T = n.tags ?? f.tags, E = {
|
|
64
|
+
...x ? { visibility: x } : {},
|
|
65
|
+
...S === void 0 ? {} : { access: S },
|
|
66
|
+
...w ? { folder: w } : {},
|
|
67
|
+
...T ? { tags: T } : {},
|
|
68
|
+
...n.alt ? { alt: n.alt } : {},
|
|
69
|
+
...n.caption ? { caption: n.caption } : {}
|
|
70
|
+
}, D = (e) => ({
|
|
71
|
+
id: e.id,
|
|
72
|
+
url: A(e.url),
|
|
73
|
+
name: y,
|
|
74
|
+
mime: e.contentType,
|
|
75
|
+
size: e.size,
|
|
76
|
+
...e.width === void 0 ? {} : { width: e.width },
|
|
77
|
+
...e.height === void 0 ? {} : { height: e.height }
|
|
78
|
+
}), O = n.operationId ?? f.operationId, k = async () => {
|
|
79
|
+
let e = n.mintTag ?? f.mintTag ?? p("mintUploadTicket"), a = r(l, e), u = await i(c, a({
|
|
80
|
+
contentType: v,
|
|
81
|
+
...E,
|
|
82
|
+
...C ? { key: C } : {},
|
|
83
|
+
...O === void 0 ? {} : { operationId: O }
|
|
84
|
+
}));
|
|
85
|
+
O = u.operationId ?? O;
|
|
86
|
+
let d = await _(A(u.uploadUrl), v, t, s, o);
|
|
87
|
+
return D(d);
|
|
88
|
+
}, j = async () => {
|
|
89
|
+
let e = n.presignMintTag ?? f.presignMintTag ?? p("mintPresignedUpload"), a = n.finalizeTag ?? f.finalizeTag ?? p("finalizeUpload"), u;
|
|
90
|
+
try {
|
|
91
|
+
let t = r(l, e);
|
|
92
|
+
u = await i(c, t({
|
|
93
|
+
contentType: v,
|
|
94
|
+
...E
|
|
95
|
+
}));
|
|
96
|
+
} catch {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
await g(u.uploadUrl, v, t, s, o);
|
|
100
|
+
let d = r(l, a), m = await i(c, d({ finalizeToken: u.finalizeToken }));
|
|
101
|
+
return D(m);
|
|
102
|
+
}, M = async () => {
|
|
103
|
+
let e = n.beginResumableTag ?? f.beginResumableTag ?? p("beginResumableUpload"), a = r(l, e), u = t.size, d = n.chunkSize ?? f.chunkSize, m = await i(c, a({
|
|
104
|
+
contentType: v,
|
|
105
|
+
size: u,
|
|
106
|
+
...E,
|
|
107
|
+
...d ? { chunkSize: d } : {}
|
|
108
|
+
})), g = A(m.uploadUrl), _ = Math.max(1, m.chunkSize), y = Math.max(1, Math.ceil(u / _)), b = Math.max(0, n.retries ?? f.retries ?? 1), x = 0, S = null;
|
|
109
|
+
for (let e = 0; e < y; e++) {
|
|
110
|
+
let n = e * _, r = Math.min(u, n + _), i = t.slice(n, r), a = e === y - 1, c = r - n, l = 0;
|
|
111
|
+
for (;;) {
|
|
112
|
+
if (o.aborted) throw new DOMException("upload aborted", "AbortError");
|
|
113
|
+
try {
|
|
114
|
+
let t = await h(`${g}?${`token=${encodeURIComponent(m.resumableToken)}&index=${e}${a ? "&final=1" : ""}`}`, v, i, (e) => s((x + e * c) / u), o, a);
|
|
115
|
+
a && (S = t);
|
|
116
|
+
break;
|
|
117
|
+
} catch (e) {
|
|
118
|
+
if (e instanceof DOMException && e.name === "AbortError" || l++ >= b) throw e;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
x += c, s(x / u);
|
|
122
|
+
}
|
|
123
|
+
if (!S) throw Error("resumable upload produced no final reply");
|
|
124
|
+
return D(S);
|
|
125
|
+
}, N = async () => {
|
|
126
|
+
let e = n.multipartBeginTag ?? f.multipartBeginTag ?? p("beginMultipartUpload"), a = n.multipartSignTag ?? f.multipartSignTag ?? p("signMultipartPart"), u = n.multipartCompleteTag ?? f.multipartCompleteTag ?? p("completeMultipartUpload"), d = n.multipartAbortTag ?? f.multipartAbortTag ?? p("abortMultipartUpload"), h = t.size, g = n.chunkSize ?? f.chunkSize, _;
|
|
127
|
+
try {
|
|
128
|
+
let t = r(l, e);
|
|
129
|
+
_ = await i(c, t({
|
|
130
|
+
contentType: v,
|
|
131
|
+
size: h,
|
|
132
|
+
...E,
|
|
133
|
+
...g ? { partSize: g } : {}
|
|
134
|
+
}));
|
|
135
|
+
} catch {
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
let b = r(l, a), x = r(l, u), S = r(l, d), C = Math.max(1, _.partSize), w = Math.max(1, Math.ceil(h / C)), T = Math.max(0, n.retries ?? f.retries ?? 1), D = [], O = 0;
|
|
139
|
+
try {
|
|
140
|
+
for (let e = 0; e < w; e++) {
|
|
141
|
+
let n = e * C, r = Math.min(h, n + C), a = t.slice(n, r), l = e + 1, u = r - n, d = 0;
|
|
142
|
+
for (;;) {
|
|
143
|
+
if (o.aborted) throw new DOMException("upload aborted", "AbortError");
|
|
144
|
+
try {
|
|
145
|
+
let { url: e } = await i(c, b({
|
|
146
|
+
multipartToken: _.multipartToken,
|
|
147
|
+
partNumber: l
|
|
148
|
+
})), t = await m(e, a, (e) => s((O + e * u) / h), o);
|
|
149
|
+
D.push({
|
|
150
|
+
partNumber: l,
|
|
151
|
+
etag: t
|
|
152
|
+
});
|
|
153
|
+
break;
|
|
154
|
+
} catch (e) {
|
|
155
|
+
if (e instanceof DOMException && e.name === "AbortError" || d++ >= T) throw e;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
O += u, s(O / h);
|
|
159
|
+
}
|
|
160
|
+
let e = await i(c, x({
|
|
161
|
+
multipartToken: _.multipartToken,
|
|
162
|
+
parts: D
|
|
163
|
+
}));
|
|
164
|
+
return {
|
|
165
|
+
id: e.id,
|
|
166
|
+
url: A(e.url),
|
|
167
|
+
name: y,
|
|
168
|
+
mime: v,
|
|
169
|
+
size: e.size
|
|
170
|
+
};
|
|
171
|
+
} catch (e) {
|
|
172
|
+
try {
|
|
173
|
+
await i(c, S({ multipartToken: _.multipartToken }));
|
|
174
|
+
} catch {}
|
|
175
|
+
throw e;
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
if ((n.prefer ?? f.prefer) === "multipart") return await N() || await M();
|
|
179
|
+
if ((n.prefer ?? f.prefer) === "resumable") return await M();
|
|
180
|
+
let P = (n.prefer ?? f.prefer) === "presign", F;
|
|
181
|
+
for (let e = 0; e <= u; e++) {
|
|
182
|
+
if (o.aborted) throw new DOMException("upload aborted", "AbortError");
|
|
183
|
+
try {
|
|
184
|
+
if (P) {
|
|
185
|
+
let e = await j();
|
|
186
|
+
if (e) return e;
|
|
187
|
+
}
|
|
188
|
+
return await k();
|
|
189
|
+
} catch (t) {
|
|
190
|
+
if (t instanceof DOMException && t.name === "AbortError" || (F = t, e === u)) throw t;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
throw F;
|
|
194
|
+
}, [
|
|
195
|
+
d,
|
|
196
|
+
A,
|
|
197
|
+
f.operationId,
|
|
198
|
+
f.mintTag,
|
|
199
|
+
f.presignMintTag,
|
|
200
|
+
f.finalizeTag,
|
|
201
|
+
f.beginResumableTag,
|
|
202
|
+
f.multipartBeginTag,
|
|
203
|
+
f.multipartSignTag,
|
|
204
|
+
f.multipartCompleteTag,
|
|
205
|
+
f.multipartAbortTag,
|
|
206
|
+
f.chunkSize,
|
|
207
|
+
f.prefer,
|
|
208
|
+
f.visibility,
|
|
209
|
+
f.key,
|
|
210
|
+
f.folder,
|
|
211
|
+
f.tags,
|
|
212
|
+
f.retries
|
|
213
|
+
]), M = s(async (e, n = {}) => {
|
|
214
|
+
let r = new AbortController();
|
|
215
|
+
D.current = r, w("uploading"), E(void 0), S(0);
|
|
216
|
+
try {
|
|
217
|
+
let t = await j(e, n, r.signal, S);
|
|
218
|
+
return S(1), w("success"), t;
|
|
219
|
+
} catch (e) {
|
|
220
|
+
throw w("error"), E(e), e instanceof DOMException && e.name === "AbortError" || b.current.errorBus.emit({
|
|
221
|
+
source: "action",
|
|
222
|
+
tag: n.mintTag ?? f.mintTag ?? p("mintUploadTicket"),
|
|
223
|
+
error: e,
|
|
224
|
+
kind: t(e, "unknown"),
|
|
225
|
+
outcome: t(e, "unknown") === "transport" ? "unknown" : "not-applicable"
|
|
226
|
+
}), e;
|
|
227
|
+
}
|
|
228
|
+
}, [j, f.mintTag]), N = s(async (e, n = {}) => {
|
|
229
|
+
if (e.length === 0) return [];
|
|
230
|
+
if (e.length > 1 && (n.operationId ?? f.operationId) !== void 0) throw Error("useUpload: one operationId identifies one file; upload files with separate operation identities.");
|
|
231
|
+
let r = new AbortController();
|
|
232
|
+
D.current = r, w("uploading"), E(void 0), S(0);
|
|
233
|
+
let i = Math.max(1, n.concurrency ?? f.concurrency ?? 3), a = Array(e.length), s = o(e.length), c = 0, l = async () => {
|
|
234
|
+
for (;;) {
|
|
235
|
+
let t = c++;
|
|
236
|
+
if (t >= e.length) return;
|
|
237
|
+
a[t] = await j(e[t], n, r.signal, (n) => {
|
|
238
|
+
S(s(t, n, e.length));
|
|
239
|
+
}), S(s(t, 1, e.length));
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
try {
|
|
243
|
+
return await Promise.all(Array.from({ length: Math.min(i, e.length) }, () => l())), S(1), w("success"), a;
|
|
244
|
+
} catch (e) {
|
|
245
|
+
throw r.abort(), w("error"), E(e), e instanceof DOMException && e.name === "AbortError" || b.current.errorBus.emit({
|
|
246
|
+
source: "action",
|
|
247
|
+
tag: n.mintTag ?? f.mintTag ?? p("mintUploadTicket"),
|
|
248
|
+
error: e,
|
|
249
|
+
kind: t(e, "unknown"),
|
|
250
|
+
outcome: t(e, "unknown") === "transport" ? "unknown" : "not-applicable"
|
|
251
|
+
}), e;
|
|
252
|
+
}
|
|
253
|
+
}, [
|
|
254
|
+
j,
|
|
255
|
+
f.concurrency,
|
|
256
|
+
f.mintTag,
|
|
257
|
+
f.operationId
|
|
258
|
+
]), P = s((e, t = {}) => {
|
|
259
|
+
e.preventDefault();
|
|
260
|
+
let n = e.dataTransfer ? Array.from(e.dataTransfer.files) : [];
|
|
261
|
+
return n.length ? N(n, t) : Promise.resolve([]);
|
|
262
|
+
}, [N]), F = s((e, t = {}) => {
|
|
263
|
+
let n = e.clipboardData ? Array.from(e.clipboardData.files) : [];
|
|
264
|
+
return n.length ? N(n, t) : Promise.resolve([]);
|
|
265
|
+
}, [N]), I = c(() => ({
|
|
266
|
+
onDragOver: (e) => e.preventDefault(),
|
|
267
|
+
onDrop: (e) => {
|
|
268
|
+
P(e);
|
|
269
|
+
}
|
|
270
|
+
}), [P]);
|
|
271
|
+
return c(() => ({
|
|
272
|
+
upload: M,
|
|
273
|
+
uploadMany: N,
|
|
274
|
+
progress: x,
|
|
275
|
+
status: C,
|
|
276
|
+
error: T,
|
|
277
|
+
cancel: k,
|
|
278
|
+
reset: O,
|
|
279
|
+
onDrop: P,
|
|
280
|
+
onPaste: F,
|
|
281
|
+
dropzoneProps: I
|
|
282
|
+
}), [
|
|
283
|
+
M,
|
|
284
|
+
N,
|
|
285
|
+
x,
|
|
286
|
+
C,
|
|
287
|
+
T,
|
|
288
|
+
k,
|
|
289
|
+
O,
|
|
290
|
+
P,
|
|
291
|
+
F,
|
|
292
|
+
I
|
|
293
|
+
]);
|
|
294
|
+
};
|
|
295
|
+
//#endregion
|
|
296
|
+
export { v as useUpload };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { useSubscription as e } from "./useSubscription.js";
|
|
2
|
+
import { useCallback as t, useMemo as n, useRef as r, useState as i } from "react";
|
|
3
|
+
//#region src/useWindowedSubscription.ts
|
|
4
|
+
var a = (e) => {
|
|
5
|
+
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);
|
|
6
|
+
return {
|
|
7
|
+
startIndex: l,
|
|
8
|
+
endIndex: d,
|
|
9
|
+
offset: l,
|
|
10
|
+
limit: Math.max(0, d - l),
|
|
11
|
+
topSpacer: l * r,
|
|
12
|
+
bottomSpacer: a === void 0 ? 0 : Math.max(0, (a - d) * r)
|
|
13
|
+
};
|
|
14
|
+
}, o = (o, s, c) => {
|
|
15
|
+
let { rowHeight: l, viewportHeight: u, overscan: d, total: f, input: p } = c, [m, h] = i(0), g = r(0), _ = n(() => a({
|
|
16
|
+
scrollTop: g.current,
|
|
17
|
+
viewportHeight: u,
|
|
18
|
+
rowHeight: l,
|
|
19
|
+
...d === void 0 ? {} : { overscan: d },
|
|
20
|
+
...f === void 0 ? {} : { total: f }
|
|
21
|
+
}), [
|
|
22
|
+
m,
|
|
23
|
+
u,
|
|
24
|
+
l,
|
|
25
|
+
d,
|
|
26
|
+
f
|
|
27
|
+
]), v = n(() => ({
|
|
28
|
+
...p,
|
|
29
|
+
offset: _.offset,
|
|
30
|
+
limit: _.limit
|
|
31
|
+
}), [
|
|
32
|
+
p,
|
|
33
|
+
_.offset,
|
|
34
|
+
_.limit
|
|
35
|
+
]), y = e(o, s, v), b = r(_);
|
|
36
|
+
b.current = _;
|
|
37
|
+
let x = t((e) => {
|
|
38
|
+
let t = e.currentTarget.scrollTop;
|
|
39
|
+
g.current = t;
|
|
40
|
+
let n = a({
|
|
41
|
+
scrollTop: t,
|
|
42
|
+
viewportHeight: u,
|
|
43
|
+
rowHeight: l,
|
|
44
|
+
...d === void 0 ? {} : { overscan: d },
|
|
45
|
+
...f === void 0 ? {} : { total: f }
|
|
46
|
+
}), r = b.current;
|
|
47
|
+
(n.offset !== r.offset || n.limit !== r.limit || n.topSpacer !== r.topSpacer || n.bottomSpacer !== r.bottomSpacer) && (b.current = n, h(t));
|
|
48
|
+
}, [
|
|
49
|
+
u,
|
|
50
|
+
l,
|
|
51
|
+
d,
|
|
52
|
+
f
|
|
53
|
+
]);
|
|
54
|
+
return {
|
|
55
|
+
rows: y.data ?? [],
|
|
56
|
+
window: _,
|
|
57
|
+
onScroll: x,
|
|
58
|
+
topSpacer: _.topSpacer,
|
|
59
|
+
bottomSpacer: _.bottomSpacer,
|
|
60
|
+
loading: y.data === void 0,
|
|
61
|
+
error: y.error
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
//#endregion
|
|
65
|
+
export { a as computeWindow, o as useWindowedSubscription };
|