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

SyncConfig.md

206 lines4.3 KB

1---
2id: SyncConfig
3title: SyncConfig
4---
5​
6Defined in: [packages/db/src/types.ts:445](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L445)
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:500](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L500)
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:494](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L494)
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:505](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L505)
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:510](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L510)
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:519](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L519)
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:449](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L449)
134​
135#### Parameters
136​
137##### params
138​
139###### begin
140​
141() => `void`
142​
143Begin a new sync transaction.
144​
145###### collection
146​
147[`Collection`](Collection.md)\<`T`, `TKey`, `any`, `any`, `any`\>
148​
149###### commit
150​
151(`signal?`) => [`SyncAppliedReceipt`](../type-aliases/SyncAppliedReceipt.md)
152​
153Commit the active sync transaction in FIFO order. Core accepts it at
154once, and an accepted transaction always applies. Returns `true` when
155its writes are visible, or a receipt that resolves when they become
156visible. While an optimistic transaction is persisting, it becomes
157visible when that transaction settles, together with the drop of its
158optimistic state. A signal that is already aborted abandons the
159transaction before acceptance, and the receipt rejects with an error
160named `AbortError`. Aborting after acceptance has no effect.
161​
162###### invalidateLoadedSubsets
163​
164() => `void`
165​
166Report that rows this adapter serves for loaded subsets may have shifted
167between served pages, after a refetch that the adapter started on its
168own has applied. Each ordered live query then re-establishes its window
169with a bounded repair from the start of its order. Calls in one turn are
170coalesced. Do not call it for results that answer a `loadSubset` call.
171​
172###### markError
173​
174(`error?`) => `void`
175​
176Signal that initial sync failed before producing a usable snapshot.
177When supplied, `error` is preserved as the rejection reason from `preload()`.
178​
179###### markReady
180​
181() => `void`
182​
183Signal that a usable initial or recovered snapshot is available.
184​
185###### metadata?
186​
187[`SyncMetadataApi`](SyncMetadataApi.md)\<`TKey`\>
188​
189###### truncate
190​
191(`options?`) => `void`
192​
193Replace the synced rows. By default the replacement also marks the
194Collection ready. Set markReady:false to publish without changing status,
195for example when confirming a committed write from a closed source.
196The last truncate in a transaction supplies its readiness intent.
197​
198###### write
199​
200(`message`) => `void`
201​
202#### Returns
203​
204 \| `void`
205 \| [`CleanupFn`](../type-aliases/CleanupFn.md)
206 \| [`SyncConfigRes`](../type-aliases/SyncConfigRes.md)