@hemia/common 0.0.7 → 0.0.8

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.
@@ -1,4 +1,5 @@
1
1
  import 'reflect-metadata';
2
+ import { decorate, injectable } from 'inversify';
2
3
 
3
4
  const METADATA_KEYS = {
4
5
  BASE_PATH: 'base_path',
@@ -16,12 +17,8 @@ const METADATA_KEYS = {
16
17
  TRANSFORMERS: 'hemia:transformers',
17
18
  VALIDATORS: 'hemia:validators',
18
19
  CUSTOMS: 'hemia:customs',
19
- };
20
-
21
- const Controller = (basePath = '/') => {
22
- return (target) => {
23
- Reflect.defineMetadata(METADATA_KEYS.BASE_PATH, basePath, target);
24
- };
20
+ MODULE: "hemia:module",
21
+ INJECTION_ID: "hemia:injection_id"
25
22
  };
26
23
 
27
24
  var HttpMethod;
@@ -282,6 +279,50 @@ function Serialize(dto) {
282
279
  return SetMetadata(METADATA_KEYS.SERIALIZE, dto);
283
280
  }
284
281
 
282
+ function Module(metadata) {
283
+ return (target) => {
284
+ Reflect.defineMetadata(METADATA_KEYS.MODULE, metadata, target);
285
+ };
286
+ }
287
+
288
+ function registerProvider(target, id) {
289
+ decorate(injectable(), target);
290
+ Reflect.defineMetadata(METADATA_KEYS.INJECTION_ID, id || target, target);
291
+ }
292
+ function Service(identifier) {
293
+ return (target) => registerProvider(target, identifier);
294
+ }
295
+ function Repository(identifier) {
296
+ return (target) => registerProvider(target, identifier);
297
+ }
298
+
299
+ function isRedirectResponse(value) {
300
+ return value && typeof value === 'object' && typeof value.url === 'string';
301
+ }
302
+
303
+ class ControllerRegistry {
304
+ static register(target) {
305
+ if (!this.controllers.includes(target)) {
306
+ this.controllers.push(target);
307
+ }
308
+ }
309
+ static getAll() {
310
+ return this.controllers.slice();
311
+ }
312
+ static clear() {
313
+ this.controllers = [];
314
+ }
315
+ }
316
+ ControllerRegistry.controllers = [];
317
+
318
+ const Controller = (basePath = '/') => {
319
+ return (target) => {
320
+ decorate(injectable(), target);
321
+ Reflect.defineMetadata(METADATA_KEYS.BASE_PATH, basePath, target);
322
+ ControllerRegistry.register(target);
323
+ };
324
+ };
325
+
285
326
  /**
286
327
  * Decorador para extraer datos personalizados del request.
287
328
  *
@@ -355,10 +396,6 @@ class ApiResponse {
355
396
  }
356
397
  }
357
398
 
358
- function isRedirectResponse(value) {
359
- return value && typeof value === 'object' && typeof value.url === 'string';
360
- }
361
-
362
399
  class HttpError extends Error {
363
400
  constructor(message, statusCode, error) {
364
401
  super(message);
@@ -655,4 +692,4 @@ class InfraDataDeserializationError extends InfrastructureError {
655
692
  }
656
693
  }
657
694
 
658
- export { ApiResponse, BackupError, BadRequestError, Body, BusinessRuleViolationError, ConfigurationError, ConflictError, ConnectionError, Controller, Cookies, Custom, CustomHttpError, DataConflictError, DataIntegrityError, DataMigrationError, DataNotFoundError, DataValidationError, Delete, DependencyError, DomainError, DuplicateEntityError, EntityNotFoundError, File, Files, ForbiddenError, GatewayTimeoutError, Get, Head, Header, Headers, Host, HttpError, HttpErrorWithDetails, HttpMethod, IndexingError, InfraAuthenticationError, InfraAuthorizationError, InfraCacheConnectionError, InfraConfigurationError, InfraDataDeserializationError, InfraDataSerializationError, InfraDatabaseConnectionError, InfraExternalServiceError, InfraMessageQueueError, InfraNetworkError, InfraServiceUnavailableError, InfraTimeoutError, InfrastructureError, InternalServerError, Ip, Locale, METADATA_KEYS, Next, NotFoundError, OperationNotAllowedError, Options, Param, ParamType, Patch, PersistenceError, Post, Put, Query, QueryExecutionError, Redirect, Req, ReqAuth, ReqContext, ReqPermissions, ReqUser, Request, Res, ResourceLimitError, ResourceLimitExceededError, Response, RestoreError, SchemaMismatchError, Serialize, ServiceUnavailableError, Session, SetMetadata, TimeoutError, TransactionError, Transform, UnauthorizedError, UnprocessableEntityError, UseGuards, UseInterceptors, Validate, ValidationError, isRedirectResponse };
695
+ export { ApiResponse, BackupError, BadRequestError, Body, BusinessRuleViolationError, ConfigurationError, ConflictError, ConnectionError, Controller, ControllerRegistry, Cookies, Custom, CustomHttpError, DataConflictError, DataIntegrityError, DataMigrationError, DataNotFoundError, DataValidationError, Delete, DependencyError, DomainError, DuplicateEntityError, EntityNotFoundError, File, Files, ForbiddenError, GatewayTimeoutError, Get, Head, Header, Headers, Host, HttpError, HttpErrorWithDetails, HttpMethod, IndexingError, InfraAuthenticationError, InfraAuthorizationError, InfraCacheConnectionError, InfraConfigurationError, InfraDataDeserializationError, InfraDataSerializationError, InfraDatabaseConnectionError, InfraExternalServiceError, InfraMessageQueueError, InfraNetworkError, InfraServiceUnavailableError, InfraTimeoutError, InfrastructureError, InternalServerError, Ip, Locale, METADATA_KEYS, Module, Next, NotFoundError, OperationNotAllowedError, Options, Param, ParamType, Patch, PersistenceError, Post, Put, Query, QueryExecutionError, Redirect, Repository, Req, ReqAuth, ReqContext, ReqPermissions, ReqUser, Request, Res, ResourceLimitError, ResourceLimitExceededError, Response, RestoreError, SchemaMismatchError, Serialize, Service, ServiceUnavailableError, Session, SetMetadata, TimeoutError, TransactionError, Transform, UnauthorizedError, UnprocessableEntityError, UseGuards, UseInterceptors, Validate, ValidationError, isRedirectResponse };
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  require('reflect-metadata');
4
+ var inversify = require('inversify');
4
5
 
5
6
  const METADATA_KEYS = {
6
7
  BASE_PATH: 'base_path',
@@ -18,12 +19,8 @@ const METADATA_KEYS = {
18
19
  TRANSFORMERS: 'hemia:transformers',
19
20
  VALIDATORS: 'hemia:validators',
20
21
  CUSTOMS: 'hemia:customs',
21
- };
22
-
23
- const Controller = (basePath = '/') => {
24
- return (target) => {
25
- Reflect.defineMetadata(METADATA_KEYS.BASE_PATH, basePath, target);
26
- };
22
+ MODULE: "hemia:module",
23
+ INJECTION_ID: "hemia:injection_id"
27
24
  };
28
25
 
29
26
  exports.HttpMethod = void 0;
@@ -284,6 +281,50 @@ function Serialize(dto) {
284
281
  return SetMetadata(METADATA_KEYS.SERIALIZE, dto);
285
282
  }
286
283
 
284
+ function Module(metadata) {
285
+ return (target) => {
286
+ Reflect.defineMetadata(METADATA_KEYS.MODULE, metadata, target);
287
+ };
288
+ }
289
+
290
+ function registerProvider(target, id) {
291
+ inversify.decorate(inversify.injectable(), target);
292
+ Reflect.defineMetadata(METADATA_KEYS.INJECTION_ID, id || target, target);
293
+ }
294
+ function Service(identifier) {
295
+ return (target) => registerProvider(target, identifier);
296
+ }
297
+ function Repository(identifier) {
298
+ return (target) => registerProvider(target, identifier);
299
+ }
300
+
301
+ function isRedirectResponse(value) {
302
+ return value && typeof value === 'object' && typeof value.url === 'string';
303
+ }
304
+
305
+ class ControllerRegistry {
306
+ static register(target) {
307
+ if (!this.controllers.includes(target)) {
308
+ this.controllers.push(target);
309
+ }
310
+ }
311
+ static getAll() {
312
+ return this.controllers.slice();
313
+ }
314
+ static clear() {
315
+ this.controllers = [];
316
+ }
317
+ }
318
+ ControllerRegistry.controllers = [];
319
+
320
+ const Controller = (basePath = '/') => {
321
+ return (target) => {
322
+ inversify.decorate(inversify.injectable(), target);
323
+ Reflect.defineMetadata(METADATA_KEYS.BASE_PATH, basePath, target);
324
+ ControllerRegistry.register(target);
325
+ };
326
+ };
327
+
287
328
  /**
288
329
  * Decorador para extraer datos personalizados del request.
289
330
  *
@@ -357,10 +398,6 @@ class ApiResponse {
357
398
  }
358
399
  }
359
400
 
360
- function isRedirectResponse(value) {
361
- return value && typeof value === 'object' && typeof value.url === 'string';
362
- }
363
-
364
401
  class HttpError extends Error {
365
402
  constructor(message, statusCode, error) {
366
403
  super(message);
@@ -666,6 +703,7 @@ exports.ConfigurationError = ConfigurationError;
666
703
  exports.ConflictError = ConflictError;
667
704
  exports.ConnectionError = ConnectionError;
668
705
  exports.Controller = Controller;
706
+ exports.ControllerRegistry = ControllerRegistry;
669
707
  exports.Cookies = Cookies;
670
708
  exports.Custom = Custom;
671
709
  exports.CustomHttpError = CustomHttpError;
@@ -708,6 +746,7 @@ exports.InternalServerError = InternalServerError;
708
746
  exports.Ip = Ip;
709
747
  exports.Locale = Locale;
710
748
  exports.METADATA_KEYS = METADATA_KEYS;
749
+ exports.Module = Module;
711
750
  exports.Next = Next;
712
751
  exports.NotFoundError = NotFoundError;
713
752
  exports.OperationNotAllowedError = OperationNotAllowedError;
@@ -720,6 +759,7 @@ exports.Put = Put;
720
759
  exports.Query = Query;
721
760
  exports.QueryExecutionError = QueryExecutionError;
722
761
  exports.Redirect = Redirect;
762
+ exports.Repository = Repository;
723
763
  exports.Req = Req;
724
764
  exports.ReqAuth = ReqAuth;
725
765
  exports.ReqContext = ReqContext;
@@ -733,6 +773,7 @@ exports.Response = Response;
733
773
  exports.RestoreError = RestoreError;
734
774
  exports.SchemaMismatchError = SchemaMismatchError;
735
775
  exports.Serialize = Serialize;
776
+ exports.Service = Service;
736
777
  exports.ServiceUnavailableError = ServiceUnavailableError;
737
778
  exports.Session = Session;
738
779
  exports.SetMetadata = SetMetadata;
@@ -2,3 +2,6 @@ export * from "./use-guards.decorator";
2
2
  export * from "./use-interceptors.decorator";
3
3
  export * from "./set-metadata.decorator";
4
4
  export * from "./serialize.decorator";
5
+ export * from "./module.decorator";
6
+ export * from "./service.decorator";
7
+ export * from "./controller.decorator";
@@ -0,0 +1,8 @@
1
+ import "reflect-metadata";
2
+ export interface ModuleMetadata {
3
+ imports?: any[];
4
+ controllers?: any[];
5
+ providers?: any[];
6
+ exports?: any[];
7
+ }
8
+ export declare function Module(metadata: ModuleMetadata): ClassDecorator;
@@ -0,0 +1,2 @@
1
+ export declare function Service(identifier?: symbol | string): ClassDecorator;
2
+ export declare function Repository(identifier?: symbol | string): ClassDecorator;
@@ -1,4 +1,3 @@
1
- export * from "./controller.decorator";
2
1
  export * from "./method.decorators";
3
2
  export * from "./param.decorators";
4
3
  export * from "./response.decorators";
@@ -14,4 +14,6 @@ export declare const METADATA_KEYS: {
14
14
  readonly TRANSFORMERS: "hemia:transformers";
15
15
  readonly VALIDATORS: "hemia:validators";
16
16
  readonly CUSTOMS: "hemia:customs";
17
+ readonly MODULE: "hemia:module";
18
+ readonly INJECTION_ID: "hemia:injection_id";
17
19
  };
@@ -0,0 +1,6 @@
1
+ export declare class ControllerRegistry {
2
+ private static controllers;
3
+ static register(target: Function): void;
4
+ static getAll(): Function[];
5
+ static clear(): void;
6
+ }
@@ -1 +1,2 @@
1
1
  export * from "./type-guards";
2
+ export * from "./controller-registry";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hemia/common",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "description": "Paquete común para proyectos de Hemia",
5
5
  "main": "dist/hemia-common.js",
6
6
  "module": "dist/hemia-common.esm.js",
@@ -28,7 +28,8 @@
28
28
  "rollup-plugin-typescript2": "^0.36.0",
29
29
  "ts-jest": "^29.2.5",
30
30
  "ts-node": "^8.9.0",
31
- "typescript": "^5.5.4"
31
+ "typescript": "^5.5.4",
32
+ "inversify": "^7.11.0"
32
33
  },
33
34
  "peerDependencies": {
34
35
  "reflect-metadata": "^0.2.2"
@@ -37,5 +38,8 @@
37
38
  "license": "ISC",
38
39
  "files": [
39
40
  "dist"
40
- ]
41
+ ],
42
+ "dependencies": {
43
+
44
+ }
41
45
  }