@hemia/common 0.0.3 → 0.0.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/hemia-common.esm.js +29 -2
- package/dist/hemia-common.js +30 -1
- package/dist/types/decorators/auth/index.d.ts +2 -0
- package/dist/types/decorators/auth/permissions.decorator.d.ts +5 -0
- package/dist/types/decorators/auth/roles.decorator.d.ts +5 -0
- package/dist/types/decorators/core/index.d.ts +2 -0
- package/dist/types/decorators/core/serialize.decorator.d.ts +9 -0
- package/dist/types/decorators/core/set-metadata.decorator.d.ts +7 -0
- package/dist/types/decorators/metadata.d.ts +3 -0
- package/dist/types/errors/domain.error.d.ts +34 -0
- package/dist/types/errors/infrastructure.error.d.ts +40 -0
- package/dist/types/errors/persistence.error.d.ts +43 -0
- package/dist/types/interfaces/configuration/aws-s3-configuration.interface.d.ts +6 -0
- package/dist/types/interfaces/configuration/drizzle-db-configuration.interface.d.ts +7 -0
- package/dist/types/interfaces/configuration/mongo-db-configuration.interface.d.ts +7 -0
- package/dist/types/interfaces/configuration/olap-db-configuration.interface.d.ts +6 -0
- package/dist/types/interfaces/configuration/redis-configuration.interface.d.ts +8 -0
- package/dist/types/interfaces/index.d.ts +5 -0
- package/package.json +1 -1
package/dist/hemia-common.esm.js
CHANGED
|
@@ -8,7 +8,10 @@ const METADATA_KEYS = {
|
|
|
8
8
|
REDIRECT: 'redirect',
|
|
9
9
|
GUARDS: 'hemia:guards',
|
|
10
10
|
INTERCEPTORS: 'hemia:interceptors',
|
|
11
|
-
CUSTOM: 'hemia:custom'
|
|
11
|
+
CUSTOM: 'hemia:custom',
|
|
12
|
+
SERIALIZE: 'hemia:serialize',
|
|
13
|
+
ROLES: 'hemia:roles',
|
|
14
|
+
PERMISSIONS: 'hemia:permissions'
|
|
12
15
|
};
|
|
13
16
|
|
|
14
17
|
const Controller = (basePath = '/') => {
|
|
@@ -135,6 +138,30 @@ function UseInterceptors(...interceptors) {
|
|
|
135
138
|
};
|
|
136
139
|
}
|
|
137
140
|
|
|
141
|
+
/**
|
|
142
|
+
* Decorador que asigna metadata personalizada a una clase o método.
|
|
143
|
+
* @param metadataKey La clave para guardar la metadata (string, symbol, etc.)
|
|
144
|
+
* @param metadataValue El valor a guardar (objeto, array, primitivo, etc.)
|
|
145
|
+
*/
|
|
146
|
+
const SetMetadata = (metadataKey, metadataValue) => {
|
|
147
|
+
return (target, key, descriptor) => {
|
|
148
|
+
if (descriptor) {
|
|
149
|
+
Reflect.defineMetadata(metadataKey, metadataValue, descriptor.value);
|
|
150
|
+
return descriptor;
|
|
151
|
+
}
|
|
152
|
+
Reflect.defineMetadata(metadataKey, metadataValue, target);
|
|
153
|
+
return target;
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Decorador que transforma la respuesta saliente a una instancia del DTO proporcionado.
|
|
159
|
+
* @param dto La clase DTO a la que quieres convertir la respuesta.
|
|
160
|
+
*/
|
|
161
|
+
function Serialize(dto) {
|
|
162
|
+
return SetMetadata(METADATA_KEYS.SERIALIZE, dto);
|
|
163
|
+
}
|
|
164
|
+
|
|
138
165
|
class ApiResponse {
|
|
139
166
|
static success(data, message = 'OK', status = 200) {
|
|
140
167
|
return {
|
|
@@ -223,4 +250,4 @@ class HttpErrorWithDetails extends HttpError {
|
|
|
223
250
|
}
|
|
224
251
|
}
|
|
225
252
|
|
|
226
|
-
export { ApiResponse, BadRequestError, Body, ConflictError, Controller, CustomHttpError, Delete, ForbiddenError, GatewayTimeoutError, Get, Head, Header, Headers, Host, HttpError, HttpErrorWithDetails, HttpMethod, InternalServerError, Ip, METADATA_KEYS, Next, NotFoundError, Options, Param, ParamType, Patch, Post, Put, Query, Redirect, Req, Request, Res, Response, ServiceUnavailableError, Session, UnauthorizedError, UnprocessableEntityError, UseGuards, UseInterceptors, isRedirectResponse };
|
|
253
|
+
export { ApiResponse, BadRequestError, Body, ConflictError, Controller, CustomHttpError, Delete, ForbiddenError, GatewayTimeoutError, Get, Head, Header, Headers, Host, HttpError, HttpErrorWithDetails, HttpMethod, InternalServerError, Ip, METADATA_KEYS, Next, NotFoundError, Options, Param, ParamType, Patch, Post, Put, Query, Redirect, Req, Request, Res, Response, Serialize, ServiceUnavailableError, Session, SetMetadata, UnauthorizedError, UnprocessableEntityError, UseGuards, UseInterceptors, isRedirectResponse };
|
package/dist/hemia-common.js
CHANGED
|
@@ -10,7 +10,10 @@ const METADATA_KEYS = {
|
|
|
10
10
|
REDIRECT: 'redirect',
|
|
11
11
|
GUARDS: 'hemia:guards',
|
|
12
12
|
INTERCEPTORS: 'hemia:interceptors',
|
|
13
|
-
CUSTOM: 'hemia:custom'
|
|
13
|
+
CUSTOM: 'hemia:custom',
|
|
14
|
+
SERIALIZE: 'hemia:serialize',
|
|
15
|
+
ROLES: 'hemia:roles',
|
|
16
|
+
PERMISSIONS: 'hemia:permissions'
|
|
14
17
|
};
|
|
15
18
|
|
|
16
19
|
const Controller = (basePath = '/') => {
|
|
@@ -137,6 +140,30 @@ function UseInterceptors(...interceptors) {
|
|
|
137
140
|
};
|
|
138
141
|
}
|
|
139
142
|
|
|
143
|
+
/**
|
|
144
|
+
* Decorador que asigna metadata personalizada a una clase o método.
|
|
145
|
+
* @param metadataKey La clave para guardar la metadata (string, symbol, etc.)
|
|
146
|
+
* @param metadataValue El valor a guardar (objeto, array, primitivo, etc.)
|
|
147
|
+
*/
|
|
148
|
+
const SetMetadata = (metadataKey, metadataValue) => {
|
|
149
|
+
return (target, key, descriptor) => {
|
|
150
|
+
if (descriptor) {
|
|
151
|
+
Reflect.defineMetadata(metadataKey, metadataValue, descriptor.value);
|
|
152
|
+
return descriptor;
|
|
153
|
+
}
|
|
154
|
+
Reflect.defineMetadata(metadataKey, metadataValue, target);
|
|
155
|
+
return target;
|
|
156
|
+
};
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Decorador que transforma la respuesta saliente a una instancia del DTO proporcionado.
|
|
161
|
+
* @param dto La clase DTO a la que quieres convertir la respuesta.
|
|
162
|
+
*/
|
|
163
|
+
function Serialize(dto) {
|
|
164
|
+
return SetMetadata(METADATA_KEYS.SERIALIZE, dto);
|
|
165
|
+
}
|
|
166
|
+
|
|
140
167
|
class ApiResponse {
|
|
141
168
|
static success(data, message = 'OK', status = 200) {
|
|
142
169
|
return {
|
|
@@ -257,8 +284,10 @@ exports.Req = Req;
|
|
|
257
284
|
exports.Request = Request;
|
|
258
285
|
exports.Res = Res;
|
|
259
286
|
exports.Response = Response;
|
|
287
|
+
exports.Serialize = Serialize;
|
|
260
288
|
exports.ServiceUnavailableError = ServiceUnavailableError;
|
|
261
289
|
exports.Session = Session;
|
|
290
|
+
exports.SetMetadata = SetMetadata;
|
|
262
291
|
exports.UnauthorizedError = UnauthorizedError;
|
|
263
292
|
exports.UnprocessableEntityError = UnprocessableEntityError;
|
|
264
293
|
exports.UseGuards = UseGuards;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Define los permisos específicos requeridos para acceder a un recurso.
|
|
3
|
+
* @param permissions Lista de permisos (ej: 'read:users', 'write:posts')
|
|
4
|
+
*/
|
|
5
|
+
export declare const Permissions: (...permissions: string[]) => (target: object | Function, key?: string | symbol, descriptor?: PropertyDescriptor) => object;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Type } from "../../interfaces";
|
|
2
|
+
export interface SerializeOptions {
|
|
3
|
+
excludeExtraneousValues?: boolean;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Decorador que transforma la respuesta saliente a una instancia del DTO proporcionado.
|
|
7
|
+
* @param dto La clase DTO a la que quieres convertir la respuesta.
|
|
8
|
+
*/
|
|
9
|
+
export declare function Serialize(dto: Type<any>): (target: object | Function, key?: string | symbol, descriptor?: PropertyDescriptor) => object;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
/**
|
|
3
|
+
* Decorador que asigna metadata personalizada a una clase o método.
|
|
4
|
+
* @param metadataKey La clave para guardar la metadata (string, symbol, etc.)
|
|
5
|
+
* @param metadataValue El valor a guardar (objeto, array, primitivo, etc.)
|
|
6
|
+
*/
|
|
7
|
+
export declare const SetMetadata: <K = string | symbol, V = any>(metadataKey: K, metadataValue: V) => (target: object | Function, key?: string | symbol, descriptor?: PropertyDescriptor) => object;
|
|
@@ -7,4 +7,7 @@ export declare const METADATA_KEYS: {
|
|
|
7
7
|
readonly GUARDS: "hemia:guards";
|
|
8
8
|
readonly INTERCEPTORS: "hemia:interceptors";
|
|
9
9
|
readonly CUSTOM: "hemia:custom";
|
|
10
|
+
readonly SERIALIZE: "hemia:serialize";
|
|
11
|
+
readonly ROLES: "hemia:roles";
|
|
12
|
+
readonly PERMISSIONS: "hemia:permissions";
|
|
10
13
|
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Errores de lógica de negocio (Business Layer)
|
|
3
|
+
* No conocen HTTP, son agnósticos a la infraestructura
|
|
4
|
+
*/
|
|
5
|
+
export declare class DomainError extends Error {
|
|
6
|
+
constructor(message: string);
|
|
7
|
+
}
|
|
8
|
+
export declare class EntityNotFoundError extends DomainError {
|
|
9
|
+
constructor(entity: string, criteria: string);
|
|
10
|
+
}
|
|
11
|
+
export declare class DuplicateEntityError extends DomainError {
|
|
12
|
+
constructor(entity: string, criteria: string);
|
|
13
|
+
}
|
|
14
|
+
export declare class ValidationError extends DomainError {
|
|
15
|
+
constructor(message: string);
|
|
16
|
+
}
|
|
17
|
+
export declare class BusinessRuleViolationError extends DomainError {
|
|
18
|
+
constructor(message: string);
|
|
19
|
+
}
|
|
20
|
+
export declare class OperationNotAllowedError extends DomainError {
|
|
21
|
+
constructor(operation: string);
|
|
22
|
+
}
|
|
23
|
+
export declare class DependencyError extends DomainError {
|
|
24
|
+
constructor(dependency: string, message: string);
|
|
25
|
+
}
|
|
26
|
+
export declare class TimeoutError extends DomainError {
|
|
27
|
+
constructor(operation: string, timeout: number);
|
|
28
|
+
}
|
|
29
|
+
export declare class ResourceLimitExceededError extends DomainError {
|
|
30
|
+
constructor(resource: string, limit: number);
|
|
31
|
+
}
|
|
32
|
+
export declare class ConfigurationError extends DomainError {
|
|
33
|
+
constructor(message: string);
|
|
34
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export declare class InfrastructureError extends Error {
|
|
2
|
+
readonly originalError?: Error | undefined;
|
|
3
|
+
constructor(message: string, originalError?: Error | undefined);
|
|
4
|
+
}
|
|
5
|
+
export declare class InfraDatabaseConnectionError extends InfrastructureError {
|
|
6
|
+
constructor(dbType: string, originalError?: Error);
|
|
7
|
+
}
|
|
8
|
+
export declare class InfraCacheConnectionError extends InfrastructureError {
|
|
9
|
+
constructor(cacheType: string, originalError?: Error);
|
|
10
|
+
}
|
|
11
|
+
export declare class InfraMessageQueueError extends InfrastructureError {
|
|
12
|
+
constructor(queueType: string, originalError?: Error);
|
|
13
|
+
}
|
|
14
|
+
export declare class InfraExternalServiceError extends InfrastructureError {
|
|
15
|
+
constructor(serviceName: string, originalError?: Error);
|
|
16
|
+
}
|
|
17
|
+
export declare class InfraConfigurationError extends InfrastructureError {
|
|
18
|
+
constructor(configItem: string, originalError?: Error);
|
|
19
|
+
}
|
|
20
|
+
export declare class InfraNetworkError extends InfrastructureError {
|
|
21
|
+
constructor(message: string, originalError?: Error);
|
|
22
|
+
}
|
|
23
|
+
export declare class InfraTimeoutError extends InfrastructureError {
|
|
24
|
+
constructor(operation: string, timeout: number, originalError?: Error);
|
|
25
|
+
}
|
|
26
|
+
export declare class InfraAuthenticationError extends InfrastructureError {
|
|
27
|
+
constructor(message: string, originalError?: Error);
|
|
28
|
+
}
|
|
29
|
+
export declare class InfraAuthorizationError extends InfrastructureError {
|
|
30
|
+
constructor(message: string, originalError?: Error);
|
|
31
|
+
}
|
|
32
|
+
export declare class InfraServiceUnavailableError extends InfrastructureError {
|
|
33
|
+
constructor(serviceName: string, originalError?: Error);
|
|
34
|
+
}
|
|
35
|
+
export declare class InfraDataSerializationError extends InfrastructureError {
|
|
36
|
+
constructor(dataType: string, originalError?: Error);
|
|
37
|
+
}
|
|
38
|
+
export declare class InfraDataDeserializationError extends InfrastructureError {
|
|
39
|
+
constructor(dataType: string, originalError?: Error);
|
|
40
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export declare class PersistenceError extends Error {
|
|
2
|
+
readonly originalError?: Error | undefined;
|
|
3
|
+
constructor(message: string, originalError?: Error | undefined);
|
|
4
|
+
}
|
|
5
|
+
export declare class DataNotFoundError extends PersistenceError {
|
|
6
|
+
constructor(entity: string, criteria: string, originalError?: Error);
|
|
7
|
+
}
|
|
8
|
+
export declare class DataConflictError extends PersistenceError {
|
|
9
|
+
constructor(entity: string, criteria: string, originalError?: Error);
|
|
10
|
+
}
|
|
11
|
+
export declare class DataValidationError extends PersistenceError {
|
|
12
|
+
constructor(message: string, originalError?: Error);
|
|
13
|
+
}
|
|
14
|
+
export declare class TransactionError extends PersistenceError {
|
|
15
|
+
constructor(message: string, originalError?: Error);
|
|
16
|
+
}
|
|
17
|
+
export declare class QueryExecutionError extends PersistenceError {
|
|
18
|
+
constructor(query: string, originalError?: Error);
|
|
19
|
+
}
|
|
20
|
+
export declare class ConnectionError extends PersistenceError {
|
|
21
|
+
constructor(databaseType: string, originalError?: Error);
|
|
22
|
+
}
|
|
23
|
+
export declare class SchemaMismatchError extends PersistenceError {
|
|
24
|
+
constructor(expectedSchema: string, actualSchema: string, originalError?: Error);
|
|
25
|
+
}
|
|
26
|
+
export declare class DataIntegrityError extends PersistenceError {
|
|
27
|
+
constructor(message: string, originalError?: Error);
|
|
28
|
+
}
|
|
29
|
+
export declare class BackupError extends PersistenceError {
|
|
30
|
+
constructor(message: string, originalError?: Error);
|
|
31
|
+
}
|
|
32
|
+
export declare class RestoreError extends PersistenceError {
|
|
33
|
+
constructor(message: string, originalError?: Error);
|
|
34
|
+
}
|
|
35
|
+
export declare class IndexingError extends PersistenceError {
|
|
36
|
+
constructor(indexName: string, originalError?: Error);
|
|
37
|
+
}
|
|
38
|
+
export declare class DataMigrationError extends PersistenceError {
|
|
39
|
+
constructor(migrationName: string, originalError?: Error);
|
|
40
|
+
}
|
|
41
|
+
export declare class ResourceLimitError extends PersistenceError {
|
|
42
|
+
constructor(resourceType: string, limit: number, originalError?: Error);
|
|
43
|
+
}
|
|
@@ -7,3 +7,8 @@ export * from "./features/arguments-host.interface";
|
|
|
7
7
|
export * from './type.interface';
|
|
8
8
|
export * from './handler.interface';
|
|
9
9
|
export * from './interceptor.interface';
|
|
10
|
+
export * from './configuration/redis-configuration.interface';
|
|
11
|
+
export * from './configuration/mongo-db-configuration.interface';
|
|
12
|
+
export * from './configuration/aws-s3-configuration.interface';
|
|
13
|
+
export * from './configuration/drizzle-db-configuration.interface';
|
|
14
|
+
export * from './configuration/olap-db-configuration.interface';
|