@fluidframework/container-loader 2.0.0-internal.3.0.5 → 2.0.0-internal.3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. package/.eslintrc.js +18 -21
  2. package/.mocharc.js +2 -2
  3. package/README.md +45 -43
  4. package/api-extractor.json +2 -2
  5. package/closeAndGetPendingLocalState.md +51 -0
  6. package/dist/audience.d.ts.map +1 -1
  7. package/dist/audience.js.map +1 -1
  8. package/dist/catchUpMonitor.d.ts.map +1 -1
  9. package/dist/catchUpMonitor.js.map +1 -1
  10. package/dist/collabWindowTracker.d.ts.map +1 -1
  11. package/dist/collabWindowTracker.js.map +1 -1
  12. package/dist/connectionManager.d.ts +2 -2
  13. package/dist/connectionManager.d.ts.map +1 -1
  14. package/dist/connectionManager.js +51 -24
  15. package/dist/connectionManager.js.map +1 -1
  16. package/dist/connectionState.d.ts.map +1 -1
  17. package/dist/connectionState.js.map +1 -1
  18. package/dist/connectionStateHandler.d.ts.map +1 -1
  19. package/dist/connectionStateHandler.js +35 -16
  20. package/dist/connectionStateHandler.js.map +1 -1
  21. package/dist/container.d.ts +1 -10
  22. package/dist/container.d.ts.map +1 -1
  23. package/dist/container.js +89 -44
  24. package/dist/container.js.map +1 -1
  25. package/dist/containerContext.d.ts.map +1 -1
  26. package/dist/containerContext.js +6 -2
  27. package/dist/containerContext.js.map +1 -1
  28. package/dist/containerStorageAdapter.d.ts.map +1 -1
  29. package/dist/containerStorageAdapter.js +2 -4
  30. package/dist/containerStorageAdapter.js.map +1 -1
  31. package/dist/contracts.d.ts.map +1 -1
  32. package/dist/contracts.js.map +1 -1
  33. package/dist/deltaManager.d.ts +3 -3
  34. package/dist/deltaManager.d.ts.map +1 -1
  35. package/dist/deltaManager.js +56 -27
  36. package/dist/deltaManager.js.map +1 -1
  37. package/dist/deltaManagerProxy.d.ts.map +1 -1
  38. package/dist/deltaManagerProxy.js.map +1 -1
  39. package/dist/deltaQueue.d.ts.map +1 -1
  40. package/dist/deltaQueue.js +4 -2
  41. package/dist/deltaQueue.js.map +1 -1
  42. package/dist/index.d.ts +1 -1
  43. package/dist/index.d.ts.map +1 -1
  44. package/dist/index.js.map +1 -1
  45. package/dist/loader.d.ts +3 -3
  46. package/dist/loader.d.ts.map +1 -1
  47. package/dist/loader.js +18 -15
  48. package/dist/loader.js.map +1 -1
  49. package/dist/packageVersion.d.ts +1 -1
  50. package/dist/packageVersion.js +1 -1
  51. package/dist/packageVersion.js.map +1 -1
  52. package/dist/protocol.d.ts.map +1 -1
  53. package/dist/protocol.js +2 -1
  54. package/dist/protocol.js.map +1 -1
  55. package/dist/protocolTreeDocumentStorageService.d.ts.map +1 -1
  56. package/dist/protocolTreeDocumentStorageService.js.map +1 -1
  57. package/dist/quorum.d.ts.map +1 -1
  58. package/dist/quorum.js.map +1 -1
  59. package/dist/retriableDocumentStorageService.d.ts.map +1 -1
  60. package/dist/retriableDocumentStorageService.js +6 -2
  61. package/dist/retriableDocumentStorageService.js.map +1 -1
  62. package/dist/utils.d.ts.map +1 -1
  63. package/dist/utils.js +6 -4
  64. package/dist/utils.js.map +1 -1
  65. package/lib/audience.d.ts.map +1 -1
  66. package/lib/audience.js.map +1 -1
  67. package/lib/catchUpMonitor.d.ts.map +1 -1
  68. package/lib/catchUpMonitor.js.map +1 -1
  69. package/lib/collabWindowTracker.d.ts.map +1 -1
  70. package/lib/collabWindowTracker.js.map +1 -1
  71. package/lib/connectionManager.d.ts +2 -2
  72. package/lib/connectionManager.d.ts.map +1 -1
  73. package/lib/connectionManager.js +53 -26
  74. package/lib/connectionManager.js.map +1 -1
  75. package/lib/connectionState.d.ts.map +1 -1
  76. package/lib/connectionState.js.map +1 -1
  77. package/lib/connectionStateHandler.d.ts.map +1 -1
  78. package/lib/connectionStateHandler.js +35 -16
  79. package/lib/connectionStateHandler.js.map +1 -1
  80. package/lib/container.d.ts +1 -10
  81. package/lib/container.d.ts.map +1 -1
  82. package/lib/container.js +93 -48
  83. package/lib/container.js.map +1 -1
  84. package/lib/containerContext.d.ts.map +1 -1
  85. package/lib/containerContext.js +6 -2
  86. package/lib/containerContext.js.map +1 -1
  87. package/lib/containerStorageAdapter.d.ts.map +1 -1
  88. package/lib/containerStorageAdapter.js +2 -4
  89. package/lib/containerStorageAdapter.js.map +1 -1
  90. package/lib/contracts.d.ts.map +1 -1
  91. package/lib/contracts.js.map +1 -1
  92. package/lib/deltaManager.d.ts +3 -3
  93. package/lib/deltaManager.d.ts.map +1 -1
  94. package/lib/deltaManager.js +58 -29
  95. package/lib/deltaManager.js.map +1 -1
  96. package/lib/deltaManagerProxy.d.ts.map +1 -1
  97. package/lib/deltaManagerProxy.js.map +1 -1
  98. package/lib/deltaQueue.d.ts.map +1 -1
  99. package/lib/deltaQueue.js +4 -2
  100. package/lib/deltaQueue.js.map +1 -1
  101. package/lib/index.d.ts +1 -1
  102. package/lib/index.d.ts.map +1 -1
  103. package/lib/index.js.map +1 -1
  104. package/lib/loader.d.ts +3 -3
  105. package/lib/loader.d.ts.map +1 -1
  106. package/lib/loader.js +18 -15
  107. package/lib/loader.js.map +1 -1
  108. package/lib/packageVersion.d.ts +1 -1
  109. package/lib/packageVersion.js +1 -1
  110. package/lib/packageVersion.js.map +1 -1
  111. package/lib/protocol.d.ts.map +1 -1
  112. package/lib/protocol.js +2 -1
  113. package/lib/protocol.js.map +1 -1
  114. package/lib/protocolTreeDocumentStorageService.d.ts.map +1 -1
  115. package/lib/protocolTreeDocumentStorageService.js.map +1 -1
  116. package/lib/quorum.d.ts.map +1 -1
  117. package/lib/quorum.js.map +1 -1
  118. package/lib/retriableDocumentStorageService.d.ts.map +1 -1
  119. package/lib/retriableDocumentStorageService.js +6 -2
  120. package/lib/retriableDocumentStorageService.js.map +1 -1
  121. package/lib/utils.d.ts.map +1 -1
  122. package/lib/utils.js +6 -4
  123. package/lib/utils.js.map +1 -1
  124. package/package.json +115 -114
  125. package/prettier.config.cjs +1 -1
  126. package/src/audience.ts +51 -46
  127. package/src/catchUpMonitor.ts +39 -37
  128. package/src/collabWindowTracker.ts +75 -70
  129. package/src/connectionManager.ts +1006 -944
  130. package/src/connectionState.ts +19 -19
  131. package/src/connectionStateHandler.ts +544 -465
  132. package/src/container.ts +2056 -1909
  133. package/src/containerContext.ts +350 -340
  134. package/src/containerStorageAdapter.ts +163 -153
  135. package/src/contracts.ts +155 -153
  136. package/src/deltaManager.ts +1069 -992
  137. package/src/deltaManagerProxy.ts +143 -137
  138. package/src/deltaQueue.ts +155 -151
  139. package/src/index.ts +14 -17
  140. package/src/loader.ts +428 -430
  141. package/src/packageVersion.ts +1 -1
  142. package/src/protocol.ts +93 -87
  143. package/src/protocolTreeDocumentStorageService.ts +30 -33
  144. package/src/quorum.ts +34 -34
  145. package/src/retriableDocumentStorageService.ts +118 -102
  146. package/src/utils.ts +89 -82
  147. package/tsconfig.esnext.json +6 -6
  148. package/tsconfig.json +8 -12
