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
@@ -1,14 +1,16 @@
1
- import { Lazy } from "../../utils/lazy.js";
2
- import { Leaves } from "../../utils/object.js";
3
- import { GetReferences, Node, NodeKind, Serializer } from "../Node.js";
4
- import { MemberDecl, ObjectType, SerializedObjectType } from "../types/generic/ObjectType.js";
1
+ import { Lazy } from "../../../shared/utils/lazy.js";
2
+ import type { Leaves } from "../../../shared/utils/object.js";
3
+ import type { GetReferences, Node, Serializer } from "../Node.js";
4
+ import { NodeKind } from "../Node.js";
5
+ import type { MemberDecl, ObjectType, SerializedObjectType } from "../types/generic/ObjectType.js";
5
6
  import { StringType } from "../types/primitives/StringType.js";
6
- import { AsType, SerializedAsType, Type } from "../types/Type.js";
7
- import { ValidatorHelpers } from "../validation/type.js";
8
- import { BaseDecl, GetNestedDeclarations, SerializedBaseDecl } from "./Declaration.js";
7
+ import type { AsType, SerializedAsType } from "../types/Type.js";
8
+ import type { ValidatorHelpers } from "../validation/type.js";
9
+ import type { BaseDecl, GetNestedDeclarations, SerializedBaseDecl } from "./Declaration.js";
9
10
  import { TypeAliasDecl } from "./TypeAliasDecl.js";
