tsondb 0.5.19 → 0.6.1

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 (223) hide show
  1. package/dist/src/bin/tsondb.js +1 -1
  2. package/dist/src/index.d.ts +1 -1
  3. package/dist/src/node/config.d.ts +20 -0
  4. package/dist/src/node/config.js +5 -0
  5. package/dist/src/node/index.d.ts +3 -2
  6. package/dist/src/node/index.js +13 -8
  7. package/dist/src/node/renderers/jsonschema/render.d.ts +1 -1
  8. package/dist/src/node/renderers/jsonschema/render.js +12 -7
  9. package/dist/src/node/renderers/ts/render.d.ts +1 -1
  10. package/dist/src/node/renderers/ts/render.js +12 -6
  11. package/dist/src/node/schema/Node.d.ts +100 -29
  12. package/dist/src/node/schema/Node.js +268 -61
  13. package/dist/src/node/schema/Schema.js +96 -1
  14. package/dist/src/node/schema/TypeParameter.d.ts +7 -9
  15. package/dist/src/node/schema/TypeParameter.js +7 -5
  16. package/dist/src/node/schema/declarations/Declaration.d.ts +10 -28
  17. package/dist/src/node/schema/declarations/Declaration.js +8 -110
  18. package/dist/src/node/schema/declarations/EntityDecl.d.ts +48 -48
  19. package/dist/src/node/schema/declarations/EntityDecl.js +15 -12
  20. package/dist/src/node/schema/declarations/EnumDecl.d.ts +14 -17
  21. package/dist/src/node/schema/declarations/EnumDecl.js +12 -12
  22. package/dist/src/node/schema/declarations/TypeAliasDecl.d.ts +8 -14
  23. package/dist/src/node/schema/declarations/TypeAliasDecl.js +10 -11
  24. package/dist/src/node/schema/index.d.ts +0 -2
  25. package/dist/src/node/schema/index.js +0 -1
  26. package/dist/src/node/schema/types/Type.d.ts +19 -42
  27. package/dist/src/node/schema/types/Type.js +29 -167
  28. package/dist/src/node/schema/types/generic/ArrayType.d.ts +5 -14
  29. package/dist/src/node/schema/types/generic/ArrayType.js +15 -20
  30. package/dist/src/node/schema/types/generic/EnumType.d.ts +5 -17
  31. package/dist/src/node/schema/types/generic/EnumType.js +12 -20
  32. package/dist/src/node/schema/types/generic/ObjectType.d.ts +5 -19
  33. package/dist/src/node/schema/types/generic/ObjectType.js +11 -15
  34. package/dist/src/node/schema/types/primitives/BooleanType.d.ts +7 -8
  35. package/dist/src/node/schema/types/primitives/BooleanType.js +5 -4
  36. package/dist/src/node/schema/types/primitives/DateType.d.ts +6 -8
  37. package/dist/src/node/schema/types/primitives/DateType.js +5 -4
  38. package/dist/src/node/schema/types/primitives/FloatType.d.ts +9 -21
  39. package/dist/src/node/schema/types/primitives/FloatType.js +5 -4
  40. package/dist/src/node/schema/types/primitives/IntegerType.d.ts +9 -21
  41. package/dist/src/node/schema/types/primitives/IntegerType.js +5 -4
  42. package/dist/src/node/schema/types/primitives/StringType.d.ts +6 -10
  43. package/dist/src/node/schema/types/primitives/StringType.js +5 -4
  44. package/dist/src/node/schema/types/references/ChildEntitiesType.d.ts +18 -0
  45. package/dist/src/node/schema/types/references/ChildEntitiesType.js +18 -0
  46. package/dist/src/node/schema/types/references/IncludeIdentifierType.d.ts +7 -13
  47. package/dist/src/node/schema/types/references/IncludeIdentifierType.js +12 -12
  48. package/dist/src/node/schema/types/references/NestedEntityMapType.d.ts +7 -17
  49. package/dist/src/node/schema/types/references/NestedEntityMapType.js +11 -13
  50. package/dist/src/node/schema/types/references/ReferenceIdentifierType.d.ts +4 -10
  51. package/dist/src/node/schema/types/references/ReferenceIdentifierType.js +3 -5
  52. package/dist/src/node/schema/types/references/TypeArgumentType.d.ts +5 -10
  53. package/dist/src/node/schema/types/references/TypeArgumentType.js +10 -5
  54. package/dist/src/node/server/api/declarations.js +24 -6
  55. package/dist/src/node/server/api/index.js +11 -0
  56. package/dist/src/node/server/api/instances.js +9 -6
  57. package/dist/src/node/server/index.d.ts +6 -1
  58. package/dist/src/node/server/index.js +7 -3
  59. package/dist/src/node/server/init.d.ts +2 -1
  60. package/dist/src/node/server/init.js +11 -11
  61. package/dist/src/node/server/utils/childInstances.d.ts +4 -0
  62. package/dist/src/node/server/utils/childInstances.js +41 -0
  63. package/dist/src/node/server/utils/instanceOperations.d.ts +8 -0
  64. package/dist/src/node/server/utils/instanceOperations.js +107 -0
  65. package/dist/src/node/server/utils/locales.d.ts +2 -0
  66. package/dist/src/node/server/utils/locales.js +8 -0
  67. package/dist/src/node/utils/childInstances.d.ts +32 -0
  68. package/dist/src/node/utils/childInstances.js +164 -0
  69. package/dist/src/node/utils/displayName.d.ts +2 -1
  70. package/dist/src/node/utils/displayName.js +5 -4
  71. package/dist/src/node/utils/files.d.ts +5 -0
  72. package/dist/src/node/utils/files.js +9 -0
  73. package/dist/src/node/utils/instanceOperations.d.ts +14 -0
  74. package/dist/src/node/utils/instanceOperations.js +88 -0
  75. package/dist/src/node/utils/instances.d.ts +1 -1
  76. package/dist/src/node/utils/instances.js +12 -6
  77. package/dist/src/node/utils/references.d.ts +3 -1
  78. package/dist/src/node/utils/references.js +43 -18
  79. package/dist/src/node/utils/referencesWorker.d.ts +5 -0
  80. package/dist/src/node/utils/referencesWorker.js +22 -0
  81. package/dist/src/node/utils/workers.d.ts +15 -0
  82. package/dist/src/node/utils/workers.js +90 -0
  83. package/dist/src/shared/api.d.ts +14 -1
  84. package/dist/src/shared/schema/Node.d.ts +63 -0
  85. package/dist/src/shared/schema/Node.js +128 -0
  86. package/dist/src/shared/schema/TypeParameter.d.ts +9 -0
  87. package/dist/src/shared/schema/TypeParameter.js +2 -0
  88. package/dist/src/shared/schema/declarations/Declaration.d.ts +21 -0
  89. package/dist/src/shared/schema/declarations/Declaration.js +4 -0
  90. package/dist/src/shared/schema/declarations/EntityDecl.d.ts +32 -0
  91. package/dist/src/shared/schema/declarations/EntityDecl.js +8 -0
  92. package/dist/src/shared/schema/declarations/EnumDecl.d.ts +11 -0
  93. package/dist/src/shared/schema/declarations/EnumDecl.js +9 -0
  94. package/dist/src/shared/schema/declarations/TypeAliasDecl.d.ts +11 -0
  95. package/dist/src/shared/schema/declarations/TypeAliasDecl.js +7 -0
  96. package/dist/src/shared/schema/types/ArrayType.d.ts +11 -0
  97. package/dist/src/shared/schema/types/ArrayType.js +8 -0
  98. package/dist/src/shared/schema/types/BooleanType.d.ts +7 -0
  99. package/dist/src/shared/schema/types/BooleanType.js +2 -0
  100. package/dist/src/shared/schema/types/ChildEntitiesType.d.ts +8 -0
  101. package/dist/src/shared/schema/types/ChildEntitiesType.js +2 -0
  102. package/dist/src/shared/schema/types/DateType.d.ts +8 -0
  103. package/dist/src/shared/schema/types/DateType.js +2 -0
  104. package/dist/src/shared/schema/types/EnumType.d.ts +14 -0
  105. package/dist/src/shared/schema/types/EnumType.js +28 -0
  106. package/dist/src/shared/schema/types/FloatType.d.ts +11 -0
  107. package/dist/src/shared/schema/types/FloatType.js +2 -0
  108. package/dist/src/shared/schema/types/IncludeIdentifierType.d.ts +11 -0
  109. package/dist/src/shared/schema/types/IncludeIdentifierType.js +13 -0
  110. package/dist/src/shared/schema/types/IntegerType.d.ts +11 -0
  111. package/dist/src/shared/schema/types/IntegerType.js +2 -0
  112. package/dist/src/shared/schema/types/NestedEntityMapType.d.ts +17 -0
  113. package/dist/src/shared/schema/types/NestedEntityMapType.js +14 -0
  114. package/dist/src/shared/schema/types/ObjectType.d.ts +19 -0
  115. package/dist/src/shared/schema/types/ObjectType.js +14 -0
  116. package/dist/src/shared/schema/types/ReferenceIdentifierType.d.ts +8 -0
  117. package/dist/src/shared/schema/types/ReferenceIdentifierType.js +2 -0
  118. package/dist/src/shared/schema/types/StringType.d.ts +10 -0
  119. package/dist/src/shared/schema/types/StringType.js +2 -0
  120. package/dist/src/shared/schema/types/Type.d.ts +20 -0
  121. package/dist/src/shared/schema/types/TypeArgumentType.d.ts +12 -0
  122. package/dist/src/shared/schema/types/TypeArgumentType.js +7 -0
  123. package/dist/src/shared/utils/array.d.ts +4 -0
  124. package/dist/src/shared/utils/array.js +30 -0
  125. package/dist/src/shared/utils/async.d.ts +8 -0
  126. package/dist/src/shared/utils/async.js +35 -0
  127. package/dist/src/shared/utils/compare.js +3 -3
  128. package/dist/src/shared/utils/displayName.d.ts +6 -2
  129. package/dist/src/shared/utils/displayName.js +21 -8
  130. package/dist/src/shared/utils/instances.d.ts +2 -3
  131. package/dist/src/shared/utils/instances.js +3 -1
  132. package/dist/src/shared/utils/markdown.d.ts +4 -0
  133. package/dist/src/shared/utils/markdown.js +91 -4
  134. package/dist/src/shared/utils/object.d.ts +2 -0
  135. package/dist/src/shared/utils/object.js +2 -0
  136. package/dist/src/shared/utils/result.d.ts +8 -2
  137. package/dist/src/shared/utils/result.js +1 -1
  138. package/dist/src/web/api/declarations.d.ts +26 -0
  139. package/dist/src/web/api/declarations.js +51 -0
  140. package/dist/src/web/api/git.d.ts +14 -0
  141. package/dist/src/web/api/git.js +20 -0
  142. package/dist/src/web/api/index.d.ts +1 -0
  143. package/dist/src/web/api/index.js +2 -0
  144. package/dist/src/web/api/instances.d.ts +2 -0
  145. package/dist/src/web/api/instances.js +2 -0
  146. package/dist/src/web/components/Git.js +19 -16
  147. package/dist/src/web/components/InstanceRouteSkeleton.d.ts +42 -0
  148. package/dist/src/web/components/InstanceRouteSkeleton.js +114 -0
  149. package/dist/src/web/components/Layout.js +3 -2
  150. package/dist/src/web/components/ModalDialog.d.ts +2 -0
  151. package/dist/src/web/components/ModalDialog.js +16 -0
  152. package/dist/src/web/components/Select.d.ts +1 -2
  153. package/dist/src/web/components/Settings.d.ts +2 -0
  154. package/dist/src/web/components/Settings.js +47 -0
  155. package/dist/src/web/components/typeInputs/ArrayTypeInput.d.ts +3 -11
  156. package/dist/src/web/components/typeInputs/ArrayTypeInput.js +5 -4
  157. package/dist/src/web/components/typeInputs/BooleanTypeInput.d.ts +3 -6
  158. package/dist/src/web/components/typeInputs/BooleanTypeInput.js +2 -2
  159. package/dist/src/web/components/typeInputs/ChildEntitiesTypeInput.d.ts +6 -0
  160. package/dist/src/web/components/typeInputs/ChildEntitiesTypeInput.js +27 -0
  161. package/dist/src/web/components/typeInputs/DateTypeInput.d.ts +3 -6
  162. package/dist/src/web/components/typeInputs/DateTypeInput.js +2 -2
  163. package/dist/src/web/components/typeInputs/EnumTypeInput.d.ts +3 -11
  164. package/dist/src/web/components/typeInputs/EnumTypeInput.js +55 -22
  165. package/dist/src/web/components/typeInputs/FloatTypeInput.d.ts +3 -6
  166. package/dist/src/web/components/typeInputs/FloatTypeInput.js +2 -2
  167. package/dist/src/web/components/typeInputs/GenericTypeArgumentIdentifierTypeInput.d.ts +3 -4
  168. package/dist/src/web/components/typeInputs/IncludeIdentifierTypeInput.d.ts +3 -11
  169. package/dist/src/web/components/typeInputs/IncludeIdentifierTypeInput.js +3 -2
  170. package/dist/src/web/components/typeInputs/IntegerTypeInput.d.ts +3 -6
  171. package/dist/src/web/components/typeInputs/IntegerTypeInput.js +2 -2
  172. package/dist/src/web/components/typeInputs/NestedEntityMapTypeInput.d.ts +3 -11
  173. package/dist/src/web/components/typeInputs/NestedEntityMapTypeInput.js +5 -4
  174. package/dist/src/web/components/typeInputs/ObjectTypeInput.d.ts +3 -11
  175. package/dist/src/web/components/typeInputs/ObjectTypeInput.js +8 -5
  176. package/dist/src/web/components/typeInputs/ReferenceIdentifierTypeInput.d.ts +3 -8
  177. package/dist/src/web/components/typeInputs/ReferenceIdentifierTypeInput.js +2 -2
  178. package/dist/src/web/components/typeInputs/StringTypeInput.d.ts +3 -6
  179. package/dist/src/web/components/typeInputs/StringTypeInput.js +3 -3
  180. package/dist/src/web/components/typeInputs/TypeInput.d.ts +12 -4
  181. package/dist/src/web/components/typeInputs/TypeInput.js +22 -17
  182. package/dist/src/web/components/typeInputs/utils/ValidationErrors.d.ts +1 -0
  183. package/dist/src/web/components/typeInputs/utils/ValidationErrors.js +1 -3
  184. package/dist/src/web/context/config.d.ts +11 -0
  185. package/dist/src/web/context/config.js +6 -0
  186. package/dist/src/web/context/entities.d.ts +8 -5
  187. package/dist/src/web/context/entities.js +1 -1
  188. package/dist/src/web/context/settings.d.ts +8 -0
  189. package/dist/src/web/context/settings.js +10 -0
  190. package/dist/src/web/hooks/useEntityFromRoute.d.ts +1 -1
  191. package/dist/src/web/hooks/useEntityFromRoute.js +2 -2
  192. package/dist/src/web/hooks/useInstanceNamesByEntity.d.ts +1 -1
  193. package/dist/src/web/hooks/useInstanceNamesByEntity.js +4 -2
  194. package/dist/src/web/hooks/useMappedAPIResource.js +2 -4
  195. package/dist/src/web/hooks/useSecondaryDeclarations.d.ts +1 -1
  196. package/dist/src/web/hooks/useSecondaryDeclarations.js +8 -4
  197. package/dist/src/web/hooks/useSettings.d.ts +10 -0
  198. package/dist/src/web/hooks/useSettings.js +51 -0
  199. package/dist/src/web/index.js +11 -5
  200. package/dist/src/web/routes/CreateInstance.js +40 -79
  201. package/dist/src/web/routes/Entity.js +42 -19
  202. package/dist/src/web/routes/Home.js +24 -5
  203. package/dist/src/web/routes/Instance.js +34 -85
  204. package/dist/src/web/utils/InlineMarkdown.d.ts +1 -1
  205. package/dist/src/web/utils/InlineMarkdown.js +13 -1
  206. package/dist/src/web/utils/api.d.ts +25 -0
  207. package/dist/src/web/utils/api.js +34 -0
  208. package/dist/src/web/utils/typeSkeleton.d.ts +1 -1
  209. package/dist/src/web/utils/typeSkeleton.js +2 -0
  210. package/package.json +14 -13
  211. package/public/css/styles.css +171 -12
  212. package/dist/src/node/schema/types/primitives/NumericType.d.ts +0 -6
  213. package/dist/src/node/schema/types/primitives/NumericType.js +0 -2
  214. package/dist/src/node/schema/types/primitives/PrimitiveType.d.ts +0 -6
  215. package/dist/src/node/schema/validation/type.d.ts +0 -4
  216. package/dist/src/node/schema/validation/type.js +0 -1
  217. package/dist/src/node/server/api/instanceOperations.d.ts +0 -6
  218. package/dist/src/node/server/api/instanceOperations.js +0 -93
  219. package/dist/src/shared/config.d.ts +0 -11
  220. package/dist/src/shared/config.js +0 -1
  221. package/dist/src/web/api.d.ts +0 -24
  222. package/dist/src/web/api.js +0 -201
  223. /package/dist/src/{node/schema/types/primitives/PrimitiveType.js → shared/schema/types/Type.js} +0 -0
