tsondb 0.2.0 → 0.3.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/lib/ModelContainer.js +9 -7
- package/lib/client/api.d.ts +14 -1
- package/lib/client/api.js +119 -0
- package/lib/client/components/Git.d.ts +2 -0
- package/lib/client/components/Git.js +116 -0
- package/lib/client/components/Layout.js +2 -1
- package/lib/client/components/typeInputs/ArrayTypeInput.js +2 -1
- package/lib/client/components/typeInputs/EnumTypeInput.d.ts +13 -0
- package/lib/client/components/typeInputs/{utils/EnumDeclField.js → EnumTypeInput.js} +10 -10
- package/lib/client/components/typeInputs/IncludeIdentifierTypeInput.js +1 -10
- package/lib/client/components/typeInputs/TypeInput.js +3 -0
- package/lib/client/components/typeInputs/utils/Markdown.js +1 -32
- package/lib/client/hooks/useAPIResource.d.ts +1 -0
- package/lib/client/hooks/useAPIResource.js +2 -0
- package/lib/client/hooks/useMappedAPIResource.d.ts +1 -0
- package/lib/client/hooks/useMappedAPIResource.js +19 -0
- package/lib/client/routes/Entity.js +18 -24
- package/lib/client/routes/Home.js +3 -12
- package/lib/client/utils/typeSkeleton.js +10 -16
- package/lib/renderers/jsonschema/index.d.ts +1 -1
- package/lib/renderers/jsonschema/index.js +30 -7
- package/lib/renderers/jsonschema/render.d.ts +5 -1
- package/lib/renderers/jsonschema/render.js +35 -16
- package/lib/renderers/ts/index.d.ts +1 -1
- package/lib/renderers/ts/index.js +37 -6
- package/lib/renderers/ts/render.d.ts +2 -0
- package/lib/renderers/ts/render.js +55 -32
- package/lib/schema/Node.d.ts +1 -0
- package/lib/schema/Node.js +6 -1
- package/lib/schema/declarations/Declaration.d.ts +3 -1
- package/lib/schema/declarations/Declaration.js +4 -0
- package/lib/schema/declarations/EntityDecl.d.ts +3 -0
- package/lib/schema/declarations/EnumDecl.d.ts +4 -21
- package/lib/schema/declarations/EnumDecl.js +16 -79
- package/lib/schema/index.d.ts +1 -0
- package/lib/schema/index.js +1 -0
- package/lib/schema/types/Type.d.ts +8 -2
- package/lib/schema/types/Type.js +57 -11
- package/lib/schema/types/generic/ArrayType.d.ts +2 -1
- package/lib/schema/types/generic/ArrayType.js +2 -1
- package/lib/schema/types/generic/EnumType.d.ts +38 -0
- package/lib/schema/types/generic/EnumType.js +96 -0
- package/lib/schema/types/generic/ObjectType.d.ts +2 -1
- package/lib/schema/types/generic/ObjectType.js +4 -0
- package/lib/schema/types/primitives/BooleanType.d.ts +2 -1
- package/lib/schema/types/primitives/BooleanType.js +1 -0
- package/lib/schema/types/primitives/DateType.d.ts +2 -1
- package/lib/schema/types/primitives/DateType.js +1 -0
- package/lib/schema/types/primitives/FloatType.d.ts +2 -1
- package/lib/schema/types/primitives/FloatType.js +1 -0
- package/lib/schema/types/primitives/IntegerType.d.ts +2 -1
- package/lib/schema/types/primitives/IntegerType.js +1 -0
- package/lib/schema/types/primitives/StringType.d.ts +2 -1
- package/lib/schema/types/primitives/StringType.js +1 -0
- package/lib/schema/types/references/GenericArgumentIdentifierType.d.ts +2 -1
- package/lib/schema/types/references/GenericArgumentIdentifierType.js +1 -0
- package/lib/schema/types/references/IncludeIdentifierType.d.ts +5 -3
- package/lib/schema/types/references/IncludeIdentifierType.js +15 -2
- package/lib/schema/types/references/NestedEntityMapType.d.ts +2 -1
- package/lib/schema/types/references/NestedEntityMapType.js +5 -1
- package/lib/schema/types/references/ReferenceIdentifierType.d.ts +2 -1
- package/lib/schema/types/references/ReferenceIdentifierType.js +2 -1
- package/lib/server/api/declarations.d.ts +1 -0
- package/lib/server/api/declarations.js +154 -0
- package/lib/server/api/git.d.ts +1 -0
- package/lib/server/api/git.js +174 -0
- package/lib/server/api/index.d.ts +1 -0
- package/lib/server/api/index.js +8 -0
- package/lib/server/api/instanceOperations.d.ts +6 -0
- package/lib/server/api/instanceOperations.js +82 -0
- package/lib/server/api/instances.d.ts +1 -0
- package/lib/server/api/instances.js +23 -0
- package/lib/server/index.d.ts +22 -1
- package/lib/server/index.js +11 -165
- package/lib/server/init.d.ts +5 -0
- package/lib/server/init.js +56 -0
- package/lib/shared/api.d.ts +12 -1
- package/lib/shared/utils/array.d.ts +19 -0
- package/lib/shared/utils/array.js +27 -0
- 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/shared/utils/markdown.d.ts +14 -0
- package/lib/shared/utils/markdown.js +42 -0
- package/lib/shared/utils/object.d.ts +1 -0
- package/lib/shared/utils/object.js +4 -0
- package/lib/shared/utils/string.d.ts +1 -0
- package/lib/shared/utils/string.js +9 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/utils/git.d.ts +3 -0
- package/lib/utils/git.js +12 -0
- package/lib/utils/instances.d.ts +3 -2
- package/lib/utils/instances.js +9 -2
- package/lib/utils/path.d.ts +1 -0
- package/lib/utils/path.js +2 -0
- package/lib/utils/references.d.ts +7 -0
- package/lib/utils/references.js +40 -0
- package/lib/utils/render.d.ts +6 -1
- package/lib/utils/render.js +27 -1
- package/package.json +8 -1
- package/public/css/styles.css +200 -1
- package/lib/client/components/typeInputs/utils/EnumDeclField.d.ts +0 -13
- package/lib/server/instanceOperations.d.ts +0 -7
- package/lib/server/instanceOperations.js +0 -67
package/public/css/styles.css
CHANGED
|
@@ -40,6 +40,28 @@ body {
|
|
|
40
40
|
padding: 1.5rem;
|
|
41
41
|
line-height: 1.4;
|
|
42
42
|
background: var(--background);
|
|
43
|
+
z-index: 1;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
#app {
|
|
47
|
+
display: grid;
|
|
48
|
+
grid-template-columns: 1fr auto;
|
|
49
|
+
grid-template-areas: "header aside" "main main";
|
|
50
|
+
gap: 0 1rem;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@media (min-width: 80rem) {
|
|
54
|
+
#app {
|
|
55
|
+
grid-template-columns: 1fr auto;
|
|
56
|
+
grid-template-areas: "header header" "main aside";
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
header {
|
|
61
|
+
display: flex;
|
|
62
|
+
justify-content: space-between;
|
|
63
|
+
align-items: center;
|
|
64
|
+
grid-area: header;
|
|
43
65
|
}
|
|
44
66
|
|
|
45
67
|
header nav ol {
|
|
@@ -50,6 +72,10 @@ header nav ol {
|
|
|
50
72
|
margin: 0;
|
|
51
73
|
}
|
|
52
74
|
|
|
75
|
+
main {
|
|
76
|
+
grid-area: main;
|
|
77
|
+
}
|
|
78
|
+
|
|
53
79
|
h1 {
|
|
54
80
|
margin: 2rem 0 1.5rem;
|
|
55
81
|
font-size: 2.5rem;
|
|
@@ -68,6 +94,18 @@ h1 .id {
|
|
|
68
94
|
margin-top: 0.25rem;
|
|
69
95
|
}
|
|
70
96
|
|
|
97
|
+
h2 {
|
|
98
|
+
margin: 1.8rem 0 1.25rem;
|
|
99
|
+
font-size: 1.75rem;
|
|
100
|
+
line-height: 1.1;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
h2.h1-faded {
|
|
104
|
+
margin: 2rem 0 1.5rem;
|
|
105
|
+
font-size: 2.5rem;
|
|
106
|
+
color: var(--tertiary-color);
|
|
107
|
+
}
|
|
108
|
+
|
|
71
109
|
a {
|
|
72
110
|
color: var(--color);
|
|
73
111
|
}
|
|
@@ -389,7 +427,6 @@ form > .field--container {
|
|
|
389
427
|
flex: 1 1 0;
|
|
390
428
|
}
|
|
391
429
|
|
|
392
|
-
|
|
393
430
|
.field--string .preview p {
|
|
394
431
|
margin: 0.5rem 0 0;
|
|
395
432
|
}
|
|
@@ -454,3 +491,165 @@ button[type="submit"] {
|
|
|
454
491
|
color: var(--secondary-color);
|
|
455
492
|
margin: 0.5rem 0 0;
|
|
456
493
|
}
|
|
494
|
+
|
|
495
|
+
.git-status {
|
|
496
|
+
width: 1.75rem;
|
|
497
|
+
height: 1.75rem;
|
|
498
|
+
border-radius: 2px;
|
|
499
|
+
text-align: center;
|
|
500
|
+
line-height: 1.75rem;
|
|
501
|
+
margin: 0;
|
|
502
|
+
font-weight: 600;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
.instance-item .git-status {
|
|
506
|
+
margin-top: 0.3rem;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
.git-status.git-status--U {
|
|
510
|
+
color: rgb(13, 149, 101);
|
|
511
|
+
background: rgba(13, 149, 101, 0.15);
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
.git-status.git-status--A {
|
|
515
|
+
color: rgb(20, 148, 29);
|
|
516
|
+
background: rgba(20, 148, 29, 0.15);
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
.git-status.git-status--M {
|
|
520
|
+
color: rgb(196, 155, 18);
|
|
521
|
+
background: rgba(196, 155, 18, 0.15);
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
.git-status.git-status--D {
|
|
525
|
+
color: rgb(135, 22, 11);
|
|
526
|
+
background: rgba(135, 22, 11, 0.15);
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
.git-status.git-status--R {
|
|
530
|
+
color: rgb(20, 97, 148);
|
|
531
|
+
background: rgba(20, 97, 148, 0.15);
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
aside.git {
|
|
535
|
+
max-width: 30rem;
|
|
536
|
+
grid-area: aside;
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
aside.git h2 {
|
|
540
|
+
display: none;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
@media (min-width: 80rem) {
|
|
544
|
+
aside.git {
|
|
545
|
+
border-left: 1px solid var(--separator-color);
|
|
546
|
+
padding-left: 1rem;
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
aside.git h2 {
|
|
550
|
+
display: block;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
aside.git > button {
|
|
554
|
+
display: none;
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
aside.git h3 {
|
|
559
|
+
font-size: 1.25rem;
|
|
560
|
+
margin: 0;
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
aside.git ul {
|
|
564
|
+
list-style-type: " ";
|
|
565
|
+
padding: 0;
|
|
566
|
+
margin: 0;
|
|
567
|
+
display: block;
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
aside.git .git-entity-list-item > .title {
|
|
571
|
+
margin: 1rem 0 0.5rem;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
aside.git .git-instance-list-item {
|
|
575
|
+
display: flex;
|
|
576
|
+
justify-content: space-between;
|
|
577
|
+
margin: 0.25rem 0 0;
|
|
578
|
+
gap: 0.25rem;
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
aside.git li .title {
|
|
582
|
+
display: block;
|
|
583
|
+
margin: 0.25rem 0;
|
|
584
|
+
flex: 1 1 0;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
aside.git li.git-entity-list-item > .title {
|
|
588
|
+
font-weight: 600;
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
aside.git li button {
|
|
592
|
+
padding: 0 0.5rem;
|
|
593
|
+
line-height: 1.75rem;
|
|
594
|
+
height: 1.75rem;
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
aside.git .git-section-title {
|
|
598
|
+
display: flex;
|
|
599
|
+
justify-content: space-between;
|
|
600
|
+
align-items: center;
|
|
601
|
+
gap: 0.5rem;
|
|
602
|
+
margin: 1rem 0 0.5rem;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
aside.git .git-section-title h2 {
|
|
606
|
+
margin: 0;
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
aside.git p.no-changes {
|
|
610
|
+
color: var(--tertiary-color);
|
|
611
|
+
margin: 0;
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
aside.git .commit,
|
|
615
|
+
aside.git .sync,
|
|
616
|
+
aside.git .branch {
|
|
617
|
+
display: flex;
|
|
618
|
+
gap: 0.5rem;
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
aside.git .sync,
|
|
622
|
+
aside.git .branch {
|
|
623
|
+
margin-bottom: 1rem;
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
aside.git .commit input,
|
|
627
|
+
aside.git .branch .select-wrapper {
|
|
628
|
+
flex: 1 1 0;
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
.git-overlay {
|
|
632
|
+
display: none;
|
|
633
|
+
position: absolute;
|
|
634
|
+
right: 1.5rem;
|
|
635
|
+
box-shadow: 0 0.5rem 2rem rgba(160, 163, 165, 0.5);
|
|
636
|
+
z-index: 1000;
|
|
637
|
+
padding: 1rem;
|
|
638
|
+
background: var(--background);
|
|
639
|
+
overflow-y: auto;
|
|
640
|
+
max-height: calc(90vh - 5rem);
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
@media (min-width: 80rem) {
|
|
644
|
+
.git-overlay {
|
|
645
|
+
display: block;
|
|
646
|
+
position: static;
|
|
647
|
+
box-shadow: none;
|
|
648
|
+
padding: 0.5rem 0 0;
|
|
649
|
+
max-height: none;
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
.git-overlay.git-overlay--open {
|
|
654
|
+
display: block;
|
|
655
|
+
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { FunctionComponent } from "preact";
|
|
2
|
-
import { SerializedEnumDecl } from "../../../../schema/declarations/EnumDecl.js";
|
|
3
|
-
import { InstanceNamesByEntity } from "../../../hooks/useInstanceNamesByEntity.js";
|
|
4
|
-
import { GetDeclFromDeclName } from "../../../hooks/useSecondaryDeclarations.js";
|
|
5
|
-
type Props = {
|
|
6
|
-
decl: SerializedEnumDecl;
|
|
7
|
-
value: unknown;
|
|
8
|
-
instanceNamesByEntity: InstanceNamesByEntity;
|
|
9
|
-
getDeclFromDeclName: GetDeclFromDeclName;
|
|
10
|
-
onChange: (value: unknown) => void;
|
|
11
|
-
};
|
|
12
|
-
export declare const EnumDeclField: FunctionComponent<Props>;
|
|
13
|
-
export {};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { ModelContainer } from "../ModelContainer.js";
|
|
2
|
-
import { EntityDecl } from "../schema/declarations/EntityDecl.js";
|
|
3
|
-
import { InstanceContainer, InstancesByEntityName } from "../shared/utils/instances.js";
|
|
4
|
-
import { Result } from "../utils/result.js";
|
|
5
|
-
export declare const createInstance: (modelContainer: ModelContainer, entitiesByName: Record<string, EntityDecl>, instancesByEntityName: InstancesByEntityName, entityName: string, instance: unknown, idQueryParam: unknown) => Promise<Result<InstanceContainer, [code: number, message: string]>>;
|
|
6
|
-
export declare const updateInstance: (modelContainer: ModelContainer, entitiesByName: Record<string, EntityDecl>, instancesByEntityName: InstancesByEntityName, entityName: string, id: string, instance: unknown) => Promise<Result<InstanceContainer, [code: number, message: string]>>;
|
|
7
|
-
export declare const deleteInstance: (modelContainer: ModelContainer, instancesByEntityName: InstancesByEntityName, entityName: string, id: string) => Promise<Result<InstanceContainer, [code: number, message: string]>>;
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { rm, writeFile } from "node:fs/promises";
|
|
2
|
-
import { join } from "node:path";
|
|
3
|
-
import { v4 as uuidv4 } from "uuid";
|
|
4
|
-
import { validateEntityDecl } from "../schema/declarations/EntityDecl.js";
|
|
5
|
-
import { createValidators } from "../schema/Node.js";
|
|
6
|
-
import { getErrorMessageForDisplay } from "../utils/error.js";
|
|
7
|
-
import { error, ok } from "../utils/result.js";
|
|
8
|
-
export const createInstance = async (modelContainer, entitiesByName, instancesByEntityName, entityName, instance, idQueryParam) => {
|
|
9
|
-
const entity = entitiesByName[entityName];
|
|
10
|
-
const validationErrors = validateEntityDecl(createValidators(instancesByEntityName), entity, instance);
|
|
11
|
-
if (validationErrors.length > 0) {
|
|
12
|
-
return error([400, validationErrors.map(getErrorMessageForDisplay).join("\n\n")]);
|
|
13
|
-
}
|
|
14
|
-
if (modelContainer.schema.localeEntity === entity && typeof idQueryParam !== "string") {
|
|
15
|
-
return error([400, "Missing id for locale entity"]);
|
|
16
|
-
}
|
|
17
|
-
const id = modelContainer.schema.localeEntity === entity ? idQueryParam : uuidv4();
|
|
18
|
-
if (modelContainer.schema.localeEntity === entity &&
|
|
19
|
-
instancesByEntityName[entity.name].some(instance => instance.id === id)) {
|
|
20
|
-
return error([400, `Duplicate id "${id}" for locale entity`]);
|
|
21
|
-
}
|
|
22
|
-
const fileName = `${id}.json`;
|
|
23
|
-
await writeFile(join(modelContainer.dataRootPath, entity.name, fileName), JSON.stringify(instance, undefined, 2), { encoding: "utf-8" });
|
|
24
|
-
const instanceContainer = {
|
|
25
|
-
fileName,
|
|
26
|
-
id,
|
|
27
|
-
content: instance,
|
|
28
|
-
};
|
|
29
|
-
instancesByEntityName[entity.name] = [
|
|
30
|
-
...(instancesByEntityName[entity.name] ?? []),
|
|
31
|
-
instanceContainer,
|
|
32
|
-
];
|
|
33
|
-
return ok(instanceContainer);
|
|
34
|
-
};
|
|
35
|
-
export const updateInstance = async (modelContainer, entitiesByName, instancesByEntityName, entityName, id, instance) => {
|
|
36
|
-
const instanceContainer = instancesByEntityName[entityName]?.find(instance => instance.id === id);
|
|
37
|
-
if (instanceContainer === undefined) {
|
|
38
|
-
return error([404, "Instance not found"]);
|
|
39
|
-
}
|
|
40
|
-
const entity = entitiesByName[entityName];
|
|
41
|
-
const validationErrors = validateEntityDecl(createValidators(instancesByEntityName), entity, instance);
|
|
42
|
-
if (validationErrors.length > 0) {
|
|
43
|
-
return error([400, validationErrors.map(getErrorMessageForDisplay).join("\n\n")]);
|
|
44
|
-
}
|
|
45
|
-
await writeFile(join(modelContainer.dataRootPath, entity.name, instanceContainer.fileName), JSON.stringify(instance, undefined, 2), { encoding: "utf-8" });
|
|
46
|
-
instanceContainer.content = instance;
|
|
47
|
-
return ok(instanceContainer);
|
|
48
|
-
};
|
|
49
|
-
export const deleteInstance = async (modelContainer, instancesByEntityName, entityName, id) => {
|
|
50
|
-
const instances = instancesByEntityName[entityName] ?? [];
|
|
51
|
-
const instanceContainerIndex = instances.findIndex(instance => instance.id === id);
|
|
52
|
-
const instanceContainer = instances[instanceContainerIndex];
|
|
53
|
-
if (instanceContainer === undefined) {
|
|
54
|
-
return error([404, "Instance not found"]);
|
|
55
|
-
}
|
|
56
|
-
try {
|
|
57
|
-
await rm(join(modelContainer.dataRootPath, entityName, instanceContainer.fileName));
|
|
58
|
-
instancesByEntityName[entityName] = [
|
|
59
|
-
...instances.slice(0, instanceContainerIndex),
|
|
60
|
-
...instances.slice(instanceContainerIndex + 1),
|
|
61
|
-
];
|
|
62
|
-
return ok(instanceContainer);
|
|
63
|
-
}
|
|
64
|
-
catch (err) {
|
|
65
|
-
return error([500, `Failed to delete instance: ${err}`]);
|
|
66
|
-
}
|
|
67
|
-
};
|