tsondb 0.1.3 → 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.
Files changed (110) hide show
  1. package/lib/ModelContainer.js +9 -7
  2. package/lib/Schema.js +1 -3
  3. package/lib/client/api.d.ts +14 -1
  4. package/lib/client/api.js +119 -0
  5. package/lib/client/components/Git.d.ts +2 -0
  6. package/lib/client/components/Git.js +116 -0
  7. package/lib/client/components/Layout.js +2 -1
  8. package/lib/client/components/typeInputs/ArrayTypeInput.js +3 -2
  9. package/lib/client/components/typeInputs/EnumTypeInput.d.ts +13 -0
  10. package/lib/client/components/typeInputs/{utils/EnumDeclField.js → EnumTypeInput.js} +13 -13
  11. package/lib/client/components/typeInputs/IncludeIdentifierTypeInput.js +1 -10
  12. package/lib/client/components/typeInputs/StringTypeInput.js +8 -5
  13. package/lib/client/components/typeInputs/TypeInput.js +3 -0
  14. package/lib/client/components/typeInputs/utils/Markdown.d.ts +6 -0
  15. package/lib/client/components/typeInputs/utils/Markdown.js +26 -0
  16. package/lib/client/hooks/useAPIResource.d.ts +1 -0
  17. package/lib/client/hooks/useAPIResource.js +2 -0
  18. package/lib/client/hooks/useMappedAPIResource.d.ts +1 -0
  19. package/lib/client/hooks/useMappedAPIResource.js +19 -0
  20. package/lib/client/routes/Entity.js +18 -24
  21. package/lib/client/routes/Home.js +3 -12
  22. package/lib/client/utils/typeSkeleton.js +10 -16
  23. package/lib/renderers/jsonschema/index.d.ts +1 -1
  24. package/lib/renderers/jsonschema/index.js +30 -7
  25. package/lib/renderers/jsonschema/render.d.ts +5 -1
  26. package/lib/renderers/jsonschema/render.js +43 -16
  27. package/lib/renderers/ts/index.d.ts +1 -1
  28. package/lib/renderers/ts/index.js +37 -6
  29. package/lib/renderers/ts/render.d.ts +2 -0
  30. package/lib/renderers/ts/render.js +59 -33
  31. package/lib/schema/Node.d.ts +2 -0
  32. package/lib/schema/Node.js +7 -1
  33. package/lib/schema/declarations/Declaration.d.ts +5 -3
  34. package/lib/schema/declarations/Declaration.js +14 -10
  35. package/lib/schema/declarations/EntityDecl.d.ts +6 -0
  36. package/lib/schema/declarations/EnumDecl.d.ts +11 -8
  37. package/lib/schema/declarations/EnumDecl.js +16 -68
  38. package/lib/schema/declarations/TypeAliasDecl.d.ts +4 -0
  39. package/lib/schema/declarations/TypeAliasDecl.js +1 -1
  40. package/lib/schema/index.d.ts +1 -0
  41. package/lib/schema/index.js +1 -0
  42. package/lib/schema/types/Type.d.ts +8 -2
  43. package/lib/schema/types/Type.js +57 -11
  44. package/lib/schema/types/generic/ArrayType.d.ts +2 -1
  45. package/lib/schema/types/generic/ArrayType.js +3 -2
  46. package/lib/schema/types/generic/EnumType.d.ts +38 -0
  47. package/lib/schema/types/generic/EnumType.js +96 -0
  48. package/lib/schema/types/generic/ObjectType.d.ts +6 -1
  49. package/lib/schema/types/generic/ObjectType.js +9 -4
  50. package/lib/schema/types/primitives/BooleanType.d.ts +2 -1
  51. package/lib/schema/types/primitives/BooleanType.js +1 -0
  52. package/lib/schema/types/primitives/DateType.d.ts +2 -1
  53. package/lib/schema/types/primitives/DateType.js +1 -0
  54. package/lib/schema/types/primitives/FloatType.d.ts +2 -1
  55. package/lib/schema/types/primitives/FloatType.js +1 -0
  56. package/lib/schema/types/primitives/IntegerType.d.ts +2 -1
  57. package/lib/schema/types/primitives/IntegerType.js +1 -0
  58. package/lib/schema/types/primitives/StringType.d.ts +2 -1
  59. package/lib/schema/types/primitives/StringType.js +1 -0
  60. package/lib/schema/types/references/GenericArgumentIdentifierType.d.ts +2 -1
  61. package/lib/schema/types/references/GenericArgumentIdentifierType.js +1 -0
  62. package/lib/schema/types/references/IncludeIdentifierType.d.ts +5 -3
  63. package/lib/schema/types/references/IncludeIdentifierType.js +18 -3
  64. package/lib/schema/types/references/NestedEntityMapType.d.ts +2 -1
  65. package/lib/schema/types/references/NestedEntityMapType.js +6 -13
  66. package/lib/schema/types/references/ReferenceIdentifierType.d.ts +6 -7
  67. package/lib/schema/types/references/ReferenceIdentifierType.js +5 -2
  68. package/lib/server/api/declarations.d.ts +1 -0
  69. package/lib/server/api/declarations.js +154 -0
  70. package/lib/server/api/git.d.ts +1 -0
  71. package/lib/server/api/git.js +174 -0
  72. package/lib/server/api/index.d.ts +1 -0
  73. package/lib/server/api/index.js +8 -0
  74. package/lib/server/api/instanceOperations.d.ts +6 -0
  75. package/lib/server/api/instanceOperations.js +82 -0
  76. package/lib/server/api/instances.d.ts +1 -0
  77. package/lib/server/api/instances.js +23 -0
  78. package/lib/server/index.d.ts +22 -1
  79. package/lib/server/index.js +11 -165
  80. package/lib/server/init.d.ts +5 -0
  81. package/lib/server/init.js +56 -0
  82. package/lib/shared/api.d.ts +12 -1
  83. package/lib/shared/utils/array.d.ts +19 -0
  84. package/lib/shared/utils/array.js +27 -0
  85. package/lib/shared/utils/git.d.ts +12 -0
  86. package/lib/shared/utils/git.js +98 -0
  87. package/lib/shared/utils/instances.d.ts +10 -0
  88. package/lib/shared/utils/instances.js +8 -1
  89. package/lib/shared/utils/markdown.d.ts +14 -0
  90. package/lib/shared/utils/markdown.js +42 -0
  91. package/lib/shared/utils/object.d.ts +1 -0
  92. package/lib/shared/utils/object.js +4 -0
  93. package/lib/shared/utils/string.d.ts +1 -0
  94. package/lib/shared/utils/string.js +9 -0
  95. package/lib/tsconfig.tsbuildinfo +1 -1
  96. package/lib/utils/git.d.ts +3 -0
  97. package/lib/utils/git.js +12 -0
  98. package/lib/utils/instances.d.ts +3 -2
  99. package/lib/utils/instances.js +9 -2
  100. package/lib/utils/path.d.ts +1 -0
  101. package/lib/utils/path.js +2 -0
  102. package/lib/utils/references.d.ts +7 -0
  103. package/lib/utils/references.js +40 -0
  104. package/lib/utils/render.d.ts +6 -1
  105. package/lib/utils/render.js +27 -1
  106. package/package.json +8 -2
  107. package/public/css/styles.css +238 -1
  108. package/lib/client/components/typeInputs/utils/EnumDeclField.d.ts +0 -13
  109. package/lib/server/instanceOperations.d.ts +0 -7
  110. package/lib/server/instanceOperations.js +0 -67
