Skip to content
Source
Sign inSign up
TanStack/db
Open History to see the last commit

SyncConfig.md

237 lines5.7 KB

1---
2id: SyncConfig
3title: SyncConfig
4---
5​
6Defined in: [packages/db/src/types.ts:446](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L446)
7​
8## Type Parameters
9​
10### T
11​
12`T` *extends* `object` = `Record`\<`string`, `unknown`\>
13​
14### TKey
15​
16`TKey` *extends* `string` \| `number` = `string` \| `number`
17​
18## Properties
19​
20### exportSyncMeta()?
21​
22```ts
23optional exportSyncMeta: () => unknown;
24```
25​
26Defined in: [packages/db/src/types.ts:532](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L532)
27​
28Export adapter-specific metadata that lets hydration/persistence resume sync.
29The payload shape is owned by the adapter.
30​
31#### Returns
32​
33`unknown`
34​
35***
36​
37### getSyncMetadata()?
38​
39```ts
40optional getSyncMetadata: () => Record<string, unknown>;
41```
42​
43Defined in: [packages/db/src/types.ts:526](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L526)
44​
45Get the sync metadata for insert operations
46​
47#### Returns
48​
49`Record`\<`string`, `unknown`\>
50​
51Record containing relation information
52​
53***
54​
55### importSyncMeta()?
56​
57```ts
58optional importSyncMeta: (meta) => void;
59```
60​
61Defined in: [packages/db/src/types.ts:537](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L537)
62​
63Import adapter-specific metadata produced by exportSyncMeta.
64​
65#### Parameters
66​
67##### meta
68​
69`unknown`
70​
71#### Returns
72​
73`void`
74​
75***
76​
77### mergeSyncMeta()?
78​
79```ts
80optional mergeSyncMeta: (current, incoming) => unknown;
81```
82​
83Defined in: [packages/db/src/types.ts:542](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L542)
84​
85Merge two adapter-specific metadata payloads during hydration.
86​
87#### Parameters
88​
89##### current
90​
91`unknown`
92​
93##### incoming
94​
95`unknown`
96​
97#### Returns
98​
99`unknown`
100​
101***
102​
103### rowUpdateMode?
104​
105```ts
106optional rowUpdateMode: "full" | "partial";
107```
108​
109Defined in: [packages/db/src/types.ts:551](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L551)
110​
111The row update mode used to sync to the collection.
112​
113#### Default
114​
115`partial`
116​
117#### Description
118​
119- `partial`: Updates contain only the changes to the row.
120- `full`: Updates contain the entire row.
121​
122***
123​
124### sync()
125​
126```ts
127sync: (params) =>
128 | void
129 | CleanupFn
130 | SyncConfigRes;
131```
132​
133Defined in: [packages/db/src/types.ts:450](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L450)
134​
135#### Parameters
136​
137##### params
138​
139###### begin
140​
141(`options?`) => `void`
142​
143Begin a new sync transaction. Its writes apply on the rows the
144Collection holds, also during a reload. `snapshot: true` declares that
145the transaction carries every row: its commit replaces every synced
146row, as `truncate({ markReady: false })` at its start does. A reload's
147new run replaces the kept rows only with a snapshot or `truncate()`.
148​
149###### collection
150​
151[`Collection`](Collection.md)\<`T`, `TKey`, `any`, `any`, `any`\>
152​
153###### commit
154​
155(`signal?`) => [`SyncAppliedReceipt`](../type-aliases/SyncAppliedReceipt.md)
156​
157Commit the active sync transaction in FIFO order. Core accepts it at
158once, and an accepted transaction always applies. Returns `true` when
159its writes are visible, or a receipt that resolves when they become
160visible. While an optimistic transaction is persisting, it becomes
161visible when that transaction settles, together with the drop of its
162optimistic state. A signal that is already aborted abandons the
163transaction before acceptance, and the receipt rejects with an error
164named `AbortError`. Aborting after acceptance has no effect.
165​
166###### fail
167​
168(`error`) => `void`
169​
170The sync adapter stopped. Before the first ready the status becomes
171`error` and `preload()` rejects with `error`. After it, the rows stay, the
172status stays `ready`, and the node's `error` holds the cause until a
173reload. A second `fail()` in the same sync run does nothing.
174While the sync adapter retries, call nothing or `reportError()`.
175​
176###### invalidateLoadedSubsets
177​
178() => `void`
179​
180Report that rows this adapter serves for loaded subsets may have shifted
181between served pages, after a refetch that the adapter started on its
182own has applied. Each ordered live query then re-establishes its window
183with a bounded repair from the start of its order. Calls in one turn are
184coalesced. Do not call it for results that answer a `loadSubset` call.
185​
186###### markReady
187​
188() => `void`
189​
190Signal that the sync run's initial data is available. During a reload
191it completes the reload and keeps the rows unless a snapshot replaced
192them. A second call in the run, or one after `fail()`, does nothing.
193​
194###### metadata?
195​
196[`SyncMetadataApi`](SyncMetadataApi.md)\<`TKey`\>
197​
198###### reportError
199​
200(`error`) => `void`
201​
202Report a problem after the first ready while the sync adapter keeps
203trying. It shows as the node's `failureReason` and adds a failure to its
204`errors`; the status and rows do not change. One error value is one
205failure: reporting a value already listed changes nothing, and that
206failure keeps its place and its `at`. Throws before the first ready and
207after `fail()`.
208​
209###### reportHealthy
210​
211(`error?`) => `void`
212​
213Sync works again. With no `error`, clears the `failureReason`. With an
214`error`, removes only the failure whose cause is that value, for
215example one of several requests that recovered; the `failureReason`
216then shows the newest failure left, and clears once none is left. With
217nothing to clear or remove it does nothing, so it can follow every
218commit. Throws before the first ready and after `fail()`.
219​
220###### truncate
221​
222(`options?`) => `void`
223​
224Replace the synced rows. By default the replacement also marks the
225Collection ready. Set markReady:false to publish without changing status,
226for example when confirming a committed write from a closed source.
227The last truncate in a transaction supplies its readiness intent.
228​
229###### write
230​
231(`message`) => `void`
232​
233#### Returns
234​
235 \| `void`
236 \| [`CleanupFn`](../type-aliases/CleanupFn.md)
237 \| [`SyncConfigRes`](../type-aliases/SyncConfigRes.md)