denwa-nest-shared 1.2.5 → 1.2.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/dist/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { FindOptionsOrder, FindOptionsWhere } from 'typeorm';
1
+ import { FindOptionsOrder, FindOptionsSelect, FindOptionsWhere } from 'typeorm';
2
2
  export declare enum LANG {
3
3
  RU = "ru",
4
4
  EN = "en",
@@ -11,6 +11,13 @@ export interface IResponse<StatusCode, Data = object> {
11
11
  error?: string;
12
12
  data?: Data;
13
13
  }
14
+ export interface ICursorPagination {
15
+ id: string | number;
16
+ sortValue?: unknown;
17
+ sortValues?: Record<string, unknown>;
18
+ order?: string;
19
+ field?: string;
20
+ }
14
21
  export interface IPaginate {
15
22
  page: number;
16
23
  pages: number;
@@ -18,10 +25,13 @@ export interface IPaginate {
18
25
  next?: number;
19
26
  count: number;
20
27
  limit: number;
28
+ cursor?: string;
29
+ hasNextPage?: boolean;
21
30
  }
22
31
  export type QueryDataType<Entity> = {
23
32
  skip: number;
24
33
  take: number;
34
+ select?: (keyof Entity)[] | FindOptionsSelect<Entity>;
25
35
  order?: FindOptionsOrder<Entity>;
26
36
  where?: FindOptionsWhere<Entity>[] | FindOptionsWhere<Entity>;
27
37
  relations?: string[];
@@ -65,6 +75,7 @@ export interface IGetQuery {
65
75
  filterType?: FilterType;
66
76
  filter?: object;
67
77
  search?: object;
78
+ cursor?: string | ICursorPagination;
68
79
  }
69
80
  export declare enum ImageContentTypeEnum {
70
81
  'image/avif' = "image/avif",
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAEA,MAAM,CAAN,IAAY,IAIX;AAJD,WAAY,IAAI;IACd,iBAAS,CAAA;IACT,iBAAS,CAAA;IACT,iBAAS,CAAA;AACX,CAAC,EAJW,IAAI,KAAJ,IAAI,QAIf;AAyED,MAAM,CAAN,IAAY,oBAMX;AAND,WAAY,oBAAoB;IAC9B,iDAA2B,CAAA;IAC3B,iDAA2B,CAAA;IAC3B,iDAA2B,CAAA;IAC3B,+CAAyB,CAAA;IACzB,6EAAuD,CAAA;AACzD,CAAC,EANW,oBAAoB,KAApB,oBAAoB,QAM/B","sourcesContent":["import { FindOptionsOrder, FindOptionsWhere } from 'typeorm';\n\nexport enum LANG {\n RU = 'ru',\n EN = 'en',\n AR = 'ar',\n}\n\nexport interface IResponse<StatusCode, Data = object> {\n statusCode: StatusCode;\n messages?: string[];\n message?: string;\n error?: string;\n data?: Data;\n}\nexport interface IPaginate {\n page: number;\n pages: number;\n previous?: number;\n next?: number;\n count: number;\n limit: number;\n}\n\nexport type QueryDataType<Entity> = {\n skip: number;\n take: number;\n order?: FindOptionsOrder<Entity>;\n where?: FindOptionsWhere<Entity>[] | FindOptionsWhere<Entity>;\n relations?: string[];\n};\n\nexport type OkNotFoundType = IResponse<404 | 200>;\nexport type OkNotFoundBadRequestType = IResponse<404 | 400 | 200>;\nexport type OkNotFoundForbiddenType = IResponse<404 | 403 | 200>;\n\nexport type FilterType = 'and' | 'or';\nexport type SortOrderType = 'asc' | 'desc' | 'ASC' | 'DESC';\n\nexport interface IPreparedImage {\n name: string;\n fileExtensions?: string[];\n prefixes?: string[];\n originalFileExtension: string;\n entityId: string;\n folder?: string;\n fullPathExample: string;\n altRU?: string;\n altEN?: string;\n altAR?: string;\n}\n\nexport interface IPreparedFile {\n name: string;\n fullName: string;\n extension: string;\n entityId: string;\n fullPathExample: string;\n folder?: string;\n}\n\nexport interface IPreparedImageAndOrder extends IPreparedImage {\n order: number;\n}\n\nexport interface IPreparedFileAndOrder extends IPreparedFile {\n order: number;\n}\n\nexport interface IGetQuery {\n page?: number;\n limit?: number;\n sortField?: string;\n sortOrder?: SortOrderType;\n filterType?: FilterType;\n filter?: object;\n search?: object;\n}\n\nexport enum ImageContentTypeEnum {\n 'image/avif' = 'image/avif',\n 'image/webp' = 'image/webp',\n 'image/jpeg' = 'image/jpeg',\n 'image/png' = 'image/png',\n 'application/octet-stream' = 'application/octet-stream',\n}\n\nexport type NullToUndefined<T> = T extends null\n ? undefined\n : T extends (infer U)[]\n ? NullToUndefined<U>[]\n : T extends object\n ? { [K in keyof T]: NullToUndefined<T[K]> }\n : T;\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAEA,MAAM,CAAN,IAAY,IAIX;AAJD,WAAY,IAAI;IACd,iBAAS,CAAA;IACT,iBAAS,CAAA;IACT,iBAAS,CAAA;AACX,CAAC,EAJW,IAAI,KAAJ,IAAI,QAIf;AAsFD,MAAM,CAAN,IAAY,oBAMX;AAND,WAAY,oBAAoB;IAC9B,iDAA2B,CAAA;IAC3B,iDAA2B,CAAA;IAC3B,iDAA2B,CAAA;IAC3B,+CAAyB,CAAA;IACzB,6EAAuD,CAAA;AACzD,CAAC,EANW,oBAAoB,KAApB,oBAAoB,QAM/B","sourcesContent":["import { FindOptionsOrder, FindOptionsSelect, FindOptionsWhere } from 'typeorm';\n\nexport enum LANG {\n RU = 'ru',\n EN = 'en',\n AR = 'ar',\n}\n\nexport interface IResponse<StatusCode, Data = object> {\n statusCode: StatusCode;\n messages?: string[];\n message?: string;\n error?: string;\n data?: Data;\n}\n\nexport interface ICursorPagination {\n id: string | number;\n sortValue?: unknown;\n sortValues?: Record<string, unknown>;\n order?: string;\n field?: string;\n}\n\nexport interface IPaginate {\n page: number;\n pages: number;\n previous?: number;\n next?: number;\n count: number;\n limit: number;\n cursor?: string;\n hasNextPage?: boolean;\n}\n\nexport type QueryDataType<Entity> = {\n skip: number;\n take: number;\n select?: (keyof Entity)[] | FindOptionsSelect<Entity>;\n order?: FindOptionsOrder<Entity>;\n where?: FindOptionsWhere<Entity>[] | FindOptionsWhere<Entity>;\n relations?: string[];\n};\n\nexport type OkNotFoundType = IResponse<404 | 200>;\nexport type OkNotFoundBadRequestType = IResponse<404 | 400 | 200>;\nexport type OkNotFoundForbiddenType = IResponse<404 | 403 | 200>;\n\nexport type FilterType = 'and' | 'or';\nexport type SortOrderType = 'asc' | 'desc' | 'ASC' | 'DESC';\n\nexport interface IPreparedImage {\n name: string;\n fileExtensions?: string[];\n prefixes?: string[];\n originalFileExtension: string;\n entityId: string;\n folder?: string;\n fullPathExample: string;\n altRU?: string;\n altEN?: string;\n altAR?: string;\n}\n\nexport interface IPreparedFile {\n name: string;\n fullName: string;\n extension: string;\n entityId: string;\n fullPathExample: string;\n folder?: string;\n}\n\nexport interface IPreparedImageAndOrder extends IPreparedImage {\n order: number;\n}\n\nexport interface IPreparedFileAndOrder extends IPreparedFile {\n order: number;\n}\n\nexport interface IGetQuery {\n page?: number;\n limit?: number;\n sortField?: string;\n sortOrder?: SortOrderType;\n filterType?: FilterType;\n filter?: object;\n search?: object;\n cursor?: string | ICursorPagination;\n}\n\nexport enum ImageContentTypeEnum {\n 'image/avif' = 'image/avif',\n 'image/webp' = 'image/webp',\n 'image/jpeg' = 'image/jpeg',\n 'image/png' = 'image/png',\n 'application/octet-stream' = 'application/octet-stream',\n}\n\nexport type NullToUndefined<T> = T extends null\n ? undefined\n : T extends (infer U)[]\n ? NullToUndefined<U>[]\n : T extends object\n ? { [K in keyof T]: NullToUndefined<T[K]> }\n : T;\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "denwa-nest-shared",
4
- "version": "1.2.5",
4
+ "version": "1.2.7",
5
5
  "skills": "skills",
6
6
  "types": "./dist/index.d.ts",
7
7
  "main": "./cjs/index.js",
@@ -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: