@zenofolio/hyper-decor 1.0.67 → 1.0.68

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 (56) hide show
  1. package/dist/__internals/constants.d.ts +2 -1
  2. package/dist/__internals/constants.js +2 -1
  3. package/dist/__internals/helpers/prepare.helper.js +33 -0
  4. package/dist/__internals/helpers/tree.helper.d.ts +8 -4
  5. package/dist/__internals/helpers/tree.helper.js +47 -14
  6. package/dist/__internals/transform/transform.registry.d.ts +33 -0
  7. package/dist/__internals/transform/transform.registry.js +59 -0
  8. package/dist/common/helpers/index.d.ts +1 -0
  9. package/dist/common/helpers/index.js +1 -0
  10. package/dist/common/helpers/state.d.ts +17 -0
  11. package/dist/common/helpers/state.js +44 -0
  12. package/dist/decorators/Http.js +1 -1
  13. package/dist/decorators/HyperApp.d.ts +0 -4
  14. package/dist/decorators/HyperApp.js +9 -6
  15. package/dist/decorators/Transform.d.ts +14 -0
  16. package/dist/decorators/Transform.js +18 -0
  17. package/dist/decorators/index.d.ts +1 -0
  18. package/dist/decorators/index.js +1 -0
  19. package/dist/extension.js +6 -0
  20. package/dist/lib/openapi/collectors/class.collector.js +24 -10
  21. package/dist/lib/openapi/collectors/index.d.ts +1 -0
  22. package/dist/lib/openapi/collectors/index.js +1 -0
  23. package/dist/lib/openapi/collectors/method.collector.d.ts +0 -1
  24. package/dist/lib/openapi/collectors/method.collector.js +21 -2
  25. package/dist/lib/openapi/collectors/schema.collector.d.ts +11 -0
  26. package/dist/lib/openapi/collectors/schema.collector.js +37 -0
  27. package/dist/lib/openapi/decorators/api-bearer-auth.decorator.d.ts +2 -0
  28. package/dist/lib/openapi/decorators/api-bearer-auth.decorator.js +10 -0
  29. package/dist/lib/openapi/decorators/api-method.decorator.d.ts +1 -1
  30. package/dist/lib/openapi/decorators/api-parameter.decorator.d.ts +1 -1
  31. package/dist/lib/openapi/decorators/api-request-body.decorator.d.ts +1 -1
  32. package/dist/lib/openapi/decorators/{api-response.decodator.d.ts → api-response.decorator.d.ts} +1 -1
  33. package/dist/lib/openapi/decorators/{api-response.decodator.js → api-response.decorator.js} +1 -1
  34. package/dist/lib/openapi/decorators/api-security.decorator.d.ts +1 -1
  35. package/dist/lib/openapi/decorators/api-security.decorator.js +2 -2
  36. package/dist/lib/openapi/decorators/index.d.ts +2 -1
  37. package/dist/lib/openapi/decorators/index.js +2 -1
  38. package/dist/lib/openapi/helpers/index.d.ts +1 -0
  39. package/dist/lib/openapi/helpers/index.js +1 -0
  40. package/dist/lib/openapi/helpers/openapi.helper.d.ts +7 -0
  41. package/dist/lib/openapi/helpers/openapi.helper.js +51 -0
  42. package/dist/lib/openapi/helpers/security.helper.d.ts +1 -1
  43. package/dist/lib/openapi/helpers/security.helper.js +10 -3
  44. package/dist/lib/openapi/index.d.ts +5 -0
  45. package/dist/lib/openapi/index.js +5 -0
  46. package/dist/lib/openapi/metadata.registry.d.ts +29 -0
  47. package/dist/lib/openapi/metadata.registry.js +41 -0
  48. package/dist/type.d.ts +8 -0
  49. package/package.json +8 -4
  50. package/tsconfig.json +18 -13
  51. package/dist/run-bench.d.ts +0 -1
  52. package/dist/run-bench.js +0 -190
  53. package/dist/scripts/test-server.d.ts +0 -1
  54. package/dist/scripts/test-server.js +0 -110
  55. package/dist/vitest.config.d.ts +0 -2
  56. package/dist/vitest.config.js +0 -34
