@fluidframework/driver-utils 2.0.0-internal.3.4.2 → 2.0.0-internal.4.0.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 (105) hide show
  1. package/dist/index.d.ts +3 -10
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +1 -21
  4. package/dist/index.js.map +1 -1
  5. package/dist/messageRecognition.d.ts +0 -20
  6. package/dist/messageRecognition.d.ts.map +1 -1
  7. package/dist/messageRecognition.js +1 -37
  8. package/dist/messageRecognition.js.map +1 -1
  9. package/dist/network.d.ts +0 -15
  10. package/dist/network.d.ts.map +1 -1
  11. package/dist/network.js.map +1 -1
  12. package/dist/networkUtils.d.ts +0 -12
  13. package/dist/networkUtils.d.ts.map +1 -1
  14. package/dist/networkUtils.js +1 -34
  15. package/dist/networkUtils.js.map +1 -1
  16. package/dist/packageVersion.d.ts +1 -1
  17. package/dist/packageVersion.js +1 -1
  18. package/dist/packageVersion.js.map +1 -1
  19. package/lib/index.d.ts +3 -10
  20. package/lib/index.d.ts.map +1 -1
  21. package/lib/index.js +2 -9
  22. package/lib/index.js.map +1 -1
  23. package/lib/messageRecognition.d.ts +0 -20
  24. package/lib/messageRecognition.d.ts.map +1 -1
  25. package/lib/messageRecognition.js +0 -35
  26. package/lib/messageRecognition.js.map +1 -1
  27. package/lib/network.d.ts +0 -15
  28. package/lib/network.d.ts.map +1 -1
  29. package/lib/network.js.map +1 -1
  30. package/lib/networkUtils.d.ts +0 -12
  31. package/lib/networkUtils.d.ts.map +1 -1
  32. package/lib/networkUtils.js +0 -32
  33. package/lib/networkUtils.js.map +1 -1
  34. package/lib/packageVersion.d.ts +1 -1
  35. package/lib/packageVersion.js +1 -1
  36. package/lib/packageVersion.js.map +1 -1
  37. package/package.json +64 -7
  38. package/src/index.ts +2 -19
  39. package/src/messageRecognition.ts +0 -36
  40. package/src/network.ts +0 -16
  41. package/src/networkUtils.ts +0 -34
  42. package/src/packageVersion.ts +1 -1
  43. package/dist/blobAggregationStorage.d.ts +0 -56
  44. package/dist/blobAggregationStorage.d.ts.map +0 -1
  45. package/dist/blobAggregationStorage.js +0 -327
  46. package/dist/blobAggregationStorage.js.map +0 -1
  47. package/dist/blobCacheStorageService.d.ts +0 -27
  48. package/dist/blobCacheStorageService.d.ts.map +0 -1
  49. package/dist/blobCacheStorageService.js +0 -40
  50. package/dist/blobCacheStorageService.js.map +0 -1
  51. package/dist/emptyDocumentDeltaStorageService.d.ts +0 -18
  52. package/dist/emptyDocumentDeltaStorageService.d.ts.map +0 -1
  53. package/dist/emptyDocumentDeltaStorageService.js +0 -25
  54. package/dist/emptyDocumentDeltaStorageService.js.map +0 -1
  55. package/dist/mapWithExpiration.d.ts +0 -75
  56. package/dist/mapWithExpiration.d.ts.map +0 -1
  57. package/dist/mapWithExpiration.js +0 -146
  58. package/dist/mapWithExpiration.js.map +0 -1
  59. package/dist/multiDocumentServiceFactory.d.ts +0 -34
  60. package/dist/multiDocumentServiceFactory.d.ts.map +0 -1
  61. package/dist/multiDocumentServiceFactory.js +0 -81
  62. package/dist/multiDocumentServiceFactory.js.map +0 -1
  63. package/dist/multiUrlResolver.d.ts +0 -34
  64. package/dist/multiUrlResolver.d.ts.map +0 -1
  65. package/dist/multiUrlResolver.js +0 -59
  66. package/dist/multiUrlResolver.js.map +0 -1
  67. package/dist/treeUtils.d.ts +0 -72
  68. package/dist/treeUtils.d.ts.map +0 -1
  69. package/dist/treeUtils.js +0 -102
  70. package/dist/treeUtils.js.map +0 -1
  71. package/lib/blobAggregationStorage.d.ts +0 -56
  72. package/lib/blobAggregationStorage.d.ts.map +0 -1
  73. package/lib/blobAggregationStorage.js +0 -322
  74. package/lib/blobAggregationStorage.js.map +0 -1
  75. package/lib/blobCacheStorageService.d.ts +0 -27
  76. package/lib/blobCacheStorageService.d.ts.map +0 -1
  77. package/lib/blobCacheStorageService.js +0 -36
  78. package/lib/blobCacheStorageService.js.map +0 -1
  79. package/lib/emptyDocumentDeltaStorageService.d.ts +0 -18
  80. package/lib/emptyDocumentDeltaStorageService.d.ts.map +0 -1
  81. package/lib/emptyDocumentDeltaStorageService.js +0 -21
  82. package/lib/emptyDocumentDeltaStorageService.js.map +0 -1
  83. package/lib/mapWithExpiration.d.ts +0 -75
  84. package/lib/mapWithExpiration.d.ts.map +0 -1
  85. package/lib/mapWithExpiration.js +0 -142
  86. package/lib/mapWithExpiration.js.map +0 -1
  87. package/lib/multiDocumentServiceFactory.d.ts +0 -34
  88. package/lib/multiDocumentServiceFactory.d.ts.map +0 -1
  89. package/lib/multiDocumentServiceFactory.js +0 -77
  90. package/lib/multiDocumentServiceFactory.js.map +0 -1
  91. package/lib/multiUrlResolver.d.ts +0 -34
  92. package/lib/multiUrlResolver.d.ts.map +0 -1
  93. package/lib/multiUrlResolver.js +0 -54
  94. package/lib/multiUrlResolver.js.map +0 -1
  95. package/lib/treeUtils.d.ts +0 -72
  96. package/lib/treeUtils.d.ts.map +0 -1
  97. package/lib/treeUtils.js +0 -97
  98. package/lib/treeUtils.js.map +0 -1
  99. package/src/blobAggregationStorage.ts +0 -430
  100. package/src/blobCacheStorageService.ts +0 -46
  101. package/src/emptyDocumentDeltaStorageService.ts +0 -30
  102. package/src/mapWithExpiration.ts +0 -165
  103. package/src/multiDocumentServiceFactory.ts +0 -109
  104. package/src/multiUrlResolver.ts +0 -62
  105. package/src/treeUtils.ts +0 -128
