@avleon/core 0.0.44 → 0.0.46

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 (58) hide show
  1. package/License +21 -21
  2. package/README.md +667 -681
  3. package/dist/application.test.js +15 -0
  4. package/dist/controller.test.js +0 -14
  5. package/dist/core/application.d.ts +74 -0
  6. package/dist/core/application.js +424 -0
  7. package/dist/core/router.d.ts +44 -0
  8. package/dist/core/router.js +520 -0
  9. package/dist/core/testing.d.ts +21 -0
  10. package/dist/core/testing.js +104 -0
  11. package/dist/core/types.d.ts +67 -0
  12. package/dist/core/types.js +2 -0
  13. package/dist/event-dispatcher.d.ts +0 -1
  14. package/dist/event-dispatcher.js +4 -7
  15. package/dist/file-storage.test.js +15 -2
  16. package/dist/helpers.d.ts +9 -42
  17. package/dist/helpers.js +19 -411
  18. package/dist/index.d.ts +17 -15
  19. package/dist/index.js +18 -22
  20. package/dist/interfaces/avleon-application.d.ts +74 -26
  21. package/dist/interfaces/avleon-application.js +1 -0
  22. package/dist/middleware.d.ts +11 -4
  23. package/dist/middleware.js +9 -0
  24. package/dist/multipart.d.ts +2 -2
  25. package/dist/openapi.d.ts +70 -3
  26. package/dist/openapi.js +32 -0
  27. package/dist/params.js +1 -6
  28. package/dist/params.test.js +8 -8
  29. package/dist/queue.d.ts +27 -36
  30. package/dist/queue.js +67 -99
  31. package/dist/route-methods.js +16 -5
  32. package/dist/swagger-schema.d.ts +11 -17
  33. package/dist/swagger-schema.js +84 -82
  34. package/dist/swagger-schema.test.js +32 -12
  35. package/dist/utils/common-utils.d.ts +17 -0
  36. package/dist/utils/common-utils.js +108 -0
  37. package/dist/utils/di-utils.d.ts +1 -0
  38. package/dist/utils/di-utils.js +22 -0
  39. package/dist/utils/hash.d.ts +0 -2
  40. package/dist/utils/hash.js +1 -5
  41. package/dist/utils/object-utils.d.ts +11 -0
  42. package/dist/utils/object-utils.js +198 -0
  43. package/dist/utils/validation-utils.d.ts +13 -0
  44. package/dist/utils/validation-utils.js +119 -0
  45. package/dist/validation.js +1 -4
  46. package/dist/websocket.d.ts +3 -0
  47. package/dist/websocket.js +2 -1
  48. package/package.json +53 -39
  49. package/dist/application.d.ts +0 -47
  50. package/dist/application.js +0 -50
  51. package/dist/icore.d.ts +0 -226
  52. package/dist/icore.js +0 -968
  53. package/dist/icore.test.js +0 -14
  54. package/dist/queue.test.d.ts +0 -1
  55. package/dist/queue.test.js +0 -79
  56. package/dist/testing.d.ts +0 -55
  57. package/dist/testing.js +0 -196
  58. /package/dist/{icore.test.d.ts → application.test.d.ts} +0 -0
package/dist/index.d.ts CHANGED
@@ -5,28 +5,30 @@
5
5
  * @url https://github.com/xtareq
6
6
  */
7
7
  import * as sw from "./swagger-schema";
8
- export * from "./icore";
9
- export * from "./testing";
10
- export { inject, validateRequestBody, pick, exclude } from "./helpers";
8
+ import "reflect-metadata";
11
9
  export * from "./decorators";
12
- export * from "./middleware";
13
- export * from "./config";
14
- export * from "./openapi";
15
- export * from "./map-types";
10
+ export * from "./interfaces/avleon-application";
11
+ export * from "./core/application";
12
+ export * from "./core/testing";
13
+ export * from "./core/types";
14
+ export * from "./helpers";
16
15
  export * from "./response";
