teamplay 0.4.0-alpha.83 → 0.4.0-alpha.84

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/orm/Query.js +27 -3
  2. package/package.json +2 -2
package/orm/Query.js CHANGED
@@ -304,7 +304,10 @@ export class QuerySubscriptions {
304
304
  this.ownerFetchCount.delete(ownerKey)
305
305
  this.ownerSubscribeCount.delete(ownerKey)
306
306
  const staleTransportHash = this.ownerToTransport.get(ownerKey)
307
- if (staleTransportHash) this.removeOwnerMeta(ownerKey, staleTransportHash)
307
+ if (staleTransportHash) {
308
+ this.removeOwnerMeta(ownerKey, staleTransportHash)
309
+ this.cleanupStaleTransportState(staleTransportHash)
310
+ }
308
311
  previousCount = 0
309
312
  }
310
313
 
@@ -321,7 +324,10 @@ export class QuerySubscriptions {
321
324
  const isAttached = existingTransportHash != null
322
325
 
323
326
  if (!isAttached || existingTransportHash !== transportHash) {
324
- if (isAttached) this.removeOwnerMeta(ownerKey, existingTransportHash)
327
+ if (isAttached) {
328
+ this.removeOwnerMeta(ownerKey, existingTransportHash)
329
+ this.cleanupStaleTransportState(existingTransportHash)
330
+ }
325
331
  this.ownerToTransport.set(ownerKey, transportHash)
326
332
  this.ownerMeta.set(ownerKey, { collectionName, params, transportHash, rootId })
327
333
  let ownerKeys = this.ownerKeysByTransport.get(transportHash)
@@ -353,10 +359,12 @@ export class QuerySubscriptions {
353
359
  const currentIntentCount = this.getOwnerIntentCount(ownerKey, intent)
354
360
  if (currentIntentCount <= 0) {
355
361
  if ((this.subCount.get(ownerKey) || 0) > 0 && !this.queries.get($query[HASH])) {
362
+ const staleTransportHash = this.ownerToTransport.get(ownerKey)
356
363
  this.subCount.delete(ownerKey)
357
364
  this.ownerFetchCount.delete(ownerKey)
358
365
  this.ownerSubscribeCount.delete(ownerKey)
359
366
  this.removeOwnerMeta(ownerKey)
367
+ if (staleTransportHash) this.cleanupStaleTransportState(staleTransportHash)
360
368
  }
361
369
  if (ERROR_ON_EXCESSIVE_UNSUBSCRIBES) throw Error(ERRORS.notSubscribed($query))
362
370
  return
@@ -567,12 +575,15 @@ export class QuerySubscriptions {
567
575
  const query = this.queries.get(transportHash)
568
576
  await this.reconcileTransport(transportHash)
569
577
  if ((this.transportSubCount.get(transportHash) || 0) <= 0) {
570
- if (query?.activeTransportMode !== 'idle') await unsubscribeQueryTransport(query, { keepRoots: true })
578
+ if (query && query.activeTransportMode !== 'idle') {
579
+ await unsubscribeQueryTransport(query, { keepRoots: true })
580
+ }
571
581
  query?._detachTransportData?.({ keepRoots: false })
572
582
  this.transportSubCount.delete(transportHash)
573
583
  this.ownerKeysByTransport.delete(transportHash)
574
584
  this.queries.delete(transportHash)
575
585
  }
586
+ this.cleanupStaleTransportState(transportHash)
576
587
  settlePending()
577
588
  return
578
589
  }
@@ -595,6 +606,8 @@ export class QuerySubscriptions {
595
606
  }
596
607
  if (!query) {
597
608
  this.transportSubCount.delete(transportHash)
609
+ this.ownerKeysByTransport.delete(transportHash)
610
+ this.cleanupStaleTransportState(transportHash)
598
611
  settlePending()
599
612
  return
600
613
  }
@@ -638,6 +651,17 @@ export class QuerySubscriptions {
638
651
  ownerKeys.delete(ownerKey)
639
652
  if (ownerKeys.size === 0) this.ownerKeysByTransport.delete(knownTransportHash)
640
653
  }
654
+
655
+ cleanupStaleTransportState (transportHash) {
656
+ if (!transportHash) return
657
+ if (this.queries.has(transportHash)) return
658
+ const ownerKeys = this.ownerKeysByTransport.get(transportHash)
659
+ if (ownerKeys?.size) return
660
+ const transportCount = this.transportSubCount.get(transportHash)
661
+ if (transportCount == null || transportCount <= 0) {
662
+ this.transportSubCount.delete(transportHash)
663
+ }
664
+ }
641
665
  }
642
666
 
643
667
  export const querySubscriptions = new QuerySubscriptions()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teamplay",
3
- "version": "0.4.0-alpha.83",
3
+ "version": "0.4.0-alpha.84",
4
4
  "description": "Full-stack signals ORM with multiplayer",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -83,5 +83,5 @@
83
83
  ]
84
84
  },
85
85
  "license": "MIT",
86
- "gitHead": "cf9710fd110129aafbfc8f0e7260ec3186795cb2"
86
+ "gitHead": "780ddafe342631202a373d7a886d791e87764749"
87
87
  }