tsondb 0.12.3 → 0.12.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/node/index.js +17 -20
- package/dist/src/node/schema/Node.d.ts +2 -2
- package/dist/src/node/schema/Node.js +3 -5
- package/dist/src/node/schema/declarations/EntityDecl.d.ts +4 -4
- package/dist/src/node/schema/types/references/IncludeIdentifierType.js +0 -3
- package/dist/src/node/server/api/declarations.js +27 -10
- package/dist/src/node/server/api/git.js +2 -5
- package/dist/src/node/server/api/instances.js +2 -3
- package/dist/src/node/server/index.d.ts +4 -3
- package/dist/src/node/server/index.js +2 -2
- package/dist/src/node/server/init.d.ts +2 -2
- package/dist/src/node/server/init.js +14 -11
- package/dist/src/node/server/utils/childInstances.d.ts +0 -3
- package/dist/src/node/server/utils/childInstances.js +2 -43
- package/dist/src/node/server/utils/instanceOperations.d.ts +3 -4
- package/dist/src/node/server/utils/instanceOperations.js +44 -84
- package/dist/src/node/utils/childInstances.d.ts +11 -10
- package/dist/src/node/utils/childInstances.js +60 -130
- package/dist/src/node/utils/databaseInMemory.d.ts +18 -0
- package/dist/src/node/utils/databaseInMemory.js +86 -0
- package/dist/src/node/utils/databaseOnDisk.d.ts +2 -0
- package/dist/src/node/utils/databaseOnDisk.js +62 -0
- package/dist/src/node/utils/databaseTransactions.d.ts +46 -0
- package/dist/src/node/utils/databaseTransactions.js +105 -0
- package/dist/src/node/utils/displayName.d.ts +3 -3
- package/dist/src/node/utils/error.d.ts +4 -0
- package/dist/src/node/utils/error.js +8 -0
- package/dist/src/node/utils/files.d.ts +4 -2
- package/dist/src/node/utils/files.js +2 -1
- package/dist/src/node/utils/git.d.ts +3 -1
- package/dist/src/node/utils/git.js +8 -2
- package/dist/src/node/utils/instanceTransactionSteps.d.ts +9 -0
- package/dist/src/node/utils/instanceTransactionSteps.js +40 -0
- package/dist/src/node/utils/references.d.ts +4 -3
- package/dist/src/node/utils/references.js +3 -2
- package/dist/src/shared/schema/declarations/EntityDecl.d.ts +2 -2
- package/dist/src/shared/utils/dictionary.d.ts +17 -0
- package/dist/src/shared/utils/dictionary.js +76 -0
- package/dist/src/shared/utils/instances.d.ts +2 -2
- package/dist/src/shared/utils/result.d.ts +4 -0
- package/dist/src/shared/utils/result.js +4 -0
- package/dist/src/web/components/InstanceRouteSkeleton.d.ts +9 -8
- package/dist/src/web/components/typeInputs/ChildEntitiesTypeInput.js +1 -1
- package/dist/src/web/hooks/useGitClient.js +0 -1
- package/dist/src/web/hooks/useMappedAPIResource.js +2 -4
- package/dist/src/web/utils/typeSkeleton.d.ts +2 -2
- package/dist/src/web/utils/typeSkeleton.js +1 -1
- package/package.json +3 -3
- package/dist/src/node/utils/instanceOperations.d.ts +0 -14
- package/dist/src/node/utils/instanceOperations.js +0 -88
- package/dist/src/node/utils/instances.d.ts +0 -6
- package/dist/src/node/utils/instances.js +0 -29
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tsondb",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.5",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "Lukas Obermann",
|
|
@@ -44,10 +44,10 @@
|
|
|
44
44
|
"prettier": "^3.6.2",
|
|
45
45
|
"tsx": "^4.20.6",
|
|
46
46
|
"typescript": "^5.9.3",
|
|
47
|
-
"typescript-eslint": "^8.
|
|
47
|
+
"typescript-eslint": "^8.48.0"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@preact/signals": "^2.5.
|
|
50
|
+
"@preact/signals": "^2.5.1",
|
|
51
51
|
"debug": "^4.4.3",
|
|
52
52
|
"express": "^5.1.0",
|
|
53
53
|
"preact": "^10.27.2",
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { InstancesByEntityName } from "../../shared/utils/instances.ts";
|
|
2
|
-
import { type Result } from "../../shared/utils/result.ts";
|
|
3
|
-
import type { EntityDecl } from "../schema/declarations/EntityDecl.js";
|
|
4
|
-
import { type ReferencesToInstances } from "./references.ts";
|
|
5
|
-
export declare const createNewId: () => `${string}-${string}-${string}-${string}-${string}`;
|
|
6
|
-
export declare const checkCreateInstancePossible: (localeEntity: EntityDecl | undefined, instancesByEntityName: InstancesByEntityName, entity: EntityDecl, instanceContent: unknown, customId: unknown) => Result<string, [code: number, message: string]>;
|
|
7
|
-
export declare const createInstance: (dataRoot: string, localeEntity: EntityDecl | undefined, instancesByEntityName: InstancesByEntityName, entity: EntityDecl, instanceContent: unknown, customId: unknown) => Promise<Result<string, [code: number, message: string]>>;
|
|
8
|
-
export declare const checkUpdateInstancePossible: (instancesByEntityName: InstancesByEntityName, entity: EntityDecl, instanceContent: unknown) => Result<void, [code: number, message: string]>;
|
|
9
|
-
export declare const checkCreateNonLocaleInstancePossible: (instancesByEntityName: InstancesByEntityName, entity: EntityDecl, instanceContent: unknown) => Result<void, [code: number, message: string]>;
|
|
10
|
-
export declare const unsafeWriteInstance: (dataRoot: string, entity: EntityDecl, instanceId: string, instanceContent: unknown) => Promise<Result<string, [code: number, message: string]>>;
|
|
11
|
-
export declare const updateInstance: (dataRoot: string, instancesByEntityName: InstancesByEntityName, entity: EntityDecl, instanceId: string, instanceContent: unknown) => Promise<Result<string, [code: number, message: string]>>;
|
|
12
|
-
export declare const checkDeleteInstancePossible: (referencesToInstances: ReferencesToInstances, instanceId: string) => Result<void, [code: number, message: string]>;
|
|
13
|
-
export declare const unsafeDeleteInstance: (dataRoot: string, entityName: string, instanceId: string) => Promise<Result<string, [code: number, message: string]>>;
|
|
14
|
-
export declare const deleteInstance: (dataRoot: string, referencesToInstances: ReferencesToInstances, entityName: string, instanceId: string) => Promise<Result<string, [code: number, message: string]>>;
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { error, isOk, map, ok } from "../../shared/utils/result.js";
|
|
3
|
-
import { createValidators, validateEntityDecl } from "../schema/index.js";
|
|
4
|
-
import { getErrorMessageForDisplay } from "./error.js";
|
|
5
|
-
import * as Files from "./files.js";
|
|
6
|
-
import { isReferencedByOtherInstances } from "./references.js";
|
|
7
|
-
export const createNewId = () => randomUUID();
|
|
8
|
-
export const checkCreateInstancePossible = (localeEntity, instancesByEntityName, entity, instanceContent, customId) => {
|
|
9
|
-
const newInstanceId = entity === localeEntity ? customId : createNewId();
|
|
10
|
-
if (typeof newInstanceId !== "string") {
|
|
11
|
-
return error([400, `New identifier "${String(newInstanceId)}" is not a string`]);
|
|
12
|
-
}
|
|
13
|
-
if (localeEntity === entity &&
|
|
14
|
-
instancesByEntityName[entity.name]?.some(instance => instance.id === newInstanceId)) {
|
|
15
|
-
return error([400, `Duplicate id "${newInstanceId}" for locale entity`]);
|
|
16
|
-
}
|
|
17
|
-
return map(checkUpdateInstancePossible(instancesByEntityName, entity, instanceContent), () => newInstanceId);
|
|
18
|
-
};
|
|
19
|
-
export const createInstance = async (dataRoot, localeEntity, instancesByEntityName, entity, instanceContent, customId) => {
|
|
20
|
-
const prerequisiteCheckResult = checkCreateInstancePossible(localeEntity, instancesByEntityName, entity, instanceContent, customId);
|
|
21
|
-
if (isOk(prerequisiteCheckResult)) {
|
|
22
|
-
const newInstanceId = prerequisiteCheckResult.value;
|
|
23
|
-
return unsafeWriteInstance(dataRoot, entity, newInstanceId, instanceContent);
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
return prerequisiteCheckResult;
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
export const checkUpdateInstancePossible = (instancesByEntityName, entity, instanceContent) => {
|
|
30
|
-
const validationErrors = validateEntityDecl(createValidators(instancesByEntityName, false), [], entity, instanceContent);
|
|
31
|
-
if (validationErrors.length > 0) {
|
|
32
|
-
return error([400, validationErrors.map(getErrorMessageForDisplay).join("\n\n")]);
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
return ok();
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
export const checkCreateNonLocaleInstancePossible = checkUpdateInstancePossible;
|
|
39
|
-
export const unsafeWriteInstance = async (dataRoot, entity, instanceId, instanceContent) => {
|
|
40
|
-
try {
|
|
41
|
-
await Files.writeInstance(dataRoot, entity, instanceId, instanceContent);
|
|
42
|
-
return ok(instanceId);
|
|
43
|
-
}
|
|
44
|
-
catch (err) {
|
|
45
|
-
return error([
|
|
46
|
-
500,
|
|
47
|
-
`Failed to write instance: ${err instanceof Error ? err.toString() : String(err)}`,
|
|
48
|
-
]);
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
export const updateInstance = async (dataRoot, instancesByEntityName, entity, instanceId, instanceContent) => {
|
|
52
|
-
const prerequisiteCheckResult = checkUpdateInstancePossible(instancesByEntityName, entity, instanceContent);
|
|
53
|
-
if (isOk(prerequisiteCheckResult)) {
|
|
54
|
-
return unsafeWriteInstance(dataRoot, entity, instanceId, instanceContent);
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
return prerequisiteCheckResult;
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
export const checkDeleteInstancePossible = (referencesToInstances, instanceId) => {
|
|
61
|
-
if (isReferencedByOtherInstances(referencesToInstances, instanceId)) {
|
|
62
|
-
return error([400, "Cannot delete instance that is referenced by other instances"]);
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
return ok();
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
export const unsafeDeleteInstance = async (dataRoot, entityName, instanceId) => {
|
|
69
|
-
try {
|
|
70
|
-
await Files.deleteInstance(dataRoot, entityName, instanceId);
|
|
71
|
-
return ok(instanceId);
|
|
72
|
-
}
|
|
73
|
-
catch (err) {
|
|
74
|
-
return error([
|
|
75
|
-
500,
|
|
76
|
-
`Failed to delete instance: ${err instanceof Error ? err.toString() : String(err)}`,
|
|
77
|
-
]);
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
export const deleteInstance = async (dataRoot, referencesToInstances, entityName, instanceId) => {
|
|
81
|
-
const prerequisiteCheckResult = checkDeleteInstancePossible(referencesToInstances, instanceId);
|
|
82
|
-
if (isOk(prerequisiteCheckResult)) {
|
|
83
|
-
return unsafeDeleteInstance(dataRoot, entityName, instanceId);
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
return prerequisiteCheckResult;
|
|
87
|
-
}
|
|
88
|
-
};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { StatusResult } from "simple-git";
|
|
2
|
-
import type { InstancesByEntityName } from "../../shared/utils/instances.ts";
|
|
3
|
-
import type { EntityDecl } from "../schema/declarations/EntityDecl.js";
|
|
4
|
-
export declare const getInstancesByEntityName: (dataRoot: string, entities: readonly EntityDecl[]) => Promise<InstancesByEntityName>;
|
|
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,29 +0,0 @@
|
|
|
1
|
-
import child_process from "node:child_process";
|
|
2
|
-
import { readdir, readFile } from "node:fs/promises";
|
|
3
|
-
import { basename, extname, join } from "node:path";
|
|
4
|
-
import { platform } from "node:process";
|
|
5
|
-
import { promisify } from "node:util";
|
|
6
|
-
import { mapAsync } from "../../shared/utils/async.js";
|
|
7
|
-
import { formatValue } from "../schema/index.js";
|
|
8
|
-
import { getFileNameForId } from "./files.js";
|
|
9
|
-
import { getGitFileStatusFromStatusResult } from "./git.js";
|
|
10
|
-
const exec = promisify(child_process.exec);
|
|
11
|
-
const ulimit = platform === "win32" ? 2048 : Number.parseInt((await exec("ulimit -n")).stdout);
|
|
12
|
-
export const getInstancesByEntityName = async (dataRoot, entities) => Object.fromEntries((await mapAsync(entities, async (entity) => {
|
|
13
|
-
const entityDir = join(dataRoot, entity.name);
|
|
14
|
-
const instanceFileNames = await readdir(entityDir);
|
|
15
|
-
const instances = await mapAsync(instanceFileNames, async (instanceFileName) => ({
|
|
16
|
-
id: basename(instanceFileName, extname(instanceFileName)),
|
|
17
|
-
content: JSON.parse(await readFile(join(entityDir, instanceFileName), "utf-8")),
|
|
18
|
-
}), ulimit);
|
|
19
|
-
return [entity.name, instances];
|
|
20
|
-
}, 1)).toSorted(([a], [b]) => a.localeCompare(b)));
|
|
21
|
-
export const attachGitStatusToInstancesByEntityName = (instancesByEntityName, dataRoot, gitRoot, gitStatus) => {
|
|
22
|
-
Object.entries(instancesByEntityName).forEach(([entityName, instances]) => {
|
|
23
|
-
instancesByEntityName[entityName] = instances.map(instanceContainer => ({
|
|
24
|
-
...instanceContainer,
|
|
25
|
-
gitStatus: getGitFileStatusFromStatusResult(gitStatus, gitRoot, dataRoot, entityName, getFileNameForId(instanceContainer.id)),
|
|
26
|
-
}));
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
export const formatInstance = (entity, instanceContent) => JSON.stringify(formatValue(entity.type.value, instanceContent), undefined, 2) + "\n";
|