pacc 4.37.0 → 4.37.2

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.37.0",
3
+ "version": "4.37.2",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": true
@@ -115,7 +115,7 @@ export { default_attribute as type_attribute };
115
115
  /**
116
116
  * @type {AttributeDefinition}
117
117
  */
118
- export { default_attribute_writable as state_attribute };
118
+ export { default_attribute_writable as state_attribute_writable };
119
119
 
120
120
  /**
121
121
  * @type {AttributeDefinition}
@@ -312,13 +312,13 @@ export const id_attribute = {
312
312
  * The body text.
313
313
  * @type {AttributeDefinition}
314
314
  */
315
- export { default_attribute_writable as body_attribute };
315
+ export { default_attribute_writable as body_attribute_writable };
316
316
 
317
317
  /**
318
318
  * The one line description.
319
319
  * @type {AttributeDefinition}
320
320
  */
321
- export const title_attribute = {
321
+ export const title_attribute_writable = {
322
322
  ...default_attribute,
323
323
  description: "human readable title",
324
324
  writable: true
package/src/types.mjs CHANGED
@@ -1,3 +1,5 @@
1
+ import { attributeIterator } from "./attributes.mjs";
2
+
1
3
  export const types = {
2
4
  string: { name: "string", primitive: true },
3
5
  number: {
@@ -28,40 +30,61 @@ export const types = {
28
30
  object: { name: "object", extends: "base" }
29
31
  };
30
32
 
33
+ function error(message) {
34
+ throw new Error(message);
35
+ }
36
+
31
37
  export function addType(type) {
38
+ if (types[type.name]) {
39
+ return Object.assign(types[type.name], type);
40
+ }
41
+
32
42
  types[type.name] = type;
43
+
44
+ for (const [path, attribute] of attributeIterator(type.attributes)) {
45
+ if (typeof attribute.type === "string") {
46
+ attribute.type = oneOfType(attribute.type);
47
+ }
48
+ if(attribute.isKey && !type.key) {
49
+ type.key = path.join('.');
50
+ }
51
+ }
52
+
33
53
  return type;
34
54
  }
35
55
 
36
56
  export function oneOfType(definition) {
37
- const aggregate = list =>
38
- list.reduce(
39
- (a, c) => a.union(c?.members ?? new Set([types[c] ?? c])),
40
- new Set()
41
- );
57
+ const aggregate = (name, list) => {
58
+ const def = {
59
+ name,
60
+ members: list.reduce((all, type) => {
61
+ if (typeof type === "string") {
62
+ const t = types[type] || addType({ name: type });
63
+ if (!t) {
64
+ error(`Unknown type ${type} in '${definition}'`);
65
+ }
66
+ type = t;
67
+ }
68
+ return all.union(type.members ?? new Set([type]));
69
+ }, new Set())
70
+ };
42
71
 
43
- if (Array.isArray(definition)) {
44
- const name = definition
45
- .map(t => t.name ?? t)
46
- .sort()
47
- .join("|");
72
+ if (def.members.size < 2) {
73
+ delete def.members;
74
+ }
75
+ return types[name] || addType(def);
76
+ };
48
77
 
49
- return (
50
- types[name] ||
51
- addType({
52
- name,
53
- members: aggregate(definition)
54
- })
78
+ if (Array.isArray(definition)) {
79
+ return aggregate(
80
+ definition
81
+ .map(t => t.name ?? t)
82
+ .sort()
83
+ .join("|"),
84
+ definition
55
85
  );
56
86
  } else {
57
87
  const parts = definition.split("|").sort();
58
- const name = parts.join("|");
59
- return (
60
- types[name] ||
61
- addType({
62
- name,
63
- members: aggregate(parts.map(t => types[t]))
64
- })
65
- );
88
+ return aggregate(parts.join("|"), parts);
66
89
  }
67
90
  }
@@ -157,7 +157,7 @@ export const id_attribute: AttributeDefinition;
157
157
  * The one line description.
158
158
  * @type {AttributeDefinition}
159
159
  */
160
- export const title_attribute: AttributeDefinition;
160
+ export const title_attribute_writable: AttributeDefinition;
161
161
  /**
162
162
  * In case there are several providers able to support a given source which one sould be used ?
163
163
  * this defines the order.
@@ -220,4 +220,4 @@ export type AttributeDefinition = {
220
220
  */
221
221
  additionalValues?: object;
222
222
  };
223
- export { default_attribute as string_attribute, default_attribute_writable as string_attribute_writable, default_attribute as type_attribute, default_attribute_writable as state_attribute, 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 as size_attribute, default_attribute_writable as body_attribute, number_attribute as duration_attribute };
223
+ export { default_attribute as string_attribute, default_attribute_writable as string_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 as size_attribute, default_attribute_writable as body_attribute_writable, number_attribute as duration_attribute };