pacc 4.31.0 → 4.32.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 +2 -1
- package/package.json +2 -2
- package/src/attributes.mjs +5 -6
- package/src/environment.mjs +1 -1
- package/src/multiple.mjs +27 -4
- package/types/multiple.d.mts +7 -0
package/README.md
CHANGED
|
@@ -183,6 +183,7 @@ Type: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Globa
|
|
|
183
183
|
* `default` **any?** the default value
|
|
184
184
|
* `set` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)?** set the value
|
|
185
185
|
* `get` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)?** get the value can be used to calculate default values
|
|
186
|
+
* `prepareValue` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)?** 
|
|
186
187
|
* `values` **[Set](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Set)\<any>?** allowed values
|
|
187
188
|
* `externalName` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** attrubute name used by external system
|
|
188
189
|
* `env` **([Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)> | [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String))?** environment variable(s) used to provide the value
|
|
@@ -383,8 +384,8 @@ Extract values from environment.
|
|
|
383
384
|
|
|
384
385
|
### Parameters
|
|
385
386
|
|
|
386
|
-
* `attributes` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** as from process.env
|
|
387
387
|
* `env` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** as from process.env
|
|
388
|
+
* `attributes` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** as from process.env
|
|
388
389
|
* `instanceIdentifier` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** part of variable name.
|
|
389
390
|
|
|
390
391
|
Returns **([Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object) | [undefined](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined))** undefined if no suitable environment variables have been found
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pacc",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.32.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"provenance": true
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"browser-ava": "^2.3.32",
|
|
43
43
|
"c8": "^10.1.3",
|
|
44
44
|
"documentation": "^14.0.3",
|
|
45
|
-
"semantic-release": "^24.2.
|
|
45
|
+
"semantic-release": "^24.2.9",
|
|
46
46
|
"typescript": "^5.9.2"
|
|
47
47
|
},
|
|
48
48
|
"engines": {
|
package/src/attributes.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {getAttribute} from "./settergetter.mjs";
|
|
1
|
+
import { getAttribute } from "./settergetter.mjs";
|
|
2
2
|
|
|
3
3
|
export const baseTypes = new Set(["string", "number", "bigint", "boolean"]);
|
|
4
4
|
|
|
@@ -86,14 +86,13 @@ function mergeAttributeDefinitions(dest, atts) {
|
|
|
86
86
|
export function* attributeIterator(definition, filter, path = []) {
|
|
87
87
|
if (definition) {
|
|
88
88
|
for (const [name, def] of Object.entries(definition)) {
|
|
89
|
+
const path2 = [...path, name];
|
|
89
90
|
if (!filter || filter(name, def)) {
|
|
90
|
-
const path2 = [...path, name];
|
|
91
|
-
|
|
92
91
|
yield [path2, def];
|
|
92
|
+
}
|
|
93
93
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
94
|
+
if (def.attributes) {
|
|
95
|
+
yield* attributeIterator(def.attributes, filter, path2);
|
|
97
96
|
}
|
|
98
97
|
}
|
|
99
98
|
}
|
package/src/environment.mjs
CHANGED
|
@@ -12,7 +12,7 @@ export function environmentValues(env, attributes, instanceIdentifier) {
|
|
|
12
12
|
|
|
13
13
|
for (const [path, attribute] of attributeIterator(
|
|
14
14
|
attributes,
|
|
15
|
-
(name, attribute) => attribute.env
|
|
15
|
+
(name, attribute) => attribute.env
|
|
16
16
|
)) {
|
|
17
17
|
const name = path.join(".");
|
|
18
18
|
|
package/src/multiple.mjs
CHANGED
|
@@ -18,7 +18,7 @@ export function setAttributes(object, source, definitions, cb) {
|
|
|
18
18
|
if (def.default === undefined) {
|
|
19
19
|
continue;
|
|
20
20
|
} else {
|
|
21
|
-
if (getAttribute(object, name) !== undefined) {
|
|
21
|
+
if (getAttribute(object, name, def) !== undefined) {
|
|
22
22
|
continue;
|
|
23
23
|
}
|
|
24
24
|
value = def.default;
|
|
@@ -28,7 +28,7 @@ export function setAttributes(object, source, definitions, cb) {
|
|
|
28
28
|
if (def.set) {
|
|
29
29
|
def.set.call(object, value, def);
|
|
30
30
|
} else {
|
|
31
|
-
setAttribute(object, name, value);
|
|
31
|
+
setAttribute(object, name, value, def);
|
|
32
32
|
}
|
|
33
33
|
if (cb) {
|
|
34
34
|
cb(def, name, value);
|
|
@@ -48,9 +48,32 @@ export function getAttributes(object, definitions) {
|
|
|
48
48
|
for (const [path, def] of attributeIterator(definitions)) {
|
|
49
49
|
const name = path.join(".");
|
|
50
50
|
|
|
51
|
-
const value = getAttribute(object, name);
|
|
51
|
+
const value = getAttribute(object, name, def);
|
|
52
52
|
if (value !== undefined) {
|
|
53
|
-
result
|
|
53
|
+
setAttribute(result, name, value, def);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Retrive attribute values from an object.
|
|
61
|
+
* @param {Object} object attribute value source
|
|
62
|
+
* @param {Object} definitions
|
|
63
|
+
* @return {Object} values
|
|
64
|
+
*/
|
|
65
|
+
export function getAttributesJSON(object, definitions) {
|
|
66
|
+
const result = {};
|
|
67
|
+
|
|
68
|
+
for (const [path, def] of attributeIterator(definitions)) {
|
|
69
|
+
const name = path.join(".");
|
|
70
|
+
|
|
71
|
+
let value = getAttribute(object, name, def);
|
|
72
|
+
if (value !== undefined) {
|
|
73
|
+
if(value instanceof Set) {
|
|
74
|
+
value = [...value];
|
|
75
|
+
}
|
|
76
|
+
setAttribute(result, def.externalName ?? name, value, def);
|
|
54
77
|
}
|
|
55
78
|
}
|
|
56
79
|
return result;
|
package/types/multiple.d.mts
CHANGED
|
@@ -13,3 +13,10 @@ export function setAttributes(object: any, source: any, definitions: any, cb: Fu
|
|
|
13
13
|
* @return {Object} values
|
|
14
14
|
*/
|
|
15
15
|
export function getAttributes(object: any, definitions: any): any;
|
|
16
|
+
/**
|
|
17
|
+
* Retrive attribute values from an object.
|
|
18
|
+
* @param {Object} object attribute value source
|
|
19
|
+
* @param {Object} definitions
|
|
20
|
+
* @return {Object} values
|
|
21
|
+
*/
|
|
22
|
+
export function getAttributesJSON(object: any, definitions: any): any;
|