@avleon/core 0.0.45 → 0.0.48

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 (131) hide show
  1. package/README.md +355 -369
  2. package/dist/chunk-9hOWP6kD.cjs +64 -0
  3. package/dist/chunk-DORXReHP.js +37 -0
  4. package/dist/index-BxIMWhgy.d.ts +1284 -0
  5. package/dist/index-DPn7qtzq.d.cts +1283 -0
  6. package/dist/index.cjs +3194 -0
  7. package/dist/index.cjs.map +1 -0
  8. package/dist/index.js +3022 -83
  9. package/dist/index.js.map +1 -0
  10. package/dist/lib-Bk8hUm06.cjs +7847 -0
  11. package/dist/lib-Bk8hUm06.cjs.map +1 -0
  12. package/dist/lib-CvDxBMkR.js +7843 -0
  13. package/dist/lib-CvDxBMkR.js.map +1 -0
  14. package/package.json +67 -116
  15. package/dist/application.d.ts +0 -47
  16. package/dist/application.js +0 -50
  17. package/dist/authentication.d.ts +0 -13
  18. package/dist/authentication.js +0 -16
  19. package/dist/cache.d.ts +0 -12
  20. package/dist/cache.js +0 -78
  21. package/dist/cache.test.d.ts +0 -1
  22. package/dist/cache.test.js +0 -36
  23. package/dist/collection.d.ts +0 -43
  24. package/dist/collection.js +0 -231
  25. package/dist/collection.test.d.ts +0 -1
  26. package/dist/collection.test.js +0 -59
  27. package/dist/config.d.ts +0 -18
  28. package/dist/config.js +0 -58
  29. package/dist/config.test.d.ts +0 -1
  30. package/dist/config.test.js +0 -40
  31. package/dist/constants.d.ts +0 -1
  32. package/dist/constants.js +0 -4
  33. package/dist/container.d.ts +0 -30
  34. package/dist/container.js +0 -55
  35. package/dist/controller.d.ts +0 -50
  36. package/dist/controller.js +0 -71
  37. package/dist/controller.test.d.ts +0 -1
  38. package/dist/controller.test.js +0 -111
  39. package/dist/decorators.d.ts +0 -15
  40. package/dist/decorators.js +0 -41
  41. package/dist/environment-variables.d.ts +0 -49
  42. package/dist/environment-variables.js +0 -130
  43. package/dist/environment-variables.test.d.ts +0 -1
  44. package/dist/environment-variables.test.js +0 -70
  45. package/dist/event-dispatcher.d.ts +0 -23
  46. package/dist/event-dispatcher.js +0 -100
  47. package/dist/event-subscriber.d.ts +0 -14
  48. package/dist/event-subscriber.js +0 -87
  49. package/dist/exceptions/http-exceptions.d.ts +0 -50
  50. package/dist/exceptions/http-exceptions.js +0 -85
  51. package/dist/exceptions/index.d.ts +0 -1
  52. package/dist/exceptions/index.js +0 -17
  53. package/dist/exceptions/system-exception.d.ts +0 -22
  54. package/dist/exceptions/system-exception.js +0 -26
  55. package/dist/file-storage.d.ts +0 -69
  56. package/dist/file-storage.js +0 -323
  57. package/dist/file-storage.test.d.ts +0 -1
  58. package/dist/file-storage.test.js +0 -104
  59. package/dist/helpers.d.ts +0 -44
  60. package/dist/helpers.js +0 -419
  61. package/dist/helpers.test.d.ts +0 -1
  62. package/dist/helpers.test.js +0 -95
  63. package/dist/icore.d.ts +0 -226
  64. package/dist/icore.js +0 -968
  65. package/dist/icore.test.d.ts +0 -1
  66. package/dist/icore.test.js +0 -14
  67. package/dist/index.d.ts +0 -55
  68. package/dist/interfaces/avleon-application.d.ts +0 -27
  69. package/dist/interfaces/avleon-application.js +0 -1
  70. package/dist/kenx-provider.d.ts +0 -7
  71. package/dist/kenx-provider.js +0 -44
  72. package/dist/kenx-provider.test.d.ts +0 -1
  73. package/dist/kenx-provider.test.js +0 -36
  74. package/dist/logger.d.ts +0 -12
  75. package/dist/logger.js +0 -87
  76. package/dist/logger.test.d.ts +0 -1
  77. package/dist/logger.test.js +0 -42
  78. package/dist/map-types.d.ts +0 -17
  79. package/dist/map-types.js +0 -89
  80. package/dist/middleware.d.ts +0 -27
  81. package/dist/middleware.js +0 -64
  82. package/dist/middleware.test.d.ts +0 -1
  83. package/dist/middleware.test.js +0 -121
  84. package/dist/multipart.d.ts +0 -17
  85. package/dist/multipart.js +0 -70
  86. package/dist/multipart.test.d.ts +0 -1
  87. package/dist/multipart.test.js +0 -87
  88. package/dist/openapi.d.ts +0 -343
  89. package/dist/openapi.js +0 -27
  90. package/dist/openapi.test.d.ts +0 -1
  91. package/dist/openapi.test.js +0 -111
  92. package/dist/params.d.ts +0 -17
  93. package/dist/params.js +0 -64
  94. package/dist/params.test.d.ts +0 -1
  95. package/dist/params.test.js +0 -83
  96. package/dist/queue.d.ts +0 -29
  97. package/dist/queue.js +0 -84
  98. package/dist/response.d.ts +0 -16
  99. package/dist/response.js +0 -56
  100. package/dist/results.d.ts +0 -20
  101. package/dist/results.js +0 -32
  102. package/dist/route-methods.d.ts +0 -25
  103. package/dist/route-methods.js +0 -49
  104. package/dist/route-methods.test.d.ts +0 -1
  105. package/dist/route-methods.test.js +0 -129
  106. package/dist/swagger-schema.d.ts +0 -43
  107. package/dist/swagger-schema.js +0 -452
  108. package/dist/swagger-schema.test.d.ts +0 -1
  109. package/dist/swagger-schema.test.js +0 -105
  110. package/dist/testing.d.ts +0 -55
  111. package/dist/testing.js +0 -196
  112. package/dist/types/app-builder.interface.d.ts +0 -15
  113. package/dist/types/app-builder.interface.js +0 -8
  114. package/dist/types/application.interface.d.ts +0 -8
  115. package/dist/types/application.interface.js +0 -2
  116. package/dist/utils/hash.d.ts +0 -4
  117. package/dist/utils/hash.js +0 -15
  118. package/dist/utils/index.d.ts +0 -2
  119. package/dist/utils/index.js +0 -18
  120. package/dist/utils/optional-require.d.ts +0 -8
  121. package/dist/utils/optional-require.js +0 -70
  122. package/dist/validation.d.ts +0 -39
  123. package/dist/validation.js +0 -111
  124. package/dist/validation.test.d.ts +0 -1
  125. package/dist/validation.test.js +0 -61
  126. package/dist/validator-extend.d.ts +0 -7
  127. package/dist/validator-extend.js +0 -28
  128. package/dist/websocket.d.ts +0 -7
  129. package/dist/websocket.js +0 -20
  130. package/dist/websocket.test.d.ts +0 -1
  131. package/dist/websocket.test.js +0 -27
