@fluidframework/local-driver 1.4.0-115997 → 2.0.0-dev-rc.1.0.0.224419

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 (123) hide show
  1. package/.eslintrc.js +19 -22
  2. package/.mocharc.js +12 -0
  3. package/CHANGELOG.md +127 -0
  4. package/README.md +38 -0
  5. package/api-extractor-lint.json +4 -0
  6. package/api-extractor.json +4 -0
  7. package/api-report/local-driver.api.md +129 -0
  8. package/dist/{auth.js → auth.cjs} +8 -6
  9. package/dist/auth.cjs.map +1 -0
  10. package/dist/auth.d.ts.map +1 -1
  11. package/dist/index.cjs +24 -0
  12. package/dist/index.cjs.map +1 -0
  13. package/dist/index.d.ts +7 -6
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/local-driver-alpha.d.ts +110 -0
  16. package/dist/local-driver-beta.d.ts +75 -0
  17. package/dist/local-driver-public.d.ts +75 -0
  18. package/dist/local-driver-untrimmed.d.ts +226 -0
  19. package/dist/localCreateDocument.cjs +28 -0
  20. package/dist/localCreateDocument.cjs.map +1 -0
  21. package/dist/localCreateDocument.d.ts +8 -0
  22. package/dist/localCreateDocument.d.ts.map +1 -0
  23. package/dist/{localDeltaStorageService.js → localDeltaStorageService.cjs} +3 -2
  24. package/dist/localDeltaStorageService.cjs.map +1 -0
  25. package/dist/localDeltaStorageService.d.ts +4 -3
  26. package/dist/localDeltaStorageService.d.ts.map +1 -1
  27. package/dist/{localDocumentDeltaConnection.js → localDocumentDeltaConnection.cjs} +9 -11
  28. package/dist/localDocumentDeltaConnection.cjs.map +1 -0
  29. package/dist/localDocumentDeltaConnection.d.ts +5 -4
  30. package/dist/localDocumentDeltaConnection.d.ts.map +1 -1
  31. package/dist/{localDocumentService.js → localDocumentService.cjs} +15 -30
  32. package/dist/localDocumentService.cjs.map +1 -0
  33. package/dist/localDocumentService.d.ts +15 -11
  34. package/dist/localDocumentService.d.ts.map +1 -1
  35. package/dist/{localDocumentServiceFactory.js → localDocumentServiceFactory.cjs} +14 -31
  36. package/dist/localDocumentServiceFactory.cjs.map +1 -0
  37. package/dist/localDocumentServiceFactory.d.ts +3 -2
  38. package/dist/localDocumentServiceFactory.d.ts.map +1 -1
  39. package/dist/localDocumentStorageService.cjs +88 -0
  40. package/dist/localDocumentStorageService.cjs.map +1 -0
  41. package/dist/localDocumentStorageService.d.ts +30 -0
  42. package/dist/localDocumentStorageService.d.ts.map +1 -0
  43. package/dist/{localResolver.js → localResolver.cjs} +10 -6
  44. package/dist/localResolver.cjs.map +1 -0
  45. package/dist/localResolver.d.ts +5 -0
  46. package/dist/localResolver.d.ts.map +1 -1
  47. package/dist/{localSessionStorageDb.js → localSessionStorageDb.cjs} +26 -18
  48. package/dist/localSessionStorageDb.cjs.map +1 -0
  49. package/dist/localSessionStorageDb.d.ts +1 -1
  50. package/dist/localSessionStorageDb.d.ts.map +1 -1
  51. package/dist/tsdoc-metadata.json +11 -0
  52. package/lib/auth.d.mts +12 -0
  53. package/lib/auth.d.mts.map +1 -0
  54. package/lib/auth.mjs +40 -0
  55. package/lib/auth.mjs.map +1 -0
  56. package/lib/index.d.mts +12 -0
  57. package/lib/index.d.mts.map +1 -0
  58. package/lib/index.mjs +12 -0
  59. package/lib/index.mjs.map +1 -0
  60. package/lib/local-driver-alpha.d.mts +110 -0
  61. package/lib/local-driver-beta.d.mts +75 -0
  62. package/lib/local-driver-public.d.mts +75 -0
  63. package/lib/local-driver-untrimmed.d.mts +226 -0
  64. package/lib/localCreateDocument.d.mts +8 -0
  65. package/lib/localCreateDocument.d.mts.map +1 -0
  66. package/lib/localCreateDocument.mjs +24 -0
  67. package/lib/localCreateDocument.mjs.map +1 -0
  68. package/lib/localDeltaStorageService.d.mts +20 -0
  69. package/lib/localDeltaStorageService.d.mts.map +1 -0
  70. package/lib/localDeltaStorageService.mjs +32 -0
  71. package/lib/localDeltaStorageService.mjs.map +1 -0
  72. package/lib/localDocumentDeltaConnection.d.mts +48 -0
  73. package/lib/localDocumentDeltaConnection.d.mts.map +1 -0
  74. package/lib/localDocumentDeltaConnection.mjs +86 -0
  75. package/lib/localDocumentDeltaConnection.mjs.map +1 -0
  76. package/lib/localDocumentService.d.mts +56 -0
  77. package/lib/localDocumentService.d.mts.map +1 -0
  78. package/lib/localDocumentService.mjs +84 -0
  79. package/lib/localDocumentService.mjs.map +1 -0
  80. package/lib/localDocumentServiceFactory.d.mts +45 -0
  81. package/lib/localDocumentServiceFactory.d.mts.map +1 -0
  82. package/lib/localDocumentServiceFactory.mjs +80 -0
  83. package/lib/localDocumentServiceFactory.mjs.map +1 -0
  84. package/lib/localDocumentStorageService.d.mts +30 -0
  85. package/lib/localDocumentStorageService.d.mts.map +1 -0
  86. package/lib/localDocumentStorageService.mjs +84 -0
  87. package/lib/localDocumentStorageService.mjs.map +1 -0
  88. package/lib/localResolver.d.mts +31 -0
  89. package/lib/localResolver.d.mts.map +1 -0
  90. package/lib/localResolver.mjs +74 -0
  91. package/lib/localResolver.mjs.map +1 -0
  92. package/lib/localSessionStorageDb.d.mts +11 -0
  93. package/lib/localSessionStorageDb.d.mts.map +1 -0
  94. package/lib/localSessionStorageDb.mjs +292 -0
  95. package/lib/localSessionStorageDb.mjs.map +1 -0
  96. package/package.json +102 -59
  97. package/prettier.config.cjs +8 -0
  98. package/src/auth.ts +42 -33
  99. package/src/index.ts +7 -6
  100. package/src/localCreateDocument.ts +48 -0
  101. package/src/localDeltaStorageService.ts +28 -27
  102. package/src/localDocumentDeltaConnection.ts +91 -88
  103. package/src/localDocumentService.ts +117 -97
  104. package/src/localDocumentServiceFactory.ts +95 -123
  105. package/src/localDocumentStorageService.ts +131 -0
  106. package/src/localResolver.ts +57 -59
  107. package/src/localSessionStorageDb.ts +272 -265
  108. package/tsc-multi.test.json +4 -0
  109. package/tsconfig.json +11 -13
  110. package/dist/auth.js.map +0 -1
  111. package/dist/index.js +0 -23
  112. package/dist/index.js.map +0 -1
  113. package/dist/localDeltaStorageService.js.map +0 -1
  114. package/dist/localDocumentDeltaConnection.js.map +0 -1
  115. package/dist/localDocumentService.js.map +0 -1
  116. package/dist/localDocumentServiceFactory.js.map +0 -1
  117. package/dist/localResolver.js.map +0 -1
  118. package/dist/localSessionStorageDb.js.map +0 -1
  119. package/dist/packageVersion.d.ts +0 -9
  120. package/dist/packageVersion.d.ts.map +0 -1
  121. package/dist/packageVersion.js +0 -12
  122. package/dist/packageVersion.js.map +0 -1
  123. package/src/packageVersion.ts +0 -9
