tsondb 0.5.5 → 0.5.7

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 (203) hide show
  1. package/README.md +45 -8
  2. package/{lib → dist/src}/bin/tsondb.js +18 -3
  3. package/{lib → dist/src}/node/Schema.d.ts +2 -2
  4. package/{lib → dist/src}/node/index.d.ts +8 -3
  5. package/{lib → dist/src}/node/index.js +15 -14
  6. package/{lib → dist/src}/node/renderers/Output.d.ts +1 -1
  7. package/{lib → dist/src}/node/renderers/jsonschema/index.d.ts +2 -2
  8. package/{lib → dist/src}/node/renderers/jsonschema/render.d.ts +1 -1
  9. package/{lib → dist/src}/node/renderers/ts/index.d.ts +2 -2
  10. package/{lib → dist/src}/node/renderers/ts/render.d.ts +1 -1
  11. package/{lib → dist/src}/node/schema/Node.d.ts +4 -4
  12. package/{lib → dist/src}/node/schema/Node.js +12 -9
  13. package/{lib → dist/src}/node/schema/TypeParameter.d.ts +3 -3
  14. package/{lib → dist/src}/node/schema/declarations/Declaration.d.ts +8 -8
  15. package/{lib → dist/src}/node/schema/declarations/EntityDecl.d.ts +10 -10
  16. package/{lib → dist/src}/node/schema/declarations/EnumDecl.d.ts +9 -9
  17. package/{lib → dist/src}/node/schema/declarations/TypeAliasDecl.d.ts +7 -7
  18. package/dist/src/node/schema/index.d.ts +21 -0
  19. package/{lib → dist/src}/node/schema/types/Type.d.ts +16 -16
  20. package/{lib → dist/src}/node/schema/types/generic/ArrayType.d.ts +5 -5
  21. package/{lib → dist/src}/node/schema/types/generic/ArrayType.js +3 -2
  22. package/{lib → dist/src}/node/schema/types/generic/EnumType.d.ts +5 -5
  23. package/{lib → dist/src}/node/schema/types/generic/EnumType.js +6 -5
  24. package/{lib → dist/src}/node/schema/types/generic/ObjectType.d.ts +6 -6
  25. package/{lib → dist/src}/node/schema/types/generic/ObjectType.js +4 -3
  26. package/{lib → dist/src}/node/schema/types/primitives/BooleanType.d.ts +4 -4
  27. package/{lib → dist/src}/node/schema/types/primitives/BooleanType.js +2 -1
  28. package/{lib → dist/src}/node/schema/types/primitives/DateType.d.ts +5 -5
  29. package/{lib → dist/src}/node/schema/types/primitives/DateType.js +2 -1
  30. package/{lib → dist/src}/node/schema/types/primitives/FloatType.d.ts +5 -5
  31. package/{lib → dist/src}/node/schema/types/primitives/FloatType.js +2 -1
  32. package/{lib → dist/src}/node/schema/types/primitives/IntegerType.d.ts +5 -5
  33. package/{lib → dist/src}/node/schema/types/primitives/IntegerType.js +2 -1
  34. package/{lib → dist/src}/node/schema/types/primitives/NumericType.d.ts +4 -4
  35. package/{lib → dist/src}/node/schema/types/primitives/PrimitiveType.d.ts +4 -4
  36. package/{lib → dist/src}/node/schema/types/primitives/StringType.d.ts +5 -5
  37. package/{lib → dist/src}/node/schema/types/primitives/StringType.js +2 -1
  38. package/{lib → dist/src}/node/schema/types/references/IncludeIdentifierType.d.ts +9 -9
  39. package/{lib → dist/src}/node/schema/types/references/NestedEntityMapType.d.ts +8 -8
  40. package/{lib → dist/src}/node/schema/types/references/NestedEntityMapType.js +3 -2
  41. package/{lib → dist/src}/node/schema/types/references/ReferenceIdentifierType.d.ts +6 -6
  42. package/{lib → dist/src}/node/schema/types/references/TypeArgumentType.d.ts +5 -5
  43. package/{lib → dist/src}/node/schema/validation/type.d.ts +2 -2
  44. package/{lib → dist/src}/node/server/api/instanceOperations.d.ts +3 -3
  45. package/{lib → dist/src}/node/server/index.d.ts +4 -4
  46. package/{lib → dist/src}/node/server/init.d.ts +2 -2
  47. package/dist/src/node/utils/errorFormatting.d.ts +3 -0
  48. package/dist/src/node/utils/errorFormatting.js +4 -0
  49. package/{lib → dist/src}/node/utils/git.d.ts +1 -1
  50. package/{lib → dist/src}/node/utils/instances.d.ts +2 -2
  51. package/{lib → dist/src}/node/utils/references.d.ts +2 -2
  52. package/{lib → dist/src}/shared/api.d.ts +2 -2
  53. package/{lib → dist/src}/shared/utils/displayName.d.ts +1 -1
  54. package/{lib → dist/src}/shared/utils/instances.d.ts +2 -2
  55. package/{lib → dist/src}/web/api.d.ts +2 -2
  56. package/{lib → dist/src}/web/components/typeInputs/ArrayTypeInput.d.ts +3 -3
  57. package/{lib → dist/src}/web/components/typeInputs/BooleanTypeInput.d.ts +1 -1
  58. package/{lib → dist/src}/web/components/typeInputs/DateTypeInput.d.ts +1 -1
  59. package/{lib → dist/src}/web/components/typeInputs/EnumTypeInput.d.ts +3 -3
  60. package/{lib → dist/src}/web/components/typeInputs/FloatTypeInput.d.ts +1 -1
  61. package/{lib → dist/src}/web/components/typeInputs/GenericTypeArgumentIdentifierTypeInput.d.ts +1 -1
  62. package/{lib → dist/src}/web/components/typeInputs/IncludeIdentifierTypeInput.d.ts +3 -3
  63. package/{lib → dist/src}/web/components/typeInputs/IntegerTypeInput.d.ts +1 -1
  64. package/{lib → dist/src}/web/components/typeInputs/NestedEntityMapTypeInput.d.ts +3 -3
  65. package/{lib → dist/src}/web/components/typeInputs/ObjectTypeInput.d.ts +3 -3
  66. package/{lib → dist/src}/web/components/typeInputs/ReferenceIdentifierTypeInput.d.ts +2 -2
  67. package/{lib → dist/src}/web/components/typeInputs/StringTypeInput.d.ts +1 -1
  68. package/{lib → dist/src}/web/components/typeInputs/TypeInput.d.ts +3 -3
  69. package/{lib → dist/src}/web/hooks/useEntityFromRoute.d.ts +1 -1
  70. package/{lib → dist/src}/web/hooks/useInstanceNamesByEntity.d.ts +1 -1
  71. package/{lib → dist/src}/web/hooks/useSecondaryDeclarations.d.ts +1 -1
  72. package/{lib → dist/src}/web/utils/typeSkeleton.d.ts +2 -2
  73. package/package.json +20 -23
  74. package/lib/node/schema/index.d.ts +0 -21
  75. /package/{lib → dist/src}/bin/tsondb.d.ts +0 -0
  76. /package/{lib → dist/src}/index.d.ts +0 -0
  77. /package/{lib → dist/src}/index.js +0 -0
  78. /package/{lib → dist/src}/node/Schema.js +0 -0
  79. /package/{lib → dist/src}/node/renderers/Output.js +0 -0
  80. /package/{lib → dist/src}/node/renderers/jsonschema/index.js +0 -0
  81. /package/{lib → dist/src}/node/renderers/jsonschema/render.js +0 -0
  82. /package/{lib → dist/src}/node/renderers/ts/index.js +0 -0
  83. /package/{lib → dist/src}/node/renderers/ts/render.js +0 -0
  84. /package/{lib → dist/src}/node/schema/TypeParameter.js +0 -0
  85. /package/{lib → dist/src}/node/schema/declarations/Declaration.js +0 -0
  86. /package/{lib → dist/src}/node/schema/declarations/EntityDecl.js +0 -0
  87. /package/{lib → dist/src}/node/schema/declarations/EnumDecl.js +0 -0
  88. /package/{lib → dist/src}/node/schema/declarations/TypeAliasDecl.js +0 -0
  89. /package/{lib → dist/src}/node/schema/index.js +0 -0
  90. /package/{lib → dist/src}/node/schema/types/Type.js +0 -0
  91. /package/{lib → dist/src}/node/schema/types/primitives/NumericType.js +0 -0
  92. /package/{lib → dist/src}/node/schema/types/primitives/PrimitiveType.js +0 -0
  93. /package/{lib → dist/src}/node/schema/types/references/IncludeIdentifierType.js +0 -0
  94. /package/{lib → dist/src}/node/schema/types/references/ReferenceIdentifierType.js +0 -0
  95. /package/{lib → dist/src}/node/schema/types/references/TypeArgumentType.js +0 -0
  96. /package/{lib → dist/src}/node/schema/validation/options.d.ts +0 -0
  97. /package/{lib → dist/src}/node/schema/validation/options.js +0 -0
  98. /package/{lib → dist/src}/node/schema/validation/type.js +0 -0
  99. /package/{lib → dist/src}/node/server/api/declarations.d.ts +0 -0
  100. /package/{lib → dist/src}/node/server/api/declarations.js +0 -0
  101. /package/{lib → dist/src}/node/server/api/git.d.ts +0 -0
  102. /package/{lib → dist/src}/node/server/api/git.js +0 -0
  103. /package/{lib → dist/src}/node/server/api/index.d.ts +0 -0
  104. /package/{lib → dist/src}/node/server/api/index.js +0 -0
  105. /package/{lib → dist/src}/node/server/api/instanceOperations.js +0 -0
  106. /package/{lib → dist/src}/node/server/api/instances.d.ts +0 -0
  107. /package/{lib → dist/src}/node/server/api/instances.js +0 -0
  108. /package/{lib → dist/src}/node/server/index.js +0 -0
  109. /package/{lib → dist/src}/node/server/init.js +0 -0
  110. /package/{lib → dist/src}/node/utils/error.d.ts +0 -0
  111. /package/{lib → dist/src}/node/utils/error.js +0 -0
  112. /package/{lib → dist/src}/node/utils/git.js +0 -0
  113. /package/{lib → dist/src}/node/utils/instances.js +0 -0
  114. /package/{lib → dist/src}/node/utils/path.d.ts +0 -0
  115. /package/{lib → dist/src}/node/utils/path.js +0 -0
  116. /package/{lib → dist/src}/node/utils/references.js +0 -0
  117. /package/{lib → dist/src}/node/utils/render.d.ts +0 -0
  118. /package/{lib → dist/src}/node/utils/render.js +0 -0
  119. /package/{lib → dist/src}/shared/api.js +0 -0
  120. /package/{lib → dist/src}/shared/enum.d.ts +0 -0
  121. /package/{lib → dist/src}/shared/enum.js +0 -0
  122. /package/{lib → dist/src}/shared/utils/array.d.ts +0 -0
  123. /package/{lib → dist/src}/shared/utils/array.js +0 -0
  124. /package/{lib → dist/src}/shared/utils/compare.d.ts +0 -0
  125. /package/{lib → dist/src}/shared/utils/compare.js +0 -0
  126. /package/{lib → dist/src}/shared/utils/displayName.js +0 -0
  127. /package/{lib → dist/src}/shared/utils/enum.d.ts +0 -0
  128. /package/{lib → dist/src}/shared/utils/enum.js +0 -0
  129. /package/{lib → dist/src}/shared/utils/git.d.ts +0 -0
  130. /package/{lib → dist/src}/shared/utils/git.js +0 -0
  131. /package/{lib → dist/src}/shared/utils/instances.js +0 -0
  132. /package/{lib → dist/src}/shared/utils/lazy.d.ts +0 -0
  133. /package/{lib → dist/src}/shared/utils/lazy.js +0 -0
  134. /package/{lib → dist/src}/shared/utils/markdown.d.ts +0 -0
  135. /package/{lib → dist/src}/shared/utils/markdown.js +0 -0
  136. /package/{lib → dist/src}/shared/utils/object.d.ts +0 -0
  137. /package/{lib → dist/src}/shared/utils/object.js +0 -0
  138. /package/{lib → dist/src}/shared/utils/result.d.ts +0 -0
  139. /package/{lib → dist/src}/shared/utils/result.js +0 -0
  140. /package/{lib → dist/src}/shared/utils/string.d.ts +0 -0
  141. /package/{lib → dist/src}/shared/utils/string.js +0 -0
  142. /package/{lib → dist/src}/shared/utils/typeSafety.d.ts +0 -0
  143. /package/{lib → dist/src}/shared/utils/typeSafety.js +0 -0
  144. /package/{lib → dist/src}/shared/utils/validation.d.ts +0 -0
  145. /package/{lib → dist/src}/shared/utils/validation.js +0 -0
  146. /package/{lib → dist/src}/shared/validation/array.d.ts +0 -0
  147. /package/{lib → dist/src}/shared/validation/array.js +0 -0
  148. /package/{lib → dist/src}/shared/validation/date.d.ts +0 -0
  149. /package/{lib → dist/src}/shared/validation/date.js +0 -0
  150. /package/{lib → dist/src}/shared/validation/identifier.d.ts +0 -0
  151. /package/{lib → dist/src}/shared/validation/identifier.js +0 -0
  152. /package/{lib → dist/src}/shared/validation/number.d.ts +0 -0
  153. /package/{lib → dist/src}/shared/validation/number.js +0 -0
  154. /package/{lib → dist/src}/shared/validation/object.d.ts +0 -0
  155. /package/{lib → dist/src}/shared/validation/object.js +0 -0
  156. /package/{lib → dist/src}/shared/validation/string.d.ts +0 -0
  157. /package/{lib → dist/src}/shared/validation/string.js +0 -0
  158. /package/{lib → dist/src}/web/api.js +0 -0
  159. /package/{lib → dist/src}/web/components/Git.d.ts +0 -0
  160. /package/{lib → dist/src}/web/components/Git.js +0 -0
  161. /package/{lib → dist/src}/web/components/Layout.d.ts +0 -0
  162. /package/{lib → dist/src}/web/components/Layout.js +0 -0
  163. /package/{lib → dist/src}/web/components/Select.d.ts +0 -0
  164. /package/{lib → dist/src}/web/components/Select.js +0 -0
  165. /package/{lib → dist/src}/web/components/typeInputs/ArrayTypeInput.js +0 -0
  166. /package/{lib → dist/src}/web/components/typeInputs/BooleanTypeInput.js +0 -0
  167. /package/{lib → dist/src}/web/components/typeInputs/DateTypeInput.js +0 -0
  168. /package/{lib → dist/src}/web/components/typeInputs/EnumTypeInput.js +0 -0
  169. /package/{lib → dist/src}/web/components/typeInputs/FloatTypeInput.js +0 -0
  170. /package/{lib → dist/src}/web/components/typeInputs/GenericTypeArgumentIdentifierTypeInput.js +0 -0
  171. /package/{lib → dist/src}/web/components/typeInputs/IncludeIdentifierTypeInput.js +0 -0
  172. /package/{lib → dist/src}/web/components/typeInputs/IntegerTypeInput.js +0 -0
  173. /package/{lib → dist/src}/web/components/typeInputs/NestedEntityMapTypeInput.js +0 -0
  174. /package/{lib → dist/src}/web/components/typeInputs/ObjectTypeInput.js +0 -0
  175. /package/{lib → dist/src}/web/components/typeInputs/ReferenceIdentifierTypeInput.js +0 -0
  176. /package/{lib → dist/src}/web/components/typeInputs/StringTypeInput.js +0 -0
  177. /package/{lib → dist/src}/web/components/typeInputs/TypeInput.js +0 -0
  178. /package/{lib → dist/src}/web/components/typeInputs/utils/MismatchingTypeError.d.ts +0 -0
  179. /package/{lib → dist/src}/web/components/typeInputs/utils/MismatchingTypeError.js +0 -0
  180. /package/{lib → dist/src}/web/components/typeInputs/utils/ValidationErrors.d.ts +0 -0
  181. /package/{lib → dist/src}/web/components/typeInputs/utils/ValidationErrors.js +0 -0
  182. /package/{lib → dist/src}/web/hooks/useAPIResource.d.ts +0 -0
  183. /package/{lib → dist/src}/web/hooks/useAPIResource.js +0 -0
  184. /package/{lib → dist/src}/web/hooks/useEntityFromRoute.js +0 -0
  185. /package/{lib → dist/src}/web/hooks/useInstanceNamesByEntity.js +0 -0
  186. /package/{lib → dist/src}/web/hooks/useMappedAPIResource.d.ts +0 -0
  187. /package/{lib → dist/src}/web/hooks/useMappedAPIResource.js +0 -0
  188. /package/{lib → dist/src}/web/hooks/useSecondaryDeclarations.js +0 -0
  189. /package/{lib → dist/src}/web/index.d.ts +0 -0
  190. /package/{lib → dist/src}/web/index.js +0 -0
  191. /package/{lib → dist/src}/web/routes/CreateInstance.d.ts +0 -0
  192. /package/{lib → dist/src}/web/routes/CreateInstance.js +0 -0
  193. /package/{lib → dist/src}/web/routes/Entity.d.ts +0 -0
  194. /package/{lib → dist/src}/web/routes/Entity.js +0 -0
  195. /package/{lib → dist/src}/web/routes/Home.d.ts +0 -0
  196. /package/{lib → dist/src}/web/routes/Home.js +0 -0
  197. /package/{lib → dist/src}/web/routes/Instance.d.ts +0 -0
  198. /package/{lib → dist/src}/web/routes/Instance.js +0 -0
  199. /package/{lib → dist/src}/web/routes/NotFound.d.ts +0 -0
  200. /package/{lib → dist/src}/web/routes/NotFound.js +0 -0
  201. /package/{lib → dist/src}/web/utils/Markdown.d.ts +0 -0
  202. /package/{lib → dist/src}/web/utils/Markdown.js +0 -0
  203. /package/{lib → dist/src}/web/utils/typeSkeleton.js +0 -0