@@ -7,19 +7,19 @@ import { IDisposable, ITelemetryLogger } from "@fluidframework/common-definition
7
7
  import { assert } from "@fluidframework/common-utils";
8
8
  import { ISnapshotTreeWithBlobContents } from "@fluidframework/container-definitions";
9
9
  import {
10
- FetchSource,
11
- IDocumentService,
12
- IDocumentStorageService,
13
- IDocumentStorageServicePolicies,
14
- ISummaryContext,
10
+ FetchSource,
11
+ IDocumentService,
12
+ IDocumentStorageService,
13
+ IDocumentStorageServicePolicies,
14
+ ISummaryContext,
15
15
  } from "@fluidframework/driver-definitions";
16
16
  import { UsageError } from "@fluidframework/driver-utils";
17
17
  import {
18
- ICreateBlobResponse,
19
- ISnapshotTree,
20
- ISummaryHandle,
21
- ISummaryTree,
22
- IVersion,
18
+ ICreateBlobResponse,
19
+ ISnapshotTree,
20
+ ISummaryHandle,
21
+ ISummaryTree,
22
+ IVersion,
23
23
  } from "@fluidframework/protocol-definitions";
24
24
  import { IDetachedBlobStorage } from "./loader";
25
25
  import { ProtocolTreeStorageService } from "./protocolTreeDocumentStorageService";
