@fluidframework/file-driver 0.56.5 → 0.57.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/dist/fileDocumentStorageService.d.ts +4 -17
- package/dist/fileDocumentStorageService.d.ts.map +1 -1
- package/dist/fileDocumentStorageService.js +5 -71
- package/dist/fileDocumentStorageService.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/package.json +4 -4
- package/src/fileDocumentStorageService.ts +6 -87
- package/src/packageVersion.ts +1 -1
|
@@ -29,7 +29,6 @@ export declare class FluidFetchReader extends ReadDocumentStorageServiceBase imp
|
|
|
29
29
|
readBlob(sha: string): Promise<ArrayBufferLike>;
|
|
30
30
|
}
|
|
31
31
|
export interface ISnapshotWriterStorage extends IDocumentStorageService {
|
|
32
|
-
onCommitHandler(dataStoreName: string, tree: api.ITree): void;
|
|
33
32
|
onSnapshotHandler(snapshot: IFileSnapshot): void;
|
|
34
33
|
reset(): void;
|
|
35
34
|
}
|
|
@@ -37,25 +36,19 @@ export declare type ReaderConstructor = new (...args: any[]) => IDocumentStorage
|
|
|
37
36
|
export declare const FileSnapshotWriterClassFactory: <TBase extends ReaderConstructor>(Base: TBase) => {
|
|
38
37
|
new (...args: any[]): {
|
|
39
38
|
blobsWriter: Map<string, ArrayBufferLike>;
|
|
40
|
-
commitsWriter: {
|
|
41
|
-
[key: string]: api.ITree;
|
|
42
|
-
};
|
|
43
39
|
latestWriterTree?: api.ISnapshotTree | undefined;
|
|
44
40
|
docId?: string | undefined;
|
|
45
41
|
reset(): void;
|
|
46
|
-
onCommitHandler(dataStoreName: string, tree: api.ITree): void;
|
|
47
42
|
onSnapshotHandler(snapshot: IFileSnapshot): void;
|
|
48
43
|
readBlob(sha: string): Promise<ArrayBufferLike>;
|
|
49
44
|
getVersions(versionId: string | null, count: number): Promise<api.IVersion[]>;
|
|
50
45
|
getSnapshotTree(version?: api.IVersion | undefined): Promise<api.ISnapshotTree | null>;
|
|
51
|
-
|
|
52
|
-
writeOutFullSnapshot(tree: api.ITree): Promise<void>;
|
|
53
|
-
sortTree(tree: api.ITree): void;
|
|
46
|
+
uploadSummaryWithContext(summary: api.ISummaryTree, context: ISummaryContext): Promise<string>;
|
|
54
47
|
buildTree(snapshotTree: api.ISnapshotTree): Promise<api.ITree>;
|
|
55
48
|
repositoryUrl: string;
|
|
56
49
|
readonly policies?: IDocumentStorageServicePolicies | undefined;
|
|
50
|
+
write(root: api.ITree, parents: string[], message: string, ref: string): Promise<api.IVersion>;
|
|
57
51
|
createBlob(file: ArrayBufferLike): Promise<api.ICreateBlobResponse>;
|
|
58
|
-
uploadSummaryWithContext(summary: api.ISummaryTree, context: ISummaryContext): Promise<string>;
|
|
59
52
|
downloadSummary(handle: api.ISummaryHandle): Promise<api.ISummaryTree>;
|
|
60
53
|
readonly disposed?: boolean | undefined;
|
|
61
54
|
dispose?: ((error?: Error | undefined) => void) | undefined;
|
|
@@ -64,25 +57,19 @@ export declare const FileSnapshotWriterClassFactory: <TBase extends ReaderConstr
|
|
|
64
57
|
export declare const FluidFetchReaderFileSnapshotWriter: {
|
|
65
58
|
new (...args: any[]): {
|
|
66
59
|
blobsWriter: Map<string, ArrayBufferLike>;
|
|
67
|
-
commitsWriter: {
|
|
68
|
-
[key: string]: api.ITree;
|
|
69
|
-
};
|
|
70
60
|
latestWriterTree?: api.ISnapshotTree | undefined;
|
|
71
61
|
docId?: string | undefined;
|
|
72
62
|
reset(): void;
|
|
73
|
-
onCommitHandler(dataStoreName: string, tree: api.ITree): void;
|
|
74
63
|
onSnapshotHandler(snapshot: IFileSnapshot): void;
|
|
75
64
|
readBlob(sha: string): Promise<ArrayBufferLike>;
|
|
76
65
|
getVersions(versionId: string | null, count: number): Promise<api.IVersion[]>;
|
|
77
66
|
getSnapshotTree(version?: api.IVersion | undefined): Promise<api.ISnapshotTree | null>;
|
|
78
|
-
|
|
79
|
-
writeOutFullSnapshot(tree: api.ITree): Promise<void>;
|
|
80
|
-
sortTree(tree: api.ITree): void;
|
|
67
|
+
uploadSummaryWithContext(summary: api.ISummaryTree, context: ISummaryContext): Promise<string>;
|
|
81
68
|
buildTree(snapshotTree: api.ISnapshotTree): Promise<api.ITree>;
|
|
82
69
|
repositoryUrl: string;
|
|
83
70
|
readonly policies?: IDocumentStorageServicePolicies | undefined;
|
|
71
|
+
write(root: api.ITree, parents: string[], message: string, ref: string): Promise<api.IVersion>;
|
|
84
72
|
createBlob(file: ArrayBufferLike): Promise<api.ICreateBlobResponse>;
|
|
85
|
-
uploadSummaryWithContext(summary: api.ISummaryTree, context: ISummaryContext): Promise<string>;
|
|
86
73
|
downloadSummary(handle: api.ISummaryHandle): Promise<api.ISummaryTree>;
|
|
87
74
|
readonly disposed?: boolean | undefined;
|
|
88
75
|
dispose?: ((error?: Error | undefined) => void) | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileDocumentStorageService.d.ts","sourceRoot":"","sources":["../src/fileDocumentStorageService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EACH,uBAAuB,EACvB,+BAA+B,EAAK,qCAAqC;AACzE,eAAe,EAClB,MAAM,oCAAoC,CAAC;AAE5C,OAAO,KAAK,GAAG,MAAM,sCAAsC,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,8BAA8B,EAAE,MAAM,+BAA+B,CAAC;AAI9F,eAAO,MAAM,uBAAuB,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"fileDocumentStorageService.d.ts","sourceRoot":"","sources":["../src/fileDocumentStorageService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EACH,uBAAuB,EACvB,+BAA+B,EAAK,qCAAqC;AACzE,eAAe,EAClB,MAAM,oCAAoC,CAAC;AAE5C,OAAO,KAAK,GAAG,MAAM,sCAAsC,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,8BAA8B,EAA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AAC;;;;;;;;;SAgC9E,CAAC;AAYN,eAAO,MAAM,kCAAkC;kBA5GD,GAAG,EAAE;;;;;oCAcR,aAAa,GAAG,IAAI;sBAI5B,MAAM,GAAG,QAAQ,eAAe,CAAC;+BAQxB,MAAM,GAAG,IAAI,SAAS,MAAM,GAAG,QAAQ,IAAI,QAAQ,EAAE,CAAC;6DAiBpC,QAAQ,IAAI,aAAa,GAAG,IAAI,CAAC;0CAOxC,IAAI,YAAY,WAAW,eAAe,GAAG,QAAQ,MAAM,CAAC;gCActE,IAAI,aAAa,GAAG,QAAQ,IAAI,KAAK,CAAC;;;;;;;;;2BA4Ce,CAAC"}
|
|
@@ -37,8 +37,6 @@ const replay_driver_1 = require("@fluidframework/replay-driver");
|
|
|
37
37
|
exports.FileStorageDocumentName = "FileStorageDocId"; // Some unique document name
|
|
38
38
|
// Tree ID use to communicate between getVersions() & getSnapshotTree() that IVersion is ours.
|
|
39
39
|
const FileStorageVersionTreeId = "FileStorageTreeId";
|
|
40
|
-
// This ID should not show up anywhere, as it's internal only ID that no public API should accept.
|
|
41
|
-
const FileStorageVersionTreeIdUnused = "baad";
|
|
42
40
|
/**
|
|
43
41
|
* Document storage service for the file driver.
|
|
44
42
|
*/
|
|
@@ -79,7 +77,6 @@ class FluidFetchReader extends replay_driver_1.ReadDocumentStorageServiceBase {
|
|
|
79
77
|
if (rootTree) {
|
|
80
78
|
this.docTree = tree;
|
|
81
79
|
}
|
|
82
|
-
// Fill in this.commit right here?
|
|
83
80
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
84
81
|
return tree;
|
|
85
82
|
}
|
|
@@ -97,7 +94,6 @@ class FluidFetchReader extends replay_driver_1.ReadDocumentStorageServiceBase {
|
|
|
97
94
|
return [];
|
|
98
95
|
}
|
|
99
96
|
else if (this.versionName !== undefined) {
|
|
100
|
-
// We loaded from snapshot - search for commit there.
|
|
101
97
|
common_utils_1.assert(!!this.docTree, 0x094 /* "Missing snapshot tree!" */);
|
|
102
98
|
return [{
|
|
103
99
|
id: versionId,
|
|
@@ -123,16 +119,12 @@ const FileSnapshotWriterClassFactory = (Base) => class extends Base {
|
|
|
123
119
|
super(...arguments);
|
|
124
120
|
// Note: if variable name has same name as in base class, it overrides it!
|
|
125
121
|
this.blobsWriter = new Map();
|
|
126
|
-
this.commitsWriter = {};
|
|
127
122
|
}
|
|
128
123
|
reset() {
|
|
129
124
|
this.blobsWriter = new Map();
|
|
130
|
-
this.commitsWriter = {};
|
|
131
125
|
this.latestWriterTree = undefined;
|
|
132
126
|
this.docId = undefined;
|
|
133
127
|
}
|
|
134
|
-
onCommitHandler(dataStoreName, tree) {
|
|
135
|
-
}
|
|
136
128
|
onSnapshotHandler(snapshot) {
|
|
137
129
|
throw new Error("onSnapshotHandler is not setup! Please provide your handler!");
|
|
138
130
|
}
|
|
@@ -155,81 +147,23 @@ const FileSnapshotWriterClassFactory = (Base) => class extends Base {
|
|
|
155
147
|
if (this.docId === undefined && versionId !== null) {
|
|
156
148
|
this.docId = versionId;
|
|
157
149
|
}
|
|
158
|
-
if (versionId !== null && this.commitsWriter[versionId] !== undefined) {
|
|
159
|
-
// PrefetchDocumentStorageService likes to prefetch everything!
|
|
160
|
-
// Skip, as Container does not really need it.
|
|
161
|
-
throw new Error("Not supporting commit loading");
|
|
162
|
-
// Return [{id: versionId, treeId: FileStorageVersionTreeId}];
|
|
163
|
-
}
|
|
164
150
|
return super.getVersions(versionId, count);
|
|
165
151
|
}
|
|
166
152
|
async getSnapshotTree(version) {
|
|
167
153
|
if (this.latestWriterTree && (!version || version.id === "latest")) {
|
|
168
154
|
return this.latestWriterTree;
|
|
169
155
|
}
|
|
170
|
-
if (version && this.commitsWriter[version.id] !== undefined) {
|
|
171
|
-
return driver_utils_1.buildSnapshotTree(this.commitsWriter[version.id].entries, this.blobsWriter);
|
|
172
|
-
}
|
|
173
156
|
return super.getSnapshotTree(version);
|
|
174
157
|
}
|
|
175
|
-
async
|
|
176
|
-
|
|
177
|
-
if (tree && tree.entries) {
|
|
178
|
-
tree.entries.forEach((entry) => {
|
|
179
|
-
if (entry.path === ".component" && entry.type === api.TreeEntry.Blob) {
|
|
180
|
-
const blob = entry.value;
|
|
181
|
-
const content = blob.contents.split(":");
|
|
182
|
-
if (content[0] === `{"pkg"`) {
|
|
183
|
-
dataStoreName = content[1].substring(1, content[1].lastIndexOf(`"`));
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
const commitName = `commit_${dataStoreName}`;
|
|
189
|
-
// Sort entries for easier diffing
|
|
190
|
-
this.sortTree(tree);
|
|
158
|
+
async uploadSummaryWithContext(summary, context) {
|
|
159
|
+
const tree = driver_utils_1.convertSummaryTreeToSnapshotITree(summary);
|
|
191
160
|
// Remove tree IDs for easier comparison of snapshots
|
|
192
161
|
delete tree.id;
|
|
193
162
|
removeNullTreeIds(tree);
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
}
|
|
197
|
-
else {
|
|
198
|
-
// Rebuild latest tree - runtime will ask for it when generating next snapshot to write out
|
|
199
|
-
// non-changed commits for data stores
|
|
200
|
-
await this.writeOutFullSnapshot(tree);
|
|
201
|
-
// Prep for the future - refresh latest tree, as it's requests on next snapshot generation.
|
|
202
|
-
// Do not care about blobs (at least for now), as blobs are not written out (need follow up)
|
|
203
|
-
this.latestWriterTree = driver_utils_1.buildSnapshotTree(tree.entries, this.blobsWriter);
|
|
204
|
-
// Do not reset this.commitsWriter - runtime will reference same commits in future snapshots
|
|
205
|
-
// if data store did not change in between two snapshots.
|
|
206
|
-
// We can optimize here by filtering commits based on contents of this.docTree.commits
|
|
207
|
-
}
|
|
208
|
-
this.onCommitHandler(dataStoreName, tree);
|
|
209
|
-
return {
|
|
210
|
-
id: commitName,
|
|
211
|
-
date: new Date().toUTCString(),
|
|
212
|
-
treeId: FileStorageVersionTreeIdUnused,
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
async writeOutFullSnapshot(tree) {
|
|
216
|
-
const commits = {};
|
|
217
|
-
// Sort keys. This does not guarantees that JSON.stringify() would produce sorted result,
|
|
218
|
-
// but in practice it does.
|
|
219
|
-
const commitsSorted = {};
|
|
220
|
-
for (const key of Object.keys(commits).sort()) {
|
|
221
|
-
commitsSorted[key] = commits[key];
|
|
222
|
-
}
|
|
223
|
-
const fileSnapshot = { tree, commits: commitsSorted };
|
|
163
|
+
this.latestWriterTree = driver_utils_1.buildSnapshotTree(tree.entries, this.blobsWriter);
|
|
164
|
+
const fileSnapshot = { tree, commits: {} };
|
|
224
165
|
this.onSnapshotHandler(fileSnapshot);
|
|
225
|
-
|
|
226
|
-
sortTree(tree) {
|
|
227
|
-
tree.entries.sort((a, b) => a.path.localeCompare(b.path));
|
|
228
|
-
tree.entries.map((entry) => {
|
|
229
|
-
if (entry.type === api.TreeEntry.Tree) {
|
|
230
|
-
this.sortTree(entry.value);
|
|
231
|
-
}
|
|
232
|
-
});
|
|
166
|
+
return "testHandleId";
|
|
233
167
|
}
|
|
234
168
|
async buildTree(snapshotTree) {
|
|
235
169
|
const tree = { entries: [] };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileDocumentStorageService.js","sourceRoot":"","sources":["../src/fileDocumentStorageService.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,4CAAoB;AACpB,+DAAsE;AAMtE,+DAAiE;AACjE,0EAA4D;AAC5D,iEAA8F;AAE9F,iDAAiD;AACjD,gFAAgF;AACnE,QAAA,uBAAuB,GAAG,kBAAkB,CAAC,CAAC,4BAA4B;AAEvF,8FAA8F;AAC9F,MAAM,wBAAwB,GAAG,mBAAmB,CAAC;AAErD,kGAAkG;AAClG,MAAM,8BAA8B,GAAG,MAAM,CAAC;AAE9C;;GAEG;AACH,MAAa,gBAAiB,SAAQ,8CAA8B;IAGhE,YAA6B,IAAY,EAAmB,WAAoB;QAC5E,KAAK,EAAE,CAAC;QADiB,SAAI,GAAJ,IAAI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AK,CAAC,QAAQ,CAAC,CAAC,CAAC;YACjE,MAAM,QAAQ,GAAG,6BAAc,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;YAChD,MAAM,IAAI,GAAc;gBACpB,QAAQ;gBACR,QAAQ,EAAE,OAAO;aACpB,CAAC;YACF,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;gBACd,IAAI,EAAE,GAAG,CAAC,QAAQ,CAAC,IAAI;gBACvB,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,GAAG,CAAC,SAAS,CAAC,IAAI;gBACxB,KAAK,EAAE,IAAI;aACd,CAAC,CAAC;SACN;QAED,qBAAM,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,MAAM,KAAK,CAAC,EACjD,KAAK,CAAC,sDAAsD,CAAC,CAAC;QAClE,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ,CAAC;AAzKO,QAAA,8BAA8B,kCAyKrC;AAEN,SAAS,iBAAiB,CAAC,IAAe;IACtC,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,OAAO,EAAE;QAC7B,IAAI,IAAI,CAAC,IAAI,KAAK,GAAG,CAAC,SAAS,CAAC,IAAI,EAAE;YAClC,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SACjC;KACJ;IACD,qBAAM,CAAC,IAAI,CAAC,EAAE,KAAK,SAAS,IAAI,IAAI,CAAC,EAAE,KAAK,IAAI,EAC5C,KAAK,CAAC,+DAA+D,CAAC,CAAC;IAC3E,OAAO,IAAI,CAAC,EAAE,CAAC;AACnB,CAAC;AAEY,QAAA,kCAAkC,GAAG,sCAA8B,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\";\nimport { assert, bufferToString } from \"@fluidframework/common-utils\";\nimport {\n IDocumentStorageService,\n IDocumentStorageServicePolicies, // these are needed for api-extractor\n ISummaryContext, // these are needed for api-extractor\n} from \"@fluidframework/driver-definitions\";\nimport { buildSnapshotTree } from \"@fluidframework/driver-utils\";\nimport * as api from \"@fluidframework/protocol-definitions\";\nimport { IFileSnapshot, ReadDocumentStorageServiceBase } from \"@fluidframework/replay-driver\";\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.\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// This ID should not show up anywhere, as it's internal only ID that no public API should accept.\nconst FileStorageVersionTreeIdUnused = \"baad\";\n\n/**\n * Document storage service for the file driver.\n */\nexport class FluidFetchReader extends ReadDocumentStorageServiceBase implements IDocumentStorageService {\n protected docTree: api.ISnapshotTree | null = null;\n\n constructor(private readonly path: string, private readonly versionName?: string) {\n super();\n }\n\n /**\n * Read the file and returns the snapshot tree.\n * @param version - The version contains the path of the file which contains the snapshot tree.\n */\n public async getSnapshotTree(version?: api.IVersion): Promise<api.ISnapshotTree | null> {\n assert(version !== null, 0x092 /* \"version input for reading snapshot tree is null!\" */);\n assert(!version || version.treeId === FileStorageVersionTreeId,\n 0x093 /* \"invalid version input for reading snapshot tree!\" */);\n\n let filename: string;\n let rootTree = false;\n if (!version || version.id === \"latest\") {\n if (this.docTree) {\n return this.docTree;\n }\n if (this.versionName === undefined) {\n return null;\n }\n rootTree = true;\n filename = `${this.path}/${this.versionName}/tree.json`;\n } else {\n filename = `${this.path}/${this.versionName}/${version.id}.json`;\n }\n\n if (!fs.existsSync(filename)) {\n throw new Error(`Can't find file ${filename}`);\n }\n const data = fs.readFileSync(filename);\n const tree = JSON.parse(data.toString(\"utf-8\"));\n if (rootTree) {\n this.docTree = tree;\n }\n // Fill in this.commit right here?\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return tree;\n }\n\n /**\n * Gets the path of the snapshot tree to be read.\n * @param versionId - version ID.\n * @param count - Number of versions to be returned.\n */\n public async getVersions(versionId: string | null, count: number): Promise<api.IVersion[]> {\n if (versionId === FileStorageDocumentName || versionId === null) {\n if (this.docTree || this.versionName !== undefined) {\n return [{ id: \"latest\", treeId: FileStorageVersionTreeId }];\n }\n // Started with ops - return empty set.\n return [];\n } else if (this.versionName !== undefined) {\n // We loaded from snapshot - search for commit there.\n assert(!!this.docTree, 0x094 /* \"Missing snapshot tree!\" */);\n return [{\n id: versionId,\n treeId: FileStorageVersionTreeId,\n }];\n }\n throw new Error(`Unknown version: ${versionId}`);\n }\n\n public async readBlob(sha: string): Promise<ArrayBufferLike> {\n if (this.versionName !== undefined) {\n const fileName = `${this.path}/${this.versionName}/${sha}`;\n if (fs.existsSync(fileName)) {\n const data = fs.readFileSync(fileName);\n return data;\n }\n }\n throw new Error(`Can't find blob ${sha}`);\n }\n}\n\nexport interface ISnapshotWriterStorage extends IDocumentStorageService {\n onCommitHandler(dataStoreName: string, tree: api.ITree): void;\n onSnapshotHandler(snapshot: IFileSnapshot): void;\n reset(): void;\n}\n\nexport type ReaderConstructor = new (...args: any[]) => IDocumentStorageService;\nexport const FileSnapshotWriterClassFactory = <TBase extends ReaderConstructor>(Base: TBase) =>\n class extends Base implements ISnapshotWriterStorage {\n // Note: if variable name has same name as in base class, it overrides it!\n public blobsWriter = new Map<string, ArrayBufferLike>();\n public commitsWriter: { [key: string]: api.ITree } = {};\n public latestWriterTree?: api.ISnapshotTree;\n public docId?: string;\n\n public reset() {\n this.blobsWriter = new Map<string, ArrayBufferLike>();\n this.commitsWriter = {};\n this.latestWriterTree = undefined;\n this.docId = undefined;\n }\n\n public onCommitHandler(dataStoreName: string, tree: api.ITree): void {\n }\n\n public onSnapshotHandler(snapshot: IFileSnapshot): void {\n throw new Error(\"onSnapshotHandler is not setup! Please provide your handler!\");\n }\n\n public async readBlob(sha: string): Promise<ArrayBufferLike> {\n const blob = this.blobsWriter.get(sha);\n if (blob !== undefined) {\n return blob;\n }\n return super.readBlob(sha);\n }\n\n public async getVersions(versionId: string | null, count: number): Promise<api.IVersion[]> {\n // If we already saved document, that means we are getting here because of snapshot generation.\n // Not returning tree ensures that ContainerRuntime.snapshot() would regenerate subtrees for\n // each unchanged data store.\n // If we want to change that, we would need to capture docId on first call and return this.latestWriterTree\n // when latest is requested.\n if (this.latestWriterTree && (this.docId === versionId || versionId === null)) {\n return [{ id: \"latest\", treeId: FileStorageVersionTreeId }];\n }\n\n if (this.docId === undefined && versionId !== null) {\n this.docId = versionId;\n }\n\n if (versionId !== null && this.commitsWriter[versionId] !== undefined) {\n // PrefetchDocumentStorageService likes to prefetch everything!\n // Skip, as Container does not really need it.\n throw new Error(\"Not supporting commit loading\");\n // Return [{id: versionId, treeId: FileStorageVersionTreeId}];\n }\n return super.getVersions(versionId, count);\n }\n\n public async getSnapshotTree(version?: api.IVersion): Promise<api.ISnapshotTree | null> {\n if (this.latestWriterTree && (!version || version.id === \"latest\")) {\n return this.latestWriterTree;\n }\n if (version && this.commitsWriter[version.id] !== undefined) {\n return buildSnapshotTree(this.commitsWriter[version.id].entries, this.blobsWriter);\n }\n return super.getSnapshotTree(version);\n }\n\n public async write(\n tree: api.ITree,\n parents: string[],\n message: string,\n ref: string): Promise<api.IVersion> {\n let dataStoreName = ref ? ref : \"container\";\n if (tree && tree.entries) {\n tree.entries.forEach((entry) => {\n if (entry.path === \".component\" && entry.type === api.TreeEntry.Blob) {\n const blob: api.IBlob = entry.value;\n const content = blob.contents.split(\":\");\n if (content[0] === `{\"pkg\"`) {\n dataStoreName = content[1].substring(1, content[1].lastIndexOf(`\"`));\n }\n }\n });\n }\n\n const commitName = `commit_${dataStoreName}`;\n\n // Sort entries for easier diffing\n this.sortTree(tree);\n\n // Remove tree IDs for easier comparison of snapshots\n delete tree.id;\n removeNullTreeIds(tree);\n\n if (ref) {\n this.commitsWriter[commitName] = tree;\n } else {\n // Rebuild latest tree - runtime will ask for it when generating next snapshot to write out\n // non-changed commits for data stores\n await this.writeOutFullSnapshot(tree);\n\n // Prep for the future - refresh latest tree, as it's requests on next snapshot generation.\n // Do not care about blobs (at least for now), as blobs are not written out (need follow up)\n this.latestWriterTree = buildSnapshotTree(tree.entries, this.blobsWriter);\n\n // Do not reset this.commitsWriter - runtime will reference same commits in future snapshots\n // if data store did not change in between two snapshots.\n // We can optimize here by filtering commits based on contents of this.docTree.commits\n }\n\n this.onCommitHandler(dataStoreName, tree);\n return {\n id: commitName,\n date: new Date().toUTCString(),\n treeId: FileStorageVersionTreeIdUnused,\n };\n }\n\n public async writeOutFullSnapshot(tree: api.ITree) {\n const commits: { [key: string]: api.ITree } = {};\n\n // Sort keys. This does not guarantees that JSON.stringify() would produce sorted result,\n // but in practice it does.\n const commitsSorted: { [key: string]: api.ITree } = {};\n for (const key of Object.keys(commits).sort()) {\n commitsSorted[key] = commits[key];\n }\n\n const fileSnapshot: IFileSnapshot = { tree, commits: commitsSorted };\n this.onSnapshotHandler(fileSnapshot);\n }\n\n public sortTree(tree: api.ITree) {\n tree.entries.sort((a, b) => a.path.localeCompare(b.path));\n tree.entries.map((entry) => {\n if (entry.type === api.TreeEntry.Tree) {\n this.sortTree(entry.value);\n }\n });\n }\n\n public async buildTree(snapshotTree: api.ISnapshotTree): Promise<api.ITree> {\n const tree: api.ITree = { entries: [] };\n\n for (const subTreeId of Object.keys(snapshotTree.trees)) {\n const subTree = await this.buildTree(snapshotTree.trees[subTreeId]);\n tree.entries.push({\n mode: api.FileMode.Directory,\n path: subTreeId,\n type: api.TreeEntry.Tree,\n value: subTree,\n });\n }\n\n for (const blobName of Object.keys(snapshotTree.blobs)) {\n const buffer = await this.readBlob(snapshotTree.blobs[blobName]);\n const contents = bufferToString(buffer, \"utf8\");\n const blob: api.IBlob = {\n contents,\n encoding: \"utf-8\",\n };\n tree.entries.push({\n mode: api.FileMode.File,\n path: blobName,\n type: api.TreeEntry.Blob,\n value: blob,\n });\n }\n\n assert(Object.keys(snapshotTree.commits).length === 0,\n 0x095 /* \"Leftover distinct commits after building tree!\" */);\n return tree;\n }\n };\n\nfunction removeNullTreeIds(tree: api.ITree) {\n for (const node of tree.entries) {\n if (node.type === api.TreeEntry.Tree) {\n removeNullTreeIds(node.value);\n }\n }\n assert(tree.id === undefined || tree.id === null,\n 0x096 /* \"Trying to remove valid tree IDs in removeNullTreeIds()!\" */);\n delete tree.id;\n}\n\nexport const FluidFetchReaderFileSnapshotWriter = FileSnapshotWriterClassFactory(FluidFetchReader);\n"]}
|
|
1
|
+
{"version":3,"file":"fileDocumentStorageService.js","sourceRoot":"","sources":["../src/fileDocumentStorageService.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,4CAAoB;AACpB,+DAAsE;AAMtE,+DAAoG;AACpG,0EAA4D;AAC5D,iEAA8F;AAE9F,iDAAiD;AACjD,gFAAgF;AACnE,QAAA,uBAAuB,GAAG,kBAAkB,CAAC,CAAC,4BAA4B;AAEvF,8FAA8F;AAC9F,MAAM,wBAAwB,GAAG,mBAAmB,CAAC;AAErD;;GAEG;AACH,MAAa,gBAAiB,SAAQ,8CAA8B;IAGhE,YAA6B,IAAY,EAAmB,WAAoB;QAC5E,KAAK,EAAE,CAAC;QADiB,SAAI,GAAJ,IAAI,CAAQ;QAAmB,gBAAW,GAAX,WAAW,CAAS;QAFtE,YAAO,GAA6B,IAAI,CAAC;IAInD,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,eAAe,CAAC,OAAsB;QAC/C,qBAAM,CAAC,OAAO,KAAK,IAAI,EAAE,KAAK,CAAC,wDAAwD,CAAC,CAAC;QACzF,qBAAM,CAAC,CAAC,OAAO,IAAI,OAAO,CAAC,MAAM,KAAK,wBAAwB,EAC1D,KAAK,CAAC,wDAAwD,CAAC,CAAC;QAEpE,IAAI,QAAgB,CAAC;QACrB,IAAI,QAAQ,GAAG,KAAK,CAAC;QACrB,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,EAAE,KAAK,QAAQ,EAAE;YACr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,CAAC,EACjD,KAAK,CAAC,sDAAsD,CAAC,CAAC;QAClE,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ,CAAC;AA/FO,QAAA,8BAA8B,kCA+FrC;AAEN,SAAS,iBAAiB,CAAC,IAAe;IACtC,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,OAAO,EAAE;QAC7B,IAAI,IAAI,CAAC,IAAI,KAAK,GAAG,CAAC,SAAS,CAAC,IAAI,EAAE;YAClC,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SACjC;KACJ;IACD,qBAAM,CAAC,IAAI,CAAC,EAAE,KAAK,SAAS,IAAI,IAAI,CAAC,EAAE,KAAK,IAAI,EAC5C,KAAK,CAAC,+DAA+D,CAAC,CAAC;IAC3E,OAAO,IAAI,CAAC,EAAE,CAAC;AACnB,CAAC;AACY,QAAA,kCAAkC,GAAG,sCAA8B,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\";\nimport { assert, bufferToString } from \"@fluidframework/common-utils\";\nimport {\n IDocumentStorageService,\n IDocumentStorageServicePolicies, // these are needed for api-extractor\n ISummaryContext, // these are needed for api-extractor\n} from \"@fluidframework/driver-definitions\";\nimport { buildSnapshotTree, convertSummaryTreeToSnapshotITree } from \"@fluidframework/driver-utils\";\nimport * as api from \"@fluidframework/protocol-definitions\";\nimport { IFileSnapshot, ReadDocumentStorageServiceBase } from \"@fluidframework/replay-driver\";\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.\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 */\nexport class FluidFetchReader extends ReadDocumentStorageServiceBase implements IDocumentStorageService {\n protected docTree: api.ISnapshotTree | null = null;\n\n constructor(private readonly path: string, private readonly versionName?: string) {\n super();\n }\n\n /**\n * Read the file and returns the snapshot tree.\n * @param version - The version contains the path of the file which contains the snapshot tree.\n */\n public async getSnapshotTree(version?: api.IVersion): Promise<api.ISnapshotTree | null> {\n assert(version !== null, 0x092 /* \"version input for reading snapshot tree is null!\" */);\n assert(!version || version.treeId === FileStorageVersionTreeId,\n 0x093 /* \"invalid version input for reading snapshot tree!\" */);\n\n let filename: string;\n let rootTree = false;\n if (!version || version.id === \"latest\") {\n if (this.docTree) {\n return this.docTree;\n }\n if (this.versionName === undefined) {\n return null;\n }\n rootTree = true;\n filename = `${this.path}/${this.versionName}/tree.json`;\n } else {\n filename = `${this.path}/${this.versionName}/${version.id}.json`;\n }\n\n if (!fs.existsSync(filename)) {\n throw new Error(`Can't find file ${filename}`);\n }\n const data = fs.readFileSync(filename);\n const tree = JSON.parse(data.toString(\"utf-8\"));\n if (rootTree) {\n this.docTree = tree;\n }\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return tree;\n }\n\n /**\n * Gets the path of the snapshot tree to be read.\n * @param versionId - version ID.\n * @param count - Number of versions to be returned.\n */\n public async getVersions(versionId: string | null, count: number): Promise<api.IVersion[]> {\n if (versionId === FileStorageDocumentName || versionId === null) {\n if (this.docTree || this.versionName !== undefined) {\n return [{ id: \"latest\", treeId: FileStorageVersionTreeId }];\n }\n // Started with ops - return empty set.\n return [];\n } else if (this.versionName !== undefined) {\n assert(!!this.docTree, 0x094 /* \"Missing snapshot tree!\" */);\n return [{\n id: versionId,\n treeId: FileStorageVersionTreeId,\n }];\n }\n throw new Error(`Unknown version: ${versionId}`);\n }\n\n public async readBlob(sha: string): Promise<ArrayBufferLike> {\n if (this.versionName !== undefined) {\n const fileName = `${this.path}/${this.versionName}/${sha}`;\n if (fs.existsSync(fileName)) {\n const data = fs.readFileSync(fileName);\n return data;\n }\n }\n throw new Error(`Can't find blob ${sha}`);\n }\n}\n\nexport interface ISnapshotWriterStorage extends IDocumentStorageService {\n onSnapshotHandler(snapshot: IFileSnapshot): void;\n reset(): void;\n}\n\nexport type ReaderConstructor = new (...args: any[]) => IDocumentStorageService;\nexport const FileSnapshotWriterClassFactory = <TBase extends ReaderConstructor>(Base: TBase) =>\n class extends Base implements ISnapshotWriterStorage {\n // Note: if variable name has same name as in base class, it overrides it!\n public blobsWriter = new Map<string, ArrayBufferLike>();\n public latestWriterTree?: api.ISnapshotTree;\n public docId?: string;\n\n public reset() {\n this.blobsWriter = new Map<string, ArrayBufferLike>();\n this.latestWriterTree = undefined;\n this.docId = undefined;\n }\n\n public onSnapshotHandler(snapshot: IFileSnapshot): void {\n throw new Error(\"onSnapshotHandler is not setup! Please provide your handler!\");\n }\n\n public async readBlob(sha: string): Promise<ArrayBufferLike> {\n const blob = this.blobsWriter.get(sha);\n if (blob !== undefined) {\n return blob;\n }\n return super.readBlob(sha);\n }\n\n public async getVersions(versionId: string | null, count: number): Promise<api.IVersion[]> {\n // If we already saved document, that means we are getting here because of snapshot generation.\n // Not returning tree ensures that ContainerRuntime.snapshot() would regenerate subtrees for\n // each unchanged data store.\n // If we want to change that, we would need to capture docId on first call and return this.latestWriterTree\n // when latest is requested.\n if (this.latestWriterTree && (this.docId === versionId || versionId === null)) {\n return [{ id: \"latest\", treeId: FileStorageVersionTreeId }];\n }\n\n if (this.docId === undefined && versionId !== null) {\n this.docId = versionId;\n }\n\n return super.getVersions(versionId, count);\n }\n\n public async getSnapshotTree(version?: api.IVersion): Promise<api.ISnapshotTree | null> {\n if (this.latestWriterTree && (!version || version.id === \"latest\")) {\n return this.latestWriterTree;\n }\n return super.getSnapshotTree(version);\n }\n\n public async uploadSummaryWithContext(summary: api.ISummaryTree, context: ISummaryContext): Promise<string> {\n const tree = convertSummaryTreeToSnapshotITree(summary);\n\n // Remove tree IDs for easier comparison of snapshots\n delete tree.id;\n removeNullTreeIds(tree);\n\n this.latestWriterTree = buildSnapshotTree(tree.entries, this.blobsWriter);\n\n const fileSnapshot: IFileSnapshot = { tree, commits: {} };\n this.onSnapshotHandler(fileSnapshot);\n return \"testHandleId\";\n }\n\n public async buildTree(snapshotTree: api.ISnapshotTree): Promise<api.ITree> {\n const tree: api.ITree = { entries: [] };\n\n for (const subTreeId of Object.keys(snapshotTree.trees)) {\n const subTree = await this.buildTree(snapshotTree.trees[subTreeId]);\n tree.entries.push({\n mode: api.FileMode.Directory,\n path: subTreeId,\n type: api.TreeEntry.Tree,\n value: subTree,\n });\n }\n\n for (const blobName of Object.keys(snapshotTree.blobs)) {\n const buffer = await this.readBlob(snapshotTree.blobs[blobName]);\n const contents = bufferToString(buffer, \"utf8\");\n const blob: api.IBlob = {\n contents,\n encoding: \"utf-8\",\n };\n tree.entries.push({\n mode: api.FileMode.File,\n path: blobName,\n type: api.TreeEntry.Blob,\n value: blob,\n });\n }\n\n assert(Object.keys(snapshotTree.commits).length === 0,\n 0x095 /* \"Leftover distinct commits after building tree!\" */);\n return tree;\n }\n };\n\nfunction removeNullTreeIds(tree: api.ITree) {\n for (const node of tree.entries) {\n if (node.type === api.TreeEntry.Tree) {\n removeNullTreeIds(node.value);\n }\n }\n assert(tree.id === undefined || tree.id === null,\n 0x096 /* \"Trying to remove valid tree IDs in removeNullTreeIds()!\" */);\n delete tree.id;\n}\nexport const FluidFetchReaderFileSnapshotWriter = FileSnapshotWriterClassFactory(FluidFetchReader);\n"]}
|
package/dist/packageVersion.d.ts
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
|
|
6
6
|
*/
|
|
7
7
|
export declare const pkgName = "@fluidframework/file-driver";
|
|
8
|
-
export declare const pkgVersion = "0.
|
|
8
|
+
export declare const pkgVersion = "0.57.0";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
package/dist/packageVersion.js
CHANGED
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.pkgVersion = exports.pkgName = void 0;
|
|
10
10
|
exports.pkgName = "@fluidframework/file-driver";
|
|
11
|
-
exports.pkgVersion = "0.
|
|
11
|
+
exports.pkgVersion = "0.57.0";
|
|
12
12
|
//# sourceMappingURL=packageVersion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,6BAA6B,CAAC;AACxC,QAAA,UAAU,GAAG,QAAQ,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/file-driver\";\nexport const pkgVersion = \"0.
|
|
1
|
+
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,6BAA6B,CAAC;AACxC,QAAA,UAAU,GAAG,QAAQ,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/file-driver\";\nexport const pkgVersion = \"0.57.0\";\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluidframework/file-driver",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.57.0",
|
|
4
4
|
"description": "A driver that reads/write from/to local file storage.",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": "https://github.com/microsoft/FluidFramework",
|
|
@@ -31,13 +31,13 @@
|
|
|
31
31
|
"@fluidframework/common-definitions": "^0.20.1",
|
|
32
32
|
"@fluidframework/common-utils": "^0.32.1",
|
|
33
33
|
"@fluidframework/driver-definitions": "^0.44.0",
|
|
34
|
-
"@fluidframework/driver-utils": "^0.
|
|
34
|
+
"@fluidframework/driver-utils": "^0.57.0",
|
|
35
35
|
"@fluidframework/protocol-definitions": "^0.1026.0",
|
|
36
|
-
"@fluidframework/replay-driver": "^0.
|
|
36
|
+
"@fluidframework/replay-driver": "^0.57.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@fluidframework/build-common": "^0.23.0",
|
|
40
|
-
"@fluidframework/eslint-config-fluid": "^0.
|
|
40
|
+
"@fluidframework/eslint-config-fluid": "^0.26.0",
|
|
41
41
|
"@microsoft/api-extractor": "^7.16.1",
|
|
42
42
|
"@rushstack/eslint-config": "^2.5.1",
|
|
43
43
|
"@types/node": "^14.18.0",
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
IDocumentStorageServicePolicies, // these are needed for api-extractor
|
|
11
11
|
ISummaryContext, // these are needed for api-extractor
|
|
12
12
|
} from "@fluidframework/driver-definitions";
|
|
13
|
-
import { buildSnapshotTree } from "@fluidframework/driver-utils";
|
|
13
|
+
import { buildSnapshotTree, convertSummaryTreeToSnapshotITree } from "@fluidframework/driver-utils";
|
|
14
14
|
import * as api from "@fluidframework/protocol-definitions";
|
|
15
15
|
import { IFileSnapshot, ReadDocumentStorageServiceBase } from "@fluidframework/replay-driver";
|
|
16
16
|
|
|
@@ -21,9 +21,6 @@ export const FileStorageDocumentName = "FileStorageDocId"; // Some unique docume
|
|
|
21
21
|
// Tree ID use to communicate between getVersions() & getSnapshotTree() that IVersion is ours.
|
|
22
22
|
const FileStorageVersionTreeId = "FileStorageTreeId";
|
|
23
23
|
|
|
24
|
-
// This ID should not show up anywhere, as it's internal only ID that no public API should accept.
|
|
25
|
-
const FileStorageVersionTreeIdUnused = "baad";
|
|
26
|
-
|
|
27
24
|
/**
|
|
28
25
|
* Document storage service for the file driver.
|
|
29
26
|
*/
|
|
@@ -66,7 +63,6 @@ export class FluidFetchReader extends ReadDocumentStorageServiceBase implements
|
|
|
66
63
|
if (rootTree) {
|
|
67
64
|
this.docTree = tree;
|
|
68
65
|
}
|
|
69
|
-
// Fill in this.commit right here?
|
|
70
66
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
71
67
|
return tree;
|
|
72
68
|
}
|
|
@@ -84,7 +80,6 @@ export class FluidFetchReader extends ReadDocumentStorageServiceBase implements
|
|
|
84
80
|
// Started with ops - return empty set.
|
|
85
81
|
return [];
|
|
86
82
|
} else if (this.versionName !== undefined) {
|
|
87
|
-
// We loaded from snapshot - search for commit there.
|
|
88
83
|
assert(!!this.docTree, 0x094 /* "Missing snapshot tree!" */);
|
|
89
84
|
return [{
|
|
90
85
|
id: versionId,
|
|
@@ -107,7 +102,6 @@ export class FluidFetchReader extends ReadDocumentStorageServiceBase implements
|
|
|
107
102
|
}
|
|
108
103
|
|
|
109
104
|
export interface ISnapshotWriterStorage extends IDocumentStorageService {
|
|
110
|
-
onCommitHandler(dataStoreName: string, tree: api.ITree): void;
|
|
111
105
|
onSnapshotHandler(snapshot: IFileSnapshot): void;
|
|
112
106
|
reset(): void;
|
|
113
107
|
}
|
|
@@ -117,20 +111,15 @@ export const FileSnapshotWriterClassFactory = <TBase extends ReaderConstructor>(
|
|
|
117
111
|
class extends Base implements ISnapshotWriterStorage {
|
|
118
112
|
// Note: if variable name has same name as in base class, it overrides it!
|
|
119
113
|
public blobsWriter = new Map<string, ArrayBufferLike>();
|
|
120
|
-
public commitsWriter: { [key: string]: api.ITree } = {};
|
|
121
114
|
public latestWriterTree?: api.ISnapshotTree;
|
|
122
115
|
public docId?: string;
|
|
123
116
|
|
|
124
117
|
public reset() {
|
|
125
118
|
this.blobsWriter = new Map<string, ArrayBufferLike>();
|
|
126
|
-
this.commitsWriter = {};
|
|
127
119
|
this.latestWriterTree = undefined;
|
|
128
120
|
this.docId = undefined;
|
|
129
121
|
}
|
|
130
122
|
|
|
131
|
-
public onCommitHandler(dataStoreName: string, tree: api.ITree): void {
|
|
132
|
-
}
|
|
133
|
-
|
|
134
123
|
public onSnapshotHandler(snapshot: IFileSnapshot): void {
|
|
135
124
|
throw new Error("onSnapshotHandler is not setup! Please provide your handler!");
|
|
136
125
|
}
|
|
@@ -157,12 +146,6 @@ export const FileSnapshotWriterClassFactory = <TBase extends ReaderConstructor>(
|
|
|
157
146
|
this.docId = versionId;
|
|
158
147
|
}
|
|
159
148
|
|
|
160
|
-
if (versionId !== null && this.commitsWriter[versionId] !== undefined) {
|
|
161
|
-
// PrefetchDocumentStorageService likes to prefetch everything!
|
|
162
|
-
// Skip, as Container does not really need it.
|
|
163
|
-
throw new Error("Not supporting commit loading");
|
|
164
|
-
// Return [{id: versionId, treeId: FileStorageVersionTreeId}];
|
|
165
|
-
}
|
|
166
149
|
return super.getVersions(versionId, count);
|
|
167
150
|
}
|
|
168
151
|
|
|
@@ -170,84 +153,21 @@ export const FileSnapshotWriterClassFactory = <TBase extends ReaderConstructor>(
|
|
|
170
153
|
if (this.latestWriterTree && (!version || version.id === "latest")) {
|
|
171
154
|
return this.latestWriterTree;
|
|
172
155
|
}
|
|
173
|
-
if (version && this.commitsWriter[version.id] !== undefined) {
|
|
174
|
-
return buildSnapshotTree(this.commitsWriter[version.id].entries, this.blobsWriter);
|
|
175
|
-
}
|
|
176
156
|
return super.getSnapshotTree(version);
|
|
177
157
|
}
|
|
178
158
|
|
|
179
|
-
public async
|
|
180
|
-
tree
|
|
181
|
-
parents: string[],
|
|
182
|
-
message: string,
|
|
183
|
-
ref: string): Promise<api.IVersion> {
|
|
184
|
-
let dataStoreName = ref ? ref : "container";
|
|
185
|
-
if (tree && tree.entries) {
|
|
186
|
-
tree.entries.forEach((entry) => {
|
|
187
|
-
if (entry.path === ".component" && entry.type === api.TreeEntry.Blob) {
|
|
188
|
-
const blob: api.IBlob = entry.value;
|
|
189
|
-
const content = blob.contents.split(":");
|
|
190
|
-
if (content[0] === `{"pkg"`) {
|
|
191
|
-
dataStoreName = content[1].substring(1, content[1].lastIndexOf(`"`));
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
const commitName = `commit_${dataStoreName}`;
|
|
198
|
-
|
|
199
|
-
// Sort entries for easier diffing
|
|
200
|
-
this.sortTree(tree);
|
|
159
|
+
public async uploadSummaryWithContext(summary: api.ISummaryTree, context: ISummaryContext): Promise<string> {
|
|
160
|
+
const tree = convertSummaryTreeToSnapshotITree(summary);
|
|
201
161
|
|
|
202
162
|
// Remove tree IDs for easier comparison of snapshots
|
|
203
163
|
delete tree.id;
|
|
204
164
|
removeNullTreeIds(tree);
|
|
205
165
|
|
|
206
|
-
|
|
207
|
-
this.commitsWriter[commitName] = tree;
|
|
208
|
-
} else {
|
|
209
|
-
// Rebuild latest tree - runtime will ask for it when generating next snapshot to write out
|
|
210
|
-
// non-changed commits for data stores
|
|
211
|
-
await this.writeOutFullSnapshot(tree);
|
|
212
|
-
|
|
213
|
-
// Prep for the future - refresh latest tree, as it's requests on next snapshot generation.
|
|
214
|
-
// Do not care about blobs (at least for now), as blobs are not written out (need follow up)
|
|
215
|
-
this.latestWriterTree = buildSnapshotTree(tree.entries, this.blobsWriter);
|
|
166
|
+
this.latestWriterTree = buildSnapshotTree(tree.entries, this.blobsWriter);
|
|
216
167
|
|
|
217
|
-
|
|
218
|
-
// if data store did not change in between two snapshots.
|
|
219
|
-
// We can optimize here by filtering commits based on contents of this.docTree.commits
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
this.onCommitHandler(dataStoreName, tree);
|
|
223
|
-
return {
|
|
224
|
-
id: commitName,
|
|
225
|
-
date: new Date().toUTCString(),
|
|
226
|
-
treeId: FileStorageVersionTreeIdUnused,
|
|
227
|
-
};
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
public async writeOutFullSnapshot(tree: api.ITree) {
|
|
231
|
-
const commits: { [key: string]: api.ITree } = {};
|
|
232
|
-
|
|
233
|
-
// Sort keys. This does not guarantees that JSON.stringify() would produce sorted result,
|
|
234
|
-
// but in practice it does.
|
|
235
|
-
const commitsSorted: { [key: string]: api.ITree } = {};
|
|
236
|
-
for (const key of Object.keys(commits).sort()) {
|
|
237
|
-
commitsSorted[key] = commits[key];
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
const fileSnapshot: IFileSnapshot = { tree, commits: commitsSorted };
|
|
168
|
+
const fileSnapshot: IFileSnapshot = { tree, commits: {} };
|
|
241
169
|
this.onSnapshotHandler(fileSnapshot);
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
public sortTree(tree: api.ITree) {
|
|
245
|
-
tree.entries.sort((a, b) => a.path.localeCompare(b.path));
|
|
246
|
-
tree.entries.map((entry) => {
|
|
247
|
-
if (entry.type === api.TreeEntry.Tree) {
|
|
248
|
-
this.sortTree(entry.value);
|
|
249
|
-
}
|
|
250
|
-
});
|
|
170
|
+
return "testHandleId";
|
|
251
171
|
}
|
|
252
172
|
|
|
253
173
|
public async buildTree(snapshotTree: api.ISnapshotTree): Promise<api.ITree> {
|
|
@@ -294,5 +214,4 @@ function removeNullTreeIds(tree: api.ITree) {
|
|
|
294
214
|
0x096 /* "Trying to remove valid tree IDs in removeNullTreeIds()!" */);
|
|
295
215
|
delete tree.id;
|
|
296
216
|
}
|
|
297
|
-
|
|
298
217
|
export const FluidFetchReaderFileSnapshotWriter = FileSnapshotWriterClassFactory(FluidFetchReader);
|
package/src/packageVersion.ts
CHANGED