@lunora/client 1.0.0-alpha.3 → 1.0.0-alpha.300

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 (100) hide show
  1. package/LICENSE.md +207 -104
  2. package/README.md +24 -7
  3. package/dist/admin/index.d.mts +689 -0
  4. package/dist/admin/index.d.ts +689 -0
  5. package/dist/admin/index.mjs +1 -0
  6. package/dist/auth/index.d.mts +174 -13
  7. package/dist/auth/index.d.ts +174 -13
  8. package/dist/auth/index.mjs +1 -60
  9. package/dist/index.d.mts +1121 -190
  10. package/dist/index.d.ts +1121 -190
  11. package/dist/index.mjs +1 -14
  12. package/dist/packem_shared/ADMIN_AUTH_DEFAULT_PAGE_SIZE-aKbm8N1z.mjs +1 -0
  13. package/dist/packem_shared/CONFLICT_ERROR_CODE-B7qNZMMk.mjs +1 -0
  14. package/dist/packem_shared/DEFAULT_MAX_BUFFER-Bd-_iyiV.mjs +1 -0
  15. package/dist/packem_shared/LunoraAdminClient-ClQxFDiy.mjs +1 -0
  16. package/dist/packem_shared/LunoraClient-D8eDGCKr.mjs +1 -0
  17. package/dist/packem_shared/OfflineQueue-BGkx7pBL.mjs +1 -0
  18. package/dist/packem_shared/RETIRE_AFTER_DURABLE_SEQ_ADVANCE-DoEHtuR8.mjs +1 -0
  19. package/dist/packem_shared/SKIP-d7LeP-sY.mjs +1 -0
  20. package/dist/packem_shared/SubscriptionRegistry-DjFfxba2.mjs +1 -0
  21. package/dist/packem_shared/TabCoordinator-DIySdaRV.mjs +1 -0
  22. package/dist/packem_shared/applyDelta-CaudNj2C.mjs +1 -0
  23. package/dist/packem_shared/base64-849R7V-V.mjs +1 -0
  24. package/dist/packem_shared/client-tuning-C10B2KCO.mjs +1 -0
  25. package/dist/packem_shared/client-urls-BHLUjjcG.mjs +1 -0
  26. package/dist/packem_shared/connectLiveStream-BdjsWP1-.mjs +1 -0
  27. package/dist/packem_shared/createAsyncStoragePersistence-BgfdvLwe.mjs +1 -0
  28. package/dist/packem_shared/createAsyncStorageQueryCache-6Y94ocbQ.mjs +1 -0
  29. package/dist/packem_shared/createCallRunner-Bwcrfh76.mjs +1 -0
  30. package/dist/packem_shared/createClientQuery-B8Nfj-7o.mjs +1 -0
  31. package/dist/packem_shared/createInMemoryBookmarkStorage-BooZhW0n.mjs +1 -0
  32. package/dist/packem_shared/createInMemoryPersistence-C-IzNVbg.mjs +1 -0
  33. package/dist/packem_shared/createInMemoryQueryCache-DR6AorA2.mjs +1 -0
  34. package/dist/packem_shared/createLocalStore-WKNHD1ca.mjs +1 -0
  35. package/dist/packem_shared/createMutatorRunner-CuMRJpUx.mjs +1 -0
  36. package/dist/packem_shared/createReconnect-CjTmjJDH.mjs +1 -0
  37. package/dist/packem_shared/createServerClient-CcH_sS6i.mjs +1 -0
  38. package/dist/packem_shared/createSnapshotPrecondition-BXP1NPBW.mjs +1 -0
  39. package/dist/packem_shared/delta-merge-C6OqMEPH.mjs +1 -0
  40. package/dist/packem_shared/deserializePreloaded-DxozvweR.mjs +1 -0
  41. package/dist/packem_shared/frame-hint-D-NK691z.mjs +1 -0
  42. package/dist/packem_shared/function-reference.d-Br_hsKje.d.mts +45 -0
  43. package/dist/packem_shared/function-reference.d-Br_hsKje.d.ts +45 -0
  44. package/dist/packem_shared/getServerSession-BaOoo1p6.mjs +1 -0
  45. package/dist/packem_shared/httpStream-DN3D9WqW.mjs +7 -0
  46. package/dist/packem_shared/idb-utility-BS7xvou1.mjs +1 -0
  47. package/dist/packem_shared/live-stream-DBKgZlnb.mjs +10 -0
  48. package/dist/packem_shared/liveTopicSubscription-DQtKMFKw.mjs +1 -0
  49. package/dist/packem_shared/lunora-client-BC2DJGwq.mjs +1 -0
  50. package/dist/packem_shared/lunora-client.d-BswMNnv7.d.mts +5060 -0
  51. package/dist/packem_shared/lunora-client.d-TchceUzJ.d.ts +5060 -0
  52. package/dist/packem_shared/lunoraQueryKey-CucWmxnx.mjs +1 -0
  53. package/dist/packem_shared/offline-queue-HwrYARIL.mjs +1 -0
  54. package/dist/packem_shared/optimistic-layers-BI61YTO3.mjs +1 -0
  55. package/dist/packem_shared/preload.d-BKdXfr3n.d.ts +21 -0
  56. package/dist/packem_shared/preload.d-qY64gg1w.d.mts +21 -0
  57. package/dist/packem_shared/preloadQuery-uFy24PCR.mjs +1 -0
  58. package/dist/packem_shared/setAuthTokenProvider-DhBppDiZ.mjs +1 -0
  59. package/dist/packem_shared/single-blob-store-DeaYPBSS.mjs +1 -0
  60. package/dist/packem_shared/snapshot-precondition-BEtcSbWr.mjs +1 -0
  61. package/dist/packem_shared/stream-idle-C7CsIT_m.mjs +1 -0
  62. package/dist/packem_shared/wire-errors-BDckSTKZ.mjs +1 -0
  63. package/dist/pagination/index.d.mts +72 -43
  64. package/dist/pagination/index.d.ts +72 -43
  65. package/dist/pagination/index.mjs +1 -61
  66. package/dist/query/index.d.mts +183 -44
  67. package/dist/query/index.d.ts +183 -44
  68. package/dist/query/index.mjs +1 -1
  69. package/dist/service.d.mts +49 -0
  70. package/dist/service.d.ts +49 -0
  71. package/dist/service.mjs +1 -0
  72. package/dist/ssr/index.d.mts +109 -80
  73. package/dist/ssr/index.d.ts +109 -80
  74. package/dist/ssr/index.mjs +1 -4
  75. package/dist/upload.d.mts +49 -0
  76. package/dist/upload.d.ts +49 -0
  77. package/dist/upload.mjs +1 -0
  78. package/package.json +22 -2
  79. package/dist/packem_shared/CONFLICT_ERROR_CODE-aUdVbEDw.mjs +0 -4
  80. package/dist/packem_shared/DEFAULT_MAX_BUFFER-BDkqO5PW.mjs +0 -107
  81. package/dist/packem_shared/LunoraClient-UiULzH_1.mjs +0 -2165
  82. package/dist/packem_shared/OfflineQueue-D5p_QgF_.mjs +0 -127
  83. package/dist/packem_shared/SKIP-vItZChkw.mjs +0 -50
  84. package/dist/packem_shared/SubscriptionRegistry-B-Qx_Gux.mjs +0 -26
  85. package/dist/packem_shared/applyDelta-4jFGTPA3.mjs +0 -61
  86. package/dist/packem_shared/createAsyncStoragePersistence-1Z5BZ8RC.mjs +0 -45
  87. package/dist/packem_shared/createInMemoryBookmarkStorage-BoN7a7TH.mjs +0 -11
  88. package/dist/packem_shared/createInMemoryPersistence-CW82inU5.mjs +0 -105
  89. package/dist/packem_shared/createInMemoryQueryCache-B1PQ9Twl.mjs +0 -138
  90. package/dist/packem_shared/createLocalStore-DSUfoLqY.mjs +0 -36
  91. package/dist/packem_shared/createMutationRunner-BqsavzvG.mjs +0 -21
  92. package/dist/packem_shared/createReconnect-Di_-oHH7.mjs +0 -22
  93. package/dist/packem_shared/createServerClient-BjZc3gD8.mjs +0 -11
  94. package/dist/packem_shared/deserializePreloaded-C0eJTY_W.mjs +0 -4
  95. package/dist/packem_shared/getServerSession-8jXewqxd.mjs +0 -13
  96. package/dist/packem_shared/lunora-client.d-DGvyuJ_p.d.mts +0 -1597
  97. package/dist/packem_shared/lunora-client.d-DGvyuJ_p.d.ts +0 -1597
  98. package/dist/packem_shared/preload.d-BoDmFqSG.d.ts +0 -20
  99. package/dist/packem_shared/preload.d-dSaRMuhL.d.mts +0 -20
  100. package/dist/packem_shared/preloadQuery-lobFkD2Z.mjs +0 -13
