pacc 4.34.0 → 4.34.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 +1 -1
- package/src/attributes.mjs +2 -2
- package/src/types.mjs +23 -7
package/package.json
CHANGED
package/src/attributes.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getAttribute } from "./settergetter.mjs";
|
|
2
|
-
import { types } from "./types.mjs";
|
|
2
|
+
import { types, oneOfType } from "./types.mjs";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Create attributes from its definition.
|
|
@@ -13,7 +13,7 @@ export function prepareAttributesDefinitions(
|
|
|
13
13
|
) {
|
|
14
14
|
for (const [path, def] of attributeIterator(newDefinitions)) {
|
|
15
15
|
if (typeof def.type === "string") {
|
|
16
|
-
def.type =
|
|
16
|
+
def.type = oneOfType(def.type);
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
|
package/src/types.mjs
CHANGED
|
@@ -39,17 +39,33 @@ export function addType(type) {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
export function oneOfType(definition) {
|
|
42
|
+
const aggregate = list =>
|
|
43
|
+
list.reduce(
|
|
44
|
+
(a, c) => a.union(c?.members ?? new Set([types[c] ?? c])),
|
|
45
|
+
new Set()
|
|
46
|
+
);
|
|
47
|
+
|
|
42
48
|
if (Array.isArray(definition)) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
49
|
+
const name = definition
|
|
50
|
+
.map(t => t.name ?? t)
|
|
51
|
+
.sort()
|
|
52
|
+
.join("|");
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
types[name] ||
|
|
56
|
+
addType({
|
|
57
|
+
name,
|
|
58
|
+
members: aggregate(definition)
|
|
59
|
+
})
|
|
60
|
+
);
|
|
47
61
|
} else {
|
|
62
|
+
const parts = definition.split("|").sort();
|
|
63
|
+
const name = parts.join("|");
|
|
48
64
|
return (
|
|
49
|
-
types[
|
|
65
|
+
types[name] ||
|
|
50
66
|
addType({
|
|
51
|
-
name
|
|
52
|
-
members:
|
|
67
|
+
name,
|
|
68
|
+
members: aggregate(parts.map(t => types[t]))
|
|
53
69
|
})
|
|
54
70
|
);
|
|
55
71
|
}
|