@lunora/client 1.0.0-alpha.21 → 1.0.0-alpha.211

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 (89) 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 +809 -268
  6. package/dist/index.d.ts +809 -268
  7. package/dist/index.mjs +1 -15
  8. package/dist/packem_shared/CONFLICT_ERROR_CODE-B7qNZMMk.mjs +1 -0
  9. package/dist/packem_shared/DEFAULT_MAX_BUFFER-D3QH2iaq.mjs +1 -0
  10. package/dist/packem_shared/LunoraClient-BSI0RIrs.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-5CHmk3d8.mjs +1 -0
  15. package/dist/packem_shared/TabCoordinator-CXD7vulJ.mjs +1 -0
  16. package/dist/packem_shared/applyDelta-UuKQOPo1.mjs +1 -0
  17. package/dist/packem_shared/createAsyncStoragePersistence-DXlhLrFv.mjs +1 -0
  18. package/dist/packem_shared/createAsyncStorageQueryCache-CAPNYhcK.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-CriEK0Fm.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-D7ZQOnat.mjs +1 -0
  28. package/dist/packem_shared/createSnapshotPrecondition-D-WkMTIs.mjs +1 -0
  29. package/dist/packem_shared/delta-merge-CDCNlktH.mjs +1 -0
  30. package/dist/packem_shared/deserializePreloaded-CEQci6cB.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-B5J3zeB8.mjs +9 -0
  35. package/dist/packem_shared/idb-utility-C8WS390w.mjs +1 -0
  36. package/dist/packem_shared/local-store-CtP_1rJj.mjs +1 -0
  37. package/dist/packem_shared/lunora-client.d-B-1VFscs.d.mts +4647 -0
  38. package/dist/packem_shared/lunora-client.d-_Qd50jQo.d.ts +4647 -0
  39. package/dist/packem_shared/offline-queue-D_fr-uQ3.mjs +1 -0
  40. package/dist/packem_shared/preload.d-D82baNUQ.d.mts +21 -0
  41. package/dist/packem_shared/preload.d-ubxA2STh.d.ts +21 -0
  42. package/dist/packem_shared/preloadQuery-uFy24PCR.mjs +1 -0
  43. package/dist/packem_shared/single-blob-store-D7kYfN1I.mjs +1 -0
  44. package/dist/packem_shared/wire-codec-3Mj5UgNj.mjs +1 -0
  45. package/dist/packem_shared/wire-errors-CYMmnEcW.mjs +1 -0
  46. package/dist/packem_shared/wire-key-3XBGlnux.mjs +1 -0
  47. package/dist/pagination/index.d.mts +42 -42
  48. package/dist/pagination/index.d.ts +42 -42
  49. package/dist/pagination/index.mjs +1 -61
  50. package/dist/query/index.d.mts +111 -43
  51. package/dist/query/index.d.ts +111 -43
  52. package/dist/query/index.mjs +1 -1
  53. package/dist/service.d.mts +49 -0
  54. package/dist/service.d.ts +49 -0
  55. package/dist/service.mjs +1 -0
  56. package/dist/ssr/index.d.mts +109 -79
  57. package/dist/ssr/index.d.ts +109 -79
  58. package/dist/ssr/index.mjs +1 -4
  59. package/dist/upload.d.mts +35 -0
  60. package/dist/upload.d.ts +35 -0
  61. package/dist/upload.mjs +1 -0
  62. package/package.json +14 -2
  63. package/dist/packem_shared/CONFLICT_ERROR_CODE-B8gQ8tyU.mjs +0 -33
  64. package/dist/packem_shared/DEFAULT_MAX_BUFFER-7hFnzNk9.mjs +0 -110
  65. package/dist/packem_shared/LunoraClient-kXpHNyaE.mjs +0 -3460
  66. package/dist/packem_shared/OfflineQueue-GGYJRmhF.mjs +0 -1
  67. package/dist/packem_shared/SKIP-vItZChkw.mjs +0 -50
  68. package/dist/packem_shared/SubscriptionRegistry-DjGKZsqq.mjs +0 -1
  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/createInMemoryBookmarkStorage-BoN7a7TH.mjs +0 -11
  72. package/dist/packem_shared/createInMemoryPersistence-DZ2VHWgm.mjs +0 -79
  73. package/dist/packem_shared/createInMemoryQueryCache-DiaGZkA2.mjs +0 -112
  74. package/dist/packem_shared/createLocalStore-jRoqmazl.mjs +0 -2
  75. package/dist/packem_shared/createMutationRunner-BqsavzvG.mjs +0 -21
  76. package/dist/packem_shared/createMutatorRunner-BETvCd0p.mjs +0 -31
  77. package/dist/packem_shared/createReconnect-Di_-oHH7.mjs +0 -22
  78. package/dist/packem_shared/createServerClient-DF-3mLmb.mjs +0 -11
  79. package/dist/packem_shared/deserializePreloaded-C0eJTY_W.mjs +0 -4
  80. package/dist/packem_shared/getServerSession-8jXewqxd.mjs +0 -13
  81. package/dist/packem_shared/idb-utility-DrSVX43Q.mjs +0 -48
  82. package/dist/packem_shared/local-store-BveBeFEo.mjs +0 -106
  83. package/dist/packem_shared/lunora-client.d-BYkEjCEJ.d.mts +0 -2540
  84. package/dist/packem_shared/lunora-client.d-BYkEjCEJ.d.ts +0 -2540
  85. package/dist/packem_shared/offline-queue-B9vfdSqp.mjs +0 -170
  86. package/dist/packem_shared/preload.d-B-vyHnml.d.ts +0 -20
  87. package/dist/packem_shared/preload.d-DrfuisCE.d.mts +0 -20
  88. package/dist/packem_shared/preloadQuery-lobFkD2Z.mjs +0 -13
  89. package/dist/packem_shared/subscription-BjynOXCU.mjs +0 -68
