jsgar 4.13.2 → 4.13.3

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 (3) hide show
  1. package/dist/gar.umd.js +25 -5
  2. package/gar.js +25 -5
  3. package/package.json +1 -1
package/dist/gar.umd.js CHANGED
@@ -1179,7 +1179,9 @@
1179
1179
  * @param {Object} opts - Named subscription options (fields below).
1180
1180
  * @param {string} opts.name - Subscription name
1181
1181
  * @param {string} [opts.subscriptionMode='Streaming'] - Subscription mode
1182
- * @param {string|Array<string>|null} [keyName=null] - Key name(s)
1182
+ * @param {string|Array<string>|Array<number>|null} [keyName=null] - Key name(s), matched
1183
+ * exactly via a synthesized key_filter alternation (keys are NOT created by
1184
+ * subscribing); an array of integers passes through as the wire key_id_list
1183
1185
  * @param {string|Array<string>|null} [topicName=null] - Topic name(s)
1184
1186
  * @param {string|Array<string>|null} [className=null] - Class name(s)
1185
1187
  * @param {string|null} [keyFilter=null] - Key filter regex (cannot use with keyName)
@@ -1258,16 +1260,24 @@
1258
1260
  referencingClasses = referencingClassList;
1259
1261
  }
1260
1262
 
1261
- let singleClass = Array.isArray(classList) && classList.length === 1 ? classList[0] : null;
1262
-
1263
- // Convert keyName to array
1263
+ // Convert keyName to array. Subscribing must NOT create keys: names are no longer
1264
+ // introduced to build a key_id_list (the old behavior materialized every named key on
1265
+ // the server). Names become an exact-match alternation key_filter instead — the server
1266
+ // recognizes the literal-alternation shape and builds a trie, skipping the full
1267
+ // regex->DFA compilation. An array of integers passes through as key_id_list verbatim
1268
+ // (the caller already holds real key ids).
1264
1269
  let keyNames = [];
1265
1270
  if (typeof keyName === 'string') {
1266
1271
  keyNames = [keyName];
1267
1272
  } else if (Array.isArray(keyName)) {
1268
1273
  keyNames = keyName;
1269
1274
  }
1270
- const keyIdList = keyNames.map(x => this.getAndPossiblyIntroduceKeyId(x, singleClass));
1275
+ let keyIdList = [];
1276
+ if (keyNames.length > 0 && keyNames.every(Number.isInteger)) {
1277
+ keyIdList = keyNames;
1278
+ } else if (keyNames.length > 0) {
1279
+ keyFilter = keyNames.map(GARClient.escapeRegex).join('|');
1280
+ }
1271
1281
 
1272
1282
  // Convert topicName to array
1273
1283
  let topicNames = [];
@@ -1849,6 +1859,16 @@
1849
1859
  });
1850
1860
  }
1851
1861
 
1862
+ /**
1863
+ * Escape TRS-regex metacharacters so `name` matches literally (TRS regexes match the
1864
+ * whole string, so an escaped name is an exact-match alternative in a key_filter).
1865
+ * @param {string} name
1866
+ * @returns {string}
1867
+ */
1868
+ static escapeRegex(name) {
1869
+ return String(name).replace(/[\\.^$|?*+()[\]{}]/g, '\\$&');
1870
+ }
1871
+
1852
1872
  static _generateUUID() {
1853
1873
  const bytes = new Uint8Array(16);
1854
1874
  if (typeof globalThis.crypto !== 'undefined' && globalThis.crypto.getRandomValues)
package/gar.js CHANGED
@@ -1172,7 +1172,9 @@ class GARClient {
1172
1172
  * @param {Object} opts - Named subscription options (fields below).
1173
1173
  * @param {string} opts.name - Subscription name
1174
1174
  * @param {string} [opts.subscriptionMode='Streaming'] - Subscription mode
1175
- * @param {string|Array<string>|null} [keyName=null] - Key name(s)
1175
+ * @param {string|Array<string>|Array<number>|null} [keyName=null] - Key name(s), matched
1176
+ * exactly via a synthesized key_filter alternation (keys are NOT created by
1177
+ * subscribing); an array of integers passes through as the wire key_id_list
1176
1178
  * @param {string|Array<string>|null} [topicName=null] - Topic name(s)
1177
1179
  * @param {string|Array<string>|null} [className=null] - Class name(s)
1178
1180
  * @param {string|null} [keyFilter=null] - Key filter regex (cannot use with keyName)
@@ -1251,16 +1253,24 @@ class GARClient {
1251
1253
  referencingClasses = referencingClassList;
1252
1254
  }
1253
1255
 
1254
- let singleClass = Array.isArray(classList) && classList.length === 1 ? classList[0] : null;
1255
-
1256
- // Convert keyName to array
1256
+ // Convert keyName to array. Subscribing must NOT create keys: names are no longer
1257
+ // introduced to build a key_id_list (the old behavior materialized every named key on
1258
+ // the server). Names become an exact-match alternation key_filter instead — the server
1259
+ // recognizes the literal-alternation shape and builds a trie, skipping the full
1260
+ // regex->DFA compilation. An array of integers passes through as key_id_list verbatim
1261
+ // (the caller already holds real key ids).
1257
1262
  let keyNames = [];
1258
1263
  if (typeof keyName === 'string') {
1259
1264
  keyNames = [keyName];
1260
1265
  } else if (Array.isArray(keyName)) {
1261
1266
  keyNames = keyName;
1262
1267
  }
1263
- const keyIdList = keyNames.map(x => this.getAndPossiblyIntroduceKeyId(x, singleClass));
1268
+ let keyIdList = [];
1269
+ if (keyNames.length > 0 && keyNames.every(Number.isInteger)) {
1270
+ keyIdList = keyNames;
1271
+ } else if (keyNames.length > 0) {
1272
+ keyFilter = keyNames.map(GARClient.escapeRegex).join('|');
1273
+ }
1264
1274
 
1265
1275
  // Convert topicName to array
1266
1276
  let topicNames = [];
@@ -1842,6 +1852,16 @@ class GARClient {
1842
1852
  });
1843
1853
  }
1844
1854
 
1855
+ /**
1856
+ * Escape TRS-regex metacharacters so `name` matches literally (TRS regexes match the
1857
+ * whole string, so an escaped name is an exact-match alternative in a key_filter).
1858
+ * @param {string} name
1859
+ * @returns {string}
1860
+ */
1861
+ static escapeRegex(name) {
1862
+ return String(name).replace(/[\\.^$|?*+()[\]{}]/g, '\\$&');
1863
+ }
1864
+
1845
1865
  static _generateUUID() {
1846
1866
  const bytes = new Uint8Array(16);
1847
1867
  if (typeof globalThis.crypto !== 'undefined' && globalThis.crypto.getRandomValues)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsgar",
3
- "version": "4.13.2",
3
+ "version": "4.13.3",
4
4
  "description": "A Javascript client for the GAR protocol",
5
5
  "type": "module",
6
6
  "main": "dist/gar.umd.js",