tsondb 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/lib/ModelContainer.d.ts +17 -0
- package/lib/ModelContainer.js +63 -0
- package/lib/Schema.d.ts +8 -0
- package/lib/Schema.js +72 -0
- package/lib/client/api.d.ts +11 -0
- package/lib/client/api.js +83 -0
- package/lib/client/components/Layout.d.ts +10 -0
- package/lib/client/components/Layout.js +4 -0
- package/lib/client/components/Select.d.ts +3 -0
- package/lib/client/components/Select.js +2 -0
- package/lib/client/components/typeInputs/ArrayTypeInput.d.ts +13 -0
- package/lib/client/components/typeInputs/ArrayTypeInput.js +10 -0
- package/lib/client/components/typeInputs/BooleanTypeInput.d.ts +9 -0
- package/lib/client/components/typeInputs/BooleanTypeInput.js +6 -0
- package/lib/client/components/typeInputs/DateTypeInput.d.ts +9 -0
- package/lib/client/components/typeInputs/DateTypeInput.js +9 -0
- package/lib/client/components/typeInputs/FloatTypeInput.d.ts +9 -0
- package/lib/client/components/typeInputs/FloatTypeInput.js +15 -0
- package/lib/client/components/typeInputs/GenericTypeArgumentIdentifierTypeInput.d.ts +7 -0
- package/lib/client/components/typeInputs/GenericTypeArgumentIdentifierTypeInput.js +4 -0
- package/lib/client/components/typeInputs/IncludeIdentifierTypeInput.d.ts +13 -0
- package/lib/client/components/typeInputs/IncludeIdentifierTypeInput.js +18 -0
- package/lib/client/components/typeInputs/IntegerTypeInput.d.ts +9 -0
- package/lib/client/components/typeInputs/IntegerTypeInput.js +15 -0
- package/lib/client/components/typeInputs/NestedEntityMapTypeInput.d.ts +13 -0
- package/lib/client/components/typeInputs/NestedEntityMapTypeInput.js +25 -0
- package/lib/client/components/typeInputs/ObjectTypeInput.d.ts +13 -0
- package/lib/client/components/typeInputs/ObjectTypeInput.js +20 -0
- package/lib/client/components/typeInputs/ReferenceIdentifierTypeInput.d.ts +11 -0
- package/lib/client/components/typeInputs/ReferenceIdentifierTypeInput.js +9 -0
- package/lib/client/components/typeInputs/StringTypeInput.d.ts +9 -0
- package/lib/client/components/typeInputs/StringTypeInput.js +10 -0
- package/lib/client/components/typeInputs/TypeInput.d.ts +13 -0
- package/lib/client/components/typeInputs/TypeInput.js +87 -0
- package/lib/client/components/typeInputs/utils/EnumDeclField.d.ts +13 -0
- package/lib/client/components/typeInputs/utils/EnumDeclField.js +38 -0
- package/lib/client/components/typeInputs/utils/MismatchingTypeError.d.ts +7 -0
- package/lib/client/components/typeInputs/utils/MismatchingTypeError.js +4 -0
- package/lib/client/components/typeInputs/utils/ValidationErrors.d.ts +6 -0
- package/lib/client/components/typeInputs/utils/ValidationErrors.js +4 -0
- package/lib/client/hooks/useEntityFromRoute.d.ts +5 -0
- package/lib/client/hooks/useEntityFromRoute.js +20 -0
- package/lib/client/hooks/useInstanceNamesByEntity.d.ts +3 -0
- package/lib/client/hooks/useInstanceNamesByEntity.js +18 -0
- package/lib/client/hooks/useSecondaryDeclarations.d.ts +3 -0
- package/lib/client/hooks/useSecondaryDeclarations.js +18 -0
- package/lib/client/index.d.ts +1 -0
- package/lib/client/index.js +11 -0
- package/lib/client/routes/CreateInstance.d.ts +2 -0
- package/lib/client/routes/CreateInstance.js +68 -0
- package/lib/client/routes/Entity.d.ts +2 -0
- package/lib/client/routes/Entity.js +47 -0
- package/lib/client/routes/Home.d.ts +2 -0
- package/lib/client/routes/Home.js +18 -0
- package/lib/client/routes/Instance.d.ts +2 -0
- package/lib/client/routes/Instance.js +73 -0
- package/lib/client/routes/NotFound.d.ts +2 -0
- package/lib/client/routes/NotFound.js +5 -0
- package/lib/client/utils/typeSkeleton.d.ts +3 -0
- package/lib/client/utils/typeSkeleton.js +51 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/renderers/Output.d.ts +4 -0
- package/lib/renderers/Output.js +1 -0
- package/lib/renderers/jsonschema/index.d.ts +6 -0
- package/lib/renderers/jsonschema/index.js +12 -0
- package/lib/renderers/jsonschema/render.d.ts +5 -0
- package/lib/renderers/jsonschema/render.js +156 -0
- package/lib/renderers/ts/index.d.ts +6 -0
- package/lib/renderers/ts/index.js +11 -0
- package/lib/renderers/ts/render.d.ts +5 -0
- package/lib/renderers/ts/render.js +109 -0
- package/lib/schema/Node.d.ts +37 -0
- package/lib/schema/Node.js +79 -0
- package/lib/schema/declarations/Declaration.d.ts +44 -0
- package/lib/schema/declarations/Declaration.js +98 -0
- package/lib/schema/declarations/EntityDecl.d.ts +73 -0
- package/lib/schema/declarations/EntityDecl.js +57 -0
- package/lib/schema/declarations/EnumDecl.d.ts +33 -0
- package/lib/schema/declarations/EnumDecl.js +104 -0
- package/lib/schema/declarations/TypeAliasDecl.d.ts +33 -0
- package/lib/schema/declarations/TypeAliasDecl.js +49 -0
- package/lib/schema/index.d.ts +20 -0
- package/lib/schema/index.js +20 -0
- package/lib/schema/parameters/TypeParameter.d.ts +14 -0
- package/lib/schema/parameters/TypeParameter.js +11 -0
- package/lib/schema/types/Type.d.ts +42 -0
- package/lib/schema/types/Type.js +177 -0
- package/lib/schema/types/generic/ArrayType.d.ts +30 -0
- package/lib/schema/types/generic/ArrayType.js +38 -0
- package/lib/schema/types/generic/ObjectType.d.ts +47 -0
- package/lib/schema/types/generic/ObjectType.js +70 -0
- package/lib/schema/types/primitives/BooleanType.d.ts +15 -0
- package/lib/schema/types/primitives/BooleanType.js +15 -0
- package/lib/schema/types/primitives/DateType.d.ts +16 -0
- package/lib/schema/types/primitives/DateType.js +17 -0
- package/lib/schema/types/primitives/FloatType.d.ts +26 -0
- package/lib/schema/types/primitives/FloatType.js +17 -0
- package/lib/schema/types/primitives/IntegerType.d.ts +26 -0
- package/lib/schema/types/primitives/IntegerType.js +21 -0
- package/lib/schema/types/primitives/NumericType.d.ts +6 -0
- package/lib/schema/types/primitives/NumericType.js +2 -0
- package/lib/schema/types/primitives/PrimitiveType.d.ts +6 -0
- package/lib/schema/types/primitives/PrimitiveType.js +1 -0
- package/lib/schema/types/primitives/StringType.d.ts +25 -0
- package/lib/schema/types/primitives/StringType.js +20 -0
- package/lib/schema/types/references/GenericArgumentIdentifierType.d.ts +21 -0
- package/lib/schema/types/references/GenericArgumentIdentifierType.js +18 -0
- package/lib/schema/types/references/IncludeIdentifierType.d.ts +28 -0
- package/lib/schema/types/references/IncludeIdentifierType.js +25 -0
- package/lib/schema/types/references/NestedEntityMapType.d.ts +36 -0
- package/lib/schema/types/references/NestedEntityMapType.js +67 -0
- package/lib/schema/types/references/ReferenceIdentifierType.d.ts +23 -0
- package/lib/schema/types/references/ReferenceIdentifierType.js +21 -0
- package/lib/schema/validation/options.d.ts +4 -0
- package/lib/schema/validation/options.js +12 -0
- package/lib/schema/validation/type.d.ts +4 -0
- package/lib/schema/validation/type.js +1 -0
- package/lib/server/index.d.ts +8 -0
- package/lib/server/index.js +207 -0
- package/lib/server/instanceOperations.d.ts +7 -0
- package/lib/server/instanceOperations.js +67 -0
- package/lib/shared/api.d.ts +42 -0
- package/lib/shared/api.js +1 -0
- package/lib/shared/enum.d.ts +1 -0
- package/lib/shared/enum.js +1 -0
- package/lib/shared/utils/compare.d.ts +13 -0
- package/lib/shared/utils/compare.js +24 -0
- package/lib/shared/utils/displayName.d.ts +2 -0
- package/lib/shared/utils/displayName.js +31 -0
- package/lib/shared/utils/instances.d.ts +6 -0
- package/lib/shared/utils/instances.js +1 -0
- package/lib/shared/utils/object.d.ts +2 -0
- package/lib/shared/utils/object.js +2 -0
- package/lib/shared/utils/string.d.ts +6 -0
- package/lib/shared/utils/string.js +52 -0
- package/lib/shared/utils/typeSafety.d.ts +1 -0
- package/lib/shared/utils/typeSafety.js +3 -0
- package/lib/shared/utils/validation.d.ts +3 -0
- package/lib/shared/utils/validation.js +14 -0
- package/lib/shared/validation/array.d.ts +6 -0
- package/lib/shared/validation/array.js +29 -0
- package/lib/shared/validation/date.d.ts +4 -0
- package/lib/shared/validation/date.js +13 -0
- package/lib/shared/validation/identifier.d.ts +1 -0
- package/lib/shared/validation/identifier.js +7 -0
- package/lib/shared/validation/number.d.ts +12 -0
- package/lib/shared/validation/number.js +34 -0
- package/lib/shared/validation/object.d.ts +6 -0
- package/lib/shared/validation/object.js +13 -0
- package/lib/shared/validation/string.d.ts +6 -0
- package/lib/shared/validation/string.js +15 -0
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/lib/utils/enum.d.ts +6 -0
- package/lib/utils/enum.js +1 -0
- package/lib/utils/error.d.ts +2 -0
- package/lib/utils/error.js +18 -0
- package/lib/utils/instances.d.ts +4 -0
- package/lib/utils/instances.js +12 -0
- package/lib/utils/lazy.d.ts +16 -0
- package/lib/utils/lazy.js +32 -0
- package/lib/utils/object.d.ts +3 -0
- package/lib/utils/object.js +1 -0
- package/lib/utils/render.d.ts +4 -0
- package/lib/utils/render.js +8 -0
- package/lib/utils/result.d.ts +57 -0
- package/lib/utils/result.js +48 -0
- package/package.json +46 -0
- package/public/css/styles.css +418 -0
package/README.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Output } from "./renderers/Output.js";
|
|
2
|
+
import { Schema } from "./Schema.js";
|
|
3
|
+
export interface ModelContainer {
|
|
4
|
+
schema: Schema;
|
|
5
|
+
outputs: Output[];
|
|
6
|
+
dataRootPath: string;
|
|
7
|
+
}
|
|
8
|
+
export declare const ModelContainer: (options: {
|
|
9
|
+
schema: Schema;
|
|
10
|
+
outputs: Output[];
|
|
11
|
+
dataRootPath: string;
|
|
12
|
+
}) => ModelContainer;
|
|
13
|
+
export declare const generateOutputs: (modelContainer: ModelContainer) => Promise<void>;
|
|
14
|
+
export declare const validate: (modelContainer: ModelContainer) => Promise<void>;
|
|
15
|
+
export declare const generateAndValidate: (modelContainer: ModelContainer) => Promise<void>;
|
|
16
|
+
export declare const serve: (modelContainer: ModelContainer) => Promise<void>;
|
|
17
|
+
export declare const generateValidateAndServe: (modelContainer: ModelContainer) => Promise<void>;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { mkdir } from "fs/promises";
|
|
2
|
+
import { join } from "path";
|
|
3
|
+
import { getEntities } from "./Schema.js";
|
|
4
|
+
import { createValidators, validateEntityDecl } from "./schema/index.js";
|
|
5
|
+
import { createServer } from "./server/index.js";
|
|
6
|
+
import { parallelizeErrors } from "./shared/utils/validation.js";
|
|
7
|
+
import { getErrorMessageForDisplay, wrapErrorsIfAny } from "./utils/error.js";
|
|
8
|
+
import { getInstancesByEntityName } from "./utils/instances.js";
|
|
9
|
+
export const ModelContainer = (options) => ({
|
|
10
|
+
...options,
|
|
11
|
+
});
|
|
12
|
+
const prepareFolders = async (modelContainer, entities) => {
|
|
13
|
+
await mkdir(modelContainer.dataRootPath, { recursive: true });
|
|
14
|
+
for (const entity of entities) {
|
|
15
|
+
const entityDir = join(modelContainer.dataRootPath, entity.name);
|
|
16
|
+
await mkdir(entityDir, { recursive: true });
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
export const generateOutputs = async (modelContainer) => {
|
|
20
|
+
for (const output of modelContainer.outputs) {
|
|
21
|
+
await output.run(modelContainer.schema);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const _validate = async (entities, instancesByEntityName) => {
|
|
25
|
+
const errors = entities.flatMap(entity => parallelizeErrors(instancesByEntityName[entity.name].map(instance => wrapErrorsIfAny(`in file "${entity.name}/${instance.fileName}"`, validateEntityDecl(createValidators(instancesByEntityName), entity, instance.content)))));
|
|
26
|
+
if (errors.length === 0) {
|
|
27
|
+
console.log("All entities are valid");
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
console.error("Errors:\n");
|
|
31
|
+
for (const error of errors) {
|
|
32
|
+
console.error(getErrorMessageForDisplay(error) + "\n");
|
|
33
|
+
}
|
|
34
|
+
throw new Error("Validation failed");
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
export const validate = async (modelContainer) => {
|
|
38
|
+
const entities = getEntities(modelContainer.schema);
|
|
39
|
+
await prepareFolders(modelContainer, entities);
|
|
40
|
+
const instancesByEntityName = await getInstancesByEntityName(modelContainer, entities);
|
|
41
|
+
return _validate(entities, instancesByEntityName);
|
|
42
|
+
};
|
|
43
|
+
export const generateAndValidate = async (modelContainer) => {
|
|
44
|
+
await generateOutputs(modelContainer);
|
|
45
|
+
const entities = getEntities(modelContainer.schema);
|
|
46
|
+
await prepareFolders(modelContainer, entities);
|
|
47
|
+
const instancesByEntityName = await getInstancesByEntityName(modelContainer, entities);
|
|
48
|
+
await _validate(entities, instancesByEntityName);
|
|
49
|
+
};
|
|
50
|
+
export const serve = async (modelContainer) => {
|
|
51
|
+
const entities = getEntities(modelContainer.schema);
|
|
52
|
+
await prepareFolders(modelContainer, entities);
|
|
53
|
+
const instancesByEntityName = await getInstancesByEntityName(modelContainer, entities);
|
|
54
|
+
createServer(modelContainer, instancesByEntityName);
|
|
55
|
+
};
|
|
56
|
+
export const generateValidateAndServe = async (modelContainer) => {
|
|
57
|
+
await generateOutputs(modelContainer);
|
|
58
|
+
const entities = getEntities(modelContainer.schema);
|
|
59
|
+
await prepareFolders(modelContainer, entities);
|
|
60
|
+
const instancesByEntityName = await getInstancesByEntityName(modelContainer, entities);
|
|
61
|
+
await _validate(entities, instancesByEntityName);
|
|
62
|
+
createServer(modelContainer, instancesByEntityName);
|
|
63
|
+
};
|
package/lib/Schema.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Decl } from "./schema/declarations/Declaration.js";
|
|
2
|
+
import { EntityDecl } from "./schema/declarations/EntityDecl.js";
|
|
3
|
+
export interface Schema {
|
|
4
|
+
declarations: readonly Decl[];
|
|
5
|
+
localeEntity?: EntityDecl;
|
|
6
|
+
}
|
|
7
|
+
export declare const Schema: (declarations: Decl[], localeEntity?: EntityDecl) => Schema;
|
|
8
|
+
export declare const getEntities: (schema: Schema) => EntityDecl[];
|
package/lib/Schema.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { getNestedDeclarations, getParameterNames, } from "./schema/declarations/Declaration.js";
|
|
2
|
+
import { isEntityDecl } from "./schema/declarations/EntityDecl.js";
|
|
3
|
+
import { isStringType } from "./schema/types/primitives/StringType.js";
|
|
4
|
+
import { isNestedEntityMapType } from "./schema/types/references/NestedEntityMapType.js";
|
|
5
|
+
import { findTypeAtPath } from "./schema/types/Type.js";
|
|
6
|
+
const checkDuplicateIdentifier = (existingDecls, decl) => {
|
|
7
|
+
if (existingDecls
|
|
8
|
+
.values()
|
|
9
|
+
.some(otherDecl => otherDecl !== decl && otherDecl.name.toLowerCase() === decl.name.toLowerCase())) {
|
|
10
|
+
throw new Error(`Duplicate declaration name: "${decl.name}". Make sure declaration names are globally unique.`);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
const checkParameterNamesShadowing = (decls) => {
|
|
14
|
+
for (const decl of decls) {
|
|
15
|
+
for (const param of getParameterNames(decl)) {
|
|
16
|
+
if (decls.values().some(decl => decl.name === param)) {
|
|
17
|
+
throw new Error(`Parameter name "${param}" shadows declaration name.`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const checkEntityDisplayNamePaths = (decls, localeEntity) => {
|
|
23
|
+
for (const decl of decls) {
|
|
24
|
+
if (isEntityDecl(decl)) {
|
|
25
|
+
const displayName = decl.displayName ?? "name";
|
|
26
|
+
if (typeof displayName === "object") {
|
|
27
|
+
const pathToLocaleMap = displayName.pathToLocaleMap ?? "translations";
|
|
28
|
+
const pathInLocaleMap = displayName.pathInLocaleMap ?? "name";
|
|
29
|
+
if (localeEntity === undefined) {
|
|
30
|
+
throw new Error(`Display name path "${pathToLocaleMap}" for entity "${decl.name}" requires a defined locale entity.`);
|
|
31
|
+
}
|
|
32
|
+
const localeMapAtPath = findTypeAtPath(decl.type.value, pathToLocaleMap.split("."));
|
|
33
|
+
if (!localeMapAtPath ||
|
|
34
|
+
!isNestedEntityMapType(localeMapAtPath) ||
|
|
35
|
+
localeMapAtPath.secondaryEntity.name !== localeEntity.name) {
|
|
36
|
+
throw new Error(`Display name path "${pathToLocaleMap}" for entity "${decl.name}" does not lead to a nested entity map for the defined locale entity.`);
|
|
37
|
+
}
|
|
38
|
+
const typeAtLocaleMapPath = findTypeAtPath(localeMapAtPath.type.value, pathInLocaleMap.split("."));
|
|
39
|
+
if (!typeAtLocaleMapPath || !isStringType(typeAtLocaleMapPath)) {
|
|
40
|
+
throw new Error(`Display name path "${pathInLocaleMap}" for entity "${decl.name}" does not lead to a value of type string in nested locale map.`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
const path = displayName.split(".");
|
|
45
|
+
const typeAtPath = findTypeAtPath(decl.type.value, path);
|
|
46
|
+
if (!typeAtPath || !isStringType(typeAtPath)) {
|
|
47
|
+
throw new Error(`Display name path "${displayName}" for entity "${decl.name}" does not lead to a value of type string.`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
const addDeclarations = (existingDecls, declsToAdd, nested) => declsToAdd.reduce((accDecls, decl) => {
|
|
54
|
+
if (!accDecls.includes(decl)) {
|
|
55
|
+
checkDuplicateIdentifier(accDecls, decl);
|
|
56
|
+
const nestedDecls = nested
|
|
57
|
+
? getNestedDeclarations(declToAdd => accDecls.includes(declToAdd), decl)
|
|
58
|
+
: [];
|
|
59
|
+
return addDeclarations([...accDecls, decl], nestedDecls, false);
|
|
60
|
+
}
|
|
61
|
+
return accDecls;
|
|
62
|
+
}, existingDecls);
|
|
63
|
+
export const Schema = (declarations, localeEntity) => {
|
|
64
|
+
const allDecls = addDeclarations([], localeEntity ? declarations.concat(localeEntity) : declarations, true);
|
|
65
|
+
checkParameterNamesShadowing(allDecls);
|
|
66
|
+
checkEntityDisplayNamePaths(allDecls, localeEntity);
|
|
67
|
+
return {
|
|
68
|
+
declarations: allDecls,
|
|
69
|
+
localeEntity,
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
export const getEntities = (schema) => schema.declarations.filter(isEntityDecl);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { SerializedEntityDecl } from "../schema/declarations/EntityDecl.js";
|
|
2
|
+
import { CreateInstanceOfEntityResponseBody, DeleteInstanceOfEntityResponseBody, GetAllDeclarationsResponseBody, GetAllInstancesOfEntityResponseBody, GetAllInstancesResponseBody, GetDeclarationResponseBody, GetInstanceOfEntityResponseBody, UpdateInstanceOfEntityResponseBody } from "../shared/api.js";
|
|
3
|
+
export declare const getAllDeclarations: (kind?: "Entity" | "Enum" | "TypeAlias") => Promise<GetAllDeclarationsResponseBody>;
|
|
4
|
+
export declare const getAllEntities: () => Promise<GetAllDeclarationsResponseBody<SerializedEntityDecl>>;
|
|
5
|
+
export declare const getEntityByName: (name: string) => Promise<GetDeclarationResponseBody<SerializedEntityDecl>>;
|
|
6
|
+
export declare const getInstancesByEntityName: (name: string) => Promise<GetAllInstancesOfEntityResponseBody>;
|
|
7
|
+
export declare const createInstanceByEntityNameAndId: (name: string, content: unknown, id?: string) => Promise<CreateInstanceOfEntityResponseBody>;
|
|
8
|
+
export declare const getInstanceByEntityNameAndId: (name: string, id: string) => Promise<GetInstanceOfEntityResponseBody>;
|
|
9
|
+
export declare const updateInstanceByEntityNameAndId: (name: string, id: string, content: unknown) => Promise<UpdateInstanceOfEntityResponseBody>;
|
|
10
|
+
export declare const deleteInstanceByEntityNameAndId: (name: string, id: string) => Promise<DeleteInstanceOfEntityResponseBody>;
|
|
11
|
+
export declare const getAllInstances: (locales: string[]) => Promise<GetAllInstancesResponseBody>;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
export const getAllDeclarations = async (kind) => {
|
|
2
|
+
const url = new URL("/api/declarations", window.location.origin);
|
|
3
|
+
if (kind) {
|
|
4
|
+
url.searchParams.append("kind", kind);
|
|
5
|
+
}
|
|
6
|
+
const response = await fetch(url);
|
|
7
|
+
if (!response.ok) {
|
|
8
|
+
throw new Error(await response.text());
|
|
9
|
+
}
|
|
10
|
+
return response.json();
|
|
11
|
+
};
|
|
12
|
+
export const getAllEntities = () => getAllDeclarations("Entity");
|
|
13
|
+
export const getEntityByName = async (name) => {
|
|
14
|
+
const response = await fetch(`/api/declarations/${name}`);
|
|
15
|
+
if (!response.ok) {
|
|
16
|
+
throw new Error(await response.text());
|
|
17
|
+
}
|
|
18
|
+
return response.json();
|
|
19
|
+
};
|
|
20
|
+
export const getInstancesByEntityName = async (name) => {
|
|
21
|
+
const response = await fetch(`/api/declarations/${name}/instances`);
|
|
22
|
+
if (!response.ok) {
|
|
23
|
+
throw new Error(await response.text());
|
|
24
|
+
}
|
|
25
|
+
return response.json();
|
|
26
|
+
};
|
|
27
|
+
export const createInstanceByEntityNameAndId = async (name, content, id) => {
|
|
28
|
+
const url = new URL(`/api/declarations/${name}/instances`, window.location.origin);
|
|
29
|
+
if (id) {
|
|
30
|
+
url.searchParams.append("id", id);
|
|
31
|
+
}
|
|
32
|
+
const response = await fetch(url, {
|
|
33
|
+
method: "POST",
|
|
34
|
+
body: JSON.stringify(content),
|
|
35
|
+
headers: {
|
|
36
|
+
"Content-Type": "application/json",
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
if (!response.ok) {
|
|
40
|
+
throw new Error(await response.text());
|
|
41
|
+
}
|
|
42
|
+
return response.json();
|
|
43
|
+
};
|
|
44
|
+
export const getInstanceByEntityNameAndId = async (name, id) => {
|
|
45
|
+
const response = await fetch(`/api/declarations/${name}/instances/${id}`);
|
|
46
|
+
if (!response.ok) {
|
|
47
|
+
throw new Error(await response.text());
|
|
48
|
+
}
|
|
49
|
+
return response.json();
|
|
50
|
+
};
|
|
51
|
+
export const updateInstanceByEntityNameAndId = async (name, id, content) => {
|
|
52
|
+
const response = await fetch(`/api/declarations/${name}/instances/${id}`, {
|
|
53
|
+
method: "PUT",
|
|
54
|
+
body: JSON.stringify(content),
|
|
55
|
+
headers: {
|
|
56
|
+
"Content-Type": "application/json",
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
if (!response.ok) {
|
|
60
|
+
throw new Error(await response.text());
|
|
61
|
+
}
|
|
62
|
+
return response.json();
|
|
63
|
+
};
|
|
64
|
+
export const deleteInstanceByEntityNameAndId = async (name, id) => {
|
|
65
|
+
const response = await fetch(`/api/declarations/${name}/instances/${id}`, {
|
|
66
|
+
method: "DELETE",
|
|
67
|
+
});
|
|
68
|
+
if (!response.ok) {
|
|
69
|
+
throw new Error(await response.text());
|
|
70
|
+
}
|
|
71
|
+
return response.json();
|
|
72
|
+
};
|
|
73
|
+
export const getAllInstances = async (locales) => {
|
|
74
|
+
const url = new URL("/api/instances", window.location.origin);
|
|
75
|
+
for (const locale of locales) {
|
|
76
|
+
url.searchParams.append("locales", locale);
|
|
77
|
+
}
|
|
78
|
+
const response = await fetch(url);
|
|
79
|
+
if (!response.ok) {
|
|
80
|
+
throw new Error(await response.text());
|
|
81
|
+
}
|
|
82
|
+
return response.json();
|
|
83
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
export const Layout = ({ breadcrumbs, children }) => {
|
|
3
|
+
return (_jsxs(_Fragment, { children: [_jsx("header", { children: _jsx("nav", { children: _jsx("ol", { children: breadcrumbs.map(({ url, label }) => (_jsx("li", { children: _jsx("a", { href: url, children: label }) }))) }) }) }), _jsx("main", { children: children })] }));
|
|
4
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { FunctionComponent } from "preact";
|
|
2
|
+
import { SerializedArrayType } from "../../../schema/types/generic/ArrayType.js";
|
|
3
|
+
import { InstanceNamesByEntity } from "../../hooks/useInstanceNamesByEntity.js";
|
|
4
|
+
import { GetDeclFromDeclName } from "../../hooks/useSecondaryDeclarations.js";
|
|
5
|
+
type Props = {
|
|
6
|
+
type: SerializedArrayType;
|
|
7
|
+
value: unknown[];
|
|
8
|
+
instanceNamesByEntity: InstanceNamesByEntity;
|
|
9
|
+
getDeclFromDeclName: GetDeclFromDeclName;
|
|
10
|
+
onChange: (value: unknown[]) => void;
|
|
11
|
+
};
|
|
12
|
+
export declare const ArrayTypeInput: FunctionComponent<Props>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
import { validateArrayConstraints } from "../../../shared/validation/array.js";
|
|
3
|
+
import { createTypeSkeleton } from "../../utils/typeSkeleton.js";
|
|
4
|
+
import { TypeInput } from "./TypeInput.js";
|
|
5
|
+
import { ValidationErrors } from "./utils/ValidationErrors.js";
|
|
6
|
+
export const ArrayTypeInput = ({ type, value, instanceNamesByEntity, getDeclFromDeclName, onChange, }) => {
|
|
7
|
+
const errors = validateArrayConstraints(type, value);
|
|
8
|
+
const isTuple = typeof type.minItems === "number" && type.minItems === type.maxItems;
|
|
9
|
+
return (_jsxs("div", { class: "field field--container field--array", children: [value.length > 0 && (_jsx("ol", { children: value.map((item, i) => (_jsxs("li", { class: "container-item array-item", children: [_jsx(TypeInput, { type: type.items, value: item, instanceNamesByEntity: instanceNamesByEntity, getDeclFromDeclName: getDeclFromDeclName, onChange: newItem => onChange([...value.slice(0, i), newItem, ...value.slice(i + 1)]) }), isTuple ? null : (_jsx("button", { class: "destructive", onClick: () => onChange([...value, createTypeSkeleton(getDeclFromDeclName, type.items)]), disabled: type.minItems !== undefined && value.length <= type.minItems, children: "Delete Item" }))] }, i))) })), isTuple ? null : (_jsx("div", { class: "add-item-container", children: _jsx("button", { onClick: () => onChange([...value, createTypeSkeleton(getDeclFromDeclName, type.items)]), disabled: type.maxItems !== undefined && value.length >= type.maxItems, children: "Add Item" }) })), _jsx(ValidationErrors, { errors: errors })] }));
|
|
10
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FunctionComponent } from "preact";
|
|
2
|
+
import { SerializedBooleanType } from "../../../schema/types/primitives/BooleanType.js";
|
|
3
|
+
type Props = {
|
|
4
|
+
type: SerializedBooleanType;
|
|
5
|
+
value: boolean;
|
|
6
|
+
onChange: (value: boolean) => void;
|
|
7
|
+
};
|
|
8
|
+
export declare const BooleanTypeInput: FunctionComponent<Props>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { jsx as _jsx } from "preact/jsx-runtime";
|
|
2
|
+
export const BooleanTypeInput = ({ value, onChange }) => {
|
|
3
|
+
return (_jsx("div", { class: "field", children: _jsx("input", { type: "checkbox", checked: value, onInput: event => {
|
|
4
|
+
onChange(event.currentTarget.checked);
|
|
5
|
+
} }) }));
|
|
6
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FunctionComponent } from "preact";
|
|
2
|
+
import { SerializedDateType } from "../../../schema/types/primitives/DateType.js";
|
|
3
|
+
type Props = {
|
|
4
|
+
type: SerializedDateType;
|
|
5
|
+
value: string;
|
|
6
|
+
onChange: (value: string) => void;
|
|
7
|
+
};
|
|
8
|
+
export declare const DateTypeInput: FunctionComponent<Props>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
import { validateDateConstraints } from "../../../shared/validation/date.js";
|
|
3
|
+
import { ValidationErrors } from "./utils/ValidationErrors.js";
|
|
4
|
+
export const DateTypeInput = ({ type, value, onChange }) => {
|
|
5
|
+
const errors = validateDateConstraints(type, value);
|
|
6
|
+
return (_jsxs("div", { class: "field", children: [_jsx("input", { type: "date", value: value, onInput: event => {
|
|
7
|
+
onChange(event.currentTarget.value);
|
|
8
|
+
} }), _jsx(ValidationErrors, { errors: errors })] }));
|
|
9
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FunctionComponent } from "preact";
|
|
2
|
+
import { SerializedFloatType } from "../../../schema/types/primitives/FloatType.js";
|
|
3
|
+
type Props = {
|
|
4
|
+
type: SerializedFloatType;
|
|
5
|
+
value: number;
|
|
6
|
+
onChange: (value: number) => void;
|
|
7
|
+
};
|
|
8
|
+
export declare const FloatTypeInput: FunctionComponent<Props>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
import { useState } from "preact/hooks";
|
|
3
|
+
import { validateNumberConstraints } from "../../../shared/validation/number.js";
|
|
4
|
+
import { ValidationErrors } from "./utils/ValidationErrors.js";
|
|
5
|
+
export const FloatTypeInput = ({ type, value, onChange }) => {
|
|
6
|
+
const [stringValue, setStringValue] = useState(value.toString());
|
|
7
|
+
const errors = validateNumberConstraints(type, value);
|
|
8
|
+
return (_jsxs("div", { class: "field", children: [_jsx("input", { type: "number", value: stringValue, onInput: event => {
|
|
9
|
+
setStringValue(event.currentTarget.value);
|
|
10
|
+
const numericValue = Number.parseFloat(event.currentTarget.value);
|
|
11
|
+
if (!Number.isNaN(numericValue)) {
|
|
12
|
+
onChange(numericValue);
|
|
13
|
+
}
|
|
14
|
+
}, step: 0.01, "aria-invalid": errors.length > 0 }), _jsx(ValidationErrors, { errors: errors })] }));
|
|
15
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { FunctionComponent } from "preact";
|
|
2
|
+
import { SerializedGenericArgumentIdentifierType } from "../../../schema/types/references/GenericArgumentIdentifierType.js";
|
|
3
|
+
type Props = {
|
|
4
|
+
type: SerializedGenericArgumentIdentifierType;
|
|
5
|
+
};
|
|
6
|
+
export declare const GenericArgumentIdentifierTypeInput: FunctionComponent<Props>;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { FunctionComponent } from "preact";
|
|
2
|
+
import { SerializedIncludeIdentifierType } from "../../../schema/index.js";
|
|
3
|
+
import { InstanceNamesByEntity } from "../../hooks/useInstanceNamesByEntity.js";
|
|
4
|
+
import { GetDeclFromDeclName } from "../../hooks/useSecondaryDeclarations.js";
|
|
5
|
+
type Props = {
|
|
6
|
+
type: SerializedIncludeIdentifierType;
|
|
7
|
+
value: unknown;
|
|
8
|
+
instanceNamesByEntity: InstanceNamesByEntity;
|
|
9
|
+
getDeclFromDeclName: GetDeclFromDeclName;
|
|
10
|
+
onChange: (value: unknown) => void;
|
|
11
|
+
};
|
|
12
|
+
export declare const IncludeIdentifierTypeInput: FunctionComponent<Props>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
import { assertExhaustive } from "../../../shared/utils/typeSafety.js";
|
|
3
|
+
import { TypeInput } from "./TypeInput.js";
|
|
4
|
+
import { EnumDeclField } from "./utils/EnumDeclField.js";
|
|
5
|
+
export const IncludeIdentifierTypeInput = ({ type, value, instanceNamesByEntity, getDeclFromDeclName, onChange, }) => {
|
|
6
|
+
const decl = getDeclFromDeclName(type.reference);
|
|
7
|
+
if (decl === undefined) {
|
|
8
|
+
return (_jsxs("div", { role: "alert", children: ["Unresolved declaration identifier ", _jsx("code", { children: type.reference })] }));
|
|
9
|
+
}
|
|
10
|
+
switch (decl.kind) {
|
|
11
|
+
case "EnumDecl":
|
|
12
|
+
return (_jsx(EnumDeclField, { decl: decl, value: value, instanceNamesByEntity: instanceNamesByEntity, getDeclFromDeclName: getDeclFromDeclName, onChange: onChange }));
|
|
13
|
+
case "TypeAliasDecl":
|
|
14
|
+
return (_jsx(TypeInput, { type: decl.type, value: value, instanceNamesByEntity: instanceNamesByEntity, getDeclFromDeclName: getDeclFromDeclName, onChange: onChange }));
|
|
15
|
+
default:
|
|
16
|
+
return assertExhaustive(decl);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FunctionComponent } from "preact";
|
|
2
|
+
import { SerializedIntegerType } from "../../../schema/types/primitives/IntegerType.js";
|
|
3
|
+
type Props = {
|
|
4
|
+
type: SerializedIntegerType;
|
|
5
|
+
value: number;
|
|
6
|
+
onChange: (value: number) => void;
|
|
7
|
+
};
|
|
8
|
+
export declare const IntegerTypeInput: FunctionComponent<Props>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
import { useState } from "preact/hooks";
|
|
3
|
+
import { validateNumberConstraints } from "../../../shared/validation/number.js";
|
|
4
|
+
import { ValidationErrors } from "./utils/ValidationErrors.js";
|
|
5
|
+
export const IntegerTypeInput = ({ type, value, onChange }) => {
|
|
6
|
+
const [stringValue, setStringValue] = useState(value.toString());
|
|
7
|
+
const errors = validateNumberConstraints(type, value);
|
|
8
|
+
return (_jsxs("div", { class: "field", children: [_jsx("input", { type: "number", value: stringValue, onInput: event => {
|
|
9
|
+
setStringValue(event.currentTarget.value);
|
|
10
|
+
const numericValue = Number.parseInt(event.currentTarget.value, 10);
|
|
11
|
+
if (!Number.isNaN(numericValue)) {
|
|
12
|
+
onChange(numericValue);
|
|
13
|
+
}
|
|
14
|
+
}, step: 0.01, "aria-invalid": errors.length > 0 }), _jsx(ValidationErrors, { errors: errors })] }));
|
|
15
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { FunctionComponent } from "preact";
|
|
2
|
+
import { SerializedNestedEntityMapType } from "../../../schema/types/references/NestedEntityMapType.js";
|
|
3
|
+
import { InstanceNamesByEntity } from "../../hooks/useInstanceNamesByEntity.js";
|
|
4
|
+
import { GetDeclFromDeclName } from "../../hooks/useSecondaryDeclarations.js";
|
|
5
|
+
type Props = {
|
|
6
|
+
type: SerializedNestedEntityMapType;
|
|
7
|
+
value: Record<string, unknown>;
|
|
8
|
+
instanceNamesByEntity: InstanceNamesByEntity;
|
|
9
|
+
getDeclFromDeclName: GetDeclFromDeclName;
|
|
10
|
+
onChange: (value: Record<string, unknown>) => void;
|
|
11
|
+
};
|
|
12
|
+
export declare const NestedEntityMapTypeInput: FunctionComponent<Props>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
import { useState } from "preact/hooks";
|
|
3
|
+
import { sortObjectKeysAlphabetically } from "../../../shared/utils/object.js";
|
|
4
|
+
import { createTypeSkeleton } from "../../utils/typeSkeleton.js";
|
|
5
|
+
import { Select } from "../Select.js";
|
|
6
|
+
import { TypeInput } from "./TypeInput.js";
|
|
7
|
+
export const NestedEntityMapTypeInput = ({ type, value, instanceNamesByEntity, getDeclFromDeclName, onChange, }) => {
|
|
8
|
+
const [newKey, setNewKey] = useState("");
|
|
9
|
+
const existingKeys = Object.keys(value);
|
|
10
|
+
const secondaryInstances = (instanceNamesByEntity[type.secondaryEntity] ?? [])
|
|
11
|
+
.slice()
|
|
12
|
+
.filter(instance => !existingKeys.includes(instance.id))
|
|
13
|
+
.sort((a, b) => a.name.localeCompare(b.name));
|
|
14
|
+
return (_jsxs("div", { class: "field field--container field--nestedentitymap", children: [existingKeys.length > 0 && (_jsx("ul", { children: Object.entries(value).map(([key, item]) => (_jsxs("li", { class: "container-item dict-item", children: [_jsxs("div", { className: "container-item-header", children: [_jsx("div", { className: "container-item-title", children: _jsxs("span", { children: [_jsx("strong", { children: instanceNamesByEntity[type.secondaryEntity].find(instance => instance.id === key)?.name ?? key }), " ", _jsx("span", { className: "id", children: key })] }) }), _jsx("div", { className: "btns", children: _jsx("button", { class: "destructive", onClick: () => {
|
|
15
|
+
const newObj = { ...value };
|
|
16
|
+
delete newObj[key];
|
|
17
|
+
onChange(newObj);
|
|
18
|
+
}, children: "Delete Key" }) })] }), _jsx(TypeInput, { type: type.type, value: item, instanceNamesByEntity: instanceNamesByEntity, getDeclFromDeclName: getDeclFromDeclName, onChange: newItem => onChange(sortObjectKeysAlphabetically({ ...value, [key]: newItem })) })] }, key))) })), _jsxs("div", { class: "add-item-container", children: [_jsxs(Select, { value: newKey, onInput: event => setNewKey(event.currentTarget.value), disabled: secondaryInstances.length === 0, children: [secondaryInstances.length === 0 ? (_jsx("option", { value: "", disabled: true, children: "No instances available" })) : (_jsx("option", { value: "", disabled: true, children: "No selected instance" })), secondaryInstances.map(instance => (_jsx("option", { value: instance.id, children: instance.name })))] }), _jsx("button", { onClick: () => {
|
|
19
|
+
onChange(sortObjectKeysAlphabetically({
|
|
20
|
+
...value,
|
|
21
|
+
[newKey]: createTypeSkeleton(getDeclFromDeclName, type.type),
|
|
22
|
+
}));
|
|
23
|
+
setNewKey("");
|
|
24
|
+
}, disabled: newKey === "", children: "Add Key" })] })] }));
|
|
25
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { FunctionComponent } from "preact";
|
|
2
|
+
import { SerializedObjectType } from "../../../schema/types/generic/ObjectType.js";
|
|
3
|
+
import { InstanceNamesByEntity } from "../../hooks/useInstanceNamesByEntity.js";
|
|
4
|
+
import { GetDeclFromDeclName } from "../../hooks/useSecondaryDeclarations.js";
|
|
5
|
+
type Props = {
|
|
6
|
+
type: SerializedObjectType;
|
|
7
|
+
value: Record<string, unknown>;
|
|
8
|
+
instanceNamesByEntity: InstanceNamesByEntity;
|
|
9
|
+
getDeclFromDeclName: GetDeclFromDeclName;
|
|
10
|
+
onChange: (value: Record<string, unknown>) => void;
|
|
11
|
+
};
|
|
12
|
+
export declare const ObjectTypeInput: FunctionComponent<Props>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
import { sortObjectKeys } from "../../../shared/utils/object.js";
|
|
3
|
+
import { toTitleCase } from "../../../shared/utils/string.js";
|
|
4
|
+
import { validateObjectConstraints } from "../../../shared/validation/object.js";
|
|
5
|
+
import { createTypeSkeleton } from "../../utils/typeSkeleton.js";
|
|
6
|
+
import { TypeInput } from "./TypeInput.js";
|
|
7
|
+
import { ValidationErrors } from "./utils/ValidationErrors.js";
|
|
8
|
+
export const ObjectTypeInput = ({ type, value, instanceNamesByEntity, getDeclFromDeclName, onChange, }) => {
|
|
9
|
+
const errors = validateObjectConstraints(type, Object.keys(type.properties), value);
|
|
10
|
+
return (_jsxs("div", { class: "field field--container field--object", children: [_jsx("ul", { children: Object.entries(type.properties).map(([key, memberDecl]) => (_jsxs("li", { class: "container-item object-item", children: [_jsxs("div", { className: "container-item-header", children: [_jsxs("div", { className: "container-item-title", children: [_jsx("strong", { children: toTitleCase(key) }), memberDecl.comment === undefined ? null : (_jsx("p", { class: "comment", children: memberDecl.comment }))] }), memberDecl.isRequired ? null : value[key] === undefined ? (_jsx("button", { onClick: () => {
|
|
11
|
+
onChange(sortObjectKeys({
|
|
12
|
+
...value,
|
|
13
|
+
[key]: createTypeSkeleton(getDeclFromDeclName, memberDecl.type),
|
|
14
|
+
}, Object.keys(type.properties)));
|
|
15
|
+
}, children: "Add Property" })) : (_jsx("button", { class: "destructive", onClick: () => {
|
|
16
|
+
const newObj = { ...value };
|
|
17
|
+
delete newObj[key];
|
|
18
|
+
onChange(newObj);
|
|
19
|
+
}, children: "Remove Property" }))] }), memberDecl.isRequired || value[key] !== undefined ? (_jsx(TypeInput, { type: memberDecl.type, value: value[key], instanceNamesByEntity: instanceNamesByEntity, getDeclFromDeclName: getDeclFromDeclName, onChange: newItem => onChange(sortObjectKeys({ ...value, [key]: newItem }, Object.keys(type.properties))) })) : null] }, key))) }), _jsx(ValidationErrors, { errors: errors })] }));
|
|
20
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FunctionComponent } from "preact";
|
|
2
|
+
import { SerializedReferenceIdentifierType } from "../../../schema/types/references/ReferenceIdentifierType.js";
|
|
3
|
+
import { InstanceNamesByEntity } from "../../hooks/useInstanceNamesByEntity.js";
|
|
4
|
+
type Props = {
|
|
5
|
+
type: SerializedReferenceIdentifierType;
|
|
6
|
+
value: string;
|
|
7
|
+
instanceNamesByEntity: InstanceNamesByEntity;
|
|
8
|
+
onChange: (value: string) => void;
|
|
9
|
+
};
|
|
10
|
+
export declare const ReferenceIdentifierTypeInput: FunctionComponent<Props>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
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 => onChange(event.currentTarget.value), 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 })))] }), _jsx(ValidationErrors, { errors: !value ? [ReferenceError("no reference provided")] : [] })] }));
|
|
9
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FunctionComponent } from "preact";
|
|
2
|
+
import { SerializedStringType } from "../../../schema/types/primitives/StringType.js";
|
|
3
|
+
type Props = {
|
|
4
|
+
type: SerializedStringType;
|
|
5
|
+
value: string;
|
|
6
|
+
onChange: (value: string) => void;
|
|
7
|
+
};
|
|
8
|
+
export declare const StringTypeInput: FunctionComponent<Props>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
import { validateStringConstraints } from "../../../shared/validation/string.js";
|
|
3
|
+
import { ValidationErrors } from "./utils/ValidationErrors.js";
|
|
4
|
+
export const StringTypeInput = ({ type, value, onChange }) => {
|
|
5
|
+
const { minLength, maxLength, pattern } = type;
|
|
6
|
+
const errors = validateStringConstraints(type, value);
|
|
7
|
+
return (_jsxs("div", { class: "field", children: [_jsx("input", { type: "text", value: value, minLength: minLength, maxLength: maxLength, pattern: pattern, onInput: event => {
|
|
8
|
+
onChange(event.currentTarget.value);
|
|
9
|
+
}, "aria-invalid": errors.length > 0 }), _jsx(ValidationErrors, { errors: errors })] }));
|
|
10
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { FunctionComponent } from "preact";
|
|
2
|
+
import { SerializedType } from "../../../schema/types/Type.js";
|
|
3
|
+
import { InstanceNamesByEntity } from "../../hooks/useInstanceNamesByEntity.js";
|
|
4
|
+
import { 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 {};
|