@voltro/client 0.27.0 → 0.29.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/dist/index.d.ts CHANGED
@@ -175,6 +175,13 @@ export declare interface ApiHandle {
175
175
  readonly errorBus: RpcErrorBus;
176
176
  }
177
177
 
178
+ /**
179
+ * Apply preload seeds from the hydration payload, BEFORE the first client
180
+ * render. Idempotent (a Map upsert) so a re-hydration or a repeated key is
181
+ * harmless — last write wins, matching the store-seed rule.
182
+ */
183
+ export declare const applyPreloadSeeds: (seeds: ReadonlyArray<PreloadSeed> | undefined) => void;
184
+
178
185
  /**
179
186
  * Apply seeds from the hydration payload, BEFORE the first client render.
180
187
  *
@@ -820,6 +827,8 @@ export declare class LoadingSubscriptionCache extends SubscriptionCache {
820
827
  };
821
828
  }
822
829
 
830
+ export declare const makePreloadSeedBag: () => PreloadSeedBag;
831
+
823
832
  export declare const makeStoreSeedBag: () => StoreSeedBag;
824
833
 
825
834
  /** Exported for tests: the inspect URL this hook fetches. */
@@ -1000,6 +1009,27 @@ export declare interface PersistOptions<S> {
1000
1009
  readonly migrate?: (stored: unknown) => Partial<S> | undefined;
1001
1010
  }
1002
1011
 
1012
+ /** Options `usePreloadedSubscription` accepts. It OWNS `initialSnapshot` (the
1013
+ * preload payload supplies it), so callers pass only `skip` — `fallback` and
1014
+ * `initialSnapshot` are its own concern. */
1015
+ export declare type PreloadedSubscriptionOptions = Pick<SubscriptionOptions<never>, 'skip'>;
1016
+
1017
+ /** One preloaded subscription snapshot, as it travels in the hydration payload. */
1018
+ export declare interface PreloadSeed {
1019
+ /** The api mount name the subscription reads from (first arg of `useSubscription`). */
1020
+ readonly api: string;
1021
+ /** `stableKey([rpcTag, input])` — identical to the SubscriptionCache's own key,
1022
+ * so the seed and the live subscription address the same entry. */
1023
+ readonly key: string;
1024
+ /** The server-fetched snapshot value. */
1025
+ readonly value: unknown;
1026
+ }
1027
+
1028
+ /** Collects preload seeds for ONE request. The server creates one per render. */
1029
+ export declare interface PreloadSeedBag {
1030
+ readonly seeds: PreloadSeed[];
1031
+ }
1032
+
1003
1033
  /** Structural mirror of @voltro/runtime's PreviewDiff (client stays decoupled). */
