tsondb 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (228) hide show
  1. package/LICENSE +385 -0
  2. package/README.md +173 -1
  3. package/lib/bin/tsondb.d.ts +8 -0
  4. package/lib/bin/tsondb.js +83 -0
  5. package/lib/index.d.ts +2 -1
  6. package/lib/index.js +1 -1
  7. package/lib/{Schema.d.ts → node/Schema.d.ts} +2 -2
  8. package/lib/{Schema.js → node/Schema.js} +1 -1
  9. package/lib/node/index.d.ts +8 -0
  10. package/lib/node/index.js +62 -0
  11. package/lib/{renderers → node/renderers}/Output.d.ts +1 -1
  12. package/lib/node/renderers/jsonschema/index.d.ts +6 -0
  13. package/lib/node/renderers/jsonschema/index.js +35 -0
  14. package/lib/node/renderers/jsonschema/render.d.ts +9 -0
  15. package/lib/{renderers → node/renderers}/jsonschema/render.js +42 -23
  16. package/lib/node/renderers/ts/index.d.ts +6 -0
  17. package/lib/node/renderers/ts/index.js +42 -0
  18. package/lib/{renderers → node/renderers}/ts/render.d.ts +3 -1
  19. package/lib/node/renderers/ts/render.js +136 -0
  20. package/lib/{schema → node/schema}/Node.d.ts +5 -4
  21. package/lib/{schema → node/schema}/Node.js +11 -6
  22. package/lib/{schema/parameters → node/schema}/TypeParameter.d.ts +3 -2
  23. package/lib/{schema/parameters → node/schema}/TypeParameter.js +2 -2
  24. package/lib/{schema → node/schema}/declarations/Declaration.d.ts +11 -10
  25. package/lib/{schema → node/schema}/declarations/Declaration.js +10 -4
  26. package/lib/{schema → node/schema}/declarations/EntityDecl.d.ts +13 -9
  27. package/lib/{schema → node/schema}/declarations/EntityDecl.js +2 -2
  28. package/lib/{schema → node/schema}/declarations/EnumDecl.d.ts +11 -26
  29. package/lib/node/schema/declarations/EnumDecl.js +52 -0
  30. package/lib/{schema → node/schema}/declarations/TypeAliasDecl.d.ts +8 -7
  31. package/lib/{schema → node/schema}/declarations/TypeAliasDecl.js +3 -3
  32. package/lib/{schema → node/schema}/index.d.ts +4 -3
  33. package/lib/{schema → node/schema}/index.js +3 -3
  34. package/lib/node/schema/types/Type.d.ts +48 -0
  35. package/lib/{schema → node/schema}/types/Type.js +90 -28
  36. package/lib/{schema → node/schema}/types/generic/ArrayType.d.ts +6 -4
  37. package/lib/{schema → node/schema}/types/generic/ArrayType.js +5 -4
  38. package/lib/node/schema/types/generic/EnumType.d.ts +39 -0
  39. package/lib/node/schema/types/generic/EnumType.js +98 -0
  40. package/lib/{schema → node/schema}/types/generic/ObjectType.d.ts +9 -7
  41. package/lib/{schema → node/schema}/types/generic/ObjectType.js +11 -3
  42. package/lib/{schema → node/schema}/types/primitives/BooleanType.d.ts +5 -3
  43. package/lib/{schema → node/schema}/types/primitives/BooleanType.js +1 -0
  44. package/lib/{schema → node/schema}/types/primitives/DateType.d.ts +6 -4
  45. package/lib/{schema → node/schema}/types/primitives/DateType.js +2 -1
  46. package/lib/{schema → node/schema}/types/primitives/FloatType.d.ts +6 -4
  47. package/lib/{schema → node/schema}/types/primitives/FloatType.js +2 -1
  48. package/lib/{schema → node/schema}/types/primitives/IntegerType.d.ts +6 -4
  49. package/lib/{schema → node/schema}/types/primitives/IntegerType.js +2 -1
  50. package/lib/{schema → node/schema}/types/primitives/NumericType.d.ts +2 -2
  51. package/lib/node/schema/types/primitives/PrimitiveType.d.ts +6 -0
  52. package/lib/{schema → node/schema}/types/primitives/StringType.d.ts +6 -4
  53. package/lib/{schema → node/schema}/types/primitives/StringType.js +2 -1
  54. package/lib/{schema → node/schema}/types/references/IncludeIdentifierType.d.ts +11 -8
  55. package/lib/{schema → node/schema}/types/references/IncludeIdentifierType.js +15 -2
  56. package/lib/{schema → node/schema}/types/references/NestedEntityMapType.d.ts +11 -9
  57. package/lib/{schema → node/schema}/types/references/NestedEntityMapType.js +6 -2
  58. package/lib/{schema → node/schema}/types/references/ReferenceIdentifierType.d.ts +8 -6
  59. package/lib/{schema → node/schema}/types/references/ReferenceIdentifierType.js +1 -0
  60. package/lib/node/schema/types/references/TypeArgumentType.d.ts +23 -0
  61. package/lib/node/schema/types/references/TypeArgumentType.js +19 -0
  62. package/lib/node/schema/validation/type.d.ts +4 -0
  63. package/lib/node/server/api/declarations.d.ts +1 -0
  64. package/lib/node/server/api/declarations.js +154 -0
  65. package/lib/node/server/api/git.d.ts +1 -0
  66. package/lib/node/server/api/git.js +178 -0
  67. package/lib/node/server/api/index.d.ts +1 -0
  68. package/lib/node/server/api/index.js +8 -0
  69. package/lib/node/server/api/instanceOperations.d.ts +6 -0
  70. package/lib/node/server/api/instanceOperations.js +91 -0
  71. package/lib/node/server/api/instances.d.ts +1 -0
  72. package/lib/node/server/api/instances.js +27 -0
  73. package/lib/node/server/index.d.ts +28 -0
  74. package/lib/node/server/index.js +53 -0
  75. package/lib/node/server/init.d.ts +5 -0
  76. package/lib/node/server/init.js +56 -0
  77. package/lib/{utils → node/utils}/error.js +4 -1
  78. package/lib/node/utils/git.d.ts +3 -0
  79. package/lib/node/utils/git.js +12 -0
  80. package/lib/node/utils/instances.d.ts +5 -0
  81. package/lib/node/utils/instances.js +21 -0
  82. package/lib/node/utils/path.d.ts +1 -0
  83. package/lib/node/utils/path.js +2 -0
  84. package/lib/node/utils/references.d.ts +7 -0
  85. package/lib/node/utils/references.js +40 -0
  86. package/lib/node/utils/render.d.ts +9 -0
  87. package/lib/node/utils/render.js +34 -0
  88. package/lib/shared/api.d.ts +19 -2
  89. package/lib/shared/utils/array.d.ts +19 -0
  90. package/lib/shared/utils/array.js +30 -0
  91. package/lib/shared/utils/displayName.d.ts +1 -1
  92. package/lib/shared/utils/displayName.js +4 -2
  93. package/lib/shared/utils/git.d.ts +12 -0
  94. package/lib/shared/utils/git.js +98 -0
  95. package/lib/shared/utils/instances.d.ts +10 -0
  96. package/lib/shared/utils/instances.js +8 -1
  97. package/lib/{utils → shared/utils}/lazy.js +1 -1
  98. package/lib/shared/utils/markdown.d.ts +14 -0
  99. package/lib/shared/utils/markdown.js +42 -0
  100. package/lib/shared/utils/object.d.ts +4 -0
  101. package/lib/shared/utils/object.js +5 -0
  102. package/lib/{utils → shared/utils}/result.js +2 -2
  103. package/lib/shared/utils/string.d.ts +1 -0
  104. package/lib/shared/utils/string.js +16 -4
  105. package/lib/shared/utils/validation.js +3 -2
  106. package/lib/shared/validation/number.js +3 -3
  107. package/lib/shared/validation/object.js +4 -3
  108. package/lib/shared/validation/string.js +12 -7
  109. package/lib/web/api.d.ts +24 -0
  110. package/lib/web/api.js +204 -0
  111. package/lib/web/components/Git.d.ts +2 -0
  112. package/lib/web/components/Git.js +160 -0
  113. package/lib/{client → web}/components/Layout.d.ts +1 -1
  114. package/lib/{client → web}/components/Layout.js +2 -1
  115. package/lib/web/components/Select.d.ts +3 -0
  116. package/lib/web/components/Select.js +5 -0
  117. package/lib/web/components/typeInputs/ArrayTypeInput.d.ts +13 -0
  118. package/lib/{client → web}/components/typeInputs/ArrayTypeInput.js +8 -1
  119. package/lib/{client → web}/components/typeInputs/BooleanTypeInput.d.ts +2 -2
  120. package/lib/{client → web}/components/typeInputs/DateTypeInput.d.ts +2 -2
  121. package/lib/web/components/typeInputs/EnumTypeInput.d.ts +13 -0
  122. package/lib/{client/components/typeInputs/utils/EnumDeclField.js → web/components/typeInputs/EnumTypeInput.js} +11 -11
  123. package/lib/{client → web}/components/typeInputs/FloatTypeInput.d.ts +2 -2
  124. package/lib/web/components/typeInputs/GenericTypeArgumentIdentifierTypeInput.d.ts +7 -0
  125. package/lib/{client → web}/components/typeInputs/GenericTypeArgumentIdentifierTypeInput.js +1 -1
  126. package/lib/web/components/typeInputs/IncludeIdentifierTypeInput.d.ts +13 -0
  127. package/lib/web/components/typeInputs/IncludeIdentifierTypeInput.js +9 -0
  128. package/lib/{client → web}/components/typeInputs/IntegerTypeInput.d.ts +2 -2
  129. package/lib/web/components/typeInputs/NestedEntityMapTypeInput.d.ts +13 -0
  130. package/lib/{client → web}/components/typeInputs/NestedEntityMapTypeInput.js +7 -2
  131. package/lib/{client → web}/components/typeInputs/ObjectTypeInput.d.ts +4 -4
  132. package/lib/{client → web}/components/typeInputs/ObjectTypeInput.js +4 -1
  133. package/lib/{client → web}/components/typeInputs/ReferenceIdentifierTypeInput.d.ts +3 -3
  134. package/lib/web/components/typeInputs/ReferenceIdentifierTypeInput.js +11 -0
  135. package/lib/{client → web}/components/typeInputs/StringTypeInput.d.ts +2 -2
  136. package/lib/web/components/typeInputs/TypeInput.d.ts +13 -0
  137. package/lib/{client → web}/components/typeInputs/TypeInput.js +6 -3
  138. package/lib/{client → web}/components/typeInputs/utils/Markdown.d.ts +1 -1
  139. package/lib/web/components/typeInputs/utils/Markdown.js +26 -0
  140. package/lib/{client → web}/components/typeInputs/utils/MismatchingTypeError.d.ts +1 -1
  141. package/lib/{client → web}/components/typeInputs/utils/ValidationErrors.d.ts +1 -1
  142. package/lib/web/hooks/useAPIResource.d.ts +1 -0
  143. package/lib/web/hooks/useAPIResource.js +2 -0
  144. package/lib/{client → web}/hooks/useEntityFromRoute.d.ts +1 -1
  145. package/lib/{client → web}/hooks/useEntityFromRoute.js +1 -1
  146. package/lib/{client → web}/hooks/useInstanceNamesByEntity.d.ts +1 -1
  147. package/lib/{client → web}/hooks/useInstanceNamesByEntity.js +8 -6
  148. package/lib/web/hooks/useMappedAPIResource.d.ts +1 -0
  149. package/lib/web/hooks/useMappedAPIResource.js +17 -0
  150. package/lib/{client → web}/hooks/useSecondaryDeclarations.d.ts +1 -1
  151. package/lib/{client → web}/hooks/useSecondaryDeclarations.js +4 -2
  152. package/lib/{client → web}/routes/CreateInstance.d.ts +1 -1
  153. package/lib/{client → web}/routes/CreateInstance.js +4 -2
  154. package/lib/web/routes/Entity.d.ts +2 -0
  155. package/lib/web/routes/Entity.js +43 -0
  156. package/lib/web/routes/Home.d.ts +2 -0
  157. package/lib/web/routes/Home.js +9 -0
  158. package/lib/{client → web}/routes/Instance.d.ts +1 -1
  159. package/lib/{client → web}/routes/Instance.js +14 -8
  160. package/lib/{client → web}/routes/NotFound.d.ts +1 -1
  161. package/lib/web/utils/typeSkeleton.d.ts +3 -0
  162. package/lib/{client → web}/utils/typeSkeleton.js +14 -17
  163. package/package.json +35 -15
  164. package/public/css/styles.css +200 -1
  165. package/lib/ModelContainer.d.ts +0 -17
  166. package/lib/ModelContainer.js +0 -63
  167. package/lib/client/api.d.ts +0 -11
  168. package/lib/client/api.js +0 -83
  169. package/lib/client/components/Select.d.ts +0 -3
  170. package/lib/client/components/Select.js +0 -2
  171. package/lib/client/components/typeInputs/ArrayTypeInput.d.ts +0 -13
  172. package/lib/client/components/typeInputs/GenericTypeArgumentIdentifierTypeInput.d.ts +0 -7
  173. package/lib/client/components/typeInputs/IncludeIdentifierTypeInput.d.ts +0 -13
  174. package/lib/client/components/typeInputs/IncludeIdentifierTypeInput.js +0 -18
  175. package/lib/client/components/typeInputs/NestedEntityMapTypeInput.d.ts +0 -13
  176. package/lib/client/components/typeInputs/ReferenceIdentifierTypeInput.js +0 -9
  177. package/lib/client/components/typeInputs/TypeInput.d.ts +0 -13
  178. package/lib/client/components/typeInputs/utils/EnumDeclField.d.ts +0 -13
  179. package/lib/client/components/typeInputs/utils/Markdown.js +0 -57
  180. package/lib/client/routes/Entity.d.ts +0 -2
  181. package/lib/client/routes/Entity.js +0 -47
  182. package/lib/client/routes/Home.d.ts +0 -2
  183. package/lib/client/routes/Home.js +0 -18
  184. package/lib/client/utils/typeSkeleton.d.ts +0 -3
  185. package/lib/renderers/jsonschema/index.d.ts +0 -6
  186. package/lib/renderers/jsonschema/index.js +0 -12
  187. package/lib/renderers/jsonschema/render.d.ts +0 -5
  188. package/lib/renderers/ts/index.d.ts +0 -6
  189. package/lib/renderers/ts/index.js +0 -11
  190. package/lib/renderers/ts/render.js +0 -112
  191. package/lib/schema/declarations/EnumDecl.js +0 -115
  192. package/lib/schema/types/Type.d.ts +0 -42
  193. package/lib/schema/types/primitives/PrimitiveType.d.ts +0 -6
  194. package/lib/schema/types/references/GenericArgumentIdentifierType.d.ts +0 -21
  195. package/lib/schema/types/references/GenericArgumentIdentifierType.js +0 -18
  196. package/lib/schema/validation/type.d.ts +0 -4
  197. package/lib/server/index.d.ts +0 -8
  198. package/lib/server/index.js +0 -207
  199. package/lib/server/instanceOperations.d.ts +0 -7
  200. package/lib/server/instanceOperations.js +0 -67
  201. package/lib/tsconfig.tsbuildinfo +0 -1
  202. package/lib/utils/instances.d.ts +0 -4
  203. package/lib/utils/instances.js +0 -12
  204. package/lib/utils/object.d.ts +0 -3
  205. package/lib/utils/object.js +0 -1
  206. package/lib/utils/render.d.ts +0 -4
  207. package/lib/utils/render.js +0 -8
  208. /package/lib/{renderers → node/renderers}/Output.js +0 -0
  209. /package/lib/{schema → node/schema}/types/primitives/NumericType.js +0 -0
  210. /package/lib/{schema → node/schema}/types/primitives/PrimitiveType.js +0 -0
  211. /package/lib/{schema → node/schema}/validation/options.d.ts +0 -0
  212. /package/lib/{schema → node/schema}/validation/options.js +0 -0
  213. /package/lib/{schema → node/schema}/validation/type.js +0 -0
  214. /package/lib/{utils → node/utils}/error.d.ts +0 -0
  215. /package/lib/{utils → shared/utils}/enum.d.ts +0 -0
  216. /package/lib/{utils → shared/utils}/enum.js +0 -0
  217. /package/lib/{utils → shared/utils}/lazy.d.ts +0 -0
  218. /package/lib/{utils → shared/utils}/result.d.ts +0 -0
  219. /package/lib/{client → web}/components/typeInputs/BooleanTypeInput.js +0 -0
  220. /package/lib/{client → web}/components/typeInputs/DateTypeInput.js +0 -0
  221. /package/lib/{client → web}/components/typeInputs/FloatTypeInput.js +0 -0
  222. /package/lib/{client → web}/components/typeInputs/IntegerTypeInput.js +0 -0
  223. /package/lib/{client → web}/components/typeInputs/StringTypeInput.js +0 -0
  224. /package/lib/{client → web}/components/typeInputs/utils/MismatchingTypeError.js +0 -0
  225. /package/lib/{client → web}/components/typeInputs/utils/ValidationErrors.js +0 -0
  226. /package/lib/{client → web}/index.d.ts +0 -0
  227. /package/lib/{client → web}/index.js +0 -0
  228. /package/lib/{client → web}/routes/NotFound.js +0 -0
