@roit/roit-data-firestore 1.2.30 → 1.2.31

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.
@@ -31,80 +31,97 @@ class ManualQueryHelper {
31
31
  });
32
32
  }
33
33
  static handleExecuteQueryManual(className, config, options, queryRef = false) {
34
- var _a;
35
34
  return __awaiter(this, void 0, void 0, function* () {
36
- const cacheResolver = global.instances.cacheResolver;
37
- const result = yield cacheResolver.getCacheResult(className, 'any', JSON.stringify(Object.assign(Object.assign({}, config), { options })));
38
- if (result) {
39
- return result;
40
- }
41
- const repositoryOptions = QueryPredicateFunctionTransform_1.QueryPredicateFunctionTransform.classConfig.get(className);
42
- if (repositoryOptions) {
43
- const firestoreInstance = FirestoreInstance_1.FirestoreInstance.getInstance();
44
- const collection = firestoreInstance.collection(repositoryOptions.collection);
45
- let queryList;
46
- let queryExecute = collection;
47
- if ((config === null || config === void 0 ? void 0 : config.query) && ((_a = config === null || config === void 0 ? void 0 : config.query) === null || _a === void 0 ? void 0 : _a.length) > 0) {
48
- queryList = config.query.map(query => {
49
- if (Object.keys(query).length === 1) {
50
- return this.convertToMQuery(query);
51
- }
52
- return query;
53
- });
54
- const queryInit = queryList[0];
55
- queryExecute = collection.where(queryInit.field, queryInit.operator, queryInit.value);
56
- queryList.shift();
57
- queryList.forEach(que => {
58
- queryExecute = queryExecute.where(que.field, que.operator, que.value);
59
- });
60
- }
61
- if (config && (config === null || config === void 0 ? void 0 : config.select)) {
62
- if (queryExecute) {
63
- queryExecute = queryExecute.select(...config.select);
64
- }
65
- else {
66
- queryExecute = collection.select(...config.select);
67
- }
68
- }
69
- if (config && (config === null || config === void 0 ? void 0 : config.orderBy)) {
70
- if (queryExecute) {
71
- queryExecute = queryExecute.orderBy(config.orderBy.field, config.orderBy.direction);
72
- }
73
- else {
74
- queryExecute = collection.orderBy(config.orderBy.field, config.orderBy.direction);
35
+ return yield global.instances.startTracer('firestore.query', (span) => __awaiter(this, void 0, void 0, function* () {
36
+ var _a;
37
+ try {
38
+ const cacheResolver = global.instances.cacheResolver;
39
+ const result = yield cacheResolver.getCacheResult(className, 'any', JSON.stringify(Object.assign(Object.assign({}, config), { options })));
40
+ if (result) {
41
+ return result;
75
42
  }
76
- }
77
- if (queryExecute) {
78
- let count = null;
79
- if (config === null || config === void 0 ? void 0 : config.paging) {
80
- const { documentRef, totalItens } = yield new QueryCreatorConfig_1.QueryCreatorConfig().buildPaging(queryExecute, config.paging, options);
81
- queryExecute = documentRef;
82
- count = totalItens;
83
- }
84
- if (queryRef) {
85
- return queryExecute;
43
+ const repositoryOptions = QueryPredicateFunctionTransform_1.QueryPredicateFunctionTransform.classConfig.get(className);
44
+ if (repositoryOptions) {
45
+ const firestoreInstance = FirestoreInstance_1.FirestoreInstance.getInstance();
46
+ const collection = firestoreInstance.collection(repositoryOptions.collection);
47
+ let queryList;
48
+ let queryExecute = collection;
49
+ if ((config === null || config === void 0 ? void 0 : config.query) && ((_a = config === null || config === void 0 ? void 0 : config.query) === null || _a === void 0 ? void 0 : _a.length) > 0) {
50
+ queryList = config.query.map(query => {
51
+ if (Object.keys(query).length === 1) {
52
+ return this.convertToMQuery(query);
53
+ }
54
+ return query;
55
+ });
56
+ const queryInit = queryList[0];
57
+ queryExecute = collection.where(queryInit.field, queryInit.operator, queryInit.value);
58
+ queryList.shift();
59
+ queryList.forEach(que => {
60
+ queryExecute = queryExecute.where(que.field, que.operator, que.value);
61
+ });
62
+ }
63
+ if (config && (config === null || config === void 0 ? void 0 : config.select)) {
64
+ if (queryExecute) {
65
+ queryExecute = queryExecute.select(...config.select);
66
+ }
67
+ else {
68
+ queryExecute = collection.select(...config.select);
69
+ }
70
+ }
71
+ if (config && (config === null || config === void 0 ? void 0 : config.orderBy)) {
72
+ if (queryExecute) {
73
+ queryExecute = queryExecute.orderBy(config.orderBy.field, config.orderBy.direction);
74
+ }
75
+ else {
76
+ queryExecute = collection.orderBy(config.orderBy.field, config.orderBy.direction);
77
+ }
78
+ }
79
+ if (queryExecute) {
80
+ let count = null;
81
+ if (config === null || config === void 0 ? void 0 : config.paging) {
82
+ const { documentRef, totalItens } = yield new QueryCreatorConfig_1.QueryCreatorConfig().buildPaging(queryExecute, config.paging, options);
83
+ queryExecute = documentRef;
84
+ count = totalItens;
85
+ }
86
+ if (queryRef) {
87
+ return queryExecute;
88
+ }
89
+ const snapshot = yield queryExecute.get();
90
+ const data = this.getData(snapshot);
91
+ yield cacheResolver.cacheResult(className, 'any', { data, count }, JSON.stringify(Object.assign(Object.assign({}, config), { options })));
92
+ const firestoreReadAuditResolver = global.instances.firestoreReadAuditResolver;
93
+ yield firestoreReadAuditResolver.persistFirestoreRead({
94
+ collection: repositoryOptions.collection,
95
+ repositoryClassName: className,
96
+ functionSignature: 'manual-query',
97
+ params: JSON.stringify(config),
98
+ queryResult: data
99
+ });
100
+ span.setAttributes({
101
+ 'firestore.operation.name': 'query',
102
+ 'firestore.collection.name': repositoryOptions.collection,
103
+ 'firestore.operation.size': data.length,
104
+ });
105
+ return {
106
+ data,
107
+ totalItens: count
108
+ };
109
+ }
86
110
  }
87
- const snapshot = yield queryExecute.get();
88
- const data = this.getData(snapshot);
89
- yield cacheResolver.cacheResult(className, 'any', { data, count }, JSON.stringify(Object.assign(Object.assign({}, config), { options })));
90
- const firestoreReadAuditResolver = global.instances.firestoreReadAuditResolver;
91
- yield firestoreReadAuditResolver.persistFirestoreRead({
92
- collection: repositoryOptions.collection,
93
- repositoryClassName: className,
94
- functionSignature: 'manual-query',
95
- params: JSON.stringify(config),
96
- queryResult: data
97
- });
98
111
  return {
99
- data,
100
- totalItens: count
112
+ data: [],
113
+ totalItens: 0
101
114
  };
102
115
  }
103
- }
104
- return {
105
- data: [],
106
- totalItens: 0
107
- };
116
+ catch (error) {
117
+ span.setStatus({
118
+ code: 2,
119
+ message: error.message
120
+ });
121
+ span.recordException(error);
122
+ throw error;
123
+ }
124
+ }));
108
125
  });
109
126
  }
110
127
  static convertToMQuery(query) {
@@ -28,7 +28,6 @@ const CacheResolver_1 = require("../cache/CacheResolver");
28
28
  const ValidatorDataHandle_1 = require("../exception/handle/ValidatorDataHandle");
29
29
  const FirestoreReadAuditResolver_1 = require("../firestore-read-audit/FirestoreReadAuditResolver");
30
30
  const EnvironmentUtil_1 = require("../util/EnvironmentUtil");
31
- // import { CreateFunction } from "./operator/CreateFunction";
32
31
  const QueryCreatorConfig_1 = require("./QueryCreatorConfig");
33
32
  const firestore_1 = require("@google-cloud/firestore");
34
33
  const TtlBuilderUtil_1 = require("../util/TtlBuilderUtil");
@@ -39,6 +38,7 @@ const class_validator_1 = __importDefault(require("class-validator"));
39
38
  const uuid = __importStar(require("uuid"));
40
39
  const fs_1 = __importDefault(require("fs"));
41
40
  const path_1 = __importDefault(require("path"));
41
+ const Tracer_1 = require("../tracer/Tracer");
42
42
  const functionQueryTemplate = fs_1.default.readFileSync(path_1.default.resolve(__dirname, '../template/FunctionQueryTemplate.txt'), 'utf8');
43
43
  const methodList = {
44
44
  'aggregation': fs_1.default.readFileSync(path_1.default.resolve(__dirname, '../template/FunctionAggregationTemplate.txt'), 'utf8'),
@@ -72,7 +72,8 @@ class QueryPredicateFunctionTransform {
72
72
  convertToMQuery: ManualQueryHelper_1.ManualQueryHelper.convertToMQuery,
73
73
  aggregateAverage: firestore_1.AggregateField.average,
74
74
  aggregateSum: firestore_1.AggregateField.sum,
75
- aggregateCount: firestore_1.AggregateField.count
75
+ aggregateCount: firestore_1.AggregateField.count,
76
+ startTracer: Tracer_1.startTracer
76
77
  };
77
78
  if (!(options === null || options === void 0 ? void 0 : options.collection)) {
78
79
  throw new Error(`Collection is required`);
@@ -80,11 +81,8 @@ class QueryPredicateFunctionTransform {
80
81
  this.classConfig.set(repositoryClassName, options);
81
82
  const modelName = options.validateModel.name;
82
83
  this.prototypeRegister.set(modelName, options.validateModel.prototype);
83
- // const target = getMetadataStorage()['validationMetadatas'].find((valu: any) => String(valu.target).includes(modelName))
84
- // console.log(getMetadataStorage()['validationMetadatas'].map((valu: any) => String(valu.target)))
85
84
  const instance = Object.create(options.validateModel);
86
85
  this.schemaRegister.set(modelName, (0, class_validator_jsonschema_1.targetConstructorToSchema)(instance));
87
- // const func = new CreateFunction().createFunction(methodSignature)
88
86
  if (methodSignature in methodList) {
89
87
  const func = methodList[methodSignature];
90
88
  let functionString = func.toString()
@@ -1,53 +1,68 @@
1
1
  aggregation(config) {
2
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);
3
+ return yield global.instances.startTracer('firestore.aggregation', async (span) => {
4
+ try {
5
+ const db = global.instances.globalDbFile.FirestoreInstance.getInstance();
6
+ const environmentUtil = global.instances.environmentUtil;
7
+ const convertToMQuery = global.instances.convertToMQuery;
8
+ const aggregateAverage = global.instances.aggregateAverage;
9
+ const aggregateSum = global.instances.aggregateSum;
10
+ const aggregateCount = global.instances.aggregateCount;
11
+ if (environmentUtil.areWeTesting()) {
12
+ console.log('It was decreed that it is being executed try, no operation or effective transaction will be performed');
13
+ return {};
20
14
  }
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();
15
+ const collection = db.collection('<COLLECTION_REPLACE>');
16
+ let queryList;
17
+ let queryExecute;
18
+ if ((config === null || config === void 0 ? void 0 : config.query) && config.query.length > 0) {
19
+ queryList = config.query.map(query => {
20
+ if (Object.keys(query).length === 1) {
21
+ return convertToMQuery(query);
22
+ }
23
+ return query;
24
+ });
25
+ const queryInit = queryList[0];
26
+ queryExecute = collection.where(queryInit.field, queryInit.operator, queryInit.value);
27
+ queryList.shift();
28
+ queryList.forEach(que => {
29
+ queryExecute = queryExecute.where(que.field, que.operator, que.value);
30
+ });
31
+ }
32
+ else {
33
+ queryExecute = collection;
34
+ }
35
+ let aggregateObject = {};
36
+ config.aggregations.forEach(item => {
37
+ if (item.type == 'average') {
38
+ aggregateObject[item.field] = aggregateAverage(item.field);
39
+ }
40
+ if (item.type == 'sum') {
41
+ aggregateObject[item.field] = aggregateSum(item.field);
42
+ }
43
+ if (item.type == 'count') {
44
+ aggregateObject[item.field] = aggregateCount();
45
+ }
46
+ });
47
+ const averageAggregateQuery = queryExecute.aggregate(aggregateObject);
48
+ const snapshot = yield averageAggregateQuery.get();
49
+ let resultBuilder = {};
50
+ config.aggregations.forEach(item => {
51
+ resultBuilder[item.field] = snapshot.data()[item.field];
52
+ });
53
+ span.setAttributes({
54
+ 'firestore.operation.name': 'aggregation',
55
+ 'firestore.collection.name': '<COLLECTION_REPLACE>'
56
+ })
57
+ return resultBuilder;
58
+ } catch (error) {
59
+ span.setStatus({
60
+ code: 2,
61
+ message: error.message
62
+ })
63
+ span.recordException(error)
64
+ throw error
43
65
  }
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;
66
+ })
52
67
  });
53
68
  }
@@ -1,37 +1,52 @@
1
1
  average(config) {
2
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);
3
+ return yield global.instances.startTracer('firestore.findById', async (span) => {
4
+ try {
5
+ const db = global.instances.globalDbFile.FirestoreInstance.getInstance();
6
+ const environmentUtil = global.instances.environmentUtil;
7
+ const convertToMQuery = global.instances.convertToMQuery;
8
+ const aggregateAverage = global.instances.aggregateAverage;
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 0;
18
12
  }
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;
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
+ const averageAggregateQuery = queryExecute.aggregate({
34
+ average: aggregateAverage(config.attributeAvg),
35
+ });
36
+ const snapshot = yield averageAggregateQuery.get();
37
+ span.setAttributes({
38
+ 'firestore.operation.name': 'average',
39
+ 'firestore.collection.name': '<COLLECTION_REPLACE>'
40
+ })
41
+ return snapshot.data().average;
42
+ } catch (error) {
43
+ span.setStatus({
44
+ code: 2,
45
+ message: error.message
46
+ })
47
+ span.recordException(error)
48
+ throw error
49
+ }
50
+ })
36
51
  });
37
52
  }
@@ -1,33 +1,57 @@
1
1
  count(config) {
2
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);
3
+ return yield global.instances.startTracer('firestore.count', async (span) => {
4
+ try {
5
+ const db = global.instances.globalDbFile.FirestoreInstance.getInstance();
6
+ const environmentUtil = global.instances.environmentUtil;
7
+ const convertToMQuery = global.instances.convertToMQuery;
8
+ if (environmentUtil.areWeTesting()) {
9
+ console.log('It was decreed that it is being executed try, no operation or effective transaction will be performed');
10
+ return 0;
17
11
  }
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;
12
+ const collection = db.collection('<COLLECTION_REPLACE>');
13
+ let queryList;
14
+ let queryExecute;
15
+ const traceQuery = []
16
+ const pushTraceQuery = (query) => {
17
+ traceQuery.push({ field: query.field, operator: query.operator, value: '?' })
18
+ }
19
+ if ((config === null || config === void 0 ? void 0 : config.query) && config.query.length > 0) {
20
+ queryList = config.query.map(query => {
21
+ if (Object.keys(query).length === 1) {
22
+ return convertToMQuery(query);
23
+ }
24
+ return query;
25
+ });
26
+ const queryInit = queryList[0];
27
+ queryExecute = collection.where(queryInit.field, queryInit.operator, queryInit.value);
28
+ pushTraceQuery(queryInit)
29
+ queryList.shift();
30
+ queryList.forEach(que => {
31
+ queryExecute = queryExecute.where(que.field, que.operator, que.value);
32
+ pushTraceQuery(que)
33
+ });
34
+ }
35
+ else {
36
+ queryExecute = collection;
37
+ }
38
+ const snapshot = yield queryExecute.count().get();
39
+ const count = snapshot.data().count;
40
+ span.setAttributes({
41
+ 'firestore.operation.name': 'count',
42
+ 'firestore.operation.query': JSON.stringify(traceQuery),
43
+ 'firestore.collection.name': '<COLLECTION_REPLACE>',
44
+ 'firestore.operation.result.size': count,
45
+ })
46
+ return count;
47
+ } catch (error) {
48
+ span.setStatus({
49
+ code: 2,
50
+ message: error.message
51
+ })
52
+ span.recordException(error)
53
+ throw error
54
+ }
55
+ })
32
56
  });
