@tsofist/schema-forge 3.4.2 → 3.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/dbml-generator/generator.d.ts +1 -1
- package/lib/dbml-generator/generator.d.ts.map +1 -1
- package/lib/dbml-generator/generator.js +6 -27
- package/lib/dbml-generator/types.d.ts +3 -0
- package/lib/dbml-generator/types.d.ts.map +1 -1
- package/lib/fake-generator/generator-host.js +1 -1
- package/lib/schema-generator/forge.d.ts +1 -1
- package/lib/schema-generator/forge.d.ts.map +1 -1
- package/lib/schema-generator/forge.js +2 -1
- package/lib/schema-generator/forge.spec.js +11 -7
- package/lib/schema-generator/generate-schema.d.ts +2 -3
- package/lib/schema-generator/generate-schema.d.ts.map +1 -1
- package/lib/schema-generator/generate-schema.js +7 -10
- package/lib/schema-generator/sort-properties.d.ts +2 -2
- package/lib/schema-generator/sort-properties.d.ts.map +1 -1
- package/lib/schema-generator/types.d.ts +1 -1
- package/lib/schema-generator/types.d.ts.map +1 -1
- package/lib/schema-generator/types.js +1 -0
- package/lib/schema-registry/kw-dbml.d.ts.map +1 -1
- package/lib/schema-registry/kw-dbml.js +7 -0
- package/lib/types.d.ts +26 -3
- package/lib/types.d.ts.map +1 -1
- package/lib/types.js +1 -0
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { SchemaForgeRegistry } from '../schema-registry/types';
|
|
2
|
-
import { DBMLGeneratorOptions, DBMLProjectScope } from './types';
|
|
2
|
+
import type { DBMLGeneratorOptions, DBMLProjectScope } from './types';
|
|
3
3
|
export declare function generateDBMLSpec(schemaRegistry: SchemaForgeRegistry, scopes: DBMLProjectScope[], options?: DBMLGeneratorOptions): string;
|
|
4
4
|
//# sourceMappingURL=generator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../src/dbml-generator/generator.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../src/dbml-generator/generator.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAEpE,OAAO,KAAK,EAER,oBAAoB,EAGpB,gBAAgB,EACnB,MAAM,SAAS,CAAC;AAEjB,wBAAgB,gBAAgB,CAC5B,cAAc,EAAE,mBAAmB,EACnC,MAAM,EAAE,gBAAgB,EAAE,EAC1B,OAAO,GAAE,oBAAyB,UAsGrC"}
|
|
@@ -95,6 +95,7 @@ function generateDBMLSpec(schemaRegistry, scopes, options = {}) {
|
|
|
95
95
|
function generateTable(info, options, dereferencedRootSchema) {
|
|
96
96
|
const includeNotes = options.includeNotes ?? false;
|
|
97
97
|
const entityTypeName = info.type;
|
|
98
|
+
const columnsOrder = options.columnsOrder || DefaultColumnsOrder;
|
|
98
99
|
const entitySchema = (dereferencedRootSchema.definitions || dereferencedRootSchema.$defs)?.[entityTypeName];
|
|
99
100
|
if (!entitySchema)
|
|
100
101
|
return;
|
|
@@ -104,7 +105,7 @@ function generateTable(info, options, dereferencedRootSchema) {
|
|
|
104
105
|
if (!tableName)
|
|
105
106
|
return;
|
|
106
107
|
const { properties, required } = listProperties(entitySchema);
|
|
107
|
-
const columns = generateColumns(properties, required, includeNotes, info.schemaId, tableName);
|
|
108
|
+
const columns = generateColumns(properties, required, includeNotes, info.schemaId, tableName, columnsOrder);
|
|
108
109
|
const indexes = generateIndexes(tableName, properties, readDBEntityIndexes(entitySchema), includeNotes, info.schemaId);
|
|
109
110
|
const text = new text_builder_1.TextBuilder();
|
|
110
111
|
if (entitySchema.$comment) {
|
|
@@ -128,12 +129,12 @@ function generateTable(info, options, dereferencedRootSchema) {
|
|
|
128
129
|
value: text.stringify(),
|
|
129
130
|
};
|
|
130
131
|
}
|
|
131
|
-
function generateColumns(properties, requiredFields, notes, schemaId, tableName) {
|
|
132
|
+
function generateColumns(properties, requiredFields, notes, schemaId, tableName, columnsOrder) {
|
|
132
133
|
const text = new text_builder_1.TextBuilder();
|
|
133
134
|
let count = 0;
|
|
134
135
|
for (const [key, property] of (0, entries_1.entries)(properties).sort(([keyA], [keyB]) => {
|
|
135
|
-
const indexA =
|
|
136
|
-
const indexB =
|
|
136
|
+
const indexA = columnsOrder.indexOf(keyA);
|
|
137
|
+
const indexB = columnsOrder.indexOf(keyB);
|
|
137
138
|
if (indexA === -1 && indexB === -1)
|
|
138
139
|
return 0;
|
|
139
140
|
else if (indexA === -1)
|
|
@@ -410,28 +411,6 @@ function listProperties(schema) {
|
|
|
410
411
|
};
|
|
411
412
|
}
|
|
412
413
|
const DefaultScopeName = 'Default';
|
|
413
|
-
|
|
414
|
-
const SortableFields = [
|
|
415
|
-
'uid',
|
|
416
|
-
'slug',
|
|
417
|
-
'system',
|
|
418
|
-
'created',
|
|
419
|
-
'updated',
|
|
420
|
-
'deleted',
|
|
421
|
-
'position',
|
|
422
|
-
'priority',
|
|
423
|
-
'creator',
|
|
424
|
-
'active',
|
|
425
|
-
'name',
|
|
426
|
-
'kind',
|
|
427
|
-
'validity',
|
|
428
|
-
'location',
|
|
429
|
-
'visual',
|
|
430
|
-
'integration',
|
|
431
|
-
'refs',
|
|
432
|
-
'seo',
|
|
433
|
-
'contacts',
|
|
434
|
-
'content',
|
|
435
|
-
];
|
|
414
|
+
const DefaultColumnsOrder = ['id', 'uid', 'slug', 'name'];
|
|
436
415
|
// todo escape notes!
|
|
437
416
|
// todo escape comments!
|
|
@@ -23,6 +23,7 @@ export interface DBMLProjectMeta {
|
|
|
23
23
|
export interface DBMLGeneratorOptions {
|
|
24
24
|
meta?: DBMLProjectMeta;
|
|
25
25
|
includeNotes?: boolean;
|
|
26
|
+
columnsOrder?: string[];
|
|
26
27
|
}
|
|
27
28
|
/**
|
|
28
29
|
* Database index type list.
|
|
@@ -83,6 +84,8 @@ export type DBMLIndexOptions = {
|
|
|
83
84
|
comment?: string;
|
|
84
85
|
};
|
|
85
86
|
export type DBMLIndexOptionsDef<B extends boolean = boolean> = ArrayMay<DBMLIndexOptions | string | B>;
|
|
87
|
+
export type DBMLForeignKeyOptionsDef = boolean;
|
|
88
|
+
export type DBMLForeignKeyOptions = DBMLForeignKeyOptionsDef;
|
|
86
89
|
/**
|
|
87
90
|
* Database entity options.
|
|
88
91
|
*
|
|
@@ -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;
|
|
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,CAA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/C,MAAM,MAAM,qBAAqB,GAAG,wBAAwB,CAAC;AAE7D;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC5B;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;;;OAMG;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"}
|
|
@@ -28,7 +28,7 @@ function createFakeGeneratorHost(source, options = {}) {
|
|
|
28
28
|
generator.option({
|
|
29
29
|
alwaysFakeOptionals: true,
|
|
30
30
|
refDepthMax: 1_000,
|
|
31
|
-
pruneProperties: ['dbEntity', 'dbIndex', 'dbColumn'],
|
|
31
|
+
pruneProperties: ['dbEntity', 'dbIndex', 'dbColumn', 'dbFK'],
|
|
32
32
|
...options,
|
|
33
33
|
resolveJsonPath: false,
|
|
34
34
|
});
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ForgeSchemaOptions, ForgeSchemaResult } from '../types';
|
|
2
2
|
export declare function forgeSchema(options: ForgeSchemaOptions): Promise<ForgeSchemaResult>;
|
|
3
3
|
//# sourceMappingURL=forge.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"forge.d.ts","sourceRoot":"","sources":["../../src/schema-generator/forge.ts"],"names":[],"mappings":"
|
|
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"}
|
|
@@ -44,6 +44,7 @@ async function forgeSchema(options) {
|
|
|
44
44
|
...options,
|
|
45
45
|
})),
|
|
46
46
|
...(options.schemaMetadata || {}),
|
|
47
|
+
hash: undefined,
|
|
47
48
|
};
|
|
48
49
|
{
|
|
49
50
|
const algorithm = options.schemaMetadata?.hash == null ||
|
|
@@ -75,7 +76,7 @@ async function forgeSchema(options) {
|
|
|
75
76
|
serviceRefs: {},
|
|
76
77
|
serviceNames: {},
|
|
77
78
|
};
|
|
78
|
-
const defs = new Set(Object.keys(
|
|
79
|
+
const defs = new Set(Object.keys(schema.definitions || {}));
|
|
79
80
|
for (const name of definitions) {
|
|
80
81
|
const ref = (0, ref_1.buildSchemaDefinitionRef)(name, options.schemaId);
|
|
81
82
|
map.names[name] = ref;
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const promises_1 = require("node:fs/promises");
|
|
4
4
|
const error_1 = require("@tsofist/stem/lib/error");
|
|
5
5
|
const noop_1 = require("@tsofist/stem/lib/noop");
|
|
6
|
+
const keys_1 = require("@tsofist/stem/lib/object/keys");
|
|
6
7
|
const pick_1 = require("@tsofist/stem/lib/object/pick");
|
|
7
8
|
const artefacts_policy_1 = require("../artefacts-policy");
|
|
8
9
|
const types_1 = require("../definition-info/types");
|
|
@@ -49,7 +50,7 @@ describe('generator for a8', () => {
|
|
|
49
50
|
it('generated schema should have correct metadata', () => {
|
|
50
51
|
expect(forgeSchemaResult).toBeTruthy();
|
|
51
52
|
const schema = forgeSchemaResult.schema;
|
|
52
|
-
expect((0, pick_1.pickProps)(schema,
|
|
53
|
+
expect((0, pick_1.pickProps)(schema, (0, keys_1.keysOf)(schemaMetadata))).toStrictEqual(schemaMetadata);
|
|
53
54
|
});
|
|
54
55
|
it('generated schema should be valid', () => {
|
|
55
56
|
expect(forgeSchemaResult).toBeTruthy();
|
|
@@ -94,7 +95,7 @@ describe('generator for a7', () => {
|
|
|
94
95
|
it('generated schema should have correct metadata', () => {
|
|
95
96
|
expect(forgeSchemaResult).toBeTruthy();
|
|
96
97
|
const schema = forgeSchemaResult.schema;
|
|
97
|
-
expect((0, pick_1.pickProps)(schema,
|
|
98
|
+
expect((0, pick_1.pickProps)(schema, (0, keys_1.keysOf)(schemaMetadata))).toStrictEqual(schemaMetadata);
|
|
98
99
|
});
|
|
99
100
|
it('generated schema should be valid', () => {
|
|
100
101
|
expect(forgeSchemaResult).toBeTruthy();
|
|
@@ -243,7 +244,7 @@ describe('generator for a5', () => {
|
|
|
243
244
|
expect(forgeSchemaResult).toBeTruthy();
|
|
244
245
|
const defs = forgeSchemaResult?.schema?.definitions;
|
|
245
246
|
expect(defs).toBeTruthy();
|
|
246
|
-
expect(
|
|
247
|
+
expect((0, keys_1.keysOf)(defs)).toStrictEqual([
|
|
247
248
|
'DomainNum',
|
|
248
249
|
'DomainValue',
|
|
249
250
|
'DomainValuesType',
|
|
@@ -301,10 +302,12 @@ describe('generator for a5', () => {
|
|
|
301
302
|
},
|
|
302
303
|
indexedField1: {
|
|
303
304
|
dbIndex: 'ix_some_indexed_field',
|
|
305
|
+
dbFK: true,
|
|
304
306
|
type: 'number',
|
|
305
307
|
},
|
|
306
308
|
indexedField2: {
|
|
307
309
|
dbIndex: true,
|
|
310
|
+
dbFK: false,
|
|
308
311
|
type: 'number',
|
|
309
312
|
},
|
|
310
313
|
indexedField3: {
|
|
@@ -377,7 +380,7 @@ describe('generator for a4', () => {
|
|
|
377
380
|
expect(forgeSchemaResult).toBeTruthy();
|
|
378
381
|
const defs = forgeSchemaResult?.schema?.definitions;
|
|
379
382
|
expect(defs).toBeTruthy();
|
|
380
|
-
expect(
|
|
383
|
+
expect((0, keys_1.keysOf)(defs)).toStrictEqual(['API', 'Enum', 'FormatMode', 'Some', 'Some2']);
|
|
381
384
|
});
|
|
382
385
|
});
|
|
383
386
|
describe('generator for a3', () => {
|
|
@@ -410,9 +413,10 @@ describe('generator for a3', () => {
|
|
|
410
413
|
expect(registry.getRootSchema('')).toBeTruthy();
|
|
411
414
|
});
|
|
412
415
|
it('interface generics should works', () => {
|
|
413
|
-
const props = forgeSchemaResult.schema.definitions?.InterfaceWithGeneric__APIInterface
|
|
416
|
+
const props = forgeSchemaResult.schema.definitions?.InterfaceWithGeneric__APIInterface?.properties;
|
|
414
417
|
expect(props).toBeTruthy();
|
|
415
418
|
expect(props.propWithGeneric).toBeTruthy();
|
|
419
|
+
// @ts-expect-error It's a test
|
|
416
420
|
expect(props.propWithGeneric.$ref).toStrictEqual('#/definitions/NonEmptyString');
|
|
417
421
|
});
|
|
418
422
|
it('optional args in API methods should works', () => {
|
|
@@ -448,9 +452,9 @@ describe('generator for a3', () => {
|
|
|
448
452
|
// }
|
|
449
453
|
});
|
|
450
454
|
it('extends should works', () => {
|
|
451
|
-
const props = forgeSchemaResult.schema.definitions?.BAPI__APIInterface
|
|
455
|
+
const props = forgeSchemaResult.schema.definitions?.BAPI__APIInterface?.properties;
|
|
452
456
|
expect(props).toBeTruthy();
|
|
453
|
-
expect(
|
|
457
|
+
expect((0, keys_1.keysOf)(props)).toStrictEqual([
|
|
454
458
|
'propertyA',
|
|
455
459
|
'propertyB',
|
|
456
460
|
'propertyC',
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import './extended-annotations-reader';
|
|
2
|
-
import { SchemaObject } from 'ajv';
|
|
3
2
|
import { CompletedConfig } from 'ts-json-schema-generator';
|
|
4
|
-
import { ForgeSchemaOptions } from '../types';
|
|
3
|
+
import type { ForgedSchema, ForgeSchemaOptions } from '../types';
|
|
5
4
|
/**
|
|
6
5
|
* @internal
|
|
7
6
|
*/
|
|
8
|
-
export declare function generateSchemaByDraftTypes(options: InternalOptions): Promise<
|
|
7
|
+
export declare function generateSchemaByDraftTypes(options: InternalOptions): Promise<ForgedSchema>;
|
|
9
8
|
interface InternalOptions extends ForgeSchemaOptions {
|
|
10
9
|
tsconfig: string;
|
|
11
10
|
definitions: readonly string[];
|
|
@@ -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;
|
|
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"}
|
|
@@ -51,11 +51,11 @@ async function generateSchemaByDraftTypes(options) {
|
|
|
51
51
|
description: undefined,
|
|
52
52
|
version: undefined,
|
|
53
53
|
$comment: undefined,
|
|
54
|
-
definitions: {},
|
|
55
54
|
};
|
|
55
|
+
const defs = (result.definitions ??= {});
|
|
56
56
|
for (const definitionName of options.definitions) {
|
|
57
57
|
const schema = generator.createSchema(definitionName);
|
|
58
|
-
Object.assign(
|
|
58
|
+
Object.assign(defs, schema.definitions);
|
|
59
59
|
}
|
|
60
60
|
const shrinkDefinitionNames = !options.shrinkDefinitionNames
|
|
61
61
|
? undefined
|
|
@@ -64,18 +64,15 @@ async function generateSchemaByDraftTypes(options) {
|
|
|
64
64
|
: options.shrinkDefinitionNames;
|
|
65
65
|
if (shrinkDefinitionNames) {
|
|
66
66
|
const replacement = new Set();
|
|
67
|
-
|
|
68
|
-
for (const name of Object.keys(result.definitions)) {
|
|
67
|
+
for (const name of Object.keys(defs)) {
|
|
69
68
|
const shortName = shrinkDefinitionNames(name);
|
|
70
69
|
if (shortName) {
|
|
71
|
-
if (replacement.has(shortName) || shortName in
|
|
70
|
+
if (replacement.has(shortName) || shortName in defs) {
|
|
72
71
|
(0, error_1.raise)(`Duplicate replacement definition name: ${shortName}`);
|
|
73
72
|
}
|
|
74
73
|
// rename property
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
78
|
-
delete result.definitions[name];
|
|
74
|
+
defs[shortName] = defs[name];
|
|
75
|
+
delete defs[name];
|
|
79
76
|
// rename references
|
|
80
77
|
const targets = (0, jsonpath_plus_1.JSONPath)({
|
|
81
78
|
path: `$..[?(@ && @.$ref == "#/definitions/${escapeDefinitionNameForJSONPath(name)}")]`,
|
|
@@ -88,7 +85,7 @@ async function generateSchemaByDraftTypes(options) {
|
|
|
88
85
|
}
|
|
89
86
|
}
|
|
90
87
|
}
|
|
91
|
-
result.definitions = Object.fromEntries(Object.entries((
|
|
88
|
+
result.definitions = Object.fromEntries(Object.entries((defs || {})).sort());
|
|
92
89
|
if (options.sortObjectProperties)
|
|
93
90
|
(0, sort_properties_1.sortSchemaProperties)(result.definitions);
|
|
94
91
|
await new ajv_1.default({
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { JSONSchema7Object } from 'json-schema';
|
|
2
|
-
export declare function sortSchemaProperties<T extends JSONSchema7Object>(schema: T): T;
|
|
1
|
+
import type { JSONSchema7, JSONSchema7Object } from 'json-schema';
|
|
2
|
+
export declare function sortSchemaProperties<T extends JSONSchema7Object | JSONSchema7>(schema: T): T;
|
|
3
3
|
//# sourceMappingURL=sort-properties.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sort-properties.d.ts","sourceRoot":"","sources":["../../src/schema-generator/sort-properties.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;
|
|
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"}
|
|
@@ -4,7 +4,7 @@ export declare const SFG_CONFIG_DEFAULTS: {
|
|
|
4
4
|
readonly additionalProperties: false;
|
|
5
5
|
readonly expose: "export";
|
|
6
6
|
readonly strictTuples: true;
|
|
7
|
-
readonly extraTags: ["apiMember", "apiMethod", "apiInterface", "apiProperty", "dbColumn", "dbIndex", "dbEntity", "faker"];
|
|
7
|
+
readonly extraTags: ["apiMember", "apiMethod", "apiInterface", "apiProperty", "dbColumn", "dbIndex", "dbEntity", "dbFK", "faker"];
|
|
8
8
|
readonly encodeRefs: false;
|
|
9
9
|
readonly markdownDescription: false;
|
|
10
10
|
readonly discriminatorType: undefined;
|
|
@@ -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;;;;;;;;;;
|
|
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,eAAO,MAAM,oBAAoB;;;;CAIN,CAAC"}
|
|
@@ -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;
|
|
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"}
|
|
@@ -16,6 +16,9 @@ const DBMLIndexOptionsProperties = {
|
|
|
16
16
|
note: { type: 'string' },
|
|
17
17
|
comment: { type: 'string' },
|
|
18
18
|
};
|
|
19
|
+
const DBMLForeignKeySchema = {
|
|
20
|
+
type: ['boolean'],
|
|
21
|
+
};
|
|
19
22
|
const DBMLIndexSchema = {
|
|
20
23
|
type: ['string', 'boolean', 'object', 'array'],
|
|
21
24
|
pattern: NP_IX,
|
|
@@ -35,6 +38,10 @@ DBMLIndexSchema.items = {
|
|
|
35
38
|
type: ['string', 'boolean', 'object'],
|
|
36
39
|
};
|
|
37
40
|
exports.SFRDBMLKeywords = [
|
|
41
|
+
{
|
|
42
|
+
keyword: 'dbFK',
|
|
43
|
+
metaSchema: DBMLForeignKeySchema,
|
|
44
|
+
},
|
|
38
45
|
{
|
|
39
46
|
keyword: 'dbIndex',
|
|
40
47
|
metaSchema: DBMLIndexSchema,
|
package/lib/types.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import type { NonEmptyString, Nullable, PRec } from '@tsofist/stem';
|
|
2
|
-
import type { ErrorObject, ErrorsTextOptions,
|
|
1
|
+
import type { NonEmptyString, Nullable, PRec, Reintroduce } from '@tsofist/stem';
|
|
2
|
+
import type { ErrorObject, ErrorsTextOptions, ValidateFunction } from 'ajv';
|
|
3
|
+
import type { JSONSchema7 as Schema } from 'json-schema';
|
|
3
4
|
import type { Config } from 'ts-json-schema-generator';
|
|
5
|
+
import type { DBMLColumnOptions, DBMLEntityOptionsDef, DBMLForeignKeyOptions, DBMLIndexOptionsDef } from './dbml-generator/types';
|
|
4
6
|
export interface ForgeSchemaOptions {
|
|
5
7
|
/**
|
|
6
8
|
* Generate schema definitions for public types only
|
|
@@ -116,8 +118,29 @@ export interface SchemaForgeMetadata {
|
|
|
116
118
|
serviceRefs: PRec<string, SchemaForgeDefinitionRef>;
|
|
117
119
|
serviceNames: PRec<SchemaForgeDefinitionRef>;
|
|
118
120
|
}
|
|
121
|
+
declare const ForgedSchemaDraft7Id = "http://json-schema.org/draft-07/schema#";
|
|
122
|
+
export type ForgedSchema = Reintroduce<Schema, {
|
|
123
|
+
$schema: typeof ForgedSchemaDraft7Id;
|
|
124
|
+
$id?: string;
|
|
125
|
+
$comment?: string;
|
|
126
|
+
hash?: string;
|
|
127
|
+
title?: string;
|
|
128
|
+
description?: string;
|
|
129
|
+
version?: string;
|
|
130
|
+
$defs?: PRec<Schema>;
|
|
131
|
+
definitions?: PRec<Schema>;
|
|
132
|
+
}>;
|
|
133
|
+
export type ForgedEntitySchema = Schema & {
|
|
134
|
+
dbEntity?: DBMLEntityOptionsDef;
|
|
135
|
+
properties?: PRec<ForgedEntitySchema>;
|
|
136
|
+
};
|
|
137
|
+
export type ForgedPropertySchema = Schema & {
|
|
138
|
+
dbFK?: DBMLForeignKeyOptions;
|
|
139
|
+
dbIndex?: DBMLIndexOptionsDef;
|
|
140
|
+
dbColumn?: DBMLColumnOptions;
|
|
141
|
+
};
|
|
119
142
|
export interface ForgeSchemaResult {
|
|
120
|
-
schema:
|
|
143
|
+
schema: ForgedSchema;
|
|
121
144
|
refs: readonly SchemaForgeDefinitionRef[];
|
|
122
145
|
generatedTemporaryFiles: readonly string[];
|
|
123
146
|
generatedNamesBySourceFile: ReadonlyMap<string, ReadonlySet<string>>;
|
package/lib/types.d.ts.map
CHANGED
|
@@ -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,MAAM,eAAe,CAAC;
|
|
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,E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