@@ -12,302 +12,309 @@ 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
- private readonly collectionName: string;
16
- constructor(namespace, name) {
17
- this.collectionName = `${namespace}-${name}`;
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
- 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
+ public async findAndUpdate(query: any, value: T): Promise<{ value: T; existing: boolean }> {
31
+ throw new Error("Method not implemented.");
32
+ }
30
33
 
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
- }
34
+ /**
35
+ * {@inheritDoc @fluidframework/server-services-core#ICollection.find}
36
+ */
37
+ /*
38
+ * Each query key consists of several keys separated by '.' e.g: "operation.sequenceNumber".
39
+ * The hierarchical syntax allows finding nested key patterns.
40
+ */
41
+ public async find(query: any, sort: any): Promise<any[]> {
42
+ // split the keys and get the corresponding value
43
+ function getValueByKey(propertyBag, key: string) {
44
+ const keys = key.split(".");
45
+ let value = propertyBag;
46
+ keys.forEach((splitKey) => {
47
+ value = value[splitKey];
48
+ });
49
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
50
+ return value;
51
+ }
49
52
 
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
- });
53
+ // getting keys of the query we are trying to find
54
+ const queryKeys = Object.keys(query);
55
+ let filteredCollection = this.getAllInternal();
56
+ queryKeys.forEach((key) => {
57
+ if (!query[key]) {
58
+ return;
59
+ }
60
+ if (query[key].$gt > 0 || query[key].$lt > 0) {
61
+ if (query[key].$gt > 0) {
62
+ filteredCollection = filteredCollection.filter(
63
+ (value) => getValueByKey(value, key) > query[key].$gt,
64
+ );
65
+ }
66
+ if (query[key].$lt > 0) {
67
+ filteredCollection = filteredCollection.filter(
68
+ (value) => getValueByKey(value, key) < query[key].$lt,
69
+ );
70
+ }
71
+ } else {
72
+ filteredCollection = filteredCollection.filter(
73
+ (value) => getValueByKey(value, key) === query[key],
74
+ );
75
+ }
76
+ });
71
77
 
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
- }
78
+ if (sort && Object.keys(sort).length === 1) {
79
+ // eslint-disable-next-line no-inner-declarations
80
+ function compare(a, b) {
81
+ const sortKey = Object.keys(sort)[0];
82
+ return sort[sortKey] === 1
83
+ ? getValueByKey(a, sortKey) - getValueByKey(b, sortKey)
84
+ : getValueByKey(b, sortKey) - getValueByKey(a, sortKey);
85
+ }
80
86
 
81
- filteredCollection = filteredCollection.sort(compare);
82
- }
83
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
84
- return filteredCollection;
85
- }
87
+ filteredCollection = filteredCollection.sort(compare);
88
+ }
89
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
90
+ return filteredCollection;
91
+ }
86
92
 