10
11
  export interface EntityDecl<Name extends string = string, T extends ObjectType = ObjectType> extends BaseDecl<Name, []> {
11
12
  kind: NodeKind["EntityDecl"];
13
+ namePlural: string;
12
14
  type: Lazy<T>;
13
15
  /**
14
16
  * @default "name"
@@ -27,6 +29,7 @@ export interface EntityDecl<Name extends string = string, T extends ObjectType =
27
29
  }
28
30
  export interface SerializedEntityDecl<Name extends string = string, T extends SerializedObjectType = SerializedObjectType> extends SerializedBaseDecl<Name, []> {
29
31
  kind: NodeKind["EntityDecl"];
32
+ namePlural: string;
30
33
  type: T;
31
34
  /**
32
35
  * @default "name"
@@ -45,6 +48,7 @@ export interface SerializedEntityDecl<Name extends string = string, T extends Se
45
48
  }
46
49
  export declare const EntityDecl: <Name extends string, T extends ObjectType>(sourceUrl: string, options: {
47
50
  name: Name;
51
+ namePlural: string;
48
52
  comment?: string;
49
53
  type: () => T;
50
54
  /**
@@ -67,10 +71,10 @@ export declare const isEntityDecl: (node: Node) => node is EntityDecl;
67
71
  export declare const getNestedDeclarationsInEntityDecl: GetNestedDeclarations<EntityDecl>;
68
72
  export declare const validateEntityDecl: (helpers: ValidatorHelpers, decl: EntityDecl, value: unknown) => Error[];
69
73
  export declare const resolveTypeArgumentsInEntityDecl: (decl: EntityDecl) => EntityDecl;
70
- export declare const addEphemeralUUIDToType: <T extends Record<string, MemberDecl<Type, boolean>>>(decl: EntityDecl<string, ObjectType<T>>) => ObjectType<Omit<T, "id"> & {
74
+ export declare const addEphemeralUUIDToType: <T extends Record<string, MemberDecl>>(decl: EntityDecl<string, ObjectType<T>>) => ObjectType<Omit<T, "id"> & {
71
75
  id: MemberDecl<StringType, true>;
72
76
  }>;
73
77
  export declare const createEntityIdentifierType: () => StringType;
74
- export declare const createEntityIdentifierTypeAsDecl: <Name extends string>(decl: EntityDecl<Name, ObjectType>) => TypeAliasDecl<`${Name}_ID`, StringType, []>;
78
+ export declare const createEntityIdentifierTypeAsDecl: <Name extends string>(decl: EntityDecl<Name>) => TypeAliasDecl<`${Name}_ID`, StringType, []>;
75
79
  export declare const serializeEntityDecl: Serializer<EntityDecl, SerializedEntityDecl>;
76
80
  export declare const getReferencesForEntityDecl: GetReferences<EntityDecl>;
@@ -1,9 +1,9 @@
1
- import { Lazy } from "../../utils/lazy.js";
1
+ import { Lazy } from "../../../shared/utils/lazy.js";
2
2
  import { NodeKind } from "../Node.js";
3
3
  import { getNestedDeclarationsInObjectType, getReferencesForObjectType, Required, resolveTypeArgumentsInObjectType, serializeObjectType, } from "../types/generic/ObjectType.js";
4
4
  import { StringType } from "../types/primitives/StringType.js";
5
5
  import { validate } from "../types/Type.js";
6
- import { validateDeclName, } from "./Declaration.js";
6
+ import { validateDeclName } from "./Declaration.js";
7
7
  import { TypeAliasDecl } from "./TypeAliasDecl.js";
8
8
  export const EntityDecl = (sourceUrl, options) => {
9
9
  validateDeclName(options.name);
@@ -1,17 +1,20 @@
1
- import { Lazy } from "../../utils/lazy.js";
2
- import { GetReferences, Node, NodeKind, Serializer } from "../Node.js";
3
- import { SerializedTypeParameter, TypeParameter } from "../parameters/TypeParameter.js";
4
- import { SerializedType, Type } from "../types/Type.js";
5
- import { ValidatorHelpers } from "../validation/type.js";
6
- import { BaseDecl, GetNestedDeclarations, SerializedBaseDecl, TypeArguments } from "./Declaration.js";
1
+ import { Lazy } from "../../../shared/utils/lazy.js";
2
+ import type { GetReferences, Node, Serializer } from "../Node.js";
3
+ import { NodeKind } from "../Node.js";
4
+ import type { SerializedTypeParameter, TypeParameter } from "../TypeParameter.js";
5
+ import type { EnumCaseDecl, SerializedEnumCaseDecl, SerializedEnumType } from "../types/generic/EnumType.js";
6
+ import { EnumType } from "../types/generic/EnumType.js";
7
+ import type { Type } from "../types/Type.js";
8
+ import type { ValidatorHelpers } from "../validation/type.js";
9
+ import type { BaseDecl, GetNestedDeclarations, SerializedBaseDecl, TypeArguments } from "./Declaration.js";
7
10
  export interface EnumDecl<Name extends string = string, T extends Record<string, EnumCaseDecl> = Record<string, EnumCaseDecl>, Params extends TypeParameter[] = TypeParameter[]> extends BaseDecl<Name, Params> {
8
11
  kind: NodeKind["EnumDecl"];
9
- values: Lazy<T>;
12
+ type: Lazy<EnumType<T>>;
10
13
  isDeprecated?: boolean;
11
14
  }
12
15
  export interface SerializedEnumDecl<Name extends string = string, T extends Record<string, SerializedEnumCaseDecl> = Record<string, SerializedEnumCaseDecl>, Params extends SerializedTypeParameter[] = SerializedTypeParameter[]> extends SerializedBaseDecl<Name, Params> {
13
16
  kind: NodeKind["EnumDecl"];
14
- values: T;
17
+ type: SerializedEnumType<T>;
15
18
  isDeprecated?: boolean;
16
19
  }
17
20
  export declare const GenEnumDecl: <Name extends string, T extends Record<string, EnumCaseDecl>, Params extends TypeParameter[]>(sourceUrl: string, options: {
@@ -31,23 +34,5 @@ export declare const isEnumDecl: (node: Node) => node is EnumDecl;
31
34
  export declare const getNestedDeclarationsInEnumDecl: GetNestedDeclarations<EnumDecl>;
32
35
  export declare const validateEnumDecl: (helpers: ValidatorHelpers, decl: EnumDecl, args: Type[], value: unknown) => Error[];
33
36
  export declare const resolveTypeArgumentsInEnumDecl: <Params extends TypeParameter[]>(decl: EnumDecl<string, Record<string, EnumCaseDecl>, Params>, args: TypeArguments<Params>) => EnumDecl<string, Record<string, EnumCaseDecl>, []>;
34
- export interface EnumCaseDecl<T extends Type | null = Type | null> {
35
- kind: NodeKind["EnumCaseDecl"];
36
- type: T;
37
- comment?: string;
38
- isDeprecated?: boolean;
39
- }
40
- export interface SerializedEnumCaseDecl<T extends SerializedType | null = SerializedType | null> {
41
- kind: NodeKind["EnumCaseDecl"];
42
- type: T;
43
- comment?: string;
44
- isDeprecated?: boolean;
45
- }
46
- export declare const EnumCaseDecl: <T extends Type | null>(options: {
47
- type: T;
48
- comment?: string;
49
- isDeprecated?: boolean;
50
- }) => EnumCaseDecl<T>;
51
- export { EnumCaseDecl as EnumCase };
52
37
  export declare const serializeEnumDecl: Serializer<EnumDecl, SerializedEnumDecl>;
53
38
  export declare const getReferencesForEnumDecl: GetReferences<EnumDecl>;
@@ -0,0 +1,52 @@
1
+ import { Lazy } from "../../../shared/utils/lazy.js";
2
+ import { NodeKind } from "../Node.js";
3
+ import { serializeTypeParameter } from "../TypeParameter.js";
4
+ import { EnumType, getNestedDeclarationsInEnumType, getReferencesForEnumType, resolveTypeArgumentsInEnumType, serializeEnumType, validateEnumType, } from "../types/generic/EnumType.js";
5
+ import { getTypeArgumentsRecord, validateDeclName } from "./Declaration.js";
6
+ export const GenEnumDecl = (sourceUrl, options) => {
7
+ validateDeclName(options.name);
8
+ const decl = {
9
+ ...options,
10
+ kind: NodeKind.EnumDecl,
11
+ sourceUrl,
12
+ type: Lazy.of(() => {
13
+ const type = EnumType(options.values(...options.parameters));
14
+ type.parent = decl;
15
+ return type;
16
+ }),
17
+ };
18
+ return decl;
19
+ };
20
+ export { GenEnumDecl as GenEnum };
21
+ export const EnumDecl = (sourceUrl, options) => {
22
+ validateDeclName(options.name);
23
+ const decl = {
24
+ ...options,
25
+ kind: NodeKind.EnumDecl,
26
+ sourceUrl,
27
+ parameters: [],
28
+ type: Lazy.of(() => {
29
+ const type = EnumType(options.values());
30
+ type.parent = decl;
31
+ return type;
32
+ }),
33
+ };
34
+ return decl;
35
+ };
36
+ export { EnumDecl as Enum };
37
+ export const isEnumDecl = (node) => node.kind === NodeKind.EnumDecl;
38
+ export const getNestedDeclarationsInEnumDecl = (addedDecls, decl) => getNestedDeclarationsInEnumType(addedDecls, decl.type.value);
39
+ export const validateEnumDecl = (helpers, decl, args, value) => validateEnumType(helpers, resolveTypeArgumentsInEnumType(getTypeArgumentsRecord(decl, args), decl.type.value), value);
40
+ export const resolveTypeArgumentsInEnumDecl = (decl, args) => {
41
+ const resolvedArgs = getTypeArgumentsRecord(decl, args);
42
+ return EnumDecl(decl.sourceUrl, {
43
+ ...decl,
44
+ values: () => resolveTypeArgumentsInEnumType(resolvedArgs, decl.type.value).values,
45
+ });
46
+ };
47
+ export const serializeEnumDecl = decl => ({
48
+ ...decl,
49
+ type: serializeEnumType(decl.type.value),
50
+ parameters: decl.parameters.map(param => serializeTypeParameter(param)),
51
+ });
52
+ export const getReferencesForEnumDecl = (decl, value) => getReferencesForEnumType(decl.type.value, value);
@@ -1,9 +1,10 @@
1
- import { Lazy } from "../../utils/lazy.js";
2
- import { GetReferences, Node, NodeKind, Serializer } from "../Node.js";
3
- import { SerializedTypeParameter, TypeParameter } from "../parameters/TypeParameter.js";
4
- import { SerializedType, Type } from "../types/Type.js";
5
- import { ValidatorHelpers } from "../validation/type.js";
6
- import { BaseDecl, GetNestedDeclarations, SerializedBaseDecl, TypeArguments } from "./Declaration.js";
1
+ import { Lazy } from "../../../shared/utils/lazy.js";
2
+ import type { GetReferences, Node, Serializer } from "../Node.js";
3
+ import { NodeKind } from "../Node.js";
4
+ import type { SerializedTypeParameter, TypeParameter } from "../TypeParameter.js";
5
+ import type { SerializedType, Type } from "../types/Type.js";
6
+ import type { ValidatorHelpers } from "../validation/type.js";
7
+ import type { BaseDecl, GetNestedDeclarations, SerializedBaseDecl, TypeArguments } from "./Declaration.js";
7
8
  export interface TypeAliasDecl<Name extends string = string, T extends Type = Type, Params extends TypeParameter[] = TypeParameter[]> extends BaseDecl<Name, Params> {
8
9
  kind: NodeKind["TypeAliasDecl"];
9
10
  type: Lazy<T>;
@@ -29,7 +30,7 @@ export declare const TypeAliasDecl: <Name extends string, T extends Type>(source
29
30
  type: () => T;
30
31
  }) => TypeAliasDecl<Name, T, []>;
31
32
  export { TypeAliasDecl as TypeAlias };
32
- export declare const isTypeAliasDecl: (node: Node) => node is TypeAliasDecl<string, Type, TypeParameter[]>;
33
+ export declare const isTypeAliasDecl: (node: Node) => node is TypeAliasDecl;
33
34
  export declare const getNestedDeclarationsInTypeAliasDecl: GetNestedDeclarations<TypeAliasDecl>;
34
35
  export declare const validateTypeAliasDecl: <Params extends TypeParameter[]>(helpers: ValidatorHelpers, decl: TypeAliasDecl<string, Type, Params>, args: TypeArguments<Params>, value: unknown) => Error[];
35
36
  export declare const resolveTypeArgumentsInTypeAliasDecl: <Params extends TypeParameter[]>(decl: TypeAliasDecl<string, Type, Params>, args: TypeArguments<Params>) => TypeAliasDecl<string, Type, []>;
@@ -1,8 +1,8 @@
1
- import { Lazy } from "../../utils/lazy.js";
1
+ import { Lazy } from "../../../shared/utils/lazy.js";
2
2
  import { NodeKind } from "../Node.js";
3
- import { serializeTypeParameter, } from "../parameters/TypeParameter.js";
3
+ import { serializeTypeParameter } from "../TypeParameter.js";
4
4
  import { getReferencesForType, resolveTypeArgumentsInType, serializeType, validate, } from "../types/Type.js";
5
- import { getNestedDeclarations, getTypeArgumentsRecord, validateDeclName, } from "./Declaration.js";
5
+ import { getNestedDeclarations, getTypeArgumentsRecord, validateDeclName } from "./Declaration.js";
6
6
  export const GenTypeAliasDecl = (sourceUrl, options) => {
7
7
  validateDeclName(options.name);
8
8
  const decl = {
@@ -3,18 +3,19 @@ export * from "./declarations/EntityDecl.js";
3
3
  export * from "./declarations/EnumDecl.js";
4
4
  export * from "./declarations/TypeAliasDecl.js";
5
5
  export * from "./Node.js";
6
- export * from "./parameters/TypeParameter.js";
6
+ export * from "./TypeParameter.js";
7
7
  export * from "./types/generic/ArrayType.js";
8
+ export * from "./types/generic/EnumType.js";
8
9
  export * from "./types/generic/ObjectType.js";
9
10
  export * from "./types/primitives/BooleanType.js";
10
11
  export * from "./types/primitives/DateType.js";
11
12
  export * from "./types/primitives/FloatType.js";
12
13
  export * from "./types/primitives/IntegerType.js";
13
14
  export * from "./types/primitives/NumericType.js";
14
- export * from "./types/primitives/PrimitiveType.js";
15
+ export type * from "./types/primitives/PrimitiveType.js";
15
16
  export * from "./types/primitives/StringType.js";
16
- export * from "./types/references/GenericArgumentIdentifierType.js";
17
17
  export * from "./types/references/IncludeIdentifierType.js";
18
18
  export * from "./types/references/NestedEntityMapType.js";
19
19
  export * from "./types/references/ReferenceIdentifierType.js";
20
+ export * from "./types/references/TypeArgumentType.js";
20
21
  export * from "./types/Type.js";
@@ -3,18 +3,18 @@ export * from "./declarations/EntityDecl.js";
3
3
  export * from "./declarations/EnumDecl.js";
4
4
  export * from "./declarations/TypeAliasDecl.js";
5
5
  export * from "./Node.js";
6
- export * from "./parameters/TypeParameter.js";
6
+ export * from "./TypeParameter.js";
7
7
  export * from "./types/generic/ArrayType.js";
8
+ export * from "./types/generic/EnumType.js";
8
9
  export * from "./types/generic/ObjectType.js";
9
10
  export * from "./types/primitives/BooleanType.js";
10
11
  export * from "./types/primitives/DateType.js";
11
12
  export * from "./types/primitives/FloatType.js";
12
13
  export * from "./types/primitives/IntegerType.js";
13
14
  export * from "./types/primitives/NumericType.js";
14
- export * from "./types/primitives/PrimitiveType.js";
15
15
  export * from "./types/primitives/StringType.js";
16
- export * from "./types/references/GenericArgumentIdentifierType.js";
17
16
  export * from "./types/references/IncludeIdentifierType.js";
18
17
  export * from "./types/references/NestedEntityMapType.js";
19
18
  export * from "./types/references/ReferenceIdentifierType.js";
19
+ export * from "./types/references/TypeArgumentType.js";
20
20
  export * from "./types/Type.js";
@@ -0,0 +1,48 @@
1
+ import type { Decl } from "../declarations/Declaration.js";
2
+ import type { BaseNode, GetReferences, Serializer } from "../Node.js";
3
+ import type { Validator } from "../validation/type.js";
4
+ import type { ArrayType, SerializedArrayType } from "./generic/ArrayType.js";
5
+ import type { EnumType, SerializedEnumType } from "./generic/EnumType.js";
6
+ import type { MemberDecl, ObjectType, SerializedMemberDecl, SerializedObjectType } from "./generic/ObjectType.js";
7
+ import type { BooleanType, SerializedBooleanType } from "./primitives/BooleanType.js";
8
+ import type { DateType, SerializedDateType } from "./primitives/DateType.js";
9
+ import type { FloatType, SerializedFloatType } from "./primitives/FloatType.js";
10
+ import type { IntegerType, SerializedIntegerType } from "./primitives/IntegerType.js";
11
+ import type { PrimitiveType, SerializedPrimitiveType } from "./primitives/PrimitiveType.js";
12
+ import type { SerializedStringType, StringType } from "./primitives/StringType.js";
13
+ import type { IncludeIdentifierType, SerializedIncludeIdentifierType } from "./references/IncludeIdentifierType.js";
14
+ import type { NestedEntityMapType, SerializedNestedEntityMapType } from "./references/NestedEntityMapType.js";
15
+ import type { ReferenceIdentifierType, SerializedReferenceIdentifierType } from "./references/ReferenceIdentifierType.js";
16
+ import type { SerializedTypeArgumentType, TypeArgumentType } from "./references/TypeArgumentType.js";
17
+ export interface BaseType extends BaseNode {
18
+ /**
19
+ * The parent node of this type will be set when the type is used in a declaration or nested in another type.
20
+ */
21
+ parent?: Type | Decl;
22
+ }
23
+ export interface SerializedBaseType extends BaseNode {
24
+ }
25
+ export type Type = PrimitiveType | ArrayType | ObjectType | TypeArgumentType | ReferenceIdentifierType | IncludeIdentifierType | NestedEntityMapType | EnumType;
26
+ export type SerializedType = SerializedPrimitiveType | SerializedArrayType | SerializedObjectType | SerializedTypeArgumentType | SerializedReferenceIdentifierType | SerializedIncludeIdentifierType | SerializedNestedEntityMapType | SerializedEnumType;
27
+ export declare const validate: Validator<Type>;
28
+ export declare const resolveTypeArgumentsInType: (args: Record<string, Type>, type: Type) => Type;
29
+ export declare function walkTypeNodeTree(callbackFn: (type: Type) => void, type: Type): void;
30
+ export type AsType<T extends Type> = T extends ArrayType<infer I> ? AsType<I>[] : T extends ObjectType<infer P> ? {
31
+ [K in keyof P]: P[K] extends MemberDecl<Type, true> ? AsType<P[K]["type"]> : AsType<P[K]["type"]> | undefined;
32
+ } : T extends BooleanType ? boolean : T extends DateType ? Date : T extends FloatType ? number : T extends IntegerType ? number : T extends StringType ? string : T extends TypeArgumentType ? unknown : T extends IncludeIdentifierType ? unknown : T extends NestedEntityMapType ? unknown : T extends ReferenceIdentifierType ? unknown : never;
33
+ export type SerializedAsType<T extends SerializedType> = T extends SerializedArrayType<infer I> ? SerializedAsType<I>[] : T extends SerializedObjectType<infer P> ? {
34
+ [K in keyof P]: P[K] extends SerializedMemberDecl<SerializedType, true> ? SerializedAsType<P[K]["type"]> : SerializedAsType<P[K]["type"]> | undefined;
35
+ } : T extends SerializedBooleanType ? boolean : T extends SerializedDateType ? Date : T extends SerializedFloatType ? number : T extends SerializedIntegerType ? number : T extends SerializedStringType ? string : T extends SerializedTypeArgumentType ? unknown : T extends SerializedIncludeIdentifierType ? unknown : T extends SerializedNestedEntityMapType ? unknown : T extends SerializedReferenceIdentifierType ? unknown : never;
36
+ export type AsNode<T> = T extends (infer I)[] ? ArrayType<AsNode<I>> : T extends Record<string, unknown> ? ObjectType<{
37
+ [K in keyof T]: T[K] extends MemberDecl ? T[K] : T extends null | undefined ? MemberDecl<AsNode<NonNullable<T[K]>>, false> : MemberDecl<AsNode<T[K]>, true>;
38
+ }> : T extends string ? StringType : T extends number ? FloatType : T extends boolean ? BooleanType : never;
39
+ export declare const getParentDecl: (type: Type) => Decl | undefined;
40
+ export declare const findTypeAtPath: (type: Type, path: string[]) => Type | undefined;
41
+ export declare const serializeType: Serializer<Type, SerializedType>;
42
+ export declare const removeParentKey: <T extends BaseType>(type: T) => Omit<T, "parent">;
43
+ export declare const getReferencesForType: GetReferences<Type>;
44
+ /**
45
+ * Format the structure of a value to always look the same when serialized as JSON.
46
+ */
47
+ export type StructureFormatter<T extends Type> = (type: T, value: unknown) => unknown;
48
+ export declare const formatValue: StructureFormatter<Type>;
@@ -1,17 +1,18 @@
1
- import { assertExhaustive } from "../../shared/utils/typeSafety.js";
1
+ import { assertExhaustive } from "../../../shared/utils/typeSafety.js";
2
2
  import { isDecl } from "../declarations/Declaration.js";
