@noldova/git.hosting.protocol 0.0.0-stage → 0.0.2

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.
@@ -0,0 +1,1472 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+
9
+ import { Exception, type ExceptionOptions } from "@noldova/context.exceptions";
10
+ import type { JsonException, JsonObject, JsonReader } from "@noldova/context.json";
11
+
12
+ export type { JsonObject, JsonValue } from "@noldova/context.json";
13
+
14
+ /**
15
+ * Where a host module's sign-in stands on this computer.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * import { SignInState } from "@noldova/git.hosting.protocol";
20
+ *
21
+ * console.log(SignInState.Waiting);
22
+ * ```
23
+ */
24
+ export declare const SignInState: {
25
+ /**
26
+ * No account is signed in.
27
+ */
28
+ readonly SignedOut: "SignedOut";
29
+
30
+ /**
31
+ * The host showed a code and waits for the person to enter it on the host's page.
32
+ */
33
+ readonly Waiting: "Waiting";
34
+
35
+ /**
36
+ * An account is signed in, and its token is kept in the module's secrets on this computer.
37
+ */
38
+ readonly SignedIn: "SignedIn";
39
+ };
40
+
41
+ /**
42
+ * Where a host module's sign-in stands on this computer.
43
+ */
44
+ export type SignInState = (typeof SignInState)[keyof typeof SignInState];
45
+
46
+ /**
47
+ * Why the last sign-in ended signed out.
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * import { SignInFailure } from "@noldova/git.hosting.protocol";
52
+ *
53
+ * console.log(SignInFailure.Expired);
54
+ * ```
55
+ */
56
+ export declare const SignInFailure: {
57
+ /**
58
+ * The code expired before the person entered it.
59
+ */
60
+ readonly Expired: "Expired";
61
+
62
+ /**
63
+ * The person declined the app's access on the host's page.
64
+ */
65
+ readonly Denied: "Denied";
66
+
67
+ /**
68
+ * The host no longer accepts the kept token, which the module forgot.
69
+ */
70
+ readonly Revoked: "Revoked";
71
+
72
+ /**
73
+ * The host couldn't be reached.
74
+ */
75
+ readonly Unreachable: "Unreachable";
76
+
77
+ /**
78
+ * The host refused the request or answered in a way the module doesn't read.
79
+ */
80
+ readonly Refused: "Refused";
81
+
82
+ /**
83
+ * The token couldn't be kept in the module's secrets on this computer.
84
+ */
85
+ readonly Unkept: "Unkept";
86
+
87
+ /**
88
+ * The person signed out, but the token couldn't be removed from the module's secrets on this computer, so a later start may restore it.
89
+ */
90
+ readonly Unforgotten: "Unforgotten";
91
+ };
92
+
93
+ /**
94
+ * Why the last sign-in ended signed out.
95
+ */
96
+ export type SignInFailure = (typeof SignInFailure)[keyof typeof SignInFailure];
97
+
98
+ /**
99
+ * Whether an item on a host is a pull request or an issue.
100
+ *
101
+ * @example
102
+ * ```ts
103
+ * import { ReferenceKind } from "@noldova/git.hosting.protocol";
104
+ *
105
+ * console.log(ReferenceKind.PullRequest);
106
+ * ```
107
+ */
108
+ export declare const ReferenceKind: {
109
+ /**
110
+ * A pull request, or a merge request on a host that calls it so.
111
+ */
112
+ readonly PullRequest: "PullRequest";
113
+
114
+ /**
115
+ * An issue.
116
+ */
117
+ readonly Issue: "Issue";
118
+ };
119
+
120
+ /**
121
+ * Whether an item on a host is a pull request or an issue.
122
+ */
123
+ export type ReferenceKind = (typeof ReferenceKind)[keyof typeof ReferenceKind];
124
+
125
+ /**
126
+ * Where a pull request or an issue stands on its host: a pull request is `Open`, `Draft`, `Merged` or `Closed`, and an issue is `Open`,
127
+ * `ClosedDone` or `ClosedNotPlanned`.
128
+ *
129
+ * @example
130
+ * ```ts
131
+ * import { ReferenceState } from "@noldova/git.hosting.protocol";
132
+ *
133
+ * console.log(ReferenceState.Merged);
134
+ * ```
135
+ */
136
+ export declare const ReferenceState: {
137
+ /**
138
+ * A pull request ready for review, or an issue, that is open.
139
+ */
140
+ readonly Open: "Open";
141
+
142
+ /**
143
+ * A pull request that is open as a draft.
144
+ */
145
+ readonly Draft: "Draft";
146
+
147
+ /**
148
+ * A pull request whose changes were merged.
149
+ */
150
+ readonly Merged: "Merged";
151
+
152
+ /**
153
+ * A pull request closed without being merged.
154
+ */
155
+ readonly Closed: "Closed";
156
+
157
+ /**
158
+ * An issue closed as done.
159
+ */
160
+ readonly ClosedDone: "ClosedDone";
161
+
162
+ /**
163
+ * An issue closed as not planned.
164
+ */
165
+ readonly ClosedNotPlanned: "ClosedNotPlanned";
166
+ };
167
+
168
+ /**
169
+ * Where a pull request or an issue stands on its host.
170
+ */
171
+ export type ReferenceState = (typeof ReferenceState)[keyof typeof ReferenceState];
172
+
173
+ /**
174
+ * Where a check on a commit stands, such as a CI job.
175
+ *
176
+ * @example
177
+ * ```ts
178
+ * import { CheckState } from "@noldova/git.hosting.protocol";
179
+ *
180
+ * console.log(CheckState.Failed);
181
+ * ```
182
+ */
183
+ export declare const CheckState: {
184
+ /**
185
+ * The check waits to start.
186
+ */
187
+ readonly Queued: "Queued";
188
+
189
+ /**
190
+ * The check runs.
191
+ */
192
+ readonly Running: "Running";
193
+
194
+ /**
195
+ * The check finished and passed.
196
+ */
197
+ readonly Succeeded: "Succeeded";
198
+
199
+ /**
200
+ * The check finished and failed.
201
+ */
202
+ readonly Failed: "Failed";
203
+
204
+ /**
205
+ * The check finished with no verdict, such as one skipped or neutral on the host.
206
+ */
207
+ readonly Neutral: "Neutral";
208
+ };
209
+
210
+ /**
211
+ * Where a check on a commit stands.
212
+ */
213
+ export type CheckState = (typeof CheckState)[keyof typeof CheckState];
214
+
215
+
216
+ /**
217
+ * The base of the hosting protocol's own exceptions; catch it to catch them all.
218
+ * A model's `fromJson` also throws context's `JsonException`, which isn't under this base.
219
+ * It is abstract: a model's constructor throws {@link HostingArgumentException}, and its `fromJson` {@link HostingFieldException}.
220
+ *
221
+ * @example
222
+ * ```ts
223
+ * import { HostingProtocolException, HostReference } from "@noldova/git.hosting.protocol";
224
+ *
225
+ * try {
226
+ * HostReference.fromJson({ host: "git-github", owner: "team", repository: "repo", number: 0 });
227
+ * }
228
+ * catch (error) {
229
+ * if (error instanceof HostingProtocolException)
230
+ * console.log(error.message);
231
+ * }
232
+ * ```
233
+ */
234
+ export declare abstract class HostingProtocolException extends Exception {
235
+ /**
236
+ * Makes the failure; only the hosting protocol's own exceptions call it.
237
+ *
238
+ * @param message The message, from the protocol's resources.
239
+ * @param options The cause, when there is one.
240
+ * @example
241
+ * ```ts
242
+ * import { HostingArgumentException } from "@noldova/git.hosting.protocol";
243
+ *
244
+ * const failure = new HostingArgumentException("login", "a text that isn't blank");
245
+ * console.log(failure.message);
246
+ * ```
247
+ */
248
+ protected constructor(message: string, options?: ExceptionOptions);
249
+ }
250
+
251
+ /**
252
+ * The failure a model's constructor throws for a part it can't take, naming the parameter.
253
+ *
254
+ * @example
255
+ * ```ts
256
+ * import { HostingArgumentException, HostReference } from "@noldova/git.hosting.protocol";
257
+ *
258
+ * try {
259
+ * new HostReference("git-github", "team", "repo", 0);
260
+ * }
261
+ * catch (error) {
262
+ * if (error instanceof HostingArgumentException)
263
+ * console.log(error.parameterName);
264
+ * }
265
+ * ```
266
+ */
267
+ export declare class HostingArgumentException extends HostingProtocolException {
268
+ /**
269
+ * The refused parameter's name, such as `number`.
270
+ */
271
+ public readonly parameterName: string;
272
+
273
+ /**
274
+ * What the parameter must hold, such as `a whole number above zero`, which the message names.
275
+ */
276
+ public readonly expectation: string;
277
+
278
+ /**
279
+ * Makes the failure for a parameter and what it expected.
280
+ *
281
+ * @param parameterName The parameter's name.
282
+ * @param expectation What the parameter must hold.
283
+ * @example
284
+ * ```ts
285
+ * import { HostingArgumentException } from "@noldova/git.hosting.protocol";
286
+ *
287
+ * export function refuseNumber(): never {
288
+ * throw new HostingArgumentException("number", "a whole number above zero");
289
+ * }
290
+ * ```
291
+ */
292
+ public constructor(parameterName: string, expectation: string);
293
+ }
294
+
295
+ /**
296
+ * The failure a model's `fromJson` throws for a field it can't take, naming the field by its path.
297
+ *
298
+ * @example
299
+ * ```ts
300
+ * import { HostingFieldException, HostReference } from "@noldova/git.hosting.protocol";
301
+ *
302
+ * try {
303
+ * HostReference.fromJson({ host: "git-github", owner: "team", repository: "repo", number: 0 });
304
+ * }
305
+ * catch (error) {
306
+ * if (error instanceof HostingFieldException)
307
+ * console.log(error.field);
308
+ * }
309
+ * ```
310
+ */
311
+ export declare class HostingFieldException extends HostingProtocolException {
312
+ /**
313
+ * The field's path, such as `$.reference.number`.
314
+ */
315
+ public readonly field: string;
316
+
317
+ /**
318
+ * What the field must hold, such as `a whole number above zero`, which the message names.
319
+ */
320
+ public readonly expectation: string;
321
+
322
+ /**
323
+ * Makes the failure for a field and what it expected.
324
+ *
325
+ * @param field The field's path.
326
+ * @param expectation What the field must hold.
327
+ * @example
328
+ * ```ts
329
+ * import { HostingFieldException } from "@noldova/git.hosting.protocol";
330
+ *
331
+ * export function refuseNumber(): never {
332
+ * throw new HostingFieldException("$.reference.number", "a whole number above zero");
333
+ * }
334
+ * ```
335
+ */
336
+ public constructor(field: string, expectation: string);
337
+ }
338
+
339
+ /**
340
+ * The one-time code a device sign-in shows, the host's page where the person enters it, and when it expires.
341
+ *
342
+ * @example
343
+ * ```ts
344
+ * import { DeviceCode } from "@noldova/git.hosting.protocol";
345
+ *
346
+ * const code = new DeviceCode("WDJB-MJHT", "https://github.com/login/device", Date.now() + 900_000);
347
+ * console.log(code.toJson());
348
+ * ```
349
+ */
350
+ export declare class DeviceCode {
351
+ /**
352
+ * The code the person enters on the host's page.
353
+ */
354
+ public readonly userCode: string;
355
+
356
+ /**
357
+ * The host's https page where the person enters the code.
358
+ */
359
+ public readonly verificationUri: string;
360
+
361
+ /**
362
+ * When the code expires, in milliseconds since the Unix epoch.
363
+ */
364
+ public readonly expiresAt: number;
365
+
366
+ /**
367
+ * Makes a code from its parts.
368
+ *
369
+ * @param userCode The code, which isn't blank.
370
+ * @param verificationUri The host's https page.
371
+ * @param expiresAt When the code expires, a whole number of milliseconds above zero.
372
+ * @param reader The reader the values came from, so an error names the field by its path; omitted for values that didn't come from JSON.
373
+ * @throws {HostingArgumentException} Without a reader, when a part is out of its range, naming the field as the parameter, such as `userCode`.
374
+ * @throws {HostingFieldException} With a reader, when a part is out of its range, naming the field by its path, such as `$.userCode`.
375
+ * @example
376
+ * ```ts
377
+ * import { DeviceCode } from "@noldova/git.hosting.protocol";
378
+ *
379
+ * const code = new DeviceCode("WDJB-MJHT", "https://github.com/login/device", 1_800_000_000_000);
380
+ * // @ts-expect-error The expiry is a number of milliseconds, not a date.
381
+ * new DeviceCode("WDJB-MJHT", "https://github.com/login/device", new Date());
382
+ * ```
383
+ */
384
+ public constructor(userCode: string, verificationUri: string, expiresAt: number, reader?: JsonReader);
385
+
386
+ /**
387
+ * Reads a code from its JSON.
388
+ *
389
+ * @param value The JSON, with exactly the fields `toJson` writes.
390
+ * @param path The JSON's path, `$` by default.
391
+ * @returns The code.
392
+ * @throws {JsonException} When the value isn't an object, or a field is missing or of the wrong type; it comes from `@noldova/context.json`.
393
+ * @throws {HostingFieldException} When a field is unknown or out of its range.
394
+ * @example
395
+ * ```ts
396
+ * import { DeviceCode } from "@noldova/git.hosting.protocol";
397
+ *
398
+ * const code = DeviceCode.fromJson({ userCode: "WDJB-MJHT", verificationUri: "https://github.com/login/device", expiresAt: 1_800_000_000_000 });
399
+ * console.log(code.userCode);
400
+ * ```
401
+ */
402
+ public static fromJson(value: unknown, path?: string): DeviceCode;
403
+
404
+ /**
405
+ * Writes the code as JSON: `userCode`, `verificationUri` and `expiresAt`.
406
+ *
407
+ * @returns The JSON.
408
+ * @example
409
+ * ```ts
410
+ * import { DeviceCode } from "@noldova/git.hosting.protocol";
411
+ *
412
+ * console.log(new DeviceCode("WDJB-MJHT", "https://github.com/login/device", 1_800_000_000_000).toJson());
413
+ * ```
414
+ */
415
+ public toJson(): JsonObject;
416
+ }
417
+
418
+ /**
419
+ * The account a host module is signed in to: its login, its display name, its avatar and the access its token was given.
420
+ *
421
+ * @example
422
+ * ```ts
423
+ * import { HostAccount } from "@noldova/git.hosting.protocol";
424
+ *
425
+ * const account = new HostAccount("octocat", "The Octocat", "data:image/png;base64,iVBORw0KGgo=", ["repo"]);
426
+ * console.log(account.login);
427
+ * ```
428
+ */
429
+ export declare class HostAccount {
430
+ /**
431
+ * The account's login on the host.
432
+ */
433
+ public readonly login: string;
434
+
435
+ /**
436
+ * The account's display name, or null when it has none.
437
+ */
438
+ public readonly name: string | null;
439
+
440
+ /**
441
+ * The account's avatar as a base64 data address of a PNG, JPEG, GIF or WebP image of at most 64 KiB, which a window can show under a policy that
442
+ * allows only its own and data images; null when the host gives none or the module couldn't read it.
443
+ */
444
+ public readonly avatar: string | null;
445
+
446
+ /**
447
+ * The access the host gave the token, in the host's own scope names, such as GitHub's `repo`.
448
+ */
449
+ public readonly scopes: readonly string[];
450
+
451
+ /**
452
+ * Makes an account from its parts.
453
+ *
454
+ * @param login The login, which isn't blank.
455
+ * @param name The display name, which isn't blank, or null.
456
+ * @param avatar The avatar as a base64 data address of a PNG, JPEG, GIF or WebP image of at most 64 KiB, or null.
457
+ * @param scopes The token's scopes, none blank.
458
+ * @param reader The reader the values came from, so an error names the field by its path; omitted for values that didn't come from JSON.
459
+ * @throws {HostingArgumentException} Without a reader, when a part is out of its range, naming the field as the parameter, such as `login`.
460
+ * @throws {HostingFieldException} With a reader, when a part is out of its range, naming the field by its path, such as `$.login`.
461
+ * @example
462
+ * ```ts
463
+ * import { HostAccount } from "@noldova/git.hosting.protocol";
464
+ *
465
+ * const account = new HostAccount("octocat", null, null, ["repo"]);
466
+ * // @ts-expect-error The scopes are a list, not one text.
467
+ * new HostAccount("octocat", null, null, "repo");
468
+ * ```
469
+ */
470
+ public constructor(login: string, name: string | null, avatar: string | null, scopes: readonly string[], reader?: JsonReader);
471
+
472
+ /**
473
+ * Reads an account from its JSON.
474
+ *
475
+ * @param value The JSON, with exactly the fields `toJson` writes.
476
+ * @param path The JSON's path, `$` by default.
477
+ * @returns The account.
478
+ * @throws {JsonException} When the value isn't an object, or a field is missing or of the wrong type; it comes from `@noldova/context.json`.
479
+ * @throws {HostingFieldException} When a field is unknown or out of its range.
480
+ * @example
481
+ * ```ts
482
+ * import { HostAccount } from "@noldova/git.hosting.protocol";
483
+ *
484
+ * const account = HostAccount.fromJson({ login: "octocat", name: null, avatar: null, scopes: ["repo"] });
485
+ * console.log(account.scopes);
486
+ * ```
487
+ */
488
+ public static fromJson(value: unknown, path?: string): HostAccount;
489
+
490
+ /**
491
+ * Writes the account as JSON: `login`, `name`, `avatar` and `scopes`.
492
+ *
493
+ * @returns The JSON.
494
+ * @example
495
+ * ```ts
496
+ * import { HostAccount } from "@noldova/git.hosting.protocol";
497
+ *
498
+ * console.log(new HostAccount("octocat", null, null, []).toJson());
499
+ * ```
500
+ */
501
+ public toJson(): JsonObject;
502
+ }
503
+
504
+ /**
505
+ * A host module's sign-in on this computer: its state, the code while it waits, the account while signed in, and why it last ended signed
506
+ * out.
507
+ *
508
+ * @example
509
+ * ```ts
510
+ * import { HostSignIn, SignInFailure } from "@noldova/git.hosting.protocol";
511
+ *
512
+ * console.log(HostSignIn.signedOut(SignInFailure.Expired).toJson());
513
+ * ```
514
+ */
515
+ export declare class HostSignIn {
516
+ /**
517
+ * Where the sign-in stands.
518
+ */
519
+ public readonly state: SignInState;
520
+
521
+ /**
522
+ * The code, exactly while the sign-in waits.
523
+ */
524
+ public readonly deviceCode: DeviceCode | null;
525
+
526
+ /**
527
+ * The account, exactly while signed in.
528
+ */
529
+ public readonly account: HostAccount | null;
530
+
531
+ /**
532
+ * Why the last sign-in ended signed out, only while signed out, or null.
533
+ */
534
+ public readonly failure: SignInFailure | null;
535
+
536
+ /**
537
+ * Makes a sign-in from its parts.
538
+ *
539
+ * @param state Where it stands.
540
+ * @param deviceCode The code, exactly while it waits.
541
+ * @param account The account, exactly while signed in.
542
+ * @param failure The failure, only while signed out.
543
+ * @param reader The reader the values came from, so an error names the field by its path; omitted for values that didn't come from JSON.
544
+ * @throws {HostingArgumentException} Without a reader, when the parts don't fit the state, naming the field as the parameter, such as `account`.
545
+ * @throws {HostingFieldException} With a reader, when the parts don't fit the state, naming the field by its path, such as `$.account`.
546
+ * @example
547
+ * ```ts
548
+ * import { HostSignIn, SignInFailure, SignInState } from "@noldova/git.hosting.protocol";
549
+ *
550
+ * const signIn = new HostSignIn(SignInState.SignedOut, null, null, SignInFailure.Denied);
551
+ * console.log(signIn.failure);
552
+ * ```
553
+ */
554
+ public constructor(state: SignInState, deviceCode: DeviceCode | null, account: HostAccount | null, failure: SignInFailure | null, reader?: JsonReader);
555
+
556
+ /**
557
+ * A sign-out, with why the last sign-in ended or null.
558
+ *
559
+ * @param failure Why it ended; left out when nothing failed.
560
+ * @returns The sign-in.
561
+ * @example
562
+ * ```ts
563
+ * import { HostSignIn, SignInFailure } from "@noldova/git.hosting.protocol";
564
+ *
565
+ * console.log(HostSignIn.signedOut().failure, HostSignIn.signedOut(SignInFailure.Revoked).failure);
566
+ * ```
567
+ */
568
+ public static signedOut(failure?: SignInFailure): HostSignIn;
569
+
570
+ /**
571
+ * A sign-in that waits for the person to enter its code.
572
+ *
573
+ * @param deviceCode The code.
574
+ * @returns The sign-in.
575
+ * @example
576
+ * ```ts
577
+ * import { DeviceCode, HostSignIn } from "@noldova/git.hosting.protocol";
578
+ *
579
+ * const signIn = HostSignIn.waiting(new DeviceCode("WDJB-MJHT", "https://github.com/login/device", 1_800_000_000_000));
580
+ * console.log(signIn.deviceCode?.userCode);
581
+ * ```
582
+ */
583
+ public static waiting(deviceCode: DeviceCode): HostSignIn;
584
+
585
+ /**
586
+ * A signed-in account.
587
+ *
588
+ * @param account The account.
589
+ * @returns The sign-in.
590
+ * @example
591
+ * ```ts
592
+ * import { HostAccount, HostSignIn } from "@noldova/git.hosting.protocol";
593
+ *
594
+ * const signIn = HostSignIn.signedIn(new HostAccount("octocat", null, null, ["repo"]));
595
+ * console.log(signIn.account?.login);
596
+ * ```
597
+ */
598
+ public static signedIn(account: HostAccount): HostSignIn;
599
+
600
+ /**
601
+ * Reads a sign-in from its JSON.
602
+ *
603
+ * @param value The JSON, with exactly the fields `toJson` writes.
604
+ * @param path The JSON's path, `$` by default.
605
+ * @returns The sign-in.
606
+ * @throws {JsonException} When the value isn't an object, or a field is missing or of the wrong type; it comes from `@noldova/context.json`.
607
+ * @throws {HostingFieldException} When a field is unknown, out of its range or doesn't fit the state.
608
+ * @example
609
+ * ```ts
610
+ * import { HostSignIn } from "@noldova/git.hosting.protocol";
611
+ *
612
+ * const signIn = HostSignIn.fromJson({ state: "SignedOut", deviceCode: null, account: null, failure: "Expired" });
613
+ * console.log(signIn.state);
614
+ * ```
615
+ */
616
+ public static fromJson(value: unknown, path?: string): HostSignIn;
617
+
618
+ /**
619
+ * Writes the sign-in as JSON: `state`, `deviceCode`, `account` and `failure`, each null when it has none.
620
+ *
621
+ * @returns The JSON.
622
+ * @example
623
+ * ```ts
624
+ * import { HostSignIn } from "@noldova/git.hosting.protocol";
625
+ *
626
+ * console.log(HostSignIn.signedOut().toJson());
627
+ * ```
628
+ */
629
+ public toJson(): JsonObject;
630
+ }
631
+
632
+ /**
633
+ * The member names every host module gives its sign-in's methods and event, after its own module id and a dot.
634
+ *
635
+ * @example
636
+ * ```ts
637
+ * import { HostingNames } from "@noldova/git.hosting.protocol";
638
+ *
639
+ * console.log(HostingNames.nameOf("git-github", HostingNames.readSignInMethod));
640
+ * ```
641
+ */
642
+ export declare class HostingNames {
643
+ /**
644
+ * The method that answers the sign-in as `HostSignIn` JSON.
645
+ */
646
+ public static readonly readSignInMethod: string;
647
+
648
+ /**
649
+ * The method that starts a sign-in, or leaves one that waits or is signed in as it is, and answers the sign-in.
650
+ */
651
+ public static readonly startSignInMethod: string;
652
+
653
+ /**
654
+ * The method that stops a sign-in that waits, and answers the sign-in.
655
+ */
656
+ public static readonly cancelSignInMethod: string;
657
+
658
+ /**
659
+ * The method that forgets the kept token on this computer, and answers the sign-in.
660
+ */
661
+ public static readonly signOutMethod: string;
662
+
663
+ /**
664
+ * The event that carries the sign-in as `HostSignIn` JSON each time it changes.
665
+ */
666
+ public static readonly signInChangedEvent: string;
667
+
668
+ /**
669
+ * The method that takes a `HostReference` as JSON and answers the pull request or issue as `HostItem` JSON, or null when the module can't
670
+ * show it.
671
+ */
672
+ public static readonly readReferenceMethod: string;
673
+
674
+ /**
675
+ * The method that takes a `BranchQuery` as JSON and answers the branch's pull request with its checks as `BranchPullRequest` JSON.
676
+ */
677
+ public static readonly readBranchPullRequestMethod: string;
678
+
679
+ /**
680
+ * The method that takes a `PullRequestDraft` as JSON, opens the pull request on the host and answers it as `HostItem` JSON.
681
+ */
682
+ public static readonly createPullRequestMethod: string;
683
+
684
+ /**
685
+ * A member's full name in a module.
686
+ *
687
+ * @param moduleId The host module's id, such as `git-github`.
688
+ * @param member The member's name.
689
+ * @returns The name, `<module id>.<member>`.
690
+ * @example
691
+ * ```ts
692
+ * import { HostingNames } from "@noldova/git.hosting.protocol";
693
+ *
694
+ * console.log(HostingNames.nameOf("git-github", HostingNames.signOutMethod));
695
+ * ```
696
+ */
697
+ public static nameOf(moduleId: string, member: string): string;
698
+ }
699
+
700
+
701
+ /**
702
+ * An issue or pull request on a host, such as GitHub, by the host module's id, the repository's owner and name, and its number.
703
+ *
704
+ * @example
705
+ * ```ts
706
+ * import { HostReference } from "@noldova/git.hosting.protocol";
707
+ *
708
+ * const reference = new HostReference("git-github", "team", "repo", 7);
709
+ * console.log(reference.text);
710
+ * ```
711
+ */
712
+ export declare class HostReference {
713
+ /**
714
+ * The id of the host module that reads the reference, as its module.json declares it.
715
+ */
716
+ public readonly host: string;
717
+
718
+ /**
719
+ * The owner of the repository on the host: a person or an organization.
720
+ */
721
+ public readonly owner: string;
722
+
723
+ /**
724
+ * The repository's name on the host.
725
+ */
726
+ public readonly repository: string;
727
+
728
+ /**
729
+ * The issue's or pull request's number in its repository.
730
+ */
731
+ public readonly number: number;
732
+
733
+ /**
734
+ * Makes a reference from its parts.
735
+ *
736
+ * @param host The id of the host module that reads the reference, which isn't blank.
737
+ * @param owner The owner of the repository on the host: names of letters, digits, `.`, `_` and `-` joined by `/` for nested groups, none of them `.` or `..`.
738
+ * @param repository The repository's name on the host: letters, digits, `.`, `_` and `-`, other than `.` and `..`.
739
+ * @param number The issue's or pull request's number in its repository, a whole number above zero.
740
+ * @param reader The reader the values came from, so an error names the field by its path; omitted for values that didn't come from JSON.
741
+ * @throws {HostingArgumentException} Without a reader, when a part is out of its range, naming the field as the parameter, such as `number`.
742
+ * @throws {HostingFieldException} With a reader, when a part is out of its range, naming the field by its path, such as `$.number`.
743
+ * @example
744
+ * ```ts
745
+ * import { HostReference } from "@noldova/git.hosting.protocol";
746
+ *
747
+ * const reference = new HostReference("git-github", "team", "repo", 7);
748
+ * ```
749
+ */
750
+ public constructor(host: string, owner: string, repository: string, number: number, reader?: JsonReader);
751
+
752
+ /**
753
+ * The reference as a person writes it: the owner, a slash, the repository, a number sign and the number.
754
+ *
755
+ * @example
756
+ * ```ts
757
+ * import { HostReference } from "@noldova/git.hosting.protocol";
758
+ *
759
+ * console.log(new HostReference("git-github", "team", "repo", 7).text);
760
+ * ```
761
+ */
762
+ public get text(): string;
763
+
764
+ /**
765
+ * Reads a reference from its JSON.
766
+ *
767
+ * @param value The JSON, with exactly the fields `toJson` writes.
768
+ * @param path The JSON's path, `$` by default.
769
+ * @returns The reference.
770
+ * @throws {JsonException} When the value isn't an object, or a field is missing or of the wrong type; it comes from `@noldova/context.json`.
771
+ * @throws {HostingFieldException} When the value holds an unknown field, or a field is out of its range.
772
+ * @example
773
+ * ```ts
774
+ * import { HostReference } from "@noldova/git.hosting.protocol";
775
+ *
776
+ * const reference = HostReference.fromJson({ host: "git-github", owner: "team", repository: "repo", number: 7 });
777
+ * ```
778
+ */
779
+ public static fromJson(value: unknown, path?: string): HostReference;
780
+
781
+ /**
782
+ * Writes the reference as JSON: `host`, `owner`, `repository` and `number`.
783
+ *
784
+ * @returns The JSON.
785
+ * @example
786
+ * ```ts
787
+ * import { HostReference } from "@noldova/git.hosting.protocol";
788
+ *
789
+ * console.log(new HostReference("git-github", "team", "repo", 7).toJson());
790
+ * ```
791
+ */
792
+ public toJson(): JsonObject;
793
+ }
794
+
795
+ /**
796
+ * A person on a host, such as the author of a pull request or an issue: their login and their avatar.
797
+ *
798
+ * @example
799
+ * ```ts
800
+ * import { HostPerson } from "@noldova/git.hosting.protocol";
801
+ *
802
+ * const person = new HostPerson("octocat", "data:image/png;base64,iVBORw0KGgo=", null);
803
+ * console.log(person.login);
804
+ * ```
805
+ */
806
+ export declare class HostPerson {
807
+ /**
808
+ * The person's login on the host.
809
+ */
810
+ public readonly login: string;
811
+
812
+ /**
813
+ * The person's avatar as a base64 data address of a PNG, JPEG, GIF or WebP image of at most 64 KiB, which a window can show under a policy that
814
+ * allows only its own and data images; null when the host gives none or the module couldn't read it.
815
+ */
816
+ public readonly avatar: string | null;
817
+
818
+ /**
819
+ * The person's profile page on the host, an https address as the host gives it, such as an app's page for an app; null when the host gives none.
820
+ */
821
+ public readonly url: string | null;
822
+
823
+ /**
824
+ * Makes a person from their parts.
825
+ *
826
+ * @param login The login, which isn't blank.
827
+ * @param avatar The avatar as a base64 data address of a PNG, JPEG, GIF or WebP image of at most 64 KiB, or null.
828
+ * @param url The profile page as an https address, or null.
829
+ * @param reader The reader the values came from, so an error names the field by its path; omitted for values that didn't come from JSON.
830
+ * @throws {HostingArgumentException} Without a reader, when a part is out of its range, naming the field as the parameter, such as `login`.
831
+ * @throws {HostingFieldException} With a reader, when a part is out of its range, naming the field by its path, such as `$.login`.
832
+ * @example
833
+ * ```ts
834
+ * import { HostPerson } from "@noldova/git.hosting.protocol";
835
+ *
836
+ * const person = new HostPerson("monalisa", null, null);
837
+ * ```
838
+ */
839
+ public constructor(login: string, avatar: string | null, url: string | null, reader?: JsonReader);
840
+
841
+ /**
842
+ * Reads a person from their JSON.
843
+ *
844
+ * @param value The JSON, with exactly the fields `toJson` writes.
845
+ * @param path The JSON's path, `$` by default.
846
+ * @returns The person.
847
+ * @throws {JsonException} When the value isn't an object, or a field is missing or of the wrong type; it comes from `@noldova/context.json`.
848
+ * @throws {HostingFieldException} When the value holds an unknown field, or a field is out of its range.
849
+ * @example
850
+ * ```ts
851
+ * import { HostPerson } from "@noldova/git.hosting.protocol";
852
+ *
853
+ * const person = HostPerson.fromJson({ login: "octocat", avatar: null, url: "https://github.com/octocat" });
854
+ * ```
855
+ */
856
+ public static fromJson(value: unknown, path?: string): HostPerson;
857
+
858
+ /**
859
+ * Writes the person as JSON: `login`, `avatar` and `url`, each of the last two null when there is none.
860
+ *
861
+ * @returns The JSON.
862
+ * @example
863
+ * ```ts
864
+ * import { HostPerson } from "@noldova/git.hosting.protocol";
865
+ *
866
+ * console.log(new HostPerson("hubot", null, null).toJson());
867
+ * ```
868
+ */
869
+ public toJson(): JsonObject;
870
+ }
871
+
872
+ /**
873
+ * What a pull request changes: its lines added and deleted, its files changed, its head and base branches and its head commit.
874
+ *
875
+ * @example
876
+ * ```ts
877
+ * import { HostChanges } from "@noldova/git.hosting.protocol";
878
+ *
879
+ * const changes = new HostChanges(12, 3, 2, "octocat/patch-1", "main", "7fd1a60b01f91b314f59955a4e4d4e80d8edf11d");
880
+ * console.log(changes.headBranch);
881
+ * ```
882
+ */
883
+ export declare class HostChanges {
884
+ /**
885
+ * The lines the pull request adds.
886
+ */
887
+ public readonly additions: number;
888
+
889
+ /**
890
+ * The lines the pull request deletes.
891
+ */
892
+ public readonly deletions: number;
893
+
894
+ /**
895
+ * The files the pull request changes.
896
+ */
897
+ public readonly changedFiles: number;
898
+
899
+ /**
900
+ * The branch whose changes the pull request brings.
901
+ */
902
+ public readonly headBranch: string;
903
+
904
+ /**
905
+ * The branch the pull request merges into.
906
+ */
907
+ public readonly baseBranch: string;
908
+
909
+ /**
910
+ * The head branch's commit the pull request shows, as a full hash.
911
+ */
912
+ public readonly headCommit: string;
913
+
914
+ /**
915
+ * Makes changes from their parts.
916
+ *
917
+ * @param additions The lines added, a whole number, zero or more.
918
+ * @param deletions The lines deleted, a whole number, zero or more.
919
+ * @param changedFiles The files changed, a whole number, zero or more.
920
+ * @param headBranch The head branch, which isn't blank.
921
+ * @param baseBranch The base branch, which isn't blank.
922
+ * @param headCommit The head commit, a full hash of 40 or 64 lowercase hexadecimal digits.
923
+ * @param reader The reader the values came from, so an error names the field by its path; omitted for values that didn't come from JSON.
924
+ * @throws {HostingArgumentException} Without a reader, when a part is out of its range, naming the field as the parameter, such as `headCommit`.
925
+ * @throws {HostingFieldException} With a reader, when a part is out of its range, naming the field by its path, such as `$.headCommit`.
926
+ * @example
927
+ * ```ts
928
+ * import { HostChanges } from "@noldova/git.hosting.protocol";
929
+ *
930
+ * const changes = new HostChanges(0, 0, 0, "monalisa/fix", "main", "6dcb09b5b57875f334f61aebed695e2e4193db5e");
931
+ * ```
932
+ */
933
+ public constructor(additions: number, deletions: number, changedFiles: number, headBranch: string, baseBranch: string, headCommit: string,
934
+ reader?: JsonReader);
935
+
936
+ /**
937
+ * Reads changes from their JSON.
938
+ *
939
+ * @param value The JSON, with exactly the fields `toJson` writes.
940
+ * @param path The JSON's path, `$` by default.
941
+ * @returns The changes.
942
+ * @throws {JsonException} When the value isn't an object, or a field is missing or of the wrong type; it comes from `@noldova/context.json`.
943
+ * @throws {HostingFieldException} When the value holds an unknown field, or a field is out of its range.
944
+ * @example
945
+ * ```ts
946
+ * import { HostChanges } from "@noldova/git.hosting.protocol";
947
+ *
948
+ * const changes = HostChanges.fromJson({
949
+ * additions: 12,
950
+ * deletions: 3,
951
+ * changedFiles: 2,
952
+ * headBranch: "octocat/patch-1",
953
+ * baseBranch: "main",
954
+ * headCommit: "7fd1a60b01f91b314f59955a4e4d4e80d8edf11d"
955
+ * });
956
+ * ```
957
+ */
958
+ public static fromJson(value: unknown, path?: string): HostChanges;
959
+
960
+ /**
961
+ * Writes the changes as JSON: `additions`, `deletions`, `changedFiles`, `headBranch`, `baseBranch` and `headCommit`.
962
+ *
963
+ * @returns The JSON.
964
+ * @example
965
+ * ```ts
966
+ * import { HostChanges } from "@noldova/git.hosting.protocol";
967
+ *
968
+ * console.log(new HostChanges(12, 3, 2, "octocat/patch-1", "main", "7fd1a60b01f91b314f59955a4e4d4e80d8edf11d").toJson());
969
+ * ```
970
+ */
971
+ public toJson(): JsonObject;
972
+ }
973
+
974
+ /**
975
+ * A pull request or an issue as its host shows it: its reference, kind, state, title, page, author, when it was opened and when it was merged or
976
+ * closed, its comments and, for a pull request, its changes.
977
+ *
978
+ * @example
979
+ * ```ts
980
+ * import { HostItem, HostReference, ReferenceKind, ReferenceState } from "@noldova/git.hosting.protocol";
981
+ *
982
+ * const item = new HostItem(new HostReference("git-github", "octocat", "hello-world", 2), ReferenceKind.Issue, ReferenceState.Open,
983
+ * "Add a README", "https://github.com/octocat/hello-world/issues/2", null, 1_700_000_000_000, null, 0, null);
984
+ * console.log(item.title);
985
+ * ```
986
+ */
987
+ export declare class HostItem {
988
+ /**
989
+ * The item's reference: its host module, repository and number.
990
+ */
991
+ public readonly reference: HostReference;
992
+
993
+ /**
994
+ * Whether the item is a pull request or an issue.
995
+ */
996
+ public readonly kind: ReferenceKind;
997
+
998
+ /**
999
+ * Where the item stands: `Open`, `Draft`, `Merged` or `Closed` for a pull request, and `Open`, `ClosedDone` or `ClosedNotPlanned` for an issue.
1000
+ */
1001
+ public readonly state: ReferenceState;
1002
+
1003
+ /**
1004
+ * The item's title.
1005
+ */
1006
+ public readonly title: string;
1007
+
1008
+ /**
1009
+ * The https address of the item's page on the host.
1010
+ */
1011
+ public readonly url: string;
1012
+
1013
+ /**
1014
+ * The person who opened the item, or null when the host no longer knows them.
1015
+ */
1016
+ public readonly author: HostPerson | null;
1017
+
1018
+ /**
1019
+ * When the item was opened, in milliseconds since the Unix epoch.
1020
+ */
1021
+ public readonly createdAt: number;
1022
+
1023
+ /**
1024
+ * When a merged pull request was merged, or a closed pull request or issue was closed, in milliseconds since the Unix epoch; null while it's
1025
+ * open or a draft.
1026
+ */
1027
+ public readonly closedAt: number | null;
1028
+
1029
+ /**
1030
+ * The comments on the item.
1031
+ */
1032
+ public readonly comments: number;
1033
+
1034
+ /**
1035
+ * What the pull request changes, exactly for a pull request; null for an issue.
1036
+ */
1037
+ public readonly changes: HostChanges | null;
1038
+
1039
+ /**
1040
+ * Makes an item from its parts.
1041
+ *
1042
+ * @param reference The reference.
1043
+ * @param kind The kind.
1044
+ * @param state The state, one of the kind's states.
1045
+ * @param title The title, which isn't blank.
1046
+ * @param url The page's https address, with no user name or password.
1047
+ * @param author The author, or null.
1048
+ * @param createdAt When it was opened, a whole number of milliseconds above zero.
1049
+ * @param closedAt When it was merged or closed, a whole number of milliseconds above zero, exactly when the state is neither Open nor Draft.
1050
+ * @param comments The comments, a whole number, zero or more.
1051
+ * @param changes The changes, exactly for a pull request.
1052
+ * @param reader The reader the values came from, so an error names the field by its path; omitted for values that didn't come from JSON.
1053
+ * @throws {HostingArgumentException} Without a reader, when a part is out of its range or doesn't fit the kind, naming the field as the parameter,
1054
+ * such as `changes`.
1055
+ * @throws {HostingFieldException} With a reader, when a part is out of its range or doesn't fit the kind, naming the field by its path, such
1056
+ * as `$.changes`.
1057
+ * @example
1058
+ * ```ts
1059
+ * import { HostChanges, HostItem, HostPerson, HostReference, ReferenceKind, ReferenceState } from "@noldova/git.hosting.protocol";
1060
+ *
1061
+ * const item = new HostItem(new HostReference("git-github", "octocat", "hello-world", 1), ReferenceKind.PullRequest, ReferenceState.Open,
1062
+ * "Fix the greeting", "https://github.com/octocat/hello-world/pull/1",
1063
+ * new HostPerson("monalisa", null, null), 1_700_000_000_000, null, 2,
1064
+ * new HostChanges(12, 3, 2, "monalisa/fix-greeting", "main", "7fd1a60b01f91b314f59955a4e4d4e80d8edf11d"));
1065
+ * ```
1066
+ */
1067
+ public constructor(reference: HostReference, kind: ReferenceKind, state: ReferenceState, title: string, url: string, author: HostPerson | null,
1068
+ createdAt: number, closedAt: number | null, comments: number, changes: HostChanges | null, reader?: JsonReader);
1069
+
1070
+ /**
1071
+ * Reads an item from its JSON.
1072
+ *
1073
+ * @param value The JSON, with exactly the fields `toJson` writes.
1074
+ * @param path The JSON's path, `$` by default.
1075
+ * @returns The item.
1076
+ * @throws {JsonException} When the value isn't an object, a field is missing or of the wrong type, or the kind or state isn't one of its
1077
+ * names; it comes from `@noldova/context.json`.
1078
+ * @throws {HostingFieldException} When the value holds an unknown field, or a field is out of its range or doesn't fit the kind.
1079
+ * @example
1080
+ * ```ts
1081
+ * import { HostItem } from "@noldova/git.hosting.protocol";
1082
+ *
1083
+ * const item = HostItem.fromJson({
1084
+ * reference: { host: "git-github", owner: "octocat", repository: "hello-world", number: 2 },
1085
+ * kind: "Issue",
1086
+ * state: "ClosedDone",
1087
+ * title: "Add a README",
1088
+ * url: "https://github.com/octocat/hello-world/issues/2",
1089
+ * author: { login: "hubot", avatar: null },
1090
+ * createdAt: 1_700_000_000_000,
1091
+ * closedAt: 1_700_000_360_000,
1092
+ * comments: 1,
1093
+ * changes: null
1094
+ * });
1095
+ * ```
1096
+ */
1097
+ public static fromJson(value: unknown, path?: string): HostItem;
1098
+
1099
+ /**
1100
+ * Writes the item as JSON: `reference`, `kind`, `state`, `title`, `url`, `author`, `createdAt`, `closedAt`, `comments` and `changes`, the
1101
+ * author, closing time and changes null when it has none.
1102
+ *
1103
+ * @returns The JSON.
1104
+ * @example
1105
+ * ```ts
1106
+ * import { HostItem, HostReference, ReferenceKind, ReferenceState } from "@noldova/git.hosting.protocol";
1107
+ *
1108
+ * console.log(new HostItem(new HostReference("git-github", "octocat", "hello-world", 2), ReferenceKind.Issue, ReferenceState.Open,
1109
+ * "Add a README", "https://github.com/octocat/hello-world/issues/2", null, 1_700_000_000_000, null, 0, null).toJson());
1110
+ * ```
1111
+ */
1112
+ public toJson(): JsonObject;
1113
+ }
1114
+
1115
+ /**
1116
+ * A check on a commit, such as a CI job: its name, where it stands and its page.
1117
+ *
1118
+ * @example
1119
+ * ```ts
1120
+ * import { CheckState, HostCheck } from "@noldova/git.hosting.protocol";
1121
+ *
1122
+ * const check = new HostCheck("build", CheckState.Succeeded, "https://github.com/octocat/hello-world/actions/runs/1");
1123
+ * console.log(check.state);
1124
+ * ```
1125
+ */
1126
+ export declare class HostCheck {
1127
+ /**
1128
+ * The check's name on the host.
1129
+ */
1130
+ public readonly name: string;
1131
+
1132
+ /**
1133
+ * Where the check stands.
1134
+ */
1135
+ public readonly state: CheckState;
1136
+
1137
+ /**
1138
+ * The https address of the check's page on the host, or null when it has none.
1139
+ */
1140
+ public readonly url: string | null;
1141
+
1142
+ /**
1143
+ * Makes a check from its parts.
1144
+ *
1145
+ * @param name The name, which isn't blank.
1146
+ * @param state Where it stands.
1147
+ * @param url The page's https address, with no user name or password, or null.
1148
+ * @param reader The reader the values came from, so an error names the field by its path; omitted for values that didn't come from JSON.
1149
+ * @throws {HostingArgumentException} Without a reader, when a part is out of its range, naming the field as the parameter, such as `url`.
1150
+ * @throws {HostingFieldException} With a reader, when a part is out of its range, naming the field by its path, such as `$.url`.
1151
+ * @example
1152
+ * ```ts
1153
+ * import { CheckState, HostCheck } from "@noldova/git.hosting.protocol";
1154
+ *
1155
+ * const check = new HostCheck("lint", CheckState.Running, null);
1156
+ * ```
1157
+ */
1158
+ public constructor(name: string, state: CheckState, url: string | null, reader?: JsonReader);
1159
+
1160
+ /**
1161
+ * Reads a check from its JSON.
1162
+ *
1163
+ * @param value The JSON, with exactly the fields `toJson` writes.
1164
+ * @param path The JSON's path, `$` by default.
1165
+ * @returns The check.
1166
+ * @throws {JsonException} When the value isn't an object, a field is missing or of the wrong type, or the state isn't one of its names; it
1167
+ * comes from `@noldova/context.json`.
1168
+ * @throws {HostingFieldException} When the value holds an unknown field, or a field is out of its range.
1169
+ * @example
1170
+ * ```ts
1171
+ * import { HostCheck } from "@noldova/git.hosting.protocol";
1172
+ *
1173
+ * const check = HostCheck.fromJson({ name: "build", state: "Failed", url: "https://github.com/octocat/hello-world/actions/runs/1" });
1174
+ * ```
1175
+ */
1176
+ public static fromJson(value: unknown, path?: string): HostCheck;
1177
+
1178
+ /**
1179
+ * Writes the check as JSON: `name`, `state` and `url`, null when it has none.
1180
+ *
1181
+ * @returns The JSON.
1182
+ * @example
1183
+ * ```ts
1184
+ * import { CheckState, HostCheck } from "@noldova/git.hosting.protocol";
1185
+ *
1186
+ * console.log(new HostCheck("lint", CheckState.Queued, null).toJson());
1187
+ * ```
1188
+ */
1189
+ public toJson(): JsonObject;
1190
+ }
1191
+
1192
+ /**
1193
+ * A question for a branch's pull request on a host: the host, the repository's path, the branch and the commit whose checks to read.
1194
+ *
1195
+ * @example
1196
+ * ```ts
1197
+ * import { BranchQuery } from "@noldova/git.hosting.protocol";
1198
+ *
1199
+ * const query = new BranchQuery("github.com", "octocat/hello-world", "octocat/patch-1", "7fd1a60b01f91b314f59955a4e4d4e80d8edf11d");
1200
+ * console.log(query.toJson());
1201
+ * ```
1202
+ */
1203
+ export declare class BranchQuery {
1204
+ /**
1205
+ * The host the repository is on, such as `github.com`.
1206
+ */
1207
+ public readonly host: string;
1208
+
1209
+ /**
1210
+ * The repository's path on the host, such as `octocat/hello-world`.
1211
+ */
1212
+ public readonly path: string;
1213
+
1214
+ /**
1215
+ * The branch whose pull request to read.
1216
+ */
1217
+ public readonly branch: string;
1218
+
1219
+ /**
1220
+ * The commit whose checks to read, as a full hash, or null for the pull request's own head.
1221
+ */
1222
+ public readonly headCommit: string | null;
1223
+
1224
+ /**
1225
+ * Makes a query from its parts.
1226
+ *
1227
+ * @param host The host, which isn't blank.
1228
+ * @param path The repository's path: names of letters, digits, `.`, `_` and `-` joined by `/`, none of them `.` or `..`.
1229
+ * @param branch The branch, which isn't blank.
1230
+ * @param headCommit The commit, a full hash of 40 or 64 lowercase hexadecimal digits, or null.
1231
+ * @param reader The reader the values came from, so an error names the field by its path; omitted for values that didn't come from JSON.
1232
+ * @throws {HostingArgumentException} Without a reader, when a part is out of its range, naming the field as the parameter, such as `headCommit`.
1233
+ * @throws {HostingFieldException} With a reader, when a part is out of its range, naming the field by its path, such as `$.headCommit`.
1234
+ * @example
1235
+ * ```ts
1236
+ * import { BranchQuery } from "@noldova/git.hosting.protocol";
1237
+ *
1238
+ * const query = new BranchQuery("github.com", "octocat/hello-world", "monalisa/fix", null);
1239
+ * ```
1240
+ */
1241
+ public constructor(host: string, path: string, branch: string, headCommit: string | null, reader?: JsonReader);
1242
+
1243
+ /**
1244
+ * Reads a query from its JSON.
1245
+ *
1246
+ * @param value The JSON, with exactly the fields `toJson` writes.
1247
+ * @param path The JSON's path, `$` by default.
1248
+ * @returns The query.
1249
+ * @throws {JsonException} When the value isn't an object, or a field is missing or of the wrong type; it comes from `@noldova/context.json`.
1250
+ * @throws {HostingFieldException} When the value holds an unknown field, or a field is out of its range.
1251
+ * @example
1252
+ * ```ts
1253
+ * import { BranchQuery } from "@noldova/git.hosting.protocol";
1254
+ *
1255
+ * const query = BranchQuery.fromJson({ host: "github.com", path: "octocat/hello-world", branch: "octocat/patch-1", headCommit: null });
1256
+ * ```
1257
+ */
1258
+ public static fromJson(value: unknown, path?: string): BranchQuery;
1259
+
1260
+ /**
1261
+ * Writes the query as JSON: `host`, `path`, `branch` and `headCommit`, null when there is none.
1262
+ *
1263
+ * @returns The JSON.
1264
+ * @example
1265
+ * ```ts
1266
+ * import { BranchQuery } from "@noldova/git.hosting.protocol";
1267
+ *
1268
+ * console.log(new BranchQuery("github.com", "octocat/hello-world", "octocat/patch-1", null).toJson());
1269
+ * ```
1270
+ */
1271
+ public toJson(): JsonObject;
1272
+ }
1273
+
1274
+ /**
1275
+ * A branch's pull request on a host, or none, and the checks on its commit.
1276
+ *
1277
+ * @example
1278
+ * ```ts
1279
+ * import type { BranchPullRequest } from "@noldova/git.hosting.protocol";
1280
+ *
1281
+ * function describe(answer: BranchPullRequest): string {
1282
+ * return answer.pullRequest === null ? "no pull request" : `${answer.pullRequest.reference.text}: ${answer.checksState ?? "no checks"}`;
1283
+ * }
1284
+ * ```
1285
+ */
1286
+ export declare class BranchPullRequest {
1287
+ /**
1288
+ * The branch's pull request, or null when it has none.
1289
+ */
1290
+ public readonly pullRequest: HostItem | null;
1291
+
1292
+ /**
1293
+ * The checks on the commit, none when there is no pull request.
1294
+ */
1295
+ public readonly checks: readonly HostCheck[];
1296
+
1297
+ /**
1298
+ * Makes an answer from its parts.
1299
+ *
1300
+ * @param pullRequest The pull request, an item of the kind `PullRequest`, or null.
1301
+ * @param checks The checks, none when the pull request is null.
1302
+ * @param reader The reader the values came from, so an error names the field by its path; omitted for values that didn't come from JSON.
1303
+ * @throws {HostingArgumentException} Without a reader, when the item isn't a pull request or there are checks with no pull request, naming the field
1304
+ * as the parameter, `pullRequest` or `checks`.
1305
+ * @throws {HostingFieldException} With a reader, when the item isn't a pull request or there are checks with no pull request, naming the
1306
+ * field by its path, such as `$.checks`.
1307
+ * @example
1308
+ * ```ts
1309
+ * import { BranchPullRequest } from "@noldova/git.hosting.protocol";
1310
+ *
1311
+ * const none = new BranchPullRequest(null, []);
1312
+ * ```
1313
+ */
1314
+ public constructor(pullRequest: HostItem | null, checks: readonly HostCheck[], reader?: JsonReader);
1315
+
1316
+ /**
1317
+ * The worst state among the checks, in the order `Failed`, `Running`, `Queued`, `Succeeded` and `Neutral`, or null when there are no checks.
1318
+ *
1319
+ * @example
1320
+ * ```ts
1321
+ * import { type BranchPullRequest, CheckState } from "@noldova/git.hosting.protocol";
1322
+ *
1323
+ * function isFailing(answer: BranchPullRequest): boolean {
1324
+ * return answer.checksState === CheckState.Failed;
1325
+ * }
1326
+ * ```
1327
+ */
1328
+ public get checksState(): CheckState | null;
1329
+
1330
+ /**
1331
+ * Reads an answer from its JSON.
1332
+ *
1333
+ * @param value The JSON, with exactly the fields `toJson` writes.
1334
+ * @param path The JSON's path, `$` by default.
1335
+ * @returns The answer.
1336
+ * @throws {JsonException} When the value isn't an object, or a field is missing or of the wrong type; it comes from `@noldova/context.json`.
1337
+ * @throws {HostingFieldException} When the value holds an unknown field, a field is out of its range, the item isn't a pull request, or
1338
+ * there are checks with no pull request.
1339
+ * @example
1340
+ * ```ts
1341
+ * import { BranchPullRequest } from "@noldova/git.hosting.protocol";
1342
+ *
1343
+ * const none = BranchPullRequest.fromJson({ pullRequest: null, checks: [] });
1344
+ * ```
1345
+ */
1346
+ public static fromJson(value: unknown, path?: string): BranchPullRequest;
1347
+
1348
+ /**
1349
+ * Writes the answer as JSON: `pullRequest`, null when there is none, and `checks`.
1350
+ *
1351
+ * @returns The JSON.
1352
+ * @example
1353
+ * ```ts
1354
+ * import { BranchPullRequest } from "@noldova/git.hosting.protocol";
1355
+ *
1356
+ * console.log(new BranchPullRequest(null, []).toJson());
1357
+ * ```
1358
+ */
1359
+ public toJson(): JsonObject;
1360
+ }
1361
+
1362
+ /**
1363
+ * A pull request to open on a host: the host, the repository's path, the head and base branches, the title, the body and whether it
1364
+ * opens as a draft.
1365
+ *
1366
+ * @example
1367
+ * ```ts
1368
+ * import { PullRequestDraft } from "@noldova/git.hosting.protocol";
1369
+ *
1370
+ * const draft = new PullRequestDraft("github.com", "octocat/hello-world", "octocat/patch-1", "main", "Fix the greeting", "", true);
1371
+ * console.log(draft.toJson());
1372
+ * ```
1373
+ */
1374
+ export declare class PullRequestDraft {
1375
+ /**
1376
+ * The host the repository is on, such as `github.com`.
1377
+ */
1378
+ public readonly host: string;
1379
+
1380
+ /**
1381
+ * The repository's path on the host, such as `octocat/hello-world`.
1382
+ */
1383
+ public readonly path: string;
1384
+
1385
+ /**
1386
+ * The branch whose changes the pull request brings.
1387
+ */
1388
+ public readonly headBranch: string;
1389
+
1390
+ /**
1391
+ * The branch the pull request merges into.
1392
+ */
1393
+ public readonly baseBranch: string;
1394
+
1395
+ /**
1396
+ * The pull request's title.
1397
+ */
1398
+ public readonly title: string;
1399
+
1400
+ /**
1401
+ * The pull request's description, which may be empty.
1402
+ */
1403
+ public readonly body: string;
1404
+
1405
+ /**
1406
+ * Whether the pull request opens as a draft.
1407
+ */
1408
+ public readonly isDraft: boolean;
1409
+
1410
+ /**
1411
+ * Makes a draft from its parts.
1412
+ *
1413
+ * @param host The host, which isn't blank.
1414
+ * @param path The repository's path: names of letters, digits, `.`, `_` and `-` joined by `/`, none of them `.` or `..`.
1415
+ * @param headBranch The head branch, which isn't blank.
1416
+ * @param baseBranch The base branch, which isn't blank and isn't the head branch.
1417
+ * @param title The title, which isn't blank.
1418
+ * @param body The description, any text.
1419
+ * @param isDraft Whether it opens as a draft.
1420
+ * @param reader The reader the values came from, so an error names the field by its path; omitted for values that didn't come from JSON.
1421
+ * @throws {HostingArgumentException} Without a reader, when a part is out of its range or the base branch is the head branch, naming the field as the
1422
+ * parameter, such as `baseBranch`.
1423
+ * @throws {HostingFieldException} With a reader, when a part is out of its range or the base branch is the head branch, naming the field by
1424
+ * its path, such as `$.baseBranch`.
1425
+ * @example
1426
+ * ```ts
1427
+ * import { PullRequestDraft } from "@noldova/git.hosting.protocol";
1428
+ *
1429
+ * const draft = new PullRequestDraft("github.com", "octocat/hello-world", "monalisa/fix", "main", "Fix the greeting", "Closes #2.", false);
1430
+ * ```
1431
+ */
1432
+ public constructor(host: string, path: string, headBranch: string, baseBranch: string, title: string, body: string, isDraft: boolean,
1433
+ reader?: JsonReader);
1434
+
1435
+ /**
1436
+ * Reads a draft from its JSON.
1437
+ *
1438
+ * @param value The JSON, with exactly the fields `toJson` writes.
1439
+ * @param path The JSON's path, `$` by default.
1440
+ * @returns The draft.
1441
+ * @throws {JsonException} When the value isn't an object, or a field is missing or of the wrong type; it comes from `@noldova/context.json`.
1442
+ * @throws {HostingFieldException} When the value holds an unknown field, a field is out of its range, or the base branch is the head branch.
1443
+ * @example
1444
+ * ```ts
1445
+ * import { PullRequestDraft } from "@noldova/git.hosting.protocol";
1446
+ *
1447
+ * const draft = PullRequestDraft.fromJson({
1448
+ * host: "github.com",
1449
+ * path: "octocat/hello-world",
1450
+ * headBranch: "octocat/patch-1",
1451
+ * baseBranch: "main",
1452
+ * title: "Fix the greeting",
1453
+ * body: "",
1454
+ * isDraft: true
1455
+ * });
1456
+ * ```
1457
+ */
1458
+ public static fromJson(value: unknown, path?: string): PullRequestDraft;
1459
+
1460
+ /**
1461
+ * Writes the draft as JSON: `host`, `path`, `headBranch`, `baseBranch`, `title`, `body` and `isDraft`.
1462
+ *
1463
+ * @returns The JSON.
1464
+ * @example
1465
+ * ```ts
1466
+ * import { PullRequestDraft } from "@noldova/git.hosting.protocol";
1467
+ *
1468
+ * console.log(new PullRequestDraft("github.com", "octocat/hello-world", "octocat/patch-1", "main", "Fix the greeting", "", true).toJson());
1469
+ * ```
1470
+ */
1471
+ public toJson(): JsonObject;
1472
+ }