@voltro/client 0.83.1 → 0.85.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.
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Resolve `tag(input)` once on the api behind `handleRef`: a query to the data
3
+ * of its first snapshot, a mutation or action to its result.
4
+ *
5
+ * Waits out the client boot window like every other imperative seam, and
6
+ * rejects the way the server loader's `query` does: with the declared error
7
+ * itself, whether it arrived as an in-band `error` event or as a failed call —
8
+ * the same value every hook hands over. Aborting `signal` interrupts the call.
9
+ *
10
+ * @public
11
+ * @remarks
12
+ * The cross-package browser half of `LoaderContext.query`, wired by
13
+ * `@voltro/web`'s router. Apps read through `ctx.query`.
14
+ */
15
+ export declare const queryOnce: (handleRef: {
16
+ readonly current: ResolvableHandle;
17
+ }, apiName: string, tag: string, input: Record<string, unknown> | undefined, signal?: AbortSignal) => Promise<unknown>;
18
+
19
+ /** The minimum shape every api handle has; each hook reads more from its own. */
20
+ declare interface ResolvableHandle {
21
+ readonly runtime: unknown;
22
+ readonly client: unknown;
23
+ }
24
+
25
+ export { }
package/dist/query.js ADDED
@@ -0,0 +1,2 @@
1
+ import { t as e } from "./queryOnce-D5Y4V1SB.js";
2
+ export { e as queryOnce };
@@ -0,0 +1,55 @@
1
+ import { i as e, m as t, n, t as r, u as i } from "./runRpc-Zfz3w709.js";
2
+ import { createContext as a, useContext as o, useEffect as s } from "react";
3
+ import { Effect as c, Exit as l, Option as u, Stream as d } from "effect";
4
+ import { firstEventValue as f } from "@voltro/protocol";
5
+ //#region src/runtimeContext.ts
6
+ var p = a(null), m = () => {
7
+ 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");
8
+ }, h = new Proxy(() => m(), {
9
+ get: (e, t) => h,
10
+ has: () => !0,
11
+ apply: () => m()
12
+ }), g = Symbol.for("@voltro/client/ssrDescriptors"), _ = globalThis, v = _[g] ?? (_[g] = { byApi: /* @__PURE__ */ new Map() }), y = (e, t) => {
13
+ v.byApi.set(e, t);
14
+ }, b = (e) => v.byApi.get(e), x = () => {
15
+ v.byApi.clear();
16
+ }, S = {
17
+ runtime: { runPromiseExit: () => Promise.resolve(l.die(/* @__PURE__ */ Error("Voltro: mutations are not invokable during SSR"))) },
18
+ cache: new t(),
19
+ client: h,
20
+ descriptors: {},
21
+ inspectBaseUrl: "",
22
+ errorBus: new i(),
23
+ recovery: new e("ssr")
24
+ }, C = {
25
+ get: (e) => {
26
+ let t = b(e);
27
+ return t === void 0 ? S : {
28
+ ...S,
29
+ descriptors: t
30
+ };
31
+ },
32
+ names: []
33
+ }, w = !1, T = !1, E = null, D = () => {
34
+ w = !1, T = !1, E !== null && (clearTimeout(E), E = null);
35
+ }, O = () => {
36
+ let e = o(p);
37
+ return e ? (T || (T = !0, E !== null && (clearTimeout(E), E = null)), e) : (globalThis.window !== void 0 && !w && !T && E === null && process.env.NODE_ENV !== "production" && (E = setTimeout(() => {
38
+ E = null, !(w || T) && (w = !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>."));
39
+ }, 0)), C);
40
+ }, k = (e) => {
41
+ let t = O(), n = t.demand;
42
+ return s(() => {
43
+ n?.(e);
44
+ }, [n, e]), t.get(e);
45
+ }, A = (e) => typeof e.runtime?.runFork != "function", j = 15e3, M = async (e, t, n) => {
46
+ if (!A(e.current)) return e.current;
47
+ let r = Date.now() + j;
48
+ for (; Date.now() < r;) if (await new Promise((e) => setTimeout(e, 16)), !A(e.current)) return e.current;
49
+ throw Error(`Voltro: the api "${t}" did not resolve within ${j}ms, so ${n} was never sent. This is not the boot window — that is waited out. Check that "${t}" is a configured api name and that its client could connect.`);
50
+ }, N = async (e, t, i, a, o) => {
51
+ let { runtime: s, client: l } = await M(e, t, i), p = n(l, i)(a ?? {}), m = c.isEffect(p) ? p : d.runHead(p).pipe(c.map(u.getOrUndefined)), h = await r(s, m, { signal: o });
52
+ return f(i, h, "[loader.query]");
53
+ };
54
+ //#endregion
55
+ export { x as a, h as c, k as d, O as f, D as i, b as l, M as n, A as o, p as r, y as s, N as t, S as u };