@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/multipart.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @copyright 2024
|
|
3
|
-
* @author Tareq Hossain
|
|
4
|
-
* @email xtrinsic96@gmail.com
|
|
5
|
-
* @url https://github.com/xtareq
|
|
6
|
-
*/
|
|
7
|
-
import { MultipartFile as FsM, SavedMultipartFile } from "@fastify/multipart";
|
|
8
|
-
import { IRequest } from "./icore";
|
|
9
|
-
export declare function UploadFile(fieldName: string): (target: any, propertyKey: string | symbol, parameterIndex: number) => void;
|
|
10
|
-
export declare function UploadFiles(fieldName?: string): (target: any, propertyKey: string | symbol, parameterIndex: number) => void;
|
|
11
|
-
type Foptions = {
|
|
12
|
-
saveAs?: string;
|
|
13
|
-
dest?: true;
|
|
14
|
-
};
|
|
15
|
-
export type MultipartFile = FsM | SavedMultipartFile;
|
|
16
|
-
export declare function UploadFileFromRequest(req: IRequest, options?: Foptions): Promise<FsM | undefined>;
|
|
17
|
-
export {};
|
package/dist/multipart.js
DELETED
|
@@ -1,70 +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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.UploadFile = UploadFile;
|
|
13
|
-
exports.UploadFiles = UploadFiles;
|
|
14
|
-
exports.UploadFileFromRequest = UploadFileFromRequest;
|
|
15
|
-
const fs_1 = __importDefault(require("fs"));
|
|
16
|
-
const path_1 = __importDefault(require("path"));
|
|
17
|
-
const promises_1 = require("stream/promises");
|
|
18
|
-
const exceptions_1 = require("./exceptions");
|
|
19
|
-
const container_1 = require("./container");
|
|
20
|
-
function UploadFile(fieldName) {
|
|
21
|
-
return function (target, propertyKey, parameterIndex) {
|
|
22
|
-
if (!Reflect.hasMetadata(container_1.REQUEST_BODY_FILE_KEY, target, propertyKey)) {
|
|
23
|
-
Reflect.defineMetadata(container_1.REQUEST_BODY_FILE_KEY, [], target, propertyKey);
|
|
24
|
-
}
|
|
25
|
-
const existingMetadata = Reflect.getMetadata(container_1.REQUEST_BODY_FILE_KEY, target, propertyKey);
|
|
26
|
-
existingMetadata.push({ fieldName, index: parameterIndex });
|
|
27
|
-
Reflect.defineMetadata(container_1.REQUEST_BODY_FILE_KEY, existingMetadata, target, propertyKey);
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
function UploadFiles(fieldName) {
|
|
31
|
-
return function (target, propertyKey, parameterIndex) {
|
|
32
|
-
if (!Reflect.hasMetadata(container_1.REQUEST_BODY_FILES_KEY, target, propertyKey)) {
|
|
33
|
-
Reflect.defineMetadata(container_1.REQUEST_BODY_FILES_KEY, [], target, propertyKey);
|
|
34
|
-
}
|
|
35
|
-
const existingMetadata = Reflect.getMetadata(container_1.REQUEST_BODY_FILES_KEY, target, propertyKey);
|
|
36
|
-
existingMetadata.push({
|
|
37
|
-
fieldName: fieldName ? fieldName : "all",
|
|
38
|
-
index: parameterIndex,
|
|
39
|
-
});
|
|
40
|
-
Reflect.defineMetadata(container_1.REQUEST_BODY_FILES_KEY, existingMetadata, target, propertyKey);
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
function UploadFileFromRequest(req, options) {
|
|
44
|
-
return Promise.resolve(req.file().then(async (f) => {
|
|
45
|
-
if (f && f.file) {
|
|
46
|
-
let fname = f.filename;
|
|
47
|
-
if (options) {
|
|
48
|
-
if (options.dest) {
|
|
49
|
-
fname = options.saveAs
|
|
50
|
-
? options.dest + "/" + options.saveAs
|
|
51
|
-
: options.dest + "/" + f.filename;
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
fname = path_1.default.join(process.cwd(), `public/${options.saveAs ? options.saveAs : f.filename}`);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
fname = path_1.default.join(process.cwd(), `public/${f.filename}`);
|
|
59
|
-
}
|
|
60
|
-
if (fs_1.default.existsSync(fname)) {
|
|
61
|
-
throw new exceptions_1.InternalErrorException("File already exists.");
|
|
62
|
-
}
|
|
63
|
-
await (0, promises_1.pipeline)(f.file, fs_1.default.createWriteStream(fname));
|
|
64
|
-
return {
|
|
65
|
-
...f,
|
|
66
|
-
filename: (options === null || options === void 0 ? void 0 : options.saveAs) ? options.saveAs : f.filename,
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
}));
|
|
70
|
-
}
|
package/dist/multipart.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/multipart.test.js
DELETED
|
@@ -1,87 +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
|
-
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
|
-
});
|
package/dist/openapi.d.ts
DELETED
|
@@ -1,343 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @copyright 2024
|
|
3
|
-
* @author Tareq Hossain
|
|
4
|
-
* @email xtrinsic96@gmail.com
|
|
5
|
-
* @url https://github.com/xtareq
|
|
6
|
-
*/
|
|
7
|
-
export interface InfoObject {
|
|
8
|
-
title: string;
|
|
9
|
-
description?: string;
|
|
10
|
-
termsOfService?: string;
|
|
11
|
-
contact?: ContactObject;
|
|
12
|
-
license?: LicenseObject;
|
|
13
|
-
version: string;
|
|
14
|
-
}
|
|
15
|
-
export interface ContactObject {
|
|
16
|
-
name?: string;
|
|
17
|
-
url?: string;
|
|
18
|
-
email?: string;
|
|
19
|
-
}
|
|
20
|
-
export interface LicenseObject {
|
|
21
|
-
name: string;
|
|
22
|
-
url?: string;
|
|
23
|
-
}
|
|
24
|
-
export interface ServerObject {
|
|
25
|
-
url: string;
|
|
26
|
-
description?: string;
|
|
27
|
-
variables?: {
|
|
28
|
-
[variable: string]: ServerVariableObject;
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
export interface ServerVariableObject {
|
|
32
|
-
enum?: string[];
|
|
33
|
-
default: string;
|
|
34
|
-
description?: string;
|
|
35
|
-
}
|
|
36
|
-
export type OpenApiUiOptions = {
|
|
37
|
-
logo?: any;
|
|
38
|
-
theme?: any;
|
|
39
|
-
ui?: "default" | "scalar";
|
|
40
|
-
openapi?: string;
|
|
41
|
-
configuration?: any;
|
|
42
|
-
routePrefix?: string;
|
|
43
|
-
info?: InfoObject;
|
|
44
|
-
servers?: ServerObject[];
|
|
45
|
-
paths?: PathsObject<any>;
|
|
46
|
-
components?: ComponentsObject;
|
|
47
|
-
security?: SecurityRequirementObject[];
|
|
48
|
-
tags?: TagObject[];
|
|
49
|
-
externalDocs?: any;
|
|
50
|
-
"x-express-openapi-additional-middleware"?: (((request: any, response: any, next: any) => Promise<void>) | ((request: any, response: any, next: any) => void))[];
|
|
51
|
-
"x-express-openapi-validation-strict"?: boolean;
|
|
52
|
-
};
|
|
53
|
-
export interface PathsObject<T extends {} = {}, P extends {} = {}> {
|
|
54
|
-
[pattern: string]: (PathItemObject<T> & P) | undefined;
|
|
55
|
-
}
|
|
56
|
-
declare enum HttpMethods {
|
|
57
|
-
GET = "get",
|
|
58
|
-
PUT = "put",
|
|
59
|
-
POST = "post",
|
|
60
|
-
DELETE = "delete",
|
|
61
|
-
OPTIONS = "options",
|
|
62
|
-
HEAD = "head",
|
|
63
|
-
PATCH = "patch",
|
|
64
|
-
TRACE = "trace"
|
|
65
|
-
}
|
|
66
|
-
export type PathItemObject<T extends {} = {}> = {
|
|
67
|
-
$ref?: string;
|
|
68
|
-
summary?: string;
|
|
69
|
-
description?: string;
|
|
70
|
-
servers?: ServerObject[];
|
|
71
|
-
parameters?: (ReferenceObject | ParameterObject)[];
|
|
72
|
-
} & {
|
|
73
|
-
[method in HttpMethods]?: OperationObject<T>;
|
|
74
|
-
};
|
|
75
|
-
export type OperationObject<T extends {} = {}> = {
|
|
76
|
-
tags?: string[];
|
|
77
|
-
summary?: string;
|
|
78
|
-
description?: string;
|
|
79
|
-
externalDocs?: ExternalDocumentationObject;
|
|
80
|
-
operationId?: string;
|
|
81
|
-
parameters?: (ReferenceObject | ParameterObject)[];
|
|
82
|
-
requestBody?: ReferenceObject | RequestBodyObject;
|
|
83
|
-
responses: ResponsesObject;
|
|
84
|
-
callbacks?: {
|
|
85
|
-
[callback: string]: ReferenceObject | CallbackObject;
|
|
86
|
-
};
|
|
87
|
-
deprecated?: boolean;
|
|
88
|
-
security?: SecurityRequirementObject[];
|
|
89
|
-
servers?: ServerObject[];
|
|
90
|
-
} & T;
|
|
91
|
-
export interface ExternalDocumentationObject {
|
|
92
|
-
description?: string;
|
|
93
|
-
url: string;
|
|
94
|
-
}
|
|
95
|
-
export interface ParameterObject extends ParameterBaseObject {
|
|
96
|
-
name: string;
|
|
97
|
-
in: string;
|
|
98
|
-
}
|
|
99
|
-
export interface HeaderObject extends ParameterBaseObject {
|
|
100
|
-
}
|
|
101
|
-
export interface ParameterBaseObject {
|
|
102
|
-
description?: string;
|
|
103
|
-
required?: boolean;
|
|
104
|
-
deprecated?: boolean;
|
|
105
|
-
allowEmptyValue?: boolean;
|
|
106
|
-
style?: string;
|
|
107
|
-
explode?: boolean;
|
|
108
|
-
allowReserved?: boolean;
|
|
109
|
-
schema?: ReferenceObject | SchemaObject;
|
|
110
|
-
example?: any;
|
|
111
|
-
examples?: {
|
|
112
|
-
[media: string]: ReferenceObject | ExampleObject;
|
|
113
|
-
};
|
|
114
|
-
content?: {
|
|
115
|
-
[media: string]: MediaTypeObject;
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
export type NonArraySchemaObjectType = "boolean" | "object" | "number" | "string" | "integer";
|
|
119
|
-
export type ArraySchemaObjectType = "array";
|
|
120
|
-
export type SchemaObject = ArraySchemaObject | NonArraySchemaObject;
|
|
121
|
-
export interface ArraySchemaObject extends BaseSchemaObject {
|
|
122
|
-
type: ArraySchemaObjectType;
|
|
123
|
-
items: ReferenceObject | SchemaObject;
|
|
124
|
-
}
|
|
125
|
-
export interface NonArraySchemaObject extends BaseSchemaObject {
|
|
126
|
-
type?: NonArraySchemaObjectType;
|
|
127
|
-
}
|
|
128
|
-
export interface BaseSchemaObject {
|
|
129
|
-
title?: string;
|
|
130
|
-
description?: string;
|
|
131
|
-
format?: string;
|
|
132
|
-
default?: any;
|
|
133
|
-
multipleOf?: number;
|
|
134
|
-
maximum?: number;
|
|
135
|
-
exclusiveMaximum?: boolean;
|
|
136
|
-
minimum?: number;
|
|
137
|
-
exclusiveMinimum?: boolean;
|
|
138
|
-
maxLength?: number;
|
|
139
|
-
minLength?: number;
|
|
140
|
-
pattern?: string;
|
|
141
|
-
additionalProperties?: boolean | ReferenceObject | SchemaObject;
|
|
142
|
-
maxItems?: number;
|
|
143
|
-
minItems?: number;
|
|
144
|
-
uniqueItems?: boolean;
|
|
145
|
-
maxProperties?: number;
|
|
146
|
-
minProperties?: number;
|
|
147
|
-
required?: string[];
|
|
148
|
-
enum?: any[];
|
|
149
|
-
properties?: {
|
|
150
|
-
[name: string]: ReferenceObject | SchemaObject;
|
|
151
|
-
};
|
|
152
|
-
allOf?: (ReferenceObject | SchemaObject)[];
|
|
153
|
-
oneOf?: (ReferenceObject | SchemaObject)[];
|
|
154
|
-
anyOf?: (ReferenceObject | SchemaObject)[];
|
|
155
|
-
not?: ReferenceObject | SchemaObject;
|
|
156
|
-
nullable?: boolean;
|
|
157
|
-
discriminator?: DiscriminatorObject;
|
|
158
|
-
readOnly?: boolean;
|
|
159
|
-
writeOnly?: boolean;
|
|
160
|
-
xml?: XMLObject;
|
|
161
|
-
externalDocs?: ExternalDocumentationObject;
|
|
162
|
-
example?: any;
|
|
163
|
-
deprecated?: boolean;
|
|
164
|
-
}
|
|
165
|
-
export interface DiscriminatorObject {
|
|
166
|
-
propertyName: string;
|
|
167
|
-
mapping?: {
|
|
168
|
-
[value: string]: string;
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
export interface XMLObject {
|
|
172
|
-
name?: string;
|
|
173
|
-
namespace?: string;
|
|
174
|
-
prefix?: string;
|
|
175
|
-
attribute?: boolean;
|
|
176
|
-
wrapped?: boolean;
|
|
177
|
-
}
|
|
178
|
-
export interface ReferenceObject {
|
|
179
|
-
$ref: string;
|
|
180
|
-
}
|
|
181
|
-
export interface ExampleObject {
|
|
182
|
-
summary?: string;
|
|
183
|
-
description?: string;
|
|
184
|
-
value?: any;
|
|
185
|
-
externalValue?: string;
|
|
186
|
-
}
|
|
187
|
-
export interface MediaTypeObject {
|
|
188
|
-
schema?: ReferenceObject | SchemaObject;
|
|
189
|
-
example?: any;
|
|
190
|
-
examples?: {
|
|
191
|
-
[media: string]: ReferenceObject | ExampleObject;
|
|
192
|
-
};
|
|
193
|
-
encoding?: {
|
|
194
|
-
[media: string]: EncodingObject;
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
export interface EncodingObject {
|
|
198
|
-
contentType?: string;
|
|
199
|
-
headers?: {
|
|
200
|
-
[header: string]: ReferenceObject | HeaderObject;
|
|
201
|
-
};
|
|
202
|
-
style?: string;
|
|
203
|
-
explode?: boolean;
|
|
204
|
-
allowReserved?: boolean;
|
|
205
|
-
}
|
|
206
|
-
export interface RequestBodyObject {
|
|
207
|
-
description?: string;
|
|
208
|
-
content: {
|
|
209
|
-
[media: string]: MediaTypeObject;
|
|
210
|
-
};
|
|
211
|
-
required?: boolean;
|
|
212
|
-
}
|
|
213
|
-
export interface ResponsesObject {
|
|
214
|
-
[code: string]: ReferenceObject | ResponseObject;
|
|
215
|
-
}
|
|
216
|
-
export interface ResponseObject {
|
|
217
|
-
description: string;
|
|
218
|
-
headers?: {
|
|
219
|
-
[header: string]: ReferenceObject | HeaderObject;
|
|
220
|
-
};
|
|
221
|
-
content?: {
|
|
222
|
-
[media: string]: MediaTypeObject;
|
|
223
|
-
};
|
|
224
|
-
links?: {
|
|
225
|
-
[link: string]: ReferenceObject | LinkObject;
|
|
226
|
-
};
|
|
227
|
-
}
|
|
228
|
-
export interface LinkObject {
|
|
229
|
-
operationRef?: string;
|
|
230
|
-
operationId?: string;
|
|
231
|
-
parameters?: {
|
|
232
|
-
[parameter: string]: any;
|
|
233
|
-
};
|
|
234
|
-
requestBody?: any;
|
|
235
|
-
description?: string;
|
|
236
|
-
server?: ServerObject;
|
|
237
|
-
}
|
|
238
|
-
export interface CallbackObject {
|
|
239
|
-
[url: string]: PathItemObject;
|
|
240
|
-
}
|
|
241
|
-
export interface SecurityRequirementObject {
|
|
242
|
-
[name: string]: string[];
|
|
243
|
-
}
|
|
244
|
-
export interface ComponentsObject {
|
|
245
|
-
schemas?: {
|
|
246
|
-
[key: string]: ReferenceObject | SchemaObject;
|
|
247
|
-
};
|
|
248
|
-
responses?: {
|
|
249
|
-
[key: string]: ReferenceObject | ResponseObject;
|
|
250
|
-
};
|
|
251
|
-
parameters?: {
|
|
252
|
-
[key: string]: ReferenceObject | ParameterObject;
|
|
253
|
-
};
|
|
254
|
-
examples?: {
|
|
255
|
-
[key: string]: ReferenceObject | ExampleObject;
|
|
256
|
-
};
|
|
257
|
-
requestBodies?: {
|
|
258
|
-
[key: string]: ReferenceObject | RequestBodyObject;
|
|
259
|
-
};
|
|
260
|
-
headers?: {
|
|
261
|
-
[key: string]: ReferenceObject | HeaderObject;
|
|
262
|
-
};
|
|
263
|
-
securitySchemes?: {
|
|
264
|
-
[key: string]: ReferenceObject | SecuritySchemeObject;
|
|
265
|
-
};
|
|
266
|
-
links?: {
|
|
267
|
-
[key: string]: ReferenceObject | LinkObject;
|
|
268
|
-
};
|
|
269
|
-
callbacks?: {
|
|
270
|
-
[key: string]: ReferenceObject | CallbackObject;
|
|
271
|
-
};
|
|
272
|
-
}
|
|
273
|
-
export type SecuritySchemeObject = HttpSecurityScheme | ApiKeySecurityScheme | OAuth2SecurityScheme | OpenIdSecurityScheme;
|
|
274
|
-
export interface HttpSecurityScheme {
|
|
275
|
-
type: "http";
|
|
276
|
-
description?: string;
|
|
277
|
-
scheme: string;
|
|
278
|
-
bearerFormat?: string;
|
|
279
|
-
}
|
|
280
|
-
export interface ApiKeySecurityScheme {
|
|
281
|
-
type: "apiKey";
|
|
282
|
-
description?: string;
|
|
283
|
-
name: string;
|
|
284
|
-
in: string;
|
|
285
|
-
}
|
|
286
|
-
export interface OAuth2SecurityScheme {
|
|
287
|
-
type: "oauth2";
|
|
288
|
-
description?: string;
|
|
289
|
-
flows: {
|
|
290
|
-
implicit?: {
|
|
291
|
-
authorizationUrl: string;
|
|
292
|
-
refreshUrl?: string;
|
|
293
|
-
scopes: {
|
|
294
|
-
[scope: string]: string;
|
|
295
|
-
};
|
|
296
|
-
};
|
|
297
|
-
password?: {
|
|
298
|
-
tokenUrl: string;
|
|
299
|
-
refreshUrl?: string;
|
|
300
|
-
scopes: {
|
|
301
|
-
[scope: string]: string;
|
|
302
|
-
};
|
|
303
|
-
};
|
|
304
|
-
clientCredentials?: {
|
|
305
|
-
tokenUrl: string;
|
|
306
|
-
refreshUrl?: string;
|
|
307
|
-
scopes: {
|
|
308
|
-
[scope: string]: string;
|
|
309
|
-
};
|
|
310
|
-
};
|
|
311
|
-
authorizationCode?: {
|
|
312
|
-
authorizationUrl: string;
|
|
313
|
-
tokenUrl: string;
|
|
314
|
-
refreshUrl?: string;
|
|
315
|
-
scopes: {
|
|
316
|
-
[scope: string]: string;
|
|
317
|
-
};
|
|
318
|
-
};
|
|
319
|
-
};
|
|
320
|
-
}
|
|
321
|
-
export interface OpenIdSecurityScheme {
|
|
322
|
-
type: "openIdConnect";
|
|
323
|
-
description?: string;
|
|
324
|
-
openIdConnectUrl: string;
|
|
325
|
-
}
|
|
326
|
-
export interface TagObject {
|
|
327
|
-
name: string;
|
|
328
|
-
description?: string;
|
|
329
|
-
externalDocs?: ExternalDocumentationObject;
|
|
330
|
-
}
|
|
331
|
-
export type OpenApiOptions = {
|
|
332
|
-
exclude?: boolean;
|
|
333
|
-
deprecated?: boolean;
|
|
334
|
-
tags?: readonly string[];
|
|
335
|
-
description?: string;
|
|
336
|
-
summary?: string;
|
|
337
|
-
components?: ComponentsObject;
|
|
338
|
-
response?: any;
|
|
339
|
-
responseBody?: any;
|
|
340
|
-
requestBody?: any;
|
|
341
|
-
} & any;
|
|
342
|
-
export declare function OpenApi(options: OpenApiOptions): MethodDecorator & ClassDecorator & PropertyDecorator;
|
|
343
|
-
export {};
|
package/dist/openapi.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OpenApi = OpenApi;
|
|
4
|
-
var HttpMethods;
|
|
5
|
-
(function (HttpMethods) {
|
|
6
|
-
HttpMethods["GET"] = "get";
|
|
7
|
-
HttpMethods["PUT"] = "put";
|
|
8
|
-
HttpMethods["POST"] = "post";
|
|
9
|
-
HttpMethods["DELETE"] = "delete";
|
|
10
|
-
HttpMethods["OPTIONS"] = "options";
|
|
11
|
-
HttpMethods["HEAD"] = "head";
|
|
12
|
-
HttpMethods["PATCH"] = "patch";
|
|
13
|
-
HttpMethods["TRACE"] = "trace";
|
|
14
|
-
})(HttpMethods || (HttpMethods = {}));
|
|
15
|
-
function OpenApi(options) {
|
|
16
|
-
return function (target, propertyKey, descriptor) {
|
|
17
|
-
if (typeof target === "function" && !propertyKey) {
|
|
18
|
-
Reflect.defineMetadata("controller:openapi", options, target);
|
|
19
|
-
}
|
|
20
|
-
else if (descriptor) {
|
|
21
|
-
Reflect.defineMetadata("route:openapi", options, target, propertyKey);
|
|
22
|
-
}
|
|
23
|
-
else if (propertyKey) {
|
|
24
|
-
Reflect.defineMetadata("property:openapi", options, target, propertyKey);
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
}
|
package/dist/openapi.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import 'reflect-metadata';
|
package/dist/openapi.test.js
DELETED
|
@@ -1,111 +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 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
|
-
});
|
package/dist/params.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @copyright 2024
|
|
3
|
-
* @author Tareq Hossain
|
|
4
|
-
* @email xtrinsic96@gmail.com
|
|
5
|
-
* @url https://github.com/xtareq
|
|
6
|
-
*/
|
|
7
|
-
type ParameterOptions = {
|
|
8
|
-
required?: boolean;
|
|
9
|
-
validate?: boolean;
|
|
10
|
-
type?: any;
|
|
11
|
-
};
|
|
12
|
-
export declare const Param: (key?: string | ParameterOptions, options?: ParameterOptions) => ParameterDecorator;
|
|
13
|
-
export declare const Query: (key?: string | ParameterOptions, options?: ParameterOptions) => ParameterDecorator;
|
|
14
|
-
export declare const Body: (key?: string | ParameterOptions, options?: ParameterOptions) => ParameterDecorator;
|
|
15
|
-
export declare const Header: (key?: string | ParameterOptions, options?: ParameterOptions) => ParameterDecorator;
|
|
16
|
-
export declare const AuthUser: (key?: string | ParameterOptions, options?: ParameterOptions) => ParameterDecorator;
|
|
17
|
-
export {};
|