@fluidframework/local-driver 2.0.0-internal.3.0.2 → 2.0.0-internal.3.2.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.
Files changed (36) hide show
  1. package/.eslintrc.js +19 -22
  2. package/.mocharc.js +2 -2
  3. package/dist/auth.d.ts.map +1 -1
  4. package/dist/auth.js +2 -2
  5. package/dist/auth.js.map +1 -1
  6. package/dist/localDeltaStorageService.d.ts.map +1 -1
  7. package/dist/localDeltaStorageService.js.map +1 -1
  8. package/dist/localDocumentDeltaConnection.d.ts.map +1 -1
  9. package/dist/localDocumentDeltaConnection.js.map +1 -1
  10. package/dist/localDocumentService.d.ts.map +1 -1
  11. package/dist/localDocumentService.js.map +1 -1
  12. package/dist/localDocumentServiceFactory.d.ts.map +1 -1
  13. package/dist/localDocumentServiceFactory.js +3 -2
  14. package/dist/localDocumentServiceFactory.js.map +1 -1
  15. package/dist/localDocumentStorageService.d.ts.map +1 -1
  16. package/dist/localDocumentStorageService.js +4 -3
  17. package/dist/localDocumentStorageService.js.map +1 -1
  18. package/dist/localResolver.d.ts.map +1 -1
  19. package/dist/localResolver.js.map +1 -1
  20. package/dist/localSessionStorageDb.d.ts.map +1 -1
  21. package/dist/localSessionStorageDb.js.map +1 -1
  22. package/dist/packageVersion.d.ts +1 -1
  23. package/dist/packageVersion.js +1 -1
  24. package/dist/packageVersion.js.map +1 -1
  25. package/package.json +37 -36
  26. package/prettier.config.cjs +1 -1
  27. package/src/auth.ts +35 -29
  28. package/src/localDeltaStorageService.ts +26 -29
  29. package/src/localDocumentDeltaConnection.ts +89 -85
  30. package/src/localDocumentService.ts +106 -98
  31. package/src/localDocumentServiceFactory.ts +126 -117
  32. package/src/localDocumentStorageService.ts +17 -10
  33. package/src/localResolver.ts +55 -55
  34. package/src/localSessionStorageDb.ts +267 -261
  35. package/src/packageVersion.ts +1 -1
  36. package/tsconfig.json +9 -13
@@ -12,299 +12,305 @@ 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
- * @param collectionName - data type of the collection, e.g. blobs, deltas, trees, etc.
17
- */
18
- constructor(private readonly collectionName: string) { }
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
- public aggregate(pipeline: any, options?: any): any {
21
- throw new Error("Method Not Implemented");
22
- }
20
+ public aggregate(pipeline: any, options?: any): any {
21
+ throw new Error("Method Not Implemented");
22
+ }
23
23
 
24
- public async updateMany(filter: any, set: any, addToSet: any): Promise<void> {
25
- throw new Error("Method Not Implemented");
26
- }
27
- public async distinct(key: any, query: any): Promise<any> {
28
- throw new Error("Method Not Implemented");
29
- }
24
+ public async updateMany(filter: any, set: any, addToSet: any): Promise<void> {
25
+ throw new Error("Method Not Implemented");
26
+ }
27
+ public async distinct(key: any, query: any): Promise<any> {
28
+ throw new Error("Method Not Implemented");
29
+ }
30
30
 
