@noldova/git.hosting.protocol 0.0.6 → 0.0.8

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.
Files changed (52) hide show
  1. package/package.json +4 -4
  2. package/src/api/index.d.ts +3697 -122
  3. package/src/api/index.js +42 -0
  4. package/src/enums/file-change-kind.js +13 -0
  5. package/src/enums/host-capability.js +23 -0
  6. package/src/enums/policy-state.js +14 -0
  7. package/src/enums/pull-request-status.js +13 -0
  8. package/src/enums/thread-status.js +16 -0
  9. package/src/enums/work-item-category.js +14 -0
  10. package/src/enums/work-item-scope.js +11 -0
  11. package/src/models/author-query.js +40 -0
  12. package/src/models/branch-pull-request.js +11 -4
  13. package/src/models/commit-query.js +32 -0
  14. package/src/models/field-check.js +6 -0
  15. package/src/models/host-avatar.js +27 -0
  16. package/src/models/host-build.js +60 -0
  17. package/src/models/host-capabilities.js +33 -0
  18. package/src/models/host-changes.js +12 -4
  19. package/src/models/host-comment.js +50 -0
  20. package/src/models/host-commit-comments.js +42 -0
  21. package/src/models/host-person.js +9 -4
  22. package/src/models/host-policy.js +43 -0
  23. package/src/models/host-pull-request-commit.js +34 -0
  24. package/src/models/host-pull-request-commits.js +33 -0
  25. package/src/models/host-pull-request-conflicts.js +34 -0
  26. package/src/models/host-pull-request-file.js +36 -0
  27. package/src/models/host-pull-request-files.js +46 -0
  28. package/src/models/host-pull-request-head.js +47 -0
  29. package/src/models/host-pull-request-heads.js +42 -0
  30. package/src/models/host-pull-request-list.js +42 -0
  31. package/src/models/host-pull-request-row.js +79 -0
  32. package/src/models/host-pull-request-threads.js +28 -0
  33. package/src/models/host-pull-request-update.js +46 -0
  34. package/src/models/host-pull-request-updates.js +33 -0
  35. package/src/models/host-pull-request.js +69 -0
  36. package/src/models/host-review-request-list.js +42 -0
  37. package/src/models/host-review-request.js +45 -0
  38. package/src/models/host-reviewer.js +41 -0
  39. package/src/models/host-sign-in.js +17 -6
  40. package/src/models/host-thread.js +53 -0
  41. package/src/models/host-work-item-detail.js +83 -0
  42. package/src/models/host-work-item-link.js +51 -0
  43. package/src/models/host-work-item-list.js +31 -0
  44. package/src/models/host-work-item-type.js +37 -0
  45. package/src/models/host-work-item.js +91 -0
  46. package/src/models/hosting-names.js +12 -0
  47. package/src/models/person-query.js +36 -0
  48. package/src/models/repository-query.js +29 -0
  49. package/src/models/work-item-query.js +32 -0
  50. package/src/models/work-item-update.js +47 -0
  51. package/src/models/work-items-query.js +49 -0
  52. package/src/resources.js +122 -3
package/src/api/index.js CHANGED
@@ -6,23 +6,65 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  export { CheckState } from "../enums/check-state.js";
9
+ export { FileChangeKind } from "../enums/file-change-kind.js";
10
+ export { HostCapability } from "../enums/host-capability.js";
11
+ export { PolicyState } from "../enums/policy-state.js";
12
+ export { PullRequestStatus } from "../enums/pull-request-status.js";
9
13
  export { ReferenceKind } from "../enums/reference-kind.js";
10
14
  export { ReferenceState } from "../enums/reference-state.js";
11
15
  export { ReviewDecision } from "../enums/review-decision.js";
12
16
  export { SignInFailure } from "../enums/sign-in-failure.js";
13
17
  export { SignInState } from "../enums/sign-in-state.js";
