@zenofolio/hyper-decor 1.0.61 → 1.0.63

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 (72) hide show
  1. package/dist/__internals/constants.d.ts +1 -0
  2. package/dist/__internals/constants.js +1 -0
  3. package/dist/__internals/decorator-base.js +46 -10
  4. package/dist/__internals/helpers/imports.helper.d.ts +2 -2
  5. package/dist/__internals/helpers/imports.helper.js +68 -21
  6. package/dist/__internals/helpers/lifecycle.helper.d.ts +3 -0
  7. package/dist/__internals/helpers/lifecycle.helper.js +25 -0
  8. package/dist/__internals/helpers/merge-metadata.js +16 -20
  9. package/dist/__internals/helpers/prepare.helper.js +85 -52
  10. package/dist/__internals/helpers/tree.helper.d.ts +32 -0
  11. package/dist/__internals/helpers/tree.helper.js +48 -0
  12. package/dist/__internals/transform/middleware.transform.js +0 -2
  13. package/dist/__internals/transform/role.transform.js +5 -5
  14. package/dist/__internals/transform/scope.transfrom.js +2 -3
  15. package/dist/common/bootstrap.js +4 -0
  16. package/dist/common/helpers/role.js +1 -4
  17. package/dist/common/message-bus.d.ts +11 -0
  18. package/dist/common/message-bus.js +51 -0
  19. package/dist/common/transport.d.ts +9 -0
  20. package/dist/common/transport.js +46 -0
  21. package/dist/decorators/HyperApp.js +3 -1
  22. package/dist/decorators/HyperService.d.ts +2 -1
  23. package/dist/decorators/HyperService.js +6 -4
  24. package/dist/decorators/Messaging.d.ts +10 -0
  25. package/dist/decorators/Messaging.js +22 -0
  26. package/dist/decorators/Middleware.d.ts +1 -1
  27. package/dist/decorators/Middleware.js +14 -2
  28. package/dist/decorators/index.d.ts +1 -0
  29. package/dist/decorators/index.js +1 -0
  30. package/dist/decorators/types.d.ts +21 -4
  31. package/dist/index.d.ts +3 -0
  32. package/dist/index.js +3 -0
  33. package/dist/type.d.ts +5 -2
  34. package/dist/vitest.config.d.ts +2 -0
  35. package/dist/vitest.config.js +34 -0
  36. package/package.json +66 -59
  37. package/scripts/clean.js +56 -0
  38. package/vitest.config.mjs +30 -0
  39. package/vitest.json +0 -0
  40. package/.mocharc.js +0 -5
  41. package/dist/__internals/store.d.ts +0 -29
  42. package/dist/__internals/store.js +0 -17
  43. package/dist/__internals/stores/index.d.ts +0 -15
  44. package/dist/__internals/stores/index.js +0 -37
  45. package/dist/__internals/stores/middleware.store.d.ts +0 -7
  46. package/dist/__internals/stores/middleware.store.js +0 -19
  47. package/dist/__internals/stores/params.store.d.ts +0 -21
  48. package/dist/__internals/stores/params.store.js +0 -65
  49. package/dist/__internals/stores/routes.store.d.ts +0 -17
  50. package/dist/__internals/stores/routes.store.js +0 -43
  51. package/dist/__internals/stores/store.interface.d.ts +0 -8
  52. package/dist/__internals/stores/store.interface.js +0 -2
  53. package/dist/__internals/transform/method.transform.d.ts +0 -2
  54. package/dist/__internals/transform/method.transform.js +0 -20
  55. package/dist/__internals/transform/pass.transfrom.d.ts +0 -1
  56. package/dist/__internals/transform/pass.transfrom.js +0 -2
  57. package/dist/__internals/utils/mixin.utils.d.ts +0 -11
  58. package/dist/__internals/utils/mixin.utils.js +0 -34
  59. package/dist/__internals/utils/router.d.ts +0 -1
  60. package/dist/__internals/utils/router.js +0 -2
  61. package/dist/collectors/index.d.ts +0 -1
  62. package/dist/collectors/index.js +0 -17
  63. package/dist/collectors/scope.collector.d.ts +0 -14
  64. package/dist/collectors/scope.collector.js +0 -29
  65. package/dist/common/openapi/collect-class-data.d.ts +0 -21
  66. package/dist/common/openapi/collect-class-data.js +0 -45
  67. package/dist/common/openapi/collect-function-data.d.ts +0 -32
  68. package/dist/common/openapi/collect-function-data.js +0 -70
  69. package/dist/common/openapi/index.d.ts +0 -2
  70. package/dist/common/openapi/index.js +0 -18
  71. package/dist/decorators/Service.d.ts +0 -5
  72. package/dist/decorators/Service.js +0 -16
