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 validate(helpers, associatedType, value[caseName]);
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) => typeof value === "object" &&
77
- value !== null &&
78
- !Array.isArray(value) &&
79
- discriminatorKey in value &&
80
- typeof value[discriminatorKey] === "string" &&
81
- value[discriminatorKey] in type.values &&
82
- type.values[value[discriminatorKey]]?.type == null &&
83
- value[discriminatorKey] in value
84
- ? getReferencesForType(
85
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
86
- type.values[value[discriminatorKey]].type, value[value[discriminatorKey]])
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 &&
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tsondb",
3
- "version": "0.5.13",
3
+ "version": "0.5.15",
4
4
  "description": "",
5
5
  "license": "ISC",
6
6
  "author": "Lukas Obermann",