jsgar 1.2.3 → 1.3.1

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 +25 -8
  2. package/package.json +1 -1
package/dist/gar.umd.js CHANGED
@@ -38,8 +38,10 @@
38
38
  * @param {string} wsEndpoint - WebSocket endpoint (e.g., "ws://localhost:8765")
39
39
  * @param {string} user - Client username for identification
40
40
  * @param {number} [heartbeatInterval=4000] - Heartbeat interval in milliseconds
41
+ * @param {boolean} [allowSelfSignedCertificate=false] - Allow self-signed certificates
42
+ * @param {string} [logLevel='INFO'] - Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
41
43
  */
42
- constructor(wsEndpoint, user, heartbeatInterval = 4000, allowSelfSignedCertificate = false) {
44
+ constructor(wsEndpoint, user, heartbeatInterval = 4000, allowSelfSignedCertificate = false, logLevel = 'INFO') {
43
45
  this.wsEndpoint = wsEndpoint;
44
46
  this.websocket = null;
45
47
  this.messageQueue = [];
@@ -70,18 +72,33 @@
70
72
  this.allowSelfSignedCertificate = allowSelfSignedCertificate;
71
73
  this.exitCode = 0;
72
74
 
75
+ // Initialize log levels and set logLevel
76
+ this.logLevels = ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'];
77
+ this.logLevel = logLevel.toUpperCase();
78
+ if (!this.logLevels.includes(this.logLevel)) {
79
+ console.warn(`Invalid logLevel "${logLevel}" provided; defaulting to INFO`);
80
+ this.logLevel = 'INFO';
81
+ }
82
+
73
83
  this.registerDefaultHandlers();
74
84
  }
75
85
 
76
86
  /**
77
- * Log messages with a specific level.
78
- * @param {string} level - Log level (DEBUG, INFO, WARNING, ERROR)
87
+ * Log messages with a specific level, only if the level is at or above the configured logLevel.
88
+ * @param {string} level - Log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
79
89
  * @param {string} message - Message to log
80
- * @param {...any} args - Additional arguments
90
+ * @param {...any} args - Additional arguments
81
91
  */
82
92
  log(level, message, ...args) {
83
- const timestamp = new Date().toISOString();
84
- console.log(`${timestamp} ${level} gar.js - ${message}`, ...args);
93
+ const levelUpper = level.toUpperCase();
94
+ if (!this.logLevels.includes(levelUpper)) {
95
+ console.warn(`Invalid log level "${level}" in log call`);
96
+ return;
97
+ }
98
+ if (this.logLevels.indexOf(levelUpper) >= this.logLevels.indexOf(this.logLevel)) {
99
+ const timestamp = new Date().toISOString();
100
+ console.log(`${timestamp} ${levelUpper} gar.js - ${message}`, ...args);
101
+ }
85
102
  }
86
103
 
87
104
  /**
@@ -558,14 +575,14 @@
558
575
  * @param {string|null} [keyFilter=null] - Key filter regex
559
576
  * @param {string|null} [topicFilter=null] - Topic filter regex
560
577
  */
561
- subscribe(name, mode = 'Streaming', keyName = null, topicName = null, classFilter = null, keyFilter = null, topicFilter = null, include_unknown_keys = false) {
578
+ subscribe(name, mode = 'Streaming', keyName = null, topicName = null, classFilter = null, keyFilter = null, topicFilter = null, all_matching_keys = false) {
562
579
  const keyId = keyName ? this.getAndPossiblyIntroduceKeyId(keyName) : 0;
563
580
  const topicId = topicName ? this.getAndPossiblyIntroduceTopicId(topicName) : 0;
564
581
  const subMsg = {
565
582
  message_type: 'Subscribe',
566
583
  value: {
567
584
  subscription_mode: mode,
568
- include_unknown_keys: include_unknown_keys,
585
+ all_matching_keys: all_matching_keys,
569
586
  nagle_interval: 0,
570
587
  name,
571
588
  key_id: keyId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsgar",
3
- "version": "1.2.3",
3
+ "version": "1.3.1",
4
4
  "description": "A Javascript client for the GAR protocol",
5
5
  "type": "module",
6
6
  "main": "dist/gar.umd.js",