87
- /**
88
- * {@inheritDoc @fluidframework/server-services-core#ICollection.findAll}
89
- */
90
- public async findAll(): Promise<any[]> {
91
- return Promise.resolve(this.getAllInternal());
92
- }
93
+ /**
94
+ * {@inheritDoc @fluidframework/server-services-core#ICollection.findAll}
95
+ */
96
+ public async findAll(): Promise<any[]> {
97
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
98
+ return this.getAllInternal();
99
+ }
93
100
 
94
- /**
95
- * {@inheritDoc @fluidframework/server-services-core#ICollection.findOne}
96
- */
97
- /*
98
- * Query is expected to have a member "_id" which is a string used to find value in the database.
99
- */
100
- public async findOne(query: any): Promise<any> {
101
- return Promise.resolve(this.findOneInternal(query));
102
- }
101
+ /**
102
+ * {@inheritDoc @fluidframework/server-services-core#ICollection.findOne}
103
+ */
104
+ /*
105
+ * Query is expected to have a member "_id" which is a string used to find value in the database.
106
+ */
107
+ public async findOne(query: any): Promise<any> {
108
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
109
+ return this.findOneInternal(query);
110
+ }
103
111
 
104
- /**
105
- * {@inheritDoc @fluidframework/server-services-core#ICollection.update}
106
- */
107
- /*
108
- * Query is expected to have a member "_id" which is a string used to find value in the database.
109
- */
110
- public async update(query: any, set: any, addToSet: any): Promise<void> {
111
- const value = this.findOneInternal(query);
112
- if (!value) {
113
- throw new Error("Not found");
114
- } else {
115
- for (const key of Object.keys(set)) {
116
- value[key] = set[key];
117
- }
118
- this.insertInternal(value);
119
- }
120
- }
112
+ /**
113
+ * {@inheritDoc @fluidframework/server-services-core#ICollection.update}
114
+ */
115
+ /*
116
+ * Query is expected to have a member "_id" which is a string used to find value in the database.
117
+ */
118
+ public async update(query: any, set: any, addToSet: any): Promise<void> {
119
+ const value = this.findOneInternal(query);
120
+ if (!value) {
121
+ throw new Error("Not found");
122
+ } else {
123
+ for (const key of Object.keys(set)) {
124
+ value[key] = set[key];
125
+ }
126
+ this.insertInternal(value);
127
+ }
128
+ }
121
129
 
