tsondb 0.5.18 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +173 -110
- 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 +3 -0
- package/dist/src/web/components/ModalDialog.js +16 -0
- 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 +2 -1
- 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
package/dist/src/bin/tsondb.js
CHANGED
|
@@ -84,7 +84,7 @@ switch (passedArguments.command.name) {
|
|
|
84
84
|
break;
|
|
85
85
|
case "serve":
|
|
86
86
|
debug(`running command: serve`);
|
|
87
|
-
await serve(config.schema, config.dataRootPath, config.serverOptions);
|
|
87
|
+
await serve(config.schema, config.dataRootPath, config.defaultLocales, config.homeLayoutSections, config.serverOptions);
|
|
88
88
|
break;
|
|
89
89
|
case "validate":
|
|
90
90
|
debug(`running command: validate`);
|
package/dist/src/index.d.ts
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Output } from "../shared/output.ts";
|
|
2
|
+
import type { EntityDecl } from "./schema/index.ts";
|
|
3
|
+
import type { Schema } from "./schema/Schema.ts";
|
|
4
|
+
export type Config = {
|
|
5
|
+
serverOptions?: ServerOptions;
|
|
6
|
+
schema: Schema;
|
|
7
|
+
outputs: Output[];
|
|
8
|
+
defaultLocales: string[];
|
|
9
|
+
dataRootPath: string;
|
|
10
|
+
homeLayoutSections?: HomeLayoutSection[];
|
|
11
|
+
};
|
|
12
|
+
export type ServerOptions = {
|
|
13
|
+
port: number;
|
|
14
|
+
};
|
|
15
|
+
export type HomeLayoutSection = {
|
|
16
|
+
title: string;
|
|
17
|
+
comment?: string;
|
|
18
|
+
entities: EntityDecl[];
|
|
19
|
+
};
|
|
20
|
+
export declare const validateConfig: (config: Config) => void;
|
package/dist/src/node/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Output } from "../shared/output.ts";
|
|
2
|
+
import type { HomeLayoutSection } from "./config.ts";
|
|
2
3
|
import { type Schema } from "./schema/Schema.ts";
|
|
3
4
|
import type { ServerOptions } from "./server/index.ts";
|
|
4
5
|
export declare const generateOutputs: (schema: Schema, outputs: Output[]) => Promise<void>;
|
|
@@ -8,7 +9,7 @@ type ValidationOptions = {
|
|
|
8
9
|
};
|
|
9
10
|
export declare const validate: (schema: Schema, dataRootPath: string, options?: Partial<ValidationOptions>) => Promise<void>;
|
|
10
11
|
export declare const generateAndValidate: (schema: Schema, outputs: Output[], dataRootPath: string, validationOptions?: Partial<ValidationOptions>) => Promise<void>;
|
|
11
|
-
export declare const serve: (schema: Schema, dataRootPath: string, serverOptions?: Partial<ServerOptions>) => Promise<void>;
|
|
12
|
-
export declare const generateValidateAndServe: (schema: Schema, outputs: Output[], dataRootPath: string, serverOptions?: Partial<ServerOptions>, validationOptions?: Partial<ValidationOptions>) => Promise<void>;
|
|
12
|
+
export declare const serve: (schema: Schema, dataRootPath: string, defaultLocales: string[], homeLayoutSections?: HomeLayoutSection[], serverOptions?: Partial<ServerOptions>) => Promise<void>;
|
|
13
|
+
export declare const generateValidateAndServe: (schema: Schema, outputs: Output[], dataRootPath: string, defaultLocales: string[], homeLayoutSections?: HomeLayoutSection[], serverOptions?: Partial<ServerOptions>, validationOptions?: Partial<ValidationOptions>) => Promise<void>;
|
|
13
14
|
export declare const format: (schema: Schema, dataRootPath: string) => Promise<void>;
|
|
14
15
|
export {};
|
package/dist/src/node/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Debug from "debug";
|
|
2
|
-
import { mkdir
|
|
2
|
+
import { mkdir } from "fs/promises";
|
|
3
3
|
import { join, sep } from "path";
|
|
4
4
|
import { styleText } from "util";
|
|
5
5
|
import { parallelizeErrors } from "../shared/utils/validation.js";
|
|
@@ -8,7 +8,8 @@ import { createValidators } from "./schema/Node.js";
|
|
|
8
8
|
import { getEntities } from "./schema/Schema.js";
|
|
9
9
|
import { createServer } from "./server/index.js";
|
|
10
10
|
import { countErrors, getErrorMessageForDisplay, wrapErrorsIfAny } from "./utils/error.js";
|
|
11
|
-
import {
|
|
11
|
+
import { getFileNameForId, writeInstance } from "./utils/files.js";
|
|
12
|
+
import { getInstancesByEntityName } from "./utils/instances.js";
|
|
12
13
|
const debug = Debug("tsondb:jsapi");
|
|
13
14
|
const prepareFolders = async (dataRootPath, entities) => {
|
|
14
15
|
await mkdir(dataRootPath, { recursive: true });
|
|
@@ -29,10 +30,11 @@ const _validate = (dataRootPath, entities, instancesByEntityName, options = {})
|
|
|
29
30
|
throw new Error(`Entity "${onlyEntity}" not found in schema`);
|
|
30
31
|
}
|
|
31
32
|
}
|
|
33
|
+
const validationHelpers = createValidators(instancesByEntityName, true, checkReferentialIntegrity);
|
|
32
34
|
const errors = (checkOnlyEntities.length > 0
|
|
33
35
|
? entities.filter(entity => checkOnlyEntities.includes(entity.name))
|
|
34
36
|
: entities)
|
|
35
|
-
.flatMap(entity => parallelizeErrors(instancesByEntityName[entity.name]?.map(instance => wrapErrorsIfAny(`in file ${styleText("white", `"${dataRootPath}${sep}${styleText("bold", join(entity.name, instance.
|
|
37
|
+
.flatMap(entity => parallelizeErrors(instancesByEntityName[entity.name]?.map(instance => wrapErrorsIfAny(`in file ${styleText("white", `"${dataRootPath}${sep}${styleText("bold", join(entity.name, getFileNameForId(instance.id)))}"`)}`, validateEntityDecl(validationHelpers, entity, instance.content))) ?? []))
|
|
36
38
|
.toSorted((a, b) => a.message.localeCompare(b.message));
|
|
37
39
|
if (errors.length === 0) {
|
|
38
40
|
debug("All entities are valid");
|
|
@@ -55,21 +57,24 @@ export const generateAndValidate = async (schema, outputs, dataRootPath, validat
|
|
|
55
57
|
const instancesByEntityName = await getInstancesByEntityName(dataRootPath, entities);
|
|
56
58
|
_validate(dataRootPath, entities, instancesByEntityName, validationOptions);
|
|
57
59
|
};
|
|
58
|
-
export const serve = async (schema, dataRootPath, serverOptions) => {
|
|
60
|
+
export const serve = async (schema, dataRootPath, defaultLocales, homeLayoutSections, serverOptions) => {
|
|
61
|
+
if (defaultLocales.length === 0) {
|
|
62
|
+
throw new Error("At least one default locale must be specified to start the server.");
|
|
63
|
+
}
|
|
59
64
|
const entities = getEntities(schema);
|
|
60
65
|
await prepareFolders(dataRootPath, entities);
|
|
61
66
|
debug("prepared folders");
|
|
62
67
|
const instancesByEntityName = await getInstancesByEntityName(dataRootPath, entities);
|
|
63
68
|
debug("loaded instances");
|
|
64
|
-
await createServer(schema, dataRootPath, instancesByEntityName, serverOptions);
|
|
69
|
+
await createServer(schema, dataRootPath, instancesByEntityName, defaultLocales, homeLayoutSections, serverOptions);
|
|
65
70
|
};
|
|
66
|
-
export const generateValidateAndServe = async (schema, outputs, dataRootPath, serverOptions, validationOptions) => {
|
|
71
|
+
export const generateValidateAndServe = async (schema, outputs, dataRootPath, defaultLocales, homeLayoutSections, serverOptions, validationOptions) => {
|
|
67
72
|
await generateOutputs(schema, outputs);
|
|
68
73
|
const entities = getEntities(schema);
|
|
69
74
|
await prepareFolders(dataRootPath, entities);
|
|
70
75
|
const instancesByEntityName = await getInstancesByEntityName(dataRootPath, entities);
|
|
71
76
|
_validate(dataRootPath, entities, instancesByEntityName, validationOptions);
|
|
72
|
-
await createServer(schema, dataRootPath, instancesByEntityName, serverOptions);
|
|
77
|
+
await createServer(schema, dataRootPath, instancesByEntityName, defaultLocales, homeLayoutSections, serverOptions);
|
|
73
78
|
};
|
|
74
79
|
export const format = async (schema, dataRootPath) => {
|
|
75
80
|
const entities = getEntities(schema);
|
|
@@ -80,7 +85,7 @@ export const format = async (schema, dataRootPath) => {
|
|
|
80
85
|
const entity = entities.find(entity => entity.name === entityName);
|
|
81
86
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
82
87
|
for (const instance of instancesByEntityName[entityName]) {
|
|
83
|
-
await
|
|
88
|
+
await writeInstance(dataRootPath, entity, instance.id, instance.content);
|
|
84
89
|
}
|
|
85
90
|
}
|
|
86
91
|
};
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { dirname, relative } from "node:path";
|
|
2
2
|
import { discriminatorKey } from "../../../shared/enum.js";
|
|
3
3
|
import { assertExhaustive } from "../../../shared/utils/typeSafety.js";
|
|
4
|
+
import { asDecl } from "../../schema/declarations/Declaration.js";
|
|
4
5
|
import { addEphemeralUUIDToType, createEntityIdentifierTypeAsDecl, isEntityDecl, } from "../../schema/declarations/EntityDecl.js";
|
|
5
6
|
import { TypeAliasDecl } from "../../schema/declarations/TypeAliasDecl.js";
|
|
6
7
|
import { flatMapAuxiliaryDecls, NodeKind } from "../../schema/Node.js";
|
|
8
|
+
import { ArrayType } from "../../schema/types/generic/ArrayType.js";
|
|
7
9
|
import { isNestedEntityMapType } from "../../schema/types/references/NestedEntityMapType.js";
|
|
8
|
-
import {
|
|
10
|
+
import { ReferenceIdentifierType } from "../../schema/types/references/ReferenceIdentifierType.js";
|
|
9
11
|
import { ensureSpecialDirStart } from "../../utils/path.js";
|
|
10
12
|
const defaultIndentation = 2;
|
|
11
13
|
const defaultOptions = {
|
|
@@ -74,7 +76,7 @@ const renderReferenceIdentifierType = (_options, type) => ({
|
|
|
74
76
|
$ref: `#/$defs/${type.entity.name}_ID`,
|
|
75
77
|
});
|
|
76
78
|
const renderIncludeIdentifierType = (options, type) => {
|
|
77
|
-
const sourceUrl =
|
|
79
|
+
const sourceUrl = options.parentDecl?.sourceUrl ?? "";
|
|
78
80
|
const filePath = options.preserveFiles && sourceUrl !== type.reference.sourceUrl
|
|
79
81
|
? ensureSpecialDirStart(relative(dirname(sourceUrl), type.reference.sourceUrl))
|
|
80
82
|
: "";
|
|
@@ -101,6 +103,7 @@ const renderEnumType = (options, type) => ({
|
|
|
101
103
|
required: [discriminatorKey, ...(caseDef.type === null ? [] : [caseName])],
|
|
102
104
|
})),
|
|
103
105
|
});
|
|
106
|
+
const renderChildEntitiesType = (options, type) => renderType(options, ArrayType(ReferenceIdentifierType(type.entity), { uniqueItems: true }));
|
|
104
107
|
const renderType = (options, type) => {
|
|
105
108
|
switch (type.kind) {
|
|
106
109
|
case NodeKind.ArrayType:
|
|
@@ -127,6 +130,8 @@ const renderType = (options, type) => {
|
|
|
127
130
|
return renderNestedEntityMapType(options, type);
|
|
128
131
|
case NodeKind.EnumType:
|
|
129
132
|
return renderEnumType(options, type);
|
|
133
|
+
case NodeKind.ChildEntitiesType:
|
|
134
|
+
return renderChildEntitiesType(options, type);
|
|
130
135
|
default:
|
|
131
136
|
return assertExhaustive(type, "Unknown type");
|
|
132
137
|
}
|
|
@@ -149,11 +154,11 @@ const renderTypeAliasDecl = (options, decl) => ({
|
|
|
149
154
|
const renderDecl = (options, decl) => {
|
|
150
155
|
switch (decl.kind) {
|
|
151
156
|
case NodeKind.EntityDecl:
|
|
152
|
-
return renderEntityDecl(options, decl);
|
|
157
|
+
return renderEntityDecl({ ...options, parentDecl: decl }, decl);
|
|
153
158
|
case NodeKind.EnumDecl:
|
|
154
|
-
return renderEnumDecl(options, decl);
|
|
159
|
+
return renderEnumDecl({ ...options, parentDecl: decl }, decl);
|
|
155
160
|
case NodeKind.TypeAliasDecl:
|
|
156
|
-
return renderTypeAliasDecl(options, decl);
|
|
161
|
+
return renderTypeAliasDecl({ ...options, parentDecl: decl }, decl);
|
|
157
162
|
default:
|
|
158
163
|
return assertExhaustive(decl, "Unknown declaration");
|
|
159
164
|
}
|
|
@@ -162,14 +167,14 @@ const renderDeclarations = (options, declarations) => Object.fromEntries(declara
|
|
|
162
167
|
export const render = (options = defaultOptions, declarations) => {
|
|
163
168
|
const finalOptions = { ...defaultOptions, ...options };
|
|
164
169
|
return JSON.stringify({
|
|
165
|
-
$defs: renderDeclarations(finalOptions, flatMapAuxiliaryDecls((node, existingDecls) => {
|
|
170
|
+
$defs: renderDeclarations(finalOptions, flatMapAuxiliaryDecls((parentNodes, node, existingDecls) => {
|
|
166
171
|
if (isNestedEntityMapType(node)) {
|
|
167
172
|
if (existingDecls.some(decl => decl.name === node.name)) {
|
|
168
173
|
// this may happen when a nested entity map is defined in a generic declaration and the generic declaration is used multiple times
|
|
169
174
|
// TODO: circumvent by defining the nested entity declaration outside the generic declaration
|
|
170
175
|
return undefined;
|
|
171
176
|
}
|
|
172
|
-
return TypeAliasDecl(
|
|
177
|
+
return TypeAliasDecl(asDecl(parentNodes[0])?.sourceUrl ?? "", {
|
|
173
178
|
name: node.name,
|
|
174
179
|
comment: node.comment,
|
|
175
180
|
type: () => node.type.value,
|
|
@@ -4,12 +4,14 @@ import { discriminatorKey } from "../../../shared/enum.js";
|
|
|
4
4
|
import { unique } from "../../../shared/utils/array.js";
|
|
5
5
|
import { toCamelCase } from "../../../shared/utils/string.js";
|
|
6
6
|
import { assertExhaustive } from "../../../shared/utils/typeSafety.js";
|
|
7
|
+
import { asDecl } from "../../schema/declarations/Declaration.js";
|
|
7
8
|
import { addEphemeralUUIDToType, createEntityIdentifierTypeAsDecl, isEntityDecl, } from "../../schema/declarations/EntityDecl.js";
|
|
8
9
|
import { TypeAliasDecl } from "../../schema/declarations/TypeAliasDecl.js";
|
|
9
10
|
import { flatMapAuxiliaryDecls, NodeKind } from "../../schema/Node.js";
|
|
11
|
+
import { ArrayType } from "../../schema/types/generic/ArrayType.js";
|
|
10
12
|
import { isObjectType } from "../../schema/types/generic/ObjectType.js";
|
|
11
13
|
import { isNestedEntityMapType } from "../../schema/types/references/NestedEntityMapType.js";
|
|
12
|
-
import {
|
|
14
|
+
import { ReferenceIdentifierType } from "../../schema/types/references/ReferenceIdentifierType.js";
|
|
13
15
|
import { ensureSpecialDirStart } from "../../utils/path.js";
|
|
14
16
|
import { combineSyntaxes, indent, prefixLines, syntax } from "../../utils/render.js";
|
|
15
17
|
const defaultOptions = {
|
|
@@ -38,7 +40,8 @@ const renderObjectType = (options, type) => {
|
|
|
38
40
|
};
|
|
39
41
|
const renderBooleanType = (_options, _type) => syntax `boolean`;
|
|
40
42
|
const renderDateType = (_options, _type) => syntax `Date`;
|
|
41
|
-
const
|
|
43
|
+
const renderFloatType = (_options, _type) => syntax `number`;
|
|
44
|
+
const renderIntegerType = (_options, _type) => syntax `number`;
|
|
42
45
|
const renderStringType = (_options, _type) => syntax `string`;
|
|
43
46
|
const renderTypeArgumentType = (_options, type) => syntax `${type.argument.name}`;
|
|
44
47
|
const renderReferenceIdentifierType = (_options, type) => [
|
|
@@ -55,6 +58,7 @@ const renderNestedEntityMapType = (options, type) => wrapAsObject(options, synta
|
|
|
55
58
|
const renderEnumType = (options, type) => combineSyntaxes(Object.entries(type.values).map(([caseName, caseDef]) => indent(options.indentation, 1, syntax `${EOL}| {${EOL}${indent(options.indentation, 1, syntax `${discriminatorKey}: "${caseName}"${caseDef.type === null
|
|
56
59
|
? ""
|
|
57
60
|
: syntax `${EOL}${caseName}: ${renderType(options, caseDef.type)}`}`)}${EOL}}`)));
|
|
61
|
+
const renderChildEntitiesType = (options, type) => renderType(options, ArrayType(ReferenceIdentifierType(type.entity), { uniqueItems: true }));
|
|
58
62
|
const renderType = (options, type) => {
|
|
59
63
|
switch (type.kind) {
|
|
60
64
|
case NodeKind.ArrayType:
|
|
@@ -66,9 +70,9 @@ const renderType = (options, type) => {
|
|
|
66
70
|
case NodeKind.DateType:
|
|
67
71
|
return renderDateType(options, type);
|
|
68
72
|
case NodeKind.FloatType:
|
|
69
|
-
return
|
|
73
|
+
return renderFloatType(options, type);
|
|
70
74
|
case NodeKind.IntegerType:
|
|
71
|
-
return
|
|
75
|
+
return renderIntegerType(options, type);
|
|
72
76
|
case NodeKind.StringType:
|
|
73
77
|
return renderStringType(options, type);
|
|
74
78
|
case NodeKind.TypeArgumentType:
|
|
@@ -81,6 +85,8 @@ const renderType = (options, type) => {
|
|
|
81
85
|
return renderNestedEntityMapType(options, type);
|
|
82
86
|
case NodeKind.EnumType:
|
|
83
87
|
return renderEnumType(options, type);
|
|
88
|
+
case NodeKind.ChildEntitiesType:
|
|
89
|
+
return renderChildEntitiesType(options, type);
|
|
84
90
|
default:
|
|
85
91
|
return assertExhaustive(type, "Unknown type");
|
|
86
92
|
}
|
|
@@ -119,9 +125,9 @@ const renderImports = (currentUrl, imports) => {
|
|
|
119
125
|
};
|
|
120
126
|
export const render = (options = defaultOptions, declarations) => {
|
|
121
127
|
const finalOptions = { ...defaultOptions, ...options };
|
|
122
|
-
const [imports, content] = renderDeclarations(finalOptions, flatMapAuxiliaryDecls(node => {
|
|
128
|
+
const [imports, content] = renderDeclarations(finalOptions, flatMapAuxiliaryDecls((parentNodes, node) => {
|
|
123
129
|
if (isNestedEntityMapType(node)) {
|
|
124
|
-
return TypeAliasDecl(
|
|
130
|
+
return TypeAliasDecl(asDecl(parentNodes[0])?.sourceUrl ?? "", {
|
|
125
131
|
name: node.name,
|
|
126
132
|
comment: node.comment,
|
|
127
133
|
type: () => node.type.value,
|
|
@@ -1,32 +1,50 @@
|
|
|
1
|
+
import type { SerializedEntityDecl } from "../../shared/schema/declarations/EntityDecl.ts";
|
|
2
|
+
import type { SerializedEnumDecl } from "../../shared/schema/declarations/EnumDecl.ts";
|
|
3
|
+
import type { SerializedTypeAliasDecl } from "../../shared/schema/declarations/TypeAliasDecl.ts";
|
|
4
|
+
import { NodeKind } from "../../shared/schema/Node.ts";
|
|
5
|
+
import type { SerializedTypeParameter } from "../../shared/schema/TypeParameter.ts";
|
|
6
|
+
import type { SerializedArrayType } from "../../shared/schema/types/ArrayType.ts";
|
|
7
|
+
import type { SerializedBooleanType } from "../../shared/schema/types/BooleanType.ts";
|
|
8
|
+
import type { SerializedChildEntitiesType } from "../../shared/schema/types/ChildEntitiesType.ts";
|
|
9
|
+
import type { SerializedDateType } from "../../shared/schema/types/DateType.ts";
|
|
10
|
+
import type { SerializedEnumCaseDecl, SerializedEnumType } from "../../shared/schema/types/EnumType.ts";
|
|
11
|
+
import type { SerializedFloatType } from "../../shared/schema/types/FloatType.ts";
|
|
12
|
+
import type { SerializedIncludeIdentifierType } from "../../shared/schema/types/IncludeIdentifierType.ts";
|
|
13
|
+
import type { SerializedIntegerType } from "../../shared/schema/types/IntegerType.ts";
|
|
14
|
+
import type { SerializedNestedEntityMapType } from "../../shared/schema/types/NestedEntityMapType.ts";
|
|
15
|
+
import type { SerializedMemberDecl, SerializedObjectType } from "../../shared/schema/types/ObjectType.ts";
|
|
16
|
+
import type { SerializedReferenceIdentifierType } from "../../shared/schema/types/ReferenceIdentifierType.ts";
|
|
17
|
+
import type { SerializedStringType } from "../../shared/schema/types/StringType.ts";
|
|
18
|
+
import type { SerializedTypeArgumentType } from "../../shared/schema/types/TypeArgumentType.ts";
|
|
1
19
|
import type { InstancesByEntityName } from "../../shared/utils/instances.ts";
|
|
2
|
-
import type
|
|
20
|
+
import { type Decl, type IncludableDeclP } from "./declarations/Declaration.ts";
|
|
21
|
+
import { type EntityDecl } from "./declarations/EntityDecl.ts";
|
|
22
|
+
import { type EnumDecl } from "./declarations/EnumDecl.ts";
|
|
23
|
+
import { type TypeAliasDecl } from "./declarations/TypeAliasDecl.ts";
|
|
24
|
+
import { type TypeParameter } from "./TypeParameter.ts";
|
|
25
|
+
import { type ArrayType } from "./types/generic/ArrayType.ts";
|
|
26
|
+
import { type EnumCaseDecl, type EnumType } from "./types/generic/EnumType.ts";
|
|
27
|
+
import { type MemberDecl, type ObjectType } from "./types/generic/ObjectType.ts";
|
|
28
|
+
import { type BooleanType } from "./types/primitives/BooleanType.ts";
|
|
29
|
+
import { type DateType } from "./types/primitives/DateType.ts";
|
|
30
|
+
import { type FloatType } from "./types/primitives/FloatType.ts";
|
|
31
|
+
import { type IntegerType } from "./types/primitives/IntegerType.ts";
|
|
32
|
+
import { type StringType } from "./types/primitives/StringType.ts";
|
|
33
|
+
import { type ChildEntitiesType } from "./types/references/ChildEntitiesType.ts";
|
|
34
|
+
import { type IncludeIdentifierType } from "./types/references/IncludeIdentifierType.ts";
|
|
35
|
+
import { type NestedEntityMapType } from "./types/references/NestedEntityMapType.ts";
|
|
36
|
+
import { type ReferenceIdentifierType } from "./types/references/ReferenceIdentifierType.ts";
|
|
37
|
+
import { type TypeArgumentType } from "./types/references/TypeArgumentType.ts";
|
|
3
38
|
import type { Type } from "./types/Type.ts";
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
FloatType: "FloatType";
|
|
14
|
-
IntegerType: "IntegerType";
|
|
15
|
-
StringType: "StringType";
|
|
16
|
-
DateType: "DateType";
|
|
17
|
-
TypeArgumentType: "TypeArgumentType";
|
|
18
|
-
GenericParameter: "GenericParameter";
|
|
19
|
-
ReferenceIdentifierType: "ReferenceIdentifierType";
|
|
20
|
-
IncludeIdentifierType: "IncludeIdentifierType";
|
|
21
|
-
NestedEntityMapType: "NestedEntityMapType";
|
|
22
|
-
EnumType: "EnumType";
|
|
23
|
-
}
|
|
24
|
-
export declare const NodeKind: NodeKind;
|
|
25
|
-
export interface BaseNode {
|
|
26
|
-
kind: (typeof NodeKind)[keyof typeof NodeKind];
|
|
27
|
-
}
|
|
28
|
-
export type Node = Decl | Type;
|
|
29
|
-
export declare const flatMapAuxiliaryDecls: (callbackFn: (node: Node, existingDecls: Decl[]) => (Decl | undefined)[] | Decl | undefined, declarations: readonly Decl[]) => Decl[];
|
|
39
|
+
export type { BaseNode } from "../../shared/schema/Node.ts";
|
|
40
|
+
export { NodeKind };
|
|
41
|
+
export type Node = Decl | Type | TypeParameter;
|
|
42
|
+
export declare const reduceNodes: <R>(reducer: (parentNodes: Node[], node: Node, collectedResults: R[]) => R[], nodes: readonly Node[], options?: {
|
|
43
|
+
initialResults?: R[];
|
|
44
|
+
followIncludes?: boolean;
|
|
45
|
+
followChildEntities?: boolean;
|
|
46
|
+
}) => R[];
|
|
47
|
+
export declare const flatMapAuxiliaryDecls: (callbackFn: (parentNodes: Node[], node: Node, existingDecls: Decl[]) => (Decl | undefined)[] | Decl | undefined, declarations: readonly Decl[]) => Decl[];
|
|
30
48
|
export type IdentifierToCheck = {
|
|
31
49
|
name: string;
|
|
32
50
|
value: unknown;
|
|
@@ -36,5 +54,58 @@ export interface Validators {
|
|
|
36
54
|
checkReferentialIntegrity: (identifier: IdentifierToCheck) => Error[];
|
|
37
55
|
}
|
|
38
56
|
export declare const createValidators: (instancesByEntityName: InstancesByEntityName, useStyling: boolean, checkReferentialIntegrity?: boolean) => Validators;
|
|
39
|
-
export type
|
|
40
|
-
export type
|
|
57
|
+
export type Predicate<T extends Node> = (node: Node) => node is T;
|
|
58
|
+
export type GetNestedDeclarations<T extends Node = Node> = (addedDecls: Decl[], node: T) => Decl[];
|
|
59
|
+
export declare const getNestedDeclarations: GetNestedDeclarations;
|
|
60
|
+
export type Validator<T extends Node = Node> = (helpers: Validators, node: T, value: unknown) => Error[];
|
|
61
|
+
export type ValidatorOfParamDecl<T extends Node = Node> = (helpers: Validators, node: T, typeArgs: Type[], value: unknown) => Error[];
|
|
62
|
+
export declare const validateDecl: ValidatorOfParamDecl<Decl>;
|
|
63
|
+
export declare const validateType: Validator<Type>;
|
|
64
|
+
export type NodeWithResolvedTypeArguments<T extends Node | null> = T extends BooleanType | DateType | FloatType | IntegerType | StringType | ReferenceIdentifierType ? T : T extends EntityDecl<infer N, infer P, infer FK> ? EntityDecl<N, {
|
|
65
|
+
[K in keyof P]: P[K] extends MemberDecl<infer PT, infer R> ? MemberDecl<NodeWithResolvedTypeArguments<PT>, R> : never;
|
|
66
|
+
}, FK> : T extends EnumDecl<infer N, infer V, TypeParameter[]> ? EnumDecl<N, {
|
|
67
|
+
[K in keyof V]: V[K] extends EnumCaseDecl<infer CT> ? EnumCaseDecl<NodeWithResolvedTypeArguments<CT>> : never;
|
|
68
|
+
}, [
|
|
69
|
+
]> : T extends TypeAliasDecl<infer N, infer U, TypeParameter[]> ? TypeAliasDecl<N, NodeWithResolvedTypeArguments<U>, []> : T extends ArrayType<infer I> ? ArrayType<NodeWithResolvedTypeArguments<I>> : T extends EnumType<infer V> ? EnumType<{
|
|
70
|
+
[K in keyof V]: V[K] extends EnumCaseDecl<infer CT> ? EnumCaseDecl<NodeWithResolvedTypeArguments<CT>> : never;
|
|
71
|
+
}> : T extends ObjectType<infer P> ? ObjectType<{
|
|
72
|
+
[K in keyof P]: P[K] extends MemberDecl<infer PT, infer R> ? MemberDecl<NodeWithResolvedTypeArguments<PT>, R> : never;
|
|
73
|
+
}> : T extends TypeArgumentType ? Type : T extends IncludeIdentifierType<[], IncludableDeclP<[]>> ? T : T extends IncludeIdentifierType ? Type : T extends NestedEntityMapType<infer N, infer P> ? NestedEntityMapType<N, {
|
|
74
|
+
[K in keyof P]: P[K] extends MemberDecl<infer PT, infer R> ? MemberDecl<NodeWithResolvedTypeArguments<PT>, R> : never;
|
|
75
|
+
}> : T extends TypeParameter<infer N, infer C> ? TypeParameter<N, NodeWithResolvedTypeArguments<C>> : T extends ChildEntitiesType<infer E> ? ChildEntitiesType<E> : T extends null ? null : never;
|
|
76
|
+
export type TypeArgumentsResolver<T extends Node = Node> = (args: Record<string, Type>, node: T) => NodeWithResolvedTypeArguments<T>;
|
|
77
|
+
export declare const resolveTypeArguments: <T extends Node = Node>(args: Record<string, Type>, node: T) => NodeWithResolvedTypeArguments<T>;
|
|
78
|
+
export type SerializedNodeMap = {
|
|
79
|
+
[NodeKind.EntityDecl]: [EntityDecl, SerializedEntityDecl];
|
|
80
|
+
[NodeKind.EnumDecl]: [EnumDecl, SerializedEnumDecl];
|
|
81
|
+
[NodeKind.TypeAliasDecl]: [TypeAliasDecl, SerializedTypeAliasDecl];
|
|
82
|
+
[NodeKind.ArrayType]: [ArrayType, SerializedArrayType];
|
|
83
|
+
[NodeKind.ObjectType]: [ObjectType, SerializedObjectType];
|
|
84
|
+
[NodeKind.BooleanType]: [BooleanType, SerializedBooleanType];
|
|
85
|
+
[NodeKind.DateType]: [DateType, SerializedDateType];
|
|
86
|
+
[NodeKind.FloatType]: [FloatType, SerializedFloatType];
|
|
87
|
+
[NodeKind.IntegerType]: [IntegerType, SerializedIntegerType];
|
|
88
|
+
[NodeKind.StringType]: [StringType, SerializedStringType];
|
|
89
|
+
[NodeKind.TypeArgumentType]: [TypeArgumentType, SerializedTypeArgumentType];
|
|
90
|
+
[NodeKind.ReferenceIdentifierType]: [ReferenceIdentifierType, SerializedReferenceIdentifierType];
|
|
91
|
+
[NodeKind.IncludeIdentifierType]: [IncludeIdentifierType, SerializedIncludeIdentifierType];
|
|
92
|
+
[NodeKind.NestedEntityMapType]: [NestedEntityMapType, SerializedNestedEntityMapType];
|
|
93
|
+
[NodeKind.EnumType]: [EnumType, SerializedEnumType];
|
|
94
|
+
[NodeKind.TypeParameter]: [TypeParameter, SerializedTypeParameter];
|
|
95
|
+
[NodeKind.ChildEntitiesType]: [ChildEntitiesType, SerializedChildEntitiesType];
|
|
96
|
+
};
|
|
97
|
+
export type SerializedTypeParameters<T extends TypeParameter[]> = {
|
|
98
|
+
[K in keyof T]: T[K] extends TypeParameter<infer N, infer C> ? SerializedTypeParameter<N, C extends Type ? Serialized<C> : undefined> : never;
|
|
99
|
+
};
|
|
100
|
+
export type SerializedMemberDeclObject<T extends Record<string, MemberDecl>> = {
|
|
101
|
+
[K in keyof T]: T[K] extends MemberDecl<infer CT, infer R> ? SerializedMemberDecl<Serialized<CT>, R> : never;
|
|
102
|
+
};
|
|
103
|
+
export type SerializedEnumCaseDeclObject<T extends Record<string, EnumCaseDecl>> = {
|
|
104
|
+
[K in keyof T]: T[K] extends EnumCaseDecl<infer CT> ? SerializedEnumCaseDecl<CT extends Type ? Serialized<CT> : null> : never;
|
|
105
|
+
};
|
|
106
|
+
export type Serialized<T extends Node> = T extends EntityDecl<infer Name, infer T, infer FK> ? SerializedEntityDecl<Name, SerializedMemberDeclObject<T>, FK> : T extends EnumDecl<infer Name, infer T, infer Params> ? SerializedEnumDecl<Name, SerializedEnumCaseDeclObject<T>, SerializedTypeParameters<Params>> : T extends TypeAliasDecl<infer Name, infer T, infer Params> ? SerializedTypeAliasDecl<Name, Serialized<T>, SerializedTypeParameters<Params>> : T extends ArrayType<infer T> ? SerializedArrayType<Serialized<T>> : T extends ObjectType<infer T> ? SerializedObjectType<SerializedMemberDeclObject<T>> : T extends BooleanType ? SerializedBooleanType : T extends DateType ? SerializedDateType : T extends FloatType ? SerializedFloatType : T extends IntegerType ? SerializedIntegerType : T extends StringType ? SerializedStringType : T extends TypeArgumentType<infer T> ? SerializedTypeArgumentType<Serialized<T>> : T extends ReferenceIdentifierType ? SerializedReferenceIdentifierType : T extends IncludeIdentifierType<infer Params> ? SerializedIncludeIdentifierType<SerializedTypeParameters<Params>> : T extends NestedEntityMapType<infer Name, infer T> ? SerializedNestedEntityMapType<Name, SerializedMemberDeclObject<T>> : T extends EnumType<infer T> ? SerializedEnumType<SerializedEnumCaseDeclObject<T>> : T extends TypeParameter<infer N, infer C> ? SerializedTypeParameter<N, C extends Type ? Serialized<C> : undefined> : T extends ChildEntitiesType ? SerializedChildEntitiesType : never;
|
|
107
|
+
export type SerializedOf<T extends Node> = SerializedNodeMap[T["kind"]][1];
|
|
108
|
+
export type Serializer<T extends Node = Node> = (node: T) => Serialized<T>;
|
|
109
|
+
export declare const serializeNode: <T extends Node>(node: T) => Serialized<T>;
|
|
110
|
+
export type GetReferences<T extends Node = Node> = (node: T, value: unknown) => string[];
|
|
111
|
+
export declare const getReferences: GetReferences;
|