package/README.md CHANGED
@@ -10,6 +10,44 @@ TSON-DB can also be used to render type declarations in multiple languages or vo
10
10
  npm install tsondb
11
11
  ```
12
12
 
13
+ ## Configuration
14
+
15
+ To configure `tsondb`, create a configuration file at the location from where you are going to run its commands, usually the project root. The following file names are possible and are checked in the given order:
16
+
17
+ 1. `tsondb.config.mts`
18
+ 2. `tsondb.config.ts`
19
+ 3. `tsondb.config.mjs`
20
+ 4. `tsondb.config.js`
21
+
22
+ You need to export an object conforming to the `Config` type as the default export.
23
+
24
+ ```ts
25
+ // tsondb.config.ts
26
+ import { join } from "node:path"
27
+ import { type Config, Schema } from "tsondb"
28
+ import { JsonSchemaOutput } from "tsondb/renderer/jsonschema"
29
+ import { TypeScriptOutput } from "tsondb/renderer/ts"
30
+
31
+ export default {
32
+ schema: new Schema(
33
+ [
34
+ // add your entities here
35
+ ]
36
+ ),
37
+ outputs: [
38
+ TypeScriptOutput({
39
+ targetPath: join(import.meta.dirname, "gen", "ts"),
40
+ }),
41
+ JsonSchemaOutput({
42
+ targetPath: join(import.meta.dirname, "gen", "schema"),
43
+ }),
44
+ ],
45
+ dataRootPath: join(import.meta.dirname, "data"),
46
+ } satisfies Config
47
+ ```
48
+
49
+ See the following sections for details on how the different parts come together.
50
+
13
51
  ## Define a Schema
14
52
 
15
53
  You define a schema by declarations that consist of types.
@@ -40,6 +78,8 @@ Note that some imports may shadow global objects (like `String` and `Object` in
40
78
 
41
79
  Make sure to always pass `import.meta.url` as the first parameter to each declaration function, otherwise some functionality will not work at all or will not work as expected.
42
80
 
81
+ To actually add `Ùser` to your schema, either list it in the array passed to the `Schema` function or reference it in an entity that is already listed.
82
+
43
83
  ### Available Declarations
44
84
 
45
85
  #### `Entity` or `EntityDecl`
@@ -146,26 +186,23 @@ If the database is in a Git repository, you’ll also get a simple Git GUI for m
146
186
 
147
187
  ## Generate typings
148
188
 
149
- To generate typings, you have to define the `outputs` option on the `ModelContainer`.
189
+ To generate typings, you have to define the `outputs` property in the configuration file.
150
190
 
151
191
  ```ts
