@roit/roit-data-firestore 0.0.54 → 0.1.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/README.md +35 -0
- package/dist/config/BaseRepository.d.ts +2 -0
- package/dist/config/BaseRepository.js +6 -0
- package/dist/config/ReadonlyRepository.d.ts +2 -0
- package/dist/config/ReadonlyRepository.js +6 -0
- package/dist/model/MQuery.d.ts +3 -0
- package/dist/model/MQuery.js +4 -1
- package/dist/model/QueryResult.d.ts +4 -0
- package/dist/model/QueryResult.js +6 -0
- package/dist/model/index.d.ts +1 -0
- package/dist/model/index.js +1 -0
- package/dist/query/ManualQueryHelper.d.ts +4 -1
- package/dist/query/ManualQueryHelper.js +24 -4
- package/dist/query/QueryCreatorConfig.d.ts +5 -1
- package/dist/query/QueryCreatorConfig.js +32 -13
- package/dist/query/operator/CreateFunction.js +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/config/BaseRepository.ts +6 -0
- package/src/config/ReadonlyRepository.ts +6 -0
- package/src/model/MQuery.ts +4 -0
- package/src/model/QueryResult.ts +4 -0
- package/src/model/index.ts +2 -1
- package/src/query/ManualQueryHelper.ts +27 -8
- package/src/query/QueryCreatorConfig.ts +14 -3
- package/src/query/operator/CreateFunction.ts +1 -1
- package/dist/src/main/cache/CacheResolver.d.ts +0 -15
- package/dist/src/main/cache/CacheResolver.js +0 -88
- package/dist/src/main/cache/providers/CacheProvider.d.ts +0 -6
- package/dist/src/main/cache/providers/CacheProvider.js +0 -2
- package/dist/src/main/cache/providers/InMemoryCacheProvider.d.ts +0 -8
- package/dist/src/main/cache/providers/InMemoryCacheProvider.js +0 -46
- package/dist/src/main/cache/providers/RedisCacheProvider.d.ts +0 -18
- package/dist/src/main/cache/providers/RedisCacheProvider.js +0 -117
- package/dist/src/main/cache/providers/index.d.ts +0 -2
- package/dist/src/main/cache/providers/index.js +0 -5
- package/dist/src/main/config/BaseRepository.d.ts +0 -29
- package/dist/src/main/config/BaseRepository.js +0 -64
- package/dist/src/main/config/ClassCollectionMap.d.ts +0 -7
- package/dist/src/main/config/ClassCollectionMap.js +0 -16
- package/dist/src/main/config/ClassMethodQueryMap.d.ts +0 -11
- package/dist/src/main/config/ClassMethodQueryMap.js +0 -31
- package/dist/src/main/config/FirestoreInstance.d.ts +0 -7
- package/dist/src/main/config/FirestoreInstance.js +0 -31
- package/dist/src/main/config/ReadonlyRepository.d.ts +0 -7
- package/dist/src/main/config/ReadonlyRepository.js +0 -40
- package/dist/src/main/decorators/Cacheable.d.ts +0 -2
- package/dist/src/main/decorators/Cacheable.js +0 -11
- package/dist/src/main/decorators/Query.d.ts +0 -5
- package/dist/src/main/decorators/Query.js +0 -18
- package/dist/src/main/decorators/Repository.d.ts +0 -2
- package/dist/src/main/decorators/Repository.js +0 -39
- package/dist/src/main/emulator/FirestoreEmuator.d.ts +0 -1
- package/dist/src/main/emulator/FirestoreEmuator.js +0 -26
- package/dist/src/main/exception/RepositoryBusinessException.d.ts +0 -4
- package/dist/src/main/exception/RepositoryBusinessException.js +0 -10
- package/dist/src/main/exception/RepositoryException.d.ts +0 -14
- package/dist/src/main/exception/RepositoryException.js +0 -23
- package/dist/src/main/exception/RepositorySystemException.d.ts +0 -4
- package/dist/src/main/exception/RepositorySystemException.js +0 -10
- package/dist/src/main/exception/RepositoryValidationException.d.ts +0 -5
- package/dist/src/main/exception/RepositoryValidationException.js +0 -10
- package/dist/src/main/exception/handle/ValidatorDataHandle.d.ts +0 -6
- package/dist/src/main/exception/handle/ValidatorDataHandle.js +0 -55
- package/dist/src/main/firestore-read-audit/FirestoreReadAuditResolver.d.ts +0 -10
- package/dist/src/main/firestore-read-audit/FirestoreReadAuditResolver.js +0 -50
- package/dist/src/main/firestore-read-audit/providers/BigQueryFirestoreReadAuditProvider.d.ts +0 -13
- package/dist/src/main/firestore-read-audit/providers/BigQueryFirestoreReadAuditProvider.js +0 -111
- package/dist/src/main/firestore-read-audit/providers/FirestoreReadAuditProvider.d.ts +0 -4
- package/dist/src/main/firestore-read-audit/providers/FirestoreReadAuditProvider.js +0 -2
- package/dist/src/main/firestore-read-audit/providers/PubSubFirestoreReadAuditProvider.d.ts +0 -9
- package/dist/src/main/firestore-read-audit/providers/PubSubFirestoreReadAuditProvider.js +0 -59
- package/dist/src/main/index.d.ts +0 -15
- package/dist/src/main/index.js +0 -35
- package/dist/src/main/model/CacheProviders.d.ts +0 -4
- package/dist/src/main/model/CacheProviders.js +0 -8
- package/dist/src/main/model/CacheableOptions.d.ts +0 -13
- package/dist/src/main/model/CacheableOptions.js +0 -20
- package/dist/src/main/model/MQuery.d.ts +0 -20
- package/dist/src/main/model/MQuery.js +0 -24
- package/dist/src/main/model/Paging.d.ts +0 -7
- package/dist/src/main/model/Paging.js +0 -12
- package/dist/src/main/model/PersistFirestoreReadProps.d.ts +0 -19
- package/dist/src/main/model/PersistFirestoreReadProps.js +0 -2
- package/dist/src/main/model/QueryPredicate.d.ts +0 -6
- package/dist/src/main/model/QueryPredicate.js +0 -6
- package/dist/src/main/model/RepositoryOptions.d.ts +0 -6
- package/dist/src/main/model/RepositoryOptions.js +0 -6
- package/dist/src/main/model/index.d.ts +0 -6
- package/dist/src/main/model/index.js +0 -18
- package/dist/src/main/platform/PlatformTools.d.ts +0 -3
- package/dist/src/main/platform/PlatformTools.js +0 -46
- package/dist/src/main/query/ManualQueryHelper.d.ts +0 -6
- package/dist/src/main/query/ManualQueryHelper.js +0 -106
- package/dist/src/main/query/QueryCreatorConfig.d.ts +0 -5
- package/dist/src/main/query/QueryCreatorConfig.js +0 -21
- package/dist/src/main/query/QueryPredicateFunctionTransform.d.ts +0 -9
- package/dist/src/main/query/QueryPredicateFunctionTransform.js +0 -77
- package/dist/src/main/query/TransformMethodFromQuery.d.ts +0 -6
- package/dist/src/main/query/TransformMethodFromQuery.js +0 -38
- package/dist/src/main/query/operator/CreateFunction.d.ts +0 -13
- package/dist/src/main/query/operator/CreateFunction.js +0 -288
- package/dist/src/main/query/operator/OperatorMap.d.ts +0 -1
- package/dist/src/main/query/operator/OperatorMap.js +0 -62
- package/dist/src/main/tsconfig.build.tsbuildinfo +0 -1
- package/dist/src/main/util/EnvironmentUtil.d.ts +0 -3
- package/dist/src/main/util/EnvironmentUtil.js +0 -10
- package/dist/src/main/util/TemplateLoading.d.ts +0 -4
- package/dist/src/main/util/TemplateLoading.js +0 -30
package/README.md
CHANGED
|
@@ -262,6 +262,41 @@ export class Repository1 extends BaseRepository<User> {
|
|
|
262
262
|
}
|
|
263
263
|
```
|
|
264
264
|
|
|
265
|
+
#### Paginated Query
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
Use queryPaginated() method preset in BaseRepository
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
findByNameAndId(name: string, id: string, paging: Paging): Promise<QueryResult<User>> {
|
|
274
|
+
return this.queryPaginated({
|
|
275
|
+
query: [
|
|
276
|
+
{
|
|
277
|
+
field: 'name',
|
|
278
|
+
operator: '==',
|
|
279
|
+
value: name
|
|
280
|
+
},
|
|
281
|
+
{
|
|
282
|
+
field: 'id',
|
|
283
|
+
operator: '==',
|
|
284
|
+
value: id
|
|
285
|
+
}
|
|
286
|
+
],
|
|
287
|
+
paging
|
|
288
|
+
})
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
The return of this method is a QueryResult:
|
|
292
|
+
|
|
293
|
+
class QueryResult<T = any> {
|
|
294
|
+
data: T[];
|
|
295
|
+
totalItens: number | null;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
```
|
|
299
|
+
|
|
265
300
|
#### Select Example
|
|
266
301
|
|
|
267
302
|
```
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { QueryResult } from "../model";
|
|
1
2
|
import { Config } from '../model/MQuery';
|
|
2
3
|
import { Paging } from "../model/Paging";
|
|
3
4
|
export declare abstract class BaseRepository<T> {
|
|
@@ -33,4 +34,5 @@ export declare abstract class BaseRepository<T> {
|
|
|
33
34
|
*/
|
|
34
35
|
incrementField: (id: Required<string>, field: Required<string>, increment?: number) => Promise<void>;
|
|
35
36
|
query(config: Config): Promise<T[]>;
|
|
37
|
+
queryPaginated(config: Config): Promise<QueryResult<T>>;
|
|
36
38
|
}
|
|
@@ -28,6 +28,12 @@ class BaseRepository {
|
|
|
28
28
|
return ManualQueryHelper_1.ManualQueryHelper.executeQueryManual(className, config);
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
|
+
queryPaginated(config) {
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
const className = this.constructor.prototype.constructor.name;
|
|
34
|
+
return ManualQueryHelper_1.ManualQueryHelper.executeQueryManualPaginated(className, config);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
31
37
|
}
|
|
32
38
|
__decorate([
|
|
33
39
|
(0, Query_1.Query)(),
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { Paging } from "../model/Paging";
|
|
2
2
|
import { Config } from '../model/MQuery';
|
|
3
|
+
import { QueryResult } from "../model";
|
|
3
4
|
export declare abstract class ReadonlyRepository<T> {
|
|
4
5
|
findAll: (paging?: Paging) => Promise<T[]>;
|
|
5
6
|
findById: (id: string) => Promise<T> | undefined;
|
|
6
7
|
query(config: Config): Promise<T[]>;
|
|
8
|
+
queryPaginated(config: Config): Promise<QueryResult<T>>;
|
|
7
9
|
}
|
|
@@ -28,6 +28,12 @@ class ReadonlyRepository {
|
|
|
28
28
|
return ManualQueryHelper_1.ManualQueryHelper.executeQueryManual(className, config);
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
|
+
queryPaginated(config) {
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
const className = this.constructor.prototype.constructor.name;
|
|
34
|
+
return ManualQueryHelper_1.ManualQueryHelper.executeQueryManualPaginated(className, config);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
31
37
|
}
|
|
32
38
|
__decorate([
|
|
33
39
|
(0, Query_1.Query)(),
|
package/dist/model/MQuery.d.ts
CHANGED
package/dist/model/MQuery.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OrderBy = exports.Config = exports.MQuerySimple = exports.MQuery = void 0;
|
|
3
|
+
exports.Options = exports.OrderBy = exports.Config = exports.MQuerySimple = exports.MQuery = void 0;
|
|
4
4
|
class MQuery {
|
|
5
5
|
constructor() {
|
|
6
6
|
this.operator = '==';
|
|
@@ -22,3 +22,6 @@ class OrderBy {
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
exports.OrderBy = OrderBy;
|
|
25
|
+
class Options {
|
|
26
|
+
}
|
|
27
|
+
exports.Options = Options;
|
package/dist/model/index.d.ts
CHANGED
package/dist/model/index.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { Config } from '../model/MQuery';
|
|
1
|
+
import { Config, Options } from '../model/MQuery';
|
|
2
|
+
import { QueryResult } from "../model";
|
|
2
3
|
export declare class ManualQueryHelper {
|
|
3
4
|
static executeQueryManual(className: string, config: Config): Promise<Array<any>>;
|
|
5
|
+
static executeQueryManualPaginated(className: string, config: Config): Promise<QueryResult>;
|
|
6
|
+
static handleExecuteQueryManual(className: string, config: Config, options: Options): Promise<QueryResult>;
|
|
4
7
|
private static convertToMQuery;
|
|
5
8
|
private static getData;
|
|
6
9
|
}
|
|
@@ -16,9 +16,20 @@ const MQuery_1 = require("../model/MQuery");
|
|
|
16
16
|
const QueryCreatorConfig_1 = require("./QueryCreatorConfig");
|
|
17
17
|
class ManualQueryHelper {
|
|
18
18
|
static executeQueryManual(className, config) {
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
const { data } = yield this.handleExecuteQueryManual(className, config, { showCount: false });
|
|
21
|
+
return data;
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
static executeQueryManualPaginated(className, config) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
return this.handleExecuteQueryManual(className, config, { showCount: true });
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
static handleExecuteQueryManual(className, config, options) {
|
|
19
30
|
return __awaiter(this, void 0, void 0, function* () {
|
|
20
31
|
const cacheResolver = global.instances.cacheResolver;
|
|
21
|
-
const result = yield cacheResolver.getCacheResult(className, 'any', JSON.stringify(config));
|
|
32
|
+
const result = yield cacheResolver.getCacheResult(className, 'any', JSON.stringify(Object.assign(Object.assign({}, config), { showCount: (options === null || options === void 0 ? void 0 : options.showCount) || false })));
|
|
22
33
|
if (result) {
|
|
23
34
|
return result;
|
|
24
35
|
}
|
|
@@ -59,8 +70,11 @@ class ManualQueryHelper {
|
|
|
59
70
|
}
|
|
60
71
|
}
|
|
61
72
|
if (queryExecute) {
|
|
73
|
+
let count = null;
|
|
62
74
|
if (config === null || config === void 0 ? void 0 : config.paging) {
|
|
63
|
-
|
|
75
|
+
const { documentRef, totalItens } = yield new QueryCreatorConfig_1.QueryCreatorConfig().buildPaging(queryExecute, config.paging, options);
|
|
76
|
+
queryExecute = documentRef;
|
|
77
|
+
count = totalItens;
|
|
64
78
|
}
|
|
65
79
|
const snapshot = yield queryExecute.get();
|
|
66
80
|
const data = this.getData(snapshot);
|
|
@@ -73,10 +87,16 @@ class ManualQueryHelper {
|
|
|
73
87
|
params: JSON.stringify(config),
|
|
74
88
|
queryResult: data
|
|
75
89
|
});
|
|
76
|
-
return
|
|
90
|
+
return {
|
|
91
|
+
data,
|
|
92
|
+
totalItens: count
|
|
93
|
+
};
|
|
77
94
|
}
|
|
78
95
|
}
|
|
79
|
-
return
|
|
96
|
+
return {
|
|
97
|
+
data: [],
|
|
98
|
+
totalItens: 0
|
|
99
|
+
};
|
|
80
100
|
});
|
|
81
101
|
}
|
|
82
102
|
static convertToMQuery(query) {
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { CollectionReference, DocumentData, Query } from "@google-cloud/firestore";
|
|
2
2
|
import { Paging } from "../model/Paging";
|
|
3
|
+
import { Options } from "../model";
|
|
3
4
|
export declare class QueryCreatorConfig {
|
|
4
|
-
buildPaging(collectionRef: CollectionReference<DocumentData>, paging?: Paging):
|
|
5
|
+
buildPaging(collectionRef: CollectionReference<DocumentData>, paging?: Paging, options?: Options): Promise<{
|
|
6
|
+
documentRef: Query<DocumentData>;
|
|
7
|
+
totalItens: number | null;
|
|
8
|
+
}>;
|
|
5
9
|
}
|
|
@@ -1,21 +1,40 @@
|
|
|
1
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
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.QueryCreatorConfig = void 0;
|
|
4
13
|
class QueryCreatorConfig {
|
|
5
|
-
buildPaging(collectionRef, paging) {
|
|
14
|
+
buildPaging(collectionRef, paging, options) {
|
|
6
15
|
var _a;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
const orderByDirection = (paging === null || paging === void 0 ? void 0 : paging.orderByDirection) || 'asc';
|
|
18
|
+
const limit = (_a = paging === null || paging === void 0 ? void 0 : paging.limit) !== null && _a !== void 0 ? _a : 1000;
|
|
19
|
+
let totalItens = null;
|
|
20
|
+
if (options === null || options === void 0 ? void 0 : options.showCount) {
|
|
21
|
+
const itensQuery = yield collectionRef.count().get();
|
|
22
|
+
totalItens = itensQuery.data().count;
|
|
23
|
+
}
|
|
24
|
+
let documentRef = collectionRef.limit(limit);
|
|
25
|
+
if (paging === null || paging === void 0 ? void 0 : paging.orderBy) {
|
|
26
|
+
const ordersBy = Array.isArray(paging.orderBy) ? paging.orderBy : [paging.orderBy];
|
|
27
|
+
ordersBy.forEach(order => documentRef = documentRef.orderBy(order, orderByDirection));
|
|
28
|
+
}
|
|
29
|
+
if (paging === null || paging === void 0 ? void 0 : paging.cursor) {
|
|
30
|
+
const startAfter = Array.isArray(paging.cursor) ? paging.cursor : [paging.cursor];
|
|
31
|
+
documentRef = documentRef.startAfter(...startAfter);
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
documentRef,
|
|
35
|
+
totalItens
|
|
36
|
+
};
|
|
37
|
+
});
|
|
19
38
|
}
|
|
20
39
|
}
|
|
21
40
|
exports.QueryCreatorConfig = QueryCreatorConfig;
|
|
@@ -214,7 +214,7 @@ class CreateFunction {
|
|
|
214
214
|
console.log('It was decreed that it is being executed try, no operation or effective transaction will be performed');
|
|
215
215
|
return [];
|
|
216
216
|
}
|
|
217
|
-
let documentRef = queryCreatorConfig.buildPaging(collection, paging);
|
|
217
|
+
let { documentRef } = yield queryCreatorConfig.buildPaging(collection, paging);
|
|
218
218
|
const snapshot = yield documentRef.get();
|
|
219
219
|
let items = new Array;
|
|
220
220
|
snapshot.forEach(doc => {
|