@sylphx/lens-solid 2.2.1 → 2.2.2

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 +46 -3
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -390,6 +390,38 @@ class ReconnectionMetricsTracker {
390
390
  }
391
391
 
392
392
  // ../client/dist/index.js
393
+ function hasAnySubscription(entities, entityName, select, visited = new Set) {
394
+ if (!entities)
395
+ return false;
396
+ if (visited.has(entityName))
397
+ return false;
398
+ visited.add(entityName);
399
+ const entityMetadata = entities[entityName];
400
+ if (!entityMetadata)
401
+ return false;
402
+ const fieldsToCheck = select ? Object.keys(select) : Object.keys(entityMetadata);
403
+ for (const fieldName of fieldsToCheck) {
404
+ const fieldMode = entityMetadata[fieldName];
405
+ if (!fieldMode)
406
+ continue;
407
+ if (fieldMode === "subscribe") {
408
+ return true;
409
+ }
410
+ const fieldSelect = select?.[fieldName];
411
+ const nestedSelect = typeof fieldSelect === "object" && fieldSelect !== null && "select" in fieldSelect ? fieldSelect.select : undefined;
412
+ if (nestedSelect || typeof fieldSelect === "object" && fieldSelect !== null) {
413
+ for (const targetEntityName of Object.keys(entities)) {
414
+ if (targetEntityName === entityName)
415
+ continue;
416
+ if (hasAnySubscription(entities, targetEntityName, nestedSelect, visited)) {
417
+ return true;
418
+ }
419
+ }
420
+ }
421
+ }
422
+ return false;
423
+ }
424
+
393
425
  class ClientImpl {
394
426
  transport;
395
427
  plugins;
@@ -496,6 +528,17 @@ class ClientImpl {
496
528
  }
497
529
  return;
498
530
  }
531
+ requiresSubscription(path, select) {
532
+ const meta = this.getOperationMeta(path);
533
+ if (!meta)
534
+ return false;
535
+ if (meta.type === "subscription")
536
+ return true;
537
+ if (meta.type === "query" && meta.returnType && this.metadata?.entities) {
538
+ return hasAnySubscription(this.metadata.entities, meta.returnType, select);
539
+ }
540
+ return false;
541
+ }
499
542
  generateId(type, path) {
500
543
  return `${type}-${path}-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
501
544
  }
@@ -526,7 +569,8 @@ class ClientImpl {
526
569
  data: null,
527
570
  error: null,
528
571
  completed: false,
529
- observers: new Set
572
+ observers: new Set,
573
+ ...select && { select }
530
574
  });
531
575
  }
532
576
  const sub = this.subscriptions.get(key);
@@ -623,8 +667,7 @@ class ClientImpl {
623
667
  if (!sub)
624
668
  return;
625
669
  await this.ensureConnected();
626
- const meta = this.getOperationMeta(path);
627
- const isSubscription = meta?.type === "subscription";
670
+ const isSubscription = this.requiresSubscription(path, sub.select);
628
671
  if (isSubscription) {
629
672
  const op2 = {
630
673
  id: this.generateId("subscription", path),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sylphx/lens-solid",
3
- "version": "2.2.1",
3
+ "version": "2.2.2",
4
4
  "description": "SolidJS bindings for Lens API framework",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -31,7 +31,7 @@
31
31
  "author": "SylphxAI",
32
32
  "license": "MIT",
33
33
  "dependencies": {
34
- "@sylphx/lens-client": "^2.3.2",
34
+ "@sylphx/lens-client": "^2.4.0",
35
35
  "@sylphx/lens-core": "^2.3.0"
36
36
  },
37
37
  "peerDependencies": {