@@ -1,26 +1,90 @@
1
- import { S as SubscriptionError, F as FunctionReference, A as ArgsOf, R as ReturnOf, L as LunoraClient, a as Unsubscribe } from "../packem_shared/lunora-client.d-DGvyuJ_p.mjs";
2
- export type { b as SubscriptionErrorCallback } from "../packem_shared/lunora-client.d-DGvyuJ_p.mjs";
3
- import '@lunora/runtime';
1
+ import { F as FunctionReference, R as ReturnOf, A as ArgsOf } from "../packem_shared/function-reference.d-Br_hsKje.mjs";
2
+ import { L as LunoraClient, S as SubscriptionError, a as Unsubscribe } from "../packem_shared/lunora-client.d-BswMNnv7.mjs";
3
+ export type {
4
4
  /**
5
- * The sentinel a framework adapter resolves its reactive args to when it wants
6
- * to short-circuit a query — no network call, no socket.
7
- */
5
+ * `@lunora/client/query` — the framework-neutral live-query state machine shared
6
+ * by every Lunora UI adapter (React, Vue, Svelte, Solid). It owns the seam
7
+ * between a `LunoraClient` subscription and a framework's reactivity primitive:
8
+ * the subscribe → snapshot → error/reset → cleanup lifecycle, with the
9
+ * skip-handling, value/error fan-out, attach-throw normalisation, and
10
+ * cancellation-guarded teardown all in one place. Nothing here imports a UI
11
+ * framework — each adapter supplies thin sinks that write into its own ref /
12
+ * store / signal / cache.
13
+ *
14
+ * It also owns the TanStack Query key contract (`lunoraQueryKey`,
15
+ * `lunoraQueryOptions`), so every adapter and server entry keys a Lunora query
16
+ * the same way.
17
+ */
18
+ b as SubscriptionErrorCallback } from "../packem_shared/lunora-client.d-BswMNnv7.mjs";
19
+ import '@lunora/errors';
20
+ /**
21
+ * The TanStack Query cache-key contract for Lunora queries. It lives here, not
22
+ * in an adapter, because every TanStack binding (React, Vue, Solid, Svelte,
23
+ * Angular Query) hashes keys the same way, and a value prefetched through one
24
+ * entry point must land under the exact key a hook reads back.
25
+ *
26
+ * Typed as `ReadonlyArray<unknown>` — TanStack v5's default `QueryKey` — so this
27
+ * module needs no TanStack dependency.
28
+ */
29
+ type LunoraQueryKey = ReadonlyArray<unknown>;
30
+ /**
31
+ * Project a Lunora `(fn, args, shardKey)` triple into the query key TanStack
32
+ * hashes for dedup. The `"lunora"` literal namespaces our entries so an app's
33
+ * own queries can't collide with ours.
34
+ *
35
+ * `args` sits in the key already encoded by `stableWireKey`, not as the raw
36
+ * object. TanStack hashes keys with `JSON.stringify`, which maps `NaN` to
37
+ * `null`, `-0` to `0` and a `Date` to its ISO string (so distinct args shared
38
+ * one cache entry and served each other's rows) and throws on a `bigint`. A
39
+ * string slot hashes the same under any hash function, so every QueryClient
40
+ * agrees on it without configuration.
41
+ */
42
+ declare const lunoraQueryKeyFromArgsKey: (ref: string, argsKey: string, shardKey: string | undefined) => LunoraQueryKey;
43
+ declare const lunoraQueryKey: (function_: FunctionReference, args: Record<string, unknown>, shardKey: string | undefined) => LunoraQueryKey;
44
+ /** Shape returned by `lunoraQueryOptions`, spread into a TanStack hook. */
45
+ interface LunoraQueryOptions<F extends FunctionReference> {
46
+ queryFn: () => Promise<ReturnOf<F>>;
47
+ queryKey: LunoraQueryKey;
48
+ staleTime: number;
49
+ }
50
+ /**
51
+ * Build a TanStack Query options object for a Lunora query, keyed identically
52
+ * to the adapters' first-class hooks (see `lunoraQueryKey`), so a value fetched
53
+ * through it shares cache identity with anything those hooks or a server-side
54
+ * `prefetchQuery` read or write for the same `(fn, args, shardKey)` triple.
55
+ *
56
+ * ```ts
57
+ * const { data } = useSuspenseQuery(lunoraQueryOptions(client, api.posts.list, {}));
58
+ * ```
59
+ *
60
+ * This is a one-shot fetch: it resolves once and `staleTime` is infinite, so
61
+ * TanStack never refetches on its own. It opens no WebSocket and has no
62
+ * framework or browser dependency, so it is safe on either side of an RSC
63
+ * boundary — the transport is the `LunoraClient` passed in.
64
+ */
65
+ declare const lunoraQueryOptions: <F extends FunctionReference>(client: LunoraClient, function_: F, args: ArgsOf<F>, options?: {
66
+ shardKey?: string;
67
+ }) => LunoraQueryOptions<F>;
68
+ /**
69
+ * The sentinel a framework adapter resolves its reactive args to when it wants
70
+ * to short-circuit a query — no network call, no socket.
71
+ */
8
72
  declare const SKIP: "skip";
