@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.
- package/.eslintrc.js +19 -22
- package/.mocharc.js +12 -0
- package/CHANGELOG.md +127 -0
- package/README.md +38 -0
- package/api-extractor-lint.json +4 -0
- package/api-extractor.json +4 -0
- package/api-report/local-driver.api.md +129 -0
- package/dist/{auth.js → auth.cjs} +8 -6
- package/dist/auth.cjs.map +1 -0
- package/dist/auth.d.ts.map +1 -1
- package/dist/index.cjs +24 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +7 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/local-driver-alpha.d.ts +110 -0
- package/dist/local-driver-beta.d.ts +75 -0
- package/dist/local-driver-public.d.ts +75 -0
- package/dist/local-driver-untrimmed.d.ts +226 -0
- package/dist/localCreateDocument.cjs +28 -0
- package/dist/localCreateDocument.cjs.map +1 -0
- package/dist/localCreateDocument.d.ts +8 -0
- package/dist/localCreateDocument.d.ts.map +1 -0
- package/dist/{localDeltaStorageService.js → localDeltaStorageService.cjs} +3 -2
- package/dist/localDeltaStorageService.cjs.map +1 -0
- package/dist/localDeltaStorageService.d.ts +4 -3
- package/dist/localDeltaStorageService.d.ts.map +1 -1
- package/dist/{localDocumentDeltaConnection.js → localDocumentDeltaConnection.cjs} +9 -11
- package/dist/localDocumentDeltaConnection.cjs.map +1 -0
- package/dist/localDocumentDeltaConnection.d.ts +5 -4
- package/dist/localDocumentDeltaConnection.d.ts.map +1 -1
- package/dist/{localDocumentService.js → localDocumentService.cjs} +15 -30
- package/dist/localDocumentService.cjs.map +1 -0
- package/dist/localDocumentService.d.ts +15 -11
- package/dist/localDocumentService.d.ts.map +1 -1
- package/dist/{localDocumentServiceFactory.js → localDocumentServiceFactory.cjs} +14 -31
- package/dist/localDocumentServiceFactory.cjs.map +1 -0
- package/dist/localDocumentServiceFactory.d.ts +3 -2
- package/dist/localDocumentServiceFactory.d.ts.map +1 -1
- package/dist/localDocumentStorageService.cjs +88 -0
- package/dist/localDocumentStorageService.cjs.map +1 -0
- package/dist/localDocumentStorageService.d.ts +30 -0
- package/dist/localDocumentStorageService.d.ts.map +1 -0
- package/dist/{localResolver.js → localResolver.cjs} +10 -6
- package/dist/localResolver.cjs.map +1 -0
- package/dist/localResolver.d.ts +5 -0
- package/dist/localResolver.d.ts.map +1 -1
- package/dist/{localSessionStorageDb.js → localSessionStorageDb.cjs} +26 -18
- package/dist/localSessionStorageDb.cjs.map +1 -0
- package/dist/localSessionStorageDb.d.ts +1 -1
- package/dist/localSessionStorageDb.d.ts.map +1 -1
- package/dist/tsdoc-metadata.json +11 -0
- package/lib/auth.d.mts +12 -0
- package/lib/auth.d.mts.map +1 -0
- package/lib/auth.mjs +40 -0
- package/lib/auth.mjs.map +1 -0
- package/lib/index.d.mts +12 -0
- package/lib/index.d.mts.map +1 -0
- package/lib/index.mjs +12 -0
- package/lib/index.mjs.map +1 -0
- package/lib/local-driver-alpha.d.mts +110 -0
- package/lib/local-driver-beta.d.mts +75 -0
- package/lib/local-driver-public.d.mts +75 -0
- package/lib/local-driver-untrimmed.d.mts +226 -0
- package/lib/localCreateDocument.d.mts +8 -0
- package/lib/localCreateDocument.d.mts.map +1 -0
- package/lib/localCreateDocument.mjs +24 -0
- package/lib/localCreateDocument.mjs.map +1 -0
- package/lib/localDeltaStorageService.d.mts +20 -0
- package/lib/localDeltaStorageService.d.mts.map +1 -0
- package/lib/localDeltaStorageService.mjs +32 -0
- package/lib/localDeltaStorageService.mjs.map +1 -0
- package/lib/localDocumentDeltaConnection.d.mts +48 -0
- package/lib/localDocumentDeltaConnection.d.mts.map +1 -0
- package/lib/localDocumentDeltaConnection.mjs +86 -0
- package/lib/localDocumentDeltaConnection.mjs.map +1 -0
- package/lib/localDocumentService.d.mts +56 -0
- package/lib/localDocumentService.d.mts.map +1 -0
- package/lib/localDocumentService.mjs +84 -0
- package/lib/localDocumentService.mjs.map +1 -0
- package/lib/localDocumentServiceFactory.d.mts +45 -0
- package/lib/localDocumentServiceFactory.d.mts.map +1 -0
- package/lib/localDocumentServiceFactory.mjs +80 -0
- package/lib/localDocumentServiceFactory.mjs.map +1 -0
- package/lib/localDocumentStorageService.d.mts +30 -0
- package/lib/localDocumentStorageService.d.mts.map +1 -0
- package/lib/localDocumentStorageService.mjs +84 -0
- package/lib/localDocumentStorageService.mjs.map +1 -0
- package/lib/localResolver.d.mts +31 -0
- package/lib/localResolver.d.mts.map +1 -0
- package/lib/localResolver.mjs +74 -0
- package/lib/localResolver.mjs.map +1 -0
- package/lib/localSessionStorageDb.d.mts +11 -0
- package/lib/localSessionStorageDb.d.mts.map +1 -0
- package/lib/localSessionStorageDb.mjs +292 -0
- package/lib/localSessionStorageDb.mjs.map +1 -0
- package/package.json +102 -59
- package/prettier.config.cjs +8 -0
- package/src/auth.ts +42 -33
- package/src/index.ts +7 -6
- package/src/localCreateDocument.ts +48 -0
- package/src/localDeltaStorageService.ts +28 -27
- package/src/localDocumentDeltaConnection.ts +91 -88
- package/src/localDocumentService.ts +117 -97
- package/src/localDocumentServiceFactory.ts +95 -123
- package/src/localDocumentStorageService.ts +131 -0
- package/src/localResolver.ts +57 -59
- package/src/localSessionStorageDb.ts +272 -265
- package/tsc-multi.test.json +4 -0
- package/tsconfig.json +11 -13
- package/dist/auth.js.map +0 -1
- package/dist/index.js +0 -23
- package/dist/index.js.map +0 -1
- package/dist/localDeltaStorageService.js.map +0 -1
- package/dist/localDocumentDeltaConnection.js.map +0 -1
- package/dist/localDocumentService.js.map +0 -1
- package/dist/localDocumentServiceFactory.js.map +0 -1
- package/dist/localResolver.js.map +0 -1
- package/dist/localSessionStorageDb.js.map +0 -1
- package/dist/packageVersion.d.ts +0 -9
- package/dist/packageVersion.d.ts.map +0 -1
- package/dist/packageVersion.js +0 -12
- package/dist/packageVersion.js.map +0 -1
- 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
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
public aggregate(pipeline: any, options?: any): any {
|
|
21
|
+
throw new Error("Method Not Implemented");
|
|
22
|
+
}
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
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
|
-
|
|
157
|
-
|
|
164
|
+
return this.insertInternal(value);
|
|
165
|
+
}
|
|
158
166
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
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
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
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
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
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
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
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
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
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
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
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
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
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
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
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
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
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
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
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
|
-
|
|
307
|
-
|
|
308
|
-
|
|
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
|
}
|
package/tsconfig.json
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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"]}
|