152
- ModelContainer({
192
+ export default {
153
193
  // ...
154
194
  outputs: [
155
195
  TypeScriptOutput({
156
- targetPath: join(import.meta.dirname, "..", "gen", "types.d.ts"),
157
- rendererOptions: {
158
- preserveFiles: false,
159
- },
196
+ targetPath: join(import.meta.dirname, "gen", "types.d.ts"),
160
197
  }),
161
198
  JsonSchemaOutput({
162
- targetPath: join(import.meta.dirname, "..", "gen", "types.schema.json"),
199
+ targetPath: join(import.meta.dirname, "gen", "schema"),
163
200
  rendererOptions: {
164
201
  preserveFiles: true,
165
202
  },
166
203
  }),
167
204
  ],
168
- })
205
+ } satisfies Config
169
206
  ```
170
207
 
171
208
  You specify a target path where to save each generated content, and you can optionally provide custom settings to the respective renderers.
@@ -19,6 +19,18 @@ const passedArguments = parseArguments({
19
19
  commands: {
20
20
  validate: {
21
21
  name: "validate",
22
+ options: {
23
+ checkReferentialIntegrity: {
24
+ name: "check-referential-integrity",
25
+ type: Boolean,
26
+ },
27
+ entities: {
28
+ name: "entities",
29
+ alias: "e",
30
+ multiple: true,
31
+ type: String,
32
+ },
33
+ },
22
34
  },
23
35
  generate: {
24
36
  name: "generate",
@@ -33,10 +45,10 @@ const passedArguments = parseArguments({
33
45
  });
34
46
  // import the config
35
47
  const possibleConfigNames = [
36
- "tsondb.config.ts",
37
48
  "tsondb.config.mts",
38
- "tsondb.config.js",
49
+ "tsondb.config.ts",
39
50
  "tsondb.config.mjs",
51
+ "tsondb.config.js",
40
52
  ];
41
53
  const config = await (async () => {
42
54
  for (const configName of possibleConfigNames) {
@@ -76,7 +88,10 @@ switch (passedArguments.command.name) {
76
88
  break;
77
89
  case "validate":
78
90
  debug(`running command: validate`);
79
- await validate(config.schema, config.dataRootPath);
91
+ await validate(config.schema, config.dataRootPath, {
92
+ checkReferentialIntegrity: passedArguments.command.options?.checkReferentialIntegrity,
93
+ checkOnlyEntities: passedArguments.command.options?.entities,
94
+ });
80
95
  break;
81
96
  case "format":
82
97
  debug(`running command: format`);
@@ -1,5 +1,5 @@
1
- import type { Decl } from "./schema/declarations/Declaration.js";
2
- import type { EntityDecl } from "./schema/declarations/EntityDecl.js";
1
+ import type { Decl } from "./schema/declarations/Declaration.ts";
2
+ import type { EntityDecl } from "./schema/declarations/EntityDecl.ts";
3
3
  export interface Schema {
4
4
  declarations: readonly Decl[];
5
5
  localeEntity?: EntityDecl;
@@ -2,8 +2,13 @@ import type { Output } from "./renderers/Output.ts";
2
2
  import type { Schema } from "./Schema.ts";
3
3
  import type { ServerOptions } from "./server/index.ts";
4
4
  export declare const generateOutputs: (schema: Schema, outputs: Output[]) => Promise<void>;
5
- export declare const validate: (schema: Schema, dataRootPath: string) => Promise<void>;
6
- export declare const generateAndValidate: (schema: Schema, outputs: Output[], dataRootPath: string) => Promise<void>;
5
+ type ValidationOptions = {
6
+ checkReferentialIntegrity: boolean;
7
+ checkOnlyEntities: string[];
8
+ };
9
+ export declare const validate: (schema: Schema, dataRootPath: string, options?: Partial<ValidationOptions>) => Promise<void>;
10
+ export declare const generateAndValidate: (schema: Schema, outputs: Output[], dataRootPath: string, validationOptions?: Partial<ValidationOptions>) => Promise<void>;
7
11
  export declare const serve: (schema: Schema, dataRootPath: string, serverOptions?: Partial<ServerOptions>) => Promise<void>;
8
- export declare const generateValidateAndServe: (schema: Schema, outputs: Output[], dataRootPath: string, serverOptions?: Partial<ServerOptions>) => Promise<void>;
12
+ export declare const generateValidateAndServe: (schema: Schema, outputs: Output[], dataRootPath: string, serverOptions?: Partial<ServerOptions>, validationOptions?: Partial<ValidationOptions>) => Promise<void>;
9
13
  export declare const format: (schema: Schema, dataRootPath: string) => Promise<void>;
14
+ export {};
@@ -1,6 +1,7 @@
1
1
  import Debug from "debug";
2
2
  import { mkdir, writeFile } from "fs/promises";
3
- import { join } from "path";
3
+ import { join, sep } from "path";
4
+ import { styleText } from "util";
4
5
  import { parallelizeErrors } from "../shared/utils/validation.js";
5
6
  import { getEntities } from "./Schema.js";
6
7
  import { createValidators, validateEntityDecl } from "./schema/index.js";
@@ -20,33 +21,33 @@ export const generateOutputs = async (schema, outputs) => {
20
21
  await output.run(schema);
21
22
  }
22
23
  };
23
- const _validate = (dataRootPath, entities, instancesByEntityName) => {
24
- const errors = entities
25
- .flatMap(entity => parallelizeErrors(instancesByEntityName[entity.name]?.map(instance => wrapErrorsIfAny(`in file "${join(dataRootPath, entity.name, instance.fileName)}"`, validateEntityDecl(createValidators(instancesByEntityName), entity, instance.content))) ?? []))
24
+ const _validate = (dataRootPath, entities, instancesByEntityName, options = {}) => {
25
+ const { checkReferentialIntegrity = false, checkOnlyEntities = [] } = options;
26
+ const errors = (checkOnlyEntities.length > 0
27
+ ? entities.filter(entity => checkOnlyEntities.includes(entity.name))
28
+ : entities)
29
+ .flatMap(entity => parallelizeErrors(instancesByEntityName[entity.name]?.map(instance => wrapErrorsIfAny(`in file ${styleText("white", `"${dataRootPath}${sep}${styleText("bold", join(entity.name, instance.fileName))}"`)}`, validateEntityDecl(createValidators(instancesByEntityName, checkReferentialIntegrity), entity, instance.content))) ?? []))
26
30
  .toSorted((a, b) => a.message.localeCompare(b.message));
27
31
  if (errors.length === 0) {
28
32
  debug("All entities are valid");
29
33
  }
30
34
  else {
31
- debug("Errors:\n");
32
- for (const error of errors) {
33
- debug(getErrorMessageForDisplay(error) + "\n");
34
- }
35
+ console.error(styleText("red", "\n" + errors.map(err => getErrorMessageForDisplay(err)).join("\n\n")));
35
36
  throw new Error(`Validation failed with ${countErrors(errors).toString()} errors`);
36
37
  }
37
38
  };
38
- export const validate = async (schema, dataRootPath) => {
39
+ export const validate = async (schema, dataRootPath, options) => {
39
40
  const entities = getEntities(schema);
40
41
  await prepareFolders(dataRootPath, entities);
41
42
  const instancesByEntityName = await getInstancesByEntityName(dataRootPath, entities);
42
- _validate(dataRootPath, entities, instancesByEntityName);
43
+ _validate(dataRootPath, entities, instancesByEntityName, options);
43
44
  };
44
- export const generateAndValidate = async (schema, outputs, dataRootPath) => {
45
+ export const generateAndValidate = async (schema, outputs, dataRootPath, validationOptions) => {
45
46
  await generateOutputs(schema, outputs);
46
47
  const entities = getEntities(schema);
47
48
  await prepareFolders(dataRootPath, entities);
48
49
  const instancesByEntityName = await getInstancesByEntityName(dataRootPath, entities);
49
- _validate(dataRootPath, entities, instancesByEntityName);
50
+ _validate(dataRootPath, entities, instancesByEntityName, validationOptions);
50
51
  };
51
52
  export const serve = async (schema, dataRootPath, serverOptions) => {
52
53
  const entities = getEntities(schema);
@@ -54,12 +55,12 @@ export const serve = async (schema, dataRootPath, serverOptions) => {
54
55
  const instancesByEntityName = await getInstancesByEntityName(dataRootPath, entities);
55
56
  await createServer(schema, dataRootPath, instancesByEntityName, serverOptions);
56
57
  };
57
- export const generateValidateAndServe = async (schema, outputs, dataRootPath, serverOptions) => {
58
+ export const generateValidateAndServe = async (schema, outputs, dataRootPath, serverOptions, validationOptions) => {
58
59
  await generateOutputs(schema, outputs);
59
60
  const entities = getEntities(schema);
60
61
  await prepareFolders(dataRootPath, entities);
61
62
  const instancesByEntityName = await getInstancesByEntityName(dataRootPath, entities);
62
- _validate(dataRootPath, entities, instancesByEntityName);
63
+ _validate(dataRootPath, entities, instancesByEntityName, validationOptions);
63
64
  await createServer(schema, dataRootPath, instancesByEntityName, serverOptions);
64
65
  };
65
66
  export const format = async (schema, dataRootPath) => {
@@ -1,4 +1,4 @@
1
- import type { Schema } from "../Schema.js";
1
+ import type { Schema } from "../Schema.ts";
2
2
  export interface Output {
3
3
  run: (schema: Schema) => Promise<void>;
4
4
  }
@@ -1,5 +1,5 @@
1
- import type { Output } from "../Output.js";
2
- import type { JsonSchemaRendererOptions } from "./render.js";
1
+ import type { Output } from "../Output.ts";
2
+ import type { JsonSchemaRendererOptions } from "./render.ts";
3
3
  export declare const JsonSchemaOutput: (options: {
4
4
  targetPath: string;
5
5
  rendererOptions?: Partial<JsonSchemaRendererOptions>;
@@ -1,4 +1,4 @@
1
- import type { Decl } from "../../schema/declarations/Declaration.js";
1
+ import type { Decl } from "../../schema/declarations/Declaration.ts";
2
2
  export type JsonSchemaRendererOptions = {
3
3
  format: "minified" | "tabs" | {
4
4
  kind: "spaces";
@@ -1,5 +1,5 @@
1
- import type { Output } from "../Output.js";
2
- import type { TypeScriptRendererOptions } from "./render.js";
1
+ import type { Output } from "../Output.ts";
2
+ import type { TypeScriptRendererOptions } from "./render.ts";
3
3
  export declare const TypeScriptOutput: (options: {
4
4
  targetPath: string;
5
5
  rendererOptions?: Partial<TypeScriptRendererOptions>;
@@ -1,4 +1,4 @@
1
- import type { Decl } from "../../schema/declarations/Declaration.js";
1
+ import type { Decl } from "../../schema/declarations/Declaration.ts";
2
2
  export type TypeScriptRendererOptions = {
3
3
  indentation: number;
4
4
  objectTypeKeyword: "interface" | "type";
@@ -1,6 +1,6 @@
1
- import type { InstancesByEntityName } from "../../shared/utils/instances.js";
2
- import type { Decl } from "./declarations/Declaration.js";
3
- import type { Type } from "./types/Type.js";
1
+ import type { InstancesByEntityName } from "../../shared/utils/instances.ts";
2
+ import type { Decl } from "./declarations/Declaration.ts";
3
+ import type { Type } from "./types/Type.ts";
4
4
  export interface NodeKind {
5
5
  EntityDecl: "EntityDecl";
6
6
  EnumDecl: "EnumDecl";
@@ -34,6 +34,6 @@ export type IdentifierToCheck = {
34
34
  export interface Validators {
35
35
  checkReferentialIntegrity: (identifier: IdentifierToCheck) => Error[];
36
36
  }
37
- export declare const createValidators: (instancesByEntityName: InstancesByEntityName) => Validators;
37
+ export declare const createValidators: (instancesByEntityName: InstancesByEntityName, checkReferentialIntegrity?: boolean) => Validators;
38
38
  export type Serializer<T, U> = (node: T) => U;
39
39
  export type GetReferences<T extends Node> = (node: T, value: unknown) => string[];
@@ -1,5 +1,6 @@
1
1
  import { enumOfObject } from "../../shared/utils/enum.js";
2
2
  import { assertExhaustive } from "../../shared/utils/typeSafety.js";
3
+ import { entity, json } from "../utils/errorFormatting.js";
3
4
  export const NodeKind = enumOfObject({
4
5
  EntityDecl: null,
5
6
  EnumDecl: null,
@@ -74,13 +75,15 @@ export const flatMapAuxiliaryDecls = (callbackFn, declarations) => {
74
75
  };
75
76
  return declarations.reduce((decls, node) => mapNodeTree(reducer, node, [...decls, node]), []);
76
77
  };
77
- export const createValidators = (instancesByEntityName) => ({
78
- checkReferentialIntegrity: ({ name, value }) => instancesByEntityName[name]?.some(instance => typeof instance.content === "object" &&
79
- instance.content !== null &&
80
- !Array.isArray(instance.content) &&
81
- instance.id === value)
82
- ? []
83
- : [
84
- ReferenceError(`Invalid reference to instance of entity "${name}" with identifier ${JSON.stringify(value)}`),
85
- ],
78
+ export const createValidators = (instancesByEntityName, checkReferentialIntegrity = true) => ({
79
+ checkReferentialIntegrity: checkReferentialIntegrity
80
+ ? ({ name, value }) => instancesByEntityName[name]?.some(instance => typeof instance.content === "object" &&
81
+ instance.content !== null &&
82
+ !Array.isArray(instance.content) &&
83
+ instance.id === value)
84
+ ? []
85
+ : [
86
+ ReferenceError(`Invalid reference to instance of entity ${entity(`"${name}"`)} with identifier ${json(value)}`),
87
+ ]
88
+ : () => [],
86
89
  });
@@ -1,6 +1,6 @@
1
- import type { Serializer } from "./Node.js";
2
- import { NodeKind } from "./Node.js";
3
- import type { SerializedBaseType, SerializedType, Type } from "./types/Type.js";
1
+ import type { Serializer } from "./Node.ts";
2
+ import { NodeKind } from "./Node.ts";
3
+ import type { SerializedBaseType, SerializedType, Type } from "./types/Type.ts";
4
4
  export interface TypeParameter<N extends string = string, T extends Type = Type> {
5
5
  kind: NodeKind["GenericParameter"];
6
6
  name: N;
@@ -1,11 +1,11 @@
1
- import type { BaseNode, GetReferences, Node, Serializer } from "../Node.js";
2
- import type { SerializedTypeParameter, TypeParameter } from "../TypeParameter.js";
3
- import type { EnumCaseDecl, SerializedEnumCaseDecl } from "../types/generic/EnumType.js";
4
- import { type SerializedType, type Type } from "../types/Type.js";
5
- import type { ValidatorHelpers } from "../validation/type.js";
6
- import type { EntityDecl, SerializedEntityDecl } from "./EntityDecl.js";
7
- import type { EnumDecl, SerializedEnumDecl } from "./EnumDecl.js";
8
- import type { SerializedTypeAliasDecl, TypeAliasDecl } from "./TypeAliasDecl.js";
1
+ import type { BaseNode, GetReferences, Node, Serializer } from "../Node.ts";
2
+ import type { SerializedTypeParameter, TypeParameter } from "../TypeParameter.ts";
3
+ import type { EnumCaseDecl, SerializedEnumCaseDecl } from "../types/generic/EnumType.ts";
4
+ import { type SerializedType, type Type } from "../types/Type.ts";
5
+ import type { ValidatorHelpers } from "../validation/type.ts";
6
+ import type { EntityDecl, SerializedEntityDecl } from "./EntityDecl.ts";
7
+ import type { EnumDecl, SerializedEnumDecl } from "./EnumDecl.ts";
8
+ import type { SerializedTypeAliasDecl, TypeAliasDecl } from "./TypeAliasDecl.ts";
9
9
  export type TypeArguments<Params extends TypeParameter[]> = {
10
10
  [K in keyof Params]: Params[K] extends TypeParameter<string, infer T> ? T : Type;
11
11
  };
@@ -1,13 +1,13 @@
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";
6
- import { StringType } from "../types/primitives/StringType.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";
10
- import { TypeAliasDecl } from "./TypeAliasDecl.js";
1
+ import { Lazy } from "../../../shared/utils/lazy.ts";
2
+ import type { Leaves } from "../../../shared/utils/object.ts";
3
+ import type { GetReferences, Node, Serializer } from "../Node.ts";
4
+ import { NodeKind } from "../Node.ts";
5
+ import type { MemberDecl, ObjectType, SerializedObjectType } from "../types/generic/ObjectType.ts";
6
+ 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";
10
+ import { TypeAliasDecl } from "./TypeAliasDecl.ts";
11
11
  export interface EntityDecl<Name extends string = string, T extends ObjectType = ObjectType> extends BaseDecl<Name, []> {
12
12
  kind: NodeKind["EntityDecl"];
13
13
  namePlural: string;
@@ -1,12 +1,12 @@
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";
1
+ import { Lazy } from "../../../shared/utils/lazy.ts";
2
+ import type { GetReferences, Node, Serializer } from "../Node.ts";
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";
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
10
  export interface EnumDecl<Name extends string = string, T extends Record<string, EnumCaseDecl> = Record<string, EnumCaseDecl>, Params extends TypeParameter[] = TypeParameter[]> extends BaseDecl<Name, Params> {
11
11
  kind: NodeKind["EnumDecl"];
12
12
  type: Lazy<EnumType<T>>;
@@ -1,10 +1,10 @@
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";
1
+ import { Lazy } from "../../../shared/utils/lazy.ts";
2
+ import type { GetReferences, Node, Serializer } from "../Node.ts";
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";
8
8
  export interface TypeAliasDecl<Name extends string = string, T extends Type = Type, Params extends TypeParameter[] = TypeParameter[]> extends BaseDecl<Name, Params> {
9
9
  kind: NodeKind["TypeAliasDecl"];
10
10
  type: Lazy<T>;
@@ -0,0 +1,21 @@
1
+ export * from "./declarations/Declaration.ts";
2
+ export * from "./declarations/EntityDecl.ts";
3
+ export * from "./declarations/EnumDecl.ts";
4
+ export * from "./declarations/TypeAliasDecl.ts";
5
+ export * from "./Node.ts";
6
+ export * from "./TypeParameter.ts";
7
+ export * from "./types/generic/ArrayType.ts";
8
+ export * from "./types/generic/EnumType.ts";
9
+ export * from "./types/generic/ObjectType.ts";
10
+ export * from "./types/primitives/BooleanType.ts";
11
+ export * from "./types/primitives/DateType.ts";
12
+ export * from "./types/primitives/FloatType.ts";
13
+ export * from "./types/primitives/IntegerType.ts";
14
+ export * from "./types/primitives/NumericType.ts";
15
+ export type * from "./types/primitives/PrimitiveType.ts";
16
+ export * from "./types/primitives/StringType.ts";
17
+ export * from "./types/references/IncludeIdentifierType.ts";
18
+ export * from "./types/references/NestedEntityMapType.ts";
19
+ export * from "./types/references/ReferenceIdentifierType.ts";
20
+ export * from "./types/references/TypeArgumentType.ts";
21
+ export * from "./types/Type.ts";
@@ -1,19 +1,19 @@
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";
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";
17
17
  export interface BaseType extends BaseNode {
18
18
  /**
19
19
  * The parent node of this type will be set when the type is used in a declaration or nested in another type.
@@ -1,8 +1,8 @@
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";
1
+ import type { GetNestedDeclarations } from "../../declarations/Declaration.ts";
2
+ import type { GetReferences, Node, Serializer } from "../../Node.ts";
3
+ import { NodeKind } from "../../Node.ts";
4
+ import type { Validator } from "../../validation/type.ts";
5
+ import type { BaseType, SerializedBaseType, SerializedType, StructureFormatter, Type } from "../Type.ts";
6
6
  export interface ArrayType<T extends Type = Type> extends BaseType {
7
7
  kind: NodeKind["ArrayType"];
8
8
  minItems?: number;
@@ -1,6 +1,7 @@
1
1
  import { parallelizeErrors } from "../../../../shared/utils/validation.js";
2
2
  import { validateArrayConstraints } from "../../../../shared/validation/array.js";
3
3
  import { wrapErrorsIfAny } from "../../../utils/error.js";
4
+ import { json, key } from "../../../utils/errorFormatting.js";
4
5
  import { getNestedDeclarations } from "../../declarations/Declaration.js";
5
6
  import { NodeKind } from "../../Node.js";
6
7
  import { validateOption } from "../../validation/options.js";
@@ -21,11 +22,11 @@ export const isArrayType = (node) => node.kind === NodeKind.ArrayType;
21
22
  export const getNestedDeclarationsInArrayType = (addedDecls, type) => getNestedDeclarations(addedDecls, type.items);
22
23
  export const validateArrayType = (helpers, type, value) => {
23
24
  if (!Array.isArray(value)) {
24
- return [TypeError(`expected an array, but got ${JSON.stringify(value)}`)];
25
+ return [TypeError(`expected an array, but got ${json(value)}`)];
25
26
  }
26
27
  return parallelizeErrors([
27
28
  ...validateArrayConstraints(type, value),
28
- ...value.map((item, index) => wrapErrorsIfAny(`at index ${index.toString()}`, validate(helpers, type.items, item))),
29
+ ...value.map((item, index) => wrapErrorsIfAny(`at index ${key(index.toString())}`, validate(helpers, type.items, item))),
29
30
  ]);
30
31
  };
31
32
  export const resolveTypeArgumentsInArrayType = (args, type) => ArrayType(resolveTypeArgumentsInType(args, type.items), {
@@ -1,8 +1,8 @@
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";
1
+ import type { GetNestedDeclarations } from "../../declarations/Declaration.ts";
2
+ import type { GetReferences, Node, Serializer } from "../../Node.ts";
3
+ import { NodeKind } from "../../Node.ts";
4
+ import type { Validator } from "../../validation/type.ts";
5
+ import type { BaseType, SerializedBaseType, SerializedType, StructureFormatter, Type } from "../Type.ts";
6
6
  export interface EnumType<T extends Record<string, EnumCaseDecl> = Record<string, EnumCaseDecl>> extends BaseType {
7
7
  kind: NodeKind["EnumType"];
8
8
  values: T;
@@ -1,4 +1,5 @@
1
1
  import { discriminatorKey } from "../../../../shared/enum.js";
2
+ import { json, key } from "../../../utils/errorFormatting.js";
2
3
  import { getNestedDeclarations } from "../../declarations/Declaration.js";
3
4
  import { NodeKind } from "../../Node.js";
4
5
  import { formatValue, getReferencesForType, removeParentKey, resolveTypeArgumentsInType, serializeType, validate, } from "../Type.js";
@@ -17,24 +18,24 @@ export const isEnumType = (node) => node.kind === NodeKind.EnumType;
17
18
  export const getNestedDeclarationsInEnumType = (addedDecls, type) => Object.values(type.values).reduce((acc, caseMember) => caseMember.type === null ? acc : getNestedDeclarations(acc, caseMember.type), addedDecls);
18
19
  export const validateEnumType = (helpers, type, value) => {
19
20
  if (typeof value !== "object" || value === null || Array.isArray(value)) {
20
- return [TypeError(`expected an object, but got ${JSON.stringify(value)}`)];
21
+ return [TypeError(`expected an object, but got ${json(value)}`)];
21
22
  }
22
23
  const actualKeys = Object.keys(value);
23
24
  if (!(discriminatorKey in value) || typeof value[discriminatorKey] !== "string") {
24
25
  return [
25
- TypeError(`missing required discriminator value at key "${discriminatorKey}" of type string`),
26
+ TypeError(`missing required discriminator value at key ${key(`"${discriminatorKey}"`)} of type string`),
26
27
  ];
27
28
  }
28
29
  const caseName = value[discriminatorKey];
29
30
  if (!(caseName in type.values)) {
30
31
  return [
31
- TypeError(`discriminator "${caseName}" is not a valid enum case, possible cases are: ${Object.keys(type.values).join(", ")}`),
32
+ TypeError(`discriminator ${key(`"${caseName}"`)} is not a valid enum case, possible cases are: ${Object.keys(type.values).join(", ")}`),
32
33
  ];
33
34
  }
34
35
  const unknownKeyErrors = actualKeys.flatMap(actualKey => actualKey === discriminatorKey || actualKey in type.values
35
36
  ? []
36
37
  : [
37
- TypeError(`key "${actualKey}" is not the discriminator key "${caseName}" or a valid enum case, possible cases are: ${Object.keys(type.values).join(", ")}`),
38
+ TypeError(`key ${key(`"${actualKey}"`)} is not the discriminator key ${key(`"${caseName}"`)} or a valid enum case, possible cases are: ${Object.keys(type.values).join(", ")}`),
38
39
  ]);
39
40
  if (unknownKeyErrors.length > 0) {
40
41
  return unknownKeyErrors;
@@ -42,7 +43,7 @@ export const validateEnumType = (helpers, type, value) => {
42
43
  const associatedType = type.values[caseName]?.type;
43
44
  if (associatedType != null) {
44
45
  if (!(caseName in value)) {
45
- return [TypeError(`missing required associated value for case "${caseName}"`)];
46
+ return [TypeError(`missing required associated value for case ${key(`"${caseName}"`)}`)];
46
47
  }
47
48
  return validate(helpers, associatedType, value[caseName]);
48
49
  }
@@ -1,9 +1,9 @@
1
- import type { ObjectConstraints } from "../../../../shared/validation/object.js";
2
- import type { GetNestedDeclarations } from "../../declarations/Declaration.js";
3
- import type { GetReferences, Node, Serializer } from "../../Node.js";
4
- import { NodeKind } from "../../Node.js";
5
- import type { Validator } from "../../validation/type.js";
6
- import type { BaseType, SerializedBaseType, SerializedType, StructureFormatter, Type } from "../Type.js";
1
+ import type { ObjectConstraints } from "../../../../shared/validation/object.ts";
2
+ import type { GetNestedDeclarations } from "../../declarations/Declaration.ts";
3
+ import type { GetReferences, Node, Serializer } from "../../Node.ts";
4
+ import { NodeKind } from "../../Node.ts";
5
+ import type { Validator } from "../../validation/type.ts";
6
+ import type { BaseType, SerializedBaseType, SerializedType, StructureFormatter, Type } from "../Type.ts";
7
7
  type TConstraint = Record<string, MemberDecl>;
8
8
  export interface ObjectType<T extends TConstraint = TConstraint> extends BaseType, ObjectConstraints {
9
9
  kind: NodeKind["ObjectType"];