@lunora/solid 1.0.0-alpha.21 → 1.0.0-alpha.23

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/dist/index.mjs CHANGED
@@ -1,13 +1,13 @@
1
1
  export { LunoraContext, useLunora } from './packem_shared/LunoraContext-C59PzHhN.mjs';
2
2
  export { AuthLoading, Authenticated, Unauthenticated, createAuth } from './packem_shared/AuthLoading-u5QJoV-J.mjs';
3
3
  export { default as createConnectionStatus } from './packem_shared/createConnectionStatus-1poqwqR9.mjs';
4
- export { createFlag, createFlags } from './packem_shared/createFlag-DTGaIdMo.mjs';
4
+ export { createFlag, createFlags } from './packem_shared/createFlag-Bu9YfzcJ.mjs';
5
5
  export { createMutation, createMutationForClient } from './packem_shared/createMutation-LkrbhItI.mjs';
6
6
  export { createMutator } from './packem_shared/createMutator-foSnPJPt.mjs';
7
- export { createInfiniteQuery, createPaginatedQuery } from './packem_shared/createInfiniteQuery-q2r4PSqD.mjs';
8
- export { createPresence } from './packem_shared/createPresence-DMiDP353.mjs';
7
+ export { createInfiniteQuery, createPaginatedQuery } from './packem_shared/createInfiniteQuery-Dy9k7Px2.mjs';
8
+ export { createPresence } from './packem_shared/createPresence-DM2cVkiG.mjs';
9
9
  export { createQuery } from './packem_shared/createQuery-BUldvZXj.mjs';
10
10
  export { createRateLimit } from './packem_shared/createRateLimit-BA2f8XyF.mjs';
11
- export { createSubscription } from './packem_shared/createSubscription-C_ed4Rov.mjs';
11
+ export { createSubscription } from './packem_shared/createSubscription-D3HbChGe.mjs';
12
12
  export { default as hydratePreloaded } from './packem_shared/hydratePreloaded-CWny5-2J.mjs';
13
13
  export { LunoraProvider } from './packem_shared/LunoraProvider-CzB3zGhy.mjs';
@@ -1,43 +1,7 @@
1
1
  import { createSignal, createEffect, on, onCleanup } from 'solid-js';
2
+ import { s as stableStringify } from './stable-key-CGp4e2Ux.mjs';
2
3
  import { useLunora } from './LunoraContext-C59PzHhN.mjs';
3
4
 
4
- const compareKeys = (a, b) => {
5
- if (a < b) {
6
- return -1;
7
- }
8
- return a > b ? 1 : 0;
9
- };
10
- const stableStringify = (value) => {
11
- if (value === void 0) {
12
- return "null";
13
- }
14
- if (typeof value === "bigint") {
15
- throw new TypeError("stableStringify: cannot use a bigint in a cache key (query/subscription/shape args) — pass it as a string");
16
- }
17
- if (value === null || typeof value !== "object") {
18
- return JSON.stringify(value);
19
- }
20
- if (Array.isArray(value)) {
21
- return `[${value.map((item) => stableStringify(item)).join(",")}]`;
22
- }
23
- const proto = Object.getPrototypeOf(value);
24
- if (proto !== null && proto !== Object.prototype) {
25
- const name = value.constructor?.name ?? "value";
26
- throw new TypeError(`stableStringify: cannot use a ${name} in a cache key (query/subscription/shape args) — only plain objects, arrays, and JSON primitives are supported`);
27
- }
28
- const record = value;
29
- const keys = Object.keys(record).toSorted(compareKeys);
30
- const parts = [];
31
- for (const key of keys) {
32
- const raw = record[key];
33
- if (raw === void 0) {
34
- continue;
35
- }
36
- parts.push(`${JSON.stringify(key)}:${stableStringify(raw)}`);
37
- }
38
- return `{${parts.join(",")}}`;
39
- };
40
-
41
5
  const FLAGS_EVAL_PATH = "__lunora_flags__:eval";