31
- /**
32
- * {@inheritDoc @fluidframework/server-services-core#ICollection.find}
33
- */
34
- /*
35
- * Each query key consists of several keys separated by '.' e.g: "operation.sequenceNumber".
36
- * The hierarchical syntax allows finding nested key patterns.
37
- */
38
- public async find(query: any, sort: any): Promise<any[]> {
39
- // split the keys and get the corresponding value
40
- function getValueByKey(propertyBag, key: string) {
41
- const keys = key.split(".");
42
- let value = propertyBag;
43
- keys.forEach((splitKey) => {
44
- value = value[splitKey];
45
- });
46
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
47
- return value;
48
- }
31
+ /**
32
+ * {@inheritDoc @fluidframework/server-services-core#ICollection.find}
33
+ */
34
+ /*
35
+ * Each query key consists of several keys separated by '.' e.g: "operation.sequenceNumber".
36
+ * The hierarchical syntax allows finding nested key patterns.
37
+ */
38
+ public async find(query: any, sort: any): Promise<any[]> {
39
+ // split the keys and get the corresponding value
40
+ function getValueByKey(propertyBag, key: string) {
41
+ const keys = key.split(".");
42
+ let value = propertyBag;
43
+ keys.forEach((splitKey) => {
44
+ value = value[splitKey];
45
+ });
46
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
47
+ return value;
48
+ }
49
49
 
50
- // getting keys of the query we are trying to find
51
- const queryKeys = Object.keys(query);
52
- let filteredCollection = this.getAllInternal();
53
- queryKeys.forEach((key) => {
54
- if (!query[key]) {
55
- return;
56
- }
57
- if (query[key].$gt > 0 || query[key].$lt > 0) {
58
- if (query[key].$gt > 0) {
59
- filteredCollection = filteredCollection.filter(
60
- (value) => getValueByKey(value, key) > query[key].$gt);
61
- }
62
- if (query[key].$lt > 0) {
63
- filteredCollection = filteredCollection.filter(
64
- (value) => getValueByKey(value, key) < query[key].$lt);
65
- }
66
- } else {
67
- filteredCollection = filteredCollection.filter(
68
- (value) => getValueByKey(value, key) === query[key]);
69
- }
70
- });
50
+ // getting keys of the query we are trying to find
51
+ const queryKeys = Object.keys(query);
52
+ let filteredCollection = this.getAllInternal();
53
+ queryKeys.forEach((key) => {
54
+ if (!query[key]) {
55
+ return;
56
+ }
57
+ if (query[key].$gt > 0 || query[key].$lt > 0) {
58
+ if (query[key].$gt > 0) {
59
+ filteredCollection = filteredCollection.filter(
60
+ (value) => getValueByKey(value, key) > query[key].$gt,
61
+ );
62
+ }
63
+ if (query[key].$lt > 0) {
64
+ filteredCollection = filteredCollection.filter(
65
+ (value) => getValueByKey(value, key) < query[key].$lt,
66
+ );
67
+ }
68
+ } else {
69
+ filteredCollection = filteredCollection.filter(
70
+ (value) => getValueByKey(value, key) === query[key],
71
+ );
72
+ }
73
+ });
71
74
 
72
- if (sort && Object.keys(sort).length === 1) {
73
- // eslint-disable-next-line no-inner-declarations
74
- function compare(a, b) {
75
- const sortKey = Object.keys(sort)[0];
76
- return sort[sortKey] === 1
77
- ? getValueByKey(a, sortKey) - getValueByKey(b, sortKey)
78
- : getValueByKey(b, sortKey) - getValueByKey(a, sortKey);
79
- }
75
+ if (sort && Object.keys(sort).length === 1) {
76
+ // eslint-disable-next-line no-inner-declarations
77
+ function compare(a, b) {
78
+ const sortKey = Object.keys(sort)[0];
79
+ return sort[sortKey] === 1
80
+ ? getValueByKey(a, sortKey) - getValueByKey(b, sortKey)
81
+ : getValueByKey(b, sortKey) - getValueByKey(a, sortKey);
82
+ }
80
83
 
81
- filteredCollection = filteredCollection.sort(compare);
82
- }
83
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
84
- return filteredCollection;
85
- }
84
+ filteredCollection = filteredCollection.sort(compare);
85
+ }
86
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
87
+ return filteredCollection;
88
+ }
86
89
 