18
+ export { ThreadStatus } from "../enums/thread-status.js";
19
+ export { WorkItemCategory } from "../enums/work-item-category.js";
20
+ export { WorkItemScope } from "../enums/work-item-scope.js";
14
21
  export { HostingArgumentException } from "../exceptions/hosting-argument.exception.js";
15
22
  export { HostingFieldException } from "../exceptions/hosting-field.exception.js";
16
23
  export { HostingProtocolException } from "../exceptions/hosting-protocol.exception.js";
24
+ export { AuthorQuery } from "../models/author-query.js";
17
25
  export { BranchPullRequest } from "../models/branch-pull-request.js";
18
26
  export { BranchQuery } from "../models/branch-query.js";
27
+ export { CommitQuery } from "../models/commit-query.js";
19
28
  export { DeviceCode } from "../models/device-code.js";
20
29
  export { HostAccount } from "../models/host-account.js";
30
+ export { HostAvatar } from "../models/host-avatar.js";
31
+ export { HostBuild } from "../models/host-build.js";
32
+ export { HostCapabilities } from "../models/host-capabilities.js";
21
33
  export { HostChanges } from "../models/host-changes.js";
34
+ export { HostComment } from "../models/host-comment.js";
35
+ export { HostCommitComments } from "../models/host-commit-comments.js";
22
36
  export { HostCheck } from "../models/host-check.js";
23
37
  export { HostItem } from "../models/host-item.js";
24
38
  export { HostPerson } from "../models/host-person.js";
39
+ export { HostPolicy } from "../models/host-policy.js";
40
+ export { HostPullRequest } from "../models/host-pull-request.js";
41
+ export { HostPullRequestCommit } from "../models/host-pull-request-commit.js";
42
+ export { HostPullRequestCommits } from "../models/host-pull-request-commits.js";
43
+ export { HostPullRequestConflicts } from "../models/host-pull-request-conflicts.js";
44
+ export { HostPullRequestFile } from "../models/host-pull-request-file.js";
45
+ export { HostPullRequestFiles } from "../models/host-pull-request-files.js";
46
+ export { HostPullRequestHead } from "../models/host-pull-request-head.js";
47
+ export { HostPullRequestHeads } from "../models/host-pull-request-heads.js";
48
+ export { HostPullRequestList } from "../models/host-pull-request-list.js";
49
+ export { HostPullRequestRow } from "../models/host-pull-request-row.js";
50
+ export { HostPullRequestThreads } from "../models/host-pull-request-threads.js";
51
+ export { HostPullRequestUpdate } from "../models/host-pull-request-update.js";
52
+ export { HostPullRequestUpdates } from "../models/host-pull-request-updates.js";
25
53
  export { HostReference } from "../models/host-reference.js";
54
+ export { HostReviewRequest } from "../models/host-review-request.js";
55
+ export { HostReviewRequestList } from "../models/host-review-request-list.js";
56
+ export { HostReviewer } from "../models/host-reviewer.js";
26
57
  export { HostSignIn } from "../models/host-sign-in.js";
58
+ export { HostThread } from "../models/host-thread.js";
59
+ export { HostWorkItemDetail } from "../models/host-work-item-detail.js";
60
+ export { HostWorkItemList } from "../models/host-work-item-list.js";
61
+ export { HostWorkItemLink } from "../models/host-work-item-link.js";
62
+ export { HostWorkItemType } from "../models/host-work-item-type.js";
63
+ export { HostWorkItem } from "../models/host-work-item.js";
27
64
  export { HostingNames } from "../models/hosting-names.js";
65
+ export { PersonQuery } from "../models/person-query.js";
28
66
  export { PullRequestDraft } from "../models/pull-request-draft.js";
