tsondb 0.1.3
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/README.md +3 -0
- package/lib/ModelContainer.d.ts +17 -0
- package/lib/ModelContainer.js +63 -0
- package/lib/Schema.d.ts +8 -0
- package/lib/Schema.js +72 -0
- package/lib/client/api.d.ts +11 -0
- package/lib/client/api.js +83 -0
- package/lib/client/components/Layout.d.ts +10 -0
- package/lib/client/components/Layout.js +4 -0
- package/lib/client/components/Select.d.ts +3 -0
- package/lib/client/components/Select.js +2 -0
- package/lib/client/components/typeInputs/ArrayTypeInput.d.ts +13 -0
- package/lib/client/components/typeInputs/ArrayTypeInput.js +10 -0
- package/lib/client/components/typeInputs/BooleanTypeInput.d.ts +9 -0
- package/lib/client/components/typeInputs/BooleanTypeInput.js +6 -0
- package/lib/client/components/typeInputs/DateTypeInput.d.ts +9 -0
- package/lib/client/components/typeInputs/DateTypeInput.js +9 -0
- package/lib/client/components/typeInputs/FloatTypeInput.d.ts +9 -0
- package/lib/client/components/typeInputs/FloatTypeInput.js +15 -0
- package/lib/client/components/typeInputs/GenericTypeArgumentIdentifierTypeInput.d.ts +7 -0
- package/lib/client/components/typeInputs/GenericTypeArgumentIdentifierTypeInput.js +4 -0
- package/lib/client/components/typeInputs/IncludeIdentifierTypeInput.d.ts +13 -0
- package/lib/client/components/typeInputs/IncludeIdentifierTypeInput.js +18 -0
- package/lib/client/components/typeInputs/IntegerTypeInput.d.ts +9 -0
- package/lib/client/components/typeInputs/IntegerTypeInput.js +15 -0
- package/lib/client/components/typeInputs/NestedEntityMapTypeInput.d.ts +13 -0
- package/lib/client/components/typeInputs/NestedEntityMapTypeInput.js +25 -0
- package/lib/client/components/typeInputs/ObjectTypeInput.d.ts +13 -0
- package/lib/client/components/typeInputs/ObjectTypeInput.js +20 -0
- package/lib/client/components/typeInputs/ReferenceIdentifierTypeInput.d.ts +11 -0
- package/lib/client/components/typeInputs/ReferenceIdentifierTypeInput.js +9 -0
- package/lib/client/components/typeInputs/StringTypeInput.d.ts +9 -0
- package/lib/client/components/typeInputs/StringTypeInput.js +10 -0
- package/lib/client/components/typeInputs/TypeInput.d.ts +13 -0
- package/lib/client/components/typeInputs/TypeInput.js +87 -0
- package/lib/client/components/typeInputs/utils/EnumDeclField.d.ts +13 -0
- package/lib/client/components/typeInputs/utils/EnumDeclField.js +38 -0
- package/lib/client/components/typeInputs/utils/MismatchingTypeError.d.ts +7 -0
- package/lib/client/components/typeInputs/utils/MismatchingTypeError.js +4 -0
- package/lib/client/components/typeInputs/utils/ValidationErrors.d.ts +6 -0
- package/lib/client/components/typeInputs/utils/ValidationErrors.js +4 -0
- package/lib/client/hooks/useEntityFromRoute.d.ts +5 -0
- package/lib/client/hooks/useEntityFromRoute.js +20 -0
- package/lib/client/hooks/useInstanceNamesByEntity.d.ts +3 -0
- package/lib/client/hooks/useInstanceNamesByEntity.js +18 -0
- package/lib/client/hooks/useSecondaryDeclarations.d.ts +3 -0
- package/lib/client/hooks/useSecondaryDeclarations.js +18 -0
- package/lib/client/index.d.ts +1 -0
- package/lib/client/index.js +11 -0
- package/lib/client/routes/CreateInstance.d.ts +2 -0
- package/lib/client/routes/CreateInstance.js +68 -0
- package/lib/client/routes/Entity.d.ts +2 -0
- package/lib/client/routes/Entity.js +47 -0
- package/lib/client/routes/Home.d.ts +2 -0
- package/lib/client/routes/Home.js +18 -0
- package/lib/client/routes/Instance.d.ts +2 -0
- package/lib/client/routes/Instance.js +73 -0
- package/lib/client/routes/NotFound.d.ts +2 -0
- package/lib/client/routes/NotFound.js +5 -0
- package/lib/client/utils/typeSkeleton.d.ts +3 -0
- package/lib/client/utils/typeSkeleton.js +51 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/renderers/Output.d.ts +4 -0
- package/lib/renderers/Output.js +1 -0
- package/lib/renderers/jsonschema/index.d.ts +6 -0
- package/lib/renderers/jsonschema/index.js +12 -0
- package/lib/renderers/jsonschema/render.d.ts +5 -0
- package/lib/renderers/jsonschema/render.js +156 -0
- package/lib/renderers/ts/index.d.ts +6 -0
- package/lib/renderers/ts/index.js +11 -0
- package/lib/renderers/ts/render.d.ts +5 -0
- package/lib/renderers/ts/render.js +109 -0
- package/lib/schema/Node.d.ts +37 -0
- package/lib/schema/Node.js +79 -0
- package/lib/schema/declarations/Declaration.d.ts +44 -0
- package/lib/schema/declarations/Declaration.js +98 -0
- package/lib/schema/declarations/EntityDecl.d.ts +73 -0
- package/lib/schema/declarations/EntityDecl.js +57 -0
- package/lib/schema/declarations/EnumDecl.d.ts +33 -0
- package/lib/schema/declarations/EnumDecl.js +104 -0
- package/lib/schema/declarations/TypeAliasDecl.d.ts +33 -0
- package/lib/schema/declarations/TypeAliasDecl.js +49 -0
- package/lib/schema/index.d.ts +20 -0
- package/lib/schema/index.js +20 -0
- package/lib/schema/parameters/TypeParameter.d.ts +14 -0
- package/lib/schema/parameters/TypeParameter.js +11 -0
- package/lib/schema/types/Type.d.ts +42 -0
- package/lib/schema/types/Type.js +177 -0
- package/lib/schema/types/generic/ArrayType.d.ts +30 -0
- package/lib/schema/types/generic/ArrayType.js +38 -0
- package/lib/schema/types/generic/ObjectType.d.ts +47 -0
- package/lib/schema/types/generic/ObjectType.js +70 -0
- package/lib/schema/types/primitives/BooleanType.d.ts +15 -0
- package/lib/schema/types/primitives/BooleanType.js +15 -0
- package/lib/schema/types/primitives/DateType.d.ts +16 -0
- package/lib/schema/types/primitives/DateType.js +17 -0
- package/lib/schema/types/primitives/FloatType.d.ts +26 -0
- package/lib/schema/types/primitives/FloatType.js +17 -0
- package/lib/schema/types/primitives/IntegerType.d.ts +26 -0
- package/lib/schema/types/primitives/IntegerType.js +21 -0
- package/lib/schema/types/primitives/NumericType.d.ts +6 -0
- package/lib/schema/types/primitives/NumericType.js +2 -0
- package/lib/schema/types/primitives/PrimitiveType.d.ts +6 -0
- package/lib/schema/types/primitives/PrimitiveType.js +1 -0
- package/lib/schema/types/primitives/StringType.d.ts +25 -0
- package/lib/schema/types/primitives/StringType.js +20 -0
- package/lib/schema/types/references/GenericArgumentIdentifierType.d.ts +21 -0
- package/lib/schema/types/references/GenericArgumentIdentifierType.js +18 -0
- package/lib/schema/types/references/IncludeIdentifierType.d.ts +28 -0
- package/lib/schema/types/references/IncludeIdentifierType.js +25 -0
- package/lib/schema/types/references/NestedEntityMapType.d.ts +36 -0
- package/lib/schema/types/references/NestedEntityMapType.js +67 -0
- package/lib/schema/types/references/ReferenceIdentifierType.d.ts +23 -0
- package/lib/schema/types/references/ReferenceIdentifierType.js +21 -0
- package/lib/schema/validation/options.d.ts +4 -0
- package/lib/schema/validation/options.js +12 -0
- package/lib/schema/validation/type.d.ts +4 -0
- package/lib/schema/validation/type.js +1 -0
- package/lib/server/index.d.ts +8 -0
- package/lib/server/index.js +207 -0
- package/lib/server/instanceOperations.d.ts +7 -0
- package/lib/server/instanceOperations.js +67 -0
- package/lib/shared/api.d.ts +42 -0
- package/lib/shared/api.js +1 -0
- package/lib/shared/enum.d.ts +1 -0
- package/lib/shared/enum.js +1 -0
- package/lib/shared/utils/compare.d.ts +13 -0
- package/lib/shared/utils/compare.js +24 -0
- package/lib/shared/utils/displayName.d.ts +2 -0
- package/lib/shared/utils/displayName.js +31 -0
- package/lib/shared/utils/instances.d.ts +6 -0
- package/lib/shared/utils/instances.js +1 -0
- package/lib/shared/utils/object.d.ts +2 -0
- package/lib/shared/utils/object.js +2 -0
- package/lib/shared/utils/string.d.ts +6 -0
- package/lib/shared/utils/string.js +52 -0
- package/lib/shared/utils/typeSafety.d.ts +1 -0
- package/lib/shared/utils/typeSafety.js +3 -0
- package/lib/shared/utils/validation.d.ts +3 -0
- package/lib/shared/utils/validation.js +14 -0
- package/lib/shared/validation/array.d.ts +6 -0
- package/lib/shared/validation/array.js +29 -0
- package/lib/shared/validation/date.d.ts +4 -0
- package/lib/shared/validation/date.js +13 -0
- package/lib/shared/validation/identifier.d.ts +1 -0
- package/lib/shared/validation/identifier.js +7 -0
- package/lib/shared/validation/number.d.ts +12 -0
- package/lib/shared/validation/number.js +34 -0
- package/lib/shared/validation/object.d.ts +6 -0
- package/lib/shared/validation/object.js +13 -0
- package/lib/shared/validation/string.d.ts +6 -0
- package/lib/shared/validation/string.js +15 -0
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/lib/utils/enum.d.ts +6 -0
- package/lib/utils/enum.js +1 -0
- package/lib/utils/error.d.ts +2 -0
- package/lib/utils/error.js +18 -0
- package/lib/utils/instances.d.ts +4 -0
- package/lib/utils/instances.js +12 -0
- package/lib/utils/lazy.d.ts +16 -0
- package/lib/utils/lazy.js +32 -0
- package/lib/utils/object.d.ts +3 -0
- package/lib/utils/object.js +1 -0
- package/lib/utils/render.d.ts +4 -0
- package/lib/utils/render.js +8 -0
- package/lib/utils/result.d.ts +57 -0
- package/lib/utils/result.js +48 -0
- package/package.json +46 -0
- package/public/css/styles.css +418 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ObjectConstraints } from "../../../shared/validation/object.js";
|
|
2
|
+
import { GetNestedDeclarations } from "../../declarations/Declaration.js";
|
|
3
|
+
import { GetReferences, Node, NodeKind, Serializer } from "../../Node.js";
|
|
4
|
+
import { Validator } from "../../validation/type.js";
|
|
5
|
+
import { BaseType, SerializedBaseType, SerializedType, Type } from "../Type.js";
|
|
6
|
+
type TConstraint = Record<string, MemberDecl<Type, boolean>>;
|
|
7
|
+
export interface ObjectType<T extends TConstraint = TConstraint> extends BaseType, ObjectConstraints {
|
|
8
|
+
kind: NodeKind["ObjectType"];
|
|
9
|
+
properties: T;
|
|
10
|
+
}
|
|
11
|
+
type TSerializedConstraint = Record<string, SerializedMemberDecl<SerializedType, boolean>>;
|
|
12
|
+
export interface SerializedObjectType<T extends TSerializedConstraint = TSerializedConstraint> extends SerializedBaseType, ObjectConstraints {
|
|
13
|
+
kind: NodeKind["ObjectType"];
|
|
14
|
+
properties: T;
|
|
15
|
+
}
|
|
16
|
+
export declare const ObjectType: <T extends TConstraint>(properties: T, options?: {
|
|
17
|
+
additionalProperties?: boolean;
|
|
18
|
+
minProperties?: number;
|
|
19
|
+
maxProperties?: number;
|
|
20
|
+
}) => ObjectType<T>;
|
|
21
|
+
export { ObjectType as Object };
|
|
22
|
+
export declare const isObjectType: (node: Node) => node is ObjectType;
|
|
23
|
+
export declare const getNestedDeclarationsInObjectType: GetNestedDeclarations<ObjectType>;
|
|
24
|
+
export declare const validateObjectType: Validator<ObjectType>;
|
|
25
|
+
export declare const resolveTypeArgumentsInObjectType: (args: Record<string, Type>, type: ObjectType) => ObjectType;
|
|
26
|
+
export interface MemberDecl<T extends Type = Type, R extends boolean = boolean> {
|
|
27
|
+
kind: NodeKind["MemberDecl"];
|
|
28
|
+
isRequired: R;
|
|
29
|
+
type: T;
|
|
30
|
+
comment?: string;
|
|
31
|
+
}
|
|
32
|
+
export interface SerializedMemberDecl<T extends SerializedType = SerializedType, R extends boolean = boolean> {
|
|
33
|
+
kind: NodeKind["MemberDecl"];
|
|
34
|
+
isRequired: R;
|
|
35
|
+
type: T;
|
|
36
|
+
comment?: string;
|
|
37
|
+
}
|
|
38
|
+
export declare const Required: <T extends Type>(options: {
|
|
39
|
+
comment?: string;
|
|
40
|
+
type: T;
|
|
41
|
+
}) => MemberDecl<T, true>;
|
|
42
|
+
export declare const Optional: <T extends Type>(options: {
|
|
43
|
+
comment?: string;
|
|
44
|
+
type: T;
|
|
45
|
+
}) => MemberDecl<T, false>;
|
|
46
|
+
export declare const serializeObjectType: Serializer<ObjectType, SerializedObjectType>;
|
|
47
|
+
export declare const getReferencesForObjectType: GetReferences<ObjectType>;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { parallelizeErrors } from "../../../shared/utils/validation.js";
|
|
2
|
+
import { validateObjectConstraints } from "../../../shared/validation/object.js";
|
|
3
|
+
import { wrapErrorsIfAny } from "../../../utils/error.js";
|
|
4
|
+
import { getNestedDeclarations } from "../../declarations/Declaration.js";
|
|
5
|
+
import { NodeKind } from "../../Node.js";
|
|
6
|
+
import { validateOption } from "../../validation/options.js";
|
|
7
|
+
import { getReferencesForType, removeParentKey, resolveTypeArgumentsInType, serializeType, validate, } from "../Type.js";
|
|
8
|
+
const keyPattern = /^[a-zA-Z0-9][a-zA-Z0-9_]*$/;
|
|
9
|
+
export const ObjectType = (properties, options = {}) => {
|
|
10
|
+
const type = {
|
|
11
|
+
...options,
|
|
12
|
+
kind: NodeKind.ObjectType,
|
|
13
|
+
minProperties: validateOption(options.minProperties, "minProperties", option => Number.isInteger(option) && option >= 0),
|
|
14
|
+
maxProperties: validateOption(options.maxProperties, "maxProperties", option => Number.isInteger(option) && option >= 0),
|
|
15
|
+
properties,
|
|
16
|
+
};
|
|
17
|
+
Object.keys(properties).forEach(key => {
|
|
18
|
+
if (!keyPattern.test(key)) {
|
|
19
|
+
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
|
+
properties[key].type.parent = type;
|
|
22
|
+
});
|
|
23
|
+
return type;
|
|
24
|
+
};
|
|
25
|
+
export { ObjectType as Object };
|
|
26
|
+
export const isObjectType = (node) => node.kind === NodeKind.ObjectType;
|
|
27
|
+
export const getNestedDeclarationsInObjectType = (isDeclAdded, type) => Object.values(type.properties).flatMap(prop => getNestedDeclarations(isDeclAdded, prop.type));
|
|
28
|
+
export const validateObjectType = (helpers, type, value) => {
|
|
29
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
30
|
+
return [TypeError(`expected an object, but got ${JSON.stringify(value)}`)];
|
|
31
|
+
}
|
|
32
|
+
const expectedKeys = Object.keys(type.properties);
|
|
33
|
+
return parallelizeErrors([
|
|
34
|
+
...validateObjectConstraints(type, expectedKeys, value),
|
|
35
|
+
...expectedKeys.map(key => {
|
|
36
|
+
const prop = type.properties[key];
|
|
37
|
+
if (prop.isRequired && !(key in value)) {
|
|
38
|
+
return TypeError(`missing required property "${key}"`);
|
|
39
|
+
}
|
|
40
|
+
else if (prop.isRequired || value[key] !== undefined) {
|
|
41
|
+
return wrapErrorsIfAny(`at object key "${key}"`, validate(helpers, prop.type, value[key]));
|
|
42
|
+
}
|
|
43
|
+
return undefined;
|
|
44
|
+
}),
|
|
45
|
+
]);
|
|
46
|
+
};
|
|
47
|
+
export const resolveTypeArgumentsInObjectType = (args, type) => ObjectType(Object.fromEntries(Object.entries(type.properties).map(([key, config]) => [key, { ...config, type: resolveTypeArgumentsInType(args, config.type) }])), {
|
|
48
|
+
...type,
|
|
49
|
+
});
|
|
50
|
+
const MemberDecl = (isRequired, type, comment) => ({
|
|
51
|
+
kind: NodeKind.MemberDecl,
|
|
52
|
+
isRequired,
|
|
53
|
+
type,
|
|
54
|
+
comment,
|
|
55
|
+
});
|
|
56
|
+
export const Required = (options) => MemberDecl(true, options.type, options.comment);
|
|
57
|
+
export const Optional = (options) => MemberDecl(false, options.type, options.comment);
|
|
58
|
+
export const serializeObjectType = type => ({
|
|
59
|
+
...removeParentKey(type),
|
|
60
|
+
properties: Object.fromEntries(Object.entries(type.properties).map(([key, prop]) => [
|
|
61
|
+
key,
|
|
62
|
+
{
|
|
63
|
+
...prop,
|
|
64
|
+
type: serializeType(prop.type),
|
|
65
|
+
},
|
|
66
|
+
])),
|
|
67
|
+
});
|
|
68
|
+
export const getReferencesForObjectType = (type, value) => typeof value === "object" && value !== null
|
|
69
|
+
? Object.entries(value).flatMap(([key, propValue]) => key in type.properties ? getReferencesForType(type.properties[key].type, propValue) : [])
|
|
70
|
+
: [];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { GetReferences, Node, NodeKind, Serializer } from "../../Node.js";
|
|
2
|
+
import { Validator } from "../../validation/type.js";
|
|
3
|
+
import { BaseType, SerializedBaseType } from "../Type.js";
|
|
4
|
+
export interface BooleanType extends BaseType {
|
|
5
|
+
kind: NodeKind["BooleanType"];
|
|
6
|
+
}
|
|
7
|
+
export interface SerializedBooleanType extends SerializedBaseType {
|
|
8
|
+
kind: NodeKind["BooleanType"];
|
|
9
|
+
}
|
|
10
|
+
export declare const BooleanType: () => BooleanType;
|
|
11
|
+
export { BooleanType as Boolean };
|
|
12
|
+
export declare const isBooleanType: (node: Node) => node is BooleanType;
|
|
13
|
+
export declare const validateBooleanType: Validator<BooleanType>;
|
|
14
|
+
export declare const serializeBooleanType: Serializer<BooleanType, SerializedBooleanType>;
|
|
15
|
+
export declare const getReferencesForBooleanType: GetReferences<BooleanType>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { NodeKind } from "../../Node.js";
|
|
2
|
+
import { removeParentKey } from "../Type.js";
|
|
3
|
+
export const BooleanType = () => ({
|
|
4
|
+
kind: NodeKind.BooleanType,
|
|
5
|
+
});
|
|
6
|
+
export { BooleanType as Boolean };
|
|
7
|
+
export const isBooleanType = (node) => node.kind === NodeKind.BooleanType;
|
|
8
|
+
export const validateBooleanType = (_helpers, _type, value) => {
|
|
9
|
+
if (typeof value !== "boolean") {
|
|
10
|
+
return [TypeError(`expected a boolean value, but got ${JSON.stringify(value)}`)];
|
|
11
|
+
}
|
|
12
|
+
return [];
|
|
13
|
+
};
|
|
14
|
+
export const serializeBooleanType = type => removeParentKey(type);
|
|
15
|
+
export const getReferencesForBooleanType = (_type, _value) => [];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { DateConstraints } from "../../../shared/validation/date.js";
|
|
2
|
+
import { GetReferences, Node, NodeKind, Serializer } from "../../Node.js";
|
|
3
|
+
import { Validator } from "../../validation/type.js";
|
|
4
|
+
import { BaseType, SerializedBaseType } from "../Type.js";
|
|
5
|
+
export interface DateType extends BaseType, DateConstraints {
|
|
6
|
+
kind: NodeKind["DateType"];
|
|
7
|
+
}
|
|
8
|
+
export interface SerializedDateType extends SerializedBaseType, DateConstraints {
|
|
9
|
+
kind: NodeKind["DateType"];
|
|
10
|
+
}
|
|
11
|
+
export declare const DateType: (options?: DateConstraints) => DateType;
|
|
12
|
+
export { DateType as Date };
|
|
13
|
+
export declare const isDateType: (node: Node) => node is DateType;
|
|
14
|
+
export declare const validateDateType: Validator<DateType>;
|
|
15
|
+
export declare const serializeDateType: Serializer<DateType, SerializedDateType>;
|
|
16
|
+
export declare const getReferencesForDateType: GetReferences<DateType>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { validateDateConstraints } from "../../../shared/validation/date.js";
|
|
2
|
+
import { NodeKind } from "../../Node.js";
|
|
3
|
+
import { removeParentKey } from "../Type.js";
|
|
4
|
+
export const DateType = (options) => ({
|
|
5
|
+
...options,
|
|
6
|
+
kind: NodeKind.DateType,
|
|
7
|
+
});
|
|
8
|
+
export { DateType as Date };
|
|
9
|
+
export const isDateType = (node) => node.kind === NodeKind.DateType;
|
|
10
|
+
export const validateDateType = (_helpers, type, value) => {
|
|
11
|
+
if (typeof value !== "string") {
|
|
12
|
+
return [TypeError(`expected a string, but got ${JSON.stringify(value)}`)];
|
|
13
|
+
}
|
|
14
|
+
return validateDateConstraints(type, value);
|
|
15
|
+
};
|
|
16
|
+
export const serializeDateType = type => removeParentKey(type);
|
|
17
|
+
export const getReferencesForDateType = (_type, _value) => [];
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { RangeBound } from "../../../shared/validation/number.js";
|
|
2
|
+
import { GetReferences, Node, NodeKind, Serializer } from "../../Node.js";
|
|
3
|
+
import { Validator } from "../../validation/type.js";
|
|
4
|
+
import { BaseType, SerializedBaseType } from "../Type.js";
|
|
5
|
+
export interface FloatType extends BaseType {
|
|
6
|
+
kind: NodeKind["FloatType"];
|
|
7
|
+
minimum?: RangeBound;
|
|
8
|
+
maximum?: RangeBound;
|
|
9
|
+
multipleOf?: number;
|
|
10
|
+
}
|
|
11
|
+
export interface SerializedFloatType extends SerializedBaseType {
|
|
12
|
+
kind: NodeKind["FloatType"];
|
|
13
|
+
minimum?: RangeBound;
|
|
14
|
+
maximum?: RangeBound;
|
|
15
|
+
multipleOf?: number;
|
|
16
|
+
}
|
|
17
|
+
export declare const FloatType: (options?: {
|
|
18
|
+
minimum?: RangeBound;
|
|
19
|
+
maximum?: RangeBound;
|
|
20
|
+
multipleOf?: number;
|
|
21
|
+
}) => FloatType;
|
|
22
|
+
export { FloatType as Float };
|
|
23
|
+
export declare const isFloatType: (node: Node) => node is FloatType;
|
|
24
|
+
export declare const validateFloatType: Validator<FloatType>;
|
|
25
|
+
export declare const serializeFloatType: Serializer<FloatType, SerializedFloatType>;
|
|
26
|
+
export declare const getReferencesForFloatType: GetReferences<FloatType>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { validateNumberConstraints } from "../../../shared/validation/number.js";
|
|
2
|
+
import { NodeKind } from "../../Node.js";
|
|
3
|
+
import { removeParentKey } from "../Type.js";
|
|
4
|
+
export const FloatType = (options = {}) => ({
|
|
5
|
+
...options,
|
|
6
|
+
kind: NodeKind.FloatType,
|
|
7
|
+
});
|
|
8
|
+
export { FloatType as Float };
|
|
9
|
+
export const isFloatType = (node) => node.kind === NodeKind.FloatType;
|
|
10
|
+
export const validateFloatType = (_helpers, type, value) => {
|
|
11
|
+
if (typeof value !== "number") {
|
|
12
|
+
return [TypeError(`expected a floating-point number, but got ${JSON.stringify(value)}`)];
|
|
13
|
+
}
|
|
14
|
+
return validateNumberConstraints(type, value);
|
|
15
|
+
};
|
|
16
|
+
export const serializeFloatType = type => removeParentKey(type);
|
|
17
|
+
export const getReferencesForFloatType = (_type, _value) => [];
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { RangeBound } from "../../../shared/validation/number.js";
|
|
2
|
+
import { GetReferences, Node, NodeKind, Serializer } from "../../Node.js";
|
|
3
|
+
import { Validator } from "../../validation/type.js";
|
|
4
|
+
import { BaseType, SerializedBaseType } from "../Type.js";
|
|
5
|
+
export interface IntegerType extends BaseType {
|
|
6
|
+
kind: NodeKind["IntegerType"];
|
|
7
|
+
minimum?: RangeBound;
|
|
8
|
+
maximum?: RangeBound;
|
|
9
|
+
multipleOf?: number;
|
|
10
|
+
}
|
|
11
|
+
export interface SerializedIntegerType extends SerializedBaseType {
|
|
12
|
+
kind: NodeKind["IntegerType"];
|
|
13
|
+
minimum?: RangeBound;
|
|
14
|
+
maximum?: RangeBound;
|
|
15
|
+
multipleOf?: number;
|
|
16
|
+
}
|
|
17
|
+
export declare const IntegerType: (options?: {
|
|
18
|
+
minimum?: RangeBound;
|
|
19
|
+
maximum?: RangeBound;
|
|
20
|
+
multipleOf?: number;
|
|
21
|
+
}) => IntegerType;
|
|
22
|
+
export { IntegerType as Integer };
|
|
23
|
+
export declare const isIntegerType: (node: Node) => node is IntegerType;
|
|
24
|
+
export declare const validateIntegerType: Validator<IntegerType>;
|
|
25
|
+
export declare const serializeIntegerType: Serializer<IntegerType, SerializedIntegerType>;
|
|
26
|
+
export declare const getReferencesForIntegerType: GetReferences<IntegerType>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { validateNumberConstraints } from "../../../shared/validation/number.js";
|
|
2
|
+
import { NodeKind } from "../../Node.js";
|
|
3
|
+
import { validateOption } from "../../validation/options.js";
|
|
4
|
+
import { removeParentKey } from "../Type.js";
|
|
5
|
+
const isIntegerRangeBoundOption = (option) => Number.isInteger(typeof option === "number" ? option : option.value);
|
|
6
|
+
export const IntegerType = (options = {}) => ({
|
|
7
|
+
kind: NodeKind.IntegerType,
|
|
8
|
+
minimum: validateOption(options.minimum, "minimum", isIntegerRangeBoundOption),
|
|
9
|
+
maximum: validateOption(options.maximum, "maximum", isIntegerRangeBoundOption),
|
|
10
|
+
multipleOf: options.multipleOf,
|
|
11
|
+
});
|
|
12
|
+
export { IntegerType as Integer };
|
|
13
|
+
export const isIntegerType = (node) => node.kind === NodeKind.IntegerType;
|
|
14
|
+
export const validateIntegerType = (_helpers, type, value) => {
|
|
15
|
+
if (typeof value !== "number" || !Number.isInteger(value)) {
|
|
16
|
+
return [TypeError(`expected an integer, but got ${JSON.stringify(value)}`)];
|
|
17
|
+
}
|
|
18
|
+
return validateNumberConstraints(type, value);
|
|
19
|
+
};
|
|
20
|
+
export const serializeIntegerType = type => removeParentKey(type);
|
|
21
|
+
export const getReferencesForIntegerType = (_type, _value) => [];
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { FloatType, SerializedFloatType } from "./FloatType.js";
|
|
2
|
+
import { IntegerType, SerializedIntegerType } from "./IntegerType.js";
|
|
3
|
+
export type NumericType = FloatType | IntegerType;
|
|
4
|
+
export type SerializedNumericType = SerializedFloatType | SerializedIntegerType;
|
|
5
|
+
export * from "./FloatType.js";
|
|
6
|
+
export * from "./IntegerType.js";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { BooleanType, SerializedBooleanType } from "./BooleanType.js";
|
|
2
|
+
import { DateType, SerializedDateType } from "./DateType.js";
|
|
3
|
+
import { NumericType, SerializedNumericType } from "./NumericType.js";
|
|
4
|
+
import { SerializedStringType, StringType } from "./StringType.js";
|
|
5
|
+
export type PrimitiveType = BooleanType | DateType | NumericType | StringType;
|
|
6
|
+
export type SerializedPrimitiveType = SerializedBooleanType | SerializedDateType | SerializedNumericType | SerializedStringType;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { StringConstraints } from "../../../shared/validation/string.js";
|
|
2
|
+
import { GetReferences, Node, NodeKind, Serializer } from "../../Node.js";
|
|
3
|
+
import { Validator } from "../../validation/type.js";
|
|
4
|
+
import { BaseType, SerializedBaseType } from "../Type.js";
|
|
5
|
+
export interface StringType extends BaseType, StringConstraints {
|
|
6
|
+
kind: NodeKind["StringType"];
|
|
7
|
+
pattern?: RegExp;
|
|
8
|
+
isMarkdown?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface SerializedStringType extends SerializedBaseType, StringConstraints {
|
|
11
|
+
kind: NodeKind["StringType"];
|
|
12
|
+
pattern?: string;
|
|
13
|
+
isMarkdown?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare const StringType: (options?: {
|
|
16
|
+
minLength?: number;
|
|
17
|
+
maxLength?: number;
|
|
18
|
+
pattern?: RegExp;
|
|
19
|
+
isMarkdown?: boolean;
|
|
20
|
+
}) => StringType;
|
|
21
|
+
export { StringType as String };
|
|
22
|
+
export declare const isStringType: (node: Node) => node is StringType;
|
|
23
|
+
export declare const validateStringType: Validator<StringType>;
|
|
24
|
+
export declare const serializeStringType: Serializer<StringType, SerializedStringType>;
|
|
25
|
+
export declare const getReferencesForStringType: GetReferences<StringType>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { validateStringConstraints } from "../../../shared/validation/string.js";
|
|
2
|
+
import { NodeKind } from "../../Node.js";
|
|
3
|
+
import { removeParentKey } from "../Type.js";
|
|
4
|
+
export const StringType = (options = {}) => ({
|
|
5
|
+
...options,
|
|
6
|
+
kind: NodeKind.StringType,
|
|
7
|
+
});
|
|
8
|
+
export { StringType as String };
|
|
9
|
+
export const isStringType = (node) => node.kind === NodeKind.StringType;
|
|
10
|
+
export const validateStringType = (_helpers, type, value) => {
|
|
11
|
+
if (typeof value !== "string") {
|
|
12
|
+
return [TypeError(`expected a string, but got ${JSON.stringify(value)}`)];
|
|
13
|
+
}
|
|
14
|
+
return validateStringConstraints(type, value);
|
|
15
|
+
};
|
|
16
|
+
export const serializeStringType = type => removeParentKey({
|
|
17
|
+
...type,
|
|
18
|
+
pattern: type.pattern?.source,
|
|
19
|
+
});
|
|
20
|
+
export const getReferencesForStringType = (_type, _value) => [];
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { GetReferences, Node, NodeKind, Serializer } from "../../Node.js";
|
|
2
|
+
import { SerializedTypeParameter, TypeParameter } from "../../parameters/TypeParameter.js";
|
|
3
|
+
import { Validator } from "../../validation/type.js";
|
|
4
|
+
import { BaseType, SerializedBaseType, Type } from "../Type.js";
|
|
5
|
+
type TConstraint = TypeParameter;
|
|
6
|
+
export interface GenericArgumentIdentifierType<T extends TConstraint = TConstraint> extends BaseType {
|
|
7
|
+
kind: NodeKind["GenericArgumentIdentifierType"];
|
|
8
|
+
argument: T;
|
|
9
|
+
}
|
|
10
|
+
type TSerializedConstraint = SerializedTypeParameter;
|
|
11
|
+
export interface SerializedGenericArgumentIdentifierType<T extends TSerializedConstraint = TSerializedConstraint> extends SerializedBaseType {
|
|
12
|
+
kind: NodeKind["GenericArgumentIdentifierType"];
|
|
13
|
+
argument: T;
|
|
14
|
+
}
|
|
15
|
+
export declare const GenericArgumentIdentifierType: <T extends TConstraint>(argument: T) => GenericArgumentIdentifierType<T>;
|
|
16
|
+
export { GenericArgumentIdentifierType as GenericArgumentIdentifier };
|
|
17
|
+
export declare const isGenericArgumentIdentifierType: (node: Node) => node is GenericArgumentIdentifierType;
|
|
18
|
+
export declare const validateGenericArgumentIdentifierType: Validator<GenericArgumentIdentifierType>;
|
|
19
|
+
export declare const resolveTypeArgumentsInGenericArgumentIdentifierType: <T extends TConstraint, Args extends Record<string, Type>>(args: Args, type: GenericArgumentIdentifierType<T>) => Args[T["name"]];
|
|
20
|
+
export declare const serializeGenericArgumentIdentifierType: Serializer<GenericArgumentIdentifierType, SerializedGenericArgumentIdentifierType>;
|
|
21
|
+
export declare const getReferencesForGenericArgumentIdentifierType: GetReferences<GenericArgumentIdentifierType>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { NodeKind } from "../../Node.js";
|
|
2
|
+
import { serializeTypeParameter, } from "../../parameters/TypeParameter.js";
|
|
3
|
+
import { removeParentKey } from "../Type.js";
|
|
4
|
+
export const GenericArgumentIdentifierType = (argument) => ({
|
|
5
|
+
kind: NodeKind.GenericArgumentIdentifierType,
|
|
6
|
+
argument,
|
|
7
|
+
});
|
|
8
|
+
export { GenericArgumentIdentifierType as GenericArgumentIdentifier };
|
|
9
|
+
export const isGenericArgumentIdentifierType = (node) => node.kind === NodeKind.GenericArgumentIdentifierType;
|
|
10
|
+
export const validateGenericArgumentIdentifierType = (_helpers, type, _value) => {
|
|
11
|
+
throw new TypeError(`generic argument "${type.argument.name}" has not been replaced with a concrete type`);
|
|
12
|
+
};
|
|
13
|
+
export const resolveTypeArgumentsInGenericArgumentIdentifierType = (args, type) => args[type.argument.name];
|
|
14
|
+
export const serializeGenericArgumentIdentifierType = type => ({
|
|
15
|
+
...removeParentKey(type),
|
|
16
|
+
argument: serializeTypeParameter(type.argument),
|
|
17
|
+
});
|
|
18
|
+
export const getReferencesForGenericArgumentIdentifierType = (_type, _value) => [];
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { GetNestedDeclarations, SerializedTypeArguments, TypeArguments } from "../../declarations/Declaration.js";
|
|
2
|
+
import { EnumDecl } from "../../declarations/EnumDecl.js";
|
|
3
|
+
import { TypeAliasDecl } from "../../declarations/TypeAliasDecl.js";
|
|
4
|
+
import { GetReferences, Node, NodeKind, Serializer } from "../../Node.js";
|
|
5
|
+
import { SerializedTypeParameter, TypeParameter } from "../../parameters/TypeParameter.js";
|
|
6
|
+
import { Validator } from "../../validation/type.js";
|
|
7
|
+
import { BaseType, SerializedBaseType, Type } from "../Type.js";
|
|
8
|
+
type TConstraint<Params extends TypeParameter[]> = TypeAliasDecl<string, Type, Params> | EnumDecl<string, Record<string, Type | null>, Params>;
|
|
9
|
+
export interface IncludeIdentifierType<Params extends TypeParameter[] = TypeParameter[], T extends TConstraint<Params> = TConstraint<Params>> extends BaseType {
|
|
10
|
+
kind: NodeKind["IncludeIdentifierType"];
|
|
11
|
+
reference: T;
|
|
12
|
+
args: TypeArguments<Params>;
|
|
13
|
+
}
|
|
14
|
+
export interface SerializedIncludeIdentifierType<Params extends SerializedTypeParameter[] = SerializedTypeParameter[]> extends SerializedBaseType {
|
|
15
|
+
kind: NodeKind["IncludeIdentifierType"];
|
|
16
|
+
reference: string;
|
|
17
|
+
args: SerializedTypeArguments<Params>;
|
|
18
|
+
}
|
|
19
|
+
export declare const GenIncludeIdentifierType: <T extends TConstraint<Params>, Params extends TypeParameter[] = []>(reference: T, args: TypeArguments<Params>) => IncludeIdentifierType<Params, T>;
|
|
20
|
+
export { GenIncludeIdentifierType as GenIncludeIdentifier };
|
|
21
|
+
export declare const IncludeIdentifierType: <T extends TConstraint<[]>>(reference: T) => IncludeIdentifierType<[], T>;
|
|
22
|
+
export { IncludeIdentifierType as IncludeIdentifier };
|
|
23
|
+
export declare const isIncludeIdentifierType: (node: Node) => node is IncludeIdentifierType;
|
|
24
|
+
export declare const getNestedDeclarationsInIncludeIdentifierType: GetNestedDeclarations<IncludeIdentifierType>;
|
|
25
|
+
export declare const validateIncludeIdentifierType: Validator<IncludeIdentifierType>;
|
|
26
|
+
export declare const resolveTypeArgumentsInIncludeIdentifierType: (args: Record<string, Type>, type: IncludeIdentifierType) => IncludeIdentifierType;
|
|
27
|
+
export declare const serializeIncludeIdentifierType: Serializer<IncludeIdentifierType, SerializedIncludeIdentifierType>;
|
|
28
|
+
export declare const getReferencesForIncludeIdentifierType: GetReferences<IncludeIdentifierType>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { getNestedDeclarations, getReferencesForDecl, resolveTypeArgumentsInDecl, validateDecl, } from "../../declarations/Declaration.js";
|
|
2
|
+
import { NodeKind } from "../../Node.js";
|
|
3
|
+
import { removeParentKey, resolveTypeArgumentsInType, serializeType, } from "../Type.js";
|
|
4
|
+
export const GenIncludeIdentifierType = (reference, args) => ({
|
|
5
|
+
kind: NodeKind.IncludeIdentifierType,
|
|
6
|
+
reference,
|
|
7
|
+
args,
|
|
8
|
+
});
|
|
9
|
+
export { GenIncludeIdentifierType as GenIncludeIdentifier };
|
|
10
|
+
export const IncludeIdentifierType = (reference) => ({
|
|
11
|
+
kind: NodeKind.IncludeIdentifierType,
|
|
12
|
+
reference,
|
|
13
|
+
args: [],
|
|
14
|
+
});
|
|
15
|
+
export { IncludeIdentifierType as IncludeIdentifier };
|
|
16
|
+
export const isIncludeIdentifierType = (node) => node.kind === NodeKind.IncludeIdentifierType;
|
|
17
|
+
export const getNestedDeclarationsInIncludeIdentifierType = (isDeclAdded, type) => [type.reference, ...getNestedDeclarations(isDeclAdded, type.reference)];
|
|
18
|
+
export const validateIncludeIdentifierType = (helpers, type, value) => validateDecl(helpers, type.reference, type.args, value);
|
|
19
|
+
export const resolveTypeArgumentsInIncludeIdentifierType = (args, type) => GenIncludeIdentifierType(type.reference, type.args.map(arg => resolveTypeArgumentsInType(args, arg)));
|
|
20
|
+
export const serializeIncludeIdentifierType = type => ({
|
|
21
|
+
...removeParentKey(type),
|
|
22
|
+
reference: type.reference.name,
|
|
23
|
+
args: type.args.map(arg => serializeType(arg)),
|
|
24
|
+
});
|
|
25
|
+
export const getReferencesForIncludeIdentifierType = (type, value) => getReferencesForDecl(resolveTypeArgumentsInDecl(type.reference, type.args), value);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Lazy } from "../../../utils/lazy.js";
|
|
2
|
+
import { GetNestedDeclarations } from "../../declarations/Declaration.js";
|
|
3
|
+
import { EntityDecl } from "../../declarations/EntityDecl.js";
|
|
4
|
+
import { GetReferences, Node, NodeKind, Serializer } from "../../Node.js";
|
|
5
|
+
import { Validator } from "../../validation/type.js";
|
|
6
|
+
import { MemberDecl, ObjectType, SerializedMemberDecl, SerializedObjectType } from "../generic/ObjectType.js";
|
|
7
|
+
import { BaseType, SerializedBaseType, SerializedType, Type } from "../Type.js";
|
|
8
|
+
type TConstraint = Record<string, MemberDecl<Type, boolean>>;
|
|
9
|
+
export interface NestedEntityMapType<Name extends string = string, T extends TConstraint = TConstraint> extends BaseType {
|
|
10
|
+
kind: NodeKind["NestedEntityMapType"];
|
|
11
|
+
name: Name;
|
|
12
|
+
comment?: string;
|
|
13
|
+
secondaryEntity: EntityDecl;
|
|
14
|
+
type: Lazy<ObjectType<T>>;
|
|
15
|
+
}
|
|
16
|
+
type TSerializedConstraint = Record<string, SerializedMemberDecl<SerializedType, boolean>>;
|
|
17
|
+
export interface SerializedNestedEntityMapType<Name extends string = string, T extends TSerializedConstraint = TSerializedConstraint> extends SerializedBaseType {
|
|
18
|
+
kind: NodeKind["NestedEntityMapType"];
|
|
19
|
+
name: Name;
|
|
20
|
+
comment?: string;
|
|
21
|
+
secondaryEntity: string;
|
|
22
|
+
type: SerializedObjectType<T>;
|
|
23
|
+
}
|
|
24
|
+
export declare const NestedEntityMapType: <Name extends string, T extends TConstraint>(options: {
|
|
25
|
+
name: Name;
|
|
26
|
+
comment?: string;
|
|
27
|
+
secondaryEntity: EntityDecl;
|
|
28
|
+
type: ObjectType<T>;
|
|
29
|
+
}) => NestedEntityMapType<Name, T>;
|
|
30
|
+
export { NestedEntityMapType as NestedEntityMap };
|
|
31
|
+
export declare const isNestedEntityMapType: (node: Node) => node is NestedEntityMapType;
|
|
32
|
+
export declare const getNestedDeclarationsInNestedEntityMapType: GetNestedDeclarations<NestedEntityMapType>;
|
|
33
|
+
export declare const validateNestedEntityMapType: Validator<NestedEntityMapType>;
|
|
34
|
+
export declare const resolveTypeArgumentsInNestedEntityMapType: (args: Record<string, Type>, type: NestedEntityMapType) => NestedEntityMapType;
|
|
35
|
+
export declare const serializeNestedEntityMapType: Serializer<NestedEntityMapType, SerializedNestedEntityMapType>;
|
|
36
|
+
export declare const getReferencesForNestedEntityMapType: GetReferences<NestedEntityMapType>;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { parallelizeErrors } from "../../../shared/utils/validation.js";
|
|
2
|
+
import { wrapErrorsIfAny } from "../../../utils/error.js";
|
|
3
|
+
import { Lazy } from "../../../utils/lazy.js";
|
|
4
|
+
import { isEntityDecl } from "../../declarations/EntityDecl.js";
|
|
5
|
+
import { NodeKind } from "../../Node.js";
|
|
6
|
+
import { getNestedDeclarationsInObjectType, getReferencesForObjectType, resolveTypeArgumentsInObjectType, serializeObjectType, validateObjectType, } from "../generic/ObjectType.js";
|
|
7
|
+
import { getParentDecl, removeParentKey, } from "../Type.js";
|
|
8
|
+
export const NestedEntityMapType = (options) => {
|
|
9
|
+
const nestedEntityMapType = {
|
|
10
|
+
...options,
|
|
11
|
+
kind: NodeKind.NestedEntityMapType,
|
|
12
|
+
type: Lazy.of(() => {
|
|
13
|
+
const parentDecl = getParentDecl(nestedEntityMapType);
|
|
14
|
+
if (!parentDecl) {
|
|
15
|
+
throw new Error("Parent declaration not found");
|
|
16
|
+
}
|
|
17
|
+
if (!isEntityDecl(parentDecl)) {
|
|
18
|
+
throw new Error(`Parent declaration "${parentDecl.name}" is not an entity declaration`);
|
|
19
|
+
}
|
|
20
|
+
const type = options.type;
|
|
21
|
+
type.parent = nestedEntityMapType;
|
|
22
|
+
return type;
|
|
23
|
+
}),
|
|
24
|
+
};
|
|
25
|
+
return nestedEntityMapType;
|
|
26
|
+
};
|
|
27
|
+
export { NestedEntityMapType as NestedEntityMap };
|
|
28
|
+
const _NestedEntityMapType = (options) => {
|
|
29
|
+
const nestedEntityMapType = {
|
|
30
|
+
...options,
|
|
31
|
+
kind: NodeKind.NestedEntityMapType,
|
|
32
|
+
type: Lazy.of(() => {
|
|
33
|
+
const type = options.type();
|
|
34
|
+
type.parent = nestedEntityMapType;
|
|
35
|
+
return type;
|
|
36
|
+
}),
|
|
37
|
+
};
|
|
38
|
+
return nestedEntityMapType;
|
|
39
|
+
};
|
|
40
|
+
export const isNestedEntityMapType = (node) => node.kind === NodeKind.NestedEntityMapType;
|
|
41
|
+
export const getNestedDeclarationsInNestedEntityMapType = (isDeclAdded, type) => [
|
|
42
|
+
type.secondaryEntity,
|
|
43
|
+
...getNestedDeclarationsInObjectType(isDeclAdded, type.type.value),
|
|
44
|
+
];
|
|
45
|
+
export const validateNestedEntityMapType = (helpers, type, value) => {
|
|
46
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
47
|
+
return [TypeError(`expected an object, but got ${JSON.stringify(value)}`)];
|
|
48
|
+
}
|
|
49
|
+
return parallelizeErrors(Object.keys(value).map(key => wrapErrorsIfAny(`at nested entity map "${type.name}" at key "${key}"`, validateObjectType(helpers, type.type.value, value[key]).concat(helpers.checkReferentialIntegrity({
|
|
50
|
+
name: type.secondaryEntity.name,
|
|
51
|
+
value: key,
|
|
52
|
+
})))));
|
|
53
|
+
};
|
|
54
|
+
export const resolveTypeArgumentsInNestedEntityMapType = (args, type) => _NestedEntityMapType({
|
|
55
|
+
...type,
|
|
56
|
+
type: () => resolveTypeArgumentsInObjectType(args, type.type.value),
|
|
57
|
+
});
|
|
58
|
+
export const serializeNestedEntityMapType = type => ({
|
|
59
|
+
...removeParentKey(type),
|
|
60
|
+
secondaryEntity: type.secondaryEntity.name,
|
|
61
|
+
type: serializeObjectType(type.type.value),
|
|
62
|
+
});
|
|
63
|
+
export const getReferencesForNestedEntityMapType = (type, value) => typeof value === "object" && value !== null && !Array.isArray(value)
|
|
64
|
+
? Object.values(value)
|
|
65
|
+
.flatMap(item => getReferencesForObjectType(type.type.value, item))
|
|
66
|
+
.concat(Object.keys(value))
|
|
67
|
+
: [];
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { GetNestedDeclarations } from "../../declarations/Declaration.js";
|
|
2
|
+
import { EntityDecl } from "../../declarations/EntityDecl.js";
|
|
3
|
+
import { GetReferences, Node, NodeKind, Serializer } from "../../Node.js";
|
|
4
|
+
import { Validator } from "../../validation/type.js";
|
|
5
|
+
import { MemberDecl, ObjectType } from "../generic/ObjectType.js";
|
|
6
|
+
import { BaseType, SerializedBaseType, Type } from "../Type.js";
|
|
7
|
+
type TConstraint = Record<string, MemberDecl<Type, boolean>>;
|
|
8
|
+
export interface ReferenceIdentifierType<Name extends string = string, T extends TConstraint = TConstraint> extends BaseType {
|
|
9
|
+
kind: NodeKind["ReferenceIdentifierType"];
|
|
10
|
+
entity: EntityDecl<Name, ObjectType<T>>;
|
|
11
|
+
}
|
|
12
|
+
export interface SerializedReferenceIdentifierType extends SerializedBaseType {
|
|
13
|
+
kind: NodeKind["ReferenceIdentifierType"];
|
|
14
|
+
entity: string;
|
|
15
|
+
}
|
|
16
|
+
export declare const ReferenceIdentifierType: <Name extends string, T extends TConstraint>(entity: EntityDecl<Name, ObjectType<T>>) => ReferenceIdentifierType<Name, T>;
|
|
17
|
+
export { ReferenceIdentifierType as ReferenceIdentifier };
|
|
18
|
+
export declare const isReferenceIdentifierType: (node: Node) => node is ReferenceIdentifierType;
|
|
19
|
+
export declare const getNestedDeclarationsInReferenceIdentifierType: GetNestedDeclarations<ReferenceIdentifierType>;
|
|
20
|
+
export declare const validateReferenceIdentifierType: Validator<ReferenceIdentifierType>;
|
|
21
|
+
export declare const resolveTypeArgumentsInReferenceIdentifierType: <Name extends string, T extends TConstraint, Args extends Record<string, Type>>(_args: Args, type: ReferenceIdentifierType<Name, T>) => ReferenceIdentifierType<Name, T>;
|
|
22
|
+
export declare const serializeReferenceIdentifierType: Serializer<ReferenceIdentifierType, SerializedReferenceIdentifierType>;
|
|
23
|
+
export declare const getReferencesForReferenceIdentifierType: GetReferences<ReferenceIdentifierType>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { getNestedDeclarations } from "../../declarations/Declaration.js";
|
|
2
|
+
import { createEntityIdentifierType } from "../../declarations/EntityDecl.js";
|
|
3
|
+
import { NodeKind } from "../../Node.js";
|
|
4
|
+
import { removeParentKey, validate } from "../Type.js";
|
|
5
|
+
export const ReferenceIdentifierType = (entity) => ({
|
|
6
|
+
kind: NodeKind.ReferenceIdentifierType,
|
|
7
|
+
entity,
|
|
8
|
+
});
|
|
9
|
+
export { ReferenceIdentifierType as ReferenceIdentifier };
|
|
10
|
+
export const isReferenceIdentifierType = (node) => node.kind === NodeKind.ReferenceIdentifierType;
|
|
11
|
+
export const getNestedDeclarationsInReferenceIdentifierType = (isDeclAdded, type) => [type.entity, ...getNestedDeclarations(isDeclAdded, type.entity)];
|
|
12
|
+
export const validateReferenceIdentifierType = (helpers, type, value) => validate(helpers, createEntityIdentifierType(), value).concat(helpers.checkReferentialIntegrity({
|
|
13
|
+
name: type.entity.name,
|
|
14
|
+
value: value,
|
|
15
|
+
}));
|
|
16
|
+
export const resolveTypeArgumentsInReferenceIdentifierType = (_args, type) => type;
|
|
17
|
+
export const serializeReferenceIdentifierType = type => ({
|
|
18
|
+
...removeParentKey(type),
|
|
19
|
+
entity: type.entity.name,
|
|
20
|
+
});
|
|
21
|
+
export const getReferencesForReferenceIdentifierType = (_type, value) => (typeof value === "string" ? [value] : []);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export class OptionError extends Error {
|
|
2
|
+
constructor(message) {
|
|
3
|
+
super(message);
|
|
4
|
+
this.name = "OptionError";
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
export const validateOption = (value, name, validator) => {
|
|
8
|
+
if (value == null || validator(value)) {
|
|
9
|
+
return value;
|
|
10
|
+
}
|
|
11
|
+
throw new OptionError(`Invalid value for "${name}": ${JSON.stringify(value)}`);
|
|
12
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Validators } from "../Node.js";
|
|
2
|
+
import { Type } from "../types/Type.js";
|
|
3
|
+
export type ValidatorHelpers = Validators;
|
|
4
|
+
export type Validator<T extends Type, Args extends any[] = []> = (helpers: ValidatorHelpers, type: T, value: unknown, ...args: Args) => Error[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|