@avleon/core 0.0.8 → 0.0.10

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 (45) hide show
  1. package/dist/authentication.d.ts +6 -0
  2. package/dist/authentication.js +7 -2
  3. package/dist/collection.js +7 -0
  4. package/dist/config.d.ts +7 -1
  5. package/dist/config.js +6 -0
  6. package/dist/container.d.ts +8 -0
  7. package/dist/container.js +9 -1
  8. package/dist/controller.js +6 -0
  9. package/dist/decorators.d.ts +6 -0
  10. package/dist/decorators.js +6 -0
  11. package/dist/environment-variables.d.ts +7 -0
  12. package/dist/environment-variables.js +10 -1
  13. package/dist/exceptions/http-exceptions.d.ts +6 -0
  14. package/dist/exceptions/http-exceptions.js +6 -0
  15. package/dist/exceptions/system-exception.d.ts +6 -0
  16. package/dist/file-storage.d.ts +17 -0
  17. package/dist/file-storage.js +153 -0
  18. package/dist/helpers.js +7 -1
  19. package/dist/icore.d.ts +105 -9
  20. package/dist/icore.js +192 -40
  21. package/dist/index.d.ts +9 -0
  22. package/dist/index.js +9 -1
  23. package/dist/map-types.d.ts +6 -1
  24. package/dist/map-types.js +6 -1
  25. package/dist/middleware.js +6 -0
  26. package/dist/multipart.d.ts +17 -0
  27. package/dist/multipart.js +62 -0
  28. package/dist/openapi.d.ts +6 -0
  29. package/dist/params.js +6 -0
  30. package/dist/queue.d.ts +6 -0
  31. package/dist/queue.js +6 -0
  32. package/dist/response.d.ts +6 -0
  33. package/dist/response.js +8 -1
  34. package/dist/security.d.ts +4 -0
  35. package/dist/security.js +15 -0
  36. package/dist/swagger-schema.d.ts +6 -0
  37. package/dist/swagger-schema.js +6 -0
  38. package/dist/types/app-builder.interface.d.ts +6 -0
  39. package/dist/types/app-builder.interface.js +6 -0
  40. package/dist/types/application.interface.d.ts +6 -0
  41. package/dist/validation.d.ts +6 -0
  42. package/dist/validation.js +6 -0
  43. package/dist/validator-extend.d.ts +6 -0
  44. package/dist/validator-extend.js +6 -0
  45. package/package.json +15 -8
package/dist/icore.js CHANGED
@@ -54,7 +54,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
54
54
  return (mod && mod.__esModule) ? mod : { "default": mod };
55
55
  };
56
56
  Object.defineProperty(exports, "__esModule", { value: true });
57
- exports.Builder = void 0;
57
+ exports.Builder = exports.TestBuilder = void 0;
58
+ /**
59
+ * @copyright 2024
60
+ * @author Tareq Hossain
61
+ * @email xtrinsic96@gmail.com
62
+ * @url https://github.com/xtareq
63
+ */
58
64
  const fastify_1 = __importDefault(require("fastify"));
59
65
  const typedi_1 = __importDefault(require("typedi"));
60
66
  const promises_1 = __importDefault(require("fs/promises"));
@@ -67,6 +73,8 @@ const exceptions_1 = require("./exceptions");
67
73
  const swagger_1 = __importDefault(require("@fastify/swagger"));
68
74
  const config_1 = require("./config");
69
75
  const environment_variables_1 = require("./environment-variables");
76
+ const cors_1 = __importDefault(require("@fastify/cors"));
77
+ const multipart_1 = __importDefault(require("@fastify/multipart"));
70
78
  const isTsNode = process.env.TS_NODE_DEV ||
71
79
  process.env.TS_NODE_PROJECT ||
72
80
  process[Symbol.for("ts-node.register.instance")];
