tsondb 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +385 -0
- package/README.md +173 -1
- package/lib/bin/tsondb.d.ts +8 -0
- package/lib/bin/tsondb.js +83 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +1 -1
- package/lib/{Schema.d.ts → node/Schema.d.ts} +2 -2
- package/lib/{Schema.js → node/Schema.js} +1 -1
- package/lib/node/index.d.ts +8 -0
- package/lib/node/index.js +62 -0
- package/lib/{renderers → node/renderers}/Output.d.ts +1 -1
- package/lib/node/renderers/jsonschema/index.d.ts +6 -0
- package/lib/node/renderers/jsonschema/index.js +35 -0
- package/lib/node/renderers/jsonschema/render.d.ts +9 -0
- package/lib/{renderers → node/renderers}/jsonschema/render.js +42 -23
- package/lib/node/renderers/ts/index.d.ts +6 -0
- package/lib/node/renderers/ts/index.js +42 -0
- package/lib/{renderers → node/renderers}/ts/render.d.ts +3 -1
- package/lib/node/renderers/ts/render.js +136 -0
- package/lib/{schema → node/schema}/Node.d.ts +5 -4
- package/lib/{schema → node/schema}/Node.js +11 -6
- package/lib/{schema/parameters → node/schema}/TypeParameter.d.ts +3 -2
- package/lib/{schema/parameters → node/schema}/TypeParameter.js +2 -2
- package/lib/{schema → node/schema}/declarations/Declaration.d.ts +11 -10
- package/lib/{schema → node/schema}/declarations/Declaration.js +10 -4
- package/lib/{schema → node/schema}/declarations/EntityDecl.d.ts +13 -9
- package/lib/{schema → node/schema}/declarations/EntityDecl.js +2 -2
- package/lib/{schema → node/schema}/declarations/EnumDecl.d.ts +11 -26
- package/lib/node/schema/declarations/EnumDecl.js +52 -0
- package/lib/{schema → node/schema}/declarations/TypeAliasDecl.d.ts +8 -7
- package/lib/{schema → node/schema}/declarations/TypeAliasDecl.js +3 -3
- package/lib/{schema → node/schema}/index.d.ts +4 -3
- package/lib/{schema → node/schema}/index.js +3 -3
- package/lib/node/schema/types/Type.d.ts +48 -0
- package/lib/{schema → node/schema}/types/Type.js +90 -28
- package/lib/{schema → node/schema}/types/generic/ArrayType.d.ts +6 -4
- package/lib/{schema → node/schema}/types/generic/ArrayType.js +5 -4
- package/lib/node/schema/types/generic/EnumType.d.ts +39 -0
- package/lib/node/schema/types/generic/EnumType.js +98 -0
- package/lib/{schema → node/schema}/types/generic/ObjectType.d.ts +9 -7
- package/lib/{schema → node/schema}/types/generic/ObjectType.js +11 -3
- package/lib/{schema → node/schema}/types/primitives/BooleanType.d.ts +5 -3
- package/lib/{schema → node/schema}/types/primitives/BooleanType.js +1 -0
- package/lib/{schema → node/schema}/types/primitives/DateType.d.ts +6 -4
- package/lib/{schema → node/schema}/types/primitives/DateType.js +2 -1
- package/lib/{schema → node/schema}/types/primitives/FloatType.d.ts +6 -4
- package/lib/{schema → node/schema}/types/primitives/FloatType.js +2 -1
- package/lib/{schema → node/schema}/types/primitives/IntegerType.d.ts +6 -4
- package/lib/{schema → node/schema}/types/primitives/IntegerType.js +2 -1
- package/lib/{schema → node/schema}/types/primitives/NumericType.d.ts +2 -2
- package/lib/node/schema/types/primitives/PrimitiveType.d.ts +6 -0
- package/lib/{schema → node/schema}/types/primitives/StringType.d.ts +6 -4
- package/lib/{schema → node/schema}/types/primitives/StringType.js +2 -1
- package/lib/{schema → node/schema}/types/references/IncludeIdentifierType.d.ts +11 -8
- package/lib/{schema → node/schema}/types/references/IncludeIdentifierType.js +15 -2
- package/lib/{schema → node/schema}/types/references/NestedEntityMapType.d.ts +11 -9
- package/lib/{schema → node/schema}/types/references/NestedEntityMapType.js +6 -2
- package/lib/{schema → node/schema}/types/references/ReferenceIdentifierType.d.ts +8 -6
- package/lib/{schema → node/schema}/types/references/ReferenceIdentifierType.js +1 -0
- package/lib/node/schema/types/references/TypeArgumentType.d.ts +23 -0
- package/lib/node/schema/types/references/TypeArgumentType.js +19 -0
- package/lib/node/schema/validation/type.d.ts +4 -0
- package/lib/node/server/api/declarations.d.ts +1 -0
- package/lib/node/server/api/declarations.js +154 -0
- package/lib/node/server/api/git.d.ts +1 -0
- package/lib/node/server/api/git.js +178 -0
- package/lib/node/server/api/index.d.ts +1 -0
- package/lib/node/server/api/index.js +8 -0
- package/lib/node/server/api/instanceOperations.d.ts +6 -0
- package/lib/node/server/api/instanceOperations.js +91 -0
- package/lib/node/server/api/instances.d.ts +1 -0
- package/lib/node/server/api/instances.js +27 -0
- package/lib/node/server/index.d.ts +28 -0
- package/lib/node/server/index.js +53 -0
- package/lib/node/server/init.d.ts +5 -0
- package/lib/node/server/init.js +56 -0
- package/lib/{utils → node/utils}/error.js +4 -1
- package/lib/node/utils/git.d.ts +3 -0
- package/lib/node/utils/git.js +12 -0
- package/lib/node/utils/instances.d.ts +5 -0
- package/lib/node/utils/instances.js +21 -0
- package/lib/node/utils/path.d.ts +1 -0
- package/lib/node/utils/path.js +2 -0
- package/lib/node/utils/references.d.ts +7 -0
- package/lib/node/utils/references.js +40 -0
- package/lib/node/utils/render.d.ts +9 -0
- package/lib/node/utils/render.js +34 -0
- package/lib/shared/api.d.ts +19 -2
- package/lib/shared/utils/array.d.ts +19 -0
- package/lib/shared/utils/array.js +30 -0
- package/lib/shared/utils/displayName.d.ts +1 -1
- package/lib/shared/utils/displayName.js +4 -2
- package/lib/shared/utils/git.d.ts +12 -0
- package/lib/shared/utils/git.js +98 -0
- package/lib/shared/utils/instances.d.ts +10 -0
- package/lib/shared/utils/instances.js +8 -1
- package/lib/{utils → shared/utils}/lazy.js +1 -1
- package/lib/shared/utils/markdown.d.ts +14 -0
- package/lib/shared/utils/markdown.js +42 -0
- package/lib/shared/utils/object.d.ts +4 -0
- package/lib/shared/utils/object.js +5 -0
- package/lib/{utils → shared/utils}/result.js +2 -2
- package/lib/shared/utils/string.d.ts +1 -0
- package/lib/shared/utils/string.js +16 -4
- package/lib/shared/utils/validation.js +3 -2
- package/lib/shared/validation/number.js +3 -3
- package/lib/shared/validation/object.js +4 -3
- package/lib/shared/validation/string.js +12 -7
- package/lib/web/api.d.ts +24 -0
- package/lib/web/api.js +204 -0
- package/lib/web/components/Git.d.ts +2 -0
- package/lib/web/components/Git.js +160 -0
- package/lib/{client → web}/components/Layout.d.ts +1 -1
- package/lib/{client → web}/components/Layout.js +2 -1
- package/lib/web/components/Select.d.ts +3 -0
- package/lib/web/components/Select.js +5 -0
- package/lib/web/components/typeInputs/ArrayTypeInput.d.ts +13 -0
- package/lib/{client → web}/components/typeInputs/ArrayTypeInput.js +8 -1
- package/lib/{client → web}/components/typeInputs/BooleanTypeInput.d.ts +2 -2
- package/lib/{client → web}/components/typeInputs/DateTypeInput.d.ts +2 -2
- package/lib/web/components/typeInputs/EnumTypeInput.d.ts +13 -0
- package/lib/{client/components/typeInputs/utils/EnumDeclField.js → web/components/typeInputs/EnumTypeInput.js} +11 -11
- package/lib/{client → web}/components/typeInputs/FloatTypeInput.d.ts +2 -2
- package/lib/web/components/typeInputs/GenericTypeArgumentIdentifierTypeInput.d.ts +7 -0
- package/lib/{client → web}/components/typeInputs/GenericTypeArgumentIdentifierTypeInput.js +1 -1
- package/lib/web/components/typeInputs/IncludeIdentifierTypeInput.d.ts +13 -0
- package/lib/web/components/typeInputs/IncludeIdentifierTypeInput.js +9 -0
- package/lib/{client → web}/components/typeInputs/IntegerTypeInput.d.ts +2 -2
- package/lib/web/components/typeInputs/NestedEntityMapTypeInput.d.ts +13 -0
- package/lib/{client → web}/components/typeInputs/NestedEntityMapTypeInput.js +7 -2
- package/lib/{client → web}/components/typeInputs/ObjectTypeInput.d.ts +4 -4
- package/lib/{client → web}/components/typeInputs/ObjectTypeInput.js +4 -1
- package/lib/{client → web}/components/typeInputs/ReferenceIdentifierTypeInput.d.ts +3 -3
- package/lib/web/components/typeInputs/ReferenceIdentifierTypeInput.js +11 -0
- package/lib/{client → web}/components/typeInputs/StringTypeInput.d.ts +2 -2
- package/lib/web/components/typeInputs/TypeInput.d.ts +13 -0
- package/lib/{client → web}/components/typeInputs/TypeInput.js +6 -3
- package/lib/{client → web}/components/typeInputs/utils/Markdown.d.ts +1 -1
- package/lib/web/components/typeInputs/utils/Markdown.js +26 -0
- package/lib/{client → web}/components/typeInputs/utils/MismatchingTypeError.d.ts +1 -1
- package/lib/{client → web}/components/typeInputs/utils/ValidationErrors.d.ts +1 -1
- package/lib/web/hooks/useAPIResource.d.ts +1 -0
- package/lib/web/hooks/useAPIResource.js +2 -0
- package/lib/{client → web}/hooks/useEntityFromRoute.d.ts +1 -1
- package/lib/{client → web}/hooks/useEntityFromRoute.js +1 -1
- package/lib/{client → web}/hooks/useInstanceNamesByEntity.d.ts +1 -1
- package/lib/{client → web}/hooks/useInstanceNamesByEntity.js +8 -6
- package/lib/web/hooks/useMappedAPIResource.d.ts +1 -0
- package/lib/web/hooks/useMappedAPIResource.js +17 -0
- package/lib/{client → web}/hooks/useSecondaryDeclarations.d.ts +1 -1
- package/lib/{client → web}/hooks/useSecondaryDeclarations.js +4 -2
- package/lib/{client → web}/routes/CreateInstance.d.ts +1 -1
- package/lib/{client → web}/routes/CreateInstance.js +4 -2
- package/lib/web/routes/Entity.d.ts +2 -0
- package/lib/web/routes/Entity.js +43 -0
- package/lib/web/routes/Home.d.ts +2 -0
- package/lib/web/routes/Home.js +9 -0
- package/lib/{client → web}/routes/Instance.d.ts +1 -1
- package/lib/{client → web}/routes/Instance.js +14 -8
- package/lib/{client → web}/routes/NotFound.d.ts +1 -1
- package/lib/web/utils/typeSkeleton.d.ts +3 -0
- package/lib/{client → web}/utils/typeSkeleton.js +14 -17
- package/package.json +35 -15
- package/public/css/styles.css +200 -1
- package/lib/ModelContainer.d.ts +0 -17
- package/lib/ModelContainer.js +0 -63
- package/lib/client/api.d.ts +0 -11
- package/lib/client/api.js +0 -83
- package/lib/client/components/Select.d.ts +0 -3
- package/lib/client/components/Select.js +0 -2
- package/lib/client/components/typeInputs/ArrayTypeInput.d.ts +0 -13
- package/lib/client/components/typeInputs/GenericTypeArgumentIdentifierTypeInput.d.ts +0 -7
- package/lib/client/components/typeInputs/IncludeIdentifierTypeInput.d.ts +0 -13
- package/lib/client/components/typeInputs/IncludeIdentifierTypeInput.js +0 -18
- package/lib/client/components/typeInputs/NestedEntityMapTypeInput.d.ts +0 -13
- package/lib/client/components/typeInputs/ReferenceIdentifierTypeInput.js +0 -9
- package/lib/client/components/typeInputs/TypeInput.d.ts +0 -13
- package/lib/client/components/typeInputs/utils/EnumDeclField.d.ts +0 -13
- package/lib/client/components/typeInputs/utils/Markdown.js +0 -57
- package/lib/client/routes/Entity.d.ts +0 -2
- package/lib/client/routes/Entity.js +0 -47
- package/lib/client/routes/Home.d.ts +0 -2
- package/lib/client/routes/Home.js +0 -18
- package/lib/client/utils/typeSkeleton.d.ts +0 -3
- package/lib/renderers/jsonschema/index.d.ts +0 -6
- package/lib/renderers/jsonschema/index.js +0 -12
- package/lib/renderers/jsonschema/render.d.ts +0 -5
- package/lib/renderers/ts/index.d.ts +0 -6
- package/lib/renderers/ts/index.js +0 -11
- package/lib/renderers/ts/render.js +0 -112
- package/lib/schema/declarations/EnumDecl.js +0 -115
- package/lib/schema/types/Type.d.ts +0 -42
- package/lib/schema/types/primitives/PrimitiveType.d.ts +0 -6
- package/lib/schema/types/references/GenericArgumentIdentifierType.d.ts +0 -21
- package/lib/schema/types/references/GenericArgumentIdentifierType.js +0 -18
- package/lib/schema/validation/type.d.ts +0 -4
- package/lib/server/index.d.ts +0 -8
- package/lib/server/index.js +0 -207
- package/lib/server/instanceOperations.d.ts +0 -7
- package/lib/server/instanceOperations.js +0 -67
- package/lib/tsconfig.tsbuildinfo +0 -1
- package/lib/utils/instances.d.ts +0 -4
- package/lib/utils/instances.js +0 -12
- package/lib/utils/object.d.ts +0 -3
- package/lib/utils/object.js +0 -1
- package/lib/utils/render.d.ts +0 -4
- package/lib/utils/render.js +0 -8
- /package/lib/{renderers → node/renderers}/Output.js +0 -0
- /package/lib/{schema → node/schema}/types/primitives/NumericType.js +0 -0
- /package/lib/{schema → node/schema}/types/primitives/PrimitiveType.js +0 -0
- /package/lib/{schema → node/schema}/validation/options.d.ts +0 -0
- /package/lib/{schema → node/schema}/validation/options.js +0 -0
- /package/lib/{schema → node/schema}/validation/type.js +0 -0
- /package/lib/{utils → node/utils}/error.d.ts +0 -0
- /package/lib/{utils → shared/utils}/enum.d.ts +0 -0
- /package/lib/{utils → shared/utils}/enum.js +0 -0
- /package/lib/{utils → shared/utils}/lazy.d.ts +0 -0
- /package/lib/{utils → shared/utils}/result.d.ts +0 -0
- /package/lib/{client → web}/components/typeInputs/BooleanTypeInput.js +0 -0
- /package/lib/{client → web}/components/typeInputs/DateTypeInput.js +0 -0
- /package/lib/{client → web}/components/typeInputs/FloatTypeInput.js +0 -0
- /package/lib/{client → web}/components/typeInputs/IntegerTypeInput.js +0 -0
- /package/lib/{client → web}/components/typeInputs/StringTypeInput.js +0 -0
- /package/lib/{client → web}/components/typeInputs/utils/MismatchingTypeError.js +0 -0
- /package/lib/{client → web}/components/typeInputs/utils/ValidationErrors.js +0 -0
- /package/lib/{client → web}/index.d.ts +0 -0
- /package/lib/{client → web}/index.js +0 -0
- /package/lib/{client → web}/routes/NotFound.js +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { FunctionComponent } from "preact";
|
|
2
|
-
import { SerializedReferenceIdentifierType } from "../../../schema/types/references/ReferenceIdentifierType.js";
|
|
3
|
-
import { InstanceNamesByEntity } from "../../hooks/useInstanceNamesByEntity.js";
|
|
1
|
+
import type { FunctionComponent } from "preact";
|
|
2
|
+
import type { SerializedReferenceIdentifierType } from "../../../node/schema/types/references/ReferenceIdentifierType.js";
|
|
3
|
+
import type { InstanceNamesByEntity } from "../../hooks/useInstanceNamesByEntity.js";
|
|
4
4
|
type Props = {
|
|
5
5
|
type: SerializedReferenceIdentifierType;
|
|
6
6
|
value: string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
import { Select } from "../Select.js";
|
|
3
|
+
import { ValidationErrors } from "./utils/ValidationErrors.js";
|
|
4
|
+
export const ReferenceIdentifierTypeInput = ({ type, value, instanceNamesByEntity, onChange, }) => {
|
|
5
|
+
const instances = (instanceNamesByEntity[type.entity] ?? [])
|
|
6
|
+
.slice()
|
|
7
|
+
.sort((a, b) => a.name.localeCompare(b.name));
|
|
8
|
+
return (_jsxs("div", { class: "field", children: [_jsxs(Select, { value: value, onInput: event => {
|
|
9
|
+
onChange(event.currentTarget.value);
|
|
10
|
+
}, disabled: instances.length === 0, "aria-invalid": !value, children: [instances.length === 0 ? (_jsx("option", { value: "", disabled: true, children: "No instances available" })) : (_jsx("option", { value: "", disabled: true, children: "No selected instance" })), instances.map(instance => (_jsx("option", { value: instance.id, children: instance.name }, instance.id)))] }), _jsx(ValidationErrors, { errors: !value ? [ReferenceError("no reference provided")] : [] })] }));
|
|
11
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FunctionComponent } from "preact";
|
|
2
|
-
import { SerializedStringType } from "../../../schema/types/primitives/StringType.js";
|
|
1
|
+
import type { FunctionComponent } from "preact";
|
|
2
|
+
import type { SerializedStringType } from "../../../node/schema/types/primitives/StringType.js";
|
|
3
3
|
type Props = {
|
|
4
4
|
type: SerializedStringType;
|
|
5
5
|
value: string;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { FunctionComponent } from "preact";
|
|
2
|
+
import type { SerializedType } from "../../../node/schema/types/Type.js";
|
|
3
|
+
import type { InstanceNamesByEntity } from "../../hooks/useInstanceNamesByEntity.js";
|
|
4
|
+
import type { GetDeclFromDeclName } from "../../hooks/useSecondaryDeclarations.js";
|
|
5
|
+
type Props = {
|
|
6
|
+
type: SerializedType;
|
|
7
|
+
value: unknown;
|
|
8
|
+
instanceNamesByEntity: InstanceNamesByEntity;
|
|
9
|
+
getDeclFromDeclName: GetDeclFromDeclName;
|
|
10
|
+
onChange: (value: unknown) => void;
|
|
11
|
+
};
|
|
12
|
+
export declare const TypeInput: FunctionComponent<Props>;
|
|
13
|
+
export {};
|
|
@@ -3,8 +3,9 @@ import { assertExhaustive } from "../../../shared/utils/typeSafety.js";
|
|
|
3
3
|
import { ArrayTypeInput } from "./ArrayTypeInput.js";
|
|
4
4
|
import { BooleanTypeInput } from "./BooleanTypeInput.js";
|
|
5
5
|
import { DateTypeInput } from "./DateTypeInput.js";
|
|
6
|
+
import { EnumTypeInput } from "./EnumTypeInput.js";
|
|
6
7
|
import { FloatTypeInput } from "./FloatTypeInput.js";
|
|
7
|
-
import {
|
|
8
|
+
import { TypeArgumentTypeInput } from "./GenericTypeArgumentIdentifierTypeInput.js";
|
|
8
9
|
import { IncludeIdentifierTypeInput } from "./IncludeIdentifierTypeInput.js";
|
|
9
10
|
import { IntegerTypeInput } from "./IntegerTypeInput.js";
|
|
10
11
|
import { NestedEntityMapTypeInput } from "./NestedEntityMapTypeInput.js";
|
|
@@ -63,8 +64,8 @@ export const TypeInput = ({ type, value, instanceNamesByEntity, getDeclFromDeclN
|
|
|
63
64
|
else {
|
|
64
65
|
return _jsx(MismatchingTypeError, { expected: "object", actual: value });
|
|
65
66
|
}
|
|
66
|
-
case "
|
|
67
|
-
return _jsx(
|
|
67
|
+
case "TypeArgumentType":
|
|
68
|
+
return _jsx(TypeArgumentTypeInput, { type: type });
|
|
68
69
|
case "ReferenceIdentifierType":
|
|
69
70
|
if (typeof value === "string") {
|
|
70
71
|
return (_jsx(ReferenceIdentifierTypeInput, { type: type, value: value, instanceNamesByEntity: instanceNamesByEntity, onChange: onChange }));
|
|
@@ -81,6 +82,8 @@ export const TypeInput = ({ type, value, instanceNamesByEntity, getDeclFromDeclN
|
|
|
81
82
|
else {
|
|
82
83
|
return _jsx(MismatchingTypeError, { expected: "entity map", actual: value });
|
|
83
84
|
}
|
|
85
|
+
case "EnumType":
|
|
86
|
+
return (_jsx(EnumTypeInput, { type: type, value: value, instanceNamesByEntity: instanceNamesByEntity, getDeclFromDeclName: getDeclFromDeclName, onChange: onChange }));
|
|
84
87
|
default:
|
|
85
88
|
return assertExhaustive(type);
|
|
86
89
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { jsx as _jsx } from "preact/jsx-runtime";
|
|
2
|
+
import { parseBlockMarkdown } from "../../../../shared/utils/markdown.js";
|
|
3
|
+
export const Markdown = ({ string }) => {
|
|
4
|
+
const blocks = parseBlockMarkdown(string);
|
|
5
|
+
return blocks.map((block, i) => _jsx(BlockMarkdown, { node: block }, `md-block-${i.toString()}`));
|
|
6
|
+
};
|
|
7
|
+
const BlockMarkdown = ({ node }) => {
|
|
8
|
+
switch (node.kind) {
|
|
9
|
+
case "paragraph":
|
|
10
|
+
return (_jsx("p", { children: node.content.map((inline, ii) => (_jsx(InlineMarkdown, { node: inline }, ii))) }));
|
|
11
|
+
case "text":
|
|
12
|
+
return node.content;
|
|
13
|
+
default:
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
const InlineMarkdown = ({ node }) => {
|
|
18
|
+
switch (node.kind) {
|
|
19
|
+
case "bold":
|
|
20
|
+
return (_jsx("strong", { children: node.content.map((inline, i) => (_jsx(InlineMarkdown, { node: inline }, i))) }));
|
|
21
|
+
case "italic":
|
|
22
|
+
return (_jsx("em", { children: node.content.map((inline, i) => (_jsx(InlineMarkdown, { node: inline }, i))) }));
|
|
23
|
+
case "text":
|
|
24
|
+
return node.content;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useAPIResource: <T, A extends unknown[]>(apiFn: (...args: A) => Promise<T>, ...args: A) => [T | undefined, () => Promise<void>];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SerializedEntityDecl } from "../../schema/declarations/EntityDecl.js";
|
|
1
|
+
import type { SerializedEntityDecl } from "../../node/schema/declarations/EntityDecl.js";
|
|
2
2
|
export declare const useEntityFromRoute: () => {
|
|
3
3
|
entity: SerializedEntityDecl;
|
|
4
4
|
isLocaleEntity: boolean;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { GetAllInstancesResponseBody } from "../../shared/api.js";
|
|
1
|
+
import type { GetAllInstancesResponseBody } from "../../shared/api.js";
|
|
2
2
|
export type InstanceNamesByEntity = GetAllInstancesResponseBody["instances"];
|
|
3
3
|
export declare const useInstanceNamesByEntity: (locales?: string[]) => [InstanceNamesByEntity, () => void];
|
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
import { useEffect, useState } from "preact/hooks";
|
|
1
|
+
import { useCallback, useEffect, useState } from "preact/hooks";
|
|
2
2
|
import { getAllInstances } from "../api.js";
|
|
3
3
|
export const useInstanceNamesByEntity = (locales = []) => {
|
|
4
4
|
const [instanceNamesByEntity, setInstanceNamesByEntity] = useState({});
|
|
5
|
-
const updateInstanceNamesByEntity = () => {
|
|
5
|
+
const updateInstanceNamesByEntity = useCallback(() => {
|
|
6
6
|
getAllInstances(locales)
|
|
7
7
|
.then(data => {
|
|
8
8
|
setInstanceNamesByEntity(data.instances);
|
|
9
9
|
})
|
|
10
|
-
.catch(error => {
|
|
11
|
-
|
|
10
|
+
.catch((error) => {
|
|
11
|
+
if (error instanceof Error) {
|
|
12
|
+
console.error("Error fetching data:", error.toString());
|
|
13
|
+
}
|
|
12
14
|
});
|
|
13
|
-
};
|
|
15
|
+
}, [locales]);
|
|
14
16
|
useEffect(() => {
|
|
15
17
|
updateInstanceNamesByEntity();
|
|
16
|
-
}, []);
|
|
18
|
+
}, [updateInstanceNamesByEntity]);
|
|
17
19
|
return [instanceNamesByEntity, updateInstanceNamesByEntity];
|
|
18
20
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useMappedAPIResource: <T, A extends unknown[], U>(apiFn: (...args: A) => Promise<T>, mapFn: (data: T) => U, ...args: A) => [U | undefined, () => Promise<void>];
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useCallback, useEffect, useState } from "preact/hooks";
|
|
2
|
+
export const useMappedAPIResource = (apiFn, mapFn, ...args) => {
|
|
3
|
+
const [data, setData] = useState();
|
|
4
|
+
const fetchData = useCallback(() => apiFn(...args).then(result => {
|
|
5
|
+
setData(mapFn(result));
|
|
6
|
+
}), [apiFn, args, mapFn]);
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
fetchData().catch((err) => {
|
|
9
|
+
console.log(err);
|
|
10
|
+
});
|
|
11
|
+
}, [fetchData]);
|
|
12
|
+
const reload = useCallback(() => {
|
|
13
|
+
setData(undefined);
|
|
14
|
+
return fetchData();
|
|
15
|
+
}, [fetchData]);
|
|
16
|
+
return [data, reload];
|
|
17
|
+
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { SerializedSecondaryDecl } from "../../schema/declarations/Declaration.js";
|
|
1
|
+
import type { SerializedSecondaryDecl } from "../../node/schema/declarations/Declaration.js";
|
|
2
2
|
export type GetDeclFromDeclName = (name: string) => SerializedSecondaryDecl | undefined;
|
|
3
3
|
export declare const useGetDeclFromDeclName: () => GetDeclFromDeclName;
|
|
@@ -9,8 +9,10 @@ export const useGetDeclFromDeclName = () => {
|
|
|
9
9
|
.map(decl => decl.declaration)
|
|
10
10
|
.filter((decl) => decl.kind === "EnumDecl" || decl.kind === "TypeAliasDecl"));
|
|
11
11
|
})
|
|
12
|
-
.catch(error => {
|
|
13
|
-
|
|
12
|
+
.catch((error) => {
|
|
13
|
+
if (error instanceof Error) {
|
|
14
|
+
console.error("Error fetching data:", error.toString());
|
|
15
|
+
}
|
|
14
16
|
});
|
|
15
17
|
}, []);
|
|
16
18
|
const getDeclFromDeclName = useCallback((name) => secondaryDeclarations.find(decl => decl.name === name), [secondaryDeclarations]);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { FunctionalComponent } from "preact";
|
|
1
|
+
import type { FunctionalComponent } from "preact";
|
|
2
2
|
export declare const CreateInstance: FunctionalComponent;
|
|
@@ -48,8 +48,10 @@ export const CreateInstance = () => {
|
|
|
48
48
|
route(`/entities/${entity.name}?created=${encodeURIComponent(createdInstance.instance.id)}`);
|
|
49
49
|
}
|
|
50
50
|
})
|
|
51
|
-
.catch(error => {
|
|
52
|
-
|
|
51
|
+
.catch((error) => {
|
|
52
|
+
if (error instanceof Error) {
|
|
53
|
+
alert(`Error creating instance:\n\n${error.toString()}`);
|
|
54
|
+
}
|
|
53
55
|
});
|
|
54
56
|
}
|
|
55
57
|
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
import { useRoute } from "preact-iso";
|
|
3
|
+
import { useEffect } from "preact/hooks";
|
|
4
|
+
import { getDisplayNameFromEntityInstance } from "../../shared/utils/displayName.js";
|
|
5
|
+
import { getGitStatusForDisplay, getLabelForGitStatus } from "../../shared/utils/git.js";
|
|
6
|
+
import { deleteInstanceByEntityNameAndId, getEntityByName, getInstancesByEntityName, } from "../api.js";
|
|
7
|
+
import { Layout } from "../components/Layout.js";
|
|
8
|
+
import { useAPIResource } from "../hooks/useAPIResource.js";
|
|
9
|
+
import { useMappedAPIResource } from "../hooks/useMappedAPIResource.js";
|
|
10
|
+
import { NotFound } from "./NotFound.js";
|
|
11
|
+
export const Entity = () => {
|
|
12
|
+
const { params: { name }, query: { created }, } = useRoute();
|
|
13
|
+
const [entity] = useAPIResource(getEntityByName, name ?? "");
|
|
14
|
+
const [instances, reloadInstances] = useMappedAPIResource(getInstancesByEntityName, data => data.instances, name ?? "");
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
if (created) {
|
|
17
|
+
const instanceElement = document.getElementById(`instance-${created}`);
|
|
18
|
+
if (instanceElement) {
|
|
19
|
+
instanceElement.scrollIntoView({ behavior: "smooth", block: "center" });
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}, [created]);
|
|
23
|
+
if (!name) {
|
|
24
|
+
return _jsx(NotFound, {});
|
|
25
|
+
}
|
|
26
|
+
if (!entity || !instances) {
|
|
27
|
+
return (_jsxs("div", { children: [_jsx("h1", { children: name }), _jsx("p", { className: "loading", children: "Loading \u2026" })] }));
|
|
28
|
+
}
|
|
29
|
+
return (_jsxs(Layout, { breadcrumbs: [{ url: "/", label: "Home" }], children: [_jsxs("div", { class: "header-with-btns", children: [_jsx("h1", { children: name }), _jsx("a", { class: "btn btn--primary", href: `/entities/${entity.declaration.name}/instances/create`, children: "Add" })] }), entity.declaration.comment && _jsx("p", { className: "description", children: entity.declaration.comment }), _jsxs("p", { children: [instances.length, " instance", instances.length === 1 ? "" : "s"] }), _jsx("ul", { class: "instances", children: instances.map(instance => {
|
|
30
|
+
const gitStatusForDisplay = getGitStatusForDisplay(instance.gitStatus);
|
|
31
|
+
return (_jsxs("li", { id: `instance-${instance.id}`, class: `instance-item ${created === instance.id ? "instance-item--created" : ""} ${gitStatusForDisplay === undefined ? "" : `git-status--${gitStatusForDisplay}`}`, children: [_jsx("h2", { children: getDisplayNameFromEntityInstance(entity.declaration, instance.content, instance.id) }), _jsx("p", { "aria-hidden": true, class: "id", children: instance.id }), gitStatusForDisplay !== undefined && (_jsx("p", { class: `git-status git-status--${gitStatusForDisplay}`, title: getLabelForGitStatus(gitStatusForDisplay), children: gitStatusForDisplay })), _jsxs("div", { className: "btns", children: [_jsx("a", { href: `/entities/${entity.declaration.name}/instances/${instance.id}`, class: "btn", children: "Edit" }), _jsx("button", { class: "destructive", onClick: () => {
|
|
32
|
+
if (confirm("Are you sure you want to delete this instance?")) {
|
|
33
|
+
deleteInstanceByEntityNameAndId(entity.declaration.name, instance.id)
|
|
34
|
+
.then(() => reloadInstances())
|
|
35
|
+
.catch((error) => {
|
|
36
|
+
if (error instanceof Error) {
|
|
37
|
+
alert("Error deleting instance:\n\n" + error.toString());
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}, children: "Delete" })] })] }, instance.id));
|
|
42
|
+
}) })] }));
|
|
43
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
import { toTitleCase } from "../../shared/utils/string.js";
|
|
3
|
+
import { getAllEntities } from "../api.js";
|
|
4
|
+
import { Layout } from "../components/Layout.js";
|
|
5
|
+
import { useMappedAPIResource } from "../hooks/useMappedAPIResource.js";
|
|
6
|
+
export const Home = () => {
|
|
7
|
+
const [entities] = useMappedAPIResource(getAllEntities, data => data.declarations.sort((a, b) => a.declaration.name.localeCompare(b.declaration.name)));
|
|
8
|
+
return (_jsxs(Layout, { breadcrumbs: [{ url: "/", label: "Home" }], children: [_jsx("h1", { children: "Entities" }), _jsx("ul", { class: "entities", children: (entities ?? []).map(entity => (_jsxs("li", { class: "entity-item", children: [_jsxs("div", { className: "title", children: [_jsx("h2", { children: toTitleCase(entity.declaration.name) }), entity.declaration.comment && _jsx("p", { children: entity.declaration.comment })] }), _jsxs("p", { class: "meta", children: [entity.instanceCount, " instance", entity.instanceCount === 1 ? "" : "s"] }), _jsx("div", { className: "btns", children: _jsx("a", { href: `/entities/${entity.declaration.name}`, class: "btn", children: "View" }) })] }, entity.declaration.name))) })] }));
|
|
9
|
+
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { FunctionalComponent } from "preact";
|
|
1
|
+
import type { FunctionalComponent } from "preact";
|
|
2
2
|
export declare const Instance: FunctionalComponent;
|
|
@@ -26,22 +26,23 @@ export const Instance = () => {
|
|
|
26
26
|
setInstance(instanceData.instance);
|
|
27
27
|
setOriginalInstance(instanceData.instance);
|
|
28
28
|
})
|
|
29
|
-
.catch(error => {
|
|
29
|
+
.catch((error) => {
|
|
30
30
|
console.error("Error fetching entities:", error);
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
|
-
}, []);
|
|
33
|
+
}, [id, name]);
|
|
34
34
|
const handleSubmit = (event) => {
|
|
35
35
|
event.preventDefault();
|
|
36
36
|
if (name && id && instance) {
|
|
37
37
|
updateInstanceByEntityNameAndId(name, id, instance.content)
|
|
38
38
|
.then(updatedInstance => {
|
|
39
|
-
0;
|
|
40
39
|
setInstance(updatedInstance.instance);
|
|
41
40
|
setOriginalInstance(updatedInstance.instance);
|
|
42
41
|
})
|
|
43
|
-
.catch(error => {
|
|
44
|
-
|
|
42
|
+
.catch((error) => {
|
|
43
|
+
if (error instanceof Error) {
|
|
44
|
+
alert(`Error updating instance:\n\n${error}`);
|
|
45
|
+
}
|
|
45
46
|
});
|
|
46
47
|
}
|
|
47
48
|
};
|
|
@@ -65,9 +66,14 @@ export const Instance = () => {
|
|
|
65
66
|
.then(() => {
|
|
66
67
|
route(`/entities/${name}`);
|
|
67
68
|
})
|
|
68
|
-
.catch(error => {
|
|
69
|
-
|
|
69
|
+
.catch((error) => {
|
|
70
|
+
if (error instanceof Error) {
|
|
71
|
+
alert("Error deleting instance:\n\n" + error.toString());
|
|
72
|
+
}
|
|
70
73
|
});
|
|
71
74
|
}
|
|
72
|
-
}, children: "Delete" })] }), _jsxs("form", { onSubmit: handleSubmit, children: [_jsx(TypeInput, { type: entityFromRoute.entity.type, value: instance.content, instanceNamesByEntity: instanceNamesByEntity, getDeclFromDeclName: getDeclFromDeclName, onChange: value =>
|
|
75
|
+
}, children: "Delete" })] }), _jsxs("form", { onSubmit: handleSubmit, children: [_jsx(TypeInput, { type: entityFromRoute.entity.type, value: instance.content, instanceNamesByEntity: instanceNamesByEntity, getDeclFromDeclName: getDeclFromDeclName, onChange: value => {
|
|
76
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
77
|
+
setInstance(container => ({ ...container, content: value }));
|
|
78
|
+
} }), _jsx("button", { type: "submit", disabled: !hasChanges, class: "primary", children: "Save" })] })] }));
|
|
73
79
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { FunctionalComponent } from "preact";
|
|
1
|
+
import type { FunctionalComponent } from "preact";
|
|
2
2
|
export declare const NotFound: FunctionalComponent;
|
|
@@ -17,7 +17,7 @@ export const createTypeSkeleton = (getDeclFromDeclName, type) => {
|
|
|
17
17
|
return Object.fromEntries(Object.entries(type.properties).flatMap(([key, memberDecl]) => memberDecl.isRequired
|
|
18
18
|
? [[key, createTypeSkeleton(getDeclFromDeclName, memberDecl.type)]]
|
|
19
19
|
: []));
|
|
20
|
-
case "
|
|
20
|
+
case "TypeArgumentType":
|
|
21
21
|
return undefined;
|
|
22
22
|
case "ReferenceIdentifierType":
|
|
23
23
|
return "";
|
|
@@ -26,25 +26,22 @@ export const createTypeSkeleton = (getDeclFromDeclName, type) => {
|
|
|
26
26
|
if (referencedDecl === undefined) {
|
|
27
27
|
return undefined;
|
|
28
28
|
}
|
|
29
|
-
|
|
30
|
-
case "TypeAliasDecl":
|
|
31
|
-
return createTypeSkeleton(getDeclFromDeclName, referencedDecl.type);
|
|
32
|
-
case "EnumDecl": {
|
|
33
|
-
const firstCase = Object.entries(referencedDecl.values)[0];
|
|
34
|
-
if (firstCase[1].type === null) {
|
|
35
|
-
return { kind: firstCase[0] };
|
|
36
|
-
}
|
|
37
|
-
return {
|
|
38
|
-
kind: firstCase[0],
|
|
39
|
-
[firstCase[0]]: createTypeSkeleton(getDeclFromDeclName, firstCase[1].type),
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
default:
|
|
43
|
-
return assertExhaustive(referencedDecl);
|
|
44
|
-
}
|
|
29
|
+
return createTypeSkeleton(getDeclFromDeclName, referencedDecl.type);
|
|
45
30
|
}
|
|
46
31
|
case "NestedEntityMapType":
|
|
47
32
|
return {};
|
|
33
|
+
case "EnumType": {
|
|
34
|
+
const firstCase = Object.entries(type.values)[0];
|
|
35
|
+
if (firstCase === undefined) {
|
|
36
|
+
return {};
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
kind: firstCase[0],
|
|
40
|
+
...(firstCase[1].type === null
|
|
41
|
+
? {}
|
|
42
|
+
: { [firstCase[0]]: createTypeSkeleton(getDeclFromDeclName, firstCase[1].type) }),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
48
45
|
default:
|
|
49
46
|
return assertExhaustive(type);
|
|
50
47
|
}
|
package/package.json
CHANGED
|
@@ -1,45 +1,65 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tsondb",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "Lukas Obermann",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"files": [
|
|
9
|
-
"lib",
|
|
9
|
+
"lib/**/*.d.ts",
|
|
10
|
+
"lib/**/*.js",
|
|
10
11
|
"public"
|
|
11
12
|
],
|
|
13
|
+
"bin": {
|
|
14
|
+
"tsondb": "lib/bin/tsondb.js"
|
|
15
|
+
},
|
|
12
16
|
"main": "lib/index.js",
|
|
13
17
|
"exports": {
|
|
14
18
|
".": "./lib/index.js",
|
|
15
|
-
"./renderer/jsonschema": "./lib/renderers/jsonschema/index.js",
|
|
16
|
-
"./renderer/ts": "./lib/renderers/ts/index.js",
|
|
17
|
-
"./
|
|
18
|
-
"./schema": "./lib/
|
|
19
|
-
"./schema/def": "./lib/schema/index.js"
|
|
19
|
+
"./renderer/jsonschema": "./lib/node/renderers/jsonschema/index.js",
|
|
20
|
+
"./renderer/ts": "./lib/node/renderers/ts/index.js",
|
|
21
|
+
"./schema": "./lib/node/Schema.js",
|
|
22
|
+
"./schema/def": "./lib/node/schema/index.js"
|
|
20
23
|
},
|
|
21
24
|
"scripts": {
|
|
22
25
|
"build": "tsc -b",
|
|
23
26
|
"watch": "tsc -b -w",
|
|
24
|
-
"test": "
|
|
27
|
+
"test": "node --import tsx --test",
|
|
28
|
+
"lint": "eslint",
|
|
29
|
+
"check-format": "prettier \"{src,test}/**/*.{ts,tsx}\" --check",
|
|
30
|
+
"format": "prettier \"{src,test}/**/*.{ts,tsx}\" --write",
|
|
25
31
|
"release": "commit-and-tag-version"
|
|
26
32
|
},
|
|
27
33
|
"devDependencies": {
|
|
28
|
-
"@
|
|
29
|
-
"@types/
|
|
34
|
+
"@eslint/js": "^9.30.1",
|
|
35
|
+
"@types/debug": "^4.1.12",
|
|
36
|
+
"@types/express": "^5.0.3",
|
|
37
|
+
"@types/node": "^24.0.12",
|
|
30
38
|
"commit-and-tag-version": "^12.5.1",
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
39
|
+
"eslint": "^9.30.1",
|
|
40
|
+
"eslint-plugin-react": "^7.37.5",
|
|
41
|
+
"eslint-plugin-react-hooks": "^5.2.0",
|
|
42
|
+
"globals": "^16.3.0",
|
|
43
|
+
"prettier": "^3.6.2",
|
|
44
|
+
"tsx": "^4.20.3",
|
|
45
|
+
"typescript": "^5.8.3",
|
|
46
|
+
"typescript-eslint": "^8.36.0"
|
|
34
47
|
},
|
|
35
48
|
"dependencies": {
|
|
49
|
+
"debug": "^4.4.1",
|
|
36
50
|
"express": "^5.1.0",
|
|
37
|
-
"preact": "^10.26.
|
|
38
|
-
"preact-iso": "^2.9.
|
|
51
|
+
"preact": "^10.26.9",
|
|
52
|
+
"preact-iso": "^2.9.2",
|
|
53
|
+
"simple-cli-args": "^0.1.0",
|
|
54
|
+
"simple-git": "^3.28.0",
|
|
55
|
+
"supports-color": "^10.0.0",
|
|
39
56
|
"uuid": "^11.1.0"
|
|
40
57
|
},
|
|
41
58
|
"repository": "github:elyukai/tsondb",
|
|
42
59
|
"bugs": {
|
|
43
60
|
"url": "https://github.com/elyukai/tsondb/issues"
|
|
61
|
+
},
|
|
62
|
+
"engines": {
|
|
63
|
+
"node": ">=23.6.0"
|
|
44
64
|
}
|
|
45
65
|
}
|