@avleon/core 0.0.19 → 0.0.24
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 +559 -2
- package/dist/application.d.ts +26 -0
- package/dist/application.js +50 -0
- package/dist/collection.js +3 -2
- package/dist/container.d.ts +1 -0
- package/dist/container.js +2 -1
- package/dist/environment-variables.js +1 -1
- package/dist/file-storage.js +0 -128
- package/dist/helpers.d.ts +2 -0
- package/dist/helpers.js +41 -4
- package/dist/icore.d.ts +68 -26
- package/dist/icore.js +235 -212
- package/dist/index.d.ts +2 -2
- package/dist/index.js +4 -2
- package/dist/middleware.js +0 -8
- package/dist/multipart.js +4 -1
- package/dist/openapi.d.ts +37 -37
- package/dist/params.js +2 -2
- package/dist/response.js +6 -2
- package/dist/route-methods.js +1 -1
- package/dist/swagger-schema.js +4 -1
- package/dist/testing.js +5 -2
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +18 -0
- package/dist/utils/optional-require.d.ts +8 -0
- package/dist/utils/optional-require.js +70 -0
- package/dist/validation.d.ts +4 -1
- package/dist/validation.js +10 -5
- package/package.json +19 -11
- package/src/application.ts +96 -0
- package/src/authentication.ts +16 -0
- package/src/collection.ts +254 -0
- package/src/config.ts +39 -0
- package/src/constants.ts +1 -0
- package/src/container.ts +54 -0
- package/src/controller.ts +128 -0
- package/src/decorators.ts +27 -0
- package/src/environment-variables.ts +46 -0
- package/src/exceptions/http-exceptions.ts +86 -0
- package/src/exceptions/index.ts +1 -0
- package/src/exceptions/system-exception.ts +34 -0
- package/src/file-storage.ts +206 -0
- package/src/helpers.ts +328 -0
- package/src/icore.ts +1064 -0
- package/src/index.ts +30 -0
- package/src/logger.ts +72 -0
- package/src/map-types.ts +159 -0
- package/src/middleware.ts +98 -0
- package/src/multipart.ts +116 -0
- package/src/openapi.ts +372 -0
- package/src/params.ts +111 -0
- package/src/queue.ts +126 -0
- package/src/response.ts +117 -0
- package/src/results.ts +30 -0
- package/src/route-methods.ts +186 -0
- package/src/swagger-schema.ts +213 -0
- package/src/testing.ts +220 -0
- package/src/types/app-builder.interface.ts +19 -0
- package/src/types/application.interface.ts +9 -0
- package/src/utils/hash.ts +5 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/optional-require.ts +50 -0
- package/src/validation.ts +156 -0
- package/src/validator-extend.ts +25 -0
- package/dist/classToOpenapi.d.ts +0 -0
- package/dist/classToOpenapi.js +0 -1
- package/dist/render.d.ts +0 -1
- package/dist/render.js +0 -8
- package/jest.config.ts +0 -9
- package/tsconfig.json +0 -25
- /package/dist/{security.d.ts → utils/hash.d.ts} +0 -0
- /package/dist/{security.js → utils/hash.js} +0 -0
package/dist/index.js
CHANGED
|
@@ -39,7 +39,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
39
39
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
40
|
};
|
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.Container = exports.GetSchema = exports.validateRequestBody = exports.inject = void 0;
|
|
42
|
+
exports.Container = exports.GetSchema = exports.exclude = exports.pick = exports.validateRequestBody = exports.inject = void 0;
|
|
43
43
|
/**
|
|
44
44
|
* @copyright 2024
|
|
45
45
|
* @author Tareq Hossain
|
|
@@ -52,6 +52,8 @@ __exportStar(require("./testing"), exports);
|
|
|
52
52
|
var helpers_1 = require("./helpers");
|
|
53
53
|
Object.defineProperty(exports, "inject", { enumerable: true, get: function () { return helpers_1.inject; } });
|
|
54
54
|
Object.defineProperty(exports, "validateRequestBody", { enumerable: true, get: function () { return helpers_1.validateRequestBody; } });
|
|
55
|
+
Object.defineProperty(exports, "pick", { enumerable: true, get: function () { return helpers_1.pick; } });
|
|
56
|
+
Object.defineProperty(exports, "exclude", { enumerable: true, get: function () { return helpers_1.exclude; } });
|
|
55
57
|
__exportStar(require("./decorators"), exports);
|
|
56
58
|
__exportStar(require("./middleware"), exports);
|
|
57
59
|
__exportStar(require("./config"), exports);
|
|
@@ -64,7 +66,7 @@ __exportStar(require("./validation"), exports);
|
|
|
64
66
|
__exportStar(require("./environment-variables"), exports);
|
|
65
67
|
__exportStar(require("./collection"), exports);
|
|
66
68
|
__exportStar(require("./queue"), exports);
|
|
67
|
-
__exportStar(require("./
|
|
69
|
+
__exportStar(require("./utils/hash"), exports);
|
|
68
70
|
__exportStar(require("./multipart"), exports);
|
|
69
71
|
__exportStar(require("./file-storage"), exports);
|
|
70
72
|
__exportStar(require("./logger"), exports);
|
package/dist/middleware.js
CHANGED
|
@@ -41,14 +41,6 @@ function Middleware(target) {
|
|
|
41
41
|
}
|
|
42
42
|
(0, typedi_1.Service)()(target);
|
|
43
43
|
}
|
|
44
|
-
// export function CurrentUser(): ParameterDecorator {
|
|
45
|
-
// return (target, propertyKey, parameterIndex) => {
|
|
46
|
-
// const existingMetadata =
|
|
47
|
-
// Reflect.getMetadata("currentUser:params", target, propertyKey!) || [];
|
|
48
|
-
// existingMetadata.push(parameterIndex);
|
|
49
|
-
// Reflect.defineMetadata("currentUser:params", existingMetadata, target, propertyKey!);
|
|
50
|
-
// };
|
|
51
|
-
// }
|
|
52
44
|
function UseMiddleware(options) {
|
|
53
45
|
return function (target, propertyKey, descriptor) {
|
|
54
46
|
const normalizeMiddleware = (middleware) => typeof middleware === "function" ? new middleware() : middleware;
|
package/dist/multipart.js
CHANGED
|
@@ -61,7 +61,10 @@ function UploadFileFromRequest(req, options) {
|
|
|
61
61
|
throw new exceptions_1.InternalErrorException("File already exists.");
|
|
62
62
|
}
|
|
63
63
|
await (0, promises_1.pipeline)(f.file, fs_1.default.createWriteStream(fname));
|
|
64
|
-
return
|
|
64
|
+
return {
|
|
65
|
+
...f,
|
|
66
|
+
filename: (options === null || options === void 0 ? void 0 : options.saveAs) ? options.saveAs : f.filename,
|
|
67
|
+
};
|
|
65
68
|
}
|
|
66
69
|
}));
|
|
67
70
|
}
|
package/dist/openapi.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @email xtrinsic96@gmail.com
|
|
5
5
|
* @url https://github.com/xtareq
|
|
6
6
|
*/
|
|
7
|
-
interface InfoObject {
|
|
7
|
+
export interface InfoObject {
|
|
8
8
|
title: string;
|
|
9
9
|
description?: string;
|
|
10
10
|
termsOfService?: string;
|
|
@@ -12,23 +12,23 @@ interface InfoObject {
|
|
|
12
12
|
license?: LicenseObject;
|
|
13
13
|
version: string;
|
|
14
14
|
}
|
|
15
|
-
interface ContactObject {
|
|
15
|
+
export interface ContactObject {
|
|
16
16
|
name?: string;
|
|
17
17
|
url?: string;
|
|
18
18
|
email?: string;
|
|
19
19
|
}
|
|
20
|
-
interface LicenseObject {
|
|
20
|
+
export interface LicenseObject {
|
|
21
21
|
name: string;
|
|
22
22
|
url?: string;
|
|
23
23
|
}
|
|
24
|
-
interface ServerObject {
|
|
24
|
+
export interface ServerObject {
|
|
25
25
|
url: string;
|
|
26
26
|
description?: string;
|
|
27
27
|
variables?: {
|
|
28
28
|
[variable: string]: ServerVariableObject;
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
|
-
interface ServerVariableObject {
|
|
31
|
+
export interface ServerVariableObject {
|
|
32
32
|
enum?: string[];
|
|
33
33
|
default: string;
|
|
34
34
|
description?: string;
|
|
@@ -50,7 +50,7 @@ export type OpenApiUiOptions = {
|
|
|
50
50
|
"x-express-openapi-additional-middleware"?: (((request: any, response: any, next: any) => Promise<void>) | ((request: any, response: any, next: any) => void))[];
|
|
51
51
|
"x-express-openapi-validation-strict"?: boolean;
|
|
52
52
|
};
|
|
53
|
-
interface PathsObject<T extends {} = {}, P extends {} = {}> {
|
|
53
|
+
export interface PathsObject<T extends {} = {}, P extends {} = {}> {
|
|
54
54
|
[pattern: string]: (PathItemObject<T> & P) | undefined;
|
|
55
55
|
}
|
|
56
56
|
declare enum HttpMethods {
|
|
@@ -63,7 +63,7 @@ declare enum HttpMethods {
|
|
|
63
63
|
PATCH = "patch",
|
|
64
64
|
TRACE = "trace"
|
|
65
65
|
}
|
|
66
|
-
type PathItemObject<T extends {} = {}> = {
|
|
66
|
+
export type PathItemObject<T extends {} = {}> = {
|
|
67
67
|
$ref?: string;
|
|
68
68
|
summary?: string;
|
|
69
69
|
description?: string;
|
|
@@ -72,7 +72,7 @@ type PathItemObject<T extends {} = {}> = {
|
|
|
72
72
|
} & {
|
|
73
73
|
[method in HttpMethods]?: OperationObject<T>;
|
|
74
74
|
};
|
|
75
|
-
type OperationObject<T extends {} = {}> = {
|
|
75
|
+
export type OperationObject<T extends {} = {}> = {
|
|
76
76
|
tags?: string[];
|
|
77
77
|
summary?: string;
|
|
78
78
|
description?: string;
|
|
@@ -88,17 +88,17 @@ type OperationObject<T extends {} = {}> = {
|
|
|
88
88
|
security?: SecurityRequirementObject[];
|
|
89
89
|
servers?: ServerObject[];
|
|
90
90
|
} & T;
|
|
91
|
-
interface ExternalDocumentationObject {
|
|
91
|
+
export interface ExternalDocumentationObject {
|
|
92
92
|
description?: string;
|
|
93
93
|
url: string;
|
|
94
94
|
}
|
|
95
|
-
interface ParameterObject extends ParameterBaseObject {
|
|
95
|
+
export interface ParameterObject extends ParameterBaseObject {
|
|
96
96
|
name: string;
|
|
97
97
|
in: string;
|
|
98
98
|
}
|
|
99
|
-
interface HeaderObject extends ParameterBaseObject {
|
|
99
|
+
export interface HeaderObject extends ParameterBaseObject {
|
|
100
100
|
}
|
|
101
|
-
interface ParameterBaseObject {
|
|
101
|
+
export interface ParameterBaseObject {
|
|
102
102
|
description?: string;
|
|
103
103
|
required?: boolean;
|
|
104
104
|
deprecated?: boolean;
|
|
@@ -115,17 +115,17 @@ interface ParameterBaseObject {
|
|
|
115
115
|
[media: string]: MediaTypeObject;
|
|
116
116
|
};
|
|
117
117
|
}
|
|
118
|
-
type NonArraySchemaObjectType = "boolean" | "object" | "number" | "string" | "integer";
|
|
119
|
-
type ArraySchemaObjectType = "array";
|
|
120
|
-
type SchemaObject = ArraySchemaObject | NonArraySchemaObject;
|
|
121
|
-
interface ArraySchemaObject extends BaseSchemaObject {
|
|
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
122
|
type: ArraySchemaObjectType;
|
|
123
123
|
items: ReferenceObject | SchemaObject;
|
|
124
124
|
}
|
|
125
|
-
interface NonArraySchemaObject extends BaseSchemaObject {
|
|
125
|
+
export interface NonArraySchemaObject extends BaseSchemaObject {
|
|
126
126
|
type?: NonArraySchemaObjectType;
|
|
127
127
|
}
|
|
128
|
-
interface BaseSchemaObject {
|
|
128
|
+
export interface BaseSchemaObject {
|
|
129
129
|
title?: string;
|
|
130
130
|
description?: string;
|
|
131
131
|
format?: string;
|
|
@@ -162,29 +162,29 @@ interface BaseSchemaObject {
|
|
|
162
162
|
example?: any;
|
|
163
163
|
deprecated?: boolean;
|
|
164
164
|
}
|
|
165
|
-
interface DiscriminatorObject {
|
|
165
|
+
export interface DiscriminatorObject {
|
|
166
166
|
propertyName: string;
|
|
167
167
|
mapping?: {
|
|
168
168
|
[value: string]: string;
|
|
169
169
|
};
|
|
170
170
|
}
|
|
171
|
-
interface XMLObject {
|
|
171
|
+
export interface XMLObject {
|
|
172
172
|
name?: string;
|
|
173
173
|
namespace?: string;
|
|
174
174
|
prefix?: string;
|
|
175
175
|
attribute?: boolean;
|
|
176
176
|
wrapped?: boolean;
|
|
177
177
|
}
|
|
178
|
-
interface ReferenceObject {
|
|
178
|
+
export interface ReferenceObject {
|
|
179
179
|
$ref: string;
|
|
180
180
|
}
|
|
181
|
-
interface ExampleObject {
|
|
181
|
+
export interface ExampleObject {
|
|
182
182
|
summary?: string;
|
|
183
183
|
description?: string;
|
|
184
184
|
value?: any;
|
|
185
185
|
externalValue?: string;
|
|
186
186
|
}
|
|
187
|
-
interface MediaTypeObject {
|
|
187
|
+
export interface MediaTypeObject {
|
|
188
188
|
schema?: ReferenceObject | SchemaObject;
|
|
189
189
|
example?: any;
|
|
190
190
|
examples?: {
|
|
@@ -194,7 +194,7 @@ interface MediaTypeObject {
|
|
|
194
194
|
[media: string]: EncodingObject;
|
|
195
195
|
};
|
|
196
196
|
}
|
|
197
|
-
interface EncodingObject {
|
|
197
|
+
export interface EncodingObject {
|
|
198
198
|
contentType?: string;
|
|
199
199
|
headers?: {
|
|
200
200
|
[header: string]: ReferenceObject | HeaderObject;
|
|
@@ -203,17 +203,17 @@ interface EncodingObject {
|
|
|
203
203
|
explode?: boolean;
|
|
204
204
|
allowReserved?: boolean;
|
|
205
205
|
}
|
|
206
|
-
interface RequestBodyObject {
|
|
206
|
+
export interface RequestBodyObject {
|
|
207
207
|
description?: string;
|
|
208
208
|
content: {
|
|
209
209
|
[media: string]: MediaTypeObject;
|
|
210
210
|
};
|
|
211
211
|
required?: boolean;
|
|
212
212
|
}
|
|
213
|
-
interface ResponsesObject {
|
|
213
|
+
export interface ResponsesObject {
|
|
214
214
|
[code: string]: ReferenceObject | ResponseObject;
|
|
215
215
|
}
|
|
216
|
-
interface ResponseObject {
|
|
216
|
+
export interface ResponseObject {
|
|
217
217
|
description: string;
|
|
218
218
|
headers?: {
|
|
219
219
|
[header: string]: ReferenceObject | HeaderObject;
|
|
@@ -225,7 +225,7 @@ interface ResponseObject {
|
|
|
225
225
|
[link: string]: ReferenceObject | LinkObject;
|
|
226
226
|
};
|
|
227
227
|
}
|
|
228
|
-
interface LinkObject {
|
|
228
|
+
export interface LinkObject {
|
|
229
229
|
operationRef?: string;
|
|
230
230
|
operationId?: string;
|
|
231
231
|
parameters?: {
|
|
@@ -235,13 +235,13 @@ interface LinkObject {
|
|
|
235
235
|
description?: string;
|
|
236
236
|
server?: ServerObject;
|
|
237
237
|
}
|
|
238
|
-
interface CallbackObject {
|
|
238
|
+
export interface CallbackObject {
|
|
239
239
|
[url: string]: PathItemObject;
|
|
240
240
|
}
|
|
241
|
-
interface SecurityRequirementObject {
|
|
241
|
+
export interface SecurityRequirementObject {
|
|
242
242
|
[name: string]: string[];
|
|
243
243
|
}
|
|
244
|
-
interface ComponentsObject {
|
|
244
|
+
export interface ComponentsObject {
|
|
245
245
|
schemas?: {
|
|
246
246
|
[key: string]: ReferenceObject | SchemaObject;
|
|
247
247
|
};
|
|
@@ -270,20 +270,20 @@ interface ComponentsObject {
|
|
|
270
270
|
[key: string]: ReferenceObject | CallbackObject;
|
|
271
271
|
};
|
|
272
272
|
}
|
|
273
|
-
type SecuritySchemeObject = HttpSecurityScheme | ApiKeySecurityScheme | OAuth2SecurityScheme | OpenIdSecurityScheme;
|
|
274
|
-
interface HttpSecurityScheme {
|
|
273
|
+
export type SecuritySchemeObject = HttpSecurityScheme | ApiKeySecurityScheme | OAuth2SecurityScheme | OpenIdSecurityScheme;
|
|
274
|
+
export interface HttpSecurityScheme {
|
|
275
275
|
type: "http";
|
|
276
276
|
description?: string;
|
|
277
277
|
scheme: string;
|
|
278
278
|
bearerFormat?: string;
|
|
279
279
|
}
|
|
280
|
-
interface ApiKeySecurityScheme {
|
|
280
|
+
export interface ApiKeySecurityScheme {
|
|
281
281
|
type: "apiKey";
|
|
282
282
|
description?: string;
|
|
283
283
|
name: string;
|
|
284
284
|
in: string;
|
|
285
285
|
}
|
|
286
|
-
interface OAuth2SecurityScheme {
|
|
286
|
+
export interface OAuth2SecurityScheme {
|
|
287
287
|
type: "oauth2";
|
|
288
288
|
description?: string;
|
|
289
289
|
flows: {
|
|
@@ -318,12 +318,12 @@ interface OAuth2SecurityScheme {
|
|
|
318
318
|
};
|
|
319
319
|
};
|
|
320
320
|
}
|
|
321
|
-
interface OpenIdSecurityScheme {
|
|
321
|
+
export interface OpenIdSecurityScheme {
|
|
322
322
|
type: "openIdConnect";
|
|
323
323
|
description?: string;
|
|
324
324
|
openIdConnectUrl: string;
|
|
325
325
|
}
|
|
326
|
-
interface TagObject {
|
|
326
|
+
export interface TagObject {
|
|
327
327
|
name: string;
|
|
328
328
|
description?: string;
|
|
329
329
|
externalDocs?: ExternalDocumentationObject;
|
package/dist/params.js
CHANGED
|
@@ -24,8 +24,8 @@ function createParamDecorator(type) {
|
|
|
24
24
|
index: parameterIndex,
|
|
25
25
|
key: key ? key : "all",
|
|
26
26
|
name: paramNames[parameterIndex],
|
|
27
|
-
required: options.required
|
|
28
|
-
validate: options.validate
|
|
27
|
+
required: options.required == undefined ? true : options.required,
|
|
28
|
+
validate: options.validate == undefined ? true : options.validate,
|
|
29
29
|
dataType: (0, helpers_1.getDataType)(paramDataType),
|
|
30
30
|
validatorClass: (0, helpers_1.isClassValidatorClass)(paramDataType),
|
|
31
31
|
schema: (0, helpers_1.isClassValidatorClass)(paramDataType)
|
package/dist/response.js
CHANGED
|
@@ -27,8 +27,12 @@ class HttpResponse {
|
|
|
27
27
|
excludeExtraneousValues: true,
|
|
28
28
|
});
|
|
29
29
|
const transformedResult = isPaginated
|
|
30
|
-
?
|
|
31
|
-
|
|
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
|
+
};
|
|
32
36
|
}
|
|
33
37
|
return { message: "success", data: obj };
|
|
34
38
|
}
|
package/dist/route-methods.js
CHANGED
|
@@ -35,7 +35,7 @@ function createRouteDecorator(method = "GET") {
|
|
|
35
35
|
Reflect.defineMetadata("route:path", path, target, propertyKey);
|
|
36
36
|
Reflect.defineMetadata("route:method", method || "GET", target, propertyKey);
|
|
37
37
|
Reflect.getMetadata(container_1.CONTROLLER_META_KEY, target.constructor);
|
|
38
|
-
Reflect.defineMetadata(container_1.ROUTE_META_KEY,
|
|
38
|
+
Reflect.defineMetadata(container_1.ROUTE_META_KEY, { ...options, method, path, controller: target.constructor.name }, target, propertyKey);
|
|
39
39
|
if (options) {
|
|
40
40
|
Reflect.defineMetadata("route:options", options, target, propertyKey);
|
|
41
41
|
}
|
package/dist/swagger-schema.js
CHANGED
|
@@ -56,7 +56,10 @@ function generateSwaggerSchema(classType) {
|
|
|
56
56
|
}
|
|
57
57
|
// Apply OpenApi metadata if present
|
|
58
58
|
if (openApiMeta) {
|
|
59
|
-
swaggerProperty =
|
|
59
|
+
swaggerProperty = {
|
|
60
|
+
...swaggerProperty,
|
|
61
|
+
...extractOpenApiFields(openApiMeta),
|
|
62
|
+
};
|
|
60
63
|
}
|
|
61
64
|
schema.properties[propertyName] = swaggerProperty;
|
|
62
65
|
});
|
package/dist/testing.js
CHANGED
|
@@ -19,7 +19,10 @@ class AvleonTestUtility {
|
|
|
19
19
|
}
|
|
20
20
|
// Initialize test database if options provided
|
|
21
21
|
if (options === null || options === void 0 ? void 0 : options.dataSourceOptions) {
|
|
22
|
-
this.testDataSource = new typeorm_1.DataSource(
|
|
22
|
+
this.testDataSource = new typeorm_1.DataSource({
|
|
23
|
+
...options.dataSourceOptions,
|
|
24
|
+
logging: false, // Disable logging during tests
|
|
25
|
+
});
|
|
23
26
|
await this.testDataSource.initialize();
|
|
24
27
|
await this.testDataSource.synchronize(true); // Create schema
|
|
25
28
|
}
|
|
@@ -91,7 +94,7 @@ class AvleonTestBuilder {
|
|
|
91
94
|
* @param options Test configuration options
|
|
92
95
|
*/
|
|
93
96
|
setOptions(options) {
|
|
94
|
-
this.testOptions =
|
|
97
|
+
this.testOptions = { ...this.testOptions, ...options };
|
|
95
98
|
return this;
|
|
96
99
|
}
|
|
97
100
|
/**
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./hash"), exports);
|
|
18
|
+
__exportStar(require("./optional-require"), exports);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare function optionalRequire<T = any>(moduleName: string, options?: {
|
|
2
|
+
failOnMissing?: boolean;
|
|
3
|
+
customMessage?: string;
|
|
4
|
+
}): T | undefined;
|
|
5
|
+
export declare function optionalImport<T = any>(moduleName: string, options?: {
|
|
6
|
+
failOnMissing?: boolean;
|
|
7
|
+
customMessage?: string;
|
|
8
|
+
}): Promise<T | undefined>;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.optionalRequire = optionalRequire;
|
|
37
|
+
exports.optionalImport = optionalImport;
|
|
38
|
+
function optionalRequire(moduleName, options = {}) {
|
|
39
|
+
try {
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
41
|
+
return require(moduleName);
|
|
42
|
+
}
|
|
43
|
+
catch (err) {
|
|
44
|
+
if (err.code === "MODULE_NOT_FOUND" && err.message.includes(moduleName)) {
|
|
45
|
+
if (options.failOnMissing) {
|
|
46
|
+
throw new Error(options.customMessage ||
|
|
47
|
+
`Optional dependency "${moduleName}" is not installed.\nInstall it with:\n\n npm install ${moduleName}`);
|
|
48
|
+
}
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
throw err;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async function optionalImport(moduleName, options = {}) {
|
|
55
|
+
try {
|
|
56
|
+
const mod = await Promise.resolve(`${moduleName}`).then(s => __importStar(require(s)));
|
|
57
|
+
return mod;
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
if ((err.code === "ERR_MODULE_NOT_FOUND" || err.code === "MODULE_NOT_FOUND") &&
|
|
61
|
+
err.message.includes(moduleName)) {
|
|
62
|
+
if (options.failOnMissing) {
|
|
63
|
+
throw new Error(options.customMessage ||
|
|
64
|
+
`Optional dependency "${moduleName}" is not installed.\nInstall it with:\n\n npm install ${moduleName}`);
|
|
65
|
+
}
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
throw err;
|
|
69
|
+
}
|
|
70
|
+
}
|
package/dist/validation.d.ts
CHANGED
|
@@ -25,5 +25,8 @@ export type ValidationRule = StringRule | NumberRule | BooleanRule;
|
|
|
25
25
|
export type ValidationProps = {
|
|
26
26
|
[key: string]: ValidationRule;
|
|
27
27
|
};
|
|
28
|
-
export
|
|
28
|
+
export type ValidateOptons = {
|
|
29
|
+
location?: 'header' | 'queryparam' | 'param' | 'body' | 'custom';
|
|
30
|
+
};
|
|
31
|
+
export declare function validateOrThrow<T extends {}>(obj: T, rules: ValidationProps, options?: ValidateOptons): any;
|
|
29
32
|
export {};
|
package/dist/validation.js
CHANGED
|
@@ -16,9 +16,13 @@ class PValidationRule {
|
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
class Validator {
|
|
19
|
-
constructor(obj) {
|
|
19
|
+
constructor(obj, options) {
|
|
20
20
|
this.rules = [];
|
|
21
|
+
this.options = {};
|
|
21
22
|
this.init(obj);
|
|
23
|
+
if (options) {
|
|
24
|
+
this.options = options;
|
|
25
|
+
}
|
|
22
26
|
}
|
|
23
27
|
init(obj) {
|
|
24
28
|
Object.keys(obj).forEach((key) => {
|
|
@@ -26,7 +30,7 @@ class Validator {
|
|
|
26
30
|
this.rules.push(new PValidationRule(key, rule.type, rule.message));
|
|
27
31
|
});
|
|
28
32
|
}
|
|
29
|
-
validate(obj) {
|
|
33
|
+
validate(obj, options) {
|
|
30
34
|
const erors = [];
|
|
31
35
|
this.rules.forEach((k) => {
|
|
32
36
|
const r = Object.keys(obj).find((key) => key == k.name);
|
|
@@ -64,7 +68,8 @@ class Validator {
|
|
|
64
68
|
if (messages.length > 0) {
|
|
65
69
|
erors.push({
|
|
66
70
|
path: k.name,
|
|
67
|
-
|
|
71
|
+
...(this.options.location ? { location: this.options.location } : {}),
|
|
72
|
+
constraints: messages,
|
|
68
73
|
});
|
|
69
74
|
}
|
|
70
75
|
});
|
|
@@ -94,8 +99,8 @@ const parseBoolean = (val) => {
|
|
|
94
99
|
}
|
|
95
100
|
return false; // Default for unsupported types (null, undefined, objects, etc.)
|
|
96
101
|
};
|
|
97
|
-
function validateOrThrow(obj, rules) {
|
|
98
|
-
const valid = new Validator(rules);
|
|
102
|
+
function validateOrThrow(obj, rules, options) {
|
|
103
|
+
const valid = new Validator(rules, options);
|
|
99
104
|
const errors = valid.validate(obj);
|
|
100
105
|
if (errors[0].length > 0) {
|
|
101
106
|
throw new exceptions_1.BadRequestException(errors[0]);
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@avleon/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.24",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"scripts": {
|
|
6
|
-
"build": "
|
|
6
|
+
"build": "npm run clean && tsc",
|
|
7
|
+
"clean": "rm -rf dist",
|
|
7
8
|
"watch": "tsc-watch",
|
|
8
9
|
"test": "jest",
|
|
9
10
|
"test:watch": "jest --watch"
|
|
@@ -31,22 +32,25 @@
|
|
|
31
32
|
"@fastify/static": "^8.1.1",
|
|
32
33
|
"@fastify/swagger": "^9.4.0",
|
|
33
34
|
"@fastify/swagger-ui": "^5.1.0",
|
|
35
|
+
"@fastify/view": "^11.0.0",
|
|
34
36
|
"bcryptjs": "^3.0.2",
|
|
35
37
|
"dotenv": "^16.4.7",
|
|
36
38
|
"fastify": "^5.1.0",
|
|
39
|
+
"highlight.js": "^11.9.0",
|
|
37
40
|
"pino": "^9.6.0",
|
|
38
41
|
"pino-pretty": "^13.0.0",
|
|
39
42
|
"reflect-metadata": "^0.2.2",
|
|
40
43
|
"typedi": "^0.10.0"
|
|
41
44
|
},
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"@scalar/fastify-api-reference": "*"
|
|
47
|
+
},
|
|
48
|
+
"peerDependenciesMeta": {
|
|
49
|
+
"@scalar/fastify-api-reference": {
|
|
50
|
+
"optional": true
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
|
|
50
54
|
"directories": {
|
|
51
55
|
"test": "tests"
|
|
52
56
|
},
|
|
@@ -54,5 +58,9 @@
|
|
|
54
58
|
"repository": {
|
|
55
59
|
"type": "git",
|
|
56
60
|
"url": "git+https://github.com/avleonjs/avleon-core"
|
|
57
|
-
}
|
|
61
|
+
},
|
|
62
|
+
"files": [
|
|
63
|
+
"dist",
|
|
64
|
+
"src"
|
|
65
|
+
]
|
|
58
66
|
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import Container from "typedi";
|
|
2
|
+
import { Constructor } from "./helpers";
|
|
3
|
+
import fastify, { FastifyInstance, RouteShorthandMethod } from "fastify";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
export interface InlineRoutes{
|
|
9
|
+
get: RouteShorthandMethod;
|
|
10
|
+
post: RouteShorthandMethod;
|
|
11
|
+
put: RouteShorthandMethod;
|
|
12
|
+
patch: RouteShorthandMethod;
|
|
13
|
+
delete: RouteShorthandMethod;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
export interface Application{
|
|
18
|
+
|
|
19
|
+
inlineRoutes:() => InlineRoutes;
|
|
20
|
+
mapGroup:(path?: string | RegExp) => InlineRoutes;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Start the application
|
|
24
|
+
* @param port
|
|
25
|
+
* @returns void
|
|
26
|
+
*/
|
|
27
|
+
start:(port?: number)=> void
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface TestApplication{
|
|
31
|
+
getController: <T>(controller: Constructor<T>)=>T;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class IqraTestApplication implements TestApplication{
|
|
36
|
+
|
|
37
|
+
getController<T>(controller: Constructor<T>){
|
|
38
|
+
const con = Container.get(controller);
|
|
39
|
+
return con;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
class IqraApplication implements Application{
|
|
43
|
+
|
|
44
|
+
private app!: FastifyInstance;
|
|
45
|
+
|
|
46
|
+
constructor(){
|
|
47
|
+
if(!this.app){
|
|
48
|
+
this.app = fastify.prototype;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
inlineRoutes() {
|
|
55
|
+
return {
|
|
56
|
+
get: this.app.get,
|
|
57
|
+
post: this.app.post,
|
|
58
|
+
put: this.app.put,
|
|
59
|
+
patch: this.app.patch,
|
|
60
|
+
delete: this.app.delete
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
mapGroup(path?:string|RegExp){
|
|
66
|
+
return this.inlineRoutes();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
start(port?:number){
|
|
71
|
+
const p = port ? port : 4000
|
|
72
|
+
this.app.listen({port:p});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
export class Builder{
|
|
79
|
+
|
|
80
|
+
static createApplication(): Application{
|
|
81
|
+
const app = new IqraApplication();
|
|
82
|
+
return app;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
static createTestApplication(app?: Application): TestApplication {
|
|
86
|
+
const testApp = new IqraTestApplication();
|
|
87
|
+
return testApp;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
const app = Builder.createApplication();
|
|
93
|
+
const route = app.inlineRoutes();
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|