@avleon/core 0.0.4
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 +1 -0
- package/dist/config.d.ts +30 -0
- package/dist/config.js +19 -0
- package/dist/container.d.ts +19 -0
- package/dist/container.js +51 -0
- package/dist/controller.d.ts +47 -0
- package/dist/controller.js +38 -0
- package/dist/decorators.d.ts +8 -0
- package/dist/decorators.js +25 -0
- package/dist/exceptions/http-exceptions.d.ts +21 -0
- package/dist/exceptions/http-exceptions.js +38 -0
- package/dist/exceptions/index.d.ts +1 -0
- package/dist/exceptions/index.js +17 -0
- package/dist/exceptions/system-exception.d.ts +13 -0
- package/dist/exceptions/system-exception.js +18 -0
- package/dist/helpers.d.ts +24 -0
- package/dist/helpers.js +192 -0
- package/dist/icore.d.ts +58 -0
- package/dist/icore.js +239 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +33 -0
- package/dist/map-types.d.ts +12 -0
- package/dist/map-types.js +85 -0
- package/dist/openapi.d.ts +333 -0
- package/dist/openapi.js +27 -0
- package/dist/params.d.ts +16 -0
- package/dist/params.js +48 -0
- package/dist/queue.d.ts +0 -0
- package/dist/queue.js +1 -0
- package/dist/repository.d.ts +0 -0
- package/dist/repository.js +1 -0
- package/dist/response.d.ts +9 -0
- package/dist/response.js +36 -0
- package/dist/results.d.ts +20 -0
- package/dist/results.js +32 -0
- package/dist/route-methods.d.ts +56 -0
- package/dist/route-methods.js +83 -0
- package/dist/swagger-schema.d.ts +1 -0
- package/dist/swagger-schema.js +29 -0
- package/dist/validator-extend.d.ts +1 -0
- package/dist/validator-extend.js +22 -0
- package/jest.config.ts +9 -0
- package/package.json +39 -0
- package/tsconfig.json +25 -0
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
interface InfoObject {
|
|
2
|
+
title: string;
|
|
3
|
+
description?: string;
|
|
4
|
+
termsOfService?: string;
|
|
5
|
+
contact?: ContactObject;
|
|
6
|
+
license?: LicenseObject;
|
|
7
|
+
version: string;
|
|
8
|
+
}
|
|
9
|
+
interface ContactObject {
|
|
10
|
+
name?: string;
|
|
11
|
+
url?: string;
|
|
12
|
+
email?: string;
|
|
13
|
+
}
|
|
14
|
+
interface LicenseObject {
|
|
15
|
+
name: string;
|
|
16
|
+
url?: string;
|
|
17
|
+
}
|
|
18
|
+
interface ServerObject {
|
|
19
|
+
url: string;
|
|
20
|
+
description?: string;
|
|
21
|
+
variables?: {
|
|
22
|
+
[variable: string]: ServerVariableObject;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
interface ServerVariableObject {
|
|
26
|
+
enum?: string[];
|
|
27
|
+
default: string;
|
|
28
|
+
description?: string;
|
|
29
|
+
}
|
|
30
|
+
export type OpenApiUiOptions = {
|
|
31
|
+
openapi?: string;
|
|
32
|
+
routePrefix?: string;
|
|
33
|
+
info?: InfoObject;
|
|
34
|
+
servers?: ServerObject[];
|
|
35
|
+
paths?: PathsObject<any>;
|
|
36
|
+
components?: ComponentsObject;
|
|
37
|
+
security?: SecurityRequirementObject[];
|
|
38
|
+
tags?: TagObject[];
|
|
39
|
+
externalDocs?: any;
|
|
40
|
+
"x-express-openapi-additional-middleware"?: (((request: any, response: any, next: any) => Promise<void>) | ((request: any, response: any, next: any) => void))[];
|
|
41
|
+
"x-express-openapi-validation-strict"?: boolean;
|
|
42
|
+
};
|
|
43
|
+
interface PathsObject<T extends {} = {}, P extends {} = {}> {
|
|
44
|
+
[pattern: string]: (PathItemObject<T> & P) | undefined;
|
|
45
|
+
}
|
|
46
|
+
declare enum HttpMethods {
|
|
47
|
+
GET = "get",
|
|
48
|
+
PUT = "put",
|
|
49
|
+
POST = "post",
|
|
50
|
+
DELETE = "delete",
|
|
51
|
+
OPTIONS = "options",
|
|
52
|
+
HEAD = "head",
|
|
53
|
+
PATCH = "patch",
|
|
54
|
+
TRACE = "trace"
|
|
55
|
+
}
|
|
56
|
+
type PathItemObject<T extends {} = {}> = {
|
|
57
|
+
$ref?: string;
|
|
58
|
+
summary?: string;
|
|
59
|
+
description?: string;
|
|
60
|
+
servers?: ServerObject[];
|
|
61
|
+
parameters?: (ReferenceObject | ParameterObject)[];
|
|
62
|
+
} & {
|
|
63
|
+
[method in HttpMethods]?: OperationObject<T>;
|
|
64
|
+
};
|
|
65
|
+
type OperationObject<T extends {} = {}> = {
|
|
66
|
+
tags?: string[];
|
|
67
|
+
summary?: string;
|
|
68
|
+
description?: string;
|
|
69
|
+
externalDocs?: ExternalDocumentationObject;
|
|
70
|
+
operationId?: string;
|
|
71
|
+
parameters?: (ReferenceObject | ParameterObject)[];
|
|
72
|
+
requestBody?: ReferenceObject | RequestBodyObject;
|
|
73
|
+
responses: ResponsesObject;
|
|
74
|
+
callbacks?: {
|
|
75
|
+
[callback: string]: ReferenceObject | CallbackObject;
|
|
76
|
+
};
|
|
77
|
+
deprecated?: boolean;
|
|
78
|
+
security?: SecurityRequirementObject[];
|
|
79
|
+
servers?: ServerObject[];
|
|
80
|
+
} & T;
|
|
81
|
+
interface ExternalDocumentationObject {
|
|
82
|
+
description?: string;
|
|
83
|
+
url: string;
|
|
84
|
+
}
|
|
85
|
+
interface ParameterObject extends ParameterBaseObject {
|
|
86
|
+
name: string;
|
|
87
|
+
in: string;
|
|
88
|
+
}
|
|
89
|
+
interface HeaderObject extends ParameterBaseObject {
|
|
90
|
+
}
|
|
91
|
+
interface ParameterBaseObject {
|
|
92
|
+
description?: string;
|
|
93
|
+
required?: boolean;
|
|
94
|
+
deprecated?: boolean;
|
|
95
|
+
allowEmptyValue?: boolean;
|
|
96
|
+
style?: string;
|
|
97
|
+
explode?: boolean;
|
|
98
|
+
allowReserved?: boolean;
|
|
99
|
+
schema?: ReferenceObject | SchemaObject;
|
|
100
|
+
example?: any;
|
|
101
|
+
examples?: {
|
|
102
|
+
[media: string]: ReferenceObject | ExampleObject;
|
|
103
|
+
};
|
|
104
|
+
content?: {
|
|
105
|
+
[media: string]: MediaTypeObject;
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
type NonArraySchemaObjectType = "boolean" | "object" | "number" | "string" | "integer";
|
|
109
|
+
type ArraySchemaObjectType = "array";
|
|
110
|
+
type SchemaObject = ArraySchemaObject | NonArraySchemaObject;
|
|
111
|
+
interface ArraySchemaObject extends BaseSchemaObject {
|
|
112
|
+
type: ArraySchemaObjectType;
|
|
113
|
+
items: ReferenceObject | SchemaObject;
|
|
114
|
+
}
|
|
115
|
+
interface NonArraySchemaObject extends BaseSchemaObject {
|
|
116
|
+
type?: NonArraySchemaObjectType;
|
|
117
|
+
}
|
|
118
|
+
interface BaseSchemaObject {
|
|
119
|
+
title?: string;
|
|
120
|
+
description?: string;
|
|
121
|
+
format?: string;
|
|
122
|
+
default?: any;
|
|
123
|
+
multipleOf?: number;
|
|
124
|
+
maximum?: number;
|
|
125
|
+
exclusiveMaximum?: boolean;
|
|
126
|
+
minimum?: number;
|
|
127
|
+
exclusiveMinimum?: boolean;
|
|
128
|
+
maxLength?: number;
|
|
129
|
+
minLength?: number;
|
|
130
|
+
pattern?: string;
|
|
131
|
+
additionalProperties?: boolean | ReferenceObject | SchemaObject;
|
|
132
|
+
maxItems?: number;
|
|
133
|
+
minItems?: number;
|
|
134
|
+
uniqueItems?: boolean;
|
|
135
|
+
maxProperties?: number;
|
|
136
|
+
minProperties?: number;
|
|
137
|
+
required?: string[];
|
|
138
|
+
enum?: any[];
|
|
139
|
+
properties?: {
|
|
140
|
+
[name: string]: ReferenceObject | SchemaObject;
|
|
141
|
+
};
|
|
142
|
+
allOf?: (ReferenceObject | SchemaObject)[];
|
|
143
|
+
oneOf?: (ReferenceObject | SchemaObject)[];
|
|
144
|
+
anyOf?: (ReferenceObject | SchemaObject)[];
|
|
145
|
+
not?: ReferenceObject | SchemaObject;
|
|
146
|
+
nullable?: boolean;
|
|
147
|
+
discriminator?: DiscriminatorObject;
|
|
148
|
+
readOnly?: boolean;
|
|
149
|
+
writeOnly?: boolean;
|
|
150
|
+
xml?: XMLObject;
|
|
151
|
+
externalDocs?: ExternalDocumentationObject;
|
|
152
|
+
example?: any;
|
|
153
|
+
deprecated?: boolean;
|
|
154
|
+
}
|
|
155
|
+
interface DiscriminatorObject {
|
|
156
|
+
propertyName: string;
|
|
157
|
+
mapping?: {
|
|
158
|
+
[value: string]: string;
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
interface XMLObject {
|
|
162
|
+
name?: string;
|
|
163
|
+
namespace?: string;
|
|
164
|
+
prefix?: string;
|
|
165
|
+
attribute?: boolean;
|
|
166
|
+
wrapped?: boolean;
|
|
167
|
+
}
|
|
168
|
+
interface ReferenceObject {
|
|
169
|
+
$ref: string;
|
|
170
|
+
}
|
|
171
|
+
interface ExampleObject {
|
|
172
|
+
summary?: string;
|
|
173
|
+
description?: string;
|
|
174
|
+
value?: any;
|
|
175
|
+
externalValue?: string;
|
|
176
|
+
}
|
|
177
|
+
interface MediaTypeObject {
|
|
178
|
+
schema?: ReferenceObject | SchemaObject;
|
|
179
|
+
example?: any;
|
|
180
|
+
examples?: {
|
|
181
|
+
[media: string]: ReferenceObject | ExampleObject;
|
|
182
|
+
};
|
|
183
|
+
encoding?: {
|
|
184
|
+
[media: string]: EncodingObject;
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
interface EncodingObject {
|
|
188
|
+
contentType?: string;
|
|
189
|
+
headers?: {
|
|
190
|
+
[header: string]: ReferenceObject | HeaderObject;
|
|
191
|
+
};
|
|
192
|
+
style?: string;
|
|
193
|
+
explode?: boolean;
|
|
194
|
+
allowReserved?: boolean;
|
|
195
|
+
}
|
|
196
|
+
interface RequestBodyObject {
|
|
197
|
+
description?: string;
|
|
198
|
+
content: {
|
|
199
|
+
[media: string]: MediaTypeObject;
|
|
200
|
+
};
|
|
201
|
+
required?: boolean;
|
|
202
|
+
}
|
|
203
|
+
interface ResponsesObject {
|
|
204
|
+
[code: string]: ReferenceObject | ResponseObject;
|
|
205
|
+
}
|
|
206
|
+
interface ResponseObject {
|
|
207
|
+
description: string;
|
|
208
|
+
headers?: {
|
|
209
|
+
[header: string]: ReferenceObject | HeaderObject;
|
|
210
|
+
};
|
|
211
|
+
content?: {
|
|
212
|
+
[media: string]: MediaTypeObject;
|
|
213
|
+
};
|
|
214
|
+
links?: {
|
|
215
|
+
[link: string]: ReferenceObject | LinkObject;
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
interface LinkObject {
|
|
219
|
+
operationRef?: string;
|
|
220
|
+
operationId?: string;
|
|
221
|
+
parameters?: {
|
|
222
|
+
[parameter: string]: any;
|
|
223
|
+
};
|
|
224
|
+
requestBody?: any;
|
|
225
|
+
description?: string;
|
|
226
|
+
server?: ServerObject;
|
|
227
|
+
}
|
|
228
|
+
interface CallbackObject {
|
|
229
|
+
[url: string]: PathItemObject;
|
|
230
|
+
}
|
|
231
|
+
interface SecurityRequirementObject {
|
|
232
|
+
[name: string]: string[];
|
|
233
|
+
}
|
|
234
|
+
interface ComponentsObject {
|
|
235
|
+
schemas?: {
|
|
236
|
+
[key: string]: ReferenceObject | SchemaObject;
|
|
237
|
+
};
|
|
238
|
+
responses?: {
|
|
239
|
+
[key: string]: ReferenceObject | ResponseObject;
|
|
240
|
+
};
|
|
241
|
+
parameters?: {
|
|
242
|
+
[key: string]: ReferenceObject | ParameterObject;
|
|
243
|
+
};
|
|
244
|
+
examples?: {
|
|
245
|
+
[key: string]: ReferenceObject | ExampleObject;
|
|
246
|
+
};
|
|
247
|
+
requestBodies?: {
|
|
248
|
+
[key: string]: ReferenceObject | RequestBodyObject;
|
|
249
|
+
};
|
|
250
|
+
headers?: {
|
|
251
|
+
[key: string]: ReferenceObject | HeaderObject;
|
|
252
|
+
};
|
|
253
|
+
securitySchemes?: {
|
|
254
|
+
[key: string]: ReferenceObject | SecuritySchemeObject;
|
|
255
|
+
};
|
|
256
|
+
links?: {
|
|
257
|
+
[key: string]: ReferenceObject | LinkObject;
|
|
258
|
+
};
|
|
259
|
+
callbacks?: {
|
|
260
|
+
[key: string]: ReferenceObject | CallbackObject;
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
type SecuritySchemeObject = HttpSecurityScheme | ApiKeySecurityScheme | OAuth2SecurityScheme | OpenIdSecurityScheme;
|
|
264
|
+
interface HttpSecurityScheme {
|
|
265
|
+
type: "http";
|
|
266
|
+
description?: string;
|
|
267
|
+
scheme: string;
|
|
268
|
+
bearerFormat?: string;
|
|
269
|
+
}
|
|
270
|
+
interface ApiKeySecurityScheme {
|
|
271
|
+
type: "apiKey";
|
|
272
|
+
description?: string;
|
|
273
|
+
name: string;
|
|
274
|
+
in: string;
|
|
275
|
+
}
|
|
276
|
+
interface OAuth2SecurityScheme {
|
|
277
|
+
type: "oauth2";
|
|
278
|
+
description?: string;
|
|
279
|
+
flows: {
|
|
280
|
+
implicit?: {
|
|
281
|
+
authorizationUrl: string;
|
|
282
|
+
refreshUrl?: string;
|
|
283
|
+
scopes: {
|
|
284
|
+
[scope: string]: string;
|
|
285
|
+
};
|
|
286
|
+
};
|
|
287
|
+
password?: {
|
|
288
|
+
tokenUrl: string;
|
|
289
|
+
refreshUrl?: string;
|
|
290
|
+
scopes: {
|
|
291
|
+
[scope: string]: string;
|
|
292
|
+
};
|
|
293
|
+
};
|
|
294
|
+
clientCredentials?: {
|
|
295
|
+
tokenUrl: string;
|
|
296
|
+
refreshUrl?: string;
|
|
297
|
+
scopes: {
|
|
298
|
+
[scope: string]: string;
|
|
299
|
+
};
|
|
300
|
+
};
|
|
301
|
+
authorizationCode?: {
|
|
302
|
+
authorizationUrl: string;
|
|
303
|
+
tokenUrl: string;
|
|
304
|
+
refreshUrl?: string;
|
|
305
|
+
scopes: {
|
|
306
|
+
[scope: string]: string;
|
|
307
|
+
};
|
|
308
|
+
};
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
interface OpenIdSecurityScheme {
|
|
312
|
+
type: "openIdConnect";
|
|
313
|
+
description?: string;
|
|
314
|
+
openIdConnectUrl: string;
|
|
315
|
+
}
|
|
316
|
+
interface TagObject {
|
|
317
|
+
name: string;
|
|
318
|
+
description?: string;
|
|
319
|
+
externalDocs?: ExternalDocumentationObject;
|
|
320
|
+
}
|
|
321
|
+
export type OpenApiOptions = {
|
|
322
|
+
exclude?: boolean;
|
|
323
|
+
deprecated?: boolean;
|
|
324
|
+
tags?: readonly string[];
|
|
325
|
+
description?: string;
|
|
326
|
+
summary?: string;
|
|
327
|
+
components?: ComponentsObject;
|
|
328
|
+
response?: any;
|
|
329
|
+
responseBody?: any;
|
|
330
|
+
requestBody?: any;
|
|
331
|
+
} & any;
|
|
332
|
+
export declare function OpenApi(options: OpenApiOptions): MethodDecorator & ClassDecorator & PropertyDecorator;
|
|
333
|
+
export {};
|
package/dist/openapi.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
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/params.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
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 {};
|
package/dist/params.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Header = exports.Body = exports.Query = exports.Param = void 0;
|
|
4
|
+
const container_1 = require("./container");
|
|
5
|
+
const helpers_1 = require("./helpers");
|
|
6
|
+
function createParamDecorator(type) {
|
|
7
|
+
return function (key, options = {}) {
|
|
8
|
+
return function (target, propertyKey, parameterIndex) {
|
|
9
|
+
var _a;
|
|
10
|
+
const existingParams = Reflect.getMetadata(type, target, propertyKey) || [];
|
|
11
|
+
const parameterTypes = Reflect.getMetadata("design:paramtypes", target, propertyKey) || [];
|
|
12
|
+
const functionSource = target[propertyKey].toString();
|
|
13
|
+
const paramNames = (_a = functionSource.match(/\(([^)]*)\)/)) === null || _a === void 0 ? void 0 : _a[1].split(',').map((name) => name.trim());
|
|
14
|
+
const paramDataType = parameterTypes[parameterIndex];
|
|
15
|
+
existingParams.push({
|
|
16
|
+
index: parameterIndex,
|
|
17
|
+
key: key ? key : 'all',
|
|
18
|
+
name: paramNames[parameterIndex],
|
|
19
|
+
required: options.required || false,
|
|
20
|
+
validate: options.validate || true,
|
|
21
|
+
dataType: (0, helpers_1.getDataType)(paramDataType),
|
|
22
|
+
validatorClass: (0, helpers_1.isClassValidatorClass)(paramDataType),
|
|
23
|
+
type
|
|
24
|
+
});
|
|
25
|
+
switch (type) {
|
|
26
|
+
case 'route:param':
|
|
27
|
+
Reflect.defineMetadata(container_1.PARAM_META_KEY, existingParams, target, propertyKey);
|
|
28
|
+
break;
|
|
29
|
+
case 'route:query':
|
|
30
|
+
Reflect.defineMetadata(container_1.QUERY_META_KEY, existingParams, target, propertyKey);
|
|
31
|
+
break;
|
|
32
|
+
case 'route:body':
|
|
33
|
+
Reflect.defineMetadata(container_1.REQUEST_BODY_META_KEY, existingParams, target, propertyKey);
|
|
34
|
+
break;
|
|
35
|
+
case 'route:header':
|
|
36
|
+
Reflect.defineMetadata(container_1.REQUEST_HEADER_META_KEY, existingParams, target, propertyKey);
|
|
37
|
+
break;
|
|
38
|
+
default:
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
exports.Param = createParamDecorator("route:param");
|
|
45
|
+
exports.Query = createParamDecorator("route:query");
|
|
46
|
+
exports.Body = createParamDecorator("route:body");
|
|
47
|
+
exports.Header = createParamDecorator("route:header");
|
|
48
|
+
``;
|
package/dist/queue.d.ts
ADDED
|
File without changes
|
package/dist/queue.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
package/dist/response.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpResponse = void 0;
|
|
4
|
+
require("reflect-metadata");
|
|
5
|
+
const class_transformer_1 = require("class-transformer");
|
|
6
|
+
function isClassTransformerClass(target) {
|
|
7
|
+
const prototype = target.prototype;
|
|
8
|
+
const keys = Reflect.getMetadataKeys(prototype);
|
|
9
|
+
// Check for class-transformer metadata
|
|
10
|
+
return keys.some(key => key.startsWith('class_transformer:'));
|
|
11
|
+
}
|
|
12
|
+
function isClassTransformerType(target) {
|
|
13
|
+
return isClassTransformerClass(target);
|
|
14
|
+
}
|
|
15
|
+
class HttpResponse {
|
|
16
|
+
static Ok(obj, s) {
|
|
17
|
+
if (s) {
|
|
18
|
+
let pg = false;
|
|
19
|
+
if (obj.hasOwnProperty('total')) {
|
|
20
|
+
pg = true;
|
|
21
|
+
}
|
|
22
|
+
const data = (0, class_transformer_1.instanceToPlain)((0, class_transformer_1.plainToInstance)(s, pg ? obj.data : obj, { enableImplicitConversion: true, exposeUnsetFields: false }), { strategy: 'excludeAll' });
|
|
23
|
+
if (pg) {
|
|
24
|
+
return Object.assign(Object.assign({ message: "success" }, obj), { data: data });
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
return { message: "success", data };
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
return { message: "success", data: obj };
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
static NoContent() { }
|
|
35
|
+
}
|
|
36
|
+
exports.HttpResponse = HttpResponse;
|
|
@@ -0,0 +1,20 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
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;
|
|
@@ -0,0 +1,56 @@
|
|
|
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
|
+
/**
|
|
10
|
+
* Options for defining a route's method and metadata.
|
|
11
|
+
*/
|
|
12
|
+
export type RouteMethodOptions = {
|
|
13
|
+
/**
|
|
14
|
+
* HTTP method for the route (e.g., GET, POST, PUT, DELETE).
|
|
15
|
+
*/
|
|
16
|
+
method?: RouteMethods;
|
|
17
|
+
/**
|
|
18
|
+
* The path or endpoint for the route (e.g., "/users/:id").
|
|
19
|
+
*/
|
|
20
|
+
path?: string;
|
|
21
|
+
/**
|
|
22
|
+
* OpenAPI metadata for the route, including summary and description.
|
|
23
|
+
*/
|
|
24
|
+
openapi?: OpenApiOptions;
|
|
25
|
+
/**
|
|
26
|
+
* Name of the route.
|
|
27
|
+
*
|
|
28
|
+
* @description If Swagger is enabled in the project, this will appear as a tag in the generated documentation.
|
|
29
|
+
*/
|
|
30
|
+
name?: string;
|
|
31
|
+
};
|
|
32
|
+
export declare function createRouteDecorator(method?: RouteMethods): (pathOrOptions: string | RouteMethodOptions, maybeOptions?: RouteMethodOptions) => MethodDecorator;
|
|
33
|
+
/**
|
|
34
|
+
* @description HTTP Get method
|
|
35
|
+
* @param {string} path
|
|
36
|
+
*/
|
|
37
|
+
export declare function Get(path?: string): MethodDecorator;
|
|
38
|
+
export declare function Get(path: string | RouteMethodOptions): MethodDecorator;
|
|
39
|
+
/**
|
|
40
|
+
* @description HTTP Get method
|
|
41
|
+
* @param {string} path
|
|
42
|
+
* @param {RouteMethodOptions} options
|
|
43
|
+
*/
|
|
44
|
+
export declare function Get(path: string, options: RouteMethodOptions): MethodDecorator;
|
|
45
|
+
export declare function Post(path?: string): MethodDecorator;
|
|
46
|
+
export declare function Post(path: string | RouteMethodOptions): MethodDecorator;
|
|
47
|
+
export declare function Post(path: string, options: RouteMethodOptions): MethodDecorator;
|
|
48
|
+
export declare function Put(path?: string): MethodDecorator;
|
|
49
|
+
export declare function Put(path: string | RouteMethodOptions): MethodDecorator;
|
|
50
|
+
export declare function Put(path: string, options: RouteMethodOptions): MethodDecorator;
|
|
51
|
+
export declare function Delete(path?: string): MethodDecorator;
|
|
52
|
+
export declare function Delete(path: string | RouteMethodOptions): MethodDecorator;
|
|
53
|
+
export declare function Delete(path: string, options: RouteMethodOptions): MethodDecorator;
|
|
54
|
+
export declare const Patch: (pathOrOptions: string | RouteMethodOptions, maybeOptions?: RouteMethodOptions) => MethodDecorator;
|
|
55
|
+
export declare const Options: (pathOrOptions: string | RouteMethodOptions, maybeOptions?: RouteMethodOptions) => MethodDecorator;
|
|
56
|
+
export declare const All: (pathOrOptions: string | RouteMethodOptions, maybeOptions?: RouteMethodOptions) => MethodDecorator;
|
|
@@ -0,0 +1,83 @@
|
|
|
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 = void 0;
|
|
10
|
+
exports.createRouteDecorator = createRouteDecorator;
|
|
11
|
+
exports.Get = Get;
|
|
12
|
+
exports.Post = Post;
|
|
13
|
+
exports.Put = Put;
|
|
14
|
+
exports.Delete = Delete;
|
|
15
|
+
const container_1 = require("./container");
|
|
16
|
+
const schema = {
|
|
17
|
+
tags: ["hello"],
|
|
18
|
+
};
|
|
19
|
+
// Overloads
|
|
20
|
+
// Implementation
|
|
21
|
+
function createRouteDecorator(method = "GET") {
|
|
22
|
+
return function (pathOrOptions, maybeOptions) {
|
|
23
|
+
return function (target, propertyKey, descriptor) {
|
|
24
|
+
let path = "/";
|
|
25
|
+
let options = {};
|
|
26
|
+
if (typeof pathOrOptions === "string") {
|
|
27
|
+
path = pathOrOptions;
|
|
28
|
+
options = maybeOptions || {};
|
|
29
|
+
}
|
|
30
|
+
else if (typeof pathOrOptions === "object") {
|
|
31
|
+
options = pathOrOptions;
|
|
32
|
+
path = options.name || "/";
|
|
33
|
+
}
|
|
34
|
+
// Define metadata
|
|
35
|
+
Reflect.defineMetadata("route:path", path, target, propertyKey);
|
|
36
|
+
Reflect.defineMetadata("route:method", method || "GET", target, propertyKey);
|
|
37
|
+
Reflect.getMetadata(container_1.CONTROLLER_META_KEY, target.constructor);
|
|
38
|
+
Reflect.defineMetadata(container_1.ROUTE_META_KEY, Object.assign(Object.assign({}, options), { method, path, controller: target.constructor.name }), target, propertyKey);
|
|
39
|
+
if (options) {
|
|
40
|
+
Reflect.defineMetadata("route:options", options, target, propertyKey);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function Get(path, options) {
|
|
46
|
+
const parsedPath = !path && !options ? "/" : path;
|
|
47
|
+
if (options) {
|
|
48
|
+
return createRouteDecorator("GET")(parsedPath, options);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
return createRouteDecorator("GET")(parsedPath);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function Post(path, options) {
|
|
55
|
+
const parsedPath = !path && !options ? "/" : path;
|
|
56
|
+
if (options) {
|
|
57
|
+
return createRouteDecorator("POST")(parsedPath, options);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
return createRouteDecorator("POST")(parsedPath);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function Put(path, options) {
|
|
64
|
+
const parsedPath = !path && !options ? "/" : path;
|
|
65
|
+
if (options) {
|
|
66
|
+
return createRouteDecorator("PUT")(parsedPath, options);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
return createRouteDecorator("PUT")(parsedPath);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function Delete(path, options) {
|
|
73
|
+
const parsedPath = !path && !options ? "/" : path;
|
|
74
|
+
if (options) {
|
|
75
|
+
return createRouteDecorator("DELETE")(parsedPath, options);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
return createRouteDecorator("DELETE")(parsedPath);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
exports.Patch = createRouteDecorator("PATCH");
|
|
82
|
+
exports.Options = createRouteDecorator("OPTIONS");
|
|
83
|
+
exports.All = createRouteDecorator("ALL");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function generateSwaggerSchema(classType: any): any;
|