pacc 4.27.0 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pacc",
3
- "version": "4.27.0",
3
+ "version": "4.28.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);
@@ -293,5 +293,6 @@ export function parse(input, context = { globals }) {
293
293
  export const globals = {
294
294
  min: (a, b) => (a < b ? a : b),
295
295
  max: (a, b) => (a > b ? a : b),
296
- substring: (s,a,b) => s.substring(a,b)
296
+ substring: (s, a, b) => s.substring(a, b),
297
+ length: s => s.length
297
298
  };
@@ -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: {
@@ -4,10 +4,12 @@ export function parse(input: any, context?: {
4
4
  min: (a: any, b: any) => any;
5
5
  max: (a: any, b: any) => any;
6
6
  substring: (s: any, a: any, b: any) => any;
7
+ length: (s: any) => any;
7
8
  };
8
9
  }): any;
9
10
  export namespace globals {
10
11
  function min(a: any, b: any): any;
11
12
  function max(a: any, b: any): any;
12
13
  function substring(s: any, a: any, b: any): any;
14
+ function length(s: any): any;
13
15
  }