metal-orm 1.0.90 → 1.0.91
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.map +1 -1
- package/dist/index.d.cts +24 -10
- package/dist/index.d.ts +24 -10
- package/dist/index.js.map +1 -1
- package/package.json +4 -2
- package/src/core/ddl/introspect/utils.ts +45 -45
- package/src/decorators/bootstrap.ts +37 -37
- 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 +34 -34
- package/src/dto/openapi/generators/dto.ts +94 -94
- package/src/dto/openapi/generators/filter.ts +74 -74
- package/src/dto/openapi/generators/nested-dto.ts +532 -532
- package/src/dto/openapi/generators/pagination.ts +111 -111
- package/src/dto/openapi/generators/relation-filter.ts +210 -210
- package/src/dto/openapi/index.ts +17 -17
- package/src/dto/openapi/type-mappings.ts +191 -191
- package/src/dto/openapi/types.ts +90 -83
- package/src/dto/openapi/utilities.ts +45 -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.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,34 @@
|
|
|
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
|
-
export function columnToOpenApiSchema(col: ColumnDef): OpenApiSchema {
|
|
6
|
-
const schema: OpenApiSchema = {
|
|
7
|
-
type: columnTypeToOpenApiType(col),
|
|
8
|
-
format: columnTypeToOpenApiFormat(col),
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
if (!col.notNull) {
|
|
12
|
-
schema.nullable = true;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
if (col.comment) {
|
|
16
|
-
schema.description = col.comment;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if (col.type.toUpperCase() === 'ENUM' && col.args && Array.isArray(col.args) && col.args.every(v => typeof v === 'string')) {
|
|
20
|
-
schema.enum = col.args as string[];
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const args = col.args;
|
|
24
|
-
if (args && args.length > 0) {
|
|
25
|
-
if (col.type.toUpperCase() === 'VARCHAR' || col.type.toUpperCase() === 'CHAR') {
|
|
26
|
-
const length = args[0] as number;
|
|
27
|
-
if (length) {
|
|
28
|
-
schema.example = 'a'.repeat(length);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return schema;
|
|
34
|
-
}
|
|
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
|
+
export function columnToOpenApiSchema(col: ColumnDef): OpenApiSchema {
|
|
6
|
+
const schema: OpenApiSchema = {
|
|
7
|
+
type: columnTypeToOpenApiType(col),
|
|
8
|
+
format: columnTypeToOpenApiFormat(col),
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
if (!col.notNull) {
|
|
12
|
+
schema.nullable = true;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (col.comment) {
|
|
16
|
+
schema.description = col.comment;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (col.type.toUpperCase() === 'ENUM' && col.args && Array.isArray(col.args) && col.args.every(v => typeof v === 'string')) {
|
|
20
|
+
schema.enum = col.args as string[];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const args = col.args;
|
|
24
|
+
if (args && args.length > 0) {
|
|
25
|
+
if (col.type.toUpperCase() === 'VARCHAR' || col.type.toUpperCase() === 'CHAR') {
|
|
26
|
+
const length = args[0] as number;
|
|
27
|
+
if (length) {
|
|
28
|
+
schema.example = 'a'.repeat(length);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return schema;
|
|
34
|
+
}
|
|
@@ -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
|
-
): OpenApiSchema {
|
|
12
|
-
const columns = getColumnMap(target);
|
|
13
|
-
const properties: Record<string, OpenApiSchema> = {};
|
|
14
|
-
const required: string[] = [];
|
|
15
|
-
|
|
16
|
-
for (const [key, col] of Object.entries(columns)) {
|
|
17
|
-
if (exclude?.includes(key as TExclude)) {
|
|
18
|
-
continue;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
properties[key] = columnToOpenApiSchema(col);
|
|
22
|
-
|
|
23
|
-
if (col.notNull || col.primary) {
|
|
24
|
-
required.push(key);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return {
|
|
29
|
-
type: 'object',
|
|
30
|
-
properties,
|
|
31
|
-
...(required.length > 0 && { required }),
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
36
|
-
export function createDtoToOpenApiSchema<T extends TableDef | EntityConstructor, TExclude extends keyof any>(
|
|
37
|
-
target: T,
|
|
38
|
-
exclude?: TExclude[]
|
|
39
|
-
): OpenApiSchema {
|
|
40
|
-
const columns = getColumnMap(target);
|
|
41
|
-
const properties: Record<string, OpenApiSchema> = {};
|
|
42
|
-
const required: string[] = [];
|
|
43
|
-
|
|
44
|
-
for (const [key, col] of Object.entries(columns)) {
|
|
45
|
-
if (exclude?.includes(key as TExclude)) {
|
|
46
|
-
continue;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (col.autoIncrement || col.generated) {
|
|
50
|
-
continue;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
properties[key] = columnToOpenApiSchema(col);
|
|
54
|
-
|
|
55
|
-
if (col.notNull && !col.default) {
|
|
56
|
-
required.push(key);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return {
|
|
61
|
-
type: 'object',
|
|
62
|
-
properties,
|
|
63
|
-
...(required.length > 0 && { required }),
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
68
|
-
export function updateDtoToOpenApiSchema<T extends TableDef | EntityConstructor, TExclude extends keyof any>(
|
|
69
|
-
target: T,
|
|
70
|
-
exclude?: TExclude[]
|
|
71
|
-
): OpenApiSchema {
|
|
72
|
-
const columns = getColumnMap(target);
|
|
73
|
-
const properties: Record<string, OpenApiSchema> = {};
|
|
74
|
-
|
|
75
|
-
for (const [key, col] of Object.entries(columns)) {
|
|
76
|
-
if (exclude?.includes(key as TExclude)) {
|
|
77
|
-
continue;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (col.autoIncrement || col.generated) {
|
|
81
|
-
continue;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
properties[key] = {
|
|
85
|
-
...columnToOpenApiSchema(col),
|
|
86
|
-
...(!col.notNull ? { nullable: true } : {}),
|
|
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 } 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
|
+
): OpenApiSchema {
|
|
12
|
+
const columns = getColumnMap(target);
|
|
13
|
+
const properties: Record<string, OpenApiSchema> = {};
|
|
14
|
+
const required: string[] = [];
|
|
15
|
+
|
|
16
|
+
for (const [key, col] of Object.entries(columns)) {
|
|
17
|
+
if (exclude?.includes(key as TExclude)) {
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
properties[key] = columnToOpenApiSchema(col);
|
|
22
|
+
|
|
23
|
+
if (col.notNull || col.primary) {
|
|
24
|
+
required.push(key);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
type: 'object',
|
|
30
|
+
properties,
|
|
31
|
+
...(required.length > 0 && { required }),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
36
|
+
export function createDtoToOpenApiSchema<T extends TableDef | EntityConstructor, TExclude extends keyof any>(
|
|
37
|
+
target: T,
|
|
38
|
+
exclude?: TExclude[]
|
|
39
|
+
): OpenApiSchema {
|
|
40
|
+
const columns = getColumnMap(target);
|
|
41
|
+
const properties: Record<string, OpenApiSchema> = {};
|
|
42
|
+
const required: string[] = [];
|
|
43
|
+
|
|
44
|
+
for (const [key, col] of Object.entries(columns)) {
|
|
45
|
+
if (exclude?.includes(key as TExclude)) {
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (col.autoIncrement || col.generated) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
properties[key] = columnToOpenApiSchema(col);
|
|
54
|
+
|
|
55
|
+
if (col.notNull && !col.default) {
|
|
56
|
+
required.push(key);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
type: 'object',
|
|
62
|
+
properties,
|
|
63
|
+
...(required.length > 0 && { required }),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
68
|
+
export function updateDtoToOpenApiSchema<T extends TableDef | EntityConstructor, TExclude extends keyof any>(
|
|
69
|
+
target: T,
|
|
70
|
+
exclude?: TExclude[]
|
|
71
|
+
): OpenApiSchema {
|
|
72
|
+
const columns = getColumnMap(target);
|
|
73
|
+
const properties: Record<string, OpenApiSchema> = {};
|
|
74
|
+
|
|
75
|
+
for (const [key, col] of Object.entries(columns)) {
|
|
76
|
+
if (exclude?.includes(key as TExclude)) {
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (col.autoIncrement || col.generated) {
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
properties[key] = {
|
|
85
|
+
...columnToOpenApiSchema(col),
|
|
86
|
+
...(!col.notNull ? { nullable: true } : {}),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return {
|
|
91
|
+
type: 'object',
|
|
92
|
+
properties,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
@@ -1,74 +1,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 } from '../types.js';
|
|
5
|
-
import { columnTypeToOpenApiType } from '../type-mappings.js';
|
|
6
|
-
import { getColumnMap } from './base.js';
|
|
7
|
-
|
|
8
|
-
function filterFieldToOpenApiSchema(col: ColumnDef): OpenApiSchema {
|
|
9
|
-
const normalizedType = col.type.toUpperCase();
|
|
10
|
-
columnTypeToOpenApiType(col);
|
|
11
|
-
|
|
12
|
-
let filterProperties: Record<string, OpenApiSchema> = {};
|
|
13
|
-
|
|
14
|
-
if (['INT', 'INTEGER', 'BIGINT', 'DECIMAL', 'FLOAT', 'DOUBLE'].includes(normalizedType)) {
|
|
15
|
-
filterProperties = {
|
|
16
|
-
equals: { type: 'number' },
|
|
17
|
-
not: { type: 'number' },
|
|
18
|
-
in: { type: 'array', items: { type: 'number' } },
|
|
19
|
-
notIn: { type: 'array', items: { type: 'number' } },
|
|
20
|
-
lt: { type: 'number' },
|
|
21
|
-
lte: { type: 'number' },
|
|
22
|
-
gt: { type: 'number' },
|
|
23
|
-
gte: { type: 'number' },
|
|
24
|
-
};
|
|
25
|
-
} else if (['BOOLEAN'].includes(normalizedType)) {
|
|
26
|
-
filterProperties = {
|
|
27
|
-
equals: { type: 'boolean' },
|
|
28
|
-
not: { type: 'boolean' },
|
|
29
|
-
};
|
|
30
|
-
} else if (['DATE', 'DATETIME', 'TIMESTAMP', 'TIMESTAMPTZ'].includes(normalizedType)) {
|
|
31
|
-
filterProperties = {
|
|
32
|
-
equals: { type: 'string', format: 'date-time' },
|
|
33
|
-
not: { type: 'string', format: 'date-time' },
|
|
34
|
-
in: { type: 'array', items: { type: 'string', format: 'date-time' } },
|
|
35
|
-
notIn: { type: 'array', items: { type: 'string', format: 'date-time' } },
|
|
36
|
-
lt: { type: 'string', format: 'date-time' },
|
|
37
|
-
lte: { type: 'string', format: 'date-time' },
|
|
38
|
-
gt: { type: 'string', format: 'date-time' },
|
|
39
|
-
gte: { type: 'string', format: 'date-time' },
|
|
40
|
-
};
|
|
41
|
-
} else {
|
|
42
|
-
filterProperties = {
|
|
43
|
-
equals: { type: 'string' },
|
|
44
|
-
not: { type: 'string' },
|
|
45
|
-
in: { type: 'array', items: { type: 'string' } },
|
|
46
|
-
notIn: { type: 'array', items: { type: 'string' } },
|
|
47
|
-
contains: { type: 'string' },
|
|
48
|
-
startsWith: { type: 'string' },
|
|
49
|
-
endsWith: { type: 'string' },
|
|
50
|
-
mode: { type: 'string', enum: ['default', 'insensitive'] },
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return {
|
|
55
|
-
type: 'object',
|
|
56
|
-
properties: filterProperties,
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export function whereInputToOpenApiSchema<T extends TableDef | EntityConstructor>(
|
|
61
|
-
target: T
|
|
62
|
-
): OpenApiSchema {
|
|
63
|
-
const columns = getColumnMap(target);
|
|
64
|
-
const properties: Record<string, OpenApiSchema> = {};
|
|
65
|
-
|
|
66
|
-
for (const [key, col] of Object.entries(columns)) {
|
|
67
|
-
properties[key] = filterFieldToOpenApiSchema(col);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return {
|
|
71
|
-
type: 'object',
|
|
72
|
-
properties,
|
|
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 } from '../types.js';
|
|
5
|
+
import { columnTypeToOpenApiType } from '../type-mappings.js';
|
|
6
|
+
import { getColumnMap } from './base.js';
|
|
7
|
+
|
|
8
|
+
function filterFieldToOpenApiSchema(col: ColumnDef): OpenApiSchema {
|
|
9
|
+
const normalizedType = col.type.toUpperCase();
|
|
10
|
+
columnTypeToOpenApiType(col);
|
|
11
|
+
|
|
12
|
+
let filterProperties: Record<string, OpenApiSchema> = {};
|
|
13
|
+
|
|
14
|
+
if (['INT', 'INTEGER', 'BIGINT', 'DECIMAL', 'FLOAT', 'DOUBLE'].includes(normalizedType)) {
|
|
15
|
+
filterProperties = {
|
|
16
|
+
equals: { type: 'number' },
|
|
17
|
+
not: { type: 'number' },
|
|
18
|
+
in: { type: 'array', items: { type: 'number' } },
|
|
19
|
+
notIn: { type: 'array', items: { type: 'number' } },
|
|
20
|
+
lt: { type: 'number' },
|
|
21
|
+
lte: { type: 'number' },
|
|
22
|
+
gt: { type: 'number' },
|
|
23
|
+
gte: { type: 'number' },
|
|
24
|
+
};
|
|
25
|
+
} else if (['BOOLEAN'].includes(normalizedType)) {
|
|
26
|
+
filterProperties = {
|
|
27
|
+
equals: { type: 'boolean' },
|
|
28
|
+
not: { type: 'boolean' },
|
|
29
|
+
};
|
|
30
|
+
} else if (['DATE', 'DATETIME', 'TIMESTAMP', 'TIMESTAMPTZ'].includes(normalizedType)) {
|
|
31
|
+
filterProperties = {
|
|
32
|
+
equals: { type: 'string', format: 'date-time' },
|
|
33
|
+
not: { type: 'string', format: 'date-time' },
|
|
34
|
+
in: { type: 'array', items: { type: 'string', format: 'date-time' } },
|
|
35
|
+
notIn: { type: 'array', items: { type: 'string', format: 'date-time' } },
|
|
36
|
+
lt: { type: 'string', format: 'date-time' },
|
|
37
|
+
lte: { type: 'string', format: 'date-time' },
|
|
38
|
+
gt: { type: 'string', format: 'date-time' },
|
|
39
|
+
gte: { type: 'string', format: 'date-time' },
|
|
40
|
+
};
|
|
41
|
+
} else {
|
|
42
|
+
filterProperties = {
|
|
43
|
+
equals: { type: 'string' },
|
|
44
|
+
not: { type: 'string' },
|
|
45
|
+
in: { type: 'array', items: { type: 'string' } },
|
|
46
|
+
notIn: { type: 'array', items: { type: 'string' } },
|
|
47
|
+
contains: { type: 'string' },
|
|
48
|
+
startsWith: { type: 'string' },
|
|
49
|
+
endsWith: { type: 'string' },
|
|
50
|
+
mode: { type: 'string', enum: ['default', 'insensitive'] },
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
type: 'object',
|
|
56
|
+
properties: filterProperties,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function whereInputToOpenApiSchema<T extends TableDef | EntityConstructor>(
|
|
61
|
+
target: T
|
|
62
|
+
): OpenApiSchema {
|
|
63
|
+
const columns = getColumnMap(target);
|
|
64
|
+
const properties: Record<string, OpenApiSchema> = {};
|
|
65
|
+
|
|
66
|
+
for (const [key, col] of Object.entries(columns)) {
|
|
67
|
+
properties[key] = filterFieldToOpenApiSchema(col);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
type: 'object',
|
|
72
|
+
properties,
|
|
73
|
+
};
|
|
74
|
+
}
|