equipped 5.0.0-beta.9 → 5.0.0-rc.2
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/CHANGELOG.md +156 -0
- package/lib/bull/index.js +33 -44
- package/lib/cache/cache.d.ts +1 -0
- package/lib/cache/types/redis-cache.d.ts +1 -0
- package/lib/cache/types/redis-cache.js +8 -0
- package/lib/db/_instance.d.ts +2 -2
- package/lib/db/_instance.js +9 -25
- package/lib/db/mongoose/changes.d.ts +1 -26
- package/lib/db/mongoose/changes.js +7 -20
- package/lib/db/mongoose/index.d.ts +2 -27
- package/lib/db/mongoose/index.js +8 -24
- package/lib/db/mongoose/query.d.ts +0 -25
- package/lib/errors/customError.js +2 -0
- package/lib/errors/types/accessTokenExpired.js +1 -1
- package/lib/errors/types/badRequestError.js +1 -1
- package/lib/errors/types/notAuthenticatedError.js +1 -1
- package/lib/errors/types/notAuthorizedError.js +1 -1
- package/lib/errors/types/notFoundError.js +1 -1
- package/lib/errors/types/refreshTokenMisusedError.js +1 -1
- package/lib/errors/types/validationError.js +1 -1
- package/lib/events/index.js +1 -3
- package/lib/events/kafka.d.ts +1 -1
- package/lib/events/kafka.js +19 -25
- package/lib/events/rabbit.d.ts +1 -1
- package/lib/events/rabbit.js +9 -22
- package/lib/instance/index.d.ts +2 -1
- package/lib/instance/index.js +28 -41
- package/lib/instance/settings.d.ts +2 -2
- package/lib/instance/settings.js +4 -4
- package/lib/listeners/emitter.d.ts +6 -3
- package/lib/listeners/emitter.js +97 -109
- package/lib/scripts/json-schema.d.ts +2 -1
- package/lib/scripts/json-schema.js +29 -22
- package/lib/server/impls/base.d.ts +18 -7
- package/lib/server/impls/base.js +177 -80
- package/lib/server/impls/express.d.ts +0 -1
- package/lib/server/impls/express.js +16 -34
- package/lib/server/impls/fastify.d.ts +2 -4
- package/lib/server/impls/fastify.js +21 -39
- package/lib/server/middlewares/errorHandler.d.ts +2 -2
- package/lib/server/middlewares/notFoundHandler.d.ts +2 -2
- package/lib/server/middlewares/parseAuthUser.d.ts +2 -2
- package/lib/server/middlewares/requireAuthUser.d.ts +2 -2
- package/lib/server/middlewares/requireAuthUser.js +2 -2
- package/lib/server/middlewares/requireRefreshUser.d.ts +2 -2
- package/lib/server/middlewares/requireRefreshUser.js +2 -2
- package/lib/server/requests.d.ts +10 -7
- package/lib/server/requests.js +27 -21
- package/lib/server/routes.d.ts +4 -2
- package/lib/server/routes.js +33 -33
- package/lib/server/types.d.ts +19 -9
- package/lib/server/types.js +3 -0
- package/lib/storage/index.d.ts +0 -1
- package/lib/structure/baseEntity.js +7 -9
- package/lib/types/index.d.ts +2 -2
- package/lib/utils/auth.d.ts +5 -5
- package/lib/utils/authUser.d.ts +3 -2
- package/lib/utils/media.d.ts +0 -1
- package/lib/utils/utils.d.ts +1 -0
- package/lib/utils/utils.js +9 -0
- package/lib/validations/index.d.ts +79 -85
- package/lib/validations/index.js +4 -4
- package/package.json +24 -25
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,162 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [5.0.0-rc.2](https://github.com/kevinand11/equipped/compare/v5.0.0-rc.1...v5.0.0-rc.2) (2024-08-10)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* getOrSet in cache ([f21f132](https://github.com/kevinand11/equipped/commit/f21f1326221a5169c84de6b26483dc2cf6dd98c4))
|
|
11
|
+
|
|
12
|
+
## [5.0.0-rc.1](https://github.com/kevinand11/equipped/compare/v5.0.0-alpha.17...v5.0.0-rc.1) (2024-07-31)
|
|
13
|
+
|
|
14
|
+
## [5.0.0-alpha.17](https://github.com/kevinand11/equipped/compare/v5.0.0-alpha.16...v5.0.0-alpha.17) (2024-07-12)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
* validate schema ([c6977e9](https://github.com/kevinand11/equipped/commit/c6977e96eb159ee25df56dabb8fcae463cdb5f36))
|
|
20
|
+
|
|
21
|
+
## [5.0.0-alpha.16](https://github.com/kevinand11/equipped/compare/v5.0.0-alpha.15...v5.0.0-alpha.16) (2024-07-09)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
### Bug Fixes
|
|
25
|
+
|
|
26
|
+
* to json on BaseEntity ([9196906](https://github.com/kevinand11/equipped/commit/919690689694823ccce6515e41df98fee3012666))
|
|
27
|
+
|
|
28
|
+
## [5.0.0-alpha.15](https://github.com/kevinand11/equipped/compare/v5.0.0-alpha.14...v5.0.0-alpha.15) (2024-07-09)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
### Bug Fixes
|
|
32
|
+
|
|
33
|
+
* excludeIgnored by default ([983caac](https://github.com/kevinand11/equipped/commit/983caac977ccd2c5eeca17c144384bc057286440))
|
|
34
|
+
|
|
35
|
+
## [5.0.0-alpha.14](https://github.com/kevinand11/equipped/compare/v5.0.0-alpha.13...v5.0.0-alpha.14) (2024-07-07)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
### Features
|
|
39
|
+
|
|
40
|
+
* add redocs doc ([f98347e](https://github.com/kevinand11/equipped/commit/f98347e5b815467a9c2a8bff97bdbfa166bc4c7d))
|
|
41
|
+
* redirect to scalar doc ([884f271](https://github.com/kevinand11/equipped/commit/884f271910d4bc2b1f2d50a6bbcf76f6889db85e))
|
|
42
|
+
|
|
43
|
+
## [5.0.0-alpha.13](https://github.com/kevinand11/equipped/compare/v5.0.0-alpha.12...v5.0.0-alpha.13) (2024-07-04)
|
|
44
|
+
|
|
45
|
+
## [5.0.0-alpha.12](https://github.com/kevinand11/equipped/compare/v5.0.0-alpha.11...v5.0.0-alpha.12) (2024-07-04)
|
|
46
|
+
|
|
47
|
+
## [5.0.0-alpha.11](https://github.com/kevinand11/equipped/compare/v5.0.0-alpha.10...v5.0.0-alpha.11) (2024-07-03)
|
|
48
|
+
|
|
49
|
+
## [5.0.0-alpha.10](https://github.com/kevinand11/equipped/compare/v5.0.0-alpha.9...v5.0.0-alpha.10) (2024-07-03)
|
|
50
|
+
|
|
51
|
+
## [5.0.0-alpha.9](https://github.com/kevinand11/equipped/compare/v5.0.0-alpha.8...v5.0.0-alpha.9) (2024-06-29)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
### Bug Fixes
|
|
55
|
+
|
|
56
|
+
* ignoreTrailingSlash for fastify ([dc42565](https://github.com/kevinand11/equipped/commit/dc425659c472d1b8c8e3b899036077c4aa520e00))
|
|
57
|
+
|
|
58
|
+
## [5.0.0-alpha.8](https://github.com/kevinand11/equipped/compare/v5.0.0-alpha.7...v5.0.0-alpha.8) (2024-06-27)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
### Bug Fixes
|
|
62
|
+
|
|
63
|
+
* apiDef key for api definition ([29608b9](https://github.com/kevinand11/equipped/commit/29608b98ff9c1e6eab1061fdc03deb95fed4b023))
|
|
64
|
+
|
|
65
|
+
## [5.0.0-alpha.7](https://github.com/kevinand11/equipped/compare/v5.0.0-alpha.6...v5.0.0-alpha.7) (2024-06-27)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
### Bug Fixes
|
|
69
|
+
|
|
70
|
+
* typing of AuthRoles ([8c6ad91](https://github.com/kevinand11/equipped/commit/8c6ad911c8c0b668d53c0c3269414c3b6bdf30aa))
|
|
71
|
+
|
|
72
|
+
## [5.0.0-alpha.6](https://github.com/kevinand11/equipped/compare/v5.0.0-alpha.5...v5.0.0-alpha.6) (2024-06-26)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
### Bug Fixes
|
|
76
|
+
|
|
77
|
+
* openapi.json relative to index html ([31658f9](https://github.com/kevinand11/equipped/commit/31658f924263ff88dfe2ac757e032e9412598665))
|
|
78
|
+
|
|
79
|
+
## [5.0.0-alpha.5](https://github.com/kevinand11/equipped/compare/v5.0.0-alpha.4...v5.0.0-alpha.5) (2024-06-26)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
### Features
|
|
83
|
+
|
|
84
|
+
* route tag descriptions ([644ef9f](https://github.com/kevinand11/equipped/commit/644ef9f5f929b738aabc99f55d3c61af8a85266e))
|
|
85
|
+
|
|
86
|
+
## [5.0.0-alpha.4](https://github.com/kevinand11/equipped/compare/v5.0.0-alpha.3...v5.0.0-alpha.4) (2024-06-18)
|
|
87
|
+
|
|
88
|
+
## [5.0.0-alpha.3](https://github.com/kevinand11/equipped/compare/v5.0.0-alpha.2...v5.0.0-alpha.3) (2024-06-18)
|
|
89
|
+
|
|
90
|
+
## [5.0.0-alpha.2](https://github.com/kevinand11/equipped/compare/v5.0.0-alpha.1...v5.0.0-alpha.2) (2024-06-16)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
### Features
|
|
94
|
+
|
|
95
|
+
* open api base url ([2a1becf](https://github.com/kevinand11/equipped/commit/2a1becf5f18f2b62ec5b2aada4c14db349e449bc))
|
|
96
|
+
|
|
97
|
+
## [5.0.0-alpha.1](https://github.com/kevinand11/equipped/compare/v5.0.0-beta.17...v5.0.0-alpha.1) (2024-06-09)
|
|
98
|
+
|
|
99
|
+
## [5.0.0-beta.17](https://github.com/kevinand11/equipped/compare/v5.0.0-beta.16...v5.0.0-beta.17) (2024-06-03)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
### Bug Fixes
|
|
103
|
+
|
|
104
|
+
* clean path ([b669329](https://github.com/kevinand11/equipped/commit/b669329136c319d827f9c6b5440342ef2b05c8ca))
|
|
105
|
+
|
|
106
|
+
## [5.0.0-beta.16](https://github.com/kevinand11/equipped/compare/v5.0.0-beta.15...v5.0.0-beta.16) (2024-06-03)
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
### Features
|
|
110
|
+
|
|
111
|
+
* support headers in schema ([85a9319](https://github.com/kevinand11/equipped/commit/85a93195ffb9b97927dc22a61d5f118f49598926))
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
### Bug Fixes
|
|
115
|
+
|
|
116
|
+
* error when cloning objects in toJSON ([1f4cf25](https://github.com/kevinand11/equipped/commit/1f4cf252a6924f0b2c329c11b41f5ac71c68f87b))
|
|
117
|
+
|
|
118
|
+
## [5.0.0-beta.15](https://github.com/kevinand11/equipped/compare/v5.0.0-beta.14...v5.0.0-beta.15) (2024-06-02)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
### Bug Fixes
|
|
122
|
+
|
|
123
|
+
* remove slowdown to avoid esm ([414b2ef](https://github.com/kevinand11/equipped/commit/414b2ef3c047a0c9843ae828b21a1aeaa10925b9))
|
|
124
|
+
|
|
125
|
+
## [5.0.0-beta.14](https://github.com/kevinand11/equipped/compare/v5.0.0-beta.13...v5.0.0-beta.14) (2024-06-02)
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
### Bug Fixes
|
|
129
|
+
|
|
130
|
+
* use maps for registered maps for speed ([1882a24](https://github.com/kevinand11/equipped/commit/1882a24d02d666e7779212dbeb67e1022761c823))
|
|
131
|
+
|
|
132
|
+
## [5.0.0-beta.13](https://github.com/kevinand11/equipped/compare/v5.0.0-beta.12...v5.0.0-beta.13) (2024-06-01)
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
### Features
|
|
136
|
+
|
|
137
|
+
* add description for each status code ([064a686](https://github.com/kevinand11/equipped/commit/064a68647ea91a5791aad75b1b95988accc38b32))
|
|
138
|
+
|
|
139
|
+
## [5.0.0-beta.12](https://github.com/kevinand11/equipped/compare/v5.0.0-beta.11...v5.0.0-beta.12) (2024-06-01)
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
### Bug Fixes
|
|
143
|
+
|
|
144
|
+
* function overloading for validate function ([e1209ab](https://github.com/kevinand11/equipped/commit/e1209ab10f435514d7ac84c3c0af1788d7f3699d))
|
|
145
|
+
* references to BaseEntity ([071a07a](https://github.com/kevinand11/equipped/commit/071a07a827e6c4f73b5cf43ae462541c4518df21))
|
|
146
|
+
|
|
147
|
+
## [5.0.0-beta.11](https://github.com/kevinand11/equipped/compare/v5.0.0-beta.10...v5.0.0-beta.11) (2024-06-01)
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
### Features
|
|
151
|
+
|
|
152
|
+
* unique paths and keys for routes ([36d1776](https://github.com/kevinand11/equipped/commit/36d17762b6d31497e9f15883cc05073ff29a886e))
|
|
153
|
+
|
|
154
|
+
## [5.0.0-beta.10](https://github.com/kevinand11/equipped/compare/v5.0.0-beta.9...v5.0.0-beta.10) (2024-05-31)
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
### Bug Fixes
|
|
158
|
+
|
|
159
|
+
* generateJSONSchema ([062360b](https://github.com/kevinand11/equipped/commit/062360bb92ccdaa1ae8fa3d167f9bbb71f156f7c))
|
|
160
|
+
|
|
5
161
|
## [5.0.0-beta.9](https://github.com/kevinand11/equipped/compare/v5.0.0-beta.8...v5.0.0-beta.9) (2024-05-31)
|
|
6
162
|
|
|
7
163
|
|
package/lib/bull/index.js
CHANGED
|
@@ -1,19 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
-
};
|
|
8
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
-
};
|
|
13
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
4
|
};
|
|
16
|
-
var _BullJob_instances, _a, _BullJob_queue, _BullJob_getNewId, _BullJob_addCronJob, _BullJob_cleanup;
|
|
17
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
6
|
exports.BullJob = void 0;
|
|
19
7
|
const bull_1 = __importDefault(require("bull"));
|
|
@@ -26,14 +14,16 @@ var JobNames;
|
|
|
26
14
|
JobNames["DelayedJob"] = "DelayedJob";
|
|
27
15
|
})(JobNames || (JobNames = {}));
|
|
28
16
|
class BullJob {
|
|
17
|
+
#queue;
|
|
29
18
|
constructor() {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
19
|
+
this.#queue = new bull_1.default(instance_1.Instance.get().settings.bullQueueName, instance_1.Instance.get().settings.redisURI);
|
|
20
|
+
}
|
|
21
|
+
static #getNewId() {
|
|
22
|
+
return [Date.now(), utils_1.Random.string()].join(':');
|
|
33
23
|
}
|
|
34
24
|
async addDelayedJob(data, delayInMs) {
|
|
35
|
-
const job = await
|
|
36
|
-
jobId:
|
|
25
|
+
const job = await this.#queue.add(JobNames.DelayedJob, data, {
|
|
26
|
+
jobId: BullJob.#getNewId(),
|
|
37
27
|
delay: delayInMs,
|
|
38
28
|
removeOnComplete: true,
|
|
39
29
|
backoff: 1000,
|
|
@@ -42,8 +32,8 @@ class BullJob {
|
|
|
42
32
|
return job.id.toString();
|
|
43
33
|
}
|
|
44
34
|
async addCronLikeJob(data, cron, tz) {
|
|
45
|
-
const job = await
|
|
46
|
-
jobId:
|
|
35
|
+
const job = await this.#queue.add(JobNames.CronLikeJob, data, {
|
|
36
|
+
jobId: BullJob.#getNewId(),
|
|
47
37
|
repeat: { cron, ...(tz ? { tz } : {}) },
|
|
48
38
|
removeOnComplete: true,
|
|
49
39
|
backoff: 1000,
|
|
@@ -52,42 +42,41 @@ class BullJob {
|
|
|
52
42
|
return job.opts?.repeat?.key ?? '';
|
|
53
43
|
}
|
|
54
44
|
async removeDelayedJob(jobId) {
|
|
55
|
-
const job = await
|
|
45
|
+
const job = await this.#queue.getJob(jobId);
|
|
56
46
|
if (job)
|
|
57
47
|
await job.discard();
|
|
58
48
|
}
|
|
59
49
|
async removeCronLikeJob(jobKey) {
|
|
60
|
-
await
|
|
50
|
+
await this.#queue.removeRepeatableByKey(jobKey);
|
|
61
51
|
}
|
|
62
52
|
async retryAllFailedJobs() {
|
|
63
|
-
const failedJobs = await
|
|
53
|
+
const failedJobs = await this.#queue.getFailed();
|
|
64
54
|
await Promise.all(failedJobs.map((job) => job.retry()));
|
|
65
55
|
}
|
|
66
56
|
async startProcessingQueues(crons, callbacks) {
|
|
67
|
-
await
|
|
68
|
-
await Promise.all(crons.map(({ cron, name }) =>
|
|
57
|
+
await this.#cleanup();
|
|
58
|
+
await Promise.all(crons.map(({ cron, name }) => this.#addCronJob(name, cron)));
|
|
69
59
|
await Promise.all([
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
60
|
+
this.#queue.process(JobNames.DelayedJob, async (job) => await callbacks.onDelayed?.(job.data)),
|
|
61
|
+
this.#queue.process(JobNames.CronJob, async (job) => await callbacks.onCron?.(job.data.type)),
|
|
62
|
+
this.#queue.process(JobNames.CronLikeJob, async (job) => await callbacks.onCronLike?.(job.data))
|
|
73
63
|
]);
|
|
74
64
|
}
|
|
65
|
+
async #addCronJob(type, cron) {
|
|
66
|
+
const job = await this.#queue.add(JobNames.CronJob, { type }, {
|
|
67
|
+
repeat: { cron },
|
|
68
|
+
removeOnComplete: true,
|
|
69
|
+
backoff: 1000,
|
|
70
|
+
attempts: 3
|
|
71
|
+
});
|
|
72
|
+
return job.id.toString();
|
|
73
|
+
}
|
|
74
|
+
async #cleanup() {
|
|
75
|
+
await this.retryAllFailedJobs();
|
|
76
|
+
const repeatableJobs = await this.#queue.getRepeatableJobs();
|
|
77
|
+
await Promise.all(repeatableJobs
|
|
78
|
+
.filter((job) => job.name === JobNames.CronJob)
|
|
79
|
+
.map((job) => this.#queue.removeRepeatableByKey(job.key)));
|
|
80
|
+
}
|
|
75
81
|
}
|
|
76
82
|
exports.BullJob = BullJob;
|
|
77
|
-
_a = BullJob, _BullJob_queue = new WeakMap(), _BullJob_instances = new WeakSet(), _BullJob_getNewId = function _BullJob_getNewId() {
|
|
78
|
-
return [Date.now(), utils_1.Random.string()].join(':');
|
|
79
|
-
}, _BullJob_addCronJob = async function _BullJob_addCronJob(type, cron) {
|
|
80
|
-
const job = await __classPrivateFieldGet(this, _BullJob_queue, "f").add(JobNames.CronJob, { type }, {
|
|
81
|
-
repeat: { cron },
|
|
82
|
-
removeOnComplete: true,
|
|
83
|
-
backoff: 1000,
|
|
84
|
-
attempts: 3
|
|
85
|
-
});
|
|
86
|
-
return job.id.toString();
|
|
87
|
-
}, _BullJob_cleanup = async function _BullJob_cleanup() {
|
|
88
|
-
await this.retryAllFailedJobs();
|
|
89
|
-
const repeatableJobs = await __classPrivateFieldGet(this, _BullJob_queue, "f").getRepeatableJobs();
|
|
90
|
-
await Promise.all(repeatableJobs
|
|
91
|
-
.filter((job) => job.name === JobNames.CronJob)
|
|
92
|
-
.map((job) => __classPrivateFieldGet(this, _BullJob_queue, "f").removeRepeatableByKey(job.key)));
|
|
93
|
-
};
|
package/lib/cache/cache.d.ts
CHANGED
|
@@ -4,4 +4,5 @@ export declare abstract class Cache {
|
|
|
4
4
|
abstract set(key: string, data: string, ttlInSecs: number): Promise<void>;
|
|
5
5
|
abstract get(key: string): Promise<string | null>;
|
|
6
6
|
abstract delete(key: string): Promise<void>;
|
|
7
|
+
abstract getOrSet<T>(key: string, fn: () => Promise<T>, ttlInSecs: number): Promise<T>;
|
|
7
8
|
}
|
|
@@ -8,4 +8,5 @@ export declare class RedisCache extends Cache {
|
|
|
8
8
|
delete(key: string): Promise<void>;
|
|
9
9
|
get(key: string): Promise<string | null>;
|
|
10
10
|
set(key: string, data: string, ttlInSecs: number): Promise<void>;
|
|
11
|
+
getOrSet<T>(key: string, fn: () => Promise<T>, ttlInSecs: number): Promise<any>;
|
|
11
12
|
}
|
|
@@ -6,6 +6,7 @@ const exit_1 = require("../../exit");
|
|
|
6
6
|
const instance_1 = require("../../instance");
|
|
7
7
|
const cache_1 = require("../cache");
|
|
8
8
|
class RedisCache extends cache_1.Cache {
|
|
9
|
+
client;
|
|
9
10
|
constructor() {
|
|
10
11
|
super();
|
|
11
12
|
this.client = (0, redis_1.createClient)({ url: instance_1.Instance.get().settings.redisURI });
|
|
@@ -31,5 +32,12 @@ class RedisCache extends cache_1.Cache {
|
|
|
31
32
|
else
|
|
32
33
|
this.client.set(key, data);
|
|
33
34
|
}
|
|
35
|
+
async getOrSet(key, fn, ttlInSecs) {
|
|
36
|
+
const cached = await this.get(key);
|
|
37
|
+
if (cached)
|
|
38
|
+
return JSON.parse(cached);
|
|
39
|
+
const result = await fn();
|
|
40
|
+
await this.set(key, JSON.stringify(result), ttlInSecs);
|
|
41
|
+
}
|
|
34
42
|
}
|
|
35
43
|
exports.RedisCache = RedisCache;
|
package/lib/db/_instance.d.ts
CHANGED
|
@@ -4,14 +4,14 @@ import { DebeziumSetup } from './debezium';
|
|
|
4
4
|
import { QueryParams, QueryResults } from './query';
|
|
5
5
|
export declare abstract class Db {
|
|
6
6
|
#private;
|
|
7
|
-
abstract change<Model, Entity extends BaseEntity
|
|
7
|
+
abstract change<Model, Entity extends BaseEntity<any, any>>(collection: any, callbacks: DbChangeCallbacks<Model, Entity>, mapper: (model: Model | null) => Entity | null): DbChange<Model, Entity>;
|
|
8
8
|
abstract query<Model>(collection: any, params: QueryParams): Promise<QueryResults<Model>>;
|
|
9
9
|
protected _addToDbChanges(dbChange: DbChange<any, any>): this;
|
|
10
10
|
startAllDbChanges(): Promise<void>;
|
|
11
11
|
abstract start(): Promise<void>;
|
|
12
12
|
abstract close(): Promise<void>;
|
|
13
13
|
}
|
|
14
|
-
export declare abstract class DbChange<Model, Entity extends BaseEntity
|
|
14
|
+
export declare abstract class DbChange<Model, Entity extends BaseEntity<any, any>> {
|
|
15
15
|
#private;
|
|
16
16
|
constructor(callbacks: DbChangeCallbacks<Model, Entity>, mapper: (model: Model | null) => Entity | null);
|
|
17
17
|
abstract start(): Promise<void>;
|
package/lib/db/_instance.js
CHANGED
|
@@ -1,19 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
-
};
|
|
7
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
8
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
9
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
10
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
11
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
12
|
-
};
|
|
13
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
4
|
};
|
|
16
|
-
var _Db_dbChanges, _DbChange_callbacks, _DbChange_mapper;
|
|
17
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
6
|
exports.DbChange = exports.Db = void 0;
|
|
19
7
|
const axios_1 = __importDefault(require("axios"));
|
|
@@ -21,31 +9,28 @@ const exit_1 = require("../exit");
|
|
|
21
9
|
const instance_1 = require("../instance");
|
|
22
10
|
const debezium_1 = require("./debezium");
|
|
23
11
|
class Db {
|
|
24
|
-
|
|
25
|
-
_Db_dbChanges.set(this, []);
|
|
26
|
-
}
|
|
12
|
+
#dbChanges = [];
|
|
27
13
|
_addToDbChanges(dbChange) {
|
|
28
|
-
|
|
14
|
+
this.#dbChanges.push(dbChange);
|
|
29
15
|
return this;
|
|
30
16
|
}
|
|
31
17
|
async startAllDbChanges() {
|
|
32
|
-
await Promise.all(
|
|
18
|
+
await Promise.all(this.#dbChanges.map((change) => change.start()));
|
|
33
19
|
}
|
|
34
20
|
}
|
|
35
21
|
exports.Db = Db;
|
|
36
|
-
_Db_dbChanges = new WeakMap();
|
|
37
22
|
class DbChange {
|
|
23
|
+
#callbacks = {};
|
|
24
|
+
#mapper;
|
|
38
25
|
constructor(callbacks, mapper) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
__classPrivateFieldSet(this, _DbChange_callbacks, callbacks, "f");
|
|
42
|
-
__classPrivateFieldSet(this, _DbChange_mapper, mapper, "f");
|
|
26
|
+
this.#callbacks = callbacks;
|
|
27
|
+
this.#mapper = mapper;
|
|
43
28
|
}
|
|
44
29
|
get callbacks() {
|
|
45
|
-
return Object.freeze(
|
|
30
|
+
return Object.freeze(this.#callbacks);
|
|
46
31
|
}
|
|
47
32
|
get mapper() {
|
|
48
|
-
return
|
|
33
|
+
return this.#mapper;
|
|
49
34
|
}
|
|
50
35
|
async _setup(key, data) {
|
|
51
36
|
data = { ...debezium_1.DefaultDebeziumSetup, ...data };
|
|
@@ -62,4 +47,3 @@ class DbChange {
|
|
|
62
47
|
}
|
|
63
48
|
}
|
|
64
49
|
exports.DbChange = DbChange;
|
|
65
|
-
_DbChange_callbacks = new WeakMap(), _DbChange_mapper = new WeakMap();
|
|
@@ -1,32 +1,7 @@
|
|
|
1
|
-
/// <reference types="mongoose/types/aggregate" />
|
|
2
|
-
/// <reference types="mongoose/types/callback" />
|
|
3
|
-
/// <reference types="mongoose/types/collection" />
|
|
4
|
-
/// <reference types="mongoose/types/connection" />
|
|
5
|
-
/// <reference types="mongoose/types/cursor" />
|
|
6
|
-
/// <reference types="mongoose/types/document" />
|
|
7
|
-
/// <reference types="mongoose/types/error" />
|
|
8
|
-
/// <reference types="mongoose/types/expressions" />
|
|
9
|
-
/// <reference types="mongoose/types/helpers" />
|
|
10
|
-
/// <reference types="mongoose/types/middlewares" />
|
|
11
|
-
/// <reference types="mongoose/types/indexes" />
|
|
12
|
-
/// <reference types="mongoose/types/models" />
|
|
13
|
-
/// <reference types="mongoose/types/mongooseoptions" />
|
|
14
|
-
/// <reference types="mongoose/types/pipelinestage" />
|
|
15
|
-
/// <reference types="mongoose/types/populate" />
|
|
16
|
-
/// <reference types="mongoose/types/query" />
|
|
17
|
-
/// <reference types="mongoose/types/schemaoptions" />
|
|
18
|
-
/// <reference types="mongoose/types/schematypes" />
|
|
19
|
-
/// <reference types="mongoose/types/session" />
|
|
20
|
-
/// <reference types="mongoose/types/types" />
|
|
21
|
-
/// <reference types="mongoose/types/utility" />
|
|
22
|
-
/// <reference types="mongoose/types/validation" />
|
|
23
|
-
/// <reference types="mongoose/types/virtuals" />
|
|
24
|
-
/// <reference types="mongoose/types/inferschematype" />
|
|
25
|
-
/// <reference types="mongoose/types/inferrawdoctype" />
|
|
26
1
|
import mongoose from 'mongoose';
|
|
27
2
|
import { BaseEntity } from '../../structure';
|
|
28
3
|
import { DbChange, DbChangeCallbacks } from '../_instance';
|
|
29
|
-
export declare class MongoDbChange<Model, Entity extends BaseEntity
|
|
4
|
+
export declare class MongoDbChange<Model, Entity extends BaseEntity<any, any>> extends DbChange<Model, Entity> {
|
|
30
5
|
#private;
|
|
31
6
|
constructor(model: mongoose.Model<Model>, callbacks: DbChangeCallbacks<Model, Entity>, mapper: (model: Model | null) => Entity | null);
|
|
32
7
|
start(): Promise<void>;
|
|
@@ -1,19 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
-
};
|
|
8
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
-
};
|
|
13
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
4
|
};
|
|
16
|
-
var _MongoDbChange_started, _MongoDbChange_model;
|
|
17
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
6
|
exports.MongoDbChange = void 0;
|
|
19
7
|
const mongoose_1 = __importDefault(require("mongoose"));
|
|
@@ -24,17 +12,17 @@ const validations_1 = require("../../validations");
|
|
|
24
12
|
const _instance_1 = require("../_instance");
|
|
25
13
|
const debezium_1 = require("../debezium");
|
|
26
14
|
class MongoDbChange extends _instance_1.DbChange {
|
|
15
|
+
#started = false;
|
|
16
|
+
#model;
|
|
27
17
|
constructor(model, callbacks, mapper) {
|
|
28
18
|
super(callbacks, mapper);
|
|
29
|
-
|
|
30
|
-
_MongoDbChange_model.set(this, void 0);
|
|
31
|
-
__classPrivateFieldSet(this, _MongoDbChange_model, model, "f");
|
|
19
|
+
this.#model = model;
|
|
32
20
|
}
|
|
33
21
|
async start() {
|
|
34
|
-
if (
|
|
22
|
+
if (this.#started)
|
|
35
23
|
return;
|
|
36
|
-
|
|
37
|
-
const model =
|
|
24
|
+
this.#started = true;
|
|
25
|
+
const model = this.#model;
|
|
38
26
|
const dbName = model.db.name;
|
|
39
27
|
const colName = model.collection.name;
|
|
40
28
|
const dbColName = `${dbName}.${colName}`;
|
|
@@ -90,12 +78,11 @@ class MongoDbChange extends _instance_1.DbChange {
|
|
|
90
78
|
await instance_1.Instance.get().logger.warn(`Waiting for db changes for ${dbColName} to start...`);
|
|
91
79
|
throw new Error(`Wait a few minutes for db changes for ${dbColName} to initialize...`);
|
|
92
80
|
}
|
|
93
|
-
}, 5,
|
|
81
|
+
}, 5, 60_000)
|
|
94
82
|
.catch((err) => (0, exit_1.exit)(err.message));
|
|
95
83
|
}
|
|
96
84
|
}
|
|
97
85
|
exports.MongoDbChange = MongoDbChange;
|
|
98
|
-
_MongoDbChange_started = new WeakMap(), _MongoDbChange_model = new WeakMap();
|
|
99
86
|
const makeId = (id) => {
|
|
100
87
|
try {
|
|
101
88
|
return new mongoose_1.default.Types.ObjectId(id);
|
|
@@ -1,39 +1,14 @@
|
|
|
1
|
-
/// <reference types="mongoose/types/aggregate" />
|
|
2
|
-
/// <reference types="mongoose/types/callback" />
|
|
3
|
-
/// <reference types="mongoose/types/collection" />
|
|
4
|
-
/// <reference types="mongoose/types/connection" />
|
|
5
|
-
/// <reference types="mongoose/types/cursor" />
|
|
6
|
-
/// <reference types="mongoose/types/document" />
|
|
7
|
-
/// <reference types="mongoose/types/error" />
|
|
8
|
-
/// <reference types="mongoose/types/expressions" />
|
|
9
|
-
/// <reference types="mongoose/types/helpers" />
|
|
10
|
-
/// <reference types="mongoose/types/middlewares" />
|
|
11
|
-
/// <reference types="mongoose/types/indexes" />
|
|
12
|
-
/// <reference types="mongoose/types/models" />
|
|
13
|
-
/// <reference types="mongoose/types/mongooseoptions" />
|
|
14
|
-
/// <reference types="mongoose/types/pipelinestage" />
|
|
15
|
-
/// <reference types="mongoose/types/populate" />
|
|
16
|
-
/// <reference types="mongoose/types/query" />
|
|
17
|
-
/// <reference types="mongoose/types/schemaoptions" />
|
|
18
|
-
/// <reference types="mongoose/types/schematypes" />
|
|
19
|
-
/// <reference types="mongoose/types/session" />
|
|
20
|
-
/// <reference types="mongoose/types/types" />
|
|
21
|
-
/// <reference types="mongoose/types/utility" />
|
|
22
|
-
/// <reference types="mongoose/types/validation" />
|
|
23
|
-
/// <reference types="mongoose/types/virtuals" />
|
|
24
|
-
/// <reference types="mongoose/types/inferschematype" />
|
|
25
|
-
/// <reference types="mongoose/types/inferrawdoctype" />
|
|
26
1
|
import mongoose from 'mongoose';
|
|
27
2
|
import { BaseEntity } from '../../structure';
|
|
28
|
-
import { QueryParams, QueryResults } from '../query';
|
|
29
3
|
import { Db, DbChangeCallbacks } from '../_instance';
|
|
4
|
+
import { QueryParams, QueryResults } from '../query';
|
|
30
5
|
import { MongoDbChange } from './changes';
|
|
31
6
|
export declare class MongoDb extends Db {
|
|
32
7
|
#private;
|
|
33
8
|
get Schema(): typeof mongoose.Schema;
|
|
34
9
|
get Id(): mongoose.Types.ObjectId;
|
|
35
10
|
use(dbName?: string): mongoose.Connection;
|
|
36
|
-
change<Model, Entity extends BaseEntity
|
|
11
|
+
change<Model, Entity extends BaseEntity<any, any>>(model: mongoose.Model<Model>, callbacks: DbChangeCallbacks<Model, Entity>, mapper: (model: Model | null) => Entity | null): MongoDbChange<Model, Entity>;
|
|
37
12
|
query<Model>(model: mongoose.Model<Model>, params: QueryParams): Promise<QueryResults<Model>>;
|
|
38
13
|
start(): Promise<void>;
|
|
39
14
|
close(): Promise<void>;
|
package/lib/db/mongoose/index.js
CHANGED
|
@@ -1,19 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
-
};
|
|
7
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
8
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
9
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
10
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
11
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
12
|
-
};
|
|
13
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
4
|
};
|
|
16
|
-
var _MongoDb_instances, _MongoDb_started, _MongoDb_connections_get;
|
|
17
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
6
|
exports.MongoDb = void 0;
|
|
19
7
|
const mongoose_1 = __importDefault(require("mongoose"));
|
|
@@ -25,17 +13,16 @@ const _instance_1 = require("../_instance");
|
|
|
25
13
|
const changes_1 = require("./changes");
|
|
26
14
|
const query_1 = require("./query");
|
|
27
15
|
class MongoDb extends _instance_1.Db {
|
|
28
|
-
|
|
29
|
-
super(...arguments);
|
|
30
|
-
_MongoDb_instances.add(this);
|
|
31
|
-
_MongoDb_started.set(this, false);
|
|
32
|
-
}
|
|
16
|
+
#started = false;
|
|
33
17
|
get Schema() {
|
|
34
18
|
return mongoose_1.default.Schema;
|
|
35
19
|
}
|
|
36
20
|
get Id() {
|
|
37
21
|
return new mongoose_1.default.Types.ObjectId();
|
|
38
22
|
}
|
|
23
|
+
get #connections() {
|
|
24
|
+
return mongoose_1.default.connection.otherDbs ?? [];
|
|
25
|
+
}
|
|
39
26
|
use(dbName = 'default') {
|
|
40
27
|
const conn = dbName === 'default' ? mongoose_1.default.connection : mongoose_1.default.connection.useDb(dbName, { useCache: true });
|
|
41
28
|
conn.plugin(mongoose_lean_defaults_1.default).plugin(mongoose_lean_virtuals_1.default).plugin(mongoose_lean_getters_1.default);
|
|
@@ -50,12 +37,12 @@ class MongoDb extends _instance_1.Db {
|
|
|
50
37
|
return await (0, query_1.parseMongodbQueryParams)(model, params);
|
|
51
38
|
}
|
|
52
39
|
async start() {
|
|
53
|
-
if (
|
|
40
|
+
if (this.#started)
|
|
54
41
|
return;
|
|
55
|
-
|
|
42
|
+
this.#started = true;
|
|
56
43
|
mongoose_1.default.set('strictQuery', true);
|
|
57
44
|
await mongoose_1.default.connect(instance_1.Instance.get().settings.mongoDbURI);
|
|
58
|
-
await Promise.all([mongoose_1.default.connection, ...
|
|
45
|
+
await Promise.all([mongoose_1.default.connection, ...this.#connections].map((conn) => {
|
|
59
46
|
return Object.values(conn.models)
|
|
60
47
|
.map(async (model) => {
|
|
61
48
|
await conn.db.createCollection(model.collection.name, {
|
|
@@ -65,11 +52,8 @@ class MongoDb extends _instance_1.Db {
|
|
|
65
52
|
}).flat());
|
|
66
53
|
}
|
|
67
54
|
async close() {
|
|
68
|
-
await Promise.all(
|
|
55
|
+
await Promise.all(this.#connections.map(async (conn) => conn.close()));
|
|
69
56
|
await mongoose_1.default.disconnect();
|
|
70
57
|
}
|
|
71
58
|
}
|
|
72
59
|
exports.MongoDb = MongoDb;
|
|
73
|
-
_MongoDb_started = new WeakMap(), _MongoDb_instances = new WeakSet(), _MongoDb_connections_get = function _MongoDb_connections_get() {
|
|
74
|
-
return mongoose_1.default.connection.otherDbs ?? [];
|
|
75
|
-
};
|
|
@@ -1,28 +1,3 @@
|
|
|
1
|
-
/// <reference types="mongoose/types/aggregate" />
|
|
2
|
-
/// <reference types="mongoose/types/callback" />
|
|
3
|
-
/// <reference types="mongoose/types/collection" />
|
|
4
|
-
/// <reference types="mongoose/types/connection" />
|
|
5
|
-
/// <reference types="mongoose/types/cursor" />
|
|
6
|
-
/// <reference types="mongoose/types/document" />
|
|
7
|
-
/// <reference types="mongoose/types/error" />
|
|
8
|
-
/// <reference types="mongoose/types/expressions" />
|
|
9
|
-
/// <reference types="mongoose/types/helpers" />
|
|
10
|
-
/// <reference types="mongoose/types/middlewares" />
|
|
11
|
-
/// <reference types="mongoose/types/indexes" />
|
|
12
|
-
/// <reference types="mongoose/types/models" />
|
|
13
|
-
/// <reference types="mongoose/types/mongooseoptions" />
|
|
14
|
-
/// <reference types="mongoose/types/pipelinestage" />
|
|
15
|
-
/// <reference types="mongoose/types/populate" />
|
|
16
|
-
/// <reference types="mongoose/types/query" />
|
|
17
|
-
/// <reference types="mongoose/types/schemaoptions" />
|
|
18
|
-
/// <reference types="mongoose/types/schematypes" />
|
|
19
|
-
/// <reference types="mongoose/types/session" />
|
|
20
|
-
/// <reference types="mongoose/types/types" />
|
|
21
|
-
/// <reference types="mongoose/types/utility" />
|
|
22
|
-
/// <reference types="mongoose/types/validation" />
|
|
23
|
-
/// <reference types="mongoose/types/virtuals" />
|
|
24
|
-
/// <reference types="mongoose/types/inferschematype" />
|
|
25
|
-
/// <reference types="mongoose/types/inferrawdoctype" />
|
|
26
1
|
import mongoose from 'mongoose';
|
|
27
2
|
import { QueryParams, QueryResults } from '../query';
|
|
28
3
|
export declare const parseMongodbQueryParams: <Model>(model: mongoose.Model<Model>, params: QueryParams) => Promise<QueryResults<Model>>;
|