jsgar 4.6.3 → 4.8.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.
Files changed (3) hide show
  1. package/dist/gar.umd.js +19 -3
  2. package/gar.js +19 -3
  3. package/package.json +1 -1
package/dist/gar.umd.js CHANGED
@@ -1331,13 +1331,29 @@
1331
1331
  * @param {boolean} [options.skipOwnershipChecks=false] - Bypass ownership validation.
1332
1332
  * @param {boolean} [options.requireExisting=false] - Only write to existing keys; do not create new keys.
1333
1333
  * @param {number} [options.clientKeyId=0] - The g::Client key ID for ownership. 0 uses the connection key.
1334
+ * @param {string} [options.clientKeyName=''] - If non-empty, atomically introduce this g::Client key with
1335
+ * the message. The server creates the key and maps the remote id in one round-trip; no separate
1336
+ * KeyIntroduction is sent. Ignored if the name is already mapped locally (existing id is reused).
1334
1337
  */
1335
- updateActiveOwnership({ msgRef = 0, ownershipAction = 'None', skipOwnershipChecks = false, requireExisting = false, clientKeyId = 0 } = {}) {
1338
+ updateActiveOwnership({ msgRef = 0, ownershipAction = 'None', skipOwnershipChecks = false, requireExisting = false, clientKeyId = 0, clientKeyName = '' } = {}) {
1339
+ if (clientKeyName) {
1340
+ const existingId = this.localKeyMap.get(clientKeyName);
1341
+ if (existingId !== undefined) {
1342
+ clientKeyId = existingId;
1343
+ clientKeyName = '';
1344
+ } else {
1345
+ clientKeyId = this.localKeyCounter++;
1346
+ this.localKeyMap.set(clientKeyName, clientKeyId);
1347
+ }
1348
+ }
1336
1349
  const newOwnership = { msg_ref: msgRef, ownership_action: ownershipAction, skip_ownership_checks: skipOwnershipChecks, require_existing: requireExisting, client_key_id: clientKeyId };
1337
1350
  const cur = this._activeOwnership;
1338
- if (newOwnership.msg_ref !== cur.msg_ref || newOwnership.ownership_action !== cur.ownership_action || newOwnership.skip_ownership_checks !== cur.skip_ownership_checks || newOwnership.require_existing !== cur.require_existing || newOwnership.client_key_id !== cur.client_key_id) {
1351
+ const changed = newOwnership.msg_ref !== cur.msg_ref || newOwnership.ownership_action !== cur.ownership_action || newOwnership.skip_ownership_checks !== cur.skip_ownership_checks || newOwnership.require_existing !== cur.require_existing || newOwnership.client_key_id !== cur.client_key_id;
1352
+ if (changed || clientKeyName) {
1339
1353
  this._activeOwnership = newOwnership;
1340
- this.sendMessage({ message_type: 'ActiveOwnership', value: newOwnership });
1354
+ const value = { ...newOwnership };
1355
+ if (clientKeyName) value.client_key_name = clientKeyName;
1356
+ this.sendMessage({ message_type: 'ActiveOwnership', value });
1341
1357
  }
1342
1358
  }
1343
1359
 
package/gar.js CHANGED
@@ -1325,13 +1325,29 @@ class GARClient {
1325
1325
  * @param {boolean} [options.skipOwnershipChecks=false] - Bypass ownership validation.
1326
1326
  * @param {boolean} [options.requireExisting=false] - Only write to existing keys; do not create new keys.
1327
1327
  * @param {number} [options.clientKeyId=0] - The g::Client key ID for ownership. 0 uses the connection key.
1328
+ * @param {string} [options.clientKeyName=''] - If non-empty, atomically introduce this g::Client key with
1329
+ * the message. The server creates the key and maps the remote id in one round-trip; no separate
1330
+ * KeyIntroduction is sent. Ignored if the name is already mapped locally (existing id is reused).
1328
1331
  */
1329
- updateActiveOwnership({ msgRef = 0, ownershipAction = 'None', skipOwnershipChecks = false, requireExisting = false, clientKeyId = 0 } = {}) {
1332
+ updateActiveOwnership({ msgRef = 0, ownershipAction = 'None', skipOwnershipChecks = false, requireExisting = false, clientKeyId = 0, clientKeyName = '' } = {}) {
1333
+ if (clientKeyName) {
1334
+ const existingId = this.localKeyMap.get(clientKeyName);
1335
+ if (existingId !== undefined) {
1336
+ clientKeyId = existingId;
1337
+ clientKeyName = '';
1338
+ } else {
1339
+ clientKeyId = this.localKeyCounter++;
1340
+ this.localKeyMap.set(clientKeyName, clientKeyId);
1341
+ }
1342
+ }
1330
1343
  const newOwnership = { msg_ref: msgRef, ownership_action: ownershipAction, skip_ownership_checks: skipOwnershipChecks, require_existing: requireExisting, client_key_id: clientKeyId };
1331
1344
  const cur = this._activeOwnership;
1332
- if (newOwnership.msg_ref !== cur.msg_ref || newOwnership.ownership_action !== cur.ownership_action || newOwnership.skip_ownership_checks !== cur.skip_ownership_checks || newOwnership.require_existing !== cur.require_existing || newOwnership.client_key_id !== cur.client_key_id) {
1345
+ const changed = newOwnership.msg_ref !== cur.msg_ref || newOwnership.ownership_action !== cur.ownership_action || newOwnership.skip_ownership_checks !== cur.skip_ownership_checks || newOwnership.require_existing !== cur.require_existing || newOwnership.client_key_id !== cur.client_key_id;
1346
+ if (changed || clientKeyName) {
1333
1347
  this._activeOwnership = newOwnership;
1334
- this.sendMessage({ message_type: 'ActiveOwnership', value: newOwnership });
1348
+ const value = { ...newOwnership };
1349
+ if (clientKeyName) value.client_key_name = clientKeyName;
1350
+ this.sendMessage({ message_type: 'ActiveOwnership', value });
1335
1351
  }
1336
1352
  }
1337
1353
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsgar",
3
- "version": "4.6.3",
3
+ "version": "4.8.0",
4
4
  "description": "A Javascript client for the GAR protocol",
5
5
  "type": "module",
6
6
  "main": "dist/gar.umd.js",