MCPcopy Index your code
hub / github.com/TanStack/db / createWrappedSyncConfig

Function createWrappedSyncConfig

packages/db-sqlite-persistence-core/src/persisted.ts:2201–2536  ·  view source on GitHub ↗
(
  sourceSyncConfig: SyncConfig<T, TKey>,
  runtime: PersistedCollectionRuntime<T, TKey>,
)

Source from the content-addressed store, hash-verified

2199}
2200
2201function createWrappedSyncConfig<
2202 T extends object,
2203 TKey extends string | number,
2204>(
2205 sourceSyncConfig: SyncConfig<T, TKey>,
2206 runtime: PersistedCollectionRuntime<T, TKey>,
2207): SyncConfig<T, TKey> {
2208 return {
2209 ...sourceSyncConfig,
2210 sync: (params) => {
2211 const transactionStack: Array<OpenSyncTransaction<T, TKey>> = []
2212 const getOpenTransaction = () =>
2213 transactionStack[transactionStack.length - 1]
2214 let fullStartPromise: Promise<void> | null = null
2215 const cancelledLoadKeys = new Set<string>()
2216 const loadSubscriptionIds = new WeakMap<object, string>()
2217 let nextLoadSubscriptionId = 0
2218 const getLoadKey = (options: LoadSubsetOptions) => {
2219 const subscription = options.subscription as object | undefined
2220 if (subscription && typeof subscription === `object`) {
2221 const existingId = loadSubscriptionIds.get(subscription)
2222 if (existingId) {
2223 return `sub:${existingId}`
2224 }
2225 nextLoadSubscriptionId++
2226 const nextId = String(nextLoadSubscriptionId)
2227 loadSubscriptionIds.set(subscription, nextId)
2228 return `sub:${nextId}`
2229 }
2230
2231 return `opts:${stableSerialize(normalizeSubsetOptionsForKey(options))}`
2232 }
2233 runtime.setSyncControls({
2234 begin: params.begin,
2235 write: params.write as SyncControlFns<T, TKey>[`write`],
2236 commit: params.commit,
2237 truncate: params.truncate,
2238 metadata: params.metadata ?? null,
2239 })
2240 runtime.setCollection(
2241 params.collection as Collection<T, TKey, PersistedCollectionUtils>,
2242 )
2243
2244 const wrappedParams = {
2245 ...params,
2246 markReady: () => {
2247 void (fullStartPromise ?? runtime.ensureStarted())
2248 .then(() => {
2249 params.markReady()
2250 })
2251 .catch((error) => {
2252 console.warn(
2253 `Failed persisted sync startup before markReady:`,
2254 error,
2255 )
2256 params.markReady()
2257 })
2258 },

Callers 1

Calls 15

getOpenTransactionFunction · 0.85
getLoadKeyFunction · 0.85
setSyncControlsMethod · 0.80
setCollectionMethod · 0.80
ensureStartedMethod · 0.80
markReadyMethod · 0.80
isApplyingInternallyMethod · 0.80
isHydratingNowMethod · 0.80
scanPersistedRowsMethod · 0.80
filterMethod · 0.80
fromMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…