@avleon/core 0.0.45 → 0.0.46

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 (54) hide show
  1. package/License +21 -21
  2. package/README.md +667 -681
  3. package/dist/application.test.js +15 -0
  4. package/dist/controller.test.js +0 -14
  5. package/dist/core/application.d.ts +74 -0
  6. package/dist/core/application.js +424 -0
  7. package/dist/core/router.d.ts +44 -0
  8. package/dist/core/router.js +520 -0
  9. package/dist/core/testing.d.ts +21 -0
  10. package/dist/core/testing.js +104 -0
  11. package/dist/core/types.d.ts +67 -0
  12. package/dist/core/types.js +2 -0
  13. package/dist/event-dispatcher.d.ts +0 -1
  14. package/dist/event-dispatcher.js +4 -7
  15. package/dist/file-storage.test.js +15 -2
  16. package/dist/helpers.d.ts +9 -42
  17. package/dist/helpers.js +19 -411
  18. package/dist/index.d.ts +17 -15
  19. package/dist/index.js +18 -22
  20. package/dist/interfaces/avleon-application.d.ts +74 -26
  21. package/dist/interfaces/avleon-application.js +1 -0
  22. package/dist/middleware.d.ts +11 -4
  23. package/dist/middleware.js +9 -0
  24. package/dist/multipart.d.ts +2 -2
  25. package/dist/openapi.d.ts +70 -3
  26. package/dist/openapi.js +32 -0
  27. package/dist/params.js +1 -1
  28. package/dist/params.test.js +8 -8
  29. package/dist/route-methods.js +16 -5
  30. package/dist/swagger-schema.d.ts +11 -17
  31. package/dist/swagger-schema.js +84 -82
  32. package/dist/swagger-schema.test.js +32 -12
  33. package/dist/utils/common-utils.d.ts +17 -0
  34. package/dist/utils/common-utils.js +108 -0
  35. package/dist/utils/di-utils.d.ts +1 -0
  36. package/dist/utils/di-utils.js +22 -0
  37. package/dist/utils/hash.d.ts +0 -2
  38. package/dist/utils/hash.js +1 -5
  39. package/dist/utils/object-utils.d.ts +11 -0
  40. package/dist/utils/object-utils.js +198 -0
  41. package/dist/utils/validation-utils.d.ts +13 -0
  42. package/dist/utils/validation-utils.js +119 -0
  43. package/dist/validation.js +1 -4
  44. package/dist/websocket.d.ts +3 -0
  45. package/dist/websocket.js +2 -1
  46. package/package.json +53 -40
  47. package/dist/application.d.ts +0 -47
  48. package/dist/application.js +0 -50
  49. package/dist/icore.d.ts +0 -226
  50. package/dist/icore.js +0 -968
  51. package/dist/icore.test.js +0 -14
  52. package/dist/testing.d.ts +0 -55
  53. package/dist/testing.js +0 -196
  54. /package/dist/{icore.test.d.ts → application.test.d.ts} +0 -0
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const icore_1 = require("./icore");
4
- describe("Avleon.createApplication", () => {
5
- it("should return an instance of AvleonApplication", () => {
6
- const app = icore_1.Avleon.createApplication();
7
- expect(app).toBeInstanceOf(icore_1.AvleonApplication);
8
- });
9
- it("should always return the same instance (singleton)", () => {
10
- const app1 = icore_1.Avleon.createApplication();
11
- const app2 = icore_1.Avleon.createApplication();
12
- expect(app1).toBe(app2);
13
- });
14
- });
package/dist/testing.d.ts DELETED
@@ -1,55 +0,0 @@
1
- import "reflect-metadata";
2
- import { DataSourceOptions } from "typeorm";
3
- export declare class AvleonTestUtility {
4
- private static testDataSource;
5
- private static testContainer;
6
- /**
7
- * Initialize test environment
8
- */
9
- static init(options?: {
10
- dataSourceOptions?: DataSourceOptions;
11
- resetContainer?: boolean;
12
- }): Promise<typeof AvleonTestUtility>;
13
- /**
14
- * Mock a dependency for testing
15
- * @param token Dependency token
16
- * @param mockImplementation Mock implementation
17
- */
18
- static mockDependency<T>(token: any, mockImplementation: T): T;
19
- /**
20
- * Create an isolated test instance of a class
21
- * @param ClassType Class to instantiate
22
- * @param overrides Optional property overrides
23
- */
24
- static createTestInstance<T>(ClassType: new (...args: any[]) => T, overrides?: Partial<T>): T;
25
- /**
26
- * Cleanup test environment
27
- */
28
- static cleanup(): Promise<void>;
29
- }
30
- export declare class AvleonTestBuilder {
31
- private controllers;
32
- private testOptions;
33
- private mocks;
34
- /**
35
- * Add controllers for testing
36
- * @param controllers Controllers to add
37
- */
38
- addControllers(...controllers: any[]): this;
39
- /**
40
- * Mock a dependency
41
- * @param token Dependency token
42
- * @param mockImplementation Mock implementation
43
- */
44
- mockDependency(token: any, mockImplementation: any): this;
45
- /**
46
- * Set test options
47
- * @param options Test configuration options
48
- */
49
- setOptions(options: any): this;
50
- /**
51
- * Build test application
52
- */
53
- build(): Promise<import("./icore").TestApplication>;
54
- }
55
- export declare function UnitTest(): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
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
- // }
File without changes