tsondb 0.3.0 → 0.5.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 +10 -0
- package/lib/bin/tsondb.js +84 -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} +6 -5
- package/lib/node/index.d.ts +9 -0
- package/lib/node/index.js +75 -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 +9 -2
- package/lib/{renderers → node/renderers}/jsonschema/render.d.ts +1 -1
- package/lib/{renderers → node/renderers}/jsonschema/render.js +15 -10
- 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 +13 -9
- package/lib/{schema → node/schema}/Node.d.ts +5 -5
- package/lib/{schema → node/schema}/Node.js +9 -8
- 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 +13 -12
- package/lib/{schema → node/schema}/declarations/EntityDecl.js +4 -5
- package/lib/{schema → node/schema}/declarations/EnumDecl.d.ts +9 -7
- package/lib/{schema → node/schema}/declarations/EnumDecl.js +6 -13
- package/lib/{schema → node/schema}/declarations/TypeAliasDecl.d.ts +8 -7
- package/lib/{schema → node/schema}/declarations/TypeAliasDecl.js +6 -14
- 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 +54 -0
- package/lib/{schema → node/schema}/types/Type.js +55 -29
- package/lib/{schema → node/schema}/types/generic/ArrayType.d.ts +5 -4
- package/lib/{schema → node/schema}/types/generic/ArrayType.js +5 -5
- package/lib/{schema → node/schema}/types/generic/EnumType.d.ts +5 -4
- package/lib/{schema → node/schema}/types/generic/EnumType.js +10 -4
- package/lib/{schema → node/schema}/types/generic/ObjectType.d.ts +8 -7
- package/lib/{schema → node/schema}/types/generic/ObjectType.js +14 -7
- 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 +8 -16
- 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 +7 -3
- package/lib/{server → node/server}/api/git.js +14 -11
- package/lib/{server → node/server}/api/instanceOperations.d.ts +3 -3
- package/lib/{server → node/server}/api/instanceOperations.js +18 -7
- 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 +23 -13
- package/lib/node/server/init.d.ts +5 -0
- package/lib/{server → node/server}/init.js +9 -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 +4 -3
- package/lib/{utils → node/utils}/instances.js +10 -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 +9 -3
- package/lib/shared/utils/array.d.ts +1 -0
- package/lib/shared/utils/array.js +13 -9
- package/lib/shared/utils/displayName.d.ts +1 -1
- package/lib/shared/utils/displayName.js +7 -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 +5 -1
- 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 +3 -3
- package/lib/{client → web}/api.js +5 -6
- package/lib/web/components/Git.d.ts +2 -0
- package/lib/{client → web}/components/Git.js +59 -15
- 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/useAPIResource.js +2 -1
- 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 +9 -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 +8 -6
- package/lib/web/routes/Home.d.ts +2 -0
- package/lib/{client → web}/routes/Home.js +2 -1
- 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 +33 -19
- 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}/index.d.ts +0 -0
- /package/lib/{client → web}/index.js +0 -0
- /package/lib/{client → web}/routes/NotFound.js +0 -0
|
@@ -1,19 +1,16 @@
|
|
|
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 { EnumType, getNestedDeclarationsInEnumType, getReferencesForEnumType, resolveTypeArgumentsInEnumType, serializeEnumType, validateEnumType, } from "../types/generic/EnumType.js";
|
|
5
|
-
import {
|
|
5
|
+
import { setParent } from "../types/Type.js";
|
|
6
|
+
import { getTypeArgumentsRecord, validateDeclName } from "./Declaration.js";
|
|
6
7
|
export const GenEnumDecl = (sourceUrl, options) => {
|
|
7
8
|
validateDeclName(options.name);
|
|
8
9
|
const decl = {
|
|
9
10
|
...options,
|
|
10
11
|
kind: NodeKind.EnumDecl,
|
|
11
12
|
sourceUrl,
|
|
12
|
-
type: Lazy.of(() =>
|
|
13
|
-
const type = EnumType(options.values(...options.parameters));
|
|
14
|
-
type.parent = decl;
|
|
15
|
-
return type;
|
|
16
|
-
}),
|
|
13
|
+
type: Lazy.of(() => setParent(EnumType(options.values(...options.parameters)), decl)),
|
|
17
14
|
};
|
|
18
15
|
return decl;
|
|
19
16
|
};
|
|
@@ -25,11 +22,7 @@ export const EnumDecl = (sourceUrl, options) => {
|
|
|
25
22
|
kind: NodeKind.EnumDecl,
|
|
26
23
|
sourceUrl,
|
|
27
24
|
parameters: [],
|
|
28
|
-
type: Lazy.of(() =>
|
|
29
|
-
const type = EnumType(options.values());
|
|
30
|
-
type.parent = decl;
|
|
31
|
-
return type;
|
|
32
|
-
}),
|
|
25
|
+
type: Lazy.of(() => setParent(EnumType(options.values()), decl)),
|
|
33
26
|
};
|
|
34
27
|
return decl;
|
|
35
28
|
};
|
|
@@ -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,19 +1,15 @@
|
|
|
1
|
-
import { Lazy } from "
|
|
1
|
+
import { Lazy } from "../../../shared/utils/lazy.js";
|
|
2
2
|
import { NodeKind } from "../Node.js";
|
|
3
|
-
import { serializeTypeParameter
|
|
4
|
-
import { getReferencesForType, resolveTypeArgumentsInType, serializeType, validate, } from "../types/Type.js";
|
|
5
|
-
import { getNestedDeclarations, getTypeArgumentsRecord, validateDeclName
|
|
3
|
+
import { serializeTypeParameter } from "../TypeParameter.js";
|
|
4
|
+
import { getReferencesForType, resolveTypeArgumentsInType, serializeType, setParent, validate, } from "../types/Type.js";
|
|
5
|
+
import { getNestedDeclarations, getTypeArgumentsRecord, validateDeclName } from "./Declaration.js";
|
|
6
6
|
export const GenTypeAliasDecl = (sourceUrl, options) => {
|
|
7
7
|
validateDeclName(options.name);
|
|
8
8
|
const decl = {
|
|
9
9
|
...options,
|
|
10
10
|
kind: NodeKind.TypeAliasDecl,
|
|
11
11
|
sourceUrl,
|
|
12
|
-
type: Lazy.of(() =>
|
|
13
|
-
const type = options.type(...options.parameters);
|
|
14
|
-
type.parent = decl;
|
|
15
|
-
return type;
|
|
16
|
-
}),
|
|
12
|
+
type: Lazy.of(() => setParent(options.type(...options.parameters), decl)),
|
|
17
13
|
};
|
|
18
14
|
return decl;
|
|
19
15
|
};
|
|
@@ -25,11 +21,7 @@ export const TypeAliasDecl = (sourceUrl, options) => {
|
|
|
25
21
|
kind: NodeKind.TypeAliasDecl,
|
|
26
22
|
sourceUrl,
|
|
27
23
|
parameters: [],
|
|
28
|
-
type: Lazy.of(() =>
|
|
29
|
-
const type = options.type();
|
|
30
|
-
type.parent = decl;
|
|
31
|
-
return type;
|
|
32
|
-
}),
|
|
24
|
+
type: Lazy.of(() => setParent(options.type(), decl)),
|
|
33
25
|
};
|
|
34
26
|
return decl;
|
|
35
27
|
};
|
|
@@ -3,19 +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
|
|
8
|
+
export * from "./types/generic/EnumType.js";
|
|
9
9
|
export * from "./types/generic/ObjectType.js";
|
|
10
10
|
export * from "./types/primitives/BooleanType.js";
|
|
11
11
|
export * from "./types/primitives/DateType.js";
|
|
12
12
|
export * from "./types/primitives/FloatType.js";
|
|
13
13
|
export * from "./types/primitives/IntegerType.js";
|
|
14
14
|
export * from "./types/primitives/NumericType.js";
|
|
15
|
-
export * from "./types/primitives/PrimitiveType.js";
|
|
15
|
+
export type * from "./types/primitives/PrimitiveType.js";
|
|
16
16
|
export * from "./types/primitives/StringType.js";
|
|
17
|
-
export * from "./types/references/GenericArgumentIdentifierType.js";
|
|
18
17
|
export * from "./types/references/IncludeIdentifierType.js";
|
|
19
18
|
export * from "./types/references/NestedEntityMapType.js";
|
|
20
19
|
export * from "./types/references/ReferenceIdentifierType.js";
|
|
20
|
+
export * from "./types/references/TypeArgumentType.js";
|
|
21
21
|
export * from "./types/Type.js";
|
|
@@ -3,19 +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
|
|
8
|
+
export * from "./types/generic/EnumType.js";
|
|
9
9
|
export * from "./types/generic/ObjectType.js";
|
|
10
10
|
export * from "./types/primitives/BooleanType.js";
|
|
11
11
|
export * from "./types/primitives/DateType.js";
|
|
12
12
|
export * from "./types/primitives/FloatType.js";
|
|
13
13
|
export * from "./types/primitives/IntegerType.js";
|
|
14
14
|
export * from "./types/primitives/NumericType.js";
|
|
15
|
-
export * from "./types/primitives/PrimitiveType.js";
|
|
16
15
|
export * from "./types/primitives/StringType.js";
|
|
17
|
-
export * from "./types/references/GenericArgumentIdentifierType.js";
|
|
18
16
|
export * from "./types/references/IncludeIdentifierType.js";
|
|
19
17
|
export * from "./types/references/NestedEntityMapType.js";
|
|
20
18
|
export * from "./types/references/ReferenceIdentifierType.js";
|
|
19
|
+
export * from "./types/references/TypeArgumentType.js";
|
|
21
20
|
export * from "./types/Type.js";
|
|
@@ -0,0 +1,54 @@
|
|
|
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
|
+
/**
|
|
41
|
+
* Sets the `parent` property of the passed `type` to the passed `parentNode`.
|
|
42
|
+
*
|
|
43
|
+
* The property is set on the instance. It does not create a new instance.
|
|
44
|
+
*/
|
|
45
|
+
export declare const setParent: <T extends BaseType>(type: Omit<T, "parent">, parentNode: Type | Decl) => T;
|
|
46
|
+
export declare const removeParentKey: <T extends BaseType>(type: T) => Omit<T, "parent">;
|
|
47
|
+
export declare const findTypeAtPath: (type: Type, path: string[]) => Type | undefined;
|
|
48
|
+
export declare const serializeType: Serializer<Type, SerializedType>;
|
|
49
|
+
export declare const getReferencesForType: GetReferences<Type>;
|
|
50
|
+
/**
|
|
51
|
+
* Format the structure of a value to always look the same when serialized as JSON.
|
|
52
|
+
*/
|
|
53
|
+
export type StructureFormatter<T extends Type> = (type: T, value: unknown) => unknown;
|
|
54
|
+
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
|
}
|
|
@@ -111,11 +127,25 @@ export const getParentDecl = (type) => {
|
|
|
111
127
|
return getParentDecl(type.parent);
|
|
112
128
|
}
|
|
113
129
|
};
|
|
130
|
+
/**
|
|
131
|
+
* Sets the `parent` property of the passed `type` to the passed `parentNode`.
|
|
132
|
+
*
|
|
133
|
+
* The property is set on the instance. It does not create a new instance.
|
|
134
|
+
*/
|
|
135
|
+
export const setParent = (type, parentNode) => {
|
|
136
|
+
;
|
|
137
|
+
type.parent = parentNode;
|
|
138
|
+
return type;
|
|
139
|
+
};
|
|
140
|
+
export const removeParentKey = (type) => {
|
|
141
|
+
const { parent: _parent, ...rest } = type;
|
|
142
|
+
return rest;
|
|
143
|
+
};
|
|
114
144
|
export const findTypeAtPath = (type, path) => {
|
|
115
|
-
|
|
145
|
+
const [head, ...tail] = path;
|
|
146
|
+
if (head === undefined) {
|
|
116
147
|
return type;
|
|
117
148
|
}
|
|
118
|
-
const [head, ...tail] = path;
|
|
119
149
|
if (type.kind === NodeKind.ObjectType) {
|
|
120
150
|
const prop = type.properties[head];
|
|
121
151
|
if (prop) {
|
|
@@ -143,8 +173,8 @@ export const serializeType = type => {
|
|
|
143
173
|
return serializeIntegerType(type);
|
|
144
174
|
case NodeKind.StringType:
|
|
145
175
|
return serializeStringType(type);
|
|
146
|
-
case NodeKind.
|
|
147
|
-
return
|
|
176
|
+
case NodeKind.TypeArgumentType:
|
|
177
|
+
return serializeTypeArgumentType(type);
|
|
148
178
|
case NodeKind.ReferenceIdentifierType:
|
|
149
179
|
return serializeReferenceIdentifierType(type);
|
|
150
180
|
case NodeKind.IncludeIdentifierType:
|
|
@@ -157,10 +187,6 @@ export const serializeType = type => {
|
|
|
157
187
|
return assertExhaustive(type);
|
|
158
188
|
}
|
|
159
189
|
};
|
|
160
|
-
export const removeParentKey = (type) => {
|
|
161
|
-
const { parent: _parent, ...rest } = type;
|
|
162
|
-
return rest;
|
|
163
|
-
};
|
|
164
190
|
export const getReferencesForType = (type, value) => {
|
|
165
191
|
switch (type.kind) {
|
|
166
192
|
case NodeKind.ArrayType:
|
|
@@ -177,8 +203,8 @@ export const getReferencesForType = (type, value) => {
|
|
|
177
203
|
return getReferencesForIntegerType(type, value);
|
|
178
204
|
case NodeKind.StringType:
|
|
179
205
|
return getReferencesForStringType(type, value);
|
|
180
|
-
case NodeKind.
|
|
181
|
-
return
|
|
206
|
+
case NodeKind.TypeArgumentType:
|
|
207
|
+
return getReferencesForTypeArgumentType(type, value);
|
|
182
208
|
case NodeKind.ReferenceIdentifierType:
|
|
183
209
|
return getReferencesForReferenceIdentifierType(type, value);
|
|
184
210
|
case NodeKind.IncludeIdentifierType:
|
|
@@ -207,8 +233,8 @@ export const formatValue = (type, value) => {
|
|
|
207
233
|
return formatIntegerValue(type, value);
|
|
208
234
|
case NodeKind.StringType:
|
|
209
235
|
return formatStringValue(type, value);
|
|
210
|
-
case NodeKind.
|
|
211
|
-
return
|
|
236
|
+
case NodeKind.TypeArgumentType:
|
|
237
|
+
return formatTypeArgumentValue(type, value);
|
|
212
238
|
case NodeKind.IncludeIdentifierType:
|
|
213
239
|
return formatIncludeIdentifierValue(type, value);
|
|
214
240
|
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,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 { formatValue, getReferencesForType, removeParentKey, resolveTypeArgumentsInType, serializeType, validate, } from "../Type.js";
|
|
7
|
+
import { formatValue, getReferencesForType, removeParentKey, resolveTypeArgumentsInType, serializeType, setParent, validate, } from "../Type.js";
|
|
8
8
|
export const ArrayType = (items, options = {}) => {
|
|
9
9
|
const type = {
|
|
10
10
|
...options,
|
|
@@ -13,7 +13,7 @@ export const ArrayType = (items, options = {}) => {
|
|
|
13
13
|
maxItems: validateOption(options.maxItems, "maxItems", option => Number.isInteger(option) && option >= 0),
|
|
14
14
|
items,
|
|
15
15
|
};
|
|
16
|
-
items
|
|
16
|
+
setParent(type.items, type);
|
|
17
17
|
return type;
|
|
18
18
|
};
|
|
19
19
|
export { ArrayType as Array };
|
|
@@ -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";
|
|
@@ -27,11 +27,15 @@ export const validateEnumType = (helpers, type, value) => {
|
|
|
27
27
|
}
|
|
28
28
|
const caseName = value[discriminatorKey];
|
|
29
29
|
if (!(caseName in type.values)) {
|
|
30
|
-
return [
|
|
30
|
+
return [
|
|
31
|
+
TypeError(`discriminator "${caseName}" is not a valid enum case, possible cases are: ${Object.keys(type.values).join(", ")}`),
|
|
32
|
+
];
|
|
31
33
|
}
|
|
32
34
|
const unknownKeyErrors = actualKeys.flatMap(actualKey => actualKey === discriminatorKey || actualKey in type.values
|
|
33
35
|
? []
|
|
34
|
-
: [
|
|
36
|
+
: [
|
|
37
|
+
TypeError(`key "${actualKey}" is not the discriminator key "${caseName}" or a valid enum case, possible cases are: ${Object.keys(type.values).join(", ")}`),
|
|
38
|
+
]);
|
|
35
39
|
if (unknownKeyErrors.length > 0) {
|
|
36
40
|
return unknownKeyErrors;
|
|
37
41
|
}
|
|
@@ -74,7 +78,9 @@ export const getReferencesForEnumType = (type, value) => typeof value === "objec
|
|
|
74
78
|
value[discriminatorKey] in type.values &&
|
|
75
79
|
type.values[value[discriminatorKey]]?.type == null &&
|
|
76
80
|
value[discriminatorKey] in value
|
|
77
|
-
? getReferencesForType(
|
|
81
|
+
? getReferencesForType(
|
|
82
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
83
|
+
type.values[value[discriminatorKey]].type, value[value[discriminatorKey]])
|
|
78
84
|
: [];
|
|
79
85
|
export const formatEnumType = (type, value) => {
|
|
80
86
|
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,11 +1,11 @@
|
|
|
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";
|
|
7
7
|
import { validateOption } from "../../validation/options.js";
|
|
8
|
-
import { getReferencesForType, removeParentKey, resolveTypeArgumentsInType, serializeType, validate, } from "../Type.js";
|
|
8
|
+
import { formatValue, getReferencesForType, removeParentKey, resolveTypeArgumentsInType, serializeType, setParent, validate, } from "../Type.js";
|
|
9
9
|
const keyPattern = /^[a-zA-Z0-9][a-zA-Z0-9_]*$/;
|
|
10
10
|
export const ObjectType = (properties, options = {}) => {
|
|
11
11
|
const type = {
|
|
@@ -19,7 +19,8 @@ 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
|
-
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
23
|
+
setParent(properties[key].type, type);
|
|
23
24
|
});
|
|
24
25
|
return type;
|
|
25
26
|
};
|
|
@@ -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,8 +70,13 @@ 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
|
-
? sortObjectKeys(
|
|
78
|
+
? sortObjectKeys(Object.fromEntries(Object.entries(value).map(([key, item]) => [
|
|
79
|
+
key,
|
|
80
|
+
type.properties[key] ? formatValue(type.properties[key].type, item) : item,
|
|
81
|
+
])), Object.keys(type.properties))
|
|
75
82
|
: value;
|
|
@@ -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";
|