@lunora/client 1.0.0-alpha.4 → 1.0.0-alpha.41

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.
Files changed (85) hide show
  1. package/LICENSE.md +6 -0
  2. package/README.md +2 -0
  3. package/dist/auth/index.d.mts +11 -10
  4. package/dist/auth/index.d.ts +11 -10
  5. package/dist/auth/index.mjs +1 -60
  6. package/dist/index.d.mts +736 -172
  7. package/dist/index.d.ts +736 -172
  8. package/dist/index.mjs +1 -14
  9. package/dist/packem_shared/CONFLICT_ERROR_CODE-B2SU0CaJ.mjs +1 -0
  10. package/dist/packem_shared/ClientServiceWorker-CRQ5yl7-.mjs +1 -0
  11. package/dist/packem_shared/DEFAULT_MAX_BUFFER-TBn2s7Rz.mjs +1 -0
  12. package/dist/packem_shared/LunoraClient-CB5y0HME.mjs +1 -0
  13. package/dist/packem_shared/OfflineQueue-y4mymc5n.mjs +1 -0
  14. package/dist/packem_shared/RETIRE_AFTER_DURABLE_SEQ_ADVANCE-D96iRJDY.mjs +1 -0
  15. package/dist/packem_shared/SKIP-CArzT3Vl.mjs +1 -0
  16. package/dist/packem_shared/SubscriptionRegistry-C72rCp44.mjs +1 -0
  17. package/dist/packem_shared/TabCoordinator-CMFYQCL-.mjs +1 -0
  18. package/dist/packem_shared/anyApi-BD4dgvDY.mjs +1 -0
  19. package/dist/packem_shared/applyDelta-DXqQORbM.mjs +1 -0
  20. package/dist/packem_shared/createAsyncStoragePersistence-BRLqeXsC.mjs +1 -0
  21. package/dist/packem_shared/createClientQuery-CrdRoicO.mjs +1 -0
  22. package/dist/packem_shared/createInMemoryBookmarkStorage-DCd5Ej-t.mjs +1 -0
  23. package/dist/packem_shared/createInMemoryPersistence-CQYXy8UP.mjs +1 -0
  24. package/dist/packem_shared/createInMemoryQueryCache-DjCKrLjk.mjs +1 -0
  25. package/dist/packem_shared/createLocalStore-CwuKPK9x.mjs +1 -0
  26. package/dist/packem_shared/createMutationRunner-lQXH8Amk.mjs +1 -0
  27. package/dist/packem_shared/createMutatorRunner-BVzo0FBZ.mjs +1 -0
  28. package/dist/packem_shared/createReconnect-CFT7YRSR.mjs +1 -0
  29. package/dist/packem_shared/createReply-DF0jRsv-.mjs +1 -0
  30. package/dist/packem_shared/createServerClient-C1At_rrh.mjs +1 -0
  31. package/dist/packem_shared/createSnapshotPrecondition-CKvCNKyD.mjs +1 -0
  32. package/dist/packem_shared/deserializePreloaded-CHfOFpka.mjs +1 -0
  33. package/dist/packem_shared/getServerSession-CGjgRBAE.mjs +1 -0
  34. package/dist/packem_shared/httpStream-Cz4_QyjV.mjs +11 -0
  35. package/dist/packem_shared/idb-utility-C-DR8nG1.mjs +1 -0
  36. package/dist/packem_shared/local-store-DFMSEM2j.mjs +1 -0
  37. package/dist/packem_shared/lunora-client.d-D_WLwpn0.d.mts +2175 -0
  38. package/dist/packem_shared/lunora-client.d-cFPjoyDb.d.ts +2175 -0
  39. package/dist/packem_shared/offline-queue-BeWay5u5.mjs +1 -0
  40. package/dist/packem_shared/preload.d-BkbCVtZe.d.ts +21 -0
  41. package/dist/packem_shared/preload.d-DNxm6niZ.d.mts +21 -0
  42. package/dist/packem_shared/preloadQuery-DjwSjFwt.mjs +1 -0
  43. package/dist/packem_shared/types.d-CA7ZeJm9.d.mts +942 -0
  44. package/dist/packem_shared/types.d-CA7ZeJm9.d.ts +942 -0
  45. package/dist/packem_shared/wire-codec-D_fiax9d.mjs +1 -0
  46. package/dist/packem_shared/wire-key-j8BZ65HQ.mjs +1 -0
  47. package/dist/pagination/index.d.mts +42 -42
  48. package/dist/pagination/index.d.ts +42 -42
  49. package/dist/pagination/index.mjs +1 -61
  50. package/dist/query/index.d.mts +43 -42
  51. package/dist/query/index.d.ts +43 -42
  52. package/dist/query/index.mjs +1 -1
  53. package/dist/service.d.mts +49 -0
  54. package/dist/service.d.ts +49 -0
  55. package/dist/service.mjs +1 -0
  56. package/dist/ssr/index.d.mts +80 -79
  57. package/dist/ssr/index.d.ts +80 -79
  58. package/dist/ssr/index.mjs +1 -4
  59. package/dist/upload.d.mts +35 -0
  60. package/dist/upload.d.ts +35 -0
  61. package/dist/upload.mjs +1 -0
  62. package/package.json +13 -1
  63. package/dist/packem_shared/CONFLICT_ERROR_CODE-aUdVbEDw.mjs +0 -4
  64. package/dist/packem_shared/DEFAULT_MAX_BUFFER-BDkqO5PW.mjs +0 -107
  65. package/dist/packem_shared/LunoraClient-DHMV-94j.mjs +0 -2198
  66. package/dist/packem_shared/OfflineQueue-D5p_QgF_.mjs +0 -127
  67. package/dist/packem_shared/SKIP-vItZChkw.mjs +0 -50
  68. package/dist/packem_shared/SubscriptionRegistry-Dn-7k7eo.mjs +0 -1
  69. package/dist/packem_shared/applyDelta-4jFGTPA3.mjs +0 -61
  70. package/dist/packem_shared/createAsyncStoragePersistence-1Z5BZ8RC.mjs +0 -45
  71. package/dist/packem_shared/createInMemoryBookmarkStorage-BoN7a7TH.mjs +0 -11
  72. package/dist/packem_shared/createInMemoryPersistence-CW82inU5.mjs +0 -105
  73. package/dist/packem_shared/createInMemoryQueryCache-B1PQ9Twl.mjs +0 -138
  74. package/dist/packem_shared/createLocalStore-DSUfoLqY.mjs +0 -36
  75. package/dist/packem_shared/createMutationRunner-BqsavzvG.mjs +0 -21
  76. package/dist/packem_shared/createReconnect-Di_-oHH7.mjs +0 -22
  77. package/dist/packem_shared/createServerClient-DMh-2UDv.mjs +0 -11
  78. package/dist/packem_shared/deserializePreloaded-C0eJTY_W.mjs +0 -4
  79. package/dist/packem_shared/getServerSession-8jXewqxd.mjs +0 -13
  80. package/dist/packem_shared/lunora-client.d-CbnxmuqG.d.mts +0 -1623
  81. package/dist/packem_shared/lunora-client.d-CbnxmuqG.d.ts +0 -1623
  82. package/dist/packem_shared/preload.d-Bhq6DBSe.d.mts +0 -20
  83. package/dist/packem_shared/preload.d-C73DT6bL.d.ts +0 -20
  84. package/dist/packem_shared/preloadQuery-lobFkD2Z.mjs +0 -13
  85. package/dist/packem_shared/subscription-C1Jy7HiF.mjs +0 -55