@@ -81,8 +89,10 @@ class AvleonApplication {
81
89
  this.rMap = new Map();
82
90
  this.hasSwagger = false;
83
91
  this.globalSwaggerOptions = {};
92
+ this.dataSourceOptions = undefined;
84
93
  this.controllers = [];
85
94
  this.authorizeMiddleware = undefined;
95
+ this.dataSource = undefined;
86
96
  this.metaCache = new Map();
87
97
  this.app = (0, fastify_1.default)();
88
98
  this.appConfig = new config_1.AppConfig();
@@ -95,6 +105,14 @@ class AvleonApplication {
95
105
  AvleonApplication.buildOptions = buildOptions;
96
106
  if (buildOptions.controllers) {
97
107
  }
108
+ if (buildOptions.dataSourceOptions) {
109
+ AvleonApplication.instance.dataSourceOptions =
110
+ buildOptions.dataSourceOptions;
111
+ const typeorm = require("typeorm");
112
+ const datasource = new typeorm.DataSource(buildOptions.dataSourceOptions);
113
+ typedi_1.default.set("idatasource", datasource);
114
+ AvleonApplication.instance.dataSource = datasource;
115
+ }
98
116
  return AvleonApplication.instance;
99
117
  }
100
118
  isDevelopment() {
@@ -107,8 +125,6 @@ class AvleonApplication {
107
125
  openapi: Object.assign({ openapi: "3.0.0" }, restOptions),
108
126
  });
109
127
  const rPrefix = routePrefix ? routePrefix : "/docs";
110
- //import fastifyApiReference from "@scalar/fastify-api-reference";
111
- //const fastifyApiReference = await require("@scalar/fastify-api-reference");
112
128
  await this.app.register(require("@fastify/swagger-ui"), {
113
129
  logo: logo ? logo : null,
114
130
  theme: theme ? theme : {},
@@ -123,6 +139,9 @@ class AvleonApplication {
123
139
  },
124
140
  });
125
141
  }
