pacc 4.27.1 → 4.28.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 +1 -1
- package/src/attributes.mjs +28 -18
- package/types/attributes.d.mts +9 -5
package/package.json
CHANGED
package/src/attributes.mjs
CHANGED
|
@@ -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:
|
|
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:
|
|
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
|
|
25
|
-
|
|
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
|
-
*
|
|
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
|
-
|
|
87
|
+
if (!filter || filter(name, def)) {
|
|
88
|
+
const path2 = [...path, name];
|
|
82
89
|
|
|
83
|
-
|
|
84
|
-
yield* attributeIterator(def.attributes, path);
|
|
85
|
-
}
|
|
90
|
+
yield [path2, def];
|
|
86
91
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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);
|
package/types/attributes.d.mts
CHANGED
|
@@ -6,11 +6,14 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export function prepareAttributesDefinitions(newDefinitions: any, presentDefinitions?: any): any;
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
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[]):
|
|
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
|
|
30
|
+
prepareValue: (value: any) => any;
|
|
28
31
|
};
|
|
29
32
|
boolean: {
|
|
30
33
|
name: string;
|
|
31
34
|
extends: string;
|
|
32
|
-
prepareValue: (value: any
|
|
35
|
+
prepareValue: (value: any) => boolean;
|
|
33
36
|
};
|
|
34
37
|
integer: {
|
|
35
38
|
name: string;
|
|
36
39
|
extends: string;
|
|
37
|
-
prepareValue: (value: 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: {
|