@avleon/core 0.0.20 → 0.0.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/README.md +559 -2
  2. package/dist/application.d.ts +47 -0
  3. package/dist/application.js +50 -0
  4. package/dist/cache.d.ts +12 -0
  5. package/dist/cache.js +78 -0
  6. package/dist/collection.js +3 -2
  7. package/dist/container.d.ts +1 -0
  8. package/dist/container.js +2 -1
  9. package/dist/environment-variables.js +1 -1
  10. package/dist/file-storage.js +0 -128
  11. package/dist/helpers.d.ts +2 -0
  12. package/dist/helpers.js +41 -4
  13. package/dist/icore.d.ts +93 -42
  14. package/dist/icore.js +319 -251
  15. package/dist/index.d.ts +2 -2
  16. package/dist/index.js +4 -2
  17. package/dist/middleware.js +0 -8
  18. package/dist/multipart.js +4 -1
  19. package/dist/openapi.d.ts +37 -37
  20. package/dist/params.js +2 -2
  21. package/dist/response.js +6 -2
  22. package/dist/route-methods.js +1 -1
  23. package/dist/swagger-schema.js +4 -1
  24. package/dist/testing.js +6 -3
  25. package/dist/utils/index.d.ts +2 -0
  26. package/dist/utils/index.js +18 -0
  27. package/dist/utils/optional-require.d.ts +8 -0
  28. package/dist/utils/optional-require.js +70 -0
  29. package/dist/validation.d.ts +4 -1
  30. package/dist/validation.js +10 -5
  31. package/package.json +26 -9
  32. package/src/application.ts +125 -0
  33. package/src/authentication.ts +16 -0
  34. package/src/cache.ts +91 -0
  35. package/src/collection.ts +254 -0
  36. package/src/config.ts +42 -0
  37. package/src/constants.ts +1 -0
  38. package/src/container.ts +54 -0
  39. package/src/controller.ts +127 -0
  40. package/src/decorators.ts +27 -0
  41. package/src/environment-variables.ts +46 -0
  42. package/src/exceptions/http-exceptions.ts +86 -0
  43. package/src/exceptions/index.ts +1 -0
  44. package/src/exceptions/system-exception.ts +34 -0
  45. package/src/file-storage.ts +206 -0
  46. package/src/helpers.ts +328 -0
  47. package/src/icore.ts +1140 -0
  48. package/src/index.ts +30 -0
  49. package/src/logger.ts +72 -0
  50. package/src/map-types.ts +159 -0
  51. package/src/middleware.ts +98 -0
  52. package/src/multipart.ts +116 -0
  53. package/src/openapi.ts +372 -0
  54. package/src/params.ts +111 -0
  55. package/src/queue.ts +126 -0
  56. package/src/response.ts +117 -0
  57. package/src/results.ts +30 -0
  58. package/src/route-methods.ts +186 -0
  59. package/src/swagger-schema.ts +213 -0
  60. package/src/testing.ts +220 -0
  61. package/src/types/app-builder.interface.ts +19 -0
  62. package/src/types/application.interface.ts +9 -0
  63. package/src/utils/hash.ts +5 -0
  64. package/src/utils/index.ts +2 -0
  65. package/src/utils/optional-require.ts +50 -0
  66. package/src/validation.ts +156 -0
  67. package/src/validator-extend.ts +25 -0
  68. package/dist/classToOpenapi.d.ts +0 -0
  69. package/dist/classToOpenapi.js +0 -1
  70. package/dist/render.d.ts +0 -1
  71. package/dist/render.js +0 -8
  72. package/jest.config.ts +0 -9
  73. package/tsconfig.json +0 -25
  74. /package/dist/{security.d.ts → utils/hash.d.ts} +0 -0
  75. /package/dist/{security.js → utils/hash.js} +0 -0
package/dist/index.d.ts CHANGED
@@ -7,7 +7,7 @@
7
7
  import * as sw from "./swagger-schema";
8
8
  export * from "./icore";
9
9
  export * from "./testing";
10
- export { inject, validateRequestBody } from "./helpers";
10
+ export { inject, validateRequestBody, pick, exclude } from "./helpers";
11
11
  export * from "./decorators";
12
12
  export * from "./middleware";
13
13
  export * from "./config";
@@ -20,7 +20,7 @@ export * from "./validation";
20
20
  export * from "./environment-variables";
21
21
  export * from "./collection";
22
22
  export * from "./queue";
23
- export * from "./security";
23
+ export * from "./utils/hash";
24
24
  export * from "./multipart";
25
25
  export * from "./file-storage";
26
26
  export * from "./logger";
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("./security"), exports);
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);
@@ -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 Object.assign(Object.assign({}, f), { filename: (options === null || options === void 0 ? void 0 : options.saveAs) ? options.saveAs : f.filename });
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 || false,
28
- validate: options.validate || true,
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
- ? Object.assign(Object.assign({}, obj), { data: (0, class_transformer_1.instanceToPlain)(transformedData) }) : { data: (0, class_transformer_1.instanceToPlain)(transformedData) };
31
- return Object.assign({ message: "success" }, transformedResult);
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
  }
