@tacxou/nestjs_module_restools 0.0.11

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 (115) hide show
  1. package/.tsbuildinfo +1 -0
  2. package/LICENSE +21 -0
  3. package/README.md +58 -0
  4. package/_abstracts/abstract.controller.d.ts +12 -0
  5. package/_abstracts/abstract.controller.js +15 -0
  6. package/_abstracts/abstract.controller.js.map +1 -0
  7. package/_abstracts/abstract.service.d.ts +21 -0
  8. package/_abstracts/abstract.service.js +38 -0
  9. package/_abstracts/abstract.service.js.map +1 -0
  10. package/_abstracts/index.d.ts +2 -0
  11. package/_abstracts/index.js +19 -0
  12. package/_abstracts/index.js.map +1 -0
  13. package/_decorators/index.d.ts +1 -0
  14. package/_decorators/index.js +18 -0
  15. package/_decorators/index.js.map +1 -0
  16. package/_decorators/real-ip.decorator.d.ts +1 -0
  17. package/_decorators/real-ip.decorator.js +45 -0
  18. package/_decorators/real-ip.decorator.js.map +1 -0
  19. package/_filters/index.d.ts +1 -0
  20. package/_filters/index.js +18 -0
  21. package/_filters/index.js.map +1 -0
  22. package/_filters/mongoose-validation.filter.d.ts +17 -0
  23. package/_filters/mongoose-validation.filter.js +84 -0
  24. package/_filters/mongoose-validation.filter.js.map +1 -0
  25. package/_pipes/dto-validation.pipe.d.ts +15 -0
  26. package/_pipes/dto-validation.pipe.js +60 -0
  27. package/_pipes/dto-validation.pipe.js.map +1 -0
  28. package/_pipes/index.d.ts +2 -0
  29. package/_pipes/index.js +19 -0
  30. package/_pipes/index.js.map +1 -0
  31. package/_pipes/object-id-validation.pipe.d.ts +6 -0
  32. package/_pipes/object-id-validation.pipe.js +56 -0
  33. package/_pipes/object-id-validation.pipe.js.map +1 -0
  34. package/_services/app.cluster.service.d.ts +8 -0
  35. package/_services/app.cluster.service.js +74 -0
  36. package/_services/app.cluster.service.js.map +1 -0
  37. package/_services/index.d.ts +1 -0
  38. package/_services/index.js +18 -0
  39. package/_services/index.js.map +1 -0
  40. package/_utils/memoize.util.d.ts +1 -0
  41. package/_utils/memoize.util.js +20 -0
  42. package/_utils/memoize.util.js.map +1 -0
  43. package/auth/_test/_strategies/local.strategy.d.ts +8 -0
  44. package/auth/_test/_strategies/local.strategy.js +34 -0
  45. package/auth/_test/_strategies/local.strategy.js.map +1 -0
  46. package/auth/_test/test-public.controller.d.ts +4 -0
  47. package/auth/_test/test-public.controller.js +46 -0
  48. package/auth/_test/test-public.controller.js.map +1 -0
  49. package/auth/_test/test.controller.d.ts +3 -0
  50. package/auth/_test/test.controller.js +33 -0
  51. package/auth/_test/test.controller.js.map +1 -0
  52. package/auth/_test/test.module.d.ts +2 -0
  53. package/auth/_test/test.module.js +30 -0
  54. package/auth/_test/test.module.js.map +1 -0
  55. package/auth/auth.guard.d.ts +2 -0
  56. package/auth/auth.guard.js +56 -0
  57. package/auth/auth.guard.js.map +1 -0
  58. package/auth/auth.spec.d.ts +1 -0
  59. package/auth/auth.spec.js +52 -0
  60. package/auth/auth.spec.js.map +1 -0
  61. package/auth/index.d.ts +2 -0
  62. package/auth/index.js +19 -0
  63. package/auth/index.js.map +1 -0
  64. package/auth/public.decorator.d.ts +2 -0
  65. package/auth/public.decorator.js +8 -0
  66. package/auth/public.decorator.js.map +1 -0
  67. package/index.d.ts +8 -0
  68. package/index.js +25 -0
  69. package/index.js.map +1 -0
  70. package/package.json +73 -0
  71. package/request-context/_test/test-context.d.ts +7 -0
  72. package/request-context/_test/test-context.js +11 -0
  73. package/request-context/_test/test-context.js.map +1 -0
  74. package/request-context/_test/test.controller.d.ts +6 -0
  75. package/request-context/_test/test.controller.js +37 -0
  76. package/request-context/_test/test.controller.js.map +1 -0
  77. package/request-context/_test/test.middleware.d.ts +6 -0
  78. package/request-context/_test/test.middleware.js +25 -0
  79. package/request-context/_test/test.middleware.js.map +1 -0
  80. package/request-context/_test/test.module.d.ts +4 -0
  81. package/request-context/_test/test.module.js +28 -0
  82. package/request-context/_test/test.module.js.map +1 -0
  83. package/request-context/_test/test.service.d.ts +5 -0
  84. package/request-context/_test/test.service.js +30 -0
  85. package/request-context/_test/test.service.js.map +1 -0
  86. package/request-context/index.d.ts +3 -0
  87. package/request-context/index.js +20 -0
  88. package/request-context/index.js.map +1 -0
  89. package/request-context/request-context.middleware.d.ts +4 -0
  90. package/request-context/request-context.middleware.js +21 -0
  91. package/request-context/request-context.middleware.js.map +1 -0
  92. package/request-context/request-context.module.d.ts +4 -0
  93. package/request-context/request-context.module.js +24 -0
  94. package/request-context/request-context.module.js.map +1 -0
  95. package/request-context/request-context.spec.d.ts +1 -0
  96. package/request-context/request-context.spec.js +35 -0
  97. package/request-context/request-context.spec.js.map +1 -0
  98. package/request-context/request-context.storage.d.ts +9 -0
  99. package/request-context/request-context.storage.js +16 -0
  100. package/request-context/request-context.storage.js.map +1 -0
  101. package/search-filter-schema/index.d.ts +2 -0
  102. package/search-filter-schema/index.js +19 -0
  103. package/search-filter-schema/index.js.map +1 -0
  104. package/search-filter-schema/search-filter-options.decorator.d.ts +34 -0
  105. package/search-filter-schema/search-filter-options.decorator.js +60 -0
  106. package/search-filter-schema/search-filter-options.decorator.js.map +1 -0
  107. package/search-filter-schema/search-filter-options.decorator.spec.d.ts +1 -0
  108. package/search-filter-schema/search-filter-options.decorator.spec.js +65 -0
  109. package/search-filter-schema/search-filter-options.decorator.spec.js.map +1 -0
  110. package/search-filter-schema/search-filter-schema.decorator.d.ts +32 -0
  111. package/search-filter-schema/search-filter-schema.decorator.js +238 -0
  112. package/search-filter-schema/search-filter-schema.decorator.js.map +1 -0
  113. package/search-filter-schema/search-filter-schema.decorator.spec.d.ts +1 -0
  114. package/search-filter-schema/search-filter-schema.decorator.spec.js +300 -0
  115. package/search-filter-schema/search-filter-schema.decorator.spec.js.map +1 -0
