jsgar 1.7.2 → 2.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.
- package/dist/gar.umd.js +51 -30
- 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 =
|
|
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,
|
|
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.
|
|
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,
|
|
393
|
-
this.log('DEBUG', `New server key: ${name}
|
|
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} [
|
|
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,39 @@
|
|
|
619
606
|
mode = 'Streaming',
|
|
620
607
|
keyName = null,
|
|
621
608
|
topicName = null,
|
|
622
|
-
|
|
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
|
-
|
|
630
|
-
|
|
616
|
+
// Convert keyName to array
|
|
617
|
+
let keyNames = [];
|
|
618
|
+
if (typeof keyName === 'string') {
|
|
619
|
+
keyNames = keyName.split(/\s+/).filter(Boolean);
|
|
620
|
+
} else if (Array.isArray(keyName)) {
|
|
621
|
+
keyNames = keyName;
|
|
622
|
+
}
|
|
623
|
+
const keyIdList = keyNames.map(x => this.getAndPossiblyIntroduceKeyId(x));
|
|
624
|
+
|
|
625
|
+
// Convert topicName to array
|
|
626
|
+
let topicNames = [];
|
|
627
|
+
if (typeof topicName === 'string') {
|
|
628
|
+
topicNames = topicName.split(/\s+/).filter(Boolean);
|
|
629
|
+
} else if (Array.isArray(topicName)) {
|
|
630
|
+
topicNames = topicName;
|
|
631
|
+
}
|
|
632
|
+
const topicIdList = topicNames.map(x => this.getAndPossiblyIntroduceTopicId(x));
|
|
633
|
+
|
|
634
|
+
// Convert className to array
|
|
635
|
+
let classList = null;
|
|
636
|
+
if (typeof className === 'string') {
|
|
637
|
+
classList = className.split(/\s+/).filter(Boolean);
|
|
638
|
+
} else if (Array.isArray(className)) {
|
|
639
|
+
classList = className;
|
|
640
|
+
}
|
|
641
|
+
|
|
631
642
|
const subMsg = {
|
|
632
643
|
message_type: 'Subscribe',
|
|
633
644
|
value: {
|
|
@@ -636,9 +647,9 @@
|
|
|
636
647
|
snapshot_size_limit: snapshotSizeLimit,
|
|
637
648
|
nagle_interval: 0,
|
|
638
649
|
name,
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
650
|
+
key_id_list: keyIdList,
|
|
651
|
+
topic_id_list: topicIdList,
|
|
652
|
+
class_list: classList,
|
|
642
653
|
key_filter: keyFilter,
|
|
643
654
|
topic_filter: topicFilter,
|
|
644
655
|
subscription_group: subscriptionGroup
|
|
@@ -650,21 +661,31 @@
|
|
|
650
661
|
/**
|
|
651
662
|
* Introduce a new key if not already known and return local key ID.
|
|
652
663
|
* @param {string} name - Key name
|
|
653
|
-
* @param {string|null} [className=null] - Class name
|
|
664
|
+
* @param {string|Array<string>|null} [className=null] - Class name(s)
|
|
654
665
|
* @returns {number} Local key ID
|
|
655
666
|
*/
|
|
656
667
|
getAndPossiblyIntroduceKeyId(name, className = null) {
|
|
657
668
|
if (!this.localKeyMap.has(name)) {
|
|
658
669
|
const keyId = this.localKeyCounter++;
|
|
659
670
|
this.localKeyMap.set(name, keyId);
|
|
671
|
+
let classList = null;
|
|
672
|
+
if (className) {
|
|
673
|
+
if (typeof className === 'string') {
|
|
674
|
+
classList = className.split(/\s+/).filter(Boolean);
|
|
675
|
+
} else if (Array.isArray(className)) {
|
|
676
|
+
classList = className;
|
|
677
|
+
}
|
|
678
|
+
}
|
|
660
679
|
const msg = {
|
|
661
680
|
message_type: 'KeyIntroduction',
|
|
662
681
|
value: {
|
|
663
682
|
key_id: keyId,
|
|
664
|
-
name
|
|
665
|
-
_class: className
|
|
683
|
+
name
|
|
666
684
|
}
|
|
667
685
|
};
|
|
686
|
+
if (classList) {
|
|
687
|
+
msg.value.class_list = classList;
|
|
688
|
+
}
|
|
668
689
|
this.sendMessage(msg);
|
|
669
690
|
}
|
|
670
691
|
return this.localKeyMap.get(name);
|