87
- /**
88
- * {@inheritDoc @fluidframework/server-services-core#ICollection.findAll}
89
- */
90
- public async findAll(): Promise<any[]> {
91
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
92
- return this.getAllInternal();
93
- }
90
+ /**
91
+ * {@inheritDoc @fluidframework/server-services-core#ICollection.findAll}
92
+ */
93
+ public async findAll(): Promise<any[]> {
94
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
95
+ return this.getAllInternal();
96
+ }
94
97
 
95
- /**
96
- * {@inheritDoc @fluidframework/server-services-core#ICollection.findOne}
97
- */
98
- /*
99
- * Query is expected to have a member "_id" which is a string used to find value in the database.
100
- */
101
- public async findOne(query: any): Promise<any> {
102
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
103
- return this.findOneInternal(query);
104
- }
98
+ /**
99
+ * {@inheritDoc @fluidframework/server-services-core#ICollection.findOne}
100
+ */
101
+ /*
102
+ * Query is expected to have a member "_id" which is a string used to find value in the database.
103
+ */
104
+ public async findOne(query: any): Promise<any> {
105
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
106
+ return this.findOneInternal(query);
107
+ }
105
108
 
106
- /**
107
- * {@inheritDoc @fluidframework/server-services-core#ICollection.update}
108
- */
109
- /*
110
- * Query is expected to have a member "_id" which is a string used to find value in the database.
111
- */
112
- public async update(query: any, set: any, addToSet: any): Promise<void> {
113
- const value = this.findOneInternal(query);
114
- if (!value) {
115
- throw new Error("Not found");
116
- } else {
117
- for (const key of Object.keys(set)) {
118
- value[key] = set[key];
119
- }
120
- this.insertInternal(value);
121
- }
122
- }
109
+ /**
110
+ * {@inheritDoc @fluidframework/server-services-core#ICollection.update}
111
+ */
112
+ /*
113
+ * Query is expected to have a member "_id" which is a string used to find value in the database.
114
+ */
115
+ public async update(query: any, set: any, addToSet: any): Promise<void> {
116
+ const value = this.findOneInternal(query);
117
+ if (!value) {
118
+ throw new Error("Not found");
119
+ } else {
120
+ for (const key of Object.keys(set)) {
121
+ value[key] = set[key];
122
+ }
123
+ this.insertInternal(value);
124
+ }
125
+ }
123
126
 
124
- /**
125
- * {@inheritDoc @fluidframework/server-services-core#ICollection.upsert}
126
- */
127
- /*
128
- * Query is expected to have a member "_id" which is a string used to find value in the database.
129
- */
130
- public async upsert(query: any, set: any, addToSet: any): Promise<void> {
131
- const value = this.findOneInternal(query);
132
- if (!value) {
133
- this.insertInternal(set);
134
- } else {
135
- for (const key of Object.keys(set)) {
136
- value[key] = set[key];
137
- }
138
- this.insertInternal(value);
139
- }
140
- }
127
+ /**
128
+ * {@inheritDoc @fluidframework/server-services-core#ICollection.upsert}
129
+ */
130
+ /*
131
+ * Query is expected to have a member "_id" which is a string used to find value in the database.
132
+ */
133
+ public async upsert(query: any, set: any, addToSet: any): Promise<void> {
134
+ const value = this.findOneInternal(query);
135
+ if (!value) {
136
+ this.insertInternal(set);
137
+ } else {
138
+ for (const key of Object.keys(set)) {
139
+ value[key] = set[key];
140
+ }
141
+ this.insertInternal(value);
142
+ }
143
+ }
141
144
 
