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

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 (30) hide show
  1. package/dist/auth/index.d.mts +1 -1
  2. package/dist/auth/index.d.ts +1 -1
  3. package/dist/index.d.mts +212 -4
  4. package/dist/index.d.ts +212 -4
  5. package/dist/index.mjs +9 -4
  6. package/dist/packem_shared/ClientServiceWorker-C3PAFwy0.mjs +100 -0
  7. package/dist/packem_shared/{LunoraClient-kXpHNyaE.mjs → LunoraClient-Clb118SU.mjs} +279 -22
  8. package/dist/packem_shared/{OfflineQueue-GGYJRmhF.mjs → OfflineQueue-B4HUF7rt.mjs} +1 -1
  9. package/dist/packem_shared/SubscriptionRegistry-D4jfIzZu.mjs +31 -0
  10. package/dist/packem_shared/TabCoordinator-BwRR8H06.mjs +222 -0
  11. package/dist/packem_shared/createClientQuery-CQ51bWAE.mjs +71 -0
  12. package/dist/packem_shared/createLocalStore-BDbbkoXw.mjs +2 -0
  13. package/dist/packem_shared/createReply-lI4tVS2w.mjs +36 -0
  14. package/dist/packem_shared/{createServerClient-DF-3mLmb.mjs → createServerClient-Dxemst5C.mjs} +1 -1
  15. package/dist/packem_shared/createSnapshotPrecondition-CBwnVz6r.mjs +18 -0
  16. package/dist/packem_shared/{local-store-BveBeFEo.mjs → local-store-DtcIW4c0.mjs} +1 -1
  17. package/dist/packem_shared/{lunora-client.d-BYkEjCEJ.d.mts → lunora-client.d-pw-9sLl0.d.mts} +183 -1
  18. package/dist/packem_shared/{lunora-client.d-BYkEjCEJ.d.ts → lunora-client.d-pw-9sLl0.d.ts} +183 -1
  19. package/dist/packem_shared/{offline-queue-B9vfdSqp.mjs → offline-queue-CF4_Co5k.mjs} +29 -0
  20. package/dist/packem_shared/{preload.d-DrfuisCE.d.mts → preload.d-6ME5ubgq.d.mts} +1 -1
  21. package/dist/packem_shared/{preload.d-B-vyHnml.d.ts → preload.d-BkQr-3Vh.d.ts} +1 -1
  22. package/dist/packem_shared/{subscription-BjynOXCU.mjs → stable-key-wv6eP48B.mjs} +1 -29
  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 +1 -1
  28. package/package.json +1 -1
  29. package/dist/packem_shared/SubscriptionRegistry-DjGKZsqq.mjs +0 -1
  30. package/dist/packem_shared/createLocalStore-jRoqmazl.mjs +0 -2
@@ -152,6 +152,35 @@ class OfflineQueue {
152
152
  this.items.unshift(...items);
153
153
  this.notifySize();
154
154
  }
