jsgar 4.5.0 → 4.5.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.
- package/dist/gar.umd.js +12 -22
- package/gar.js +12 -22
- package/package.json +1 -1
package/dist/gar.umd.js
CHANGED
|
@@ -72,8 +72,8 @@
|
|
|
72
72
|
this.serverKeyNameToId = new Map();
|
|
73
73
|
this.localTopicMap = new Map();
|
|
74
74
|
this.localKeyMap = new Map();
|
|
75
|
+
this.invalidatedKeyIds = new Set();
|
|
75
76
|
this.recordMap = new Map();
|
|
76
|
-
this._activeOwnership = { msg_ref: 0, ownership_action: 'None', skip_ownership_checks: false, client_key_id: 0 };
|
|
77
77
|
|
|
78
78
|
this.running = false;
|
|
79
79
|
this.heartbeatIntervalId = null;
|
|
@@ -138,9 +138,7 @@
|
|
|
138
138
|
this.localKeyCounter = 1;
|
|
139
139
|
this.localTopicMap.clear();
|
|
140
140
|
this.localKeyMap.clear();
|
|
141
|
-
|
|
142
|
-
// Active ownership state
|
|
143
|
-
this._activeOwnership = { msg_ref: 0, ownership_action: 'None', skip_ownership_checks: false, client_key_id: 0 };
|
|
141
|
+
this.invalidatedKeyIds.clear();
|
|
144
142
|
|
|
145
143
|
// Heartbeat grace period flags
|
|
146
144
|
this._initialGracePeriod = false;
|
|
@@ -757,6 +755,8 @@
|
|
|
757
755
|
if (!('name' in message.value)) message.value.name = null;
|
|
758
756
|
}
|
|
759
757
|
this.serverKeyIdToName.delete(keyId);
|
|
758
|
+
} else if (msgType === 'ClientIntroducedKeyInvalidated') {
|
|
759
|
+
this.invalidatedKeyIds.add(message.value.client_introduced_key_id);
|
|
760
760
|
} else if (msgType === 'Heartbeat') {
|
|
761
761
|
this.lastHeartbeatTime = Date.now() / 1000;
|
|
762
762
|
if (this._initialGracePeriod) {
|
|
@@ -1135,30 +1135,18 @@
|
|
|
1135
1135
|
);
|
|
1136
1136
|
}
|
|
1137
1137
|
|
|
1138
|
-
/**
|
|
1139
|
-
* Send an ActiveOwnership message if the parameters differ from the last sent values.
|
|
1140
|
-
* @param {Object} [options]
|
|
1141
|
-
* @param {number} [options.msgRef=0] - Message reference for correlating recoverable error responses.
|
|
1142
|
-
* @param {string} [options.ownershipAction='None'] - 'None' (check only), 'Acquire', or 'Release'.
|
|
1143
|
-
* @param {boolean} [options.skipOwnershipChecks=false] - Bypass ownership validation.
|
|
1144
|
-
* @param {number} [options.clientKeyId=0] - The g::Client key ID for ownership. 0 uses the connection key.
|
|
1145
|
-
*/
|
|
1146
|
-
updateActiveOwnership({ msgRef = 0, ownershipAction = 'None', skipOwnershipChecks = false, clientKeyId = 0 } = {}) {
|
|
1147
|
-
const newOwnership = { msg_ref: msgRef, ownership_action: ownershipAction, skip_ownership_checks: skipOwnershipChecks, client_key_id: clientKeyId };
|
|
1148
|
-
const cur = this._activeOwnership;
|
|
1149
|
-
if (newOwnership.msg_ref !== cur.msg_ref || newOwnership.ownership_action !== cur.ownership_action || newOwnership.skip_ownership_checks !== cur.skip_ownership_checks || newOwnership.client_key_id !== cur.client_key_id) {
|
|
1150
|
-
this._activeOwnership = newOwnership;
|
|
1151
|
-
this.sendMessage({ message_type: 'ActiveOwnership', value: newOwnership });
|
|
1152
|
-
}
|
|
1153
|
-
}
|
|
1154
|
-
|
|
1155
1138
|
/**
|
|
1156
1139
|
* Introduce a new key if not already known and return local key ID.
|
|
1157
1140
|
* @param {string} name - Key name
|
|
1158
1141
|
* @param {string|Array<string>|null} [className=null] - Class name(s)
|
|
1159
1142
|
* @returns {number} Local key ID
|
|
1160
1143
|
*/
|
|
1161
|
-
getAndPossiblyIntroduceKeyId(name, className = null) {
|
|
1144
|
+
getAndPossiblyIntroduceKeyId(name, className = null, { forceWrite = false, noAcquire = false } = {}) {
|
|
1145
|
+
const existingId = this.localKeyMap.get(name);
|
|
1146
|
+
if (existingId !== undefined && this.invalidatedKeyIds.has(existingId)) {
|
|
1147
|
+
this.invalidatedKeyIds.delete(existingId);
|
|
1148
|
+
this.localKeyMap.delete(name);
|
|
1149
|
+
}
|
|
1162
1150
|
if (!this.localKeyMap.has(name)) {
|
|
1163
1151
|
const keyId = this.localKeyCounter++;
|
|
1164
1152
|
this.localKeyMap.set(name, keyId);
|
|
@@ -1170,6 +1158,8 @@
|
|
|
1170
1158
|
value.class_list = className;
|
|
1171
1159
|
}
|
|
1172
1160
|
}
|
|
1161
|
+
if (forceWrite) value.force_write = true;
|
|
1162
|
+
if (noAcquire) value.no_acquire = true;
|
|
1173
1163
|
this.sendMessage({ message_type: 'KeyIntroduction', value });
|
|
1174
1164
|
}
|
|
1175
1165
|
return this.localKeyMap.get(name);
|
package/gar.js
CHANGED
|
@@ -66,8 +66,8 @@ class GARClient {
|
|
|
66
66
|
this.serverKeyNameToId = new Map();
|
|
67
67
|
this.localTopicMap = new Map();
|
|
68
68
|
this.localKeyMap = new Map();
|
|
69
|
+
this.invalidatedKeyIds = new Set();
|
|
69
70
|
this.recordMap = new Map();
|
|
70
|
-
this._activeOwnership = { msg_ref: 0, ownership_action: 'None', skip_ownership_checks: false, client_key_id: 0 };
|
|
71
71
|
|
|
72
72
|
this.running = false;
|
|
73
73
|
this.heartbeatIntervalId = null;
|
|
@@ -132,9 +132,7 @@ class GARClient {
|
|
|
132
132
|
this.localKeyCounter = 1;
|
|
133
133
|
this.localTopicMap.clear();
|
|
134
134
|
this.localKeyMap.clear();
|
|
135
|
-
|
|
136
|
-
// Active ownership state
|
|
137
|
-
this._activeOwnership = { msg_ref: 0, ownership_action: 'None', skip_ownership_checks: false, client_key_id: 0 };
|
|
135
|
+
this.invalidatedKeyIds.clear();
|
|
138
136
|
|
|
139
137
|
// Heartbeat grace period flags
|
|
140
138
|
this._initialGracePeriod = false;
|
|
@@ -751,6 +749,8 @@ class GARClient {
|
|
|
751
749
|
if (!('name' in message.value)) message.value.name = null;
|
|
752
750
|
}
|
|
753
751
|
this.serverKeyIdToName.delete(keyId);
|
|
752
|
+
} else if (msgType === 'ClientIntroducedKeyInvalidated') {
|
|
753
|
+
this.invalidatedKeyIds.add(message.value.client_introduced_key_id);
|
|
754
754
|
} else if (msgType === 'Heartbeat') {
|
|
755
755
|
this.lastHeartbeatTime = Date.now() / 1000;
|
|
756
756
|
if (this._initialGracePeriod) {
|
|
@@ -1129,30 +1129,18 @@ class GARClient {
|
|
|
1129
1129
|
);
|
|
1130
1130
|
}
|
|
1131
1131
|
|
|
1132
|
-
/**
|
|
1133
|
-
* Send an ActiveOwnership message if the parameters differ from the last sent values.
|
|
1134
|
-
* @param {Object} [options]
|
|
1135
|
-
* @param {number} [options.msgRef=0] - Message reference for correlating recoverable error responses.
|
|
1136
|
-
* @param {string} [options.ownershipAction='None'] - 'None' (check only), 'Acquire', or 'Release'.
|
|
1137
|
-
* @param {boolean} [options.skipOwnershipChecks=false] - Bypass ownership validation.
|
|
1138
|
-
* @param {number} [options.clientKeyId=0] - The g::Client key ID for ownership. 0 uses the connection key.
|
|
1139
|
-
*/
|
|
1140
|
-
updateActiveOwnership({ msgRef = 0, ownershipAction = 'None', skipOwnershipChecks = false, clientKeyId = 0 } = {}) {
|
|
1141
|
-
const newOwnership = { msg_ref: msgRef, ownership_action: ownershipAction, skip_ownership_checks: skipOwnershipChecks, client_key_id: clientKeyId };
|
|
1142
|
-
const cur = this._activeOwnership;
|
|
1143
|
-
if (newOwnership.msg_ref !== cur.msg_ref || newOwnership.ownership_action !== cur.ownership_action || newOwnership.skip_ownership_checks !== cur.skip_ownership_checks || newOwnership.client_key_id !== cur.client_key_id) {
|
|
1144
|
-
this._activeOwnership = newOwnership;
|
|
1145
|
-
this.sendMessage({ message_type: 'ActiveOwnership', value: newOwnership });
|
|
1146
|
-
}
|
|
1147
|
-
}
|
|
1148
|
-
|
|
1149
1132
|
/**
|
|
1150
1133
|
* Introduce a new key if not already known and return local key ID.
|
|
1151
1134
|
* @param {string} name - Key name
|
|
1152
1135
|
* @param {string|Array<string>|null} [className=null] - Class name(s)
|
|
1153
1136
|
* @returns {number} Local key ID
|
|
1154
1137
|
*/
|
|
1155
|
-
getAndPossiblyIntroduceKeyId(name, className = null) {
|
|
1138
|
+
getAndPossiblyIntroduceKeyId(name, className = null, { forceWrite = false, noAcquire = false } = {}) {
|
|
1139
|
+
const existingId = this.localKeyMap.get(name);
|
|
1140
|
+
if (existingId !== undefined && this.invalidatedKeyIds.has(existingId)) {
|
|
1141
|
+
this.invalidatedKeyIds.delete(existingId);
|
|
1142
|
+
this.localKeyMap.delete(name);
|
|
1143
|
+
}
|
|
1156
1144
|
if (!this.localKeyMap.has(name)) {
|
|
1157
1145
|
const keyId = this.localKeyCounter++;
|
|
1158
1146
|
this.localKeyMap.set(name, keyId);
|
|
@@ -1164,6 +1152,8 @@ class GARClient {
|
|
|
1164
1152
|
value.class_list = className;
|
|
1165
1153
|
}
|
|
1166
1154
|
}
|
|
1155
|
+
if (forceWrite) value.force_write = true;
|
|
1156
|
+
if (noAcquire) value.no_acquire = true;
|
|
1167
1157
|
this.sendMessage({ message_type: 'KeyIntroduction', value });
|
|
1168
1158
|
}
|
|
1169
1159
|
return this.localKeyMap.get(name);
|