142
- /**
143
- * {@inheritDoc @fluidframework/server-services-core#ICollection.insertOne}
144
- */
145
- /*
146
- * Value is expected to have a member "_id" which is a string used to search in the database.
147
- */
148
- public async insertOne(value: any): Promise<any> {
149
- const presentVal = this.findOneInternal(value);
150
- // Only raise error when the object is present and the value is not equal.
151
- if (presentVal) {
152
- if (JSON.stringify(presentVal) === JSON.stringify(value)) {
153
- return;
154
- }
155
- throw new Error("Existing Object!!");
156
- }
145
+ /**
146
+ * {@inheritDoc @fluidframework/server-services-core#ICollection.insertOne}
147
+ */
148
+ /*
149
+ * Value is expected to have a member "_id" which is a string used to search in the database.
150
+ */
151
+ public async insertOne(value: any): Promise<any> {
152
+ const presentVal = this.findOneInternal(value);
153
+ // Only raise error when the object is present and the value is not equal.
154
+ if (presentVal) {
155
+ if (JSON.stringify(presentVal) === JSON.stringify(value)) {
156
+ return;
157
+ }
158
+ throw new Error("Existing Object!!");
159
+ }
157
160
 
158
- return this.insertInternal(value);
159
- }
161
+ return this.insertInternal(value);
162
+ }
160
163
 
161
- /**
162
- * {@inheritDoc @fluidframework/server-services-core#ICollection.findOrCreate}
163
- */
164
- /*
165
- * Value and query are expected to have a member "_id" which is a string used to search or insert in the database.
166
- */
167
- public async findOrCreate(query: any, value: any): Promise<{ value: any; existing: boolean; }> {
168
- const existing = this.findOneInternal(query);
169
- if (existing) {
170
- return { value: existing, existing: true };
171
- }
172
- this.insertInternal(value);
173
- return { value, existing: false };
174
- }
164
+ /**
165
+ * {@inheritDoc @fluidframework/server-services-core#ICollection.findOrCreate}
166
+ */
167
+ /*
168
+ * Value and query are expected to have a member "_id" which is a string used to search or insert in the database.
169
+ */
170
+ public async findOrCreate(query: any, value: any): Promise<{ value: any; existing: boolean }> {
171
+ const existing = this.findOneInternal(query);
172
+ if (existing) {
173
+ return { value: existing, existing: true };
174
+ }
175
+ this.insertInternal(value);
176
+ return { value, existing: false };
177
+ }
175
178
 
176
- /**
177
- * {@inheritDoc @fluidframework/server-services-core#ICollection.insertMany}
178
- */
179
- /*
180
- * Each element in values is expected to have a member "_id" which is a string used to insert in the database.
181
- */
182
- public async insertMany(values: any[], ordered: boolean): Promise<void> {
183
- this.insertInternal(...values);
184
- }
179
+ /**
180
+ * {@inheritDoc @fluidframework/server-services-core#ICollection.insertMany}
181
+ */
182
+ /*
183
+ * Each element in values is expected to have a member "_id" which is a string used to insert in the database.
184
+ */
185
+ public async insertMany(values: any[], ordered: boolean): Promise<void> {
186
+ this.insertInternal(...values);
187
+ }
185
188
 
186
- /**
187
- * {@inheritDoc @fluidframework/server-services-core#ICollection.deleteOne}
188
- */
189
- public async deleteOne(query: any): Promise<any> {
190
- throw new Error("Method not implemented.");
191
- }
189
+ /**
190
+ * {@inheritDoc @fluidframework/server-services-core#ICollection.deleteOne}
191
+ */
192
+ public async deleteOne(query: any): Promise<any> {
193
+ throw new Error("Method not implemented.");
194
+ }
192
195
 
193
- /**
194
- * {@inheritDoc @fluidframework/server-services-core#ICollection.deleteMany}
195
- */
196
- public async deleteMany(query: any): Promise<any> {
197
- throw new Error("Method not implemented.");
198
- }
196
+ /**
197
+ * {@inheritDoc @fluidframework/server-services-core#ICollection.deleteMany}
198
+ */
199
+ public async deleteMany(query: any): Promise<any> {
200
+ throw new Error("Method not implemented.");
201
+ }
199
202
 
200
- /**
201
- * {@inheritDoc @fluidframework/server-services-core#ICollection.createIndex}
202
- */
203
- public async createIndex(index: any, unique: boolean): Promise<void> {
204
- throw new Error("Method not implemented.");
205
- }
203
+ /**
204
+ * {@inheritDoc @fluidframework/server-services-core#ICollection.createIndex}
205
+ */
206
+ public async createIndex(index: any, unique: boolean): Promise<void> {
207
+ throw new Error("Method not implemented.");
208
+ }
206
209
 
