@lunora/client 1.0.0-alpha.1 → 1.0.0-alpha.11

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 (32) hide show
  1. package/README.md +2 -0
  2. package/__assets__/package-og.svg +1 -1
  3. package/dist/auth/index.d.mts +1 -1
  4. package/dist/auth/index.d.ts +1 -1
  5. package/dist/index.d.mts +136 -5
  6. package/dist/index.d.ts +136 -5
  7. package/dist/index.mjs +8 -7
  8. package/dist/packem_shared/{LunoraClient-B00f7VUM.mjs → LunoraClient-6J-4BGWK.mjs} +744 -187
  9. package/dist/packem_shared/OfflineQueue-BI0FNNvc.mjs +1 -0
  10. package/dist/packem_shared/SubscriptionRegistry-Dn-7k7eo.mjs +1 -0
  11. package/dist/packem_shared/{createIndexedDbPersistence-CW82inU5.mjs → createInMemoryPersistence-DlFjWtOm.mjs} +13 -1
  12. package/dist/packem_shared/{createIndexedDbQueryCache-B1PQ9Twl.mjs → createInMemoryQueryCache-4AkTV38-.mjs} +13 -1
  13. package/dist/packem_shared/createLocalStore-IOur0jHF.mjs +1 -0
  14. package/dist/packem_shared/createMutatorRunner-BETvCd0p.mjs +31 -0
  15. package/dist/packem_shared/{createServerClient-DyFIHnWZ.mjs → createServerClient-CtklXrs2.mjs} +1 -1
  16. package/dist/packem_shared/local-store-BNgN3Dw3.mjs +111 -0
  17. package/dist/packem_shared/{lunora-client.d-DGvyuJ_p.d.mts → lunora-client.d-Dm1BYq19.d.mts} +652 -43
  18. package/dist/packem_shared/{lunora-client.d-DGvyuJ_p.d.ts → lunora-client.d-Dm1BYq19.d.ts} +652 -43
  19. package/dist/packem_shared/{OfflineQueue-D5p_QgF_.mjs → offline-queue-7Wc4onA0.mjs} +42 -5
  20. package/dist/packem_shared/{preload.d-dSaRMuhL.d.mts → preload.d-BfWzGJWV.d.mts} +1 -1
  21. package/dist/packem_shared/{preload.d-BoDmFqSG.d.ts → preload.d-Sp_Ef-_u.d.ts} +1 -1
  22. package/dist/packem_shared/subscription-C1Jy7HiF.mjs +55 -0
  23. package/dist/query/index.d.mts +2 -2
  24. package/dist/query/index.d.ts +2 -2
  25. package/dist/ssr/index.d.mts +3 -3
  26. package/dist/ssr/index.d.ts +3 -3
  27. package/dist/ssr/index.mjs +2 -2
  28. package/package.json +2 -2
  29. package/dist/packem_shared/SubscriptionRegistry-B-Qx_Gux.mjs +0 -26
  30. package/dist/packem_shared/createLocalStore-DSUfoLqY.mjs +0 -36
  31. /package/dist/packem_shared/{createStream-BDkqO5PW.mjs → DEFAULT_MAX_BUFFER-BDkqO5PW.mjs} +0 -0
  32. /package/dist/packem_shared/{serializePreloaded-C0eJTY_W.mjs → deserializePreloaded-C0eJTY_W.mjs} +0 -0
@@ -0,0 +1 @@
1
+ export { O as OfflineQueue, n as nextId, r as reportPersistenceError } from './offline-queue-7Wc4onA0.mjs';
@@ -0,0 +1 @@
1
+ export { S as SubscriptionRegistry } from './subscription-C1Jy7HiF.mjs';
@@ -101,5 +101,17 @@ const createIndexedDbPersistence = (options = {}) => {
101
101
  }
102
102
  };
103
103
  };
104
+ const resolvePersistenceAdapter = (option, autoProbe = true) => {
105
+ if (option === false) {
106
+ return void 0;
107
+ }
108
+ if (option) {
109
+ return option;
110
+ }
111
+ if (!autoProbe || typeof indexedDB === "undefined") {
112
+ return void 0;
113
+ }
114
+ return createIndexedDbPersistence();
115
+ };
104
116
 
105
- export { createInMemoryPersistence, createIndexedDbPersistence };
117
+ export { createInMemoryPersistence, createIndexedDbPersistence, resolvePersistenceAdapter };
@@ -134,5 +134,17 @@ const createIndexedDbQueryCache = (options = {}) => {
134
134
  }
135
135
  };
136
136
  };
137
+ const resolveQueryCacheAdapter = (option) => {
138
+ if (option === false) {
139
+ return void 0;
140
+ }
141
+ if (option) {
142
+ return option;
143
+ }
144
+ if (typeof indexedDB === "undefined") {
145
+ return void 0;
146
+ }
147
+ return createIndexedDbQueryCache();
148
+ };
137
149
 
