repository-provider 28.3.13 → 28.4.0

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/README.md CHANGED
@@ -940,9 +940,10 @@ Abstract branch.
940
940
 
941
941
  ### Parameters
942
942
 
943
- * `repository` **[Repository](#repository)**
944
- * `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** (optional, default `repository.defaultBranchName`)
943
+ * `owner`
944
+ * `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** (optional, default `owner.defaultBranchName`)
945
945
  * `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
946
+ * `repository` **[Repository](#repository)**
946
947
 
947
948
  ### Properties
948
949
 
@@ -1182,7 +1183,7 @@ Check for equality.
1182
1183
 
1183
1184
  * `other` **[NamedObject](#namedobject)**
1184
1185
 
1185
- Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** true if names are equal and have the same owner
1186
+ Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** true if names are equal and have the same provider
1186
1187
 
1187
1188
  ### fullName
1188
1189
 
@@ -1190,7 +1191,7 @@ Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/G
1190
1191
 
1191
1192
  ### toJSON
1192
1193
 
1193
- Provide name and all defined attributes.
1194
+ Provided name and all defined attributes.
1194
1195
 
1195
1196
  ## OwnedObject
1196
1197
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "repository-provider",
3
- "version": "28.3.13",
3
+ "version": "28.4.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -36,7 +36,7 @@
36
36
  "ava": "^4.2.0",
37
37
  "c8": "^7.11.2",
38
38
  "documentation": "^13.2.5",
39
- "repository-provider-test-support": "^2.1.9",
39
+ "repository-provider-test-support": "^2.1.10",
40
40
  "semantic-release": "^19.0.2",
41
41
  "typescript": "^4.6.3"
42
42
  },
@@ -10,11 +10,8 @@ import { RepositoryGroup } from "./repository-group.mjs";
10
10
  *
11
11
  */
12
12
  export class MultiGroupProvider extends BaseProvider {
13
- constructor(options) {
14
- super(options, {
15
- _repositoryGroups: { value: new Map() }
16
- });
17
- }
13
+
14
+ #repositoryGroups = new Map();
18
15
 
19
16
  /**
20
17
  * Lookup a repository in the provider and all of its repository groups.
@@ -68,7 +65,7 @@ export class MultiGroupProvider extends BaseProvider {
68
65
  if (this.supportsBase(base)) {
69
66
  name = stripBaseNames(name, this.provider.repositoryBases);
70
67
  await this.initializeRepositories();
71
- return this._repositoryGroups.get(this.normalizeGroupName(name, true));
68
+ return this.#repositoryGroups.get(this.normalizeGroupName(name, true));
72
69
  }
73
70
  }
74
71
 
@@ -81,7 +78,7 @@ export class MultiGroupProvider extends BaseProvider {
81
78
  await this.initializeRepositories();
82
79
 
83
80
  yield* matcher(
84
- this._repositoryGroups.values(),
81
+ this.#repositoryGroups.values(),
85
82
  stripBaseNames(patterns, this.provider.repositoryBases),
86
83
  {
87
84
  caseSensitive: this.areGroupNamesCaseSensitive,
@@ -108,13 +105,10 @@ export class MultiGroupProvider extends BaseProvider {
108
105
  * @return {RepositoryGroup}
109
106
  */
110
107
  addRepositoryGroup(name, options) {
111
- const normalizedName = this.normalizeGroupName(name, true);
108
+ return this.#repositoryGroups.get(this.normalizeGroupName(name, true)) || new this.repositoryGroupClass(this, name, options);
109
+ }
112
110
 
113
- let repositoryGroup = this._repositoryGroups.get(normalizedName);
114
- if (repositoryGroup === undefined) {
115
- repositoryGroup = new this.repositoryGroupClass(this, name, options);
116
- this._repositoryGroups.set(normalizedName, repositoryGroup);
117
- }
118
- return repositoryGroup;
111
+ _addRepositoryGroup(repositoryGroup) {
112
+ this.#repositoryGroups.set(this.normalizeGroupName(repositoryGroup.name, true), repositoryGroup);
119
113
  }
120
114
  }
@@ -1,5 +1,5 @@
1
1
  import { RepositoryOwner } from "./repository-owner.mjs";
2
- import { NamedObject } from "./named-object.mjs";
2
+ import { OwnedObject } from "./owned-object.mjs";
3
3
  import { BaseProvider } from "./base-provider.mjs";
4
4
 
5
5
  /**
@@ -16,7 +16,12 @@ import { BaseProvider } from "./base-provider.mjs";
16
16
  * @property {string} name
17
17
  */
18
18
 
19
- export class RepositoryGroup extends RepositoryOwner(NamedObject) {
19
+ export class RepositoryGroup extends RepositoryOwner(OwnedObject) {
20
+
21
+ static get registerInstanceMethodName() {
22
+ return "_addRepositoryGroup";
23
+ }
24
+
20
25
  static get attributes() {
21
26
  return {
22
27
  ...super.attributes,
@@ -43,15 +48,9 @@ export class RepositoryGroup extends RepositoryOwner(NamedObject) {
43
48
  return {};
44
49
  }
45
50
 
46
- constructor(provider, name, options) {
47
- super(name, options, {
48
- provider: { value: provider }
49
- });
50
- }
51
-
52
- get owner()
51
+ get provider()
53
52
  {
54
- return this.provider;
53
+ return this.owner;
55
54
  }
56
55
 
57
56
  get isAdmin() {
@@ -59,10 +58,10 @@ export class RepositoryGroup extends RepositoryOwner(NamedObject) {
59
58
  }
60
59
 
61
60
  get areRepositoryNamesCaseSensitive() {
62
- return this.provider.areRepositoryNamesCaseSensitive;
61
+ return this.owner.areRepositoryNamesCaseSensitive;
63
62
  }
64
63
 
65
64
  get areRepositoryGroupNamesCaseSensitive() {
66
- return this.provider.areRepositoryGroupNamesCaseSensitive;
65
+ return this.owner.areRepositoryGroupNamesCaseSensitive;
67
66
  }
68
67
  }
@@ -9,11 +9,8 @@ import { asArray, stripBaseName, stripBaseNames } from "./util.mjs";
9
9
  */
10
10
  export function RepositoryOwner(base) {
11
11
  return class RepositoryOwner extends base {
12
- constructor(...args) {
13
- super(...args);
14
12
 
15
- Object.defineProperties(this, { _repositories: { value: new Map() } });
16
- }
13
+ #repositories = new Map();
17
14
 
18
15
  /**
19
16
  * Normalizes a repository name.
@@ -51,7 +48,7 @@ export function RepositoryOwner(base) {
51
48
 
52
49
  await this.initializeRepositories();
53
50
 
54
- return this._repositories.get(this.normalizeRepositoryName(name, true));
51
+ return this.#repositories.get(this.normalizeRepositoryName(name, true));
55
52
  }
56
53
 
57
54
  /**
@@ -75,7 +72,7 @@ export function RepositoryOwner(base) {
75
72
 
76
73
  await this.initializeRepositories();
77
74
  yield* matcher(
78
- this._repositories.values(),
75
+ this.#repositories.values(),
79
76
  stripBaseNames(patterns, this.provider.repositoryBases),
80
77
  {
81
78
  caseSensitive: this.areRepositoryNamesCaseSensitive,
@@ -91,7 +88,7 @@ export function RepositoryOwner(base) {
91
88
  name = stripBaseName(name, this.provider.repositoryBases);
92
89
 
93
90
  const [repoName, typeName] = split ? split(name) : name.split("/");
94
- const repository = this._repositories.get(repoName);
91
+ const repository = this.#repositories.get(repoName);
95
92
 
96
93
  if (repository) {
97
94
  if (typeName === undefined && defaultItem) {
@@ -113,10 +110,10 @@ export function RepositoryOwner(base) {
113
110
  ? split(pattern)
114
111
  : pattern.split("/");
115
112
 
116
- for (const name of matcher(this._repositories.keys(), repoPattern, {
113
+ for (const name of matcher(this.#repositories.keys(), repoPattern, {
117
114
  caseSensitive: this.areRepositoriesCaseSensitive
118
115
  })) {
119
- const repository = this._repositories.get(name);
116
+ const repository = this.#repositories.get(name);
120
117
 
121
118
  if (typePattern === undefined && defaultItem) {
122
119
  const item = await defaultItem(repository);
@@ -149,18 +146,13 @@ export function RepositoryOwner(base) {
149
146
  * @return {Promise<Repository>} newly created repository
150
147
  */
151
148
  addRepository(name, options) {
152
- const normalizedName = this.normalizeRepositoryName(name, true);
153
- let repository = this._repositories.get(normalizedName);
154
- if (repository === undefined) {
155
- repository = new this.repositoryClass(this, name, options);
156
- }
157
- return repository;
149
+ return this.#repositories.get(this.normalizeRepositoryName(name, true)) || new this.repositoryClass(this, name, options);
158
150
  }
159
151
 
160
152
  _addRepository(repository)
161
153
  {
162
154
  const normalizedName = this.normalizeRepositoryName(repository.name, true);
163
- this._repositories.set(normalizedName, repository);
155
+ this.#repositories.set(normalizedName, repository);
164
156
  }
165
157
 
166
158
  /**
@@ -169,7 +161,7 @@ export function RepositoryOwner(base) {
169
161
  * @return {Promise<any>}
170
162
  */
171
163
  async deleteRepository(name) {
172
- this._repositories.delete(this.normalizeRepositoryName(name, true));
164
+ this.#repositories.delete(this.normalizeRepositoryName(name, true));
173
165
  }
174
166
 
175
167
  initializeRepositories() {}
@@ -242,12 +242,7 @@ export class Repository extends OwnedObject {
242
242
  */
243
243
  async branch(name) {
244
244
  if(name === this.defaultBranchName) {
245
- const branch = this._branches.get(name);
246
- if(branch) {
247
- return branch;
248
- }
249
-
250
- return this.addBranch(name);
245
+ return this._branches.get(name) || this.addBranch(name);
251
246
  }
252
247
 
253
248
  await this.initializeBranches();
@@ -284,12 +279,7 @@ export class Repository extends OwnedObject {
284
279
  * @return {Branch} newly created branch
285
280
  */
286
281
  addBranch(name, options) {
287
- let branch = this._branches.get(name);
288
- if (branch === undefined) {
289
- branch = new this.branchClass(this, name, options);
290
- }
291
-
292
- return branch;
282
+ return this._branches.get(name) || new this.branchClass(this, name, options);
293
283
  }
294
284
 
295
285
  _addBranch(branch) {
@@ -335,12 +325,7 @@ export class Repository extends OwnedObject {
335
325
  * @return {Tag} newly created tag
336
326
  */
337
327
  addTag(name, options) {
338
- let tag = this._tags.get(name);
339
- if (tag === undefined) {
340
- tag = new this.tagClass(this, name, options);
341
- }
342
-
343
- return tag;
328
+ return this._tags.get(name) || new this.tagClass(this, name, options);
344
329
  }
345
330
 
346
331
  _addTag(tag) {