@tsofist/schema-forge 4.2.3 → 5.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 (37) hide show
  1. package/lib/dbml-generator/converter.d.ts +1 -2
  2. package/lib/dbml-generator/converter.d.ts.map +1 -1
  3. package/lib/dbml-generator/converter.js +2 -6
  4. package/lib/dbml-generator/types.d.ts +1 -6
  5. package/lib/dbml-generator/types.d.ts.map +1 -1
  6. package/lib/schema-dereference/dereference-shallow.d.ts +11 -0
  7. package/lib/schema-dereference/dereference-shallow.d.ts.map +1 -0
  8. package/lib/schema-dereference/dereference-shallow.js +63 -0
  9. package/lib/schema-dereference/dereference.d.ts +1 -1
  10. package/lib/schema-generator/forge.d.ts.map +1 -1
  11. package/lib/schema-generator/forge.js +10 -1
  12. package/lib/schema-generator/forge.spec.js +23 -10
  13. package/lib/schema-generator/generate-drafts.d.ts +1 -1
  14. package/lib/schema-generator/generate-drafts.d.ts.map +1 -1
  15. package/lib/schema-generator/generate-drafts.js +35 -4
  16. package/lib/schema-generator/generate-schema.d.ts.map +1 -1
  17. package/lib/schema-generator/generate-schema.js +48 -15
  18. package/lib/schema-generator/helpers-tsc.d.ts.map +1 -1
  19. package/lib/schema-generator/helpers-tsc.js +3 -1
  20. package/lib/schema-generator/kw.types.d.ts +15 -0
  21. package/lib/schema-generator/kw.types.d.ts.map +1 -0
  22. package/lib/schema-generator/kw.types.js +2 -0
  23. package/lib/schema-generator/patch-enum-node-parser.d.ts.map +1 -1
  24. package/lib/schema-generator/patch-enum-node-parser.js +12 -1
  25. package/lib/schema-generator/sort-contents.d.ts +4 -0
  26. package/lib/schema-generator/sort-contents.d.ts.map +1 -0
  27. package/lib/schema-generator/sort-contents.js +108 -0
  28. package/lib/schema-generator/types.d.ts +1 -1
  29. package/lib/schema-registry/kw-common.d.ts.map +1 -1
  30. package/lib/schema-registry/kw-common.js +15 -0
  31. package/lib/types.d.ts +32 -10
  32. package/lib/types.d.ts.map +1 -1
  33. package/lib/types.js +7 -0
  34. package/package.json +3 -3
  35. package/lib/schema-generator/sort-properties.d.ts +0 -3
  36. package/lib/schema-generator/sort-properties.d.ts.map +0 -1
  37. package/lib/schema-generator/sort-properties.js +0 -39
@@ -1,5 +1,4 @@
1
1
  import type { ExportFormatOption } from '@dbml/core/types/export/ModelExporter';
2
- export declare function convertDBMLToDatabaseModel(source: string): import("@dbml/core/types/model_structure/database").default;
3
- export declare function convertDBMLToJSON(source: string): import("@dbml/core/types/model_structure/database").RawDatabase;
2
+ export declare function convertDBMLToDatabaseModel(dbmlStringSpec: string): import("@dbml/core/types/model_structure/database").default;
4
3
  export declare function convertDBMLToSQL(source: string, format?: ExportFormatOption): string;
5
4
  //# sourceMappingURL=converter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"converter.d.ts","sourceRoot":"","sources":["../../src/dbml-generator/converter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAEhF,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,MAAM,+DAExD;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,mEAE/C;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,GAAE,kBAA+B,UAEvF"}
