| 1 | import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; |
| 2 | import { Transform, Type |
| 3 | import { |
| 4 | IsBoolean, |
| 5 | IsISO8601, |
| 6 | IsInt, |
| 7 | IsOptional, |
| 8 | IsString, |
| 9 | Max, |
| 10 | Matches, |
| 11 | MaxLength, |
| 12 | Min, |
| 13 | MinLength, |
| 14 | ValidateIf, |
| 15 | ValidateNested, |
| 16 | } from 'class-validator'; |
| 17 | |
| 18 | export class ReleaseAssetDTO |
| 19 | @ApiProperty() |
| 20 | @IsString() |
| 21 | id: string; |
| 22 | |
| 23 | @ApiProperty({ example |
| 24 | @IsString() |
| 25 | name: string; |
| 26 | |
| 27 | @ApiProperty({ example |
| 28 | @IsString() |
| 29 | contentType: string; |
| 30 | |
| 31 | @ApiProperty({ description |
| 32 | @IsInt() |
| 33 | size: number; |
| 34 | |
| 35 | @ApiProperty() |
| 36 | @IsInt() |
| 37 | downloadCount: number; |
| 38 | |
| 39 | @ApiProperty() |
| 40 | @IsISO8601() |
| 41 | createdAt: string; |
| 42 | } |
| 43 | |
| 44 | export class UploadReleaseAssetQueryDTO |
| 45 | @ApiProperty({ |
| 46 | description: 'File name the asset is saved and downloaded under.', |
| 47 | example: 'ghost-linux-x64.tar.gz', |
| 48 | }) |
| 49 | @IsString() |
| 50 | @MaxLength(255) |
| 51 | name: string; |
| 52 | |
| 53 | @ApiPropertyOptional({ |
| 54 | description: |
| 55 | 'Media type the file is served with. The request body itself is always `application/octet-stream`.', |
| 56 | example: 'application/gzip', |
| 57 | }) |
| 58 | @IsString() |
| 59 | @IsOptional() |
| 60 | @Matches(/^[ |
| 61 | type?: string |
| 62 | } |
| 63 | |
| 64 | export class ReleaseDTO |
| 65 | @ApiProperty() |
| 66 | @IsString() |
| 67 | id: string; |
| 68 | |
| 69 | @ApiProperty({ |
| 70 | description: 'Tag name, without the `refs/tags/` prefix.', |
| 71 | example: 'v1.0.0', |
| 72 | }) |
| 73 | @IsString() |
| 74 | tagName: string; |
| 75 | |
| 76 | @ApiProperty({ |
| 77 | type: String, |
| 78 | nullable: true, |
| 79 | description: '`null` reads as the tag name.', |
| 80 | }) |
| 81 | @IsString() |
| 82 | @IsOptional() |
| 83 | name: string |
| 84 | |
| 85 | @ApiProperty({ type |
| 86 | @IsString() |
| 87 | @IsOptional() |
| 88 | body: string |
| 89 | |
| 90 | @ApiProperty({ |
| 91 | description: 'Only people who can write to the repository see drafts.', |
| 92 | }) |
| 93 | @IsBoolean() |
| 94 | isDraft: boolean; |
| 95 | |
| 96 | @ApiProperty() |
| 97 | @IsBoolean() |
| 98 | isPrerelease: boolean; |
| 99 | |
| 100 | @ApiProperty({ |
| 101 | description: |
| 102 | 'The most recently published release that is neither a draft nor a prerelease.', |
| 103 | }) |
| 104 | @IsBoolean() |
| 105 | isLatest: boolean; |
| 106 | |
| 107 | @ApiProperty({ |
| 108 | type: String, |
| 109 | nullable: true, |
| 110 | description: 'Null once the author account is deleted.', |
| 111 | }) |
| 112 | @IsString() |
| 113 | @IsOptional() |
| 114 | authorUsername: string |
| 115 | |
| 116 | @ApiProperty({ |
| 117 | type: String, |
| 118 | nullable: true, |
| 119 | description: |
| 120 | 'The commit the tag points at. `null` when the tag has since been deleted.', |
| 121 | }) |
| 122 | @IsString() |
| 123 | @IsOptional() |
| 124 | commitSha: string |
| 125 | |
| 126 | @ApiProperty({ type |
| 127 | @ValidateNested({ each |
| 128 | @Type(() => |
| 129 | assets: ReleaseAssetDTO |
| 130 | |
| 131 | @ApiProperty({ type |
| 132 | @IsISO8601() |
| 133 | @IsOptional() |
| 134 | publishedAt: string |
| 135 | |
| 136 | @ApiProperty() |
| 137 | @IsISO8601() |
| 138 | createdAt: string; |
| 139 | |
| 140 | @ApiProperty() |
| 141 | @IsISO8601() |
| 142 | updatedAt: string; |
| 143 | |
| 144 | @ApiProperty({ |
| 145 | description: 'True when the requesting user can write to the repository.', |
| 146 | }) |
| 147 | @IsBoolean() |
| 148 | viewerCanEdit: boolean; |
| 149 | } |
| 150 | |
| 151 | export class GetReleasesQueryDTO |
| 152 | @ApiPropertyOptional({ |
| 153 | description: |
| 154 | 'Opaque cursor returned as `nextCursor` by the previous page. Omit for the first page.', |
| 155 | }) |
| 156 | @IsString() |
| 157 | @IsOptional() |
| 158 | cursor?: string |
| 159 | |
| 160 | @ApiPropertyOptional({ |
| 161 | description: 'Page size.', |
| 162 | minimum: 1, |
| 163 | maximum: 100, |
| 164 | default: 10, |
| 165 | }) |
| 166 | @Type(() => |
| 167 | @IsInt() |
| 168 | @Min(1) |
| 169 | @Max(100) |
| 170 | @IsOptional() |
| 171 | limit?: number |
| 172 | } |
| 173 | |
| 174 | export class GetReleasesResponseDTO |
| 175 | @ApiProperty({ type |
| 176 | @ValidateNested({ each |
| 177 | @Type(() => |
| 178 | releases: ReleaseDTO |
| 179 | |
| 180 | @ApiProperty({ type |
| 181 | @IsString() |
| 182 | @IsOptional() |
| 183 | nextCursor: string |
| 184 | } |
| 185 | |
| 186 | export class CreateReleaseRequestDTO |
| 187 | @ApiProperty({ |
| 188 | description: |
| 189 | 'An existing tag, or a new one to create at `target`. Without the `refs/tags/` prefix.', |
| 190 | example: 'v1.0.0', |
| 191 | }) |
| 192 | @IsString() |
| 193 | @Transform(({ |
| 194 | @MinLength(1) |
| 195 | @MaxLength(250) |
| 196 | tagName: string; |
| 197 | |
| 198 | @ApiPropertyOptional({ |
| 199 | description: |
| 200 | 'Branch or commit sha a new tag points at. Defaults to the default branch; ignored when the tag already exists.', |
| 201 | example: 'main', |
| 202 | }) |
| 203 | @IsString() |
| 204 | @IsOptional() |
| 205 | @MaxLength(250) |
| 206 | target?: string |
| 207 | |
| 208 | @ApiPropertyOptional({ example |
| 209 | @IsString() |
| 210 | @IsOptional() |
| 211 | @Transform(({ |
| 212 | @MaxLength(200) |
| 213 | name?: string |
| 214 | |
| 215 | @ApiPropertyOptional({ description |
| 216 | @IsString() |
| 217 | @IsOptional() |
| 218 | @MaxLength(100000) |
| 219 | body?: string |
| 220 | |
| 221 | @ApiPropertyOptional({ default |
| 222 | @IsBoolean() |
| 223 | @IsOptional() |
| 224 | isDraft?: boolean |
| 225 | |
| 226 | @ApiPropertyOptional({ default |
| 227 | @IsBoolean() |
| 228 | @IsOptional() |
| 229 | isPrerelease?: boolean |
| 230 | } |
| 231 | |
| 232 | export class UpdateReleaseRequestDTO |
| 233 | @ApiPropertyOptional({ |
| 234 | type: String, |
| 235 | nullable: true, |
| 236 | description: '`null` falls back to the tag name.', |
| 237 | }) |
| 238 | @IsString() |
| 239 | @IsOptional() |
| 240 | @ValidateIf((_ |
| 241 | @Transform(({ |
| 242 | @MaxLength(200) |
| 243 | name?: string |
| 244 | |
| 245 | @ApiPropertyOptional({ |
| 246 | type: String, |
| 247 | nullable: true, |
| 248 | description: 'Markdown. `null` clears the notes.', |
| 249 | }) |
| 250 | @IsString() |
| 251 | @IsOptional() |
| 252 | @ValidateIf((_ |
| 253 | @MaxLength(100000) |
| 254 | body?: string |
| 255 | |
| 256 | @ApiPropertyOptional({ |
| 257 | description: 'Publishing a draft stamps `publishedAt` the first time.', |
| 258 | }) |
| 259 | @IsBoolean() |
| 260 | @IsOptional() |
| 261 | isDraft?: boolean |
| 262 | |
| 263 | @ApiPropertyOptional() |
| 264 | @IsBoolean() |
| 265 | @IsOptional() |
| 266 | isPrerelease?: boolean |
| 267 | } |