tsondb 0.3.0 → 0.5.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 +10 -0
- package/lib/bin/tsondb.js +84 -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} +6 -5
- package/lib/node/index.d.ts +9 -0
- package/lib/node/index.js +75 -0
- package/lib/{renderers → node/renderers}/Output.d.ts +1 -1
- package/lib/{renderers → node/renderers}/jsonschema/index.d.ts +2 -2
- package/lib/{renderers → node/renderers}/jsonschema/index.js +9 -2
- package/lib/{renderers → node/renderers}/jsonschema/render.d.ts +1 -1
- package/lib/{renderers → node/renderers}/jsonschema/render.js +15 -10
- package/lib/{renderers → node/renderers}/ts/index.d.ts +2 -2
- package/lib/{renderers → node/renderers}/ts/index.js +2 -2
- package/lib/{renderers → node/renderers}/ts/render.d.ts +1 -1
- package/lib/{renderers → node/renderers}/ts/render.js +13 -9
- package/lib/{schema → node/schema}/Node.d.ts +5 -5
- package/lib/{schema → node/schema}/Node.js +9 -8
- 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 +10 -11
- package/lib/{schema → node/schema}/declarations/Declaration.js +7 -5
- package/lib/{schema → node/schema}/declarations/EntityDecl.d.ts +13 -12
- package/lib/{schema → node/schema}/declarations/EntityDecl.js +4 -5
- package/lib/{schema → node/schema}/declarations/EnumDecl.d.ts +9 -7
- package/lib/{schema → node/schema}/declarations/EnumDecl.js +6 -13
- package/lib/{schema → node/schema}/declarations/TypeAliasDecl.d.ts +8 -7
- package/lib/{schema → node/schema}/declarations/TypeAliasDecl.js +6 -14
- package/lib/{schema → node/schema}/index.d.ts +4 -4
- package/lib/{schema → node/schema}/index.js +3 -4
- package/lib/node/schema/types/Type.d.ts +54 -0
- package/lib/{schema → node/schema}/types/Type.js +55 -29
- package/lib/{schema → node/schema}/types/generic/ArrayType.d.ts +5 -4
- package/lib/{schema → node/schema}/types/generic/ArrayType.js +5 -5
- package/lib/{schema → node/schema}/types/generic/EnumType.d.ts +5 -4
- package/lib/{schema → node/schema}/types/generic/EnumType.js +10 -4
- package/lib/{schema → node/schema}/types/generic/ObjectType.d.ts +8 -7
- package/lib/{schema → node/schema}/types/generic/ObjectType.js +14 -7
- package/lib/{schema → node/schema}/types/primitives/BooleanType.d.ts +4 -3
- package/lib/{schema → node/schema}/types/primitives/DateType.d.ts +5 -4
- package/lib/{schema → node/schema}/types/primitives/DateType.js +1 -1
- package/lib/{schema → node/schema}/types/primitives/FloatType.d.ts +5 -4
- package/lib/{schema → node/schema}/types/primitives/FloatType.js +1 -1
- package/lib/{schema → node/schema}/types/primitives/IntegerType.d.ts +5 -4
- package/lib/{schema → node/schema}/types/primitives/IntegerType.js +1 -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 +5 -4
- package/lib/{schema → node/schema}/types/primitives/StringType.js +1 -1
- package/lib/{schema → node/schema}/types/references/IncludeIdentifierType.d.ts +9 -8
- package/lib/{schema → node/schema}/types/references/IncludeIdentifierType.js +1 -1
- package/lib/{schema → node/schema}/types/references/NestedEntityMapType.d.ts +10 -9
- package/lib/{schema → node/schema}/types/references/NestedEntityMapType.js +8 -16
- package/lib/{schema → node/schema}/types/references/ReferenceIdentifierType.d.ts +7 -6
- package/lib/{schema → node/schema}/types/references/ReferenceIdentifierType.js +1 -1
- 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/{server → node/server}/api/declarations.js +7 -3
- package/lib/{server → node/server}/api/git.js +14 -11
- package/lib/{server → node/server}/api/instanceOperations.d.ts +3 -3
- package/lib/{server → node/server}/api/instanceOperations.js +18 -7
- package/lib/{server → node/server}/api/instances.js +7 -3
- package/lib/node/server/index.d.ts +28 -0
- package/lib/{server → node/server}/index.js +23 -13
- package/lib/node/server/init.d.ts +5 -0
- package/lib/{server → node/server}/init.js +9 -8
- package/lib/{utils → node/utils}/error.js +4 -1
- package/lib/{utils → node/utils}/git.d.ts +2 -2
- package/lib/{utils → node/utils}/instances.d.ts +4 -3
- package/lib/{utils → node/utils}/instances.js +10 -6
- package/lib/{utils → node/utils}/references.d.ts +2 -2
- package/lib/{utils → node/utils}/references.js +3 -3
- package/lib/{utils → node/utils}/render.js +1 -1
- package/lib/shared/api.d.ts +9 -3
- package/lib/shared/utils/array.d.ts +1 -0
- package/lib/shared/utils/array.js +13 -9
- package/lib/shared/utils/displayName.d.ts +1 -1
- package/lib/shared/utils/displayName.js +7 -2
- package/lib/shared/utils/instances.d.ts +2 -2
- package/lib/{utils → shared/utils}/lazy.js +1 -1
- package/lib/shared/utils/markdown.js +6 -6
- package/lib/shared/utils/object.d.ts +3 -0
- package/lib/shared/utils/object.js +5 -1
- package/lib/{utils → shared/utils}/result.js +2 -2
- package/lib/shared/utils/string.js +7 -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/{client → web}/api.d.ts +3 -3
- package/lib/{client → web}/api.js +5 -6
- package/lib/web/components/Git.d.ts +2 -0
- package/lib/{client → web}/components/Git.js +59 -15
- package/lib/{client → web}/components/Layout.d.ts +1 -1
- package/lib/{client → web}/components/Layout.js +1 -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 +7 -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 → web}/components/typeInputs/EnumTypeInput.js +1 -1
- 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/{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 +3 -3
- package/lib/{client → web}/components/typeInputs/utils/Markdown.d.ts +1 -1
- package/lib/{client → web}/components/typeInputs/utils/Markdown.js +2 -2
- 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/{client → web}/hooks/useAPIResource.js +2 -1
- 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/{client → web}/hooks/useMappedAPIResource.js +9 -9
- 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/{client → web}/routes/Entity.js +8 -6
- package/lib/web/routes/Home.d.ts +2 -0
- package/lib/{client → web}/routes/Home.js +2 -1
- 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 +4 -1
- package/package.json +33 -19
- package/lib/ModelContainer.d.ts +0 -17
- package/lib/ModelContainer.js +0 -65
- package/lib/client/components/Git.d.ts +0 -2
- 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/EnumTypeInput.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/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/hooks/useAPIResource.d.ts +0 -1
- package/lib/client/hooks/useMappedAPIResource.d.ts +0 -1
- package/lib/client/routes/Entity.d.ts +0 -2
- package/lib/client/routes/Home.d.ts +0 -2
- package/lib/client/utils/typeSkeleton.d.ts +0 -3
- package/lib/schema/types/Type.d.ts +0 -48
- package/lib/schema/types/primitives/PrimitiveType.d.ts +0 -6
- package/lib/schema/types/references/GenericArgumentIdentifierType.d.ts +0 -22
- package/lib/schema/types/references/GenericArgumentIdentifierType.js +0 -19
- package/lib/schema/validation/type.d.ts +0 -4
- package/lib/server/index.d.ts +0 -29
- package/lib/server/init.d.ts +0 -5
- package/lib/tsconfig.tsbuildinfo +0 -1
- package/lib/utils/object.d.ts +0 -3
- package/lib/utils/object.js +0 -1
- /package/lib/{renderers → node/renderers}/Output.js +0 -0
- /package/lib/{schema → node/schema}/types/primitives/BooleanType.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/{server → node/server}/api/declarations.d.ts +0 -0
- /package/lib/{server → node/server}/api/git.d.ts +0 -0
- /package/lib/{server → node/server}/api/index.d.ts +0 -0
- /package/lib/{server → node/server}/api/index.js +0 -0
- /package/lib/{server → node/server}/api/instances.d.ts +0 -0
- /package/lib/{utils → node/utils}/error.d.ts +0 -0
- /package/lib/{utils → node/utils}/git.js +0 -0
- /package/lib/{utils → node/utils}/path.d.ts +0 -0
- /package/lib/{utils → node/utils}/path.js +0 -0
- /package/lib/{utils → node/utils}/render.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/IncludeIdentifierTypeInput.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,5 +1,6 @@
|
|
|
1
|
-
import { StatusResult } from "simple-git";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import type { StatusResult } from "simple-git";
|
|
2
|
+
import type { InstancesByEntityName } from "../../shared/utils/instances.js";
|
|
3
|
+
import type { EntityDecl } from "../schema/declarations/EntityDecl.js";
|
|
4
4
|
export declare const getInstancesByEntityName: (dataRoot: string, entities: readonly EntityDecl[]) => Promise<InstancesByEntityName>;
|
|
5
5
|
export declare const attachGitStatusToInstancesByEntityName: (instancesByEntityName: InstancesByEntityName, dataRoot: string, gitRoot: string, gitStatus: StatusResult) => void;
|
|
6
|
+
export declare const formatInstance: (entity: EntityDecl, instanceContent: unknown) => string;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { readdir, readFile } from "node:fs/promises";
|
|
2
2
|
import { basename, extname, join } from "node:path";
|
|
3
|
+
import { formatValue } from "../schema/index.js";
|
|
3
4
|
import { getGitFileStatusFromStatusResult } from "./git.js";
|
|
4
5
|
export const getInstancesByEntityName = async (dataRoot, entities) => Object.fromEntries(await Promise.all(entities.map(async (entity) => {
|
|
5
6
|
const entityDir = join(dataRoot, entity.name);
|
|
@@ -11,9 +12,12 @@ export const getInstancesByEntityName = async (dataRoot, entities) => Object.fro
|
|
|
11
12
|
})));
|
|
12
13
|
return [entity.name, instances];
|
|
13
14
|
})));
|
|
14
|
-
export const attachGitStatusToInstancesByEntityName = (instancesByEntityName, dataRoot, gitRoot, gitStatus) =>
|
|
15
|
-
instancesByEntityName[entityName
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
});
|
|
15
|
+
export const attachGitStatusToInstancesByEntityName = (instancesByEntityName, dataRoot, gitRoot, gitStatus) => {
|
|
16
|
+
Object.entries(instancesByEntityName).forEach(([entityName, instances]) => {
|
|
17
|
+
instancesByEntityName[entityName] = instances.map(instanceContainer => ({
|
|
18
|
+
...instanceContainer,
|
|
19
|
+
gitStatus: getGitFileStatusFromStatusResult(gitStatus, gitRoot, dataRoot, entityName, instanceContainer.fileName),
|
|
20
|
+
}));
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
export const formatInstance = (entity, instanceContent) => JSON.stringify(formatValue(entity.type.value, instanceContent), undefined, 2) + "\n";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { InstanceContainer } from "../../shared/utils/instances.js";
|
|
2
|
+
import type { EntityDecl } from "../schema/declarations/EntityDecl.js";
|
|
3
3
|
export type ReferencesToInstances = {
|
|
4
4
|
[instanceId: string]: string[];
|
|
5
5
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { difference, removeAt } from "../../shared/utils/array.js";
|
|
1
2
|
import { getReferencesForEntityDecl } from "../schema/declarations/EntityDecl.js";
|
|
2
|
-
import { difference, removeAt } from "../shared/utils/array.js";
|
|
3
3
|
const addReference = (acc, reference, instanceId) => ({
|
|
4
4
|
...acc,
|
|
5
5
|
[reference]: [...(acc[reference] ?? []), instanceId],
|
|
@@ -31,8 +31,8 @@ export const updateReferencesToInstances = (entitiesByName, referencesToInstance
|
|
|
31
31
|
if (newInstance === undefined) {
|
|
32
32
|
return removeReferences(referencesToInstances, getReferencesForEntityDecl(entity, oldInstance), instanceId);
|
|
33
33
|
}
|
|
34
|
-
const oldReferences =
|
|
35
|
-
const newReferences =
|
|
34
|
+
const oldReferences = getReferencesForEntityDecl(entity, oldInstance);
|
|
35
|
+
const newReferences = getReferencesForEntityDecl(entity, newInstance);
|
|
36
36
|
const { added, removed } = difference(oldReferences, newReferences);
|
|
37
37
|
return removeReferences(addReferences(referencesToInstances, added, instanceId), removed, instanceId);
|
|
38
38
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EOL } from "node:os";
|
|
2
|
-
import { mergeObjects } from "
|
|
2
|
+
import { mergeObjects } from "../../shared/utils/object.js";
|
|
3
3
|
export const prefixLines = (prefix, text, includeEmptyLines = false) => text
|
|
4
4
|
.split(EOL)
|
|
5
5
|
.map(line => (includeEmptyLines || line.length > 0 ? prefix + line : line))
|
package/lib/shared/api.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { SerializedDecl } from "../schema/declarations/Declaration.js";
|
|
2
|
-
import { InstanceContainer, InstanceContainerOverview } from "./utils/instances.js";
|
|
1
|
+
import type { SerializedDecl } from "../node/schema/declarations/Declaration.js";
|
|
2
|
+
import type { InstanceContainer, InstanceContainerOverview } from "./utils/instances.js";
|
|
3
3
|
export interface GetAllDeclarationsResponseBody<D extends SerializedDecl = SerializedDecl> {
|
|
4
4
|
declarations: {
|
|
5
5
|
declaration: D;
|
|
@@ -13,7 +13,7 @@ export interface GetDeclarationResponseBody<D extends SerializedDecl = Serialize
|
|
|
13
13
|
isLocaleEntity: boolean;
|
|
14
14
|
}
|
|
15
15
|
export interface GetAllInstancesOfEntityResponseBody {
|
|
16
|
-
instances:
|
|
16
|
+
instances: InstanceContainerOverview[];
|
|
17
17
|
isLocaleEntity: boolean;
|
|
18
18
|
}
|
|
19
19
|
export interface CreateInstanceOfEntityResponseBody {
|
|
@@ -51,3 +51,9 @@ export interface GetAllGitBranchesResponseBody {
|
|
|
51
51
|
allBranches: string[];
|
|
52
52
|
currentBranch: string;
|
|
53
53
|
}
|
|
54
|
+
export interface CreateCommitRequestBody {
|
|
55
|
+
message: string;
|
|
56
|
+
}
|
|
57
|
+
export interface CreateBranchRequestBody {
|
|
58
|
+
branchName: string;
|
|
59
|
+
}
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
export const removeAt = (arr, index) =>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
export const removeAt = (arr, index) => {
|
|
2
|
+
if (index < 0 || index >= arr.length) {
|
|
3
|
+
throw new RangeError(`index ${index.toString()} is out of bounds for array of length ${arr.length.toString()}`);
|
|
4
|
+
}
|
|
5
|
+
return [...arr.slice(0, index), ...arr.slice(index + 1)];
|
|
6
|
+
};
|
|
7
|
+
export const insertAt = (arr, index, item) => {
|
|
8
|
+
if (index < 0 || index > arr.length) {
|
|
9
|
+
throw new RangeError(`index ${index.toString()} is out of bounds for array of length ${arr.length.toString()}`);
|
|
10
|
+
}
|
|
11
|
+
return [...arr.slice(0, index), item, ...arr.slice(index)];
|
|
12
|
+
};
|
|
10
13
|
/**
|
|
11
14
|
* Calculates the difference between two arrays, including duplicated values.
|
|
12
15
|
* @param oldArr - The original array.
|
|
@@ -25,3 +28,4 @@ export const difference = (oldArr, newArr) => newArr.reduce((acc, item) => {
|
|
|
25
28
|
}
|
|
26
29
|
return acc;
|
|
27
30
|
}, { removed: oldArr, added: newArr });
|
|
31
|
+
export const unique = (arr, equalityCheck = (a, b) => a === b) => arr.filter((item, index) => arr.findIndex(other => equalityCheck(item, other)) === index);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { SerializedEntityDecl } from "../../schema/index.js";
|
|
1
|
+
import type { SerializedEntityDecl } from "../../node/schema/index.js";
|
|
2
2
|
export declare const getDisplayNameFromEntityInstance: (entity: SerializedEntityDecl, instance: unknown, defaultName: string, locales?: string[]) => string;
|
|
@@ -12,6 +12,9 @@ const getValueAtPath = (value, path) => {
|
|
|
12
12
|
return current;
|
|
13
13
|
};
|
|
14
14
|
export const getDisplayNameFromEntityInstance = (entity, instance, defaultName, locales = []) => {
|
|
15
|
+
if (entity.displayName === null) {
|
|
16
|
+
return defaultName;
|
|
17
|
+
}
|
|
15
18
|
const displayNamePath = entity.displayName ?? "name";
|
|
16
19
|
if (typeof displayNamePath === "string") {
|
|
17
20
|
return getValueAtPath(instance, displayNamePath) ?? defaultName;
|
|
@@ -23,9 +26,11 @@ export const getDisplayNameFromEntityInstance = (entity, instance, defaultName,
|
|
|
23
26
|
const availableLocales = Object.keys(localeMap ?? {});
|
|
24
27
|
return availableLocales.length === 0
|
|
25
28
|
? defaultName
|
|
26
|
-
: locales.reduce((name, locale) => name ??
|
|
29
|
+
: (locales.reduce((name, locale) => name ??
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
27
31
|
getValueAtPath(localeMap[locale], pathInLocaleMap), undefined) ??
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
28
33
|
getValueAtPath(localeMap[availableLocales[0]], pathInLocaleMap) ??
|
|
29
|
-
defaultName;
|
|
34
|
+
defaultName);
|
|
30
35
|
}
|
|
31
36
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { SerializedEntityDecl } from "../../schema/index.js";
|
|
2
|
-
import { GitFileStatus } from "./git.js";
|
|
1
|
+
import type { SerializedEntityDecl } from "../../node/schema/index.js";
|
|
2
|
+
import type { GitFileStatus } from "./git.js";
|
|
3
3
|
export interface InstanceContainer {
|
|
4
4
|
fileName: string;
|
|
5
5
|
id: string;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
const boldWithItalicRule = {
|
|
2
2
|
pattern: /\*\*(.*?\*.+?\*.*?)\*\*/,
|
|
3
|
-
map: (result, parseInside) => ({ kind: "bold", content: parseInside(result[1]) }),
|
|
3
|
+
map: (result, parseInside) => ({ kind: "bold", content: parseInside(result[1] ?? "") }),
|
|
4
4
|
};
|
|
5
5
|
const italicWithBoldRule = {
|
|
6
6
|
pattern: /\*(.*?\*\*.+?\*\*.*?)\*/,
|
|
7
|
-
map: (result, parseInside) => ({ kind: "italic", content: parseInside(result[1]) }),
|
|
7
|
+
map: (result, parseInside) => ({ kind: "italic", content: parseInside(result[1] ?? "") }),
|
|
8
8
|
};
|
|
9
9
|
const boldRule = {
|
|
10
10
|
pattern: /\*\*(.+?)\*\*/,
|
|
11
|
-
map: (result, parseInside) => ({ kind: "bold", content: parseInside(result[1]) }),
|
|
11
|
+
map: (result, parseInside) => ({ kind: "bold", content: parseInside(result[1] ?? "") }),
|
|
12
12
|
};
|
|
13
13
|
const italicRule = {
|
|
14
14
|
pattern: /\*(.+?)\*/,
|
|
15
|
-
map: (result, parseInside) => ({ kind: "italic", content: parseInside(result[1]) }),
|
|
15
|
+
map: (result, parseInside) => ({ kind: "italic", content: parseInside(result[1] ?? "") }),
|
|
16
16
|
};
|
|
17
17
|
const rules = [boldWithItalicRule, italicWithBoldRule, boldRule, italicRule];
|
|
18
18
|
export const parseBlockMarkdown = (text) => text.split(/\n{2,}/).map(par => ({ kind: "paragraph", content: parseInlineMarkdown(par) }));
|
|
@@ -20,10 +20,10 @@ const parseForRules = (rules, text) => {
|
|
|
20
20
|
if (text.length === 0) {
|
|
21
21
|
return [];
|
|
22
22
|
}
|
|
23
|
-
|
|
23
|
+
const activeRule = rules[0];
|
|
24
|
+
if (activeRule === undefined) {
|
|
24
25
|
return [{ kind: "text", content: text }];
|
|
25
26
|
}
|
|
26
|
-
const activeRule = rules[0];
|
|
27
27
|
const res = activeRule.pattern.exec(text);
|
|
28
28
|
if (res && (activeRule.predicate?.(res) ?? true)) {
|
|
29
29
|
const { index } = res;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
export declare const sortObjectKeys: (obj: Record<string, unknown>, keys: string[]) => Record<string, unknown>;
|
|
2
2
|
export declare const sortObjectKeysAlphabetically: (obj: Record<string, unknown>) => Record<string, unknown>;
|
|
3
3
|
export declare const mergeObjects: <T>(obj1: Record<string, T>, obj2: Record<string, T>, solveConflict: (a: T, b: T) => T) => Record<string, T>;
|
|
4
|
+
export type Leaves<T> = T extends object ? {
|
|
5
|
+
[K in keyof T]: T[K] extends unknown[] ? never : `${Exclude<K, symbol>}${Leaves<T[K]> extends never ? "" : `.${Leaves<T[K]>}`}`;
|
|
6
|
+
}[keyof T] : never;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
export const sortObjectKeys = (obj, keys) => Object.fromEntries(
|
|
1
|
+
export const sortObjectKeys = (obj, keys) => Object.fromEntries([
|
|
2
|
+
...keys.flatMap(key => (obj[key] === undefined ? [] : [[key, obj[key]]])),
|
|
3
|
+
...Object.entries(obj).filter(([key]) => !keys.includes(key)),
|
|
4
|
+
]);
|
|
2
5
|
export const sortObjectKeysAlphabetically = (obj) => Object.fromEntries(Object.entries(obj).sort(([keyA], [keyB]) => keyA.localeCompare(keyB)));
|
|
3
6
|
export const mergeObjects = (obj1, obj2, solveConflict) => Object.entries(obj2).reduce((acc, [key, value]) => ({
|
|
4
7
|
...acc,
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
5
9
|
[key]: Object.hasOwn(acc, key) ? solveConflict(acc[key], value) : value,
|
|
6
10
|
}), obj1);
|
|
@@ -24,11 +24,11 @@ export const reduce = (result, fok, ferror) => (isOk(result) ? fok(result.value)
|
|
|
24
24
|
/**
|
|
25
25
|
* Maps the value of a result to a new value.
|
|
26
26
|
*/
|
|
27
|
-
export const map = (result, f) =>
|
|
27
|
+
export const map = (result, f) => isOk(result) ? ok(f(result.value)) : result;
|
|
28
28
|
/**
|
|
29
29
|
* Maps an error to a new error.
|
|
30
30
|
*/
|
|
31
|
-
export const mapError = (result, f) =>
|
|
31
|
+
export const mapError = (result, f) => isError(result) ? error(f(result.error)) : result;
|
|
32
32
|
export const combine = (result1, result2, fok, ferror) => isOk(result1)
|
|
33
33
|
? isOk(result2)
|
|
34
34
|
? ok(fok(result1.value, result2.value))
|
|
@@ -5,14 +5,17 @@ const separator = /[^a-z0-9]/;
|
|
|
5
5
|
const lastChar = (str) => str[str.length - 1];
|
|
6
6
|
const lastElement = (arr) => arr[arr.length - 1];
|
|
7
7
|
const isAllUppercase = (str) => str === str.toUpperCase();
|
|
8
|
-
export const splitStringParts = (str) => [...str].reduce((acc,
|
|
8
|
+
export const splitStringParts = (str) => [...new Intl.Segmenter().segment(str)].reduce((acc, segment, i, strArr) => {
|
|
9
|
+
const char = segment.segment;
|
|
9
10
|
if (acc.length === 0) {
|
|
10
11
|
return letterOrDigit.test(char) ? [char] : acc;
|
|
11
12
|
}
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
12
14
|
const lastPart = lastElement(acc);
|
|
13
15
|
if (uppercase.test(char)) {
|
|
14
16
|
const lastCharOfLastPart = lastChar(lastPart);
|
|
15
|
-
const
|
|
17
|
+
const nextSegment = strArr[i + 1];
|
|
18
|
+
const nextChar = nextSegment?.segment;
|
|
16
19
|
if (lastCharOfLastPart === undefined ||
|
|
17
20
|
(uppercase.test(lastCharOfLastPart) && (nextChar === undefined || separator.test(nextChar)))) {
|
|
18
21
|
return [...acc.slice(0, -1), lastPart + char];
|
|
@@ -47,8 +50,8 @@ export const toKebabCase = (str) => splitStringParts(str)
|
|
|
47
50
|
export const toSnakeCase = (str) => splitStringParts(str)
|
|
48
51
|
.map(part => part.toLowerCase())
|
|
49
52
|
.join("_");
|
|
50
|
-
export const toTitleCase = (str) => splitStringParts(str)
|
|
51
|
-
.map(part => part.charAt(0).toUpperCase() + part.slice(1).toLowerCase())
|
|
53
|
+
export const toTitleCase = (str) => splitStringParts(isAllUppercase(str) ? str.toLowerCase() : str)
|
|
54
|
+
.map(part => isAllUppercase(part) ? part : part.charAt(0).toUpperCase() + part.slice(1).toLowerCase())
|
|
52
55
|
.join(" ");
|
|
53
56
|
export const commonPrefix = (...strs) => {
|
|
54
57
|
if (strs.length === 0) {
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { gte, lte } from "./compare.js";
|
|
2
2
|
export const parallelizeErrors = (errors) => errors.filter(error => error !== undefined);
|
|
3
|
+
const normalizeLabel = (label) => Array.isArray(label) ? label : [label, label + "s"];
|
|
3
4
|
export const validateLengthRangeBound = (end, label, rangeBound, value) => {
|
|
4
5
|
if (rangeBound === undefined) {
|
|
5
6
|
return;
|
|
6
7
|
}
|
|
7
8
|
const [operator, description] = end === "lower" ? [gte, "least"] : [lte, "most"];
|
|
8
9
|
const length = value.length;
|
|
9
|
-
const normalizedLabel =
|
|
10
|
+
const normalizedLabel = normalizeLabel(label);
|
|
10
11
|
if (!operator(length, rangeBound)) {
|
|
11
|
-
return RangeError(`
|
|
12
|
+
return RangeError(`expected at ${description} ${rangeBound.toString()} ${normalizedLabel[rangeBound === 1 ? 0 : 1]}, but got ${length.toString()} ${normalizedLabel[length === 1 ? 0 : 1]}`);
|
|
12
13
|
}
|
|
13
14
|
return;
|
|
14
15
|
};
|
|
@@ -18,8 +18,8 @@ export const validateRangeBound = (end, rangeBound, value) => {
|
|
|
18
18
|
: normalizedRangeBound.isExclusive
|
|
19
19
|
? [lt, "less than"]
|
|
20
20
|
: [lte, "less than or equal"];
|
|
21
|
-
if (operator(value, normalizedRangeBound.value)) {
|
|
22
|
-
return RangeError(`expected a value ${description} ${normalizedRangeBound.value}, but got ${value}`);
|
|
21
|
+
if (!operator(value, normalizedRangeBound.value)) {
|
|
22
|
+
return RangeError(`expected a value ${description} ${normalizedRangeBound.value.toString()}, but got ${value.toString()}`);
|
|
23
23
|
}
|
|
24
24
|
return;
|
|
25
25
|
};
|
|
@@ -28,7 +28,7 @@ export const validateMultipleOf = (multipleOf, value) => {
|
|
|
28
28
|
return;
|
|
29
29
|
}
|
|
30
30
|
if (value % multipleOf !== 0) {
|
|
31
|
-
return RangeError(`expected a value that is a multiple of ${multipleOf}, but got ${value}`);
|
|
31
|
+
return RangeError(`expected a value that is a multiple of ${multipleOf.toString()}, but got ${value.toString()}`);
|
|
32
32
|
}
|
|
33
33
|
return;
|
|
34
34
|
};
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { parallelizeErrors, validateLengthRangeBound } from "../utils/validation.js";
|
|
2
2
|
export const validateObjectConstraints = (constraints, expectedKeys, value) => {
|
|
3
3
|
const label = ["property", "properties"];
|
|
4
|
+
const actualKeys = Object.keys(value);
|
|
4
5
|
return parallelizeErrors([
|
|
5
|
-
validateLengthRangeBound("lower", label, constraints.minProperties,
|
|
6
|
-
validateLengthRangeBound("upper", label, constraints.maxProperties,
|
|
6
|
+
validateLengthRangeBound("lower", label, constraints.minProperties, actualKeys),
|
|
7
|
+
validateLengthRangeBound("upper", label, constraints.maxProperties, actualKeys),
|
|
7
8
|
...(constraints.additionalProperties !== true
|
|
8
|
-
?
|
|
9
|
+
? actualKeys.flatMap(valueKey => expectedKeys.includes(valueKey)
|
|
9
10
|
? []
|
|
10
11
|
: [TypeError(`object does not allow unknown keys and key "${valueKey}" is not known`)])
|
|
11
12
|
: []),
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import { parallelizeErrors } from "../utils/validation.js";
|
|
2
2
|
export const validateStringConstraints = (constraints, value) => parallelizeErrors([
|
|
3
3
|
constraints.minLength !== undefined && value.length < constraints.minLength
|
|
4
|
-
? RangeError(`expected a string with at least ${constraints.minLength} character${constraints.minLength === 1 ? "" : "s"}, but got ${value.length} character${value.length === 1 ? "" : "s"}`)
|
|
4
|
+
? RangeError(`expected a string with at least ${constraints.minLength.toString()} character${constraints.minLength === 1 ? "" : "s"}, but got ${value.length.toString()} character${value.length === 1 ? "" : "s"}`)
|
|
5
5
|
: undefined,
|
|
6
6
|
constraints.maxLength !== undefined && value.length > constraints.maxLength
|
|
7
|
-
? RangeError(`expected a string with at most ${constraints.maxLength} character${constraints.maxLength === 1 ? "" : "s"}, but got ${value.length} character${value.length === 1 ? "" : "s"}`)
|
|
7
|
+
? RangeError(`expected a string with at most ${constraints.maxLength.toString()} character${constraints.maxLength === 1 ? "" : "s"}, but got ${value.length.toString()} character${value.length === 1 ? "" : "s"}`)
|
|
8
8
|
: undefined,
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
(() => {
|
|
10
|
+
if (constraints.pattern === undefined) {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
const pattern = typeof constraints.pattern === "string"
|
|
11
14
|
? new RegExp(constraints.pattern)
|
|
12
|
-
: constraints.pattern
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
: constraints.pattern;
|
|
16
|
+
return !pattern.test(value)
|
|
17
|
+
? TypeError(`string does not match the pattern ${pattern.toString()}`)
|
|
18
|
+
: undefined;
|
|
19
|
+
})(),
|
|
15
20
|
]);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { SerializedEntityDecl } from "../schema/declarations/EntityDecl.js";
|
|
2
|
-
import { CreateInstanceOfEntityResponseBody, DeleteInstanceOfEntityResponseBody, GetAllDeclarationsResponseBody, GetAllGitBranchesResponseBody, GetAllInstancesOfEntityResponseBody, GetAllInstancesResponseBody, GetDeclarationResponseBody, GetInstanceOfEntityResponseBody, GitStatusResponseBody, UpdateInstanceOfEntityResponseBody } from "../shared/api.js";
|
|
1
|
+
import type { SerializedEntityDecl } from "../node/schema/declarations/EntityDecl.js";
|
|
2
|
+
import type { CreateInstanceOfEntityResponseBody, DeleteInstanceOfEntityResponseBody, GetAllDeclarationsResponseBody, GetAllGitBranchesResponseBody, GetAllInstancesOfEntityResponseBody, GetAllInstancesResponseBody, GetDeclarationResponseBody, GetInstanceOfEntityResponseBody, GitStatusResponseBody, UpdateInstanceOfEntityResponseBody } from "../shared/api.js";
|
|
3
3
|
export declare const getAllDeclarations: (kind?: "Entity" | "Enum" | "TypeAlias") => Promise<GetAllDeclarationsResponseBody>;
|
|
4
4
|
export declare const getAllEntities: () => Promise<GetAllDeclarationsResponseBody<SerializedEntityDecl>>;
|
|
5
5
|
export declare const getEntityByName: (name: string) => Promise<GetDeclarationResponseBody<SerializedEntityDecl>>;
|
|
@@ -9,7 +9,7 @@ export declare const getInstanceByEntityNameAndId: (name: string, id: string) =>
|
|
|
9
9
|
export declare const updateInstanceByEntityNameAndId: (name: string, id: string, content: unknown) => Promise<UpdateInstanceOfEntityResponseBody>;
|
|
10
10
|
export declare const deleteInstanceByEntityNameAndId: (name: string, id: string) => Promise<DeleteInstanceOfEntityResponseBody>;
|
|
11
11
|
export declare const getAllInstances: (locales: string[]) => Promise<GetAllInstancesResponseBody>;
|
|
12
|
-
export declare const getGitStatus: (
|
|
12
|
+
export declare const getGitStatus: () => Promise<GitStatusResponseBody>;
|
|
13
13
|
export declare const stageAllFiles: () => Promise<void>;
|
|
14
14
|
export declare const stageAllFilesOfEntity: (entityName: string) => Promise<void>;
|
|
15
15
|
export declare const stageFileOfEntity: (entityName: string, id: string) => Promise<void>;
|
|
@@ -81,11 +81,8 @@ export const getAllInstances = async (locales) => {
|
|
|
81
81
|
}
|
|
82
82
|
return response.json();
|
|
83
83
|
};
|
|
84
|
-
export const getGitStatus = async (
|
|
84
|
+
export const getGitStatus = async () => {
|
|
85
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
86
|
const response = await fetch(url);
|
|
90
87
|
if (!response.ok) {
|
|
91
88
|
throw new Error(await response.text());
|
|
@@ -141,9 +138,10 @@ export const unstageFileOfEntity = async (entityName, id) => {
|
|
|
141
138
|
}
|
|
142
139
|
};
|
|
143
140
|
export const commitStagedFiles = async (message) => {
|
|
141
|
+
const body = { message };
|
|
144
142
|
const response = await fetch(`/api/git/commit`, {
|
|
145
143
|
method: "POST",
|
|
146
|
-
body: JSON.stringify(
|
|
144
|
+
body: JSON.stringify(body),
|
|
147
145
|
headers: {
|
|
148
146
|
"Content-Type": "application/json",
|
|
149
147
|
},
|
|
@@ -181,9 +179,10 @@ export const getBranches = async () => {
|
|
|
181
179
|
return response.json();
|
|
182
180
|
};
|
|
183
181
|
export const createBranch = async (branchName) => {
|
|
182
|
+
const body = { branchName };
|
|
184
183
|
const response = await fetch(`/api/git/branch`, {
|
|
185
184
|
method: "POST",
|
|
186
|
-
body: JSON.stringify(
|
|
185
|
+
body: JSON.stringify(body),
|
|
187
186
|
headers: {
|
|
188
187
|
"Content-Type": "application/json",
|
|
189
188
|
},
|
|
@@ -14,7 +14,7 @@ const filterFilesForDisplay = (predicate, entities, data) => Object.entries(data
|
|
|
14
14
|
.sort((a, b) => a[1].localeCompare(b[1]));
|
|
15
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
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: () => {
|
|
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
18
|
onFile(entityName, instance);
|
|
19
19
|
}, children: isIndex ? "Unstage" : "Stage" })] }, instance.fileName));
|
|
20
20
|
}) })] }, entityName))) }));
|
|
@@ -28,7 +28,7 @@ export const Git = () => {
|
|
|
28
28
|
const [entities, setEntities] = useState([]);
|
|
29
29
|
const [allBranches, setAllBranches] = useState([]);
|
|
30
30
|
const [currentBranch, setCurrentBranch] = useState("");
|
|
31
|
-
const updateGitStatus = (localEntities) => Promise.all([getGitStatus(
|
|
31
|
+
const updateGitStatus = (localEntities) => Promise.all([getGitStatus(), getBranches()]).then(([statusData, branchesData]) => {
|
|
32
32
|
setIndexFiles(filterFilesForDisplay(isChangedInIndex, localEntities, statusData));
|
|
33
33
|
setWorkingTreeFiles(filterFilesForDisplay(isChangedInWorkingDir, localEntities, statusData));
|
|
34
34
|
setCommitsAhead(statusData.commitsAhead);
|
|
@@ -37,31 +37,67 @@ export const Git = () => {
|
|
|
37
37
|
setCurrentBranch(branchesData.currentBranch);
|
|
38
38
|
});
|
|
39
39
|
useEffect(() => {
|
|
40
|
-
getAllEntities()
|
|
40
|
+
getAllEntities()
|
|
41
|
+
.then(async (data) => {
|
|
41
42
|
const entitiesFromServer = data.declarations.map(decl => decl.declaration);
|
|
42
43
|
setEntities(entitiesFromServer);
|
|
43
44
|
return updateGitStatus(entitiesFromServer);
|
|
45
|
+
})
|
|
46
|
+
.catch((error) => {
|
|
47
|
+
if (error instanceof Error) {
|
|
48
|
+
console.error("Error fetching entities:", error.toString());
|
|
49
|
+
}
|
|
44
50
|
});
|
|
45
51
|
}, []);
|
|
46
52
|
const stage = (entityName, instance) => {
|
|
47
|
-
stageFileOfEntity(entityName, instance.id)
|
|
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
|
+
});
|
|
48
60
|
};
|
|
49
61
|
const stageAll = () => {
|
|
50
|
-
stageAllFiles()
|
|
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
|
+
});
|
|
51
69
|
};
|
|
52
70
|
const unstage = (entityName, instance) => {
|
|
53
|
-
unstageFileOfEntity(entityName, instance.id)
|
|
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
|
+
});
|
|
54
78
|
};
|
|
55
79
|
const unstageAll = () => {
|
|
56
|
-
unstageAllFiles()
|
|
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
|
+
});
|
|
57
87
|
};
|
|
58
88
|
const commit = () => {
|
|
59
89
|
if (commitMessage.length > 0 &&
|
|
60
90
|
indexFiles.length > 0 &&
|
|
61
91
|
confirm("Do you want to commit all staged files?")) {
|
|
62
|
-
commitStagedFiles(commitMessage)
|
|
92
|
+
commitStagedFiles(commitMessage)
|
|
93
|
+
.then(() => {
|
|
63
94
|
setCommitMessage("");
|
|
64
95
|
return updateGitStatus(entities);
|
|
96
|
+
})
|
|
97
|
+
.catch((error) => {
|
|
98
|
+
if (error instanceof Error) {
|
|
99
|
+
console.error("Error committing instances:", error.toString());
|
|
100
|
+
}
|
|
65
101
|
});
|
|
66
102
|
}
|
|
67
103
|
};
|
|
@@ -71,7 +107,7 @@ export const Git = () => {
|
|
|
71
107
|
alert("Pushed commits successfully");
|
|
72
108
|
return updateGitStatus(entities);
|
|
73
109
|
})
|
|
74
|
-
.catch(error => {
|
|
110
|
+
.catch((error) => {
|
|
75
111
|
console.error("Error pushing commits:", error);
|
|
76
112
|
});
|
|
77
113
|
};
|
|
@@ -81,7 +117,7 @@ export const Git = () => {
|
|
|
81
117
|
alert("Pulled commits successfully");
|
|
82
118
|
return updateGitStatus(entities);
|
|
83
119
|
})
|
|
84
|
-
.catch(error => {
|
|
120
|
+
.catch((error) => {
|
|
85
121
|
console.error("Error pulling commits:", error);
|
|
86
122
|
});
|
|
87
123
|
};
|
|
@@ -99,8 +135,10 @@ export const Git = () => {
|
|
|
99
135
|
.then(() => {
|
|
100
136
|
return updateGitStatus(entities);
|
|
101
137
|
})
|
|
102
|
-
.catch(error => {
|
|
103
|
-
|
|
138
|
+
.catch((error) => {
|
|
139
|
+
if (error instanceof Error) {
|
|
140
|
+
alert("Error switching branch:" + error.toString());
|
|
141
|
+
}
|
|
104
142
|
});
|
|
105
143
|
};
|
|
106
144
|
const onSwitchBranch = (event) => {
|
|
@@ -108,9 +146,15 @@ export const Git = () => {
|
|
|
108
146
|
.then(() => {
|
|
109
147
|
return updateGitStatus(entities);
|
|
110
148
|
})
|
|
111
|
-
.catch(error => {
|
|
112
|
-
|
|
149
|
+
.catch((error) => {
|
|
150
|
+
if (error instanceof Error) {
|
|
151
|
+
alert("Error switching branch: " + error.toString());
|
|
152
|
+
}
|
|
113
153
|
});
|
|
114
154
|
};
|
|
115
|
-
return (_jsxs("aside", { class: "git", children: [_jsx("h2", { class: "h1-faded", children: "Version Control" }), _jsx("button", { onClick: () =>
|
|
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 })] })] }));
|
|
116
160
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
2
|
import { Git } from "./Git.js";
|
|
3
3
|
export const Layout = ({ breadcrumbs, 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 }) }))) }) }) }), _jsx(Git, {}), _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 })] }));
|
|
5
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 {};
|