@@ -1 +0,0 @@
1
- export { O as OfflineQueue, n as nextId, r as reportPersistenceError } from './offline-queue-B9vfdSqp.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 +0,0 @@
1
- export { S as SubscriptionRegistry } from './subscription-BjynOXCU.mjs';
@@ -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,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 };
@@ -1,112 +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 queryCacheKey = (functionPath, argsKey, shardKey) => `${functionPath}::${argsKey}::${shardKey ?? ""}`;
5
- const DEFAULT_MAX_ENTRIES = 500;
6
- const createInMemoryQueryCache = (options = {}) => {
7
- const maxEntries = options.maxEntries ?? DEFAULT_MAX_ENTRIES;
8
- const entries = /* @__PURE__ */ new Map();
9
- const clone = (entry) => {
10
- return { ...entry, value: structuredClone(entry.value) };
11
- };
12
- const evict = () => {
13
- if (entries.size <= maxEntries) {
14
- return;
15
- }
16
- const ordered = [...entries.values()].toSorted((a, b) => a.ts - b.ts);
17
- for (const entry of ordered) {
18
- if (entries.size <= maxEntries) {
19
- break;
20
- }
21
- entries.delete(entry.key);
22
- }
23
- };
24
- return {
25
- clear: () => {
26
- entries.clear();
27
- return Promise.resolve();
28
- },
29
- load: () => Promise.resolve([...entries.values()].map((entry) => clone(entry))),
30
- put: (key, entry) => {
31
- entries.set(key, clone({ ...entry, key }));
32
- evict();
33
- return Promise.resolve();
34
- },
35
- remove: (key) => {
36
- entries.delete(key);
37
- return Promise.resolve();
38
- }
39
- };
40
- };
41
- const DEFAULT_DATABASE = "lunora-query-cache";
42
- const DEFAULT_STORE = "query-cache";
43
- const TS_INDEX = "by_ts";
44
- const DATABASE_VERSION = 1;
45
- const createIndexedDbQueryCache = (options = {}) => {
46
- const factory = options.indexedDB ?? (typeof indexedDB === "undefined" ? void 0 : indexedDB);
47
- if (!factory) {
48
- throw new LunoraError("INTERNAL", "createIndexedDbQueryCache: no IndexedDB available — pass `indexedDB` or use createInMemoryQueryCache()");
49
- }
50
- const databaseName = options.databaseName ?? DEFAULT_DATABASE;
51
- const storeName = options.storeName ?? DEFAULT_STORE;
52
- const maxEntries = options.maxEntries ?? DEFAULT_MAX_ENTRIES;
53
- const openDatabase = createDatabaseOpener(factory, databaseName, DATABASE_VERSION, (database) => {
54
- if (!database.objectStoreNames.contains(storeName)) {
55
- const store = database.createObjectStore(storeName, { keyPath: "key" });
56
- store.createIndex(TS_INDEX, "ts", { unique: false });
57
- }
58
- });
59
- const withStore = createWithStore(openDatabase, storeName);
60
- const evict = async (store) => {
61
- const count = await promisifyRequest(store.count());
62
- let overflow = count - maxEntries;
63
- if (overflow <= 0) {
64
- return;
65
- }
66
- await new Promise((resolve, reject) => {
67
- const cursorRequest = store.index(TS_INDEX).openCursor();
68
- cursorRequest.addEventListener("success", () => {
69
- const cursor = cursorRequest.result;
70
- if (!cursor || overflow <= 0) {
71
- resolve();
72
- return;
73
- }
74
- cursor.delete();
75
- overflow -= 1;
76
- cursor.continue();
77
- });
78
- cursorRequest.addEventListener("error", () => {
79
- reject(cursorRequest.error ?? new Error("IndexedDB eviction failed"));
80
- });
81
- });
82
- };
83
- return {
84
- clear: async () => {
85
- await withStore("readwrite", (store) => promisifyRequest(store.clear()));
86
- },
87
- load: async () => withStore("readonly", (store) => promisifyRequest(store.getAll())),
88
- put: async (key, entry) => {
89
- await withStore("readwrite", async (store) => {
90
- await promisifyRequest(store.put({ ...entry, key }));
91
- await evict(store);
92
- });
93
- },
94
- remove: async (key) => {
95
- await withStore("readwrite", (store) => promisifyRequest(store.delete(key)));
96
- }
97
- };
98
- };
99
- const resolveQueryCacheAdapter = (option) => {
100
- if (option === false) {
101
- return void 0;
102
- }
103
- if (option) {
104
- return option;
105
- }
106
- if (typeof indexedDB === "undefined") {
107
- return void 0;
108
- }
109
- return createIndexedDbQueryCache();
110
- };
111
-
112
- export { createInMemoryQueryCache, createIndexedDbQueryCache, queryCacheKey, resolveQueryCacheAdapter };
@@ -1,2 +0,0 @@
1
- export { c as createLocalStore } from './local-store-BveBeFEo.mjs';
2
- import './subscription-BjynOXCU.mjs';
@@ -1,21 +0,0 @@
1
- const createMutationRunner = (client, function_, sinks) => {
2
- let inFlight = 0;
3
- return async (args, options) => {
4
- inFlight += 1;
5
- sinks.setPending(true);
6
- try {
7
- const result = await client.mutation(function_, args, options);
8
- sinks.setResult(result);
9
- return result;
10
- } catch (error) {
11
- const normalized = error instanceof Error ? error : new Error(String(error));
12
- sinks.setError(normalized);
13
- throw normalized;
14
- } finally {
15
- inFlight -= 1;
16
- sinks.setPending(inFlight > 0);
17
- }
18
- };
19
- };
20
-
21
- export { createMutationRunner };
@@ -1,31 +0,0 @@
1
- const createMutatorRunner = (handle, sinks) => {
2
- let inFlight = 0;
3
- let latestInvocation = 0;
4
- const mutate = async (args) => {
5
- latestInvocation += 1;
6
- const invocation = latestInvocation;
7
- inFlight += 1;
8
- sinks.setPending(true);
9
- try {
10
- await handle(args).isPersisted.promise;
11
- if (invocation === latestInvocation) {
12
- sinks.setError(void 0);
13
- }
14
- } catch (error) {
15
- const normalized = error instanceof Error ? error : new Error(String(error));
16
- if (invocation === latestInvocation) {
17
- sinks.setError(normalized);
18
- }
19
- throw normalized;
20
- } finally {
21
- inFlight -= 1;
22
- sinks.setPending(inFlight > 0);
23
- }
24
- };
25
- const reset = () => {
26
- sinks.setError(void 0);
27
- };
28
- return { mutate, reset };
29
- };
30
-
31
- export { createMutatorRunner };
@@ -1,22 +0,0 @@
1
- const createReconnect = (options = {}, random = Math.random) => {
2
- const initialDelayMs = options.initialDelayMs ?? 250;
3
- const maxDelayMs = options.maxDelayMs ?? 3e4;
4
- const jitter = options.jitter ?? true;
5
- let attempt = 0;
6
- return {
7
- next() {
8
- const exponential = Math.min(maxDelayMs, initialDelayMs * 2 ** attempt);
9
- attempt += 1;
10
- if (!jitter) {
11
- return exponential;
12
- }
13
- const min = exponential / 2;
14
- return Math.floor(min + random() * (exponential - min));
15
- },
16
- reset() {
17
- attempt = 0;
18
- }
19
- };
20
- };
21
-
22
- export { createReconnect };
@@ -1,11 +0,0 @@
1
- import { LunoraClient } from './LunoraClient-kXpHNyaE.mjs';
2
-
3
- const createServerClient = (options) => {
4
- const client = new LunoraClient({ fetch: options.fetch, url: options.url });
5
- if (options.token !== void 0) {
6
- client.setAuthToken(options.token);
7
- }
8
- return client;
9
- };
10
-
11
- export { createServerClient };
@@ -1,4 +0,0 @@
1
- const serializePreloaded = (preloaded) => JSON.stringify(preloaded).replaceAll("<", String.raw`\u003c`);
2
- const deserializePreloaded = (serialized) => JSON.parse(serialized);
3
-
4
- export { deserializePreloaded, serializePreloaded };
@@ -1,13 +0,0 @@
1
- const extractHeaders = (source) => {
2
- if (source instanceof Headers) {
3
- return source;
4
- }
5
- return source.headers;
6
- };
7
- const getServerSession = async (request, auth) => {
8
- const headers = extractHeaders(request);
9
- const result = await auth.api.getSession({ headers });
10
- return result ?? null;
11
- };
12
-
13
- export { getServerSession };
@@ -1,48 +0,0 @@
1
- const promisifyRequest = (request) => new Promise((resolve, reject) => {
2
- request.addEventListener("success", () => {
3
- resolve(request.result);
4
- });
5
- request.addEventListener("error", () => {
6
- reject(request.error ?? new Error("IndexedDB request failed"));
7
- });
8
- });
9
- const createDatabaseOpener = (factory, databaseName, version, upgrade) => {
10
- let databasePromise;
11
- return () => {
12
- if (databasePromise) {
13
- return databasePromise;
14
- }
15
- databasePromise = new Promise((resolve, reject) => {
16
- const request = factory.open(databaseName, version);
17
- request.addEventListener("upgradeneeded", () => {
18
- upgrade(request.result);
19
- });
20
- request.addEventListener("success", () => {
21
- resolve(request.result);
22
- });
23
- request.addEventListener("error", () => {
24
- reject(request.error ?? new Error("IndexedDB open failed"));
25
- });
26
- });
27
- return databasePromise;
28
- };
29
- };
30
- const createWithStore = (open, storeName) => async (mode, run) => {
31
- const database = await open();
32
- const transaction = database.transaction(storeName, mode);
33
- const result = await run(transaction.objectStore(storeName));
34
- await new Promise((resolve, reject) => {
35
- transaction.addEventListener("complete", () => {
36
- resolve();
37
- });
38
- transaction.addEventListener("error", () => {
39
- reject(transaction.error ?? new Error("IndexedDB transaction failed"));
40
- });
41
- transaction.addEventListener("abort", () => {
42
- reject(transaction.error ?? new Error("IndexedDB transaction aborted"));
43
- });
44
- });
45
- return result;
46
- };
47
-
48
- export { createDatabaseOpener as a, createWithStore as c, promisifyRequest as p };
@@ -1,106 +0,0 @@
1
- import { S as SubscriptionRegistry } from './subscription-BjynOXCU.mjs';
2
-
3
- const foldOptimistic = (base, layers) => {
4
- let value = base;
5
- for (const layer of layers) {
6
- try {
7
- value = layer.transform(value);
8
- } catch {
9
- }
10
- }
11
- return value;
12
- };
13
- const notifySubscription = (state, value) => {
14
- if (value === state.lastValue) {
15
- return;
16
- }
17
- state.lastValue = value;
18
- for (const callback of state.callbacks) {
19
- try {
20
- callback(value);
21
- } catch {
22
- }
23
- }
24
- };
25
- const applyOptimisticLayer = (state, optimistic) => {
26
- let next;
27
- try {
28
- next = optimistic(state.lastValue);
29
- } catch {
30
- return void 0;
31
- }
32
- const layer = { id: /* @__PURE__ */ Symbol("optimistic"), transform: optimistic };
33
- state.optimisticLayers.push(layer);
34
- notifySubscription(state, next);
35
- const remove = () => {
36
- const index = state.optimisticLayers.findIndex((entry) => entry.id === layer.id);
37
- if (index === -1) {
38
- return false;
39
- }
40
- state.optimisticLayers.splice(index, 1);
41
- return true;
42
- };
43
- const refold = () => {
44
- notifySubscription(state, foldOptimistic(state.serverBase, state.optimisticLayers));
45
- };
46
- return {
47
- confirm: (commitCursor) => {
48
- if (commitCursor === void 0) {
49
- remove();
50
- return;
51
- }
52
- layer.commitCursor = commitCursor;
53
- if (state.serverCursor !== void 0 && state.serverCursor >= commitCursor && remove()) {
54
- refold();
55
- }
56
- },
57
- rollback: () => {
58
- if (remove()) {
59
- refold();
60
- }
61
- }
62
- };
63
- };
64
- const dropConfirmedLayers = (state, cursor) => {
65
- if (cursor === void 0 || state.optimisticLayers.length === 0) {
66
- return false;
67
- }
68
- const before = state.optimisticLayers.length;
69
- state.optimisticLayers = state.optimisticLayers.filter((layer) => layer.commitCursor === void 0 || layer.commitCursor > cursor);
70
- return state.optimisticLayers.length !== before;
71
- };
72
-
73
- const createLocalStore = (subscriptions, shardKey) => {
74
- const confirms = [];
75
- const rollbacks = [];
76
- const findState = (functionRef, args) => subscriptions.get(SubscriptionRegistry.key(functionRef, args, shardKey));
77
- const store = {
78
- getAllQueries: (function_) => {
79
- const matches = [];
80
- for (const state of subscriptions.all()) {
81
- if (state.fn.__lunoraRef === function_.__lunoraRef && (state.shardKey ?? "") === (shardKey ?? "")) {
82
- matches.push({ args: state.args, value: state.lastValue });
83
- }
84
- }
85
- return matches;
86
- },
87
- getQuery: (function_, args) => {
88
- const state = findState(function_.__lunoraRef, args ?? {});
89
- return state?.lastValue;
90
- },
91
- setQuery: (function_, args, value) => {
92
- const state = findState(function_.__lunoraRef, args ?? {});
93
- if (!state) {
94
- return;
95
- }
96
- const handle = applyOptimisticLayer(state, () => value);
97
- if (handle) {
98
- confirms.push(handle.confirm);
99
- rollbacks.push(handle.rollback);
100
- }
101
- }
102
- };
103
- return { confirms, rollbacks, store };
104
- };
105
-
106
- export { applyOptimisticLayer as a, createLocalStore as c, dropConfirmedLayers as d, foldOptimistic as f, notifySubscription as n };