@@ -0,0 +1,20 @@
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("./request-context.middleware"), exports);
18
+ __exportStar(require("./request-context.storage"), exports);
19
+ __exportStar(require("./request-context.module"), exports);
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/request-context/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+DAA4C;AAC5C,4DAAyC;AACzC,2DAAwC"}
@@ -0,0 +1,4 @@
1
+ import { NestMiddleware } from '@nestjs/common';
2
+ export declare class RequestContextMiddleware<Request = any, Response = any> implements NestMiddleware<Request, Response> {
3
+ use(req: Request, res: Response, next: () => void): void;
4
+ }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.RequestContextMiddleware = void 0;
10
+ const common_1 = require("@nestjs/common");
11
+ const request_context_storage_1 = require("./request-context.storage");
12
+ let RequestContextMiddleware = class RequestContextMiddleware {
13
+ use(req, res, next) {
14
+ request_context_storage_1.RequestContextStorage.storage.run(new request_context_storage_1.RequestContextStorage(req, res), next);
15
+ }
16
+ };
17
+ exports.RequestContextMiddleware = RequestContextMiddleware;
18
+ exports.RequestContextMiddleware = RequestContextMiddleware = __decorate([
19
+ (0, common_1.Injectable)()
20
+ ], RequestContextMiddleware);
21
+ //# sourceMappingURL=request-context.middleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-context.middleware.js","sourceRoot":"","sources":["../../src/request-context/request-context.middleware.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA2D;AAC3D,uEAAiE;AAG1D,IAAM,wBAAwB,GAA9B,MAAM,wBAAwB;IAC5B,GAAG,CAAC,GAAY,EAAE,GAAa,EAAE,IAAgB;QACtD,+CAAqB,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,+CAAqB,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,IAAI,CAAC,CAAA;IAC9E,CAAC;CACF,CAAA;AAJY,4DAAwB;mCAAxB,wBAAwB;IADpC,IAAA,mBAAU,GAAE;GACA,wBAAwB,CAIpC"}
@@ -0,0 +1,4 @@
1
+ import { MiddlewareConsumer, NestModule } from '@nestjs/common';
2
+ export declare class RequestContextModule implements NestModule {
3
+ configure(consumer: MiddlewareConsumer): any;
4
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.RequestContextModule = void 0;
10
+ const common_1 = require("@nestjs/common");
11
+ const request_context_middleware_1 = require("./request-context.middleware");
12
+ let RequestContextModule = class RequestContextModule {
13
+ configure(consumer) {
14
+ consumer.apply(request_context_middleware_1.RequestContextMiddleware).forRoutes('*');
15
+ }
16
+ };
17
+ exports.RequestContextModule = RequestContextModule;
18
+ exports.RequestContextModule = RequestContextModule = __decorate([
19
+ (0, common_1.Module)({
20
+ providers: [request_context_middleware_1.RequestContextMiddleware],
21
+ exports: [request_context_middleware_1.RequestContextMiddleware],
22
+ })
23
+ ], RequestContextModule);
24
+ //# sourceMappingURL=request-context.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-context.module.js","sourceRoot":"","sources":["../../src/request-context/request-context.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAuE;AACvE,6EAAuE;AAMhE,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAC/B,SAAS,CAAC,QAA4B;QACpC,QAAQ,CAAC,KAAK,CAAC,qDAAwB,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAA;IACzD,CAAC;CACF,CAAA;AAJY,oDAAoB;+BAApB,oBAAoB;IAJhC,IAAA,eAAM,EAAC;QACN,SAAS,EAAE,CAAC,qDAAwB,CAAC;QACrC,OAAO,EAAE,CAAC,qDAAwB,CAAC;KACpC,CAAC;GACW,oBAAoB,CAIhC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,35 @@
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
+ const testing_1 = require("@nestjs/testing");
7
+ const supertest_1 = __importDefault(require("supertest"));
8
+ const test_module_1 = require("./_test/test.module");
9
+ describe('request-context', () => {
10
+ let app;
11
+ beforeEach(async () => {
12
+ app = (await testing_1.Test.createTestingModule({
13
+ imports: [test_module_1.TestModule],
14
+ }).compile()).createNestApplication();
15
+ await app.init();
16
+ });
17
+ it('should work', () => {
18
+ expect(true).toBe(true);
19
+ });
20
+ it('test with multiples requests same as different requestId count', async () => {
21
+ await (0, supertest_1.default)(app.getHttpServer()).get('/').expect(200, {
22
+ initializationCount: 2,
23
+ requestId: 0,
24
+ });
25
+ await (0, supertest_1.default)(app.getHttpServer()).get('/').expect(200, {
26
+ initializationCount: 2,
27
+ requestId: 1,
28
+ });
29
+ await (0, supertest_1.default)(app.getHttpServer()).get('/').expect(200, {
30
+ initializationCount: 2,
31
+ requestId: 2,
32
+ });
33
+ });
34
+ });
35
+ //# sourceMappingURL=request-context.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-context.spec.js","sourceRoot":"","sources":["../../src/request-context/request-context.spec.ts"],"names":[],"mappings":";;;;;AAAA,6CAAsC;AACtC,0DAA+B;AAE/B,qDAAgD;AAchD,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,IAAI,GAAqB,CAAA;IAEzB,UAAU,CAAC,KAAK,IAAI,EAAE;QACpB,GAAG,GAAG,CACJ,MAAM,cAAI,CAAC,mBAAmB,CAAC;YAC7B,OAAO,EAAE,CAAC,wBAAU,CAAC;SACtB,CAAC,CAAC,OAAO,EAAE,CACb,CAAC,qBAAqB,EAAE,CAAA;QACzB,MAAM,GAAG,CAAC,IAAI,EAAE,CAAA;IAClB,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,aAAa,EAAE,GAAG,EAAE;QACrB,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACzB,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,gEAAgE,EAAE,KAAK,IAAI,EAAE;QAC9E,MAAM,IAAA,mBAAO,EAAC,GAAG,CAAC,aAAa,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,GAAG,EAAE;YACtD,mBAAmB,EAAE,CAAC;YACtB,SAAS,EAAE,CAAC;SACb,CAAC,CAAA;QACF,MAAM,IAAA,mBAAO,EAAC,GAAG,CAAC,aAAa,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,GAAG,EAAE;YACtD,mBAAmB,EAAE,CAAC;YACtB,SAAS,EAAE,CAAC;SACb,CAAC,CAAA;QACF,MAAM,IAAA,mBAAO,EAAC,GAAG,CAAC,aAAa,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,GAAG,EAAE;YACtD,mBAAmB,EAAE,CAAC;YACtB,SAAS,EAAE,CAAC;SACb,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -0,0 +1,9 @@
1
+ /// <reference types="node" />
2
+ import { AsyncLocalStorage } from 'node:async_hooks';
3
+ export declare class RequestContextStorage<TReq = any, TRes = any> {
4
+ readonly req: TReq;
5
+ readonly res: TRes;
6
+ static storage: AsyncLocalStorage<RequestContextStorage<any, any>>;
7
+ constructor(req: TReq, res: TRes);
8
+ static get currentContext(): RequestContextStorage;
9
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RequestContextStorage = void 0;
4
+ const node_async_hooks_1 = require("node:async_hooks");
5
+ class RequestContextStorage {
6
+ constructor(req, res) {
7
+ this.req = req;
8
+ this.res = res;
9
+ }
10
+ static get currentContext() {
11
+ return this.storage.getStore();
12
+ }
13
+ }
14
+ exports.RequestContextStorage = RequestContextStorage;
15
+ RequestContextStorage.storage = new node_async_hooks_1.AsyncLocalStorage();
16
+ //# sourceMappingURL=request-context.storage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-context.storage.js","sourceRoot":"","sources":["../../src/request-context/request-context.storage.ts"],"names":[],"mappings":";;;AAAA,uDAAoD;AAEpD,MAAa,qBAAqB;IAGhC,YAAmC,GAAS,EAAkB,GAAS;QAApC,QAAG,GAAH,GAAG,CAAM;QAAkB,QAAG,GAAH,GAAG,CAAM;IAAI,CAAC;IAErE,MAAM,KAAK,cAAc;QAC9B,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAA;IAChC,CAAC;;AAPH,sDAQC;AAPe,6BAAO,GAAG,IAAI,oCAAiB,EAAyB,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from './search-filter-options.decorator';
2
+ export * from './search-filter-schema.decorator';
@@ -0,0 +1,19 @@
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("./search-filter-options.decorator"), exports);
18
+ __exportStar(require("./search-filter-schema.decorator"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/search-filter-schema/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oEAAiD;AACjD,mEAAgD"}
@@ -0,0 +1,34 @@
1
+ import { ParsedQs } from 'qs';
2
+ export declare const DEFAULT_SEARCH_OPTIONS: {
3
+ loggerType: string;
4
+ defaultLimit: number;
5
+ limitKey: string;
6
+ skipKey: string;
7
+ pageKey: string;
8
+ sortKey: string;
9
+ allowUnlimited: boolean;
10
+ };
11
+ export interface FilterSearchOptions {
12
+ loggerType?: string;
13
+ defaultLimit?: number;
14
+ limitKey?: string;
15
+ skipKey?: string;
16
+ pageKey?: string;
17
+ sortKey?: string;
18
+ allowUnlimited?: boolean;
19
+ }
20
+ export interface SortOptions {
21
+ [key: string]: 'asc' | 'desc' | 1 | -1;
22
+ }
23
+ export declare const DEFAULT_FILTER_OPTIONS: {
24
+ limit: number;
25
+ skip: number;
26
+ sort: {};
27
+ };
28
+ export interface FilterOptions {
29
+ limit: number;
30
+ skip: number;
31
+ sort: SortOptions;
32
+ }
33
+ export declare const SearchFilterOptions: (...dataOrPipes: (import("@nestjs/common").PipeTransform<any, any> | import("@nestjs/common").Type<import("@nestjs/common").PipeTransform<any, any>> | FilterSearchOptions)[]) => ParameterDecorator;
34
+ export declare function filterOptions(queries: string | string[] | ParsedQs | ParsedQs[], options?: FilterSearchOptions): FilterOptions;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.filterOptions = exports.SearchFilterOptions = exports.DEFAULT_FILTER_OPTIONS = exports.DEFAULT_SEARCH_OPTIONS = void 0;
4
+ const common_1 = require("@nestjs/common");
5
+ exports.DEFAULT_SEARCH_OPTIONS = {
6
+ loggerType: 'FilterOptionsControl',
7
+ defaultLimit: 10,
8
+ limitKey: 'limit',
9
+ skipKey: 'skip',
10
+ pageKey: 'page',
11
+ sortKey: 'sort',
12
+ allowUnlimited: false,
13
+ };
14
+ exports.DEFAULT_FILTER_OPTIONS = {
15
+ limit: exports.DEFAULT_SEARCH_OPTIONS.defaultLimit,
16
+ skip: 0,
17
+ sort: {},
18
+ };
19
+ exports.SearchFilterOptions = (0, common_1.createParamDecorator)((options, ctx) => {
20
+ options = Object.assign(Object.assign({}, exports.DEFAULT_SEARCH_OPTIONS), options);
21
+ const req = ctx.switchToHttp().getRequest();
22
+ try {
23
+ return filterOptions(req.query, options);
24
+ }
25
+ catch (error) {
26
+ throw new common_1.BadRequestException(error.message);
27
+ }
28
+ });
29
+ function filterOptions(queries, options) {
30
+ options = Object.assign(Object.assign({}, exports.DEFAULT_SEARCH_OPTIONS), options);
31
+ let limit = parseInt(`${queries[options.limitKey]}`) || options.defaultLimit;
32
+ if (limit === -1 && options.allowUnlimited)
33
+ limit = undefined;
34
+ let skip = parseInt(`${queries[options.skipKey]}`) || 0;
35
+ if (queries[options.pageKey]) {
36
+ if (skip > 0)
37
+ common_1.Logger.debug(`Both ${options.skipKey} and ${options.pageKey} are set. ${options.skipKey} will be ignored`, options.loggerType);
38
+ skip = (parseInt(`${queries[options.pageKey]}`) - 1) * limit;
39
+ }
40
+ const sort = {};
41
+ for (const key in queries[options.sortKey]) {
42
+ switch (`${queries[options.sortKey][key]}`.toLowerCase()) {
43
+ case '1':
44
+ case 'asc':
45
+ sort[key] = 1;
46
+ break;
47
+ case '-1':
48
+ case 'desc':
49
+ sort[key] = -1;
50
+ break;
51
+ }
52
+ }
53
+ return {
54
+ limit,
55
+ skip,
56
+ sort,
57
+ };
58
+ }
59
+ exports.filterOptions = filterOptions;
60
+ //# sourceMappingURL=search-filter-options.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"search-filter-options.decorator.js","sourceRoot":"","sources":["../../src/search-filter-schema/search-filter-options.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAAoG;AAIvF,QAAA,sBAAsB,GAAG;IACpC,UAAU,EAAE,sBAAsB;IAClC,YAAY,EAAE,EAAE;IAChB,QAAQ,EAAE,OAAO;IACjB,OAAO,EAAE,MAAM;IACf,OAAO,EAAE,MAAM;IACf,OAAO,EAAE,MAAM;IACf,cAAc,EAAE,KAAK;CACtB,CAAA;AAgBY,QAAA,sBAAsB,GAAG;IACpC,KAAK,EAAE,8BAAsB,CAAC,YAAY;IAC1C,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,EAAE;CACT,CAAA;AASY,QAAA,mBAAmB,GAAG,IAAA,6BAAoB,EAAC,CAAC,OAA4B,EAAE,GAAqB,EAAiB,EAAE;IAC7H,OAAO,mCAAQ,8BAAsB,GAAK,OAAO,CAAE,CAAA;IACnD,MAAM,GAAG,GAAG,GAAG,CAAC,YAAY,EAAE,CAAC,UAAU,EAAW,CAAA;IAEpD,IAAI,CAAC;QACH,OAAO,aAAa,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;IAC1C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,4BAAmB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IAC9C,CAAC;AACH,CAAC,CAAC,CAAA;AAEF,SAAgB,aAAa,CAC3B,OAAkD,EAClD,OAA6B;IAE7B,OAAO,mCAAQ,8BAAsB,GAAK,OAAO,CAAE,CAAA;IACnD,IAAI,KAAK,GAAG,QAAQ,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,OAAO,CAAC,YAAY,CAAA;IAC5E,IAAI,KAAK,KAAK,CAAC,CAAC,IAAI,OAAO,CAAC,cAAc;QAAE,KAAK,GAAG,SAAS,CAAA;IAC7D,IAAI,IAAI,GAAG,QAAQ,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,CAAA;IAEvD,IAAI,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QAC7B,IAAI,IAAI,GAAG,CAAC;YAAE,eAAM,CAAC,KAAK,CAAC,QAAQ,OAAO,CAAC,OAAO,QAAQ,OAAO,CAAC,OAAO,aAAa,OAAO,CAAC,OAAO,kBAAkB,EAAE,OAAO,CAAC,UAAU,CAAC,CAAA;QAC5I,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,CAAA;IAC9D,CAAC;IAED,MAAM,IAAI,GAAG,EAAE,CAAA;IACf,KAAK,MAAM,GAAG,IAA2B,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QAClE,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC;YACzD,KAAK,GAAG,CAAC;YACT,KAAK,KAAK;gBACR,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;gBACb,MAAK;YAEP,KAAK,IAAI,CAAC;YACV,KAAK,MAAM;gBACT,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAA;gBACd,MAAK;QACT,CAAC;IACH,CAAC;IAED,OAAO;QACL,KAAK;QACL,IAAI;QACJ,IAAI;KACL,CAAA;AACH,CAAC;AAlCD,sCAkCC"}
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const search_filter_options_decorator_1 = require("./search-filter-options.decorator");
4
+ describe('search-filter-options', () => {
5
+ it('should work', () => {
6
+ expect(true).toBe(true);
7
+ });
8
+ it('sort with desc string', () => {
9
+ expect((0, search_filter_options_decorator_1.filterOptions)({
10
+ sort: { 'metadata.lastUpdatedAt': 'desc' },
11
+ })).toStrictEqual(Object.assign(Object.assign({}, search_filter_options_decorator_1.DEFAULT_FILTER_OPTIONS), { sort: { 'metadata.lastUpdatedAt': -1 } }));
12
+ });
13
+ it('sort with desc number', () => {
14
+ expect((0, search_filter_options_decorator_1.filterOptions)({
15
+ sort: { 'metadata.lastUpdatedAt': '-1' },
16
+ })).toStrictEqual(Object.assign(Object.assign({}, search_filter_options_decorator_1.DEFAULT_FILTER_OPTIONS), { sort: { 'metadata.lastUpdatedAt': -1 } }));
17
+ });
18
+ it('sort with asc string', () => {
19
+ expect((0, search_filter_options_decorator_1.filterOptions)({
20
+ sort: { 'metadata.lastUpdatedAt': 'asc' },
21
+ })).toStrictEqual(Object.assign(Object.assign({}, search_filter_options_decorator_1.DEFAULT_FILTER_OPTIONS), { sort: { 'metadata.lastUpdatedAt': 1 } }));
22
+ });
23
+ it('sort with asc number', () => {
24
+ expect((0, search_filter_options_decorator_1.filterOptions)({
25
+ sort: { 'metadata.lastUpdatedAt': '1' },
26
+ })).toStrictEqual(Object.assign(Object.assign({}, search_filter_options_decorator_1.DEFAULT_FILTER_OPTIONS), { sort: { 'metadata.lastUpdatedAt': 1 } }));
27
+ });
28
+ it('limit 69', () => {
29
+ expect((0, search_filter_options_decorator_1.filterOptions)({
30
+ limit: '69',
31
+ })).toStrictEqual(Object.assign(Object.assign({}, search_filter_options_decorator_1.DEFAULT_FILTER_OPTIONS), { limit: 69 }));
32
+ });
33
+ it('skip 71', () => {
34
+ expect((0, search_filter_options_decorator_1.filterOptions)({
35
+ skip: '71',
36
+ })).toStrictEqual(Object.assign(Object.assign({}, search_filter_options_decorator_1.DEFAULT_FILTER_OPTIONS), { skip: 71 }));
37
+ });
38
+ it('skip with other key', () => {
39
+ expect((0, search_filter_options_decorator_1.filterOptions)({
40
+ jump: '71',
41
+ }, { skipKey: 'jump' })).toStrictEqual(Object.assign(Object.assign({}, search_filter_options_decorator_1.DEFAULT_FILTER_OPTIONS), { skip: 71 }));
42
+ });
43
+ it('limit with other key', () => {
44
+ expect((0, search_filter_options_decorator_1.filterOptions)({
45
+ quota: '71',
46
+ }, { limitKey: 'quota' })).toStrictEqual(Object.assign(Object.assign({}, search_filter_options_decorator_1.DEFAULT_FILTER_OPTIONS), { limit: 71 }));
47
+ });
48
+ it('use pagination number', () => {
49
+ expect((0, search_filter_options_decorator_1.filterOptions)({
50
+ page: '42',
51
+ })).toStrictEqual(Object.assign(Object.assign({}, search_filter_options_decorator_1.DEFAULT_FILTER_OPTIONS), { skip: search_filter_options_decorator_1.DEFAULT_FILTER_OPTIONS.limit * 41 }));
52
+ });
53
+ it('use pagination number with other key', () => {
54
+ expect((0, search_filter_options_decorator_1.filterOptions)({
55
+ increment: '11',
56
+ }, { pageKey: 'increment' })).toStrictEqual(Object.assign(Object.assign({}, search_filter_options_decorator_1.DEFAULT_FILTER_OPTIONS), { skip: search_filter_options_decorator_1.DEFAULT_FILTER_OPTIONS.limit * 10 }));
57
+ });
58
+ it('use pagination number and conflict with skip', () => {
59
+ expect((0, search_filter_options_decorator_1.filterOptions)({
60
+ page: '5',
61
+ skip: '50',
62
+ })).toStrictEqual(Object.assign(Object.assign({}, search_filter_options_decorator_1.DEFAULT_FILTER_OPTIONS), { skip: search_filter_options_decorator_1.DEFAULT_FILTER_OPTIONS.limit * 4 }));
63
+ });
64
+ });
65
+ //# sourceMappingURL=search-filter-options.decorator.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"search-filter-options.decorator.spec.js","sourceRoot":"","sources":["../../src/search-filter-schema/search-filter-options.decorator.spec.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,32 @@
1
+ import { ParsedQs } from 'qs';
2
+ export declare const FILTER_SYMBOL_EQUAL = ":";
3
+ export declare const FILTER_SYMBOL_GREATER = ">";
4
+ export declare const FILTER_SYMBOL_LESS = "<";
5
+ export declare const FILTER_SYMBOL_NOT_EQUAL = "!";
6
+ export declare const FILTER_SYMBOL_IN = "@";
7
+ export declare const FILTER_SYMBOL_REGEX = "^";
8
+ export declare const FILTER_SYMBOL_BOOLEAN = "?";
9
+ export declare const FILTER_SYMBOL_NUMBER = "#";
10
+ export declare const DEFAULT_ALLOWED_FILTERS: string[];
11
+ export declare const DEFAULT_SCHEMA_OPTIONS: {
12
+ loggerType: string;
13
+ unsafe: boolean;
14
+ queryKey: string;
15
+ strict: boolean;
16
+ convertNull: boolean;
17
+ convertObjectId: boolean;
18
+ };
19
+ export interface FilterSchemaOptions {
20
+ loggerType?: string;
21
+ dayjsLocale?: string;
22
+ unsafe?: boolean;
23
+ queryKey?: string;
24
+ strict?: boolean;
25
+ convertNull?: boolean;
26
+ convertObjectId?: boolean;
27
+ }
28
+ export interface FilterSchema {
29
+ [key: string | number]: FilterSchema;
30
+ }
31
+ export declare const SearchFilterSchema: (...dataOrPipes: (import("@nestjs/common").PipeTransform<any, any> | import("@nestjs/common").Type<import("@nestjs/common").PipeTransform<any, any>> | FilterSchemaOptions)[]) => ParameterDecorator;
32
+ export declare function filterSchema(filters: string | string[] | ParsedQs | ParsedQs[], options?: FilterSchemaOptions): FilterSchema;
@@ -0,0 +1,238 @@
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 (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.filterSchema = exports.SearchFilterSchema = exports.DEFAULT_SCHEMA_OPTIONS = exports.DEFAULT_ALLOWED_FILTERS = exports.FILTER_SYMBOL_NUMBER = exports.FILTER_SYMBOL_BOOLEAN = exports.FILTER_SYMBOL_REGEX = exports.FILTER_SYMBOL_IN = exports.FILTER_SYMBOL_NOT_EQUAL = exports.FILTER_SYMBOL_LESS = exports.FILTER_SYMBOL_GREATER = exports.FILTER_SYMBOL_EQUAL = void 0;
30
+ const common_1 = require("@nestjs/common");
31
+ const dayjs_1 = __importDefault(require("dayjs"));
32
+ const deepmerge_1 = __importDefault(require("deepmerge"));
33
+ const is_plain_object_1 = require("is-plain-object");
34
+ let ObjectId;
35
+ (async () => {
36
+ try {
37
+ const mongooseModule = await Promise.resolve().then(() => __importStar(require('mongoose')));
38
+ ObjectId = mongooseModule.Types.ObjectId;
39
+ }
40
+ catch (error) {
41
+ common_1.Logger.debug(`Mongoose module not found`, exports.SearchFilterSchema.name);
42
+ }
43
+ })();
44
+ exports.FILTER_SYMBOL_EQUAL = ':';
45
+ exports.FILTER_SYMBOL_GREATER = '>';
46
+ exports.FILTER_SYMBOL_LESS = '<';
47
+ exports.FILTER_SYMBOL_NOT_EQUAL = '!';
48
+ exports.FILTER_SYMBOL_IN = '@';
49
+ exports.FILTER_SYMBOL_REGEX = '^';
50
+ exports.FILTER_SYMBOL_BOOLEAN = '?';
51
+ exports.FILTER_SYMBOL_NUMBER = '#';
52
+ exports.DEFAULT_ALLOWED_FILTERS = [
53
+ exports.FILTER_SYMBOL_EQUAL,
54
+ exports.FILTER_SYMBOL_BOOLEAN,
55
+ exports.FILTER_SYMBOL_NUMBER,
56
+ exports.FILTER_SYMBOL_NOT_EQUAL,
57
+ exports.FILTER_SYMBOL_GREATER,
58
+ exports.FILTER_SYMBOL_LESS,
59
+ exports.FILTER_SYMBOL_REGEX,
60
+ exports.FILTER_SYMBOL_IN,
61
+ ];
62
+ exports.DEFAULT_SCHEMA_OPTIONS = {
63
+ loggerType: 'FilterSchemaControl',
64
+ unsafe: false,
65
+ queryKey: 'filters',
66
+ strict: true,
67
+ convertNull: true,
68
+ convertObjectId: true,
69
+ };
70
+ exports.SearchFilterSchema = (0, common_1.createParamDecorator)((options, ctx) => {
71
+ options = Object.assign(Object.assign({}, exports.DEFAULT_SCHEMA_OPTIONS), options);
72
+ const req = ctx.switchToHttp().getRequest();
73
+ try {
74
+ return filterSchema(req.query[options.queryKey], options);
75
+ }
76
+ catch (error) {
77
+ throw new common_1.BadRequestException(error.message);
78
+ }
79
+ });
80
+ function filterSchema(filters, options) {
81
+ options = Object.assign(Object.assign({}, exports.DEFAULT_SCHEMA_OPTIONS), options);
82
+ let conditions = {};
83
+ if (typeof filters === 'object') {
84
+ for (const key of Object.keys(filters)) {
85
+ const data = filters[key];
86
+ conditions = (0, deepmerge_1.default)(conditions, internalFilterbyType(key, data, exports.DEFAULT_ALLOWED_FILTERS, options), {
87
+ isMergeableObject: is_plain_object_1.isPlainObject,
88
+ });
89
+ }
90
+ }
91
+ return conditions;
92
+ }
93
+ exports.filterSchema = filterSchema;
94
+ function internalFilterbyType(key, data, allowed, options) {
95
+ const parsed = {};
96
+ const keyCheck = key.replace(new RegExp(`[${allowed.join('')}]`, 'g'), '');
97
+ if (keyCheck.length === 0 || (!allowed.includes(key[0]) && !/[a-zA-Z0-9-_]/.test(key[0])))
98
+ return {};
99
+ switch (key[0]) {
100
+ case exports.FILTER_SYMBOL_BOOLEAN: {
101
+ parsed[key.slice(1)] = /true|on|yes|1/i.test(data);
102
+ break;
103
+ }
104
+ case exports.FILTER_SYMBOL_NUMBER: {
105
+ const valueHashtag = Number(data);
106
+ if (isNaN(valueHashtag)) {
107
+ if (options.strict)
108
+ throw new Error(`Invalid filter key ${keyCheck} with number: ${data}`);
109
+ common_1.Logger.verbose(`Invalid filter key ${keyCheck} with number: ${data}`, options.loggerType);
110
+ break;
111
+ }
112
+ parsed[key.slice(1)] = valueHashtag;
113
+ break;
114
+ }
115
+ case exports.FILTER_SYMBOL_NOT_EQUAL: {
116
+ const valueExclamation = internalFilterbyType(key.slice(1), data, [
117
+ exports.FILTER_SYMBOL_NUMBER,
118
+ exports.FILTER_SYMBOL_IN,
119
+ exports.FILTER_SYMBOL_EQUAL,
120
+ ], options);
121
+ if (Object.keys(valueExclamation).length === 0)
122
+ break;
123
+ const typeExclamation = Object.keys(valueExclamation[keyCheck] || {})[0];
124
+ if (typeExclamation === '$in') {
125
+ parsed[keyCheck] = { $nin: valueExclamation[keyCheck]['$in'] };
126
+ break;
127
+ }
128
+ parsed[keyCheck] = { $ne: valueExclamation[keyCheck] };
129
+ break;
130
+ }
131
+ case exports.FILTER_SYMBOL_LESS:
132
+ case exports.FILTER_SYMBOL_GREATER: {
133
+ let upperLowerType = key[0] === exports.FILTER_SYMBOL_GREATER ? '$gt' : '$lt';
134
+ if (key[1] === '|')
135
+ upperLowerType = `${upperLowerType}e`;
136
+ const upperLowerKey = key.slice(upperLowerType.length - 2);
137
+ const valueGreater = internalFiltersByTypeUpperLower(upperLowerType, upperLowerKey, data, options);
138
+ if (Object.keys(valueGreater).length === 0)
139
+ break;
140
+ const subKeyGreater = Object.keys(valueGreater)[0];
141
+ parsed[subKeyGreater] = valueGreater[subKeyGreater];
142
+ break;
143
+ }
144
+ case exports.FILTER_SYMBOL_REGEX: {
145
+ const re = data.trim().split('/');
146
+ if (re[0] !== '' || re.length < 3) {
147
+ if (options.strict)
148
+ throw new Error(`Invalid filter key ${keyCheck} with regex: ${data}`);
149
+ common_1.Logger.verbose(`Invalid filter key ${keyCheck} with regex: ${data}`, options.loggerType);
150
+ break;
151
+ }
152
+ re.shift();
153
+ const $options = re.pop();
154
+ parsed[key.slice(1)] = { $regex: re.join('') };
155
+ if ($options)
156
+ parsed[key.slice(1)]['$options'] = $options;
157
+ break;
158
+ }
159
+ case exports.FILTER_SYMBOL_IN: {
160
+ let subKeyAt;
161
+ const $in = [];
162
+ if (!Array.isArray(data)) {
163
+ if (options.strict)
164
+ throw new Error(`Invalid filter key ${keyCheck} with bad array: ${data}`);
165
+ common_1.Logger.verbose(`Invalid filter key ${keyCheck} with bad array: ${data}`, options.loggerType);
166
+ break;
167
+ }
168
+ for (const d of data) {
169
+ const valueAt = internalFilterbyType(key.slice(1), d, [exports.FILTER_SYMBOL_NUMBER], options);
170
+ if (Object.keys(valueAt).length === 0)
171
+ break;
172
+ subKeyAt = Object.keys(valueAt)[0];
173
+ $in.push(valueAt[subKeyAt]);
174
+ }
175
+ if (!subKeyAt) {
176
+ if (options.strict)
177
+ throw new Error(`Invalid filter key ${keyCheck} with array: ${JSON.stringify(data)}`);
178
+ common_1.Logger.verbose(`Invalid filter key ${keyCheck} with array: ${JSON.stringify(data)}`, options.loggerType);
179
+ break;
180
+ }
181
+ parsed[subKeyAt] = { $in };
182
+ break;
183
+ }
184
+ case exports.FILTER_SYMBOL_EQUAL: {
185
+ if (Array.isArray(data)) {
186
+ if (options.strict)
187
+ throw new Error(`Invalid filter key ${keyCheck} with strict array: ${JSON.stringify(data)}`);
188
+ common_1.Logger.verbose(`Invalid filter key ${keyCheck} with strict string: ${JSON.stringify(data)}`, options.loggerType);
189
+ break;
190
+ }
191
+ if (options.convertObjectId && ObjectId.isValid(data)) {
192
+ parsed[key.slice(1)] = new ObjectId(data);
193
+ break;
194
+ }
195
+ if (options.convertNull && data === 'null') {
196
+ parsed[key.slice(1)] = null;
197
+ break;
198
+ }
199
+ parsed[key.slice(1)] = `${data}`;
200
+ break;
201
+ }
202
+ default: {
203
+ if (!options.unsafe && Array.isArray(data)) {
204
+ if (options.strict)
205
+ throw new Error(`Invalid filter key ${keyCheck} with unsafe: ${JSON.stringify(data)}`);
206
+ common_1.Logger.verbose(`Invalid filter key ${keyCheck} with unsafe: ${JSON.stringify(data)}`, options.loggerType);
207
+ break;
208
+ }
209
+ parsed[key] = data;
210
+ break;
211
+ }
212
+ }
213
+ return parsed;
214
+ }
215
+ function internalFiltersByTypeUpperLower(type, key, data, options) {
216
+ const parsed = {};
217
+ if (key[0] !== exports.FILTER_SYMBOL_NUMBER) {
218
+ const dayjsDate = (0, dayjs_1.default)(data, options.dayjsLocale);
219
+ if (!dayjsDate.isValid() || dayjsDate.toDate().toString() === 'Invalid Date') {
220
+ if (options.strict)
221
+ throw new Error(`Invalid filter key ${key} with date: ${data}`);
222
+ common_1.Logger.verbose(`Invalid filter key ${key} with date: ${data}`, options.loggerType);
223
+ return {};
224
+ }
225
+ parsed[key] = {};
226
+ parsed[key][type] = dayjsDate.toDate();
227
+ return parsed;
228
+ }
229
+ const value = internalFilterbyType(key, data, [exports.FILTER_SYMBOL_NUMBER], options);
230
+ if (Object.keys(value).length === 0)
231
+ return {};
232
+ const subKey = Object.keys(value)[0];
233
+ parsed[subKey] = {};
234
+ parsed[subKey][type] = {};
235
+ parsed[subKey][type] = value[subKey];
236
+ return parsed;
237
+ }
238
+ //# sourceMappingURL=search-filter-schema.decorator.js.map