@fluidframework/file-driver 2.1.0-276985 → 2.1.0
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.
- package/CHANGELOG.md +4 -0
- package/README.md +84 -2
- package/dist/fileDeltaStorageService.d.ts.map +1 -1
- package/dist/fileDeltaStorageService.js +6 -1
- package/dist/fileDeltaStorageService.js.map +1 -1
- package/dist/fileDocumentStorageService.d.ts.map +1 -1
- package/dist/fileDocumentStorageService.js +4 -0
- package/dist/fileDocumentStorageService.js.map +1 -1
- package/dist/public.d.ts +1 -1
- package/internal.d.ts +1 -1
- package/lib/fileDeltaStorageService.d.ts.map +1 -1
- package/lib/fileDeltaStorageService.js +6 -1
- package/lib/fileDeltaStorageService.js.map +1 -1
- package/lib/fileDocumentStorageService.d.ts.map +1 -1
- package/lib/fileDocumentStorageService.js +4 -0
- package/lib/fileDocumentStorageService.js.map +1 -1
- package/lib/public.d.ts +1 -1
- package/package.json +14 -14
- package/src/fileDeltaStorageService.ts +6 -2
- package/src/fileDocumentStorageService.ts +6 -2
- package/tsconfig.json +0 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
This is an implementation of a driver which provides a DocumentService which uses local filesystem to get data for different endpoints like Document Storage, Delta Storage and Delta stream. It also provides implementation of Document Storage, Delta Storage and Delta stream. It also has a replay service which provides user the capability to replays ops accordingly.
|
|
4
4
|
|
|
5
|
-
<!-- AUTO-GENERATED-CONTENT:START (
|
|
5
|
+
<!-- AUTO-GENERATED-CONTENT:START (LIBRARY_PACKAGE_README_HEADER) -->
|
|
6
6
|
|
|
7
7
|
<!-- prettier-ignore-start -->
|
|
8
8
|
<!-- NOTE: This section is automatically generated using @fluid-tools/markdown-magic. Do not update these generated contents directly. -->
|
|
@@ -15,15 +15,97 @@ library consumers should always prefer `^`.
|
|
|
15
15
|
|
|
16
16
|
If using any of Fluid Framework's unstable APIs (for example, its `beta` APIs), we recommend using a more constrained version range, such as `~`.
|
|
17
17
|
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
To get started, install the package by running the following command:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm i @fluidframework/file-driver
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## API Documentation
|
|
27
|
+
|
|
28
|
+
API documentation for **@fluidframework/file-driver** is available at <https://fluidframework.com/docs/apis/file-driver>.
|
|
29
|
+
|
|
18
30
|
<!-- prettier-ignore-end -->
|
|
19
31
|
|
|
20
32
|
<!-- AUTO-GENERATED-CONTENT:END -->
|
|
21
33
|
|
|
22
|
-
<!-- AUTO-GENERATED-CONTENT:START (
|
|
34
|
+
<!-- AUTO-GENERATED-CONTENT:START (LIBRARY_PACKAGE_README_FOOTER) -->
|
|
23
35
|
|
|
24
36
|
<!-- prettier-ignore-start -->
|
|
25
37
|
<!-- NOTE: This section is automatically generated using @fluid-tools/markdown-magic. Do not update these generated contents directly. -->
|
|
26
38
|
|
|
39
|
+
## Minimum Client Requirements
|
|
40
|
+
|
|
41
|
+
These are the platform requirements for the current version of Fluid Framework Client Packages.
|
|
42
|
+
These requirements err on the side of being too strict since within a major version they can be relaxed over time, but not made stricter.
|
|
43
|
+
For Long Term Support (LTS) versions this can require supporting these platforms for several years.
|
|
44
|
+
|
|
45
|
+
It is likely that other configurations will work, but they are not supported: if they stop working, we do not consider that a bug.
|
|
46
|
+
If you would benefit from support for something not listed here, file an issue and the product team will evaluate your request.
|
|
47
|
+
When making such a request please include if the configuration already works (and thus the request is just that it becomes officially supported), or if changes are required to get it working.
|
|
48
|
+
|
|
49
|
+
### Supported Runtimes
|
|
50
|
+
|
|
51
|
+
- NodeJs ^20.10.0 except that we will drop support for it [when NodeJs 20 loses its upstream support on 2026-04-30](https://github.com/nodejs/release#release-schedule), and will support a newer LTS version of NodeJS (22) at least 1 year before 20 is end-of-life. This same policy applies to NodeJS 22 when it is end of life (2027-04-30).
|
|
52
|
+
- Modern browsers supporting the es2022 standard library: in response to asks we can add explicit support for using babel to polyfill to target specific standards or runtimes (meaning we can avoid/remove use of things that don't polyfill robustly, but otherwise target modern standards).
|
|
53
|
+
|
|
54
|
+
### Supported Tools
|
|
55
|
+
|
|
56
|
+
- TypeScript 5.4:
|
|
57
|
+
- All [`strict`](https://www.typescriptlang.org/tsconfig) options are supported.
|
|
58
|
+
- [`strictNullChecks`](https://www.typescriptlang.org/tsconfig) is required.
|
|
59
|
+
- [Configuration options deprecated in 5.0](https://github.com/microsoft/TypeScript/issues/51909) are not supported.
|
|
60
|
+
- `exactOptionalPropertyTypes` is currently not fully supported.
|
|
61
|
+
If used, narrowing members of Fluid Framework types types using `in`, `Reflect.has`, `Object.hasOwn` or `Object.prototype.hasOwnProperty` should be avoided as they may incorrectly exclude `undefined` from the possible values in some cases.
|
|
62
|
+
- [webpack](https://webpack.js.org/) 5
|
|
63
|
+
- We are not intending to be prescriptive about what bundler to use.
|
|
64
|
+
Other bundlers which can handle ES Modules should work, but webpack is the only one we actively test.
|
|
65
|
+
|
|
66
|
+
### Module Resolution
|
|
67
|
+
|
|
68
|
+
[`Node16`, `NodeNext`, or `Bundler`](https://www.typescriptlang.org/tsconfig#moduleResolution) resolution should be used with TypeScript compilerOptions to follow the [Node.js v12+ ESM Resolution and Loading algorithm](https://nodejs.github.io/nodejs.dev/en/api/v20/esm/#resolution-and-loading-algorithm).
|
|
69
|
+
Node10 resolution is not supported as it does not support Fluid Framework's API structuring pattern that is used to distinguish stable APIs from those that are in development.
|
|
70
|
+
|
|
71
|
+
### Module Formats
|
|
72
|
+
|
|
73
|
+
- ES Modules:
|
|
74
|
+
ES Modules are the preferred way to consume our client packages (including in NodeJs) and consuming our client packages from ES Modules is fully supported.
|
|
75
|
+
- CommonJs:
|
|
76
|
+
Consuming our client packages as CommonJs is supported only in NodeJS and only for the cases listed below.
|
|
77
|
+
This is done to accommodate some workflows without good ES Module support.
|
|
78
|
+
If you have a workflow you would like included in this list, file an issue.
|
|
79
|
+
Once this list of workflows motivating CommonJS support is empty, we may drop support for CommonJS one year after notice of the change is posted here.
|
|
80
|
+
|
|
81
|
+
- Testing with Jest (which lacks [stable ESM support](https://jestjs.io/docs/ecmascript-modules) due to [unstable APIs in NodeJs](https://github.com/nodejs/node/issues/37648))
|
|
82
|
+
|
|
83
|
+
## Contribution Guidelines
|
|
84
|
+
|
|
85
|
+
There are many ways to [contribute](https://github.com/microsoft/FluidFramework/blob/main/CONTRIBUTING.md) to Fluid.
|
|
86
|
+
|
|
87
|
+
- Participate in Q&A in our [GitHub Discussions](https://github.com/microsoft/FluidFramework/discussions).
|
|
88
|
+
- [Submit bugs](https://github.com/microsoft/FluidFramework/issues) and help us verify fixes as they are checked in.
|
|
89
|
+
- Review the [source code changes](https://github.com/microsoft/FluidFramework/pulls).
|
|
90
|
+
- [Contribute bug fixes](https://github.com/microsoft/FluidFramework/blob/main/CONTRIBUTING.md).
|
|
91
|
+
|
|
92
|
+
Detailed instructions for working in the repo can be found in the [Wiki](https://github.com/microsoft/FluidFramework/wiki).
|
|
93
|
+
|
|
94
|
+
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
|
|
95
|
+
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
|
|
96
|
+
|
|
97
|
+
This project may contain Microsoft trademarks or logos for Microsoft projects, products, or services.
|
|
98
|
+
Use of these trademarks or logos must follow Microsoft’s [Trademark & Brand Guidelines](https://www.microsoft.com/trademarks).
|
|
99
|
+
Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
|
|
100
|
+
|
|
101
|
+
## Help
|
|
102
|
+
|
|
103
|
+
Not finding what you're looking for in this README? Check out [fluidframework.com](https://fluidframework.com/docs/).
|
|
104
|
+
|
|
105
|
+
Still not finding what you're looking for? Please [file an issue](https://github.com/microsoft/FluidFramework/wiki/Submitting-Bugs-and-Feature-Requests).
|
|
106
|
+
|
|
107
|
+
Thank you!
|
|
108
|
+
|
|
27
109
|
## Trademark
|
|
28
110
|
|
|
29
111
|
This project may contain Microsoft trademarks or logos for Microsoft projects, products, or services.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileDeltaStorageService.d.ts","sourceRoot":"","sources":["../src/fileDeltaStorageService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EACN,4BAA4B,EAC5B,OAAO,EACP,yBAAyB,EACzB,MAAM,6CAA6C,CAAC;AAGrD;;;GAGG;AACH,qBAAa,uBAAwB,YAAW,4BAA4B;IAI/D,OAAO,CAAC,QAAQ,CAAC,IAAI;IAHjC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA8B;IACvD,OAAO,CAAC,OAAO,CAAmC;gBAErB,IAAI,EAAE,MAAM;IAkBlC,aAAa,CACnB,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,GAAG,SAAS,EACtB,WAAW,CAAC,EAAE,WAAW,EACzB,UAAU,CAAC,EAAE,OAAO,GAClB,OAAO,CAAC,yBAAyB,EAAE,CAAC;IAIvC,IAAW,GAAG,IAAI,SAAS,QAAQ,CAAC,yBAAyB,CAAC,EAAE,CAE/D;IAED;;;;;OAKG;IACI,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,yBAAyB,EAAE;
|
|
1
|
+
{"version":3,"file":"fileDeltaStorageService.d.ts","sourceRoot":"","sources":["../src/fileDeltaStorageService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EACN,4BAA4B,EAC5B,OAAO,EACP,yBAAyB,EACzB,MAAM,6CAA6C,CAAC;AAGrD;;;GAGG;AACH,qBAAa,uBAAwB,YAAW,4BAA4B;IAI/D,OAAO,CAAC,QAAQ,CAAC,IAAI;IAHjC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA8B;IACvD,OAAO,CAAC,OAAO,CAAmC;gBAErB,IAAI,EAAE,MAAM;IAkBlC,aAAa,CACnB,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,GAAG,SAAS,EACtB,WAAW,CAAC,EAAE,WAAW,EACzB,UAAU,CAAC,EAAE,OAAO,GAClB,OAAO,CAAC,yBAAyB,EAAE,CAAC;IAIvC,IAAW,GAAG,IAAI,SAAS,QAAQ,CAAC,yBAAyB,CAAC,EAAE,CAE/D;IAED;;;;;OAKG;IACI,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,yBAAyB,EAAE;CAuB9E"}
|
|
@@ -54,11 +54,16 @@ class FileDeltaStorageService {
|
|
|
54
54
|
return [];
|
|
55
55
|
}
|
|
56
56
|
// Optimizations for multiple readers (replay tool)
|
|
57
|
+
// Non null asserting here because of the length check
|
|
58
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
57
59
|
if (this.lastOps.length > 0 && this.lastOps[0].sequenceNumber === readFrom + 1) {
|
|
58
60
|
return this.lastOps;
|
|
59
61
|
}
|
|
60
62
|
this.lastOps = this.messages.slice(readFrom, readTo);
|
|
61
|
-
(0, internal_1.assert)(
|
|
63
|
+
(0, internal_1.assert)(
|
|
64
|
+
// Non null asserting here because of the length check above
|
|
65
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
66
|
+
this.lastOps[0].sequenceNumber === readFrom + 1, 0x091 /* "Retrieved ops' first sequence number has unexpected value!" */);
|
|
62
67
|
return this.lastOps;
|
|
63
68
|
}
|
|
64
69
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileDeltaStorageService.js","sourceRoot":"","sources":["../src/fileDeltaStorageService.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAEH,4CAAoB;AAEpB,kEAA6D;AAM7D,oEAA2E;AAE3E;;;GAGG;AACH,MAAa,uBAAuB;IAInC,YAA6B,IAAY;QAAZ,S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ensed under the MIT License.\n */\n\nimport fs from \"fs\";\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport {\n\tIDocumentDeltaStorageService,\n\tIStream,\n\tISequencedDocumentMessage,\n} from \"@fluidframework/driver-definitions/internal\";\nimport { emptyMessageStream } from \"@fluidframework/driver-utils/internal\";\n\n/**\n * Provides access to the underlying delta storage on the local file storage for file driver.\n * @internal\n */\nexport class FileDeltaStorageService implements IDocumentDeltaStorageService {\n\tprivate readonly messages: ISequencedDocumentMessage[];\n\tprivate lastOps: ISequencedDocumentMessage[] = [];\n\n\tconstructor(private readonly path: string) {\n\t\tthis.messages = [];\n\t\tlet counter = 0;\n\t\t// eslint-disable-next-line no-constant-condition\n\t\twhile (true) {\n\t\t\tconst filename = `${this.path}//messages${counter === 0 ? \"\" : counter}.json`;\n\t\t\tif (!fs.existsSync(filename)) {\n\t\t\t\tif (counter === 0) {\n\t\t\t\t\tthrow new Error(`file ${filename} not found`);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tconst data = fs.readFileSync(filename);\n\t\t\tthis.messages = this.messages.concat(JSON.parse(data.toString(\"utf-8\")));\n\t\t\tcounter++;\n\t\t}\n\t}\n\n\tpublic fetchMessages(\n\t\tfrom: number,\n\t\tto: number | undefined,\n\t\tabortSignal?: AbortSignal,\n\t\tcachedOnly?: boolean,\n\t): IStream<ISequencedDocumentMessage[]> {\n\t\treturn emptyMessageStream;\n\t}\n\n\tpublic get ops(): readonly Readonly<ISequencedDocumentMessage>[] {\n\t\treturn this.messages;\n\t}\n\n\t/**\n\t * Retrieve ops within the exclusive sequence number range.\n\t *\n\t * @param from - First op to be fetched.\n\t * @param to - Last op to be fetched. This is exclusive.\n\t */\n\tpublic getFromWebSocket(from: number, to: number): ISequencedDocumentMessage[] {\n\t\tconst readFrom = Math.max(from, 0); // Inclusive\n\t\tconst readTo = Math.min(to, this.messages.length); // Exclusive\n\n\t\tif (readFrom >= this.messages.length || readTo <= 0 || readFrom >= readTo) {\n\t\t\treturn [];\n\t\t}\n\n\t\t// Optimizations for multiple readers (replay tool)\n\t\t// Non null asserting here because of the length check\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tif (this.lastOps.length > 0 && this.lastOps[0]!.sequenceNumber === readFrom + 1) {\n\t\t\treturn this.lastOps;\n\t\t}\n\t\tthis.lastOps = this.messages.slice(readFrom, readTo);\n\t\tassert(\n\t\t\t// Non null asserting here because of the length check above\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tthis.lastOps[0]!.sequenceNumber === readFrom + 1,\n\t\t\t0x091 /* \"Retrieved ops' first sequence number has unexpected value!\" */,\n\t\t);\n\t\treturn this.lastOps;\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileDocumentStorageService.d.ts","sourceRoot":"","sources":["../src/fileDocumentStorageService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAClE,OAAO,EACN,uBAAuB,EACvB,eAAe,EACf,aAAa,EACb,QAAQ,EACR,KAAK,EAIL,MAAM,6CAA6C,CAAC;AAKrD,OAAO,EACN,aAAa,EACb,8BAA8B,EAC9B,MAAM,wCAAwC,CAAC;AAIhD;;GAEG;AACH,eAAO,MAAM,uBAAuB,qBAAqB,CAAC;AAK1D;;;GAGG;AACH,qBAAa,gBACZ,SAAQ,8BACR,YAAW,uBAAuB;IAKjC,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC;IAJ9B,SAAS,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI,CAAQ;gBAG7B,IAAI,EAAE,MAAM,EACZ,WAAW,CAAC,oBAAQ;IAKtC;;;OAGG;IAEU,eAAe,CAAC,OAAO,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC;IAkC/E;;;;OAI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I5B,MAAM,GAAG,QAAQ,eAAe,CAAC;+BASxB,MAAM,GAAG,IAAI,SAAS,MAAM,GAAG,QAAQ,QAAQ,EAAE,CAAC;kCAkB/C,QAAQ,GAAG,QAAQ,aAAa,GAAG,IAAI,CAAC;0CAQrE,YAAY,WACZ,eAAe,GACtB,QAAQ,MAAM,CAAC;gCAcmB,aAAa,GAAG,QAAQ,KAAK,CAAC;;;;;;;;2BAoDpB,CAAC"}
|
|
@@ -163,6 +163,8 @@ const FileSnapshotWriterClassFactory = (Base) => class extends Base {
|
|
|
163
163
|
async buildTree(snapshotTree) {
|
|
164
164
|
const tree = { entries: [] };
|
|
165
165
|
for (const subTreeId of Object.keys(snapshotTree.trees)) {
|
|
166
|
+
// Non null asserting here, we should use Object.entries() instead
|
|
167
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
166
168
|
const subTree = await this.buildTree(snapshotTree.trees[subTreeId]);
|
|
167
169
|
tree.entries.push({
|
|
168
170
|
mode: internal_2.FileMode.Directory,
|
|
@@ -172,6 +174,8 @@ const FileSnapshotWriterClassFactory = (Base) => class extends Base {
|
|
|
172
174
|
});
|
|
173
175
|
}
|
|
174
176
|
for (const blobName of Object.keys(snapshotTree.blobs)) {
|
|
177
|
+
// Non null asserting here, we should use Object.entries() instead
|
|
178
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
175
179
|
const buffer = await this.readBlob(snapshotTree.blobs[blobName]);
|
|
176
180
|
const contents = (0, client_utils_1.bufferToString)(buffer, "utf8");
|
|
177
181
|
const blob = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileDocumentStorageService.js","sourceRoot":"","sources":["../src/fileDocumentStorageService.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAEH,4CAAoB;AAEpB,+DAA8D;AAC9D,kEAA6D;AAE7D,0EASqD;AACrD,oEAG+C;AAC/C,qEAGgD;AAEhD,iDAAiD;AACjD,gFAAgF;AAChF;;GA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AAC,EAAE,KAAK,SAAS,IAAI,IAAI,CAAC,EAAE,KAAK,IAAI,EACzC,KAAK,CAAC,+DAA+D,CACrE,CAAC;IACF,OAAO,IAAI,CAAC,EAAE,CAAC;AAChB,CAAC;AACD;;GAEG;AACU,QAAA,kCAAkC,GAC9C,IAAA,sCAA8B,EAAC,gBAAgB,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport fs from \"fs\";\n\nimport { bufferToString } from \"@fluid-internal/client-utils\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { ISummaryTree } from \"@fluidframework/driver-definitions\";\nimport {\n\tIDocumentStorageService,\n\tISummaryContext,\n\tISnapshotTree,\n\tIVersion,\n\tITree,\n\tFileMode,\n\tTreeEntry,\n\tIBlob,\n} from \"@fluidframework/driver-definitions/internal\";\nimport {\n\tbuildSnapshotTree,\n\tconvertSummaryTreeToSnapshotITree,\n} from \"@fluidframework/driver-utils/internal\";\nimport {\n\tIFileSnapshot,\n\tReadDocumentStorageServiceBase,\n} from \"@fluidframework/replay-driver/internal\";\n\n// This ID is used by replay tool as Document Id.\n// We leverage it to figure out when container is asking for root document tree.\n/**\n * @internal\n */\nexport const FileStorageDocumentName = \"FileStorageDocId\"; // Some unique document name\n\n// Tree ID use to communicate between getVersions() & getSnapshotTree() that IVersion is ours.\nconst FileStorageVersionTreeId = \"FileStorageTreeId\";\n\n/**\n * Document storage service for the file driver.\n * @internal\n */\nexport class FluidFetchReader\n\textends ReadDocumentStorageServiceBase\n\timplements IDocumentStorageService\n{\n\tprotected docTree: ISnapshotTree | null = null;\n\n\tconstructor(\n\t\tprivate readonly path: string,\n\t\tprivate readonly versionName?: string,\n\t) {\n\t\tsuper();\n\t}\n\n\t/**\n\t * Read the file and returns the snapshot tree.\n\t * @param version - The version contains the path of the file which contains the snapshot tree.\n\t */\n\t// eslint-disable-next-line @rushstack/no-new-null\n\tpublic async getSnapshotTree(version?: IVersion): Promise<ISnapshotTree | null> {\n\t\tassert(version !== null, 0x092 /* \"version input for reading snapshot tree is null!\" */);\n\t\tassert(\n\t\t\t!version || version.treeId === FileStorageVersionTreeId,\n\t\t\t0x093 /* \"invalid version input for reading snapshot tree!\" */,\n\t\t);\n\n\t\tlet filename: string;\n\t\tlet rootTree = false;\n\t\tif (!version || version.id === \"latest\") {\n\t\t\tif (this.docTree) {\n\t\t\t\treturn this.docTree;\n\t\t\t}\n\t\t\tif (this.versionName === undefined) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\trootTree = true;\n\t\t\tfilename = `${this.path}/${this.versionName}/tree.json`;\n\t\t} else {\n\t\t\tfilename = `${this.path}/${this.versionName}/${version.id}.json`;\n\t\t}\n\n\t\tif (!fs.existsSync(filename)) {\n\t\t\tthrow new Error(`Can't find file ${filename}`);\n\t\t}\n\t\tconst data = fs.readFileSync(filename);\n\t\tconst tree = JSON.parse(data.toString(\"utf-8\"));\n\t\tif (rootTree) {\n\t\t\tthis.docTree = tree;\n\t\t}\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\treturn tree;\n\t}\n\n\t/**\n\t * Gets the path of the snapshot tree to be read.\n\t * @param versionId - version ID.\n\t * @param count - Number of versions to be returned.\n\t */\n\t// eslint-disable-next-line @rushstack/no-new-null\n\tpublic async getVersions(versionId: string | null, count: number): Promise<IVersion[]> {\n\t\tif (versionId === FileStorageDocumentName || versionId === null) {\n\t\t\tif (this.docTree !== null || this.versionName !== undefined) {\n\t\t\t\treturn [{ id: \"latest\", treeId: FileStorageVersionTreeId }];\n\t\t\t}\n\t\t\t// Started with ops - return empty set.\n\t\t\treturn [];\n\t\t} else if (this.versionName !== undefined) {\n\t\t\tassert(!!this.docTree, 0x094 /* \"Missing snapshot tree!\" */);\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tid: versionId,\n\t\t\t\t\ttreeId: FileStorageVersionTreeId,\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\t\tthrow new Error(`Unknown version: ${versionId}`);\n\t}\n\n\tpublic async readBlob(sha: string): Promise<ArrayBufferLike> {\n\t\tif (this.versionName !== undefined) {\n\t\t\tconst fileName = `${this.path}/${this.versionName}/${sha}`;\n\t\t\tif (fs.existsSync(fileName)) {\n\t\t\t\tconst data = fs.readFileSync(fileName);\n\t\t\t\treturn data;\n\t\t\t}\n\t\t}\n\t\tthrow new Error(`Can't find blob ${sha}`);\n\t}\n}\n\n/**\n * @internal\n */\nexport interface ISnapshotWriterStorage extends IDocumentStorageService {\n\tonSnapshotHandler(snapshot: IFileSnapshot): void;\n\treset(): void;\n}\n\n/**\n * @internal\n */\nexport type ReaderConstructor = new (...args: any[]) => IDocumentStorageService;\n/**\n * @internal\n */\nexport const FileSnapshotWriterClassFactory = <TBase extends ReaderConstructor>(Base: TBase) =>\n\tclass extends Base implements ISnapshotWriterStorage {\n\t\t// Note: if variable name has same name as in base class, it overrides it!\n\t\tpublic blobsWriter = new Map<string, ArrayBufferLike>();\n\t\tpublic latestWriterTree?: ISnapshotTree;\n\t\tpublic docId?: string;\n\n\t\tpublic reset() {\n\t\t\tthis.blobsWriter = new Map<string, ArrayBufferLike>();\n\t\t\tthis.latestWriterTree = undefined;\n\t\t\tthis.docId = undefined;\n\t\t}\n\n\t\tpublic onSnapshotHandler(snapshot: IFileSnapshot): void {\n\t\t\tthrow new Error(\"onSnapshotHandler is not setup! Please provide your handler!\");\n\t\t}\n\n\t\tpublic async readBlob(sha: string): Promise<ArrayBufferLike> {\n\t\t\tconst blob = this.blobsWriter.get(sha);\n\t\t\tif (blob !== undefined) {\n\t\t\t\treturn blob;\n\t\t\t}\n\t\t\treturn super.readBlob(sha);\n\t\t}\n\n\t\t// eslint-disable-next-line @rushstack/no-new-null\n\t\tpublic async getVersions(versionId: string | null, count: number): Promise<IVersion[]> {\n\t\t\t// If we already saved document, that means we are getting here because of snapshot generation.\n\t\t\t// Not returning tree ensures that ContainerRuntime.snapshot() would regenerate subtrees for\n\t\t\t// each unchanged data store.\n\t\t\t// If we want to change that, we would need to capture docId on first call and return this.latestWriterTree\n\t\t\t// when latest is requested.\n\t\t\tif (this.latestWriterTree && (this.docId === versionId || versionId === null)) {\n\t\t\t\treturn [{ id: \"latest\", treeId: FileStorageVersionTreeId }];\n\t\t\t}\n\n\t\t\tif (this.docId === undefined && versionId !== null) {\n\t\t\t\tthis.docId = versionId;\n\t\t\t}\n\n\t\t\treturn super.getVersions(versionId, count);\n\t\t}\n\n\t\t// eslint-disable-next-line @rushstack/no-new-null\n\t\tpublic async getSnapshotTree(version?: IVersion): Promise<ISnapshotTree | null> {\n\t\t\tif (this.latestWriterTree && (!version || version.id === \"latest\")) {\n\t\t\t\treturn this.latestWriterTree;\n\t\t\t}\n\t\t\treturn super.getSnapshotTree(version);\n\t\t}\n\n\t\tpublic async uploadSummaryWithContext(\n\t\t\tsummary: ISummaryTree,\n\t\t\tcontext: ISummaryContext,\n\t\t): Promise<string> {\n\t\t\tconst tree = convertSummaryTreeToSnapshotITree(summary);\n\n\t\t\t// Remove tree IDs for easier comparison of snapshots\n\t\t\tdelete tree.id;\n\t\t\tremoveNullTreeIds(tree);\n\n\t\t\tthis.latestWriterTree = buildSnapshotTree(tree.entries, this.blobsWriter);\n\n\t\t\tconst fileSnapshot: IFileSnapshot = { tree, commits: {} };\n\t\t\tthis.onSnapshotHandler(fileSnapshot);\n\t\t\treturn \"testHandleId\";\n\t\t}\n\n\t\tpublic async buildTree(snapshotTree: ISnapshotTree): Promise<ITree> {\n\t\t\tconst tree: ITree = { entries: [] };\n\n\t\t\tfor (const subTreeId of Object.keys(snapshotTree.trees)) {\n\t\t\t\tconst subTree = await this.buildTree(snapshotTree.trees[subTreeId]);\n\t\t\t\ttree.entries.push({\n\t\t\t\t\tmode: FileMode.Directory,\n\t\t\t\t\tpath: subTreeId,\n\t\t\t\t\ttype: TreeEntry.Tree,\n\t\t\t\t\tvalue: subTree,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tfor (const blobName of Object.keys(snapshotTree.blobs)) {\n\t\t\t\tconst buffer = await this.readBlob(snapshotTree.blobs[blobName]);\n\t\t\t\tconst contents = bufferToString(buffer, \"utf8\");\n\t\t\t\tconst blob: IBlob = {\n\t\t\t\t\tcontents,\n\t\t\t\t\tencoding: \"utf-8\",\n\t\t\t\t};\n\t\t\t\ttree.entries.push({\n\t\t\t\t\tmode: FileMode.File,\n\t\t\t\t\tpath: blobName,\n\t\t\t\t\ttype: TreeEntry.Blob,\n\t\t\t\t\tvalue: blob,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn tree;\n\t\t}\n\t};\n\nfunction removeNullTreeIds(tree: ITree) {\n\tfor (const node of tree.entries) {\n\t\tif (node.type === TreeEntry.Tree) {\n\t\t\tremoveNullTreeIds(node.value);\n\t\t}\n\t}\n\tassert(\n\t\ttree.id === undefined || tree.id === null,\n\t\t0x096 /* \"Trying to remove valid tree IDs in removeNullTreeIds()!\" */,\n\t);\n\tdelete tree.id;\n}\n/**\n * @internal\n */\nexport const FluidFetchReaderFileSnapshotWriter =\n\tFileSnapshotWriterClassFactory(FluidFetchReader);\n"]}
|
|
1
|
+
{"version":3,"file":"fileDocumentStorageService.js","sourceRoot":"","sources":["../src/fileDocumentStorageService.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAEH,4CAAoB;AAEpB,+DAA8D;AAC9D,kEAA6D;AAE7D,0EASqD;AACrD,oEAG+C;AAC/C,qEAGgD;AAEhD,iDAAiD;AACjD,gFAAgF;AAChF;;GAEG;AACU,QAAA,uBAAuB,GAAG,kBAAkB,CAAC,CAAC,4BAA4B;AAEvF,8FAA8F;AAC9F,MAAM,wBAAwB,GAAG,mBAAmB,CAAC;AAErD;;;GAGG;AACH,MAAa,gBACZ,SAAQ,yCAA8B;IAKtC,YACkB,IAAY,EACZ,WAAoB;QAErC,KAAK,EAAE,CAAC;QAHS,SAAI,GAAJ,IAAI,CAAQ;QACZ,gBAAW,GAAX,WAAW,CAAS;QAJ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ent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport fs from \"fs\";\n\nimport { bufferToString } from \"@fluid-internal/client-utils\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { ISummaryTree } from \"@fluidframework/driver-definitions\";\nimport {\n\tIDocumentStorageService,\n\tISummaryContext,\n\tISnapshotTree,\n\tIVersion,\n\tITree,\n\tFileMode,\n\tTreeEntry,\n\tIBlob,\n} from \"@fluidframework/driver-definitions/internal\";\nimport {\n\tbuildSnapshotTree,\n\tconvertSummaryTreeToSnapshotITree,\n} from \"@fluidframework/driver-utils/internal\";\nimport {\n\tIFileSnapshot,\n\tReadDocumentStorageServiceBase,\n} from \"@fluidframework/replay-driver/internal\";\n\n// This ID is used by replay tool as Document Id.\n// We leverage it to figure out when container is asking for root document tree.\n/**\n * @internal\n */\nexport const FileStorageDocumentName = \"FileStorageDocId\"; // Some unique document name\n\n// Tree ID use to communicate between getVersions() & getSnapshotTree() that IVersion is ours.\nconst FileStorageVersionTreeId = \"FileStorageTreeId\";\n\n/**\n * Document storage service for the file driver.\n * @internal\n */\nexport class FluidFetchReader\n\textends ReadDocumentStorageServiceBase\n\timplements IDocumentStorageService\n{\n\tprotected docTree: ISnapshotTree | null = null;\n\n\tconstructor(\n\t\tprivate readonly path: string,\n\t\tprivate readonly versionName?: string,\n\t) {\n\t\tsuper();\n\t}\n\n\t/**\n\t * Read the file and returns the snapshot tree.\n\t * @param version - The version contains the path of the file which contains the snapshot tree.\n\t */\n\t// eslint-disable-next-line @rushstack/no-new-null\n\tpublic async getSnapshotTree(version?: IVersion): Promise<ISnapshotTree | null> {\n\t\tassert(version !== null, 0x092 /* \"version input for reading snapshot tree is null!\" */);\n\t\tassert(\n\t\t\t!version || version.treeId === FileStorageVersionTreeId,\n\t\t\t0x093 /* \"invalid version input for reading snapshot tree!\" */,\n\t\t);\n\n\t\tlet filename: string;\n\t\tlet rootTree = false;\n\t\tif (!version || version.id === \"latest\") {\n\t\t\tif (this.docTree) {\n\t\t\t\treturn this.docTree;\n\t\t\t}\n\t\t\tif (this.versionName === undefined) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\trootTree = true;\n\t\t\tfilename = `${this.path}/${this.versionName}/tree.json`;\n\t\t} else {\n\t\t\tfilename = `${this.path}/${this.versionName}/${version.id}.json`;\n\t\t}\n\n\t\tif (!fs.existsSync(filename)) {\n\t\t\tthrow new Error(`Can't find file ${filename}`);\n\t\t}\n\t\tconst data = fs.readFileSync(filename);\n\t\tconst tree = JSON.parse(data.toString(\"utf-8\"));\n\t\tif (rootTree) {\n\t\t\tthis.docTree = tree;\n\t\t}\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\treturn tree;\n\t}\n\n\t/**\n\t * Gets the path of the snapshot tree to be read.\n\t * @param versionId - version ID.\n\t * @param count - Number of versions to be returned.\n\t */\n\t// eslint-disable-next-line @rushstack/no-new-null\n\tpublic async getVersions(versionId: string | null, count: number): Promise<IVersion[]> {\n\t\tif (versionId === FileStorageDocumentName || versionId === null) {\n\t\t\tif (this.docTree !== null || this.versionName !== undefined) {\n\t\t\t\treturn [{ id: \"latest\", treeId: FileStorageVersionTreeId }];\n\t\t\t}\n\t\t\t// Started with ops - return empty set.\n\t\t\treturn [];\n\t\t} else if (this.versionName !== undefined) {\n\t\t\tassert(!!this.docTree, 0x094 /* \"Missing snapshot tree!\" */);\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tid: versionId,\n\t\t\t\t\ttreeId: FileStorageVersionTreeId,\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\t\tthrow new Error(`Unknown version: ${versionId}`);\n\t}\n\n\tpublic async readBlob(sha: string): Promise<ArrayBufferLike> {\n\t\tif (this.versionName !== undefined) {\n\t\t\tconst fileName = `${this.path}/${this.versionName}/${sha}`;\n\t\t\tif (fs.existsSync(fileName)) {\n\t\t\t\tconst data = fs.readFileSync(fileName);\n\t\t\t\treturn data;\n\t\t\t}\n\t\t}\n\t\tthrow new Error(`Can't find blob ${sha}`);\n\t}\n}\n\n/**\n * @internal\n */\nexport interface ISnapshotWriterStorage extends IDocumentStorageService {\n\tonSnapshotHandler(snapshot: IFileSnapshot): void;\n\treset(): void;\n}\n\n/**\n * @internal\n */\nexport type ReaderConstructor = new (...args: any[]) => IDocumentStorageService;\n/**\n * @internal\n */\nexport const FileSnapshotWriterClassFactory = <TBase extends ReaderConstructor>(Base: TBase) =>\n\tclass extends Base implements ISnapshotWriterStorage {\n\t\t// Note: if variable name has same name as in base class, it overrides it!\n\t\tpublic blobsWriter = new Map<string, ArrayBufferLike>();\n\t\tpublic latestWriterTree?: ISnapshotTree;\n\t\tpublic docId?: string;\n\n\t\tpublic reset() {\n\t\t\tthis.blobsWriter = new Map<string, ArrayBufferLike>();\n\t\t\tthis.latestWriterTree = undefined;\n\t\t\tthis.docId = undefined;\n\t\t}\n\n\t\tpublic onSnapshotHandler(snapshot: IFileSnapshot): void {\n\t\t\tthrow new Error(\"onSnapshotHandler is not setup! Please provide your handler!\");\n\t\t}\n\n\t\tpublic async readBlob(sha: string): Promise<ArrayBufferLike> {\n\t\t\tconst blob = this.blobsWriter.get(sha);\n\t\t\tif (blob !== undefined) {\n\t\t\t\treturn blob;\n\t\t\t}\n\t\t\treturn super.readBlob(sha);\n\t\t}\n\n\t\t// eslint-disable-next-line @rushstack/no-new-null\n\t\tpublic async getVersions(versionId: string | null, count: number): Promise<IVersion[]> {\n\t\t\t// If we already saved document, that means we are getting here because of snapshot generation.\n\t\t\t// Not returning tree ensures that ContainerRuntime.snapshot() would regenerate subtrees for\n\t\t\t// each unchanged data store.\n\t\t\t// If we want to change that, we would need to capture docId on first call and return this.latestWriterTree\n\t\t\t// when latest is requested.\n\t\t\tif (this.latestWriterTree && (this.docId === versionId || versionId === null)) {\n\t\t\t\treturn [{ id: \"latest\", treeId: FileStorageVersionTreeId }];\n\t\t\t}\n\n\t\t\tif (this.docId === undefined && versionId !== null) {\n\t\t\t\tthis.docId = versionId;\n\t\t\t}\n\n\t\t\treturn super.getVersions(versionId, count);\n\t\t}\n\n\t\t// eslint-disable-next-line @rushstack/no-new-null\n\t\tpublic async getSnapshotTree(version?: IVersion): Promise<ISnapshotTree | null> {\n\t\t\tif (this.latestWriterTree && (!version || version.id === \"latest\")) {\n\t\t\t\treturn this.latestWriterTree;\n\t\t\t}\n\t\t\treturn super.getSnapshotTree(version);\n\t\t}\n\n\t\tpublic async uploadSummaryWithContext(\n\t\t\tsummary: ISummaryTree,\n\t\t\tcontext: ISummaryContext,\n\t\t): Promise<string> {\n\t\t\tconst tree = convertSummaryTreeToSnapshotITree(summary);\n\n\t\t\t// Remove tree IDs for easier comparison of snapshots\n\t\t\tdelete tree.id;\n\t\t\tremoveNullTreeIds(tree);\n\n\t\t\tthis.latestWriterTree = buildSnapshotTree(tree.entries, this.blobsWriter);\n\n\t\t\tconst fileSnapshot: IFileSnapshot = { tree, commits: {} };\n\t\t\tthis.onSnapshotHandler(fileSnapshot);\n\t\t\treturn \"testHandleId\";\n\t\t}\n\n\t\tpublic async buildTree(snapshotTree: ISnapshotTree): Promise<ITree> {\n\t\t\tconst tree: ITree = { entries: [] };\n\n\t\t\tfor (const subTreeId of Object.keys(snapshotTree.trees)) {\n\t\t\t\t// Non null asserting here, we should use Object.entries() instead\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tconst subTree = await this.buildTree(snapshotTree.trees[subTreeId]!);\n\t\t\t\ttree.entries.push({\n\t\t\t\t\tmode: FileMode.Directory,\n\t\t\t\t\tpath: subTreeId,\n\t\t\t\t\ttype: TreeEntry.Tree,\n\t\t\t\t\tvalue: subTree,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tfor (const blobName of Object.keys(snapshotTree.blobs)) {\n\t\t\t\t// Non null asserting here, we should use Object.entries() instead\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tconst buffer = await this.readBlob(snapshotTree.blobs[blobName]!);\n\t\t\t\tconst contents = bufferToString(buffer, \"utf8\");\n\t\t\t\tconst blob: IBlob = {\n\t\t\t\t\tcontents,\n\t\t\t\t\tencoding: \"utf-8\",\n\t\t\t\t};\n\t\t\t\ttree.entries.push({\n\t\t\t\t\tmode: FileMode.File,\n\t\t\t\t\tpath: blobName,\n\t\t\t\t\ttype: TreeEntry.Blob,\n\t\t\t\t\tvalue: blob,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn tree;\n\t\t}\n\t};\n\nfunction removeNullTreeIds(tree: ITree) {\n\tfor (const node of tree.entries) {\n\t\tif (node.type === TreeEntry.Tree) {\n\t\t\tremoveNullTreeIds(node.value);\n\t\t}\n\t}\n\tassert(\n\t\ttree.id === undefined || tree.id === null,\n\t\t0x096 /* \"Trying to remove valid tree IDs in removeNullTreeIds()!\" */,\n\t);\n\tdelete tree.id;\n}\n/**\n * @internal\n */\nexport const FluidFetchReaderFileSnapshotWriter =\n\tFileSnapshotWriterClassFactory(FluidFetchReader);\n"]}
|
package/dist/public.d.ts
CHANGED
package/internal.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileDeltaStorageService.d.ts","sourceRoot":"","sources":["../src/fileDeltaStorageService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EACN,4BAA4B,EAC5B,OAAO,EACP,yBAAyB,EACzB,MAAM,6CAA6C,CAAC;AAGrD;;;GAGG;AACH,qBAAa,uBAAwB,YAAW,4BAA4B;IAI/D,OAAO,CAAC,QAAQ,CAAC,IAAI;IAHjC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA8B;IACvD,OAAO,CAAC,OAAO,CAAmC;gBAErB,IAAI,EAAE,MAAM;IAkBlC,aAAa,CACnB,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,GAAG,SAAS,EACtB,WAAW,CAAC,EAAE,WAAW,EACzB,UAAU,CAAC,EAAE,OAAO,GAClB,OAAO,CAAC,yBAAyB,EAAE,CAAC;IAIvC,IAAW,GAAG,IAAI,SAAS,QAAQ,CAAC,yBAAyB,CAAC,EAAE,CAE/D;IAED;;;;;OAKG;IACI,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,yBAAyB,EAAE;
|
|
1
|
+
{"version":3,"file":"fileDeltaStorageService.d.ts","sourceRoot":"","sources":["../src/fileDeltaStorageService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EACN,4BAA4B,EAC5B,OAAO,EACP,yBAAyB,EACzB,MAAM,6CAA6C,CAAC;AAGrD;;;GAGG;AACH,qBAAa,uBAAwB,YAAW,4BAA4B;IAI/D,OAAO,CAAC,QAAQ,CAAC,IAAI;IAHjC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA8B;IACvD,OAAO,CAAC,OAAO,CAAmC;gBAErB,IAAI,EAAE,MAAM;IAkBlC,aAAa,CACnB,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,GAAG,SAAS,EACtB,WAAW,CAAC,EAAE,WAAW,EACzB,UAAU,CAAC,EAAE,OAAO,GAClB,OAAO,CAAC,yBAAyB,EAAE,CAAC;IAIvC,IAAW,GAAG,IAAI,SAAS,QAAQ,CAAC,yBAAyB,CAAC,EAAE,CAE/D;IAED;;;;;OAKG;IACI,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,yBAAyB,EAAE;CAuB9E"}
|
|
@@ -48,11 +48,16 @@ export class FileDeltaStorageService {
|
|
|
48
48
|
return [];
|
|
49
49
|
}
|
|
50
50
|
// Optimizations for multiple readers (replay tool)
|
|
51
|
+
// Non null asserting here because of the length check
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
51
53
|
if (this.lastOps.length > 0 && this.lastOps[0].sequenceNumber === readFrom + 1) {
|
|
52
54
|
return this.lastOps;
|
|
53
55
|
}
|
|
54
56
|
this.lastOps = this.messages.slice(readFrom, readTo);
|
|
55
|
-
assert(
|
|
57
|
+
assert(
|
|
58
|
+
// Non null asserting here because of the length check above
|
|
59
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
60
|
+
this.lastOps[0].sequenceNumber === readFrom + 1, 0x091 /* "Retrieved ops' first sequence number has unexpected value!" */);
|
|
56
61
|
return this.lastOps;
|
|
57
62
|
}
|
|
58
63
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileDeltaStorageService.js","sourceRoot":"","sources":["../src/fileDeltaStorageService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAM7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAE3E;;;GAGG;AACH,MAAM,OAAO,uBAAuB;IAInC,YAA6B,IAAY;QAAZ,SAAI,GAAJ,IAAI,CAAQ;QAFjC,YAAO,GAAgC,EAAE,CAAC;QAGjD,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;QACnB,IAAI,OAAO,GAAG,CAAC,CAAC;QAChB,iDAAiD;QACjD,OAAO,IAAI,EAAE,CAAC;YACb,MAAM,QAAQ,GAAG,GAAG,IAAI,CAAC,IAAI,aAAa,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,OAAO,CAAC;YAC9E,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;gBAC9B,IAAI,OAAO,KAAK,CAAC,EAAE,CAAC;oBACnB,MAAM,IAAI,KAAK,CAAC,QAAQ,QAAQ,YAAY,CAAC,CAAC;gBAC/C,CAAC;gBACD,MAAM;YACP,CAAC;YACD,MAAM,IAAI,GAAG,EAAE,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;YACvC,IAAI,CAAC,QAAQ,GAAG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,CAAC,IAAI,QAAQ,IAAI,MAAM,EAAE,CAAC;YAC3E,OAAO,EAAE,CAAC;QACX,CAAC;QAED,mDAAmD;QACnD,sDAAsD;QACtD,oEAAoE;QACpE,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC,CAAE,CAAC,cAAc,KAAK,QAAQ,GAAG,CAAC,EAAE,CAAC;YACjF,OAAO,IAAI,CAAC,OAAO,CAAC;QACrB,CAAC;QACD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QACrD,MAAM;QACL,4DAA4D;QAC5D,oEAAoE;QACpE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAE,CAAC,cAAc,KAAK,QAAQ,GAAG,CAAC,EAChD,KAAK,CAAC,kEAAkE,CACxE,CAAC;QACF,OAAO,IAAI,CAAC,OAAO,CAAC;IACrB,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport fs from \"fs\";\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport {\n\tIDocumentDeltaStorageService,\n\tIStream,\n\tISequencedDocumentMessage,\n} from \"@fluidframework/driver-definitions/internal\";\nimport { emptyMessageStream } from \"@fluidframework/driver-utils/internal\";\n\n/**\n * Provides access to the underlying delta storage on the local file storage for file driver.\n * @internal\n */\nexport class FileDeltaStorageService implements IDocumentDeltaStorageService {\n\tprivate readonly messages: ISequencedDocumentMessage[];\n\tprivate lastOps: ISequencedDocumentMessage[] = [];\n\n\tconstructor(private readonly path: string) {\n\t\tthis.messages = [];\n\t\tlet counter = 0;\n\t\t// eslint-disable-next-line no-constant-condition\n\t\twhile (true) {\n\t\t\tconst filename = `${this.path}//messages${counter === 0 ? \"\" : counter}.json`;\n\t\t\tif (!fs.existsSync(filename)) {\n\t\t\t\tif (counter === 0) {\n\t\t\t\t\tthrow new Error(`file ${filename} not found`);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tconst data = fs.readFileSync(filename);\n\t\t\tthis.messages = this.messages.concat(JSON.parse(data.toString(\"utf-8\")));\n\t\t\tcounter++;\n\t\t}\n\t}\n\n\tpublic fetchMessages(\n\t\tfrom: number,\n\t\tto: number | undefined,\n\t\tabortSignal?: AbortSignal,\n\t\tcachedOnly?: boolean,\n\t): IStream<ISequencedDocumentMessage[]> {\n\t\treturn emptyMessageStream;\n\t}\n\n\tpublic get ops(): readonly Readonly<ISequencedDocumentMessage>[] {\n\t\treturn this.messages;\n\t}\n\n\t/**\n\t * Retrieve ops within the exclusive sequence number range.\n\t *\n\t * @param from - First op to be fetched.\n\t * @param to - Last op to be fetched. This is exclusive.\n\t */\n\tpublic getFromWebSocket(from: number, to: number): ISequencedDocumentMessage[] {\n\t\tconst readFrom = Math.max(from, 0); // Inclusive\n\t\tconst readTo = Math.min(to, this.messages.length); // Exclusive\n\n\t\tif (readFrom >= this.messages.length || readTo <= 0 || readFrom >= readTo) {\n\t\t\treturn [];\n\t\t}\n\n\t\t// Optimizations for multiple readers (replay tool)\n\t\t// Non null asserting here because of the length check\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tif (this.lastOps.length > 0 && this.lastOps[0]!.sequenceNumber === readFrom + 1) {\n\t\t\treturn this.lastOps;\n\t\t}\n\t\tthis.lastOps = this.messages.slice(readFrom, readTo);\n\t\tassert(\n\t\t\t// Non null asserting here because of the length check above\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tthis.lastOps[0]!.sequenceNumber === readFrom + 1,\n\t\t\t0x091 /* \"Retrieved ops' first sequence number has unexpected value!\" */,\n\t\t);\n\t\treturn this.lastOps;\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileDocumentStorageService.d.ts","sourceRoot":"","sources":["../src/fileD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,uBAAuB;IACtE,iBAAiB,CAAC,QAAQ,EAAE,aAAa,GAAG,IAAI,CAAC;IACjD,KAAK,IAAI,IAAI,CAAC;CACd;AAED;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,uBAAuB,CAAC;AAChF;;GAEG;AACH,eAAO,MAAM,8BAA8B,0CAA2C,KAAK;kBAJ7C,GAAG,EAAE;;;;;oCAiBd,aAAa,GAAG,IAAI;sBAI5B,MAAM,GAAG,QAAQ,eAAe,CAAC;+BASxB,MAAM,GAAG,IAAI,SAAS,MAAM,GAAG,QAAQ,QAAQ,EAAE,CAAC;kCAkB/C,QAAQ,GAAG,QAAQ,aAAa,GAAG,IAAI,CAAC;0CAQrE,YAAY,WACZ,eAAe,GACtB,QAAQ,MAAM,CAAC;gCAcmB,aAAa,GAAG,QAAQ,KAAK,CAAC;;;;;;;;SAkCnE,CAAC;AAcH;;GAEG;AACH,eAAO,MAAM,kCAAkC;kBA3HD,GAAG,EAAE;;;;;oCAiBd,aAAa,GAAG,IAAI;sBAI5B,MAAM,GAAG,QAAQ,eAAe,CAAC;+BASxB,MAAM,GAAG,IAAI,SAAS,MAAM,GAAG,QAAQ,QAAQ,EAAE,CAAC;kCAkB/C,QAAQ,GAAG,QAAQ,aAAa,GAAG,IAAI,CAAC;0CAQrE,YAAY,WACZ,eAAe,GACtB,QAAQ,MAAM,CAAC;gCAcmB,aAAa,GAAG,QAAQ,KAAK,CAAC;;;;;;;;2BAoDpB,CAAC"}
|
|
@@ -156,6 +156,8 @@ export const FileSnapshotWriterClassFactory = (Base) => class extends Base {
|
|
|
156
156
|
async buildTree(snapshotTree) {
|
|
157
157
|
const tree = { entries: [] };
|
|
158
158
|
for (const subTreeId of Object.keys(snapshotTree.trees)) {
|
|
159
|
+
// Non null asserting here, we should use Object.entries() instead
|
|
160
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
159
161
|
const subTree = await this.buildTree(snapshotTree.trees[subTreeId]);
|
|
160
162
|
tree.entries.push({
|
|
161
163
|
mode: FileMode.Directory,
|
|
@@ -165,6 +167,8 @@ export const FileSnapshotWriterClassFactory = (Base) => class extends Base {
|
|
|
165
167
|
});
|
|
166
168
|
}
|
|
167
169
|
for (const blobName of Object.keys(snapshotTree.blobs)) {
|
|
170
|
+
// Non null asserting here, we should use Object.entries() instead
|
|
171
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
168
172
|
const buffer = await this.readBlob(snapshotTree.blobs[blobName]);
|
|
169
173
|
const contents = bufferToString(buffer, "utf8");
|
|
170
174
|
const blob = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileDocumentStorageService.js","sourceRoot":"","sources":["../src/fileDocumentStorageService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAE7D,OAAO,EAMN,QAAQ,EACR,SAAS,GAET,MAAM,6CAA6C,CAAC;AACrD,OAAO,EACN,iBAAiB,EACjB,iCAAiC,GACjC,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAEN,8BAA8B,GAC9B,MAAM,wCAAwC,CAAC;AAEhD,iDAAiD;AACjD,gFAAgF;AAChF;;GAEG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,kBAAkB,CAAC,CAAC,4BAA4B;AAEvF,8FAA8F;AAC9F,MAAM,wBAAwB,GAAG,mBAAmB,CAAC;AAErD;;;GAGG;AACH,MAAM,OAAO,gBACZ,SAAQ,8BAA8B;IAKtC,YACkB,IAAY,EACZ,WAAoB;QAErC,KAAK,EAAE,CAAC;QAHS,SAAI,GAAJ,IAAI,CAAQ;QACZ,gBAAW,GAAX,WAAW,CAAS;QAJ5B,YAAO,GAAyB,IAAI,CAAC;IAO/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M,QAAQ,IAAI,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC;YACxD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;YACjE,MAAM,QAAQ,GAAG,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;YAChD,MAAM,IAAI,GAAU;gBACnB,QAAQ;gBACR,QAAQ,EAAE,OAAO;aACjB,CAAC;YACF,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;gBACjB,IAAI,EAAE,QAAQ,CAAC,IAAI;gBACnB,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,SAAS,CAAC,IAAI;gBACpB,KAAK,EAAE,IAAI;aACX,CAAC,CAAC;QACJ,CAAC;QAED,OAAO,IAAI,CAAC;IACb,CAAC;CACD,CAAC;AAEH,SAAS,iBAAiB,CAAC,IAAW;IACrC,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;QACjC,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,IAAI,EAAE,CAAC;YAClC,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC/B,CAAC;IACF,CAAC;IACD,MAAM,CACL,IAAI,CAAC,EAAE,KAAK,SAAS,IAAI,IAAI,CAAC,EAAE,KAAK,IAAI,EACzC,KAAK,CAAC,+DAA+D,CACrE,CAAC;IACF,OAAO,IAAI,CAAC,EAAE,CAAC;AAChB,CAAC;AACD;;GAEG;AACH,MAAM,CAAC,MAAM,kCAAkC,GAC9C,8BAA8B,CAAC,gBAAgB,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport fs from \"fs\";\n\nimport { bufferToString } from \"@fluid-internal/client-utils\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { ISummaryTree } from \"@fluidframework/driver-definitions\";\nimport {\n\tIDocumentStorageService,\n\tISummaryContext,\n\tISnapshotTree,\n\tIVersion,\n\tITree,\n\tFileMode,\n\tTreeEntry,\n\tIBlob,\n} from \"@fluidframework/driver-definitions/internal\";\nimport {\n\tbuildSnapshotTree,\n\tconvertSummaryTreeToSnapshotITree,\n} from \"@fluidframework/driver-utils/internal\";\nimport {\n\tIFileSnapshot,\n\tReadDocumentStorageServiceBase,\n} from \"@fluidframework/replay-driver/internal\";\n\n// This ID is used by replay tool as Document Id.\n// We leverage it to figure out when container is asking for root document tree.\n/**\n * @internal\n */\nexport const FileStorageDocumentName = \"FileStorageDocId\"; // Some unique document name\n\n// Tree ID use to communicate between getVersions() & getSnapshotTree() that IVersion is ours.\nconst FileStorageVersionTreeId = \"FileStorageTreeId\";\n\n/**\n * Document storage service for the file driver.\n * @internal\n */\nexport class FluidFetchReader\n\textends ReadDocumentStorageServiceBase\n\timplements IDocumentStorageService\n{\n\tprotected docTree: ISnapshotTree | null = null;\n\n\tconstructor(\n\t\tprivate readonly path: string,\n\t\tprivate readonly versionName?: string,\n\t) {\n\t\tsuper();\n\t}\n\n\t/**\n\t * Read the file and returns the snapshot tree.\n\t * @param version - The version contains the path of the file which contains the snapshot tree.\n\t */\n\t// eslint-disable-next-line @rushstack/no-new-null\n\tpublic async getSnapshotTree(version?: IVersion): Promise<ISnapshotTree | null> {\n\t\tassert(version !== null, 0x092 /* \"version input for reading snapshot tree is null!\" */);\n\t\tassert(\n\t\t\t!version || version.treeId === FileStorageVersionTreeId,\n\t\t\t0x093 /* \"invalid version input for reading snapshot tree!\" */,\n\t\t);\n\n\t\tlet filename: string;\n\t\tlet rootTree = false;\n\t\tif (!version || version.id === \"latest\") {\n\t\t\tif (this.docTree) {\n\t\t\t\treturn this.docTree;\n\t\t\t}\n\t\t\tif (this.versionName === undefined) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\trootTree = true;\n\t\t\tfilename = `${this.path}/${this.versionName}/tree.json`;\n\t\t} else {\n\t\t\tfilename = `${this.path}/${this.versionName}/${version.id}.json`;\n\t\t}\n\n\t\tif (!fs.existsSync(filename)) {\n\t\t\tthrow new Error(`Can't find file ${filename}`);\n\t\t}\n\t\tconst data = fs.readFileSync(filename);\n\t\tconst tree = JSON.parse(data.toString(\"utf-8\"));\n\t\tif (rootTree) {\n\t\t\tthis.docTree = tree;\n\t\t}\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\treturn tree;\n\t}\n\n\t/**\n\t * Gets the path of the snapshot tree to be read.\n\t * @param versionId - version ID.\n\t * @param count - Number of versions to be returned.\n\t */\n\t// eslint-disable-next-line @rushstack/no-new-null\n\tpublic async getVersions(versionId: string | null, count: number): Promise<IVersion[]> {\n\t\tif (versionId === FileStorageDocumentName || versionId === null) {\n\t\t\tif (this.docTree !== null || this.versionName !== undefined) {\n\t\t\t\treturn [{ id: \"latest\", treeId: FileStorageVersionTreeId }];\n\t\t\t}\n\t\t\t// Started with ops - return empty set.\n\t\t\treturn [];\n\t\t} else if (this.versionName !== undefined) {\n\t\t\tassert(!!this.docTree, 0x094 /* \"Missing snapshot tree!\" */);\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tid: versionId,\n\t\t\t\t\ttreeId: FileStorageVersionTreeId,\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\t\tthrow new Error(`Unknown version: ${versionId}`);\n\t}\n\n\tpublic async readBlob(sha: string): Promise<ArrayBufferLike> {\n\t\tif (this.versionName !== undefined) {\n\t\t\tconst fileName = `${this.path}/${this.versionName}/${sha}`;\n\t\t\tif (fs.existsSync(fileName)) {\n\t\t\t\tconst data = fs.readFileSync(fileName);\n\t\t\t\treturn data;\n\t\t\t}\n\t\t}\n\t\tthrow new Error(`Can't find blob ${sha}`);\n\t}\n}\n\n/**\n * @internal\n */\nexport interface ISnapshotWriterStorage extends IDocumentStorageService {\n\tonSnapshotHandler(snapshot: IFileSnapshot): void;\n\treset(): void;\n}\n\n/**\n * @internal\n */\nexport type ReaderConstructor = new (...args: any[]) => IDocumentStorageService;\n/**\n * @internal\n */\nexport const FileSnapshotWriterClassFactory = <TBase extends ReaderConstructor>(Base: TBase) =>\n\tclass extends Base implements ISnapshotWriterStorage {\n\t\t// Note: if variable name has same name as in base class, it overrides it!\n\t\tpublic blobsWriter = new Map<string, ArrayBufferLike>();\n\t\tpublic latestWriterTree?: ISnapshotTree;\n\t\tpublic docId?: string;\n\n\t\tpublic reset() {\n\t\t\tthis.blobsWriter = new Map<string, ArrayBufferLike>();\n\t\t\tthis.latestWriterTree = undefined;\n\t\t\tthis.docId = undefined;\n\t\t}\n\n\t\tpublic onSnapshotHandler(snapshot: IFileSnapshot): void {\n\t\t\tthrow new Error(\"onSnapshotHandler is not setup! Please provide your handler!\");\n\t\t}\n\n\t\tpublic async readBlob(sha: string): Promise<ArrayBufferLike> {\n\t\t\tconst blob = this.blobsWriter.get(sha);\n\t\t\tif (blob !== undefined) {\n\t\t\t\treturn blob;\n\t\t\t}\n\t\t\treturn super.readBlob(sha);\n\t\t}\n\n\t\t// eslint-disable-next-line @rushstack/no-new-null\n\t\tpublic async getVersions(versionId: string | null, count: number): Promise<IVersion[]> {\n\t\t\t// If we already saved document, that means we are getting here because of snapshot generation.\n\t\t\t// Not returning tree ensures that ContainerRuntime.snapshot() would regenerate subtrees for\n\t\t\t// each unchanged data store.\n\t\t\t// If we want to change that, we would need to capture docId on first call and return this.latestWriterTree\n\t\t\t// when latest is requested.\n\t\t\tif (this.latestWriterTree && (this.docId === versionId || versionId === null)) {\n\t\t\t\treturn [{ id: \"latest\", treeId: FileStorageVersionTreeId }];\n\t\t\t}\n\n\t\t\tif (this.docId === undefined && versionId !== null) {\n\t\t\t\tthis.docId = versionId;\n\t\t\t}\n\n\t\t\treturn super.getVersions(versionId, count);\n\t\t}\n\n\t\t// eslint-disable-next-line @rushstack/no-new-null\n\t\tpublic async getSnapshotTree(version?: IVersion): Promise<ISnapshotTree | null> {\n\t\t\tif (this.latestWriterTree && (!version || version.id === \"latest\")) {\n\t\t\t\treturn this.latestWriterTree;\n\t\t\t}\n\t\t\treturn super.getSnapshotTree(version);\n\t\t}\n\n\t\tpublic async uploadSummaryWithContext(\n\t\t\tsummary: ISummaryTree,\n\t\t\tcontext: ISummaryContext,\n\t\t): Promise<string> {\n\t\t\tconst tree = convertSummaryTreeToSnapshotITree(summary);\n\n\t\t\t// Remove tree IDs for easier comparison of snapshots\n\t\t\tdelete tree.id;\n\t\t\tremoveNullTreeIds(tree);\n\n\t\t\tthis.latestWriterTree = buildSnapshotTree(tree.entries, this.blobsWriter);\n\n\t\t\tconst fileSnapshot: IFileSnapshot = { tree, commits: {} };\n\t\t\tthis.onSnapshotHandler(fileSnapshot);\n\t\t\treturn \"testHandleId\";\n\t\t}\n\n\t\tpublic async buildTree(snapshotTree: ISnapshotTree): Promise<ITree> {\n\t\t\tconst tree: ITree = { entries: [] };\n\n\t\t\tfor (const subTreeId of Object.keys(snapshotTree.trees)) {\n\t\t\t\tconst subTree = await this.buildTree(snapshotTree.trees[subTreeId]);\n\t\t\t\ttree.entries.push({\n\t\t\t\t\tmode: FileMode.Directory,\n\t\t\t\t\tpath: subTreeId,\n\t\t\t\t\ttype: TreeEntry.Tree,\n\t\t\t\t\tvalue: subTree,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tfor (const blobName of Object.keys(snapshotTree.blobs)) {\n\t\t\t\tconst buffer = await this.readBlob(snapshotTree.blobs[blobName]);\n\t\t\t\tconst contents = bufferToString(buffer, \"utf8\");\n\t\t\t\tconst blob: IBlob = {\n\t\t\t\t\tcontents,\n\t\t\t\t\tencoding: \"utf-8\",\n\t\t\t\t};\n\t\t\t\ttree.entries.push({\n\t\t\t\t\tmode: FileMode.File,\n\t\t\t\t\tpath: blobName,\n\t\t\t\t\ttype: TreeEntry.Blob,\n\t\t\t\t\tvalue: blob,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn tree;\n\t\t}\n\t};\n\nfunction removeNullTreeIds(tree: ITree) {\n\tfor (const node of tree.entries) {\n\t\tif (node.type === TreeEntry.Tree) {\n\t\t\tremoveNullTreeIds(node.value);\n\t\t}\n\t}\n\tassert(\n\t\ttree.id === undefined || tree.id === null,\n\t\t0x096 /* \"Trying to remove valid tree IDs in removeNullTreeIds()!\" */,\n\t);\n\tdelete tree.id;\n}\n/**\n * @internal\n */\nexport const FluidFetchReaderFileSnapshotWriter =\n\tFileSnapshotWriterClassFactory(FluidFetchReader);\n"]}
|
|
1
|
+
{"version":3,"file":"fileDocumentStorageService.js","sourceRoot":"","sources":["../src/fileDocumentStorageService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAE7D,OAAO,EAMN,QAAQ,EACR,SAAS,GAET,MAAM,6CAA6C,CAAC;AACrD,OAAO,EACN,iBAAiB,EACjB,iCAAiC,GACjC,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAEN,8BAA8B,GAC9B,MAAM,wCAAwC,CAAC;AAEhD,iDAAiD;AACjD,gFAAgF;AAChF;;GAEG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,kBAAkB,CAAC,CAAC,4BAA4B;AAEvF,8FAA8F;AAC9F,MAAM,wBAAwB,GAAG,mBAAmB,CAAC;AAErD;;;GAGG;AACH,MAAM,OAAO,gBACZ,SAAQ,8BAA8B;IAKtC,YACkB,IAAY,EACZ,WAAoB;QAErC,KAAK,EAAE,CAAC;QAHS,SAAI,GAAJ,IAAI,CAAQ;QACZ,gBAAW,GAAX,WAAW,CAAS;QAJ5B,YAAO,GAAyB,IAAI,CAAC;IAO/C,CAAC;IAED;;;OAGG;IACH,kDAAkD;IAC3C,KAAK,CAAC,eAAe,CAAC,OAAkB;QAC9C,MAAM,CAAC,OAAO,KAAK,IAAI,EAAE,KAAK,CA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oEAAoE;YACpE,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,KAAK,CAAC,QAAQ,CAAE,CAAC,CAAC;YAClE,MAAM,QAAQ,GAAG,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;YAChD,MAAM,IAAI,GAAU;gBACnB,QAAQ;gBACR,QAAQ,EAAE,OAAO;aACjB,CAAC;YACF,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;gBACjB,IAAI,EAAE,QAAQ,CAAC,IAAI;gBACnB,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,SAAS,CAAC,IAAI;gBACpB,KAAK,EAAE,IAAI;aACX,CAAC,CAAC;QACJ,CAAC;QAED,OAAO,IAAI,CAAC;IACb,CAAC;CACD,CAAC;AAEH,SAAS,iBAAiB,CAAC,IAAW;IACrC,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;QACjC,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,IAAI,EAAE,CAAC;YAClC,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC/B,CAAC;IACF,CAAC;IACD,MAAM,CACL,IAAI,CAAC,EAAE,KAAK,SAAS,IAAI,IAAI,CAAC,EAAE,KAAK,IAAI,EACzC,KAAK,CAAC,+DAA+D,CACrE,CAAC;IACF,OAAO,IAAI,CAAC,EAAE,CAAC;AAChB,CAAC;AACD;;GAEG;AACH,MAAM,CAAC,MAAM,kCAAkC,GAC9C,8BAA8B,CAAC,gBAAgB,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport fs from \"fs\";\n\nimport { bufferToString } from \"@fluid-internal/client-utils\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { ISummaryTree } from \"@fluidframework/driver-definitions\";\nimport {\n\tIDocumentStorageService,\n\tISummaryContext,\n\tISnapshotTree,\n\tIVersion,\n\tITree,\n\tFileMode,\n\tTreeEntry,\n\tIBlob,\n} from \"@fluidframework/driver-definitions/internal\";\nimport {\n\tbuildSnapshotTree,\n\tconvertSummaryTreeToSnapshotITree,\n} from \"@fluidframework/driver-utils/internal\";\nimport {\n\tIFileSnapshot,\n\tReadDocumentStorageServiceBase,\n} from \"@fluidframework/replay-driver/internal\";\n\n// This ID is used by replay tool as Document Id.\n// We leverage it to figure out when container is asking for root document tree.\n/**\n * @internal\n */\nexport const FileStorageDocumentName = \"FileStorageDocId\"; // Some unique document name\n\n// Tree ID use to communicate between getVersions() & getSnapshotTree() that IVersion is ours.\nconst FileStorageVersionTreeId = \"FileStorageTreeId\";\n\n/**\n * Document storage service for the file driver.\n * @internal\n */\nexport class FluidFetchReader\n\textends ReadDocumentStorageServiceBase\n\timplements IDocumentStorageService\n{\n\tprotected docTree: ISnapshotTree | null = null;\n\n\tconstructor(\n\t\tprivate readonly path: string,\n\t\tprivate readonly versionName?: string,\n\t) {\n\t\tsuper();\n\t}\n\n\t/**\n\t * Read the file and returns the snapshot tree.\n\t * @param version - The version contains the path of the file which contains the snapshot tree.\n\t */\n\t// eslint-disable-next-line @rushstack/no-new-null\n\tpublic async getSnapshotTree(version?: IVersion): Promise<ISnapshotTree | null> {\n\t\tassert(version !== null, 0x092 /* \"version input for reading snapshot tree is null!\" */);\n\t\tassert(\n\t\t\t!version || version.treeId === FileStorageVersionTreeId,\n\t\t\t0x093 /* \"invalid version input for reading snapshot tree!\" */,\n\t\t);\n\n\t\tlet filename: string;\n\t\tlet rootTree = false;\n\t\tif (!version || version.id === \"latest\") {\n\t\t\tif (this.docTree) {\n\t\t\t\treturn this.docTree;\n\t\t\t}\n\t\t\tif (this.versionName === undefined) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\trootTree = true;\n\t\t\tfilename = `${this.path}/${this.versionName}/tree.json`;\n\t\t} else {\n\t\t\tfilename = `${this.path}/${this.versionName}/${version.id}.json`;\n\t\t}\n\n\t\tif (!fs.existsSync(filename)) {\n\t\t\tthrow new Error(`Can't find file ${filename}`);\n\t\t}\n\t\tconst data = fs.readFileSync(filename);\n\t\tconst tree = JSON.parse(data.toString(\"utf-8\"));\n\t\tif (rootTree) {\n\t\t\tthis.docTree = tree;\n\t\t}\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\treturn tree;\n\t}\n\n\t/**\n\t * Gets the path of the snapshot tree to be read.\n\t * @param versionId - version ID.\n\t * @param count - Number of versions to be returned.\n\t */\n\t// eslint-disable-next-line @rushstack/no-new-null\n\tpublic async getVersions(versionId: string | null, count: number): Promise<IVersion[]> {\n\t\tif (versionId === FileStorageDocumentName || versionId === null) {\n\t\t\tif (this.docTree !== null || this.versionName !== undefined) {\n\t\t\t\treturn [{ id: \"latest\", treeId: FileStorageVersionTreeId }];\n\t\t\t}\n\t\t\t// Started with ops - return empty set.\n\t\t\treturn [];\n\t\t} else if (this.versionName !== undefined) {\n\t\t\tassert(!!this.docTree, 0x094 /* \"Missing snapshot tree!\" */);\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tid: versionId,\n\t\t\t\t\ttreeId: FileStorageVersionTreeId,\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\t\tthrow new Error(`Unknown version: ${versionId}`);\n\t}\n\n\tpublic async readBlob(sha: string): Promise<ArrayBufferLike> {\n\t\tif (this.versionName !== undefined) {\n\t\t\tconst fileName = `${this.path}/${this.versionName}/${sha}`;\n\t\t\tif (fs.existsSync(fileName)) {\n\t\t\t\tconst data = fs.readFileSync(fileName);\n\t\t\t\treturn data;\n\t\t\t}\n\t\t}\n\t\tthrow new Error(`Can't find blob ${sha}`);\n\t}\n}\n\n/**\n * @internal\n */\nexport interface ISnapshotWriterStorage extends IDocumentStorageService {\n\tonSnapshotHandler(snapshot: IFileSnapshot): void;\n\treset(): void;\n}\n\n/**\n * @internal\n */\nexport type ReaderConstructor = new (...args: any[]) => IDocumentStorageService;\n/**\n * @internal\n */\nexport const FileSnapshotWriterClassFactory = <TBase extends ReaderConstructor>(Base: TBase) =>\n\tclass extends Base implements ISnapshotWriterStorage {\n\t\t// Note: if variable name has same name as in base class, it overrides it!\n\t\tpublic blobsWriter = new Map<string, ArrayBufferLike>();\n\t\tpublic latestWriterTree?: ISnapshotTree;\n\t\tpublic docId?: string;\n\n\t\tpublic reset() {\n\t\t\tthis.blobsWriter = new Map<string, ArrayBufferLike>();\n\t\t\tthis.latestWriterTree = undefined;\n\t\t\tthis.docId = undefined;\n\t\t}\n\n\t\tpublic onSnapshotHandler(snapshot: IFileSnapshot): void {\n\t\t\tthrow new Error(\"onSnapshotHandler is not setup! Please provide your handler!\");\n\t\t}\n\n\t\tpublic async readBlob(sha: string): Promise<ArrayBufferLike> {\n\t\t\tconst blob = this.blobsWriter.get(sha);\n\t\t\tif (blob !== undefined) {\n\t\t\t\treturn blob;\n\t\t\t}\n\t\t\treturn super.readBlob(sha);\n\t\t}\n\n\t\t// eslint-disable-next-line @rushstack/no-new-null\n\t\tpublic async getVersions(versionId: string | null, count: number): Promise<IVersion[]> {\n\t\t\t// If we already saved document, that means we are getting here because of snapshot generation.\n\t\t\t// Not returning tree ensures that ContainerRuntime.snapshot() would regenerate subtrees for\n\t\t\t// each unchanged data store.\n\t\t\t// If we want to change that, we would need to capture docId on first call and return this.latestWriterTree\n\t\t\t// when latest is requested.\n\t\t\tif (this.latestWriterTree && (this.docId === versionId || versionId === null)) {\n\t\t\t\treturn [{ id: \"latest\", treeId: FileStorageVersionTreeId }];\n\t\t\t}\n\n\t\t\tif (this.docId === undefined && versionId !== null) {\n\t\t\t\tthis.docId = versionId;\n\t\t\t}\n\n\t\t\treturn super.getVersions(versionId, count);\n\t\t}\n\n\t\t// eslint-disable-next-line @rushstack/no-new-null\n\t\tpublic async getSnapshotTree(version?: IVersion): Promise<ISnapshotTree | null> {\n\t\t\tif (this.latestWriterTree && (!version || version.id === \"latest\")) {\n\t\t\t\treturn this.latestWriterTree;\n\t\t\t}\n\t\t\treturn super.getSnapshotTree(version);\n\t\t}\n\n\t\tpublic async uploadSummaryWithContext(\n\t\t\tsummary: ISummaryTree,\n\t\t\tcontext: ISummaryContext,\n\t\t): Promise<string> {\n\t\t\tconst tree = convertSummaryTreeToSnapshotITree(summary);\n\n\t\t\t// Remove tree IDs for easier comparison of snapshots\n\t\t\tdelete tree.id;\n\t\t\tremoveNullTreeIds(tree);\n\n\t\t\tthis.latestWriterTree = buildSnapshotTree(tree.entries, this.blobsWriter);\n\n\t\t\tconst fileSnapshot: IFileSnapshot = { tree, commits: {} };\n\t\t\tthis.onSnapshotHandler(fileSnapshot);\n\t\t\treturn \"testHandleId\";\n\t\t}\n\n\t\tpublic async buildTree(snapshotTree: ISnapshotTree): Promise<ITree> {\n\t\t\tconst tree: ITree = { entries: [] };\n\n\t\t\tfor (const subTreeId of Object.keys(snapshotTree.trees)) {\n\t\t\t\t// Non null asserting here, we should use Object.entries() instead\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tconst subTree = await this.buildTree(snapshotTree.trees[subTreeId]!);\n\t\t\t\ttree.entries.push({\n\t\t\t\t\tmode: FileMode.Directory,\n\t\t\t\t\tpath: subTreeId,\n\t\t\t\t\ttype: TreeEntry.Tree,\n\t\t\t\t\tvalue: subTree,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tfor (const blobName of Object.keys(snapshotTree.blobs)) {\n\t\t\t\t// Non null asserting here, we should use Object.entries() instead\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tconst buffer = await this.readBlob(snapshotTree.blobs[blobName]!);\n\t\t\t\tconst contents = bufferToString(buffer, \"utf8\");\n\t\t\t\tconst blob: IBlob = {\n\t\t\t\t\tcontents,\n\t\t\t\t\tencoding: \"utf-8\",\n\t\t\t\t};\n\t\t\t\ttree.entries.push({\n\t\t\t\t\tmode: FileMode.File,\n\t\t\t\t\tpath: blobName,\n\t\t\t\t\ttype: TreeEntry.Blob,\n\t\t\t\t\tvalue: blob,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn tree;\n\t\t}\n\t};\n\nfunction removeNullTreeIds(tree: ITree) {\n\tfor (const node of tree.entries) {\n\t\tif (node.type === TreeEntry.Tree) {\n\t\t\tremoveNullTreeIds(node.value);\n\t\t}\n\t}\n\tassert(\n\t\ttree.id === undefined || tree.id === null,\n\t\t0x096 /* \"Trying to remove valid tree IDs in removeNullTreeIds()!\" */,\n\t);\n\tdelete tree.id;\n}\n/**\n * @internal\n */\nexport const FluidFetchReaderFileSnapshotWriter =\n\tFileSnapshotWriterClassFactory(FluidFetchReader);\n"]}
|
package/lib/public.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluidframework/file-driver",
|
|
3
|
-
"version": "2.1.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "A driver that reads/write from/to local file storage.",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -37,21 +37,21 @@
|
|
|
37
37
|
"main": "lib/index.js",
|
|
38
38
|
"types": "lib/public.d.ts",
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@fluid-internal/client-utils": "2.1.0
|
|
41
|
-
"@fluidframework/core-interfaces": "2.1.0
|
|
42
|
-
"@fluidframework/core-utils": "2.1.0
|
|
43
|
-
"@fluidframework/driver-definitions": "2.1.0
|
|
44
|
-
"@fluidframework/driver-utils": "2.1.0
|
|
45
|
-
"@fluidframework/replay-driver": "2.1.0
|
|
40
|
+
"@fluid-internal/client-utils": "~2.1.0",
|
|
41
|
+
"@fluidframework/core-interfaces": "~2.1.0",
|
|
42
|
+
"@fluidframework/core-utils": "~2.1.0",
|
|
43
|
+
"@fluidframework/driver-definitions": "~2.1.0",
|
|
44
|
+
"@fluidframework/driver-utils": "~2.1.0",
|
|
45
|
+
"@fluidframework/replay-driver": "~2.1.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@arethetypeswrong/cli": "^0.15.2",
|
|
49
|
-
"@biomejs/biome": "
|
|
50
|
-
"@fluid-tools/build-cli": "^0.
|
|
49
|
+
"@biomejs/biome": "~1.8.3",
|
|
50
|
+
"@fluid-tools/build-cli": "^0.41.0",
|
|
51
51
|
"@fluidframework/build-common": "^2.0.3",
|
|
52
|
-
"@fluidframework/build-tools": "^0.
|
|
52
|
+
"@fluidframework/build-tools": "^0.41.0",
|
|
53
53
|
"@fluidframework/eslint-config-fluid": "^5.3.0",
|
|
54
|
-
"@fluidframework/file-driver-previous": "npm:@fluidframework/file-driver@2.0.0
|
|
54
|
+
"@fluidframework/file-driver-previous": "npm:@fluidframework/file-driver@2.0.0",
|
|
55
55
|
"@microsoft/api-extractor": "^7.45.1",
|
|
56
56
|
"@types/node": "^18.19.0",
|
|
57
57
|
"concurrently": "^8.2.1",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
},
|
|
71
71
|
"typeValidation": {
|
|
72
72
|
"broken": {
|
|
73
|
-
"
|
|
73
|
+
"Variable_FluidFetchReaderFileSnapshotWriter": {
|
|
74
74
|
"forwardCompat": false
|
|
75
75
|
}
|
|
76
76
|
}
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
"build:docs": "api-extractor run --local",
|
|
85
85
|
"build:esnext": "tsc --project ./tsconfig.json",
|
|
86
86
|
"check:are-the-types-wrong": "attw --pack .",
|
|
87
|
-
"check:biome": "biome check .
|
|
87
|
+
"check:biome": "biome check .",
|
|
88
88
|
"check:exports": "concurrently \"npm:check:exports:*\"",
|
|
89
89
|
"check:exports:bundle-release-tags": "api-extractor run --config api-extractor/api-extractor-lint-bundle.json",
|
|
90
90
|
"check:exports:cjs:public": "api-extractor run --config api-extractor/api-extractor-lint-public.cjs.json",
|
|
@@ -96,7 +96,7 @@
|
|
|
96
96
|
"eslint": "eslint --format stylish src",
|
|
97
97
|
"eslint:fix": "eslint --format stylish src --fix --fix-type problem,suggestion,layout",
|
|
98
98
|
"format": "npm run format:biome",
|
|
99
|
-
"format:biome": "biome check . --
|
|
99
|
+
"format:biome": "biome check . --write",
|
|
100
100
|
"format:prettier": "prettier --write . --cache --ignore-path ../../../.prettierignore",
|
|
101
101
|
"lint": "fluid-build . --task lint",
|
|
102
102
|
"lint:fix": "fluid-build . --task eslint:fix --task format",
|
|
@@ -67,12 +67,16 @@ export class FileDeltaStorageService implements IDocumentDeltaStorageService {
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
// Optimizations for multiple readers (replay tool)
|
|
70
|
-
|
|
70
|
+
// Non null asserting here because of the length check
|
|
71
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
72
|
+
if (this.lastOps.length > 0 && this.lastOps[0]!.sequenceNumber === readFrom + 1) {
|
|
71
73
|
return this.lastOps;
|
|
72
74
|
}
|
|
73
75
|
this.lastOps = this.messages.slice(readFrom, readTo);
|
|
74
76
|
assert(
|
|
75
|
-
|
|
77
|
+
// Non null asserting here because of the length check above
|
|
78
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
79
|
+
this.lastOps[0]!.sequenceNumber === readFrom + 1,
|
|
76
80
|
0x091 /* "Retrieved ops' first sequence number has unexpected value!" */,
|
|
77
81
|
);
|
|
78
82
|
return this.lastOps;
|
|
@@ -217,7 +217,9 @@ export const FileSnapshotWriterClassFactory = <TBase extends ReaderConstructor>(
|
|
|
217
217
|
const tree: ITree = { entries: [] };
|
|
218
218
|
|
|
219
219
|
for (const subTreeId of Object.keys(snapshotTree.trees)) {
|
|
220
|
-
|
|
220
|
+
// Non null asserting here, we should use Object.entries() instead
|
|
221
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
222
|
+
const subTree = await this.buildTree(snapshotTree.trees[subTreeId]!);
|
|
221
223
|
tree.entries.push({
|
|
222
224
|
mode: FileMode.Directory,
|
|
223
225
|
path: subTreeId,
|
|
@@ -227,7 +229,9 @@ export const FileSnapshotWriterClassFactory = <TBase extends ReaderConstructor>(
|
|
|
227
229
|
}
|
|
228
230
|
|
|
229
231
|
for (const blobName of Object.keys(snapshotTree.blobs)) {
|
|
230
|
-
|
|
232
|
+
// Non null asserting here, we should use Object.entries() instead
|
|
233
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
234
|
+
const buffer = await this.readBlob(snapshotTree.blobs[blobName]!);
|
|
231
235
|
const contents = bufferToString(buffer, "utf8");
|
|
232
236
|
const blob: IBlob = {
|
|
233
237
|
contents,
|