@@ -1,8 +1,34 @@
1
1
  import { EOL } from "node:os";
2
+ import { mergeObjects } from "../shared/utils/object.js";
2
3
  export const prefixLines = (prefix, text, includeEmptyLines = false) => text
3
4
  .split(EOL)
4
5
  .map(line => (includeEmptyLines || line.length > 0 ? prefix + line : line))
5
6
  .join(EOL);
6
7
  export const applyIndentation = (indentLevel, text, spaces) => prefixLines(" ".repeat(spaces * indentLevel), text);
7
8
  export const joinSyntax = (...syntaxes) => syntaxes.filter(syntax => syntax !== undefined).join("");
8
- export const syntax = (strings, ...values) => strings.reduce((acc, str, i) => acc + str.replace(/\n/g, EOL) + (values[i] !== undefined ? values[i] : ""), "");
9
+ const emptyRenderResult = [{}, ""];
10
+ export const combineSyntaxes = (syntaxes, separator = "") => syntaxes
11
+ .filter(syntax => syntax !== undefined)
12
+ .reduce((acc, value, i) => typeof value === "string"
13
+ ? [acc[0], acc[1] + (i === 0 ? "" : separator) + value]
14
+ : [mergeArraysByKey(acc[0], value[0]), acc[1] + (i === 0 ? "" : separator) + value[1]], emptyRenderResult);
15
+ const mergeArraysByKey = (...arrayGroups) => arrayGroups.reduce((acc, arrayGroup) => mergeObjects(acc, arrayGroup, (a, b) => a.concat(b)), {});
16
+ export const syntax = (strings, ...values) => strings.reduce((acc, str, i) => {
17
+ const nextValue = values[i];
18
+ if (typeof nextValue === "string") {
19
+ return [acc[0], acc[1] + str.replace(/\n/g, EOL) + nextValue];
20
+ }
21
+ else if (Array.isArray(nextValue)) {
22
+ return [
23
+ mergeArraysByKey(acc[0], nextValue[0]),
24
+ acc[1] + str.replace(/\n/g, EOL) + nextValue[1],
25
+ ];
26
+ }
27
+ else {
28
+ return [acc[0], acc[1] + str.replace(/\n/g, EOL)];
29
+ }
30
+ }, emptyRenderResult);
31
+ export const indent = (spaces, indentLevel, text) => [
32
+ text[0],
33
+ prefixLines(" ".repeat(spaces * indentLevel), text[1]),
34
+ ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tsondb",
3
- "version": "0.1.3",
3
+ "version": "0.3.0",
4
4
  "description": "",
5
5
  "license": "ISC",
6
6
  "author": "Lukas Obermann",
@@ -13,7 +13,6 @@
13
13
  "exports": {
14
14
  ".": "./lib/index.js",
15
15
  "./renderer/jsonschema": "./lib/renderers/jsonschema/index.js",
16
- "./renderer/md": "./lib/renderers/md/index.js",
17
16
  "./renderer/ts": "./lib/renderers/ts/index.js",
18
17
  "./modelcontainer": "./lib/ModelContainer.js",
19
18
  "./schema": "./lib/Schema.js",
@@ -26,6 +25,7 @@
26
25
  "release": "commit-and-tag-version"
27
26
  },
28
27
  "devDependencies": {
28
+ "@types/debug": "^4.1.12",
29
29
  "@types/express": "^5.0.1",
30
30
  "@types/node": "^22.13.14",
31
31
  "commit-and-tag-version": "^12.5.1",
@@ -34,13 +34,19 @@
34
34
  "typescript": "^5.8.2"
35
35
  },
36
36
  "dependencies": {
37
+ "debug": "^4.4.0",
37
38
  "express": "^5.1.0",
38
39
  "preact": "^10.26.5",
39
40
  "preact-iso": "^2.9.1",
41
+ "simple-git": "^3.27.0",
42
+ "supports-color": "^10.0.0",
40
43
  "uuid": "^11.1.0"
41
44
  },
42
45
  "repository": "github:elyukai/tsondb",
43
46
  "bugs": {
44
47
  "url": "https://github.com/elyukai/tsondb/issues"
48
+ },
49
+ "engines": {
50
+ "node": ">=21.2.0"
45
51
  }
46
52
  }
