jsgar 3.0.0 → 3.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.
- package/dist/gar.umd.js +92 -1
- 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 = 650706;
|
|
54
54
|
|
|
55
55
|
if (typeof window !== 'undefined' && window.location) {
|
|
56
56
|
this.application = window.location.href;
|
|
@@ -343,6 +343,19 @@
|
|
|
343
343
|
}, subscriptionGroup);
|
|
344
344
|
}
|
|
345
345
|
|
|
346
|
+
/**
|
|
347
|
+
* Register handler for BatchUpdate message.
|
|
348
|
+
* If a batch handler is registered it is expected to process all the updates in the batch.
|
|
349
|
+
* If no batch handler is registered, individual key introductions and record updates will be fanned out to their respective handlers.
|
|
350
|
+
* @param {Function} handler - Callback with (batchData, subscriptionGroup)
|
|
351
|
+
* @param {number} [subscriptionGroup=0] - The subscription group for callback
|
|
352
|
+
*/
|
|
353
|
+
registerBatchUpdateHandler(handler, subscriptionGroup = 0) {
|
|
354
|
+
this.registerHandler('BatchUpdate', (msg) => {
|
|
355
|
+
handler(msg.value, subscriptionGroup);
|
|
356
|
+
}, subscriptionGroup);
|
|
357
|
+
}
|
|
358
|
+
|
|
346
359
|
/**
|
|
347
360
|
* Register a callback to handle heartbeat timeout events.
|
|
348
361
|
* @param {Function} handler - Callback with no arguments
|
|
@@ -569,6 +582,84 @@
|
|
|
569
582
|
subscriptionGroup = this.activeSubscriptionGroup;
|
|
570
583
|
const {key_id: keyId, topic_id: topicId} = message.value;
|
|
571
584
|
this.recordMap.delete(`${keyId}:${topicId}`);
|
|
585
|
+
} else if (msgType === 'BatchUpdate') {
|
|
586
|
+
subscriptionGroup = this.activeSubscriptionGroup;
|
|
587
|
+
const value = message.value;
|
|
588
|
+
const defaultClass = value.default_class;
|
|
589
|
+
|
|
590
|
+
// Check if there's a specific batch update handler
|
|
591
|
+
const batchHandlerKey = subscriptionGroup ? `BatchUpdate ${subscriptionGroup}` : 'BatchUpdate';
|
|
592
|
+
const hasBatchHandler = this.messageHandlers.has(batchHandlerKey);
|
|
593
|
+
|
|
594
|
+
// Pre-check for individual handlers if no batch handler
|
|
595
|
+
let keyHandler = null;
|
|
596
|
+
let recordHandler = null;
|
|
597
|
+
if (!hasBatchHandler) {
|
|
598
|
+
const keyHandlerKey = subscriptionGroup ? `KeyIntroduction ${subscriptionGroup}` : 'KeyIntroduction';
|
|
599
|
+
keyHandler = this.messageHandlers.get(keyHandlerKey);
|
|
600
|
+
|
|
601
|
+
const recordHandlerKey = subscriptionGroup ? `JSONRecordUpdate ${subscriptionGroup}` : 'JSONRecordUpdate';
|
|
602
|
+
recordHandler = this.messageHandlers.get(recordHandlerKey);
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
for (const keyUpdate of value.keys || []) {
|
|
606
|
+
const keyId = keyUpdate.key_id;
|
|
607
|
+
const keyName = keyUpdate.name;
|
|
608
|
+
|
|
609
|
+
// Handle key introduction if name is provided and key is new
|
|
610
|
+
if (keyName && !this.serverKeyIdToName.has(keyId)) {
|
|
611
|
+
this.serverKeyIdToName.set(keyId, keyName);
|
|
612
|
+
this.serverKeyNameToId.set(keyName, keyId);
|
|
613
|
+
|
|
614
|
+
// If no batch handler but key handler exists, call KeyIntroduction handler
|
|
615
|
+
if (!hasBatchHandler && keyHandler) {
|
|
616
|
+
// Determine class_list: use key's classes, or default_class, or null
|
|
617
|
+
let keyClasses = keyUpdate.classes;
|
|
618
|
+
if (!keyClasses && keyUpdate.class) {
|
|
619
|
+
keyClasses = [keyUpdate.class];
|
|
620
|
+
} else if (!keyClasses && defaultClass) {
|
|
621
|
+
keyClasses = [defaultClass];
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
const keyIntroMsg = {
|
|
625
|
+
message_type: 'KeyIntroduction',
|
|
626
|
+
value: {
|
|
627
|
+
key_id: keyId,
|
|
628
|
+
name: keyName,
|
|
629
|
+
...(keyClasses ? { class_list: keyClasses } : {})
|
|
630
|
+
}
|
|
631
|
+
};
|
|
632
|
+
keyHandler(keyIntroMsg);
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
// Process topics for this key - topic IDs are object keys
|
|
637
|
+
const topicsDict = keyUpdate.topics || {};
|
|
638
|
+
for (const [topicIdStr, recordValue] of Object.entries(topicsDict)) {
|
|
639
|
+
const topicId = parseInt(topicIdStr, 10);
|
|
640
|
+
this.recordMap.set(`${keyId}:${topicId}`, recordValue);
|
|
641
|
+
|
|
642
|
+
// If no batch handler but record handler exists, call JSONRecordUpdate handler
|
|
643
|
+
if (!hasBatchHandler && recordHandler) {
|
|
644
|
+
const recordUpdateMsg = {
|
|
645
|
+
message_type: 'JSONRecordUpdate',
|
|
646
|
+
value: {
|
|
647
|
+
record_id: { key_id: keyId, topic_id: topicId },
|
|
648
|
+
value: recordValue
|
|
649
|
+
}
|
|
650
|
+
};
|
|
651
|
+
recordHandler(recordUpdateMsg);
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
// If there is a batch handler, call it
|
|
657
|
+
if (hasBatchHandler) {
|
|
658
|
+
const batchHandler = this.messageHandlers.get(batchHandlerKey);
|
|
659
|
+
if (batchHandler) {
|
|
660
|
+
batchHandler(message);
|
|
661
|
+
}
|
|
662
|
+
}
|
|
572
663
|
} else if (msgType === "ActiveSubscription") {
|
|
573
664
|
this.activeSubscriptionGroup = message["value"]["subscription_group"];
|
|
574
665
|
} else if (msgType === 'Logoff') {
|