@zenofolio/hyper-decor 1.0.71 → 1.0.73

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.
Files changed (122) hide show
  1. package/.agent/rules/philosophy.md +103 -0
  2. package/.agent/rules/writing.md +32 -0
  3. package/README.md +78 -207
  4. package/dist/__internals/constants.d.ts +1 -62
  5. package/dist/__internals/constants.js +3 -69
  6. package/dist/__internals/creators/request.creator.d.ts +1 -10
  7. package/dist/__internals/creators/request.creator.js +141 -23
  8. package/dist/__internals/helpers/merge-metadata.d.ts +2 -3
  9. package/dist/__internals/helpers/merge-metadata.js +31 -7
  10. package/dist/__internals/helpers/prepare.helper.d.ts +4 -10
  11. package/dist/__internals/helpers/prepare.helper.js +316 -283
  12. package/dist/__internals/stores/hyper.store.d.ts +5 -0
  13. package/dist/__internals/stores/hyper.store.js +5 -0
  14. package/dist/__internals/stores/index.d.ts +4 -0
  15. package/dist/__internals/stores/index.js +20 -0
  16. package/dist/__internals/stores/meta.store.d.ts +34 -0
  17. package/dist/__internals/stores/meta.store.js +107 -0
  18. package/dist/__internals/stores/scope.store.d.ts +14 -0
  19. package/dist/__internals/stores/scope.store.js +29 -0
  20. package/dist/__internals/stores/serivces.store.d.ts +1 -0
  21. package/dist/__internals/stores/serivces.store.js +4 -0
  22. package/dist/__internals/transform/middleware.transform.d.ts +1 -1
  23. package/dist/__internals/transform/middleware.transform.js +1 -1
  24. package/dist/__internals/transform/role.transform.d.ts +1 -1
  25. package/dist/__internals/transform/role.transform.js +4 -4
  26. package/dist/__internals/transform/scope.transfrom.d.ts +1 -1
  27. package/dist/__internals/transform/scope.transfrom.js +2 -2
  28. package/dist/__internals/types.d.ts +53 -4
  29. package/dist/common/bootstrap.d.ts +6 -2
  30. package/dist/common/bootstrap.js +44 -10
  31. package/dist/common/transport.d.ts +1 -0
  32. package/dist/common/transport.js +27 -14
  33. package/dist/constants.d.ts +1 -0
  34. package/dist/constants.js +2 -1
  35. package/dist/decorators/Http.d.ts +3 -43
  36. package/dist/decorators/Http.js +9 -103
  37. package/dist/decorators.d.ts +1 -0
  38. package/dist/decorators.js +17 -0
  39. package/dist/index.d.ts +6 -5
  40. package/dist/index.js +6 -5
  41. package/dist/lib/event/meta.store.d.ts +4 -0
  42. package/dist/lib/event/meta.store.js +5 -0
  43. package/dist/lib/openapi/collectors/class.collector.d.ts +5 -9
  44. package/dist/lib/openapi/collectors/class.collector.js +6 -63
  45. package/dist/lib/openapi/collectors/index.d.ts +3 -4
  46. package/dist/lib/openapi/collectors/index.js +0 -1
  47. package/dist/lib/openapi/collectors/method.collector.d.ts +6 -1
  48. package/dist/lib/openapi/collectors/method.collector.js +92 -59
  49. package/dist/lib/openapi/collectors/schema.collector.d.ts +3 -8
  50. package/dist/lib/openapi/collectors/schema.collector.js +17 -25
  51. package/dist/lib/openapi/constants.d.ts +1 -0
  52. package/dist/lib/openapi/constants.js +2 -2
  53. package/dist/lib/openapi/decorators.d.ts +16 -0
  54. package/dist/lib/openapi/decorators.js +93 -0
  55. package/dist/lib/openapi/index.d.ts +29 -5
  56. package/dist/lib/openapi/index.js +119 -5
  57. package/dist/lib/openapi/metadata.d.ts +7 -0
  58. package/dist/lib/openapi/metadata.js +8 -0
  59. package/dist/lib/openapi/metadata.registry.d.ts +1 -1
  60. package/dist/lib/server/decorators/File.d.ts +37 -0
  61. package/dist/lib/server/decorators/File.js +167 -0
  62. package/dist/lib/server/decorators/Http.d.ts +12 -0
  63. package/dist/lib/server/decorators/Http.js +56 -0
  64. package/dist/lib/server/decorators/HyperApp.d.ts +7 -0
  65. package/dist/lib/server/decorators/HyperApp.js +14 -0
  66. package/dist/lib/server/decorators/HyperController.d.ts +6 -0
  67. package/dist/lib/server/decorators/HyperController.js +27 -0
  68. package/dist/lib/server/decorators/HyperModule.d.ts +6 -0
  69. package/dist/lib/server/decorators/HyperModule.js +13 -0
  70. package/dist/lib/server/decorators/HyperService.d.ts +11 -0
  71. package/dist/lib/server/decorators/HyperService.js +30 -0
  72. package/dist/lib/server/decorators/Messaging.d.ts +8 -0
  73. package/dist/lib/server/decorators/Messaging.js +19 -0
  74. package/dist/lib/server/decorators/Middleware.d.ts +18 -0
  75. package/dist/lib/server/decorators/Middleware.js +52 -0
  76. package/dist/lib/server/decorators/Output.d.ts +6 -0
  77. package/dist/lib/server/decorators/Output.js +14 -0
  78. package/dist/lib/server/decorators/Pass.d.ts +10 -0
  79. package/dist/lib/server/decorators/Pass.js +13 -0
  80. package/dist/lib/server/decorators/Role.d.ts +7 -0
  81. package/dist/lib/server/decorators/Role.js +14 -0
  82. package/dist/lib/server/decorators/Routes.d.ts +14 -0
  83. package/dist/lib/server/decorators/Routes.js +39 -0
  84. package/dist/lib/server/decorators/Scope.d.ts +7 -0
  85. package/dist/lib/server/decorators/Scope.js +14 -0
  86. package/dist/lib/server/decorators/index.d.ts +16 -0
  87. package/dist/lib/server/decorators/index.js +32 -0
  88. package/dist/lib/server/decorators/metadata.d.ts +1 -0
  89. package/dist/lib/server/decorators/metadata.js +5 -0
  90. package/dist/lib/server/decorators/types.d.ts +125 -0
  91. package/dist/lib/server/decorators/types.js +6 -0
  92. package/dist/lib/server/exeptions/DuplicateControllerPathException.d.ts +14 -0
  93. package/dist/lib/server/exeptions/DuplicateControllerPathException.js +12 -0
  94. package/dist/lib/server/exeptions/DuplicatedException.d.ts +8 -0
  95. package/dist/lib/server/exeptions/DuplicatedException.js +12 -0
  96. package/dist/lib/server/exeptions/DuplicatedHandlerException.d.ts +4 -0
  97. package/dist/lib/server/exeptions/DuplicatedHandlerException.js +12 -0
  98. package/dist/lib/server/exeptions/HyperException.d.ts +8 -0
  99. package/dist/lib/server/exeptions/HyperException.js +14 -0
  100. package/dist/lib/server/exeptions/HyperFileException.d.ts +4 -0
  101. package/dist/lib/server/exeptions/HyperFileException.js +12 -0
  102. package/dist/lib/server/exeptions/MethodNotFountException.d.ts +4 -0
  103. package/dist/lib/server/exeptions/MethodNotFountException.js +12 -0
  104. package/dist/lib/server/exeptions/NotPropertyException.d.ts +6 -0
  105. package/dist/lib/server/exeptions/NotPropertyException.js +16 -0
  106. package/dist/lib/server/exeptions/NotRoleException.d.ts +6 -0
  107. package/dist/lib/server/exeptions/NotRoleException.js +17 -0
  108. package/dist/lib/server/exeptions/NotScopeException.d.ts +7 -0
  109. package/dist/lib/server/exeptions/NotScopeException.js +18 -0
  110. package/dist/lib/server/exeptions/WrongPlaceException.d.ts +8 -0
  111. package/dist/lib/server/exeptions/WrongPlaceException.js +21 -0
  112. package/dist/lib/server/exeptions/index.d.ts +8 -0
  113. package/dist/lib/server/exeptions/index.js +18 -0
  114. package/dist/lib/server/exeptions/types.d.ts +1 -0
  115. package/dist/lib/server/exeptions/types.js +2 -0
  116. package/dist/lib/tree/tree.d.ts +36 -0
  117. package/dist/lib/tree/tree.js +106 -0
  118. package/package.json +1 -1
  119. package/scripts/clean.js +55 -55
  120. package/scripts/test-server.ts +85 -85
  121. package/vitest.config.mjs +33 -30
  122. package/vitest.json +0 -0
