pacc 4.40.3 → 4.40.4

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.40.3",
3
+ "version": "4.40.4",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": true
@@ -46,7 +46,7 @@
46
46
  "typescript": "^5.9.3"
47
47
  },
48
48
  "engines": {
49
- "node": ">=22.20.0"
49
+ "node": ">=22.21.0"
50
50
  },
51
51
  "repository": {
52
52
  "type": "git",
package/src/types.mjs CHANGED
@@ -30,10 +30,23 @@ export const types = {
30
30
  object: { name: "object" }
31
31
  };
32
32
 
33
- export function error(message) {
33
+ function error(message) {
34
34
  throw new Error(message);
35
35
  }
36
36
 
37
+ function raiseOnUnknownType(type, origin) {
38
+ switch (typeof type) {
39
+ case "string":
40
+ if (types[type]) {
41
+ return types[type];
42
+ }
43
+ case "undefined":
44
+ error(`Unknown type ${type} in '${origin}'`);
45
+ }
46
+
47
+ return type;
48
+ }
49
+
37
50
  export function addType(type) {
38
51
  if (type.typeDefinition) {
39
52
  const clazz = type;
@@ -64,28 +77,25 @@ export function addType(type) {
64
77
 
65
78
  case "string":
66
79
  if (typeof type.extends === "string") {
67
- const ex = types[type.extends];
68
- if (!ex) {
69
- error(`${type.name}: missing type '${type.extends}'`);
70
- }
71
- type.extends = ex;
80
+ type.extends = raiseOnUnknownType(type.extends, type);
72
81
  }
73
-
74
82
  break;
75
83
  }
76
84
 
85
+ if (!types[type.name]) {
86
+ types[type.name] = type;
87
+ }
88
+
77
89
  for (const [path, attribute] of attributeIterator(type.attributes)) {
78
90
  if (typeof attribute.type === "string") {
79
91
  attribute.type = oneOfType(attribute.type);
80
92
  }
81
93
  }
82
94
 
83
- if (types[type.name]) {
95
+ if (types[type.name] !== type) {
84
96
  return Object.assign(types[type.name], type);
85
97
  }
86
98
 
87
- types[type.name] = type;
88
-
89
99
  return type;
90
100
  }
91
101
 
@@ -95,11 +105,7 @@ export function oneOfType(definition) {
95
105
  name,
96
106
  members: list.reduce((all, type) => {
97
107
  if (typeof type === "string") {
98
- const t = types[type] || addType({ name: type });
99
- if (!t) {
100
- error(`Unknown type ${type} in '${definition}'`);
101
- }
102
- type = t;
108
+ type = raiseOnUnknownType(type, definition); // addType({ name: type });
103
109
  }
104
110
  return all.union(type.members ?? new Set([type]));
105
111
  }, new Set())
@@ -124,3 +130,15 @@ export function oneOfType(definition) {
124
130
  return aggregate(parts.join("|"), parts);
125
131
  }
126
132
  }
133
+
134
+ export function resolveTypeLinks() {
135
+ for (const type of Object.values(types)) {
136
+ if (typeof type.extends === "string") {
137
+ type.extends = raiseOnUnknownType(type.extends, type);
138
+ }
139
+
140
+ if (type.owners) {
141
+ type.owners = type.owners.map(owner => raiseOnUnknownType(owner, type));
142
+ }
143
+ }
144
+ }
package/types/types.d.mts CHANGED
@@ -1,6 +1,6 @@
1
- export function error(message: any): void;
2
1
  export function addType(type: any): any;
3
2
  export function oneOfType(definition: any): any;
3
+ export function resolveTypeLinks(): void;
4
4
  export const types: {
5
5
  string: {
6
6
  name: string;