122
- /**
123
- * {@inheritDoc @fluidframework/server-services-core#ICollection.upsert}
124
- */
125
- /*
126
- * Query is expected to have a member "_id" which is a string used to find value in the database.
127
- */
128
- public async upsert(query: any, set: any, addToSet: any): Promise<void> {
129
- const value = this.findOneInternal(query);
130
- if (!value) {
131
- this.insertInternal(set);
132
- } else {
133
- for (const key of Object.keys(set)) {
134
- value[key] = set[key];
135
- }
136
- this.insertInternal(value);
137
- }
138
- }
130
+ /**
131
+ * {@inheritDoc @fluidframework/server-services-core#ICollection.upsert}
132
+ */
133
+ /*
134
+ * Query is expected to have a member "_id" which is a string used to find value in the database.
135
+ */
136
+ public async upsert(query: any, set: any, addToSet: any): Promise<void> {
137
+ const value = this.findOneInternal(query);
138
+ if (!value) {
139
+ this.insertInternal(set);
140
+ } else {
141
+ for (const key of Object.keys(set)) {
142
+ value[key] = set[key];
143
+ }
144
+ this.insertInternal(value);
145
+ }
146
+ }
139
147
 
140
- /**
141
- * {@inheritDoc @fluidframework/server-services-core#ICollection.insertOne}
142
- */
143
- /*
144
- * Value is expected to have a member "_id" which is a string used to search in the database.
145
- */
146
- public async insertOne(value: any): Promise<any> {
147
- const presentVal = this.findOneInternal(value);
148
- // Only raise error when the object is present and the value is not equal.
149
- if (presentVal) {
150
- if (JSON.stringify(presentVal) === JSON.stringify(value)) {
151
- return;
152
- }
153
- throw new Error("Existing Object!!");
154
- }
148
+ /**
149
+ * {@inheritDoc @fluidframework/server-services-core#ICollection.insertOne}
150
+ */
151
+ /*
152
+ * Value is expected to have a member "_id" which is a string used to search in the database.
153
+ */
154
+ public async insertOne(value: any): Promise<any> {
155
+ const presentVal = this.findOneInternal(value);
156
+ // Only raise error when the object is present and the value is not equal.
157
+ if (presentVal) {
158
+ if (JSON.stringify(presentVal) === JSON.stringify(value)) {
159
+ return;
160
+ }
161
+ throw new Error("Existing Object!!");
162
+ }
155
163
 
156
- return this.insertInternal(value);
157
- }
164
+ return this.insertInternal(value);
165
+ }
158
166
 
