wsp-ms-core 1.0.18 → 1.0.20
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.d.mts +125 -17
- package/dist/index.d.ts +125 -17
- package/dist/index.js +103 -63
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +100 -62
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -10
- package/dist/ErrorManager-b8cb2152.d.ts +0 -110
- package/dist/express.d.mts +0 -7
- package/dist/express.d.ts +0 -7
- package/dist/express.js +0 -177
- package/dist/express.js.map +0 -1
- package/dist/express.mjs +0 -150
- package/dist/express.mjs.map +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { Pool, RowDataPacket, PoolConnection } from 'mysql2/promise';
|
|
2
|
+
import { RequestHandler, ErrorRequestHandler } from 'express';
|
|
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
|
+
get value(): TPrimitive;
|
|
9
|
+
toString(): string;
|
|
10
|
+
equals(vo?: ValueObject<TPrimitive> | null): boolean;
|
|
11
|
+
}
|
|
4
12
|
|
|
5
13
|
declare class UUID extends ValueObject<string> {
|
|
6
14
|
private constructor();
|
|
@@ -112,6 +120,47 @@ declare class Email extends ValueObject<string> {
|
|
|
112
120
|
static isValid(raw: string): boolean;
|
|
113
121
|
}
|
|
114
122
|
|
|
123
|
+
declare class Language extends ValueObject<string> {
|
|
124
|
+
static readonly SUPPORTED: readonly string[];
|
|
125
|
+
static readonly DEFAULT: Language;
|
|
126
|
+
static readonly ENGLISH: Language;
|
|
127
|
+
static readonly ENGLISH_UNITED_STATES: Language;
|
|
128
|
+
static readonly ENGLISH_UNITED_KINGDOM: Language;
|
|
129
|
+
static readonly ENGLISH_AUSTRALIA: Language;
|
|
130
|
+
static readonly ENGLISH_CANADA: Language;
|
|
131
|
+
static readonly ENGLISH_NEW_ZEALAND: Language;
|
|
132
|
+
static readonly ENGLISH_IRELAND: Language;
|
|
133
|
+
static readonly ENGLISH_SOUTH_AFRICA: Language;
|
|
134
|
+
static readonly ENGLISH_JAMAICA: Language;
|
|
135
|
+
static readonly ENGLISH_BELIZE: Language;
|
|
136
|
+
static readonly ENGLISH_TRINIDAD: Language;
|
|
137
|
+
static readonly PORTUGUESE_BRAZIL: Language;
|
|
138
|
+
static readonly PORTUGUESE_PORTUGAL: Language;
|
|
139
|
+
static readonly SPANISH: Language;
|
|
140
|
+
static readonly SPANISH_ARGENTINA: Language;
|
|
141
|
+
static readonly SPANISH_GUATEMALA: Language;
|
|
142
|
+
static readonly SPANISH_COSTA_RICA: Language;
|
|
143
|
+
static readonly SPANISH_PANAMA: Language;
|
|
144
|
+
static readonly SPANISH_REPUBLICA_DOMINICANA: Language;
|
|
145
|
+
static readonly SPANISH_MEXICO: Language;
|
|
146
|
+
static readonly SPANISH_VENEZUELA: Language;
|
|
147
|
+
static readonly SPANISH_COLOMBIA: Language;
|
|
148
|
+
static readonly SPANISH_PERU: Language;
|
|
149
|
+
static readonly SPANISH_ECUADOR: Language;
|
|
150
|
+
static readonly SPANISH_CHILE: Language;
|
|
151
|
+
static readonly SPANISH_URUGUAY: Language;
|
|
152
|
+
static readonly SPANISH_PARAGUAY: Language;
|
|
153
|
+
static readonly SPANISH_BOLIVIA: Language;
|
|
154
|
+
static readonly SPANISH_EL_SALVADOR: Language;
|
|
155
|
+
static readonly SPANISH_HONDURAS: Language;
|
|
156
|
+
static readonly SPANISH_NICARAGUA: Language;
|
|
157
|
+
static readonly SPANISH_PUERTO_RICO: Language;
|
|
158
|
+
private constructor();
|
|
159
|
+
protected validate(value: string): void;
|
|
160
|
+
base(): string;
|
|
161
|
+
static create(raw: string): Language;
|
|
162
|
+
}
|
|
163
|
+
|
|
115
164
|
declare class Price extends ValueObject<{
|
|
116
165
|
amount: number;
|
|
117
166
|
currency: Currency;
|
|
@@ -150,7 +199,6 @@ interface DatabaseConnection<Q = string, Params = unknown[], Row = Record<string
|
|
|
150
199
|
transaction<T>(fn: (conn: this) => Promise<T>): Promise<T>;
|
|
151
200
|
close(): Promise<void>;
|
|
152
201
|
}
|
|
153
|
-
|
|
154
202
|
interface DatabaseConnector<C extends DatabaseConnection = DatabaseConnection> {
|
|
155
203
|
getConnection(options?: {
|
|
156
204
|
readonly?: boolean;
|
|
@@ -158,15 +206,63 @@ interface DatabaseConnector<C extends DatabaseConnection = DatabaseConnection> {
|
|
|
158
206
|
closePool(): Promise<void>;
|
|
159
207
|
}
|
|
160
208
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
209
|
+
interface Logger {
|
|
210
|
+
debug(type: string, message: string, meta?: Record<string, any>): void;
|
|
211
|
+
info(type: string, message: string, meta?: Record<string, any>): void;
|
|
212
|
+
warn(type: string, message: string, meta?: Record<string, any>): void;
|
|
213
|
+
error(type: string, message: string, meta?: Record<string, any>): void;
|
|
214
|
+
fatal(type: string, message: string, meta?: Record<string, any>): void;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
interface HttpRequest {
|
|
218
|
+
readonly headers: Record<string, string>;
|
|
219
|
+
readonly params: Record<string, string>;
|
|
220
|
+
readonly query: Record<string, string>;
|
|
221
|
+
readonly lang: string;
|
|
222
|
+
readonly body: any;
|
|
223
|
+
readonly files?: Record<string, UploadedFile | UploadedFile[]>;
|
|
224
|
+
}
|
|
225
|
+
interface HttpResponse {
|
|
226
|
+
statusCode: number;
|
|
227
|
+
body: any;
|
|
228
|
+
}
|
|
229
|
+
interface UploadedFile {
|
|
230
|
+
fieldName: string;
|
|
231
|
+
originalName: string;
|
|
232
|
+
encoding: string;
|
|
233
|
+
mimetype: string;
|
|
234
|
+
buffer: Buffer;
|
|
235
|
+
size: number;
|
|
236
|
+
}
|
|
237
|
+
interface HttpController {
|
|
238
|
+
handle(request: HttpRequest): Promise<HttpResponse>;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
interface ErrorTemplate {
|
|
242
|
+
type: string;
|
|
243
|
+
languages: Record<string, string>;
|
|
244
|
+
}
|
|
245
|
+
type ErrorManagerHandleResult = {
|
|
246
|
+
status: number | string;
|
|
247
|
+
message: string;
|
|
248
|
+
};
|
|
249
|
+
declare class ErrorManager {
|
|
250
|
+
private readonly logger;
|
|
251
|
+
private static readonly DEFAULT_MESSAGES;
|
|
252
|
+
static readonly APP_ERRORS: {
|
|
253
|
+
readonly UNDEFINED: "UNDEFINED_ERROR";
|
|
254
|
+
readonly PROCESS: "PROCESS_ERROR";
|
|
255
|
+
readonly DATABASE: "DATABASE_ERROR";
|
|
256
|
+
};
|
|
257
|
+
private static readonly TEMPLATES;
|
|
258
|
+
constructor(logger?: Logger | null);
|
|
259
|
+
private getDefaultMessage;
|
|
260
|
+
private onFatal;
|
|
261
|
+
private onInternal;
|
|
262
|
+
private onUsage;
|
|
263
|
+
private onUnknown;
|
|
264
|
+
handle(err: Error, lang: Language): ErrorManagerHandleResult;
|
|
265
|
+
static addTemplate(template: ErrorTemplate): void;
|
|
170
266
|
}
|
|
171
267
|
|
|
172
268
|
declare class MysqlConnector implements DatabaseConnector<MysqlConnection> {
|
|
@@ -178,13 +274,25 @@ declare class MysqlConnector implements DatabaseConnector<MysqlConnection> {
|
|
|
178
274
|
closePool(): Promise<void>;
|
|
179
275
|
static ping(): Promise<boolean>;
|
|
180
276
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
277
|
+
declare class MysqlConnection implements DatabaseConnection<string, any[], RowDataPacket> {
|
|
278
|
+
private readonly _conn;
|
|
279
|
+
constructor(conn: PoolConnection);
|
|
280
|
+
query<R = RowDataPacket>(statement: string, params?: any[]): Promise<R[]>;
|
|
281
|
+
begin(): Promise<void>;
|
|
282
|
+
commit(): Promise<void>;
|
|
283
|
+
rollback(): Promise<void>;
|
|
284
|
+
transaction<T>(fn: (conn: this) => Promise<T>): Promise<T>;
|
|
285
|
+
close(): Promise<void>;
|
|
184
286
|
}
|
|
185
287
|
|
|
186
288
|
declare class HttpHealthCheckController implements HttpController {
|
|
187
289
|
handle(request: HttpRequest): Promise<HttpResponse>;
|
|
188
290
|
}
|
|
291
|
+
declare class HttpNotFoundController implements HttpController {
|
|
292
|
+
handle(request: HttpRequest): Promise<HttpResponse>;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
declare function adaptExpressRoute(Controller: new () => HttpController): RequestHandler;
|
|
296
|
+
declare function adaptExpressErrorHandler(errorManager: ErrorManager): ErrorRequestHandler;
|
|
189
297
|
|
|
190
|
-
export { Currency, DatabaseConnection, DatabaseConnector, DateTime, DomainEntity, DomainError, DomainEvent, Email, EventBus, EventBusRepository, FatalError, HttpController, HttpHealthCheckController, HttpNotFoundController, HttpRequest, HttpResponse, InternalError, MysqlConnection, MysqlConnector, Price, UUID, UsageError, ValueObject };
|
|
298
|
+
export { Currency, DatabaseConnection, DatabaseConnector, DateTime, DomainEntity, DomainError, DomainEvent, Email, ErrorManager, ErrorManagerHandleResult, ErrorTemplate, EventBus, EventBusRepository, FatalError, HttpController, HttpHealthCheckController, HttpNotFoundController, HttpRequest, HttpResponse, InternalError, Language, Logger, MysqlConnection, MysqlConnector, Price, UUID, UploadedFile, UsageError, ValueObject, adaptExpressErrorHandler, adaptExpressRoute };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { Pool, RowDataPacket, PoolConnection } from 'mysql2/promise';
|
|
2
|
+
import { RequestHandler, ErrorRequestHandler } from 'express';
|
|
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
|
+
get value(): TPrimitive;
|
|
9
|
+
toString(): string;
|
|
10
|
+
equals(vo?: ValueObject<TPrimitive> | null): boolean;
|
|
11
|
+
}
|
|
4
12
|
|
|
5
13
|
declare class UUID extends ValueObject<string> {
|
|
6
14
|
private constructor();
|
|
@@ -112,6 +120,47 @@ declare class Email extends ValueObject<string> {
|
|
|
112
120
|
static isValid(raw: string): boolean;
|
|
113
121
|
}
|
|
114
122
|
|
|
123
|
+
declare class Language extends ValueObject<string> {
|
|
124
|
+
static readonly SUPPORTED: readonly string[];
|
|
125
|
+
static readonly DEFAULT: Language;
|
|
126
|
+
static readonly ENGLISH: Language;
|
|
127
|
+
static readonly ENGLISH_UNITED_STATES: Language;
|
|
128
|
+
static readonly ENGLISH_UNITED_KINGDOM: Language;
|
|
129
|
+
static readonly ENGLISH_AUSTRALIA: Language;
|
|
130
|
+
static readonly ENGLISH_CANADA: Language;
|
|
131
|
+
static readonly ENGLISH_NEW_ZEALAND: Language;
|
|
132
|
+
static readonly ENGLISH_IRELAND: Language;
|
|
133
|
+
static readonly ENGLISH_SOUTH_AFRICA: Language;
|
|
134
|
+
static readonly ENGLISH_JAMAICA: Language;
|
|
135
|
+
static readonly ENGLISH_BELIZE: Language;
|
|
136
|
+
static readonly ENGLISH_TRINIDAD: Language;
|
|
137
|
+
static readonly PORTUGUESE_BRAZIL: Language;
|
|
138
|
+
static readonly PORTUGUESE_PORTUGAL: Language;
|
|
139
|
+
static readonly SPANISH: Language;
|
|
140
|
+
static readonly SPANISH_ARGENTINA: Language;
|
|
141
|
+
static readonly SPANISH_GUATEMALA: Language;
|
|
142
|
+
static readonly SPANISH_COSTA_RICA: Language;
|
|
143
|
+
static readonly SPANISH_PANAMA: Language;
|
|
144
|
+
static readonly SPANISH_REPUBLICA_DOMINICANA: Language;
|
|
145
|
+
static readonly SPANISH_MEXICO: Language;
|
|
146
|
+
static readonly SPANISH_VENEZUELA: Language;
|
|
147
|
+
static readonly SPANISH_COLOMBIA: Language;
|
|
148
|
+
static readonly SPANISH_PERU: Language;
|
|
149
|
+
static readonly SPANISH_ECUADOR: Language;
|
|
150
|
+
static readonly SPANISH_CHILE: Language;
|
|
151
|
+
static readonly SPANISH_URUGUAY: Language;
|
|
152
|
+
static readonly SPANISH_PARAGUAY: Language;
|
|
153
|
+
static readonly SPANISH_BOLIVIA: Language;
|
|
154
|
+
static readonly SPANISH_EL_SALVADOR: Language;
|
|
155
|
+
static readonly SPANISH_HONDURAS: Language;
|
|
156
|
+
static readonly SPANISH_NICARAGUA: Language;
|
|
157
|
+
static readonly SPANISH_PUERTO_RICO: Language;
|
|
158
|
+
private constructor();
|
|
159
|
+
protected validate(value: string): void;
|
|
160
|
+
base(): string;
|
|
161
|
+
static create(raw: string): Language;
|
|
162
|
+
}
|
|
163
|
+
|
|
115
164
|
declare class Price extends ValueObject<{
|
|
116
165
|
amount: number;
|
|
117
166
|
currency: Currency;
|
|
@@ -150,7 +199,6 @@ interface DatabaseConnection<Q = string, Params = unknown[], Row = Record<string
|
|
|
150
199
|
transaction<T>(fn: (conn: this) => Promise<T>): Promise<T>;
|
|
151
200
|
close(): Promise<void>;
|
|
152
201
|
}
|
|
153
|
-
|
|
154
202
|
interface DatabaseConnector<C extends DatabaseConnection = DatabaseConnection> {
|
|
155
203
|
getConnection(options?: {
|
|
156
204
|
readonly?: boolean;
|
|
@@ -158,15 +206,63 @@ interface DatabaseConnector<C extends DatabaseConnection = DatabaseConnection> {
|
|
|
158
206
|
closePool(): Promise<void>;
|
|
159
207
|
}
|
|
160
208
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
209
|
+
interface Logger {
|
|
210
|
+
debug(type: string, message: string, meta?: Record<string, any>): void;
|
|
211
|
+
info(type: string, message: string, meta?: Record<string, any>): void;
|
|
212
|
+
warn(type: string, message: string, meta?: Record<string, any>): void;
|
|
213
|
+
error(type: string, message: string, meta?: Record<string, any>): void;
|
|
214
|
+
fatal(type: string, message: string, meta?: Record<string, any>): void;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
interface HttpRequest {
|
|
218
|
+
readonly headers: Record<string, string>;
|
|
219
|
+
readonly params: Record<string, string>;
|
|
220
|
+
readonly query: Record<string, string>;
|
|
221
|
+
readonly lang: string;
|
|
222
|
+
readonly body: any;
|
|
223
|
+
readonly files?: Record<string, UploadedFile | UploadedFile[]>;
|
|
224
|
+
}
|
|
225
|
+
interface HttpResponse {
|
|
226
|
+
statusCode: number;
|
|
227
|
+
body: any;
|
|
228
|
+
}
|
|
229
|
+
interface UploadedFile {
|
|
230
|
+
fieldName: string;
|
|
231
|
+
originalName: string;
|
|
232
|
+
encoding: string;
|
|
233
|
+
mimetype: string;
|
|
234
|
+
buffer: Buffer;
|
|
235
|
+
size: number;
|
|
236
|
+
}
|
|
237
|
+
interface HttpController {
|
|
238
|
+
handle(request: HttpRequest): Promise<HttpResponse>;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
interface ErrorTemplate {
|
|
242
|
+
type: string;
|
|
243
|
+
languages: Record<string, string>;
|
|
244
|
+
}
|
|
245
|
+
type ErrorManagerHandleResult = {
|
|
246
|
+
status: number | string;
|
|
247
|
+
message: string;
|
|
248
|
+
};
|
|
249
|
+
declare class ErrorManager {
|
|
250
|
+
private readonly logger;
|
|
251
|
+
private static readonly DEFAULT_MESSAGES;
|
|
252
|
+
static readonly APP_ERRORS: {
|
|
253
|
+
readonly UNDEFINED: "UNDEFINED_ERROR";
|
|
254
|
+
readonly PROCESS: "PROCESS_ERROR";
|
|
255
|
+
readonly DATABASE: "DATABASE_ERROR";
|
|
256
|
+
};
|
|
257
|
+
private static readonly TEMPLATES;
|
|
258
|
+
constructor(logger?: Logger | null);
|
|
259
|
+
private getDefaultMessage;
|
|
260
|
+
private onFatal;
|
|
261
|
+
private onInternal;
|
|
262
|
+
private onUsage;
|
|
263
|
+
private onUnknown;
|
|
264
|
+
handle(err: Error, lang: Language): ErrorManagerHandleResult;
|
|
265
|
+
static addTemplate(template: ErrorTemplate): void;
|
|
170
266
|
}
|
|
171
267
|
|
|
172
268
|
declare class MysqlConnector implements DatabaseConnector<MysqlConnection> {
|
|
@@ -178,13 +274,25 @@ declare class MysqlConnector implements DatabaseConnector<MysqlConnection> {
|
|
|
178
274
|
closePool(): Promise<void>;
|
|
179
275
|
static ping(): Promise<boolean>;
|
|
180
276
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
277
|
+
declare class MysqlConnection implements DatabaseConnection<string, any[], RowDataPacket> {
|
|
278
|
+
private readonly _conn;
|
|
279
|
+
constructor(conn: PoolConnection);
|
|
280
|
+
query<R = RowDataPacket>(statement: string, params?: any[]): Promise<R[]>;
|
|
281
|
+
begin(): Promise<void>;
|
|
282
|
+
commit(): Promise<void>;
|
|
283
|
+
rollback(): Promise<void>;
|
|
284
|
+
transaction<T>(fn: (conn: this) => Promise<T>): Promise<T>;
|
|
285
|
+
close(): Promise<void>;
|
|
184
286
|
}
|
|
185
287
|
|
|
186
288
|
declare class HttpHealthCheckController implements HttpController {
|
|
187
289
|
handle(request: HttpRequest): Promise<HttpResponse>;
|
|
188
290
|
}
|
|
291
|
+
declare class HttpNotFoundController implements HttpController {
|
|
292
|
+
handle(request: HttpRequest): Promise<HttpResponse>;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
declare function adaptExpressRoute(Controller: new () => HttpController): RequestHandler;
|
|
296
|
+
declare function adaptExpressErrorHandler(errorManager: ErrorManager): ErrorRequestHandler;
|
|
189
297
|
|
|
190
|
-
export { Currency, DatabaseConnection, DatabaseConnector, DateTime, DomainEntity, DomainError, DomainEvent, Email, EventBus, EventBusRepository, FatalError, HttpController, HttpHealthCheckController, HttpNotFoundController, HttpRequest, HttpResponse, InternalError, MysqlConnection, MysqlConnector, Price, UUID, UsageError, ValueObject };
|
|
298
|
+
export { Currency, DatabaseConnection, DatabaseConnector, DateTime, DomainEntity, DomainError, DomainEvent, Email, ErrorManager, ErrorManagerHandleResult, ErrorTemplate, EventBus, EventBusRepository, FatalError, HttpController, HttpHealthCheckController, HttpNotFoundController, HttpRequest, HttpResponse, InternalError, Language, Logger, MysqlConnection, MysqlConnector, Price, UUID, UploadedFile, UsageError, ValueObject, adaptExpressErrorHandler, adaptExpressRoute };
|
package/dist/index.js
CHANGED
|
@@ -36,7 +36,9 @@ __export(src_exports, {
|
|
|
36
36
|
Price: () => Price,
|
|
37
37
|
UUID: () => UUID,
|
|
38
38
|
UsageError: () => UsageError,
|
|
39
|
-
ValueObject: () => ValueObject
|
|
39
|
+
ValueObject: () => ValueObject,
|
|
40
|
+
adaptExpressErrorHandler: () => adaptExpressErrorHandler,
|
|
41
|
+
adaptExpressRoute: () => adaptExpressRoute
|
|
40
42
|
});
|
|
41
43
|
module.exports = __toCommonJS(src_exports);
|
|
42
44
|
|
|
@@ -164,11 +166,12 @@ var DateTime = _DateTime;
|
|
|
164
166
|
// src/domain/contracts/DomainEntity.ts
|
|
165
167
|
var DomainEntity = class {
|
|
166
168
|
constructor(uuid, props, audit) {
|
|
169
|
+
var _a, _b;
|
|
167
170
|
this.uuid = uuid;
|
|
168
171
|
this.props = props;
|
|
169
|
-
this._createdAt = audit
|
|
170
|
-
this._updatedAt = audit
|
|
171
|
-
this._deletedAt = audit
|
|
172
|
+
this._createdAt = (_a = audit == null ? void 0 : audit.createdAt) != null ? _a : DateTime.create();
|
|
173
|
+
this._updatedAt = (_b = audit == null ? void 0 : audit.updatedAt) != null ? _b : this.createdAt;
|
|
174
|
+
this._deletedAt = audit == null ? void 0 : audit.deletedAt;
|
|
172
175
|
}
|
|
173
176
|
touch() {
|
|
174
177
|
this._updatedAt = DateTime.create();
|
|
@@ -460,7 +463,7 @@ var UUID = class _UUID extends ValueObject {
|
|
|
460
463
|
}
|
|
461
464
|
}
|
|
462
465
|
static create(uuid) {
|
|
463
|
-
return new _UUID(uuid
|
|
466
|
+
return new _UUID(uuid != null ? uuid : crypto.randomUUID());
|
|
464
467
|
}
|
|
465
468
|
static isValid(uuid) {
|
|
466
469
|
return /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(uuid);
|
|
@@ -490,33 +493,38 @@ var _ErrorManager = class _ErrorManager {
|
|
|
490
493
|
return _ErrorManager.DEFAULT_MESSAGES[lang.value] || _ErrorManager.DEFAULT_MESSAGES[lang.base()] || "error";
|
|
491
494
|
}
|
|
492
495
|
onFatal(err, lang) {
|
|
493
|
-
|
|
496
|
+
var _a;
|
|
497
|
+
(_a = this.logger) == null ? void 0 : _a.fatal(err.type, err.message);
|
|
494
498
|
return { status: "ERROR", message: this.getDefaultMessage(lang) };
|
|
495
499
|
}
|
|
496
500
|
onInternal(err, lang) {
|
|
497
|
-
|
|
501
|
+
var _a;
|
|
502
|
+
(_a = this.logger) == null ? void 0 : _a.error(err.type, err.message);
|
|
498
503
|
return { status: "ERROR", message: this.getDefaultMessage(lang) };
|
|
499
504
|
}
|
|
500
505
|
onUsage(err, lang) {
|
|
506
|
+
var _a, _b, _c;
|
|
501
507
|
const tmpl = _ErrorManager.TEMPLATES.get(err.type);
|
|
502
508
|
if (!tmpl) {
|
|
503
|
-
this.logger
|
|
509
|
+
(_a = this.logger) == null ? void 0 : _a.error("TEMPLATE_NOT_FOUND", `${err.type}`);
|
|
504
510
|
return { status: "ERROR", message: this.getDefaultMessage(lang) };
|
|
505
511
|
}
|
|
506
512
|
const code = lang.value;
|
|
507
513
|
const base = lang.base();
|
|
508
|
-
const rawMsg = tmpl.languages[code]
|
|
514
|
+
const rawMsg = (_c = (_b = tmpl.languages[code]) != null ? _b : tmpl.languages[base]) != null ? _c : this.getDefaultMessage(lang);
|
|
509
515
|
return {
|
|
510
516
|
status: "ERROR",
|
|
511
517
|
message: StringVars.parse(rawMsg, err.vars)
|
|
512
518
|
};
|
|
513
519
|
}
|
|
514
520
|
onUnknown(err, lang) {
|
|
515
|
-
|
|
521
|
+
var _a;
|
|
522
|
+
(_a = this.logger) == null ? void 0 : _a.error("UNKNOWN_ERROR", err.message);
|
|
516
523
|
return { status: "ERROR", message: this.getDefaultMessage(lang) };
|
|
517
524
|
}
|
|
518
525
|
handle(err, lang) {
|
|
519
|
-
|
|
526
|
+
var _a;
|
|
527
|
+
if (["local", "dev"].includes((_a = process.env.ENVIRONMENT) != null ? _a : "")) {
|
|
520
528
|
console.log(err);
|
|
521
529
|
}
|
|
522
530
|
if (err instanceof FatalError) {
|
|
@@ -547,49 +555,14 @@ _ErrorManager.APP_ERRORS = {
|
|
|
547
555
|
_ErrorManager.TEMPLATES = /* @__PURE__ */ new Map();
|
|
548
556
|
var ErrorManager = _ErrorManager;
|
|
549
557
|
|
|
550
|
-
// src/infrastructure/mysql/
|
|
558
|
+
// src/infrastructure/mysql/Mysql.ts
|
|
551
559
|
var import_promise = require("mysql2/promise");
|
|
552
|
-
|
|
553
|
-
// src/infrastructure/mysql/MysqlConnection.ts
|
|
554
|
-
var MysqlConnection = class {
|
|
555
|
-
constructor(conn) {
|
|
556
|
-
this._conn = conn;
|
|
557
|
-
}
|
|
558
|
-
async query(statement, params = []) {
|
|
559
|
-
const [rows] = await this._conn.query(statement, params);
|
|
560
|
-
return rows;
|
|
561
|
-
}
|
|
562
|
-
async begin() {
|
|
563
|
-
await this._conn.beginTransaction();
|
|
564
|
-
}
|
|
565
|
-
async commit() {
|
|
566
|
-
await this._conn.commit();
|
|
567
|
-
}
|
|
568
|
-
async rollback() {
|
|
569
|
-
await this._conn.rollback();
|
|
570
|
-
}
|
|
571
|
-
async transaction(fn) {
|
|
572
|
-
await this.begin();
|
|
573
|
-
try {
|
|
574
|
-
const result = await fn(this);
|
|
575
|
-
await this.commit();
|
|
576
|
-
return result;
|
|
577
|
-
} catch (err) {
|
|
578
|
-
await this.rollback();
|
|
579
|
-
throw err;
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
async close() {
|
|
583
|
-
this._conn.release();
|
|
584
|
-
}
|
|
585
|
-
};
|
|
586
|
-
|
|
587
|
-
// src/infrastructure/mysql/MysqlConnector.ts
|
|
588
560
|
var _MysqlConnector = class _MysqlConnector {
|
|
589
561
|
constructor(pool) {
|
|
590
|
-
|
|
562
|
+
var _a;
|
|
563
|
+
this._pool = pool != null ? pool : (0, import_promise.createPool)({
|
|
591
564
|
host: process.env.DB_HOST,
|
|
592
|
-
port: Number(process.env.DB_PORT
|
|
565
|
+
port: Number((_a = process.env.DB_PORT) != null ? _a : 3306),
|
|
593
566
|
user: process.env.DB_USER,
|
|
594
567
|
password: process.env.DB_PASSWORD,
|
|
595
568
|
database: process.env.DB_NAME,
|
|
@@ -623,21 +596,40 @@ var _MysqlConnector = class _MysqlConnector {
|
|
|
623
596
|
};
|
|
624
597
|
_MysqlConnector.DEFAULT_POOL_SIZE = 10;
|
|
625
598
|
var MysqlConnector = _MysqlConnector;
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
599
|
+
var MysqlConnection = class {
|
|
600
|
+
constructor(conn) {
|
|
601
|
+
this._conn = conn;
|
|
602
|
+
}
|
|
603
|
+
async query(statement, params = []) {
|
|
604
|
+
const [rows] = await this._conn.query(statement, params);
|
|
605
|
+
return rows;
|
|
606
|
+
}
|
|
607
|
+
async begin() {
|
|
608
|
+
await this._conn.beginTransaction();
|
|
609
|
+
}
|
|
610
|
+
async commit() {
|
|
611
|
+
await this._conn.commit();
|
|
612
|
+
}
|
|
613
|
+
async rollback() {
|
|
614
|
+
await this._conn.rollback();
|
|
615
|
+
}
|
|
616
|
+
async transaction(fn) {
|
|
617
|
+
await this.begin();
|
|
618
|
+
try {
|
|
619
|
+
const result = await fn(this);
|
|
620
|
+
await this.commit();
|
|
621
|
+
return result;
|
|
622
|
+
} catch (err) {
|
|
623
|
+
await this.rollback();
|
|
624
|
+
throw err;
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
async close() {
|
|
628
|
+
this._conn.release();
|
|
637
629
|
}
|
|
638
630
|
};
|
|
639
631
|
|
|
640
|
-
// src/infrastructure/http/
|
|
632
|
+
// src/infrastructure/http/DefaultController.ts
|
|
641
633
|
var HttpHealthCheckController = class {
|
|
642
634
|
async handle(request) {
|
|
643
635
|
return {
|
|
@@ -650,6 +642,52 @@ var HttpHealthCheckController = class {
|
|
|
650
642
|
};
|
|
651
643
|
}
|
|
652
644
|
};
|
|
645
|
+
var HttpNotFoundController = class {
|
|
646
|
+
async handle(request) {
|
|
647
|
+
return {
|
|
648
|
+
statusCode: 404,
|
|
649
|
+
body: {
|
|
650
|
+
status: "NOT_FOUND",
|
|
651
|
+
message: `Route ${request.headers.location} not found`
|
|
652
|
+
}
|
|
653
|
+
};
|
|
654
|
+
}
|
|
655
|
+
};
|
|
656
|
+
|
|
657
|
+
// src/infrastructure/express/ExpressAdapters.ts
|
|
658
|
+
function adaptExpressRoute(Controller) {
|
|
659
|
+
return async (req, res, next) => {
|
|
660
|
+
var _a, _b;
|
|
661
|
+
const rawLangHeader = (_b = (_a = req.headers["accept-language"]) != null ? _a : req.headers["Accept-Language"]) != null ? _b : "es";
|
|
662
|
+
const rawLang = Array.isArray(rawLangHeader) ? rawLangHeader[0] : rawLangHeader || "";
|
|
663
|
+
const lang = rawLang.split(",")[0].split(";")[0].trim().toLowerCase();
|
|
664
|
+
const httpRequest = {
|
|
665
|
+
headers: req.headers,
|
|
666
|
+
params: req.params,
|
|
667
|
+
query: Object.fromEntries(Object.entries(req.query).map(([k, v]) => [k, String(v)])),
|
|
668
|
+
lang,
|
|
669
|
+
body: req.body
|
|
670
|
+
};
|
|
671
|
+
try {
|
|
672
|
+
const controller = new Controller();
|
|
673
|
+
const { statusCode, body } = await controller.handle(httpRequest);
|
|
674
|
+
res.status(statusCode).json(body);
|
|
675
|
+
} catch (err) {
|
|
676
|
+
next(err);
|
|
677
|
+
}
|
|
678
|
+
};
|
|
679
|
+
}
|
|
680
|
+
function adaptExpressErrorHandler(errorManager) {
|
|
681
|
+
return (err, req, res, next) => {
|
|
682
|
+
var _a, _b;
|
|
683
|
+
const raw = (_b = (_a = req.headers["accept-language"]) != null ? _a : req.headers["Accept-Language"]) != null ? _b : "es";
|
|
684
|
+
const rawLang = Array.isArray(raw) ? raw[0] : raw != null ? raw : "";
|
|
685
|
+
const langCode = rawLang.split(",")[0].split(";")[0].trim().toLowerCase();
|
|
686
|
+
const result = errorManager.handle(err, Language.create(langCode));
|
|
687
|
+
const statusCode = typeof result.status === "number" ? result.status : 500;
|
|
688
|
+
res.status(statusCode).json({ message: result.message });
|
|
689
|
+
};
|
|
690
|
+
}
|
|
653
691
|
// Annotate the CommonJS export names for ESM import in node:
|
|
654
692
|
0 && (module.exports = {
|
|
655
693
|
Currency,
|
|
@@ -669,6 +707,8 @@ var HttpHealthCheckController = class {
|
|
|
669
707
|
Price,
|
|
670
708
|
UUID,
|
|
671
709
|
UsageError,
|
|
672
|
-
ValueObject
|
|
710
|
+
ValueObject,
|
|
711
|
+
adaptExpressErrorHandler,
|
|
712
|
+
adaptExpressRoute
|
|
673
713
|
});
|
|
674
714
|
//# sourceMappingURL=index.js.map
|