@webda/gcp 2.0.0-beta.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/LICENSE +166 -0
- package/README.md +13 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +18 -0
- package/lib/index.js.map +1 -0
- package/lib/index.spec.d.ts +4 -0
- package/lib/index.spec.js +25 -0
- package/lib/index.spec.js.map +1 -0
- package/lib/services/firestore.d.ts +124 -0
- package/lib/services/firestore.js +426 -0
- package/lib/services/firestore.js.map +1 -0
- package/lib/services/firestore.spec.d.ts +1 -0
- package/lib/services/firestore.spec.js +226 -0
- package/lib/services/firestore.spec.js.map +1 -0
- package/lib/services/index.d.ts +1 -0
- package/lib/services/index.js +18 -0
- package/lib/services/index.js.map +1 -0
- package/lib/services/pubsub.d.ts +35 -0
- package/lib/services/pubsub.js +93 -0
- package/lib/services/pubsub.js.map +1 -0
- package/lib/services/pubsub.spec.d.ts +1 -0
- package/lib/services/pubsub.spec.js +73 -0
- package/lib/services/pubsub.spec.js.map +1 -0
- package/lib/services/queue.d.ts +81 -0
- package/lib/services/queue.js +159 -0
- package/lib/services/queue.js.map +1 -0
- package/lib/services/queue.spec.d.ts +1 -0
- package/lib/services/queue.spec.js +120 -0
- package/lib/services/queue.spec.js.map +1 -0
- package/lib/services/storage.d.ts +131 -0
- package/lib/services/storage.js +244 -0
- package/lib/services/storage.js.map +1 -0
- package/lib/services/storage.spec.d.ts +1 -0
- package/lib/services/storage.spec.js +213 -0
- package/lib/services/storage.spec.js.map +1 -0
- package/package.json +63 -0
- package/webda.module.json +12 -0
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.FireStore = exports.FireStoreParameters = void 0;
|
|
13
|
+
const firestore_1 = require("@google-cloud/firestore");
|
|
14
|
+
const core_1 = require("@webda/core");
|
|
15
|
+
/**
|
|
16
|
+
* Firebase parameters
|
|
17
|
+
*/
|
|
18
|
+
class FireStoreParameters extends core_1.StoreParameters {
|
|
19
|
+
constructor(params, service) {
|
|
20
|
+
var _a;
|
|
21
|
+
super(params, service);
|
|
22
|
+
// Default to empty compoundIndexes
|
|
23
|
+
(_a = this.compoundIndexes) !== null && _a !== void 0 ? _a : (this.compoundIndexes = []);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.FireStoreParameters = FireStoreParameters;
|
|
27
|
+
/**
|
|
28
|
+
* Implement Firebase abstraction within Webda
|
|
29
|
+
*
|
|
30
|
+
* @WebdaModda GoogleCloudFireStore
|
|
31
|
+
*/
|
|
32
|
+
class FireStore extends core_1.Store {
|
|
33
|
+
/**
|
|
34
|
+
* @override
|
|
35
|
+
*/
|
|
36
|
+
loadParameters(params) {
|
|
37
|
+
return new FireStoreParameters(params, this);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* @override
|
|
41
|
+
*/
|
|
42
|
+
init() {
|
|
43
|
+
const _super = Object.create(null, {
|
|
44
|
+
init: { get: () => super.init }
|
|
45
|
+
});
|
|
46
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
yield _super.init.call(this);
|
|
48
|
+
this.firestore = new firestore_1.Firestore();
|
|
49
|
+
this.firestore.settings({ ignoreUndefinedProperties: true });
|
|
50
|
+
this.compoundIndexes = {};
|
|
51
|
+
this.parameters.compoundIndexes.forEach(a => {
|
|
52
|
+
const key = Object.keys(a).join("/");
|
|
53
|
+
// Should contain the array of accessible order
|
|
54
|
+
this.compoundIndexes[key] = {};
|
|
55
|
+
Object.keys(a).forEach(field => {
|
|
56
|
+
var _a;
|
|
57
|
+
var _b;
|
|
58
|
+
(_a = (_b = this.compoundIndexes[key])[field]) !== null && _a !== void 0 ? _a : (_b[field] = new Set());
|
|
59
|
+
this.compoundIndexes[key][field].add(a[field]);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Get Document Reference
|
|
66
|
+
* @param uuid
|
|
67
|
+
* @param collection
|
|
68
|
+
* @returns
|
|
69
|
+
*/
|
|
70
|
+
getDocumentRef(uuid, collection = this.parameters.collection) {
|
|
71
|
+
return this.firestore.doc(`${collection}/${uuid}`);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* @override
|
|
75
|
+
*
|
|
76
|
+
* Return all for now
|
|
77
|
+
*/
|
|
78
|
+
find(parsedQuery) {
|
|
79
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
let offset = parseInt(parsedQuery.continuationToken || "0");
|
|
81
|
+
let query = this.firestore.collection(this.parameters.collection);
|
|
82
|
+
if (offset) {
|
|
83
|
+
query = query.offset(offset);
|
|
84
|
+
}
|
|
85
|
+
let filter = new core_1.WebdaQL.AndExpression([]);
|
|
86
|
+
let rangeAttribute;
|
|
87
|
+
let toProcess;
|
|
88
|
+
if (!(parsedQuery.filter instanceof core_1.WebdaQL.AndExpression)) {
|
|
89
|
+
toProcess = new core_1.WebdaQL.AndExpression([parsedQuery.filter]);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
toProcess = parsedQuery.filter;
|
|
93
|
+
}
|
|
94
|
+
const queryAttributes = new Set();
|
|
95
|
+
let count = 0;
|
|
96
|
+
let hasIn = false;
|
|
97
|
+
toProcess.children.forEach((child) => {
|
|
98
|
+
if (!(child instanceof core_1.WebdaQL.ComparisonExpression) || count) {
|
|
99
|
+
// Do not manage OR yet
|
|
100
|
+
filter.children.push(child);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (child.operator === "LIKE") {
|
|
104
|
+
this.log("WARN", "Firebase do not natively have 'LIKE'");
|
|
105
|
+
// LIKE is not managed by Firestore
|
|
106
|
+
filter.children.push(child);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
let operator;
|
|
110
|
+
let attribute = child.attribute.join(".");
|
|
111
|
+
queryAttributes.add(attribute);
|
|
112
|
+
// Translate operators
|
|
113
|
+
if (["=", "IN"].includes(child.operator)) {
|
|
114
|
+
// = is permitted on every fields
|
|
115
|
+
// if rangeQuery then need to check indexes
|
|
116
|
+
if (child.operator === "=") {
|
|
117
|
+
operator = "==";
|
|
118
|
+
}
|
|
119
|
+
else if (child.operator === "IN") {
|
|
120
|
+
operator = "in";
|
|
121
|
+
if (child.value.length > 10) {
|
|
122
|
+
this.log("WARN", "Firebase cannot have more than 10 values for 'in'");
|
|
123
|
+
filter.children.push(child);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (hasIn) {
|
|
127
|
+
this.log("WARN", "Firebase cannot have two 'in' clause");
|
|
128
|
+
filter.children.push(child);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
hasIn = true;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
// Requires compoundIndex
|
|
136
|
+
if (queryAttributes.size > 1 && !this.compoundIndexes[[...queryAttributes.values()].sort().join("/")]) {
|
|
137
|
+
this.log("WARN", "Compound index not defined");
|
|
138
|
+
filter.children.push(child);
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
if (child.operator !== "!=") {
|
|
142
|
+
// Check compoundIndex exist
|
|
143
|
+
rangeAttribute !== null && rangeAttribute !== void 0 ? rangeAttribute : (rangeAttribute = attribute);
|
|
144
|
+
// Range need to apply on only one attribute
|
|
145
|
+
if (rangeAttribute !== attribute) {
|
|
146
|
+
filter.children.push(child);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
operator = child.operator;
|
|
151
|
+
}
|
|
152
|
+
query = query.where(attribute, operator, child.value);
|
|
153
|
+
});
|
|
154
|
+
// OrderBy have quite some complexity with FireStore
|
|
155
|
+
query = this.handleOrderBy(query, parsedQuery.orderBy, rangeAttribute);
|
|
156
|
+
const res = yield query.limit(parsedQuery.limit || 0).get();
|
|
157
|
+
return {
|
|
158
|
+
results: res.docs.map(d => this.initModel(d.data())),
|
|
159
|
+
filter: filter.children.length ? filter : true,
|
|
160
|
+
continuationToken: res.docs.length >= parsedQuery.limit ? (offset + parsedQuery.limit).toString() : undefined,
|
|
161
|
+
};
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Manage OrderBy complex condition on Firebase
|
|
166
|
+
* @param query
|
|
167
|
+
* @param orderBy
|
|
168
|
+
* @param rangeAttribute
|
|
169
|
+
* @param index
|
|
170
|
+
*/
|
|
171
|
+
handleOrderBy(query, orderBy, rangeAttribute) {
|
|
172
|
+
// Manage order if index
|
|
173
|
+
if (!orderBy) {
|
|
174
|
+
return query;
|
|
175
|
+
}
|
|
176
|
+
let requiredIndex = orderBy.map(order => order.field).sort();
|
|
177
|
+
let orders;
|
|
178
|
+
// Require index with multiple ORDER BY
|
|
179
|
+
if (requiredIndex.length > 1) {
|
|
180
|
+
orders = this.compoundIndexes[requiredIndex.join("/")];
|
|
181
|
+
if (!orders) {
|
|
182
|
+
this.log("WARN", "Skip orderBy as we are missing the index");
|
|
183
|
+
return query;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
// Range must be the first orderBy
|
|
187
|
+
if (rangeAttribute) {
|
|
188
|
+
if (!orderBy.some(order => {
|
|
189
|
+
// Need to check the permitted orderBy and direction
|
|
190
|
+
if (order.field === rangeAttribute) {
|
|
191
|
+
query = query.orderBy(order.field, order.direction.toLowerCase());
|
|
192
|
+
return true;
|
|
193
|
+
}
|
|
194
|
+
})) {
|
|
195
|
+
this.log("WARN", "Skip orderBy as the range attribute is not within ORDER BY expression");
|
|
196
|
+
// If rangeAttribute is not in orderBy then skip the orderBy completely
|
|
197
|
+
return query;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
// Add remaining orderBy from index
|
|
201
|
+
orderBy
|
|
202
|
+
.filter(order => order.field !== rangeAttribute)
|
|
203
|
+
.forEach(order => {
|
|
204
|
+
if (!orders || orders[order.field].has(order.direction.toLowerCase())) {
|
|
205
|
+
query = query.orderBy(order.field, order.direction.toLowerCase());
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
this.log("WARN", "Skip orderBy as the direction does not match index");
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
return query;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* @override
|
|
215
|
+
*/
|
|
216
|
+
exists(uid) {
|
|
217
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
218
|
+
return (yield this.getDocumentRef(uid).get()).exists;
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* @override
|
|
223
|
+
*/
|
|
224
|
+
_delete(uid, writeCondition, itemWriteConditionField) {
|
|
225
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
226
|
+
yield this.firestore.runTransaction((t) => __awaiter(this, void 0, void 0, function* () {
|
|
227
|
+
const docRef = this.getDocumentRef(uid);
|
|
228
|
+
const doc = (yield t.get(docRef)).data();
|
|
229
|
+
if (writeCondition && doc[itemWriteConditionField] !== writeCondition) {
|
|
230
|
+
throw new core_1.UpdateConditionFailError(uid, itemWriteConditionField, writeCondition);
|
|
231
|
+
}
|
|
232
|
+
t.delete(docRef);
|
|
233
|
+
}));
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* @override
|
|
238
|
+
*/
|
|
239
|
+
_get(uid, raiseIfNotFound) {
|
|
240
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
241
|
+
let doc = (yield this.getDocumentRef(uid).get()).data();
|
|
242
|
+
if (!doc) {
|
|
243
|
+
if (raiseIfNotFound) {
|
|
244
|
+
throw new core_1.StoreNotFoundError(uid, this.getName());
|
|
245
|
+
}
|
|
246
|
+
return undefined;
|
|
247
|
+
}
|
|
248
|
+
return this.initModel(doc);
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* @override
|
|
253
|
+
*/
|
|
254
|
+
getAll(list) {
|
|
255
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
256
|
+
let res = [];
|
|
257
|
+
if (list) {
|
|
258
|
+
res = (yield this.firestore.collection(this.parameters.collection).where("uuid", "in", list).get()).docs;
|
|
259
|
+
}
|
|
260
|
+
else {
|
|
261
|
+
res = yield this.firestore.collection(this.parameters.collection).listDocuments();
|
|
262
|
+
}
|
|
263
|
+
return res.map(this.initModel, this);
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* @override
|
|
268
|
+
*/
|
|
269
|
+
_update(object, uid, itemWriteCondition, itemWriteConditionField) {
|
|
270
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
271
|
+
yield this._setDocument(false, object, uid, itemWriteCondition, itemWriteConditionField);
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
checkCondition(uid, data, field, condition) {
|
|
275
|
+
if (condition) {
|
|
276
|
+
let values = [data[field], condition].map(i => (i instanceof firestore_1.Timestamp ? i.toMillis() : i));
|
|
277
|
+
if (values[0] !== values[1]) {
|
|
278
|
+
throw new core_1.UpdateConditionFailError(uid, field, condition);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
/***
|
|
283
|
+
* Internal function that implement both update and patch
|
|
284
|
+
*/
|
|
285
|
+
_setDocument(merge, object, uid, itemWriteCondition, itemWriteConditionField) {
|
|
286
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
287
|
+
let update = object;
|
|
288
|
+
if (object instanceof core_1.CoreModel) {
|
|
289
|
+
update = object.toStoredJSON();
|
|
290
|
+
}
|
|
291
|
+
yield this.firestore.runTransaction((t) => __awaiter(this, void 0, void 0, function* () {
|
|
292
|
+
const docRef = this.getDocumentRef(uid);
|
|
293
|
+
const doc = yield t.get(docRef);
|
|
294
|
+
if (!doc.exists) {
|
|
295
|
+
throw new core_1.StoreNotFoundError(uid, this.getName());
|
|
296
|
+
}
|
|
297
|
+
this.checkCondition(uid, doc.data(), itemWriteConditionField, itemWriteCondition);
|
|
298
|
+
t.set(docRef, update, {
|
|
299
|
+
merge,
|
|
300
|
+
});
|
|
301
|
+
}));
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* @override
|
|
306
|
+
*/
|
|
307
|
+
_patch(object, uid, itemWriteCondition, itemWriteConditionField) {
|
|
308
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
309
|
+
yield this._setDocument(true, object, uid, itemWriteCondition, itemWriteConditionField);
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* @override
|
|
314
|
+
*/
|
|
315
|
+
_removeAttribute(uuid, attribute, itemWriteCondition, itemWriteConditionField) {
|
|
316
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
317
|
+
yield this.firestore.runTransaction((t) => __awaiter(this, void 0, void 0, function* () {
|
|
318
|
+
const docRef = this.getDocumentRef(uuid);
|
|
319
|
+
const doc = yield t.get(docRef);
|
|
320
|
+
if (!doc.exists) {
|
|
321
|
+
throw new core_1.StoreNotFoundError(uuid, this.getName());
|
|
322
|
+
}
|
|
323
|
+
this.checkCondition(uuid, doc.data(), itemWriteConditionField, itemWriteCondition);
|
|
324
|
+
t.update(docRef, {
|
|
325
|
+
[attribute]: firestore_1.FieldValue.delete(),
|
|
326
|
+
});
|
|
327
|
+
}));
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* @override
|
|
332
|
+
*/
|
|
333
|
+
_save(object) {
|
|
334
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
335
|
+
yield this.getDocumentRef(object.getUuid()).set(object.toStoredJSON());
|
|
336
|
+
return object;
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* @override
|
|
341
|
+
*/
|
|
342
|
+
_incrementAttribute(uid, prop, value, updateDate) {
|
|
343
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
344
|
+
try {
|
|
345
|
+
yield this.getDocumentRef(uid).update({
|
|
346
|
+
[prop]: firestore_1.FieldValue.increment(value),
|
|
347
|
+
[this._lastUpdateField]: updateDate,
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
catch (err) {
|
|
351
|
+
if (err.code === 5) {
|
|
352
|
+
throw new core_1.StoreNotFoundError(uid, this.getName());
|
|
353
|
+
}
|
|
354
|
+
throw err;
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* @override
|
|
360
|
+
*/
|
|
361
|
+
_upsertItemToCollection(uid, prop, item, index, itemWriteCondition, itemWriteConditionField, updateDate) {
|
|
362
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
363
|
+
if (index !== undefined) {
|
|
364
|
+
yield this.firestore.runTransaction((t) => __awaiter(this, void 0, void 0, function* () {
|
|
365
|
+
const docRef = this.getDocumentRef(uid);
|
|
366
|
+
const doc = yield t.get(docRef);
|
|
367
|
+
if (!doc.exists) {
|
|
368
|
+
throw new core_1.StoreNotFoundError(uid, this.getName());
|
|
369
|
+
}
|
|
370
|
+
const data = doc.data();
|
|
371
|
+
this.checkCondition(uid, data[prop][index], itemWriteConditionField, itemWriteCondition);
|
|
372
|
+
data[prop][index] = item;
|
|
373
|
+
t.update(docRef, {
|
|
374
|
+
[prop]: data[prop],
|
|
375
|
+
[this._lastUpdateField]: updateDate,
|
|
376
|
+
});
|
|
377
|
+
}));
|
|
378
|
+
}
|
|
379
|
+
else {
|
|
380
|
+
try {
|
|
381
|
+
yield this.getDocumentRef(uid).update({
|
|
382
|
+
[prop]: firestore_1.FieldValue.arrayUnion(item),
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
catch (err) {
|
|
386
|
+
if (err.code === 5) {
|
|
387
|
+
throw new core_1.StoreNotFoundError(uid, this.getName());
|
|
388
|
+
}
|
|
389
|
+
throw err;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* @override
|
|
396
|
+
*/
|
|
397
|
+
_deleteItemFromCollection(uid, prop, index, itemWriteCondition, itemWriteConditionField, updateDate) {
|
|
398
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
399
|
+
yield this.firestore.runTransaction((t) => __awaiter(this, void 0, void 0, function* () {
|
|
400
|
+
const docRef = this.getDocumentRef(uid);
|
|
401
|
+
const doc = yield t.get(docRef);
|
|
402
|
+
if (!doc.exists) {
|
|
403
|
+
throw new core_1.StoreNotFoundError(uid, this.getName());
|
|
404
|
+
}
|
|
405
|
+
const data = doc.data();
|
|
406
|
+
this.checkCondition(uid, data[prop][index], itemWriteConditionField, itemWriteCondition);
|
|
407
|
+
// Get item from doc?
|
|
408
|
+
t.update(docRef, {
|
|
409
|
+
[prop]: firestore_1.FieldValue.arrayRemove(data[prop][index]),
|
|
410
|
+
[this._lastUpdateField]: updateDate,
|
|
411
|
+
});
|
|
412
|
+
}));
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* @override
|
|
417
|
+
*/
|
|
418
|
+
__clean() {
|
|
419
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
420
|
+
// Empty on purpose, unit test use custom collection each time
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
exports.default = FireStore;
|
|
425
|
+
exports.FireStore = FireStore;
|
|
426
|
+
//# sourceMappingURL=firestore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"firestore.js","sourceRoot":"","sources":["../../src/services/firestore.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uDAAgH;AAChH,sCASqB;AAUrB;;GAEG;AACH,MAAa,mBAAoB,SAAQ,sBAAe;IAYtD,YAAY,MAAwC,EAAE,OAAc;;QAClE,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACvB,mCAAmC;QACnC,MAAA,IAAI,CAAC,eAAe,oCAApB,IAAI,CAAC,eAAe,GAAK,EAAE,EAAC;IAC9B,CAAC;CACF;AAjBD,kDAiBC;AAED;;;;GAIG;AACH,MAAqB,SAGnB,SAAQ,YAAW;IAInB;;OAEG;IACH,cAAc,CAAC,MAAsB;QACnC,OAAO,IAAI,mBAAmB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAC/C,CAAC;IAED;;OAEG;IACG,IAAI;;;;;YACR,MAAM,OAAM,IAAI,WAAE,CAAC;YACnB,IAAI,CAAC,SAAS,GAAG,IAAI,qBAAS,EAAE,CAAC;YACjC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,yBAAyB,EAAE,IAAI,EAAE,CAAC,CAAC;YAC7D,IAAI,CAAC,eAAe,GAAG,EAAE,CAAC;YAC1B,IAAI,CAAC,UAAU,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE;gBAC1C,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;gBACrC,+CAA+C;gBAC/C,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC;gBAC/B,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;;;oBAC7B,Y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I,CAAC,CAAC,KAAK,CAAC,EAAE,uBAAuB,EAAE,kBAAkB,CAAC,CAAC;gBACzF,qBAAqB;gBACrB,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE;oBACf,CAAC,IAAI,CAAC,EAAE,sBAAU,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC;oBACjD,CAAC,IAAI,CAAC,gBAAgB,CAAC,EAAE,UAAU;iBACpC,CAAC,CAAC;YACL,CAAC,CAAA,CAAC,CAAC;QACL,CAAC;KAAA;IAED;;OAEG;IACG,OAAO;;YACX,8DAA8D;QAChE,CAAC;KAAA;CACF;AAxZD,4BAwZC;AAEQ,8BAAS"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
9
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
10
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
11
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
12
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
13
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
14
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
const store_spec_1 = require("@webda/core/lib/stores/store.spec");
|
|
19
|
+
const mocha_1 = require("@testdeck/mocha");
|
|
20
|
+
const firestore_1 = require("./firestore");
|
|
21
|
+
const assert = require("assert");
|
|
22
|
+
const sinon = require("sinon");
|
|
23
|
+
const uuid_1 = require("uuid");
|
|
24
|
+
const firestore_2 = require("@google-cloud/firestore");
|
|
25
|
+
const core_1 = require("@webda/core");
|
|
26
|
+
let FireStoreTest = class FireStoreTest extends store_spec_1.StoreTest {
|
|
27
|
+
before() {
|
|
28
|
+
const _super = Object.create(null, {
|
|
29
|
+
before: { get: () => super.before }
|
|
30
|
+
});
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
this.unitUuid = (0, uuid_1.v4)();
|
|
33
|
+
this.firestore = new firestore_2.Firestore();
|
|
34
|
+
yield _super.before.call(this);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
getIdentStore() {
|
|
38
|
+
let ident = this.getService("fireidents");
|
|
39
|
+
ident.getParameters().collection += "_" + this.unitUuid;
|
|
40
|
+
return ident;
|
|
41
|
+
}
|
|
42
|
+
getUserStore() {
|
|
43
|
+
let user = this.getService("fireusers");
|
|
44
|
+
user.getParameters().collection += "_" + this.unitUuid;
|
|
45
|
+
return user;
|
|
46
|
+
}
|
|
47
|
+
getModelClass() {
|
|
48
|
+
return core_1.Ident;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Delete a full collection
|
|
52
|
+
*/
|
|
53
|
+
deleteCollection(collectionPath, batchSize) {
|
|
54
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
const collectionRef = this.firestore.collection(collectionPath);
|
|
56
|
+
const query = collectionRef.orderBy("__name__").limit(batchSize);
|
|
57
|
+
return new Promise((resolve, reject) => {
|
|
58
|
+
this.deleteQueryBatch(this.firestore, query, resolve).catch(reject);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
cleanCollection() {
|
|
63
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
let collections = yield this.firestore.listCollections();
|
|
65
|
+
yield Promise.all(collections.map(c => {
|
|
66
|
+
return this.deleteCollection(c.id, 1000);
|
|
67
|
+
}));
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
fillForQuery() {
|
|
71
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
// Create a new store
|
|
73
|
+
let store = new firestore_1.FireStore(this.webda, "queryStore", {
|
|
74
|
+
collection: "webda-query",
|
|
75
|
+
compoundIndexes: [{ state: "asc", "team.id": "asc" }],
|
|
76
|
+
expose: {
|
|
77
|
+
url: "/query",
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
store.resolve();
|
|
81
|
+
yield store.init();
|
|
82
|
+
let res = yield this.firestore.collection("webda-query").where("order", "==", 1).get();
|
|
83
|
+
if (!res.docs.length) {
|
|
84
|
+
console.log("Init the query collection");
|
|
85
|
+
yield Promise.all(this.getQueryDocuments().map(d => store.save(d)));
|
|
86
|
+
}
|
|
87
|
+
return store;
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
query() {
|
|
91
|
+
const _super = Object.create(null, {
|
|
92
|
+
query: { get: () => super.query }
|
|
93
|
+
});
|
|
94
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
95
|
+
let store = yield _super.query.call(this);
|
|
96
|
+
let exp = new core_1.WebdaQL.QueryValidator('state = "CA" AND role = 4').getExpression();
|
|
97
|
+
let res = yield store.find({ filter: exp, limit: 1000 });
|
|
98
|
+
assert.strictEqual(res.filter, true, `Should not have any post filter ${res.filter.toString()}`);
|
|
99
|
+
assert.strictEqual(res.results.length, 50);
|
|
100
|
+
exp = new core_1.WebdaQL.QueryValidator('state = "CA" AND team.id < 5').getExpression();
|
|
101
|
+
res = yield store.find({ filter: exp, limit: 1000 });
|
|
102
|
+
assert.strictEqual(res.filter, true, `Should not have post filter ${res.filter.toString()}`);
|
|
103
|
+
assert.strictEqual(res.results.length, 100);
|
|
104
|
+
exp = new core_1.WebdaQL.QueryValidator('state = "CA" AND team.id < 5 AND role >= 4').getExpression();
|
|
105
|
+
res = yield store.find({ filter: exp, limit: 1000 });
|
|
106
|
+
assert.notStrictEqual(res.filter, true, `Should have post filter ${res.filter.toString()}`);
|
|
107
|
+
assert.strictEqual(res.results.length, 100);
|
|
108
|
+
assert.strictEqual(res.results.filter(c => res.filter.eval(c)).length, 50);
|
|
109
|
+
exp = new core_1.WebdaQL.QueryValidator('state = "CA" AND role <= 4').getExpression();
|
|
110
|
+
res = yield store.find({ filter: exp, limit: 1000 });
|
|
111
|
+
assert.notStrictEqual(res.filter, true, "Should have post filter");
|
|
112
|
+
assert.strictEqual(res.results.length, 250);
|
|
113
|
+
let items = ["CA", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"];
|
|
114
|
+
res = yield store.find({
|
|
115
|
+
filter: new core_1.WebdaQL.QueryValidator(`state IN [${items.map(i => `"${i}"`).join(",")}]`).getExpression(),
|
|
116
|
+
limit: 1000,
|
|
117
|
+
});
|
|
118
|
+
// Should be post filtered
|
|
119
|
+
assert.strictEqual(res.results.length, 1000);
|
|
120
|
+
res = yield store.find({
|
|
121
|
+
filter: new core_1.WebdaQL.QueryValidator(`state IN ["CA", "OR"] AND team.id IN [4,8]`).getExpression(),
|
|
122
|
+
limit: 1000,
|
|
123
|
+
});
|
|
124
|
+
assert.strictEqual(res.results.length, 500);
|
|
125
|
+
res = yield store.find({
|
|
126
|
+
filter: new core_1.WebdaQL.QueryValidator(`team.id < 5 AND state > "CA"`).getExpression(),
|
|
127
|
+
limit: 1000,
|
|
128
|
+
});
|
|
129
|
+
assert.strictEqual(res.results.length, 250);
|
|
130
|
+
return store;
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
queryOrder() {
|
|
134
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
135
|
+
// Disable default ordering query as it is not possible with Dynamo
|
|
136
|
+
let store = yield this.fillForQuery();
|
|
137
|
+
let res = yield store.query("order > 900 ORDER BY order DESC LIMIT 10");
|
|
138
|
+
assert.strictEqual(res.results.shift().order, 999);
|
|
139
|
+
res = yield store.query("ORDER BY order ASC LIMIT 10");
|
|
140
|
+
assert.strictEqual(res.results.shift().order, 0);
|
|
141
|
+
res = yield store.query("ORDER BY order DESC LIMIT 10");
|
|
142
|
+
assert.strictEqual(res.results.shift().order, 999);
|
|
143
|
+
res = yield store.query("ORDER BY state ASC, team.id ASC LIMIT 10");
|
|
144
|
+
res.results
|
|
145
|
+
.map(c => this.mapQueryModel(c))
|
|
146
|
+
.forEach(c => {
|
|
147
|
+
assert.deepStrictEqual({ teamId: 0, state: "CA" }, { teamId: c.teamId, state: c.state });
|
|
148
|
+
});
|
|
149
|
+
// It should not fail even if index is not found
|
|
150
|
+
res = yield store.query("ORDER BY state ASC, team.id DESC LIMIT 10");
|
|
151
|
+
res = yield store.query("order > 900 ORDER BY team.id ASC LIMIT 10");
|
|
152
|
+
res = yield store.query("ORDER BY team.id ASC, order DESC LIMIT 10");
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Query batch
|
|
157
|
+
*
|
|
158
|
+
* Code from Google Documentation
|
|
159
|
+
*
|
|
160
|
+
*/
|
|
161
|
+
deleteQueryBatch(db, query, resolve) {
|
|
162
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
163
|
+
const snapshot = yield query.get();
|
|
164
|
+
const batchSize = snapshot.size;
|
|
165
|
+
if (batchSize === 0) {
|
|
166
|
+
// When there are no documents left, we are done
|
|
167
|
+
resolve();
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
// Delete documents in a batch
|
|
171
|
+
const batch = db.batch();
|
|
172
|
+
snapshot.docs.forEach(doc => {
|
|
173
|
+
batch.delete(doc.ref);
|
|
174
|
+
});
|
|
175
|
+
yield batch.commit();
|
|
176
|
+
// Recurse on the next process tick, to avoid
|
|
177
|
+
// exploding the stack.
|
|
178
|
+
process.nextTick(() => {
|
|
179
|
+
this.deleteQueryBatch(db, query, resolve);
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
after() {
|
|
184
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
185
|
+
yield this.deleteCollection(`idents_${this.unitUuid}`, 10000);
|
|
186
|
+
yield this.deleteCollection(`users_${this.unitUuid}`, 10000);
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
deleteCondition() {
|
|
190
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
191
|
+
let idents = this.getIdentStore();
|
|
192
|
+
let obj = yield idents.save({
|
|
193
|
+
plop: 3,
|
|
194
|
+
});
|
|
195
|
+
yield assert.rejects(() => idents._delete(obj.getUuid(), 2, "plop"), /UpdateCondition not met/);
|
|
196
|
+
yield idents._delete(obj.getUuid(), 3, "plop");
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
cov() {
|
|
200
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
201
|
+
const store = this.getIdentStore();
|
|
202
|
+
yield assert.rejects(() => store.upsertItemToCollection("inexisting", "plop", {}, 0), /Item not found inexisting/);
|
|
203
|
+
sinon.stub(store, "getDocumentRef").callsFake(() => {
|
|
204
|
+
throw new Error("FAKE");
|
|
205
|
+
});
|
|
206
|
+
yield assert.rejects(() => store.upsertItemToCollection("inexisting", "plop", {}), /FAKE/);
|
|
207
|
+
yield assert.rejects(() => store.incrementAttribute("inexisting", "plop", 1), /FAKE/);
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
__decorate([
|
|
212
|
+
mocha_1.test
|
|
213
|
+
], FireStoreTest.prototype, "query", null);
|
|
214
|
+
__decorate([
|
|
215
|
+
mocha_1.test
|
|
216
|
+
], FireStoreTest.prototype, "queryOrder", null);
|
|
217
|
+
__decorate([
|
|
218
|
+
mocha_1.test
|
|
219
|
+
], FireStoreTest.prototype, "deleteCondition", null);
|
|
220
|
+
__decorate([
|
|
221
|
+
mocha_1.test
|
|
222
|
+
], FireStoreTest.prototype, "cov", null);
|
|
223
|
+
FireStoreTest = __decorate([
|
|
224
|
+
mocha_1.suite
|
|
225
|
+
], FireStoreTest);
|
|
226
|
+
//# sourceMappingURL=firestore.spec.js.map
|