tsondb 0.5.13 → 0.5.15
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.
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { discriminatorKey } from "../../../../shared/enum.js";
|
|
2
|
+
import { parallelizeErrors } from "../../../../shared/utils/validation.js";
|
|
3
|
+
import { wrapErrorsIfAny } from "../../../utils/error.js";
|
|
2
4
|
import { json, key } from "../../../utils/errorFormatting.js";
|
|
3
5
|
import { getNestedDeclarations } from "../../declarations/Declaration.js";
|
|
4
6
|
import { NodeKind } from "../../Node.js";
|
|
@@ -47,7 +49,9 @@ export const validateEnumType = (helpers, type, value) => {
|
|
|
47
49
|
TypeError(`missing required associated value for case ${key(`"${caseName}"`, helpers.useStyling)}`),
|
|
48
50
|
];
|
|
49
51
|
}
|
|
50
|
-
return
|
|
52
|
+
return parallelizeErrors([
|
|
53
|
+
wrapErrorsIfAny(`at enum case ${key(`"${caseName}"`, helpers.useStyling)}`, validate(helpers, associatedType, value[caseName])),
|
|
54
|
+
]);
|
|
51
55
|
}
|
|
52
56
|
return [];
|
|
53
57
|
};
|
|
@@ -73,18 +77,22 @@ export const serializeEnumType = type => ({
|
|
|
73
77
|
},
|
|
74
78
|
])),
|
|
75
79
|
});
|
|
76
|
-
export const getReferencesForEnumType = (type, value) =>
|
|
77
|
-
value !==
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
value[discriminatorKey]
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
80
|
+
export const getReferencesForEnumType = (type, value) => {
|
|
81
|
+
if (typeof value !== "object" ||
|
|
82
|
+
value === null ||
|
|
83
|
+
Array.isArray(value) ||
|
|
84
|
+
!(discriminatorKey in value)) {
|
|
85
|
+
return [];
|
|
86
|
+
}
|
|
87
|
+
const enumCase = value[discriminatorKey];
|
|
88
|
+
return typeof enumCase === "string" &&
|
|
89
|
+
enumCase in type.values &&
|
|
90
|
+
type.values[enumCase] !== undefined &&
|
|
91
|
+
type.values[enumCase].type !== null &&
|
|
92
|
+
enumCase in value
|
|
93
|
+
? getReferencesForType(type.values[enumCase].type, value[enumCase])
|
|
94
|
+
: [];
|
|
95
|
+
};
|
|
88
96
|
export const formatEnumType = (type, value) => {
|
|
89
97
|
if (typeof value === "object" &&
|
|
90
98
|
value !== null &&
|