denwa-nest-shared 1.2.5 → 1.2.6
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/CHANGELOG.md +2 -0
- package/README.md +29 -1
- package/cjs/decorators.d.ts +4 -2
- package/cjs/decorators.js +34 -3
- package/cjs/decorators.js.map +1 -1
- package/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/decorators.d.ts +4 -2
- package/dist/decorators.js +35 -4
- package/dist/decorators.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/skills/schema-definition/SKILL.md +62 -0
package/package.json
CHANGED
|
@@ -112,8 +112,70 @@ export class StatsDto {
|
|
|
112
112
|
}
|
|
113
113
|
```
|
|
114
114
|
|
|
115
|
+
### Nested / Complex DTOs
|
|
116
|
+
|
|
117
|
+
`type` accepts only primitives (`string | int | float | date | boolean`). For nested objects pass the DTO
|
|
118
|
+
class via `objectType` (preferred) or `swaggerType` (backward compatible, including `[SomeDto]`).
|
|
119
|
+
The decorator then emits `@Field(() => SomeDto)`, `@ValidateNested()` and `@Type(() => SomeDto)`
|
|
120
|
+
instead of `IsString`, so no manual `@Field` is required.
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
import { InputType } from '@nestjs/graphql';
|
|
124
|
+
import { ApiValidationProperty } from 'denwa-nest-shared';
|
|
125
|
+
|
|
126
|
+
@InputType()
|
|
127
|
+
class ImageDto {
|
|
128
|
+
@ApiValidationProperty({ type: 'string', max: 256 })
|
|
129
|
+
tempName: string;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
@InputType()
|
|
133
|
+
export class CreateProductDto {
|
|
134
|
+
// Массив вложенных DTO
|
|
135
|
+
@ApiValidationProperty({
|
|
136
|
+
type: 'object',
|
|
137
|
+
objectType: ImageDto,
|
|
138
|
+
isArray: true,
|
|
139
|
+
isOptional: true,
|
|
140
|
+
})
|
|
141
|
+
images?: ImageDto[];
|
|
142
|
+
|
|
143
|
+
// Одиночный вложенный DTO
|
|
144
|
+
@ApiValidationProperty({
|
|
145
|
+
type: 'object',
|
|
146
|
+
objectType: ImageDto,
|
|
147
|
+
isOptional: true,
|
|
148
|
+
})
|
|
149
|
+
cover?: ImageDto;
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Built-in element types are not treated as nested: `swaggerType: [String]` still behaves as a string array.
|
|
154
|
+
|
|
115
155
|
## Common Mistakes
|
|
116
156
|
|
|
157
|
+
### CRITICAL Using `type: 'string'` for Nested DTOs
|
|
158
|
+
|
|
159
|
+
Wrong:
|
|
160
|
+
|
|
161
|
+
```typescript
|
|
162
|
+
@ApiValidationProperty({ type: 'string', isArray: true })
|
|
163
|
+
items: ItemDto[];
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Correct:
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
@ApiValidationProperty({ type: 'object', objectType: ItemDto, isArray: true })
|
|
170
|
+
items: ItemDto[];
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
`type` describes the primitive GraphQL scalar. Using `string` for objects emits `IsString({ each: true })`,
|
|
174
|
+
which rejects every object with `each value in items must be a string`. Passing the class in
|
|
175
|
+
`swaggerType` (e.g. `swaggerType: [ItemDto]`) is also supported for backward compatibility.
|
|
176
|
+
|
|
177
|
+
Source: Denwa799/nest-shared:src/decorators.ts
|
|
178
|
+
|
|
117
179
|
### CRITICAL Using Separate Decorators
|
|
118
180
|
|
|
119
181
|
Wrong:
|