17
16
  export * from "./exceptions";
18
- export * from "./validator-extend";
19
- export * from "./validation";
20
- export * from "./environment-variables";
17
+ export * from "./openapi";
18
+ export * from "./swagger-schema";
19
+ export * from "./container";
20
+ export * from "./middleware";
21
+ export * from "./kenx-provider";
21
22
  export * from "./collection";
23
+ export * from "./event-dispatcher";
24
+ export * from "./event-subscriber";
22
25
  export * from "./queue";
23
- export * from "./utils/hash";
24
- export * from "./multipart";
25
26
  export * from "./file-storage";
27
+ export * from "./config";
26
28
  export * from "./logger";
27
- export * from "./event-dispatcher";
28
- export * from "./kenx-provider";
29
- export { Subscribe, Private } from "./event-subscriber";
29
+ export * from "./cache";
30
+ export * from "./results";
31
+ export * from "./environment-variables";
30
32
  export declare const GetSchema: typeof sw.generateSwaggerSchema;
31
33
  export declare const GetObjectSchema: typeof sw.CreateSwaggerObjectSchema;
32
34
  export declare const OpenApiOk: (args1: any) => {
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.AvleonContainer = exports.OpenApiProperty = exports.OpenApiResponse = exports.OpenApiOk = exports.GetObjectSchema = exports.GetSchema = exports.Private = exports.Subscribe = exports.exclude = exports.pick = exports.validateRequestBody = exports.inject = void 0;
42
+ exports.AvleonContainer = exports.OpenApiProperty = exports.OpenApiResponse = exports.OpenApiOk = exports.GetObjectSchema = exports.GetSchema = void 0;
43
43
  /**
44
44
  * @copyright 2024
45
45
  * @author Tareq Hossain
@@ -47,34 +47,30 @@ exports.AvleonContainer = exports.OpenApiProperty = exports.OpenApiResponse = ex
47
47
  * @url https://github.com/xtareq
48
48
  */
49
49
  const sw = __importStar(require("./swagger-schema"));
50
- __exportStar(require("./icore"), exports);
51
- __exportStar(require("./testing"), exports);
52
- var helpers_1 = require("./helpers");
53
- Object.defineProperty(exports, "inject", { enumerable: true, get: function () { return helpers_1.inject; } });
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; } });
50
+ require("reflect-metadata");
57
51
  __exportStar(require("./decorators"), exports);
58
- __exportStar(require("./middleware"), exports);
59
- __exportStar(require("./config"), exports);
60
- __exportStar(require("./openapi"), exports);
61
- __exportStar(require("./map-types"), exports);
52
+ __exportStar(require("./interfaces/avleon-application"), exports);
53
+ __exportStar(require("./core/application"), exports);
54
+ __exportStar(require("./core/testing"), exports);
55
+ __exportStar(require("./core/types"), exports);
56
+ __exportStar(require("./helpers"), exports);
62
57
  __exportStar(require("./response"), exports);
63
58
  __exportStar(require("./exceptions"), exports);
64
- __exportStar(require("./validator-extend"), exports);
65
- __exportStar(require("./validation"), exports);
66
- __exportStar(require("./environment-variables"), exports);
59
+ __exportStar(require("./openapi"), exports);
60
+ __exportStar(require("./swagger-schema"), exports);
61
+ __exportStar(require("./container"), exports);
62
+ __exportStar(require("./middleware"), exports);
63
+ __exportStar(require("./kenx-provider"), exports);
67
64
  __exportStar(require("./collection"), exports);
65
+ __exportStar(require("./event-dispatcher"), exports);
66
+ __exportStar(require("./event-subscriber"), exports);
68
67
  __exportStar(require("./queue"), exports);
69
- __exportStar(require("./utils/hash"), exports);
70
- __exportStar(require("./multipart"), exports);
71
68
  __exportStar(require("./file-storage"), exports);
