@avleon/core 0.0.46 → 0.0.49

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 (142) hide show
  1. package/License +21 -21
  2. package/README.md +666 -666
  3. package/dist/chunk-9hOWP6kD.cjs +64 -0
  4. package/dist/chunk-DORXReHP.js +37 -0
  5. package/dist/index-CWUcfHYp.d.ts +1283 -0
  6. package/dist/index-CzAzauXZ.d.cts +1282 -0
  7. package/dist/index.cjs +3194 -0
  8. package/dist/index.cjs.map +1 -0
  9. package/dist/index.js +3022 -79
  10. package/dist/index.js.map +1 -0
  11. package/dist/lib-Bk8hUm06.cjs +7847 -0
  12. package/dist/lib-Bk8hUm06.cjs.map +1 -0
  13. package/dist/lib-CvDxBMkR.js +7843 -0
  14. package/dist/lib-CvDxBMkR.js.map +1 -0
  15. package/package.json +41 -103
  16. package/dist/application.test.d.ts +0 -1
  17. package/dist/application.test.js +0 -15
  18. package/dist/authentication.d.ts +0 -13
  19. package/dist/authentication.js +0 -16
  20. package/dist/cache.d.ts +0 -12
  21. package/dist/cache.js +0 -78
  22. package/dist/cache.test.d.ts +0 -1
  23. package/dist/cache.test.js +0 -36
  24. package/dist/collection.d.ts +0 -43
  25. package/dist/collection.js +0 -231
  26. package/dist/collection.test.d.ts +0 -1
  27. package/dist/collection.test.js +0 -59
  28. package/dist/config.d.ts +0 -18
  29. package/dist/config.js +0 -58
  30. package/dist/config.test.d.ts +0 -1
  31. package/dist/config.test.js +0 -40
  32. package/dist/constants.d.ts +0 -1
  33. package/dist/constants.js +0 -4
  34. package/dist/container.d.ts +0 -30
  35. package/dist/container.js +0 -55
  36. package/dist/controller.d.ts +0 -50
  37. package/dist/controller.js +0 -71
  38. package/dist/controller.test.d.ts +0 -1
  39. package/dist/controller.test.js +0 -97
  40. package/dist/core/application.d.ts +0 -74
  41. package/dist/core/application.js +0 -424
  42. package/dist/core/router.d.ts +0 -44
  43. package/dist/core/router.js +0 -520
  44. package/dist/core/testing.d.ts +0 -21
  45. package/dist/core/testing.js +0 -104
  46. package/dist/core/types.d.ts +0 -67
  47. package/dist/core/types.js +0 -2
  48. package/dist/decorators.d.ts +0 -15
  49. package/dist/decorators.js +0 -41
  50. package/dist/environment-variables.d.ts +0 -49
  51. package/dist/environment-variables.js +0 -130
  52. package/dist/environment-variables.test.d.ts +0 -1
  53. package/dist/environment-variables.test.js +0 -70
  54. package/dist/event-dispatcher.d.ts +0 -22
  55. package/dist/event-dispatcher.js +0 -97
  56. package/dist/event-subscriber.d.ts +0 -14
  57. package/dist/event-subscriber.js +0 -87
  58. package/dist/exceptions/http-exceptions.d.ts +0 -50
  59. package/dist/exceptions/http-exceptions.js +0 -85
  60. package/dist/exceptions/index.d.ts +0 -1
  61. package/dist/exceptions/index.js +0 -17
  62. package/dist/exceptions/system-exception.d.ts +0 -22
  63. package/dist/exceptions/system-exception.js +0 -26
  64. package/dist/file-storage.d.ts +0 -69
  65. package/dist/file-storage.js +0 -323
  66. package/dist/file-storage.test.d.ts +0 -1
  67. package/dist/file-storage.test.js +0 -117
  68. package/dist/helpers.d.ts +0 -11
  69. package/dist/helpers.js +0 -27
  70. package/dist/helpers.test.d.ts +0 -1
  71. package/dist/helpers.test.js +0 -95
  72. package/dist/index.d.ts +0 -57
  73. package/dist/interfaces/avleon-application.d.ts +0 -75
  74. package/dist/interfaces/avleon-application.js +0 -2
  75. package/dist/kenx-provider.d.ts +0 -7
  76. package/dist/kenx-provider.js +0 -44
  77. package/dist/kenx-provider.test.d.ts +0 -1
  78. package/dist/kenx-provider.test.js +0 -36
  79. package/dist/logger.d.ts +0 -12
  80. package/dist/logger.js +0 -87
  81. package/dist/logger.test.d.ts +0 -1
  82. package/dist/logger.test.js +0 -42
  83. package/dist/map-types.d.ts +0 -17
  84. package/dist/map-types.js +0 -89
  85. package/dist/middleware.d.ts +0 -34
  86. package/dist/middleware.js +0 -73
  87. package/dist/middleware.test.d.ts +0 -1
  88. package/dist/middleware.test.js +0 -121
  89. package/dist/multipart.d.ts +0 -17
  90. package/dist/multipart.js +0 -70
  91. package/dist/multipart.test.d.ts +0 -1
  92. package/dist/multipart.test.js +0 -87
  93. package/dist/openapi.d.ts +0 -410
  94. package/dist/openapi.js +0 -59
  95. package/dist/openapi.test.d.ts +0 -1
  96. package/dist/openapi.test.js +0 -111
  97. package/dist/params.d.ts +0 -17
  98. package/dist/params.js +0 -64
  99. package/dist/params.test.d.ts +0 -1
  100. package/dist/params.test.js +0 -83
  101. package/dist/queue.d.ts +0 -29
  102. package/dist/queue.js +0 -84
  103. package/dist/response.d.ts +0 -16
  104. package/dist/response.js +0 -56
  105. package/dist/results.d.ts +0 -20
  106. package/dist/results.js +0 -32
  107. package/dist/route-methods.d.ts +0 -25
  108. package/dist/route-methods.js +0 -60
  109. package/dist/route-methods.test.d.ts +0 -1
  110. package/dist/route-methods.test.js +0 -129
  111. package/dist/swagger-schema.d.ts +0 -37
  112. package/dist/swagger-schema.js +0 -454
  113. package/dist/swagger-schema.test.d.ts +0 -1
  114. package/dist/swagger-schema.test.js +0 -125
  115. package/dist/types/app-builder.interface.d.ts +0 -15
  116. package/dist/types/app-builder.interface.js +0 -8
  117. package/dist/types/application.interface.d.ts +0 -8
  118. package/dist/types/application.interface.js +0 -2
  119. package/dist/utils/common-utils.d.ts +0 -17
  120. package/dist/utils/common-utils.js +0 -108
  121. package/dist/utils/di-utils.d.ts +0 -1
  122. package/dist/utils/di-utils.js +0 -22
  123. package/dist/utils/hash.d.ts +0 -2
  124. package/dist/utils/hash.js +0 -11
  125. package/dist/utils/index.d.ts +0 -2
  126. package/dist/utils/index.js +0 -18
  127. package/dist/utils/object-utils.d.ts +0 -11
  128. package/dist/utils/object-utils.js +0 -198
  129. package/dist/utils/optional-require.d.ts +0 -8
  130. package/dist/utils/optional-require.js +0 -70
  131. package/dist/utils/validation-utils.d.ts +0 -13
  132. package/dist/utils/validation-utils.js +0 -119
  133. package/dist/validation.d.ts +0 -39
  134. package/dist/validation.js +0 -108
  135. package/dist/validation.test.d.ts +0 -1
  136. package/dist/validation.test.js +0 -61
  137. package/dist/validator-extend.d.ts +0 -7
  138. package/dist/validator-extend.js +0 -28
  139. package/dist/websocket.d.ts +0 -10
  140. package/dist/websocket.js +0 -21
  141. package/dist/websocket.test.d.ts +0 -1
  142. package/dist/websocket.test.js +0 -27
