tsondb 0.2.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/node/renderers/jsonschema/index.d.ts +6 -0
- package/lib/node/renderers/jsonschema/index.js +35 -0
- package/lib/node/renderers/jsonschema/render.d.ts +9 -0
- package/lib/{renderers → node/renderers}/jsonschema/render.js +42 -23
- package/lib/node/renderers/ts/index.d.ts +6 -0
- package/lib/node/renderers/ts/index.js +42 -0
- package/lib/{renderers → node/renderers}/ts/render.d.ts +3 -1
- package/lib/node/renderers/ts/render.js +136 -0
- package/lib/{schema → node/schema}/Node.d.ts +5 -4
- package/lib/{schema → node/schema}/Node.js +11 -6
- 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 +11 -10
- package/lib/{schema → node/schema}/declarations/Declaration.js +10 -4
- package/lib/{schema → node/schema}/declarations/EntityDecl.d.ts +13 -9
- package/lib/{schema → node/schema}/declarations/EntityDecl.js +2 -2
- package/lib/{schema → node/schema}/declarations/EnumDecl.d.ts +11 -26
- package/lib/node/schema/declarations/EnumDecl.js +52 -0
- 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 -3
- package/lib/{schema → node/schema}/index.js +3 -3
- package/lib/node/schema/types/Type.d.ts +48 -0
- package/lib/{schema → node/schema}/types/Type.js +90 -28
- package/lib/{schema → node/schema}/types/generic/ArrayType.d.ts +6 -4
- package/lib/{schema → node/schema}/types/generic/ArrayType.js +5 -4
- package/lib/node/schema/types/generic/EnumType.d.ts +39 -0
- package/lib/node/schema/types/generic/EnumType.js +98 -0
- package/lib/{schema → node/schema}/types/generic/ObjectType.d.ts +9 -7
- package/lib/{schema → node/schema}/types/generic/ObjectType.js +11 -3
- package/lib/{schema → node/schema}/types/primitives/BooleanType.d.ts +5 -3
- package/lib/{schema → node/schema}/types/primitives/BooleanType.js +1 -0
- package/lib/{schema → node/schema}/types/primitives/DateType.d.ts +6 -4
- package/lib/{schema → node/schema}/types/primitives/DateType.js +2 -1
- package/lib/{schema → node/schema}/types/primitives/FloatType.d.ts +6 -4
- package/lib/{schema → node/schema}/types/primitives/FloatType.js +2 -1
- package/lib/{schema → node/schema}/types/primitives/IntegerType.d.ts +6 -4
- package/lib/{schema → node/schema}/types/primitives/IntegerType.js +2 -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 +6 -4
- package/lib/{schema → node/schema}/types/primitives/StringType.js +2 -1
- package/lib/{schema → node/schema}/types/references/IncludeIdentifierType.d.ts +11 -8
- package/lib/{schema → node/schema}/types/references/IncludeIdentifierType.js +15 -2
- package/lib/{schema → node/schema}/types/references/NestedEntityMapType.d.ts +11 -9
- package/lib/{schema → node/schema}/types/references/NestedEntityMapType.js +6 -2
- package/lib/{schema → node/schema}/types/references/ReferenceIdentifierType.d.ts +8 -6
- package/lib/{schema → node/schema}/types/references/ReferenceIdentifierType.js +1 -0
- 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/node/server/api/declarations.d.ts +1 -0
- package/lib/node/server/api/declarations.js +154 -0
- package/lib/node/server/api/git.d.ts +1 -0
- package/lib/node/server/api/git.js +178 -0
- package/lib/node/server/api/index.d.ts +1 -0
- package/lib/node/server/api/index.js +8 -0
- package/lib/node/server/api/instanceOperations.d.ts +6 -0
- package/lib/node/server/api/instanceOperations.js +91 -0
- package/lib/node/server/api/instances.d.ts +1 -0
- package/lib/node/server/api/instances.js +27 -0
- package/lib/node/server/index.d.ts +28 -0
- package/lib/node/server/index.js +53 -0
- package/lib/node/server/init.d.ts +5 -0
- package/lib/node/server/init.js +56 -0
- package/lib/{utils → node/utils}/error.js +4 -1
- package/lib/node/utils/git.d.ts +3 -0
- package/lib/node/utils/git.js +12 -0
- package/lib/node/utils/instances.d.ts +5 -0
- package/lib/node/utils/instances.js +21 -0
- package/lib/node/utils/path.d.ts +1 -0
- package/lib/node/utils/path.js +2 -0
- package/lib/node/utils/references.d.ts +7 -0
- package/lib/node/utils/references.js +40 -0
- package/lib/node/utils/render.d.ts +9 -0
- package/lib/node/utils/render.js +34 -0
- package/lib/shared/api.d.ts +19 -2
- package/lib/shared/utils/array.d.ts +19 -0
- package/lib/shared/utils/array.js +30 -0
- package/lib/shared/utils/displayName.d.ts +1 -1
- package/lib/shared/utils/displayName.js +4 -2
- package/lib/shared/utils/git.d.ts +12 -0
- package/lib/shared/utils/git.js +98 -0
- package/lib/shared/utils/instances.d.ts +10 -0
- package/lib/shared/utils/instances.js +8 -1
- package/lib/{utils → shared/utils}/lazy.js +1 -1
- package/lib/shared/utils/markdown.d.ts +14 -0
- package/lib/shared/utils/markdown.js +42 -0
- package/lib/shared/utils/object.d.ts +4 -0
- package/lib/shared/utils/object.js +5 -0
- package/lib/{utils → shared/utils}/result.js +2 -2
- package/lib/shared/utils/string.d.ts +1 -0
- package/lib/shared/utils/string.js +16 -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/web/api.d.ts +24 -0
- package/lib/web/api.js +204 -0
- package/lib/web/components/Git.d.ts +2 -0
- package/lib/web/components/Git.js +160 -0
- package/lib/{client → web}/components/Layout.d.ts +1 -1
- package/lib/{client → web}/components/Layout.js +2 -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 +8 -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/components/typeInputs/utils/EnumDeclField.js → web/components/typeInputs/EnumTypeInput.js} +11 -11
- 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/web/components/typeInputs/IncludeIdentifierTypeInput.js +9 -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 +6 -3
- package/lib/{client → web}/components/typeInputs/utils/Markdown.d.ts +1 -1
- package/lib/web/components/typeInputs/utils/Markdown.js +26 -0
- 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/web/hooks/useAPIResource.js +2 -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/web/hooks/useMappedAPIResource.js +17 -0
- 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/web/routes/Entity.js +43 -0
- package/lib/web/routes/Home.d.ts +2 -0
- package/lib/web/routes/Home.js +9 -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 +14 -17
- package/package.json +35 -15
- package/public/css/styles.css +200 -1
- package/lib/ModelContainer.d.ts +0 -17
- package/lib/ModelContainer.js +0 -63
- package/lib/client/api.d.ts +0 -11
- package/lib/client/api.js +0 -83
- 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/GenericTypeArgumentIdentifierTypeInput.d.ts +0 -7
- package/lib/client/components/typeInputs/IncludeIdentifierTypeInput.d.ts +0 -13
- package/lib/client/components/typeInputs/IncludeIdentifierTypeInput.js +0 -18
- 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/components/typeInputs/utils/EnumDeclField.d.ts +0 -13
- package/lib/client/components/typeInputs/utils/Markdown.js +0 -57
- package/lib/client/routes/Entity.d.ts +0 -2
- package/lib/client/routes/Entity.js +0 -47
- package/lib/client/routes/Home.d.ts +0 -2
- package/lib/client/routes/Home.js +0 -18
- package/lib/client/utils/typeSkeleton.d.ts +0 -3
- package/lib/renderers/jsonschema/index.d.ts +0 -6
- package/lib/renderers/jsonschema/index.js +0 -12
- package/lib/renderers/jsonschema/render.d.ts +0 -5
- package/lib/renderers/ts/index.d.ts +0 -6
- package/lib/renderers/ts/index.js +0 -11
- package/lib/renderers/ts/render.js +0 -112
- package/lib/schema/declarations/EnumDecl.js +0 -115
- package/lib/schema/types/Type.d.ts +0 -42
- package/lib/schema/types/primitives/PrimitiveType.d.ts +0 -6
- package/lib/schema/types/references/GenericArgumentIdentifierType.d.ts +0 -21
- package/lib/schema/types/references/GenericArgumentIdentifierType.js +0 -18
- package/lib/schema/validation/type.d.ts +0 -4
- package/lib/server/index.d.ts +0 -8
- package/lib/server/index.js +0 -207
- package/lib/server/instanceOperations.d.ts +0 -7
- package/lib/server/instanceOperations.js +0 -67
- package/lib/tsconfig.tsbuildinfo +0 -1
- package/lib/utils/instances.d.ts +0 -4
- package/lib/utils/instances.js +0 -12
- package/lib/utils/object.d.ts +0 -3
- package/lib/utils/object.js +0 -1
- package/lib/utils/render.d.ts +0 -4
- package/lib/utils/render.js +0 -8
- /package/lib/{renderers → node/renderers}/Output.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/{utils → node/utils}/error.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/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}/index.d.ts +0 -0
- /package/lib/{client → web}/index.js +0 -0
- /package/lib/{client → web}/routes/NotFound.js +0 -0
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import { Lazy } from "
|
|
2
|
-
import { Leaves } from "
|
|
3
|
-
import { GetReferences, Node,
|
|
4
|
-
import {
|
|
1
|
+
import { Lazy } from "../../../shared/utils/lazy.js";
|
|
2
|
+
import type { Leaves } from "../../../shared/utils/object.js";
|
|
3
|
+
import type { GetReferences, Node, Serializer } from "../Node.js";
|
|
4
|
+
import { NodeKind } from "../Node.js";
|
|
5
|
+
import type { MemberDecl, ObjectType, SerializedObjectType } from "../types/generic/ObjectType.js";
|
|
5
6
|
import { StringType } from "../types/primitives/StringType.js";
|
|
6
|
-
import { AsType, SerializedAsType
|
|
7
|
-
import { ValidatorHelpers } from "../validation/type.js";
|
|
8
|
-
import { BaseDecl, GetNestedDeclarations, SerializedBaseDecl } from "./Declaration.js";
|
|
7
|
+
import type { AsType, SerializedAsType } from "../types/Type.js";
|
|
8
|
+
import type { ValidatorHelpers } from "../validation/type.js";
|
|
9
|
+
import type { BaseDecl, GetNestedDeclarations, SerializedBaseDecl } from "./Declaration.js";
|
|
9
10
|
import { TypeAliasDecl } from "./TypeAliasDecl.js";
|
|
10
11
|
export interface EntityDecl<Name extends string = string, T extends ObjectType = ObjectType> extends BaseDecl<Name, []> {
|
|
11
12
|
kind: NodeKind["EntityDecl"];
|
|
13
|
+
namePlural: string;
|
|
12
14
|
type: Lazy<T>;
|
|
13
15
|
/**
|
|
14
16
|
* @default "name"
|
|
@@ -27,6 +29,7 @@ export interface EntityDecl<Name extends string = string, T extends ObjectType =
|
|
|
27
29
|
}
|
|
28
30
|
export interface SerializedEntityDecl<Name extends string = string, T extends SerializedObjectType = SerializedObjectType> extends SerializedBaseDecl<Name, []> {
|
|
29
31
|
kind: NodeKind["EntityDecl"];
|
|
32
|
+
namePlural: string;
|
|
30
33
|
type: T;
|
|
31
34
|
/**
|
|
32
35
|
* @default "name"
|
|
@@ -45,6 +48,7 @@ export interface SerializedEntityDecl<Name extends string = string, T extends Se
|
|
|
45
48
|
}
|
|
46
49
|
export declare const EntityDecl: <Name extends string, T extends ObjectType>(sourceUrl: string, options: {
|
|
47
50
|
name: Name;
|
|
51
|
+
namePlural: string;
|
|
48
52
|
comment?: string;
|
|
49
53
|
type: () => T;
|
|
50
54
|
/**
|
|
@@ -67,10 +71,10 @@ export declare const isEntityDecl: (node: Node) => node is EntityDecl;
|
|
|
67
71
|
export declare const getNestedDeclarationsInEntityDecl: GetNestedDeclarations<EntityDecl>;
|
|
68
72
|
export declare const validateEntityDecl: (helpers: ValidatorHelpers, decl: EntityDecl, value: unknown) => Error[];
|
|
69
73
|
export declare const resolveTypeArgumentsInEntityDecl: (decl: EntityDecl) => EntityDecl;
|
|
70
|
-
export declare const addEphemeralUUIDToType: <T extends Record<string, MemberDecl
|
|
74
|
+
export declare const addEphemeralUUIDToType: <T extends Record<string, MemberDecl>>(decl: EntityDecl<string, ObjectType<T>>) => ObjectType<Omit<T, "id"> & {
|
|
71
75
|
id: MemberDecl<StringType, true>;
|
|
72
76
|
}>;
|
|
73
77
|
export declare const createEntityIdentifierType: () => StringType;
|
|
74
|
-
export declare const createEntityIdentifierTypeAsDecl: <Name extends string>(decl: EntityDecl<Name
|
|
78
|
+
export declare const createEntityIdentifierTypeAsDecl: <Name extends string>(decl: EntityDecl<Name>) => TypeAliasDecl<`${Name}_ID`, StringType, []>;
|
|
75
79
|
export declare const serializeEntityDecl: Serializer<EntityDecl, SerializedEntityDecl>;
|
|
76
80
|
export declare const getReferencesForEntityDecl: GetReferences<EntityDecl>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Lazy } from "
|
|
1
|
+
import { Lazy } from "../../../shared/utils/lazy.js";
|
|
2
2
|
import { NodeKind } from "../Node.js";
|
|
3
3
|
import { getNestedDeclarationsInObjectType, getReferencesForObjectType, Required, resolveTypeArgumentsInObjectType, serializeObjectType, } from "../types/generic/ObjectType.js";
|
|
4
4
|
import { StringType } from "../types/primitives/StringType.js";
|
|
5
5
|
import { validate } from "../types/Type.js";
|
|
6
|
-
import { validateDeclName
|
|
6
|
+
import { validateDeclName } from "./Declaration.js";
|
|
7
7
|
import { TypeAliasDecl } from "./TypeAliasDecl.js";
|
|
8
8
|
export const EntityDecl = (sourceUrl, options) => {
|
|
9
9
|
validateDeclName(options.name);
|
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
import { Lazy } from "
|
|
2
|
-
import { GetReferences, Node,
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
1
|
+
import { Lazy } from "../../../shared/utils/lazy.js";
|
|
2
|
+
import type { GetReferences, Node, Serializer } from "../Node.js";
|
|
3
|
+
import { NodeKind } from "../Node.js";
|
|
4
|
+
import type { SerializedTypeParameter, TypeParameter } from "../TypeParameter.js";
|
|
5
|
+
import type { EnumCaseDecl, SerializedEnumCaseDecl, SerializedEnumType } from "../types/generic/EnumType.js";
|
|
6
|
+
import { EnumType } from "../types/generic/EnumType.js";
|
|
7
|
+
import type { Type } from "../types/Type.js";
|
|
8
|
+
import type { ValidatorHelpers } from "../validation/type.js";
|
|
9
|
+
import type { BaseDecl, GetNestedDeclarations, SerializedBaseDecl, TypeArguments } from "./Declaration.js";
|
|
7
10
|
export interface EnumDecl<Name extends string = string, T extends Record<string, EnumCaseDecl> = Record<string, EnumCaseDecl>, Params extends TypeParameter[] = TypeParameter[]> extends BaseDecl<Name, Params> {
|
|
8
11
|
kind: NodeKind["EnumDecl"];
|
|
9
|
-
|
|
12
|
+
type: Lazy<EnumType<T>>;
|
|
10
13
|
isDeprecated?: boolean;
|
|
11
14
|
}
|
|
12
15
|
export interface SerializedEnumDecl<Name extends string = string, T extends Record<string, SerializedEnumCaseDecl> = Record<string, SerializedEnumCaseDecl>, Params extends SerializedTypeParameter[] = SerializedTypeParameter[]> extends SerializedBaseDecl<Name, Params> {
|
|
13
16
|
kind: NodeKind["EnumDecl"];
|
|
14
|
-
|
|
17
|
+
type: SerializedEnumType<T>;
|
|
15
18
|
isDeprecated?: boolean;
|
|
16
19
|
}
|
|
17
20
|
export declare const GenEnumDecl: <Name extends string, T extends Record<string, EnumCaseDecl>, Params extends TypeParameter[]>(sourceUrl: string, options: {
|
|
@@ -31,23 +34,5 @@ export declare const isEnumDecl: (node: Node) => node is EnumDecl;
|
|
|
31
34
|
export declare const getNestedDeclarationsInEnumDecl: GetNestedDeclarations<EnumDecl>;
|
|
32
35
|
export declare const validateEnumDecl: (helpers: ValidatorHelpers, decl: EnumDecl, args: Type[], value: unknown) => Error[];
|
|
33
36
|
export declare const resolveTypeArgumentsInEnumDecl: <Params extends TypeParameter[]>(decl: EnumDecl<string, Record<string, EnumCaseDecl>, Params>, args: TypeArguments<Params>) => EnumDecl<string, Record<string, EnumCaseDecl>, []>;
|
|
34
|
-
export interface EnumCaseDecl<T extends Type | null = Type | null> {
|
|
35
|
-
kind: NodeKind["EnumCaseDecl"];
|
|
36
|
-
type: T;
|
|
37
|
-
comment?: string;
|
|
38
|
-
isDeprecated?: boolean;
|
|
39
|
-
}
|
|
40
|
-
export interface SerializedEnumCaseDecl<T extends SerializedType | null = SerializedType | null> {
|
|
41
|
-
kind: NodeKind["EnumCaseDecl"];
|
|
42
|
-
type: T;
|
|
43
|
-
comment?: string;
|
|
44
|
-
isDeprecated?: boolean;
|
|
45
|
-
}
|
|
46
|
-
export declare const EnumCaseDecl: <T extends Type | null>(options: {
|
|
47
|
-
type: T;
|
|
48
|
-
comment?: string;
|
|
49
|
-
isDeprecated?: boolean;
|
|
50
|
-
}) => EnumCaseDecl<T>;
|
|
51
|
-
export { EnumCaseDecl as EnumCase };
|
|
52
37
|
export declare const serializeEnumDecl: Serializer<EnumDecl, SerializedEnumDecl>;
|
|
53
38
|
export declare const getReferencesForEnumDecl: GetReferences<EnumDecl>;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Lazy } from "../../../shared/utils/lazy.js";
|
|
2
|
+
import { NodeKind } from "../Node.js";
|
|
3
|
+
import { serializeTypeParameter } from "../TypeParameter.js";
|
|
4
|
+
import { EnumType, getNestedDeclarationsInEnumType, getReferencesForEnumType, resolveTypeArgumentsInEnumType, serializeEnumType, validateEnumType, } from "../types/generic/EnumType.js";
|
|
5
|
+
import { getTypeArgumentsRecord, validateDeclName } from "./Declaration.js";
|
|
6
|
+
export const GenEnumDecl = (sourceUrl, options) => {
|
|
7
|
+
validateDeclName(options.name);
|
|
8
|
+
const decl = {
|
|
9
|
+
...options,
|
|
10
|
+
kind: NodeKind.EnumDecl,
|
|
11
|
+
sourceUrl,
|
|
12
|
+
type: Lazy.of(() => {
|
|
13
|
+
const type = EnumType(options.values(...options.parameters));
|
|
14
|
+
type.parent = decl;
|
|
15
|
+
return type;
|
|
16
|
+
}),
|
|
17
|
+
};
|
|
18
|
+
return decl;
|
|
19
|
+
};
|
|
20
|
+
export { GenEnumDecl as GenEnum };
|
|
21
|
+
export const EnumDecl = (sourceUrl, options) => {
|
|
22
|
+
validateDeclName(options.name);
|
|
23
|
+
const decl = {
|
|
24
|
+
...options,
|
|
25
|
+
kind: NodeKind.EnumDecl,
|
|
26
|
+
sourceUrl,
|
|
27
|
+
parameters: [],
|
|
28
|
+
type: Lazy.of(() => {
|
|
29
|
+
const type = EnumType(options.values());
|
|
30
|
+
type.parent = decl;
|
|
31
|
+
return type;
|
|
32
|
+
}),
|
|
33
|
+
};
|
|
34
|
+
return decl;
|
|
35
|
+
};
|
|
36
|
+
export { EnumDecl as Enum };
|
|
37
|
+
export const isEnumDecl = (node) => node.kind === NodeKind.EnumDecl;
|
|
38
|
+
export const getNestedDeclarationsInEnumDecl = (addedDecls, decl) => getNestedDeclarationsInEnumType(addedDecls, decl.type.value);
|
|
39
|
+
export const validateEnumDecl = (helpers, decl, args, value) => validateEnumType(helpers, resolveTypeArgumentsInEnumType(getTypeArgumentsRecord(decl, args), decl.type.value), value);
|
|
40
|
+
export const resolveTypeArgumentsInEnumDecl = (decl, args) => {
|
|
41
|
+
const resolvedArgs = getTypeArgumentsRecord(decl, args);
|
|
42
|
+
return EnumDecl(decl.sourceUrl, {
|
|
43
|
+
...decl,
|
|
44
|
+
values: () => resolveTypeArgumentsInEnumType(resolvedArgs, decl.type.value).values,
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
export const serializeEnumDecl = decl => ({
|
|
48
|
+
...decl,
|
|
49
|
+
type: serializeEnumType(decl.type.value),
|
|
50
|
+
parameters: decl.parameters.map(param => serializeTypeParameter(param)),
|
|
51
|
+
});
|
|
52
|
+
export const getReferencesForEnumDecl = (decl, value) => getReferencesForEnumType(decl.type.value, value);
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { Lazy } from "
|
|
2
|
-
import { GetReferences, Node,
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
1
|
+
import { Lazy } from "../../../shared/utils/lazy.js";
|
|
2
|
+
import type { GetReferences, Node, Serializer } from "../Node.js";
|
|
3
|
+
import { NodeKind } from "../Node.js";
|
|
4
|
+
import type { SerializedTypeParameter, TypeParameter } from "../TypeParameter.js";
|
|
5
|
+
import type { SerializedType, Type } from "../types/Type.js";
|
|
6
|
+
import type { ValidatorHelpers } from "../validation/type.js";
|
|
7
|
+
import type { BaseDecl, GetNestedDeclarations, SerializedBaseDecl, TypeArguments } from "./Declaration.js";
|
|
7
8
|
export interface TypeAliasDecl<Name extends string = string, T extends Type = Type, Params extends TypeParameter[] = TypeParameter[]> extends BaseDecl<Name, Params> {
|
|
8
9
|
kind: NodeKind["TypeAliasDecl"];
|
|
9
10
|
type: Lazy<T>;
|
|
@@ -29,7 +30,7 @@ export declare const TypeAliasDecl: <Name extends string, T extends Type>(source
|
|
|
29
30
|
type: () => T;
|
|
30
31
|
}) => TypeAliasDecl<Name, T, []>;
|
|
31
32
|
export { TypeAliasDecl as TypeAlias };
|
|
32
|
-
export declare const isTypeAliasDecl: (node: Node) => node is TypeAliasDecl
|
|
33
|
+
export declare const isTypeAliasDecl: (node: Node) => node is TypeAliasDecl;
|
|
33
34
|
export declare const getNestedDeclarationsInTypeAliasDecl: GetNestedDeclarations<TypeAliasDecl>;
|
|
34
35
|
export declare const validateTypeAliasDecl: <Params extends TypeParameter[]>(helpers: ValidatorHelpers, decl: TypeAliasDecl<string, Type, Params>, args: TypeArguments<Params>, value: unknown) => Error[];
|
|
35
36
|
export declare const resolveTypeArgumentsInTypeAliasDecl: <Params extends TypeParameter[]>(decl: TypeAliasDecl<string, Type, Params>, args: TypeArguments<Params>) => TypeAliasDecl<string, Type, []>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Lazy } from "
|
|
1
|
+
import { Lazy } from "../../../shared/utils/lazy.js";
|
|
2
2
|
import { NodeKind } from "../Node.js";
|
|
3
|
-
import { serializeTypeParameter
|
|
3
|
+
import { serializeTypeParameter } from "../TypeParameter.js";
|
|
4
4
|
import { getReferencesForType, resolveTypeArgumentsInType, serializeType, validate, } from "../types/Type.js";
|
|
5
|
-
import { getNestedDeclarations, getTypeArgumentsRecord, validateDeclName
|
|
5
|
+
import { getNestedDeclarations, getTypeArgumentsRecord, validateDeclName } from "./Declaration.js";
|
|
6
6
|
export const GenTypeAliasDecl = (sourceUrl, options) => {
|
|
7
7
|
validateDeclName(options.name);
|
|
8
8
|
const decl = {
|
|
@@ -3,18 +3,19 @@ export * from "./declarations/EntityDecl.js";
|
|
|
3
3
|
export * from "./declarations/EnumDecl.js";
|
|
4
4
|
export * from "./declarations/TypeAliasDecl.js";
|
|
5
5
|
export * from "./Node.js";
|
|
6
|
-
export * from "./
|
|
6
|
+
export * from "./TypeParameter.js";
|
|
7
7
|
export * from "./types/generic/ArrayType.js";
|
|
8
|
+
export * from "./types/generic/EnumType.js";
|
|
8
9
|
export * from "./types/generic/ObjectType.js";
|
|
9
10
|
export * from "./types/primitives/BooleanType.js";
|
|
10
11
|
export * from "./types/primitives/DateType.js";
|
|
11
12
|
export * from "./types/primitives/FloatType.js";
|
|
12
13
|
export * from "./types/primitives/IntegerType.js";
|
|
13
14
|
export * from "./types/primitives/NumericType.js";
|
|
14
|
-
export * from "./types/primitives/PrimitiveType.js";
|
|
15
|
+
export type * from "./types/primitives/PrimitiveType.js";
|
|
15
16
|
export * from "./types/primitives/StringType.js";
|
|
16
|
-
export * from "./types/references/GenericArgumentIdentifierType.js";
|
|
17
17
|
export * from "./types/references/IncludeIdentifierType.js";
|
|
18
18
|
export * from "./types/references/NestedEntityMapType.js";
|
|
19
19
|
export * from "./types/references/ReferenceIdentifierType.js";
|
|
20
|
+
export * from "./types/references/TypeArgumentType.js";
|
|
20
21
|
export * from "./types/Type.js";
|
|
@@ -3,18 +3,18 @@ export * from "./declarations/EntityDecl.js";
|
|
|
3
3
|
export * from "./declarations/EnumDecl.js";
|
|
4
4
|
export * from "./declarations/TypeAliasDecl.js";
|
|
5
5
|
export * from "./Node.js";
|
|
6
|
-
export * from "./
|
|
6
|
+
export * from "./TypeParameter.js";
|
|
7
7
|
export * from "./types/generic/ArrayType.js";
|
|
8
|
+
export * from "./types/generic/EnumType.js";
|
|
8
9
|
export * from "./types/generic/ObjectType.js";
|
|
9
10
|
export * from "./types/primitives/BooleanType.js";
|
|
10
11
|
export * from "./types/primitives/DateType.js";
|
|
11
12
|
export * from "./types/primitives/FloatType.js";
|
|
12
13
|
export * from "./types/primitives/IntegerType.js";
|
|
13
14
|
export * from "./types/primitives/NumericType.js";
|
|
14
|
-
export * from "./types/primitives/PrimitiveType.js";
|
|
15
15
|
export * from "./types/primitives/StringType.js";
|
|
16
|
-
export * from "./types/references/GenericArgumentIdentifierType.js";
|
|
17
16
|
export * from "./types/references/IncludeIdentifierType.js";
|
|
18
17
|
export * from "./types/references/NestedEntityMapType.js";
|
|
19
18
|
export * from "./types/references/ReferenceIdentifierType.js";
|
|
19
|
+
export * from "./types/references/TypeArgumentType.js";
|
|
20
20
|
export * from "./types/Type.js";
|
|
@@ -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,17 +1,18 @@
|
|
|
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
|
-
import { getReferencesForArrayType, resolveTypeArgumentsInArrayType, serializeArrayType, validateArrayType, } from "./generic/ArrayType.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import { getReferencesForIncludeIdentifierType, resolveTypeArgumentsInIncludeIdentifierType, serializeIncludeIdentifierType, validateIncludeIdentifierType, } from "./references/IncludeIdentifierType.js";
|
|
13
|
-
import { getReferencesForNestedEntityMapType, resolveTypeArgumentsInNestedEntityMapType, serializeNestedEntityMapType, validateNestedEntityMapType, } from "./references/NestedEntityMapType.js";
|
|
14
|
-
import { getReferencesForReferenceIdentifierType, resolveTypeArgumentsInReferenceIdentifierType, serializeReferenceIdentifierType, validateReferenceIdentifierType, } from "./references/ReferenceIdentifierType.js";
|
|
4
|
+
import { formatArrayValue, getReferencesForArrayType, resolveTypeArgumentsInArrayType, serializeArrayType, validateArrayType, } from "./generic/ArrayType.js";
|
|
5
|
+
import { formatEnumType, getReferencesForEnumType, resolveTypeArgumentsInEnumType, serializeEnumType, validateEnumType, } from "./generic/EnumType.js";
|
|
6
|
+
import { formatObjectValue, getReferencesForObjectType, resolveTypeArgumentsInObjectType, serializeObjectType, validateObjectType, } from "./generic/ObjectType.js";
|
|
7
|
+
import { formatBooleanValue, getReferencesForBooleanType, serializeBooleanType, validateBooleanType, } from "./primitives/BooleanType.js";
|
|
8
|
+
import { formatDateValue, getReferencesForDateType, serializeDateType, validateDateType, } from "./primitives/DateType.js";
|
|
9
|
+
import { formatFloatValue, getReferencesForFloatType, serializeFloatType, validateFloatType, } from "./primitives/FloatType.js";
|
|
10
|
+
import { formatIntegerValue, getReferencesForIntegerType, serializeIntegerType, validateIntegerType, } from "./primitives/IntegerType.js";
|
|
11
|
+
import { formatStringValue, getReferencesForStringType, serializeStringType, validateStringType, } from "./primitives/StringType.js";
|
|
12
|
+
import { formatIncludeIdentifierValue, getReferencesForIncludeIdentifierType, resolveTypeArgumentsInIncludeIdentifierType, serializeIncludeIdentifierType, validateIncludeIdentifierType, } from "./references/IncludeIdentifierType.js";
|
|
13
|
+
import { formatNestedEntityMapValue, getReferencesForNestedEntityMapType, resolveTypeArgumentsInNestedEntityMapType, serializeNestedEntityMapType, validateNestedEntityMapType, } from "./references/NestedEntityMapType.js";
|
|
14
|
+
import { formatReferenceIdentifierValue, getReferencesForReferenceIdentifierType, resolveTypeArgumentsInReferenceIdentifierType, serializeReferenceIdentifierType, validateReferenceIdentifierType, } from "./references/ReferenceIdentifierType.js";
|
|
15
|
+
import { formatTypeArgumentValue, getReferencesForTypeArgumentType, resolveTypeArgumentsInTypeArgumentType, serializeTypeArgumentType, validateTypeArgumentType, } from "./references/TypeArgumentType.js";
|
|
15
16
|
export const validate = (helpers, type, value) => {
|
|
16
17
|
switch (type.kind) {
|
|
17
18
|
case NodeKind.ArrayType:
|
|
@@ -28,14 +29,16 @@ export const validate = (helpers, type, value) => {
|
|
|
28
29
|
return validateIntegerType(helpers, type, value);
|
|
29
30
|
case NodeKind.StringType:
|
|
30
31
|
return validateStringType(helpers, type, value);
|
|
31
|
-
case NodeKind.
|
|
32
|
-
return
|
|
32
|
+
case NodeKind.TypeArgumentType:
|
|
33
|
+
return validateTypeArgumentType(helpers, type, value);
|
|
33
34
|
case NodeKind.ReferenceIdentifierType:
|
|
34
35
|
return validateReferenceIdentifierType(helpers, type, value);
|
|
35
36
|
case NodeKind.IncludeIdentifierType:
|
|
36
37
|
return validateIncludeIdentifierType(helpers, type, value);
|
|
37
38
|
case NodeKind.NestedEntityMapType:
|
|
38
39
|
return validateNestedEntityMapType(helpers, type, value);
|
|
40
|
+
case NodeKind.EnumType:
|
|
41
|
+
return validateEnumType(helpers, type, value);
|
|
39
42
|
default:
|
|
40
43
|
return assertExhaustive(type);
|
|
41
44
|
}
|
|
@@ -52,14 +55,16 @@ export const resolveTypeArgumentsInType = (args, type) => {
|
|
|
52
55
|
case NodeKind.IntegerType:
|
|
53
56
|
case NodeKind.StringType:
|
|
54
57
|
return type;
|
|
55
|
-
case NodeKind.
|
|
56
|
-
return
|
|
58
|
+
case NodeKind.TypeArgumentType:
|
|
59
|
+
return resolveTypeArgumentsInTypeArgumentType(args, type);
|
|
57
60
|
case NodeKind.ReferenceIdentifierType:
|
|
58
61
|
return resolveTypeArgumentsInReferenceIdentifierType(args, type);
|
|
59
62
|
case NodeKind.IncludeIdentifierType:
|
|
60
63
|
return resolveTypeArgumentsInIncludeIdentifierType(args, type);
|
|
61
64
|
case NodeKind.NestedEntityMapType:
|
|
62
65
|
return resolveTypeArgumentsInNestedEntityMapType(args, type);
|
|
66
|
+
case NodeKind.EnumType:
|
|
67
|
+
return resolveTypeArgumentsInEnumType(args, type);
|
|
63
68
|
default:
|
|
64
69
|
return assertExhaustive(type);
|
|
65
70
|
}
|
|
@@ -68,22 +73,45 @@ export function walkTypeNodeTree(callbackFn, type) {
|
|
|
68
73
|
switch (type.kind) {
|
|
69
74
|
case NodeKind.ArrayType:
|
|
70
75
|
callbackFn(type);
|
|
71
|
-
|
|
76
|
+
{
|
|
77
|
+
walkTypeNodeTree(callbackFn, type.items);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
72
80
|
case NodeKind.ObjectType:
|
|
73
81
|
callbackFn(type);
|
|
74
|
-
|
|
82
|
+
{
|
|
83
|
+
Object.values(type.properties).forEach(prop => {
|
|
84
|
+
walkTypeNodeTree(callbackFn, prop.type);
|
|
85
|
+
});
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
75
88
|
case NodeKind.NestedEntityMapType:
|
|
76
89
|
callbackFn(type);
|
|
77
|
-
|
|
90
|
+
{
|
|
91
|
+
walkTypeNodeTree(callbackFn, type.type.value);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
78
94
|
case NodeKind.BooleanType:
|
|
79
95
|
case NodeKind.DateType:
|
|
80
96
|
case NodeKind.FloatType:
|
|
81
97
|
case NodeKind.IntegerType:
|
|
82
98
|
case NodeKind.StringType:
|
|
83
|
-
case NodeKind.
|
|
99
|
+
case NodeKind.TypeArgumentType:
|
|
84
100
|
case NodeKind.ReferenceIdentifierType:
|
|
85
|
-
case NodeKind.IncludeIdentifierType:
|
|
86
|
-
|
|
101
|
+
case NodeKind.IncludeIdentifierType: {
|
|
102
|
+
callbackFn(type);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
case NodeKind.EnumType:
|
|
106
|
+
callbackFn(type);
|
|
107
|
+
{
|
|
108
|
+
Object.values(type.values).forEach(value => {
|
|
109
|
+
if (value.type) {
|
|
110
|
+
walkTypeNodeTree(callbackFn, value.type);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
87
115
|
default:
|
|
88
116
|
return assertExhaustive(type);
|
|
89
117
|
}
|
|
@@ -100,10 +128,10 @@ export const getParentDecl = (type) => {
|
|
|
100
128
|
}
|
|
101
129
|
};
|
|
102
130
|
export const findTypeAtPath = (type, path) => {
|
|
103
|
-
|
|
131
|
+
const [head, ...tail] = path;
|
|
132
|
+
if (head === undefined) {
|
|
104
133
|
return type;
|
|
105
134
|
}
|
|
106
|
-
const [head, ...tail] = path;
|
|
107
135
|
if (type.kind === NodeKind.ObjectType) {
|
|
108
136
|
const prop = type.properties[head];
|
|
109
137
|
if (prop) {
|
|
@@ -131,14 +159,16 @@ export const serializeType = type => {
|
|
|
131
159
|
return serializeIntegerType(type);
|
|
132
160
|
case NodeKind.StringType:
|
|
133
161
|
return serializeStringType(type);
|
|
134
|
-
case NodeKind.
|
|
135
|
-
return
|
|
162
|
+
case NodeKind.TypeArgumentType:
|
|
163
|
+
return serializeTypeArgumentType(type);
|
|
136
164
|
case NodeKind.ReferenceIdentifierType:
|
|
137
165
|
return serializeReferenceIdentifierType(type);
|
|
138
166
|
case NodeKind.IncludeIdentifierType:
|
|
139
167
|
return serializeIncludeIdentifierType(type);
|
|
140
168
|
case NodeKind.NestedEntityMapType:
|
|
141
169
|
return serializeNestedEntityMapType(type);
|
|
170
|
+
case NodeKind.EnumType:
|
|
171
|
+
return serializeEnumType(type);
|
|
142
172
|
default:
|
|
143
173
|
return assertExhaustive(type);
|
|
144
174
|
}
|
|
@@ -163,14 +193,46 @@ export const getReferencesForType = (type, value) => {
|
|
|
163
193
|
return getReferencesForIntegerType(type, value);
|
|
164
194
|
case NodeKind.StringType:
|
|
165
195
|
return getReferencesForStringType(type, value);
|
|
166
|
-
case NodeKind.
|
|
167
|
-
return
|
|
196
|
+
case NodeKind.TypeArgumentType:
|
|
197
|
+
return getReferencesForTypeArgumentType(type, value);
|
|
168
198
|
case NodeKind.ReferenceIdentifierType:
|
|
169
199
|
return getReferencesForReferenceIdentifierType(type, value);
|
|
170
200
|
case NodeKind.IncludeIdentifierType:
|
|
171
201
|
return getReferencesForIncludeIdentifierType(type, value);
|
|
172
202
|
case NodeKind.NestedEntityMapType:
|
|
173
203
|
return getReferencesForNestedEntityMapType(type, value);
|
|
204
|
+
case NodeKind.EnumType:
|
|
205
|
+
return getReferencesForEnumType(type, value);
|
|
206
|
+
default:
|
|
207
|
+
return assertExhaustive(type);
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
export const formatValue = (type, value) => {
|
|
211
|
+
switch (type.kind) {
|
|
212
|
+
case NodeKind.ArrayType:
|
|
213
|
+
return formatArrayValue(type, value);
|
|
214
|
+
case NodeKind.ObjectType:
|
|
215
|
+
return formatObjectValue(type, value);
|
|
216
|
+
case NodeKind.BooleanType:
|
|
217
|
+
return formatBooleanValue(type, value);
|
|
218
|
+
case NodeKind.DateType:
|
|
219
|
+
return formatDateValue(type, value);
|
|
220
|
+
case NodeKind.FloatType:
|
|
221
|
+
return formatFloatValue(type, value);
|
|
222
|
+
case NodeKind.IntegerType:
|
|
223
|
+
return formatIntegerValue(type, value);
|
|
224
|
+
case NodeKind.StringType:
|
|
225
|
+
return formatStringValue(type, value);
|
|
226
|
+
case NodeKind.TypeArgumentType:
|
|
227
|
+
return formatTypeArgumentValue(type, value);
|
|
228
|
+
case NodeKind.IncludeIdentifierType:
|
|
229
|
+
return formatIncludeIdentifierValue(type, value);
|
|
230
|
+
case NodeKind.NestedEntityMapType:
|
|
231
|
+
return formatNestedEntityMapValue(type, value);
|
|
232
|
+
case NodeKind.ReferenceIdentifierType:
|
|
233
|
+
return formatReferenceIdentifierValue(type, value);
|
|
234
|
+
case NodeKind.EnumType:
|
|
235
|
+
return formatEnumType(type, value);
|
|
174
236
|
default:
|
|
175
237
|
return assertExhaustive(type);
|
|
176
238
|
}
|
|
@@ -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;
|
|
@@ -28,3 +29,4 @@ export declare const validateArrayType: Validator<ArrayType>;
|
|
|
28
29
|
export declare const resolveTypeArgumentsInArrayType: (args: Record<string, Type>, type: ArrayType) => ArrayType;
|
|
29
30
|
export declare const serializeArrayType: Serializer<ArrayType, SerializedArrayType>;
|
|
30
31
|
export declare const getReferencesForArrayType: GetReferences<ArrayType>;
|
|
32
|
+
export declare const formatArrayValue: StructureFormatter<ArrayType>;
|
|
@@ -1,10 +1,10 @@
|
|
|
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";
|
|
6
6
|
import { validateOption } from "../../validation/options.js";
|
|
7
|
-
import { getReferencesForType, removeParentKey, resolveTypeArgumentsInType, serializeType, validate, } from "../Type.js";
|
|
7
|
+
import { formatValue, getReferencesForType, removeParentKey, resolveTypeArgumentsInType, serializeType, validate, } from "../Type.js";
|
|
8
8
|
export const ArrayType = (items, options = {}) => {
|
|
9
9
|
const type = {
|
|
10
10
|
...options,
|
|
@@ -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), {
|
|
@@ -36,3 +36,4 @@ export const serializeArrayType = type => ({
|
|
|
36
36
|
items: serializeType(type.items),
|
|
37
37
|
});
|
|
38
38
|
export const getReferencesForArrayType = (type, value) => Array.isArray(value) ? value.flatMap(item => getReferencesForType(type.items, item)) : [];
|
|
39
|
+
export const formatArrayValue = (type, value) => Array.isArray(value) ? value.map(item => formatValue(type.items, item)) : value;
|
|
@@ -0,0 +1,39 @@
|
|
|
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";
|
|
6
|
+
export interface EnumType<T extends Record<string, EnumCaseDecl> = Record<string, EnumCaseDecl>> extends BaseType {
|
|
7
|
+
kind: NodeKind["EnumType"];
|
|
8
|
+
values: T;
|
|
9
|
+
}
|
|
10
|
+
export interface SerializedEnumType<T extends Record<string, SerializedEnumCaseDecl> = Record<string, SerializedEnumCaseDecl>> extends SerializedBaseType {
|
|
11
|
+
kind: NodeKind["EnumType"];
|
|
12
|
+
values: T;
|
|
13
|
+
}
|
|
14
|
+
export declare const EnumType: <T extends Record<string, EnumCaseDecl> = Record<string, EnumCaseDecl>>(values: T) => EnumType<T>;
|
|
15
|
+
export declare const isEnumType: (node: Node) => node is EnumType;
|
|
16
|
+
export declare const getNestedDeclarationsInEnumType: GetNestedDeclarations<EnumType>;
|
|
17
|
+
export declare const validateEnumType: Validator<EnumType>;
|
|
18
|
+
export declare const resolveTypeArgumentsInEnumType: (args: Record<string, Type>, type: EnumType) => EnumType;
|
|
19
|
+
export interface EnumCaseDecl<T extends Type | null = Type | null> {
|
|
20
|
+
kind: NodeKind["EnumCaseDecl"];
|
|
21
|
+
type: T;
|
|
22
|
+
comment?: string;
|
|
23
|
+
isDeprecated?: boolean;
|
|
24
|
+
}
|
|
25
|
+
export interface SerializedEnumCaseDecl<T extends SerializedType | null = SerializedType | null> {
|
|
26
|
+
kind: NodeKind["EnumCaseDecl"];
|
|
27
|
+
type: T;
|
|
28
|
+
comment?: string;
|
|
29
|
+
isDeprecated?: boolean;
|
|
30
|
+
}
|
|
31
|
+
export declare const EnumCaseDecl: <T extends Type | null>(options: {
|
|
32
|
+
type: T;
|
|
33
|
+
comment?: string;
|
|
34
|
+
isDeprecated?: boolean;
|
|
35
|
+
}) => EnumCaseDecl<T>;
|
|
36
|
+
export { EnumCaseDecl as EnumCase };
|
|
37
|
+
export declare const serializeEnumType: Serializer<EnumType, SerializedEnumType>;
|
|
38
|
+
export declare const getReferencesForEnumType: GetReferences<EnumType>;
|
|
39
|
+
export declare const formatEnumType: StructureFormatter<EnumType>;
|