@@ -0,0 +1,942 @@
1
+ /** The registered function kinds a {@link FunctionReference} can describe. `stream` is a query that yields multiple frames over the WS. */
2
+ type FunctionKind = "action" | "mutation" | "query" | "stream";
3
+ /**
4
+ * Opaque reference to a registered function emitted by `@lunora/codegen`.
5
+ *
6
+ * At runtime it carries the `<file>:<function>` identifier in `__lunoraRef`.
7
+ * Generated declarations decorate this with phantom type parameters so the
8
+ * client can infer args / return values per call site.
9
+ */
10
+ interface FunctionReference<Kind extends FunctionKind = FunctionKind, Args = unknown, Return = unknown> {
11
+ /**
12
+ * Phantom marker carrying the `Kind`/`Args`/`Return` type parameters for
13
+ * inference. Never present at runtime; declared as a covariant (output)
14
+ * position so a concrete reference stays assignable to a widened one.
15
+ */
16
+ readonly __lunoraPhantom?: {
17
+ args: Args;
18
+ kind: Kind;
19
+ returns: Return;
20
+ };
21
+ readonly __lunoraRef: string;
22
+ }
23
+ /** Extract the args type from a {@link FunctionReference}. */
24
+ type ArgsOf<F> = F extends FunctionReference<infer _K, infer A, infer _R> ? A : never;
25
+ /** Extract the return type from a {@link FunctionReference}. */
26
+ type ReturnOf<F> = F extends FunctionReference<infer _K, infer _A, infer R> ? R : never;
27
+ /**
28
+ * Typed reference to an HTTP-SSE stream route (`httpRoute.<verb>(path).stream()`)
29
+ * emitted by `@lunora/codegen` as `httpStreams.<namespace>.<name>`.
30
+ *
31
+ * Distinct from {@link FunctionReference}: this is the **HTTP-SSE route stream**
32
+ * (opened with `fetch` + `ReadableStream` against the route's own URL), not the
33
+ * WS procedure stream (`kind: "stream"`). At runtime it carries the HTTP verb
34
+ * and the route path; the phantom marker carries the chunk / searchParams /
35
+ * params types so `httpStream` (and the framework hooks over it) infer the
36
+ * chunk type end-to-end.
37
+ * @experimental Reconnect/POST-body/wire-fidelity design questions are still open, so the shape may change.
38
+ */
39
+ interface HttpStreamRef<Chunk = unknown, SearchParams = unknown, Params = unknown> {
40
+ /**
41
+ * Phantom marker carrying the `Chunk`/`SearchParams`/`Params` type
42
+ * parameters for inference. Never present at runtime; declared in a
43
+ * covariant (output) position so a concrete reference stays assignable to
44
+ * a widened one.
45
+ */
46
+ readonly __lunoraHttpStream?: {
47
+ chunk: Chunk;
48
+ params: Params;
49
+ searchParams: SearchParams;
50
+ };
51
+ /** HTTP verb the route binds to (uppercased), e.g. `"GET"`. */
52
+ readonly method: string;
53
+ /** The route path as declared, e.g. `/api/tokens/:id` — `:name` segments are filled from `params`. */
54
+ readonly path: string;
55
+ }
56
+ /**
57
+ * The call-side args of an HTTP-SSE stream route: `:name` path params plus URL query params.
58
+ * @experimental Part of the HTTP-SSE stream surface.
59
+ */
60
+ interface HttpStreamCallArgs<SearchParams = unknown, Params = unknown> {
61
+ /** Values for the route path's `:name` segments. */
62
+ params?: Params;
63
+ /** URL query params, appended to the request URL (undefined entries are skipped). */
64
+ searchParams?: SearchParams;
65
+ }
66
+ /**
67
+ * Extract the chunk type from a {@link HttpStreamRef}.
68
+ * @experimental Part of the HTTP-SSE stream surface.
69
+ */
70
+ type HttpStreamChunkOf<R> = R extends HttpStreamRef<infer Chunk, infer _S, infer _P> ? Chunk : never;
71
+ /**
72
+ * Extract the call-side args type from a {@link HttpStreamRef}.
73
+ * @experimental Part of the HTTP-SSE stream surface.
74
+ */
75
+ type HttpStreamArgsOf<R> = R extends HttpStreamRef<infer _C, infer S, infer P> ? HttpStreamCallArgs<S, P> : never;
76
+ type Unsubscribe = () => void;
77
+ /**
78
+ * Serializable result of `preloadQuery`. Produced on the server during SSR,
79
+ * embedded in the rendered HTML, then handed to `usePreloadedQuery` on the
80
+ * client so the first render shows the server value with no loading flash
81
+ * before a live subscription attaches. Every field survives `JSON.stringify`.
82
+ */
83
+ interface Preloaded<T = unknown> {
84
+ readonly __lunoraPreloaded: true;
85
+ readonly args: Record<string, unknown>;
86
+ readonly functionPath: string;
87
+ readonly shardKey?: string;
88
+ readonly value: T;
89
+ }
90
+ /**
91
+ * Pluggable storage for the `x-d1-bookmark` value used to provide
92
+ * read-your-writes between a mutation and subsequent queries.
93
+ */
94
+ interface BookmarkStorage {
95
+ get: () => string | null;
96
+ set: (value: string | null) => void;
97
+ }
98
+ interface ReconnectOptions {
99
+ initialDelayMs?: number;
100
+ jitter?: boolean;
101
+ maxDelayMs?: number;
102
+ }
103
+ /** Which durable-storage operation failed, passed to {@link OfflineQueueOptions.onPersistenceError}. */
104
+ type PersistenceOperation = "append" | "clear" | "load" | "remove";
105
+ /** Context handed to a persistence-error handler. */
106
+ interface PersistenceErrorContext {
107
+ readonly error: unknown;
108
+ /** The mutation id involved, when the failing op was scoped to one (`append`/`remove`). */
109
+ readonly mutationId?: string;
110
+ readonly operation: PersistenceOperation;
111
+ }
112
+ interface OfflineQueueOptions {
113
+ maxItems?: number;
114
+ /**
115
+ * Invoked when a {@link PersistenceAdapter} call rejects (e.g. IndexedDB quota
116
+ * exceeded). Without a handler, failures are logged via `console.warn` so they
117
+ * are never fully silent. Note: a failed `append` means the write is queued in
118
+ * memory but NOT durable — it will not survive a reload.
119
+ */
120
+ onPersistenceError?: (context: PersistenceErrorContext) => void;
121
+ /**
122
+ * Queue mutations issued before a shard's first successful WebSocket
123
+ * connect (defaults to `false`). The standard behaviour (`LunoraClient`'s
124
+ * `mutation()`) queues only when the targeted shard has been connected at
125
+ * least once (`wasEverConnected`), so the registry / resubscribe handshake
126
+ * has run. Set this to `true` for offline-first apps that want to enqueue
127
+ * writes on the very first session before the WS is up.
128
+ */
129
+ queueBeforeFirstConnect?: boolean;
130
+ }
131
+ /**
132
+ * Serializable shape of an offline mutation, durably stored by a
133
+ * {@link PersistenceAdapter} so queued writes survive a reload/crash. The live
134
+ * `resolve`/`reject` callbacks of an in-flight `QueuedMutation` are *not*
135
+ * persisted — a restored mutation is replayed with no original awaiter.
136
+ */
137
+ interface PersistedMutation {
138
+ args: Record<string, unknown>;
139
+ functionPath: string;
140
+ id: string;
141
+ /**
142
+ * Issuing identity fingerprint, persisted so a hydrated write replays only
143
+ * under the identity that queued it (`null` = queued while signed out).
144
+ * Absent on records written by older client versions, which replay under
145
+ * the ambient identity for back-compat.
146
+ */
147
+ identity?: string | null;
148
+ shardKey?: string;
149
+ /**
150
+ * App/schema version stamped at enqueue (from `LunoraClientOptions.persistenceVersion`).
151
+ * On hydrate, a record whose `version` doesn't match the current one is dropped
152
+ * and purged rather than replayed — so a write persisted by an older deploy
153
+ * (with a now-changed function signature) can't replay against the new schema.
154
+ * Absent when no `persistenceVersion` is configured (no version gating).
155
+ */
156
+ version?: string;
157
+ }
158
+ /**
159
+ * Durable store for the offline mutation queue. The default client keeps the
160
+ * queue in memory; supplying an adapter (e.g. `createIndexedDbPersistence`)
161
+ * makes queued writes survive a page reload. Implementations must preserve FIFO
162
+ * (enqueue) order in `PersistenceAdapter.load`.
163
+ *
164
+ * Replay semantics are at-least-once: a mutation is removed only after the
165
+ * server confirms (or rejects) it, so a crash between commit and `remove` can
166
+ * replay it again on the next load.
167
+ */
168
+ interface PersistenceAdapter {
169
+ /** Append a mutation to durable storage (called on enqueue). */
170
+ append: (mutation: PersistedMutation) => Promise<void>;
171
+ /** Drop every persisted mutation (e.g. on logout). */
172
+ clear: () => Promise<void>;
173
+ /** Load all persisted mutations in FIFO order — called once at startup. */
174
+ load: () => Promise<PersistedMutation[]>;
175
+ /** Remove a mutation by id once it has been replayed (resolved or rejected). */
176
+ remove: (id: string) => Promise<void>;
177
+ }
178
+ /**
179
+ * One write handed to an {@link OutboxSink}. Mirrors {@link PersistedMutation}
180
+ * plus the custom-mutator identity (`clientId`/`mutationId`/`idempotencyKey`)
181
+ * the durable outbox needs to dedupe and watermark replays.
182
+ */
183
+ interface OutboxMutation {
184
+ args: Record<string, unknown>;
185
+ /** Stable per-client id; pairs with {@link OutboxMutation.mutationId} as `idempotencyKey`. */
186
+ clientId: string;
187
+ functionPath: string;
188
+ /** `${clientId}:${mutationId}` — sent as `x-lunora-mutation-id` so a replay is server-idempotent. */
189
+ idempotencyKey: string;
190
+ /** Issuing identity fingerprint (`null` = signed out); drives the sink's identity guard. */
191
+ identity: string | null;
192
+ /** Monotonic per-client mutation id, backing the server `__client_watermark`. */
193
+ mutationId: number;
194
+ shardKey?: string;
195
+ }
196
+ /**
197
+ * Pluggable durable outbox seam. When set on {@link LunoraClientOptions.outbox},
198
+ * the client delegates offline write durability + at-least-once replay to this
199
+ * sink instead of its built-in {@link PersistenceAdapter}-backed `OfflineQueue`.
200
+ * `@lunora/db` supplies the blessed implementation (`createExecutorOutboxSink`,
201
+ * backed by the TanStack `OfflineExecutor`); the interface itself is
202
+ * dependency-free so `@lunora/client` stays TanStack-free.
203
+ */
204
+ interface OutboxSink {
205
+ /**
206
+ * Persist and schedule a write for replay. Rejects with an
207
+ * `OFFLINE_QUEUE_OVERFLOW`-coded error when the sink's cap is exceeded, so
208
+ * the caller can surface back-pressure to the issuing mutation.
209
+ */
210
+ enqueue: (mutation: OutboxMutation) => Promise<void>;
211
+ }
212
+ /**
213
+ * One persisted query result in the durable read cache (Pillar 2). Keyed in the
214
+ * store by `shardKey + functionPath + argsKey`; the record carries everything
215
+ * needed to render offline on reload and to resume the live subscription.
216
+ */
217
+ interface CachedQuery {
218
+ /**
219
+ * Issuing identity fingerprint (same shape the offline queue stamps). A
220
+ * cached value only hydrates when it matches the current identity, so a
221
+ * signed-out cache never leaks into a new session. `null` = cached while
222
+ * signed out.
223
+ */
224
+ identity: string | null;
225
+ /**
226
+ * The `cursor` high-watermark this value reflects, replayed as `sinceSeq`
227
+ * on reconnect so the server can resume instead of re-snapshotting. Absent
228
+ * when the value predates CDC / no cursor was advertised.
229
+ */
230
+ serverCursor?: number;
231
+ /**
232
+ * The CDC `epoch` the `serverCursor` belongs to, replayed as `sinceEpoch`
233
+ * on reconnect so the server only resumes when the client is still on the
234
+ * same changelog timeline. Absent when no epoch was advertised.
235
+ */
236
+ serverEpoch?: string;
237
+ /** Wall-clock millis the value was written — drives LRU eviction. */
238
+ ts: number;
239
+ /** The full query result last seen from the server. */
240
+ value: unknown;
241
+ /**
242
+ * App/schema version stamped when persisted (from `LunoraClientOptions.persistenceVersion`).
243
+ * A cached value whose `version` doesn't match the current one is not hydrated —
244
+ * so a result of a now-changed shape from an older deploy can't render. Absent
245
+ * when no `persistenceVersion` is configured (no version gating).
246
+ */
247
+ version?: string;
248
+ }
249
+ /**
250
+ * Durable store for the client read cache (Pillar 2): query results survive a
251
+ * reload so reads hydrate from disk and render immediately while the socket
252
+ * reconnects. Opt-in via {@link LunoraClientOptions.queryCache}; omit to keep
253
+ * reads in memory only (today's behaviour). Mirrors {@link PersistenceAdapter}'s
254
+ * shape over the same IndexedDB plumbing.
255
+ */
256
+ interface QueryCacheAdapter {
257
+ /** Drop every cached query (e.g. on logout / identity change). */
258
+ clear: () => Promise<void>;
259
+ /** Load every cached query — called once at startup to hydrate reads. */
260
+ load: () => Promise<(CachedQuery & {
261
+ key: string;
262
+ })[]>;
263
+ /** Upsert one cached query by key (called when a subscription value advances). */
264
+ put: (key: string, entry: CachedQuery) => Promise<void>;
265
+ /** Remove one cached query by key. */
266
+ remove: (key: string) => Promise<void>;
267
+ }
268
+ /**
269
+ * Resolves the WS `?token=` credential fresh at every (re)connect — the channel
270
+ * for short-lived tokens (e.g. the ephemeral admin sub-token the worker mints
271
+ * at `POST /_lunora/admin/ws-token`) instead of a static secret in the URL.
272
+ * May return the token synchronously or as a Promise; returning `undefined`
273
+ * connects without a token. A thrown error / rejected Promise fails that
274
+ * connect attempt, and the client retries with its normal reconnect backoff.
275
+ */
276
+ type WsTokenProvider = () => Promise<string | undefined> | string | undefined;
277
+ interface LunoraClientOptions {
278
+ /**
279
+ * Base path the worker mounts better-auth at, used by the client's
280
+ * `getCurrentUser()` to reach the `get-session` route. Defaults to
281
+ * `/api/auth` (matching `@lunora/auth`'s `DEFAULT_AUTH_BASE_PATH`).
282
+ */
283
+ authBasePath?: string;
284
+ bookmarkStorage?: BookmarkStorage;
285
+ /**
286
+ * Stable per-client id backing the custom-mutator watermark. Sent on the
287
+ * `connect` envelope (so the server can scope this client's
288
+ * `__client_watermark`) and stamped onto every {@link OutboxMutation} the
289
+ * {@link LunoraClientOptions.outbox} sink persists, where it pairs with the
290
+ * monotonic mutation id to form the idempotency key. The `@lunora/db` path
291
+ * persists a stable id alongside the outbox and passes it here; omit for the
292
+ * standalone client, which generates an ephemeral per-session id.
293
+ */
294
+ clientId?: string;
295
+ /**
296
+ * Default app context sent in the `connect` envelope right after each socket
297
+ * opens, forwarded to the server's `onConnect`/`onDisconnect` lifecycle hooks
298
+ * as `event.context`. A per-shard context registered via
299
+ * `setConnectionContext` overrides this for that shard. Omit when no lifecycle
300
+ * hook needs connection context.
301
+ */
302
+ connectionContext?: Record<string, unknown>;
303
+ /**
304
+ * Fail-fast timeout (ms) for opening a subscription WebSocket. If the
305
+ * handshake doesn't complete within this window — a hung dev proxy or a cold
306
+ * worker that never upgrades — the client force-closes the socket and routes
307
+ * through its normal reconnect/backoff (surfacing `offline` status) instead
308
+ * of leaving the live channel silently stuck on the browser's much longer
309
+ * default. Does not affect HTTP queries/mutations (those never ride the WS).
310
+ * Defaults to 10000 (10s); set to `0` (or negative) to disable.
311
+ */
312
+ connectTimeoutMs?: number;
313
+ /**
314
+ * When `true`, tabs sharing the same origin coordinate via BroadcastChannel
315
+ * so only one tab (the "leader") opens WebSocket connections to the server.
316
+ * Follower tabs receive subscription data through the channel instead.
317
+ *
318
+ * Reduces simultaneous WS connections, bandwidth, and cross-tab state drift.
319
+ * Requires `BroadcastChannel` (browser-only); silently ignored otherwise.
320
+ * Defaults to `false`.
321
+ */
322
+ crossTabSync?: boolean;
323
+ fetch?: typeof fetch;
324
+ /**
325
+ * Interval (ms) between keepalive pings sent on each open subscription
326
+ * socket. The server answers them via the Durable Object's hibernation
327
+ * auto-response WITHOUT waking the DO, so an idle socket stays alive across
328
+ * hibernation without a billable wakeup. Defaults to 30000 (30s); set to
329
+ * `0` (or a negative value) to disable the heartbeat entirely.
330
+ */
331
+ heartbeatIntervalMs?: number;
332
+ /**
333
+ * When `true` and a `queryCache` is active, framework hooks (React, Vue, …)
334
+ * wait for the durable cache to finish hydrating before their first render
335
+ * with an enabled subscription, so users see cached data instead of an
336
+ * undefined flash before the socket round-trip. Defaults to `false`.
337
+ *
338
+ * Requires `queryCache` to be set (not `false`); silently ignored otherwise.
339
+ */
340
+ hydrateOnStart?: boolean;
341
+ offlineQueue?: OfflineQueueOptions;
342
+ /**
343
+ * Durable outbox seam for offline writes. When supplied (the `@lunora/db`
344
+ * path wires `createExecutorOutboxSink`), offline mutations are delegated to
345
+ * the sink and the built-in {@link PersistenceAdapter}-backed `OfflineQueue`
346
+ * is bypassed, so a db app has exactly one durable write path. Omit for the
347
+ * standalone client, which keeps using {@link LunoraClientOptions.persistence}.
348
+ */
349
+ outbox?: OutboxSink;
350
+ /**
351
+ * Durable store for the offline mutation queue. Tri-state — an explicit
352
+ * {@link PersistenceAdapter} is used as-is; `false` opts out (the queue stays
353
+ * in memory, lost on reload); omitted (the default) auto-probes a durable
354
+ * IndexedDB store when the `indexedDB` global is present (browsers), otherwise
355
+ * in-memory, so SSR/Node/React-Native keep the in-memory behaviour and only
356
+ * environments that can persist do. Pass `createAsyncStoragePersistence()` on
357
+ * React Native.
358
+ */
359
+ persistence?: false | PersistenceAdapter;
360
+ /**
361
+ * App/schema version stamped onto every persisted queued write and cached
362
+ * read. Bump it on a breaking change to a function signature or query shape:
363
+ * on the next boot, persisted writes / cached reads stamped with a different
364
+ * version are dropped (and purged) rather than replayed / hydrated against the
365
+ * new schema. Omit to disable version gating (records are never invalidated by
366
+ * version).
367
+ *
368
+ * **Adoption is itself an invalidation event:** records written before you set
369
+ * `persistenceVersion` carry no version, so the first boot after enabling it
370
+ * purges all currently-queued offline writes (and cached reads) as stale. Adopt
371
+ * it on a build where that clean slate is acceptable — typically the same
372
+ * breaking deploy you're protecting against — not purely speculatively.
373
+ */
374
+ persistenceVersion?: string;
375
+ /**
376
+ * Durable store for the read cache (Pillar 2). When active, query results
377
+ * are persisted as their subscriptions advance and hydrated on construction
378
+ * so a reload renders cached data before the socket reconnects, then resumes
379
+ * the live subscription from the persisted cursor. Tri-state — an explicit
380
+ * {@link QueryCacheAdapter} is used as-is; `false` opts out (reads stay in
381
+ * memory only); omitted (the default) auto-probes IndexedDB exactly like
382
+ * {@link LunoraClientOptions.persistence}.
383
+ */
384
+ queryCache?: QueryCacheAdapter | false;
385
+ reconnect?: ReconnectOptions;
386
+ url: string;
387
+ WebSocket?: typeof WebSocket;
388
+ /**
389
+ * Credential appended to the WebSocket URL as `?token=…`. The server matches
390
+ * it against `LUNORA_WS_BEARER` (to clear the upgrade gate) and/or
391
+ * `LUNORA_ADMIN_TOKEN` (to authorize `__lunora_admin__:*` subscriptions —
392
+ * what the studio supplies). Browsers can't set headers on the `WebSocket`
393
+ * constructor, so the query parameter is the only channel; it ends up in
394
+ * server logs and history, so prefer a short-lived rotating token in
395
+ * production over a static secret.
396
+ *
397
+ * Pass a {@link WsTokenProvider} function to resolve the token fresh at
398
+ * every (re)connect — the channel for short-lived credentials such as the
399
+ * ephemeral admin sub-token minted by `POST /_lunora/admin/ws-token`: the
400
+ * provider re-mints on each reconnect, including the one following a `4001`
401
+ * token-expired drop, so a static master token never has to ride the URL.
402
+ */
403
+ wsToken?: string | WsTokenProvider;
404
+ wsUrl?: string;
405
+ }
406
+ /** Wire envelope sent on `POST /_lunora/rpc`. */
407
+ interface RpcEnvelope {
408
+ args?: Record<string, unknown>;
409
+ /**
410
+ * Stable per-client identifier (custom-mutator push path). Pairs with
411
+ * {@link RpcEnvelope.mutationId} to form `idempotencyKey` and scope the
412
+ * server `__client_watermark`. Absent on plain `client.mutation` calls.
413
+ */
414
+ clientId?: string;
415
+ functionPath: string;
416
+ /**
417
+ * Idempotency key (`${clientId}:${mutationId}`) for the custom-mutator push
418
+ * path, mirrored into the `x-lunora-mutation-id` header. Absent on plain
419
+ * `client.mutation` calls.
420
+ */
421
+ idempotencyKey?: string;
422
+ /**
423
+ * Monotonic per-client mutation id (custom-mutator push path), backing the
424
+ * server-side per-client watermark: `id <= watermark` is a replay (skipped),
425
+ * `id == watermark + 1` runs authoritatively, `id > watermark + 1` halts the
426
+ * batch so the client resends from `watermark + 1`. Absent on plain
427
+ * `client.mutation` calls.
428
+ */
429
+ mutationId?: number;
430
+ shardKey?: string;
431
+ }
432
+ /**
433
+ * Wire response from the shard's `/rpc` endpoint (forwarded by the runtime). A
434
+ * watermarked custom-mutator push additionally carries `lastMutationId` — the
435
+ * highest per-client sequence the DO has applied — which the client uses to keep
436
+ * its `clientSeq` generator monotonic across reloads (see `LunoraClient.callMutator`).
437
+ * A plain mutation on a CDC shard carries `commitCursor` — the cursor the write
438
+ * committed at — which gates the drop of a per-call optimistic layer.
439
+ */
440
+ type RpcResponseBody = {
441
+ error: {
442
+ code: string;
443
+ data?: unknown;
444
+ message: string;
445
+ };
446
+ } | {
447
+ commitCursor?: number;
448
+ lastMutationId?: number;
449
+ result: unknown;
450
+ };
451
+ /** Subscription protocol — client → server. */
452
+ interface ClientSubscribeMessage {
453
+ id: string;
454
+ /**
455
+ * `sinceSeq` is the persisted `cursor` high-watermark the client last saw
456
+ * for this shard (Pillar 1b resume). Present only when a durable
457
+ * {@link QueryCacheAdapter} restored a cached value with a cursor; the
458
+ * server replies with a lightweight `resume` frame instead of a full
459
+ * snapshot when nothing the query reads changed since it. Absent on a
460
+ * first-time subscribe.
461
+ */
462
+ query: {
463
+ args?: Record<string, unknown>;
464
+ functionPath?: string;
465
+ sinceEpoch?: string;
466
+ sinceSeq?: number;
467
+ table?: string;
468
+ };
469
+ type: "subscribe";
470
+ }
471
+ interface ClientUnsubscribeMessage {
472
+ id: string;
473
+ type: "unsubscribe";
474
+ }
475
+ /**
476
+ * One-shot control frame sent right after the socket opens. Registers the
477
+ * connection's app `context` (e.g. `{ roomId, sessionId }`) with the server and
478
+ * fires the `onConnect` lifecycle hooks; the same context is replayed to
479
+ * `onDisconnect` when the socket drops.
480
+ */
481
+ interface ClientConnectMessage {
482
+ /**
483
+ * Stable per-client id (persisted alongside the outbox). Lets the server
484
+ * scope this connection's `__client_watermark` so custom-mutator pokes can
485
+ * echo the right per-client `lastMutationId`. Omitted by clients that don't
486
+ * use custom mutators.
487
+ */
488
+ clientId?: string;
489
+ context?: Record<string, unknown>;
490
+ id: string;
491
+ type: "connect";
492
+ }
493
+ /**
494
+ * Subscribe to a declarative **shape** — server-side partial replication scoped
495
+ * by `shardBy` + the shape's predicate + RLS. The client sends the shape *name*
496
+ * + validated `args`; the server resolves the trusted `where` (identity/RLS
497
+ * `baseWhere` the client can't forge) and streams the matching rowset, then live
498
+ * {@link ServerPokePartMessage} diffs. `id` namespaces the subscription and is
499
+ * echoed as `shapeId` on every poke part.
500
+ */
501
+ interface ClientShapeSubscribeMessage {
502
+ id: string;
503
+ shape: {
504
+ args?: Record<string, unknown>;
505
+ name: string;
506
+ };
507
+ /**
508
+ * Resume from this checkpoint (the `__cdc_log` cursor the client last
509
+ * applied for this shape). When absent or below the server's retained floor
510
+ * (`minCdcSeq`), the server re-seeds with a full insert-poke instead of a
511
+ * delta.
512
+ */
513
+ sinceCheckpoint?: number;
514
+ /**
515
+ * The CDC epoch {@link ClientShapeSubscribeMessage.sinceCheckpoint} belongs
516
+ * to. A mismatch (forked changelog timeline) forces a full re-seed even when
517
+ * the cursor is numerically in range.
518
+ */
519
+ sinceEpoch?: string;
520
+ type: "shape_subscribe";
521
+ }
522
+ /** Cancel a shape subscription started with the same `id`. */
523
+ interface ClientShapeUnsubscribeMessage {
524
+ id: string;
525
+ type: "shape_unsubscribe";
526
+ }
527
+ interface ClientAckMessage {
528
+ id: string;
529
+ type: "ack";
530
+ }
531
+ /**
532
+ * Start a streaming query. The id namespaces a fresh stream and is echoed on
533
+ * every {@link ServerChunkMessage} the server pushes back. Cancel a running
534
+ * stream by sending a {@link ClientUnsubscribeMessage} with the same id —
535
+ * subscription and stream id-spaces share the cancel channel; the prefix
536
+ * (`sub_*` vs `stream_*`) keeps the local registries searchable.
537
+ */
538
+ interface ClientStreamMessage {
539
+ id: string;
540
+ query: {
541
+ args?: Record<string, unknown>;
542
+ functionPath: string;
543
+ shardKey?: string;
544
+ };
545
+ type: "stream";
546
+ }
547
+ /**
548
+ * Join or leave a whisper `topic` — an app-chosen ephemeral channel scoped to a
549
+ * shard. While joined, the client receives every {@link ServerWhisperMessage}
550
+ * other members broadcast to the topic.
551
+ */
552
+ interface ClientWhisperSubscribeMessage {
553
+ topic: string;
554
+ type: "whisper_subscribe" | "whisper_unsubscribe";
555
+ }
556
+ /**
557
+ * Broadcast ephemeral `data` to the topic's other members on the shard. The
558
+ * payload is relayed verbatim with no server-side persistence (no SQLite/CDC
559
+ * write) — for typing indicators, live cursors, presence pings. The sender does
560
+ * not receive its own whisper.
561
+ */
562
+ interface ClientWhisperMessage {
563
+ data?: unknown;
564
+ topic: string;
565
+ type: "whisper";
566
+ }
567
+ type ClientMessage = ClientAckMessage | ClientConnectMessage | ClientShapeSubscribeMessage | ClientShapeUnsubscribeMessage | ClientStreamMessage | ClientSubscribeMessage | ClientUnsubscribeMessage | ClientWhisperMessage | ClientWhisperSubscribeMessage;
568
+ /** Subscription protocol — server → client. */
569
+ interface ServerDataMessage {
570
+ /**
571
+ * The `__cdc_log` high-watermark covered by this frame (Pillar 1b). The
572
+ * client persists it as the query's `serverCursor` and replays it as
573
+ * `sinceSeq` on the next reconnect. Absent on shards that never enabled CDC.
574
+ */
575
+ cursor?: number;
576
+ data?: unknown;
577
+ delta?: unknown;
578
+ /** The CDC epoch this frame's cursor belongs to (see {@link CachedQuery.serverEpoch}). */
579
+ epoch?: string;
580
+ id: string;
581
+ /**
582
+ * The highest custom-mutator `mutationId` from this client the server has
583
+ * now applied (the per-client `__client_watermark`). Echoed so the client's
584
+ * outbox can drop confirmed pending mutations and let TanStack DB collapse
585
+ * the matching optimistic overlay. Absent on shards without custom mutators.
586
+ */
587
+ lastMutationId?: number;
588
+ type: "data" | "delta";
589
+ }
590
+ /**
591
+ * Lightweight resume acknowledgement (Pillar 1b): the server determined that
592
+ * nothing the subscription reads changed since the client's `sinceSeq`, so it
593
+ * skips re-sending the snapshot. The client keeps its cached value and only
594
+ * advances `serverCursor` to `cursor`.
595
+ */
596
+ interface ServerResumeMessage {
597
+ cursor?: number;
598
+ /** The CDC epoch this resume's cursor belongs to (see {@link CachedQuery.serverEpoch}). */
599
+ epoch?: string;
600
+ id: string;
601
+ /** Per-client custom-mutator watermark (see {@link ServerDataMessage.lastMutationId}). */
602
+ lastMutationId?: number;
603
+ type: "resume";
604
+ }
605
+ /**
606
+ * Settled acknowledgement for a **list** subscription: a write touched one of
607
+ * the subscription's read tables but produced a byte-identical result, so the
608
+ * server suppressed the data frame. Sent ONLY to a `@lunora/db` custom-mutator
609
+ * client (one that announced a `clientId`, hence has a server-side
610
+ * `__client_watermark`) so its optimistic list overlay drops even when no data
611
+ * frame arrives. Plain `useQuery` subscribers never receive it, and an older
612
+ * client safely ignores the unknown frame.
613
+ */
614
+ interface ServerSettledMessage {
615
+ cursor?: number;
616
+ /** The CDC epoch this settled frame's cursor belongs to (see {@link CachedQuery.serverEpoch}). */
617
+ epoch?: string;
618
+ id: string;
619
+ /**
620
+ * The highest custom-mutator `mutationId` from this client the server has
621
+ * now applied (the per-client `__client_watermark`). Forwarded to a
622
+ * collection's `onCheckpoint` so it can drop the overlay for the confirmed
623
+ * write whose result didn't change this list.
624
+ */
625
+ lastMutationId?: number;
626
+ type: "settled";
627
+ }
628
+ interface ServerErrorMessage {
629
+ error?: unknown;
630
+ id?: string;
631
+ message?: string;
632
+ type: "error";
633
+ }
634
+ interface ServerAckMessage {
635
+ id: string;
636
+ type: "ack";
637
+ }
638
+ interface ServerCompleteMessage {
639
+ id: string;
640
+ type: "complete";
641
+ }
642
+ /** One frame of a streaming query — `data` carries the user-yielded chunk. */
643
+ interface ServerChunkMessage {
644
+ data: unknown;
645
+ id: string;
646
+ type: "chunk";
647
+ }
648
+ /**
649
+ * An ephemeral whisper relayed from another member of `topic` on the same shard
650
+ * (AnyCable-style whispering). `data` is the sender's payload verbatim; `from`
651
+ * is the sender's verified user id when known (absent for an anonymous sender).
652
+ * Never persisted server-side.
653
+ */
654
+ interface ServerWhisperMessage {
655
+ data: unknown;
656
+ from?: string;
657
+ topic: string;
658
+ type: "whisper";
659
+ }
660
+ /**
661
+ * One row-level change in a shape's replication stream — the wire form of the
662
+ * DO's `__cdc_log` `CdcChange`. `insert`/`update` carry the post-image in
663
+ * `value` (projected to the shape's `columns`); `delete` omits it, identifying
664
+ * the removed row by `key` alone. The client applies these to its local
665
+ * collection; an unknown `key` on a `delete` is a safe no-op (a row the client
666
+ * never had in this shape).
667
+ */
668
+ interface RowOp {
669
+ /** Row primary key (`_id`). */
670
+ key: string;
671
+ op: "delete" | "insert" | "update";
672
+ /** Logical table the row belongs to. */
673
+ table: string;
674
+ /** Post-image document for insert/update; absent on delete. */
675
+ value?: Record<string, unknown>;
676
+ }
677
+ /**
678
+ * Opens a **poke** — an atomically-applied batch of shape diffs (Zero's poke
679
+ * protocol). A `pokeStart` is followed by zero or more {@link ServerPokePartMessage}
680
+ * frames and closed by exactly one {@link ServerPokeEndMessage}; the client
681
+ * buffers every part and applies them in a single transaction at `pokeEnd`, so a
682
+ * socket that drops mid-poke simply re-seeds on reconnect (no torn view).
683
+ */
684
+ interface ServerPokeStartMessage {
685
+ /** The checkpoint the client's view is expected to be at before this poke applies (for ordering/gap detection). */
686
+ baseCheckpoint?: number;
687
+ /** CDC epoch this poke belongs to; a mismatch forces the client to re-seed rather than apply. */
688
+ epoch?: string;
689
+ /** Correlates this poke's `pokeStart`/`pokePart`/`pokeEnd` frames. */
690
+ pokeId: string;
691
+ type: "pokeStart";
692
+ }
693
+ /** One shape's slice of an in-flight poke: the row-ops to apply for `shapeId`. */
694
+ interface ServerPokePartMessage {
695
+ /** Per-client custom-mutator watermark carried with this slice (see {@link ServerSettledMessage.lastMutationId}). */
696
+ lastMutationId?: number;
697
+ pokeId: string;
698
+ /** Ordered row-level changes for this shape, applied in sequence at `pokeEnd`. */
699
+ rowsPatch: RowOp[];
700
+ /** The {@link ClientShapeSubscribeMessage.id} these row-ops belong to. */
701
+ shapeId: string;
702
+ type: "pokePart";
703
+ }
704
+ /**
705
+ * Closes a poke: the client commits the buffered parts atomically and advances
706
+ * its checkpoint to {@link ServerPokeEndMessage.checkpoint} (the `__cdc_log`
707
+ * cursor high-watermark the view now reflects), replayed as `sinceCheckpoint` on
708
+ * the next reconnect.
709
+ */
710
+ interface ServerPokeEndMessage {
711
+ /** The `__cdc_log` cursor the view is at after applying this poke. */
712
+ checkpoint?: number;
713
+ /** CDC epoch the {@link ServerPokeEndMessage.checkpoint} belongs to. */
714
+ epoch?: string;
715
+ pokeId: string;
716
+ type: "pokeEnd";
717
+ }
718
+ type ServerMessage = ServerAckMessage | ServerChunkMessage | ServerCompleteMessage | ServerDataMessage | ServerErrorMessage | ServerPokeEndMessage | ServerPokePartMessage | ServerPokeStartMessage | ServerResumeMessage | ServerSettledMessage | ServerWhisperMessage;
719
+ /**
720
+ * The authenticated user as exposed client-side, mirroring better-auth's
721
+ * `user` row (the `user` field of the `get-session` response). Kept minimal
722
+ * and structural — only `id` is guaranteed; the rest are the common better-auth
723
+ * fields, and the index signature carries any plugin-contributed extras.
724
+ */
725
+ interface User {
726
+ readonly createdAt?: NullableTimestamp;
727
+ readonly email?: null | string;
728
+ readonly emailVerified?: boolean | null;
729
+ readonly id: string;
730
+ readonly image?: null | string;
731
+ readonly name?: null | string;
732
+ readonly [key: string]: unknown;
733
+ readonly updatedAt?: NullableTimestamp;
734
+ }
735
+ /**
736
+ * One pending scheduled function, as returned by the worker's
737
+ * `GET /_lunora/admin/scheduled` endpoint. Mirrors `@lunora/scheduler`'s
738
+ * `ScheduleRecord` structurally so the client carries no dependency on it.
739
+ */
740
+ interface ScheduleRecord {
741
+ args: Record<string, unknown>;
742
+ /**
743
+ * Dispatch attempts already made. Absent (treated as 0) until the first
744
+ * failure; on a dead-letter record it is the exhausted count (> the retry
745
+ * budget). Surfaced so the studio can show how hard a job tried before it
746
+ * was parked.
747
+ */
748
+ attempts?: number;
749
+ enqueuedAt: number;
750
+ functionPath: string;
751
+ id: string;
752
+ /** Logical workpool the job is routed to (concurrency-gated), when any. */
753
+ pool?: string;
754
+ scheduledFor: number;
755
+ shardKey?: string;
756
+ }
757
+ /**
758
+ * One workpool's live backlog, as returned by the worker's
759
+ * `GET /_lunora/admin/scheduled/status` endpoint. Mirrors `@lunora/scheduler`'s
760
+ * `SchedulerPoolStatus` structurally so the client carries no dependency on it.
761
+ */
762
+ interface SchedulerPoolStatus {
763
+ /** Jobs currently dispatched-but-not-yet-completed (the held concurrency slots). */
764
+ inFlight: number;
765
+ /** The pool's concurrency cap. */
766
+ maxConcurrency: number;
767
+ /** The logical workpool name. */
768
+ name: string;
769
+ /** Pending jobs routed to this pool but not yet dispatched. */
770
+ queued: number;
771
+ }
772
+ /**
773
+ * The app-level scheduler backlog, as returned by the worker's
774
+ * `GET /_lunora/admin/scheduled/status` endpoint. `pools` is the per-pool
775
+ * breakdown; `backlog` and `inFlight` are the app-wide sums of `queued` and
776
+ * `inFlight` across every pool — the headline numbers for the studio SLO
777
+ * view. Mirrors `@lunora/scheduler`'s `SchedulerStatus` structurally.
778
+ */
779
+ interface SchedulerStatus {
780
+ /** Sum of every pool's `queued` count — the total pending backlog. */
781
+ backlog: number;
782
+ /** Sum of every pool's `inFlight` count — the total held concurrency slots. */
783
+ inFlight: number;
784
+ /** Per-pool backlog breakdown. */
785
+ pools: SchedulerPoolStatus[];
786
+ }
787
+ /**
788
+ * One shard's request volume, as returned by the worker's
789
+ * `POST /_lunora/admin/shard-traffic` endpoint. The cross-shard traffic feed
790
+ * the studio's `hot_shard` advisor lint consumes: `requests` is the shard's
791
+ * lifetime dispatch total, `shardKey` the DO id name (`""` for the root shard).
792
+ */
793
+ interface ShardTrafficEntry {
794
+ requests: number;
795
+ shardKey: string;
796
+ }
797
+ /**
798
+ * The whole-shard-set traffic distribution returned by the worker's
799
+ * `POST /_lunora/admin/shard-traffic` endpoint. `shards` is one entry per live
800
+ * shard (a failed shard surfaces with `requests: 0`); `ok`/`failed` count the
801
+ * shards that returned vs. errored. Shaped to feed the advisor's `hot_shard`
802
+ * lint after the studio tags each entry with its sharded function `group`.
803
+ */
804
+ interface ShardTrafficResult {
805
+ failed: number;
806
+ ok: number;
807
+ shards: ShardTrafficEntry[];
808
+ }
809
+ /**
810
+ * One object in the storage bucket, as returned by the worker's
811
+ * `GET /_lunora/admin/storage` endpoint. Mirrors `@lunora/storage`'s
812
+ * `R2ObjectLike` structurally.
813
+ */
814
+ interface StorageObject {
815
+ customMetadata?: Record<string, string>;
816
+ etag: string;
817
+ httpMetadata?: {
818
+ contentType?: string;
819
+ };
820
+ key: string;
821
+ size: number;
822
+ /**
823
+ * When the object was stored. R2 emits a `Date`, which JSON-serializes to an
824
+ * ISO string over the wire; a mock may supply epoch ms — so consumers should
825
+ * normalise via `new Date(uploaded)`. Absent if the backend didn't report it.
826
+ */
827
+ uploaded?: number | string;
828
+ }
829
+ /** One page of {@link StorageObject}s plus the cursor to fetch the next, if any. */
830
+ interface StorageListPage {
831
+ cursor?: string;
832
+ objects: StorageObject[];
833
+ }
834
+ /**
835
+ * One argument of a registered function, derived from its `v.*` validator by the
836
+ * worker. A compact signature shape — enough to render a function's API without
837
+ * the build-time codegen types.
838
+ */
839
+ interface FunctionArgumentDescriptor {
840
+ /** Element validator kind for an `array` arg (one level), e.g. `string`. */
841
+ element?: string;
842
+ /** The (optional-unwrapped) validator kind, e.g. `string`, `id`, `object`. */
843
+ kind: string;
844
+ /** The argument name. */
845
+ name: string;
846
+ /** True when the arg is wrapped in `v.optional(...)`. */
847
+ optional: boolean;
848
+ /** Target table for an `id` arg (`v.id("table")`). */
849
+ table?: string;
850
+ }
851
+ /**
852
+ * One registered function, as returned by the worker's
853
+ * `GET /_lunora/admin/functions` endpoint: its `<file>:<function>` path, which
854
+ * client method (`query` / `mutation` / `action`) invokes it, and its argument
855
+ * signature. `args` is absent on responses from an older worker.
856
+ */
857
+ interface FunctionDescriptor {
858
+ args?: FunctionArgumentDescriptor[];
859
+ kind: "action" | "mutation" | "query";
860
+ path: string;
861
+ }
862
+ /** A `.global()` (D1-backed) table plus its row count, from `/_lunora/admin/global/tables`. */
863
+ interface GlobalTableInfo {
864
+ name: string;
865
+ rowCount: number;
866
+ }
867
+ /** A window of rows from one global table, from `/_lunora/admin/global/table`. */
868
+ interface GlobalTablePage {
869
+ columns: string[];
870
+ /** FK columns (local column → referenced table) for external tables with real `REFERENCES` constraints, from `PRAGMA foreign_key_list`. */
871
+ refs?: Record<string, string>;
872
+ rows: Record<string, unknown>[];
873
+ total: number;
874
+ }
875
+ /**
876
+ * One equality constraint a facet-value click adds to the global browser's view
877
+ * (`column = value`). `value` is the raw stored scalar the facet returned, sent
878
+ * as-is and bound server-side, so it never injects SQL.
879
+ */
880
+ interface GlobalFilterClause {
881
+ column: string;
882
+ value: unknown;
883
+ }
884
+ /** One distinct value of a faceted global column with its row count, from `/_lunora/admin/global/facet`. */
885
+ interface GlobalFacetValue {
886
+ count: number;
887
+ value: unknown;
888
+ }
889
+ /** Per-column distinct-value summary for the global browser, from `/_lunora/admin/global/facet`. */
890
+ interface GlobalFacetResult {
891
+ truncated: boolean;
892
+ values: GlobalFacetValue[];
893
+ }
894
+ /** A nullable timestamp field as better-auth serializes it: epoch-ms, ISO string, or null. */
895
+ type NullableTimestamp = null | number | string;
896
+ /** A workflow instance's lifecycle status. Mirrors Cloudflare's `InstanceStatus`. */
897
+ type WorkflowInstanceStatus = "complete" | "errored" | "paused" | "queued" | "running" | "terminated" | "unknown" | "waiting" | "waitingForPause";
898
+ /** The lifecycle mutations the status endpoint accepts. */
899
+ type WorkflowInstanceAction = "pause" | "resume" | "terminate";
900
+ /** One row of the workflow-instances list. */
901
+ interface WorkflowInstanceSummary {
902
+ createdOn?: string;
903
+ endedOn?: string;
904
+ id: string;
905
+ startedOn?: string;
906
+ status: WorkflowInstanceStatus;
907
+ }
908
+ /** One durable step of an instance's execution timeline. */
909
+ interface WorkflowStepDetail {
910
+ /** 1-based attempt count (`> 1` means the step retried). */
911
+ attempts?: number;
912
+ end?: string;
913
+ error?: unknown;
914
+ name: string;
915
+ output?: unknown;
916
+ start?: string;
917
+ success?: boolean;
918
+ /** `step` / `sleep` / `waitForEvent` / … (Cloudflare's step `type`). */
919
+ type?: string;
920
+ }
921
+ /** A workflow instance's full detail: summary plus params/output/error and the step timeline. */
922
+ interface WorkflowInstanceDetail extends WorkflowInstanceSummary {
923
+ error?: unknown;
924
+ output?: unknown;
925
+ params?: unknown;
926
+ steps: WorkflowStepDetail[];
927
+ }
928
+ /** A page of workflow instances. */
929
+ interface WorkflowInstancePage {
930
+ /**
931
+ * Whether workflow inspection is configured on the worker (a Cloudflare
932
+ * account id + API token). `false` when the admin proxy reports it can't
933
+ * inspect instances; omitted (treated as configured) otherwise. Lets a
934
+ * caller render a "set credentials" state without a failed request.
935
+ */
936
+ configured?: boolean;
937
+ instances: WorkflowInstanceSummary[];
938
+ page: number;
939
+ perPage: number;
940
+ totalCount?: number;
941
+ }
942
+ export { ArgsOf as A, BookmarkStorage as B, CachedQuery as C, RpcEnvelope as D, RpcResponseBody as E, FunctionReference as F, GlobalTableInfo as G, HttpStreamRef as H, SchedulerPoolStatus as I, ServerMessage as J, ServerPokeEndMessage as K, LunoraClientOptions as L, ServerPokePartMessage as M, ServerPokeStartMessage as N, OfflineQueueOptions as O, Preloaded as P, QueryCacheAdapter as Q, ReturnOf as R, ShardTrafficResult as S, ShardTrafficEntry as T, User as U, StorageObject as V, WsTokenProvider as W, WorkflowInstanceSummary as X, WorkflowStepDetail as Y, Unsubscribe as a, ScheduleRecord as b, SchedulerStatus as c, WorkflowInstanceStatus as d, WorkflowInstancePage as e, WorkflowInstanceDetail as f, WorkflowInstanceAction as g, FunctionDescriptor as h, StorageListPage as i, GlobalFilterClause as j, GlobalTablePage as k, GlobalFacetResult as l, HttpStreamArgsOf as m, HttpStreamChunkOf as n, PersistenceAdapter as o, ReconnectOptions as p, ClientMessage as q, ClientShapeSubscribeMessage as r, ClientShapeUnsubscribeMessage as s, FunctionArgumentDescriptor as t, GlobalFacetValue as u, HttpStreamCallArgs as v, OutboxMutation as w, OutboxSink as x, PersistedMutation as y, RowOp as z };