33
57
  }
@@ -1,51 +1,68 @@
1
1
  createOrUpdate(items) {
2
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();
3
+ return yield global.instances.startTracer('firestore.createOrUpdate', async (span) => {
4
+ try {
5
+ let modelName = '';
6
+ let validatorOptions;
7
+ let ttlExpirationIn;
8
+ let ttlUnit;
9
+ if (!Array.isArray(items)) {
10
+ items = [items];
11
+ }
12
+ if (items.length > 500) {
13
+ throw new RepositoryBusinessException_1.RepositoryBusinessException(`To perform the create, the maximum number of elements is 500, size current: ${items.length}`, []);
14
+ }
15
+ const db = global.instances.globalDbFile.FirestoreInstance.getInstance();
16
+ const { newDate } = global.instances.dateRef;
17
+ const uuid = global.instances.uuid;
18
+ const environmentUtil = global.instances.environmentUtil;
19
+ const getTtlTimestamp = global.instances.getTtlTimestamp;
20
+ const collection = db.collection('<COLLECTION_REPLACE>');
21
+ const validatorDataHandle = global.instances.validatorDataHandle;
22
+ const batch = db.batch();
23
+ for (const item of items) {
24
+ yield validatorDataHandle.validateModel(modelName, item, validatorOptions);
25
+ if (!item.id) {
26
+ item.id = uuid();
27
+ }
28
+ if (!item.createAt) {
29
+ item.createAt = newDate();
30
+ item.createTimestampAt = new Date(item.createAt).getTime();
31
+ }
32
+ item.updateAt = newDate();
33
+ item.updateTimestampAt = new Date(item.updateAt).getTime();
34
+ item.lastServiceModify = process.env.SERVICE || 'PROJECT_UNDEFINED';
35
+ const docRef = collection.doc(item.id);
36
+ batch.set(docRef, JSON.parse(JSON.stringify(item)), { merge: true });
37
+ if (ttlExpirationIn && ttlUnit) {
38
+ const ttl = getTtlTimestamp(ttlExpirationIn, ttlUnit);
39
+ batch.set(docRef, {
40
+ ttlExpirationAt: ttl,
41
+ }, { merge: true });
42
+ }
43
+ }
44
+ if (!environmentUtil.areWeTesting()) {
45
+ yield batch.commit();
46
+ yield this.revokeCache();
47
+ }
48
+ else {
49
+ console.log('It was decreed that it is being executed try, no operation or effective transaction will be performed');
50
+ }
51
+ span.setAttributes({
52
+ 'firestore.operation.name': 'createOrUpdate',
53
+ 'firestore.operation.size': items.length,
54
+ 'firestore.collection.name': '<COLLECTION_REPLACE>',
55
+ })
56
+ return items;
57
+
58
+ } catch (error) {
59
+ span.setStatus({
60
+ code: 2,
61
+ message: error.message
62
+ })
63
+ span.recordException(error)
64
+ throw error
25
65
  }
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 = process.env.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;
66
+ })
50
67
  });
51
68
  }