@voltro/client 0.89.1 → 0.90.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/README.md CHANGED
@@ -20,7 +20,29 @@ Installation, guides, the full API reference, and examples all live in the
20
20
  **[Voltro documentation](https://docs.voltro.dev/docs/intro/getting-started)** — the single source of truth. This README is
21
21
  deliberately short so there is nothing here to drift out of date.
22
22
 
23
+ Workflow commands and control reads belong to their original API, Subject and
24
+ mounted view. See the [callback lifetime contract](https://docs.voltro.dev/docs/reference/hooks-data#workflow-callback-lifetime)
25
+ for account changes, concurrent calls and uncertain remote outcomes.
26
+
27
+ Uploads capture original files and metadata and own every local batch. See the
28
+ [upload lifetime contract](https://docs.voltro.dev/docs/plugins/storage#upload-callback-lifetime)
29
+ for cancellation, reset and unconfirmed physical cleanup.
30
+
31
+ Transcription owns one local intent and captures its original extra data. See
32
+ [media modalities](https://docs.voltro.dev/docs/ai/media) and
33
+ [action withdrawal](https://docs.voltro.dev/docs/data/actions) for cancellation
34
+ and uncertain server outcomes.
35
+
23
36
  ## License
24
37
 
25
38
  Proprietary. © 2026 Voltro UG. Your use is governed by the
26
39
  [Terms of Service](https://voltro.cloud/legal/terms). See the bundled `LICENSE`.
40
+
41
+
42
+ ## Analytics taxonomy without RPC bindings
43
+
44
+ `@voltro/client/analytics` exports the existing `defineEvent`, `eventCatalog`,
45
+ `validateEventPayload` and `createAnalytics`, plus their types and
46
+ `TrackingEvent`/`TrackingSink`. It loads no RPC or hook binding. The Client root
47
+ re-exports the same implementation. `createAnalytics` remains best effort;
48
+ consent and durable telemetry delivery require their owning runtime contracts.
@@ -0,0 +1,68 @@
1
+ import { Schema } from 'effect';
2
+
3
+ export declare interface Analytics<E extends ReadonlyArray<EventDescriptor<string, unknown>>> {
4
+ /** Emit an event — name + payload typed by the catalog; validated at runtime. */
5
+ readonly track: <K extends keyof EventMap<E> & string>(name: K, payload: EventMap<E>[K]) => void;
6
+ readonly names: ReadonlyArray<string>;
7
+ readonly catalog: EventCatalog;
8
+ }
9
+
10
+ /**
11
+ * Build a typed analytics surface from a declared event list + a sink. `track`
12
+ * is typed against the catalog; on a payload that fails its Schema it logs a
13
+ * loud dev error (the "bad event shape is loud" rule) and still forwards (best-
14
+ * effort — losing the event would be worse than a slightly-off payload).
15
+ */
16
+ export declare const createAnalytics: <const E extends ReadonlyArray<EventDescriptor<string, unknown>>>(events: E, sink: TrackingSink) => Analytics<E>;
17
+
18
+ /** Declare a typed analytics event. */
19
+ export declare const defineEvent: <const Name extends string, A, I>(name: Name, payload: Schema.Codec<A, I>) => EventDescriptor<Name, A>;
20
+
21
+ export declare interface EventCatalog {
22
+ readonly names: ReadonlyArray<string>;
23
+ readonly get: (name: string) => EventDescriptor<string, unknown> | undefined;
24
+ /** Discovery inventory: every event's name + its JSON-Schema-able payload. */
25
+ readonly events: ReadonlyArray<EventDescriptor<string, unknown>>;
26
+ }
27
+
28
+ export declare const eventCatalog: (events: ReadonlyArray<EventDescriptor<string, unknown>>) => EventCatalog;
29
+
30
+ export declare interface EventDescriptor<Name extends string, A> {
31
+ readonly name: Name;
32
+ /** The payload Schema, erased — `Schema` is INVARIANT in its decoded type, so
33
+ * storing `Schema.Schema<A>` here would make `EventDescriptor` invariant in
34
+ * `A` and break a heterogeneous catalog. The decoded type is carried by the
35
+ * covariant phantom `_type` below instead, so `EventDescriptor<string,
36
+ * unknown>` accepts every typed descriptor AND `track` stays typed. */
37
+ readonly payload: Schema.Top;
38
+ /** Phantom — never present at runtime; carries the decoded payload type for
39
+ * `track`'s compile-time signature. Covariant (optional), so erasure works. */
40
+ readonly _type?: A;
41
+ }
42
+
43
+ /** Map a tuple of event descriptors → `{ name: payloadType }` for typing track.
44
+ * The covariant `_type` phantom lets `EventDescriptor<string, unknown>` accept
45
+ * every typed descriptor as a constraint while inference still recovers `A`. */
46
+ declare type EventMap<E extends ReadonlyArray<EventDescriptor<string, unknown>>> = {
47
+ [D in E[number] as D['name']]: D extends EventDescriptor<string, infer A> ? A : never;
48
+ };
49
+
50
+ export declare interface EventValidation {
51
+ readonly valid: boolean;
52
+ /** `path` → message, empty when valid. */
53
+ readonly errors: Readonly<Record<string, string>>;
54
+ }
55
+
56
+ /** A resolved analytics event: a name + arbitrary payload. */
57
+ export declare type TrackingEvent = {
58
+ readonly event: string;
59
+ } & Record<string, unknown>;
60
+
61
+ /** Where resolved events go — the analytics sink (the client→server transport
62
+ * provides this; tests provide a recorder). */
63
+ export declare type TrackingSink = (event: TrackingEvent) => void;
64
+
65
+ /** Validate a payload against an event descriptor's Schema. Pure. */
66
+ export declare const validateEventPayload: (descriptor: EventDescriptor<string, unknown>, payload: unknown) => EventValidation;
67
+
68
+ export { }
@@ -0,0 +1 @@
1
+ export { createAnalytics, defineEvent, eventCatalog, validateEventPayload } from "./analyticsCatalog.js";
@@ -1,22 +1,48 @@
1
- import { isUnresolvedApi as e } from "./frameworkRuntimesContext.js";
2
- import { ConnectionPrerequisiteInvalidated as t } from "./connectionPrerequisite.js";
1
+ import { recoveryCoordinatorFor as e } from "./recoveryCoordinator.js";
2
+ import { isUnresolvedApi as t } from "./frameworkRuntimesContext.js";
3
+ import { ConnectionPrerequisiteInvalidated as n } from "./connectionPrerequisite.js";
3
4
  // src/awaitResolvedApi.ts
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
- 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
- }, i = async (n, i, a) => {
10
- let o = e(n.current) ? void 0 : n.current.recovery, s = o?.subjectSignal, c = await r(n, i, a), l = c.recovery;
11
- if (s?.aborted || o !== void 0 && l !== o) throw new t("inactive");
12
- if (l === void 0) return c;
13
- let u = s ?? l.subjectSignal, d = Date.now();
14
- for (;;) {
15
- let e = await l.waitForProtocolReady(d, u);
16
- if (u.aborted || l.subjectSignal !== u) throw new t("inactive");
17
- if (!e) throw new t("timeout");
18
- if (c = await r(n, i, a), u.aborted || c.recovery !== l) throw new t("inactive");
19
- if (l.getSnapshot().rawTransport === "connected") return c;
5
+ var r = 15e3, i = (n, r, i, a) => {
6
+ let o = n.recovery ?? e(n.errorBus, r), s = n.subjectSignal ?? o.subjectSignal, c = !t(n);
7
+ return !a || a.apiName !== r || a.rpcTag !== i || a.subject.aborted || a.resolved && (a.recovery !== o || a.subject !== s) ? {
8
+ apiName: r,
9
+ rpcTag: i,
10
+ recovery: o,
11
+ subject: s,
12
+ resolved: c
13
+ } : (!a.resolved && c && (a.recovery = o, a.subject = s, a.resolved = !0), a);
14
+ }, a = (n, r) => {
15
+ if (n.subject.aborted) return !1;
16
+ if (!n.resolved && t(r)) return !0;
17
+ let i = r.recovery ?? e(r.errorBus, n.apiName);
18
+ return i === n.recovery && (r.subjectSignal ?? i.subjectSignal) === n.subject;
19
+ }, o = (t, n) => {
20
+ if (t.resolved) return;
21
+ let r = n.recovery ?? e(n.errorBus, t.apiName);
22
+ t.recovery = r, t.subject = n.subjectSignal ?? r.subjectSignal, t.resolved = !0;
23
+ }, s = async (e, n, i, a) => {
24
+ if (a?.throwIfAborted(), !t(e.current)) return e.current;
25
+ let o = Date.now() + r;
26
+ for (; Date.now() < o;) if (await new Promise((e) => setTimeout(e, 16)), a?.throwIfAborted(), !t(e.current)) return e.current;
27
+ throw Error(`Voltro: the api "${n}" did not resolve within ${r}ms, so ${i} was never sent. This is not the boot window — that is waited out. Check that "${n}" is a configured api name and that its client could connect.`);
28
+ }, c = async (e, r, i, a) => {
29
+ a?.throwIfAborted();
30
+ let o = t(e.current) ? void 0 : e.current.recovery, c = o?.subjectSignal, l = await s(e, r, i, a), u = l.recovery;
31
+ if (a?.aborted || c?.aborted || o !== void 0 && u !== o) throw new n("inactive");
32
+ if (u === void 0) return l;
33
+ let d = c ?? u.subjectSignal, f = a === void 0 ? void 0 : new AbortController(), p = () => f?.abort();
34
+ f && (d.addEventListener("abort", p, { once: !0 }), a?.addEventListener("abort", p, { once: !0 }), (d.aborted || a?.aborted) && f.abort());
35
+ let m = Date.now();
36
+ try {
37
+ for (;;) {
38
+ let t = await u.waitForProtocolReady(m, f?.signal ?? d);
39
+ if (a?.aborted || d.aborted || u.subjectSignal !== d) throw new n("inactive");
40
+ if (!t) throw new n("timeout");
41
+ if (l = await s(e, r, i, a), a?.aborted || d.aborted || l.recovery !== u) throw new n("inactive");
42
+ if (u.getSnapshot().rawTransport === "connected") return l;
43
+ }
44
+ } finally {
45
+ d.removeEventListener("abort", p), a?.removeEventListener("abort", p);
20
46
  }
21
47
  };
22
- export { n as RESOLVE_TIMEOUT_MS, i as awaitReadyApi, r as awaitResolvedApi };
48
+ export { r as RESOLVE_TIMEOUT_MS, c as awaitReadyApi, s as awaitResolvedApi, o as bindResolvedRpcInvocationOwner, i as captureRpcInvocationOwner, a as rpcInvocationOwnerCurrent };
@@ -520,7 +520,6 @@ declare type RawTransportStatus = 'connected' | 'disconnected';
520
520
  * retain the complete sequence.
521
521
  */
522
522
  declare class RecoveryCoordinator {
523
- #private;
524
523
  constructor(apiName: string, options?: RecoveryOptions, scheduler?: Partial<RecoveryScheduler>);
525
524
  get options(): ResolvedRecoveryOptions;
526
525
  /** Ends on login/logout, tenant change or API disposal, not ordinary reconnect. */
@@ -654,7 +653,6 @@ declare interface RpcError {
654
653
  }
655
654
 
656
655
  declare class RpcErrorBus {
657
- #private;
658
656
  /** Subscribe. Returns an unsubscribe function. */
659
657
  on(listener: RpcErrorListener): () => void;
660
658
  /** Emit. Pipeline code (useMutation / subscriptionCache) calls this. */
@@ -753,36 +751,7 @@ declare type StoreStorageArea = 'local' | 'session';
753
751
  declare type StoreStorageProvider = (area: StoreStorageArea) => StoreStorage | null;
754
752
 
755
753
  declare class SubscriptionCache {
756
- private readonly entries;
757
- private readonly entriesByTable;
758
- private readonly entriesByTag;
759
- private readonly entriesByMutation;
760
- private readonly patchMemberships;
761
- private readonly entryOrder;
762
- private orderedMemberships;
763
- private nextEntryOrder;
764
- /** Standing optimistic intents, by mutation id — see `autoApply`. */
765
- private readonly intents;
766
- private readonly tableRows;
767
- private readonly anyListeners;
768
- private readonly tableListeners;
769
- private readonly refreshing;
770
- /**
771
- * Same-subject runtime replacement. A mutation may settle against the cache
772
- * it started on after React has already switched to the replacement cache.
773
- * Keep this link one-way so staging and settlement follow the visible data
774
- * without retaining an old cache from the new runtime.
775
- */
776
- private successor;
777
- private readonly inactiveTtlMs;
778
- private readonly onChangeHook;
779
- private readonly errorBus;
780
- private readonly mirror;
781
- private readonly mergeCell;
782
- private readonly apiName;
783
- private readonly recoveryStuckMs;
784
754
  constructor(options?: SubscriptionCacheOptions);
785
- private diagnose;
786
755
  /**
787
756
  * Register a subscriber. The cache forks the underlying fiber on the
788
757
  * first subscriber and re-uses it for the rest. Returns the snapshot
@@ -846,31 +815,6 @@ declare class SubscriptionCache {
846
815
  * resolve briefly exposes a stale base before the server delta lands.
847
816
  */
848
817
  confirmByMutation(mutationId: string): void;
849
- /**
850
- * The confirmed-patch window expired: a committed write never got its
851
- * superseding server event. Re-issue the affected subscriptions instead of
852
- * discarding the write's preview.
853
- *
854
- * Three things are load-bearing, and each was a way to reintroduce the bug:
855
- *
856
- * - **The patch is KEPT across the resync.** `refreshAll` already
857
- * establishes that shape ("the new base snapshot will land on top of
858
- * them"). Clearing it here would be the revert again, wearing a longer
859
- * word.
860
- * - **A stub entry — no `fetch`, no `runtime` — is left ALONE.** There is
861
- * nothing to re-issue, and the only other option is to show a base the
862
- * client knows is stale. Keeping the patch is the honest state.
863
- * - **It is LOUD.** The reporter found the jump only by reading minified
864
- * source, because in the UI it is indistinguishable from "the server did
865
- * not save it" — and that is the false trail they followed first. This
866
- * goes to the error bus, so it reaches `voltro logs` rather than only a
867
- * console nobody has open.
868
- *
869
- * No second timer is armed: this runs once per mutation, from the one
870
- * `confirmByMutation` scheduled it, so a server that never echoes cannot put
871
- * the client into a resync loop.
872
- */
873
- private resyncUnechoedMutation;
874
818
  /**
875
819
  * Auto-derive optimistic patches from a mutation's declared target(s).
876
820
  * Iterates every cache entry whose `source` table matches a target's
@@ -894,10 +838,6 @@ declare class SubscriptionCache {
894
838
  * {@link SubscriptionCache.autoApply}). Carried to a same-subject
895
839
  * replacement cache, so a stager can tell "already staged" from "new". */
896
840
  hasIntent(mutationId: string): boolean;
897
- private applyIntent;
898
- private applyStandingIntents;
899
- /** Drop a specific patch by id. */
900
- private revertPatch;
901
841
  /**
902
842
  * Read the current snapshot for a key WITHOUT subscribing. If the
903
843
  * entry doesn't exist, returns the "empty" snapshot (data=undefined,
@@ -944,40 +884,6 @@ declare class SubscriptionCache {
944
884
  * patches. Coalesce refreshes until that request answers or fails; never
945
885
  * interrupt an initial read merely because another refresh was requested. */
946
886
  refresh(key: ReadonlyArray<unknown>): boolean;
947
- /* Excluded from this release type: resumeTransportFailures */
948
- /**
949
- * The stall watchdog for one re-issued entry: `recoveryStuckMs` after the
950
- * re-issue with neither snapshot nor delta, the entry is reported stuck and
951
- * its subscribers are notified.
952
- *
953
- * That is a finding only if the watchdog itself ran on time. A browser
954
- * throttles timers in a hidden tab — to a one-second grid, then a one-minute
955
- * grid — so a timer there fires whenever the tab next wakes, and it used to
956
- * report the interval it was ARMED with as the interval waited. A delivery
957
- * queued behind the same throttling then arrived a moment after the warning
958
- * and the invalidation, under the same attempt: the watchdog had measured
959
- * its own delay and called it a stall.
960
- *
961
- * So the watchdog compares its due time with its fire time. Late beyond the
962
- * tolerance, or firing in a hidden tab, it does not judge: it records ONE
963
- * `recovery-timer-late` for the attempt (with how late, and whether hidden)
964
- * and re-arms. The first on-time fire in a visible tab decides — which gives
965
- * a delivery `recoveryStuckMs` of unthrottled time once the tab is looked at
966
- * again, and reports a real stall within that.
967
- */
968
- private armRecoveryWatchdog;
969
- /**
970
- * Re-issue ONE entry's subscription: interrupt the fiber, reset the base,
971
- * re-fork through the saved `fetch`.
972
- *
973
- * Extracted so `refreshAll` and the confirmed-patch resync cannot disagree
974
- * about it — and the thing they must agree on is that **optimistic patches
975
- * survive**. For a re-auth they belong to in-flight mutations; for the resync
976
- * they describe a write the server has already committed. Dropping them here
977
- * would be a revert with a longer name, which is the defect the resync exists
978
- * to remove.
979
- */
980
- private reissue;
981
887
  /**
982
888
  * Seed this (fresh) cache with the last-known-good rows held by the cache it
983
889
  * REPLACES, so a transport rebuild degrades to STALE DATA rather than to
@@ -1017,21 +923,6 @@ declare class SubscriptionCache {
1017
923
  * Returns the number of entries seeded (diagnostics / tests).
1018
924
  */
1019
925
  seedStaleFrom(previous: SubscriptionCache): number;
1020
- private create;
1021
- private createStub;
1022
- private freshState;
1023
- private startFiber;
1024
- private sourceTables;
1025
- private addIndex;
1026
- private removeIndex;
1027
- private orderedEntries;
1028
- private indexSource;
1029
- private appendPatch;
1030
- private replacePatches;
1031
- private indexPatches;
1032
- private registerEntry;
1033
- private unindexEntry;
1034
- private invalidate;
1035
926
  /**
1036
927
  * Every row of `table` this cache holds — the client's local replica of the
1037
928
  * table: the union of the rows of every entry sourced on that table ALONE
@@ -1045,12 +936,6 @@ declare class SubscriptionCache {
1045
936
  subscribeTable(table: string, listener: () => void): () => void;
1046
937
  /** Call `listener` after any entry changed. Returns the unsubscribe. */
1047
938
  subscribeAny(listener: () => void): () => void;
1048
- private getSnapshot;
1049
- private unsubscribe;
1050
- /** Start (or restart) the inactive-TTL countdown for `entry`: unless
1051
- * something subscribes first, interrupt its fiber and drop it. Shared by
1052
- * the last-subscriber-out path and by `seedStaleFrom`'s unclaimed seeds. */
1053
- private scheduleEviction;
1054
939
  }
1055
940
 
1056
941
  declare interface SubscriptionCacheOptions {
@@ -5,12 +5,13 @@ import { connectionScopeForRuntime as r } from "./connectionScope.js";
5
5
  import { resolveByTag as i } from "./tagWalk.js";
6
6
  import { runRpcPromise as a } from "./runRpc.js";
7
7
  import { ConnectionPrerequisite as o, ConnectionPrerequisiteInvalidated as s, SUPERSEDED_BY_LATER_ACTIVATION as c, activationEndReason as l } from "./connectionPrerequisite.js";
8
- import { settleMutation as u, startMutation as d } from "./mutationsBus.js";
9
- import { createConnectionSetupHandle as f } from "./mutationConnectionSetup.js";
10
- import { freshIdempotencyKey as p, withIdempotencyKey as m } from "./mutationIdentity.js";
11
- import { Cause as h, Effect as g, Exit as _ } from "effect";
8
+ import { captureRpcInvocationOwner as u, rpcInvocationOwnerCurrent as d } from "./awaitResolvedApi.js";
9
+ import { omitMutationInputs as f, startMutation as p } from "./mutationsBus.js";
10
+ import { createConnectionSetupHandle as m } from "./mutationConnectionSetup.js";
11
+ import { freshIdempotencyKey as h, withIdempotencyKey as g } from "./mutationIdentity.js";
12
+ import { Cause as _, Effect as v, Exit as y } from "effect";
12
13
  // src/connectionSetupController.ts
13
- var v = class {
14
+ var b = class {
14
15
  #e;
15
16
  #t;
16
17
  #n;
@@ -25,7 +26,7 @@ var v = class {
25
26
  #s;
26
27
  handle;
27
28
  constructor(e, t, n) {
28
- this.#e = e, this.#t = t, this.#n = n, this.handle = f(e, { capture: () => this.#f() });
29
+ this.#e = e, this.#t = t, this.#n = n, this.handle = m(e, { capture: () => this.#f() });
29
30
  }
30
31
  getSnapshot = () => this.#a;
31
32
  subscribe = (e) => (this.#r.add(e), () => {
@@ -33,7 +34,7 @@ var v = class {
33
34
  });
34
35
  clear = (e = !1) => {
35
36
  let t = this.#i;
36
- this.#i = void 0, this.#s = void 0, t?.detachSubject?.(), t?.controller.abort(e ? c : void 0), this.#h({
37
+ this.#i = void 0, this.#s = void 0, t && (t.initialDelivery = void 0), t?.detachSubject?.(), t?.controller.abort(e ? c : void 0), this.#h({
37
38
  status: "idle",
38
39
  data: void 0,
39
40
  error: void 0
@@ -41,25 +42,29 @@ var v = class {
41
42
  };
42
43
  async activate(e, t) {
43
44
  this.clear(!0);
44
- let n = new AbortController(), r = {
45
+ let n = new AbortController(), r = () => {}, i = new Promise((e) => {
46
+ r = e;
47
+ }), a = {
45
48
  input: e,
46
- key: p(),
49
+ key: h(),
47
50
  controller: n,
48
- subject: void 0,
51
+ owner: void 0,
49
52
  detachSubject: void 0,
50
53
  prerequisite: new o(n.signal, this.#c(this.#n()).options.replayWindowMs),
51
- established: !1
54
+ established: !1,
55
+ outputs: /* @__PURE__ */ new WeakMap(),
56
+ initialDelivery: r
52
57
  };
53
- this.#i = r, this.#h({
58
+ this.#i = a, this.#h({
54
59
  status: "pending",
55
60
  data: void 0,
56
61
  error: void 0
57
62
  });
58
63
  try {
59
- let e = await t(), n = await this.#p(r, e.runtime, e.client);
60
- return this.#l(r), r.prerequisite.assertCurrent(e.runtime, n), r.established = !0, n.output;
64
+ let e = await t(), n = await this.#p(a, e.runtime, e.client);
65
+ return this.#l(a), a.prerequisite.assertCurrent(e.runtime, n), a.established = !0, await i;
61
66
  } catch (e) {
62
- throw this.#i === r && (this.clear(), this.#h({
67
+ throw this.#l(a), this.#i === a && (this.clear(), this.#h({
63
68
  status: "error",
64
69
  data: void 0,
65
70
  error: e
@@ -70,7 +75,7 @@ var v = class {
70
75
  let t = r(e.runtime), n = () => {
71
76
  let n = this.#i;
72
77
  if (n === void 0 || !n.established || this.#n().runtime !== e.runtime) return;
73
- if (n.subject !== this.#c(e).subjectSignal) {
78
+ if (n.owner === void 0 || !d(n.owner, e)) {
74
79
  this.clear();
75
80
  return;
76
81
  }
@@ -92,15 +97,14 @@ var v = class {
92
97
  #u(e, t, n) {
93
98
  this.#l(e);
94
99
  let r = this.#n();
95
- if (e.subject !== void 0 && e.subject !== this.#c(r).subjectSignal) throw new s("inactive");
100
+ if (e.owner !== void 0 && !d(e.owner, r)) throw new s("inactive");
96
101
  if (r.runtime !== t || r.client !== n) throw new s("connection-changed");
97
102
  return r;
98
103
  }
99
104
  #d(e, t) {
100
- if (e.subject !== void 0) return;
101
- let n = this.#c(t).subjectSignal;
102
- e.subject = n;
103
- let r = () => {
105
+ if (e.owner !== void 0) return;
106
+ e.owner = u(t, this.#e, this.#t);
107
+ let n = e.owner.subject, r = () => {
104
108
  this.#i === e && this.clear();
105
109
  };
106
110
  n.addEventListener("abort", r, { once: !0 }), e.detachSubject = () => n.removeEventListener("abort", r), n.aborted && r();
@@ -110,10 +114,10 @@ var v = class {
110
114
  if (e === void 0) throw new s("inactive");
111
115
  return { prepare: async (t, n) => {
112
116
  let r = await this.#p(e, t, n);
113
- return { run: (i) => e.prerequisite.run(t, r, g.try({
117
+ return { run: (i) => e.prerequisite.run(t, r, v.try({
114
118
  try: () => this.#u(e, t, n),
115
119
  catch: (e) => e
116
- }).pipe(g.andThen(i))) };
120
+ }).pipe(v.andThen(i))) };
117
121
  } };
118
122
  }
119
123
  async #p(e, t, n) {
@@ -123,17 +127,17 @@ var v = class {
123
127
  let c = r(t);
124
128
  if (c === void 0) throw new s("connection-unavailable");
125
129
  if (c.getSnapshot() === void 0) {
126
- let n = g.callback((t) => {
130
+ let n = v.callback((t) => {
127
131
  let n = () => {
128
132
  let n = c.getSnapshot();
129
- e.controller.signal.aborted ? t(g.fail(new s(l(e.controller.signal)))) : n !== void 0 && t(g.succeed(n));
133
+ e.controller.signal.aborted ? t(v.fail(new s(l(e.controller.signal)))) : n !== void 0 && t(v.succeed(n));
130
134
  }, r = c.subscribe(n);
131
- return e.controller.signal.addEventListener("abort", n, { once: !0 }), n(), g.sync(() => {
135
+ return e.controller.signal.addEventListener("abort", n, { once: !0 }), n(), v.sync(() => {
132
136
  r(), e.controller.signal.removeEventListener("abort", n);
133
137
  });
134
- }).pipe(g.timeoutOrElse({
138
+ }).pipe(v.timeoutOrElse({
135
139
  duration: this.#c(i).options.replayWindowMs,
136
- orElse: () => g.fail(new s("timeout"))
140
+ orElse: () => v.fail(new s("timeout"))
137
141
  }));
138
142
  await a(t, n);
139
143
  }
@@ -141,55 +145,83 @@ var v = class {
141
145
  let u = c.getSnapshot();
142
146
  try {
143
147
  let r = await e.prerequisite.prepare(t, this.#m(e, i));
144
- return this.#u(e, t, n), this.#s = r.lease, this.#h({
148
+ return this.#u(e, t, n), this.#s = r.lease, this.#n().descriptors[this.#t]?.outputRetention === "none" && (e.outputs = /* @__PURE__ */ new WeakMap()), this.#h({
145
149
  status: "ready",
146
- data: r.output,
150
+ data: e.outputs.get(r.lease),
147
151
  error: void 0
148
152
  }), this.#u(e, t, n), e.prerequisite.assertCurrent(t, r), r;
149
- } catch (n) {
150
- throw this.#i === e && this.#n().runtime === t && c.getSnapshot() === u && this.#h({
153
+ } catch (r) {
154
+ throw this.#u(e, t, n), this.#i === e && this.#n().runtime === t && c.getSnapshot() === u && this.#h({
151
155
  status: "error",
152
156
  data: void 0,
153
- error: n
154
- }), n;
157
+ error: r
158
+ }), this.#u(e, t, n), r;
155
159
  }
156
160
  }
157
- #m(n, r) {
158
- return g.suspend(() => {
159
- let a = `setup_${n.key}_${++this.#o}`;
160
- return d({
161
- id: a,
161
+ #m(n, a) {
162
+ return v.suspend(() => {
163
+ let o = r(a.runtime)?.getSnapshot();
164
+ if (o === void 0) return v.fail(new s("connection-unavailable"));
165
+ let c = `setup_${n.key}_${++this.#o}`;
166
+ this.#u(n, a.runtime, a.client);
167
+ let l = n.owner?.subject;
168
+ if (l === void 0) throw new s("inactive");
169
+ let u = a.descriptors[this.#t]?.outputRetention === "none", d = !a.descriptors[this.#t] || a.descriptors[this.#t]?.clientHistory?.input === "omit", m = p({
170
+ id: c,
162
171
  apiName: this.#e,
163
172
  tag: this.#t,
164
- input: n.input
165
- }), g.suspend(() => {
166
- this.#u(n, r.runtime, r.client);
167
- let e = i(r.client, this.#t);
168
- return m(e(n.input), n.key);
169
- }).pipe(g.withSpan(`client.connectionSetup.${this.#t}`)).pipe(g.onExit((n) => g.sync(() => {
170
- if (_.isSuccess(n)) u(a, {
171
- status: "success",
172
- output: n.value
173
- }), r.errorBus.emitSuccess({
174
- source: "mutation",
175
- tag: this.#t
176
- });
177
- else {
178
- let i = e(n.cause);
179
- if (u(a, {
173
+ input: d ? void 0 : n.input,
174
+ ...d ? { inputOmitted: !0 } : {},
175
+ ...u ? { outputOmitted: !0 } : {}
176
+ }, l), h = () => {
177
+ try {
178
+ return this.#u(n, a.runtime, a.client), !0;
179
+ } catch {
180
+ return !1;
181
+ }
182
+ };
183
+ return v.suspend(() => {
184
+ this.#u(n, a.runtime, a.client);
185
+ let e = i(a.client, this.#t);
186
+ return g(e(n.input), n.key);
187
+ }).pipe(v.withSpan(`client.connectionSetup.${this.#t}`)).pipe(v.onExit((n) => v.sync(() => {
188
+ if (this.#n().descriptors[this.#t]?.clientHistory?.input === "omit" && f(this.#e, this.#t), y.isSuccess(n)) {
189
+ let e = u || this.#n().descriptors[this.#t]?.outputRetention === "none";
190
+ if (m.settle({
191
+ status: "success",
192
+ output: e ? void 0 : n.value,
193
+ ...e ? { outputOmitted: !0 } : {}
194
+ }), !h()) return;
195
+ a.errorBus.emitSuccess({
196
+ source: "mutation",
197
+ tag: this.#t
198
+ });
199
+ } else {
200
+ let r = e(n.cause);
201
+ if (m.settle({
180
202
  status: "error",
181
- error: i
182
- }), !h.hasInterruptsOnly(n.cause)) {
183
- let e = t(i, "handler");
184
- r.errorBus.emit({
203
+ error: r
204
+ }), h() && !_.hasInterruptsOnly(n.cause)) {
205
+ let e = t(r, "handler");
206
+ a.errorBus.emit({
185
207
  source: "mutation",
186
208
  tag: this.#t,
187
- error: i,
209
+ error: r,
188
210
  kind: e,
189
211
  outcome: e === "transport" ? "unknown" : "known"
190
212
  });
191
213
  }
192
214
  }
215
+ })), v.flatMap((e) => v.try({
216
+ try: () => {
217
+ this.#u(n, a.runtime, a.client);
218
+ let t = r(a.runtime)?.getSnapshot();
219
+ if (t !== o || o.signal.aborted) throw new s("connection-changed");
220
+ u || this.#n().descriptors[this.#t]?.outputRetention === "none" ? n.outputs = /* @__PURE__ */ new WeakMap() : n.outputs.set(t, e);
221
+ let i = n.initialDelivery;
222
+ n.initialDelivery = void 0, i?.(e);
223
+ },
224
+ catch: (e) => e
193
225
  })));
194
226
  });
195
227
  }
@@ -202,4 +234,4 @@ var v = class {
202
234
  }
203
235
  }
204
236
  };
205
- export { v as ConnectionSetupController };
237
+ export { b as ConnectionSetupController };