Skip to content

Commit bba5ee7

Browse files
authored
Merge branch 'main' into fix/no-flush-on-init
2 parents c43a5fe + 67c840f commit bba5ee7

89 files changed

Lines changed: 1158 additions & 215 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.changeset/clean-query-ownership.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

.changeset/hot-bats-camp.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@tanstack/powersync-db-collection': patch
3+
---
4+
5+
Fix: applyTransaction hangs forever when a transaction mixes delete+insert on one collection for a same-millisecond tie.

.changeset/young-cats-initialize.md

Lines changed: 0 additions & 7 deletions
This file was deleted.

docs/collections/query-collection.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,57 @@ Some TanStack Query fields are owned or reinterpreted by Query Collection and ar
241241

242242
`placeholderData` is intentionally unsupported. TanStack Query treats placeholder data as observer-local presentation state rather than cached Query data. Materializing it would expose temporary UI data as collection-wide normalized rows. Render placeholders in the consuming UI instead.
243243

244+
### Request Cancellation with `QueryFunctionContext.signal`
245+
246+
TanStack Query passes an `AbortSignal` to `queryFn` through the query function
247+
context. Forward `ctx.signal` to `fetch` or another abortable client to make the
248+
request cancellable:
249+
250+
```typescript
251+
const todosCollection = createCollection(
252+
queryCollectionOptions({
253+
queryKey: ["todos"],
254+
queryFn: async (ctx) => {
255+
const response = await fetch("/api/todos", {
256+
signal: ctx.signal,
257+
})
258+
259+
if (!response.ok) {
260+
throw new Error("Failed to fetch todos")
261+
}
262+
263+
return response.json() as Promise<Array<Todo>>
264+
},
265+
queryClient,
266+
getKey: (todo) => todo.id,
267+
}),
268+
)
269+
```
270+
271+
Explicit collection cleanup cancels each exact Query key the collection is
272+
currently tracking before removing it from the Query cache:
273+
274+
```typescript
275+
await todosCollection.cleanup()
276+
```
277+
278+
The underlying request is aborted only when its client consumes `ctx.signal`.
279+
A client that ignores the signal may continue its request even though the
280+
collection has been cleaned up.
281+
282+
An unloaded on-demand subset is no longer tracked. A later explicit collection
283+
cleanup does not revisit its Query key.
284+
285+
Query cache entries are shared within a `QueryClient`. Explicit cleanup can
286+
affect other consumers using the same exact Query keys.
287+
288+
On-demand subset unloading does not explicitly call
289+
`queryClient.cancelQueries()`. It removes the subset's Query observer. If this
290+
was the final observer and the query function consumed `ctx.signal`, TanStack
291+
Query aborts the request. If the signal was ignored, or another observer still
292+
uses the same exact Query key, the request may finish and remain cached until
293+
`gcTime`.
294+
244295
### Using with `queryOptions(...)`
245296

246297
If your app already uses TanStack Query's `queryOptions` helper (e.g. from `@tanstack/react-query`), you can spread compatible top-level options into `queryCollectionOptions`. Note that `queryFn` must be explicitly provided since query collections require it both in types and at runtime, and Query Collection's `select` option is for row extraction rather than TanStack Query observer-level selection:

docs/reference/query-db-collection/classes/DeleteOperationItemNotFoundError.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ title: DeleteOperationItemNotFoundError
55

66
# Class: DeleteOperationItemNotFoundError
77