@@ -1,59 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const collection_1 = require("./collection");
4
- describe("Collection", () => {
5
- let collection;
6
- beforeEach(() => {
7
- collection = collection_1.Collection.from([
8
- {
9
- id: 1,
10
- body: "test 1",
11
- completed: false,
12
- },
13
- {
14
- id: 2,
15
- body: "test 2",
16
- completed: true,
17
- },
18
- {
19
- id: 3,
20
- body: "test 2",
21
- completed: true,
22
- },
23
- ]);
24
- });
25
- afterEach(() => {
26
- collection.clear();
27
- });
28
- describe("find()", () => {
29
- it("should be return collection", () => {
30
- const result = collection.find();
31
- expect(result).toHaveProperty("length");
32
- expect(result.length).toBe(3);
33
- });
34
- it("should return only completed task", () => {
35
- const result = collection.find((todo) => todo.completed);
36
- expect(result).toHaveProperty("length");
37
- expect(result.length).toBe(2);
38
- expect(result[0].id).toBe(2);
39
- });
40
- });
41
- describe("findOne()", () => {
42
- it("should be return todo", () => {
43
- const result = collection.findOne({ where: { id: 1 } });
44
- expect(result).toHaveProperty("id");
45
- expect(result === null || result === void 0 ? void 0 : result.id).toBe(1);
46
- });
47
- it("should return only completed task", () => {
48
- const result = collection.findOne({
49
- where: {
50
- id: {
51
- $in: [3],
52
- },
53
- },
54
- });
55
- expect(result).toHaveProperty("id");
56
- expect(result === null || result === void 0 ? void 0 : result.completed).toBe(true);
57
- });
58
- });
59
- });
package/dist/config.d.ts DELETED
@@ -1,18 +0,0 @@
1
- /**
2
- * @copyright 2024
3
- * @author Tareq Hossain
4
- * @email xtrinsic96@gmail.com
5
- * @url https://github.com/xtareq
6
- */
7
- import { Constructable } from "typedi";
8
- import { Environment } from "./environment-variables";
9
- export interface IConfig<T = any> {
10
- config(env: Environment): T;
11
- }
12
- export declare function AppConfig<T extends IConfig>(target: Constructable<T>): void;
13
- export declare class AvleonConfig {
14
- get<T extends IConfig<R>, R>(configClass: Constructable<T>): R;
15
- }
16
- export declare function GetConfig<T extends IConfig<R>, R = ReturnType<InstanceType<Constructable<T>>["config"]>>(ConfigClass: Constructable<T>): R;
17
- export declare function GetConfig<T = any>(config: string | symbol): T;
18
- export declare function CreateConfig<T>(token: string | symbol, callback: (env: Environment) => T): void;
package/dist/config.js DELETED
@@ -1,58 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AvleonConfig = void 0;
4
- exports.AppConfig = AppConfig;
5
- exports.GetConfig = GetConfig;
6
- exports.CreateConfig = CreateConfig;
7
- /**
8
- * @copyright 2024
9
- * @author Tareq Hossain
10
- * @email xtrinsic96@gmail.com
11
- * @url https://github.com/xtareq
12
- */
13
- const typedi_1 = require("typedi");
14
- const environment_variables_1 = require("./environment-variables");
15
- const helpers_1 = require("./helpers");
16
- function AppConfig(target) {
17
- typedi_1.Container.set({ id: target, type: target });
18
- }
19
- class AvleonConfig {
20
- get(configClass) {
21
- const instance = typedi_1.Container.get(configClass);
22
- if (!instance) {
23
- throw new Error(`Configuration for ${configClass.name} not found.`);
24
- }
25
- return instance.config(new environment_variables_1.Environment());
26
- }
27
- }
28
- exports.AvleonConfig = AvleonConfig;
29
- // Implementation
30
- function GetConfig(token) {
31
- // 1. Class‐based: token.prototype.config is a function
32
- if (typeof token === "function" &&
33
- token.prototype != null &&
34
- typeof token.prototype.config === "function") {
35
- const instance = typedi_1.Container.get(token);
36
- if (!instance) {
37
- throw new Error(`Class "${token.name}" is not registered as a config.`);
38
- }
39
- return instance.config((0, helpers_1.inject)(environment_variables_1.Environment));
40
- }
41
- // 2. Functional: token is the callback itself
42
- const stored = typedi_1.Container.get(token);
43
- if (!stored) {
44
- throw new Error("Config object is not registered.");
45
- }
46
- return stored;
47
- }
48
- function CreateConfig(token, callback) {
49
- let env;
50
- try {
51
- env = typedi_1.Container.get(environment_variables_1.Environment);
52
- }
53
- catch (error) {
54
- env = new environment_variables_1.Environment();
55
- }
56
- let config = callback(env);
57
- typedi_1.Container.set(token, config);
58
- }
@@ -1 +0,0 @@
1
- import "reflect-metadata";
@@ -1,40 +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
- Object.defineProperty(exports, "__esModule", { value: true });
9
- require("reflect-metadata");
10
- const config_1 = require("./config");
11
- describe("Config", () => {
12
- describe("class", () => {
13
- it("should be call by get config", () => {
14
- let MyConfig = class MyConfig {
15
- config(env) {
16
- return {
17
- name: "avleon",
18
- };
19
- }
20
- };
21
- MyConfig = __decorate([
22
- config_1.AppConfig
23
- ], MyConfig);
24
- const mConfig = (0, config_1.GetConfig)(MyConfig);
25
- expect(mConfig).toHaveProperty("name");
26
- expect(mConfig["name"]).toBe("avleon");
27
- });
28
- });
29
- describe("createConfig()", () => {
30
- it("it should create config and called with GetConfig", () => {
31
- (0, config_1.CreateConfig)("myconfig", (env) => ({
32
- firstname: "tareq",
33
- os: env.get("name"),
34
- }));
35
- const mConfig = (0, config_1.GetConfig)("myconfig");
36
- expect(mConfig).toHaveProperty("firstname");
37
- expect(mConfig.firstname).toBe("tareq");
38
- });
39
- });
40
- });
@@ -1 +0,0 @@
1
- export declare const TEST_DATASOURCE_OPTIONS_KEY: unique symbol;
package/dist/constants.js DELETED
@@ -1,4 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TEST_DATASOURCE_OPTIONS_KEY = void 0;
4
- exports.TEST_DATASOURCE_OPTIONS_KEY = Symbol("itestdatasource");
@@ -1,30 +0,0 @@
1
- /**
2
- * @copyright 2024
3
- * @author Tareq Hossain
4
- * @email xtrinsic96@gmail.com
5
- * @url https://github.com/xtareq
6
- */
7
- import { Knex } from "knex";
8
- import TypediContainer from "typedi";
9
- export declare const FEATURE_KEY: unique symbol;
10
- export declare const ROUTE_META_KEY: unique symbol;
11
- export declare const CONTROLLER_META_KEY: unique symbol;
12
- export declare const PARAM_META_KEY: unique symbol;
13
- export declare const QUERY_META_KEY: unique symbol;
14
- export declare const REQUEST_BODY_META_KEY: unique symbol;
15
- export declare const REQUEST_BODY_FILE_KEY: unique symbol;
16
- export declare const REQUEST_BODY_FILES_KEY: unique symbol;
17
- export declare const REQUEST_USER_META_KEY: unique symbol;
18
- export declare const REQUEST_HEADER_META_KEY: unique symbol;
19
- export declare const DATASOURCE_META_KEY: unique symbol;
20
- export declare const AUTHORIZATION_META_KEY: unique symbol;
21
- declare const Container: typeof TypediContainer;
22
- export declare function registerController(controller: Function): void;
23
- export declare function registerService(service: Function): void;
24
- export declare function getRegisteredServices(): Function[];
25
- export declare function getRegisteredControllers(): Function[];
26
- export declare const API_CONTROLLER_METADATA_KEY: unique symbol;
27
- export declare function isApiController(target: Function): boolean;
28
- export declare function registerDataSource(dataSource: any): void;
29
- export declare function registerKnex(dataSource: Knex.Config): void;
30
- export default Container;
package/dist/container.js DELETED
@@ -1,55 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.API_CONTROLLER_METADATA_KEY = exports.AUTHORIZATION_META_KEY = exports.DATASOURCE_META_KEY = exports.REQUEST_HEADER_META_KEY = exports.REQUEST_USER_META_KEY = exports.REQUEST_BODY_FILES_KEY = exports.REQUEST_BODY_FILE_KEY = exports.REQUEST_BODY_META_KEY = exports.QUERY_META_KEY = exports.PARAM_META_KEY = exports.CONTROLLER_META_KEY = exports.ROUTE_META_KEY = exports.FEATURE_KEY = void 0;
7
- exports.registerController = registerController;
8
- exports.registerService = registerService;
9
- exports.getRegisteredServices = getRegisteredServices;
10
- exports.getRegisteredControllers = getRegisteredControllers;
11
- exports.isApiController = isApiController;
12
- exports.registerDataSource = registerDataSource;
13
- exports.registerKnex = registerKnex;
14
- const typedi_1 = __importDefault(require("typedi"));
15
- exports.FEATURE_KEY = Symbol.for("features");
16
- exports.ROUTE_META_KEY = Symbol("iroute:options");
17
- exports.CONTROLLER_META_KEY = Symbol("icontroller:options");
18
- exports.PARAM_META_KEY = Symbol("iparam:options");
19
- exports.QUERY_META_KEY = Symbol("iparam:options");
20
- exports.REQUEST_BODY_META_KEY = Symbol("iparam:options");
21
- exports.REQUEST_BODY_FILE_KEY = Symbol("iparam:options");
22
- exports.REQUEST_BODY_FILES_KEY = Symbol("iparam:options");
23
- exports.REQUEST_USER_META_KEY = Symbol("iparam:options");
24
- exports.REQUEST_HEADER_META_KEY = Symbol("iheader:options");
25
- exports.DATASOURCE_META_KEY = Symbol("idatasource:options");
26
- exports.AUTHORIZATION_META_KEY = Symbol("idatasource:authorization");
27
- const controllerRegistry = new Set();
28
- const serviceRegistry = new Set();
29
- const optionsRegistry = new Map();
30
- const Container = typedi_1.default;
31
- function registerController(controller) {
32
- controllerRegistry.add(controller);
33
- }
34
- function registerService(service) {
35
- Container.set(service, service);
36
- serviceRegistry.add(service);
37
- }
38
- function getRegisteredServices() {
39
- return Array.from(serviceRegistry);
40
- }
41
- function getRegisteredControllers() {
42
- return Array.from(controllerRegistry);
43
- }
44
- exports.API_CONTROLLER_METADATA_KEY = Symbol("apiController");
45
- function isApiController(target) {
46
- return Reflect.getMetadata(exports.API_CONTROLLER_METADATA_KEY, target) === true;
47
- }
48
- Container.set("appName", "Iqra");
49
- function registerDataSource(dataSource) {
50
- Container.set("idatasource", dataSource);
51
- }
52
- function registerKnex(dataSource) {
53
- Container.set("KnexConnection", dataSource);
54
- }
55
- exports.default = Container;
@@ -1,50 +0,0 @@
1
- /**
2
- * @copyright 2024
3
- * @author Tareq Hossain
4
- * @email xtrinsic96@gmail.com
5
- * @url https://github.com/xtareq
6
- */
7
- export declare const REQUEST_METADATA_KEY: unique symbol;
8
- export declare function AvleonRequest(): ParameterDecorator;
9
- /**
10
- * Options for configuring a controller.
11
- * @remarks
12
- * Controller default options
13
- * @type {Object} ControllerOptions
14
- * @property {string} [name] - The name of the controller.
15
- * @property {string} [path] - The base path for the controller's routes.
16
- * @property {string} [version] - The version of the controller. If not provided, it will default to the version from `package.json`.
17
- * @property {string} [since] - The date or version since the controller was introduced.
18
- * @property {any} [meta] - Additional metadata associated with the controller.
19
- */
20
- export type ControllerOptions = {
21
- /**
22
- *@property {string} name
23
- *@description Name of the controller. If specified it'll used as swagger tags
24
- *@default Contorller class name
25
- * */
26
- name?: string;
27
- path?: string;
28
- version?: string;
29
- since?: string;
30
- meta?: any;
31
- };
32
- export declare function createControllerDecorator(type?: "api" | "web"): (pathOrOptions?: string | ControllerOptions, maybeOptions?: ControllerOptions) => ClassDecorator;
33
- /**
34
- *@description Api controller's are used for rest . It will populate
35
- * json on return and all it http methods {get} {post} etc must return
36
- *Results.*
37
- * @param path {string} this will used as route prefix
38
- *
39
- **/
40
- export declare function ApiController(target: Function): void;
41
- export declare function ApiController(path: string): ClassDecorator;
42
- /**
43
- *@description Api controller's are used for rest . It will populate
44
- * json on return and all it http methods {get} {post} etc must return
45
- * Results.*
46
- * @param {ControllerOptions} options this will used as route prefix
47
- *
48
- **/
49
- export declare function ApiController(options: ControllerOptions): ClassDecorator;
50
- export declare function ApiController(path: string, options?: ControllerOptions): ClassDecorator;
@@ -1,71 +0,0 @@
1
- "use strict";
2
- /**
3
- * @copyright 2024
4
- * @author Tareq Hossain
5
- * @email xtrinsic96@gmail.com
6
- * @url https://github.com/xtareq
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.REQUEST_METADATA_KEY = void 0;
10
- exports.AvleonRequest = AvleonRequest;
11
- exports.createControllerDecorator = createControllerDecorator;
12
- exports.ApiController = ApiController;
13
- const typedi_1 = require("typedi");
14
- const container_1 = require("./container");
15
- exports.REQUEST_METADATA_KEY = Symbol('avleon:request');
16
- function AvleonRequest() {
17
- return (target, propertyKey, parameterIndex) => {
18
- const existingParams = Reflect.getMetadata(exports.REQUEST_METADATA_KEY, target, propertyKey) || [];
19
- existingParams.push({
20
- index: parameterIndex,
21
- type: 'request',
22
- });
23
- Reflect.defineMetadata(exports.REQUEST_METADATA_KEY, existingParams, target, propertyKey);
24
- };
25
- }
26
- function createControllerDecorator(type = "web") {
27
- return function (pathOrOptions, maybeOptions) {
28
- return function (target) {
29
- let path = "/";
30
- let options = {};
31
- if (typeof pathOrOptions === "string") {
32
- path = pathOrOptions;
33
- options = maybeOptions || {};
34
- }
35
- else if (typeof pathOrOptions === "object") {
36
- options = pathOrOptions;
37
- path = options.path || "/";
38
- }
39
- Reflect.defineMetadata(container_1.API_CONTROLLER_METADATA_KEY, true, target);
40
- // Ensure Service is applied as a ClassDecorator
41
- if (typeof typedi_1.Service === "function") {
42
- (0, container_1.registerController)(target); // Add to custom registry
43
- (0, typedi_1.Service)()(target); // Apply DI decorator
44
- Reflect.defineMetadata(container_1.CONTROLLER_META_KEY, { type, path, options }, target);
45
- }
46
- else {
47
- throw new Error("Service decorator is not a function");
48
- }
49
- };
50
- };
51
- }
52
- function ApiController(pathOrOptions = "/", mayBeOptions) {
53
- if (typeof pathOrOptions == "function") {
54
- Reflect.defineMetadata(container_1.API_CONTROLLER_METADATA_KEY, true, pathOrOptions);
55
- // Ensure Service is applied as a ClassDecorator
56
- if (typeof typedi_1.Service === "function") {
57
- (0, container_1.registerController)(pathOrOptions); // Add to custom registry
58
- (0, typedi_1.Service)()(pathOrOptions); // Apply DI decorator
59
- Reflect.defineMetadata(container_1.CONTROLLER_META_KEY, { type: "api", path: "/", options: {} }, pathOrOptions);
60
- }
61
- else {
62
- throw new Error("Service decorator is not a function");
63
- }
64
- }
65
- else {
66
- if (mayBeOptions) {
67
- return createControllerDecorator("api")(pathOrOptions, mayBeOptions);
68
- }
69
- return createControllerDecorator("api")(pathOrOptions);
70
- }
71
- }
@@ -1 +0,0 @@
1
- import "reflect-metadata";
@@ -1,97 +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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
- 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;
22
- return c > 3 && r && Object.defineProperty(target, key, r), r;
23
- };
24
- var __importStar = (this && this.__importStar) || (function () {
25
- var ownKeys = function(o) {
26
- ownKeys = Object.getOwnPropertyNames || function (o) {
27
- var ar = [];
28
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
29
- return ar;
30
- };
31
- return ownKeys(o);
32
- };
33
- return function (mod) {
34
- if (mod && mod.__esModule) return mod;
35
- var result = {};
36
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
37
- __setModuleDefault(result, mod);
38
- return result;
39
- };
40
- })();
41
- Object.defineProperty(exports, "__esModule", { value: true });
42
- require("reflect-metadata");
43
- const controller_1 = require("./controller");
44
- const containerModule = __importStar(require("./container"));
45
- describe("Controller Decorators", () => {
46
- beforeEach(() => {
47
- jest.clearAllMocks();
48
- });
49
- describe("ApiController", () => {
50
- it("should apply metadata and Service decorator when used as a class decorator", () => {
51
- const registerControllerSpy = jest.spyOn(containerModule, "registerController");
52
- let TestController = class TestController {
53
- };
54
- TestController = __decorate([
55
- controller_1.ApiController
56
- ], TestController);
57
- expect(Reflect.getMetadata(containerModule.API_CONTROLLER_METADATA_KEY, TestController)).toBe(true);
58
- expect(registerControllerSpy).toHaveBeenCalledWith(TestController);
59
- expect(Reflect.getMetadata(containerModule.CONTROLLER_META_KEY, TestController)).toEqual({
60
- type: "api",
61
- path: "/",
62
- options: {},
63
- });
64
- });
65
- it("should apply metadata and Service decorator when used with a path", () => {
66
- const registerControllerSpy = jest.spyOn(containerModule, "registerController");
67
- let TestController = class TestController {
68
- };
69
- TestController = __decorate([
70
- (0, controller_1.ApiController)("/test")
71
- ], TestController);
72
- expect(Reflect.getMetadata(containerModule.API_CONTROLLER_METADATA_KEY, TestController)).toBe(true);
73
- expect(registerControllerSpy).toHaveBeenCalledWith(TestController);
74
- expect(Reflect.getMetadata(containerModule.CONTROLLER_META_KEY, TestController)).toEqual({
75
- type: "api",
76
- path: "/test",
77
- options: {},
78
- });
79
- });
80
- it("should apply metadata and Service decorator when used with options", () => {
81
- const registerControllerSpy = jest.spyOn(containerModule, "registerController");
82
- const options = { name: "Custom", path: "/custom", version: "1.0.0" };
83
- let TestController = class TestController {
84
- };
85
- TestController = __decorate([
86
- (0, controller_1.ApiController)(options)
87
- ], TestController);
88
- expect(Reflect.getMetadata(containerModule.API_CONTROLLER_METADATA_KEY, TestController)).toBe(true);
89
- expect(registerControllerSpy).toHaveBeenCalledWith(TestController);
90
- expect(Reflect.getMetadata(containerModule.CONTROLLER_META_KEY, TestController)).toEqual({
91
- type: "api",
92
- path: "/custom",
93
- options,
94
- });
95
- });
96
- });
97
- });
@@ -1,74 +0,0 @@
1
- /**
2
- * @copyright 2024
3
- * @author Tareq Hossain
4
- * @email xtrinsic96@gmail.com
5
- * @url https://github.com/xtareq
6
- */
7
- import { FastifyInstance } from "fastify";
8
- import "@fastify/swagger";
9
- import { IAvleonApplication, AvleonApplicationOptions, CorsOptions, GlobalOptions } from "../interfaces/avleon-application";
10
- import { Constructor } from "../helpers";
11
- import { OpenApiUiOptions } from "../openapi";
12
- import { DataSource } from "typeorm";
13
- import { AvleonMiddleware } from "../middleware";
14
- import { AutoControllerOptions } from "./types";
15
- export declare class AvleonApplication implements IAvleonApplication {
16
- app: FastifyInstance;
17
- private router;
18
- private static instance;
19
- private alreadyRun;
20
- private hasSwagger;
21
- private globalSwaggerOptions;
22
- private dataSourceOptions;
23
- private dataSource;
24
- private isMapFeatures;
25
- private registerControllerAuto;
26
- private registerControllerPath;
27
- private controllers;
28
- private _hasWebsocket;
29
- private io;
30
- private constructor();
31
- static getApp(options?: AvleonApplicationOptions): AvleonApplication;
32
- /**
33
- * @deprecated Use `getApp` instead. This is internal.
34
- */
35
- static getInternalApp(options?: AvleonApplicationOptions): AvleonApplication;
36
- useCors(options: CorsOptions): this;
37
- useDatasource(dataSource: DataSource): this;
38
- useMultipart(options?: any): this;
39
- useOpenApi(options: OpenApiUiOptions): this;
40
- private initSwagger;
41
- useMiddlewares(middlewares: Constructor<AvleonMiddleware>[]): this;
42
- useAuthorization(authorization: Constructor<any>): this;
43
- useSerialization(): this;
44
- useControllers(controllers: Constructor[] | AutoControllerOptions): this;
45
- useStaticFiles(options: any): this;
46
- useHttps(options?: any): this;
47
- useGlobal(options: GlobalOptions): this;
48
- useSocketIo(options?: any): this;
49
- useKnex(options: any): this;
50
- mapFeatures(): this;
51
- private _mapControllers;
52
- private _resolveControllerDir;
53
- private autoControllers;
54
- private _mapFeatures;
55
- initializeDatabase(): Promise<void>;
56
- handleSocket(socket: any): void;
57
- mapGet<T extends (...args: any[]) => any>(path: string | undefined, fn: T): {
58
- useMiddleware: <M extends AvleonMiddleware>(middlewares: Constructor<AvleonMiddleware>[]) => /*elided*/ any;
59
- useOpenApi: (options: import("../openapi").OpenApiOptions) => /*elided*/ any;
60
- };
61
- mapPost<T extends (...args: any[]) => any>(path: string | undefined, fn: T): {
62
- useMiddleware: <M extends AvleonMiddleware>(middlewares: Constructor<AvleonMiddleware>[]) => /*elided*/ any;
63
- useOpenApi: (options: import("../openapi").OpenApiOptions) => /*elided*/ any;
64
- };
65
- mapPut<T extends (...args: any[]) => any>(path: string | undefined, fn: T): {
66
- useMiddleware: <M extends AvleonMiddleware>(middlewares: Constructor<AvleonMiddleware>[]) => /*elided*/ any;
67
- useOpenApi: (options: import("../openapi").OpenApiOptions) => /*elided*/ any;
68
- };
69
- mapDelete<T extends (...args: any[]) => any>(path: string | undefined, fn: T): {
70
- useMiddleware: <M extends AvleonMiddleware>(middlewares: Constructor<AvleonMiddleware>[]) => /*elided*/ any;
71
- useOpenApi: (options: import("../openapi").OpenApiOptions) => /*elided*/ any;
72
- };
73
- run(port?: number, fn?: CallableFunction): Promise<void>;
74
- }