3
3
  import { NodeKind } from "../Node.js";
4
- import { getReferencesForArrayType, resolveTypeArgumentsInArrayType, serializeArrayType, validateArrayType, } from "./generic/ArrayType.js";
5
- import { getReferencesForObjectType, resolveTypeArgumentsInObjectType, serializeObjectType, validateObjectType, } from "./generic/ObjectType.js";
6
- import { getReferencesForBooleanType, serializeBooleanType, validateBooleanType, } from "./primitives/BooleanType.js";
7
- import { getReferencesForDateType, serializeDateType, validateDateType, } from "./primitives/DateType.js";
8
- import { getReferencesForFloatType, serializeFloatType, validateFloatType, } from "./primitives/FloatType.js";
9
- import { getReferencesForIntegerType, serializeIntegerType, validateIntegerType, } from "./primitives/IntegerType.js";
10
- import { getReferencesForStringType, serializeStringType, validateStringType, } from "./primitives/StringType.js";
11
- import { getReferencesForGenericArgumentIdentifierType, resolveTypeArgumentsInGenericArgumentIdentifierType, serializeGenericArgumentIdentifierType, validateGenericArgumentIdentifierType, } from "./references/GenericArgumentIdentifierType.js";
12
- import { getReferencesForIncludeIdentifierType, resolveTypeArgumentsInIncludeIdentifierType, serializeIncludeIdentifierType, validateIncludeIdentifierType, } from "./references/IncludeIdentifierType.js";
13
- import { getReferencesForNestedEntityMapType, resolveTypeArgumentsInNestedEntityMapType, serializeNestedEntityMapType, validateNestedEntityMapType, } from "./references/NestedEntityMapType.js";
14
- import { getReferencesForReferenceIdentifierType, resolveTypeArgumentsInReferenceIdentifierType, serializeReferenceIdentifierType, validateReferenceIdentifierType, } from "./references/ReferenceIdentifierType.js";
4
+ import { formatArrayValue, getReferencesForArrayType, resolveTypeArgumentsInArrayType, serializeArrayType, validateArrayType, } from "./generic/ArrayType.js";
5
+ import { formatEnumType, getReferencesForEnumType, resolveTypeArgumentsInEnumType, serializeEnumType, validateEnumType, } from "./generic/EnumType.js";
6
+ import { formatObjectValue, getReferencesForObjectType, resolveTypeArgumentsInObjectType, serializeObjectType, validateObjectType, } from "./generic/ObjectType.js";
7
+ import { formatBooleanValue, getReferencesForBooleanType, serializeBooleanType, validateBooleanType, } from "./primitives/BooleanType.js";
8
+ import { formatDateValue, getReferencesForDateType, serializeDateType, validateDateType, } from "./primitives/DateType.js";
9
+ import { formatFloatValue, getReferencesForFloatType, serializeFloatType, validateFloatType, } from "./primitives/FloatType.js";
10
+ import { formatIntegerValue, getReferencesForIntegerType, serializeIntegerType, validateIntegerType, } from "./primitives/IntegerType.js";
11
+ import { formatStringValue, getReferencesForStringType, serializeStringType, validateStringType, } from "./primitives/StringType.js";
12
+ import { formatIncludeIdentifierValue, getReferencesForIncludeIdentifierType, resolveTypeArgumentsInIncludeIdentifierType, serializeIncludeIdentifierType, validateIncludeIdentifierType, } from "./references/IncludeIdentifierType.js";
13
+ import { formatNestedEntityMapValue, getReferencesForNestedEntityMapType, resolveTypeArgumentsInNestedEntityMapType, serializeNestedEntityMapType, validateNestedEntityMapType, } from "./references/NestedEntityMapType.js";
14
+ import { formatReferenceIdentifierValue, getReferencesForReferenceIdentifierType, resolveTypeArgumentsInReferenceIdentifierType, serializeReferenceIdentifierType, validateReferenceIdentifierType, } from "./references/ReferenceIdentifierType.js";
15
+ import { formatTypeArgumentValue, getReferencesForTypeArgumentType, resolveTypeArgumentsInTypeArgumentType, serializeTypeArgumentType, validateTypeArgumentType, } from "./references/TypeArgumentType.js";
15
16
  export const validate = (helpers, type, value) => {
16
17
  switch (type.kind) {
17
18
  case NodeKind.ArrayType:
@@ -28,14 +29,16 @@ export const validate = (helpers, type, value) => {
28
29
  return validateIntegerType(helpers, type, value);
29
30
  case NodeKind.StringType:
30
31
  return validateStringType(helpers, type, value);
31
- case NodeKind.GenericArgumentIdentifierType:
32
- return validateGenericArgumentIdentifierType(helpers, type, value);
32
+ case NodeKind.TypeArgumentType:
33
+ return validateTypeArgumentType(helpers, type, value);
33
34
  case NodeKind.ReferenceIdentifierType:
34
35
  return validateReferenceIdentifierType(helpers, type, value);
35
36
  case NodeKind.IncludeIdentifierType:
36
37
  return validateIncludeIdentifierType(helpers, type, value);
37
38
  case NodeKind.NestedEntityMapType:
38
39
  return validateNestedEntityMapType(helpers, type, value);
40
+ case NodeKind.EnumType:
41
+ return validateEnumType(helpers, type, value);
39
42
  default:
40
43
  return assertExhaustive(type);
41
44
  }
@@ -52,14 +55,16 @@ export const resolveTypeArgumentsInType = (args, type) => {
52
55
  case NodeKind.IntegerType:
53
56
  case NodeKind.StringType:
54
57
  return type;
55
- case NodeKind.GenericArgumentIdentifierType:
56
- return resolveTypeArgumentsInGenericArgumentIdentifierType(args, type);
58
+ case NodeKind.TypeArgumentType:
59
+ return resolveTypeArgumentsInTypeArgumentType(args, type);
57
60
  case NodeKind.ReferenceIdentifierType:
58
61
  return resolveTypeArgumentsInReferenceIdentifierType(args, type);
59
62
  case NodeKind.IncludeIdentifierType:
60
63
  return resolveTypeArgumentsInIncludeIdentifierType(args, type);
61
64
  case NodeKind.NestedEntityMapType:
62
65
  return resolveTypeArgumentsInNestedEntityMapType(args, type);
66
+ case NodeKind.EnumType:
67
+ return resolveTypeArgumentsInEnumType(args, type);
63
68
  default:
64
69
  return assertExhaustive(type);
65
70
  }
@@ -68,22 +73,45 @@ export function walkTypeNodeTree(callbackFn, type) {
68
73
  switch (type.kind) {
69
74
  case NodeKind.ArrayType:
70
75
  callbackFn(type);
71
- return walkTypeNodeTree(callbackFn, type.items);
76
+ {
77
+ walkTypeNodeTree(callbackFn, type.items);
78
+ return;
79
+ }
72
80
  case NodeKind.ObjectType:
73
81
  callbackFn(type);
74
- return Object.values(type.properties).forEach(prop => walkTypeNodeTree(callbackFn, prop.type));
82
+ {
83
+ Object.values(type.properties).forEach(prop => {
84
+ walkTypeNodeTree(callbackFn, prop.type);
85
+ });
86
+ return;
87
+ }
75
88
  case NodeKind.NestedEntityMapType:
76
89
  callbackFn(type);
77
- return walkTypeNodeTree(callbackFn, type.type.value);
90
+ {
91
+ walkTypeNodeTree(callbackFn, type.type.value);
92
+ return;
93
+ }
78
94
  case NodeKind.BooleanType:
79
95
  case NodeKind.DateType:
80
96
  case NodeKind.FloatType:
81
97
  case NodeKind.IntegerType:
82
98
  case NodeKind.StringType:
83
- case NodeKind.GenericArgumentIdentifierType:
99
+ case NodeKind.TypeArgumentType:
84
100
  case NodeKind.ReferenceIdentifierType:
85
- case NodeKind.IncludeIdentifierType:
86
- return callbackFn(type);
101
+ case NodeKind.IncludeIdentifierType: {
102
+ callbackFn(type);
103
+ return;
104
+ }
105
+ case NodeKind.EnumType:
106
+ callbackFn(type);
107
+ {
108
+ Object.values(type.values).forEach(value => {
109
+ if (value.type) {
110
+ walkTypeNodeTree(callbackFn, value.type);
111
+ }
112
+ });
113
+ return;
114
+ }
87
115
  default:
88
116
  return assertExhaustive(type);
89
117
  }
@@ -100,10 +128,10 @@ export const getParentDecl = (type) => {
100
128
  }
101
129
  };
102
130
  export const findTypeAtPath = (type, path) => {
103
- if (path.length === 0) {
131
+ const [head, ...tail] = path;
132
+ if (head === undefined) {
104
133
  return type;
105
134
  }
106
- const [head, ...tail] = path;
107
135
  if (type.kind === NodeKind.ObjectType) {
108
136
  const prop = type.properties[head];
109
137
  if (prop) {
@@ -131,14 +159,16 @@ export const serializeType = type => {
131
159
  return serializeIntegerType(type);
132
160
  case NodeKind.StringType:
133
161
  return serializeStringType(type);
134
- case NodeKind.GenericArgumentIdentifierType:
135
- return serializeGenericArgumentIdentifierType(type);
162
+ case NodeKind.TypeArgumentType:
163
+ return serializeTypeArgumentType(type);
136
164
  case NodeKind.ReferenceIdentifierType:
137
165
  return serializeReferenceIdentifierType(type);
138
166
  case NodeKind.IncludeIdentifierType:
139
167
  return serializeIncludeIdentifierType(type);
140
168
  case NodeKind.NestedEntityMapType:
141
169
  return serializeNestedEntityMapType(type);
170
+ case NodeKind.EnumType:
171
+ return serializeEnumType(type);
142
172
  default:
143
173
  return assertExhaustive(type);
144
174
  }
@@ -163,14 +193,46 @@ export const getReferencesForType = (type, value) => {
163
193
  return getReferencesForIntegerType(type, value);
164
194
  case NodeKind.StringType:
165
195
  return getReferencesForStringType(type, value);
166
- case NodeKind.GenericArgumentIdentifierType:
167
- return getReferencesForGenericArgumentIdentifierType(type, value);
196
+ case NodeKind.TypeArgumentType:
197
+ return getReferencesForTypeArgumentType(type, value);
168
198
  case NodeKind.ReferenceIdentifierType:
169
199
  return getReferencesForReferenceIdentifierType(type, value);
170
200
  case NodeKind.IncludeIdentifierType:
171
201
  return getReferencesForIncludeIdentifierType(type, value);
172
202
  case NodeKind.NestedEntityMapType:
173
203
  return getReferencesForNestedEntityMapType(type, value);
204
+ case NodeKind.EnumType:
205
+ return getReferencesForEnumType(type, value);
206
+ default:
207
+ return assertExhaustive(type);
208
+ }
209
+ };
210
+ export const formatValue = (type, value) => {
211
+ switch (type.kind) {
212
+ case NodeKind.ArrayType:
213
+ return formatArrayValue(type, value);
214
+ case NodeKind.ObjectType:
215
+ return formatObjectValue(type, value);
216
+ case NodeKind.BooleanType:
217
+ return formatBooleanValue(type, value);
218
+ case NodeKind.DateType:
219
+ return formatDateValue(type, value);
220
+ case NodeKind.FloatType:
221
+ return formatFloatValue(type, value);
222
+ case NodeKind.IntegerType:
223
+ return formatIntegerValue(type, value);
224
+ case NodeKind.StringType:
225
+ return formatStringValue(type, value);
226
+ case NodeKind.TypeArgumentType:
227
+ return formatTypeArgumentValue(type, value);
228
+ case NodeKind.IncludeIdentifierType:
229
+ return formatIncludeIdentifierValue(type, value);
230
+ case NodeKind.NestedEntityMapType:
231
+ return formatNestedEntityMapValue(type, value);
232
+ case NodeKind.ReferenceIdentifierType:
233
+ return formatReferenceIdentifierValue(type, value);
234
+ case NodeKind.EnumType:
235
+ return formatEnumType(type, value);
174
236
  default:
175
237
  return assertExhaustive(type);
176
238
  }
@@ -1,7 +1,8 @@
1
- import { GetNestedDeclarations } from "../../declarations/Declaration.js";
2
- import { GetReferences, Node, NodeKind, Serializer } from "../../Node.js";
3
- import { Validator } from "../../validation/type.js";
4
- import { BaseType, SerializedBaseType, SerializedType, Type } from "../Type.js";
1
+ import type { GetNestedDeclarations } from "../../declarations/Declaration.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, SerializedType, StructureFormatter, Type } from "../Type.js";
5
6
  export interface ArrayType<T extends Type = Type> extends BaseType {
6
7
  kind: NodeKind["ArrayType"];
7
8
  minItems?: number;
@@ -28,3 +29,4 @@ export declare const validateArrayType: Validator<ArrayType>;
28
29
  export declare const resolveTypeArgumentsInArrayType: (args: Record<string, Type>, type: ArrayType) => ArrayType;
29
30
  export declare const serializeArrayType: Serializer<ArrayType, SerializedArrayType>;
30
31
  export declare const getReferencesForArrayType: GetReferences<ArrayType>;
32
+ export declare const formatArrayValue: StructureFormatter<ArrayType>;
@@ -1,10 +1,10 @@
1
- import { parallelizeErrors } from "../../../shared/utils/validation.js";
2
- import { validateArrayConstraints } from "../../../shared/validation/array.js";
1
+ import { parallelizeErrors } from "../../../../shared/utils/validation.js";
2
+ import { validateArrayConstraints } from "../../../../shared/validation/array.js";
3
3
  import { wrapErrorsIfAny } from "../../../utils/error.js";
4
4
  import { getNestedDeclarations } from "../../declarations/Declaration.js";
5
5
  import { NodeKind } from "../../Node.js";
6
6
  import { validateOption } from "../../validation/options.js";
7
- import { getReferencesForType, removeParentKey, resolveTypeArgumentsInType, serializeType, validate, } from "../Type.js";
7
+ import { formatValue, getReferencesForType, removeParentKey, resolveTypeArgumentsInType, serializeType, validate, } from "../Type.js";
8
8
  export const ArrayType = (items, options = {}) => {
9
9
  const type = {
10
10
  ...options,
@@ -25,7 +25,7 @@ export const validateArrayType = (helpers, type, value) => {
25
25
  }
26
26
  return parallelizeErrors([
27
27
  ...validateArrayConstraints(type, value),
28
- ...value.map((item, index) => wrapErrorsIfAny(`at index ${index}`, validate(helpers, type.items, item))),
28
+ ...value.map((item, index) => wrapErrorsIfAny(`at index ${index.toString()}`, validate(helpers, type.items, item))),
29
29
  ]);
30
30
  };
31
31
  export const resolveTypeArgumentsInArrayType = (args, type) => ArrayType(resolveTypeArgumentsInType(args, type.items), {
@@ -36,3 +36,4 @@ export const serializeArrayType = type => ({
36
36
  items: serializeType(type.items),
37
37
  });
38
38
  export const getReferencesForArrayType = (type, value) => Array.isArray(value) ? value.flatMap(item => getReferencesForType(type.items, item)) : [];
39
+ export const formatArrayValue = (type, value) => Array.isArray(value) ? value.map(item => formatValue(type.items, item)) : value;
@@ -0,0 +1,39 @@
1
+ import type { GetNestedDeclarations } from "../../declarations/Declaration.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, SerializedType, StructureFormatter, Type } from "../Type.js";
6
+ export interface EnumType<T extends Record<string, EnumCaseDecl> = Record<string, EnumCaseDecl>> extends BaseType {
7
+ kind: NodeKind["EnumType"];
8
+ values: T;
9
+ }
10
+ export interface SerializedEnumType<T extends Record<string, SerializedEnumCaseDecl> = Record<string, SerializedEnumCaseDecl>> extends SerializedBaseType {
11
+ kind: NodeKind["EnumType"];
12
+ values: T;
13
+ }
14
+ export declare const EnumType: <T extends Record<string, EnumCaseDecl> = Record<string, EnumCaseDecl>>(values: T) => EnumType<T>;
15
+ export declare const isEnumType: (node: Node) => node is EnumType;
16
+ export declare const getNestedDeclarationsInEnumType: GetNestedDeclarations<EnumType>;
17
+ export declare const validateEnumType: Validator<EnumType>;
18
+ export declare const resolveTypeArgumentsInEnumType: (args: Record<string, Type>, type: EnumType) => EnumType;
19
+ export interface EnumCaseDecl<T extends Type | null = Type | null> {
20
+ kind: NodeKind["EnumCaseDecl"];
21
+ type: T;
22
+ comment?: string;
23
+ isDeprecated?: boolean;
24
+ }
25
+ export interface SerializedEnumCaseDecl<T extends SerializedType | null = SerializedType | null> {
26
+ kind: NodeKind["EnumCaseDecl"];
27
+ type: T;
28
+ comment?: string;
29
+ isDeprecated?: boolean;
30
+ }
31
+ export declare const EnumCaseDecl: <T extends Type | null>(options: {
32
+ type: T;
33
+ comment?: string;
34
+ isDeprecated?: boolean;
35
+ }) => EnumCaseDecl<T>;
36
+ export { EnumCaseDecl as EnumCase };
37
+ export declare const serializeEnumType: Serializer<EnumType, SerializedEnumType>;
38
+ export declare const getReferencesForEnumType: GetReferences<EnumType>;
39
+ export declare const formatEnumType: StructureFormatter<EnumType>;