@@ -0,0 +1,30 @@
1
+ import { defineConfig } from 'vitest/config';
2
+ import swc from 'unplugin-swc';
3
+
4
+ export default defineConfig({
5
+ test: {
6
+ globals: true,
7
+ environment: 'node',
8
+ include: ['tests/**/*.{test,spec,bench}.ts', 'tests/*.{test,spec,bench}.ts'],
9
+ poolOptions: {
10
+ threads: {
11
+ singleThread: true,
12
+ },
13
+ },
14
+ },
15
+ plugins: [
16
+ swc.vite({
17
+ jsc: {
18
+ parser: {
19
+ syntax: 'typescript',
20
+ decorators: true,
21
+ dynamicImport: true,
22
+ },
23
+ transform: {
24
+ legacyDecorator: true,
25
+ decoratorMetadata: true,
26
+ },
27
+ },
28
+ }),
29
+ ],
30
+ });
package/vitest.json ADDED
Binary file
package/.mocharc.js DELETED
@@ -1,5 +0,0 @@
1
- module.exports = {
2
- "extension": ["ts", "cjs"],
3
- "spec": "**/*.test.ts",
4
- "require": "ts-node/register"
5
- };
@@ -1,29 +0,0 @@
1
- import { MiddlewareHandler } from "hyper-express";
2
- import { RoleType, ScopeType } from "../decorators";
3
- interface HyperAppStoreItemBase {
4
- middlewares: Set<MiddlewareHandler>;
5
- roles: Set<RoleType>;
6
- scopes: Set<ScopeType>;
7
- }
8
- interface HyperAppStoreRoute extends HyperAppStoreItemBase {
9
- method: string;
10
- path: string;
11
- handler: string;
12
- }
13
- export interface HyperAppStoreController extends HyperAppStoreItemBase {
14
- routes: Map<string, HyperAppStoreRoute>;
15
- }
16
- export interface HyperAppStoreModule {
17
- controllers: Map<string, string>;
18
- }
19
- export default class HyperAppStore {
20
- private roles;
21
- private scopes;
22
- private modules;
23
- private controllers;
24
- private routes;
25
- private middlewares;
26
- addRole(role: string): void;
27
- addModuleRole(module: string, role: string): void;
28
- }
29
- export {};
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class HyperAppStore {
4
- constructor() {
5
- this.roles = new Set();
6
- this.scopes = new Set();
7
- this.modules = new Map();
8
- this.controllers = new Map();
9
- this.routes = new Map();
10
- this.middlewares = new Map();
11
- }
12
- addRole(role) {
13
- this.roles.add(role);
14
- }
15
- addModuleRole(module, role) { }
16
- }
17
- exports.default = HyperAppStore;
@@ -1,15 +0,0 @@
1
- interface MetadataStoreOptions {
2
- target: any;
3
- propertyKey?: string | symbol;
4
- descriptorOrIndex?: any;
5
- }
6
- declare class MetadatStore {
7
- static define(key: string | symbol, value: any, { target, propertyKey }: MetadataStoreOptions): void;
8
- static get<T>(key: string | symbol, { target, propertyKey }: MetadataStoreOptions, def: T): T;
9
- static list<T extends any = any>(key: string | symbol, { target, propertyKey }: MetadataStoreOptions): {
10
- has: () => boolean;
11
- get: () => never[];
12
- set: (...value: T[]) => void;
13
- };
14
- }
15
- export default MetadatStore;
@@ -1,37 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const object_util_1 = require("../utils/object.util");
4
- class MetadatStore {
5
- static define(key, value, { target, propertyKey }) {
6
- if (target && typeof propertyKey === "string") {
7
- Reflect.defineMetadata(key, value, Reflect.get(target, propertyKey));
8
- }
9
- else {
10
- Reflect.defineMetadata(key, value, (0, object_util_1.$constructor)(target));
11
- }
12
- }
13
- static get(key, { target, propertyKey }, def) {
14
- if (target && typeof propertyKey === "string") {
15
- return Reflect.getMetadata(key, Reflect.get(target, propertyKey)) || def;
16
- }
17
- else {
18
- return Reflect.getMetadata(key, (0, object_util_1.$constructor)(target)) || def;
19
- }
20
- }
21
- static list(key, { target, propertyKey }) {
22
- return {
23
- has: () => {
24
- return this.get(key, { target, propertyKey }, []).length > 0;
25
- },
26
- get: () => {
27
- return this.get(key, { target, propertyKey }, []);
28
- },
29
- set: (...value) => {
30
- const list = this.get(key, { target, propertyKey }, []);
31
- list.push(...value);
32
- this.define(key, list, { target, propertyKey });
33
- },
34
- };
35
- }
36
- }
37
- exports.default = MetadatStore;
@@ -1,7 +0,0 @@
1
- import "reflect-metadata";
2
- import { MiddlewareHandler } from "hyper-express";
3
- export declare const middlewareStore: Readonly<{
4
- get(target: any): any;
5
- has(target: any): boolean;
6
- set(target: any, ...middlewares: MiddlewareHandler[]): void;
7
- }>;
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.middlewareStore = void 0;
4
- require("reflect-metadata");
5
- const constants_1 = require("../constants");
6
- const { MIDDLEWARES } = constants_1.METADATA_KEYS;
7
- exports.middlewareStore = Object.freeze({
8
- get(target) {
9
- return Reflect.getMetadata(MIDDLEWARES, target);
10
- },
11
- has(target) {
12
- return !!this.get(target);
13
- },
14
- set(target, ...middlewares) {
15
- const list = this.get(target) || [];
16
- list.push(...middlewares);
17
- Reflect.defineMetadata(MIDDLEWARES, list, target);
18
- },
19
- });
@@ -1,21 +0,0 @@
1
- import { Request, Response } from "hyper-express";
2
- export type ByPassKeys = "req" | "res";
3
- export type IParamsResolver = (req: Request, res: Response) => any | Promise<any>;
4
- export type IStoreParams = {
5
- name: string;
6
- type: any;
7
- index: number;
8
- key: string;
9
- propertyKey: string;
10
- resolver: IParamsResolver;
11
- };
12
- export type IStoreParamsMap = Map<string, IStoreParams>;
13
- export declare const paramsStore: Readonly<{
14
- has(target: any, propety: any, key: string): boolean;
15
- get(target: any, propety?: any): IStoreParamsMap | undefined;
16
- set(target: any, propety: any, value: IStoreParams): void;
17
- delete(target: any, propety: any): void;
18
- support(target: any, propety: any): boolean;
19
- prepareArgs(target: any, propety: any, req: Request, res: Response): Promise<any[]>;
20
- intercept(target: any, propety: any, req: Request, res: Response): Promise<void>;
21
- }>;
@@ -1,65 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.paramsStore = void 0;
13
- const no_conflict_1 = require("reflect-metadata/no-conflict");
14
- const constants_1 = require("../constants");
15
- exports.paramsStore = Object.freeze({
16
- has(target, propety, key) {
17
- const data = this.get(target, propety);
18
- return data ? data.has(key) : false;
19
- },
20
- get(target, propety) {
21
- if (!propety) {
22
- return (0, no_conflict_1.getMetadata)(constants_1.KEY_PARAMS_PARAM, target);
23
- }
24
- return (0, no_conflict_1.getMetadata)(constants_1.KEY_PARAMS_PARAM, target, propety);
25
- },
26
- set(target, propety, value) {
27
- const data = this.get(target, propety) || new Map();
28
- data.set(value.key, value);
29
- (0, no_conflict_1.defineMetadata)(constants_1.KEY_PARAMS_PARAM, data, target, propety);
30
- },
31
- delete(target, propety) {
32
- (0, no_conflict_1.deleteMetadata)(constants_1.KEY_PARAMS_PARAM, target, propety);
33
- },
34
- support(target, propety) {
35
- const params = (0, no_conflict_1.getMetadata)(constants_1.DESIGN_PARAMTYPES, target, propety) || [];
36
- return params.length > 0;
37
- },
38
- prepareArgs(target, propety, req, res) {
39
- return __awaiter(this, void 0, void 0, function* () {
40
- const data = this.get(target, propety);
41
- if (!data)
42
- return [];
43
- const args = [];
44
- yield Promise.all(Array.from(data.values()).map((value) => __awaiter(this, void 0, void 0, function* () {
45
- const { key, resolver } = value;
46
- switch (key) {
47
- case "req":
48
- args[value.index] = req;
49
- break;
50
- case "res":
51
- args[value.index] = res;
52
- break;
53
- default: {
54
- const result = yield resolver(req, res);
55
- args[value.index] = result;
56
- }
57
- }
58
- })));
59
- return args;
60
- });
61
- },
62
- intercept(target, propety, req, res) {
63
- return __awaiter(this, void 0, void 0, function* () { });
64
- },
65
- });
@@ -1,17 +0,0 @@
1
- import { IStore } from "./store.interface";
2
- interface IRoute {
3
- className: string;
4
- method: string;
5
- path: string;
6
- handler: (...args: any[]) => any;
7
- }
8
- export declare class RouteStore implements IStore<any> {
9
- has(target: any, property?: any): boolean;
10
- get(target: any, property?: any): Set<IRoute> | undefined;
11
- set(target: any, property: any, value: IRoute): void;
12
- create(target: any, property?: any, key?: any): Set<IRoute> | null;
13
- delete(target: any, value?: IRoute): void;
14
- support(target: any, property: any): boolean;
15
- }
16
- declare const routeStore: RouteStore;
17
- export { routeStore };
@@ -1,43 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.routeStore = exports.RouteStore = void 0;
4
- const no_conflict_1 = require("reflect-metadata/no-conflict");
5
- const constants_1 = require("../constants");
6
- class RouteStore {
7
- has(target, property) {
8
- return (0, no_conflict_1.hasMetadata)(constants_1.METADATA_KEYS.ROUTES, target);
9
- }
10
- get(target, property) {
11
- return (0, no_conflict_1.getMetadata)(constants_1.METADATA_KEYS.ROUTES, target);
12
- }
13
- set(target, property, value) {
14
- const routes = this.get(target) || new Set();
15
- routes.add(value);
16
- (0, no_conflict_1.defineMetadata)(constants_1.METADATA_KEYS.ROUTES, routes, target);
17
- }
18
- create(target, property, key) {
19
- const data = this.has(target, property)
20
- ? this.get(target, property)
21
- : new Set();
22
- (0, no_conflict_1.defineMetadata)(constants_1.METADATA_KEYS.ROUTES, data, target);
23
- return data;
24
- }
25
- delete(target, value) {
26
- const routes = this.create(target, value === null || value === void 0 ? void 0 : value.className);
27
- if (!routes)
28
- return;
29
- if (value) {
30
- routes.delete(value);
31
- (0, no_conflict_1.defineMetadata)(constants_1.METADATA_KEYS.ROUTES, routes, target);
32
- }
33
- else {
34
- (0, no_conflict_1.deleteMetadata)(constants_1.METADATA_KEYS.ROUTES, target);
35
- }
36
- }
37
- support(target, property) {
38
- return this.has(target, property);
39
- }
40
- }
41
- exports.RouteStore = RouteStore;
42
- const routeStore = new RouteStore();
43
- exports.routeStore = routeStore;
@@ -1,8 +0,0 @@
1
- export interface IStore<T> {
2
- has(target: any, property: any): boolean;
3
- get(target: any, property: any): T | undefined;
4
- set(target: any, property: any, value: T): void;
5
- create(target: any, property: any, extra?: Partial<T>): T | null;
6
- delete(target: any, property?: any): void;
7
- support(target: any, property: any): boolean;
8
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +0,0 @@
1
- import "reflect-metadata";
2
- export default function methodTransformer(target: any, key: string | symbol, transfrom?: (...args: any[]) => any): void;
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = methodTransformer;
4
- require("reflect-metadata");
5
- function methodTransformer(target, key, transfrom) {
6
- const prototype = target.constructor.prototype;
7
- if (!prototype || prototype.__transformed)
8
- return;
9
- prototype.__transformed = true;
10
- const original = Reflect.getOwnMetadata(key, target);
11
- if (!(original === null || original === void 0 ? void 0 : original.value))
12
- return;
13
- console.log(original, "original");
14
- original.value = function (...args) {
15
- console.log("Before method call", args);
16
- };
17
- // const descriptor = Object.getOwnPropertyDescriptor(prototype, key);
18
- // if(!descriptor) return;
19
- // console.log(descriptor, "descriptor");
20
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,11 +0,0 @@
1
- import "reflect-metadata";
2
- type Constructor<T = any> = new (...args: any[]) => T;
3
- export declare class MixinBuilder<TClass extends Constructor<any>, Type = InstanceType<TClass>> {
4
- private __class;
5
- constructor(__class: TClass);
6
- mix<NClass extends Constructor<any>>(clazz: NClass): MixinBuilder<NClass & TClass>;
7
- build(): TClass;
8
- construct(...args: any[]): Type;
9
- static mix<NClass extends Constructor<any>>(clazz: NClass): MixinBuilder<NClass, InstanceType<NClass>>;
10
- }
11
- export {};
@@ -1,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MixinBuilder = void 0;
4
- require("reflect-metadata");
5
- class MixinBuilder {
6
- constructor(__class) {
7
- this.__class = __class;
8
- }
9
- mix(clazz) {
10
- return new MixinBuilder(Mix(this.__class, clazz));
11
- }
12
- build() {
13
- return this.__class;
14
- }
15
- construct(...args) {
16
- return new this.__class(...args);
17
- }
18
- ////////////////////////////
19
- /// Static methods
20
- ////////////////////////////
21
- static mix(clazz) {
22
- return new MixinBuilder(clazz);
23
- }
24
- }
25
- exports.MixinBuilder = MixinBuilder;
26
- const Mix = (a, b) => {
27
- return class extends a {
28
- constructor(...args) {
29
- super(...args);
30
- Object.assign(this, new b(...args));
31
- console.log(a);
32
- }
33
- };
34
- };
@@ -1 +0,0 @@
1
- export {};
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +0,0 @@
1
- export * from "./scope.collector";
@@ -1,17 +0,0 @@
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("./scope.collector"), exports);
@@ -1,14 +0,0 @@
1
- import { ScopeMap } from "../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
- }
@@ -1,29 +0,0 @@
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();
@@ -1,21 +0,0 @@
1
- import "reflect-metadata";
2
- /**
3
- * Options to customize class metadata extraction.
4
- */
5
- interface ClassDataOptions {
6
- includePrivateMethods?: boolean;
7
- methodOptions?: Record<string, any>;
8
- }
9
- /**
10
- * Extracts metadata from a class, including methods and OpenAPI data.
11
- *
12
- * @param Target - The class constructor.
13
- * @param options - Options for metadata extraction.
14
- * @returns Object containing class metadata and method details.
15
- */
16
- export declare function collectClassData(Target: new (...args: any[]) => any, options?: ClassDataOptions): {
17
- className: string;
18
- methods: Record<string, any>;
19
- staticMethods: Record<string, any>;
20
- };
21
- export {};
@@ -1,45 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.collectClassData = collectClassData;
4
- require("reflect-metadata");
5
- const collect_function_data_1 = require("./collect-function-data");
6
- /**
7
- * Extracts metadata from a class, including methods and OpenAPI data.
8
- *
9
- * @param Target - The class constructor.
10
- * @param options - Options for metadata extraction.
11
- * @returns Object containing class metadata and method details.
12
- */
13
- function collectClassData(Target, options = {}) {
14
- if (typeof Target !== "function") {
15
- throw new Error("Target must be a class constructor.");
16
- }
17
- const prototype = Target.prototype;
18
- const className = Target.name;
19
- // Get method names
20
- const allMethods = Object.getOwnPropertyNames(prototype).filter((name) => typeof prototype[name] === "function" && name !== "constructor");
21
- // Get static methods
22
- const staticMethods = Object.getOwnPropertyNames(Target).filter((name) => typeof Target[name] === "function");
23
- // Filter private methods (if not included)
24
- const isPrivate = (name) => name.startsWith("_");
25
- const methods = options.includePrivateMethods
26
- ? allMethods
27
- : allMethods.filter((m) => !isPrivate(m));
28
- // Extract metadata for each method
29
- const methodsData = methods.reduce((acc, methodName) => {
30
- var _a;
31
- acc[methodName] = (0, collect_function_data_1.collectFunctionData)(prototype[methodName], ((_a = options.methodOptions) === null || _a === void 0 ? void 0 : _a[methodName]) || {});
32
- return acc;
33
- }, {});
34
- // Extract metadata for static methods
35
- const staticMethodsData = staticMethods.reduce((acc, methodName) => {
36
- var _a;
37
- acc[methodName] = (0, collect_function_data_1.collectFunctionData)(Target[methodName], ((_a = options.methodOptions) === null || _a === void 0 ? void 0 : _a[methodName]) || {});
38
- return acc;
39
- }, {});
40
- return {
41
- className,
42
- methods: methodsData,
43
- staticMethods: staticMethodsData,
44
- };
45
- }
@@ -1,32 +0,0 @@
1
- type OpenAPIParamLocation = "query" | "path" | "body";
2
- type OpenAPIType = "string" | "number" | "boolean" | "object" | "array" | "any";
3
- /**
4
- * Options to customize OpenAPI metadata extraction.
5
- */
6
- interface FunctionDataOptions {
7
- paramLocation?: OpenAPIParamLocation;
8
- paramDescriptions?: Record<string, string>;
9
- responseDescriptions?: Record<number, string>;
10
- responseSchemas?: Record<number, any>;
11
- }
12
- /**
13
- * Extracts function metadata and adapts it for OpenAPI documentation.
14
- *
15
- * @param Target - The function to analyze.
16
- * @param options - Customization options for OpenAPI extraction.
17
- * @returns An object formatted for OpenAPI documentation.
18
- */
19
- export declare function collectFunctionData(Target: (...args: any[]) => any, options?: FunctionDataOptions): {
20
- operationId: string;
21
- parameters: {
22
- name: string;
23
- in: OpenAPIParamLocation;
24
- required: boolean;
25
- description: string;
26
- schema: {
27
- type: OpenAPIType;
28
- };
29
- }[];
30
- responses: Record<number, any>;
31
- };
32
- export {};
@@ -1,70 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.collectFunctionData = collectFunctionData;
4
- const constants_1 = require("../../__internals/constants");
5
- const function_util_1 = require("../../__internals/utils/function.util");
6
- /**
7
- * Maps TypeScript types to OpenAPI-compatible types.
8
- */
9
- const mapTypeToOpenAPI = (type) => {
10
- if (!type)
11
- return "any";
12
- const typeMap = {
13
- String: "string",
14
- Number: "number",
15
- Boolean: "boolean",
16
- Object: "object",
17
- Array: "array",
18
- };
19
- return type.name === "Array" ? "array" : typeMap[type.name] || "any";
20
- };
21
- /**
22
- * Formats the response schema for OpenAPI.
23
- */
24
- const formatResponseSchema = (type, description = "Successful response") => ({
25
- description,
26
- content: {
27
- "application/json": {
28
- schema: { type: mapTypeToOpenAPI(type) },
29
- },
30
- },
31
- });
32
- /**
33
- * Extracts function metadata and adapts it for OpenAPI documentation.
34
- *
35
- * @param Target - The function to analyze.
36
- * @param options - Customization options for OpenAPI extraction.
37
- * @returns An object formatted for OpenAPI documentation.
38
- */
39
- function collectFunctionData(Target, options = {}) {
40
- var _a;
41
- if (typeof Target !== "function") {
42
- throw new Error("Target must be a function.");
43
- }
44
- // Extract metadata
45
- const paramTypes = Reflect.getMetadata(constants_1.DESIGN_PARAMTYPES, Target) || [];
46
- const paramNames = (_a = (0, function_util_1.extreactArgsNames)(Target)) !== null && _a !== void 0 ? _a : [];
47
- const returnType = Reflect.getMetadata(constants_1.DESIGN_RETURNTYPE, Target);
48
- // Default locations and descriptions
49
- const { paramLocation = "query", paramDescriptions = {}, responseDescriptions = { 200: "Successful response" }, responseSchemas = {}, } = options;
50
- // Build OpenAPI parameters
51
- const parameters = paramNames.map((name, index) => ({
52
- name,
53
- in: paramLocation,
54
- required: true,
55
- description: paramDescriptions[name] || `Parameter ${name}`,
56
- schema: { type: mapTypeToOpenAPI(paramTypes[index]) },
57
- }));
58
- // Build OpenAPI responses
59
- const responses = {};
60
- Object.entries(responseDescriptions).forEach(([statusCode, description]) => {
61
- const code = Number(statusCode);
62
- responses[code] =
63
- responseSchemas[code] || formatResponseSchema(returnType, description);
64
- });
65
- return {
66
- operationId: Target.name || "anonymous",
67
- parameters,
68
- responses,
69
- };
70
- }