@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
package/dist/helpers.js DELETED
@@ -1,27 +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
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
- if (k2 === undefined) k2 = k;
10
- var desc = Object.getOwnPropertyDescriptor(m, k);
11
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
- desc = { enumerable: true, get: function() { return m[k]; } };
13
- }
14
- Object.defineProperty(o, k2, desc);
15
- }) : (function(o, m, k, k2) {
16
- if (k2 === undefined) k2 = k;
17
- o[k2] = m[k];
18
- }));
19
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
20
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
21
- };
22
- Object.defineProperty(exports, "__esModule", { value: true });
23
- __exportStar(require("./utils/common-utils"), exports);
24
- __exportStar(require("./utils/object-utils"), exports);
25
- __exportStar(require("./utils/validation-utils"), exports);
26
- __exportStar(require("./utils/di-utils"), exports);
27
- __exportStar(require("./validation"), exports);
@@ -1 +0,0 @@
1
- export {};
@@ -1,95 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const helpers_1 = require("./helpers");
4
- describe("helpers.ts", () => {
5
- describe("formatUrl", () => {
6
- it("should format URLs correctly", () => {
7
- expect((0, helpers_1.formatUrl)("test")).toBe("/test");
8
- expect((0, helpers_1.formatUrl)("/test")).toBe("/test");
9
- expect((0, helpers_1.formatUrl)("///test//")).toBe("/test");
10
- expect(() => (0, helpers_1.formatUrl)(123)).toThrow();
11
- });
12
- });
13
- describe("parsedPath", () => {
14
- it("should ensure path starts with /", () => {
15
- expect((0, helpers_1.parsedPath)("abc")).toBe("/abc");
16
- expect((0, helpers_1.parsedPath)("/abc")).toBe("/abc");
17
- });
18
- });
19
- describe("findDuplicates", () => {
20
- it("should find duplicates in array", () => {
21
- expect((0, helpers_1.findDuplicates)(["a", "b", "a", "c", "b"])).toEqual(["a", "b"]);
22
- expect((0, helpers_1.findDuplicates)(["a", "b", "c"])).toEqual([]);
23
- });
24
- });
25
- describe("getDataType", () => {
26
- it("should return correct data type", () => {
27
- expect((0, helpers_1.getDataType)(String)).toBe("string");
28
- expect((0, helpers_1.getDataType)(Number)).toBe("number");
29
- expect((0, helpers_1.getDataType)(Boolean)).toBe("boolean");
30
- expect((0, helpers_1.getDataType)(Object)).toBe("object");
31
- expect((0, helpers_1.getDataType)(Array)).toBe(Array);
32
- });
33
- });
34
- describe("isValidType", () => {
35
- it("should validate types correctly", () => {
36
- expect((0, helpers_1.isValidType)("abc", String)).toBe(true);
37
- expect((0, helpers_1.isValidType)(123, Number)).toBe(true);
38
- expect((0, helpers_1.isValidType)(true, Boolean)).toBe(true);
39
- expect((0, helpers_1.isValidType)({}, Object)).toBe(true);
40
- expect((0, helpers_1.isValidType)(undefined, String)).toBe(true);
41
- expect((0, helpers_1.isValidType)(null, Number)).toBe(true);
42
- expect((0, helpers_1.isValidType)("123", Number)).toBe(true);
43
- expect((0, helpers_1.isValidType)("abc", Number)).toBe(false);
44
- });
45
- });
46
- describe("isValidJsonString", () => {
47
- it("should validate JSON strings", () => {
48
- expect((0, helpers_1.isValidJsonString)('{"a":1}')).toEqual({ a: 1 });
49
- expect((0, helpers_1.isValidJsonString)("not json")).toBe(false);
50
- });
51
- });
52
- describe("jsonToJs", () => {
53
- it("should parse JSON to JS object", () => {
54
- expect((0, helpers_1.jsonToJs)('{"a":1}')).toEqual({ a: 1 });
55
- expect((0, helpers_1.jsonToJs)("bad json")).toBe(false);
56
- });
57
- });
58
- // describe("normalizePath", () => {
59
- // it("should normalize paths", () => {
60
- // expect(normalizePath("api", "v1")).toBe("/api/v1");
61
- // expect(normalizePath("/", "/")).toBe("/");
62
- // expect(normalizePath("api/", "/v1/")).toBe("/api/v1");
63
- // });
64
- // });
65
- describe("extrctParamFromUrl", () => {
66
- it("should extract params from URL", () => {
67
- expect((0, helpers_1.extrctParamFromUrl)("/user/:id/:name")).toEqual([
68
- { key: "id", required: true },
69
- { key: "name", required: true },
70
- ]);
71
- expect((0, helpers_1.extrctParamFromUrl)("/user/?:id")).toEqual([
72
- { key: "id", required: false },
73
- ]);
74
- });
75
- });
76
- describe("pick", () => {
77
- it("should pick properties from object", () => {
78
- const obj = { a: 1, b: { c: 2, d: 3 }, e: 4 };
79
- expect((0, helpers_1.pick)(obj, ["a"])).toEqual({ a: 1 });
80
- expect((0, helpers_1.pick)(obj, ["b.c"])).toEqual({ b: { c: 2 } });
81
- expect((0, helpers_1.pick)(obj, ["b.d", "e"])).toEqual({ b: { d: 3 }, e: 4 });
82
- });
83
- });
84
- describe("exclude", () => {
85
- it("should exclude properties from object", () => {
86
- const obj = { a: 1, b: { c: 2, d: 3 }, e: 4 };
87
- expect((0, helpers_1.exclude)(obj, ["a"])).toEqual({ b: { c: 2, d: 3 }, e: 4 });
88
- expect((0, helpers_1.exclude)(obj, ["b.c"])).toEqual({ a: 1, b: { d: 3 }, e: 4 });
89
- expect((0, helpers_1.exclude)([obj, obj], ["e"])).toEqual([
90
- { a: 1, b: { c: 2, d: 3 } },
91
- { a: 1, b: { c: 2, d: 3 } },
92
- ]);
93
- });
94
- });
95
- });
package/dist/index.d.ts DELETED
@@ -1,57 +0,0 @@
1
- /**
2
- * @copyright 2024
3
- * @author Tareq Hossain
4
- * @email xtrinsic96@gmail.com
5
- * @url https://github.com/xtareq
6
- */
7
- import * as sw from "./swagger-schema";
8
- import "reflect-metadata";
9
- export * from "./decorators";
10
- export * from "./interfaces/avleon-application";
11
- export * from "./core/application";
12
- export * from "./core/testing";
13
- export * from "./core/types";
14
- export * from "./helpers";
15
- export * from "./response";
16
- export * from "./exceptions";
17
- export * from "./openapi";
18
- export * from "./swagger-schema";
19
- export * from "./container";
20
- export * from "./middleware";
21
- export * from "./kenx-provider";
22
- export * from "./collection";
23
- export * from "./event-dispatcher";
24
- export * from "./event-subscriber";
25
- export * from "./queue";
26
- export * from "./file-storage";
27
- export * from "./config";
28
- export * from "./logger";
29
- export * from "./cache";
30
- export * from "./results";
31
- export * from "./environment-variables";
32
- export declare const GetSchema: typeof sw.generateSwaggerSchema;
33
- export declare const GetObjectSchema: typeof sw.CreateSwaggerObjectSchema;
34
- export declare const OpenApiOk: (args1: any) => {
35
- description: string;
36
- content: {
37
- "application/json": {
38
- schema: {
39
- type: string;
40
- properties: {
41
- code: {
42
- type: string;
43
- example: number;
44
- };
45
- status: {
46
- type: string;
47
- example: string;
48
- };
49
- data: any;
50
- };
51
- };
52
- };
53
- };
54
- };
55
- export declare const OpenApiResponse: typeof sw.OpenApiResponse;
56
- export declare const OpenApiProperty: typeof sw.OpenApiProperty;
57
- export { default as AvleonContainer } from "./container";
@@ -1,75 +0,0 @@
1
- /**
2
- * @copyright 2024
3
- * @author Tareq Hossain
4
- * @email xtrinsic96@gmail.com
5
- * @url https://github.com/xtareq
6
- */
7
- import { Constructor } from "../helpers";
8
- import { AvleonMiddleware } from "../middleware";
9
- import { DataSource, DataSourceOptions } from "typeorm";
10
- import { OpenApiUiOptions } from "../openapi";
11
- import { FastifyServerOptions, InjectOptions, LightMyRequestResponse } from "fastify";
12
- export type CorsOptions = {
13
- origin?: boolean | string | RegExp | (string | RegExp)[] | ((origin: string, cb: (err: Error | null, allow?: boolean) => void) => void);
14
- methods?: string | string[];
15
- allowedHeaders?: string | string[];
16
- exposedHeaders?: string | string[];
17
- credentials?: boolean;
18
- maxAge?: number;
19
- preflight?: boolean;
20
- strictPreflight?: boolean;
21
- hideOptionsRoute?: boolean;
22
- optionsSuccessStatus?: number;
23
- };
24
- export type GlobalOptions = {
25
- cors?: CorsOptions;
26
- openApi?: OpenApiUiOptions;
27
- controllers?: any;
28
- middlewares?: any;
29
- authorization?: any;
30
- multipart?: any;
31
- staticFiles?: any;
32
- };
33
- export type AvleonApplicationOptions = {
34
- server?: FastifyServerOptions;
35
- dataSourceOptions?: DataSourceOptions;
36
- };
37
- export type AutoControllerOptions = {
38
- auto: true;
39
- path?: string;
40
- };
41
- export interface IAvleonApplication {
42
- useCors: (options: CorsOptions) => this;
43
- useDatasource: (dataSource: DataSource) => this;
44
- useMultipart: (options?: any) => this;
45
- useOpenApi: (options: OpenApiUiOptions) => this;
46
- useMiddlewares: (middlewares: Constructor<AvleonMiddleware>[]) => this;
47
- useAuthorization: (authorization: Constructor<any>) => this;
48
- useSerialization: () => this;
49
- useControllers: (controllers: Constructor[] | AutoControllerOptions) => this;
50
- useStaticFiles: (options: any) => this;
51
- useHttps: (options?: any) => this;
52
- useGlobal: (options: GlobalOptions) => this;
53
- useSocketIo: (options?: any) => this;
54
- useKnex: (options: any) => this;
55
- mapFeatures: () => this;
56
- mapGet: <T extends (...args: any[]) => any>(path: string, fn: T) => any;
57
- mapPost: <T extends (...args: any[]) => any>(path: string, fn: T) => any;
58
- mapPut: <T extends (...args: any[]) => any>(path: string, fn: T) => any;
59
- mapDelete: <T extends (...args: any[]) => any>(path: string, fn: T) => any;
60
- run: (port?: number, fn?: CallableFunction) => Promise<void>;
61
- }
62
- export type TestResponse = LightMyRequestResponse | Promise<LightMyRequestResponse>;
63
- export interface TestApplication {
64
- get: (url: string, options?: InjectOptions) => TestResponse;
65
- post: (url: string, options?: InjectOptions) => TestResponse;
66
- put: (url: string, options?: InjectOptions) => TestResponse;
67
- patch: (url: string, options?: InjectOptions) => TestResponse;
68
- delete: (url: string, options?: InjectOptions) => TestResponse;
69
- options: (url: string, options?: InjectOptions) => TestResponse;
70
- getController: <T>(controller: Constructor<T>, deps?: any[]) => T;
71
- }
72
- export type TestAppOptions = {
73
- controllers: Constructor[] | unknown[];
74
- dataSource?: DataSourceOptions;
75
- };
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,7 +0,0 @@
1
- import type { Knex } from "knex";
2
- export declare class DB {
3
- private connection;
4
- constructor();
5
- init(config: Knex.Config): Knex<any, any[]>;
6
- get client(): Knex;
7
- }
@@ -1,44 +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
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.DB = void 0;
13
- const typedi_1 = require("typedi");
14
- const typedi_2 = require("typedi");
15
- let DB = class DB {
16
- constructor() {
17
- const existing = typedi_2.Container.has("KnexConnection")
18
- ? typedi_2.Container.get("KnexConnection")
19
- : null;
20
- if (existing) {
21
- this.connection = existing;
22
- }
23
- }
24
- // Initialize manually (call this in main if you want)
25
- init(config) {
26
- if (!this.connection) {
27
- const knex = require("knex");
28
- this.connection = knex(config);
29
- typedi_2.Container.set("KnexConnection", this.connection);
30
- }
31
- return this.connection;
32
- }
33
- get client() {
34
- if (!this.connection) {
35
- throw new Error("Knex is not initialized. Call DB.init(config) first.");
36
- }
37
- return this.connection;
38
- }
39
- };
40
- exports.DB = DB;
41
- exports.DB = DB = __decorate([
42
- (0, typedi_1.Service)(),
43
- __metadata("design:paramtypes", [])
44
- ], DB);
@@ -1 +0,0 @@
1
- import "reflect-metadata";
@@ -1,36 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- require("reflect-metadata");
4
- const typedi_1 = require("typedi");
5
- const kenx_provider_1 = require("./kenx-provider");
6
- jest.mock("knex", () => jest.fn(() => ({ mock: "knexInstance" })));
7
- describe("DB", () => {
8
- beforeEach(() => {
9
- typedi_1.Container.reset();
10
- });
11
- it("should throw error if client is accessed before init", () => {
12
- const db = new kenx_provider_1.DB();
13
- expect(() => db.client).toThrow("Knex is not initialized. Call DB.init(config) first.");
14
- });
15
- it("should initialize knex and set connection", () => {
16
- const db = new kenx_provider_1.DB();
17
- const config = { client: "sqlite3", connection: {} };
18
- const conn = db.init(config);
19
- expect(conn).toEqual({ mock: "knexInstance" });
20
- expect(db.client).toEqual({ mock: "knexInstance" });
21
- expect(typedi_1.Container.get("KnexConnection")).toEqual({ mock: "knexInstance" });
22
- });
23
- it("should use existing connection from Container", () => {
24
- const existingConn = { mock: "existingKnex" };
25
- typedi_1.Container.set("KnexConnection", existingConn);
26
- const db = new kenx_provider_1.DB();
27
- expect(db.client).toBe(existingConn);
28
- });
29
- // it("should not reinitialize if connection exists", () => {
30
- // const db = new DB();
31
- // const config = { client: "sqlite3", connection: {} };
32
- // db.init(config as Knex.Config);
33
- // const conn2 = db.init(config as Knex.Config);
34
- // expect(conn2).toEqual({ mock: "knexInstance" });
35
- // });
36
- });
package/dist/logger.d.ts DELETED
@@ -1,12 +0,0 @@
1
- import pino from "pino";
2
- export declare class LoggerService {
3
- private logger;
4
- constructor();
5
- getLogger(): pino.Logger;
6
- info(message: string, obj?: any): void;
7
- error(message: string, obj?: any): void;
8
- warn(message: string, obj?: any): void;
9
- debug(message: string, obj?: any): void;
10
- fatal(message: string, obj?: any): void;
11
- trace(message: string, obj?: any): void;
12
- }
package/dist/logger.js DELETED
@@ -1,87 +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 __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.LoggerService = void 0;
16
- const pino_1 = __importDefault(require("pino"));
17
- const decorators_1 = require("./decorators");
18
- let LoggerService = class LoggerService {
19
- constructor() {
20
- this.logger = (0, pino_1.default)({
21
- level: process.env.LOG_LEVEL || "info",
22
- transport: {
23
- target: "pino-pretty",
24
- options: {
25
- translateTime: "SYS:standard",
26
- ignore: "pid,hostname",
27
- },
28
- },
29
- });
30
- }
31
- getLogger() {
32
- return this.logger;
33
- }
34
- info(message, obj) {
35
- if (obj) {
36
- this.logger.info(obj, message);
37
- }
38
- else {
39
- this.logger.info(message);
40
- }
41
- }
42
- error(message, obj) {
43
- if (obj) {
44
- this.logger.error(obj, message);
45
- }
46
- else {
47
- this.logger.error(message);
48
- }
49
- }
50
- warn(message, obj) {
51
- if (obj) {
52
- this.logger.warn(obj, message);
53
- }
54
- else {
55
- this.logger.warn(message);
56
- }
57
- }
58
- debug(message, obj) {
59
- if (obj) {
60
- this.logger.debug(obj, message);
61
- }
62
- else {
63
- this.logger.debug(message);
64
- }
65
- }
66
- fatal(message, obj) {
67
- if (obj) {
68
- this.logger.fatal(obj, message);
69
- }
70
- else {
71
- this.logger.fatal(message);
72
- }
73
- }
74
- trace(message, obj) {
75
- if (obj) {
76
- this.logger.trace(obj, message);
77
- }
78
- else {
79
- this.logger.trace(message);
80
- }
81
- }
82
- };
83
- exports.LoggerService = LoggerService;
84
- exports.LoggerService = LoggerService = __decorate([
85
- decorators_1.AppService,
86
- __metadata("design:paramtypes", [])
87
- ], LoggerService);
@@ -1 +0,0 @@
1
- export {};
@@ -1,42 +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
- const logger_1 = require("./logger");
7
- const pino_1 = __importDefault(require("pino"));
8
- jest.mock("pino");
9
- describe("LoggerService constructor", () => {
10
- const mockPino = pino_1.default;
11
- beforeEach(() => {
12
- mockPino.mockClear();
13
- });
14
- it("should initialize logger with default level 'info' when LOG_LEVEL is not set", () => {
15
- delete process.env.LOG_LEVEL;
16
- new logger_1.LoggerService();
17
- expect(mockPino).toHaveBeenCalledWith({
18
- level: "info",
19
- transport: {
20
- target: "pino-pretty",
21
- options: {
22
- translateTime: "SYS:standard",
23
- ignore: "pid,hostname",
24
- },
25
- },
26
- });
27
- });
28
- it("should initialize logger with LOG_LEVEL from environment", () => {
29
- process.env.LOG_LEVEL = "debug";
30
- new logger_1.LoggerService();
31
- expect(mockPino).toHaveBeenCalledWith({
32
- level: "debug",
33
- transport: {
34
- target: "pino-pretty",
35
- options: {
36
- translateTime: "SYS:standard",
37
- ignore: "pid,hostname",
38
- },
39
- },
40
- });
41
- });
42
- });
@@ -1,17 +0,0 @@
1
- /**
2
- * @copyright 2024
3
- * @author Tareq Hossain
4
- * @email xtrinsic96@gmail.com
5
- * @url https://github.com/xtareq
6
- */
7
- type Constructor<T = any> = new (...args: any[]) => T;
8
- export declare function PartialType<T>(BaseClass: Constructor<T>): Constructor<Partial<T>>;
9
- /**
10
- * Utility to pick specific properties from a class.
11
- */
12
- export declare function PickType<T, K extends keyof T>(BaseClass: Constructor<T>, keys: K[]): Constructor<Pick<T, K>>;
13
- /**
14
- * Utility to omit specific properties from a class.
15
- */
16
- export declare function OmitType<T, K extends keyof T>(BaseClass: Constructor<T>, keys: K[]): Constructor<Omit<T, K>>;
17
- export {};
package/dist/map-types.js DELETED
@@ -1,89 +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.PartialType = PartialType;
10
- exports.PickType = PickType;
11
- exports.OmitType = OmitType;
12
- function PartialType(BaseClass) {
13
- const baseProperties = [];
14
- let currentPrototype = BaseClass.prototype;
15
- // Collect properties from the base class (including inherited ones)
16
- while (currentPrototype && currentPrototype !== Object.prototype) {
17
- const properties = Object.getOwnPropertyNames(currentPrototype).filter((prop) => prop !== "constructor");
18
- // Retrieve metadata for each property
19
- properties.forEach((key) => {
20
- // Check if the property has type metadata (design:type)
21
- const designType = Reflect.getMetadata("design:type", currentPrototype, key);
22
- if (designType) {
23
- baseProperties.push(key);
24
- }
25
- // Retrieve validation metadata (class-validator)
26
- const validationMetadata = Reflect.getMetadataKeys(currentPrototype, key);
27
- validationMetadata.forEach((metadataKey) => { });
28
- });
29
- currentPrototype = Object.getPrototypeOf(currentPrototype); // Move up the prototype chain
30
- }
31
- class PartialClass {
32
- }
33
- // Define properties as optional and copy metadata
34
- baseProperties.forEach((key) => {
35
- const propertyType = Reflect.getMetadata("design:type", BaseClass.prototype, key);
36
- Reflect.defineMetadata("design:type", propertyType, PartialClass.prototype, key);
37
- // Propagate class-validator metadata to the new class
38
- const validationMetadataKeys = Reflect.getMetadataKeys(BaseClass.prototype, key) || [];
39
- validationMetadataKeys.forEach((metadataKey) => {
40
- const metadataValue = Reflect.getMetadata(metadataKey, BaseClass.prototype, key);
41
- Reflect.defineMetadata(metadataKey, metadataValue, PartialClass.prototype, key);
42
- });
43
- });
44
- // Copy other metadata from the base class (non-property metadata)
45
- Reflect.getMetadataKeys(BaseClass.prototype).forEach((key) => {
46
- const metadataValue = Reflect.getMetadata(key, BaseClass.prototype);
47
- Reflect.defineMetadata(key, metadataValue, PartialClass.prototype);
48
- });
49
- return PartialClass;
50
- }
51
- /**
52
- * Utility to pick specific properties from a class.
53
- */
54
- function PickType(BaseClass, keys) {
55
- class PickClass {
56
- constructor() {
57
- keys.forEach((key) => {
58
- Reflect.defineMetadata("design:type", Reflect.getMetadata("design:type", BaseClass.prototype, key), this, key);
59
- });
60
- }
61
- }
62
- Reflect.decorate([Reflect.metadata("design:properties", keys)], PickClass);
63
- // Copy metadata from BaseClass to PickClass
64
- Reflect.getMetadataKeys(BaseClass.prototype).forEach((key) => {
65
- Reflect.defineMetadata(key, Reflect.getMetadata(key, BaseClass.prototype), PickClass.prototype);
66
- });
67
- return PickClass;
68
- }
69
- /**
70
- * Utility to omit specific properties from a class.
71
- */
72
- function OmitType(BaseClass, keys) {
73
- const allKeys = Reflect.getMetadata("design:properties", BaseClass) || [];
74
- const omitKeys = new Set(keys);
75
- const finalKeys = allKeys.filter((key) => !omitKeys.has(key));
76
- class OmitClass {
77
- constructor() {
78
- finalKeys.forEach((key) => {
79
- Reflect.defineMetadata("design:type", Reflect.getMetadata("design:type", BaseClass.prototype, key), this, key);
80
- });
81
- }
82
- }
83
- Reflect.decorate([Reflect.metadata("design:properties", finalKeys)], OmitClass);
84
- // Copy metadata from BaseClass to OmitClass
85
- Reflect.getMetadataKeys(BaseClass.prototype).forEach((key) => {
86
- Reflect.defineMetadata(key, Reflect.getMetadata(key, BaseClass.prototype), OmitClass.prototype);
87
- });
88
- return OmitClass;
89
- }
@@ -1,34 +0,0 @@
1
- import { IRequest, IResponse } from "./core/types";
2
- import { HttpExceptionTypes as HttpException } from "./exceptions";
3
- import { Constructor } from "./helpers";
4
- export declare abstract class AvleonMiddleware {
5
- abstract invoke(req: IRequest, res?: IResponse): Promise<IRequest | HttpException>;
6
- }
7
- export type AuthHandler = (req: IRequest, roles?: string[]) => Promise<IRequest | HttpException>;
8
- export declare abstract class AuthorizeMiddleware {
9
- abstract authorize(roles: string[]): (req: IRequest, res?: IResponse) => IRequest | Promise<IRequest>;
10
- }
11
- export type AuthReturnTypes = IRequest | Promise<IRequest>;
12
- interface AuthorizeClass {
13
- authorize(req: IRequest, options?: any): AuthReturnTypes;
14
- }
15
- export declare function CanAuthorize(target: {
16
- new (...args: any[]): AuthorizeClass;
17
- }): void;
18
- export declare function AppAuthorization(target: {
19
- new (...args: any[]): AuthorizeClass;
20
- }): void;
21
- export declare function Authorized(): ClassDecorator & MethodDecorator;
22
- export declare function Authorized(options?: any): ClassDecorator & MethodDecorator;
23
- export declare function AppMiddleware(target: Constructor<AvleonMiddleware>): void;
24
- /**
25
- * A decorator function that applies one or more middleware to a class or a method.
26
- *
27
- * When applied to a class, the middleware are registered for the entire controller.
28
- * When applied to a method, the middleware are registered for that specific route.
29
- *
30
- * @param options - A single middleware instance/class or an array of middleware instances/classes to be applied.
31
- * @returns A decorator that registers the middleware metadata.
32
- */
33
- export declare function UseMiddleware<T extends AvleonMiddleware | (new (...args: any[]) => AvleonMiddleware)>(options: T | T[]): MethodDecorator & ClassDecorator;
34
- export {};