blob: f48588b35c71f2e5715b09cc2f51cbc45d9f7fbd [file] [log] [blame]
Tao Zhou5b60a3682019-11-06 09:31:57 +01001/**
2 * @license
Ben Rohlfs94fcbbc2022-05-27 10:45:03 +02003 * Copyright 2019 Google LLC
4 * SPDX-License-Identifier: Apache-2.0
Tao Zhou5b60a3682019-11-06 09:31:57 +01005 */
Ole Rehmsen8b8d26b2021-02-05 14:29:38 +01006import {DiffLayer as DiffLayerApi} from '../api/diff';
Dhruvbbcbe152022-06-07 21:49:18 +02007import {MessageTag, Side} from '../constants/constants';
Dmitrii Filippov6a038002020-10-14 18:50:07 +02008import {
Ben Rohlfsa00ef282021-01-22 21:45:53 +01009 AccountInfo,
Dhruv Srivastava591b4902021-03-10 11:48:12 +010010 BasePatchSetNum,
Ben Rohlfsa00ef282021-01-22 21:45:53 +010011 ChangeViewChangeInfo,
Ben Rohlfsa00ef282021-01-22 21:45:53 +010012 CommitInfo,
Ben Rohlfscf96f092022-05-30 11:44:16 +020013 EditPatchSet,
Dmitrii Filippov6a038002020-10-14 18:50:07 +020014 PatchSetNum,
Ben Rohlfsd5e77a22023-05-11 08:42:33 +020015 PatchSetNumber,
Ben Rohlfsa00ef282021-01-22 21:45:53 +010016 ReviewerUpdateInfo,
17 RevisionInfo,
Ben Rohlfsd5e77a22023-05-11 08:42:33 +020018 RevisionPatchSetNum,
Ben Rohlfsa00ef282021-01-22 21:45:53 +010019 Timestamp,
Dmitrii Filippov6a038002020-10-14 18:50:07 +020020} from './common';
Ben Rohlfs4fa7c532020-08-24 18:16:13 +020021
Dhruv Srivastava7cfec742023-09-28 10:25:47 +020022// A finalizable object has a single method `finalize` that is called when
23// the object is no longer needed and should clean itself up.
24export interface Finalizable {
25 finalize(): void;
26}
27
Ben Rohlfs9b2f7402022-10-17 12:40:31 +020028export function isDefined<T>(x: T): x is NonNullable<T> {
Ben Rohlfs7aeecaa2022-10-11 15:26:45 +000029 return x !== undefined && x !== null;
Ben Rohlfs713445d2020-08-27 09:14:02 +020030}
31
Frank Borden42c1a452022-08-11 16:27:20 +020032export type {CoverageRange} from '../api/diff';
33export {CoverageType} from '../api/diff';
Ben Rohlfs22e00e12020-08-14 19:18:36 +020034
Milutin Kristoficbe0b5162020-09-01 11:22:29 +020035export enum ErrorType {
36 AUTH = 'AUTH',
37 NETWORK = 'NETWORK',
38 GENERIC = 'GENERIC',
39}
40
Dhruv Srivastavabb862dc2023-09-29 10:25:17 +020041export enum LoadingStatus {
42 NOT_LOADED = 'NOT_LOADED',
43 LOADING = 'LOADING',
Dhruv Srivastavabb862dc2023-09-29 10:25:17 +020044 LOADED = 'LOADED',
45}
46
Dhruv Srivastava4f326672023-03-01 15:22:34 +010047export 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 Poucetd6568032022-06-28 13:13:23 +020054/*
Ben Rohlfs22e00e12020-08-14 19:18:36 +020055export interface OwnerRoot {
56 host?: HTMLElement;
57}
Ben Rohlfs87dac482020-08-23 21:11:43 +020058
Ben Rohlfsae255782020-09-05 12:51:04 +020059/** https://highlightjs.readthedocs.io/en/latest/api.html */
60export interface HighlightJSResult {
61 value: string;
62 top: unknown;
63}
64
65/** https://highlightjs.readthedocs.io/en/latest/api.html */
Milutin Kristofic76f91902020-09-02 20:24:58 +020066export interface HighlightJS {
Ben Rohlfsae255782020-09-05 12:51:04 +020067 configure(options: {classPrefix: string}): void;
68 getLanguage(languageName: string): unknown | undefined;
69 highlight(
70 languageName: string,
71 code: string,
72 ignore_illegals: boolean,
Ben Rohlfsde5c02e2022-02-01 12:42:12 +010073 continuation?: unknown
Ben Rohlfsae255782020-09-05 12:51:04 +020074 ): HighlightJSResult;
75}
76
77export type DiffLayerListener = (
Ben Rohlfse535b8c2022-01-12 11:39:24 +010078 /** 1-based inclusive */
Ben Rohlfsae255782020-09-05 12:51:04 +020079 start: number,
Ben Rohlfse535b8c2022-01-12 11:39:24 +010080 /** 1-based inclusive */
Ben Rohlfsae255782020-09-05 12:51:04 +020081 end: number,
82 side: Side
83) => void;
84
Ole Rehmsen8b8d26b2021-02-05 14:29:38 +010085export interface DiffLayer extends DiffLayerApi {
Ben Rohlfsae255782020-09-05 12:51:04 +020086 addListener?(listener: DiffLayerListener): void;
87 removeListener?(listener: DiffLayerListener): void;
Milutin Kristofic76f91902020-09-02 20:24:58 +020088}
Ben Rohlfs3f3d9892020-10-04 20:23:01 +020089
Ben Rohlfs3f3d9892020-10-04 20:23:01 +020090export interface PatchSetFile {
91 path: string;
92 basePath?: string;
93 patchNum?: PatchSetNum;
94}
95
96export interface PatchNumOnly {
97 patchNum: PatchSetNum;
98}
99
100export function isPatchSetFile(
101 x: PatchSetFile | PatchNumOnly
102): x is PatchSetFile {
103 return !!(x as PatchSetFile).path;
104}
105
Ben Rohlfsd5e77a22023-05-11 08:42:33 +0200106export 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 Rohlfsea4cb7e2020-12-03 16:00:00 +0100117export interface FetchRequest {
118 url: string;
119 fetchOptions?: AuthRequestInit;
120 anonymizedUrl?: string;
121}
Ben Rohlfsa00ef282021-01-22 21:45:53 +0100122
123export 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 Rohlfs6547e2f2023-09-15 18:02:25 +0200131/**
132 * https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#edit-info
133 */
Ben Rohlfsa00ef282021-01-22 21:45:53 +0100134export interface EditRevisionInfo extends Partial<RevisionInfo> {
135 // EditRevisionInfo has less required properties then RevisionInfo
Ben Rohlfs6547e2f2023-09-15 18:02:25 +0200136 // TODO: Explicitly list which props are required and optional here.
Ben Rohlfscf96f092022-05-30 11:44:16 +0200137 _number: EditPatchSet;
Dhruv Srivastava591b4902021-03-10 11:48:12 +0100138 basePatchNum: BasePatchSetNum;
Ben Rohlfsa00ef282021-01-22 21:45:53 +0100139 commit: CommitInfo;
140}
141
142export interface ParsedChangeInfo
143 extends Omit<ChangeViewChangeInfo, 'reviewer_updates' | 'revisions'> {
144 revisions: {[revisionId: string]: RevisionInfo | EditRevisionInfo};
145 reviewer_updates?: ReviewerUpdateInfo[] | FormattedReviewerUpdateInfo[];
146}