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
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { discriminatorKey } from "../../../../shared/enum.js";
|
|
2
|
+
import { getNestedDeclarations } from "../../declarations/Declaration.js";
|
|
3
|
+
import { NodeKind } from "../../Node.js";
|
|
4
|
+
import { formatValue, getReferencesForType, removeParentKey, resolveTypeArgumentsInType, serializeType, validate, } from "../Type.js";
|
|
5
|
+
export const EnumType = (values) => {
|
|
6
|
+
const type = {
|
|
7
|
+
kind: NodeKind.EnumType,
|
|
8
|
+
values,
|
|
9
|
+
};
|
|
10
|
+
type.values = Object.fromEntries(Object.entries(values).map(([caseName, caseDef]) => [
|
|
11
|
+
caseName,
|
|
12
|
+
{ ...caseDef, type: caseDef.type === null ? null : { ...caseDef.type, parent: type } },
|
|
13
|
+
]));
|
|
14
|
+
return type;
|
|
15
|
+
};
|
|
16
|
+
export const isEnumType = (node) => node.kind === NodeKind.EnumType;
|
|
17
|
+
export const getNestedDeclarationsInEnumType = (addedDecls, type) => Object.values(type.values).reduce((acc, caseMember) => caseMember.type === null ? acc : getNestedDeclarations(acc, caseMember.type), addedDecls);
|
|
18
|
+
export const validateEnumType = (helpers, type, value) => {
|
|
19
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
20
|
+
return [TypeError(`expected an object, but got ${JSON.stringify(value)}`)];
|
|
21
|
+
}
|
|
22
|
+
const actualKeys = Object.keys(value);
|
|
23
|
+
if (!(discriminatorKey in value) || typeof value[discriminatorKey] !== "string") {
|
|
24
|
+
return [
|
|
25
|
+
TypeError(`missing required discriminator value at key "${discriminatorKey}" of type string`),
|
|
26
|
+
];
|
|
27
|
+
}
|
|
28
|
+
const caseName = value[discriminatorKey];
|
|
29
|
+
if (!(caseName in type.values)) {
|
|
30
|
+
return [TypeError(`discriminator "${caseName}" is not a valid enum case`)];
|
|
31
|
+
}
|
|
32
|
+
const unknownKeyErrors = actualKeys.flatMap(actualKey => actualKey === discriminatorKey || actualKey in type.values
|
|
33
|
+
? []
|
|
34
|
+
: [TypeError(`key "${actualKey}" is not the discriminator key or a valid enum case`)]);
|
|
35
|
+
if (unknownKeyErrors.length > 0) {
|
|
36
|
+
return unknownKeyErrors;
|
|
37
|
+
}
|
|
38
|
+
const associatedType = type.values[caseName]?.type;
|
|
39
|
+
if (associatedType != null) {
|
|
40
|
+
if (!(caseName in value)) {
|
|
41
|
+
return [TypeError(`missing required associated value for case "${caseName}"`)];
|
|
42
|
+
}
|
|
43
|
+
return validate(helpers, associatedType, value[caseName]);
|
|
44
|
+
}
|
|
45
|
+
return [];
|
|
46
|
+
};
|
|
47
|
+
export const resolveTypeArgumentsInEnumType = (args, type) => EnumType(Object.fromEntries(Object.entries(type.values).map(([key, { type, ...caseMember }]) => [
|
|
48
|
+
key,
|
|
49
|
+
{
|
|
50
|
+
...caseMember,
|
|
51
|
+
type: type === null ? null : resolveTypeArgumentsInType(args, type),
|
|
52
|
+
},
|
|
53
|
+
])));
|
|
54
|
+
export const EnumCaseDecl = (options) => ({
|
|
55
|
+
...options,
|
|
56
|
+
kind: NodeKind.EnumCaseDecl,
|
|
57
|
+
});
|
|
58
|
+
export { EnumCaseDecl as EnumCase };
|
|
59
|
+
export const serializeEnumType = type => ({
|
|
60
|
+
...removeParentKey(type),
|
|
61
|
+
values: Object.fromEntries(Object.entries(type.values).map(([key, caseMember]) => [
|
|
62
|
+
key,
|
|
63
|
+
{
|
|
64
|
+
...caseMember,
|
|
65
|
+
type: caseMember.type === null ? null : serializeType(caseMember.type),
|
|
66
|
+
},
|
|
67
|
+
])),
|
|
68
|
+
});
|
|
69
|
+
export const getReferencesForEnumType = (type, value) => typeof value === "object" &&
|
|
70
|
+
value !== null &&
|
|
71
|
+
!Array.isArray(value) &&
|
|
72
|
+
discriminatorKey in value &&
|
|
73
|
+
typeof value[discriminatorKey] === "string" &&
|
|
74
|
+
value[discriminatorKey] in type.values &&
|
|
75
|
+
type.values[value[discriminatorKey]]?.type == null &&
|
|
76
|
+
value[discriminatorKey] in value
|
|
77
|
+
? getReferencesForType(
|
|
78
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
79
|
+
type.values[value[discriminatorKey]].type, value[value[discriminatorKey]])
|
|
80
|
+
: [];
|
|
81
|
+
export const formatEnumType = (type, value) => {
|
|
82
|
+
if (typeof value === "object" &&
|
|
83
|
+
value !== null &&
|
|
84
|
+
!Array.isArray(value) &&
|
|
85
|
+
discriminatorKey in value &&
|
|
86
|
+
typeof value[discriminatorKey] === "string") {
|
|
87
|
+
const caseName = value[discriminatorKey];
|
|
88
|
+
const caseValue = value[caseName];
|
|
89
|
+
const caseType = type.values[caseName]?.type;
|
|
90
|
+
return {
|
|
91
|
+
[discriminatorKey]: caseName,
|
|
92
|
+
...(caseValue == null || caseType == null
|
|
93
|
+
? {}
|
|
94
|
+
: { [caseName]: formatValue(caseType, caseValue) }),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
return value;
|
|
98
|
+
};
|
|
@@ -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;
|
|
@@ -49,3 +50,4 @@ export declare const Optional: <T extends Type>(options: {
|
|
|
49
50
|
}) => MemberDecl<T, false>;
|
|
50
51
|
export declare const serializeObjectType: Serializer<ObjectType, SerializedObjectType>;
|
|
51
52
|
export declare const getReferencesForObjectType: GetReferences<ObjectType>;
|
|
53
|
+
export declare const formatObjectValue: StructureFormatter<ObjectType>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { sortObjectKeys } from "../../../../shared/utils/object.js";
|
|
2
|
+
import { parallelizeErrors } from "../../../../shared/utils/validation.js";
|
|
3
|
+
import { validateObjectConstraints } from "../../../../shared/validation/object.js";
|
|
3
4
|
import { wrapErrorsIfAny } from "../../../utils/error.js";
|
|
4
5
|
import { getNestedDeclarations } from "../../declarations/Declaration.js";
|
|
5
6
|
import { NodeKind } from "../../Node.js";
|
|
@@ -18,6 +19,7 @@ export const ObjectType = (properties, options = {}) => {
|
|
|
18
19
|
if (!keyPattern.test(key)) {
|
|
19
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})`);
|
|
20
21
|
}
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
21
23
|
properties[key].type.parent = type;
|
|
22
24
|
});
|
|
23
25
|
return type;
|
|
@@ -33,6 +35,7 @@ export const validateObjectType = (helpers, type, value) => {
|
|
|
33
35
|
return parallelizeErrors([
|
|
34
36
|
...validateObjectConstraints(type, expectedKeys, value),
|
|
35
37
|
...expectedKeys.map(key => {
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
36
39
|
const prop = type.properties[key];
|
|
37
40
|
if (prop.isRequired && !(key in value)) {
|
|
38
41
|
return TypeError(`missing required property "${key}"`);
|
|
@@ -67,5 +70,10 @@ export const serializeObjectType = type => ({
|
|
|
67
70
|
])),
|
|
68
71
|
});
|
|
69
72
|
export const getReferencesForObjectType = (type, value) => typeof value === "object" && value !== null
|
|
70
|
-
? 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) : [])
|
|
71
76
|
: [];
|
|
77
|
+
export const formatObjectValue = (type, value) => typeof value === "object" && value !== null && !Array.isArray(value)
|
|
78
|
+
? sortObjectKeys(value, Object.keys(type.properties))
|
|
79
|
+
: 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
|
}
|
|
@@ -13,3 +14,4 @@ export declare const isBooleanType: (node: Node) => node is BooleanType;
|
|
|
13
14
|
export declare const validateBooleanType: Validator<BooleanType>;
|
|
14
15
|
export declare const serializeBooleanType: Serializer<BooleanType, SerializedBooleanType>;
|
|
15
16
|
export declare const getReferencesForBooleanType: GetReferences<BooleanType>;
|
|
17
|
+
export declare const formatBooleanValue: StructureFormatter<BooleanType>;
|
|
@@ -13,3 +13,4 @@ export const validateBooleanType = (_helpers, _type, value) => {
|
|
|
13
13
|
};
|
|
14
14
|
export const serializeBooleanType = type => removeParentKey(type);
|
|
15
15
|
export const getReferencesForBooleanType = (_type, _value) => [];
|
|
16
|
+
export const formatBooleanValue = (_type, value) => value;
|
|
@@ -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
|
}
|
|
@@ -14,3 +15,4 @@ export declare const isDateType: (node: Node) => node is DateType;
|
|
|
14
15
|
export declare const validateDateType: Validator<DateType>;
|
|
15
16
|
export declare const serializeDateType: Serializer<DateType, SerializedDateType>;
|
|
16
17
|
export declare const getReferencesForDateType: GetReferences<DateType>;
|
|
18
|
+
export declare const formatDateValue: StructureFormatter<DateType>;
|
|
@@ -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) => ({
|
|
@@ -15,3 +15,4 @@ export const validateDateType = (_helpers, type, value) => {
|
|
|
15
15
|
};
|
|
16
16
|
export const serializeDateType = type => removeParentKey(type);
|
|
17
17
|
export const getReferencesForDateType = (_type, _value) => [];
|
|
18
|
+
export const formatDateValue = (_type, value) => value;
|
|
@@ -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;
|
|
@@ -24,3 +25,4 @@ export declare const isFloatType: (node: Node) => node is FloatType;
|
|
|
24
25
|
export declare const validateFloatType: Validator<FloatType>;
|
|
25
26
|
export declare const serializeFloatType: Serializer<FloatType, SerializedFloatType>;
|
|
26
27
|
export declare const getReferencesForFloatType: GetReferences<FloatType>;
|
|
28
|
+
export declare const formatFloatValue: StructureFormatter<FloatType>;
|
|
@@ -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 = {}) => ({
|
|
@@ -15,3 +15,4 @@ export const validateFloatType = (_helpers, type, value) => {
|
|
|
15
15
|
};
|
|
16
16
|
export const serializeFloatType = type => removeParentKey(type);
|
|
17
17
|
export const getReferencesForFloatType = (_type, _value) => [];
|
|
18
|
+
export const formatFloatValue = (_type, value) => value;
|
|
@@ -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;
|
|
@@ -24,3 +25,4 @@ export declare const isIntegerType: (node: Node) => node is IntegerType;
|
|
|
24
25
|
export declare const validateIntegerType: Validator<IntegerType>;
|
|
25
26
|
export declare const serializeIntegerType: Serializer<IntegerType, SerializedIntegerType>;
|
|
26
27
|
export declare const getReferencesForIntegerType: GetReferences<IntegerType>;
|
|
28
|
+
export declare const formatIntegerValue: StructureFormatter<IntegerType>;
|
|
@@ -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";
|
|
@@ -19,3 +19,4 @@ export const validateIntegerType = (_helpers, type, value) => {
|
|
|
19
19
|
};
|
|
20
20
|
export const serializeIntegerType = type => removeParentKey(type);
|
|
21
21
|
export const getReferencesForIntegerType = (_type, _value) => [];
|
|
22
|
+
export const formatIntegerValue = (_type, value) => value;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FloatType, SerializedFloatType } from "./FloatType.js";
|
|
2
|
-
import { IntegerType, SerializedIntegerType } from "./IntegerType.js";
|
|
1
|
+
import type { FloatType, SerializedFloatType } from "./FloatType.js";
|
|
2
|
+
import type { IntegerType, SerializedIntegerType } from "./IntegerType.js";
|
|
3
3
|
export type NumericType = FloatType | IntegerType;
|
|
4
4
|
export type SerializedNumericType = SerializedFloatType | SerializedIntegerType;
|
|
5
5
|
export * from "./FloatType.js";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { BooleanType, SerializedBooleanType } from "./BooleanType.js";
|
|
2
|
+
import type { DateType, SerializedDateType } from "./DateType.js";
|
|
3
|
+
import type { NumericType, SerializedNumericType } from "./NumericType.js";
|
|
4
|
+
import type { SerializedStringType, StringType } from "./StringType.js";
|
|
5
|
+
export type PrimitiveType = BooleanType | DateType | NumericType | StringType;
|
|
6
|
+
export type SerializedPrimitiveType = SerializedBooleanType | SerializedDateType | SerializedNumericType | SerializedStringType;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { StringConstraints } from "
|
|
2
|
-
import { GetReferences, Node,
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import type { StringConstraints } from "../../../../shared/validation/string.js";
|
|
2
|
+
import type { GetReferences, Node, Serializer } from "../../Node.js";
|
|
3
|
+
import { NodeKind } from "../../Node.js";
|
|
4
|
+
import type { Validator } from "../../validation/type.js";
|
|
5
|
+
import type { BaseType, SerializedBaseType, StructureFormatter } from "../Type.js";
|
|
5
6
|
export interface StringType extends BaseType, StringConstraints {
|
|
6
7
|
kind: NodeKind["StringType"];
|
|
7
8
|
pattern?: RegExp;
|
|
@@ -23,3 +24,4 @@ export declare const isStringType: (node: Node) => node is StringType;
|
|
|
23
24
|
export declare const validateStringType: Validator<StringType>;
|
|
24
25
|
export declare const serializeStringType: Serializer<StringType, SerializedStringType>;
|
|
25
26
|
export declare const getReferencesForStringType: GetReferences<StringType>;
|
|
27
|
+
export declare const formatStringValue: StructureFormatter<StringType>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { validateStringConstraints } from "
|
|
1
|
+
import { validateStringConstraints } from "../../../../shared/validation/string.js";
|
|
2
2
|
import { NodeKind } from "../../Node.js";
|
|
3
3
|
import { removeParentKey } from "../Type.js";
|
|
4
4
|
export const StringType = (options = {}) => ({
|
|
@@ -18,3 +18,4 @@ export const serializeStringType = type => removeParentKey({
|
|
|
18
18
|
pattern: type.pattern?.source,
|
|
19
19
|
});
|
|
20
20
|
export const getReferencesForStringType = (_type, _value) => [];
|
|
21
|
+
export const formatStringValue = (_type, value) => value;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { GetNestedDeclarations, SerializedTypeArguments, TypeArguments } from "../../declarations/Declaration.js";
|
|
2
|
-
import {
|
|
3
|
-
import { TypeAliasDecl } from "../../declarations/TypeAliasDecl.js";
|
|
4
|
-
import { GetReferences, Node,
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
1
|
+
import type { GetNestedDeclarations, SerializedTypeArguments, TypeArguments } from "../../declarations/Declaration.js";
|
|
2
|
+
import type { EnumDecl } from "../../declarations/EnumDecl.js";
|
|
3
|
+
import type { TypeAliasDecl } from "../../declarations/TypeAliasDecl.js";
|
|
4
|
+
import type { GetReferences, Node, Serializer } from "../../Node.js";
|
|
5
|
+
import { NodeKind } from "../../Node.js";
|
|
6
|
+
import type { SerializedTypeParameter, TypeParameter } from "../../TypeParameter.js";
|
|
7
|
+
import type { Validator } from "../../validation/type.js";
|
|
8
|
+
import type { EnumCaseDecl } from "../generic/EnumType.js";
|
|
9
|
+
import type { BaseType, SerializedBaseType, StructureFormatter, Type } from "../Type.js";
|
|
8
10
|
type TConstraint<Params extends TypeParameter[]> = TypeAliasDecl<string, Type, Params> | EnumDecl<string, Record<string, EnumCaseDecl>, Params>;
|
|
9
11
|
export interface IncludeIdentifierType<Params extends TypeParameter[] = TypeParameter[], T extends TConstraint<Params> = TConstraint<Params>> extends BaseType {
|
|
10
12
|
kind: NodeKind["IncludeIdentifierType"];
|
|
@@ -23,6 +25,7 @@ export { IncludeIdentifierType as IncludeIdentifier };
|
|
|
23
25
|
export declare const isIncludeIdentifierType: (node: Node) => node is IncludeIdentifierType;
|
|
24
26
|
export declare const getNestedDeclarationsInIncludeIdentifierType: GetNestedDeclarations<IncludeIdentifierType>;
|
|
25
27
|
export declare const validateIncludeIdentifierType: Validator<IncludeIdentifierType>;
|
|
26
|
-
export declare const resolveTypeArgumentsInIncludeIdentifierType: (args: Record<string, Type>, type: IncludeIdentifierType) =>
|
|
28
|
+
export declare const resolveTypeArgumentsInIncludeIdentifierType: (args: Record<string, Type>, type: IncludeIdentifierType) => Type;
|
|
27
29
|
export declare const serializeIncludeIdentifierType: Serializer<IncludeIdentifierType, SerializedIncludeIdentifierType>;
|
|
28
30
|
export declare const getReferencesForIncludeIdentifierType: GetReferences<IncludeIdentifierType>;
|
|
31
|
+
export declare const formatIncludeIdentifierValue: StructureFormatter<IncludeIdentifierType>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getNestedDeclarations, getReferencesForDecl, resolveTypeArgumentsInDecl, validateDecl, } from "../../declarations/Declaration.js";
|
|
2
2
|
import { NodeKind } from "../../Node.js";
|
|
3
|
-
import {
|
|
3
|
+
import { formatEnumType } from "../generic/EnumType.js";
|
|
4
|
+
import { formatValue, removeParentKey, resolveTypeArgumentsInType, serializeType } from "../Type.js";
|
|
4
5
|
export const GenIncludeIdentifierType = (reference, args) => ({
|
|
5
6
|
kind: NodeKind.IncludeIdentifierType,
|
|
6
7
|
reference,
|
|
@@ -18,10 +19,22 @@ export const getNestedDeclarationsInIncludeIdentifierType = (addedDecls, type) =
|
|
|
18
19
|
? addedDecls
|
|
19
20
|
: getNestedDeclarations([type.reference, ...addedDecls], type.reference);
|
|
20
21
|
export const validateIncludeIdentifierType = (helpers, type, value) => validateDecl(helpers, type.reference, type.args, value);
|
|
21
|
-
export const resolveTypeArgumentsInIncludeIdentifierType = (args, type) =>
|
|
22
|
+
export const resolveTypeArgumentsInIncludeIdentifierType = (args, type) => type.args.length === 0
|
|
23
|
+
? type
|
|
24
|
+
: resolveTypeArgumentsInDecl(type.reference, type.args.map(arg => resolveTypeArgumentsInType(args, arg))).type.value;
|
|
22
25
|
export const serializeIncludeIdentifierType = type => ({
|
|
23
26
|
...removeParentKey(type),
|
|
24
27
|
reference: type.reference.name,
|
|
25
28
|
args: type.args.map(arg => serializeType(arg)),
|
|
26
29
|
});
|
|
27
30
|
export const getReferencesForIncludeIdentifierType = (type, value) => getReferencesForDecl(resolveTypeArgumentsInDecl(type.reference, type.args), value);
|
|
31
|
+
export const formatIncludeIdentifierValue = (type, value) => {
|
|
32
|
+
switch (type.reference.kind) {
|
|
33
|
+
case NodeKind.TypeAliasDecl:
|
|
34
|
+
return formatValue(type.reference.type.value, value);
|
|
35
|
+
case NodeKind.EnumDecl:
|
|
36
|
+
return formatEnumType(type.reference.type.value, value);
|
|
37
|
+
default:
|
|
38
|
+
return value;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { Lazy } from "
|
|
2
|
-
import { GetNestedDeclarations } from "../../declarations/Declaration.js";
|
|
3
|
-
import { EntityDecl } from "../../declarations/EntityDecl.js";
|
|
4
|
-
import { GetReferences, Node,
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
type
|
|
1
|
+
import { Lazy } from "../../../../shared/utils/lazy.js";
|
|
2
|
+
import type { GetNestedDeclarations } from "../../declarations/Declaration.js";
|
|
3
|
+
import type { EntityDecl } from "../../declarations/EntityDecl.js";
|
|
4
|
+
import type { GetReferences, Node, Serializer } from "../../Node.js";
|
|
5
|
+
import { NodeKind } from "../../Node.js";
|
|
6
|
+
import type { Validator } from "../../validation/type.js";
|
|
7
|
+
import type { MemberDecl, ObjectType, SerializedMemberDecl, SerializedObjectType } from "../generic/ObjectType.js";
|
|
8
|
+
import type { BaseType, SerializedBaseType, StructureFormatter, Type } from "../Type.js";
|
|
9
|
+
type TConstraint = Record<string, MemberDecl>;
|
|
9
10
|
export interface NestedEntityMapType<Name extends string = string, T extends TConstraint = TConstraint> extends BaseType {
|
|
10
11
|
kind: NodeKind["NestedEntityMapType"];
|
|
11
12
|
name: Name;
|
|
@@ -13,7 +14,7 @@ export interface NestedEntityMapType<Name extends string = string, T extends TCo
|
|
|
13
14
|
secondaryEntity: EntityDecl;
|
|
14
15
|
type: Lazy<ObjectType<T>>;
|
|
15
16
|
}
|
|
16
|
-
type TSerializedConstraint = Record<string, SerializedMemberDecl
|
|
17
|
+
type TSerializedConstraint = Record<string, SerializedMemberDecl>;
|
|
17
18
|
export interface SerializedNestedEntityMapType<Name extends string = string, T extends TSerializedConstraint = TSerializedConstraint> extends SerializedBaseType {
|
|
18
19
|
kind: NodeKind["NestedEntityMapType"];
|
|
19
20
|
name: Name;
|
|
@@ -34,3 +35,4 @@ export declare const validateNestedEntityMapType: Validator<NestedEntityMapType>
|
|
|
34
35
|
export declare const resolveTypeArgumentsInNestedEntityMapType: (args: Record<string, Type>, type: NestedEntityMapType) => NestedEntityMapType;
|
|
35
36
|
export declare const serializeNestedEntityMapType: Serializer<NestedEntityMapType, SerializedNestedEntityMapType>;
|
|
36
37
|
export declare const getReferencesForNestedEntityMapType: GetReferences<NestedEntityMapType>;
|
|
38
|
+
export declare const formatNestedEntityMapValue: StructureFormatter<NestedEntityMapType>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Lazy } from "../../../../shared/utils/lazy.js";
|
|
2
|
+
import { sortObjectKeysAlphabetically } from "../../../../shared/utils/object.js";
|
|
3
|
+
import { parallelizeErrors } from "../../../../shared/utils/validation.js";
|
|
2
4
|
import { wrapErrorsIfAny } from "../../../utils/error.js";
|
|
3
|
-
import { Lazy } from "../../../utils/lazy.js";
|
|
4
5
|
import { NodeKind } from "../../Node.js";
|
|
5
6
|
import { getNestedDeclarationsInObjectType, getReferencesForObjectType, resolveTypeArgumentsInObjectType, serializeObjectType, validateObjectType, } from "../generic/ObjectType.js";
|
|
6
7
|
import { removeParentKey } from "../Type.js";
|
|
@@ -54,3 +55,6 @@ export const getReferencesForNestedEntityMapType = (type, value) => typeof value
|
|
|
54
55
|
.flatMap(item => getReferencesForObjectType(type.type.value, item))
|
|
55
56
|
.concat(Object.keys(value))
|
|
56
57
|
: [];
|
|
58
|
+
export const formatNestedEntityMapValue = (_type, value) => typeof value === "object" && value !== null && !Array.isArray(value)
|
|
59
|
+
? sortObjectKeysAlphabetically(value)
|
|
60
|
+
: value;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { GetNestedDeclarations } from "../../declarations/Declaration.js";
|
|
2
|
-
import { EntityDecl } from "../../declarations/EntityDecl.js";
|
|
3
|
-
import { GetReferences, Node,
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import type { GetNestedDeclarations } from "../../declarations/Declaration.js";
|
|
2
|
+
import type { EntityDecl } from "../../declarations/EntityDecl.js";
|
|
3
|
+
import type { GetReferences, Node, Serializer } from "../../Node.js";
|
|
4
|
+
import { NodeKind } from "../../Node.js";
|
|
5
|
+
import type { Validator } from "../../validation/type.js";
|
|
6
|
+
import type { BaseType, SerializedBaseType, StructureFormatter, Type } from "../Type.js";
|
|
6
7
|
export interface ReferenceIdentifierType extends BaseType {
|
|
7
8
|
kind: NodeKind["ReferenceIdentifierType"];
|
|
8
9
|
entity: EntityDecl;
|
|
@@ -16,6 +17,7 @@ export { ReferenceIdentifierType as ReferenceIdentifier };
|
|
|
16
17
|
export declare const isReferenceIdentifierType: (node: Node) => node is ReferenceIdentifierType;
|
|
17
18
|
export declare const getNestedDeclarationsInReferenceIdentifierType: GetNestedDeclarations<ReferenceIdentifierType>;
|
|
18
19
|
export declare const validateReferenceIdentifierType: Validator<ReferenceIdentifierType>;
|
|
19
|
-
export declare const resolveTypeArgumentsInReferenceIdentifierType:
|
|
20
|
+
export declare const resolveTypeArgumentsInReferenceIdentifierType: (_args: Record<string, Type>, type: ReferenceIdentifierType) => ReferenceIdentifierType;
|
|
20
21
|
export declare const serializeReferenceIdentifierType: Serializer<ReferenceIdentifierType, SerializedReferenceIdentifierType>;
|
|
21
22
|
export declare const getReferencesForReferenceIdentifierType: GetReferences<ReferenceIdentifierType>;
|
|
23
|
+
export declare const formatReferenceIdentifierValue: StructureFormatter<ReferenceIdentifierType>;
|
|
@@ -21,3 +21,4 @@ export const serializeReferenceIdentifierType = type => ({
|
|
|
21
21
|
entity: type.entity.name,
|
|
22
22
|
});
|
|
23
23
|
export const getReferencesForReferenceIdentifierType = (_type, value) => (typeof value === "string" ? [value] : []);
|
|
24
|
+
export const formatReferenceIdentifierValue = (_type, value) => value;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { GetReferences, Node, Serializer } from "../../Node.js";
|
|
2
|
+
import { NodeKind } from "../../Node.js";
|
|
3
|
+
import type { SerializedTypeParameter, TypeParameter } from "../../TypeParameter.js";
|
|
4
|
+
import type { Validator } from "../../validation/type.js";
|
|
5
|
+
import type { BaseType, SerializedBaseType, StructureFormatter, Type } from "../Type.js";
|
|
6
|
+
type TConstraint = TypeParameter;
|
|
7
|
+
export interface TypeArgumentType<T extends TConstraint = TConstraint> extends BaseType {
|
|
8
|
+
kind: NodeKind["TypeArgumentType"];
|
|
9
|
+
argument: T;
|
|
10
|
+
}
|
|
11
|
+
type TSerializedConstraint = SerializedTypeParameter;
|
|
12
|
+
export interface SerializedTypeArgumentType<T extends TSerializedConstraint = TSerializedConstraint> extends SerializedBaseType {
|
|
13
|
+
kind: NodeKind["TypeArgumentType"];
|
|
14
|
+
argument: T;
|
|
15
|
+
}
|
|
16
|
+
export declare const TypeArgumentType: <T extends TConstraint>(argument: T) => TypeArgumentType<T>;
|
|
17
|
+
export { TypeArgumentType as TypeArgument };
|
|
18
|
+
export declare const isTypeArgumentType: (node: Node) => node is TypeArgumentType;
|
|
19
|
+
export declare const validateTypeArgumentType: Validator<TypeArgumentType>;
|
|
20
|
+
export declare const resolveTypeArgumentsInTypeArgumentType: <T extends TConstraint, Args extends Record<string, Type>>(args: Args, type: TypeArgumentType<T>) => Args[T["name"]];
|
|
21
|
+
export declare const serializeTypeArgumentType: Serializer<TypeArgumentType, SerializedTypeArgumentType>;
|
|
22
|
+
export declare const getReferencesForTypeArgumentType: GetReferences<TypeArgumentType>;
|
|
23
|
+
export declare const formatTypeArgumentValue: StructureFormatter<TypeArgumentType>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { NodeKind } from "../../Node.js";
|
|
2
|
+
import { serializeTypeParameter } from "../../TypeParameter.js";
|
|
3
|
+
import { removeParentKey } from "../Type.js";
|
|
4
|
+
export const TypeArgumentType = (argument) => ({
|
|
5
|
+
kind: NodeKind.TypeArgumentType,
|
|
6
|
+
argument,
|
|
7
|
+
});
|
|
8
|
+
export { TypeArgumentType as TypeArgument };
|
|
9
|
+
export const isTypeArgumentType = (node) => node.kind === NodeKind.TypeArgumentType;
|
|
10
|
+
export const validateTypeArgumentType = (_helpers, type, _value) => {
|
|
11
|
+
throw new TypeError(`generic argument "${type.argument.name}" has not been replaced with a concrete type`);
|
|
12
|
+
};
|
|
13
|
+
export const resolveTypeArgumentsInTypeArgumentType = (args, type) => args[type.argument.name];
|
|
14
|
+
export const serializeTypeArgumentType = type => ({
|
|
15
|
+
...removeParentKey(type),
|
|
16
|
+
argument: serializeTypeParameter(type.argument),
|
|
17
|
+
});
|
|
18
|
+
export const getReferencesForTypeArgumentType = (_type, _value) => [];
|
|
19
|
+
export const formatTypeArgumentValue = (_type, value) => value;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Validators } from "../Node.js";
|
|
2
|
+
import type { Type } from "../types/Type.js";
|
|
3
|
+
export type ValidatorHelpers = Validators;
|
|
4
|
+
export type Validator<T extends Type, Args extends unknown[] = []> = (helpers: ValidatorHelpers, type: T, value: unknown, ...args: Args) => Error[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const declarationsApi: import("express-serve-static-core").Router;
|