@fluidframework/local-driver 2.0.0-dev.3.1.0.125672 → 2.0.0-dev.4.1.0.148229

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/api-extractor.json +4 -0
  2. package/dist/localCreateDocument.d.ts +8 -0
  3. package/dist/localCreateDocument.d.ts.map +1 -0
  4. package/dist/localCreateDocument.js +29 -0
  5. package/dist/localCreateDocument.js.map +1 -0
  6. package/dist/localDocumentService.d.ts.map +1 -1
  7. package/dist/localDocumentService.js +1 -1
  8. package/dist/localDocumentService.js.map +1 -1
  9. package/dist/localDocumentServiceFactory.d.ts +0 -1
  10. package/dist/localDocumentServiceFactory.d.ts.map +1 -1
  11. package/dist/localDocumentServiceFactory.js +4 -21
  12. package/dist/localDocumentServiceFactory.js.map +1 -1
  13. package/dist/localDocumentStorageService.d.ts +5 -2
  14. package/dist/localDocumentStorageService.d.ts.map +1 -1
  15. package/dist/localDocumentStorageService.js +14 -1
  16. package/dist/localDocumentStorageService.js.map +1 -1
  17. package/dist/localSessionStorageDb.d.ts.map +1 -1
  18. package/dist/localSessionStorageDb.js +3 -0
  19. package/dist/localSessionStorageDb.js.map +1 -1
  20. package/dist/packageVersion.d.ts +1 -1
  21. package/dist/packageVersion.js +1 -1
  22. package/dist/packageVersion.js.map +1 -1
  23. package/lib/auth.d.ts +12 -0
  24. package/lib/auth.d.ts.map +1 -0
  25. package/lib/auth.js +38 -0
  26. package/lib/auth.js.map +1 -0
  27. package/lib/index.d.ts +12 -0
  28. package/lib/index.d.ts.map +1 -0
  29. package/lib/index.js +12 -0
  30. package/lib/index.js.map +1 -0
  31. package/lib/localCreateDocument.d.ts +8 -0
  32. package/lib/localCreateDocument.d.ts.map +1 -0
  33. package/lib/localCreateDocument.js +25 -0
  34. package/lib/localCreateDocument.js.map +1 -0
  35. package/lib/localDeltaStorageService.d.ts +19 -0
  36. package/lib/localDeltaStorageService.d.ts.map +1 -0
  37. package/lib/localDeltaStorageService.js +31 -0
  38. package/lib/localDeltaStorageService.js.map +1 -0
  39. package/lib/localDocumentDeltaConnection.d.ts +47 -0
  40. package/lib/localDocumentDeltaConnection.d.ts.map +1 -0
  41. package/lib/localDocumentDeltaConnection.js +88 -0
  42. package/lib/localDocumentDeltaConnection.js.map +1 -0
  43. package/lib/localDocumentService.d.ts +52 -0
  44. package/lib/localDocumentService.d.ts.map +1 -0
  45. package/lib/localDocumentService.js +80 -0
  46. package/lib/localDocumentService.js.map +1 -0
  47. package/lib/localDocumentServiceFactory.d.ts +43 -0
  48. package/lib/localDocumentServiceFactory.d.ts.map +1 -0
  49. package/lib/localDocumentServiceFactory.js +81 -0
  50. package/lib/localDocumentServiceFactory.js.map +1 -0
  51. package/lib/localDocumentStorageService.d.ts +27 -0
  52. package/lib/localDocumentStorageService.d.ts.map +1 -0
  53. package/lib/localDocumentStorageService.js +85 -0
  54. package/lib/localDocumentStorageService.js.map +1 -0
  55. package/lib/localResolver.d.ts +26 -0
  56. package/lib/localResolver.d.ts.map +1 -0
  57. package/lib/localResolver.js +70 -0
  58. package/lib/localResolver.js.map +1 -0
  59. package/lib/localSessionStorageDb.d.ts +10 -0
  60. package/lib/localSessionStorageDb.d.ts.map +1 -0
  61. package/lib/localSessionStorageDb.js +295 -0
  62. package/lib/localSessionStorageDb.js.map +1 -0
  63. package/lib/packageVersion.d.ts +9 -0
  64. package/lib/packageVersion.d.ts.map +1 -0
  65. package/lib/packageVersion.js +9 -0
  66. package/lib/packageVersion.js.map +1 -0
  67. package/package.json +57 -49
  68. package/src/localCreateDocument.ts +48 -0
  69. package/src/localDocumentService.ts +2 -0
  70. package/src/localDocumentServiceFactory.ts +6 -43
  71. package/src/localDocumentStorageService.ts +17 -0
  72. package/src/localSessionStorageDb.ts +3 -0
  73. package/src/packageVersion.ts +1 -1
  74. package/tsconfig.esnext.json +7 -0