@@ -1,126 +1,24 @@
1
- import { assertExhaustive } from "../../../shared/utils/typeSafety.js";
2
- import { NodeKind } from "../Node.js";
3
- import { getNestedDeclarationsInArrayType } from "../types/generic/ArrayType.js";
4
- import { getNestedDeclarationsInEnumType } from "../types/generic/EnumType.js";
5
- import { getNestedDeclarationsInObjectType } from "../types/generic/ObjectType.js";
6
- import { getNestedDeclarationsInIncludeIdentifierType } from "../types/references/IncludeIdentifierType.js";
7
- import { getNestedDeclarationsInNestedEntityMapType } from "../types/references/NestedEntityMapType.js";
8
- import { getNestedDeclarationsInReferenceIdentifierType } from "../types/references/ReferenceIdentifierType.js";
1
+ import { resolveTypeArguments } from "../Node.js";
9
2
  import { walkTypeNodeTree } from "../types/Type.js";
10
- import { getNestedDeclarationsInEntityDecl, getReferencesForEntityDecl, isEntityDecl, resolveTypeArgumentsInEntityDecl, serializeEntityDecl, validateEntityDecl, } from "./EntityDecl.js";
11
- import { getNestedDeclarationsInEnumDecl, getReferencesForEnumDecl, isEnumDecl, resolveTypeArgumentsInEnumDecl, serializeEnumDecl, validateEnumDecl, } from "./EnumDecl.js";
12
- import { getNestedDeclarationsInTypeAliasDecl, getReferencesForTypeAliasDecl, isTypeAliasDecl, resolveTypeArgumentsInTypeAliasDecl, serializeTypeAliasDecl, validateTypeAliasDecl, } from "./TypeAliasDecl.js";
3
+ import { isEntityDecl } from "./EntityDecl.js";
4
+ import { isEnumDecl } from "./EnumDecl.js";
5
+ import { isTypeAliasDecl } from "./TypeAliasDecl.js";
13
6
  export const getParameterNames = (decl) => decl.parameters.map(param => param.name);