42
6
  const flagKind = (value) => {
43
7
  const kind = typeof value;
@@ -1,5 +1,6 @@
1
1
  import { initialPages, derivePaginationStatus, rebalance, applyLoadMore } from '@lunora/client/pagination';
2
2
  import { createMemo, createSignal, createEffect, on, onCleanup } from 'solid-js';
3
+ import { s as stableStringify } from './stable-key-CGp4e2Ux.mjs';
3
4
  import { useLunora } from './LunoraContext-C59PzHhN.mjs';
4
5
 
5
6
  const buildPageArgs = (page, baseArgs) => {
@@ -12,7 +13,7 @@ const buildPageArgs = (page, baseArgs) => {
12
13
  }
13
14
  };
14
15
  };
15
- const buildPageKey = (functionPath, pageArgs) => `${functionPath}::${JSON.stringify(pageArgs)}`;
16
+ const buildPageKey = (functionPath, pageArgs) => `${functionPath}::${stableStringify(pageArgs)}`;
16
17
  const createPaginatedCore = (function_, args, options) => {
17
18
  const client = useLunora();
18
19
  const {
@@ -32,6 +33,22 @@ const createPaginatedCore = (function_, args, options) => {
32
33
  });
33
34
  setPageResults(updated);
34
35
  };
36
+ const migrateResultsForRebalance = (oldPages, newPages, baseArgs) => {
37
+ const keyOf = (page) => buildPageKey(function_["__lunoraRef"], buildPageArgs(page, baseArgs));
38
+ for (const newPage of newPages) {
39
+ const newKey = keyOf(newPage);
40
+ if (resultsByKey.has(newKey)) {
41
+ continue;
42
+ }
43
+ const donor = oldPages.find((oldPage) => oldPage.lower === newPage.lower);
44
+ if (donor) {
45
+ const carried = resultsByKey.get(keyOf(donor));
46
+ if (carried) {
47
+ resultsByKey.set(newKey, carried);
48
+ }
49
+ }
50
+ }
51
+ };
35
52
  const syncSubscriptions = (currentPages, baseArgs) => {
36
53
  const wantedKeys = /* @__PURE__ */ new Set();
37
54
  for (const page of currentPages) {
@@ -42,6 +59,7 @@ const createPaginatedCore = (function_, args, options) => {
42
59
  unsub();
43
60
  activeSubs.delete(key);
44
61
  pendingPageKeys.delete(key);
62
+ resultsByKey.delete(key);
45
63
  }
46
64
  }
47
65
  for (const page of currentPages) {
@@ -60,8 +78,10 @@ const createPaginatedCore = (function_, args, options) => {
60
78
  }
61
79
  rebuildPageResults(pages(), currentArgs);
62
80
  if (pendingPageKeys.size === 0) {
63
- const next = rebalance(pages(), pageResults());
81
+ const latestPages = pages();
82
+ const next = rebalance(latestPages, pageResults());
64
83
  if (next) {
84
+ migrateResultsForRebalance(latestPages, next, currentArgs);
65
85
  setPages(next);
66
86
  }
67
87
  }
@@ -1,12 +1,19 @@
1
1
  import { createSignal, onMount, onCleanup } from 'solid-js';
2
2
  import { useLunora } from './LunoraContext-C59PzHhN.mjs';
3
3
 
4
- const makeSessionId = () => {
5
- if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
6
- return crypto.randomUUID();
4
+ const randomSessionId = (prefix = "sess") => {
5
+ if (typeof crypto !== "undefined") {
6
+ if (typeof crypto.randomUUID === "function") {
7
+ return crypto.randomUUID();
8
+ }
9
+ if (typeof crypto.getRandomValues === "function") {
10
+ const bytes = crypto.getRandomValues(new Uint8Array(16));
11
+ return `${prefix}-${Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("")}`;
12
+ }
7
13
  }
8
- return `sess-${Math.random().toString(36).slice(2)}-${String(Date.now())}`;
14
+ return `${prefix}-${Date.now().toString(36)}`;
9
15
  };
16
+
10
17
  const DEFAULT_INTERVAL_MS = 1e4;
11
18
  const createPresence = (roomId, options) => {
12
19
  const client = useLunora();
@@ -16,7 +23,7 @@ const createPresence = (roomId, options) => {
16
23
  listPresent,
17
24
  shardKey
18
25
  } = options;
19
- const sessionId = options.sessionId ?? makeSessionId();
26
+ const sessionId = options.sessionId ?? randomSessionId();
20
27
  const [present, setPresent] = createSignal(void 0);
21
28
  let latestData = options.data;
22
29
  const sendHeartbeat = () => {
@@ -1,4 +1,5 @@
1
1
  import { createQuerySubscription } from '@lunora/client/query';
2
+ import { LunoraError } from '@lunora/errors';
2
3
  import { createSignal, createEffect, on, onCleanup } from 'solid-js';
3
4
  import { useLunora } from './LunoraContext-C59PzHhN.mjs';
4
5
 
@@ -19,7 +20,8 @@ const createSubscription = (function_, args, options = {}) => {
19
20
  setError(() => void 0);
20
21
  },
21
22
  onError: (subscriptionError) => {
22
- setError(() => new Error(subscriptionError.message));
23
+ const normalized = subscriptionError.code ? new LunoraError(subscriptionError.code, subscriptionError.message) : new Error(subscriptionError.message);
24
+ setError(() => normalized);
23
25
  setData(() => void 0);
24
26
  },
25
27
  onReset: () => {
@@ -0,0 +1,38 @@
1
+ const compareKeys = (a, b) => {
2
+ if (a < b) {
3
+ return -1;
4
+ }
5
+ return a > b ? 1 : 0;
6
+ };
7
+ const stableStringify = (value) => {
8
+ if (value === void 0) {
9
+ return "null";
10
+ }
11
+ if (typeof value === "bigint") {
12
+ throw new TypeError("stableStringify: cannot use a bigint in a cache key (query/subscription/shape args) — pass it as a string");
13
+ }
14
+ if (value === null || typeof value !== "object") {
15
+ return JSON.stringify(value);
16
+ }
17
+ if (Array.isArray(value)) {
18
+ return `[${value.map((item) => stableStringify(item)).join(",")}]`;
19
+ }
20
+ const proto = Object.getPrototypeOf(value);
21
+ if (proto !== null && proto !== Object.prototype) {
22
+ const name = value.constructor?.name ?? "value";
23
+ throw new TypeError(`stableStringify: cannot use a ${name} in a cache key (query/subscription/shape args) — only plain objects, arrays, and JSON primitives are supported`);
24
+ }
25
+ const record = value;
26
+ const keys = Object.keys(record).toSorted(compareKeys);
27
+ const parts = [];
28
+ for (const key of keys) {
29
+ const raw = record[key];
30
+ if (raw === void 0) {
31
+ continue;
32
+ }
33
+ parts.push(`${JSON.stringify(key)}:${stableStringify(raw)}`);
34
+ }
35
+ return `{${parts.join(",")}}`;
36
+ };
37
+
38
+ export { stableStringify as s };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/solid",
3
- "version": "1.0.0-alpha.21",
3
+ "version": "1.0.0-alpha.23",
4
4
  "description": "SolidJS adapter for Lunora — live queries, optimistic mutations, and reactive loaders",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -50,9 +50,9 @@
50
50
  "access": "public"
51
51
  },
52
52
  "dependencies": {
53
- "@lunora/client": "1.0.0-alpha.19",
54
- "@lunora/errors": "1.0.0-alpha.2",
55
- "@lunora/ratelimit": "1.0.0-alpha.5"
53
+ "@lunora/client": "1.0.0-alpha.21",
54
+ "@lunora/errors": "1.0.0-alpha.4",
55
+ "@lunora/ratelimit": "1.0.0-alpha.7"
56
56
  },
57
57
  "peerDependencies": {
58
58
  "solid-js": "^1.9.0"