@@ -9,6 +9,7 @@
9
9
  "Courier New", monospace;
10
10
  --font-serif: ui-serif, Georgia, Cambria, "Times New Roman", Times, serif;
11
11
  --background: white;
12
+ --markdown-background: #e1e3e7;
12
13
  --color: black;
13
14
  --error-color: #9d1212;
14
15
  --separator-color: #e9e5eb;
@@ -39,6 +40,28 @@ body {
39
40
  padding: 1.5rem;
40
41
  line-height: 1.4;
41
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;
42
65
  }
43
66
 
44
67
  header nav ol {
@@ -49,6 +72,10 @@ header nav ol {
49
72
  margin: 0;
50
73
  }
51
74
 
75
+ main {
76
+ grid-area: main;
77
+ }
78
+
52
79
  h1 {
53
80
  margin: 2rem 0 1.5rem;
54
81
  font-size: 2.5rem;
@@ -67,6 +94,18 @@ h1 .id {
67
94
  margin-top: 0.25rem;
68
95
  }
69
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
+
70
109
  a {
71
110
  color: var(--color);
72
111
  }
@@ -137,7 +176,9 @@ button.destructive:disabled {
137
176
  cursor: not-allowed;
138
177
  }
139
178
 
140
- input, select {
179
+ input,
180
+ textarea,
181
+ select {
141
182
  font-family: var(--font-sans);
142
183
  border: 1px solid var(--color);
143
184
  padding: 0.5rem;
@@ -149,6 +190,7 @@ input, select {
149
190
  }
150
191
 
151
192
  input[aria-invalid="true"],
193
+ textarea[aria-invalid="true"],
152
194
  select[aria-invalid="true"] {
153
195
  border-color: var(--error-color);
154
196
  color: var(--error-color);
@@ -181,6 +223,11 @@ input[type="checkbox"]:checked::before {
181
223
  margin: calc(-0.2rem - 1px) 0 0 calc(-0.275rem - 1px);
182
224
  }
183
225
 
226
+ textarea {
227
+ min-height: 5rem;
228
+ resize: vertical;
229
+ }
230
+
184
231
  .select-wrapper {
185
232
  position: relative;
186
233
  }
@@ -364,6 +411,34 @@ form > .field--container {
364
411
  padding-bottom: 0;
365
412
  }
366
413
 
414
+ .field--string {
415
+ display: flex;
416
+ gap: 1rem;
417
+ align-items: start;
418
+ }
419
+
420
+ .field--string .editor {
421
+ flex: 1 1 0;
422
+ }
423
+
424
+ .field--string .preview {
425
+ padding: 1rem;
426
+ background: var(--markdown-background);
427
+ flex: 1 1 0;
428
+ }
429
+
430
+ .field--string .preview p {
431
+ margin: 0.5rem 0 0;
432
+ }
433
+
434
+ .field--string .preview > :first-child {
435
+ margin-top: 0;
436
+ }
437
+
438
+ .field--string .preview > :last-child {
439
+ margin-bottom: 0;
440
+ }
441
+
367
442
  .container-item-header {
368
443
  display: flex;
369
444
  align-items: center;
@@ -416,3 +491,165 @@ button[type="submit"] {
416
491
  color: var(--secondary-color);
417
492
  margin: 0.5rem 0 0;
418
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
- };