jsgar 1.7.2 → 2.1.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 +53 -30
  2. package/package.json +1 -1
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 = 650269;
53
+ this.version = 650704;
54
54
 
55
55
  if (typeof window !== 'undefined' && window.location) {
56
56
  this.application = window.location.href;
@@ -289,13 +289,13 @@
289
289
 
290
290
  /**
291
291
  * Register handler for KeyIntroduction message.
292
- * @param {Function} handler - Callback with (keyId, name, _class)
292
+ * @param {Function} handler - Callback with (keyId, name, class_list)
293
293
  * @param subscriptionGroup - The subscription group for callback (default 0)
294
294
  */
295
295
  registerKeyIntroductionHandler(handler, subscriptionGroup = 0) {
296
296
  this.registerHandler('KeyIntroduction', (msg) => {
297
297
  const value = msg.value;
298
- handler(value.key_id, value.name, value._class || null);
298
+ handler(value.key_id, value.name, value.class_list || null);
299
299
  }, subscriptionGroup);
300
300
  }
301
301
 
@@ -343,18 +343,6 @@
343
343
  }, subscriptionGroup);
344
344
  }
345
345
 
346
- /**
347
- * Register handler for Shutdown message.
348
- * @param {Function} handler - Callback with no arguments
349
- */
350
- registerShutdownHandler(handler) {
351
- this.registerHandler('Shutdown', () => handler());
352
- }
353
-
354
- clearShutdownHandler() {
355
- this.messageHandlers.delete('Shutdown');
356
- }
357
-
358
346
  /**
359
347
  * Register a callback to handle heartbeat timeout events.
360
348
  * @param {Function} handler - Callback with no arguments
@@ -389,8 +377,8 @@
389
377
  this.registerLogoffHandler(() => this.log('INFO', 'Logoff received'));
390
378
  this.registerTopicIntroductionHandler((topicId, name) =>
391
379
  this.log('DEBUG', `New server topic: ${name} (Server ID: ${topicId})`));
392
- this.registerKeyIntroductionHandler((keyId, name, _class) =>
393
- this.log('DEBUG', `New server key: ${name} (Server ID: ${keyId})`));
380
+ this.registerKeyIntroductionHandler((keyId, name, classList) =>
381
+ this.log('DEBUG', `New server key: ${name} : ${keyId} (Classes: ${JSON.stringify(classList)})`));
394
382
  this.registerDeleteKeyHandler((keyId) =>
395
383
  this.log('DEBUG', `Delete key: ${this.serverKeyIdToName.get(keyId) || 'unknown'} (Server ID: ${keyId})`));
396
384
  this.registerSubscriptionStatusHandler(this._defaultSubscriptionStatusHandler.bind(this));
@@ -398,7 +386,6 @@
398
386
  this.log('DEBUG', `Delete record: ${this.serverKeyIdToName.get(keyId) || 'unknown'} - ${this.serverTopicIdToName.get(topicId) || 'unknown'}`));
399
387
  this.registerRecordUpdateHandler((keyId, topicId, value) =>
400
388
  this.log('DEBUG', `Record update: ${this.serverKeyIdToName.get(keyId) || 'unknown'} - ${this.serverTopicIdToName.get(topicId) || 'unknown'} = ${JSON.stringify(value)}`));
401
- this.registerShutdownHandler(() => this.log('INFO', 'Shutdown received'));
402
389
  }
403
390
 
404
391
  /**
@@ -605,9 +592,9 @@
605
592
  * Send a subscription request using local IDs.
606
593
  * @param {string} name - Subscription name
607
594
  * @param {string} [mode='Streaming'] - Subscription mode
608
- * @param {string|null} [keyName=null] - Key name
609
- * @param {string|null} [topicName=null] - Topic name
610
- * @param {string|null} [classFilter=null] - Class filter
595
+ * @param {string|Array<string>|null} [keyName=null] - Key name(s)
596
+ * @param {string|Array<string>|null} [topicName=null] - Topic name(s)
597
+ * @param {string|Array<string>|null} [className=null] - Class name(s)
611
598
  * @param {string|null} [keyFilter=null] - Key filter regex
612
599
  * @param {string|null} [topicFilter=null] - Topic filter regex
613
600
  * @param {boolean} [allMatchingKeys=false] - Retrieve all matching keys
@@ -619,15 +606,41 @@
619
606
  mode = 'Streaming',
620
607
  keyName = null,
621
608
  topicName = null,
622
- classFilter = null,
609
+ className = null,
623
610
  keyFilter = null,
624
611
  topicFilter = null,
625
612
  allMatchingKeys = false,
626
613
  subscriptionGroup = 0,
627
614
  snapshotSizeLimit = 0
628
615
  ) {
629
- const keyId = keyName ? this.getAndPossiblyIntroduceKeyId(keyName) : 0;
630
- const topicId = topicName ? this.getAndPossiblyIntroduceTopicId(topicName) : 0;
616
+ // Convert className to array
617
+ let classList = null;
618
+ if (typeof className === 'string') {
619
+ classList = className.split(/\s+/).filter(Boolean);
620
+ } else if (Array.isArray(className)) {
621
+ classList = className;
622
+ }
623
+
624
+ let singleClass = Array.isArray(classList) && classList.length === 1 ? classList[0] : null;
625
+
626
+ // Convert keyName to array
627
+ let keyNames = [];
628
+ if (typeof keyName === 'string') {
629
+ keyNames = keyName.split(/\s+/).filter(Boolean);
630
+ } else if (Array.isArray(keyName)) {
631
+ keyNames = keyName;
632
+ }
633
+ const keyIdList = keyNames.map(x => this.getAndPossiblyIntroduceKeyId(x, singleClass));
634
+
635
+ // Convert topicName to array
636
+ let topicNames = [];
637
+ if (typeof topicName === 'string') {
638
+ topicNames = topicName.split(/\s+/).filter(Boolean);
639
+ } else if (Array.isArray(topicName)) {
640
+ topicNames = topicName;
641
+ }
642
+ const topicIdList = topicNames.map(x => this.getAndPossiblyIntroduceTopicId(x));
643
+
631
644
  const subMsg = {
632
645
  message_type: 'Subscribe',
633
646
  value: {
@@ -636,9 +649,9 @@
636
649
  snapshot_size_limit: snapshotSizeLimit,
637
650
  nagle_interval: 0,
638
651
  name,
639
- key_id: keyId,
640
- topic_id: topicId,
641
- _class: classFilter,
652
+ key_id_list: keyIdList,
653
+ topic_id_list: topicIdList,
654
+ class_list: classList,
642
655
  key_filter: keyFilter,
643
656
  topic_filter: topicFilter,
644
657
  subscription_group: subscriptionGroup
@@ -650,21 +663,31 @@
650
663
  /**
651
664
  * Introduce a new key if not already known and return local key ID.
652
665
  * @param {string} name - Key name
653
- * @param {string|null} [className=null] - Class name
666
+ * @param {string|Array<string>|null} [className=null] - Class name(s)
654
667
  * @returns {number} Local key ID
655
668
  */
656
669
  getAndPossiblyIntroduceKeyId(name, className = null) {
657
670
  if (!this.localKeyMap.has(name)) {
658
671
  const keyId = this.localKeyCounter++;
659
672
  this.localKeyMap.set(name, keyId);
673
+ let classList = null;
674
+ if (className) {
675
+ if (typeof className === 'string') {
676
+ classList = className.split(/\s+/).filter(Boolean);
677
+ } else if (Array.isArray(className)) {
678
+ classList = className;
679
+ }
680
+ }
660
681
  const msg = {
661
682
  message_type: 'KeyIntroduction',
662
683
  value: {
663
684
  key_id: keyId,
664
- name,
665
- _class: className
685
+ name
666
686
  }
667
687
  };
688
+ if (classList) {
689
+ msg.value.class_list = classList;
690
+ }
668
691
  this.sendMessage(msg);
669
692
  }
670
693
  return this.localKeyMap.get(name);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsgar",
3
- "version": "1.7.2",
3
+ "version": "2.1.0",
4
4
  "description": "A Javascript client for the GAR protocol",
5
5
  "type": "module",
6
6
  "main": "dist/gar.umd.js",