@roit/roit-data-firestore 1.2.23 → 1.2.24
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/dist/query/QueryPredicateFunctionTransform.js +53 -15
- package/dist/template/FunctionAggregationTemplate.txt +53 -0
- package/dist/template/FunctionAverageTemplate.txt +37 -0
- package/dist/template/FunctionCountTemplate.txt +33 -0
- package/dist/template/FunctionCreateOrUpdateTemplate.txt +51 -0
- package/dist/template/FunctionCreateTemplate.txt +51 -0
- package/dist/template/FunctionDeleteTemplate.txt +29 -0
- package/dist/template/FunctionFindAllTemplate.txt +35 -0
- package/dist/template/FunctionFindByIdTemplate.txt +30 -0
- package/dist/template/FunctionIncrementFieldTemplate.txt +22 -0
- package/dist/template/FunctionRevokeCacheTemplate.txt +3 -0
- package/dist/template/FunctionSumTemplate.txt +37 -0
- package/dist/template/FunctionUpdatePartialTemplate.txt +25 -0
- package/dist/template/FunctionUpdateTemplate.txt +47 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +3 -2
- package/tsconfig.json +1 -0
- package/.github/workflows/deploy.yml +0 -79
- package/src/cache/CacheResolver.ts +0 -90
- package/src/cache/providers/CacheProvider.ts +0 -7
- package/src/cache/providers/InMemoryCacheProvider.ts +0 -45
- package/src/cache/providers/RedisCacheProvider.ts +0 -146
- package/src/cache/providers/index.ts +0 -2
- package/src/config/BaseRepository.ts +0 -77
- package/src/config/ClassCollectionMap.ts +0 -19
- package/src/config/ClassMethodQueryMap.ts +0 -43
- package/src/config/FirestoreInstance.ts +0 -39
- package/src/config/ReadonlyRepository.ts +0 -23
- package/src/decorators/Cacheable.ts +0 -11
- package/src/decorators/Query.ts +0 -14
- package/src/decorators/Repository.ts +0 -36
- package/src/emulator/FirestoreEmuator.ts +0 -6
- package/src/emulator/firebase.json +0 -10
- package/src/emulator/firestore-debug.log +0 -0
- package/src/emulator/ui-debug.log +0 -1
- package/src/exception/RepositoryBusinessException.ts +0 -8
- package/src/exception/RepositoryException.ts +0 -17
- package/src/exception/RepositorySystemException.ts +0 -8
- package/src/exception/RepositoryValidationException.ts +0 -9
- package/src/exception/handle/ValidatorDataHandle.ts +0 -50
- package/src/firestore-read-audit/FirestoreReadAuditResolver.ts +0 -58
- package/src/firestore-read-audit/providers/BigQueryFirestoreReadAuditProvider.ts +0 -116
- package/src/firestore-read-audit/providers/FirestoreReadAuditProvider.ts +0 -5
- package/src/firestore-read-audit/providers/PubSubFirestoreReadAuditProvider.ts +0 -62
- package/src/index.ts +0 -20
- package/src/model/Aggregate.ts +0 -10
- package/src/model/CacheProviders.ts +0 -3
- package/src/model/CacheableOptions.ts +0 -20
- package/src/model/FindDataConfig.ts +0 -5
- package/src/model/MQuery.ts +0 -37
- package/src/model/Paging.ts +0 -17
- package/src/model/PersistFirestoreReadProps.ts +0 -20
- package/src/model/QueryPredicate.ts +0 -10
- package/src/model/QueryResult.ts +0 -4
- package/src/model/RepositoryOptions.ts +0 -23
- package/src/model/index.ts +0 -7
- package/src/platform/PlatformTools.ts +0 -26
- package/src/query/ManualQueryHelper.ts +0 -142
- package/src/query/QueryCreatorConfig.ts +0 -50
- package/src/query/QueryPredicateFunctionTransform.ts +0 -114
- package/src/query/TransformMethodFromQuery.ts +0 -49
- package/src/query/operator/CreateFunction.ts +0 -609
- package/src/query/operator/OperatorMap.ts +0 -61
- package/src/util/EnvironmentUtil.ts +0 -8
- package/src/util/TemplateLoading.ts +0 -11
- package/src/util/TtlBuilderUtil.ts +0 -27
- package/test/CacheResolver.spec.ts +0 -115
- package/test/TesteExample.spec.ts +0 -44
- package/test/TransformMethodFromQuery.spec.ts +0 -203
- package/test/example/Repository1.ts +0 -54
- package/test/example/model/User.ts +0 -14
- /package/{template → dist/template}/FunctionQueryTemplate.txt +0 -0
|
@@ -1,4 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
2
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
25
|
exports.QueryPredicateFunctionTransform = void 0;
|
|
4
26
|
const class_validator_jsonschema_1 = require("class-validator-jsonschema");
|
|
@@ -6,28 +28,43 @@ const CacheResolver_1 = require("../cache/CacheResolver");
|
|
|
6
28
|
const ValidatorDataHandle_1 = require("../exception/handle/ValidatorDataHandle");
|
|
7
29
|
const FirestoreReadAuditResolver_1 = require("../firestore-read-audit/FirestoreReadAuditResolver");
|
|
8
30
|
const EnvironmentUtil_1 = require("../util/EnvironmentUtil");
|
|
9
|
-
|
|
31
|
+
// import { CreateFunction } from "./operator/CreateFunction";
|
|
10
32
|
const QueryCreatorConfig_1 = require("./QueryCreatorConfig");
|
|
11
33
|
const firestore_1 = require("@google-cloud/firestore");
|
|
12
34
|
const TtlBuilderUtil_1 = require("../util/TtlBuilderUtil");
|
|
13
35
|
const ManualQueryHelper_1 = require("./ManualQueryHelper");
|
|
14
|
-
const firestore = require(
|
|
15
|
-
const dateRef = require(
|
|
16
|
-
const
|
|
17
|
-
const uuid = require("uuid");
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
36
|
+
const firestore = __importStar(require("../config/FirestoreInstance"));
|
|
37
|
+
const dateRef = __importStar(require("@roit/roit-date"));
|
|
38
|
+
const class_validator_1 = __importDefault(require("class-validator"));
|
|
39
|
+
const uuid = __importStar(require("uuid"));
|
|
40
|
+
const roit_environment_1 = require("roit-environment");
|
|
41
|
+
const fs_1 = __importDefault(require("fs"));
|
|
42
|
+
const path_1 = __importDefault(require("path"));
|
|
43
|
+
const functionQueryTemplate = fs_1.default.readFileSync(path_1.default.resolve(__dirname, '../template/FunctionQueryTemplate.txt'), 'utf8');
|
|
44
|
+
const methodList = {
|
|
45
|
+
'aggregation': fs_1.default.readFileSync(path_1.default.resolve(__dirname, '../template/FunctionAggregationTemplate.txt'), 'utf8'),
|
|
46
|
+
'average': fs_1.default.readFileSync(path_1.default.resolve(__dirname, '../template/FunctionAverageTemplate.txt'), 'utf8'),
|
|
47
|
+
'count': fs_1.default.readFileSync(path_1.default.resolve(__dirname, '../template/FunctionCountTemplate.txt'), 'utf8'),
|
|
48
|
+
'createOrUpdate': fs_1.default.readFileSync(path_1.default.resolve(__dirname, '../template/FunctionCreateOrUpdateTemplate.txt'), 'utf8'),
|
|
49
|
+
'create': fs_1.default.readFileSync(path_1.default.resolve(__dirname, '../template/FunctionCreateTemplate.txt'), 'utf8'),
|
|
50
|
+
'delete': fs_1.default.readFileSync(path_1.default.resolve(__dirname, '../template/FunctionDeleteTemplate.txt'), 'utf8'),
|
|
51
|
+
'findAll': fs_1.default.readFileSync(path_1.default.resolve(__dirname, '../template/FunctionFindAllTemplate.txt'), 'utf8'),
|
|
52
|
+
'findById': fs_1.default.readFileSync(path_1.default.resolve(__dirname, '../template/FunctionFindByIdTemplate.txt'), 'utf8'),
|
|
53
|
+
'incrementField': fs_1.default.readFileSync(path_1.default.resolve(__dirname, '../template/FunctionIncrementFieldTemplate.txt'), 'utf8'),
|
|
54
|
+
'revokeCache': fs_1.default.readFileSync(path_1.default.resolve(__dirname, '../template/FunctionRevokeCacheTemplate.txt'), 'utf8'),
|
|
55
|
+
'sum': fs_1.default.readFileSync(path_1.default.resolve(__dirname, '../template/FunctionSumTemplate.txt'), 'utf8'),
|
|
56
|
+
'updatePartial': fs_1.default.readFileSync(path_1.default.resolve(__dirname, '../template/FunctionUpdatePartialTemplate.txt'), 'utf8'),
|
|
57
|
+
'update': fs_1.default.readFileSync(path_1.default.resolve(__dirname, '../template/FunctionUpdateTemplate.txt'), 'utf8')
|
|
58
|
+
};
|
|
22
59
|
class QueryPredicateFunctionTransform {
|
|
23
60
|
static createFunction(queryPredicate, methodSignature, repositoryClassName, options, methodQueryOptions) {
|
|
24
61
|
global.instances = {
|
|
25
62
|
globalDbFile: firestore,
|
|
26
63
|
dateRef,
|
|
27
|
-
classValidator,
|
|
64
|
+
classValidator: class_validator_1.default,
|
|
28
65
|
validatorDataHandle: new ValidatorDataHandle_1.ValidatorDataHandle,
|
|
29
66
|
uuid: uuid.v4,
|
|
30
|
-
Environment,
|
|
67
|
+
Environment: roit_environment_1.Environment,
|
|
31
68
|
queryCreatorConfig: new QueryCreatorConfig_1.QueryCreatorConfig,
|
|
32
69
|
cacheResolver: CacheResolver_1.CacheResolver.getInstance(),
|
|
33
70
|
environmentUtil: new EnvironmentUtil_1.EnvironmentUtil,
|
|
@@ -49,8 +86,9 @@ class QueryPredicateFunctionTransform {
|
|
|
49
86
|
// console.log(getMetadataStorage()['validationMetadatas'].map((valu: any) => String(valu.target)))
|
|
50
87
|
const instance = Object.create(options.validateModel);
|
|
51
88
|
this.schemaRegister.set(modelName, (0, class_validator_jsonschema_1.targetConstructorToSchema)(instance));
|
|
52
|
-
const func = new
|
|
53
|
-
if (
|
|
89
|
+
// const func = new CreateFunction().createFunction(methodSignature)
|
|
90
|
+
if (methodSignature in methodList) {
|
|
91
|
+
const func = methodList[methodSignature];
|
|
54
92
|
let functionString = func.toString()
|
|
55
93
|
.replace(methodSignature, 'async function')
|
|
56
94
|
.replace('return __awaiter(this, void 0, void 0, function* () {', '')
|
|
@@ -70,7 +108,7 @@ class QueryPredicateFunctionTransform {
|
|
|
70
108
|
}
|
|
71
109
|
let parameters = queryPredicate.filter(query => { var _a; return (_a = query.operator) === null || _a === void 0 ? void 0 : _a.includes('.where'); });
|
|
72
110
|
parameters = parameters.concat({ attribute: 'paging' });
|
|
73
|
-
let functionBuilder =
|
|
111
|
+
let functionBuilder = functionQueryTemplate;
|
|
74
112
|
const getAttribute = (queryPredicate) => { var _a; return (_a = queryPredicate.paramContent) !== null && _a !== void 0 ? _a : queryPredicate.attribute; };
|
|
75
113
|
functionBuilder = functionBuilder.replace(/<repositoryClassName_value>/g, repositoryClassName);
|
|
76
114
|
functionBuilder = functionBuilder.replace(/<methodSignature_value>/g, methodSignature);
|
|
@@ -78,7 +116,7 @@ class QueryPredicateFunctionTransform {
|
|
|
78
116
|
functionBuilder = functionBuilder.replace(/<params_validator_replace>/g, parameters.filter(par => par.attribute != 'paging').map(att => `!${getAttribute(att)}`).join('||'));
|
|
79
117
|
functionBuilder = functionBuilder.replace(/<collection_name_replace>/g, options.collection);
|
|
80
118
|
functionBuilder = functionBuilder.replace(/<query_predicate_replace>/g, queryPredicate.map(att => { var _a; return `${(_a = att.operator) === null || _a === void 0 ? void 0 : _a.replace('ATRIBUTE', att.attribute).replace('VALUE', getAttribute(att))}`; }).join(''));
|
|
81
|
-
functionBuilder = functionBuilder.replace(/<is_one_row>/g, (methodQueryOptions === null || methodQueryOptions === void 0 ? void 0 : methodQueryOptions.oneRow)
|
|
119
|
+
functionBuilder = functionBuilder.replace(/<is_one_row>/g, (methodQueryOptions === null || methodQueryOptions === void 0 ? void 0 : methodQueryOptions.oneRow) ? 'true' : 'false');
|
|
82
120
|
return Function(`return ${functionBuilder}`)();
|
|
83
121
|
}
|
|
84
122
|
static removeLast(value, repl) {
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
aggregation(config) {
|
|
2
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3
|
+
const db = global.instances.globalDbFile.FirestoreInstance.getInstance();
|
|
4
|
+
const environmentUtil = global.instances.environmentUtil;
|
|
5
|
+
const convertToMQuery = global.instances.convertToMQuery;
|
|
6
|
+
const aggregateAverage = global.instances.aggregateAverage;
|
|
7
|
+
const aggregateSum = global.instances.aggregateSum;
|
|
8
|
+
const aggregateCount = global.instances.aggregateCount;
|
|
9
|
+
if (environmentUtil.areWeTesting()) {
|
|
10
|
+
console.log('It was decreed that it is being executed try, no operation or effective transaction will be performed');
|
|
11
|
+
return {};
|
|
12
|
+
}
|
|
13
|
+
const collection = db.collection('<COLLECTION_REPLACE>');
|
|
14
|
+
let queryList;
|
|
15
|
+
let queryExecute;
|
|
16
|
+
if ((config === null || config === void 0 ? void 0 : config.query) && config.query.length > 0) {
|
|
17
|
+
queryList = config.query.map(query => {
|
|
18
|
+
if (Object.keys(query).length === 1) {
|
|
19
|
+
return convertToMQuery(query);
|
|
20
|
+
}
|
|
21
|
+
return query;
|
|
22
|
+
});
|
|
23
|
+
const queryInit = queryList[0];
|
|
24
|
+
queryExecute = collection.where(queryInit.field, queryInit.operator, queryInit.value);
|
|
25
|
+
queryList.shift();
|
|
26
|
+
queryList.forEach(que => {
|
|
27
|
+
queryExecute = queryExecute.where(que.field, que.operator, que.value);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
queryExecute = collection;
|
|
32
|
+
}
|
|
33
|
+
let aggregateObject = {};
|
|
34
|
+
config.aggregations.forEach(item => {
|
|
35
|
+
if (item.type == 'average') {
|
|
36
|
+
aggregateObject[item.field] = aggregateAverage(item.field);
|
|
37
|
+
}
|
|
38
|
+
if (item.type == 'sum') {
|
|
39
|
+
aggregateObject[item.field] = aggregateSum(item.field);
|
|
40
|
+
}
|
|
41
|
+
if (item.type == 'count') {
|
|
42
|
+
aggregateObject[item.field] = aggregateCount();
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
const averageAggregateQuery = queryExecute.aggregate(aggregateObject);
|
|
46
|
+
const snapshot = yield averageAggregateQuery.get();
|
|
47
|
+
let resultBuilder = {};
|
|
48
|
+
config.aggregations.forEach(item => {
|
|
49
|
+
resultBuilder[item.field] = snapshot.data()[item.field];
|
|
50
|
+
});
|
|
51
|
+
return resultBuilder;
|
|
52
|
+
});
|
|
53
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
average(config) {
|
|
2
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3
|
+
const db = global.instances.globalDbFile.FirestoreInstance.getInstance();
|
|
4
|
+
const environmentUtil = global.instances.environmentUtil;
|
|
5
|
+
const convertToMQuery = global.instances.convertToMQuery;
|
|
6
|
+
const aggregateAverage = global.instances.aggregateAverage;
|
|
7
|
+
if (environmentUtil.areWeTesting()) {
|
|
8
|
+
console.log('It was decreed that it is being executed try, no operation or effective transaction will be performed');
|
|
9
|
+
return 0;
|
|
10
|
+
}
|
|
11
|
+
const collection = db.collection('<COLLECTION_REPLACE>');
|
|
12
|
+
let queryList;
|
|
13
|
+
let queryExecute;
|
|
14
|
+
if ((config === null || config === void 0 ? void 0 : config.query) && config.query.length > 0) {
|
|
15
|
+
queryList = config.query.map(query => {
|
|
16
|
+
if (Object.keys(query).length === 1) {
|
|
17
|
+
return convertToMQuery(query);
|
|
18
|
+
}
|
|
19
|
+
return query;
|
|
20
|
+
});
|
|
21
|
+
const queryInit = queryList[0];
|
|
22
|
+
queryExecute = collection.where(queryInit.field, queryInit.operator, queryInit.value);
|
|
23
|
+
queryList.shift();
|
|
24
|
+
queryList.forEach(que => {
|
|
25
|
+
queryExecute = queryExecute.where(que.field, que.operator, que.value);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
queryExecute = collection;
|
|
30
|
+
}
|
|
31
|
+
const averageAggregateQuery = queryExecute.aggregate({
|
|
32
|
+
average: aggregateAverage(config.attributeAvg),
|
|
33
|
+
});
|
|
34
|
+
const snapshot = yield averageAggregateQuery.get();
|
|
35
|
+
return snapshot.data().average;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
count(config) {
|
|
2
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3
|
+
const db = global.instances.globalDbFile.FirestoreInstance.getInstance();
|
|
4
|
+
const environmentUtil = global.instances.environmentUtil;
|
|
5
|
+
const convertToMQuery = global.instances.convertToMQuery;
|
|
6
|
+
if (environmentUtil.areWeTesting()) {
|
|
7
|
+
console.log('It was decreed that it is being executed try, no operation or effective transaction will be performed');
|
|
8
|
+
return 0;
|
|
9
|
+
}
|
|
10
|
+
const collection = db.collection('<COLLECTION_REPLACE>');
|
|
11
|
+
let queryList;
|
|
12
|
+
let queryExecute;
|
|
13
|
+
if ((config === null || config === void 0 ? void 0 : config.query) && config.query.length > 0) {
|
|
14
|
+
queryList = config.query.map(query => {
|
|
15
|
+
if (Object.keys(query).length === 1) {
|
|
16
|
+
return convertToMQuery(query);
|
|
17
|
+
}
|
|
18
|
+
return query;
|
|
19
|
+
});
|
|
20
|
+
const queryInit = queryList[0];
|
|
21
|
+
queryExecute = collection.where(queryInit.field, queryInit.operator, queryInit.value);
|
|
22
|
+
queryList.shift();
|
|
23
|
+
queryList.forEach(que => {
|
|
24
|
+
queryExecute = queryExecute.where(que.field, que.operator, que.value);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
queryExecute = collection;
|
|
29
|
+
}
|
|
30
|
+
const snapshot = yield queryExecute.count().get();
|
|
31
|
+
return snapshot.data().count;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
createOrUpdate(items) {
|
|
2
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3
|
+
let modelName = '';
|
|
4
|
+
let validatorOptions;
|
|
5
|
+
let ttlExpirationIn;
|
|
6
|
+
let ttlUnit;
|
|
7
|
+
if (!Array.isArray(items)) {
|
|
8
|
+
items = [items];
|
|
9
|
+
}
|
|
10
|
+
if (items.length > 500) {
|
|
11
|
+
throw new RepositoryBusinessException_1.RepositoryBusinessException(`To perform the create, the maximum number of elements is 500, size current: ${items.length}`, []);
|
|
12
|
+
}
|
|
13
|
+
const db = global.instances.globalDbFile.FirestoreInstance.getInstance();
|
|
14
|
+
const { newDate } = global.instances.dateRef;
|
|
15
|
+
const uuid = global.instances.uuid;
|
|
16
|
+
const environmentUtil = global.instances.environmentUtil;
|
|
17
|
+
const getTtlTimestamp = global.instances.getTtlTimestamp;
|
|
18
|
+
const collection = db.collection('<COLLECTION_REPLACE>');
|
|
19
|
+
const validatorDataHandle = global.instances.validatorDataHandle;
|
|
20
|
+
const batch = db.batch();
|
|
21
|
+
for (const item of items) {
|
|
22
|
+
yield validatorDataHandle.validateModel(modelName, item, validatorOptions);
|
|
23
|
+
if (!item.id) {
|
|
24
|
+
item.id = uuid();
|
|
25
|
+
}
|
|
26
|
+
if (!item.createAt) {
|
|
27
|
+
item.createAt = newDate();
|
|
28
|
+
item.createTimestampAt = new Date(item.createAt).getTime();
|
|
29
|
+
}
|
|
30
|
+
item.updateAt = newDate();
|
|
31
|
+
item.updateTimestampAt = new Date(item.updateAt).getTime();
|
|
32
|
+
item.lastServiceModify = global.instances.Environment.getProperty('service') || 'PROJECT_UNDEFINED';
|
|
33
|
+
const docRef = collection.doc(item.id);
|
|
34
|
+
batch.set(docRef, JSON.parse(JSON.stringify(item)), { merge: true });
|
|
35
|
+
if (ttlExpirationIn && ttlUnit) {
|
|
36
|
+
const ttl = getTtlTimestamp(ttlExpirationIn, ttlUnit);
|
|
37
|
+
batch.set(docRef, {
|
|
38
|
+
ttlExpirationAt: ttl,
|
|
39
|
+
}, { merge: true });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (!environmentUtil.areWeTesting()) {
|
|
43
|
+
yield batch.commit();
|
|
44
|
+
yield this.revokeCache();
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
console.log('It was decreed that it is being executed try, no operation or effective transaction will be performed');
|
|
48
|
+
}
|
|
49
|
+
return items;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
create(items) {
|
|
2
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3
|
+
let modelName = '';
|
|
4
|
+
let validatorOptions;
|
|
5
|
+
let ttlExpirationIn;
|
|
6
|
+
let ttlUnit;
|
|
7
|
+
if (!Array.isArray(items)) {
|
|
8
|
+
items = [items];
|
|
9
|
+
}
|
|
10
|
+
if (items.length > 500) {
|
|
11
|
+
throw new RepositoryBusinessException_1.RepositoryBusinessException(`To perform the create, the maximum number of elements is 500, size current: ${items.length}`, []);
|
|
12
|
+
}
|
|
13
|
+
const db = global.instances.globalDbFile.FirestoreInstance.getInstance();
|
|
14
|
+
const { newDate } = global.instances.dateRef;
|
|
15
|
+
const uuid = global.instances.uuid;
|
|
16
|
+
const environmentUtil = global.instances.environmentUtil;
|
|
17
|
+
const getTtlTimestamp = global.instances.getTtlTimestamp;
|
|
18
|
+
const collection = db.collection('<COLLECTION_REPLACE>');
|
|
19
|
+
const validatorDataHandle = global.instances.validatorDataHandle;
|
|
20
|
+
const batch = db.batch();
|
|
21
|
+
for (const item of items) {
|
|
22
|
+
yield validatorDataHandle.validateModel(modelName, item, validatorOptions);
|
|
23
|
+
if (!item.id) {
|
|
24
|
+
item.id = uuid();
|
|
25
|
+
}
|
|
26
|
+
if (!item.createAt) {
|
|
27
|
+
item.createAt = newDate();
|
|
28
|
+
item.createTimestampAt = new Date(item.createAt).getTime();
|
|
29
|
+
}
|
|
30
|
+
item.updateAt = newDate();
|
|
31
|
+
item.updateTimestampAt = new Date(item.updateAt).getTime();
|
|
32
|
+
item.lastServiceModify = global.instances.Environment.getProperty('service') || 'PROJECT_UNDEFINED';
|
|
33
|
+
const docRef = collection.doc(item.id);
|
|
34
|
+
batch.set(docRef, JSON.parse(JSON.stringify(item)));
|
|
35
|
+
if (ttlExpirationIn && ttlUnit) {
|
|
36
|
+
const ttl = getTtlTimestamp(ttlExpirationIn, ttlUnit);
|
|
37
|
+
batch.set(docRef, {
|
|
38
|
+
ttlExpirationAt: ttl,
|
|
39
|
+
}, { merge: true });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (!environmentUtil.areWeTesting()) {
|
|
43
|
+
yield batch.commit();
|
|
44
|
+
yield this.revokeCache();
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
console.log('It was decreed that it is being executed try, no operation or effective transaction will be performed');
|
|
48
|
+
}
|
|
49
|
+
return items;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
delete(ids) {
|
|
2
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3
|
+
if (!ids) {
|
|
4
|
+
throw new RepositoryBusinessException_1.RepositoryBusinessException(`Id is required`, []);
|
|
5
|
+
}
|
|
6
|
+
if (!Array.isArray(ids)) {
|
|
7
|
+
ids = [ids];
|
|
8
|
+
}
|
|
9
|
+
if (ids.length > 500) {
|
|
10
|
+
throw new RepositoryBusinessException_1.RepositoryBusinessException(`To perform the delete, the maximum number of elements is 500, size current: ${ids.length}`, []);
|
|
11
|
+
}
|
|
12
|
+
const db = global.instances.globalDbFile.FirestoreInstance.getInstance();
|
|
13
|
+
const environmentUtil = global.instances.environmentUtil;
|
|
14
|
+
const batch = db.batch();
|
|
15
|
+
const collection = db.collection('<COLLECTION_REPLACE>');
|
|
16
|
+
ids.forEach(id => {
|
|
17
|
+
const docRef = collection.doc(id);
|
|
18
|
+
batch.delete(docRef);
|
|
19
|
+
});
|
|
20
|
+
if (!environmentUtil.areWeTesting()) {
|
|
21
|
+
yield batch.commit();
|
|
22
|
+
yield this.revokeCache();
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
console.log('It was decreed that it is being executed try, no operation or effective transaction will be performed');
|
|
26
|
+
}
|
|
27
|
+
return ids;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
findAll(paging) {
|
|
2
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3
|
+
let repositoryClassName = '';
|
|
4
|
+
let methodSignature = '';
|
|
5
|
+
const db = global.instances.globalDbFile.FirestoreInstance.getInstance();
|
|
6
|
+
const cacheResolver = global.instances.cacheResolver;
|
|
7
|
+
const result = yield cacheResolver.getCacheResult(repositoryClassName, methodSignature, 'Any');
|
|
8
|
+
if (result) {
|
|
9
|
+
return result;
|
|
10
|
+
}
|
|
11
|
+
const queryCreatorConfig = global.instances.queryCreatorConfig;
|
|
12
|
+
const collection = db.collection('<COLLECTION_REPLACE>');
|
|
13
|
+
const environmentUtil = global.instances.environmentUtil;
|
|
14
|
+
if (environmentUtil.areWeTesting()) {
|
|
15
|
+
console.log('It was decreed that it is being executed try, no operation or effective transaction will be performed');
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
18
|
+
let { documentRef } = yield queryCreatorConfig.buildPaging(collection, paging, { showCount: false });
|
|
19
|
+
const snapshot = yield documentRef.get();
|
|
20
|
+
let items = new Array;
|
|
21
|
+
snapshot.forEach(doc => {
|
|
22
|
+
const data = doc.data();
|
|
23
|
+
items.push(Object.assign({}, data));
|
|
24
|
+
});
|
|
25
|
+
yield cacheResolver.cacheResult(repositoryClassName, methodSignature, items, 'Any');
|
|
26
|
+
const firestoreReadAuditResolver = global.instances.firestoreReadAuditResolver;
|
|
27
|
+
yield firestoreReadAuditResolver.persistFirestoreRead({
|
|
28
|
+
collection: '<COLLECTION_REPLACE>',
|
|
29
|
+
repositoryClassName,
|
|
30
|
+
functionSignature: methodSignature,
|
|
31
|
+
queryResult: items
|
|
32
|
+
});
|
|
33
|
+
return items;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
findById(id) {
|
|
2
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3
|
+
let repositoryClassName = '';
|
|
4
|
+
let methodSignature = '';
|
|
5
|
+
const db = global.instances.globalDbFile.FirestoreInstance.getInstance();
|
|
6
|
+
const cacheResolver = global.instances.cacheResolver;
|
|
7
|
+
const result = yield cacheResolver.getCacheResult(repositoryClassName, methodSignature, id);
|
|
8
|
+
if (result) {
|
|
9
|
+
return result;
|
|
10
|
+
}
|
|
11
|
+
const collection = db.collection('<COLLECTION_REPLACE>');
|
|
12
|
+
const environmentUtil = global.instances.environmentUtil;
|
|
13
|
+
if (environmentUtil.areWeTesting()) {
|
|
14
|
+
console.log('It was decreed that it is being executed try, no operation or effective transaction will be performed');
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
const response = yield collection.doc(id).get();
|
|
18
|
+
const item = response.data();
|
|
19
|
+
yield cacheResolver.cacheResult(repositoryClassName, methodSignature, item, id);
|
|
20
|
+
const firestoreReadAuditResolver = global.instances.firestoreReadAuditResolver;
|
|
21
|
+
yield firestoreReadAuditResolver.persistFirestoreRead({
|
|
22
|
+
collection: '<COLLECTION_REPLACE>',
|
|
23
|
+
repositoryClassName,
|
|
24
|
+
functionSignature: methodSignature,
|
|
25
|
+
params: id,
|
|
26
|
+
queryResult: item
|
|
27
|
+
});
|
|
28
|
+
return item;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
incrementField(id, field, increment) {
|
|
2
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3
|
+
const db = global.instances.globalDbFile.FirestoreInstance.getInstance();
|
|
4
|
+
const environmentUtil = global.instances.environmentUtil;
|
|
5
|
+
const fieldValueIncrement = global.instances.fieldValueIncrement;
|
|
6
|
+
const document = db.collection('<COLLECTION_REPLACE>').doc(id);
|
|
7
|
+
try {
|
|
8
|
+
if (!environmentUtil.areWeTesting()) {
|
|
9
|
+
let payload = {};
|
|
10
|
+
payload[field] = fieldValueIncrement(increment || 1);
|
|
11
|
+
yield document.set(payload, { merge: true });
|
|
12
|
+
yield this.revokeCache();
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
console.log('It was decreed that it is being executed try, no operation or effective transaction will be performed');
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
catch (e) {
|
|
19
|
+
console.error(e === null || e === void 0 ? void 0 : e.details);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
sum(config) {
|
|
2
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3
|
+
const db = global.instances.globalDbFile.FirestoreInstance.getInstance();
|
|
4
|
+
const environmentUtil = global.instances.environmentUtil;
|
|
5
|
+
const convertToMQuery = global.instances.convertToMQuery;
|
|
6
|
+
const aggregateSum = global.instances.aggregateSum;
|
|
7
|
+
if (environmentUtil.areWeTesting()) {
|
|
8
|
+
console.log('It was decreed that it is being executed try, no operation or effective transaction will be performed');
|
|
9
|
+
return 0;
|
|
10
|
+
}
|
|
11
|
+
const collection = db.collection('<COLLECTION_REPLACE>');
|
|
12
|
+
let queryList;
|
|
13
|
+
let queryExecute;
|
|
14
|
+
if ((config === null || config === void 0 ? void 0 : config.query) && config.query.length > 0) {
|
|
15
|
+
queryList = config.query.map(query => {
|
|
16
|
+
if (Object.keys(query).length === 1) {
|
|
17
|
+
return convertToMQuery(query);
|
|
18
|
+
}
|
|
19
|
+
return query;
|
|
20
|
+
});
|
|
21
|
+
const queryInit = queryList[0];
|
|
22
|
+
queryExecute = collection.where(queryInit.field, queryInit.operator, queryInit.value);
|
|
23
|
+
queryList.shift();
|
|
24
|
+
queryList.forEach(que => {
|
|
25
|
+
queryExecute = queryExecute.where(que.field, que.operator, que.value);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
queryExecute = collection;
|
|
30
|
+
}
|
|
31
|
+
const sumAggregateQuery = queryExecute.aggregate({
|
|
32
|
+
sum: aggregateSum(config.attributeSum),
|
|
33
|
+
});
|
|
34
|
+
const snapshot = yield sumAggregateQuery.get();
|
|
35
|
+
return snapshot.data().sum;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
updatePartial(id, item) {
|
|
2
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3
|
+
const db = global.instances.globalDbFile.FirestoreInstance.getInstance();
|
|
4
|
+
const { newDate } = global.instances.dateRef;
|
|
5
|
+
const lastServiceModify = global.instances.Environment.getProperty('service') || 'PROJECT_UNDEFINED';
|
|
6
|
+
const updateAt = newDate();
|
|
7
|
+
const updateTimestampAt = new Date(updateAt).getTime();
|
|
8
|
+
const environmentUtil = global.instances.environmentUtil;
|
|
9
|
+
const document = db.collection('<COLLECTION_REPLACE>').doc(id);
|
|
10
|
+
try {
|
|
11
|
+
if (!environmentUtil.areWeTesting()) {
|
|
12
|
+
yield document.set(Object.assign({ lastServiceModify,
|
|
13
|
+
updateAt,
|
|
14
|
+
updateTimestampAt }, item), { merge: true });
|
|
15
|
+
yield this.revokeCache();
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
console.log('It was decreed that it is being executed try, no operation or effective transaction will be performed');
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
catch (e) {
|
|
22
|
+
console.error(e === null || e === void 0 ? void 0 : e.details);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
update(items) {
|
|
2
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3
|
+
let modelName = '';
|
|
4
|
+
let validatorOptions;
|
|
5
|
+
let ttlExpirationIn;
|
|
6
|
+
let ttlUnit;
|
|
7
|
+
let ttlUpdate;
|
|
8
|
+
if (!Array.isArray(items)) {
|
|
9
|
+
items = [items];
|
|
10
|
+
}
|
|
11
|
+
if (items.length > 500) {
|
|
12
|
+
throw new RepositoryBusinessException_1.RepositoryBusinessException(`To perform the create, the maximum number of elements is 500, size current: ${items.length}`, []);
|
|
13
|
+
}
|
|
14
|
+
const db = global.instances.globalDbFile.FirestoreInstance.getInstance();
|
|
15
|
+
const { newDate } = global.instances.dateRef;
|
|
16
|
+
const environmentUtil = global.instances.environmentUtil;
|
|
17
|
+
const getTtlTimestamp = global.instances.getTtlTimestamp;
|
|
18
|
+
const collection = db.collection('<COLLECTION_REPLACE>');
|
|
19
|
+
const validatorDataHandle = global.instances.validatorDataHandle;
|
|
20
|
+
const batch = db.batch();
|
|
21
|
+
for (const item of items) {
|
|
22
|
+
yield validatorDataHandle.validateModel(modelName, item, validatorOptions);
|
|
23
|
+
if (!item.id) {
|
|
24
|
+
throw new RepositoryBusinessException_1.RepositoryBusinessException(`Id is required`, []);
|
|
25
|
+
}
|
|
26
|
+
item.updateAt = newDate();
|
|
27
|
+
item.updateTimestampAt = new Date(item.updateAt).getTime();
|
|
28
|
+
item.lastServiceModify = global.instances.Environment.getProperty('service') || 'PROJECT_UNDEFINED';
|
|
29
|
+
const docRef = collection.doc(item.id);
|
|
30
|
+
batch.set(docRef, JSON.parse(JSON.stringify(item)), { merge: true });
|
|
31
|
+
if (ttlExpirationIn && ttlUnit && ttlUpdate) {
|
|
32
|
+
const ttl = getTtlTimestamp(ttlExpirationIn, ttlUnit);
|
|
33
|
+
batch.set(docRef, {
|
|
34
|
+
ttlExpirationAt: ttl,
|
|
35
|
+
}, { merge: true });
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (!environmentUtil.areWeTesting()) {
|
|
39
|
+
yield batch.commit();
|
|
40
|
+
yield this.revokeCache();
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
console.log('It was decreed that it is being executed try, no operation or effective transaction will be performed');
|
|
44
|
+
}
|
|
45
|
+
return items;
|
|
46
|
+
});
|
|
47
|
+
}
|