@@ -0,0 +1,5 @@
1
+ import { HyperCommonMetadata, HyperMethodMetadata } from "../types";
2
+ export declare const HyperMeta: {
3
+ set: (target: object, propertyKey: any, data: Partial<HyperCommonMetadata> | Partial<HyperMethodMetadata>) => void;
4
+ get: (target: object, propertyKey?: any) => Partial<HyperCommonMetadata> | Partial<HyperMethodMetadata>;
5
+ };
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HyperMeta = void 0;
4
+ const meta_store_1 = require("./meta.store");
5
+ exports.HyperMeta = meta_store_1.Metadata.prefix('server');
@@ -0,0 +1,4 @@
1
+ export * from "./meta.store";
2
+ export * from "./hyper.store";
3
+ export * from "./scope.store";
4
+ export * from "./serivces.store";
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./meta.store"), exports);
18
+ __exportStar(require("./hyper.store"), exports);
19
+ __exportStar(require("./scope.store"), exports);
20
+ __exportStar(require("./serivces.store"), exports);
@@ -0,0 +1,34 @@
1
+ import 'reflect-metadata';
2
+ type MetadataRecord = Record<string, unknown>;
3
+ export declare class Metadata {
4
+ /**
5
+ * Resolve the real metadata target.
6
+ * If an instance is passed, use its constructor.
7
+ */
8
+ private static resolveTarget;
9
+ /**
10
+ * Track class constructors for discovery.
11
+ */
12
+ private static track;
13
+ /**
14
+ * Get metadata for a target.
15
+ * Auto-initializes the metadata object if missing.
16
+ */
17
+ static get<T = MetadataRecord>(target: object): T;
18
+ /**
19
+ * Replace the full metadata object for a target.
20
+ */
21
+ static rawSet<T extends MetadataRecord>(target: object, value: T): void;
22
+ /**
23
+ * Create a scoped metadata accessor.
24
+ */
25
+ static prefix<TCommon extends object, TMember extends object>(name: string): {
26
+ set: (target: object, propertyKey: any, data: Partial<TCommon> | Partial<TMember>) => void;
27
+ get: (target: object, propertyKey?: any) => Partial<TCommon> | Partial<TMember>;
28
+ };
29
+ /**
30
+ * Get all tracked classes.
31
+ */
32
+ static getTrackedClasses(): object[];
33
+ }
34
+ export {};
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ var _a, _b;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.Metadata = void 0;
5
+ require("reflect-metadata");
6
+ /**
7
+ * Global Symbols for cross-package consistency
8
+ */
9
+ const METADATA_STORE = Symbol.for('hyper:store');
10
+ const DISCOVERY_INDEX = Symbol.for('hyper:index');
11
+ const globalRegistry = globalThis;
12
+ /**
13
+ * Global stores ensure that even different copies of the package
14
+ * share the same metadata and discovery registry.
15
+ */
16
+ const globalStore = (_a = globalRegistry[METADATA_STORE]) !== null && _a !== void 0 ? _a : (globalRegistry[METADATA_STORE] = new WeakMap());
17
+ const globalIndex = (_b = globalRegistry[DISCOVERY_INDEX]) !== null && _b !== void 0 ? _b : (globalRegistry[DISCOVERY_INDEX] = new Set());
18
+ class Metadata {
19
+ /**
20
+ * Resolve the real metadata target.
21
+ * If an instance is passed, use its constructor.
22
+ */
23
+ static resolveTarget(target) {
24
+ return typeof target === 'function' ? target : target.constructor;
25
+ }
26
+ /**
27
+ * Track class constructors for discovery.
28
+ */
29
+ static track(target) {
30
+ if (typeof target === 'function') {
31
+ globalIndex.add(target);
32
+ }
33
+ }
34
+ /**
35
+ * Get metadata for a target.
36
+ * Auto-initializes the metadata object if missing.
37
+ */
38
+ static get(target) {
39
+ const resolved = this.resolveTarget(target);
40
+ let meta = globalStore.get(resolved);
41
+ if (!meta) {
42
+ meta = {};
43
+ globalStore.set(resolved, meta);
44
+ this.track(resolved);
45
+ }
46
+ return meta;
47
+ }
48
+ /**
49
+ * Replace the full metadata object for a target.
50
+ */
51
+ static rawSet(target, value) {
52
+ const resolved = this.resolveTarget(target);
53
+ globalStore.set(resolved, value);
54
+ this.track(resolved);
55
+ }
56
+ /**
57
+ * Create a scoped metadata accessor.
58
+ */
59
+ static prefix(name) {
60
+ const resolveKey = (key) => {
61
+ if (typeof key === 'string' || typeof key === 'symbol' || key === undefined) {
62
+ return key;
63
+ }
64
+ if (typeof key === 'object' && key !== null) {
65
+ if (key.kind === 'class')
66
+ return undefined;
67
+ if (key.name)
68
+ return key.name;
69
+ }
70
+ return undefined;
71
+ };
72
+ return {
73
+ set: (target, propertyKey, data) => {
74
+ var _a, _b, _c, _d;
75
+ const root = Metadata.get(target);
76
+ const scoped = ((_a = root[name]) !== null && _a !== void 0 ? _a : (root[name] = {}));
77
+ const key = resolveKey(propertyKey);
78
+ if (key === undefined) {
79
+ Object.assign(((_b = scoped.common) !== null && _b !== void 0 ? _b : (scoped.common = {})), data);
80
+ return;
81
+ }
82
+ const methods = ((_c = scoped.methods) !== null && _c !== void 0 ? _c : (scoped.methods = {}));
83
+ Object.assign(((_d = methods[key]) !== null && _d !== void 0 ? _d : (methods[key] = {})), data);
84
+ },
85
+ get: (target, propertyKey) => {
86
+ var _a, _b, _c;
87
+ const root = Metadata.get(target);
88
+ const scoped = root[name];
89
+ if (!scoped) {
90
+ return {};
91
+ }
92
+ const key = resolveKey(propertyKey);
93
+ if (key === undefined) {
94
+ return ((_a = scoped.common) !== null && _a !== void 0 ? _a : (scoped.common = {}));
95
+ }
96
+ return (_c = (_b = scoped.methods) === null || _b === void 0 ? void 0 : _b[key]) !== null && _c !== void 0 ? _c : {};
97
+ },
98
+ };
99
+ }
100
+ /**
101
+ * Get all tracked classes.
102
+ */
103
+ static getTrackedClasses() {
104
+ return [...globalIndex];
105
+ }
106
+ }
107
+ exports.Metadata = Metadata;
@@ -0,0 +1,14 @@
1
+ import { ScopeMap } from "../../lib/server/decorators";
2
+ /**
3
+ * This class is a store for the scopes that are defined in the application.
4
+ *
5
+ */
6
+ export declare class ScopeStore {
7
+ private static scopes;
8
+ static add(scope: ScopeMap): void;
9
+ static addAll(scopes: ScopeMap[]): void;
10
+ static getScopes(): ScopeMap[];
11
+ static getScopeNames(): string[];
12
+ static isEmpty(): boolean;
13
+ static clear(): void;
14
+ }
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ScopeStore = void 0;
4
+ /**
5
+ * This class is a store for the scopes that are defined in the application.
6
+ *
7
+ */
8
+ class ScopeStore {
9
+ static add(scope) {
10
+ this.scopes.set(scope.scope, scope); // Evita duplicados basados en el nombre del scope
11
+ }
12
+ static addAll(scopes) {
13
+ scopes.forEach((scope) => this.add(scope));
14
+ }
15
+ static getScopes() {
16
+ return Array.from(this.scopes.values());
17
+ }
18
+ static getScopeNames() {
19
+ return Array.from(this.scopes.keys());
20
+ }
21
+ static isEmpty() {
22
+ return this.scopes.size === 0;
23
+ }
24
+ static clear() {
25
+ this.scopes.clear();
26
+ }
27
+ }
28
+ exports.ScopeStore = ScopeStore;
29
+ ScopeStore.scopes = new Map();
@@ -0,0 +1 @@
1
+ export declare const serviceStore: Set<any>;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.serviceStore = void 0;
4
+ exports.serviceStore = new Set();
@@ -1,3 +1,3 @@
1
1
  import { MiddlewareHandler } from "hyper-express";
