pacc 4.28.0 → 4.29.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/README.md +6 -1
- package/package.json +1 -1
- package/src/attributes.mjs +5 -2
- package/src/common-attributes.mjs +2 -0
- package/src/properties.mjs +2 -1
- package/types/common-attributes.d.mts +12 -0
package/README.md
CHANGED
|
@@ -154,13 +154,16 @@ Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/G
|
|
|
154
154
|
|
|
155
155
|
## attributeIterator
|
|
156
156
|
|
|
157
|
-
|
|
157
|
+
Iterate over all attributes.
|
|
158
158
|
|
|
159
159
|
### Parameters
|
|
160
160
|
|
|
161
161
|
* `definition` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** 
|
|
162
|
+
* `filter` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** 
|
|
162
163
|
* `path` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>** (optional, default `[]`)
|
|
163
164
|
|
|
165
|
+
Returns **Iterable<\[[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>, [object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)]>** 
|
|
166
|
+
|
|
164
167
|
## AttributeDefinition
|
|
165
168
|
|
|
166
169
|
Type: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)
|
|
@@ -178,6 +181,8 @@ Type: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Globa
|
|
|
178
181
|
* `default` **any?** the default value
|
|
179
182
|
* `set` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)?** set the value
|
|
180
183
|
* `get` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)?** get the value can be used to calculate default values
|
|
184
|
+
* `values` **[Set](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Set)\<any>?** allowed values
|
|
185
|
+
* `externalName` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** attrubute name used by external system
|
|
181
186
|
* `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
|
|
182
187
|
|
|
183
188
|
## default\_attribute
|
package/package.json
CHANGED
package/src/attributes.mjs
CHANGED
|
@@ -102,8 +102,11 @@ export function* writableAttributeIterator(definition) {
|
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
export function prepareValue(value, attribute) {
|
|
105
|
-
if (attribute
|
|
106
|
-
|
|
105
|
+
if (attribute) {
|
|
106
|
+
const prepareValue = attribute.prepareValue ?? attribute.type?.prepareValue;
|
|
107
|
+
if (prepareValue) {
|
|
108
|
+
return prepareValue(value, attribute);
|
|
109
|
+
}
|
|
107
110
|
}
|
|
108
111
|
return value;
|
|
109
112
|
}
|
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
* @property {any} [default] the default value
|
|
13
13
|
* @property {Function} [set] set the value
|
|
14
14
|
* @property {Function} [get] get the value can be used to calculate default values
|
|
15
|
+
* @property {Set<any>} [values] allowed values
|
|
16
|
+
* @property {string} [externalName] attrubute name used by external system
|
|
15
17
|
* @property {string[]|string} [env] environment variable(s) used to provide the value
|
|
16
18
|
*/
|
|
17
19
|
|
package/src/properties.mjs
CHANGED
|
@@ -12,8 +12,9 @@ export function definePropertiesFromAttributes(
|
|
|
12
12
|
|
|
13
13
|
for (const [path, attribute] of attributeIterator(attributes)) {
|
|
14
14
|
const name = path.join(".");
|
|
15
|
+
const externalName = attribute.externalName ?? name;
|
|
15
16
|
|
|
16
|
-
let value = getAttribute(initialValues,
|
|
17
|
+
let value = getAttribute(initialValues, externalName, attribute) ?? initialValues?.[externalName] ?? attribute.default;
|
|
17
18
|
|
|
18
19
|
if (value !== undefined) {
|
|
19
20
|
if (path.length === 1) {
|
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
* @property {any} [default] the default value
|
|
13
13
|
* @property {Function} [set] set the value
|
|
14
14
|
* @property {Function} [get] get the value can be used to calculate default values
|
|
15
|
+
* @property {Set<any>} [values] allowed values
|
|
16
|
+
* @property {string} [externalName] attrubute name used by external system
|
|
15
17
|
* @property {string[]|string} [env] environment variable(s) used to provide the value
|
|
16
18
|
*/
|
|
17
19
|
/**
|
|
@@ -37,6 +39,8 @@ export namespace string_collection_attribute {
|
|
|
37
39
|
export { _default as default };
|
|
38
40
|
export let set: Function;
|
|
39
41
|
export let get: Function;
|
|
42
|
+
export let values: Set<any>;
|
|
43
|
+
export let externalName: string;
|
|
40
44
|
export let env: string[] | string;
|
|
41
45
|
}
|
|
42
46
|
/**
|
|
@@ -190,6 +194,14 @@ export type AttributeDefinition = {
|
|
|
190
194
|
* get the value can be used to calculate default values
|
|
191
195
|
*/
|
|
192
196
|
get?: Function;
|
|
197
|
+
/**
|
|
198
|
+
* allowed values
|
|
199
|
+
*/
|
|
200
|
+
values?: Set<any>;
|
|
201
|
+
/**
|
|
202
|
+
* attrubute name used by external system
|
|
203
|
+
*/
|
|
204
|
+
externalName?: string;
|
|
193
205
|
/**
|
|
194
206
|
* environment variable(s) used to provide the value
|
|
195
207
|
*/
|