pacc 4.34.0 → 4.34.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/types.mjs +23 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pacc",
3
- "version": "4.34.0",
3
+ "version": "4.34.1",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": true
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
- return addType({
44
- name: definition.map(t => t.name).join("|"),
45
- members: new Set(definition)
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[definition] ||
65
+ types[name] ||
50
66
  addType({
51
- name: definition,
52
- members: new Set(definition.split("|").map(t => types[t]))
67
+ name,
68
+ members: aggregate(parts.map(t => types[t]))
53
69
  })
54
70
  );
55
71
  }