14
7
  export const getTypeArgumentsRecord = (decl, args) => Object.fromEntries(
15
8
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
16
9
  args.slice(0, decl.parameters.length).map((arg, i) => [decl.parameters[i].name, arg]));
17
- export const getNestedDeclarations = (addedDecls, node) => {
18
- switch (node.kind) {
19
- case NodeKind.EntityDecl:
20
- return getNestedDeclarationsInEntityDecl(addedDecls, node);
21
- case NodeKind.EnumDecl:
22
- return getNestedDeclarationsInEnumDecl(addedDecls, node);
23
- case NodeKind.TypeAliasDecl:
24
- return getNestedDeclarationsInTypeAliasDecl(addedDecls, node);
25
- case NodeKind.ArrayType:
26
- return getNestedDeclarationsInArrayType(addedDecls, node);
27
- case NodeKind.ObjectType:
28
- return getNestedDeclarationsInObjectType(addedDecls, node);
29
- case NodeKind.BooleanType:
30
- case NodeKind.DateType:
31
- case NodeKind.FloatType:
32
- case NodeKind.IntegerType:
33
- case NodeKind.StringType:
34
- case NodeKind.TypeArgumentType:
35
- return addedDecls;
36
- case NodeKind.ReferenceIdentifierType:
37
- return getNestedDeclarationsInReferenceIdentifierType(addedDecls, node);
38
- case NodeKind.IncludeIdentifierType:
39
- return getNestedDeclarationsInIncludeIdentifierType(addedDecls, node);
40
- case NodeKind.NestedEntityMapType:
41
- return getNestedDeclarationsInNestedEntityMapType(addedDecls, node);
42
- case NodeKind.EnumType:
43
- return getNestedDeclarationsInEnumType(addedDecls, node);
44
- default:
45
- return assertExhaustive(node);
46
- }
47
- };
48
10
  export const isDecl = (node) => isEntityDecl(node) || isEnumDecl(node) || isTypeAliasDecl(node);
49
- export const validateDecl = (helpers, decl, args, value) => {
50
- switch (decl.kind) {
51
- case NodeKind.EntityDecl:
52
- return validateEntityDecl(helpers, decl, value);
53
- case NodeKind.EnumDecl:
54
- return validateEnumDecl(helpers, decl, args, value);
55
- case NodeKind.TypeAliasDecl:
56
- return validateTypeAliasDecl(helpers, decl, args, value);
57
- default:
58
- return assertExhaustive(decl);
59
- }
60
- };
11
+ export const asDecl = (node) => node && isDecl(node) ? node : undefined;
61
12
  const declNamePattern = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
