@tanstack/svelte-db 0.5.3 → 0.5.5

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.
@@ -4,6 +4,12 @@ import { untrack } from 'svelte';
4
4
  import { SvelteMap } from 'svelte/reactivity';
5
5
  import { BaseQueryBuilder, UnhashableQueryIRError, createLiveQueryCollection, createLiveQueryObserver, getLiveQueryHash, getPublicCollection, getStableValueHash, isCollection, isSingleResultCollection, prepareLiveQueryValue, resolveLiveQueryValue, } from '@tanstack/db';
6
6
  import { useOptionalDbClient } from './db-context.js';
7
+ /** Copy a snapshot's ordered rows; a single-result query's `data` is one row. */
8
+ function snapshotRows(data) {
9
+ if (Array.isArray(data))
10
+ return [...data];
11
+ return data === undefined ? [] : [data];
12
+ }
7
13
  function toValue(value) {
8
14
  if (typeof value === `function`) {
9
15
  return value();
@@ -118,7 +124,7 @@ export function useLiveQuery(configOrQueryOrCollection, deps = []) {
118
124
  // Reactive state that gets updated granularly through change events
119
125
  const state = new SvelteMap(initialSnapshot.state ?? []);
120
126
  // Reactive data array that maintains sorted order
121
- let internalData = $state(Array.from(initialSnapshot.state?.values() ?? []));
127
+ let internalData = $state(snapshotRows(initialSnapshot.data));
122
128
  // Track collection status reactively
123
129
  let status = $state(initialSnapshot.status);
124
130
  let persistedStatus = $state(initialSnapshot.persistedStatus);
@@ -148,7 +154,7 @@ export function useLiveQuery(configOrQueryOrCollection, deps = []) {
148
154
  state.set(key, value);
149
155
  }
150
156
  }
151
- internalData = Array.from(snapshot.state?.values() ?? []);
157
+ internalData = snapshotRows(snapshot.data);
152
158
  });
153
159
  };
154
160
  // Watch for collection changes and subscribe to updates
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/svelte-db",
3
- "version": "0.5.3",
3
+ "version": "0.5.5",
4
4
  "description": "Svelte integration for @tanstack/db",
5
5
  "author": "Kyle Mathews",
6
6
  "license": "MIT",
@@ -35,7 +35,7 @@
35
35
  "skills"
36
36
  ],
37
37
  "dependencies": {
38
- "@tanstack/db": "0.11.3"
38
+ "@tanstack/db": "0.12.1"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "svelte": "^5.0.0"