67
+ export { RepositoryQuery } from "../models/repository-query.js";
68
+ export { WorkItemQuery } from "../models/work-item-query.js";
69
+ export { WorkItemUpdate } from "../models/work-item-update.js";
70
+ export { WorkItemsQuery } from "../models/work-items-query.js";
@@ -0,0 +1,13 @@
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
+ export const FileChangeKind = {
9
+ Added: "Added",
10
+ Modified: "Modified",
11
+ Deleted: "Deleted",
12
+ Renamed: "Renamed"
13
+ };
@@ -0,0 +1,23 @@
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
+ export const HostCapability = {
9
+ SignIn: "SignIn",
10
+ ReadItem: "ReadItem",
11
+ BranchPullRequest: "BranchPullRequest",
12
+ CreatePullRequest: "CreatePullRequest",
13
+ Checks: "Checks",
14
+ Votes: "Votes",
15
+ Policies: "Policies",
16
+ Builds: "Builds",
17
+ AutoComplete: "AutoComplete",
18
+ WorkItems: "WorkItems",
19
+ BranchFromItem: "BranchFromItem",
20
+ Pipelines: "Pipelines",
21
+ AuthorAvatars: "AuthorAvatars",
22
+ PullRequests: "PullRequests"
23
+ };
@@ -0,0 +1,14 @@
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
+ export const PolicyState = {
9
+ Queued: "Queued",
10
+ Running: "Running",
11
+ Approved: "Approved",
12
+ Rejected: "Rejected",
13
+ NotApplicable: "NotApplicable"
14
+ };
@@ -0,0 +1,13 @@
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
+ export const PullRequestStatus = {
9
+ Failed: "Failed",
10
+ Pending: "Pending",
11
+ Succeeded: "Succeeded",
12
+ None: "None"
13
+ };
@@ -0,0 +1,16 @@
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
+ export const ThreadStatus = {
9
+ Active: "Active",
10
+ Pending: "Pending",
11
+ Resolved: "Resolved",
12
+ WontFix: "WontFix",
13
+ ByDesign: "ByDesign",
14
+ Closed: "Closed",
15
+ None: "None"
16
+ };
@@ -0,0 +1,14 @@
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
+ export const WorkItemCategory = {
9
+ Proposed: "Proposed",
10
+ InProgress: "InProgress",
11
+ Resolved: "Resolved",
12
+ Completed: "Completed",
13
+ Removed: "Removed"
14
+ };
@@ -0,0 +1,11 @@
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
+ export const WorkItemScope = {
9
+ Mine: "Mine",
10
+ Ids: "Ids"
11
+ };
@@ -0,0 +1,40 @@
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 AuthorQuery {
12
+ static FIELDS = [Resources.hostField, Resources.pathField, Resources.emailField, Resources.commitField];
13
+ host;
14
+ path;
15
+ email;
16
+ commit;
17
+ constructor(host, path, email, commit, reader) {
18
+ FieldCheck.requireText(host, Resources.hostField, reader);
19
+ FieldCheck.requirePath(path, Resources.pathField, reader);
20
+ FieldCheck.requireText(email, Resources.emailField, reader);
21
+ FieldCheck.requireCommit(commit, Resources.commitField, reader);
22
+ this.host = host;
23
+ this.path = path;
24
+ this.email = email;
25
+ this.commit = commit;
26
+ }
27
+ static fromJson(value, path) {
28
+ const reader = JsonReader.fromValue(value, path);
29
+ FieldCheck.refuseUnknownFields(reader, AuthorQuery.FIELDS);
30
+ return new AuthorQuery(reader.readString(Resources.hostField), reader.readString(Resources.pathField), reader.readString(Resources.emailField), reader.readString(Resources.commitField), reader);
31
+ }
32
+ toJson() {
33
+ return {
34
+ [Resources.hostField]: this.host,
35
+ [Resources.pathField]: this.path,
36
+ [Resources.emailField]: this.email,
37
+ [Resources.commitField]: this.commit
38
+ };
39
+ }
40
+ }
@@ -14,23 +14,29 @@ import { FieldCheck } from "./field-check.js";
14
14
  import { HostCheck } from "./host-check.js";
15
15
  import { HostItem } from "./host-item.js";
