@tsofist/schema-forge 3.7.1 → 4.1.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 (47) hide show
  1. package/lib/dbml-generator/generator.spec.js +13 -2
  2. package/lib/dbml-generator/types.d.ts +7 -1
  3. package/lib/dbml-generator/types.d.ts.map +1 -1
  4. package/lib/definition-info/guards.d.ts +7 -1
  5. package/lib/definition-info/guards.d.ts.map +1 -1
  6. package/lib/definition-info/guards.js +20 -0
  7. package/lib/definition-info/parser.d.ts +1 -1
  8. package/lib/definition-info/parser.d.ts.map +1 -1
  9. package/lib/definition-info/parser.js +10 -10
  10. package/lib/fake-generator/generator-host.d.ts.map +1 -1
  11. package/lib/fake-generator/generator-host.js +2 -1
  12. package/lib/schema-dereference/dereference.d.ts.map +1 -1
  13. package/lib/schema-dereference/dereference.js +7 -2
  14. package/lib/schema-dereference/types.d.ts +13 -0
  15. package/lib/schema-dereference/types.d.ts.map +1 -1
  16. package/lib/schema-generator/forge.spec.js +45 -5
  17. package/lib/schema-generator/generate-drafts.d.ts.map +1 -1
  18. package/lib/schema-generator/generate-drafts.js +1 -0
  19. package/lib/schema-generator/generate-schema.d.ts +1 -1
  20. package/lib/schema-generator/generate-schema.d.ts.map +1 -1
  21. package/lib/schema-generator/generate-schema.js +80 -5
  22. package/lib/schema-generator/helpers-tsc.d.ts +2 -0
  23. package/lib/schema-generator/helpers-tsc.d.ts.map +1 -1
  24. package/lib/schema-generator/helpers-tsc.js +18 -1
  25. package/lib/schema-generator/patch-enum-node-parser.d.ts +12 -0
  26. package/lib/schema-generator/patch-enum-node-parser.d.ts.map +1 -0
  27. package/lib/schema-generator/patch-enum-node-parser.js +54 -0
  28. package/lib/schema-generator/shrink-definition-name.d.ts +2 -2
  29. package/lib/schema-generator/shrink-definition-name.d.ts.map +1 -1
  30. package/lib/schema-generator/shrink-definition-name.js +2 -2
  31. package/lib/schema-generator/types.d.ts +8 -7
  32. package/lib/schema-generator/types.d.ts.map +1 -1
  33. package/lib/schema-generator/types.js +31 -21
  34. package/lib/schema-registry/kw-api.d.ts.map +1 -1
  35. package/lib/schema-registry/kw-api.js +4 -4
  36. package/lib/schema-registry/kw-common.d.ts.map +1 -1
  37. package/lib/schema-registry/kw-common.js +44 -0
  38. package/lib/schema-registry/kw-dbml.d.ts +1 -1
  39. package/lib/schema-registry/kw-dbml.d.ts.map +1 -1
  40. package/lib/schema-registry/kw-dbml.js +6 -2
  41. package/lib/schema-registry/registry.d.ts.map +1 -1
  42. package/lib/schema-registry/registry.js +5 -2
  43. package/lib/schema-registry/types.d.ts +3 -3
  44. package/lib/schema-registry/types.d.ts.map +1 -1
  45. package/lib/types.d.ts +33 -15
  46. package/lib/types.d.ts.map +1 -1
  47. package/package.json +4 -4
