@noldova/git.hosting.protocol 0.0.12 → 0.0.14

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@noldova/git.hosting.protocol",
3
- "version": "0.0.12",
3
+ "version": "0.0.14",
4
4
  "description": "The hosting protocol that each of Git's host modules implements: a reference to an issue or pull request, the item and its checks, a branch's pull request, a pull request draft, and the sign-in's account and device code.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -34,5 +34,5 @@
34
34
  "@noldova/context.exceptions": ">=0.0.18 <0.1.0",
35
35
  "@noldova/context.json": ">=0.0.18 <0.1.0"
36
36
  },
37
- "gitHead": "20d594ec9f183a11399993db53d2e6510e31e41f"
37
+ "gitHead": "a900e302eac2bbdfd14e6727962556c66b156e7a"
38
38
  }
@@ -877,12 +877,21 @@ export declare class HostingNames {
877
877
  public static readonly readReviewRequestsMethod: string;
878
878
 
879
879
  /**
880
- * The method that takes an `AccountQuery` as JSON and answers the repositories that account can clone as `HostRepositoryList` JSON, the most
881
- * recently pushed first where the host tells when; for an account that isn't signed in, `HostRepositoryList.signedOut()`, having asked the host
882
- * nothing.
880
+ * The method that takes a `RepositoryListQuery` as JSON and answers the repositories that account can clone as `HostRepositoryList` JSON, the
881
+ * most recently pushed first where the host tells when; a fresh query reads them from the host even when the module holds a recent answer. For an
882
+ * account that isn't signed in, `HostRepositoryList.signedOut()`, having asked the host nothing. An `AccountQuery`'s JSON reads as a query that
883
+ * isn't fresh.
883
884
  */
884
885
  public static readonly readRepositoriesMethod: string;
885
886
 
887
+ /**
888
+ * The method that takes a `RepositorySearch` as JSON and answers the repositories that account can clone whose name holds the search's text,
889
+ * ignoring case, as `HostRepositoryList` JSON, in the order `readRepositoriesMethod` gives them; it looks past the repositories that method
890
+ * answers, through as many as the host lets it read in one search, and `hasMore` says when it stopped before the account's last. For an account
891
+ * that isn't signed in, `HostRepositoryList.signedOut()`, having asked the host nothing.
892
+ */
893
+ public static readonly searchRepositoriesMethod: string;
894
+
886
895
  /**
887
896
  * The method that takes a `CommitQuery` as JSON and answers the review comments on that commit as `HostCommitComments` JSON: their count, whether
888
897
  * a page of the host's answer was full, and the page that shows them; `HostCommitComments.none()` when signed out, for another host, or when the host
@@ -5197,6 +5206,17 @@ export declare class HostRepository {
5197
5206
  */
5198
5207
  public readonly pushedAt: number | null;
5199
5208
 
5209
+ /**
5210
+ * Who the repository belongs to on the host, by which a list groups it: the owner's login on GitHub, such as `octocat`, and the project on Azure
5211
+ * DevOps, such as `Fabrikam`.
5212
+ */
5213
+ public readonly owner: string;
5214
+
5215
+ /**
5216
+ * Whether the repository is a fork of another.
5217
+ */
5218
+ public readonly isFork: boolean;
5219
+
5200
5220
  /**
5201
5221
  * Makes a repository from its parts.
5202
5222
  *
@@ -5204,6 +5224,8 @@ export declare class HostRepository {
5204
5224
  * @param url The https clone address.
5205
5225
  * @param isPrivate Whether it is private.
5206
5226
  * @param pushedAt When it was last pushed to, a positive number of milliseconds since 1970, or null.
5227
+ * @param owner Who it belongs to, not empty.
5228
+ * @param isFork Whether it is a fork.
5207
5229
  * @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.
5208
5230
  * @throws {HostingArgumentException} Without a reader, when a part is out of its range, naming the field as the parameter, such as `url`.
5209
5231
  * @throws {HostingFieldException} With a reader, when a part is out of its range, naming the field by its path, such as `$.url`.
@@ -5211,10 +5233,10 @@ export declare class HostRepository {
5211
5233
  * ```ts
5212
5234
  * import { HostRepository } from "@noldova/git.hosting.protocol";
5213
5235
  *
5214
- * const repository = new HostRepository("octocat/hello-world", "https://github.com/octocat/hello-world.git", false, 1_700_000_000_000);
5236
+ * const repository = new HostRepository("octocat/hello-world", "https://github.com/octocat/hello-world.git", false, 1_700_000_000_000, "octocat", false);
5215
5237
  * ```
5216
5238
  */
5217
- public constructor(name: string, url: string, isPrivate: boolean, pushedAt: number | null, reader?: JsonReader);
5239
+ public constructor(name: string, url: string, isPrivate: boolean, pushedAt: number | null, owner: string, isFork: boolean, reader?: JsonReader);
5218
5240
 
5219
5241
  /**
5220
5242
  * Reads a repository from its JSON.
@@ -5229,20 +5251,20 @@ export declare class HostRepository {
5229
5251
  * import { HostRepository } from "@noldova/git.hosting.protocol";
5230
5252
  *
5231
5253
  * const repository = HostRepository.fromJson({ name: "octocat/hello-world", url: "https://github.com/octocat/hello-world.git", isPrivate: false,
5232
- * pushedAt: null });
5254
+ * pushedAt: null, owner: "octocat", isFork: false });
5233
5255
  * ```
5234
5256
  */
5235
5257
  public static fromJson(value: unknown, path?: string): HostRepository;
5236
5258
 
5237
5259
  /**
5238
- * Writes the repository as JSON: `name`, `url`, `isPrivate` and `pushedAt`.
5260
+ * Writes the repository as JSON: `name`, `url`, `isPrivate`, `pushedAt`, `owner` and `isFork`.
5239
5261
  *
5240
5262
  * @returns The JSON.
5241
5263
  * @example
5242
5264
  * ```ts
5243
5265
  * import { HostRepository } from "@noldova/git.hosting.protocol";
5244
5266
  *
5245
- * console.log(new HostRepository("octocat/hello-world", "https://github.com/octocat/hello-world.git", false, null).toJson());
5267
+ * console.log(new HostRepository("octocat/hello-world", "https://github.com/octocat/hello-world.git", false, null, "octocat", false).toJson());
5246
5268
  * ```
5247
5269
  */
5248
5270
  public toJson(): JsonObject;
@@ -5341,6 +5363,158 @@ export declare class HostRepositoryList {
5341
5363
  public toJson(): JsonObject;
5342
5364
  }
5343
5365
 
5366
+ /**
5367
+ * A read of the repositories one of the accounts a module keeps can clone, from the host itself or from the module's recent answer.
5368
+ *
5369
+ * @example
5370
+ * ```ts
5371
+ * import { RepositoryListQuery } from "@noldova/git.hosting.protocol";
5372
+ *
5373
+ * const query = new RepositoryListQuery(2, true);
5374
+ * ```
5375
+ */
5376
+ export declare class RepositoryListQuery {
5377
+ /**
5378
+ * The account's id, which the module gave it when it was added; the first account is 1.
5379
+ */
5380
+ public readonly account: number;
5381
+
5382
+ /**
5383
+ * Whether the module reads the list from the host even when it holds a recent answer, as when the person asks for the list again.
5384
+ */
5385
+ public readonly isFresh: boolean;
5386
+
5387
+ /**
5388
+ * Makes the query from its parts.
5389
+ *
5390
+ * @param account The account's id, a positive whole number.
5391
+ * @param isFresh Whether the module reads the list from the host even when it holds a recent answer.
5392
+ * @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.
5393
+ * @throws {HostingArgumentException} Without a reader, when the account is out of its range, naming the field as the parameter, `account`.
5394
+ * @throws {HostingFieldException} With a reader, when the account is out of its range, naming the field by its path, `$.account`.
5395
+ * @example
5396
+ * ```ts
5397
+ * import { RepositoryListQuery } from "@noldova/git.hosting.protocol";
5398
+ *
5399
+ * const query = new RepositoryListQuery(1, false);
5400
+ * ```
5401
+ */
5402
+ public constructor(account: number, isFresh: boolean, reader?: JsonReader);
5403
+
5404
+ /**
5405
+ * Reads it from its JSON.
5406
+ *
5407
+ * @param value The JSON, with the fields `toJson` writes; without `isFresh`, as an `AccountQuery` writes it, the query isn't fresh.
5408
+ * @param path The JSON's path, `$` by default.
5409
+ * @returns The query.
5410
+ * @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`.
5411
+ * @throws {HostingFieldException} When the value holds an unknown field, or the account is out of its range.
5412
+ * @example
5413
+ * ```ts
5414
+ * import { RepositoryListQuery } from "@noldova/git.hosting.protocol";
5415
+ *
5416
+ * const query = RepositoryListQuery.fromJson({ account: 2, isFresh: true });
5417
+ * ```
5418
+ */
5419
+ public static fromJson(value: unknown, path?: string): RepositoryListQuery;
5420
+
5421
+ /**
5422
+ * Writes it as JSON: `account` and `isFresh`.
5423
+ *
5424
+ * @returns The JSON object.
5425
+ * @example
5426
+ * ```ts
5427
+ * import { RepositoryListQuery } from "@noldova/git.hosting.protocol";
5428
+ *
5429
+ * const json = new RepositoryListQuery(2, false).toJson();
5430
+ * ```
5431
+ */
5432
+ public toJson(): JsonObject;
5433
+ }
5434
+
5435
+ /**
5436
+ * A search of the repositories one of the accounts a module keeps can clone, by a text their names hold.
5437
+ *
5438
+ * @example
5439
+ * ```ts
5440
+ * import { RepositorySearch } from "@noldova/git.hosting.protocol";
5441
+ *
5442
+ * const search = new RepositorySearch(2, "hello");
5443
+ * ```
5444
+ */
5445
+ export declare class RepositorySearch {
5446
+ /**
5447
+ * The account's id, which the module gave it when it was added; the first account is 1.
5448
+ */
5449
+ public readonly account: number;
5450
+
5451
+ /**
5452
+ * The text a repository's name holds, ignoring case and the text's leading and trailing spaces.
5453
+ */
5454
+ public readonly text: string;
5455
+
5456
+ /**
5457
+ * Makes the search from its parts.
5458
+ *
5459
+ * @param account The account's id, a positive whole number.
5460
+ * @param text The text, not blank.
5461
+ * @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.
5462
+ * @throws {HostingArgumentException} Without a reader, when a part is out of its range, naming the field as the parameter, such as `text`.
5463
+ * @throws {HostingFieldException} With a reader, when a part is out of its range, naming the field by its path, such as `$.text`.
5464
+ * @example
5465
+ * ```ts
5466
+ * import { RepositorySearch } from "@noldova/git.hosting.protocol";
5467
+ *
5468
+ * const search = new RepositorySearch(1, "website");
5469
+ * ```
5470
+ */
5471
+ public constructor(account: number, text: string, reader?: JsonReader);
5472
+
5473
+ /**
5474
+ * Reads it from its JSON.
5475
+ *
5476
+ * @param value The JSON, with exactly the fields `toJson` writes.
5477
+ * @param path The JSON's path, `$` by default.
5478
+ * @returns The search.
5479
+ * @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`.
5480
+ * @throws {HostingFieldException} When the value holds an unknown field, or a field is out of its range.
5481
+ * @example
5482
+ * ```ts
5483
+ * import { RepositorySearch } from "@noldova/git.hosting.protocol";
5484
+ *
5485
+ * const search = RepositorySearch.fromJson({ account: 2, text: "hello" });
5486
+ * ```
5487
+ */
5488
+ public static fromJson(value: unknown, path?: string): RepositorySearch;
5489
+
5490
+ /**
5491
+ * Whether a repository's name holds the search's text, ignoring case.
5492
+ *
5493
+ * @param name The repository's name, such as `octocat/hello-world`.
5494
+ * @returns Whether it matches.
5495
+ * @example
5496
+ * ```ts
5497
+ * import { RepositorySearch } from "@noldova/git.hosting.protocol";
5498
+ *
5499
+ * console.log(new RepositorySearch(1, "Hello").matches("octocat/hello-world"));
5500
+ * ```
5501
+ */
5502
+ public matches(name: string): boolean;
5503
+
5504
+ /**
5505
+ * Writes it as JSON: `account` and `text`.
5506
+ *
5507
+ * @returns The JSON.
5508
+ * @example
5509
+ * ```ts
5510
+ * import { RepositorySearch } from "@noldova/git.hosting.protocol";
5511
+ *
5512
+ * console.log(new RepositorySearch(2, "hello").toJson());
5513
+ * ```
5514
+ */
5515
+ public toJson(): JsonObject;
5516
+ }
5517
+
5344
5518
  /**
5345
5519
  * One of the accounts a module keeps, by its id, for a sign-in method that acts on one account.
5346
5520
  *
package/src/api/index.js CHANGED
@@ -72,7 +72,9 @@ export { HostingNames } from "../models/hosting-names.js";
72
72
  export { PersonQuery } from "../models/person-query.js";
73
73
  export { PullRequestDraft } from "../models/pull-request-draft.js";
74
74
  export { RepositoryAccount } from "../models/repository-account.js";
75
+ export { RepositoryListQuery } from "../models/repository-list-query.js";
75
76
  export { RepositoryQuery } from "../models/repository-query.js";
77
+ export { RepositorySearch } from "../models/repository-search.js";
76
78
  export { WorkItemQuery } from "../models/work-item-query.js";
77
79
  export { WorkItemUpdate } from "../models/work-item-update.js";
78
80
  export { WorkItemsQuery } from "../models/work-items-query.js";
@@ -10,32 +10,40 @@ import { JsonReader } from "@noldova/context.json";
10
10
  import { Resources } from "../resources.js";
11
11
  import { FieldCheck } from "./field-check.js";
12
12
  export class HostRepository {
13
- static FIELDS = [Resources.nameField, Resources.urlField, Resources.isPrivateField, Resources.pushedAtField];
13
+ static FIELDS = [Resources.nameField, Resources.urlField, Resources.isPrivateField, Resources.pushedAtField,
14
+ Resources.ownerField, Resources.isForkField];
14
15
  name;
15
16
  url;
16
17
  isPrivate;
17
18
  pushedAt;
18
- constructor(name, url, isPrivate, pushedAt, reader) {
19
+ owner;
20
+ isFork;
21
+ constructor(name, url, isPrivate, pushedAt, owner, isFork, reader) {
19
22
  FieldCheck.requireText(name, Resources.nameField, reader);
20
23
  FieldCheck.requireHttps(url, Resources.urlField, reader);
21
24
  if (!Object.isNull(pushedAt))
22
25
  FieldCheck.requirePositive(pushedAt, Resources.pushedAtField, reader);
26
+ FieldCheck.requireText(owner, Resources.ownerField, reader);
23
27
  this.name = name;
24
28
  this.url = url;
25
29
  this.isPrivate = isPrivate;
26
30
  this.pushedAt = pushedAt;
31
+ this.owner = owner;
32
+ this.isFork = isFork;
27
33
  }
28
34
  static fromJson(value, path) {
29
35
  const reader = JsonReader.fromValue(value, path);
30
36
  FieldCheck.refuseUnknownFields(reader, HostRepository.FIELDS);
31
- return new HostRepository(reader.readString(Resources.nameField), reader.readString(Resources.urlField), reader.readBoolean(Resources.isPrivateField), reader.readNullableInteger(Resources.pushedAtField), reader);
37
+ return new HostRepository(reader.readString(Resources.nameField), reader.readString(Resources.urlField), reader.readBoolean(Resources.isPrivateField), reader.readNullableInteger(Resources.pushedAtField), reader.readString(Resources.ownerField), reader.readBoolean(Resources.isForkField), reader);
32
38
  }
33
39
  toJson() {
34
40
  return {
35
41
  [Resources.nameField]: this.name,
36
42
  [Resources.urlField]: this.url,
37
43
  [Resources.isPrivateField]: this.isPrivate,
38
- [Resources.pushedAtField]: this.pushedAt
44
+ [Resources.pushedAtField]: this.pushedAt,
45
+ [Resources.ownerField]: this.owner,
46
+ [Resources.isForkField]: this.isFork
39
47
  };
40
48
  }
41
49
  }
@@ -32,6 +32,7 @@ export class HostingNames {
32
32
  static readPullRequestsMethod = "readPullRequests";
33
33
  static readReviewRequestsMethod = "readReviewRequests";
34
34
  static readRepositoriesMethod = "readRepositories";
35
+ static searchRepositoriesMethod = "searchRepositories";
35
36
  static readCommitCommentsMethod = "readCommitComments";
36
37
  static readPullRequestThreadsMethod = "readPullRequestThreads";
37
38
  static rateLimitedUntilDetail = "rateLimitedUntil";
@@ -0,0 +1,28 @@
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
+ import { JsonReader } from "@noldova/context.json";
9
+ import { Resources } from "../resources.js";
10
+ import { FieldCheck } from "./field-check.js";
11
+ export class RepositoryListQuery {
12
+ static FIELDS = [Resources.accountField, Resources.isFreshField];
13
+ account;
14
+ isFresh;
15
+ constructor(account, isFresh, reader) {
16
+ FieldCheck.requirePositive(account, Resources.accountField, reader);
17
+ this.account = account;
18
+ this.isFresh = isFresh;
19
+ }
20
+ static fromJson(value, path) {
21
+ const reader = JsonReader.fromValue(value, path);
22
+ FieldCheck.refuseUnknownFields(reader, RepositoryListQuery.FIELDS);
23
+ return new RepositoryListQuery(reader.readInteger(Resources.accountField), reader.hasField(Resources.isFreshField) && reader.readBoolean(Resources.isFreshField), reader);
24
+ }
25
+ toJson() {
26
+ return { [Resources.accountField]: this.account, [Resources.isFreshField]: this.isFresh };
27
+ }
28
+ }
@@ -0,0 +1,32 @@
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
+ import { JsonReader } from "@noldova/context.json";
9
+ import { Resources } from "../resources.js";
10
+ import { FieldCheck } from "./field-check.js";
11
+ export class RepositorySearch {
12
+ static FIELDS = [Resources.accountField, Resources.textField];
13
+ account;
14
+ text;
15
+ constructor(account, text, reader) {
16
+ FieldCheck.requirePositive(account, Resources.accountField, reader);
17
+ FieldCheck.requireText(text, Resources.textField, reader);
18
+ this.account = account;
19
+ this.text = text;
20
+ }
21
+ static fromJson(value, path) {
22
+ const reader = JsonReader.fromValue(value, path);
23
+ FieldCheck.refuseUnknownFields(reader, RepositorySearch.FIELDS);
24
+ return new RepositorySearch(reader.readInteger(Resources.accountField), reader.readString(Resources.textField), reader);
25
+ }
26
+ matches(name) {
27
+ return name.toLowerCase().includes(this.text.trim().toLowerCase());
28
+ }
29
+ toJson() {
30
+ return { [Resources.accountField]: this.account, [Resources.textField]: this.text };
31
+ }
32
+ }
package/src/resources.js CHANGED
@@ -138,6 +138,9 @@ export class Resources {
138
138
  static isDraftField = "isDraft";
139
139
  static isPrivateField = "isPrivate";
140
140
  static pushedAtField = "pushedAt";
141
+ static isForkField = "isFork";
142
+ static isFreshField = "isFresh";
143
+ static textField = "text";
141
144
  static capabilitiesField = "capabilities";
142
145
  static personField = "person";
143
146
  static voteField = "vote";