adorn-api 1.0.1 → 1.0.2
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/README.md +4 -1
- package/dist/adapters/express/createApp.d.ts +149 -11
- package/dist/adapters/express/createApp.d.ts.map +1 -1
- package/dist/adapters/express/createApp.js +112 -6
- package/dist/adapters/express/createApp.js.map +1 -1
- package/dist/adapters/express/middleware/errorHandler.d.ts +193 -2
- package/dist/adapters/express/middleware/errorHandler.d.ts.map +1 -1
- package/dist/adapters/express/middleware/errorHandler.js +164 -3
- package/dist/adapters/express/middleware/errorHandler.js.map +1 -1
- package/dist/adapters/express/router.d.ts +1 -1
- package/dist/adapters/express/router.d.ts.map +1 -1
- package/dist/adapters/express/router.js +6 -4
- package/dist/adapters/express/router.js.map +1 -1
- package/dist/adapters/express/transport/request.js.map +1 -1
- package/dist/adapters/express/transport/response.d.ts +1 -1
- package/dist/adapters/express/transport/response.d.ts.map +1 -1
- package/dist/adapters/express/transport/response.js.map +1 -1
- package/dist/contracts/openapi-v3.d.ts +461 -0
- package/dist/contracts/openapi-v3.d.ts.map +1 -1
- package/dist/contracts/reply.d.ts +109 -1
- package/dist/contracts/reply.d.ts.map +1 -1
- package/dist/contracts/reply.js +40 -1
- package/dist/contracts/reply.js.map +1 -1
- package/dist/contracts/response-types.d.ts +5 -5
- package/dist/contracts/response-types.d.ts.map +1 -1
- package/dist/contracts/responses.d.ts +84 -4
- package/dist/contracts/responses.d.ts.map +1 -1
- package/dist/contracts/route-options.d.ts +134 -3
- package/dist/contracts/route-options.d.ts.map +1 -1
- package/dist/contracts/validator.d.ts +121 -0
- package/dist/contracts/validator.d.ts.map +1 -1
- package/dist/core/binding/binder.d.ts +56 -1
- package/dist/core/binding/binder.d.ts.map +1 -1
- package/dist/core/binding/binder.js +33 -0
- package/dist/core/binding/binder.js.map +1 -1
- package/dist/core/binding/coerce/primitives.d.ts +68 -1
- package/dist/core/binding/coerce/primitives.d.ts.map +1 -1
- package/dist/core/binding/coerce/primitives.js +82 -12
- package/dist/core/binding/coerce/primitives.js.map +1 -1
- package/dist/core/errors/http-error.d.ts +54 -0
- package/dist/core/errors/http-error.d.ts.map +1 -1
- package/dist/core/errors/http-error.js +54 -0
- package/dist/core/errors/http-error.js.map +1 -1
- package/dist/core/errors/validation-error.d.ts +65 -0
- package/dist/core/errors/validation-error.d.ts.map +1 -1
- package/dist/core/errors/validation-error.js +65 -0
- package/dist/core/errors/validation-error.js.map +1 -1
- package/dist/core/openapi/buildOpenApi.d.ts +65 -0
- package/dist/core/openapi/buildOpenApi.d.ts.map +1 -1
- package/dist/core/openapi/buildOpenApi.js +66 -4
- package/dist/core/openapi/buildOpenApi.js.map +1 -1
- package/dist/core/openapi/schema/registry.d.ts +1 -1
- package/dist/core/openapi/schema/registry.d.ts.map +1 -1
- package/dist/core/openapi/schema/registry.js.map +1 -1
- package/dist/core/registry/buildRegistry.d.ts.map +1 -1
- package/dist/core/registry/buildRegistry.js +49 -5
- package/dist/core/registry/buildRegistry.js.map +1 -1
- package/dist/core/registry/types.d.ts +194 -1
- package/dist/core/registry/types.d.ts.map +1 -1
- package/dist/core/reply/reply.d.ts +94 -0
- package/dist/core/reply/reply.d.ts.map +1 -1
- package/dist/core/reply/reply.js +87 -0
- package/dist/core/reply/reply.js.map +1 -1
- package/dist/core/reply/typed.d.ts +137 -3
- package/dist/core/reply/typed.d.ts.map +1 -1
- package/dist/core/reply/typed.js +137 -2
- package/dist/core/reply/typed.js.map +1 -1
- package/dist/core/responses/helpers.d.ts +1 -1
- package/dist/core/responses/helpers.d.ts.map +1 -1
- package/dist/core/responses/normalize.d.ts.map +1 -1
- package/dist/core/responses/normalize.js +2 -1
- package/dist/core/responses/normalize.js.map +1 -1
- package/dist/core/route/defineRoute.d.ts +48 -1
- package/dist/core/route/defineRoute.d.ts.map +1 -1
- package/dist/core/route/defineRoute.js +42 -1
- package/dist/core/route/defineRoute.js.map +1 -1
- package/dist/decorators/binding.d.ts +1 -1
- package/dist/decorators/binding.d.ts.map +1 -1
- package/dist/decorators/binding.js.map +1 -1
- package/dist/decorators/controller.d.ts +1 -1
- package/dist/decorators/controller.d.ts.map +1 -1
- package/dist/decorators/controller.js.map +1 -1
- package/dist/decorators/docs.d.ts +6 -0
- package/dist/decorators/docs.d.ts.map +1 -1
- package/dist/decorators/docs.js +45 -2
- package/dist/decorators/docs.js.map +1 -1
- package/dist/decorators/index.d.ts +3 -0
- package/dist/decorators/index.d.ts.map +1 -1
- package/dist/decorators/index.js +3 -0
- package/dist/decorators/index.js.map +1 -1
- package/dist/decorators/methods.d.ts +128 -6
- package/dist/decorators/methods.d.ts.map +1 -1
- package/dist/decorators/methods.js +124 -0
- package/dist/decorators/methods.js.map +1 -1
- package/dist/decorators/responses.d.ts +5 -0
- package/dist/decorators/responses.d.ts.map +1 -1
- package/dist/decorators/responses.js +43 -2
- package/dist/decorators/responses.js.map +1 -1
- package/dist/decorators/security.d.ts +6 -0
- package/dist/decorators/security.d.ts.map +1 -1
- package/dist/decorators/security.js +38 -2
- package/dist/decorators/security.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/integrations/metal-orm/schema/column-map.d.ts +91 -0
- package/dist/integrations/metal-orm/schema/column-map.d.ts.map +1 -1
- package/dist/integrations/metal-orm/schema/column-map.js +129 -2
- package/dist/integrations/metal-orm/schema/column-map.js.map +1 -1
- package/dist/integrations/metal-orm/schema/dto.d.ts +2 -2
- package/dist/integrations/metal-orm/schema/dto.d.ts.map +1 -1
- package/dist/integrations/metal-orm/schema/dto.js.map +1 -1
- package/dist/integrations/metal-orm/schema/entity.d.ts +90 -8
- package/dist/integrations/metal-orm/schema/entity.d.ts.map +1 -1
- package/dist/integrations/metal-orm/schema/entity.js +78 -6
- package/dist/integrations/metal-orm/schema/entity.js.map +1 -1
- package/dist/integrations/metal-orm/schema/filters.d.ts +1 -1
- package/dist/integrations/metal-orm/schema/filters.d.ts.map +1 -1
- package/dist/integrations/metal-orm/schema/filters.js +2 -1
- package/dist/integrations/metal-orm/schema/filters.js.map +1 -1
- package/dist/integrations/metal-orm/schema/tabledef.d.ts +1 -1
- package/dist/integrations/metal-orm/schema/tabledef.d.ts.map +1 -1
- package/dist/metadata/bag.d.ts +2 -1
- package/dist/metadata/bag.d.ts.map +1 -1
- package/dist/metadata/bag.js +2 -1
- package/dist/metadata/bag.js.map +1 -1
- package/dist/metadata/keys.d.ts +203 -1
- package/dist/metadata/keys.d.ts.map +1 -1
- package/dist/metadata/keys.js +3 -9
- package/dist/metadata/keys.js.map +1 -1
- package/dist/metadata/merge.d.ts.map +1 -1
- package/dist/metadata/merge.js +4 -1
- package/dist/metadata/merge.js.map +1 -1
- package/dist/validation/native/schema.d.ts +2 -2
- package/dist/validation/native/schema.d.ts.map +1 -1
- package/dist/validation/native/validator.d.ts +1 -1
- package/dist/validation/native/validator.d.ts.map +1 -1
- package/package.json +6 -2
|
@@ -1,5 +1,96 @@
|
|
|
1
1
|
import type { Schema } from '../../../validation/native/schema.js';
|
|
2
2
|
import type { ColumnDef } from 'metal-orm';
|
|
3
|
+
/**
|
|
4
|
+
* Maps Metal-ORM column definitions to validation schemas.
|
|
5
|
+
*
|
|
6
|
+
* This function converts database column types to appropriate
|
|
7
|
+
* validation schemas that can be used for request validation
|
|
8
|
+
* and data processing.
|
|
9
|
+
*
|
|
10
|
+
* @param column - Metal-ORM column definition
|
|
11
|
+
* @returns Validation schema appropriate for the column type
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* // Integer column
|
|
16
|
+
* const intColumn = { type: 'int', notNull: true };
|
|
17
|
+
* const intSchema = columnToSchema(intColumn);
|
|
18
|
+
* // Returns: v.number().int()
|
|
19
|
+
*
|
|
20
|
+
* // UUID column
|
|
21
|
+
* const uuidColumn = { type: 'uuid', notNull: false };
|
|
22
|
+
* const uuidSchema = columnToSchema(uuidColumn);
|
|
23
|
+
* // Returns: v.string().format('uuid')
|
|
24
|
+
*
|
|
25
|
+
* // DateTime column
|
|
26
|
+
* const dateColumn = { type: 'timestamp', notNull: true };
|
|
27
|
+
* const dateSchema = columnToSchema(dateColumn);
|
|
28
|
+
* // Returns: v.string().format('date-time')
|
|
29
|
+
*
|
|
30
|
+
* // VARCHAR with length
|
|
31
|
+
* const varcharColumn = { type: 'varchar', args: [255], notNull: true };
|
|
32
|
+
* const varcharSchema = columnToSchema(varcharColumn);
|
|
33
|
+
* // Returns: v.string().max(255)
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* // Using in entity schema generation
|
|
39
|
+
* import { entity } from './entity';
|
|
40
|
+
* import { columnToSchema } from './column-map';
|
|
41
|
+
*
|
|
42
|
+
* // Custom entity schema with column mapping
|
|
43
|
+
* function customEntitySchema(Entity: EntityCtor<any>) {
|
|
44
|
+
* const table = tableDefOf(Entity);
|
|
45
|
+
* const shape: Record<string, Schema<any>> = {};
|
|
46
|
+
*
|
|
47
|
+
* for (const [key, column] of Object.entries(table.columns)) {
|
|
48
|
+
* const schema = columnToSchema(column);
|
|
49
|
+
* shape[key] = column.notNull ? schema : v.optional(schema);
|
|
50
|
+
* }
|
|
51
|
+
*
|
|
52
|
+
* return v.object(shape);
|
|
53
|
+
* }
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @see entity for complete entity schema generation
|
|
57
|
+
* @see ValidationResult for validation result structure
|
|
58
|
+
*/
|
|
3
59
|
export declare function columnToSchema(column: ColumnDef): Schema<unknown>;
|
|
60
|
+
/**
|
|
61
|
+
* Checks if a column is required (not nullable).
|
|
62
|
+
*
|
|
63
|
+
* @param column - Metal-ORM column definition
|
|
64
|
+
* @returns true if column is required (notNull), false otherwise
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* // Required column
|
|
69
|
+
* const requiredColumn = { type: 'string', notNull: true };
|
|
70
|
+
* const isRequired = isRequiredColumn(requiredColumn); // true
|
|
71
|
+
*
|
|
72
|
+
* // Optional column
|
|
73
|
+
* const optionalColumn = { type: 'string', notNull: false };
|
|
74
|
+
* const isOptional = isRequiredColumn(optionalColumn); // false
|
|
75
|
+
* ```
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* // Using in schema generation
|
|
80
|
+
* function generateSchemaFromTable(table: TableDef) {
|
|
81
|
+
* const shape: Record<string, Schema<any>> = {};
|
|
82
|
+
*
|
|
83
|
+
* for (const [key, column] of Object.entries(table.columns)) {
|
|
84
|
+
* const schema = columnToSchema(column);
|
|
85
|
+
* const required = isRequiredColumn(column);
|
|
86
|
+
* shape[key] = required ? schema : v.optional(schema);
|
|
87
|
+
* }
|
|
88
|
+
*
|
|
89
|
+
* return v.object(shape);
|
|
90
|
+
* }
|
|
91
|
+
* ```
|
|
92
|
+
*
|
|
93
|
+
* @see columnToSchema for column type mapping
|
|
94
|
+
*/
|
|
4
95
|
export declare function isRequiredColumn(column: ColumnDef): boolean;
|
|
5
96
|
//# sourceMappingURL=column-map.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"column-map.d.ts","sourceRoot":"","sources":["../../../../src/integrations/metal-orm/schema/column-map.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sCAAsC,CAAC;AAEnE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"column-map.d.ts","sourceRoot":"","sources":["../../../../src/integrations/metal-orm/schema/column-map.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sCAAsC,CAAC;AAEnE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAyE3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,CAwDjE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAE3D"}
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { v } from '../../../validation/native/schema.js';
|
|
2
|
+
/**
|
|
3
|
+
* Database column type categories for schema mapping.
|
|
4
|
+
*
|
|
5
|
+
* These sets categorize database column types for
|
|
6
|
+
* appropriate schema generation.
|
|
7
|
+
*/
|
|
2
8
|
const INTEGER_TYPES = new Set(['int', 'integer', 'bigint']);
|
|
3
9
|
const DECIMAL_TYPES = new Set(['decimal', 'numeric', 'float', 'double', 'real']);
|
|
4
10
|
const STRING_TYPES = new Set(['char', 'text', 'enum']);
|
|
@@ -6,18 +12,48 @@ const BOOLEAN_TYPES = new Set(['boolean', 'bool']);
|
|
|
6
12
|
const DATE_TIME_TYPES = new Set(['date', 'datetime', 'timestamp', 'timestamptz', 'time', 'timetz']);
|
|
7
13
|
const JSON_TYPES = new Set(['json', 'jsonb']);
|
|
8
14
|
const BINARY_TYPES = new Set(['blob', 'binary', 'varbinary', 'bytea']);
|
|
15
|
+
/**
|
|
16
|
+
* Helper function to create successful validation results.
|
|
17
|
+
*
|
|
18
|
+
* @template T - The value type
|
|
19
|
+
* @param value - The validated value
|
|
20
|
+
* @returns Validation result with ok: true
|
|
21
|
+
*/
|
|
9
22
|
function ok(value) {
|
|
10
23
|
return { ok: true, value };
|
|
11
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Creates a base string schema.
|
|
27
|
+
*
|
|
28
|
+
* @returns Basic string validation schema
|
|
29
|
+
*/
|
|
12
30
|
function baseStringSchema() {
|
|
13
31
|
return v.string();
|
|
14
32
|
}
|
|
15
|
-
|
|
33
|
+
/**
|
|
34
|
+
* Creates a base number schema.
|
|
35
|
+
*
|
|
36
|
+
* @returns Basic number validation schema
|
|
37
|
+
*/
|
|
38
|
+
function _baseNumberSchema() {
|
|
16
39
|
return v.number();
|
|
17
40
|
}
|
|
18
|
-
|
|
41
|
+
/**
|
|
42
|
+
* Creates a base boolean schema.
|
|
43
|
+
*
|
|
44
|
+
* @returns Basic boolean validation schema
|
|
45
|
+
*/
|
|
46
|
+
function _baseBooleanSchema() {
|
|
19
47
|
return v.boolean();
|
|
20
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Creates a schema that accepts any value.
|
|
51
|
+
*
|
|
52
|
+
* Used for JSON/BLOB columns that can contain
|
|
53
|
+
* arbitrary data structures.
|
|
54
|
+
*
|
|
55
|
+
* @returns Schema that validates any value
|
|
56
|
+
*/
|
|
21
57
|
function anySchema() {
|
|
22
58
|
return {
|
|
23
59
|
kind: 'object',
|
|
@@ -28,6 +64,62 @@ function anySchema() {
|
|
|
28
64
|
},
|
|
29
65
|
};
|
|
30
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Maps Metal-ORM column definitions to validation schemas.
|
|
69
|
+
*
|
|
70
|
+
* This function converts database column types to appropriate
|
|
71
|
+
* validation schemas that can be used for request validation
|
|
72
|
+
* and data processing.
|
|
73
|
+
*
|
|
74
|
+
* @param column - Metal-ORM column definition
|
|
75
|
+
* @returns Validation schema appropriate for the column type
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* // Integer column
|
|
80
|
+
* const intColumn = { type: 'int', notNull: true };
|
|
81
|
+
* const intSchema = columnToSchema(intColumn);
|
|
82
|
+
* // Returns: v.number().int()
|
|
83
|
+
*
|
|
84
|
+
* // UUID column
|
|
85
|
+
* const uuidColumn = { type: 'uuid', notNull: false };
|
|
86
|
+
* const uuidSchema = columnToSchema(uuidColumn);
|
|
87
|
+
* // Returns: v.string().format('uuid')
|
|
88
|
+
*
|
|
89
|
+
* // DateTime column
|
|
90
|
+
* const dateColumn = { type: 'timestamp', notNull: true };
|
|
91
|
+
* const dateSchema = columnToSchema(dateColumn);
|
|
92
|
+
* // Returns: v.string().format('date-time')
|
|
93
|
+
*
|
|
94
|
+
* // VARCHAR with length
|
|
95
|
+
* const varcharColumn = { type: 'varchar', args: [255], notNull: true };
|
|
96
|
+
* const varcharSchema = columnToSchema(varcharColumn);
|
|
97
|
+
* // Returns: v.string().max(255)
|
|
98
|
+
* ```
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```typescript
|
|
102
|
+
* // Using in entity schema generation
|
|
103
|
+
* import { entity } from './entity';
|
|
104
|
+
* import { columnToSchema } from './column-map';
|
|
105
|
+
*
|
|
106
|
+
* // Custom entity schema with column mapping
|
|
107
|
+
* function customEntitySchema(Entity: EntityCtor<any>) {
|
|
108
|
+
* const table = tableDefOf(Entity);
|
|
109
|
+
* const shape: Record<string, Schema<any>> = {};
|
|
110
|
+
*
|
|
111
|
+
* for (const [key, column] of Object.entries(table.columns)) {
|
|
112
|
+
* const schema = columnToSchema(column);
|
|
113
|
+
* shape[key] = column.notNull ? schema : v.optional(schema);
|
|
114
|
+
* }
|
|
115
|
+
*
|
|
116
|
+
* return v.object(shape);
|
|
117
|
+
* }
|
|
118
|
+
* ```
|
|
119
|
+
*
|
|
120
|
+
* @see entity for complete entity schema generation
|
|
121
|
+
* @see ValidationResult for validation result structure
|
|
122
|
+
*/
|
|
31
123
|
export function columnToSchema(column) {
|
|
32
124
|
const rawType = String(column.type ?? '').toLowerCase();
|
|
33
125
|
const normalizedType = rawType.split('(')[0].trim();
|
|
@@ -74,6 +166,41 @@ export function columnToSchema(column) {
|
|
|
74
166
|
}
|
|
75
167
|
return baseStringSchema();
|
|
76
168
|
}
|
|
169
|
+
/**
|
|
170
|
+
* Checks if a column is required (not nullable).
|
|
171
|
+
*
|
|
172
|
+
* @param column - Metal-ORM column definition
|
|
173
|
+
* @returns true if column is required (notNull), false otherwise
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```typescript
|
|
177
|
+
* // Required column
|
|
178
|
+
* const requiredColumn = { type: 'string', notNull: true };
|
|
179
|
+
* const isRequired = isRequiredColumn(requiredColumn); // true
|
|
180
|
+
*
|
|
181
|
+
* // Optional column
|
|
182
|
+
* const optionalColumn = { type: 'string', notNull: false };
|
|
183
|
+
* const isOptional = isRequiredColumn(optionalColumn); // false
|
|
184
|
+
* ```
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* ```typescript
|
|
188
|
+
* // Using in schema generation
|
|
189
|
+
* function generateSchemaFromTable(table: TableDef) {
|
|
190
|
+
* const shape: Record<string, Schema<any>> = {};
|
|
191
|
+
*
|
|
192
|
+
* for (const [key, column] of Object.entries(table.columns)) {
|
|
193
|
+
* const schema = columnToSchema(column);
|
|
194
|
+
* const required = isRequiredColumn(column);
|
|
195
|
+
* shape[key] = required ? schema : v.optional(schema);
|
|
196
|
+
* }
|
|
197
|
+
*
|
|
198
|
+
* return v.object(shape);
|
|
199
|
+
* }
|
|
200
|
+
* ```
|
|
201
|
+
*
|
|
202
|
+
* @see columnToSchema for column type mapping
|
|
203
|
+
*/
|
|
77
204
|
export function isRequiredColumn(column) {
|
|
78
205
|
return Boolean(column.notNull);
|
|
79
206
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"column-map.js","sourceRoot":"","sources":["../../../../src/integrations/metal-orm/schema/column-map.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,sCAAsC,CAAC;AAKzD,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC;AAC5D,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC;AACjF,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,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GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IACtD,CAAC;IAED,IAAI,YAAY,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE,CAAC;QACrC,OAAO,gBAAgB,EAAE,CAAC;IAC5B,CAAC;IAED,IAAI,UAAU,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE,CAAC;QACnC,OAAO,SAAS,EAAE,CAAC;IACrB,CAAC;IAED,IAAI,YAAY,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE,CAAC;QACrC,MAAM,MAAM,GAAG,gBAAgB,EAAE,CAAC;QAClC,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,IAAI,cAAc,KAAK,MAAM,EAAE,CAAC;QAC9B,OAAO,gBAAgB,EAAE,CAAC;IAC5B,CAAC;IAED,OAAO,gBAAgB,EAAE,CAAC;AAC5B,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAiB;IAChD,OAAO,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AACjC,CAAC"}
|
|
@@ -2,6 +2,6 @@ import type { Schema } from '../../../validation/native/schema.js';
|
|
|
2
2
|
import { type EntityCtor } from './tabledef.js';
|
|
3
3
|
import type { SaveGraphInputPayload } from 'metal-orm';
|
|
4
4
|
export type DtoMode = 'create' | 'update';
|
|
5
|
-
export
|
|
6
|
-
export declare function entityDto<T>(Entity: EntityCtor<T>, mode:
|
|
5
|
+
export type EntityDtoSchema<T, Mode extends DtoMode> = Mode extends 'create' ? Schema<SaveGraphInputPayload<T>> : Schema<Partial<SaveGraphInputPayload<T>>>;
|
|
6
|
+
export declare function entityDto<T, Mode extends DtoMode>(Entity: EntityCtor<T>, mode: Mode): EntityDtoSchema<T, Mode>;
|
|
7
7
|
//# sourceMappingURL=dto.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dto.d.ts","sourceRoot":"","sources":["../../../../src/integrations/metal-orm/schema/dto.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sCAAsC,CAAC;AACnE,OAAO,EAAc,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC;AAE5D,OAAO,KAAK,EAAa,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAElE,MAAM,MAAM,OAAO,GAAG,QAAQ,GAAG,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"dto.d.ts","sourceRoot":"","sources":["../../../../src/integrations/metal-orm/schema/dto.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sCAAsC,CAAC;AACnE,OAAO,EAAc,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC;AAE5D,OAAO,KAAK,EAAa,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAElE,MAAM,MAAM,OAAO,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAE1C,MAAM,MAAM,eAAe,CAAC,CAAC,EAAE,IAAI,SAAS,OAAO,IACjD,IAAI,SAAS,QAAQ,GACjB,MAAM,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,GAChC,MAAM,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAahD,wBAAgB,SAAS,CAAC,CAAC,EAAE,IAAI,SAAS,OAAO,EAC/C,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,EACrB,IAAI,EAAE,IAAI,GACT,eAAe,CAAC,CAAC,EAAE,IAAI,CAAC,CAqB1B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dto.js","sourceRoot":"","sources":["../../../../src/integrations/metal-orm/schema/dto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,CAAC,EAAE,MAAM,sCAAsC,CAAC;AAEnE,OAAO,EAAE,UAAU,EA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C,MAAM,CAAC,CAAC;YAC9B,SAAS;QACX,CAAC;QAED,MAAM,QAAQ,GAAG,mBAAmB,CAAC,MAAM,CAAC,CAAC;QAC7C,KAAK,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IACpD,CAAC;IAED,MAAM,IAAI,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;IACtC,OAAO,IAAgC,CAAC;AAC1C,CAAC"}
|
|
@@ -1,17 +1,99 @@
|
|
|
1
1
|
import type { Schema } from '../../../validation/native/schema.js';
|
|
2
2
|
import { type EntityCtor } from './tabledef.js';
|
|
3
|
+
/**
|
|
4
|
+
* Options for customizing entity schema generation.
|
|
5
|
+
*
|
|
6
|
+
* These options allow selecting specific columns, excluding columns,
|
|
7
|
+
* and naming the generated schema.
|
|
8
|
+
*/
|
|
3
9
|
export type EntitySchemaOptions = {
|
|
10
|
+
/** Array of column names to include (exclusive selection) */
|
|
4
11
|
pick?: readonly string[];
|
|
12
|
+
/** Array of column names to exclude */
|
|
5
13
|
omit?: readonly string[];
|
|
14
|
+
/** Optional name for the generated schema */
|
|
6
15
|
name?: string;
|
|
7
16
|
};
|
|
17
|
+
/**
|
|
18
|
+
* Generates a validation schema from a Metal-ORM entity.
|
|
19
|
+
*
|
|
20
|
+
* This function creates a Schema object that validates data against
|
|
21
|
+
* the structure of a Metal-ORM entity, including column types,
|
|
22
|
+
* nullability constraints, and other database-level validations.
|
|
23
|
+
*
|
|
24
|
+
* @template T - The entity type
|
|
25
|
+
* @param Entity - Metal-ORM entity constructor
|
|
26
|
+
* @param opts - Options for customizing schema generation
|
|
27
|
+
* @returns Schema that validates against the entity structure
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* // Basic entity schema
|
|
32
|
+
* const userSchema = entity(User);
|
|
33
|
+
*
|
|
34
|
+
* // Schema with selected columns only
|
|
35
|
+
* const userProfileSchema = entity(User, {
|
|
36
|
+
* pick: ['id', 'name', 'email', 'avatarUrl']
|
|
37
|
+
* });
|
|
38
|
+
*
|
|
39
|
+
* // Schema with excluded columns
|
|
40
|
+
* const userPublicSchema = entity(User, {
|
|
41
|
+
* omit: ['passwordHash', 'emailVerificationToken']
|
|
42
|
+
* });
|
|
43
|
+
*
|
|
44
|
+
* // Named schema
|
|
45
|
+
* const createUserSchema = entity(User, {
|
|
46
|
+
* name: 'CreateUserDto',
|
|
47
|
+
* omit: ['id', 'createdAt', 'updatedAt']
|
|
48
|
+
* });
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* // Using in a controller with validation
|
|
54
|
+
* @Post('/users')
|
|
55
|
+
* async createUser(@Body() userData: unknown) {
|
|
56
|
+
* const userSchema = entity(User, {
|
|
57
|
+
* omit: ['id', 'createdAt', 'updatedAt']
|
|
58
|
+
* });
|
|
59
|
+
*
|
|
60
|
+
* const validationResult = await validator.validate(userData, userSchema);
|
|
61
|
+
* if (!validationResult.ok) {
|
|
62
|
+
* throw ValidationError.fromIssues(validationResult.issues);
|
|
63
|
+
* }
|
|
64
|
+
*
|
|
65
|
+
* const createdUser = await userService.create(validationResult.value);
|
|
66
|
+
* return reply(201, createdUser);
|
|
67
|
+
* }
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* @see Schema for the returned schema type
|
|
71
|
+
* @see EntityCtor for Metal-ORM entity constructor type
|
|
72
|
+
*/
|
|
8
73
|
export declare function entity<T>(Entity: EntityCtor<T>, opts?: EntitySchemaOptions): Schema<T>;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
74
|
+
/**
|
|
75
|
+
* Generates a validation schema for an array of entities.
|
|
76
|
+
*
|
|
77
|
+
* @template T - The entity type
|
|
78
|
+
* @param Entity - Metal-ORM entity constructor
|
|
79
|
+
* @param opts - Options for customizing schema generation
|
|
80
|
+
* @returns Schema that validates an array of entities
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* // Array of users
|
|
85
|
+
* const usersArraySchema = entityArray(User);
|
|
86
|
+
*
|
|
87
|
+
* // Array with selected columns
|
|
88
|
+
* const userPreviewsSchema = entityArray(User, {
|
|
89
|
+
* pick: ['id', 'name', 'email']
|
|
90
|
+
* });
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
export declare function entityArray<T>(Entity: EntityCtor<T>, opts?: EntitySchemaOptions): Schema<T[]> & {
|
|
94
|
+
min(n: number): Schema<T[]> & /*elided*/ any;
|
|
95
|
+
max(n: number): Schema<T[]> & /*elided*/ any;
|
|
96
|
+
optional(): Schema<T[] | undefined>;
|
|
97
|
+
nullable(): Schema<T[] | null>;
|
|
98
|
+
};
|
|
17
99
|
//# sourceMappingURL=entity.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity.d.ts","sourceRoot":"","sources":["../../../../src/integrations/metal-orm/schema/entity.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sCAAsC,CAAC;AAEnE,OAAO,EAAc,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC;AAG5D,MAAM,MAAM,mBAAmB,GAAG;IAChC,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACzB,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,IAAI,GAAE,mBAAwB,GAAG,MAAM,CAAC,CAAC,CAAC,CAkB1F;AAED
|
|
1
|
+
{"version":3,"file":"entity.d.ts","sourceRoot":"","sources":["../../../../src/integrations/metal-orm/schema/entity.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sCAAsC,CAAC;AAEnE,OAAO,EAAc,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC;AAG5D;;;;;GAKG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC,6DAA6D;IAC7D,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACzB,uCAAuC;IACvC,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACzB,6CAA6C;IAC7C,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,IAAI,GAAE,mBAAwB,GAAG,MAAM,CAAC,CAAC,CAAC,CAkB1F;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,IAAI,GAAE,mBAAwB;;;;;EAEnF"}
|
|
@@ -1,6 +1,62 @@
|
|
|
1
1
|
import { optional, v } from '../../../validation/native/schema.js';
|
|
2
2
|
import { columnToSchema } from './column-map.js';
|
|
3
3
|
import { tableDefOf } from './tabledef.js';
|
|
4
|
+
/**
|
|
5
|
+
* Generates a validation schema from a Metal-ORM entity.
|
|
6
|
+
*
|
|
7
|
+
* This function creates a Schema object that validates data against
|
|
8
|
+
* the structure of a Metal-ORM entity, including column types,
|
|
9
|
+
* nullability constraints, and other database-level validations.
|
|
10
|
+
*
|
|
11
|
+
* @template T - The entity type
|
|
12
|
+
* @param Entity - Metal-ORM entity constructor
|
|
13
|
+
* @param opts - Options for customizing schema generation
|
|
14
|
+
* @returns Schema that validates against the entity structure
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* // Basic entity schema
|
|
19
|
+
* const userSchema = entity(User);
|
|
20
|
+
*
|
|
21
|
+
* // Schema with selected columns only
|
|
22
|
+
* const userProfileSchema = entity(User, {
|
|
23
|
+
* pick: ['id', 'name', 'email', 'avatarUrl']
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* // Schema with excluded columns
|
|
27
|
+
* const userPublicSchema = entity(User, {
|
|
28
|
+
* omit: ['passwordHash', 'emailVerificationToken']
|
|
29
|
+
* });
|
|
30
|
+
*
|
|
31
|
+
* // Named schema
|
|
32
|
+
* const createUserSchema = entity(User, {
|
|
33
|
+
* name: 'CreateUserDto',
|
|
34
|
+
* omit: ['id', 'createdAt', 'updatedAt']
|
|
35
|
+
* });
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* // Using in a controller with validation
|
|
41
|
+
* @Post('/users')
|
|
42
|
+
* async createUser(@Body() userData: unknown) {
|
|
43
|
+
* const userSchema = entity(User, {
|
|
44
|
+
* omit: ['id', 'createdAt', 'updatedAt']
|
|
45
|
+
* });
|
|
46
|
+
*
|
|
47
|
+
* const validationResult = await validator.validate(userData, userSchema);
|
|
48
|
+
* if (!validationResult.ok) {
|
|
49
|
+
* throw ValidationError.fromIssues(validationResult.issues);
|
|
50
|
+
* }
|
|
51
|
+
*
|
|
52
|
+
* const createdUser = await userService.create(validationResult.value);
|
|
53
|
+
* return reply(201, createdUser);
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* @see Schema for the returned schema type
|
|
58
|
+
* @see EntityCtor for Metal-ORM entity constructor type
|
|
59
|
+
*/
|
|
4
60
|
export function entity(Entity, opts = {}) {
|
|
5
61
|
const table = tableDefOf(Entity);
|
|
6
62
|
const pick = opts.pick ? new Set(opts.pick) : null;
|
|
@@ -18,10 +74,26 @@ export function entity(Entity, opts = {}) {
|
|
|
18
74
|
const typed = base;
|
|
19
75
|
return opts.name ? v.named(opts.name, typed) : typed;
|
|
20
76
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
77
|
+
/**
|
|
78
|
+
* Generates a validation schema for an array of entities.
|
|
79
|
+
*
|
|
80
|
+
* @template T - The entity type
|
|
81
|
+
* @param Entity - Metal-ORM entity constructor
|
|
82
|
+
* @param opts - Options for customizing schema generation
|
|
83
|
+
* @returns Schema that validates an array of entities
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```typescript
|
|
87
|
+
* // Array of users
|
|
88
|
+
* const usersArraySchema = entityArray(User);
|
|
89
|
+
*
|
|
90
|
+
* // Array with selected columns
|
|
91
|
+
* const userPreviewsSchema = entityArray(User, {
|
|
92
|
+
* pick: ['id', 'name', 'email']
|
|
93
|
+
* });
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
export function entityArray(Entity, opts = {}) {
|
|
97
|
+
return v.array(entity(Entity, opts));
|
|
98
|
+
}
|
|
27
99
|
//# sourceMappingURL=entity.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity.js","sourceRoot":"","sources":["../../../../src/integrations/metal-orm/schema/entity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,CAAC,EAAE,MAAM,sCAAsC,CAAC;AAEnE,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAmB,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"entity.js","sourceRoot":"","sources":["../../../../src/integrations/metal-orm/schema/entity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,CAAC,EAAE,MAAM,sCAAsC,CAAC;AAEnE,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAmB,MAA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ACvD,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,WAAW,CAAI,MAAqB,EAAE,OAA4B,EAAE;IAClF,OAAO,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;AACvC,CAAC"}
|
|
@@ -5,7 +5,7 @@ export type FiltersOptions<P extends readonly (string & PropertyKey)[]> = {
|
|
|
5
5
|
pick: P;
|
|
6
6
|
paging?: boolean;
|
|
7
7
|
};
|
|
8
|
-
export declare function filtersFromEntity<T, const P extends readonly (keyof T & string)[], const Opts extends FiltersOptions<P>>(Entity: EntityCtor<T>, opts: Opts): Schema<(Opts['paging'] extends false ?
|
|
8
|
+
export declare function filtersFromEntity<T, const P extends readonly (keyof T & string)[], const Opts extends FiltersOptions<P>>(Entity: EntityCtor<T>, opts: Opts): Schema<(Opts['paging'] extends false ? Record<string, never> : Paged) & Partial<{
|
|
9
9
|
[K in P[number]]: HttpPick<T, K>;
|
|
10
10
|
}>>;
|
|
11
11
|
//# sourceMappingURL=filters.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filters.d.ts","sourceRoot":"","sources":["../../../../src/integrations/metal-orm/schema/filters.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sCAAsC,CAAC;AACnE,OAAO,EAAc,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"filters.d.ts","sourceRoot":"","sources":["../../../../src/integrations/metal-orm/schema/filters.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sCAAsC,CAAC;AACnE,OAAO,EAAc,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC;AAG5D,OAAO,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAElD,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,SAAS,CAAC,MAAM,GAAG,WAAW,CAAC,EAAE,IAAI;IACxE,IAAI,EAAE,CAAC,CAAC;IACR,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,wBAAgB,iBAAiB,CAC/B,CAAC,EACD,KAAK,CAAC,CAAC,SAAS,SAAS,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,EAAE,EAC7C,KAAK,CAAC,IAAI,SAAS,cAAc,CAAC,CAAC,CAAC,EAEpC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,EACrB,IAAI,EAAE,IAAI,GACT,MAAM,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,KAAK,CAAC,GAAG,OAAO,CAAC;KAAG,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,GAAG,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC;CAAE,CAAC,CAAC,CAmBxH"}
|
|
@@ -8,8 +8,9 @@ export function filtersFromEntity(Entity, opts) {
|
|
|
8
8
|
shape.page = v.number().int().min(1).optional();
|
|
9
9
|
shape.pageSize = v.number().int().min(1).max(100).optional();
|
|
10
10
|
}
|
|
11
|
+
const columns = table.columns;
|
|
11
12
|
for (const key of opts.pick) {
|
|
12
|
-
const column =
|
|
13
|
+
const column = columns[key];
|
|
13
14
|
if (!column)
|
|
14
15
|
continue;
|
|
15
16
|
shape[key] = optional(columnToSchema(column));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filters.js","sourceRoot":"","sources":["../../../../src/integrations/metal-orm/schema/filters.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,CAAC,EAAE,MAAM,sCAAsC,CAAC;AAEnE,OAAO,EAAE,UAAU,EAAmB,MAAM,eAAe,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"filters.js","sourceRoot":"","sources":["../../../../src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Ctor<T = unknown> = new (...args: unknown[]) => T;
|
|
3
3
|
export declare function tableDefOf<T>(Entity: EntityCtor<T>): TableDef;
|
|
4
4
|
//# sourceMappingURL=tabledef.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tabledef.d.ts","sourceRoot":"","sources":["../../../../src/integrations/metal-orm/schema/tabledef.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAqB,QAAQ,EAAE,MAAM,WAAW,CAAC;AAE7D,MAAM,MAAM,UAAU,CAAC,CAAC,GAAG,
|
|
1
|
+
{"version":3,"file":"tabledef.d.ts","sourceRoot":"","sources":["../../../../src/integrations/metal-orm/schema/tabledef.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAqB,QAAQ,EAAE,MAAM,WAAW,CAAC;AAE7D,MAAM,MAAM,UAAU,CAAC,CAAC,GAAG,OAAO,IAAI,KAAK,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;AAEpE,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,QAAQ,CAO7D"}
|
package/dist/metadata/bag.d.ts
CHANGED
|
@@ -5,10 +5,11 @@
|
|
|
5
5
|
* We treat the metadata as an open bag: Record<PropertyKey, unknown>.
|
|
6
6
|
*/
|
|
7
7
|
export type MetaBag = Record<PropertyKey, unknown>;
|
|
8
|
+
export type MetaConstructor = new (...args: never[]) => unknown;
|
|
8
9
|
export declare function bagFromContext(context: {
|
|
9
10
|
metadata?: object | undefined;
|
|
10
11
|
}): MetaBag;
|
|
11
|
-
export declare function bagFromClass(ctor:
|
|
12
|
+
export declare function bagFromClass(ctor: MetaConstructor): MetaBag;
|
|
12
13
|
export declare function bagGet<T>(bag: MetaBag, key: PropertyKey): T | undefined;
|
|
13
14
|
export declare function bagSet<T>(bag: MetaBag, key: PropertyKey, value: T): void;
|
|
14
15
|
export declare function bagEnsureObject<T extends object>(bag: MetaBag, key: PropertyKey, init: () => T): T;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bag.d.ts","sourceRoot":"","sources":["../../src/metadata/bag.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;AAEnD,wBAAgB,cAAc,CAAC,OAAO,EAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,GAAG,OAAO,CAMlF;
|
|
1
|
+
{"version":3,"file":"bag.d.ts","sourceRoot":"","sources":["../../src/metadata/bag.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;AAEnD,MAAM,MAAM,eAAe,GAAG,KAAK,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,CAAC;AAEhE,wBAAgB,cAAc,CAAC,OAAO,EAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,GAAG,OAAO,CAMlF;AAMD,wBAAgB,YAAY,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAG3D;AAED,wBAAgB,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,WAAW,GAAG,CAAC,GAAG,SAAS,CAEvE;AAED,wBAAgB,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,CAExE;AAED,wBAAgB,eAAe,CAAC,CAAC,SAAS,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,CAMlG;AAED,wBAAgB,cAAc,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,WAAW,GAAG,CAAC,EAAE,CAMrE;AAED,wBAAgB,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,GAAG,IAAI,CAGxE"}
|
package/dist/metadata/bag.js
CHANGED
|
@@ -7,7 +7,8 @@ export function bagFromContext(context) {
|
|
|
7
7
|
return target.metadata;
|
|
8
8
|
}
|
|
9
9
|
export function bagFromClass(ctor) {
|
|
10
|
-
|
|
10
|
+
const ctorWithMeta = ctor;
|
|
11
|
+
return (ctorWithMeta[SYMBOL_METADATA] ?? {});
|
|
11
12
|
}
|
|
12
13
|
export function bagGet(bag, key) {
|
|
13
14
|
return bag[key];
|
package/dist/metadata/bag.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bag.js","sourceRoot":"","sources":["../../src/metadata/bag.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"bag.js","sourceRoot":"","sources":["../../src/metadata/bag.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAY5C,MAAM,UAAU,cAAc,CAAC,OAA0C;IACvE,MAAM,MAAM,GAAG,OAAgC,CAAC;IAChD,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;QACrB,MAAM,CAAC,QAAQ,GAAG,EAAE,CAAC;IACvB,CAAC;IACD,OAAO,MAAM,CAAC,QAA8B,CAAC;AAC/C,CAAC;AAMD,MAAM,UAAU,YAAY,CAAC,IAAqB;IAChD,MAAM,YAAY,GAAG,IAA+B,CAAC;IACrD,OAAO,CAAC,YAAY,CAAC,eAAe,CAAC,IAAI,EAAE,CAAY,CAAC;AAC1D,CAAC;AAED,MAAM,UAAU,MAAM,CAAI,GAAY,EAAE,GAAgB;IACtD,OAAO,GAAG,CAAC,GAAG,CAAkB,CAAC;AACnC,CAAC;AAED,MAAM,UAAU,MAAM,CAAI,GAAY,EA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