jsgar 1.3.2 → 1.4.2

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