tsondb 0.3.0 → 0.4.0
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/LICENSE +385 -0
- package/README.md +173 -1
- package/lib/bin/tsondb.d.ts +8 -0
- package/lib/bin/tsondb.js +83 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +1 -1
- package/lib/{Schema.d.ts → node/Schema.d.ts} +2 -2
- package/lib/{Schema.js → node/Schema.js} +1 -1
- package/lib/node/index.d.ts +8 -0
- package/lib/node/index.js +62 -0
- package/lib/{renderers → node/renderers}/Output.d.ts +1 -1
- package/lib/{renderers → node/renderers}/jsonschema/index.d.ts +2 -2
- package/lib/{renderers → node/renderers}/jsonschema/index.js +2 -2
- package/lib/{renderers → node/renderers}/jsonschema/render.d.ts +1 -1
- package/lib/{renderers → node/renderers}/jsonschema/render.js +9 -9
- package/lib/{renderers → node/renderers}/ts/index.d.ts +2 -2
- package/lib/{renderers → node/renderers}/ts/index.js +2 -2
- package/lib/{renderers → node/renderers}/ts/render.d.ts +1 -1
- package/lib/{renderers → node/renderers}/ts/render.js +9 -8
- package/lib/{schema → node/schema}/Node.d.ts +4 -4
- package/lib/{schema → node/schema}/Node.js +5 -5
- package/lib/{schema/parameters → node/schema}/TypeParameter.d.ts +3 -2
- package/lib/{schema/parameters → node/schema}/TypeParameter.js +2 -2
- package/lib/{schema → node/schema}/declarations/Declaration.d.ts +10 -11
- package/lib/{schema → node/schema}/declarations/Declaration.js +7 -5
- package/lib/{schema → node/schema}/declarations/EntityDecl.d.ts +10 -9
- package/lib/{schema → node/schema}/declarations/EntityDecl.js +2 -2
- package/lib/{schema → node/schema}/declarations/EnumDecl.d.ts +9 -7
- package/lib/{schema → node/schema}/declarations/EnumDecl.js +3 -3
- package/lib/{schema → node/schema}/declarations/TypeAliasDecl.d.ts +8 -7
- package/lib/{schema → node/schema}/declarations/TypeAliasDecl.js +3 -3
- package/lib/{schema → node/schema}/index.d.ts +4 -4
- package/lib/{schema → node/schema}/index.js +3 -4
- package/lib/node/schema/types/Type.d.ts +48 -0
- package/lib/{schema → node/schema}/types/Type.js +41 -25
- package/lib/{schema → node/schema}/types/generic/ArrayType.d.ts +5 -4
- package/lib/{schema → node/schema}/types/generic/ArrayType.js +3 -3
- package/lib/{schema → node/schema}/types/generic/EnumType.d.ts +5 -4
- package/lib/{schema → node/schema}/types/generic/EnumType.js +4 -2
- package/lib/{schema → node/schema}/types/generic/ObjectType.d.ts +8 -7
- package/lib/{schema → node/schema}/types/generic/ObjectType.js +8 -4
- package/lib/{schema → node/schema}/types/primitives/BooleanType.d.ts +4 -3
- package/lib/{schema → node/schema}/types/primitives/DateType.d.ts +5 -4
- package/lib/{schema → node/schema}/types/primitives/DateType.js +1 -1
- package/lib/{schema → node/schema}/types/primitives/FloatType.d.ts +5 -4
- package/lib/{schema → node/schema}/types/primitives/FloatType.js +1 -1
- package/lib/{schema → node/schema}/types/primitives/IntegerType.d.ts +5 -4
- package/lib/{schema → node/schema}/types/primitives/IntegerType.js +1 -1
- package/lib/{schema → node/schema}/types/primitives/NumericType.d.ts +2 -2
- package/lib/node/schema/types/primitives/PrimitiveType.d.ts +6 -0
- package/lib/{schema → node/schema}/types/primitives/StringType.d.ts +5 -4
- package/lib/{schema → node/schema}/types/primitives/StringType.js +1 -1
- package/lib/{schema → node/schema}/types/references/IncludeIdentifierType.d.ts +9 -8
- package/lib/{schema → node/schema}/types/references/IncludeIdentifierType.js +1 -1
- package/lib/{schema → node/schema}/types/references/NestedEntityMapType.d.ts +10 -9
- package/lib/{schema → node/schema}/types/references/NestedEntityMapType.js +4 -4
- package/lib/{schema → node/schema}/types/references/ReferenceIdentifierType.d.ts +7 -6
- package/lib/{schema → node/schema}/types/references/ReferenceIdentifierType.js +1 -1
- package/lib/node/schema/types/references/TypeArgumentType.d.ts +23 -0
- package/lib/node/schema/types/references/TypeArgumentType.js +19 -0
- package/lib/node/schema/validation/type.d.ts +4 -0
- package/lib/{server → node/server}/api/declarations.js +1 -1
- package/lib/{server → node/server}/api/git.js +14 -10
- package/lib/{server → node/server}/api/instanceOperations.d.ts +3 -3
- package/lib/{server → node/server}/api/instanceOperations.js +13 -4
- package/lib/{server → node/server}/api/instances.js +7 -3
- package/lib/node/server/index.d.ts +28 -0
- package/lib/{server → node/server}/index.js +6 -6
- package/lib/node/server/init.d.ts +5 -0
- package/lib/{server → node/server}/init.js +8 -8
- package/lib/{utils → node/utils}/error.js +4 -1
- package/lib/{utils → node/utils}/git.d.ts +2 -2
- package/lib/{utils → node/utils}/instances.d.ts +3 -3
- package/lib/{utils → node/utils}/instances.js +8 -6
- package/lib/{utils → node/utils}/references.d.ts +2 -2
- package/lib/{utils → node/utils}/references.js +3 -3
- package/lib/{utils → node/utils}/render.js +1 -1
- package/lib/shared/api.d.ts +8 -2
- package/lib/shared/utils/array.js +12 -9
- package/lib/shared/utils/displayName.d.ts +1 -1
- package/lib/shared/utils/displayName.js +4 -2
- package/lib/shared/utils/instances.d.ts +2 -2
- package/lib/{utils → shared/utils}/lazy.js +1 -1
- package/lib/shared/utils/markdown.js +6 -6
- package/lib/shared/utils/object.d.ts +3 -0
- package/lib/shared/utils/object.js +1 -0
- package/lib/{utils → shared/utils}/result.js +2 -2
- package/lib/shared/utils/string.js +7 -4
- package/lib/shared/utils/validation.js +3 -2
- package/lib/shared/validation/number.js +3 -3
- package/lib/shared/validation/object.js +4 -3
- package/lib/shared/validation/string.js +12 -7
- package/lib/{client → web}/api.d.ts +2 -2
- package/lib/{client → web}/api.js +4 -2
- package/lib/web/components/Git.d.ts +2 -0
- package/lib/{client → web}/components/Git.js +58 -14
- package/lib/{client → web}/components/Layout.d.ts +1 -1
- package/lib/{client → web}/components/Layout.js +1 -1
- package/lib/web/components/Select.d.ts +3 -0
- package/lib/web/components/Select.js +5 -0
- package/lib/web/components/typeInputs/ArrayTypeInput.d.ts +13 -0
- package/lib/{client → web}/components/typeInputs/ArrayTypeInput.js +7 -1
- package/lib/{client → web}/components/typeInputs/BooleanTypeInput.d.ts +2 -2
- package/lib/{client → web}/components/typeInputs/DateTypeInput.d.ts +2 -2
- package/lib/web/components/typeInputs/EnumTypeInput.d.ts +13 -0
- package/lib/{client → web}/components/typeInputs/EnumTypeInput.js +1 -1
- package/lib/{client → web}/components/typeInputs/FloatTypeInput.d.ts +2 -2
- package/lib/web/components/typeInputs/GenericTypeArgumentIdentifierTypeInput.d.ts +7 -0
- package/lib/{client → web}/components/typeInputs/GenericTypeArgumentIdentifierTypeInput.js +1 -1
- package/lib/web/components/typeInputs/IncludeIdentifierTypeInput.d.ts +13 -0
- package/lib/{client → web}/components/typeInputs/IntegerTypeInput.d.ts +2 -2
- package/lib/web/components/typeInputs/NestedEntityMapTypeInput.d.ts +13 -0
- package/lib/{client → web}/components/typeInputs/NestedEntityMapTypeInput.js +7 -2
- package/lib/{client → web}/components/typeInputs/ObjectTypeInput.d.ts +4 -4
- package/lib/{client → web}/components/typeInputs/ObjectTypeInput.js +4 -1
- package/lib/{client → web}/components/typeInputs/ReferenceIdentifierTypeInput.d.ts +3 -3
- package/lib/web/components/typeInputs/ReferenceIdentifierTypeInput.js +11 -0
- package/lib/{client → web}/components/typeInputs/StringTypeInput.d.ts +2 -2
- package/lib/web/components/typeInputs/TypeInput.d.ts +13 -0
- package/lib/{client → web}/components/typeInputs/TypeInput.js +3 -3
- package/lib/{client → web}/components/typeInputs/utils/Markdown.d.ts +1 -1
- package/lib/{client → web}/components/typeInputs/utils/Markdown.js +2 -2
- package/lib/{client → web}/components/typeInputs/utils/MismatchingTypeError.d.ts +1 -1
- package/lib/{client → web}/components/typeInputs/utils/ValidationErrors.d.ts +1 -1
- package/lib/web/hooks/useAPIResource.d.ts +1 -0
- package/lib/{client → web}/hooks/useEntityFromRoute.d.ts +1 -1
- package/lib/{client → web}/hooks/useEntityFromRoute.js +1 -1
- package/lib/{client → web}/hooks/useInstanceNamesByEntity.d.ts +1 -1
- package/lib/{client → web}/hooks/useInstanceNamesByEntity.js +8 -6
- package/lib/web/hooks/useMappedAPIResource.d.ts +1 -0
- package/lib/{client → web}/hooks/useMappedAPIResource.js +7 -9
- package/lib/{client → web}/hooks/useSecondaryDeclarations.d.ts +1 -1
- package/lib/{client → web}/hooks/useSecondaryDeclarations.js +4 -2
- package/lib/{client → web}/routes/CreateInstance.d.ts +1 -1
- package/lib/{client → web}/routes/CreateInstance.js +4 -2
- package/lib/web/routes/Entity.d.ts +2 -0
- package/lib/{client → web}/routes/Entity.js +5 -3
- package/lib/web/routes/Home.d.ts +2 -0
- package/lib/{client → web}/routes/Instance.d.ts +1 -1
- package/lib/{client → web}/routes/Instance.js +14 -8
- package/lib/{client → web}/routes/NotFound.d.ts +1 -1
- package/lib/web/utils/typeSkeleton.d.ts +3 -0
- package/lib/{client → web}/utils/typeSkeleton.js +4 -1
- package/package.json +31 -18
- package/lib/ModelContainer.d.ts +0 -17
- package/lib/ModelContainer.js +0 -65
- package/lib/client/components/Git.d.ts +0 -2
- package/lib/client/components/Select.d.ts +0 -3
- package/lib/client/components/Select.js +0 -2
- package/lib/client/components/typeInputs/ArrayTypeInput.d.ts +0 -13
- package/lib/client/components/typeInputs/EnumTypeInput.d.ts +0 -13
- package/lib/client/components/typeInputs/GenericTypeArgumentIdentifierTypeInput.d.ts +0 -7
- package/lib/client/components/typeInputs/IncludeIdentifierTypeInput.d.ts +0 -13
- package/lib/client/components/typeInputs/NestedEntityMapTypeInput.d.ts +0 -13
- package/lib/client/components/typeInputs/ReferenceIdentifierTypeInput.js +0 -9
- package/lib/client/components/typeInputs/TypeInput.d.ts +0 -13
- package/lib/client/hooks/useAPIResource.d.ts +0 -1
- package/lib/client/hooks/useMappedAPIResource.d.ts +0 -1
- package/lib/client/routes/Entity.d.ts +0 -2
- package/lib/client/routes/Home.d.ts +0 -2
- package/lib/client/utils/typeSkeleton.d.ts +0 -3
- package/lib/schema/types/Type.d.ts +0 -48
- package/lib/schema/types/primitives/PrimitiveType.d.ts +0 -6
- package/lib/schema/types/references/GenericArgumentIdentifierType.d.ts +0 -22
- package/lib/schema/types/references/GenericArgumentIdentifierType.js +0 -19
- package/lib/schema/validation/type.d.ts +0 -4
- package/lib/server/index.d.ts +0 -29
- package/lib/server/init.d.ts +0 -5
- package/lib/tsconfig.tsbuildinfo +0 -1
- package/lib/utils/object.d.ts +0 -3
- package/lib/utils/object.js +0 -1
- /package/lib/{renderers → node/renderers}/Output.js +0 -0
- /package/lib/{schema → node/schema}/types/primitives/BooleanType.js +0 -0
- /package/lib/{schema → node/schema}/types/primitives/NumericType.js +0 -0
- /package/lib/{schema → node/schema}/types/primitives/PrimitiveType.js +0 -0
- /package/lib/{schema → node/schema}/validation/options.d.ts +0 -0
- /package/lib/{schema → node/schema}/validation/options.js +0 -0
- /package/lib/{schema → node/schema}/validation/type.js +0 -0
- /package/lib/{server → node/server}/api/declarations.d.ts +0 -0
- /package/lib/{server → node/server}/api/git.d.ts +0 -0
- /package/lib/{server → node/server}/api/index.d.ts +0 -0
- /package/lib/{server → node/server}/api/index.js +0 -0
- /package/lib/{server → node/server}/api/instances.d.ts +0 -0
- /package/lib/{utils → node/utils}/error.d.ts +0 -0
- /package/lib/{utils → node/utils}/git.js +0 -0
- /package/lib/{utils → node/utils}/path.d.ts +0 -0
- /package/lib/{utils → node/utils}/path.js +0 -0
- /package/lib/{utils → node/utils}/render.d.ts +0 -0
- /package/lib/{utils → shared/utils}/enum.d.ts +0 -0
- /package/lib/{utils → shared/utils}/enum.js +0 -0
- /package/lib/{utils → shared/utils}/lazy.d.ts +0 -0
- /package/lib/{utils → shared/utils}/result.d.ts +0 -0
- /package/lib/{client → web}/components/typeInputs/BooleanTypeInput.js +0 -0
- /package/lib/{client → web}/components/typeInputs/DateTypeInput.js +0 -0
- /package/lib/{client → web}/components/typeInputs/FloatTypeInput.js +0 -0
- /package/lib/{client → web}/components/typeInputs/IncludeIdentifierTypeInput.js +0 -0
- /package/lib/{client → web}/components/typeInputs/IntegerTypeInput.js +0 -0
- /package/lib/{client → web}/components/typeInputs/StringTypeInput.js +0 -0
- /package/lib/{client → web}/components/typeInputs/utils/MismatchingTypeError.js +0 -0
- /package/lib/{client → web}/components/typeInputs/utils/ValidationErrors.js +0 -0
- /package/lib/{client → web}/hooks/useAPIResource.js +0 -0
- /package/lib/{client → web}/index.d.ts +0 -0
- /package/lib/{client → web}/index.js +0 -0
- /package/lib/{client → web}/routes/Home.js +0 -0
- /package/lib/{client → web}/routes/NotFound.js +0 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { Decl } from "../declarations/Declaration.js";
|
|
2
|
+
import type { BaseNode, GetReferences, Serializer } from "../Node.js";
|
|
3
|
+
import type { Validator } from "../validation/type.js";
|
|
4
|
+
import type { ArrayType, SerializedArrayType } from "./generic/ArrayType.js";
|
|
5
|
+
import type { EnumType, SerializedEnumType } from "./generic/EnumType.js";
|
|
6
|
+
import type { MemberDecl, ObjectType, SerializedMemberDecl, SerializedObjectType } from "./generic/ObjectType.js";
|
|
7
|
+
import type { BooleanType, SerializedBooleanType } from "./primitives/BooleanType.js";
|
|
8
|
+
import type { DateType, SerializedDateType } from "./primitives/DateType.js";
|
|
9
|
+
import type { FloatType, SerializedFloatType } from "./primitives/FloatType.js";
|
|
10
|
+
import type { IntegerType, SerializedIntegerType } from "./primitives/IntegerType.js";
|
|
11
|
+
import type { PrimitiveType, SerializedPrimitiveType } from "./primitives/PrimitiveType.js";
|
|
12
|
+
import type { SerializedStringType, StringType } from "./primitives/StringType.js";
|
|
13
|
+
import type { IncludeIdentifierType, SerializedIncludeIdentifierType } from "./references/IncludeIdentifierType.js";
|
|
14
|
+
import type { NestedEntityMapType, SerializedNestedEntityMapType } from "./references/NestedEntityMapType.js";
|
|
15
|
+
import type { ReferenceIdentifierType, SerializedReferenceIdentifierType } from "./references/ReferenceIdentifierType.js";
|
|
16
|
+
import type { SerializedTypeArgumentType, TypeArgumentType } from "./references/TypeArgumentType.js";
|
|
17
|
+
export interface BaseType extends BaseNode {
|
|
18
|
+
/**
|
|
19
|
+
* The parent node of this type will be set when the type is used in a declaration or nested in another type.
|
|
20
|
+
*/
|
|
21
|
+
parent?: Type | Decl;
|
|
22
|
+
}
|
|
23
|
+
export interface SerializedBaseType extends BaseNode {
|
|
24
|
+
}
|
|
25
|
+
export type Type = PrimitiveType | ArrayType | ObjectType | TypeArgumentType | ReferenceIdentifierType | IncludeIdentifierType | NestedEntityMapType | EnumType;
|
|
26
|
+
export type SerializedType = SerializedPrimitiveType | SerializedArrayType | SerializedObjectType | SerializedTypeArgumentType | SerializedReferenceIdentifierType | SerializedIncludeIdentifierType | SerializedNestedEntityMapType | SerializedEnumType;
|
|
27
|
+
export declare const validate: Validator<Type>;
|
|
28
|
+
export declare const resolveTypeArgumentsInType: (args: Record<string, Type>, type: Type) => Type;
|
|
29
|
+
export declare function walkTypeNodeTree(callbackFn: (type: Type) => void, type: Type): void;
|
|
30
|
+
export type AsType<T extends Type> = T extends ArrayType<infer I> ? AsType<I>[] : T extends ObjectType<infer P> ? {
|
|
31
|
+
[K in keyof P]: P[K] extends MemberDecl<Type, true> ? AsType<P[K]["type"]> : AsType<P[K]["type"]> | undefined;
|
|
32
|
+
} : T extends BooleanType ? boolean : T extends DateType ? Date : T extends FloatType ? number : T extends IntegerType ? number : T extends StringType ? string : T extends TypeArgumentType ? unknown : T extends IncludeIdentifierType ? unknown : T extends NestedEntityMapType ? unknown : T extends ReferenceIdentifierType ? unknown : never;
|
|
33
|
+
export type SerializedAsType<T extends SerializedType> = T extends SerializedArrayType<infer I> ? SerializedAsType<I>[] : T extends SerializedObjectType<infer P> ? {
|
|
34
|
+
[K in keyof P]: P[K] extends SerializedMemberDecl<SerializedType, true> ? SerializedAsType<P[K]["type"]> : SerializedAsType<P[K]["type"]> | undefined;
|
|
35
|
+
} : T extends SerializedBooleanType ? boolean : T extends SerializedDateType ? Date : T extends SerializedFloatType ? number : T extends SerializedIntegerType ? number : T extends SerializedStringType ? string : T extends SerializedTypeArgumentType ? unknown : T extends SerializedIncludeIdentifierType ? unknown : T extends SerializedNestedEntityMapType ? unknown : T extends SerializedReferenceIdentifierType ? unknown : never;
|
|
36
|
+
export type AsNode<T> = T extends (infer I)[] ? ArrayType<AsNode<I>> : T extends Record<string, unknown> ? ObjectType<{
|
|
37
|
+
[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>;
|
|
38
|
+
}> : T extends string ? StringType : T extends number ? FloatType : T extends boolean ? BooleanType : never;
|
|
39
|
+
export declare const getParentDecl: (type: Type) => Decl | undefined;
|
|
40
|
+
export declare const findTypeAtPath: (type: Type, path: string[]) => Type | undefined;
|
|
41
|
+
export declare const serializeType: Serializer<Type, SerializedType>;
|
|
42
|
+
export declare const removeParentKey: <T extends BaseType>(type: T) => Omit<T, "parent">;
|
|
43
|
+
export declare const getReferencesForType: GetReferences<Type>;
|
|
44
|
+
/**
|
|
45
|
+
* Format the structure of a value to always look the same when serialized as JSON.
|
|
46
|
+
*/
|
|
47
|
+
export type StructureFormatter<T extends Type> = (type: T, value: unknown) => unknown;
|
|
48
|
+
export declare const formatValue: StructureFormatter<Type>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { assertExhaustive } from "
|
|
1
|
+
import { assertExhaustive } from "../../../shared/utils/typeSafety.js";
|
|
2
2
|
import { isDecl } from "../declarations/Declaration.js";
|
|
3
3
|
import { NodeKind } from "../Node.js";
|
|
4
4
|
import { formatArrayValue, getReferencesForArrayType, resolveTypeArgumentsInArrayType, serializeArrayType, validateArrayType, } from "./generic/ArrayType.js";
|
|
@@ -9,10 +9,10 @@ import { formatDateValue, getReferencesForDateType, serializeDateType, validateD
|
|
|
9
9
|
import { formatFloatValue, getReferencesForFloatType, serializeFloatType, validateFloatType, } from "./primitives/FloatType.js";
|
|
10
10
|
import { formatIntegerValue, getReferencesForIntegerType, serializeIntegerType, validateIntegerType, } from "./primitives/IntegerType.js";
|
|
11
11
|
import { formatStringValue, getReferencesForStringType, serializeStringType, validateStringType, } from "./primitives/StringType.js";
|
|
12
|
-
import { formatGenericArgumentIdentifierValue, getReferencesForGenericArgumentIdentifierType, resolveTypeArgumentsInGenericArgumentIdentifierType, serializeGenericArgumentIdentifierType, validateGenericArgumentIdentifierType, } from "./references/GenericArgumentIdentifierType.js";
|
|
13
12
|
import { formatIncludeIdentifierValue, getReferencesForIncludeIdentifierType, resolveTypeArgumentsInIncludeIdentifierType, serializeIncludeIdentifierType, validateIncludeIdentifierType, } from "./references/IncludeIdentifierType.js";
|
|
14
13
|
import { formatNestedEntityMapValue, getReferencesForNestedEntityMapType, resolveTypeArgumentsInNestedEntityMapType, serializeNestedEntityMapType, validateNestedEntityMapType, } from "./references/NestedEntityMapType.js";
|
|
15
14
|
import { formatReferenceIdentifierValue, getReferencesForReferenceIdentifierType, resolveTypeArgumentsInReferenceIdentifierType, serializeReferenceIdentifierType, validateReferenceIdentifierType, } from "./references/ReferenceIdentifierType.js";
|
|
15
|
+
import { formatTypeArgumentValue, getReferencesForTypeArgumentType, resolveTypeArgumentsInTypeArgumentType, serializeTypeArgumentType, validateTypeArgumentType, } from "./references/TypeArgumentType.js";
|
|
16
16
|
export const validate = (helpers, type, value) => {
|
|
17
17
|
switch (type.kind) {
|
|
18
18
|
case NodeKind.ArrayType:
|
|
@@ -29,8 +29,8 @@ export const validate = (helpers, type, value) => {
|
|
|
29
29
|
return validateIntegerType(helpers, type, value);
|
|
30
30
|
case NodeKind.StringType:
|
|
31
31
|
return validateStringType(helpers, type, value);
|
|
32
|
-
case NodeKind.
|
|
33
|
-
return
|
|
32
|
+
case NodeKind.TypeArgumentType:
|
|
33
|
+
return validateTypeArgumentType(helpers, type, value);
|
|
34
34
|
case NodeKind.ReferenceIdentifierType:
|
|
35
35
|
return validateReferenceIdentifierType(helpers, type, value);
|
|
36
36
|
case NodeKind.IncludeIdentifierType:
|
|
@@ -55,8 +55,8 @@ export const resolveTypeArgumentsInType = (args, type) => {
|
|
|
55
55
|
case NodeKind.IntegerType:
|
|
56
56
|
case NodeKind.StringType:
|
|
57
57
|
return type;
|
|
58
|
-
case NodeKind.
|
|
59
|
-
return
|
|
58
|
+
case NodeKind.TypeArgumentType:
|
|
59
|
+
return resolveTypeArgumentsInTypeArgumentType(args, type);
|
|
60
60
|
case NodeKind.ReferenceIdentifierType:
|
|
61
61
|
return resolveTypeArgumentsInReferenceIdentifierType(args, type);
|
|
62
62
|
case NodeKind.IncludeIdentifierType:
|
|
@@ -73,29 +73,45 @@ export function walkTypeNodeTree(callbackFn, type) {
|
|
|
73
73
|
switch (type.kind) {
|
|
74
74
|
case NodeKind.ArrayType:
|
|
75
75
|
callbackFn(type);
|
|
76
|
-
|
|
76
|
+
{
|
|
77
|
+
walkTypeNodeTree(callbackFn, type.items);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
77
80
|
case NodeKind.ObjectType:
|
|
78
81
|
callbackFn(type);
|
|
79
|
-
|
|
82
|
+
{
|
|
83
|
+
Object.values(type.properties).forEach(prop => {
|
|
84
|
+
walkTypeNodeTree(callbackFn, prop.type);
|
|
85
|
+
});
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
80
88
|
case NodeKind.NestedEntityMapType:
|
|
81
89
|
callbackFn(type);
|
|
82
|
-
|
|
90
|
+
{
|
|
91
|
+
walkTypeNodeTree(callbackFn, type.type.value);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
83
94
|
case NodeKind.BooleanType:
|
|
84
95
|
case NodeKind.DateType:
|
|
85
96
|
case NodeKind.FloatType:
|
|
86
97
|
case NodeKind.IntegerType:
|
|
87
98
|
case NodeKind.StringType:
|
|
88
|
-
case NodeKind.
|
|
99
|
+
case NodeKind.TypeArgumentType:
|
|
89
100
|
case NodeKind.ReferenceIdentifierType:
|
|
90
|
-
case NodeKind.IncludeIdentifierType:
|
|
91
|
-
|
|
101
|
+
case NodeKind.IncludeIdentifierType: {
|
|
102
|
+
callbackFn(type);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
92
105
|
case NodeKind.EnumType:
|
|
93
106
|
callbackFn(type);
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
107
|
+
{
|
|
108
|
+
Object.values(type.values).forEach(value => {
|
|
109
|
+
if (value.type) {
|
|
110
|
+
walkTypeNodeTree(callbackFn, value.type);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
99
115
|
default:
|
|
100
116
|
return assertExhaustive(type);
|
|
101
117
|
}
|
|
@@ -112,10 +128,10 @@ export const getParentDecl = (type) => {
|
|
|
112
128
|
}
|
|
113
129
|
};
|
|
114
130
|
export const findTypeAtPath = (type, path) => {
|
|
115
|
-
|
|
131
|
+
const [head, ...tail] = path;
|
|
132
|
+
if (head === undefined) {
|
|
116
133
|
return type;
|
|
117
134
|
}
|
|
118
|
-
const [head, ...tail] = path;
|
|
119
135
|
if (type.kind === NodeKind.ObjectType) {
|
|
120
136
|
const prop = type.properties[head];
|
|
121
137
|
if (prop) {
|
|
@@ -143,8 +159,8 @@ export const serializeType = type => {
|
|
|
143
159
|
return serializeIntegerType(type);
|
|
144
160
|
case NodeKind.StringType:
|
|
145
161
|
return serializeStringType(type);
|
|
146
|
-
case NodeKind.
|
|
147
|
-
return
|
|
162
|
+
case NodeKind.TypeArgumentType:
|
|
163
|
+
return serializeTypeArgumentType(type);
|
|
148
164
|
case NodeKind.ReferenceIdentifierType:
|
|
149
165
|
return serializeReferenceIdentifierType(type);
|
|
150
166
|
case NodeKind.IncludeIdentifierType:
|
|
@@ -177,8 +193,8 @@ export const getReferencesForType = (type, value) => {
|
|
|
177
193
|
return getReferencesForIntegerType(type, value);
|
|
178
194
|
case NodeKind.StringType:
|
|
179
195
|
return getReferencesForStringType(type, value);
|
|
180
|
-
case NodeKind.
|
|
181
|
-
return
|
|
196
|
+
case NodeKind.TypeArgumentType:
|
|
197
|
+
return getReferencesForTypeArgumentType(type, value);
|
|
182
198
|
case NodeKind.ReferenceIdentifierType:
|
|
183
199
|
return getReferencesForReferenceIdentifierType(type, value);
|
|
184
200
|
case NodeKind.IncludeIdentifierType:
|
|
@@ -207,8 +223,8 @@ export const formatValue = (type, value) => {
|
|
|
207
223
|
return formatIntegerValue(type, value);
|
|
208
224
|
case NodeKind.StringType:
|
|
209
225
|
return formatStringValue(type, value);
|
|
210
|
-
case NodeKind.
|
|
211
|
-
return
|
|
226
|
+
case NodeKind.TypeArgumentType:
|
|
227
|
+
return formatTypeArgumentValue(type, value);
|
|
212
228
|
case NodeKind.IncludeIdentifierType:
|
|
213
229
|
return formatIncludeIdentifierValue(type, value);
|
|
214
230
|
case NodeKind.NestedEntityMapType:
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { GetNestedDeclarations } from "../../declarations/Declaration.js";
|
|
2
|
-
import { GetReferences, Node,
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import type { GetNestedDeclarations } from "../../declarations/Declaration.js";
|
|
2
|
+
import type { GetReferences, Node, Serializer } from "../../Node.js";
|
|
3
|
+
import { NodeKind } from "../../Node.js";
|
|
4
|
+
import type { Validator } from "../../validation/type.js";
|
|
5
|
+
import type { BaseType, SerializedBaseType, SerializedType, StructureFormatter, Type } from "../Type.js";
|
|
5
6
|
export interface ArrayType<T extends Type = Type> extends BaseType {
|
|
6
7
|
kind: NodeKind["ArrayType"];
|
|
7
8
|
minItems?: number;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { parallelizeErrors } from "
|
|
2
|
-
import { validateArrayConstraints } from "
|
|
1
|
+
import { parallelizeErrors } from "../../../../shared/utils/validation.js";
|
|
2
|
+
import { validateArrayConstraints } from "../../../../shared/validation/array.js";
|
|
3
3
|
import { wrapErrorsIfAny } from "../../../utils/error.js";
|
|
4
4
|
import { getNestedDeclarations } from "../../declarations/Declaration.js";
|
|
5
5
|
import { NodeKind } from "../../Node.js";
|
|
@@ -25,7 +25,7 @@ export const validateArrayType = (helpers, type, value) => {
|
|
|
25
25
|
}
|
|
26
26
|
return parallelizeErrors([
|
|
27
27
|
...validateArrayConstraints(type, value),
|
|
28
|
-
...value.map((item, index) => wrapErrorsIfAny(`at index ${index}`, validate(helpers, type.items, item))),
|
|
28
|
+
...value.map((item, index) => wrapErrorsIfAny(`at index ${index.toString()}`, validate(helpers, type.items, item))),
|
|
29
29
|
]);
|
|
30
30
|
};
|
|
31
31
|
export const resolveTypeArgumentsInArrayType = (args, type) => ArrayType(resolveTypeArgumentsInType(args, type.items), {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { GetNestedDeclarations } from "../../declarations/Declaration.js";
|
|
2
|
-
import { GetReferences, Node,
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import type { GetNestedDeclarations } from "../../declarations/Declaration.js";
|
|
2
|
+
import type { GetReferences, Node, Serializer } from "../../Node.js";
|
|
3
|
+
import { NodeKind } from "../../Node.js";
|
|
4
|
+
import type { Validator } from "../../validation/type.js";
|
|
5
|
+
import type { BaseType, SerializedBaseType, SerializedType, StructureFormatter, Type } from "../Type.js";
|
|
5
6
|
export interface EnumType<T extends Record<string, EnumCaseDecl> = Record<string, EnumCaseDecl>> extends BaseType {
|
|
6
7
|
kind: NodeKind["EnumType"];
|
|
7
8
|
values: T;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { discriminatorKey } from "
|
|
1
|
+
import { discriminatorKey } from "../../../../shared/enum.js";
|
|
2
2
|
import { getNestedDeclarations } from "../../declarations/Declaration.js";
|
|
3
3
|
import { NodeKind } from "../../Node.js";
|
|
4
4
|
import { formatValue, getReferencesForType, removeParentKey, resolveTypeArgumentsInType, serializeType, validate, } from "../Type.js";
|
|
@@ -74,7 +74,9 @@ export const getReferencesForEnumType = (type, value) => typeof value === "objec
|
|
|
74
74
|
value[discriminatorKey] in type.values &&
|
|
75
75
|
type.values[value[discriminatorKey]]?.type == null &&
|
|
76
76
|
value[discriminatorKey] in value
|
|
77
|
-
? getReferencesForType(
|
|
77
|
+
? getReferencesForType(
|
|
78
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
79
|
+
type.values[value[discriminatorKey]].type, value[value[discriminatorKey]])
|
|
78
80
|
: [];
|
|
79
81
|
export const formatEnumType = (type, value) => {
|
|
80
82
|
if (typeof value === "object" &&
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { ObjectConstraints } from "
|
|
2
|
-
import { GetNestedDeclarations } from "../../declarations/Declaration.js";
|
|
3
|
-
import { GetReferences, Node,
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
type
|
|
1
|
+
import type { ObjectConstraints } from "../../../../shared/validation/object.js";
|
|
2
|
+
import type { GetNestedDeclarations } from "../../declarations/Declaration.js";
|
|
3
|
+
import type { GetReferences, Node, Serializer } from "../../Node.js";
|
|
4
|
+
import { NodeKind } from "../../Node.js";
|
|
5
|
+
import type { Validator } from "../../validation/type.js";
|
|
6
|
+
import type { BaseType, SerializedBaseType, SerializedType, StructureFormatter, Type } from "../Type.js";
|
|
7
|
+
type TConstraint = Record<string, MemberDecl>;
|
|
7
8
|
export interface ObjectType<T extends TConstraint = TConstraint> extends BaseType, ObjectConstraints {
|
|
8
9
|
kind: NodeKind["ObjectType"];
|
|
9
10
|
properties: T;
|
|
10
11
|
}
|
|
11
|
-
type TSerializedConstraint = Record<string, SerializedMemberDecl
|
|
12
|
+
type TSerializedConstraint = Record<string, SerializedMemberDecl>;
|
|
12
13
|
export interface SerializedObjectType<T extends TSerializedConstraint = TSerializedConstraint> extends SerializedBaseType, ObjectConstraints {
|
|
13
14
|
kind: NodeKind["ObjectType"];
|
|
14
15
|
properties: T;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { sortObjectKeys } from "
|
|
2
|
-
import { parallelizeErrors } from "
|
|
3
|
-
import { validateObjectConstraints } from "
|
|
1
|
+
import { sortObjectKeys } from "../../../../shared/utils/object.js";
|
|
2
|
+
import { parallelizeErrors } from "../../../../shared/utils/validation.js";
|
|
3
|
+
import { validateObjectConstraints } from "../../../../shared/validation/object.js";
|
|
4
4
|
import { wrapErrorsIfAny } from "../../../utils/error.js";
|
|
5
5
|
import { getNestedDeclarations } from "../../declarations/Declaration.js";
|
|
6
6
|
import { NodeKind } from "../../Node.js";
|
|
@@ -19,6 +19,7 @@ export const ObjectType = (properties, options = {}) => {
|
|
|
19
19
|
if (!keyPattern.test(key)) {
|
|
20
20
|
throw new TypeError(`Invalid object key "${key}". Object keys must not start with an underscore and may only contain letters, digits and underscores. (Pattern: ${keyPattern.source})`);
|
|
21
21
|
}
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
22
23
|
properties[key].type.parent = type;
|
|
23
24
|
});
|
|
24
25
|
return type;
|
|
@@ -34,6 +35,7 @@ export const validateObjectType = (helpers, type, value) => {
|
|
|
34
35
|
return parallelizeErrors([
|
|
35
36
|
...validateObjectConstraints(type, expectedKeys, value),
|
|
36
37
|
...expectedKeys.map(key => {
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
37
39
|
const prop = type.properties[key];
|
|
38
40
|
if (prop.isRequired && !(key in value)) {
|
|
39
41
|
return TypeError(`missing required property "${key}"`);
|
|
@@ -68,7 +70,9 @@ export const serializeObjectType = type => ({
|
|
|
68
70
|
])),
|
|
69
71
|
});
|
|
70
72
|
export const getReferencesForObjectType = (type, value) => typeof value === "object" && value !== null
|
|
71
|
-
? Object.entries(value).flatMap(([key, propValue]) =>
|
|
73
|
+
? Object.entries(value).flatMap(([key, propValue]) =>
|
|
74
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
75
|
+
key in type.properties ? getReferencesForType(type.properties[key].type, propValue) : [])
|
|
72
76
|
: [];
|
|
73
77
|
export const formatObjectValue = (type, value) => typeof value === "object" && value !== null && !Array.isArray(value)
|
|
74
78
|
? sortObjectKeys(value, Object.keys(type.properties))
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { GetReferences, Node,
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import type { GetReferences, Node, Serializer } from "../../Node.js";
|
|
2
|
+
import { NodeKind } from "../../Node.js";
|
|
3
|
+
import type { Validator } from "../../validation/type.js";
|
|
4
|
+
import type { BaseType, SerializedBaseType, StructureFormatter } from "../Type.js";
|
|
4
5
|
export interface BooleanType extends BaseType {
|
|
5
6
|
kind: NodeKind["BooleanType"];
|
|
6
7
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { DateConstraints } from "
|
|
2
|
-
import { GetReferences, Node,
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import type { DateConstraints } from "../../../../shared/validation/date.js";
|
|
2
|
+
import type { GetReferences, Node, Serializer } from "../../Node.js";
|
|
3
|
+
import { NodeKind } from "../../Node.js";
|
|
4
|
+
import type { Validator } from "../../validation/type.js";
|
|
5
|
+
import type { BaseType, SerializedBaseType, StructureFormatter } from "../Type.js";
|
|
5
6
|
export interface DateType extends BaseType, DateConstraints {
|
|
6
7
|
kind: NodeKind["DateType"];
|
|
7
8
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { validateDateConstraints } from "
|
|
1
|
+
import { validateDateConstraints } from "../../../../shared/validation/date.js";
|
|
2
2
|
import { NodeKind } from "../../Node.js";
|
|
3
3
|
import { removeParentKey } from "../Type.js";
|
|
4
4
|
export const DateType = (options) => ({
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { RangeBound } from "
|
|
2
|
-
import { GetReferences, Node,
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import type { RangeBound } from "../../../../shared/validation/number.js";
|
|
2
|
+
import type { GetReferences, Node, Serializer } from "../../Node.js";
|
|
3
|
+
import { NodeKind } from "../../Node.js";
|
|
4
|
+
import type { Validator } from "../../validation/type.js";
|
|
5
|
+
import type { BaseType, SerializedBaseType, StructureFormatter } from "../Type.js";
|
|
5
6
|
export interface FloatType extends BaseType {
|
|
6
7
|
kind: NodeKind["FloatType"];
|
|
7
8
|
minimum?: RangeBound;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { validateNumberConstraints } from "
|
|
1
|
+
import { validateNumberConstraints } from "../../../../shared/validation/number.js";
|
|
2
2
|
import { NodeKind } from "../../Node.js";
|
|
3
3
|
import { removeParentKey } from "../Type.js";
|
|
4
4
|
export const FloatType = (options = {}) => ({
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { RangeBound } from "
|
|
2
|
-
import { GetReferences, Node,
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import type { RangeBound } from "../../../../shared/validation/number.js";
|
|
2
|
+
import type { GetReferences, Node, Serializer } from "../../Node.js";
|
|
3
|
+
import { NodeKind } from "../../Node.js";
|
|
4
|
+
import type { Validator } from "../../validation/type.js";
|
|
5
|
+
import type { BaseType, SerializedBaseType, StructureFormatter } from "../Type.js";
|
|
5
6
|
export interface IntegerType extends BaseType {
|
|
6
7
|
kind: NodeKind["IntegerType"];
|
|
7
8
|
minimum?: RangeBound;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { validateNumberConstraints } from "
|
|
1
|
+
import { validateNumberConstraints } from "../../../../shared/validation/number.js";
|
|
2
2
|
import { NodeKind } from "../../Node.js";
|
|
3
3
|
import { validateOption } from "../../validation/options.js";
|
|
4
4
|
import { removeParentKey } from "../Type.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FloatType, SerializedFloatType } from "./FloatType.js";
|
|
2
|
-
import { IntegerType, SerializedIntegerType } from "./IntegerType.js";
|
|
1
|
+
import type { FloatType, SerializedFloatType } from "./FloatType.js";
|
|
2
|
+
import type { IntegerType, SerializedIntegerType } from "./IntegerType.js";
|
|
3
3
|
export type NumericType = FloatType | IntegerType;
|
|
4
4
|
export type SerializedNumericType = SerializedFloatType | SerializedIntegerType;
|
|
5
5
|
export * from "./FloatType.js";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { BooleanType, SerializedBooleanType } from "./BooleanType.js";
|
|
2
|
+
import type { DateType, SerializedDateType } from "./DateType.js";
|
|
3
|
+
import type { NumericType, SerializedNumericType } from "./NumericType.js";
|
|
4
|
+
import type { SerializedStringType, StringType } from "./StringType.js";
|
|
5
|
+
export type PrimitiveType = BooleanType | DateType | NumericType | StringType;
|
|
6
|
+
export type SerializedPrimitiveType = SerializedBooleanType | SerializedDateType | SerializedNumericType | SerializedStringType;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { StringConstraints } from "
|
|
2
|
-
import { GetReferences, Node,
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import type { StringConstraints } from "../../../../shared/validation/string.js";
|
|
2
|
+
import type { GetReferences, Node, Serializer } from "../../Node.js";
|
|
3
|
+
import { NodeKind } from "../../Node.js";
|
|
4
|
+
import type { Validator } from "../../validation/type.js";
|
|
5
|
+
import type { BaseType, SerializedBaseType, StructureFormatter } from "../Type.js";
|
|
5
6
|
export interface StringType extends BaseType, StringConstraints {
|
|
6
7
|
kind: NodeKind["StringType"];
|
|
7
8
|
pattern?: RegExp;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { validateStringConstraints } from "
|
|
1
|
+
import { validateStringConstraints } from "../../../../shared/validation/string.js";
|
|
2
2
|
import { NodeKind } from "../../Node.js";
|
|
3
3
|
import { removeParentKey } from "../Type.js";
|
|
4
4
|
export const StringType = (options = {}) => ({
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { GetNestedDeclarations, SerializedTypeArguments, TypeArguments } from "../../declarations/Declaration.js";
|
|
2
|
-
import { EnumDecl } from "../../declarations/EnumDecl.js";
|
|
3
|
-
import { TypeAliasDecl } from "../../declarations/TypeAliasDecl.js";
|
|
4
|
-
import { GetReferences, Node,
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
1
|
+
import type { GetNestedDeclarations, SerializedTypeArguments, TypeArguments } from "../../declarations/Declaration.js";
|
|
2
|
+
import type { EnumDecl } from "../../declarations/EnumDecl.js";
|
|
3
|
+
import type { TypeAliasDecl } from "../../declarations/TypeAliasDecl.js";
|
|
4
|
+
import type { GetReferences, Node, Serializer } from "../../Node.js";
|
|
5
|
+
import { NodeKind } from "../../Node.js";
|
|
6
|
+
import type { SerializedTypeParameter, TypeParameter } from "../../TypeParameter.js";
|
|
7
|
+
import type { Validator } from "../../validation/type.js";
|
|
8
|
+
import type { EnumCaseDecl } from "../generic/EnumType.js";
|
|
9
|
+
import type { BaseType, SerializedBaseType, StructureFormatter, Type } from "../Type.js";
|
|
9
10
|
type TConstraint<Params extends TypeParameter[]> = TypeAliasDecl<string, Type, Params> | EnumDecl<string, Record<string, EnumCaseDecl>, Params>;
|
|
10
11
|
export interface IncludeIdentifierType<Params extends TypeParameter[] = TypeParameter[], T extends TConstraint<Params> = TConstraint<Params>> extends BaseType {
|
|
11
12
|
kind: NodeKind["IncludeIdentifierType"];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getNestedDeclarations, getReferencesForDecl, resolveTypeArgumentsInDecl, validateDecl, } from "../../declarations/Declaration.js";
|
|
2
2
|
import { NodeKind } from "../../Node.js";
|
|
3
3
|
import { formatEnumType } from "../generic/EnumType.js";
|
|
4
|
-
import { formatValue, removeParentKey, resolveTypeArgumentsInType, serializeType
|
|
4
|
+
import { formatValue, removeParentKey, resolveTypeArgumentsInType, serializeType } from "../Type.js";
|
|
5
5
|
export const GenIncludeIdentifierType = (reference, args) => ({
|
|
6
6
|
kind: NodeKind.IncludeIdentifierType,
|
|
7
7
|
reference,
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { Lazy } from "
|
|
2
|
-
import { GetNestedDeclarations } from "../../declarations/Declaration.js";
|
|
3
|
-
import { EntityDecl } from "../../declarations/EntityDecl.js";
|
|
4
|
-
import { GetReferences, Node,
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
type
|
|
1
|
+
import { Lazy } from "../../../../shared/utils/lazy.js";
|
|
2
|
+
import type { GetNestedDeclarations } from "../../declarations/Declaration.js";
|
|
3
|
+
import type { EntityDecl } from "../../declarations/EntityDecl.js";
|
|
4
|
+
import type { GetReferences, Node, Serializer } from "../../Node.js";
|
|
5
|
+
import { NodeKind } from "../../Node.js";
|
|
6
|
+
import type { Validator } from "../../validation/type.js";
|
|
7
|
+
import type { MemberDecl, ObjectType, SerializedMemberDecl, SerializedObjectType } from "../generic/ObjectType.js";
|
|
8
|
+
import type { BaseType, SerializedBaseType, StructureFormatter, Type } from "../Type.js";
|
|
9
|
+
type TConstraint = Record<string, MemberDecl>;
|
|
9
10
|
export interface NestedEntityMapType<Name extends string = string, T extends TConstraint = TConstraint> extends BaseType {
|
|
10
11
|
kind: NodeKind["NestedEntityMapType"];
|
|
11
12
|
name: Name;
|
|
@@ -13,7 +14,7 @@ export interface NestedEntityMapType<Name extends string = string, T extends TCo
|
|
|
13
14
|
secondaryEntity: EntityDecl;
|
|
14
15
|
type: Lazy<ObjectType<T>>;
|
|
15
16
|
}
|
|
16
|
-
type TSerializedConstraint = Record<string, SerializedMemberDecl
|
|
17
|
+
type TSerializedConstraint = Record<string, SerializedMemberDecl>;
|
|
17
18
|
export interface SerializedNestedEntityMapType<Name extends string = string, T extends TSerializedConstraint = TSerializedConstraint> extends SerializedBaseType {
|
|
18
19
|
kind: NodeKind["NestedEntityMapType"];
|
|
19
20
|
name: Name;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Lazy } from "../../../../shared/utils/lazy.js";
|
|
2
|
+
import { sortObjectKeysAlphabetically } from "../../../../shared/utils/object.js";
|
|
3
|
+
import { parallelizeErrors } from "../../../../shared/utils/validation.js";
|
|
3
4
|
import { wrapErrorsIfAny } from "../../../utils/error.js";
|
|
4
|
-
import { Lazy } from "../../../utils/lazy.js";
|
|
5
5
|
import { NodeKind } from "../../Node.js";
|
|
6
6
|
import { getNestedDeclarationsInObjectType, getReferencesForObjectType, resolveTypeArgumentsInObjectType, serializeObjectType, validateObjectType, } from "../generic/ObjectType.js";
|
|
7
|
-
import { removeParentKey
|
|
7
|
+
import { removeParentKey } from "../Type.js";
|
|
8
8
|
export const NestedEntityMapType = (options) => {
|
|
9
9
|
const nestedEntityMapType = {
|
|
10
10
|
...options,
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { GetNestedDeclarations } from "../../declarations/Declaration.js";
|
|
2
|
-
import { EntityDecl } from "../../declarations/EntityDecl.js";
|
|
3
|
-
import { GetReferences, Node,
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import type { GetNestedDeclarations } from "../../declarations/Declaration.js";
|
|
2
|
+
import type { EntityDecl } from "../../declarations/EntityDecl.js";
|
|
3
|
+
import type { GetReferences, Node, Serializer } from "../../Node.js";
|
|
4
|
+
import { NodeKind } from "../../Node.js";
|
|
5
|
+
import type { Validator } from "../../validation/type.js";
|
|
6
|
+
import type { BaseType, SerializedBaseType, StructureFormatter, Type } from "../Type.js";
|
|
6
7
|
export interface ReferenceIdentifierType extends BaseType {
|
|
7
8
|
kind: NodeKind["ReferenceIdentifierType"];
|
|
8
9
|
entity: EntityDecl;
|
|
@@ -16,7 +17,7 @@ export { ReferenceIdentifierType as ReferenceIdentifier };
|
|
|
16
17
|
export declare const isReferenceIdentifierType: (node: Node) => node is ReferenceIdentifierType;
|
|
17
18
|
export declare const getNestedDeclarationsInReferenceIdentifierType: GetNestedDeclarations<ReferenceIdentifierType>;
|
|
18
19
|
export declare const validateReferenceIdentifierType: Validator<ReferenceIdentifierType>;
|
|
19
|
-
export declare const resolveTypeArgumentsInReferenceIdentifierType:
|
|
20
|
+
export declare const resolveTypeArgumentsInReferenceIdentifierType: (_args: Record<string, Type>, type: ReferenceIdentifierType) => ReferenceIdentifierType;
|
|
20
21
|
export declare const serializeReferenceIdentifierType: Serializer<ReferenceIdentifierType, SerializedReferenceIdentifierType>;
|
|
21
22
|
export declare const getReferencesForReferenceIdentifierType: GetReferences<ReferenceIdentifierType>;
|
|
22
23
|
export declare const formatReferenceIdentifierValue: StructureFormatter<ReferenceIdentifierType>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getNestedDeclarations } from "../../declarations/Declaration.js";
|
|
2
2
|
import { createEntityIdentifierType } from "../../declarations/EntityDecl.js";
|
|
3
3
|
import { NodeKind } from "../../Node.js";
|
|
4
|
-
import { removeParentKey, validate
|
|
4
|
+
import { removeParentKey, validate } from "../Type.js";
|
|
5
5
|
export const ReferenceIdentifierType = (entity) => ({
|
|
6
6
|
kind: NodeKind.ReferenceIdentifierType,
|
|
7
7
|
entity,
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { GetReferences, Node, Serializer } from "../../Node.js";
|
|
2
|
+
import { NodeKind } from "../../Node.js";
|
|
3
|
+
import type { SerializedTypeParameter, TypeParameter } from "../../TypeParameter.js";
|
|
4
|
+
import type { Validator } from "../../validation/type.js";
|
|
5
|
+
import type { BaseType, SerializedBaseType, StructureFormatter, Type } from "../Type.js";
|
|
6
|
+
type TConstraint = TypeParameter;
|
|
7
|
+
export interface TypeArgumentType<T extends TConstraint = TConstraint> extends BaseType {
|
|
8
|
+
kind: NodeKind["TypeArgumentType"];
|
|
9
|
+
argument: T;
|
|
10
|
+
}
|
|
11
|
+
type TSerializedConstraint = SerializedTypeParameter;
|
|
12
|
+
export interface SerializedTypeArgumentType<T extends TSerializedConstraint = TSerializedConstraint> extends SerializedBaseType {
|
|
13
|
+
kind: NodeKind["TypeArgumentType"];
|
|
14
|
+
argument: T;
|
|
15
|
+
}
|
|
16
|
+
export declare const TypeArgumentType: <T extends TConstraint>(argument: T) => TypeArgumentType<T>;
|
|
17
|
+
export { TypeArgumentType as TypeArgument };
|
|
18
|
+
export declare const isTypeArgumentType: (node: Node) => node is TypeArgumentType;
|
|
19
|
+
export declare const validateTypeArgumentType: Validator<TypeArgumentType>;
|
|
20
|
+
export declare const resolveTypeArgumentsInTypeArgumentType: <T extends TConstraint, Args extends Record<string, Type>>(args: Args, type: TypeArgumentType<T>) => Args[T["name"]];
|
|
21
|
+
export declare const serializeTypeArgumentType: Serializer<TypeArgumentType, SerializedTypeArgumentType>;
|
|
22
|
+
export declare const getReferencesForTypeArgumentType: GetReferences<TypeArgumentType>;
|
|
23
|
+
export declare const formatTypeArgumentValue: StructureFormatter<TypeArgumentType>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { NodeKind } from "../../Node.js";
|
|
2
|
+
import { serializeTypeParameter } from "../../TypeParameter.js";
|
|
3
|
+
import { removeParentKey } from "../Type.js";
|
|
4
|
+
export const TypeArgumentType = (argument) => ({
|
|
5
|
+
kind: NodeKind.TypeArgumentType,
|
|
6
|
+
argument,
|
|
7
|
+
});
|
|
8
|
+
export { TypeArgumentType as TypeArgument };
|
|
9
|
+
export const isTypeArgumentType = (node) => node.kind === NodeKind.TypeArgumentType;
|
|
10
|
+
export const validateTypeArgumentType = (_helpers, type, _value) => {
|
|
11
|
+
throw new TypeError(`generic argument "${type.argument.name}" has not been replaced with a concrete type`);
|
|
12
|
+
};
|
|
13
|
+
export const resolveTypeArgumentsInTypeArgumentType = (args, type) => args[type.argument.name];
|
|
14
|
+
export const serializeTypeArgumentType = type => ({
|
|
15
|
+
...removeParentKey(type),
|
|
16
|
+
argument: serializeTypeParameter(type.argument),
|
|
17
|
+
});
|
|
18
|
+
export const getReferencesForTypeArgumentType = (_type, _value) => [];
|
|
19
|
+
export const formatTypeArgumentValue = (_type, value) => value;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Validators } from "../Node.js";
|
|
2
|
+
import type { Type } from "../types/Type.js";
|
|
3
|
+
export type ValidatorHelpers = Validators;
|
|
4
|
+
export type Validator<T extends Type, Args extends unknown[] = []> = (helpers: ValidatorHelpers, type: T, value: unknown, ...args: Args) => Error[];
|