@arcote.tech/arc-adapter-db-sqlite 0.7.10 → 0.7.11

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/dist/index.js +31 -0
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -4282,6 +4282,7 @@ class StreamingQueryCache {
4282
4282
  views = [];
4283
4283
  activeStreams = new Map;
4284
4284
  pendingUnsubscribes = new Map;
4285
+ streamScopes = new Map;
4285
4286
  static UNSUBSCRIBE_DELAY_MS = 5000;
4286
4287
  registerViews(views) {
4287
4288
  this.views = views;
@@ -4340,6 +4341,7 @@ class StreamingQueryCache {
4340
4341
  if (current2 && current2.refCount <= 0) {
4341
4342
  current2.unsubscribe();
4342
4343
  this.activeStreams.delete(viewName);
4344
+ this.streamScopes.delete(viewName);
4343
4345
  }
4344
4346
  }, StreamingQueryCache.UNSUBSCRIBE_DELAY_MS);
4345
4347
  this.pendingUnsubscribes.set(viewName, timeout);
@@ -4347,6 +4349,8 @@ class StreamingQueryCache {
4347
4349
  }
4348
4350
  subscribeQuery(descriptor, eventWire, scope) {
4349
4351
  const key = descriptor.element;
4352
+ if (scope)
4353
+ this.streamScopes.set(key, scope);
4350
4354
  const { unsubscribe } = this.registerStream(key, () => {
4351
4355
  const subId = eventWire.subscribeQuery(descriptor, (data) => {
4352
4356
  this.setViewData(descriptor.element, data);
@@ -4355,6 +4359,28 @@ class StreamingQueryCache {
4355
4359
  });
4356
4360
  return unsubscribe;
4357
4361
  }
4362
+ invalidateScope(scope) {
4363
+ for (const [viewName, viewScope] of this.streamScopes) {
4364
+ if (viewScope !== scope)
4365
+ continue;
4366
+ const pending = this.pendingUnsubscribes.get(viewName);
4367
+ if (pending) {
4368
+ clearTimeout(pending);
4369
+ this.pendingUnsubscribes.delete(viewName);
4370
+ }
4371
+ const stream = this.activeStreams.get(viewName);
4372
+ if (stream) {
4373
+ try {
4374
+ stream.unsubscribe();
4375
+ } catch {}
4376
+ this.activeStreams.delete(viewName);
4377
+ }
4378
+ this.streamScopes.delete(viewName);
4379
+ const store = this.stores.get(viewName);
4380
+ if (store)
4381
+ store.clear();
4382
+ }
4383
+ }
4358
4384
  setViewData(viewName, data) {
4359
4385
  const store = this.stores.get(viewName);
4360
4386
  if (!store)
@@ -4402,6 +4428,11 @@ class StreamingQueryCache {
4402
4428
  stream.unsubscribe();
4403
4429
  }
4404
4430
  this.activeStreams.clear();
4431
+ this.streamScopes.clear();
4432
+ for (const timeout of this.pendingUnsubscribes.values()) {
4433
+ clearTimeout(timeout);
4434
+ }
4435
+ this.pendingUnsubscribes.clear();
4405
4436
  for (const store of this.stores.values()) {
4406
4437
  store.clear();
4407
4438
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcote.tech/arc-adapter-db-sqlite",
3
- "version": "0.7.10",
3
+ "version": "0.7.11",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -20,7 +20,7 @@
20
20
  "test": "bun test"
21
21
  },
22
22
  "peerDependencies": {
23
- "@arcote.tech/arc": "^0.7.10"
23
+ "@arcote.tech/arc": "^0.7.11"
24
24
  },
25
25
  "devDependencies": {
26
26
  "typescript": "^5.0.0"