@fluidframework/local-driver 2.0.0-internal.1.4.2 → 2.0.0-internal.2.0.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/.eslintrc.js +23 -9
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- 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 +18 -14
- package/src/index.ts +1 -0
- 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
|
@@ -12,8 +12,11 @@ const uuid_1 = require("uuid");
|
|
|
12
12
|
* Functions include database operations such as queries, insertion and update.
|
|
13
13
|
*/
|
|
14
14
|
class LocalSessionStorageCollection {
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
/**
|
|
16
|
+
* @param collectionName - data type of the collection, e.g. blobs, deltas, trees, etc.
|
|
17
|
+
*/
|
|
18
|
+
constructor(collectionName) {
|
|
19
|
+
this.collectionName = collectionName;
|
|
17
20
|
}
|
|
18
21
|
aggregate(pipeline, options) {
|
|
19
22
|
throw new Error("Method Not Implemented");
|
|
@@ -78,7 +81,8 @@ class LocalSessionStorageCollection {
|
|
|
78
81
|
* {@inheritDoc @fluidframework/server-services-core#ICollection.findAll}
|
|
79
82
|
*/
|
|
80
83
|
async findAll() {
|
|
81
|
-
return
|
|
84
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
85
|
+
return this.getAllInternal();
|
|
82
86
|
}
|
|
83
87
|
/**
|
|
84
88
|
* {@inheritDoc @fluidframework/server-services-core#ICollection.findOne}
|
|
@@ -87,7 +91,8 @@ class LocalSessionStorageCollection {
|
|
|
87
91
|
* Query is expected to have a member "_id" which is a string used to find value in the database.
|
|
88
92
|
*/
|
|
89
93
|
async findOne(query) {
|
|
90
|
-
return
|
|
94
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
95
|
+
return this.findOneInternal(query);
|
|
91
96
|
}
|
|
92
97
|
/**
|
|
93
98
|
* {@inheritDoc @fluidframework/server-services-core#ICollection.update}
|
|
@@ -259,17 +264,14 @@ class LocalSessionStorageCollection {
|
|
|
259
264
|
* A database for testing that stores data in the browsers session storage
|
|
260
265
|
*/
|
|
261
266
|
class LocalSessionStorageDb extends events_1.EventEmitter {
|
|
262
|
-
constructor(
|
|
263
|
-
super();
|
|
264
|
-
this.namespace = namespace;
|
|
267
|
+
constructor() {
|
|
268
|
+
super(...arguments);
|
|
265
269
|
this.collections = new Map();
|
|
266
270
|
}
|
|
267
|
-
async close() {
|
|
268
|
-
return Promise.resolve();
|
|
269
|
-
}
|
|
271
|
+
async close() { }
|
|
270
272
|
collection(name) {
|
|
271
273
|
if (!this.collections.has(name)) {
|
|
272
|
-
this.collections.set(name, new LocalSessionStorageCollection(
|
|
274
|
+
this.collections.set(name, new LocalSessionStorageCollection(name));
|
|
273
275
|
}
|
|
274
276
|
return this.collections.get(name);
|
|
275
277
|
}
|
|
@@ -285,8 +287,8 @@ class LocalSessionStorageDb extends events_1.EventEmitter {
|
|
|
285
287
|
* A database factory for testing that stores data in the browsers session storage
|
|
286
288
|
*/
|
|
287
289
|
class LocalSessionStorageDbFactory {
|
|
288
|
-
constructor(
|
|
289
|
-
this.testDatabase = new LocalSessionStorageDb(
|
|
290
|
+
constructor() {
|
|
291
|
+
this.testDatabase = new LocalSessionStorageDb();
|
|
290
292
|
}
|
|
291
293
|
async connect() {
|
|
292
294
|
return this.testDatabase;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localSessionStorageDb.js","sourceRoot":"","sources":["../src/localSessionStorageDb.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,mCAAsC;AAGtC,+BAAkC;AAElC;;;GAGG;AACH,MAAM,6BAA6B;IAE/B,YAAY,SAAS,EAAE,IAAI;QACvB,IAAI,CAAC,cAAc,GAAG,GAAG,SAAS,IAAI,IAAI,EAAE,CAAC;IACjD,CAAC;IAEM,SAAS,CAAC,QAAa,EAAE,OAAa;QACzC,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAC9C,CAAC;IAEM,KAAK,CAAC,UAAU,CAAC,MAAW,EAAE,GAAQ,EAAE,QAAa;QACxD,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAC9C,CAAC;IACM,KAAK,CAAC,QAAQ,CAAC,GAAQ,EAAE,KAAU;QACtC,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAC9C,CAAC;IAED;;OAEG;IACH;;;OAGG;I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C;IAC7D,CAAC;IACM,KAAK,CAAC,OAAO;QAChB,OAAO,IAAI,CAAC,YAAY,CAAC;IAC7B,CAAC;CACJ;AARD,oEAQC","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 private readonly collectionName: string;\n constructor(namespace, name) {\n this.collectionName = `${namespace}-${name}`;\n }\n\n public aggregate(pipeline: any, options?: any): any {\n throw new Error(\"Method Not Implemented\");\n }\n\n public async updateMany(filter: any, set: any, addToSet: any): Promise<void> {\n throw new Error(\"Method Not Implemented\");\n }\n public async distinct(key: any, query: any): Promise<any> {\n throw new Error(\"Method Not Implemented\");\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.find}\n */\n /*\n * Each query key consists of several keys separated by '.' e.g: \"operation.sequenceNumber\".\n * The hierarchical syntax allows finding nested key patterns.\n */\n public async find(query: any, sort: any): Promise<any[]> {\n // split the keys and get the corresponding value\n function getValueByKey(propertyBag, key: string) {\n const keys = key.split(\".\");\n let value = propertyBag;\n keys.forEach((splitKey) => {\n value = value[splitKey];\n });\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return value;\n }\n\n // getting keys of the query we are trying to find\n const queryKeys = Object.keys(query);\n let filteredCollection = this.getAllInternal();\n queryKeys.forEach((key) => {\n if (!query[key]) {\n return;\n }\n if (query[key].$gt > 0 || query[key].$lt > 0) {\n if (query[key].$gt > 0) {\n filteredCollection = filteredCollection.filter(\n (value) => getValueByKey(value, key) > query[key].$gt);\n }\n if (query[key].$lt > 0) {\n filteredCollection = filteredCollection.filter(\n (value) => getValueByKey(value, key) < query[key].$lt);\n }\n } else {\n filteredCollection = filteredCollection.filter(\n (value) => getValueByKey(value, key) === query[key]);\n }\n });\n\n if (sort && Object.keys(sort).length === 1) {\n // eslint-disable-next-line no-inner-declarations\n function compare(a, b) {\n const sortKey = Object.keys(sort)[0];\n return sort[sortKey] === 1\n ? getValueByKey(a, sortKey) - getValueByKey(b, sortKey)\n : getValueByKey(b, sortKey) - getValueByKey(a, sortKey);\n }\n\n filteredCollection = filteredCollection.sort(compare);\n }\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return filteredCollection;\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.findAll}\n */\n public async findAll(): Promise<any[]> {\n return Promise.resolve(this.getAllInternal());\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.findOne}\n */\n /*\n * Query is expected to have a member \"_id\" which is a string used to find value in the database.\n */\n public async findOne(query: any): Promise<any> {\n return Promise.resolve(this.findOneInternal(query));\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.update}\n */\n /*\n * Query is expected to have a member \"_id\" which is a string used to find value in the database.\n */\n public async update(query: any, set: any, addToSet: any): Promise<void> {\n const value = this.findOneInternal(query);\n if (!value) {\n throw new Error(\"Not found\");\n } else {\n for (const key of Object.keys(set)) {\n value[key] = set[key];\n }\n this.insertInternal(value);\n }\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.upsert}\n */\n /*\n * Query is expected to have a member \"_id\" which is a string used to find value in the database.\n */\n public async upsert(query: any, set: any, addToSet: any): Promise<void> {\n const value = this.findOneInternal(query);\n if (!value) {\n this.insertInternal(set);\n } else {\n for (const key of Object.keys(set)) {\n value[key] = set[key];\n }\n this.insertInternal(value);\n }\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.insertOne}\n */\n /*\n * Value is expected to have a member \"_id\" which is a string used to search in the database.\n */\n public async insertOne(value: any): Promise<any> {\n const presentVal = this.findOneInternal(value);\n // Only raise error when the object is present and the value is not equal.\n if (presentVal) {\n if (JSON.stringify(presentVal) === JSON.stringify(value)) {\n return;\n }\n throw new Error(\"Existing Object!!\");\n }\n\n return this.insertInternal(value);\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.findOrCreate}\n */\n /*\n * Value and query are expected to have a member \"_id\" which is a string used to search or insert in the database.\n */\n public async findOrCreate(query: any, value: any): Promise<{ value: any; existing: boolean; }> {\n const existing = this.findOneInternal(query);\n if (existing) {\n return { value: existing, existing: true };\n }\n this.insertInternal(value);\n return { value, existing: false };\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.insertMany}\n */\n /*\n * Each element in values is expected to have a member \"_id\" which is a string used to insert in the database.\n */\n public async insertMany(values: any[], ordered: boolean): Promise<void> {\n this.insertInternal(...values);\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.deleteOne}\n */\n public async deleteOne(query: any): Promise<any> {\n throw new Error(\"Method not implemented.\");\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.deleteMany}\n */\n public async deleteMany(query: any): Promise<any> {\n throw new Error(\"Method not implemented.\");\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.createIndex}\n */\n public async createIndex(index: any, unique: boolean): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n\n /**\n * Return all values in the database\n */\n private getAllInternal(): any[] {\n const values: string[] = [];\n for (let i = 0; i < sessionStorage.length; i++) {\n const key = sessionStorage.key(i);\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n if (key!.startsWith(this.collectionName)) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n values.push(JSON.parse(sessionStorage.getItem(key!)!));\n }\n }\n return values;\n }\n\n /**\n * Inserts values into the session storge.\n * Values are expected to have a member \"_id\" which is a unique id, otherwise will be assigned one\n *\n * @param values - data to insert to the database\n */\n private insertInternal(...values: any[]) {\n for (const value of values) {\n if (value) {\n if (!value._id) {\n value._id = uuid();\n }\n sessionStorage.setItem(`${this.collectionName}-${value._id}`, JSON.stringify(value));\n }\n }\n }\n\n /**\n * Finds the query in session storage and returns its value.\n * Returns null if query is not found.\n * Query is expected to have a member \"_id\" which is a unique id.\n *\n * @param query - what to find in the database\n */\n private findOneInternal(query: any): any {\n if (query._id) {\n const json = sessionStorage.getItem(`${this.collectionName}-${query._id}`);\n if (json) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return JSON.parse(json);\n }\n } else {\n const queryKeys = Object.keys(query);\n for (let i = 0; i < sessionStorage.length; i++) {\n const ssKey = sessionStorage.key(i);\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n if (!ssKey!.startsWith(this.collectionName)) {\n continue;\n }\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const value = JSON.parse(sessionStorage.getItem(ssKey!)!);\n let foundMismatch = false;\n for (const qk of queryKeys) {\n if (value[qk] !== query[qk]) {\n foundMismatch = true;\n break;\n }\n }\n\n if (!foundMismatch) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return value;\n }\n }\n }\n return null;\n }\n}\n\n/**\n * A database for testing that stores data in the browsers session storage\n */\nclass LocalSessionStorageDb extends EventEmitter implements IDb {\n private readonly collections = new Map<string, LocalSessionStorageCollection<any>>();\n constructor(private readonly namespace) {\n super();\n }\n public async close(): Promise<void> {\n return Promise.resolve();\n }\n public collection<T>(name: string): ICollection<T> {\n if (!this.collections.has(name)) {\n this.collections.set(name, new LocalSessionStorageCollection<T>(`${this.namespace}-db`, name));\n }\n return this.collections.get(name) as LocalSessionStorageCollection<T>;\n }\n\n public async dropCollection(name: string): Promise<boolean> {\n if (!this.collections.has(name)) {\n return true;\n }\n this.collections.delete(name);\n return true;\n }\n}\n\n/**\n * A database factory for testing that stores data in the browsers session storage\n */\nexport class LocalSessionStorageDbFactory implements ITestDbFactory {\n public readonly testDatabase: IDb;\n constructor(namespace: string) {\n this.testDatabase = new LocalSessionStorageDb(namespace);\n }\n public async connect(): Promise<IDb> {\n return this.testDatabase;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"localSessionStorageDb.js","sourceRoot":"","sources":["../src/localSessionStorageDb.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,mCAAsC;AAGtC,+BAAkC;AAElC;;;GAGG;AACH,MAAM,6BAA6B;IAC/B;;OAEG;IACH,YAA6B,cAAsB;QAAtB,mBAAc,GAAd,cAAc,CAAQ;IAAI,CAAC;IAEjD,SAAS,CAAC,QAAa,EAAE,OAAa;QACzC,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAC9C,CAAC;IAEM,KAAK,CAAC,UAAU,CAAC,MAAW,EAAE,GAAQ,EAAE,QAAa;QACxD,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAC9C,CAAC;IACM,KAAK,CAAC,QAAQ,CAAC,GAAQ,EAAE,KAAU;QACtC,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAC9C,CAAC;IAED;;OAEG;IACH;;;OAGG;IACI,KAAK,CAAC,IAAI,CAAC,KAAU,EAAE,IAAS;QACnC,iDAAiD;QACjD,SAAS,aAAa,CAAC,WAAW,EAAE,GAAW;YAC3C,MAAM,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAC5B,IAAI,KAAK,GAAG,WAAW,CAAC;YACxB,IAAI,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;gBACtB,KAAK,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC;YAC5B,CAAC,CAAC,CAAC;YACH,+DAA+D;YAC/D,OAAO,KAAK,CAAC;QACjB,CAAC;QAED,kDAAkD;QAClD,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACrC,IAAI,kBAAkB,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;QAC/C,SAAS,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;Y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,6BAA6B,CAAI,IAAI,CAAC,CAAC,CAAC;SAC1E;QACD,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAqC,CAAC;IAC1E,CAAC;IAEM,KAAK,CAAC,cAAc,CAAC,IAAY;QACpC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;YAC7B,OAAO,IAAI,CAAC;SACf;QACD,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC9B,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ;AAED;;GAEG;AACH,MAAa,4BAA4B;IAAzC;QACoB,iBAAY,GAAQ,IAAI,qBAAqB,EAAE,CAAC;IAIpE,CAAC;IAHU,KAAK,CAAC,OAAO;QAChB,OAAO,IAAI,CAAC,YAAY,CAAC;IAC7B,CAAC;CACJ;AALD,oEAKC","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 /**\n * @param collectionName - data type of the collection, e.g. blobs, deltas, trees, etc.\n */\n constructor(private readonly collectionName: string) { }\n\n public aggregate(pipeline: any, options?: any): any {\n throw new Error(\"Method Not Implemented\");\n }\n\n public async updateMany(filter: any, set: any, addToSet: any): Promise<void> {\n throw new Error(\"Method Not Implemented\");\n }\n public async distinct(key: any, query: any): Promise<any> {\n throw new Error(\"Method Not Implemented\");\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.find}\n */\n /*\n * Each query key consists of several keys separated by '.' e.g: \"operation.sequenceNumber\".\n * The hierarchical syntax allows finding nested key patterns.\n */\n public async find(query: any, sort: any): Promise<any[]> {\n // split the keys and get the corresponding value\n function getValueByKey(propertyBag, key: string) {\n const keys = key.split(\".\");\n let value = propertyBag;\n keys.forEach((splitKey) => {\n value = value[splitKey];\n });\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return value;\n }\n\n // getting keys of the query we are trying to find\n const queryKeys = Object.keys(query);\n let filteredCollection = this.getAllInternal();\n queryKeys.forEach((key) => {\n if (!query[key]) {\n return;\n }\n if (query[key].$gt > 0 || query[key].$lt > 0) {\n if (query[key].$gt > 0) {\n filteredCollection = filteredCollection.filter(\n (value) => getValueByKey(value, key) > query[key].$gt);\n }\n if (query[key].$lt > 0) {\n filteredCollection = filteredCollection.filter(\n (value) => getValueByKey(value, key) < query[key].$lt);\n }\n } else {\n filteredCollection = filteredCollection.filter(\n (value) => getValueByKey(value, key) === query[key]);\n }\n });\n\n if (sort && Object.keys(sort).length === 1) {\n // eslint-disable-next-line no-inner-declarations\n function compare(a, b) {\n const sortKey = Object.keys(sort)[0];\n return sort[sortKey] === 1\n ? getValueByKey(a, sortKey) - getValueByKey(b, sortKey)\n : getValueByKey(b, sortKey) - getValueByKey(a, sortKey);\n }\n\n filteredCollection = filteredCollection.sort(compare);\n }\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return filteredCollection;\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.findAll}\n */\n public async findAll(): Promise<any[]> {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return this.getAllInternal();\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.findOne}\n */\n /*\n * Query is expected to have a member \"_id\" which is a string used to find value in the database.\n */\n public async findOne(query: any): Promise<any> {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return this.findOneInternal(query);\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.update}\n */\n /*\n * Query is expected to have a member \"_id\" which is a string used to find value in the database.\n */\n public async update(query: any, set: any, addToSet: any): Promise<void> {\n const value = this.findOneInternal(query);\n if (!value) {\n throw new Error(\"Not found\");\n } else {\n for (const key of Object.keys(set)) {\n value[key] = set[key];\n }\n this.insertInternal(value);\n }\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.upsert}\n */\n /*\n * Query is expected to have a member \"_id\" which is a string used to find value in the database.\n */\n public async upsert(query: any, set: any, addToSet: any): Promise<void> {\n const value = this.findOneInternal(query);\n if (!value) {\n this.insertInternal(set);\n } else {\n for (const key of Object.keys(set)) {\n value[key] = set[key];\n }\n this.insertInternal(value);\n }\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.insertOne}\n */\n /*\n * Value is expected to have a member \"_id\" which is a string used to search in the database.\n */\n public async insertOne(value: any): Promise<any> {\n const presentVal = this.findOneInternal(value);\n // Only raise error when the object is present and the value is not equal.\n if (presentVal) {\n if (JSON.stringify(presentVal) === JSON.stringify(value)) {\n return;\n }\n throw new Error(\"Existing Object!!\");\n }\n\n return this.insertInternal(value);\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.findOrCreate}\n */\n /*\n * Value and query are expected to have a member \"_id\" which is a string used to search or insert in the database.\n */\n public async findOrCreate(query: any, value: any): Promise<{ value: any; existing: boolean; }> {\n const existing = this.findOneInternal(query);\n if (existing) {\n return { value: existing, existing: true };\n }\n this.insertInternal(value);\n return { value, existing: false };\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.insertMany}\n */\n /*\n * Each element in values is expected to have a member \"_id\" which is a string used to insert in the database.\n */\n public async insertMany(values: any[], ordered: boolean): Promise<void> {\n this.insertInternal(...values);\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.deleteOne}\n */\n public async deleteOne(query: any): Promise<any> {\n throw new Error(\"Method not implemented.\");\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.deleteMany}\n */\n public async deleteMany(query: any): Promise<any> {\n throw new Error(\"Method not implemented.\");\n }\n\n /**\n * {@inheritDoc @fluidframework/server-services-core#ICollection.createIndex}\n */\n public async createIndex(index: any, unique: boolean): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n\n /**\n * Return all values in the database\n */\n private getAllInternal(): any[] {\n const values: string[] = [];\n for (let i = 0; i < sessionStorage.length; i++) {\n const key = sessionStorage.key(i);\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n if (key!.startsWith(this.collectionName)) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n values.push(JSON.parse(sessionStorage.getItem(key!)!));\n }\n }\n return values;\n }\n\n /**\n * Inserts values into the session storge.\n * Values are expected to have a member \"_id\" which is a unique id, otherwise will be assigned one\n *\n * @param values - data to insert to the database\n */\n private insertInternal(...values: any[]) {\n for (const value of values) {\n if (value) {\n if (!value._id) {\n value._id = uuid();\n }\n sessionStorage.setItem(`${this.collectionName}-${value._id}`, JSON.stringify(value));\n }\n }\n }\n\n /**\n * Finds the query in session storage and returns its value.\n * Returns null if query is not found.\n * Query is expected to have a member \"_id\" which is a unique id.\n *\n * @param query - what to find in the database\n */\n private findOneInternal(query: any): any {\n if (query._id) {\n const json = sessionStorage.getItem(`${this.collectionName}-${query._id}`);\n if (json) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return JSON.parse(json);\n }\n } else {\n const queryKeys = Object.keys(query);\n for (let i = 0; i < sessionStorage.length; i++) {\n const ssKey = sessionStorage.key(i);\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n if (!ssKey!.startsWith(this.collectionName)) {\n continue;\n }\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const value = JSON.parse(sessionStorage.getItem(ssKey!)!);\n let foundMismatch = false;\n for (const qk of queryKeys) {\n if (value[qk] !== query[qk]) {\n foundMismatch = true;\n break;\n }\n }\n\n if (!foundMismatch) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return value;\n }\n }\n }\n return null;\n }\n}\n\n/**\n * A database for testing that stores data in the browsers session storage\n */\nclass LocalSessionStorageDb extends EventEmitter implements IDb {\n private readonly collections = new Map<string, LocalSessionStorageCollection<any>>();\n public async close(): Promise<void> { }\n public collection<T>(name: string): ICollection<T> {\n if (!this.collections.has(name)) {\n this.collections.set(name, new LocalSessionStorageCollection<T>(name));\n }\n return this.collections.get(name) as LocalSessionStorageCollection<T>;\n }\n\n public async dropCollection(name: string): Promise<boolean> {\n if (!this.collections.has(name)) {\n return true;\n }\n this.collections.delete(name);\n return true;\n }\n}\n\n/**\n * A database factory for testing that stores data in the browsers session storage\n */\nexport class LocalSessionStorageDbFactory implements ITestDbFactory {\n public readonly testDatabase: IDb = new LocalSessionStorageDb();\n public async connect(): Promise<IDb> {\n return this.testDatabase;\n }\n}\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/local-driver";
|
|
8
|
-
export declare const pkgVersion = "2.0.0-internal.
|
|
8
|
+
export declare const pkgVersion = "2.0.0-internal.2.0.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/local-driver";
|
|
11
|
-
exports.pkgVersion = "2.0.0-internal.
|
|
11
|
+
exports.pkgVersion = "2.0.0-internal.2.0.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,8BAA8B,CAAC;AACzC,QAAA,UAAU,GAAG,sBAAsB,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-internal.
|
|
1
|
+
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,8BAA8B,CAAC;AACzC,QAAA,UAAU,GAAG,sBAAsB,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-internal.2.0.0\";\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluidframework/local-driver",
|
|
3
|
-
"version": "2.0.0-internal.
|
|
3
|
+
"version": "2.0.0-internal.2.0.0",
|
|
4
4
|
"description": "Fluid local driver",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -33,7 +33,8 @@
|
|
|
33
33
|
"test:mocha:verbose": "cross-env FLUID_TEST_VERBOSE=1 npm run test:mocha",
|
|
34
34
|
"tsc": "tsc",
|
|
35
35
|
"tsfmt": "tsfmt --verify",
|
|
36
|
-
"tsfmt:fix": "tsfmt --replace"
|
|
36
|
+
"tsfmt:fix": "tsfmt --replace",
|
|
37
|
+
"typetests:gen": "fluid-type-validator -g -d ."
|
|
37
38
|
},
|
|
38
39
|
"nyc": {
|
|
39
40
|
"all": true,
|
|
@@ -58,24 +59,27 @@
|
|
|
58
59
|
"dependencies": {
|
|
59
60
|
"@fluidframework/common-definitions": "^0.20.1",
|
|
60
61
|
"@fluidframework/common-utils": "^1.0.0",
|
|
61
|
-
"@fluidframework/core-interfaces": "^2.0.0-internal.
|
|
62
|
-
"@fluidframework/driver-base": "^2.0.0-internal.
|
|
63
|
-
"@fluidframework/driver-definitions": "^2.0.0-internal.
|
|
64
|
-
"@fluidframework/driver-utils": "^2.0.0-internal.
|
|
65
|
-
"@fluidframework/protocol-
|
|
66
|
-
"@fluidframework/
|
|
67
|
-
"@fluidframework/
|
|
68
|
-
"@fluidframework/server-
|
|
69
|
-
"@fluidframework/server-services-
|
|
70
|
-
"@fluidframework/server-
|
|
62
|
+
"@fluidframework/core-interfaces": "^2.0.0-internal.2.0.0",
|
|
63
|
+
"@fluidframework/driver-base": "^2.0.0-internal.2.0.0",
|
|
64
|
+
"@fluidframework/driver-definitions": "^2.0.0-internal.2.0.0",
|
|
65
|
+
"@fluidframework/driver-utils": "^2.0.0-internal.2.0.0",
|
|
66
|
+
"@fluidframework/protocol-base": "^0.1038.2000",
|
|
67
|
+
"@fluidframework/protocol-definitions": "^1.1.0",
|
|
68
|
+
"@fluidframework/routerlicious-driver": "^2.0.0-internal.2.0.0",
|
|
69
|
+
"@fluidframework/server-local-server": "^0.1038.2000",
|
|
70
|
+
"@fluidframework/server-services-client": "^0.1038.2000",
|
|
71
|
+
"@fluidframework/server-services-core": "^0.1038.2000",
|
|
72
|
+
"@fluidframework/server-test-utils": "^0.1038.2000",
|
|
73
|
+
"@fluidframework/telemetry-utils": "^2.0.0-internal.2.0.0",
|
|
71
74
|
"jsrsasign": "^10.5.25",
|
|
75
|
+
"url": "^0.11.0",
|
|
72
76
|
"uuid": "^8.3.1"
|
|
73
77
|
},
|
|
74
78
|
"devDependencies": {
|
|
75
79
|
"@fluidframework/build-common": "^1.0.0",
|
|
76
80
|
"@fluidframework/eslint-config-fluid": "^1.0.0",
|
|
77
|
-
"@fluidframework/local-driver-previous": "npm:@fluidframework/local-driver
|
|
78
|
-
"@fluidframework/mocha-test-setup": "^2.0.0-internal.
|
|
81
|
+
"@fluidframework/local-driver-previous": "npm:@fluidframework/local-driver@>=2.0.0-internal.1.4.0 <2.0.0-internal.2.0.0",
|
|
82
|
+
"@fluidframework/mocha-test-setup": "^2.0.0-internal.2.0.0",
|
|
79
83
|
"@rushstack/eslint-config": "^2.5.1",
|
|
80
84
|
"@types/jsrsasign": "^8.0.8",
|
|
81
85
|
"@types/mocha": "^9.1.1",
|
package/src/index.ts
CHANGED
|
@@ -7,5 +7,6 @@ export * from "./localDeltaStorageService";
|
|
|
7
7
|
export * from "./localDocumentDeltaConnection";
|
|
8
8
|
export * from "./localDocumentService";
|
|
9
9
|
export * from "./localDocumentServiceFactory";
|
|
10
|
+
export * from "./localDocumentStorageService";
|
|
10
11
|
export * from "./localResolver";
|
|
11
12
|
export * from "./localSessionStorageDb";
|
|
@@ -3,7 +3,10 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import
|
|
6
|
+
import {
|
|
7
|
+
IDocumentDeltaStorageService,
|
|
8
|
+
IStream,
|
|
9
|
+
} from "@fluidframework/driver-definitions";
|
|
7
10
|
import { ISequencedDocumentMessage } from "@fluidframework/protocol-definitions";
|
|
8
11
|
import { IDatabaseManager } from "@fluidframework/server-services-core";
|
|
9
12
|
import { streamFromMessages } from "@fluidframework/driver-utils";
|
|
@@ -11,7 +14,7 @@ import { streamFromMessages } from "@fluidframework/driver-utils";
|
|
|
11
14
|
/**
|
|
12
15
|
* Provides access to the underlying delta storage on the server for local driver.
|
|
13
16
|
*/
|
|
14
|
-
export class LocalDeltaStorageService implements
|
|
17
|
+
export class LocalDeltaStorageService implements IDocumentDeltaStorageService {
|
|
15
18
|
constructor(
|
|
16
19
|
private readonly tenantId: string,
|
|
17
20
|
private readonly id: string,
|
|
@@ -23,7 +26,7 @@ export class LocalDeltaStorageService implements api.IDocumentDeltaStorageServic
|
|
|
23
26
|
to: number | undefined,
|
|
24
27
|
abortSignal?: AbortSignal,
|
|
25
28
|
cachedOnly?: boolean,
|
|
26
|
-
):
|
|
29
|
+
): IStream<ISequencedDocumentMessage[]> {
|
|
27
30
|
return streamFromMessages(this.getCore(from, to));
|
|
28
31
|
}
|
|
29
32
|
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { TelemetryNullLogger } from "@fluidframework/common-utils";
|
|
7
6
|
import { DocumentDeltaConnection } from "@fluidframework/driver-base";
|
|
8
7
|
import {
|
|
9
8
|
IClient,
|
|
@@ -11,8 +10,9 @@ import {
|
|
|
11
10
|
IDocumentMessage,
|
|
12
11
|
NackErrorType,
|
|
13
12
|
} from "@fluidframework/protocol-definitions";
|
|
13
|
+
import { TelemetryNullLogger } from "@fluidframework/telemetry-utils";
|
|
14
14
|
import { LocalWebSocketServer } from "@fluidframework/server-local-server";
|
|
15
|
-
import
|
|
15
|
+
import { IWebSocketServer } from "@fluidframework/server-services-core";
|
|
16
16
|
import type { Socket } from "socket.io-client";
|
|
17
17
|
|
|
18
18
|
const testProtocolVersions = ["^0.3.0", "^0.2.0", "^0.1.0"];
|
|
@@ -36,7 +36,7 @@ export class LocalDocumentDeltaConnection extends DocumentDeltaConnection {
|
|
|
36
36
|
id: string,
|
|
37
37
|
token: string,
|
|
38
38
|
client: IClient,
|
|
39
|
-
webSocketServer:
|
|
39
|
+
webSocketServer: IWebSocketServer,
|
|
40
40
|
timeoutMs = 60000,
|
|
41
41
|
): Promise<LocalDocumentDeltaConnection> {
|
|
42
42
|
const socket = (webSocketServer as LocalWebSocketServer).createConnection();
|
|
@@ -3,19 +3,24 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import
|
|
6
|
+
import {
|
|
7
|
+
IDocumentDeltaConnection,
|
|
8
|
+
IDocumentDeltaStorageService,
|
|
9
|
+
IDocumentService,
|
|
10
|
+
IDocumentServicePolicies,
|
|
11
|
+
IDocumentStorageService,
|
|
12
|
+
IResolvedUrl,
|
|
13
|
+
} from "@fluidframework/driver-definitions";
|
|
7
14
|
import { IClient } from "@fluidframework/protocol-definitions";
|
|
8
|
-
import
|
|
15
|
+
import { ITokenProvider } from "@fluidframework/routerlicious-driver";
|
|
9
16
|
import { GitManager } from "@fluidframework/server-services-client";
|
|
10
17
|
import { TestHistorian } from "@fluidframework/server-test-utils";
|
|
11
18
|
import { ILocalDeltaConnectionServer } from "@fluidframework/server-local-server";
|
|
12
|
-
import {
|
|
13
|
-
import { LocalDeltaStorageService, LocalDocumentDeltaConnection } from ".";
|
|
14
|
-
|
|
19
|
+
import { LocalDeltaStorageService, LocalDocumentDeltaConnection, LocalDocumentStorageService } from ".";
|
|
15
20
|
/**
|
|
16
21
|
* Basic implementation of a document service for local use.
|
|
17
22
|
*/
|
|
18
|
-
export class LocalDocumentService implements
|
|
23
|
+
export class LocalDocumentService implements IDocumentService {
|
|
19
24
|
/**
|
|
20
25
|
* @param localDeltaConnectionServer - delta connection server for ops
|
|
21
26
|
* @param tokenProvider - token provider
|
|
@@ -23,14 +28,14 @@ export class LocalDocumentService implements api.IDocumentService {
|
|
|
23
28
|
* @param documentId - ID of document
|
|
24
29
|
*/
|
|
25
30
|
constructor(
|
|
26
|
-
public readonly resolvedUrl:
|
|
31
|
+
public readonly resolvedUrl: IResolvedUrl,
|
|
27
32
|
private readonly localDeltaConnectionServer: ILocalDeltaConnectionServer,
|
|
28
|
-
private readonly tokenProvider:
|
|
33
|
+
private readonly tokenProvider: ITokenProvider,
|
|
29
34
|
private readonly tenantId: string,
|
|
30
35
|
private readonly documentId: string,
|
|
31
36
|
private readonly documentDeltaConnectionsMap: Map<string, LocalDocumentDeltaConnection>,
|
|
32
|
-
public readonly policies:
|
|
33
|
-
private readonly innerDocumentService?:
|
|
37
|
+
public readonly policies: IDocumentServicePolicies = {},
|
|
38
|
+
private readonly innerDocumentService?: IDocumentService,
|
|
34
39
|
) { }
|
|
35
40
|
|
|
36
41
|
public dispose() { }
|
|
@@ -38,22 +43,18 @@ export class LocalDocumentService implements api.IDocumentService {
|
|
|
38
43
|
/**
|
|
39
44
|
* Creates and returns a document storage service for local use.
|
|
40
45
|
*/
|
|
41
|
-
public async connectToStorage(): Promise<
|
|
42
|
-
return new
|
|
46
|
+
public async connectToStorage(): Promise<IDocumentStorageService> {
|
|
47
|
+
return new LocalDocumentStorageService(
|
|
43
48
|
this.documentId,
|
|
44
49
|
new GitManager(new TestHistorian(this.localDeltaConnectionServer.testDbFactory.testDatabase)),
|
|
45
|
-
new TelemetryNullLogger(),
|
|
46
50
|
{ minBlobSize: 2048 }, // Test blob aggregation.
|
|
47
|
-
|
|
48
|
-
undefined,
|
|
49
|
-
undefined,
|
|
50
|
-
new GitManager(new TestHistorian(this.localDeltaConnectionServer.testDbFactory.testDatabase)));
|
|
51
|
+
);
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
/**
|
|
54
55
|
* Creates and returns a delta storage service for local use.
|
|
55
56
|
*/
|
|
56
|
-
public async connectToDeltaStorage(): Promise<
|
|
57
|
+
public async connectToDeltaStorage(): Promise<IDocumentDeltaStorageService> {
|
|
57
58
|
if (this.innerDocumentService) {
|
|
58
59
|
return this.innerDocumentService.connectToDeltaStorage();
|
|
59
60
|
}
|
|
@@ -67,7 +68,7 @@ export class LocalDocumentService implements api.IDocumentService {
|
|
|
67
68
|
* Creates and returns a delta stream for local use.
|
|
68
69
|
* @param client - client data
|
|
69
70
|
*/
|
|
70
|
-
public async connectToDeltaStream(client: IClient): Promise<
|
|
71
|
+
public async connectToDeltaStream(client: IClient): Promise<IDocumentDeltaConnection> {
|
|
71
72
|
if (this.policies.storageOnly === true) {
|
|
72
73
|
throw new Error("can't connect to delta stream in storage-only mode");
|
|
73
74
|
}
|
|
@@ -107,14 +108,14 @@ export class LocalDocumentService implements api.IDocumentService {
|
|
|
107
108
|
* @param documentId - ID of document
|
|
108
109
|
*/
|
|
109
110
|
export function createLocalDocumentService(
|
|
110
|
-
resolvedUrl:
|
|
111
|
+
resolvedUrl: IResolvedUrl,
|
|
111
112
|
localDeltaConnectionServer: ILocalDeltaConnectionServer,
|
|
112
|
-
tokenProvider:
|
|
113
|
+
tokenProvider: ITokenProvider,
|
|
113
114
|
tenantId: string,
|
|
114
115
|
documentId: string,
|
|
115
116
|
documentDeltaConnectionsMap: Map<string, LocalDocumentDeltaConnection>,
|
|
116
|
-
policies?:
|
|
117
|
-
innerDocumentService?:
|
|
117
|
+
policies?: IDocumentServicePolicies,
|
|
118
|
+
innerDocumentService?: IDocumentService): IDocumentService {
|
|
118
119
|
return new LocalDocumentService(
|
|
119
120
|
resolvedUrl,
|
|
120
121
|
localDeltaConnectionServer,
|
|
@@ -76,6 +76,7 @@ export class LocalDocumentServiceFactory implements IDocumentServiceFactory {
|
|
|
76
76
|
defaultHash,
|
|
77
77
|
resolvedUrl.endpoints.ordererUrl ?? "",
|
|
78
78
|
resolvedUrl.endpoints.storageUrl ?? "",
|
|
79
|
+
resolvedUrl.endpoints.deltaStorageUrl ?? "",
|
|
79
80
|
quorumValues,
|
|
80
81
|
false, /* enableDiscovery */
|
|
81
82
|
);
|
|
@@ -125,11 +126,11 @@ export class LocalDocumentServiceFactory implements IDocumentServiceFactory {
|
|
|
125
126
|
* @param disconnectReason - The reason of the disconnection.
|
|
126
127
|
*/
|
|
127
128
|
public disconnectClient(clientId: string, disconnectReason: string) {
|
|
128
|
-
|
|
129
|
+
const documentDeltaConnection = this.documentDeltaConnectionsMap.get(clientId);
|
|
130
|
+
if (documentDeltaConnection === undefined) {
|
|
129
131
|
throw new Error(`No client with the id: ${clientId}`);
|
|
130
132
|
}
|
|
131
|
-
|
|
132
|
-
this.documentDeltaConnectionsMap.get(clientId)!.disconnectClient(disconnectReason);
|
|
133
|
+
documentDeltaConnection.disconnectClient(disconnectReason);
|
|
133
134
|
}
|
|
134
135
|
|
|
135
136
|
/**
|
|
@@ -140,10 +141,10 @@ export class LocalDocumentServiceFactory implements IDocumentServiceFactory {
|
|
|
140
141
|
* @param message - A message about the nack for debugging/logging/telemetry purposes.
|
|
141
142
|
*/
|
|
142
143
|
public nackClient(clientId: string, code?: number, type?: NackErrorType, message?: any) {
|
|
143
|
-
|
|
144
|
+
const documentDeltaConnection = this.documentDeltaConnectionsMap.get(clientId);
|
|
145
|
+
if (documentDeltaConnection === undefined) {
|
|
144
146
|
throw new Error(`No client with the id: ${clientId}`);
|
|
145
147
|
}
|
|
146
|
-
|
|
147
|
-
this.documentDeltaConnectionsMap.get(clientId)!.nackClient(code, type, message);
|
|
148
|
+
documentDeltaConnection.nackClient(code, type, message);
|
|
148
149
|
}
|
|
149
150
|
}
|
|
@@ -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