jsgar 1.7.1 → 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 +52 -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,12 +592,13 @@
|
|
|
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
|
|
601
|
+
* @param subscriptionGroup - Subscription group ID for isolating callbacks
|
|
614
602
|
* @param {number} [snapshotSizeLimit=0] - Limit snapshot size
|
|
615
603
|
*/
|
|
616
604
|
subscribe(
|
|
@@ -618,15 +606,39 @@
|
|
|
618
606
|
mode = 'Streaming',
|
|
619
607
|
keyName = null,
|
|
620
608
|
topicName = null,
|
|
621
|
-
|
|
609
|
+
className = null,
|
|
622
610
|
keyFilter = null,
|
|
623
611
|
topicFilter = null,
|
|
624
612
|
allMatchingKeys = false,
|
|
625
613
|
subscriptionGroup = 0,
|
|
626
614
|
snapshotSizeLimit = 0
|
|
627
615
|
) {
|
|
628
|
-
|
|
629
|
-
|
|
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
|
+
|
|
630
642
|
const subMsg = {
|
|
631
643
|
message_type: 'Subscribe',
|
|
632
644
|
value: {
|
|
@@ -635,9 +647,9 @@
|
|
|
635
647
|
snapshot_size_limit: snapshotSizeLimit,
|
|
636
648
|
nagle_interval: 0,
|
|
637
649
|
name,
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
650
|
+
key_id_list: keyIdList,
|
|
651
|
+
topic_id_list: topicIdList,
|
|
652
|
+
class_list: classList,
|
|
641
653
|
key_filter: keyFilter,
|
|
642
654
|
topic_filter: topicFilter,
|
|
643
655
|
subscription_group: subscriptionGroup
|
|
@@ -649,21 +661,31 @@
|
|
|
649
661
|
/**
|
|
650
662
|
* Introduce a new key if not already known and return local key ID.
|
|
651
663
|
* @param {string} name - Key name
|
|
652
|
-
* @param {string|null} [className=null] - Class name
|
|
664
|
+
* @param {string|Array<string>|null} [className=null] - Class name(s)
|
|
653
665
|
* @returns {number} Local key ID
|
|
654
666
|
*/
|
|
655
667
|
getAndPossiblyIntroduceKeyId(name, className = null) {
|
|
656
668
|
if (!this.localKeyMap.has(name)) {
|
|
657
669
|
const keyId = this.localKeyCounter++;
|
|
658
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
|
+
}
|
|
659
679
|
const msg = {
|
|
660
680
|
message_type: 'KeyIntroduction',
|
|
661
681
|
value: {
|
|
662
682
|
key_id: keyId,
|
|
663
|
-
name
|
|
664
|
-
_class: className
|
|
683
|
+
name
|
|
665
684
|
}
|
|
666
685
|
};
|
|
686
|
+
if (classList) {
|
|
687
|
+
msg.value.class_list = classList;
|
|
688
|
+
}
|
|
667
689
|
this.sendMessage(msg);
|
|
668
690
|
}
|
|
669
691
|
return this.localKeyMap.get(name);
|