pacc 3.4.8 → 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
@@ -103,7 +88,7 @@ Split property path into tokens
103
88
 
104
89
  ## setAttribute
105
90
 
106
- Set Object attribute.
91
+ Set object attribute.
107
92
  The name may be a property path like 'a.b.c'.
108
93
 
109
94
  ### Parameters
@@ -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,15 +1,15 @@
1
1
  {
2
2
  "name": "pacc",
3
- "version": "3.4.8",
3
+ "version": "3.6.0",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": true
7
7
  },
8
- "types": "./types/attribute.d.mts",
8
+ "types": "./types/module.d.mts",
9
9
  "exports": {
10
10
  ".": {
11
- "types": "./types/attribute.d.mts",
12
- "default": "./src/attribute.mjs"
11
+ "types": "./types/module.d.mts",
12
+ "default": "./src/module.mjs"
13
13
  }
14
14
  },
15
15
  "description": "property path utils",
@@ -36,15 +36,15 @@
36
36
  "npm-pkgbuild": "^18.1.1"
37
37
  },
38
38
  "devDependencies": {
39
- "ava": "^6.4.0",
39
+ "ava": "^6.4.1",
40
40
  "browser-ava": "^2.3.31",
41
41
  "c8": "^10.1.3",
42
42
  "documentation": "^14.0.3",
43
- "semantic-release": "^24.2.5",
43
+ "semantic-release": "^24.2.7",
44
44
  "typescript": "^5.8.3"
45
45
  },
46
46
  "engines": {
47
- "node": ">=22.16.0"
47
+ "node": ">=22.17.1"
48
48
  },