159
- /**
160
- * {@inheritDoc @fluidframework/server-services-core#ICollection.findOrCreate}
161
- */
162
- /*
163
- * Value and query are expected to have a member "_id" which is a string used to search or insert in the database.
164
- */
165
- public async findOrCreate(query: any, value: any): Promise<{ value: any; existing: boolean; }> {
166
- const existing = this.findOneInternal(query);
167
- if (existing) {
168
- return { value: existing, existing: true };
169
- }
170
- this.insertInternal(value);
171
- return { value, existing: false };
172
- }
167
+ /**
168
+ * {@inheritDoc @fluidframework/server-services-core#ICollection.findOrCreate}
169
+ */
170
+ /*
171
+ * Value and query are expected to have a member "_id" which is a string used to search or insert in the database.
172
+ */
173
+ public async findOrCreate(query: any, value: any): Promise<{ value: any; existing: boolean }> {
174
+ const existing = this.findOneInternal(query);
175
+ if (existing) {
176
+ return { value: existing, existing: true };
177
+ }
178
+ this.insertInternal(value);
179
+ return { value, existing: false };
180
+ }
173
181
 
174
- /**
175
- * {@inheritDoc @fluidframework/server-services-core#ICollection.insertMany}
176
- */
177
- /*
178
- * Each element in values is expected to have a member "_id" which is a string used to insert in the database.
179
- */
180
- public async insertMany(values: any[], ordered: boolean): Promise<void> {
181
- this.insertInternal(...values);
182
- }
182
+ /**
183
+ * {@inheritDoc @fluidframework/server-services-core#ICollection.insertMany}
184
+ */
185
+ /*
186
+ * Each element in values is expected to have a member "_id" which is a string used to insert in the database.
187
+ */
188
+ public async insertMany(values: any[], ordered: boolean): Promise<void> {
189
+ this.insertInternal(...values);
190
+ }
183
191
 
184
- /**
185
- * {@inheritDoc @fluidframework/server-services-core#ICollection.deleteOne}
186
- */
187
- public async deleteOne(query: any): Promise<any> {
188
- throw new Error("Method not implemented.");
189
- }
192
+ /**
193
+ * {@inheritDoc @fluidframework/server-services-core#ICollection.deleteOne}
194
+ */
195
+ public async deleteOne(query: any): Promise<any> {
196
+ throw new Error("Method not implemented.");
197
+ }
190
198
 
191
- /**
192
- * {@inheritDoc @fluidframework/server-services-core#ICollection.deleteMany}
193
- */
194
- public async deleteMany(query: any): Promise<any> {
195
- throw new Error("Method not implemented.");
196
- }
199
+ /**
200
+ * {@inheritDoc @fluidframework/server-services-core#ICollection.deleteMany}
201
+ */
202
+ public async deleteMany(query: any): Promise<any> {
203
+ throw new Error("Method not implemented.");
204
+ }
197
205
 
198
- /**
199
- * {@inheritDoc @fluidframework/server-services-core#ICollection.createIndex}
200
- */
201
- public async createIndex(index: any, unique: boolean): Promise<void> {
202
- throw new Error("Method not implemented.");
203
- }
206
+ /**
207
+ * {@inheritDoc @fluidframework/server-services-core#ICollection.createIndex}
208
+ */
209
+ public async createIndex(index: any, unique: boolean): Promise<void> {
210
+ throw new Error("Method not implemented.");
211
+ }
204
212
 
