entropic-bond 1.49.0 → 1.50.1
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/lib/auth/auth-mock.spec.d.ts +1 -0
- package/lib/cloud-functions/cloud-functions-mock.spec.d.ts +1 -0
- package/lib/cloud-storage/cloud-storage.spec.d.ts +1 -0
- package/lib/entropic-bond.js +1667 -0
- package/lib/entropic-bond.umd.cjs +7 -0
- package/lib/observable/observable.spec.d.ts +1 -0
- package/lib/persistent/entropic-component.spec.d.ts +1 -0
- package/lib/persistent/persistent.spec.d.ts +67 -0
- package/lib/server-auth/server-auth-mock.spec.d.ts +1 -0
- package/lib/store/json-data-source.spec.d.ts +1 -0
- package/lib/store/model.spec.d.ts +1 -0
- package/lib/store/store.spec.d.ts +1 -0
- package/lib/types/utility-types.spec.d.ts +1 -0
- package/lib/utils/utils.spec.d.ts +1 -0
- package/package.json +26 -19
- package/lib/auth/auth-mock.js +0 -111
- package/lib/auth/auth-mock.js.map +0 -1
- package/lib/auth/auth.js +0 -149
- package/lib/auth/auth.js.map +0 -1
- package/lib/auth/user-auth-types.js +0 -3
- package/lib/auth/user-auth-types.js.map +0 -1
- package/lib/cloud-functions/cloud-functions-mock.js +0 -19
- package/lib/cloud-functions/cloud-functions-mock.js.map +0 -1
- package/lib/cloud-functions/cloud-functions.js +0 -64
- package/lib/cloud-functions/cloud-functions.js.map +0 -1
- package/lib/cloud-storage/cloud-storage.js +0 -37
- package/lib/cloud-storage/cloud-storage.js.map +0 -1
- package/lib/cloud-storage/mock-cloud-storage.js +0 -68
- package/lib/cloud-storage/mock-cloud-storage.js.map +0 -1
- package/lib/cloud-storage/stored-file.js +0 -106
- package/lib/cloud-storage/stored-file.js.map +0 -1
- package/lib/index.js +0 -36
- package/lib/index.js.map +0 -1
- package/lib/observable/observable.js +0 -66
- package/lib/observable/observable.js.map +0 -1
- package/lib/persistent/entropic-component.js +0 -109
- package/lib/persistent/entropic-component.js.map +0 -1
- package/lib/persistent/persistent.js +0 -539
- package/lib/persistent/persistent.js.map +0 -1
- package/lib/server-auth/server-auth-mock.js +0 -39
- package/lib/server-auth/server-auth-mock.js.map +0 -1
- package/lib/server-auth/server-auth.js +0 -36
- package/lib/server-auth/server-auth.js.map +0 -1
- package/lib/store/data-source.js +0 -62
- package/lib/store/data-source.js.map +0 -1
- package/lib/store/json-data-source.js +0 -199
- package/lib/store/json-data-source.js.map +0 -1
- package/lib/store/mocks/test-user.js +0 -135
- package/lib/store/mocks/test-user.js.map +0 -1
- package/lib/store/model.js +0 -417
- package/lib/store/model.js.map +0 -1
- package/lib/store/store.js +0 -102
- package/lib/store/store.js.map +0 -1
- package/lib/types/utility-types.js +0 -3
- package/lib/types/utility-types.js.map +0 -1
- package/lib/utils/test-utils/test-person.js +0 -25
- package/lib/utils/test-utils/test-person.js.map +0 -1
- package/lib/utils/utils.js +0 -76
- package/lib/utils/utils.js.map +0 -1
package/lib/store/model.js
DELETED
|
@@ -1,417 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Query = exports.Model = void 0;
|
|
4
|
-
const persistent_1 = require("../persistent/persistent");
|
|
5
|
-
const data_source_1 = require("./data-source");
|
|
6
|
-
/**
|
|
7
|
-
* Provides abstraction to the database access. You should gain access to a Model
|
|
8
|
-
* object through the Store.getModel method instead of its constructor.
|
|
9
|
-
*/
|
|
10
|
-
class Model {
|
|
11
|
-
constructor(stream, persistentClass, subCollection) {
|
|
12
|
-
if (subCollection) {
|
|
13
|
-
if (!(persistentClass instanceof persistent_1.Persistent))
|
|
14
|
-
throw new Error(Model.error.persistentNeedForSubCollection);
|
|
15
|
-
this.collectionName = `${persistentClass.className}/${persistentClass.id}/${subCollection}`;
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
this.collectionName = persistentClass instanceof persistent_1.Persistent
|
|
19
|
-
? persistentClass.className
|
|
20
|
-
: persistentClass;
|
|
21
|
-
}
|
|
22
|
-
this._stream = stream;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Finds an stored object in the database by its id. The field id is provided
|
|
26
|
-
* by the Persistent parent class and it is automatically managed. Therefore,
|
|
27
|
-
* you should obtain the id by looking at the id field of the object.
|
|
28
|
-
*
|
|
29
|
-
* @param id the id to look for
|
|
30
|
-
* @param instance you can pass an instace that will be filled with the found data
|
|
31
|
-
* @returns a promise resolving to an instance with the found data
|
|
32
|
-
*/
|
|
33
|
-
findById(id, instance) {
|
|
34
|
-
return new Promise((resolve, reject) => {
|
|
35
|
-
this._stream.findById(id, this.collectionName)
|
|
36
|
-
.then((data) => {
|
|
37
|
-
if (data) {
|
|
38
|
-
if (!instance)
|
|
39
|
-
instance = persistent_1.Persistent.createInstance(data);
|
|
40
|
-
else
|
|
41
|
-
instance.fromObject(data);
|
|
42
|
-
resolve(instance);
|
|
43
|
-
}
|
|
44
|
-
else
|
|
45
|
-
resolve(undefined);
|
|
46
|
-
})
|
|
47
|
-
.catch(error => reject(error));
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Stores an object in the database
|
|
52
|
-
*
|
|
53
|
-
* @param instance the object instance to store
|
|
54
|
-
* @returns a promise
|
|
55
|
-
*/
|
|
56
|
-
save(instance) {
|
|
57
|
-
const obj = instance.toObject();
|
|
58
|
-
if (this.collectionName !== obj.__className) {
|
|
59
|
-
obj.__rootCollections[this.collectionName] = obj.__rootCollections[obj.__className];
|
|
60
|
-
delete obj.__rootCollections[obj.__className];
|
|
61
|
-
}
|
|
62
|
-
return new Promise((resolve, reject) => {
|
|
63
|
-
this._stream.save(obj.__rootCollections)
|
|
64
|
-
.then(() => resolve())
|
|
65
|
-
.catch(error => reject(error));
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Removes an element from the database by id
|
|
70
|
-
* @param id the id of the element to be removed
|
|
71
|
-
* @returns a promise
|
|
72
|
-
*/
|
|
73
|
-
delete(id) {
|
|
74
|
-
return new Promise((resolve, reject) => {
|
|
75
|
-
this._stream.delete(id, this.collectionName)
|
|
76
|
-
.then(() => resolve())
|
|
77
|
-
.catch(error => reject(error));
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Call find to retrieve a Query object used to define the search conditions
|
|
82
|
-
* @returns a Query object
|
|
83
|
-
*/
|
|
84
|
-
find() {
|
|
85
|
-
return new Query(this);
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Define the search conditions. You pass query operations and how the query
|
|
89
|
-
* results are returned to the QueryObject
|
|
90
|
-
* @param queryObject the QueryObject with the search constrains
|
|
91
|
-
* @param objectType Deprecated! - restricts the search to a specific instances of the class type
|
|
92
|
-
* @returns a promise resolving to a collection of matched documents
|
|
93
|
-
*/
|
|
94
|
-
query(queryObject = {}, /** @deprecated */ objectType) {
|
|
95
|
-
if (objectType) {
|
|
96
|
-
const className = objectType instanceof persistent_1.Persistent ? objectType.className : objectType;
|
|
97
|
-
if (!queryObject.operations)
|
|
98
|
-
queryObject.operations = [];
|
|
99
|
-
queryObject.operations.push({ property: '__className', operator: '==', value: className });
|
|
100
|
-
}
|
|
101
|
-
return this.mapToInstance(() => this._stream.find(this.preprocessQueryObject(queryObject), this.collectionName));
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Get the amount of documents matching the query
|
|
105
|
-
* @param queryObject the QueryObject with the search constrains
|
|
106
|
-
* @returns a promise resolving to the amount of matched documents
|
|
107
|
-
*/
|
|
108
|
-
count(queryObject) {
|
|
109
|
-
return this._stream.count(queryObject, this.collectionName);
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Get the next bunch of documents matching the last query
|
|
113
|
-
* @param limit the max amount of documents to retrieve. If not set, uses the
|
|
114
|
-
* last limit set
|
|
115
|
-
* @returns a promise resolving to a collection of matched documents
|
|
116
|
-
*/
|
|
117
|
-
next(limit) {
|
|
118
|
-
return this.mapToInstance(() => this._stream.next(limit));
|
|
119
|
-
}
|
|
120
|
-
// /**
|
|
121
|
-
// * Get the previous bunch of documents matching the last query
|
|
122
|
-
// * @param limit the max amount of documents to retrieve. If not set, uses the
|
|
123
|
-
// * last limit set
|
|
124
|
-
// * @returns a promise resolving to a collection of matched documents
|
|
125
|
-
// */
|
|
126
|
-
// prev<U extends T>( limit?: number ): Promise<U[]> {
|
|
127
|
-
// return this.mapToInstance( () => this._stream.prev( limit ) )
|
|
128
|
-
// }
|
|
129
|
-
mapToInstance(from) {
|
|
130
|
-
return new Promise((resolve, reject) => {
|
|
131
|
-
from()
|
|
132
|
-
.then(data => resolve(data.map(obj => persistent_1.Persistent.createInstance(obj))))
|
|
133
|
-
.catch(error => reject(error));
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Normalizes the query object to match the data source requirements.
|
|
138
|
-
* Call this method before you do any query operation on the concrete data source
|
|
139
|
-
* @param queryObject the query object containing the query operations
|
|
140
|
-
* @param operatorConversor a function that converts the query operators to the
|
|
141
|
-
* operators supported by the concrete data source
|
|
142
|
-
* @returns the normalized query object
|
|
143
|
-
*/
|
|
144
|
-
preprocessQueryObject(queryObject) {
|
|
145
|
-
if (Object.values(queryObject).length === 0)
|
|
146
|
-
return queryObject;
|
|
147
|
-
const operations = queryObject.operations?.map(operation => {
|
|
148
|
-
const value = operation.value[0] ?? operation.value;
|
|
149
|
-
if (data_source_1.DataSource.isArrayOperator(operation.operator) && value instanceof persistent_1.Persistent) {
|
|
150
|
-
return {
|
|
151
|
-
property: persistent_1.Persistent.searchableArrayNameFor(operation.property),
|
|
152
|
-
operator: operation.operator,
|
|
153
|
-
value: Array.isArray(operation.value) ? operation.value.map(v => v.id) : value.id,
|
|
154
|
-
aggregate: operation.aggregate
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
return {
|
|
159
|
-
property: operation.property,
|
|
160
|
-
operator: operation.operator,
|
|
161
|
-
value: operation.value instanceof persistent_1.Persistent ? { id: operation.value.id } : operation.value,
|
|
162
|
-
aggregate: operation.aggregate
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
}) ?? [];
|
|
166
|
-
return {
|
|
167
|
-
...queryObject,
|
|
168
|
-
operations
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
exports.Model = Model;
|
|
173
|
-
Model.error = {
|
|
174
|
-
persistentNeedForSubCollection: 'The document parameter for a sub-collection should be a Persistent instace',
|
|
175
|
-
invalidQueryOrder: 'Cannot add where calls after or calls'
|
|
176
|
-
};
|
|
177
|
-
/**
|
|
178
|
-
* The Query class is used to define the search conditions. You can chain
|
|
179
|
-
* where operations to define the search conditions. The where operations
|
|
180
|
-
* are stored in a QueryObject that is passed to the query method of the
|
|
181
|
-
* Model class.
|
|
182
|
-
*/
|
|
183
|
-
class Query {
|
|
184
|
-
constructor(model) {
|
|
185
|
-
this.queryObject = { operations: [] };
|
|
186
|
-
this.model = model;
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* Matches all documents that the value of the property satisfies the condition
|
|
190
|
-
* in the operator parameter. Subsequent `where` calls will be operated to the
|
|
191
|
-
* previous ones using the AND operator
|
|
192
|
-
* @param property the property to be compared
|
|
193
|
-
* @param operator the operator to be used in the comparison. The available
|
|
194
|
-
* operators are: ==, !=, >, >=, < and <=
|
|
195
|
-
* @param value the value to be compared
|
|
196
|
-
* @param aggregate if true, the query will use the logical or operator and
|
|
197
|
-
* aggregate the results to the previous query
|
|
198
|
-
* @returns this Query object to make chained calls possible
|
|
199
|
-
* @example
|
|
200
|
-
* query.where( 'name', '==', 'John' )
|
|
201
|
-
* query.where( 'age', '>', 18 )
|
|
202
|
-
* query.where( 'age', '==', 18 ).where( 'name', '==', 'John' )
|
|
203
|
-
* @see whereDeepProp
|
|
204
|
-
* @see or
|
|
205
|
-
* @see orDeepProp
|
|
206
|
-
*/
|
|
207
|
-
where(property, operator, value, aggregate) {
|
|
208
|
-
if (this.queryObject.operations?.at(-1)?.aggregate && !aggregate)
|
|
209
|
-
throw new Error(Model.error.invalidQueryOrder);
|
|
210
|
-
this.queryObject.operations?.push({
|
|
211
|
-
property,
|
|
212
|
-
operator,
|
|
213
|
-
value: value,
|
|
214
|
-
aggregate
|
|
215
|
-
});
|
|
216
|
-
return this;
|
|
217
|
-
}
|
|
218
|
-
// where2<P extends PropPath<T>>( property: P, operator: QueryOperator, value: PropPathType<T, P> ) {
|
|
219
|
-
// if ( property.indexOf( '.' ) > 0 ) return this.whereDeepProp( property, operator, value )
|
|
220
|
-
// let val = value instanceof Persistent? { id: value.id } : value
|
|
221
|
-
// this.queryObject.operations.push({
|
|
222
|
-
// property,
|
|
223
|
-
// operator,
|
|
224
|
-
// value: val
|
|
225
|
-
// })
|
|
226
|
-
// return this
|
|
227
|
-
// }
|
|
228
|
-
/**
|
|
229
|
-
* Matches all documents that the value of the deep property satisfies the condition
|
|
230
|
-
* in the operator parameter
|
|
231
|
-
* @param propertyPath the path to the property to be compared
|
|
232
|
-
* @param operator the operator to be used in the comparison. The available
|
|
233
|
-
* operators are: ==, !=, >, >=, < and <=
|
|
234
|
-
* @param value the value to be compared
|
|
235
|
-
* @returns this Query object to make chained calls possible
|
|
236
|
-
* @example
|
|
237
|
-
* query.whereDeepProp( 'address.street', '==', 'Main Street' )
|
|
238
|
-
* @see where
|
|
239
|
-
* @see or
|
|
240
|
-
* @see orDeepProp
|
|
241
|
-
*/
|
|
242
|
-
whereDeepProp(propertyPath, operator, value, aggregate) {
|
|
243
|
-
if (this.queryObject.operations?.at(-1)?.aggregate && !aggregate)
|
|
244
|
-
throw new Error(Model.error.invalidQueryOrder);
|
|
245
|
-
const props = propertyPath.split('.');
|
|
246
|
-
let obj = {};
|
|
247
|
-
let result = props.length > 1 ? obj : value; // TODO: review
|
|
248
|
-
props.slice(1).forEach((prop, i) => {
|
|
249
|
-
obj[prop] = i < props.length - 2 ? {} : value;
|
|
250
|
-
obj = obj[prop];
|
|
251
|
-
});
|
|
252
|
-
this.queryObject.operations?.push({
|
|
253
|
-
property: props[0],
|
|
254
|
-
operator,
|
|
255
|
-
value: result,
|
|
256
|
-
aggregate
|
|
257
|
-
});
|
|
258
|
-
return this;
|
|
259
|
-
}
|
|
260
|
-
/**
|
|
261
|
-
* Matches all documents that the value of the property satisfies the condition
|
|
262
|
-
* in the operator parameter and aggregates the results to the previous query
|
|
263
|
-
* @param property the property to be compared
|
|
264
|
-
* @param operator the operator to be used in the comparison. The available
|
|
265
|
-
* operators are: ==, !=, >, >=, < and <=
|
|
266
|
-
* @returns this Query object to make chained calls possible
|
|
267
|
-
* @example
|
|
268
|
-
* query.where( 'name', '==', 'John' ).and( 'age', '>', 18 )
|
|
269
|
-
* @see andDeepProp
|
|
270
|
-
* @see where
|
|
271
|
-
* @see whereDeepProp
|
|
272
|
-
* @see or
|
|
273
|
-
* @see orDeepProp
|
|
274
|
-
*/
|
|
275
|
-
and(property, operator, value) {
|
|
276
|
-
return this.where(property, operator, value);
|
|
277
|
-
}
|
|
278
|
-
/**
|
|
279
|
-
* Matches all documents that the value of the deep property satisfies the condition
|
|
280
|
-
* in the operator parameter and aggregates the results to the previous query
|
|
281
|
-
* @param propertyPath the path to the property to be compared
|
|
282
|
-
* @param operator the operator to be used in the comparison. The available
|
|
283
|
-
* operators are: ==, !=, >, >=, < and <=
|
|
284
|
-
* @param value the value to be compared
|
|
285
|
-
* @returns this Query object to make chained calls possible
|
|
286
|
-
* @example
|
|
287
|
-
* query.whereDeepProp( 'address.street', '==', 'Main Street' ).andDeepProp( 'address.city', '==', 'New York' )
|
|
288
|
-
* @see and
|
|
289
|
-
* @see where
|
|
290
|
-
* @see whereDeepProp
|
|
291
|
-
* @see or
|
|
292
|
-
* @see orDeepProp
|
|
293
|
-
*/
|
|
294
|
-
andDeepProp(propertyPath, operator, value) {
|
|
295
|
-
return this.whereDeepProp(propertyPath, operator, value);
|
|
296
|
-
}
|
|
297
|
-
/**
|
|
298
|
-
* Matches all documents that the value of the property satisfies the condition
|
|
299
|
-
* in the operator parameter and aggregates the results to the previous query
|
|
300
|
-
* @param property the property to be compared
|
|
301
|
-
* @param operator the operator to be used in the comparison. The available
|
|
302
|
-
* operators are: ==, !=, >, >=, < and <=
|
|
303
|
-
* @returns this Query object to make chained calls possible
|
|
304
|
-
* @example
|
|
305
|
-
* query.or( 'name', '==', 'John' )
|
|
306
|
-
* query.or( 'age', '>', 18 )
|
|
307
|
-
* @see orDeepProp
|
|
308
|
-
* @see where
|
|
309
|
-
* @see whereDeepProp
|
|
310
|
-
*/
|
|
311
|
-
or(property, operator, value) {
|
|
312
|
-
return this.where(property, operator, value, true);
|
|
313
|
-
}
|
|
314
|
-
/**
|
|
315
|
-
* Matches all documents that the value of the deep property satisfies the condition
|
|
316
|
-
* in the operator parameter and aggregates the results to the previous query
|
|
317
|
-
* @param propertyPath the path to the property to be compared
|
|
318
|
-
* @param operator the operator to be used in the comparison. The available
|
|
319
|
-
* operators are: ==, !=, >, >=, < and <=
|
|
320
|
-
* @param value the value to be compared
|
|
321
|
-
* @returns this Query object to make chained calls possible
|
|
322
|
-
* @example
|
|
323
|
-
* query.orDeepProp( 'address.street', '==', 'Main Street' )
|
|
324
|
-
* @see or
|
|
325
|
-
* @see where
|
|
326
|
-
* @see whereDeepProp
|
|
327
|
-
*/
|
|
328
|
-
orDeepProp(propertyPath, operator, value) {
|
|
329
|
-
return this.whereDeepProp(propertyPath, operator, value, true);
|
|
330
|
-
}
|
|
331
|
-
/**
|
|
332
|
-
* Defines a where condition to match documents that are instances of the
|
|
333
|
-
* given class
|
|
334
|
-
* @param classId the class name or an instance to match
|
|
335
|
-
* @returns this Query object to make chained calls possible
|
|
336
|
-
* @example
|
|
337
|
-
* query.instanceOf( 'Person' )
|
|
338
|
-
* query.instanceOf( Person )
|
|
339
|
-
* query.instanceOf( Person ).where( 'age', '>', 18 )
|
|
340
|
-
*/
|
|
341
|
-
instanceOf(classId) {
|
|
342
|
-
const className = classId instanceof persistent_1.Persistent ? classId.className : classId;
|
|
343
|
-
this.queryObject.operations?.push({
|
|
344
|
-
property: '__className',
|
|
345
|
-
operator: '==',
|
|
346
|
-
value: className
|
|
347
|
-
});
|
|
348
|
-
return this;
|
|
349
|
-
}
|
|
350
|
-
/**
|
|
351
|
-
* Executes the query and returns the result
|
|
352
|
-
* @param limit the max amount of documents to retrieve. If not set, uses the
|
|
353
|
-
* last limit set or all the matching documents
|
|
354
|
-
* @returns a promise resolving to a collection of matched documents
|
|
355
|
-
* @example
|
|
356
|
-
* const namedJohn = await query.where( 'name', '==', 'John' ).get()
|
|
357
|
-
*/
|
|
358
|
-
get(limit) {
|
|
359
|
-
if (limit) {
|
|
360
|
-
this.queryObject.limit = limit;
|
|
361
|
-
}
|
|
362
|
-
return this.model.query(this.queryObject);
|
|
363
|
-
}
|
|
364
|
-
/**
|
|
365
|
-
* Limits the number of documents to retrieve
|
|
366
|
-
* @param maxDocs the max amount of documents to retrieve
|
|
367
|
-
* @returns this Query object to make chained calls possible
|
|
368
|
-
* @example
|
|
369
|
-
* query.where( 'name', '==', 'John' ).limit( 10 )
|
|
370
|
-
*/
|
|
371
|
-
limit(maxDocs) {
|
|
372
|
-
this.queryObject.limit = maxDocs;
|
|
373
|
-
return this;
|
|
374
|
-
}
|
|
375
|
-
/**
|
|
376
|
-
* Orders the result set by a property.
|
|
377
|
-
* @param propertyName The name of the property to order by
|
|
378
|
-
* @param order The sort direction. Possible values are 'asc' and 'desc'
|
|
379
|
-
* @returns a chainable query object
|
|
380
|
-
* @example
|
|
381
|
-
* query.orderBy( 'name', 'asc' )
|
|
382
|
-
* query.orderBy( 'age', 'desc' )
|
|
383
|
-
*/
|
|
384
|
-
orderBy(propertyName, order = 'asc') {
|
|
385
|
-
this.queryObject.sort = {
|
|
386
|
-
propertyName,
|
|
387
|
-
order
|
|
388
|
-
};
|
|
389
|
-
return this;
|
|
390
|
-
}
|
|
391
|
-
/**
|
|
392
|
-
* Orders the result set by a deep property
|
|
393
|
-
*
|
|
394
|
-
* @param propertyPath The full path of the deep property. It should be
|
|
395
|
-
* separated by dots like person.name.firstName.
|
|
396
|
-
* @param order The sort direction. Possible values are 'asc' and 'desc'
|
|
397
|
-
* @returns a chainable query object
|
|
398
|
-
*/
|
|
399
|
-
orderByDeepProp(propertyPath, order = 'asc') {
|
|
400
|
-
this.queryObject.sort = {
|
|
401
|
-
propertyName: propertyPath,
|
|
402
|
-
order
|
|
403
|
-
};
|
|
404
|
-
return this;
|
|
405
|
-
}
|
|
406
|
-
/**
|
|
407
|
-
* Returns the number of documents that match the query
|
|
408
|
-
* @returns a promise resolving to the number of documents that match the query
|
|
409
|
-
* @example
|
|
410
|
-
* const count = await query.where( 'name', '==', 'John' ).count()
|
|
411
|
-
*/
|
|
412
|
-
count() {
|
|
413
|
-
return this.model.count(this.queryObject);
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
exports.Query = Query;
|
|
417
|
-
//# sourceMappingURL=model.js.map
|
package/lib/store/model.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"model.js","sourceRoot":"","sources":["../../src/store/model.ts"],"names":[],"mappings":";;;AAAA,yDAAuE;AAEvE,+CAAkH;AAElH;;;GAGG;AACH,MAAa,KAAK;IAMjB,YAAa,MAAkB,EAAE,eAAoC,EAAE,aAAsB;QAC5F,IAAK,aAAa,EAAG;YACpB,IAAI,CAAC,CAAE,eAAe,YAAY,uBAAU,CAAE;gBAAG,MAAM,IAAI,KAAK,CAAE,KAAK,CAAC,KAAK,CAAC,8BAA8B,CAAE,CAAA;YAE9G,IAAI,CAAC,cAAc,GAAG,GAAI,eAAe,CAAC,SAAU,IAAK,eAAe,CAAC,EAAG,IAAK,aAAc,EAAE,CAAA;SACjG;aACI;YACJ,IAAI,CAAC,cAAc,GAAG,eAAe,YAAY,uBAAU;gBAC1D,CAAC,CAAC,eAAe,CAAC,SAAS;gBAC3B,CAAC,CAAC,eAAe,CA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,IAAI,CAAC,WAAW,CAAC,KAAK,GAAG,KAAK,CAAA;SAC9B;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAE,IAAI,CAAC,WAAwC,CAAE,CAAA;IACzE,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAE,OAAe;QACrB,IAAI,CAAC,WAAW,CAAC,KAAK,GAAG,OAAO,CAAA;QAChC,OAAO,IAAI,CAAA;IACZ,CAAC;IAED;;;;;;;;OAQG;IACH,OAAO,CAA+B,YAAe,EAAE,QAAoB,KAAK;QAC/E,IAAI,CAAC,WAAW,CAAC,IAAI,GAAG;YACvB,YAAY;YACZ,KAAK;SACL,CAAA;QAED,OAAO,IAAI,CAAA;IACZ,CAAC;IAED;;;;;;;OAOG;IACH,eAAe,CAAE,YAAoB,EAAE,QAAoB,KAAK;QAC/D,IAAI,CAAC,WAAW,CAAC,IAAI,GAAG;YACvB,YAAY,EAAE,YAAY;YAC1B,KAAK;SACL,CAAA;QAED,OAAO,IAAI,CAAA;IACZ,CAAC;IAED;;;;;OAKG;IACH,KAAK;QACJ,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAE,IAAI,CAAC,WAAW,CAAE,CAAA;IAC5C,CAAC;CAID;AAhQD,sBAgQC"}
|
package/lib/store/store.js
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Store = void 0;
|
|
4
|
-
const model_1 = require("./model");
|
|
5
|
-
/**
|
|
6
|
-
* The store is the main entry point for the data access layer.
|
|
7
|
-
* It provides methods to retrieve models for collections and subcollections.
|
|
8
|
-
* It also provides methods to populate property references with actual data from the store.
|
|
9
|
-
* You need to register a data source before using the store.
|
|
10
|
-
* @example
|
|
11
|
-
* // Register a data source
|
|
12
|
-
* Store.useDataSource( new FirestoreDataSource( firebase.firestore() ) )
|
|
13
|
-
* // Retrieve a model for a collection
|
|
14
|
-
* const model = Store.getModel( 'User' )
|
|
15
|
-
* // Retrieve a model for a subcollection
|
|
16
|
-
* const model = Store.getModelForSubCollection( user, 'Posts' )
|
|
17
|
-
* // Populate property references
|
|
18
|
-
* const user = await Store.populate( user )
|
|
19
|
-
*/
|
|
20
|
-
class Store {
|
|
21
|
-
constructor() { }
|
|
22
|
-
/**
|
|
23
|
-
* Registers a data source to be used by the store.
|
|
24
|
-
* You need to register a data source before using the store.
|
|
25
|
-
* @param dataSource the data source to be used by the store
|
|
26
|
-
*/
|
|
27
|
-
static useDataSource(dataSource) {
|
|
28
|
-
this._dataSource = dataSource;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* The data source currently used by the store
|
|
32
|
-
* @returns the data source
|
|
33
|
-
*/
|
|
34
|
-
static get dataSource() {
|
|
35
|
-
return Store._dataSource;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Retrieves a model for a collection
|
|
39
|
-
* @param classId the class name or an instance of the document type stored in the collection
|
|
40
|
-
* @returns the model for the collection
|
|
41
|
-
*/
|
|
42
|
-
static getModel(classId) {
|
|
43
|
-
if (!Store._dataSource)
|
|
44
|
-
throw new Error(this.error.shouldBeRegistered);
|
|
45
|
-
return new model_1.Model(Store._dataSource, classId);
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Retrieves a model for a subcollection
|
|
49
|
-
* @param document the persistent object that owns the subcollection
|
|
50
|
-
* @param subCollection the name of the subcollection
|
|
51
|
-
* @returns the model for the subcollection
|
|
52
|
-
*/
|
|
53
|
-
static getModelForSubCollection(document, subCollection) {
|
|
54
|
-
if (!Store._dataSource)
|
|
55
|
-
throw new Error(this.error.shouldBeRegistered);
|
|
56
|
-
return new model_1.Model(Store._dataSource, document, subCollection);
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Populates property references with actual data from the store.
|
|
60
|
-
* It will not retrieve data if the instance is already populated
|
|
61
|
-
* @param instance the data to be populated.
|
|
62
|
-
* @returns the populated instance
|
|
63
|
-
*/
|
|
64
|
-
static async populate(instance) {
|
|
65
|
-
if (!instance)
|
|
66
|
-
return undefined;
|
|
67
|
-
const populateItem = async (item) => {
|
|
68
|
-
const ref = item;
|
|
69
|
-
if (!ref.__documentReference)
|
|
70
|
-
return item;
|
|
71
|
-
const model = this.getModel(ref.__documentReference.storedInCollection);
|
|
72
|
-
const populated = await model.findById(ref.id, item);
|
|
73
|
-
if (populated) {
|
|
74
|
-
populated['__documentReference'] = undefined;
|
|
75
|
-
}
|
|
76
|
-
return populated;
|
|
77
|
-
};
|
|
78
|
-
if (Array.isArray(instance)) {
|
|
79
|
-
const items = await Promise.all(instance.map(item => populateItem(item)));
|
|
80
|
-
return items.filter(item => item);
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
return populateItem(instance);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Checks if an instance is populated
|
|
88
|
-
* @param instance the instance or array of instances to be checked
|
|
89
|
-
* @returns true if the instance is populated
|
|
90
|
-
*/
|
|
91
|
-
static isPopulated(instance) {
|
|
92
|
-
if (Array.isArray(instance)) {
|
|
93
|
-
return instance.reduce((prevVal, item) => prevVal && item['__documentReference'] === undefined, true);
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
return instance['__documentReference'] === undefined;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
exports.Store = Store;
|
|
101
|
-
Store.error = { shouldBeRegistered: 'You should register a data source before using the data Store.' };
|
|
102
|
-
//# sourceMappingURL=store.js.map
|
package/lib/store/store.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/store/store.ts"],"names":[],"mappings":";;;AAEA,mCAAgC;AAEhC;;;;;;;;;;;;;;GAcG;AACH,MAAa,KAAK;IACjB,gBAAsB,CAAC;IAIvB;;;;OAIG;IACH,MAAM,CAAC,aAAa,CAAE,UAAsB;Q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AAS,CAAA;QACjB,CAAC,CAAA;QAED,IAAK,KAAK,CAAC,OAAO,CAAE,QAAQ,CAAE,EAAG;YAChC,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,GAAG,CAC9B,QAAQ,CAAC,GAAG,CAAE,IAAI,CAAC,EAAE,CAAC,YAAY,CAAE,IAAI,CAAE,CAAE,CAC5C,CAAA;YACD,OAAO,KAAK,CAAC,MAAM,CAAE,IAAI,CAAC,EAAE,CAAC,IAAI,CAAO,CAAA;SACxC;aACI;YACJ,OAAO,YAAY,CAAE,QAAQ,CAAgB,CAAA;SAC7C;IACF,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,WAAW,CAAyB,QAA0B;QACpE,IAAK,KAAK,CAAC,OAAO,CAAE,QAAQ,CAAE,EAAG;YAChC,OAAO,QAAQ,CAAC,MAAM,CACrB,CAAE,OAAO,EAAE,IAAI,EAAG,EAAE,CAAC,OAAO,IAAI,IAAI,CAAC,qBAAqB,CAAC,KAAK,SAAS,EACzE,IAAI,CACJ,CAAA;SACD;aACI;YACJ,OAAO,QAAQ,CAAC,qBAAqB,CAAC,KAAK,SAAS,CAAA;SACpD;IACF,CAAC;;AA1FF,sBA6FC;AA1FO,WAAK,GAAG,EAAE,kBAAkB,EAAE,gEAAgE,EAAE,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utility-types.js","sourceRoot":"","sources":["../../src/types/utility-types.ts"],"names":[],"mappings":""}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.samplePerson = void 0;
|
|
4
|
-
function samplePerson() {
|
|
5
|
-
return ({
|
|
6
|
-
id: 'testPersonId',
|
|
7
|
-
age: 34,
|
|
8
|
-
name: {
|
|
9
|
-
firstName: 'Joe',
|
|
10
|
-
secondName: 'Manteca'
|
|
11
|
-
},
|
|
12
|
-
address: {
|
|
13
|
-
coordinates: {
|
|
14
|
-
x: 10,
|
|
15
|
-
y: 20
|
|
16
|
-
},
|
|
17
|
-
postalAddress: 'Madison Av.',
|
|
18
|
-
senderMethod() { }
|
|
19
|
-
},
|
|
20
|
-
testMethod() { },
|
|
21
|
-
deepProp: { l1: { l2: { l3: { l4: { l5: { l6: {} } } } } } }
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
exports.samplePerson = samplePerson;
|
|
25
|
-
//# sourceMappingURL=test-person.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"test-person.js","sourceRoot":"","sources":["../../../src/utils/test-utils/test-person.ts"],"names":[],"mappings":";;;AAuBA,SAAgB,YAAY;IAC3B,OAAO,CAAC;QACP,EAAE,EAAE,cAAc;QAClB,GAAG,EAAE,EAAE;QACP,IAAI,EAAE;YACL,SAAS,EAAE,KAAK;YAChB,UAAU,EAAE,SAAS;SACrB;QACD,OAAO,EAAE;YACR,WAAW,EAAE;gBACZ,CAAC,EAAE,EAAE;gBACL,CAAC,EAAE,EAAE;aACL;YACD,aAAa,EAAE,aAAa;YAC5B,YAAY,KAAG,CAAC;SAChB;QACD,UAAU,KAAG,CAAC;QACd,QAAQ,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAC,EAAC,EAAC,EAAC,EAAC,EAAC;KACtD,CAAC,CAAA;AACH,CAAC;AAnBD,oCAmBC"}
|
package/lib/utils/utils.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getDeepValue = exports.snakeCase = exports.camelCase = exports.replaceValue = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Replaces keys found in a string for its values. The keys should be inserted
|
|
6
|
-
* inside brackets ${ key } as is done in the string template literals substitutions
|
|
7
|
-
* @param text the string template
|
|
8
|
-
* @param values an object with key-value pairs
|
|
9
|
-
* @returns the string filled with corresponding values
|
|
10
|
-
* @example
|
|
11
|
-
* const text = 'Hello ${name}, how are you ${ action }?'
|
|
12
|
-
* const values = { name: 'John', action: 'today' }
|
|
13
|
-
* const result = replaceValue( text, values )
|
|
14
|
-
* // result = 'Hello John, how are you today?'
|
|
15
|
-
*/
|
|
16
|
-
function replaceValue(text, values) {
|
|
17
|
-
if (!text)
|
|
18
|
-
return '';
|
|
19
|
-
return text.replace(/\${\s*(\w*)\s*}/g, function (_match, group) {
|
|
20
|
-
return values[group] || '';
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
exports.replaceValue = replaceValue;
|
|
24
|
-
/**
|
|
25
|
-
* Transforms a string to a camel case format (camelCaseFormat)
|
|
26
|
-
* @param str the string to transform. It can be a string with spaces or a
|
|
27
|
-
* snake case format
|
|
28
|
-
* @returns the camel case transformed string
|
|
29
|
-
* @example
|
|
30
|
-
* const str = 'snake-case-format'
|
|
31
|
-
* const result = camelCase( str )
|
|
32
|
-
* // result = 'snakeCaseFormat'
|
|
33
|
-
*/
|
|
34
|
-
function camelCase(str) {
|
|
35
|
-
if (!str)
|
|
36
|
-
return '';
|
|
37
|
-
return str.replace(/([-_ ][\w])/g, group => group.toUpperCase().replace('-', '').replace('_', '').replace(' ', ''));
|
|
38
|
-
}
|
|
39
|
-
exports.camelCase = camelCase;
|
|
40
|
-
/**
|
|
41
|
-
* Transforms a string in to a snake case format (snake-case-format)
|
|
42
|
-
* @param str the string to transform. It can be a string with spaces or a camel
|
|
43
|
-
* case format
|
|
44
|
-
* @param snakeChar the character used to separate words. If the passed string is
|
|
45
|
-
* in camel case and the snakeChar is a space, this will transform the came case
|
|
46
|
-
* string in to a regular spaced string
|
|
47
|
-
* @returns the snake case transformed string
|
|
48
|
-
* @example
|
|
49
|
-
* const str = 'camelCaseFormat'
|
|
50
|
-
* const result = snakeCase( str )
|
|
51
|
-
* // result = 'camel-case-format'
|
|
52
|
-
*/
|
|
53
|
-
function snakeCase(str, snakeChar = '-') {
|
|
54
|
-
if (!str)
|
|
55
|
-
return '';
|
|
56
|
-
const replaced = str.slice(1).replace(/( |[A-Z])/g, g => g === ' ' ? '-' : snakeChar + g[0].toLowerCase());
|
|
57
|
-
return str[0].toLocaleLowerCase() + replaced.replace(/--/g, '-');
|
|
58
|
-
}
|
|
59
|
-
exports.snakeCase = snakeCase;
|
|
60
|
-
/**
|
|
61
|
-
* Gets the value of the supproperty in the passed object
|
|
62
|
-
*
|
|
63
|
-
* @param obj the object containing the subproperty
|
|
64
|
-
* @param path a string containing the subproperty path in dotted notation
|
|
65
|
-
* @returns the value of the supproperty in the passed object
|
|
66
|
-
* @example
|
|
67
|
-
* const obj = { a: { b: { c: 1 } } }
|
|
68
|
-
* const path = 'a.b.c'
|
|
69
|
-
* const result = getDeepValue( obj, path )
|
|
70
|
-
* // result = 1
|
|
71
|
-
*/
|
|
72
|
-
function getDeepValue(obj, path) {
|
|
73
|
-
return path.split('.').reduce((acc, prop) => acc[prop], obj);
|
|
74
|
-
}
|
|
75
|
-
exports.getDeepValue = getDeepValue;
|
|
76
|
-
//# sourceMappingURL=utils.js.map
|
package/lib/utils/utils.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils/utils.ts"],"names":[],"mappings":";;;AAWA;;;;;;;;;;;GAWG;AACH,SAAgB,YAAY,CAAE,IAA+B,EAAE,MAAc;IAC5E,IAAK,CAAC,IAAI;QAAG,OAAO,EAAE,CAAA;IAEtB,OAAO,IAAI,CAAC,OAAO,CAAC,kBAAkB,EAAE,UAAU,MAAM,EAAG,KAAK;QAC/D,OAAO,MAAM,CAAE,KAAK,CAAE,IAAI,EAAE,CAAC;IAC9B,CAAC,CAAC,CAAC;AACJ,CAAC;AAND,oCAMC;AAED;;;;;;;;;GASG;AACH,SAAgB,SAAS,CAAE,GAA8B;IACxD,IAAK,CAAC,GAA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