1
+ {"version":3,"file":"converter.d.ts","sourceRoot":"","sources":["../../src/dbml-generator/converter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAEhF,wBAAgB,0BAA0B,CAAC,cAAc,EAAE,MAAM,+DAEhE;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,GAAE,kBAA+B,UAEvF"}
@@ -1,14 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.convertDBMLToDatabaseModel = convertDBMLToDatabaseModel;
4
- exports.convertDBMLToJSON = convertDBMLToJSON;
5
4
  exports.convertDBMLToSQL = convertDBMLToSQL;
6
5
  const core_1 = require("@dbml/core");
7
- function convertDBMLToDatabaseModel(source) {
8
- return core_1.Parser.parse(source, 'json');
9
- }
10
- function convertDBMLToJSON(source) {
11
- return core_1.Parser.parseDBMLToJSONv2(source);
6
+ function convertDBMLToDatabaseModel(dbmlStringSpec) {
7
+ return core_1.Parser.parse(dbmlStringSpec, 'dbmlv2');
12
8
  }
13
9
  function convertDBMLToSQL(source, format = 'postgres') {
14
10
  return core_1.exporter.export(source, format);
@@ -1,4 +1,4 @@
1
- import type { ArrayMay, HexString, PRec } from '@tsofist/stem';
1
+ import type { ArrayMay, HexString } from '@tsofist/stem';
2
2
  import type { SchemaDefinitionInfoForType } from '../definition-info/types';
3
3
  /**
4
4
  * DBML Project Source
@@ -145,9 +145,4 @@ export type DBMLColumnOptions = {
145
145
  type?: DBMLColumnType;
146
146
  };
147
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
- ]>;
153
148
  //# 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,IAAI,EAAE,MAAM,eAAe,CAAC;AAC/D,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,C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G;IACH,OAAO,CAAC,EAAE;QACN,CAAC,KAAK,EAAE,MAAM,GAAG,mBAAmB,CAAC,IAAI,CAAC,CAAC;KAC9C,CAAC;IACF;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,QAAQ,CAAC,EAAE;QAAE,WAAW,EAAE,SAAS,CAAA;KAAE,CAAC;CACzC,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG,iBAAiB,GAAG,MAAM,CAAC;AAE9D,MAAM,MAAM,iBAAiB,GAAG;IAC5B;;;;OAIG;IACH,EAAE,CAAC,EAAE,OAAO,CAAC;IACb;;;;OAIG;IACH,IAAI,CAAC,EAAE,cAAc,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,OAAO,GAAG,MAAM,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { JSONSchema7 } from 'json-schema';
2
+ /**
3
+ * Shallow dereference a JSON Schema by resolving only the top-level `$ref` pointer
4
+ * for each definition.
5
+ *
6
+ * @param schema Root JSON Schema to dereference
7
+ * @param soloRefs If true, only dereference `$ref` entries that appear once in the schema
8
+ * @returns New (shallow copy) schema with top-level `$ref` pointers resolved.
9
+ */
10
+ export declare function shallowDereferenceSchema(schema: JSONSchema7, soloRefs?: boolean): JSONSchema7;
11
+ //# sourceMappingURL=dereference-shallow.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dereference-shallow.d.ts","sourceRoot":"","sources":["../../src/schema-dereference/dereference-shallow.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,WAAW,EAAE,QAAQ,UAAO,GAAG,WAAW,CA+B1F"}
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.shallowDereferenceSchema = shallowDereferenceSchema;
4
+ const error_1 = require("@tsofist/stem/lib/error");
5
+ const entries_1 = require("@tsofist/stem/lib/object/entries");
6
+ /**
7
+ * Shallow dereference a JSON Schema by resolving only the top-level `$ref` pointer
8
+ * for each definition.
9
+ *
10
+ * @param schema Root JSON Schema to dereference
11
+ * @param soloRefs If true, only dereference `$ref` entries that appear once in the schema
12
+ * @returns New (shallow copy) schema with top-level `$ref` pointers resolved.
13
+ */
14
+ function shallowDereferenceSchema(schema, soloRefs = true) {
15
+ const result = { ...schema };
16
+ let defs;
17
+ if (result.$defs) {
18
+ defs = result.$defs = { ...result.$defs };
19
+ }
20
+ else if (result.definitions) {
21
+ defs = result.definitions = { ...result.definitions };
22
+ }
23
+ else {
24
+ return result;
25
+ }
26
+ const usedRefs = new Map();
27
+ eachReferencedDefinition(defs, ({ $ref }) => {
28
+ const count = (usedRefs.get($ref) || 0) + 1;
29
+ usedRefs.set($ref, count);
30
+ });
31
+ eachReferencedDefinition(defs, (def, name) => {
32
+ const seen = usedRefs.get(def.$ref);
33
+ if (!soloRefs || seen === 1) {
34
+ const resolved = resolveRef(def.$ref, schema);
35
+ if (!resolved) {
36
+ (0, error_1.raise)(`Failed to dereference $ref: ${def.$ref} during shallow dereference`);
37
+ }
38
+ defs[name] = resolved;
39
+ }
40
+ });
41
+ return result;
42
+ }
43
+ function eachReferencedDefinition(defs, cb) {
44
+ for (const [nameRaw, raw] of (0, entries_1.entries)(defs)) {
45
+ const def = typeof raw === 'object' && raw !== null ? raw : undefined;
46
+ if (def && def.$ref && def.$ref.startsWith('#/') && Object.keys(def).length === 1) {
47
+ cb(def, nameRaw);
48
+ }
49
+ }
50
+ }
51
+ function resolveRef(ref, root) {
52
+ const path = ref.slice(2).split('/').map(decodeURIComponent);
53
+ let current = root;
54
+ for (const segment of path) {
55
+ if (current && typeof current === 'object' && segment in current) {
56
+ current = current[segment];
57
+ }
58
+ else {
59
+ return undefined;
60
+ }
61
+ }
62
+ return current;
63
+ }
@@ -1,7 +1,7 @@
1
1
  import type { JSONSchema7 } from 'json-schema';
2
2
  import type { SchemaForgeDereferenceOptions } from './types';
3
3
  /**
4
- * Dereference a JSON Schema by resolving all (relative) `$ref` pointers.
4
+ * Recursively dereference a JSON Schema by resolving all relative `$ref` pointers.
5
5
  *
6
6
  * @returns new schema with no `$ref` pointers
7
7
  */
@@ -1 +1 @@
1
- {"version":3,"file":"forge.d.ts","sourceRoot":"","sources":["../../src/schema-generator/forge.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAER,kBAAkB,EAClB,iBAAiB,EAEpB,MAAM,UAAU,CAAC;AAIlB,wBAAsB,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAuHzF"}
1
+ {"version":3,"file":"forge.d.ts","sourceRoot":"","sources":["../../src/schema-generator/forge.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAER,kBAAkB,EAClB,iBAAiB,EAEpB,MAAM,UAAU,CAAC;AAKlB,wBAAsB,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAgIzF"}
@@ -7,8 +7,11 @@ const as_array_1 = require("@tsofist/stem/lib/as-array");
7
7
  const error_1 = require("@tsofist/stem/lib/error");
8
8
  const noop_1 = require("@tsofist/stem/lib/noop");
9
9
  const random_1 = require("@tsofist/stem/lib/string/random");
10
+ const ts_json_schema_generator_1 = require("ts-json-schema-generator");
10
11
  const artefacts_policy_1 = require("../artefacts-policy");
11
12
  const ref_1 = require("../definition-info/ref");
13
+ const dereference_shallow_1 = require("../schema-dereference/dereference-shallow");
14
+ const format_error_1 = require("./format-error");
12
15
  const generate_drafts_1 = require("./generate-drafts");
13
16
  const generate_schema_1 = require("./generate-schema");
14
17
  async function forgeSchema(options) {
@@ -60,7 +63,7 @@ async function forgeSchema(options) {
60
63
  delete schema.hash;
61
64
  }
62
65
  }
63
- const content = JSON.stringify(schema, null, 2);
66
+ const content = JSON.stringify(options.shallowDeref ? (0, dereference_shallow_1.shallowDereferenceSchema)(schema) : schema, null, 2);
64
67
  await (0, promises_1.writeFile)(options.outputSchemaFile, content, { encoding: 'utf8' });
65
68
  }
66
69
  if (options.outputSchemaMetadataFile) {
@@ -94,6 +97,12 @@ async function forgeSchema(options) {
94
97
  });
95
98
  }
96
99
  }
100
+ catch (e) {
101
+ if (e instanceof ts_json_schema_generator_1.BuildError) {
102
+ console.error('[forgeSchema: build error]\n', (0, format_error_1.formatForgeSchemaError)(e));
103
+ }
104
+ throw e;
105
+ }
97
106
  finally {
98
107
  if (!artefacts_policy_1.KEEP_GEN_ARTEFACTS) {
99
108
  await Promise.all(files.map((fileName) => (0, promises_1.unlink)(fileName).catch(noop_1.noop)));
@@ -443,23 +443,23 @@ describe('generator for a5', () => {
443
443
  },
444
444
  },
445
445
  required: [
446
- 'vals',
447
- 'name0',
448
- 'name1',
449
- 'num0',
450
- 'num1',
451
- 'variadic',
452
- 'variadic1',
453
- 'variadicList',
454
- 'variadicList1',
455
446
  'abnormalNames',
456
447
  'indexedField1',
457
448
  'indexedField2',
458
449
  'indexedField3',
459
450
  'indexedField4',
451
+ 'name0',
452
+ 'name1',
453
+ 'num0',
454
+ 'num1',
460
455
  'ref0',
461
456
  'ref1',
462
457
  'ref2',
458
+ 'vals',
459
+ 'variadic',
460
+ 'variadic1',
461
+ 'variadicList',
462
+ 'variadicList1',
463
463
  ],
464
464
  additionalProperties: false,
465
465
  dbEntity: 'cmn.some',
@@ -585,7 +585,7 @@ describe('generator for a3', () => {
585
585
  // expect(props.maxItems).toBeUndefined();
586
586
  // }
587
587
  });
588
- it('extends should works', () => {
588
+ it('should works with extends: interface', () => {
589
589
  const props = forgeSchemaResult.schema.definitions?.BAPI__APIInterface?.properties;
590
590
  expect(props).toBeTruthy();
591
591
  expect((0, keys_1.keysOf)(props)).toStrictEqual([
@@ -605,6 +605,19 @@ describe('generator for a3', () => {
605
605
  'methodY',
606
606
  ]);
607
607
  });
608
+ // it('should works with extends: type w/ generics', () => {
609
+ // const props = forgeSchemaResult!.schema.definitions?.APIFromBase__APIInterface?.properties;
610
+ // expect(props).toBeTruthy();
611
+ // expect(keysOf(props)).toStrictEqual(['doSomethingAndReturnR', 'doSomethingElse']);
612
+ // });
613
+ //
614
+ // it('should works with extends: type w/o own members', () => {
615
+ // const props =
616
+ // forgeSchemaResult!.schema.definitions?.APIFromBaseExtendOnly__APIInterface?.properties;
617
+ // expect(props).toBeTruthy();
618
+ // // console.log(JSON.stringify(forgeSchemaResult!.schema, null, 2));
619
+ // expect(keysOf(props)).toStrictEqual(['doSomethingAndReturnR']);
620
+ // });
608
621
  });
609
622
  describe('generator for a2', () => {
610
623
  const outputSchemaFile = './a2.generated.schema.tmp.json';
@@ -1,5 +1,5 @@
1
1
  import { type CompletedConfig } from 'ts-json-schema-generator/dist/src/Config';
2
- import { ForgeSchemaOptions } from '../types';
2
+ import type { ForgeSchemaOptions } from '../types';
3
3
  /**
4
4
  * @internal
5
5
  */
@@ -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;;;;;GAkCjE;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":"AAMA,OAAO,EAAE,KAAK,eAAe,EAAkB,MAAM,0CAA0C,CAAC;AAsChG,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAWnD;;GAEG;AACH,wBAAsB,sBAAsB,CAAC,OAAO,EAAE,YAAY;;;;;GAkCjE;AA8YD,UAAU,YAAa,SAAQ,kBAAkB;IAC7C,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,MAAM,EAAE,CAAC;CAC5B"}
@@ -147,7 +147,25 @@ function processAPIInterfaceDeclaration(statement, context) {
147
147
  const interfaceGenericText = (0, helpers_tsc_1.readInterfaceGenericText)(statement);
148
148
  const interfaceDesc = (0, helpers_tsc_1.readJSDocDescription)(statement, allowUseFallbackDescription);
149
149
  const interfaceDeprecated = (0, typescript_1.getTextOfJSDocComment)((0, typescript_1.getJSDocDeprecatedTag)(statement)?.comment);
150
- function onSignature(method, memberName, memberDescription, deprecated) {
150
+ const interfaceSymbol = context.typeChecker.getSymbolAtLocation(statement.name);
151
+ const interfaceType = context.typeChecker.getDeclaredTypeOfSymbol(interfaceSymbol);
152
+ const properties = {};
153
+ for (const symbol of context.typeChecker.getPropertiesOfType(interfaceType)) {
154
+ for (const decl of symbol.declarations || []) {
155
+ if ((0, typescript_1.isMethodSignature)(decl) || (0, typescript_1.isPropertySignature)(decl) || (0, typescript_1.isFunctionTypeNode)(decl)) {
156
+ const name = (0, helpers_tsc_1.readNodeName)(decl);
157
+ if (name) {
158
+ if (properties[name]) {
159
+ // todo throw?
160
+ }
161
+ else {
162
+ properties[name] = symbol;
163
+ }
164
+ }
165
+ }
166
+ }
167
+ }
168
+ function onSignature(_property, method, memberName, memberDescription, deprecated) {
151
169
  const minArgsNum = countRequiredParams(method.parameters);
152
170
  const maxArgsNum = method.parameters.length;
153
171
  const argsNames = [];
@@ -167,6 +185,16 @@ function processAPIInterfaceDeclaration(statement, context) {
167
185
  })
168
186
  .join(', ');
169
187
  const resultTypeName = (0, helpers_tsc_1.readMemberTypeName)(method);
188
+ // todo
189
+ // {
190
+ // const pt = context.typeChecker.getTypeOfSymbolAtLocation(property, method);
191
+ // const sig = context.typeChecker.getSignaturesOfType(pt, SignatureKind.Call)[0];
192
+ // if (sig) {
193
+ // const rt = context.typeChecker.getReturnTypeOfSignature(sig);
194
+ // const rts = context.typeChecker.typeToString(rt, statement);
195
+ // resultTypeName = rts;
196
+ // }
197
+ // }
170
198
  const definitionNameArgs = (0, api_signature_1.buildAPIMethodArgsSDS)(interfaceName, memberName, legacy);
171
199
  const definitionNameResult = (0, api_signature_1.buildAPIMethodResultSDS)(interfaceName, memberName, legacy);
172
200
  const comment = `Method:${interfaceName}#${memberName}`;
@@ -207,14 +235,17 @@ function processAPIInterfaceDeclaration(statement, context) {
207
235
  if (isPrivate)
208
236
  return;
209
237
  const memberName = (0, helpers_tsc_1.readNodeName)(member);
238
+ const property = properties[memberName];
239
+ if (!property)
240
+ return;
210
241
  const memberDescription = (0, helpers_tsc_1.readJSDocDescription)(member, allowUseFallbackDescription);
211
242
  const deprecated = (0, typescript_1.getTextOfJSDocComment)((0, typescript_1.getJSDocDeprecatedTag)(member)?.comment);
212
243
  if ((0, typescript_1.isMethodSignature)(member)) {
213
- onSignature(member, memberName, memberDescription, deprecated);
244
+ onSignature(property, member, memberName, memberDescription, deprecated);
214
245
  }
215
246
  else if ((0, typescript_1.isPropertySignature)(member)) {
216
247
  if (member.type && (0, typescript_1.isFunctionTypeNode)(member.type)) {
217
- onSignature(member.type, memberName, memberDescription, deprecated);
248
+ onSignature(property, member.type, memberName, memberDescription, deprecated);
218
249
  }
219
250
  else {
220
251
  definitionsMetaList.push({
@@ -232,7 +263,7 @@ function processAPIInterfaceDeclaration(statement, context) {
232
263
  for (const type of clause.types) {
233
264
  const declaration = context.typeChecker.getTypeAtLocation(type).symbol?.declarations?.[0];
234
265
  if (declaration &&
235
- (0, typescript_1.isInterfaceDeclaration)(declaration) &&
266
+ ((0, typescript_1.isInterfaceDeclaration)(declaration) || (0, typescript_1.isTypeLiteralNode)(declaration)) &&
236
267
  declaration.members?.length) {
237
268
  for (const member of declaration.members) {
238
269
  onMember(member);
@@ -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;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,CAoGhG;AAgLD,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;AAQvC,OAAO,EAIH,eAAe,EAqBlB,MAAM,0BAA0B,CAAC;AAelC,OAAO,EAAwB,YAAY,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAQlF;;GAEG;AACH,wBAAsB,0BAA0B,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,YAAY,CAAC,CAoGhG;AA2MD,UAAU,eAAgB,SAAQ,kBAAkB;IAChD,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/B,2BAA2B,EAAE,eAAe,CAAC;CAChD"}
@@ -5,6 +5,7 @@ exports.generateSchemaByDraftTypes = generateSchemaByDraftTypes;
5
5
  const tslib_1 = require("tslib");
6
6
  require("./extended-annotations-reader");
7
7
  const error_1 = require("@tsofist/stem/lib/error");
8
+ const is_empty_1 = require("@tsofist/stem/lib/object/is-empty");
8
9
  const value_in_1 = require("@tsofist/stem/lib/value-in");
9
10
  const ajv_1 = require("ajv");
10
11
  const jsonpath_plus_1 = require("jsonpath-plus");
@@ -13,7 +14,7 @@ const typescript_1 = require("typescript");
13
14
  const helpers_tsc_1 = require("./helpers-tsc");
14
15
  const patch_enum_node_parser_1 = require("./patch-enum-node-parser");
15
16
  const shrink_definition_name_1 = require("./shrink-definition-name");
16
- const sort_properties_1 = require("./sort-properties");
17
+ const sort_contents_1 = require("./sort-contents");
17
18
  const types_1 = require("./types");
18
19
  /**
19
20
  * @internal
@@ -90,8 +91,8 @@ async function generateSchemaByDraftTypes(options) {
90
91
  }
91
92
  }
92
93
  result.definitions = Object.fromEntries(Object.entries((defs || {})).sort());
93
- if (options.sortObjectProperties)
94
- (0, sort_properties_1.sortSchemaProperties)(result.definitions);
94
+ if (options.sortContents ?? true)
95
+ (0, sort_contents_1.sortSchemaContents)(result.definitions, options.sortContents);
95
96
  await new ajv_1.default({
96
97
  strict: true,
97
98
  allErrors: true,
@@ -115,29 +116,61 @@ class EnumTypeFormatterEx extends ts_json_schema_generator_1.EnumTypeFormatter {
115
116
  getDefinition(type) {
116
117
  const id = type.getId();
117
118
  const inherited = super.getDefinition(type);
118
- if (inherited?.enum) {
119
+ const isMember = 'const' in inherited;
120
+ if (inherited && (inherited.enum || inherited.const)) {
119
121
  let count = 0;
120
- const annotations = {};
121
- for (const value of inherited.enum) {
122
+ const enumAnnotation = {};
123
+ const enumMember = {};
124
+ const append = (value) => {
122
125
  if ((0, value_in_1.valueIn)(typeof value, ['string', 'number'])) {
123
126
  const v = value;
124
127
  const key = `${id}.${v}`;
125
128
  const doc = this.metaMap.get(key);
126
129
  if (doc) {
127
130
  count++;
128
- const ann = (annotations[doc.title] = [doc.value]);
129
- if (doc.description)
130
- ann.push(doc.description);
131
- if (doc.comment)
132
- ann.push(doc.comment);
131
+ if (isMember) {
132
+ enumMember.title = doc.title;
133
+ if (doc.description)
134
+ enumMember.note = doc.description;
135
+ if (doc.comment)
136
+ enumMember.comment = doc.comment;
137
+ if (doc.typeName)
138
+ enumMember.enum = doc.typeName;
139
+ }
140
+ else {
141
+ const rec = (enumAnnotation[doc.title] = [doc.value]);
142
+ if (doc.description)
143
+ rec.push(doc.description);
144
+ if (doc.comment)
145
+ rec.push(doc.comment);
146
+ if (isMember && doc.typeName) {
147
+ enumAnnotation[''] = [doc.typeName];
148
+ }
149
+ }
133
150
  }
134
151
  }
152
+ };
153
+ if (inherited.const) {
154
+ append(inherited.const);
155
+ }
156
+ else if (inherited.enum) {
157
+ for (const value of inherited.enum) {
158
+ append(value);
159
+ }
135
160
  }
136
161
  if (count > 0) {
137
- return {
138
- ...inherited,
139
- enumAnnotation: annotations,
140
- };
162
+ if (isMember && !(0, is_empty_1.isEmptyObject)(enumMember)) {
163
+ return {
164
+ ...inherited,
165
+ enumMember,
166
+ };
167
+ }
168
+ else if (!isMember && !(0, is_empty_1.isEmptyObject)(enumAnnotation)) {
169
+ return {
170
+ ...inherited,
171
+ enumAnnotation,
172
+ };
173
+ }
141
174
  }
142
175
  }
143
176
  return inherited;
@@ -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,iBAAiB,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAcjF;AAED,wBAAgB,oBAAoB,CAChC,IAAI,EAAE,IAAI,EACV,2BAA2B,EAAE,OAAO,GAAG,SAAS,EAChD,qCAAqC,UAAO,GAC7C,MAAM,GAAG,SAAS,CAsCp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B,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"}
@@ -66,7 +66,9 @@ function readJSDocDescription(node, allowUseFallbackDescription, allowUseFallbac
66
66
  }
67
67
  function readNodeName(node) {
68
68
  if ('name' in node && !!node.name) {
69
- return node.name.escapedText + '';
69
+ const v = node.name;
70
+ if (v != null && v.escapedText)
71
+ return v.escapedText;
70
72
  }
71
73
  return undefined;
72
74
  }
@@ -0,0 +1,15 @@
1
+ import type { PRec } from '@tsofist/stem';
2
+ export type SGEnumAnnotationOptions = PRec<[
3
+ /** 0 */ value: string | number,
4
+ /** 1 */ note?: string,
5
+ /** 2 */ comment?: string
6
+ ]>;
7
+ export type SGEnumMemberOptions = {
8
+ /** Enum name */
9
+ enum: string;
10
+ /** Title (Key) */
11
+ title: string;
12
+ note?: string;
13
+ comment?: string;
14
+ };
15
+ //# sourceMappingURL=kw.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kw.types.d.ts","sourceRoot":"","sources":["../../src/schema-generator/kw.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAE1C,MAAM,MAAM,uBAAuB,GAAG,IAAI,CACtC;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;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAC9B,gBAAgB;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,kBAAkB;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +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"}
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,aAmFnD;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"}
@@ -30,7 +30,18 @@ function patchEnumNodeParser(root, checker, meta, allowUseFallbackDescription) {
30
30
  arguments);
31
31
  const resultId = result.getId();
32
32
  if ((0, typescript_1.isEnumMember)(node)) {
33
- // todo EnumMember!
33
+ const memberValue = checker.getConstantValue(node);
34
+ const memberName = (0, helpers_tsc_1.readNodeName)(node);
35
+ const metaKey = `${resultId}.${String(memberValue)}`;
36
+ const description = (0, helpers_tsc_1.readJSDocDescription)(node, allowUseFallbackDescription);
37
+ const comment = (0, helpers_tsc_1.readJSDocTagValue)(node, 'comment');
38
+ meta.set(metaKey, {
39
+ typeName: (0, helpers_tsc_1.readNodeName)(node.parent),
40
+ title: memberName,
41
+ value: memberValue,
42
+ description,
43
+ comment,
44
+ });
34
45
  return result;
35
46
  }
36
47
  else {
@@ -0,0 +1,4 @@
1
+ import type { JSONSchema7, JSONSchema7Object } from 'json-schema';
2
+ import { SchemaForgeSortableContentSet } from '../types';
3
+ export declare function sortSchemaContents<T extends JSONSchema7Object | JSONSchema7>(schema: T, contents?: boolean | SchemaForgeSortableContentSet): T;
4
+ //# sourceMappingURL=sort-contents.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sort-contents.d.ts","sourceRoot":"","sources":["../../src/schema-generator/sort-contents.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAuB,MAAM,aAAa,CAAC;AACvF,OAAO,EAAsC,6BAA6B,EAAE,MAAM,UAAU,CAAC;AAG7F,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,iBAAiB,GAAG,WAAW,EACxE,MAAM,EAAE,CAAC,EACT,QAAQ,GAAE,OAAO,GAAG,6BAAkE,GACvF,CAAC,CAsEH"}
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sortSchemaContents = sortSchemaContents;
4
+ const is_primitive_1 = require("@tsofist/stem/lib/is-primitive");
5
+ const entries_1 = require("@tsofist/stem/lib/object/entries");
6
+ const is_empty_1 = require("@tsofist/stem/lib/object/is-empty");
7
+ const omit_1 = require("@tsofist/stem/lib/object/omit");
8
+ const compare_1 = require("@tsofist/stem/lib/string/compare");
9
+ const types_1 = require("../types");
10
+ const types_2 = require("./types");
11
+ function sortSchemaContents(schema, contents = types_1.SchemaForgeDefaultSortableContents) {
12
+ contents =
13
+ contents === true ? types_1.SchemaForgeDefaultSortableContents : contents == false ? [] : contents;
14
+ const stack = [];
15
+ const process = (item) => {
16
+ if ((0, is_primitive_1.isPrimitive)(item))
17
+ return;
18
+ if (Array.isArray(item)) {
19
+ stack.push(...item);
20
+ }
21
+ else {
22
+ const processedProps = new Set();
23
+ const hr = hasRequired(item);
24
+ const hp = hasProperties(item);
25
+ if (hr || hp) {
26
+ if (hr) {
27
+ if (contents.includes('required')) {
28
+ item.required.sort(compare_1.compareStringsAsc);
29
+ }
30
+ processedProps.add('required');
31
+ }
32
+ if (hp) {
33
+ if (contents.includes('properties')) {
34
+ item.properties = Object.fromEntries(Object.entries(item.properties).sort(entitiesComparatorAsk));
35
+ }
36
+ processedProps.add('properties');
37
+ }
38
+ }
39
+ else {
40
+ if (hasEnum(item)) {
41
+ if (contents.includes('enum')) {
42
+ item.enum.sort(indexComparatorAsk);
43
+ }
44
+ processedProps.add('enum');
45
+ }
46
+ else if (hasAnyOf(item)) {
47
+ if (contents.includes('anyOf')) {
48
+ item.anyOf.sort(nullTypeFirstComparator);
49
+ }
50
+ processedProps.add('anyOf');
51
+ }
52
+ else if (hasOneOf(item)) {
53
+ if (contents.includes('oneOf')) {
54
+ item.oneOf.sort(nullTypeFirstComparator);
55
+ }
56
+ processedProps.add('oneOf');
57
+ }
58
+ }
59
+ {
60
+ const saved = { ...item };
61
+ for (const k in item)
62
+ delete item[k];
63
+ for (const [k, v] of (0, entries_1.entries)(saved).sort(entitiesComparatorAsk)) {
64
+ // @ts-expect-error It's OK
65
+ item[k] = v;
66
+ }
67
+ }
68
+ stack.push(...Object.values((0, omit_1.omitProps)(item, [...processedProps, ...types_2.SFG_EXTRA_TAGS])));
69
+ }
70
+ };
71
+ process(schema);
72
+ while (stack.length) {
73
+ process(stack.pop());
74
+ }
75
+ return schema;
76
+ }
77
+ function entitiesComparatorAsk([a], [b]) {
78
+ return (0, compare_1.compareStringsAsc)(a, b);
79
+ }
80
+ function indexComparatorAsk(a, b) {
81
+ return a === b ? 0 : a > b ? 1 : -1;
82
+ }
83
+ function nullTypeFirstComparator(a, b) {
84
+ const an = a.type === 'null';
85
+ const bn = b.type === 'null';
86
+ if (an && !bn)
87
+ return -1;
88
+ if (!an && bn)
89
+ return 1;
90
+ return 0;
91
+ }
92
+ function hasProperties(target) {
93
+ return ('properties' in target &&
94
+ typeof target.properties === 'object' &&
95
+ !(0, is_empty_1.isEmptyObject)(target.properties));
96
+ }
97
+ function hasRequired(target) {
98
+ return 'required' in target && Array.isArray(target.required) && target.required.length > 0;
99
+ }
100
+ function hasEnum(target) {
101
+ return 'enum' in target && Array.isArray(target.enum) && target.enum.length > 0;
102
+ }
103
+ function hasAnyOf(target) {
104
+ return 'anyOf' in target && Array.isArray(target.anyOf) && target.anyOf.length > 0;
105
+ }
106
+ function hasOneOf(target) {
107
+ return 'oneOf' in target && Array.isArray(target.oneOf) && target.oneOf.length > 0;
108
+ }
@@ -5,7 +5,7 @@ export declare const SFG_CONFIG_DEFAULTS: {
5
5
  readonly discriminatorType: undefined;
6
6
  readonly encodeRefs: false;
7
7
  readonly expose: "export";
8
- readonly extraTags: ("spec" | "hash" | "dbEntity" | "dbFK" | "dbColumn" | "dbIndex" | "dbEnum" | "enumAnnotation" | "version" | "repository" | "apiInterface" | "apiProperty" | "apiMethod" | "apiMember" | "enumMember" | "faker")[];
8
+ readonly extraTags: ("spec" | "hash" | "dbEntity" | "dbFK" | "dbColumn" | "dbIndex" | "dbEnum" | "enumAnnotation" | "enumMember" | "version" | "repository" | "apiInterface" | "apiProperty" | "apiMethod" | "apiMember" | "faker")[];
9
9
  readonly functions: "hide";
10
10
  readonly markdownDescription: false;
11
11
  readonly skipTypeCheck: false;
@@ -1 +1 @@
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;AAO7C,eAAO,MAAM,iBAAiB,EAAE,SAAS,iBAAiB,EA2FtD,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;AAO7C,eAAO,MAAM,iBAAiB,EAAE,SAAS,iBAAiB,EA0GtD,CAAC"}
@@ -61,6 +61,21 @@ exports.SFRCommonKeywords = [
61
61
  },
62
62
  },
63
63
  },
64
+ {
65
+ keyword: 'enumMember',
66
+ dependencies: ['const'],
67
+ metaSchema: {
68
+ type: 'object',
69
+ properties: {
70
+ enum: { type: 'string' },
71
+ title: { type: 'string', pattern: NP_ENUM_KEY },
72
+ note: { type: 'string' },
73
+ comment: { type: 'string' },
74
+ },
75
+ required: ['enum', 'title'],
76
+ additionalProperties: false,
77
+ },
78
+ },
64
79
  {
65
80
  keyword: 'faker',
66
81
  metaSchema: {
package/lib/types.d.ts CHANGED
@@ -2,7 +2,8 @@ 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 { DBMLColumnOptions, DBMLEntityOptionsDef, DBMLEnumAnnotationOptions, DBMLEnumOptionsDef, DBMLForeignKeyOptions, DBMLIndexOptionsDef } from './dbml-generator/types';
5
+ import { DBMLColumnOptions, DBMLEntityOptionsDef, DBMLEnumOptionsDef, DBMLForeignKeyOptions, DBMLIndexOptionsDef } from './dbml-generator/types';
6
+ import { SGEnumAnnotationOptions, SGEnumMemberOptions } from './schema-generator/kw.types';
6
7
  export interface ForgeSchemaOptions {
7
8
  /**
8
9
  * Generate schema definitions for public types only
@@ -83,16 +84,33 @@ export interface ForgeSchemaOptions {
83
84
  readonly outputSchemaMetadataFile?: string;
84
85
  readonly discriminatorType?: DiscriminatorType;
85
86
  /**
86
- * Determines whether to sort the properties of object schemas in alphabetical order.
87
- * If set to `true`, the tool will sort both the fields in the `properties` section
88
- * and the field names in the `required` array for object-schema definitions.
89
- * Sorting can improve readability and consistency,
90
- * but may affect the order in which properties appear in generated outputs.
91
- * Applicable only to schemas of type `object`.
87
+ * Determines whether to sort the contents of the schema.
88
+ * If set to `true`, the tool will sort certain parts of the schema in alphabetical order.
89
+ * Sorting can significantly improve readability and consistency
90
+ * of the data across iterations of updates.
92
91
  *
92
+ * The following are sorted:
93
+ * - `properties` (optional)
94
+ * - `required`
95
+ * - `enum`
96
+ * - `anyOf` (type=null is always first)
97
+ * - `oneOf` (type=null is always first)
98
+ * - `definitions` / `$defs`
99
+ *
100
+ * @default true
101
+ */
102
+ readonly sortContents?: boolean | SchemaForgeSortableContentSet;
103
+ /**
104
+ * If true, the top-level `$ref` pointers for each definition will be resolved.
105
+ * This improves schema readability by reducing the number of references
106
+ * while still keeping the schema relatively compact.
107
+ * Note: only references used once will be dereferenced.
108
+ *
109
+ * @see shallowDereferenceSchema
110
+ * @see dereferenceSchema
93
111
  * @default false
94
112
  */
95
- readonly sortObjectProperties?: boolean;
113
+ readonly shallowDeref?: boolean;
96
114
  /**
97
115
  * If you want to shrink the schema definition names,
98
116
  * you have to provide a replacement function.
@@ -146,7 +164,7 @@ export type ForgedSchema = Reintroduce<Schema, Pick<ForgedSchemaDefinition, 'see
146
164
  export type ForgedEntitySchema = Schema & Pick<ForgedSchemaDefinition, 'see' | 'spec' | 'dbEntity'> & {
147
165
  properties?: Rec<ForgedEntitySchema>;
148
166
  };
149
- export type ForgedPropertySchema = Schema & Pick<ForgedSchemaDefinition, 'dbFK' | 'dbColumn' | 'dbIndex' | 'dbEnum' | 'enumAnnotation'>;
167
+ export type ForgedPropertySchema = Schema & Pick<ForgedSchemaDefinition, 'dbFK' | 'dbColumn' | 'dbIndex' | 'dbEnum' | 'enumAnnotation' | 'enumMember'>;
150
168
  export type ForgedSchemaDefinition = Schema & {
151
169
  see?: (string | [ref: string, title: string])[];
152
170
  spec?: string;
@@ -154,7 +172,8 @@ export type ForgedSchemaDefinition = Schema & {
154
172
  dbColumn?: DBMLColumnOptions;
155
173
  dbIndex?: DBMLIndexOptionsDef;
156
174
  dbEnum?: DBMLEnumOptionsDef;
157
- enumAnnotation?: DBMLEnumAnnotationOptions;
175
+ enumAnnotation?: SGEnumAnnotationOptions;
176
+ enumMember?: SGEnumMemberOptions;
158
177
  dbEntity?: DBMLEntityOptionsDef;
159
178
  properties?: PRec<ForgedEntitySchema>;
160
179
  };
@@ -179,6 +198,9 @@ export interface SchemaForgeValidationResult {
179
198
  }
180
199
  export type SchemaForgeValidationFunction<T = unknown> = ValidateFunction<T>;
181
200
  export type SchemaForgeValidationReport = ErrorObject[];
201
+ export type SchemaForgeSortableContents = 'properties' | 'required' | 'enum' | 'anyOf' | 'oneOf';
202
+ export type SchemaForgeSortableContentSet = SchemaForgeSortableContents[];
203
+ export declare const SchemaForgeDefaultSortableContents: ["required", "enum", "anyOf", "oneOf"];
182
204
  type TypeExposeKind = Config['expose'];
183
205
  type DiscriminatorType = Config['discriminatorType'];
184
206
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAA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BAAwB,EAAE,CAAC;IAC1C,uBAAuB,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3C,0BAA0B,EAAE,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;CACxE;AAED;;;;;;GAMG;AACH,MAAM,MAAM,wBAAwB,GAAG,EAAE,GAAG,GAAG,MAAM,iBAAiB,MAAM,EAAE,CAAC;AAE/E,MAAM,WAAW,2BAA2B;IACxC,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,QAAQ,CAAC,2BAA2B,CAAC,CAAC;IAC9C,UAAU,EAAE,CAAC,OAAO,CAAC,EAAE,iBAAiB,KAAK,MAAM,CAAC;CACvD;AAED,MAAM,MAAM,6BAA6B,CAAC,CAAC,GAAG,OAAO,IAAI,gBAAgB,CAAC,CAAC,CAAC,CAAC;AAC7E,MAAM,MAAM,2BAA2B,GAAG,WAAW,EAAE,CAAC;AACxD,MAAM,MAAM,2BAA2B,GAAG,YAAY,GAAG,UAAU,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC;AACjG,MAAM,MAAM,6BAA6B,GAAG,2BAA2B,EAAE,CAAC;AAE1E,eAAO,MAAM,kCAAkC,wCAKG,CAAC;AAEnD,KAAK,cAAc,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;AACvC,KAAK,iBAAiB,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAC"}
package/lib/types.js CHANGED
@@ -1,3 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SchemaForgeDefaultSortableContents = void 0;
3
4
  const ForgedSchemaDraft7Id = 'http://json-schema.org/draft-07/schema#';
5
+ exports.SchemaForgeDefaultSortableContents = [
6
+ 'required',
7
+ 'enum',
8
+ 'anyOf',
9
+ 'oneOf',
10
+ ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsofist/schema-forge",
3
- "version": "4.2.3",
3
+ "version": "5.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",
@@ -22,7 +22,7 @@
22
22
  "dependencies": {
23
23
  "@dbml/core": "~3.13.9",
24
24
  "@faker-js/faker": "^9.9.0",
25
- "@tsofist/stem": "^5.2.2",
25
+ "@tsofist/stem": "^5.4.0",
26
26
  "@ungap/structured-clone": "^1.3.0",
27
27
  "ajv": "^8.17.1",
28
28
  "ajv-formats": "^3.0.1",
@@ -38,7 +38,7 @@
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.1.2",
41
+ "jest": "~30.1.3",
42
42
  "rimraf": "^6.0.1",
43
43
  "supertest": "^7.1.4",
44
44
  "ts-jest": "~29.4.1",
@@ -1,3 +0,0 @@
1
- import type { JSONSchema7, JSONSchema7Object } from 'json-schema';
2
- export declare function sortSchemaProperties<T extends JSONSchema7Object | JSONSchema7>(schema: T): T;
3
- //# sourceMappingURL=sort-properties.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sort-properties.d.ts","sourceRoot":"","sources":["../../src/schema-generator/sort-properties.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAElE,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,iBAAiB,GAAG,WAAW,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,CAyC5F"}
@@ -1,39 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sortSchemaProperties = sortSchemaProperties;
4
- const is_empty_1 = require("@tsofist/stem/lib/object/is-empty");
5
- const compare_1 = require("@tsofist/stem/lib/string/compare");
6
- function sortSchemaProperties(schema) {
7
- const stack = [];
8
- const isTarget = (target) => {
9
- return (target != null &&
10
- typeof target === 'object' &&
11
- 'type' in target &&
12
- target.type === 'object' &&
13
- 'properties' in target &&
14
- typeof target.properties === 'object' &&
15
- !(0, is_empty_1.isEmptyObject)(target.properties));
16
- };
17
- const process = (item) => {
18
- if (!item)
19
- return;
20
- if (Array.isArray(item)) {
21
- stack.push(...item);
22
- }
23
- else {
24
- if (isTarget(item)) {
25
- item.properties = Object.fromEntries(Object.entries(item.properties).sort(([a], [b]) => (0, compare_1.compareStringsAsc)(a, b)));
26
- if (item.required?.length)
27
- item.required.sort(compare_1.compareStringsAsc);
28
- }
29
- if (typeof item === 'object') {
30
- stack.push(...Object.values(item));
31
- }
32
- }
33
- };
34
- process(schema);
35
- while (stack.length) {
36
- process(stack.pop());
37
- }
38
- return schema;
39
- }