@lunora/client 1.0.0-alpha.22 → 1.0.0-alpha.220

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 (92) hide show
  1. package/README.md +16 -3
  2. package/dist/auth/index.d.mts +43 -12
  3. package/dist/auth/index.d.ts +43 -12
  4. package/dist/auth/index.mjs +1 -60
  5. package/dist/index.d.mts +768 -416
  6. package/dist/index.d.ts +768 -416
  7. package/dist/index.mjs +1 -20
  8. package/dist/packem_shared/CONFLICT_ERROR_CODE-B7qNZMMk.mjs +1 -0
  9. package/dist/packem_shared/DEFAULT_MAX_BUFFER-Bd-_iyiV.mjs +1 -0
  10. package/dist/packem_shared/LunoraClient-C7RQBwz0.mjs +1 -0
  11. package/dist/packem_shared/OfflineQueue-BWamzR6p.mjs +1 -0
  12. package/dist/packem_shared/RETIRE_AFTER_DURABLE_SEQ_ADVANCE-DoEHtuR8.mjs +1 -0
  13. package/dist/packem_shared/SKIP-d7LeP-sY.mjs +1 -0
  14. package/dist/packem_shared/SubscriptionRegistry-DKIXE7M7.mjs +1 -0
  15. package/dist/packem_shared/TabCoordinator-CXD7vulJ.mjs +1 -0
  16. package/dist/packem_shared/applyDelta-CWpwS3Bb.mjs +1 -0
  17. package/dist/packem_shared/createAsyncStoragePersistence-6FCvqc6C.mjs +1 -0
  18. package/dist/packem_shared/createAsyncStorageQueryCache-f5023fdB.mjs +1 -0
  19. package/dist/packem_shared/createCallRunner-Bwcrfh76.mjs +1 -0
  20. package/dist/packem_shared/createClientQuery-B8Nfj-7o.mjs +1 -0
  21. package/dist/packem_shared/createInMemoryBookmarkStorage-BooZhW0n.mjs +1 -0
  22. package/dist/packem_shared/createInMemoryPersistence-Cz2W6XVj.mjs +1 -0
  23. package/dist/packem_shared/createInMemoryQueryCache-D2uNHLfM.mjs +1 -0
  24. package/dist/packem_shared/createLocalStore-BT0QPKdf.mjs +1 -0
  25. package/dist/packem_shared/createMutatorRunner-CuMRJpUx.mjs +1 -0
  26. package/dist/packem_shared/createReconnect-CjTmjJDH.mjs +1 -0
  27. package/dist/packem_shared/createServerClient-C5GKWZsC.mjs +1 -0
  28. package/dist/packem_shared/createSnapshotPrecondition-CLkxVeN1.mjs +1 -0
  29. package/dist/packem_shared/delta-merge-Ls3DED4g.mjs +1 -0
  30. package/dist/packem_shared/deserializePreloaded-CyFK_cv6.mjs +1 -0
  31. package/dist/packem_shared/function-reference.d-Br_hsKje.d.mts +45 -0
  32. package/dist/packem_shared/function-reference.d-Br_hsKje.d.ts +45 -0
  33. package/dist/packem_shared/getServerSession-BaOoo1p6.mjs +1 -0
  34. package/dist/packem_shared/httpStream-BhSpxRWB.mjs +9 -0
  35. package/dist/packem_shared/idb-utility-C8WS390w.mjs +1 -0
  36. package/dist/packem_shared/local-store-fqWV2n_Z.mjs +1 -0
  37. package/dist/packem_shared/lunora-client.d-B22TAgVj.d.mts +4720 -0
  38. package/dist/packem_shared/lunora-client.d-Cq8NykWg.d.ts +4720 -0
  39. package/dist/packem_shared/offline-queue-D_fr-uQ3.mjs +1 -0
  40. package/dist/packem_shared/preload.d-3Sb8o5sD.d.mts +21 -0
  41. package/dist/packem_shared/preload.d-CPzCWpiu.d.ts +21 -0
  42. package/dist/packem_shared/preloadQuery-uFy24PCR.mjs +1 -0
  43. package/dist/packem_shared/single-blob-store-DpqSxsgi.mjs +1 -0
  44. package/dist/packem_shared/wire-errors-WYlbE1Nh.mjs +1 -0
  45. package/dist/pagination/index.d.mts +42 -42
  46. package/dist/pagination/index.d.ts +42 -42
  47. package/dist/pagination/index.mjs +1 -61
  48. package/dist/query/index.d.mts +111 -43
  49. package/dist/query/index.d.ts +111 -43
  50. package/dist/query/index.mjs +1 -1
  51. package/dist/service.d.mts +49 -0
  52. package/dist/service.d.ts +49 -0
  53. package/dist/service.mjs +1 -0
  54. package/dist/ssr/index.d.mts +109 -79
  55. package/dist/ssr/index.d.ts +109 -79
  56. package/dist/ssr/index.mjs +1 -4
  57. package/dist/upload.d.mts +35 -0
  58. package/dist/upload.d.ts +35 -0
  59. package/dist/upload.mjs +1 -0
  60. package/package.json +15 -2
  61. package/dist/packem_shared/CONFLICT_ERROR_CODE-B8gQ8tyU.mjs +0 -33
  62. package/dist/packem_shared/ClientServiceWorker-C3PAFwy0.mjs +0 -100
  63. package/dist/packem_shared/DEFAULT_MAX_BUFFER-7hFnzNk9.mjs +0 -110
  64. package/dist/packem_shared/LunoraClient-Clb118SU.mjs +0 -3717
  65. package/dist/packem_shared/OfflineQueue-B4HUF7rt.mjs +0 -1
  66. package/dist/packem_shared/SKIP-vItZChkw.mjs +0 -50
  67. package/dist/packem_shared/SubscriptionRegistry-D4jfIzZu.mjs +0 -31
  68. package/dist/packem_shared/TabCoordinator-BwRR8H06.mjs +0 -222
  69. package/dist/packem_shared/applyDelta-CRKZ1PBt.mjs +0 -81
  70. package/dist/packem_shared/createAsyncStoragePersistence-1Z5BZ8RC.mjs +0 -45
  71. package/dist/packem_shared/createClientQuery-CQ51bWAE.mjs +0 -71
  72. package/dist/packem_shared/createInMemoryBookmarkStorage-BoN7a7TH.mjs +0 -11
  73. package/dist/packem_shared/createInMemoryPersistence-DZ2VHWgm.mjs +0 -79
  74. package/dist/packem_shared/createInMemoryQueryCache-DiaGZkA2.mjs +0 -112
  75. package/dist/packem_shared/createLocalStore-BDbbkoXw.mjs +0 -2
  76. package/dist/packem_shared/createMutationRunner-BqsavzvG.mjs +0 -21
  77. package/dist/packem_shared/createMutatorRunner-BETvCd0p.mjs +0 -31
  78. package/dist/packem_shared/createReconnect-Di_-oHH7.mjs +0 -22
  79. package/dist/packem_shared/createReply-lI4tVS2w.mjs +0 -36
  80. package/dist/packem_shared/createServerClient-Dxemst5C.mjs +0 -11
  81. package/dist/packem_shared/createSnapshotPrecondition-CBwnVz6r.mjs +0 -18
  82. package/dist/packem_shared/deserializePreloaded-C0eJTY_W.mjs +0 -4
  83. package/dist/packem_shared/getServerSession-8jXewqxd.mjs +0 -13
  84. package/dist/packem_shared/idb-utility-DrSVX43Q.mjs +0 -48
  85. package/dist/packem_shared/local-store-DtcIW4c0.mjs +0 -106
  86. package/dist/packem_shared/lunora-client.d-pw-9sLl0.d.mts +0 -2722
  87. package/dist/packem_shared/lunora-client.d-pw-9sLl0.d.ts +0 -2722
  88. package/dist/packem_shared/offline-queue-CF4_Co5k.mjs +0 -199
  89. package/dist/packem_shared/preload.d-6ME5ubgq.d.mts +0 -20
  90. package/dist/packem_shared/preload.d-BkQr-3Vh.d.ts +0 -20
  91. package/dist/packem_shared/preloadQuery-lobFkD2Z.mjs +0 -13
  92. package/dist/packem_shared/stable-key-wv6eP48B.mjs +0 -40
