@lunora/client 1.0.0-alpha.7 → 1.0.0-alpha.71
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +6 -0
- package/dist/auth/index.d.mts +12 -10
- package/dist/auth/index.d.ts +12 -10
- package/dist/auth/index.mjs +1 -60
- package/dist/index.d.mts +878 -230
- package/dist/index.d.ts +878 -230
- package/dist/index.mjs +1 -15
- package/dist/packem_shared/CONFLICT_ERROR_CODE-CDDneB-G.mjs +1 -0
- package/dist/packem_shared/ClientServiceWorker-DXnBXeWK.mjs +1 -0
- package/dist/packem_shared/DEFAULT_MAX_BUFFER-D3QH2iaq.mjs +1 -0
- package/dist/packem_shared/LunoraClient-B9UMg5lY.mjs +1 -0
- package/dist/packem_shared/OfflineQueue-B6IWyX5W.mjs +1 -0
- package/dist/packem_shared/RETIRE_AFTER_DURABLE_SEQ_ADVANCE-DoEHtuR8.mjs +1 -0
- package/dist/packem_shared/SKIP-d7LeP-sY.mjs +1 -0
- package/dist/packem_shared/SubscriptionRegistry-BQPU90ST.mjs +1 -0
- package/dist/packem_shared/TabCoordinator-CXD7vulJ.mjs +1 -0
- package/dist/packem_shared/anyApi-CBOws2ZA.mjs +1 -0
- package/dist/packem_shared/applyDelta-BiegnbZR.mjs +1 -0
- package/dist/packem_shared/createAsyncStoragePersistence-CNdM5o1u.mjs +1 -0
- package/dist/packem_shared/createAsyncStorageQueryCache-MoM77Nwg.mjs +1 -0
- package/dist/packem_shared/createCallRunner-Bwcrfh76.mjs +1 -0
- package/dist/packem_shared/createClientQuery-B8Nfj-7o.mjs +1 -0
- package/dist/packem_shared/createInMemoryBookmarkStorage-BooZhW0n.mjs +1 -0
- package/dist/packem_shared/createInMemoryPersistence-C0qm7c47.mjs +1 -0
- package/dist/packem_shared/createInMemoryQueryCache-D2uNHLfM.mjs +1 -0
- package/dist/packem_shared/createLocalStore-v6oiATqG.mjs +1 -0
- package/dist/packem_shared/createMutatorRunner-CuMRJpUx.mjs +1 -0
- package/dist/packem_shared/createReconnect-CjTmjJDH.mjs +1 -0
- package/dist/packem_shared/createReply-CwFABEJs.mjs +1 -0
- package/dist/packem_shared/createServerClient-BevCicNQ.mjs +1 -0
- package/dist/packem_shared/createSnapshotPrecondition-C4bSgHkg.mjs +1 -0
- package/dist/packem_shared/delta-merge-BPM4sFID.mjs +1 -0
- package/dist/packem_shared/deserializePreloaded-CHfOFpka.mjs +1 -0
- package/dist/packem_shared/function-reference.d-Br_hsKje.d.mts +45 -0
- package/dist/packem_shared/function-reference.d-Br_hsKje.d.ts +45 -0
- package/dist/packem_shared/getServerSession-BaOoo1p6.mjs +1 -0
- package/dist/packem_shared/httpStream-x6q-x4yK.mjs +11 -0
- package/dist/packem_shared/idb-utility-C8WS390w.mjs +1 -0
- package/dist/packem_shared/local-store-CNgeGW02.mjs +1 -0
- package/dist/packem_shared/lunora-client.d-BSNUC85h.d.mts +3491 -0
- package/dist/packem_shared/lunora-client.d-BkDgDzTg.d.ts +3491 -0
- package/dist/packem_shared/offline-queue-8mpNPwG8.mjs +1 -0
- package/dist/packem_shared/preload.d-Do17SOqk.d.ts +21 -0
- package/dist/packem_shared/preload.d-XsWPDlX6.d.mts +21 -0
- package/dist/packem_shared/preloadQuery-uFy24PCR.mjs +1 -0
- package/dist/packem_shared/single-blob-store-DrhzObic.mjs +1 -0
- package/dist/packem_shared/wire-codec-BfIZrTJe.mjs +1 -0
- package/dist/packem_shared/wire-key-C9UKT-C3.mjs +1 -0
- package/dist/pagination/index.d.mts +42 -42
- package/dist/pagination/index.d.ts +42 -42
- package/dist/pagination/index.mjs +1 -61
- package/dist/query/index.d.mts +111 -43
- package/dist/query/index.d.ts +111 -43
- package/dist/query/index.mjs +1 -1
- package/dist/service.d.mts +49 -0
- package/dist/service.d.ts +49 -0
- package/dist/service.mjs +1 -0
- package/dist/ssr/index.d.mts +100 -79
- package/dist/ssr/index.d.ts +100 -79
- package/dist/ssr/index.mjs +1 -4
- package/dist/upload.d.mts +35 -0
- package/dist/upload.d.ts +35 -0
- package/dist/upload.mjs +1 -0
- package/package.json +16 -1
- package/dist/packem_shared/CONFLICT_ERROR_CODE-aUdVbEDw.mjs +0 -4
- package/dist/packem_shared/DEFAULT_MAX_BUFFER-BDkqO5PW.mjs +0 -107
- package/dist/packem_shared/LunoraClient-Bsv8immC.mjs +0 -2546
- package/dist/packem_shared/OfflineQueue-D-ASeqL7.mjs +0 -131
- package/dist/packem_shared/SKIP-vItZChkw.mjs +0 -50
- package/dist/packem_shared/SubscriptionRegistry-Dn-7k7eo.mjs +0 -1
- package/dist/packem_shared/applyDelta-4jFGTPA3.mjs +0 -61
- package/dist/packem_shared/createAsyncStoragePersistence-1Z5BZ8RC.mjs +0 -45
- package/dist/packem_shared/createInMemoryBookmarkStorage-BoN7a7TH.mjs +0 -11
- package/dist/packem_shared/createInMemoryPersistence-CW82inU5.mjs +0 -105
- package/dist/packem_shared/createInMemoryQueryCache-B1PQ9Twl.mjs +0 -138
- package/dist/packem_shared/createLocalStore-DSUfoLqY.mjs +0 -36
- package/dist/packem_shared/createMutationRunner-BqsavzvG.mjs +0 -21
- package/dist/packem_shared/createMutatorRunner-BETvCd0p.mjs +0 -31
- package/dist/packem_shared/createReconnect-Di_-oHH7.mjs +0 -22
- package/dist/packem_shared/createServerClient-DucOyOz3.mjs +0 -11
- package/dist/packem_shared/deserializePreloaded-C0eJTY_W.mjs +0 -4
- package/dist/packem_shared/getServerSession-8jXewqxd.mjs +0 -13
- package/dist/packem_shared/lunora-client.d-DLbxPGH9.d.mts +0 -2006
- package/dist/packem_shared/lunora-client.d-DLbxPGH9.d.ts +0 -2006
- package/dist/packem_shared/preload.d-BAT6GeSD.d.mts +0 -20
- package/dist/packem_shared/preload.d-CSkjbfEq.d.ts +0 -20
- package/dist/packem_shared/preloadQuery-lobFkD2Z.mjs +0 -13
- package/dist/packem_shared/subscription-C1Jy7HiF.mjs +0 -55
package/dist/query/index.d.ts
CHANGED
|
@@ -1,26 +1,39 @@
|
|
|
1
|
-
import { S as SubscriptionError,
|
|
2
|
-
export type {
|
|
1
|
+
import { S as SubscriptionError, L as LunoraClient, a as Unsubscribe } from "../packem_shared/lunora-client.d-BkDgDzTg.js";
|
|
2
|
+
export type {
|
|
3
|
+
/**
|
|
4
|
+
* `@lunora/client/query` — the framework-neutral live-query state machine shared
|
|
5
|
+
* by every Lunora UI adapter (React, Vue, Svelte, Solid). It owns the seam
|
|
6
|
+
* between a `LunoraClient` subscription and a framework's reactivity primitive:
|
|
7
|
+
* the subscribe → snapshot → error/reset → cleanup lifecycle, with the
|
|
8
|
+
* skip-handling, value/error fan-out, attach-throw normalisation, and
|
|
9
|
+
* cancellation-guarded teardown all in one place. Nothing here imports a UI
|
|
10
|
+
* framework — each adapter supplies thin sinks that write into its own ref /
|
|
11
|
+
* store / signal / cache.
|
|
12
|
+
*/
|
|
13
|
+
b as SubscriptionErrorCallback } from "../packem_shared/lunora-client.d-BkDgDzTg.js";
|
|
14
|
+
import { F as FunctionReference, A as ArgsOf, R as ReturnOf } from "../packem_shared/function-reference.d-Br_hsKje.js";
|
|
15
|
+
import '@lunora/errors';
|
|
3
16
|
import '@lunora/runtime';
|
|
4
17
|
/**
|
|
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
|
-
*/
|
|
18
|
+
* The sentinel a framework adapter resolves its reactive args to when it wants
|
|
19
|
+
* to short-circuit a query — no network call, no socket.
|
|
20
|
+
*/
|
|
8
21
|
declare const SKIP: "skip";
|
|
9
22
|
/** Args after a framework has resolved its reactivity primitive, or the skip sentinel. */
|
|
10
23
|
type ResolvedArgs<F extends FunctionReference> = ArgsOf<F> | typeof SKIP;
|
|
11
24
|
/**
|
|
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
|
-
*/
|
|
25
|
+
* The framework-neutral sinks a {@link createQuerySubscription} call drives. A
|
|
26
|
+
* framework adapter supplies these, wiring each into its own reactivity
|
|
27
|
+
* primitive (a TanStack cache write, a Vue `ref`, a Svelte store `set`, a Solid
|
|
28
|
+
* signal setter).
|
|
29
|
+
*
|
|
30
|
+
* `onData` fires when a fresh server value lands (the initial frame or a delta).
|
|
31
|
+
* `onError` fires when the subscription attach threw, or the server pushed a
|
|
32
|
+
* subscription-scoped error — it is optional, and when omitted an attach throw
|
|
33
|
+
* propagates to the caller (preserving the "no error channel" behaviour of
|
|
34
|
+
* adapters like Solid/Vue that never had one) rather than being swallowed.
|
|
35
|
+
* `onReset` fires when the resolved args are `"skip"`: clear any prior value.
|
|
36
|
+
*/
|
|
24
37
|
interface QuerySubscriptionSinks<T> {
|
|
25
38
|
onData: (value: T) => void;
|
|
26
39
|
onError?: (error: SubscriptionError) => void;
|
|
@@ -33,30 +46,85 @@ interface QuerySubscriptionOptions {
|
|
|
33
46
|
/** Normalise an unknown thrown value into the client's {@link SubscriptionError} shape. */
|
|
34
47
|
declare const toSubscriptionError: (error: unknown) => SubscriptionError;
|
|
35
48
|
/**
|
|
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
|
-
*/
|
|
49
|
+
* The subscribe → snapshot → error/reset → cleanup state machine shared by
|
|
50
|
+
* every Lunora framework adapter's live-query hook.
|
|
51
|
+
*
|
|
52
|
+
* Given a `client`, a function reference, the already-resolved `args` (a
|
|
53
|
+
* framework reads its own reactive source first, then hands the plain value in),
|
|
54
|
+
* and a set of {@link QuerySubscriptionSinks}, this opens one `client.subscribe`
|
|
55
|
+
* registration and returns the {@link Unsubscribe} to tear it down. Each
|
|
56
|
+
* framework owns *when* to call this (a React effect, a Vue `watch`, a Svelte
|
|
57
|
+
* store start callback, a Solid `createEffect(on(...))`) and *where* to stash
|
|
58
|
+
* the value — this owns the lifecycle in between, so the skip-handling, the
|
|
59
|
+
* value/error fan-out, the attach-throw normalisation, and the
|
|
60
|
+
* cancellation-guarded teardown live in exactly one place.
|
|
61
|
+
*
|
|
62
|
+
* Behaviour. When `args === "skip"` it calls `sinks.onReset?.()` and returns a
|
|
63
|
+
* no-op teardown; no `client.subscribe` is issued. Otherwise it opens
|
|
64
|
+
* `client.subscribe(fn, args, …, { shardKey, onError })`: server pushes route to
|
|
65
|
+
* `sinks.onData`, and the client's own `onError` channel (a server-rejected
|
|
66
|
+
* subscription) routes to `sinks.onError` when present. The attach is wrapped —
|
|
67
|
+
* if `client.subscribe` itself throws, the error is normalised to a
|
|
68
|
+
* {@link SubscriptionError} and delivered to `sinks.onError` when present; with
|
|
69
|
+
* no `onError` sink the throw is rethrown so adapters without an error channel
|
|
70
|
+
* behave exactly as before. The returned teardown is idempotent and
|
|
71
|
+
* cancellation-guarded: once it runs, no further `onData`/`onError` from an
|
|
72
|
+
* in-flight push reaches the sinks.
|
|
73
|
+
*/
|
|
61
74
|
declare const createQuerySubscription: <F extends FunctionReference, T = ReturnOf<F>>(client: LunoraClient, function_: F, args: ResolvedArgs<F>, sinks: QuerySubscriptionSinks<T>, options?: QuerySubscriptionOptions) => Unsubscribe;
|
|
62
|
-
export {
|
|
75
|
+
export {
|
|
76
|
+
/**
|
|
77
|
+
* `@lunora/client/query` — the framework-neutral live-query state machine shared
|
|
78
|
+
* by every Lunora UI adapter (React, Vue, Svelte, Solid). It owns the seam
|
|
79
|
+
* between a `LunoraClient` subscription and a framework's reactivity primitive:
|
|
80
|
+
* the subscribe → snapshot → error/reset → cleanup lifecycle, with the
|
|
81
|
+
* skip-handling, value/error fan-out, attach-throw normalisation, and
|
|
82
|
+
* cancellation-guarded teardown all in one place. Nothing here imports a UI
|
|
83
|
+
* framework — each adapter supplies thin sinks that write into its own ref /
|
|
84
|
+
* store / signal / cache.
|
|
85
|
+
*/
|
|
86
|
+
type ArgsOf,
|
|
87
|
+
/**
|
|
88
|
+
* `@lunora/client/query` — the framework-neutral live-query state machine shared
|
|
89
|
+
* by every Lunora UI adapter (React, Vue, Svelte, Solid). It owns the seam
|
|
90
|
+
* between a `LunoraClient` subscription and a framework's reactivity primitive:
|
|
91
|
+
* the subscribe → snapshot → error/reset → cleanup lifecycle, with the
|
|
92
|
+
* skip-handling, value/error fan-out, attach-throw normalisation, and
|
|
93
|
+
* cancellation-guarded teardown all in one place. Nothing here imports a UI
|
|
94
|
+
* framework — each adapter supplies thin sinks that write into its own ref /
|
|
95
|
+
* store / signal / cache.
|
|
96
|
+
*/
|
|
97
|
+
type FunctionReference, type QuerySubscriptionOptions, type QuerySubscriptionSinks, type ResolvedArgs,
|
|
98
|
+
/**
|
|
99
|
+
* `@lunora/client/query` — the framework-neutral live-query state machine shared
|
|
100
|
+
* by every Lunora UI adapter (React, Vue, Svelte, Solid). It owns the seam
|
|
101
|
+
* between a `LunoraClient` subscription and a framework's reactivity primitive:
|
|
102
|
+
* the subscribe → snapshot → error/reset → cleanup lifecycle, with the
|
|
103
|
+
* skip-handling, value/error fan-out, attach-throw normalisation, and
|
|
104
|
+
* cancellation-guarded teardown all in one place. Nothing here imports a UI
|
|
105
|
+
* framework — each adapter supplies thin sinks that write into its own ref /
|
|
106
|
+
* store / signal / cache.
|
|
107
|
+
*/
|
|
108
|
+
type ReturnOf, SKIP,
|
|
109
|
+
/**
|
|
110
|
+
* `@lunora/client/query` — the framework-neutral live-query state machine shared
|
|
111
|
+
* by every Lunora UI adapter (React, Vue, Svelte, Solid). It owns the seam
|
|
112
|
+
* between a `LunoraClient` subscription and a framework's reactivity primitive:
|
|
113
|
+
* the subscribe → snapshot → error/reset → cleanup lifecycle, with the
|
|
114
|
+
* skip-handling, value/error fan-out, attach-throw normalisation, and
|
|
115
|
+
* cancellation-guarded teardown all in one place. Nothing here imports a UI
|
|
116
|
+
* framework — each adapter supplies thin sinks that write into its own ref /
|
|
117
|
+
* store / signal / cache.
|
|
118
|
+
*/
|
|
119
|
+
type SubscriptionError,
|
|
120
|
+
/**
|
|
121
|
+
* `@lunora/client/query` — the framework-neutral live-query state machine shared
|
|
122
|
+
* by every Lunora UI adapter (React, Vue, Svelte, Solid). It owns the seam
|
|
123
|
+
* between a `LunoraClient` subscription and a framework's reactivity primitive:
|
|
124
|
+
* the subscribe → snapshot → error/reset → cleanup lifecycle, with the
|
|
125
|
+
* skip-handling, value/error fan-out, attach-throw normalisation, and
|
|
126
|
+
* cancellation-guarded teardown all in one place. Nothing here imports a UI
|
|
127
|
+
* framework — each adapter supplies thin sinks that write into its own ref /
|
|
128
|
+
* store / signal / cache.
|
|
129
|
+
*/
|
|
130
|
+
type Unsubscribe, createQuerySubscription, toSubscriptionError };
|
package/dist/query/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{SKIP as t,createQuerySubscription as e,toSubscriptionError as i}from"../packem_shared/SKIP-d7LeP-sY.mjs";export{t as SKIP,e as createQuerySubscription,i 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 };
|
package/dist/service.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LunoraError as u}from"@lunora/errors";import{e as w,d as f}from"./packem_shared/wire-codec-BfIZrTJe.mjs";const v="/_lunora/rpc",$="https://lunora.internal",N=e=>{const t=new Error(e.message??"request failed");return t.code=e.code,e.data!==void 0&&(t.data=f(e.data)),e.hint!==void 0&&(t.hint=e.hint),e.docsUrl!==void 0&&(t.docsUrl=e.docsUrl),t},h=async(e,t,r,a,l)=>{const s=r.__lunoraRef;let d;try{d=JSON.stringify({args:w(a??{}),functionPath:s,...l?.shardKey===void 0?{}:{shardKey:l.shardKey}})}catch(o){const p=o instanceof Error?o.message:String(o);throw new TypeError(`@lunora/client/service: cannot encode args for '${s}' — ${p}`,o instanceof Error?{cause:o}:void 0)}const n=await e.fetch(new Request(`${$}${v}`,{body:d,headers:{"content-type":"application/json"},method:"POST"}));let i;try{i=await n.json()}catch{throw new u("INTERNAL",`@lunora/client/service: ${t} "${s}" got a non-JSON response (status ${n.status.toString()}). Check the service binding points at the Lunora Worker that declares this function.`,{status:n.status})}if(i===null||typeof i!="object")throw new u("INTERNAL",`@lunora/client/service: ${t} "${s}" returned a JSON body that is not an object (status ${n.status.toString()}). Check the service binding points at the Lunora Worker that declares this function.`,{status:n.status});const c=i;if("error"in c)throw N(c.error);if(!n.ok)throw new u("INTERNAL",`@lunora/client/service: ${t} "${s}" failed with status ${n.status.toString()} and no error envelope.`,{status:n.status});return f(c.result)},E=e=>({action:async(t,r,a)=>await h(e,"action",t,r,a),mutation:async(t,r,a)=>await h(e,"mutation",t,r,a),query:async(t,r,a)=>await h(e,"query",t,r,a)});export{v as RPC_PATH,E as createServiceClient};
|
package/dist/ssr/index.d.mts
CHANGED
|
@@ -1,27 +1,48 @@
|
|
|
1
|
-
import { P as Preloaded, L as LunoraClient } from "../packem_shared/lunora-client.d-
|
|
2
|
-
export type { A as ArgsOf, F as FunctionReference, R as ReturnOf } from "../packem_shared/
|
|
3
|
-
export {
|
|
1
|
+
import { P as Preloaded, L as LunoraClient } from "../packem_shared/lunora-client.d-BSNUC85h.mjs";
|
|
2
|
+
export type { A as ArgsOf, F as FunctionReference, R as ReturnOf } from "../packem_shared/function-reference.d-Br_hsKje.mjs";
|
|
3
|
+
export {
|
|
4
|
+
/**
|
|
5
|
+
* `@lunora/client/ssr` — the framework-neutral server contract that every Lunora
|
|
6
|
+
* meta-framework adapter (React, Solid, Svelte, Vue) depends on. It owns the
|
|
7
|
+
* server-side seam: a request-scoped HTTP RPC client, session resolution from
|
|
8
|
+
* the inbound request, query preloading, and the dehydrate/serialize helpers
|
|
9
|
+
* for handing a preloaded snapshot to the client. Nothing here opens a
|
|
10
|
+
* WebSocket or touches a UI framework, so it is safe to import from any SSR
|
|
11
|
+
* loader.
|
|
12
|
+
*/
|
|
13
|
+
p as preloadQuery,
|
|
14
|
+
/**
|
|
15
|
+
* `@lunora/client/ssr` — the framework-neutral server contract that every Lunora
|
|
16
|
+
* meta-framework adapter (React, Solid, Svelte, Vue) depends on. It owns the
|
|
17
|
+
* server-side seam: a request-scoped HTTP RPC client, session resolution from
|
|
18
|
+
* the inbound request, query preloading, and the dehydrate/serialize helpers
|
|
19
|
+
* for handing a preloaded snapshot to the client. Nothing here opens a
|
|
20
|
+
* WebSocket or touches a UI framework, so it is safe to import from any SSR
|
|
21
|
+
* loader.
|
|
22
|
+
*/
|
|
23
|
+
a as preloadedQueryResult } from "../packem_shared/preload.d-XsWPDlX6.mjs";
|
|
24
|
+
import '@lunora/errors';
|
|
4
25
|
import '@lunora/runtime';
|
|
5
26
|
/**
|
|
6
|
-
* Structural shape of a better-auth `getSession` call's resolved value.
|
|
7
|
-
*
|
|
8
|
-
* better-auth's `auth.api.getSession({ headers })` returns `{ user, session }`
|
|
9
|
-
* when a valid session cookie is present, or `null` otherwise. We keep `user`
|
|
10
|
-
* and `session` as open records so `@lunora/client/ssr` carries no hard dependency on
|
|
11
|
-
* better-auth's concrete `User`/`Session` types — the adapter passing the real
|
|
12
|
-
* `auth` instance keeps full inference, while this package stays decoupled.
|
|
13
|
-
*/
|
|
27
|
+
* Structural shape of a better-auth `getSession` call's resolved value.
|
|
28
|
+
*
|
|
29
|
+
* better-auth's `auth.api.getSession({ headers })` returns `{ user, session }`
|
|
30
|
+
* when a valid session cookie is present, or `null` otherwise. We keep `user`
|
|
31
|
+
* and `session` as open records so `@lunora/client/ssr` carries no hard dependency on
|
|
32
|
+
* better-auth's concrete `User`/`Session` types — the adapter passing the real
|
|
33
|
+
* `auth` instance keeps full inference, while this package stays decoupled.
|
|
34
|
+
*/
|
|
14
35
|
interface ServerSession<User extends Record<string, unknown> = Record<string, unknown>, Session extends Record<string, unknown> = Record<string, unknown>> {
|
|
15
36
|
readonly session: Session;
|
|
16
37
|
readonly user: User;
|
|
17
38
|
}
|
|
18
39
|
/**
|
|
19
|
-
* Structural subset of a better-auth instance: just the one endpoint
|
|
20
|
-
* `getServerSession` needs. Typing it this way (rather than importing
|
|
21
|
-
* `@lunora/auth`'s `LunoraAuth`) means `@lunora/client/ssr` does not depend on
|
|
22
|
-
* better-auth internals — any object exposing `api.getSession` works, including
|
|
23
|
-
* a test stub. The concrete return type is inferred from the passed instance.
|
|
24
|
-
*/
|
|
40
|
+
* Structural subset of a better-auth instance: just the one endpoint
|
|
41
|
+
* `getServerSession` needs. Typing it this way (rather than importing
|
|
42
|
+
* `@lunora/auth`'s `LunoraAuth`) means `@lunora/client/ssr` does not depend on
|
|
43
|
+
* better-auth internals — any object exposing `api.getSession` works, including
|
|
44
|
+
* a test stub. The concrete return type is inferred from the passed instance.
|
|
45
|
+
*/
|
|
25
46
|
interface AuthLike<Result = ServerSession | null> {
|
|
26
47
|
readonly api: {
|
|
27
48
|
getSession: (input: {
|
|
@@ -30,86 +51,86 @@ interface AuthLike<Result = ServerSession | null> {
|
|
|
30
51
|
};
|
|
31
52
|
}
|
|
32
53
|
/**
|
|
33
|
-
* Anything `getServerSession` can read request headers from: a `Request`, a
|
|
34
|
-
* `Headers` object, or a plain object exposing `headers`. SSR loaders across
|
|
35
|
-
* meta-frameworks hand back slightly different request objects, so accept the
|
|
36
|
-
* common shapes rather than forcing the caller to unwrap.
|
|
37
|
-
*/
|
|
54
|
+
* Anything `getServerSession` can read request headers from: a `Request`, a
|
|
55
|
+
* `Headers` object, or a plain object exposing `headers`. SSR loaders across
|
|
56
|
+
* meta-frameworks hand back slightly different request objects, so accept the
|
|
57
|
+
* common shapes rather than forcing the caller to unwrap.
|
|
58
|
+
*/
|
|
38
59
|
type HeadersSource = Headers | Request | {
|
|
39
60
|
readonly headers: Headers;
|
|
40
61
|
};
|
|
41
62
|
/**
|
|
42
|
-
* Resolve the signed-in session from a request inside an SSR loader.
|
|
43
|
-
*
|
|
44
|
-
* Wraps `auth.api.getSession({ headers })` — the helper every meta-framework
|
|
45
|
-
* app otherwise hand-rolls — so a loader can read identity off the inbound
|
|
46
|
-
* cookies in one call. Returns `{ user, session }` when a valid session cookie
|
|
47
|
-
* is present, or `null` for anonymous requests.
|
|
48
|
-
*
|
|
49
|
-
* The `auth` parameter is structurally typed ({@link AuthLike}), so this
|
|
50
|
-
* package does not depend on better-auth internals; pass a real
|
|
51
|
-
* `@lunora/auth` instance to keep full type inference on `user`/`session`.
|
|
52
|
-
* Forward the resolved session's token to `createServerClient` to run the
|
|
53
|
-
* server-side load (and the later WS subscription) as the same identity.
|
|
54
|
-
*/
|
|
63
|
+
* Resolve the signed-in session from a request inside an SSR loader.
|
|
64
|
+
*
|
|
65
|
+
* Wraps `auth.api.getSession({ headers })` — the helper every meta-framework
|
|
66
|
+
* app otherwise hand-rolls — so a loader can read identity off the inbound
|
|
67
|
+
* cookies in one call. Returns `{ user, session }` when a valid session cookie
|
|
68
|
+
* is present, or `null` for anonymous requests.
|
|
69
|
+
*
|
|
70
|
+
* The `auth` parameter is structurally typed ({@link AuthLike}), so this
|
|
71
|
+
* package does not depend on better-auth internals; pass a real
|
|
72
|
+
* `@lunora/auth` instance to keep full type inference on `user`/`session`.
|
|
73
|
+
* Forward the resolved session's token to `createServerClient` to run the
|
|
74
|
+
* server-side load (and the later WS subscription) as the same identity.
|
|
75
|
+
*/
|
|
55
76
|
declare const getServerSession: <Result>(request: HeadersSource, auth: AuthLike<Result>) => Promise<NonNullable<Result> | null>;
|
|
56
77
|
/**
|
|
57
|
-
* Serialize a {@link Preloaded} token to a JSON string for embedding in the
|
|
58
|
-
* rendered HTML (e.g. a
|
|
59
|
-
* reads on hydration). Every field of `Preloaded` is JSON-serializable by
|
|
60
|
-
* construction — `preloadQuery` only captures the query args, function path,
|
|
61
|
-
* optional shard key, and the resolved value — so this is a thin, explicit
|
|
62
|
-
* `JSON.stringify` that documents the dehydration seam and keeps callers from
|
|
63
|
-
* accidentally stringifying a non-serializable wrapper.
|
|
64
|
-
*
|
|
65
|
-
* The
|
|
66
|
-
*
|
|
67
|
-
* it — the standard XSS-safe script-embedding precaution. This escaping is NOT
|
|
68
|
-
* sufficient for an HTML *attribute* sink (which also needs the quote and
|
|
69
|
-
* characters escaped); embed the output in a raw-text script element, not a
|
|
70
|
-
* data attribute.
|
|
71
|
-
*/
|
|
78
|
+
* Serialize a {@link Preloaded} token to a JSON string for embedding in the
|
|
79
|
+
* rendered HTML (e.g. a `<script>` payload the client
|
|
80
|
+
* reads on hydration). Every field of `Preloaded` is JSON-serializable by
|
|
81
|
+
* construction — `preloadQuery` only captures the query args, function path,
|
|
82
|
+
* optional shard key, and the resolved value — so this is a thin, explicit
|
|
83
|
+
* `JSON.stringify` that documents the dehydration seam and keeps callers from
|
|
84
|
+
* accidentally stringifying a non-serializable wrapper.
|
|
85
|
+
*
|
|
86
|
+
* The `<` is escaped to `<` so the payload is safe to inline inside a
|
|
87
|
+
* `<script>` tag without a stray `<\/script>` (or `<!--`) prematurely closing
|
|
88
|
+
* it — the standard XSS-safe script-embedding precaution. This escaping is NOT
|
|
89
|
+
* sufficient for an HTML *attribute* sink (which also needs the quote and `&`
|
|
90
|
+
* characters escaped); embed the output in a raw-text script element, not a
|
|
91
|
+
* data attribute.
|
|
92
|
+
*/
|
|
72
93
|
declare const serializePreloaded: <T>(preloaded: Preloaded<T>) => string;
|
|
73
94
|
/**
|
|
74
|
-
* Inverse of {@link serializePreloaded}: parse a serialized token back into a
|
|
75
|
-
* {@link Preloaded} value on the client. The
|
|
76
|
-
* is transparent to `JSON.parse`, so no un-escaping step is needed.
|
|
77
|
-
*/
|
|
95
|
+
* Inverse of {@link serializePreloaded}: parse a serialized token back into a
|
|
96
|
+
* {@link Preloaded} value on the client. The `<` escape from serialization
|
|
97
|
+
* is transparent to `JSON.parse`, so no un-escaping step is needed.
|
|
98
|
+
*/
|
|
78
99
|
declare const deserializePreloaded: <T = unknown>(serialized: string) => Preloaded<T>;
|
|
79
100
|
/** Options accepted by {@link createServerClient}. */
|
|
80
101
|
interface ServerClientOptions {
|
|
81
102
|
/**
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
103
|
+
* `fetch` implementation used for HTTP RPC. Defaults to the ambient global
|
|
104
|
+
* `fetch` (present in Node 18+, Workers, and meta-framework SSR runtimes).
|
|
105
|
+
* Pass one explicitly to forward cookies/headers or to use an instrumented
|
|
106
|
+
* fetch.
|
|
107
|
+
*/
|
|
87
108
|
fetch?: typeof fetch;
|
|
88
109
|
/**
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
110
|
+
* Bearer token sent as `Authorization: Bearer <token>` on every RPC. In an
|
|
111
|
+
* SSR loader you typically read this from the request (e.g. the session
|
|
112
|
+
* resolved by `getServerSession`) and pass it here so the server-side
|
|
113
|
+
* load runs as the signed-in user — and so the client subscription that
|
|
114
|
+
* resumes after hydration carries the same identity.
|
|
115
|
+
*/
|
|
95
116
|
token?: string;
|
|
96
117
|
/** Base URL of the deployed Lunora worker, e.g. `https://app.example.workers.dev`. */
|
|
97
118
|
url: string;
|
|
98
119
|
}
|
|
99
120
|
/**
|
|
100
|
-
* Build a request-scoped {@link LunoraClient} for use inside an SSR loader. SSR
|
|
101
|
-
* data loading only ever calls `.query()` (HTTP RPC over `fetch`); a
|
|
102
|
-
* `LunoraClient` opens a socket lazily on `.subscribe()`/`.stream()` and those
|
|
103
|
-
* are never called server-side, so no live connection is established even if the
|
|
104
|
-
* server runtime happens to expose a global `WebSocket`.
|
|
105
|
-
*
|
|
106
|
-
* Create one per request rather than sharing a module-level instance: the bearer
|
|
107
|
-
* token (and any forwarded cookies in `fetch`) are per-user, and a shared client
|
|
108
|
-
* would leak one request's identity into another.
|
|
109
|
-
*
|
|
110
|
-
* This is the framework-neutral home of the helper that previously lived only in
|
|
111
|
-
* `@lunora/react/server`; the React server module re-exports the same surface so
|
|
112
|
-
* existing imports keep working.
|
|
113
|
-
*/
|
|
121
|
+
* Build a request-scoped {@link LunoraClient} for use inside an SSR loader. SSR
|
|
122
|
+
* data loading only ever calls `.query()` (HTTP RPC over `fetch`); a
|
|
123
|
+
* `LunoraClient` opens a socket lazily on `.subscribe()`/`.stream()` and those
|
|
124
|
+
* are never called server-side, so no live connection is established even if the
|
|
125
|
+
* server runtime happens to expose a global `WebSocket`.
|
|
126
|
+
*
|
|
127
|
+
* Create one per request rather than sharing a module-level instance: the bearer
|
|
128
|
+
* token (and any forwarded cookies in `fetch`) are per-user, and a shared client
|
|
129
|
+
* would leak one request's identity into another.
|
|
130
|
+
*
|
|
131
|
+
* This is the framework-neutral home of the helper that previously lived only in
|
|
132
|
+
* `@lunora/react/server`; the React server module re-exports the same surface so
|
|
133
|
+
* existing imports keep working.
|
|
134
|
+
*/
|
|
114
135
|
declare const createServerClient: (options: ServerClientOptions) => LunoraClient;
|
|
115
136
|
export { type AuthLike, type HeadersSource, type Preloaded, type ServerClientOptions, type ServerSession, createServerClient, deserializePreloaded, getServerSession, serializePreloaded };
|