@fluidframework/container-loader 2.63.0-358419 → 2.63.0-359286

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 (82) hide show
  1. package/api-report/container-loader.legacy.alpha.api.md +1 -9
  2. package/dist/connectionManager.d.ts.map +1 -1
  3. package/dist/connectionManager.js +64 -49
  4. package/dist/connectionManager.js.map +1 -1
  5. package/dist/container.d.ts.map +1 -1
  6. package/dist/container.js +3 -5
  7. package/dist/container.js.map +1 -1
  8. package/dist/containerContext.d.ts +10 -22
  9. package/dist/containerContext.d.ts.map +1 -1
  10. package/dist/containerContext.js +3 -1
  11. package/dist/containerContext.js.map +1 -1
  12. package/dist/contracts.d.ts +5 -1
  13. package/dist/contracts.d.ts.map +1 -1
  14. package/dist/contracts.js.map +1 -1
  15. package/dist/createAndLoadContainerUtils.d.ts +1 -33
  16. package/dist/createAndLoadContainerUtils.d.ts.map +1 -1
  17. package/dist/createAndLoadContainerUtils.js +1 -1
  18. package/dist/createAndLoadContainerUtils.js.map +1 -1
  19. package/dist/deltaManager.d.ts.map +1 -1
  20. package/dist/deltaManager.js +56 -55
  21. package/dist/deltaManager.js.map +1 -1
  22. package/dist/frozenServices.d.ts +2 -0
  23. package/dist/frozenServices.d.ts.map +1 -1
  24. package/dist/frozenServices.js +20 -12
  25. package/dist/frozenServices.js.map +1 -1
  26. package/dist/packageVersion.d.ts +1 -1
  27. package/dist/packageVersion.js +1 -1
  28. package/dist/packageVersion.js.map +1 -1
  29. package/dist/protocol.d.ts +51 -8
  30. package/dist/protocol.d.ts.map +1 -1
  31. package/dist/protocol.js +11 -12
  32. package/dist/protocol.js.map +1 -1
  33. package/dist/serializedStateManager.d.ts +4 -3
  34. package/dist/serializedStateManager.d.ts.map +1 -1
  35. package/dist/serializedStateManager.js +63 -23
  36. package/dist/serializedStateManager.js.map +1 -1
  37. package/lib/connectionManager.d.ts.map +1 -1
  38. package/lib/connectionManager.js +18 -3
  39. package/lib/connectionManager.js.map +1 -1
  40. package/lib/container.d.ts.map +1 -1
  41. package/lib/container.js +3 -5
  42. package/lib/container.js.map +1 -1
  43. package/lib/containerContext.d.ts +10 -22
  44. package/lib/containerContext.d.ts.map +1 -1
  45. package/lib/containerContext.js +3 -1
  46. package/lib/containerContext.js.map +1 -1
  47. package/lib/contracts.d.ts +5 -1
  48. package/lib/contracts.d.ts.map +1 -1
  49. package/lib/contracts.js.map +1 -1
  50. package/lib/createAndLoadContainerUtils.d.ts +1 -33
  51. package/lib/createAndLoadContainerUtils.d.ts.map +1 -1
  52. package/lib/createAndLoadContainerUtils.js +1 -1
  53. package/lib/createAndLoadContainerUtils.js.map +1 -1
  54. package/lib/deltaManager.d.ts.map +1 -1
  55. package/lib/deltaManager.js +2 -1
  56. package/lib/deltaManager.js.map +1 -1
  57. package/lib/frozenServices.d.ts +2 -0
  58. package/lib/frozenServices.d.ts.map +1 -1
  59. package/lib/frozenServices.js +20 -12
  60. package/lib/frozenServices.js.map +1 -1
  61. package/lib/packageVersion.d.ts +1 -1
  62. package/lib/packageVersion.js +1 -1
  63. package/lib/packageVersion.js.map +1 -1
  64. package/lib/protocol.d.ts +51 -8
  65. package/lib/protocol.d.ts.map +1 -1
  66. package/lib/protocol.js +5 -6
  67. package/lib/protocol.js.map +1 -1
  68. package/lib/serializedStateManager.d.ts +4 -3
  69. package/lib/serializedStateManager.d.ts.map +1 -1
  70. package/lib/serializedStateManager.js +63 -23
  71. package/lib/serializedStateManager.js.map +1 -1
  72. package/package.json +12 -12
  73. package/src/connectionManager.ts +31 -14
  74. package/src/container.ts +9 -13
  75. package/src/containerContext.ts +34 -34
  76. package/src/contracts.ts +4 -1
  77. package/src/createAndLoadContainerUtils.ts +3 -42
  78. package/src/deltaManager.ts +12 -5
  79. package/src/frozenServices.ts +24 -12
  80. package/src/packageVersion.ts +1 -1
  81. package/src/protocol.ts +67 -10
  82. package/src/serializedStateManager.ts +60 -29
@@ -1 +1 @@
1
- {"version":3,"file":"protoc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AED;;;;GAIG;AACH,wBAAgB,kCAAkC,CACjD,OAAO,EAAE,cAAc,GACrB,OAAO,IAAI,cAAc,CAW3B"}
package/dist/protocol.js CHANGED
@@ -9,12 +9,11 @@ const internal_1 = require("@fluidframework/driver-definitions/internal");
9
9
  const internal_2 = require("@fluidframework/driver-utils/internal");
10
10
  const index_js_1 = require("./protocol/index.js");
11
11
  // ADO: #1986: Start using enum from protocol-base.
