repository-provider 35.5.16 → 35.6.1

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,10 +1,11 @@
1
1
  {
2
2
  "name": "repository-provider",
3
- "version": "35.5.16",
3
+ "version": "35.6.1",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": true
7
7
  },
8
+ "packageManager": "npm@11.6.0+sha512.77f3fb0dbbd881835d7bd1217deabdf7ed77fc4ec4f363df64fc3cb986404abf6c437661041080f5c5d225103508e7c9ea30cb2742b7e942675d05a10af2d7b9",
8
9
  "types": "./types/index.d.mts",
9
10
  "exports": {
10
11
  ".": {
@@ -37,21 +38,21 @@
37
38
  "lint:typescript": "tsc --allowJs --checkJs --noEmit --resolveJsonModule --target esnext -m esnext --module nodenext --moduleResolution nodenext ./src**/*.mjs"
38
39
  },
39
40
  "dependencies": {
40
- "content-entry": "^14.2.4",
41
+ "content-entry": "^14.2.5",
41
42
  "matching-iterator": "^2.1.4",
42
- "pacc": "^4.9.1"
43
+ "pacc": "^4.39.0"
43
44
  },
44
45
  "devDependencies": {
45
46
  "ava": "^6.4.1",
46
- "browser-ava": "^2.3.31",
47
+ "browser-ava": "^2.3.34",
47
48
  "c8": "^10.1.3",
48
49
  "documentation": "^14.0.3",
49
- "repository-provider-test-support": "^3.1.52",
50
- "semantic-release": "^24.2.7",
50
+ "repository-provider-test-support": "^4.0.0",
51
+ "semantic-release": "^24.2.9",
51
52
  "typescript": "^5.9.2"
52
53
  },
53
54
  "engines": {
54
- "node": ">=22.18.0"
55
+ "node": ">=22.19.5"
55
56
  },
56
57
  "repository": {
57
58
  "type": "git",
@@ -1,8 +1,8 @@
1
1
  import {
2
- definePropertiesFromOptions,
3
- mapAttributes
4
- } from "./attribute-extras.mjs";
5
- import { description_attribute, id_attribute } from "pacc";
2
+ definePropertiesFromAttributes,
3
+ description_attribute,
4
+ id_attribute
5
+ } from "pacc";
6
6
 
7
7
  /**
8
8
  * Creates an instance of BaseObject.
@@ -52,12 +52,6 @@ export class BaseObject {
52
52
  );
53
53
  }
54
54
 
55
- /**
56
- * Map attributes between external and internal representation.
57
- * @return {Object}
58
- */
59
- static attributeMapping = {};
60
-
61
55
  /** @type {string} */ id;
62
56
  /** @type {string} */ description;
63
57
 
@@ -66,10 +60,9 @@ export class BaseObject {
66
60
  * @param {Object} [options]
67
61
  * @param {string} [options.id]
68
62
  * @param {string} [options.description]
69
- * @param {Object} [additionalProperties]
70
63
  */
71
- constructor(options, additionalProperties) {
72
- this.updateAttributes(options, additionalProperties);
64
+ constructor(options) {
65
+ this.updateAttributes(options);
73
66
  }
74
67
 
75
68
  /**
@@ -77,13 +70,8 @@ export class BaseObject {
77
70
  * @param {Object} [options]
78
71
  * @param {Object} [additionalProperties]
79
72
  */
80
- updateAttributes(options, additionalProperties) {
81
- definePropertiesFromOptions(
82
- this,
83
- // @ts-ignore
84
- mapAttributes(options, this.constructor.attributeMapping),
85
- additionalProperties
86
- );
73
+ updateAttributes(options) {
74
+ definePropertiesFromAttributes(this, this.constructor.attributes, options);
87
75
  }
88
76
 
89
77
  /**
@@ -1,8 +1,10 @@
1
1
  import {
2
+ manadatoryAttributesPresent,
3
+ environmentValues,
2
4
  url_attribute,
3
- name_attribute,
5
+ name_attribute_writable,
4
6
  priority_attribute,
5
- default_attribute
7
+ object_attribute
6
8
  } from "pacc";
7
9
  import { asArray, stripBaseName } from "./util.mjs";
8
10
  import { PullRequest } from "./pull-request.mjs";
@@ -58,65 +60,6 @@ export class BaseProvider extends BaseObject {
58
60
  return "";
59
61
  }
60
62
 
61
- /**
62
- * Extract options suitable for the constructor.
63
- * Form the given set of environment variables.
64
- * Object with the detected key value pairs is delivered.
65
- * @param {Object} [env] as from process.env
66
- * @param {string} instanceIdentifier part of variable name.
67
- * @return {Object|undefined} undefined if no suitable environment variables have been found
68
- */
69
- static optionsFromEnvironment(
70
- env,
71
- instanceIdentifier = this.instanceIdentifier
72
- ) {
73
- let options;
74
-
75
- if (env !== undefined) {
76
- const attributes = this.attributes;
77
-
78
- for (let [envName, value] of Object.entries(env)) {
79
- for (const [name, attribute] of Object.entries(attributes)) {
80
- if (
81
- asArray(attribute.env).find(
82
- e =>
83
- e.replace(
84
- "{{instanceIdentifier}}",
85
- () => instanceIdentifier
86
- ) === envName
87
- )
88
- ) {
89
- options ??= {};
90
-
91
- if (options[name] === undefined) {
92
- options[name] = value;
93
- Object.assign(options, attribute.additionalAttributes);
94
- }
95
- break;
96
- }
97
- }
98
- }
99
- }
100
- return options;
101
- }
102
-
103
- /**
104
- * Check if given options are sufficient to create a provider.
105
- * @param {Object} options
106
- * @return {boolean} true if options ar sufficient to construct a provider
107
- */
108
- static areOptionsSufficcient(options) {
109
- for (const [name, attribute] of Object.entries(this.attributes).filter(
110
- ([name, attribute]) => attribute.mandatory
111
- )) {
112
- if (options[name] === undefined) {
113
- return false;
114
- }
115
- }
116
-
117
- return true;
118
- }
119
-
120
63
  static attributes = {
121
64
  ...BaseObject.attributes,
122
65
 
@@ -124,7 +67,7 @@ export class BaseProvider extends BaseObject {
124
67
  * Name of the provider.
125
68
  */
126
69
  name: {
127
- ...name_attribute,
70
+ ...name_attribute_writable,
128
71
  env: "{{instanceIdentifier}}NAME"
129
72
  },
130
73
 
@@ -135,8 +78,7 @@ export class BaseProvider extends BaseObject {
135
78
  * To forward info/warn and error messages to
136
79
  */
137
80
  messageDestination: {
138
- ...default_attribute,
139
- type: "object",
81
+ ...object_attribute,
140
82
  default: console,
141
83
  writable: true,
142
84
  private: true
@@ -163,10 +105,14 @@ export class BaseProvider extends BaseObject {
163
105
  static initialize(options, env) {
164
106
  options = {
165
107
  ...options,
166
- ...this.optionsFromEnvironment(env, options?.instanceIdentifier)
108
+ ...environmentValues(
109
+ env,
110
+ this.attributes,
111
+ options?.instanceIdentifier ?? this.instanceIdentifier
112
+ )
167
113
  };
168
114
 
169
- if (this.areOptionsSufficcient(options)) {
115
+ if (manadatoryAttributesPresent(options, this.attributes)) {
170
116
  return new this(options);
171
117
  }
172
118
  }
package/src/hook.mjs CHANGED
@@ -2,8 +2,9 @@ import {
2
2
  secret_attribute,
3
3
  boolean_attribute,
4
4
  active_attribute,
5
- url_attribute,
6
- string_attribute
5
+ url_attribute_writable,
6
+ string_attribute_writable,
7
+ string_collection_attribute_writable
7
8
  } from "pacc";
8
9
  import { OwnedObject } from "./owned-object.mjs";
9
10
 
@@ -17,12 +18,23 @@ export class Hook extends OwnedObject {
17
18
  ...super.attributes,
18
19
  active: active_attribute,
19
20
  secret: secret_attribute,
20
- url: { ...url_attribute, description: "target url", writable: true },
21
- content_type: { ...string_attribute, default: "json", writable: true },
21
+ url: { ...url_attribute_writable, description: "target url" },
22
+ content_type: { ...string_attribute_writable, default: "json" },
22
23
  insecure_ssl: boolean_attribute,
23
- events: { type: "set", default: this.defaultEvents }
24
+ events: {
25
+ ...string_collection_attribute_writable,
26
+ default: this.defaultEvents
27
+ }
24
28
  };
25
29
 
30
+ set events(value) {
31
+ this._events = new Set(value);
32
+ }
33
+
34
+ get events() {
35
+ return this._events;
36
+ }
37
+
26
38
  static get addMethodName() {
27
39
  return "_addHook";
28
40
  }
package/src/index.mjs CHANGED
@@ -18,5 +18,4 @@ export * from "./hook.mjs";
18
18
  export * from "./milestone.mjs";
19
19
  export * from "./review.mjs";
20
20
  export * from "./application.mjs";
21
- export * from "./attribute-extras.mjs";
22
21
  export * from "./util.mjs";
package/src/milestone.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { state_attribute } from "pacc";
1
+ import { state_attribute_writable } from "pacc";
2
2
  import { OwnedObject } from "./owned-object.mjs";
3
3
 
4
4
  /**
@@ -6,7 +6,7 @@ import { OwnedObject } from "./owned-object.mjs";
6
6
  export class Milestone extends OwnedObject {
7
7
  static attributes = {
8
8
  ...super.attributes,
9
- state: state_attribute
9
+ state: state_attribute_writable
10
10
  };
11
11
 
12
12
  async *issues() {}
@@ -1,5 +1,4 @@
1
- import { name_attribute } from "pacc";
2
- import { optionJSON } from "./attribute-extras.mjs";
1
+ import { getAttributesJSON, name_attribute_writable } from "pacc";
3
2
  import { BaseObject } from "./base-object.mjs";
4
3
 
5
4
  /**
@@ -16,24 +15,15 @@ import { BaseObject } from "./base-object.mjs";
16
15
  export class NamedObject extends BaseObject {
17
16
  static attributes = {
18
17
  ...BaseObject.attributes,
19
- name: name_attribute
18
+ name: name_attribute_writable
20
19
  };
21
20
 
22
- constructor(name, options, additionalProperties) {
23
- super(options, {
24
- name: { value: name },
25
- ...additionalProperties
26
- });
27
- }
28
-
29
- /** @type {string} */ #name;
30
-
31
- get name() {
32
- return this.#name;
33
- }
21
+ name;
34
22
 
35
- set name(name) {
36
- this.#name = name;
23
+ constructor(name, options) {
24
+ delete options?.name; // TODO
25
+ super(options);
26
+ this.name = name;
37
27
  }
38
28
 
39
29
  /**
@@ -77,9 +67,7 @@ export class NamedObject extends BaseObject {
77
67
  /**
78
68
  * Provided name and all defined attributes.
79
69
  */
80
- toJSON() {
81
- return optionJSON(this, {
82
- name: this.name
83
- });
70
+ toJSON(filter) {
71
+ return { ...getAttributesJSON(this, this.constructor.attributes, filter), name: this.name };
84
72
  }
85
73
  }
@@ -29,8 +29,8 @@ export class OwnedObject extends NamedObject {
29
29
 
30
30
  owner;
31
31
 
32
- constructor(owner, name, options, additionalProperties) {
33
- super(name, options, additionalProperties);
32
+ constructor(owner, name, options) {
33
+ super(name, options);
34
34
  this.owner = owner;
35
35
  // @ts-ignore
36
36
  owner[this.constructor.addMethodName](this);
@@ -1,12 +1,15 @@
1
1
  import {
2
+ getAttributesJSON,
3
+ attributeIterator,
2
4
  url_attribute,
3
- state_attribute,
4
- body_attribute,
5
- title_attribute,
5
+ state_attribute_writable,
6
+ body_attribute_writable,
7
+ title_attribute_writable,
6
8
  boolean_attribute_false,
7
- empty_attribute
9
+ boolean_attribute_writable_false,
10
+ empty_attribute,
11
+ types
8
12
  } from "pacc";
9
- import { optionJSON } from "./attribute-extras.mjs";
10
13
  import { OwnedObject } from "./owned-object.mjs";
11
14
  import { Branch } from "./branch.mjs";
12
15
  import { Repository } from "./repository.mjs";
@@ -94,8 +97,8 @@ export class PullRequest extends OwnedObject {
94
97
 
95
98
  static attributes = {
96
99
  ...super.attributes,
97
- body: body_attribute,
98
- title: title_attribute,
100
+ body: body_attribute_writable,
101
+ title: title_attribute_writable,
99
102
  url: url_attribute,
100
103
 
101
104
  /**
@@ -106,7 +109,7 @@ export class PullRequest extends OwnedObject {
106
109
  * @return {string}
107
110
  */
108
111
  state: {
109
- ...state_attribute,
112
+ ...state_attribute_writable,
110
113
  default: "OPEN",
111
114
  values: this.states
112
115
  },
@@ -115,7 +118,7 @@ export class PullRequest extends OwnedObject {
115
118
  * Locked state of the pull request.
116
119
  * @return {boolean}
117
120
  */
118
- locked: boolean_attribute_false,
121
+ locked: boolean_attribute_writable_false,
119
122
 
120
123
  /**
121
124
  * Merged state of the pull request.
@@ -127,44 +130,41 @@ export class PullRequest extends OwnedObject {
127
130
  * Draft state of the pull request.
128
131
  * @return {boolean}
129
132
  */
130
- draft: boolean_attribute_false,
133
+ draft: boolean_attribute_writable_false,
131
134
  dry: boolean_attribute_false,
132
135
  empty: empty_attribute
133
136
  };
134
137
 
135
138
  /** @type {Branch} */ source;
136
139
 
137
- constructor(source, owner, name, options) {
138
- let state = "OPEN";
139
-
140
- super(owner, name, options, {
141
- state: {
142
- set(value) {
143
- value = value.toUpperCase();
144
- // @ts-ignore
145
- if (this.constructor.attributes.state.values.has(value)) {
146
- state = value;
147
- } else throw new Error(`Invalid Pull Request state ${value}`);
148
- },
149
- get() {
150
- return state;
151
- }
152
- },
153
- merged: {
154
- set(value) {
155
- if (value) {
156
- state = "MERGED";
157
- }
158
- },
159
- get() {
160
- return state === "MERGED";
161
- }
162
- }
163
- });
140
+ _state = "OPEN";
164
141
 
142
+ constructor(source, owner, name, options) {
143
+ super(owner, name, options);
165
144
  this.source = source;
166
145
  }
167
146
 
147
+ set state(value) {
148
+ value = value.toUpperCase();
149
+ if (this.constructor.attributes.state.values.has(value)) {
150
+ this._state = value;
151
+ } else throw new Error(`Invalid Pull Request state ${value}`);
152
+ }
153
+
154
+ get state() {
155
+ return this._state;
156
+ }
157
+
158
+ set merged(value) {
159
+ if (value) {
160
+ this.state = "MERGED";
161
+ }
162
+ }
163
+
164
+ get merged() {
165
+ return this.state === "MERGED";
166
+ }
167
+
168
168
  get destination() {
169
169
  return this.owner;
170
170
  }
@@ -237,31 +237,34 @@ export class PullRequest extends OwnedObject {
237
237
 
238
238
  toString() {
239
239
  return [
240
- // @ts-ignore
241
240
  [this.name, this.title],
242
241
  ["source", this.source?.identifier],
243
242
  ["destination", this.owner.identifier],
244
- // @ts-ignore
245
- ...Object.entries(this.constructor.attributes)
246
- .filter(
247
- ([k, v]) =>
248
- !v.isKey &&
249
- v.type !== "url" &&
250
- k !== "title" &&
251
- k !== "body" &&
252
- this[k] !== undefined
243
+ ...[
244
+ ...attributeIterator(
245
+ this.constructor.attributes,
246
+ (name, attribute) =>
247
+ !attribute.isKey &&
248
+ attribute.type !== types.url &&
249
+ name !== "title" &&
250
+ name !== "body" &&
251
+ this[name] !== undefined
253
252
  )
254
- .map(([k]) => [k, this[k]])
253
+ ].map(([path, attribute]) => {
254
+ const name = path.join(".");
255
+ return [name, this[name]];
256
+ })
255
257
  ]
256
- .map(([k, v]) => `${k}: ${v}`)
257
- .join(", ");
258
+ .map(([name, value]) => `${name}:${value}`)
259
+ .join(",");
258
260
  }
259
261
 
260
- toJSON() {
261
- return optionJSON(this, {
262
+ toJSON(filter) {
263
+ return {
264
+ ...getAttributesJSON(this, this.constructor.attributes, filter),
262
265
  source: this.source,
263
266
  destination: this.owner
264
- });
267
+ };
265
268
  }
266
269
 
267
270
  /**
package/src/ref.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { name_attribute, boolean_attribute_writable_false } from "pacc";
1
+ import { name_attribute_writable, boolean_attribute_writable_false } from "pacc";
2
2
  import { ContentEntry } from "content-entry";
3
3
  import { OwnedObject } from "./owned-object.mjs";
4
4
 
@@ -16,17 +16,13 @@ export class Ref extends OwnedObject {
16
16
  * @type {Object}
17
17
  */
18
18
  static attributes = {
19
- name: name_attribute,
19
+ name: name_attribute_writable,
20
20
 
21
21
  /**
22
22
  * Can the ref be modified.
23
23
  * @return {boolean}
24
24
  */
25
- isProtected: boolean_attribute_writable_false
26
- };
27
-
28
- static attributeMapping = {
29
- protected: "isProtected"
25
+ isProtected: {...boolean_attribute_writable_false, externalName: "protected" }
30
26
  };
31
27
 
32
28
  get refType() {
@@ -1,4 +1,4 @@
1
- import { url_attribute, url_attribute_writble, boolean_attribute, type_attribute } from "pacc";
1
+ import { url_attribute, url_attribute_writable, boolean_attribute, type_attribute } from "pacc";
2
2
  import { RepositoryOwner } from "./repository-owner.mjs";
3
3
  import { OwnedObject } from "./owned-object.mjs";
4
4
  import { BaseProvider } from "./base-provider.mjs";
@@ -46,14 +46,9 @@ export class RepositoryGroup extends RepositoryOwner(OwnedObject) {
46
46
  * The url of home page.
47
47
  * @return {string}
48
48
  */
49
- homePageURL: url_attribute_writble
49
+ homePageURL: url_attribute_writable
50
50
  };
51
51
 
52
- /**
53
- * Map attributes between external and internal representation.
54
- */
55
- static attributeMapping() {}
56
-
57
52
  get isAdmin() {
58
53
  return false;
59
54
  }
@@ -1,8 +1,8 @@
1
1
  import {
2
- string_attribute,
2
+ string_attribute_writable,
3
3
  url_attribute,
4
- boolean_attribute,
5
- boolean_attribute_false
4
+ boolean_attribute_false,
5
+ boolean_attribute_writable_false
6
6
  } from "pacc";
7
7
  import { matcher } from "matching-iterator";
8
8
  import { ContentEntry } from "content-entry";
@@ -56,16 +56,18 @@ export class Repository extends OwnedObject {
56
56
  * @return {string}
57
57
  */
58
58
  defaultBranchName: {
59
- ...string_attribute,
60
- default: Repository.defaultBranchName
59
+ ...string_attribute_writable,
60
+ default: this.defaultBranchName,
61
+ externalName: "default_branch"
61
62
  },
62
63
 
63
64
  cloneURL: url_attribute,
64
- isArchived: boolean_attribute,
65
- isLocked: boolean_attribute,
66
- isDisabled: boolean_attribute,
67
- isTemplate: boolean_attribute,
68
- isFork: boolean_attribute_false
65
+ isArchived: { ...boolean_attribute_writable_false, externalName: "archived" },
66
+ isLocked: { ...boolean_attribute_writable_false, externalName: "locked" },
67
+ isDisabled: { ...boolean_attribute_writable_false, externalName: "disabled" },
68
+ isTemplate: { ...boolean_attribute_writable_false, externalName: "template" },
69
+ isFork: { ...boolean_attribute_false, externalName: "fork" },
70
+ isPrivate: { ...boolean_attribute_writable_false, externalName: "private" }
69
71
  };
70
72
 
71
73
  /** @type {Map<string,Branch>} */ #branches = new Map();
@@ -85,14 +87,12 @@ export class Repository extends OwnedObject {
85
87
  * @param {Object} [options]
86
88
  * @param {string} [options.id]
87
89
  * @param {string} [options.description]
88
- * @param {Object} [additionalProperties]
89
90
  */
90
- constructor(owner, name, options, additionalProperties) {
91
+ constructor(owner, name, options) {
91
92
  super(
92
93
  owner,
93
94
  owner.normalizeRepositoryName(name, false),
94
- options,
95
- additionalProperties
95
+ options
96
96
  );
97
97
  }
98
98
 
@@ -113,7 +113,7 @@ export class Repository extends OwnedObject {
113
113
  }
114
114
 
115
115
  get defaultBranchName() {
116
- return Repository.defaultBranchName;
116
+ return this.constructor.defaultBranchName;
117
117
  }
118
118
 
119
119
  /**
@@ -34,22 +34,16 @@ export class BaseObject {
34
34
  * @return {Object} writable attributes
35
35
  */
36
36
  static get writableAttributes(): any;
37
- /**
38
- * Map attributes between external and internal representation.
39
- * @return {Object}
40
- */
41
- static attributeMapping: {};
42
37
  /**
43
38
  * Creates an instance of BaseObject.
44
39
  * @param {Object} [options]
45
40
  * @param {string} [options.id]
46
41
  * @param {string} [options.description]
47
- * @param {Object} [additionalProperties]
48
42
  */
49
43
  constructor(options?: {
50
44
  id?: string;
51
45
  description?: string;
52
- }, additionalProperties?: any);
46
+ });
53
47
  /** @type {string} */ id: string;
54
48
  /** @type {string} */ description: string;
55
49
  /**
@@ -57,7 +51,7 @@ export class BaseObject {
57
51
  * @param {Object} [options]
58
52
  * @param {Object} [additionalProperties]
59
53
  */
60
- updateAttributes(options?: any, additionalProperties?: any): void;
54
+ updateAttributes(options?: any): void;
61
55
  /**
62
56
  * Save object attributes in the backing store.
63
57
  */