( sourceSyncConfig: SyncConfig<T, TKey>, runtime: PersistedCollectionRuntime<T, TKey>, )
| 2199 | } |
| 2200 | |
| 2201 | function 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 | }, |
no test coverage detected
searching dependent graphs…