| 1 | import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; |
| 2 | import { |
| 3 | IsArray, |
| 4 | IsBoolean, |
| 5 | IsInt, |
| 6 | IsNumber, |
| 7 | IsOptional, |
| 8 | IsString, |
| 9 | Max, |
| 10 | MaxLength, |
| 11 | Min, |
| 12 | MinLength, |
| 13 | ValidateNested, |
| 14 | } from 'class-validator'; |
| 15 | import { Type } |
| 16 | |
| 17 | export class SearchCodeQueryDTO |
| 18 | @ApiProperty({ |
| 19 | description: |
| 20 | 'A zoekt query: plain text, `/regex/`, `file:` and `lang:` filters, `case:yes`.', |
| 21 | example: 'readReceivePackHeader lang:typescript', |
| 22 | }) |
| 23 | @IsString() |
| 24 | @MinLength(1) |
| 25 | @MaxLength(512) |
| 26 | q: string; |
| 27 | |
| 28 | @ApiPropertyOptional({ |
| 29 | description: 'Most files to return.', |
| 30 | default: 50, |
| 31 | minimum: 1, |
| 32 | maximum: 100, |
| 33 | }) |
| 34 | @Type(() => |
| 35 | @IsInt() |
| 36 | @Min(1) |
| 37 | @Max(100) |
| 38 | @IsOptional() |
| 39 | limit?: number |
| 40 | } |
| 41 | |
| 42 | export class CodeSearchRangeDTO |
| 43 | @ApiProperty({ example |
| 44 | @IsNumber() |
| 45 | start: number; |
| 46 | |
| 47 | @ApiProperty({ example |
| 48 | @IsNumber() |
| 49 | end: number; |
| 50 | } |
| 51 | |
| 52 | export class CodeSearchLineDTO |
| 53 | @ApiProperty({ example |
| 54 | @IsNumber() |
| 55 | lineNumber: number; |
| 56 | |
| 57 | @ApiProperty({ |
| 58 | example: 'export async function readReceivePackHeader(body) {', |
| 59 | }) |
| 60 | @IsString() |
| 61 | line: string; |
| 62 | |
| 63 | @ApiProperty({ |
| 64 | type: [CodeSearchRangeDTO], |
| 65 | description: |
| 66 | 'Matched spans of `line`, as [start, end) offsets that slice a JavaScript string directly.', |
| 67 | }) |
| 68 | @IsArray() |
| 69 | @ValidateNested({ each |
| 70 | @Type(() => |
| 71 | ranges: CodeSearchRangeDTO |
| 72 | } |
| 73 | |
| 74 | export class CodeSearchFileDTO |
| 75 | @ApiProperty({ |
| 76 | description: |
| 77 | 'The commit the index was built from; line numbers refer to it.', |
| 78 | example: '9311a72c0e7f4b8a1d2e3f4a5b6c7d8e9f0a1b2c', |
| 79 | }) |
| 80 | @IsString() |
| 81 | commit: string; |
| 82 | |
| 83 | @ApiProperty({ |
| 84 | example: 'apps/api/src/lib/git/protocol/receive-pack-request.ts', |
| 85 | }) |
| 86 | @IsString() |
| 87 | path: string; |
| 88 | |
| 89 | @ApiProperty({ example |
| 90 | @IsString() |
| 91 | language: string; |
| 92 | |
| 93 | @ApiProperty({ |
| 94 | type: [CodeSearchLineDTO], |
| 95 | description: 'Matching lines. Empty when only the path matched.', |
| 96 | }) |
| 97 | @IsArray() |
| 98 | @ValidateNested({ each |
| 99 | @Type(() => |
| 100 | lines: CodeSearchLineDTO |
| 101 | } |
| 102 | |
| 103 | export class SearchRepositoryCodeResponseDTO |
| 104 | @ApiProperty({ |
| 105 | description: |
| 106 | 'The default branch has commits the index does not cover yet. They are being indexed and show up in results within seconds.', |
| 107 | example: false, |
| 108 | }) |
| 109 | @IsBoolean() |
| 110 | indexing: boolean; |
| 111 | |
| 112 | @ApiProperty({ |
| 113 | type: [CodeSearchFileDTO], |
| 114 | description: 'Files on the default branch that match, best first.', |
| 115 | }) |
| 116 | @IsArray() |
| 117 | @ValidateNested({ each |
| 118 | @Type(() => |
| 119 | files: CodeSearchFileDTO |
| 120 | } |
| 121 | |
| 122 | export class SearchCodeRepositoryDTO |
| 123 | @ApiProperty({ example |
| 124 | @IsString() |
| 125 | owner: string; |
| 126 | |
| 127 | @ApiProperty({ example |
| 128 | @IsString() |
| 129 | slug: string; |
| 130 | |
| 131 | @ApiProperty({ example |
| 132 | @IsString() |
| 133 | name: string; |
| 134 | } |
| 135 | |
| 136 | export class SearchCodeFileDTO |
| 137 | @ApiProperty({ type |
| 138 | @ValidateNested() |
| 139 | @Type(() => |
| 140 | repository: SearchCodeRepositoryDTO |
| 141 | } |
| 142 | |
| 143 | export class SearchCodeResponseDTO |
| 144 | @ApiProperty({ |
| 145 | type: [SearchCodeFileDTO], |
| 146 | description: |
| 147 | 'Files in public repositories that match, best first. Only repositories opened since code search was switched on are indexed.', |
| 148 | }) |
| 149 | @IsArray() |
| 150 | @ValidateNested({ each |
| 151 | @Type(() => |
| 152 | files: SearchCodeFileDTO |
| 153 | } |