tsondb 0.5.19 → 0.6.1
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/dist/src/bin/tsondb.js +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/node/config.d.ts +20 -0
- package/dist/src/node/config.js +5 -0
- package/dist/src/node/index.d.ts +3 -2
- package/dist/src/node/index.js +13 -8
- package/dist/src/node/renderers/jsonschema/render.d.ts +1 -1
- package/dist/src/node/renderers/jsonschema/render.js +12 -7
- package/dist/src/node/renderers/ts/render.d.ts +1 -1
- package/dist/src/node/renderers/ts/render.js +12 -6
- package/dist/src/node/schema/Node.d.ts +100 -29
- package/dist/src/node/schema/Node.js +268 -61
- package/dist/src/node/schema/Schema.js +96 -1
- package/dist/src/node/schema/TypeParameter.d.ts +7 -9
- package/dist/src/node/schema/TypeParameter.js +7 -5
- package/dist/src/node/schema/declarations/Declaration.d.ts +10 -28
- package/dist/src/node/schema/declarations/Declaration.js +8 -110
- package/dist/src/node/schema/declarations/EntityDecl.d.ts +48 -48
- package/dist/src/node/schema/declarations/EntityDecl.js +15 -12
- package/dist/src/node/schema/declarations/EnumDecl.d.ts +14 -17
- package/dist/src/node/schema/declarations/EnumDecl.js +12 -12
- package/dist/src/node/schema/declarations/TypeAliasDecl.d.ts +8 -14
- package/dist/src/node/schema/declarations/TypeAliasDecl.js +10 -11
- package/dist/src/node/schema/index.d.ts +0 -2
- package/dist/src/node/schema/index.js +0 -1
- package/dist/src/node/schema/types/Type.d.ts +19 -42
- package/dist/src/node/schema/types/Type.js +29 -167
- package/dist/src/node/schema/types/generic/ArrayType.d.ts +5 -14
- package/dist/src/node/schema/types/generic/ArrayType.js +15 -20
- package/dist/src/node/schema/types/generic/EnumType.d.ts +5 -17
- package/dist/src/node/schema/types/generic/EnumType.js +12 -20
- package/dist/src/node/schema/types/generic/ObjectType.d.ts +5 -19
- package/dist/src/node/schema/types/generic/ObjectType.js +11 -15
- package/dist/src/node/schema/types/primitives/BooleanType.d.ts +7 -8
- package/dist/src/node/schema/types/primitives/BooleanType.js +5 -4
- package/dist/src/node/schema/types/primitives/DateType.d.ts +6 -8
- package/dist/src/node/schema/types/primitives/DateType.js +5 -4
- package/dist/src/node/schema/types/primitives/FloatType.d.ts +9 -21
- package/dist/src/node/schema/types/primitives/FloatType.js +5 -4
- package/dist/src/node/schema/types/primitives/IntegerType.d.ts +9 -21
- package/dist/src/node/schema/types/primitives/IntegerType.js +5 -4
- package/dist/src/node/schema/types/primitives/StringType.d.ts +6 -10
- package/dist/src/node/schema/types/primitives/StringType.js +5 -4
- package/dist/src/node/schema/types/references/ChildEntitiesType.d.ts +18 -0
- package/dist/src/node/schema/types/references/ChildEntitiesType.js +18 -0
- package/dist/src/node/schema/types/references/IncludeIdentifierType.d.ts +7 -13
- package/dist/src/node/schema/types/references/IncludeIdentifierType.js +12 -12
- package/dist/src/node/schema/types/references/NestedEntityMapType.d.ts +7 -17
- package/dist/src/node/schema/types/references/NestedEntityMapType.js +11 -13
- package/dist/src/node/schema/types/references/ReferenceIdentifierType.d.ts +4 -10
- package/dist/src/node/schema/types/references/ReferenceIdentifierType.js +3 -5
- package/dist/src/node/schema/types/references/TypeArgumentType.d.ts +5 -10
- package/dist/src/node/schema/types/references/TypeArgumentType.js +10 -5
- package/dist/src/node/server/api/declarations.js +24 -6
- package/dist/src/node/server/api/index.js +11 -0
- package/dist/src/node/server/api/instances.js +9 -6
- package/dist/src/node/server/index.d.ts +6 -1
- package/dist/src/node/server/index.js +7 -3
- package/dist/src/node/server/init.d.ts +2 -1
- package/dist/src/node/server/init.js +11 -11
- package/dist/src/node/server/utils/childInstances.d.ts +4 -0
- package/dist/src/node/server/utils/childInstances.js +41 -0
- package/dist/src/node/server/utils/instanceOperations.d.ts +8 -0
- package/dist/src/node/server/utils/instanceOperations.js +107 -0
- package/dist/src/node/server/utils/locales.d.ts +2 -0
- package/dist/src/node/server/utils/locales.js +8 -0
- package/dist/src/node/utils/childInstances.d.ts +32 -0
- package/dist/src/node/utils/childInstances.js +164 -0
- package/dist/src/node/utils/displayName.d.ts +2 -1
- package/dist/src/node/utils/displayName.js +5 -4
- package/dist/src/node/utils/files.d.ts +5 -0
- package/dist/src/node/utils/files.js +9 -0
- package/dist/src/node/utils/instanceOperations.d.ts +14 -0
- package/dist/src/node/utils/instanceOperations.js +88 -0
- package/dist/src/node/utils/instances.d.ts +1 -1
- package/dist/src/node/utils/instances.js +12 -6
- package/dist/src/node/utils/references.d.ts +3 -1
- package/dist/src/node/utils/references.js +43 -18
- package/dist/src/node/utils/referencesWorker.d.ts +5 -0
- package/dist/src/node/utils/referencesWorker.js +22 -0
- package/dist/src/node/utils/workers.d.ts +15 -0
- package/dist/src/node/utils/workers.js +90 -0
- package/dist/src/shared/api.d.ts +14 -1
- package/dist/src/shared/schema/Node.d.ts +63 -0
- package/dist/src/shared/schema/Node.js +128 -0
- package/dist/src/shared/schema/TypeParameter.d.ts +9 -0
- package/dist/src/shared/schema/TypeParameter.js +2 -0
- package/dist/src/shared/schema/declarations/Declaration.d.ts +21 -0
- package/dist/src/shared/schema/declarations/Declaration.js +4 -0
- package/dist/src/shared/schema/declarations/EntityDecl.d.ts +32 -0
- package/dist/src/shared/schema/declarations/EntityDecl.js +8 -0
- package/dist/src/shared/schema/declarations/EnumDecl.d.ts +11 -0
- package/dist/src/shared/schema/declarations/EnumDecl.js +9 -0
- package/dist/src/shared/schema/declarations/TypeAliasDecl.d.ts +11 -0
- package/dist/src/shared/schema/declarations/TypeAliasDecl.js +7 -0
- package/dist/src/shared/schema/types/ArrayType.d.ts +11 -0
- package/dist/src/shared/schema/types/ArrayType.js +8 -0
- package/dist/src/shared/schema/types/BooleanType.d.ts +7 -0
- package/dist/src/shared/schema/types/BooleanType.js +2 -0
- package/dist/src/shared/schema/types/ChildEntitiesType.d.ts +8 -0
- package/dist/src/shared/schema/types/ChildEntitiesType.js +2 -0
- package/dist/src/shared/schema/types/DateType.d.ts +8 -0
- package/dist/src/shared/schema/types/DateType.js +2 -0
- package/dist/src/shared/schema/types/EnumType.d.ts +14 -0
- package/dist/src/shared/schema/types/EnumType.js +28 -0
- package/dist/src/shared/schema/types/FloatType.d.ts +11 -0
- package/dist/src/shared/schema/types/FloatType.js +2 -0
- package/dist/src/shared/schema/types/IncludeIdentifierType.d.ts +11 -0
- package/dist/src/shared/schema/types/IncludeIdentifierType.js +13 -0
- package/dist/src/shared/schema/types/IntegerType.d.ts +11 -0
- package/dist/src/shared/schema/types/IntegerType.js +2 -0
- package/dist/src/shared/schema/types/NestedEntityMapType.d.ts +17 -0
- package/dist/src/shared/schema/types/NestedEntityMapType.js +14 -0
- package/dist/src/shared/schema/types/ObjectType.d.ts +19 -0
- package/dist/src/shared/schema/types/ObjectType.js +14 -0
- package/dist/src/shared/schema/types/ReferenceIdentifierType.d.ts +8 -0
- package/dist/src/shared/schema/types/ReferenceIdentifierType.js +2 -0
- package/dist/src/shared/schema/types/StringType.d.ts +10 -0
- package/dist/src/shared/schema/types/StringType.js +2 -0
- package/dist/src/shared/schema/types/Type.d.ts +20 -0
- package/dist/src/shared/schema/types/TypeArgumentType.d.ts +12 -0
- package/dist/src/shared/schema/types/TypeArgumentType.js +7 -0
- package/dist/src/shared/utils/array.d.ts +4 -0
- package/dist/src/shared/utils/array.js +30 -0
- package/dist/src/shared/utils/async.d.ts +8 -0
- package/dist/src/shared/utils/async.js +35 -0
- package/dist/src/shared/utils/compare.js +3 -3
- package/dist/src/shared/utils/displayName.d.ts +6 -2
- package/dist/src/shared/utils/displayName.js +21 -8
- package/dist/src/shared/utils/instances.d.ts +2 -3
- package/dist/src/shared/utils/instances.js +3 -1
- package/dist/src/shared/utils/markdown.d.ts +4 -0
- package/dist/src/shared/utils/markdown.js +91 -4
- package/dist/src/shared/utils/object.d.ts +2 -0
- package/dist/src/shared/utils/object.js +2 -0
- package/dist/src/shared/utils/result.d.ts +8 -2
- package/dist/src/shared/utils/result.js +1 -1
- package/dist/src/web/api/declarations.d.ts +26 -0
- package/dist/src/web/api/declarations.js +51 -0
- package/dist/src/web/api/git.d.ts +14 -0
- package/dist/src/web/api/git.js +20 -0
- package/dist/src/web/api/index.d.ts +1 -0
- package/dist/src/web/api/index.js +2 -0
- package/dist/src/web/api/instances.d.ts +2 -0
- package/dist/src/web/api/instances.js +2 -0
- package/dist/src/web/components/Git.js +19 -16
- package/dist/src/web/components/InstanceRouteSkeleton.d.ts +42 -0
- package/dist/src/web/components/InstanceRouteSkeleton.js +114 -0
- package/dist/src/web/components/Layout.js +3 -2
- package/dist/src/web/components/ModalDialog.d.ts +2 -0
- package/dist/src/web/components/ModalDialog.js +16 -0
- package/dist/src/web/components/Select.d.ts +1 -2
- package/dist/src/web/components/Settings.d.ts +2 -0
- package/dist/src/web/components/Settings.js +47 -0
- package/dist/src/web/components/typeInputs/ArrayTypeInput.d.ts +3 -11
- package/dist/src/web/components/typeInputs/ArrayTypeInput.js +5 -4
- package/dist/src/web/components/typeInputs/BooleanTypeInput.d.ts +3 -6
- package/dist/src/web/components/typeInputs/BooleanTypeInput.js +2 -2
- package/dist/src/web/components/typeInputs/ChildEntitiesTypeInput.d.ts +6 -0
- package/dist/src/web/components/typeInputs/ChildEntitiesTypeInput.js +27 -0
- package/dist/src/web/components/typeInputs/DateTypeInput.d.ts +3 -6
- package/dist/src/web/components/typeInputs/DateTypeInput.js +2 -2
- package/dist/src/web/components/typeInputs/EnumTypeInput.d.ts +3 -11
- package/dist/src/web/components/typeInputs/EnumTypeInput.js +55 -22
- package/dist/src/web/components/typeInputs/FloatTypeInput.d.ts +3 -6
- package/dist/src/web/components/typeInputs/FloatTypeInput.js +2 -2
- package/dist/src/web/components/typeInputs/GenericTypeArgumentIdentifierTypeInput.d.ts +3 -4
- package/dist/src/web/components/typeInputs/IncludeIdentifierTypeInput.d.ts +3 -11
- package/dist/src/web/components/typeInputs/IncludeIdentifierTypeInput.js +3 -2
- package/dist/src/web/components/typeInputs/IntegerTypeInput.d.ts +3 -6
- package/dist/src/web/components/typeInputs/IntegerTypeInput.js +2 -2
- package/dist/src/web/components/typeInputs/NestedEntityMapTypeInput.d.ts +3 -11
- package/dist/src/web/components/typeInputs/NestedEntityMapTypeInput.js +5 -4
- package/dist/src/web/components/typeInputs/ObjectTypeInput.d.ts +3 -11
- package/dist/src/web/components/typeInputs/ObjectTypeInput.js +8 -5
- package/dist/src/web/components/typeInputs/ReferenceIdentifierTypeInput.d.ts +3 -8
- package/dist/src/web/components/typeInputs/ReferenceIdentifierTypeInput.js +2 -2
- package/dist/src/web/components/typeInputs/StringTypeInput.d.ts +3 -6
- package/dist/src/web/components/typeInputs/StringTypeInput.js +3 -3
- package/dist/src/web/components/typeInputs/TypeInput.d.ts +12 -4
- package/dist/src/web/components/typeInputs/TypeInput.js +22 -17
- package/dist/src/web/components/typeInputs/utils/ValidationErrors.d.ts +1 -0
- package/dist/src/web/components/typeInputs/utils/ValidationErrors.js +1 -3
- package/dist/src/web/context/config.d.ts +11 -0
- package/dist/src/web/context/config.js +6 -0
- package/dist/src/web/context/entities.d.ts +8 -5
- package/dist/src/web/context/entities.js +1 -1
- package/dist/src/web/context/settings.d.ts +8 -0
- package/dist/src/web/context/settings.js +10 -0
- package/dist/src/web/hooks/useEntityFromRoute.d.ts +1 -1
- package/dist/src/web/hooks/useEntityFromRoute.js +2 -2
- package/dist/src/web/hooks/useInstanceNamesByEntity.d.ts +1 -1
- package/dist/src/web/hooks/useInstanceNamesByEntity.js +4 -2
- package/dist/src/web/hooks/useMappedAPIResource.js +2 -4
- package/dist/src/web/hooks/useSecondaryDeclarations.d.ts +1 -1
- package/dist/src/web/hooks/useSecondaryDeclarations.js +8 -4
- package/dist/src/web/hooks/useSettings.d.ts +10 -0
- package/dist/src/web/hooks/useSettings.js +51 -0
- package/dist/src/web/index.js +11 -5
- package/dist/src/web/routes/CreateInstance.js +40 -79
- package/dist/src/web/routes/Entity.js +42 -19
- package/dist/src/web/routes/Home.js +24 -5
- package/dist/src/web/routes/Instance.js +34 -85
- package/dist/src/web/utils/InlineMarkdown.d.ts +1 -1
- package/dist/src/web/utils/InlineMarkdown.js +13 -1
- package/dist/src/web/utils/api.d.ts +25 -0
- package/dist/src/web/utils/api.js +34 -0
- package/dist/src/web/utils/typeSkeleton.d.ts +1 -1
- package/dist/src/web/utils/typeSkeleton.js +2 -0
- package/package.json +14 -13
- package/public/css/styles.css +171 -12
- package/dist/src/node/schema/types/primitives/NumericType.d.ts +0 -6
- package/dist/src/node/schema/types/primitives/NumericType.js +0 -2
- package/dist/src/node/schema/types/primitives/PrimitiveType.d.ts +0 -6
- package/dist/src/node/schema/validation/type.d.ts +0 -4
- package/dist/src/node/schema/validation/type.js +0 -1
- package/dist/src/node/server/api/instanceOperations.d.ts +0 -6
- package/dist/src/node/server/api/instanceOperations.js +0 -93
- package/dist/src/shared/config.d.ts +0 -11
- package/dist/src/shared/config.js +0 -1
- package/dist/src/web/api.d.ts +0 -24
- package/dist/src/web/api.js +0 -201
- /package/dist/src/{node/schema/types/primitives/PrimitiveType.js → shared/schema/types/Type.js} +0 -0
|
@@ -1,49 +1,55 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { NodeKind } from "../../shared/schema/Node.js";
|
|
2
2
|
import { assertExhaustive } from "../../shared/utils/typeSafety.js";
|
|
3
3
|
import { entity, json } from "../utils/errorFormatting.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
const
|
|
4
|
+
import { isDecl } from "./declarations/Declaration.js";
|
|
5
|
+
import { getNestedDeclarationsInEntityDecl, getReferencesForEntityDecl, resolveTypeArgumentsInEntityDecl, serializeEntityDecl, validateEntityDecl, } from "./declarations/EntityDecl.js";
|
|
6
|
+
import { getNestedDeclarationsInEnumDecl, getReferencesForEnumDecl, resolveTypeArgumentsInEnumDecl, serializeEnumDecl, validateEnumDecl, } from "./declarations/EnumDecl.js";
|
|
7
|
+
import { getNestedDeclarationsInTypeAliasDecl, getReferencesForTypeAliasDecl, resolveTypeArgumentsInTypeAliasDecl, serializeTypeAliasDecl, validateTypeAliasDecl, } from "./declarations/TypeAliasDecl.js";
|
|
8
|
+
import { getNestedDeclarationsInTypeParameter, getReferencesForTypeParameter, resolveTypeArgumentsInTypeParameter, serializeTypeParameter, } from "./TypeParameter.js";
|
|
9
|
+
import { getNestedDeclarationsInArrayType, getReferencesForArrayType, resolveTypeArgumentsInArrayType, serializeArrayType, validateArrayType, } from "./types/generic/ArrayType.js";
|
|
10
|
+
import { getNestedDeclarationsInEnumType, getReferencesForEnumType, resolveTypeArgumentsInEnumType, serializeEnumType, validateEnumType, } from "./types/generic/EnumType.js";
|
|
11
|
+
import { getNestedDeclarationsInObjectType, getReferencesForObjectType, resolveTypeArgumentsInObjectType, serializeObjectType, validateObjectType, } from "./types/generic/ObjectType.js";
|
|
12
|
+
import { getNestedDeclarationsInBooleanType, getReferencesForBooleanType, resolveTypeArgumentsInBooleanType, serializeBooleanType, validateBooleanType, } from "./types/primitives/BooleanType.js";
|
|
13
|
+
import { getNestedDeclarationsInDateType, getReferencesForDateType, resolveTypeArgumentsInDateType, serializeDateType, validateDateType, } from "./types/primitives/DateType.js";
|
|
14
|
+
import { getNestedDeclarationsInFloatType, getReferencesForFloatType, resolveTypeArgumentsInFloatType, serializeFloatType, validateFloatType, } from "./types/primitives/FloatType.js";
|
|
15
|
+
import { getNestedDeclarationsInIntegerType, getReferencesForIntegerType, resolveTypeArgumentsInIntegerType, serializeIntegerType, validateIntegerType, } from "./types/primitives/IntegerType.js";
|
|
16
|
+
import { getNestedDeclarationsInStringType, getReferencesForStringType, resolveTypeArgumentsInStringType, serializeStringType, validateStringType, } from "./types/primitives/StringType.js";
|
|
17
|
+
import { getNestedDeclarationsInChildEntitiesType, getReferencesForChildEntitiesType, resolveTypeArgumentsInChildEntitiesType, serializeChildEntitiesType, validateChildEntitiesType, } from "./types/references/ChildEntitiesType.js";
|
|
18
|
+
import { getNestedDeclarationsInIncludeIdentifierType, getReferencesForIncludeIdentifierType, resolveTypeArgumentsInIncludeIdentifierType, serializeIncludeIdentifierType, validateIncludeIdentifierType, } from "./types/references/IncludeIdentifierType.js";
|
|
19
|
+
import { getNestedDeclarationsInNestedEntityMapType, getReferencesForNestedEntityMapType, resolveTypeArgumentsInNestedEntityMapType, serializeNestedEntityMapType, validateNestedEntityMapType, } from "./types/references/NestedEntityMapType.js";
|
|
20
|
+
import { getNestedDeclarationsInReferenceIdentifierType, getReferencesForReferenceIdentifierType, resolveTypeArgumentsInReferenceIdentifierType, serializeReferenceIdentifierType, validateReferenceIdentifierType, } from "./types/references/ReferenceIdentifierType.js";
|
|
21
|
+
import { getNestedDeclarationsInTypeArgumentType, getReferencesForTypeArgumentType, resolveTypeArgumentsInTypeArgumentType, serializeTypeArgumentType, validateTypeArgumentType, } from "./types/references/TypeArgumentType.js";
|
|
22
|
+
export { NodeKind };
|
|
23
|
+
export const reduceNodes = (reducer, nodes, options = {}) => {
|
|
24
|
+
const { initialResults = [], followIncludes = false, followChildEntities = false } = options;
|
|
25
|
+
const reduceNodeTree = (parentNodes, node, collectedResults, reducedDecls) => {
|
|
26
26
|
switch (node.kind) {
|
|
27
|
-
case NodeKind.EntityDecl:
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
case NodeKind.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
case NodeKind.
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
case NodeKind.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
27
|
+
case NodeKind.EntityDecl:
|
|
28
|
+
case NodeKind.EnumDecl:
|
|
29
|
+
case NodeKind.TypeAliasDecl:
|
|
30
|
+
return reduceNodeTree([node], node.type.value, reducer(parentNodes, node, collectedResults), [...reducedDecls, node]);
|
|
31
|
+
case NodeKind.ArrayType:
|
|
32
|
+
return reduceNodeTree([...parentNodes, node], node.items, reducer(parentNodes, node, collectedResults), reducedDecls);
|
|
33
|
+
case NodeKind.ObjectType:
|
|
34
|
+
return Object.values(node.properties).reduce((collectedResultsAcc, prop) => reduceNodeTree([...parentNodes, node], prop.type, collectedResultsAcc.results, collectedResultsAcc.reducedDecls), { results: reducer(parentNodes, node, collectedResults), reducedDecls });
|
|
35
|
+
case NodeKind.EnumType:
|
|
36
|
+
return Object.values(node.values).reduce((collectedResultsAcc, caseDef) => caseDef.type === null
|
|
37
|
+
? collectedResultsAcc
|
|
38
|
+
: reduceNodeTree([...parentNodes, node], caseDef.type, collectedResultsAcc.results, collectedResultsAcc.reducedDecls), { results: reducer(parentNodes, node, collectedResults), reducedDecls });
|
|
39
|
+
case NodeKind.IncludeIdentifierType:
|
|
40
|
+
if (followIncludes && !reducedDecls.includes(node.reference)) {
|
|
41
|
+
return reduceNodeTree([], node.reference, reducer(parentNodes, node, collectedResults), reducedDecls);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
return { results: reducer(parentNodes, node, collectedResults), reducedDecls };
|
|
45
|
+
}
|
|
46
|
+
case NodeKind.ChildEntitiesType:
|
|
47
|
+
if (followChildEntities && !reducedDecls.includes(node.entity)) {
|
|
48
|
+
return reduceNodeTree([], node.entity, reducer(parentNodes, node, collectedResults), reducedDecls);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
return { results: reducer(parentNodes, node, collectedResults), reducedDecls };
|
|
52
|
+
}
|
|
47
53
|
case NodeKind.BooleanType:
|
|
48
54
|
case NodeKind.DateType:
|
|
49
55
|
case NodeKind.FloatType:
|
|
@@ -51,30 +57,27 @@ export const flatMapAuxiliaryDecls = (callbackFn, declarations) => {
|
|
|
51
57
|
case NodeKind.StringType:
|
|
52
58
|
case NodeKind.TypeArgumentType:
|
|
53
59
|
case NodeKind.ReferenceIdentifierType:
|
|
54
|
-
case NodeKind.IncludeIdentifierType:
|
|
55
60
|
case NodeKind.NestedEntityMapType:
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const newDecls = callbackFn(node, decls);
|
|
59
|
-
return Object.values(node.values).reduce((newDeclsAcc, caseDef) => caseDef.type === null ? newDecls : mapNodeTree(callbackFn, caseDef.type, newDeclsAcc), newDecls);
|
|
60
|
-
}
|
|
61
|
+
case NodeKind.TypeParameter:
|
|
62
|
+
return { results: reducer(parentNodes, node, collectedResults), reducedDecls };
|
|
61
63
|
default:
|
|
62
64
|
return assertExhaustive(node);
|
|
63
65
|
}
|
|
64
66
|
};
|
|
65
|
-
|
|
66
|
-
const result = callbackFn(node, decls);
|
|
67
|
-
const normalizedResult = (Array.isArray(result) ? result : [result]).filter(decl => decl !== undefined);
|
|
68
|
-
normalizedResult.forEach(decl => {
|
|
69
|
-
const existingDeclWithSameName = decls.find(existingDecl => existingDecl !== decl && existingDecl.name === decl.name);
|
|
70
|
-
if (existingDeclWithSameName) {
|
|
71
|
-
throw new Error(`Duplicate declaration name: "${decl.name}" in "${decl.sourceUrl}" and "${existingDeclWithSameName.sourceUrl}". Make sure declaration names are globally unique.`);
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
return decls.concat(normalizedResult);
|
|
75
|
-
};
|
|
76
|
-
return declarations.reduce((decls, node) => mapNodeTree(reducer, node, [...decls, node]), []);
|
|
67
|
+
return nodes.reduce(({ results, reducedDecls }, node) => reduceNodeTree([], node, results, reducedDecls), { results: initialResults, reducedDecls: [] }).results;
|
|
77
68
|
};
|
|
69
|
+
export const flatMapAuxiliaryDecls = (callbackFn, declarations) => reduceNodes((parentNodes, node, decls) => {
|
|
70
|
+
const declsWithCurrentDecl = isDecl(node) ? [...decls, node] : decls;
|
|
71
|
+
const result = callbackFn(parentNodes, node, declsWithCurrentDecl);
|
|
72
|
+
const normalizedResult = (Array.isArray(result) ? result : [result]).filter(decl => decl !== undefined);
|
|
73
|
+
normalizedResult.forEach(decl => {
|
|
74
|
+
const existingDeclWithSameName = decls.find(existingDecl => existingDecl !== decl && existingDecl.name === decl.name);
|
|
75
|
+
if (existingDeclWithSameName) {
|
|
76
|
+
throw new Error(`Duplicate declaration name: "${decl.name}" in "${decl.sourceUrl}" and "${existingDeclWithSameName.sourceUrl}". Make sure declaration names are globally unique.`);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
return declsWithCurrentDecl.concat(normalizedResult);
|
|
80
|
+
}, declarations);
|
|
78
81
|
export const createValidators = (instancesByEntityName, useStyling, checkReferentialIntegrity = true) => ({
|
|
79
82
|
useStyling,
|
|
80
83
|
checkReferentialIntegrity: checkReferentialIntegrity
|
|
@@ -88,3 +91,207 @@ export const createValidators = (instancesByEntityName, useStyling, checkReferen
|
|
|
88
91
|
]
|
|
89
92
|
: () => [],
|
|
90
93
|
});
|
|
94
|
+
export const getNestedDeclarations = (addedDecls, node) => {
|
|
95
|
+
switch (node.kind) {
|
|
96
|
+
case NodeKind.EntityDecl:
|
|
97
|
+
return getNestedDeclarationsInEntityDecl(addedDecls, node);
|
|
98
|
+
case NodeKind.EnumDecl:
|
|
99
|
+
return getNestedDeclarationsInEnumDecl(addedDecls, node);
|
|
100
|
+
case NodeKind.TypeAliasDecl:
|
|
101
|
+
return getNestedDeclarationsInTypeAliasDecl(addedDecls, node);
|
|
102
|
+
case NodeKind.ArrayType:
|
|
103
|
+
return getNestedDeclarationsInArrayType(addedDecls, node);
|
|
104
|
+
case NodeKind.ObjectType:
|
|
105
|
+
return getNestedDeclarationsInObjectType(addedDecls, node);
|
|
106
|
+
case NodeKind.BooleanType:
|
|
107
|
+
return getNestedDeclarationsInBooleanType(addedDecls, node);
|
|
108
|
+
case NodeKind.DateType:
|
|
109
|
+
return getNestedDeclarationsInDateType(addedDecls, node);
|
|
110
|
+
case NodeKind.FloatType:
|
|
111
|
+
return getNestedDeclarationsInFloatType(addedDecls, node);
|
|
112
|
+
case NodeKind.IntegerType:
|
|
113
|
+
return getNestedDeclarationsInIntegerType(addedDecls, node);
|
|
114
|
+
case NodeKind.StringType:
|
|
115
|
+
return getNestedDeclarationsInStringType(addedDecls, node);
|
|
116
|
+
case NodeKind.TypeArgumentType:
|
|
117
|
+
return getNestedDeclarationsInTypeArgumentType(addedDecls, node);
|
|
118
|
+
case NodeKind.ReferenceIdentifierType:
|
|
119
|
+
return getNestedDeclarationsInReferenceIdentifierType(addedDecls, node);
|
|
120
|
+
case NodeKind.IncludeIdentifierType:
|
|
121
|
+
return getNestedDeclarationsInIncludeIdentifierType(addedDecls, node);
|
|
122
|
+
case NodeKind.NestedEntityMapType:
|
|
123
|
+
return getNestedDeclarationsInNestedEntityMapType(addedDecls, node);
|
|
124
|
+
case NodeKind.EnumType:
|
|
125
|
+
return getNestedDeclarationsInEnumType(addedDecls, node);
|
|
126
|
+
case NodeKind.TypeParameter:
|
|
127
|
+
return getNestedDeclarationsInTypeParameter(addedDecls, node);
|
|
128
|
+
case NodeKind.ChildEntitiesType:
|
|
129
|
+
return getNestedDeclarationsInChildEntitiesType(addedDecls, node);
|
|
130
|
+
default:
|
|
131
|
+
return assertExhaustive(node);
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
export const validateDecl = (helpers, decl, typeArgs, value) => {
|
|
135
|
+
switch (decl.kind) {
|
|
136
|
+
case NodeKind.EntityDecl:
|
|
137
|
+
return validateEntityDecl(helpers, decl, value);
|
|
138
|
+
case NodeKind.EnumDecl:
|
|
139
|
+
return validateEnumDecl(helpers, decl, typeArgs, value);
|
|
140
|
+
case NodeKind.TypeAliasDecl:
|
|
141
|
+
return validateTypeAliasDecl(helpers, decl, typeArgs, value);
|
|
142
|
+
default:
|
|
143
|
+
return assertExhaustive(decl);
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
export const validateType = (helpers, type, value) => {
|
|
147
|
+
switch (type.kind) {
|
|
148
|
+
case NodeKind.ArrayType:
|
|
149
|
+
return validateArrayType(helpers, type, value);
|
|
150
|
+
case NodeKind.ObjectType:
|
|
151
|
+
return validateObjectType(helpers, type, value);
|
|
152
|
+
case NodeKind.BooleanType:
|
|
153
|
+
return validateBooleanType(helpers, type, value);
|
|
154
|
+
case NodeKind.DateType:
|
|
155
|
+
return validateDateType(helpers, type, value);
|
|
156
|
+
case NodeKind.FloatType:
|
|
157
|
+
return validateFloatType(helpers, type, value);
|
|
158
|
+
case NodeKind.IntegerType:
|
|
159
|
+
return validateIntegerType(helpers, type, value);
|
|
160
|
+
case NodeKind.StringType:
|
|
161
|
+
return validateStringType(helpers, type, value);
|
|
162
|
+
case NodeKind.TypeArgumentType:
|
|
163
|
+
return validateTypeArgumentType(helpers, type, value);
|
|
164
|
+
case NodeKind.ReferenceIdentifierType:
|
|
165
|
+
return validateReferenceIdentifierType(helpers, type, value);
|
|
166
|
+
case NodeKind.IncludeIdentifierType:
|
|
167
|
+
return validateIncludeIdentifierType(helpers, type, value);
|
|
168
|
+
case NodeKind.NestedEntityMapType:
|
|
169
|
+
return validateNestedEntityMapType(helpers, type, value);
|
|
170
|
+
case NodeKind.EnumType:
|
|
171
|
+
return validateEnumType(helpers, type, value);
|
|
172
|
+
case NodeKind.ChildEntitiesType:
|
|
173
|
+
return validateChildEntitiesType(helpers, type, value);
|
|
174
|
+
default:
|
|
175
|
+
return assertExhaustive(type);
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
export const resolveTypeArguments = (args, node) => {
|
|
179
|
+
switch (node.kind) {
|
|
180
|
+
case NodeKind.EntityDecl:
|
|
181
|
+
return resolveTypeArgumentsInEntityDecl(args, node);
|
|
182
|
+
case NodeKind.EnumDecl:
|
|
183
|
+
return resolveTypeArgumentsInEnumDecl(args, node);
|
|
184
|
+
case NodeKind.TypeAliasDecl:
|
|
185
|
+
return resolveTypeArgumentsInTypeAliasDecl(args, node);
|
|
186
|
+
case NodeKind.ArrayType:
|
|
187
|
+
return resolveTypeArgumentsInArrayType(args, node);
|
|
188
|
+
case NodeKind.ObjectType:
|
|
189
|
+
return resolveTypeArgumentsInObjectType(args, node);
|
|
190
|
+
case NodeKind.BooleanType:
|
|
191
|
+
return resolveTypeArgumentsInBooleanType(args, node);
|
|
192
|
+
case NodeKind.DateType:
|
|
193
|
+
return resolveTypeArgumentsInDateType(args, node);
|
|
194
|
+
case NodeKind.FloatType:
|
|
195
|
+
return resolveTypeArgumentsInFloatType(args, node);
|
|
196
|
+
case NodeKind.IntegerType:
|
|
197
|
+
return resolveTypeArgumentsInIntegerType(args, node);
|
|
198
|
+
case NodeKind.StringType:
|
|
199
|
+
return resolveTypeArgumentsInStringType(args, node);
|
|
200
|
+
case NodeKind.TypeArgumentType:
|
|
201
|
+
return resolveTypeArgumentsInTypeArgumentType(args, node);
|
|
202
|
+
case NodeKind.ReferenceIdentifierType:
|
|
203
|
+
return resolveTypeArgumentsInReferenceIdentifierType(args, node);
|
|
204
|
+
case NodeKind.IncludeIdentifierType:
|
|
205
|
+
return resolveTypeArgumentsInIncludeIdentifierType(args, node);
|
|
206
|
+
case NodeKind.NestedEntityMapType:
|
|
207
|
+
return resolveTypeArgumentsInNestedEntityMapType(args, node);
|
|
208
|
+
case NodeKind.EnumType:
|
|
209
|
+
return resolveTypeArgumentsInEnumType(args, node);
|
|
210
|
+
case NodeKind.TypeParameter:
|
|
211
|
+
return resolveTypeArgumentsInTypeParameter(args, node);
|
|
212
|
+
case NodeKind.ChildEntitiesType:
|
|
213
|
+
return resolveTypeArgumentsInChildEntitiesType(args, node);
|
|
214
|
+
default:
|
|
215
|
+
return assertExhaustive(node);
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
export const serializeNode = (node) => {
|
|
219
|
+
switch (node.kind) {
|
|
220
|
+
case NodeKind.EntityDecl:
|
|
221
|
+
return serializeEntityDecl(node);
|
|
222
|
+
case NodeKind.EnumDecl:
|
|
223
|
+
return serializeEnumDecl(node);
|
|
224
|
+
case NodeKind.TypeAliasDecl:
|
|
225
|
+
return serializeTypeAliasDecl(node);
|
|
226
|
+
case NodeKind.ArrayType:
|
|
227
|
+
return serializeArrayType(node);
|
|
228
|
+
case NodeKind.ObjectType:
|
|
229
|
+
return serializeObjectType(node);
|
|
230
|
+
case NodeKind.BooleanType:
|
|
231
|
+
return serializeBooleanType(node);
|
|
232
|
+
case NodeKind.DateType:
|
|
233
|
+
return serializeDateType(node);
|
|
234
|
+
case NodeKind.FloatType:
|
|
235
|
+
return serializeFloatType(node);
|
|
236
|
+
case NodeKind.IntegerType:
|
|
237
|
+
return serializeIntegerType(node);
|
|
238
|
+
case NodeKind.StringType:
|
|
239
|
+
return serializeStringType(node);
|
|
240
|
+
case NodeKind.TypeArgumentType:
|
|
241
|
+
return serializeTypeArgumentType(node);
|
|
242
|
+
case NodeKind.ReferenceIdentifierType:
|
|
243
|
+
return serializeReferenceIdentifierType(node);
|
|
244
|
+
case NodeKind.IncludeIdentifierType:
|
|
245
|
+
return serializeIncludeIdentifierType(node);
|
|
246
|
+
case NodeKind.NestedEntityMapType:
|
|
247
|
+
return serializeNestedEntityMapType(node);
|
|
248
|
+
case NodeKind.EnumType:
|
|
249
|
+
return serializeEnumType(node);
|
|
250
|
+
case NodeKind.TypeParameter:
|
|
251
|
+
return serializeTypeParameter(node);
|
|
252
|
+
case NodeKind.ChildEntitiesType:
|
|
253
|
+
return serializeChildEntitiesType(node);
|
|
254
|
+
default:
|
|
255
|
+
return assertExhaustive(node);
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
export const getReferences = (node, value) => {
|
|
259
|
+
switch (node.kind) {
|
|
260
|
+
case NodeKind.EntityDecl:
|
|
261
|
+
return getReferencesForEntityDecl(node, value);
|
|
262
|
+
case NodeKind.EnumDecl:
|
|
263
|
+
return getReferencesForEnumDecl(node, value);
|
|
264
|
+
case NodeKind.TypeAliasDecl:
|
|
265
|
+
return getReferencesForTypeAliasDecl(node, value);
|
|
266
|
+
case NodeKind.ArrayType:
|
|
267
|
+
return getReferencesForArrayType(node, value);
|
|
268
|
+
case NodeKind.ObjectType:
|
|
269
|
+
return getReferencesForObjectType(node, value);
|
|
270
|
+
case NodeKind.BooleanType:
|
|
271
|
+
return getReferencesForBooleanType(node, value);
|
|
272
|
+
case NodeKind.DateType:
|
|
273
|
+
return getReferencesForDateType(node, value);
|
|
274
|
+
case NodeKind.FloatType:
|
|
275
|
+
return getReferencesForFloatType(node, value);
|
|
276
|
+
case NodeKind.IntegerType:
|
|
277
|
+
return getReferencesForIntegerType(node, value);
|
|
278
|
+
case NodeKind.StringType:
|
|
279
|
+
return getReferencesForStringType(node, value);
|
|
280
|
+
case NodeKind.TypeArgumentType:
|
|
281
|
+
return getReferencesForTypeArgumentType(node, value);
|
|
282
|
+
case NodeKind.ReferenceIdentifierType:
|
|
283
|
+
return getReferencesForReferenceIdentifierType(node, value);
|
|
284
|
+
case NodeKind.IncludeIdentifierType:
|
|
285
|
+
return getReferencesForIncludeIdentifierType(node, value);
|
|
286
|
+
case NodeKind.NestedEntityMapType:
|
|
287
|
+
return getReferencesForNestedEntityMapType(node, value);
|
|
288
|
+
case NodeKind.EnumType:
|
|
289
|
+
return getReferencesForEnumType(node, value);
|
|
290
|
+
case NodeKind.TypeParameter:
|
|
291
|
+
return getReferencesForTypeParameter(node, value);
|
|
292
|
+
case NodeKind.ChildEntitiesType:
|
|
293
|
+
return getReferencesForChildEntitiesType(node, value);
|
|
294
|
+
default:
|
|
295
|
+
return assertExhaustive(node);
|
|
296
|
+
}
|
|
297
|
+
};
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import Debug from "debug";
|
|
2
|
-
import {
|
|
2
|
+
import { getParameterNames, walkNodeTree } from "./declarations/Declaration.js";
|
|
3
3
|
import { isEntityDecl } from "./declarations/EntityDecl.js";
|
|
4
|
+
import { cases, isEnumDecl } from "./declarations/EnumDecl.js";
|
|
5
|
+
import { getNestedDeclarations } from "./Node.js";
|
|
6
|
+
import { isObjectType } from "./types/generic/ObjectType.js";
|
|
4
7
|
import { isStringType } from "./types/primitives/StringType.js";
|
|
8
|
+
import { isChildEntitiesType } from "./types/references/ChildEntitiesType.js";
|
|
5
9
|
import { isIncludeIdentifierType } from "./types/references/IncludeIdentifierType.js";
|
|
6
10
|
import { isNestedEntityMapType } from "./types/references/NestedEntityMapType.js";
|
|
11
|
+
import { isReferenceIdentifierType, } from "./types/references/ReferenceIdentifierType.js";
|
|
7
12
|
import { findTypeAtPath } from "./types/Type.js";
|
|
8
13
|
const debug = Debug("tsondb:schema");
|
|
9
14
|
const checkDuplicateIdentifier = (existingDecls, decl) => {
|
|
@@ -59,6 +64,92 @@ const checkEntityDisplayNamePaths = (decls, localeEntity) => {
|
|
|
59
64
|
}
|
|
60
65
|
}
|
|
61
66
|
};
|
|
67
|
+
const checkChildEntityTypeNotInEnumDecl = (checkedDecls, decl) => {
|
|
68
|
+
if (!checkedDecls.has(decl)) {
|
|
69
|
+
checkedDecls.add(decl);
|
|
70
|
+
walkNodeTree(node => {
|
|
71
|
+
if (isChildEntitiesType(node)) {
|
|
72
|
+
throw new Error(`Child entities type for entity "${node.entity.name}" in declaration "${decl.name}" cannot be used inside an enum declaration.`);
|
|
73
|
+
}
|
|
74
|
+
else if (isIncludeIdentifierType(node)) {
|
|
75
|
+
checkChildEntityTypeNotInEnumDecl(checkedDecls, node.reference);
|
|
76
|
+
}
|
|
77
|
+
}, decl);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
const checkChildEntityTypeInEntityDecl = (checkedDecls, entityDecl, decl) => {
|
|
81
|
+
if (!checkedDecls.has(decl)) {
|
|
82
|
+
checkedDecls.add(decl);
|
|
83
|
+
walkNodeTree((node, parentTypes) => {
|
|
84
|
+
if (isIncludeIdentifierType(node)) {
|
|
85
|
+
checkChildEntityTypeInEntityDecl(checkedDecls, entityDecl, node.reference);
|
|
86
|
+
}
|
|
87
|
+
else if (isChildEntitiesType(node)) {
|
|
88
|
+
if (!parentTypes.every(parentType => isObjectType(parentType))) {
|
|
89
|
+
throw new Error(`Child entities type for entity "${node.entity.name}" in entity declaration "${entityDecl.name}" must be a constant child of the entity declaration, i.e. it must only be contained directly in the entity declaration or in nested object types.`);
|
|
90
|
+
}
|
|
91
|
+
const backReferenceMemberDeclAtParent = node.entity.type.value.properties[node.entity.parentReferenceKey];
|
|
92
|
+
if (backReferenceMemberDeclAtParent === undefined) {
|
|
93
|
+
throw new Error(`Child entities type for entity "${node.entity.name}" in entity declaration "${entityDecl.name}" requires that the child entity has a reference to its parent defined.`);
|
|
94
|
+
}
|
|
95
|
+
if (!backReferenceMemberDeclAtParent.isRequired) {
|
|
96
|
+
throw new Error(`The parent reference "${node.entity.parentReferenceKey}" in child entity "${node.entity.name}" must be required.`);
|
|
97
|
+
}
|
|
98
|
+
if (isReferenceIdentifierType(backReferenceMemberDeclAtParent.type)) {
|
|
99
|
+
if (backReferenceMemberDeclAtParent.type.entity !== entityDecl) {
|
|
100
|
+
throw new Error(`The parent reference "${node.entity.parentReferenceKey}" in child entity "${node.entity.name}" must reference the entity "${entityDecl.name}". If the parent entity is polymorphic, use an enum of reference identifier types instead.`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
else if (isIncludeIdentifierType(backReferenceMemberDeclAtParent.type)) {
|
|
104
|
+
if (!isEnumDecl(backReferenceMemberDeclAtParent.type.reference)) {
|
|
105
|
+
throw new Error(`The parent reference "${node.entity.parentReferenceKey}" in child entity "${node.entity.name}" must reference an enum declaration if it is an IncludeIdentifierType.`);
|
|
106
|
+
}
|
|
107
|
+
const enumCases = cases(backReferenceMemberDeclAtParent.type.reference);
|
|
108
|
+
if (!enumCases.every((caseDecl) => caseDecl.type !== null && isReferenceIdentifierType(caseDecl.type))) {
|
|
109
|
+
throw new Error(`All cases of the enum "${backReferenceMemberDeclAtParent.type.reference.name}" referenced by the parent reference "${node.entity.parentReferenceKey}" in child entity "${node.entity.name}" must be ReferenceIdentifierTypes.`);
|
|
110
|
+
}
|
|
111
|
+
if (!enumCases.some(caseDecl => caseDecl.type.entity === entityDecl)) {
|
|
112
|
+
throw new Error(`At least one case of the enum "${backReferenceMemberDeclAtParent.type.reference.name}" referenced by the parent reference "${node.entity.parentReferenceKey}" in child entity "${node.entity.name}" must reference the entity "${decl.name}".`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
throw new Error(`The parent reference "${node.entity.parentReferenceKey}" in child entity "${node.entity.name}" must be either a ReferenceIdentifierType or an IncludeIdentifierType that references an enum declaration.`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}, decl);
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
const checkChildEntityTypes = (localeEntity, decls) => {
|
|
123
|
+
if (localeEntity && localeEntity.parentReferenceKey !== undefined) {
|
|
124
|
+
throw new TypeError(`The locale entity "${localeEntity.name}" cannot be used as a child entity to other entities.`);
|
|
125
|
+
}
|
|
126
|
+
// TODO: Check that no cycles exist in child entity relations
|
|
127
|
+
for (const decl of decls) {
|
|
128
|
+
if (isEnumDecl(decl)) {
|
|
129
|
+
checkChildEntityTypeNotInEnumDecl(new Set(), decl);
|
|
130
|
+
}
|
|
131
|
+
if (isEntityDecl(decl)) {
|
|
132
|
+
checkChildEntityTypeInEntityDecl(new Set(), decl, decl);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
const checkChildEntitiesProvideCorrectPathToParentReferenceIdentifierType = (decls) => {
|
|
137
|
+
for (const decl of decls) {
|
|
138
|
+
if (isEntityDecl(decl) && decl.parentReferenceKey !== undefined) {
|
|
139
|
+
const valueAtParentReferenceKey = decl.type.value.properties[decl.parentReferenceKey];
|
|
140
|
+
if (valueAtParentReferenceKey) {
|
|
141
|
+
const typeAtProperty = valueAtParentReferenceKey.type;
|
|
142
|
+
// the parent reference must either be an enum of reference types (for polymorphic relations) or a reference identifier type
|
|
143
|
+
if (!((isIncludeIdentifierType(typeAtProperty) &&
|
|
144
|
+
isEnumDecl(typeAtProperty.reference) &&
|
|
145
|
+
cases(typeAtProperty.reference).every(caseDecl => caseDecl.type !== null && isReferenceIdentifierType(caseDecl.type))) ||
|
|
146
|
+
isReferenceIdentifierType(typeAtProperty))) {
|
|
147
|
+
throw new TypeError(`Parent reference key "${decl.parentReferenceKey}" in entity declaration "${decl.name}" must be an IncludeIdentifierType that references an enum declaration whose cases all have a ReferenceIdentifierType.`);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
};
|
|
62
153
|
const addDeclarations = (existingDecls, declsToAdd, nested) => declsToAdd.reduce((accDecls, decl) => {
|
|
63
154
|
if (!accDecls.includes(decl)) {
|
|
64
155
|
checkDuplicateIdentifier(accDecls, decl);
|
|
@@ -75,6 +166,10 @@ export const Schema = (declarations, localeEntity) => {
|
|
|
75
166
|
checkParameterNamesShadowing(allDecls);
|
|
76
167
|
debug("checking entity display name paths ...");
|
|
77
168
|
checkEntityDisplayNamePaths(allDecls, localeEntity);
|
|
169
|
+
debug("checking child entities ...");
|
|
170
|
+
checkChildEntitiesProvideCorrectPathToParentReferenceIdentifierType(allDecls);
|
|
171
|
+
debug("checking child entity types ...");
|
|
172
|
+
checkChildEntityTypes(localeEntity, allDecls);
|
|
78
173
|
debug("created schema, no integrity violations found");
|
|
79
174
|
return {
|
|
80
175
|
declarations: allDecls,
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import type { Serializer } from "./Node.ts";
|
|
1
|
+
import type { GetNestedDeclarations, GetReferences, Serializer, TypeArgumentsResolver } from "./Node.ts";
|
|
2
2
|
import { NodeKind } from "./Node.ts";
|
|
3
|
-
import type {
|
|
3
|
+
import type { Type } from "./types/Type.ts";
|
|
4
4
|
export interface TypeParameter<N extends string = string, T extends Type = Type> {
|
|
5
|
-
kind: NodeKind["
|
|
6
|
-
name: N;
|
|
7
|
-
constraint?: T;
|
|
8
|
-
}
|
|
9
|
-
export interface SerializedTypeParameter<N extends string = string, T extends SerializedType = SerializedType> extends SerializedBaseType {
|
|
10
|
-
kind: NodeKind["GenericParameter"];
|
|
5
|
+
kind: NodeKind["TypeParameter"];
|
|
11
6
|
name: N;
|
|
12
7
|
constraint?: T;
|
|
13
8
|
}
|
|
14
9
|
export declare const Param: <N extends string = string, T extends Type = Type>(name: N, constraint?: T) => TypeParameter<N, T>;
|
|
15
|
-
export declare const
|
|
10
|
+
export declare const getNestedDeclarationsInTypeParameter: GetNestedDeclarations<TypeParameter>;
|
|
11
|
+
export declare const resolveTypeArgumentsInTypeParameter: TypeArgumentsResolver<TypeParameter>;
|
|
12
|
+
export declare const serializeTypeParameter: Serializer<TypeParameter>;
|
|
13
|
+
export declare const getReferencesForTypeParameter: GetReferences<TypeParameter>;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { NodeKind } from "./Node.js";
|
|
2
|
-
import { removeParentKey, serializeType } from "./types/Type.js";
|
|
1
|
+
import { getNestedDeclarations, NodeKind, serializeNode } from "./Node.js";
|
|
3
2
|
export const Param = (name, constraint) => ({
|
|
4
|
-
kind: NodeKind.
|
|
3
|
+
kind: NodeKind.TypeParameter,
|
|
5
4
|
name,
|
|
6
5
|
constraint,
|
|
7
6
|
});
|
|
7
|
+
export const getNestedDeclarationsInTypeParameter = (addedDecls, param) => (param.constraint ? getNestedDeclarations(addedDecls, param.constraint) : addedDecls);
|
|
8
|
+
export const resolveTypeArgumentsInTypeParameter = (_args, param) => param;
|
|
8
9
|
export const serializeTypeParameter = type => ({
|
|
9
|
-
...
|
|
10
|
-
constraint: type.constraint ?
|
|
10
|
+
...type,
|
|
11
|
+
constraint: type.constraint ? serializeNode(type.constraint) : undefined,
|
|
11
12
|
});
|
|
13
|
+
export const getReferencesForTypeParameter = () => [];
|
|
@@ -1,47 +1,29 @@
|
|
|
1
|
-
import type { BaseNode,
|
|
2
|
-
import type {
|
|
3
|
-
import type { EnumCaseDecl
|
|
4
|
-
import { type
|
|
5
|
-
import type {
|
|
6
|
-
import type {
|
|
7
|
-
import type {
|
|
8
|
-
import type { SerializedTypeAliasDecl, TypeAliasDecl } from "./TypeAliasDecl.ts";
|
|
1
|
+
import type { BaseNode, Node } from "../Node.ts";
|
|
2
|
+
import type { TypeParameter } from "../TypeParameter.ts";
|
|
3
|
+
import type { EnumCaseDecl } from "../types/generic/EnumType.ts";
|
|
4
|
+
import { type Type } from "../types/Type.ts";
|
|
5
|
+
import type { EntityDecl } from "./EntityDecl.ts";
|
|
6
|
+
import type { EnumDecl } from "./EnumDecl.ts";
|
|
7
|
+
import type { TypeAliasDecl } from "./TypeAliasDecl.ts";
|
|
9
8
|
export type TypeArguments<Params extends TypeParameter[]> = {
|
|
10
9
|
[K in keyof Params]: Params[K] extends TypeParameter<string, infer T> ? T : Type;
|
|
11
10
|
};
|
|
12
|
-
export type SerializedTypeArguments<Params extends SerializedTypeParameter[]> = {
|
|
13
|
-
[K in keyof Params]: Params[K] extends SerializedTypeParameter<string, infer T> ? T : Type;
|
|
14
|
-
};
|
|
15
11
|
export declare const getParameterNames: (decl: Decl) => string[];
|
|
16
12
|
export declare const getTypeArgumentsRecord: <Params extends TypeParameter[]>(decl: DeclP<Params>, args: TypeArguments<Params>) => Record<string, Type>;
|
|
17
13
|
export type Decl = EntityDecl | EnumDecl | TypeAliasDecl;
|
|
18
|
-
export type SerializedDecl = SerializedEntityDecl | SerializedEnumDecl | SerializedTypeAliasDecl;
|
|
19
14
|
export type DeclP<Params extends TypeParameter[] = TypeParameter[]> = EntityDecl | EnumDecl<string, Record<string, EnumCaseDecl>, Params> | TypeAliasDecl<string, Type, Params>;
|
|
20
15
|
export type IncludableDeclP<Params extends TypeParameter[] = TypeParameter[]> = EnumDecl<string, Record<string, EnumCaseDecl>, Params> | TypeAliasDecl<string, Type, Params>;
|
|
21
|
-
export type SerializedDeclP<Params extends SerializedTypeParameter[] = SerializedTypeParameter[]> = SerializedEntityDecl | SerializedEnumDecl<string, Record<string, SerializedEnumCaseDecl>, Params> | SerializedTypeAliasDecl<string, SerializedType, Params>;
|
|
22
16
|
export type SecondaryDecl = EnumDecl | TypeAliasDecl;
|
|
23
|
-
export type SerializedSecondaryDecl = SerializedEnumDecl | SerializedTypeAliasDecl;
|
|
24
|
-
export declare const getNestedDeclarations: GetNestedDeclarations;
|
|
25
|
-
export type GetNestedDeclarations<T extends Node = Node> = (addedDecls: Decl[], node: T) => Decl[];
|
|
26
17
|
export declare const isDecl: (node: Node) => node is Decl;
|
|
18
|
+
export declare const asDecl: (node: Node | undefined) => Decl | undefined;
|
|
27
19
|
export interface BaseDecl<Name extends string = string, Params extends TypeParameter[] = TypeParameter[]> extends BaseNode {
|
|
28
20
|
sourceUrl: string;
|
|
29
21
|
name: Name;
|
|
30
22
|
comment?: string;
|
|
31
23
|
parameters: Params;
|
|
32
24
|
}
|
|
33
|
-
export interface SerializedBaseDecl<Name extends string = string, Params extends SerializedTypeParameter[] = SerializedTypeParameter[]> extends BaseNode {
|
|
34
|
-
sourceUrl: string;
|
|
35
|
-
name: Name;
|
|
36
|
-
comment?: string;
|
|
37
|
-
parameters: Params;
|
|
38
|
-
}
|
|
39
|
-
export declare const validateDecl: (helpers: ValidatorHelpers, decl: Decl, args: Type[], value: unknown) => Error[];
|
|
40
25
|
export declare const validateDeclName: (name: string) => void;
|
|
41
|
-
export declare const resolveTypeArgumentsInDecl: <Params extends TypeParameter[]>(decl: DeclP<Params>, args: TypeArguments<Params>) => DeclP<[]>;
|
|
42
26
|
export declare const isDeclWithoutTypeParameters: (decl: Decl) => decl is DeclP<[]>;
|
|
43
|
-
export declare const resolveTypeArgumentsInDecls: (decls: readonly Decl[]) =>
|
|
44
|
-
export declare function walkNodeTree(callbackFn: (node: Node) => void, decl: Decl): void;
|
|
45
|
-
export declare const serializeDecl: Serializer<Decl, SerializedDecl>;
|
|
46
|
-
export declare const getReferencesForDecl: GetReferences<Decl>;
|
|
27
|
+
export declare const resolveTypeArgumentsInDecls: (decls: readonly Decl[]) => Decl[];
|
|
28
|
+
export declare function walkNodeTree(callbackFn: (node: Node, parentTypes: Type[], parentDecl: Decl) => void, decl: Decl): void;
|
|
47
29
|
export declare const groupDeclarationsBySourceUrl: (decls: readonly Decl[]) => Partial<Record<string, Decl[]>>;
|