@@ -0,0 +1,11 @@
1
+ import "reflect-metadata";
2
+ import { Schema } from "../types";
3
+ /**
4
+ * Collector responsible for transforming DTO classes into OpenAPI Schema objects.
5
+ * Uses design:type and property inspection.
6
+ */
7
+ export declare function collectSchema(Target: any): Schema;
8
+ /**
9
+ * Infer OpenAPI type from JavaScript constructor names.
10
+ */
11
+ export declare function inferType(constructorName: string): string;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.collectSchema = collectSchema;
4
+ exports.inferType = inferType;
5
+ require("reflect-metadata");
6
+ /**
7
+ * Collector responsible for transforming DTO classes into OpenAPI Schema objects.
8
+ * Uses design:type and property inspection.
9
+ */
10
+ function collectSchema(Target) {
11
+ if (!Target || typeof Target !== "function") {
12
+ return { type: "object" };
13
+ }
14
+ const schema = {
15
+ type: "object",
16
+ properties: {},
17
+ };
18
+ // Note: Standard reflect-metadata has limitations for property enumeration.
19
+ // In a full implementation, we might use a custom decorator or
20
+ // class-transformer/class-validator if available.
21
+ // For now, we provide the structure to be extended.
22
+ return schema;
23
+ }
24
+ /**
25
+ * Infer OpenAPI type from JavaScript constructor names.
26
+ */
27
+ function inferType(constructorName) {
28
+ const map = {
29
+ String: "string",
30
+ Number: "number",
31
+ Boolean: "boolean",
32
+ Array: "array",
33
+ Object: "object",
34
+ Date: "string", // Dates are strings in OpenAPI
35
+ };
36
+ return map[constructorName] || "string";
37
+ }
@@ -0,0 +1,2 @@
1
+ import 'reflect-metadata';
2
+ export declare function ApiBearerAuth(name?: string): (target: any, propertyKey?: any, descriptor?: any) => void;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ApiBearerAuth = ApiBearerAuth;
4
+ require("reflect-metadata");
5
+ const security_helper_1 = require("../helpers/security.helper");
6
+ function ApiBearerAuth(name = 'bearerAuth') {
7
+ return (target, propertyKey, descriptor) => {
8
+ (0, security_helper_1.apiSecurity)(target, { [name]: [] }, propertyKey);
9
+ };
10
+ }
@@ -1,3 +1,3 @@
1
1
  import "reflect-metadata";
2
2
  import { Operation } from "../types";
3
- export declare function ApiMethod(options: Partial<Operation>): MethodDecorator;
3
+ export declare function ApiMethod(options: Partial<Operation>): <T>(target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<T>) => any;
@@ -1,3 +1,3 @@
1
1
  import 'reflect-metadata';
2
2
  import { Parameter } from '../types';
3
- export declare function ApiParameter(options: Parameter): (target: any, propertyKey: string) => void;
3
+ export declare function ApiParameter(options: Parameter): (target: any, propertyKey: any) => void;
@@ -1,3 +1,3 @@
1
1
  import 'reflect-metadata';
2
2
  import { RequestBody } from '../types';
3
- export declare function ApiRequestBody(options: RequestBody): (target: any, propertyKey: string) => void;
3
+ export declare function ApiRequestBody(options: RequestBody): (target: any, propertyKey: any) => void;
@@ -1,3 +1,3 @@
1
1
  import "reflect-metadata";
2
2
  import { Responses } from "../types";
3
- export declare function ApiResponse(options: Responses): (target: any, propertyKey: string) => void;
3
+ export declare function ApiResponse(options: Responses): (target: any, propertyKey?: any, descriptor?: any) => any;
@@ -4,7 +4,7 @@ exports.ApiResponse = ApiResponse;
4
4
  require("reflect-metadata");
5
5
  const response_helper_1 = require("../helpers/response.helper");
