@fluidframework/container-loader 2.0.0-internal.1.1.0 → 2.0.0-internal.1.2.0.93071

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 (67) hide show
  1. package/dist/collabWindowTracker.d.ts +1 -1
  2. package/dist/collabWindowTracker.d.ts.map +1 -1
  3. package/dist/collabWindowTracker.js +2 -1
  4. package/dist/collabWindowTracker.js.map +1 -1
  5. package/dist/connectionManager.d.ts +1 -1
  6. package/dist/connectionManager.d.ts.map +1 -1
  7. package/dist/connectionManager.js +5 -5
  8. package/dist/connectionManager.js.map +1 -1
  9. package/dist/container.d.ts +10 -0
  10. package/dist/container.d.ts.map +1 -1
  11. package/dist/container.js +54 -42
  12. package/dist/container.js.map +1 -1
  13. package/dist/containerContext.d.ts +18 -7
  14. package/dist/containerContext.d.ts.map +1 -1
  15. package/dist/containerContext.js +18 -8
  16. package/dist/containerContext.js.map +1 -1
  17. package/dist/deltaManager.d.ts +1 -1
  18. package/dist/deltaManager.d.ts.map +1 -1
  19. package/dist/deltaManager.js +18 -6
  20. package/dist/deltaManager.js.map +1 -1
  21. package/dist/loader.d.ts +1 -1
  22. package/dist/loader.js.map +1 -1
  23. package/dist/packageVersion.d.ts +1 -1
  24. package/dist/packageVersion.d.ts.map +1 -1
  25. package/dist/packageVersion.js +1 -1
  26. package/dist/packageVersion.js.map +1 -1
  27. package/dist/protocol.d.ts.map +1 -1
  28. package/dist/protocol.js +2 -1
  29. package/dist/protocol.js.map +1 -1
  30. package/lib/collabWindowTracker.d.ts +1 -1
  31. package/lib/collabWindowTracker.d.ts.map +1 -1
  32. package/lib/collabWindowTracker.js +3 -2
  33. package/lib/collabWindowTracker.js.map +1 -1
  34. package/lib/connectionManager.d.ts +1 -1
  35. package/lib/connectionManager.d.ts.map +1 -1
  36. package/lib/connectionManager.js +6 -8
  37. package/lib/connectionManager.js.map +1 -1
  38. package/lib/container.d.ts +10 -0
  39. package/lib/container.d.ts.map +1 -1
  40. package/lib/container.js +56 -44
  41. package/lib/container.js.map +1 -1
  42. package/lib/containerContext.d.ts +18 -7
  43. package/lib/containerContext.d.ts.map +1 -1
  44. package/lib/containerContext.js +19 -9
  45. package/lib/containerContext.js.map +1 -1
  46. package/lib/deltaManager.d.ts +1 -1
  47. package/lib/deltaManager.d.ts.map +1 -1
  48. package/lib/deltaManager.js +18 -6
  49. package/lib/deltaManager.js.map +1 -1
  50. package/lib/loader.d.ts +1 -1
  51. package/lib/loader.js.map +1 -1
  52. package/lib/packageVersion.d.ts +1 -1
  53. package/lib/packageVersion.d.ts.map +1 -1
  54. package/lib/packageVersion.js +1 -1
  55. package/lib/packageVersion.js.map +1 -1
  56. package/lib/protocol.d.ts.map +1 -1
  57. package/lib/protocol.js +2 -1
  58. package/lib/protocol.js.map +1 -1
  59. package/package.json +12 -12
  60. package/src/collabWindowTracker.ts +4 -3
  61. package/src/connectionManager.ts +6 -6
  62. package/src/container.ts +67 -50
  63. package/src/containerContext.ts +22 -8
  64. package/src/deltaManager.ts +20 -7
  65. package/src/loader.ts +1 -1
  66. package/src/packageVersion.ts +1 -1
  67. package/src/protocol.ts +2 -1
