jsgar 2.1.0 → 3.0.0

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/gar.umd.js +167 -26
  2. package/package.json +2 -2
package/dist/gar.umd.js CHANGED
@@ -50,7 +50,7 @@
50
50
  this.user = user;
51
51
  this.working_namespace = working_namespace;
52
52
  this.heartbeatTimeoutInterval = heartbeatTimeoutInterval;
53
- this.version = 650704;
53
+ this.version = 650705;
54
54
 
55
55
  if (typeof window !== 'undefined' && window.location) {
56
56
  this.application = window.location.href;
@@ -589,30 +589,76 @@
589
589
  }
590
590
 
591
591
  /**
592
- * Send a subscription request using local IDs.
592
+ * Send an already-formatted subscription message
593
+ * @param {object} subscriptionMessageValue - json representation of the gar `subscribe` struct
594
+ */
595
+ subscribeFormatted(subscriptionMessageValue) {
596
+ const subMsg = {
597
+ message_type: 'Subscribe',
598
+ value: subscriptionMessageValue,
599
+ };
600
+ this.sendMessage(subMsg);
601
+ }
602
+
603
+ /**
604
+ * Send a subscription request
593
605
  * @param {string} name - Subscription name
594
- * @param {string} [mode='Streaming'] - Subscription mode
606
+ * @param {string} [subscriptionMode='Streaming'] - Subscription mode
595
607
  * @param {string|Array<string>|null} [keyName=null] - Key name(s)
596
608
  * @param {string|Array<string>|null} [topicName=null] - Topic name(s)
597
609
  * @param {string|Array<string>|null} [className=null] - Class name(s)
598
- * @param {string|null} [keyFilter=null] - Key filter regex
599
- * @param {string|null} [topicFilter=null] - Topic filter regex
600
- * @param {boolean} [allMatchingKeys=false] - Retrieve all matching keys
601
- * @param subscriptionGroup - Subscription group ID for isolating callbacks
610
+ * @param {string|null} [keyFilter=null] - Key filter regex (cannot use with keyName)
611
+ * @param {string|null} [topicFilter=null] - Topic filter regex (cannot use with topicName)
612
+ * @param {string|null} [excludeKeyFilter=null] - Exclude key filter regex (cannot use with keyName)
613
+ * @param {string|null} [excludeTopicFilter=null] - Exclude topic filter regex (cannot use with topicName)
614
+ * @param {string|null} [maxHistory] - Maximum history to include
615
+ * @param {boolean} [includeReferencedKeys=false] - Add keys from key references in matched records
616
+ * @param {boolean} [includeReferencingKeys=false] - Add keys that have one or more records referencing any matched keys
617
+ * @param {boolean} [includeAllNamespace=false] - Include keys and topics from all namespaces
618
+ * @param {string|null} [workingNamespace] - Namespace for matching relative paths
619
+ * @param {string|null} [density] - For performance tuning
620
+ * @param {number} [subscriptionGroup=0] - Subscription group ID for isolating callbacks
621
+ * @param {string|null} [subscriptionSet] - Subscription set identifier
602
622
  * @param {number} [snapshotSizeLimit=0] - Limit snapshot size
623
+ * @param {number} [nagleInterval=0] - Nagle interval in milliseconds
624
+ * @param {number} [limit=0] - Limits records in initial snapshot (0 = all)
603
625
  */
