@solid-nestjs/common 0.2.6 → 0.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/index.d.ts +7 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +23 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/validation.adapter.d.ts +20 -0
- package/dist/adapters/validation.adapter.d.ts.map +1 -0
- package/dist/adapters/validation.adapter.js +309 -0
- package/dist/adapters/validation.adapter.js.map +1 -0
- package/dist/decorator-registry/decorator-registry.d.ts +54 -0
- package/dist/decorator-registry/decorator-registry.d.ts.map +1 -0
- package/dist/decorator-registry/decorator-registry.js +161 -0
- package/dist/decorator-registry/decorator-registry.js.map +1 -0
- package/dist/decorator-registry/index.d.ts +2 -0
- package/dist/decorator-registry/index.d.ts.map +1 -0
- package/dist/decorator-registry/index.js +18 -0
- package/dist/decorator-registry/index.js.map +1 -0
- package/dist/decorators/index.d.ts +6 -0
- package/dist/decorators/index.d.ts.map +1 -1
- package/dist/decorators/index.js +6 -0
- package/dist/decorators/index.js.map +1 -1
- package/dist/decorators/solid-entity.decorator.d.ts +6 -0
- package/dist/decorators/solid-entity.decorator.d.ts.map +1 -0
- package/dist/decorators/solid-entity.decorator.js +23 -0
- package/dist/decorators/solid-entity.decorator.js.map +1 -0
- package/dist/decorators/solid-field.decorator.d.ts +7 -0
- package/dist/decorators/solid-field.decorator.d.ts.map +1 -0
- package/dist/decorators/solid-field.decorator.js +51 -0
- package/dist/decorators/solid-field.decorator.js.map +1 -0
- package/dist/decorators/solid-id.decorator.d.ts +9 -0
- package/dist/decorators/solid-id.decorator.d.ts.map +1 -0
- package/dist/decorators/solid-id.decorator.js +27 -0
- package/dist/decorators/solid-id.decorator.js.map +1 -0
- package/dist/decorators/solid-input.decorator.d.ts +6 -0
- package/dist/decorators/solid-input.decorator.d.ts.map +1 -0
- package/dist/decorators/solid-input.decorator.js +35 -0
- package/dist/decorators/solid-input.decorator.js.map +1 -0
- package/dist/decorators/solid-relation.decorator.d.ts +19 -0
- package/dist/decorators/solid-relation.decorator.d.ts.map +1 -0
- package/dist/decorators/solid-relation.decorator.js +66 -0
- package/dist/decorators/solid-relation.decorator.js.map +1 -0
- package/dist/decorators/solid-timestamp.decorator.d.ts +13 -0
- package/dist/decorators/solid-timestamp.decorator.d.ts.map +1 -0
- package/dist/decorators/solid-timestamp.decorator.js +49 -0
- package/dist/decorators/solid-timestamp.decorator.js.map +1 -0
- package/dist/enums/aggregate-function.enum.d.ts +42 -0
- package/dist/enums/aggregate-function.enum.d.ts.map +1 -0
- package/dist/enums/aggregate-function.enum.js +46 -0
- package/dist/enums/aggregate-function.enum.js.map +1 -0
- package/dist/enums/index.d.ts +1 -0
- package/dist/enums/index.d.ts.map +1 -1
- package/dist/enums/index.js +1 -0
- package/dist/enums/index.js.map +1 -1
- package/dist/helpers/args-helpers/class-generator.helper.d.ts +143 -0
- package/dist/helpers/args-helpers/class-generator.helper.d.ts.map +1 -0
- package/dist/helpers/args-helpers/class-generator.helper.js +221 -0
- package/dist/helpers/args-helpers/class-generator.helper.js.map +1 -0
- package/dist/helpers/args-helpers/create-groupby-request.helper.d.ts +83 -0
- package/dist/helpers/args-helpers/create-groupby-request.helper.d.ts.map +1 -0
- package/dist/helpers/args-helpers/create-groupby-request.helper.js +119 -0
- package/dist/helpers/args-helpers/create-groupby-request.helper.js.map +1 -0
- package/dist/helpers/args-helpers/decorator-builder.helper.d.ts +160 -0
- package/dist/helpers/args-helpers/decorator-builder.helper.d.ts.map +1 -0
- package/dist/helpers/args-helpers/decorator-builder.helper.js +161 -0
- package/dist/helpers/args-helpers/decorator-builder.helper.js.map +1 -0
- package/dist/helpers/args-helpers/field-config.helper.d.ts +98 -0
- package/dist/helpers/args-helpers/field-config.helper.d.ts.map +1 -0
- package/dist/helpers/args-helpers/field-config.helper.js +143 -0
- package/dist/helpers/args-helpers/field-config.helper.js.map +1 -0
- package/dist/helpers/args-helpers/groupby-args-from.helper.d.ts +87 -0
- package/dist/helpers/args-helpers/groupby-args-from.helper.d.ts.map +1 -0
- package/dist/helpers/args-helpers/groupby-args-from.helper.js +185 -0
- package/dist/helpers/args-helpers/groupby-args-from.helper.js.map +1 -0
- package/dist/helpers/args-helpers/index.d.ts +15 -0
- package/dist/helpers/args-helpers/index.d.ts.map +1 -0
- package/dist/helpers/args-helpers/index.js +58 -0
- package/dist/helpers/args-helpers/index.js.map +1 -0
- package/dist/helpers/args-helpers/type-inference.helper.d.ts +191 -0
- package/dist/helpers/args-helpers/type-inference.helper.d.ts.map +1 -0
- package/dist/helpers/args-helpers/type-inference.helper.js +330 -0
- package/dist/helpers/args-helpers/type-inference.helper.js.map +1 -0
- package/dist/helpers/class-generation/dynamic-class.helper.d.ts +101 -0
- package/dist/helpers/class-generation/dynamic-class.helper.d.ts.map +1 -0
- package/dist/helpers/class-generation/dynamic-class.helper.js +180 -0
- package/dist/helpers/class-generation/dynamic-class.helper.js.map +1 -0
- package/dist/helpers/class-generation/index.d.ts +9 -0
- package/dist/helpers/class-generation/index.d.ts.map +1 -0
- package/dist/helpers/class-generation/index.js +18 -0
- package/dist/helpers/class-generation/index.js.map +1 -0
- package/dist/helpers/decorators/decorator-utils.helper.d.ts +75 -0
- package/dist/helpers/decorators/decorator-utils.helper.d.ts.map +1 -0
- package/dist/helpers/decorators/decorator-utils.helper.js +92 -0
- package/dist/helpers/decorators/decorator-utils.helper.js.map +1 -0
- package/dist/helpers/decorators/index.d.ts +9 -0
- package/dist/helpers/decorators/index.d.ts.map +1 -0
- package/dist/helpers/decorators/index.js +16 -0
- package/dist/helpers/decorators/index.js.map +1 -0
- package/dist/helpers/dto-generator-base.helper.d.ts +19 -0
- package/dist/helpers/dto-generator-base.helper.d.ts.map +1 -0
- package/dist/helpers/dto-generator-base.helper.js +72 -0
- package/dist/helpers/dto-generator-base.helper.js.map +1 -0
- package/dist/helpers/index.d.ts +9 -0
- package/dist/helpers/index.d.ts.map +1 -1
- package/dist/helpers/index.js +9 -0
- package/dist/helpers/index.js.map +1 -1
- package/dist/helpers/metadata-extractor.helper.d.ts +26 -0
- package/dist/helpers/metadata-extractor.helper.d.ts.map +1 -0
- package/dist/helpers/metadata-extractor.helper.js +67 -0
- package/dist/helpers/metadata-extractor.helper.js.map +1 -0
- package/dist/helpers/package-detector.helper.d.ts +33 -0
- package/dist/helpers/package-detector.helper.d.ts.map +1 -0
- package/dist/helpers/package-detector.helper.js +82 -0
- package/dist/helpers/package-detector.helper.js.map +1 -0
- package/dist/helpers/property-filter.helper.d.ts +15 -0
- package/dist/helpers/property-filter.helper.d.ts.map +1 -0
- package/dist/helpers/property-filter.helper.js +44 -0
- package/dist/helpers/property-filter.helper.js.map +1 -0
- package/dist/helpers/type-inference.helper.d.ts +76 -0
- package/dist/helpers/type-inference.helper.d.ts.map +1 -0
- package/dist/helpers/type-inference.helper.js +205 -0
- package/dist/helpers/type-inference.helper.js.map +1 -0
- package/dist/helpers/validation-inference.helper.d.ts +18 -0
- package/dist/helpers/validation-inference.helper.d.ts.map +1 -0
- package/dist/helpers/validation-inference.helper.js +100 -0
- package/dist/helpers/validation-inference.helper.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/interfaces/adapters/decorator-adapter.interface.d.ts +8 -0
- package/dist/interfaces/adapters/decorator-adapter.interface.d.ts.map +1 -0
- package/dist/interfaces/adapters/decorator-adapter.interface.js +3 -0
- package/dist/interfaces/adapters/decorator-adapter.interface.js.map +1 -0
- package/dist/interfaces/decorators/solid-field-options.interface.d.ts +55 -0
- package/dist/interfaces/decorators/solid-field-options.interface.d.ts.map +1 -0
- package/dist/interfaces/decorators/solid-field-options.interface.js +3 -0
- package/dist/interfaces/decorators/solid-field-options.interface.js.map +1 -0
- package/dist/interfaces/index.d.ts +5 -0
- package/dist/interfaces/index.d.ts.map +1 -1
- package/dist/interfaces/index.js +5 -0
- package/dist/interfaces/index.js.map +1 -1
- package/dist/interfaces/inputs/filters.interfaces.d.ts +36 -0
- package/dist/interfaces/inputs/filters.interfaces.d.ts.map +1 -0
- package/dist/interfaces/inputs/filters.interfaces.js +3 -0
- package/dist/interfaces/inputs/filters.interfaces.js.map +1 -0
- package/dist/interfaces/inputs/find-args.interface.d.ts +8 -0
- package/dist/interfaces/inputs/find-args.interface.d.ts.map +1 -0
- package/dist/interfaces/inputs/find-args.interface.js +3 -0
- package/dist/interfaces/inputs/find-args.interface.js.map +1 -0
- package/dist/interfaces/inputs/group-by-args.interface.d.ts +33 -0
- package/dist/interfaces/inputs/group-by-args.interface.d.ts.map +1 -0
- package/dist/interfaces/inputs/group-by-args.interface.js +3 -0
- package/dist/interfaces/inputs/group-by-args.interface.js.map +1 -0
- package/dist/interfaces/inputs/group-by-request.interface.d.ts +63 -0
- package/dist/interfaces/inputs/group-by-request.interface.d.ts.map +1 -0
- package/dist/interfaces/inputs/group-by-request.interface.js +3 -0
- package/dist/interfaces/inputs/group-by-request.interface.js.map +1 -0
- package/dist/interfaces/inputs/index.d.ts +6 -0
- package/dist/interfaces/inputs/index.d.ts.map +1 -0
- package/dist/interfaces/inputs/index.js +22 -0
- package/dist/interfaces/inputs/index.js.map +1 -0
- package/dist/interfaces/inputs/pagination-request.interface.d.ts +7 -0
- package/dist/interfaces/inputs/pagination-request.interface.d.ts.map +1 -0
- package/dist/interfaces/inputs/pagination-request.interface.js +3 -0
- package/dist/interfaces/inputs/pagination-request.interface.js.map +1 -0
- package/dist/interfaces/metadata/field-metadata.interface.d.ts +29 -0
- package/dist/interfaces/metadata/field-metadata.interface.d.ts.map +1 -0
- package/dist/interfaces/metadata/field-metadata.interface.js +3 -0
- package/dist/interfaces/metadata/field-metadata.interface.js.map +1 -0
- package/dist/interfaces/misc/group-by-args.interface.d.ts +33 -0
- package/dist/interfaces/misc/group-by-args.interface.d.ts.map +1 -0
- package/dist/interfaces/misc/group-by-args.interface.js +3 -0
- package/dist/interfaces/misc/group-by-args.interface.js.map +1 -0
- package/dist/interfaces/misc/group-by-request.interface.d.ts +63 -0
- package/dist/interfaces/misc/group-by-request.interface.d.ts.map +1 -0
- package/dist/interfaces/misc/group-by-request.interface.js +3 -0
- package/dist/interfaces/misc/group-by-request.interface.js.map +1 -0
- package/dist/interfaces/misc/group-by-response.interface.d.ts +59 -0
- package/dist/interfaces/misc/group-by-response.interface.d.ts.map +1 -0
- package/dist/interfaces/misc/group-by-response.interface.js +3 -0
- package/dist/interfaces/misc/group-by-response.interface.js.map +1 -0
- package/dist/interfaces/misc/group-by.interface.d.ts +145 -0
- package/dist/interfaces/misc/group-by.interface.d.ts.map +1 -0
- package/dist/interfaces/misc/group-by.interface.js +3 -0
- package/dist/interfaces/misc/group-by.interface.js.map +1 -0
- package/dist/interfaces/misc/index.d.ts +0 -4
- package/dist/interfaces/misc/index.d.ts.map +1 -1
- package/dist/interfaces/misc/index.js +0 -4
- package/dist/interfaces/misc/index.js.map +1 -1
- package/dist/interfaces/outputs/group-by-response.interface.d.ts +59 -0
- package/dist/interfaces/outputs/group-by-response.interface.d.ts.map +1 -0
- package/dist/interfaces/outputs/group-by-response.interface.js +3 -0
- package/dist/interfaces/outputs/group-by-response.interface.js.map +1 -0
- package/dist/interfaces/outputs/index.d.ts +3 -0
- package/dist/interfaces/outputs/index.d.ts.map +1 -0
- package/dist/interfaces/outputs/index.js +19 -0
- package/dist/interfaces/outputs/index.js.map +1 -0
- package/dist/interfaces/outputs/pagination-result.interface.d.ts +10 -0
- package/dist/interfaces/outputs/pagination-result.interface.d.ts.map +1 -0
- package/dist/interfaces/outputs/pagination-result.interface.js +3 -0
- package/dist/interfaces/outputs/pagination-result.interface.js.map +1 -0
- package/dist/interfaces/services/crud-service.interface.d.ts +2 -1
- package/dist/interfaces/services/crud-service.interface.d.ts.map +1 -1
- package/dist/interfaces/services/crud-service.interface.js.map +1 -1
- package/dist/interfaces/services/data-service.interface.d.ts +3 -1
- package/dist/interfaces/services/data-service.interface.d.ts.map +1 -1
- package/dist/interfaces/structures/common-services.index.d.ts +1 -0
- package/dist/interfaces/structures/common-services.index.d.ts.map +1 -0
- package/dist/interfaces/structures/common-services.index.js +2 -0
- package/dist/interfaces/structures/common-services.index.js.map +1 -0
- package/dist/interfaces/structures/crud-service-structure.interface.d.ts +2 -1
- package/dist/interfaces/structures/crud-service-structure.interface.d.ts.map +1 -1
- package/dist/interfaces/structures/data-service-structure.interface.d.ts +2 -1
- package/dist/interfaces/structures/data-service-structure.interface.d.ts.map +1 -1
- package/dist/interfaces/structures/entity-provider-structure.interface.d.ts +2 -1
- package/dist/interfaces/structures/entity-provider-structure.interface.d.ts.map +1 -1
- package/dist/interfaces/structures/entity-provider-structure.interface.js.map +1 -1
- package/dist/interfaces/structures/service-plugins.interface.d.ts +2 -1
- package/dist/interfaces/structures/service-plugins.interface.d.ts.map +1 -1
- package/dist/metadata/index.d.ts +2 -0
- package/dist/metadata/index.d.ts.map +1 -0
- package/dist/metadata/index.js +18 -0
- package/dist/metadata/index.js.map +1 -0
- package/dist/metadata/metadata-storage.d.ts +54 -0
- package/dist/metadata/metadata-storage.d.ts.map +1 -0
- package/dist/metadata/metadata-storage.js +106 -0
- package/dist/metadata/metadata-storage.js.map +1 -0
- package/dist/registry/index.d.ts +2 -0
- package/dist/registry/index.d.ts.map +1 -0
- package/dist/registry/index.js +18 -0
- package/dist/registry/index.js.map +1 -0
- package/dist/registry/relation-adapter-registry.d.ts +11 -0
- package/dist/registry/relation-adapter-registry.d.ts.map +1 -0
- package/dist/registry/relation-adapter-registry.js +30 -0
- package/dist/registry/relation-adapter-registry.js.map +1 -0
- package/dist/types/dto-generation.types.d.ts +46 -0
- package/dist/types/dto-generation.types.d.ts.map +1 -0
- package/dist/types/dto-generation.types.js +6 -0
- package/dist/types/dto-generation.types.js.map +1 -0
- package/dist/types/find-args.type.d.ts +9 -7
- package/dist/types/find-args.type.d.ts.map +1 -1
- package/dist/types/group-by.type.d.ts +41 -0
- package/dist/types/group-by.type.d.ts.map +1 -0
- package/dist/types/group-by.type.js +3 -0
- package/dist/types/group-by.type.js.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -1
- package/package.json +2 -2
- package/dist/utils/object.utils.d.ts +0 -8
- package/dist/utils/object.utils.d.ts.map +0 -1
- package/dist/utils/object.utils.js +0 -11
- package/dist/utils/object.utils.js.map +0 -1
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { Type } from '@nestjs/common';
|
|
2
|
+
import 'reflect-metadata';
|
|
3
|
+
/**
|
|
4
|
+
* Options for generating a dynamic class
|
|
5
|
+
*/
|
|
6
|
+
export interface ClassGeneratorOptions {
|
|
7
|
+
className: string;
|
|
8
|
+
baseClass?: Type<any>;
|
|
9
|
+
interfaces?: Type<any>[];
|
|
10
|
+
metadata?: Record<string, any>;
|
|
11
|
+
isAbstract?: boolean;
|
|
12
|
+
description?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Options for adding a property to a class
|
|
16
|
+
*/
|
|
17
|
+
export interface PropertyOptions {
|
|
18
|
+
type: Type<any>;
|
|
19
|
+
isOptional?: boolean;
|
|
20
|
+
isArray?: boolean;
|
|
21
|
+
description?: string;
|
|
22
|
+
example?: any;
|
|
23
|
+
deprecated?: boolean;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Generates a base class with the specified options.
|
|
27
|
+
* This is the foundation for creating dynamic DTO classes.
|
|
28
|
+
*
|
|
29
|
+
* @param options - Configuration for the class generation
|
|
30
|
+
* @returns A dynamically created class constructor
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* const MyClass = generateBaseClass({
|
|
35
|
+
* className: 'ProductWhereFields',
|
|
36
|
+
* metadata: { version: '1.0' }
|
|
37
|
+
* });
|
|
38
|
+
*
|
|
39
|
+
* const instance = new MyClass();
|
|
40
|
+
* console.log(instance.constructor.name); // 'ProductWhereFields'
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare function generateBaseClass(options: ClassGeneratorOptions): Type<any>;
|
|
44
|
+
/**
|
|
45
|
+
* Adds a property to a class prototype with proper descriptors.
|
|
46
|
+
* This function is used to dynamically add fields to generated DTO classes.
|
|
47
|
+
*
|
|
48
|
+
* @param targetClass - The class to add the property to
|
|
49
|
+
* @param propertyName - Name of the property to add
|
|
50
|
+
* @param options - Configuration for the property
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* const MyClass = generateBaseClass({ className: 'TestClass' });
|
|
55
|
+
*
|
|
56
|
+
* addPropertyToClass(MyClass, 'name', {
|
|
57
|
+
* type: String,
|
|
58
|
+
* isOptional: true,
|
|
59
|
+
* description: 'The name field'
|
|
60
|
+
* });
|
|
61
|
+
*
|
|
62
|
+
* const instance = new MyClass();
|
|
63
|
+
* instance.name = 'test'; // Property is now available
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export declare function addPropertyToClass(targetClass: Type<any>, propertyName: string, options: PropertyOptions): void;
|
|
67
|
+
/**
|
|
68
|
+
* Applies a decorator to a class property.
|
|
69
|
+
* This is a utility function for applying decorators dynamically.
|
|
70
|
+
*
|
|
71
|
+
* @param decorator - The decorator function to apply
|
|
72
|
+
* @param targetClass - The class containing the property
|
|
73
|
+
* @param propertyName - The name of the property to decorate
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* import { IsOptional } from 'class-validator';
|
|
78
|
+
*
|
|
79
|
+
* applyPropertyDecorator(
|
|
80
|
+
* IsOptional(),
|
|
81
|
+
* MyClass,
|
|
82
|
+
* 'name'
|
|
83
|
+
* );
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
export declare function applyPropertyDecorator(decorator: PropertyDecorator, targetClass: Type<any>, propertyName: string): void;
|
|
87
|
+
/**
|
|
88
|
+
* Applies multiple decorators to a class property.
|
|
89
|
+
*
|
|
90
|
+
* @param decorators - Array of decorators to apply
|
|
91
|
+
* @param targetClass - The class containing the property
|
|
92
|
+
* @param propertyName - The name of the property to decorate
|
|
93
|
+
*/
|
|
94
|
+
export declare function applyPropertyDecorators(decorators: PropertyDecorator[], targetClass: Type<any>, propertyName: string): void;
|
|
95
|
+
/**
|
|
96
|
+
* Applies a decorator to a class.
|
|
97
|
+
*
|
|
98
|
+
* @param decorator - The class decorator to apply
|
|
99
|
+
* @param targetClass - The class to decorate
|
|
100
|
+
*/
|
|
101
|
+
export declare function applyClassDecorator(decorator: ClassDecorator, targetClass: Type<any>): void;
|
|
102
|
+
/**
|
|
103
|
+
* Applies multiple decorators to a class.
|
|
104
|
+
*
|
|
105
|
+
* @param decorators - Array of class decorators to apply
|
|
106
|
+
* @param targetClass - The class to decorate
|
|
107
|
+
*/
|
|
108
|
+
export declare function applyMultipleClassDecorators(decorators: ClassDecorator[], targetClass: Type<any>): void;
|
|
109
|
+
/**
|
|
110
|
+
* Gets metadata for a property from a class.
|
|
111
|
+
*
|
|
112
|
+
* @param targetClass - The class to get metadata from
|
|
113
|
+
* @param propertyName - The property name
|
|
114
|
+
* @param metadataKey - The metadata key to retrieve
|
|
115
|
+
* @returns The metadata value or undefined
|
|
116
|
+
*/
|
|
117
|
+
export declare function getPropertyMetadata(targetClass: Type<any>, propertyName: string, metadataKey: string): any;
|
|
118
|
+
/**
|
|
119
|
+
* Sets metadata for a property on a class.
|
|
120
|
+
*
|
|
121
|
+
* @param targetClass - The class to set metadata on
|
|
122
|
+
* @param propertyName - The property name
|
|
123
|
+
* @param metadataKey - The metadata key
|
|
124
|
+
* @param metadataValue - The metadata value
|
|
125
|
+
*/
|
|
126
|
+
export declare function setPropertyMetadata(targetClass: Type<any>, propertyName: string, metadataKey: string, metadataValue: any): void;
|
|
127
|
+
/**
|
|
128
|
+
* Gets all property names that have been defined on a class.
|
|
129
|
+
*
|
|
130
|
+
* @param targetClass - The class to inspect
|
|
131
|
+
* @returns Array of property names
|
|
132
|
+
*/
|
|
133
|
+
export declare function getDefinedProperties(targetClass: Type<any>): string[];
|
|
134
|
+
/**
|
|
135
|
+
* Clones a class constructor, creating a new class with the same properties.
|
|
136
|
+
* This is useful for creating variations of existing classes.
|
|
137
|
+
*
|
|
138
|
+
* @param sourceClass - The class to clone
|
|
139
|
+
* @param newClassName - Name for the new class
|
|
140
|
+
* @returns A new class constructor
|
|
141
|
+
*/
|
|
142
|
+
export declare function cloneClass(sourceClass: Type<any>, newClassName: string): Type<any>;
|
|
143
|
+
//# sourceMappingURL=class-generator.helper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"class-generator.helper.d.ts","sourceRoot":"","sources":["../../../src/helpers/args-helpers/class-generator.helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,kBAAkB,CAAC;AAE1B;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;IACtB,UAAU,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC/B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;IAChB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED;;;;;;;;;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GAAG,CAAC,GAAG,MAAM,EAAE,CAmBrE;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,WAAW,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAWlF"}
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateBaseClass = generateBaseClass;
|
|
4
|
+
exports.addPropertyToClass = addPropertyToClass;
|
|
5
|
+
exports.applyPropertyDecorator = applyPropertyDecorator;
|
|
6
|
+
exports.applyPropertyDecorators = applyPropertyDecorators;
|
|
7
|
+
exports.applyClassDecorator = applyClassDecorator;
|
|
8
|
+
exports.applyMultipleClassDecorators = applyMultipleClassDecorators;
|
|
9
|
+
exports.getPropertyMetadata = getPropertyMetadata;
|
|
10
|
+
exports.setPropertyMetadata = setPropertyMetadata;
|
|
11
|
+
exports.getDefinedProperties = getDefinedProperties;
|
|
12
|
+
exports.cloneClass = cloneClass;
|
|
13
|
+
require("reflect-metadata");
|
|
14
|
+
/**
|
|
15
|
+
* Generates a base class with the specified options.
|
|
16
|
+
* This is the foundation for creating dynamic DTO classes.
|
|
17
|
+
*
|
|
18
|
+
* @param options - Configuration for the class generation
|
|
19
|
+
* @returns A dynamically created class constructor
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const MyClass = generateBaseClass({
|
|
24
|
+
* className: 'ProductWhereFields',
|
|
25
|
+
* metadata: { version: '1.0' }
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* const instance = new MyClass();
|
|
29
|
+
* console.log(instance.constructor.name); // 'ProductWhereFields'
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
function generateBaseClass(options) {
|
|
33
|
+
const { className, baseClass, metadata } = options;
|
|
34
|
+
// Create the dynamic class
|
|
35
|
+
let DynamicClass;
|
|
36
|
+
if (baseClass) {
|
|
37
|
+
// Extend from base class if provided
|
|
38
|
+
DynamicClass = class extends baseClass {
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
// Create standalone class
|
|
43
|
+
DynamicClass = class {
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
// Set the class name
|
|
47
|
+
Object.defineProperty(DynamicClass, 'name', {
|
|
48
|
+
value: className,
|
|
49
|
+
configurable: true
|
|
50
|
+
});
|
|
51
|
+
// Apply custom metadata if provided
|
|
52
|
+
if (metadata) {
|
|
53
|
+
for (const [key, value] of Object.entries(metadata)) {
|
|
54
|
+
Reflect.defineMetadata(key, value, DynamicClass);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return DynamicClass;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Adds a property to a class prototype with proper descriptors.
|
|
61
|
+
* This function is used to dynamically add fields to generated DTO classes.
|
|
62
|
+
*
|
|
63
|
+
* @param targetClass - The class to add the property to
|
|
64
|
+
* @param propertyName - Name of the property to add
|
|
65
|
+
* @param options - Configuration for the property
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* const MyClass = generateBaseClass({ className: 'TestClass' });
|
|
70
|
+
*
|
|
71
|
+
* addPropertyToClass(MyClass, 'name', {
|
|
72
|
+
* type: String,
|
|
73
|
+
* isOptional: true,
|
|
74
|
+
* description: 'The name field'
|
|
75
|
+
* });
|
|
76
|
+
*
|
|
77
|
+
* const instance = new MyClass();
|
|
78
|
+
* instance.name = 'test'; // Property is now available
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
function addPropertyToClass(targetClass, propertyName, options) {
|
|
82
|
+
const { type, isOptional = true } = options;
|
|
83
|
+
// Define the property on the prototype
|
|
84
|
+
Object.defineProperty(targetClass.prototype, propertyName, {
|
|
85
|
+
writable: true,
|
|
86
|
+
enumerable: true,
|
|
87
|
+
configurable: true,
|
|
88
|
+
value: undefined
|
|
89
|
+
});
|
|
90
|
+
// Set design-time type metadata for reflection
|
|
91
|
+
Reflect.defineMetadata('design:type', type, targetClass.prototype, propertyName);
|
|
92
|
+
// Set parameter types metadata (for constructor injection if needed)
|
|
93
|
+
const existingParamTypes = Reflect.getMetadata('design:paramtypes', targetClass) || [];
|
|
94
|
+
Reflect.defineMetadata('design:paramtypes', existingParamTypes, targetClass);
|
|
95
|
+
// Store additional property metadata
|
|
96
|
+
const propertyMetadata = {
|
|
97
|
+
type,
|
|
98
|
+
isOptional,
|
|
99
|
+
description: options.description,
|
|
100
|
+
example: options.example,
|
|
101
|
+
deprecated: options.deprecated
|
|
102
|
+
};
|
|
103
|
+
Reflect.defineMetadata(`property:${propertyName}`, propertyMetadata, targetClass.prototype);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Applies a decorator to a class property.
|
|
107
|
+
* This is a utility function for applying decorators dynamically.
|
|
108
|
+
*
|
|
109
|
+
* @param decorator - The decorator function to apply
|
|
110
|
+
* @param targetClass - The class containing the property
|
|
111
|
+
* @param propertyName - The name of the property to decorate
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```typescript
|
|
115
|
+
* import { IsOptional } from 'class-validator';
|
|
116
|
+
*
|
|
117
|
+
* applyPropertyDecorator(
|
|
118
|
+
* IsOptional(),
|
|
119
|
+
* MyClass,
|
|
120
|
+
* 'name'
|
|
121
|
+
* );
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
function applyPropertyDecorator(decorator, targetClass, propertyName) {
|
|
125
|
+
decorator(targetClass.prototype, propertyName);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Applies multiple decorators to a class property.
|
|
129
|
+
*
|
|
130
|
+
* @param decorators - Array of decorators to apply
|
|
131
|
+
* @param targetClass - The class containing the property
|
|
132
|
+
* @param propertyName - The name of the property to decorate
|
|
133
|
+
*/
|
|
134
|
+
function applyPropertyDecorators(decorators, targetClass, propertyName) {
|
|
135
|
+
for (const decorator of decorators) {
|
|
136
|
+
applyPropertyDecorator(decorator, targetClass, propertyName);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Applies a decorator to a class.
|
|
141
|
+
*
|
|
142
|
+
* @param decorator - The class decorator to apply
|
|
143
|
+
* @param targetClass - The class to decorate
|
|
144
|
+
*/
|
|
145
|
+
function applyClassDecorator(decorator, targetClass) {
|
|
146
|
+
decorator(targetClass);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Applies multiple decorators to a class.
|
|
150
|
+
*
|
|
151
|
+
* @param decorators - Array of class decorators to apply
|
|
152
|
+
* @param targetClass - The class to decorate
|
|
153
|
+
*/
|
|
154
|
+
function applyMultipleClassDecorators(decorators, targetClass) {
|
|
155
|
+
for (const decorator of decorators) {
|
|
156
|
+
applyClassDecorator(decorator, targetClass);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Gets metadata for a property from a class.
|
|
161
|
+
*
|
|
162
|
+
* @param targetClass - The class to get metadata from
|
|
163
|
+
* @param propertyName - The property name
|
|
164
|
+
* @param metadataKey - The metadata key to retrieve
|
|
165
|
+
* @returns The metadata value or undefined
|
|
166
|
+
*/
|
|
167
|
+
function getPropertyMetadata(targetClass, propertyName, metadataKey) {
|
|
168
|
+
return Reflect.getMetadata(metadataKey, targetClass.prototype, propertyName);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Sets metadata for a property on a class.
|
|
172
|
+
*
|
|
173
|
+
* @param targetClass - The class to set metadata on
|
|
174
|
+
* @param propertyName - The property name
|
|
175
|
+
* @param metadataKey - The metadata key
|
|
176
|
+
* @param metadataValue - The metadata value
|
|
177
|
+
*/
|
|
178
|
+
function setPropertyMetadata(targetClass, propertyName, metadataKey, metadataValue) {
|
|
179
|
+
Reflect.defineMetadata(metadataKey, metadataValue, targetClass.prototype, propertyName);
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Gets all property names that have been defined on a class.
|
|
183
|
+
*
|
|
184
|
+
* @param targetClass - The class to inspect
|
|
185
|
+
* @returns Array of property names
|
|
186
|
+
*/
|
|
187
|
+
function getDefinedProperties(targetClass) {
|
|
188
|
+
const properties = [];
|
|
189
|
+
const prototype = targetClass.prototype;
|
|
190
|
+
// Get own property names
|
|
191
|
+
const ownProps = Object.getOwnPropertyNames(prototype);
|
|
192
|
+
properties.push(...ownProps.filter(prop => prop !== 'constructor'));
|
|
193
|
+
// Walk up the prototype chain to get inherited properties
|
|
194
|
+
let currentProto = Object.getPrototypeOf(prototype);
|
|
195
|
+
while (currentProto && currentProto !== Object.prototype) {
|
|
196
|
+
const protoProps = Object.getOwnPropertyNames(currentProto);
|
|
197
|
+
properties.push(...protoProps.filter(prop => prop !== 'constructor' && !properties.includes(prop)));
|
|
198
|
+
currentProto = Object.getPrototypeOf(currentProto);
|
|
199
|
+
}
|
|
200
|
+
return properties;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Clones a class constructor, creating a new class with the same properties.
|
|
204
|
+
* This is useful for creating variations of existing classes.
|
|
205
|
+
*
|
|
206
|
+
* @param sourceClass - The class to clone
|
|
207
|
+
* @param newClassName - Name for the new class
|
|
208
|
+
* @returns A new class constructor
|
|
209
|
+
*/
|
|
210
|
+
function cloneClass(sourceClass, newClassName) {
|
|
211
|
+
// Create new class extending the source
|
|
212
|
+
const ClonedClass = class extends sourceClass {
|
|
213
|
+
};
|
|
214
|
+
// Set the new name
|
|
215
|
+
Object.defineProperty(ClonedClass, 'name', {
|
|
216
|
+
value: newClassName,
|
|
217
|
+
configurable: true
|
|
218
|
+
});
|
|
219
|
+
return ClonedClass;
|
|
220
|
+
}
|
|
221
|
+
//# sourceMappingURL=class-generator.helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"class-generator.helper.js","sourceRoot":"","sources":["../../../src/helpers/args-helpers/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C,CACrD,CAAC,CAAC;QACH,YAAY,GAAG,MAAM,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC;IACrD,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,UAAU,CAAC,WAAsB,EAAE,YAAoB;IACrE,wCAAwC;IACxC,MAAM,WAAW,GAAG,KAAM,SAAQ,WAAW;KAAG,CAAC;IAEjD,mBAAmB;IACnB,MAAM,CAAC,cAAc,CAAC,WAAW,EAAE,MAAM,EAAE;QACzC,KAAK,EAAE,YAAY;QACnB,YAAY,EAAE,IAAI;KACnB,CAAC,CAAC;IAEH,OAAO,WAAW,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core GroupByRequest Helper - Common Infrastructure
|
|
3
|
+
*
|
|
4
|
+
* This module provides the shared logic for creating GroupByRequest classes.
|
|
5
|
+
* It's used by the package-specific implementations in rest-api, graphql, and rest-graphql packages.
|
|
6
|
+
*/
|
|
7
|
+
import { Type } from '@nestjs/common';
|
|
8
|
+
import { type ClassOptions } from './field-config.helper';
|
|
9
|
+
/**
|
|
10
|
+
* Configuration for creating a GroupByRequest class
|
|
11
|
+
*/
|
|
12
|
+
export interface GroupByRequestConfig {
|
|
13
|
+
/** The GroupByFields class containing field definitions */
|
|
14
|
+
fields: Type<any>;
|
|
15
|
+
/** Optional custom class name (defaults to `${fields.name}Request`) */
|
|
16
|
+
className?: string;
|
|
17
|
+
/** Optional description for the GroupByRequest */
|
|
18
|
+
description?: string;
|
|
19
|
+
/** Optional class-level configuration */
|
|
20
|
+
classOptions?: ClassOptions;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Parsed and validated GroupByRequest configuration
|
|
24
|
+
*/
|
|
25
|
+
export interface ParsedGroupByRequestConfig {
|
|
26
|
+
fieldsType: Type<any>;
|
|
27
|
+
className: string;
|
|
28
|
+
description: string;
|
|
29
|
+
classOptions: ClassOptions;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Validates and parses GroupByRequest configuration
|
|
33
|
+
*
|
|
34
|
+
* @param config - Raw configuration object
|
|
35
|
+
* @returns Parsed and validated configuration
|
|
36
|
+
* @throws Error if configuration is invalid
|
|
37
|
+
*/
|
|
38
|
+
export declare function parseGroupByRequestConfig(config: GroupByRequestConfig): ParsedGroupByRequestConfig;
|
|
39
|
+
/**
|
|
40
|
+
* Creates the base GroupByRequest class with shared logic.
|
|
41
|
+
* This is the core implementation used by package-specific helpers.
|
|
42
|
+
*
|
|
43
|
+
* @param config - Configuration for GroupByRequest creation
|
|
44
|
+
* @returns Base class ready for decorator application
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* // This is typically used by package-specific implementations
|
|
49
|
+
* const BaseClass = createGroupByRequestBase({
|
|
50
|
+
* fields: ProductGroupByFields,
|
|
51
|
+
* className: 'ProductGroupByRequest'
|
|
52
|
+
* });
|
|
53
|
+
*
|
|
54
|
+
* // Then apply package-specific decorators...
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare function createGroupByRequestBase(config: GroupByRequestConfig): Type<any>;
|
|
58
|
+
/**
|
|
59
|
+
* Gets GroupByRequest metadata from a class
|
|
60
|
+
*
|
|
61
|
+
* @param target - The GroupByRequest class
|
|
62
|
+
* @returns Metadata object or undefined if not found
|
|
63
|
+
*/
|
|
64
|
+
export declare function getGroupByRequestMetadata(target: Type<any>): any;
|
|
65
|
+
/**
|
|
66
|
+
* Checks if a class was created using createGroupByRequest helpers
|
|
67
|
+
*
|
|
68
|
+
* @param target - The class to check
|
|
69
|
+
* @returns True if it's a GroupByRequest class
|
|
70
|
+
*/
|
|
71
|
+
export declare function isGroupByRequestClass(target: Type<any>): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Base class that can be extended by GroupByRequest implementations
|
|
74
|
+
* Provides common structure and can be used for type checking
|
|
75
|
+
*/
|
|
76
|
+
export declare abstract class GroupByRequestInput {
|
|
77
|
+
/** Fields to group by */
|
|
78
|
+
fields?: any;
|
|
79
|
+
/** Optional aggregates configuration (for future use) */
|
|
80
|
+
aggregates?: any[];
|
|
81
|
+
}
|
|
82
|
+
export type { GroupByRequestConfig as GroupByRequestConfigType };
|
|
83
|
+
//# sourceMappingURL=create-groupby-request.helper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-groupby-request.helper.d.ts","sourceRoot":"","sources":["../../../src/helpers/args-helpers/create-groupby-request.helper.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAEtC,OAAO,EAA2C,KAAK,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAEnG;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,2DAA2D;IAC3D,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;IAClB,uEAAuE;IACvE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kDAAkD;IAClD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,yCAAyC;IACzC,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,UAAU,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,YAAY,CAAC;CAC5B;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,oBAAoB,GAAG,0BAA0B,CAkClG;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,oBAAoB,GAAG,IAAI,CAAC,GAAG,CAAC,CA+BhF;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,CAEhE;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,OAAO,CAEhE;AAED;;;GAGG;AACH,8BAAsB,mBAAmB;IACvC,yBAAyB;IACzB,MAAM,CAAC,EAAE,GAAG,CAAC;IAEb,yDAAyD;IACzD,UAAU,CAAC,EAAE,GAAG,EAAE,CAAC;CACpB;AAGD,YAAY,EAAE,oBAAoB,IAAI,wBAAwB,EAAE,CAAC"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Core GroupByRequest Helper - Common Infrastructure
|
|
4
|
+
*
|
|
5
|
+
* This module provides the shared logic for creating GroupByRequest classes.
|
|
6
|
+
* It's used by the package-specific implementations in rest-api, graphql, and rest-graphql packages.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.GroupByRequestInput = void 0;
|
|
10
|
+
exports.parseGroupByRequestConfig = parseGroupByRequestConfig;
|
|
11
|
+
exports.createGroupByRequestBase = createGroupByRequestBase;
|
|
12
|
+
exports.getGroupByRequestMetadata = getGroupByRequestMetadata;
|
|
13
|
+
exports.isGroupByRequestClass = isGroupByRequestClass;
|
|
14
|
+
const class_generation_1 = require("../class-generation");
|
|
15
|
+
const field_config_helper_1 = require("./field-config.helper");
|
|
16
|
+
/**
|
|
17
|
+
* Validates and parses GroupByRequest configuration
|
|
18
|
+
*
|
|
19
|
+
* @param config - Raw configuration object
|
|
20
|
+
* @returns Parsed and validated configuration
|
|
21
|
+
* @throws Error if configuration is invalid
|
|
22
|
+
*/
|
|
23
|
+
function parseGroupByRequestConfig(config) {
|
|
24
|
+
if (!config) {
|
|
25
|
+
throw new Error('GroupByRequestConfig is required');
|
|
26
|
+
}
|
|
27
|
+
if (!config.fields) {
|
|
28
|
+
throw new Error('fields is required in GroupByRequestConfig');
|
|
29
|
+
}
|
|
30
|
+
if (typeof config.fields !== 'function') {
|
|
31
|
+
throw new Error('fields must be a class constructor (Type<any>)');
|
|
32
|
+
}
|
|
33
|
+
// Validate class options if provided
|
|
34
|
+
if (config.classOptions) {
|
|
35
|
+
(0, field_config_helper_1.validateClassOptions)(config.classOptions);
|
|
36
|
+
}
|
|
37
|
+
// Generate class name
|
|
38
|
+
const className = config.className || `${config.fields.name}Request`;
|
|
39
|
+
// Parse class options
|
|
40
|
+
const classOptions = (0, field_config_helper_1.parseClassOptions)(config.fields.name, 'Request', config.classOptions);
|
|
41
|
+
return {
|
|
42
|
+
fieldsType: config.fields,
|
|
43
|
+
className,
|
|
44
|
+
description: config.description || `GroupBy request with ${config.fields.name}`,
|
|
45
|
+
classOptions
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Creates the base GroupByRequest class with shared logic.
|
|
50
|
+
* This is the core implementation used by package-specific helpers.
|
|
51
|
+
*
|
|
52
|
+
* @param config - Configuration for GroupByRequest creation
|
|
53
|
+
* @returns Base class ready for decorator application
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* // This is typically used by package-specific implementations
|
|
58
|
+
* const BaseClass = createGroupByRequestBase({
|
|
59
|
+
* fields: ProductGroupByFields,
|
|
60
|
+
* className: 'ProductGroupByRequest'
|
|
61
|
+
* });
|
|
62
|
+
*
|
|
63
|
+
* // Then apply package-specific decorators...
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
function createGroupByRequestBase(config) {
|
|
67
|
+
const parsedConfig = parseGroupByRequestConfig(config);
|
|
68
|
+
// Generate base class
|
|
69
|
+
const BaseClass = (0, class_generation_1.generateBaseClass)({
|
|
70
|
+
className: parsedConfig.className,
|
|
71
|
+
metadata: {
|
|
72
|
+
'groupby-request:config': {
|
|
73
|
+
fieldsType: parsedConfig.fieldsType.name,
|
|
74
|
+
className: parsedConfig.className,
|
|
75
|
+
description: parsedConfig.description,
|
|
76
|
+
},
|
|
77
|
+
...parsedConfig.classOptions.metadata
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
// Add fields property to prototype (will be decorated by package-specific implementations)
|
|
81
|
+
Object.defineProperty(BaseClass.prototype, 'fields', {
|
|
82
|
+
writable: true,
|
|
83
|
+
enumerable: true,
|
|
84
|
+
configurable: true
|
|
85
|
+
});
|
|
86
|
+
// Add aggregates property to prototype (optional, for future aggregation support)
|
|
87
|
+
Object.defineProperty(BaseClass.prototype, 'aggregates', {
|
|
88
|
+
writable: true,
|
|
89
|
+
enumerable: true,
|
|
90
|
+
configurable: true
|
|
91
|
+
});
|
|
92
|
+
return BaseClass;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Gets GroupByRequest metadata from a class
|
|
96
|
+
*
|
|
97
|
+
* @param target - The GroupByRequest class
|
|
98
|
+
* @returns Metadata object or undefined if not found
|
|
99
|
+
*/
|
|
100
|
+
function getGroupByRequestMetadata(target) {
|
|
101
|
+
return Reflect.getMetadata('groupby-request:config', target);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Checks if a class was created using createGroupByRequest helpers
|
|
105
|
+
*
|
|
106
|
+
* @param target - The class to check
|
|
107
|
+
* @returns True if it's a GroupByRequest class
|
|
108
|
+
*/
|
|
109
|
+
function isGroupByRequestClass(target) {
|
|
110
|
+
return !!getGroupByRequestMetadata(target);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Base class that can be extended by GroupByRequest implementations
|
|
114
|
+
* Provides common structure and can be used for type checking
|
|
115
|
+
*/
|
|
116
|
+
class GroupByRequestInput {
|
|
117
|
+
}
|
|
118
|
+
exports.GroupByRequestInput = GroupByRequestInput;
|
|
119
|
+
//# sourceMappingURL=create-groupby-request.helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-groupby-request.helper.js","sourceRoot":"","sources":["../../../src/helpers/args-helpers/create-groupby-request.helper.ts"],"names":[],"mappings":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