8-
Defined in: [packages/query-db-collection/src/errors.ts:76](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/errors.ts#L76)
8+
Defined in: [packages/query-db-collection/src/errors.ts:85](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/errors.ts#L85)
99

1010
## Extends
1111

@@ -19,7 +19,7 @@ Defined in: [packages/query-db-collection/src/errors.ts:76](https://github.com/T
1919
new DeleteOperationItemNotFoundError(key): DeleteOperationItemNotFoundError;
2020
```
2121

22-
Defined in: [packages/query-db-collection/src/errors.ts:77](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/errors.ts#L77)
22+
Defined in: [packages/query-db-collection/src/errors.ts:86](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/errors.ts#L86)
2323

2424
#### Parameters
2525

docs/reference/query-db-collection/classes/DuplicateKeyInBatchError.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ title: DuplicateKeyInBatchError
55

66
# Class: DuplicateKeyInBatchError
77

8-
Defined in: [packages/query-db-collection/src/errors.ts:62](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/errors.ts#L62)
8+
Defined in: [packages/query-db-collection/src/errors.ts:71](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/errors.ts#L71)
99

1010
## Extends
1111

@@ -19,7 +19,7 @@ Defined in: [packages/query-db-collection/src/errors.ts:62](https://github.com/T
1919
new DuplicateKeyInBatchError(key): DuplicateKeyInBatchError;
2020
```
2121

22-
Defined in: [packages/query-db-collection/src/errors.ts:63](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/errors.ts#L63)
22+
Defined in: [packages/query-db-collection/src/errors.ts:72](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/errors.ts#L72)
2323

2424
#### Parameters
2525

Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
---
2+
id: InitialDataInOnDemandModeError
3+
title: InitialDataInOnDemandModeError
4+
---
5+
6+
# Class: InitialDataInOnDemandModeError
7+
8+
Defined in: [packages/query-db-collection/src/errors.ts:39](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/errors.ts#L39)
9+
10+
## Extends
11+
12+
- [`QueryCollectionError`](QueryCollectionError.md)
13+
14+
## Constructors
15+
16+
### Constructor
17+
18+
```ts
19+
new InitialDataInOnDemandModeError(): InitialDataInOnDemandModeError;
20+
```
21+
22+
Defined in: [packages/query-db-collection/src/errors.ts:40](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/errors.ts#L40)
23+
24+
#### Returns
25+
26+
`InitialDataInOnDemandModeError`
27+
28+
#### Overrides
29+
30+
[`QueryCollectionError`](QueryCollectionError.md).[`constructor`](QueryCollectionError.md#constructor)
31+
32+
## Properties
33+
34+
### cause?
35+
36+
```ts
37+
optional cause: unknown;
38+
```
39+
40+
Defined in: node\_modules/.pnpm/typescript@5.9.3/node\_modules/typescript/lib/lib.es2022.error.d.ts:26
41+
42+
#### Inherited from
43+
44+
[`QueryCollectionError`](QueryCollectionError.md).[`cause`](QueryCollectionError.md#cause)
45+
46+
***
47+
48+
### message
49+
50+
```ts
51+
message: string;
52+
```
53+
54+
Defined in: node\_modules/.pnpm/typescript@5.9.3/node\_modules/typescript/lib/lib.es5.d.ts:1077
55+
56+
#### Inherited from
57+
58+
[`QueryCollectionError`](QueryCollectionError.md).[`message`](QueryCollectionError.md#message)
59+
60+
***
61+
62+
### name
63+
64+
```ts
65+
name: string;
66+
```
67+
68+
Defined in: node\_modules/.pnpm/typescript@5.9.3/node\_modules/typescript/lib/lib.es5.d.ts:1076
69+
70+
#### Inherited from
71+
72+
[`QueryCollectionError`](QueryCollectionError.md).[`name`](QueryCollectionError.md#name)
73+
74+
***
75+
76+
### stack?
77+
78+
```ts
79+
optional stack: string;
80+
```
81+
82+
Defined in: node\_modules/.pnpm/typescript@5.9.3/node\_modules/typescript/lib/lib.es5.d.ts:1078
83+
84+
#### Inherited from
85+
86+
[`QueryCollectionError`](QueryCollectionError.md).[`stack`](QueryCollectionError.md#stack)
87+
88+
***
89+
90+
### stackTraceLimit
91+
92+
```ts
93+
static stackTraceLimit: number;
94+
```
95+
96+
Defined in: node\_modules/.pnpm/@types+node@25.2.2/node\_modules/@types/node/globals.d.ts:67
97+
98+
The `Error.stackTraceLimit` property specifies the number of stack frames
99+
collected by a stack trace (whether generated by `new Error().stack` or
100+
`Error.captureStackTrace(obj)`).
101+
102+
The default value is `10` but may be set to any valid JavaScript number. Changes
103+
will affect any stack trace captured _after_ the value has been changed.
104+
105+
If set to a non-number value, or set to a negative number, stack traces will
106+
not capture any frames.
107+
108+
#### Inherited from
109+
110+
[`QueryCollectionError`](QueryCollectionError.md).[`stackTraceLimit`](QueryCollectionError.md#stacktracelimit)
111+
112+
## Methods
113+
114+
### captureStackTrace()
115+
116+
```ts
117+
static captureStackTrace(targetObject, constructorOpt?): void;
118+
```
119+
120+
Defined in: node\_modules/.pnpm/@types+node@25.2.2/node\_modules/@types/node/globals.d.ts:51
121+
122+
Creates a `.stack` property on `targetObject`, which when accessed returns
123+
a string representing the location in the code at which
124+
`Error.captureStackTrace()` was called.
125+
126+
```js
127+
const myObject = {};
128+
Error.captureStackTrace(myObject);
129+
myObject.stack; // Similar to `new Error().stack`
130+
```
131+
132+
The first line of the trace will be prefixed with
133+
`${myObject.name}: ${myObject.message}`.
134+
135+
The optional `constructorOpt` argument accepts a function. If given, all frames
136+
above `constructorOpt`, including `constructorOpt`, will be omitted from the
137+
generated stack trace.
138+
139+
The `constructorOpt` argument is useful for hiding implementation
140+
details of error generation from the user. For instance:
141+
142+
```js
143+
function a() {
144+
b();
145+
}
146+
147+
function b() {
148+
c();
149+
}
150+
151+
function c() {
152+
// Create an error without stack trace to avoid calculating the stack trace twice.
153+
const { stackTraceLimit } = Error;
154+
Error.stackTraceLimit = 0;
155+
const error = new Error();
156+
Error.stackTraceLimit = stackTraceLimit;
157+
158+
// Capture the stack trace above function b
159+
Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
160+
throw error;
161+
}
162+
163+
a();
164+
```
165+
166+
#### Parameters
167+
168+
##### targetObject
169+
170+
`object`
171+
172+
##### constructorOpt?
173+
174+
`Function`
175+
176+
#### Returns
177+
178+
`void`
179+
180+
#### Inherited from
181+
182+
[`QueryCollectionError`](QueryCollectionError.md).[`captureStackTrace`](QueryCollectionError.md#capturestacktrace)
183+
184+
***
185+
186+
### prepareStackTrace()
187+
188+
```ts
189+
static prepareStackTrace(err, stackTraces): any;
190+
```
191+
192+
Defined in: node\_modules/.pnpm/@types+node@25.2.2/node\_modules/@types/node/globals.d.ts:55
193+
194+
#### Parameters
195+
196+
##### err
197+
198+
`Error`
199+
200+
##### stackTraces
201+
202+
`CallSite`[]
203+
204+
#### Returns
205+
206+
`any`
207+
208+
#### See
209+
210+
https://v8.dev/docs/stack-trace-api#customizing-stack-traces
211+
212+
#### Inherited from
213+
214+
[`QueryCollectionError`](QueryCollectionError.md).[`prepareStackTrace`](QueryCollectionError.md#preparestacktrace)

docs/reference/query-db-collection/classes/InvalidItemStructureError.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ title: InvalidItemStructureError
55

66
# Class: InvalidItemStructureError
77

8-
Defined in: [packages/query-db-collection/src/errors.ts:48](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/errors.ts#L48)
8+
Defined in: [packages/query-db-collection/src/errors.ts:57](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/errors.ts#L57)
99

1010
## Extends
1111

@@ -19,7 +19,7 @@ Defined in: [packages/query-db-collection/src/errors.ts:48](https://github.com/T
1919
new InvalidItemStructureError(message): InvalidItemStructureError;
2020
```
2121

22-
Defined in: [packages/query-db-collection/src/errors.ts:49](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/errors.ts#L49)
22+
Defined in: [packages/query-db-collection/src/errors.ts:58](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/errors.ts#L58)
2323

2424
#### Parameters
2525

docs/reference/query-db-collection/classes/InvalidSyncOperationError.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ title: InvalidSyncOperationError
55

66
# Class: InvalidSyncOperationError
77

8-
Defined in: [packages/query-db-collection/src/errors.ts:83](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/errors.ts#L83)
8+
Defined in: [packages/query-db-collection/src/errors.ts:92](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/errors.ts#L92)
99

1010
## Extends
1111

@@ -19,7 +19,7 @@ Defined in: [packages/query-db-collection/src/errors.ts:83](https://github.com/T
1919
new InvalidSyncOperationError(message): InvalidSyncOperationError;
2020
```
2121

22-
Defined in: [packages/query-db-collection/src/errors.ts:84](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/errors.ts#L84)
22+
Defined in: [packages/query-db-collection/src/errors.ts:93](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/errors.ts#L93)
2323

2424
#### Parameters
2525

docs/reference/query-db-collection/classes/ItemNotFoundError.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ title: ItemNotFoundError
55

66
# Class: ItemNotFoundError
77

8-
Defined in: [packages/query-db-collection/src/errors.ts:55](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/errors.ts#L55)
8+
Defined in: [packages/query-db-collection/src/errors.ts:64](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/errors.ts#L64)
99

1010
## Extends
1111

@@ -19,7 +19,7 @@ Defined in: [packages/query-db-collection/src/errors.ts:55](https://github.com/T
1919
new ItemNotFoundError(key): ItemNotFoundError;
2020
```
2121

22-
Defined in: [packages/query-db-collection/src/errors.ts:56](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/errors.ts#L56)
22+
Defined in: [packages/query-db-collection/src/errors.ts:65](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/errors.ts#L65)
2323

2424
#### Parameters
2525

0 commit comments

Comments
 (0)