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

SyncConfig.md

196 lines3.9 KB

1---
2id: SyncConfig
3title: SyncConfig
4---
5​
6Defined in: [packages/db/src/types.ts:419](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L419)
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:466](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L466)
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:460](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L460)
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:471](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L471)
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:476](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L476)
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:485](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L485)
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:423](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L423)
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###### markError
163​
164(`error?`) => `void`
165​
166Signal that initial sync failed before producing a usable snapshot.
167When supplied, `error` is preserved as the rejection reason from `preload()`.
168​
169###### markReady
170​
171() => `void`
172​
173Signal that a usable initial or recovered snapshot is available.
174​
175###### metadata?
176​
177[`SyncMetadataApi`](SyncMetadataApi.md)\<`TKey`\>
178​
179###### truncate
180​
181(`options?`) => `void`
182​
183Replace the synced rows. By default the replacement also marks the
184Collection ready. Set markReady:false to publish without changing status,
185for example when confirming a committed write from a closed source.
186The last truncate in a transaction supplies its readiness intent.
187​
188###### write
189​
190(`message`) => `void`
191​
192#### Returns
193​
194 \| `void`
195 \| [`CleanupFn`](../type-aliases/CleanupFn.md)
196 \| [`SyncConfigRes`](../type-aliases/SyncConfigRes.md)