205
- /**
206
- * Return all values in the database
207
- */
208
- private getAllInternal(): any[] {
209
- const values: string[] = [];
210
- for (let i = 0; i < sessionStorage.length; i++) {
211
- const key = sessionStorage.key(i);
212
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
213
- if (key!.startsWith(this.collectionName)) {
214
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
215
- values.push(JSON.parse(sessionStorage.getItem(key!)!));
216
- }
217
- }
218
- return values;
219
- }
213
+ /**
214
+ * Return all values in the database
215
+ */
216
+ private getAllInternal(): any[] {
217
+ const values: string[] = [];
218
+ for (let i = 0; i < sessionStorage.length; i++) {
219
+ const key = sessionStorage.key(i);
220
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
221
+ if (key!.startsWith(this.collectionName)) {
222
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
223
+ values.push(JSON.parse(sessionStorage.getItem(key!)!));
224
+ }
225
+ }
226
+ return values;
227
+ }
220
228
 
221
- /**
222
- * Inserts values into the session storge.
223
- * Values are expected to have a member "_id" which is a unique id, otherwise will be assigned one
224
- *
225
- * @param values - data to insert to the database
226
- */
227
- private insertInternal(...values: any[]) {
228
- for (const value of values) {
229
- if (value) {
230
- if (!value._id) {
231
- value._id = uuid();
232
- }
233
- sessionStorage.setItem(`${this.collectionName}-${value._id}`, JSON.stringify(value));
234
- }
235
- }
236
- }
229
+ /**
230
+ * Inserts values into the session storge.
231
+ * Values are expected to have a member "_id" which is a unique id, otherwise will be assigned one
232
+ *
233
+ * @param values - data to insert to the database
234
+ */
235
+ private insertInternal(...values: any[]) {
236
+ for (const value of values) {
237
+ if (value) {
238
+ if (!value._id) {
239
+ value._id = uuid();
240
+ }
241
+ sessionStorage.setItem(
242
+ `${this.collectionName}-${value._id}`,
243
+ JSON.stringify(value),
244
+ );
245
+ }
246
+ }
247
+ }
237
248
 
238
- /**
239
- * Finds the query in session storage and returns its value.
240
- * Returns null if query is not found.
241
- * Query is expected to have a member "_id" which is a unique id.
242
- *
243
- * @param query - what to find in the database
244
- */
245
- private findOneInternal(query: any): any {
246
- if (query._id) {
247
- const json = sessionStorage.getItem(`${this.collectionName}-${query._id}`);
248
- if (json) {
249
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
250
- return JSON.parse(json);
251
- }
252
- } else {
253
- const queryKeys = Object.keys(query);
254
- for (let i = 0; i < sessionStorage.length; i++) {
255
- const ssKey = sessionStorage.key(i);
256
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
257
- if (!ssKey!.startsWith(this.collectionName)) {
258
- continue;
259
- }
260
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
261
- const value = JSON.parse(sessionStorage.getItem(ssKey!)!);
262
- for (const qk of queryKeys) {
263
- if (value[qk] !== query[qk]) {
264
- continue;
265
- }
266
- }
267
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
268
- return value;
269
- }
270
- }
271
- return null;
272
- }
249
+ /**
250
+ * Finds the query in session storage and returns its value.
251
+ * Returns null if query is not found.
252
+ * Query is expected to have a member "_id" which is a unique id.
253
+ *
254
+ * @param query - what to find in the database
255
+ */
256
+ private findOneInternal(query: any): any {
257
+ if (query._id) {
258
+ const json = sessionStorage.getItem(`${this.collectionName}-${query._id}`);
259
+ if (json) {
260
+ return JSON.parse(json);
261
+ }
262
+ } else {
263
+ const queryKeys = Object.keys(query);
264
+ for (let i = 0; i < sessionStorage.length; i++) {
265
+ const ssKey = sessionStorage.key(i);
266
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
267
+ if (!ssKey!.startsWith(this.collectionName)) {
268
+ continue;
269
+ }
270
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
271
+ const value = JSON.parse(sessionStorage.getItem(ssKey!)!);
272
+ let foundMismatch = false;
273
+ for (const qk of queryKeys) {
274
+ if (value[qk] !== query[qk]) {
275
+ foundMismatch = true;
276
+ break;
277
+ }
278
+ }
279
+
280
+ if (!foundMismatch) {
281
+ return value;
282
+ }
283
+ }
284
+ }
285
+ return null;
286
+ }
273
287
  }