9
73
  /** Args after a framework has resolved its reactivity primitive, or the skip sentinel. */
10
74
  type ResolvedArgs<F extends FunctionReference> = ArgsOf<F> | typeof SKIP;
11
75
  /**
12
- * The framework-neutral sinks a {@link createQuerySubscription} call drives. A
13
- * framework adapter supplies these, wiring each into its own reactivity
14
- * primitive (a TanStack cache write, a Vue `ref`, a Svelte store `set`, a Solid
15
- * signal setter).
16
- *
17
- * `onData` fires when a fresh server value lands (the initial frame or a delta).
18
- * `onError` fires when the subscription attach threw, or the server pushed a
19
- * subscription-scoped error — it is optional, and when omitted an attach throw
20
- * propagates to the caller (preserving the "no error channel" behaviour of
21
- * adapters like Solid/Vue that never had one) rather than being swallowed.
22
- * `onReset` fires when the resolved args are `"skip"`: clear any prior value.
23
- */
76
+ * The framework-neutral sinks a {@link createQuerySubscription} call drives. A
77
+ * framework adapter supplies these, wiring each into its own reactivity
78
+ * primitive (a TanStack cache write, a Vue `ref`, a Svelte store `set`, a Solid
79
+ * signal setter).
80
+ *
81
+ * `onData` fires when a fresh server value lands (the initial frame or a delta).
82
+ * `onError` fires when the subscription attach threw, or the server pushed a
83
+ * subscription-scoped error — it is optional, and when omitted an attach throw
84
+ * propagates to the caller (preserving the "no error channel" behaviour of
85
+ * adapters like Solid/Vue that never had one) rather than being swallowed.
86
+ * `onReset` fires when the resolved args are `"skip"`: clear any prior value.
87
+ */
24
88
  interface QuerySubscriptionSinks<T> {
25
89
  onData: (value: T) => void;
26
90
  onError?: (error: SubscriptionError) => void;
@@ -33,30 +97,105 @@ interface QuerySubscriptionOptions {
33
97
  /** Normalise an unknown thrown value into the client's {@link SubscriptionError} shape. */
34
98
  declare const toSubscriptionError: (error: unknown) => SubscriptionError;
35
99
  /**
36
- * The subscribe → snapshot → error/reset → cleanup state machine shared by
37
- * every Lunora framework adapter's live-query hook.
38
- *
39
- * Given a `client`, a function reference, the already-resolved `args` (a
40
- * framework reads its own reactive source first, then hands the plain value in),
41
- * and a set of {@link QuerySubscriptionSinks}, this opens one `client.subscribe`
42
- * registration and returns the {@link Unsubscribe} to tear it down. Each
43
- * framework owns *when* to call this (a React effect, a Vue `watch`, a Svelte
44
- * store start callback, a Solid `createEffect(on(...))`) and *where* to stash
45
- * the value — this owns the lifecycle in between, so the skip-handling, the
46
- * value/error fan-out, the attach-throw normalisation, and the
47
- * cancellation-guarded teardown live in exactly one place.
48
- *
49
- * Behaviour. When `args === "skip"` it calls `sinks.onReset?.()` and returns a
50
- * no-op teardown; no `client.subscribe` is issued. Otherwise it opens
51
- * `client.subscribe(fn, args, …, { shardKey, onError })`: server pushes route to
52
- * `sinks.onData`, and the client's own `onError` channel (a server-rejected
53
- * subscription) routes to `sinks.onError` when present. The attach is wrapped —
54
- * if `client.subscribe` itself throws, the error is normalised to a
55
- * {@link SubscriptionError} and delivered to `sinks.onError` when present; with
56
- * no `onError` sink the throw is rethrown so adapters without an error channel
57
- * behave exactly as before. The returned teardown is idempotent and
58
- * cancellation-guarded: once it runs, no further `onData`/`onError` from an
59
- * in-flight push reaches the sinks.
60
- */
100
+ * The subscribe → snapshot → error/reset → cleanup state machine shared by
101
+ * every Lunora framework adapter's live-query hook.
102
+ *
103
+ * Given a `client`, a function reference, the already-resolved `args` (a
104
+ * framework reads its own reactive source first, then hands the plain value in),
105
+ * and a set of {@link QuerySubscriptionSinks}, this opens one `client.subscribe`
106
+ * registration and returns the {@link Unsubscribe} to tear it down. Each
107
+ * framework owns *when* to call this (a React effect, a Vue `watch`, a Svelte
108
+ * store start callback, a Solid `createEffect(on(...))`) and *where* to stash
109
+ * the value — this owns the lifecycle in between, so the skip-handling, the
110
+ * value/error fan-out, the attach-throw normalisation, and the
111
+ * cancellation-guarded teardown live in exactly one place.
112
+ *
113
+ * Behaviour. When `args === "skip"` it calls `sinks.onReset?.()` and returns a
114
+ * no-op teardown; no `client.subscribe` is issued. Otherwise it opens
115
+ * `client.subscribe(fn, args, …, { shardKey, onError })`: server pushes route to
116
+ * `sinks.onData`, and the client's own `onError` channel (a server-rejected
117
+ * subscription) routes to `sinks.onError` when present. The attach is wrapped —
118
+ * if `client.subscribe` itself throws, the error is normalised to a
119
+ * {@link SubscriptionError} and delivered to `sinks.onError` when present; with
120
+ * no `onError` sink the throw is rethrown so adapters without an error channel
121
+ * behave exactly as before. The returned teardown is idempotent and
122
+ * cancellation-guarded: once it runs, no further `onData`/`onError` from an
123
+ * in-flight push reaches the sinks.
124
+ */
61
125
  declare const createQuerySubscription: <F extends FunctionReference, T = ReturnOf<F>>(client: LunoraClient, function_: F, args: ResolvedArgs<F>, sinks: QuerySubscriptionSinks<T>, options?: QuerySubscriptionOptions) => Unsubscribe;
62
- export { type ArgsOf, type FunctionReference, type QuerySubscriptionOptions, type QuerySubscriptionSinks, type ResolvedArgs, type ReturnOf, SKIP, type SubscriptionError, type Unsubscribe, createQuerySubscription, toSubscriptionError };
126
+ export {
127
+ /**
128
+ * `@lunora/client/query` — the framework-neutral live-query state machine shared
129
+ * by every Lunora UI adapter (React, Vue, Svelte, Solid). It owns the seam
130
+ * between a `LunoraClient` subscription and a framework's reactivity primitive:
131
+ * the subscribe → snapshot → error/reset → cleanup lifecycle, with the
132
+ * skip-handling, value/error fan-out, attach-throw normalisation, and
133
+ * cancellation-guarded teardown all in one place. Nothing here imports a UI
134
+ * framework — each adapter supplies thin sinks that write into its own ref /
135
+ * store / signal / cache.
136
+ *
137
+ * It also owns the TanStack Query key contract (`lunoraQueryKey`,
138
+ * `lunoraQueryOptions`), so every adapter and server entry keys a Lunora query
139
+ * the same way.
140
+ */
141
+ type ArgsOf,
142
+ /**
143
+ * `@lunora/client/query` — the framework-neutral live-query state machine shared
144
+ * by every Lunora UI adapter (React, Vue, Svelte, Solid). It owns the seam
145
+ * between a `LunoraClient` subscription and a framework's reactivity primitive:
146
+ * the subscribe → snapshot → error/reset → cleanup lifecycle, with the
147
+ * skip-handling, value/error fan-out, attach-throw normalisation, and
148
+ * cancellation-guarded teardown all in one place. Nothing here imports a UI
149
+ * framework — each adapter supplies thin sinks that write into its own ref /
150
+ * store / signal / cache.
151
+ *
152
+ * It also owns the TanStack Query key contract (`lunoraQueryKey`,
153
+ * `lunoraQueryOptions`), so every adapter and server entry keys a Lunora query
154
+ * the same way.
155
+ */
156
+ type FunctionReference, type LunoraQueryKey, type LunoraQueryOptions, type QuerySubscriptionOptions, type QuerySubscriptionSinks, type ResolvedArgs,
157
+ /**
158
+ * `@lunora/client/query` — the framework-neutral live-query state machine shared
159
+ * by every Lunora UI adapter (React, Vue, Svelte, Solid). It owns the seam
160
+ * between a `LunoraClient` subscription and a framework's reactivity primitive:
161
+ * the subscribe → snapshot → error/reset → cleanup lifecycle, with the
162
+ * skip-handling, value/error fan-out, attach-throw normalisation, and
163
+ * cancellation-guarded teardown all in one place. Nothing here imports a UI
164
+ * framework — each adapter supplies thin sinks that write into its own ref /
165
+ * store / signal / cache.
166
+ *
167
+ * It also owns the TanStack Query key contract (`lunoraQueryKey`,
168
+ * `lunoraQueryOptions`), so every adapter and server entry keys a Lunora query
169
+ * the same way.
170
+ */
171
+ type ReturnOf, SKIP,
172
+ /**
173
+ * `@lunora/client/query` — the framework-neutral live-query state machine shared
174
+ * by every Lunora UI adapter (React, Vue, Svelte, Solid). It owns the seam
175
+ * between a `LunoraClient` subscription and a framework's reactivity primitive:
176
+ * the subscribe → snapshot → error/reset → cleanup lifecycle, with the
177
+ * skip-handling, value/error fan-out, attach-throw normalisation, and
178
+ * cancellation-guarded teardown all in one place. Nothing here imports a UI
179
+ * framework — each adapter supplies thin sinks that write into its own ref /
180
+ * store / signal / cache.
181
+ *
182
+ * It also owns the TanStack Query key contract (`lunoraQueryKey`,
183
+ * `lunoraQueryOptions`), so every adapter and server entry keys a Lunora query
184
+ * the same way.
185
+ */
186
+ type SubscriptionError,
187
+ /**
188
+ * `@lunora/client/query` — the framework-neutral live-query state machine shared
189
+ * by every Lunora UI adapter (React, Vue, Svelte, Solid). It owns the seam
190
+ * between a `LunoraClient` subscription and a framework's reactivity primitive:
191
+ * the subscribe → snapshot → error/reset → cleanup lifecycle, with the
192
+ * skip-handling, value/error fan-out, attach-throw normalisation, and
193
+ * cancellation-guarded teardown all in one place. Nothing here imports a UI
194
+ * framework — each adapter supplies thin sinks that write into its own ref /
195
+ * store / signal / cache.
196
+ *
197
+ * It also owns the TanStack Query key contract (`lunoraQueryKey`,
198
+ * `lunoraQueryOptions`), so every adapter and server entry keys a Lunora query
199
+ * the same way.
200
+ */
201
+ type Unsubscribe, createQuerySubscription, lunoraQueryKey, lunoraQueryKeyFromArgsKey, lunoraQueryOptions, toSubscriptionError };
@@ -1,26 +1,90 @@
1
- import { S as SubscriptionError, F as FunctionReference, A as ArgsOf, R as ReturnOf, L as LunoraClient, a as Unsubscribe } from "../packem_shared/lunora-client.d-DGvyuJ_p.js";
2
- export type { b as SubscriptionErrorCallback } from "../packem_shared/lunora-client.d-DGvyuJ_p.js";
3
- import '@lunora/runtime';
1
+ import { F as FunctionReference, R as ReturnOf, A as ArgsOf } from "../packem_shared/function-reference.d-Br_hsKje.js";
2
+ import { L as LunoraClient, S as SubscriptionError, a as Unsubscribe } from "../packem_shared/lunora-client.d-TchceUzJ.js";
3
+ export type {
4
4
  /**
5
- * The sentinel a framework adapter resolves its reactive args to when it wants
6
- * to short-circuit a query — no network call, no socket.
7
- */
5
+ * `@lunora/client/query` — the framework-neutral live-query state machine shared
6
+ * by every Lunora UI adapter (React, Vue, Svelte, Solid). It owns the seam
7
+ * between a `LunoraClient` subscription and a framework's reactivity primitive:
8
+ * the subscribe → snapshot → error/reset → cleanup lifecycle, with the
9
+ * skip-handling, value/error fan-out, attach-throw normalisation, and
10
+ * cancellation-guarded teardown all in one place. Nothing here imports a UI
11
+ * framework — each adapter supplies thin sinks that write into its own ref /
12
+ * store / signal / cache.
13
+ *
14
+ * It also owns the TanStack Query key contract (`lunoraQueryKey`,
15
+ * `lunoraQueryOptions`), so every adapter and server entry keys a Lunora query
16
+ * the same way.
17
+ */
18
+ b as SubscriptionErrorCallback } from "../packem_shared/lunora-client.d-TchceUzJ.js";
19
+ import '@lunora/errors';
20
+ /**
21
+ * The TanStack Query cache-key contract for Lunora queries. It lives here, not
22
+ * in an adapter, because every TanStack binding (React, Vue, Solid, Svelte,
23
+ * Angular Query) hashes keys the same way, and a value prefetched through one
24
+ * entry point must land under the exact key a hook reads back.
25
+ *
26
+ * Typed as `ReadonlyArray<unknown>` — TanStack v5's default `QueryKey` — so this
27
+ * module needs no TanStack dependency.
28
+ */
29
+ type LunoraQueryKey = ReadonlyArray<unknown>;
30
+ /**
31
+ * Project a Lunora `(fn, args, shardKey)` triple into the query key TanStack
32
+ * hashes for dedup. The `"lunora"` literal namespaces our entries so an app's
33
+ * own queries can't collide with ours.
34
+ *
35
+ * `args` sits in the key already encoded by `stableWireKey`, not as the raw
36
+ * object. TanStack hashes keys with `JSON.stringify`, which maps `NaN` to
37
+ * `null`, `-0` to `0` and a `Date` to its ISO string (so distinct args shared
38
+ * one cache entry and served each other's rows) and throws on a `bigint`. A
39
+ * string slot hashes the same under any hash function, so every QueryClient
40
+ * agrees on it without configuration.
41
+ */
42
+ declare const lunoraQueryKeyFromArgsKey: (ref: string, argsKey: string, shardKey: string | undefined) => LunoraQueryKey;
43
+ declare const lunoraQueryKey: (function_: FunctionReference, args: Record<string, unknown>, shardKey: string | undefined) => LunoraQueryKey;
44
+ /** Shape returned by `lunoraQueryOptions`, spread into a TanStack hook. */
45
+ interface LunoraQueryOptions<F extends FunctionReference> {
46
+ queryFn: () => Promise<ReturnOf<F>>;
47
+ queryKey: LunoraQueryKey;
48
+ staleTime: number;
49
+ }
50
+ /**
51
+ * Build a TanStack Query options object for a Lunora query, keyed identically
52
+ * to the adapters' first-class hooks (see `lunoraQueryKey`), so a value fetched
53
+ * through it shares cache identity with anything those hooks or a server-side
54
+ * `prefetchQuery` read or write for the same `(fn, args, shardKey)` triple.
55
+ *
56
+ * ```ts
57
+ * const { data } = useSuspenseQuery(lunoraQueryOptions(client, api.posts.list, {}));
58
+ * ```
59
+ *
60
+ * This is a one-shot fetch: it resolves once and `staleTime` is infinite, so
61
+ * TanStack never refetches on its own. It opens no WebSocket and has no
62
+ * framework or browser dependency, so it is safe on either side of an RSC
63
+ * boundary — the transport is the `LunoraClient` passed in.
64
+ */
65
+ declare const lunoraQueryOptions: <F extends FunctionReference>(client: LunoraClient, function_: F, args: ArgsOf<F>, options?: {
66
+ shardKey?: string;
67
+ }) => LunoraQueryOptions<F>;
68
+ /**
69
+ * The sentinel a framework adapter resolves its reactive args to when it wants
70
+ * to short-circuit a query — no network call, no socket.
71
+ */
8
72
  declare const SKIP: "skip";
9
73
  /** Args after a framework has resolved its reactivity primitive, or the skip sentinel. */
10
74
  type ResolvedArgs<F extends FunctionReference> = ArgsOf<F> | typeof SKIP;
11
75
  /**
12
- * The framework-neutral sinks a {@link createQuerySubscription} call drives. A
13
- * framework adapter supplies these, wiring each into its own reactivity
14
- * primitive (a TanStack cache write, a Vue `ref`, a Svelte store `set`, a Solid
15
- * signal setter).
16
- *
17
- * `onData` fires when a fresh server value lands (the initial frame or a delta).
18
- * `onError` fires when the subscription attach threw, or the server pushed a
19
- * subscription-scoped error — it is optional, and when omitted an attach throw
20
- * propagates to the caller (preserving the "no error channel" behaviour of
21
- * adapters like Solid/Vue that never had one) rather than being swallowed.
22
- * `onReset` fires when the resolved args are `"skip"`: clear any prior value.
23
- */
76
+ * The framework-neutral sinks a {@link createQuerySubscription} call drives. A
77
+ * framework adapter supplies these, wiring each into its own reactivity
78
+ * primitive (a TanStack cache write, a Vue `ref`, a Svelte store `set`, a Solid
79
+ * signal setter).
80
+ *
81
+ * `onData` fires when a fresh server value lands (the initial frame or a delta).
82
+ * `onError` fires when the subscription attach threw, or the server pushed a
83
+ * subscription-scoped error — it is optional, and when omitted an attach throw
84
+ * propagates to the caller (preserving the "no error channel" behaviour of
85
+ * adapters like Solid/Vue that never had one) rather than being swallowed.
86
+ * `onReset` fires when the resolved args are `"skip"`: clear any prior value.
87
+ */
24
88
  interface QuerySubscriptionSinks<T> {
25
89
  onData: (value: T) => void;
26
90
  onError?: (error: SubscriptionError) => void;
@@ -33,30 +97,105 @@ interface QuerySubscriptionOptions {
33
97
  /** Normalise an unknown thrown value into the client's {@link SubscriptionError} shape. */
34
98
  declare const toSubscriptionError: (error: unknown) => SubscriptionError;
35
99
  /**
36
- * The subscribe → snapshot → error/reset → cleanup state machine shared by
37
- * every Lunora framework adapter's live-query hook.
38
- *
39
- * Given a `client`, a function reference, the already-resolved `args` (a
40
- * framework reads its own reactive source first, then hands the plain value in),
41
- * and a set of {@link QuerySubscriptionSinks}, this opens one `client.subscribe`
42
- * registration and returns the {@link Unsubscribe} to tear it down. Each
43
- * framework owns *when* to call this (a React effect, a Vue `watch`, a Svelte
44
- * store start callback, a Solid `createEffect(on(...))`) and *where* to stash
45
- * the value — this owns the lifecycle in between, so the skip-handling, the
46
- * value/error fan-out, the attach-throw normalisation, and the
47
- * cancellation-guarded teardown live in exactly one place.
48
- *
49
- * Behaviour. When `args === "skip"` it calls `sinks.onReset?.()` and returns a
50
- * no-op teardown; no `client.subscribe` is issued. Otherwise it opens
51
- * `client.subscribe(fn, args, …, { shardKey, onError })`: server pushes route to
52
- * `sinks.onData`, and the client's own `onError` channel (a server-rejected
53
- * subscription) routes to `sinks.onError` when present. The attach is wrapped —
54
- * if `client.subscribe` itself throws, the error is normalised to a
55
- * {@link SubscriptionError} and delivered to `sinks.onError` when present; with
56
- * no `onError` sink the throw is rethrown so adapters without an error channel
57
- * behave exactly as before. The returned teardown is idempotent and
58
- * cancellation-guarded: once it runs, no further `onData`/`onError` from an
59
- * in-flight push reaches the sinks.
60
- */
100
+ * The subscribe → snapshot → error/reset → cleanup state machine shared by
101
+ * every Lunora framework adapter's live-query hook.
102
+ *
103
+ * Given a `client`, a function reference, the already-resolved `args` (a
104
+ * framework reads its own reactive source first, then hands the plain value in),
105
+ * and a set of {@link QuerySubscriptionSinks}, this opens one `client.subscribe`
106
+ * registration and returns the {@link Unsubscribe} to tear it down. Each
107
+ * framework owns *when* to call this (a React effect, a Vue `watch`, a Svelte
108
+ * store start callback, a Solid `createEffect(on(...))`) and *where* to stash
109
+ * the value — this owns the lifecycle in between, so the skip-handling, the
110
+ * value/error fan-out, the attach-throw normalisation, and the
111
+ * cancellation-guarded teardown live in exactly one place.
112
+ *
113
+ * Behaviour. When `args === "skip"` it calls `sinks.onReset?.()` and returns a
114
+ * no-op teardown; no `client.subscribe` is issued. Otherwise it opens
115
+ * `client.subscribe(fn, args, …, { shardKey, onError })`: server pushes route to
116
+ * `sinks.onData`, and the client's own `onError` channel (a server-rejected
117
+ * subscription) routes to `sinks.onError` when present. The attach is wrapped —
118
+ * if `client.subscribe` itself throws, the error is normalised to a
119
+ * {@link SubscriptionError} and delivered to `sinks.onError` when present; with
120
+ * no `onError` sink the throw is rethrown so adapters without an error channel
121
+ * behave exactly as before. The returned teardown is idempotent and
122
+ * cancellation-guarded: once it runs, no further `onData`/`onError` from an
123
+ * in-flight push reaches the sinks.
124
+ */
61
125
  declare const createQuerySubscription: <F extends FunctionReference, T = ReturnOf<F>>(client: LunoraClient, function_: F, args: ResolvedArgs<F>, sinks: QuerySubscriptionSinks<T>, options?: QuerySubscriptionOptions) => Unsubscribe;
62
- export { type ArgsOf, type FunctionReference, type QuerySubscriptionOptions, type QuerySubscriptionSinks, type ResolvedArgs, type ReturnOf, SKIP, type SubscriptionError, type Unsubscribe, createQuerySubscription, toSubscriptionError };
126
+ export {
127
+ /**
128
+ * `@lunora/client/query` — the framework-neutral live-query state machine shared
129
+ * by every Lunora UI adapter (React, Vue, Svelte, Solid). It owns the seam
130
+ * between a `LunoraClient` subscription and a framework's reactivity primitive:
131
+ * the subscribe → snapshot → error/reset → cleanup lifecycle, with the
132
+ * skip-handling, value/error fan-out, attach-throw normalisation, and
133
+ * cancellation-guarded teardown all in one place. Nothing here imports a UI
134
+ * framework — each adapter supplies thin sinks that write into its own ref /
135
+ * store / signal / cache.
136
+ *
137
+ * It also owns the TanStack Query key contract (`lunoraQueryKey`,
138
+ * `lunoraQueryOptions`), so every adapter and server entry keys a Lunora query
139
+ * the same way.
140
+ */
141
+ type ArgsOf,
142
+ /**
143
+ * `@lunora/client/query` — the framework-neutral live-query state machine shared
144
+ * by every Lunora UI adapter (React, Vue, Svelte, Solid). It owns the seam
145
+ * between a `LunoraClient` subscription and a framework's reactivity primitive:
146
+ * the subscribe → snapshot → error/reset → cleanup lifecycle, with the
147
+ * skip-handling, value/error fan-out, attach-throw normalisation, and
148
+ * cancellation-guarded teardown all in one place. Nothing here imports a UI
149
+ * framework — each adapter supplies thin sinks that write into its own ref /
150
+ * store / signal / cache.
151
+ *
152
+ * It also owns the TanStack Query key contract (`lunoraQueryKey`,
153
+ * `lunoraQueryOptions`), so every adapter and server entry keys a Lunora query
154
+ * the same way.
155
+ */
156
+ type FunctionReference, type LunoraQueryKey, type LunoraQueryOptions, type QuerySubscriptionOptions, type QuerySubscriptionSinks, type ResolvedArgs,
157
+ /**
158
+ * `@lunora/client/query` — the framework-neutral live-query state machine shared
159
+ * by every Lunora UI adapter (React, Vue, Svelte, Solid). It owns the seam
160
+ * between a `LunoraClient` subscription and a framework's reactivity primitive:
161
+ * the subscribe → snapshot → error/reset → cleanup lifecycle, with the
162
+ * skip-handling, value/error fan-out, attach-throw normalisation, and
163
+ * cancellation-guarded teardown all in one place. Nothing here imports a UI
164
+ * framework — each adapter supplies thin sinks that write into its own ref /
165
+ * store / signal / cache.
166
+ *
167
+ * It also owns the TanStack Query key contract (`lunoraQueryKey`,
168
+ * `lunoraQueryOptions`), so every adapter and server entry keys a Lunora query
169
+ * the same way.
170
+ */
171
+ type ReturnOf, SKIP,
172
+ /**
173
+ * `@lunora/client/query` — the framework-neutral live-query state machine shared
174
+ * by every Lunora UI adapter (React, Vue, Svelte, Solid). It owns the seam
175
+ * between a `LunoraClient` subscription and a framework's reactivity primitive:
176
+ * the subscribe → snapshot → error/reset → cleanup lifecycle, with the
177
+ * skip-handling, value/error fan-out, attach-throw normalisation, and
178
+ * cancellation-guarded teardown all in one place. Nothing here imports a UI
179
+ * framework — each adapter supplies thin sinks that write into its own ref /
180
+ * store / signal / cache.
181
+ *
182
+ * It also owns the TanStack Query key contract (`lunoraQueryKey`,
183
+ * `lunoraQueryOptions`), so every adapter and server entry keys a Lunora query
184
+ * the same way.
185
+ */
186
+ type SubscriptionError,
187
+ /**
188
+ * `@lunora/client/query` — the framework-neutral live-query state machine shared
189
+ * by every Lunora UI adapter (React, Vue, Svelte, Solid). It owns the seam
190
+ * between a `LunoraClient` subscription and a framework's reactivity primitive:
191
+ * the subscribe → snapshot → error/reset → cleanup lifecycle, with the
192
+ * skip-handling, value/error fan-out, attach-throw normalisation, and
193
+ * cancellation-guarded teardown all in one place. Nothing here imports a UI
194
+ * framework — each adapter supplies thin sinks that write into its own ref /
195
+ * store / signal / cache.
196
+ *
197
+ * It also owns the TanStack Query key contract (`lunoraQueryKey`,
198
+ * `lunoraQueryOptions`), so every adapter and server entry keys a Lunora query
199
+ * the same way.
200
+ */
201
+ type Unsubscribe, createQuerySubscription, lunoraQueryKey, lunoraQueryKeyFromArgsKey, lunoraQueryOptions, toSubscriptionError };
@@ -1 +1 @@
1
- export { SKIP, createQuerySubscription, toSubscriptionError } from '../packem_shared/SKIP-vItZChkw.mjs';
1
+ import{lunoraQueryKey as e,lunoraQueryKeyFromArgsKey as u,lunoraQueryOptions as t}from"../packem_shared/lunoraQueryKey-CucWmxnx.mjs";import{SKIP as n,createQuerySubscription as i,toSubscriptionError as p}from"../packem_shared/SKIP-d7LeP-sY.mjs";export{n as SKIP,i as createQuerySubscription,e as lunoraQueryKey,u as lunoraQueryKeyFromArgsKey,t as lunoraQueryOptions,p as toSubscriptionError};
@@ -0,0 +1,49 @@
1
+ import { F as FunctionReference, A as ArgsOf, R as ReturnOf } from "./packem_shared/function-reference.d-Br_hsKje.mjs";
2
+ /**
3
+ * The wire endpoint every Lunora Worker serves. Matches `createWorker`'s RPC
4
+ * route; the envelope shape below is that route's documented contract.
5
+ */
6
+ declare const RPC_PATH = "/_lunora/rpc";
7
+ /**
8
+ * The slice of a Cloudflare service binding this module uses.
9
+ *
10
+ * Structural on purpose: `env.BACKEND` satisfies it, and so does a one-method
11
+ * fake in a test. Declaring the full `Fetcher` would drag
12
+ * `@cloudflare/workers-types` into every consumer for a single method.
13
+ */
14
+ interface ServiceBindingLike {
15
+ fetch: (request: Request) => Promise<Response>;
16
+ }
17
+ interface ServiceCallOptions {
18
+ /**
19
+ * Route to a specific shard. Omitted, the callee routes to its default shard
20
+ * — the same rule the HTTP path follows, so a sharded app must pass the key
21
+ * it would have passed there.
22
+ */
23
+ shardKey?: string;
24
+ }
25
+ /**
26
+ * A typed caller bound to one Lunora Worker.
27
+ *
28
+ * The three methods are separate rather than one `call` so a reader can tell a
29
+ * read from a write at the call site, and so the reference's `Kind` is checked:
30
+ * passing a mutation reference to `query` is a compile error, matching how
31
+ * `ctx.runQuery`/`ctx.runMutation` behave inside an app.
32
+ */
33
+ interface LunoraServiceClient {
34
+ action: <F extends FunctionReference<"action">>(reference: F, args?: ArgsOf<F>, options?: ServiceCallOptions) => Promise<ReturnOf<F>>;
35
+ mutation: <F extends FunctionReference<"mutation">>(reference: F, args?: ArgsOf<F>, options?: ServiceCallOptions) => Promise<ReturnOf<F>>;
36
+ query: <F extends FunctionReference<"query">>(reference: F, args?: ArgsOf<F>, options?: ServiceCallOptions) => Promise<ReturnOf<F>>;
37
+ }
38
+ /**
39
+ * Build a typed caller for the Lunora Worker behind `binding`.
40
+ *
41
+ * Only PUBLIC functions are reachable. An `internal*` procedure is deliberately
42
+ * absent from the generated `api` object and rejected by the callee, because a
43
+ * service binding is a trust boundary between deployments, not the intra-app
44
+ * `ctx.run*` seam.
45
+ * @param binding The service binding, e.g. `env.BACKEND`.
46
+ * @returns a client whose methods type-check against the generated `api`.
47
+ */
48
+ declare const createServiceClient: (binding: ServiceBindingLike) => LunoraServiceClient;
49
+ export { type LunoraServiceClient, RPC_PATH, type ServiceBindingLike, type ServiceCallOptions, createServiceClient };
@@ -0,0 +1,49 @@
1
+ import { F as FunctionReference, A as ArgsOf, R as ReturnOf } from "./packem_shared/function-reference.d-Br_hsKje.js";
2
+ /**
3
+ * The wire endpoint every Lunora Worker serves. Matches `createWorker`'s RPC
4
+ * route; the envelope shape below is that route's documented contract.
5
+ */
6
+ declare const RPC_PATH = "/_lunora/rpc";
7
+ /**
8
+ * The slice of a Cloudflare service binding this module uses.
9
+ *
10
+ * Structural on purpose: `env.BACKEND` satisfies it, and so does a one-method
11
+ * fake in a test. Declaring the full `Fetcher` would drag
12
+ * `@cloudflare/workers-types` into every consumer for a single method.
13
+ */
14
+ interface ServiceBindingLike {
15
+ fetch: (request: Request) => Promise<Response>;
16
+ }
17
+ interface ServiceCallOptions {
18
+ /**
19
+ * Route to a specific shard. Omitted, the callee routes to its default shard
20
+ * — the same rule the HTTP path follows, so a sharded app must pass the key
21
+ * it would have passed there.
22
+ */
23
+ shardKey?: string;
24
+ }
25
+ /**
26
+ * A typed caller bound to one Lunora Worker.
27
+ *
28
+ * The three methods are separate rather than one `call` so a reader can tell a
29
+ * read from a write at the call site, and so the reference's `Kind` is checked:
30
+ * passing a mutation reference to `query` is a compile error, matching how
31
+ * `ctx.runQuery`/`ctx.runMutation` behave inside an app.
32
+ */
33
+ interface LunoraServiceClient {
34
+ action: <F extends FunctionReference<"action">>(reference: F, args?: ArgsOf<F>, options?: ServiceCallOptions) => Promise<ReturnOf<F>>;
35
+ mutation: <F extends FunctionReference<"mutation">>(reference: F, args?: ArgsOf<F>, options?: ServiceCallOptions) => Promise<ReturnOf<F>>;
36
+ query: <F extends FunctionReference<"query">>(reference: F, args?: ArgsOf<F>, options?: ServiceCallOptions) => Promise<ReturnOf<F>>;
37
+ }
38
+ /**
39
+ * Build a typed caller for the Lunora Worker behind `binding`.
40
+ *
41
+ * Only PUBLIC functions are reachable. An `internal*` procedure is deliberately
42
+ * absent from the generated `api` object and rejected by the callee, because a
43
+ * service binding is a trust boundary between deployments, not the intra-app
44
+ * `ctx.run*` seam.
45
+ * @param binding The service binding, e.g. `env.BACKEND`.
46
+ * @returns a client whose methods type-check against the generated `api`.
47
+ */
48
+ declare const createServiceClient: (binding: ServiceBindingLike) => LunoraServiceClient;
49
+ export { type LunoraServiceClient, RPC_PATH, type ServiceBindingLike, type ServiceCallOptions, createServiceClient };
@@ -0,0 +1 @@
1
+ import{LunoraError as c}from"@lunora/errors";import{encodeArgsOrThrow as d,decodeWire as y}from"@lunora/wire";import{e as f,r as w}from"./packem_shared/wire-errors-BDckSTKZ.mjs";const v="/_lunora/rpc",N="https://lunora.internal",i=async(n,t,r,o,u)=>{const a=r.__lunoraRef,p=JSON.stringify({args:d("@lunora/client/service",a,o??{}),functionPath:a,...u?.shardKey===void 0?{}:{shardKey:u.shardKey}}),e=await n.fetch(new Request(`${N}${v}`,{body:p,headers:{"content-type":"application/json"},method:"POST"}));let s;try{s=await e.json()}catch{throw new c("INTERNAL",`@lunora/client/service: ${t} "${a}" got a non-JSON response (status ${e.status.toString()}). Check the service binding points at the Lunora Worker that declares this function.`,{status:e.status})}if(s===null||typeof s!="object")throw new c("INTERNAL",`@lunora/client/service: ${t} "${a}" returned a JSON body that is not an object (status ${e.status.toString()}). Check the service binding points at the Lunora Worker that declares this function.`,{status:e.status});const h=s,l=f(h);if(l!==void 0)throw w(l);if(!e.ok)throw new c("INTERNAL",`@lunora/client/service: ${t} "${a}" failed with status ${e.status.toString()} and no error envelope.`,{status:e.status});return y(h.result)},R=n=>({action:async(t,r,o)=>await i(n,"action",t,r,o),mutation:async(t,r,o)=>await i(n,"mutation",t,r,o),query:async(t,r,o)=>await i(n,"query",t,r,o)});export{v as RPC_PATH,R as createServiceClient};