package/dist/container.js CHANGED
@@ -961,7 +961,7 @@ class Container extends telemetry_utils_1.EventEmitterWithErrorHandling {
961
961
  async initializeProtocolState(attributes, quorumSnapshot) {
962
962
  var _a, _b;
963
963
  const protocolHandlerBuilder = (_a = this.protocolHandlerBuilder) !== null && _a !== void 0 ? _a : ((...args) => new protocol_1.ProtocolHandler(...args, new audience_1.Audience()));
964
- const protocol = protocolHandlerBuilder(attributes, quorumSnapshot, (key, value) => this.submitMessage(protocol_definitions_1.MessageType.Propose, { key, value }), (_b = this._initialClients) !== null && _b !== void 0 ? _b : []);
964
+ const protocol = protocolHandlerBuilder(attributes, quorumSnapshot, (key, value) => this.submitMessage(protocol_definitions_1.MessageType.Propose, JSON.stringify({ key, value })), (_b = this._initialClients) !== null && _b !== void 0 ? _b : []);
965
965
  this._initialClients = undefined;
966
966
  const protocolLogger = telemetry_utils_1.ChildLogger.create(this.subLogger, "ProtocolHandler");
967
967
  protocol.quorum.on("error", (error) => {
@@ -1091,6 +1091,7 @@ class Container extends telemetry_utils_1.EventEmitterWithErrorHandling {
1091
1091
  this.emit("warning", warn);
1092
1092
  });
1093
1093
  deltaManager.on("readonly", (readonly) => {
1094
+ this.setContextConnectedState(this.connectionState === connectionState_1.ConnectionState.Connected, readonly);
1094
1095
  this.emit("readonly", readonly);
1095
1096
  });
1096
1097
  deltaManager.on("closed", (error) => {
@@ -1159,39 +1160,46 @@ class Container extends telemetry_utils_1.EventEmitterWithErrorHandling {
1159
1160
  }
1160
1161
  const state = this.connectionState === connectionState_1.ConnectionState.Connected;
1161
1162
  // Both protocol and context should not be undefined if we got so far.
1162
- if (((_a = this._context) === null || _a === void 0 ? void 0 : _a.disposed) === false) {
1163
- this.context.setConnectionState(state, this.clientId);
1164
- }
1163
+ this.setContextConnectedState(state, (_a = this._deltaManager.connectionManager.readOnlyInfo.readonly) !== null && _a !== void 0 ? _a : false);
1165
1164
  this.protocolHandler.setConnectionState(state, this.clientId);
1166
1165
  (0, telemetry_utils_1.raiseConnectedEvent)(this.mc.logger, this, state, this.clientId);
1167
1166
  if (logOpsOnReconnect) {
1168
1167
  this.mc.logger.sendTelemetryEvent({ eventName: "OpsSentOnReconnect", count: this.messageCountAfterDisconnection });
1169
1168
  }
1170
1169
  }
1170
+ // back-compat: ADO #1385: Remove in the future, summary op should come through submitSummaryMessage()
1171
1171
  submitContainerMessage(type, contents, batch, metadata) {
1172
- const outboundMessageType = type;
1173
- switch (outboundMessageType) {
1172
+ switch (type) {
1174
1173
  case protocol_definitions_1.MessageType.Operation:
1175
- case protocol_definitions_1.MessageType.RemoteHelp:
1176
- break;
1177
- case protocol_definitions_1.MessageType.Summarize: {
1178
- // github #6451: this is only needed for staging so the server
1179
- // know when the protocol tree is included
1180
- // this can be removed once all clients send
1181
- // protocol tree by default
1182
- const summary = contents;
1183
- if (summary.details === undefined) {
1184
- summary.details = {};
1185
- }
1186
- summary.details.includesProtocolTree =
1187
- this.options.summarizeProtocolTree === true;
1188
- break;
1189
- }
1174
+ return this.submitMessage(type, JSON.stringify(contents), batch, metadata);
1175
+ case protocol_definitions_1.MessageType.Summarize:
1176
+ return this.submitSummaryMessage(contents);
1190
1177
  default:
1191
1178
  this.close(new container_utils_1.GenericError("invalidContainerSubmitOpType", undefined /* error */, { messageType: type }));
1192
1179
  return -1;
1193
1180
  }
1194
- return this.submitMessage(type, contents, batch, metadata);
1181
+ }
1182
+ /** @returns clientSequenceNumber of last message in a batch */
1183
+ submitBatch(batch) {
1184
+ let clientSequenceNumber = -1;
1185
+ for (const message of batch) {
1186
+ clientSequenceNumber = this.submitMessage(protocol_definitions_1.MessageType.Operation, message.contents, true, // batch
1187
+ message.metadata);
1188
+ }
1189
+ this._deltaManager.flush();
1190
+ return clientSequenceNumber;
1191
+ }
1192
+ submitSummaryMessage(summary) {
1193
+ // github #6451: this is only needed for staging so the server
1194
+ // know when the protocol tree is included
1195
+ // this can be removed once all clients send
1196
+ // protocol tree by default
1197
+ if (summary.details === undefined) {
1198
+ summary.details = {};
1199
+ }
1200
+ summary.details.includesProtocolTree =
1201
+ this.options.summarizeProtocolTree === true;
1202
+ return this.submitMessage(protocol_definitions_1.MessageType.Summarize, JSON.stringify(summary), false /* batch */);
1195
1203
  }
1196
1204
  submitMessage(type, contents, batch, metadata) {
1197
1205
  var _a;
@@ -1206,22 +1214,9 @@ class Container extends telemetry_utils_1.EventEmitterWithErrorHandling {
1206
1214
  processRemoteMessage(message) {
1207
1215
  const local = this.clientId === message.clientId;
1208
1216
  // Allow the protocol handler to process the message
1209
- let result = { immediateNoOp: false };
1210
- try {
1211
- result = this.protocolHandler.processMessage(message, local);
1212
- }
1213
- catch (error) {
1214
- this.close((0, telemetry_utils_1.wrapError)(error, (errorMessage) => new container_utils_1.DataCorruptionError(errorMessage, (0, container_utils_1.extractSafePropertiesFromMessage)(message))));
1215
- }
1216
- // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
1217
- if ((0, driver_utils_1.isUnpackedRuntimeMessage)(message) && !(0, driver_utils_1.isRuntimeMessage)(message)) {
1218
- this.mc.logger.sendTelemetryEvent({ eventName: "UnpackedRuntimeMessage", type: message.type });
1219
- }
1220
- // Forward non system messages to the loaded runtime for processing
1221
- // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
1222
- if ((0, driver_utils_1.isRuntimeMessage)(message) || (0, driver_utils_1.isUnpackedRuntimeMessage)(message)) {
1223
- this.context.process(message, local, undefined);
1224
- }
1217
+ const result = this.protocolHandler.processMessage(message, local);
1218
+ // Forward messages to the loaded runtime for processing
1219
+ this.context.process(message, local, undefined);
1225
1220
  // Inactive (not in quorum or not writers) clients don't take part in the minimum sequence number calculation.
1226
1221
  if (this.activeConnection()) {
1227
1222
  if (this.collabWindowTracker === undefined) {
@@ -1230,15 +1225,14 @@ class Container extends telemetry_utils_1.EventEmitterWithErrorHandling {
1230
1225
  // clients.
1231
1226
  // All existing will continue to use settings they got earlier.
1232
1227
  (0, common_utils_1.assert)(this.serviceConfiguration !== undefined, 0x2e4 /* "there should be service config for active connection" */);
1233
- this.collabWindowTracker = new collabWindowTracker_1.CollabWindowTracker((type, contents) => {
1228
+ this.collabWindowTracker = new collabWindowTracker_1.CollabWindowTracker((type) => {
1234
1229
  (0, common_utils_1.assert)(this.activeConnection(), 0x241 /* "disconnect should result in stopSequenceNumberUpdate() call" */);
1235
- this.submitMessage(type, contents);
1230
+ this.submitMessage(type);
1236
1231
  }, this.serviceConfiguration.noopTimeFrequency, this.serviceConfiguration.noopCountFrequency);
1237
1232
  }
1238
1233
  this.collabWindowTracker.scheduleSequenceNumberUpdate(message, result.immediateNoOp === true);
1239
1234
  }
1240
1235
  this.emit("op", message);
1241
- return result;
1242
1236
  }
1243
1237
  submitSignal(message) {
1244
1238
  this._deltaManager.submitSignal(JSON.stringify(message));
@@ -1285,7 +1279,7 @@ class Container extends telemetry_utils_1.EventEmitterWithErrorHandling {
1285
1279
  // The relative loader will proxy requests to '/' to the loader itself assuming no non-cache flags
1286
1280
  // are set. Global requests will still go directly to the loader
1287
1281
  const loader = new loader_1.RelativeLoader(this, this.loader);
1288
- this._context = await containerContext_1.ContainerContext.createOrLoad(this, this.scope, this.codeLoader, codeDetails, snapshot, new deltaManagerProxy_1.DeltaManagerProxy(this._deltaManager), new quorum_1.QuorumProxy(this.protocolHandler.quorum), loader, (type, contents, batch, metadata) => this.submitContainerMessage(type, contents, batch, metadata), (message) => this.submitSignal(message), (error) => this.close(error), Container.version, (dirty) => this.updateDirtyContainerState(dirty), existing, pendingLocalState);
1282
+ this._context = await containerContext_1.ContainerContext.createOrLoad(this, this.scope, this.codeLoader, codeDetails, snapshot, new deltaManagerProxy_1.DeltaManagerProxy(this._deltaManager), new quorum_1.QuorumProxy(this.protocolHandler.quorum), loader, (type, contents, batch, metadata) => this.submitContainerMessage(type, contents, batch, metadata), (summaryOp) => this.submitSummaryMessage(summaryOp), (batch) => this.submitBatch(batch), (message) => this.submitSignal(message), (error) => this.close(error), Container.version, (dirty) => this.updateDirtyContainerState(dirty), existing, pendingLocalState);
1289
1283
  this.emit("contextChanged", codeDetails);
1290
1284
  }
1291
1285
  updateDirtyContainerState(dirty) {
@@ -1298,6 +1292,24 @@ class Container extends telemetry_utils_1.EventEmitterWithErrorHandling {
1298
1292
  logContainerError(warning) {
1299
1293
  this.mc.logger.sendErrorEvent({ eventName: "ContainerWarning" }, warning);
1300
1294
  }
1295
+ /**
1296
+ * Set the connected state of the ContainerContext
1297
+ * This controls the "connected" state of the ContainerRuntime as well
1298
+ * @param state - Is the container currently connected?
1299
+ * @param readonly - Is the container in readonly mode?
1300
+ */
1301
+ setContextConnectedState(state, readonly) {
1302
+ var _a;
1303
+ if (((_a = this._context) === null || _a === void 0 ? void 0 : _a.disposed) === false) {
1304
+ /**
1305
+ * We want to lie to the ContainerRuntime when we are in readonly mode to prevent issues with pending
1306
+ * ops getting through to the DeltaManager.
1307
+ * The ContainerRuntime's "connected" state simply means it is ok to send ops
1308
+ * See https://dev.azure.com/fluidframework/internal/_workitems/edit/1246
1309
+ */
1310
+ this.context.setConnectionState(state && !readonly, this.clientId);
1311
+ }
1312
+ }
1301
1313
  }
1302
1314
  exports.Container = Container;
1303
1315
  Container.version = "^0.1.0";