tsondb 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (206) hide show
  1. package/LICENSE +385 -0
  2. package/README.md +173 -1
  3. package/lib/bin/tsondb.d.ts +10 -0
  4. package/lib/bin/tsondb.js +84 -0
  5. package/lib/index.d.ts +2 -1
  6. package/lib/index.js +1 -1
  7. package/lib/{Schema.d.ts → node/Schema.d.ts} +2 -2
  8. package/lib/{Schema.js → node/Schema.js} +6 -5
  9. package/lib/node/index.d.ts +9 -0
  10. package/lib/node/index.js +75 -0
  11. package/lib/{renderers → node/renderers}/Output.d.ts +1 -1
  12. package/lib/{renderers → node/renderers}/jsonschema/index.d.ts +2 -2
  13. package/lib/{renderers → node/renderers}/jsonschema/index.js +9 -2
  14. package/lib/{renderers → node/renderers}/jsonschema/render.d.ts +1 -1
  15. package/lib/{renderers → node/renderers}/jsonschema/render.js +15 -10
  16. package/lib/{renderers → node/renderers}/ts/index.d.ts +2 -2
  17. package/lib/{renderers → node/renderers}/ts/index.js +2 -2
  18. package/lib/{renderers → node/renderers}/ts/render.d.ts +1 -1
  19. package/lib/{renderers → node/renderers}/ts/render.js +13 -9
  20. package/lib/{schema → node/schema}/Node.d.ts +5 -5
  21. package/lib/{schema → node/schema}/Node.js +9 -8
  22. package/lib/{schema/parameters → node/schema}/TypeParameter.d.ts +3 -2
  23. package/lib/{schema/parameters → node/schema}/TypeParameter.js +2 -2
  24. package/lib/{schema → node/schema}/declarations/Declaration.d.ts +10 -11
  25. package/lib/{schema → node/schema}/declarations/Declaration.js +7 -5
  26. package/lib/{schema → node/schema}/declarations/EntityDecl.d.ts +13 -12
  27. package/lib/{schema → node/schema}/declarations/EntityDecl.js +4 -5
  28. package/lib/{schema → node/schema}/declarations/EnumDecl.d.ts +9 -7
  29. package/lib/{schema → node/schema}/declarations/EnumDecl.js +6 -13
  30. package/lib/{schema → node/schema}/declarations/TypeAliasDecl.d.ts +8 -7
  31. package/lib/{schema → node/schema}/declarations/TypeAliasDecl.js +6 -14
  32. package/lib/{schema → node/schema}/index.d.ts +4 -4
  33. package/lib/{schema → node/schema}/index.js +3 -4
  34. package/lib/node/schema/types/Type.d.ts +54 -0
  35. package/lib/{schema → node/schema}/types/Type.js +55 -29
  36. package/lib/{schema → node/schema}/types/generic/ArrayType.d.ts +5 -4
  37. package/lib/{schema → node/schema}/types/generic/ArrayType.js +5 -5
  38. package/lib/{schema → node/schema}/types/generic/EnumType.d.ts +5 -4
  39. package/lib/{schema → node/schema}/types/generic/EnumType.js +10 -4
  40. package/lib/{schema → node/schema}/types/generic/ObjectType.d.ts +8 -7
  41. package/lib/{schema → node/schema}/types/generic/ObjectType.js +14 -7
  42. package/lib/{schema → node/schema}/types/primitives/BooleanType.d.ts +4 -3
  43. package/lib/{schema → node/schema}/types/primitives/DateType.d.ts +5 -4
  44. package/lib/{schema → node/schema}/types/primitives/DateType.js +1 -1
  45. package/lib/{schema → node/schema}/types/primitives/FloatType.d.ts +5 -4
  46. package/lib/{schema → node/schema}/types/primitives/FloatType.js +1 -1
  47. package/lib/{schema → node/schema}/types/primitives/IntegerType.d.ts +5 -4
  48. package/lib/{schema → node/schema}/types/primitives/IntegerType.js +1 -1
  49. package/lib/{schema → node/schema}/types/primitives/NumericType.d.ts +2 -2
  50. package/lib/node/schema/types/primitives/PrimitiveType.d.ts +6 -0
  51. package/lib/{schema → node/schema}/types/primitives/StringType.d.ts +5 -4
  52. package/lib/{schema → node/schema}/types/primitives/StringType.js +1 -1
  53. package/lib/{schema → node/schema}/types/references/IncludeIdentifierType.d.ts +9 -8
  54. package/lib/{schema → node/schema}/types/references/IncludeIdentifierType.js +1 -1
  55. package/lib/{schema → node/schema}/types/references/NestedEntityMapType.d.ts +10 -9
  56. package/lib/{schema → node/schema}/types/references/NestedEntityMapType.js +8 -16
  57. package/lib/{schema → node/schema}/types/references/ReferenceIdentifierType.d.ts +7 -6
  58. package/lib/{schema → node/schema}/types/references/ReferenceIdentifierType.js +1 -1
  59. package/lib/node/schema/types/references/TypeArgumentType.d.ts +23 -0
  60. package/lib/node/schema/types/references/TypeArgumentType.js +19 -0
  61. package/lib/node/schema/validation/type.d.ts +4 -0
  62. package/lib/{server → node/server}/api/declarations.js +7 -3
  63. package/lib/{server → node/server}/api/git.js +14 -11
  64. package/lib/{server → node/server}/api/instanceOperations.d.ts +3 -3
  65. package/lib/{server → node/server}/api/instanceOperations.js +18 -7
  66. package/lib/{server → node/server}/api/instances.js +7 -3
  67. package/lib/node/server/index.d.ts +28 -0
  68. package/lib/{server → node/server}/index.js +23 -13
  69. package/lib/node/server/init.d.ts +5 -0
  70. package/lib/{server → node/server}/init.js +9 -8
  71. package/lib/{utils → node/utils}/error.js +4 -1
  72. package/lib/{utils → node/utils}/git.d.ts +2 -2
  73. package/lib/{utils → node/utils}/instances.d.ts +4 -3
  74. package/lib/{utils → node/utils}/instances.js +10 -6
  75. package/lib/{utils → node/utils}/references.d.ts +2 -2
  76. package/lib/{utils → node/utils}/references.js +3 -3
  77. package/lib/{utils → node/utils}/render.js +1 -1
  78. package/lib/shared/api.d.ts +9 -3
  79. package/lib/shared/utils/array.d.ts +1 -0
  80. package/lib/shared/utils/array.js +13 -9
  81. package/lib/shared/utils/displayName.d.ts +1 -1
  82. package/lib/shared/utils/displayName.js +7 -2
  83. package/lib/shared/utils/instances.d.ts +2 -2
  84. package/lib/{utils → shared/utils}/lazy.js +1 -1
  85. package/lib/shared/utils/markdown.js +6 -6
  86. package/lib/shared/utils/object.d.ts +3 -0
  87. package/lib/shared/utils/object.js +5 -1
  88. package/lib/{utils → shared/utils}/result.js +2 -2
  89. package/lib/shared/utils/string.js +7 -4
  90. package/lib/shared/utils/validation.js +3 -2
  91. package/lib/shared/validation/number.js +3 -3
  92. package/lib/shared/validation/object.js +4 -3
  93. package/lib/shared/validation/string.js +12 -7
  94. package/lib/{client → web}/api.d.ts +3 -3
  95. package/lib/{client → web}/api.js +5 -6
  96. package/lib/web/components/Git.d.ts +2 -0
  97. package/lib/{client → web}/components/Git.js +59 -15
  98. package/lib/{client → web}/components/Layout.d.ts +1 -1
  99. package/lib/{client → web}/components/Layout.js +1 -1
  100. package/lib/web/components/Select.d.ts +3 -0
  101. package/lib/web/components/Select.js +5 -0
  102. package/lib/web/components/typeInputs/ArrayTypeInput.d.ts +13 -0
  103. package/lib/{client → web}/components/typeInputs/ArrayTypeInput.js +7 -1
  104. package/lib/{client → web}/components/typeInputs/BooleanTypeInput.d.ts +2 -2
  105. package/lib/{client → web}/components/typeInputs/DateTypeInput.d.ts +2 -2
  106. package/lib/web/components/typeInputs/EnumTypeInput.d.ts +13 -0
  107. package/lib/{client → web}/components/typeInputs/EnumTypeInput.js +1 -1
  108. package/lib/{client → web}/components/typeInputs/FloatTypeInput.d.ts +2 -2
  109. package/lib/web/components/typeInputs/GenericTypeArgumentIdentifierTypeInput.d.ts +7 -0
  110. package/lib/{client → web}/components/typeInputs/GenericTypeArgumentIdentifierTypeInput.js +1 -1
  111. package/lib/web/components/typeInputs/IncludeIdentifierTypeInput.d.ts +13 -0
  112. package/lib/{client → web}/components/typeInputs/IntegerTypeInput.d.ts +2 -2
  113. package/lib/web/components/typeInputs/NestedEntityMapTypeInput.d.ts +13 -0
  114. package/lib/{client → web}/components/typeInputs/NestedEntityMapTypeInput.js +7 -2
  115. package/lib/{client → web}/components/typeInputs/ObjectTypeInput.d.ts +4 -4
  116. package/lib/{client → web}/components/typeInputs/ObjectTypeInput.js +4 -1
  117. package/lib/{client → web}/components/typeInputs/ReferenceIdentifierTypeInput.d.ts +3 -3
  118. package/lib/web/components/typeInputs/ReferenceIdentifierTypeInput.js +11 -0
  119. package/lib/{client → web}/components/typeInputs/StringTypeInput.d.ts +2 -2
  120. package/lib/web/components/typeInputs/TypeInput.d.ts +13 -0
  121. package/lib/{client → web}/components/typeInputs/TypeInput.js +3 -3
  122. package/lib/{client → web}/components/typeInputs/utils/Markdown.d.ts +1 -1
  123. package/lib/{client → web}/components/typeInputs/utils/Markdown.js +2 -2
  124. package/lib/{client → web}/components/typeInputs/utils/MismatchingTypeError.d.ts +1 -1
  125. package/lib/{client → web}/components/typeInputs/utils/ValidationErrors.d.ts +1 -1
  126. package/lib/web/hooks/useAPIResource.d.ts +1 -0
  127. package/lib/{client → web}/hooks/useAPIResource.js +2 -1
  128. package/lib/{client → web}/hooks/useEntityFromRoute.d.ts +1 -1
  129. package/lib/{client → web}/hooks/useEntityFromRoute.js +1 -1
  130. package/lib/{client → web}/hooks/useInstanceNamesByEntity.d.ts +1 -1
  131. package/lib/{client → web}/hooks/useInstanceNamesByEntity.js +8 -6
  132. package/lib/web/hooks/useMappedAPIResource.d.ts +1 -0
  133. package/lib/{client → web}/hooks/useMappedAPIResource.js +9 -9
  134. package/lib/{client → web}/hooks/useSecondaryDeclarations.d.ts +1 -1
  135. package/lib/{client → web}/hooks/useSecondaryDeclarations.js +4 -2
  136. package/lib/{client → web}/routes/CreateInstance.d.ts +1 -1
  137. package/lib/{client → web}/routes/CreateInstance.js +4 -2
  138. package/lib/web/routes/Entity.d.ts +2 -0
  139. package/lib/{client → web}/routes/Entity.js +8 -6
  140. package/lib/web/routes/Home.d.ts +2 -0
  141. package/lib/{client → web}/routes/Home.js +2 -1
  142. package/lib/{client → web}/routes/Instance.d.ts +1 -1
  143. package/lib/{client → web}/routes/Instance.js +14 -8
  144. package/lib/{client → web}/routes/NotFound.d.ts +1 -1
  145. package/lib/web/utils/typeSkeleton.d.ts +3 -0
  146. package/lib/{client → web}/utils/typeSkeleton.js +4 -1
  147. package/package.json +33 -19
  148. package/lib/ModelContainer.d.ts +0 -17
  149. package/lib/ModelContainer.js +0 -65
  150. package/lib/client/components/Git.d.ts +0 -2
  151. package/lib/client/components/Select.d.ts +0 -3
  152. package/lib/client/components/Select.js +0 -2
  153. package/lib/client/components/typeInputs/ArrayTypeInput.d.ts +0 -13
  154. package/lib/client/components/typeInputs/EnumTypeInput.d.ts +0 -13
  155. package/lib/client/components/typeInputs/GenericTypeArgumentIdentifierTypeInput.d.ts +0 -7
  156. package/lib/client/components/typeInputs/IncludeIdentifierTypeInput.d.ts +0 -13
  157. package/lib/client/components/typeInputs/NestedEntityMapTypeInput.d.ts +0 -13
  158. package/lib/client/components/typeInputs/ReferenceIdentifierTypeInput.js +0 -9
  159. package/lib/client/components/typeInputs/TypeInput.d.ts +0 -13
  160. package/lib/client/hooks/useAPIResource.d.ts +0 -1
  161. package/lib/client/hooks/useMappedAPIResource.d.ts +0 -1
  162. package/lib/client/routes/Entity.d.ts +0 -2
  163. package/lib/client/routes/Home.d.ts +0 -2
  164. package/lib/client/utils/typeSkeleton.d.ts +0 -3
  165. package/lib/schema/types/Type.d.ts +0 -48
  166. package/lib/schema/types/primitives/PrimitiveType.d.ts +0 -6
  167. package/lib/schema/types/references/GenericArgumentIdentifierType.d.ts +0 -22
  168. package/lib/schema/types/references/GenericArgumentIdentifierType.js +0 -19
  169. package/lib/schema/validation/type.d.ts +0 -4
  170. package/lib/server/index.d.ts +0 -29
  171. package/lib/server/init.d.ts +0 -5
  172. package/lib/tsconfig.tsbuildinfo +0 -1
  173. package/lib/utils/object.d.ts +0 -3
  174. package/lib/utils/object.js +0 -1
  175. /package/lib/{renderers → node/renderers}/Output.js +0 -0
  176. /package/lib/{schema → node/schema}/types/primitives/BooleanType.js +0 -0
  177. /package/lib/{schema → node/schema}/types/primitives/NumericType.js +0 -0
  178. /package/lib/{schema → node/schema}/types/primitives/PrimitiveType.js +0 -0
  179. /package/lib/{schema → node/schema}/validation/options.d.ts +0 -0
  180. /package/lib/{schema → node/schema}/validation/options.js +0 -0
  181. /package/lib/{schema → node/schema}/validation/type.js +0 -0
  182. /package/lib/{server → node/server}/api/declarations.d.ts +0 -0
  183. /package/lib/{server → node/server}/api/git.d.ts +0 -0
  184. /package/lib/{server → node/server}/api/index.d.ts +0 -0
  185. /package/lib/{server → node/server}/api/index.js +0 -0
  186. /package/lib/{server → node/server}/api/instances.d.ts +0 -0
  187. /package/lib/{utils → node/utils}/error.d.ts +0 -0
  188. /package/lib/{utils → node/utils}/git.js +0 -0
  189. /package/lib/{utils → node/utils}/path.d.ts +0 -0
  190. /package/lib/{utils → node/utils}/path.js +0 -0
  191. /package/lib/{utils → node/utils}/render.d.ts +0 -0
  192. /package/lib/{utils → shared/utils}/enum.d.ts +0 -0
  193. /package/lib/{utils → shared/utils}/enum.js +0 -0
  194. /package/lib/{utils → shared/utils}/lazy.d.ts +0 -0
  195. /package/lib/{utils → shared/utils}/result.d.ts +0 -0
  196. /package/lib/{client → web}/components/typeInputs/BooleanTypeInput.js +0 -0
  197. /package/lib/{client → web}/components/typeInputs/DateTypeInput.js +0 -0
  198. /package/lib/{client → web}/components/typeInputs/FloatTypeInput.js +0 -0
  199. /package/lib/{client → web}/components/typeInputs/IncludeIdentifierTypeInput.js +0 -0
  200. /package/lib/{client → web}/components/typeInputs/IntegerTypeInput.js +0 -0
  201. /package/lib/{client → web}/components/typeInputs/StringTypeInput.js +0 -0
  202. /package/lib/{client → web}/components/typeInputs/utils/MismatchingTypeError.js +0 -0
  203. /package/lib/{client → web}/components/typeInputs/utils/ValidationErrors.js +0 -0
  204. /package/lib/{client → web}/index.d.ts +0 -0
  205. /package/lib/{client → web}/index.js +0 -0
  206. /package/lib/{client → web}/routes/NotFound.js +0 -0
