@avleon/core 0.0.39 → 0.0.42-rc0.1

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 (52) hide show
  1. package/README.md +113 -28
  2. package/dist/cache.test.d.ts +1 -0
  3. package/dist/cache.test.js +36 -0
  4. package/dist/controller.d.ts +2 -0
  5. package/dist/controller.js +13 -0
  6. package/dist/controller.test.d.ts +1 -0
  7. package/dist/controller.test.js +111 -0
  8. package/dist/environment-variables.test.d.ts +1 -0
  9. package/dist/environment-variables.test.js +70 -0
  10. package/dist/exceptions/http-exceptions.d.ts +1 -0
  11. package/dist/exceptions/http-exceptions.js +3 -1
  12. package/dist/file-storage.d.ts +44 -9
  13. package/dist/file-storage.js +209 -59
  14. package/dist/file-storage.test.d.ts +1 -0
  15. package/dist/file-storage.test.js +104 -0
  16. package/dist/helpers.test.d.ts +1 -0
  17. package/dist/helpers.test.js +95 -0
  18. package/dist/icore.d.ts +7 -5
  19. package/dist/icore.js +191 -69
  20. package/dist/icore.test.d.ts +1 -0
  21. package/dist/icore.test.js +14 -0
  22. package/dist/index.d.ts +24 -0
  23. package/dist/index.js +8 -1
  24. package/dist/kenx-provider.test.d.ts +1 -0
  25. package/dist/kenx-provider.test.js +36 -0
  26. package/dist/logger.test.d.ts +1 -0
  27. package/dist/logger.test.js +42 -0
  28. package/dist/middleware.d.ts +3 -0
  29. package/dist/middleware.js +7 -0
  30. package/dist/middleware.test.d.ts +1 -0
  31. package/dist/middleware.test.js +121 -0
  32. package/dist/multipart.test.d.ts +1 -0
  33. package/dist/multipart.test.js +87 -0
  34. package/dist/openapi.test.d.ts +1 -0
  35. package/dist/openapi.test.js +111 -0
  36. package/dist/params.test.d.ts +1 -0
  37. package/dist/params.test.js +83 -0
  38. package/dist/queue.test.d.ts +1 -0
  39. package/dist/queue.test.js +79 -0
  40. package/dist/route-methods.test.d.ts +1 -0
  41. package/dist/route-methods.test.js +129 -0
  42. package/dist/swagger-schema.d.ts +42 -0
  43. package/dist/swagger-schema.js +331 -58
  44. package/dist/swagger-schema.test.d.ts +1 -0
  45. package/dist/swagger-schema.test.js +105 -0
  46. package/dist/validation.d.ts +7 -0
  47. package/dist/validation.js +2 -0
  48. package/dist/validation.test.d.ts +1 -0
  49. package/dist/validation.test.js +61 -0
  50. package/dist/websocket.test.d.ts +1 -0
  51. package/dist/websocket.test.js +27 -0
  52. package/package.json +11 -9