207
- /**
208
- * Return all values in the database
209
- */
210
- private getAllInternal(): any[] {
211
- const values: string[] = [];
212
- for (let i = 0; i < sessionStorage.length; i++) {
213
- const key = sessionStorage.key(i);
214
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
215
- if (key!.startsWith(this.collectionName)) {
216
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
217
- values.push(JSON.parse(sessionStorage.getItem(key!)!));
218
- }
219
- }
220
- return values;
221
- }
210
+ /**
211
+ * Return all values in the database
212
+ */
213
+ private getAllInternal(): any[] {
214
+ const values: string[] = [];
215
+ for (let i = 0; i < sessionStorage.length; i++) {
216
+ const key = sessionStorage.key(i);
217
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
218
+ if (key!.startsWith(this.collectionName)) {
219
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
220
+ values.push(JSON.parse(sessionStorage.getItem(key!)!));
221
+ }
222
+ }
223
+ return values;
224
+ }
222
225
 
223
- /**
224
- * Inserts values into the session storge.
225
- * Values are expected to have a member "_id" which is a unique id, otherwise will be assigned one
226
- *
227
- * @param values - data to insert to the database
228
- */
229
- private insertInternal(...values: any[]) {
230
- for (const value of values) {
231
- if (value) {
232
- if (!value._id) {
233
- value._id = uuid();
234
- }
235
- sessionStorage.setItem(`${this.collectionName}-${value._id}`, JSON.stringify(value));
236
- }
237
- }
238
- }
226
+ /**
227
+ * Inserts values into the session storge.
228
+ * Values are expected to have a member "_id" which is a unique id, otherwise will be assigned one
229
+ *
230
+ * @param values - data to insert to the database
231
+ */
232
+ private insertInternal(...values: any[]) {
233
+ for (const value of values) {
234
+ if (value) {
235
+ if (!value._id) {
236
+ value._id = uuid();
237
+ }
238
+ sessionStorage.setItem(
239
+ `${this.collectionName}-${value._id}`,
240
+ JSON.stringify(value),
241
+ );
242
+ }
243
+ }
244
+ }
239
245
 
240
- /**
241
- * Finds the query in session storage and returns its value.
242
- * Returns null if query is not found.
243
- * Query is expected to have a member "_id" which is a unique id.
244
- *
245
- * @param query - what to find in the database
246
- */
247
- private findOneInternal(query: any): any {
248
- if (query._id) {
249
- const json = sessionStorage.getItem(`${this.collectionName}-${query._id}`);
250
- if (json) {
251
- return JSON.parse(json);
252
- }
253
- } else {
254
- const queryKeys = Object.keys(query);
255
- for (let i = 0; i < sessionStorage.length; i++) {
256
- const ssKey = sessionStorage.key(i);
257
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
258
- if (!ssKey!.startsWith(this.collectionName)) {
259
- continue;
260
- }
261
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
262
- const value = JSON.parse(sessionStorage.getItem(ssKey!)!);
263
- let foundMismatch = false;
264
- for (const qk of queryKeys) {
265
- if (value[qk] !== query[qk]) {
266
- foundMismatch = true;
267
- break;
268
- }
269
- }
246
+ /**
247
+ * Finds the query in session storage and returns its value.
248
+ * Returns null if query is not found.
249
+ * Query is expected to have a member "_id" which is a unique id.
250
+ *
251
+ * @param query - what to find in the database
252
+ */
253
+ private findOneInternal(query: any): any {
254
+ if (query._id) {
255
+ const json = sessionStorage.getItem(`${this.collectionName}-${query._id}`);
256
+ if (json) {
257
+ return JSON.parse(json);
258
+ }
259
+ } else {
260
+ const queryKeys = Object.keys(query);
261
+ for (let i = 0; i < sessionStorage.length; i++) {
262
+ const ssKey = sessionStorage.key(i);
263
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
264
+ if (!ssKey!.startsWith(this.collectionName)) {
265
+ continue;
266
+ }
267
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
268
+ const value = JSON.parse(sessionStorage.getItem(ssKey!)!);
269
+ let foundMismatch = false;
270
+ for (const qk of queryKeys) {
271
+ if (value[qk] !== query[qk]) {
272
+ foundMismatch = true;
273
+ break;
274
+ }
275
+ }
270
276
 
271
- if (!foundMismatch) {
272
- return value;
273
- }
274
- }
275
- }
276
- return null;
277
- }
277
+ if (!foundMismatch) {
278
+ return value;
279
+ }
280
+ }
281
+ }
282
+ return null;
283
+ }
278
284
  }
