metal-orm 1.0.90 → 1.0.92
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/dist/index.cjs +214 -118
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +71 -32
- package/dist/index.d.ts +71 -32
- package/dist/index.js +206 -118
- package/dist/index.js.map +1 -1
- package/package.json +4 -2
- package/scripts/generate-entities/render.mjs +16 -3
- package/src/core/ddl/introspect/utils.ts +45 -45
- package/src/decorators/bootstrap.ts +37 -37
- package/src/decorators/column-decorator.ts +3 -1
- package/src/dto/apply-filter.ts +279 -281
- package/src/dto/dto-types.ts +229 -229
- package/src/dto/filter-types.ts +193 -193
- package/src/dto/index.ts +97 -97
- package/src/dto/openapi/generators/base.ts +29 -29
- package/src/dto/openapi/generators/column.ts +37 -34
- package/src/dto/openapi/generators/dto.ts +94 -94
- package/src/dto/openapi/generators/filter.ts +75 -74
- package/src/dto/openapi/generators/nested-dto.ts +618 -532
- package/src/dto/openapi/generators/pagination.ts +111 -111
- package/src/dto/openapi/generators/relation-filter.ts +228 -210
- package/src/dto/openapi/index.ts +17 -17
- package/src/dto/openapi/type-mappings.ts +191 -191
- package/src/dto/openapi/types.ts +101 -83
- package/src/dto/openapi/utilities.ts +90 -45
- package/src/dto/pagination-utils.ts +150 -150
- package/src/dto/transform.ts +197 -193
- package/src/index.ts +69 -69
- package/src/orm/entity-context.ts +9 -9
- package/src/orm/entity-metadata.ts +14 -14
- package/src/orm/entity.ts +74 -74
- package/src/orm/orm-session.ts +159 -159
- package/src/orm/relation-change-processor.ts +3 -3
- package/src/orm/runtime-types.ts +5 -5
- package/src/schema/column-types.ts +4 -4
- package/src/schema/types.ts +5 -1
|
@@ -1,34 +1,37 @@
|
|
|
1
|
-
import type { ColumnDef } from '../../../schema/column-types.js';
|
|
2
|
-
import type { OpenApiSchema } from '../types.js';
|
|
3
|
-
import { columnTypeToOpenApiType, columnTypeToOpenApiFormat } from '../type-mappings.js';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
1
|
+
import type { ColumnDef } from '../../../schema/column-types.js';
|
|
2
|
+
import type { OpenApiSchema, OpenApiDialect } from '../types.js';
|
|
3
|
+
import { columnTypeToOpenApiType, columnTypeToOpenApiFormat } from '../type-mappings.js';
|
|
4
|
+
import { applyNullability, isNullableColumn } from '../utilities.js';
|
|
5
|
+
|
|
6
|
+
export function columnToOpenApiSchema(
|
|
7
|
+
col: ColumnDef,
|
|
8
|
+
dialect: OpenApiDialect = 'openapi-3.1'
|
|
9
|
+
): OpenApiSchema {
|
|
10
|
+
const schema: OpenApiSchema = {
|
|
11
|
+
type: columnTypeToOpenApiType(col),
|
|
12
|
+
format: columnTypeToOpenApiFormat(col),
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const nullable = isNullableColumn(col);
|
|
16
|
+
const result = applyNullability(schema, nullable, dialect);
|
|
17
|
+
|
|
18
|
+
if (col.comment) {
|
|
19
|
+
result.description = col.comment;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (col.type.toUpperCase() === 'ENUM' && col.args && Array.isArray(col.args) && col.args.every(v => typeof v === 'string')) {
|
|
23
|
+
result.enum = col.args as string[];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const args = col.args;
|
|
27
|
+
if (args && args.length > 0) {
|
|
28
|
+
if (col.type.toUpperCase() === 'VARCHAR' || col.type.toUpperCase() === 'CHAR') {
|
|
29
|
+
const length = args[0] as number;
|
|
30
|
+
if (length) {
|
|
31
|
+
result.example = 'a'.repeat(length);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
@@ -1,94 +1,94 @@
|
|
|
1
|
-
import type { TableDef } from '../../../schema/table.js';
|
|
2
|
-
import type { EntityConstructor } from '../../../orm/entity-metadata.js';
|
|
3
|
-
import type { OpenApiSchema } from '../types.js';
|
|
4
|
-
import { columnToOpenApiSchema } from './column.js';
|
|
5
|
-
import { getColumnMap } from './base.js';
|
|
6
|
-
|
|
7
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
8
|
-
export function dtoToOpenApiSchema<T extends TableDef | EntityConstructor, TExclude extends keyof any>(
|
|
9
|
-
target: T,
|
|
10
|
-
exclude?: TExclude[]
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return {
|
|
91
|
-
type: 'object',
|
|
92
|
-
properties,
|
|
93
|
-
};
|
|
94
|
-
}
|
|
1
|
+
import type { TableDef } from '../../../schema/table.js';
|
|
2
|
+
import type { EntityConstructor } from '../../../orm/entity-metadata.js';
|
|
3
|
+
import type { OpenApiSchema, OpenApiDialect } from '../types.js';
|
|
4
|
+
import { columnToOpenApiSchema } from './column.js';
|
|
5
|
+
import { getColumnMap } from './base.js';
|
|
6
|
+
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
8
|
+
export function dtoToOpenApiSchema<T extends TableDef | EntityConstructor, TExclude extends keyof any>(
|
|
9
|
+
target: T,
|
|
10
|
+
exclude?: TExclude[],
|
|
11
|
+
dialect: OpenApiDialect = 'openapi-3.1'
|
|
12
|
+
): OpenApiSchema {
|
|
13
|
+
const columns = getColumnMap(target);
|
|
14
|
+
const properties: Record<string, OpenApiSchema> = {};
|
|
15
|
+
const required: string[] = [];
|
|
16
|
+
|
|
17
|
+
for (const [key, col] of Object.entries(columns)) {
|
|
18
|
+
if (exclude?.includes(key as TExclude)) {
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
properties[key] = columnToOpenApiSchema(col, dialect);
|
|
23
|
+
|
|
24
|
+
if (col.notNull || col.primary) {
|
|
25
|
+
required.push(key);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
type: 'object',
|
|
31
|
+
properties,
|
|
32
|
+
...(required.length > 0 && { required }),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
37
|
+
export function createDtoToOpenApiSchema<T extends TableDef | EntityConstructor, TExclude extends keyof any>(
|
|
38
|
+
target: T,
|
|
39
|
+
exclude?: TExclude[],
|
|
40
|
+
dialect: OpenApiDialect = 'openapi-3.1'
|
|
41
|
+
): OpenApiSchema {
|
|
42
|
+
const columns = getColumnMap(target);
|
|
43
|
+
const properties: Record<string, OpenApiSchema> = {};
|
|
44
|
+
const required: string[] = [];
|
|
45
|
+
|
|
46
|
+
for (const [key, col] of Object.entries(columns)) {
|
|
47
|
+
if (exclude?.includes(key as TExclude)) {
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (col.autoIncrement || col.generated) {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
properties[key] = columnToOpenApiSchema(col, dialect);
|
|
56
|
+
|
|
57
|
+
if (col.notNull && !col.default) {
|
|
58
|
+
required.push(key);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
type: 'object',
|
|
64
|
+
properties,
|
|
65
|
+
...(required.length > 0 && { required }),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
70
|
+
export function updateDtoToOpenApiSchema<T extends TableDef | EntityConstructor, TExclude extends keyof any>(
|
|
71
|
+
target: T,
|
|
72
|
+
exclude?: TExclude[],
|
|
73
|
+
dialect: OpenApiDialect = 'openapi-3.1'
|
|
74
|
+
): OpenApiSchema {
|
|
75
|
+
const columns = getColumnMap(target);
|
|
76
|
+
const properties: Record<string, OpenApiSchema> = {};
|
|
77
|
+
|
|
78
|
+
for (const [key, col] of Object.entries(columns)) {
|
|
79
|
+
if (exclude?.includes(key as TExclude)) {
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (col.autoIncrement || col.generated) {
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
properties[key] = columnToOpenApiSchema(col, dialect);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return {
|
|
91
|
+
type: 'object',
|
|
92
|
+
properties,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
@@ -1,74 +1,75 @@
|
|
|
1
|
-
import type { TableDef } from '../../../schema/table.js';
|
|
2
|
-
import type { ColumnDef } from '../../../schema/column-types.js';
|
|
3
|
-
import type { EntityConstructor } from '../../../orm/entity-metadata.js';
|
|
4
|
-
import type { OpenApiSchema } from '../types.js';
|
|
5
|
-
import { columnTypeToOpenApiType } from '../type-mappings.js';
|
|
6
|
-
import { getColumnMap } from './base.js';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
columnTypeToOpenApiType(col);
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
filterProperties = {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
filterProperties = {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export function whereInputToOpenApiSchema<T extends TableDef | EntityConstructor>(
|
|
61
|
-
target: T
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
1
|
+
import type { TableDef } from '../../../schema/table.js';
|
|
2
|
+
import type { ColumnDef } from '../../../schema/column-types.js';
|
|
3
|
+
import type { EntityConstructor } from '../../../orm/entity-metadata.js';
|
|
4
|
+
import type { OpenApiSchema, OpenApiDialect } from '../types.js';
|
|
5
|
+
import { columnTypeToOpenApiType, columnTypeToOpenApiFormat } from '../type-mappings.js';
|
|
6
|
+
import { getColumnMap } from './base.js';
|
|
7
|
+
import { applyNullability, isNullableColumn } from '../utilities.js';
|
|
8
|
+
|
|
9
|
+
function filterFieldToOpenApiSchema(col: ColumnDef): OpenApiSchema {
|
|
10
|
+
const openApiType = columnTypeToOpenApiType(col);
|
|
11
|
+
const openApiFormat = columnTypeToOpenApiFormat(col);
|
|
12
|
+
|
|
13
|
+
const filterProperties: Record<string, OpenApiSchema> = {};
|
|
14
|
+
|
|
15
|
+
filterProperties.equals = { type: openApiType, format: openApiFormat };
|
|
16
|
+
filterProperties.not = { type: openApiType, format: openApiFormat };
|
|
17
|
+
filterProperties.in = { type: 'array', items: { type: openApiType, format: openApiFormat } };
|
|
18
|
+
filterProperties.notIn = { type: 'array', items: { type: openApiType, format: openApiFormat } };
|
|
19
|
+
|
|
20
|
+
const isNumeric = openApiType === 'integer' || openApiType === 'number';
|
|
21
|
+
const isDateOrTime = openApiType === 'string' && (openApiFormat === 'date' || openApiFormat === 'date-time');
|
|
22
|
+
const isString = openApiType === 'string' && !isDateOrTime;
|
|
23
|
+
|
|
24
|
+
if (isNumeric) {
|
|
25
|
+
filterProperties.lt = { type: openApiType, format: openApiFormat };
|
|
26
|
+
filterProperties.lte = { type: openApiType, format: openApiFormat };
|
|
27
|
+
filterProperties.gt = { type: openApiType, format: openApiFormat };
|
|
28
|
+
filterProperties.gte = { type: openApiType, format: openApiFormat };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (isDateOrTime) {
|
|
32
|
+
filterProperties.lt = { type: openApiType, format: openApiFormat };
|
|
33
|
+
filterProperties.lte = { type: openApiType, format: openApiFormat };
|
|
34
|
+
filterProperties.gt = { type: openApiType, format: openApiFormat };
|
|
35
|
+
filterProperties.gte = { type: openApiType, format: openApiFormat };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (isString) {
|
|
39
|
+
filterProperties.contains = { type: 'string' };
|
|
40
|
+
filterProperties.startsWith = { type: 'string' };
|
|
41
|
+
filterProperties.endsWith = { type: 'string' };
|
|
42
|
+
filterProperties.mode = { type: 'string', enum: ['default', 'insensitive'] };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
type: 'object',
|
|
47
|
+
properties: filterProperties,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function columnToFilterSchema(
|
|
52
|
+
col: ColumnDef,
|
|
53
|
+
dialect: OpenApiDialect = 'openapi-3.1'
|
|
54
|
+
): OpenApiSchema {
|
|
55
|
+
const filterSchema = filterFieldToOpenApiSchema(col);
|
|
56
|
+
const nullable = isNullableColumn(col);
|
|
57
|
+
return applyNullability(filterSchema, nullable, dialect);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function whereInputToOpenApiSchema<T extends TableDef | EntityConstructor>(
|
|
61
|
+
target: T,
|
|
62
|
+
dialect: OpenApiDialect = 'openapi-3.1'
|
|
63
|
+
): OpenApiSchema {
|
|
64
|
+
const columns = getColumnMap(target);
|
|
65
|
+
const properties: Record<string, OpenApiSchema> = {};
|
|
66
|
+
|
|
67
|
+
for (const [key, col] of Object.entries(columns)) {
|
|
68
|
+
properties[key] = columnToFilterSchema(col, dialect);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return {
|
|
72
|
+
type: 'object',
|
|
73
|
+
properties,
|
|
74
|
+
};
|
|
75
|
+
}
|