@@ -1,13 +1,14 @@
1
- import { getNestedDeclarations, getParameterNames, } from "./schema/declarations/Declaration.js";
1
+ import { getNestedDeclarations, getParameterNames } from "./schema/declarations/Declaration.js";
2
2
  import { isEntityDecl } from "./schema/declarations/EntityDecl.js";
3
3
  import { isStringType } from "./schema/types/primitives/StringType.js";
4
4
  import { isNestedEntityMapType } from "./schema/types/references/NestedEntityMapType.js";
5
5
  import { findTypeAtPath } from "./schema/types/Type.js";
6
6
  const checkDuplicateIdentifier = (existingDecls, decl) => {
7
- if (existingDecls
7
+ const existingDeclWithSameName = existingDecls
8
8
  .values()
9
- .some(otherDecl => otherDecl !== decl && otherDecl.name.toLowerCase() === decl.name.toLowerCase())) {
10
- throw new Error(`Duplicate declaration name: "${decl.name}". Make sure declaration names are globally unique.`);
9
+ .find(otherDecl => otherDecl !== decl && otherDecl.name.toLowerCase() === decl.name.toLowerCase());
10
+ if (existingDeclWithSameName) {
11
+ throw new Error(`Duplicate declaration name "${decl.name}" in "${decl.sourceUrl}" and "${existingDeclWithSameName.sourceUrl}". Make sure declaration names are globally unique.`);
11
12
  }
12
13
  };
13
14
  const checkParameterNamesShadowing = (decls) => {
@@ -21,7 +22,7 @@ const checkParameterNamesShadowing = (decls) => {
21
22
  };
22
23
  const checkEntityDisplayNamePaths = (decls, localeEntity) => {
23
24
  for (const decl of decls) {
24
- if (isEntityDecl(decl)) {
25
+ if (isEntityDecl(decl) && decl.displayName !== null) {
25
26
  const displayName = decl.displayName ?? "name";
26
27
  if (typeof displayName === "object") {
27
28
  const pathToLocaleMap = displayName.pathToLocaleMap ?? "translations";
@@ -0,0 +1,9 @@
1
+ import type { Output } from "./renderers/Output.ts";
2
+ import type { Schema } from "./Schema.ts";
3
+ import type { ServerOptions } from "./server/index.ts";
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>;
7
+ 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>;
9
+ export declare const format: (schema: Schema, dataRootPath: string) => Promise<void>;
@@ -0,0 +1,75 @@
1
+ import Debug from "debug";
2
+ import { mkdir, writeFile } from "fs/promises";
3
+ import { join } from "path";
4
+ import { parallelizeErrors } from "../shared/utils/validation.js";
5
+ import { getEntities } from "./Schema.js";
6
+ import { createValidators, validateEntityDecl } from "./schema/index.js";
7
+ import { createServer } from "./server/index.js";
8
+ import { getErrorMessageForDisplay, wrapErrorsIfAny } from "./utils/error.js";
9
+ import { formatInstance, getInstancesByEntityName } from "./utils/instances.js";
10
+ const debug = Debug("tsondb:schema");
11
+ const prepareFolders = async (dataRootPath, entities) => {
12
+ await mkdir(dataRootPath, { recursive: true });
13
+ for (const entity of entities) {
14
+ const entityDir = join(dataRootPath, entity.name);
15
+ await mkdir(entityDir, { recursive: true });
16
+ }
17
+ };
18
+ export const generateOutputs = async (schema, outputs) => {
19
+ for (const output of outputs) {
20
+ await output.run(schema);
21
+ }
22
+ };
23
+ const _validate = (dataRootPath, entities, instancesByEntityName) => {
24
+ const errors = entities.flatMap(entity => parallelizeErrors(instancesByEntityName[entity.name]?.map(instance => wrapErrorsIfAny(`in file "${join(dataRootPath, entity.name, instance.fileName)}"`, validateEntityDecl(createValidators(instancesByEntityName), entity, instance.content))) ?? []));
25
+ if (errors.length === 0) {
26
+ debug("All entities are valid");
27
+ }
28
+ else {
29
+ debug("Errors:\n");
30
+ for (const error of errors) {
31
+ debug(getErrorMessageForDisplay(error) + "\n");
32
+ }
33
+ throw new Error("Validation failed");
34
+ }
35
+ };
36
+ export const validate = async (schema, dataRootPath) => {
37
+ const entities = getEntities(schema);
38
+ await prepareFolders(dataRootPath, entities);
39
+ const instancesByEntityName = await getInstancesByEntityName(dataRootPath, entities);
40
+ _validate(dataRootPath, entities, instancesByEntityName);
41
+ };
42
+ export const generateAndValidate = async (schema, outputs, dataRootPath) => {
43
+ await generateOutputs(schema, outputs);
44
+ const entities = getEntities(schema);
45
+ await prepareFolders(dataRootPath, entities);
46
+ const instancesByEntityName = await getInstancesByEntityName(dataRootPath, entities);
47
+ _validate(dataRootPath, entities, instancesByEntityName);
48
+ };
49
+ export const serve = async (schema, dataRootPath, serverOptions) => {
50
+ const entities = getEntities(schema);
51
+ await prepareFolders(dataRootPath, entities);
52
+ const instancesByEntityName = await getInstancesByEntityName(dataRootPath, entities);
53
+ await createServer(schema, dataRootPath, instancesByEntityName, serverOptions);
54
+ };
55
+ export const generateValidateAndServe = async (schema, outputs, dataRootPath, serverOptions) => {
56
+ await generateOutputs(schema, outputs);
57
+ const entities = getEntities(schema);
58
+ await prepareFolders(dataRootPath, entities);
59
+ const instancesByEntityName = await getInstancesByEntityName(dataRootPath, entities);
60
+ _validate(dataRootPath, entities, instancesByEntityName);
61
+ await createServer(schema, dataRootPath, instancesByEntityName, serverOptions);
62
+ };
63
+ export const format = async (schema, dataRootPath) => {
64
+ const entities = getEntities(schema);
65
+ await prepareFolders(dataRootPath, entities);
66
+ const instancesByEntityName = await getInstancesByEntityName(dataRootPath, entities);
67
+ for (const entityName in instancesByEntityName) {
68
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
69
+ const entity = entities.find(entity => entity.name === entityName);
70
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
71
+ for (const instance of instancesByEntityName[entityName]) {
72
+ await writeFile(join(dataRootPath, entityName, instance.fileName), formatInstance(entity, instance.content), { encoding: "utf-8" });
73
+ }
74
+ }
75
+ };
@@ -1,4 +1,4 @@
1
- import { Schema } from "../Schema.js";
1
+ import type { Schema } from "../Schema.js";
2
2
  export interface Output {
3
3
  run: (schema: Schema) => Promise<void>;
4
4
  }
@@ -1,5 +1,5 @@
1
- import { Output } from "../Output.js";
2
- import { JsonSchemaRendererOptions } from "./render.js";
1
+ import type { Output } from "../Output.js";
2
+ import type { JsonSchemaRendererOptions } from "./render.js";
3
3
  export declare const JsonSchemaOutput: (options: {
4
4
  targetPath: string;
5
5
  rendererOptions?: Partial<JsonSchemaRendererOptions>;
@@ -1,17 +1,21 @@
1
+ import Debug from "debug";
1
2
  import { mkdir, rm, writeFile } from "node:fs/promises";
2
3
  import { basename, dirname, extname, join, relative } from "node:path";
3
4
  import { fileURLToPath } from "node:url";
5
+ import { commonPrefix } from "../../../shared/utils/string.js";
4
6
  import { groupDeclarationsBySourceUrl, resolveTypeArgumentsInDecls } from "../../schema/index.js";
5
- import { commonPrefix } from "../../shared/utils/string.js";
6
7
  import { render } from "./render.js";
8
+ const debug = Debug("tsondb:renderer:jsonschema");
7
9
  const extension = ".schema.json";
8
10
  export const JsonSchemaOutput = (options) => ({
9
11
  run: async (schema) => {
10
12
  if (options.rendererOptions?.preserveFiles === true) {
13
+ debug("emitting declarations to multiple files...");
11
14
  await rm(options.targetPath, { recursive: true, force: true });
12
15
  await mkdir(options.targetPath, { recursive: true });
13
16
  const declarationsBySourceUrl = groupDeclarationsBySourceUrl(resolveTypeArgumentsInDecls(schema.declarations));
14
17
  const sourceRootPath = fileURLToPath(commonPrefix(...Object.keys(declarationsBySourceUrl)));
18
+ debug("common source root path: %s", sourceRootPath);
15
19
  if (sourceRootPath) {
16
20
  for (const [sourceUrl, decls] of Object.entries(declarationsBySourceUrl)) {
17
21
  const sourcePath = fileURLToPath(sourceUrl);
@@ -19,17 +23,20 @@ export const JsonSchemaOutput = (options) => ({
19
23
  const newDir = join(options.targetPath, relativePath);
20
24
  const newPath = join(newDir, basename(sourcePath, extname(sourcePath)) + extension);
21
25
  await mkdir(newDir, { recursive: true });
22
- await writeFile(newPath, render(options.rendererOptions, decls), {
26
+ await writeFile(newPath, render(options.rendererOptions, decls ?? []), {
23
27
  encoding: "utf-8",
24
28
  });
25
29
  }
30
+ debug("emitted declaration files to %s", options.targetPath);
26
31
  }
27
32
  }
28
33
  else {
34
+ debug("emitting declarations to single file...");
29
35
  await mkdir(dirname(options.targetPath), { recursive: true });
30
36
  await writeFile(options.targetPath, render(options.rendererOptions, resolveTypeArgumentsInDecls(schema.declarations)), {
31
37
  encoding: "utf-8",
32
38
  });
39
+ debug("emitted declarations to %s", options.targetPath);
33
40
  }
34
41
  },
35
42
  });
@@ -1,4 +1,4 @@
1
- import { Decl } from "../../schema/declarations/Declaration.js";
1
+ import type { Decl } from "../../schema/declarations/Declaration.js";
2
2
  export type JsonSchemaRendererOptions = {
3
3
  format: "minified" | "tabs" | {
4
4
  kind: "spaces";
@@ -1,11 +1,11 @@
1
1
  import { dirname, relative } from "node:path";
2
+ import { discriminatorKey } from "../../../shared/enum.js";
3
+ import { assertExhaustive } from "../../../shared/utils/typeSafety.js";
2
4
  import { addEphemeralUUIDToType, createEntityIdentifierTypeAsDecl, isEntityDecl, } from "../../schema/declarations/EntityDecl.js";
3
5
  import { TypeAliasDecl } from "../../schema/declarations/TypeAliasDecl.js";
4
6
  import { flatMapAuxiliaryDecls, NodeKind } from "../../schema/Node.js";
5
- import { isNestedEntityMapType, } from "../../schema/types/references/NestedEntityMapType.js";
7
+ import { isNestedEntityMapType } from "../../schema/types/references/NestedEntityMapType.js";
6
8
  import { getParentDecl } from "../../schema/types/Type.js";
7
- import { discriminatorKey } from "../../shared/enum.js";
8
- import { assertExhaustive } from "../../shared/utils/typeSafety.js";
9
9
  import { ensureSpecialDirStart } from "../../utils/path.js";
10
10
  const defaultIndentation = 2;
11
11
  const defaultOptions = {
@@ -67,8 +67,8 @@ const renderStringType = (_options, type) => ({
67
67
  maxLength: type.maxLength,
68
68
  pattern: type.pattern?.source,
69
69
  });
70
- const renderGenericArgumentIdentifierType = (_options, _type) => {
71
- throw new TypeError("GenericArgumentIdentifierType is not supported in JSON Schema.");
70
+ const renderTypeArgumentType = (_options, _type) => {
71
+ throw new TypeError("TypeArgumentType is not supported in JSON Schema.");
72
72
  };
73
73
  const renderReferenceIdentifierType = (_options, type) => ({
74
74
  $ref: `#/$defs/${type.entity.name}_ID`,
@@ -98,7 +98,7 @@ const renderEnumType = (options, type) => ({
98
98
  },
99
99
  ...(caseDef.type === null ? {} : { [caseName]: renderType(options, caseDef.type) }),
100
100
  },
101
- required: [discriminatorKey, ...(caseDef === null ? [] : [caseName])],
101
+ required: [discriminatorKey, ...(caseDef.type === null ? [] : [caseName])],
102
102
  })),
103
103
  });
104
104
  const renderType = (options, type) => {
@@ -117,8 +117,8 @@ const renderType = (options, type) => {
117
117
  return renderIntegerType(options, type);
118
118
  case NodeKind.StringType:
119
119
  return renderStringType(options, type);
120
- case NodeKind.GenericArgumentIdentifierType:
121
- return renderGenericArgumentIdentifierType(options, type);
120
+ case NodeKind.TypeArgumentType:
121
+ return renderTypeArgumentType(options, type);
122
122
  case NodeKind.ReferenceIdentifierType:
123
123
  return renderReferenceIdentifierType(options, type);
124
124
  case NodeKind.IncludeIdentifierType:
@@ -162,8 +162,13 @@ const renderDeclarations = (options, declarations) => Object.fromEntries(declara
162
162
  export const render = (options = defaultOptions, declarations) => {
163
163
  const finalOptions = { ...defaultOptions, ...options };
164
164
  return JSON.stringify({
165
- $defs: renderDeclarations(finalOptions, flatMapAuxiliaryDecls(node => {
165
+ $defs: renderDeclarations(finalOptions, flatMapAuxiliaryDecls((node, existingDecls) => {
166
166
  if (isNestedEntityMapType(node)) {
167
+ if (existingDecls.some(decl => decl.name === node.name)) {
168
+ // this may happen when a nested entity map is defined in a generic declaration and the generic declaration is used multiple times
169
+ // TODO: circumvent by defining the nested entity declaration outside the generic declaration
170
+ return undefined;
171
+ }
167
172
  return TypeAliasDecl(getParentDecl(node)?.sourceUrl ?? "", {
168
173
  name: node.name,
169
174
  comment: node.comment,
@@ -179,5 +184,5 @@ export const render = (options = defaultOptions, declarations) => {
179
184
  ? undefined
180
185
  : finalOptions.format === "tabs"
181
186
  ? "\t"
182
- : finalOptions.format.indentation ?? defaultIndentation);
187
+ : (finalOptions.format.indentation ?? defaultIndentation));
183
188
  };
@@ -1,5 +1,5 @@
1
- import { Output } from "../Output.js";
2
- import { TypeScriptRendererOptions } from "./render.js";
1
+ import type { Output } from "../Output.js";
2
+ import type { TypeScriptRendererOptions } from "./render.js";
3
3
  export declare const TypeScriptOutput: (options: {
4
4
  targetPath: string;
5
5
  rendererOptions?: Partial<TypeScriptRendererOptions>;
@@ -2,8 +2,8 @@ import Debug from "debug";
2
2
  import { mkdir, rm, writeFile } from "node:fs/promises";
3
3
  import { basename, dirname, extname, join, relative } from "node:path";
4
4
  import { fileURLToPath } from "node:url";
5
+ import { commonPrefix } from "../../../shared/utils/string.js";
5
6
  import { groupDeclarationsBySourceUrl } from "../../schema/declarations/Declaration.js";
6
- import { commonPrefix } from "../../shared/utils/string.js";
7
7
  import { render } from "./render.js";
8
8
  const debug = Debug("tsondb:renderer:ts");
9
9
  const extension = ".d.ts";
@@ -23,7 +23,7 @@ export const TypeScriptOutput = (options) => ({
23
23
  const newDir = join(options.targetPath, relativePath);
24
24
  const newPath = join(newDir, basename(sourcePath, extname(sourcePath)) + extension);
25
25
  await mkdir(newDir, { recursive: true });
26
- await writeFile(newPath, render(options.rendererOptions, decls), {
26
+ await writeFile(newPath, render(options.rendererOptions, decls ?? []), {
27
27
  encoding: "utf-8",
28
28
  });
29
29
  }
@@ -1,4 +1,4 @@
1
- import { Decl } from "../../schema/declarations/Declaration.js";
1
+ import type { Decl } from "../../schema/declarations/Declaration.js";
2
2
  export type TypeScriptRendererOptions = {
3
3
  indentation: number;
4
4
  objectTypeKeyword: "interface" | "type";
@@ -1,14 +1,15 @@
1
1
  import { EOL } from "node:os";
2
2
  import { dirname, relative } from "node:path";
3
+ import { discriminatorKey } from "../../../shared/enum.js";
4
+ import { unique } from "../../../shared/utils/array.js";
5
+ import { toCamelCase } from "../../../shared/utils/string.js";
6
+ import { assertExhaustive } from "../../../shared/utils/typeSafety.js";
3
7
  import { addEphemeralUUIDToType, createEntityIdentifierTypeAsDecl, isEntityDecl, } from "../../schema/declarations/EntityDecl.js";
4
8
  import { TypeAliasDecl } from "../../schema/declarations/TypeAliasDecl.js";
5
9
  import { flatMapAuxiliaryDecls, NodeKind } from "../../schema/Node.js";
6
10
  import { isObjectType } from "../../schema/types/generic/ObjectType.js";
7
- import { isNestedEntityMapType, } from "../../schema/types/references/NestedEntityMapType.js";
11
+ import { isNestedEntityMapType } from "../../schema/types/references/NestedEntityMapType.js";
8
12
  import { getParentDecl } from "../../schema/types/Type.js";
9
- import { discriminatorKey } from "../../shared/enum.js";
10
- import { toCamelCase } from "../../shared/utils/string.js";
11
- import { assertExhaustive } from "../../shared/utils/typeSafety.js";
12
13
  import { ensureSpecialDirStart } from "../../utils/path.js";
13
14
  import { combineSyntaxes, indent, prefixLines, syntax } from "../../utils/render.js";
14
15
  const defaultOptions = {
@@ -39,7 +40,7 @@ const renderBooleanType = (_options, _type) => syntax `boolean`;
39
40
  const renderDateType = (_options, _type) => syntax `Date`;
40
41
  const renderNumericType = (_options, _type) => syntax `number`;
41
42
  const renderStringType = (_options, _type) => syntax `string`;
42
- const renderGenericArgumentIdentifierType = (_options, type) => syntax `${type.argument.name}`;
43
+ const renderTypeArgumentType = (_options, type) => syntax `${type.argument.name}`;
43
44
  const renderReferenceIdentifierType = (_options, type) => [
44
45
  { [type.entity.sourceUrl]: [type.entity.name + "_ID"] },
45
46
  type.entity.name + "_ID",
@@ -70,8 +71,8 @@ const renderType = (options, type) => {
70
71
  return renderNumericType(options, type);
71
72
  case NodeKind.StringType:
72
73
  return renderStringType(options, type);
73
- case NodeKind.GenericArgumentIdentifierType:
74
- return renderGenericArgumentIdentifierType(options, type);
74
+ case NodeKind.TypeArgumentType:
75
+ return renderTypeArgumentType(options, type);
75
76
  case NodeKind.ReferenceIdentifierType:
76
77
  return renderReferenceIdentifierType(options, type);
77
78
  case NodeKind.IncludeIdentifierType:
@@ -110,7 +111,9 @@ const renderImports = (currentUrl, imports) => {
110
111
  names,
111
112
  ])
112
113
  .toSorted(([sourceUrlA], [sourceUrlB]) => sourceUrlA.localeCompare(sourceUrlB))
113
- .map(([sourceUrl, names]) => `import { ${names.toSorted((a, b) => a.localeCompare(b)).join(", ")} } from "${sourceUrl}"`)
114
+ .map(([sourceUrl, names]) => `import { ${unique(names)
115
+ .toSorted((a, b) => a.localeCompare(b))
116
+ .join(", ")} } from "${sourceUrl}"`)
114
117
  .join(EOL);
115
118
  return importsSyntax.length > 0 ? importsSyntax + EOL + EOL : "";
116
119
  };
@@ -130,6 +133,7 @@ export const render = (options = defaultOptions, declarations) => {
130
133
  return undefined;
131
134
  }, declarations));
132
135
  return finalOptions.preserveFiles
133
- ? renderImports(declarations[0].sourceUrl, imports) + content
136
+ ? (declarations[0] === undefined ? "" : renderImports(declarations[0].sourceUrl, imports)) +
137
+ content
134
138
  : content;
135
139
  };
@@ -1,6 +1,6 @@
1
- import { InstancesByEntityName } from "../shared/utils/instances.js";
2
- import { Decl } from "./declarations/Declaration.js";
3
- import { Type } from "./types/Type.js";
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";
4
4
  export interface NodeKind {
5
5
  EntityDecl: "EntityDecl";
6
6
  EnumDecl: "EnumDecl";
@@ -14,7 +14,7 @@ export interface NodeKind {
14
14
  IntegerType: "IntegerType";
15
15
  StringType: "StringType";
16
16
  DateType: "DateType";
17
- GenericArgumentIdentifierType: "GenericArgumentIdentifierType";
17
+ TypeArgumentType: "TypeArgumentType";
18
18
  GenericParameter: "GenericParameter";
19
19
  ReferenceIdentifierType: "ReferenceIdentifierType";
20
20
  IncludeIdentifierType: "IncludeIdentifierType";
@@ -26,7 +26,7 @@ export interface BaseNode {
26
26
  kind: (typeof NodeKind)[keyof typeof NodeKind];
27
27
  }
28
28
  export type Node = Decl | Type;
29
- export declare const flatMapAuxiliaryDecls: (callbackFn: (node: Node) => (Decl | undefined)[] | Decl | undefined, declarations: readonly Decl[]) => Decl[];
29
+ export declare const flatMapAuxiliaryDecls: (callbackFn: (node: Node, existingDecls: Decl[]) => (Decl | undefined)[] | Decl | undefined, declarations: readonly Decl[]) => Decl[];
30
30
  export type IdentifierToCheck = {
31
31
  name: string;
32
32
  value: unknown;
@@ -1,5 +1,5 @@
1
- import { assertExhaustive } from "../shared/utils/typeSafety.js";
2
- import { enumOfObject } from "../utils/enum.js";
1
+ import { enumOfObject } from "../../shared/utils/enum.js";
2
+ import { assertExhaustive } from "../../shared/utils/typeSafety.js";
3
3
  export const NodeKind = enumOfObject({
4
4
  EntityDecl: null,
5
5
  EnumDecl: null,
@@ -13,7 +13,7 @@ export const NodeKind = enumOfObject({
13
13
  IntegerType: null,
14
14
  StringType: null,
15
15
  DateType: null,
16
- GenericArgumentIdentifierType: null,
16
+ TypeArgumentType: null,
17
17
  GenericParameter: null,
18
18
  ReferenceIdentifierType: null,
19
19
  IncludeIdentifierType: null,
@@ -48,7 +48,7 @@ export const flatMapAuxiliaryDecls = (callbackFn, declarations) => {
48
48
  case NodeKind.FloatType:
49
49
  case NodeKind.IntegerType:
50
50
  case NodeKind.StringType:
51
- case NodeKind.GenericArgumentIdentifierType:
51
+ case NodeKind.TypeArgumentType:
52
52
  case NodeKind.ReferenceIdentifierType:
53
53
  case NodeKind.IncludeIdentifierType:
54
54
  case NodeKind.NestedEntityMapType:
@@ -62,11 +62,12 @@ export const flatMapAuxiliaryDecls = (callbackFn, declarations) => {
62
62
  }
63
63
  };
64
64
  const reducer = (node, decls) => {
65
- const result = callbackFn(node);
65
+ const result = callbackFn(node, decls);
66
66
  const normalizedResult = (Array.isArray(result) ? result : [result]).filter(decl => decl !== undefined);
67
67
  normalizedResult.forEach(decl => {
68
- if (decls.some(existingDecl => existingDecl.name === decl.name)) {
69
- throw new Error(`Duplicate declaration name: "${decl.name}". Make sure declaration names are globally unique.`);
68
+ const existingDeclWithSameName = decls.find(existingDecl => existingDecl !== decl && existingDecl.name === decl.name);
69
+ if (existingDeclWithSameName) {
70
+ throw new Error(`Duplicate declaration name: "${decl.name}" in "${decl.sourceUrl}" and "${existingDeclWithSameName.sourceUrl}". Make sure declaration names are globally unique.`);
70
71
  }
71
72
  });
72
73
  return decls.concat(normalizedResult);
@@ -74,7 +75,7 @@ export const flatMapAuxiliaryDecls = (callbackFn, declarations) => {
74
75
  return declarations.reduce((decls, node) => mapNodeTree(reducer, node, [...decls, node]), []);
75
76
  };
76
77
  export const createValidators = (instancesByEntityName) => ({
77
- checkReferentialIntegrity: ({ name, value }) => instancesByEntityName[name].some(instance => typeof instance.content === "object" &&
78
+ checkReferentialIntegrity: ({ name, value }) => instancesByEntityName[name]?.some(instance => typeof instance.content === "object" &&
78
79
  instance.content !== null &&
79
80
  !Array.isArray(instance.content) &&
80
81
  instance.id === value)
@@ -1,5 +1,6 @@
1
- import { NodeKind, Serializer } from "../Node.js";
2
- import { SerializedBaseType, SerializedType, Type } from "../types/Type.js";
1
+ import type { Serializer } from "./Node.js";
2
+ import { NodeKind } from "./Node.js";
3
+ import type { SerializedBaseType, SerializedType, Type } from "./types/Type.js";
3
4
  export interface TypeParameter<N extends string = string, T extends Type = Type> {
4
5
  kind: NodeKind["GenericParameter"];
5
6
  name: N;
@@ -1,5 +1,5 @@
1
- import { NodeKind } from "../Node.js";
2
- import { removeParentKey, serializeType, } from "../types/Type.js";
1
+ import { NodeKind } from "./Node.js";
2
+ import { removeParentKey, serializeType } from "./types/Type.js";
3
3
  export const Param = (name, constraint) => ({
4
4
  kind: NodeKind.GenericParameter,
5
5
  name,
@@ -1,12 +1,11 @@
1
- import { BaseNode, GetReferences, Node, Serializer } from "../Node.js";
2
- import { SerializedTypeParameter, TypeParameter } from "../parameters/TypeParameter.js";
3
- import { EnumCaseDecl, SerializedEnumCaseDecl } from "../types/generic/EnumType.js";
4
- import { ObjectType, SerializedObjectType } from "../types/generic/ObjectType.js";
5
- import { SerializedType, Type } from "../types/Type.js";
6
- import { ValidatorHelpers } from "../validation/type.js";
7
- import { EntityDecl, SerializedEntityDecl } from "./EntityDecl.js";
8
- import { EnumDecl, SerializedEnumDecl } from "./EnumDecl.js";
9
- import { SerializedTypeAliasDecl, TypeAliasDecl } from "./TypeAliasDecl.js";
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 } 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";
10
9
  export type TypeArguments<Params extends TypeParameter[]> = {
11
10
  [K in keyof Params]: Params[K] extends TypeParameter<string, infer T> ? T : Type;
12
11
  };
@@ -17,8 +16,8 @@ export declare const getParameterNames: (decl: Decl) => string[];
17
16
  export declare const getTypeArgumentsRecord: <Params extends TypeParameter[]>(decl: DeclP<Params>, args: TypeArguments<Params>) => Record<string, Type>;
18
17
  export type Decl = EntityDecl | EnumDecl | TypeAliasDecl;
19
18
  export type SerializedDecl = SerializedEntityDecl | SerializedEnumDecl | SerializedTypeAliasDecl;
20
- export type DeclP<Params extends TypeParameter[] = TypeParameter[]> = EntityDecl<string, ObjectType> | EnumDecl<string, Record<string, EnumCaseDecl>, Params> | TypeAliasDecl<string, Type, Params>;
21
- export type SerializedDeclP<Params extends SerializedTypeParameter[] = SerializedTypeParameter[]> = SerializedEntityDecl<string, SerializedObjectType> | SerializedEnumDecl<string, Record<string, SerializedEnumCaseDecl>, Params> | SerializedTypeAliasDecl<string, SerializedType, Params>;
19
+ export type DeclP<Params extends TypeParameter[] = TypeParameter[]> = EntityDecl | EnumDecl<string, Record<string, EnumCaseDecl>, Params> | TypeAliasDecl<string, Type, Params>;
20
+ export type SerializedDeclP<Params extends SerializedTypeParameter[] = SerializedTypeParameter[]> = SerializedEntityDecl | SerializedEnumDecl<string, Record<string, SerializedEnumCaseDecl>, Params> | SerializedTypeAliasDecl<string, SerializedType, Params>;
22
21
  export type SecondaryDecl = EnumDecl | TypeAliasDecl;
23
22
  export type SerializedSecondaryDecl = SerializedEnumDecl | SerializedTypeAliasDecl;
24
23
  export declare const getNestedDeclarations: GetNestedDeclarations;
@@ -1,8 +1,8 @@
1
- import { assertExhaustive } from "../../shared/utils/typeSafety.js";
1
+ import { assertExhaustive } from "../../../shared/utils/typeSafety.js";
2
2
  import { NodeKind } from "../Node.js";
3
3
  import { getNestedDeclarationsInArrayType } from "../types/generic/ArrayType.js";
4
- import { getNestedDeclarationsInEnumType, } from "../types/generic/EnumType.js";
5
- import { getNestedDeclarationsInObjectType, } from "../types/generic/ObjectType.js";
4
+ import { getNestedDeclarationsInEnumType } from "../types/generic/EnumType.js";
5
+ import { getNestedDeclarationsInObjectType } from "../types/generic/ObjectType.js";
6
6
  import { getNestedDeclarationsInIncludeIdentifierType } from "../types/references/IncludeIdentifierType.js";
7
7
  import { getNestedDeclarationsInNestedEntityMapType } from "../types/references/NestedEntityMapType.js";
8
8
  import { getNestedDeclarationsInReferenceIdentifierType } from "../types/references/ReferenceIdentifierType.js";
@@ -10,7 +10,9 @@ import { getNestedDeclarationsInEntityDecl, getReferencesForEntityDecl, isEntity
10
10
  import { getNestedDeclarationsInEnumDecl, getReferencesForEnumDecl, isEnumDecl, resolveTypeArgumentsInEnumDecl, serializeEnumDecl, validateEnumDecl, } from "./EnumDecl.js";
11
11
  import { getNestedDeclarationsInTypeAliasDecl, getReferencesForTypeAliasDecl, isTypeAliasDecl, resolveTypeArgumentsInTypeAliasDecl, serializeTypeAliasDecl, validateTypeAliasDecl, } from "./TypeAliasDecl.js";
12
12
  export const getParameterNames = (decl) => decl.parameters.map(param => param.name);
13
- export const getTypeArgumentsRecord = (decl, args) => Object.fromEntries(args.map((arg, i) => [decl.parameters[i].name, arg]));
13
+ export const getTypeArgumentsRecord = (decl, args) => Object.fromEntries(
14
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
15
+ args.slice(0, decl.parameters.length).map((arg, i) => [decl.parameters[i].name, arg]));
14
16
  export const getNestedDeclarations = (addedDecls, node) => {
15
17
  switch (node.kind) {
16
18
  case NodeKind.EntityDecl:
@@ -28,7 +30,7 @@ export const getNestedDeclarations = (addedDecls, node) => {
28
30
  case NodeKind.FloatType:
29
31
  case NodeKind.IntegerType:
30
32
  case NodeKind.StringType:
31
- case NodeKind.GenericArgumentIdentifierType:
33
+ case NodeKind.TypeArgumentType:
32
34
  return addedDecls;
33
35
  case NodeKind.ReferenceIdentifierType:
34
36
  return getNestedDeclarationsInReferenceIdentifierType(addedDecls, node);
@@ -1,11 +1,12 @@
1
- import { Lazy } from "../../utils/lazy.js";
2
- import { Leaves } from "../../utils/object.js";
3
- import { GetReferences, Node, NodeKind, Serializer } from "../Node.js";
4
- import { MemberDecl, ObjectType, SerializedObjectType } from "../types/generic/ObjectType.js";
1
+ import { Lazy } from "../../../shared/utils/lazy.js";
2
+ import type { Leaves } from "../../../shared/utils/object.js";
3
+ import type { GetReferences, Node, Serializer } from "../Node.js";
4
+ import { NodeKind } from "../Node.js";
5
+ import type { MemberDecl, ObjectType, SerializedObjectType } from "../types/generic/ObjectType.js";
5
6
  import { StringType } from "../types/primitives/StringType.js";
6
- import { AsType, SerializedAsType, Type } from "../types/Type.js";
7
- import { ValidatorHelpers } from "../validation/type.js";
8
- import { BaseDecl, GetNestedDeclarations, SerializedBaseDecl } from "./Declaration.js";
7
+ import type { AsType, SerializedAsType } from "../types/Type.js";
8
+ import type { ValidatorHelpers } from "../validation/type.js";
9
+ import type { BaseDecl, GetNestedDeclarations, SerializedBaseDecl } from "./Declaration.js";
9
10
  import { TypeAliasDecl } from "./TypeAliasDecl.js";
10
11
  export interface EntityDecl<Name extends string = string, T extends ObjectType = ObjectType> extends BaseDecl<Name, []> {
11
12
  kind: NodeKind["EntityDecl"];
@@ -23,7 +24,7 @@ export interface EntityDecl<Name extends string = string, T extends ObjectType =
23
24
  * @default "name"
24
25
  */
25
26
  pathInLocaleMap?: string;
26
- };
27
+ } | null;
27
28
  isDeprecated?: boolean;
28
29
  }
29
30
  export interface SerializedEntityDecl<Name extends string = string, T extends SerializedObjectType = SerializedObjectType> extends SerializedBaseDecl<Name, []> {
@@ -42,7 +43,7 @@ export interface SerializedEntityDecl<Name extends string = string, T extends Se
42
43
  * @default "name"
43
44
  */
44
45
  pathInLocaleMap?: string;
45
- };
46
+ } | null;
46
47
  isDeprecated?: boolean;
47
48
  }
48
49
  export declare const EntityDecl: <Name extends string, T extends ObjectType>(sourceUrl: string, options: {
@@ -62,7 +63,7 @@ export declare const EntityDecl: <Name extends string, T extends ObjectType>(sou
62
63
  * @default "name"
63
64
  */
64
65
  pathInLocaleMap?: string;
65
- };
66
+ } | null;
66
67
  isDeprecated?: boolean;
67
68
  }) => EntityDecl<Name, T>;
68
69
  export { EntityDecl as Entity };
@@ -70,10 +71,10 @@ export declare const isEntityDecl: (node: Node) => node is EntityDecl;
70
71
  export declare const getNestedDeclarationsInEntityDecl: GetNestedDeclarations<EntityDecl>;
71
72
  export declare const validateEntityDecl: (helpers: ValidatorHelpers, decl: EntityDecl, value: unknown) => Error[];
72
73
  export declare const resolveTypeArgumentsInEntityDecl: (decl: EntityDecl) => EntityDecl;
73
- export declare const addEphemeralUUIDToType: <T extends Record<string, MemberDecl<Type, boolean>>>(decl: EntityDecl<string, ObjectType<T>>) => ObjectType<Omit<T, "id"> & {
74
+ export declare const addEphemeralUUIDToType: <T extends Record<string, MemberDecl>>(decl: EntityDecl<string, ObjectType<T>>) => ObjectType<Omit<T, "id"> & {
74
75
  id: MemberDecl<StringType, true>;
75
76
  }>;
76
77
  export declare const createEntityIdentifierType: () => StringType;
77
- export declare const createEntityIdentifierTypeAsDecl: <Name extends string>(decl: EntityDecl<Name, ObjectType>) => TypeAliasDecl<`${Name}_ID`, StringType, []>;
78
+ export declare const createEntityIdentifierTypeAsDecl: <Name extends string>(decl: EntityDecl<Name>) => TypeAliasDecl<`${Name}_ID`, StringType, []>;
78
79
  export declare const serializeEntityDecl: Serializer<EntityDecl, SerializedEntityDecl>;
79
80
  export declare const getReferencesForEntityDecl: GetReferences<EntityDecl>;
@@ -1,9 +1,9 @@
1
- import { Lazy } from "../../utils/lazy.js";
1
+ import { Lazy } from "../../../shared/utils/lazy.js";
2
2
  import { NodeKind } from "../Node.js";
3
3
  import { getNestedDeclarationsInObjectType, getReferencesForObjectType, Required, resolveTypeArgumentsInObjectType, serializeObjectType, } from "../types/generic/ObjectType.js";
4
4
  import { StringType } from "../types/primitives/StringType.js";
5
- import { validate } from "../types/Type.js";
6
- import { validateDeclName, } from "./Declaration.js";
5
+ import { setParent, validate } from "../types/Type.js";
6
+ import { validateDeclName } from "./Declaration.js";
7
7
  import { TypeAliasDecl } from "./TypeAliasDecl.js";
8
8
  export const EntityDecl = (sourceUrl, options) => {
9
9
  validateDeclName(options.name);
@@ -19,8 +19,7 @@ export const EntityDecl = (sourceUrl, options) => {
19
19
  throw new TypeError(`Invalid object key "${key}" for entity "${options.name}". The key "id" is reserved for the entity identifier.`);
20
20
  }
21
21
  });
22
- type.parent = decl;
23
- return type;
22
+ return setParent(type, decl);
24
23
  }),
25
24
  };
26
25
  return decl;
@@ -1,10 +1,12 @@
1
- import { Lazy } from "../../utils/lazy.js";
2
- import { GetReferences, Node, NodeKind, Serializer } from "../Node.js";
3
- import { SerializedTypeParameter, TypeParameter } from "../parameters/TypeParameter.js";
4
- import { EnumCaseDecl, EnumType, SerializedEnumCaseDecl, SerializedEnumType } from "../types/generic/EnumType.js";
5
- import { Type } from "../types/Type.js";
6
- import { ValidatorHelpers } from "../validation/type.js";
7
- import { BaseDecl, GetNestedDeclarations, SerializedBaseDecl, TypeArguments } from "./Declaration.js";
1
+ import { Lazy } from "../../../shared/utils/lazy.js";
2
+ import type { GetReferences, Node, Serializer } from "../Node.js";
3
+ import { NodeKind } from "../Node.js";
4
+ import type { SerializedTypeParameter, TypeParameter } from "../TypeParameter.js";
5
+ import type { EnumCaseDecl, SerializedEnumCaseDecl, SerializedEnumType } from "../types/generic/EnumType.js";
6
+ import { EnumType } from "../types/generic/EnumType.js";
7
+ import { type Type } from "../types/Type.js";
8
+ import type { ValidatorHelpers } from "../validation/type.js";
9
+ import type { BaseDecl, GetNestedDeclarations, SerializedBaseDecl, TypeArguments } from "./Declaration.js";
8
10
  export interface EnumDecl<Name extends string = string, T extends Record<string, EnumCaseDecl> = Record<string, EnumCaseDecl>, Params extends TypeParameter[] = TypeParameter[]> extends BaseDecl<Name, Params> {
9
11
  kind: NodeKind["EnumDecl"];
10
12
  type: Lazy<EnumType<T>>;