pacc 6.9.1 → 7.0.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
@@ -51,12 +51,13 @@ const result = getAttribute({ a: [0,{ b: 4 }]}, "a[1].b");
51
51
  * [version\_attribute\_writable](#version_attribute_writable)
52
52
  * [description\_attribute](#description_attribute)
53
53
  * [boolean\_attribute](#boolean_attribute)
54
+ * [boolean\_attribute](#boolean_attribute-1)
54
55
  * [boolean\_attribute\_writable](#boolean_attribute_writable)
55
56
  * [boolean\_attribute\_writable\_true](#boolean_attribute_writable_true)
56
57
  * [boolean\_attribute\_writable\_true](#boolean_attribute_writable_true-1)
57
58
  * [boolean\_attribute\_writable\_false](#boolean_attribute_writable_false)
58
59
  * [boolean\_attribute\_false](#boolean_attribute_false)
59
- * [empty\_attribute](#empty_attribute)
60
+ * [yesno\_attribute](#yesno_attribute)
60
61
  * [uuid\_attribute](#uuid_attribute)
61
62
  * [secret\_attribute](#secret_attribute)
62
63
  * [secret\_attribute](#secret_attribute-1)
@@ -90,34 +91,38 @@ const result = getAttribute({ a: [0,{ b: 4 }]}, "a[1].b");
90
91
  * [expand](#expand)
91
92
  * [Parameters](#parameters-5)
92
93
  * [promises](#promises)
93
- * [filter](#filter)
94
+ * [error](#error)
94
95
  * [Parameters](#parameters-6)
95
- * [setAttributes](#setattributes)
96
+ * [binopError](#binoperror)
96
97
  * [Parameters](#parameters-7)
97
- * [getAttributes](#getattributes)
98
+ * [filter](#filter)
98
99
  * [Parameters](#parameters-8)
99
- * [getAttributesJSON](#getattributesjson)
100
+ * [setAttributes](#setattributes)
100
101
  * [Parameters](#parameters-9)
102
+ * [getAttributes](#getattributes)
103
+ * [Parameters](#parameters-10)
104
+ * [getAttributesJSON](#getattributesjson)
105
+ * [Parameters](#parameters-11)
101
106
  * [tokens](#tokens)
102
107
  * [tokens](#tokens-1)
103
- * [Parameters](#parameters-10)
108
+ * [Parameters](#parameters-12)
104
109
  * [setAttribute](#setattribute)
105
- * [Parameters](#parameters-11)
110
+ * [Parameters](#parameters-13)
106
111
  * [getAttribute](#getattribute)
107
- * [Parameters](#parameters-12)
112
+ * [Parameters](#parameters-14)
108
113
  * [getAttributeAndOperator](#getattributeandoperator)
109
- * [Parameters](#parameters-13)
114
+ * [Parameters](#parameters-15)
110
115
  * [parseDuration](#parseduration)
111
- * [Parameters](#parameters-14)
116
+ * [Parameters](#parameters-16)
112
117
  * [formatDuration](#formatduration)
113
- * [Parameters](#parameters-15)
118
+ * [Parameters](#parameters-17)
114
119
  * [formatDurationISO](#formatdurationiso)
115
- * [Parameters](#parameters-16)
120
+ * [Parameters](#parameters-18)
116
121
  * [lookup](#lookup)
117
122
  * [Token](#token)
118
123
  * [Properties](#properties-1)
119
124
  * [createToken](#createtoken)
120
- * [Parameters](#parameters-17)
125
+ * [Parameters](#parameters-19)
121
126
  * [PLUS](#plus)
122
127
  * [MINUS](#minus)
123
128
  * [STAR](#star)
@@ -149,7 +154,7 @@ const result = getAttribute({ a: [0,{ b: 4 }]}, "a[1].b");
149
154
  * [Type](#type)
150
155
  * [Properties](#properties-2)
151
156
  * [raiseOnUnknownType](#raiseonunknowntype)
152
- * [Parameters](#parameters-18)
157
+ * [Parameters](#parameters-20)
153
158
 
154
159
  ## prepareAttributesDefinitions
155
160
 
@@ -214,7 +219,8 @@ Type: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Globa
214
219
  * `default` **any?** the default value
215
220
  * `set` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)?** set the value
216
221
  * `get` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)?** get the value can be used to calculate default values
217
- * `prepareValue` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)?** 
222
+ * `toInternal` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)?** 
223
+ * `toExternal` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)?** 
218
224
  * `values` **[Set](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Set)\<any>?** allowed values
219
225
  * `externalName` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** attribute name used by external system
220
226
  * `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
@@ -286,6 +292,10 @@ Type: [AttributeDefinition](#attributedefinition)
286
292
 
287
293
  Type: [AttributeDefinition](#attributedefinition)
288
294
 
295
+ ## boolean\_attribute
296
+
297
+ Type: [AttributeDefinition](#attributedefinition)
298
+
289
299
  ## boolean\_attribute\_writable
290
300
 
291
301
  Type: [AttributeDefinition](#attributedefinition)
@@ -306,7 +316,7 @@ Type: [AttributeDefinition](#attributedefinition)
306
316
 
307
317
  Type: [AttributeDefinition](#attributedefinition)
308
318
 
309
- ## empty\_attribute
319
+ ## yesno\_attribute
310
320
 
311
321
  Type: [AttributeDefinition](#attributedefinition)
312
322
 
@@ -461,6 +471,20 @@ Returns **any**&#x20;
461
471
 
462
472
  Type: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<any>>
463
473
 
474
+ ## error
475
+
476
+ ### Parameters
477
+
478
+ * `message` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**&#x20;
479
+
480
+ ## binopError
481
+
482
+ ### Parameters
483
+
484
+ * `op` **[Token](#token)**&#x20;
485
+ * `left` **AST**&#x20;
486
+ * `right` **AST**&#x20;
487
+
464
488
  ## filter
465
489
 
466
490
  Generate filter function.
@@ -720,7 +744,7 @@ Type: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Globa
720
744
 
721
745
  * `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**&#x20;
722
746
  * `primitive` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?**&#x20;
723
- * `prepareValue` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)?**&#x20;
747
+ * `toInternal` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)?**&#x20;
724
748
 
725
749
  ## raiseOnUnknownType
726
750
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pacc",
3
- "version": "6.9.1",
3
+ "version": "7.0.1",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": true
@@ -70,11 +70,23 @@ export function* writableAttributeIterator(definition) {
70
70
  yield* attributeIterator(definition, filterWritable);
71
71
  }
72
72
 
73
- export function prepareValue(value, attribute) {
73
+ export function toInternal(value, attribute) {
74
74
  if (attribute) {
75
- const prepareValue = attribute.prepareValue ?? attribute.type?.prepareValue;
76
- if (prepareValue) {
77
- return prepareValue(value, attribute);
75
+ const toInternal = attribute.toInternal ?? attribute.type?.toInternal;
76
+ if (toInternal) {
77
+ return toInternal(value, attribute);
78
+ }
79
+ }
80
+ return value;
81
+ }
82
+
83
+ export { toInternal as prepareValue }; // DEPRECATED
84
+
85
+ export function toExternal(value, attribute) {
86
+ if (attribute) {
87
+ const toExternal = attribute.toExternal ?? attribute.type?.toExternal;
88
+ if (toExternal) {
89
+ return toExternal(value, attribute);
78
90
  }
79
91
  }
80
92
  return value;
@@ -16,7 +16,8 @@ import { types } from "./types.mjs";
16
16
  * @property {any} [default] the default value
17
17
  * @property {Function} [set] set the value
18
18
  * @property {Function} [get] get the value can be used to calculate default values
19
- * @property {Function} [prepareValue]
19
+ * @property {Function} [toInternal]
20
+ * @property {Function} [toExternal]
20
21
  * @property {Set<any>} [values] allowed values
21
22
  * @property {string} [externalName] attribute name used by external system
22
23
  * @property {string[]|string} [env] environment variable(s) used to provide the value
@@ -178,11 +179,21 @@ export { boolean_attribute_writable_true as active_attribute };
178
179
  /**
179
180
  * @type {AttributeDefinition}
180
181
  */
181
- export const empty_attribute = {
182
- ...default_attribute,
183
- type: types.boolean
182
+ export const yesno_attribute = {
183
+ ...boolean_attribute,
184
+ type: types.yesno
185
+ };
186
+
187
+ export const yesno_attribute_writable = {
188
+ ...yesno_attribute,
189
+ writable: true
184
190
  };
185
191
 
192
+ /**
193
+ * @type {AttributeDefinition}
194
+ */
195
+ export { boolean_attribute as empty_attribute };
196
+
186
197
  /**
187
198
  * @type {AttributeDefinition}
188
199
  */
package/src/multiple.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { setAttribute, getAttribute } from "./settergetter.mjs";
2
- import { attributeIterator } from "./attributes.mjs";
3
-
2
+ import { attributeIterator, toExternal } from "./attributes.mjs";
3
+ import { default_attribute } from "./common-attributes.mjs";
4
4
  /**
5
5
  * Copies attribute values from a source object into a destination object.
6
6
  * @param {Object} object target object to be modified
@@ -71,10 +71,11 @@ export function getAttributesJSON(object, definitions, filter) {
71
71
 
72
72
  let value = getAttribute(object, name, def);
73
73
  if (value !== undefined) {
74
+ value = toExternal(value);
74
75
  if (value instanceof Set) {
75
76
  value = [...value];
76
77
  }
77
- setAttribute(result, def.externalName ?? name, value, def);
78
+ setAttribute(result, def.externalName ?? name, value, default_attribute);
78
79
  }
79
80
  }
80
81
  return result;
@@ -1,6 +1,6 @@
1
1
  import { attributeIterator } from "./attributes.mjs";
2
2
  import { getAttribute, setAttribute } from "./settergetter.mjs";
3
- import { prepareValue } from "./attributes.mjs";
3
+ import { toInternal } from "./attributes.mjs";
4
4
 
5
5
  function findPropertyDescriptor(obj, name) {
6
6
  let descriptor;
@@ -29,7 +29,7 @@ export function definePropertiesFromAttributes(
29
29
  attribute.default;
30
30
 
31
31
  if (value !== undefined) {
32
- value = prepareValue(value, attribute);
32
+ value = toInternal(value, attribute);
33
33
 
34
34
  if (path.length === 1) {
35
35
  const property = properties[name];
@@ -17,7 +17,7 @@ import {
17
17
  IDENTIFIER
18
18
  } from "./tokens.mjs";
19
19
  import { parse } from "./expression.mjs";
20
- import { prepareValue } from "./attributes.mjs";
20
+ import { toInternal } from "./attributes.mjs";
21
21
 
22
22
  /**
23
23
  * Set object attribute.
@@ -49,7 +49,7 @@ export function setAttribute(object, expression, value, definition) {
49
49
  }
50
50
 
51
51
  if (anchor) {
52
- anchor[anchorKey] = prepareValue(value, definition);
52
+ anchor[anchorKey] = toInternal(value, definition);
53
53
  }
54
54
  }
55
55
 
package/src/types.mjs CHANGED
@@ -6,7 +6,7 @@ import { parseBytes } from "./bytes.mjs";
6
6
  * @typedef {Object} Type
7
7
  * @property {string} name
8
8
  * @property {boolean} [primitive]
9
- * @property {Function} [prepareValue]
9
+ * @property {Function} [toInternal]
10
10
  */
11
11
 
12
12
  const emptyStringIsUndefined = value =>
@@ -17,45 +17,54 @@ export const types = {
17
17
  number: {
18
18
  name: "number",
19
19
  primitive: true,
20
- prepareValue: value =>
20
+ toInternal: value =>
21
21
  typeof value === "string" ? parseFloat(value) : value
22
22
  },
23
23
  boolean: {
24
24
  name: "boolean",
25
25
  primitive: true,
26
- prepareValue: value =>
26
+ toInternal: value =>
27
27
  !value || value === "0" || value === "false" || value === "no"
28
28
  ? false
29
29
  : true
30
30
  },
31
+ yesno: {
32
+ name: "yesno",
33
+ primitive: true,
34
+ toInternal: value =>
35
+ !value || value === "0" || value === "false" || value === "no"
36
+ ? false
37
+ : true,
38
+ toExternal: value => value ? "yes" : "no"
39
+ },
31
40
  integer: {
32
41
  name: "integer",
33
42
  primitive: true,
34
- prepareValue: value => (typeof value === "string" ? parseInt(value) : value)
43
+ toInternal: value => (typeof value === "string" ? parseInt(value) : value)
35
44
  },
36
45
  "unsigned-integer": {
37
46
  name: "unsigned-integer",
38
47
  primitive: true,
39
- prepareValue: value => (typeof value === "string" ? parseInt(value) : value)
48
+ toInternal: value => (typeof value === "string" ? parseInt(value) : value)
40
49
  },
41
50
  duration: {
42
51
  name: "duration",
43
52
  primitive: true,
44
- prepareValue: value => parseDuration(value)
53
+ toInternal: value => parseDuration(value)
45
54
  },
46
55
  duration_ms: {
47
56
  name: "duration_ms",
48
57
  primitive: true,
49
- prepareValue: value => parseDuration(value) * 1000
58
+ toInternal: value => parseDuration(value) * 1000
50
59
  },
51
60
  byte_size: {
52
61
  name: "byte_size",
53
62
  primitive: true,
54
- prepareValue: parseBytes
63
+ toInternal: parseBytes
55
64
  },
56
65
  url: {
57
66
  name: "url",
58
- prepareValue: emptyStringIsUndefined,
67
+ toInternal: emptyStringIsUndefined,
59
68
  primitive: true
60
69
  },
61
70
  object: { name: "object", primitive: false }
@@ -14,6 +14,8 @@ export function prepareAttributesDefinitions(newDefinitions: any, presentDefinit
14
14
  */
15
15
  export function attributeIterator(definition: any, filter?: Function, path?: string[]): Iterable<[string[], object]>;
16
16
  export function writableAttributeIterator(definition: any): Generator<[string[], any], void, any>;
17
- export function prepareValue(value: any, attribute: any): any;
17
+ export function toInternal(value: any, attribute: any): any;
18
+ export function toExternal(value: any, attribute: any): any;
18
19
  export function mandatoryAttributesPresent(object: any, attributes: any): boolean;
19
20
  export function filterWritable(name: any, attribute: any): any;
21
+ export { toInternal as prepareValue };
@@ -14,7 +14,8 @@
14
14
  * @property {any} [default] the default value
15
15
  * @property {Function} [set] set the value
16
16
  * @property {Function} [get] get the value can be used to calculate default values
17
- * @property {Function} [prepareValue]
17
+ * @property {Function} [toInternal]
18
+ * @property {Function} [toExternal]
18
19
  * @property {Set<any>} [values] allowed values
19
20
  * @property {string} [externalName] attribute name used by external system
20
21
  * @property {string[]|string} [env] environment variable(s) used to provide the value
@@ -45,7 +46,8 @@ export namespace string_collection_attribute {
45
46
  export { _default as default };
46
47
  export let set: Function;
47
48
  export let get: Function;
48
- export let prepareValue: Function;
49
+ export let toInternal: Function;
50
+ export let toExternal: Function;
49
51
  export let values: Set<any>;
50
52
  export let externalName: string;
51
53
  export let env: string[] | string;
@@ -103,7 +105,13 @@ export const boolean_attribute_false: AttributeDefinition;
103
105
  /**
104
106
  * @type {AttributeDefinition}
105
107
  */
106
- export const empty_attribute: AttributeDefinition;
108
+ export const yesno_attribute: AttributeDefinition;
109
+ export namespace yesno_attribute_writable {
110
+ let writable_1: boolean;
111
+ export { writable_1 as writable };
112
+ let collection_1: boolean;
113
+ export { collection_1 as collection };
114
+ }
107
115
  /**
108
116
  * @type {AttributeDefinition}
109
117
  */
@@ -140,11 +148,9 @@ export namespace bytes_size_attribute {
140
148
  let type_1: {
141
149
  name: string;
142
150
  primitive: boolean;
143
- prepareValue: typeof import("./bytes.mjs").parseBytes;
151
+ toInternal: typeof import("./bytes.mjs").parseBytes;
144
152
  };
145
153
  export { type_1 as type };
146
- let collection_1: boolean;
147
- export { collection_1 as collection };
148
154
  }
149
155
  /**
150
156
  * @type {AttributeDefinition}
@@ -240,7 +246,8 @@ export type AttributeDefinition = {
240
246
  * get the value can be used to calculate default values
241
247
  */
242
248
  get?: Function;
243
- prepareValue?: Function;
249
+ toInternal?: Function;
250
+ toExternal?: Function;
244
251
  /**
245
252
  * allowed values
246
253
  */
@@ -258,4 +265,4 @@ export type AttributeDefinition = {
258
265
  */
259
266
  additionalValues?: object;
260
267
  };
261
- export { default_attribute as string_attribute, default_attribute_writable as string_attribute_writable, description_attribute as description_attribute_writable, default_attribute as type_attribute, default_attribute_writable as state_attribute_writable, boolean_attribute_writable_true as active_attribute, secret_attribute as username_attribute, secret_attribute as password_attribute, secret_attribute as token_attribute, secret_attribute as certificate_attribute, integer_attribute as count_attribute, integer_attribute_writable as count_attribute_writable, integer_attribute as size_attribute, default_attribute_writable as body_attribute_writable };
268
+ export { default_attribute as string_attribute, default_attribute_writable as string_attribute_writable, description_attribute as description_attribute_writable, default_attribute as type_attribute, default_attribute_writable as state_attribute_writable, boolean_attribute_writable_true as active_attribute, boolean_attribute as empty_attribute, secret_attribute as username_attribute, secret_attribute as password_attribute, secret_attribute as token_attribute, secret_attribute as certificate_attribute, integer_attribute as count_attribute, integer_attribute_writable as count_attribute_writable, integer_attribute as size_attribute, default_attribute_writable as body_attribute_writable };
package/types/types.d.mts CHANGED
@@ -10,41 +10,47 @@ export const types: {
10
10
  number: {
11
11
  name: string;
12
12
  primitive: boolean;
13
- prepareValue: (value: any) => any;
13
+ toInternal: (value: any) => any;
14
14
  };
15
15
  boolean: {
16
16
  name: string;
17
17
  primitive: boolean;
18
- prepareValue: (value: any) => boolean;
18
+ toInternal: (value: any) => boolean;
19
+ };
20
+ yesno: {
21
+ name: string;
22
+ primitive: boolean;
23
+ toInternal: (value: any) => boolean;
24
+ toExternal: (value: any) => "no" | "yes";
19
25
  };
20
26
  integer: {
21
27
  name: string;
22
28
  primitive: boolean;
23
- prepareValue: (value: any) => any;
29
+ toInternal: (value: any) => any;
24
30
  };
25
31
  "unsigned-integer": {
26
32
  name: string;
27
33
  primitive: boolean;
28
- prepareValue: (value: any) => any;
34
+ toInternal: (value: any) => any;
29
35
  };
30
36
  duration: {
31
37
  name: string;
32
38
  primitive: boolean;
33
- prepareValue: (value: any) => number;
39
+ toInternal: (value: any) => number;
34
40
  };
35
41
  duration_ms: {
36
42
  name: string;
37
43
  primitive: boolean;
38
- prepareValue: (value: any) => number;
44
+ toInternal: (value: any) => number;
39
45
  };
40
46
  byte_size: {
41
47
  name: string;
42
48
  primitive: boolean;
43
- prepareValue: typeof parseBytes;
49
+ toInternal: typeof parseBytes;
44
50
  };
45
51
  url: {
46
52
  name: string;
47
- prepareValue: (value: any) => any;
53
+ toInternal: (value: any) => any;
48
54
  primitive: boolean;
49
55
  };
50
56
  object: {
@@ -55,6 +61,6 @@ export const types: {
55
61
  export type Type = {
56
62
  name: string;
57
63
  primitive?: boolean;
58
- prepareValue?: Function;
64
+ toInternal?: Function;
59
65
  };
60
66
  import { parseBytes } from "./bytes.mjs";