jsgar 1.3.2 → 1.4.4
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 +54 -15
- package/package.json +1 -1
package/dist/gar.umd.js
CHANGED
|
@@ -41,13 +41,14 @@
|
|
|
41
41
|
* @param {boolean} [allowSelfSignedCertificate=false] - Allow self-signed certificates
|
|
42
42
|
* @param {string} [logLevel='INFO'] - Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
|
|
43
43
|
*/
|
|
44
|
-
constructor(wsEndpoint, user, heartbeatInterval = 4000, allowSelfSignedCertificate = false, logLevel = 'INFO') {
|
|
44
|
+
constructor(wsEndpoint, user, working_namespace = null, heartbeatInterval = 4000, allowSelfSignedCertificate = false, logLevel = 'INFO') {
|
|
45
45
|
this.wsEndpoint = wsEndpoint;
|
|
46
46
|
this.websocket = null;
|
|
47
47
|
this.messageQueue = [];
|
|
48
48
|
this.connected = false;
|
|
49
49
|
this.reconnectDelay = 5000; // Milliseconds
|
|
50
50
|
this.user = user;
|
|
51
|
+
this.working_namespace = working_namespace;
|
|
51
52
|
this.heartbeatInterval = heartbeatInterval;
|
|
52
53
|
this.version = 650269;
|
|
53
54
|
|
|
@@ -387,7 +388,7 @@
|
|
|
387
388
|
registerDefaultHandlers() {
|
|
388
389
|
this.registerIntroductionHandler((version, interval, user, _schema) =>
|
|
389
390
|
this.log('INFO', `Connected to server: ${user}`));
|
|
390
|
-
this.registerHeartbeatHandler((u_milliseconds) => this.log('INFO', `Heartbeat received ${u_milliseconds}
|
|
391
|
+
this.registerHeartbeatHandler((u_milliseconds) => this.log('INFO', `Heartbeat received ${u_milliseconds}ms`));
|
|
391
392
|
this.registerLogoffHandler(() => this.log('INFO', 'Logoff received'));
|
|
392
393
|
this.registerTopicIntroductionHandler((topicId, name) =>
|
|
393
394
|
this.log('DEBUG', `New server topic: ${name} (Server ID: ${topicId})`));
|
|
@@ -395,8 +396,7 @@
|
|
|
395
396
|
this.log('DEBUG', `New server key: ${name} (Server ID: ${keyId})`));
|
|
396
397
|
this.registerDeleteKeyHandler((keyId) =>
|
|
397
398
|
this.log('DEBUG', `Delete key: ${this.serverKeyMap.get(keyId) || 'unknown'} (Server ID: ${keyId})`));
|
|
398
|
-
this.registerSubscriptionStatusHandler((
|
|
399
|
-
this.log('INFO', `Subscription ${name} status: ${status}`));
|
|
399
|
+
this.registerSubscriptionStatusHandler(this._defaultSubscriptionStatusHandler.bind(this));
|
|
400
400
|
this.registerDeleteRecordHandler((keyId, topicId) =>
|
|
401
401
|
this.log('DEBUG', `Delete record: ${this.serverKeyMap.get(keyId) || 'unknown'} - ${this.serverTopicMap.get(topicId) || 'unknown'}`));
|
|
402
402
|
this.registerRecordUpdateHandler((keyId, topicId, value) =>
|
|
@@ -404,6 +404,19 @@
|
|
|
404
404
|
this.registerShutdownHandler(() => this.log('INFO', 'Shutdown received'));
|
|
405
405
|
}
|
|
406
406
|
|
|
407
|
+
/**
|
|
408
|
+
* Default handler for subscription status messages.
|
|
409
|
+
* @param {string} name - Subscription name
|
|
410
|
+
* @param {string} status - Subscription status
|
|
411
|
+
*/
|
|
412
|
+
_defaultSubscriptionStatusHandler(name, status) {
|
|
413
|
+
this.log('INFO', `Subscription ${name} status: ${status}`);
|
|
414
|
+
if (status === 'NeedsContinue') {
|
|
415
|
+
this.log('INFO', `Snapshot size limit reached, sending SubscribeContinue for ${name}`);
|
|
416
|
+
this.sendSubscribeContinue(name);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
407
420
|
/**
|
|
408
421
|
* Start the client and send introduction message.
|
|
409
422
|
*/
|
|
@@ -414,7 +427,8 @@
|
|
|
414
427
|
value: {
|
|
415
428
|
version: this.version,
|
|
416
429
|
heartbeat_timeout_interval: this.heartbeatInterval,
|
|
417
|
-
user: this.user
|
|
430
|
+
user: this.user,
|
|
431
|
+
working_namespace: this.working_namespace
|
|
418
432
|
}
|
|
419
433
|
};
|
|
420
434
|
this.sendMessage(introMsg);
|
|
@@ -423,13 +437,13 @@
|
|
|
423
437
|
}
|
|
424
438
|
|
|
425
439
|
/**
|
|
426
|
-
|
|
427
|
-
|
|
440
|
+
* Wait until in-memory queue is empty and WebSocket bufferedAmount is zero.
|
|
441
|
+
*/
|
|
428
442
|
async _waitForDrain(pollMs = 50) {
|
|
429
443
|
while (
|
|
430
444
|
this.messageQueue.length > 0 ||
|
|
431
445
|
(this.websocket && this.websocket.bufferedAmount > 0)
|
|
432
|
-
|
|
446
|
+
) {
|
|
433
447
|
await new Promise(r => setTimeout(r, pollMs));
|
|
434
448
|
}
|
|
435
449
|
}
|
|
@@ -447,7 +461,7 @@
|
|
|
447
461
|
this.heartbeatIntervalId = null;
|
|
448
462
|
}
|
|
449
463
|
|
|
450
|
-
// if it's a regular stop, wait for send
|
|
464
|
+
// if it's a regular stop, wait for send-queue + socket to drain
|
|
451
465
|
if (this.connected && this.websocket) {
|
|
452
466
|
await this._waitForDrain();
|
|
453
467
|
}
|
|
@@ -488,6 +502,18 @@
|
|
|
488
502
|
this.messageQueue.push(message);
|
|
489
503
|
}
|
|
490
504
|
|
|
505
|
+
/**
|
|
506
|
+
* Send a SubscribeContinue message for a subscription name.
|
|
507
|
+
* @param {string} name - Subscription name
|
|
508
|
+
*/
|
|
509
|
+
sendSubscribeContinue(name) {
|
|
510
|
+
const msg = {
|
|
511
|
+
message_type: 'SubscribeContinue',
|
|
512
|
+
value: { name }
|
|
513
|
+
};
|
|
514
|
+
this.sendMessage(msg);
|
|
515
|
+
}
|
|
516
|
+
|
|
491
517
|
/**
|
|
492
518
|
* Send periodic heartbeat messages.
|
|
493
519
|
*/
|
|
@@ -574,15 +600,28 @@
|
|
|
574
600
|
* @param {string|null} [classFilter=null] - Class filter
|
|
575
601
|
* @param {string|null} [keyFilter=null] - Key filter regex
|
|
576
602
|
* @param {string|null} [topicFilter=null] - Topic filter regex
|
|
577
|
-
|
|
578
|
-
|
|
603
|
+
* @param {boolean} [allMatchingKeys=false] - Retrieve all matching keys
|
|
604
|
+
* @param {number} [snapshotSizeLimit=0] - Limit snapshot size
|
|
605
|
+
*/
|
|
606
|
+
subscribe(
|
|
607
|
+
name,
|
|
608
|
+
mode = 'Streaming',
|
|
609
|
+
keyName = null,
|
|
610
|
+
topicName = null,
|
|
611
|
+
classFilter = null,
|
|
612
|
+
keyFilter = null,
|
|
613
|
+
topicFilter = null,
|
|
614
|
+
allMatchingKeys = false,
|
|
615
|
+
snapshotSizeLimit = 0
|
|
616
|
+
) {
|
|
579
617
|
const keyId = keyName ? this.getAndPossiblyIntroduceKeyId(keyName) : 0;
|
|
580
618
|
const topicId = topicName ? this.getAndPossiblyIntroduceTopicId(topicName) : 0;
|
|
581
619
|
const subMsg = {
|
|
582
620
|
message_type: 'Subscribe',
|
|
583
621
|
value: {
|
|
584
622
|
subscription_mode: mode,
|
|
585
|
-
all_matching_keys:
|
|
623
|
+
all_matching_keys: allMatchingKeys,
|
|
624
|
+
snapshot_size_limit: snapshotSizeLimit,
|
|
586
625
|
nagle_interval: 0,
|
|
587
626
|
name,
|
|
588
627
|
key_id: keyId,
|
|
@@ -706,10 +745,10 @@
|
|
|
706
745
|
* @param {string} keyName - Key name
|
|
707
746
|
* @param {string} topicName - Topic name
|
|
708
747
|
* @param {any} value - JSON-serializable value
|
|
709
|
-
* @param
|
|
748
|
+
* @param {string|null} [className=null] - Class name
|
|
710
749
|
*/
|
|
711
|
-
publishRecord(keyName, topicName, value,
|
|
712
|
-
const keyId = this.getAndPossiblyIntroduceKeyId(keyName,
|
|
750
|
+
publishRecord(keyName, topicName, value, className = null) {
|
|
751
|
+
const keyId = this.getAndPossiblyIntroduceKeyId(keyName, className);
|
|
713
752
|
const topicId = this.getAndPossiblyIntroduceTopicId(topicName);
|
|
714
753
|
this.publishRecordWithIds(keyId, topicId, value);
|
|
715
754
|
}
|