12
- var SignalType;
13
- (function (SignalType) {
14
- SignalType["ClientJoin"] = "join";
15
- SignalType["ClientLeave"] = "leave";
16
- SignalType["Clear"] = "clear";
17
- })(SignalType || (exports.SignalType = SignalType = {}));
12
+ exports.SignalType = {
13
+ ClientJoin: "join", // same value as MessageType.ClientJoin,
14
+ ClientLeave: "leave", // same value as MessageType.ClientLeave,
15
+ Clear: "clear", // used only by client for synthetic signals
16
+ };
18
17
  class ProtocolHandler extends index_js_1.ProtocolOpHandler {
19
18
  constructor(attributes, quorumSnapshot,
20
19
  // TODO: use a real type (breaking change)
@@ -53,7 +52,7 @@ class ProtocolHandler extends index_js_1.ProtocolOpHandler {
53
52
  processSignal(message) {
54
53
  const innerContent = message.content;
55
54
  switch (innerContent.type) {
56
- case SignalType.Clear: {
55
+ case exports.SignalType.Clear: {
57
56
  const members = this.audience.getMembers();
58
57
  for (const [clientId, client] of members) {
59
58
  if (client.mode === "read") {
@@ -62,7 +61,7 @@ class ProtocolHandler extends index_js_1.ProtocolOpHandler {
62
61
  }
63
62
  break;
64
63
  }
65
- case SignalType.ClientJoin: {
64
+ case exports.SignalType.ClientJoin: {
66
65
  const newClient = innerContent.content;
67
66
  // Ignore write clients - quorum will control such clients.
68
67
  if (newClient.client.mode === "read") {
@@ -70,7 +69,7 @@ class ProtocolHandler extends index_js_1.ProtocolOpHandler {
70
69
  }
71
70
  break;
72
71
  }
73
- case SignalType.ClientLeave: {
72
+ case exports.SignalType.ClientLeave: {
74
73
  const leftClientId = innerContent.content;
75
74
  // Ignore write clients - quorum will control such clients.
76
75
  if (this.audience.getMember(leftClientId)?.mode === "read") {
@@ -94,9 +93,9 @@ function protocolHandlerShouldProcessSignal(message) {
94
93
  // Signal originates from server
95
94
  if (message.clientId === null) {
96
95
  const innerContent = message.content;
97
- return (innerContent.type === SignalType.Clear ||
98
- innerContent.type === SignalType.ClientJoin ||
99
- innerContent.type === SignalType.ClientLeave);
96
+ return (innerContent.type === exports.SignalType.Clear ||
97
+ innerContent.type === exports.SignalType.ClientJoin ||
98
+ innerContent.type === exports.SignalType.ClientLeave);
100
99
  }
101
100
  return false;
102
101
  }
@@ -1 +1 @@
1
- {"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,0EAOqD;AACrD,oEAAgF;AAEhF,kDAI6B;AAE7B,mDAAmD;AACnD,IAAY,UAIX;AAJD,WAAY,UAAU;IACrB,iCAAmB,CAAA;IACnB,mCAAqB,CAAA;IACrB,6BAAe,CAAA;AAChB,CAAC,EAJW,UAAU,0BAAV,UAAU,QAIrB;AAsBD,MAAa,eAAgB,SAAQ,4BAAiB;IACrD,YACC,UAA+B,EAC/B,cAA+B;IAC/B,0CAA0C;IAC1C,8DAA8D;IAC9D,YAAiD,EACjC,QAAwB,EACvB,oBAAmD;QAEpE,KAAK,CACJ,UAAU,CAAC,qBAAqB,EAChC,UAAU,CAAC,cAAc,EACzB,cAAc,CAAC,OAAO,EACtB,cAAc,CAAC,SAAS,EACxB,cAAc,CAAC,MAAM,EACrB,YAAY,CACZ,CAAC;QAVc,aAAQ,GAAR,QAAQ,CAAgB;QACvB,yBAAoB,GAApB,oBAAoB,CAA+B;QAWpE,KAAK,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,EAAE,CAAC;YAC3D,QAAQ,CAAC,SAAS,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;QAC7C,CAAC;QAED,oFAAoF;QACpF,IA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KAAK,UAAU,CAAC,KAAK;YACtC,YAAY,CAAC,IAAI,KAAK,UAAU,CAAC,UAAU;YAC3C,YAAY,CAAC,IAAI,KAAK,UAAU,CAAC,WAAW,CAC5C,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC;AAXD,gFAWC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { IAudienceOwner } from \"@fluidframework/container-definitions/internal\";\nimport {\n\ttype IDocumentAttributes,\n\ttype IProcessMessageResult,\n\ttype ISignalClient,\n\tMessageType,\n\ttype ISequencedDocumentMessage,\n\ttype ISignalMessage,\n} from \"@fluidframework/driver-definitions/internal\";\nimport { canBeCoalescedByService } from \"@fluidframework/driver-utils/internal\";\n\nimport {\n\ttype IBaseProtocolHandler,\n\ttype IQuorumSnapshot,\n\tProtocolOpHandler,\n} from \"./protocol/index.js\";\n\n// ADO: #1986: Start using enum from protocol-base.\nexport enum SignalType {\n\tClientJoin = \"join\", // same value as MessageType.ClientJoin,\n\tClientLeave = \"leave\", // same value as MessageType.ClientLeave,\n\tClear = \"clear\", // used only by client for synthetic signals\n}\n\n/**\n * Function to be used for creating a protocol handler.\n * @legacy @beta\n */\nexport type ProtocolHandlerBuilder = (\n\tattributes: IDocumentAttributes,\n\tsnapshot: IQuorumSnapshot,\n\t// TODO: use a real type (breaking change)\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tsendProposal: (key: string, value: any) => number,\n) => IProtocolHandler;\n\n/**\n * @legacy @beta\n */\nexport interface IProtocolHandler extends IBaseProtocolHandler {\n\treadonly audience: IAudienceOwner;\n\tprocessSignal(message: ISignalMessage);\n}\n\nexport class ProtocolHandler extends ProtocolOpHandler implements IProtocolHandler {\n\tconstructor(\n\t\tattributes: IDocumentAttributes,\n\t\tquorumSnapshot: IQuorumSnapshot,\n\t\t// TODO: use a real type (breaking change)\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tsendProposal: (key: string, value: any) => number,\n\t\tpublic readonly audience: IAudienceOwner,\n\t\tprivate readonly shouldClientHaveLeft: (clientId: string) => boolean,\n\t) {\n\t\tsuper(\n\t\t\tattributes.minimumSequenceNumber,\n\t\t\tattributes.sequenceNumber,\n\t\t\tquorumSnapshot.members,\n\t\t\tquorumSnapshot.proposals,\n\t\t\tquorumSnapshot.values,\n\t\t\tsendProposal,\n\t\t);\n\n\t\tfor (const [clientId, member] of this.quorum.getMembers()) {\n\t\t\taudience.addMember(clientId, member.client);\n\t\t}\n\n\t\t// Join / leave signals are ignored for \"write\" clients in favor of join / leave ops\n\t\tthis.quorum.on(\"addMember\", (clientId, details) =>\n\t\t\taudience.addMember(clientId, details.client),\n\t\t);\n\t\tthis.quorum.on(\"removeMember\", (clientId) => audience.removeMember(clientId));\n\t}\n\n\tpublic processMessage(\n\t\tmessage: ISequencedDocumentMessage,\n\t\tlocal: boolean,\n\t): IProcessMessageResult {\n\t\t// Check and report if we're getting messages from a clientId that we previously\n\t\t// flagged as shouldHaveLeft, or from a client that's not in the quorum but should be\n\t\t// eslint-disable-next-line unicorn/no-null\n\t\tif (message.clientId != null) {\n\t\t\tconst client = this.quorum.getMember(message.clientId);\n\n\t\t\tif (client === undefined && message.type !== MessageType.ClientJoin) {\n\t\t\t\t// pre-0.58 error message: messageClientIdMissingFromQuorum\n\t\t\t\tthrow new Error(\"Remote message's clientId is missing from the quorum\");\n\t\t\t}\n\n\t\t\t// Here checking canBeCoalescedByService is used as an approximation of \"is benign to process despite being unexpected\".\n\t\t\t// It's still not good to see these messages from unexpected clientIds, but since they don't harm the integrity of the\n\t\t\t// document we don't need to blow up aggressively.\n\t\t\tif (this.shouldClientHaveLeft(message.clientId) && !canBeCoalescedByService(message)) {\n\t\t\t\t// pre-0.58 error message: messageClientIdShouldHaveLeft\n\t\t\t\tthrow new Error(\"Remote message's clientId already should have left\");\n\t\t\t}\n\t\t}\n\n\t\treturn super.processMessage(message, local);\n\t}\n\n\tpublic processSignal(message: ISignalMessage): void {\n\t\tconst innerContent = message.content as { content: unknown; type: string };\n\t\tswitch (innerContent.type) {\n\t\t\tcase SignalType.Clear: {\n\t\t\t\tconst members = this.audience.getMembers();\n\t\t\t\tfor (const [clientId, client] of members) {\n\t\t\t\t\tif (client.mode === \"read\") {\n\t\t\t\t\t\tthis.audience.removeMember(clientId);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SignalType.ClientJoin: {\n\t\t\t\tconst newClient = innerContent.content as ISignalClient;\n\t\t\t\t// Ignore write clients - quorum will control such clients.\n\t\t\t\tif (newClient.client.mode === \"read\") {\n\t\t\t\t\tthis.audience.addMember(newClient.clientId, newClient.client);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SignalType.ClientLeave: {\n\t\t\t\tconst leftClientId = innerContent.content as string;\n\t\t\t\t// Ignore write clients - quorum will control such clients.\n\t\t\t\tif (this.audience.getMember(leftClientId)?.mode === \"read\") {\n\t\t\t\t\tthis.audience.removeMember(leftClientId);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n}\n\n/**\n * Function to check whether the protocol handler should process the Signal.\n * The protocol handler should strictly handle only ClientJoin, ClientLeave\n * and Clear signal types.\n */\nexport function protocolHandlerShouldProcessSignal(message: ISignalMessage): boolean {\n\t// Signal originates from server\n\tif (message.clientId === null) {\n\t\tconst innerContent = message.content as { content: unknown; type: string };\n\t\treturn (\n\t\t\tinnerContent.type === SignalType.Clear ||\n\t\t\tinnerContent.type === SignalType.ClientJoin ||\n\t\t\tinnerContent.type === SignalType.ClientLeave\n\t\t);\n\t}\n\treturn false;\n}\n"]}
1
+ {"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,0EAOqD;AACrD,oEAAgF;AA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MAAM,EAAE,CAAC;oBACtC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,SAAS,CAAC,QAAQ,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;gBAC/D,CAAC;gBACD,MAAM;YACP,CAAC;YACD,KAAK,kBAAU,CAAC,WAAW,CAAC,CAAC,CAAC;gBAC7B,MAAM,YAAY,GAAG,YAAY,CAAC,OAAO,CAAC;gBAC1C,2DAA2D;gBAC3D,IAAI,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,YAAY,CAAC,EAAE,IAAI,KAAK,MAAM,EAAE,CAAC;oBAC5D,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;gBAC1C,CAAC;gBACD,MAAM;YACP,CAAC;YACD,OAAO,CAAC,CAAC,CAAC;gBACT,MAAM;YACP,CAAC;QACF,CAAC;IACF,CAAC;CACD;AA1FD,0CA0FC;AAED;;;;GAIG;AACH,SAAgB,kCAAkC,CACjD,OAAuB;IAEvB,gCAAgC;IAChC,IAAI,OAAO,CAAC,QAAQ,KAAK,IAAI,EAAE,CAAC;QAC/B,MAAM,YAAY,GAAG,OAAO,CAAC,OAA6C,CAAC;QAC3E,OAAO,CACN,YAAY,CAAC,IAAI,KAAK,kBAAU,CAAC,KAAK;YACtC,YAAY,CAAC,IAAI,KAAK,kBAAU,CAAC,UAAU;YAC3C,YAAY,CAAC,IAAI,KAAK,kBAAU,CAAC,WAAW,CAC5C,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC;AAbD,gFAaC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { IAudienceOwner } from \"@fluidframework/container-definitions/internal\";\nimport {\n\ttype IDocumentAttributes,\n\ttype IProcessMessageResult,\n\ttype ISignalClient,\n\tMessageType,\n\ttype ISequencedDocumentMessage,\n\ttype ISignalMessage,\n} from \"@fluidframework/driver-definitions/internal\";\nimport { canBeCoalescedByService } from \"@fluidframework/driver-utils/internal\";\n\nimport {\n\ttype IBaseProtocolHandler,\n\ttype IQuorumSnapshot,\n\tProtocolOpHandler,\n} from \"./protocol/index.js\";\n\n// ADO: #1986: Start using enum from protocol-base.\nexport const SignalType = {\n\tClientJoin: \"join\", // same value as MessageType.ClientJoin,\n\tClientLeave: \"leave\", // same value as MessageType.ClientLeave,\n\tClear: \"clear\", // used only by client for synthetic signals\n} as const;\n\ninterface SystemSignalContent {\n\ttype: (typeof SignalType)[keyof typeof SignalType];\n\tcontent?: unknown;\n}\n\ninterface InboundSystemSignal<TSignalContent extends SystemSignalContent>\n\textends ISignalMessage<{ type: never; content: TSignalContent }> {\n\t// eslint-disable-next-line @rushstack/no-new-null -- `null` is used in JSON protocol to indicate system message\n\treadonly clientId: null;\n}\n\ntype ClientJoinSignal = InboundSystemSignal<{\n\ttype: typeof SignalType.ClientJoin;\n\tcontent: ISignalClient;\n}>;\n\ntype ClientLeaveSignal = InboundSystemSignal<{\n\ttype: typeof SignalType.ClientLeave;\n\tcontent: string; // clientId of leaving client\n}>;\n\ntype ClearClientsSignal = InboundSystemSignal<{\n\ttype: typeof SignalType.Clear;\n}>;\n\ntype AudienceSignal = ClientJoinSignal | ClientLeaveSignal | ClearClientsSignal;\n\n/**\n * Function to be used for creating a protocol handler.\n * @legacy @beta\n */\nexport type ProtocolHandlerBuilder = (\n\tattributes: IDocumentAttributes,\n\tsnapshot: IQuorumSnapshot,\n\t// TODO: use a real type (breaking change)\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tsendProposal: (key: string, value: any) => number,\n) => IProtocolHandler;\n\n/**\n * @legacy @beta\n */\nexport interface IProtocolHandler extends IBaseProtocolHandler {\n\treadonly audience: IAudienceOwner;\n\tprocessSignal(message: ISignalMessage);\n}\n\n/**\n * More specific version of {@link IProtocolHandler} with narrower call\n * constraints for {@link IProtocolHandler.processSignal}.\n */\nexport interface ProtocolHandlerInternal extends IProtocolHandler {\n\t/**\n\t * Process the audience related signal.\n\t * @privateRemarks\n\t * Internally, only {@link AudienceSignal} messages need handling.\n\t */\n\tprocessSignal(message: AudienceSignal): void;\n}\n\n/**\n * Function to be used for creating a protocol handler.\n *\n * @remarks This is the same are {@link ProtocolHandlerBuilder} but\n * returns the {@link ProtocolHandlerInternal} which has narrower\n * expectations for `processSignal`.\n */\nexport type InternalProtocolHandlerBuilder = (\n\tattributes: IDocumentAttributes,\n\tsnapshot: IQuorumSnapshot,\n\t// TODO: use a real type (breaking change)\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tsendProposal: (key: string, value: any) => number,\n) => ProtocolHandlerInternal;\n\nexport class ProtocolHandler extends ProtocolOpHandler implements ProtocolHandlerInternal {\n\tconstructor(\n\t\tattributes: IDocumentAttributes,\n\t\tquorumSnapshot: IQuorumSnapshot,\n\t\t// TODO: use a real type (breaking change)\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tsendProposal: (key: string, value: any) => number,\n\t\tpublic readonly audience: IAudienceOwner,\n\t\tprivate readonly shouldClientHaveLeft: (clientId: string) => boolean,\n\t) {\n\t\tsuper(\n\t\t\tattributes.minimumSequenceNumber,\n\t\t\tattributes.sequenceNumber,\n\t\t\tquorumSnapshot.members,\n\t\t\tquorumSnapshot.proposals,\n\t\t\tquorumSnapshot.values,\n\t\t\tsendProposal,\n\t\t);\n\n\t\tfor (const [clientId, member] of this.quorum.getMembers()) {\n\t\t\taudience.addMember(clientId, member.client);\n\t\t}\n\n\t\t// Join / leave signals are ignored for \"write\" clients in favor of join / leave ops\n\t\tthis.quorum.on(\"addMember\", (clientId, details) =>\n\t\t\taudience.addMember(clientId, details.client),\n\t\t);\n\t\tthis.quorum.on(\"removeMember\", (clientId) => audience.removeMember(clientId));\n\t}\n\n\tpublic processMessage(\n\t\tmessage: ISequencedDocumentMessage,\n\t\tlocal: boolean,\n\t): IProcessMessageResult {\n\t\t// Check and report if we're getting messages from a clientId that we previously\n\t\t// flagged as shouldHaveLeft, or from a client that's not in the quorum but should be\n\t\t// eslint-disable-next-line unicorn/no-null\n\t\tif (message.clientId != null) {\n\t\t\tconst client = this.quorum.getMember(message.clientId);\n\n\t\t\tif (client === undefined && message.type !== MessageType.ClientJoin) {\n\t\t\t\t// pre-0.58 error message: messageClientIdMissingFromQuorum\n\t\t\t\tthrow new Error(\"Remote message's clientId is missing from the quorum\");\n\t\t\t}\n\n\t\t\t// Here checking canBeCoalescedByService is used as an approximation of \"is benign to process despite being unexpected\".\n\t\t\t// It's still not good to see these messages from unexpected clientIds, but since they don't harm the integrity of the\n\t\t\t// document we don't need to blow up aggressively.\n\t\t\tif (this.shouldClientHaveLeft(message.clientId) && !canBeCoalescedByService(message)) {\n\t\t\t\t// pre-0.58 error message: messageClientIdShouldHaveLeft\n\t\t\t\tthrow new Error(\"Remote message's clientId already should have left\");\n\t\t\t}\n\t\t}\n\n\t\treturn super.processMessage(message, local);\n\t}\n\n\tpublic processSignal(message: AudienceSignal): void {\n\t\tconst innerContent = message.content;\n\t\tswitch (innerContent.type) {\n\t\t\tcase SignalType.Clear: {\n\t\t\t\tconst members = this.audience.getMembers();\n\t\t\t\tfor (const [clientId, client] of members) {\n\t\t\t\t\tif (client.mode === \"read\") {\n\t\t\t\t\t\tthis.audience.removeMember(clientId);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SignalType.ClientJoin: {\n\t\t\t\tconst newClient = innerContent.content;\n\t\t\t\t// Ignore write clients - quorum will control such clients.\n\t\t\t\tif (newClient.client.mode === \"read\") {\n\t\t\t\t\tthis.audience.addMember(newClient.clientId, newClient.client);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SignalType.ClientLeave: {\n\t\t\t\tconst leftClientId = innerContent.content;\n\t\t\t\t// Ignore write clients - quorum will control such clients.\n\t\t\t\tif (this.audience.getMember(leftClientId)?.mode === \"read\") {\n\t\t\t\t\tthis.audience.removeMember(leftClientId);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n}\n\n/**\n * Function to check whether the protocol handler should process the Signal.\n * The protocol handler should strictly handle only ClientJoin, ClientLeave\n * and Clear signal types.\n */\nexport function protocolHandlerShouldProcessSignal(\n\tmessage: ISignalMessage,\n): message is AudienceSignal {\n\t// Signal originates from server\n\tif (message.clientId === null) {\n\t\tconst innerContent = message.content as { content: unknown; type: string };\n\t\treturn (\n\t\t\tinnerContent.type === SignalType.Clear ||\n\t\t\tinnerContent.type === SignalType.ClientJoin ||\n\t\t\tinnerContent.type === SignalType.ClientLeave\n\t\t);\n\t}\n\treturn false;\n}\n"]}
@@ -4,7 +4,7 @@
4
4
  */
5
5
  import type { IRuntime } from "@fluidframework/container-definitions/internal";
6
6
  import type { IEventProvider, IEvent, ITelemetryBaseLogger } from "@fluidframework/core-interfaces";
7
- import { type IDocumentStorageService, type IResolvedUrl, type ISnapshot, type ISnapshotTree, type IVersion, type ISequencedDocumentMessage } from "@fluidframework/driver-definitions/internal";
7
+ import { type IDocumentStorageService, type IResolvedUrl, type ISnapshot, type IDocumentAttributes, type ISnapshotTree, type IVersion, type ISequencedDocumentMessage } from "@fluidframework/driver-definitions/internal";
8
8
  import { type MonitoringContext } from "@fluidframework/telemetry-utils/internal";
9
9
  import { type ISerializableBlobContents } from "./containerStorageAdapter.js";
10
10
  /**
@@ -113,7 +113,7 @@ export declare class SerializedStateManager {
113
113
  private readonly mc;
114
114
  private snapshot;
115
115
  private latestSnapshot;
116
- private _refreshSnapshotP;
116
+ private readonly refreshTracker;
117
117
  private readonly lastSavedOpSequenceNumber;
118
118
  private readonly refreshTimer;
119
119
  private readonly snapshotRefreshTimeoutMs;
@@ -132,7 +132,7 @@ export declare class SerializedStateManager {
132
132
  * only intended to be used for testing purposes.
133
133
  * @returns The snapshot sequence number associated with the latest fetched snapshot
134
134
  */
135
- get refreshSnapshotP(): Promise<number> | undefined;
135
+ get refreshSnapshotP(): Promise<number | undefined> | undefined;
136
136
  /**
137
137
  * Called whenever an incoming op is processed by the Container
138
138
  */
@@ -150,6 +150,7 @@ export declare class SerializedStateManager {
150
150
  fetchSnapshot(specifiedVersion: string | undefined): Promise<{
151
151
  baseSnapshot: ISnapshot | ISnapshotTree;
152
152
  version: IVersion | undefined;
153
+ attributes: IDocumentAttributes;
153
154
  }>;
154
155
  private tryRefreshSnapshot;
155
156
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"serializedStateManager.d.ts","sourceRoot":"","sources":["../src/serializedStateManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gDAAgD,CAAC;AAC/E,OAAO,KAAK,EACX,cAAc,EACd,MAAM,EACN,oBAAoB,EAEpB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAEN,KAAK,uBAAuB,EAC5B,KAAK,YAAY,EACjB,KAAK,SAAS,EAEd,KAAK,aAAa,EAClB,KAAK,QAAQ,EACb,KAAK,yBAAyB,EAC9B,MAAM,6CAA6C,CAAC;AAErD,OAAO,EACN,KAAK,iBAAiB,EAKtB,MAAM,0CAA0C,CAAC;AAElD,OAAO,EACN,KAAK,yBAAyB,EAE9B,MAAM,8BAA8B,CAAC;AAGtC;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IACjC;;OAEG;IACH,YAAY,EAAE,aAAa,CAAC;IAC5B;;;OAGG;IACH,aAAa,EAAE,yBAAyB,CAAC;CACzC;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,sBAAuB,SAAQ,iBAAiB;IAChE;;OAEG;IACH,QAAQ,EAAE,IAAI,CAAC;IACf;;;OAGG;IACH,mBAAmB,EAAE,OAAO,CAAC;IAC7B;;OAEG;IACH,sBAAsB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IACvD;;;;OAIG;IACH,QAAQ,EAAE,yBAAyB,EAAE,C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
  * Licensed under the MIT License.
5
5
  */
6
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
7
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
8
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
9
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
10
+ };
11
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
12
+ if (kind === "m") throw new TypeError("Private method is not writable");
13
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
14
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
15
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
16
+ };
17
+ var _RefreshPromiseTracker_promise;
6
18
  Object.defineProperty(exports, "__esModule", { value: true });
7
19
  exports.fetchISnapshotTree = exports.fetchISnapshot = exports.getLatestSnapshotInfo = exports.SerializedStateManager = void 0;
8
20
  const client_utils_1 = require("@fluid-internal/client-utils");
@@ -12,6 +24,28 @@ const internal_3 = require("@fluidframework/driver-utils/internal");
12
24
  const internal_4 = require("@fluidframework/telemetry-utils/internal");
13
25
  const containerStorageAdapter_js_1 = require("./containerStorageAdapter.js");
14
26
  const utils_js_1 = require("./utils.js");
27
+ class RefreshPromiseTracker {
28
+ get hasPromise() {
29
+ return __classPrivateFieldGet(this, _RefreshPromiseTracker_promise, "f") !== undefined;
30
+ }
31
+ get Promise() {
32
+ return __classPrivateFieldGet(this, _RefreshPromiseTracker_promise, "f");
33
+ }
34
+ constructor(catchHandler) {
35
+ this.catchHandler = catchHandler;
36
+ _RefreshPromiseTracker_promise.set(this, void 0);
37
+ }
38
+ setPromise(p) {
39
+ if (this.hasPromise) {
40
+ throw new Error("Cannot set promise while promise exists");
41
+ }
42
+ __classPrivateFieldSet(this, _RefreshPromiseTracker_promise, p.finally(() => {
43
+ __classPrivateFieldSet(this, _RefreshPromiseTracker_promise, undefined, "f");
44
+ }), "f");
45
+ p.catch(this.catchHandler);
46
+ }
47
+ }
48
+ _RefreshPromiseTracker_promise = new WeakMap();
15
49
  /**
16
50
  * Helper class to manage the state of the container needed for proper serialization.
17
51
  *
@@ -35,6 +69,11 @@ class SerializedStateManager {
35
69
  this.containerDirty = containerDirty;
36
70
  this.supportGetSnapshotApi = supportGetSnapshotApi;
37
71
  this.processedOps = [];
72
+ this.refreshTracker = new RefreshPromiseTracker(
73
+ // eslint-disable-next-line unicorn/consistent-function-scoping
74
+ (error) => this.mc.logger.sendErrorEvent({
75
+ eventName: "RefreshLatestSnapshotFailed",
76
+ }, error));
38
77
  this.lastSavedOpSequenceNumber = 0;
39
78
  this.snapshotRefreshTimeoutMs = 60 * 60 * 24 * 1000;
40
79
  this.mc = (0, internal_4.createChildMonitoringContext)({
@@ -62,7 +101,7 @@ class SerializedStateManager {
62
101
  * @returns The snapshot sequence number associated with the latest fetched snapshot
63
102
  */
64
103
  get refreshSnapshotP() {
65
- return this._refreshSnapshotP;
104
+ return this.refreshTracker.Promise;
66
105
  }
67
106
  /**
68
107
  * Called whenever an incoming op is processed by the Container
@@ -87,18 +126,22 @@ class SerializedStateManager {
87
126
  if (this.pendingLocalState === undefined) {
88
127
  const { baseSnapshot, version } = await getSnapshot(this.mc, this.storageAdapter, this.supportGetSnapshotApi(), specifiedVersion);
89
128
  const baseSnapshotTree = (0, internal_3.getSnapshotTree)(baseSnapshot);
129
+ const attributes = await (0, utils_js_1.getDocumentAttributes)(this.storageAdapter, baseSnapshotTree);
90
130
  // non-interactive clients will not have any pending state we want to save
91
131
  if (this.offlineLoadEnabled) {
92
- const snapshotBlobs = await (0, containerStorageAdapter_js_1.getBlobContentsFromTree)(baseSnapshot, this.storageAdapter);
93
- const attributes = await (0, utils_js_1.getDocumentAttributes)(this.storageAdapter, baseSnapshotTree);
94
- this.snapshot = {
95
- baseSnapshot: baseSnapshotTree,
96
- snapshotBlobs,
97
- snapshotSequenceNumber: attributes.sequenceNumber,
98
- };
99
- this.refreshTimer.start();
132
+ // we defer getting the blobs to not impact the container load flow
133
+ // only getPendingState depends on the resolution of this promise
134
+ this.refreshTracker.setPromise((0, containerStorageAdapter_js_1.getBlobContentsFromTree)(baseSnapshot, this.storageAdapter).then((snapshotBlobs) => {
135
+ this.snapshot = {
136
+ baseSnapshot: baseSnapshotTree,
137
+ snapshotBlobs,
138
+ snapshotSequenceNumber: attributes.sequenceNumber,
139
+ };
140
+ this.refreshTimer.start();
141
+ return attributes.sequenceNumber;
142
+ }));
100
143
  }
101
- return { baseSnapshot, version };
144
+ return { baseSnapshot, version, attributes };
102
145
  }
103
146
  else {
104
147
  const { baseSnapshot, snapshotBlobs } = this.pendingLocalState;
@@ -121,25 +164,15 @@ class SerializedStateManager {
121
164
  ops: [],
122
165
  snapshotFormatV: 1,
123
166
  };
124
- return { baseSnapshot: iSnapshot, version: undefined };
167
+ return { baseSnapshot: iSnapshot, version: undefined, attributes };
125
168
  }
126
169
  }
127
170
  tryRefreshSnapshot() {
128
171
  if (this.mc.config.getBoolean("Fluid.Container.enableOfflineSnapshotRefresh") === true &&
129
- this._refreshSnapshotP === undefined &&
172
+ !this.refreshTracker.hasPromise &&
130
173
  this.latestSnapshot === undefined) {
131
174
  // Don't block on the refresh snapshot call - it is for the next time we serialize, not booting this incarnation
132
- this._refreshSnapshotP = this.refreshLatestSnapshot(this.supportGetSnapshotApi());
133
- this._refreshSnapshotP
134
- .catch((error) => {
135
- this.mc.logger.sendTelemetryEvent({
136
- eventName: "RefreshLatestSnapshotFailed",
137
- error,
138
- });
139
- })
140
- .finally(() => {
141
- this._refreshSnapshotP = undefined;
142
- });
175
+ this.refreshTracker.setPromise(this.refreshLatestSnapshot(this.supportGetSnapshotApi()));
143
176
  }
144
177
  }
145
178
  /**
@@ -257,6 +290,13 @@ class SerializedStateManager {
257
290
  if (!this.offlineLoadEnabled) {
258
291
  throw new internal_4.UsageError("Can't get pending local state unless offline load is enabled");
259
292
  }
293
+ if (this.snapshot === undefined && this.refreshTracker.hasPromise) {
294
+ // we deferred the initial download of the snapshot to not block
295
+ // the container load flow, so if it is not resolved
296
+ // and we don't have a snapshot, we will wait for the download
297
+ // to finish.
298
+ await this.refreshTracker.Promise;
299
+ }
260
300
  (0, internal_1.assert)(this.snapshot !== undefined, 0x8e5 /* no base data */);
261
301
  const pendingRuntimeState = await runtime.getPendingLocalState({
262
302
  notifyImminentClosure: false,
@@ -1 +1 @@
1
- {"version":3,"file":"serializedStateManager.js","sourceRoot":"","sources":["../src/serializedStateManager.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAA8D;AAQ9D,kEAAoE;AACpE,0EASqD;AACrD,oEAAwE;AACxE,uEAMkD;AAElD,6EAGsC;AACtC,yCAAkF;AAoGlF;;;;;;GAMG;AACH,MAAa,sBAAsB;IAUlC;;;;;;;OAOG;IACH,YACkB,iBAAqD,EACtE,SAA+B,EACd,cAA6D,EAC7D,mBAA4B,EAC7C,cAAgD,EAC/B,cAA6B,EAC7B,qBAAoC,EACrD,wBAAiC;QAPhB,sBAAiB,GAAjB,iBAAiB,CAAoC;QAErD,mBAAc,GAAd,cAAc,CAA+C;QAC7D,wBAAmB,GAAnB,mBAAmB,CAAS;QAE5B,mBAAc,GAAd,cAAc,CAAe;QAC7B,0BAAqB,GAArB,qBAAqB,CAAe;QAxBrC,iBAAY,GAAgC,EAAE,CAAC;QAK/C,8BAAyB,GAAW,CAAC,CAAC;QAEtC,6BAAwB,GAAW,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;QAoBvE,IAAI,CAAC,EAAE,GAAG,IAAA,uCAA4B,EAAC;YACtC,MAAM,EAAE,SAAS;YACjB,SAAS,EAAE,wBAAwB;SACnC,CAAC,CAAC;QAEH,IAAI,CAAC,wBAAwB,GAAG,wBAAwB,IAAI,IAAI,CAAC,wBAAw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GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;IAE5B,IAAI,OAAO,KAAK,SAAS,IAAI,gBAAgB,KAAK,SAAS,EAAE,CAAC;QAC7D,+EAA+E;QAC/E,EAAE,CAAC,MAAM,CAAC,cAAc,CAAC;YACxB,SAAS,EAAE,6BAA6B;YACxC,EAAE,EAAE,gBAAgB;SACpB,CAAC,CAAC;IACJ,CAAC;IACD,MAAM,QAAQ,GAAG,CAAC,MAAM,cAAc,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,IAAI,SAAS,CAAC;IAE9E,IAAI,QAAQ,KAAK,SAAS,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QACrD,EAAE,CAAC,MAAM,CAAC,cAAc,CAAC,EAAE,SAAS,EAAE,uBAAuB,EAAE,EAAE,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC;IAClF,CAAC;SAAM,IAAI,QAAQ,KAAK,SAAS,IAAI,OAAO,EAAE,EAAE,KAAK,SAAS,EAAE,CAAC;QAChE,EAAE,CAAC,MAAM,CAAC,cAAc,CAAC;YACxB,SAAS,EAAE,wCAAwC;YACnD,UAAU,EAAE,OAAO,KAAK,SAAS,EAAE,mFAAmF;SACtH,CAAC,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;AAC9B,CAAC;AA5BD,gDA4BC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { stringToBuffer } from \"@fluid-internal/client-utils\";\nimport type { IRuntime } from \"@fluidframework/container-definitions/internal\";\nimport type {\n\tIEventProvider,\n\tIEvent,\n\tITelemetryBaseLogger,\n\tTagged,\n} from \"@fluidframework/core-interfaces\";\nimport { Timer, assert } from \"@fluidframework/core-utils/internal\";\nimport {\n\tFetchSource,\n\ttype IDocumentStorageService,\n\ttype IResolvedUrl,\n\ttype ISnapshot,\n\ttype IDocumentAttributes,\n\ttype ISnapshotTree,\n\ttype IVersion,\n\ttype ISequencedDocumentMessage,\n} from \"@fluidframework/driver-definitions/internal\";\nimport { getSnapshotTree } from \"@fluidframework/driver-utils/internal\";\nimport {\n\ttype MonitoringContext,\n\tPerformanceEvent,\n\tUsageError,\n\tcreateChildMonitoringContext,\n\ttype TelemetryEventPropertyTypeExt,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport {\n\ttype ISerializableBlobContents,\n\tgetBlobContentsFromTree,\n} from \"./containerStorageAdapter.js\";\nimport { convertSnapshotToSnapshotInfo, getDocumentAttributes } from \"./utils.js\";\n\n/**\n * This is very similar to {@link @fluidframework/protocol-definitions/internal#ISnapshot}, but the difference is\n * that the blobs of ISnapshot are of type ArrayBufferLike, while the blobs of this interface are serializable because\n * they are already converted to string.\n */\nexport interface SnapshotWithBlobs {\n\t/**\n\t * Snapshot from which container initially loaded.\n\t */\n\tbaseSnapshot: ISnapshotTree;\n\t/**\n\t * Serializable blobs from the base snapshot. Used to load offline since\n\t * storage is not available.\n\t */\n\tsnapshotBlobs: ISerializableBlobContents;\n}\n\n/**\n * State saved by a container at close time, to be used to load a new instance\n * of the container to the same state\n *\n * This is very similar to {@link @fluidframework/protocol-definitions/internal#ISnapshot}, but the difference is\n * that the blobs of ISnapshot are of type ArrayBufferLike, while the blobs of this interface are serializable because\n * they are already converted to string.\n *\n * @internal\n */\nexport interface IPendingContainerState extends SnapshotWithBlobs {\n\t/**\n\t * This container was attached (as opposed to IPendingDetachedContainerState.attached which is false)\n\t */\n\tattached: true;\n\t/**\n\t * Runtime-specific state that will be needed to properly rehydrate\n\t * (it's included in ContainerContext passed to instantiateRuntime)\n\t */\n\tpendingRuntimeState: unknown;\n\t/**\n\t * Any group snapshots (aka delay-loaded) we've downloaded from the service for this container\n\t */\n\tloadedGroupIdSnapshots?: Record<string, ISnapshotInfo>;\n\t/**\n\t * All ops since base snapshot sequence number up to the latest op\n\t * seen when the container was closed. Used to apply stashed (saved pending)\n\t * ops at the same sequence number at which they were made.\n\t */\n\tsavedOps: ISequencedDocumentMessage[];\n\t/**\n\t * The Container's URL in the service, needed to hook up the driver during rehydration\n\t */\n\turl: string;\n\t/**\n\t * If the Container was connected when serialized, its clientId. Used as the initial clientId upon rehydration, until reconnected.\n\t */\n\tclientId?: string;\n}\n\n/**\n * State saved by a container in detached state, to be used to load a new instance\n * of the container to the same state (rehydrate)\n * @internal\n */\nexport interface IPendingDetachedContainerState extends SnapshotWithBlobs {\n\t/**\n\t * This container was not attached (as opposed to IPendingContainerState.attached which is true)\n\t */\n\tattached: false;\n\t/**\n\t * Indicates whether we expect the rehydrated container to have non-empty Detached Blob Storage\n\t */\n\thasAttachmentBlobs: boolean;\n\t/**\n\t * Used by the memory blob storage to persisted attachment blobs\n\t */\n\tattachmentBlobs?: string;\n\t/**\n\t * Runtime-specific state that will be needed to properly rehydrate\n\t * (it's included in ContainerContext passed to instantiateRuntime)\n\t */\n\tpendingRuntimeState?: unknown;\n}\n\nexport interface ISnapshotInfo extends SnapshotWithBlobs {\n\tsnapshotSequenceNumber: number;\n\tsnapshotFetchedTime?: number | undefined;\n}\n\nexport type ISerializedStateManagerDocumentStorageService = Pick<\n\tIDocumentStorageService,\n\t\"getSnapshot\" | \"getSnapshotTree\" | \"getVersions\" | \"readBlob\"\n> & {\n\tloadedGroupIdSnapshots: Record<string, ISnapshot>;\n};\n\ninterface ISerializerEvent extends IEvent {\n\t(event: \"saved\", listener: (dirty: boolean) => void): void;\n}\n\n/**\n * Helper class to manage the state of the container needed for proper serialization.\n *\n * It holds the pendingLocalState the container was rehydrated from (if any),\n * as well as the snapshot to be used for serialization.\n * It also keeps track of container dirty state and which local ops have been processed\n */\nexport class SerializedStateManager {\n\tprivate readonly processedOps: ISequencedDocumentMessage[] = [];\n\tprivate readonly mc: MonitoringContext;\n\tprivate snapshot: ISnapshotInfo | undefined;\n\tprivate latestSnapshot: ISnapshotInfo | undefined;\n\tprivate _refreshSnapshotP: Promise<number> | undefined;\n\tprivate readonly lastSavedOpSequenceNumber: number = 0;\n\tprivate readonly refreshTimer: Timer;\n\tprivate readonly snapshotRefreshTimeoutMs: number = 60 * 60 * 24 * 1000;\n\n\t/**\n\t * @param pendingLocalState - The pendingLocalState being rehydrated, if any (undefined when loading directly from storage)\n\t * @param subLogger - Container's logger to use as parent for our logger\n\t * @param storageAdapter - Storage adapter for fetching snapshots\n\t * @param _offlineLoadEnabled - Is serializing/rehydrating containers allowed?\n\t * @param containerEvent - Source of the \"saved\" event when the container has all its pending state uploaded\n\t * @param containerDirty - Is the container \"dirty\"? That's the opposite of \"saved\" - there is pending state that may not have been received yet by the service.\n\t */\n\tconstructor(\n\t\tprivate readonly pendingLocalState: IPendingContainerState | undefined,\n\t\tsubLogger: ITelemetryBaseLogger,\n\t\tprivate readonly storageAdapter: ISerializedStateManagerDocumentStorageService,\n\t\tprivate readonly _offlineLoadEnabled: boolean,\n\t\tcontainerEvent: IEventProvider<ISerializerEvent>,\n\t\tprivate readonly containerDirty: () => boolean,\n\t\tprivate readonly supportGetSnapshotApi: () => boolean,\n\t\tsnapshotRefreshTimeoutMs?: number,\n\t) {\n\t\tthis.mc = createChildMonitoringContext({\n\t\t\tlogger: subLogger,\n\t\t\tnamespace: \"serializedStateManager\",\n\t\t});\n\n\t\tthis.snapshotRefreshTimeoutMs = snapshotRefreshTimeoutMs ?? this.snapshotRefreshTimeoutMs;\n\t\tthis.refreshTimer = new Timer(this.snapshotRefreshTimeoutMs, () =>\n\t\t\tthis.tryRefreshSnapshot(),\n\t\t);\n\t\t// special case handle. Obtaining the last saved op seq num to avoid\n\t\t// refreshing the snapshot before we have processed it. It could cause\n\t\t// a subsequent stashing to have a newer snapshot than allowed.\n\t\tif (pendingLocalState && pendingLocalState.savedOps.length > 0) {\n\t\t\tconst savedOpsSize = pendingLocalState.savedOps.length;\n\t\t\tthis.lastSavedOpSequenceNumber =\n\t\t\t\tpendingLocalState.savedOps[savedOpsSize - 1].sequenceNumber;\n\t\t}\n\t\tcontainerEvent.on(\"saved\", () => this.updateSnapshotAndProcessedOpsMaybe());\n\t}\n\n\tpublic get offlineLoadEnabled(): boolean {\n\t\treturn this._offlineLoadEnabled;\n\t}\n\n\t/**\n\t * Promise that will resolve (or reject) once we've tried to download the latest snapshot(s) from storage\n\t * only intended to be used for testing purposes.\n\t * @returns The snapshot sequence number associated with the latest fetched snapshot\n\t */\n\tpublic get refreshSnapshotP(): Promise<number> | undefined {\n\t\treturn this._refreshSnapshotP;\n\t}\n\n\t/**\n\t * Called whenever an incoming op is processed by the Container\n\t */\n\tpublic addProcessedOp(message: ISequencedDocumentMessage): void {\n\t\tif (this.offlineLoadEnabled) {\n\t\t\tthis.processedOps.push(message);\n\t\t\tthis.updateSnapshotAndProcessedOpsMaybe();\n\t\t}\n\t}\n\n\t/**\n\t * This wraps the basic functionality of fetching the snapshot for this container during Container load.\n\t *\n\t * If we have pendingLocalState, we get the snapshot from there.\n\t * Otherwise, fetch it from storage (according to specifiedVersion if provided).\n\t *\n\t * @param specifiedVersion - If a version is specified and we don't have pendingLocalState, fetch this version from storage.\n\t * @param supportGetSnapshotApi - a boolean indicating whether to use the fetchISnapshot or fetchISnapshotTree.\n\t * @returns The snapshot to boot the container from\n\t */\n\tpublic async fetchSnapshot(specifiedVersion: string | undefined): Promise<{\n\t\tbaseSnapshot: ISnapshot | ISnapshotTree;\n\t\tversion: IVersion | undefined;\n\t}> {\n\t\tif (this.pendingLocalState === undefined) {\n\t\t\tconst { baseSnapshot, version } = await getSnapshot(\n\t\t\t\tthis.mc,\n\t\t\t\tthis.storageAdapter,\n\t\t\t\tthis.supportGetSnapshotApi(),\n\t\t\t\tspecifiedVersion,\n\t\t\t);\n\t\t\tconst baseSnapshotTree: ISnapshotTree | undefined = getSnapshotTree(baseSnapshot);\n\t\t\t// non-interactive clients will not have any pending state we want to save\n\t\t\tif (this.offlineLoadEnabled) {\n\t\t\t\tconst snapshotBlobs = await getBlobContentsFromTree(baseSnapshot, this.storageAdapter);\n\t\t\t\tconst attributes = await getDocumentAttributes(this.storageAdapter, baseSnapshotTree);\n\t\t\t\tthis.snapshot = {\n\t\t\t\t\tbaseSnapshot: baseSnapshotTree,\n\t\t\t\t\tsnapshotBlobs,\n\t\t\t\t\tsnapshotSequenceNumber: attributes.sequenceNumber,\n\t\t\t\t};\n\t\t\t\tthis.refreshTimer.start();\n\t\t\t}\n\t\t\treturn { baseSnapshot, version };\n\t\t} else {\n\t\t\tconst { baseSnapshot, snapshotBlobs } = this.pendingLocalState;\n\t\t\tconst attributes = await getDocumentAttributes(this.storageAdapter, baseSnapshot);\n\t\t\tthis.snapshot = {\n\t\t\t\tbaseSnapshot,\n\t\t\t\tsnapshotBlobs,\n\t\t\t\tsnapshotSequenceNumber: attributes.sequenceNumber,\n\t\t\t};\n\t\t\tthis.tryRefreshSnapshot();\n\t\t\tconst blobContents = new Map<string, ArrayBuffer>();\n\t\t\tfor (const [id, value] of Object.entries(snapshotBlobs)) {\n\t\t\t\tblobContents.set(id, stringToBuffer(value, \"utf8\"));\n\t\t\t}\n\t\t\tconst iSnapshot: ISnapshot = {\n\t\t\t\tsequenceNumber: this.snapshot.snapshotSequenceNumber,\n\t\t\t\tsnapshotTree: baseSnapshot,\n\t\t\t\tblobContents,\n\t\t\t\tlatestSequenceNumber: undefined,\n\t\t\t\tops: [],\n\t\t\t\tsnapshotFormatV: 1,\n\t\t\t};\n\t\t\treturn { baseSnapshot: iSnapshot, version: undefined };\n\t\t}\n\t}\n\n\tprivate tryRefreshSnapshot(): void {\n\t\tif (\n\t\t\tthis.mc.config.getBoolean(\"Fluid.Container.enableOfflineSnapshotRefresh\") === true &&\n\t\t\tthis._refreshSnapshotP === undefined &&\n\t\t\tthis.latestSnapshot === undefined\n\t\t) {\n\t\t\t// Don't block on the refresh snapshot call - it is for the next time we serialize, not booting this incarnation\n\t\t\tthis._refreshSnapshotP = this.refreshLatestSnapshot(this.supportGetSnapshotApi());\n\t\t\tthis._refreshSnapshotP\n\t\t\t\t.catch(\n\t\t\t\t\t(error: TelemetryEventPropertyTypeExt | Tagged<TelemetryEventPropertyTypeExt>) => {\n\t\t\t\t\t\tthis.mc.logger.sendTelemetryEvent({\n\t\t\t\t\t\t\teventName: \"RefreshLatestSnapshotFailed\",\n\t\t\t\t\t\t\terror,\n\t\t\t\t\t\t});\n\t\t\t\t\t},\n\t\t\t\t)\n\t\t\t\t.finally(() => {\n\t\t\t\t\tthis._refreshSnapshotP = undefined;\n\t\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Fetch the latest snapshot for the container, including delay-loaded groupIds if pendingLocalState was provided and contained any groupIds.\n\t * Note that this will update the StorageAdapter's cached snapshots for the groupIds (if present)\n\t *\n\t * @param supportGetSnapshotApi - a boolean indicating whether to use the fetchISnapshot or fetchISnapshotTree (must be true to fetch by groupIds)\n\t */\n\tprivate async refreshLatestSnapshot(supportGetSnapshotApi: boolean): Promise<number> {\n\t\tthis.latestSnapshot = await getLatestSnapshotInfo(\n\t\t\tthis.mc,\n\t\t\tthis.storageAdapter,\n\t\t\tsupportGetSnapshotApi,\n\t\t);\n\n\t\t// These are loading groupIds that the containerRuntime has requested over its lifetime.\n\t\t// We will fetch the latest snapshot for the groupIds, which will update storageAdapter.loadedGroupIdSnapshots's cache\n\t\tconst downloadedGroupIds = Object.keys(this.storageAdapter.loadedGroupIdSnapshots);\n\t\tif (supportGetSnapshotApi && downloadedGroupIds.length > 0) {\n\t\t\tassert(\n\t\t\t\tthis.storageAdapter.getSnapshot !== undefined,\n\t\t\t\t0x972 /* getSnapshot should exist */,\n\t\t\t);\n\t\t\t// (This is a separate network call from above because it requires work for storage to add a special base groupId)\n\t\t\tconst snapshot = await this.storageAdapter.getSnapshot({\n\t\t\t\tversionId: undefined,\n\t\t\t\tscenarioName: \"getLatestSnapshotInfo\",\n\t\t\t\tcacheSnapshot: false,\n\t\t\t\tloadingGroupIds: downloadedGroupIds,\n\t\t\t\tfetchSource: FetchSource.noCache,\n\t\t\t});\n\t\t\tassert(snapshot !== undefined, 0x973 /* Snapshot should exist */);\n\t\t}\n\n\t\treturn this.updateSnapshotAndProcessedOpsMaybe();\n\t}\n\n\t/**\n\t * Updates class snapshot and processedOps if we have a new snapshot and it's among processedOps range.\n\t */\n\tprivate updateSnapshotAndProcessedOpsMaybe(): number {\n\t\tconst snapshotSequenceNumber = this.latestSnapshot?.snapshotSequenceNumber;\n\t\tif (\n\t\t\tsnapshotSequenceNumber === undefined ||\n\t\t\tthis.processedOps.length === 0 ||\n\t\t\tthis.processedOps[this.processedOps.length - 1].sequenceNumber <\n\t\t\t\tthis.lastSavedOpSequenceNumber ||\n\t\t\tthis.containerDirty()\n\t\t) {\n\t\t\t// can't refresh latest snapshot until we have processed the ops up to it.\n\t\t\t// Pending state would be behind the latest snapshot.\n\t\t\treturn -1;\n\t\t}\n\t\tconst firstProcessedOpSequenceNumber = this.processedOps[0].sequenceNumber;\n\t\tconst lastProcessedOpSequenceNumber =\n\t\t\tthis.processedOps[this.processedOps.length - 1].sequenceNumber;\n\n\t\tif (snapshotSequenceNumber < firstProcessedOpSequenceNumber) {\n\t\t\t// Snapshot seq number is older than our first processed op, which could mean we're fetching\n\t\t\t// the same snapshot that we already have or snapshot is too old, implicating an unexpected behavior.\n\t\t\tthis.mc.logger.sendTelemetryEvent({\n\t\t\t\teventName: \"OldSnapshotFetchWhileRefreshing\",\n\t\t\t\tsnapshotSequenceNumber,\n\t\t\t\tfirstProcessedOpSequenceNumber,\n\t\t\t\tlastProcessedOpSequenceNumber,\n\t\t\t\tstashedSnapshotSequenceNumber: this.snapshot?.snapshotSequenceNumber,\n\t\t\t});\n\t\t\tthis.latestSnapshot = undefined;\n\t\t\tthis.refreshTimer.restart();\n\t\t} else if (snapshotSequenceNumber <= lastProcessedOpSequenceNumber) {\n\t\t\t// Snapshot seq num is between the first and last processed op.\n\t\t\t// Remove the ops that are already part of the snapshot\n\t\t\tthis.processedOps.splice(0, snapshotSequenceNumber - firstProcessedOpSequenceNumber + 1);\n\t\t\tthis.snapshot = this.latestSnapshot;\n\t\t\tthis.latestSnapshot = undefined;\n\t\t\tthis.refreshTimer.restart();\n\t\t\tthis.mc.logger.sendTelemetryEvent({\n\t\t\t\teventName: \"SnapshotRefreshed\",\n\t\t\t\tsnapshotSequenceNumber,\n\t\t\t\tfirstProcessedOpSequenceNumber,\n\t\t\t\tnewFirstProcessedOpSequenceNumber:\n\t\t\t\t\tthis.processedOps.length === 0 ? undefined : this.processedOps[0].sequenceNumber,\n\t\t\t});\n\t\t}\n\t\treturn snapshotSequenceNumber;\n\t}\n\n\t/**\n\t * When the Container attaches, we need to stash the initial snapshot (a form of the attach summary).\n\t * This method is only meant to be used by Container.attach() to set the initial\n\t * base snapshot when attaching.\n\t * @param snapshot - snapshot and blobs collected while attaching (a form of the attach summary)\n\t */\n\tpublic setInitialSnapshot(snapshot: SnapshotWithBlobs | undefined): void {\n\t\tif (this.offlineLoadEnabled) {\n\t\t\tassert(\n\t\t\t\tthis.snapshot === undefined,\n\t\t\t\t0x937 /* inital snapshot should only be defined once */,\n\t\t\t);\n\t\t\tassert(snapshot !== undefined, 0x938 /* attachment snapshot should be defined */);\n\t\t\tconst { baseSnapshot, snapshotBlobs } = snapshot;\n\t\t\tconst attributesHash =\n\t\t\t\t\".protocol\" in baseSnapshot.trees\n\t\t\t\t\t? baseSnapshot.trees[\".protocol\"].blobs.attributes\n\t\t\t\t\t: baseSnapshot.blobs[\".attributes\"];\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\t\t\tconst attributes = JSON.parse(snapshotBlobs[attributesHash]);\n\t\t\tassert(\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n\t\t\t\tattributes.sequenceNumber === 0,\n\t\t\t\t0x939 /* trying to set a non attachment snapshot */,\n\t\t\t);\n\t\t\tthis.snapshot = {\n\t\t\t\t...snapshot,\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n\t\t\t\tsnapshotSequenceNumber: attributes.sequenceNumber as number,\n\t\t\t};\n\t\t\tthis.refreshTimer.start();\n\t\t}\n\t}\n\n\t/**\n\t * Assembles and serializes the {@link IPendingContainerState} for the container,\n\t * to be stored and used to rehydrate the container at a later time.\n\t */\n\tpublic async getPendingLocalState(\n\t\tclientId: string | undefined,\n\t\truntime: Pick<IRuntime, \"getPendingLocalState\">,\n\t\tresolvedUrl: IResolvedUrl,\n\t): Promise<string> {\n\t\treturn PerformanceEvent.timedExecAsync(\n\t\t\tthis.mc.logger,\n\t\t\t{\n\t\t\t\teventName: \"getPendingLocalState\",\n\t\t\t\tdetails: {\n\t\t\t\t\tnotifyImminentClosure: false,\n\t\t\t\t\tsessionExpiryTimerStarted: undefined,\n\t\t\t\t\tsnapshotSequenceNumber: undefined,\n\t\t\t\t\tprocessedOpsSize: this.processedOps.length,\n\t\t\t\t},\n\t\t\t\tclientId,\n\t\t\t},\n\t\t\tasync () => {\n\t\t\t\tif (!this.offlineLoadEnabled) {\n\t\t\t\t\tthrow new UsageError(\"Can't get pending local state unless offline load is enabled\");\n\t\t\t\t}\n\t\t\t\tassert(this.snapshot !== undefined, 0x8e5 /* no base data */);\n\t\t\t\tconst pendingRuntimeState = await runtime.getPendingLocalState({\n\t\t\t\t\tnotifyImminentClosure: false,\n\t\t\t\t\tsnapshotSequenceNumber: this.snapshot.snapshotSequenceNumber,\n\t\t\t\t\tsessionExpiryTimerStarted: this.snapshot.snapshotFetchedTime,\n\t\t\t\t});\n\t\t\t\t// This conversion is required because ArrayBufferLike doesn't survive JSON.stringify\n\t\t\t\tconst loadedGroupIdSnapshots = {};\n\t\t\t\tlet hasGroupIdSnapshots = false;\n\t\t\t\tconst groupIdSnapshots = Object.entries(this.storageAdapter.loadedGroupIdSnapshots);\n\t\t\t\tif (groupIdSnapshots.length > 0) {\n\t\t\t\t\tfor (const [groupId, snapshot] of groupIdSnapshots) {\n\t\t\t\t\t\thasGroupIdSnapshots = true;\n\t\t\t\t\t\tloadedGroupIdSnapshots[groupId] = convertSnapshotToSnapshotInfo(snapshot);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tconst pendingState: IPendingContainerState = {\n\t\t\t\t\tattached: true,\n\t\t\t\t\tpendingRuntimeState,\n\t\t\t\t\tbaseSnapshot: this.snapshot.baseSnapshot,\n\t\t\t\t\tsnapshotBlobs: this.snapshot.snapshotBlobs,\n\t\t\t\t\tloadedGroupIdSnapshots: hasGroupIdSnapshots ? loadedGroupIdSnapshots : undefined,\n\t\t\t\t\tsavedOps: this.processedOps,\n\t\t\t\t\turl: resolvedUrl.url,\n\t\t\t\t\tclientId,\n\t\t\t\t};\n\n\t\t\t\treturn JSON.stringify(pendingState);\n\t\t\t},\n\t\t);\n\t}\n}\n\n/**\n * Retrieves the most recent snapshot and returns its info.\n *\n * @param mc - The monitoring context.\n * @param storageAdapter - The storage adapter providing methods to retrieve the snapshot.\n * @param supportGetSnapshotApi - a boolean indicating whether to use the fetchISnapshot or fetchISnapshotTree.\n * @returns a SnapshotInfo object containing the snapshot tree, snapshot blobs and its sequence number.\n */\nexport async function getLatestSnapshotInfo(\n\tmc: MonitoringContext,\n\tstorageAdapter: ISerializedStateManagerDocumentStorageService,\n\tsupportGetSnapshotApi: boolean,\n): Promise<ISnapshotInfo | undefined> {\n\treturn PerformanceEvent.timedExecAsync(\n\t\tmc.logger,\n\t\t{ eventName: \"GetLatestSnapshotInfo\" },\n\t\tasync () => {\n\t\t\t// get the latest non cached snapshot version\n\t\t\tconst specifiedVersion: IVersion[] = await storageAdapter.getVersions(\n\t\t\t\t// eslint-disable-next-line unicorn/no-null\n\t\t\t\tnull,\n\t\t\t\t1,\n\t\t\t\t\"getLatestSnapshotInfo\",\n\t\t\t\tFetchSource.noCache,\n\t\t\t);\n\t\t\tconst { baseSnapshot } = await getSnapshot(\n\t\t\t\tmc,\n\t\t\t\tstorageAdapter,\n\t\t\t\tsupportGetSnapshotApi,\n\t\t\t\tspecifiedVersion[0]?.id,\n\t\t\t);\n\n\t\t\tconst baseSnapshotTree: ISnapshotTree | undefined = getSnapshotTree(baseSnapshot);\n\t\t\tconst snapshotFetchedTime = Date.now();\n\t\t\tconst snapshotBlobs = await getBlobContentsFromTree(baseSnapshot, storageAdapter);\n\t\t\tconst attributes: IDocumentAttributes = await getDocumentAttributes(\n\t\t\t\tstorageAdapter,\n\t\t\t\tbaseSnapshotTree,\n\t\t\t);\n\t\t\tconst snapshotSequenceNumber = attributes.sequenceNumber;\n\t\t\treturn {\n\t\t\t\tbaseSnapshot: baseSnapshotTree,\n\t\t\t\tsnapshotBlobs,\n\t\t\t\tsnapshotSequenceNumber,\n\t\t\t\tsnapshotFetchedTime,\n\t\t\t};\n\t\t},\n\t).catch(() => undefined);\n}\n\n/**\n * Retrieves a snapshot from the storage adapter and transforms it into an ISnapshotTree object.\n *\n * @param mc - The monitoring context.\n * @param storageAdapter - The storage adapter providing methods to retrieve the snapshot.\n * @param supportGetSnapshotApi - a boolean indicating whether to use the fetchISnapshot or fetchISnapshotTree.\n * @param specifiedVersion - An optional version string specifying the version of the snapshot tree to fetch.\n * @returns - An ISnapshotTree and its version.\n */\nasync function getSnapshot(\n\tmc: MonitoringContext,\n\tstorageAdapter: Pick<\n\t\tIDocumentStorageService,\n\t\t\"getSnapshot\" | \"getSnapshotTree\" | \"getVersions\"\n\t>,\n\tsupportGetSnapshotApi: boolean,\n\tspecifiedVersion: string | undefined,\n): Promise<{ baseSnapshot: ISnapshot | ISnapshotTree; version?: IVersion }> {\n\tconst { snapshot, version } = supportGetSnapshotApi\n\t\t? await fetchISnapshot(mc, storageAdapter, specifiedVersion)\n\t\t: await fetchISnapshotTree(mc, storageAdapter, specifiedVersion);\n\tassert(snapshot !== undefined, 0x8e4 /* Snapshot should exist */);\n\treturn { baseSnapshot: snapshot, version };\n}\n\n/**\n * Fetches an ISnapshot from a storage adapter based on the specified version.\n *\n * @param mc - The monitoring context.\n * @param storageAdapter - The storage adapter providing a getSnapshot method to retrieve the ISnapshot and version.\n * @param specifiedVersion - An optional version string specifying the version of the snapshot tree to fetch.\n * @returns - The fetched snapshot tree and its version.\n */\nexport async function fetchISnapshot(\n\tmc: MonitoringContext,\n\tstorageAdapter: Pick<IDocumentStorageService, \"getSnapshot\">,\n\tspecifiedVersion: string | undefined,\n): Promise<{ snapshot?: ISnapshot; version?: IVersion }> {\n\tconst snapshot = await storageAdapter.getSnapshot?.({ versionId: specifiedVersion });\n\tconst version: IVersion | undefined =\n\t\tsnapshot?.snapshotTree.id === undefined\n\t\t\t? undefined\n\t\t\t: {\n\t\t\t\t\tid: snapshot.snapshotTree.id,\n\t\t\t\t\ttreeId: snapshot.snapshotTree.id,\n\t\t\t\t};\n\n\tif (snapshot === undefined && specifiedVersion !== undefined) {\n\t\tmc.logger.sendErrorEvent({\n\t\t\teventName: \"getSnapshotTreeFailed\",\n\t\t\tid: specifiedVersion,\n\t\t});\n\t} else if (snapshot !== undefined && version?.id === undefined) {\n\t\tmc.logger.sendErrorEvent({\n\t\t\teventName: \"getSnapshotFetchedTreeWithoutVersionId\",\n\t\t\thasVersion: version !== undefined, // if hasVersion is true, this means that the contract with the service was broken.\n\t\t});\n\t}\n\treturn { snapshot, version };\n}\n\n/**\n * Fetches an ISnapshotTree from a storage adapter based on the specified version.\n *\n * @param mc - The monitoring context.\n * @param storageAdapter - The storage adapter providing methods to retrieve the ISnapshotTree and version.\n * @param specifiedVersion - An optional version string specifying the version of the snapshot tree to fetch.\n * @returns - The fetched snapshot tree and its version.\n */\nexport async function fetchISnapshotTree(\n\tmc: MonitoringContext,\n\tstorageAdapter: Pick<IDocumentStorageService, \"getSnapshotTree\" | \"getVersions\">,\n\tspecifiedVersion: string | undefined,\n): Promise<{ snapshot?: ISnapshotTree; version?: IVersion | undefined }> {\n\t// API uses null\n\t// eslint-disable-next-line unicorn/no-null\n\tconst versions = await storageAdapter.getVersions(specifiedVersion ?? null, 1);\n\tconst version = versions[0];\n\n\tif (version === undefined && specifiedVersion !== undefined) {\n\t\t// We should have a defined version to load from if specified version requested\n\t\tmc.logger.sendErrorEvent({\n\t\t\teventName: \"NoVersionFoundWhenSpecified\",\n\t\t\tid: specifiedVersion,\n\t\t});\n\t}\n\tconst snapshot = (await storageAdapter.getSnapshotTree(version)) ?? undefined;\n\n\tif (snapshot === undefined && version !== undefined) {\n\t\tmc.logger.sendErrorEvent({ eventName: \"getSnapshotTreeFailed\", id: version.id });\n\t} else if (snapshot !== undefined && version?.id === undefined) {\n\t\tmc.logger.sendErrorEvent({\n\t\t\teventName: \"getSnapshotFetchedTreeWithoutVersionId\",\n\t\t\thasVersion: version !== undefined, // if hasVersion is true, this means that the contract with the service was broken.\n\t\t});\n\t}\n\treturn { snapshot, version };\n}\n"]}
1
+ {"version":3,"file":"serializedStateManager.js","sourceRoot":"","sources":["../src/serializedStateManager.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;AAEH,+DAA8D;AAO9D,kEAAoE;AACpE,0EASqD;AACrD,oEAAwE;AACxE,uEAKkD;AAElD,6EAGsC;AACtC,yCAAkF;AAoGlF,MAAM,qBAAqB;IAC1B,IAAW,UAAU;QACpB,OAAO,uBAAA,IAAI,sCAAS,KAAK,SAAS,CAAC;IACpC,CAAC;IACD,IAAW,OAAO;QACjB,OAAO,uBAAA,IAAI,sCAAS,CAAC;IACtB,CAAC;IACD,YAA6B,YAAoC;QAApC,iBAAY,GAAZ,YAAY,CAAwB;QAEjE,iDAAsC;IAF8B,CAAC;IAGrE,UAAU,CAAC,CAAkB;QAC5B,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;QAC5D,CAAC;QACD,uBAAA,IAAI,kCAAY,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE;YAC9B,uBAAA,IAAI,kCAAY,SAAS,MAAA,CAAC;QAC3B,CAAC,CAAC,MAAA,CAAC;QACH,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAC5B,CAAC;CACD;;AAED;;;;;;GAMG;A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AG,CAAC,MAAM,cAAc,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,IAAI,SAAS,CAAC;IAE9E,IAAI,QAAQ,KAAK,SAAS,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QACrD,EAAE,CAAC,MAAM,CAAC,cAAc,CAAC,EAAE,SAAS,EAAE,uBAAuB,EAAE,EAAE,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC;IAClF,CAAC;SAAM,IAAI,QAAQ,KAAK,SAAS,IAAI,OAAO,EAAE,EAAE,KAAK,SAAS,EAAE,CAAC;QAChE,EAAE,CAAC,MAAM,CAAC,cAAc,CAAC;YACxB,SAAS,EAAE,wCAAwC;YACnD,UAAU,EAAE,OAAO,KAAK,SAAS,EAAE,mFAAmF;SACtH,CAAC,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;AAC9B,CAAC;AA5BD,gDA4BC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { stringToBuffer } from \"@fluid-internal/client-utils\";\nimport type { IRuntime } from \"@fluidframework/container-definitions/internal\";\nimport type {\n\tIEventProvider,\n\tIEvent,\n\tITelemetryBaseLogger,\n} from \"@fluidframework/core-interfaces\";\nimport { Timer, assert } from \"@fluidframework/core-utils/internal\";\nimport {\n\tFetchSource,\n\ttype IDocumentStorageService,\n\ttype IResolvedUrl,\n\ttype ISnapshot,\n\ttype IDocumentAttributes,\n\ttype ISnapshotTree,\n\ttype IVersion,\n\ttype ISequencedDocumentMessage,\n} from \"@fluidframework/driver-definitions/internal\";\nimport { getSnapshotTree } from \"@fluidframework/driver-utils/internal\";\nimport {\n\ttype MonitoringContext,\n\tPerformanceEvent,\n\tUsageError,\n\tcreateChildMonitoringContext,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport {\n\ttype ISerializableBlobContents,\n\tgetBlobContentsFromTree,\n} from \"./containerStorageAdapter.js\";\nimport { convertSnapshotToSnapshotInfo, getDocumentAttributes } from \"./utils.js\";\n\n/**\n * This is very similar to {@link @fluidframework/protocol-definitions/internal#ISnapshot}, but the difference is\n * that the blobs of ISnapshot are of type ArrayBufferLike, while the blobs of this interface are serializable because\n * they are already converted to string.\n */\nexport interface SnapshotWithBlobs {\n\t/**\n\t * Snapshot from which container initially loaded.\n\t */\n\tbaseSnapshot: ISnapshotTree;\n\t/**\n\t * Serializable blobs from the base snapshot. Used to load offline since\n\t * storage is not available.\n\t */\n\tsnapshotBlobs: ISerializableBlobContents;\n}\n\n/**\n * State saved by a container at close time, to be used to load a new instance\n * of the container to the same state\n *\n * This is very similar to {@link @fluidframework/protocol-definitions/internal#ISnapshot}, but the difference is\n * that the blobs of ISnapshot are of type ArrayBufferLike, while the blobs of this interface are serializable because\n * they are already converted to string.\n *\n * @internal\n */\nexport interface IPendingContainerState extends SnapshotWithBlobs {\n\t/**\n\t * This container was attached (as opposed to IPendingDetachedContainerState.attached which is false)\n\t */\n\tattached: true;\n\t/**\n\t * Runtime-specific state that will be needed to properly rehydrate\n\t * (it's included in ContainerContext passed to instantiateRuntime)\n\t */\n\tpendingRuntimeState: unknown;\n\t/**\n\t * Any group snapshots (aka delay-loaded) we've downloaded from the service for this container\n\t */\n\tloadedGroupIdSnapshots?: Record<string, ISnapshotInfo>;\n\t/**\n\t * All ops since base snapshot sequence number up to the latest op\n\t * seen when the container was closed. Used to apply stashed (saved pending)\n\t * ops at the same sequence number at which they were made.\n\t */\n\tsavedOps: ISequencedDocumentMessage[];\n\t/**\n\t * The Container's URL in the service, needed to hook up the driver during rehydration\n\t */\n\turl: string;\n\t/**\n\t * If the Container was connected when serialized, its clientId. Used as the initial clientId upon rehydration, until reconnected.\n\t */\n\tclientId?: string;\n}\n\n/**\n * State saved by a container in detached state, to be used to load a new instance\n * of the container to the same state (rehydrate)\n * @internal\n */\nexport interface IPendingDetachedContainerState extends SnapshotWithBlobs {\n\t/**\n\t * This container was not attached (as opposed to IPendingContainerState.attached which is true)\n\t */\n\tattached: false;\n\t/**\n\t * Indicates whether we expect the rehydrated container to have non-empty Detached Blob Storage\n\t */\n\thasAttachmentBlobs: boolean;\n\t/**\n\t * Used by the memory blob storage to persisted attachment blobs\n\t */\n\tattachmentBlobs?: string;\n\t/**\n\t * Runtime-specific state that will be needed to properly rehydrate\n\t * (it's included in ContainerContext passed to instantiateRuntime)\n\t */\n\tpendingRuntimeState?: unknown;\n}\n\nexport interface ISnapshotInfo extends SnapshotWithBlobs {\n\tsnapshotSequenceNumber: number;\n\tsnapshotFetchedTime?: number | undefined;\n}\n\nexport type ISerializedStateManagerDocumentStorageService = Pick<\n\tIDocumentStorageService,\n\t\"getSnapshot\" | \"getSnapshotTree\" | \"getVersions\" | \"readBlob\"\n> & {\n\tloadedGroupIdSnapshots: Record<string, ISnapshot>;\n};\n\ninterface ISerializerEvent extends IEvent {\n\t(event: \"saved\", listener: (dirty: boolean) => void): void;\n}\n\nclass RefreshPromiseTracker {\n\tpublic get hasPromise(): boolean {\n\t\treturn this.#promise !== undefined;\n\t}\n\tpublic get Promise(): Promise<number> | undefined {\n\t\treturn this.#promise;\n\t}\n\tconstructor(private readonly catchHandler: (error: Error) => void) {}\n\n\t#promise: Promise<number> | undefined;\n\tsetPromise(p: Promise<number>): void {\n\t\tif (this.hasPromise) {\n\t\t\tthrow new Error(\"Cannot set promise while promise exists\");\n\t\t}\n\t\tthis.#promise = p.finally(() => {\n\t\t\tthis.#promise = undefined;\n\t\t});\n\t\tp.catch(this.catchHandler);\n\t}\n}\n\n/**\n * Helper class to manage the state of the container needed for proper serialization.\n *\n * It holds the pendingLocalState the container was rehydrated from (if any),\n * as well as the snapshot to be used for serialization.\n * It also keeps track of container dirty state and which local ops have been processed\n */\nexport class SerializedStateManager {\n\tprivate readonly processedOps: ISequencedDocumentMessage[] = [];\n\tprivate readonly mc: MonitoringContext;\n\tprivate snapshot: ISnapshotInfo | undefined;\n\tprivate latestSnapshot: ISnapshotInfo | undefined;\n\tprivate readonly refreshTracker = new RefreshPromiseTracker(\n\t\t// eslint-disable-next-line unicorn/consistent-function-scoping\n\t\t(error) =>\n\t\t\tthis.mc.logger.sendErrorEvent(\n\t\t\t\t{\n\t\t\t\t\teventName: \"RefreshLatestSnapshotFailed\",\n\t\t\t\t},\n\t\t\t\terror,\n\t\t\t),\n\t);\n\tprivate readonly lastSavedOpSequenceNumber: number = 0;\n\tprivate readonly refreshTimer: Timer;\n\tprivate readonly snapshotRefreshTimeoutMs: number = 60 * 60 * 24 * 1000;\n\n\t/**\n\t * @param pendingLocalState - The pendingLocalState being rehydrated, if any (undefined when loading directly from storage)\n\t * @param subLogger - Container's logger to use as parent for our logger\n\t * @param storageAdapter - Storage adapter for fetching snapshots\n\t * @param _offlineLoadEnabled - Is serializing/rehydrating containers allowed?\n\t * @param containerEvent - Source of the \"saved\" event when the container has all its pending state uploaded\n\t * @param containerDirty - Is the container \"dirty\"? That's the opposite of \"saved\" - there is pending state that may not have been received yet by the service.\n\t */\n\tconstructor(\n\t\tprivate readonly pendingLocalState: IPendingContainerState | undefined,\n\t\tsubLogger: ITelemetryBaseLogger,\n\t\tprivate readonly storageAdapter: ISerializedStateManagerDocumentStorageService,\n\t\tprivate readonly _offlineLoadEnabled: boolean,\n\t\tcontainerEvent: IEventProvider<ISerializerEvent>,\n\t\tprivate readonly containerDirty: () => boolean,\n\t\tprivate readonly supportGetSnapshotApi: () => boolean,\n\t\tsnapshotRefreshTimeoutMs?: number,\n\t) {\n\t\tthis.mc = createChildMonitoringContext({\n\t\t\tlogger: subLogger,\n\t\t\tnamespace: \"serializedStateManager\",\n\t\t});\n\n\t\tthis.snapshotRefreshTimeoutMs = snapshotRefreshTimeoutMs ?? this.snapshotRefreshTimeoutMs;\n\t\tthis.refreshTimer = new Timer(this.snapshotRefreshTimeoutMs, () =>\n\t\t\tthis.tryRefreshSnapshot(),\n\t\t);\n\t\t// special case handle. Obtaining the last saved op seq num to avoid\n\t\t// refreshing the snapshot before we have processed it. It could cause\n\t\t// a subsequent stashing to have a newer snapshot than allowed.\n\t\tif (pendingLocalState && pendingLocalState.savedOps.length > 0) {\n\t\t\tconst savedOpsSize = pendingLocalState.savedOps.length;\n\t\t\tthis.lastSavedOpSequenceNumber =\n\t\t\t\tpendingLocalState.savedOps[savedOpsSize - 1].sequenceNumber;\n\t\t}\n\t\tcontainerEvent.on(\"saved\", () => this.updateSnapshotAndProcessedOpsMaybe());\n\t}\n\n\tpublic get offlineLoadEnabled(): boolean {\n\t\treturn this._offlineLoadEnabled;\n\t}\n\n\t/**\n\t * Promise that will resolve (or reject) once we've tried to download the latest snapshot(s) from storage\n\t * only intended to be used for testing purposes.\n\t * @returns The snapshot sequence number associated with the latest fetched snapshot\n\t */\n\tpublic get refreshSnapshotP(): Promise<number | undefined> | undefined {\n\t\treturn this.refreshTracker.Promise;\n\t}\n\n\t/**\n\t * Called whenever an incoming op is processed by the Container\n\t */\n\tpublic addProcessedOp(message: ISequencedDocumentMessage): void {\n\t\tif (this.offlineLoadEnabled) {\n\t\t\tthis.processedOps.push(message);\n\t\t\tthis.updateSnapshotAndProcessedOpsMaybe();\n\t\t}\n\t}\n\n\t/**\n\t * This wraps the basic functionality of fetching the snapshot for this container during Container load.\n\t *\n\t * If we have pendingLocalState, we get the snapshot from there.\n\t * Otherwise, fetch it from storage (according to specifiedVersion if provided).\n\t *\n\t * @param specifiedVersion - If a version is specified and we don't have pendingLocalState, fetch this version from storage.\n\t * @param supportGetSnapshotApi - a boolean indicating whether to use the fetchISnapshot or fetchISnapshotTree.\n\t * @returns The snapshot to boot the container from\n\t */\n\tpublic async fetchSnapshot(specifiedVersion: string | undefined): Promise<{\n\t\tbaseSnapshot: ISnapshot | ISnapshotTree;\n\t\tversion: IVersion | undefined;\n\t\tattributes: IDocumentAttributes;\n\t}> {\n\t\tif (this.pendingLocalState === undefined) {\n\t\t\tconst { baseSnapshot, version } = await getSnapshot(\n\t\t\t\tthis.mc,\n\t\t\t\tthis.storageAdapter,\n\t\t\t\tthis.supportGetSnapshotApi(),\n\t\t\t\tspecifiedVersion,\n\t\t\t);\n\t\t\tconst baseSnapshotTree: ISnapshotTree | undefined = getSnapshotTree(baseSnapshot);\n\t\t\tconst attributes = await getDocumentAttributes(this.storageAdapter, baseSnapshotTree);\n\t\t\t// non-interactive clients will not have any pending state we want to save\n\t\t\tif (this.offlineLoadEnabled) {\n\t\t\t\t// we defer getting the blobs to not impact the container load flow\n\t\t\t\t// only getPendingState depends on the resolution of this promise\n\t\t\t\tthis.refreshTracker.setPromise(\n\t\t\t\t\tgetBlobContentsFromTree(baseSnapshot, this.storageAdapter).then((snapshotBlobs) => {\n\t\t\t\t\t\tthis.snapshot = {\n\t\t\t\t\t\t\tbaseSnapshot: baseSnapshotTree,\n\t\t\t\t\t\t\tsnapshotBlobs,\n\t\t\t\t\t\t\tsnapshotSequenceNumber: attributes.sequenceNumber,\n\t\t\t\t\t\t};\n\t\t\t\t\t\tthis.refreshTimer.start();\n\t\t\t\t\t\treturn attributes.sequenceNumber;\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn { baseSnapshot, version, attributes };\n\t\t} else {\n\t\t\tconst { baseSnapshot, snapshotBlobs } = this.pendingLocalState;\n\t\t\tconst attributes = await getDocumentAttributes(this.storageAdapter, baseSnapshot);\n\t\t\tthis.snapshot = {\n\t\t\t\tbaseSnapshot,\n\t\t\t\tsnapshotBlobs,\n\t\t\t\tsnapshotSequenceNumber: attributes.sequenceNumber,\n\t\t\t};\n\t\t\tthis.tryRefreshSnapshot();\n\t\t\tconst blobContents = new Map<string, ArrayBuffer>();\n\t\t\tfor (const [id, value] of Object.entries(snapshotBlobs)) {\n\t\t\t\tblobContents.set(id, stringToBuffer(value, \"utf8\"));\n\t\t\t}\n\t\t\tconst iSnapshot: ISnapshot = {\n\t\t\t\tsequenceNumber: this.snapshot.snapshotSequenceNumber,\n\t\t\t\tsnapshotTree: baseSnapshot,\n\t\t\t\tblobContents,\n\t\t\t\tlatestSequenceNumber: undefined,\n\t\t\t\tops: [],\n\t\t\t\tsnapshotFormatV: 1,\n\t\t\t};\n\t\t\treturn { baseSnapshot: iSnapshot, version: undefined, attributes };\n\t\t}\n\t}\n\n\tprivate tryRefreshSnapshot(): void {\n\t\tif (\n\t\t\tthis.mc.config.getBoolean(\"Fluid.Container.enableOfflineSnapshotRefresh\") === true &&\n\t\t\t!this.refreshTracker.hasPromise &&\n\t\t\tthis.latestSnapshot === undefined\n\t\t) {\n\t\t\t// Don't block on the refresh snapshot call - it is for the next time we serialize, not booting this incarnation\n\t\t\tthis.refreshTracker.setPromise(this.refreshLatestSnapshot(this.supportGetSnapshotApi()));\n\t\t}\n\t}\n\n\t/**\n\t * Fetch the latest snapshot for the container, including delay-loaded groupIds if pendingLocalState was provided and contained any groupIds.\n\t * Note that this will update the StorageAdapter's cached snapshots for the groupIds (if present)\n\t *\n\t * @param supportGetSnapshotApi - a boolean indicating whether to use the fetchISnapshot or fetchISnapshotTree (must be true to fetch by groupIds)\n\t */\n\tprivate async refreshLatestSnapshot(supportGetSnapshotApi: boolean): Promise<number> {\n\t\tthis.latestSnapshot = await getLatestSnapshotInfo(\n\t\t\tthis.mc,\n\t\t\tthis.storageAdapter,\n\t\t\tsupportGetSnapshotApi,\n\t\t);\n\n\t\t// These are loading groupIds that the containerRuntime has requested over its lifetime.\n\t\t// We will fetch the latest snapshot for the groupIds, which will update storageAdapter.loadedGroupIdSnapshots's cache\n\t\tconst downloadedGroupIds = Object.keys(this.storageAdapter.loadedGroupIdSnapshots);\n\t\tif (supportGetSnapshotApi && downloadedGroupIds.length > 0) {\n\t\t\tassert(\n\t\t\t\tthis.storageAdapter.getSnapshot !== undefined,\n\t\t\t\t0x972 /* getSnapshot should exist */,\n\t\t\t);\n\t\t\t// (This is a separate network call from above because it requires work for storage to add a special base groupId)\n\t\t\tconst snapshot = await this.storageAdapter.getSnapshot({\n\t\t\t\tversionId: undefined,\n\t\t\t\tscenarioName: \"getLatestSnapshotInfo\",\n\t\t\t\tcacheSnapshot: false,\n\t\t\t\tloadingGroupIds: downloadedGroupIds,\n\t\t\t\tfetchSource: FetchSource.noCache,\n\t\t\t});\n\t\t\tassert(snapshot !== undefined, 0x973 /* Snapshot should exist */);\n\t\t}\n\n\t\treturn this.updateSnapshotAndProcessedOpsMaybe();\n\t}\n\n\t/**\n\t * Updates class snapshot and processedOps if we have a new snapshot and it's among processedOps range.\n\t */\n\tprivate updateSnapshotAndProcessedOpsMaybe(): number {\n\t\tconst snapshotSequenceNumber = this.latestSnapshot?.snapshotSequenceNumber;\n\t\tif (\n\t\t\tsnapshotSequenceNumber === undefined ||\n\t\t\tthis.processedOps.length === 0 ||\n\t\t\tthis.processedOps[this.processedOps.length - 1].sequenceNumber <\n\t\t\t\tthis.lastSavedOpSequenceNumber ||\n\t\t\tthis.containerDirty()\n\t\t) {\n\t\t\t// can't refresh latest snapshot until we have processed the ops up to it.\n\t\t\t// Pending state would be behind the latest snapshot.\n\t\t\treturn -1;\n\t\t}\n\t\tconst firstProcessedOpSequenceNumber = this.processedOps[0].sequenceNumber;\n\t\tconst lastProcessedOpSequenceNumber =\n\t\t\tthis.processedOps[this.processedOps.length - 1].sequenceNumber;\n\n\t\tif (snapshotSequenceNumber < firstProcessedOpSequenceNumber) {\n\t\t\t// Snapshot seq number is older than our first processed op, which could mean we're fetching\n\t\t\t// the same snapshot that we already have or snapshot is too old, implicating an unexpected behavior.\n\t\t\tthis.mc.logger.sendTelemetryEvent({\n\t\t\t\teventName: \"OldSnapshotFetchWhileRefreshing\",\n\t\t\t\tsnapshotSequenceNumber,\n\t\t\t\tfirstProcessedOpSequenceNumber,\n\t\t\t\tlastProcessedOpSequenceNumber,\n\t\t\t\tstashedSnapshotSequenceNumber: this.snapshot?.snapshotSequenceNumber,\n\t\t\t});\n\t\t\tthis.latestSnapshot = undefined;\n\t\t\tthis.refreshTimer.restart();\n\t\t} else if (snapshotSequenceNumber <= lastProcessedOpSequenceNumber) {\n\t\t\t// Snapshot seq num is between the first and last processed op.\n\t\t\t// Remove the ops that are already part of the snapshot\n\t\t\tthis.processedOps.splice(0, snapshotSequenceNumber - firstProcessedOpSequenceNumber + 1);\n\t\t\tthis.snapshot = this.latestSnapshot;\n\t\t\tthis.latestSnapshot = undefined;\n\t\t\tthis.refreshTimer.restart();\n\t\t\tthis.mc.logger.sendTelemetryEvent({\n\t\t\t\teventName: \"SnapshotRefreshed\",\n\t\t\t\tsnapshotSequenceNumber,\n\t\t\t\tfirstProcessedOpSequenceNumber,\n\t\t\t\tnewFirstProcessedOpSequenceNumber:\n\t\t\t\t\tthis.processedOps.length === 0 ? undefined : this.processedOps[0].sequenceNumber,\n\t\t\t});\n\t\t}\n\t\treturn snapshotSequenceNumber;\n\t}\n\n\t/**\n\t * When the Container attaches, we need to stash the initial snapshot (a form of the attach summary).\n\t * This method is only meant to be used by Container.attach() to set the initial\n\t * base snapshot when attaching.\n\t * @param snapshot - snapshot and blobs collected while attaching (a form of the attach summary)\n\t */\n\tpublic setInitialSnapshot(snapshot: SnapshotWithBlobs | undefined): void {\n\t\tif (this.offlineLoadEnabled) {\n\t\t\tassert(\n\t\t\t\tthis.snapshot === undefined,\n\t\t\t\t0x937 /* inital snapshot should only be defined once */,\n\t\t\t);\n\t\t\tassert(snapshot !== undefined, 0x938 /* attachment snapshot should be defined */);\n\t\t\tconst { baseSnapshot, snapshotBlobs } = snapshot;\n\t\t\tconst attributesHash =\n\t\t\t\t\".protocol\" in baseSnapshot.trees\n\t\t\t\t\t? baseSnapshot.trees[\".protocol\"].blobs.attributes\n\t\t\t\t\t: baseSnapshot.blobs[\".attributes\"];\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\t\t\tconst attributes = JSON.parse(snapshotBlobs[attributesHash]);\n\t\t\tassert(\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n\t\t\t\tattributes.sequenceNumber === 0,\n\t\t\t\t0x939 /* trying to set a non attachment snapshot */,\n\t\t\t);\n\t\t\tthis.snapshot = {\n\t\t\t\t...snapshot,\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n\t\t\t\tsnapshotSequenceNumber: attributes.sequenceNumber as number,\n\t\t\t};\n\t\t\tthis.refreshTimer.start();\n\t\t}\n\t}\n\n\t/**\n\t * Assembles and serializes the {@link IPendingContainerState} for the container,\n\t * to be stored and used to rehydrate the container at a later time.\n\t */\n\tpublic async getPendingLocalState(\n\t\tclientId: string | undefined,\n\t\truntime: Pick<IRuntime, \"getPendingLocalState\">,\n\t\tresolvedUrl: IResolvedUrl,\n\t): Promise<string> {\n\t\treturn PerformanceEvent.timedExecAsync(\n\t\t\tthis.mc.logger,\n\t\t\t{\n\t\t\t\teventName: \"getPendingLocalState\",\n\t\t\t\tdetails: {\n\t\t\t\t\tnotifyImminentClosure: false,\n\t\t\t\t\tsessionExpiryTimerStarted: undefined,\n\t\t\t\t\tsnapshotSequenceNumber: undefined,\n\t\t\t\t\tprocessedOpsSize: this.processedOps.length,\n\t\t\t\t},\n\t\t\t\tclientId,\n\t\t\t},\n\t\t\tasync () => {\n\t\t\t\tif (!this.offlineLoadEnabled) {\n\t\t\t\t\tthrow new UsageError(\"Can't get pending local state unless offline load is enabled\");\n\t\t\t\t}\n\t\t\t\tif (this.snapshot === undefined && this.refreshTracker.hasPromise) {\n\t\t\t\t\t// we deferred the initial download of the snapshot to not block\n\t\t\t\t\t// the container load flow, so if it is not resolved\n\t\t\t\t\t// and we don't have a snapshot, we will wait for the download\n\t\t\t\t\t// to finish.\n\t\t\t\t\tawait this.refreshTracker.Promise;\n\t\t\t\t}\n\n\t\t\t\tassert(this.snapshot !== undefined, 0x8e5 /* no base data */);\n\t\t\t\tconst pendingRuntimeState = await runtime.getPendingLocalState({\n\t\t\t\t\tnotifyImminentClosure: false,\n\t\t\t\t\tsnapshotSequenceNumber: this.snapshot.snapshotSequenceNumber,\n\t\t\t\t\tsessionExpiryTimerStarted: this.snapshot.snapshotFetchedTime,\n\t\t\t\t});\n\t\t\t\t// This conversion is required because ArrayBufferLike doesn't survive JSON.stringify\n\t\t\t\tconst loadedGroupIdSnapshots = {};\n\t\t\t\tlet hasGroupIdSnapshots = false;\n\t\t\t\tconst groupIdSnapshots = Object.entries(this.storageAdapter.loadedGroupIdSnapshots);\n\t\t\t\tif (groupIdSnapshots.length > 0) {\n\t\t\t\t\tfor (const [groupId, snapshot] of groupIdSnapshots) {\n\t\t\t\t\t\thasGroupIdSnapshots = true;\n\t\t\t\t\t\tloadedGroupIdSnapshots[groupId] = convertSnapshotToSnapshotInfo(snapshot);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tconst pendingState: IPendingContainerState = {\n\t\t\t\t\tattached: true,\n\t\t\t\t\tpendingRuntimeState,\n\t\t\t\t\tbaseSnapshot: this.snapshot.baseSnapshot,\n\t\t\t\t\tsnapshotBlobs: this.snapshot.snapshotBlobs,\n\t\t\t\t\tloadedGroupIdSnapshots: hasGroupIdSnapshots ? loadedGroupIdSnapshots : undefined,\n\t\t\t\t\tsavedOps: this.processedOps,\n\t\t\t\t\turl: resolvedUrl.url,\n\t\t\t\t\tclientId,\n\t\t\t\t};\n\n\t\t\t\treturn JSON.stringify(pendingState);\n\t\t\t},\n\t\t);\n\t}\n}\n\n/**\n * Retrieves the most recent snapshot and returns its info.\n *\n * @param mc - The monitoring context.\n * @param storageAdapter - The storage adapter providing methods to retrieve the snapshot.\n * @param supportGetSnapshotApi - a boolean indicating whether to use the fetchISnapshot or fetchISnapshotTree.\n * @returns a SnapshotInfo object containing the snapshot tree, snapshot blobs and its sequence number.\n */\nexport async function getLatestSnapshotInfo(\n\tmc: MonitoringContext,\n\tstorageAdapter: ISerializedStateManagerDocumentStorageService,\n\tsupportGetSnapshotApi: boolean,\n): Promise<ISnapshotInfo | undefined> {\n\treturn PerformanceEvent.timedExecAsync(\n\t\tmc.logger,\n\t\t{ eventName: \"GetLatestSnapshotInfo\" },\n\t\tasync () => {\n\t\t\t// get the latest non cached snapshot version\n\t\t\tconst specifiedVersion: IVersion[] = await storageAdapter.getVersions(\n\t\t\t\t// eslint-disable-next-line unicorn/no-null\n\t\t\t\tnull,\n\t\t\t\t1,\n\t\t\t\t\"getLatestSnapshotInfo\",\n\t\t\t\tFetchSource.noCache,\n\t\t\t);\n\t\t\tconst { baseSnapshot } = await getSnapshot(\n\t\t\t\tmc,\n\t\t\t\tstorageAdapter,\n\t\t\t\tsupportGetSnapshotApi,\n\t\t\t\tspecifiedVersion[0]?.id,\n\t\t\t);\n\n\t\t\tconst baseSnapshotTree: ISnapshotTree | undefined = getSnapshotTree(baseSnapshot);\n\t\t\tconst snapshotFetchedTime = Date.now();\n\t\t\tconst snapshotBlobs = await getBlobContentsFromTree(baseSnapshot, storageAdapter);\n\t\t\tconst attributes: IDocumentAttributes = await getDocumentAttributes(\n\t\t\t\tstorageAdapter,\n\t\t\t\tbaseSnapshotTree,\n\t\t\t);\n\t\t\tconst snapshotSequenceNumber = attributes.sequenceNumber;\n\t\t\treturn {\n\t\t\t\tbaseSnapshot: baseSnapshotTree,\n\t\t\t\tsnapshotBlobs,\n\t\t\t\tsnapshotSequenceNumber,\n\t\t\t\tsnapshotFetchedTime,\n\t\t\t};\n\t\t},\n\t).catch(() => undefined);\n}\n\n/**\n * Retrieves a snapshot from the storage adapter and transforms it into an ISnapshotTree object.\n *\n * @param mc - The monitoring context.\n * @param storageAdapter - The storage adapter providing methods to retrieve the snapshot.\n * @param supportGetSnapshotApi - a boolean indicating whether to use the fetchISnapshot or fetchISnapshotTree.\n * @param specifiedVersion - An optional version string specifying the version of the snapshot tree to fetch.\n * @returns - An ISnapshotTree and its version.\n */\nasync function getSnapshot(\n\tmc: MonitoringContext,\n\tstorageAdapter: Pick<\n\t\tIDocumentStorageService,\n\t\t\"getSnapshot\" | \"getSnapshotTree\" | \"getVersions\"\n\t>,\n\tsupportGetSnapshotApi: boolean,\n\tspecifiedVersion: string | undefined,\n): Promise<{ baseSnapshot: ISnapshot | ISnapshotTree; version?: IVersion }> {\n\tconst { snapshot, version } = supportGetSnapshotApi\n\t\t? await fetchISnapshot(mc, storageAdapter, specifiedVersion)\n\t\t: await fetchISnapshotTree(mc, storageAdapter, specifiedVersion);\n\tassert(snapshot !== undefined, 0x8e4 /* Snapshot should exist */);\n\treturn { baseSnapshot: snapshot, version };\n}\n\n/**\n * Fetches an ISnapshot from a storage adapter based on the specified version.\n *\n * @param mc - The monitoring context.\n * @param storageAdapter - The storage adapter providing a getSnapshot method to retrieve the ISnapshot and version.\n * @param specifiedVersion - An optional version string specifying the version of the snapshot tree to fetch.\n * @returns - The fetched snapshot tree and its version.\n */\nexport async function fetchISnapshot(\n\tmc: MonitoringContext,\n\tstorageAdapter: Pick<IDocumentStorageService, \"getSnapshot\">,\n\tspecifiedVersion: string | undefined,\n): Promise<{ snapshot?: ISnapshot; version?: IVersion }> {\n\tconst snapshot = await storageAdapter.getSnapshot?.({ versionId: specifiedVersion });\n\tconst version: IVersion | undefined =\n\t\tsnapshot?.snapshotTree.id === undefined\n\t\t\t? undefined\n\t\t\t: {\n\t\t\t\t\tid: snapshot.snapshotTree.id,\n\t\t\t\t\ttreeId: snapshot.snapshotTree.id,\n\t\t\t\t};\n\n\tif (snapshot === undefined && specifiedVersion !== undefined) {\n\t\tmc.logger.sendErrorEvent({\n\t\t\teventName: \"getSnapshotTreeFailed\",\n\t\t\tid: specifiedVersion,\n\t\t});\n\t} else if (snapshot !== undefined && version?.id === undefined) {\n\t\tmc.logger.sendErrorEvent({\n\t\t\teventName: \"getSnapshotFetchedTreeWithoutVersionId\",\n\t\t\thasVersion: version !== undefined, // if hasVersion is true, this means that the contract with the service was broken.\n\t\t});\n\t}\n\treturn { snapshot, version };\n}\n\n/**\n * Fetches an ISnapshotTree from a storage adapter based on the specified version.\n *\n * @param mc - The monitoring context.\n * @param storageAdapter - The storage adapter providing methods to retrieve the ISnapshotTree and version.\n * @param specifiedVersion - An optional version string specifying the version of the snapshot tree to fetch.\n * @returns - The fetched snapshot tree and its version.\n */\nexport async function fetchISnapshotTree(\n\tmc: MonitoringContext,\n\tstorageAdapter: Pick<IDocumentStorageService, \"getSnapshotTree\" | \"getVersions\">,\n\tspecifiedVersion: string | undefined,\n): Promise<{ snapshot?: ISnapshotTree; version?: IVersion | undefined }> {\n\t// API uses null\n\t// eslint-disable-next-line unicorn/no-null\n\tconst versions = await storageAdapter.getVersions(specifiedVersion ?? null, 1);\n\tconst version = versions[0];\n\n\tif (version === undefined && specifiedVersion !== undefined) {\n\t\t// We should have a defined version to load from if specified version requested\n\t\tmc.logger.sendErrorEvent({\n\t\t\teventName: \"NoVersionFoundWhenSpecified\",\n\t\t\tid: specifiedVersion,\n\t\t});\n\t}\n\tconst snapshot = (await storageAdapter.getSnapshotTree(version)) ?? undefined;\n\n\tif (snapshot === undefined && version !== undefined) {\n\t\tmc.logger.sendErrorEvent({ eventName: \"getSnapshotTreeFailed\", id: version.id });\n\t} else if (snapshot !== undefined && version?.id === undefined) {\n\t\tmc.logger.sendErrorEvent({\n\t\t\teventName: \"getSnapshotFetchedTreeWithoutVersionId\",\n\t\t\thasVersion: version !== undefined, // if hasVersion is true, this means that the contract with the service was broken.\n\t\t});\n\t}\n\treturn { snapshot, version };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"connectionManager.d.ts","sourceRoot":"","sources":["../src/connectionManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AACrF,OAAO,KAAK,EACX,WAAW,EACX,YAAY,EACZ,MAAM,gDAAgD,CAAC;AACxD,OAAO,EAAE,KAAK,wBAAwB,EAAY,MAAM,iCAAiC,CAAC;AAE1F,OAAO,KAAK,EACX,cAAc,EACd,OAAO,EACP,cAAc,EACd,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAEN,KAAK,gBAAgB,EAGrB,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EAOrB,KAAK,yBAAyB,EAE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";
7
+ import { JsonStringify } from "@fluidframework/core-interfaces/internal";
7
8
  import { assert } from "@fluidframework/core-utils/internal";
8
9
  import { DriverErrorTypes, MessageType, ScopeType, } from "@fluidframework/driver-definitions/internal";
9
10
  import { calculateMaxWaitTime, canRetryOnError, createGenericNetworkError, createWriteError, getRetryDelayFromError, isRuntimeMessage, logNetworkFailure, } from "@fluidframework/driver-utils/internal";
@@ -35,6 +36,16 @@ const waitForOnline = async () => {
35
36
  });
36
37
  }
37
38
  };
39
+ function assertExpectedSignals(signals) {
40
+ for (const signal of signals) {
41
+ if ("type" in signal) {
42
+ throw new Error("Unexpected type in ISignalMessage");
43
+ }
44
+ if (typeof signal.content !== "string") {
45
+ throw new TypeError("Non-string content in ISignalMessage");
46
+ }
47
+ }
48
+ }
38
49
  /**
39
50
  * Implementation of IConnectionManager, used by Container class
40
51
  * Implements constant connectivity to relay service, by reconnecting in case of lost connection or error.
@@ -191,6 +202,7 @@ export class ConnectionManager {
191
202
  };
192
203
  this.signalHandler = (signalsArg) => {
193
204
  const signals = Array.isArray(signalsArg) ? signalsArg : [signalsArg];
205
+ assertExpectedSignals(signals);
194
206
  this.props.signalHandler(signals);
195
207
  };
196
208
  // Always connect in write mode after getting nacked.
@@ -670,17 +682,19 @@ export class ConnectionManager {
670
682
  // API uses null
671
683
  // eslint-disable-next-line unicorn/no-null
672
684
  clientId: null, // system message
673
- content: JSON.stringify({
685
+ content: JsonStringify({
674
686
  type: SignalType.Clear,
675
687
  }),
676
688
  };
677
689
  // list of signals to process due to this new connection
678
- let signalsToProcess = [clearSignal];
690
+ let signalsToProcess = [
691
+ clearSignal,
692
+ ];
679
693
  const clientJoinSignals = (connection.initialClients ?? []).map((priorClient) => ({
680
694
  // API uses null
681
695
  // eslint-disable-next-line unicorn/no-null
682
696
  clientId: null, // system signal
683
- content: JSON.stringify({
697
+ content: JsonStringify({
684
698
  type: SignalType.ClientJoin,
685
699
  content: priorClient, // ISignalClient
686
700
  }),
@@ -693,6 +707,7 @@ export class ConnectionManager {
693
707
  // for "self" and connection.initialClients does not contain "self", so we have to process them after
694
708
  // "clear" signal above.
695
709
  if (connection.initialSignals !== undefined && connection.initialSignals.length > 0) {
710
+ assertExpectedSignals(connection.initialSignals);
696
711
  signalsToProcess = [...signalsToProcess, ...connection.initialSignals];
697
712
  }
698
713
  this.props.signalHandler(signalsToProcess);