138
- export { createInMemoryQueryCache, createIndexedDbQueryCache, queryCacheKey };
150
+ export { createInMemoryQueryCache, createIndexedDbQueryCache, queryCacheKey, resolveQueryCacheAdapter };
@@ -0,0 +1 @@
1
+ export { c as createLocalStore } from './local-store-BNgN3Dw3.mjs';
@@ -0,0 +1,31 @@
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,4 +1,4 @@
1
- import { LunoraClient } from './LunoraClient-B00f7VUM.mjs';
1
+ import { LunoraClient } from './LunoraClient-6J-4BGWK.mjs';
2
2
 
3
3
  const createServerClient = (options) => {
4
4
  const client = new LunoraClient({ fetch: options.fetch, url: options.url });
@@ -0,0 +1,111 @@
1
+ const foldOptimistic = (base, layers) => {
2
+ let value = base;
3
+ for (const layer of layers) {
4
+ try {
5
+ value = layer.transform(value);
6
+ } catch {
7
+ }
8
+ }
9
+ return value;
10
+ };
11
+ const notifySubscription = (state, value) => {
12
+ if (value === state.lastValue) {
13
+ return;
14
+ }
15
+ state.lastValue = value;
16
+ for (const callback of state.callbacks) {
17
+ try {
18
+ callback(value);
19
+ } catch {
20
+ }
21
+ }
22
+ };
23
+ const applyOptimisticLayer = (state, optimistic) => {
24
+ let next;
25
+ try {
26
+ next = optimistic(state.lastValue);
27
+ } catch {
28
+ return void 0;
29
+ }
30
+ const layer = { id: /* @__PURE__ */ Symbol("optimistic"), transform: optimistic };
31
+ state.optimisticLayers.push(layer);
32
+ notifySubscription(state, next);
33
+ const remove = () => {
34
+ const index = state.optimisticLayers.findIndex((entry) => entry.id === layer.id);
35
+ if (index === -1) {
36
+ return false;
37
+ }
38
+ state.optimisticLayers.splice(index, 1);
39
+ return true;
40
+ };
41
+ const refold = () => {
42
+ notifySubscription(state, foldOptimistic(state.serverBase, state.optimisticLayers));
43
+ };
44
+ return {
45
+ confirm: (commitCursor) => {
46
+ if (commitCursor === void 0) {
47
+ remove();
48
+ return;
49
+ }
50
+ layer.commitCursor = commitCursor;
51
+ if (state.serverCursor !== void 0 && state.serverCursor >= commitCursor && remove()) {
52
+ refold();
53
+ }
54
+ },
55
+ rollback: () => {
56
+ if (remove()) {
57
+ refold();
58
+ }
59
+ }
60
+ };
61
+ };
62
+ const dropConfirmedLayers = (state, cursor) => {
63
+ if (cursor === void 0 || state.optimisticLayers.length === 0) {
64
+ return false;
65
+ }
66
+ const before = state.optimisticLayers.length;
67
+ state.optimisticLayers = state.optimisticLayers.filter((layer) => layer.commitCursor === void 0 || layer.commitCursor > cursor);
68
+ return state.optimisticLayers.length !== before;
69
+ };
70
+
71
+ const createLocalStore = (subscriptions, shardKey, stableStringify) => {
72
+ const confirms = [];
73
+ const rollbacks = [];
74
+ const findState = (functionRef, argsKey) => {
75
+ for (const state of subscriptions.all()) {
76
+ if (state.fn.__lunoraRef === functionRef && state.shardKey === shardKey && state.argsKey === argsKey) {
77
+ return state;
78
+ }
79
+ }
80
+ return void 0;
81
+ };
82
+ const store = {
83
+ getAllQueries: (function_) => {
84
+ const matches = [];
85
+ for (const state of subscriptions.all()) {
86
+ if (state.fn.__lunoraRef === function_.__lunoraRef && state.shardKey === shardKey) {
87
+ matches.push({ args: state.args, value: state.lastValue });
88
+ }
89
+ }
90
+ return matches;
91
+ },
92
+ getQuery: (function_, args) => {
93
+ const state = findState(function_.__lunoraRef, stableStringify(args ?? {}));
94
+ return state?.lastValue;
95
+ },
96
+ setQuery: (function_, args, value) => {
97
+ const state = findState(function_.__lunoraRef, stableStringify(args ?? {}));
98
+ if (!state) {
99
+ return;
100
+ }
101
+ const handle = applyOptimisticLayer(state, () => value);
102
+ if (handle) {
103
+ confirms.push(handle.confirm);
104
+ rollbacks.push(handle.rollback);
105
+ }
106
+ }
107
+ };
108
+ return { confirms, rollbacks, store };
109
+ };
110
+
111
+ export { applyOptimisticLayer as a, createLocalStore as c, dropConfirmedLayers as d, foldOptimistic as f, notifySubscription as n };