tsondb 0.7.3 → 0.7.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.
|
@@ -43,20 +43,22 @@ const checkEntityDisplayNamePaths = (decls, localeEntity) => {
|
|
|
43
43
|
if (localeEntity === undefined) {
|
|
44
44
|
throw new Error(`Display name path "${pathToLocaleMap}" for entity "${decl.name}" requires a defined locale entity.`);
|
|
45
45
|
}
|
|
46
|
-
const localeMapAtPath = findTypeAtPath(decl.type.value, pathToLocaleMap.split(".")
|
|
46
|
+
const localeMapAtPath = findTypeAtPath(decl.type.value, pathToLocaleMap.split("."), {
|
|
47
|
+
followTypeAliasIncludes: true,
|
|
48
|
+
});
|
|
47
49
|
if (!localeMapAtPath ||
|
|
48
50
|
!isNestedEntityMapType(localeMapAtPath) ||
|
|
49
51
|
localeMapAtPath.secondaryEntity.name !== localeEntity.name) {
|
|
50
52
|
throw new Error(`Display name path "${pathToLocaleMap}" for entity "${decl.name}" does not lead to a nested entity map for the defined locale entity.`);
|
|
51
53
|
}
|
|
52
|
-
const typeAtLocaleMapPath = findTypeAtPath(localeMapAtPath.type.value, pathInLocaleMap.split("."));
|
|
54
|
+
const typeAtLocaleMapPath = findTypeAtPath(localeMapAtPath.type.value, pathInLocaleMap.split("."), { followTypeAliasIncludes: true });
|
|
53
55
|
if (!typeAtLocaleMapPath || !isStringType(typeAtLocaleMapPath)) {
|
|
54
56
|
throw new Error(`Display name path "${pathInLocaleMap}" for entity "${decl.name}" does not lead to a value of type string in nested locale map.`);
|
|
55
57
|
}
|
|
56
58
|
}
|
|
57
59
|
else {
|
|
58
60
|
const path = displayName.split(".");
|
|
59
|
-
const typeAtPath = findTypeAtPath(decl.type.value, path);
|
|
61
|
+
const typeAtPath = findTypeAtPath(decl.type.value, path, { followTypeAliasIncludes: true });
|
|
60
62
|
if (!typeAtPath || !isStringType(typeAtPath)) {
|
|
61
63
|
throw new Error(`Display name path "${displayName}" for entity "${decl.name}" does not lead to a value of type string.`);
|
|
62
64
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Decl } from "../index.ts";
|
|
2
2
|
import type { BaseNode } from "../Node.ts";
|
|
3
3
|
import type { ArrayType } from "./generic/ArrayType.ts";
|
|
4
4
|
import type { EnumType } from "./generic/EnumType.ts";
|
|
@@ -23,7 +23,9 @@ export type AsType<T extends Type> = T extends ArrayType<infer I> ? AsType<I>[]
|
|
|
23
23
|
export type AsNode<T> = T extends (infer I)[] ? ArrayType<AsNode<I>> : T extends Record<string, unknown> ? ObjectType<{
|
|
24
24
|
[K in keyof T]: T[K] extends MemberDecl ? T[K] : T extends null | undefined ? MemberDecl<AsNode<NonNullable<T[K]>>, false> : MemberDecl<AsNode<T[K]>, true>;
|
|
25
25
|
}> : T extends string ? StringType : T extends number ? FloatType : T extends boolean ? BooleanType : T extends Date ? DateType : never;
|
|
26
|
-
export declare const findTypeAtPath: (type: Type, path: string[]
|
|
26
|
+
export declare const findTypeAtPath: (type: Type, path: string[], options?: {
|
|
27
|
+
followTypeAliasIncludes?: boolean;
|
|
28
|
+
}) => Type | undefined;
|
|
27
29
|
/**
|
|
28
30
|
* Format the structure of a value to always look the same when serialized as JSON.
|
|
29
31
|
*/
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { assertExhaustive } from "../../../shared/utils/typeSafety.js";
|
|
2
|
+
import { isTypeAliasDecl } from "../index.js";
|
|
2
3
|
import { NodeKind } from "../Node.js";
|
|
3
|
-
import { formatArrayValue } from "./generic/ArrayType.js";
|
|
4
|
+
import { formatArrayValue, isArrayType } from "./generic/ArrayType.js";
|
|
4
5
|
import { formatEnumType } from "./generic/EnumType.js";
|
|
5
|
-
import { formatObjectValue } from "./generic/ObjectType.js";
|
|
6
|
+
import { formatObjectValue, isObjectType } from "./generic/ObjectType.js";
|
|
6
7
|
import { formatBooleanValue } from "./primitives/BooleanType.js";
|
|
7
8
|
import { formatDateValue } from "./primitives/DateType.js";
|
|
8
9
|
import { formatFloatValue } from "./primitives/FloatType.js";
|
|
9
10
|
import { formatIntegerValue } from "./primitives/IntegerType.js";
|
|
10
11
|
import { formatStringValue } from "./primitives/StringType.js";
|
|
11
12
|
import { formatChildEntitiesValue } from "./references/ChildEntitiesType.js";
|
|
12
|
-
import { formatIncludeIdentifierValue } from "./references/IncludeIdentifierType.js";
|
|
13
|
+
import { formatIncludeIdentifierValue, isIncludeIdentifierType, } from "./references/IncludeIdentifierType.js";
|
|
13
14
|
import { formatNestedEntityMapValue } from "./references/NestedEntityMapType.js";
|
|
14
15
|
import { formatReferenceIdentifierValue } from "./references/ReferenceIdentifierType.js";
|
|
15
16
|
import { formatTypeArgumentValue } from "./references/TypeArgumentType.js";
|
|
@@ -63,19 +64,24 @@ export function walkTypeNodeTree(callbackFn, type, parentTypes, parentDecl) {
|
|
|
63
64
|
return assertExhaustive(type);
|
|
64
65
|
}
|
|
65
66
|
}
|
|
66
|
-
export const findTypeAtPath = (type, path) => {
|
|
67
|
+
export const findTypeAtPath = (type, path, options = {}) => {
|
|
67
68
|
const [head, ...tail] = path;
|
|
68
69
|
if (head === undefined) {
|
|
69
70
|
return type;
|
|
70
71
|
}
|
|
71
|
-
if (type
|
|
72
|
+
if (isObjectType(type)) {
|
|
72
73
|
const prop = type.properties[head];
|
|
73
74
|
if (prop) {
|
|
74
|
-
return findTypeAtPath(prop.type, tail);
|
|
75
|
+
return findTypeAtPath(prop.type, tail, options);
|
|
75
76
|
}
|
|
76
77
|
}
|
|
77
|
-
else if (type
|
|
78
|
-
return findTypeAtPath(type.items, path);
|
|
78
|
+
else if (isArrayType(type) && head === "0") {
|
|
79
|
+
return findTypeAtPath(type.items, path, options);
|
|
80
|
+
}
|
|
81
|
+
else if (isIncludeIdentifierType(type) &&
|
|
82
|
+
options.followTypeAliasIncludes &&
|
|
83
|
+
isTypeAliasDecl(type.reference)) {
|
|
84
|
+
return findTypeAtPath(type.reference.type.value, path, options);
|
|
79
85
|
}
|
|
80
86
|
return undefined;
|
|
81
87
|
};
|