2
- import { MiddlewareType } from "../../decorators";
2
+ import { MiddlewareType } from "../../lib/server/decorators";
3
3
  export default function middlewareTransformer(list: MiddlewareType[]): MiddlewareHandler[];
@@ -4,7 +4,7 @@ exports.default = middlewareTransformer;
4
4
  const tsyringe_1 = require("tsyringe");
5
5
  function middlewareTransformer(list) {
6
6
  return list
7
- .map((middleware) => {
7
+ .map((middleware, idx) => {
8
8
  if (isClass(middleware)) {
9
9
  const instance = tsyringe_1.container.resolve(middleware);
10
10
  return instance.handle.bind(instance);
@@ -1,5 +1,5 @@
1
1
  import { MiddlewareHandler } from "hyper-express";
2
- import { RoleType } from "../../decorators";
2
+ import { RoleType } from "../../lib/server/decorators";
3
3
  export default function roleTransform(list: RoleType[], callback?: (middleware: MiddlewareHandler, roles: {
4
4
  role: string;
5
5
  description: string;
@@ -1,16 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = roleTransform;
4
- const exeptions_1 = require("../../exeptions");
5
- const helpers_1 = require("../../common/helpers");
6
- const constants_1 = require("../constants");
4
+ const exeptions_1 = require("../../lib/server/exeptions");
5
+ const role_1 = require("../../common/helpers/role");
6
+ const constants_1 = require("../../constants");
7
7
  function roleTransform(list, callback) {
8
8
  const { roles, names, isEmtpy } = resolveRoles(list);
9
9
  const middleware = (req, res, next) => {
10
10
  var _a;
11
11
  if (isEmtpy)
12
12
  return next();
13
- const requestRoles = (_a = (0, helpers_1.getRoles)(req)) !== null && _a !== void 0 ? _a : [];
13
+ const requestRoles = (_a = (0, role_1.getRoles)(req)) !== null && _a !== void 0 ? _a : [];
14
14
  if (requestRoles.length === 0 && isEmtpy)
15
15
  return next();
16
16
  if (requestRoles.includes(constants_1.FULL_ACCESS))
@@ -1,5 +1,5 @@
1
1
  import { MiddlewareHandler } from "hyper-express/types";
2
- import { ScopeMap, ScopeType } from "../../decorators";
2
+ import { ScopeMap, ScopeType } from "../../lib/server/decorators";
3
3
  type Callback = (middleware: MiddlewareHandler, scopes: ScopeMap[], names: Set<string>) => void;
4
4
  export default function scopeTransfrom(listScopes: ScopeType[], ...callback: Callback[]): MiddlewareHandler;
5
5
  export {};
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = scopeTransfrom;
4
- const exeptions_1 = require("../../exeptions");
4
+ const exeptions_1 = require("../../lib/server/exeptions");
5
5
  const helpers_1 = require("../../common/helpers");
6
- const constants_1 = require("../constants");
6
+ const constants_1 = require("../../constants");
7
7
  function scopeTransfrom(listScopes, ...callback) {
8
8
  const { scopes, scopeNames, isEmpty } = resolveScopes(listScopes);
9
9
  const middleware = (req, res, next) => {
@@ -1,7 +1,56 @@
1
- import { RouteMetadata } from "../decorators";
2
- export interface RouterList {
3
- type: string;
4
- routes: Set<RouteMetadata>;
1
+ import { HyperAppMetadata, HyperModuleMetadata, HyperControllerMetadata, HyperParameterMetadata, RouteMetadata, Constructor, MiddlewareType, ScopeType, RoleType } from "../lib/server/decorators/types";
2
+ /**
3
+ * 🛠️ Shared Class-Level Metadata Keys
4
+ */
5
+ export interface HyperBaseCommon {
6
+ middlewares?: MiddlewareType[];
7
+ scopes?: ScopeType[];
8
+ roles?: RoleType[];
9
+ pass?: unknown;
10
+ }
11
+ /**
12
+ * 📦 Hierarchical Metadata Structure for Components
13
+ */
14
+ export type HyperCommonMetadata = (HyperAppMetadata & HyperBaseCommon & {
15
+ type: 'app';
16
+ }) | (HyperModuleMetadata & HyperBaseCommon & {
17
+ type: 'module';
18
+ }) | (HyperControllerMetadata & HyperBaseCommon & {
19
+ type: 'controller';
20
+ }) | (HyperBaseCommon & {
21
+ type: 'service';
22
+ });
23
+ /**
24
+ * 📡 Hierarchical Metadata Structure for Methods
25
+ */
26
+ export interface HyperMethodMetadata {
27
+ route?: RouteMetadata;
28
+ params?: HyperParameterMetadata;
29
+ middlewares?: MiddlewareType[];
30
+ scopes?: ScopeType[];
31
+ roles?: RoleType[];
32
+ onMessage?: {
33
+ topic: string;
34
+ };
35
+ output?: unknown;
36
+ reflection?: {
37
+ params?: (Constructor | Function)[];
38
+ output?: Constructor | Function;
39
+ };
40
+ }
41
+ /**
42
+ * 🌳 Root storage for a prefix segment (e.g. 'hyper')
43
+ */
44
+ export interface HyperPrefixRoot {
45
+ common: HyperCommonMetadata;
46
+ methods: Record<string, HyperMethodMetadata>;
47
+ }
48
+ /**
49
+ * 🏦 The global metadata store structure per class constructor
50
+ */
51
+ export interface HyperMetadataStore {
52
+ server?: HyperPrefixRoot;
53
+ openapi?: unknown;
5
54
  }
6
55
  export type HyperApplicationPrivate<T> = T & {
7
56
  prepare(): Promise<void>;
@@ -1,3 +1,7 @@
1
1
  import { IHyperApp, IHyperApplication } from "../type";
2
- export default function createApplication<T extends IHyperApplication>(app: new (...args: any[]) => T): Promise<IHyperApp<T>>;
3
- export { createApplication };
2
+ /**
3
+ * Creates a new HyperApplication.
4
+ *
5
+ * @param app
6
+ */
7
+ export declare function createApplication<T extends IHyperApplication>(application: new (...args: any[]) => T): Promise<IHyperApp<T>>;
@@ -9,21 +9,55 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.default = createApplication;
13
12
  exports.createApplication = createApplication;
14
13
  const tsyringe_1 = require("tsyringe");
15
14
  const message_bus_1 = require("./message-bus");
16
- function createApplication(app) {
15
+ const stores_1 = require("../__internals/stores");
16
+ const prepare_helper_1 = require("../__internals/helpers/prepare.helper");
17
+ const transform_registry_1 = require("../__internals/transform/transform.registry");
18
+ /**
19
+ * Creates a new HyperApplication.
20
+ *
21
+ * @param app
22
+ */
23
+ function createApplication(application) {
17
24
  return __awaiter(this, void 0, void 0, function* () {
18
- var _a;
19
- const instance = tsyringe_1.container.resolve(app);
20
- if (instance.prepare) {
21
- yield instance.prepare();
25
+ const metadata = stores_1.HyperMeta.get(application);
26
+ if (metadata.type !== "app") {
27
+ throw new Error("Application must be decorated with @HyperApp");
22
28
  }
23
- (_a = instance === null || instance === void 0 ? void 0 : instance.onPrepare) === null || _a === void 0 ? void 0 : _a.call(instance);
24
- instance.emit = (topic, data) => __awaiter(this, void 0, void 0, function* () {
25
- yield message_bus_1.MessageBus.emit(topic, data);
29
+ const logger = metadata.logger || console.log;
30
+ const logWrapper = (space, msg) => logger(`[${space}] ${msg}`);
31
+ const appServer = yield (0, prepare_helper_1.prepareApplication)(metadata, application, logWrapper);
32
+ const appInstance = tsyringe_1.container.resolve(application);
33
+ const appProxy = new Proxy(appInstance, {
34
+ get(target, prop) {
35
+ if (prop === "useTransform") {
36
+ return (transformer) => {
37
+ transform_registry_1.transformRegistry.register(transformer);
38
+ return appProxy;
39
+ };
40
+ }
41
+ if (prop === "emit") {
42
+ return (topic, data) => __awaiter(this, void 0, void 0, function* () {
43
+ const bus = tsyringe_1.container.resolve(message_bus_1.MessageBus);
44
+ yield bus.emit(topic, data);
45
+ });
46
+ }
47
+ // Prioritize application instance methods/props
48
+ if (prop in target) {
49
+ const value = target[prop];
50
+ return typeof value === "function" ? value.bind(target) : value;
51
+ }
52
+ // Fallback to hyper-express server
53
+ const serverValue = appServer[prop];
54
+ return typeof serverValue === "function" ? serverValue.bind(appServer) : serverValue;
55
+ },
26
56
  });
27
- return instance;
57
+ if ("onPrepare" in appInstance && typeof appInstance.onPrepare === "function") {
58
+ const onPrepare = appInstance.onPrepare.bind(appInstance);
59
+ yield onPrepare();
60
+ }
61
+ return appProxy;
28
62
  });
29
63
  }
@@ -4,6 +4,7 @@ export interface IMessageTransport {
4
4
  }
5
5
  export declare class InternalTransport implements IMessageTransport {
6
6
  private emitter;
7
+ private wildcardHandlers;
7
8
  listen(topic: string, handler: (data: any) => Promise<void> | void): Promise<void>;
8
9
  emit(topic: string, data: any): Promise<void>;
9
10
  }
@@ -1,4 +1,10 @@
1
1
  "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
2
8
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
9
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
10
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -10,25 +16,23 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
16
  };
11
17
  Object.defineProperty(exports, "__esModule", { value: true });
12
18
  exports.InternalTransport = void 0;
19
+ const tsyringe_1 = require("tsyringe");
13
20
  const eventemitter3_1 = require("eventemitter3");
14
- class InternalTransport {
21
+ let InternalTransport = class InternalTransport {
15
22
  constructor() {
16
23
  this.emitter = new eventemitter3_1.EventEmitter();
24
+ this.wildcardHandlers = [];
17
25
  }
18
26
  listen(topic, handler) {
19
27
  return __awaiter(this, void 0, void 0, function* () {
20
- // Basic wildcard support: user.* -> user.created, user.updated
21
- // We'll use a simple regex for this internal transport
22
28
  if (topic.includes("*")) {
23
- const pattern = new RegExp("^" + topic.replace(/\*/g, ".*") + "$");
24
- // We need a catch-all for wildcards in EventEmitter3?
25
- // EE3 doesn't support wildcards out of the box easily without listening to all events.
26
- // For this internal implementation, we'll override emit or use a proxy.
27
- // But simpler: just use a pattern-matching listener.
28
- this.emitter.on("message", (t, data) => {
29
- if (pattern.test(t)) {
30
- handler(data);
31
- }
29
+ const patternString = topic
30
+ .replace(/[+?^${}()|[\]\\]/g, "\\$&")
31
+ .replace(/\./g, "\\.")
32
+ .replace(/\*/g, ".*");
33
+ this.wildcardHandlers.push({
34
+ pattern: new RegExp(`^${patternString}$`),
35
+ handler,
32
36
  });
33
37
  }
34
38
  else {
@@ -38,9 +42,18 @@ class InternalTransport {
38
42
  }
39
43
  emit(topic, data) {
40
44
  return __awaiter(this, void 0, void 0, function* () {
45
+ // 1. Regular emit
41
46
  this.emitter.emit(topic, data);
42
- this.emitter.emit("message", topic, data); // For wildcard listeners
47
+ // 2. Wildcard checks
48
+ for (const item of this.wildcardHandlers) {
49
+ if (item.pattern.test(topic)) {
50
+ yield item.handler(data);
51
+ }
52
+ }
43
53
  });
44
54
  }
45
- }
55
+ };
46
56
  exports.InternalTransport = InternalTransport;
57
+ exports.InternalTransport = InternalTransport = __decorate([
58
+ (0, tsyringe_1.singleton)()
59
+ ], InternalTransport);
@@ -1,3 +1,4 @@
1
1
  export declare const HYPER_SCOPES_KEY = "__HYPER_SCOPES_KEY";
2
2
  export declare const HYPER_ROLE_KEY = "__HYPER_ROLE_KEY";
3
3
  export declare const HYPER_PASS_KEY = "__HYPER_PASS_KEY";
4
+ export declare const FULL_ACCESS = "*";
package/dist/constants.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HYPER_PASS_KEY = exports.HYPER_ROLE_KEY = exports.HYPER_SCOPES_KEY = void 0;
3
+ exports.FULL_ACCESS = exports.HYPER_PASS_KEY = exports.HYPER_ROLE_KEY = exports.HYPER_SCOPES_KEY = void 0;
4
4
  exports.HYPER_SCOPES_KEY = "__HYPER_SCOPES_KEY";
5
5
  exports.HYPER_ROLE_KEY = "__HYPER_ROLE_KEY";
6
6
  exports.HYPER_PASS_KEY = "__HYPER_PASS_KEY";
7
+ exports.FULL_ACCESS = "*";
@@ -14,49 +14,9 @@ import { ParameterResolver } from "./types";
14
14
  * \@Query(UserQueryDto)
15
15
  */
16
16
  export declare function Query(keyOrSchema?: string | any, schemaOrTransform?: any): any;
17
- /**
18
- * Get the body of the request or transform it via a schema.
19
- *
20
- * @example
21
- * \@Body()
22
- * \@Body(CreateUserDto)
23
- */
24
- export declare function Body(schemaOrResolver?: any): any;
25
- /**
26
- * Get the params from the request or transform via schema.
27
- *
28
- * @example
29
- * \@Param('id')
30
- * \@Param('id', IntSchema)
31
- */
32
- export declare function Param(keyOrSchema: string | any, schemaOrValidator?: any): any;
33
- /**
34
- * Get the headers from the request.
35
- */
36
- export declare function Headers(keyOrSchema?: string | any, schema?: any): any;
17
+ export declare function Body(keyOrSchema?: string | any, schemaOrTransform?: any): any;
18
+ export declare function Param(keyOrSchema: string | any, schemaOrTransform?: any): any;
19
+ export declare function Headers(keyOrSchema?: string | any, schemaOrTransform?: any): any;
37
20
  export declare const Req: () => ParameterDecorator;
38
21
  export declare const Res: () => ParameterDecorator;
39
- /**
40
- * Create a custom request decorator
41
- * that can be used to extract data from the request object
42
- *
43
- *
44
- * @example
45
- * ```typescript
46
- *
47
- * interface LoginData {
48
- * username: string;
49
- * password: string;
50
- * }
51
- *
52
- * const LoginData = createCustomRequestDecorator<LoginData>({
53
- * resolver: async (request) => {
54
- * const data = await request.json();
55
- * return [data];
56
- * }
57
- * }
58
- *
59
- *
60
- *
61
- */
62
22
  export declare const createCustomRequestDecorator: (decoratorName: string, resolver: ParameterResolver) => ParameterDecorator;