pacc 4.27.1 → 4.29.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.27.1",
3
+ "version": "4.29.0",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": true
@@ -1,30 +1,34 @@
1
-
2
-
3
1
  export const baseTypes = new Set(["string", "number", "bigint", "boolean"]);
4
2
 
5
3
  export const types = {
6
4
  base: { name: "base" },
7
-
5
+
8
6
  string: { name: "string", extends: "base" },
9
7
  number: {
10
8
  name: "number",
11
9
  extends: "base",
12
- prepareValue: (value, attribute) =>
10
+ prepareValue: value =>
13
11
  typeof value === "string" ? parseFloat(value) : value
14
12
  },
15
13
  boolean: {
16
14
  name: "boolean",
17
15
  extends: "base",
18
- prepareValue: (value, attribute) => (!value || value === "0" ? false : true)
16
+ prepareValue: value =>
17
+ !value || value === "0" || value === "false" || value === "no"
18
+ ? false
19
+ : true
19
20
  },
20
-
21
21
  integer: {
22
22
  name: "integer",
23
23
  extends: "base",
24
- prepareValue: (value, attribute) =>
25
- typeof value === "string" ? parseInt(value) : value
24
+ prepareValue: value => (typeof value === "string" ? parseInt(value) : value)
25
+ },
26
+ "unsigned-integer": {
27
+ name: "unsigned-integer",
28
+ prepareValue: value =>
29
+ typeof value === "string" ? parseInt(value) : value,
30
+ extends: "integer"
26
31
  },
27
- "unsigned-integer": { name: "unsigned-integer", extends: "integer" },
28
32
  url: { name: "url", extends: "string" },
29
33
  object: { name: "object", extends: "base" }
30
34
  };
@@ -71,26 +75,32 @@ function mergeAttributeDefinitions(dest, atts) {
71
75
  }
72
76
 
73
77
  /**
74
- * iterate over all attributes.
78
+ * Iterate over all attributes.
75
79
  * @param {Object} definition
80
+ * @param {Function} filter
76
81
  * @param {string[]} path
82
+ * @return {Iterable<[string[],object]>}
77
83
  */
78
- export function* attributeIterator(definition, path = []) {
84
+ export function* attributeIterator(definition, filter, path = []) {
79
85
  if (definition) {
80
86
  for (const [name, def] of Object.entries(definition)) {
81
- path.push(name);
87
+ if (!filter || filter(name, def)) {
88
+ const path2 = [...path, name];
82
89
 
83
- if (def.attributes) {
84
- yield* attributeIterator(def.attributes, path);
85
- }
90
+ yield [path2, def];
86
91
 
87
- yield [path, def];
88
-
89
- path.pop();
92
+ if (def.attributes) {
93
+ yield* attributeIterator(def.attributes, filter, path2);
94
+ }
95
+ }
90
96
  }
91
97
  }
92
98
  }
93
99
 
100
+ export function* writableAttributeIterator(definition) {
101
+ yield* attributeIterator(definition, (name, def) => def.writable);
102
+ }
103
+
94
104
  export function prepareValue(value, attribute) {
95
105
  if (attribute?.type?.prepareValue) {
96
106
  return attribute.type.prepareValue(value, attribute);
@@ -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
 
@@ -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, name, attribute) ?? initialValues?.[name] ?? attribute.default;
17
+ let value = getAttribute(initialValues, externalName, attribute) ?? initialValues?.[externalName] ?? attribute.default;
17
18
 
18
19
  if (value !== undefined) {
19
20
  if (path.length === 1) {
@@ -6,11 +6,14 @@
6
6
  */
7
7
  export function prepareAttributesDefinitions(newDefinitions: any, presentDefinitions?: any): any;
8
8
  /**
9
- * iterate over all attributes.
9
+ * Iterate over all attributes.
10
10
  * @param {Object} definition
11
+ * @param {Function} filter
11
12
  * @param {string[]} path
13
+ * @return {Iterable<[string[],object]>}
12
14
  */
13
- export function attributeIterator(definition: any, path?: string[]): any;
15
+ export function attributeIterator(definition: any, filter: Function, path?: string[]): Iterable<[string[], object]>;
16
+ export function writableAttributeIterator(definition: any): Generator<[string[], any], void, any>;
14
17
  export function prepareValue(value: any, attribute: any): any;
15
18
  export const baseTypes: Set<string>;
16
19
  export const types: {
@@ -24,20 +27,21 @@ export const types: {
24
27
  number: {
25
28
  name: string;
26
29
  extends: string;
27
- prepareValue: (value: any, attribute: any) => any;
30
+ prepareValue: (value: any) => any;
28
31
  };
29
32
  boolean: {
30
33
  name: string;
31
34
  extends: string;
32
- prepareValue: (value: any, attribute: any) => boolean;
35
+ prepareValue: (value: any) => boolean;
33
36
  };
34
37
  integer: {
35
38
  name: string;
36
39
  extends: string;
37
- prepareValue: (value: any, attribute: any) => any;
40
+ prepareValue: (value: any) => any;
38
41
  };
39
42
  "unsigned-integer": {
40
43
  name: string;
44
+ prepareValue: (value: any) => any;
41
45
  extends: string;
42
46
  };
43
47
  url: {
@@ -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
  */