wsp-ms-core 1.0.6 → 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 +1521 -198
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +680 -0
- package/dist/index.d.ts +443 -71
- package/dist/index.js +1491 -196
- package/dist/index.js.map +1 -1
- package/package.json +17 -28
- package/dist/index.d.cts +0 -308
package/dist/index.d.ts
CHANGED
|
@@ -1,24 +1,25 @@
|
|
|
1
|
-
import { RowDataPacket, PoolConnection, Pool } from 'mysql2/promise';
|
|
2
1
|
import { RequestHandler, ErrorRequestHandler } from 'express';
|
|
2
|
+
import { Pool, RowDataPacket, PoolConnection } from 'mysql2/promise';
|
|
3
3
|
|
|
4
4
|
declare abstract class ValueObject<TPrimitive = unknown> {
|
|
5
5
|
protected readonly _value: TPrimitive;
|
|
6
6
|
protected constructor(value: TPrimitive);
|
|
7
7
|
protected abstract validate(value: TPrimitive): void;
|
|
8
|
+
abstract toPrimitives(): Record<string, unknown>;
|
|
9
|
+
toProps(): TPrimitive;
|
|
8
10
|
get value(): TPrimitive;
|
|
9
11
|
toString(): string;
|
|
10
12
|
equals(vo?: ValueObject<TPrimitive> | null): boolean;
|
|
11
13
|
}
|
|
12
14
|
|
|
13
|
-
declare class UUID extends ValueObject<string> {
|
|
14
|
-
private constructor();
|
|
15
|
-
protected validate(uuid: string): void;
|
|
16
|
-
static create(uuid?: string): UUID;
|
|
17
|
-
static isValid(uuid: string): boolean;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
15
|
declare class DateTime extends ValueObject<string> {
|
|
21
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;
|
|
22
23
|
private readonly _dt;
|
|
23
24
|
private static fromLuxon;
|
|
24
25
|
private static toUtcFormat;
|
|
@@ -44,42 +45,87 @@ declare class DateTime extends ValueObject<string> {
|
|
|
44
45
|
get second(): number;
|
|
45
46
|
getMonthName(locale?: string): string;
|
|
46
47
|
getWeekdayName(locale?: string): string;
|
|
48
|
+
getDayName(locale?: string): string;
|
|
49
|
+
format(format: string): string;
|
|
50
|
+
toPrimitives(): Record<string, unknown>;
|
|
47
51
|
static create(input?: string | number): DateTime;
|
|
52
|
+
static now(): DateTime;
|
|
48
53
|
}
|
|
49
54
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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> {
|
|
55
103
|
protected readonly props: T;
|
|
56
|
-
protected
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
deletedAt?: DateTime;
|
|
60
|
-
});
|
|
104
|
+
protected _events: DomainEvent[];
|
|
105
|
+
protected constructor(props: T);
|
|
106
|
+
protected recordEvent(event: DomainEvent): void;
|
|
61
107
|
protected touch(): void;
|
|
108
|
+
get uuid(): UUID;
|
|
62
109
|
get createdAt(): DateTime;
|
|
63
110
|
get updatedAt(): DateTime;
|
|
64
111
|
get deletedAt(): DateTime | undefined;
|
|
65
112
|
get isDeleted(): boolean;
|
|
113
|
+
pullEvents(): DomainEvent[];
|
|
66
114
|
abstract equals(entity?: DomainEntity<T>): boolean;
|
|
67
|
-
|
|
115
|
+
abstract toProps(): T;
|
|
68
116
|
abstract toPrimitives(): Record<string, unknown>;
|
|
69
117
|
}
|
|
70
118
|
|
|
71
|
-
declare abstract class
|
|
72
|
-
readonly
|
|
73
|
-
protected constructor(
|
|
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>;
|
|
74
124
|
}
|
|
75
125
|
|
|
76
|
-
declare abstract class
|
|
126
|
+
declare abstract class DomainError extends Error {
|
|
77
127
|
readonly type: string;
|
|
78
|
-
|
|
79
|
-
private readonly _payload;
|
|
80
|
-
protected constructor(payload: T);
|
|
81
|
-
get payload(): T;
|
|
82
|
-
get occurredAt(): DateTime;
|
|
128
|
+
protected constructor(type: string, message?: string);
|
|
83
129
|
}
|
|
84
130
|
|
|
85
131
|
declare class FatalError extends DomainError {
|
|
@@ -95,6 +141,101 @@ declare class UsageError extends DomainError {
|
|
|
95
141
|
constructor(type: string, vars?: Record<string, any>);
|
|
96
142
|
}
|
|
97
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
|
+
|
|
98
239
|
declare class Currency extends ValueObject<string> {
|
|
99
240
|
static readonly ALPHA_REGEX: RegExp;
|
|
100
241
|
static readonly NUM_REGEX: RegExp;
|
|
@@ -108,6 +249,7 @@ declare class Currency extends ValueObject<string> {
|
|
|
108
249
|
readonly numeric: number;
|
|
109
250
|
private constructor();
|
|
110
251
|
protected validate(alpha: string): void;
|
|
252
|
+
toPrimitives(): Record<string, unknown>;
|
|
111
253
|
static create(raw: string | number): Currency;
|
|
112
254
|
static isValid(raw: string | number): boolean;
|
|
113
255
|
}
|
|
@@ -116,6 +258,7 @@ declare class Email extends ValueObject<string> {
|
|
|
116
258
|
static readonly REGEX: RegExp;
|
|
117
259
|
private constructor();
|
|
118
260
|
protected validate(value: string): void;
|
|
261
|
+
toPrimitives(): Record<string, unknown>;
|
|
119
262
|
static create(raw: string): Email;
|
|
120
263
|
static isValid(raw: string): boolean;
|
|
121
264
|
}
|
|
@@ -158,39 +301,103 @@ declare class Language extends ValueObject<string> {
|
|
|
158
301
|
private constructor();
|
|
159
302
|
protected validate(value: string): void;
|
|
160
303
|
base(): string;
|
|
304
|
+
toPrimitives(): Record<string, unknown>;
|
|
161
305
|
static create(raw: string): Language;
|
|
162
306
|
}
|
|
163
307
|
|
|
164
|
-
|
|
308
|
+
interface PriceProps {
|
|
165
309
|
amount: number;
|
|
166
310
|
currency: Currency;
|
|
167
|
-
}
|
|
311
|
+
}
|
|
312
|
+
declare class Price extends ValueObject<PriceProps> {
|
|
168
313
|
static readonly MIN_AMOUNT: number;
|
|
169
|
-
readonly
|
|
170
|
-
readonly currency: Currency;
|
|
314
|
+
static readonly MAX_AMOUNT: number;
|
|
171
315
|
private constructor();
|
|
172
316
|
protected validate(props: {
|
|
173
317
|
amount: number;
|
|
174
318
|
currency: Currency;
|
|
175
319
|
}): void;
|
|
320
|
+
get amount(): number;
|
|
321
|
+
get currency(): Currency;
|
|
176
322
|
equals(other?: Price | null): boolean;
|
|
177
323
|
private assertSameCurrency;
|
|
178
324
|
add(other: Price): Price;
|
|
179
325
|
subtract(other: Price): Price;
|
|
326
|
+
toPrimitives(): Record<string, unknown>;
|
|
180
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;
|
|
181
342
|
}
|
|
182
343
|
|
|
183
|
-
|
|
184
|
-
|
|
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;
|
|
185
378
|
}
|
|
186
379
|
|
|
187
380
|
interface EventBusRepository {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
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;
|
|
192
392
|
}
|
|
193
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
|
+
}
|
|
194
401
|
interface DatabaseConnection<Q = string, Params = unknown[], Row = Record<string, unknown>> {
|
|
195
402
|
query<T = Row>(statement: Q, params?: Params): Promise<T[]>;
|
|
196
403
|
begin(): Promise<void>;
|
|
@@ -200,25 +407,83 @@ interface DatabaseConnection<Q = string, Params = unknown[], Row = Record<string
|
|
|
200
407
|
close(): Promise<void>;
|
|
201
408
|
}
|
|
202
409
|
|
|
203
|
-
interface
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
}): Promise<C>;
|
|
207
|
-
closePool(): Promise<void>;
|
|
410
|
+
interface UnitOfWork<C extends DatabaseConnection = DatabaseConnection> {
|
|
411
|
+
readonly connection: C;
|
|
412
|
+
execute<T>(fn: () => Promise<T>): Promise<T>;
|
|
208
413
|
}
|
|
209
414
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
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;
|
|
216
481
|
}
|
|
217
482
|
|
|
218
483
|
interface HttpRequest {
|
|
219
484
|
readonly headers: Record<string, string>;
|
|
220
485
|
readonly params: Record<string, string>;
|
|
221
|
-
readonly query: Record<string,
|
|
486
|
+
readonly query: Record<string, unknown>;
|
|
222
487
|
readonly lang: string;
|
|
223
488
|
readonly body: any;
|
|
224
489
|
readonly files?: Record<string, UploadedFile | UploadedFile[]>;
|
|
@@ -226,6 +491,7 @@ interface HttpRequest {
|
|
|
226
491
|
interface HttpResponse {
|
|
227
492
|
statusCode: number;
|
|
228
493
|
body: any;
|
|
494
|
+
headers?: Record<string, string | number | readonly string[]>;
|
|
229
495
|
}
|
|
230
496
|
interface UploadedFile {
|
|
231
497
|
fieldName: string;
|
|
@@ -239,6 +505,46 @@ interface HttpController {
|
|
|
239
505
|
handle(request: HttpRequest): Promise<HttpResponse>;
|
|
240
506
|
}
|
|
241
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
|
+
|
|
242
548
|
interface ErrorTemplate {
|
|
243
549
|
type: string;
|
|
244
550
|
languages: Record<string, string>;
|
|
@@ -266,15 +572,36 @@ declare class ErrorManager {
|
|
|
266
572
|
static addTemplate(template: ErrorTemplate): void;
|
|
267
573
|
}
|
|
268
574
|
|
|
269
|
-
declare class
|
|
270
|
-
private readonly
|
|
271
|
-
constructor(
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
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>;
|
|
278
605
|
}
|
|
279
606
|
|
|
280
607
|
declare class MysqlConnector implements DatabaseConnector<MysqlConnection> {
|
|
@@ -282,27 +609,72 @@ declare class MysqlConnector implements DatabaseConnector<MysqlConnection> {
|
|
|
282
609
|
private readonly _pool;
|
|
283
610
|
constructor(pool?: Pool);
|
|
284
611
|
private wrap;
|
|
612
|
+
query(sql: string, params?: any[]): Promise<any[]>;
|
|
285
613
|
getConnection(): Promise<MysqlConnection>;
|
|
286
614
|
closePool(): Promise<void>;
|
|
287
615
|
static ping(): Promise<boolean>;
|
|
288
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
|
+
}
|
|
289
627
|
|
|
290
|
-
declare
|
|
291
|
-
|
|
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
|
+
}
|
|
292
642
|
|
|
293
|
-
declare class
|
|
294
|
-
|
|
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>;
|
|
295
654
|
}
|
|
296
655
|
|
|
297
|
-
|
|
298
|
-
|
|
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;
|
|
299
672
|
}
|
|
300
673
|
|
|
301
|
-
declare class
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
handle(request: HttpRequest): Promise<HttpResponse>;
|
|
674
|
+
declare class StringVars {
|
|
675
|
+
static parse(str: string, ob: {
|
|
676
|
+
[key: string]: any;
|
|
677
|
+
}): string;
|
|
306
678
|
}
|
|
307
679
|
|
|
308
|
-
export { Currency, DatabaseConnection, DatabaseConnector, DateTime, DomainEntity, DomainError, DomainEvent, Email, ErrorManager, ErrorManagerHandleResult, ErrorTemplate, EventBus, EventBusRepository, FatalError, HttpController,
|
|
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 };
|