@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.
- package/README.md +355 -369
- package/dist/chunk-9hOWP6kD.cjs +64 -0
- package/dist/chunk-DORXReHP.js +37 -0
- package/dist/index-BxIMWhgy.d.ts +1284 -0
- package/dist/index-DPn7qtzq.d.cts +1283 -0
- package/dist/index.cjs +3194 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +3022 -83
- package/dist/index.js.map +1 -0
- package/dist/lib-Bk8hUm06.cjs +7847 -0
- package/dist/lib-Bk8hUm06.cjs.map +1 -0
- package/dist/lib-CvDxBMkR.js +7843 -0
- package/dist/lib-CvDxBMkR.js.map +1 -0
- package/package.json +67 -116
- package/dist/application.d.ts +0 -47
- package/dist/application.js +0 -50
- package/dist/authentication.d.ts +0 -13
- package/dist/authentication.js +0 -16
- package/dist/cache.d.ts +0 -12
- package/dist/cache.js +0 -78
- package/dist/cache.test.d.ts +0 -1
- package/dist/cache.test.js +0 -36
- package/dist/collection.d.ts +0 -43
- package/dist/collection.js +0 -231
- package/dist/collection.test.d.ts +0 -1
- package/dist/collection.test.js +0 -59
- package/dist/config.d.ts +0 -18
- package/dist/config.js +0 -58
- package/dist/config.test.d.ts +0 -1
- package/dist/config.test.js +0 -40
- package/dist/constants.d.ts +0 -1
- package/dist/constants.js +0 -4
- package/dist/container.d.ts +0 -30
- package/dist/container.js +0 -55
- package/dist/controller.d.ts +0 -50
- package/dist/controller.js +0 -71
- package/dist/controller.test.d.ts +0 -1
- package/dist/controller.test.js +0 -111
- package/dist/decorators.d.ts +0 -15
- package/dist/decorators.js +0 -41
- package/dist/environment-variables.d.ts +0 -49
- package/dist/environment-variables.js +0 -130
- package/dist/environment-variables.test.d.ts +0 -1
- package/dist/environment-variables.test.js +0 -70
- package/dist/event-dispatcher.d.ts +0 -23
- package/dist/event-dispatcher.js +0 -100
- package/dist/event-subscriber.d.ts +0 -14
- package/dist/event-subscriber.js +0 -87
- package/dist/exceptions/http-exceptions.d.ts +0 -50
- package/dist/exceptions/http-exceptions.js +0 -85
- package/dist/exceptions/index.d.ts +0 -1
- package/dist/exceptions/index.js +0 -17
- package/dist/exceptions/system-exception.d.ts +0 -22
- package/dist/exceptions/system-exception.js +0 -26
- package/dist/file-storage.d.ts +0 -69
- package/dist/file-storage.js +0 -323
- package/dist/file-storage.test.d.ts +0 -1
- package/dist/file-storage.test.js +0 -104
- package/dist/helpers.d.ts +0 -44
- package/dist/helpers.js +0 -419
- package/dist/helpers.test.d.ts +0 -1
- package/dist/helpers.test.js +0 -95
- package/dist/icore.d.ts +0 -226
- package/dist/icore.js +0 -968
- package/dist/icore.test.d.ts +0 -1
- package/dist/icore.test.js +0 -14
- package/dist/index.d.ts +0 -55
- package/dist/interfaces/avleon-application.d.ts +0 -27
- package/dist/interfaces/avleon-application.js +0 -1
- package/dist/kenx-provider.d.ts +0 -7
- package/dist/kenx-provider.js +0 -44
- package/dist/kenx-provider.test.d.ts +0 -1
- package/dist/kenx-provider.test.js +0 -36
- package/dist/logger.d.ts +0 -12
- package/dist/logger.js +0 -87
- package/dist/logger.test.d.ts +0 -1
- package/dist/logger.test.js +0 -42
- package/dist/map-types.d.ts +0 -17
- package/dist/map-types.js +0 -89
- package/dist/middleware.d.ts +0 -27
- package/dist/middleware.js +0 -64
- package/dist/middleware.test.d.ts +0 -1
- package/dist/middleware.test.js +0 -121
- package/dist/multipart.d.ts +0 -17
- package/dist/multipart.js +0 -70
- package/dist/multipart.test.d.ts +0 -1
- package/dist/multipart.test.js +0 -87
- package/dist/openapi.d.ts +0 -343
- package/dist/openapi.js +0 -27
- package/dist/openapi.test.d.ts +0 -1
- package/dist/openapi.test.js +0 -111
- package/dist/params.d.ts +0 -17
- package/dist/params.js +0 -64
- package/dist/params.test.d.ts +0 -1
- package/dist/params.test.js +0 -83
- package/dist/queue.d.ts +0 -29
- package/dist/queue.js +0 -84
- package/dist/response.d.ts +0 -16
- package/dist/response.js +0 -56
- package/dist/results.d.ts +0 -20
- package/dist/results.js +0 -32
- package/dist/route-methods.d.ts +0 -25
- package/dist/route-methods.js +0 -49
- package/dist/route-methods.test.d.ts +0 -1
- package/dist/route-methods.test.js +0 -129
- package/dist/swagger-schema.d.ts +0 -43
- package/dist/swagger-schema.js +0 -452
- package/dist/swagger-schema.test.d.ts +0 -1
- package/dist/swagger-schema.test.js +0 -105
- package/dist/testing.d.ts +0 -55
- package/dist/testing.js +0 -196
- package/dist/types/app-builder.interface.d.ts +0 -15
- package/dist/types/app-builder.interface.js +0 -8
- package/dist/types/application.interface.d.ts +0 -8
- package/dist/types/application.interface.js +0 -2
- package/dist/utils/hash.d.ts +0 -4
- package/dist/utils/hash.js +0 -15
- package/dist/utils/index.d.ts +0 -2
- package/dist/utils/index.js +0 -18
- package/dist/utils/optional-require.d.ts +0 -8
- package/dist/utils/optional-require.js +0 -70
- package/dist/validation.d.ts +0 -39
- package/dist/validation.js +0 -111
- package/dist/validation.test.d.ts +0 -1
- package/dist/validation.test.js +0 -61
- package/dist/validator-extend.d.ts +0 -7
- package/dist/validator-extend.js +0 -28
- package/dist/websocket.d.ts +0 -7
- package/dist/websocket.js +0 -20
- package/dist/websocket.test.d.ts +0 -1
- package/dist/websocket.test.js +0 -27
package/dist/params.js
DELETED
|
@@ -1,64 +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.AuthUser = exports.Header = exports.Body = exports.Query = exports.Param = void 0;
|
|
10
|
-
const container_1 = require("./container");
|
|
11
|
-
const helpers_1 = require("./helpers");
|
|
12
|
-
const swagger_schema_1 = require("./swagger-schema");
|
|
13
|
-
function createParamDecorator(type) {
|
|
14
|
-
return function (key, options = {}) {
|
|
15
|
-
return function (target, propertyKey, parameterIndex) {
|
|
16
|
-
var _a, _b, _c, _d;
|
|
17
|
-
let metaKey;
|
|
18
|
-
switch (type) {
|
|
19
|
-
case "route:param":
|
|
20
|
-
metaKey = container_1.PARAM_META_KEY;
|
|
21
|
-
break;
|
|
22
|
-
case "route:query":
|
|
23
|
-
metaKey = container_1.QUERY_META_KEY;
|
|
24
|
-
break;
|
|
25
|
-
case "route:body":
|
|
26
|
-
metaKey = container_1.REQUEST_BODY_META_KEY;
|
|
27
|
-
break;
|
|
28
|
-
case "route:user":
|
|
29
|
-
metaKey = container_1.REQUEST_USER_META_KEY;
|
|
30
|
-
break;
|
|
31
|
-
case "route:header":
|
|
32
|
-
metaKey = container_1.REQUEST_HEADER_META_KEY;
|
|
33
|
-
break;
|
|
34
|
-
default:
|
|
35
|
-
throw new Error(`Unknown param decorator type: ${String(type)}`);
|
|
36
|
-
}
|
|
37
|
-
const existingParams = Reflect.getMetadata(metaKey, target, propertyKey) || [];
|
|
38
|
-
// Get parameter names (fallback safe)
|
|
39
|
-
const functionSource = target[propertyKey].toString();
|
|
40
|
-
const paramNames = ((_b = (_a = functionSource.match(/\(([^)]*)\)/)) === null || _a === void 0 ? void 0 : _a[1]) === null || _b === void 0 ? void 0 : _b.split(",").map((n) => n.trim())) || [];
|
|
41
|
-
const parameterTypes = Reflect.getMetadata("design:paramtypes", target, propertyKey) || [];
|
|
42
|
-
const paramDataType = parameterTypes[parameterIndex];
|
|
43
|
-
existingParams.push({
|
|
44
|
-
index: parameterIndex,
|
|
45
|
-
key: typeof key === "string" ? key : "all",
|
|
46
|
-
name: paramNames[parameterIndex],
|
|
47
|
-
required: (_c = options.required) !== null && _c !== void 0 ? _c : true,
|
|
48
|
-
validate: (_d = options.validate) !== null && _d !== void 0 ? _d : true,
|
|
49
|
-
dataType: (0, helpers_1.getDataType)(paramDataType),
|
|
50
|
-
validatorClass: (0, helpers_1.isClassValidatorClass)(paramDataType),
|
|
51
|
-
schema: (0, helpers_1.isClassValidatorClass)(paramDataType)
|
|
52
|
-
? (0, swagger_schema_1.generateSwaggerSchema)(paramDataType)
|
|
53
|
-
: null,
|
|
54
|
-
type,
|
|
55
|
-
});
|
|
56
|
-
Reflect.defineMetadata(metaKey, existingParams, target, propertyKey);
|
|
57
|
-
};
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
exports.Param = createParamDecorator("route:param");
|
|
61
|
-
exports.Query = createParamDecorator("route:query");
|
|
62
|
-
exports.Body = createParamDecorator("route:body");
|
|
63
|
-
exports.Header = createParamDecorator("route:header");
|
|
64
|
-
exports.AuthUser = createParamDecorator("route:user");
|
package/dist/params.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "reflect-metadata";
|
package/dist/params.test.js
DELETED
|
@@ -1,83 +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 __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
|
-
});
|
package/dist/queue.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import Bull, { Queue as BullQueue, Job, JobOptions } from 'bull';
|
|
2
|
-
export interface QueueConfig {
|
|
3
|
-
name: string;
|
|
4
|
-
adapter?: any;
|
|
5
|
-
handler?: (job: Job) => Promise<any>;
|
|
6
|
-
options?: Bull.QueueOptions;
|
|
7
|
-
}
|
|
8
|
-
export declare class AvleonQueue<T = any> {
|
|
9
|
-
protected name?: string | undefined;
|
|
10
|
-
protected adapter?: any | undefined;
|
|
11
|
-
protected queue: BullQueue<T>;
|
|
12
|
-
protected handlerFn?: (job: Job<T>) => Promise<any>;
|
|
13
|
-
constructor(name?: string | undefined, adapter?: any | undefined, handler?: (job: Job<T>) => Promise<any>);
|
|
14
|
-
handler?(job: Job<T>): Promise<any> | any;
|
|
15
|
-
add(data: T, options?: JobOptions): Promise<Bull.Job<T>>;
|
|
16
|
-
delay(data: T, delayMs: number, options?: JobOptions): Promise<Bull.Job<T>>;
|
|
17
|
-
process(handler: (job: Job<T>) => Promise<any>): void;
|
|
18
|
-
processConcurrent(concurrency: number, handler: (job: Job<T>) => Promise<any>): void;
|
|
19
|
-
getQueue(): BullQueue<T>;
|
|
20
|
-
clean(grace: number, status?: 'completed' | 'wait' | 'active' | 'delayed' | 'failed'): Promise<Job[]>;
|
|
21
|
-
close(): Promise<void>;
|
|
22
|
-
pause(): Promise<void>;
|
|
23
|
-
resume(): Promise<void>;
|
|
24
|
-
getJob(jobId: string): Promise<Job<T> | null>;
|
|
25
|
-
getJobs(types: Array<'completed' | 'waiting' | 'active' | 'delayed' | 'failed' | 'paused'>, start?: number, end?: number): Promise<Job<T>[]>;
|
|
26
|
-
}
|
|
27
|
-
export declare function Queue(config: QueueConfig): <T extends {
|
|
28
|
-
new (...args: any[]): AvleonQueue;
|
|
29
|
-
}>(target: T) => T;
|
package/dist/queue.js
DELETED
|
@@ -1,84 +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.AvleonQueue = void 0;
|
|
7
|
-
exports.Queue = Queue;
|
|
8
|
-
const bull_1 = __importDefault(require("bull"));
|
|
9
|
-
const typedi_1 = require("typedi");
|
|
10
|
-
class AvleonQueue {
|
|
11
|
-
constructor(name, adapter, handler) {
|
|
12
|
-
this.name = name;
|
|
13
|
-
this.adapter = adapter;
|
|
14
|
-
// Initialize queue with adapter or default Redis connection
|
|
15
|
-
this.queue = new bull_1.default(name || 'default', adapter);
|
|
16
|
-
this.handlerFn = handler;
|
|
17
|
-
// Check if the instance has a handler method defined
|
|
18
|
-
// This allows subclasses to define handler as a method
|
|
19
|
-
if (typeof this.handler === 'function' && !this.handlerFn) {
|
|
20
|
-
this.handlerFn = (job) => this.handler(job);
|
|
21
|
-
}
|
|
22
|
-
// If handler is provided (from decorator or class method), set up processing
|
|
23
|
-
if (this.handlerFn) {
|
|
24
|
-
this.queue.process(this.handlerFn);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
// Add job to queue
|
|
28
|
-
add(data, options) {
|
|
29
|
-
return this.queue.add(data, options);
|
|
30
|
-
}
|
|
31
|
-
// Add job with delay
|
|
32
|
-
delay(data, delayMs, options) {
|
|
33
|
-
return this.queue.add(data, { ...options, delay: delayMs });
|
|
34
|
-
}
|
|
35
|
-
// Process jobs (can be called manually if not using handler)
|
|
36
|
-
process(handler) {
|
|
37
|
-
this.handlerFn = handler;
|
|
38
|
-
this.queue.process(handler);
|
|
39
|
-
}
|
|
40
|
-
// Process with concurrency
|
|
41
|
-
processConcurrent(concurrency, handler) {
|
|
42
|
-
this.handlerFn = handler;
|
|
43
|
-
this.queue.process(concurrency, handler);
|
|
44
|
-
}
|
|
45
|
-
// Get the underlying Bull queue
|
|
46
|
-
getQueue() {
|
|
47
|
-
return this.queue;
|
|
48
|
-
}
|
|
49
|
-
async clean(grace, status) {
|
|
50
|
-
return this.queue.clean(grace, status);
|
|
51
|
-
}
|
|
52
|
-
async close() {
|
|
53
|
-
await this.queue.close();
|
|
54
|
-
}
|
|
55
|
-
async pause() {
|
|
56
|
-
await this.queue.pause();
|
|
57
|
-
}
|
|
58
|
-
async resume() {
|
|
59
|
-
await this.queue.resume();
|
|
60
|
-
}
|
|
61
|
-
async getJob(jobId) {
|
|
62
|
-
return this.queue.getJob(jobId);
|
|
63
|
-
}
|
|
64
|
-
async getJobs(types, start, end) {
|
|
65
|
-
return this.queue.getJobs(types, start, end);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
exports.AvleonQueue = AvleonQueue;
|
|
69
|
-
function Queue(config) {
|
|
70
|
-
return function (target) {
|
|
71
|
-
// Create a new class that extends the target
|
|
72
|
-
const DecoratedClass = class extends target {
|
|
73
|
-
constructor(...args) {
|
|
74
|
-
super(config.name, config.adapter, config.handler);
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
Object.defineProperty(DecoratedClass, 'name', {
|
|
78
|
-
value: target.name,
|
|
79
|
-
writable: false
|
|
80
|
-
});
|
|
81
|
-
(0, typedi_1.Service)()(DecoratedClass);
|
|
82
|
-
return DecoratedClass;
|
|
83
|
-
};
|
|
84
|
-
}
|
package/dist/response.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @copyright 2024
|
|
3
|
-
* @author Tareq Hossain
|
|
4
|
-
* @email xtrinsic96@gmail.com
|
|
5
|
-
* @url https://github.com/xtareq
|
|
6
|
-
*/
|
|
7
|
-
import { ClassConstructor } from "class-transformer";
|
|
8
|
-
export interface IHttpResponse<T extends any> {
|
|
9
|
-
message: string;
|
|
10
|
-
data: T | null;
|
|
11
|
-
}
|
|
12
|
-
export declare class HttpResponse {
|
|
13
|
-
static Ok<T>(obj: any, s?: ClassConstructor<T>): IHttpResponse<T>;
|
|
14
|
-
static Created<T>(obj: any, s?: ClassConstructor<T>): IHttpResponse<T>;
|
|
15
|
-
static NoContent(): IHttpResponse<null>;
|
|
16
|
-
}
|
package/dist/response.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HttpResponse = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* @copyright 2024
|
|
6
|
-
* @author Tareq Hossain
|
|
7
|
-
* @email xtrinsic96@gmail.com
|
|
8
|
-
* @url https://github.com/xtareq
|
|
9
|
-
*/
|
|
10
|
-
const class_transformer_1 = require("class-transformer");
|
|
11
|
-
function isClassTransformerClass(target) {
|
|
12
|
-
const prototype = target.prototype;
|
|
13
|
-
const keys = Reflect.getMetadataKeys(prototype);
|
|
14
|
-
// Check for class-transformer metadata
|
|
15
|
-
return keys.some((key) => key.startsWith("class_transformer:"));
|
|
16
|
-
}
|
|
17
|
-
function isClassTransformerType(target) {
|
|
18
|
-
return isClassTransformerClass(target);
|
|
19
|
-
}
|
|
20
|
-
class HttpResponse {
|
|
21
|
-
static Ok(obj, s) {
|
|
22
|
-
if (s) {
|
|
23
|
-
const isPaginated = obj === null || obj === void 0 ? void 0 : obj.hasOwnProperty("total");
|
|
24
|
-
const dataToTransform = isPaginated ? obj.data : obj;
|
|
25
|
-
const transformedData = (0, class_transformer_1.plainToInstance)(s, dataToTransform, {
|
|
26
|
-
enableImplicitConversion: true,
|
|
27
|
-
excludeExtraneousValues: true,
|
|
28
|
-
});
|
|
29
|
-
const transformedResult = isPaginated
|
|
30
|
-
? { ...obj, data: (0, class_transformer_1.instanceToPlain)(transformedData) }
|
|
31
|
-
: { data: (0, class_transformer_1.instanceToPlain)(transformedData) };
|
|
32
|
-
return {
|
|
33
|
-
message: "success",
|
|
34
|
-
...transformedResult,
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
return { message: "success", data: obj };
|
|
38
|
-
}
|
|
39
|
-
static Created(obj, s) {
|
|
40
|
-
if (s) {
|
|
41
|
-
const transformedData = (0, class_transformer_1.plainToInstance)(s, obj, {
|
|
42
|
-
enableImplicitConversion: true,
|
|
43
|
-
excludeExtraneousValues: true,
|
|
44
|
-
});
|
|
45
|
-
return {
|
|
46
|
-
message: "created",
|
|
47
|
-
data: (0, class_transformer_1.instanceToPlain)(transformedData),
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
return { message: "created", data: obj };
|
|
51
|
-
}
|
|
52
|
-
static NoContent() {
|
|
53
|
-
return { message: "no content", data: null };
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
exports.HttpResponse = HttpResponse;
|
package/dist/results.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export type OkOptions = {
|
|
2
|
-
streamable: boolean;
|
|
3
|
-
};
|
|
4
|
-
export declare class Results {
|
|
5
|
-
static code: number;
|
|
6
|
-
message: string;
|
|
7
|
-
static Ok<T>(data: T): Ok<T>;
|
|
8
|
-
static NoContent(): void;
|
|
9
|
-
static OkStream(): void;
|
|
10
|
-
static NotFound<T>(message: T): NotFound<T>;
|
|
11
|
-
}
|
|
12
|
-
export declare class Ok<T> {
|
|
13
|
-
data: T;
|
|
14
|
-
constructor(data: T);
|
|
15
|
-
}
|
|
16
|
-
export declare class NotFound<T> {
|
|
17
|
-
message: T;
|
|
18
|
-
constructor(message: T);
|
|
19
|
-
}
|
|
20
|
-
export type RouteResult<T = any> = typeof Results.Ok<T>;
|
package/dist/results.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NotFound = exports.Ok = exports.Results = void 0;
|
|
4
|
-
class Results {
|
|
5
|
-
constructor() {
|
|
6
|
-
this.message = "Something going wrong";
|
|
7
|
-
}
|
|
8
|
-
static Ok(data) {
|
|
9
|
-
return new Ok(data);
|
|
10
|
-
}
|
|
11
|
-
static NoContent() {
|
|
12
|
-
this.code = 204;
|
|
13
|
-
}
|
|
14
|
-
static OkStream() { }
|
|
15
|
-
static NotFound(message) {
|
|
16
|
-
return new NotFound(message);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
exports.Results = Results;
|
|
20
|
-
Results.code = 500;
|
|
21
|
-
class Ok {
|
|
22
|
-
constructor(data) {
|
|
23
|
-
this.data = data;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
exports.Ok = Ok;
|
|
27
|
-
class NotFound {
|
|
28
|
-
constructor(message) {
|
|
29
|
-
this.message = message;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
exports.NotFound = NotFound;
|
package/dist/route-methods.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @copyright 2024
|
|
3
|
-
* @author Tareq Hossain
|
|
4
|
-
* @email xtrinsic96@gmail.com
|
|
5
|
-
* @url https://github.com/xtareq
|
|
6
|
-
*/
|
|
7
|
-
import { OpenApiOptions } from "./openapi";
|
|
8
|
-
export type RouteMethods = "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "OPTIONS" | "ALL";
|
|
9
|
-
export type RouteMethodOptions = {
|
|
10
|
-
method?: RouteMethods;
|
|
11
|
-
path?: string;
|
|
12
|
-
openapi?: OpenApiOptions;
|
|
13
|
-
name?: string;
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* Generic Route decorator factory
|
|
17
|
-
*/
|
|
18
|
-
export declare function Route(method: RouteMethods, pathOrOptions?: string | RouteMethodOptions, maybeOptions?: RouteMethodOptions): MethodDecorator;
|
|
19
|
-
export declare const Get: (pathOrOptions?: string | RouteMethodOptions, maybeOptions?: RouteMethodOptions) => MethodDecorator;
|
|
20
|
-
export declare const Post: (pathOrOptions?: string | RouteMethodOptions, maybeOptions?: RouteMethodOptions) => MethodDecorator;
|
|
21
|
-
export declare const Put: (pathOrOptions?: string | RouteMethodOptions, maybeOptions?: RouteMethodOptions) => MethodDecorator;
|
|
22
|
-
export declare const Delete: (pathOrOptions?: string | RouteMethodOptions, maybeOptions?: RouteMethodOptions) => MethodDecorator;
|
|
23
|
-
export declare const Patch: (pathOrOptions?: string | RouteMethodOptions, maybeOptions?: RouteMethodOptions) => MethodDecorator;
|
|
24
|
-
export declare const Options: (pathOrOptions?: string | RouteMethodOptions, maybeOptions?: RouteMethodOptions) => MethodDecorator;
|
|
25
|
-
export declare const All: (pathOrOptions?: string | RouteMethodOptions, maybeOptions?: RouteMethodOptions) => MethodDecorator;
|
package/dist/route-methods.js
DELETED
|
@@ -1,49 +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.All = exports.Options = exports.Patch = exports.Delete = exports.Put = exports.Post = exports.Get = void 0;
|
|
10
|
-
exports.Route = Route;
|
|
11
|
-
const container_1 = require("./container");
|
|
12
|
-
/**
|
|
13
|
-
* Generic Route decorator factory
|
|
14
|
-
*/
|
|
15
|
-
function Route(method, pathOrOptions, maybeOptions) {
|
|
16
|
-
return function (target, propertyKey, descriptor) {
|
|
17
|
-
let path = "/";
|
|
18
|
-
let options = {};
|
|
19
|
-
if (typeof pathOrOptions === "string") {
|
|
20
|
-
path = pathOrOptions;
|
|
21
|
-
options = maybeOptions || {};
|
|
22
|
-
}
|
|
23
|
-
else if (typeof pathOrOptions === "object") {
|
|
24
|
-
options = pathOrOptions;
|
|
25
|
-
path = options.name || "/";
|
|
26
|
-
}
|
|
27
|
-
// Define metadata
|
|
28
|
-
Reflect.defineMetadata("route:path", path, target, propertyKey);
|
|
29
|
-
Reflect.defineMetadata("route:method", method, target, propertyKey);
|
|
30
|
-
Reflect.defineMetadata(container_1.ROUTE_META_KEY, { ...options, method, path, controller: target.constructor.name }, target, propertyKey);
|
|
31
|
-
if (options) {
|
|
32
|
-
Reflect.defineMetadata("route:options", options, target, propertyKey);
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
const Get = (pathOrOptions, maybeOptions) => Route("GET", pathOrOptions, maybeOptions);
|
|
37
|
-
exports.Get = Get;
|
|
38
|
-
const Post = (pathOrOptions, maybeOptions) => Route("POST", pathOrOptions, maybeOptions);
|
|
39
|
-
exports.Post = Post;
|
|
40
|
-
const Put = (pathOrOptions, maybeOptions) => Route("PUT", pathOrOptions, maybeOptions);
|
|
41
|
-
exports.Put = Put;
|
|
42
|
-
const Delete = (pathOrOptions, maybeOptions) => Route("DELETE", pathOrOptions, maybeOptions);
|
|
43
|
-
exports.Delete = Delete;
|
|
44
|
-
const Patch = (pathOrOptions, maybeOptions) => Route("PATCH", pathOrOptions, maybeOptions);
|
|
45
|
-
exports.Patch = Patch;
|
|
46
|
-
const Options = (pathOrOptions, maybeOptions) => Route("OPTIONS", pathOrOptions, maybeOptions);
|
|
47
|
-
exports.Options = Options;
|
|
48
|
-
const All = (pathOrOptions, maybeOptions) => Route("ALL", pathOrOptions, maybeOptions);
|
|
49
|
-
exports.All = All;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "reflect-metadata";
|
|
@@ -1,129 +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
|
-
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
|
-
});
|
package/dist/swagger-schema.d.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
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;
|
|
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
|
-
};
|