@voltro/client 0.86.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 +5321 -0
- package/THIRD-PARTY-NOTICES.md +1132 -13
- package/dist/apiRoleTransports.js +48 -0
- package/dist/apiRuntime.js +75 -65
- package/dist/apiSocketTracker.js +21 -0
- package/dist/apiSupervisor.js +16 -5
- package/dist/awaitResolvedApi.js +4 -4
- package/dist/bootstrap.d.ts +9 -0
- package/dist/bootstrap.js +3 -3
- package/dist/connectionScope.js +14 -2
- package/dist/form.d.ts +37 -4
- package/dist/form.js +4 -2
- package/dist/formData.js +72 -10
- package/dist/formRejection.js +23 -0
- package/dist/formSource.js +13 -0
- package/dist/index.d.ts +99 -20
- package/dist/index.js +56 -52
- package/dist/runtime.d.ts +17 -2
- package/dist/serverRequest.js +11 -7
- package/dist/serviceClient.js +49 -48
- package/dist/subscriptionCache.js +4 -4
- package/dist/useCapabilityManifest.js +27 -23
- package/dist/useEvent.js +77 -67
- package/dist/useFormBinding.js +225 -223
- package/dist/useRpcCaller.js +17 -0
- package/dist/useSubscription.js +55 -46
- package/package.json +2 -2
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { resolveByTag as e } from "./tagWalk.js";
|
|
2
|
+
import { Context as t, Option as n } from "effect";
|
|
3
|
+
import { RpcGroup as r, RpcSchema as i } from "effect/rpc";
|
|
4
|
+
import { EventRpcWorkload as a, apiRoleEndpointUrl as o, captureApiRoleEndpoints as s, selectApiRoleEndpoint as c } from "@voltro/protocol";
|
|
5
|
+
//#region src/apiRoleTransports.ts
|
|
6
|
+
var l = (e, l, u) => {
|
|
7
|
+
let d = e;
|
|
8
|
+
if (u === void 0) return [{
|
|
9
|
+
name: "default",
|
|
10
|
+
url: l,
|
|
11
|
+
group: d,
|
|
12
|
+
tags: new Set(d.requests.keys())
|
|
13
|
+
}];
|
|
14
|
+
let f = s(u), p = /* @__PURE__ */ new Map();
|
|
15
|
+
for (let e of d.requests.values()) {
|
|
16
|
+
let r = e, s = n.isSome(t.getOption(r.annotations, a)) ? "events" : i.isStreamSchema(r.successSchema) ? "subscriptions" : "rpc", u = c(f, e._tag, s), d = p.get(u.role) ?? {
|
|
17
|
+
url: o(l, u, "websocket"),
|
|
18
|
+
requests: []
|
|
19
|
+
};
|
|
20
|
+
d.requests.push(e), p.set(u.role, d);
|
|
21
|
+
}
|
|
22
|
+
return [...p].map(([e, t]) => ({
|
|
23
|
+
name: e,
|
|
24
|
+
url: t.url,
|
|
25
|
+
group: r.make(...t.requests).annotateMerge(d.annotations),
|
|
26
|
+
tags: new Set(t.requests.map((e) => e._tag))
|
|
27
|
+
}));
|
|
28
|
+
}, u = (t) => {
|
|
29
|
+
let n = Object.create(null);
|
|
30
|
+
for (let r of t) for (let t of r.tags) {
|
|
31
|
+
let i = t.split("."), a = n;
|
|
32
|
+
for (let e of i.slice(0, -1)) {
|
|
33
|
+
Object.hasOwn(a, e) || (a[e] = Object.create(null));
|
|
34
|
+
let t = a[e];
|
|
35
|
+
if (t === null || typeof t != "object" && typeof t != "function") throw Error("Invalid RPC namespace collision");
|
|
36
|
+
a = t;
|
|
37
|
+
}
|
|
38
|
+
let o = i[i.length - 1], s = e(r.client, t), c = (...e) => s(...e);
|
|
39
|
+
if (Object.hasOwn(a, o)) {
|
|
40
|
+
if (typeof a[o] == "function") throw Error("Duplicate routed RPC tag");
|
|
41
|
+
Object.assign(c, a[o]);
|
|
42
|
+
}
|
|
43
|
+
a[o] = c;
|
|
44
|
+
}
|
|
45
|
+
return n;
|
|
46
|
+
};
|
|
47
|
+
//#endregion
|
|
48
|
+
export { u as combineApiRoleClients, l as planApiRoleTransports };
|
package/dist/apiRuntime.js
CHANGED
|
@@ -5,15 +5,16 @@ import { makeRecoveryRetry as r } from "./recoveryRetry.js";
|
|
|
5
5
|
import { recoveryCoordinatorFor as i } from "./recoveryCoordinator.js";
|
|
6
6
|
import { makeClientScheduler as a } from "./clientScheduler.js";
|
|
7
7
|
import { readRuntimeCapabilities as o } from "./runtimeCapabilities.js";
|
|
8
|
-
import { ConnectionScope as s,
|
|
9
|
-
import { resolveByTag as
|
|
10
|
-
import {
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import {
|
|
14
|
-
import
|
|
8
|
+
import { ConnectionScope as s, combineConnectionScopes as c, registerConnectionScope as l } from "./connectionScope.js";
|
|
9
|
+
import { resolveByTag as u } from "./tagWalk.js";
|
|
10
|
+
import { combineApiRoleClients as d, planApiRoleTransports as f } from "./apiRoleTransports.js";
|
|
11
|
+
import { Context as p, Effect as m, Layer as h, ManagedRuntime as g, Result as _, Scheduler as v, Schema as y, Stream as b } from "effect";
|
|
12
|
+
import * as x from "effect/http/Headers";
|
|
13
|
+
import { RpcClient as S, RpcSerialization as C } from "effect/rpc";
|
|
14
|
+
import { compareSurfaces as w, groupShapeDigests as T } from "@voltro/protocol";
|
|
15
|
+
import * as E from "effect/socket/Socket";
|
|
15
16
|
//#region src/apiRuntime.ts
|
|
16
|
-
var
|
|
17
|
+
var D = async (t, n, r, i) => {
|
|
17
18
|
if (r !== void 0) try {
|
|
18
19
|
let a = await r({
|
|
19
20
|
apiName: t,
|
|
@@ -31,14 +32,14 @@ var w = async (t, n, r, i) => {
|
|
|
31
32
|
});
|
|
32
33
|
return;
|
|
33
34
|
}
|
|
34
|
-
},
|
|
35
|
+
}, O = (e, t = new s()) => {
|
|
35
36
|
let n;
|
|
36
37
|
return {
|
|
37
|
-
wrap: (e) =>
|
|
38
|
+
wrap: (e) => E.Socket.of({
|
|
38
39
|
...e,
|
|
39
|
-
reader:
|
|
40
|
+
reader: m.gen(function* () {
|
|
40
41
|
let r = t.begin();
|
|
41
|
-
yield*
|
|
42
|
+
yield* m.addFinalizer(() => m.sync(() => {
|
|
42
43
|
n === r && (n = void 0), r.close();
|
|
43
44
|
}));
|
|
44
45
|
let i = yield* e.reader;
|
|
@@ -46,17 +47,17 @@ var w = async (t, n, r, i) => {
|
|
|
46
47
|
})
|
|
47
48
|
}),
|
|
48
49
|
hooks: {
|
|
49
|
-
onConnect:
|
|
50
|
+
onConnect: m.sync(() => {
|
|
50
51
|
let t = n;
|
|
51
52
|
n = void 0, t?.open() !== void 0 && e();
|
|
52
53
|
}),
|
|
53
|
-
onDisconnect:
|
|
54
|
+
onDisconnect: m.void
|
|
54
55
|
}
|
|
55
56
|
};
|
|
56
|
-
},
|
|
57
|
+
}, k = 3, A = (t, n, r) => {
|
|
57
58
|
let i;
|
|
58
59
|
try {
|
|
59
|
-
i =
|
|
60
|
+
i = w(T(n), r);
|
|
60
61
|
} catch {
|
|
61
62
|
return;
|
|
62
63
|
}
|
|
@@ -67,69 +68,78 @@ var w = async (t, n, r, i) => {
|
|
|
67
68
|
missingHere: o.length,
|
|
68
69
|
first: a[0] ?? o[0] ?? null
|
|
69
70
|
});
|
|
70
|
-
let s = [...a, ...o].slice(0,
|
|
71
|
+
let s = [...a, ...o].slice(0, k), c = a.length + o.length - s.length;
|
|
71
72
|
console.warn(`[voltro] the api client this page loaded does not match what the '${t}' server binds: ${s.join(", ")}${c > 0 ? ` and ${c} more` : ""}. Responses for those procedures may decode against the wrong schema — a field the server sends and this client does not know is dropped silently. Reload; if it persists, stop the dev server, delete \`.framework/.vite\`, and start it again.`);
|
|
72
|
-
},
|
|
73
|
-
let { name:
|
|
74
|
-
e(
|
|
75
|
-
let
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
attempt: t,
|
|
79
|
-
delayMs: n,
|
|
80
|
-
owner: "socket"
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
o(E, S, fetch, 1500, N.options.capabilitiesUrl).then((t) => {
|
|
84
|
-
N.setMutationReplaySupported(t?.mutationReplay === !0, j), e(S, "runtime.capabilities", {
|
|
73
|
+
}, j = async (w) => {
|
|
74
|
+
let { name: T, wsUrl: k, group: j, headers: M, webSocketConstructor: N } = w, P = f(j, k, w.roleEndpoints), F = w.generation ?? 0;
|
|
75
|
+
e(T, "runtime.build-started", { generation: F });
|
|
76
|
+
let I = w.errorBus ?? new n(), L = w.recovery ?? i(I, T), R = L.subjectSignal;
|
|
77
|
+
o(k, T, fetch, 1500, L.options.capabilitiesUrl).then((t) => {
|
|
78
|
+
L.setMutationReplaySupported(t?.mutationReplay === !0, F), e(T, "runtime.capabilities", {
|
|
85
79
|
mutationReplay: t?.mutationReplay === !0,
|
|
86
80
|
discovered: t !== void 0
|
|
87
81
|
});
|
|
88
|
-
let n =
|
|
89
|
-
n !== void 0 &&
|
|
82
|
+
let n = w.surfaceAudience === "service" ? t?.serviceSurface : t?.surface;
|
|
83
|
+
n !== void 0 && A(T, j, n);
|
|
90
84
|
});
|
|
91
|
-
let
|
|
92
|
-
errorBus:
|
|
93
|
-
apiName:
|
|
94
|
-
...
|
|
95
|
-
}),
|
|
96
|
-
class
|
|
97
|
-
let
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
85
|
+
let z = w.descriptors ?? {}, B = await D(T, F, w.mirror, z), V = new t({
|
|
86
|
+
errorBus: I,
|
|
87
|
+
apiName: T,
|
|
88
|
+
...B === void 0 ? {} : { mirror: B }
|
|
89
|
+
}), H = P.map(() => new s()), U = c(H), W;
|
|
90
|
+
class G extends p.Service()(`@voltro/client/AppClient/${T}`) {}
|
|
91
|
+
let K = h.succeed(E.WebSocketConstructor, N), q = P.map((e, t) => p.Service(`@voltro/client/Role/${T}/${t}/${e.name}`)), J = P.map((t, n) => {
|
|
92
|
+
let i = r(L.options.retry, (n, r) => {
|
|
93
|
+
e(T, "socket.retry-scheduled", {
|
|
94
|
+
generation: F,
|
|
95
|
+
role: t.name,
|
|
96
|
+
attempt: n,
|
|
97
|
+
delayMs: r,
|
|
98
|
+
owner: "socket"
|
|
99
|
+
});
|
|
100
|
+
}), a = E.layerWebSocket(t.url).pipe(h.provide(K)), o = O(() => {
|
|
101
|
+
i.reset();
|
|
102
|
+
let n = W === void 0 ? 0 : V.resumeTransportFailures(W, w.roleEndpoints === void 0 ? void 0 : (e) => e !== void 0 && t.tags.has(e));
|
|
103
|
+
e(T, "protocol.ready", {
|
|
104
|
+
generation: F,
|
|
105
|
+
role: t.name,
|
|
106
|
+
resumed: n
|
|
107
|
+
}), U.scope.getSnapshot() !== void 0 && L.protocolReady();
|
|
108
|
+
}, H[n]), s = h.effect(E.Socket, m.map(E.Socket, o.wrap)).pipe(h.provide(a)), c = h.effect(S.Protocol, S.makeProtocolSocket({ retryPolicy: i.schedule })).pipe(h.provide(C.layerJson), h.provide(s), h.provide(h.succeed(S.ConnectionHooks, o.hooks)));
|
|
109
|
+
return h.effect(q[n], S.make(t.group)).pipe(h.provide(c));
|
|
110
|
+
}), Y = typeof M == "function" ? await M() : M, X = J.reduce((e, t) => h.merge(e, t), h.empty), Z = h.effect(G, m.map(m.all(q.map((e) => e)), (e) => d(e.map((e, t) => ({
|
|
111
|
+
client: e,
|
|
112
|
+
tags: P[t].tags
|
|
113
|
+
}))))).pipe(h.provide(X)), ee = h.effectDiscard(m.acquireRelease(m.void, () => m.sync(U.close))), te = Y ? h.succeed(S.CurrentHeaders, x.fromInput(Y)) : h.empty, Q = a(), $ = g.make(h.mergeAll(Z, te, ee).pipe(h.provideMerge(h.succeed(v.Scheduler, Q))));
|
|
114
|
+
W = $, l(W, U.scope);
|
|
106
115
|
try {
|
|
107
|
-
let t = await
|
|
108
|
-
e(
|
|
109
|
-
generation:
|
|
110
|
-
scheduler:
|
|
116
|
+
let t = await $.runPromise(G);
|
|
117
|
+
e(T, "runtime.resolved", {
|
|
118
|
+
generation: F,
|
|
119
|
+
scheduler: Q.yieldChannel
|
|
111
120
|
});
|
|
112
|
-
let n = (
|
|
113
|
-
let t =
|
|
114
|
-
return t !== void 0 &&
|
|
121
|
+
let n = (B?.warmTags ?? []).filter((e) => {
|
|
122
|
+
let t = z[e]?.input;
|
|
123
|
+
return t !== void 0 && _.isSuccess(y.decodeUnknownResult(t)({}));
|
|
115
124
|
}).map((e) => [e, {}]);
|
|
116
|
-
for (let [e, r] of [...
|
|
117
|
-
let n =
|
|
118
|
-
|
|
125
|
+
for (let [e, r] of [...B?.warm ?? [], ...n]) {
|
|
126
|
+
let n = z[e]?.source;
|
|
127
|
+
V.subscribe([e, r], () => b.suspend(() => u(t, e)(r)), $, () => {}, n === void 0 ? {} : { source: n });
|
|
119
128
|
}
|
|
120
129
|
return {
|
|
121
|
-
runtime:
|
|
130
|
+
runtime: $,
|
|
122
131
|
client: t,
|
|
123
|
-
cache:
|
|
124
|
-
errorBus:
|
|
125
|
-
recovery:
|
|
132
|
+
cache: V,
|
|
133
|
+
errorBus: I,
|
|
134
|
+
recovery: L,
|
|
135
|
+
subjectSignal: R
|
|
126
136
|
};
|
|
127
137
|
} catch (t) {
|
|
128
|
-
throw e(
|
|
129
|
-
generation:
|
|
138
|
+
throw e(T, "runtime.failed", {
|
|
139
|
+
generation: F,
|
|
130
140
|
errorName: t instanceof Error ? t.name : typeof t
|
|
131
|
-
}),
|
|
141
|
+
}), await $.dispose(), U.close(), t;
|
|
132
142
|
}
|
|
133
143
|
};
|
|
134
144
|
//#endregion
|
|
135
|
-
export {
|
|
145
|
+
export { j as buildApiRuntime, O as makeProtocolOpenRecovery };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { planApiRoleTransports as e } from "./apiRoleTransports.js";
|
|
2
|
+
//#region src/apiSocketTracker.ts
|
|
3
|
+
var t = (e, t, n) => {
|
|
4
|
+
let r = new Map(e.map((e) => [e, { open: !1 }])), i = !1;
|
|
5
|
+
return { begin: (e) => {
|
|
6
|
+
if (!r.has(e)) throw Error("Unexpected API role socket endpoint");
|
|
7
|
+
let a = { open: !1 };
|
|
8
|
+
r.set(e, a), i && (i = !1, n("close"));
|
|
9
|
+
let o = !1;
|
|
10
|
+
return {
|
|
11
|
+
open: () => {
|
|
12
|
+
o || r.get(e) !== a || a.open || (a.open = !0, !i && [...r.values()].every((e) => e.open) && (i = !0, t()));
|
|
13
|
+
},
|
|
14
|
+
issue: (t) => {
|
|
15
|
+
o || r.get(e) !== a || (o = !0, a.open = !1, i = !1, n(t));
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
} };
|
|
19
|
+
}, n = (n, r, i, a, o) => t(e(n, r, i).map((e) => e.url), a, o);
|
|
20
|
+
//#endregion
|
|
21
|
+
export { n as makeApiRoleSocketTracker, t as makeApiSocketTracker };
|
package/dist/apiSupervisor.js
CHANGED
|
@@ -12,6 +12,7 @@ var i = (e, t, n) => ({
|
|
|
12
12
|
everOpened: !1,
|
|
13
13
|
wedgeStop: null,
|
|
14
14
|
subjectMayHaveChanged: !1,
|
|
15
|
+
swapWaiters: [],
|
|
15
16
|
errorBus: e,
|
|
16
17
|
recovery: t,
|
|
17
18
|
stopRecoveryError: e.on((e) => t.observeError(e)),
|
|
@@ -84,6 +85,9 @@ var i = (e, t, n) => ({
|
|
|
84
85
|
seeded: d,
|
|
85
86
|
subjectMayHaveChanged: u
|
|
86
87
|
}), x(), c && o(c);
|
|
88
|
+
let f = n.swapWaiters.filter((e) => e.generation <= r);
|
|
89
|
+
n.swapWaiters = n.swapWaiters.filter((e) => e.generation > r);
|
|
90
|
+
for (let e of f) e.resolve();
|
|
87
91
|
} catch {
|
|
88
92
|
if (v || n.generation !== r) return;
|
|
89
93
|
C(t);
|
|
@@ -98,7 +102,7 @@ var i = (e, t, n) => ({
|
|
|
98
102
|
dispose: () => {
|
|
99
103
|
v = !0;
|
|
100
104
|
},
|
|
101
|
-
reconnect: () =>
|
|
105
|
+
reconnect: () => Promise.resolve(),
|
|
102
106
|
refreshAuth: () => {}
|
|
103
107
|
}) : (m(() => {
|
|
104
108
|
if (!v) for (let e of c) w(e);
|
|
@@ -108,14 +112,21 @@ var i = (e, t, n) => ({
|
|
|
108
112
|
v = !0;
|
|
109
113
|
for (let e of y) p(e);
|
|
110
114
|
y.clear();
|
|
111
|
-
for (let [, e] of _)
|
|
115
|
+
for (let [, e] of _) {
|
|
116
|
+
e.resolved && o(e.resolved), e.reconnectStatusDispose && e.reconnectStatusDispose(), a(e), e.stopRecoveryError(), e.stopRecoverySuccess(), e.ownsRecovery && e.recovery.dispose();
|
|
117
|
+
for (let t of e.swapWaiters) t.resolve();
|
|
118
|
+
e.swapWaiters = [];
|
|
119
|
+
}
|
|
112
120
|
for (let t of c) e(t.name, "runtime.disposed");
|
|
113
121
|
_.clear();
|
|
114
122
|
}
|
|
115
123
|
},
|
|
116
|
-
reconnect: () => {
|
|
117
|
-
|
|
118
|
-
|
|
124
|
+
reconnect: () => v ? Promise.resolve() : (T(!0), Promise.all([..._.values()].map((e) => new Promise((t) => {
|
|
125
|
+
e.swapWaiters.push({
|
|
126
|
+
generation: e.generation,
|
|
127
|
+
resolve: t
|
|
128
|
+
});
|
|
129
|
+
}))).then(() => void 0)),
|
|
119
130
|
refreshAuth: () => {
|
|
120
131
|
T(!1);
|
|
121
132
|
}
|
package/dist/awaitResolvedApi.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { isUnresolvedApi as e } from "./frameworkRuntimesContext.js";
|
|
2
2
|
import { ConnectionPrerequisiteInvalidated as t } from "./connectionPrerequisite.js";
|
|
3
3
|
//#region src/awaitResolvedApi.ts
|
|
4
|
-
var n = 15e3, r = async (t, r, i) => {
|
|
5
|
-
if (!e(t.current)) return t.current;
|
|
6
|
-
let
|
|
7
|
-
for (; Date.now() <
|
|
4
|
+
var n = 15e3, r = async (t, r, i, a) => {
|
|
5
|
+
if (a?.throwIfAborted(), !e(t.current)) return t.current;
|
|
6
|
+
let o = Date.now() + n;
|
|
7
|
+
for (; Date.now() < o;) if (await new Promise((e) => setTimeout(e, 16)), a?.throwIfAborted(), !e(t.current)) return t.current;
|
|
8
8
|
throw Error(`Voltro: the api "${r}" did not resolve within ${n}ms, so ${i} was never sent. This is not the boot window — that is waited out. Check that "${r}" is a configured api name and that its client could connect.`);
|
|
9
9
|
}, i = async (n, i, a) => {
|
|
10
10
|
let o = e(n.current) ? void 0 : n.current.recovery, s = o?.subjectSignal, c = await r(n, i, a), l = c.recovery;
|
package/dist/bootstrap.d.ts
CHANGED
|
@@ -37,6 +37,8 @@ export declare interface ApiHandle {
|
|
|
37
37
|
readonly errorBus: RpcErrorBus;
|
|
38
38
|
/** Stable UI/raw transport recovery state for this logical api. */
|
|
39
39
|
readonly recovery?: RecoveryCoordinator;
|
|
40
|
+
/** Identity lifetime captured when this transport was built. */
|
|
41
|
+
readonly subjectSignal?: AbortSignal;
|
|
40
42
|
}
|
|
41
43
|
|
|
42
44
|
/**
|
|
@@ -262,6 +264,11 @@ declare interface FormFlashPayload {
|
|
|
262
264
|
readonly errors: Readonly<Record<string, string>>;
|
|
263
265
|
/** A non-field error (the RPC refused after valid input: guard, server). */
|
|
264
266
|
readonly formError?: string;
|
|
267
|
+
/** JSON encoded through the procedure's declared error schema. Private to
|
|
268
|
+
* this failed submit; never a publication or permission proof. */
|
|
269
|
+
readonly rejection?: unknown;
|
|
270
|
+
/** Admitted original page for repeated native errors and late hydration. */
|
|
271
|
+
readonly sourcePath?: string;
|
|
265
272
|
}
|
|
266
273
|
|
|
267
274
|
export declare interface FrameworkRuntimes {
|
|
@@ -716,6 +723,8 @@ declare interface ServerRequestContextValue {
|
|
|
716
723
|
* would add a fiber fork the client boot does not have, and every
|
|
717
724
|
* ancestor arity difference shifts every useId in the app. */
|
|
718
725
|
readonly formFlash?: FormFlashPayload;
|
|
726
|
+
/** Public captured build/class selection, never a credential or write permit. */
|
|
727
|
+
readonly formSource?: string;
|
|
719
728
|
}
|
|
720
729
|
|
|
721
730
|
declare type ShellKind = 'browser' | 'expo' | 'tauri' | 'electron' | 'node' | 'test';
|
package/dist/bootstrap.js
CHANGED
|
@@ -3,6 +3,6 @@ import { FrameworkRuntimesContext as t } from "./frameworkRuntimesContext.js";
|
|
|
3
3
|
import { FrameworkRuntimesProvider as n } from "./provider.js";
|
|
4
4
|
import { applyStoreSeeds as r } from "./store.js";
|
|
5
5
|
import { browserPlatform as i, currentPlatform as a, installPlatform as o, isPlatformInstalled as s, usePlatform as c } from "./platform.js";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
export { t as FrameworkRuntimesContext, n as FrameworkRuntimesProvider,
|
|
6
|
+
import { useServerRequest as l } from "./serverRequest.js";
|
|
7
|
+
import { applyPreloadSeeds as u } from "./preloadSeed.js";
|
|
8
|
+
export { t as FrameworkRuntimesContext, n as FrameworkRuntimesProvider, u as applyPreloadSeeds, r as applyStoreSeeds, i as browserPlatform, a as currentPlatform, e as globalContext, o as installPlatform, s as isPlatformInstalled, c as usePlatform, l as useServerRequest };
|
package/dist/connectionScope.js
CHANGED
|
@@ -30,6 +30,18 @@ var e = class {
|
|
|
30
30
|
}
|
|
31
31
|
}, t = /* @__PURE__ */ new WeakMap(), n = (e, n) => {
|
|
32
32
|
t.set(e, n);
|
|
33
|
-
}, r = (e) => t.get(e)
|
|
33
|
+
}, r = (e) => t.get(e), i = (t) => {
|
|
34
|
+
let n = new e(), r = n.begin(), i = !1, a = () => {
|
|
35
|
+
let e = t.length > 0 && t.every((e) => e.getSnapshot() !== void 0);
|
|
36
|
+
e !== i && (i = e, i ? r.open() : (r.close(), r = n.begin()));
|
|
37
|
+
}, o = t.map((e) => e.subscribe(a));
|
|
38
|
+
return a(), {
|
|
39
|
+
scope: n,
|
|
40
|
+
close: () => {
|
|
41
|
+
for (let e of o) e();
|
|
42
|
+
r.close();
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
};
|
|
34
46
|
//#endregion
|
|
35
|
-
export { e as ConnectionScope, r as connectionScopeForRuntime, n as registerConnectionScope };
|
|
47
|
+
export { e as ConnectionScope, i as combineConnectionScopes, r as connectionScopeForRuntime, n as registerConnectionScope };
|
package/dist/form.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import { encodeNativeFormCapture } from '@voltro/protocol';
|
|
2
|
+
import { FORM_CAPTURE_FIELD } from '@voltro/protocol';
|
|
3
|
+
import { FORM_CAPTURE_META_NAME } from '@voltro/protocol';
|
|
4
|
+
import { formCaptureSource } from '@voltro/protocol';
|
|
5
|
+
import { readFormCaptureSource } from '@voltro/protocol';
|
|
1
6
|
import { Schema } from 'effect';
|
|
2
7
|
|
|
3
8
|
/**
|
|
@@ -11,6 +16,13 @@ export declare const decodeFieldIssues: (error: Schema.SchemaError) => ReadonlyA
|
|
|
11
16
|
* outside a browser. Primary subtag only (`de-AT` → `de`). */
|
|
12
17
|
export declare const documentLocale: () => string;
|
|
13
18
|
|
|
19
|
+
/** Encode only a declared public tagged error. Run in the schema's own module graph,
|
|
20
|
+
* including a production SSR bundle. Defects, invalid values, service-dependent
|
|
21
|
+
* codecs and oversized errors contribute no structured form state. */
|
|
22
|
+
export declare const encodeFormRejection: (schema: Schema.Top | undefined, error: unknown) => unknown;
|
|
23
|
+
|
|
24
|
+
export { encodeNativeFormCapture }
|
|
25
|
+
|
|
14
26
|
export declare interface FieldDescriptor {
|
|
15
27
|
/** Property name on the input object. */
|
|
16
28
|
readonly name: string;
|
|
@@ -79,22 +91,27 @@ export declare interface FieldSection {
|
|
|
79
91
|
readonly fields: ReadonlyArray<FieldDescriptor>;
|
|
80
92
|
}
|
|
81
93
|
|
|
94
|
+
export { FORM_CAPTURE_FIELD }
|
|
95
|
+
|
|
96
|
+
export { FORM_CAPTURE_META_NAME }
|
|
97
|
+
|
|
82
98
|
/** DOM id of the JSON script the 422 re-render embeds (survives the
|
|
83
99
|
* `interactive:'none'` strip — it is neither `type="module"` nor `src`). */
|
|
84
100
|
export declare const FORM_FLASH_SCRIPT_ID = "__voltro_form_flash__";
|
|
85
101
|
|
|
86
|
-
/** Hidden field carrying the form's instance key (multi-form pages). */
|
|
87
102
|
export declare const FORM_KEY_FIELD = "__voltro_form";
|
|
88
103
|
|
|
89
|
-
/** URL prefix the web listener mounts the no-JS endpoint under. */
|
|
90
104
|
export declare const FORM_PATH_PREFIX = "/form/";
|
|
91
105
|
|
|
92
|
-
/** Hidden field carrying the declared success-redirect path. */
|
|
93
106
|
export declare const FORM_REDIRECT_FIELD = "__voltro_redirect";
|
|
94
107
|
|
|
95
|
-
/** The
|
|
108
|
+
/** The original page, distinct from an optional success redirect. */
|
|
109
|
+
export declare const FORM_SOURCE_FIELD = "__voltro_source";
|
|
110
|
+
|
|
96
111
|
export declare const formActionPath: (mutationTag: string) => string;
|
|
97
112
|
|
|
113
|
+
export { formCaptureSource }
|
|
114
|
+
|
|
98
115
|
/**
|
|
99
116
|
* Convert posted form entries into the input object the mutation's schema
|
|
100
117
|
* decodes — the shape `validateFields` (and the RPC payload) expects.
|
|
@@ -156,6 +173,11 @@ export declare interface FormFlashPayload {
|
|
|
156
173
|
readonly errors: Readonly<Record<string, string>>;
|
|
157
174
|
/** A non-field error (the RPC refused after valid input: guard, server). */
|
|
158
175
|
readonly formError?: string;
|
|
176
|
+
/** JSON encoded through the procedure's declared error schema. Private to
|
|
177
|
+
* this failed submit; never a publication or permission proof. */
|
|
178
|
+
readonly rejection?: unknown;
|
|
179
|
+
/** Admitted original page for repeated native errors and late hydration. */
|
|
180
|
+
readonly sourcePath?: string;
|
|
159
181
|
}
|
|
160
182
|
|
|
161
183
|
/**
|
|
@@ -166,6 +188,17 @@ export declare interface FormFlashPayload {
|
|
|
166
188
|
*/
|
|
167
189
|
export declare const formSections: (fields: ReadonlyArray<FieldDescriptor>) => ReadonlyArray<FieldSection>;
|
|
168
190
|
|
|
191
|
+
/** Admit a local source page; native form endpoints cannot be their own source. */
|
|
192
|
+
export declare const formSourcePath: (raw: unknown) => string | undefined;
|
|
193
|
+
|
|
194
|
+
export { readFormCaptureSource }
|
|
195
|
+
|
|
196
|
+
/** Recover edits made to one native form before its JavaScript booted.
|
|
197
|
+
* Uses the ordinary native schema mapper; only changed, editable controls
|
|
198
|
+
* replace initial values. Hidden metadata and unrelated forms stay intact.
|
|
199
|
+
* Call once when initializing state, never as a submission or authority check. */
|
|
200
|
+
export declare const recoverNativeFormValues: (schema: Schema.Top, formKey: string, values: Readonly<Record<string, unknown>>) => Readonly<Record<string, unknown>>;
|
|
201
|
+
|
|
169
202
|
/**
|
|
170
203
|
* Render one issue id to display text: app resolver first (its `undefined`
|
|
171
204
|
* falls through), then the built-in catalog for the locale's primary subtag,
|
package/dist/form.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { formField as e, formSections as t, schemaToColumns as n, schemaToFields as r } from "./schemaFields.js";
|
|
2
2
|
import { decodeFieldIssues as i, documentLocale as a, resolveValidationMessage as o, restrictToSchema as s, validateFields as c } from "./formBinding.js";
|
|
3
3
|
import { FORM_FLASH_SCRIPT_ID as l } from "./formFlashId.js";
|
|
4
|
-
import {
|
|
5
|
-
|
|
4
|
+
import { FORM_CAPTURE_FIELD as u, FORM_CAPTURE_META_NAME as d, FORM_KEY_FIELD as f, FORM_PATH_PREFIX as p, FORM_REDIRECT_FIELD as m, FORM_SOURCE_FIELD as h, encodeNativeFormCapture as g, formActionPath as _, formCaptureSource as v, formSourcePath as y, readFormCaptureSource as b } from "./formSource.js";
|
|
5
|
+
import { formDataToInput as x, recoverNativeFormValues as S } from "./formData.js";
|
|
6
|
+
import { encodeFormRejection as C } from "./formRejection.js";
|
|
7
|
+
export { u as FORM_CAPTURE_FIELD, d as FORM_CAPTURE_META_NAME, l as FORM_FLASH_SCRIPT_ID, f as FORM_KEY_FIELD, p as FORM_PATH_PREFIX, m as FORM_REDIRECT_FIELD, h as FORM_SOURCE_FIELD, i as decodeFieldIssues, a as documentLocale, C as encodeFormRejection, g as encodeNativeFormCapture, _ as formActionPath, v as formCaptureSource, x as formDataToInput, e as formField, t as formSections, y as formSourcePath, b as readFormCaptureSource, S as recoverNativeFormValues, o as resolveValidationMessage, s as restrictToSchema, n as schemaToColumns, r as schemaToFields, c as validateFields };
|
package/dist/formData.js
CHANGED
|
@@ -1,27 +1,28 @@
|
|
|
1
1
|
import { schemaToFields as e } from "./schemaFields.js";
|
|
2
2
|
import { parseRichText as t } from "./richText.js";
|
|
3
3
|
import { FORM_FLASH_SCRIPT_ID as n } from "./formFlashId.js";
|
|
4
|
+
import { FORM_CAPTURE_FIELD as r, FORM_CAPTURE_META_NAME as i, FORM_KEY_FIELD as a, FORM_PATH_PREFIX as o, FORM_REDIRECT_FIELD as s, FORM_SOURCE_FIELD as c, encodeNativeFormCapture as l, formActionPath as u, formCaptureSource as d, formSourcePath as f, readFormCaptureSource as p } from "./formSource.js";
|
|
4
5
|
//#region src/formData.ts
|
|
5
|
-
var
|
|
6
|
+
var m = (e) => {
|
|
6
7
|
let t = Number(e);
|
|
7
|
-
return Number.
|
|
8
|
-
},
|
|
8
|
+
return Number.isFinite(t) ? t === 0 ? 0 : t : e;
|
|
9
|
+
}, h = (e) => {
|
|
9
10
|
let t = e.jsonSchema.items;
|
|
10
11
|
if (!t || typeof t != "object") return;
|
|
11
12
|
let n = t.type;
|
|
12
13
|
return typeof n == "string" ? n : void 0;
|
|
13
|
-
},
|
|
14
|
+
}, g = (e, n) => {
|
|
14
15
|
switch (e.widget) {
|
|
15
16
|
case "rich-text": return n === "" ? {
|
|
16
17
|
type: "doc",
|
|
17
18
|
content: []
|
|
18
19
|
} : t(n);
|
|
19
|
-
case "number": return n === "" ? void 0 :
|
|
20
|
+
case "number": return n === "" ? void 0 : m(n);
|
|
20
21
|
case "date":
|
|
21
22
|
case "datetime": return n === "" ? void 0 : n;
|
|
22
23
|
default: return n;
|
|
23
24
|
}
|
|
24
|
-
},
|
|
25
|
+
}, _ = (t, n) => {
|
|
25
26
|
let r = /* @__PURE__ */ new Map();
|
|
26
27
|
for (let [e, t] of n) {
|
|
27
28
|
let n = r.get(e);
|
|
@@ -50,16 +51,77 @@ var r = "/form/", i = (e) => `${r}${encodeURIComponent(e)}`, a = "__voltro_form"
|
|
|
50
51
|
continue;
|
|
51
52
|
}
|
|
52
53
|
if (n.widget === "multi-select") {
|
|
53
|
-
let t =
|
|
54
|
-
if (i) for (let e = 0; e < o.length; e += 1) o[e] =
|
|
54
|
+
let t = h(n), r = e ?? [], i = t === "number" || t === "integer", o = r.filter((e) => e !== "");
|
|
55
|
+
if (i) for (let e = 0; e < o.length; e += 1) o[e] = m(o[e]);
|
|
55
56
|
a(n.name, o);
|
|
56
57
|
continue;
|
|
57
58
|
}
|
|
58
59
|
if (e === void 0) continue;
|
|
59
|
-
let t =
|
|
60
|
+
let t = g(n, e[0]);
|
|
60
61
|
t !== void 0 && a(n.name, t);
|
|
61
62
|
}
|
|
62
63
|
return i;
|
|
64
|
+
}, v = (t, n, r) => {
|
|
65
|
+
let i = globalThis.document;
|
|
66
|
+
if (i?.forms === void 0) return r;
|
|
67
|
+
let a = [...i.forms].filter((e) => {
|
|
68
|
+
let t = [...e.elements].filter((e) => e.tagName === "INPUT" && e.name === "__voltro_form");
|
|
69
|
+
return t.length === 1 && t[0].type === "hidden" && t[0].value === n;
|
|
70
|
+
});
|
|
71
|
+
if (a.length !== 1) return r;
|
|
72
|
+
let o = a[0], s = e(t).map((e) => e.name);
|
|
73
|
+
if (s.some((e) => e.split(".").some((e) => [
|
|
74
|
+
"__proto__",
|
|
75
|
+
"prototype",
|
|
76
|
+
"constructor"
|
|
77
|
+
].includes(e)))) return r;
|
|
78
|
+
let c = new Set(s), l = /* @__PURE__ */ new Set();
|
|
79
|
+
for (let e of o.elements) {
|
|
80
|
+
if (![
|
|
81
|
+
"INPUT",
|
|
82
|
+
"TEXTAREA",
|
|
83
|
+
"SELECT"
|
|
84
|
+
].includes(e.tagName) || e.matches(":disabled")) continue;
|
|
85
|
+
let t = e, n = t.name;
|
|
86
|
+
if (n !== void 0 && c.has(n)) {
|
|
87
|
+
if (t.tagName === "INPUT") {
|
|
88
|
+
let e = t;
|
|
89
|
+
if (e.readOnly || [
|
|
90
|
+
"hidden",
|
|
91
|
+
"file",
|
|
92
|
+
"button",
|
|
93
|
+
"submit",
|
|
94
|
+
"reset",
|
|
95
|
+
"image"
|
|
96
|
+
].includes(e.type ?? "")) continue;
|
|
97
|
+
e.type === "checkbox" || e.type === "radio" ? e.checked !== e.defaultChecked && l.add(n) : e.value !== e.defaultValue && l.add(n);
|
|
98
|
+
} else if (t.tagName === "TEXTAREA") {
|
|
99
|
+
let e = t;
|
|
100
|
+
!e.readOnly && e.value !== e.defaultValue && l.add(n);
|
|
101
|
+
} else [...t.options ?? []].some((e) => e.selected !== e.defaultSelected) && l.add(n);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (l.size === 0) return r;
|
|
105
|
+
let u = o.ownerDocument.defaultView?.FormData;
|
|
106
|
+
if (u === void 0) return r;
|
|
107
|
+
let d = [];
|
|
108
|
+
for (let [e, t] of new u(o)) typeof t == "string" && d.push([e, t]);
|
|
109
|
+
let f = _(t, d), p = (e, t) => {
|
|
110
|
+
let n = e;
|
|
111
|
+
for (let e of t) {
|
|
112
|
+
if (typeof n != "object" || !n || !Object.hasOwn(n, e)) return;
|
|
113
|
+
n = n[e];
|
|
114
|
+
}
|
|
115
|
+
return n;
|
|
116
|
+
}, m = (e, t, n) => {
|
|
117
|
+
let r = Array.isArray(e) ? [...e] : typeof e == "object" && e ? { ...e } : {}, i = r, a = t[0];
|
|
118
|
+
return i[a] = t.length === 1 ? n : m(i[a], t.slice(1), n), r;
|
|
119
|
+
}, h = r;
|
|
120
|
+
for (let e of l) {
|
|
121
|
+
let t = e.split(".");
|
|
122
|
+
h = m(h, t, p(f, t));
|
|
123
|
+
}
|
|
124
|
+
return h;
|
|
63
125
|
};
|
|
64
126
|
//#endregion
|
|
65
|
-
export { n as FORM_FLASH_SCRIPT_ID, a as FORM_KEY_FIELD,
|
|
127
|
+
export { r as FORM_CAPTURE_FIELD, i as FORM_CAPTURE_META_NAME, n as FORM_FLASH_SCRIPT_ID, a as FORM_KEY_FIELD, o as FORM_PATH_PREFIX, s as FORM_REDIRECT_FIELD, c as FORM_SOURCE_FIELD, l as encodeNativeFormCapture, u as formActionPath, d as formCaptureSource, _ as formDataToInput, f as formSourcePath, p as readFormCaptureSource, v as recoverNativeFormValues };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Schema as e } from "effect";
|
|
2
|
+
import { errorMemberSchema as t, errorTag as n } from "@voltro/protocol";
|
|
3
|
+
//#region src/formRejection.ts
|
|
4
|
+
var r = 65536, i = (i, a) => {
|
|
5
|
+
if (i !== void 0) try {
|
|
6
|
+
let o = n(a);
|
|
7
|
+
if (o === void 0) return;
|
|
8
|
+
let s = t(i, o);
|
|
9
|
+
if (s === void 0) return;
|
|
10
|
+
let c = e.toCodecJson(s), l = e.encodeUnknownSync(c), u;
|
|
11
|
+
try {
|
|
12
|
+
u = l(a);
|
|
13
|
+
} catch {
|
|
14
|
+
u = l(e.decodeUnknownSync(c)(a));
|
|
15
|
+
}
|
|
16
|
+
let d = JSON.stringify(u);
|
|
17
|
+
return d === void 0 || d.length > r || new TextEncoder().encode(d).byteLength > r ? void 0 : JSON.parse(d);
|
|
18
|
+
} catch {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
//#endregion
|
|
23
|
+
export { i as encodeFormRejection };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { FORM_FLASH_SCRIPT_ID as e } from "./formFlashId.js";
|
|
2
|
+
import { FORM_CAPTURE_FIELD as t, FORM_CAPTURE_META_NAME as n, encodeNativeFormCapture as r, formCaptureSource as i, readFormCaptureSource as a } from "@voltro/protocol";
|
|
3
|
+
//#region src/formSource.ts
|
|
4
|
+
var o = "/form/", s = "__voltro_form", c = "__voltro_redirect", l = "__voltro_source", u = (e) => `${o}${encodeURIComponent(e)}`, d = (e) => {
|
|
5
|
+
if (!(typeof e != "string" || e.length === 0 || e.length > 8192 || !e.startsWith("/") || e.startsWith("//") || /[\\\x00-\x1f\x7f]/.test(e))) try {
|
|
6
|
+
let t = new URL(e, "https://form.invalid");
|
|
7
|
+
return t.origin !== "https://form.invalid" || t.pathname === "/form" || t.pathname.startsWith("/form/") ? void 0 : t.pathname + t.search;
|
|
8
|
+
} catch {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
//#endregion
|
|
13
|
+
export { t as FORM_CAPTURE_FIELD, n as FORM_CAPTURE_META_NAME, e as FORM_FLASH_SCRIPT_ID, s as FORM_KEY_FIELD, o as FORM_PATH_PREFIX, c as FORM_REDIRECT_FIELD, l as FORM_SOURCE_FIELD, r as encodeNativeFormCapture, u as formActionPath, i as formCaptureSource, d as formSourcePath, a as readFormCaptureSource };
|