49
49
  "repository": {
50
50
  "type": "git",
package/src/attribute.mjs CHANGED
@@ -1,19 +1,3 @@
1
- /**
2
- * @typedef {Object} AttributeDefinition
3
- *
4
- * @property {string} type
5
- * @property {boolean} isKey
6
- * @property {boolean} writable
7
- * @property {boolean} mandatory
8
- * @property {boolean} [private] should the value be shown
9
- * @property {string} [depends] name of an attribute we depend on
10
- * @property {string[]} additionalAttributes extra attributes that are present in case our attribute is set
11
- * @property {string} [description] human readable
12
- * @property {any} [default] the default value
13
- * @property {Function} [set] set the value
14
- * @property {Function} [get] get the value can be used to calculate default values
15
- * @property {string[]|string} [env] environment variable(s) used to provide the value
16
- */
17
1
 
18
2
  /**
19
3
  * @typedef {import('./tokens.mjs').Token} Token
@@ -32,11 +16,9 @@ import {
32
16
  GREATER_EQUAL,
33
17
  STAR
34
18
  } from "./tokens.mjs";
35
- export * from "./tokens.mjs";
36
- export * from "./filter.mjs";
37
19
 
38
20
  /**
39
- * Set Object attribute.
21
+ * Set object attribute.
40
22
  * The name may be a property path like 'a.b.c'.
41
23
  * @param {Object} object
42
24
  * @param {string} expression
package/src/module.mjs ADDED
@@ -0,0 +1,8 @@
1
+ export * from "./tokens.mjs";
2
+ export * from "./filter.mjs";
3
+ export * from "./multiple.mjs";
4
+ export {
5
+ setAttribute,
6
+ getAttribute,
7
+ getAttributeAndOperator
8
+ } from "./attribute.mjs";
@@ -0,0 +1,97 @@
1
+ import { setAttribute, getAttribute } from "./attribute.mjs";
2
+
3
+ /**
4
+ * @typedef {Object} AttributeDefinition
5
+ *
6
+ * @property {string} name
7
+ * @property {string} type
8
+ * @property {boolean} isKey
9
+ * @property {boolean} writable
10
+ * @property {boolean} mandatory
11
+ * @property {boolean} [private] should the value be shown
12
+ * @property {string} [depends] name of an attribute we depend on
13
+ * @property {string[]} additionalAttributes extra attributes that are present in case our attribute is set
14
+ * @property {string} [description] human readable
15
+ * @property {any} [default] the default value
16
+ * @property {Function} [set] set the value
17
+ * @property {Function} [get] get the value can be used to calculate default values
18
+ * @property {string[]|string} [env] environment variable(s) used to provide the value
19
+ */
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
+
63
+ /**
64
+ * Copies attribute values from a source object into a destination object.
65
+ * @param {Object} object target object to be modified
66
+ * @param {Object} source origin of the data to be copied
67
+ * @param {Object} definitions attribute definitions to be used
68
+ * @param {function} cb callback to be executed for each copied value
69
+ */
70
+ export function setAttributes(object, source, definitions, cb) {
71
+ for (const [name, def] of Object.entries(definitions)) {
72
+ const value = getAttribute(source, name);
73
+ setAttribute(object, name, value);
74
+ if (cb) {
75
+ cb(def, name, value);
76
+ }
77
+ }
78
+ }
79
+
80
+ /**
81
+ * Retrive attribute values from an object.
82
+ * @param {Object} object attribute value source
83
+ * @param {Object} definitions
84
+ * @return {Object} values
85
+ */
86
+ export function getAttributes(object, definitions) {
87
+ const result = {};
88
+
89
+ Object.keys(definitions).forEach(name => {
90
+ const value = getAttribute(object, name);
91
+ if (value !== undefined) {
92
+ result[name] = value;
93
+ }
94
+ });
95
+
96
+ return result;
97
+ }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Set Object attribute.
2
+ * Set object attribute.
3
3
  * The name may be a property path like 'a.b.c'.
4
4
  * @param {Object} object
5
5
  * @param {string} expression
@@ -22,44 +22,4 @@ export function getAttribute(object: any, expression: string): any;
22
22
  * @returns {[any,Token]} value associated with the given property name
23
23
  */
24
24
  export function getAttributeAndOperator(object: any, expression: string): [any, Token];
25
- export * from "./tokens.mjs";
26
- export * from "./filter.mjs";
27
- export type AttributeDefinition = {
28
- type: string;
29
- isKey: boolean;
30
- writable: boolean;
31
- mandatory: boolean;
32
- /**
33
- * should the value be shown
34
- */
35
- private?: boolean;
36
- /**
37
- * name of an attribute we depend on
38
- */
39
- depends?: string;
40
- /**
41
- * extra attributes that are present in case our attribute is set
42
- */
43
- additionalAttributes: string[];
44
- /**
45
- * human readable
46
- */
47
- description?: string;
48
- /**
49
- * the default value
50
- */
51
- default?: any;
52
- /**
53
- * set the value
54
- */
55
- set?: Function;
56
- /**
57
- * get the value can be used to calculate default values
58
- */
59
- get?: Function;
60
- /**
61
- * environment variable(s) used to provide the value
62
- */
63
- env?: string[] | string;
64
- };
65
25
  export type Token = import("./tokens.mjs").Token;
@@ -0,0 +1,4 @@
1
+ export * from "./tokens.mjs";
2
+ export * from "./filter.mjs";
3
+ export * from "./multiple.mjs";
4
+ export { setAttribute, getAttribute, getAttributeAndOperator } from "./attribute.mjs";
@@ -0,0 +1,67 @@
1
+ /**
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)
12
+ */
13
+ export function mergeAttributeDefinitions(dest: any, atts: any): any;
14
+ /**
15
+ * Copies attribute values from a source object into a destination object.
16
+ * @param {Object} object target object to be modified
17
+ * @param {Object} source origin of the data to be copied
18
+ * @param {Object} definitions attribute definitions to be used
19
+ * @param {function} cb callback to be executed for each copied value
20
+ */
21
+ export function setAttributes(object: any, source: any, definitions: any, cb: Function): void;
22
+ /**
23
+ * Retrive attribute values from an object.
24
+ * @param {Object} object attribute value source
25
+ * @param {Object} definitions
26
+ * @return {Object} values
27
+ */
28
+ export function getAttributes(object: any, definitions: any): any;
29
+ export type AttributeDefinition = {
30
+ name: string;
31
+ type: string;
32
+ isKey: boolean;
33
+ writable: boolean;
34
+ mandatory: boolean;
35
+ /**
36
+ * should the value be shown
37
+ */
38
+ private?: boolean;
39
+ /**
40
+ * name of an attribute we depend on
41
+ */
42
+ depends?: string;
43
+ /**
44
+ * extra attributes that are present in case our attribute is set
45
+ */
46
+ additionalAttributes: string[];
47
+ /**
48
+ * human readable
49
+ */
50
+ description?: string;
51
+ /**
52
+ * the default value
53
+ */
54
+ default?: any;
55
+ /**
56
+ * set the value
57
+ */
58
+ set?: Function;
59
+ /**
60
+ * get the value can be used to calculate default values
61
+ */
62
+ get?: Function;
63
+ /**
64
+ * environment variable(s) used to provide the value
65
+ */
66
+ env?: string[] | string;
67
+ };