604
626
  subscribe(
605
627
  name,
606
- mode = 'Streaming',
628
+ subscriptionMode = 'Streaming',
607
629
  keyName = null,
608
630
  topicName = null,
609
631
  className = null,
610
632
  keyFilter = null,
611
633
  topicFilter = null,
612
- allMatchingKeys = false,
634
+ excludeKeyFilter = null,
635
+ excludeTopicFilter = null,
636
+ maxHistory = null,
637
+ includeReferencedKeys = false,
638
+ includeReferencingKeys = false,
639
+ includeAllNamespace = false,
640
+ workingNamespace = null,
641
+ density = null,
613
642
  subscriptionGroup = 0,
614
- snapshotSizeLimit = 0
643
+ subscriptionSet = null,
644
+ snapshotSizeLimit = 0,
645
+ nagleInterval = 0,
646
+ limit = 0
615
647
  ) {
648
+ // Validate mutually exclusive parameters
649
+ if (keyName && (keyFilter || excludeKeyFilter)) {
650
+ throw new Error('keyName cannot be used with keyFilter or excludeKeyFilter');
651
+ }
652
+
653
+ if (topicName && (topicFilter || excludeTopicFilter)) {
654
+ throw new Error('topicName cannot be used with topicFilter or excludeTopicFilter');
655
+ }
656
+
657
+ // Validate limit parameter usage
658
+ if (limit > 0 && subscriptionMode === 'Streaming') {
659
+ throw new Error('limit cannot be used with streaming subscriptions');
660
+ }
661
+
616
662
  // Convert className to array
617
663
  let classList = null;
618
664
  if (typeof className === 'string') {
@@ -641,23 +687,118 @@
641
687
  }
642
688
  const topicIdList = topicNames.map(x => this.getAndPossiblyIntroduceTopicId(x));
643
689
 
644
- const subMsg = {
645
- message_type: 'Subscribe',
646
- value: {
647
- subscription_mode: mode,
648
- all_matching_keys: allMatchingKeys,
649
- snapshot_size_limit: snapshotSizeLimit,
650
- nagle_interval: 0,
651
- name,
652
- key_id_list: keyIdList,
653
- topic_id_list: topicIdList,
654
- class_list: classList,
655
- key_filter: keyFilter,
656
- topic_filter: topicFilter,
657
- subscription_group: subscriptionGroup
658
- }
690
+ // Build subscription message, filtering out null/undefined values
691
+ const valueDict = {
692
+ subscription_mode: subscriptionMode,
693
+ name,
659
694
  };
660
- this.sendMessage(subMsg);
695
+
696
+ // Add optional fields only if they have values
697
+ if (subscriptionSet) {
698
+ valueDict.subscription_set = subscriptionSet;
699
+ }
700
+ if (maxHistory) {
701
+ valueDict.max_history = maxHistory;
702
+ }
703
+ if (snapshotSizeLimit > 0) {
704
+ valueDict.snapshot_size_limit = snapshotSizeLimit;
705
+ }
706
+ if (nagleInterval > 0) {
707
+ valueDict.nagle_interval = nagleInterval;
708
+ }
709
+ if (subscriptionGroup > 0) {
710
+ valueDict.subscription_group = subscriptionGroup;
711
+ }
712
+ if (density) {
713
+ valueDict.density = density;
714
+ }
715
+ if (includeReferencedKeys) {
716
+ valueDict.include_referenced_keys = includeReferencedKeys;
717
+ }
718
+ if (includeReferencingKeys) {
719
+ valueDict.include_referencing_keys = includeReferencingKeys;
720
+ }
721
+ if (includeAllNamespace) {
722
+ valueDict.include_all_namespace = includeAllNamespace;
723
+ }
724
+ if (limit > 0) {
725
+ valueDict.limit = limit;
726
+ }
727
+ if (keyIdList.length > 0) {
728
+ valueDict.key_id_list = keyIdList;
729
+ }
730
+ if (topicIdList.length > 0) {
731
+ valueDict.topic_id_list = topicIdList;
732
+ }
733
+ if (classList) {
734
+ valueDict.class_list = classList;
735
+ }
736
+ if (keyFilter) {
737
+ valueDict.key_filter = keyFilter;
738
+ }
739
+ if (excludeKeyFilter) {
740
+ valueDict.exclude_key_filter = excludeKeyFilter;
741
+ }
742
+ if (topicFilter) {
743
+ valueDict.topic_filter = topicFilter;
744
+ }
745
+ if (excludeTopicFilter) {
746
+ valueDict.exclude_topic_filter = excludeTopicFilter;
747
+ }
748
+ if (workingNamespace) {
749
+ valueDict.working_namespace = workingNamespace;
750
+ }
751
+
752
+ this.subscribeFormatted(valueDict);
753
+ }
754
+
755
+ /**
756
+ * Wrapper to `subscribe` with a smaller set of arguments.
757
+ * @param {string} name - Subscription name
758
+ * @param {string} [subscriptionMode='Streaming'] - Subscription mode
759
+ * @param {number} [subscriptionGroup=0] - Subscription group ID for isolating callbacks
760
+ * @param {number} [snapshotSizeLimit=0] - Limit snapshot size
761
+ * @param {string|Array<string>|null} [keyName=null] - Key name(s)
762
+ * @param {string|Array<string>|null} [topicName=null] - Topic name(s)
763
+ * @param {string|Array<string>|null} [className=null] - Class name(s)
764
+ * @param {string|null} [keyFilter=null] - Key filter regex (cannot use with keyName)
765
+ * @param {string|null} [topicFilter=null] - Topic filter regex (cannot use with topicName)
766
+ * @param {string|null} [excludeKeyFilter=null] - Exclude key filter regex (cannot use with keyName)
767
+ * @param {string|null} [excludeTopicFilter=null] - Exclude topic filter regex (cannot use with topicName)
768
+ */
769
+ subscribeCommon(
770
+ name,
771
+ subscriptionMode = 'Streaming',
772
+ subscriptionGroup = 0,
773
+ snapshotSizeLimit = 0,
774
+ keyName = null,
775
+ topicName = null,
776
+ className = null,
777
+ keyFilter = null,
778
+ topicFilter = null,
779
+ excludeKeyFilter = null,
780
+ excludeTopicFilter = null,
781
+ ) {
782
+ this.subscribe(
783
+ name,
784
+ subscriptionMode,
785
+ keyName,
786
+ topicName,
787
+ className,
788
+ keyFilter,
789
+ topicFilter,
790
+ excludeKeyFilter,
791
+ excludeTopicFilter,
792
+ null,
793
+ false,
794
+ false,
795
+ false,
796
+ null,
797
+ null,
798
+ subscriptionGroup,
799
+ null,
800
+ snapshotSizeLimit
801
+ );
661
802
  }
662
803
 
663
804
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsgar",
3
- "version": "2.1.0",
3
+ "version": "3.0.0",
4
4
  "description": "A Javascript client for the GAR protocol",
5
5
  "type": "module",
6
6
  "main": "dist/gar.umd.js",
@@ -27,7 +27,7 @@
27
27
  "@eslint/json": "^0.12.0",
28
28
  "@rollup/plugin-commonjs": "^24.0.0",
29
29
  "@rollup/plugin-node-resolve": "^15.0.0",
30
- "eslint": "^9.25.0",
30
+ "eslint": "^9.33.0",
31
31
  "globals": "^16.0.0",
32
32
  "rollup": "^3.0.0"
33
33
  }