@@ -0,0 +1,85 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { stringToBuffer, Uint8ArrayToString } from "@fluidframework/common-utils";
6
+ import { buildHierarchy } from "@fluidframework/protocol-base";
7
+ import { SummaryTreeUploadManager, } from "@fluidframework/server-services-client";
8
+ import { ensureFluidResolvedUrl } from "@fluidframework/driver-utils";
9
+ import { createDocument } from "./localCreateDocument";
10
+ export class LocalDocumentStorageService {
11
+ constructor(id, manager, policies, localDeltaConnectionServer, resolvedUrl) {
12
+ this.id = id;
13
+ this.manager = manager;
14
+ this.policies = policies;
15
+ this.localDeltaConnectionServer = localDeltaConnectionServer;
16
+ this.resolvedUrl = resolvedUrl;
17
+ // The values of this cache is useless. We only need the keys. So we are always putting
18
+ // empty strings as values.
19
+ this.blobsShaCache = new Map();
20
+ this.summaryTreeUploadManager = new SummaryTreeUploadManager(manager, this.blobsShaCache, this.getPreviousFullSnapshot.bind(this));
21
+ }
22
+ get repositoryUrl() {
23
+ return "";
24
+ }
25
+ async getVersions(versionId, count) {
26
+ const id = versionId ? versionId : this.id;
27
+ const commits = await this.manager.getCommits(id, count);
28
+ return commits.map((commit) => ({
29
+ date: commit.commit.author.date,
30
+ id: commit.sha,
31
+ treeId: commit.commit.tree.sha,
32
+ }));
33
+ }
34
+ async getSnapshotTree(version) {
35
+ let requestVersion = version;
36
+ if (!requestVersion) {
37
+ const versions = await this.getVersions(this.id, 1);
38
+ if (versions.length === 0) {
39
+ return null;
40
+ }
41
+ requestVersion = versions[0];
42
+ }
43
+ const rawTree = await this.manager.getTree(requestVersion.treeId);
44
+ const tree = buildHierarchy(rawTree, this.blobsShaCache, true);
45
+ return tree;
46
+ }
47
+ async readBlob(blobId) {
48
+ const blob = await this.manager.getBlob(blobId);
49
+ this.blobsShaCache.set(blob.sha, "");
50
+ const bufferContent = stringToBuffer(blob.content, blob.encoding);
51
+ return bufferContent;
52
+ }
53
+ async uploadSummaryWithContext(summary, context) {
54
+ var _a;
55
+ if (context.referenceSequenceNumber === 0) {
56
+ if (this.localDeltaConnectionServer === undefined || this.resolvedUrl === undefined) {
57
+ throw new Error("Insufficient constructor parameters. An ILocalDeltaConnectionServer and IResolvedUrl required");
58
+ }
59
+ ensureFluidResolvedUrl(this.resolvedUrl);
60
+ await createDocument(this.localDeltaConnectionServer, this.resolvedUrl, summary);
61
+ const version = await this.getVersions(this.id, 1);
62
+ return version[0].id;
63
+ }
64
+ return this.summaryTreeUploadManager.writeSummaryTree(summary, (_a = context.ackHandle) !== null && _a !== void 0 ? _a : "", "channel");
65
+ }
66
+ async createBlob(file) {
67
+ const uint8ArrayFile = new Uint8Array(file);
68
+ return this.manager
69
+ .createBlob(Uint8ArrayToString(uint8ArrayFile, "base64"), "base64")
70
+ .then((r) => ({ id: r.sha, url: r.url }));
71
+ }
72
+ async downloadSummary(handle) {
73
+ throw new Error("NOT IMPLEMENTED!");
74
+ }
75
+ async getPreviousFullSnapshot(parentHandle) {
76
+ return parentHandle
77
+ ? this.getVersions(parentHandle, 1).then(async (versions) => {
78
+ // Clear the cache as the getSnapshotTree call will fill the cache.
79
+ this.blobsShaCache.clear();
80
+ return this.getSnapshotTree(versions[0]);
81
+ })
82
+ : undefined;
83
+ }
84
+ }
85
+ //# sourceMappingURL=localDocumentStorageService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localDocumentStorageService.js","sourceRoot":"","sources":["../src/localDocumentStorageService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAclF,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAGN,wBAAwB,GACxB,MAAM,wCAAwC,CAAC;AAEhD,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,MAAM,OAAO,2BAA2B;IAUvC,YACkB,EAAU,EACV,OAAmB,EACpB,QAAyC,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AwB,CAAC,gBAAgB,CACpD,OAAO,EACP,MAAA,OAAO,CAAC,SAAS,mCAAI,EAAE,EACvB,SAAS,CACT,CAAC;IACH,CAAC;IAEM,KAAK,CAAC,UAAU,CAAC,IAAqB;QAC5C,MAAM,cAAc,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC;QAC5C,OAAO,IAAI,CAAC,OAAO;aACjB,UAAU,CAAC,kBAAkB,CAAC,cAAc,EAAE,QAAQ,CAAC,EAAE,QAAQ,CAAC;aAClE,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IAC5C,CAAC;IAEM,KAAK,CAAC,eAAe,CAAC,MAAsB;QAClD,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACrC,CAAC;IAEO,KAAK,CAAC,uBAAuB,CACpC,YAAoB;QAEpB,OAAO,YAAY;YAClB,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE;gBAC1D,mEAAmE;gBACnE,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;gBAC3B,OAAO,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;YACzC,CAAC,CAAC;YACJ,CAAC,CAAC,SAAS,CAAC;IACd,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { stringToBuffer, Uint8ArrayToString } from \"@fluidframework/common-utils\";\nimport {\n\tIDocumentStorageService,\n\tIDocumentStorageServicePolicies,\n\tIResolvedUrl,\n\tISummaryContext,\n} from \"@fluidframework/driver-definitions\";\nimport {\n\tICreateBlobResponse,\n\tISnapshotTreeEx,\n\tISummaryHandle,\n\tISummaryTree,\n\tIVersion,\n} from \"@fluidframework/protocol-definitions\";\nimport { buildHierarchy } from \"@fluidframework/protocol-base\";\nimport {\n\tGitManager,\n\tISummaryUploadManager,\n\tSummaryTreeUploadManager,\n} from \"@fluidframework/server-services-client\";\nimport { ILocalDeltaConnectionServer } from \"@fluidframework/server-local-server\";\nimport { ensureFluidResolvedUrl } from \"@fluidframework/driver-utils\";\nimport { createDocument } from \"./localCreateDocument\";\n\nexport class LocalDocumentStorageService implements IDocumentStorageService {\n\t// The values of this cache is useless. We only need the keys. So we are always putting\n\t// empty strings as values.\n\tprotected readonly blobsShaCache = new Map<string, string>();\n\tprivate readonly summaryTreeUploadManager: ISummaryUploadManager;\n\n\tpublic get repositoryUrl(): string {\n\t\treturn \"\";\n\t}\n\n\tconstructor(\n\t\tprivate readonly id: string,\n\t\tprivate readonly manager: GitManager,\n\t\tpublic readonly policies: IDocumentStorageServicePolicies,\n\t\tprivate readonly localDeltaConnectionServer?: ILocalDeltaConnectionServer,\n\t\tprivate readonly resolvedUrl?: IResolvedUrl,\n\t) {\n\t\tthis.summaryTreeUploadManager = new SummaryTreeUploadManager(\n\t\t\tmanager,\n\t\t\tthis.blobsShaCache,\n\t\t\tthis.getPreviousFullSnapshot.bind(this),\n\t\t);\n\t}\n\n\tpublic async getVersions(versionId: string | null, count: number): Promise<IVersion[]> {\n\t\tconst id = versionId ? versionId : this.id;\n\t\tconst commits = await this.manager.getCommits(id, count);\n\t\treturn commits.map((commit) => ({\n\t\t\tdate: commit.commit.author.date,\n\t\t\tid: commit.sha,\n\t\t\ttreeId: commit.commit.tree.sha,\n\t\t}));\n\t}\n\n\tpublic async getSnapshotTree(version?: IVersion): Promise<ISnapshotTreeEx | null> {\n\t\tlet requestVersion = version;\n\t\tif (!requestVersion) {\n\t\t\tconst versions = await this.getVersions(this.id, 1);\n\t\t\tif (versions.length === 0) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\trequestVersion = versions[0];\n\t\t}\n\n\t\tconst rawTree = await this.manager.getTree(requestVersion.treeId);\n\t\tconst tree = buildHierarchy(rawTree, this.blobsShaCache, true);\n\t\treturn tree;\n\t}\n\n\tpublic async readBlob(blobId: string): Promise<ArrayBufferLike> {\n\t\tconst blob = await this.manager.getBlob(blobId);\n\t\tthis.blobsShaCache.set(blob.sha, \"\");\n\t\tconst bufferContent = stringToBuffer(blob.content, blob.encoding);\n\t\treturn bufferContent;\n\t}\n\n\tpublic async uploadSummaryWithContext(\n\t\tsummary: ISummaryTree,\n\t\tcontext: ISummaryContext,\n\t): Promise<string> {\n\t\tif (context.referenceSequenceNumber === 0) {\n\t\t\tif (this.localDeltaConnectionServer === undefined || this.resolvedUrl === undefined) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"Insufficient constructor parameters. An ILocalDeltaConnectionServer and IResolvedUrl required\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tensureFluidResolvedUrl(this.resolvedUrl);\n\t\t\tawait createDocument(this.localDeltaConnectionServer, this.resolvedUrl, summary);\n\t\t\tconst version = await this.getVersions(this.id, 1);\n\t\t\treturn version[0].id;\n\t\t}\n\t\treturn this.summaryTreeUploadManager.writeSummaryTree(\n\t\t\tsummary,\n\t\t\tcontext.ackHandle ?? \"\",\n\t\t\t\"channel\",\n\t\t);\n\t}\n\n\tpublic async createBlob(file: ArrayBufferLike): Promise<ICreateBlobResponse> {\n\t\tconst uint8ArrayFile = new Uint8Array(file);\n\t\treturn this.manager\n\t\t\t.createBlob(Uint8ArrayToString(uint8ArrayFile, \"base64\"), \"base64\")\n\t\t\t.then((r) => ({ id: r.sha, url: r.url }));\n\t}\n\n\tpublic async downloadSummary(handle: ISummaryHandle): Promise<ISummaryTree> {\n\t\tthrow new Error(\"NOT IMPLEMENTED!\");\n\t}\n\n\tprivate async getPreviousFullSnapshot(\n\t\tparentHandle: string,\n\t): Promise<ISnapshotTreeEx | null | undefined> {\n\t\treturn parentHandle\n\t\t\t? this.getVersions(parentHandle, 1).then(async (versions) => {\n\t\t\t\t\t// Clear the cache as the getSnapshotTree call will fill the cache.\n\t\t\t\t\tthis.blobsShaCache.clear();\n\t\t\t\t\treturn this.getSnapshotTree(versions[0]);\n\t\t\t })\n\t\t\t: undefined;\n\t}\n}\n"]}
@@ -0,0 +1,26 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { IRequest } from "@fluidframework/core-interfaces";
6
+ import { IResolvedUrl, IUrlResolver } from "@fluidframework/driver-definitions";
7
+ export declare function createLocalResolverCreateNewRequest(documentId: string): IRequest;
8
+ /**
9
+ * Resolves URLs by providing fake URLs which succeed with the other
10
+ * related local classes.
11
+ */
12
+ export declare class LocalResolver implements IUrlResolver {
13
+ private readonly tenantId;
14
+ private readonly tokenKey;
15
+ constructor();
16
+ /**
17
+ * Resolves URL requests by providing fake URLs with an actually generated
18
+ * token from constant test strings. The root of the URL is fake, but the
19
+ * remaining relative URL can still be parsed.
20
+ * @param request - request to handle
21
+ */
22
+ resolve(request: IRequest): Promise<IResolvedUrl>;
23
+ getAbsoluteUrl(resolvedUrl: IResolvedUrl, relativeUrl: string): Promise<string>;
24
+ createCreateNewRequest(documentId: string): IRequest;
25
+ }
26
+ //# sourceMappingURL=localResolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localResolver.d.ts","sourceRoot":"","sources":["../src/localResolver.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAC3D,OAAO,EAEN,YAAY,EACZ,YAAY,EAEZ,MAAM,oCAAoC,CAAC;AAI5C,wBAAgB,mCAAmC,CAAC,UAAU,EAAE,MAAM,GAAG,QAAQ,CAQhF;AAED;;;GAGG;AACH,qBAAa,aAAc,YAAW,YAAY;IACjD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAc;IACvC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAc;;IAIvC;;;;;OAKG;IACU,OAAO,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,YAAY,CAAC;IAoBjD,cAAc,CAAC,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAiBrF,sBAAsB,CAAC,UAAU,EAAE,MAAM,GAAG,QAAQ;CAG3D"}
@@ -0,0 +1,70 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { parse } from "url";
6
+ import { assert } from "@fluidframework/common-utils";
7
+ import { DriverHeader, } from "@fluidframework/driver-definitions";
8
+ import { ScopeType } from "@fluidframework/protocol-definitions";
9
+ import { generateToken } from "./auth";
10
+ export function createLocalResolverCreateNewRequest(documentId) {
11
+ const createNewRequest = {
12
+ url: `http://localhost:3000/${documentId}`,
13
+ headers: {
14
+ [DriverHeader.createNew]: true,
15
+ },
16
+ };
17
+ return createNewRequest;
18
+ }
19
+ /**
20
+ * Resolves URLs by providing fake URLs which succeed with the other
21
+ * related local classes.
22
+ */
23
+ export class LocalResolver {
24
+ constructor() {
25
+ this.tenantId = "tenantId";
26
+ this.tokenKey = "tokenKey";
27
+ }
28
+ /**
29
+ * Resolves URL requests by providing fake URLs with an actually generated
30
+ * token from constant test strings. The root of the URL is fake, but the
31
+ * remaining relative URL can still be parsed.
32
+ * @param request - request to handle
33
+ */
34
+ async resolve(request) {
35
+ const parsedUrl = new URL(request.url);
36
+ const fullPath = `${parsedUrl.pathname.substr(1)}${parsedUrl.search}`;
37
+ const documentId = fullPath.split("/")[0];
38
+ const scopes = [ScopeType.DocRead, ScopeType.DocWrite, ScopeType.SummaryWrite];
39
+ const resolved = {
40
+ endpoints: {
41
+ deltaStorageUrl: `http://localhost:3000/deltas/${this.tenantId}/${documentId}`,
42
+ ordererUrl: "http://localhost:3000",
43
+ storageUrl: `http://localhost:3000/repos/${this.tenantId}`,
44
+ },
45
+ id: documentId,
46
+ tokens: { jwt: generateToken(this.tenantId, documentId, this.tokenKey, scopes) },
47
+ type: "fluid",
48
+ url: `fluid-test://localhost:3000/${this.tenantId}/${fullPath}`,
49
+ };
50
+ return resolved;
51
+ }
52
+ async getAbsoluteUrl(resolvedUrl, relativeUrl) {
53
+ let url = relativeUrl;
54
+ if (url.startsWith("/")) {
55
+ url = url.substr(1);
56
+ }
57
+ const fluidResolvedUrl = resolvedUrl;
58
+ const parsedUrl = parse(fluidResolvedUrl.url);
59
+ if (parsedUrl.pathname === null) {
60
+ throw new Error("Url should contain tenant and docId!!");
61
+ }
62
+ const [, , documentId] = parsedUrl.pathname.split("/");
63
+ assert(!!documentId, 0x09a /* "'documentId' must be a defined, non-zero length string." */);
64
+ return `http://localhost:3000/${documentId}/${url}`;
65
+ }
66
+ createCreateNewRequest(documentId) {
67
+ return createLocalResolverCreateNewRequest(documentId);
68
+ }
69
+ }
70
+ //# sourceMappingURL=localResolver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localResolver.js","sourceRoot":"","sources":["../src/localResolver.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,KAAK,CAAC;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAEtD,OAAO,EAIN,YAAY,GACZ,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAEvC,MAAM,UAAU,mCAAmC,CAAC,UAAkB;IACrE,MAAM,gBAAgB,GAAa;QAClC,GAAG,EAAE,yBAAyB,UAAU,EAAE;QAC1C,OAAO,EAAE;YACR,CAAC,YAAY,CAAC,SAAS,CAAC,EAAE,IAAI;SAC9B;KACD,CAAC;IACF,OAAO,gBAAgB,CAAC;AACzB,CAAC;AAED;;;GAGG;AACH,MAAM,OAAO,aAAa;IAIzB;QAHiB,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C,CAAC;QAE1D,MAAM,SAAS,GAAG,KAAK,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC;QAC9C,IAAI,SAAS,CAAC,QAAQ,KAAK,IAAI,EAAE;YAChC,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;SACzD;QACD,MAAM,CAAC,EAAE,AAAD,EAAG,UAAU,CAAC,GAAG,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACvD,MAAM,CAAC,CAAC,CAAC,UAAU,EAAE,KAAK,CAAC,+DAA+D,CAAC,CAAC;QAE5F,OAAO,yBAAyB,UAAU,IAAI,GAAG,EAAE,CAAC;IACrD,CAAC;IAEM,sBAAsB,CAAC,UAAkB;QAC/C,OAAO,mCAAmC,CAAC,UAAU,CAAC,CAAC;IACxD,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { parse } from \"url\";\nimport { assert } from \"@fluidframework/common-utils\";\nimport { IRequest } from \"@fluidframework/core-interfaces\";\nimport {\n\tIFluidResolvedUrl,\n\tIResolvedUrl,\n\tIUrlResolver,\n\tDriverHeader,\n} from \"@fluidframework/driver-definitions\";\nimport { ScopeType } from \"@fluidframework/protocol-definitions\";\nimport { generateToken } from \"./auth\";\n\nexport function createLocalResolverCreateNewRequest(documentId: string): IRequest {\n\tconst createNewRequest: IRequest = {\n\t\turl: `http://localhost:3000/${documentId}`,\n\t\theaders: {\n\t\t\t[DriverHeader.createNew]: true,\n\t\t},\n\t};\n\treturn createNewRequest;\n}\n\n/**\n * Resolves URLs by providing fake URLs which succeed with the other\n * related local classes.\n */\nexport class LocalResolver implements IUrlResolver {\n\tprivate readonly tenantId = \"tenantId\";\n\tprivate readonly tokenKey = \"tokenKey\";\n\n\tconstructor() {}\n\n\t/**\n\t * Resolves URL requests by providing fake URLs with an actually generated\n\t * token from constant test strings. The root of the URL is fake, but the\n\t * remaining relative URL can still be parsed.\n\t * @param request - request to handle\n\t */\n\tpublic async resolve(request: IRequest): Promise<IResolvedUrl> {\n\t\tconst parsedUrl = new URL(request.url);\n\t\tconst fullPath = `${parsedUrl.pathname.substr(1)}${parsedUrl.search}`;\n\t\tconst documentId = fullPath.split(\"/\")[0];\n\t\tconst scopes = [ScopeType.DocRead, ScopeType.DocWrite, ScopeType.SummaryWrite];\n\t\tconst resolved: IFluidResolvedUrl = {\n\t\t\tendpoints: {\n\t\t\t\tdeltaStorageUrl: `http://localhost:3000/deltas/${this.tenantId}/${documentId}`,\n\t\t\t\tordererUrl: \"http://localhost:3000\",\n\t\t\t\tstorageUrl: `http://localhost:3000/repos/${this.tenantId}`,\n\t\t\t},\n\t\t\tid: documentId,\n\t\t\ttokens: { jwt: generateToken(this.tenantId, documentId, this.tokenKey, scopes) },\n\t\t\ttype: \"fluid\",\n\t\t\turl: `fluid-test://localhost:3000/${this.tenantId}/${fullPath}`,\n\t\t};\n\n\t\treturn resolved;\n\t}\n\n\tpublic async getAbsoluteUrl(resolvedUrl: IResolvedUrl, relativeUrl: string): Promise<string> {\n\t\tlet url = relativeUrl;\n\t\tif (url.startsWith(\"/\")) {\n\t\t\turl = url.substr(1);\n\t\t}\n\t\tconst fluidResolvedUrl = resolvedUrl as IFluidResolvedUrl;\n\n\t\tconst parsedUrl = parse(fluidResolvedUrl.url);\n\t\tif (parsedUrl.pathname === null) {\n\t\t\tthrow new Error(\"Url should contain tenant and docId!!\");\n\t\t}\n\t\tconst [, , documentId] = parsedUrl.pathname.split(\"/\");\n\t\tassert(!!documentId, 0x09a /* \"'documentId' must be a defined, non-zero length string.\" */);\n\n\t\treturn `http://localhost:3000/${documentId}/${url}`;\n\t}\n\n\tpublic createCreateNewRequest(documentId: string): IRequest {\n\t\treturn createLocalResolverCreateNewRequest(documentId);\n\t}\n}\n"]}
@@ -0,0 +1,10 @@
1
+ import { IDb } from "@fluidframework/server-services-core";
2
+ import { ITestDbFactory } from "@fluidframework/server-test-utils";
3
+ /**
4
+ * A database factory for testing that stores data in the browsers session storage
5
+ */
6
+ export declare class LocalSessionStorageDbFactory implements ITestDbFactory {
7
+ readonly testDatabase: IDb;
8
+ connect(): Promise<IDb>;
9
+ }
10
+ //# sourceMappingURL=localSessionStorageDb.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localSessionStorageDb.d.ts","sourceRoot":"","sources":["../src/localSessionStorageDb.ts"],"names":[],"mappings":"AAKA,OAAO,EAAe,GAAG,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAgTnE;;GAEG;AACH,qBAAa,4BAA6B,YAAW,cAAc;IAClE,SAAgB,YAAY,EAAE,GAAG,CAA+B;IACnD,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC;CAGpC"}
@@ -0,0 +1,295 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { EventEmitter } from "events";
6
+ import { v4 as uuid } from "uuid";
7
+ /**
8
+ * A collection for local session storage, where data is stored in the browser
9
+ * Functions include database operations such as queries, insertion and update.
10
+ */
11
+ class LocalSessionStorageCollection {
12
+ /**
13
+ * @param collectionName - data type of the collection, e.g. blobs, deltas, trees, etc.
14
+ */
15
+ constructor(collectionName) {
16
+ this.collectionName = collectionName;
17
+ }
18
+ aggregate(pipeline, options) {
19
+ throw new Error("Method Not Implemented");
20
+ }
21
+ async updateMany(filter, set, addToSet) {
22
+ throw new Error("Method Not Implemented");
23
+ }
24
+ async distinct(key, query) {
25
+ throw new Error("Method Not Implemented");
26
+ }
27
+ async findAndUpdate(query, value) {
28
+ throw new Error("Method not implemented.");
29
+ }
30
+ /**
31
+ * {@inheritDoc @fluidframework/server-services-core#ICollection.find}
32
+ */
33
+ /*
34
+ * Each query key consists of several keys separated by '.' e.g: "operation.sequenceNumber".
35
+ * The hierarchical syntax allows finding nested key patterns.
36
+ */
37
+ async find(query, sort) {
38
+ // split the keys and get the corresponding value
39
+ function getValueByKey(propertyBag, key) {
40
+ const keys = key.split(".");
41
+ let value = propertyBag;
42
+ keys.forEach((splitKey) => {
43
+ value = value[splitKey];
44
+ });
45
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
46
+ return value;
47
+ }
48
+ // getting keys of the query we are trying to find
49
+ const queryKeys = Object.keys(query);
50
+ let filteredCollection = this.getAllInternal();
51
+ queryKeys.forEach((key) => {
52
+ if (!query[key]) {
53
+ return;
54
+ }
55
+ if (query[key].$gt > 0 || query[key].$lt > 0) {
56
+ if (query[key].$gt > 0) {
57
+ filteredCollection = filteredCollection.filter((value) => getValueByKey(value, key) > query[key].$gt);
58
+ }
59
+ if (query[key].$lt > 0) {
60
+ filteredCollection = filteredCollection.filter((value) => getValueByKey(value, key) < query[key].$lt);
61
+ }
62
+ }
63
+ else {
64
+ filteredCollection = filteredCollection.filter((value) => getValueByKey(value, key) === query[key]);
65
+ }
66
+ });
67
+ if (sort && Object.keys(sort).length === 1) {
68
+ // eslint-disable-next-line no-inner-declarations
69
+ function compare(a, b) {
70
+ const sortKey = Object.keys(sort)[0];
71
+ return sort[sortKey] === 1
72
+ ? getValueByKey(a, sortKey) - getValueByKey(b, sortKey)
73
+ : getValueByKey(b, sortKey) - getValueByKey(a, sortKey);
74
+ }
75
+ filteredCollection = filteredCollection.sort(compare);
76
+ }
77
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
78
+ return filteredCollection;
79
+ }
80
+ /**
81
+ * {@inheritDoc @fluidframework/server-services-core#ICollection.findAll}
82
+ */
83
+ async findAll() {
84
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
85
+ return this.getAllInternal();
86
+ }
87
+ /**
88
+ * {@inheritDoc @fluidframework/server-services-core#ICollection.findOne}
89
+ */
90
+ /*
91
+ * Query is expected to have a member "_id" which is a string used to find value in the database.
92
+ */
93
+ async findOne(query) {
94
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
95
+ return this.findOneInternal(query);
96
+ }
97
+ /**
98
+ * {@inheritDoc @fluidframework/server-services-core#ICollection.update}
99
+ */
100
+ /*
101
+ * Query is expected to have a member "_id" which is a string used to find value in the database.
102
+ */
103
+ async update(query, set, addToSet) {
104
+ const value = this.findOneInternal(query);
105
+ if (!value) {
106
+ throw new Error("Not found");
107
+ }
108
+ else {
109
+ for (const key of Object.keys(set)) {
110
+ value[key] = set[key];
111
+ }
112
+ this.insertInternal(value);
113
+ }
114
+ }
115
+ /**
116
+ * {@inheritDoc @fluidframework/server-services-core#ICollection.upsert}
117
+ */
118
+ /*
119
+ * Query is expected to have a member "_id" which is a string used to find value in the database.
120
+ */
121
+ async upsert(query, set, addToSet) {
122
+ const value = this.findOneInternal(query);
123
+ if (!value) {
124
+ this.insertInternal(set);
125
+ }
126
+ else {
127
+ for (const key of Object.keys(set)) {
128
+ value[key] = set[key];
129
+ }
130
+ this.insertInternal(value);
131
+ }
132
+ }
133
+ /**
134
+ * {@inheritDoc @fluidframework/server-services-core#ICollection.insertOne}
135
+ */
136
+ /*
137
+ * Value is expected to have a member "_id" which is a string used to search in the database.
138
+ */
139
+ async insertOne(value) {
140
+ const presentVal = this.findOneInternal(value);
141
+ // Only raise error when the object is present and the value is not equal.
142
+ if (presentVal) {
143
+ if (JSON.stringify(presentVal) === JSON.stringify(value)) {
144
+ return;
145
+ }
146
+ throw new Error("Existing Object!!");
147
+ }
148
+ return this.insertInternal(value);
149
+ }
150
+ /**
151
+ * {@inheritDoc @fluidframework/server-services-core#ICollection.findOrCreate}
152
+ */
153
+ /*
154
+ * Value and query are expected to have a member "_id" which is a string used to search or insert in the database.
155
+ */
156
+ async findOrCreate(query, value) {
157
+ const existing = this.findOneInternal(query);
158
+ if (existing) {
159
+ return { value: existing, existing: true };
160
+ }
161
+ this.insertInternal(value);
162
+ return { value, existing: false };
163
+ }
164
+ /**
165
+ * {@inheritDoc @fluidframework/server-services-core#ICollection.insertMany}
166
+ */
167
+ /*
168
+ * Each element in values is expected to have a member "_id" which is a string used to insert in the database.
169
+ */
170
+ async insertMany(values, ordered) {
171
+ this.insertInternal(...values);
172
+ }
173
+ /**
174
+ * {@inheritDoc @fluidframework/server-services-core#ICollection.deleteOne}
175
+ */
176
+ async deleteOne(query) {
177
+ throw new Error("Method not implemented.");
178
+ }
179
+ /**
180
+ * {@inheritDoc @fluidframework/server-services-core#ICollection.deleteMany}
181
+ */
182
+ async deleteMany(query) {
183
+ throw new Error("Method not implemented.");
184
+ }
185
+ /**
186
+ * {@inheritDoc @fluidframework/server-services-core#ICollection.createIndex}
187
+ */
188
+ async createIndex(index, unique) {
189
+ throw new Error("Method not implemented.");
190
+ }
191
+ /**
192
+ * Return all values in the database
193
+ */
194
+ getAllInternal() {
195
+ const values = [];
196
+ for (let i = 0; i < sessionStorage.length; i++) {
197
+ const key = sessionStorage.key(i);
198
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
199
+ if (key.startsWith(this.collectionName)) {
200
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
201
+ values.push(JSON.parse(sessionStorage.getItem(key)));
202
+ }
203
+ }
204
+ return values;
205
+ }
206
+ /**
207
+ * Inserts values into the session storge.
208
+ * Values are expected to have a member "_id" which is a unique id, otherwise will be assigned one
209
+ *
210
+ * @param values - data to insert to the database
211
+ */
212
+ insertInternal(...values) {
213
+ for (const value of values) {
214
+ if (value) {
215
+ if (!value._id) {
216
+ value._id = uuid();
217
+ }
218
+ sessionStorage.setItem(`${this.collectionName}-${value._id}`, JSON.stringify(value));
219
+ }
220
+ }
221
+ }
222
+ /**
223
+ * Finds the query in session storage and returns its value.
224
+ * Returns null if query is not found.
225
+ * Query is expected to have a member "_id" which is a unique id.
226
+ *
227
+ * @param query - what to find in the database
228
+ */
229
+ findOneInternal(query) {
230
+ if (query._id) {
231
+ const json = sessionStorage.getItem(`${this.collectionName}-${query._id}`);
232
+ if (json) {
233
+ return JSON.parse(json);
234
+ }
235
+ }
236
+ else {
237
+ const queryKeys = Object.keys(query);
238
+ for (let i = 0; i < sessionStorage.length; i++) {
239
+ const ssKey = sessionStorage.key(i);
240
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
241
+ if (!ssKey.startsWith(this.collectionName)) {
242
+ continue;
243
+ }
244
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
245
+ const value = JSON.parse(sessionStorage.getItem(ssKey));
246
+ let foundMismatch = false;
247
+ for (const qk of queryKeys) {
248
+ if (value[qk] !== query[qk]) {
249
+ foundMismatch = true;
250
+ break;
251
+ }
252
+ }
253
+ if (!foundMismatch) {
254
+ return value;
255
+ }
256
+ }
257
+ }
258
+ return null;
259
+ }
260
+ }
261
+ /**
262
+ * A database for testing that stores data in the browsers session storage
263
+ */
264
+ class LocalSessionStorageDb extends EventEmitter {
265
+ constructor() {
266
+ super(...arguments);
267
+ this.collections = new Map();
268
+ }
269
+ async close() { }
270
+ collection(name) {
271
+ if (!this.collections.has(name)) {
272
+ this.collections.set(name, new LocalSessionStorageCollection(name));
273
+ }
274
+ return this.collections.get(name);
275
+ }
276
+ async dropCollection(name) {
277
+ if (!this.collections.has(name)) {
278
+ return true;
279
+ }
280
+ this.collections.delete(name);
281
+ return true;
282
+ }
283
+ }
284
+ /**
285
+ * A database factory for testing that stores data in the browsers session storage
286
+ */
287
+ export class LocalSessionStorageDbFactory {
288
+ constructor() {
289
+ this.testDatabase = new LocalSessionStorageDb();
290
+ }
291
+ async connect() {
292
+ return this.testDatabase;
293
+ }
294
+ }
295
+ //# sourceMappingURL=localSessionStorageDb.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localSessionStorageDb.js","sourceRoot":"","sources":["../src/localSessionStorageDb.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAGtC,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAC;AAElC;;;GAGG;AACH,MAAM,6BAA6B;IAClC;;OAE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I,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;YAChC,OAAO,IAAI,CAAC;SACZ;QACD,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC9B,OAAO,IAAI,CAAC;IACb,CAAC;CACD;AAED;;GAEG;AACH,MAAM,OAAO,4BAA4B;IAAzC;QACiB,iBAAY,GAAQ,IAAI,qBAAqB,EAAE,CAAC;IAIjE,CAAC;IAHO,KAAK,CAAC,OAAO;QACnB,OAAO,IAAI,CAAC,YAAY,CAAC;IAC1B,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { EventEmitter } from \"events\";\nimport { ICollection, IDb } from \"@fluidframework/server-services-core\";\nimport { ITestDbFactory } from \"@fluidframework/server-test-utils\";\nimport { v4 as uuid } from \"uuid\";\n\n/**\n * A collection for local session storage, where data is stored in the browser\n * Functions include database operations such as queries, insertion and update.\n */\nclass LocalSessionStorageCollection<T> implements ICollection<T> {\n\t/**\n\t * @param collectionName - data type of the collection, e.g. blobs, deltas, trees, etc.\n\t */\n\tconstructor(private readonly collectionName: string) {}\n\n\tpublic aggregate(pipeline: any, options?: any): any {\n\t\tthrow new Error(\"Method Not Implemented\");\n\t}\n\n\tpublic async updateMany(filter: any, set: any, addToSet: any): Promise<void> {\n\t\tthrow new Error(\"Method Not Implemented\");\n\t}\n\tpublic async distinct(key: any, query: any): Promise<any> {\n\t\tthrow new Error(\"Method Not Implemented\");\n\t}\n\tpublic async findAndUpdate(query: any, value: T): Promise<{ value: T; existing: boolean }> {\n\t\tthrow new Error(\"Method not implemented.\");\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.find}\n\t */\n\t/*\n\t * Each query key consists of several keys separated by '.' e.g: \"operation.sequenceNumber\".\n\t * The hierarchical syntax allows finding nested key patterns.\n\t */\n\tpublic async find(query: any, sort: any): Promise<any[]> {\n\t\t// split the keys and get the corresponding value\n\t\tfunction getValueByKey(propertyBag, key: string) {\n\t\t\tconst keys = key.split(\".\");\n\t\t\tlet value = propertyBag;\n\t\t\tkeys.forEach((splitKey) => {\n\t\t\t\tvalue = value[splitKey];\n\t\t\t});\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\t\treturn value;\n\t\t}\n\n\t\t// getting keys of the query we are trying to find\n\t\tconst queryKeys = Object.keys(query);\n\t\tlet filteredCollection = this.getAllInternal();\n\t\tqueryKeys.forEach((key) => {\n\t\t\tif (!query[key]) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (query[key].$gt > 0 || query[key].$lt > 0) {\n\t\t\t\tif (query[key].$gt > 0) {\n\t\t\t\t\tfilteredCollection = filteredCollection.filter(\n\t\t\t\t\t\t(value) => getValueByKey(value, key) > query[key].$gt,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tif (query[key].$lt > 0) {\n\t\t\t\t\tfilteredCollection = filteredCollection.filter(\n\t\t\t\t\t\t(value) => getValueByKey(value, key) < query[key].$lt,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfilteredCollection = filteredCollection.filter(\n\t\t\t\t\t(value) => getValueByKey(value, key) === query[key],\n\t\t\t\t);\n\t\t\t}\n\t\t});\n\n\t\tif (sort && Object.keys(sort).length === 1) {\n\t\t\t// eslint-disable-next-line no-inner-declarations\n\t\t\tfunction compare(a, b) {\n\t\t\t\tconst sortKey = Object.keys(sort)[0];\n\t\t\t\treturn sort[sortKey] === 1\n\t\t\t\t\t? getValueByKey(a, sortKey) - getValueByKey(b, sortKey)\n\t\t\t\t\t: getValueByKey(b, sortKey) - getValueByKey(a, sortKey);\n\t\t\t}\n\n\t\t\tfilteredCollection = filteredCollection.sort(compare);\n\t\t}\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\treturn filteredCollection;\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.findAll}\n\t */\n\tpublic async findAll(): Promise<any[]> {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\treturn this.getAllInternal();\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.findOne}\n\t */\n\t/*\n\t * Query is expected to have a member \"_id\" which is a string used to find value in the database.\n\t */\n\tpublic async findOne(query: any): Promise<any> {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\treturn this.findOneInternal(query);\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.update}\n\t */\n\t/*\n\t * Query is expected to have a member \"_id\" which is a string used to find value in the database.\n\t */\n\tpublic async update(query: any, set: any, addToSet: any): Promise<void> {\n\t\tconst value = this.findOneInternal(query);\n\t\tif (!value) {\n\t\t\tthrow new Error(\"Not found\");\n\t\t} else {\n\t\t\tfor (const key of Object.keys(set)) {\n\t\t\t\tvalue[key] = set[key];\n\t\t\t}\n\t\t\tthis.insertInternal(value);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.upsert}\n\t */\n\t/*\n\t * Query is expected to have a member \"_id\" which is a string used to find value in the database.\n\t */\n\tpublic async upsert(query: any, set: any, addToSet: any): Promise<void> {\n\t\tconst value = this.findOneInternal(query);\n\t\tif (!value) {\n\t\t\tthis.insertInternal(set);\n\t\t} else {\n\t\t\tfor (const key of Object.keys(set)) {\n\t\t\t\tvalue[key] = set[key];\n\t\t\t}\n\t\t\tthis.insertInternal(value);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.insertOne}\n\t */\n\t/*\n\t * Value is expected to have a member \"_id\" which is a string used to search in the database.\n\t */\n\tpublic async insertOne(value: any): Promise<any> {\n\t\tconst presentVal = this.findOneInternal(value);\n\t\t// Only raise error when the object is present and the value is not equal.\n\t\tif (presentVal) {\n\t\t\tif (JSON.stringify(presentVal) === JSON.stringify(value)) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthrow new Error(\"Existing Object!!\");\n\t\t}\n\n\t\treturn this.insertInternal(value);\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.findOrCreate}\n\t */\n\t/*\n\t * Value and query are expected to have a member \"_id\" which is a string used to search or insert in the database.\n\t */\n\tpublic async findOrCreate(query: any, value: any): Promise<{ value: any; existing: boolean }> {\n\t\tconst existing = this.findOneInternal(query);\n\t\tif (existing) {\n\t\t\treturn { value: existing, existing: true };\n\t\t}\n\t\tthis.insertInternal(value);\n\t\treturn { value, existing: false };\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.insertMany}\n\t */\n\t/*\n\t * Each element in values is expected to have a member \"_id\" which is a string used to insert in the database.\n\t */\n\tpublic async insertMany(values: any[], ordered: boolean): Promise<void> {\n\t\tthis.insertInternal(...values);\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.deleteOne}\n\t */\n\tpublic async deleteOne(query: any): Promise<any> {\n\t\tthrow new Error(\"Method not implemented.\");\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.deleteMany}\n\t */\n\tpublic async deleteMany(query: any): Promise<any> {\n\t\tthrow new Error(\"Method not implemented.\");\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/server-services-core#ICollection.createIndex}\n\t */\n\tpublic async createIndex(index: any, unique: boolean): Promise<void> {\n\t\tthrow new Error(\"Method not implemented.\");\n\t}\n\n\t/**\n\t * Return all values in the database\n\t */\n\tprivate getAllInternal(): any[] {\n\t\tconst values: string[] = [];\n\t\tfor (let i = 0; i < sessionStorage.length; i++) {\n\t\t\tconst key = sessionStorage.key(i);\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tif (key!.startsWith(this.collectionName)) {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tvalues.push(JSON.parse(sessionStorage.getItem(key!)!));\n\t\t\t}\n\t\t}\n\t\treturn values;\n\t}\n\n\t/**\n\t * Inserts values into the session storge.\n\t * Values are expected to have a member \"_id\" which is a unique id, otherwise will be assigned one\n\t *\n\t * @param values - data to insert to the database\n\t */\n\tprivate insertInternal(...values: any[]) {\n\t\tfor (const value of values) {\n\t\t\tif (value) {\n\t\t\t\tif (!value._id) {\n\t\t\t\t\tvalue._id = uuid();\n\t\t\t\t}\n\t\t\t\tsessionStorage.setItem(\n\t\t\t\t\t`${this.collectionName}-${value._id}`,\n\t\t\t\t\tJSON.stringify(value),\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Finds the query in session storage and returns its value.\n\t * Returns null if query is not found.\n\t * Query is expected to have a member \"_id\" which is a unique id.\n\t *\n\t * @param query - what to find in the database\n\t */\n\tprivate findOneInternal(query: any): any {\n\t\tif (query._id) {\n\t\t\tconst json = sessionStorage.getItem(`${this.collectionName}-${query._id}`);\n\t\t\tif (json) {\n\t\t\t\treturn JSON.parse(json);\n\t\t\t}\n\t\t} else {\n\t\t\tconst queryKeys = Object.keys(query);\n\t\t\tfor (let i = 0; i < sessionStorage.length; i++) {\n\t\t\t\tconst ssKey = sessionStorage.key(i);\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tif (!ssKey!.startsWith(this.collectionName)) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tconst value = JSON.parse(sessionStorage.getItem(ssKey!)!);\n\t\t\t\tlet foundMismatch = false;\n\t\t\t\tfor (const qk of queryKeys) {\n\t\t\t\t\tif (value[qk] !== query[qk]) {\n\t\t\t\t\t\tfoundMismatch = true;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (!foundMismatch) {\n\t\t\t\t\treturn value;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn null;\n\t}\n}\n\n/**\n * A database for testing that stores data in the browsers session storage\n */\nclass LocalSessionStorageDb extends EventEmitter implements IDb {\n\tprivate readonly collections = new Map<string, LocalSessionStorageCollection<any>>();\n\tpublic async close(): Promise<void> {}\n\tpublic collection<T>(name: string): ICollection<T> {\n\t\tif (!this.collections.has(name)) {\n\t\t\tthis.collections.set(name, new LocalSessionStorageCollection<T>(name));\n\t\t}\n\t\treturn this.collections.get(name) as LocalSessionStorageCollection<T>;\n\t}\n\n\tpublic async dropCollection(name: string): Promise<boolean> {\n\t\tif (!this.collections.has(name)) {\n\t\t\treturn true;\n\t\t}\n\t\tthis.collections.delete(name);\n\t\treturn true;\n\t}\n}\n\n/**\n * A database factory for testing that stores data in the browsers session storage\n */\nexport class LocalSessionStorageDbFactory implements ITestDbFactory {\n\tpublic readonly testDatabase: IDb = new LocalSessionStorageDb();\n\tpublic async connect(): Promise<IDb> {\n\t\treturn this.testDatabase;\n\t}\n}\n"]}
@@ -0,0 +1,9 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ *
5
+ * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
6
+ */
7
+ export declare const pkgName = "@fluidframework/local-driver";
8
+ export declare const pkgVersion = "2.0.0-dev.4.1.0.148229";
9
+ //# sourceMappingURL=packageVersion.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,iCAAiC,CAAC;AACtD,eAAO,MAAM,UAAU,2BAA2B,CAAC"}
@@ -0,0 +1,9 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ *
5
+ * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
6
+ */
7
+ export const pkgName = "@fluidframework/local-driver";
8
+ export const pkgVersion = "2.0.0-dev.4.1.0.148229";
9
+ //# sourceMappingURL=packageVersion.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,8BAA8B,CAAC;AACtD,MAAM,CAAC,MAAM,UAAU,GAAG,wBAAwB,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/local-driver\";\nexport const pkgVersion = \"2.0.0-dev.4.1.0.148229\";\n"]}