pacc 3.5.0 → 3.6.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 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,21 @@ 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
+ * [prepareAttributesDefinitions](#prepareattributesdefinitions)
44
+ * [Parameters](#parameters-5)
45
+ * [mergeAttributeDefinitions](#mergeattributedefinitions)
46
+ * [Parameters](#parameters-6)
47
+ * [setAttributes](#setattributes)
48
+ * [Parameters](#parameters-7)
49
+ * [getAttributes](#getattributes)
50
+ * [Parameters](#parameters-8)
43
51
  * [lookup](#lookup)
44
52
  * [Token](#token)
45
53
  * [Properties](#properties-1)
46
54
  * [createToken](#createtoken)
47
- * [Parameters](#parameters-5)
55
+ * [Parameters](#parameters-9)
48
56
  * [PLUS](#plus)
49
57
  * [MINUS](#minus)
50
58
  * [STAR](#star)
@@ -72,25 +80,6 @@ const result = getAttribute({ a: [0,{ b: 4 }]}, "a[1].b");
72
80
  * [BAR](#bar)
73
81
  * [DOUBLE\_BAR](#double_bar)
74
82
 
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
83
  ## tokens
95
84
 
96
85
  ## tokens
@@ -146,6 +135,69 @@ Generate filter function.
146
135
 
147
136
  Returns **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)**&#x20;
148
137
 
138
+ ## AttributeDefinition
139
+
140
+ Type: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)
141
+
142
+ ### Properties
143
+
144
+ * `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**&#x20;
145
+ * `type` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**&#x20;
146
+ * `isKey` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**&#x20;
147
+ * `writable` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**&#x20;
148
+ * `mandatory` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**&#x20;
149
+ * `private` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** should the value be shown
150
+ * `depends` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** name of an attribute we depend on
151
+ * `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
152
+ * `description` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** human readable
153
+ * `default` **any?** the default value
154
+ * `set` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)?** set the value
155
+ * `get` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)?** get the value can be used to calculate default values
156
+ * `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
157
+
158
+ ## prepareAttributesDefinitions
159
+
160
+ Create attributes from its definition.
161
+
162
+ ### Parameters
163
+
164
+ * `definitions` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**&#x20;
165
+
166
+ Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** attributes
167
+
168
+ ## mergeAttributeDefinitions
169
+
170
+ Merge attribute definitions.
171
+
172
+ ### Parameters
173
+
174
+ * `dest` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** attribute definitions to be used also the merge target
175
+ * `atts` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** attribute definitions to be used
176
+
177
+ Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** merged definitions (dest)
178
+
179
+ ## setAttributes
180
+
181
+ Copies attribute values from a source object into a destination object.
182
+
183
+ ### Parameters
184
+
185
+ * `object` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** target object to be modified
186
+ * `source` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** origin of the data to be copied
187
+ * `definitions` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** attribute definitions to be used
188
+ * `cb` **[function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** callback to be executed for each copied value
189
+
190
+ ## getAttributes
191
+
192
+ Retrive attribute values from an object.
193
+
194
+ ### Parameters
195
+
196
+ * `object` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** attribute value source
197
+ * `definitions` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**&#x20;
198
+
199
+ Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** values
200
+
149
201
  ## lookup
150
202
 
151
203
  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.1",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": true
package/src/multiple.mjs CHANGED
@@ -18,12 +18,56 @@ 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
+ integer: { name: "integer" },
26
+ boolean: { name: "boolean" },
27
+ object: { name: "object" }
28
+ };
29
+
30
+ /**
31
+ * Create attributes from its definition.
32
+ * @param {Object} definitions
33
+ * @return {Object} attributes
34
+ */
35
+ export function prepareAttributesDefinitions(definitions) {
36
+ for (const [name, d] of Object.entries(definitions)) {
37
+ d.name = name;
38
+ if (d.attributes === undefined) {
39
+ d.type = types[d.type] || types.base;
40
+ }
41
+ }
42
+ return definitions;
43
+ }
44
+
45
+ /**
46
+ * Merge attribute definitions.
47
+ * @param {Object} dest attribute definitions to be used also the merge target
48
+ * @param {Object} atts attribute definitions to be used
49
+ * @return {Object} merged definitions (dest)
50
+ */
51
+ export function mergeAttributeDefinitions(dest, atts) {
52
+ for (const [name, ca] of Object.entries(atts)) {
53
+ if (ca.attributes !== undefined) {
54
+ const bn = dest[name];
55
+
56
+ if (bn !== undefined) {
57
+ Object.assign(ca.attributes, bn.attributes);
58
+ }
59
+ }
60
+ }
61
+
62
+ return Object.assign(dest, atts);
63
+ }
64
+
21
65
  /**
22
66
  * Copies attribute values from a source object into a destination object.
23
67
  * @param {Object} object target object to be modified
24
68
  * @param {Object} source origin of the data to be copied
25
69
  * @param {Object} definitions attribute definitions to be used
26
- * @param {function} cb callback to be executed for each copied value
70
+ * @param {function?} cb callback to be executed for each copied value
27
71
  */
28
72
  export function setAttributes(object, source, definitions, cb) {
29
73
  for (const [name, def] of Object.entries(definitions)) {
@@ -1,28 +1,24 @@
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
21
17
  * @param {Object} source origin of the data to be copied
22
18
  * @param {Object} definitions attribute definitions to be used
23
- * @param {function} cb callback to be executed for each copied value
19
+ * @param {function?} cb callback to be executed for each copied value
24
20
  */
25
- export function setAttributes(object: any, source: any, definitions: any, cb: Function): void;
21
+ export function setAttributes(object: any, source: any, definitions: any, cb: Function | null): void;
26
22
  /**
27
23
  * Retrive attribute values from an object.
28
24
  * @param {Object} object attribute value source