69
+ __exportStar(require("./config"), exports);
72
70
  __exportStar(require("./logger"), exports);
73
- __exportStar(require("./event-dispatcher"), exports);
74
- __exportStar(require("./kenx-provider"), exports);
75
- var event_subscriber_1 = require("./event-subscriber");
76
- Object.defineProperty(exports, "Subscribe", { enumerable: true, get: function () { return event_subscriber_1.Subscribe; } });
77
- Object.defineProperty(exports, "Private", { enumerable: true, get: function () { return event_subscriber_1.Private; } });
71
+ __exportStar(require("./cache"), exports);
72
+ __exportStar(require("./results"), exports);
73
+ __exportStar(require("./environment-variables"), exports);
78
74
  exports.GetSchema = sw.generateSwaggerSchema;
79
75
  exports.GetObjectSchema = sw.CreateSwaggerObjectSchema;
80
76
  const OpenApiOk = (args1) => {
@@ -1,27 +1,75 @@
1
- interface AvleonApplication {
2
- useCors: () => void;
3
- /**
4
- * function for register database
5
- * @param options datasource options. options can be plain object or avleon config class
6
- * */
7
- useDatasource: () => void;
8
- useMultipart: () => void;
9
- useOpenApi: () => void;
10
- useMiddlewares: () => void;
11
- useAuthorization: () => void;
12
- useSerialization: () => void;
13
- useControllers: () => void;
14
- useStaticFiles: () => void;
15
- /**
16
- * @experimental
17
- * use https as defalut http protocol
18
- * */
19
- useHttps: () => void;
20
- mapGet: () => void;
21
- mapPost: () => void;
22
- mapPut: () => void;
23
- mapPatch: () => void;
24
- mapOptions: () => void;
25
- mapGroup: () => void;
26
- run: () => void;
1
+ /**
2
+ * @copyright 2024
3
+ * @author Tareq Hossain
4
+ * @email xtrinsic96@gmail.com
5
+ * @url https://github.com/xtareq
6
+ */
7
+ import { Constructor } from "../helpers";
8
+ import { AvleonMiddleware } from "../middleware";
9
+ import { DataSource, DataSourceOptions } from "typeorm";
10
+ import { OpenApiUiOptions } from "../openapi";
11
+ import { FastifyServerOptions, InjectOptions, LightMyRequestResponse } from "fastify";
12
+ export type CorsOptions = {
13
+ origin?: boolean | string | RegExp | (string | RegExp)[] | ((origin: string, cb: (err: Error | null, allow?: boolean) => void) => void);
14
+ methods?: string | string[];
15
+ allowedHeaders?: string | string[];
16
+ exposedHeaders?: string | string[];
17
+ credentials?: boolean;
18
+ maxAge?: number;
19
+ preflight?: boolean;
20
+ strictPreflight?: boolean;
21
+ hideOptionsRoute?: boolean;
22
+ optionsSuccessStatus?: number;
23
+ };
24
+ export type GlobalOptions = {
25
+ cors?: CorsOptions;
26
+ openApi?: OpenApiUiOptions;
27
+ controllers?: any;
28
+ middlewares?: any;
29
+ authorization?: any;
30
+ multipart?: any;
31
+ staticFiles?: any;
32
+ };
33
+ export type AvleonApplicationOptions = {
34
+ server?: FastifyServerOptions;
35
+ dataSourceOptions?: DataSourceOptions;
36
+ };
37
+ export type AutoControllerOptions = {
38
+ auto: true;
39
+ path?: string;
40
+ };
41
+ export interface IAvleonApplication {
42
+ useCors: (options: CorsOptions) => this;
43
+ useDatasource: (dataSource: DataSource) => this;
44
+ useMultipart: (options?: any) => this;
45
+ useOpenApi: (options: OpenApiUiOptions) => this;
46
+ useMiddlewares: (middlewares: Constructor<AvleonMiddleware>[]) => this;
47
+ useAuthorization: (authorization: Constructor<any>) => this;
48
+ useSerialization: () => this;
49
+ useControllers: (controllers: Constructor[] | AutoControllerOptions) => this;
50
+ useStaticFiles: (options: any) => this;
51
+ useHttps: (options?: any) => this;
52
+ useGlobal: (options: GlobalOptions) => this;
53
+ useSocketIo: (options?: any) => this;
54
+ useKnex: (options: any) => this;
55
+ mapFeatures: () => this;
56
+ mapGet: <T extends (...args: any[]) => any>(path: string, fn: T) => any;
57
+ mapPost: <T extends (...args: any[]) => any>(path: string, fn: T) => any;
58
+ mapPut: <T extends (...args: any[]) => any>(path: string, fn: T) => any;
59
+ mapDelete: <T extends (...args: any[]) => any>(path: string, fn: T) => any;
60
+ run: (port?: number, fn?: CallableFunction) => Promise<void>;
27
61
  }
62
+ export type TestResponse = LightMyRequestResponse | Promise<LightMyRequestResponse>;
63
+ export interface TestApplication {
64
+ get: (url: string, options?: InjectOptions) => TestResponse;
65
+ post: (url: string, options?: InjectOptions) => TestResponse;
66
+ put: (url: string, options?: InjectOptions) => TestResponse;
67
+ patch: (url: string, options?: InjectOptions) => TestResponse;
68
+ delete: (url: string, options?: InjectOptions) => TestResponse;
69
+ options: (url: string, options?: InjectOptions) => TestResponse;
70
+ getController: <T>(controller: Constructor<T>, deps?: any[]) => T;
71
+ }
72
+ export type TestAppOptions = {
73
+ controllers: Constructor[] | unknown[];
74
+ dataSource?: DataSourceOptions;
75
+ };
@@ -1 +1,2 @@
1
1
  "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,12 +1,10 @@
1
- import { IRequest, IResponse } from "./icore";
1
+ import { IRequest, IResponse } from "./core/types";
2
2
  import { HttpExceptionTypes as HttpException } from "./exceptions";
3
+ import { Constructor } from "./helpers";
3
4
  export declare abstract class AvleonMiddleware {
4
5
  abstract invoke(req: IRequest, res?: IResponse): Promise<IRequest | HttpException>;
5
6
  }
6
7
  export type AuthHandler = (req: IRequest, roles?: string[]) => Promise<IRequest | HttpException>;
7
- export type Constructor<T> = {
8
- new (...args: any[]): T;
9
- };
10
8
  export declare abstract class AuthorizeMiddleware {
11
9
  abstract authorize(roles: string[]): (req: IRequest, res?: IResponse) => IRequest | Promise<IRequest>;
12
10
  }
@@ -23,5 +21,14 @@ export declare function AppAuthorization(target: {
23
21
  export declare function Authorized(): ClassDecorator & MethodDecorator;
24
22
  export declare function Authorized(options?: any): ClassDecorator & MethodDecorator;
25
23
  export declare function AppMiddleware(target: Constructor<AvleonMiddleware>): void;
24
+ /**
25
+ * A decorator function that applies one or more middleware to a class or a method.
26
+ *
27
+ * When applied to a class, the middleware are registered for the entire controller.
28
+ * When applied to a method, the middleware are registered for that specific route.
29
+ *
30
+ * @param options - A single middleware instance/class or an array of middleware instances/classes to be applied.
31
+ * @returns A decorator that registers the middleware metadata.
32
+ */
26
33
  export declare function UseMiddleware<T extends AvleonMiddleware | (new (...args: any[]) => AvleonMiddleware)>(options: T | T[]): MethodDecorator & ClassDecorator;
27
34
  export {};
@@ -48,6 +48,15 @@ function AppMiddleware(target) {
48
48
  }
49
49
  (0, typedi_1.Service)()(target);
50
50
  }
51
+ /**
52
+ * A decorator function that applies one or more middleware to a class or a method.
53
+ *
54
+ * When applied to a class, the middleware are registered for the entire controller.
55
+ * When applied to a method, the middleware are registered for that specific route.
56
+ *
57
+ * @param options - A single middleware instance/class or an array of middleware instances/classes to be applied.
58
+ * @returns A decorator that registers the middleware metadata.
59
+ */
51
60
  function UseMiddleware(options) {
52
61
  return function (target, propertyKey, descriptor) {
53
62
  const normalizeMiddleware = (middleware) => typeof middleware === "function" ? new middleware() : middleware;
@@ -5,7 +5,7 @@
5
5
  * @url https://github.com/xtareq
6
6
  */
7
7
  import { MultipartFile as FsM, SavedMultipartFile } from "@fastify/multipart";
8
- import { IRequest } from "./icore";
8
+ import { IRequest } from "./core/types";
9
9
  export declare function UploadFile(fieldName: string): (target: any, propertyKey: string | symbol, parameterIndex: number) => void;
10
10
  export declare function UploadFiles(fieldName?: string): (target: any, propertyKey: string | symbol, parameterIndex: number) => void;
11
11
  type Foptions = {
@@ -13,5 +13,5 @@ type Foptions = {
13
13
  dest?: true;
14
14
  };
15
15
  export type MultipartFile = FsM | SavedMultipartFile;
16
- export declare function UploadFileFromRequest(req: IRequest, options?: Foptions): Promise<FsM | undefined>;
16
+ export declare function UploadFileFromRequest(req: IRequest, options?: Foptions): Promise<any>;
17
17
  export {};
package/dist/openapi.d.ts CHANGED
@@ -36,8 +36,10 @@ export interface ServerVariableObject {
36
36
  export type OpenApiUiOptions = {
37
37
  logo?: any;
38
38
  theme?: any;
39
+ provider?: "default" | "scalar";
39
40
  ui?: "default" | "scalar";
40
41
  openapi?: string;
42
+ uiConfig?: any;
41
43
  configuration?: any;
42
44
  routePrefix?: string;
43
45
  info?: InfoObject;
@@ -328,16 +330,81 @@ export interface TagObject {
328
330
  description?: string;
329
331
  externalDocs?: ExternalDocumentationObject;
330
332
  }
333
+ export type ParamSchema = {
334
+ type?: "string" | "number" | "integer" | "boolean" | "array";
335
+ description?: string;
336
+ example?: any;
337
+ required?: boolean;
338
+ deprecated?: boolean;
339
+ enum?: any[];
340
+ format?: string;
341
+ default?: any;
342
+ minimum?: number;
343
+ maximum?: number;
344
+ minLength?: number;
345
+ maxLength?: number;
346
+ pattern?: string;
347
+ };
348
+ export type ParamsSchemaMap = Record<string, ParamSchema>;
349
+ export type RequestBodyOptions = {
350
+ description?: string;
351
+ required?: boolean;
352
+ content?: {
353
+ [media: string]: MediaTypeObject;
354
+ };
355
+ schema?: SchemaObject | ReferenceObject;
356
+ example?: any;
357
+ examples?: Record<string, ExampleObject>;
358
+ };
359
+ export type ResponseBodyOptions = {
360
+ description?: string;
361
+ type?: NonArraySchemaObjectType | ArraySchemaObjectType;
362
+ properties?: {
363
+ [name: string]: ReferenceObject | SchemaObject;
364
+ };
365
+ items?: ReferenceObject | SchemaObject;
366
+ required?: string[];
367
+ schema?: SchemaObject | ReferenceObject;
368
+ example?: any;
369
+ examples?: Record<string, ExampleObject>;
370
+ content?: {
371
+ [media: string]: MediaTypeObject;
372
+ };
373
+ } & Partial<BaseSchemaObject>;
374
+ export type ResponsesOptions = {
375
+ [statusCode: number]: ResponseBodyOptions | ResponseObject;
376
+ };
331
377
  export type OpenApiOptions = {
332
378
  exclude?: boolean;
333
379
  deprecated?: boolean;
334
380
  tags?: readonly string[];
335
381
  description?: string;
336
382
  summary?: string;
383
+ operationId?: string;
384
+ security?: SecurityRequirementObject[];
385
+ externalDocs?: ExternalDocumentationObject;
337
386
  components?: ComponentsObject;
338
- response?: any;
387
+ /** Path parameters e.g. /:id → { id: { type: "string", example: "abc-123" } } */
388
+ params?: ParamsSchemaMap;
389
+ /** Query string parameters e.g. ?page=1 → { page: { type: "integer", example: 1 } } */
390
+ query?: ParamsSchemaMap;
391
+ /** Request headers */
392
+ headers?: ParamsSchemaMap;
393
+ /** Request body */
394
+ requestBody?: RequestBodyOptions;
395
+ /** Responses keyed by HTTP status code */
396
+ response?: ResponsesOptions;
397
+ /** @deprecated use requestBody instead */
339
398
  responseBody?: any;
340
- requestBody?: any;
341
- } & any;
399
+ };
400
+ /**
401
+ * Normalize a flat ParamsSchemaMap into a valid JSON Schema object
402
+ * that Fastify/AJV can validate against.
403
+ *
404
+ * Input: { id: { type: "string", example: "abc-123" } }
405
+ * Output: { type: "object", properties: { id: { type: "string", example: "abc-123" } } }
406
+ */
407
+ export declare function normalizeParamsToJsonSchema(params: ParamsSchemaMap, requiredKeys?: string[]): SchemaObject;
408
+ export declare function OpenApiSchema(): ClassDecorator;
342
409
  export declare function OpenApi(options: OpenApiOptions): MethodDecorator & ClassDecorator & PropertyDecorator;
343
410
  export {};
package/dist/openapi.js CHANGED
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeParamsToJsonSchema = normalizeParamsToJsonSchema;
4
+ exports.OpenApiSchema = OpenApiSchema;
3
5
  exports.OpenApi = OpenApi;
4
6
  var HttpMethods;
5
7
  (function (HttpMethods) {
@@ -12,12 +14,42 @@ var HttpMethods;
12
14
  HttpMethods["PATCH"] = "patch";
13
15
  HttpMethods["TRACE"] = "trace";
14
16
  })(HttpMethods || (HttpMethods = {}));
17
+ /**
18
+ * Normalize a flat ParamsSchemaMap into a valid JSON Schema object
19
+ * that Fastify/AJV can validate against.
20
+ *
21
+ * Input: { id: { type: "string", example: "abc-123" } }
22
+ * Output: { type: "object", properties: { id: { type: "string", example: "abc-123" } } }
23
+ */
24
+ function normalizeParamsToJsonSchema(params, requiredKeys = []) {
25
+ const properties = {};
26
+ for (const [key, val] of Object.entries(params)) {
27
+ properties[key] = {
28
+ type: "string", // sensible default
29
+ ...val,
30
+ };
31
+ }
32
+ const schema = {
33
+ type: "object",
34
+ properties,
35
+ };
36
+ if (requiredKeys.length > 0) {
37
+ schema.required = requiredKeys;
38
+ }
39
+ return schema;
40
+ }
41
+ function OpenApiSchema() {
42
+ return function (target) {
43
+ Reflect.defineMetadata("openapi:schema", true, target);
44
+ };
45
+ }
15
46
  function OpenApi(options) {
16
47
  return function (target, propertyKey, descriptor) {
17
48
  if (typeof target === "function" && !propertyKey) {
18
49
  Reflect.defineMetadata("controller:openapi", options, target);
19
50
  }
20
51
  else if (descriptor) {
52
+ // ✅ Store options as-is — router's buildRouteSchema handles normalization
21
53
  Reflect.defineMetadata("route:openapi", options, target, propertyKey);
22
54
  }
23
55
  else if (propertyKey) {
package/dist/params.js CHANGED
@@ -14,7 +14,6 @@ function createParamDecorator(type) {
14
14
  return function (key, options = {}) {
15
15
  return function (target, propertyKey, parameterIndex) {
16
16
  var _a, _b, _c, _d;
17
- // Determine correct meta key
18
17
  let metaKey;
19
18
  switch (type) {
20
19
  case "route:param":
@@ -35,15 +34,12 @@ function createParamDecorator(type) {
35
34
  default:
36
35
  throw new Error(`Unknown param decorator type: ${String(type)}`);
37
36
  }
38
- // Retrieve and preserve existing metadata
39
37
  const existingParams = Reflect.getMetadata(metaKey, target, propertyKey) || [];
40
38
  // Get parameter names (fallback safe)
41
39
  const functionSource = target[propertyKey].toString();
42
40
  const paramNames = ((_b = (_a = functionSource.match(/\(([^)]*)\)/)) === null || _a === void 0 ? void 0 : _a[1]) === null || _b === void 0 ? void 0 : _b.split(",").map((n) => n.trim())) || [];
43
- // Determine the param type
44
41
  const parameterTypes = Reflect.getMetadata("design:paramtypes", target, propertyKey) || [];
45
42
  const paramDataType = parameterTypes[parameterIndex];
46
- // Append new parameter
47
43
  existingParams.push({
48
44
  index: parameterIndex,
49
45
  key: typeof key === "string" ? key : "all",
@@ -53,11 +49,10 @@ function createParamDecorator(type) {
53
49
  dataType: (0, helpers_1.getDataType)(paramDataType),
54
50
  validatorClass: (0, helpers_1.isClassValidatorClass)(paramDataType),
55
51
  schema: (0, helpers_1.isClassValidatorClass)(paramDataType)
56
- ? (0, swagger_schema_1.generateSwaggerSchema)(paramDataType)
52
+ ? (0, swagger_schema_1.generateClassSchema)(paramDataType)
57
53
  : null,
58
54
  type,
59
55
  });
60
- // Save back using the correct meta key
61
56
  Reflect.defineMetadata(metaKey, existingParams, target, propertyKey);
62
57
  };
63
58
  };
@@ -40,26 +40,26 @@ describe("Parameter Decorators", () => {
40
40
  it("should define metadata for Query decorator", () => {
41
41
  const meta = Reflect.getMetadata(container_1.QUERY_META_KEY, TestController.prototype, "testMethod");
42
42
  expect(meta).toBeDefined();
43
- expect(meta[1].key).toBe("search");
44
- expect(meta[1].type).toBe("route:query");
43
+ expect(meta[0].key).toBe("search");
44
+ expect(meta[0].type).toBe("route:query");
45
45
  });
46
46
  it("should define metadata for Body decorator", () => {
47
47
  const meta = Reflect.getMetadata(container_1.REQUEST_BODY_META_KEY, TestController.prototype, "testMethod");
48
48
  expect(meta).toBeDefined();
49
- expect(meta[2].key).toBe("all");
50
- expect(meta[2].type).toBe("route:body");
49
+ expect(meta[0].key).toBe("all");
50
+ expect(meta[0].type).toBe("route:body");
51
51
  });
52
52
  it("should define metadata for Header decorator", () => {
53
53
  const meta = Reflect.getMetadata(container_1.REQUEST_HEADER_META_KEY, TestController.prototype, "testMethod");
54
54
  expect(meta).toBeDefined();
55
- expect(meta[3].key).toBe("x-token");
56
- expect(meta[3].type).toBe("route:header");
55
+ expect(meta[0].key).toBe("x-token");
56
+ expect(meta[0].type).toBe("route:header");
57
57
  });
58
58
  it("should define metadata for AuthUser decorator", () => {
59
59
  const meta = Reflect.getMetadata(container_1.REQUEST_USER_META_KEY, TestController.prototype, "testMethod");
60
60
  expect(meta).toBeDefined();
61
- expect(meta[4].key).toBe("all");
62
- expect(meta[4].type).toBe("route:user");
61
+ expect(meta[0].key).toBe("all");
62
+ expect(meta[0].type).toBe("route:user");
63
63
  });
64
64
  it("should set required and validate options to true by default", () => {
65
65
  const meta = Reflect.getMetadata(container_1.PARAM_META_KEY, TestController.prototype, "testMethod");
package/dist/queue.d.ts CHANGED
@@ -1,38 +1,29 @@
1
- import { EventEmitter } from "events";
2
- interface Job {
3
- id: string;
4
- data: any;
5
- runAt?: number;
6
- status?: "pending" | "running" | "failed" | "completed";
1
+ import Bull, { Queue as BullQueue, Job, JobOptions } from 'bull';
2
+ export interface QueueConfig {
3
+ name: string;
4
+ adapter?: any;
5
+ handler?: (job: Job) => Promise<any>;
6
+ options?: Bull.QueueOptions;
7
7
  }
8
- interface QueueAdapter {
9
- loadJobs(): Promise<Job[]>;
10
- saveJobs(jobs: Job[]): Promise<void>;
8
+ export declare class AvleonQueue<T = any> {
9
+ protected name?: string | undefined;
10
+ protected adapter?: any | undefined;
11
+ protected queue: BullQueue<T>;
12
+ protected handlerFn?: (job: Job<T>) => Promise<any>;
13
+ constructor(name?: string | undefined, adapter?: any | undefined, handler?: (job: Job<T>) => Promise<any>);
14
+ handler?(job: Job<T>): Promise<any> | any;
15
+ add(data: T, options?: JobOptions): Promise<Bull.Job<T>>;
16
+ delay(data: T, delayMs: number, options?: JobOptions): Promise<Bull.Job<T>>;
17
+ process(handler: (job: Job<T>) => Promise<any>): void;
18
+ processConcurrent(concurrency: number, handler: (job: Job<T>) => Promise<any>): void;
19
+ getQueue(): BullQueue<T>;
20
+ clean(grace: number, status?: 'completed' | 'wait' | 'active' | 'delayed' | 'failed'): Promise<Job[]>;
21
+ close(): Promise<void>;
22
+ pause(): Promise<void>;
23
+ resume(): Promise<void>;
24
+ getJob(jobId: string): Promise<Job<T> | null>;
25
+ getJobs(types: Array<'completed' | 'waiting' | 'active' | 'delayed' | 'failed' | 'paused'>, start?: number, end?: number): Promise<Job<T>[]>;
11
26
  }
12
- export declare class FileQueueAdapter implements QueueAdapter {
13
- private queueFile;
14
- constructor(queueName: string);
15
- loadJobs(): Promise<Job[]>;
16
- saveJobs(jobs: Job[]): Promise<void>;
17
- }
18
- export declare class AvleonQueue extends EventEmitter {
19
- private name;
20
- private processing;
21
- private stopped;
22
- private jobHandler;
23
- private adapter;
24
- constructor(name: string, adapter?: QueueAdapter, jobHandler?: (job: Job) => Promise<void>);
25
- private defaultHandler;
26
- addJob(data: any, options?: {
27
- delay?: number;
28
- }): Promise<void>;
29
- private processNext;
30
- onDone(cb: (job: Job) => void): Promise<void>;
31
- onFailed(cb: (error: any, job: Job) => void): Promise<void>;
32
- getJobs(): Promise<Job[]>;
33
- stop(): Promise<void>;
34
- }
35
- export declare class QueueManager {
36
- from(name: string, jobHandler?: (job: Job) => Promise<void>): Promise<AvleonQueue>;
37
- }
38
- export {};
27
+ export declare function Queue(config: QueueConfig): <T extends {
28
+ new (...args: any[]): AvleonQueue;
29
+ }>(target: T) => T;