@@ -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, Object.assign(Object.assign({}, options), { method, path, controller: target.constructor.name }), target, propertyKey);
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
  }
@@ -56,7 +56,10 @@ function generateSwaggerSchema(classType) {
56
56
  }
57
57
  // Apply OpenApi metadata if present
58
58
  if (openApiMeta) {
59
- swaggerProperty = Object.assign(Object.assign({}, swaggerProperty), extractOpenApiFields(openApiMeta));
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(Object.assign(Object.assign({}, options.dataSourceOptions), { logging: false }));
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 = Object.assign(Object.assign({}, this.testOptions), options);
97
+ this.testOptions = { ...this.testOptions, ...options };
95
98
  return this;
96
99
  }
97
100
  /**
@@ -112,7 +115,7 @@ class AvleonTestBuilder {
112
115
  dataSourceOptions: this.testOptions.dataSourceOptions,
113
116
  });
114
117
  // Map controllers
115
- app.mapControllers(this.controllers);
118
+ app.useControllers(this.controllers);
116
119
  // Get test application
117
120
  return app.getTestApp();
118
121
  }
@@ -0,0 +1,2 @@
1
+ export * from './hash';
2
+ export * from './optional-require';
@@ -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
+ }
@@ -25,5 +25,8 @@ export type ValidationRule = StringRule | NumberRule | BooleanRule;
25
25
  export type ValidationProps = {
26
26
  [key: string]: ValidationRule;
27
27
  };
28
- export declare function validateOrThrow<T extends {}>(obj: T, rules: ValidationProps): any;
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 {};
@@ -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
- messages: messages,
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,14 +1,16 @@
1
1
  {
2
2
  "name": "@avleon/core",
3
- "version": "0.0.20",
3
+ "version": "0.0.25",
4
4
  "main": "./dist/index.js",
5
+ "types": ["./dist/icore.d.ts"],
5
6
  "scripts": {
6
- "build": "rimraf dist && tsc",
7
+ "build": "npm run clean && tsc",
8
+ "clean": "rimraf dist",
7
9
  "watch": "tsc-watch",
8
10
  "test": "jest",
9
11
  "test:watch": "jest --watch"
10
12
  },
11
- "keywords": [],
13
+ "keywords": ["restapi", "avleon", "backend","fastify"],
12
14
  "author": "Tareq Hossain",
13
15
  "license": "ISC",
14
16
  "devDependencies": {
@@ -16,6 +18,7 @@
16
18
  "@types/node": "^20.17.25",
17
19
  "class-transformer": "^0.5.1",
18
20
  "class-validator": "^0.14.1",
21
+ "ioredis": "^5.6.1",
19
22
  "jest": "^29.7.0",
20
23
  "nodemon": "^3.1.7",
21
24
  "sharp": "^0.33.5",
@@ -31,21 +34,31 @@
31
34
  "@fastify/static": "^8.1.1",
32
35
  "@fastify/swagger": "^9.4.0",
33
36
  "@fastify/swagger-ui": "^5.1.0",
37
+ "@fastify/view": "^11.0.0",
34
38
  "bcryptjs": "^3.0.2",
35
39
  "dotenv": "^16.4.7",
36
40
  "fastify": "^5.1.0",
41
+ "highlight.js": "^11.9.0",
37
42
  "pino": "^9.6.0",
38
43
  "pino-pretty": "^13.0.0",
39
44
  "reflect-metadata": "^0.2.2",
40
45
  "typedi": "^0.10.0"
41
46
  },
42
47
  "peerDependencies": {
43
- "class-transformer": "^0.5.1",
44
- "class-validator": "^0.14.1",
45
- "typeorm": "^0.3.20"
48
+ "@scalar/fastify-api-reference": "*",
49
+ "ioredis": "*",
50
+ "sharp": "*"
46
51
  },
47
- "optionalDependencies": {
48
- "@scalar/fastify-api-reference": "^1.25.119"
52
+ "peerDependenciesMeta": {
53
+ "@scalar/fastify-api-reference": {
54
+ "optional": true
55
+ },
56
+ "ioredis": {
57
+ "optional": true
58
+ },
59
+ "sharp": {
60
+ "optional": true
61
+ }
49
62
  },
50
63
  "directories": {
51
64
  "test": "tests"
@@ -54,5 +67,9 @@
54
67
  "repository": {
55
68
  "type": "git",
56
69
  "url": "git+https://github.com/avleonjs/avleon-core"
57
- }
70
+ },
71
+ "files": [
72
+ "dist",
73
+ "src"
74
+ ]
58
75
  }