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
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { serializeEntityDecl } from "../../node/schema/index.js";
|
|
2
|
-
import { getSerializedDisplayNameFromEntityInstance } from "../../shared/utils/displayName.js";
|
|
3
|
-
export const getDisplayNameFromEntityInstance = (entity, instance, getInstanceById, locales
|
|
2
|
+
import { getSerializedDisplayNameFromEntityInstance, } from "../../shared/utils/displayName.js";
|
|
3
|
+
export const getDisplayNameFromEntityInstance = (entity, instance, getInstanceById, locales, defaultName = "", useCustomizer = true) => {
|
|
4
4
|
if (useCustomizer && entity.displayNameCustomizer) {
|
|
5
|
-
|
|
5
|
+
const calculatedName = getDisplayNameFromEntityInstance(entity, instance, getInstanceById, locales, defaultName, false);
|
|
6
|
+
return entity.displayNameCustomizer(instance, calculatedName.name, calculatedName.localeId, id => getInstanceById(id)?.instance.content, id => {
|
|
6
7
|
const result = getInstanceById(id);
|
|
7
8
|
if (result) {
|
|
8
9
|
const { entity, instance } = result;
|
|
9
|
-
return getDisplayNameFromEntityInstance(entity, instance.content, getInstanceById, locales, id);
|
|
10
|
+
return getDisplayNameFromEntityInstance(entity, instance.content, getInstanceById, locales, id).name;
|
|
10
11
|
}
|
|
11
12
|
else {
|
|
12
13
|
return undefined;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { EntityDecl } from "../schema/index.ts";
|
|
2
|
+
export declare const getFileNameForId: (id: string) => string;
|
|
3
|
+
export declare const getPathToInstance: (dataRoot: string, entityName: string, id: string) => string;
|
|
4
|
+
export declare const writeInstance: (dataRoot: string, entity: EntityDecl, id: string, instance: unknown) => Promise<void>;
|
|
5
|
+
export declare const deleteInstance: (dataRoot: string, entityName: string, id: string) => Promise<void>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { rm, writeFile } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { formatInstance } from "./instances.js";
|
|
4
|
+
export const getFileNameForId = (id) => `${id}.json`;
|
|
5
|
+
export const getPathToInstance = (dataRoot, entityName, id) => join(dataRoot, entityName, getFileNameForId(id));
|
|
6
|
+
export const writeInstance = (dataRoot, entity, id, instance) => writeFile(getPathToInstance(dataRoot, entity.name, id), formatInstance(entity, instance), {
|
|
7
|
+
encoding: "utf-8",
|
|
8
|
+
});
|
|
9
|
+
export const deleteInstance = (dataRoot, entityName, id) => rm(getPathToInstance(dataRoot, entityName, id));
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { InstancesByEntityName } from "../../shared/utils/instances.ts";
|
|
2
|
+
import { type Result } from "../../shared/utils/result.ts";
|
|
3
|
+
import type { EntityDecl } from "../schema/declarations/EntityDecl.js";
|
|
4
|
+
import { type ReferencesToInstances } from "./references.ts";
|
|
5
|
+
export declare const createNewId: () => string;
|
|
6
|
+
export declare const checkCreateInstancePossible: (localeEntity: EntityDecl | undefined, instancesByEntityName: InstancesByEntityName, entity: EntityDecl, instanceContent: unknown, customId: unknown) => Result<string, [code: number, message: string]>;
|
|
7
|
+
export declare const createInstance: (dataRoot: string, localeEntity: EntityDecl | undefined, instancesByEntityName: InstancesByEntityName, entity: EntityDecl, instanceContent: unknown, customId: unknown) => Promise<Result<string, [code: number, message: string]>>;
|
|
8
|
+
export declare const checkUpdateInstancePossible: (instancesByEntityName: InstancesByEntityName, entity: EntityDecl, instanceContent: unknown) => Result<void, [code: number, message: string]>;
|
|
9
|
+
export declare const checkCreateNonLocaleInstancePossible: (instancesByEntityName: InstancesByEntityName, entity: EntityDecl, instanceContent: unknown) => Result<void, [code: number, message: string]>;
|
|
10
|
+
export declare const unsafeWriteInstance: (dataRoot: string, entity: EntityDecl, instanceId: string, instanceContent: unknown) => Promise<Result<string, [code: number, message: string]>>;
|
|
11
|
+
export declare const updateInstance: (dataRoot: string, instancesByEntityName: InstancesByEntityName, entity: EntityDecl, instanceId: string, instanceContent: unknown) => Promise<Result<string, [code: number, message: string]>>;
|
|
12
|
+
export declare const checkDeleteInstancePossible: (referencesToInstances: ReferencesToInstances, instanceId: string) => Result<void, [code: number, message: string]>;
|
|
13
|
+
export declare const unsafeDeleteInstance: (dataRoot: string, entityName: string, instanceId: string) => Promise<Result<string, [code: number, message: string]>>;
|
|
14
|
+
export declare const deleteInstance: (dataRoot: string, referencesToInstances: ReferencesToInstances, entityName: string, instanceId: string) => Promise<Result<string, [code: number, message: string]>>;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { v4 as uuidv4 } from "uuid";
|
|
2
|
+
import { error, isOk, map, ok } from "../../shared/utils/result.js";
|
|
3
|
+
import { createValidators, validateEntityDecl } from "../schema/index.js";
|
|
4
|
+
import { getErrorMessageForDisplay } from "./error.js";
|
|
5
|
+
import * as Files from "./files.js";
|
|
6
|
+
import { isReferencedByOtherInstances } from "./references.js";
|
|
7
|
+
export const createNewId = () => uuidv4();
|
|
8
|
+
export const checkCreateInstancePossible = (localeEntity, instancesByEntityName, entity, instanceContent, customId) => {
|
|
9
|
+
const newInstanceId = entity === localeEntity ? customId : createNewId();
|
|
10
|
+
if (typeof newInstanceId !== "string") {
|
|
11
|
+
return error([400, `New identifier "${String(newInstanceId)}" is not a string`]);
|
|
12
|
+
}
|
|
13
|
+
if (localeEntity === entity &&
|
|
14
|
+
instancesByEntityName[entity.name]?.some(instance => instance.id === newInstanceId)) {
|
|
15
|
+
return error([400, `Duplicate id "${newInstanceId}" for locale entity`]);
|
|
16
|
+
}
|
|
17
|
+
return map(checkUpdateInstancePossible(instancesByEntityName, entity, instanceContent), () => newInstanceId);
|
|
18
|
+
};
|
|
19
|
+
export const createInstance = async (dataRoot, localeEntity, instancesByEntityName, entity, instanceContent, customId) => {
|
|
20
|
+
const prerequisiteCheckResult = checkCreateInstancePossible(localeEntity, instancesByEntityName, entity, instanceContent, customId);
|
|
21
|
+
if (isOk(prerequisiteCheckResult)) {
|
|
22
|
+
const newInstanceId = prerequisiteCheckResult.value;
|
|
23
|
+
return unsafeWriteInstance(dataRoot, entity, newInstanceId, instanceContent);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
return prerequisiteCheckResult;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
export const checkUpdateInstancePossible = (instancesByEntityName, entity, instanceContent) => {
|
|
30
|
+
const validationErrors = validateEntityDecl(createValidators(instancesByEntityName, false), entity, instanceContent);
|
|
31
|
+
if (validationErrors.length > 0) {
|
|
32
|
+
return error([400, validationErrors.map(getErrorMessageForDisplay).join("\n\n")]);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
return ok();
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
export const checkCreateNonLocaleInstancePossible = checkUpdateInstancePossible;
|
|
39
|
+
export const unsafeWriteInstance = async (dataRoot, entity, instanceId, instanceContent) => {
|
|
40
|
+
try {
|
|
41
|
+
await Files.writeInstance(dataRoot, entity, instanceId, instanceContent);
|
|
42
|
+
return ok(instanceId);
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
return error([
|
|
46
|
+
500,
|
|
47
|
+
`Failed to write instance: ${err instanceof Error ? err.toString() : String(err)}`,
|
|
48
|
+
]);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
export const updateInstance = async (dataRoot, instancesByEntityName, entity, instanceId, instanceContent) => {
|
|
52
|
+
const prerequisiteCheckResult = checkUpdateInstancePossible(instancesByEntityName, entity, instanceContent);
|
|
53
|
+
if (isOk(prerequisiteCheckResult)) {
|
|
54
|
+
return unsafeWriteInstance(dataRoot, entity, instanceId, instanceContent);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
return prerequisiteCheckResult;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
export const checkDeleteInstancePossible = (referencesToInstances, instanceId) => {
|
|
61
|
+
if (isReferencedByOtherInstances(referencesToInstances, instanceId)) {
|
|
62
|
+
return error([400, "Cannot delete instance that is referenced by other instances"]);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
return ok();
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
export const unsafeDeleteInstance = async (dataRoot, entityName, instanceId) => {
|
|
69
|
+
try {
|
|
70
|
+
await Files.deleteInstance(dataRoot, entityName, instanceId);
|
|
71
|
+
return ok(instanceId);
|
|
72
|
+
}
|
|
73
|
+
catch (err) {
|
|
74
|
+
return error([
|
|
75
|
+
500,
|
|
76
|
+
`Failed to delete instance: ${err instanceof Error ? err.toString() : String(err)}`,
|
|
77
|
+
]);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
export const deleteInstance = async (dataRoot, referencesToInstances, entityName, instanceId) => {
|
|
81
|
+
const prerequisiteCheckResult = checkDeleteInstancePossible(referencesToInstances, instanceId);
|
|
82
|
+
if (isOk(prerequisiteCheckResult)) {
|
|
83
|
+
return unsafeDeleteInstance(dataRoot, entityName, instanceId);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
return prerequisiteCheckResult;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { StatusResult } from "simple-git";
|
|
2
2
|
import type { InstancesByEntityName } from "../../shared/utils/instances.ts";
|
|
3
|
-
import type { EntityDecl } from "../schema/declarations/EntityDecl.
|
|
3
|
+
import type { EntityDecl } from "../schema/declarations/EntityDecl.js";
|
|
4
4
|
export declare const getInstancesByEntityName: (dataRoot: string, entities: readonly EntityDecl[]) => Promise<InstancesByEntityName>;
|
|
5
5
|
export declare const attachGitStatusToInstancesByEntityName: (instancesByEntityName: InstancesByEntityName, dataRoot: string, gitRoot: string, gitStatus: StatusResult) => void;
|
|
6
6
|
export declare const formatInstance: (entity: EntityDecl, instanceContent: unknown) => string;
|
|
@@ -1,22 +1,28 @@
|
|
|
1
|
+
import child_process from "node:child_process";
|
|
1
2
|
import { readdir, readFile } from "node:fs/promises";
|
|
2
3
|
import { basename, extname, join } from "node:path";
|
|
4
|
+
import { platform } from "node:process";
|
|
5
|
+
import { promisify } from "node:util";
|
|
6
|
+
import { mapAsync } from "../../shared/utils/async.js";
|
|
3
7
|
import { formatValue } from "../schema/index.js";
|
|
8
|
+
import { getFileNameForId } from "./files.js";
|
|
4
9
|
import { getGitFileStatusFromStatusResult } from "./git.js";
|
|
5
|
-
|
|
10
|
+
const exec = promisify(child_process.exec);
|
|
11
|
+
const ulimit = platform === "win32" ? 2048 : Number.parseInt((await exec("ulimit -n")).stdout);
|
|
12
|
+
export const getInstancesByEntityName = async (dataRoot, entities) => Object.fromEntries((await mapAsync(entities, async (entity) => {
|
|
6
13
|
const entityDir = join(dataRoot, entity.name);
|
|
7
14
|
const instanceFileNames = await readdir(entityDir);
|
|
8
|
-
const instances = await
|
|
9
|
-
fileName: instanceFileName,
|
|
15
|
+
const instances = await mapAsync(instanceFileNames, async (instanceFileName) => ({
|
|
10
16
|
id: basename(instanceFileName, extname(instanceFileName)),
|
|
11
17
|
content: JSON.parse(await readFile(join(entityDir, instanceFileName), "utf-8")),
|
|
12
|
-
}))
|
|
18
|
+
}), ulimit);
|
|
13
19
|
return [entity.name, instances];
|
|
14
|
-
}))
|
|
20
|
+
}, 1)).toSorted(([a], [b]) => a.localeCompare(b)));
|
|
15
21
|
export const attachGitStatusToInstancesByEntityName = (instancesByEntityName, dataRoot, gitRoot, gitStatus) => {
|
|
16
22
|
Object.entries(instancesByEntityName).forEach(([entityName, instances]) => {
|
|
17
23
|
instancesByEntityName[entityName] = instances.map(instanceContainer => ({
|
|
18
24
|
...instanceContainer,
|
|
19
|
-
gitStatus: getGitFileStatusFromStatusResult(gitStatus, gitRoot, dataRoot, entityName, instanceContainer.
|
|
25
|
+
gitStatus: getGitFileStatusFromStatusResult(gitStatus, gitRoot, dataRoot, entityName, getFileNameForId(instanceContainer.id)),
|
|
20
26
|
}));
|
|
21
27
|
});
|
|
22
28
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { SerializedDecl } from "../../shared/schema/declarations/Declaration.ts";
|
|
1
2
|
import type { InstanceContainer } from "../../shared/utils/instances.ts";
|
|
2
3
|
import type { EntityDecl } from "../schema/declarations/EntityDecl.ts";
|
|
3
4
|
/**
|
|
@@ -6,5 +7,6 @@ import type { EntityDecl } from "../schema/declarations/EntityDecl.ts";
|
|
|
6
7
|
export type ReferencesToInstances = {
|
|
7
8
|
[instanceId: string]: string[];
|
|
8
9
|
};
|
|
9
|
-
export declare const
|
|
10
|
+
export declare const isReferencedByOtherInstances: (referencesToInstances: ReferencesToInstances, instanceId: string, otherInstancesToDelete?: string[]) => boolean;
|
|
11
|
+
export declare const getReferencesToInstances: (instancesByEntityName: Record<string, InstanceContainer[]>, serializedDeclarationsByName: Record<string, SerializedDecl>) => Promise<ReferencesToInstances>;
|
|
10
12
|
export declare const updateReferencesToInstances: (entitiesByName: Record<string, EntityDecl>, referencesToInstances: ReferencesToInstances, entityName: string, instanceId: string, oldInstance: unknown, newInstance: unknown) => ReferencesToInstances;
|
|
@@ -1,33 +1,58 @@
|
|
|
1
1
|
import Debug from "debug";
|
|
2
|
+
import { resolve } from "node:path";
|
|
2
3
|
import { difference, removeAt } from "../../shared/utils/array.js";
|
|
4
|
+
import { isOk } from "../../shared/utils/result.js";
|
|
3
5
|
import { getReferencesForEntityDecl } from "../schema/declarations/EntityDecl.js";
|
|
6
|
+
import { WorkerPool } from "./workers.js";
|
|
4
7
|
const debug = Debug("tsondb:utils:references");
|
|
8
|
+
export const isReferencedByOtherInstances = (referencesToInstances, instanceId, otherInstancesToDelete) => {
|
|
9
|
+
const allInstancesToDelete = [instanceId, ...(otherInstancesToDelete ?? [])];
|
|
10
|
+
return referencesToInstances[instanceId]?.some(ref => allInstancesToDelete.includes(ref)) ?? false;
|
|
11
|
+
};
|
|
5
12
|
const addReference = (acc, reference, instanceId) => ({
|
|
6
13
|
...acc,
|
|
7
14
|
[reference]: [...(acc[reference] ?? []), instanceId],
|
|
8
15
|
});
|
|
9
16
|
const addReferences = (acc, references, instanceId) => references.reduce((acc1, reference) => addReference(acc1, reference, instanceId), acc);
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
17
|
+
const mergeReferences = (acc, toMerge) => {
|
|
18
|
+
for (const instanceId in toMerge) {
|
|
19
|
+
;
|
|
20
|
+
(acc[instanceId] ??= []).push(...(toMerge[instanceId] ?? []));
|
|
21
|
+
}
|
|
22
|
+
return acc;
|
|
23
|
+
};
|
|
24
|
+
const removeReference = (acc, reference, instanceId) => {
|
|
25
|
+
if (acc[reference]) {
|
|
26
|
+
const index = acc[reference].indexOf(instanceId);
|
|
27
|
+
if (index > -1) {
|
|
28
|
+
return {
|
|
29
|
+
...acc,
|
|
30
|
+
[reference]: removeAt(acc[reference], index),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
14
33
|
}
|
|
15
|
-
|
|
34
|
+
return acc;
|
|
35
|
+
};
|
|
16
36
|
const removeReferences = (acc, references, instanceId) => references.reduce((acc1, reference) => removeReference(acc1, reference, instanceId), acc);
|
|
17
|
-
export const getReferencesToInstances = (instancesByEntityName,
|
|
37
|
+
export const getReferencesToInstances = async (instancesByEntityName, serializedDeclarationsByName) => {
|
|
38
|
+
debug("creating reference worker pool ...");
|
|
39
|
+
const pool = new WorkerPool(6, resolve(import.meta.dirname, "./referencesWorker.js"), serializedDeclarationsByName);
|
|
18
40
|
debug("collecting references ...");
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
41
|
+
const separateResults = await Promise.all(Object.entries(instancesByEntityName).map(([entityName, instances]) => new Promise((resolve, reject) => {
|
|
42
|
+
pool.runTask({ entityName, instances }, result => {
|
|
43
|
+
if (isOk(result)) {
|
|
44
|
+
debug("collected references for entity %s in %d instances", entityName, instances.length);
|
|
45
|
+
resolve(result.value);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
reject(result.error);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
})));
|
|
52
|
+
await pool.close();
|
|
53
|
+
const results = separateResults.reduce(mergeReferences, {});
|
|
54
|
+
debug("collected references");
|
|
55
|
+
return results;
|
|
31
56
|
};
|
|
32
57
|
export const updateReferencesToInstances = (entitiesByName, referencesToInstances, entityName, instanceId, oldInstance, newInstance) => {
|
|
33
58
|
const entity = entitiesByName[entityName];
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { parentPort, workerData } from "node:worker_threads";
|
|
2
|
+
import { getReferencesForSerializedEntityDecl, isSerializedEntityDecl, } from "../../shared/schema/declarations/EntityDecl.js";
|
|
3
|
+
const declarationsByName = workerData;
|
|
4
|
+
const addReference = (acc, reference, instanceId) => ({
|
|
5
|
+
...acc,
|
|
6
|
+
[reference]: [...(acc[reference] ?? []), instanceId],
|
|
7
|
+
});
|
|
8
|
+
const addReferences = (acc, references, instanceId) => references.reduce((acc1, reference) => addReference(acc1, reference, instanceId), acc);
|
|
9
|
+
parentPort?.on("message", (task) => {
|
|
10
|
+
const entityDecl = declarationsByName[task.entityName];
|
|
11
|
+
if (!entityDecl) {
|
|
12
|
+
throw new Error(`entity declaration not found for entity name "${task.entityName}"`);
|
|
13
|
+
}
|
|
14
|
+
if (!isSerializedEntityDecl(entityDecl)) {
|
|
15
|
+
throw new Error(`declaration of name "${task.entityName}" is not an entity declaration`);
|
|
16
|
+
}
|
|
17
|
+
const refs = task.instances.reduce((acc, instance) => {
|
|
18
|
+
const references = getReferencesForSerializedEntityDecl(declarationsByName, entityDecl, instance.content);
|
|
19
|
+
return addReferences(acc, references, instance.id);
|
|
20
|
+
}, {});
|
|
21
|
+
parentPort?.postMessage(refs);
|
|
22
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { EventEmitter } from "node:events";
|
|
2
|
+
import { type Result } from "../../shared/utils/result.ts";
|
|
3
|
+
type TaskInfoCallback<R> = (result: Result<R, Error>) => void;
|
|
4
|
+
export declare class WorkerPool<T, R, I = undefined> extends EventEmitter {
|
|
5
|
+
private scriptPath;
|
|
6
|
+
private workers;
|
|
7
|
+
private freeWorkers;
|
|
8
|
+
private tasks;
|
|
9
|
+
private initialData;
|
|
10
|
+
constructor(...args: I extends undefined ? [numThreads: number, scriptPath: string, initialData?: I] : [numThreads: number, scriptPath: string, initialData: I]);
|
|
11
|
+
addNewWorker(): void;
|
|
12
|
+
runTask(task: T, callback: TaskInfoCallback<R>): void;
|
|
13
|
+
close(): Promise<number[]>;
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { AsyncResource } from "node:async_hooks";
|
|
2
|
+
import { EventEmitter } from "node:events";
|
|
3
|
+
import { Worker } from "node:worker_threads";
|
|
4
|
+
import { error, ok } from "../../shared/utils/result.js";
|
|
5
|
+
// from https://nodejs.org/api/async_context.html#using-asyncresource-for-a-worker-thread-pool
|
|
6
|
+
const kTaskInfo = Symbol("kTaskInfo");
|
|
7
|
+
const kWorkerFreedEvent = Symbol("kWorkerFreedEvent");
|
|
8
|
+
class WorkerPoolTaskInfo extends AsyncResource {
|
|
9
|
+
callback;
|
|
10
|
+
constructor(callback) {
|
|
11
|
+
super("WorkerPoolTaskInfo");
|
|
12
|
+
this.callback = callback;
|
|
13
|
+
}
|
|
14
|
+
done(result) {
|
|
15
|
+
this.runInAsyncScope(this.callback, null, result);
|
|
16
|
+
this.emitDestroy(); // `TaskInfo`s are used only once.
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export class WorkerPool extends EventEmitter {
|
|
20
|
+
scriptPath;
|
|
21
|
+
workers;
|
|
22
|
+
freeWorkers;
|
|
23
|
+
tasks;
|
|
24
|
+
initialData;
|
|
25
|
+
constructor(...args) {
|
|
26
|
+
const [numThreads, scriptPath, initialData] = args;
|
|
27
|
+
super();
|
|
28
|
+
this.scriptPath = scriptPath;
|
|
29
|
+
this.workers = [];
|
|
30
|
+
this.freeWorkers = [];
|
|
31
|
+
this.tasks = [];
|
|
32
|
+
this.initialData = initialData;
|
|
33
|
+
for (let i = 0; i < numThreads; i++) {
|
|
34
|
+
this.addNewWorker();
|
|
35
|
+
}
|
|
36
|
+
// Any time the kWorkerFreedEvent is emitted, dispatch
|
|
37
|
+
// the next task pending in the queue, if any.
|
|
38
|
+
this.on(kWorkerFreedEvent, () => {
|
|
39
|
+
const first = this.tasks.shift();
|
|
40
|
+
if (first) {
|
|
41
|
+
const { task, callback } = first;
|
|
42
|
+
this.runTask(task, callback);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
addNewWorker() {
|
|
47
|
+
const worker = new Worker(this.scriptPath, {
|
|
48
|
+
workerData: this.initialData,
|
|
49
|
+
});
|
|
50
|
+
worker.on("message", (result) => {
|
|
51
|
+
// In case of success: Call the callback that was passed to `runTask`,
|
|
52
|
+
// remove the `TaskInfo` associated with the Worker, and mark it as free
|
|
53
|
+
// again.
|
|
54
|
+
worker[kTaskInfo]?.done(ok(result));
|
|
55
|
+
worker[kTaskInfo] = null;
|
|
56
|
+
this.freeWorkers.push(worker);
|
|
57
|
+
this.emit(kWorkerFreedEvent);
|
|
58
|
+
});
|
|
59
|
+
worker.on("error", err => {
|
|
60
|
+
// In case of an uncaught exception: Call the callback that was passed to
|
|
61
|
+
// `runTask` with the error.
|
|
62
|
+
if (worker[kTaskInfo])
|
|
63
|
+
worker[kTaskInfo].done(error(err));
|
|
64
|
+
else
|
|
65
|
+
this.emit("error", err);
|
|
66
|
+
// Remove the worker from the list and start a new Worker to replace the
|
|
67
|
+
// current one.
|
|
68
|
+
this.workers.splice(this.workers.indexOf(worker), 1);
|
|
69
|
+
this.addNewWorker();
|
|
70
|
+
});
|
|
71
|
+
this.workers.push(worker);
|
|
72
|
+
this.freeWorkers.push(worker);
|
|
73
|
+
this.emit(kWorkerFreedEvent);
|
|
74
|
+
}
|
|
75
|
+
runTask(task, callback) {
|
|
76
|
+
if (this.freeWorkers.length === 0) {
|
|
77
|
+
// No free threads, wait until a worker thread becomes free.
|
|
78
|
+
this.tasks.push({ task, callback });
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const worker = this.freeWorkers.pop();
|
|
82
|
+
if (worker) {
|
|
83
|
+
worker[kTaskInfo] = new WorkerPoolTaskInfo(callback);
|
|
84
|
+
worker.postMessage(task);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
close() {
|
|
88
|
+
return Promise.all(this.workers.map(worker => worker.terminate()));
|
|
89
|
+
}
|
|
90
|
+
}
|
package/dist/src/shared/api.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { CreatedEntityTaggedInstanceContainerWithChildInstances, EntityTaggedInstanceContainerWithChildInstances, UpdatedEntityTaggedInstanceContainerWithChildInstances } from "../node/utils/childInstances.ts";
|
|
2
|
+
import type { WebConfig } from "../web/context/config.ts";
|
|
3
|
+
import type { SerializedDecl } from "./schema/declarations/Declaration.ts";
|
|
2
4
|
import type { InstanceContainer, InstanceContainerOverview } from "./utils/instances.ts";
|
|
5
|
+
export type GetWebConfigResponseBody = WebConfig;
|
|
3
6
|
export interface GetAllDeclarationsResponseBody<D extends SerializedDecl = SerializedDecl> {
|
|
4
7
|
declarations: {
|
|
5
8
|
declaration: D;
|
|
@@ -16,6 +19,12 @@ export interface GetAllInstancesOfEntityResponseBody {
|
|
|
16
19
|
instances: InstanceContainerOverview[];
|
|
17
20
|
isLocaleEntity: boolean;
|
|
18
21
|
}
|
|
22
|
+
export interface GetAllChildInstancesOfInstanceResponseBody {
|
|
23
|
+
instances: EntityTaggedInstanceContainerWithChildInstances[];
|
|
24
|
+
}
|
|
25
|
+
export interface CreateInstanceOfEntityRequestBody {
|
|
26
|
+
instance: CreatedEntityTaggedInstanceContainerWithChildInstances;
|
|
27
|
+
}
|
|
19
28
|
export interface CreateInstanceOfEntityResponseBody {
|
|
20
29
|
instance: InstanceContainer;
|
|
21
30
|
isLocaleEntity: boolean;
|
|
@@ -24,6 +33,9 @@ export interface GetInstanceOfEntityResponseBody {
|
|
|
24
33
|
instance: InstanceContainer;
|
|
25
34
|
isLocaleEntity: boolean;
|
|
26
35
|
}
|
|
36
|
+
export interface UpdateInstanceOfEntityRequestBody {
|
|
37
|
+
instance: UpdatedEntityTaggedInstanceContainerWithChildInstances;
|
|
38
|
+
}
|
|
27
39
|
export interface UpdateInstanceOfEntityResponseBody {
|
|
28
40
|
instance: InstanceContainer;
|
|
29
41
|
isLocaleEntity: boolean;
|
|
@@ -37,6 +49,7 @@ export interface GetAllInstancesResponseBody {
|
|
|
37
49
|
[entity: string]: {
|
|
38
50
|
id: string;
|
|
39
51
|
name: string;
|
|
52
|
+
displayNameLocaleId?: string;
|
|
40
53
|
}[];
|
|
41
54
|
};
|
|
42
55
|
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { SerializedDecl } from "./declarations/Declaration.ts";
|
|
2
|
+
import { type SerializedEntityDecl } from "./declarations/EntityDecl.ts";
|
|
3
|
+
import { type SerializedEnumDecl } from "./declarations/EnumDecl.ts";
|
|
4
|
+
import { type SerializedTypeAliasDecl } from "./declarations/TypeAliasDecl.ts";
|
|
5
|
+
import { type SerializedTypeParameter } from "./TypeParameter.ts";
|
|
6
|
+
import { type SerializedArrayType } from "./types/ArrayType.ts";
|
|
7
|
+
import { type SerializedBooleanType } from "./types/BooleanType.ts";
|
|
8
|
+
import { type SerializedChildEntitiesType } from "./types/ChildEntitiesType.ts";
|
|
9
|
+
import { type SerializedDateType } from "./types/DateType.ts";
|
|
10
|
+
import { type SerializedEnumCaseDecl, type SerializedEnumType } from "./types/EnumType.ts";
|
|
11
|
+
import { type SerializedFloatType } from "./types/FloatType.ts";
|
|
12
|
+
import { type SerializedIncludeIdentifierType } from "./types/IncludeIdentifierType.ts";
|
|
13
|
+
import { type SerializedIntegerType } from "./types/IntegerType.ts";
|
|
14
|
+
import { type SerializedNestedEntityMapType } from "./types/NestedEntityMapType.ts";
|
|
15
|
+
import { type SerializedMemberDecl, type SerializedObjectType } from "./types/ObjectType.ts";
|
|
16
|
+
import { type SerializedReferenceIdentifierType } from "./types/ReferenceIdentifierType.ts";
|
|
17
|
+
import { type SerializedStringType } from "./types/StringType.ts";
|
|
18
|
+
import type { SerializedType } from "./types/Type.ts";
|
|
19
|
+
import { type SerializedTypeArgumentType } from "./types/TypeArgumentType.ts";
|
|
20
|
+
export interface NodeKind {
|
|
21
|
+
ChildEntityDecl: "ChildEntityDecl";
|
|
22
|
+
EntityDecl: "EntityDecl";
|
|
23
|
+
EnumDecl: "EnumDecl";
|
|
24
|
+
EnumCaseDecl: "EnumCaseDecl";
|
|
25
|
+
TypeAliasDecl: "TypeAliasDecl";
|
|
26
|
+
MemberDecl: "MemberDecl";
|
|
27
|
+
ArrayType: "ArrayType";
|
|
28
|
+
ObjectType: "ObjectType";
|
|
29
|
+
BooleanType: "BooleanType";
|
|
30
|
+
FloatType: "FloatType";
|
|
31
|
+
IntegerType: "IntegerType";
|
|
32
|
+
StringType: "StringType";
|
|
33
|
+
DateType: "DateType";
|
|
34
|
+
TypeArgumentType: "TypeArgumentType";
|
|
35
|
+
TypeParameter: "TypeParameter";
|
|
36
|
+
ReferenceIdentifierType: "ReferenceIdentifierType";
|
|
37
|
+
IncludeIdentifierType: "IncludeIdentifierType";
|
|
38
|
+
NestedEntityMapType: "NestedEntityMapType";
|
|
39
|
+
EnumType: "EnumType";
|
|
40
|
+
ChildEntitiesType: "ChildEntitiesType";
|
|
41
|
+
}
|
|
42
|
+
export declare const NodeKind: NodeKind;
|
|
43
|
+
export interface BaseNode {
|
|
44
|
+
kind: (typeof NodeKind)[keyof typeof NodeKind];
|
|
45
|
+
}
|
|
46
|
+
export type SerializedNode = SerializedDecl | SerializedType | SerializedTypeParameter;
|
|
47
|
+
export type SerializedNodeWithResolvedTypeArguments<T extends SerializedNode | null> = T extends SerializedBooleanType | SerializedDateType | SerializedFloatType | SerializedIntegerType | SerializedStringType | SerializedReferenceIdentifierType ? T : T extends SerializedEntityDecl<infer N, infer P, infer FK> ? SerializedEntityDecl<N, {
|
|
48
|
+
[K in keyof P]: P[K] extends SerializedMemberDecl<infer PT, infer R> ? SerializedMemberDecl<SerializedNodeWithResolvedTypeArguments<PT>, R> : never;
|
|
49
|
+
}, FK> : T extends SerializedEnumDecl<infer N, infer V, SerializedTypeParameter[]> ? SerializedEnumDecl<N, {
|
|
50
|
+
[K in keyof V]: V[K] extends SerializedEnumCaseDecl<infer CT> ? SerializedEnumCaseDecl<SerializedNodeWithResolvedTypeArguments<CT>> : never;
|
|
51
|
+
}, [
|
|
52
|
+
]> : T extends SerializedTypeAliasDecl<infer N, infer U, SerializedTypeParameter[]> ? SerializedTypeAliasDecl<N, SerializedNodeWithResolvedTypeArguments<U>, []> : T extends SerializedArrayType<infer I> ? SerializedArrayType<SerializedNodeWithResolvedTypeArguments<I>> : T extends SerializedEnumType<infer V> ? SerializedEnumType<{
|
|
53
|
+
[K in keyof V]: V[K] extends SerializedEnumCaseDecl<infer CT> ? SerializedEnumCaseDecl<SerializedNodeWithResolvedTypeArguments<CT>> : never;
|
|
54
|
+
}> : T extends SerializedObjectType<infer P> ? SerializedObjectType<{
|
|
55
|
+
[K in keyof P]: P[K] extends SerializedMemberDecl<infer PT, infer R> ? SerializedMemberDecl<SerializedNodeWithResolvedTypeArguments<PT>, R> : never;
|
|
56
|
+
}> : T extends SerializedTypeArgumentType ? SerializedType : T extends SerializedIncludeIdentifierType<[]> ? T : T extends SerializedIncludeIdentifierType ? SerializedType : T extends SerializedNestedEntityMapType<infer N, infer P> ? SerializedNestedEntityMapType<N, {
|
|
57
|
+
[K in keyof P]: P[K] extends SerializedMemberDecl<infer PT, infer R> ? SerializedMemberDecl<SerializedNodeWithResolvedTypeArguments<PT>, R> : never;
|
|
58
|
+
}> : T extends SerializedTypeParameter<infer N, infer C> ? SerializedTypeParameter<N, SerializedNodeWithResolvedTypeArguments<C>> : T extends SerializedChildEntitiesType ? SerializedChildEntitiesType : T extends null ? null : never;
|
|
59
|
+
export type SerializedTypeArgumentsResolver<T extends SerializedNode = SerializedNode> = (decls: Record<string, SerializedDecl>, args: Record<string, SerializedType>, node: T) => SerializedNodeWithResolvedTypeArguments<T>;
|
|
60
|
+
export declare const resolveSerializedTypeArguments: <T extends SerializedNode = SerializedNode>(decls: Record<string, SerializedDecl>, args: Record<string, SerializedType>, node: T) => SerializedNodeWithResolvedTypeArguments<T>;
|
|
61
|
+
export type GetReferencesSerialized<T extends SerializedNode = SerializedNode> = (decls: Record<string, SerializedDecl>, node: T, value: unknown) => string[];
|
|
62
|
+
export declare const getReferencesSerialized: GetReferencesSerialized;
|
|
63
|
+
export declare const getDecl: (decls: Record<string, SerializedDecl>, name: string) => SerializedDecl;
|