@fluidframework/local-driver 2.0.0-dev.1.4.5.105745 → 2.0.0-dev.2.2.0.111723
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/.eslintrc.js +23 -9
- package/dist/index.d.ts +7 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -16
- package/dist/index.js.map +1 -1
- package/dist/localDeltaStorageService.d.ts +3 -3
- package/dist/localDeltaStorageService.d.ts.map +1 -1
- package/dist/localDeltaStorageService.js.map +1 -1
- package/dist/localDocumentDeltaConnection.d.ts +2 -2
- package/dist/localDocumentDeltaConnection.d.ts.map +1 -1
- package/dist/localDocumentDeltaConnection.js +2 -2
- package/dist/localDocumentDeltaConnection.js.map +1 -1
- package/dist/localDocumentService.d.ts +10 -10
- package/dist/localDocumentService.d.ts.map +1 -1
- package/dist/localDocumentService.js +1 -23
- package/dist/localDocumentService.js.map +1 -1
- package/dist/localDocumentServiceFactory.d.ts.map +1 -1
- package/dist/localDocumentServiceFactory.js +8 -8
- package/dist/localDocumentServiceFactory.js.map +1 -1
- package/dist/localDocumentStorageService.d.ts +24 -0
- package/dist/localDocumentStorageService.d.ts.map +1 -0
- package/dist/localDocumentStorageService.js +75 -0
- package/dist/localDocumentStorageService.js.map +1 -0
- package/dist/localSessionStorageDb.d.ts +0 -1
- package/dist/localSessionStorageDb.d.ts.map +1 -1
- package/dist/localSessionStorageDb.js +15 -13
- package/dist/localSessionStorageDb.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 +28 -21
- package/prettier.config.cjs +8 -0
- package/src/index.ts +7 -6
- package/src/localDeltaStorageService.ts +6 -3
- package/src/localDocumentDeltaConnection.ts +3 -3
- package/src/localDocumentService.ts +24 -23
- package/src/localDocumentServiceFactory.ts +7 -6
- package/src/localDocumentStorageService.ts +107 -0
- package/src/localSessionStorageDb.ts +11 -17
- package/src/packageVersion.ts +1 -1
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { stringToBuffer, Uint8ArrayToString } from "@fluidframework/common-utils";
|
|
7
|
+
import {
|
|
8
|
+
IDocumentStorageService,
|
|
9
|
+
IDocumentStorageServicePolicies,
|
|
10
|
+
ISummaryContext,
|
|
11
|
+
} from "@fluidframework/driver-definitions";
|
|
12
|
+
import {
|
|
13
|
+
ICreateBlobResponse,
|
|
14
|
+
ISnapshotTreeEx,
|
|
15
|
+
ISummaryHandle,
|
|
16
|
+
ISummaryTree,
|
|
17
|
+
IVersion,
|
|
18
|
+
} from "@fluidframework/protocol-definitions";
|
|
19
|
+
import { buildHierarchy } from "@fluidframework/protocol-base";
|
|
20
|
+
import { GitManager, ISummaryUploadManager, SummaryTreeUploadManager } from "@fluidframework/server-services-client";
|
|
21
|
+
|
|
22
|
+
export class LocalDocumentStorageService implements IDocumentStorageService {
|
|
23
|
+
// The values of this cache is useless. We only need the keys. So we are always putting
|
|
24
|
+
// empty strings as values.
|
|
25
|
+
protected readonly blobsShaCache = new Map<string, string>();
|
|
26
|
+
private readonly summaryTreeUploadManager: ISummaryUploadManager;
|
|
27
|
+
|
|
28
|
+
public get repositoryUrl(): string {
|
|
29
|
+
return "";
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
constructor(
|
|
33
|
+
private readonly id: string,
|
|
34
|
+
private readonly manager: GitManager,
|
|
35
|
+
public readonly policies: IDocumentStorageServicePolicies = {},
|
|
36
|
+
) {
|
|
37
|
+
this.summaryTreeUploadManager = new SummaryTreeUploadManager(
|
|
38
|
+
manager,
|
|
39
|
+
this.blobsShaCache,
|
|
40
|
+
this.getPreviousFullSnapshot.bind(this),
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public async getVersions(versionId: string | null, count: number): Promise<IVersion[]> {
|
|
45
|
+
const id = versionId ? versionId : this.id;
|
|
46
|
+
const commits = await this.manager.getCommits(id, count);
|
|
47
|
+
return commits.map((commit) => ({
|
|
48
|
+
date: commit.commit.author.date,
|
|
49
|
+
id: commit.sha,
|
|
50
|
+
treeId: commit.commit.tree.sha,
|
|
51
|
+
}));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public async getSnapshotTree(version?: IVersion): Promise<ISnapshotTreeEx | null> {
|
|
55
|
+
let requestVersion = version;
|
|
56
|
+
if (!requestVersion) {
|
|
57
|
+
const versions = await this.getVersions(this.id, 1);
|
|
58
|
+
if (versions.length === 0) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
requestVersion = versions[0];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const rawTree = await this.manager.getTree(requestVersion.treeId);
|
|
66
|
+
const tree = buildHierarchy(rawTree, this.blobsShaCache, true);
|
|
67
|
+
return tree;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
public async readBlob(blobId: string): Promise<ArrayBufferLike> {
|
|
71
|
+
const blob = await this.manager.getBlob(blobId);
|
|
72
|
+
this.blobsShaCache.set(blob.sha, "");
|
|
73
|
+
const bufferContent = stringToBuffer(blob.content, blob.encoding);
|
|
74
|
+
return bufferContent;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public async uploadSummaryWithContext(summary: ISummaryTree, context: ISummaryContext): Promise<string> {
|
|
78
|
+
return this.summaryTreeUploadManager.writeSummaryTree(
|
|
79
|
+
summary,
|
|
80
|
+
context.ackHandle ?? "",
|
|
81
|
+
"channel",
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
public async createBlob(file: ArrayBufferLike): Promise<ICreateBlobResponse> {
|
|
86
|
+
const uint8ArrayFile = new Uint8Array(file);
|
|
87
|
+
return this.manager.createBlob(
|
|
88
|
+
Uint8ArrayToString(
|
|
89
|
+
uint8ArrayFile, "base64"),
|
|
90
|
+
"base64").then((r) => ({ id: r.sha, url: r.url }));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
public async downloadSummary(handle: ISummaryHandle): Promise<ISummaryTree> {
|
|
94
|
+
throw new Error("NOT IMPLEMENTED!");
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
private async getPreviousFullSnapshot(parentHandle: string): Promise<ISnapshotTreeEx | null | undefined> {
|
|
98
|
+
return parentHandle
|
|
99
|
+
? this.getVersions(parentHandle, 1)
|
|
100
|
+
.then(async (versions) => {
|
|
101
|
+
// Clear the cache as the getSnapshotTree call will fill the cache.
|
|
102
|
+
this.blobsShaCache.clear();
|
|
103
|
+
return this.getSnapshotTree(versions[0]);
|
|
104
|
+
})
|
|
105
|
+
: undefined;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -12,10 +12,10 @@ import { v4 as uuid } from "uuid";
|
|
|
12
12
|
* Functions include database operations such as queries, insertion and update.
|
|
13
13
|
*/
|
|
14
14
|
class LocalSessionStorageCollection<T> implements ICollection<T> {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
15
|
+
/**
|
|
16
|
+
* @param collectionName - data type of the collection, e.g. blobs, deltas, trees, etc.
|
|
17
|
+
*/
|
|
18
|
+
constructor(private readonly collectionName: string) { }
|
|
19
19
|
|
|
20
20
|
public aggregate(pipeline: any, options?: any): any {
|
|
21
21
|
throw new Error("Method Not Implemented");
|
|
@@ -88,7 +88,8 @@ class LocalSessionStorageCollection<T> implements ICollection<T> {
|
|
|
88
88
|
* {@inheritDoc @fluidframework/server-services-core#ICollection.findAll}
|
|
89
89
|
*/
|
|
90
90
|
public async findAll(): Promise<any[]> {
|
|
91
|
-
return
|
|
91
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
92
|
+
return this.getAllInternal();
|
|
92
93
|
}
|
|
93
94
|
|
|
94
95
|
/**
|
|
@@ -98,7 +99,8 @@ class LocalSessionStorageCollection<T> implements ICollection<T> {
|
|
|
98
99
|
* Query is expected to have a member "_id" which is a string used to find value in the database.
|
|
99
100
|
*/
|
|
100
101
|
public async findOne(query: any): Promise<any> {
|
|
101
|
-
return
|
|
102
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
103
|
+
return this.findOneInternal(query);
|
|
102
104
|
}
|
|
103
105
|
|
|
104
106
|
/**
|
|
@@ -282,15 +284,10 @@ class LocalSessionStorageCollection<T> implements ICollection<T> {
|
|
|
282
284
|
*/
|
|
283
285
|
class LocalSessionStorageDb extends EventEmitter implements IDb {
|
|
284
286
|
private readonly collections = new Map<string, LocalSessionStorageCollection<any>>();
|
|
285
|
-
|
|
286
|
-
super();
|
|
287
|
-
}
|
|
288
|
-
public async close(): Promise<void> {
|
|
289
|
-
return Promise.resolve();
|
|
290
|
-
}
|
|
287
|
+
public async close(): Promise<void> { }
|
|
291
288
|
public collection<T>(name: string): ICollection<T> {
|
|
292
289
|
if (!this.collections.has(name)) {
|
|
293
|
-
this.collections.set(name, new LocalSessionStorageCollection<T>(
|
|
290
|
+
this.collections.set(name, new LocalSessionStorageCollection<T>(name));
|
|
294
291
|
}
|
|
295
292
|
return this.collections.get(name) as LocalSessionStorageCollection<T>;
|
|
296
293
|
}
|
|
@@ -308,10 +305,7 @@ class LocalSessionStorageDb extends EventEmitter implements IDb {
|
|
|
308
305
|
* A database factory for testing that stores data in the browsers session storage
|
|
309
306
|
*/
|
|
310
307
|
export class LocalSessionStorageDbFactory implements ITestDbFactory {
|
|
311
|
-
public readonly testDatabase: IDb;
|
|
312
|
-
constructor(namespace: string) {
|
|
313
|
-
this.testDatabase = new LocalSessionStorageDb(namespace);
|
|
314
|
-
}
|
|
308
|
+
public readonly testDatabase: IDb = new LocalSessionStorageDb();
|
|
315
309
|
public async connect(): Promise<IDb> {
|
|
316
310
|
return this.testDatabase;
|
|
317
311
|
}
|
package/src/packageVersion.ts
CHANGED