16
16
  export class BranchPullRequest {
17
- static FIELDS = [Resources.pullRequestField, Resources.checksField, Resources.reviewDecisionField];
17
+ static FIELDS = [Resources.pullRequestField, Resources.checksField, Resources.reviewDecisionField, Resources.approvalsField];
18
18
  static DECISIONS = Object.values(ReviewDecision);
19
19
  static WORST_FIRST = [CheckState.Failed, CheckState.Running, CheckState.Queued, CheckState.Succeeded,
20
20
  CheckState.Neutral];
21
21
  pullRequest;
22
22
  checks;
23
23
  reviewDecision;
24
- constructor(pullRequest, checks, reviewDecision = pullRequest === null ? null : ReviewDecision.Waiting, reader) {
24
+ approvals;
25
+ constructor(pullRequest, checks, reviewDecision = pullRequest === null ? null : ReviewDecision.Waiting, approvals = null, reader) {
25
26
  if (pullRequest !== null && pullRequest.kind !== ReferenceKind.PullRequest)
26
27
  FieldCheck.fail(Resources.pullRequestField, Resources.pullRequestExpected, reader);
27
28
  if (pullRequest === null && checks.length > 0)
28
29
  FieldCheck.fail(Resources.checksField, Resources.checksExpected, reader);
29
30
  if ((pullRequest === null) !== (reviewDecision === null))
30
31
  FieldCheck.fail(Resources.reviewDecisionField, Resources.reviewDecisionExpected, reader);
32
+ if (pullRequest === null && approvals !== null)
33
+ FieldCheck.fail(Resources.approvalsField, Resources.approvalsExpected, reader);
34
+ if (approvals !== null)
35
+ FieldCheck.requireCount(approvals, Resources.approvalsField, reader);
31
36
  this.pullRequest = pullRequest;
32
37
  this.checks = [...checks];
33
38
  this.reviewDecision = reviewDecision;
39
+ this.approvals = approvals;
34
40
  }
35
41
  get checksState() {
36
42
  return BranchPullRequest.WORST_FIRST.find(t => this.checks.some(check => check.state === t)) ?? null;
@@ -40,13 +46,14 @@ export class BranchPullRequest {
40
46
  FieldCheck.refuseUnknownFields(reader, BranchPullRequest.FIELDS);
41
47
  const pullRequest = FieldCheck.readNullableModel(reader, Resources.pullRequestField, HostItem.fromJson);
42
48
  return new BranchPullRequest(pullRequest, reader.readObjectArray(Resources.checksField).map(t => HostCheck.fromJson(t.toJson(), t.path)), reader.hasField(Resources.reviewDecisionField) ? FieldCheck.readNullableMember(reader, Resources.reviewDecisionField, BranchPullRequest.DECISIONS)
43
- : pullRequest === null ? null : ReviewDecision.Waiting, reader);
49
+ : pullRequest === null ? null : ReviewDecision.Waiting, reader.hasField(Resources.approvalsField) ? reader.readNullableInteger(Resources.approvalsField) : null, reader);
44
50
  }
45
51
  toJson() {
46
52
  return {
47
53
  [Resources.pullRequestField]: this.pullRequest?.toJson() ?? null,
48
54
  [Resources.checksField]: this.checks.map(t => t.toJson()),
49
- [Resources.reviewDecisionField]: this.reviewDecision
55
+ [Resources.reviewDecisionField]: this.reviewDecision,
56
+ [Resources.approvalsField]: this.approvals
50
57
  };
51
58
  }
52
59
  }
@@ -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 CommitQuery {
12
+ static FIELDS = [Resources.hostField, Resources.pathField, Resources.commitField];
13
+ host;
14
+ path;
15
+ commit;
16
+ constructor(host, path, commit, reader) {
17
+ FieldCheck.requireText(host, Resources.hostField, reader);
18
+ FieldCheck.requirePath(path, Resources.pathField, reader);
19
+ FieldCheck.requireCommit(commit, Resources.commitField, reader);
20
+ this.host = host;
21
+ this.path = path;
22
+ this.commit = commit;
23
+ }
24
+ static fromJson(value, path) {
25
+ const reader = JsonReader.fromValue(value, path);
26
+ FieldCheck.refuseUnknownFields(reader, CommitQuery.FIELDS);
27
+ return new CommitQuery(reader.readString(Resources.hostField), reader.readString(Resources.pathField), reader.readString(Resources.commitField), reader);
28
+ }
29
+ toJson() {
30
+ return { [Resources.hostField]: this.host, [Resources.pathField]: this.path, [Resources.commitField]: this.commit };
31
+ }
32
+ }
@@ -26,6 +26,12 @@ export class FieldCheck {
26
26
  static readNullableMember(reader, field, members) {
27
27
  return reader.readValue(field) === null ? null : reader.readOneOf(field, members);
28
28
  }
29
+ static requireMember(value, members, field, reader) {
30
+ const member = members.find(t => t === value);
31
+ if (member === undefined)
32
+ FieldCheck.fail(field, Resources.formatMemberExpected(members), reader);
33
+ return member;
34
+ }
29
35
  static requireText(value, field, reader) {
30
36
  if (value.trim().length === 0)
31
37
  FieldCheck.fail(field, Resources.nonBlankTextExpected, reader);
@@ -0,0 +1,27 @@
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 HostAvatar {
12
+ static FIELDS = [Resources.avatarField];
13
+ avatar;
14
+ constructor(avatar, reader) {
15
+ if (avatar !== null)
16
+ FieldCheck.requireAvatar(avatar, Resources.avatarField, reader);
17
+ this.avatar = avatar;
18
+ }
19
+ static fromJson(value, path) {
20
+ const reader = JsonReader.fromValue(value, path);
21
+ FieldCheck.refuseUnknownFields(reader, HostAvatar.FIELDS);
22
+ return new HostAvatar(reader.readNullableString(Resources.avatarField), reader);
23
+ }
24
+ toJson() {
25
+ return { [Resources.avatarField]: this.avatar };
26
+ }
27
+ }
@@ -0,0 +1,60 @@
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 { CheckState } from "../enums/check-state.js";
10
+ import { Resources } from "../resources.js";
11
+ import { FieldCheck } from "./field-check.js";
12
+ export class HostBuild {
13
+ static FIELDS = [Resources.nameField, Resources.stateField, Resources.urlField, Resources.startedAtField,
14
+ Resources.finishedAtField, Resources.numberField];
15
+ static STATES = Object.values(CheckState);
16
+ static FINISHED = [CheckState.Succeeded, CheckState.Failed, CheckState.Neutral];
17
+ name;
18
+ state;
19
+ url;
20
+ startedAt;
21
+ finishedAt;
22
+ number;
23
+ constructor(name, state, url, startedAt, finishedAt, number = null, reader) {
24
+ FieldCheck.requireText(name, Resources.nameField, reader);
25
+ if (number !== null)
26
+ FieldCheck.requireText(number, Resources.numberField, reader);
27
+ if (url !== null)
28
+ FieldCheck.requireHttps(url, Resources.urlField, reader);
29
+ if (startedAt !== null)
30
+ FieldCheck.requirePositive(startedAt, Resources.startedAtField, reader);
31
+ if (HostBuild.FINISHED.includes(state) !== (finishedAt !== null))
32
+ FieldCheck.fail(Resources.finishedAtField, Resources.finishedAtExpected, reader);
33
+ if (finishedAt !== null) {
34
+ FieldCheck.requirePositive(finishedAt, Resources.finishedAtField, reader);
35
+ if (startedAt !== null && finishedAt < startedAt)
36
+ FieldCheck.fail(Resources.finishedAtField, Resources.finishedAtExpected, reader);
37
+ }
38
+ this.name = name;
39
+ this.state = state;
40
+ this.url = url;
41
+ this.startedAt = startedAt;
42
+ this.finishedAt = finishedAt;
43
+ this.number = number;
44
+ }
45
+ static fromJson(value, path) {
46
+ const reader = JsonReader.fromValue(value, path);
47
+ FieldCheck.refuseUnknownFields(reader, HostBuild.FIELDS);
48
+ return new HostBuild(reader.readString(Resources.nameField), reader.readOneOf(Resources.stateField, HostBuild.STATES), reader.readNullableString(Resources.urlField), reader.readNullableInteger(Resources.startedAtField), reader.readNullableInteger(Resources.finishedAtField), reader.hasField(Resources.numberField) ? reader.readNullableString(Resources.numberField) : null, reader);
49
+ }
50
+ toJson() {
51
+ return {
52
+ [Resources.nameField]: this.name,
53
+ [Resources.stateField]: this.state,
54
+ [Resources.urlField]: this.url,
55
+ [Resources.startedAtField]: this.startedAt,
56
+ [Resources.finishedAtField]: this.finishedAt,
57
+ [Resources.numberField]: this.number
58
+ };
59
+ }
60
+ }
@@ -0,0 +1,33 @@
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 { HostCapability } from "../enums/host-capability.js";
10
+ import { Resources } from "../resources.js";
11
+ import { FieldCheck } from "./field-check.js";
12
+ export class HostCapabilities {
13
+ static FIELDS = [Resources.capabilitiesField];
14
+ static CAPABILITIES = Object.values(HostCapability);
15
+ capabilities;
16
+ constructor(capabilities, reader) {
17
+ if (new Set(capabilities).size !== capabilities.length)
18
+ FieldCheck.fail(Resources.capabilitiesField, Resources.eachOnceExpected, reader);
19
+ this.capabilities = [...capabilities];
20
+ }
21
+ has(capability) {
22
+ return this.capabilities.includes(capability);
23
+ }
24
+ static fromJson(value, path) {
25
+ const reader = JsonReader.fromValue(value, path);
26
+ FieldCheck.refuseUnknownFields(reader, HostCapabilities.FIELDS);
27
+ const names = reader.readStringArray(Resources.capabilitiesField);
28
+ return new HostCapabilities(names.map(t => FieldCheck.requireMember(t, HostCapabilities.CAPABILITIES, Resources.capabilitiesField, reader)), reader);
29
+ }
30
+ toJson() {
31
+ return { [Resources.capabilitiesField]: [...this.capabilities] };
32
+ }
33
+ }
@@ -10,17 +10,20 @@ import { Resources } from "../resources.js";
10
10
  import { FieldCheck } from "./field-check.js";
11
11
  export class HostChanges {
12
12
  static FIELDS = [Resources.additionsField, Resources.deletionsField, Resources.changedFilesField,
13
- Resources.headBranchField, Resources.baseBranchField, Resources.headCommitField];
13
+ Resources.headBranchField, Resources.baseBranchField, Resources.headCommitField, Resources.isCountedField];
14
14
  additions;
15
15
  deletions;
16
16
  changedFiles;
17
17
  headBranch;
18
18
  baseBranch;
19
19
  headCommit;
20
- constructor(additions, deletions, changedFiles, headBranch, baseBranch, headCommit, reader) {
20
+ isCounted;
21
+ constructor(additions, deletions, changedFiles, headBranch, baseBranch, headCommit, reader, isCounted = true) {
21
22
  FieldCheck.requireCount(additions, Resources.additionsField, reader);
22
23
  FieldCheck.requireCount(deletions, Resources.deletionsField, reader);
23
24
  FieldCheck.requireCount(changedFiles, Resources.changedFilesField, reader);
25
+ if (!isCounted && additions + deletions + changedFiles > 0)
26
+ FieldCheck.fail(Resources.isCountedField, Resources.countsExpected, reader);
24
27
  FieldCheck.requireText(headBranch, Resources.headBranchField, reader);
25
28
  FieldCheck.requireText(baseBranch, Resources.baseBranchField, reader);
26
29
  FieldCheck.requireCommit(headCommit, Resources.headCommitField, reader);
@@ -30,11 +33,15 @@ export class HostChanges {
30
33
  this.headBranch = headBranch;
31
34
  this.baseBranch = baseBranch;
32
35
  this.headCommit = headCommit;
36
+ this.isCounted = isCounted;
37
+ }
38
+ static uncounted(headBranch, baseBranch, headCommit) {
39
+ return new HostChanges(0, 0, 0, headBranch, baseBranch, headCommit, undefined, false);
33
40
  }
34
41
  static fromJson(value, path) {
35
42
  const reader = JsonReader.fromValue(value, path);
36
43
  FieldCheck.refuseUnknownFields(reader, HostChanges.FIELDS);
37
- return new HostChanges(reader.readInteger(Resources.additionsField), reader.readInteger(Resources.deletionsField), reader.readInteger(Resources.changedFilesField), reader.readString(Resources.headBranchField), reader.readString(Resources.baseBranchField), reader.readString(Resources.headCommitField), reader);
44
+ return new HostChanges(reader.readInteger(Resources.additionsField), reader.readInteger(Resources.deletionsField), reader.readInteger(Resources.changedFilesField), reader.readString(Resources.headBranchField), reader.readString(Resources.baseBranchField), reader.readString(Resources.headCommitField), reader, reader.hasField(Resources.isCountedField) ? reader.readBoolean(Resources.isCountedField) : true);
38
45
  }
39
46
  toJson() {
40
47
  return {
@@ -43,7 +50,8 @@ export class HostChanges {
43
50
  [Resources.changedFilesField]: this.changedFiles,
44
51
  [Resources.headBranchField]: this.headBranch,
45
52
  [Resources.baseBranchField]: this.baseBranch,
46
- [Resources.headCommitField]: this.headCommit
53
+ [Resources.headCommitField]: this.headCommit,
54
+ ...this.isCounted ? {} : { [Resources.isCountedField]: false }
47
55
  };
48
56
  }
49
57
  }
@@ -0,0 +1,50 @@
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
+ import { HostPerson } from "./host-person.js";
12
+ export class HostComment {
13
+ static FIELDS = [Resources.idField, Resources.parentField, Resources.authorField, Resources.publishedAtField,
14
+ Resources.bodyField];
15
+ id;
16
+ parent;
17
+ author;
18
+ publishedAt;
19
+ body;
20
+ constructor(id, parent, author, publishedAt, body, reader) {
21
+ FieldCheck.requirePositive(id, Resources.idField, reader);
22
+ if (parent !== null) {
23
+ FieldCheck.requirePositive(parent, Resources.parentField, reader);
24
+ if (parent === id)
25
+ FieldCheck.fail(Resources.parentField, Resources.commentParentExpected, reader);
26
+ }
27
+ FieldCheck.requirePositive(publishedAt, Resources.publishedAtField, reader);
28
+ FieldCheck.requireText(body, Resources.bodyField, reader);
29
+ this.id = id;
30
+ this.parent = parent;
31
+ this.author = author;
32
+ this.publishedAt = publishedAt;
33
+ this.body = body;
34
+ }
35
+ static fromJson(value, path) {
36
+ const reader = JsonReader.fromValue(value, path);
37
+ FieldCheck.refuseUnknownFields(reader, HostComment.FIELDS);
38
+ const author = reader.readObject(Resources.authorField);
39
+ return new HostComment(reader.readInteger(Resources.idField), reader.readNullableInteger(Resources.parentField), HostPerson.fromJson(author.toJson(), author.path), reader.readInteger(Resources.publishedAtField), reader.readString(Resources.bodyField), reader);
40
+ }
41
+ toJson() {
42
+ return {
43
+ [Resources.idField]: this.id,
44
+ [Resources.parentField]: this.parent,
45
+ [Resources.authorField]: this.author.toJson(),
46
+ [Resources.publishedAtField]: this.publishedAt,
47
+ [Resources.bodyField]: this.body
48
+ };
49
+ }
50
+ }
@@ -0,0 +1,42 @@
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 HostCommitComments {
12
+ static maximumCount = Resources.maximumCommitComments;
13
+ static FIELDS = [Resources.countField, Resources.isCappedField, Resources.urlField];
14
+ count;
15
+ isCapped;
16
+ url;
17
+ constructor(count, isCapped, url, reader) {
18
+ FieldCheck.requireCount(count, Resources.countField, reader);
19
+ if (count > Resources.maximumCommitComments)
20
+ FieldCheck.fail(Resources.countField, Resources.commitCommentsExpected, reader);
21
+ if (isCapped && count === 0)
22
+ FieldCheck.fail(Resources.isCappedField, Resources.commitCommentsCappedExpected, reader);
23
+ if ((count === 0) !== (url === null))
24
+ FieldCheck.fail(Resources.urlField, Resources.commitCommentsUrlExpected, reader);
25
+ if (url !== null)
26
+ FieldCheck.requireHttps(url, Resources.urlField, reader);
27
+ this.count = count;
28
+ this.isCapped = isCapped;
29
+ this.url = url;
30
+ }
31
+ static none() {
32
+ return new HostCommitComments(0, false, null);
33
+ }
34
+ static fromJson(value, path) {
35
+ const reader = JsonReader.fromValue(value, path);
36
+ FieldCheck.refuseUnknownFields(reader, HostCommitComments.FIELDS);
37
+ return new HostCommitComments(reader.readInteger(Resources.countField), reader.readBoolean(Resources.isCappedField), reader.readNullableString(Resources.urlField), reader);
38
+ }
39
+ toJson() {
40
+ return { [Resources.countField]: this.count, [Resources.isCappedField]: this.isCapped, [Resources.urlField]: this.url };
41
+ }
42
+ }
@@ -9,26 +9,31 @@ import { JsonReader } from "@noldova/context.json";
9
9
  import { Resources } from "../resources.js";
10
10
  import { FieldCheck } from "./field-check.js";
11
11
  export class HostPerson {
12
- static FIELDS = [Resources.loginField, Resources.avatarField, Resources.urlField];
12
+ static FIELDS = [Resources.loginField, Resources.avatarField, Resources.urlField, Resources.nameField];
13
13
  login;
14
14
  avatar;
15
15
  url;
16
- constructor(login, avatar, url, reader) {
16
+ name;
17
+ constructor(login, avatar, url, reader, name = null) {
17
18
  FieldCheck.requireText(login, Resources.loginField, reader);
18
19
  if (avatar !== null)
19
20
  FieldCheck.requireAvatar(avatar, Resources.avatarField, reader);
20
21
  if (url !== null)
21
22
  FieldCheck.requireHttps(url, Resources.urlField, reader);
23
+ if (name !== null)
24
+ FieldCheck.requireText(name, Resources.nameField, reader);
22
25
  this.login = login;
23
26
  this.avatar = avatar;
24
27
  this.url = url;
28
+ this.name = name;
25
29
  }
26
30
  static fromJson(value, path) {
27
31
  const reader = JsonReader.fromValue(value, path);
28
32
  FieldCheck.refuseUnknownFields(reader, HostPerson.FIELDS);
29
- return new HostPerson(reader.readString(Resources.loginField), reader.readNullableString(Resources.avatarField), reader.readNullableString(Resources.urlField), reader);
33
+ return new HostPerson(reader.readString(Resources.loginField), reader.readNullableString(Resources.avatarField), reader.readNullableString(Resources.urlField), reader, reader.hasField(Resources.nameField) ? reader.readString(Resources.nameField) : null);
30
34
  }
31
35
  toJson() {
32
- return { [Resources.loginField]: this.login, [Resources.avatarField]: this.avatar, [Resources.urlField]: this.url };
36
+ const person = { [Resources.loginField]: this.login, [Resources.avatarField]: this.avatar, [Resources.urlField]: this.url };
37
+ return this.name === null ? person : { ...person, [Resources.nameField]: this.name };
33
38
  }
34
39
  }