@lenne.tech/nest-server 11.1.6 → 11.1.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lenne.tech/nest-server",
3
- "version": "11.1.6",
3
+ "version": "11.1.7",
4
4
  "description": "Modern, fast, powerful Node.js web framework in TypeScript based on Nest with a GraphQL API and a connection to MongoDB (or other databases).",
5
5
  "keywords": [
6
6
  "node",
@@ -22,17 +22,6 @@ import { RoleEnum } from '../enums/role.enum';
22
22
  import { Restricted, RestrictedType } from './restricted.decorator';
23
23
 
24
24
  export interface UnifiedFieldOptions {
25
- /**
26
- * Indicates whether the property is an array.
27
- *
28
- * This value is typically determined automatically based on the property type or metadata.
29
- *
30
- * However, cases involving complex or dynamic type definitions (e.g., union types, generics, or factory functions)
31
- * may result in inaccurate detection.
32
- *
33
- * When in doubt, explicitly set this property to ensure correct behavior.
34
- */
35
- array?: boolean;
36
25
  /** Description used for both Swagger & Gql */
37
26
  description?: string;
38
27
  /** Enum for class-validator */
@@ -41,10 +30,12 @@ export interface UnifiedFieldOptions {
41
30
  example?: any;
42
31
  /** Options for graphql */
43
32
  gqlOptions?: FieldOptions;
44
- /** Type if Swagger & Gql types arent compatible */
33
+ /** Type if Swagger & Gql types aren't compatible */
45
34
  gqlType?: GraphQLScalarType | (new (...args: any[]) => any) | Record<number | string, number | string>;
46
35
  /** If the property is Any (skips all Validation) */
47
36
  isAny?: boolean;
37
+ /** Indicates whether the property is an array. */
38
+ isArray?: boolean;
48
39
  /** Default: false */
49
40
  isOptional?: boolean;
50
41
  /** Restricted roles */
@@ -75,9 +66,9 @@ export function UnifiedField(opts: UnifiedFieldOptions = {}): PropertyDecorator
75
66
  return (target: any, propertyKey: string | symbol) => {
76
67
  const metadataType = Reflect.getMetadata('design:type', target, propertyKey);
77
68
  const userType = opts.type;
78
- const isArrayField = opts.array === true || metadataType === Array;
69
+ const isArrayField = opts.isArray === true || metadataType === Array;
79
70
 
80
- // Throwing because metatype only returns the generic array, but not the type of the array items
71
+ // Throwing because meta type only returns the generic array, but not the type of the array items
81
72
  if (metadataType === Array && !userType) {
82
73
  throw new Error(`Array field '${String(propertyKey)}' of '${String(target)}' must have an explicit type`);
83
74
  }
@@ -129,12 +120,21 @@ export function UnifiedField(opts: UnifiedFieldOptions = {}): PropertyDecorator
129
120
  swaggerOpts.required = true;
130
121
  }
131
122
 
132
- // Description
123
+ // Set type for swagger
124
+ if (baseType) {
125
+ if (opts.enum) {
126
+ swaggerOpts.type = () => String;
127
+ } else {
128
+ swaggerOpts.type = () => resolvedTypeFn();
129
+ }
130
+ }
131
+
132
+ // Set description
133
133
  const defaultDesc = opts.description ?? `${String(propertyKey)} of ${target.constructor.name}`;
134
134
  gqlOpts.description = gqlOpts.description ?? defaultDesc;
135
135
  swaggerOpts.description = swaggerOpts.description ?? defaultDesc;
136
136
 
137
- // Swagger example
137
+ // Set swagger example
138
138
  if (opts.example !== undefined) {
139
139
  swaggerOpts.example = swaggerOpts.example ?? opts.example;
140
140
  }
@@ -53,7 +53,7 @@ export abstract class CoreUserInput extends CoreInput {
53
53
  */
54
54
  @Restricted({ processType: ProcessType.INPUT, roles: RoleEnum.ADMIN })
55
55
  @UnifiedField({
56
- array: true,
56
+ isArray: true,
57
57
  isOptional: true,
58
58
  type: String,
59
59
  })
@@ -9,8 +9,8 @@ import { User } from '../user.model';
9
9
  @Restricted(RoleEnum.ADMIN)
10
10
  export class FindAndCountUsersResult {
11
11
  @UnifiedField({
12
- array: true,
13
12
  description: 'Found users',
13
+ isArray: true,
14
14
  isOptional: true,
15
15
  type: () => User,
16
16
  })