62
13
  export const validateDeclName = (name) => {
63
14
  if (!declNamePattern.test(name)) {
64
15
  throw new Error(`Invalid declaration name "${name}". Declaration names must match the pattern ${declNamePattern.toString()}.`);
65
16
  }
66
17
  };
67
- export const resolveTypeArgumentsInDecl = (decl, args) => {
68
- switch (decl.kind) {
69
- case NodeKind.EntityDecl:
70
- return resolveTypeArgumentsInEntityDecl(decl);
71
- case NodeKind.EnumDecl:
72
- return resolveTypeArgumentsInEnumDecl(decl, args);
73
- case NodeKind.TypeAliasDecl:
74
- return resolveTypeArgumentsInTypeAliasDecl(decl, args);
75
- default:
76
- return assertExhaustive(decl);
77
- }
78
- };
79
18
  export const isDeclWithoutTypeParameters = (decl) => decl.parameters.length === 0;
80
- export const resolveTypeArgumentsInDecls = (decls) => decls.filter(isDeclWithoutTypeParameters).map(decl => resolveTypeArgumentsInDecl(decl, []));
19
+ export const resolveTypeArgumentsInDecls = (decls) => decls.filter(isDeclWithoutTypeParameters).map(decl => resolveTypeArguments({}, decl));
81
20
  export function walkNodeTree(callbackFn, decl) {
82
- switch (decl.kind) {
83
- case NodeKind.EntityDecl: {
84
- callbackFn(decl);
85
- walkTypeNodeTree(callbackFn, decl.type.value);
86
- return;
87
- }
88
- case NodeKind.EnumDecl: {
89
- callbackFn(decl);
90
- walkTypeNodeTree(callbackFn, decl.type.value);
91
- return;
92
- }
93
- case NodeKind.TypeAliasDecl: {
94
- callbackFn(decl);
95
- walkTypeNodeTree(callbackFn, decl.type.value);
96
- return;
97
- }
98
- default:
99
- return assertExhaustive(decl);
100
- }
21
+ callbackFn(decl, [], decl);
22
+ walkTypeNodeTree(callbackFn, decl.type.value, [], decl);
101
23
  }
102
- export const serializeDecl = decl => {
103
- switch (decl.kind) {
104
- case NodeKind.EntityDecl:
105
- return serializeEntityDecl(decl);
106
- case NodeKind.EnumDecl:
107
- return serializeEnumDecl(decl);
108
- case NodeKind.TypeAliasDecl:
109
- return serializeTypeAliasDecl(decl);
110
- default:
111
- return assertExhaustive(decl);
112
- }
113
- };
114
- export const getReferencesForDecl = (decl, value) => {
115
- switch (decl.kind) {
116
- case NodeKind.EntityDecl:
117
- return getReferencesForEntityDecl(decl, value);
118
- case NodeKind.EnumDecl:
119
- return getReferencesForEnumDecl(decl, value);
120
- case NodeKind.TypeAliasDecl:
121
- return getReferencesForTypeAliasDecl(decl, value);
122
- default:
123
- return assertExhaustive(decl);
124
- }
125
- };
126
24
  export const groupDeclarationsBySourceUrl = (decls) => Object.groupBy(decls, decl => decl.sourceUrl);
@@ -1,81 +1,81 @@
1
+ import type { DisplayNameResult } from "../../../shared/utils/displayName.ts";
1
2
  import { Lazy } from "../../../shared/utils/lazy.ts";
2
3
  import type { Leaves } from "../../../shared/utils/object.ts";
3
- import type { GetReferences, Node, Serializer } from "../Node.ts";
4
+ import type { GetNestedDeclarations, GetReferences, Predicate, Serializer, TypeArgumentsResolver, Validator } from "../Node.ts";
4
5
  import { NodeKind } from "../Node.ts";
5
- import type { MemberDecl, ObjectType, SerializedObjectType } from "../types/generic/ObjectType.ts";
6
+ import type { MemberDecl, ObjectType } from "../types/generic/ObjectType.ts";
6
7
  import { StringType } from "../types/primitives/StringType.ts";
7
- import type { AsType, SerializedAsType } from "../types/Type.ts";
8
- import type { ValidatorHelpers } from "../validation/type.ts";
9
- import type { BaseDecl, GetNestedDeclarations, SerializedBaseDecl } from "./Declaration.ts";
8
+ import type { AsType } from "../types/Type.ts";
9
+ import type { BaseDecl } from "./Declaration.ts";
10
10
  import { TypeAliasDecl } from "./TypeAliasDecl.ts";
11
- export type GenericDisplayNameFn = (instance: unknown, instanceDisplayName: string, getInstanceById: (id: string) => unknown, getDisplayNameForInstanceId: (id: string) => string | undefined, locales: string[] | undefined) => string;
11
+ export type GenericDisplayNameFn = (instance: unknown, instanceDisplayName: string, getInstanceById: (id: string) => unknown, getDisplayNameForInstanceId: (id: string) => string | undefined, locales: string[]) => string;
12
12
  export type GenericEntityDisplayName = string | {
13
13
  pathToLocaleMap?: string;
14
14
  pathInLocaleMap?: string;
15
15
  } | null;