@@ -30,103 +30,113 @@ import { RetriableDocumentStorageService } from "./retriableDocumentStorageServi
30
30
  * container attach state.
31
31
  */
32
32
  export class ContainerStorageAdapter implements IDocumentStorageService, IDisposable {
33
- private readonly blobContents: { [id: string]: ArrayBufferLike; } = {};
34
- private _storageService: IDocumentStorageService & Partial<IDisposable>;
35
-
36
- constructor(
37
- detachedBlobStorage: IDetachedBlobStorage | undefined,
38
- private readonly logger: ITelemetryLogger,
39
- private readonly captureProtocolSummary?: () => ISummaryTree,
40
- ) {
41
- this._storageService = new BlobOnlyStorage(detachedBlobStorage, logger);
42
- }
43
-
44
- disposed: boolean = false;
45
- dispose(error?: Error): void {
46
- this._storageService?.dispose?.(error);
47
- this.disposed = true;
48
- }
49
-
50
- public async connectToService(service: IDocumentService): Promise<void> {
51
- if (!(this._storageService instanceof BlobOnlyStorage)) {
52
- return;
53
- }
54
-
55
- const storageService = await service.connectToStorage();
56
- const retriableStorage = this._storageService =
57
- new RetriableDocumentStorageService(
58
- storageService,
59
- this.logger);
60
-
61
- if (this.captureProtocolSummary !== undefined) {
62
- this.logger.sendTelemetryEvent({ eventName: "summarizeProtocolTreeEnabled" });
63
- this._storageService =
64
- new ProtocolTreeStorageService(retriableStorage, this.captureProtocolSummary);
65
- }
66
-
67
- // ensure we did not lose that policy in the process of wrapping
68
- assert(storageService.policies?.minBlobSize === this._storageService.policies?.minBlobSize,
69
- 0x0e0 /* "lost minBlobSize policy" */);
70
- }
71
-
72
- public loadSnapshotForRehydratingContainer(snapshotTree: ISnapshotTreeWithBlobContents) {
73
- this.getBlobContents(snapshotTree);
74
- }
75
-
76
- private getBlobContents(snapshotTree: ISnapshotTreeWithBlobContents) {
77
- for (const [id, value] of Object.entries(snapshotTree.blobsContents)) {
78
- this.blobContents[id] = value;
79
- }
80
- for (const [_, tree] of Object.entries(snapshotTree.trees)) {
81
- this.getBlobContents(tree);
82
- }
83
- }
84
-
85
- public get policies(): IDocumentStorageServicePolicies | undefined {
86
- // back-compat 0.40 containerRuntime requests policies even in detached container if storage is present
87
- // and storage is always present in >=0.41.
88
- try {
89
- return this._storageService.policies;
90
- } catch (e) {}
91
- return undefined;
92
- }
93
-
94
- public get repositoryUrl(): string {
95
- return this._storageService.repositoryUrl;
96
- }
97
-
98
- public async getSnapshotTree(version?: IVersion, scenarioName?: string): Promise<ISnapshotTree | null> {
99
- return this._storageService.getSnapshotTree(version, scenarioName);
100
- }
101
-
102
- public async readBlob(id: string): Promise<ArrayBufferLike> {
103
- const blob = this.blobContents[id];
104
- if (blob !== undefined) {
105
- return blob;
106
- }
107
- return this._storageService.readBlob(id);
108
- }
109
-
110
- public async getVersions(
111
- versionId: string | null,
112
- count: number,
113
- scenarioName?: string,
114
- fetchSource?: FetchSource,
115
- ): Promise<IVersion[]> {
116
- return this._storageService.getVersions(versionId, count, scenarioName, fetchSource);
117
- }
118
-
119
- public async uploadSummaryWithContext(summary: ISummaryTree, context: ISummaryContext): Promise<string> {
120
- return this._storageService.uploadSummaryWithContext(summary, context);
121
- }
122
-
123
- public async downloadSummary(handle: ISummaryHandle): Promise<ISummaryTree> {
124
- return this._storageService.downloadSummary(handle);
125
- }
126
-
127
- public async createBlob(file: ArrayBufferLike): Promise<ICreateBlobResponse> {
128
- return this._storageService.createBlob(file);
129
- }
33
+ private readonly blobContents: { [id: string]: ArrayBufferLike } = {};
34
+ private _storageService: IDocumentStorageService & Partial<IDisposable>;
35
+
36
+ constructor(
37
+ detachedBlobStorage: IDetachedBlobStorage | undefined,
38
+ private readonly logger: ITelemetryLogger,
39
+ private readonly captureProtocolSummary?: () => ISummaryTree,
40
+ ) {
41
+ this._storageService = new BlobOnlyStorage(detachedBlobStorage, logger);
42
+ }
43
+
44
+ disposed: boolean = false;
45
+ dispose(error?: Error): void {
46
+ this._storageService?.dispose?.(error);
47
+ this.disposed = true;
48
+ }
49
+
50
+ public async connectToService(service: IDocumentService): Promise<void> {
51
+ if (!(this._storageService instanceof BlobOnlyStorage)) {
52
+ return;
53
+ }
54
+
55
+ const storageService = await service.connectToStorage();
56
+ const retriableStorage = (this._storageService = new RetriableDocumentStorageService(
57
+ storageService,
58
+ this.logger,
59
+ ));
60
+
61
+ if (this.captureProtocolSummary !== undefined) {
62
+ this.logger.sendTelemetryEvent({ eventName: "summarizeProtocolTreeEnabled" });
63
+ this._storageService = new ProtocolTreeStorageService(
64
+ retriableStorage,
65
+ this.captureProtocolSummary,
66
+ );
67
+ }
68
+
69
+ // ensure we did not lose that policy in the process of wrapping
70
+ assert(
71
+ storageService.policies?.minBlobSize === this._storageService.policies?.minBlobSize,
72
+ 0x0e0 /* "lost minBlobSize policy" */,
73
+ );
74
+ }
75
+
76
+ public loadSnapshotForRehydratingContainer(snapshotTree: ISnapshotTreeWithBlobContents) {
77
+ this.getBlobContents(snapshotTree);
78
+ }
79
+
80
+ private getBlobContents(snapshotTree: ISnapshotTreeWithBlobContents) {
81
+ for (const [id, value] of Object.entries(snapshotTree.blobsContents)) {
82
+ this.blobContents[id] = value;
83
+ }
84
+ for (const [_, tree] of Object.entries(snapshotTree.trees)) {
85
+ this.getBlobContents(tree);
86
+ }
87
+ }
88
+
89
+ public get policies(): IDocumentStorageServicePolicies | undefined {
90
+ // back-compat 0.40 containerRuntime requests policies even in detached container if storage is present
91
+ // and storage is always present in >=0.41.
92
+ try {
93
+ return this._storageService.policies;
94
+ } catch (e) {}
95
+ return undefined;
96
+ }
97
+
98
+ public get repositoryUrl(): string {
99
+ return this._storageService.repositoryUrl;
100
+ }
101
+
102
+ public async getSnapshotTree(
103
+ version?: IVersion,
104
+ scenarioName?: string,
105
+ ): Promise<ISnapshotTree | null> {
106
+ return this._storageService.getSnapshotTree(version, scenarioName);
107
+ }
108
+
109
+ public async readBlob(id: string): Promise<ArrayBufferLike> {
110
+ const blob = this.blobContents[id];
111
+ if (blob !== undefined) {
112
+ return blob;
113
+ }
114
+ return this._storageService.readBlob(id);
115
+ }
116
+
117
+ public async getVersions(
118
+ versionId: string | null,
119
+ count: number,
120
+ scenarioName?: string,
121
+ fetchSource?: FetchSource,
122
+ ): Promise<IVersion[]> {
123
+ return this._storageService.getVersions(versionId, count, scenarioName, fetchSource);
124
+ }
125
+
126
+ public async uploadSummaryWithContext(
127
+ summary: ISummaryTree,
128
+ context: ISummaryContext,
129
+ ): Promise<string> {
130
+ return this._storageService.uploadSummaryWithContext(summary, context);
131
+ }
132
+
133
+ public async downloadSummary(handle: ISummaryHandle): Promise<ISummaryTree> {
134
+ return this._storageService.downloadSummary(handle);
135
+ }
136
+
137
+ public async createBlob(file: ArrayBufferLike): Promise<ICreateBlobResponse> {
138
+ return this._storageService.createBlob(file);
139
+ }
130
140
  }
