Tao Zhou | 5b60a368 | 2019-11-06 09:31:57 +0100 | [diff] [blame] | 1 | /** |
| 2 | * @license |
Ben Rohlfs | 94fcbbc | 2022-05-27 10:45:03 +0200 | [diff] [blame] | 3 | * Copyright 2019 Google LLC |
| 4 | * SPDX-License-Identifier: Apache-2.0 |
Tao Zhou | 5b60a368 | 2019-11-06 09:31:57 +0100 | [diff] [blame] | 5 | */ |
Ole Rehmsen | 8b8d26b | 2021-02-05 14:29:38 +0100 | [diff] [blame] | 6 | import {DiffLayer as DiffLayerApi} from '../api/diff'; |
Dhruv | bbcbe15 | 2022-06-07 21:49:18 +0200 | [diff] [blame] | 7 | import {MessageTag, Side} from '../constants/constants'; |
Dmitrii Filippov | 6a03800 | 2020-10-14 18:50:07 +0200 | [diff] [blame] | 8 | import { |
Ben Rohlfs | a00ef28 | 2021-01-22 21:45:53 +0100 | [diff] [blame] | 9 | AccountInfo, |
Dhruv Srivastava | 591b490 | 2021-03-10 11:48:12 +0100 | [diff] [blame] | 10 | BasePatchSetNum, |
Ben Rohlfs | a00ef28 | 2021-01-22 21:45:53 +0100 | [diff] [blame] | 11 | ChangeViewChangeInfo, |
Ben Rohlfs | a00ef28 | 2021-01-22 21:45:53 +0100 | [diff] [blame] | 12 | CommitInfo, |
Ben Rohlfs | cf96f09 | 2022-05-30 11:44:16 +0200 | [diff] [blame] | 13 | EditPatchSet, |
Dmitrii Filippov | 6a03800 | 2020-10-14 18:50:07 +0200 | [diff] [blame] | 14 | PatchSetNum, |
Ben Rohlfs | d5e77a2 | 2023-05-11 08:42:33 +0200 | [diff] [blame] | 15 | PatchSetNumber, |
Ben Rohlfs | a00ef28 | 2021-01-22 21:45:53 +0100 | [diff] [blame] | 16 | ReviewerUpdateInfo, |
| 17 | RevisionInfo, |
Ben Rohlfs | d5e77a2 | 2023-05-11 08:42:33 +0200 | [diff] [blame] | 18 | RevisionPatchSetNum, |
Ben Rohlfs | a00ef28 | 2021-01-22 21:45:53 +0100 | [diff] [blame] | 19 | Timestamp, |
Dmitrii Filippov | 6a03800 | 2020-10-14 18:50:07 +0200 | [diff] [blame] | 20 | } from './common'; |
Ben Rohlfs | 4fa7c53 | 2020-08-24 18:16:13 +0200 | [diff] [blame] | 21 | |
Dhruv Srivastava | 7cfec74 | 2023-09-28 10:25:47 +0200 | [diff] [blame] | 22 | // A finalizable object has a single method `finalize` that is called when |
| 23 | // the object is no longer needed and should clean itself up. |
| 24 | export interface Finalizable { |
| 25 | finalize(): void; |
| 26 | } |
| 27 | |
Ben Rohlfs | 9b2f740 | 2022-10-17 12:40:31 +0200 | [diff] [blame] | 28 | export function isDefined<T>(x: T): x is NonNullable<T> { |
Ben Rohlfs | 7aeecaa | 2022-10-11 15:26:45 +0000 | [diff] [blame] | 29 | return x !== undefined && x !== null; |
Ben Rohlfs | 713445d | 2020-08-27 09:14:02 +0200 | [diff] [blame] | 30 | } |
| 31 | |
Frank Borden | 42c1a45 | 2022-08-11 16:27:20 +0200 | [diff] [blame] | 32 | export type {CoverageRange} from '../api/diff'; |
| 33 | export {CoverageType} from '../api/diff'; |
Ben Rohlfs | 22e00e1 | 2020-08-14 19:18:36 +0200 | [diff] [blame] | 34 | |
Milutin Kristofic | be0b516 | 2020-09-01 11:22:29 +0200 | [diff] [blame] | 35 | export enum ErrorType { |
| 36 | AUTH = 'AUTH', |
| 37 | NETWORK = 'NETWORK', |
| 38 | GENERIC = 'GENERIC', |
| 39 | } |
| 40 | |
Dhruv Srivastava | bb862dc | 2023-09-29 10:25:17 +0200 | [diff] [blame] | 41 | export enum LoadingStatus { |
| 42 | NOT_LOADED = 'NOT_LOADED', |
| 43 | LOADING = 'LOADING', |
Dhruv Srivastava | bb862dc | 2023-09-29 10:25:17 +0200 | [diff] [blame] | 44 | LOADED = 'LOADED', |
| 45 | } |
| 46 | |
Dhruv Srivastava | 4f32667 | 2023-03-01 15:22:34 +0100 | [diff] [blame] | 47 | export interface AuthRequestInit extends RequestInit { |
| 48 | // RequestInit define headers as HeadersInit, i.e. |
| 49 | // Headers | string[][] | Record<string, string> |
| 50 | // Auth class supports only Headers in options |
| 51 | headers?: Headers; |
| 52 | } |
| 53 | |
Chris Poucet | d656803 | 2022-06-28 13:13:23 +0200 | [diff] [blame] | 54 | /* |
Ben Rohlfs | 22e00e1 | 2020-08-14 19:18:36 +0200 | [diff] [blame] | 55 | export interface OwnerRoot { |
| 56 | host?: HTMLElement; |
| 57 | } |
Ben Rohlfs | 87dac48 | 2020-08-23 21:11:43 +0200 | [diff] [blame] | 58 | |
Ben Rohlfs | ae25578 | 2020-09-05 12:51:04 +0200 | [diff] [blame] | 59 | /** https://highlightjs.readthedocs.io/en/latest/api.html */ |
| 60 | export interface HighlightJSResult { |
| 61 | value: string; |
| 62 | top: unknown; |
| 63 | } |
| 64 | |
| 65 | /** https://highlightjs.readthedocs.io/en/latest/api.html */ |
Milutin Kristofic | 76f9190 | 2020-09-02 20:24:58 +0200 | [diff] [blame] | 66 | export interface HighlightJS { |
Ben Rohlfs | ae25578 | 2020-09-05 12:51:04 +0200 | [diff] [blame] | 67 | configure(options: {classPrefix: string}): void; |
| 68 | getLanguage(languageName: string): unknown | undefined; |
| 69 | highlight( |
| 70 | languageName: string, |
| 71 | code: string, |
| 72 | ignore_illegals: boolean, |
Ben Rohlfs | de5c02e | 2022-02-01 12:42:12 +0100 | [diff] [blame] | 73 | continuation?: unknown |
Ben Rohlfs | ae25578 | 2020-09-05 12:51:04 +0200 | [diff] [blame] | 74 | ): HighlightJSResult; |
| 75 | } |
| 76 | |
| 77 | export type DiffLayerListener = ( |
Ben Rohlfs | e535b8c | 2022-01-12 11:39:24 +0100 | [diff] [blame] | 78 | /** 1-based inclusive */ |
Ben Rohlfs | ae25578 | 2020-09-05 12:51:04 +0200 | [diff] [blame] | 79 | start: number, |
Ben Rohlfs | e535b8c | 2022-01-12 11:39:24 +0100 | [diff] [blame] | 80 | /** 1-based inclusive */ |
Ben Rohlfs | ae25578 | 2020-09-05 12:51:04 +0200 | [diff] [blame] | 81 | end: number, |
| 82 | side: Side |
| 83 | ) => void; |
| 84 | |
Ole Rehmsen | 8b8d26b | 2021-02-05 14:29:38 +0100 | [diff] [blame] | 85 | export interface DiffLayer extends DiffLayerApi { |
Ben Rohlfs | ae25578 | 2020-09-05 12:51:04 +0200 | [diff] [blame] | 86 | addListener?(listener: DiffLayerListener): void; |
| 87 | removeListener?(listener: DiffLayerListener): void; |
Milutin Kristofic | 76f9190 | 2020-09-02 20:24:58 +0200 | [diff] [blame] | 88 | } |
Ben Rohlfs | 3f3d989 | 2020-10-04 20:23:01 +0200 | [diff] [blame] | 89 | |
Ben Rohlfs | 3f3d989 | 2020-10-04 20:23:01 +0200 | [diff] [blame] | 90 | export interface PatchSetFile { |
| 91 | path: string; |
| 92 | basePath?: string; |
| 93 | patchNum?: PatchSetNum; |
| 94 | } |
| 95 | |
| 96 | export interface PatchNumOnly { |
| 97 | patchNum: PatchSetNum; |
| 98 | } |
| 99 | |
| 100 | export function isPatchSetFile( |
| 101 | x: PatchSetFile | PatchNumOnly |
| 102 | ): x is PatchSetFile { |
| 103 | return !!(x as PatchSetFile).path; |
| 104 | } |
| 105 | |
Ben Rohlfs | d5e77a2 | 2023-05-11 08:42:33 +0200 | [diff] [blame] | 106 | export function isPatchSetNumber( |
| 107 | x?: |
| 108 | | PatchSetNum |
| 109 | | PatchSetNumber |
| 110 | | RevisionPatchSetNum |
| 111 | | BasePatchSetNum |
| 112 | | null |
| 113 | ): x is PatchSetNumber { |
| 114 | return !!x && Number.isInteger(x) && (x as number) > 0; |
| 115 | } |
| 116 | |
Ben Rohlfs | ea4cb7e | 2020-12-03 16:00:00 +0100 | [diff] [blame] | 117 | export interface FetchRequest { |
| 118 | url: string; |
| 119 | fetchOptions?: AuthRequestInit; |
| 120 | anonymizedUrl?: string; |
| 121 | } |
Ben Rohlfs | a00ef28 | 2021-01-22 21:45:53 +0100 | [diff] [blame] | 122 | |
| 123 | export interface FormattedReviewerUpdateInfo { |
| 124 | author: AccountInfo; |
| 125 | date: Timestamp; |
| 126 | type: 'REVIEWER_UPDATE'; |
| 127 | tag: MessageTag.TAG_REVIEWER_UPDATE; |
| 128 | updates: {message: string; reviewers: AccountInfo[]}[]; |
| 129 | } |
| 130 | |
Ben Rohlfs | 6547e2f | 2023-09-15 18:02:25 +0200 | [diff] [blame] | 131 | /** |
| 132 | * https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#edit-info |
| 133 | */ |
Ben Rohlfs | a00ef28 | 2021-01-22 21:45:53 +0100 | [diff] [blame] | 134 | export interface EditRevisionInfo extends Partial<RevisionInfo> { |
| 135 | // EditRevisionInfo has less required properties then RevisionInfo |
Ben Rohlfs | 6547e2f | 2023-09-15 18:02:25 +0200 | [diff] [blame] | 136 | // TODO: Explicitly list which props are required and optional here. |
Ben Rohlfs | cf96f09 | 2022-05-30 11:44:16 +0200 | [diff] [blame] | 137 | _number: EditPatchSet; |
Dhruv Srivastava | 591b490 | 2021-03-10 11:48:12 +0100 | [diff] [blame] | 138 | basePatchNum: BasePatchSetNum; |
Ben Rohlfs | a00ef28 | 2021-01-22 21:45:53 +0100 | [diff] [blame] | 139 | commit: CommitInfo; |
| 140 | } |
| 141 | |
| 142 | export interface ParsedChangeInfo |
| 143 | extends Omit<ChangeViewChangeInfo, 'reviewer_updates' | 'revisions'> { |
| 144 | revisions: {[revisionId: string]: RevisionInfo | EditRevisionInfo}; |
| 145 | reviewer_updates?: ReviewerUpdateInfo[] | FormattedReviewerUpdateInfo[]; |
| 146 | } |