274
288
 
275
289
  /**
276
290
  * A database for testing that stores data in the browsers session storage
277
291
  */
278
292
  class LocalSessionStorageDb extends EventEmitter implements IDb {
279
- private readonly collections = new Map<string, LocalSessionStorageCollection<any>>();
280
- constructor(private readonly namespace) {
281
- super();
282
- }
283
- public async close(): Promise<void> {
284
- return Promise.resolve();
285
- }
286
- public collection<T>(name: string): ICollection<T> {
287
- if (!this.collections.has(name)) {
288
- this.collections.set(name, new LocalSessionStorageCollection<T>(`${this.namespace}-db`, name));
289
- }
290
- return this.collections.get(name) as LocalSessionStorageCollection<T>;
291
- }
293
+ private readonly collections = new Map<string, LocalSessionStorageCollection<any>>();
294
+ public async close(): Promise<void> {}
295
+ public collection<T>(name: string): ICollection<T> {
296
+ if (!this.collections.has(name)) {
297
+ this.collections.set(name, new LocalSessionStorageCollection<T>(name));
298
+ }
299
+ return this.collections.get(name) as LocalSessionStorageCollection<T>;
300
+ }
292
301
 
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
- }
302
+ public async dropCollection(name: string): Promise<boolean> {
303
+ if (!this.collections.has(name)) {
304
+ return true;
305
+ }
306
+ this.collections.delete(name);
307
+ return true;
308
+ }
300
309
  }
301
310
 
302
311
  /**
303
312
  * A database factory for testing that stores data in the browsers session storage
313
+ * @internal
304
314
  */
305
315
  export class LocalSessionStorageDbFactory implements ITestDbFactory {
306
- public readonly testDatabase: IDb;
307
- constructor(namespace: string) {
308
- this.testDatabase = new LocalSessionStorageDb(namespace);
309
- }
310
- public async connect(): Promise<IDb> {
311
- return this.testDatabase;
312
- }
316
+ public readonly testDatabase: IDb = new LocalSessionStorageDb();
317
+ public async connect(): Promise<IDb> {
318
+ return this.testDatabase;
319
+ }
313
320
  }
