tsondb 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (206) hide show
  1. package/LICENSE +385 -0
  2. package/README.md +173 -1
  3. package/lib/bin/tsondb.d.ts +10 -0
  4. package/lib/bin/tsondb.js +84 -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} +6 -5
  9. package/lib/node/index.d.ts +9 -0
  10. package/lib/node/index.js +75 -0
  11. package/lib/{renderers → node/renderers}/Output.d.ts +1 -1
  12. package/lib/{renderers → node/renderers}/jsonschema/index.d.ts +2 -2
  13. package/lib/{renderers → node/renderers}/jsonschema/index.js +9 -2
  14. package/lib/{renderers → node/renderers}/jsonschema/render.d.ts +1 -1
  15. package/lib/{renderers → node/renderers}/jsonschema/render.js +15 -10
  16. package/lib/{renderers → node/renderers}/ts/index.d.ts +2 -2
  17. package/lib/{renderers → node/renderers}/ts/index.js +2 -2
  18. package/lib/{renderers → node/renderers}/ts/render.d.ts +1 -1
  19. package/lib/{renderers → node/renderers}/ts/render.js +13 -9
  20. package/lib/{schema → node/schema}/Node.d.ts +5 -5
  21. package/lib/{schema → node/schema}/Node.js +9 -8
  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 +10 -11
  25. package/lib/{schema → node/schema}/declarations/Declaration.js +7 -5
  26. package/lib/{schema → node/schema}/declarations/EntityDecl.d.ts +13 -12
  27. package/lib/{schema → node/schema}/declarations/EntityDecl.js +4 -5
  28. package/lib/{schema → node/schema}/declarations/EnumDecl.d.ts +9 -7
  29. package/lib/{schema → node/schema}/declarations/EnumDecl.js +6 -13
  30. package/lib/{schema → node/schema}/declarations/TypeAliasDecl.d.ts +8 -7
  31. package/lib/{schema → node/schema}/declarations/TypeAliasDecl.js +6 -14
  32. package/lib/{schema → node/schema}/index.d.ts +4 -4
  33. package/lib/{schema → node/schema}/index.js +3 -4
  34. package/lib/node/schema/types/Type.d.ts +54 -0
  35. package/lib/{schema → node/schema}/types/Type.js +55 -29
  36. package/lib/{schema → node/schema}/types/generic/ArrayType.d.ts +5 -4
  37. package/lib/{schema → node/schema}/types/generic/ArrayType.js +5 -5
  38. package/lib/{schema → node/schema}/types/generic/EnumType.d.ts +5 -4
  39. package/lib/{schema → node/schema}/types/generic/EnumType.js +10 -4
  40. package/lib/{schema → node/schema}/types/generic/ObjectType.d.ts +8 -7
  41. package/lib/{schema → node/schema}/types/generic/ObjectType.js +14 -7
  42. package/lib/{schema → node/schema}/types/primitives/BooleanType.d.ts +4 -3
  43. package/lib/{schema → node/schema}/types/primitives/DateType.d.ts +5 -4
  44. package/lib/{schema → node/schema}/types/primitives/DateType.js +1 -1
  45. package/lib/{schema → node/schema}/types/primitives/FloatType.d.ts +5 -4
  46. package/lib/{schema → node/schema}/types/primitives/FloatType.js +1 -1
  47. package/lib/{schema → node/schema}/types/primitives/IntegerType.d.ts +5 -4
  48. package/lib/{schema → node/schema}/types/primitives/IntegerType.js +1 -1
  49. package/lib/{schema → node/schema}/types/primitives/NumericType.d.ts +2 -2
  50. package/lib/node/schema/types/primitives/PrimitiveType.d.ts +6 -0
  51. package/lib/{schema → node/schema}/types/primitives/StringType.d.ts +5 -4
  52. package/lib/{schema → node/schema}/types/primitives/StringType.js +1 -1
  53. package/lib/{schema → node/schema}/types/references/IncludeIdentifierType.d.ts +9 -8
  54. package/lib/{schema → node/schema}/types/references/IncludeIdentifierType.js +1 -1
  55. package/lib/{schema → node/schema}/types/references/NestedEntityMapType.d.ts +10 -9
  56. package/lib/{schema → node/schema}/types/references/NestedEntityMapType.js +8 -16
  57. package/lib/{schema → node/schema}/types/references/ReferenceIdentifierType.d.ts +7 -6
  58. package/lib/{schema → node/schema}/types/references/ReferenceIdentifierType.js +1 -1
  59. package/lib/node/schema/types/references/TypeArgumentType.d.ts +23 -0
  60. package/lib/node/schema/types/references/TypeArgumentType.js +19 -0
  61. package/lib/node/schema/validation/type.d.ts +4 -0
  62. package/lib/{server → node/server}/api/declarations.js +7 -3
  63. package/lib/{server → node/server}/api/git.js +14 -11
  64. package/lib/{server → node/server}/api/instanceOperations.d.ts +3 -3
  65. package/lib/{server → node/server}/api/instanceOperations.js +18 -7
  66. package/lib/{server → node/server}/api/instances.js +7 -3
  67. package/lib/node/server/index.d.ts +28 -0
  68. package/lib/{server → node/server}/index.js +23 -13
  69. package/lib/node/server/init.d.ts +5 -0
  70. package/lib/{server → node/server}/init.js +9 -8
  71. package/lib/{utils → node/utils}/error.js +4 -1
  72. package/lib/{utils → node/utils}/git.d.ts +2 -2
  73. package/lib/{utils → node/utils}/instances.d.ts +4 -3
  74. package/lib/{utils → node/utils}/instances.js +10 -6
  75. package/lib/{utils → node/utils}/references.d.ts +2 -2
  76. package/lib/{utils → node/utils}/references.js +3 -3
  77. package/lib/{utils → node/utils}/render.js +1 -1
  78. package/lib/shared/api.d.ts +9 -3
  79. package/lib/shared/utils/array.d.ts +1 -0
  80. package/lib/shared/utils/array.js +13 -9
  81. package/lib/shared/utils/displayName.d.ts +1 -1
  82. package/lib/shared/utils/displayName.js +7 -2
  83. package/lib/shared/utils/instances.d.ts +2 -2
  84. package/lib/{utils → shared/utils}/lazy.js +1 -1
  85. package/lib/shared/utils/markdown.js +6 -6
  86. package/lib/shared/utils/object.d.ts +3 -0
  87. package/lib/shared/utils/object.js +5 -1
  88. package/lib/{utils → shared/utils}/result.js +2 -2
  89. package/lib/shared/utils/string.js +7 -4
  90. package/lib/shared/utils/validation.js +3 -2
  91. package/lib/shared/validation/number.js +3 -3
  92. package/lib/shared/validation/object.js +4 -3
  93. package/lib/shared/validation/string.js +12 -7
  94. package/lib/{client → web}/api.d.ts +3 -3
  95. package/lib/{client → web}/api.js +5 -6
  96. package/lib/web/components/Git.d.ts +2 -0
  97. package/lib/{client → web}/components/Git.js +59 -15
  98. package/lib/{client → web}/components/Layout.d.ts +1 -1
  99. package/lib/{client → web}/components/Layout.js +1 -1
  100. package/lib/web/components/Select.d.ts +3 -0
  101. package/lib/web/components/Select.js +5 -0
  102. package/lib/web/components/typeInputs/ArrayTypeInput.d.ts +13 -0
  103. package/lib/{client → web}/components/typeInputs/ArrayTypeInput.js +7 -1
  104. package/lib/{client → web}/components/typeInputs/BooleanTypeInput.d.ts +2 -2
  105. package/lib/{client → web}/components/typeInputs/DateTypeInput.d.ts +2 -2
  106. package/lib/web/components/typeInputs/EnumTypeInput.d.ts +13 -0
  107. package/lib/{client → web}/components/typeInputs/EnumTypeInput.js +1 -1
  108. package/lib/{client → web}/components/typeInputs/FloatTypeInput.d.ts +2 -2
  109. package/lib/web/components/typeInputs/GenericTypeArgumentIdentifierTypeInput.d.ts +7 -0
  110. package/lib/{client → web}/components/typeInputs/GenericTypeArgumentIdentifierTypeInput.js +1 -1
  111. package/lib/web/components/typeInputs/IncludeIdentifierTypeInput.d.ts +13 -0
  112. package/lib/{client → web}/components/typeInputs/IntegerTypeInput.d.ts +2 -2
  113. package/lib/web/components/typeInputs/NestedEntityMapTypeInput.d.ts +13 -0
  114. package/lib/{client → web}/components/typeInputs/NestedEntityMapTypeInput.js +7 -2
  115. package/lib/{client → web}/components/typeInputs/ObjectTypeInput.d.ts +4 -4
  116. package/lib/{client → web}/components/typeInputs/ObjectTypeInput.js +4 -1
  117. package/lib/{client → web}/components/typeInputs/ReferenceIdentifierTypeInput.d.ts +3 -3
  118. package/lib/web/components/typeInputs/ReferenceIdentifierTypeInput.js +11 -0
  119. package/lib/{client → web}/components/typeInputs/StringTypeInput.d.ts +2 -2
  120. package/lib/web/components/typeInputs/TypeInput.d.ts +13 -0
  121. package/lib/{client → web}/components/typeInputs/TypeInput.js +3 -3
  122. package/lib/{client → web}/components/typeInputs/utils/Markdown.d.ts +1 -1
  123. package/lib/{client → web}/components/typeInputs/utils/Markdown.js +2 -2
  124. package/lib/{client → web}/components/typeInputs/utils/MismatchingTypeError.d.ts +1 -1
  125. package/lib/{client → web}/components/typeInputs/utils/ValidationErrors.d.ts +1 -1
  126. package/lib/web/hooks/useAPIResource.d.ts +1 -0
  127. package/lib/{client → web}/hooks/useAPIResource.js +2 -1
  128. package/lib/{client → web}/hooks/useEntityFromRoute.d.ts +1 -1
  129. package/lib/{client → web}/hooks/useEntityFromRoute.js +1 -1
  130. package/lib/{client → web}/hooks/useInstanceNamesByEntity.d.ts +1 -1
  131. package/lib/{client → web}/hooks/useInstanceNamesByEntity.js +8 -6
  132. package/lib/web/hooks/useMappedAPIResource.d.ts +1 -0
  133. package/lib/{client → web}/hooks/useMappedAPIResource.js +9 -9
  134. package/lib/{client → web}/hooks/useSecondaryDeclarations.d.ts +1 -1
  135. package/lib/{client → web}/hooks/useSecondaryDeclarations.js +4 -2
  136. package/lib/{client → web}/routes/CreateInstance.d.ts +1 -1
  137. package/lib/{client → web}/routes/CreateInstance.js +4 -2
  138. package/lib/web/routes/Entity.d.ts +2 -0
  139. package/lib/{client → web}/routes/Entity.js +8 -6
  140. package/lib/web/routes/Home.d.ts +2 -0
  141. package/lib/{client → web}/routes/Home.js +2 -1
  142. package/lib/{client → web}/routes/Instance.d.ts +1 -1
  143. package/lib/{client → web}/routes/Instance.js +14 -8
  144. package/lib/{client → web}/routes/NotFound.d.ts +1 -1
  145. package/lib/web/utils/typeSkeleton.d.ts +3 -0
  146. package/lib/{client → web}/utils/typeSkeleton.js +4 -1
  147. package/package.json +33 -19
  148. package/lib/ModelContainer.d.ts +0 -17
  149. package/lib/ModelContainer.js +0 -65
  150. package/lib/client/components/Git.d.ts +0 -2
  151. package/lib/client/components/Select.d.ts +0 -3
  152. package/lib/client/components/Select.js +0 -2
  153. package/lib/client/components/typeInputs/ArrayTypeInput.d.ts +0 -13
  154. package/lib/client/components/typeInputs/EnumTypeInput.d.ts +0 -13
  155. package/lib/client/components/typeInputs/GenericTypeArgumentIdentifierTypeInput.d.ts +0 -7
  156. package/lib/client/components/typeInputs/IncludeIdentifierTypeInput.d.ts +0 -13
  157. package/lib/client/components/typeInputs/NestedEntityMapTypeInput.d.ts +0 -13
  158. package/lib/client/components/typeInputs/ReferenceIdentifierTypeInput.js +0 -9
  159. package/lib/client/components/typeInputs/TypeInput.d.ts +0 -13
  160. package/lib/client/hooks/useAPIResource.d.ts +0 -1
  161. package/lib/client/hooks/useMappedAPIResource.d.ts +0 -1
  162. package/lib/client/routes/Entity.d.ts +0 -2
  163. package/lib/client/routes/Home.d.ts +0 -2
  164. package/lib/client/utils/typeSkeleton.d.ts +0 -3
  165. package/lib/schema/types/Type.d.ts +0 -48
  166. package/lib/schema/types/primitives/PrimitiveType.d.ts +0 -6
  167. package/lib/schema/types/references/GenericArgumentIdentifierType.d.ts +0 -22
  168. package/lib/schema/types/references/GenericArgumentIdentifierType.js +0 -19
  169. package/lib/schema/validation/type.d.ts +0 -4
  170. package/lib/server/index.d.ts +0 -29
  171. package/lib/server/init.d.ts +0 -5
  172. package/lib/tsconfig.tsbuildinfo +0 -1
  173. package/lib/utils/object.d.ts +0 -3
  174. package/lib/utils/object.js +0 -1
  175. /package/lib/{renderers → node/renderers}/Output.js +0 -0
  176. /package/lib/{schema → node/schema}/types/primitives/BooleanType.js +0 -0
  177. /package/lib/{schema → node/schema}/types/primitives/NumericType.js +0 -0
  178. /package/lib/{schema → node/schema}/types/primitives/PrimitiveType.js +0 -0
  179. /package/lib/{schema → node/schema}/validation/options.d.ts +0 -0
  180. /package/lib/{schema → node/schema}/validation/options.js +0 -0
  181. /package/lib/{schema → node/schema}/validation/type.js +0 -0
  182. /package/lib/{server → node/server}/api/declarations.d.ts +0 -0
  183. /package/lib/{server → node/server}/api/git.d.ts +0 -0
  184. /package/lib/{server → node/server}/api/index.d.ts +0 -0
  185. /package/lib/{server → node/server}/api/index.js +0 -0
  186. /package/lib/{server → node/server}/api/instances.d.ts +0 -0
  187. /package/lib/{utils → node/utils}/error.d.ts +0 -0
  188. /package/lib/{utils → node/utils}/git.js +0 -0
  189. /package/lib/{utils → node/utils}/path.d.ts +0 -0
  190. /package/lib/{utils → node/utils}/path.js +0 -0
  191. /package/lib/{utils → node/utils}/render.d.ts +0 -0
  192. /package/lib/{utils → shared/utils}/enum.d.ts +0 -0
  193. /package/lib/{utils → shared/utils}/enum.js +0 -0
  194. /package/lib/{utils → shared/utils}/lazy.d.ts +0 -0
  195. /package/lib/{utils → shared/utils}/result.d.ts +0 -0
  196. /package/lib/{client → web}/components/typeInputs/BooleanTypeInput.js +0 -0
  197. /package/lib/{client → web}/components/typeInputs/DateTypeInput.js +0 -0
  198. /package/lib/{client → web}/components/typeInputs/FloatTypeInput.js +0 -0
  199. /package/lib/{client → web}/components/typeInputs/IncludeIdentifierTypeInput.js +0 -0
  200. /package/lib/{client → web}/components/typeInputs/IntegerTypeInput.js +0 -0
  201. /package/lib/{client → web}/components/typeInputs/StringTypeInput.js +0 -0
  202. /package/lib/{client → web}/components/typeInputs/utils/MismatchingTypeError.js +0 -0
  203. /package/lib/{client → web}/components/typeInputs/utils/ValidationErrors.js +0 -0
  204. /package/lib/{client → web}/index.d.ts +0 -0
  205. /package/lib/{client → web}/index.js +0 -0
  206. /package/lib/{client → web}/routes/NotFound.js +0 -0
