pacc 4.29.0 → 4.30.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 +6 -1
- package/package.json +1 -1
- package/src/attributes.mjs +20 -2
- package/src/common-attributes.mjs +1 -0
- package/src/environment.mjs +34 -0
- package/src/module.mjs +1 -0
- package/src/properties.mjs +4 -1
- package/types/attributes.d.mts +1 -0
- package/types/common-attributes.d.mts +6 -0
- package/types/environment.d.mts +8 -0
- package/types/module.d.mts +1 -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
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import {getAttribute} from "./settergetter.mjs";
|
|
2
|
+
|
|
1
3
|
export const baseTypes = new Set(["string", "number", "bigint", "boolean"]);
|
|
2
4
|
|
|
3
5
|
export const types = {
|
|
@@ -102,8 +104,24 @@ export function* writableAttributeIterator(definition) {
|
|
|
102
104
|
}
|
|
103
105
|
|
|
104
106
|
export function prepareValue(value, attribute) {
|
|
105
|
-
if (attribute
|
|
106
|
-
|
|
107
|
+
if (attribute) {
|
|
108
|
+
const prepareValue = attribute.prepareValue ?? attribute.type?.prepareValue;
|
|
109
|
+
if (prepareValue) {
|
|
110
|
+
return prepareValue(value, attribute);
|
|
111
|
+
}
|
|
107
112
|
}
|
|
108
113
|
return value;
|
|
109
114
|
}
|
|
115
|
+
|
|
116
|
+
export function manadatoryAttributesPresent(object, attributes) {
|
|
117
|
+
for (const [path, attribute] of attributeIterator(
|
|
118
|
+
attributes,
|
|
119
|
+
(name, attribute) => attribute.mandatory
|
|
120
|
+
)) {
|
|
121
|
+
const name = path.join(".");
|
|
122
|
+
if (getAttribute(object, name) === undefined) {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
* @property {Set<any>} [values] allowed values
|
|
16
16
|
* @property {string} [externalName] attrubute name used by external system
|
|
17
17
|
* @property {string[]|string} [env] environment variable(s) used to provide the value
|
|
18
|
+
* @property {object} [additionalValues] other values to be set in case our attribute is set
|
|
18
19
|
*/
|
|
19
20
|
|
|
20
21
|
/**
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { attributeIterator, setAttribute } from "pacc";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Extract values from environment.
|
|
5
|
+
* @param {Object} attributes as from process.env
|
|
6
|
+
* @param {Object} env as from process.env
|
|
7
|
+
* @param {string} instanceIdentifier part of variable name.
|
|
8
|
+
* @return {Object|undefined} undefined if no suitable environment variables have been found
|
|
9
|
+
*/
|
|
10
|
+
export function environmentValues(attributes, env, instanceIdentifier) {
|
|
11
|
+
let values;
|
|
12
|
+
|
|
13
|
+
for (const [path, attribute] of attributeIterator(
|
|
14
|
+
attributes,
|
|
15
|
+
(name, attribute) => attribute.env || attribute.attributes
|
|
16
|
+
)) {
|
|
17
|
+
const name = path.join(".");
|
|
18
|
+
|
|
19
|
+
for (const envName of (Array.isArray(attribute.env)
|
|
20
|
+
? attribute.env
|
|
21
|
+
: [attribute.env]
|
|
22
|
+
).map(
|
|
23
|
+
name =>
|
|
24
|
+
name && name.replace("{{instanceIdentifier}}", () => instanceIdentifier)
|
|
25
|
+
)) {
|
|
26
|
+
if (env[envName] !== undefined) {
|
|
27
|
+
values ??= {};
|
|
28
|
+
setAttribute(values, name, env[envName]);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return values;
|
|
34
|
+
}
|
package/src/module.mjs
CHANGED
package/src/properties.mjs
CHANGED
|
@@ -14,7 +14,10 @@ export function definePropertiesFromAttributes(
|
|
|
14
14
|
const name = path.join(".");
|
|
15
15
|
const externalName = attribute.externalName ?? name;
|
|
16
16
|
|
|
17
|
-
let value =
|
|
17
|
+
let value =
|
|
18
|
+
getAttribute(initialValues, externalName, attribute) ??
|
|
19
|
+
initialValues?.[externalName] ??
|
|
20
|
+
attribute.default;
|
|
18
21
|
|
|
19
22
|
if (value !== undefined) {
|
|
20
23
|
if (path.length === 1) {
|
package/types/attributes.d.mts
CHANGED
|
@@ -15,6 +15,7 @@ export function prepareAttributesDefinitions(newDefinitions: any, presentDefinit
|
|
|
15
15
|
export function attributeIterator(definition: any, filter: Function, path?: string[]): Iterable<[string[], object]>;
|
|
16
16
|
export function writableAttributeIterator(definition: any): Generator<[string[], any], void, any>;
|
|
17
17
|
export function prepareValue(value: any, attribute: any): any;
|
|
18
|
+
export function manadatoryAttributesPresent(object: any, attributes: any): boolean;
|
|
18
19
|
export const baseTypes: Set<string>;
|
|
19
20
|
export const types: {
|
|
20
21
|
base: {
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
* @property {Set<any>} [values] allowed values
|
|
16
16
|
* @property {string} [externalName] attrubute name used by external system
|
|
17
17
|
* @property {string[]|string} [env] environment variable(s) used to provide the value
|
|
18
|
+
* @property {object} [additionalValues] other values to be set in case our attribute is set
|
|
18
19
|
*/
|
|
19
20
|
/**
|
|
20
21
|
* Common attribute properties.
|
|
@@ -42,6 +43,7 @@ export namespace string_collection_attribute {
|
|
|
42
43
|
export let values: Set<any>;
|
|
43
44
|
export let externalName: string;
|
|
44
45
|
export let env: string[] | string;
|
|
46
|
+
export let additionalValues: object;
|
|
45
47
|
}
|
|
46
48
|
/**
|
|
47
49
|
* @type {AttributeDefinition}
|
|
@@ -206,5 +208,9 @@ export type AttributeDefinition = {
|
|
|
206
208
|
* environment variable(s) used to provide the value
|
|
207
209
|
*/
|
|
208
210
|
env?: string[] | string;
|
|
211
|
+
/**
|
|
212
|
+
* other values to be set in case our attribute is set
|
|
213
|
+
*/
|
|
214
|
+
additionalValues?: object;
|
|
209
215
|
};
|
|
210
216
|
export { default_attribute as string_attribute, default_attribute_writable as string_attribute_writable, default_attribute as type_attribute, default_attribute_writable as state_attribute, boolean_attribute_writable_false as boolean_attribute, boolean_attribute_writable_true as active_attribute, secret_attribute as username_attribute, secret_attribute as password_attribute, secret_attribute as token_attribute, secret_attribute as certificate_attribute, integer_attribute as count_attribute, integer_attribute as size_attribute, default_attribute_writable as body_attribute, number_attribute as duration_attribute };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extract values from environment.
|
|
3
|
+
* @param {Object} attributes as from process.env
|
|
4
|
+
* @param {Object} env as from process.env
|
|
5
|
+
* @param {string} instanceIdentifier part of variable name.
|
|
6
|
+
* @return {Object|undefined} undefined if no suitable environment variables have been found
|
|
7
|
+
*/
|
|
8
|
+
export function environmentValues(attributes: any, env: any, instanceIdentifier: string): any | undefined;
|
package/types/module.d.mts
CHANGED
|
@@ -6,4 +6,5 @@ export * from "./common-attributes.mjs";
|
|
|
6
6
|
export * from "./properties.mjs";
|
|
7
7
|
export * from "./expression.mjs";
|
|
8
8
|
export * from "./expand.mjs";
|
|
9
|
+
export * from "./environment.mjs";
|
|
9
10
|
export { setAttribute, getAttribute, getAttributeAndOperator } from "./settergetter.mjs";
|