@@ -176,6 +176,7 @@ export function electricCollectionOptions(
176
176
const sync = createElectricSync < any > ( config . shapeOptions , {
177
177
seenTxids,
178
178
seenSnapshots,
179
+ collectionId : config . id ,
179
180
} )
180
181
181
182
/**
@@ -188,9 +189,12 @@ export function electricCollectionOptions(
188
189
txId : Txid ,
189
190
timeout : number = 30000
190
191
) : Promise < boolean > => {
191
- debug ( `awaitTxId called with txid %d` , txId )
192
+ debug (
193
+ `${ config . id ? `[${ config . id } ] ` : `` } awaitTxId called with txid %d` ,
194
+ txId
195
+ )
192
196
if ( typeof txId !== `number` ) {
193
- throw new ExpectedNumberInAwaitTxIdError ( typeof txId )
197
+ throw new ExpectedNumberInAwaitTxIdError ( typeof txId , config . id )
194
198
}
195
199
196
200
// First check if the txid is in the seenTxids store
@@ -207,12 +211,15 @@ export function electricCollectionOptions(
207
211
const timeoutId = setTimeout ( ( ) => {
208
212
unsubscribeSeenTxids ( )
209
213
unsubscribeSeenSnapshots ( )
210
- reject ( new TimeoutWaitingForTxIdError ( txId ) )
214
+ reject ( new TimeoutWaitingForTxIdError ( txId , config . id ) )
211
215
} , timeout )
212
216
213
217
const unsubscribeSeenTxids = seenTxids . subscribe ( ( ) => {
214
218
if ( seenTxids . state . has ( txId ) ) {
215
- debug ( `awaitTxId found match for txid %o` , txId )
219
+ debug (
220
+ `${ config . id ? `[${ config . id } ] ` : `` } awaitTxId found match for txid %o` ,
221
+ txId
222
+ )
216
223
clearTimeout ( timeoutId )
217
224
unsubscribeSeenTxids ( )
218
225
unsubscribeSeenSnapshots ( )
@@ -226,7 +233,7 @@ export function electricCollectionOptions(
226
233
)
227
234
if ( visibleSnapshot ) {
228
235
debug (
229
- `awaitTxId found match for txid %o in snapshot %o` ,
236
+ `${ config . id ? `[ ${ config . id } ] ` : `` } awaitTxId found match for txid %o in snapshot %o` ,
230
237
txId ,
231
238
visibleSnapshot
232
239
)
@@ -249,7 +256,7 @@ export function electricCollectionOptions(
249
256
const txid = handlerResult . txid
250
257
251
258
if ( ! txid ) {
252
- throw new ElectricInsertHandlerMustReturnTxIdError ( )
259
+ throw new ElectricInsertHandlerMustReturnTxIdError ( config . id )
253
260
}
254
261
255
262
// Handle both single txid and array of txids
@@ -272,7 +279,7 @@ export function electricCollectionOptions(
272
279
const txid = handlerResult . txid
273
280
274
281
if ( ! txid ) {
275
- throw new ElectricUpdateHandlerMustReturnTxIdError ( )
282
+ throw new ElectricUpdateHandlerMustReturnTxIdError ( config . id )
276
283
}
277
284
278
285
// Handle both single txid and array of txids
@@ -290,7 +297,7 @@ export function electricCollectionOptions(
290
297
? async ( params : DeleteMutationFnParams < any > ) => {
291
298
const handlerResult = await config . onDelete ! ( params )
292
299
if ( ! handlerResult . txid ) {
293
- throw new ElectricDeleteHandlerMustReturnTxIdError ( )
300
+ throw new ElectricDeleteHandlerMustReturnTxIdError ( config . id )
294
301
}
295
302
296
303
// Handle both single txid and array of txids
@@ -333,10 +340,10 @@ function createElectricSync<T extends Row<unknown>>(
333
340
options : {
334
341
seenTxids : Store < Set < Txid > >
335
342
seenSnapshots : Store < Array < PostgresSnapshot > >
343
+ collectionId ?: string
336
344
}
337
345
) : SyncConfig < T > {
338
- const { seenTxids } = options
339
- const { seenSnapshots } = options
346
+ const { seenTxids, seenSnapshots, collectionId } = options
340
347
341
348
// Store for the relation schema information
342
349
const relationSchema = new Store < string | undefined > ( undefined )
@@ -445,7 +452,7 @@ function createElectricSync<T extends Row<unknown>>(
445
452
hasUpToDate = true
446
453
} else if ( isMustRefetchMessage ( message ) ) {
447
454
debug (
448
- `Received must-refetch message, starting transaction with truncate`
455
+ `${ collectionId ? `[ ${ collectionId } ] ` : `` } Received must-refetch message, starting transaction with truncate`
449
456
)
450
457
451
458
// Start a transaction and truncate the collection
@@ -475,7 +482,10 @@ function createElectricSync<T extends Row<unknown>>(
475
482
seenTxids . setState ( ( currentTxids ) => {
476
483
const clonedSeen = new Set < Txid > ( currentTxids )
477
484
if ( newTxids . size > 0 ) {
478
- debug ( `new txids synced from pg %O` , Array . from ( newTxids ) )
485
+ debug (
486
+ `${ collectionId ? `[${ collectionId } ] ` : `` } new txids synced from pg %O` ,
487
+ Array . from ( newTxids )
488
+ )
479
489
}
480
490
newTxids . forEach ( ( txid ) => clonedSeen . add ( txid ) )
481
491
newTxids . clear ( )
@@ -486,7 +496,10 @@ function createElectricSync<T extends Row<unknown>>(
486
496
seenSnapshots . setState ( ( currentSnapshots ) => {
487
497
const seen = [ ...currentSnapshots , ...newSnapshots ]
488
498
newSnapshots . forEach ( ( snapshot ) =>
489
- debug ( `new snapshot synced from pg %o` , snapshot )
499
+ debug (
500
+ `${ collectionId ? `[${ collectionId } ] ` : `` } new snapshot synced from pg %o` ,
501
+ snapshot
502
+ )
490
503
)
491
504
newSnapshots . length = 0
492
505
return seen
0 commit comments