6
6
  function ApiResponse(options) {
7
- return (target, propertyKey) => {
7
+ return (target, propertyKey, descriptor) => {
8
8
  (0, response_helper_1.apiResponse)(target, propertyKey, options);
9
9
  };
10
10
  }
@@ -1,3 +1,3 @@
1
1
  import 'reflect-metadata';
2
2
  import { SecurityRequirement } from '../types';
3
- export declare function ApiSecurity(options: SecurityRequirement): (target: any) => void;
3
+ export declare function ApiSecurity(options: SecurityRequirement): (target: any, propertyKey?: any, descriptor?: any) => void;
@@ -4,7 +4,7 @@ exports.ApiSecurity = ApiSecurity;
4
4
  require("reflect-metadata");
5
5
  const security_helper_1 = require("../helpers/security.helper");
6
6
  function ApiSecurity(options) {
7
- return (target) => {
8
- (0, security_helper_1.apiSecurity)(target, options);
7
+ return (target, propertyKey, descriptor) => {
8
+ (0, security_helper_1.apiSecurity)(target, options, propertyKey);
9
9
  };
10
10
  }
@@ -1,6 +1,7 @@
1
1
  export * from "./api-method.decorator";
2
2
  export * from "./api-parameter.decorator";
3
3
  export * from "./api-request-body.decorator";
4
- export * from "./api-response.decodator";
4
+ export * from "./api-response.decorator";
5
5
  export * from "./api-security.decorator";
6
+ export * from "./api-bearer-auth.decorator";
6
7
  export * from "./api-tag.decorator";
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./api-method.decorator"), exports);
18
18
  __exportStar(require("./api-parameter.decorator"), exports);
19
19
  __exportStar(require("./api-request-body.decorator"), exports);
20
- __exportStar(require("./api-response.decodator"), exports);
20
+ __exportStar(require("./api-response.decorator"), exports);
21
21
  __exportStar(require("./api-security.decorator"), exports);
22
+ __exportStar(require("./api-bearer-auth.decorator"), exports);
22
23
  __exportStar(require("./api-tag.decorator"), exports);
@@ -4,3 +4,4 @@ export * from "./request-body.helper";
4
4
  export * from "./response.helper";
5
5
  export * from "./security.helper";
6
6
  export * from "./tag.helper";
7
+ export * from "./openapi.helper";
@@ -20,3 +20,4 @@ __exportStar(require("./request-body.helper"), exports);
20
20
  __exportStar(require("./response.helper"), exports);
21
21
  __exportStar(require("./security.helper"), exports);
22
22
  __exportStar(require("./tag.helper"), exports);
23
+ __exportStar(require("./openapi.helper"), exports);
@@ -0,0 +1,7 @@
1
+ import { OpenAPIDocument } from "../types";
2
+ /**
3
+ * Generates a complete OpenAPI 3.0.0 document from a HyperApp class.
4
+ *
5
+ * @param App The HyperApp class (usually decorated with @HyperApp)
6
+ */
7
+ export declare function getOpenAPI(App: any): OpenAPIDocument;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getOpenAPI = getOpenAPI;
4
+ const tree_helper_1 = require("../../../__internals/helpers/tree.helper");
5
+ /**
6
+ * Generates a complete OpenAPI 3.0.0 document from a HyperApp class.
7
+ *
8
+ * @param App The HyperApp class (usually decorated with @HyperApp)
9
+ */
10
+ function getOpenAPI(App) {
11
+ var _a;
12
+ const tree = (0, tree_helper_1.getAppTree)(App);
13
+ const appMeta = tree.app;
14
+ const doc = {
15
+ openapi: "3.0.0",
16
+ info: {
17
+ title: appMeta.name || "API Documentation",
18
+ version: appMeta.version || "1.0.0",
19
+ description: appMeta.description || "",
20
+ },
21
+ paths: {},
22
+ components: Object.assign({ schemas: {}, securitySchemes: {} }, (_a = tree.openapi) === null || _a === void 0 ? void 0 : _a.components)
23
+ };
24
+ // Populate paths from the flattened tree paths
25
+ Object.entries(tree.paths).forEach(([path, routes]) => {
26
+ // Convert /v1/user/ to /v1/user (remove trailing slash except for root)
27
+ const normalizedPath = path.length > 1 && path.endsWith("/") ? path.slice(0, -1) : path;
28
+ if (!doc.paths[normalizedPath]) {
29
+ doc.paths[normalizedPath] = {};
30
+ }
31
+ const pathItem = doc.paths[normalizedPath];
32
+ routes.forEach(route => {
33
+ var _a;
34
+ const method = route.method.toLowerCase();
35
+ // Merge route-level OpenAPI metadata
36
+ const operation = Object.assign(Object.assign({}, route.openapi), { responses: ((_a = route.openapi) === null || _a === void 0 ? void 0 : _a.responses) || {
37
+ "200": { description: "Successful operation" }
38
+ } });
39
+ // Ensure operationId if missing for better client generation
40
+ if (!operation.operationId) {
41
+ operation.operationId = `${route.propertyKey}`;
42
+ }
43
+ pathItem[method] = operation;
44
+ });
45
+ });
46
+ // Apply any global tree processors that might have added data to tree.openapi
47
+ if (tree.openapi) {
48
+ Object.assign(doc, tree.openapi);
49
+ }
50
+ return doc;
51
+ }
@@ -1,3 +1,3 @@
1
1
  import 'reflect-metadata';
2
2
  import { SecurityRequirement } from '../types';
3
- export declare function apiSecurity(target: any, options: SecurityRequirement): void;
3
+ export declare function apiSecurity(target: any, options: SecurityRequirement, propertyKey?: string): void;
@@ -3,8 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.apiSecurity = apiSecurity;
4
4
  require("reflect-metadata");
5
5
  const constants_1 = require("../constants");
6
- function apiSecurity(target, options) {
7
- const existingSecurity = Reflect.getMetadata(constants_1.SECURITY, target) || [];
6
+ function apiSecurity(target, options, propertyKey) {
7
+ const existingSecurity = propertyKey
8
+ ? Reflect.getMetadata(constants_1.SECURITY, target, propertyKey) || []
9
+ : Reflect.getMetadata(constants_1.SECURITY, target) || [];
8
10
  existingSecurity.push(options);
9
- Reflect.defineMetadata(constants_1.SECURITY, existingSecurity, target);
11
+ if (propertyKey) {
12
+ Reflect.defineMetadata(constants_1.SECURITY, existingSecurity, target, propertyKey);
13
+ }
14
+ else {
15
+ Reflect.defineMetadata(constants_1.SECURITY, existingSecurity, target);
16
+ }
10
17
  }
@@ -1 +1,6 @@
1
+ export * from "./metadata.registry";
2
+ export * from "./constants";
1
3
  export * from "./collectors";
4
+ export * from "./decorators";
5
+ export * from "./helpers";
6
+ export * from "./types";
@@ -14,4 +14,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./metadata.registry"), exports);
18
+ __exportStar(require("./constants"), exports);
17
19
  __exportStar(require("./collectors"), exports);
20
+ __exportStar(require("./decorators"), exports);
21
+ __exportStar(require("./helpers"), exports);
22
+ __exportStar(require("./types"), exports);
@@ -0,0 +1,29 @@
1
+ import { AppTree } from "../../__internals/helpers/tree.helper";
2
+ export type CollectorType = "class" | "method" | "param";
3
+ export type CollectorFn = (target: any, propertyKey?: string) => any;
4
+ export type TreeProcessorFn = (tree: AppTree) => void;
5
+ declare class OpenAPIMetadataRegistry {
6
+ private collectors;
7
+ private processors;
8
+ /**
9
+ * Register a custom metadata collector.
10
+ * @param type The level where the collector operates.
11
+ * @param collector The function that extracts metadata.
12
+ */
13
+ registerCollector(type: CollectorType, collector: CollectorFn): void;
14
+ /**
15
+ * Register a processor to transform the final AppTree.
16
+ * @param processor The function that enriches the tree.
17
+ */
18
+ registerProcessor(processor: TreeProcessorFn): void;
19
+ /**
20
+ * Returns all registered collectors for a specific type.
21
+ */
22
+ getCollectors(type: CollectorType): CollectorFn[];
23
+ /**
24
+ * Returns all registered tree processors.
25
+ */
26
+ getProcessors(): TreeProcessorFn[];
27
+ }
28
+ export declare const openApiRegistry: OpenAPIMetadataRegistry;
29
+ export {};
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.openApiRegistry = void 0;
4
+ class OpenAPIMetadataRegistry {
5
+ constructor() {
6
+ this.collectors = {
7
+ class: new Set(),
8
+ method: new Set(),
9
+ param: new Set(),
10
+ };
11
+ this.processors = new Set();
12
+ }
13
+ /**
14
+ * Register a custom metadata collector.
15
+ * @param type The level where the collector operates.
16
+ * @param collector The function that extracts metadata.
17
+ */
18
+ registerCollector(type, collector) {
19
+ this.collectors[type].add(collector);
20
+ }
21
+ /**
22
+ * Register a processor to transform the final AppTree.
23
+ * @param processor The function that enriches the tree.
24
+ */
25
+ registerProcessor(processor) {
26
+ this.processors.add(processor);
27
+ }
28
+ /**
29
+ * Returns all registered collectors for a specific type.
30
+ */
31
+ getCollectors(type) {
32
+ return Array.from(this.collectors[type]);
33
+ }
34
+ /**
35
+ * Returns all registered tree processors.
36
+ */
37
+ getProcessors() {
38
+ return Array.from(this.processors);
39
+ }
40
+ }
41
+ exports.openApiRegistry = new OpenAPIMetadataRegistry();
package/dist/type.d.ts CHANGED
@@ -1,4 +1,11 @@
1
1
  import type { Server } from "hyper-express";
2
+ declare module "hyper-express" {
3
+ interface Request {
4
+ setValue(key: string, value: any): void;
5
+ getValue<T>(key: string, defaultValue?: T): T;
6
+ }
7
+ }
8
+ import { TransformerInput } from "./__internals/transform/transform.registry";
2
9
  export type HyperRoleOptions = string | string[];
3
10
  export type HyperScopeOptions = string | string[];
4
11
  export interface IHyperApplication extends Partial<Server> {
@@ -7,6 +14,7 @@ export interface IHyperApplication extends Partial<Server> {
7
14
  }
8
15
  export type IHyperApp<T> = T & Server & {
9
16
  emit(topic: string, data: any): Promise<void>;
17
+ useTransform(transformer: TransformerInput): IHyperApp<T>;
10
18
  };
11
19
  export interface IHyperAppTarget {
12
20
  new (...args: any[]): IHyperApplication;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenofolio/hyper-decor",
3
- "version": "1.0.67",
3
+ "version": "1.0.68",
4
4
  "description": "Project core with utilities and features",
5
5
  "main": "dist/index.js",
6
6
  "author": "zenozaga",
@@ -59,9 +59,13 @@
59
59
  "node": "./dist/extension.js",
60
60
  "default": "./src/extension.ts"
61
61
  },
62
- "./lib/*": {
63
- "node": "./dist/lib/*.js",
64
- "default": "./src/lib/*.ts"
62
+ "./openapi": {
63
+ "node": "./dist/lib/openapi/index.js",
64
+ "default": "./src/lib/openapi/index.ts"
65
+ },
66
+ "./openapi/*": {
67
+ "node": "./dist/lib/openapi/*.js",
68
+ "default": "./src/lib/openapi/*.ts"
65
69
  }
66
70
  },
67
71
  "bin": {
package/tsconfig.json CHANGED
@@ -1,17 +1,22 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "module": "Node16",
4
- "moduleResolution": "Node16",
5
- "strict": true, /* Enable all strict type-checking options. */
6
- "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
7
- "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
8
- "outDir": "./dist", /* Specify an output folder for all emitted files. */
9
- "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
10
- "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
11
- "skipLibCheck": true, /* Skip type checking all .d.ts files. */
12
-
13
- "experimentalDecorators": true,
14
- "emitDecoratorMetadata": true,
3
+ "module": "Node16",
4
+ "moduleResolution": "Node16",
5
+ "strict": true, /* Enable all strict type-checking options. */
6
+ "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
7
+ "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
8
+ "outDir": "./dist", /* Specify an output folder for all emitted files. */
9
+ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
10
+ "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
11
+ "skipLibCheck": true, /* Skip type checking all .d.ts files. */
12
+ "experimentalDecorators": true,
13
+ "emitDecoratorMetadata": true,
15
14
  },
16
- "exclude": ["node_modules", "dist", "tests", "examples"],
15
+ "exclude": [
16
+ "node_modules",
17
+ "dist",
18
+ "tests",
19
+ "examples",
20
+ "scripts"
21
+ ],
17
22
  }
@@ -1 +0,0 @@
1
- import "reflect-metadata";
package/dist/run-bench.js DELETED
@@ -1,190 +0,0 @@
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
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- var __param = (this && this.__param) || function (paramIndex, decorator) {
12
- return function (target, key) { decorator(target, key, paramIndex); }
13
- };
14
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
15
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16
- return new (P || (P = Promise))(function (resolve, reject) {
17
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
18
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
19
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
20
- step((generator = generator.apply(thisArg, _arguments || [])).next());
21
- });
22
- };
23
- Object.defineProperty(exports, "__esModule", { value: true });
24
- require("reflect-metadata");
25
- const src_1 = require("./src");
26
- const tsyringe_1 = require("tsyringe");
27
- const request_1 = require("./tests/helpers/request");
28
- // Global counter to verify execution
29
- let initCounter = 0;
30
- const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms));
31
- let StaticServiceA = class StaticServiceA {
32
- onInit() {
33
- return __awaiter(this, void 0, void 0, function* () {
34
- yield delay(5);
35
- initCounter++;
36
- });
37
- }
38
- getValue() { return "A"; }
39
- };
40
- StaticServiceA = __decorate([
41
- (0, tsyringe_1.injectable)(),
42
- (0, src_1.HyperService)()
43
- ], StaticServiceA);
44
- let StaticServiceB = class StaticServiceB {
45
- onInit() {
46
- return __awaiter(this, void 0, void 0, function* () {
47
- yield delay(5);
48
- initCounter++;
49
- });
50
- }
51
- getValue() { return "B"; }
52
- };
53
- StaticServiceB = __decorate([
54
- (0, tsyringe_1.injectable)(),
55
- (0, src_1.HyperService)()
56
- ], StaticServiceB);
57
- let BenchController = class BenchController {
58
- verify(res) {
59
- return __awaiter(this, void 0, void 0, function* () {
60
- res.json({
61
- count: initCounter,
62
- status: "ok"
63
- });
64
- });
65
- }
66
- };
67
- __decorate([
68
- (0, src_1.Get)("/"),
69
- __param(0, (0, src_1.Res)()),
70
- __metadata("design:type", Function),
71
- __metadata("design:paramtypes", [src_1.Response]),
72
- __metadata("design:returntype", Promise)
73
- ], BenchController.prototype, "verify", null);
74
- BenchController = __decorate([
75
- (0, src_1.HyperController)("/verify")
76
- ], BenchController);
77
- let BenchModule = class BenchModule {
78
- };
79
- BenchModule = __decorate([
80
- (0, src_1.HyperModule)({
81
- imports: [StaticServiceA, StaticServiceB],
82
- controllers: [BenchController]
83
- })
84
- ], BenchModule);
85
- let App = class App {
86
- };
87
- App = __decorate([
88
- (0, src_1.HyperApp)({
89
- modules: [BenchModule]
90
- })
91
- ], App);
92
- let CircularA = class CircularA {
93
- constructor(b) {
94
- this.b = b;
95
- }
96
- onInit() {
97
- return __awaiter(this, void 0, void 0, function* () {
98
- yield delay(10);
99
- initCounter++;
100
- });
101
- }
102
- getName() { return "A"; }
103
- };
104
- CircularA = __decorate([
105
- (0, tsyringe_1.injectable)(),
106
- (0, src_1.HyperService)(),
107
- __param(0, (0, tsyringe_1.inject)((0, tsyringe_1.delay)(() => CircularB))),
108
- __metadata("design:paramtypes", [Object])
109
- ], CircularA);
110
- let CircularB = class CircularB {
111
- constructor(a) {
112
- this.a = a;
113
- }
114
- onInit() {
115
- return __awaiter(this, void 0, void 0, function* () {
116
- yield delay(10);
117
- initCounter++;
118
- });
119
- }
120
- getName() { return "B"; }
121
- };
122
- CircularB = __decorate([
123
- (0, tsyringe_1.injectable)(),
124
- (0, src_1.HyperService)(),
125
- __param(0, (0, tsyringe_1.inject)((0, tsyringe_1.delay)(() => CircularA))),
126
- __metadata("design:paramtypes", [Object])
127
- ], CircularB);
128
- let CircularModule = class CircularModule {
129
- };
130
- CircularModule = __decorate([
131
- (0, src_1.HyperModule)({
132
- imports: [CircularA, CircularB]
133
- })
134
- ], CircularModule);
135
- let CircularApp = class CircularApp {
136
- };
137
- CircularApp = __decorate([
138
- (0, src_1.HyperApp)({
139
- modules: [CircularModule]
140
- })
141
- ], CircularApp);
142
- function runBenchmarks() {
143
- return __awaiter(this, void 0, void 0, function* () {
144
- console.log("Enhanced Performance & Robustness Benchmark");
145
- // Test 1
146
- console.log("\n-> should verify service execution and fetch liveliness");
147
- initCounter = 0;
148
- tsyringe_1.container.reset();
149
- const start = Date.now();
150
- const app = yield (0, src_1.createApplication)(App);
151
- const duration = Date.now() - start;
152
- yield app.listen(3005);
153
- const responseText = yield (0, request_1.request)("/verify", undefined, 3005);
154
- const response = JSON.parse(responseText);
155
- console.log(`\n✅ LIVELINESS & EXECUTION:`);
156
- console.log(`- Startup: ${duration}ms`);
157
- console.log(`- Services Initialized: ${response.count}`);
158
- console.log(`- Response: ${responseText}`);
159
- if (response.status !== "ok")
160
- throw new Error("Status not ok");
161
- if (response.count !== 2)
162
- throw new Error("Count not 2");
163
- yield app.close();
164
- // Test 2
165
- console.log("\n-> should handle circular dependencies with delays");
166
- tsyringe_1.container.reset();
167
- initCounter = 0;
168
- const app2 = yield (0, src_1.createApplication)(CircularApp);
169
- const a = tsyringe_1.container.resolve(CircularA);
170
- const b = tsyringe_1.container.resolve(CircularB);
171
- console.log(`\n🔄 CIRCULAR DEP RESULTS:`);
172
- console.log(`- CircularA sees name: ${a.b.getName()}`);
173
- console.log(`- CircularB sees name: ${b.a.getName()}`);
174
- console.log(`- Init Counter: ${initCounter}`);
175
- if (a.b.getName() !== "B")
176
- throw new Error("Mismatch B");
177
- if (b.a.getName() !== "A")
178
- throw new Error("Mismatch A");
179
- if (initCounter !== 2)
180
- throw new Error("Mismatch initCounter");
181
- yield app2.close();
182
- });
183
- }
184
- runBenchmarks().then(() => {
185
- console.log("\nAll benchmarks finished successfully!");
186
- process.exit(0);
187
- }).catch(e => {
188
- console.error(e);
189
- process.exit(1);
190
- });
@@ -1 +0,0 @@
1
- import "reflect-metadata";