@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,27 +1,47 @@
1
- import { P as Preloaded, L as LunoraClient } from "../packem_shared/lunora-client.d-DGvyuJ_p.mjs";
2
- export type { A as ArgsOf, F as FunctionReference, R as ReturnOf } from "../packem_shared/lunora-client.d-DGvyuJ_p.mjs";
3
- export { p as preloadQuery, a as preloadedQueryResult } from "../packem_shared/preload.d-dSaRMuhL.mjs";
4
- import '@lunora/runtime';
1
+ import { P as Preloaded, L as LunoraClient } from "../packem_shared/lunora-client.d-BswMNnv7.mjs";
2
+ export type { A as ArgsOf, F as FunctionReference, R as ReturnOf } from "../packem_shared/function-reference.d-Br_hsKje.mjs";
3
+ export {
5
4
  /**
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
- */
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-qY64gg1w.mjs";
24
+ import '@lunora/errors';
25
+ /**
26
+ * Structural shape of a better-auth `getSession` call's resolved value.
27
+ *
28
+ * better-auth's `auth.api.getSession({ headers })` returns `{ user, session }`
29
+ * when a valid session cookie is present, or `null` otherwise. We keep `user`
30
+ * and `session` as open records so `@lunora/client/ssr` carries no hard dependency on
31
+ * better-auth's concrete `User`/`Session` types — the adapter passing the real
32
+ * `auth` instance keeps full inference, while this package stays decoupled.
33
+ */
14
34
  interface ServerSession<User extends Record<string, unknown> = Record<string, unknown>, Session extends Record<string, unknown> = Record<string, unknown>> {
15
35
  readonly session: Session;
16
36
  readonly user: User;
17
37
  }
18
38
  /**
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
- */
39
+ * Structural subset of a better-auth instance: just the one endpoint
40
+ * `getServerSession` needs. Typing it this way (rather than importing
41
+ * `@lunora/auth`'s `LunoraAuth`) means `@lunora/client/ssr` does not depend on
42
+ * better-auth internals — any object exposing `api.getSession` works, including
43
+ * a test stub. The concrete return type is inferred from the passed instance.
44
+ */
25
45
  interface AuthLike<Result = ServerSession | null> {
26
46
  readonly api: {
27
47
  getSession: (input: {
@@ -30,86 +50,95 @@ interface AuthLike<Result = ServerSession | null> {
30
50
  };
31
51
  }
32
52
  /**
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
- */
53
+ * Anything `getServerSession` can read request headers from: a `Request`, a
54
+ * `Headers` object, or a plain object exposing `headers`. SSR loaders across
55
+ * meta-frameworks hand back slightly different request objects, so accept the
56
+ * common shapes rather than forcing the caller to unwrap.
57
+ */
38
58
  type HeadersSource = Headers | Request | {
39
59
  readonly headers: Headers;
40
60
  };
41
61
  /**
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
- */
62
+ * Resolve the signed-in session from a request inside an SSR loader.
63
+ *
64
+ * Wraps `auth.api.getSession({ headers })` — the helper every meta-framework
65
+ * app otherwise hand-rolls — so a loader can read identity off the inbound
66
+ * cookies in one call. Returns `{ user, session }` when a valid session cookie
67
+ * is present, or `null` for anonymous requests.
68
+ *
69
+ * The `auth` parameter is structurally typed ({@link AuthLike}), so this
70
+ * package does not depend on better-auth internals; pass a real
71
+ * `@lunora/auth` instance to keep full type inference on `user`/`session`.
72
+ * Forward the resolved session's token to `createServerClient` to run the
73
+ * server-side load (and the later WS subscription) as the same identity.
74
+ */
55
75
  declare const getServerSession: <Result>(request: HeadersSource, auth: AuthLike<Result>) => Promise<NonNullable<Result> | null>;
56
76
  /**
57
- * Serialize a {@link Preloaded} token to a JSON string for embedding in the
58
- * rendered HTML (e.g. a `&lt;script>` payload the client
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 `&lt;` is escaped to `&lt;` so the payload is safe to inline inside a
66
- * `&lt;script>` tag without a stray `&lt;/script>` (or `&lt;!--`) prematurely closing
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 `&amp;`
69
- * characters escaped); embed the output in a raw-text script element, not a
70
- * data attribute.
71
- */
77
+ * Serialize a {@link Preloaded} token to a JSON string for embedding in the
78
+ * rendered HTML (e.g. a `<script>` payload the client
79
+ * reads on hydration).
80
+ *
81
+ * The payload is **wire-encoded** first, exactly as the RPC transport encodes
82
+ * its own bodies ({@link file://../service.ts}). `preloadQuery` captures
83
+ * `await client.query(...)`, whose RPC path ends at `decodeWire(body.result)` —
84
+ * so a `v.bigint()` column arrives here as a real `bigint` (which
85
+ * `JSON.stringify` **throws** on) and a `v.bytes()` column as a real
86
+ * `ArrayBuffer` (which `JSON.stringify` silently degrades to an index-keyed
87
+ * object). The query `args` are user-supplied and carry the same kinds.
88
+ * `encodeWire` is identity for JSON-safe data, so a pure-JSON snapshot
89
+ * serializes byte-for-byte as it did before.
90
+ *
91
+ * The `<` is escaped to `<` so the payload is safe to inline inside a
92
+ * `<script>` tag without a stray `<\/script>` (or `<!--`) prematurely closing
93
+ * it — the standard XSS-safe script-embedding precaution. This escaping is NOT
94
+ * sufficient for an HTML *attribute* sink (which also needs the quote and `&`
95
+ * characters escaped); embed the output in a raw-text script element, not a
96
+ * data attribute.
97
+ */
72
98
  declare const serializePreloaded: <T>(preloaded: Preloaded<T>) => string;
73
99
  /**
74
- * Inverse of {@link serializePreloaded}: parse a serialized token back into a
75
- * {@link Preloaded} value on the client. The `&lt;` escape from serialization
76
- * is transparent to `JSON.parse`, so no un-escaping step is needed.
77
- */
100
+ * Inverse of {@link serializePreloaded}: parse a serialized token back into a
101
+ * {@link Preloaded} value on the client, running the parsed payload back
102
+ * through {@link parseWire} so `bigint` / `ArrayBuffer` / typed-array leaves
103
+ * are restored rather than left in their tagged form. The `<` escape from
104
+ * serialization is transparent to `JSON.parse`, so no un-escaping step is
105
+ * needed.
106
+ */
78
107
  declare const deserializePreloaded: <T = unknown>(serialized: string) => Preloaded<T>;
79
108
  /** Options accepted by {@link createServerClient}. */
80
109
  interface ServerClientOptions {
81
110
  /**
82
- * `fetch` implementation used for HTTP RPC. Defaults to the ambient global
83
- * `fetch` (present in Node 18+, Workers, and meta-framework SSR runtimes).
84
- * Pass one explicitly to forward cookies/headers or to use an instrumented
85
- * fetch.
86
- */
111
+ * `fetch` implementation used for HTTP RPC. Defaults to the ambient global
112
+ * `fetch` (present in Node 18+, Workers, and meta-framework SSR runtimes).
113
+ * Pass one explicitly to forward cookies/headers or to use an instrumented
114
+ * fetch.
115
+ */
87
116
  fetch?: typeof fetch;
88
117
  /**
89
- * Bearer token sent as `Authorization: Bearer &lt;token>` on every RPC. In an
90
- * SSR loader you typically read this from the request (e.g. the session
91
- * resolved by `getServerSession`) and pass it here so the server-side
92
- * load runs as the signed-in user — and so the client subscription that
93
- * resumes after hydration carries the same identity.
94
- */
118
+ * Bearer token sent as `Authorization: Bearer <token>` on every RPC. In an
119
+ * SSR loader you typically read this from the request (e.g. the session
120
+ * resolved by `getServerSession`) and pass it here so the server-side
121
+ * load runs as the signed-in user — and so the client subscription that
122
+ * resumes after hydration carries the same identity.
123
+ */
95
124
  token?: string;
96
125
  /** Base URL of the deployed Lunora worker, e.g. `https://app.example.workers.dev`. */
97
126
  url: string;
98
127
  }
99
128
  /**
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
- */
129
+ * Build a request-scoped {@link LunoraClient} for use inside an SSR loader. SSR
130
+ * data loading only ever calls `.query()` (HTTP RPC over `fetch`); a
131
+ * `LunoraClient` opens a socket lazily on `.subscribe()`/`.stream()` and those
132
+ * are never called server-side, so no live connection is established even if the
133
+ * server runtime happens to expose a global `WebSocket`.
134
+ *
135
+ * Create one per request rather than sharing a module-level instance: the bearer
136
+ * token (and any forwarded cookies in `fetch`) are per-user, and a shared client
137
+ * would leak one request's identity into another.
138
+ *
139
+ * This is the framework-neutral home of the helper that previously lived only in
140
+ * `@lunora/react/server`; the React server module re-exports the same surface so
141
+ * existing imports keep working.
142
+ */
114
143
  declare const createServerClient: (options: ServerClientOptions) => LunoraClient;
115
144
  export { type AuthLike, type HeadersSource, type Preloaded, type ServerClientOptions, type ServerSession, createServerClient, deserializePreloaded, getServerSession, serializePreloaded };
@@ -1,27 +1,47 @@
1
- import { P as Preloaded, L as LunoraClient } from "../packem_shared/lunora-client.d-DGvyuJ_p.js";
2
- export type { A as ArgsOf, F as FunctionReference, R as ReturnOf } from "../packem_shared/lunora-client.d-DGvyuJ_p.js";
3
- export { p as preloadQuery, a as preloadedQueryResult } from "../packem_shared/preload.d-BoDmFqSG.js";
4
- import '@lunora/runtime';
1
+ import { P as Preloaded, L as LunoraClient } from "../packem_shared/lunora-client.d-TchceUzJ.js";
2
+ export type { A as ArgsOf, F as FunctionReference, R as ReturnOf } from "../packem_shared/function-reference.d-Br_hsKje.js";
3
+ export {
5
4
  /**
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
- */
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-BKdXfr3n.js";
24
+ import '@lunora/errors';
25
+ /**
26
+ * Structural shape of a better-auth `getSession` call's resolved value.
27
+ *
28
+ * better-auth's `auth.api.getSession({ headers })` returns `{ user, session }`
29
+ * when a valid session cookie is present, or `null` otherwise. We keep `user`
30
+ * and `session` as open records so `@lunora/client/ssr` carries no hard dependency on
31
+ * better-auth's concrete `User`/`Session` types — the adapter passing the real
32
+ * `auth` instance keeps full inference, while this package stays decoupled.
33
+ */
14
34
  interface ServerSession<User extends Record<string, unknown> = Record<string, unknown>, Session extends Record<string, unknown> = Record<string, unknown>> {
15
35
  readonly session: Session;
16
36
  readonly user: User;
17
37
  }
18
38
  /**
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
- */
39
+ * Structural subset of a better-auth instance: just the one endpoint
40
+ * `getServerSession` needs. Typing it this way (rather than importing
41
+ * `@lunora/auth`'s `LunoraAuth`) means `@lunora/client/ssr` does not depend on
42
+ * better-auth internals — any object exposing `api.getSession` works, including
43
+ * a test stub. The concrete return type is inferred from the passed instance.
44
+ */
25
45
  interface AuthLike<Result = ServerSession | null> {
26
46
  readonly api: {
27
47
  getSession: (input: {
@@ -30,86 +50,95 @@ interface AuthLike<Result = ServerSession | null> {
30
50
  };
31
51
  }
32
52
  /**
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
- */
53
+ * Anything `getServerSession` can read request headers from: a `Request`, a
54
+ * `Headers` object, or a plain object exposing `headers`. SSR loaders across
55
+ * meta-frameworks hand back slightly different request objects, so accept the
56
+ * common shapes rather than forcing the caller to unwrap.
57
+ */
38
58
  type HeadersSource = Headers | Request | {
39
59
  readonly headers: Headers;
40
60
  };
41
61
  /**
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
- */
62
+ * Resolve the signed-in session from a request inside an SSR loader.
63
+ *
64
+ * Wraps `auth.api.getSession({ headers })` — the helper every meta-framework
65
+ * app otherwise hand-rolls — so a loader can read identity off the inbound
66
+ * cookies in one call. Returns `{ user, session }` when a valid session cookie
67
+ * is present, or `null` for anonymous requests.
68
+ *
69
+ * The `auth` parameter is structurally typed ({@link AuthLike}), so this
70
+ * package does not depend on better-auth internals; pass a real
71
+ * `@lunora/auth` instance to keep full type inference on `user`/`session`.
72
+ * Forward the resolved session's token to `createServerClient` to run the
73
+ * server-side load (and the later WS subscription) as the same identity.
74
+ */
55
75
  declare const getServerSession: <Result>(request: HeadersSource, auth: AuthLike<Result>) => Promise<NonNullable<Result> | null>;
56
76
  /**
57
- * Serialize a {@link Preloaded} token to a JSON string for embedding in the
58
- * rendered HTML (e.g. a `&lt;script>` payload the client
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 `&lt;` is escaped to `&lt;` so the payload is safe to inline inside a
66
- * `&lt;script>` tag without a stray `&lt;/script>` (or `&lt;!--`) prematurely closing
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 `&amp;`
69
- * characters escaped); embed the output in a raw-text script element, not a
70
- * data attribute.
71
- */
77
+ * Serialize a {@link Preloaded} token to a JSON string for embedding in the
78
+ * rendered HTML (e.g. a `<script>` payload the client
79
+ * reads on hydration).
80
+ *
81
+ * The payload is **wire-encoded** first, exactly as the RPC transport encodes
82
+ * its own bodies ({@link file://../service.ts}). `preloadQuery` captures
83
+ * `await client.query(...)`, whose RPC path ends at `decodeWire(body.result)` —
84
+ * so a `v.bigint()` column arrives here as a real `bigint` (which
85
+ * `JSON.stringify` **throws** on) and a `v.bytes()` column as a real
86
+ * `ArrayBuffer` (which `JSON.stringify` silently degrades to an index-keyed
87
+ * object). The query `args` are user-supplied and carry the same kinds.
88
+ * `encodeWire` is identity for JSON-safe data, so a pure-JSON snapshot
89
+ * serializes byte-for-byte as it did before.
90
+ *
91
+ * The `<` is escaped to `<` so the payload is safe to inline inside a
92
+ * `<script>` tag without a stray `<\/script>` (or `<!--`) prematurely closing
93
+ * it — the standard XSS-safe script-embedding precaution. This escaping is NOT
94
+ * sufficient for an HTML *attribute* sink (which also needs the quote and `&`
95
+ * characters escaped); embed the output in a raw-text script element, not a
96
+ * data attribute.
97
+ */
72
98
  declare const serializePreloaded: <T>(preloaded: Preloaded<T>) => string;
73
99
  /**
74
- * Inverse of {@link serializePreloaded}: parse a serialized token back into a
75
- * {@link Preloaded} value on the client. The `&lt;` escape from serialization
76
- * is transparent to `JSON.parse`, so no un-escaping step is needed.
77
- */
100
+ * Inverse of {@link serializePreloaded}: parse a serialized token back into a
101
+ * {@link Preloaded} value on the client, running the parsed payload back
102
+ * through {@link parseWire} so `bigint` / `ArrayBuffer` / typed-array leaves
103
+ * are restored rather than left in their tagged form. The `<` escape from
104
+ * serialization is transparent to `JSON.parse`, so no un-escaping step is
105
+ * needed.
106
+ */
78
107
  declare const deserializePreloaded: <T = unknown>(serialized: string) => Preloaded<T>;
79
108
  /** Options accepted by {@link createServerClient}. */
80
109
  interface ServerClientOptions {
81
110
  /**
82
- * `fetch` implementation used for HTTP RPC. Defaults to the ambient global
83
- * `fetch` (present in Node 18+, Workers, and meta-framework SSR runtimes).
84
- * Pass one explicitly to forward cookies/headers or to use an instrumented
85
- * fetch.
86
- */
111
+ * `fetch` implementation used for HTTP RPC. Defaults to the ambient global
112
+ * `fetch` (present in Node 18+, Workers, and meta-framework SSR runtimes).
113
+ * Pass one explicitly to forward cookies/headers or to use an instrumented
114
+ * fetch.
115
+ */
87
116
  fetch?: typeof fetch;
88
117
  /**
89
- * Bearer token sent as `Authorization: Bearer &lt;token>` on every RPC. In an
90
- * SSR loader you typically read this from the request (e.g. the session
91
- * resolved by `getServerSession`) and pass it here so the server-side
92
- * load runs as the signed-in user — and so the client subscription that
93
- * resumes after hydration carries the same identity.
94
- */
118
+ * Bearer token sent as `Authorization: Bearer <token>` on every RPC. In an
119
+ * SSR loader you typically read this from the request (e.g. the session
120
+ * resolved by `getServerSession`) and pass it here so the server-side
121
+ * load runs as the signed-in user — and so the client subscription that
122
+ * resumes after hydration carries the same identity.
123
+ */
95
124
  token?: string;
96
125
  /** Base URL of the deployed Lunora worker, e.g. `https://app.example.workers.dev`. */
97
126
  url: string;
98
127
  }
99
128
  /**
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
- */
129
+ * Build a request-scoped {@link LunoraClient} for use inside an SSR loader. SSR
130
+ * data loading only ever calls `.query()` (HTTP RPC over `fetch`); a
131
+ * `LunoraClient` opens a socket lazily on `.subscribe()`/`.stream()` and those
132
+ * are never called server-side, so no live connection is established even if the
133
+ * server runtime happens to expose a global `WebSocket`.
134
+ *
135
+ * Create one per request rather than sharing a module-level instance: the bearer
136
+ * token (and any forwarded cookies in `fetch`) are per-user, and a shared client
137
+ * would leak one request's identity into another.
138
+ *
139
+ * This is the framework-neutral home of the helper that previously lived only in
140
+ * `@lunora/react/server`; the React server module re-exports the same surface so
141
+ * existing imports keep working.
142
+ */
114
143
  declare const createServerClient: (options: ServerClientOptions) => LunoraClient;
115
144
  export { type AuthLike, type HeadersSource, type Preloaded, type ServerClientOptions, type ServerSession, createServerClient, deserializePreloaded, getServerSession, serializePreloaded };
@@ -1,4 +1 @@
1
- export { getServerSession } from '../packem_shared/getServerSession-8jXewqxd.mjs';
2
- export { deserializePreloaded, serializePreloaded } from '../packem_shared/deserializePreloaded-C0eJTY_W.mjs';
3
- export { createServerClient } from '../packem_shared/createServerClient-BjZc3gD8.mjs';
4
- export { preloadQuery, preloadedQueryResult } from '../packem_shared/preloadQuery-lobFkD2Z.mjs';
1
+ import{getServerSession as o}from"../packem_shared/getServerSession-BaOoo1p6.mjs";import{deserializePreloaded as l,serializePreloaded as t}from"../packem_shared/deserializePreloaded-DxozvweR.mjs";import{createServerClient as i}from"../packem_shared/createServerClient-CcH_sS6i.mjs";import{preloadQuery as s,preloadedQueryResult as f}from"../packem_shared/preloadQuery-uFy24PCR.mjs";export{i as createServerClient,l as deserializePreloaded,o as getServerSession,s as preloadQuery,f as preloadedQueryResult,t as serializePreloaded};
@@ -0,0 +1,49 @@
1
+ /**
2
+ * `@lunora/client/upload` — framework-agnostic client upload core.
3
+ *
4
+ * The admin `uploadStorageObject` path on `LunoraClient` is a one-shot PUT gated
5
+ * by an `adminToken` — right for the Studio file browser, wrong for end users.
6
+ * This module gives end-user browsers progress, pause/resume, large-file
7
+ * resumable uploads and per-part retry by re-exporting `@visulima/storage-client`
8
+ * (Lunora does not hand-roll the uploader). Point {@link createUpload} at a route
9
+ * backed by `@lunora/storage/upload`'s RLS-gated handler.
10
+ *
11
+ * Framework users should prefer the hook re-exports (`@lunora/react` `useUpload`,
12
+ * `@lunora/vue`, `@lunora/solid`, `@lunora/svelte`); this vanilla core is for
13
+ * non-framework code and for the hooks to build on.
14
+ */
15
+ import { UploadControl, HeadersResolver, UploadRestrictions, ChunkedRestAdapter, MultipartAdapter, TusAdapter } from '@visulima/storage-client';
16
+ export { type ChunkedRestAdapter, type ChunkedRestAdapterOptions, type FingerprintFunction, type HeadersResolver, LocalStorageUrlStorage, MemoryUrlStorage, type MultipartAdapter, type MultipartAdapterOptions, type OnBeforeRequest, type RequestOptions, RestrictionError, type TusAdapter, type TusAdapterOptions, type UploadControl, UploadError, type UploadMethod, type UploadRestrictions, type UploadResult, type Uploader, type UrlStorage, createChunkedRestAdapter, createMultipartAdapter, createTusAdapter, putFile, validateFile, validateFiles } from '@visulima/storage-client';
17
+ /** Resumable upload wire protocols {@link createUpload} can drive. */
18
+ type UploadProtocol = "chunked-rest" | "multipart" | "tus";
19
+ /** The adapter shape {@link createUpload} returns — a `.upload(file)` driver plus lifecycle callbacks. */
20
+ type UploadAdapter = ChunkedRestAdapter | MultipartAdapter | TusAdapter;
21
+ /** Options for {@link createUpload}. */
22
+ interface CreateUploadOptions {
23
+ /** Chunk size in bytes (TUS / chunked-REST only). */
24
+ chunkSize?: number;
25
+ /** A shared {@link UploadControl} for pause/resume/cancel (TUS / chunked-REST). */
26
+ control?: UploadControl;
27
+ /** The upload endpoint — a route backed by `@lunora/storage/upload`'s handler. */
28
+ endpoint: string;
29
+ /** Static or dynamically-resolved request headers (e.g. an `Authorization` token). */
30
+ headers?: HeadersResolver;
31
+ /** Maximum retry attempts (TUS / chunked-REST, when `retry` is on). */
32
+ maxRetries?: number;
33
+ /** Extra metadata sent with the upload. */
34
+ metadata?: Record<string, string>;
35
+ /** Which protocol to speak. Default `"tus"` (resumable, pause/resume-capable). */
36
+ protocol?: UploadProtocol;
37
+ /** Client-side size/type restrictions, validated before any network request. */
38
+ restrictions?: UploadRestrictions;
39
+ /** Enable automatic retry on failure (TUS / chunked-REST). */
40
+ retry?: boolean;
41
+ }
42
+ /**
43
+ * Create a protocol-appropriate upload adapter against an RLS-gated endpoint.
44
+ * Defaults to TUS — the resumable path that survives pause/resume and a dropped
45
+ * connection. Call `.upload(file)` to start; use the shared {@link UploadControl}
46
+ * (or the adapter's `pause`/`resume`/`abort`) to steer it.
47
+ */
48
+ declare const createUpload: (options: CreateUploadOptions) => UploadAdapter;
49
+ export { CreateUploadOptions, UploadAdapter, UploadProtocol, createUpload };
@@ -0,0 +1,49 @@
1
+ /**
2
+ * `@lunora/client/upload` — framework-agnostic client upload core.
3
+ *
4
+ * The admin `uploadStorageObject` path on `LunoraClient` is a one-shot PUT gated
5
+ * by an `adminToken` — right for the Studio file browser, wrong for end users.
6
+ * This module gives end-user browsers progress, pause/resume, large-file
7
+ * resumable uploads and per-part retry by re-exporting `@visulima/storage-client`
8
+ * (Lunora does not hand-roll the uploader). Point {@link createUpload} at a route
9
+ * backed by `@lunora/storage/upload`'s RLS-gated handler.
10
+ *
11
+ * Framework users should prefer the hook re-exports (`@lunora/react` `useUpload`,
12
+ * `@lunora/vue`, `@lunora/solid`, `@lunora/svelte`); this vanilla core is for
13
+ * non-framework code and for the hooks to build on.
14
+ */
15
+ import { UploadControl, HeadersResolver, UploadRestrictions, ChunkedRestAdapter, MultipartAdapter, TusAdapter } from '@visulima/storage-client';
16
+ export { type ChunkedRestAdapter, type ChunkedRestAdapterOptions, type FingerprintFunction, type HeadersResolver, LocalStorageUrlStorage, MemoryUrlStorage, type MultipartAdapter, type MultipartAdapterOptions, type OnBeforeRequest, type RequestOptions, RestrictionError, type TusAdapter, type TusAdapterOptions, type UploadControl, UploadError, type UploadMethod, type UploadRestrictions, type UploadResult, type Uploader, type UrlStorage, createChunkedRestAdapter, createMultipartAdapter, createTusAdapter, putFile, validateFile, validateFiles } from '@visulima/storage-client';
17
+ /** Resumable upload wire protocols {@link createUpload} can drive. */
18
+ type UploadProtocol = "chunked-rest" | "multipart" | "tus";
19
+ /** The adapter shape {@link createUpload} returns — a `.upload(file)` driver plus lifecycle callbacks. */
20
+ type UploadAdapter = ChunkedRestAdapter | MultipartAdapter | TusAdapter;
21
+ /** Options for {@link createUpload}. */
22
+ interface CreateUploadOptions {
23
+ /** Chunk size in bytes (TUS / chunked-REST only). */
24
+ chunkSize?: number;
25
+ /** A shared {@link UploadControl} for pause/resume/cancel (TUS / chunked-REST). */
26
+ control?: UploadControl;
27
+ /** The upload endpoint — a route backed by `@lunora/storage/upload`'s handler. */
28
+ endpoint: string;
29
+ /** Static or dynamically-resolved request headers (e.g. an `Authorization` token). */
30
+ headers?: HeadersResolver;
31
+ /** Maximum retry attempts (TUS / chunked-REST, when `retry` is on). */
32
+ maxRetries?: number;
33
+ /** Extra metadata sent with the upload. */
34
+ metadata?: Record<string, string>;
35
+ /** Which protocol to speak. Default `"tus"` (resumable, pause/resume-capable). */
36
+ protocol?: UploadProtocol;
37
+ /** Client-side size/type restrictions, validated before any network request. */
38
+ restrictions?: UploadRestrictions;
39
+ /** Enable automatic retry on failure (TUS / chunked-REST). */
40
+ retry?: boolean;
41
+ }
42
+ /**
43
+ * Create a protocol-appropriate upload adapter against an RLS-gated endpoint.
44
+ * Defaults to TUS — the resumable path that survives pause/resume and a dropped
45
+ * connection. Call `.upload(file)` to start; use the shared {@link UploadControl}
46
+ * (or the adapter's `pause`/`resume`/`abort`) to steer it.
47
+ */
48
+ declare const createUpload: (options: CreateUploadOptions) => UploadAdapter;
49
+ export { CreateUploadOptions, UploadAdapter, UploadProtocol, createUpload };
@@ -0,0 +1 @@
1
+ import{createMultipartAdapter as d,createChunkedRestAdapter as u,createTusAdapter as m}from"@visulima/storage-client";import{LocalStorageUrlStorage as S,MemoryUrlStorage as f,RestrictionError as g,UploadControl as x,UploadError as C,createChunkedRestAdapter as F,createMultipartAdapter as M,createTusAdapter as O,putFile as v,validateFile as y,validateFiles as E}from"@visulima/storage-client";const U=t=>{const r=t.protocol??"tus",{chunkSize:s,control:n,endpoint:e,headers:a,maxRetries:o,metadata:p,restrictions:i,retry:l}=t;if(r==="multipart")return d({endpoint:e,headers:a,maxRetries:o,metadata:p,restrictions:i,retry:l});const c={chunkSize:s,control:n,endpoint:e,headers:a,maxRetries:o,metadata:p,restrictions:i,retry:l};return r==="chunked-rest"?u(c):m(c)};export{S as LocalStorageUrlStorage,f as MemoryUrlStorage,g as RestrictionError,x as UploadControl,C as UploadError,F as createChunkedRestAdapter,M as createMultipartAdapter,O as createTusAdapter,U as createUpload,v as putFile,y as validateFile,E as validateFiles};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/client",
3
- "version": "1.0.0-alpha.3",
3
+ "version": "1.0.0-alpha.300",
4
4
  "description": "Lunora browser SDK: WebSocket transport, optimistic updates, and an offline mutation queue",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -14,7 +14,7 @@
14
14
  ],
15
15
  "homepage": "https://lunora.sh",
16
16
  "bugs": "https://github.com/anolilab/lunora/issues",
17
- "license": "FSL-1.1-Apache-2.0",
17
+ "license": "Apache-2.0",
18
18
  "author": {
19
19
  "name": "Daniel Bannert",
20
20
  "email": "d.bannert@anolilab.de"
@@ -56,11 +56,31 @@
56
56
  "types": "./dist/ssr/index.d.ts",
57
57
  "import": "./dist/ssr/index.mjs"
58
58
  },
59
+ "./upload": {
60
+ "types": "./dist/upload.d.ts",
61
+ "import": "./dist/upload.mjs"
62
+ },
63
+ "./service": {
64
+ "types": "./dist/service.d.ts",
65
+ "import": "./dist/service.mjs"
66
+ },
67
+ "./admin": {
68
+ "types": "./dist/admin/index.d.ts",
69
+ "import": "./dist/admin/index.mjs"
70
+ },
59
71
  "./package.json": "./package.json"
60
72
  },
61
73
  "publishConfig": {
62
74
  "access": "public"
63
75
  },
76
+ "dependencies": {
77
+ "@lunora/errors": ">=1.0.0-alpha.51 <2.0.0-0",
78
+ "@lunora/wire": "1.0.0-alpha.6",
79
+ "@visulima/storage-client": "1.0.9"
80
+ },
81
+ "peerDependencies": {
82
+ "@lunora/runtime": ">=1.0.0-alpha.76 <2.0.0-0"
83
+ },
64
84
  "engines": {
65
85
  "node": "^22.15.0 || >=24.11.0"
66
86
  }
@@ -1,4 +0,0 @@
1
- const CONFLICT_ERROR_CODE = "CONFLICT";
2
- const isConflictError = (error) => error instanceof Error && error.code === CONFLICT_ERROR_CODE;
3
-
4
- export { CONFLICT_ERROR_CODE, isConflictError };