1004
1034
  export declare interface PreviewDiff {
1005
1035
  readonly rows: ReadonlyArray<PreviewRowDiff>;
@@ -1089,6 +1119,17 @@ export declare interface QueryFiltersState<Row> {
1089
1119
  readonly error: unknown | undefined;
1090
1120
  }
1091
1121
 
1122
+ /**
1123
+ * The preloaded snapshot for `(api, rpcTag, input)`, or `undefined` when none was
1124
+ * seeded. On the SERVER it reads the current request's bag directly, so the SSR
1125
+ * markup and the client hydration render see the SAME value (no hydration
1126
+ * flicker); on the CLIENT it reads the hydration-applied registry.
1127
+ *
1128
+ * A seed value is never `undefined` (it round-trips through JSON, so the worst
1129
+ * case is `null`), which is why `undefined` unambiguously means "not seeded".
1130
+ */
1131
+ export declare const readPreloadedSnapshot: (api: string, rpcTag: string, input: Readonly<Record<string, unknown>>) => unknown;
1132
+
1092
1133
  export declare interface RecordState<R> {
1093
1134
  readonly record: R | undefined;
1094
1135
  readonly loading: boolean;
@@ -1112,6 +1153,9 @@ export declare const reportClientError: (error: unknown, context?: Record<string
1112
1153
  * module-global flags + any pending grace-period timer). */
1113
1154
  export declare const _resetFrameworkRuntimesWarning: () => void;
1114
1155
 
1156
+ /** Drop all applied client-side seeds. Tests only. */
1157
+ export declare const resetPreloadSeeds: () => void;
1158
+
1115
1159
  /** Test helper: forget every defined store. NEVER call this in app code. */
1116
1160
  export declare const resetStoreRegistryForTests: () => void;
1117
1161
 
@@ -1282,6 +1326,14 @@ export declare const schemaToColumns: (schema: Schema.Schema.Any) => ReadonlyArr
1282
1326
  */
1283
1327
  export declare const schemaToFields: (schema: Schema.Schema.Any) => ReadonlyArray<FieldDescriptor>;
1284
1328
 
1329
+ /**
1330
+ * Seed a subscription's first value for THIS request's hydration. Call it on the
1331
+ * server during a render — a loader, a layout loader — with the value a
1332
+ * `ctx.query` already fetched, and `usePreloadedSubscription(api, rpcTag, input)`
1333
+ * shows it at the first paint without any serialization step of your own.
1334
+ */
1335
+ export declare const seedPreloadedSubscription: (api: string, rpcTag: string, input: Readonly<Record<string, unknown>>, value: unknown) => void;
1336
+
1285
1337
  /**
1286
1338
  * Seed a store for THIS request's hydration. Call it anywhere on the server
1287
1339
  * during a render — a loader, a layout loader — and the value reaches the
@@ -1351,6 +1403,12 @@ export declare type SequenceResult<Ctx> = {
1351
1403
  * at boot, next to your toast provider. */
1352
1404
  export declare const setMutationNotifier: (notifier: MutationNotifier | undefined) => void;
1353
1405
 
1406
+ /**
1407
+ * Install the request-scoped bag resolver. Server-side only; pass `null` to
1408
+ * uninstall (tests). `@voltro/web/ssr` registers it, backed by its own ALS.
1409
+ */
1410
+ export declare const setPreloadSeedResolver: (resolver: (() => PreloadSeedBag | null) | null) => void;
1411
+
1354
1412
  /**
1355
1413
  * Install the request-scoped bag resolver. Server-side only; pass `null` to
1356
1414
  * uninstall (tests).
@@ -2134,13 +2192,6 @@ export declare interface UploadResult {
2134
2192
 
2135
2193
  export declare type UploadStatus = 'idle' | 'uploading' | 'success' | 'error';
2136
2194
 
2137
- /**
2138
- * Invoke a server `defineAction` procedure by tag. Unlike `useMutation`,
2139
- * an action has no optimistic / cache surface — it's a unary call whose
2140
- * effects (sends, captures, side-effecting writes the framework must NOT
2141
- * preview locally) only become visible when the server pushes a delta on
2142
- * an independent subscription.
2143
- */
2144
2195
  export declare const useAction: <Input = unknown, Output = unknown>(apiName: string, rpcTag: string) => ActionState<Input, Output>;
2145
2196
 
2146
2197
  export declare const useAgent: (apiName: string, rpcTag: string) => AgentControls;
@@ -2332,6 +2383,19 @@ export declare interface UseOutboxOptions {
2332
2383
  /** The current subject's scopes (defaults to none if no provider). */
2333
2384
  export declare const usePermissions: () => PermissionState_2;
2334
2385
 
2386
+ /**
2387
+ * Subscribe to a streaming rpc, seeding the first value from the SSR preload
2388
+ * payload when one exists.
2389
+ *
2390
+ * @param apiName The api mount name (as in `useSubscription`).
2391
+ * @param rpcTag The rpc tag (e.g. `'projects.list'`).
2392
+ * @param input The rpc payload; part of the preload lookup key AND the
2393
+ * subscription's cache key (identical `stableKey`).
2394
+ * @param options `{ skip }` — defers the subscription. `initialSnapshot`
2395
+ * comes from the preload payload, not from here.
2396
+ */
2397
+ export declare function usePreloadedSubscription<T = unknown>(apiName: string, rpcTag: string, input?: Readonly<Record<string, unknown>>, options?: PreloadedSubscriptionOptions): SubscriptionState<T> | SubscriptionIdle;
2398
+
2335
2399
  export declare const usePreview: <Input = Record<string, unknown>>(apiName: string, previewTag: string) => PreviewState<Input>;
2336
2400
 
2337
2401
  export declare const useProvenance: (apiName: string, table: string, id: string, column?: string) => ProvenanceState;