@avleon/core 0.0.44 → 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.
- package/License +21 -21
- package/README.md +667 -681
- package/dist/application.test.js +15 -0
- package/dist/controller.test.js +0 -14
- package/dist/core/application.d.ts +74 -0
- package/dist/core/application.js +424 -0
- package/dist/core/router.d.ts +44 -0
- package/dist/core/router.js +520 -0
- package/dist/core/testing.d.ts +21 -0
- package/dist/core/testing.js +104 -0
- package/dist/core/types.d.ts +67 -0
- package/dist/core/types.js +2 -0
- package/dist/event-dispatcher.d.ts +0 -1
- package/dist/event-dispatcher.js +4 -7
- package/dist/file-storage.test.js +15 -2
- package/dist/helpers.d.ts +9 -42
- package/dist/helpers.js +19 -411
- package/dist/index.d.ts +17 -15
- package/dist/index.js +18 -22
- package/dist/interfaces/avleon-application.d.ts +74 -26
- package/dist/interfaces/avleon-application.js +1 -0
- package/dist/middleware.d.ts +11 -4
- package/dist/middleware.js +9 -0
- package/dist/multipart.d.ts +2 -2
- package/dist/openapi.d.ts +70 -3
- package/dist/openapi.js +32 -0
- package/dist/params.js +1 -6
- package/dist/params.test.js +8 -8
- package/dist/queue.d.ts +27 -36
- package/dist/queue.js +67 -99
- package/dist/route-methods.js +16 -5
- package/dist/swagger-schema.d.ts +11 -17
- package/dist/swagger-schema.js +84 -82
- package/dist/swagger-schema.test.js +32 -12
- package/dist/utils/common-utils.d.ts +17 -0
- package/dist/utils/common-utils.js +108 -0
- package/dist/utils/di-utils.d.ts +1 -0
- package/dist/utils/di-utils.js +22 -0
- package/dist/utils/hash.d.ts +0 -2
- package/dist/utils/hash.js +1 -5
- package/dist/utils/object-utils.d.ts +11 -0
- package/dist/utils/object-utils.js +198 -0
- package/dist/utils/validation-utils.d.ts +13 -0
- package/dist/utils/validation-utils.js +119 -0
- package/dist/validation.js +1 -4
- package/dist/websocket.d.ts +3 -0
- package/dist/websocket.js +2 -1
- package/package.json +53 -39
- package/dist/application.d.ts +0 -47
- package/dist/application.js +0 -50
- package/dist/icore.d.ts +0 -226
- package/dist/icore.js +0 -968
- package/dist/icore.test.js +0 -14
- package/dist/queue.test.d.ts +0 -1
- package/dist/queue.test.js +0 -79
- package/dist/testing.d.ts +0 -55
- package/dist/testing.js +0 -196
- /package/dist/{icore.test.d.ts → application.test.d.ts} +0 -0
package/dist/icore.test.js
DELETED
|
@@ -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/queue.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/queue.test.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const queue_1 = require("./queue");
|
|
4
|
-
const fs_1 = require("fs");
|
|
5
|
-
const path_1 = require("path");
|
|
6
|
-
jest.mock("fs", () => ({
|
|
7
|
-
promises: {
|
|
8
|
-
readFile: jest.fn(),
|
|
9
|
-
writeFile: jest.fn(),
|
|
10
|
-
},
|
|
11
|
-
}));
|
|
12
|
-
const mockQueueFile = (0, path_1.join)(__dirname, "testqueue.json");
|
|
13
|
-
describe("FileQueueAdapter", () => {
|
|
14
|
-
const jobs = [{ id: "1", data: "foo" }, { id: "2", data: "bar" }];
|
|
15
|
-
beforeEach(() => {
|
|
16
|
-
jest.clearAllMocks();
|
|
17
|
-
});
|
|
18
|
-
it("should load jobs from file", async () => {
|
|
19
|
-
fs_1.promises.readFile.mockResolvedValue(JSON.stringify(jobs));
|
|
20
|
-
const adapter = new queue_1.FileQueueAdapter("testqueue");
|
|
21
|
-
const loaded = await adapter.loadJobs();
|
|
22
|
-
expect(loaded).toEqual(jobs);
|
|
23
|
-
expect(fs_1.promises.readFile).toHaveBeenCalledWith(mockQueueFile, "utf-8");
|
|
24
|
-
});
|
|
25
|
-
it("should return empty array if file does not exist", async () => {
|
|
26
|
-
fs_1.promises.readFile.mockRejectedValue(new Error("not found"));
|
|
27
|
-
const adapter = new queue_1.FileQueueAdapter("testqueue");
|
|
28
|
-
const loaded = await adapter.loadJobs();
|
|
29
|
-
expect(loaded).toEqual([]);
|
|
30
|
-
});
|
|
31
|
-
it("should save jobs to file", async () => {
|
|
32
|
-
const adapter = new queue_1.FileQueueAdapter("testqueue");
|
|
33
|
-
await adapter.saveJobs(jobs);
|
|
34
|
-
expect(fs_1.promises.writeFile).toHaveBeenCalledWith(mockQueueFile, JSON.stringify(jobs, null, 2), "utf-8");
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
describe("QueueManager and SimpleQueue", () => {
|
|
38
|
-
let adapter;
|
|
39
|
-
// let queueManager: QueueManager;
|
|
40
|
-
let handler;
|
|
41
|
-
// beforeEach(() => {
|
|
42
|
-
// jest.clearAllMocks();
|
|
43
|
-
// adapter = new FileQueueAdapter("testqueue");
|
|
44
|
-
// queueManager = QueueManager.getInstance(adapter);
|
|
45
|
-
// handler = jest.fn().mockResolvedValue(undefined);
|
|
46
|
-
// (fs.readFile as jest.Mock).mockResolvedValue("[]");
|
|
47
|
-
// (fs.writeFile as jest.Mock).mockResolvedValue(undefined);
|
|
48
|
-
// });
|
|
49
|
-
// it("should create a queue and add a job", async () => {
|
|
50
|
-
// const queue = queueManager.createQueue(handler);
|
|
51
|
-
// await queue.addJob({ foo: "bar" });
|
|
52
|
-
// expect(fs.readFile).toHaveBeenCalled();
|
|
53
|
-
// expect(fs.writeFile).toHaveBeenCalled();
|
|
54
|
-
// });
|
|
55
|
-
// it("should process jobs using handler", async () => {
|
|
56
|
-
// (fs.readFile as jest.Mock)
|
|
57
|
-
// .mockResolvedValueOnce("[]")
|
|
58
|
-
// .mockResolvedValueOnce(JSON.stringify([{ id: "1", data: "baz" }]))
|
|
59
|
-
// .mockResolvedValueOnce("[]");
|
|
60
|
-
// const queue = queueManager.createQueue(handler);
|
|
61
|
-
// await queue.addJob("baz");
|
|
62
|
-
// expect(handler).toHaveBeenCalled();
|
|
63
|
-
// });
|
|
64
|
-
// it("should requeue job if handler throws", async () => {
|
|
65
|
-
// handler.mockRejectedValueOnce(new Error("fail"));
|
|
66
|
-
// (fs.readFile as jest.Mock)
|
|
67
|
-
// .mockResolvedValueOnce("[]")
|
|
68
|
-
// .mockResolvedValueOnce(JSON.stringify([{ id: "1", data: "baz" }]))
|
|
69
|
-
// .mockResolvedValueOnce(JSON.stringify([{ id: "1", data: "baz" }]));
|
|
70
|
-
// const queue = queueManager.createQueue(handler);
|
|
71
|
-
// await queue.addJob("baz");
|
|
72
|
-
// expect(handler).toHaveBeenCalled();
|
|
73
|
-
// expect(fs.writeFile).toHaveBeenCalledTimes(2);
|
|
74
|
-
// });
|
|
75
|
-
// it("QueueManager should be singleton", () => {
|
|
76
|
-
// const another = QueueManager.getInstance(adapter);
|
|
77
|
-
// expect(another).toBe(queueManager);
|
|
78
|
-
// });
|
|
79
|
-
});
|
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
|