@@ -16,7 +16,7 @@ describe('DBML Generator', () => {
16
16
  let registry;
17
17
  beforeAll(async () => {
18
18
  forgeSchemaResult = await (0, forge_1.forgeSchema)({
19
- allowUseFallbackDescription: false,
19
+ allowUseFallbackDescription: true,
20
20
  explicitPublic: true,
21
21
  schemaId,
22
22
  tsconfigFrom: './tsconfig.build-test.json',
@@ -39,7 +39,18 @@ describe('DBML Generator', () => {
39
39
  expect(forgeSchemaResult).toBeTruthy();
40
40
  expect(forgeSchemaResult.schema.$id).toStrictEqual(schemaId);
41
41
  expect(forgeSchemaResult.generatedTemporaryFiles.length).toStrictEqual(1);
42
- expect(forgeSchemaResult.refs.length).toStrictEqual(13);
42
+ expect(forgeSchemaResult.refs.length).toStrictEqual(18);
43
+ });
44
+ describe('enums', () => {
45
+ it('should generate dbEnum definitions', () => {
46
+ const definitions = registry.listDefinitions((_info, keywords) => {
47
+ return keywords.has('dbEnum');
48
+ });
49
+ const list = definitions.map((def) => {
50
+ return registry.getSchema(def.ref);
51
+ });
52
+ expect(list).toMatchSnapshot();
53
+ });
43
54
  });
44
55
  it('basic cases', () => {
45
56
  const definitions = registry.listDefinitions((info, keywords) => {
@@ -1,4 +1,4 @@
1
- import type { ArrayMay, HexString } from '@tsofist/stem';
1
+ import type { ArrayMay, HexString, PRec } from '@tsofist/stem';
2
2
  import type { SchemaDefinitionInfoForType } from '../definition-info/types';
3
3
  /**
4
4
  * DBML Project Source
@@ -144,4 +144,10 @@ export type DBMLColumnOptions = {
144
144
  */
145
145
  type?: DBMLColumnType;
146
146
  };
147
+ export type DBMLEnumOptionsDef = boolean | string;
148
+ export type DBMLEnumAnnotationOptions = PRec<[
149
+ /** 0 */ value: string | number,
150
+ /** 1 */ note?: string,
151
+ /** 2 */ comment?: string
152
+ ]>;
147
153
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/dbml-generator/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AAE5E;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,2BAA2B,EAAE,CAAC;IAC3C,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACjC,IAAI,CAAC,EAAE,eAAe,CAAC;IAIvB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;CAc3B;AAED;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,6DAQpB,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,kBAAkB,+ZAkCrB,CAAC;AAEX;;GAEG;AACH,MAAM,MA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AElD,MAAM,MAAM,yBAAyB,GAAG,IAAI,CACxC;IAEI,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAC/B,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM;IACtB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM;CAC5B,CACJ,CAAC"}
@@ -1,6 +1,12 @@
1
- import { APIInterfaceSDS, APIMemberSDS, APIMethodArgsSDS, APIMethodResultSDS } from './types';
1
+ import type { ForgedSchemaDefinitionShortName } from '../types';
2
+ import { APIInterfaceSDS, APIMemberSDS, APIMethodArgsSDS, APIMethodResultSDS, SchemaDefinitionInfo, SchemaDefinitionInfoForAPIInterface, SchemaDefinitionInfoForAPIMethodArguments, SchemaDefinitionInfoForAPIMethodResult, SchemaDefinitionInfoForType } from './types';
2
3
  export declare function isAPIDefinitionName(definitionName: string): definitionName is APIInterfaceSDS;
3
4
  export declare function isAPIMemberDefinitionName(definitionName: string): definitionName is APIMemberSDS;
4
5
  export declare function isAPIMethodArgsDefinitionName(definitionName: string): definitionName is APIMethodArgsSDS;
5
6
  export declare function isAPIMethodResultDefinitionName(definitionName: string): definitionName is APIMethodResultSDS;
7
+ export declare function isSchemaDefinitionForType(value: SchemaDefinitionInfo): value is SchemaDefinitionInfoForType;
8
+ export declare function isSchemaDefinitionForAPIInterface(value: SchemaDefinitionInfo): value is SchemaDefinitionInfoForAPIInterface;
9
+ export declare function isSchemaDefinitionForAPIMethodArguments(value: SchemaDefinitionInfo): value is SchemaDefinitionInfoForAPIMethodArguments;
10
+ export declare function isSchemaDefinitionForAPIMethodResult(value: SchemaDefinitionInfo): value is SchemaDefinitionInfoForAPIMethodResult;
11
+ export declare function isSchemaDefinitionShortName(name: string): name is ForgedSchemaDefinitionShortName;
6
12
  //# sourceMappingURL=guards.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"guards.d.ts","sourceRoot":"","sources":["../../src/definition-info/guards.ts"],"names":[],"mappings":"AAAA,OAAO,EAIH,eAAe,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yC,CAEpD;AAED,wBAAgB,oCAAoC,CAChD,KAAK,EAAE,oBAAoB,GAC5B,KAAK,IAAI,sCAAsC,CAEjD;AAED,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,+BAA+B,CAEjG"}
@@ -4,6 +4,11 @@ exports.isAPIDefinitionName = isAPIDefinitionName;
4
4
  exports.isAPIMemberDefinitionName = isAPIMemberDefinitionName;
5
5
  exports.isAPIMethodArgsDefinitionName = isAPIMethodArgsDefinitionName;
6
6
  exports.isAPIMethodResultDefinitionName = isAPIMethodResultDefinitionName;
7
+ exports.isSchemaDefinitionForType = isSchemaDefinitionForType;
8
+ exports.isSchemaDefinitionForAPIInterface = isSchemaDefinitionForAPIInterface;
9
+ exports.isSchemaDefinitionForAPIMethodArguments = isSchemaDefinitionForAPIMethodArguments;
10
+ exports.isSchemaDefinitionForAPIMethodResult = isSchemaDefinitionForAPIMethodResult;
11
+ exports.isSchemaDefinitionShortName = isSchemaDefinitionShortName;
7
12
  const types_1 = require("./types");
8
13
  function isAPIDefinitionName(definitionName) {
9
14
  return definitionName.endsWith(types_1.SDS_SUFFIX_API) || definitionName.endsWith(types_1._SDS_SUFFIX_API);
@@ -19,3 +24,18 @@ function isAPIMethodResultDefinitionName(definitionName) {
19
24
  return (definitionName.endsWith(types_1.SDS_SUFFIX_METHOD_RES) ||
20
25
  definitionName.endsWith(types_1._SDS_SUFFIX_METHOD_RES));
21
26
  }
27
+ function isSchemaDefinitionForType(value) {
28
+ return value.kind === types_1.SchemaDefinitionInfoKind.Type;
29
+ }
30
+ function isSchemaDefinitionForAPIInterface(value) {
31
+ return value.kind === types_1.SchemaDefinitionInfoKind.API;
32
+ }
33
+ function isSchemaDefinitionForAPIMethodArguments(value) {
34
+ return value.kind === types_1.SchemaDefinitionInfoKind.APIMethodArguments;
35
+ }
36
+ function isSchemaDefinitionForAPIMethodResult(value) {
37
+ return value.kind === types_1.SchemaDefinitionInfoKind.APIMethodResult;
38
+ }
39
+ function isSchemaDefinitionShortName(name) {
40
+ return name.startsWith('DSN') && name.includes('_H');
41
+ }
@@ -1,3 +1,3 @@
1
1
  import { type SchemaDefinitionInfo } from './types';
2
- export declare function parseSchemaDefinitionInfo(definitionName: string, schemaId: string, legacy?: boolean): SchemaDefinitionInfo;
2
+ export declare function parseSchemaDefinitionInfo<T extends SchemaDefinitionInfo>(definitionName: string, schemaId: string, legacy?: boolean): T;
3
3
  //# sourceMappingURL=parser.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/definition-info/parser.ts"],"names":[],"mappings":"AAOA,OAAO,EAEH,KAAK,oBAAoB,EAG5B,MAAM,SAAS,CAAC;AAEjB,wBAAgB,yBAAyB,CACrC,cAAc,EAAE,MAAM,EACtB,QAAQ,EAAE,MAAM,EAChB,MAAM,UAAQ,GACf,oBAAoB,CAsCtB"}
1
+ {"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/definition-info/parser.ts"],"names":[],"mappings":"AAOA,OAAO,EAEH,KAAK,oBAAoB,EAG5B,MAAM,SAAS,CAAC;AAEjB,wBAAgB,yBAAyB,CAAC,CAAC,SAAS,oBAAoB,EACpE,cAAc,EAAE,MAAM,EACtB,QAAQ,EAAE,MAAM,EAChB,MAAM,CAAC,EAAE,OAAO,GACjB,CAAC,CAAC"}
@@ -15,31 +15,31 @@ function parseSchemaDefinitionInfo(definitionName, schemaId, legacy = false) {
15
15
  : types_1.SchemaDefinitionInfoKind.Type;
16
16
  const ref = (0, ref_1.buildSchemaDefinitionRef)(definitionName, schemaId);
17
17
  switch (kind) {
18
- case types_1.SchemaDefinitionInfoKind.API:
18
+ case types_1.SchemaDefinitionInfoKind.Type:
19
19
  return {
20
20
  ref,
21
- kind,
22
- name: definitionName,
23
21
  schemaId,
24
- interface: (0, substr_1.substr)(definitionName, 0, legacy ? types_1._SDS_SUFFIX_API : types_1.SDS_SUFFIX_API),
22
+ name: definitionName,
23
+ kind,
24
+ type: definitionName,
25
25
  };
26
26
  case types_1.SchemaDefinitionInfoKind.APIMethodArguments:
27
27
  case types_1.SchemaDefinitionInfoKind.APIMethodResult:
28
28
  return {
29
29
  ref,
30
- kind,
31
- name: definitionName,
32
30
  schemaId,
31
+ name: definitionName,
32
+ kind,
33
33
  interface: (0, substr_1.substr)(definitionName, 0, '_'),
34
34
  method: (0, substr_1.substr)(definitionName, '_', '_'),
35
35
  };
36
- case types_1.SchemaDefinitionInfoKind.Type:
36
+ case types_1.SchemaDefinitionInfoKind.API:
37
37
  return {
38
38
  ref,
39
- kind,
40
- name: definitionName,
41
39
  schemaId,
42
- type: definitionName,
40
+ name: definitionName,
41
+ kind,
42
+ interface: (0, substr_1.substr)(definitionName, 0, legacy ? types_1._SDS_SUFFIX_API : types_1.SDS_SUFFIX_API),
43
43
  };
44
44
  }
45
45
  }
@@ -1 +1 @@
1
- {"version":3,"file":"generator-host.d.ts","sourceRoot":"","sources":["../../src/fake-generator/generator-host.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAEpE,OAAO,KAAK,EAAE,iBAAiB,EAA2B,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAEhG,wBAAgB,uBAAuB,CACnC,MAAM,EAAE,mBAAmB,EAC3B,OAAO,GAAE,oBAAyB,GACnC,iBAAiB,CA4CnB"}
1
+ {"version":3,"file":"generator-host.d.ts","sourceRoot":"","sources":["../../src/fake-generator/generator-host.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAEpE,OAAO,KAAK,EAAE,iBAAiB,EAA2B,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAEhG,wBAAgB,uBAAuB,CACnC,MAAM,EAAE,mBAAmB,EAC3B,OAAO,GAAE,oBAAyB,GACnC,iBAAiB,CA4CnB"}
@@ -4,6 +4,7 @@ exports.createFakeGeneratorHost = createFakeGeneratorHost;
4
4
  const fakerModule = require("@faker-js/faker");
5
5
  const as_array_1 = require("@tsofist/stem/lib/as-array");
6
6
  const json_schema_faker_1 = require("json-schema-faker");
7
+ const types_1 = require("../schema-generator/types");
7
8
  const modules_1 = require("./modules");
8
9
  function createFakeGeneratorHost(source, options = {}) {
9
10
  const rebuild = () => {
@@ -28,7 +29,7 @@ function createFakeGeneratorHost(source, options = {}) {
28
29
  generator.option({
29
30
  alwaysFakeOptionals: true,
30
31
  refDepthMax: 1_000,
31
- pruneProperties: ['dbEntity', 'dbIndex', 'dbColumn', 'dbFK'],
32
+ pruneProperties: types_1.SFG_EXTRA_TAGS.filter((name) => name.startsWith('db')),
32
33
  ...options,
33
34
  resolveJsonPath: false,
34
35
  });
@@ -1 +1 @@
1
- {"version":3,"file":"dereference.d.ts","sourceRoot":"","sources":["../../src/schema-dereference/dereference.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,SAAS,CAAC;AAE7D;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC7B,MAAM,EAAE,WAAW,EACnB,OAAO,CAAC,EAAE,6BAA6B,GACxC,WAAW,GAAG,SAAS,CAAC"}
1
+ {"version":3,"file":"dereference.d.ts","sourceRoot":"","sources":["../../src/schema-dereference/dereference.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG/C,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,SAAS,CAAC;AAE7D;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC7B,MAAM,EAAE,WAAW,EACnB,OAAO,CAAC,EAAE,6BAA6B,GACxC,WAAW,GAAG,SAAS,CAAC"}
@@ -10,7 +10,8 @@ function dereferenceSchema(raw, options = {}) {
10
10
  return cache.main.get(raw);
11
11
  const schema = structuredClone(raw);
12
12
  const seen = new WeakMap();
13
- const { throwOnDereferenceFailure = true, onDereferenceFailure } = options;
13
+ const seenRefs = new Set();
14
+ const { throwOnDereferenceFailure = true, onDereferenceFailure, onDereferenceSuccess, definitionsSource = schema, } = options;
14
15
  function resolve(current, path) {
15
16
  if (current == undefined || typeof current !== 'object')
16
17
  return current;
@@ -25,7 +26,7 @@ function dereferenceSchema(raw, options = {}) {
25
26
  }
26
27
  // $ref
27
28
  if ('$ref' in current && typeof current.$ref === 'string') {
28
- const resolvedSchema = resolveRef(cache, schema, current.$ref);
29
+ const resolvedSchema = resolveRef(cache, definitionsSource, current.$ref);
29
30
  if (resolvedSchema == null) {
30
31
  const replacement = onDereferenceFailure && !throwOnDereferenceFailure
31
32
  ? onDereferenceFailure(current.$ref, current, schema)
@@ -57,6 +58,10 @@ function dereferenceSchema(raw, options = {}) {
57
58
  delete result.$ref; // !
58
59
  Object.assign(placeholder, result);
59
60
  seen.set(resolvedSchema, result);
61
+ if (onDereferenceSuccess != null && !seenRefs.has($ref)) {
62
+ seenRefs.add($ref);
63
+ onDereferenceSuccess($ref, result);
64
+ }
60
65
  return result;
61
66
  }
62
67
  // Objects
@@ -1,6 +1,12 @@
1
+ import type { DeepReadonly } from '@tsofist/stem';
1
2
  import type { JSONSchema7 } from 'json-schema';
3
+ import type { ForgedSchema, SchemaForgeDefinitionRef } from '../types';
2
4
  import type { SchemaDereferenceSharedCache } from './cache';
3
5
  export interface SchemaForgeDereferenceOptions {
6
+ /**
7
+ * Handler called when a reference is successfully dereferenced.
8
+ */
9
+ onDereferenceSuccess?: (resolvedRef: SchemaForgeDefinitionRef, resolvedNode: DeepReadonly<JSONSchema7>) => void;
4
10
  /**
5
11
  * Handler called when dereferencing fails.
6
12
  *
@@ -29,6 +35,13 @@ export interface SchemaForgeDereferenceOptions {
29
35
  * @default DefaultSchemaDereferenceSharedCache
30
36
  */
31
37
  sharedCacheStorage?: SchemaDereferenceSharedCache;
38
+ /**
39
+ * Source of definitions for resolving $ref references.
40
+ * If not provided, the definitions from the root schema will be used.
41
+ *
42
+ * @see ForgedSchema
43
+ */
44
+ definitionsSource?: ForgedSchema | JSONSchema7;
32
45
  }
33
46
  export type SchemaForgeDereferenceFailureHandler = (unresolvedRef: string, currentNode: JSONSchema7, resultSchema: JSONSchema7) => JSONSchema7 | undefined;
34
47
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/schema-dereference/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,SAAS,CAAC;AAE5D,MAAM,WAAW,6BAA6B;IAC1C;;;;;;OAMG;IACH,oBAAoB,CAAC,EAAE,oCAAoC,CAAC;IAC5D;;;;;;;;;OASG;IACH,yBAAyB,CAAC,EAAE,OAAO,CAAC;IACpC;;;;;;;OAOG;IACH,kBAAkB,CAAC,EAAE,4BAA4B,CAAC;CACrD;AAED,MAAM,MAAM,oCAAoC,GAAG,CAC/C,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,WAAW,EACxB,YAAY,EAAE,WAAW,KACxB,WAAW,GAAG,SAAS,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/schema-dereference/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,YAAY,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAC;AACvE,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,SAAS,CAAC;AAE5D,MAAM,WAAW,6BAA6B;IAC1C;;OAEG;IACH,oBAAoB,CAAC,EAAE,CACnB,WAAW,EAAE,wBAAwB,EACrC,YAAY,EAAE,YAAY,CAAC,WAAW,CAAC,KACtC,IAAI,CAAC;IACV;;;;;;OAMG;IACH,oBAAoB,CAAC,EAAE,oCAAoC,CAAC;IAC5D;;;;;;;;;OASG;IACH,yBAAyB,CAAC,EAAE,OAAO,CAAC;IACpC;;;;;;;OAOG;IACH,kBAAkB,CAAC,EAAE,4BAA4B,CAAC;IAClD;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,YAAY,GAAG,WAAW,CAAC;CAClD;AAED,MAAM,MAAM,oCAAoC,GAAG,CAC/C,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,WAAW,EACxB,YAAY,EAAE,WAAW,KACxB,WAAW,GAAG,SAAS,CAAC"}
@@ -14,6 +14,38 @@ const registry_1 = require("../schema-registry/registry");
14
14
  const forge_1 = require("./forge");
15
15
  /* eslint-disable @typescript-eslint/no-unsafe-argument */
16
16
  /* eslint-disable @typescript-eslint/no-unsafe-member-access */
17
+ describe('validator for a9', () => {
18
+ const outputSchemaFile = './a9.generated.schema.tmp.json';
19
+ const outputSchemaMetadataFile = './a9.generated.definitions.tmp.json';
20
+ let registry;
21
+ let loadedSchema;
22
+ beforeAll(async () => {
23
+ await (0, forge_1.forgeSchema)({
24
+ schemaId: 'test',
25
+ allowUseFallbackDescription: true,
26
+ tsconfigFrom: './tsconfig.build-test.json',
27
+ sourcesDirectoryPattern: 'test-sources/a9',
28
+ sourcesFilesPattern: ['service-api.ts', 'types.ts'],
29
+ outputSchemaFile,
30
+ outputSchemaMetadataFile,
31
+ expose: 'export',
32
+ explicitPublic: true,
33
+ });
34
+ registry = (0, registry_1.createSchemaForgeRegistry)();
35
+ loadedSchema = await (0, loader_1.loadJSONSchema)([outputSchemaFile]);
36
+ registry.addSchema(loadedSchema);
37
+ });
38
+ afterAll(async () => {
39
+ if (!artefacts_policy_1.KEEP_SPEC_ARTEFACTS) {
40
+ await (0, promises_1.unlink)(outputSchemaFile).catch(noop_1.noop);
41
+ await (0, promises_1.unlink)(outputSchemaMetadataFile).catch(noop_1.noop);
42
+ }
43
+ });
44
+ it('schema should be generated correctly with enums', () => {
45
+ const schema = registry.getRootSchema('test');
46
+ expect(schema).toMatchSnapshot();
47
+ });
48
+ });
17
49
  describe('generator for a8', () => {
18
50
  const outputSchemaFile = './a8.generated.schema.tmp.json';
19
51
  const outputSchemaMetadataFile = './a8.generated.definitions.tmp.json';
@@ -188,6 +220,7 @@ describe('generator for a6', () => {
188
220
  $ref: '#/definitions/UUID',
189
221
  format: 'uuid',
190
222
  description: 'This is Collection item ID (inherits from UUID)',
223
+ // see: 'https://ru.wikipedia.org/wiki/UUID Wikipedia',
191
224
  });
192
225
  expect(registry.getSchema('test#/definitions/CollectionItemID2')).toStrictEqual({
193
226
  $ref: '#/definitions/UUID',
@@ -197,6 +230,7 @@ describe('generator for a6', () => {
197
230
  expect(registry.getSchema('test#/definitions/CollectionItemID3')).toStrictEqual({
198
231
  format: 'uuid',
199
232
  type: 'string',
233
+ // see: 'https://ru.wikipedia.org/wiki/UUID Wikipedia',
200
234
  });
201
235
  expect(registry.getSchema('test#/definitions/CollectionItemID4')).toStrictEqual({
202
236
  $ref: '#/definitions/UUID',
@@ -217,12 +251,14 @@ describe('generator for a6', () => {
217
251
  expect(registry.getSchema('test#/definitions/CollectionItemID5')).toStrictEqual({
218
252
  format: 'uuid',
219
253
  type: 'string',
254
+ // see: 'https://ru.wikipedia.org/wiki/UUID Wikipedia',
220
255
  });
221
256
  {
222
257
  const rec = registry.getValidator('test#/definitions/PRec<CollectionItem,UUID>').schema;
223
258
  expect(rec).toBeTruthy();
224
259
  expect(rec.propertyNames).toStrictEqual({
225
260
  format: 'uuid',
261
+ // see: 'https://ru.wikipedia.org/wiki/UUID Wikipedia',
226
262
  });
227
263
  }
228
264
  {
@@ -231,6 +267,7 @@ describe('generator for a6', () => {
231
267
  expect(rec.propertyNames).toStrictEqual({
232
268
  format: 'uuid',
233
269
  description: 'This is Collection item ID (inherits from UUID)',
270
+ // see: 'https://ru.wikipedia.org/wiki/UUID Wikipedia',
234
271
  });
235
272
  }
236
273
  {
@@ -277,7 +314,7 @@ describe('generator for a5', () => {
277
314
  explicitPublic: true,
278
315
  shrinkDefinitionNames: (definitionName) => {
279
316
  if (definitionName === 'NamesType')
280
- return 'NT';
317
+ return 'DSN_H';
281
318
  return undefined;
282
319
  },
283
320
  });
@@ -296,11 +333,11 @@ describe('generator for a5', () => {
296
333
  const defs = forgeSchemaResult?.schema?.definitions;
297
334
  expect(defs).toBeTruthy();
298
335
  expect((0, keys_1.keysOf)(defs)).toStrictEqual([
336
+ 'DSN_H', // 'NamesType',
299
337
  'DomainNum',
300
338
  'DomainValue',
301
339
  'DomainValuesType',
302
340
  'FKColumn',
303
- 'NT', // 'NamesType',
304
341
  'NamesTypeAbnormal',
305
342
  'NumN',
306
343
  'Nums',
@@ -311,7 +348,7 @@ describe('generator for a5', () => {
311
348
  'VariadicList',
312
349
  'VariadicList1',
313
350
  ]);
314
- expect(registry.getValidator('test#/definitions/NT').schema).toStrictEqual({
351
+ expect(registry.getValidator('test#/definitions/DSN_H').schema).toStrictEqual({
315
352
  type: 'string',
316
353
  enum: ['v:name1', 'v:name2'],
317
354
  });
@@ -331,7 +368,7 @@ describe('generator for a5', () => {
331
368
  $ref: '#/definitions/DomainValuesType',
332
369
  },
333
370
  name0: {
334
- $ref: '#/definitions/NT',
371
+ $ref: '#/definitions/DSN_H',
335
372
  },
336
373
  name1: {
337
374
  type: 'string',
@@ -433,6 +470,7 @@ describe('generator for a5', () => {
433
470
  expect(v.properties.ref0).toStrictEqual({
434
471
  type: 'string',
435
472
  format: 'uuid',
473
+ // see: 'https://ru.wikipedia.org/wiki/UUID Wikipedia',
436
474
  description: 'Inline Foreign Key',
437
475
  dbFK: true,
438
476
  });
@@ -440,6 +478,7 @@ describe('generator for a5', () => {
440
478
  type: 'string',
441
479
  format: 'uuid',
442
480
  description: 'Foreign Key Column Type.',
481
+ // see: 'https://ru.wikipedia.org/wiki/UUID Wikipedia',
443
482
  dbFK: true,
444
483
  });
445
484
  expect(v.properties.ref2).toStrictEqual({
@@ -447,6 +486,7 @@ describe('generator for a5', () => {
447
486
  format: 'uuid',
448
487
  description: 'Inline Foreign Key (2)',
449
488
  dbFK: true,
489
+ // see: 'https://ru.wikipedia.org/wiki/UUID Wikipedia',
450
490
  });
451
491
  });
452
492
  });
@@ -511,7 +551,6 @@ describe('generator for a3', () => {
511
551
  const props = forgeSchemaResult.schema.definitions?.InterfaceWithGeneric__APIInterface?.properties;
512
552
  expect(props).toBeTruthy();
513
553
  expect(props.propWithGeneric).toBeTruthy();
514
- // @ts-expect-error It's a test
515
554
  expect(props.propWithGeneric.$ref).toStrictEqual('#/definitions/NonEmptyString');
516
555
  });
517
556
  it('optional args in API methods should works', () => {
@@ -626,6 +665,7 @@ describe('generator for a1', () => {
626
665
  it('getSchema', () => {
627
666
  expect(validator.getValidator('test#/definitions/PositiveInt').schema).toStrictEqual({
628
667
  type: 'integer',
668
+ // see: 'Int',
629
669
  minimum: 1,
630
670
  maximum: 9007199254740991,
631
671
  description: 'Positive integer value.',
@@ -1 +1 @@
1
- {"version":3,"file":"generate-drafts.d.ts","sourceRoot":"","sources":["../../src/schema-generator/generate-drafts.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,eAAe,EAAkB,MAAM,0CAA0C,CAAC;AAmChG,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAW9C;;GAEG;AACH,wBAAsB,sBAAsB,CAAC,OAAO,EAAE,YAAY;;;;;GAiCjE;AA6WD,UAAU,YAAa,SAAQ,kBAAkB;IAC7C,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,MAAM,EAAE,CAAC;CAC5B"}
1
+ {"version":3,"file":"generate-drafts.d.ts","sourceRoot":"","sources":["../../src/schema-generator/generate-drafts.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,eAAe,EAAkB,MAAM,0CAA0C,CAAC;AAmChG,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAW9C;;GAEG;AACH,wBAAsB,sBAAsB,CAAC,OAAO,EAAE,YAAY;;;;;GAkCjE;AA6WD,UAAU,YAAa,SAAQ,kBAAkB;IAC7C,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,MAAM,EAAE,CAAC;CAC5B"}
@@ -21,6 +21,7 @@ async function generateDraftTypeFiles(options) {
21
21
  expose: options.expose ?? types_1.SFG_CONFIG_DEFAULTS.expose,
22
22
  path: options.sourcesPattern.length > 1 ? undefined : options.sourcesPattern[0],
23
23
  tsconfig: options.tsconfig,
24
+ skipTypeCheck: options.skipTypeCheck ?? types_1.SFG_CONFIG_DEFAULTS.skipTypeCheck,
24
25
  discriminatorType: Config_1.DEFAULT_CONFIG.discriminatorType,
25
26
  ...types_1.SFG_CONFIG_MANDATORY,
26
27
  };
@@ -1,6 +1,6 @@
1
1
  import './extended-annotations-reader';
2
2
  import { CompletedConfig } from 'ts-json-schema-generator';
3
- import type { ForgedSchema, ForgeSchemaOptions } from '../types';
3
+ import { ForgedSchema, ForgeSchemaOptions } from '../types';
4
4
  /**
5
5
  * @internal
6
6
  */
@@ -1 +1 @@
1
- {"version":3,"file":"generate-schema.d.ts","sourceRoot":"","sources":["../../src/schema-generator/generate-schema.ts"],"names":[],"mappings":"AAAA,OAAO,+BAA+B,CAAC;AAKvC,OAAO,EAGH,eAAe,EAgBlB,MAAM,0BAA0B,CAAC;AAelC,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAMjE;;GAEG;AACH,wBAAsB,0BAA0B,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,YAAY,CAAC,CAgGhG;AAsGD,UAAU,eAAgB,SAAQ,kBAAkB;IAChD,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/B,2BAA2B,EAAE,eAAe,CAAC;CAChD"}
1
+ {"version":3,"file":"generate-schema.d.ts","sourceRoot":"","sources":["../../src/schema-generator/generate-schema.ts"],"names":[],"mappings":"AAAA,OAAO,+BAA+B,CAAC;AAMvC,OAAO,EAIH,eAAe,EAqBlB,MAAM,0BAA0B,CAAC;AAgBlC,OAAO,EAAwB,YAAY,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAOlF;;GAEG;AACH,wBAAsB,0BAA0B,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,YAAY,CAAC,CA4GhG;AAiKD,UAAU,eAAgB,SAAQ,kBAAkB;IAChD,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/B,2BAA2B,EAAE,eAAe,CAAC;CAChD"}
@@ -1,13 +1,17 @@
1
1
  "use strict";
2
+ var _SchemaGeneratorEx_multipleDefinitionsErrorSuppression;
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
4
  exports.generateSchemaByDraftTypes = generateSchemaByDraftTypes;
5
+ const tslib_1 = require("tslib");
4
6
  require("./extended-annotations-reader");
5
7
  const error_1 = require("@tsofist/stem/lib/error");
8
+ const value_in_1 = require("@tsofist/stem/lib/value-in");
6
9
  const ajv_1 = require("ajv");
7
10
  const jsonpath_plus_1 = require("jsonpath-plus");
8
11
  const ts_json_schema_generator_1 = require("ts-json-schema-generator");
9
12
  const typescript_1 = require("typescript");
10
13
  const helpers_tsc_1 = require("./helpers-tsc");
14
+ const patch_enum_node_parser_1 = require("./patch-enum-node-parser");
11
15
  const shrink_definition_name_1 = require("./shrink-definition-name");
12
16
  const sort_properties_1 = require("./sort-properties");
13
17
  const types_1 = require("./types");
@@ -30,6 +34,7 @@ async function generateSchemaByDraftTypes(options) {
30
34
  expose: options.expose ?? types_1.SFG_CONFIG_DEFAULTS.expose,
31
35
  path: `${options.sourcesDirectoryPattern}/*${types_1.TMP_FILES_SUFFIX}.ts`,
32
36
  tsconfig: options.tsconfig,
37
+ skipTypeCheck: options.skipTypeCheck ?? types_1.SFG_CONFIG_DEFAULTS.skipTypeCheck,
33
38
  discriminatorType: options.discriminatorType ?? ts_json_schema_generator_1.DEFAULT_CONFIG.discriminatorType,
34
39
  ...types_1.SFG_CONFIG_MANDATORY,
35
40
  };
@@ -41,18 +46,25 @@ async function generateSchemaByDraftTypes(options) {
41
46
  parser.addNodeParser(new ArrayLiteralExpressionIdentifierParser(typeChecker));
42
47
  parser.addNodeParser(new TypeofNodeParserEx(typeChecker, parser));
43
48
  });
44
- const formatter = (0, ts_json_schema_generator_1.createFormatter)(options.sourcesTypesGeneratorConfig);
45
- const generator = new ts_json_schema_generator_1.SchemaGenerator(generatorProgram, parser, formatter, generatorConfig);
49
+ const enumMetadataMap = new Map();
50
+ (0, patch_enum_node_parser_1.patchEnumNodeParser)(parser, typeChecker, enumMetadataMap, allowUseFallbackDescription);
46
51
  const result = {
47
52
  $schema: 'http://json-schema.org/draft-07/schema#',
48
53
  $id: options.schemaId,
54
+ version: undefined,
49
55
  hash: '',
50
56
  title: undefined,
51
57
  description: undefined,
52
- version: undefined,
53
58
  $comment: undefined,
54
59
  };
55
60
  const defs = (result.definitions ??= {});
61
+ const formatter = (0, ts_json_schema_generator_1.createFormatter)(options.sourcesTypesGeneratorConfig, (formatter) => {
62
+ formatter.addTypeFormatter(new EnumTypeFormatterEx(enumMetadataMap));
63
+ });
64
+ const generator = new SchemaGeneratorEx(generatorProgram, parser, formatter, generatorConfig);
65
+ if (options.suppressMultipleDefinitionsErrors) {
66
+ generator.setMultipleDefinitionsErrorSuppression(true);
67
+ }
56
68
  for (const definitionName of options.definitions) {
57
69
  const schema = generator.createSchema(definitionName);
58
70
  Object.assign(defs, schema.definitions);
@@ -98,8 +110,46 @@ async function generateSchemaByDraftTypes(options) {
98
110
  }).validateSchema(result, true);
99
111
  return result;
100
112
  }
101
- function escapeDefinitionNameForJSONPath(value) {
102
- return value.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
113
+ class EnumTypeFormatterEx extends ts_json_schema_generator_1.EnumTypeFormatter {
114
+ constructor(metaMap) {
115
+ super();
116
+ Object.defineProperty(this, "metaMap", {
117
+ enumerable: true,
118
+ configurable: true,
119
+ writable: true,
120
+ value: metaMap
121
+ });
122
+ }
123
+ getDefinition(type) {
124
+ const id = type.getId();
125
+ const inherited = super.getDefinition(type);
126
+ if (inherited?.enum) {
127
+ let count = 0;
128
+ const annotations = {};
129
+ for (const value of inherited.enum) {
130
+ if ((0, value_in_1.valueIn)(typeof value, ['string', 'number'])) {
131
+ const v = value;
132
+ const key = `${id}.${v}`;
133
+ const doc = this.metaMap.get(key);
134
+ if (doc) {
135
+ count++;
136
+ const ann = (annotations[doc.title] = [doc.value]);
137
+ if (doc.description)
138
+ ann.push(doc.description);
139
+ if (doc.comment)
140
+ ann.push(doc.comment);
141
+ }
142
+ }
143
+ }
144
+ if (count > 0) {
145
+ return {
146
+ ...inherited,
147
+ enumAnnotation: annotations,
148
+ };
149
+ }
150
+ }
151
+ return inherited;
152
+ }
103
153
  }
104
154
  class TypeofNodeParserEx extends ts_json_schema_generator_1.TypeofNodeParser {
105
155
  createType(node, context, reference) {
@@ -184,6 +234,28 @@ class ArrayLiteralExpressionIdentifierParser {
184
234
  }
185
235
  }
186
236
  }
237
+ class SchemaGeneratorEx extends ts_json_schema_generator_1.SchemaGenerator {
238
+ constructor() {
239
+ super(...arguments);
240
+ _SchemaGeneratorEx_multipleDefinitionsErrorSuppression.set(this, false);
241
+ }
242
+ setMultipleDefinitionsErrorSuppression(value) {
243
+ tslib_1.__classPrivateFieldSet(this, _SchemaGeneratorEx_multipleDefinitionsErrorSuppression, value, "f");
244
+ }
245
+ appendRootChildDefinitions(rootType, childDefinitions) {
246
+ try {
247
+ super.appendRootChildDefinitions(rootType, childDefinitions);
248
+ }
249
+ catch (e) {
250
+ if (e instanceof ts_json_schema_generator_1.MultipleDefinitionsError) {
251
+ if (tslib_1.__classPrivateFieldGet(this, _SchemaGeneratorEx_multipleDefinitionsErrorSuppression, "f"))
252
+ return;
253
+ }
254
+ throw e;
255
+ }
256
+ }
257
+ }
258
+ _SchemaGeneratorEx_multipleDefinitionsErrorSuppression = new WeakMap();
187
259
  function getIdentifierLiteralValue(node, checker) {
188
260
  const type = checker.getTypeAtLocation(node);
189
261
  if (type.isNumberLiteral() || type.isStringLiteral()) {
@@ -191,3 +263,6 @@ function getIdentifierLiteralValue(node, checker) {
191
263
  }
192
264
  return undefined;
193
265
  }
266
+ function escapeDefinitionNameForJSONPath(value) {
267
+ return value.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
268
+ }
@@ -1,7 +1,9 @@
1
1
  import { type CompilerHost, type CompilerOptions, type MethodSignature, type NamedDeclaration, type Node, type PropertySignature, type SignatureDeclarationBase } from 'typescript';
2
2
  export declare function readMemberTypeName(member: MethodSignature | PropertySignature | SignatureDeclarationBase): string | undefined;
3
+ export declare function readJSDocTagValue(node: Node, tagName: string): string | undefined;
3
4
  export declare function readJSDocDescription(node: Node, allowUseFallbackDescription: boolean | undefined, allowUseFallbackDescriptionFromParent?: boolean): string | undefined;
4
5
  export declare function readNodeName(node: NamedDeclaration): string;
6
+ export declare function readNodeName(node: Node): string | undefined;
5
7
  export declare function readInterfaceGenericText(node: NamedDeclaration): string;
6
8
  export declare function hasJSDocTag(statement: Node, tagName: string): boolean;
7
9
  export declare function resolveModuleFileName(containingFile: string, moduleName: string, compilerOptions: CompilerOptions, compilerHost: CompilerHost): string | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"helpers-tsc.d.ts","sourceRoot":"","sources":["../../src/schema-generator/helpers-tsc.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,KAAK,YAAY,EACjB,KAAK,eAAe,EAGpB,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,IAAI,EACT,KAAK,iBAAiB,EACtB,KAAK,wBAAwB,EAUhC,MAAM,YAAY,CAAC;AAEpB,wBAAgB,kBAAkB,CAC9B,MAAM,EAAE,eAAe,GAAG,iBAAiB,GAAG,wBAAwB,GACvE,MAAM,GAAG,SAAS,CAapB;AAED,wBAAgB,oBAAoB,CAChC,IAAI,EAAE,IAAI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,EAAE,gBAAgB,GAAG,MAAM,CAKvE;AAED,wBAAgB,WAAW,CAAC,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAM3D;AAED,wBAAgB,qBAAqB,CACjC,cAAc,EAAE,MAAM,EACtB,UAAU,EAAE,MAAM,EAClB,eAAe,EAAE,eAAe,EAChC,YAAY,EAAE,YAAY,GAC3B,MAAM,GAAG,SAAS,CAQpB"}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.readMemberTypeName = readMemberTypeName;
4
+ exports.readJSDocTagValue = readJSDocTagValue;
4
5
  exports.readJSDocDescription = readJSDocDescription;
5
6
  exports.readNodeName = readNodeName;
6
7
  exports.readInterfaceGenericText = readInterfaceGenericText;
@@ -20,6 +21,19 @@ function readMemberTypeName(member) {
20
21
  }
21
22
  return type?.getText();
22
23
  }
24
+ function readJSDocTagValue(node, tagName) {
25
+ let value = undefined;
26
+ {
27
+ const isTag = (tag) => {
28
+ if (tag.tagName.escapedText === tagName) {
29
+ value = (0, typescript_1.getTextOfJSDocComment)(tag.comment);
30
+ }
31
+ return value !== undefined;
32
+ };
33
+ (0, typescript_1.getAllJSDocTags)(node, isTag);
34
+ }
35
+ return value;
36
+ }
23
37
  function readJSDocDescription(node, allowUseFallbackDescription, allowUseFallbackDescriptionFromParent = true) {
24
38
  let value = undefined;
25
39
  let fallback = undefined;
@@ -51,7 +65,10 @@ function readJSDocDescription(node, allowUseFallbackDescription, allowUseFallbac
51
65
  return value;
52
66
  }
53
67
  function readNodeName(node) {
54
- return node.name.escapedText + '';
68
+ if ('name' in node && !!node.name) {
69
+ return node.name.escapedText + '';
70
+ }
71
+ return undefined;
55
72
  }
56
73
  function readInterfaceGenericText(node) {
57
74
  if ((0, typescript_1.isInterfaceDeclaration)(node) && node.typeParameters?.length) {
@@ -0,0 +1,12 @@
1
+ import { NodeParser } from 'ts-json-schema-generator';
2
+ import { TypeChecker } from 'typescript';
3
+ export declare function patchEnumNodeParser(root: NodeParser, checker: TypeChecker, meta: SFEnumMetadataMap, allowUseFallbackDescription: boolean | undefined): undefined;
4
+ export type SFEnumMetadata = {
5
+ typeName: string;
6
+ title: string;
7
+ value: string | number;
8
+ description: string | undefined;
9
+ comment: string | undefined;
10
+ };
11
+ export type SFEnumMetadataMap = Map<string, SFEnumMetadata>;
12
+ //# sourceMappingURL=patch-enum-node-parser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"patch-enum-node-parser.d.ts","sourceRoot":"","sources":["../../src/schema-generator/patch-enum-node-parser.ts"],"names":[],"mappings":"AACA,OAAO,EAKH,UAAU,EAEb,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAA6C,WAAW,EAAE,MAAM,YAAY,CAAC;AAGpF,wBAAgB,mBAAmB,CAC/B,IAAI,EAAE,UAAU,EAChB,OAAO,EAAE,WAAW,EACpB,IAAI,EAAE,iBAAiB,EACvB,2BAA2B,EAAE,OAAO,GAAG,SAAS,aAwEnD;AAED,MAAM,MAAM,cAAc,GAAG;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC"}
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.patchEnumNodeParser = patchEnumNodeParser;
4
+ const error_1 = require("@tsofist/stem/lib/error");
5
+ const ts_json_schema_generator_1 = require("ts-json-schema-generator");
6
+ const typescript_1 = require("typescript");
7
+ const helpers_tsc_1 = require("./helpers-tsc");
8
+ function patchEnumNodeParser(root, checker, meta, allowUseFallbackDescription) {
9
+ const stack = root.childNodeParser.nodeParsers;
10
+ const enumNodeParser = stack.find((parser) => {
11
+ return (
12
+ //
13
+ parser instanceof ts_json_schema_generator_1.ExposeNodeParser &&
14
+ // @ts-expect-error It's a access-hack
15
+ parser.subNodeParser instanceof ts_json_schema_generator_1.AnnotatedNodeParser &&
16
+ // @ts-expect-error It's a access-hack
17
+ parser.subNodeParser.childNodeParser instanceof ts_json_schema_generator_1.EnumNodeParser);
18
+ });
19
+ if (!enumNodeParser) {
20
+ return (0, error_1.raise)(`Failed to patch EnumNodeParser, not found in stack`);
21
+ }
22
+ const originalCreateType = enumNodeParser.subNodeParser.childNodeParser.createType.bind(enumNodeParser.subNodeParser.childNodeParser);
23
+ enumNodeParser.subNodeParser.childNodeParser.createType = function PatchedCreateType() {
24
+ // eslint-disable-next-line prefer-rest-params
25
+ const node = arguments[0];
26
+ const typeName = (0, helpers_tsc_1.readNodeName)(node);
27
+ const result = originalCreateType.apply(this,
28
+ // @ts-expect-error It's a access-hack
29
+ // eslint-disable-next-line prefer-rest-params
30
+ arguments);
31
+ const resultId = result.getId();
32
+ if ((0, typescript_1.isEnumMember)(node)) {
33
+ // todo EnumMember!
34
+ return result;
35
+ }
36
+ else {
37
+ for (const member of node.members) {
38
+ const memberValue = checker.getConstantValue(member);
39
+ const memberName = (0, helpers_tsc_1.readNodeName)(member);
40
+ const description = (0, helpers_tsc_1.readJSDocDescription)(member, allowUseFallbackDescription);
41
+ const comment = (0, helpers_tsc_1.readJSDocTagValue)(member, 'comment');
42
+ const metaKey = `${resultId}.${String(memberValue)}`;
43
+ meta.set(metaKey, {
44
+ typeName,
45
+ title: memberName,
46
+ value: memberValue,
47
+ description,
48
+ comment,
49
+ });
50
+ }
51
+ return result;
52
+ }
53
+ };
54
+ }
@@ -1,7 +1,7 @@
1
- import type { NonEmptyString } from '@tsofist/stem';
1
+ import type { ForgedSchemaDefinitionShortName } from '../types';
2
2
  /**
3
3
  * Shrink definition name by removing generic type parameters
4
4
  * and appending a digest of the removed part.
5
5
  */
6
- export declare function shrinkDefinitionName(definitionName: string, suffixLength?: number): NonEmptyString | undefined;
6
+ export declare function shrinkDefinitionName(definitionName: string, suffixLength?: number): ForgedSchemaDefinitionShortName | undefined;
7
7
  //# sourceMappingURL=shrink-definition-name.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"shrink-definition-name.d.ts","sourceRoot":"","sources":["../../src/schema-generator/shrink-definition-name.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpD;;;GAGG;AACH,wBAAgB,oBAAoB,CAChC,cAAc,EAAE,MAAM,EACtB,YAAY,SAAI,GACjB,cAAc,GAAG,SAAS,CAc5B"}
1
+ {"version":3,"file":"shrink-definition-name.d.ts","sourceRoot":"","sources":["../../src/schema-generator/shrink-definition-name.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,UAAU,CAAC;AAEhE;;;GAGG;AACH,wBAAgB,oBAAoB,CAChC,cAAc,EAAE,MAAM,EACtB,YAAY,SAAI,GACjB,+BAA+B,GAAG,SAAS,CAc7C"}
@@ -6,7 +6,7 @@ const node_crypto_1 = require("node:crypto");
6
6
  * Shrink definition name by removing generic type parameters
7
7
  * and appending a digest of the removed part.
8
8
  */
9
- function shrinkDefinitionName(definitionName, suffixLength = 8) {
9
+ function shrinkDefinitionName(definitionName, suffixLength = 6) {
10
10
  const startPos = definitionName.indexOf('<');
11
11
  if (startPos >= 0) {
12
12
  const hashSource = definitionName.substring(startPos);
@@ -15,7 +15,7 @@ function shrinkDefinitionName(definitionName, suffixLength = 8) {
15
15
  .update(hashSource)
16
16
  .digest('hex')
17
17
  .substring(0, suffixLength);
18
- return `${prefix}_H${digest}`;
18
+ return `DSN${prefix}_H${digest}`;
19
19
  }
20
20
  return undefined;
21
21
  }
@@ -1,19 +1,20 @@
1
1
  export declare const TMP_FILES_SUFFIX = ".schema-forge.temporary-generated.tmp";
2
+ export declare const SFG_EXTRA_TAGS: readonly ["apiInterface", "apiProperty", "apiMethod", "apiMember", "dbFK", "dbEntity", "dbColumn", "dbIndex", "dbEnum", "enumAnnotation", "enumMember", "spec", "faker", "version", "hash"];
2
3
  export declare const SFG_CONFIG_DEFAULTS: {
3
- readonly sortProps: true;
4
4
  readonly additionalProperties: false;
5
- readonly expose: "export";
6
- readonly strictTuples: true;
7
- readonly extraTags: ["apiMember", "apiMethod", "apiInterface", "apiProperty", "dbColumn", "dbIndex", "dbEntity", "dbFK", "faker"];
8
- readonly encodeRefs: false;
9
- readonly markdownDescription: false;
10
5
  readonly discriminatorType: undefined;
6
+ readonly encodeRefs: false;
7
+ readonly expose: "export";
8
+ readonly extraTags: ("spec" | "hash" | "dbEntity" | "dbFK" | "dbColumn" | "dbIndex" | "dbEnum" | "enumAnnotation" | "version" | "apiInterface" | "apiProperty" | "apiMethod" | "apiMember" | "enumMember" | "faker")[];
11
9
  readonly functions: "hide";
10
+ readonly markdownDescription: false;
11
+ readonly skipTypeCheck: false;
12
+ readonly sortProps: true;
13
+ readonly strictTuples: true;
12
14
  };
13
15
  export type SF_EXTRA_JSS_TAG_NAME = (typeof SFG_CONFIG_DEFAULTS)['extraTags'][number];
14
16
  export declare const SFG_CONFIG_MANDATORY: {
15
17
  readonly jsDoc: "extended";
16
18
  readonly topRef: true;
17
- readonly skipTypeCheck: false;
18
19
  };
19
20
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/schema-generator/types.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,gBAAgB,0CAA0C,CAAC;AAExE,eAAO,MAAM,mBAAmB;;;;;;;;;;CAuBL,CAAC;AAE5B,MAAM,MAAM,qBAAqB,GAAG,CAAC,OAAO,mBAAmB,CAAC,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAEtF,eAAO,MAAM,oBAAoB;;;;CAIN,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/schema-generator/types.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,gBAAgB,0CAA0C,CAAC;AAExE,eAAO,MAAM,cAAc,6LAsBjB,CAAC;AAEX,eAAO,MAAM,mBAAmB;;;;;;;;;;;CAWL,CAAC;AAE5B,MAAM,MAAM,qBAAqB,GAAG,CAAC,OAAO,mBAAmB,CAAC,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAEtF,eAAO,MAAM,oBAAoB;;;CAGN,CAAC"}
@@ -1,33 +1,43 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SFG_CONFIG_MANDATORY = exports.SFG_CONFIG_DEFAULTS = exports.TMP_FILES_SUFFIX = void 0;
3
+ exports.SFG_CONFIG_MANDATORY = exports.SFG_CONFIG_DEFAULTS = exports.SFG_EXTRA_TAGS = exports.TMP_FILES_SUFFIX = void 0;
4
4
  exports.TMP_FILES_SUFFIX = '.schema-forge.temporary-generated.tmp';
5
+ exports.SFG_EXTRA_TAGS = [
6
+ //
7
+ 'apiInterface',
8
+ 'apiProperty',
9
+ 'apiMethod',
10
+ 'apiMember',
11
+ //
12
+ 'dbFK',
13
+ 'dbEntity',
14
+ 'dbColumn',
15
+ 'dbIndex',
16
+ 'dbEnum',
17
+ //
18
+ 'enumAnnotation',
19
+ 'enumMember',
20
+ // 'see',
21
+ 'spec',
22
+ //
23
+ 'faker',
24
+ //
25
+ 'version',
26
+ 'hash',
27
+ ];
5
28
  exports.SFG_CONFIG_DEFAULTS = {
6
- sortProps: true,
7
29
  additionalProperties: false,
8
- expose: 'export',
9
- strictTuples: true,
10
- extraTags: [
11
- //
12
- 'apiMember',
13
- 'apiMethod',
14
- 'apiInterface',
15
- 'apiProperty',
16
- //
17
- 'dbColumn',
18
- 'dbIndex',
19
- 'dbEntity',
20
- 'dbFK',
21
- //
22
- 'faker',
23
- ],
24
- encodeRefs: false,
25
- markdownDescription: false,
26
30
  discriminatorType: undefined,
31
+ encodeRefs: false,
32
+ expose: 'export',
33
+ extraTags: Array.from(exports.SFG_EXTRA_TAGS),
27
34
  functions: 'hide',
35
+ markdownDescription: false,
36
+ skipTypeCheck: false,
37
+ sortProps: true,
38
+ strictTuples: true,
28
39
  };
29
40
  exports.SFG_CONFIG_MANDATORY = {
30
41
  jsDoc: 'extended',
31
42
  topRef: true,
32
- skipTypeCheck: false,
33
43
  };
@@ -1 +1 @@
1
- {"version":3,"file":"kw-api.d.ts","sourceRoot":"","sources":["../../src/schema-registry/kw-api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,KAAK,CAAC;AAO7C,eAAO,MAAM,wBAAwB,EAAE,SAAS,iBAAiB,EAiBvD,CAAC"}
1
+ {"version":3,"file":"kw-api.d.ts","sourceRoot":"","sources":["../../src/schema-registry/kw-api.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,KAAK,CAAC;AAQ7C,eAAO,MAAM,wBAAwB,EAAE,SAAS,iBAAiB,EAmB7D,CAAC"}
@@ -7,19 +7,19 @@ const NP_API_METHOD = NP_API_PROP;
7
7
  const NP_API_MEMBER = `${NP_API_INTERFACE.substring(0, NP_API_INTERFACE.length - 1)}#${NP_API_PROP.substring(1)}`;
8
8
  exports.SFRAPIDefinitionKeywords = [
9
9
  {
10
- keyword: ['interface', 'apiInterface'],
10
+ keyword: 'apiInterface',
11
11
  metaSchema: { type: 'string', pattern: NP_API_INTERFACE },
12
12
  },
13
13
  {
14
- keyword: ['property', 'apiProperty'],
14
+ keyword: 'apiProperty',
15
15
  metaSchema: { type: 'string', pattern: NP_API_PROP },
16
16
  },
17
17
  {
18
- keyword: ['method', 'apiMethod'],
18
+ keyword: 'apiMethod',
19
19
  metaSchema: { type: 'string', pattern: NP_API_METHOD },
20
20
  },
21
21
  {
22
- keyword: ['member', 'apiMember'],
22
+ keyword: 'apiMember',
23
23
  metaSchema: { type: 'string', pattern: NP_API_MEMBER },
24
24
  },
25
25
  ];
@@ -1 +1 @@
1
- {"version":3,"file":"kw-common.d.ts","sourceRoot":"","sources":["../../src/schema-registry/kw-common.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,KAAK,CAAC;AAI7C,eAAO,MAAM,iBAAiB,EAAE,SAAS,iBAAiB,EA0ChD,CAAC"}
1
+ {"version":3,"file":"kw-common.d.ts","sourceRoot":"","sources":["../../src/schema-registry/kw-common.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,KAAK,CAAC;AAQ7C,eAAO,MAAM,iBAAiB,EAAE,SAAS,iBAAiB,EAsFtD,CAAC"}
@@ -2,6 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SFRCommonKeywords = void 0;
4
4
  const FakerModulePattern = '^[a-zA-Z.]+$';
5
+ const NP_ENUM_KEY = '^[a-zA-Z0-9-\\._]+$';
6
+ const NP_ENUM_VALUE = '^[a-zA-Z0-9-\\._:]+$';
5
7
  exports.SFRCommonKeywords = [
6
8
  {
7
9
  keyword: 'version',
@@ -13,6 +15,48 @@ exports.SFRCommonKeywords = [
13
15
  dependencies: ['$id', '$schema'],
14
16
  metaSchema: { type: 'string' },
15
17
  },
18
+ // {
19
+ // keyword: 'see',
20
+ // metaSchema: {
21
+ // additionalProperties: false,
22
+ // type: ['string', 'array'],
23
+ // items: {
24
+ // anyOf: [
25
+ // { type: 'string', format: 'uri' },
26
+ // {
27
+ // type: 'array',
28
+ // items: [{ type: 'string', format: 'uri' }, { type: 'string' }],
29
+ // minItems: 2,
30
+ // },
31
+ // ],
32
+ // },
33
+ // },
34
+ // },
35
+ {
36
+ keyword: 'spec',
37
+ metaSchema: {
38
+ type: 'array',
39
+ items: { type: 'string' },
40
+ },
41
+ },
42
+ {
43
+ keyword: 'enumAnnotation',
44
+ dependencies: ['enum'],
45
+ metaSchema: {
46
+ type: 'object',
47
+ propertyNames: { type: 'string', pattern: NP_ENUM_KEY },
48
+ additionalProperties: {
49
+ type: 'array',
50
+ minItems: 1,
51
+ maxItems: 3,
52
+ items: [
53
+ { title: 'value', type: ['string', 'number'], pattern: NP_ENUM_VALUE },
54
+ { title: 'note', type: 'string' },
55
+ { title: 'comment', type: 'string' },
56
+ ],
57
+ },
58
+ },
59
+ },
16
60
  {
17
61
  keyword: 'faker',
18
62
  metaSchema: {
@@ -1,3 +1,3 @@
1
- import { type KeywordDefinition } from 'ajv';
1
+ import type { KeywordDefinition } from 'ajv';
2
2
  export declare const SFRDBMLKeywords: readonly KeywordDefinition[];
3
3
  //# sourceMappingURL=kw-dbml.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"kw-dbml.d.ts","sourceRoot":"","sources":["../../src/schema-registry/kw-dbml.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,KAAK,CAAC;AAiD7C,eAAO,MAAM,eAAe,EAAE,SAAS,iBAAiB,EA8C9C,CAAC"}
1
+ {"version":3,"file":"kw-dbml.d.ts","sourceRoot":"","sources":["../../src/schema-registry/kw-dbml.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,KAAK,CAAC;AAkD7C,eAAO,MAAM,eAAe,EAAE,SAAS,iBAAiB,EAoDpD,CAAC"}
@@ -4,7 +4,7 @@ exports.SFRDBMLKeywords = void 0;
4
4
  const types_1 = require("../dbml-generator/types");
5
5
  const NP_IX = '^ix_[a-z][a-zA-Z0-9_]+$';
6
6
  const NP_ENTITY = '^([a-zA-Z_][a-z0-9_]*\\.)?[a-z_][a-z0-9_]*$';
7
- const NP_NESTED_PROP = '^[a-z][a-zA-Z0-9.-]+$';
7
+ const NP_NESTED_PROP = '^[a-z][a-zA-Z0-9-\\._]+$';
8
8
  const DBMLIndexOptionsProperties = {
9
9
  name: { type: 'string', pattern: NP_IX },
10
10
  unique: { type: 'boolean' },
@@ -38,6 +38,10 @@ DBMLIndexSchema.items = {
38
38
  type: ['string', 'boolean', 'object'],
39
39
  };
40
40
  exports.SFRDBMLKeywords = [
41
+ {
42
+ keyword: 'dbEnum',
43
+ metaSchema: { type: ['boolean', 'string'], pattern: NP_NESTED_PROP },
44
+ },
41
45
  {
42
46
  keyword: 'dbFK',
43
47
  metaSchema: DBMLForeignKeySchema,
@@ -69,7 +73,7 @@ exports.SFRDBMLKeywords = [
69
73
  indexes: {
70
74
  type: 'object',
71
75
  additionalProperties: DBMLIndexSchema,
72
- propertyNames: { pattern: NP_NESTED_PROP },
76
+ propertyNames: { type: 'string', pattern: NP_NESTED_PROP },
73
77
  },
74
78
  note: { type: 'string' },
75
79
  comment: { type: 'string' },
@@ -1 +1 @@
1
- {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/schema-registry/registry.ts"],"names":[],"mappings":"AA6BA,OAAO,EACH,mBAAmB,EAEnB,0BAA0B,EAC7B,MAAM,SAAS,CAAC;AAsBjB;;;;GAIG;AACH,wBAAgB,yBAAyB,CACrC,OAAO,CAAC,EAAE,0BAA0B,GACrC,mBAAmB,CA0OrB"}
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/schema-registry/registry.ts"],"names":[],"mappings":"AA8BA,OAAO,EACH,mBAAmB,EAEnB,0BAA0B,EAC7B,MAAM,SAAS,CAAC;AAsBjB;;;;GAIG;AACH,wBAAgB,yBAAyB,CACrC,OAAO,CAAC,EAAE,0BAA0B,GACrC,mBAAmB,CA+OrB"}
@@ -154,7 +154,7 @@ function createSchemaForgeRegistry(options) {
154
154
  }
155
155
  function readSchemaKeywords(schema) {
156
156
  const result = new Map();
157
- for (const tag of types_1.SFG_CONFIG_DEFAULTS.extraTags) {
157
+ for (const tag of types_1.SFG_EXTRA_TAGS) {
158
158
  if (tag in schema) {
159
159
  result.set(tag,
160
160
  // @ts-expect-error It's OK
@@ -165,9 +165,12 @@ function createSchemaForgeRegistry(options) {
165
165
  }
166
166
  function listDefinitions(predicate) {
167
167
  const result = [];
168
+ const filter = typeof predicate === 'number'
169
+ ? (info) => info.kind === predicate
170
+ : predicate;
168
171
  mapDefinitions((name, schemaId, schema) => {
169
172
  const info = (0, parser_1.parseSchemaDefinitionInfo)(name, schemaId, legacy);
170
- if (predicate === undefined || predicate(info, readSchemaKeywords(schema))) {
173
+ if (filter === undefined || filter(info, readSchemaKeywords(schema))) {
171
174
  result.push(info);
172
175
  }
173
176
  });
@@ -3,7 +3,7 @@ import type { NonNegativeInt } from '@tsofist/stem/lib/number/integer/types';
3
3
  import type { ErrorsTextOptions, Options } from 'ajv';
4
4
  import type { Options as AjvOptions } from 'ajv/dist/core';
5
5
  import type { JSONSchema7 } from 'json-schema';
6
- import type { SchemaDefinitionInfo } from '../definition-info/types';
6
+ import type { SchemaDefinitionInfo, SchemaDefinitionInfoKind } from '../definition-info/types';
7
7
  import type { SchemaForgeValidationContextBase } from '../efc';
8
8
  import type { SF_EXTRA_JSS_TAG_NAME } from '../schema-generator/types';
9
9
  import type { SchemaForgeDefinitionRef, SchemaForgeValidationFunction, SchemaForgeValidationReport, SchemaForgeValidationResult } from '../types';
@@ -63,9 +63,9 @@ export interface SchemaForgeRegistry {
63
63
  */
64
64
  validationErrorsText: (errors: Nullable<SchemaForgeValidationReport>, options?: ErrorsTextOptions) => string;
65
65
  /**
66
- * List schema definitions
66
+ * List definitions of all schemas in registry.
67
67
  */
68
- listDefinitions: (predicate?: SchemaForgeRegistryListDefinitionsPredicate) => SchemaDefinitionInfo[];
68
+ listDefinitions: <T extends SchemaDefinitionInfo>(predicate?: SchemaForgeRegistryListDefinitionsPredicate | SchemaDefinitionInfoKind) => T[];
69
69
  /**
70
70
  * Asynchronously warm up schemaRegistry cache.
71
71
  * This action is useful to pre-compile all schemas and their definitions
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/schema-registry/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAA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,CAAC,mBAAmB,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAE/E;;;OAGG;IACH,eAAe,EAAE,YAAY,CAAC;CACjC;AAED,MAAM,WAAW,0BAA0B;IACvC;;;;;OAKG;IACH,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB;;;;;OAKG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B;;;OAGG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC/B"}
package/lib/types.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import type { NonEmptyString, Nullable, PRec, Reintroduce } from '@tsofist/stem';
1
+ import type { Nullable, PRec, Rec, Reintroduce } from '@tsofist/stem';
2
2
  import type { ErrorObject, ErrorsTextOptions, ValidateFunction } from 'ajv';
3
3
  import type { JSONSchema7 as Schema } from 'json-schema';
4
4
  import type { Config } from 'ts-json-schema-generator';
5
- import type { DBMLColumnOptions, DBMLEntityOptionsDef, DBMLForeignKeyOptions, DBMLIndexOptionsDef } from './dbml-generator/types';
5
+ import { DBMLColumnOptions, DBMLEntityOptionsDef, DBMLEnumAnnotationOptions, DBMLEnumOptionsDef, DBMLForeignKeyOptions, DBMLIndexOptionsDef } from './dbml-generator/types';
6
6
  export interface ForgeSchemaOptions {
7
7
  /**
8
8
  * Generate schema definitions for public types only
@@ -99,13 +99,29 @@ export interface ForgeSchemaOptions {
99
99
  *
100
100
  * @see shrinkDefinitionName
101
101
  */
102
- readonly shrinkDefinitionNames?: boolean | ((definitionName: string) => undefined | NonEmptyString);
102
+ readonly shrinkDefinitionNames?: boolean | ((definitionName: string) => undefined | ForgedSchemaDefinitionShortName);
103
103
  /**
104
104
  * @deprecated
105
105
  * @default false
106
106
  */
107
107
  readonly legacyDefinitions?: boolean;
108
+ /**
109
+ * Skip type checking.
110
+ * This may help with some complex projects, but can lead to incorrect schema generation.
111
+ *
112
+ * @default false
113
+ */
114
+ readonly skipTypeCheck?: boolean;
115
+ /**
116
+ * Suppress errors about multiple definitions with the same name.
117
+ * By default, an error is thrown if multiple definitions with the same name are found.
118
+ * This option can be useful in monorepo setups where multiple packages may have types with the same name.
119
+ *
120
+ * @default false
121
+ */
122
+ readonly suppressMultipleDefinitionsErrors?: boolean;
108
123
  }
124
+ export type ForgedSchemaDefinitionShortName = `DSN${string}_H${string}`;
109
125
  export interface SchemaForgeMetadata {
110
126
  $id: string;
111
127
  title?: string;
@@ -119,25 +135,27 @@ export interface SchemaForgeMetadata {
119
135
  serviceNames: PRec<SchemaForgeDefinitionRef>;
120
136
  }
121
137
  declare const ForgedSchemaDraft7Id = "http://json-schema.org/draft-07/schema#";
122
- export type ForgedSchema = Reintroduce<Schema, {
138
+ export type ForgedSchema = Reintroduce<Schema, Pick<ForgedSchemaDefinition, 'see' | 'spec'> & {
123
139
  $schema: typeof ForgedSchemaDraft7Id;
124
- $id?: string;
125
- $comment?: string;
126
140
  hash?: string;
127
- title?: string;
128
- description?: string;
129
141
  version?: string;
130
- $defs?: PRec<Schema>;
131
- definitions?: PRec<Schema>;
142
+ $defs?: Rec<ForgedSchemaDefinition>;
143
+ definitions?: Rec<ForgedSchemaDefinition>;
132
144
  }>;
133
- export type ForgedEntitySchema = Schema & {
134
- dbEntity?: DBMLEntityOptionsDef;
135
- properties?: PRec<ForgedEntitySchema>;
145
+ export type ForgedEntitySchema = Schema & Pick<ForgedSchemaDefinition, 'see' | 'spec' | 'dbEntity'> & {
146
+ properties?: Rec<ForgedEntitySchema>;
136
147
  };
137
- export type ForgedPropertySchema = Schema & {
148
+ export type ForgedPropertySchema = Schema & Pick<ForgedSchemaDefinition, 'dbFK' | 'dbColumn' | 'dbIndex' | 'dbEnum' | 'enumAnnotation'>;
149
+ export type ForgedSchemaDefinition = Schema & {
150
+ see?: (string | [ref: string, title: string])[];
151
+ spec?: string;
138
152
  dbFK?: DBMLForeignKeyOptions;
139
- dbIndex?: DBMLIndexOptionsDef;
140
153
  dbColumn?: DBMLColumnOptions;
154
+ dbIndex?: DBMLIndexOptionsDef;
155
+ dbEnum?: DBMLEnumOptionsDef;
156
+ enumAnnotation?: DBMLEnumAnnotationOptions;
157
+ dbEntity?: DBMLEntityOptionsDef;
158
+ properties?: PRec<ForgedEntitySchema>;
141
159
  };
142
160
  export interface ForgeSchemaResult {
143
161
  schema: ForgedSchema;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjF,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,KAAK,CAAC;AAC5E,OAAO,KAAK,EAAE,WAAW,IAAI,MAAM,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,KAAK,EACR,iBAAiB,EACjB,oBAAoB,EACpB,qBAAqB,EACrB,mBAAmB,EACtB,MAAM,wBAAwB,CAAC;AAEhC,MAAM,WAAW,kBAAkB;IAC/B;;;OAGG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,OAAO,CAAC;IAClC;;;OAGG;IACH,QAAQ,CAAC,2BAA2B,CAAC,EAAE,OAAO,CAAC;IAC/C;;;OAGG;IACH,QAAQ,CAAC,iBAAiB,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;IACvD;;;;OAIG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,cAAc,CAAC;IACjC;;OAEG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B;;;;OAIG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE;QACtB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,QAAQ,CAAC,E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,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;AACvC,KAAK,iBAAiB,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsofist/schema-forge",
3
- "version": "3.7.1",
3
+ "version": "4.1.0",
4
4
  "description": "Generate JSON schema from TypeScript types",
5
5
  "author": "Andrew Berdnikov <tsofistgudmen@gmail.com>",
6
6
  "license": "LGPL-3.0",
@@ -38,11 +38,11 @@
38
38
  "@types/node": "^20.19.0",
39
39
  "@types/supertest": "^6.0.3",
40
40
  "@types/ungap__structured-clone": "^1.2.0",
41
- "jest": "~30.0.5",
41
+ "jest": "~30.1.2",
42
42
  "rimraf": "^6.0.1",
43
43
  "supertest": "^7.1.4",
44
- "ts-jest": "~29.4.0",
45
- "typescript": "~5.8.3"
44
+ "ts-jest": "~29.4.1",
45
+ "typescript": "~5.9.2"
46
46
  },
47
47
  "publishConfig": {
48
48
  "registry": "https://registry.npmjs.org/",