@@ -0,0 +1,121 @@
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
+ require("reflect-metadata");
13
+ const middleware_1 = require("./middleware");
14
+ describe("AvleonMiddleware", () => {
15
+ class TestMiddleware extends middleware_1.AvleonMiddleware {
16
+ async invoke(req, res) {
17
+ return req;
18
+ }
19
+ }
20
+ it("should allow AppMiddleware decorator on valid class", () => {
21
+ expect(() => (0, middleware_1.AppMiddleware)(TestMiddleware)).not.toThrow();
22
+ });
23
+ it("should throw error if AppMiddleware is used on class without invoke", () => {
24
+ class InvalidMiddleware {
25
+ }
26
+ expect(() => (0, middleware_1.AppMiddleware)(InvalidMiddleware)).toThrow(/must implement an "invoke" method/);
27
+ });
28
+ });
29
+ describe("UseMiddleware", () => {
30
+ class MW1 extends middleware_1.AvleonMiddleware {
31
+ async invoke(req) {
32
+ return req;
33
+ }
34
+ }
35
+ class MW2 extends middleware_1.AvleonMiddleware {
36
+ async invoke(req) {
37
+ return req;
38
+ }
39
+ }
40
+ it("should attach middleware to class", () => {
41
+ let TestController = class TestController {
42
+ };
43
+ TestController = __decorate([
44
+ (0, middleware_1.UseMiddleware)([MW1, MW2])
45
+ ], TestController);
46
+ const middlewares = Reflect.getMetadata("controller:middleware", TestController);
47
+ expect(middlewares).toHaveLength(2);
48
+ expect(middlewares[0]).toBeInstanceOf(MW1);
49
+ expect(middlewares[1]).toBeInstanceOf(MW2);
50
+ });
51
+ it("should attach middleware to method", () => {
52
+ class TestController {
53
+ testMethod() { }
54
+ }
55
+ __decorate([
56
+ (0, middleware_1.UseMiddleware)(MW1),
57
+ __metadata("design:type", Function),
58
+ __metadata("design:paramtypes", []),
59
+ __metadata("design:returntype", void 0)
60
+ ], TestController.prototype, "testMethod", null);
61
+ const middlewares = Reflect.getMetadata("route:middleware", TestController.prototype, "testMethod");
62
+ expect(middlewares).toHaveLength(1);
63
+ expect(middlewares[0]).toBeInstanceOf(MW1);
64
+ });
65
+ });
66
+ // describe("Authorized decorator", () => {
67
+ // it("should define metadata on class", () => {
68
+ // @Authorized({ roles: ["admin"] })
69
+ // class TestClass {}
70
+ // const meta = Reflect.getMetadata("AUTHORIZATION_META_KEY", TestClass);
71
+ // expect(meta).toEqual({ authorize: true, options: { roles: ["admin"] } });
72
+ // });
73
+ // it("should define metadata on method", () => {
74
+ // class TestClass {
75
+ // @Authorized({ roles: ["user"] })
76
+ // testMethod() {}
77
+ // }
78
+ // const meta = Reflect.getMetadata(
79
+ // "AUTHORIZATION_META_KEY",
80
+ // TestClass.constructor,
81
+ // "testMethod",
82
+ // );
83
+ // expect(meta).toEqual({ authorize: true, options: { roles: ["user"] } });
84
+ // });
85
+ describe("CanAuthorize and AppAuthorization", () => {
86
+ class ValidAuthorize {
87
+ authorize(req, options) {
88
+ return req;
89
+ }
90
+ }
91
+ it("should not throw for valid CanAuthorize", () => {
92
+ expect(() => (0, middleware_1.CanAuthorize)(ValidAuthorize)).not.toThrow();
93
+ });
94
+ it("should throw for invalid CanAuthorize", () => {
95
+ class InvalidAuthorize {
96
+ }
97
+ expect(() => (0, middleware_1.CanAuthorize)(InvalidAuthorize)).toThrow(/must implement an "authorize" method/);
98
+ });
99
+ it("should not throw for valid AppAuthorization", () => {
100
+ expect(() => (0, middleware_1.AppAuthorization)(ValidAuthorize)).not.toThrow();
101
+ });
102
+ it("should throw for invalid AppAuthorization", () => {
103
+ class InvalidAuthorize {
104
+ }
105
+ expect(() => (0, middleware_1.AppAuthorization)(InvalidAuthorize)).toThrow(/must implement an "authorize" method/);
106
+ });
107
+ });
108
+ describe("AuthorizeMiddleware", () => {
109
+ class TestAuthorizeMiddleware extends middleware_1.AuthorizeMiddleware {
110
+ authorize(roles) {
111
+ return (req) => req;
112
+ }
113
+ }
114
+ it("should implement authorize method", () => {
115
+ const mw = new TestAuthorizeMiddleware();
116
+ const handler = mw.authorize(["admin"]);
117
+ expect(typeof handler).toBe("function");
118
+ const req = {};
119
+ expect(handler(req)).toBe(req);
120
+ });
121
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,87 @@
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 multipart_1 = require("./multipart");
7
+ const exceptions_1 = require("./exceptions");
8
+ const fs_1 = __importDefault(require("fs"));
9
+ jest.mock("fs");
10
+ jest.mock("stream/promises", () => ({
11
+ pipeline: jest.fn(() => Promise.resolve()),
12
+ }));
13
+ const mockFileStream = {};
14
+ const mockReq = (fileData) => ({
15
+ params: {},
16
+ query: {},
17
+ body: {},
18
+ headers: {},
19
+ method: "POST",
20
+ url: "/upload",
21
+ file: jest.fn().mockResolvedValue(fileData),
22
+ // Add any other required IRequest properties as needed for type compatibility
23
+ });
24
+ describe("UploadFileFromRequest", () => {
25
+ beforeEach(() => {
26
+ jest.clearAllMocks();
27
+ fs_1.default.existsSync.mockReturnValue(false);
28
+ });
29
+ // it("should save file to default location", async () => {
30
+ // const fileData = {
31
+ // file: mockFileStream,
32
+ // filename: "test.txt",
33
+ // };
34
+ // const req = mockReq(fileData);
35
+ // const result = await UploadFileFromRequest(req);
36
+ // expect(fs.existsSync).toHaveBeenCalled();
37
+ // expect(pipeline).toHaveBeenCalledWith(mockFileStream, expect.anything());
38
+ // expect(result).toMatchObject({
39
+ // ...fileData,
40
+ // filename: "test.txt",
41
+ // });
42
+ // });
43
+ // it("should save file to custom location with saveAs", async () => {
44
+ // const fileData = {
45
+ // file: mockFileStream,
46
+ // filename: "original.txt",
47
+ // };
48
+ // const req = mockReq(fileData);
49
+ // const options = { saveAs: "custom.txt" };
50
+ // const result = await UploadFileFromRequest(req, options);
51
+ // expect(fs.existsSync).toHaveBeenCalled();
52
+ // expect(pipeline).toHaveBeenCalledWith(mockFileStream, expect.anything());
53
+ // expect(result).toMatchObject({
54
+ // ...fileData,
55
+ // filename: "custom.txt",
56
+ // });
57
+ // });
58
+ // it("should save file to custom dest", async () => {
59
+ // const fileData = {
60
+ // file: mockFileStream,
61
+ // filename: "file.txt",
62
+ // };
63
+ // const req = mockReq(fileData);
64
+ // const options:any = { dest: "/tmp" };
65
+ // const result = await UploadFileFromRequest(req, options);
66
+ // expect(fs.existsSync).toHaveBeenCalled();
67
+ // expect(pipeline).toHaveBeenCalledWith(mockFileStream, expect.anything());
68
+ // expect(result).toMatchObject({
69
+ // ...fileData,
70
+ // filename: "file.txt",
71
+ // });
72
+ // });
73
+ it("should throw error if file already exists", async () => {
74
+ fs_1.default.existsSync.mockReturnValue(true);
75
+ const fileData = {
76
+ file: mockFileStream,
77
+ filename: "exists.txt",
78
+ };
79
+ const req = mockReq(fileData);
80
+ await expect((0, multipart_1.UploadFileFromRequest)(req)).rejects.toThrow(exceptions_1.InternalErrorException);
81
+ });
82
+ it("should return undefined if no file is present", async () => {
83
+ const req = mockReq(null);
84
+ const result = await (0, multipart_1.UploadFileFromRequest)(req);
85
+ expect(result).toBeUndefined();
86
+ });
87
+ });
@@ -0,0 +1 @@
1
+ import 'reflect-metadata';
@@ -0,0 +1,111 @@
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
+ require("reflect-metadata");
13
+ const openapi_1 = require("./openapi");
14
+ describe('OpenApi Decorator', () => {
15
+ it('should define metadata on class', () => {
16
+ let TestController = class TestController {
17
+ };
18
+ TestController = __decorate([
19
+ (0, openapi_1.OpenApi)({ description: 'Test Controller' })
20
+ ], TestController);
21
+ const metadata = Reflect.getMetadata('controller:openapi', TestController);
22
+ expect(metadata).toEqual({ description: 'Test Controller' });
23
+ });
24
+ it('should define metadata on method', () => {
25
+ class TestController {
26
+ testMethod() { }
27
+ }
28
+ __decorate([
29
+ (0, openapi_1.OpenApi)({ description: 'Test Route' }),
30
+ __metadata("design:type", Function),
31
+ __metadata("design:paramtypes", []),
32
+ __metadata("design:returntype", void 0)
33
+ ], TestController.prototype, "testMethod", null);
34
+ const metadata = Reflect.getMetadata('route:openapi', TestController.prototype, 'testMethod');
35
+ expect(metadata).toEqual({ description: 'Test Route' });
36
+ });
37
+ it('should define metadata on property', () => {
38
+ class TestController {
39
+ constructor() {
40
+ this.testProperty = '';
41
+ }
42
+ }
43
+ __decorate([
44
+ (0, openapi_1.OpenApi)({ description: 'Test Property' }),
45
+ __metadata("design:type", String)
46
+ ], TestController.prototype, "testProperty", void 0);
47
+ const metadata = Reflect.getMetadata('property:openapi', TestController.prototype, 'testProperty');
48
+ expect(metadata).toEqual({ description: 'Test Property' });
49
+ });
50
+ });
51
+ describe('Type Definitions', () => {
52
+ it('InfoObject should allow optional description', () => {
53
+ const info = {
54
+ title: 'API',
55
+ version: '1.0.0',
56
+ description: 'API Description',
57
+ };
58
+ expect(info.description).toBe('API Description');
59
+ });
60
+ it('ContactObject should allow optional fields', () => {
61
+ const contact = {
62
+ name: 'John Doe',
63
+ email: 'john@example.com',
64
+ };
65
+ expect(contact.name).toBe('John Doe');
66
+ expect(contact.email).toBe('john@example.com');
67
+ });
68
+ it('LicenseObject should require name', () => {
69
+ const license = {
70
+ name: 'MIT',
71
+ };
72
+ expect(license.name).toBe('MIT');
73
+ });
74
+ it('ServerObject should allow variables', () => {
75
+ var _a;
76
+ const server = {
77
+ url: 'https://api.example.com',
78
+ variables: {
79
+ version: {
80
+ default: 'v1',
81
+ enum: ['v1', 'v2'],
82
+ },
83
+ },
84
+ };
85
+ expect((_a = server.variables) === null || _a === void 0 ? void 0 : _a.version.default).toBe('v1');
86
+ });
87
+ it('SchemaObject should allow array and non-array types', () => {
88
+ const arraySchema = {
89
+ type: 'array',
90
+ items: { type: 'string' },
91
+ };
92
+ expect(arraySchema.type).toBe('array');
93
+ const nonArraySchema = {
94
+ type: 'string',
95
+ };
96
+ expect(nonArraySchema.type).toBe('string');
97
+ });
98
+ it('ComponentsObject should allow schemas and responses', () => {
99
+ var _a, _b;
100
+ const components = {
101
+ schemas: {
102
+ User: { type: 'object' },
103
+ },
104
+ responses: {
105
+ NotFound: { description: 'Not found' },
106
+ },
107
+ };
108
+ expect((_a = components.schemas) === null || _a === void 0 ? void 0 : _a.User).toBeDefined();
109
+ expect(((_b = components.responses) === null || _b === void 0 ? void 0 : _b.NotFound).description).toBe('Not found');
110
+ });
111
+ });
@@ -0,0 +1 @@
1
+ import "reflect-metadata";
@@ -0,0 +1,83 @@
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 __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ require("reflect-metadata");
16
+ const params_1 = require("./params");
17
+ const container_1 = require("./container");
18
+ describe("Parameter Decorators", () => {
19
+ class DummyValidator {
20
+ }
21
+ class TestController {
22
+ testMethod(id, search, body, token, user) { }
23
+ }
24
+ __decorate([
25
+ __param(0, (0, params_1.Param)("id")),
26
+ __param(1, (0, params_1.Query)("search")),
27
+ __param(2, (0, params_1.Body)()),
28
+ __param(3, (0, params_1.Header)("x-token")),
29
+ __param(4, (0, params_1.AuthUser)()),
30
+ __metadata("design:type", Function),
31
+ __metadata("design:paramtypes", [String, String, DummyValidator, String, Object]),
32
+ __metadata("design:returntype", void 0)
33
+ ], TestController.prototype, "testMethod", null);
34
+ it("should define metadata for Param decorator", () => {
35
+ const meta = Reflect.getMetadata(container_1.PARAM_META_KEY, TestController.prototype, "testMethod");
36
+ expect(meta).toBeDefined();
37
+ expect(meta[0].key).toBe("id");
38
+ expect(meta[0].type).toBe("route:param");
39
+ });
40
+ it("should define metadata for Query decorator", () => {
41
+ const meta = Reflect.getMetadata(container_1.QUERY_META_KEY, TestController.prototype, "testMethod");
42
+ expect(meta).toBeDefined();
43
+ expect(meta[1].key).toBe("search");
44
+ expect(meta[1].type).toBe("route:query");
45
+ });
46
+ it("should define metadata for Body decorator", () => {
47
+ const meta = Reflect.getMetadata(container_1.REQUEST_BODY_META_KEY, TestController.prototype, "testMethod");
48
+ expect(meta).toBeDefined();
49
+ expect(meta[2].key).toBe("all");
50
+ expect(meta[2].type).toBe("route:body");
51
+ });
52
+ it("should define metadata for Header decorator", () => {
53
+ const meta = Reflect.getMetadata(container_1.REQUEST_HEADER_META_KEY, TestController.prototype, "testMethod");
54
+ expect(meta).toBeDefined();
55
+ expect(meta[3].key).toBe("x-token");
56
+ expect(meta[3].type).toBe("route:header");
57
+ });
58
+ it("should define metadata for AuthUser decorator", () => {
59
+ const meta = Reflect.getMetadata(container_1.REQUEST_USER_META_KEY, TestController.prototype, "testMethod");
60
+ expect(meta).toBeDefined();
61
+ expect(meta[4].key).toBe("all");
62
+ expect(meta[4].type).toBe("route:user");
63
+ });
64
+ it("should set required and validate options to true by default", () => {
65
+ const meta = Reflect.getMetadata(container_1.PARAM_META_KEY, TestController.prototype, "testMethod");
66
+ expect(meta[0].required).toBe(true);
67
+ expect(meta[0].validate).toBe(true);
68
+ });
69
+ it("should allow overriding required and validate options", () => {
70
+ class AnotherController {
71
+ test(id) { }
72
+ }
73
+ __decorate([
74
+ __param(0, (0, params_1.Param)("id", { required: false, validate: false })),
75
+ __metadata("design:type", Function),
76
+ __metadata("design:paramtypes", [String]),
77
+ __metadata("design:returntype", void 0)
78
+ ], AnotherController.prototype, "test", null);
79
+ const meta = Reflect.getMetadata(container_1.PARAM_META_KEY, AnotherController.prototype, "test");
80
+ expect(meta[0].required).toBe(false);
81
+ expect(meta[0].validate).toBe(false);
82
+ });
83
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,79 @@
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;
40
+ let handler;
41
+ beforeEach(() => {
42
+ jest.clearAllMocks();
43
+ adapter = new queue_1.FileQueueAdapter("testqueue");
44
+ queueManager = queue_1.QueueManager.getInstance(adapter);
45
+ handler = jest.fn().mockResolvedValue(undefined);
46
+ fs_1.promises.readFile.mockResolvedValue("[]");
47
+ fs_1.promises.writeFile.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_1.promises.readFile).toHaveBeenCalled();
53
+ expect(fs_1.promises.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 = queue_1.QueueManager.getInstance(adapter);
77
+ expect(another).toBe(queueManager);
78
+ });
79
+ });
@@ -0,0 +1 @@
1
+ import "reflect-metadata";
@@ -0,0 +1,129 @@
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
+ require("reflect-metadata");
13
+ const route_methods_1 = require("./route-methods");
14
+ describe("Route Decorators", () => {
15
+ class TestController {
16
+ getMethod() { }
17
+ postMethod() { }
18
+ putMethod() { }
19
+ deleteMethod() { }
20
+ patchMethod() { }
21
+ optionsMethod() { }
22
+ allMethod() { }
23
+ customRouteMethod() { }
24
+ }
25
+ __decorate([
26
+ (0, route_methods_1.Get)("/get"),
27
+ __metadata("design:type", Function),
28
+ __metadata("design:paramtypes", []),
29
+ __metadata("design:returntype", void 0)
30
+ ], TestController.prototype, "getMethod", null);
31
+ __decorate([
32
+ (0, route_methods_1.Post)({ path: "/post", name: "customPost" }),
33
+ __metadata("design:type", Function),
34
+ __metadata("design:paramtypes", []),
35
+ __metadata("design:returntype", void 0)
36
+ ], TestController.prototype, "postMethod", null);
37
+ __decorate([
38
+ (0, route_methods_1.Put)("/put", { name: "putMethod" }),
39
+ __metadata("design:type", Function),
40
+ __metadata("design:paramtypes", []),
41
+ __metadata("design:returntype", void 0)
42
+ ], TestController.prototype, "putMethod", null);
43
+ __decorate([
44
+ (0, route_methods_1.Delete)(),
45
+ __metadata("design:type", Function),
46
+ __metadata("design:paramtypes", []),
47
+ __metadata("design:returntype", void 0)
48
+ ], TestController.prototype, "deleteMethod", null);
49
+ __decorate([
50
+ (0, route_methods_1.Patch)({ name: "patchMethod" }),
51
+ __metadata("design:type", Function),
52
+ __metadata("design:paramtypes", []),
53
+ __metadata("design:returntype", void 0)
54
+ ], TestController.prototype, "patchMethod", null);
55
+ __decorate([
56
+ (0, route_methods_1.Options)("/options"),
57
+ __metadata("design:type", Function),
58
+ __metadata("design:paramtypes", []),
59
+ __metadata("design:returntype", void 0)
60
+ ], TestController.prototype, "optionsMethod", null);
61
+ __decorate([
62
+ (0, route_methods_1.All)({ path: "/all" }),
63
+ __metadata("design:type", Function),
64
+ __metadata("design:paramtypes", []),
65
+ __metadata("design:returntype", void 0)
66
+ ], TestController.prototype, "allMethod", null);
67
+ __decorate([
68
+ (0, route_methods_1.Route)("GET", "/custom", { name: "customRoute" }),
69
+ __metadata("design:type", Function),
70
+ __metadata("design:paramtypes", []),
71
+ __metadata("design:returntype", void 0)
72
+ ], TestController.prototype, "customRouteMethod", null);
73
+ it("should define metadata for Get decorator", () => {
74
+ const meta = Reflect.getMetadata("route:method", TestController.prototype, "getMethod");
75
+ expect(meta).toBe("GET");
76
+ const path = Reflect.getMetadata("route:path", TestController.prototype, "getMethod");
77
+ expect(path).toBe("/get");
78
+ });
79
+ // it("should define metadata for Post decorator with options object", () => {
80
+ // const meta = Reflect.getMetadata("route:method", TestController.prototype, "postMethod");
81
+ // expect(meta).toBe("POST");
82
+ // const path = Reflect.getMetadata("route:path", TestController.prototype, "postMethod");
83
+ // expect(path).toBe("/post");
84
+ // const options = Reflect.getMetadata("route:options", TestController.prototype, "postMethod");
85
+ // expect(options).toMatchObject({ path: "/post", name: "customPost" });
86
+ // });
87
+ it("should define metadata for Put decorator with path and options", () => {
88
+ const meta = Reflect.getMetadata("route:method", TestController.prototype, "putMethod");
89
+ expect(meta).toBe("PUT");
90
+ const path = Reflect.getMetadata("route:path", TestController.prototype, "putMethod");
91
+ expect(path).toBe("/put");
92
+ const options = Reflect.getMetadata("route:options", TestController.prototype, "putMethod");
93
+ expect(options).toMatchObject({ name: "putMethod" });
94
+ });
95
+ it("should define metadata for Delete decorator with default path", () => {
96
+ const meta = Reflect.getMetadata("route:method", TestController.prototype, "deleteMethod");
97
+ expect(meta).toBe("DELETE");
98
+ const path = Reflect.getMetadata("route:path", TestController.prototype, "deleteMethod");
99
+ expect(path).toBe("/");
100
+ });
101
+ it("should define metadata for Patch decorator with options object", () => {
102
+ const meta = Reflect.getMetadata("route:method", TestController.prototype, "patchMethod");
103
+ expect(meta).toBe("PATCH");
104
+ const path = Reflect.getMetadata("route:path", TestController.prototype, "patchMethod");
105
+ expect(path).toBe("patchMethod");
106
+ const options = Reflect.getMetadata("route:options", TestController.prototype, "patchMethod");
107
+ expect(options).toMatchObject({ name: "patchMethod" });
108
+ });
109
+ it("should define metadata for Options decorator with path", () => {
110
+ const meta = Reflect.getMetadata("route:method", TestController.prototype, "optionsMethod");
111
+ expect(meta).toBe("OPTIONS");
112
+ const path = Reflect.getMetadata("route:path", TestController.prototype, "optionsMethod");
113
+ expect(path).toBe("/options");
114
+ });
115
+ it("should define metadata for All decorator with options object", () => {
116
+ const meta = Reflect.getMetadata("route:method", TestController.prototype, "allMethod");
117
+ expect(meta).toBe("ALL");
118
+ const path = Reflect.getMetadata("route:path", TestController.prototype, "allMethod");
119
+ expect(path).toBe("/all");
120
+ });
121
+ it("should define metadata for generic Route decorator", () => {
122
+ const meta = Reflect.getMetadata("route:method", TestController.prototype, "customRouteMethod");
123
+ expect(meta).toBe("GET");
124
+ const path = Reflect.getMetadata("route:path", TestController.prototype, "customRouteMethod");
125
+ expect(path).toBe("/custom");
126
+ const options = Reflect.getMetadata("route:options", TestController.prototype, "customRouteMethod");
127
+ expect(options).toMatchObject({ name: "customRoute" });
128
+ });
129
+ });
@@ -1 +1,43 @@
1
+ export declare function OpenApiProperty(options?: {
2
+ type?: any;
3
+ description?: string;
4
+ deprecated?: boolean;
5
+ example?: any;
6
+ enum?: any[];
7
+ format?: string;
8
+ default?: any;
9
+ minimum?: number;
10
+ maximum?: number;
11
+ minLength?: number;
12
+ maxLength?: number;
13
+ pattern?: string;
14
+ oneOf?: any[];
15
+ allOf?: any[];
16
+ anyOf?: any[];
17
+ exclude?: boolean;
18
+ isArray?: boolean;
19
+ items?: Record<string, any>;
20
+ }): (target: any, propertyKey: string) => void;
21
+ export declare function CreateSwaggerObjectSchema(classType: any): any;
1
22
  export declare function generateSwaggerSchema(classType: any): any;
23
+ export declare function OpenApiResponse(code: number | undefined, model: any, description?: string): {
24
+ description: string;
25
+ content: {
26
+ "application/json": {
27
+ schema: {
28
+ type: string;
29
+ properties: {
30
+ code: {
31
+ type: string;
32
+ example: number;
33
+ };
34
+ status: {
35
+ type: string;
36
+ example: string;
37
+ };
38
+ data: any;
39
+ };
40
+ };
41
+ };
42
+ };
43
+ };