@russ-b/nestjs-common-tools 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +259 -0
- package/dist/common/util/error.util.d.ts +1 -0
- package/dist/common/util/error.util.js +10 -0
- package/dist/common/util/error.util.js.map +1 -0
- package/dist/common/util/index.d.ts +1 -0
- package/dist/common/util/index.js +1 -0
- package/dist/common/util/index.js.map +1 -1
- package/dist/errors/api-error-code.enum.d.ts +11 -0
- package/dist/errors/api-error-code.enum.js +16 -0
- package/dist/errors/api-error-code.enum.js.map +1 -0
- package/dist/errors/api-error-response.type.d.ts +11 -0
- package/dist/errors/api-error-response.type.js +3 -0
- package/dist/errors/api-error-response.type.js.map +1 -0
- package/dist/errors/api-error-root-field.constant.d.ts +1 -0
- package/dist/errors/api-error-root-field.constant.js +5 -0
- package/dist/errors/api-error-root-field.constant.js.map +1 -0
- package/dist/errors/class-validator-exception.factory.d.ts +6 -0
- package/dist/errors/class-validator-exception.factory.js +38 -0
- package/dist/errors/class-validator-exception.factory.js.map +1 -0
- package/dist/errors/error-response.factory.d.ts +10 -0
- package/dist/errors/error-response.factory.js +46 -0
- package/dist/errors/error-response.factory.js.map +1 -0
- package/dist/errors/index.d.ts +5 -0
- package/dist/errors/index.js +22 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/logger/pino/index.d.ts +1 -0
- package/dist/{common/filters → logger/pino}/index.js +1 -1
- package/dist/logger/pino/index.js.map +1 -0
- package/dist/logger/pino-logger.d.ts +13 -0
- package/dist/logger/pino-logger.js +62 -0
- package/dist/logger/pino-logger.js.map +1 -0
- package/dist/modules/index.d.ts +1 -0
- package/dist/modules/index.js +1 -0
- package/dist/modules/index.js.map +1 -1
- package/dist/modules/outbox/entities/index.d.ts +1 -0
- package/dist/modules/outbox/entities/index.js +18 -0
- package/dist/modules/outbox/entities/index.js.map +1 -0
- package/dist/modules/outbox/entities/outbox-event.entity.d.ts +12 -0
- package/dist/modules/outbox/entities/outbox-event.entity.js +67 -0
- package/dist/modules/outbox/entities/outbox-event.entity.js.map +1 -0
- package/dist/modules/outbox/enums/index.d.ts +1 -0
- package/dist/modules/outbox/enums/index.js +18 -0
- package/dist/modules/outbox/enums/index.js.map +1 -0
- package/dist/modules/outbox/enums/outbox-event-status.enum.d.ts +6 -0
- package/dist/modules/outbox/enums/outbox-event-status.enum.js +11 -0
- package/dist/modules/outbox/enums/outbox-event-status.enum.js.map +1 -0
- package/dist/modules/outbox/index.d.ts +6 -0
- package/dist/modules/outbox/index.js +23 -0
- package/dist/modules/outbox/index.js.map +1 -0
- package/dist/modules/outbox/outbox-options.util.d.ts +3 -0
- package/dist/modules/outbox/outbox-options.util.js +34 -0
- package/dist/modules/outbox/outbox-options.util.js.map +1 -0
- package/dist/modules/outbox/outbox.constants.d.ts +2 -0
- package/dist/modules/outbox/outbox.constants.js +6 -0
- package/dist/modules/outbox/outbox.constants.js.map +1 -0
- package/dist/modules/outbox/outbox.module.d.ts +6 -0
- package/dist/modules/outbox/outbox.module.js +74 -0
- package/dist/modules/outbox/outbox.module.js.map +1 -0
- package/dist/modules/outbox/services/base-worker.d.ts +14 -0
- package/dist/modules/outbox/services/base-worker.js +91 -0
- package/dist/modules/outbox/services/base-worker.js.map +1 -0
- package/dist/modules/outbox/services/index.d.ts +3 -0
- package/dist/modules/outbox/services/index.js +20 -0
- package/dist/modules/outbox/services/index.js.map +1 -0
- package/dist/modules/outbox/services/outbox-cleanup.worker.d.ts +9 -0
- package/dist/modules/outbox/services/outbox-cleanup.worker.js +59 -0
- package/dist/modules/outbox/services/outbox-cleanup.worker.js.map +1 -0
- package/dist/modules/outbox/services/outbox.service.d.ts +22 -0
- package/dist/modules/outbox/services/outbox.service.js +235 -0
- package/dist/modules/outbox/services/outbox.service.js.map +1 -0
- package/dist/modules/outbox/types/index.d.ts +1 -0
- package/dist/modules/outbox/types/index.js +18 -0
- package/dist/modules/outbox/types/index.js.map +1 -0
- package/dist/modules/outbox/types/outbox-module-options.interface.d.ts +35 -0
- package/dist/modules/outbox/types/outbox-module-options.interface.js +3 -0
- package/dist/modules/outbox/types/outbox-module-options.interface.js.map +1 -0
- package/dist/typeorm/config/postgres-typeorm-options.factory.d.ts +12 -2
- package/dist/typeorm/config/postgres-typeorm-options.factory.js +37 -2
- package/dist/typeorm/config/postgres-typeorm-options.factory.js.map +1 -1
- package/dist/zod/filters/index.d.ts +3 -0
- package/dist/zod/filters/index.js +20 -0
- package/dist/zod/filters/index.js.map +1 -0
- package/dist/zod/filters/zod-express-exception.filter.d.ts +8 -0
- package/dist/zod/filters/zod-express-exception.filter.js +35 -0
- package/dist/zod/filters/zod-express-exception.filter.js.map +1 -0
- package/dist/zod/filters/zod-fastify-exception.filter.d.ts +8 -0
- package/dist/zod/filters/zod-fastify-exception.filter.js +35 -0
- package/dist/zod/filters/zod-fastify-exception.filter.js.map +1 -0
- package/dist/zod/filters/zod-validation-error-response.d.ts +6 -0
- package/dist/zod/filters/zod-validation-error-response.js +24 -0
- package/dist/zod/filters/zod-validation-error-response.js.map +1 -0
- package/dist/zod/index.d.ts +1 -0
- package/dist/zod/index.js +18 -0
- package/dist/zod/index.js.map +1 -0
- package/package.json +63 -3
- package/dist/common/filters/index.d.ts +0 -1
- package/dist/common/filters/index.js.map +0 -1
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.OutboxService = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const typeorm_1 = require("typeorm");
|
|
18
|
+
const entities_1 = require("../entities");
|
|
19
|
+
const enums_1 = require("../enums");
|
|
20
|
+
const outbox_constants_1 = require("../outbox.constants");
|
|
21
|
+
let OutboxService = class OutboxService {
|
|
22
|
+
constructor(outboxRepository, options) {
|
|
23
|
+
this.outboxRepository = outboxRepository;
|
|
24
|
+
this.options = options;
|
|
25
|
+
}
|
|
26
|
+
getOperationalPolicy() {
|
|
27
|
+
return this.options.operationalPolicy;
|
|
28
|
+
}
|
|
29
|
+
async createEvent(eventType, payload, manager) {
|
|
30
|
+
const repo = manager
|
|
31
|
+
? manager.getRepository(entities_1.OutboxEvent)
|
|
32
|
+
: this.outboxRepository;
|
|
33
|
+
const event = repo.create({
|
|
34
|
+
eventType,
|
|
35
|
+
payload,
|
|
36
|
+
status: enums_1.OutboxEventStatus.PENDING,
|
|
37
|
+
});
|
|
38
|
+
return repo.save(event);
|
|
39
|
+
}
|
|
40
|
+
async claimById(eventId) {
|
|
41
|
+
return this.outboxRepository.manager.transaction(async (manager) => {
|
|
42
|
+
const processingStartedAt = new Date();
|
|
43
|
+
const result = await manager
|
|
44
|
+
.createQueryBuilder()
|
|
45
|
+
.update(entities_1.OutboxEvent)
|
|
46
|
+
.set({
|
|
47
|
+
status: enums_1.OutboxEventStatus.PROCESSING,
|
|
48
|
+
processingStartedAt,
|
|
49
|
+
})
|
|
50
|
+
.where('id = :id', { id: eventId })
|
|
51
|
+
.andWhere('status = :status', { status: enums_1.OutboxEventStatus.PENDING })
|
|
52
|
+
.execute();
|
|
53
|
+
if (!result.affected) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
return manager.findOne(entities_1.OutboxEvent, { where: { id: eventId } });
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
async claimPendingEventsByTypes(eventTypes, limit = this.options.operationalPolicy.claimBatchSize) {
|
|
60
|
+
if (eventTypes.length === 0) {
|
|
61
|
+
return [];
|
|
62
|
+
}
|
|
63
|
+
return this.outboxRepository.manager.transaction(async (manager) => {
|
|
64
|
+
const events = await manager
|
|
65
|
+
.createQueryBuilder(entities_1.OutboxEvent, 'outbox')
|
|
66
|
+
.where('outbox.status = :status', { status: enums_1.OutboxEventStatus.PENDING })
|
|
67
|
+
.andWhere('outbox.eventType IN (:...eventTypes)', { eventTypes })
|
|
68
|
+
.orderBy('outbox.createdAt', 'ASC')
|
|
69
|
+
.limit(limit)
|
|
70
|
+
.setLock('pessimistic_write')
|
|
71
|
+
.setOnLocked('skip_locked')
|
|
72
|
+
.getMany();
|
|
73
|
+
if (events.length > 0) {
|
|
74
|
+
const eventIds = events.map((e) => e.id);
|
|
75
|
+
const processingStartedAt = new Date();
|
|
76
|
+
await manager
|
|
77
|
+
.createQueryBuilder()
|
|
78
|
+
.update(entities_1.OutboxEvent)
|
|
79
|
+
.set({
|
|
80
|
+
status: enums_1.OutboxEventStatus.PROCESSING,
|
|
81
|
+
processingStartedAt,
|
|
82
|
+
})
|
|
83
|
+
.whereInIds(eventIds)
|
|
84
|
+
.execute();
|
|
85
|
+
events.forEach((e) => {
|
|
86
|
+
e.status = enums_1.OutboxEventStatus.PROCESSING;
|
|
87
|
+
e.processingStartedAt = processingStartedAt;
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
return events;
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
async claimPendingEvents(eventType, limit = this.options.operationalPolicy.claimBatchSize) {
|
|
94
|
+
return this.outboxRepository.manager.transaction(async (manager) => {
|
|
95
|
+
// Fetch pending events with pessimistic lock
|
|
96
|
+
const events = await manager
|
|
97
|
+
.createQueryBuilder(entities_1.OutboxEvent, 'outbox')
|
|
98
|
+
.where('outbox.status = :status', { status: enums_1.OutboxEventStatus.PENDING })
|
|
99
|
+
.andWhere('outbox.eventType = :eventType', { eventType })
|
|
100
|
+
.orderBy('outbox.createdAt', 'ASC')
|
|
101
|
+
.limit(limit)
|
|
102
|
+
.setLock('pessimistic_write')
|
|
103
|
+
.setOnLocked('skip_locked')
|
|
104
|
+
.getMany();
|
|
105
|
+
// Immediately mark as PROCESSING while we hold the lock
|
|
106
|
+
if (events.length > 0) {
|
|
107
|
+
const eventIds = events.map((e) => e.id);
|
|
108
|
+
const processingStartedAt = new Date();
|
|
109
|
+
await manager
|
|
110
|
+
.createQueryBuilder()
|
|
111
|
+
.update(entities_1.OutboxEvent)
|
|
112
|
+
.set({
|
|
113
|
+
status: enums_1.OutboxEventStatus.PROCESSING,
|
|
114
|
+
processingStartedAt,
|
|
115
|
+
})
|
|
116
|
+
.whereInIds(eventIds)
|
|
117
|
+
.execute();
|
|
118
|
+
// Update the in-memory objects too
|
|
119
|
+
events.forEach((e) => {
|
|
120
|
+
e.status = enums_1.OutboxEventStatus.PROCESSING;
|
|
121
|
+
e.processingStartedAt = processingStartedAt;
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
return events;
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
async markAsProcessing(eventId) {
|
|
128
|
+
await this.outboxRepository.update(eventId, {
|
|
129
|
+
status: enums_1.OutboxEventStatus.PROCESSING,
|
|
130
|
+
processingStartedAt: new Date(),
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
async markAsProcessed(eventId, expectedProcessingStartedAt) {
|
|
134
|
+
return this.updateEvent(eventId, {
|
|
135
|
+
status: enums_1.OutboxEventStatus.PROCESSED,
|
|
136
|
+
processingStartedAt: null,
|
|
137
|
+
processedAt: new Date(),
|
|
138
|
+
}, expectedProcessingStartedAt);
|
|
139
|
+
}
|
|
140
|
+
async incrementRetry(eventId, error, maxRetries = this.options.operationalPolicy.maxRetries, expectedProcessingStartedAt) {
|
|
141
|
+
const event = await this.findEventForProcessingUpdate(eventId, expectedProcessingStartedAt);
|
|
142
|
+
if (!event) {
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
const newRetryCount = event.retryCount + 1;
|
|
146
|
+
if (newRetryCount >= maxRetries) {
|
|
147
|
+
return this.updateEvent(eventId, {
|
|
148
|
+
status: enums_1.OutboxEventStatus.FAILED,
|
|
149
|
+
lastError: error,
|
|
150
|
+
retryCount: newRetryCount,
|
|
151
|
+
processingStartedAt: null,
|
|
152
|
+
}, expectedProcessingStartedAt);
|
|
153
|
+
}
|
|
154
|
+
return this.updateEvent(eventId, {
|
|
155
|
+
status: enums_1.OutboxEventStatus.PENDING,
|
|
156
|
+
lastError: error,
|
|
157
|
+
retryCount: newRetryCount,
|
|
158
|
+
processingStartedAt: null,
|
|
159
|
+
}, expectedProcessingStartedAt);
|
|
160
|
+
}
|
|
161
|
+
async markAsFailed(eventId, error, expectedProcessingStartedAt) {
|
|
162
|
+
const event = await this.findEventForProcessingUpdate(eventId, expectedProcessingStartedAt);
|
|
163
|
+
return this.updateEvent(eventId, {
|
|
164
|
+
status: enums_1.OutboxEventStatus.FAILED,
|
|
165
|
+
lastError: error,
|
|
166
|
+
retryCount: event?.retryCount || 0,
|
|
167
|
+
processingStartedAt: null,
|
|
168
|
+
}, expectedProcessingStartedAt);
|
|
169
|
+
}
|
|
170
|
+
async deleteProcessed(olderThanHours = this.options.operationalPolicy
|
|
171
|
+
.processedEventRetentionHours) {
|
|
172
|
+
const threshold = new Date(Date.now() - olderThanHours * 60 * 60 * 1000);
|
|
173
|
+
const result = await this.outboxRepository
|
|
174
|
+
.createQueryBuilder()
|
|
175
|
+
.delete()
|
|
176
|
+
.where('status = :status', { status: enums_1.OutboxEventStatus.PROCESSED })
|
|
177
|
+
.andWhere('processed_at < :threshold', { threshold })
|
|
178
|
+
.execute();
|
|
179
|
+
return result.affected || 0;
|
|
180
|
+
}
|
|
181
|
+
async resetStaleProcessingEvents(staleMinutes = this.options.operationalPolicy.staleProcessingMinutes) {
|
|
182
|
+
const staleThreshold = new Date(Date.now() - staleMinutes * 60 * 1000);
|
|
183
|
+
const result = await this.outboxRepository
|
|
184
|
+
.createQueryBuilder()
|
|
185
|
+
.update(entities_1.OutboxEvent)
|
|
186
|
+
.set({
|
|
187
|
+
status: enums_1.OutboxEventStatus.PENDING,
|
|
188
|
+
processingStartedAt: null,
|
|
189
|
+
})
|
|
190
|
+
.where('status = :status', { status: enums_1.OutboxEventStatus.PROCESSING })
|
|
191
|
+
.andWhere('processing_started_at < :staleThreshold', { staleThreshold })
|
|
192
|
+
.execute();
|
|
193
|
+
return result.affected || 0;
|
|
194
|
+
}
|
|
195
|
+
async findEventForProcessingUpdate(eventId, expectedProcessingStartedAt) {
|
|
196
|
+
const query = this.outboxRepository
|
|
197
|
+
.createQueryBuilder('outbox')
|
|
198
|
+
.where('outbox.id = :eventId', { eventId });
|
|
199
|
+
this.addProcessingOwnershipCondition(query, expectedProcessingStartedAt);
|
|
200
|
+
return query.getOne();
|
|
201
|
+
}
|
|
202
|
+
async updateEvent(eventId, values, expectedProcessingStartedAt) {
|
|
203
|
+
const query = this.outboxRepository
|
|
204
|
+
.createQueryBuilder()
|
|
205
|
+
.update(entities_1.OutboxEvent)
|
|
206
|
+
.set(values)
|
|
207
|
+
.where('id = :eventId', { eventId });
|
|
208
|
+
this.addProcessingOwnershipCondition(query, expectedProcessingStartedAt);
|
|
209
|
+
const result = await query.execute();
|
|
210
|
+
return Boolean(result.affected);
|
|
211
|
+
}
|
|
212
|
+
addProcessingOwnershipCondition(query, expectedProcessingStartedAt) {
|
|
213
|
+
if (expectedProcessingStartedAt === undefined) {
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
query.andWhere('status = :processingStatus', {
|
|
217
|
+
processingStatus: enums_1.OutboxEventStatus.PROCESSING,
|
|
218
|
+
});
|
|
219
|
+
if (expectedProcessingStartedAt === null) {
|
|
220
|
+
query.andWhere('processing_started_at IS NULL');
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
query.andWhere('processing_started_at = :expectedProcessingStartedAt', {
|
|
224
|
+
expectedProcessingStartedAt,
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
exports.OutboxService = OutboxService;
|
|
229
|
+
exports.OutboxService = OutboxService = __decorate([
|
|
230
|
+
(0, common_1.Injectable)(),
|
|
231
|
+
__param(0, (0, common_1.Inject)(outbox_constants_1.OUTBOX_EVENT_REPOSITORY)),
|
|
232
|
+
__param(1, (0, common_1.Inject)(outbox_constants_1.OUTBOX_MODULE_OPTIONS)),
|
|
233
|
+
__metadata("design:paramtypes", [typeorm_1.Repository, Object])
|
|
234
|
+
], OutboxService);
|
|
235
|
+
//# sourceMappingURL=outbox.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"outbox.service.js","sourceRoot":"","sources":["../../../../src/modules/outbox/services/outbox.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAoD;AACpD,qCAAoD;AACpD,0CAA0C;AAC1C,oCAA6C;AAE7C,0DAG6B;AAGtB,IAAM,aAAa,GAAnB,MAAM,aAAa;IACxB,YAEmB,gBAAyC,EAEzC,OAAoC;QAFpC,qBAAgB,GAAhB,gBAAgB,CAAyB;QAEzC,YAAO,GAAP,OAAO,CAA6B;IACpD,CAAC;IAEJ,oBAAoB;QAClB,OAAO,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC;IACxC,CAAC;IAED,KAAK,CAAC,WAAW,CACf,SAAiB,EACjB,OAA4B,EAC5B,OAAuB;QAEvB,MAAM,IAAI,GAAG,OAAO;YAClB,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,sBAAW,CAAC;YACpC,C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AE;YAC3C,gBAAgB,EAAE,yBAAiB,CAAC,UAAU;SAC/C,CAAC,CAAC;QAEH,IAAI,2BAA2B,KAAK,IAAI,EAAE,CAAC;YACzC,KAAK,CAAC,QAAQ,CAAC,+BAA+B,CAAC,CAAC;YAEhD,OAAO;QACT,CAAC;QAED,KAAK,CAAC,QAAQ,CAAC,sDAAsD,EAAE;YACrE,2BAA2B;SAC5B,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AA1TY,sCAAa;wBAAb,aAAa;IADzB,IAAA,mBAAU,GAAE;IAGR,WAAA,IAAA,eAAM,EAAC,0CAAuB,CAAC,CAAA;IAE/B,WAAA,IAAA,eAAM,EAAC,wCAAqB,CAAC,CAAA;qCADK,oBAAU;GAHpC,aAAa,CA0TzB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './outbox-module-options.interface';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./outbox-module-options.interface"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/modules/outbox/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oEAAkD"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ModuleMetadata } from '@nestjs/common';
|
|
2
|
+
import type { DataSource, DataSourceOptions } from 'typeorm';
|
|
3
|
+
export type OutboxDataSource = DataSource | DataSourceOptions | string;
|
|
4
|
+
export interface OutboxOperationalPolicy {
|
|
5
|
+
claimBatchSize?: number;
|
|
6
|
+
maxRetries?: number;
|
|
7
|
+
staleProcessingMinutes?: number;
|
|
8
|
+
resetStaleProcessingEvents?: boolean;
|
|
9
|
+
maxConcurrentEvents?: number;
|
|
10
|
+
processedEventRetentionHours?: number;
|
|
11
|
+
}
|
|
12
|
+
export interface OutboxResolvedOperationalPolicy {
|
|
13
|
+
claimBatchSize: number;
|
|
14
|
+
maxRetries: number;
|
|
15
|
+
staleProcessingMinutes: number;
|
|
16
|
+
resetStaleProcessingEvents: boolean;
|
|
17
|
+
maxConcurrentEvents?: number;
|
|
18
|
+
processedEventRetentionHours: number;
|
|
19
|
+
}
|
|
20
|
+
export interface OutboxModuleOptions {
|
|
21
|
+
operationalPolicy?: OutboxOperationalPolicy;
|
|
22
|
+
}
|
|
23
|
+
export interface OutboxModuleRootOptions extends OutboxModuleOptions {
|
|
24
|
+
dataSource?: OutboxDataSource;
|
|
25
|
+
global?: boolean;
|
|
26
|
+
}
|
|
27
|
+
export interface OutboxModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
|
|
28
|
+
useFactory: (...args: any[]) => Promise<OutboxModuleOptions> | OutboxModuleOptions;
|
|
29
|
+
inject?: any[];
|
|
30
|
+
dataSource?: OutboxDataSource;
|
|
31
|
+
global?: boolean;
|
|
32
|
+
}
|
|
33
|
+
export interface OutboxResolvedModuleOptions {
|
|
34
|
+
operationalPolicy: OutboxResolvedOperationalPolicy;
|
|
35
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"outbox-module-options.interface.js","sourceRoot":"","sources":["../../../../src/modules/outbox/types/outbox-module-options.interface.ts"],"names":[],"mappings":""}
|
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
import type { TypeOrmModuleOptions } from '@nestjs/typeorm';
|
|
2
2
|
import { CommonTypeormConfigOptions } from './typeorm-options.util';
|
|
3
|
-
export interface
|
|
3
|
+
export interface PostgresTypeormDatabaseConnectionOptions {
|
|
4
|
+
host: string;
|
|
5
|
+
port?: number;
|
|
6
|
+
username: string;
|
|
7
|
+
password: string;
|
|
8
|
+
database: string;
|
|
9
|
+
}
|
|
10
|
+
export interface PostgresTypeormConfigOptions extends Omit<CommonTypeormConfigOptions, 'databaseUrl'> {
|
|
4
11
|
type?: 'postgres';
|
|
5
|
-
|
|
12
|
+
databaseUrl?: string;
|
|
13
|
+
database?: PostgresTypeormDatabaseConnectionOptions;
|
|
14
|
+
appName?: string;
|
|
6
15
|
schema?: string;
|
|
16
|
+
sslCa?: string;
|
|
7
17
|
queryTimeout?: number;
|
|
8
18
|
}
|
|
9
19
|
export declare function createPostgresTypeormOptions(options: PostgresTypeormConfigOptions): TypeOrmModuleOptions;
|
|
@@ -10,9 +10,12 @@ function createPostgresTypeormOptions(options) {
|
|
|
10
10
|
queryTimeout: 30_000,
|
|
11
11
|
...options,
|
|
12
12
|
};
|
|
13
|
+
const connectionOptions = createConnectionOptions(resolvedOptions);
|
|
14
|
+
const ssl = createSslOptions(resolvedOptions.sslCa);
|
|
13
15
|
return {
|
|
14
16
|
type: 'postgres',
|
|
15
|
-
|
|
17
|
+
...connectionOptions,
|
|
18
|
+
...(ssl ? { ssl } : {}),
|
|
16
19
|
autoLoadEntities: true,
|
|
17
20
|
schema: resolvedOptions.schema,
|
|
18
21
|
maxQueryExecutionTime: resolvedOptions.maxQueryExecutionTime,
|
|
@@ -28,9 +31,41 @@ function createPostgresTypeormOptions(options) {
|
|
|
28
31
|
connectionTimeoutMillis: 5000,
|
|
29
32
|
maxUses: 10000,
|
|
30
33
|
keepAlive: true,
|
|
31
|
-
|
|
34
|
+
...(resolvedOptions.appName
|
|
35
|
+
? { application_name: resolvedOptions.appName }
|
|
36
|
+
: {}),
|
|
32
37
|
query_timeout: resolvedOptions.queryTimeout,
|
|
33
38
|
},
|
|
34
39
|
};
|
|
35
40
|
}
|
|
41
|
+
function createConnectionOptions(options) {
|
|
42
|
+
if (options.database) {
|
|
43
|
+
return options.database;
|
|
44
|
+
}
|
|
45
|
+
if (!options.databaseUrl) {
|
|
46
|
+
throw new Error('databaseUrl or database connection options must be configured.');
|
|
47
|
+
}
|
|
48
|
+
const databaseUrl = encodeURI(options.databaseUrl);
|
|
49
|
+
return {
|
|
50
|
+
url: options.sslCa
|
|
51
|
+
? removeConnectionStringSslParams(databaseUrl)
|
|
52
|
+
: databaseUrl,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function createSslOptions(sslCa) {
|
|
56
|
+
if (!sslCa) {
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
ca: sslCa.replace(/\\n/g, '\n'),
|
|
61
|
+
rejectUnauthorized: true,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function removeConnectionStringSslParams(databaseUrl) {
|
|
65
|
+
const parsedUrl = new URL(databaseUrl);
|
|
66
|
+
for (const param of ['ssl', 'sslcert', 'sslkey', 'sslmode', 'sslrootcert']) {
|
|
67
|
+
parsedUrl.searchParams.delete(param);
|
|
68
|
+
}
|
|
69
|
+
return parsedUrl.toString();
|
|
70
|
+
}
|
|
36
71
|
//# sourceMappingURL=postgres-typeorm-options.factory.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres-typeorm-options.factory.js","sourceRoot":"","sources":["../../../src/typeorm/config/postgres-typeorm-options.factory.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"postgres-typeorm-options.factory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+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./zod-express-exception.filter"), exports);
|
|
18
|
+
__exportStar(require("./zod-fastify-exception.filter"), exports);
|
|
19
|
+
__exportStar(require("./zod-validation-error-response"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/zod/filters/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iEAA+C;AAC/C,iEAA+C;AAC/C,kEAAgD"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ArgumentsHost, ExceptionFilter } from '@nestjs/common';
|
|
2
|
+
import { ZodError } from 'zod';
|
|
3
|
+
import { ZodExceptionFilterOptions } from './zod-validation-error-response';
|
|
4
|
+
export declare class ZodExpressExceptionFilter implements ExceptionFilter<ZodError> {
|
|
5
|
+
private readonly options;
|
|
6
|
+
constructor(options?: ZodExceptionFilterOptions);
|
|
7
|
+
catch(exception: ZodError, host: ArgumentsHost): void;
|
|
8
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ZodExpressExceptionFilter = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const zod_1 = require("zod");
|
|
15
|
+
const zod_validation_error_response_1 = require("./zod-validation-error-response");
|
|
16
|
+
let ZodExpressExceptionFilter = class ZodExpressExceptionFilter {
|
|
17
|
+
constructor(options = {}) {
|
|
18
|
+
this.options = options;
|
|
19
|
+
}
|
|
20
|
+
catch(exception, host) {
|
|
21
|
+
if (host.getType() !== 'http') {
|
|
22
|
+
throw exception;
|
|
23
|
+
}
|
|
24
|
+
const response = host.switchToHttp().getResponse();
|
|
25
|
+
response
|
|
26
|
+
.status(common_1.HttpStatus.BAD_REQUEST)
|
|
27
|
+
.json((0, zod_validation_error_response_1.createZodValidationErrorResponse)(exception, this.options));
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
exports.ZodExpressExceptionFilter = ZodExpressExceptionFilter;
|
|
31
|
+
exports.ZodExpressExceptionFilter = ZodExpressExceptionFilter = __decorate([
|
|
32
|
+
(0, common_1.Catch)(zod_1.ZodError),
|
|
33
|
+
__metadata("design:paramtypes", [Object])
|
|
34
|
+
], ZodExpressExceptionFilter);
|
|
35
|
+
//# sourceMappingURL=zod-express-exception.filter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zod-express-exception.filter.js","sourceRoot":"","sources":["../../../src/zod/filters/zod-express-exception.filter.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAKwB;AAExB,6BAA+B;AAC/B,mFAGyC;AAGlC,IAAM,yBAAyB,GAA/B,MAAM,yBAAyB;IACpC,YAA6B,UAAqC,EAAE;QAAvC,YAAO,GAAP,OAAO,CAAgC;IAAG,CAAC;IAExE,KAAK,CAAC,SAAmB,EAAE,IAAmB;QAC5C,IAAI,IAAI,CAAC,OAAO,EAAE,KAAK,MAAM,EAAE,CAAC;YAC9B,MAAM,SAAS,CAAC;QAClB,CAAC;QAED,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC,WAAW,EAAY,CAAC;QAE7D,QAAQ;aACL,MAAM,CAAC,mBAAU,CAAC,WAAW,CAAC;aAC9B,IAAI,CAAC,IAAA,gEAAgC,EAAC,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IACrE,CAAC;CACF,CAAA;AAdY,8DAAyB;oCAAzB,yBAAyB;IADrC,IAAA,cAAK,EAAC,cAAQ,CAAC;;GACH,yBAAyB,CAcrC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ArgumentsHost, ExceptionFilter } from '@nestjs/common';
|
|
2
|
+
import { ZodError } from 'zod';
|
|
3
|
+
import { ZodExceptionFilterOptions } from './zod-validation-error-response';
|
|
4
|
+
export declare class ZodFastifyExceptionFilter implements ExceptionFilter<ZodError> {
|
|
5
|
+
private readonly options;
|
|
6
|
+
constructor(options?: ZodExceptionFilterOptions);
|
|
7
|
+
catch(exception: ZodError, host: ArgumentsHost): void;
|
|
8
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ZodFastifyExceptionFilter = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const zod_1 = require("zod");
|
|
15
|
+
const zod_validation_error_response_1 = require("./zod-validation-error-response");
|
|
16
|
+
let ZodFastifyExceptionFilter = class ZodFastifyExceptionFilter {
|
|
17
|
+
constructor(options = {}) {
|
|
18
|
+
this.options = options;
|
|
19
|
+
}
|
|
20
|
+
catch(exception, host) {
|
|
21
|
+
if (host.getType() !== 'http') {
|
|
22
|
+
throw exception;
|
|
23
|
+
}
|
|
24
|
+
const response = host.switchToHttp().getResponse();
|
|
25
|
+
response
|
|
26
|
+
.code(common_1.HttpStatus.BAD_REQUEST)
|
|
27
|
+
.send((0, zod_validation_error_response_1.createZodValidationErrorResponse)(exception, this.options));
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
exports.ZodFastifyExceptionFilter = ZodFastifyExceptionFilter;
|
|
31
|
+
exports.ZodFastifyExceptionFilter = ZodFastifyExceptionFilter = __decorate([
|
|
32
|
+
(0, common_1.Catch)(zod_1.ZodError),
|
|
33
|
+
__metadata("design:paramtypes", [Object])
|
|
34
|
+
], ZodFastifyExceptionFilter);
|
|
35
|
+
//# sourceMappingURL=zod-fastify-exception.filter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zod-fastify-exception.filter.js","sourceRoot":"","sources":["../../../src/zod/filters/zod-fastify-exception.filter.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAKwB;AAExB,6BAA+B;AAC/B,mFAGyC;AAGlC,IAAM,yBAAyB,GAA/B,MAAM,yBAAyB;IACpC,YAA6B,UAAqC,EAAE;QAAvC,YAAO,GAAP,OAAO,CAAgC;IAAG,CAAC;IAExE,KAAK,CAAC,SAAmB,EAAE,IAAmB;QAC5C,IAAI,IAAI,CAAC,OAAO,EAAE,KAAK,MAAM,EAAE,CAAC;YAC9B,MAAM,SAAS,CAAC;QAClB,CAAC;QAED,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC,WAAW,EAAgB,CAAC;QAEjE,QAAQ;aACL,IAAI,CAAC,mBAAU,CAAC,WAAW,CAAC;aAC5B,IAAI,CAAC,IAAA,gEAAgC,EAAC,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IACrE,CAAC;CACF,CAAA;AAdY,8DAAyB;oCAAzB,yBAAyB;IADrC,IAAA,cAAK,EAAC,cAAQ,CAAC;;GACH,yBAAyB,CAcrC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ZodError } from 'zod';
|
|
2
|
+
import type { ApiErrorResponse } from '../../errors';
|
|
3
|
+
export interface ZodExceptionFilterOptions {
|
|
4
|
+
message?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function createZodValidationErrorResponse(exception: ZodError, options?: ZodExceptionFilterOptions): ApiErrorResponse;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createZodValidationErrorResponse = createZodValidationErrorResponse;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const errors_1 = require("../../errors");
|
|
6
|
+
const DEFAULT_VALIDATION_ERROR_MESSAGE = 'Validation failed';
|
|
7
|
+
function createZodValidationErrorResponse(exception, options = {}) {
|
|
8
|
+
return (0, errors_1.createApiErrorResponse)({
|
|
9
|
+
statusCode: common_1.HttpStatus.BAD_REQUEST,
|
|
10
|
+
message: options.message ?? DEFAULT_VALIDATION_ERROR_MESSAGE,
|
|
11
|
+
code: errors_1.ApiErrorCode.VALIDATION_FAILED,
|
|
12
|
+
errors: exception.issues.map((issue) => ({
|
|
13
|
+
field: formatZodIssuePath(issue.path),
|
|
14
|
+
message: issue.message,
|
|
15
|
+
})),
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
function formatZodIssuePath(path) {
|
|
19
|
+
if (path.length === 0) {
|
|
20
|
+
return errors_1.API_ERROR_ROOT_FIELD;
|
|
21
|
+
}
|
|
22
|
+
return path.map(String).join('.');
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=zod-validation-error-response.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zod-validation-error-response.js","sourceRoot":"","sources":["../../../src/zod/filters/zod-validation-error-response.ts"],"names":[],"mappings":";;AAeA,4EAaC;AA5BD,2CAA4C;AAE5C,yCAIsB;AAOtB,MAAM,gCAAgC,GAAG,mBAAmB,CAAC;AAE7D,SAAgB,gCAAgC,CAC9C,SAAmB,EACnB,UAAqC,EAAE;IAEvC,OAAO,IAAA,+BAAsB,EAAC;QAC5B,UAAU,EAAE,mBAAU,CAAC,WAAW;QAClC,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,gCAAgC;QAC5D,IAAI,EAAE,qBAAY,CAAC,iBAAiB;QACpC,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;YACvC,KAAK,EAAE,kBAAkB,CAAC,KAAK,CAAC,IAAI,CAAC;YACrC,OAAO,EAAE,KAAK,CAAC,OAAO;SACvB,CAAC,CAAC;KACJ,CAAC,CAAC;AACL,CAAC;AAED,SAAS,kBAAkB,CACzB,IAA4B;IAE5B,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtB,OAAO,6BAAoB,CAAC;IAC9B,CAAC;IAED,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACpC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './filters';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./filters"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/zod/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B"}
|