repository-provider 32.6.4 → 32.6.6

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
@@ -52,17 +52,17 @@ console.log(await readme.getString());
52
52
  * [Parameters](#parameters)
53
53
  * [defaultValues](#defaultvalues)
54
54
  * [Parameters](#parameters-1)
55
- * [tokens](#tokens)
55
+ * [optionJSON](#optionjson)
56
56
  * [Parameters](#parameters-2)
57
- * [setAttribute](#setattribute)
57
+ * [mapAttributes](#mapattributes)
58
58
  * [Parameters](#parameters-3)
59
- * [getAttribute](#getattribute)
59
+ * [mapAttributesInverse](#mapattributesinverse)
60
60
  * [Parameters](#parameters-4)
61
- * [optionJSON](#optionjson)
61
+ * [tokens](#tokens)
62
62
  * [Parameters](#parameters-5)
63
- * [mapAttributes](#mapattributes)
63
+ * [setAttribute](#setattribute)
64
64
  * [Parameters](#parameters-6)
65
- * [mapAttributesInverse](#mapattributesinverse)
65
+ * [getAttribute](#getattribute)
66
66
  * [Parameters](#parameters-7)
67
67
  * [description\_attribute](#description_attribute)
68
68
  * [id\_attribute](#id_attribute)
@@ -408,39 +408,6 @@ Get default values.
408
408
 
409
409
  Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** filled with default values
410
410
 
411
- ## tokens
412
-
413
- Split property path into tokens
414
-
415
- ### Parameters
416
-
417
- * `string` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** 
418
-
419
- Returns **Iterator<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>**&#x20;
420
-
421
- ## setAttribute
422
-
423
- Set Object attribute.
424
- The name may be a property path like 'a.b.c'.
425
-
426
- ### Parameters
427
-
428
- * `object` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**&#x20;
429
- * `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**&#x20;
430
- * `value` **any**&#x20;
431
-
432
- ## getAttribute
433
-
434
- Deliver attribute value.
435
- The name may be a property path like 'a.b.c'.
436
-
437
- ### Parameters
438
-
439
- * `object` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**&#x20;
440
- * `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**&#x20;
441
-
442
- Returns **any** value associated with the given property name
443
-
444
411
  ## optionJSON
445
412
 
446
413
  Create json based on present options.
@@ -482,6 +449,39 @@ Filters out null, undefined and empty strings
482
449
 
483
450
  Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** keys renamed after mapping
484
451
 
452
+ ## tokens
453
+
454
+ Split property path into tokens
455
+
456
+ ### Parameters
457
+
458
+ * `string` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**&#x20;
459
+
460
+ Returns **Iterator<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>**&#x20;
461
+
462
+ ## setAttribute
463
+
464
+ Set Object attribute.
465
+ The name may be a property path like 'a.b.c'.
466
+
467
+ ### Parameters
468
+
469
+ * `object` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**&#x20;
470
+ * `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**&#x20;
471
+ * `value` **any**&#x20;
472
+
473
+ ## getAttribute
474
+
475
+ Deliver attribute value.
476
+ The name may be a property path like 'a.b.c'.
477
+
478
+ ### Parameters
479
+
480
+ * `object` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**&#x20;
481
+ * `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**&#x20;
482
+
483
+ Returns **any** value associated with the given property name
484
+
485
485
  ## description\_attribute
486
486
 
487
487
  The description of the object content.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "repository-provider",
3
- "version": "32.6.4",
3
+ "version": "32.6.6",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -33,12 +33,12 @@
33
33
  "matching-iterator": "^2.0.11"
34
34
  },
35
35
  "devDependencies": {
36
- "ava": "^5.1.1",
37
- "browser-ava": "^1.3.20",
38
- "c8": "^7.12.0",
36
+ "ava": "^5.2.0",
37
+ "browser-ava": "^1.3.25",
38
+ "c8": "^7.13.0",
39
39
  "documentation": "^14.0.1",
40
40
  "repository-provider-test-support": "^2.2.36",
41
- "semantic-release": "^20.1.0",
41
+ "semantic-release": "^20.1.1",
42
42
  "typescript": "^4.9.5"
43
43
  },
44
44
  "engines": {
@@ -0,0 +1,208 @@
1
+
2
+ import { setAttribute, getAttribute } from "./attribute.mjs";
3
+
4
+ /**
5
+ * @typedef {Object} Attribute
6
+ *
7
+ * @property {string} type
8
+ * @property {boolean} writable
9
+ * @property {boolean} [private] should the value be shown
10
+ * @property {string} [depends] name of an attribute we depend on
11
+ * @property {string} description
12
+ * @property {any} [default] the default value
13
+ * @property {Function} [set] set the value
14
+ * @property {Function} [get] get the value can be used to calculate default values
15
+ * @property {string|string[]} [env] environment variable use to provide the value
16
+ */
17
+
18
+ /**
19
+ * Create properties from options and default options.
20
+ * Already present properties (direct) are skipped.
21
+ * The attribute list from the class will be applied to the
22
+ * options and merged with the given set of properties.
23
+ * ```js
24
+ * class aClass {
25
+ * static get attributes() {
26
+ * return { with_default: { default: 77 }};
27
+ * }
28
+ * }
29
+ *
30
+ * definePropertiesFromOptions(new aClass());
31
+ * // equivalent to
32
+ * Object.definedProperties(new aClass(),{ with_default: { value: 77 }})
33
+ * ```
34
+ * @see Object.definedProperties()
35
+ * @see Object.getOwnPropertyDescriptor()
36
+ * @param {Object} object target object
37
+ * @param {Object} options as passed to object constructor
38
+ * @param {Object} properties object properties
39
+ * @param {Object} attributes
40
+ */
41
+ export function definePropertiesFromOptions(
42
+ object,
43
+ options = {},
44
+ properties = {},
45
+ attributes = object.constructor.attributes || []
46
+ ) {
47
+ const applyLater = {};
48
+
49
+ Object.entries(attributes).forEach(([name, attribute]) => {
50
+ const path = name.split(/\./);
51
+ const first = path.shift();
52
+ const property = properties[first];
53
+
54
+ let value = getAttribute(options, name);
55
+
56
+ if (value === undefined) {
57
+ if (attribute.get) {
58
+ value = attribute.get(attribute, object, properties);
59
+ } else if (
60
+ attribute.default !== undefined &&
61
+ attribute.default !== getAttribute(object, name)
62
+ ) {
63
+ value = attribute.default;
64
+ }
65
+ }
66
+
67
+ if (attribute.set) {
68
+ value = attribute.set(value);
69
+ } else {
70
+ switch (attribute.type) {
71
+ case "set":
72
+ if (Array.isArray(value)) {
73
+ value = new Set(value);
74
+ }
75
+ break;
76
+ case "boolean":
77
+ if (value !== undefined) {
78
+ value =
79
+ value === 0 || value === "0" || value === false ? false : true;
80
+ }
81
+ break;
82
+ }
83
+ }
84
+
85
+ if (path.length) {
86
+ const remaining = path.join(".");
87
+ if (property) {
88
+ setAttribute(property.value, remaining, value);
89
+ } else {
90
+ const slice = {};
91
+ setAttribute(slice, remaining, value);
92
+ properties[first] = { configurable: true, value: slice };
93
+ }
94
+ } else {
95
+ if (value !== undefined) {
96
+ const op = Object.getOwnPropertyDescriptor(
97
+ object.constructor.prototype,
98
+ first
99
+ );
100
+
101
+ if (op?.set || property?.set) {
102
+ applyLater[first] = value;
103
+ } else {
104
+ properties[first] = Object.assign(
105
+ { value, writable: attribute.writable },
106
+ property
107
+ );
108
+ }
109
+ }
110
+ }
111
+ });
112
+
113
+ Object.defineProperties(object, properties);
114
+ Object.assign(object, applyLater);
115
+ }
116
+
117
+ /**
118
+ * Get default values.
119
+ * @param {Object} attributes
120
+ * @return {Object} filled with default values
121
+ */
122
+ export function defaultValues(attributes, object) {
123
+ return Object.fromEntries(
124
+ Object.entries(attributes).reduce((a, c) => {
125
+ const [name, attribute] = c;
126
+
127
+ if (attribute.default !== undefined) {
128
+ a.push([name, attribute.default]);
129
+ } else if (attribute.get !== undefined) {
130
+ const value = attribute.get(attribute, object);
131
+ if (value !== undefined) {
132
+ a.push([name, value]);
133
+ }
134
+ }
135
+
136
+ return a;
137
+ }, [])
138
+ );
139
+ }
140
+
141
+ /**
142
+ * Create json based on present options.
143
+ * In other words only produce key value pairs if value is defined.
144
+ * @param {Object} object
145
+ * @param {Object} initial
146
+ * @param {Object} attributes to operator on
147
+ * @return {Object} initial + defined values
148
+ */
149
+ export function optionJSON(
150
+ object,
151
+ initial = {},
152
+ attributes = object.constructor.attributes
153
+ ) {
154
+ return attributes
155
+ ? Object.keys(attributes).reduce((a, c) => {
156
+ const value = object[c];
157
+ if (value !== undefined && !(value instanceof Function)) {
158
+ if (value instanceof Set) {
159
+ a[c] = [...value];
160
+ } else {
161
+ a[c] = value;
162
+ }
163
+ }
164
+ return a;
165
+ }, initial)
166
+ : initial;
167
+ }
168
+
169
+ /**
170
+ * Rename attributes.
171
+ * Filters out null, undefined and empty strings.
172
+ * ```js
173
+ * mapAttributes({a:1},{a:"a'"}) // {"a'": 1}
174
+ * ```
175
+ * @param {Object} object
176
+ * @param {Object} mapping
177
+ * @return {Object} keys renamed after mapping
178
+ */
179
+ export function mapAttributes(object, mapping) {
180
+ if (object !== undefined) {
181
+ const o = {};
182
+
183
+ for (const k of Object.keys(object)) {
184
+ const v = getAttribute(object, k);
185
+ if (v !== undefined && v !== null && v !== "") {
186
+ setAttribute(o, mapping[k] || k, v);
187
+ }
188
+ }
189
+
190
+ return o;
191
+ }
192
+ }
193
+
194
+ /**
195
+ * Same as mapAttributes but with the inverse mapping.
196
+ * Filters out null, undefined and empty strings
197
+ * @param {Object} object
198
+ * @param {Object} mapping
199
+ * @return {Object} keys renamed after mapping
200
+ */
201
+ export function mapAttributesInverse(object, mapping) {
202
+ return mapping === undefined
203
+ ? object
204
+ : mapAttributes(
205
+ object,
206
+ Object.fromEntries(Object.entries(mapping).map(([k, v]) => [v, k]))
207
+ );
208
+ }
package/src/attribute.mjs CHANGED
@@ -1,139 +1,3 @@
1
- /**
2
- * @typedef {Object} Attribute
3
- *
4
- * @property {string} type
5
- * @property {boolean} writable
6
- * @property {boolean} [private] should the value be shown
7
- * @property {string} [depends] name of an attribute we depend on
8
- * @property {string} description
9
- * @property {any} [default] the default value
10
- * @property {Function} [set] set the value
11
- * @property {Function} [get] get the value can be used to calculate default values
12
- * @property {string|string[]} [env] environment variable use to provide the value
13
- */
14
-
15
- /**
16
- * Create properties from options and default options.
17
- * Already present properties (direct) are skipped.
18
- * The attribute list from the class will be applied to the
19
- * options and merged with the given set of properties.
20
- * ```js
21
- * class aClass {
22
- * static get attributes() {
23
- * return { with_default: { default: 77 }};
24
- * }
25
- * }
26
- *
27
- * definePropertiesFromOptions(new aClass());
28
- * // equivalent to
29
- * Object.definedProperties(new aClass(),{ with_default: { value: 77 }})
30
- * ```
31
- * @see Object.definedProperties()
32
- * @see Object.getOwnPropertyDescriptor()
33
- * @param {Object} object target object
34
- * @param {Object} options as passed to object constructor
35
- * @param {Object} properties object properties
36
- * @param {Object} attributes
37
- */
38
- export function definePropertiesFromOptions(
39
- object,
40
- options = {},
41
- properties = {},
42
- attributes = object.constructor.attributes || []
43
- ) {
44
- const applyLater = {};
45
-
46
- Object.entries(attributes).forEach(([name, attribute]) => {
47
- const path = name.split(/\./);
48
- const first = path.shift();
49
- const property = properties[first];
50
-
51
- let value = getAttribute(options, name);
52
-
53
- if (value === undefined) {
54
- if (attribute.get) {
55
- value = attribute.get(attribute, object, properties);
56
- } else if (
57
- attribute.default !== undefined &&
58
- attribute.default !== getAttribute(object, name)
59
- ) {
60
- value = attribute.default;
61
- }
62
- }
63
-
64
- if (attribute.set) {
65
- value = attribute.set(value);
66
- } else {
67
- switch (attribute.type) {
68
- case "set":
69
- if (Array.isArray(value)) {
70
- value = new Set(value);
71
- }
72
- break;
73
- case "boolean":
74
- if (value !== undefined) {
75
- value =
76
- value === 0 || value === "0" || value === false ? false : true;
77
- }
78
- break;
79
- }
80
- }
81
-
82
- if (path.length) {
83
- const remaining = path.join(".");
84
- if (property) {
85
- setAttribute(property.value, remaining, value);
86
- } else {
87
- const slice = {};
88
- setAttribute(slice, remaining, value);
89
- properties[first] = { configurable: true, value: slice };
90
- }
91
- } else {
92
- if (value !== undefined) {
93
- const op = Object.getOwnPropertyDescriptor(
94
- object.constructor.prototype,
95
- first
96
- );
97
-
98
- if (op?.set || property?.set) {
99
- applyLater[first] = value;
100
- } else {
101
- properties[first] = Object.assign(
102
- { value, writable: attribute.writable },
103
- property
104
- );
105
- }
106
- }
107
- }
108
- });
109
-
110
- Object.defineProperties(object, properties);
111
- Object.assign(object, applyLater);
112
- }
113
-
114
- /**
115
- * Get default values.
116
- * @param {Object} attributes
117
- * @return {Object} filled with default values
118
- */
119
- export function defaultValues(attributes, object) {
120
- return Object.fromEntries(
121
- Object.entries(attributes).reduce((a, c) => {
122
- const [name, attribute] = c;
123
-
124
- if (attribute.default !== undefined) {
125
- a.push([name, attribute.default]);
126
- } else if (attribute.get !== undefined) {
127
- const value = attribute.get(attribute, object);
128
- if (value !== undefined) {
129
- a.push([name, value]);
130
- }
131
- }
132
-
133
- return a;
134
- }, [])
135
- );
136
- }
137
1
 
138
2
  /**
139
3
  * Split property path into tokens
@@ -143,7 +7,6 @@ export function defaultValues(attributes, object) {
143
7
  function* tokens(string) {
144
8
  let identifier = "";
145
9
 
146
-
147
10
  for (const c of string) {
148
11
  switch (c) {
149
12
  case "\t":
@@ -239,72 +102,3 @@ export function getAttribute(object, name) {
239
102
 
240
103
  return object;
241
104
  }
242
-
243
- /**
244
- * Create json based on present options.
245
- * In other words only produce key value pairs if value is defined.
246
- * @param {Object} object
247
- * @param {Object} initial
248
- * @param {Object} attributes to operator on
249
- * @return {Object} initial + defined values
250
- */
251
- export function optionJSON(
252
- object,
253
- initial = {},
254
- attributes = object.constructor.attributes
255
- ) {
256
- return attributes
257
- ? Object.keys(attributes).reduce((a, c) => {
258
- const value = object[c];
259
- if (value !== undefined && !(value instanceof Function)) {
260
- if (value instanceof Set) {
261
- a[c] = [...value];
262
- } else {
263
- a[c] = value;
264
- }
265
- }
266
- return a;
267
- }, initial)
268
- : initial;
269
- }
270
-
271
- /**
272
- * Rename attributes.
273
- * Filters out null, undefined and empty strings.
274
- * ```js
275
- * mapAttributes({a:1},{a:"a'"}) // {"a'": 1}
276
- * ```
277
- * @param {Object} object
278
- * @param {Object} mapping
279
- * @return {Object} keys renamed after mapping
280
- */
281
- export function mapAttributes(object, mapping) {
282
- if (object !== undefined) {
283
- const o = {};
284
-
285
- for (const k of Object.keys(object)) {
286
- const v = getAttribute(object, k);
287
- if (v !== undefined && v !== null && v !== "") {
288
- setAttribute(o, mapping[k] || k, v);
289
- }
290
- }
291
-
292
- return o;
293
- }
294
- }
295
-
296
- /**
297
- * Same as mapAttributes but with the inverse mapping.
298
- * Filters out null, undefined and empty strings
299
- * @param {Object} object
300
- * @param {Object} mapping
301
- * @return {Object} keys renamed after mapping
302
- */
303
- export function mapAttributesInverse(object, mapping) {
304
- return mapping === undefined
305
- ? object
306
- : mapAttributes(
307
- object,
308
- Object.fromEntries(Object.entries(mapping).map(([k, v]) => [v, k]))
309
- );
310
- }
@@ -1,4 +1,4 @@
1
- import { definePropertiesFromOptions, mapAttributes } from "./attribute.mjs";
1
+ import { definePropertiesFromOptions, mapAttributes } from "./attribute-extras.mjs";
2
2
  import { description_attribute, id_attribute } from "./attributes.mjs";
3
3
 
4
4
  /**
@@ -8,7 +8,12 @@ import { Hook } from "./hook.mjs";
8
8
  import { Project } from "./project.mjs";
9
9
  import { Milestone } from "./milestone.mjs";
10
10
  import { BaseObject } from "./base-object.mjs";
11
- import { url_attribute, name_attribute, description_attribute, priority_attribute } from "./attributes.mjs";
11
+ import {
12
+ url_attribute,
13
+ name_attribute,
14
+ description_attribute,
15
+ priority_attribute
16
+ } from "./attributes.mjs";
12
17
 
13
18
  /**
14
19
  * @typedef {Object} MessageDestination
@@ -103,11 +108,11 @@ export class BaseProvider extends BaseObject {
103
108
  */
104
109
  name: {
105
110
  ...name_attribute,
106
- env: ["{{instanceIdentifier}}NAME"]
111
+ env: "{{instanceIdentifier}}NAME"
107
112
  },
108
113
 
109
114
  url: url_attribute,
110
- description : description_attribute,
115
+ description: description_attribute,
111
116
  priority: priority_attribute,
112
117
 
113
118
  /**
package/src/index.mjs CHANGED
@@ -19,5 +19,6 @@ export * from "./milestone.mjs";
19
19
  export * from "./review.mjs";
20
20
  export * from "./application.mjs";
21
21
  export * from "./attribute.mjs";
22
+ export * from "./attribute-extras.mjs";
22
23
  export * from "./util.mjs";
23
24
  export * from "./attributes.mjs";
@@ -1,4 +1,4 @@
1
- import { optionJSON } from "./attribute.mjs";
1
+ import { optionJSON } from "./attribute-extras.mjs";
2
2
  import { BaseObject } from "./base-object.mjs";
3
3
  import { name_attribute, url_attribute, description_attribute, id_attribute } from "./attributes.mjs";
4
4
 
@@ -1,4 +1,4 @@
1
- import { optionJSON } from "./attribute.mjs";
1
+ import { optionJSON } from "./attribute-extras.mjs";
2
2
  import { OwnedObject } from "./owned-object.mjs";
3
3
  import { Branch } from "./branch.mjs";
4
4
  import { Repository } from "./repository.mjs";