pacc 4.29.1 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pacc",
3
- "version": "4.29.1",
3
+ "version": "4.30.0",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": true
@@ -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 = {
@@ -110,3 +112,16 @@ export function prepareValue(value, attribute) {
110
112
  }
111
113
  return value;
112
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
@@ -6,6 +6,7 @@ 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 {
10
11
  setAttribute,
11
12
  getAttribute,
@@ -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 = getAttribute(initialValues, externalName, attribute) ?? initialValues?.[externalName] ?? attribute.default;
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) {
@@ -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;
@@ -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";