155
+ /**
156
+ * Remove mutations whose precondition evaluates to `false` (stale/dirty
157
+ * writes that should not replay) and reject each with an
158
+ * `OFFLINE_PRECONDITION_FAILED` error. The valid (admitted) mutations stay
159
+ * queued in FIFO order. Returns the drained stale entries.
160
+ *
161
+ * Called during reconnect before the flush cycle to weed out writes whose
162
+ * assumptions no longer hold (e.g. a document was deleted by another client).
163
+ */
164
+ drainConflict() {
165
+ const conflicted = [];
166
+ const kept = [];
167
+ for (const item of this.items) {
168
+ if (item.precondition !== void 0 && !item.precondition()) {
169
+ const error = new Error("offline mutation skipped: precondition failed before replay");
170
+ error.code = "OFFLINE_PRECONDITION_FAILED";
171
+ item.reject(error);
172
+ conflicted.push(item);
173
+ } else {
174
+ kept.push(item);
175
+ }
176
+ }
177
+ if (conflicted.length > 0) {
178
+ this.items.length = 0;
179
+ this.items.push(...kept);
180
+ this.notifySize();
181
+ }
182
+ return conflicted;
183
+ }
155
184
  clear() {
156
185
  for (const item of this.items) {
157
186
  const error = new Error("CLIENT_CLOSED");
@@ -1,4 +1,4 @@
1
- import { F as FunctionReference, L as LunoraClient, A as ArgsOf, R as ReturnOf, P as Preloaded } from "./lunora-client.d-BYkEjCEJ.mjs";
1
+ import { F as FunctionReference, L as LunoraClient, A as ArgsOf, R as ReturnOf, P as Preloaded } from "./lunora-client.d-pw-9sLl0.mjs";
2
2
  /**
3
3
  * Run a query once on the server (during SSR) and capture its result in a
4
4
  * serializable {@link Preloaded} token. Embed the token in the rendered HTML and
@@ -1,4 +1,4 @@
1
- import { F as FunctionReference, L as LunoraClient, A as ArgsOf, R as ReturnOf, P as Preloaded } from "./lunora-client.d-BYkEjCEJ.js";
1
+ import { F as FunctionReference, L as LunoraClient, A as ArgsOf, R as ReturnOf, P as Preloaded } from "./lunora-client.d-pw-9sLl0.js";
2
2
  /**
3
3
  * Run a query once on the server (during SSR) and capture its result in a
4
4
  * serializable {@link Preloaded} token. Embed the token in the rendered HTML and
@@ -37,32 +37,4 @@ const stableStringify = (value) => {
37
37
  return `{${parts.join(",")}}`;
38
38
  };
39
39
 
40
- class SubscriptionRegistry {
41
- static key(functionPath, args, shardKey) {
42
- return `${functionPath}::${stableStringify(args)}::${shardKey ?? ""}`;
43
- }
44
- byKey = /* @__PURE__ */ new Map();
45
- byId = /* @__PURE__ */ new Map();
46
- get(key) {
47
- return this.byKey.get(key);
48
- }
49
- getById(id) {
50
- return this.byId.get(id);
51
- }
52
- add(state) {
53
- this.byKey.set(SubscriptionRegistry.key(state.fn.__lunoraRef, state.args, state.shardKey), state);
54
- this.byId.set(state.id, state);
55
- }
56
- remove(state) {
57
- const key = SubscriptionRegistry.key(state.fn.__lunoraRef, state.args, state.shardKey);
58
- if (this.byKey.get(key) === state) {
59
- this.byKey.delete(key);
60
- }
61
- this.byId.delete(state.id);
62
- }
63
- all() {
64
- return [...this.byKey.values()];
65
- }
66
- }
67
-
68
- export { SubscriptionRegistry as S, stableStringify as s };
40
+ export { stableStringify as s };
@@ -1,5 +1,5 @@
1
- import { S as SubscriptionError, F as FunctionReference, A as ArgsOf, R as ReturnOf, L as LunoraClient, a as Unsubscribe } from "../packem_shared/lunora-client.d-BYkEjCEJ.mjs";
2
- export type { b as SubscriptionErrorCallback } from "../packem_shared/lunora-client.d-BYkEjCEJ.mjs";
1
+ import { S as SubscriptionError, F as FunctionReference, A as ArgsOf, R as ReturnOf, L as LunoraClient, a as Unsubscribe } from "../packem_shared/lunora-client.d-pw-9sLl0.mjs";
2
+ export type { b as SubscriptionErrorCallback } from "../packem_shared/lunora-client.d-pw-9sLl0.mjs";
3
3
  import '@lunora/runtime';
4
4
  /**
5
5
  * The sentinel a framework adapter resolves its reactive args to when it wants
@@ -1,5 +1,5 @@
1
- import { S as SubscriptionError, F as FunctionReference, A as ArgsOf, R as ReturnOf, L as LunoraClient, a as Unsubscribe } from "../packem_shared/lunora-client.d-BYkEjCEJ.js";
2
- export type { b as SubscriptionErrorCallback } from "../packem_shared/lunora-client.d-BYkEjCEJ.js";
1
+ import { S as SubscriptionError, F as FunctionReference, A as ArgsOf, R as ReturnOf, L as LunoraClient, a as Unsubscribe } from "../packem_shared/lunora-client.d-pw-9sLl0.js";
2
+ export type { b as SubscriptionErrorCallback } from "../packem_shared/lunora-client.d-pw-9sLl0.js";
3
3
  import '@lunora/runtime';
4
4
  /**
5
5
  * The sentinel a framework adapter resolves its reactive args to when it wants
@@ -1,6 +1,6 @@
1
- import { P as Preloaded, L as LunoraClient } from "../packem_shared/lunora-client.d-BYkEjCEJ.mjs";
2
- export type { A as ArgsOf, F as FunctionReference, R as ReturnOf } from "../packem_shared/lunora-client.d-BYkEjCEJ.mjs";
3
- export { p as preloadQuery, a as preloadedQueryResult } from "../packem_shared/preload.d-DrfuisCE.mjs";
1
+ import { P as Preloaded, L as LunoraClient } from "../packem_shared/lunora-client.d-pw-9sLl0.mjs";
2
+ export type { A as ArgsOf, F as FunctionReference, R as ReturnOf } from "../packem_shared/lunora-client.d-pw-9sLl0.mjs";
3
+ export { p as preloadQuery, a as preloadedQueryResult } from "../packem_shared/preload.d-6ME5ubgq.mjs";
4
4
  import '@lunora/runtime';
5
5
  /**
6
6
  * Structural shape of a better-auth `getSession` call's resolved value.
@@ -1,6 +1,6 @@
1
- import { P as Preloaded, L as LunoraClient } from "../packem_shared/lunora-client.d-BYkEjCEJ.js";
2
- export type { A as ArgsOf, F as FunctionReference, R as ReturnOf } from "../packem_shared/lunora-client.d-BYkEjCEJ.js";
3
- export { p as preloadQuery, a as preloadedQueryResult } from "../packem_shared/preload.d-B-vyHnml.js";
1
+ import { P as Preloaded, L as LunoraClient } from "../packem_shared/lunora-client.d-pw-9sLl0.js";
2
+ export type { A as ArgsOf, F as FunctionReference, R as ReturnOf } from "../packem_shared/lunora-client.d-pw-9sLl0.js";
3
+ export { p as preloadQuery, a as preloadedQueryResult } from "../packem_shared/preload.d-BkQr-3Vh.js";
4
4
  import '@lunora/runtime';
5
5
  /**
6
6
  * Structural shape of a better-auth `getSession` call's resolved value.
@@ -1,4 +1,4 @@
1
1
  export { getServerSession } from '../packem_shared/getServerSession-8jXewqxd.mjs';
2
2
  export { deserializePreloaded, serializePreloaded } from '../packem_shared/deserializePreloaded-C0eJTY_W.mjs';
3
- export { createServerClient } from '../packem_shared/createServerClient-DF-3mLmb.mjs';
3
+ export { createServerClient } from '../packem_shared/createServerClient-Dxemst5C.mjs';
4
4
  export { preloadQuery, preloadedQueryResult } from '../packem_shared/preloadQuery-lobFkD2Z.mjs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/client",
3
- "version": "1.0.0-alpha.21",
3
+ "version": "1.0.0-alpha.22",
4
4
  "description": "Lunora browser SDK: WebSocket transport, optimistic updates, and an offline mutation queue",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -1 +0,0 @@
1
- export { S as SubscriptionRegistry } from './subscription-BjynOXCU.mjs';
@@ -1,2 +0,0 @@
1
- export { c as createLocalStore } from './local-store-BveBeFEo.mjs';
2
- import './subscription-BjynOXCU.mjs';