131
141
 
132
142
  /**
@@ -134,50 +144,50 @@ export class ContainerStorageAdapter implements IDocumentStorageService, IDispos
134
144
  * blobs in detached containers.
135
145
  */
136
146
  class BlobOnlyStorage implements IDocumentStorageService {
137
- constructor(
138
- private readonly detachedStorage: IDetachedBlobStorage | undefined,
139
- private readonly logger: ITelemetryLogger,
140
- ) { }
141
-
142
- public async createBlob(content: ArrayBufferLike): Promise<ICreateBlobResponse> {
143
- return this.verifyStorage().createBlob(content);
144
- }
145
-
146
- public async readBlob(blobId: string): Promise<ArrayBufferLike> {
147
- return this.verifyStorage().readBlob(blobId);
148
- }
149
-
150
- private verifyStorage(): IDetachedBlobStorage {
151
- if (this.detachedStorage === undefined) {
152
- throw new UsageError("Real storage calls not allowed in Unattached container");
153
- }
154
- return this.detachedStorage;
155
- }
156
-
157
- public get policies(): IDocumentStorageServicePolicies | undefined {
158
- return this.notCalled();
159
- }
160
-
161
- public get repositoryUrl(): string {
162
- return this.notCalled();
163
- }
164
-
165
- /* eslint-disable @typescript-eslint/unbound-method */
166
- public getSnapshotTree: () => Promise<ISnapshotTree | null> = this.notCalled;
167
- public getVersions: () => Promise<IVersion[]> = this.notCalled;
168
- public write: () => Promise<IVersion> = this.notCalled;
169
- public uploadSummaryWithContext: () => Promise<string> = this.notCalled;
170
- public downloadSummary: () => Promise<ISummaryTree> = this.notCalled;
171
- /* eslint-enable @typescript-eslint/unbound-method */
172
-
173
- private notCalled(): never {
174
- this.verifyStorage();
175
- try {
176
- // some browsers may not populate stack unless exception is thrown
177
- throw new Error("BlobOnlyStorage not implemented method used");
178
- } catch (err) {
179
- this.logger.sendTelemetryEvent({ eventName: "BlobOnlyStorageWrongCall" }, err);
180
- throw err;
181
- }
182
- }
147
+ constructor(
148
+ private readonly detachedStorage: IDetachedBlobStorage | undefined,
149
+ private readonly logger: ITelemetryLogger,
150
+ ) {}
151
+
152
+ public async createBlob(content: ArrayBufferLike): Promise<ICreateBlobResponse> {
153
+ return this.verifyStorage().createBlob(content);
154
+ }
155
+
156
+ public async readBlob(blobId: string): Promise<ArrayBufferLike> {
157
+ return this.verifyStorage().readBlob(blobId);
158
+ }
159
+
160
+ private verifyStorage(): IDetachedBlobStorage {
161
+ if (this.detachedStorage === undefined) {
162
+ throw new UsageError("Real storage calls not allowed in Unattached container");
163
+ }
164
+ return this.detachedStorage;
165
+ }
166
+
167
+ public get policies(): IDocumentStorageServicePolicies | undefined {
168
+ return this.notCalled();
169
+ }
170
+
171
+ public get repositoryUrl(): string {
172
+ return this.notCalled();
173
+ }
174
+
175
+ /* eslint-disable @typescript-eslint/unbound-method */
176
+ public getSnapshotTree: () => Promise<ISnapshotTree | null> = this.notCalled;
177
+ public getVersions: () => Promise<IVersion[]> = this.notCalled;
178
+ public write: () => Promise<IVersion> = this.notCalled;
179
+ public uploadSummaryWithContext: () => Promise<string> = this.notCalled;
180
+ public downloadSummary: () => Promise<ISummaryTree> = this.notCalled;
181
+ /* eslint-enable @typescript-eslint/unbound-method */
182
+
183
+ private notCalled(): never {
184
+ this.verifyStorage();
185
+ try {
186
+ // some browsers may not populate stack unless exception is thrown
187
+ throw new Error("BlobOnlyStorage not implemented method used");
188
+ } catch (err) {
189
+ this.logger.sendTelemetryEvent({ eventName: "BlobOnlyStorageWrongCall" }, err);
190
+ throw err;
191
+ }
192
+ }
183
193
  }