wsp-ms-core 1.0.7 → 1.0.8-7.5
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/index.cjs +1525 -179
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +680 -0
- package/dist/index.d.ts +444 -65
- package/dist/index.js +1496 -179
- package/dist/index.js.map +1 -1
- package/package.json +17 -28
- package/dist/index.d.cts +0 -301
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,680 @@
|
|
|
1
|
+
import { RequestHandler, ErrorRequestHandler } from 'express';
|
|
2
|
+
import { Pool, RowDataPacket, PoolConnection } from 'mysql2/promise';
|
|
3
|
+
|
|
4
|
+
declare abstract class ValueObject<TPrimitive = unknown> {
|
|
5
|
+
protected readonly _value: TPrimitive;
|
|
6
|
+
protected constructor(value: TPrimitive);
|
|
7
|
+
protected abstract validate(value: TPrimitive): void;
|
|
8
|
+
abstract toPrimitives(): Record<string, unknown>;
|
|
9
|
+
toProps(): TPrimitive;
|
|
10
|
+
get value(): TPrimitive;
|
|
11
|
+
toString(): string;
|
|
12
|
+
equals(vo?: ValueObject<TPrimitive> | null): boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
declare class DateTime extends ValueObject<string> {
|
|
16
|
+
static readonly DEFAULT_FORMAT: string;
|
|
17
|
+
static readonly FORMAT: string;
|
|
18
|
+
static readonly FORMAT_Y_M = "Y-M";
|
|
19
|
+
static readonly FORMAT_Y_M_D = "Y-M-D";
|
|
20
|
+
static readonly FORMAT_Y_M_D_H_m_s = "Y-M-D H:M:S";
|
|
21
|
+
static readonly FORMAT_D_M_Y = "D-M-Y";
|
|
22
|
+
private static readonly FORMATS;
|
|
23
|
+
private readonly _dt;
|
|
24
|
+
private static fromLuxon;
|
|
25
|
+
private static toUtcFormat;
|
|
26
|
+
private constructor();
|
|
27
|
+
protected validate(value: string): void;
|
|
28
|
+
plusYears(years: number): DateTime;
|
|
29
|
+
plusMonths(months: number): DateTime;
|
|
30
|
+
plusDays(days: number): DateTime;
|
|
31
|
+
plusHours(hours: number): DateTime;
|
|
32
|
+
plusMinutes(minutes: number): DateTime;
|
|
33
|
+
plusSeconds(seconds: number): DateTime;
|
|
34
|
+
minusYears(years: number): DateTime;
|
|
35
|
+
minusMonths(months: number): DateTime;
|
|
36
|
+
minusDays(days: number): DateTime;
|
|
37
|
+
minusHours(hours: number): DateTime;
|
|
38
|
+
minusMinutes(minutes: number): DateTime;
|
|
39
|
+
minusSeconds(seconds: number): DateTime;
|
|
40
|
+
get year(): number;
|
|
41
|
+
get month(): number;
|
|
42
|
+
get day(): number;
|
|
43
|
+
get hour(): number;
|
|
44
|
+
get minute(): number;
|
|
45
|
+
get second(): number;
|
|
46
|
+
getMonthName(locale?: string): string;
|
|
47
|
+
getWeekdayName(locale?: string): string;
|
|
48
|
+
getDayName(locale?: string): string;
|
|
49
|
+
format(format: string): string;
|
|
50
|
+
toPrimitives(): Record<string, unknown>;
|
|
51
|
+
static create(input?: string | number): DateTime;
|
|
52
|
+
static now(): DateTime;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
type UUIDVersion = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
|
|
56
|
+
interface UUIDValidationOptions {
|
|
57
|
+
/** Versiones permitidas (por defecto: 1–8) */
|
|
58
|
+
allowedVersions?: UUIDVersion[];
|
|
59
|
+
/** Permitir el NIL UUID "00000000-0000-0000-0000-000000000000" (por defecto: false) */
|
|
60
|
+
allowNil?: boolean;
|
|
61
|
+
}
|
|
62
|
+
declare class UUID extends ValueObject<string> {
|
|
63
|
+
static readonly NIL = "00000000-0000-0000-0000-000000000000";
|
|
64
|
+
private constructor();
|
|
65
|
+
protected validate(uuid: string): void;
|
|
66
|
+
toPrimitives(): Record<string, unknown>;
|
|
67
|
+
static create(uuid?: string): UUID;
|
|
68
|
+
static version(uuid: string): UUIDVersion | undefined;
|
|
69
|
+
static isNil(uuid: string): boolean;
|
|
70
|
+
static isRFCStyle(uuid: string): boolean;
|
|
71
|
+
static isValid(uuid: string, opts?: UUIDValidationOptions): boolean;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
declare abstract class BaseEvent {
|
|
75
|
+
protected readonly _tenantUuid: UUID;
|
|
76
|
+
protected readonly _version: string;
|
|
77
|
+
protected readonly _type: string;
|
|
78
|
+
protected readonly _payload: Record<string, unknown>;
|
|
79
|
+
protected readonly _occurredAt: DateTime;
|
|
80
|
+
protected constructor(tenantUuid: UUID, version: string, type: string, payload: Record<string, unknown>);
|
|
81
|
+
get tenantUuid(): UUID;
|
|
82
|
+
get version(): string;
|
|
83
|
+
get type(): string;
|
|
84
|
+
get payload(): Record<string, unknown>;
|
|
85
|
+
get ocurredAt(): DateTime;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
declare class DomainEvent extends BaseEvent {
|
|
89
|
+
protected readonly _aggregateUuid: UUID;
|
|
90
|
+
protected readonly _aggregateType: string;
|
|
91
|
+
protected constructor(tenantUuid: UUID, version: string, type: string, payload: Record<string, unknown>, aggregateUuid: UUID, aggregateType: string);
|
|
92
|
+
get aggregateUuid(): UUID;
|
|
93
|
+
get aggregateType(): string;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
interface BaseEntity {
|
|
97
|
+
uuid: UUID;
|
|
98
|
+
createdAt: DateTime;
|
|
99
|
+
updatedAt: DateTime;
|
|
100
|
+
deletedAt: DateTime | undefined;
|
|
101
|
+
}
|
|
102
|
+
declare abstract class DomainEntity<T extends BaseEntity> {
|
|
103
|
+
protected readonly props: T;
|
|
104
|
+
protected _events: DomainEvent[];
|
|
105
|
+
protected constructor(props: T);
|
|
106
|
+
protected recordEvent(event: DomainEvent): void;
|
|
107
|
+
protected touch(): void;
|
|
108
|
+
get uuid(): UUID;
|
|
109
|
+
get createdAt(): DateTime;
|
|
110
|
+
get updatedAt(): DateTime;
|
|
111
|
+
get deletedAt(): DateTime | undefined;
|
|
112
|
+
get isDeleted(): boolean;
|
|
113
|
+
pullEvents(): DomainEvent[];
|
|
114
|
+
abstract equals(entity?: DomainEntity<T>): boolean;
|
|
115
|
+
abstract toProps(): T;
|
|
116
|
+
abstract toPrimitives(): Record<string, unknown>;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
declare abstract class BaseObject<T = unknown> {
|
|
120
|
+
protected readonly props: T;
|
|
121
|
+
protected constructor(props: T);
|
|
122
|
+
abstract toProps(): T;
|
|
123
|
+
abstract toPrimitives(): Record<string, unknown>;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
declare abstract class DomainError extends Error {
|
|
127
|
+
readonly type: string;
|
|
128
|
+
protected constructor(type: string, message?: string);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
declare class FatalError extends DomainError {
|
|
132
|
+
constructor(type: string, message?: string);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
declare class InternalError extends DomainError {
|
|
136
|
+
constructor(type: string, message?: string);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
declare class UsageError extends DomainError {
|
|
140
|
+
readonly vars: Record<string, any>;
|
|
141
|
+
constructor(type: string, vars?: Record<string, any>);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
declare class PaymentGateway extends ValueObject<string> {
|
|
145
|
+
static readonly SUPPORTED: readonly string[];
|
|
146
|
+
private static readonly EXTERNALS;
|
|
147
|
+
static readonly MERCADOPAGO: PaymentGateway;
|
|
148
|
+
static readonly HANDY: PaymentGateway;
|
|
149
|
+
static readonly WONA_DEBIT: PaymentGateway;
|
|
150
|
+
static readonly WONA_CARD: PaymentGateway;
|
|
151
|
+
static readonly WONA_CASH: PaymentGateway;
|
|
152
|
+
static readonly WONA_TRANSFER: PaymentGateway;
|
|
153
|
+
static readonly WONA_MERCADOPAGO: PaymentGateway;
|
|
154
|
+
private constructor();
|
|
155
|
+
protected validate(value: string): void;
|
|
156
|
+
isExternal(): boolean;
|
|
157
|
+
get isMercadoPago(): boolean;
|
|
158
|
+
get isHandy(): boolean;
|
|
159
|
+
get isWonaDebit(): boolean;
|
|
160
|
+
get isWonaCard(): boolean;
|
|
161
|
+
get isWonaCash(): boolean;
|
|
162
|
+
get isWonaTransfer(): boolean;
|
|
163
|
+
get isWonaMercadoPago(): boolean;
|
|
164
|
+
toPrimitives(): Record<string, unknown>;
|
|
165
|
+
static create(gateway: string): PaymentGateway;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
declare class PaymentStatus extends ValueObject<string> {
|
|
169
|
+
static readonly SUPPORTED: readonly string[];
|
|
170
|
+
static readonly DONE: PaymentStatus;
|
|
171
|
+
static readonly PENDING: PaymentStatus;
|
|
172
|
+
static readonly IN_PROGRESS: PaymentStatus;
|
|
173
|
+
static readonly FAILED: PaymentStatus;
|
|
174
|
+
static readonly CANCELED: PaymentStatus;
|
|
175
|
+
static readonly HOLD: PaymentStatus;
|
|
176
|
+
static readonly PENDING_REFUND: PaymentStatus;
|
|
177
|
+
static readonly REFUNDED: PaymentStatus;
|
|
178
|
+
private constructor();
|
|
179
|
+
protected validate(status: string): void;
|
|
180
|
+
get isDone(): boolean;
|
|
181
|
+
get isPending(): boolean;
|
|
182
|
+
get isInProgress(): boolean;
|
|
183
|
+
get isFailed(): boolean;
|
|
184
|
+
get isCanceled(): boolean;
|
|
185
|
+
get isHold(): boolean;
|
|
186
|
+
get isPendingRefund(): boolean;
|
|
187
|
+
get isRefunded(): boolean;
|
|
188
|
+
toPrimitives(): Record<string, unknown>;
|
|
189
|
+
static create(gateway: string): PaymentStatus;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
declare class Country extends ValueObject<string> {
|
|
193
|
+
static COUNTRIES: {
|
|
194
|
+
[key: string]: {
|
|
195
|
+
alpha2: string;
|
|
196
|
+
alpha3: string;
|
|
197
|
+
numeric: string;
|
|
198
|
+
uuid: string;
|
|
199
|
+
phoneCode: string;
|
|
200
|
+
url: string;
|
|
201
|
+
};
|
|
202
|
+
};
|
|
203
|
+
private static readonly NAMES;
|
|
204
|
+
static readonly DEFAULT: Country;
|
|
205
|
+
static readonly ARGENTINA: Country;
|
|
206
|
+
static readonly ECUADOR: Country;
|
|
207
|
+
static readonly PERU: Country;
|
|
208
|
+
static readonly BRASIL: Country;
|
|
209
|
+
static readonly CHILE: Country;
|
|
210
|
+
static readonly VENEZUELA: Country;
|
|
211
|
+
static readonly COLOMBIA: Country;
|
|
212
|
+
static readonly BOLIVIA: Country;
|
|
213
|
+
static readonly PARAGUAY: Country;
|
|
214
|
+
static readonly USA: Country;
|
|
215
|
+
private readonly _name;
|
|
216
|
+
private readonly _alpha2;
|
|
217
|
+
private readonly _alpha3;
|
|
218
|
+
private readonly _numeric;
|
|
219
|
+
private readonly _uuid;
|
|
220
|
+
private readonly _phoneCode;
|
|
221
|
+
private readonly _url;
|
|
222
|
+
private constructor();
|
|
223
|
+
protected validate(country: string): void;
|
|
224
|
+
name(): string;
|
|
225
|
+
alpha2(): string;
|
|
226
|
+
alpha3(): string;
|
|
227
|
+
numeric(): string;
|
|
228
|
+
uuid(): string;
|
|
229
|
+
phoneCode(): string;
|
|
230
|
+
url(): string;
|
|
231
|
+
static findCountryByAlpha2(alpha2: string): Country;
|
|
232
|
+
static findCountryByUUID(uuid: string): Country;
|
|
233
|
+
static create(country: string): Country;
|
|
234
|
+
static createOrDefault(country: string): Country;
|
|
235
|
+
toPrimitives(): Record<string, unknown>;
|
|
236
|
+
static isValid(country: string): boolean;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
declare class Currency extends ValueObject<string> {
|
|
240
|
+
static readonly ALPHA_REGEX: RegExp;
|
|
241
|
+
static readonly NUM_REGEX: RegExp;
|
|
242
|
+
private static readonly ALPHA_TO_NUM;
|
|
243
|
+
private static readonly NUM_TO_ALPHA;
|
|
244
|
+
static readonly USD: Currency;
|
|
245
|
+
static readonly EUR: Currency;
|
|
246
|
+
static readonly UYU: Currency;
|
|
247
|
+
static readonly ARS: Currency;
|
|
248
|
+
static readonly BRL: Currency;
|
|
249
|
+
readonly numeric: number;
|
|
250
|
+
private constructor();
|
|
251
|
+
protected validate(alpha: string): void;
|
|
252
|
+
toPrimitives(): Record<string, unknown>;
|
|
253
|
+
static create(raw: string | number): Currency;
|
|
254
|
+
static isValid(raw: string | number): boolean;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
declare class Email extends ValueObject<string> {
|
|
258
|
+
static readonly REGEX: RegExp;
|
|
259
|
+
private constructor();
|
|
260
|
+
protected validate(value: string): void;
|
|
261
|
+
toPrimitives(): Record<string, unknown>;
|
|
262
|
+
static create(raw: string): Email;
|
|
263
|
+
static isValid(raw: string): boolean;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
declare class Language extends ValueObject<string> {
|
|
267
|
+
static readonly SUPPORTED: readonly string[];
|
|
268
|
+
static readonly DEFAULT: Language;
|
|
269
|
+
static readonly ENGLISH: Language;
|
|
270
|
+
static readonly ENGLISH_UNITED_STATES: Language;
|
|
271
|
+
static readonly ENGLISH_UNITED_KINGDOM: Language;
|
|
272
|
+
static readonly ENGLISH_AUSTRALIA: Language;
|
|
273
|
+
static readonly ENGLISH_CANADA: Language;
|
|
274
|
+
static readonly ENGLISH_NEW_ZEALAND: Language;
|
|
275
|
+
static readonly ENGLISH_IRELAND: Language;
|
|
276
|
+
static readonly ENGLISH_SOUTH_AFRICA: Language;
|
|
277
|
+
static readonly ENGLISH_JAMAICA: Language;
|
|
278
|
+
static readonly ENGLISH_BELIZE: Language;
|
|
279
|
+
static readonly ENGLISH_TRINIDAD: Language;
|
|
280
|
+
static readonly PORTUGUESE_BRAZIL: Language;
|
|
281
|
+
static readonly PORTUGUESE_PORTUGAL: Language;
|
|
282
|
+
static readonly SPANISH: Language;
|
|
283
|
+
static readonly SPANISH_ARGENTINA: Language;
|
|
284
|
+
static readonly SPANISH_GUATEMALA: Language;
|
|
285
|
+
static readonly SPANISH_COSTA_RICA: Language;
|
|
286
|
+
static readonly SPANISH_PANAMA: Language;
|
|
287
|
+
static readonly SPANISH_REPUBLICA_DOMINICANA: Language;
|
|
288
|
+
static readonly SPANISH_MEXICO: Language;
|
|
289
|
+
static readonly SPANISH_VENEZUELA: Language;
|
|
290
|
+
static readonly SPANISH_COLOMBIA: Language;
|
|
291
|
+
static readonly SPANISH_PERU: Language;
|
|
292
|
+
static readonly SPANISH_ECUADOR: Language;
|
|
293
|
+
static readonly SPANISH_CHILE: Language;
|
|
294
|
+
static readonly SPANISH_URUGUAY: Language;
|
|
295
|
+
static readonly SPANISH_PARAGUAY: Language;
|
|
296
|
+
static readonly SPANISH_BOLIVIA: Language;
|
|
297
|
+
static readonly SPANISH_EL_SALVADOR: Language;
|
|
298
|
+
static readonly SPANISH_HONDURAS: Language;
|
|
299
|
+
static readonly SPANISH_NICARAGUA: Language;
|
|
300
|
+
static readonly SPANISH_PUERTO_RICO: Language;
|
|
301
|
+
private constructor();
|
|
302
|
+
protected validate(value: string): void;
|
|
303
|
+
base(): string;
|
|
304
|
+
toPrimitives(): Record<string, unknown>;
|
|
305
|
+
static create(raw: string): Language;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
interface PriceProps {
|
|
309
|
+
amount: number;
|
|
310
|
+
currency: Currency;
|
|
311
|
+
}
|
|
312
|
+
declare class Price extends ValueObject<PriceProps> {
|
|
313
|
+
static readonly MIN_AMOUNT: number;
|
|
314
|
+
static readonly MAX_AMOUNT: number;
|
|
315
|
+
private constructor();
|
|
316
|
+
protected validate(props: {
|
|
317
|
+
amount: number;
|
|
318
|
+
currency: Currency;
|
|
319
|
+
}): void;
|
|
320
|
+
get amount(): number;
|
|
321
|
+
get currency(): Currency;
|
|
322
|
+
equals(other?: Price | null): boolean;
|
|
323
|
+
private assertSameCurrency;
|
|
324
|
+
add(other: Price): Price;
|
|
325
|
+
subtract(other: Price): Price;
|
|
326
|
+
toPrimitives(): Record<string, unknown>;
|
|
327
|
+
static create(amount: number, currency: Currency | string | number): Price;
|
|
328
|
+
static createFromPrimitives(data: Record<string, unknown>): Price;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
declare class ProcessStatus extends ValueObject<string> {
|
|
332
|
+
static readonly SUPPORTED: readonly string[];
|
|
333
|
+
static readonly PENDING: ProcessStatus;
|
|
334
|
+
static readonly PROCESSING: ProcessStatus;
|
|
335
|
+
static readonly PROCESSED: ProcessStatus;
|
|
336
|
+
static readonly FAILED: ProcessStatus;
|
|
337
|
+
static readonly DEAD: ProcessStatus;
|
|
338
|
+
private constructor();
|
|
339
|
+
protected validate(value: string): void;
|
|
340
|
+
toPrimitives(): Record<string, unknown>;
|
|
341
|
+
static create(status: string): ProcessStatus;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
declare class OutboxRecord {
|
|
345
|
+
private readonly _eventUuid;
|
|
346
|
+
private readonly _eventType;
|
|
347
|
+
private readonly _tenantUuid;
|
|
348
|
+
private readonly _aggregateUuid;
|
|
349
|
+
private readonly _aggregateType;
|
|
350
|
+
private readonly _topic;
|
|
351
|
+
private readonly _payload;
|
|
352
|
+
private _status;
|
|
353
|
+
private _attempts;
|
|
354
|
+
private _errorMessage;
|
|
355
|
+
private _publishedAt;
|
|
356
|
+
private _lastAttempt;
|
|
357
|
+
private readonly _createdAt;
|
|
358
|
+
constructor(eventUuid: UUID, eventType: string, tenantUuid: UUID, aggregateUuid: UUID, aggregateType: string, topic: string, payload: string, status: ProcessStatus, attempts: number, errorMessage: string | undefined, publishedAt: DateTime | undefined, lastAttempt: DateTime | undefined, createdAt?: DateTime);
|
|
359
|
+
get eventUuid(): UUID;
|
|
360
|
+
get tenantUuid(): UUID;
|
|
361
|
+
get aggregateUuid(): UUID;
|
|
362
|
+
get aggregateType(): string;
|
|
363
|
+
get eventType(): string;
|
|
364
|
+
get topic(): string;
|
|
365
|
+
get payload(): string;
|
|
366
|
+
get status(): ProcessStatus;
|
|
367
|
+
get attempts(): number;
|
|
368
|
+
get errorMessage(): string | undefined;
|
|
369
|
+
get publishedAt(): DateTime | undefined;
|
|
370
|
+
get lastAttempt(): DateTime | undefined;
|
|
371
|
+
get createdAt(): DateTime;
|
|
372
|
+
incrementAttempts(): void;
|
|
373
|
+
markProcessed(): void;
|
|
374
|
+
markProcessing(): void;
|
|
375
|
+
markWithError(error: string): void;
|
|
376
|
+
toPrimitives(): Record<string, unknown>;
|
|
377
|
+
static reconstitute(data: Record<string, any>): OutboxRecord;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
interface EventBusRepository {
|
|
381
|
+
create(event: OutboxRecord): Promise<void>;
|
|
382
|
+
update(event: OutboxRecord): Promise<void>;
|
|
383
|
+
listPending(limit: number): Promise<OutboxRecord[]>;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
declare class IntegrationEvent extends BaseEvent {
|
|
387
|
+
protected readonly _aggregateUuid: UUID;
|
|
388
|
+
protected readonly _aggregateType: string;
|
|
389
|
+
protected constructor(tenantUuid: UUID, version: string, type: string, payload: Record<string, unknown>, aggregateUuid: UUID, aggregateType: string);
|
|
390
|
+
get aggregateUuid(): UUID;
|
|
391
|
+
get aggregateType(): string;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
interface DatabaseConnector<C extends DatabaseConnection = DatabaseConnection> {
|
|
395
|
+
getConnection(options?: {
|
|
396
|
+
readonly?: boolean;
|
|
397
|
+
}): Promise<C>;
|
|
398
|
+
query(sql: string, params: any[]): Promise<any[]>;
|
|
399
|
+
closePool(): Promise<void>;
|
|
400
|
+
}
|
|
401
|
+
interface DatabaseConnection<Q = string, Params = unknown[], Row = Record<string, unknown>> {
|
|
402
|
+
query<T = Row>(statement: Q, params?: Params): Promise<T[]>;
|
|
403
|
+
begin(): Promise<void>;
|
|
404
|
+
commit(): Promise<void>;
|
|
405
|
+
rollback(toSavepoint?: string): Promise<void>;
|
|
406
|
+
transaction<T>(fn: (conn: this) => Promise<T>): Promise<T>;
|
|
407
|
+
close(): Promise<void>;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
interface UnitOfWork<C extends DatabaseConnection = DatabaseConnection> {
|
|
411
|
+
readonly connection: C;
|
|
412
|
+
execute<T>(fn: () => Promise<T>): Promise<T>;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
type MapperEvent = (event: BaseEvent) => OutboxRecord;
|
|
416
|
+
declare class EventBus {
|
|
417
|
+
private static readonly MAPPERS;
|
|
418
|
+
private readonly repository;
|
|
419
|
+
constructor(repository: EventBusRepository);
|
|
420
|
+
publish(event: BaseEvent): Promise<void>;
|
|
421
|
+
publishMany(events: BaseEvent[]): Promise<void>;
|
|
422
|
+
static addMapper(eventType: string, mapper: MapperEvent): void;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
declare class BasicUnitOfWork implements UnitOfWork {
|
|
426
|
+
readonly connection: DatabaseConnection;
|
|
427
|
+
constructor(conn: DatabaseConnection);
|
|
428
|
+
execute<T>(fn: () => Promise<T>): Promise<T>;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
declare class BasicUnitOfWorkFactory {
|
|
432
|
+
private readonly connector;
|
|
433
|
+
constructor(connector: DatabaseConnector);
|
|
434
|
+
create(): Promise<BasicUnitOfWork>;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
interface EventMessage {
|
|
438
|
+
topic: string;
|
|
439
|
+
producer: string;
|
|
440
|
+
tenant: UUID;
|
|
441
|
+
message: string;
|
|
442
|
+
}
|
|
443
|
+
interface EventManagerConnection {
|
|
444
|
+
userName: string;
|
|
445
|
+
password: string;
|
|
446
|
+
brokers: string[];
|
|
447
|
+
}
|
|
448
|
+
type RouteCallback = (e: EventMessage) => void;
|
|
449
|
+
interface RoutesCallbackList {
|
|
450
|
+
[key: string]: RouteCallback;
|
|
451
|
+
}
|
|
452
|
+
declare abstract class EventManager {
|
|
453
|
+
protected _connection: EventManagerConnection;
|
|
454
|
+
protected _topics: string[];
|
|
455
|
+
protected _callbackList: RoutesCallbackList;
|
|
456
|
+
protected _onStart: CallableFunction | null;
|
|
457
|
+
protected _onConnected: CallableFunction | null;
|
|
458
|
+
protected _onSubscribe: CallableFunction | null;
|
|
459
|
+
protected _onMessage: CallableFunction | null;
|
|
460
|
+
protected _onError: CallableFunction | null;
|
|
461
|
+
protected _onCrash: CallableFunction | null;
|
|
462
|
+
protected _onReconnect: CallableFunction | null;
|
|
463
|
+
protected constructor(connection: EventManagerConnection);
|
|
464
|
+
protected execRoute(topic: string, event: EventMessage): Promise<void>;
|
|
465
|
+
protected execCallback(callback: CallableFunction | null, data: any): Promise<void>;
|
|
466
|
+
abstract send(event: EventMessage): void;
|
|
467
|
+
abstract start(): void;
|
|
468
|
+
abstract restart(): void;
|
|
469
|
+
abstract stop(): void;
|
|
470
|
+
abstract pause(): void;
|
|
471
|
+
route(topic: string, callback: RouteCallback): void;
|
|
472
|
+
onStart(callback: CallableFunction): void;
|
|
473
|
+
onConnected(callback: CallableFunction): void;
|
|
474
|
+
onSubscribe(callback: CallableFunction): void;
|
|
475
|
+
onMessage(callback: CallableFunction): void;
|
|
476
|
+
onError(callback: CallableFunction): void;
|
|
477
|
+
onCrash(callback: CallableFunction): void;
|
|
478
|
+
onReconnect(callback: CallableFunction): void;
|
|
479
|
+
get topics(): string[];
|
|
480
|
+
get callbackList(): RoutesCallbackList;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
interface HttpRequest {
|
|
484
|
+
readonly headers: Record<string, string>;
|
|
485
|
+
readonly params: Record<string, string>;
|
|
486
|
+
readonly query: Record<string, unknown>;
|
|
487
|
+
readonly lang: string;
|
|
488
|
+
readonly body: any;
|
|
489
|
+
readonly files?: Record<string, UploadedFile | UploadedFile[]>;
|
|
490
|
+
}
|
|
491
|
+
interface HttpResponse {
|
|
492
|
+
statusCode: number;
|
|
493
|
+
body: any;
|
|
494
|
+
headers?: Record<string, string | number | readonly string[]>;
|
|
495
|
+
}
|
|
496
|
+
interface UploadedFile {
|
|
497
|
+
fieldName: string;
|
|
498
|
+
originalName: string;
|
|
499
|
+
encoding: string;
|
|
500
|
+
mimetype: string;
|
|
501
|
+
buffer: Buffer;
|
|
502
|
+
size: number;
|
|
503
|
+
}
|
|
504
|
+
interface HttpController {
|
|
505
|
+
handle(request: HttpRequest): Promise<HttpResponse>;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
interface Logger {
|
|
509
|
+
debug(type: string, message: string, meta?: Record<string, any>): void;
|
|
510
|
+
info(type: string, message: string, meta?: Record<string, any>): void;
|
|
511
|
+
warn(type: string, message: string, meta?: Record<string, any>): void;
|
|
512
|
+
error(type: string, message: string, meta?: Record<string, any>): void;
|
|
513
|
+
fatal(type: string, message: string, meta?: Record<string, any>): void;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
declare class InboxRecord {
|
|
517
|
+
private readonly _eventUuid;
|
|
518
|
+
private readonly _tenantUuid;
|
|
519
|
+
private readonly _topic;
|
|
520
|
+
private readonly _producer;
|
|
521
|
+
private readonly _payload;
|
|
522
|
+
private _status;
|
|
523
|
+
private _attempts;
|
|
524
|
+
private _errorMessage;
|
|
525
|
+
private _lastAttempt;
|
|
526
|
+
private _processedAt;
|
|
527
|
+
private readonly _createdAt;
|
|
528
|
+
constructor(eventUuid: UUID, tenantUuid: UUID, topic: string, producer: string, payload: string, status: ProcessStatus, attempts?: number, errorMessage?: string | undefined, lastAttempt?: DateTime | undefined, processedAt?: DateTime | undefined, createdAt?: DateTime);
|
|
529
|
+
get eventUuid(): UUID;
|
|
530
|
+
get tenantUuid(): UUID;
|
|
531
|
+
get topic(): string;
|
|
532
|
+
get producer(): string;
|
|
533
|
+
get payload(): string;
|
|
534
|
+
get status(): ProcessStatus;
|
|
535
|
+
get attempts(): number;
|
|
536
|
+
get errorMessage(): string | undefined;
|
|
537
|
+
get lastAttempt(): DateTime | undefined;
|
|
538
|
+
get processedAt(): DateTime | undefined;
|
|
539
|
+
get createdAt(): DateTime;
|
|
540
|
+
incrementAttempts(): void;
|
|
541
|
+
markProcessed(): void;
|
|
542
|
+
markProcessing(): void;
|
|
543
|
+
markWithError(error: string): void;
|
|
544
|
+
toPrimitives(): Record<string, unknown>;
|
|
545
|
+
static reconstitute(data: Record<string, any>): InboxRecord;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
interface ErrorTemplate {
|
|
549
|
+
type: string;
|
|
550
|
+
languages: Record<string, string>;
|
|
551
|
+
}
|
|
552
|
+
type ErrorManagerHandleResult = {
|
|
553
|
+
status: number | string;
|
|
554
|
+
message: string;
|
|
555
|
+
};
|
|
556
|
+
declare class ErrorManager {
|
|
557
|
+
private readonly logger;
|
|
558
|
+
private static readonly DEFAULT_MESSAGES;
|
|
559
|
+
static readonly APP_ERRORS: {
|
|
560
|
+
readonly UNDEFINED: "UNDEFINED_ERROR";
|
|
561
|
+
readonly PROCESS: "PROCESS_ERROR";
|
|
562
|
+
readonly DATABASE: "DATABASE_ERROR";
|
|
563
|
+
};
|
|
564
|
+
private static readonly TEMPLATES;
|
|
565
|
+
constructor(logger?: Logger | null);
|
|
566
|
+
private getDefaultMessage;
|
|
567
|
+
private onFatal;
|
|
568
|
+
private onInternal;
|
|
569
|
+
private onUsage;
|
|
570
|
+
private onUnknown;
|
|
571
|
+
handle(err: Error, lang: Language): ErrorManagerHandleResult;
|
|
572
|
+
static addTemplate(template: ErrorTemplate): void;
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
declare class EventBusMysqlRepository implements EventBusRepository {
|
|
576
|
+
private readonly connection;
|
|
577
|
+
constructor(connection: DatabaseConnection);
|
|
578
|
+
private recordToRowValues;
|
|
579
|
+
create(record: OutboxRecord): Promise<void>;
|
|
580
|
+
update(record: OutboxRecord): Promise<void>;
|
|
581
|
+
listPending(limit: number): Promise<OutboxRecord[]>;
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
declare function adaptExpressRoute(Controller: new () => HttpController): RequestHandler;
|
|
585
|
+
declare function adaptExpressErrorHandler(errorManager: ErrorManager): ErrorRequestHandler;
|
|
586
|
+
|
|
587
|
+
declare class HttpHealthCheckController implements HttpController {
|
|
588
|
+
handle(request: HttpRequest): Promise<HttpResponse>;
|
|
589
|
+
}
|
|
590
|
+
declare class HttpNotFoundController implements HttpController {
|
|
591
|
+
handle(request: HttpRequest): Promise<HttpResponse>;
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
declare class KafkaManager extends EventManager {
|
|
595
|
+
private readonly kafka;
|
|
596
|
+
private readonly consumer;
|
|
597
|
+
private readonly producer;
|
|
598
|
+
constructor(connection: EventManagerConnection);
|
|
599
|
+
private run;
|
|
600
|
+
send(e: EventMessage): Promise<void>;
|
|
601
|
+
start(autocommit?: boolean): Promise<void>;
|
|
602
|
+
pause(): Promise<void>;
|
|
603
|
+
restart(): Promise<void>;
|
|
604
|
+
stop(): Promise<void>;
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
declare class MysqlConnector implements DatabaseConnector<MysqlConnection> {
|
|
608
|
+
static readonly DEFAULT_POOL_SIZE: number;
|
|
609
|
+
private readonly _pool;
|
|
610
|
+
constructor(pool?: Pool);
|
|
611
|
+
private wrap;
|
|
612
|
+
query(sql: string, params?: any[]): Promise<any[]>;
|
|
613
|
+
getConnection(): Promise<MysqlConnection>;
|
|
614
|
+
closePool(): Promise<void>;
|
|
615
|
+
static ping(): Promise<boolean>;
|
|
616
|
+
}
|
|
617
|
+
declare class MysqlConnection implements DatabaseConnection<string, any[], RowDataPacket> {
|
|
618
|
+
private readonly _conn;
|
|
619
|
+
constructor(conn: PoolConnection);
|
|
620
|
+
query<R = RowDataPacket>(statement: string, params?: any[]): Promise<R[]>;
|
|
621
|
+
begin(): Promise<void>;
|
|
622
|
+
commit(): Promise<void>;
|
|
623
|
+
rollback(): Promise<void>;
|
|
624
|
+
transaction<T>(fn: (conn: this) => Promise<T>): Promise<T>;
|
|
625
|
+
close(): Promise<void>;
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
declare class DefaultMysqlOutboxRunner {
|
|
629
|
+
private readonly uowFactory;
|
|
630
|
+
private readonly eventManager;
|
|
631
|
+
private readonly interval;
|
|
632
|
+
private readonly maxEvents;
|
|
633
|
+
private errors;
|
|
634
|
+
constructor(uowFactory: BasicUnitOfWorkFactory, eventManager: EventManager);
|
|
635
|
+
private addError;
|
|
636
|
+
private logErrors;
|
|
637
|
+
private sleep;
|
|
638
|
+
private processOutboxRecord;
|
|
639
|
+
private process;
|
|
640
|
+
start(): Promise<void>;
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
declare class DefaultMysqlInboxRunner {
|
|
644
|
+
private readonly uowFactory;
|
|
645
|
+
private readonly eventManager;
|
|
646
|
+
private readonly interval;
|
|
647
|
+
private readonly maxEvents;
|
|
648
|
+
private topics;
|
|
649
|
+
constructor(uowFactory: BasicUnitOfWorkFactory, eventManager: EventManager);
|
|
650
|
+
private saveEvent;
|
|
651
|
+
subscribeTo(topic: string): void;
|
|
652
|
+
private process;
|
|
653
|
+
start(): Promise<void>;
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
interface ExchangeRatesProps {
|
|
657
|
+
base: Currency;
|
|
658
|
+
rates: Record<string, number>;
|
|
659
|
+
date: DateTime;
|
|
660
|
+
}
|
|
661
|
+
declare class ExchangeRates extends BaseObject<ExchangeRatesProps> {
|
|
662
|
+
constructor(props: ExchangeRatesProps);
|
|
663
|
+
private getRate;
|
|
664
|
+
get base(): Currency;
|
|
665
|
+
get rates(): Record<string, number>;
|
|
666
|
+
get date(): DateTime;
|
|
667
|
+
toProps(): ExchangeRatesProps;
|
|
668
|
+
toPrimitives(): Record<string, unknown>;
|
|
669
|
+
exchangeToBase(price: Price): Price;
|
|
670
|
+
static create(props: ExchangeRatesProps): ExchangeRates;
|
|
671
|
+
static createFromPrimitives(data: any): ExchangeRates;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
declare class StringVars {
|
|
675
|
+
static parse(str: string, ob: {
|
|
676
|
+
[key: string]: any;
|
|
677
|
+
}): string;
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
export { BaseEntity, BaseEvent, BaseObject, BasicUnitOfWork, BasicUnitOfWorkFactory, Country, Currency, DatabaseConnection, DatabaseConnector, DateTime, DefaultMysqlInboxRunner, DefaultMysqlOutboxRunner, DomainEntity, DomainError, DomainEvent, Email, ErrorManager, ErrorManagerHandleResult, ErrorTemplate, EventBus, EventBusMysqlRepository, EventBusRepository, EventManager, EventManagerConnection, EventMessage, ExchangeRates, FatalError, HttpController, HttpHealthCheckController, HttpNotFoundController, HttpRequest, HttpResponse, InboxRecord, IntegrationEvent, InternalError, KafkaManager, Language, Logger, MysqlConnection, MysqlConnector, OutboxRecord, PaymentGateway, PaymentStatus, Price, ProcessStatus, RouteCallback, RoutesCallbackList, StringVars, UUID, UnitOfWork, UploadedFile, UsageError, ValueObject, adaptExpressErrorHandler, adaptExpressRoute };
|