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

SyncConfig.md

194 lines3.8 KB

1---
2id: SyncConfig
3title: SyncConfig
4---
5​
6Defined in: [packages/db/src/types.ts:422](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L422)
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:470](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L470)
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:464](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L464)
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:475](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L475)
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:480](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L480)
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:489](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L489)
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:426](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L426)
134​
135#### Parameters
136​
137##### params
138​
139###### begin
140​
141(`options?`) => `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.
154Returns `true` when the writes and events are already visible. Otherwise
155returns a receipt that resolves after they become visible. If collection
156cleanup or an optional request abort abandons the transaction first, the
157receipt rejects with an error named `AbortError`. If cancellation of an
158earlier transaction invalidates this transaction's insert admission, the
159receipt rejects with `DuplicateKeySyncError`.
160If cancellation removes a row required by this transaction's partial
161update, its receipt rejects with an error named `AbortError`.
162Pass a signal only for request-scoped work that must not publish after
163cancellation. Aborting after application has no effect.
164​
165###### markError
166​
167(`error?`) => `void`
168​
169Signal that initial sync failed before producing a usable snapshot.
170When supplied, `error` is preserved as the rejection reason from `preload()`.
171​
172###### markReady
173​
174() => `void`
175​
176Signal that a usable initial or recovered snapshot is available.
177​
178###### metadata?
179​
180[`SyncMetadataApi`](SyncMetadataApi.md)\<`TKey`\>
181​
182###### truncate
183​
184() => `void`
185​
186###### write
187​
188(`message`) => `void`
189​
190#### Returns
191​
192 \| `void`
193 \| [`CleanupFn`](../type-aliases/CleanupFn.md)
194 \| [`SyncConfigRes`](../type-aliases/SyncConfigRes.md)