@roit/roit-data-firestore 1.2.39 → 1.2.41
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/archive/ArchiveService.d.ts +0 -1
- package/dist/archive/ArchiveService.js +113 -136
- package/dist/cache/CacheResolver.js +80 -104
- package/dist/cache/providers/RedisCacheArchiveProvider.d.ts +0 -1
- package/dist/cache/providers/RedisCacheArchiveProvider.js +43 -69
- package/dist/cache/providers/RedisCacheProvider.js +37 -52
- package/dist/config/ArchiveConfig.d.ts +4 -0
- package/dist/config/ArchiveConfig.js +20 -1
- package/dist/config/BaseRepository.js +13 -30
- package/dist/config/ReadonlyRepository.js +7 -20
- package/dist/decorators/Repository.js +3 -12
- package/dist/exception/RepositoryException.js +1 -1
- package/dist/exception/handle/ValidatorDataHandle.js +12 -24
- package/dist/firestore-read-audit/FirestoreReadAuditResolver.js +15 -18
- package/dist/firestore-read-audit/providers/BigQueryFirestoreReadAuditProvider.js +53 -66
- package/dist/firestore-read-audit/providers/PubSubFirestoreReadAuditProvider.js +15 -26
- package/dist/model/CacheProviders.js +1 -1
- package/dist/query/ManualQueryHelper.js +132 -150
- package/dist/query/QueryCreatorConfig.js +30 -42
- package/dist/query/QueryPredicateFunctionTransform.js +10 -10
- package/dist/query/TransformMethodFromQuery.js +2 -2
- package/dist/tracer/Tracer.js +5 -14
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +10 -10
- package/tsconfig.json +2 -2
|
@@ -1,13 +1,4 @@
|
|
|
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
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.RedisCacheArchiveProvider = void 0;
|
|
13
4
|
const PlatformTools_1 = require("../../platform/PlatformTools");
|
|
@@ -19,14 +10,11 @@ const REDIS_ENABLED = ArchiveConfig_1.ArchiveConfig.getConfig().cache.enabled;
|
|
|
19
10
|
class RedisCacheArchiveProvider {
|
|
20
11
|
constructor() {
|
|
21
12
|
this.isRedisReady = false;
|
|
22
|
-
|
|
23
|
-
if (this.isDebug) {
|
|
24
|
-
console.log('[DEBUG] Redis Caching Firestore Archive > Redis is enabled', REDIS_ENABLED);
|
|
25
|
-
}
|
|
13
|
+
(0, ArchiveConfig_1.onDebugLog)(`Redis Caching Firestore Archive > Redis is enabled ${REDIS_ENABLED}`);
|
|
26
14
|
if (!this.redis && REDIS_ENABLED) {
|
|
27
15
|
const url = ArchiveConfig_1.ArchiveConfig.getConfig().cache.redisUrl;
|
|
28
16
|
if (!url) {
|
|
29
|
-
console.error(
|
|
17
|
+
console.error(`${ArchiveConfig_1.DEBUG_PREFIX} [ERROR] Redis Caching > environtment variable "firestore.archive.cache.redisUrl" was not found!`);
|
|
30
18
|
return;
|
|
31
19
|
}
|
|
32
20
|
if (process.env.JEST_WORKER_ID !== undefined) {
|
|
@@ -36,26 +24,22 @@ class RedisCacheArchiveProvider {
|
|
|
36
24
|
this.client = this.redis.createClient({ url });
|
|
37
25
|
this.client.on('error', (err) => {
|
|
38
26
|
this.isRedisReady = false;
|
|
39
|
-
|
|
40
|
-
console.warn('[WARN] Redis error', err);
|
|
41
|
-
}
|
|
27
|
+
(0, ArchiveConfig_1.onDebugWarn)(`Redis error: ${err}`);
|
|
42
28
|
});
|
|
43
29
|
this.client.on('ready', () => {
|
|
44
30
|
this.isRedisReady = true;
|
|
45
|
-
|
|
46
|
-
console.log('[DEBUG] Redis Caching Archive > Redis is ready');
|
|
47
|
-
}
|
|
31
|
+
(0, ArchiveConfig_1.onDebugLog)('Redis Caching Archive > Redis is ready');
|
|
48
32
|
});
|
|
49
33
|
this.client.connect();
|
|
50
34
|
}
|
|
51
35
|
}
|
|
52
36
|
handleTimeoutError(error) {
|
|
53
37
|
if (error.message === 'Timeout' && this.isRedisReady) {
|
|
54
|
-
|
|
38
|
+
(0, ArchiveConfig_1.onDebugLog)('Setting isRedisReady as false');
|
|
55
39
|
this.isRedisReady = false;
|
|
56
40
|
// Stop everything for a while to unburden Redis
|
|
57
41
|
setTimeout(() => {
|
|
58
|
-
|
|
42
|
+
(0, ArchiveConfig_1.onDebugLog)('Setting isRedisReady as true');
|
|
59
43
|
this.isRedisReady = true;
|
|
60
44
|
}, REDIS_RECONNECT * 1000);
|
|
61
45
|
}
|
|
@@ -68,66 +52,56 @@ class RedisCacheArchiveProvider {
|
|
|
68
52
|
}
|
|
69
53
|
catch (error) {
|
|
70
54
|
this.handleTimeoutError(error);
|
|
71
|
-
console.log(
|
|
55
|
+
console.log(`${ArchiveConfig_1.DEBUG_PREFIX} Redis Caching > Error when getting KEYS with query: ${query}, error: ${error}`);
|
|
72
56
|
}
|
|
73
57
|
return Promise.resolve([]);
|
|
74
58
|
}
|
|
75
|
-
getCacheResult(key) {
|
|
76
|
-
|
|
77
|
-
try {
|
|
78
|
-
if (this.isRedisReady) {
|
|
79
|
-
const result = yield (0, promise_timeout_1.timeout)(this.client.get(key), REDIS_TIMEOUT);
|
|
80
|
-
if (this.isDebug) {
|
|
81
|
-
if (result) {
|
|
82
|
-
console.debug('[DEBUG] Redis Caching >', `Return value in cache from key: ${key}`);
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
console.log("[DEBUG] Redis Caching > ", `Key [${key}] is not found in the cache`);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
if (result) {
|
|
89
|
-
return JSON.parse(result);
|
|
90
|
-
}
|
|
91
|
-
return null;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
catch (error) {
|
|
95
|
-
this.handleTimeoutError(error);
|
|
96
|
-
console.log(`[DEBUG] Redis Caching > Error when getting key from redis. ${key}`, { error });
|
|
97
|
-
return null;
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
saveCacheResult(key, valueToCache, ttl) {
|
|
102
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
async getCacheResult(key) {
|
|
60
|
+
try {
|
|
103
61
|
if (this.isRedisReady) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
62
|
+
const result = await (0, promise_timeout_1.timeout)(this.client.get(key), REDIS_TIMEOUT);
|
|
63
|
+
if (result) {
|
|
64
|
+
(0, ArchiveConfig_1.onDebugLog)(`Redis Caching > Return value in cache from key: ${key}`);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
(0, ArchiveConfig_1.onDebugLog)(`Redis Caching > Key [${key}] is not found in the cache`);
|
|
111
68
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
console.log(`[DEBUG] Redis Caching > Error when saving cache. Key: ${key}, value: ${valueToCache}, error: ${error}`);
|
|
69
|
+
if (result) {
|
|
70
|
+
return JSON.parse(result);
|
|
115
71
|
}
|
|
72
|
+
return null;
|
|
116
73
|
}
|
|
117
|
-
}
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
this.handleTimeoutError(error);
|
|
77
|
+
console.log(`${ArchiveConfig_1.DEBUG_PREFIX} Redis Caching > Error when getting key from redis. ${key}`, { error });
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
118
80
|
}
|
|
119
|
-
|
|
120
|
-
|
|
81
|
+
async saveCacheResult(key, valueToCache, ttl) {
|
|
82
|
+
if (this.isRedisReady) {
|
|
121
83
|
try {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
84
|
+
await (0, promise_timeout_1.timeout)(this.client.set(key, JSON.stringify(valueToCache), {
|
|
85
|
+
EX: ttl || ArchiveConfig_1.ArchiveConfig.getConfig().cache.expiresInSeconds
|
|
86
|
+
}), REDIS_TIMEOUT);
|
|
87
|
+
(0, ArchiveConfig_1.onDebugLog)(`Redis Caching > Storage cache from key: ${key}`);
|
|
125
88
|
}
|
|
126
89
|
catch (error) {
|
|
127
90
|
this.handleTimeoutError(error);
|
|
128
|
-
console.log(
|
|
91
|
+
console.log(`${ArchiveConfig_1.DEBUG_PREFIX} Redis Caching > Error when saving cache. Key: ${key}, value: ${valueToCache}, error: ${error}`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
async delete(key) {
|
|
96
|
+
try {
|
|
97
|
+
if (this.isRedisReady) {
|
|
98
|
+
await (0, promise_timeout_1.timeout)(this.client.del(key), REDIS_TIMEOUT);
|
|
129
99
|
}
|
|
130
|
-
}
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
this.handleTimeoutError(error);
|
|
103
|
+
console.log(`${ArchiveConfig_1.DEBUG_PREFIX} Redis Caching > Error when deleting key from redis. ${key}`);
|
|
104
|
+
}
|
|
131
105
|
}
|
|
132
106
|
loadRedis() {
|
|
133
107
|
try {
|
|
@@ -1,13 +1,4 @@
|
|
|
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
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.RedisCacheProvider = void 0;
|
|
13
4
|
const PlatformTools_1 = require("../../platform/PlatformTools");
|
|
@@ -67,62 +58,56 @@ class RedisCacheProvider {
|
|
|
67
58
|
}
|
|
68
59
|
return Promise.resolve([]);
|
|
69
60
|
}
|
|
70
|
-
getCacheResult(key) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
if (IsDebug_1.isDebug) {
|
|
76
|
-
if (result) {
|
|
77
|
-
console.debug('[DEBUG] Redis Caching >', `Return value in cache from key: ${key}`);
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
console.log("[DEBUG] Redis Caching > ", `Key [${key}] is not found in the cache`);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
61
|
+
async getCacheResult(key) {
|
|
62
|
+
try {
|
|
63
|
+
if (this.isRedisReady) {
|
|
64
|
+
const result = await (0, promise_timeout_1.timeout)(this.client.get(key), REDIS_TIMEOUT);
|
|
65
|
+
if (IsDebug_1.isDebug) {
|
|
83
66
|
if (result) {
|
|
84
|
-
|
|
67
|
+
console.debug('[DEBUG] Redis Caching >', `Return value in cache from key: ${key}`);
|
|
85
68
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
catch (error) {
|
|
90
|
-
this.handleTimeoutError(error);
|
|
91
|
-
console.log(`[DEBUG] Redis Caching > Error when getting key from redis. ${key}`, { error });
|
|
92
|
-
return null;
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
saveCacheResult(key, valueToCache, ttl) {
|
|
97
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
98
|
-
if (this.isRedisReady) {
|
|
99
|
-
try {
|
|
100
|
-
yield (0, promise_timeout_1.timeout)(this.client.set(key, JSON.stringify(valueToCache), {
|
|
101
|
-
EX: ttl || 0
|
|
102
|
-
}), REDIS_TIMEOUT);
|
|
103
|
-
if (IsDebug_1.isDebug) {
|
|
104
|
-
console.debug('[DEBUG] Redis Caching >', `Storage cache from key: ${key}`);
|
|
69
|
+
else {
|
|
70
|
+
console.log("[DEBUG] Redis Caching > ", `Key [${key}] is not found in the cache`);
|
|
105
71
|
}
|
|
106
72
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
console.log(`[DEBUG] Redis Caching > Error when saving cache. Key: ${key}, value: ${valueToCache}, error: ${error}`);
|
|
73
|
+
if (result) {
|
|
74
|
+
return JSON.parse(result);
|
|
110
75
|
}
|
|
76
|
+
return null;
|
|
111
77
|
}
|
|
112
|
-
}
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
this.handleTimeoutError(error);
|
|
81
|
+
console.log(`[DEBUG] Redis Caching > Error when getting key from redis. ${key}`, { error });
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
113
84
|
}
|
|
114
|
-
|
|
115
|
-
|
|
85
|
+
async saveCacheResult(key, valueToCache, ttl) {
|
|
86
|
+
if (this.isRedisReady) {
|
|
116
87
|
try {
|
|
117
|
-
|
|
118
|
-
|
|
88
|
+
await (0, promise_timeout_1.timeout)(this.client.set(key, JSON.stringify(valueToCache), {
|
|
89
|
+
EX: ttl || 0
|
|
90
|
+
}), REDIS_TIMEOUT);
|
|
91
|
+
if (IsDebug_1.isDebug) {
|
|
92
|
+
console.debug('[DEBUG] Redis Caching >', `Storage cache from key: ${key}`);
|
|
119
93
|
}
|
|
120
94
|
}
|
|
121
95
|
catch (error) {
|
|
122
96
|
this.handleTimeoutError(error);
|
|
123
|
-
console.log(`[DEBUG] Redis Caching > Error when
|
|
97
|
+
console.log(`[DEBUG] Redis Caching > Error when saving cache. Key: ${key}, value: ${valueToCache}, error: ${error}`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
async delete(key) {
|
|
102
|
+
try {
|
|
103
|
+
if (this.isRedisReady) {
|
|
104
|
+
await (0, promise_timeout_1.timeout)(this.client.del(key), REDIS_TIMEOUT);
|
|
124
105
|
}
|
|
125
|
-
}
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
this.handleTimeoutError(error);
|
|
109
|
+
console.log(`[DEBUG] Redis Caching > Error when deleting key from redis. ${key}`);
|
|
110
|
+
}
|
|
126
111
|
}
|
|
127
112
|
loadRedis() {
|
|
128
113
|
try {
|
|
@@ -14,3 +14,7 @@ export interface ArchiveConfig {
|
|
|
14
14
|
export declare class ArchiveConfig {
|
|
15
15
|
static getConfig(): ArchiveConfig;
|
|
16
16
|
}
|
|
17
|
+
export declare const DEBUG_PREFIX = "[ARCHIVE SERVICE]";
|
|
18
|
+
export declare const onDebugLog: (message: string) => void;
|
|
19
|
+
export declare const onDebugError: (message: string, error: any) => void;
|
|
20
|
+
export declare const onDebugWarn: (message: string) => void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ArchiveConfig = void 0;
|
|
3
|
+
exports.onDebugWarn = exports.onDebugError = exports.onDebugLog = exports.DEBUG_PREFIX = exports.ArchiveConfig = void 0;
|
|
4
4
|
const FIRESTORE_PROJECT_ID = process.env.FIRESTORE_PROJECTID || '';
|
|
5
5
|
const FIRESTORE_ARCHIVE_DEBUG = process.env.FIRESTORE_ARCHIVE_DEBUG || false;
|
|
6
6
|
const FIRESTORE_ARCHIVE_ENABLED = process.env.FIRESTORE_ARCHIVE_ENABLED || false;
|
|
@@ -28,3 +28,22 @@ class ArchiveConfig {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
exports.ArchiveConfig = ArchiveConfig;
|
|
31
|
+
exports.DEBUG_PREFIX = '[ARCHIVE SERVICE]';
|
|
32
|
+
const onDebugLog = (message) => {
|
|
33
|
+
if (ArchiveConfig.getConfig().debug) {
|
|
34
|
+
console.log(`${exports.DEBUG_PREFIX} ${message}`);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
exports.onDebugLog = onDebugLog;
|
|
38
|
+
const onDebugError = (message, error) => {
|
|
39
|
+
if (ArchiveConfig.getConfig().debug) {
|
|
40
|
+
console.error(`${exports.DEBUG_PREFIX} ${message}`, error);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
exports.onDebugError = onDebugError;
|
|
44
|
+
const onDebugWarn = (message) => {
|
|
45
|
+
if (ArchiveConfig.getConfig().debug) {
|
|
46
|
+
console.warn(`${exports.DEBUG_PREFIX} ${message}`);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
exports.onDebugWarn = onDebugWarn;
|
|
@@ -8,51 +8,35 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
12
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
13
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
14
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
15
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
16
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
17
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
18
|
-
});
|
|
19
|
-
};
|
|
20
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
12
|
exports.BaseRepository = void 0;
|
|
22
13
|
const ArchiveService_1 = require("../archive/ArchiveService");
|
|
23
14
|
const Query_1 = require("../decorators/Query");
|
|
24
15
|
const ManualQueryHelper_1 = require("../query/ManualQueryHelper");
|
|
25
16
|
class BaseRepository {
|
|
26
|
-
query(config) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return ManualQueryHelper_1.ManualQueryHelper.executeQueryManual(className, config);
|
|
30
|
-
});
|
|
17
|
+
async query(config) {
|
|
18
|
+
const className = this.constructor.prototype.constructor.name;
|
|
19
|
+
return ManualQueryHelper_1.ManualQueryHelper.executeQueryManual(className, config);
|
|
31
20
|
}
|
|
32
|
-
queryRef(config) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return ManualQueryHelper_1.ManualQueryHelper.executeQueryManual(className, config, true);
|
|
36
|
-
});
|
|
21
|
+
async queryRef(config) {
|
|
22
|
+
const className = this.constructor.prototype.constructor.name;
|
|
23
|
+
return ManualQueryHelper_1.ManualQueryHelper.executeQueryManual(className, config, true);
|
|
37
24
|
}
|
|
38
|
-
queryPaginated(config) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
return ManualQueryHelper_1.ManualQueryHelper.executeQueryManualPaginated(className, config);
|
|
42
|
-
});
|
|
25
|
+
async queryPaginated(config) {
|
|
26
|
+
const className = this.constructor.prototype.constructor.name;
|
|
27
|
+
return ManualQueryHelper_1.ManualQueryHelper.executeQueryManualPaginated(className, config);
|
|
43
28
|
}
|
|
44
29
|
/**
|
|
45
30
|
* Limpa o cache de documentos arquivados
|
|
46
31
|
* @param collectionName Nome da collection (opcional)
|
|
47
32
|
* @param docId ID do documento (opcional)
|
|
48
33
|
*/
|
|
49
|
-
clearArchivedCache(collectionName, docId) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
yield archiveService.clearArchivedCache(collectionName, docId);
|
|
53
|
-
});
|
|
34
|
+
async clearArchivedCache(collectionName, docId) {
|
|
35
|
+
const archiveService = await ArchiveService_1.ArchiveService.getInstance();
|
|
36
|
+
await archiveService.clearArchivedCache(collectionName, docId);
|
|
54
37
|
}
|
|
55
38
|
}
|
|
39
|
+
exports.BaseRepository = BaseRepository;
|
|
56
40
|
__decorate([
|
|
57
41
|
(0, Query_1.Query)(),
|
|
58
42
|
__metadata("design:type", Function)
|
|
@@ -101,4 +85,3 @@ __decorate([
|
|
|
101
85
|
(0, Query_1.Query)(),
|
|
102
86
|
__metadata("design:type", Function)
|
|
103
87
|
], BaseRepository.prototype, "aggregation", void 0);
|
|
104
|
-
exports.BaseRepository = BaseRepository;
|
|
@@ -8,33 +8,21 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
12
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
13
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
14
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
15
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
16
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
17
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
18
|
-
});
|
|
19
|
-
};
|
|
20
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
12
|
exports.ReadonlyRepository = void 0;
|
|
22
13
|
const Query_1 = require("../decorators/Query");
|
|
23
14
|
const ManualQueryHelper_1 = require("../query/ManualQueryHelper");
|
|
24
15
|
class ReadonlyRepository {
|
|
25
|
-
query(config) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return ManualQueryHelper_1.ManualQueryHelper.executeQueryManual(className, config);
|
|
29
|
-
});
|
|
16
|
+
async query(config) {
|
|
17
|
+
const className = this.constructor.prototype.constructor.name;
|
|
18
|
+
return ManualQueryHelper_1.ManualQueryHelper.executeQueryManual(className, config);
|
|
30
19
|
}
|
|
31
|
-
queryPaginated(config) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return ManualQueryHelper_1.ManualQueryHelper.executeQueryManualPaginated(className, config);
|
|
35
|
-
});
|
|
20
|
+
async queryPaginated(config) {
|
|
21
|
+
const className = this.constructor.prototype.constructor.name;
|
|
22
|
+
return ManualQueryHelper_1.ManualQueryHelper.executeQueryManualPaginated(className, config);
|
|
36
23
|
}
|
|
37
24
|
}
|
|
25
|
+
exports.ReadonlyRepository = ReadonlyRepository;
|
|
38
26
|
__decorate([
|
|
39
27
|
(0, Query_1.Query)(),
|
|
40
28
|
__metadata("design:type", Function)
|
|
@@ -43,4 +31,3 @@ __decorate([
|
|
|
43
31
|
(0, Query_1.Query)(),
|
|
44
32
|
__metadata("design:type", Function)
|
|
45
33
|
], ReadonlyRepository.prototype, "findById", void 0);
|
|
46
|
-
exports.ReadonlyRepository = ReadonlyRepository;
|
|
@@ -1,13 +1,4 @@
|
|
|
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
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.bindRepositoryInstance = exports.Repository = void 0;
|
|
13
4
|
const ClassMethodQueryMap_1 = require("../config/ClassMethodQueryMap");
|
|
@@ -30,10 +21,10 @@ const bindRepositoryInstance = (options, className, constructor) => {
|
|
|
30
21
|
if (baseRepository) {
|
|
31
22
|
methods = methods.concat(baseRepository);
|
|
32
23
|
}
|
|
33
|
-
constructor.prototype['revokeCache'] = () =>
|
|
24
|
+
constructor.prototype['revokeCache'] = async () => {
|
|
34
25
|
const cacheResolver = global.instances.cacheResolver;
|
|
35
|
-
|
|
36
|
-
}
|
|
26
|
+
await cacheResolver.revokeCacheFromRepository(className);
|
|
27
|
+
};
|
|
37
28
|
methods.forEach(propertyKey => {
|
|
38
29
|
const queryOptions = ClassMethodQueryMap_1.ClassMethodQueryMap.getInstance().getMethodConfig(className, propertyKey);
|
|
39
30
|
const queryOperator = TransformMethodFromQuery_1.TransformMethodFromQuery.extractQuery(propertyKey, queryOptions);
|
|
@@ -1,13 +1,4 @@
|
|
|
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
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.ValidatorDataHandle = void 0;
|
|
13
4
|
const class_validator_1 = require("class-validator");
|
|
@@ -15,19 +6,17 @@ const QueryPredicateFunctionTransform_1 = require("../../query/QueryPredicateFun
|
|
|
15
6
|
const RepositorySystemException_1 = require("../RepositorySystemException");
|
|
16
7
|
const RepositoryValidationException_1 = require("../RepositoryValidationException");
|
|
17
8
|
class ValidatorDataHandle {
|
|
18
|
-
validateModel(modelName, item, validatorOptions) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
9
|
+
async validateModel(modelName, item, validatorOptions) {
|
|
10
|
+
const prototypeRegister = QueryPredicateFunctionTransform_1.QueryPredicateFunctionTransform.prototypeRegister;
|
|
11
|
+
if (!prototypeRegister.has(modelName)) {
|
|
12
|
+
throw new RepositorySystemException_1.RepositorySystemException(`Model validator ${modelName} is not resister in map`);
|
|
13
|
+
}
|
|
14
|
+
const instance = Object.create(prototypeRegister.get(modelName));
|
|
15
|
+
const objectToValidate = Object.assign(instance, item);
|
|
16
|
+
await (0, class_validator_1.validate)(objectToValidate, validatorOptions).then((errors) => {
|
|
17
|
+
if (errors.length > 0) {
|
|
18
|
+
throw new RepositoryValidationException_1.RepositoryValidationException(`Model validation failed, model ref ${modelName}, look at the list of constraints.`, this.getConstraints(errors));
|
|
23
19
|
}
|
|
24
|
-
const instance = Object.create(prototypeRegister.get(modelName));
|
|
25
|
-
const objectToValidate = Object.assign(instance, item);
|
|
26
|
-
yield (0, class_validator_1.validate)(objectToValidate, validatorOptions).then((errors) => {
|
|
27
|
-
if (errors.length > 0) {
|
|
28
|
-
throw new RepositoryValidationException_1.RepositoryValidationException(`Model validation failed, model ref ${modelName}, look at the list of constraints.`, this.getConstraints(errors));
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
20
|
});
|
|
32
21
|
}
|
|
33
22
|
getConstraints(errors) {
|
|
@@ -38,8 +27,7 @@ class ValidatorDataHandle {
|
|
|
38
27
|
return constraintsList;
|
|
39
28
|
}
|
|
40
29
|
extractConstraints(error, ancestor, constraintsList) {
|
|
41
|
-
|
|
42
|
-
if (!((_a = error === null || error === void 0 ? void 0 : error.children) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
30
|
+
if (!error?.children?.length) {
|
|
43
31
|
const constraints = error.constraints;
|
|
44
32
|
constraintsList.push({
|
|
45
33
|
field: ancestor,
|
|
@@ -47,7 +35,7 @@ class ValidatorDataHandle {
|
|
|
47
35
|
});
|
|
48
36
|
}
|
|
49
37
|
else {
|
|
50
|
-
|
|
38
|
+
error?.children?.forEach(err => {
|
|
51
39
|
this.extractConstraints(err, `${ancestor}.${err.property}`, constraintsList);
|
|
52
40
|
});
|
|
53
41
|
}
|
|
@@ -1,13 +1,4 @@
|
|
|
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
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.FirestoreReadAuditResolver = void 0;
|
|
13
4
|
const CurrentEnv_1 = require("../util/CurrentEnv");
|
|
@@ -34,16 +25,22 @@ class FirestoreReadAuditResolver {
|
|
|
34
25
|
}
|
|
35
26
|
return false;
|
|
36
27
|
}
|
|
37
|
-
persistFirestoreRead(props) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
queryResultLength = props.queryResult.length;
|
|
43
|
-
}
|
|
44
|
-
yield this.provider.persistFirestoreRead(Object.assign(Object.assign({}, props), { env: CurrentEnv_1.currentEnv, insertAt: new Date().toISOString().slice(0, -1), projectId: process.env.FIRESTORE_PROJECTID || '', service: process.env.SERVICE || '', queryResult: JSON.stringify(props.queryResult), queryResultLength: queryResultLength }));
|
|
28
|
+
async persistFirestoreRead(props) {
|
|
29
|
+
if (this.provider && !this.isReadAuditTimeEnded()) {
|
|
30
|
+
let queryResultLength = 1;
|
|
31
|
+
if (Array.isArray(props.queryResult)) {
|
|
32
|
+
queryResultLength = props.queryResult.length;
|
|
45
33
|
}
|
|
46
|
-
|
|
34
|
+
await this.provider.persistFirestoreRead({
|
|
35
|
+
...props,
|
|
36
|
+
env: CurrentEnv_1.currentEnv,
|
|
37
|
+
insertAt: new Date().toISOString().slice(0, -1),
|
|
38
|
+
projectId: process.env.FIRESTORE_PROJECTID || '',
|
|
39
|
+
service: process.env.SERVICE || '',
|
|
40
|
+
queryResult: JSON.stringify(props.queryResult),
|
|
41
|
+
queryResultLength: queryResultLength
|
|
42
|
+
});
|
|
43
|
+
}
|
|
47
44
|
}
|
|
48
45
|
}
|
|
49
46
|
exports.FirestoreReadAuditResolver = FirestoreReadAuditResolver;
|