pacc 3.5.0 → 3.6.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 CHANGED
@@ -27,8 +27,6 @@ const result = getAttribute({ a: [0,{ b: 4 }]}, "a[1].b");
27
27
 
28
28
  ### Table of Contents
29
29
 
30
- * [AttributeDefinition](#attributedefinition)
31
- * [Properties](#properties)
32
30
  * [tokens](#tokens)
33
31
  * [tokens](#tokens-1)
34
32
  * [Parameters](#parameters)
@@ -40,11 +38,17 @@ const result = getAttribute({ a: [0,{ b: 4 }]}, "a[1].b");
40
38
  * [Parameters](#parameters-3)
41
39
  * [filter](#filter)
42
40
  * [Parameters](#parameters-4)
41
+ * [AttributeDefinition](#attributedefinition)
42
+ * [Properties](#properties)
43
+ * [setAttributes](#setattributes)
44
+ * [Parameters](#parameters-5)
45
+ * [getAttributes](#getattributes)
46
+ * [Parameters](#parameters-6)
43
47
  * [lookup](#lookup)
44
48
  * [Token](#token)
45
49
  * [Properties](#properties-1)
46
50
  * [createToken](#createtoken)
47
- * [Parameters](#parameters-5)
51
+ * [Parameters](#parameters-7)
48
52
  * [PLUS](#plus)
49
53
  * [MINUS](#minus)
50
54
  * [STAR](#star)
@@ -72,25 +76,6 @@ const result = getAttribute({ a: [0,{ b: 4 }]}, "a[1].b");
72
76
  * [BAR](#bar)
73
77
  * [DOUBLE\_BAR](#double_bar)
74
78
 
75
- ## AttributeDefinition
76
-
77
- Type: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)
78
-
79
- ### Properties
80
-
81
- * `type` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** 
82
- * `isKey` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** 
83
- * `writable` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** 
84
- * `mandatory` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** 
85
- * `private` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** should the value be shown
86
- * `depends` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** name of an attribute we depend on
87
- * `additionalAttributes` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>** extra attributes that are present in case our attribute is set
88
- * `description` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** human readable
89
- * `default` **any?** the default value
90
- * `set` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)?** set the value
91
- * `get` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)?** get the value can be used to calculate default values
92
- * `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
93
-
94
79
  ## tokens
95
80
 
96
81
  ## tokens
@@ -146,6 +131,48 @@ Generate filter function.
146
131
 
147
132
  Returns **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)**&#x20;
148
133
 
134
+ ## AttributeDefinition
135
+
136
+ Type: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)
137
+
138
+ ### Properties
139
+
140
+ * `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**&#x20;
141
+ * `type` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**&#x20;
142
+ * `isKey` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**&#x20;
143
+ * `writable` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**&#x20;
144
+ * `mandatory` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**&#x20;
145
+ * `private` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** should the value be shown
146
+ * `depends` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** name of an attribute we depend on
147
+ * `additionalAttributes` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>** extra attributes that are present in case our attribute is set
148
+ * `description` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** human readable
149
+ * `default` **any?** the default value
150
+ * `set` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)?** set the value
151
+ * `get` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)?** get the value can be used to calculate default values
152
+ * `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
153
+
154
+ ## setAttributes
155
+
156
+ Copies attribute values from a source object into a destination object.
157
+
158
+ ### Parameters
159
+
160
+ * `object` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** target object to be modified
161
+ * `source` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** origin of the data to be copied
162
+ * `definitions` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** attribute definitions to be used
163
+ * `cb` **[function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** callback to be executed for each copied value
164
+
165
+ ## getAttributes
166
+
167
+ Retrive attribute values from an object.
168
+
169
+ ### Parameters
170
+
171
+ * `object` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** attribute value source
172
+ * `definitions` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**&#x20;
173
+
174
+ Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** values
175
+
149
176
  ## lookup
150
177
 
151
178
  Token lookup
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pacc",
3
- "version": "3.5.0",
3
+ "version": "3.6.0",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": true
package/src/multiple.mjs CHANGED
@@ -18,6 +18,48 @@ import { setAttribute, getAttribute } from "./attribute.mjs";
18
18
  * @property {string[]|string} [env] environment variable(s) used to provide the value
19
19
  */
20
20
 
21
+ const types = {
22
+ base: { name: "base" },
23
+ string: { name: "string" },
24
+ number: { name: "number" },
25
+ boolean: { name: "boolean" }
26
+ };
27
+
28
+ /**
29
+ * Create attributes from its definition.
30
+ * @param {Object} definitions
31
+ * @return {Object} attributes
32
+ */
33
+ export function prepareAttributesDefinitions(definitions) {
34
+ for (const [name, d] of Object.entries(definitions)) {
35
+ d.name = name;
36
+ if (d.attributes === undefined) {
37
+ d.type = types[d.type] || types.base;
38
+ }
39
+ }
40
+ return definitions;
41
+ }
42
+
43
+ /**
44
+ * Merge attribute definitions.
45
+ * @param {Object} dest attribute definitions to be used also the merge target
46
+ * @param {Object} atts attribute definitions to be used
47
+ * @return {Object} merged definitions (dest)
48
+ */
49
+ export function mergeAttributeDefinitions(dest, atts) {
50
+ for (const [name, ca] of Object.entries(atts)) {
51
+ if (ca.attributes !== undefined) {
52
+ const bn = dest[name];
53
+
54
+ if (bn !== undefined) {
55
+ Object.assign(ca.attributes, bn.attributes);
56
+ }
57
+ }
58
+ }
59
+
60
+ return Object.assign(dest, atts);
61
+ }
62
+
21
63
  /**
22
64
  * Copies attribute values from a source object into a destination object.
23
65
  * @param {Object} object target object to be modified
@@ -1,20 +1,16 @@
1
1
  /**
2
- * @typedef {Object} AttributeDefinition
3
- *
4
- * @property {string} name
5
- * @property {string} type
6
- * @property {boolean} isKey
7
- * @property {boolean} writable
8
- * @property {boolean} mandatory
9
- * @property {boolean} [private] should the value be shown
10
- * @property {string} [depends] name of an attribute we depend on
11
- * @property {string[]} additionalAttributes extra attributes that are present in case our attribute is set
12
- * @property {string} [description] human readable
13
- * @property {any} [default] the default value
14
- * @property {Function} [set] set the value
15
- * @property {Function} [get] get the value can be used to calculate default values
16
- * @property {string[]|string} [env] environment variable(s) used to provide the value
2
+ * Create attributes from its definition.
3
+ * @param {Object} definitions
4
+ * @return {Object} attributes
5
+ */
6
+ export function prepareAttributesDefinitions(definitions: any): any;
7
+ /**
8
+ * Merge attribute definitions.
9
+ * @param {Object} dest attribute definitions to be used also the merge target
10
+ * @param {Object} atts attribute definitions to be used
11
+ * @return {Object} merged definitions (dest)
17
12
  */
13
+ export function mergeAttributeDefinitions(dest: any, atts: any): any;
18
14
  /**
19
15
  * Copies attribute values from a source object into a destination object.
20
16
  * @param {Object} object target object to be modified