@@ -0,0 +1,4 @@
1
+ {
2
+ "targets": [{ "extname": ".cjs", "module": "CommonJS", "moduleResolution": "Node10" }],
3
+ "projects": ["./tsconfig.json", "./src/test/tsconfig.json"]
4
+ }
package/tsconfig.json CHANGED
@@ -1,14 +1,12 @@
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": [
3
+ "../../../common/build/build-common/tsconfig.base.json",
4
+ "../../../common/build/build-common/tsconfig.cjs.json",
5
+ ],
6
+ "include": ["src/**/*"],
7
+ "exclude": ["src/test/**/*"],
8
+ "compilerOptions": {
9
+ "rootDir": "./src",
10
+ "outDir": "./dist",
11
+ },
12
+ }
package/dist/auth.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,yCAA8C;AAC9C,+BAAkC;AAClC,mFAAuE;AAEvE;;;GAGG;AACH,SAAgB,aAAa,CACzB,QAAgB,EAChB,UAAkB,EAClB,GAAW,EACX,MAAmB,EACnB,IAAY,EACZ,WAAmB,EAAE,GAAG,EAAE,EAC1B,MAAc,KAAK;IACnB,IAAI,SAAS,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,EAAE,CAAC;IAC/C,IAAI,SAAS,CAAC,EAAE,KAAK,EAAE,IAAI,SAAS,CAAC,EAAE,KAAK,SAAS,EAAE;QACnD,SAAS,GAAG,YAAY,EAAE,CAAC;KAC9B;IAED,0BAA0B;IAC1B,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;IAEtD,MAAM,MAAM,GAAiB;QACzB,UAAU;QACV,MAAM;QACN,QAAQ;QACR,IAAI,EAAE,SAAS;QACf,GAAG,EAAE,GAAG;QACR,GAAG,EAAE,GAAG,GAAG,QAAQ;QACnB,GAAG;KACN,CAAC;IAEF,MAAM,OAAO,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;IAC9B,OAAO,gBAAS,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AACvG,CAAC;AA5BD,sCA4BC;AAED,SAAgB,YAAY;IACxB,MAAM,UAAU,GAAG;QACf,EAAE,EAAE,IAAA,SAAI,GAAE;QACV,IAAI,EAAE,IAAA,sCAAa,EAAC,GAAG,EAAE,IAAI,CAAC;KACjC,CAAC;IAEF,OAAO,UAAU,CAAC;AACtB,CAAC;AAPD,oCAOC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITokenClaims, IUser, ScopeType } from \"@fluidframework/protocol-definitions\";\nimport { KJUR as jsrsasign } from \"jsrsasign\";\nimport { v4 as uuid } from \"uuid\";\nimport { getRandomName } from \"@fluidframework/server-services-client\";\n\n/**\n * Generates a JWT token to authorize against. We do not use the implementation in\n * services-client since it cannot run in the browser without polyfills.\n */\nexport function generateToken(\n tenantId: string,\n documentId: string,\n key: string,\n scopes: ScopeType[],\n user?: IUser,\n lifetime: number = 60 * 60,\n ver: string = \"1.0\"): string {\n let userClaim = (user) ? user : generateUser();\n if (userClaim.id === \"\" || userClaim.id === undefined) {\n userClaim = generateUser();\n }\n\n // Current time in seconds\n const now = Math.round((new Date()).getTime() / 1000);\n\n const claims: ITokenClaims = {\n documentId,\n scopes,\n tenantId,\n user: userClaim,\n iat: now,\n exp: now + lifetime,\n ver,\n };\n\n const utf8Key = { utf8: key };\n return jsrsasign.jws.JWS.sign(null, JSON.stringify({ alg: \"HS256\", typ: \"JWT\" }), claims, utf8Key);\n}\n\nexport function generateUser(): IUser {\n const randomUser = {\n id: uuid(),\n name: getRandomName(\" \", true),\n };\n\n return randomUser;\n}\n"]}
package/dist/index.js DELETED
@@ -1,23 +0,0 @@
1
- "use strict";
2
- /*!
3
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
- * Licensed under the MIT License.
5
- */
6
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
- if (k2 === undefined) k2 = k;
8
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./localDeltaStorageService"), exports);
18
- __exportStar(require("./localDocumentDeltaConnection"), exports);
19
- __exportStar(require("./localDocumentService"), exports);
20
- __exportStar(require("./localDocumentServiceFactory"), exports);
21
- __exportStar(require("./localResolver"), exports);
22
- __exportStar(require("./localSessionStorageDb"), exports);
23
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;AAEH,6DAA2C;AAC3C,iEAA+C;AAC/C,yDAAuC;AACvC,gEAA8C;AAC9C,kDAAgC;AAChC,0DAAwC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport * from \"./localDeltaStorageService\";\nexport * from \"./localDocumentDeltaConnection\";\nexport * from \"./localDocumentService\";\nexport * from \"./localDocumentServiceFactory\";\nexport * from \"./localResolver\";\nexport * from \"./localSessionStorageDb\";\n"]}