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
package/lib/web/api.js
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
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
|
+
};
|
|
84
|
+
export const getGitStatus = async (locales) => {
|
|
85
|
+
const url = new URL("/api/git/status", window.location.origin);
|
|
86
|
+
for (const locale of locales) {
|
|
87
|
+
url.searchParams.append("locales", locale);
|
|
88
|
+
}
|
|
89
|
+
const response = await fetch(url);
|
|
90
|
+
if (!response.ok) {
|
|
91
|
+
throw new Error(await response.text());
|
|
92
|
+
}
|
|
93
|
+
return response.json();
|
|
94
|
+
};
|
|
95
|
+
export const stageAllFiles = async () => {
|
|
96
|
+
const response = await fetch(`/api/git/stage`, {
|
|
97
|
+
method: "POST",
|
|
98
|
+
});
|
|
99
|
+
if (!response.ok) {
|
|
100
|
+
throw new Error(await response.text());
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
export const stageAllFilesOfEntity = async (entityName) => {
|
|
104
|
+
const response = await fetch(`/api/git/stage/${entityName}`, {
|
|
105
|
+
method: "POST",
|
|
106
|
+
});
|
|
107
|
+
if (!response.ok) {
|
|
108
|
+
throw new Error(await response.text());
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
export const stageFileOfEntity = async (entityName, id) => {
|
|
112
|
+
const response = await fetch(`/api/git/stage/${entityName}/${id}`, {
|
|
113
|
+
method: "POST",
|
|
114
|
+
});
|
|
115
|
+
if (!response.ok) {
|
|
116
|
+
throw new Error(await response.text());
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
export const unstageAllFiles = async () => {
|
|
120
|
+
const response = await fetch(`/api/git/unstage`, {
|
|
121
|
+
method: "POST",
|
|
122
|
+
});
|
|
123
|
+
if (!response.ok) {
|
|
124
|
+
throw new Error(await response.text());
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
export const unstageAllFilesOfEntity = async (entityName) => {
|
|
128
|
+
const response = await fetch(`/api/git/unstage/${entityName}`, {
|
|
129
|
+
method: "POST",
|
|
130
|
+
});
|
|
131
|
+
if (!response.ok) {
|
|
132
|
+
throw new Error(await response.text());
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
export const unstageFileOfEntity = async (entityName, id) => {
|
|
136
|
+
const response = await fetch(`/api/git/unstage/${entityName}/${id}`, {
|
|
137
|
+
method: "POST",
|
|
138
|
+
});
|
|
139
|
+
if (!response.ok) {
|
|
140
|
+
throw new Error(await response.text());
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
export const commitStagedFiles = async (message) => {
|
|
144
|
+
const body = { message };
|
|
145
|
+
const response = await fetch(`/api/git/commit`, {
|
|
146
|
+
method: "POST",
|
|
147
|
+
body: JSON.stringify(body),
|
|
148
|
+
headers: {
|
|
149
|
+
"Content-Type": "application/json",
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
if (!response.ok) {
|
|
153
|
+
throw new Error(await response.text());
|
|
154
|
+
}
|
|
155
|
+
return response.json();
|
|
156
|
+
};
|
|
157
|
+
export const pushCommits = async () => {
|
|
158
|
+
const response = await fetch(`/api/git/push`, {
|
|
159
|
+
method: "POST",
|
|
160
|
+
});
|
|
161
|
+
if (!response.ok) {
|
|
162
|
+
throw new Error(await response.text());
|
|
163
|
+
}
|
|
164
|
+
return response.json();
|
|
165
|
+
};
|
|
166
|
+
export const pullCommits = async () => {
|
|
167
|
+
const response = await fetch(`/api/git/pull`, {
|
|
168
|
+
method: "POST",
|
|
169
|
+
});
|
|
170
|
+
if (!response.ok) {
|
|
171
|
+
throw new Error(await response.text());
|
|
172
|
+
}
|
|
173
|
+
return response.json();
|
|
174
|
+
};
|
|
175
|
+
export const getBranches = async () => {
|
|
176
|
+
const response = await fetch(`/api/git/branch`, {
|
|
177
|
+
method: "GET",
|
|
178
|
+
});
|
|
179
|
+
if (!response.ok) {
|
|
180
|
+
throw new Error(await response.text());
|
|
181
|
+
}
|
|
182
|
+
return response.json();
|
|
183
|
+
};
|
|
184
|
+
export const createBranch = async (branchName) => {
|
|
185
|
+
const body = { branchName };
|
|
186
|
+
const response = await fetch(`/api/git/branch`, {
|
|
187
|
+
method: "POST",
|
|
188
|
+
body: JSON.stringify(body),
|
|
189
|
+
headers: {
|
|
190
|
+
"Content-Type": "application/json",
|
|
191
|
+
},
|
|
192
|
+
});
|
|
193
|
+
if (!response.ok) {
|
|
194
|
+
throw new Error(await response.text());
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
export const switchBranch = async (branchName) => {
|
|
198
|
+
const response = await fetch(`/api/git/branch/${branchName}`, {
|
|
199
|
+
method: "POST",
|
|
200
|
+
});
|
|
201
|
+
if (!response.ok) {
|
|
202
|
+
throw new Error(await response.text());
|
|
203
|
+
}
|
|
204
|
+
};
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
import { useEffect, useState } from "preact/hooks";
|
|
3
|
+
import { getGitStatusForDisplay, getLabelForGitStatus, isChangedInIndex, isChangedInWorkingDir, } from "../../shared/utils/git.js";
|
|
4
|
+
import { commitStagedFiles, createBranch, getAllEntities, getBranches, getGitStatus, pullCommits, pushCommits, stageAllFiles, stageFileOfEntity, switchBranch, unstageAllFiles, unstageFileOfEntity, } from "../api.js";
|
|
5
|
+
const filterFilesForDisplay = (predicate, entities, data) => Object.entries(data.instances)
|
|
6
|
+
.map(([entityName, instances]) => [
|
|
7
|
+
entityName,
|
|
8
|
+
entities.find(entity => entity.name === entityName)?.namePlural ?? entityName,
|
|
9
|
+
instances
|
|
10
|
+
.filter(instance => instance.gitStatus !== undefined && predicate(instance.gitStatus))
|
|
11
|
+
.sort((a, b) => a.displayName.localeCompare(b.displayName)),
|
|
12
|
+
])
|
|
13
|
+
.filter(([_1, _2, instances]) => instances.length > 0)
|
|
14
|
+
.sort((a, b) => a[1].localeCompare(b[1]));
|
|
15
|
+
const GitFileList = ({ filesByEntity, onFile, isIndex = false }) => filesByEntity.length === 0 ? (_jsx("p", { class: "no-changes", children: "No changes" })) : (_jsx("ul", { class: "git-entity-list", children: filesByEntity.map(([entityName, entityNamePlural, instances]) => (_jsxs("li", { class: "git-entity-list-item", children: [_jsx("span", { class: "title", children: entityNamePlural }), _jsx("ul", { class: "git-instance-list", children: instances.map(instance => {
|
|
16
|
+
const gitStatusForDisplay = getGitStatusForDisplay(instance.gitStatus);
|
|
17
|
+
return (_jsxs("li", { class: "git-instance-list-item", children: [_jsx("span", { class: "title", children: instance.displayName }), _jsx("span", { class: `git-status git-status--${gitStatusForDisplay ?? ""}`, title: getLabelForGitStatus(gitStatusForDisplay), children: gitStatusForDisplay }), _jsx("button", { onClick: () => {
|
|
18
|
+
onFile(entityName, instance);
|
|
19
|
+
}, children: isIndex ? "Unstage" : "Stage" })] }, instance.fileName));
|
|
20
|
+
}) })] }, entityName))) }));
|
|
21
|
+
export const Git = () => {
|
|
22
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
23
|
+
const [commitsAhead, setCommitsAhead] = useState(0);
|
|
24
|
+
const [commitsBehind, setCommitsBehind] = useState(0);
|
|
25
|
+
const [commitMessage, setCommitMessage] = useState("");
|
|
26
|
+
const [indexFiles, setIndexFiles] = useState([]);
|
|
27
|
+
const [workingTreeFiles, setWorkingTreeFiles] = useState([]);
|
|
28
|
+
const [entities, setEntities] = useState([]);
|
|
29
|
+
const [allBranches, setAllBranches] = useState([]);
|
|
30
|
+
const [currentBranch, setCurrentBranch] = useState("");
|
|
31
|
+
const updateGitStatus = (localEntities) => Promise.all([getGitStatus(["de-DE"]), getBranches()]).then(([statusData, branchesData]) => {
|
|
32
|
+
setIndexFiles(filterFilesForDisplay(isChangedInIndex, localEntities, statusData));
|
|
33
|
+
setWorkingTreeFiles(filterFilesForDisplay(isChangedInWorkingDir, localEntities, statusData));
|
|
34
|
+
setCommitsAhead(statusData.commitsAhead);
|
|
35
|
+
setCommitsBehind(statusData.commitsBehind);
|
|
36
|
+
setAllBranches(branchesData.allBranches);
|
|
37
|
+
setCurrentBranch(branchesData.currentBranch);
|
|
38
|
+
});
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
getAllEntities()
|
|
41
|
+
.then(async (data) => {
|
|
42
|
+
const entitiesFromServer = data.declarations.map(decl => decl.declaration);
|
|
43
|
+
setEntities(entitiesFromServer);
|
|
44
|
+
return updateGitStatus(entitiesFromServer);
|
|
45
|
+
})
|
|
46
|
+
.catch((error) => {
|
|
47
|
+
if (error instanceof Error) {
|
|
48
|
+
console.error("Error fetching entities:", error.toString());
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}, []);
|
|
52
|
+
const stage = (entityName, instance) => {
|
|
53
|
+
stageFileOfEntity(entityName, instance.id)
|
|
54
|
+
.then(() => updateGitStatus(entities))
|
|
55
|
+
.catch((error) => {
|
|
56
|
+
if (error instanceof Error) {
|
|
57
|
+
console.error("Error staging instance:", error.toString());
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
const stageAll = () => {
|
|
62
|
+
stageAllFiles()
|
|
63
|
+
.then(() => updateGitStatus(entities))
|
|
64
|
+
.catch((error) => {
|
|
65
|
+
if (error instanceof Error) {
|
|
66
|
+
console.error("Error staging all instances:", error.toString());
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
const unstage = (entityName, instance) => {
|
|
71
|
+
unstageFileOfEntity(entityName, instance.id)
|
|
72
|
+
.then(() => updateGitStatus(entities))
|
|
73
|
+
.catch((error) => {
|
|
74
|
+
if (error instanceof Error) {
|
|
75
|
+
console.error("Error unstaging instance:", error.toString());
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
const unstageAll = () => {
|
|
80
|
+
unstageAllFiles()
|
|
81
|
+
.then(() => updateGitStatus(entities))
|
|
82
|
+
.catch((error) => {
|
|
83
|
+
if (error instanceof Error) {
|
|
84
|
+
console.error("Error unstaging all instances:", error.toString());
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
const commit = () => {
|
|
89
|
+
if (commitMessage.length > 0 &&
|
|
90
|
+
indexFiles.length > 0 &&
|
|
91
|
+
confirm("Do you want to commit all staged files?")) {
|
|
92
|
+
commitStagedFiles(commitMessage)
|
|
93
|
+
.then(() => {
|
|
94
|
+
setCommitMessage("");
|
|
95
|
+
return updateGitStatus(entities);
|
|
96
|
+
})
|
|
97
|
+
.catch((error) => {
|
|
98
|
+
if (error instanceof Error) {
|
|
99
|
+
console.error("Error committing instances:", error.toString());
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
const push = () => {
|
|
105
|
+
pushCommits()
|
|
106
|
+
.then(() => {
|
|
107
|
+
alert("Pushed commits successfully");
|
|
108
|
+
return updateGitStatus(entities);
|
|
109
|
+
})
|
|
110
|
+
.catch((error) => {
|
|
111
|
+
console.error("Error pushing commits:", error);
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
const pull = () => {
|
|
115
|
+
pullCommits()
|
|
116
|
+
.then(() => {
|
|
117
|
+
alert("Pulled commits successfully");
|
|
118
|
+
return updateGitStatus(entities);
|
|
119
|
+
})
|
|
120
|
+
.catch((error) => {
|
|
121
|
+
console.error("Error pulling commits:", error);
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
const onCreateBranch = () => {
|
|
125
|
+
const newBranchName = prompt("Enter new branch name:");
|
|
126
|
+
if (!newBranchName) {
|
|
127
|
+
alert("Branch name cannot be empty");
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
if (allBranches.includes(newBranchName)) {
|
|
131
|
+
alert("Branch name already exists");
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
createBranch(newBranchName)
|
|
135
|
+
.then(() => {
|
|
136
|
+
return updateGitStatus(entities);
|
|
137
|
+
})
|
|
138
|
+
.catch((error) => {
|
|
139
|
+
if (error instanceof Error) {
|
|
140
|
+
alert("Error switching branch:" + error.toString());
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
};
|
|
144
|
+
const onSwitchBranch = (event) => {
|
|
145
|
+
switchBranch(event.currentTarget.value)
|
|
146
|
+
.then(() => {
|
|
147
|
+
return updateGitStatus(entities);
|
|
148
|
+
})
|
|
149
|
+
.catch((error) => {
|
|
150
|
+
if (error instanceof Error) {
|
|
151
|
+
alert("Error switching branch: " + error.toString());
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
return (_jsxs("aside", { class: "git", children: [_jsx("h2", { class: "h1-faded", children: "Version Control" }), _jsx("button", { onClick: () => {
|
|
156
|
+
setIsOpen(b => !b);
|
|
157
|
+
}, children: "File changes" }), _jsxs("div", { className: `git-overlay ${isOpen ? "git-overlay--open" : ""}`, children: [_jsxs("div", { class: "sync", children: [_jsxs("button", { onClick: push, children: ["Push", commitsAhead > 0 ? ` (${commitsAhead.toString()})` : ""] }), _jsxs("button", { onClick: pull, children: ["Pull", commitsBehind > 0 ? ` (${commitsBehind.toString()})` : ""] })] }), _jsxs("div", { className: "branch", children: [_jsx("div", { className: "select-wrapper", children: _jsx("select", { value: currentBranch, onInput: onSwitchBranch, children: allBranches.map(branch => (_jsx("option", { value: branch, children: branch }, branch))) }) }), _jsx("button", { onClick: onCreateBranch, children: "New branch" })] }), _jsxs("div", { class: "commit", children: [_jsx("input", { type: "text", value: commitMessage, onInput: event => {
|
|
158
|
+
setCommitMessage(event.currentTarget.value);
|
|
159
|
+
}, placeholder: "added X to instance Y, \u2026" }), _jsx("button", { onClick: commit, disabled: commitMessage.length === 0 || indexFiles.length === 0, children: "Commit" })] }), _jsxs("div", { className: "git-section-title", children: [_jsx("h3", { children: "Files to be committed" }), _jsx("button", { onClick: unstageAll, children: "Unstage all" })] }), _jsx(GitFileList, { filesByEntity: indexFiles, isIndex: true, onFile: unstage }), _jsxs("div", { className: "git-section-title", children: [_jsx("h3", { children: "Working tree changes" }), _jsx("button", { onClick: stageAll, children: "Stage all" })] }), _jsx(GitFileList, { filesByEntity: workingTreeFiles, onFile: stage })] })] }));
|
|
160
|
+
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
import { Git } from "./Git.js";
|
|
2
3
|
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
|
+
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 }) }, url))) }) }) }), _jsx(Git, {}), _jsx("main", { children: children })] }));
|
|
4
5
|
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { jsx as _jsx } from "preact/jsx-runtime";
|
|
2
|
+
const isNullableString = (value) => {
|
|
3
|
+
return typeof value === "string" || value === undefined;
|
|
4
|
+
};
|
|
5
|
+
export const Select = props => (_jsx("div", { class: "select-wrapper", children: _jsx("select", { ...props, class: `${(isNullableString(props.class) ? props.class : props.class.value) ?? ""} ${(isNullableString(props.className) ? props.className : props.className.value) ?? ""} ${!props.value ? "no-selection" : ""}` }) }));
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { FunctionComponent } from "preact";
|
|
2
|
+
import type { SerializedArrayType } from "../../../node/schema/types/generic/ArrayType.js";
|
|
3
|
+
import type { InstanceNamesByEntity } from "../../hooks/useInstanceNamesByEntity.js";
|
|
4
|
+
import type { 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 {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsxs as _jsxs, jsx as _jsx } from "preact/jsx-runtime";
|
|
2
|
+
import { removeAt } from "../../../shared/utils/array.js";
|
|
2
3
|
import { validateArrayConstraints } from "../../../shared/validation/array.js";
|
|
3
4
|
import { createTypeSkeleton } from "../../utils/typeSkeleton.js";
|
|
4
5
|
import { TypeInput } from "./TypeInput.js";
|
|
@@ -6,5 +7,11 @@ import { ValidationErrors } from "./utils/ValidationErrors.js";
|
|
|
6
7
|
export const ArrayTypeInput = ({ type, value, instanceNamesByEntity, getDeclFromDeclName, onChange, }) => {
|
|
7
8
|
const errors = validateArrayConstraints(type, value);
|
|
8
9
|
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: [isTuple ? null : (_jsxs("div", { className: "container-item-header", children: [_jsxs("div", { className: "container-item-title", children: [i + 1, "."] }), _jsx("button", { class: "destructive", onClick: () =>
|
|
10
|
+
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: [isTuple ? null : (_jsxs("div", { className: "container-item-header", children: [_jsxs("div", { className: "container-item-title", children: [i + 1, "."] }), _jsx("button", { class: "destructive", onClick: () => {
|
|
11
|
+
onChange(removeAt(value, i));
|
|
12
|
+
}, disabled: type.minItems !== undefined && value.length <= type.minItems, children: "Delete Item" })] })), _jsx(TypeInput, { type: type.items, value: item, instanceNamesByEntity: instanceNamesByEntity, getDeclFromDeclName: getDeclFromDeclName, onChange: newItem => {
|
|
13
|
+
onChange(value.with(i, newItem));
|
|
14
|
+
} })] }, i))) })), isTuple ? null : (_jsx("div", { class: "add-item-container", children: _jsx("button", { onClick: () => {
|
|
15
|
+
onChange([...value, createTypeSkeleton(getDeclFromDeclName, type.items)]);
|
|
16
|
+
}, disabled: type.maxItems !== undefined && value.length >= type.maxItems, children: "Add Item" }) })), _jsx(ValidationErrors, { errors: errors })] }));
|
|
10
17
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FunctionComponent } from "preact";
|
|
2
|
-
import { SerializedBooleanType } from "../../../schema/types/primitives/BooleanType.js";
|
|
1
|
+
import type { FunctionComponent } from "preact";
|
|
2
|
+
import type { SerializedBooleanType } from "../../../node/schema/types/primitives/BooleanType.js";
|
|
3
3
|
type Props = {
|
|
4
4
|
type: SerializedBooleanType;
|
|
5
5
|
value: boolean;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FunctionComponent } from "preact";
|
|
2
|
-
import { SerializedDateType } from "../../../schema/types/primitives/DateType.js";
|
|
1
|
+
import type { FunctionComponent } from "preact";
|
|
2
|
+
import type { SerializedDateType } from "../../../node/schema/types/primitives/DateType.js";
|
|
3
3
|
type Props = {
|
|
4
4
|
type: SerializedDateType;
|
|
5
5
|
value: string;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { FunctionComponent } from "preact";
|
|
2
|
+
import type { SerializedEnumType } from "../../../node/schema/types/generic/EnumType.js";
|
|
3
|
+
import type { InstanceNamesByEntity } from "../../hooks/useInstanceNamesByEntity.js";
|
|
4
|
+
import type { GetDeclFromDeclName } from "../../hooks/useSecondaryDeclarations.js";
|
|
5
|
+
type Props = {
|
|
6
|
+
type: SerializedEnumType;
|
|
7
|
+
value: unknown;
|
|
8
|
+
instanceNamesByEntity: InstanceNamesByEntity;
|
|
9
|
+
getDeclFromDeclName: GetDeclFromDeclName;
|
|
10
|
+
onChange: (value: unknown) => void;
|
|
11
|
+
};
|
|
12
|
+
export declare const EnumTypeInput: FunctionComponent<Props>;
|
|
13
|
+
export {};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
-
import { discriminatorKey } from "
|
|
3
|
-
import { toTitleCase } from "
|
|
4
|
-
import { createTypeSkeleton } from "
|
|
5
|
-
import { Select } from "
|
|
6
|
-
import { TypeInput } from "
|
|
7
|
-
import { MismatchingTypeError } from "./MismatchingTypeError.js";
|
|
8
|
-
export const
|
|
2
|
+
import { discriminatorKey } from "../../../shared/enum.js";
|
|
3
|
+
import { toTitleCase } from "../../../shared/utils/string.js";
|
|
4
|
+
import { createTypeSkeleton } from "../../utils/typeSkeleton.js";
|
|
5
|
+
import { Select } from "../Select.js";
|
|
6
|
+
import { TypeInput } from "./TypeInput.js";
|
|
7
|
+
import { MismatchingTypeError } from "./utils/MismatchingTypeError.js";
|
|
8
|
+
export const EnumTypeInput = ({ type, value, instanceNamesByEntity, getDeclFromDeclName, onChange, }) => {
|
|
9
9
|
if (typeof value !== "object" ||
|
|
10
10
|
value === null ||
|
|
11
11
|
Array.isArray(value) ||
|
|
@@ -13,11 +13,11 @@ export const EnumDeclField = ({ decl, value, instanceNamesByEntity, getDeclFromD
|
|
|
13
13
|
typeof value[discriminatorKey] !== "string") {
|
|
14
14
|
return _jsx(MismatchingTypeError, { expected: "enumeration value", actual: value });
|
|
15
15
|
}
|
|
16
|
-
const enumValues = Object.keys(
|
|
16
|
+
const enumValues = Object.keys(type.values);
|
|
17
17
|
const activeEnumCase = value[discriminatorKey];
|
|
18
|
-
const caseMember =
|
|
18
|
+
const caseMember = type.values[activeEnumCase];
|
|
19
19
|
return (_jsxs("div", { class: "field field--enum", children: [_jsx(Select, { value: activeEnumCase, onInput: event => {
|
|
20
|
-
const caseMember =
|
|
20
|
+
const caseMember = type.values[event.currentTarget.value];
|
|
21
21
|
if (caseMember?.type == null) {
|
|
22
22
|
onChange({
|
|
23
23
|
[discriminatorKey]: event.currentTarget.value,
|
|
@@ -29,7 +29,7 @@ export const EnumDeclField = ({ decl, value, instanceNamesByEntity, getDeclFromD
|
|
|
29
29
|
[event.currentTarget.value]: createTypeSkeleton(getDeclFromDeclName, caseMember.type),
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
|
-
}, children: enumValues.map(enumValue => (_jsx("option", { value: enumValue, selected: enumValue === activeEnumCase, children: toTitleCase(enumValue) }))) }), caseMember?.type == null ? null : (_jsx("div", { className: "associated-type", children: _jsx(TypeInput, { type: caseMember.type, value: value[activeEnumCase], instanceNamesByEntity: instanceNamesByEntity, getDeclFromDeclName: getDeclFromDeclName, onChange: newValue => {
|
|
32
|
+
}, children: enumValues.map(enumValue => (_jsx("option", { value: enumValue, selected: enumValue === activeEnumCase, children: toTitleCase(enumValue) }, enumValue))) }), caseMember?.type == null ? null : (_jsx("div", { className: "associated-type", children: _jsx(TypeInput, { type: caseMember.type, value: value[activeEnumCase], instanceNamesByEntity: instanceNamesByEntity, getDeclFromDeclName: getDeclFromDeclName, onChange: newValue => {
|
|
33
33
|
onChange({
|
|
34
34
|
[discriminatorKey]: activeEnumCase,
|
|
35
35
|
[activeEnumCase]: newValue,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FunctionComponent } from "preact";
|
|
2
|
-
import { SerializedFloatType } from "../../../schema/types/primitives/FloatType.js";
|
|
1
|
+
import type { FunctionComponent } from "preact";
|
|
2
|
+
import type { SerializedFloatType } from "../../../node/schema/types/primitives/FloatType.js";
|
|
3
3
|
type Props = {
|
|
4
4
|
type: SerializedFloatType;
|
|
5
5
|
value: number;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { FunctionComponent } from "preact";
|
|
2
|
+
import type { SerializedTypeArgumentType } from "../../../node/schema/types/references/TypeArgumentType.js";
|
|
3
|
+
type Props = {
|
|
4
|
+
type: SerializedTypeArgumentType;
|
|
5
|
+
};
|
|
6
|
+
export declare const TypeArgumentTypeInput: FunctionComponent<Props>;
|
|
7
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
-
export const
|
|
2
|
+
export const TypeArgumentTypeInput = ({ type }) => {
|
|
3
3
|
return (_jsxs("div", { role: "alert", children: ["Unresolved type argument ", _jsx("code", { children: type.argument.name })] }));
|
|
4
4
|
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { FunctionComponent } from "preact";
|
|
2
|
+
import type { SerializedIncludeIdentifierType } from "../../../node/schema/index.js";
|
|
3
|
+
import type { InstanceNamesByEntity } from "../../hooks/useInstanceNamesByEntity.js";
|
|
4
|
+
import type { 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,9 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
import { TypeInput } from "./TypeInput.js";
|
|
3
|
+
export const IncludeIdentifierTypeInput = ({ type, value, instanceNamesByEntity, getDeclFromDeclName, onChange, }) => {
|
|
4
|
+
const decl = getDeclFromDeclName(type.reference);
|
|
5
|
+
if (decl === undefined) {
|
|
6
|
+
return (_jsxs("div", { role: "alert", children: ["Unresolved declaration identifier ", _jsx("code", { children: type.reference })] }));
|
|
7
|
+
}
|
|
8
|
+
return (_jsx(TypeInput, { type: decl.type, value: value, instanceNamesByEntity: instanceNamesByEntity, getDeclFromDeclName: getDeclFromDeclName, onChange: onChange }));
|
|
9
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FunctionComponent } from "preact";
|
|
2
|
-
import { SerializedIntegerType } from "../../../schema/types/primitives/IntegerType.js";
|
|
1
|
+
import type { FunctionComponent } from "preact";
|
|
2
|
+
import type { SerializedIntegerType } from "../../../node/schema/types/primitives/IntegerType.js";
|
|
3
3
|
type Props = {
|
|
4
4
|
type: SerializedIntegerType;
|
|
5
5
|
value: number;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { FunctionComponent } from "preact";
|
|
2
|
+
import type { SerializedNestedEntityMapType } from "../../../node/schema/types/references/NestedEntityMapType.js";
|
|
3
|
+
import type { InstanceNamesByEntity } from "../../hooks/useInstanceNamesByEntity.js";
|
|
4
|
+
import type { 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 {};
|
|
@@ -11,11 +11,16 @@ export const NestedEntityMapTypeInput = ({ type, value, instanceNamesByEntity, g
|
|
|
11
11
|
.slice()
|
|
12
12
|
.filter(instance => !existingKeys.includes(instance.id))
|
|
13
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]
|
|
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
15
|
const newObj = { ...value };
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
16
17
|
delete newObj[key];
|
|
17
18
|
onChange(newObj);
|
|
18
|
-
}, children: "Delete Key" }) })] }), _jsx(TypeInput, { type: type.type, value: item, instanceNamesByEntity: instanceNamesByEntity, getDeclFromDeclName: getDeclFromDeclName, onChange: newItem =>
|
|
19
|
+
}, children: "Delete Key" }) })] }), _jsx(TypeInput, { type: type.type, value: item, instanceNamesByEntity: instanceNamesByEntity, getDeclFromDeclName: getDeclFromDeclName, onChange: newItem => {
|
|
20
|
+
onChange(sortObjectKeysAlphabetically({ ...value, [key]: newItem }));
|
|
21
|
+
} })] }, key))) })), _jsxs("div", { class: "add-item-container", children: [_jsxs(Select, { value: newKey, onInput: event => {
|
|
22
|
+
setNewKey(event.currentTarget.value);
|
|
23
|
+
}, 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 }, instance.id)))] }), _jsx("button", { onClick: () => {
|
|
19
24
|
onChange(sortObjectKeysAlphabetically({
|
|
20
25
|
...value,
|
|
21
26
|
[newKey]: createTypeSkeleton(getDeclFromDeclName, type.type),
|
|
@@ -1,7 +1,7 @@
|
|
|
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";
|
|
1
|
+
import type { FunctionComponent } from "preact";
|
|
2
|
+
import type { SerializedObjectType } from "../../../node/schema/types/generic/ObjectType.js";
|
|
3
|
+
import type { InstanceNamesByEntity } from "../../hooks/useInstanceNamesByEntity.js";
|
|
4
|
+
import type { GetDeclFromDeclName } from "../../hooks/useSecondaryDeclarations.js";
|
|
5
5
|
type Props = {
|
|
6
6
|
type: SerializedObjectType;
|
|
7
7
|
value: Record<string, unknown>;
|
|
@@ -14,7 +14,10 @@ export const ObjectTypeInput = ({ type, value, instanceNamesByEntity, getDeclFro
|
|
|
14
14
|
}, Object.keys(type.properties)));
|
|
15
15
|
}, children: "Add Property" })) : (_jsx("button", { class: "destructive", onClick: () => {
|
|
16
16
|
const newObj = { ...value };
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
17
18
|
delete newObj[key];
|
|
18
19
|
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 =>
|
|
20
|
+
}, children: "Remove Property" }))] }), memberDecl.isRequired || value[key] !== undefined ? (_jsx(TypeInput, { type: memberDecl.type, value: value[key], instanceNamesByEntity: instanceNamesByEntity, getDeclFromDeclName: getDeclFromDeclName, onChange: newItem => {
|
|
21
|
+
onChange(sortObjectKeys({ ...value, [key]: newItem }, Object.keys(type.properties)));
|
|
22
|
+
} })) : null] }, key))) }), _jsx(ValidationErrors, { errors: errors })] }));
|
|
20
23
|
};
|