@@ -1 +0,0 @@
1
- export { O as OfflineQueue, n as nextId, r as reportPersistenceError } from './offline-queue-CF4_Co5k.mjs';
@@ -1,50 +0,0 @@
1
- const SKIP = "skip";
2
- const toSubscriptionError = (error) => {
3
- if (error instanceof Error) {
4
- return { message: error.message };
5
- }
6
- return { message: String(error) };
7
- };
8
- const createQuerySubscription = (client, function_, args, sinks, options = {}) => {
9
- if (args === SKIP) {
10
- sinks.onReset?.();
11
- return () => {
12
- };
13
- }
14
- let cancelled = false;
15
- const handleError = (error) => {
16
- if (cancelled) {
17
- return;
18
- }
19
- sinks.onError?.(error);
20
- };
21
- const onError = sinks.onError ? handleError : void 0;
22
- let unsubscribe;
23
- try {
24
- unsubscribe = client.subscribe(
25
- function_,
26
- args,
27
- (value) => {
28
- if (cancelled) {
29
- return;
30
- }
31
- sinks.onData(value);
32
- },
33
- { onError, shardKey: options.shardKey }
34
- );
35
- } catch (error) {
36
- if (!sinks.onError) {
37
- throw error;
38
- }
39
- handleError(toSubscriptionError(error));
40
- return () => {
41
- cancelled = true;
42
- };
43
- }
44
- return () => {
45
- cancelled = true;
46
- unsubscribe();
47
- };
48
- };
49
-
50
- export { SKIP, createQuerySubscription, toSubscriptionError };
@@ -1,31 +0,0 @@
1
- import { s as stableStringify } from './stable-key-wv6eP48B.mjs';
2
-
3
- class SubscriptionRegistry {
4
- static key(functionPath, args, shardKey) {
5
- return `${functionPath}::${stableStringify(args)}::${shardKey ?? ""}`;
6
- }
7
- byKey = /* @__PURE__ */ new Map();
8
- byId = /* @__PURE__ */ new Map();
9
- get(key) {
10
- return this.byKey.get(key);
11
- }
12
- getById(id) {
13
- return this.byId.get(id);
14
- }
15
- add(state) {
16
- this.byKey.set(SubscriptionRegistry.key(state.fn.__lunoraRef, state.args, state.shardKey), state);
17
- this.byId.set(state.id, state);
18
- }
19
- remove(state) {
20
- const key = SubscriptionRegistry.key(state.fn.__lunoraRef, state.args, state.shardKey);
21
- if (this.byKey.get(key) === state) {
22
- this.byKey.delete(key);
23
- }
24
- this.byId.delete(state.id);
25
- }
26
- all() {
27
- return [...this.byKey.values()];
28
- }
29
- }
30
-
31
- export { SubscriptionRegistry };
@@ -1,222 +0,0 @@
1
- let nextTabId = 0;
2
- const DEFAULT_CHANNEL = "lunora-bridge";
3
- const DEFAULT_HEARTBEAT_MS = 1e3;
4
- const DEFAULT_LEADER_TIMEOUT_MS = 3e3;
5
- class TabCoordinator {
6
- bc;
7
- tabId;
8
- heartbeatInterval;
9
- leaderTimeout;
10
- /** The tab id of the current known leader, or `undefined` if no leader. */
11
- knownLeader = void 0;
12
- /** `true` when this tab believes it is the leader. */
13
- leader = false;
14
- /** `true` once `start()` has been called. */
15
- running = false;
16
- /** Timestamp of the most recent leader heartbeat. */
17
- lastHeartbeat = 0;
18
- heartbeatTimer = void 0;
19
- leaderCheckTimer = void 0;
20
- /** Callbacks set via constructor options. */
21
- onBecomeLeader;
22
- onStopBeingLeader;
23
- onSubscriptionData;
24
- onSubscriptionError;
25
- constructor(options = {}) {
26
- nextTabId += 1;
27
- this.tabId = `tab_${String(nextTabId)}_${crypto.randomUUID()}`;
28
- this.heartbeatInterval = options.heartbeatInterval ?? DEFAULT_HEARTBEAT_MS;
29
- this.leaderTimeout = options.leaderTimeout ?? DEFAULT_LEADER_TIMEOUT_MS;
30
- this.onBecomeLeader = options.onBecomeLeader;
31
- this.onStopBeingLeader = options.onStopBeingLeader;
32
- this.onSubscriptionData = options.onSubscriptionData;
33
- this.onSubscriptionError = options.onSubscriptionError;
34
- if (typeof BroadcastChannel === "undefined") {
35
- this.bc = void 0;
36
- return;
37
- }
38
- this.bc = new BroadcastChannel(options.channelName ?? DEFAULT_CHANNEL);
39
- this.bc.addEventListener("message", (event) => {
40
- this.handleMessage(event.data);
41
- });
42
- }
43
- // -----------------------------------------------------------------------
44
- // Public API
45
- // -----------------------------------------------------------------------
46
- /**
47
- * Start the coordinator: attempt to claim leadership and begin the
48
- * heartbeat/leader-check cycle. Safe to call multiple times.
49
- */
50
- start() {
51
- if (this.running) {
52
- return;
53
- }
54
- this.running = true;
55
- if (this.bc === void 0) {
56
- this.becomeLeader();
57
- return;
58
- }
59
- this.broadcast({ type: "claim-leadership", tabId: this.tabId, ts: Date.now() });
60
- setTimeout(() => {
61
- if (!this.running) {
62
- return;
63
- }
64
- if (this.knownLeader === void 0) {
65
- this.becomeLeader();
66
- }
67
- }, this.leaderTimeout);
68
- this.leaderCheckTimer = setInterval(() => {
69
- this.checkLeaderHealth();
70
- }, this.leaderTimeout);
71
- this.heartbeatTimer = setInterval(() => {
72
- this.sendHeartbeat();
73
- }, this.heartbeatInterval);
74
- }
75
- /**
76
- * Stop the coordinator: yield leadership (if held), close the channel, and
77
- * clear all timers. Safe to call multiple times.
78
- */
79
- stop() {
80
- this.running = false;
81
- if (this.leader) {
82
- this.broadcast({ type: "yield-leadership", tabId: this.tabId });
83
- this.leader = false;
84
- this.knownLeader = void 0;
85
- this.onStopBeingLeader?.();
86
- }
87
- if (this.heartbeatTimer !== void 0) {
88
- clearInterval(this.heartbeatTimer);
89
- this.heartbeatTimer = void 0;
90
- }
91
- if (this.leaderCheckTimer !== void 0) {
92
- clearInterval(this.leaderCheckTimer);
93
- this.leaderCheckTimer = void 0;
94
- }
95
- this.bc?.close();
96
- }
97
- /** `true` when this tab is the current WebSocket leader. */
98
- isLeader() {
99
- return this.leader;
100
- }
101
- /** The tab id of the current leader, or `undefined` if unknown / no leader. */
102
- get leaderTabId() {
103
- return this.knownLeader;
104
- }
105
- /** The id of this tab. */
106
- get id() {
107
- return this.tabId;
108
- }
109
- /** `true` when the coordinator has been started and is not yet stopped. */
110
- get isRunning() {
111
- return this.running;
112
- }
113
- // -----------------------------------------------------------------------
114
- // Broadcasting
115
- // -----------------------------------------------------------------------
116
- /**
117
- * Broadcast subscription data to all follower tabs. Only the leader should
118
- * call this.
119
- */
120
- broadcastSubscriptionData(key, data) {
121
- if (!this.leader) {
122
- return;
123
- }
124
- this.broadcast({ type: "subscription-data", tabId: this.tabId, key, data });
125
- }
126
- /**
127
- * Broadcast a subscription error to all follower tabs. Only the leader
128
- * should call this.
129
- */
130
- broadcastSubscriptionError(key, error) {
131
- if (!this.leader) {
132
- return;
133
- }
134
- this.broadcast({ type: "subscription-error", tabId: this.tabId, key, error });
135
- }
136
- // -----------------------------------------------------------------------
137
- // Internal
138
- // -----------------------------------------------------------------------
139
- broadcast(message) {
140
- this.bc?.postMessage(message);
141
- }
142
- handleMessage(message) {
143
- switch (message.type) {
144
- case "claim-leadership": {
145
- if (message.tabId === this.tabId) {
146
- break;
147
- }
148
- if (this.leader) {
149
- this.broadcast({ type: "heartbeat", tabId: this.tabId, ts: Date.now() });
150
- break;
151
- }
152
- if (this.knownLeader === void 0 && message.tabId < this.tabId) {
153
- this.knownLeader = message.tabId;
154
- }
155
- break;
156
- }
157
- case "heartbeat": {
158
- this.lastHeartbeat = message.ts;
159
- this.knownLeader = message.tabId;
160
- break;
161
- }
162
- case "subscription-data": {
163
- if (this.leader || message.tabId === this.tabId) {
164
- break;
165
- }
166
- this.onSubscriptionData?.(message.key, message.data);
167
- break;
168
- }
169
- case "subscription-error": {
170
- if (this.leader || message.tabId === this.tabId) {
171
- break;
172
- }
173
- this.onSubscriptionError?.(message.key, message.error);
174
- break;
175
- }
176
- case "yield-leadership": {
177
- if (this.knownLeader === message.tabId) {
178
- this.knownLeader = void 0;
179
- }
180
- break;
181
- }
182
- }
183
- }
184
- becomeLeader() {
185
- if (this.leader) {
186
- return;
187
- }
188
- this.leader = true;
189
- this.knownLeader = this.tabId;
190
- this.lastHeartbeat = Date.now();
191
- this.onBecomeLeader?.();
192
- this.broadcast({ type: "heartbeat", tabId: this.tabId, ts: Date.now() });
193
- }
194
- sendHeartbeat() {
195
- if (!this.leader) {
196
- return;
197
- }
198
- this.broadcast({ type: "heartbeat", tabId: this.tabId, ts: Date.now() });
199
- }
200
- checkLeaderHealth() {
201
- if (!this.running) {
202
- return;
203
- }
204
- if (this.leader) {
205
- return;
206
- }
207
- if (this.knownLeader !== void 0) {
208
- const elapsed = Date.now() - this.lastHeartbeat;
209
- if (elapsed > this.leaderTimeout) {
210
- this.knownLeader = void 0;
211
- this.broadcast({ type: "claim-leadership", tabId: this.tabId, ts: Date.now() });
212
- setTimeout(() => {
213
- if (this.running && this.knownLeader === void 0) {
214
- this.becomeLeader();
215
- }
216
- }, this.leaderTimeout);
217
- }
218
- }
219
- }
220
- }
221
-
222
- export { TabCoordinator };
@@ -1,81 +0,0 @@
1
- const ID_FIELD = "_id";
2
- const CREATION_FIELD = "_creationTime";
3
- const rowId = (row) => {
4
- if (typeof row !== "object" || row === null) {
5
- return void 0;
6
- }
7
- const id = row[ID_FIELD];
8
- return typeof id === "string" ? id : void 0;
9
- };
10
- const isDescending = (list) => {
11
- let previous;
12
- for (const existingRow of list) {
13
- const existing = existingRow[CREATION_FIELD];
14
- if (typeof existing !== "number") {
15
- continue;
16
- }
17
- if (previous !== void 0) {
18
- if (existing < previous) {
19
- return true;
20
- }
21
- if (existing > previous) {
22
- return false;
23
- }
24
- }
25
- previous = existing;
26
- }
27
- return false;
28
- };
29
- const insertionIndex = (list, row) => {
30
- const creation = row[CREATION_FIELD];
31
- if (typeof creation !== "number") {
32
- return list.length;
33
- }
34
- const descending = isDescending(list);
35
- for (const [index, existingRow] of list.entries()) {
36
- const existing = existingRow[CREATION_FIELD];
37
- if (typeof existing === "number" && (descending ? existing < creation : existing > creation)) {
38
- return index;
39
- }
40
- }
41
- return list.length;
42
- };
43
- const isMutationDelta = (value) => {
44
- if (typeof value !== "object" || value === null) {
45
- return false;
46
- }
47
- const candidate = value;
48
- return typeof candidate["key"] === "string" && typeof candidate["table"] === "string" && (candidate["op"] === "insert" || candidate["op"] === "update" || candidate["op"] === "delete");
49
- };
50
- const applyDelta = (current, delta) => {
51
- if (!Array.isArray(current)) {
52
- return void 0;
53
- }
54
- const rows = [];
55
- for (const element of current) {
56
- const id = rowId(element);
57
- if (id === void 0) {
58
- return void 0;
59
- }
60
- rows.push(element);
61
- }
62
- const { key, op, row } = delta;
63
- if (op === "delete") {
64
- const next2 = rows.filter((existing) => existing[ID_FIELD] !== key);
65
- return next2.length === rows.length ? [...rows] : next2;
66
- }
67
- if (row === void 0) {
68
- return void 0;
69
- }
70
- const existingIndex = rows.findIndex((existing) => existing[ID_FIELD] === key);
71
- if (existingIndex === -1) {
72
- const next2 = [...rows];
73
- next2.splice(insertionIndex(rows, row), 0, row);
74
- return next2;
75
- }
76
- const next = [...rows];
77
- next[existingIndex] = row;
78
- return next;
79
- };
80
-
81
- export { applyDelta, isMutationDelta };
@@ -1,45 +0,0 @@
1
- const DEFAULT_KEY = "lunora:offline-mutations";
2
- const createAsyncStoragePersistence = (options) => {
3
- const { storage } = options;
4
- const key = options.key ?? DEFAULT_KEY;
5
- let chain = Promise.resolve();
6
- const serialize = (run) => {
7
- const next = chain.then(run, run);
8
- chain = next.then(
9
- () => void 0,
10
- () => void 0
11
- );
12
- return next;
13
- };
14
- const readAll = async () => {
15
- const raw = await storage.getItem(key);
16
- if (raw === null) {
17
- return [];
18
- }
19
- try {
20
- const parsed = JSON.parse(raw);
21
- return Array.isArray(parsed) ? parsed : [];
22
- } catch {
23
- return [];
24
- }
25
- };
26
- const writeAll = (mutations) => storage.setItem(key, JSON.stringify(mutations));
27
- return {
28
- append: (mutation) => serialize(async () => {
29
- const mutations = await readAll();
30
- mutations.push(mutation);
31
- await writeAll(mutations);
32
- }),
33
- clear: () => serialize(() => storage.removeItem(key)),
34
- load: () => serialize(readAll),
35
- remove: (id) => serialize(async () => {
36
- const mutations = await readAll();
37
- const remaining = mutations.filter((mutation) => mutation.id !== id);
38
- if (remaining.length !== mutations.length) {
39
- await writeAll(remaining);
40
- }
41
- })
42
- };
43
- };
44
-
45
- export { createAsyncStoragePersistence };
@@ -1,71 +0,0 @@
1
- class ClientQueryStore {
2
- /** Current values, keyed by the ref's stable key. Absent = never set. */
3
- values = /* @__PURE__ */ new Map();
4
- /** Subscribers keyed by ref key — notified on every set. */
5
- subscribers = /* @__PURE__ */ new Map();
6
- /**
7
- * Return the current value for `ref`, or `ref.defaultValue` if none has
8
- * been set explicitly. Returns `ref.defaultValue` when the slot has been
9
- * set to `undefined` (which is distinct from "never set").
10
- */
11
- get(ref) {
12
- if (this.values.has(ref.key)) {
13
- return this.values.get(ref.key);
14
- }
15
- return ref.defaultValue;
16
- }
17
- /**
18
- * Set a new value for `ref` and notify every subscriber. Pass `undefined`
19
- * to reset the slot to `ref.defaultValue`.
20
- */
21
- set(ref, value) {
22
- this.values.set(ref.key, value);
23
- this.notify(ref.key);
24
- }
25
- /**
26
- * Delete the stored value for `ref`, resetting to `ref.defaultValue` and
27
- * notifying subscribers.
28
- */
29
- reset(ref) {
30
- this.values.delete(ref.key);
31
- this.notify(ref.key);
32
- }
33
- /**
34
- * Subscribe to changes for `ref`. The callback is NOT invoked on
35
- * registration — callers should read the current value via
36
- * {@link get} first. Returns an unsubscribe function.
37
- */
38
- subscribe(ref, callback) {
39
- let subs = this.subscribers.get(ref.key);
40
- if (!subs) {
41
- subs = /* @__PURE__ */ new Set();
42
- this.subscribers.set(ref.key, subs);
43
- }
44
- subs.add(callback);
45
- return () => {
46
- subs.delete(callback);
47
- if (subs.size === 0) {
48
- this.subscribers.delete(ref.key);
49
- }
50
- };
51
- }
52
- /** Notify every subscriber of a value change for the given key. */
53
- notify(key) {
54
- const subs = this.subscribers.get(key);
55
- if (!subs) {
56
- return;
57
- }
58
- const value = this.values.get(key);
59
- for (const callback of subs) {
60
- try {
61
- callback(value);
62
- } catch {
63
- }
64
- }
65
- }
66
- }
67
- const createClientQuery = (key, defaultValue) => {
68
- return { defaultValue, key };
69
- };
70
-
71
- export { ClientQueryStore, createClientQuery };
@@ -1,11 +0,0 @@
1
- const createInMemoryBookmarkStorage = () => {
2
- let value = null;
3
- return {
4
- get: () => value,
5
- set: (next) => {
6
- value = next;
7
- }
8
- };
9
- };
10
-
11
- export { createInMemoryBookmarkStorage as default };
@@ -1,79 +0,0 @@
1
- import { LunoraError } from '@lunora/errors';
2
- import { p as promisifyRequest, c as createWithStore, a as createDatabaseOpener } from './idb-utility-DrSVX43Q.mjs';
3
-
4
- const createInMemoryPersistence = () => {
5
- const entries = /* @__PURE__ */ new Map();
6
- const clone = (mutation) => {
7
- return {
8
- args: { ...mutation.args },
9
- functionPath: mutation.functionPath,
10
- id: mutation.id,
11
- identity: mutation.identity,
12
- shardKey: mutation.shardKey
13
- };
14
- };
15
- return {
16
- append: (mutation) => {
17
- entries.set(mutation.id, clone(mutation));
18
- return Promise.resolve();
19
- },
20
- clear: () => {
21
- entries.clear();
22
- return Promise.resolve();
23
- },
24
- load: () => Promise.resolve([...entries.values()].map((mutation) => clone(mutation))),
25
- remove: (id) => {
26
- entries.delete(id);
27
- return Promise.resolve();
28
- }
29
- };
30
- };
31
- const DEFAULT_DATABASE = "lunora-outbox";
32
- const DEFAULT_STORE = "offline-mutations";
33
- const ID_INDEX = "by_id";
34
- const createIndexedDbPersistence = (options = {}) => {
35
- const factory = options.indexedDB ?? (typeof indexedDB === "undefined" ? void 0 : indexedDB);
36
- if (!factory) {
37
- throw new LunoraError("INTERNAL", "createIndexedDbPersistence: no IndexedDB available — pass `indexedDB` or use createInMemoryPersistence()");
38
- }
39
- const databaseName = options.databaseName ?? DEFAULT_DATABASE;
40
- const storeName = options.storeName ?? DEFAULT_STORE;
41
- const openDatabase = createDatabaseOpener(factory, databaseName, 1, (database) => {
42
- if (!database.objectStoreNames.contains(storeName)) {
43
- const store = database.createObjectStore(storeName, { autoIncrement: true });
44
- store.createIndex(ID_INDEX, "id", { unique: true });
45
- }
46
- });
47
- const withStore = createWithStore(openDatabase, storeName);
48
- return {
49
- append: async (mutation) => {
50
- await withStore("readwrite", (store) => promisifyRequest(store.add(mutation)));
51
- },
52
- clear: async () => {
53
- await withStore("readwrite", (store) => promisifyRequest(store.clear()));
54
- },
55
- load: async () => withStore("readonly", (store) => promisifyRequest(store.getAll())),
56
- remove: async (id) => {
57
- await withStore("readwrite", async (store) => {
58
- const key = await promisifyRequest(store.index(ID_INDEX).getKey(id));
59
- if (key !== void 0) {
60
- await promisifyRequest(store.delete(key));
61
- }
62
- });
63
- }
64
- };
65
- };
66
- const resolvePersistenceAdapter = (option, autoProbe = true) => {
67
- if (option === false) {
68
- return void 0;
69
- }
70
- if (option) {
71
- return option;
72
- }
73
- if (!autoProbe || typeof indexedDB === "undefined") {
74
- return void 0;
75
- }
76
- return createIndexedDbPersistence();
77
- };
78
-
79
- export { createInMemoryPersistence, createIndexedDbPersistence, resolvePersistenceAdapter };