| 289 | } |
| 290 | |
| 291 | private createSyncMetadataApi(): SyncMetadataApi<TKey> { |
| 292 | return { |
| 293 | row: { |
| 294 | get: (key) => { |
| 295 | const pendingTransaction = |
| 296 | this.state.pendingSyncedTransactions[ |
| 297 | this.state.pendingSyncedTransactions.length - 1 |
| 298 | ] |
| 299 | const pendingWrite = pendingTransaction?.rowMetadataWrites.get(key) |
| 300 | if (pendingWrite) { |
| 301 | return pendingWrite.type === `delete` |
| 302 | ? undefined |
| 303 | : pendingWrite.value |
| 304 | } |
| 305 | if (pendingTransaction?.truncate) { |
| 306 | return undefined |
| 307 | } |
| 308 | return this.state.syncedMetadata.get(key) |
| 309 | }, |
| 310 | set: (key, metadata) => { |
| 311 | const pendingTransaction = this.getActivePendingSyncTransaction() |
| 312 | pendingTransaction.rowMetadataWrites.set(key, { |
| 313 | type: `set`, |
| 314 | value: metadata, |
| 315 | }) |
| 316 | }, |
| 317 | delete: (key) => { |
| 318 | const pendingTransaction = this.getActivePendingSyncTransaction() |
| 319 | pendingTransaction.rowMetadataWrites.set(key, { |
| 320 | type: `delete`, |
| 321 | }) |
| 322 | }, |
| 323 | }, |
| 324 | collection: { |
| 325 | get: (key) => { |
| 326 | const pendingTransaction = |
| 327 | this.state.pendingSyncedTransactions[ |
| 328 | this.state.pendingSyncedTransactions.length - 1 |
| 329 | ] |
| 330 | const pendingWrite = |
| 331 | pendingTransaction?.collectionMetadataWrites.get(key) |
| 332 | if (pendingWrite) { |
| 333 | return pendingWrite.type === `delete` |
| 334 | ? undefined |
| 335 | : pendingWrite.value |
| 336 | } |
| 337 | return this.state.syncedCollectionMetadata.get(key) |
| 338 | }, |
| 339 | set: (key, value) => { |
| 340 | const pendingTransaction = this.getActivePendingSyncTransaction() |
| 341 | pendingTransaction.collectionMetadataWrites.set(key, { |
| 342 | type: `set`, |
| 343 | value, |
| 344 | }) |
| 345 | }, |
| 346 | delete: (key) => { |
| 347 | const pendingTransaction = this.getActivePendingSyncTransaction() |
| 348 | pendingTransaction.collectionMetadataWrites.set(key, { |