package/dist/testing.js DELETED
@@ -1,196 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AvleonTestBuilder = exports.AvleonTestUtility = void 0;
4
- exports.UnitTest = UnitTest;
5
- require("reflect-metadata");
6
- const typedi_1 = require("typedi");
7
- const typeorm_1 = require("typeorm");
8
- const icore_1 = require("./icore");
9
- // Enhanced Test Utilities
10
- class AvleonTestUtility {
11
- /**
12
- * Initialize test environment
13
- */
14
- static async init(options) {
15
- // Reset container if specified
16
- if (options === null || options === void 0 ? void 0 : options.resetContainer) {
17
- this.testContainer = typedi_1.Container;
18
- this.testContainer.reset();
19
- }
20
- // Initialize test database if options provided
21
- if (options === null || options === void 0 ? void 0 : options.dataSourceOptions) {
22
- this.testDataSource = new typeorm_1.DataSource({
23
- ...options.dataSourceOptions,
24
- logging: false, // Disable logging during tests
25
- });
26
- await this.testDataSource.initialize();
27
- await this.testDataSource.synchronize(true); // Create schema
28
- }
29
- return this;
30
- }
31
- /**
32
- * Mock a dependency for testing
33
- * @param token Dependency token
34
- * @param mockImplementation Mock implementation
35
- */
36
- static mockDependency(token, mockImplementation) {
37
- typedi_1.Container.set(token, mockImplementation);
38
- return mockImplementation;
39
- }
40
- /**
41
- * Create an isolated test instance of a class
42
- * @param ClassType Class to instantiate
43
- * @param overrides Optional property overrides
44
- */
45
- static createTestInstance(ClassType, overrides = {}) {
46
- const instance = typedi_1.Container.get(ClassType);
47
- // Apply overrides
48
- Object.keys(overrides).forEach((key) => {
49
- instance[key] = overrides[key];
50
- });
51
- return instance;
52
- }
53
- /**
54
- * Cleanup test environment
55
- */
56
- static async cleanup() {
57
- if (this.testDataSource) {
58
- await this.testDataSource.dropDatabase();
59
- await this.testDataSource.destroy();
60
- this.testDataSource = null;
61
- }
62
- // Reset container
63
- typedi_1.Container.reset();
64
- }
65
- }
66
- exports.AvleonTestUtility = AvleonTestUtility;
67
- AvleonTestUtility.testDataSource = null;
68
- // Enhanced Test Builder
69
- class AvleonTestBuilder {
70
- constructor() {
71
- this.controllers = [];
72
- this.testOptions = {};
73
- this.mocks = new Map();
74
- }
75
- /**
76
- * Add controllers for testing
77
- * @param controllers Controllers to add
78
- */
79
- addControllers(...controllers) {
80
- this.controllers.push(...controllers);
81
- return this;
82
- }
83
- /**
84
- * Mock a dependency
85
- * @param token Dependency token
86
- * @param mockImplementation Mock implementation
87
- */
88
- mockDependency(token, mockImplementation) {
89
- this.mocks.set(token, mockImplementation);
90
- return this;
91
- }
92
- /**
93
- * Set test options
94
- * @param options Test configuration options
95
- */
96
- setOptions(options) {
97
- this.testOptions = { ...this.testOptions, ...options };
98
- return this;
99
- }
100
- /**
101
- * Build test application
102
- */
103
- async build() {
104
- // Apply mocks
105
- this.mocks.forEach((mock, token) => {
106
- typedi_1.Container.set(token, mock);
107
- });
108
- // Initialize test utility
109
- await AvleonTestUtility.init({
110
- dataSourceOptions: this.testOptions.dataSourceOptions,
111
- resetContainer: true,
112
- });
113
- // Create test application
114
- const app = icore_1.AvleonApplication.getInternalApp({
115
- dataSourceOptions: this.testOptions.dataSourceOptions,
116
- });
117
- // Map controllers
118
- app.useControllers(this.controllers);
119
- // Get test application
120
- return app.getTestApp();
121
- }
122
- }
123
- exports.AvleonTestBuilder = AvleonTestBuilder;
124
- // Example Usage Decorator
125
- function UnitTest() {
126
- return (target, propertyKey, descriptor) => {
127
- const originalMethod = descriptor.value;
128
- descriptor.value = async function (...args) {
129
- try {
130
- // Pre-test setup
131
- await AvleonTestUtility.init();
132
- // Execute test
133
- const result = await originalMethod.apply(this, args);
134
- // Post-test cleanup
135
- await AvleonTestUtility.cleanup();
136
- return result;
137
- }
138
- catch (error) {
139
- // Ensure cleanup even if test fails
140
- await AvleonTestUtility.cleanup();
141
- throw error;
142
- }
143
- };
144
- return descriptor;
145
- };
146
- }
147
- //
148
- // // Example of Unit and Integration Test
149
- // class UserServiceTest {
150
- // @UnitTest()
151
- // async testUserCreation() {
152
- // // Mock UserRepository
153
- // const mockRepo = AvleonTestUtility.mockDependency(
154
- // UserRepository,
155
- // { create: jest.fn() }
156
- // );
157
- //
158
- // // Create test instance
159
- // const userService = AvleonTestUtility.createTestInstance(UserService);
160
- //
161
- // // Perform test
162
- // const result = await userService.createUser({
163
- // name: 'Test User',
164
- // email: 'test@example.com'
165
- // });
166
- //
167
- // // Assertions
168
- // expect(mockRepo.create).toHaveBeenCalledWith(expect.any(Object));
169
- // }
170
- // }
171
- //
172
- // // Enhanced E2E Testing Example
173
- // class E2EUserControllerTest {
174
- // async testUserRegistration() {
175
- // // Build test application
176
- // const testApp = await new AvleonTestBuilder()
177
- // .addControllers(UserController)
178
- // .mockDependency(AuthService, mockAuthService)
179
- // .setOptions({
180
- // dataSourceOptions: testDatabaseConfig
181
- // })
182
- // .build();
183
- //
184
- // // Perform HTTP request
185
- // const response = await testApp.post('/users/register', {
186
- // payload: {
187
- // name: 'John Doe',
188
- // email: 'john@example.com'
189
- // }
190
- // });
191
- //
192
- // // Assertions
193
- // expect(response.statusCode).toBe(201);
194
- // expect(response.json()).toHaveProperty('userId');
195
- // }
196
- // }
@@ -1,15 +0,0 @@
1
- /**
2
- * @copyright 2024
3
- * @author Tareq Hossain
4
- * @email xtrinsic96@gmail.com
5
- * @url https://github.com/xtareq
6
- */
7
- import { IApplication } from "./application.interface";
8
- export interface IAppBuilder {
9
- createBuilder(): IAppBuilder;
10
- /**
11
- * @description will create a application instace
12
- * @returns IApplication
13
- */
14
- builder: () => IApplication;
15
- }
@@ -1,8 +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 });
@@ -1,8 +0,0 @@
1
- /**
2
- * @copyright 2024
3
- * @author Tareq Hossain
4
- * @email xtrinsic96@gmail.com
5
- * @url https://github.com/xtareq
6
- */
7
- export interface IApplication {
8
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,4 +0,0 @@
1
- export declare const hashPasswordSync: (password: string) => string;
2
- export declare const matchPasswordSync: (password: string, hash: string) => boolean;
3
- export declare const hashPassword: (password: string) => Promise<string>;
4
- export declare const matchPassword: (password: string, hash: string) => Promise<boolean>;
@@ -1,15 +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.matchPassword = exports.hashPassword = exports.matchPasswordSync = exports.hashPasswordSync = void 0;
7
- const bcryptjs_1 = __importDefault(require("bcryptjs"));
8
- const hashPasswordSync = (password) => bcryptjs_1.default.hashSync(password, 12);
9
- exports.hashPasswordSync = hashPasswordSync;
10
- const matchPasswordSync = (password, hash) => bcryptjs_1.default.compareSync(password, hash);
11
- exports.matchPasswordSync = matchPasswordSync;
12
- const hashPassword = (password) => bcryptjs_1.default.hash(password, 12);
13
- exports.hashPassword = hashPassword;
14
- const matchPassword = (password, hash) => bcryptjs_1.default.compare(password, hash);
15
- exports.matchPassword = matchPassword;
@@ -1,2 +0,0 @@
1
- export * from "./hash";
2
- export * from "./optional-require";
@@ -1,18 +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("./hash"), exports);
18
- __exportStar(require("./optional-require"), exports);
@@ -1,8 +0,0 @@
1
- export declare function optionalRequire<T = any>(moduleName: string, options?: {
2
- failOnMissing?: boolean;
3
- customMessage?: string;
4
- }): T | undefined;
5
- export declare function optionalImport<T = any>(moduleName: string, options?: {
6
- failOnMissing?: boolean;
7
- customMessage?: string;
8
- }): Promise<T | undefined>;
@@ -1,70 +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 __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.optionalRequire = optionalRequire;
37
- exports.optionalImport = optionalImport;
38
- function optionalRequire(moduleName, options = {}) {
39
- try {
40
- return require(moduleName);
41
- }
42
- catch (err) {
43
- if (err.code === "MODULE_NOT_FOUND" && err.message.includes(moduleName)) {
44
- if (options.failOnMissing) {
45
- throw new Error(options.customMessage ||
46
- `Optional dependency "${moduleName}" is not installed.\nInstall it with:\n\n npm install ${moduleName}`);
47
- }
48
- return undefined;
49
- }
50
- throw err;
51
- }
52
- }
53
- async function optionalImport(moduleName, options = {}) {
54
- try {
55
- const mod = await Promise.resolve(`${moduleName}`).then(s => __importStar(require(s)));
56
- return mod;
57
- }
58
- catch (err) {
59
- if ((err.code === "ERR_MODULE_NOT_FOUND" ||
60
- err.code === "MODULE_NOT_FOUND") &&
61
- err.message.includes(moduleName)) {
62
- if (options.failOnMissing) {
63
- throw new Error(options.customMessage ||
64
- `Optional dependency "${moduleName}" is not installed.\nInstall it with:\n\n npm install ${moduleName}`);
65
- }
66
- return undefined;
67
- }
68
- throw err;
69
- }
70
- }
@@ -1,39 +0,0 @@
1
- /**
2
- * @copyright 2024
3
- * @author Tareq Hossain
4
- * @email xtrinsic96@gmail.com
5
- * @url https://github.com/xtareq
6
- */
7
- type BaseRule = {
8
- required?: boolean;
9
- optional?: boolean;
10
- message?: string;
11
- };
12
- type StringRule = BaseRule & {
13
- type: "string";
14
- };
15
- type NumberRule = BaseRule & {
16
- type: "number";
17
- min?: number;
18
- max?: number;
19
- exact?: number;
20
- };
21
- type BooleanRule = BaseRule & {
22
- type: "boolean";
23
- };
24
- export type ValidationRule = StringRule | NumberRule | BooleanRule;
25
- export type ValidationProps = {
26
- [key: string]: ValidationRule;
27
- };
28
- export type ValidateOptons = {
29
- location?: "header" | "queryparam" | "param" | "body" | "custom";
30
- };
31
- export declare class Validator {
32
- private rules;
33
- private options;
34
- constructor(obj: ValidationProps, options?: ValidateOptons);
35
- private init;
36
- validate(obj: any | Array<any>, options?: ValidateOptons): any[];
37
- }
38
- export declare function validateOrThrow<T extends {}>(obj: T, rules: ValidationProps, options?: ValidateOptons): any;
39
- export {};
@@ -1,111 +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.Validator = void 0;
10
- exports.validateOrThrow = validateOrThrow;
11
- const exceptions_1 = require("./exceptions");
12
- class PValidationRule {
13
- constructor(name, type, message) {
14
- this.name = name;
15
- this.type = type;
16
- this.message = message;
17
- }
18
- }
19
- class Validator {
20
- constructor(obj, options) {
21
- this.rules = [];
22
- this.options = {};
23
- this.init(obj);
24
- if (options) {
25
- this.options = options;
26
- }
27
- }
28
- init(obj) {
29
- Object.keys(obj).forEach((key) => {
30
- const rule = obj[key];
31
- this.rules.push(new PValidationRule(key, rule.type, rule.message));
32
- });
33
- }
34
- validate(obj, options) {
35
- const erors = [];
36
- this.rules.forEach((k) => {
37
- const r = Object.keys(obj).find((key) => key == k.name);
38
- let messages = [];
39
- if (!r || obj[r] == undefined || obj[r] == "") {
40
- messages.push({
41
- constraint: "required",
42
- message: k.name + " is required",
43
- });
44
- }
45
- if (k.type == "string" && typeof obj[k.name] != "string") {
46
- messages.push({
47
- constraint: "type",
48
- message: `${k.name} must be type ${k.type}`,
49
- });
50
- }
51
- if (k.type == "number" && !parseInt(obj[k.name])) {
52
- messages.push({
53
- constraint: "type",
54
- message: `${k.name} must be type ${k.type}`,
55
- });
56
- }
57
- if (k.type == "number") {
58
- obj[k.name] = parseInt(obj[k.name]);
59
- }
60
- if (k.type == "boolean" && !isBool(obj[k.name])) {
61
- messages.push({
62
- constraint: "type",
63
- message: `${k.name} must be type ${k.type}`,
64
- });
65
- }
66
- if (k.type == "boolean") {
67
- obj[k.name] = parseBoolean(obj[k.name]);
68
- }
69
- if (messages.length > 0) {
70
- erors.push({
71
- path: k.name,
72
- ...(this.options.location ? { location: this.options.location } : {}),
73
- constraints: messages,
74
- });
75
- }
76
- });
77
- return [erors, obj];
78
- }
79
- }
80
- exports.Validator = Validator;
81
- const isBool = (val) => {
82
- if (typeof val == "boolean")
83
- return true;
84
- if (parseInt(val) == 0 || parseInt(val) == 1)
85
- return true;
86
- if (val == "true" || val == "false")
87
- return true;
88
- return false;
89
- };
90
- const parseBoolean = (val) => {
91
- if (typeof val === "boolean")
92
- return val;
93
- // if (typeof val === "number") {
94
- // return val !== 0; // Common convention: 0 → false, any other number → true
95
- // }
96
- if (parseInt(val) == 1)
97
- return true;
98
- if (typeof val === "string") {
99
- const normalized = val.trim().toLowerCase();
100
- return normalized === "true";
101
- }
102
- return false; // Default for unsupported types (null, undefined, objects, etc.)
103
- };
104
- function validateOrThrow(obj, rules, options) {
105
- const valid = new Validator(rules, options);
106
- const errors = valid.validate(obj);
107
- if (errors[0].length > 0) {
108
- throw new exceptions_1.BadRequestException(errors[0]);
109
- }
110
- return errors[1];
111
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,61 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const validation_1 = require("./validation");
4
- describe("Validator.validate", () => {
5
- const rules = {
6
- username: { type: "string", required: true },
7
- age: { type: "number", required: true },
8
- isActive: { type: "boolean", required: true },
9
- };
10
- it("should pass validation for correct types", () => {
11
- const validator = new validation_1.Validator(rules);
12
- const input = { username: "john", age: 25, isActive: true };
13
- const [errors, validated] = validator.validate(input);
14
- expect(errors).toEqual([]);
15
- expect(validated).toEqual({ username: "john", age: 25, isActive: true });
16
- });
17
- it("should fail when required fields are missing", () => {
18
- const validator = new validation_1.Validator(rules);
19
- const input = { age: 30 };
20
- const [errors] = validator.validate(input);
21
- expect(errors).toEqual(expect.arrayContaining([
22
- expect.objectContaining({ path: "username" }),
23
- expect.objectContaining({ path: "isActive" }),
24
- ]));
25
- });
26
- it("should fail when types are incorrect", () => {
27
- const validator = new validation_1.Validator(rules);
28
- const input = { username: 123, age: "notanumber", isActive: "notabool" };
29
- const [errors] = validator.validate(input);
30
- expect(errors).toEqual(expect.arrayContaining([
31
- expect.objectContaining({ path: "username" }),
32
- expect.objectContaining({ path: "age" }),
33
- expect.objectContaining({ path: "isActive" }),
34
- ]));
35
- });
36
- it("should coerce number and boolean types", () => {
37
- const validator = new validation_1.Validator(rules);
38
- const input = { username: "john", age: "42", isActive: "true" };
39
- const [errors, validated] = validator.validate(input);
40
- expect(errors).toEqual([]);
41
- expect(validated.age).toBe(42);
42
- expect(validated.isActive).toBe(true);
43
- });
44
- it("should handle boolean values as 0/1 and 'true'/'false'", () => {
45
- const validator = new validation_1.Validator(rules);
46
- const input1 = { username: "john", age: 20, isActive: 1 };
47
- const input2 = { username: "john", age: 20, isActive: "false" };
48
- const [errors1, validated1] = validator.validate(input1);
49
- const [errors2, validated2] = validator.validate(input2);
50
- expect(errors1).toEqual([]);
51
- expect(validated1.isActive).toBe(true);
52
- expect(errors2).toEqual([]);
53
- expect(validated2.isActive).toBe(false);
54
- });
55
- it("should include location in error if option is set", () => {
56
- const validator = new validation_1.Validator(rules, { location: "body" });
57
- const input = { age: 30 };
58
- const [errors] = validator.validate(input);
59
- expect(errors[0]).toHaveProperty("location", "body");
60
- });
61
- });
@@ -1,7 +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 function IsArrayNotEmpty(validationOptions?: any): (object: Object, propertyName: string) => void;
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IsArrayNotEmpty = IsArrayNotEmpty;
4
- /**
5
- * @copyright 2024
6
- * @author Tareq Hossain
7
- * @email xtrinsic96@gmail.com
8
- * @url https://github.com/xtareq
9
- */
10
- function IsArrayNotEmpty(validationOptions) {
11
- const { registerDecorator, ValidationArguments } = require("class-validator");
12
- return function (object, propertyName) {
13
- registerDecorator({
14
- name: "isArrayWithAtLeastOneElement",
15
- target: object.constructor,
16
- propertyName: propertyName,
17
- options: validationOptions,
18
- validator: {
19
- validate(value, args) {
20
- return Array.isArray(value) && value.length > 0;
21
- },
22
- defaultMessage(args) {
23
- return `${args.property} must contain at least one item.`;
24
- },
25
- },
26
- });
27
- };
28
- }
@@ -1,7 +0,0 @@
1
- export declare class AvleonSocketIo {
2
- private io?;
3
- sendToAll(): void;
4
- sendOnly(): void;
5
- sendRoom(): void;
6
- receive(channel: string): void;
7
- }
package/dist/websocket.js DELETED
@@ -1,20 +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
- exports.AvleonSocketIo = void 0;
10
- const typedi_1 = require("typedi");
11
- let AvleonSocketIo = class AvleonSocketIo {
12
- sendToAll() { }
13
- sendOnly() { }
14
- sendRoom() { }
15
- receive(channel) { }
16
- };
17
- exports.AvleonSocketIo = AvleonSocketIo;
18
- exports.AvleonSocketIo = AvleonSocketIo = __decorate([
19
- (0, typedi_1.Service)()
20
- ], AvleonSocketIo);
@@ -1 +0,0 @@
1
- export {};
@@ -1,27 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const websocket_1 = require("./websocket");
4
- describe("AvleonSocketIo", () => {
5
- let avleonSocketIo;
6
- beforeEach(() => {
7
- avleonSocketIo = new websocket_1.AvleonSocketIo();
8
- });
9
- it("should be defined", () => {
10
- expect(avleonSocketIo).toBeDefined();
11
- });
12
- it("should have sendToAll method", () => {
13
- expect(typeof avleonSocketIo.sendToAll).toBe("function");
14
- });
15
- it("should have sendOnly method", () => {
16
- expect(typeof avleonSocketIo.sendOnly).toBe("function");
17
- });
18
- it("should have sendRoom method", () => {
19
- expect(typeof avleonSocketIo.sendRoom).toBe("function");
20
- });
21
- it("should have receive method", () => {
22
- expect(typeof avleonSocketIo.receive).toBe("function");
23
- });
24
- it("receive should accept a channel string", () => {
25
- expect(() => avleonSocketIo.receive("test-channel")).not.toThrow();
26
- });
27
- });