Skip to content

Commit 1276444

Browse files
committed
Fixes to subscription
1 parent 294f9b4 commit 1276444

File tree

2 files changed

+2
-73
lines changed

2 files changed

+2
-73
lines changed

packages/db/src/collection/subscription.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { ensureIndexForExpression } from "../indexes/auto-index.js"
22
import { and, gt, lt } from "../query/builder/functions.js"
3-
import { Value } from "../query/ir.js"
43
import {
54
createFilterFunctionFromExpression,
65
createFilteredCallback,
76
} from "./change-events.js"
8-
import type { BasicExpression, OrderBy } from "../query/ir.js"
97
import type { IndexInterface } from "../indexes/base-index.js"
8+
import { Value, type BasicExpression, type OrderBy } from "../query/ir.js"
109
import type { ChangeMessage } from "../types.js"
1110
import type { CollectionImpl } from "./index.js"
1211

@@ -154,6 +153,7 @@ export class CollectionSubscription {
154153
limit,
155154
minValue,
156155
}: RequestLimitedSnapshotOptions) {
156+
console.log("in requestLimitedSnapshot")
157157
if (!limit) throw new Error(`limit is required`)
158158

159159
if (!this.orderByIndex) {

packages/db/src/collection/sync.ts

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,8 @@ import { deepEquals } from "../utils"
1111
import type { StandardSchemaV1 } from "@standard-schema/spec"
1212
import type {
1313
ChangeMessage,
14-
<<<<<<< HEAD
1514
CleanupFn,
1615
CollectionConfig,
17-
=======
18-
CollectionConfig,
19-
CleanupFn,
20-
>>>>>>> 684c70ec (Add onLoadMore callback and call it from the requestSnapshot methods)
2116
OnLoadMoreOptions,
2217
SyncConfigRes,
2318
} from "../types"
@@ -99,7 +94,6 @@ export class CollectionSyncManager<
9994
}
10095
const key = this.config.getKey(messageWithoutKey.value)
10196

102-
<<<<<<< HEAD
10397
let messageType = messageWithoutKey.type
10498

10599
// Check if an item with this key already exists when inserting
@@ -177,71 +171,6 @@ export class CollectionSyncManager<
177171
throw new SyncTransactionAlreadyCommittedWriteError()
178172
}
179173

180-
=======
181-
// Check if an item with this key already exists when inserting
182-
if (messageWithoutKey.type === `insert`) {
183-
const insertingIntoExistingSynced = this.state.syncedData.has(key)
184-
const hasPendingDeleteForKey =
185-
pendingTransaction.deletedKeys.has(key)
186-
const isTruncateTransaction = pendingTransaction.truncate === true
187-
// Allow insert after truncate in the same transaction even if it existed in syncedData
188-
if (
189-
insertingIntoExistingSynced &&
190-
!hasPendingDeleteForKey &&
191-
!isTruncateTransaction
192-
) {
193-
throw new DuplicateKeySyncError(key, this.id)
194-
}
195-
}
196-
197-
const message: ChangeMessage<TOutput> = {
198-
...messageWithoutKey,
199-
key,
200-
}
201-
pendingTransaction.operations.push(message)
202-
203-
if (messageWithoutKey.type === `delete`) {
204-
pendingTransaction.deletedKeys.add(key)
205-
}
206-
},
207-
commit: () => {
208-
const pendingTransaction =
209-
this.state.pendingSyncedTransactions[
210-
this.state.pendingSyncedTransactions.length - 1
211-
]
212-
if (!pendingTransaction) {
213-
throw new NoPendingSyncTransactionCommitError()
214-
}
215-
if (pendingTransaction.committed) {
216-
throw new SyncTransactionAlreadyCommittedError()
217-
}
218-
219-
pendingTransaction.committed = true
220-
221-
// Update status to initialCommit when transitioning from loading
222-
// This indicates we're in the process of committing the first transaction
223-
if (this.lifecycle.status === `loading`) {
224-
this.lifecycle.setStatus(`initialCommit`)
225-
}
226-
227-
this.state.commitPendingTransactions()
228-
},
229-
markReady: () => {
230-
this.lifecycle.markReady()
231-
},
232-
truncate: () => {
233-
const pendingTransaction =
234-
this.state.pendingSyncedTransactions[
235-
this.state.pendingSyncedTransactions.length - 1
236-
]
237-
if (!pendingTransaction) {
238-
throw new NoPendingSyncTransactionWriteError()
239-
}
240-
if (pendingTransaction.committed) {
241-
throw new SyncTransactionAlreadyCommittedWriteError()
242-
}
243-
244-
>>>>>>> 684c70ec (Add onLoadMore callback and call it from the requestSnapshot methods)
245174
// Clear all operations from the current transaction
246175
pendingTransaction.operations = []
247176
pendingTransaction.deletedKeys.clear()

0 commit comments

Comments
 (0)