@@ -1,430 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
-
6
- import {
7
- FetchSource,
8
- IDocumentStorageService,
9
- IDocumentStorageServicePolicies,
10
- ISummaryContext,
11
- } from "@fluidframework/driver-definitions";
12
- import {
13
- ICreateBlobResponse,
14
- ISnapshotTree,
15
- ISummaryHandle,
16
- ISummaryTree,
17
- IVersion,
18
- SummaryType,
19
- } from "@fluidframework/protocol-definitions";
20
- import {
21
- assert,
22
- bufferToString,
23
- stringToBuffer,
24
- unreachableCase,
25
- fromUtf8ToBase64,
26
- Uint8ArrayToString,
27
- } from "@fluidframework/common-utils";
28
- import { ITelemetryLogger } from "@fluidframework/common-definitions";
29
- import { loggerToMonitoringContext } from "@fluidframework/telemetry-utils";
30
-
31
- /*
32
- * Work around for bufferToString having a bug - it can't consume IsoBuffer!
33
- * To be removed once bufferToString is fixed!
34
- */
35
- function bufferToString2(blob: ArrayBufferLike, encoding: "utf-8" | "base64"): string {
36
- if (blob instanceof Uint8Array) {
37
- // IsoBuffer does not have ctor, so it's not in proto chain :(
38
- return Uint8ArrayToString(blob, encoding);
39
- }
40
- return bufferToString(blob, encoding);
41
- }
42
-
43
- /**
44
- * Class responsible for aggregating smaller blobs into one and unpacking it later on.
45
- */
46
- class BlobAggregator {
47
- private readonly content: [string, string][] = [];
48
-
49
- public addBlob(key: string, content: string) {
50
- this.content.push([key, content]);
51
- }
52
-
53
- public getAggregatedBlobContent() {
54
- if (this.content.length === 0) {
55
- return undefined;
56
- }
57
- return JSON.stringify(this.content);
58
- }
59
-
60
- static load(input: ArrayBufferLike) {
61
- const data = bufferToString2(input, "utf-8");
62
- return JSON.parse(data) as [string, string][];
63
- }
64
- }
65
-
66
- /**
67
- * Base class that deals with unpacking snapshots (in place) containing aggregated blobs
68
- * It relies on abstract methods for reads and storing unpacked blobs.
69
- *
70
- * @deprecated This class was introduced experimentally and is no longer used.
71
- */
72
- export abstract class SnapshotExtractor {
73
- protected readonly aggregatedBlobName = "__big";
74
- protected readonly virtualIdPrefix = "__";
75
-
76
- // counter for generation of virtual storage IDs
77
- protected virtualIdCounter = 0;
78
- protected getNextVirtualId() {
79
- return `${this.virtualIdPrefix}${++this.virtualIdCounter}`;
80
- }
81
-
82
- abstract getBlob(id: string, tree: ISnapshotTree): Promise<ArrayBufferLike>;
83
- abstract setBlob(id: string, tree: ISnapshotTree, content: string);
84
-
85
- public async unpackSnapshotCore(snapshot: ISnapshotTree, level = 0): Promise<void> {
86
- for (const key of Object.keys(snapshot.trees)) {
87
- const obj = snapshot.trees[key];
88
- await this.unpackSnapshotCore(obj, level + 1);
89
- }
90
-
91
- // For future proof, we will support multiple aggregated blobs with any name
92
- // that starts with this.aggregatedBlobName
93
- for (const key of Object.keys(snapshot.blobs)) {
94
- if (!key.startsWith(this.aggregatedBlobName)) {
95
- continue;
96
- }
97
- const blobId = snapshot.blobs[key];
98
- if (blobId !== undefined) {
99
- const blob = await this.getBlob(blobId, snapshot);
100
- for (const [path, value] of BlobAggregator.load(blob)) {
101
- const id = this.getNextVirtualId();
102
- this.setBlob(id, snapshot, value);
103
- const pathSplit = path.split("/");
104
- let subTree = snapshot;
105
- for (const subPath of pathSplit.slice(0, pathSplit.length - 1)) {
106
- if (subTree.trees[subPath] === undefined) {
107
- subTree.trees[subPath] = { blobs: {}, trees: {} };
108
- }
109
- subTree = subTree.trees[subPath];
110
- }
111
- const blobName = pathSplit[pathSplit.length - 1];
112
- assert(
113
- subTree.blobs[blobName] === undefined,
114
- 0x0f6 /* "real blob ID exists" */,
115
- );
116
- subTree.blobs[blobName] = id;
117
- }
118
- // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
119
- delete snapshot.blobs[this.aggregatedBlobName];
120
- }
121
- }
122
- }
123
- }
124
-
125
- /*
126
- * Snapshot extractor class that works in place, i.e. patches snapshot that has
127
- * blob content in ISnapshotTree.blobs itself, not in storage.
128
- * As result, it implements reading and writing of blobs to/from snapshot itself.
129
- * It follows existing pattern that mixes concerns - ISnapshotTree.blobs is used for two
130
- * purposes:
131
- * 1. map path name to blob ID
132
- * 2. map blob ID to blob content
133
- * #2 is what storage (IDocumentStorageService) is for, but in places where we do not have it
134
- * (like loading serialized earlier draft content), blob content is put directly into snapshot.
135
- * Ideally this should be fixed by using BlobCacheStorageService or something similar and
136
- * fixing existing flows to allow switching of storage.
137
- */
138
- class SnapshotExtractorInPlace extends SnapshotExtractor {
139
- public async getBlob(id: string, tree: ISnapshotTree): Promise<ArrayBufferLike> {
140
- const blob = tree.blobs[id];
141
- assert(blob !== undefined, 0x0f7 /* "aggregate blob missing" */);
142
- return stringToBuffer(blob, "base64");
143
- }
144
-
145
- public setBlob(id: string, tree: ISnapshotTree, content: string) {
146
- assert(
147
- tree.blobs[id] === undefined,
148
- 0x0f8 /* "blob from aggregate blob exists on its own" */,
149
- );
150
- tree.blobs[id] = fromUtf8ToBase64(content);
151
- }
152
- }
153
-
154
- /**
155
- * Snapshot packer and extractor.
156
- * When summary is written it will find and aggregate small blobs into bigger blobs
157
- * When snapshot is read, it will unpack aggregated blobs and provide them transparently to caller.
158
- *
159
- * @deprecated This class was introduced experimentally and is no longer used.
160
- */
161
- export class BlobAggregationStorage extends SnapshotExtractor implements IDocumentStorageService {
162
- // Tells data store if it can use incremental summary (i.e. reuse DDSes from previous summary
163
- // when only one DDS changed).
164
- // The answer has to be know long before we enable actual packing. The reason for the is the following:
165
- // A the moment when we enable packing, we should assume that all clients out there wil already have bits
166
- // that can unpack properly (i.e. enough time passed since we deployed bits that can unpack)
167
- // But we can still have clients where some of them already pack, and some do not. If one summary was
168
- // using packing, then it relies on non-incremental summaries going forward, even if next client who
169
- // produced summary is not packing!
170
- // This can have slight improvement by enabling it per file (based on "did summary we loaded from contain
171
- // aggregated blobs"), but that's harder to make reliable, so going for simplicity.
172
- static readonly fullDataStoreSummaries = true;
173
-
174
- protected loadedFromSummary = false;
175
-
176
- protected virtualBlobs = new Map<string, ArrayBufferLike>();
177
-
178
- static wrap(
179
- storage: IDocumentStorageService,
180
- logger: ITelemetryLogger,
181
- allowPacking?: boolean,
182
- packingLevel = 2,
183
- ) {
184
- if (storage instanceof BlobAggregationStorage) {
185
- return storage;
186
- }
187
- const mc = loggerToMonitoringContext(logger);
188
- const realAllowPackaging =
189
- mc.config.getBoolean("FluidAggregateBlobs") ?? allowPacking ?? false;
190
-
191
- // Always create BlobAggregationStorage even if storage is not asking for packing.
192
- // This is mostly to avoid cases where future changes in policy would result in inability to
193
- // load old files that were created with aggregation on.
194
- const minBlobSize = storage.policies?.minBlobSize;
195
- return new BlobAggregationStorage(
196
- storage,
197
- logger,
198
- realAllowPackaging,
199
- packingLevel,
200
- minBlobSize,
201
- );
202
- }
203
-
204
- static async unpackSnapshot(snapshot: ISnapshotTree) {
205
- const converter = new SnapshotExtractorInPlace();
206
- await converter.unpackSnapshotCore(snapshot);
207
- }
208
-
209
- public get policies(): IDocumentStorageServicePolicies | undefined {
210
- const policies = this.storage.policies;
211
- if (policies) {
212
- return { ...policies, minBlobSize: undefined };
213
- }
214
- }
215
-
216
- public async unpackSnapshot(snapshot: ISnapshotTree) {
217
- // SummarizerNodeWithGC.refreshLatestSummary can call it when this.loadedFromSummary === false
218
- // (I assumed after file was created)
219
- // assert(!this.loadedFromSummary, "unpack without summary");
220
-
221
- this.loadedFromSummary = true;
222
- await this.unpackSnapshotCore(snapshot);
223
- }
224
-
225
- protected constructor(
226
- private readonly storage: IDocumentStorageService,
227
- private readonly logger: ITelemetryLogger,
228
- private readonly allowPacking: boolean,
229
- private readonly packingLevel: number,
230
- private readonly blobCutOffSize?: number,
231
- ) {
232
- super();
233
- }
234
-
235
- public setBlob(id: string, tree: ISnapshotTree, content: string) {
236
- this.virtualBlobs.set(id, stringToBuffer(content, "utf-8"));
237
- }
238
-
239
- public async getBlob(id: string, tree: ISnapshotTree): Promise<ArrayBufferLike> {
240
- return this.readBlob(id).catch((error) => {
241
- this.logger.sendErrorEvent({ eventName: "BlobDedupNoAggregateBlob" }, error);
242
- throw error;
243
- });
244
- }
245
-
246
- public get repositoryUrl() {
247
- return this.storage.repositoryUrl;
248
- }
249
- public async getVersions(
250
- versionId: string | null,
251
- count: number,
252
- scenarioName?: string,
253
- fetchSource?: FetchSource,
254
- ) {
255
- return this.storage.getVersions(versionId, count, scenarioName, fetchSource);
256
- }
257
-
258
- public async downloadSummary(handle: ISummaryHandle): Promise<ISummaryTree> {
259
- throw new Error("NYI");
260
- }
261
-
262
- // for now we are not optimizing these blobs, with assumption that this API is used only
263
- // for big blobs (images)
264
- public async createBlob(file: ArrayBufferLike): Promise<ICreateBlobResponse> {
265
- return this.storage.createBlob(file);
266
- }
267
-
268
- public async getSnapshotTree(version?: IVersion): Promise<ISnapshotTree | null> {
269
- const tree = await this.storage.getSnapshotTree(version);
270
- if (tree) {
271
- await this.unpackSnapshot(tree);
272
- }
273
- return tree;
274
- }
275
-
276
- public async readBlob(id: string): Promise<ArrayBufferLike> {
277
- if (this.isRealStorageId(id)) {
278
- return this.storage.readBlob(id);
279
- }
280
- // We support only reading blobs from the summary we loaded from.
281
- // This may need to be extended to any general summary in the future as runtime usage pattern
282
- // of storage changes (for example, data stores start to load from recent summary, not from original
283
- // summary whole container loaded from)
284
-
285
- // are there other ways we can get here? createFile is one flow, but we should not be reading blobs
286
- // in such flow
287
- assert(this.loadedFromSummary, 0x0f9 /* "never read summary" */);
288
- const blob = this.virtualBlobs.get(id);
289
- assert(blob !== undefined, 0x0fa /* "virtual blob not found" */);
290
- return blob;
291
- }
292
-
293
- public async uploadSummaryWithContext(
294
- summary: ISummaryTree,
295
- context: ISummaryContext,
296
- ): Promise<string> {
297
- const summaryNew = this.allowPacking ? await this.compressSmallBlobs(summary) : summary;
298
- return this.storage.uploadSummaryWithContext(summaryNew, context);
299
- }
300
-
301
- // For simplification, we assume that
302
- // - blob aggregation is done at data store level only for now
303
- // - data store either reuses previous summary, or generates full summary, i.e. there is no partial (some DDS)
304
- // summary produced by data stores.
305
- // These simplifications allow us not to touch handles, as they are self-contained (either do not use aggregated
306
- // blob or contain aggregated blob that stays relevant for that sub-tree)
307
- // Note:
308
- // From perf perspective, it makes sense to place aggregated blobs one level up in the tree to not create extra
309
- // tree nodes (i.e. have shallow tree with less edges). But that creates problems with reusability of trees at
310
- // incremental summary time - we would need to understand handles and parse them. In current design we can skip
311
- // that step because if data store is reused, the whole sub-tree is reused including aggregated blob embedded into it
312
- // and that means we can do nothing and be correct!
313
- private async compressSmallBlobs(
314
- summary: ISummaryTree,
315
- path = "",
316
- level = 0,
317
- aggregatorArg?: BlobAggregator,
318
- ): Promise<ISummaryTree> {
319
- if (this.blobCutOffSize === undefined || this.blobCutOffSize < 0) {
320
- return summary;
321
- }
322
-
323
- let shouldCompress: boolean = false;
324
-
325
- let aggregator = aggregatorArg;
326
- // checking if this is a dataStore tree, since we only pack at data store level
327
- if (Object.keys(summary.tree).includes(".component")) {
328
- assert(aggregator === undefined, 0x0fb /* "logic err with aggregator" */);
329
- assert(
330
- level === this.packingLevel,
331
- 0x23b /* "we are not packing at the right level" */,
332
- );
333
- aggregator = new BlobAggregator();
334
- shouldCompress = true;
335
- } else {
336
- assert(
337
- level !== this.packingLevel,
338
- 0x23c /* "we are not packing at the right level" */,
339
- );
340
- }
341
-
342
- const newSummary: ISummaryTree = { ...summary };
343
- newSummary.tree = { ...newSummary.tree };
344
- for (const key of Object.keys(summary.tree)) {
345
- const obj = summary.tree[key];
346
- // Get path relative to root of data store (where we do aggregation)
347
- const newPath = shouldCompress ? key : `${path}/${key}`;
348
- switch (obj.type) {
349
- case SummaryType.Tree:
350
- // If client created empty tree, keep it as is
351
- // Also do not package search blobs - they are part of storage contract
352
- if (Object.keys(obj).length !== 0 && key !== "__search") {
353
- const tree = await this.compressSmallBlobs(
354
- obj,
355
- newPath,
356
- level + 1,
357
- aggregator,
358
- );
359
- newSummary.tree[key] = tree;
360
- if (Object.keys(obj).length === 0) {
361
- // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
362
- delete newSummary.tree[key];
363
- }
364
- }
365
- break;
366
- case SummaryType.Blob:
367
- if (
368
- aggregator &&
369
- typeof obj.content == "string" &&
370
- obj.content.length < this.blobCutOffSize
371
- ) {
372
- aggregator.addBlob(newPath, obj.content);
373
- // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
374
- delete newSummary.tree[key];
375
- }
376
- break;
377
- case SummaryType.Handle: {
378
- // Would be nice to:
379
- // Trees: expand the tree
380
- // Blobs: parse handle and ensure it points to real blob, not virtual blob.
381
- // We can avoid it for now given data store is the granularity of incremental summaries.
382
- let handlePath = obj.handle;
383
- if (handlePath.startsWith("/")) {
384
- handlePath = handlePath.substr(1);
385
- }
386
- // Ensure only whole data stores can be reused, no reusing at deeper level!
387
- assert(level === 0, 0x0fc /* "tree reuse at lower level" */);
388
- assert(
389
- !handlePath.includes("/"),
390
- 0x0fd /* "data stores are writing incremental summaries!" */,
391
- );
392
- break;
393
- }
394
- case SummaryType.Attachment:
395
- assert(
396
- this.isRealStorageId(obj.id),
397
- 0x0fe /* "attachment is aggregate blob" */,
398
- );
399
- break;
400
- default:
401
- unreachableCase(obj, `Unknown type: ${(obj as any).type}`);
402
- }
403
- }
404
-
405
- assert(
406
- newSummary.tree[this.aggregatedBlobName] === undefined,
407
- 0x0ff /* "duplicate aggregate blob" */,
408
- );
409
- if (shouldCompress) {
410
- // Note: It would be great to add code here to unpack aggregate blob back to normal blobs
411
- // If only one blob made it into aggregate. Currently that does not happen as we always have
412
- // at least one .component blob and at least one DDS that has .attributes blob, so it's not an issue.
413
- // But it's possible that in future that would be great addition!
414
- // Good news - it's backward compatible change.
415
- assert(aggregator !== undefined, 0x100 /* "logic error" */);
416
- const content = aggregator.getAggregatedBlobContent();
417
- if (content !== undefined) {
418
- newSummary.tree[this.aggregatedBlobName] = {
419
- type: SummaryType.Blob,
420
- content,
421
- };
422
- }
423
- }
424
- return newSummary;
425
- }
426
-
427
- protected isRealStorageId(id: string): boolean {
428
- return !id.startsWith(this.virtualIdPrefix);
429
- }
430
- }
@@ -1,46 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
-
6
- import {
7
- IDocumentStorageService,
8
- IDocumentStorageServicePolicies,
9
- } from "@fluidframework/driver-definitions";
10
- import { DocumentStorageServiceProxy } from "./documentStorageServiceProxy";
11
-
12
- /**
13
- * IDocumentStorageService adapter with pre-cached blobs.
14
- *
15
- * @deprecated 2.0.0-internal.3.2.0 Not recommended for general purpose use.
16
- */
17
- export class BlobCacheStorageService extends DocumentStorageServiceProxy {
18
- /**
19
- * @deprecated 2.0.0-internal.3.2.0 Not recommended for general purpose use.
20
- */
21
- constructor(
22
- internalStorageService: IDocumentStorageService,
23
- private readonly blobs: Map<string, ArrayBufferLike>,
24
- ) {
25
- super(internalStorageService);
26
- }
27
-
28
- /**
29
- * @deprecated 2.0.0-internal.3.2.0 Not recommended for general purpose use.
30
- */
31
- public get policies(): IDocumentStorageServicePolicies | undefined {
32
- return this.internalStorageService.policies;
33
- }
34
-
35
- /**
36
- * @deprecated 2.0.0-internal.3.2.0 Not recommended for general purpose use.
37
- */
38
- public async readBlob(id: string): Promise<ArrayBufferLike> {
39
- const blob = this.blobs.get(id);
40
- if (blob !== undefined) {
41
- return blob;
42
- }
43
-
44
- return this.internalStorageService.readBlob(id);
45
- }
46
- }
@@ -1,30 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
-
6
- import { IDocumentDeltaStorageService, IStream } from "@fluidframework/driver-definitions";
7
- import { ISequencedDocumentMessage } from "@fluidframework/protocol-definitions";
8
- import { Queue } from "./parallelRequests";
9
-
10
- /**
11
- * Implementation of IDocumentDeltaStorageService that will always return an empty message queue when fetching messages
12
- *
13
- * @deprecated 2.0.0-internal.3.2.0 Not recommended for general purpose use.
14
- */
15
- export class EmptyDocumentDeltaStorageService implements IDocumentDeltaStorageService {
16
- /**
17
- * @deprecated 2.0.0-internal.3.2.0 Not recommended for general purpose use.
18
- */
19
- public fetchMessages(
20
- from: number,
21
- _to: number | undefined,
22
- _abortSignal?: AbortSignal,
23
- _cachedOnly?: boolean,
24
- _fetchReason?: string,
25
- ): IStream<ISequencedDocumentMessage[]> {
26
- const queue = new Queue<ISequencedDocumentMessage[]>();
27
- queue.pushDone();
28
- return queue;
29
- }
30
- }
@@ -1,165 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
-
6
- import { assert } from "@fluidframework/common-utils";
7
-
8
- /**
9
- * An extension of Map that expires (deletes) entries after a period of inactivity.
10
- * The policy is based on the last time a key was written to.
11
- *
12
- * @deprecated 2.0.0-internal.3.2.0 Not recommended for general purpose use.
13
- */
14
- export class MapWithExpiration<TKey = any, TValue = any> extends Map<TKey, TValue> {
15
- /** Timestamps (as epoch ms numbers) of when each key was last refreshed */
16
- private readonly lastRefreshedTimes = new Map<TKey, number>();
17
-
18
- /**
19
- * @deprecated 2.0.0-internal.3.2.0 Not recommended for general purpose use.
20
- */
21
- constructor(private readonly expiryMs: number) {
22
- super();
23
- }
24
-
25
- private refresh(key: TKey): void {
26
- this.lastRefreshedTimes.set(key, new Date().valueOf());
27
- }
28
-
29
- /**
30
- * Returns true if the key is present and expired, false if it's not expired, and undefined if it's not found
31
- * If cleanUp is passed as true, then delete any expired entry before returning.
32
- */
33
- private checkExpiry(key: TKey, cleanUp: boolean = false): boolean | undefined {
34
- const refreshTime = this.lastRefreshedTimes.get(key);
35
- assert(
36
- (refreshTime !== undefined) === super.has(key),
37
- 0x50c /* freshness map out of sync */,
38
- );
39
-
40
- if (refreshTime === undefined) {
41
- return undefined;
42
- }
43
- const expired = new Date().valueOf() - refreshTime >= this.expiryMs;
44
- if (expired && cleanUp) {
45
- this.delete(key);
46
- }
47
- return expired;
48
- }
49
-
50
- private clearExpiredEntries() {
51
- // forEach clears out any expired entries
52
- this.forEach(() => {});
53
- }
54
-
55
- /**
56
- * @deprecated 2.0.0-internal.3.2.0 Not recommended for general purpose use.
57
- */
58
- get size(): number {
59
- this.clearExpiredEntries();
60
- return super.size;
61
- }
62
-
63
- /**
64
- * @deprecated 2.0.0-internal.3.2.0 Not recommended for general purpose use.
65
- */
66
- has(key: TKey): boolean {
67
- this.checkExpiry(key, true /* cleanUp */);
68
- return super.has(key);
69
- }
70
-
71
- /**
72
- * @deprecated 2.0.0-internal.3.2.0 Not recommended for general purpose use.
73
- */
74
- get(key: TKey): TValue | undefined {
75
- this.checkExpiry(key, true /* cleanUp */);
76
- return super.get(key);
77
- }
78
-
79
- /**
80
- * @deprecated 2.0.0-internal.3.2.0 Not recommended for general purpose use.
81
- */
82
- set(key: TKey, value: TValue): this {
83
- // Sliding window expiration policy (on write)
84
- this.refresh(key);
85
- return super.set(key, value);
86
- }
87
-
88
- /**
89
- * @deprecated 2.0.0-internal.3.2.0 Not recommended for general purpose use.
90
- */
91
- delete(key: TKey): boolean {
92
- this.lastRefreshedTimes.delete(key);
93
- return super.delete(key);
94
- }
95
-
96
- /**
97
- * @deprecated 2.0.0-internal.3.2.0 Not recommended for general purpose use.
98
- */
99
- clear(): void {
100
- this.lastRefreshedTimes.clear();
101
- super.clear();
102
- }
103
-
104
- /**
105
- * @deprecated 2.0.0-internal.3.2.0 Not recommended for general purpose use.
106
- */
107
- forEach(
108
- callbackfn: (value: TValue, key: TKey, map: Map<TKey, TValue>) => void,
109
- thisArg?: any,
110
- ): void {
111
- const expiredKeys: TKey[] = [];
112
- super.forEach(
113
- (v, k, m) => {
114
- if (this.checkExpiry(k) === true) {
115
- expiredKeys.push(k);
116
- } else {
117
- callbackfn.bind(thisArg)(v, k, m);
118
- }
119
- },
120
- // Note we don't pass thisArg here, since we bind it directly to callbackFn and don't need it otherwise
121
- );
122
-
123
- // Clean up keys we know are expired now that we're done iterating
124
- expiredKeys.forEach((key: TKey) => {
125
- this.delete(key);
126
- });
127
- }
128
-
129
- /**
130
- * @deprecated 2.0.0-internal.3.2.0 Not recommended for general purpose use.
131
- */
132
- entries(): IterableIterator<[TKey, TValue]> {
133
- this.clearExpiredEntries();
134
- return super.entries();
135
- }
136
- /**
137
- * @deprecated 2.0.0-internal.3.2.0 Not recommended for general purpose use.
138
- */
139
- keys(): IterableIterator<TKey> {
140
- this.clearExpiredEntries();
141
- return super.keys();
142
- }
143
- /**
144
- * @deprecated 2.0.0-internal.3.2.0 Not recommended for general purpose use.
145
- */
146
- values(): IterableIterator<TValue> {
147
- this.clearExpiredEntries();
148
- return super.values();
149
- }
150
- /**
151
- * @deprecated 2.0.0-internal.3.2.0 Not recommended for general purpose use.
152
- */
153
- [Symbol.iterator](): IterableIterator<[TKey, TValue]> {
154
- this.clearExpiredEntries();
155
- return super[Symbol.iterator]();
156
- }
157
-
158
- /**
159
- * @deprecated 2.0.0-internal.3.2.0 Not recommended for general purpose use.
160
- */
161
- valueOf() {
162
- this.clearExpiredEntries();
163
- return super.valueOf();
164
- }
165
- }