@@ -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,17 +0,0 @@
1
- import { Output } from "./renderers/Output.js";
2
- import { Schema } from "./Schema.js";
3
- export interface ModelContainer {
4
- schema: Schema;
5
- outputs: Output[];
6
- dataRootPath: string;
7
- }
8
- export declare const ModelContainer: (options: {
9
- schema: Schema;
10
- outputs: Output[];
11
- dataRootPath: string;
12
- }) => ModelContainer;
13
- export declare const generateOutputs: (modelContainer: ModelContainer) => Promise<void>;
14
- export declare const validate: (modelContainer: ModelContainer) => Promise<void>;
15
- export declare const generateAndValidate: (modelContainer: ModelContainer) => Promise<void>;
16
- export declare const serve: (modelContainer: ModelContainer) => Promise<void>;
17
- export declare const generateValidateAndServe: (modelContainer: ModelContainer) => Promise<void>;
@@ -1,63 +0,0 @@
1
- import { mkdir } from "fs/promises";
2
- import { join } from "path";
3
- import { getEntities } from "./Schema.js";
4
- import { createValidators, validateEntityDecl } from "./schema/index.js";
5
- import { createServer } from "./server/index.js";
6
- import { parallelizeErrors } from "./shared/utils/validation.js";
7
- import { getErrorMessageForDisplay, wrapErrorsIfAny } from "./utils/error.js";
8
- import { getInstancesByEntityName } from "./utils/instances.js";
9
- export const ModelContainer = (options) => ({
10
- ...options,
11
- });
12
- const prepareFolders = async (modelContainer, entities) => {
13
- await mkdir(modelContainer.dataRootPath, { recursive: true });
14
- for (const entity of entities) {
15
- const entityDir = join(modelContainer.dataRootPath, entity.name);
16
- await mkdir(entityDir, { recursive: true });
17
- }
18
- };
19
- export const generateOutputs = async (modelContainer) => {
20
- for (const output of modelContainer.outputs) {
21
- await output.run(modelContainer.schema);
22
- }
23
- };
24
- const _validate = async (entities, instancesByEntityName) => {
25
- const errors = entities.flatMap(entity => parallelizeErrors(instancesByEntityName[entity.name].map(instance => wrapErrorsIfAny(`in file "${entity.name}/${instance.fileName}"`, validateEntityDecl(createValidators(instancesByEntityName), entity, instance.content)))));
26
- if (errors.length === 0) {
27
- console.log("All entities are valid");
28
- }
29
- else {
30
- console.error("Errors:\n");
31
- for (const error of errors) {
32
- console.error(getErrorMessageForDisplay(error) + "\n");
33
- }
34
- throw new Error("Validation failed");
35
- }
36
- };
37
- export const validate = async (modelContainer) => {
38
- const entities = getEntities(modelContainer.schema);
39
- await prepareFolders(modelContainer, entities);
40
- const instancesByEntityName = await getInstancesByEntityName(modelContainer, entities);
41
- return _validate(entities, instancesByEntityName);
42
- };
43
- export const generateAndValidate = async (modelContainer) => {
44
- await generateOutputs(modelContainer);
45
- const entities = getEntities(modelContainer.schema);
46
- await prepareFolders(modelContainer, entities);
47
- const instancesByEntityName = await getInstancesByEntityName(modelContainer, entities);
48
- await _validate(entities, instancesByEntityName);
49
- };
50
- export const serve = async (modelContainer) => {
51
- const entities = getEntities(modelContainer.schema);
52
- await prepareFolders(modelContainer, entities);
53
- const instancesByEntityName = await getInstancesByEntityName(modelContainer, entities);
54
- createServer(modelContainer, instancesByEntityName);
55
- };
56
- export const generateValidateAndServe = async (modelContainer) => {
57
- await generateOutputs(modelContainer);
58
- const entities = getEntities(modelContainer.schema);
59
- await prepareFolders(modelContainer, entities);
60
- const instancesByEntityName = await getInstancesByEntityName(modelContainer, entities);
61
- await _validate(entities, instancesByEntityName);
62
- createServer(modelContainer, instancesByEntityName);
63
- };
@@ -1,11 +0,0 @@
1
- import { SerializedEntityDecl } from "../schema/declarations/EntityDecl.js";
2
- import { CreateInstanceOfEntityResponseBody, DeleteInstanceOfEntityResponseBody, GetAllDeclarationsResponseBody, GetAllInstancesOfEntityResponseBody, GetAllInstancesResponseBody, GetDeclarationResponseBody, GetInstanceOfEntityResponseBody, UpdateInstanceOfEntityResponseBody } from "../shared/api.js";
3
- export declare const getAllDeclarations: (kind?: "Entity" | "Enum" | "TypeAlias") => Promise<GetAllDeclarationsResponseBody>;
4
- export declare const getAllEntities: () => Promise<GetAllDeclarationsResponseBody<SerializedEntityDecl>>;
5
- export declare const getEntityByName: (name: string) => Promise<GetDeclarationResponseBody<SerializedEntityDecl>>;
6
- export declare const getInstancesByEntityName: (name: string) => Promise<GetAllInstancesOfEntityResponseBody>;
7
- export declare const createInstanceByEntityNameAndId: (name: string, content: unknown, id?: string) => Promise<CreateInstanceOfEntityResponseBody>;
8
- export declare const getInstanceByEntityNameAndId: (name: string, id: string) => Promise<GetInstanceOfEntityResponseBody>;
9
- export declare const updateInstanceByEntityNameAndId: (name: string, id: string, content: unknown) => Promise<UpdateInstanceOfEntityResponseBody>;
10
- export declare const deleteInstanceByEntityNameAndId: (name: string, id: string) => Promise<DeleteInstanceOfEntityResponseBody>;
11
- export declare const getAllInstances: (locales: string[]) => Promise<GetAllInstancesResponseBody>;
package/lib/client/api.js DELETED
@@ -1,83 +0,0 @@
1
- export const getAllDeclarations = async (kind) => {
2
- const url = new URL("/api/declarations", window.location.origin);
3
- if (kind) {
4
- url.searchParams.append("kind", kind);
5
- }
6
- const response = await fetch(url);
7
- if (!response.ok) {
8
- throw new Error(await response.text());
9
- }
10
- return response.json();
11
- };
12
- export const getAllEntities = () => getAllDeclarations("Entity");
13
- export const getEntityByName = async (name) => {
14
- const response = await fetch(`/api/declarations/${name}`);
15
- if (!response.ok) {
16
- throw new Error(await response.text());
17
- }
18
- return response.json();
19
- };
20
- export const getInstancesByEntityName = async (name) => {
21
- const response = await fetch(`/api/declarations/${name}/instances`);
22
- if (!response.ok) {
23
- throw new Error(await response.text());
24
- }
25
- return response.json();
26
- };
27
- export const createInstanceByEntityNameAndId = async (name, content, id) => {
28
- const url = new URL(`/api/declarations/${name}/instances`, window.location.origin);
29
- if (id) {
30
- url.searchParams.append("id", id);
31
- }
32
- const response = await fetch(url, {
33
- method: "POST",
34
- body: JSON.stringify(content),
35
- headers: {
36
- "Content-Type": "application/json",
37
- },
38
- });
39
- if (!response.ok) {
40
- throw new Error(await response.text());
41
- }
42
- return response.json();
43
- };
44
- export const getInstanceByEntityNameAndId = async (name, id) => {
45
- const response = await fetch(`/api/declarations/${name}/instances/${id}`);
46
- if (!response.ok) {
47
- throw new Error(await response.text());
48
- }
49
- return response.json();
50
- };
51
- export const updateInstanceByEntityNameAndId = async (name, id, content) => {
52
- const response = await fetch(`/api/declarations/${name}/instances/${id}`, {
53
- method: "PUT",
54
- body: JSON.stringify(content),
55
- headers: {
56
- "Content-Type": "application/json",
57
- },
58
- });
59
- if (!response.ok) {
60
- throw new Error(await response.text());
61
- }
62
- return response.json();
63
- };
64
- export const deleteInstanceByEntityNameAndId = async (name, id) => {
65
- const response = await fetch(`/api/declarations/${name}/instances/${id}`, {
66
- method: "DELETE",
67
- });
68
- if (!response.ok) {
69
- throw new Error(await response.text());
70
- }
71
- return response.json();
72
- };
73
- export const getAllInstances = async (locales) => {
74
- const url = new URL("/api/instances", window.location.origin);
75
- for (const locale of locales) {
76
- url.searchParams.append("locales", locale);
77
- }
78
- const response = await fetch(url);
79
- if (!response.ok) {
80
- throw new Error(await response.text());
81
- }
82
- return response.json();
83
- };
@@ -1,3 +0,0 @@
1
- import { FunctionalComponent } from "preact";
2
- import { SelectHTMLAttributes } from "preact/compat";
3
- export declare const Select: FunctionalComponent<SelectHTMLAttributes>;
@@ -1,2 +0,0 @@
1
- import { jsx as _jsx } from "preact/jsx-runtime";
2
- export const Select = props => (_jsx("div", { class: "select-wrapper", children: _jsx("select", { ...props, class: `${props.class ?? ""} ${props.className ?? ""} ${!props.value ? "no-selection" : ""}` }) }));
@@ -1,13 +0,0 @@
1
- import { FunctionComponent } from "preact";
2
- import { SerializedArrayType } from "../../../schema/types/generic/ArrayType.js";
3
- import { InstanceNamesByEntity } from "../../hooks/useInstanceNamesByEntity.js";
4
- import { GetDeclFromDeclName } from "../../hooks/useSecondaryDeclarations.js";
5
- type Props = {
6
- type: SerializedArrayType;
7
- value: unknown[];
8
- instanceNamesByEntity: InstanceNamesByEntity;
9
- getDeclFromDeclName: GetDeclFromDeclName;
10
- onChange: (value: unknown[]) => void;
11
- };
12
- export declare const ArrayTypeInput: FunctionComponent<Props>;
13
- export {};
@@ -1,7 +0,0 @@
1
- import { FunctionComponent } from "preact";
2
- import { SerializedGenericArgumentIdentifierType } from "../../../schema/types/references/GenericArgumentIdentifierType.js";
3
- type Props = {
4
- type: SerializedGenericArgumentIdentifierType;
5
- };
6
- export declare const GenericArgumentIdentifierTypeInput: FunctionComponent<Props>;
7
- export {};
@@ -1,13 +0,0 @@
1
- import { FunctionComponent } from "preact";
2
- import { SerializedIncludeIdentifierType } from "../../../schema/index.js";
3
- import { InstanceNamesByEntity } from "../../hooks/useInstanceNamesByEntity.js";
4
- import { GetDeclFromDeclName } from "../../hooks/useSecondaryDeclarations.js";
5
- type Props = {
6
- type: SerializedIncludeIdentifierType;
7
- value: unknown;
8
- instanceNamesByEntity: InstanceNamesByEntity;
9
- getDeclFromDeclName: GetDeclFromDeclName;
10
- onChange: (value: unknown) => void;
11
- };
12
- export declare const IncludeIdentifierTypeInput: FunctionComponent<Props>;
13
- export {};
@@ -1,18 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
2
- import { assertExhaustive } from "../../../shared/utils/typeSafety.js";
3
- import { TypeInput } from "./TypeInput.js";
4
- import { EnumDeclField } from "./utils/EnumDeclField.js";
5
- export const IncludeIdentifierTypeInput = ({ type, value, instanceNamesByEntity, getDeclFromDeclName, onChange, }) => {
6
- const decl = getDeclFromDeclName(type.reference);
7
- if (decl === undefined) {
8
- return (_jsxs("div", { role: "alert", children: ["Unresolved declaration identifier ", _jsx("code", { children: type.reference })] }));
9
- }
10
- switch (decl.kind) {
11
- case "EnumDecl":
12
- return (_jsx(EnumDeclField, { decl: decl, value: value, instanceNamesByEntity: instanceNamesByEntity, getDeclFromDeclName: getDeclFromDeclName, onChange: onChange }));
13
- case "TypeAliasDecl":
14
- return (_jsx(TypeInput, { type: decl.type, value: value, instanceNamesByEntity: instanceNamesByEntity, getDeclFromDeclName: getDeclFromDeclName, onChange: onChange }));
15
- default:
16
- return assertExhaustive(decl);
17
- }
18
- };
@@ -1,13 +0,0 @@
1
- import { FunctionComponent } from "preact";
2
- import { SerializedNestedEntityMapType } from "../../../schema/types/references/NestedEntityMapType.js";
3
- import { InstanceNamesByEntity } from "../../hooks/useInstanceNamesByEntity.js";
4
- import { GetDeclFromDeclName } from "../../hooks/useSecondaryDeclarations.js";
5
- type Props = {
6
- type: SerializedNestedEntityMapType;
7
- value: Record<string, unknown>;
8
- instanceNamesByEntity: InstanceNamesByEntity;
9
- getDeclFromDeclName: GetDeclFromDeclName;
10
- onChange: (value: Record<string, unknown>) => void;
11
- };
12
- export declare const NestedEntityMapTypeInput: FunctionComponent<Props>;
13
- export {};
@@ -1,9 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
2
- import { Select } from "../Select.js";
3
- import { ValidationErrors } from "./utils/ValidationErrors.js";
4
- export const ReferenceIdentifierTypeInput = ({ type, value, instanceNamesByEntity, onChange, }) => {
5
- const instances = (instanceNamesByEntity[type.entity] ?? [])
6
- .slice()
7
- .sort((a, b) => a.name.localeCompare(b.name));
8
- return (_jsxs("div", { class: "field", children: [_jsxs(Select, { value: value, onInput: event => onChange(event.currentTarget.value), disabled: instances.length === 0, "aria-invalid": !value, children: [instances.length === 0 ? (_jsx("option", { value: "", disabled: true, children: "No instances available" })) : (_jsx("option", { value: "", disabled: true, children: "No selected instance" })), instances.map(instance => (_jsx("option", { value: instance.id, children: instance.name })))] }), _jsx(ValidationErrors, { errors: !value ? [ReferenceError("no reference provided")] : [] })] }));
9
- };
@@ -1,13 +0,0 @@
1
- import { FunctionComponent } from "preact";
2
- import { SerializedType } from "../../../schema/types/Type.js";
3
- import { InstanceNamesByEntity } from "../../hooks/useInstanceNamesByEntity.js";
4
- import { GetDeclFromDeclName } from "../../hooks/useSecondaryDeclarations.js";
5
- type Props = {
6
- type: SerializedType;
7
- value: unknown;
8
- instanceNamesByEntity: InstanceNamesByEntity;
9
- getDeclFromDeclName: GetDeclFromDeclName;
10
- onChange: (value: unknown) => void;
11
- };
12
- export declare const TypeInput: FunctionComponent<Props>;
13
- export {};
@@ -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,57 +0,0 @@
1
- import { jsx as _jsx } from "preact/jsx-runtime";
2
- const bold = /\*\*(.+?)\*\*/;
3
- const italic = /\*(.+?)\*/;
4
- const boldItalic = /\*\*\*(.+?)\*\*\*/;
5
- const parseBlockMarkdown = (text) => text.split(/\n{2,}/).map(par => ({ kind: "paragraph", content: parseInlineMarkdown(par) }));
6
- const parseForPattern = (pattern, kind, text, nextPatterns = []) => {
7
- const res = pattern.exec(text);
8
- if (res) {
9
- const { index } = res;
10
- const before = text.slice(0, index);
11
- const after = text.slice(index + res[0].length);
12
- const inner = res[1];
13
- const innerNode = nextPatterns.length > 0
14
- ? parseForPattern(nextPatterns[0][1], nextPatterns[0][0], inner, nextPatterns.slice(1))
15
- : [{ kind, content: [{ kind: "text", content: inner }] }];
16
- return [
17
- ...(before.length > 0 ? [{ kind: "text", content: before }] : []),
18
- { kind, content: innerNode },
19
- ...(after.length > 0 ? parseForPattern(pattern, kind, after) : []),
20
- ];
21
- }
22
- else {
23
- return nextPatterns.length > 0
24
- ? parseForPattern(nextPatterns[0][1], nextPatterns[0][0], text, nextPatterns.slice(1))
25
- : [{ kind: "text", content: text }];
26
- }
27
- };
28
- const parseInlineMarkdown = (text) => parseForPattern(boldItalic, "boldItalic", text, [
29
- ["bold", bold],
30
- ["italic", italic],
31
- ]);
32
- export const Markdown = ({ string }) => {
33
- const blocks = parseBlockMarkdown(string);
34
- return blocks.map((block, i) => _jsx(BlockMarkdown, { node: block }, `md-block-${i}`));
35
- };
36
- const BlockMarkdown = ({ node }) => {
37
- switch (node.kind) {
38
- case "paragraph":
39
- return (_jsx("p", { children: node.content.map((inline, ii) => (_jsx(InlineMarkdown, { node: inline }, ii))) }));
40
- case "text":
41
- return node.content;
42
- default:
43
- return null;
44
- }
45
- };
46
- const InlineMarkdown = ({ node }) => {
47
- switch (node.kind) {
48
- case "bold":
49
- return (_jsx("strong", { children: node.content.map((inline, i) => (_jsx(InlineMarkdown, { node: inline }, i))) }));
50
- case "italic":
51
- return (_jsx("em", { children: node.content.map((inline, i) => (_jsx(InlineMarkdown, { node: inline }, i))) }));
52
- case "boldItalic":
53
- return (_jsx("strong", { children: _jsx("em", { children: node.content.map((inline, i) => (_jsx(InlineMarkdown, { node: inline }, i))) }) }));
54
- case "text":
55
- return node.content;
56
- }
57
- };
@@ -1,2 +0,0 @@
1
- import { FunctionalComponent } from "preact";
2
- export declare const Entity: FunctionalComponent;
@@ -1,47 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
2
- import { useRoute } from "preact-iso";
3
- import { useEffect, useState } from "preact/hooks";
4
- import { getDisplayNameFromEntityInstance } from "../../shared/utils/displayName.js";
5
- import { deleteInstanceByEntityNameAndId, getEntityByName, getInstancesByEntityName, } from "../api.js";
6
- import { Layout } from "../components/Layout.js";
7
- import { NotFound } from "./NotFound.js";
8
- export const Entity = () => {
9
- const { params: { name }, query: { created }, } = useRoute();
10
- const [entity, setEntity] = useState();
11
- const [instances, setInstances] = useState();
12
- useEffect(() => {
13
- if (name) {
14
- Promise.all([getEntityByName(name), getInstancesByEntityName(name)])
15
- .then(([entityData, instancesData]) => {
16
- setEntity(entityData);
17
- setInstances(instancesData.instances);
18
- })
19
- .catch(error => {
20
- console.error("Error fetching entities:", error);
21
- });
22
- }
23
- if (created) {
24
- const instanceElement = document.getElementById(`instance-${created}`);
25
- if (instanceElement) {
26
- instanceElement.scrollIntoView({ behavior: "smooth", block: "center" });
27
- }
28
- }
29
- }, []);
30
- if (!name) {
31
- return _jsx(NotFound, {});
32
- }
33
- if (!entity || !instances) {
34
- return (_jsxs("div", { children: [_jsx("h1", { children: name }), _jsx("p", { className: "loading", children: "Loading \u2026" })] }));
35
- }
36
- return (_jsxs(Layout, { breadcrumbs: [{ url: "/", label: "Home" }], children: [_jsxs("div", { class: "header-with-btns", children: [_jsx("h1", { children: name }), _jsx("a", { class: "btn btn--primary", href: `/entities/${entity.declaration.name}/instances/create`, children: "Add" })] }), entity.declaration.comment && _jsx("p", { className: "description", children: entity.declaration.comment }), _jsxs("p", { children: [instances.length, " instance", instances.length === 1 ? "" : "s"] }), _jsx("ul", { class: "instances", children: instances.map(instance => (_jsxs("li", { id: `instance-${instance.id}`, class: `instance-item ${created === instance.id ? "instance-item--created" : ""}`, children: [_jsx("h2", { children: getDisplayNameFromEntityInstance(entity.declaration, instance.content, instance.id) }), _jsx("p", { "aria-hidden": true, class: "id", children: instance.id }), _jsxs("div", { className: "btns", children: [_jsx("a", { href: `/entities/${entity.declaration.name}/instances/${instance.id}`, class: "btn", children: "Edit" }), _jsx("button", { class: "destructive", onClick: () => {
37
- if (confirm("Are you sure you want to delete this instance?")) {
38
- deleteInstanceByEntityNameAndId(entity.declaration.name, instance.id)
39
- .then(() => {
40
- setInstances(instances.filter(i => i.id !== instance.id));
41
- })
42
- .catch(error => {
43
- alert("Error deleting instance:\n\n" + error);
44
- });
45
- }
46
- }, children: "Delete" })] })] }, instance.id))) })] }));
47
- };
@@ -1,2 +0,0 @@
1
- import { FunctionalComponent } from "preact";
2
- export declare const Home: FunctionalComponent;
@@ -1,18 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
2
- import { useEffect, useState } from "preact/hooks";
3
- import { toTitleCase } from "../../shared/utils/string.js";
4
- import { getAllEntities } from "../api.js";
5
- import { Layout } from "../components/Layout.js";
6
- export const Home = () => {
7
- const [entities, setEntities] = useState([]);
8
- useEffect(() => {
9
- getAllEntities()
10
- .then(data => {
11
- setEntities(data.declarations.sort((a, b) => a.declaration.name.localeCompare(b.declaration.name)));
12
- })
13
- .catch(error => {
14
- console.error("Error fetching entities:", error);
15
- });
16
- }, []);
17
- return (_jsxs(Layout, { breadcrumbs: [{ url: "/", label: "Home" }], children: [_jsx("h1", { children: "Entities" }), _jsx("ul", { class: "entities", children: entities.map(entity => (_jsxs("li", { class: "entity-item", children: [_jsxs("div", { className: "title", children: [_jsx("h2", { children: toTitleCase(entity.declaration.name) }), entity.declaration.comment && _jsx("p", { children: entity.declaration.comment })] }), _jsxs("p", { class: "meta", children: [entity.instanceCount, " instance", entity.instanceCount === 1 ? "" : "s"] }), _jsx("div", { className: "btns", children: _jsx("a", { href: `/entities/${entity.declaration.name}`, class: "btn", children: "View" }) })] }, entity.declaration.name))) })] }));
18
- };
@@ -1,3 +0,0 @@
1
- import { SerializedType } from "../../schema/types/Type.js";
2
- import { GetDeclFromDeclName } from "../hooks/useSecondaryDeclarations.js";
3
- export declare const createTypeSkeleton: (getDeclFromDeclName: GetDeclFromDeclName, type: SerializedType) => unknown;