@@ -1,5 +1,5 @@
1
- import { FloatType, SerializedFloatType } from "./FloatType.js";
2
- import { IntegerType, SerializedIntegerType } from "./IntegerType.js";
1
+ import type { FloatType, SerializedFloatType } from "./FloatType.js";
2
+ import type { IntegerType, SerializedIntegerType } from "./IntegerType.js";
3
3
  export type NumericType = FloatType | IntegerType;
4
4
  export type SerializedNumericType = SerializedFloatType | SerializedIntegerType;
5
5
  export * from "./FloatType.js";
@@ -0,0 +1,6 @@
1
+ import type { BooleanType, SerializedBooleanType } from "./BooleanType.js";
2
+ import type { DateType, SerializedDateType } from "./DateType.js";
3
+ import type { NumericType, SerializedNumericType } from "./NumericType.js";
4
+ import type { SerializedStringType, StringType } from "./StringType.js";
5
+ export type PrimitiveType = BooleanType | DateType | NumericType | StringType;
6
+ export type SerializedPrimitiveType = SerializedBooleanType | SerializedDateType | SerializedNumericType | SerializedStringType;
@@ -1,7 +1,8 @@
1
- import { StringConstraints } from "../../../shared/validation/string.js";
2
- import { GetReferences, Node, NodeKind, Serializer } from "../../Node.js";
3
- import { Validator } from "../../validation/type.js";
4
- import { BaseType, SerializedBaseType, StructureFormatter } from "../Type.js";
1
+ import type { StringConstraints } from "../../../../shared/validation/string.js";
2
+ import type { GetReferences, Node, Serializer } from "../../Node.js";
3
+ import { NodeKind } from "../../Node.js";
4
+ import type { Validator } from "../../validation/type.js";
5
+ import type { BaseType, SerializedBaseType, StructureFormatter } from "../Type.js";
5
6
  export interface StringType extends BaseType, StringConstraints {
6
7
  kind: NodeKind["StringType"];
7
8
  pattern?: RegExp;
@@ -1,4 +1,4 @@
1
- import { validateStringConstraints } from "../../../shared/validation/string.js";
1
+ import { validateStringConstraints } from "../../../../shared/validation/string.js";
2
2
  import { NodeKind } from "../../Node.js";
3
3
  import { removeParentKey } from "../Type.js";
4
4
  export const StringType = (options = {}) => ({
@@ -1,11 +1,12 @@
1
- import { GetNestedDeclarations, SerializedTypeArguments, TypeArguments } from "../../declarations/Declaration.js";
2
- import { EnumDecl } from "../../declarations/EnumDecl.js";
3
- import { TypeAliasDecl } from "../../declarations/TypeAliasDecl.js";
4
- import { GetReferences, Node, NodeKind, Serializer } from "../../Node.js";
5
- import { SerializedTypeParameter, TypeParameter } from "../../parameters/TypeParameter.js";
6
- import { Validator } from "../../validation/type.js";
7
- import { EnumCaseDecl } from "../generic/EnumType.js";
8
- import { BaseType, SerializedBaseType, StructureFormatter, Type } from "../Type.js";
1
+ import type { GetNestedDeclarations, SerializedTypeArguments, TypeArguments } from "../../declarations/Declaration.js";
2
+ import type { EnumDecl } from "../../declarations/EnumDecl.js";
3
+ import type { TypeAliasDecl } from "../../declarations/TypeAliasDecl.js";
4
+ import type { GetReferences, Node, Serializer } from "../../Node.js";
5
+ import { NodeKind } from "../../Node.js";
6
+ import type { SerializedTypeParameter, TypeParameter } from "../../TypeParameter.js";
7
+ import type { Validator } from "../../validation/type.js";
8
+ import type { EnumCaseDecl } from "../generic/EnumType.js";
9
+ import type { BaseType, SerializedBaseType, StructureFormatter, Type } from "../Type.js";
9
10
  type TConstraint<Params extends TypeParameter[]> = TypeAliasDecl<string, Type, Params> | EnumDecl<string, Record<string, EnumCaseDecl>, Params>;
10
11
  export interface IncludeIdentifierType<Params extends TypeParameter[] = TypeParameter[], T extends TConstraint<Params> = TConstraint<Params>> extends BaseType {
11
12
  kind: NodeKind["IncludeIdentifierType"];
@@ -1,7 +1,7 @@
1
1
  import { getNestedDeclarations, getReferencesForDecl, resolveTypeArgumentsInDecl, validateDecl, } from "../../declarations/Declaration.js";
2
2
  import { NodeKind } from "../../Node.js";
3
3
  import { formatEnumType } from "../generic/EnumType.js";
4
- import { formatValue, removeParentKey, resolveTypeArgumentsInType, serializeType, } from "../Type.js";
4
+ import { formatValue, removeParentKey, resolveTypeArgumentsInType, serializeType } from "../Type.js";
5
5
  export const GenIncludeIdentifierType = (reference, args) => ({
6
6
  kind: NodeKind.IncludeIdentifierType,
7
7
  reference,
@@ -1,11 +1,12 @@
1
- import { Lazy } from "../../../utils/lazy.js";
2
- import { GetNestedDeclarations } from "../../declarations/Declaration.js";
3
- import { EntityDecl } from "../../declarations/EntityDecl.js";
4
- import { GetReferences, Node, NodeKind, Serializer } from "../../Node.js";
5
- import { Validator } from "../../validation/type.js";
6
- import { MemberDecl, ObjectType, SerializedMemberDecl, SerializedObjectType } from "../generic/ObjectType.js";
7
- import { BaseType, SerializedBaseType, SerializedType, StructureFormatter, Type } from "../Type.js";
8
- type TConstraint = Record<string, MemberDecl<Type, boolean>>;
1
+ import { Lazy } from "../../../../shared/utils/lazy.js";
2
+ import type { GetNestedDeclarations } from "../../declarations/Declaration.js";
3
+ import type { EntityDecl } from "../../declarations/EntityDecl.js";
4
+ import type { GetReferences, Node, Serializer } from "../../Node.js";
5
+ import { NodeKind } from "../../Node.js";
6
+ import type { Validator } from "../../validation/type.js";
7
+ import type { MemberDecl, ObjectType, SerializedMemberDecl, SerializedObjectType } from "../generic/ObjectType.js";
8
+ import type { BaseType, SerializedBaseType, StructureFormatter, Type } from "../Type.js";
9
+ type TConstraint = Record<string, MemberDecl>;
9
10
  export interface NestedEntityMapType<Name extends string = string, T extends TConstraint = TConstraint> extends BaseType {
10
11
  kind: NodeKind["NestedEntityMapType"];
11
12
  name: Name;
@@ -13,7 +14,7 @@ export interface NestedEntityMapType<Name extends string = string, T extends TCo
13
14
  secondaryEntity: EntityDecl;
14
15
  type: Lazy<ObjectType<T>>;
15
16
  }
16
- type TSerializedConstraint = Record<string, SerializedMemberDecl<SerializedType, boolean>>;
17
+ type TSerializedConstraint = Record<string, SerializedMemberDecl>;
17
18
  export interface SerializedNestedEntityMapType<Name extends string = string, T extends TSerializedConstraint = TSerializedConstraint> extends SerializedBaseType {
18
19
  kind: NodeKind["NestedEntityMapType"];
19
20
  name: Name;
@@ -1,19 +1,15 @@
1
- import { sortObjectKeysAlphabetically } from "../../../shared/utils/object.js";
2
- import { parallelizeErrors } from "../../../shared/utils/validation.js";
1
+ import { Lazy } from "../../../../shared/utils/lazy.js";
2
+ import { sortObjectKeysAlphabetically } from "../../../../shared/utils/object.js";
3
+ import { parallelizeErrors } from "../../../../shared/utils/validation.js";
3
4
  import { wrapErrorsIfAny } from "../../../utils/error.js";
4
- import { Lazy } from "../../../utils/lazy.js";
5
5
  import { NodeKind } from "../../Node.js";
6
6
  import { getNestedDeclarationsInObjectType, getReferencesForObjectType, resolveTypeArgumentsInObjectType, serializeObjectType, validateObjectType, } from "../generic/ObjectType.js";
7
- import { removeParentKey, } from "../Type.js";
7
+ import { formatValue, removeParentKey, setParent } from "../Type.js";
8
8
  export const NestedEntityMapType = (options) => {
9
9
  const nestedEntityMapType = {
10
10
  ...options,
11
11
  kind: NodeKind.NestedEntityMapType,
12
- type: Lazy.of(() => {
13
- const type = options.type;
14
- type.parent = nestedEntityMapType;
15
- return type;
16
- }),
12
+ type: Lazy.of(() => setParent(options.type, nestedEntityMapType)),
17
13
  };
18
14
  return nestedEntityMapType;
19
15
  };
@@ -22,11 +18,7 @@ const _NestedEntityMapType = (options) => {
22
18
  const nestedEntityMapType = {
23
19
  ...options,
24
20
  kind: NodeKind.NestedEntityMapType,
25
- type: Lazy.of(() => {
26
- const type = options.type();
27
- type.parent = nestedEntityMapType;
28
- return type;
29
- }),
21
+ type: Lazy.of(() => setParent(options.type(), nestedEntityMapType)),
30
22
  };
31
23
  return nestedEntityMapType;
32
24
  };
@@ -55,6 +47,6 @@ export const getReferencesForNestedEntityMapType = (type, value) => typeof value
55
47
  .flatMap(item => getReferencesForObjectType(type.type.value, item))
56
48
  .concat(Object.keys(value))
57
49
  : [];
58
- export const formatNestedEntityMapValue = (_type, value) => typeof value === "object" && value !== null && !Array.isArray(value)
59
- ? sortObjectKeysAlphabetically(value)
50
+ export const formatNestedEntityMapValue = (type, value) => typeof value === "object" && value !== null && !Array.isArray(value)
51
+ ? sortObjectKeysAlphabetically(Object.fromEntries(Object.entries(value).map(([key, item]) => [key, formatValue(type.type.value, item)])))
60
52
  : value;
@@ -1,8 +1,9 @@
1
- import { GetNestedDeclarations } from "../../declarations/Declaration.js";
2
- import { EntityDecl } from "../../declarations/EntityDecl.js";
3
- import { GetReferences, Node, NodeKind, Serializer } from "../../Node.js";
4
- import { Validator } from "../../validation/type.js";
5
- import { BaseType, SerializedBaseType, StructureFormatter, Type } from "../Type.js";
1
+ import type { GetNestedDeclarations } from "../../declarations/Declaration.js";
2
+ import type { EntityDecl } from "../../declarations/EntityDecl.js";
3
+ import type { GetReferences, Node, Serializer } from "../../Node.js";
4
+ import { NodeKind } from "../../Node.js";
5
+ import type { Validator } from "../../validation/type.js";
6
+ import type { BaseType, SerializedBaseType, StructureFormatter, Type } from "../Type.js";
6
7
  export interface ReferenceIdentifierType extends BaseType {
7
8
  kind: NodeKind["ReferenceIdentifierType"];
8
9
  entity: EntityDecl;
@@ -16,7 +17,7 @@ export { ReferenceIdentifierType as ReferenceIdentifier };
16
17
  export declare const isReferenceIdentifierType: (node: Node) => node is ReferenceIdentifierType;
17
18
  export declare const getNestedDeclarationsInReferenceIdentifierType: GetNestedDeclarations<ReferenceIdentifierType>;
18
19
  export declare const validateReferenceIdentifierType: Validator<ReferenceIdentifierType>;
19
- export declare const resolveTypeArgumentsInReferenceIdentifierType: <Args extends Record<string, Type>>(_args: Args, type: ReferenceIdentifierType) => ReferenceIdentifierType;
20
+ export declare const resolveTypeArgumentsInReferenceIdentifierType: (_args: Record<string, Type>, type: ReferenceIdentifierType) => ReferenceIdentifierType;
20
21
  export declare const serializeReferenceIdentifierType: Serializer<ReferenceIdentifierType, SerializedReferenceIdentifierType>;
21
22
  export declare const getReferencesForReferenceIdentifierType: GetReferences<ReferenceIdentifierType>;
22
23
  export declare const formatReferenceIdentifierValue: StructureFormatter<ReferenceIdentifierType>;
@@ -1,7 +1,7 @@
1
1
  import { getNestedDeclarations } from "../../declarations/Declaration.js";
2
2
  import { createEntityIdentifierType } from "../../declarations/EntityDecl.js";
3
3
  import { NodeKind } from "../../Node.js";
4
- import { removeParentKey, validate, } from "../Type.js";
4
+ import { removeParentKey, validate } from "../Type.js";
5
5
  export const ReferenceIdentifierType = (entity) => ({
6
6
  kind: NodeKind.ReferenceIdentifierType,
7
7
  entity,
@@ -0,0 +1,23 @@
1
+ import type { GetReferences, Node, Serializer } from "../../Node.js";
2
+ import { NodeKind } from "../../Node.js";
3
+ import type { SerializedTypeParameter, TypeParameter } from "../../TypeParameter.js";
4
+ import type { Validator } from "../../validation/type.js";
5
+ import type { BaseType, SerializedBaseType, StructureFormatter, Type } from "../Type.js";
6
+ type TConstraint = TypeParameter;
7
+ export interface TypeArgumentType<T extends TConstraint = TConstraint> extends BaseType {
8
+ kind: NodeKind["TypeArgumentType"];
9
+ argument: T;
10
+ }
11
+ type TSerializedConstraint = SerializedTypeParameter;
12
+ export interface SerializedTypeArgumentType<T extends TSerializedConstraint = TSerializedConstraint> extends SerializedBaseType {
13
+ kind: NodeKind["TypeArgumentType"];
14
+ argument: T;
15
+ }
16
+ export declare const TypeArgumentType: <T extends TConstraint>(argument: T) => TypeArgumentType<T>;
17
+ export { TypeArgumentType as TypeArgument };
18
+ export declare const isTypeArgumentType: (node: Node) => node is TypeArgumentType;
19
+ export declare const validateTypeArgumentType: Validator<TypeArgumentType>;
20
+ export declare const resolveTypeArgumentsInTypeArgumentType: <T extends TConstraint, Args extends Record<string, Type>>(args: Args, type: TypeArgumentType<T>) => Args[T["name"]];
21
+ export declare const serializeTypeArgumentType: Serializer<TypeArgumentType, SerializedTypeArgumentType>;
22
+ export declare const getReferencesForTypeArgumentType: GetReferences<TypeArgumentType>;
23
+ export declare const formatTypeArgumentValue: StructureFormatter<TypeArgumentType>;
@@ -0,0 +1,19 @@
1
+ import { NodeKind } from "../../Node.js";
2
+ import { serializeTypeParameter } from "../../TypeParameter.js";
3
+ import { removeParentKey } from "../Type.js";
4
+ export const TypeArgumentType = (argument) => ({
5
+ kind: NodeKind.TypeArgumentType,
6
+ argument,
7
+ });
8
+ export { TypeArgumentType as TypeArgument };
9
+ export const isTypeArgumentType = (node) => node.kind === NodeKind.TypeArgumentType;
10
+ export const validateTypeArgumentType = (_helpers, type, _value) => {
11
+ throw new TypeError(`generic argument "${type.argument.name}" has not been replaced with a concrete type`);
12
+ };
13
+ export const resolveTypeArgumentsInTypeArgumentType = (args, type) => args[type.argument.name];
14
+ export const serializeTypeArgumentType = type => ({
15
+ ...removeParentKey(type),
16
+ argument: serializeTypeParameter(type.argument),
17
+ });
18
+ export const getReferencesForTypeArgumentType = (_type, _value) => [];
19
+ export const formatTypeArgumentValue = (_type, value) => value;
@@ -0,0 +1,4 @@
1
+ import type { Validators } from "../Node.js";
2
+ import type { Type } from "../types/Type.js";
3
+ export type ValidatorHelpers = Validators;
4
+ export type Validator<T extends Type, Args extends unknown[] = []> = (helpers: ValidatorHelpers, type: T, value: unknown, ...args: Args) => Error[];
@@ -1,10 +1,11 @@
1
1
  import Debug from "debug";
2
2
  import express from "express";
3
+ import { getInstanceContainerOverview } from "../../../shared/utils/instances.js";
4
+ import { isOk } from "../../../shared/utils/result.js";
3
5
  import { serializeDecl } from "../../schema/declarations/Declaration.js";
4
- import { isEntityDecl } from "../../schema/declarations/EntityDecl.js";
6
+ import { isEntityDecl, serializeEntityDecl } from "../../schema/declarations/EntityDecl.js";
5
7
  import { isEnumDecl } from "../../schema/declarations/EnumDecl.js";
6
8
  import { isTypeAliasDecl } from "../../schema/declarations/TypeAliasDecl.js";
7
- import { isOk } from "../../utils/result.js";
8
9
  import { createInstance, deleteInstance, updateInstance } from "./instanceOperations.js";
9
10
  const debug = Debug("tsondb:server:api:declarations");
10
11
  export const declarationsApi = express.Router();
@@ -59,8 +60,11 @@ declarationsApi.get("/:name/instances", (req, res) => {
59
60
  res.status(400).send(`Declaration "${decl.name}" is not an entity`);
60
61
  return;
61
62
  }
63
+ const serializedEntityDecl = serializeEntityDecl(decl);
62
64
  const body = {
63
- instances: req.instancesByEntityName[req.params.name] ?? [],
65
+ instances: req.instancesByEntityName[req.params.name]
66
+ ?.map(instanceContainer => getInstanceContainerOverview(serializedEntityDecl, instanceContainer, req.locales))
67
+ .toSorted((a, b) => a.displayName.localeCompare(b.displayName)) ?? [],
64
68
  isLocaleEntity: decl === req.localeEntity,
65
69
  };
66
70
  res.json(body);
@@ -1,9 +1,9 @@
1
1
  import Debug from "debug";
2
- import express from "express";
2
+ import express, {} from "express";
3
3
  import { join } from "node:path";
4
+ import { hasFileChanges } from "../../../shared/utils/git.js";
5
+ import { getInstanceContainerOverview } from "../../../shared/utils/instances.js";
4
6
  import { serializeEntityDecl } from "../../schema/index.js";
5
- import { hasFileChanges } from "../../shared/utils/git.js";
6
- import { getInstanceContainerOverview } from "../../shared/utils/instances.js";
7
7
  import { attachGitStatusToInstancesByEntityName } from "../../utils/instances.js";
8
8
  import { reinit } from "../init.js";
9
9
  const debug = Debug("tsondb:server:api:git");
@@ -17,9 +17,10 @@ gitApi.use((req, res, next) => {
17
17
  next();
18
18
  });
19
19
  gitApi.get("/status", async (req, res) => {
20
- const locales = (Array.isArray(req.query["locales"]) ? req.query["locales"] : [req.query["locales"]]).filter(locale => typeof locale === "string");
21
20
  const status = await req.git.status();
22
- attachGitStatusToInstancesByEntityName(req.instancesByEntityName, req.dataRoot, req.gitRoot, status);
21
+ attachGitStatusToInstancesByEntityName(req.instancesByEntityName, req.dataRoot,
22
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
23
+ req.gitRoot, status);
23
24
  const body = {
24
25
  commitsAhead: status.ahead,
25
26
  commitsBehind: status.behind,
@@ -27,7 +28,9 @@ gitApi.get("/status", async (req, res) => {
27
28
  entityName,
28
29
  instances
29
30
  .filter(instance => hasFileChanges(instance.gitStatus))
30
- .map(instance => getInstanceContainerOverview(serializeEntityDecl(req.entitiesByName[entityName]), instance, locales)),
31
+ .map(instance => getInstanceContainerOverview(
32
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
33
+ serializeEntityDecl(req.entitiesByName[entityName]), instance, req.locales)),
31
34
  ])),
32
35
  };
33
36
  res.json(body);
@@ -118,7 +121,7 @@ gitApi.post("/commit", async (req, res) => {
118
121
  await req.git.commit(message);
119
122
  res.status(200).send("Commit successful");
120
123
  }
121
- catch (error) {
124
+ catch {
122
125
  res.status(500).send("Commit failed");
123
126
  }
124
127
  });
@@ -127,7 +130,7 @@ gitApi.post("/push", async (req, res) => {
127
130
  await req.git.push();
128
131
  res.status(200).send("Push successful");
129
132
  }
130
- catch (error) {
133
+ catch {
131
134
  res.status(500).send("Push failed");
132
135
  }
133
136
  });
@@ -136,7 +139,7 @@ gitApi.post("/pull", async (req, res) => {
136
139
  await req.git.pull();
137
140
  res.status(200).send("Pull successful");
138
141
  }
139
- catch (error) {
142
+ catch {
140
143
  res.status(500).send("Pull failed");
141
144
  }
142
145
  });
@@ -159,7 +162,7 @@ gitApi.post("/branch", async (req, res) => {
159
162
  await reinit(req);
160
163
  res.status(200).send(`Creation of branch "${branchName}" successful`);
161
164
  }
162
- catch (error) {
165
+ catch {
163
166
  res.status(500).send(`Creation of branch "${branchName}" failed`);
164
167
  }
165
168
  });
@@ -168,7 +171,7 @@ gitApi.post("/branch/:branchName", async (req, res) => {
168
171
  await req.git.checkout(req.params.branchName);
169
172
  res.status(200).send(`Switch to branch "${req.params.branchName}" successful`);
170
173
  }
171
- catch (error) {
174
+ catch {
172
175
  res.status(500).send(`Switch to branch "${req.params.branchName}" failed`);
173
176
  }
174
177
  });
@@ -1,6 +1,6 @@
1
- import { InstanceContainer } from "../../shared/utils/instances.js";
2
- import { Result } from "../../utils/result.js";
3
- import { TSONDBRequestLocals } from "../index.js";
1
+ import type { InstanceContainer } from "../../../shared/utils/instances.js";
2
+ import type { Result } from "../../../shared/utils/result.js";
3
+ import type { TSONDBRequestLocals } from "../index.js";
4
4
  export declare const createInstance: (locals: TSONDBRequestLocals, entityName: string, instance: unknown, idQueryParam: unknown) => Promise<Result<InstanceContainer, [code: number, message: string]>>;
5
5
  export declare const updateInstance: (locals: TSONDBRequestLocals, entityName: string, instanceId: string, instance: unknown) => Promise<Result<InstanceContainer, [code: number, message: string]>>;
6
6
  export declare const deleteInstance: (locals: TSONDBRequestLocals, entityName: string, instanceId: string) => Promise<Result<InstanceContainer, [code: number, message: string]>>;
@@ -1,16 +1,19 @@
1
1
  import { rm, writeFile } from "node:fs/promises";
2
2
  import { join } from "node:path";
3
3
  import { v4 as uuidv4 } from "uuid";
4
+ import { removeAt } from "../../../shared/utils/array.js";
5
+ import { error, ok } from "../../../shared/utils/result.js";
4
6
  import { validateEntityDecl } from "../../schema/declarations/EntityDecl.js";
5
- import { formatValue } from "../../schema/index.js";
6
7
  import { createValidators } from "../../schema/Node.js";
7
- import { removeAt } from "../../shared/utils/array.js";
8
8
  import { getErrorMessageForDisplay } from "../../utils/error.js";
9
9
  import { getGitFileStatusFromStatusResult } from "../../utils/git.js";
10
+ import { formatInstance } from "../../utils/instances.js";
10
11
  import { updateReferencesToInstances } from "../../utils/references.js";
11
- import { error, ok } from "../../utils/result.js";
12
12
  export const createInstance = async (locals, entityName, instance, idQueryParam) => {
13
13
  const entity = locals.entitiesByName[entityName];
14
+ if (entity === undefined) {
15
+ return error([400, "Entity not found"]);
16
+ }
14
17
  const validationErrors = validateEntityDecl(createValidators(locals.instancesByEntityName), entity, instance);
15
18
  if (validationErrors.length > 0) {
16
19
  return error([400, validationErrors.map(getErrorMessageForDisplay).join("\n\n")]);
@@ -20,11 +23,13 @@ export const createInstance = async (locals, entityName, instance, idQueryParam)
20
23
  }
21
24
  const id = locals.localeEntity === entity ? idQueryParam : uuidv4();
22
25
  if (locals.localeEntity === entity &&
23
- locals.instancesByEntityName[entity.name].some(instance => instance.id === id)) {
26
+ locals.instancesByEntityName[entity.name]?.some(instance => instance.id === id)) {
24
27
  return error([400, `Duplicate id "${id}" for locale entity`]);
25
28
  }
26
29
  const fileName = `${id}.json`;
27
- await writeFile(join(locals.dataRoot, entity.name, fileName), JSON.stringify(formatValue(entity.type.value, instance), undefined, 2), { encoding: "utf-8" });
30
+ await writeFile(join(locals.dataRoot, entity.name, fileName), formatInstance(entity, instance), {
31
+ encoding: "utf-8",
32
+ });
28
33
  const instanceContainer = {
29
34
  fileName,
30
35
  id,
@@ -46,11 +51,14 @@ export const updateInstance = async (locals, entityName, instanceId, instance) =
46
51
  return error([404, "Instance not found"]);
47
52
  }
48
53
  const entity = locals.entitiesByName[entityName];
54
+ if (entity === undefined) {
55
+ return error([400, "Entity not found"]);
56
+ }
49
57
  const validationErrors = validateEntityDecl(createValidators(locals.instancesByEntityName), entity, instance);
50
58
  if (validationErrors.length > 0) {
51
59
  return error([400, validationErrors.map(getErrorMessageForDisplay).join("\n\n")]);
52
60
  }
53
- await writeFile(join(locals.dataRoot, entity.name, instanceContainer.fileName), JSON.stringify(formatValue(entity.type.value, instance), undefined, 2), { encoding: "utf-8" });
61
+ await writeFile(join(locals.dataRoot, entity.name, instanceContainer.fileName), formatInstance(entity, instance), { encoding: "utf-8" });
54
62
  const oldInstance = instanceContainer.content;
55
63
  instanceContainer.content = instance;
56
64
  instanceContainer.gitStatus =
@@ -77,6 +85,9 @@ export const deleteInstance = async (locals, entityName, instanceId) => {
77
85
  return ok(instanceContainer);
78
86
  }
79
87
  catch (err) {
80
- return error([500, `Failed to delete instance: ${err}`]);
88
+ return error([
89
+ 500,
90
+ `Failed to delete instance: ${err instanceof Error ? err.toString() : String(err)}`,
91
+ ]);
81
92
  }
82
93
  };
@@ -1,7 +1,7 @@
1
1
  import Debug from "debug";
2
2
  import express from "express";
3
+ import { getDisplayNameFromEntityInstance } from "../../../shared/utils/displayName.js";
3
4
  import { serializeEntityDecl } from "../../schema/declarations/EntityDecl.js";
4
- import { getDisplayNameFromEntityInstance } from "../../shared/utils/displayName.js";
5
5
  const debug = Debug("tsondb:server:api:instances");
6
6
  export const instancesApi = express.Router();
7
7
  instancesApi.use((req, _res, next) => {
@@ -11,11 +11,15 @@ instancesApi.use((req, _res, next) => {
11
11
  instancesApi.get("/", (req, res) => {
12
12
  const locales = (Array.isArray(req.query["locales"]) ? req.query["locales"] : [req.query["locales"]]).filter(locale => typeof locale === "string");
13
13
  const body = {
14
- instances: Object.fromEntries(Object.entries(req.instancesByEntityName).map(([entityName, instances]) => [
14
+ instances: Object.fromEntries(Object.entries(req.instancesByEntityName)
15
+ .filter(([entityName]) => Object.hasOwn(req.entitiesByName, entityName))
16
+ .map(([entityName, instances]) => [
15
17
  entityName,
16
18
  instances.map(instance => ({
17
19
  id: instance.id,
18
- name: getDisplayNameFromEntityInstance(serializeEntityDecl(req.entitiesByName[entityName]), instance.content, instance.id, locales),
20
+ name: getDisplayNameFromEntityInstance(
21
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
22
+ serializeEntityDecl(req.entitiesByName[entityName]), instance.content, instance.id, locales),
19
23
  })),
20
24
  ])),
21
25
  };
@@ -0,0 +1,28 @@
1
+ import type { SimpleGit } from "simple-git";
2
+ import type { InstancesByEntityName } from "../../shared/utils/instances.js";
3
+ import type { Schema } from "../Schema.ts";
4
+ import type { Decl } from "../schema/declarations/Declaration.js";
5
+ import type { EntityDecl } from "../schema/declarations/EntityDecl.js";
6
+ import type { ReferencesToInstances } from "../utils/references.js";
7
+ export type ServerOptions = {
8
+ port: number;
9
+ };
10
+ export interface TSONDBRequestLocals {
11
+ git: SimpleGit;
12
+ gitRoot: string | undefined;
13
+ dataRoot: string;
14
+ declarations: readonly Decl[];
15
+ entities: readonly EntityDecl[];
16
+ instancesByEntityName: InstancesByEntityName;
17
+ entitiesByName: Record<string, EntityDecl>;
18
+ localeEntity?: EntityDecl;
19
+ referencesToInstances: ReferencesToInstances;
20
+ locales: string[];
21
+ }
22
+ declare global {
23
+ namespace Express {
24
+ interface Request extends TSONDBRequestLocals {
25
+ }
26
+ }
27
+ }
28
+ export declare const createServer: (schema: Schema, dataRootPath: string, instancesByEntityName: InstancesByEntityName, options?: Partial<ServerOptions>) => Promise<void>;
@@ -5,19 +5,19 @@ import { api } from "./api/index.js";
5
5
  import { init } from "./init.js";
6
6
  const debug = Debug("tsondb:server");
7
7
  const defaultOptions = {
8
- name: "tsondb server",
9
8
  port: 3000,
10
9
  };
11
- export const createServer = async (modelContainer, instancesByEntityName, options) => {
12
- const { name, port } = { ...defaultOptions, ...options };
10
+ export const createServer = async (schema, dataRootPath, instancesByEntityName, options) => {
11
+ const { port } = { ...defaultOptions, ...options };
13
12
  const app = express();
14
- app.use(express.static(join(import.meta.dirname, "../../public")));
15
- app.use("/js/node_modules", express.static(join(import.meta.dirname, "../../node_modules")));
16
- app.use("/js/client", express.static(join(import.meta.dirname, "../../lib/client")));
17
- app.use("/js/shared", express.static(join(import.meta.dirname, "../../lib/shared")));
13
+ app.use(express.static(join(import.meta.dirname, "../../../public")));
14
+ app.use("/js/node_modules", express.static(join(import.meta.dirname, "../../../node_modules")));
15
+ app.use("/js/client", express.static(join(import.meta.dirname, "../../../lib/web")));
16
+ app.use("/js/shared", express.static(join(import.meta.dirname, "../../../lib/shared")));
18
17
  app.use(express.json());
19
- const requestLocals = await init(modelContainer, Object.assign({}, instancesByEntityName));
18
+ const requestLocals = await init(schema, dataRootPath, Object.assign({}, instancesByEntityName));
20
19
  app.use((req, _res, next) => {
20
+ debug("%s %s", req.method, req.originalUrl);
21
21
  Object.assign(req, requestLocals);
22
22
  next();
23
23
  });
@@ -30,9 +30,6 @@ export const createServer = async (modelContainer, instancesByEntityName, option
30
30
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
31
31
  <title>TSONDB</title>
32
32
  <link rel="stylesheet" href="/css/styles.css">
33
- </head>
34
- <body>
35
- <div id="app"></div>
36
33
  <script type="importmap">
37
34
  {
38
35
  "imports": {
@@ -43,11 +40,24 @@ export const createServer = async (modelContainer, instancesByEntityName, option
43
40
  }
44
41
  }
45
42
  </script>
43
+ </head>
44
+ <body>
45
+ <div id="app"></div>
46
46
  <script type="module" src="/js/client/index.js"></script>
47
47
  </body>
48
48
  </html>`);
49
49
  });
50
- app.listen(port, () => {
51
- debug(`${name} listening on http://localhost:${port}`);
50
+ app.listen(port, (error) => {
51
+ if (error) {
52
+ if (error.code === "EADDRINUSE") {
53
+ debug(`port ${port.toString()} is already in use`);
54
+ }
55
+ else {
56
+ debug("error starting server:", error);
57
+ }
58
+ }
59
+ else {
60
+ debug(`server listening on http://localhost:${port.toString()}`);
61
+ }
52
62
  });
53
63
  };
@@ -0,0 +1,5 @@
1
+ import type { InstancesByEntityName } from "../../shared/utils/instances.js";
2
+ import type { Schema } from "../Schema.ts";
3
+ import type { TSONDBRequestLocals } from "./index.js";
4
+ export declare const init: (schema: Schema, dataRootPath: string, instancesByEntityName: InstancesByEntityName) => Promise<TSONDBRequestLocals>;
5
+ export declare const reinit: (locals: TSONDBRequestLocals) => Promise<void>;
@@ -3,8 +3,8 @@ import { isEntityDecl } from "../schema/declarations/EntityDecl.js";
3
3
  import { resolveTypeArgumentsInDecls } from "../schema/index.js";
4
4
  import { attachGitStatusToInstancesByEntityName, getInstancesByEntityName, } from "../utils/instances.js";
5
5
  import { getReferencesToInstances } from "../utils/references.js";
6
- const getGit = async (modelContainer) => {
7
- const git = simpleGit({ baseDir: modelContainer.dataRootPath });
6
+ const getGit = async (dataRootPath) => {
7
+ const git = simpleGit({ baseDir: dataRootPath });
8
8
  if (await git.checkIsRepo()) {
9
9
  try {
10
10
  const root = await git.revparse({ "--show-toplevel": null });
@@ -19,26 +19,27 @@ const getGit = async (modelContainer) => {
19
19
  return { git };
20
20
  }
21
21
  };
22
- export const init = async (modelContainer, instancesByEntityName) => {
23
- const { git, root: gitRoot, status: gitStatus } = await getGit(modelContainer);
24
- const declarations = resolveTypeArgumentsInDecls(modelContainer.schema.declarations);
22
+ export const init = async (schema, dataRootPath, instancesByEntityName) => {
23
+ const { git, root: gitRoot, status: gitStatus } = await getGit(dataRootPath);
24
+ const declarations = resolveTypeArgumentsInDecls(schema.declarations);
25
25
  const entities = declarations.filter(isEntityDecl);
26
26
  const entitiesByName = Object.fromEntries(entities.map(entity => [entity.name, entity]));
27
27
  const instancesByEntityNameInMemory = Object.assign({}, instancesByEntityName);
28
28
  const referencesToInstances = getReferencesToInstances(instancesByEntityName, entitiesByName);
29
29
  if (gitStatus) {
30
- attachGitStatusToInstancesByEntityName(instancesByEntityName, modelContainer.dataRootPath, gitRoot, gitStatus);
30
+ attachGitStatusToInstancesByEntityName(instancesByEntityName, dataRootPath, gitRoot, gitStatus);
31
31
  }
32
32
  const requestLocals = {
33
33
  git: git,
34
34
  gitRoot: gitRoot,
35
- dataRoot: modelContainer.dataRootPath,
35
+ dataRoot: dataRootPath,
36
36
  declarations: declarations,
37
37
  entities: entities,
38
38
  instancesByEntityName: instancesByEntityNameInMemory,
39
39
  entitiesByName: entitiesByName,
40
- localeEntity: modelContainer.schema.localeEntity,
40
+ localeEntity: schema.localeEntity,
41
41
  referencesToInstances,
42
+ locales: ["de-DE", "en-US"], // TODO: Make this configurable
42
43
  };
43
44
  return requestLocals;
44
45
  };
@@ -1,7 +1,10 @@
1
1
  import { applyIndentation } from "./render.js";
2
2
  export const getErrorMessageForDisplay = (error) => {
3
3
  if (error instanceof AggregateError) {
4
- return `${error.message}\n${applyIndentation(1, error.errors.map(subError => getErrorMessageForDisplay(subError)).join("\n"), 2)}`;
4
+ return `${error.message}\n${applyIndentation(1, error.errors
5
+ .filter(subError => subError instanceof Error)
6
+ .map(subError => getErrorMessageForDisplay(subError))
7
+ .join("\n"), 2)}`;
5
8
  }
6
9
  else if (error.cause instanceof Error) {
7
10
  return `${error.message}\n${applyIndentation(1, getErrorMessageForDisplay(error.cause), 2)}`;
@@ -1,3 +1,3 @@
1
- import { StatusResult } from "simple-git";
2
- import { GitFileStatus } from "../shared/utils/git.js";
1
+ import type { StatusResult } from "simple-git";
2
+ import type { GitFileStatus } from "../../shared/utils/git.js";
3
3
  export declare const getGitFileStatusFromStatusResult: (statusResult: StatusResult, repoRoot: string, dataRoot: string, entityName: string, fileName: string) => GitFileStatus | undefined;