142
+ useCors(corsOptions = {}) {
143
+ this.app.register(cors_1.default, corsOptions);
144
+ }
126
145
  useOpenApi(ConfigClass, modifyConfig) {
127
146
  const openApiConfig = this.appConfig.get(ConfigClass);
128
147
  if (modifyConfig) {
@@ -134,10 +153,19 @@ class AvleonApplication {
134
153
  }
135
154
  this.hasSwagger = true;
136
155
  }
156
+ /**
157
+ * @deprecated
158
+ * Will remove in next major version
159
+ */
137
160
  async useSwagger(options) {
138
161
  this.hasSwagger = true;
139
162
  this.globalSwaggerOptions = options;
140
163
  }
164
+ useMultipart(options) {
165
+ this.multipartOptions = options;
166
+ this.app.register(multipart_1.default, options);
167
+ return this;
168
+ }
141
169
  handleMiddlewares(mclasses) {
142
170
  for (const mclass of mclasses) {
143
171
  const cls = typedi_1.default.get(mclass.constructor);
@@ -152,6 +180,11 @@ class AvleonApplication {
152
180
  : [];
153
181
  return [...classMiddlewares, ...methodMiddlewares];
154
182
  }
183
+ /**
184
+ * build controller
185
+ * @param controller
186
+ * @returns void
187
+ */
155
188
  async buildController(controller) {
156
189
  var _a, e_1, _b, _c;
157
190
  const ctrl = typedi_1.default.get(controller);
@@ -239,7 +272,14 @@ class AvleonApplication {
239
272
  finally { if (e_1) throw e_1.error; }
240
273
  }
241
274
  }
275
+ /**
276
+ * map all request parameters
277
+ * @param req
278
+ * @param meta
279
+ * @returns
280
+ */
242
281
  async _mapArgs(req, meta) {
282
+ var _a, e_2, _b, _c;
243
283
  if (!req.hasOwnProperty("_argsCache")) {
244
284
  Object.defineProperty(req, "_argsCache", {
245
285
  value: new Map(),
@@ -257,9 +297,32 @@ class AvleonApplication {
257
297
  meta.currentUser.forEach((user) => (args[user.index] = req.user));
258
298
  meta.headers.forEach((header) => (args[header.index] =
259
299
  header.key === "all" ? req.headers : req.headers[header.key]));
300
+ if (meta.file) {
301
+ try {
302
+ for (var _d = true, _e = __asyncValues(meta.file), _f; _f = await _e.next(), _a = _f.done, !_a; _d = true) {
303
+ _c = _f.value;
304
+ _d = false;
305
+ let f = _c;
306
+ args[f.index] = await req.file();
307
+ }
308
+ }
309
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
310
+ finally {
311
+ try {
312
+ if (!_d && !_a && (_b = _e.return)) await _b.call(_e);
313
+ }
314
+ finally { if (e_2) throw e_2.error; }
315
+ }
316
+ }
260
317
  cache.set(cacheKey, args);
261
318
  return args;
262
319
  }
320
+ /**
321
+ * Process Meta for controlelr class methods
322
+ * @param prototype
323
+ * @param method
324
+ * @returns
325
+ */
263
326
  _processMeta(prototype, method) {
264
327
  const cacheKey = `${prototype.constructor.name}_${method}`;
265
328
  if (this.metaCache.has(cacheKey)) {
@@ -269,6 +332,8 @@ class AvleonApplication {
269
332
  params: Reflect.getMetadata(container_1.PARAM_META_KEY, prototype, method) || [],
270
333
  query: Reflect.getMetadata(container_1.QUERY_META_KEY, prototype, method) || [],
271
334
  body: Reflect.getMetadata(container_1.REQUEST_BODY_META_KEY, prototype, method) || [],
335
+ file: Reflect.getMetadata(container_1.REQUEST_BODY_FILE_KEY, prototype, method) || [],
336
+ files: Reflect.getMetadata(container_1.REQUEST_BODY_FILES_KEY, prototype, method) || [],
272
337
  headers: Reflect.getMetadata(container_1.REQUEST_HEADER_META_KEY, prototype, method) || [],
273
338
  currentUser: Reflect.getMetadata(container_1.REQUEST_USER_META_KEY, prototype, method) || [],
274
339
  // swagger: Reflect.getMetadata("route:openapi", prototype, method) || {}
@@ -310,12 +375,10 @@ class AvleonApplication {
310
375
  this.autoControllers();
311
376
  }
312
377
  }
313
- async handleRoute(args) {
314
- }
378
+ async handleRoute(args) { }
315
379
  async mapFn(fn) {
316
380
  const original = fn;
317
- fn = function () {
318
- };
381
+ fn = function () { };
319
382
  return fn;
320
383
  }
321
384
  useMiddlewares(mclasses) {
@@ -340,7 +403,7 @@ class AvleonApplication {
340
403
  }
341
404
  return {
342
405
  code: 500,
343
- error: "INTERNALERROR",
406
+ error: "INTERNAL_ERROR",
344
407
  message: error.message ? error.message : "Something going wrong.",
345
408
  };
346
409
  }
@@ -378,20 +441,20 @@ class AvleonApplication {
378
441
  const ms = midds.map((mclass) => {
379
442
  const cls = typedi_1.default.get(mclass);
380
443
  this.middlewares.set(mclass.name, cls);
381
- return cls.invoke; // Ensure `invoke` runs in the correct context
444
+ return cls.invoke;
382
445
  });
383
446
  const r = this.rMap.get(routeKey);
384
447
  if (r) {
385
- r.middlewares = ms; // Update middlewares array
448
+ r.middlewares = ms;
386
449
  }
387
- return route; // Ensure chaining by returning the same route object
450
+ return route;
388
451
  },
389
452
  useSwagger: (options) => {
390
453
  const r = this.rMap.get(routeKey);
391
454
  if (r) {
392
- r.schema = options; // Update schema
455
+ r.schema = options;
393
456
  }
394
- return route; // Ensure chaining
457
+ return route;
395
458
  },
396
459
  };
397
460
  return route;
@@ -414,20 +477,19 @@ class AvleonApplication {
414
477
  prefix: options.prefix ? options.prefix : "/static/",
415
478
  });
416
479
  }
480
+ async initializeDatabase() {
481
+ if (this.dataSourceOptions && this.dataSource) {
482
+ await this.dataSource.initialize();
483
+ }
484
+ }
417
485
  async run(port = 4000) {
418
486
  if (this.alreadyRun)
419
487
  throw new system_exception_1.SystemUseError("App already running");
420
488
  this.alreadyRun = true;
421
- if (AvleonApplication.buildOptions.database) {
422
- }
423
- //this.app.swagger();
424
489
  if (this.hasSwagger) {
425
490
  await this.initSwagger(this.globalSwaggerOptions);
426
491
  }
427
492
  await this._mapControllers();
428
- // this.controllers.forEach(controller => {
429
- // this.buildController(controller)
430
- // })
431
493
  this.rMap.forEach((value, key) => {
432
494
  const [m, r] = key.split(":");
433
495
  this.app.route({
@@ -456,16 +518,89 @@ class AvleonApplication {
456
518
  await this.app.listen({ port });
457
519
  console.log(`Application running on http://127.0.0.1:${port}`);
458
520
  }
459
- getTestApp(app) {
460
- return this.app;
521
+ async getTestApp(buildOptions) {
522
+ try {
523
+ if (buildOptions && buildOptions.addDataSource) {
524
+ const typeorm = await Promise.resolve().then(() => __importStar(require("typeorm")));
525
+ if (!typeorm) {
526
+ throw new system_exception_1.SystemUseError("TypeOrm not installed");
527
+ }
528
+ const datasource = new typeorm.DataSource(buildOptions.addDataSource);
529
+ typedi_1.default.set("idatasource", datasource);
530
+ await datasource.initialize();
531
+ }
532
+ this._mapControllers();
533
+ this.rMap.forEach((value, key) => {
534
+ const [m, r] = key.split(":");
535
+ this.app.route({
536
+ method: m,
537
+ url: r,
538
+ schema: value.schema || {},
539
+ preHandler: value.middlewares ? value.middlewares : [],
540
+ handler: async (req, res) => {
541
+ const result = await value.handler.apply(this, [req, res]);
542
+ return result;
543
+ },
544
+ });
545
+ });
546
+ this.app.setErrorHandler(async (error, req, res) => {
547
+ const handledErr = this._handleError(error);
548
+ if (error instanceof exceptions_1.ValidationErrorException) {
549
+ return res.status(handledErr.code).send({
550
+ code: handledErr.code,
551
+ error: handledErr.error,
552
+ errors: handledErr.message,
553
+ });
554
+ }
555
+ return res.status(handledErr.code).send(handledErr);
556
+ });
557
+ return this.app;
558
+ }
559
+ catch (error) {
560
+ throw new system_exception_1.SystemUseError("Can't get test appliction");
561
+ }
461
562
  }
462
563
  }
463
564
  AvleonApplication.buildOptions = {};
464
- // Applciation Builder
565
+ class TestBuilder {
566
+ constructor() { }
567
+ static createBuilder() {
568
+ if (!TestBuilder.instance) {
569
+ TestBuilder.instance = new TestBuilder();
570
+ }
571
+ return TestBuilder.instance;
572
+ }
573
+ getController(controller) {
574
+ return typedi_1.default.get(controller);
575
+ }
576
+ getService(service) {
577
+ return typedi_1.default.get(service);
578
+ }
579
+ async getTestApplication(options) {
580
+ const app = AvleonApplication.getInternalApp({
581
+ dataSourceOptions: this.dataSourceOptions
582
+ });
583
+ app.mapControllers([...options.controllers]);
584
+ const fa = await app.getTestApp();
585
+ return fa;
586
+ }
587
+ build(app) {
588
+ return app.getTestApp();
589
+ }
590
+ fromApplication(app) {
591
+ return app.getTestApp();
592
+ }
593
+ }
594
+ exports.TestBuilder = TestBuilder;
465
595
  class Builder {
466
596
  constructor() {
467
597
  this.alreadyBuilt = false;
468
598
  this.database = false;
599
+ this.testBuilder = false;
600
+ this.appConfig = new config_1.AppConfig();
601
+ }
602
+ getTestApplication() {
603
+ throw new Error("Method not implemented.");
469
604
  }
470
605
  static createAppBuilder() {
471
606
  if (!Builder.instance) {
@@ -473,40 +608,57 @@ class Builder {
473
608
  }
474
609
  return Builder.instance;
475
610
  }
476
- static creatTestApplication() {
611
+ static creatTestAppBuilder() {
477
612
  if (!Builder.instance) {
478
613
  Builder.instance = new Builder();
614
+ Builder.instance.testBuilder = true;
479
615
  }
480
616
  return Builder.instance;
481
617
  }
482
618
  async registerPlugin(plugin, options) {
483
619
  container_1.default.set(plugin, plugin.prototype);
484
620
  }
485
- async addDataSource(config) {
486
- if (this.database) {
487
- throw new system_exception_1.SystemUseError("Datasource already added.");
488
- }
489
- this.database = true;
490
- try {
491
- const typeorm = await Promise.resolve().then(() => __importStar(require("typeorm")));
492
- if (!typeorm) {
493
- throw new system_exception_1.SystemUseError("TypeOrm not installed");
494
- }
495
- const datasource = new typeorm.DataSource(config);
496
- typedi_1.default.set("idatasource", datasource);
497
- this.dataSource = datasource;
498
- await datasource.initialize();
621
+ addDataSource(ConfigClass, modifyConfig) {
622
+ const openApiConfig = this.appConfig.get(ConfigClass);
623
+ if (modifyConfig) {
624
+ const modifiedConfig = modifyConfig(openApiConfig);
625
+ this.dataSourceOptions = modifiedConfig;
499
626
  }
500
- catch (error) {
501
- console.error("Database Initialize Error:", error.message);
627
+ else {
628
+ this.dataSourceOptions = openApiConfig;
502
629
  }
503
630
  }
631
+ createTestApplication(buildOptions) {
632
+ return {
633
+ addDataSource: (dataSourceOptions) => (this.dataSourceOptions = dataSourceOptions),
634
+ getApp: async (options) => {
635
+ const app = AvleonApplication.getInternalApp({
636
+ database: this.database,
637
+ dataSourceOptions: buildOptions.datSource,
638
+ });
639
+ app.mapControllers([...options.controllers]);
640
+ const _tapp = await app.getTestApp();
641
+ return {
642
+ async get(url, options) {
643
+ const res = await _tapp.inject(Object.assign({ url, method: "GET" }, options));
644
+ return res;
645
+ },
646
+ };
647
+ },
648
+ getController(controller) {
649
+ return typedi_1.default.get(controller);
650
+ },
651
+ };
652
+ }
504
653
  build() {
505
- if (this.alreadyBuilt)
654
+ if (this.alreadyBuilt) {
506
655
  throw new Error("Already built");
656
+ }
507
657
  this.alreadyBuilt = true;
508
658
  const app = AvleonApplication.getInternalApp({
509
659
  database: this.database,
660
+ multipartOptions: this.multipartOptions,
661
+ dataSourceOptions: this.dataSourceOptions,
510
662
  });
511
663
  return app;
512
664
  }
package/dist/index.d.ts CHANGED
@@ -1,3 +1,9 @@
1
+ /**
2
+ * @copyright 2024
3
+ * @author Tareq Hossain
4
+ * @email xtrinsic96@gmail.com
5
+ * @url https://github.com/xtareq
6
+ */
1
7
  export * from "./icore";
2
8
  export { inject, validateRequestBody } from "./helpers";
3
9
  export * from "./decorators";
@@ -12,4 +18,7 @@ export * from "./validation";
12
18
  export * from "./environment-variables";
13
19
  export * from "./collection";
14
20
  export * from "./queue";
21
+ export * from "./security";
22
+ export * from "./multipart";
23
+ export * from "./file-storage";
15
24
  export { default as Container } from "./container";
package/dist/index.js CHANGED
@@ -1,4 +1,10 @@
1
1
  "use strict";
2
+ /**
3
+ * @copyright 2024
4
+ * @author Tareq Hossain
5
+ * @email xtrinsic96@gmail.com
6
+ * @url https://github.com/xtareq
7
+ */
2
8
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
9
  if (k2 === undefined) k2 = k;
4
10
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -18,7 +24,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
18
24
  };
19
25
  Object.defineProperty(exports, "__esModule", { value: true });
20
26
  exports.Container = exports.validateRequestBody = exports.inject = void 0;
21
- //export * from "./iqra-core";
22
27
  __exportStar(require("./icore"), exports);
23
28
  var helpers_1 = require("./helpers");
24
29
  Object.defineProperty(exports, "inject", { enumerable: true, get: function () { return helpers_1.inject; } });
@@ -35,5 +40,8 @@ __exportStar(require("./validation"), exports);
35
40
  __exportStar(require("./environment-variables"), exports);
36
41
  __exportStar(require("./collection"), exports);
37
42
  __exportStar(require("./queue"), exports);
43
+ __exportStar(require("./security"), exports);
44
+ __exportStar(require("./multipart"), exports);
45
+ __exportStar(require("./file-storage"), exports);
38
46
  var container_1 = require("./container");
39
47
  Object.defineProperty(exports, "Container", { enumerable: true, get: function () { return __importDefault(container_1).default; } });
@@ -1,4 +1,9 @@
1
- import "reflect-metadata";
1
+ /**
2
+ * @copyright 2024
3
+ * @author Tareq Hossain
4
+ * @email xtrinsic96@gmail.com
5
+ * @url https://github.com/xtareq
6
+ */
2
7
  type Constructor<T = any> = new (...args: any[]) => T;
3
8
  export declare function PartialType<T>(BaseClass: Constructor<T>): Constructor<Partial<T>>;
4
9
  /**
package/dist/map-types.js CHANGED
@@ -1,9 +1,14 @@
1
1
  "use strict";
2
+ /**
3
+ * @copyright 2024
4
+ * @author Tareq Hossain
5
+ * @email xtrinsic96@gmail.com
6
+ * @url https://github.com/xtareq
7
+ */
2
8
  Object.defineProperty(exports, "__esModule", { value: true });
3
9
  exports.PartialType = PartialType;
4
10
  exports.PickType = PickType;
5
11
  exports.OmitType = OmitType;
6
- require("reflect-metadata");
7
12
  function PartialType(BaseClass) {
8
13
  const baseProperties = [];
9
14
  let currentPrototype = BaseClass.prototype;
@@ -5,6 +5,12 @@ exports.Authorize = Authorize;
5
5
  exports.Authorized = Authorized;
6
6
  exports.Middleware = Middleware;
7
7
  exports.UseMiddleware = UseMiddleware;
8
+ /**
9
+ * @copyright 2024
10
+ * @author Tareq Hossain
11
+ * @email xtrinsic96@gmail.com
12
+ * @url https://github.com/xtareq
13
+ */
8
14
  const typedi_1 = require("typedi");
9
15
  const container_1 = require("./container");
10
16
  class AppMiddleware {
@@ -0,0 +1,17 @@
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 } 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;
16
+ export declare function UploadFileFromRequest(req: IRequest, options?: Foptions): Promise<FsM | undefined>;
17
+ export {};
@@ -0,0 +1,62 @@
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({ fieldName, index: parameterIndex });
37
+ Reflect.defineMetadata(container_1.REQUEST_BODY_FILES_KEY, existingMetadata, target, propertyKey);
38
+ };
39
+ }
40
+ function UploadFileFromRequest(req, options) {
41
+ return Promise.resolve(req.file().then(async (f) => {
42
+ if (f && f.file) {
43
+ let fname = f.filename;
44
+ if (options) {
45
+ if (options.dest) {
46
+ fname = options.saveAs ? options.dest + '/' + options.saveAs : options.dest + '/' + f.filename;
47
+ }
48
+ else {
49
+ fname = path_1.default.join(process.cwd(), `public/${options.saveAs ? options.saveAs : f.filename}`);
50
+ }
51
+ }
52
+ else {
53
+ fname = path_1.default.join(process.cwd(), `public/${f.filename}`);
54
+ }
55
+ if (fs_1.default.existsSync(fname)) {
56
+ throw new exceptions_1.InternalErrorException("File already exists.");
57
+ }
58
+ await (0, promises_1.pipeline)(f.file, fs_1.default.createWriteStream(fname));
59
+ return Object.assign(Object.assign({}, f), { filename: (options === null || options === void 0 ? void 0 : options.saveAs) ? options.saveAs : f.filename });
60
+ }
61
+ }));
62
+ }
package/dist/openapi.d.ts CHANGED
@@ -1,3 +1,9 @@
1
+ /**
2
+ * @copyright 2024
3
+ * @author Tareq Hossain
4
+ * @email xtrinsic96@gmail.com
5
+ * @url https://github.com/xtareq
6
+ */
1
7
  interface InfoObject {
2
8
  title: string;
3
9
  description?: string;
package/dist/params.js CHANGED
@@ -1,4 +1,10 @@
1
1
  "use strict";
2
+ /**
3
+ * @copyright 2024
4
+ * @author Tareq Hossain
5
+ * @email xtrinsic96@gmail.com
6
+ * @url https://github.com/xtareq
7
+ */
2
8
  Object.defineProperty(exports, "__esModule", { value: true });
3
9
  exports.AuthUser = exports.Header = exports.Body = exports.Query = exports.Param = void 0;
4
10
  const container_1 = require("./container");
package/dist/queue.d.ts CHANGED
@@ -1,3 +1,9 @@
1
+ /**
2
+ * @copyright 2024
3
+ * @author Tareq Hossain
4
+ * @email xtrinsic96@gmail.com
5
+ * @url https://github.com/xtareq
6
+ */
1
7
  interface Job {
2
8
  id: string;
3
9
  data: any;
package/dist/queue.js CHANGED
@@ -1,4 +1,10 @@
1
1
  "use strict";
2
+ /**
3
+ * @copyright 2024
4
+ * @author Tareq Hossain
5
+ * @email xtrinsic96@gmail.com
6
+ * @url https://github.com/xtareq
7
+ */
2
8
  Object.defineProperty(exports, "__esModule", { value: true });
3
9
  exports.QueueManager = exports.FileQueueAdapter = void 0;
4
10
  const fs_1 = require("fs");
@@ -1,3 +1,9 @@
1
+ /**
2
+ * @copyright 2024
3
+ * @author Tareq Hossain
4
+ * @email xtrinsic96@gmail.com
5
+ * @url https://github.com/xtareq
6
+ */
1
7
  import "reflect-metadata";
2
8
  import { ClassConstructor } from "class-transformer";
3
9
  export interface IHttpResponse<T extends any> {
package/dist/response.js CHANGED
@@ -1,4 +1,10 @@
1
1
  "use strict";
2
+ /**
3
+ * @copyright 2024
4
+ * @author Tareq Hossain
5
+ * @email xtrinsic96@gmail.com
6
+ * @url https://github.com/xtareq
7
+ */
2
8
  Object.defineProperty(exports, "__esModule", { value: true });
3
9
  exports.HttpResponse = void 0;
4
10
  require("reflect-metadata");
@@ -21,7 +27,8 @@ class HttpResponse {
21
27
  enableImplicitConversion: true,
22
28
  excludeExtraneousValues: true, // Ensures only @Expose() properties are included
23
29
  });
24
- return Object.assign({ message: "success" }, (isPaginated ? Object.assign(Object.assign({}, obj), { data: (0, class_transformer_1.instanceToPlain)(transformedData) }) : { data: (0, class_transformer_1.instanceToPlain)(transformedData) }));
30
+ return Object.assign({ message: "success" }, (isPaginated
31
+ ? Object.assign(Object.assign({}, obj), { data: (0, class_transformer_1.instanceToPlain)(transformedData) }) : { data: (0, class_transformer_1.instanceToPlain)(transformedData) }));
25
32
  }
26
33
  return { message: "success", data: obj };
27
34
  }
@@ -0,0 +1,4 @@
1
+ export declare const hashPasswordSync: (password: string) => string;
2
+ export declare const matchPasswordSync: (password: string, hash: string) => boolean;
3
+ export declare const hashPassword: (password: string) => Promise<string>;
4
+ export declare const matchPassword: (password: string, hash: string) => Promise<boolean>;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.matchPassword = exports.hashPassword = exports.matchPasswordSync = exports.hashPasswordSync = void 0;
7
+ const bcryptjs_1 = __importDefault(require("bcryptjs"));
8
+ const hashPasswordSync = (password) => bcryptjs_1.default.hashSync(password, 12);
9
+ exports.hashPasswordSync = hashPasswordSync;
10
+ const matchPasswordSync = (password, hash) => bcryptjs_1.default.compareSync(password, hash);
11
+ exports.matchPasswordSync = matchPasswordSync;
12
+ const hashPassword = (password) => bcryptjs_1.default.hash(password, 12);
13
+ exports.hashPassword = hashPassword;
14
+ const matchPassword = (password, hash) => bcryptjs_1.default.compare(password, hash);
15
+ exports.matchPassword = matchPassword;
@@ -1 +1,7 @@
1
+ /**
2
+ * @copyright 2024
3
+ * @author Tareq Hossain
4
+ * @email xtrinsic96@gmail.com
5
+ * @url https://github.com/xtareq
6
+ */
1
7
  export declare function generateSwaggerSchema(classType: any): any;