@lunora/client 1.0.0-alpha.28 → 1.0.0-alpha.281
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/README.md +19 -4
- package/dist/admin/index.d.mts +647 -0
- package/dist/admin/index.d.ts +647 -0
- package/dist/admin/index.mjs +1 -0
- package/dist/auth/index.d.mts +138 -5
- package/dist/auth/index.d.ts +138 -5
- package/dist/auth/index.mjs +1 -60
- package/dist/index.d.mts +756 -186
- package/dist/index.d.ts +756 -186
- package/dist/index.mjs +1 -21
- package/dist/packem_shared/ADMIN_AUTH_DEFAULT_PAGE_SIZE-V9c3bHU1.mjs +1 -0
- package/dist/packem_shared/CONFLICT_ERROR_CODE-B7qNZMMk.mjs +1 -0
- package/dist/packem_shared/DEFAULT_MAX_BUFFER-Bd-_iyiV.mjs +1 -0
- package/dist/packem_shared/LunoraAdminClient-1KWk7JkZ.mjs +1 -0
- package/dist/packem_shared/LunoraClient-DKPUPbuv.mjs +1 -0
- package/dist/packem_shared/OfflineQueue-Ba2qgZK1.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-BKgQtuh9.mjs +1 -0
- package/dist/packem_shared/TabCoordinator-IUCwjnqX.mjs +1 -0
- package/dist/packem_shared/applyDelta-CaudNj2C.mjs +1 -0
- package/dist/packem_shared/base64-849R7V-V.mjs +1 -0
- package/dist/packem_shared/client-tuning-C10B2KCO.mjs +1 -0
- package/dist/packem_shared/client-urls-BHLUjjcG.mjs +1 -0
- package/dist/packem_shared/connectLiveStream-BdjsWP1-.mjs +1 -0
- package/dist/packem_shared/createAsyncStoragePersistence-BgfdvLwe.mjs +1 -0
- package/dist/packem_shared/createAsyncStorageQueryCache-6Y94ocbQ.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-C-IzNVbg.mjs +1 -0
- package/dist/packem_shared/createInMemoryQueryCache-DR6AorA2.mjs +1 -0
- package/dist/packem_shared/createLocalStore-D38o4O8Z.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/createServerClient-97d5uFpA.mjs +1 -0
- package/dist/packem_shared/createSnapshotPrecondition-BXP1NPBW.mjs +1 -0
- package/dist/packem_shared/delta-merge-C6OqMEPH.mjs +1 -0
- package/dist/packem_shared/deserializePreloaded-DxozvweR.mjs +1 -0
- package/dist/packem_shared/frame-hint-D-NK691z.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-DN3D9WqW.mjs +7 -0
- package/dist/packem_shared/idb-utility-BS7xvou1.mjs +1 -0
- package/dist/packem_shared/live-stream-DBKgZlnb.mjs +10 -0
- package/dist/packem_shared/liveTopicSubscription-DQtKMFKw.mjs +1 -0
- package/dist/packem_shared/lunora-client-CNUU3FU7.mjs +1 -0
- package/dist/packem_shared/lunora-client.d-C8zXKzbE.d.mts +4966 -0
- package/dist/packem_shared/lunora-client.d-CAIGiEHg.d.ts +4966 -0
- package/dist/packem_shared/lunoraQueryKey-CucWmxnx.mjs +1 -0
- package/dist/packem_shared/offline-queue-BEqCPDmw.mjs +1 -0
- package/dist/packem_shared/optimistic-layers-D-7D3yeJ.mjs +1 -0
- package/dist/packem_shared/{preload.d-Cqb4Kh2I.d.ts → preload.d-CLx5oM3f.d.mts} +2 -1
- package/dist/packem_shared/{preload.d-CLwoXl3R.d.mts → preload.d-DTHQlBVJ.d.ts} +2 -1
- package/dist/packem_shared/preloadQuery-uFy24PCR.mjs +1 -0
- package/dist/packem_shared/setAuthTokenProvider-DhBppDiZ.mjs +1 -0
- package/dist/packem_shared/single-blob-store-DeaYPBSS.mjs +1 -0
- package/dist/packem_shared/snapshot-precondition-BEtcSbWr.mjs +1 -0
- package/dist/packem_shared/stream-idle-C7CsIT_m.mjs +1 -0
- package/dist/packem_shared/wire-errors-BDckSTKZ.mjs +1 -0
- package/dist/pagination/index.mjs +1 -61
- package/dist/query/index.d.mts +143 -4
- package/dist/query/index.d.ts +143 -4
- 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 +45 -16
- package/dist/ssr/index.d.ts +45 -16
- package/dist/ssr/index.mjs +1 -4
- package/dist/upload.d.mts +14 -0
- package/dist/upload.d.ts +14 -0
- package/dist/upload.mjs +1 -24
- package/package.json +15 -3
- package/dist/packem_shared/CONFLICT_ERROR_CODE-B8gQ8tyU.mjs +0 -33
- package/dist/packem_shared/ClientServiceWorker-C3PAFwy0.mjs +0 -100
- package/dist/packem_shared/DEFAULT_MAX_BUFFER-7hFnzNk9.mjs +0 -110
- package/dist/packem_shared/LunoraClient-DKATLGHY.mjs +0 -3631
- package/dist/packem_shared/OfflineQueue-BgarnAub.mjs +0 -1
- package/dist/packem_shared/SKIP-vItZChkw.mjs +0 -50
- package/dist/packem_shared/SubscriptionRegistry-CxS_Inha.mjs +0 -31
- package/dist/packem_shared/TabCoordinator-D_5oNTTt.mjs +0 -258
- package/dist/packem_shared/applyDelta-CRKZ1PBt.mjs +0 -81
- package/dist/packem_shared/createAsyncStoragePersistence-1Z5BZ8RC.mjs +0 -45
- package/dist/packem_shared/createClientQuery-dJZg1ohm.mjs +0 -80
- package/dist/packem_shared/createInMemoryBookmarkStorage-BoN7a7TH.mjs +0 -11
- package/dist/packem_shared/createInMemoryPersistence-DZ2VHWgm.mjs +0 -79
- package/dist/packem_shared/createInMemoryQueryCache-DiaGZkA2.mjs +0 -112
- package/dist/packem_shared/createLocalStore-BtqUmOQA.mjs +0 -2
- 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/createReply-lI4tVS2w.mjs +0 -36
- package/dist/packem_shared/createServerClient-Bp2r9tcB.mjs +0 -11
- package/dist/packem_shared/createSnapshotPrecondition-CxQ1T4ZP.mjs +0 -18
- package/dist/packem_shared/deserializePreloaded-C0eJTY_W.mjs +0 -4
- package/dist/packem_shared/getServerSession-8jXewqxd.mjs +0 -13
- package/dist/packem_shared/httpStream-DIdL8NEw.mjs +0 -168
- package/dist/packem_shared/idb-utility-DrSVX43Q.mjs +0 -48
- package/dist/packem_shared/local-store-DIq-UWfD.mjs +0 -106
- package/dist/packem_shared/lunora-client.d-B1iZb2Ph.d.mts +0 -2845
- package/dist/packem_shared/lunora-client.d-B1iZb2Ph.d.ts +0 -2845
- package/dist/packem_shared/offline-queue-N-1JvYb4.mjs +0 -211
- package/dist/packem_shared/preloadQuery-lobFkD2Z.mjs +0 -13
- package/dist/packem_shared/wire-key-Djie6aaR.mjs +0 -266
package/dist/ssr/index.d.mts
CHANGED
|
@@ -1,7 +1,27 @@
|
|
|
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 {
|
|
4
|
-
|
|
1
|
+
import { P as Preloaded, L as LunoraClient } from "../packem_shared/lunora-client.d-C8zXKzbE.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-CLx5oM3f.mjs";
|
|
24
|
+
import '@lunora/errors';
|
|
5
25
|
/**
|
|
6
26
|
* Structural shape of a better-auth `getSession` call's resolved value.
|
|
7
27
|
*
|
|
@@ -55,25 +75,34 @@ type HeadersSource = Headers | Request | {
|
|
|
55
75
|
declare const getServerSession: <Result>(request: HeadersSource, auth: AuthLike<Result>) => Promise<NonNullable<Result> | null>;
|
|
56
76
|
/**
|
|
57
77
|
* Serialize a {@link Preloaded} token to a JSON string for embedding in the
|
|
58
|
-
* rendered HTML (e.g. a
|
|
59
|
-
* reads on hydration).
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
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.
|
|
64
90
|
*
|
|
65
|
-
* The
|
|
66
|
-
*
|
|
91
|
+
* The `<` is escaped to `<` so the payload is safe to inline inside a
|
|
92
|
+
* `<script>` tag without a stray `<\/script>` (or `<!--`) prematurely closing
|
|
67
93
|
* 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
|
|
94
|
+
* sufficient for an HTML *attribute* sink (which also needs the quote and `&`
|
|
69
95
|
* characters escaped); embed the output in a raw-text script element, not a
|
|
70
96
|
* data attribute.
|
|
71
97
|
*/
|
|
72
98
|
declare const serializePreloaded: <T>(preloaded: Preloaded<T>) => string;
|
|
73
99
|
/**
|
|
74
100
|
* Inverse of {@link serializePreloaded}: parse a serialized token back into a
|
|
75
|
-
* {@link Preloaded} value on the client
|
|
76
|
-
*
|
|
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.
|
|
77
106
|
*/
|
|
78
107
|
declare const deserializePreloaded: <T = unknown>(serialized: string) => Preloaded<T>;
|
|
79
108
|
/** Options accepted by {@link createServerClient}. */
|
|
@@ -86,7 +115,7 @@ interface ServerClientOptions {
|
|
|
86
115
|
*/
|
|
87
116
|
fetch?: typeof fetch;
|
|
88
117
|
/**
|
|
89
|
-
* Bearer token sent as `Authorization: Bearer
|
|
118
|
+
* Bearer token sent as `Authorization: Bearer <token>` on every RPC. In an
|
|
90
119
|
* SSR loader you typically read this from the request (e.g. the session
|
|
91
120
|
* resolved by `getServerSession`) and pass it here so the server-side
|
|
92
121
|
* load runs as the signed-in user — and so the client subscription that
|
package/dist/ssr/index.d.ts
CHANGED
|
@@ -1,7 +1,27 @@
|
|
|
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 {
|
|
4
|
-
|
|
1
|
+
import { P as Preloaded, L as LunoraClient } from "../packem_shared/lunora-client.d-CAIGiEHg.js";
|
|
2
|
+
export type { A as ArgsOf, F as FunctionReference, R as ReturnOf } from "../packem_shared/function-reference.d-Br_hsKje.js";
|
|
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-DTHQlBVJ.js";
|
|
24
|
+
import '@lunora/errors';
|
|
5
25
|
/**
|
|
6
26
|
* Structural shape of a better-auth `getSession` call's resolved value.
|
|
7
27
|
*
|
|
@@ -55,25 +75,34 @@ type HeadersSource = Headers | Request | {
|
|
|
55
75
|
declare const getServerSession: <Result>(request: HeadersSource, auth: AuthLike<Result>) => Promise<NonNullable<Result> | null>;
|
|
56
76
|
/**
|
|
57
77
|
* Serialize a {@link Preloaded} token to a JSON string for embedding in the
|
|
58
|
-
* rendered HTML (e.g. a
|
|
59
|
-
* reads on hydration).
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
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.
|
|
64
90
|
*
|
|
65
|
-
* The
|
|
66
|
-
*
|
|
91
|
+
* The `<` is escaped to `<` so the payload is safe to inline inside a
|
|
92
|
+
* `<script>` tag without a stray `<\/script>` (or `<!--`) prematurely closing
|
|
67
93
|
* 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
|
|
94
|
+
* sufficient for an HTML *attribute* sink (which also needs the quote and `&`
|
|
69
95
|
* characters escaped); embed the output in a raw-text script element, not a
|
|
70
96
|
* data attribute.
|
|
71
97
|
*/
|
|
72
98
|
declare const serializePreloaded: <T>(preloaded: Preloaded<T>) => string;
|
|
73
99
|
/**
|
|
74
100
|
* Inverse of {@link serializePreloaded}: parse a serialized token back into a
|
|
75
|
-
* {@link Preloaded} value on the client
|
|
76
|
-
*
|
|
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.
|
|
77
106
|
*/
|
|
78
107
|
declare const deserializePreloaded: <T = unknown>(serialized: string) => Preloaded<T>;
|
|
79
108
|
/** Options accepted by {@link createServerClient}. */
|
|
@@ -86,7 +115,7 @@ interface ServerClientOptions {
|
|
|
86
115
|
*/
|
|
87
116
|
fetch?: typeof fetch;
|
|
88
117
|
/**
|
|
89
|
-
* Bearer token sent as `Authorization: Bearer
|
|
118
|
+
* Bearer token sent as `Authorization: Bearer <token>` on every RPC. In an
|
|
90
119
|
* SSR loader you typically read this from the request (e.g. the session
|
|
91
120
|
* resolved by `getServerSession`) and pass it here so the server-side
|
|
92
121
|
* load runs as the signed-in user — and so the client subscription that
|
package/dist/ssr/index.mjs
CHANGED
|
@@ -1,4 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { deserializePreloaded, serializePreloaded } from '../packem_shared/deserializePreloaded-C0eJTY_W.mjs';
|
|
3
|
-
export { createServerClient } from '../packem_shared/createServerClient-Bp2r9tcB.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-97d5uFpA.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};
|
package/dist/upload.d.mts
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
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
|
+
*/
|
|
1
15
|
import { UploadControl, HeadersResolver, UploadRestrictions, ChunkedRestAdapter, MultipartAdapter, TusAdapter } from '@visulima/storage-client';
|
|
2
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';
|
|
3
17
|
/** Resumable upload wire protocols {@link createUpload} can drive. */
|
package/dist/upload.d.ts
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
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
|
+
*/
|
|
1
15
|
import { UploadControl, HeadersResolver, UploadRestrictions, ChunkedRestAdapter, MultipartAdapter, TusAdapter } from '@visulima/storage-client';
|
|
2
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';
|
|
3
17
|
/** Resumable upload wire protocols {@link createUpload} can drive. */
|
package/dist/upload.mjs
CHANGED
|
@@ -1,24 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { LocalStorageUrlStorage, MemoryUrlStorage, RestrictionError, UploadControl, UploadError, createChunkedRestAdapter, createMultipartAdapter, createTusAdapter, putFile, validateFile, validateFiles } from '@visulima/storage-client';
|
|
3
|
-
|
|
4
|
-
const createUpload = (options) => {
|
|
5
|
-
const protocol = options.protocol ?? "tus";
|
|
6
|
-
const { chunkSize, control, endpoint, headers, maxRetries, metadata, restrictions, retry } = options;
|
|
7
|
-
if (protocol === "multipart") {
|
|
8
|
-
const multipartOptions = { endpoint, headers, maxRetries, metadata, restrictions, retry };
|
|
9
|
-
return createMultipartAdapter(multipartOptions);
|
|
10
|
-
}
|
|
11
|
-
const resumableOptions = {
|
|
12
|
-
chunkSize,
|
|
13
|
-
control,
|
|
14
|
-
endpoint,
|
|
15
|
-
headers,
|
|
16
|
-
maxRetries,
|
|
17
|
-
metadata,
|
|
18
|
-
restrictions,
|
|
19
|
-
retry
|
|
20
|
-
};
|
|
21
|
-
return protocol === "chunked-rest" ? createChunkedRestAdapter(resumableOptions) : createTusAdapter(resumableOptions);
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export { createUpload };
|
|
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
|
+
"version": "1.0.0-alpha.281",
|
|
4
4
|
"description": "Lunora browser SDK: WebSocket transport, optimistic updates, and an offline mutation queue",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -60,14 +60,26 @@
|
|
|
60
60
|
"types": "./dist/upload.d.ts",
|
|
61
61
|
"import": "./dist/upload.mjs"
|
|
62
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
|
+
},
|
|
63
71
|
"./package.json": "./package.json"
|
|
64
72
|
},
|
|
65
73
|
"publishConfig": {
|
|
66
74
|
"access": "public"
|
|
67
75
|
},
|
|
68
76
|
"dependencies": {
|
|
69
|
-
"@lunora/errors": "1.0.0-alpha.
|
|
70
|
-
"@
|
|
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"
|
|
71
83
|
},
|
|
72
84
|
"engines": {
|
|
73
85
|
"node": "^22.15.0 || >=24.11.0"
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
const LUNORA_ERROR_CODES = [
|
|
2
|
-
"BAD_REQUEST",
|
|
3
|
-
"CONFLICT",
|
|
4
|
-
"COUNT_RLS_UNSUPPORTED",
|
|
5
|
-
"FORBIDDEN",
|
|
6
|
-
"INTERNAL_SERVER_ERROR",
|
|
7
|
-
"MASK_UNSUPPORTED",
|
|
8
|
-
"NOT_FOUND",
|
|
9
|
-
"NOT_IMPLEMENTED",
|
|
10
|
-
"RELATION_PREDICATE_UNSUPPORTED",
|
|
11
|
-
"TOO_MANY_REQUESTS",
|
|
12
|
-
"UNAUTHORIZED",
|
|
13
|
-
"UNPROCESSABLE"
|
|
14
|
-
];
|
|
15
|
-
const KNOWN_ERROR_CODES = new Set(LUNORA_ERROR_CODES);
|
|
16
|
-
const CONFLICT_ERROR_CODE = "CONFLICT";
|
|
17
|
-
const isConflictError = (error) => error instanceof Error && error.code === CONFLICT_ERROR_CODE;
|
|
18
|
-
const isForbiddenError = (error) => error instanceof Error && error.code === "FORBIDDEN";
|
|
19
|
-
const isUnauthorizedError = (error) => error instanceof Error && error.code === "UNAUTHORIZED";
|
|
20
|
-
const isRateLimitedError = (error) => error instanceof Error && error.code === "TOO_MANY_REQUESTS";
|
|
21
|
-
const getErrorCode = (error) => {
|
|
22
|
-
if (!(error instanceof Error)) {
|
|
23
|
-
return void 0;
|
|
24
|
-
}
|
|
25
|
-
const { code } = error;
|
|
26
|
-
return typeof code === "string" && KNOWN_ERROR_CODES.has(code) ? code : void 0;
|
|
27
|
-
};
|
|
28
|
-
const getRetryAfterMs = (error) => {
|
|
29
|
-
const value = error?.data?.retryAfterMs;
|
|
30
|
-
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export { CONFLICT_ERROR_CODE, getErrorCode, getRetryAfterMs, isConflictError, isForbiddenError, isRateLimitedError, isUnauthorizedError };
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
class ClientServiceWorker {
|
|
2
|
-
swUrl;
|
|
3
|
-
scope;
|
|
4
|
-
#registration = void 0;
|
|
5
|
-
#status = "unregistered";
|
|
6
|
-
#onStatusChange;
|
|
7
|
-
#messageHandlers = /* @__PURE__ */ new Set();
|
|
8
|
-
constructor(options) {
|
|
9
|
-
this.swUrl = options.swUrl;
|
|
10
|
-
this.scope = options.scope ?? "/";
|
|
11
|
-
this.#onStatusChange = options.onStatusChange;
|
|
12
|
-
}
|
|
13
|
-
// ── Status ──────────────────────────────────────────────────────────
|
|
14
|
-
/** Current registration status. */
|
|
15
|
-
get status() {
|
|
16
|
-
return this.#status;
|
|
17
|
-
}
|
|
18
|
-
/** The underlying `ServiceWorkerRegistration`, if registered. */
|
|
19
|
-
get registration() {
|
|
20
|
-
return this.#registration;
|
|
21
|
-
}
|
|
22
|
-
/** Whether the SW is currently controlling this page. */
|
|
23
|
-
get active() {
|
|
24
|
-
return this.#registration?.active !== null && this.#registration?.active !== void 0;
|
|
25
|
-
}
|
|
26
|
-
// ── Registration ────────────────────────────────────────────────────
|
|
27
|
-
/**
|
|
28
|
-
* Register the service worker.
|
|
29
|
-
*
|
|
30
|
-
* Returns `false` when the browser does not support service workers.
|
|
31
|
-
*/
|
|
32
|
-
async register() {
|
|
33
|
-
if (!("serviceWorker" in navigator)) {
|
|
34
|
-
this.#setStatus("unsupported");
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
this.#setStatus("registering");
|
|
38
|
-
try {
|
|
39
|
-
this.#registration = await navigator.serviceWorker.register(this.swUrl, {
|
|
40
|
-
scope: this.scope
|
|
41
|
-
});
|
|
42
|
-
this.#setStatus("active");
|
|
43
|
-
navigator.serviceWorker.addEventListener("message", this.#onMessage);
|
|
44
|
-
} catch {
|
|
45
|
-
this.#setStatus("error");
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
return true;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Remove the active service worker registration and clear listeners.
|
|
52
|
-
*
|
|
53
|
-
* Returns `false` when no registration is currently held.
|
|
54
|
-
*/
|
|
55
|
-
async unregister() {
|
|
56
|
-
if (!this.#registration) {
|
|
57
|
-
return false;
|
|
58
|
-
}
|
|
59
|
-
navigator.serviceWorker.removeEventListener("message", this.#onMessage);
|
|
60
|
-
const ok = await this.#registration.unregister();
|
|
61
|
-
this.#registration = void 0;
|
|
62
|
-
this.#setStatus("unregistered");
|
|
63
|
-
return ok;
|
|
64
|
-
}
|
|
65
|
-
// ── Messaging ───────────────────────────────────────────────────────
|
|
66
|
-
/**
|
|
67
|
-
* Send a message to the active service worker.
|
|
68
|
-
*/
|
|
69
|
-
postMessage(message) {
|
|
70
|
-
const active = this.#registration?.active;
|
|
71
|
-
if (active) {
|
|
72
|
-
active.postMessage(message);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Register a handler for messages **from** the service worker.
|
|
77
|
-
* @returns Unsubscribe function.
|
|
78
|
-
*/
|
|
79
|
-
onMessage(handler) {
|
|
80
|
-
this.#messageHandlers.add(handler);
|
|
81
|
-
return () => {
|
|
82
|
-
this.#messageHandlers.delete(handler);
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
// ── Internals ───────────────────────────────────────────────────────
|
|
86
|
-
#setStatus(status) {
|
|
87
|
-
this.#status = status;
|
|
88
|
-
this.#onStatusChange?.(status);
|
|
89
|
-
}
|
|
90
|
-
#onMessage = (event) => {
|
|
91
|
-
for (const handler of this.#messageHandlers) {
|
|
92
|
-
try {
|
|
93
|
-
handler(event);
|
|
94
|
-
} catch {
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export { ClientServiceWorker };
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { LunoraError } from '@lunora/errors';
|
|
2
|
-
|
|
3
|
-
const DEFAULT_MAX_BUFFER = 1024;
|
|
4
|
-
const createStream = (options) => {
|
|
5
|
-
const maxBuffer = options.maxBuffer ?? DEFAULT_MAX_BUFFER;
|
|
6
|
-
const buffer = [];
|
|
7
|
-
const pending = [];
|
|
8
|
-
let done = false;
|
|
9
|
-
let failure;
|
|
10
|
-
let cancelled = false;
|
|
11
|
-
const flushOne = () => {
|
|
12
|
-
const waiter = pending.shift();
|
|
13
|
-
if (!waiter) {
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
if (failure) {
|
|
17
|
-
waiter.reject(failure);
|
|
18
|
-
return true;
|
|
19
|
-
}
|
|
20
|
-
if (buffer.length > 0) {
|
|
21
|
-
const value = buffer.shift();
|
|
22
|
-
waiter.resolve({ done: false, value });
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
25
|
-
if (done) {
|
|
26
|
-
waiter.resolve({ done: true, value: void 0 });
|
|
27
|
-
return true;
|
|
28
|
-
}
|
|
29
|
-
pending.unshift(waiter);
|
|
30
|
-
return false;
|
|
31
|
-
};
|
|
32
|
-
const handle = {
|
|
33
|
-
complete() {
|
|
34
|
-
if (done || failure) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
done = true;
|
|
38
|
-
while (flushOne()) {
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
fail(error) {
|
|
42
|
-
if (done || failure) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
failure = error;
|
|
46
|
-
buffer.length = 0;
|
|
47
|
-
while (flushOne()) {
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
push(value) {
|
|
51
|
-
if (done || failure || cancelled) {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
if (buffer.length >= maxBuffer) {
|
|
55
|
-
handle.fail(
|
|
56
|
-
new LunoraError(
|
|
57
|
-
"STREAM_BACKPRESSURE",
|
|
58
|
-
`stream buffer overflow (max=${maxBuffer.toString()}); the consumer cannot keep up with the producer`
|
|
59
|
-
)
|
|
60
|
-
);
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
buffer.push(value);
|
|
64
|
-
flushOne();
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
const cancel = () => {
|
|
68
|
-
if (cancelled) {
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
cancelled = true;
|
|
72
|
-
done = true;
|
|
73
|
-
buffer.length = 0;
|
|
74
|
-
try {
|
|
75
|
-
options.onCancel();
|
|
76
|
-
} catch {
|
|
77
|
-
}
|
|
78
|
-
while (flushOne()) {
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
const iterable = {
|
|
82
|
-
cancel,
|
|
83
|
-
[Symbol.asyncIterator]() {
|
|
84
|
-
return {
|
|
85
|
-
next() {
|
|
86
|
-
if (failure) {
|
|
87
|
-
return Promise.reject(failure);
|
|
88
|
-
}
|
|
89
|
-
if (buffer.length > 0) {
|
|
90
|
-
const value = buffer.shift();
|
|
91
|
-
return Promise.resolve({ done: false, value });
|
|
92
|
-
}
|
|
93
|
-
if (done) {
|
|
94
|
-
return Promise.resolve({ done: true, value: void 0 });
|
|
95
|
-
}
|
|
96
|
-
return new Promise((resolve, reject) => {
|
|
97
|
-
pending.push({ reject, resolve });
|
|
98
|
-
});
|
|
99
|
-
},
|
|
100
|
-
return() {
|
|
101
|
-
cancel();
|
|
102
|
-
return Promise.resolve({ done: true, value: void 0 });
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
return { handle, iterable };
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
export { DEFAULT_MAX_BUFFER, createStream };
|