16
- export type DisplayNameFn<T extends ObjectType = ObjectType> = (instance: AsType<T>, instanceDisplayName: string, getInstanceById: (id: string) => unknown, getDisplayNameForInstanceId: (id: string) => string | undefined, locales: string[] | undefined) => string;
17
- export type EntityDisplayName<T extends ObjectType> = Leaves<AsType<T>> | {
16
+ export type DisplayNameFn<T extends ObjectType = ObjectType> = (instance: AsType<T>, instanceDisplayName: string, instanceDisplayNameLocaleId: string | undefined, getInstanceById: (id: string) => unknown, getDisplayNameForInstanceId: (id: string) => string | undefined, locales: string[]) => DisplayNameResult;
17
+ export type EntityDisplayName<T extends TConstraint> = Leaves<AsType<ObjectType<T>>> | {
18
18
  /**
19
19
  * @default "translations"
20
20
  */
21
- pathToLocaleMap?: Leaves<AsType<T>>;
21
+ pathToLocaleMap?: Leaves<AsType<ObjectType<T>>>;
22
22
  /**
23
23
  * @default "name"
24
24
  */
25
25
  pathInLocaleMap?: string;
26
26
  } | null;
27
- export type SerializedEntityDisplayName<T extends SerializedObjectType> = Leaves<SerializedAsType<T>> | {
28
- /**
29
- * @default "translations"
30
- */
31
- pathToLocaleMap?: Leaves<SerializedAsType<T>>;
32
- /**
33
- * @default "name"
34
- */
35
- pathInLocaleMap?: string;
36
- } | null;
37
- export interface EntityDecl<Name extends string = string, T extends ObjectType = ObjectType> extends BaseDecl<Name, []> {
27
+ type TConstraint = Record<string, MemberDecl>;
28
+ export interface EntityDecl<Name extends string = string, T extends TConstraint = TConstraint, FK extends (keyof T & string) | undefined = (keyof T & string) | undefined> extends BaseDecl<Name, []> {
38
29
  kind: NodeKind["EntityDecl"];
39
30
  namePlural: string;
40
- type: Lazy<T>;
31
+ type: Lazy<ObjectType<T>>;
32
+ parentReferenceKey: FK;
41
33
  /**
42
34
  * @default "name"
43
35
  */
44
36
  displayName?: EntityDisplayName<T>;
45
- displayNameCustomizer?: DisplayNameFn<T>;
37
+ displayNameCustomizer?: DisplayNameFn<ObjectType<T>>;
46
38
  isDeprecated?: boolean;
47
39
  }
48
- export interface SerializedEntityDecl<Name extends string = string, T extends SerializedObjectType = SerializedObjectType> extends SerializedBaseDecl<Name, []> {
49
- kind: NodeKind["EntityDecl"];
50
- namePlural: string;
51
- type: T;
52
- /**
53
- * @default "name"
54
- */
55
- displayName?: SerializedEntityDisplayName<T>;
56
- isDeprecated?: boolean;
40
+ export interface EntityDeclWithParentReference<Name extends string = string, T extends TConstraint = TConstraint, FK extends keyof T & string = keyof T & string> extends EntityDecl<Name, T, FK> {
57
41
  }
58
- export declare const EntityDecl: <Name extends string, T extends ObjectType>(sourceUrl: string, options: {
59
- name: Name;
60
- namePlural: string;
61
- comment?: string;
62
- type: () => T;
63
- /**
64
- * @default "name"
65
- */
66
- displayName?: EntityDisplayName<T>;
67
- displayNameCustomizer?: DisplayNameFn<T>;
68
- isDeprecated?: boolean;
69
- }) => EntityDecl<Name, T>;
42
+ export declare const EntityDecl: {
43
+ <Name extends string, T extends TConstraint>(sourceUrl: string, options: {
44
+ name: Name;
45
+ namePlural: string;
46
+ comment?: string;
47
+ type: () => ObjectType<T>;
48
+ /**
49
+ * @default "name"
50
+ */
51
+ displayName?: EntityDisplayName<T>;
52
+ displayNameCustomizer?: DisplayNameFn<ObjectType<T>>;
53
+ isDeprecated?: boolean;
54
+ }): EntityDecl<Name, T, undefined>;
55
+ <Name extends string, T extends TConstraint, FK extends keyof T & string>(sourceUrl: string, options: {
56
+ name: Name;
57
+ namePlural: string;
58
+ comment?: string;
59
+ type: () => ObjectType<T>;
60
+ parentReferenceKey: FK;
61
+ /**
62
+ * @default "name"
63
+ */
64
+ displayName?: EntityDisplayName<T>;
65
+ displayNameCustomizer?: DisplayNameFn<ObjectType<T>>;
66
+ isDeprecated?: boolean;
67
+ }): EntityDecl<Name, T, FK>;
68
+ };
70
69
  export { EntityDecl as Entity };
71
- export declare const isEntityDecl: (node: Node) => node is EntityDecl;
70
+ export declare const isEntityDecl: Predicate<EntityDecl>;
71
+ export declare const isEntityDeclWithParentReference: <Name extends string, T extends TConstraint, FK extends (keyof T & string) | undefined>(decl: EntityDecl<Name, T, FK>) => decl is EntityDecl<Name, T, NonNullable<FK>>;
72
72
  export declare const getNestedDeclarationsInEntityDecl: GetNestedDeclarations<EntityDecl>;
73
- export declare const validateEntityDecl: (helpers: ValidatorHelpers, decl: EntityDecl, value: unknown) => Error[];
74
- export declare const resolveTypeArgumentsInEntityDecl: (decl: EntityDecl) => EntityDecl;
75
- export declare const addEphemeralUUIDToType: <T extends Record<string, MemberDecl>>(decl: EntityDecl<string, ObjectType<T>>) => ObjectType<Omit<T, "id"> & {
73
+ export declare const validateEntityDecl: Validator<EntityDecl>;
74
+ export declare const resolveTypeArgumentsInEntityDecl: TypeArgumentsResolver<EntityDecl>;
75
+ export declare const addEphemeralUUIDToType: <T extends TConstraint>(decl: EntityDecl<string, T>) => ObjectType<Omit<T, "id"> & {
76
76
  id: MemberDecl<StringType, true>;
77
77
  }>;
78
78
  export declare const createEntityIdentifierType: () => StringType;
79
79
  export declare const createEntityIdentifierTypeAsDecl: <Name extends string>(decl: EntityDecl<Name>) => TypeAliasDecl<`${Name}_ID`, StringType, []>;
80
- export declare const serializeEntityDecl: Serializer<EntityDecl, SerializedEntityDecl>;
80
+ export declare const serializeEntityDecl: Serializer<EntityDecl>;
81
81
  export declare const getReferencesForEntityDecl: GetReferences<EntityDecl>;
@@ -1,13 +1,12 @@
1
1
  import { Lazy } from "../../../shared/utils/lazy.js";
2
- import { NodeKind } from "../Node.js";
3
- import { getNestedDeclarationsInObjectType, getReferencesForObjectType, Required, resolveTypeArgumentsInObjectType, serializeObjectType, } from "../types/generic/ObjectType.js";
2
+ import { NodeKind, resolveTypeArguments, validateType } from "../Node.js";
3
+ import { getNestedDeclarationsInObjectType, getReferencesForObjectType, Required, serializeObjectType, } from "../types/generic/ObjectType.js";
4
4
  import { StringType } from "../types/primitives/StringType.js";
5
- import { setParent, validate } from "../types/Type.js";
6
5
  import { validateDeclName } from "./Declaration.js";
7
6
  import { TypeAliasDecl } from "./TypeAliasDecl.js";
8
7
  export const EntityDecl = (sourceUrl, options) => {
9
8
  validateDeclName(options.name);
10
- const decl = {
9
+ return {
11
10
  ...options,
12
11
  kind: NodeKind.EntityDecl,
13
12
  sourceUrl,
@@ -19,18 +18,19 @@ export const EntityDecl = (sourceUrl, options) => {
19
18
  throw new TypeError(`Invalid object key "${key}" for entity "${options.name}". The key "id" is reserved for the entity identifier.`);
20
19
  }
21
20
  });
22
- return setParent(type, decl);
21
+ return type;
23
22
  }),
23
+ parentReferenceKey: options.parentReferenceKey,
24
24
  };
25
- return decl;
26
25
  };
27
26
  export { EntityDecl as Entity };
28
- export const isEntityDecl = (node) => node.kind === NodeKind.EntityDecl;
27
+ export const isEntityDecl = node => node.kind === NodeKind.EntityDecl;
28
+ export const isEntityDeclWithParentReference = (decl) => decl.parentReferenceKey !== undefined;
29
29
  export const getNestedDeclarationsInEntityDecl = (isDeclAdded, decl) => getNestedDeclarationsInObjectType(isDeclAdded, decl.type.value);
30
- export const validateEntityDecl = (helpers, decl, value) => validate(helpers, decl.type.value, value);
31
- export const resolveTypeArgumentsInEntityDecl = (decl) => EntityDecl(decl.sourceUrl, {
30
+ export const validateEntityDecl = (helpers, decl, value) => validateType(helpers, decl.type.value, value);
31
+ export const resolveTypeArgumentsInEntityDecl = (_args, decl) => EntityDecl(decl.sourceUrl, {
32
32
  ...decl,
33
- type: () => resolveTypeArgumentsInObjectType({}, decl.type.value),
33
+ type: () => resolveTypeArguments({}, decl.type.value),
34
34
  });
35
35
  const createEntityIdentifierComment = () => "The entity’s identifier. A UUID or a locale code if it is registered as the locale entity.";
36
36
  export const addEphemeralUUIDToType = (decl) => ({
@@ -49,9 +49,12 @@ export const createEntityIdentifierTypeAsDecl = (decl) => TypeAliasDecl(decl.sou
49
49
  name: (decl.name + "_ID"),
50
50
  type: createEntityIdentifierType,
51
51
  });
52
- export const serializeEntityDecl = type => ({
52
+ export const serializeEntityDecl = (type) => ({
53
53
  ...type,
54
54
  type: serializeObjectType(type.type.value),
55
- displayName: typeof type.displayName === "function" ? null : type.displayName,
55
+ displayName: typeof type.displayName === "function"
56
+ ? null
57
+ : type.displayName,
58
+ displayNameCustomizer: type.displayNameCustomizer !== undefined,
56
59
  });
57
60
  export const getReferencesForEntityDecl = (decl, value) => getReferencesForObjectType(decl.type.value, value);
@@ -1,38 +1,35 @@
1
1
  import { Lazy } from "../../../shared/utils/lazy.ts";
2
- import type { GetReferences, Node, Serializer } from "../Node.ts";
2
+ import type { GetNestedDeclarations, GetReferences, Predicate, Serializer, TypeArgumentsResolver, ValidatorOfParamDecl } from "../Node.ts";
3
3
  import { NodeKind } from "../Node.ts";
4
- import type { SerializedTypeParameter, TypeParameter } from "../TypeParameter.ts";
5
- import type { EnumCaseDecl, SerializedEnumCaseDecl, SerializedEnumType } from "../types/generic/EnumType.ts";
4
+ import type { TypeParameter } from "../TypeParameter.ts";
5
+ import type { EnumCaseDecl } from "../types/generic/EnumType.ts";
6
6
  import { EnumType } from "../types/generic/EnumType.ts";
7
- import { type Type } from "../types/Type.ts";
8
- import type { ValidatorHelpers } from "../validation/type.ts";
9
- import type { BaseDecl, GetNestedDeclarations, SerializedBaseDecl, TypeArguments } from "./Declaration.ts";
10
- export interface EnumDecl<Name extends string = string, T extends Record<string, EnumCaseDecl> = Record<string, EnumCaseDecl>, Params extends TypeParameter[] = TypeParameter[]> extends BaseDecl<Name, Params> {
7
+ import type { BaseDecl } from "./Declaration.ts";
8
+ type TConstraint = Record<string, EnumCaseDecl>;
9
+ export interface EnumDecl<Name extends string = string, T extends TConstraint = TConstraint, Params extends TypeParameter[] = TypeParameter[]> extends BaseDecl<Name, Params> {
11
10
  kind: NodeKind["EnumDecl"];
12
11
  type: Lazy<EnumType<T>>;
13
12
  isDeprecated?: boolean;
14
13
  }
15
- export interface SerializedEnumDecl<Name extends string = string, T extends Record<string, SerializedEnumCaseDecl> = Record<string, SerializedEnumCaseDecl>, Params extends SerializedTypeParameter[] = SerializedTypeParameter[]> extends SerializedBaseDecl<Name, Params> {
16
- kind: NodeKind["EnumDecl"];
17
- type: SerializedEnumType<T>;
18
- isDeprecated?: boolean;
19
- }
20
- export declare const GenEnumDecl: <Name extends string, T extends Record<string, EnumCaseDecl>, Params extends TypeParameter[]>(sourceUrl: string, options: {
14
+ export declare const GenEnumDecl: <Name extends string, T extends TConstraint, Params extends TypeParameter[]>(sourceUrl: string, options: {
21
15
  name: Name;
22
16
  comment?: string;
23
17
  parameters: Params;
18
+ isDeprecated?: boolean;
24
19
  values: (...args: Params) => T;
25
20
  }) => EnumDecl<Name, T, Params>;
26
21
  export { GenEnumDecl as GenEnum };
27
22
  export declare const EnumDecl: <Name extends string, T extends Record<string, EnumCaseDecl>>(sourceUrl: string, options: {
28
23
  name: Name;
29
24
  comment?: string;
25
+ isDeprecated?: boolean;
30
26
  values: () => T;
31
27
  }) => EnumDecl<Name, T, []>;
32
28
  export { EnumDecl as Enum };
33
- export declare const isEnumDecl: (node: Node) => node is EnumDecl;
29
+ export declare const isEnumDecl: Predicate<EnumDecl>;
34
30
  export declare const getNestedDeclarationsInEnumDecl: GetNestedDeclarations<EnumDecl>;
35
- export declare const validateEnumDecl: (helpers: ValidatorHelpers, decl: EnumDecl, args: Type[], value: unknown) => Error[];
36
- export declare const resolveTypeArgumentsInEnumDecl: <Params extends TypeParameter[]>(decl: EnumDecl<string, Record<string, EnumCaseDecl>, Params>, args: TypeArguments<Params>) => EnumDecl<string, Record<string, EnumCaseDecl>, []>;
37
- export declare const serializeEnumDecl: Serializer<EnumDecl, SerializedEnumDecl>;
31
+ export declare const validateEnumDecl: ValidatorOfParamDecl<EnumDecl>;
32
+ export declare const resolveTypeArgumentsInEnumDecl: TypeArgumentsResolver<EnumDecl>;
33
+ export declare const serializeEnumDecl: Serializer<EnumDecl>;
38
34
  export declare const getReferencesForEnumDecl: GetReferences<EnumDecl>;
35
+ export declare const cases: <T extends TConstraint>(decl: EnumDecl<string, T>) => EnumCaseDecl<T[keyof T]["type"]>[];
@@ -1,8 +1,8 @@
1
1
  import { Lazy } from "../../../shared/utils/lazy.js";
2
+ import { onlyKeys } from "../../../shared/utils/object.js";
2
3
  import { NodeKind } from "../Node.js";
3
4
  import { serializeTypeParameter } from "../TypeParameter.js";
4
5
  import { EnumType, getNestedDeclarationsInEnumType, getReferencesForEnumType, resolveTypeArgumentsInEnumType, serializeEnumType, validateEnumType, } from "../types/generic/EnumType.js";
5
- import { setParent } from "../types/Type.js";
6
6
  import { getTypeArgumentsRecord, validateDeclName } from "./Declaration.js";
7
7
  export const GenEnumDecl = (sourceUrl, options) => {
8
8
  validateDeclName(options.name);
@@ -10,7 +10,7 @@ export const GenEnumDecl = (sourceUrl, options) => {
10
10
  ...options,
11
11
  kind: NodeKind.EnumDecl,
12
12
  sourceUrl,
13
- type: Lazy.of(() => setParent(EnumType(options.values(...options.parameters)), decl)),
13
+ type: Lazy.of(() => EnumType(options.values(...options.parameters))),
14
14
  };
15
15
  return decl;
16
16
  };
@@ -18,28 +18,28 @@ export { GenEnumDecl as GenEnum };
18
18
  export const EnumDecl = (sourceUrl, options) => {
19
19
  validateDeclName(options.name);
20
20
  const decl = {
21
- ...options,
21
+ ...onlyKeys(options, "name", "comment", "isDeprecated"),
22
22
  kind: NodeKind.EnumDecl,
23
23
  sourceUrl,
24
24
  parameters: [],
25
- type: Lazy.of(() => setParent(EnumType(options.values()), decl)),
25
+ type: Lazy.of(() => EnumType(options.values())),
26
26
  };
27
27
  return decl;
28
28
  };
29
29
  export { EnumDecl as Enum };
30
- export const isEnumDecl = (node) => node.kind === NodeKind.EnumDecl;
30
+ export const isEnumDecl = node => node.kind === NodeKind.EnumDecl;
31
31
  export const getNestedDeclarationsInEnumDecl = (addedDecls, decl) => getNestedDeclarationsInEnumType(addedDecls, decl.type.value);
32
32
  export const validateEnumDecl = (helpers, decl, args, value) => validateEnumType(helpers, resolveTypeArgumentsInEnumType(getTypeArgumentsRecord(decl, args), decl.type.value), value);
33
- export const resolveTypeArgumentsInEnumDecl = (decl, args) => {
34
- const resolvedArgs = getTypeArgumentsRecord(decl, args);
35
- return EnumDecl(decl.sourceUrl, {
36
- ...decl,
37
- values: () => resolveTypeArgumentsInEnumType(resolvedArgs, decl.type.value).values,
38
- });
39
- };
33
+ export const resolveTypeArgumentsInEnumDecl = (args, decl) => EnumDecl(decl.sourceUrl, {
34
+ name: decl.name,
35
+ comment: decl.comment,
36
+ isDeprecated: decl.isDeprecated,
37
+ values: () => resolveTypeArgumentsInEnumType(args, decl.type.value).values,
38
+ });
40
39
  export const serializeEnumDecl = decl => ({
41
40
  ...decl,
42
41
  type: serializeEnumType(decl.type.value),
43
42
  parameters: decl.parameters.map(param => serializeTypeParameter(param)),
44
43
  });
45
44
  export const getReferencesForEnumDecl = (decl, value) => getReferencesForEnumType(decl.type.value, value);
45
+ export const cases = (decl) => Object.values(decl.type.value.values);
@@ -1,20 +1,14 @@
1
1
  import { Lazy } from "../../../shared/utils/lazy.ts";
2
- import type { GetReferences, Node, Serializer } from "../Node.ts";
2
+ import type { GetNestedDeclarations, GetReferences, Predicate, Serializer, TypeArgumentsResolver, Validators } from "../Node.ts";
3
3
  import { NodeKind } from "../Node.ts";
4
- import type { SerializedTypeParameter, TypeParameter } from "../TypeParameter.ts";
5
- import type { SerializedType, Type } from "../types/Type.ts";
6
- import type { ValidatorHelpers } from "../validation/type.ts";
7
- import type { BaseDecl, GetNestedDeclarations, SerializedBaseDecl, TypeArguments } from "./Declaration.ts";
4
+ import type { TypeParameter } from "../TypeParameter.ts";
5
+ import type { Type } from "../types/Type.ts";
6
+ import type { BaseDecl, TypeArguments } from "./Declaration.ts";
8
7
  export interface TypeAliasDecl<Name extends string = string, T extends Type = Type, Params extends TypeParameter[] = TypeParameter[]> extends BaseDecl<Name, Params> {
9
8
  kind: NodeKind["TypeAliasDecl"];
10
9
  type: Lazy<T>;
11
10
  isDeprecated?: boolean;
12
11
  }
13
- export interface SerializedTypeAliasDecl<Name extends string = string, T extends SerializedType = SerializedType, Params extends SerializedTypeParameter[] = SerializedTypeParameter[]> extends SerializedBaseDecl<Name, Params> {
14
- kind: NodeKind["TypeAliasDecl"];
15
- type: T;
16
- isDeprecated?: boolean;
17
- }
18
12
  export declare const GenTypeAliasDecl: <Name extends string, T extends Type, Params extends TypeParameter[]>(sourceUrl: string, options: {
19
13
  name: Name;
20
14
  comment?: string;
@@ -30,9 +24,9 @@ export declare const TypeAliasDecl: <Name extends string, T extends Type>(source
30
24
  type: () => T;
31
25
  }) => TypeAliasDecl<Name, T, []>;
32
26
  export { TypeAliasDecl as TypeAlias };
33
- export declare const isTypeAliasDecl: (node: Node) => node is TypeAliasDecl;
27
+ export declare const isTypeAliasDecl: Predicate<TypeAliasDecl>;
34
28
  export declare const getNestedDeclarationsInTypeAliasDecl: GetNestedDeclarations<TypeAliasDecl>;
35
- export declare const validateTypeAliasDecl: <Params extends TypeParameter[]>(helpers: ValidatorHelpers, decl: TypeAliasDecl<string, Type, Params>, args: TypeArguments<Params>, value: unknown) => Error[];
36
- export declare const resolveTypeArgumentsInTypeAliasDecl: <Params extends TypeParameter[]>(decl: TypeAliasDecl<string, Type, Params>, args: TypeArguments<Params>) => TypeAliasDecl<string, Type, []>;
37
- export declare const serializeTypeAliasDecl: Serializer<TypeAliasDecl, SerializedTypeAliasDecl>;
29
+ export declare const validateTypeAliasDecl: <Params extends TypeParameter[]>(helpers: Validators, decl: TypeAliasDecl<string, Type, Params>, args: TypeArguments<Params>, value: unknown) => Error[];
30
+ export declare const resolveTypeArgumentsInTypeAliasDecl: TypeArgumentsResolver<TypeAliasDecl>;
31
+ export declare const serializeTypeAliasDecl: Serializer<TypeAliasDecl>;
38
32
  export declare const getReferencesForTypeAliasDecl: GetReferences<TypeAliasDecl>;
@@ -1,15 +1,14 @@
1
1
  import { Lazy } from "../../../shared/utils/lazy.js";
2
- import { NodeKind } from "../Node.js";
2
+ import { getNestedDeclarations, getReferences, NodeKind, resolveTypeArguments, serializeNode, validateType, } from "../Node.js";
3
3
  import { serializeTypeParameter } from "../TypeParameter.js";
4
- import { getReferencesForType, resolveTypeArgumentsInType, serializeType, setParent, validate, } from "../types/Type.js";
5
- import { getNestedDeclarations, getTypeArgumentsRecord, validateDeclName } from "./Declaration.js";
4
+ import { getTypeArgumentsRecord, validateDeclName } from "./Declaration.js";
6
5
  export const GenTypeAliasDecl = (sourceUrl, options) => {
7
6
  validateDeclName(options.name);
8
7
  const decl = {
9
8
  ...options,
10
9
  kind: NodeKind.TypeAliasDecl,
11
10
  sourceUrl,
12
- type: Lazy.of(() => setParent(options.type(...options.parameters), decl)),
11
+ type: Lazy.of(() => options.type(...options.parameters)),
13
12
  };
14
13
  return decl;
15
14
  };
@@ -21,21 +20,21 @@ export const TypeAliasDecl = (sourceUrl, options) => {
21
20
  kind: NodeKind.TypeAliasDecl,
22
21
  sourceUrl,
23
22
  parameters: [],
24
- type: Lazy.of(() => setParent(options.type(), decl)),
23
+ type: Lazy.of(() => options.type()),
25
24
  };
26
25
  return decl;
27
26
  };
28
27
  export { TypeAliasDecl as TypeAlias };
29
- export const isTypeAliasDecl = (node) => node.kind === NodeKind.TypeAliasDecl;
28
+ export const isTypeAliasDecl = node => node.kind === NodeKind.TypeAliasDecl;
30
29
  export const getNestedDeclarationsInTypeAliasDecl = (addedDecls, decl) => getNestedDeclarations(addedDecls, decl.type.value);
31
- export const validateTypeAliasDecl = (helpers, decl, args, value) => validate(helpers, resolveTypeArgumentsInType(getTypeArgumentsRecord(decl, args), decl.type.value), value);
32
- export const resolveTypeArgumentsInTypeAliasDecl = (decl, args) => TypeAliasDecl(decl.sourceUrl, {
30
+ export const validateTypeAliasDecl = ((helpers, decl, args, value) => validateType(helpers, resolveTypeArguments(getTypeArgumentsRecord(decl, args), decl.type.value), value));
31
+ export const resolveTypeArgumentsInTypeAliasDecl = (args, decl) => TypeAliasDecl(decl.sourceUrl, {
33
32
  ...decl,
34
- type: () => resolveTypeArgumentsInType(getTypeArgumentsRecord(decl, args), decl.type.value),
33
+ type: () => resolveTypeArguments(args, decl.type.value),
35
34
  });
36
35
  export const serializeTypeAliasDecl = type => ({
37
36
  ...type,
38
- type: serializeType(type.type.value),
37
+ type: serializeNode(type.type.value),
39
38
  parameters: type.parameters.map(param => serializeTypeParameter(param)),
40
39
  });
41
- export const getReferencesForTypeAliasDecl = (decl, value) => getReferencesForType(decl.type.value, value);
40
+ export const getReferencesForTypeAliasDecl = (decl, value) => getReferences(decl.type.value, value);
@@ -11,8 +11,6 @@ export * from "./types/primitives/BooleanType.ts";
11
11
  export * from "./types/primitives/DateType.ts";
12
12
  export * from "./types/primitives/FloatType.ts";
13
13
  export * from "./types/primitives/IntegerType.ts";
14
- export * from "./types/primitives/NumericType.ts";
15
- export type * from "./types/primitives/PrimitiveType.ts";
16
14
  export * from "./types/primitives/StringType.ts";
17
15
  export * from "./types/references/IncludeIdentifierType.ts";
18
16
  export * from "./types/references/NestedEntityMapType.ts";
@@ -11,7 +11,6 @@ export * from "./types/primitives/BooleanType.js";
11
11
  export * from "./types/primitives/DateType.js";
12
12
  export * from "./types/primitives/FloatType.js";
13
13
  export * from "./types/primitives/IntegerType.js";
14
- export * from "./types/primitives/NumericType.js";
15
14
  export * from "./types/primitives/StringType.js";
16
15
  export * from "./types/references/IncludeIdentifierType.js";
17
16
  export * from "./types/references/NestedEntityMapType.js";
@@ -1,52 +1,29 @@
1
- import type { Decl } from "../declarations/Declaration.ts";
2
- import type { BaseNode, GetReferences, Serializer } from "../Node.ts";
3
- import type { Validator } from "../validation/type.ts";
4
- import type { ArrayType, SerializedArrayType } from "./generic/ArrayType.ts";
5
- import type { EnumType, SerializedEnumType } from "./generic/EnumType.ts";
6
- import type { MemberDecl, ObjectType, SerializedMemberDecl, SerializedObjectType } from "./generic/ObjectType.ts";
7
- import type { BooleanType, SerializedBooleanType } from "./primitives/BooleanType.ts";
8
- import type { DateType, SerializedDateType } from "./primitives/DateType.ts";
9
- import type { FloatType, SerializedFloatType } from "./primitives/FloatType.ts";
10
- import type { IntegerType, SerializedIntegerType } from "./primitives/IntegerType.ts";
11
- import type { PrimitiveType, SerializedPrimitiveType } from "./primitives/PrimitiveType.ts";
12
- import type { SerializedStringType, StringType } from "./primitives/StringType.ts";
13
- import type { IncludeIdentifierType, SerializedIncludeIdentifierType } from "./references/IncludeIdentifierType.ts";
14
- import type { NestedEntityMapType, SerializedNestedEntityMapType } from "./references/NestedEntityMapType.ts";
15
- import type { ReferenceIdentifierType, SerializedReferenceIdentifierType } from "./references/ReferenceIdentifierType.ts";
16
- import type { SerializedTypeArgumentType, TypeArgumentType } from "./references/TypeArgumentType.ts";
1
+ import type { Decl } from "../index.ts";
2
+ import type { BaseNode } from "../Node.ts";
3
+ import type { ArrayType } from "./generic/ArrayType.ts";
4
+ import type { EnumType } from "./generic/EnumType.ts";
5
+ import type { MemberDecl, ObjectType } from "./generic/ObjectType.ts";
6
+ import type { BooleanType } from "./primitives/BooleanType.ts";
7
+ import type { DateType } from "./primitives/DateType.ts";
8
+ import type { FloatType } from "./primitives/FloatType.ts";
9
+ import type { IntegerType } from "./primitives/IntegerType.ts";
10
+ import type { StringType } from "./primitives/StringType.ts";
11
+ import { type ChildEntitiesType } from "./references/ChildEntitiesType.ts";
12
+ import type { IncludeIdentifierType } from "./references/IncludeIdentifierType.ts";
13
+ import type { NestedEntityMapType } from "./references/NestedEntityMapType.ts";
14
+ import type { ReferenceIdentifierType } from "./references/ReferenceIdentifierType.ts";
15
+ import type { TypeArgumentType } from "./references/TypeArgumentType.ts";
17
16
  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
17
  }
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;
18
+ export type Type = BooleanType | DateType | FloatType | IntegerType | StringType | ArrayType | ObjectType | TypeArgumentType | ReferenceIdentifierType | IncludeIdentifierType | NestedEntityMapType | EnumType | ChildEntitiesType;
19
+ export declare function walkTypeNodeTree(callbackFn: (type: Type, parentTypes: Type[], parentDecl: Decl) => void, type: Type, parentTypes: Type[], parentDecl: Decl): void;
30
20
  export type AsType<T extends Type> = T extends ArrayType<infer I> ? AsType<I>[] : T extends ObjectType<infer P> ? {
31
21
  [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;
22
+ } : 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 ? string : T extends ChildEntitiesType ? string[] : never;
36
23
  export type AsNode<T> = T extends (infer I)[] ? ArrayType<AsNode<I>> : T extends Record<string, unknown> ? ObjectType<{
37
24
  [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
- /**
41
- * Sets the `parent` property of the passed `type` to the passed `parentNode`.
42
- *
43
- * The property is set on the instance. It does not create a new instance.
44
- */
45
- export declare const setParent: <T extends BaseType>(type: Omit<T, "parent">, parentNode: Type | Decl) => T;
46
- export declare const removeParentKey: <T extends BaseType>(type: T) => Omit<T, "parent">;
25
+ }> : T extends string ? StringType : T extends number ? FloatType : T extends boolean ? BooleanType : T extends Date ? DateType : never;
47
26
  export declare const findTypeAtPath: (type: Type, path: string[]) => Type | undefined;
48
- export declare const serializeType: Serializer<Type, SerializedType>;
49
- export declare const getReferencesForType: GetReferences<Type>;
50
27
  /**
51
28
  * Format the structure of a value to always look the same when serialized as JSON.
52
29
  */