279
285
 
280
286
  /**
281
287
  * A database for testing that stores data in the browsers session storage
282
288
  */
283
289
  class LocalSessionStorageDb extends EventEmitter implements IDb {
284
- private readonly collections = new Map<string, LocalSessionStorageCollection<any>>();
285
- public async close(): Promise<void> { }
286
- public collection<T>(name: string): ICollection<T> {
287
- if (!this.collections.has(name)) {
288
- this.collections.set(name, new LocalSessionStorageCollection<T>(name));
289
- }
290
- return this.collections.get(name) as LocalSessionStorageCollection<T>;
291
- }
290
+ private readonly collections = new Map<string, LocalSessionStorageCollection<any>>();
291
+ public async close(): Promise<void> {}
292
+ public collection<T>(name: string): ICollection<T> {
293
+ if (!this.collections.has(name)) {
294
+ this.collections.set(name, new LocalSessionStorageCollection<T>(name));
295
+ }
296
+ return this.collections.get(name) as LocalSessionStorageCollection<T>;
297
+ }
292
298
 
293
- public async dropCollection(name: string): Promise<boolean> {
294
- if (!this.collections.has(name)) {
295
- return true;
296
- }
297
- this.collections.delete(name);
298
- return true;
299
- }
299
+ public async dropCollection(name: string): Promise<boolean> {
300
+ if (!this.collections.has(name)) {
301
+ return true;
302
+ }
303
+ this.collections.delete(name);
304
+ return true;
305
+ }
300
306
  }
301
307
 
302
308
  /**
303
309
  * A database factory for testing that stores data in the browsers session storage
304
310
  */
305
311
  export class LocalSessionStorageDbFactory implements ITestDbFactory {
306
- public readonly testDatabase: IDb = new LocalSessionStorageDb();
307
- public async connect(): Promise<IDb> {
308
- return this.testDatabase;
309
- }
312
+ public readonly testDatabase: IDb = new LocalSessionStorageDb();
313
+ public async connect(): Promise<IDb> {
314
+ return this.testDatabase;
315
+ }
310
316
  }
@@ -6,4 +6,4 @@
6
6
  */
7
7
 
8
8
  export const pkgName = "@fluidframework/local-driver";
9
- export const pkgVersion = "2.0.0-internal.3.0.2";
9
+ export const pkgVersion = "2.0.0-internal.3.2.0";
package/tsconfig.json CHANGED
@@ -1,14 +1,10 @@
1
1
  {
2
- "extends": "@fluidframework/build-common/ts-common-config.json",
3
- "exclude": [
4
- "src/test/**/*"
5
- ],
6
- "compilerOptions": {
7
- "rootDir": "./src",
8
- "outDir": "./dist",
9
- "composite": true
10
- },
11
- "include": [
12
- "src/**/*"
13
- ]
14
- }
2
+ "extends": "@fluidframework/build-common/ts-common-config.json",
3
+ "exclude": ["src/test/**/*"],
4
+ "compilerOptions": {
5
+ "rootDir": "./src",
6
+ "outDir": "./dist",
7
+ "composite": true,
8
+ },
9
+ "include": ["src/**/*"],
10
+ }