@fluidframework/runtime-utils 1.4.0-121020 → 2.0.0-dev-rc.1.0.0.225277

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 (188) hide show
  1. package/.eslintrc.js +5 -7
  2. package/.mocharc.js +12 -0
  3. package/CHANGELOG.md +191 -0
  4. package/README.md +68 -1
  5. package/api-extractor-esm.json +4 -0
  6. package/api-extractor-lint.json +4 -0
  7. package/api-extractor.json +2 -2
  8. package/api-report/runtime-utils.api.md +201 -0
  9. package/dist/{dataStoreHandleContextUtils.js → dataStoreHandleContextUtils.cjs} +5 -2
  10. package/dist/dataStoreHandleContextUtils.cjs.map +1 -0
  11. package/dist/dataStoreHandleContextUtils.d.ts +1 -0
  12. package/dist/dataStoreHandleContextUtils.d.ts.map +1 -1
  13. package/dist/{dataStoreHelpers.js → dataStoreHelpers.cjs} +44 -25
  14. package/dist/dataStoreHelpers.cjs.map +1 -0
  15. package/dist/dataStoreHelpers.d.ts +23 -4
  16. package/dist/dataStoreHelpers.d.ts.map +1 -1
  17. package/dist/index.cjs +44 -0
  18. package/dist/index.cjs.map +1 -0
  19. package/dist/index.d.ts +9 -9
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/{objectstoragepartition.js → objectstoragepartition.cjs} +4 -3
  22. package/dist/objectstoragepartition.cjs.map +1 -0
  23. package/dist/objectstoragepartition.d.ts +1 -0
  24. package/dist/objectstoragepartition.d.ts.map +1 -1
  25. package/dist/{objectstorageutils.js → objectstorageutils.cjs} +11 -15
  26. package/dist/objectstorageutils.cjs.map +1 -0
  27. package/dist/objectstorageutils.d.ts +6 -0
  28. package/dist/objectstorageutils.d.ts.map +1 -1
  29. package/dist/{requestParser.js → requestParser.cjs} +7 -11
  30. package/dist/requestParser.cjs.map +1 -0
  31. package/dist/requestParser.d.ts +1 -0
  32. package/dist/requestParser.d.ts.map +1 -1
  33. package/dist/runtime-utils-alpha.d.ts +155 -0
  34. package/dist/runtime-utils-beta.d.ts +103 -0
  35. package/dist/runtime-utils-public.d.ts +103 -0
  36. package/dist/runtime-utils-untrimmed.d.ts +306 -0
  37. package/dist/{runtimeFactoryHelper.js → runtimeFactoryHelper.cjs} +11 -12
  38. package/dist/runtimeFactoryHelper.cjs.map +1 -0
  39. package/dist/runtimeFactoryHelper.d.ts +4 -1
  40. package/dist/runtimeFactoryHelper.d.ts.map +1 -1
  41. package/dist/{summaryUtils.js → summaryUtils.cjs} +138 -34
  42. package/dist/summaryUtils.cjs.map +1 -0
  43. package/dist/summaryUtils.d.ts +66 -4
  44. package/dist/summaryUtils.d.ts.map +1 -1
  45. package/dist/tsdoc-metadata.json +11 -0
  46. package/dist/unpackUsedRoutes.cjs +34 -0
  47. package/dist/unpackUsedRoutes.cjs.map +1 -0
  48. package/dist/unpackUsedRoutes.d.ts +12 -0
  49. package/dist/unpackUsedRoutes.d.ts.map +1 -0
  50. package/dist/{utils.js → utils.cjs} +2 -1
  51. package/dist/utils.cjs.map +1 -0
  52. package/dist/utils.d.ts +7 -2
  53. package/dist/utils.d.ts.map +1 -1
  54. package/lib/{dataStoreHandleContextUtils.d.ts → dataStoreHandleContextUtils.d.mts} +2 -1
  55. package/lib/dataStoreHandleContextUtils.d.mts.map +1 -0
  56. package/lib/{dataStoreHandleContextUtils.js → dataStoreHandleContextUtils.mjs} +5 -2
  57. package/lib/dataStoreHandleContextUtils.mjs.map +1 -0
  58. package/lib/{dataStoreHelpers.d.ts → dataStoreHelpers.d.mts} +24 -5
  59. package/lib/dataStoreHelpers.d.mts.map +1 -0
  60. package/lib/{dataStoreHelpers.js → dataStoreHelpers.mjs} +42 -22
  61. package/lib/dataStoreHelpers.mjs.map +1 -0
  62. package/lib/index.d.mts +14 -0
  63. package/lib/index.d.mts.map +1 -0
  64. package/lib/index.mjs +14 -0
  65. package/lib/index.mjs.map +1 -0
  66. package/lib/{objectstoragepartition.d.ts → objectstoragepartition.d.mts} +2 -1
  67. package/lib/objectstoragepartition.d.mts.map +1 -0
  68. package/lib/{objectstoragepartition.js → objectstoragepartition.mjs} +3 -2
  69. package/lib/objectstoragepartition.mjs.map +1 -0
  70. package/lib/{objectstorageutils.d.ts → objectstorageutils.d.mts} +7 -1
  71. package/lib/objectstorageutils.d.mts.map +1 -0
  72. package/lib/{objectstorageutils.js → objectstorageutils.mjs} +11 -15
  73. package/lib/objectstorageutils.mjs.map +1 -0
  74. package/lib/{requestParser.d.ts → requestParser.d.mts} +2 -5
  75. package/lib/requestParser.d.mts.map +1 -0
  76. package/lib/{requestParser.js → requestParser.mjs} +7 -11
  77. package/lib/requestParser.mjs.map +1 -0
  78. package/lib/runtime-utils-alpha.d.mts +155 -0
  79. package/lib/runtime-utils-beta.d.mts +103 -0
  80. package/lib/runtime-utils-public.d.mts +103 -0
  81. package/lib/runtime-utils-untrimmed.d.mts +306 -0
  82. package/lib/{runtimeFactoryHelper.d.ts → runtimeFactoryHelper.d.mts} +5 -2
  83. package/lib/runtimeFactoryHelper.d.mts.map +1 -0
  84. package/lib/runtimeFactoryHelper.mjs +24 -0
  85. package/lib/runtimeFactoryHelper.mjs.map +1 -0
  86. package/lib/{summaryUtils.d.ts → summaryUtils.d.mts} +67 -5
  87. package/lib/summaryUtils.d.mts.map +1 -0
  88. package/lib/{summaryUtils.js → summaryUtils.mjs} +129 -26
  89. package/lib/summaryUtils.mjs.map +1 -0
  90. package/lib/unpackUsedRoutes.d.mts +12 -0
  91. package/lib/unpackUsedRoutes.d.mts.map +1 -0
  92. package/lib/unpackUsedRoutes.mjs +30 -0
  93. package/lib/unpackUsedRoutes.mjs.map +1 -0
  94. package/lib/{utils.d.ts → utils.d.mts} +8 -3
  95. package/lib/utils.d.mts.map +1 -0
  96. package/lib/{utils.js → utils.mjs} +2 -1
  97. package/lib/utils.mjs.map +1 -0
  98. package/package.json +134 -65
  99. package/prettier.config.cjs +8 -0
  100. package/src/dataStoreHandleContextUtils.ts +24 -16
  101. package/src/dataStoreHelpers.ts +106 -83
  102. package/src/index.ts +31 -9
  103. package/src/objectstoragepartition.ts +18 -14
  104. package/src/objectstorageutils.ts +37 -36
  105. package/src/requestParser.ts +81 -86
  106. package/src/runtimeFactoryHelper.ts +27 -26
  107. package/src/summaryUtils.ts +425 -299
  108. package/src/unpackUsedRoutes.ts +31 -0
  109. package/src/utils.ts +12 -7
  110. package/tsc-multi.test.json +4 -0
  111. package/tsconfig.json +10 -12
  112. package/dist/dataStoreHandleContextUtils.js.map +0 -1
  113. package/dist/dataStoreHelpers.js.map +0 -1
  114. package/dist/index.js +0 -26
  115. package/dist/index.js.map +0 -1
  116. package/dist/objectstoragepartition.js.map +0 -1
  117. package/dist/objectstorageutils.js.map +0 -1
  118. package/dist/packageVersion.d.ts +0 -9
  119. package/dist/packageVersion.d.ts.map +0 -1
  120. package/dist/packageVersion.js +0 -12
  121. package/dist/packageVersion.js.map +0 -1
  122. package/dist/requestParser.js.map +0 -1
  123. package/dist/runtimeFactoryHelper.js.map +0 -1
  124. package/dist/summarizerNode/index.d.ts +0 -8
  125. package/dist/summarizerNode/index.d.ts.map +0 -1
  126. package/dist/summarizerNode/index.js +0 -12
  127. package/dist/summarizerNode/index.js.map +0 -1
  128. package/dist/summarizerNode/summarizerNode.d.ts +0 -139
  129. package/dist/summarizerNode/summarizerNode.d.ts.map +0 -1
  130. package/dist/summarizerNode/summarizerNode.js +0 -480
  131. package/dist/summarizerNode/summarizerNode.js.map +0 -1
  132. package/dist/summarizerNode/summarizerNodeUtils.d.ts +0 -161
  133. package/dist/summarizerNode/summarizerNodeUtils.d.ts.map +0 -1
  134. package/dist/summarizerNode/summarizerNodeUtils.js +0 -225
  135. package/dist/summarizerNode/summarizerNodeUtils.js.map +0 -1
  136. package/dist/summarizerNode/summarizerNodeWithGc.d.ts +0 -133
  137. package/dist/summarizerNode/summarizerNodeWithGc.d.ts.map +0 -1
  138. package/dist/summarizerNode/summarizerNodeWithGc.js +0 -294
  139. package/dist/summarizerNode/summarizerNodeWithGc.js.map +0 -1
  140. package/dist/summaryUtils.js.map +0 -1
  141. package/dist/utils.js.map +0 -1
  142. package/lib/dataStoreHandleContextUtils.d.ts.map +0 -1
  143. package/lib/dataStoreHandleContextUtils.js.map +0 -1
  144. package/lib/dataStoreHelpers.d.ts.map +0 -1
  145. package/lib/dataStoreHelpers.js.map +0 -1
  146. package/lib/index.d.ts +0 -14
  147. package/lib/index.d.ts.map +0 -1
  148. package/lib/index.js +0 -14
  149. package/lib/index.js.map +0 -1
  150. package/lib/objectstoragepartition.d.ts.map +0 -1
  151. package/lib/objectstoragepartition.js.map +0 -1
  152. package/lib/objectstorageutils.d.ts.map +0 -1
  153. package/lib/objectstorageutils.js.map +0 -1
  154. package/lib/packageVersion.d.ts +0 -9
  155. package/lib/packageVersion.d.ts.map +0 -1
  156. package/lib/packageVersion.js +0 -9
  157. package/lib/packageVersion.js.map +0 -1
  158. package/lib/requestParser.d.ts.map +0 -1
  159. package/lib/requestParser.js.map +0 -1
  160. package/lib/runtimeFactoryHelper.d.ts.map +0 -1
  161. package/lib/runtimeFactoryHelper.js +0 -25
  162. package/lib/runtimeFactoryHelper.js.map +0 -1
  163. package/lib/summarizerNode/index.d.ts +0 -8
  164. package/lib/summarizerNode/index.d.ts.map +0 -1
  165. package/lib/summarizerNode/index.js +0 -7
  166. package/lib/summarizerNode/index.js.map +0 -1
  167. package/lib/summarizerNode/summarizerNode.d.ts +0 -139
  168. package/lib/summarizerNode/summarizerNode.d.ts.map +0 -1
  169. package/lib/summarizerNode/summarizerNode.js +0 -475
  170. package/lib/summarizerNode/summarizerNode.js.map +0 -1
  171. package/lib/summarizerNode/summarizerNodeUtils.d.ts +0 -161
  172. package/lib/summarizerNode/summarizerNodeUtils.d.ts.map +0 -1
  173. package/lib/summarizerNode/summarizerNodeUtils.js +0 -216
  174. package/lib/summarizerNode/summarizerNodeUtils.js.map +0 -1
  175. package/lib/summarizerNode/summarizerNodeWithGc.d.ts +0 -133
  176. package/lib/summarizerNode/summarizerNodeWithGc.d.ts.map +0 -1
  177. package/lib/summarizerNode/summarizerNodeWithGc.js +0 -289
  178. package/lib/summarizerNode/summarizerNodeWithGc.js.map +0 -1
  179. package/lib/summaryUtils.d.ts.map +0 -1
  180. package/lib/summaryUtils.js.map +0 -1
  181. package/lib/utils.d.ts.map +0 -1
  182. package/lib/utils.js.map +0 -1
  183. package/src/packageVersion.ts +0 -9
  184. package/src/summarizerNode/index.ts +0 -8
  185. package/src/summarizerNode/summarizerNode.ts +0 -662
  186. package/src/summarizerNode/summarizerNodeUtils.ts +0 -339
  187. package/src/summarizerNode/summarizerNodeWithGc.ts +0 -459
  188. package/tsconfig.esnext.json +0 -7
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/summarizerNode/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,2BAA2B,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC1F,OAAO,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AACjF,OAAO,EAAE,yBAAyB,EAAE,8BAA8B,EAAE,MAAM,wBAAwB,CAAC"}
@@ -1,7 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
- export { createRootSummarizerNode } from "./summarizerNode";
6
- export { createRootSummarizerNodeWithGC } from "./summarizerNodeWithGc";
7
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/summarizerNode/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAuB,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AACjF,OAAO,EAA6B,8BAA8B,EAAE,MAAM,wBAAwB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport { ISummarizerNodeRootContract, RefreshSummaryResult } from \"./summarizerNodeUtils\";\nexport { IRootSummarizerNode, createRootSummarizerNode } from \"./summarizerNode\";\nexport { IRootSummarizerNodeWithGC, createRootSummarizerNodeWithGC } from \"./summarizerNodeWithGc\";\n"]}
@@ -1,139 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
- import { ISummarizerNode, ISummarizerNodeConfig, ISummarizeResult, CreateChildSummarizerNodeParam, SummarizeInternalFn, ITelemetryContext } from "@fluidframework/runtime-definitions";
6
- import { ISequencedDocumentMessage, ISnapshotTree } from "@fluidframework/protocol-definitions";
7
- import { ITelemetryLogger } from "@fluidframework/common-definitions";
8
- import { ReadAndParseBlob } from "../utils";
9
- import { EscapedPath, ICreateChildDetails, IInitialSummary, ISummarizerNodeRootContract, RefreshSummaryResult, SummaryNode } from "./summarizerNodeUtils";
10
- export interface IRootSummarizerNode extends ISummarizerNode, ISummarizerNodeRootContract {
11
- }
12
- /**
13
- * Encapsulates the summarizing work and state of an individual tree node in the
14
- * summary tree. It tracks changes and allows for optimizations when unchanged, or
15
- * can allow for fallback summaries to be generated when an error is encountered.
16
- * Usage is for the root node to call startSummary first to begin tracking a WIP
17
- * (work in progress) summary. Then all nodes will call summarize to summaries their
18
- * individual parts. Once completed and uploaded to storage, the root node will call
19
- * completeSummary or clearSummary to clear the WIP summary tracking state if something
20
- * went wrong. The SummarizerNodes will track all pending summaries that have been
21
- * recorded by the completeSummary call. When one of them is acked, the root node should
22
- * call refreshLatestSummary to inform the tree of SummarizerNodes of the new baseline
23
- * latest successful summary.
24
- */
25
- export declare class SummarizerNode implements IRootSummarizerNode {
26
- protected readonly defaultLogger: ITelemetryLogger;
27
- private readonly summarizeInternalFn;
28
- private _changeSequenceNumber;
29
- /** Undefined means created without summary */
30
- private _latestSummary?;
31
- private readonly initialSummary?;
32
- protected wipSummaryLogger?: ITelemetryLogger | undefined;
33
- /**
34
- * The reference sequence number of the most recent acked summary.
35
- * Returns 0 if there is not yet an acked summary.
36
- */
37
- get referenceSequenceNumber(): number;
38
- protected readonly children: Map<string, SummarizerNode>;
39
- protected readonly pendingSummaries: Map<string, SummaryNode>;
40
- private readonly outstandingOps;
41
- private wipReferenceSequenceNumber;
42
- private wipLocalPaths;
43
- private wipSkipRecursion;
44
- startSummary(referenceSequenceNumber: number, summaryLogger: ITelemetryLogger): void;
45
- summarize(fullTree: boolean, trackState?: boolean, telemetryContext?: ITelemetryContext): Promise<ISummarizeResult>;
46
- /**
47
- * Complete the WIP summary for the given proposalHandle
48
- */
49
- completeSummary(proposalHandle: string): void;
50
- /**
51
- * Recursive implementation for completeSummary, with additional internal-only parameters
52
- */
53
- protected completeSummaryCore(proposalHandle: string, parentPath: EscapedPath | undefined, parentSkipRecursion: boolean): void;
54
- clearSummary(): void;
55
- /**
56
- * Refreshes the latest summary tracked by this node. If we have a pending summary for the given proposal handle,
57
- * it becomes the latest summary. If the current summary is already ahead (e.g., loaded from a service summary),
58
- * we skip the update. Otherwise, we get the snapshot by calling `getSnapshot` and update latest
59
- * summary based off of that.
60
- * @returns A RefreshSummaryResult type which returns information based on the following three scenarios:
61
- * 1. The latest summary was not udpated.
62
- * 2. The latest summary was updated and the summary corresponding to the params was being tracked.
63
- * 3. The latest summary was updated but the summary corresponding to the params was not tracked. In this
64
- * case, the latest summary is updated based on the downloaded snapshot which is also returned.
65
- */
66
- refreshLatestSummary(proposalHandle: string | undefined, summaryRefSeq: number, getSnapshot: () => Promise<ISnapshotTree>, readAndParseBlob: ReadAndParseBlob, correlatedSummaryLogger: ITelemetryLogger): Promise<RefreshSummaryResult>;
67
- protected refreshLatestSummaryFromPending(proposalHandle: string, referenceSequenceNumber: number): void;
68
- protected refreshLatestSummaryFromSnapshot(referenceSequenceNumber: number, snapshotTree: ISnapshotTree, basePath: EscapedPath | undefined, localPath: EscapedPath, correlatedSummaryLogger: ITelemetryLogger, readAndParseBlob: ReadAndParseBlob): Promise<void>;
69
- private refreshLatestSummaryCore;
70
- loadBaseSummaryWithoutDifferential(snapshot: ISnapshotTree): void;
71
- loadBaseSummary(snapshot: ISnapshotTree, readAndParseBlob: ReadAndParseBlob): Promise<{
72
- baseSummary: ISnapshotTree;
73
- outstandingOps: ISequencedDocumentMessage[];
74
- }>;
75
- recordChange(op: ISequencedDocumentMessage): void;
76
- invalidate(sequenceNumber: number): void;
77
- /**
78
- * True if a change has been recorded with sequence number exceeding
79
- * the latest successfully acked summary reference sequence number.
80
- * False implies that the previous summary can be reused.
81
- */
82
- protected hasChanged(): boolean;
83
- get latestSummary(): Readonly<SummaryNode> | undefined;
84
- private readonly canReuseHandle;
85
- private readonly throwOnError;
86
- /**
87
- * Sequence number of latest tracked op. This updates during recordChange,
88
- * but not for invalidate since we don't have the op. If this drifts from
89
- * changeSequenceNumber and we try to create a differential summary we assert.
90
- */
91
- private trackingSequenceNumber;
92
- /**
93
- * Do not call constructor directly.
94
- * Use createRootSummarizerNode to create root node, or createChild to create child nodes.
95
- */
96
- constructor(defaultLogger: ITelemetryLogger, summarizeInternalFn: SummarizeInternalFn, config: ISummarizerNodeConfig, _changeSequenceNumber: number,
97
- /** Undefined means created without summary */
98
- _latestSummary?: SummaryNode | undefined, initialSummary?: IInitialSummary | undefined, wipSummaryLogger?: ITelemetryLogger | undefined);
99
- createChild(
100
- /** Summarize function */
101
- summarizeInternalFn: SummarizeInternalFn,
102
- /** Initial id or path part of this node */
103
- id: string,
104
- /**
105
- * Information needed to create the node.
106
- * If it is from a base summary, it will assert that a summary has been seen.
107
- * Attach information if it is created from an attach op.
108
- */
109
- createParam: CreateChildSummarizerNodeParam, config?: ISummarizerNodeConfig): ISummarizerNode;
110
- getChild(id: string): ISummarizerNode | undefined;
111
- /**
112
- * Returns the details needed to create a child node.
113
- * @param id - Initial id or path part of the child node.
114
- * @param createParam - Information needed to create the node.
115
- * @returns the details needed to create the child node.
116
- */
117
- protected getCreateDetailsForChild(id: string, createParam: CreateChildSummarizerNodeParam): ICreateChildDetails;
118
- /**
119
- * Updates the state of the child if required. For example, if a summary is currently being tracked, the child's
120
- * summary tracking state needs to be updated too.
121
- * @param child - The child node whose state is to be updated.
122
- */
123
- protected maybeUpdateChildState(child: SummarizerNode): void;
124
- /**
125
- * Tells whether summary tracking is in progress. True if "startSummary" API is called before summarize.
126
- */
127
- protected isTrackingInProgress(): boolean;
128
- }
129
- /**
130
- * Creates a root summarizer node.
131
- * @param logger - Logger to use within SummarizerNode
132
- * @param summarizeInternalFn - Function to generate summary
133
- * @param changeSequenceNumber - Sequence number of latest change to new node/subtree
134
- * @param referenceSequenceNumber - Reference sequence number of last acked summary,
135
- * or undefined if not loaded from summary
136
- * @param config - Configure behavior of summarizer node
137
- */
138
- export declare const createRootSummarizerNode: (logger: ITelemetryLogger, summarizeInternalFn: SummarizeInternalFn, changeSequenceNumber: number, referenceSequenceNumber: number | undefined, config?: ISummarizerNodeConfig) => IRootSummarizerNode;
139
- //# sourceMappingURL=summarizerNode.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"summarizerNode.d.ts","sourceRoot":"","sources":["../../src/summarizerNode/summarizerNode.ts"],"names":[],"mappings":"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"}
@@ -1,475 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
- import { CreateSummarizerNodeSource, } from "@fluidframework/runtime-definitions";
6
- import { SummaryType, } from "@fluidframework/protocol-definitions";
7
- import { assert, unreachableCase } from "@fluidframework/common-utils";
8
- import { mergeStats, convertToSummaryTree, calculateStats } from "../summaryUtils";
9
- import { decodeSummary, encodeSummary, EscapedPath, parseSummaryForSubtrees, parseSummaryTreeForSubtrees, SummaryNode, } from "./summarizerNodeUtils";
10
- /**
11
- * Encapsulates the summarizing work and state of an individual tree node in the
12
- * summary tree. It tracks changes and allows for optimizations when unchanged, or
13
- * can allow for fallback summaries to be generated when an error is encountered.
14
- * Usage is for the root node to call startSummary first to begin tracking a WIP
15
- * (work in progress) summary. Then all nodes will call summarize to summaries their
16
- * individual parts. Once completed and uploaded to storage, the root node will call
17
- * completeSummary or clearSummary to clear the WIP summary tracking state if something
18
- * went wrong. The SummarizerNodes will track all pending summaries that have been
19
- * recorded by the completeSummary call. When one of them is acked, the root node should
20
- * call refreshLatestSummary to inform the tree of SummarizerNodes of the new baseline
21
- * latest successful summary.
22
- */
23
- export class SummarizerNode {
24
- /**
25
- * Do not call constructor directly.
26
- * Use createRootSummarizerNode to create root node, or createChild to create child nodes.
27
- */
28
- constructor(defaultLogger, summarizeInternalFn, config, _changeSequenceNumber,
29
- /** Undefined means created without summary */
30
- _latestSummary, initialSummary, wipSummaryLogger) {
31
- var _a;
32
- this.defaultLogger = defaultLogger;
33
- this.summarizeInternalFn = summarizeInternalFn;
34
- this._changeSequenceNumber = _changeSequenceNumber;
35
- this._latestSummary = _latestSummary;
36
- this.initialSummary = initialSummary;
37
- this.wipSummaryLogger = wipSummaryLogger;
38
- this.children = new Map();
39
- this.pendingSummaries = new Map();
40
- this.outstandingOps = [];
41
- this.wipSkipRecursion = false;
42
- this.canReuseHandle = (_a = config.canReuseHandle) !== null && _a !== void 0 ? _a : true;
43
- // BUGBUG: Seeing issues with differential summaries.
44
- // this will disable them, and throw instead
45
- // while we continue to investigate
46
- this.throwOnError = true; // config.throwOnFailure ?? false;
47
- this.trackingSequenceNumber = this._changeSequenceNumber;
48
- }
49
- /**
50
- * The reference sequence number of the most recent acked summary.
51
- * Returns 0 if there is not yet an acked summary.
52
- */
53
- get referenceSequenceNumber() {
54
- var _a, _b;
55
- return (_b = (_a = this._latestSummary) === null || _a === void 0 ? void 0 : _a.referenceSequenceNumber) !== null && _b !== void 0 ? _b : 0;
56
- }
57
- startSummary(referenceSequenceNumber, summaryLogger) {
58
- assert(this.wipSummaryLogger === undefined, 0x19f /* "wipSummaryLogger should not be set yet in startSummary" */);
59
- assert(this.wipReferenceSequenceNumber === undefined, 0x1a0 /* "Already tracking a summary" */);
60
- this.wipSummaryLogger = summaryLogger;
61
- for (const child of this.children.values()) {
62
- child.startSummary(referenceSequenceNumber, this.wipSummaryLogger);
63
- }
64
- this.wipReferenceSequenceNumber = referenceSequenceNumber;
65
- }
66
- async summarize(fullTree, trackState = true, telemetryContext) {
67
- assert(this.isTrackingInProgress(), 0x1a1 /* "summarize should not be called when not tracking the summary" */);
68
- assert(this.wipSummaryLogger !== undefined, 0x1a2 /* "wipSummaryLogger should have been set in startSummary or ctor" */);
69
- // Try to reuse the tree if unchanged
70
- if (this.canReuseHandle && !fullTree && !this.hasChanged()) {
71
- const latestSummary = this._latestSummary;
72
- if (latestSummary !== undefined) {
73
- this.wipLocalPaths = {
74
- localPath: latestSummary.localPath,
75
- additionalPath: latestSummary.additionalPath,
76
- };
77
- this.wipSkipRecursion = true;
78
- const stats = mergeStats();
79
- stats.handleNodeCount++;
80
- return {
81
- summary: {
82
- type: SummaryType.Handle,
83
- handle: latestSummary.fullPath.path,
84
- handleType: SummaryType.Tree,
85
- },
86
- stats,
87
- };
88
- }
89
- }
90
- try {
91
- const result = await this.summarizeInternalFn(fullTree, true, telemetryContext);
92
- this.wipLocalPaths = { localPath: EscapedPath.create(result.id) };
93
- if (result.pathPartsForChildren !== undefined) {
94
- this.wipLocalPaths.additionalPath = EscapedPath.createAndConcat(result.pathPartsForChildren);
95
- }
96
- return { summary: result.summary, stats: result.stats };
97
- }
98
- catch (error) {
99
- if (this.throwOnError || this.trackingSequenceNumber < this._changeSequenceNumber) {
100
- throw error;
101
- }
102
- const latestSummary = this._latestSummary;
103
- const initialSummary = this.initialSummary;
104
- let encodeParam;
105
- let localPath;
106
- if (latestSummary !== undefined) {
107
- // Create using handle of latest acked summary
108
- encodeParam = {
109
- fromSummary: true,
110
- summaryNode: latestSummary,
111
- };
112
- localPath = latestSummary.localPath;
113
- }
114
- else if ((initialSummary === null || initialSummary === void 0 ? void 0 : initialSummary.summary) !== undefined) {
115
- // Create using initial summary from attach op
116
- encodeParam = {
117
- fromSummary: false,
118
- initialSummary: initialSummary.summary,
119
- };
120
- localPath = EscapedPath.create(initialSummary.id);
121
- }
122
- else {
123
- // No base summary to reference
124
- throw error;
125
- }
126
- this.wipSummaryLogger.sendErrorEvent({
127
- eventName: "SummarizingWithBasePlusOps",
128
- }, error);
129
- const summary = encodeSummary(encodeParam, this.outstandingOps);
130
- this.wipLocalPaths = {
131
- localPath,
132
- additionalPath: summary.additionalPath,
133
- };
134
- this.wipSkipRecursion = true;
135
- return { summary: summary.summary, stats: summary.stats };
136
- }
137
- }
138
- /**
139
- * Complete the WIP summary for the given proposalHandle
140
- */
141
- completeSummary(proposalHandle) {
142
- this.completeSummaryCore(proposalHandle, undefined, false);
143
- }
144
- /**
145
- * Recursive implementation for completeSummary, with additional internal-only parameters
146
- */
147
- completeSummaryCore(proposalHandle, parentPath, parentSkipRecursion) {
148
- assert(this.wipSummaryLogger !== undefined, 0x1a3 /* "wipSummaryLogger should have been set in startSummary or ctor" */);
149
- assert(this.wipReferenceSequenceNumber !== undefined, 0x1a4 /* "Not tracking a summary" */);
150
- let localPathsToUse = this.wipLocalPaths;
151
- if (parentSkipRecursion) {
152
- const latestSummary = this._latestSummary;
153
- if (latestSummary !== undefined) {
154
- // This case the parent node created a failure summary or was reused.
155
- // This node and all children should only try to reference their path
156
- // by its last known good state in the actual summary tree.
157
- // If parent fails or is reused, the child summarize is not called so
158
- // it did not get a chance to change its paths.
159
- // In this case, essentially only propagate the new summary ref seq num.
160
- localPathsToUse = {
161
- localPath: latestSummary.localPath,
162
- additionalPath: latestSummary.additionalPath,
163
- };
164
- }
165
- else {
166
- // This case the child is added after the latest non-failure summary.
167
- // This node and all children should consider themselves as still not
168
- // having a successful summary yet.
169
- // We cannot "reuse" this node if unchanged since that summary, because
170
- // handles will be unable to point to that node. It never made it to the
171
- // tree itself, and only exists as an attach op in the _outstandingOps.
172
- this.clearSummary();
173
- return;
174
- }
175
- }
176
- // This should come from wipLocalPaths in normal cases, or from the latestSummary
177
- // if parentIsFailure or parentIsReused is true.
178
- // If there is no latestSummary, clearSummary and return before reaching this code.
179
- assert(!!localPathsToUse, 0x1a5 /* "Tracked summary local paths not set" */);
180
- const summary = new SummaryNode(Object.assign(Object.assign({}, localPathsToUse), { referenceSequenceNumber: this.wipReferenceSequenceNumber, basePath: parentPath }));
181
- const fullPathForChildren = summary.fullPathForChildren;
182
- for (const child of this.children.values()) {
183
- child.completeSummaryCore(proposalHandle, fullPathForChildren, this.wipSkipRecursion || parentSkipRecursion);
184
- }
185
- // Note that this overwrites existing pending summary with
186
- // the same proposalHandle. If proposalHandle is something like
187
- // a hash or unique identifier, this should be fine. If storage
188
- // can return the same proposalHandle for a different summary,
189
- // this should still be okay, because we should be proposing the
190
- // newer one later which would have to overwrite the previous one.
191
- this.pendingSummaries.set(proposalHandle, summary);
192
- this.clearSummary();
193
- }
194
- clearSummary() {
195
- this.wipReferenceSequenceNumber = undefined;
196
- this.wipLocalPaths = undefined;
197
- this.wipSkipRecursion = false;
198
- this.wipSummaryLogger = undefined;
199
- for (const child of this.children.values()) {
200
- child.clearSummary();
201
- }
202
- }
203
- /**
204
- * Refreshes the latest summary tracked by this node. If we have a pending summary for the given proposal handle,
205
- * it becomes the latest summary. If the current summary is already ahead (e.g., loaded from a service summary),
206
- * we skip the update. Otherwise, we get the snapshot by calling `getSnapshot` and update latest
207
- * summary based off of that.
208
- * @returns A RefreshSummaryResult type which returns information based on the following three scenarios:
209
- * 1. The latest summary was not udpated.
210
- * 2. The latest summary was updated and the summary corresponding to the params was being tracked.
211
- * 3. The latest summary was updated but the summary corresponding to the params was not tracked. In this
212
- * case, the latest summary is updated based on the downloaded snapshot which is also returned.
213
- */
214
- async refreshLatestSummary(proposalHandle, summaryRefSeq, getSnapshot, readAndParseBlob, correlatedSummaryLogger) {
215
- if (proposalHandle !== undefined) {
216
- const maybeSummaryNode = this.pendingSummaries.get(proposalHandle);
217
- if (maybeSummaryNode !== undefined) {
218
- this.refreshLatestSummaryFromPending(proposalHandle, maybeSummaryNode.referenceSequenceNumber);
219
- return { latestSummaryUpdated: true, wasSummaryTracked: true };
220
- }
221
- }
222
- // If we have seen a summary same or later as the current one, ignore it.
223
- if (this.referenceSequenceNumber >= summaryRefSeq) {
224
- return { latestSummaryUpdated: false };
225
- }
226
- const snapshotTree = await getSnapshot();
227
- await this.refreshLatestSummaryFromSnapshot(summaryRefSeq, snapshotTree, undefined, EscapedPath.create(""), correlatedSummaryLogger, readAndParseBlob);
228
- return { latestSummaryUpdated: true, wasSummaryTracked: false, snapshot: snapshotTree };
229
- }
230
- refreshLatestSummaryFromPending(proposalHandle, referenceSequenceNumber) {
231
- const summaryNode = this.pendingSummaries.get(proposalHandle);
232
- if (summaryNode === undefined) {
233
- // This should only happen if parent skipped recursion AND no prior summary existed.
234
- assert(this._latestSummary === undefined, 0x1a6 /* "Not found pending summary, but this node has previously completed a summary" */);
235
- return;
236
- }
237
- else {
238
- assert(referenceSequenceNumber === summaryNode.referenceSequenceNumber, 0x1a7 /* Pending summary reference sequence number should be consistent */);
239
- // Clear earlier pending summaries
240
- this.pendingSummaries.delete(proposalHandle);
241
- }
242
- this.refreshLatestSummaryCore(referenceSequenceNumber);
243
- this._latestSummary = summaryNode;
244
- // Propagate update to all child nodes
245
- for (const child of this.children.values()) {
246
- child.refreshLatestSummaryFromPending(proposalHandle, referenceSequenceNumber);
247
- }
248
- }
249
- async refreshLatestSummaryFromSnapshot(referenceSequenceNumber, snapshotTree, basePath, localPath, correlatedSummaryLogger, readAndParseBlob) {
250
- // Possible re-entrancy. If we have already seen a summary later than this one, ignore it.
251
- if (this.referenceSequenceNumber >= referenceSequenceNumber) {
252
- return;
253
- }
254
- this.refreshLatestSummaryCore(referenceSequenceNumber);
255
- const { baseSummary, pathParts } = decodeSummary(snapshotTree, correlatedSummaryLogger);
256
- this._latestSummary = new SummaryNode({
257
- referenceSequenceNumber,
258
- basePath,
259
- localPath,
260
- });
261
- const { childrenTree, childrenPathPart } = parseSummaryForSubtrees(baseSummary);
262
- if (childrenPathPart !== undefined) {
263
- pathParts.push(childrenPathPart);
264
- }
265
- if (pathParts.length > 0) {
266
- this._latestSummary.additionalPath = EscapedPath.createAndConcat(pathParts);
267
- }
268
- // Propagate update to all child nodes
269
- const pathForChildren = this._latestSummary.fullPathForChildren;
270
- await Promise.all(Array.from(this.children)
271
- .filter(([id]) => {
272
- // Assuming subtrees missing from snapshot are newer than the snapshot,
273
- // but might be nice to assert this using earliest seq for node.
274
- return childrenTree.trees[id] !== undefined;
275
- }).map(async ([id, child]) => {
276
- return child.refreshLatestSummaryFromSnapshot(referenceSequenceNumber, childrenTree.trees[id], pathForChildren, EscapedPath.create(id), correlatedSummaryLogger, readAndParseBlob);
277
- }));
278
- }
279
- refreshLatestSummaryCore(referenceSequenceNumber) {
280
- for (const [key, value] of this.pendingSummaries) {
281
- if (value.referenceSequenceNumber < referenceSequenceNumber) {
282
- this.pendingSummaries.delete(key);
283
- }
284
- }
285
- // Clear earlier outstanding ops
286
- while (this.outstandingOps.length > 0
287
- && this.outstandingOps[0].sequenceNumber <= referenceSequenceNumber) {
288
- this.outstandingOps.shift();
289
- }
290
- }
291
- loadBaseSummaryWithoutDifferential(snapshot) {
292
- // Check base summary to see if it has any additional path parts
293
- // separating child SummarizerNodes. Checks for .channels subtrees.
294
- const { childrenPathPart } = parseSummaryForSubtrees(snapshot);
295
- if (childrenPathPart !== undefined && this._latestSummary !== undefined) {
296
- this._latestSummary.additionalPath = EscapedPath.create(childrenPathPart);
297
- }
298
- }
299
- async loadBaseSummary(snapshot, readAndParseBlob) {
300
- const decodedSummary = decodeSummary(snapshot, this.defaultLogger);
301
- const outstandingOps = await decodedSummary.getOutstandingOps(readAndParseBlob);
302
- const { childrenPathPart } = parseSummaryForSubtrees(decodedSummary.baseSummary);
303
- if (childrenPathPart !== undefined) {
304
- decodedSummary.pathParts.push(childrenPathPart);
305
- }
306
- if (decodedSummary.pathParts.length > 0 && this._latestSummary !== undefined) {
307
- this._latestSummary.additionalPath = EscapedPath.createAndConcat(decodedSummary.pathParts);
308
- }
309
- // Defensive assertion: tracking number should already exceed this number.
310
- // This is probably a little excessive; can remove when stable.
311
- if (outstandingOps.length > 0) {
312
- const newOpsLatestSeq = outstandingOps[outstandingOps.length - 1].sequenceNumber;
313
- assert(newOpsLatestSeq <= this.trackingSequenceNumber, 0x1a9 /* "When loading base summary, expected outstanding ops <= tracking sequence number" */);
314
- }
315
- return {
316
- baseSummary: decodedSummary.baseSummary,
317
- outstandingOps,
318
- };
319
- }
320
- recordChange(op) {
321
- const lastOp = this.outstandingOps[this.outstandingOps.length - 1];
322
- if (lastOp !== undefined) {
323
- assert(lastOp.sequenceNumber < op.sequenceNumber, 0x1aa /* Out of order change recorded */);
324
- }
325
- this.invalidate(op.sequenceNumber);
326
- this.trackingSequenceNumber = op.sequenceNumber;
327
- this.outstandingOps.push(op);
328
- }
329
- invalidate(sequenceNumber) {
330
- if (sequenceNumber > this._changeSequenceNumber) {
331
- this._changeSequenceNumber = sequenceNumber;
332
- }
333
- }
334
- /**
335
- * True if a change has been recorded with sequence number exceeding
336
- * the latest successfully acked summary reference sequence number.
337
- * False implies that the previous summary can be reused.
338
- */
339
- hasChanged() {
340
- return this._changeSequenceNumber > this.referenceSequenceNumber;
341
- }
342
- get latestSummary() {
343
- return this._latestSummary;
344
- }
345
- createChild(
346
- /** Summarize function */
347
- summarizeInternalFn,
348
- /** Initial id or path part of this node */
349
- id,
350
- /**
351
- * Information needed to create the node.
352
- * If it is from a base summary, it will assert that a summary has been seen.
353
- * Attach information if it is created from an attach op.
354
- */
355
- createParam, config = {}) {
356
- assert(!this.children.has(id), 0x1ab /* "Create SummarizerNode child already exists" */);
357
- const createDetails = this.getCreateDetailsForChild(id, createParam);
358
- const child = new SummarizerNode(this.defaultLogger, summarizeInternalFn, config, createDetails.changeSequenceNumber, createDetails.latestSummary, createDetails.initialSummary, this.wipSummaryLogger);
359
- // There may be additional state that has to be updated in this child. For example, if a summary is being
360
- // tracked, the child's summary tracking state needs to be updated too.
361
- this.maybeUpdateChildState(child);
362
- this.children.set(id, child);
363
- return child;
364
- }
365
- getChild(id) {
366
- return this.children.get(id);
367
- }
368
- /**
369
- * Returns the details needed to create a child node.
370
- * @param id - Initial id or path part of the child node.
371
- * @param createParam - Information needed to create the node.
372
- * @returns the details needed to create the child node.
373
- */
374
- getCreateDetailsForChild(id, createParam) {
375
- var _a;
376
- let initialSummary;
377
- let latestSummary;
378
- let changeSequenceNumber;
379
- const parentLatestSummary = this._latestSummary;
380
- switch (createParam.type) {
381
- case CreateSummarizerNodeSource.FromAttach: {
382
- if (parentLatestSummary !== undefined
383
- && createParam.sequenceNumber <= parentLatestSummary.referenceSequenceNumber) {
384
- // Prioritize latest summary if it was after this node was attached.
385
- latestSummary = parentLatestSummary.createForChild(id);
386
- }
387
- else {
388
- const summary = convertToSummaryTree(createParam.snapshot);
389
- initialSummary = {
390
- sequenceNumber: createParam.sequenceNumber,
391
- id,
392
- summary,
393
- };
394
- }
395
- changeSequenceNumber = createParam.sequenceNumber;
396
- break;
397
- }
398
- case CreateSummarizerNodeSource.FromSummary: {
399
- if (this.initialSummary === undefined) {
400
- assert(!!parentLatestSummary, 0x1ac /* "Cannot create child from summary if parent does not have latest summary" */);
401
- }
402
- // fallthrough to local
403
- }
404
- case CreateSummarizerNodeSource.Local: {
405
- const parentInitialSummary = this.initialSummary;
406
- if (parentInitialSummary !== undefined) {
407
- let childSummary;
408
- if (parentInitialSummary.summary !== undefined) {
409
- const { childrenTree } = parseSummaryTreeForSubtrees(parentInitialSummary.summary.summary);
410
- assert(childrenTree.type === SummaryType.Tree, 0x1d6 /* "Parent summary object is not a tree" */);
411
- childSummary = childrenTree.tree[id];
412
- }
413
- if (createParam.type === CreateSummarizerNodeSource.FromSummary) {
414
- // Locally created would not have differential subtree.
415
- assert(!!childSummary, 0x1ad /* "Missing child summary tree" */);
416
- }
417
- let childSummaryWithStats;
418
- if (childSummary !== undefined) {
419
- assert(childSummary.type === SummaryType.Tree, 0x1ae /* "Child summary object is not a tree" */);
420
- childSummaryWithStats = {
421
- summary: childSummary,
422
- stats: calculateStats(childSummary),
423
- };
424
- }
425
- initialSummary = {
426
- sequenceNumber: parentInitialSummary.sequenceNumber,
427
- id,
428
- summary: childSummaryWithStats,
429
- };
430
- }
431
- latestSummary = parentLatestSummary === null || parentLatestSummary === void 0 ? void 0 : parentLatestSummary.createForChild(id);
432
- changeSequenceNumber = (_a = parentLatestSummary === null || parentLatestSummary === void 0 ? void 0 : parentLatestSummary.referenceSequenceNumber) !== null && _a !== void 0 ? _a : -1;
433
- break;
434
- }
435
- default: {
436
- const type = createParam.type;
437
- unreachableCase(createParam, `Unexpected CreateSummarizerNodeSource: ${type}`);
438
- }
439
- }
440
- return {
441
- initialSummary,
442
- latestSummary,
443
- changeSequenceNumber,
444
- };
445
- }
446
- /**
447
- * Updates the state of the child if required. For example, if a summary is currently being tracked, the child's
448
- * summary tracking state needs to be updated too.
449
- * @param child - The child node whose state is to be updated.
450
- */
451
- maybeUpdateChildState(child) {
452
- // If we are tracking a summary, this child was created after the tracking started. So, we need to update the
453
- // child's tracking state as well.
454
- if (this.isTrackingInProgress()) {
455
- child.wipReferenceSequenceNumber = this.wipReferenceSequenceNumber;
456
- }
457
- }
458
- /**
459
- * Tells whether summary tracking is in progress. True if "startSummary" API is called before summarize.
460
- */
461
- isTrackingInProgress() {
462
- return this.wipReferenceSequenceNumber !== undefined;
463
- }
464
- }
465
- /**
466
- * Creates a root summarizer node.
467
- * @param logger - Logger to use within SummarizerNode
468
- * @param summarizeInternalFn - Function to generate summary
469
- * @param changeSequenceNumber - Sequence number of latest change to new node/subtree
470
- * @param referenceSequenceNumber - Reference sequence number of last acked summary,
471
- * or undefined if not loaded from summary
472
- * @param config - Configure behavior of summarizer node
473
- */
474
- export const createRootSummarizerNode = (logger, summarizeInternalFn, changeSequenceNumber, referenceSequenceNumber, config = {}) => new SummarizerNode(logger, summarizeInternalFn, config, changeSequenceNumber, referenceSequenceNumber === undefined ? undefined : SummaryNode.createForRoot(referenceSequenceNumber));
475
- //# sourceMappingURL=summarizerNode.js.map