@digitaldefiance/node-express-suite 3.11.31 → 3.12.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/README.md +858 -0
- package/package.json +1 -1
- package/src/controllers/openapi.d.ts +67 -0
- package/src/controllers/openapi.d.ts.map +1 -0
- package/src/controllers/openapi.js +89 -0
- package/src/controllers/openapi.js.map +1 -0
- package/src/decorators/auth.d.ts +128 -0
- package/src/decorators/auth.d.ts.map +1 -0
- package/src/decorators/auth.js +230 -0
- package/src/decorators/auth.js.map +1 -0
- package/src/decorators/base-controller.d.ts +144 -6
- package/src/decorators/base-controller.d.ts.map +1 -1
- package/src/decorators/base-controller.js +487 -31
- package/src/decorators/base-controller.js.map +1 -1
- package/src/decorators/controller.d.ts +63 -7
- package/src/decorators/controller.d.ts.map +1 -1
- package/src/decorators/controller.js +70 -39
- package/src/decorators/controller.js.map +1 -1
- package/src/decorators/handler-args.d.ts +68 -0
- package/src/decorators/handler-args.d.ts.map +1 -0
- package/src/decorators/handler-args.js +83 -0
- package/src/decorators/handler-args.js.map +1 -0
- package/src/decorators/http-methods.d.ts +143 -0
- package/src/decorators/http-methods.d.ts.map +1 -0
- package/src/decorators/http-methods.js +265 -0
- package/src/decorators/http-methods.js.map +1 -0
- package/src/decorators/index.d.ts +22 -0
- package/src/decorators/index.d.ts.map +1 -1
- package/src/decorators/index.js +56 -0
- package/src/decorators/index.js.map +1 -1
- package/src/decorators/lifecycle.d.ts +248 -0
- package/src/decorators/lifecycle.d.ts.map +1 -0
- package/src/decorators/lifecycle.js +301 -0
- package/src/decorators/lifecycle.js.map +1 -0
- package/src/decorators/metadata-collector.d.ts +175 -0
- package/src/decorators/metadata-collector.d.ts.map +1 -0
- package/src/decorators/metadata-collector.js +272 -0
- package/src/decorators/metadata-collector.js.map +1 -0
- package/src/decorators/metadata-keys.d.ts +121 -0
- package/src/decorators/metadata-keys.d.ts.map +1 -0
- package/src/decorators/metadata-keys.js +116 -0
- package/src/decorators/metadata-keys.js.map +1 -0
- package/src/decorators/middleware.d.ts +181 -0
- package/src/decorators/middleware.d.ts.map +1 -0
- package/src/decorators/middleware.js +400 -0
- package/src/decorators/middleware.js.map +1 -0
- package/src/decorators/openapi-params.d.ts +192 -0
- package/src/decorators/openapi-params.d.ts.map +1 -0
- package/src/decorators/openapi-params.js +332 -0
- package/src/decorators/openapi-params.js.map +1 -0
- package/src/decorators/openapi.d.ts +201 -0
- package/src/decorators/openapi.d.ts.map +1 -0
- package/src/decorators/openapi.js +334 -0
- package/src/decorators/openapi.js.map +1 -0
- package/src/decorators/params.d.ts +217 -0
- package/src/decorators/params.d.ts.map +1 -0
- package/src/decorators/params.js +323 -0
- package/src/decorators/params.js.map +1 -0
- package/src/decorators/response.d.ts +200 -0
- package/src/decorators/response.d.ts.map +1 -0
- package/src/decorators/response.js +315 -0
- package/src/decorators/response.js.map +1 -0
- package/src/decorators/schema.d.ts +99 -0
- package/src/decorators/schema.d.ts.map +1 -0
- package/src/decorators/schema.js +329 -0
- package/src/decorators/schema.js.map +1 -0
- package/src/decorators/transaction.d.ts +69 -0
- package/src/decorators/transaction.d.ts.map +1 -0
- package/src/decorators/transaction.js +80 -0
- package/src/decorators/transaction.js.map +1 -0
- package/src/decorators/validation.d.ts +188 -0
- package/src/decorators/validation.d.ts.map +1 -0
- package/src/decorators/validation.js +269 -0
- package/src/decorators/validation.js.map +1 -0
- package/src/decorators/zod-validation.d.ts +164 -4
- package/src/decorators/zod-validation.d.ts.map +1 -1
- package/src/decorators/zod-validation.js +692 -13
- package/src/decorators/zod-validation.js.map +1 -1
- package/src/index.d.ts +2 -1
- package/src/index.d.ts.map +1 -1
- package/src/index.js +1 -0
- package/src/index.js.map +1 -1
- package/src/interfaces/api-message-response.d.ts +1 -1
- package/src/interfaces/api-message-response.d.ts.map +1 -1
- package/src/interfaces/index.d.ts +1 -0
- package/src/interfaces/index.d.ts.map +1 -1
- package/src/interfaces/index.js +1 -0
- package/src/interfaces/index.js.map +1 -1
- package/src/interfaces/openApi/decoratorOptions.d.ts +760 -0
- package/src/interfaces/openApi/decoratorOptions.d.ts.map +1 -0
- package/src/interfaces/openApi/decoratorOptions.js +734 -0
- package/src/interfaces/openApi/decoratorOptions.js.map +1 -0
- package/src/interfaces/openApi/index.d.ts +8 -0
- package/src/interfaces/openApi/index.d.ts.map +1 -0
- package/src/interfaces/openApi/index.js +32 -0
- package/src/interfaces/openApi/index.js.map +1 -0
- package/src/interfaces/openApi/parameter.d.ts +41 -0
- package/src/interfaces/openApi/parameter.d.ts.map +1 -0
- package/src/interfaces/openApi/parameter.js +60 -0
- package/src/interfaces/openApi/parameter.js.map +1 -0
- package/src/interfaces/openApi/parameterSchema.d.ts +39 -0
- package/src/interfaces/openApi/parameterSchema.d.ts.map +1 -0
- package/src/interfaces/openApi/parameterSchema.js +51 -0
- package/src/interfaces/openApi/parameterSchema.js.map +1 -0
- package/src/interfaces/openApi/requestBody.d.ts +25 -0
- package/src/interfaces/openApi/requestBody.d.ts.map +1 -0
- package/src/interfaces/openApi/requestBody.js +31 -0
- package/src/interfaces/openApi/requestBody.js.map +1 -0
- package/src/interfaces/openApi/responseDef.d.ts +23 -0
- package/src/interfaces/openApi/responseDef.d.ts.map +1 -0
- package/src/interfaces/openApi/responseDef.js +29 -0
- package/src/interfaces/openApi/responseDef.js.map +1 -0
- package/src/interfaces/openApi/routeMetadata.d.ts +43 -0
- package/src/interfaces/openApi/routeMetadata.d.ts.map +1 -0
- package/src/interfaces/openApi/routeMetadata.js +85 -0
- package/src/interfaces/openApi/routeMetadata.js.map +1 -0
- package/src/openapi/builder.d.ts +249 -0
- package/src/openapi/builder.d.ts.map +1 -0
- package/src/openapi/builder.js +352 -0
- package/src/openapi/builder.js.map +1 -0
- package/src/openapi/controller.d.ts +153 -0
- package/src/openapi/controller.d.ts.map +1 -0
- package/src/openapi/controller.js +331 -0
- package/src/openapi/controller.js.map +1 -0
- package/src/openapi/index.d.ts +12 -0
- package/src/openapi/index.d.ts.map +1 -0
- package/src/openapi/index.js +20 -0
- package/src/openapi/index.js.map +1 -0
- package/src/openapi/markdown-generator.d.ts +52 -0
- package/src/openapi/markdown-generator.d.ts.map +1 -0
- package/src/openapi/markdown-generator.js +569 -0
- package/src/openapi/markdown-generator.js.map +1 -0
- package/src/openapi/middleware/index.d.ts +9 -0
- package/src/openapi/middleware/index.d.ts.map +1 -0
- package/src/openapi/middleware/index.js +15 -0
- package/src/openapi/middleware/index.js.map +1 -0
- package/src/openapi/middleware/redoc.d.ts +314 -0
- package/src/openapi/middleware/redoc.d.ts.map +1 -0
- package/src/openapi/middleware/redoc.js +181 -0
- package/src/openapi/middleware/redoc.js.map +1 -0
- package/src/openapi/middleware/swagger-ui.d.ts +123 -0
- package/src/openapi/middleware/swagger-ui.d.ts.map +1 -0
- package/src/openapi/middleware/swagger-ui.js +227 -0
- package/src/openapi/middleware/swagger-ui.js.map +1 -0
- package/src/openapi/schemas.d.ts +170 -0
- package/src/openapi/schemas.d.ts.map +1 -0
- package/src/openapi/schemas.js +340 -0
- package/src/openapi/schemas.js.map +1 -0
- package/src/registry/controller-registry.d.ts +78 -0
- package/src/registry/controller-registry.d.ts.map +1 -0
- package/src/registry/controller-registry.js +86 -0
- package/src/registry/controller-registry.js.map +1 -0
- package/src/registry/index.d.ts +2 -0
- package/src/registry/index.d.ts.map +1 -1
- package/src/registry/index.js +3 -1
- package/src/registry/index.js.map +1 -1
- package/src/routers/api.d.ts +2 -1
- package/src/routers/api.d.ts.map +1 -1
- package/src/routers/api.js +7 -1
- package/src/routers/api.js.map +1 -1
- package/src/routing/route-builder.d.ts +4 -4
- package/src/routing/route-builder.d.ts.map +1 -1
- package/src/routing/route-builder.js +1 -1
- package/src/types.d.ts +3 -1
- package/src/types.d.ts.map +1 -1
- package/src/types.js +1 -0
- package/src/types.js.map +1 -1
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Schema decorators for Express Suite.
|
|
4
|
+
* Provides @ApiSchema and @ApiProperty decorators for registering
|
|
5
|
+
* OpenAPI schemas declaratively from TypeScript classes.
|
|
6
|
+
* @module decorators/schema
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.ApiSchema = ApiSchema;
|
|
10
|
+
exports.ApiProperty = ApiProperty;
|
|
11
|
+
exports.getSchemaMetadata = getSchemaMetadata;
|
|
12
|
+
exports.getPropertyMetadata = getPropertyMetadata;
|
|
13
|
+
exports.getAllPropertyMetadata = getAllPropertyMetadata;
|
|
14
|
+
exports.hasSchemaMetadata = hasSchemaMetadata;
|
|
15
|
+
exports.registerSchema = registerSchema;
|
|
16
|
+
require("reflect-metadata");
|
|
17
|
+
const schemas_1 = require("../openapi/schemas");
|
|
18
|
+
const metadata_keys_1 = require("./metadata-keys");
|
|
19
|
+
const metadata_collector_1 = require("./metadata-collector");
|
|
20
|
+
/**
|
|
21
|
+
* Symbol key for storing property metadata on a class.
|
|
22
|
+
*/
|
|
23
|
+
const SCHEMA_PROPERTIES_METADATA = Symbol('schema:properties');
|
|
24
|
+
/**
|
|
25
|
+
* Decorator that registers a class as an OpenAPI schema.
|
|
26
|
+
* The class properties decorated with @ApiProperty will be converted
|
|
27
|
+
* to OpenAPI schema properties.
|
|
28
|
+
*
|
|
29
|
+
* @param options - Schema options including name, description, and example
|
|
30
|
+
* @returns Class decorator
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* @ApiSchema({ description: 'User entity' })
|
|
35
|
+
* class User {
|
|
36
|
+
* @ApiProperty({ type: 'string', description: 'User ID' })
|
|
37
|
+
* id: string;
|
|
38
|
+
*
|
|
39
|
+
* @ApiProperty({ type: 'string', format: 'email' })
|
|
40
|
+
* email: string;
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
function ApiSchema(options = {}) {
|
|
45
|
+
return (target) => {
|
|
46
|
+
const constructor = target;
|
|
47
|
+
// Get schema name from options or class name
|
|
48
|
+
const schemaName = options.name ?? constructor.name;
|
|
49
|
+
// Collect properties from this class and parent classes
|
|
50
|
+
const properties = collectAllProperties(constructor);
|
|
51
|
+
// Create schema metadata
|
|
52
|
+
const schemaMetadata = {
|
|
53
|
+
name: schemaName,
|
|
54
|
+
options,
|
|
55
|
+
properties,
|
|
56
|
+
};
|
|
57
|
+
// Store metadata on the class
|
|
58
|
+
(0, metadata_collector_1.setMetadata)(metadata_keys_1.SCHEMA_METADATA, schemaMetadata, target);
|
|
59
|
+
// Build and register the OpenAPI schema
|
|
60
|
+
const openApiSchema = buildOpenAPISchema(schemaMetadata);
|
|
61
|
+
schemas_1.OpenAPISchemaRegistry.registerSchema(schemaName, openApiSchema);
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Decorator that marks a class property for inclusion in the OpenAPI schema.
|
|
66
|
+
* Must be used in conjunction with @ApiSchema on the class.
|
|
67
|
+
*
|
|
68
|
+
* @param options - Property options including type, format, description, etc.
|
|
69
|
+
* @returns Property decorator
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```typescript
|
|
73
|
+
* class User {
|
|
74
|
+
* @ApiProperty({
|
|
75
|
+
* type: 'string',
|
|
76
|
+
* description: 'Unique identifier',
|
|
77
|
+
* example: '123e4567-e89b-12d3-a456-426614174000'
|
|
78
|
+
* })
|
|
79
|
+
* id: string;
|
|
80
|
+
*
|
|
81
|
+
* @ApiProperty({
|
|
82
|
+
* type: 'string',
|
|
83
|
+
* format: 'email',
|
|
84
|
+
* required: true
|
|
85
|
+
* })
|
|
86
|
+
* email: string;
|
|
87
|
+
*
|
|
88
|
+
* @ApiProperty({
|
|
89
|
+
* type: 'integer',
|
|
90
|
+
* minimum: 0,
|
|
91
|
+
* maximum: 150
|
|
92
|
+
* })
|
|
93
|
+
* age?: number;
|
|
94
|
+
* }
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
function ApiProperty(options = {}) {
|
|
98
|
+
return (target, propertyKey) => {
|
|
99
|
+
// Get the constructor (class) from the prototype
|
|
100
|
+
const constructor = target.constructor;
|
|
101
|
+
// Get existing properties or create new array
|
|
102
|
+
const existingProperties = Reflect.getMetadata(SCHEMA_PROPERTIES_METADATA, constructor) ?? [];
|
|
103
|
+
// Infer type from TypeScript metadata if not provided
|
|
104
|
+
const inferredOptions = inferPropertyType(target, propertyKey, options);
|
|
105
|
+
// Add this property
|
|
106
|
+
const propertyMetadata = {
|
|
107
|
+
propertyKey: String(propertyKey),
|
|
108
|
+
options: inferredOptions,
|
|
109
|
+
};
|
|
110
|
+
existingProperties.push(propertyMetadata);
|
|
111
|
+
// Store updated properties
|
|
112
|
+
Reflect.defineMetadata(SCHEMA_PROPERTIES_METADATA, existingProperties, constructor);
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Collects all properties from a class and its parent classes.
|
|
117
|
+
* Supports inheritance by walking up the prototype chain.
|
|
118
|
+
* Child class properties override parent class properties with the same name.
|
|
119
|
+
*
|
|
120
|
+
* @param target - The class constructor
|
|
121
|
+
* @returns Array of all property metadata
|
|
122
|
+
*/
|
|
123
|
+
function collectAllProperties(target) {
|
|
124
|
+
const propertyMap = new Map();
|
|
125
|
+
// Collect classes in order from parent to child
|
|
126
|
+
const classChain = [];
|
|
127
|
+
let currentClass = target;
|
|
128
|
+
while (currentClass && currentClass !== Function.prototype) {
|
|
129
|
+
classChain.unshift(currentClass); // Add to beginning so parents come first
|
|
130
|
+
currentClass = Object.getPrototypeOf(currentClass);
|
|
131
|
+
}
|
|
132
|
+
// Process from parent to child, so child properties override parent
|
|
133
|
+
for (const cls of classChain) {
|
|
134
|
+
const properties = Reflect.getMetadata(SCHEMA_PROPERTIES_METADATA, cls) ?? [];
|
|
135
|
+
for (const prop of properties) {
|
|
136
|
+
propertyMap.set(prop.propertyKey, prop);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return Array.from(propertyMap.values());
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Infers the OpenAPI type from TypeScript design:type metadata.
|
|
143
|
+
*
|
|
144
|
+
* @param target - The class prototype
|
|
145
|
+
* @param propertyKey - The property name
|
|
146
|
+
* @param options - User-provided options
|
|
147
|
+
* @returns Options with inferred type if not provided
|
|
148
|
+
*/
|
|
149
|
+
function inferPropertyType(target, propertyKey, options) {
|
|
150
|
+
// If type is already provided, use it
|
|
151
|
+
if (options.type) {
|
|
152
|
+
return options;
|
|
153
|
+
}
|
|
154
|
+
// Try to get TypeScript design:type metadata
|
|
155
|
+
const designType = Reflect.getMetadata('design:type', target, propertyKey);
|
|
156
|
+
if (!designType) {
|
|
157
|
+
return options;
|
|
158
|
+
}
|
|
159
|
+
// Map TypeScript types to OpenAPI types
|
|
160
|
+
const typeMap = {
|
|
161
|
+
String: 'string',
|
|
162
|
+
Number: 'number',
|
|
163
|
+
Boolean: 'boolean',
|
|
164
|
+
Array: 'array',
|
|
165
|
+
Object: 'object',
|
|
166
|
+
Date: 'string',
|
|
167
|
+
};
|
|
168
|
+
const inferredType = typeMap[designType.name];
|
|
169
|
+
if (inferredType) {
|
|
170
|
+
const result = { ...options, type: inferredType };
|
|
171
|
+
// Add format for Date
|
|
172
|
+
if (designType.name === 'Date' && !options.format) {
|
|
173
|
+
result.format = 'date-time';
|
|
174
|
+
}
|
|
175
|
+
return result;
|
|
176
|
+
}
|
|
177
|
+
return options;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Builds an OpenAPI schema object from schema metadata.
|
|
181
|
+
*
|
|
182
|
+
* @param metadata - The schema metadata
|
|
183
|
+
* @returns OpenAPI schema object
|
|
184
|
+
*/
|
|
185
|
+
function buildOpenAPISchema(metadata) {
|
|
186
|
+
const schema = {
|
|
187
|
+
type: 'object',
|
|
188
|
+
};
|
|
189
|
+
// Add description if provided
|
|
190
|
+
if (metadata.options.description) {
|
|
191
|
+
schema.description = metadata.options.description;
|
|
192
|
+
}
|
|
193
|
+
// Add example if provided
|
|
194
|
+
if (metadata.options.example !== undefined) {
|
|
195
|
+
schema.example = metadata.options.example;
|
|
196
|
+
}
|
|
197
|
+
// Build properties
|
|
198
|
+
const properties = {};
|
|
199
|
+
const required = [];
|
|
200
|
+
for (const prop of metadata.properties) {
|
|
201
|
+
const propSchema = buildPropertySchema(prop.options);
|
|
202
|
+
properties[prop.propertyKey] = propSchema;
|
|
203
|
+
// Track required properties
|
|
204
|
+
if (prop.options.required) {
|
|
205
|
+
required.push(prop.propertyKey);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
if (Object.keys(properties).length > 0) {
|
|
209
|
+
schema.properties = properties;
|
|
210
|
+
}
|
|
211
|
+
if (required.length > 0) {
|
|
212
|
+
schema.required = required;
|
|
213
|
+
}
|
|
214
|
+
return schema;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Builds an OpenAPI property schema from property options.
|
|
218
|
+
*
|
|
219
|
+
* @param options - The property options
|
|
220
|
+
* @returns OpenAPI property schema
|
|
221
|
+
*/
|
|
222
|
+
function buildPropertySchema(options) {
|
|
223
|
+
const schema = {};
|
|
224
|
+
// Handle $ref separately
|
|
225
|
+
if (options.$ref) {
|
|
226
|
+
return { $ref: `#/components/schemas/${options.$ref}` };
|
|
227
|
+
}
|
|
228
|
+
// Type
|
|
229
|
+
if (options.type) {
|
|
230
|
+
schema.type = options.type;
|
|
231
|
+
}
|
|
232
|
+
// Format
|
|
233
|
+
if (options.format) {
|
|
234
|
+
schema.format = options.format;
|
|
235
|
+
}
|
|
236
|
+
// Description
|
|
237
|
+
if (options.description) {
|
|
238
|
+
schema.description = options.description;
|
|
239
|
+
}
|
|
240
|
+
// Example
|
|
241
|
+
if (options.example !== undefined) {
|
|
242
|
+
schema.example = options.example;
|
|
243
|
+
}
|
|
244
|
+
// Enum
|
|
245
|
+
if (options.enum && options.enum.length > 0) {
|
|
246
|
+
schema.enum = options.enum;
|
|
247
|
+
}
|
|
248
|
+
// Nullable
|
|
249
|
+
if (options.nullable) {
|
|
250
|
+
schema.nullable = options.nullable;
|
|
251
|
+
}
|
|
252
|
+
// Numeric constraints
|
|
253
|
+
if (options.minimum !== undefined) {
|
|
254
|
+
schema.minimum = options.minimum;
|
|
255
|
+
}
|
|
256
|
+
if (options.maximum !== undefined) {
|
|
257
|
+
schema.maximum = options.maximum;
|
|
258
|
+
}
|
|
259
|
+
// String constraints
|
|
260
|
+
if (options.minLength !== undefined) {
|
|
261
|
+
schema.minLength = options.minLength;
|
|
262
|
+
}
|
|
263
|
+
if (options.maxLength !== undefined) {
|
|
264
|
+
schema.maxLength = options.maxLength;
|
|
265
|
+
}
|
|
266
|
+
if (options.pattern) {
|
|
267
|
+
schema.pattern = options.pattern;
|
|
268
|
+
}
|
|
269
|
+
// Array items
|
|
270
|
+
if (options.items) {
|
|
271
|
+
if (typeof options.items === 'string') {
|
|
272
|
+
schema.items = { $ref: `#/components/schemas/${options.items}` };
|
|
273
|
+
}
|
|
274
|
+
else {
|
|
275
|
+
schema.items = options.items;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return schema;
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Gets the schema metadata for a class.
|
|
282
|
+
*
|
|
283
|
+
* @param target - The class constructor
|
|
284
|
+
* @returns The schema metadata or undefined
|
|
285
|
+
*/
|
|
286
|
+
function getSchemaMetadata(target) {
|
|
287
|
+
return (0, metadata_collector_1.getMetadata)(metadata_keys_1.SCHEMA_METADATA, target);
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Gets the property metadata for a class (without inheritance).
|
|
291
|
+
*
|
|
292
|
+
* @param target - The class constructor
|
|
293
|
+
* @returns Array of property metadata
|
|
294
|
+
*/
|
|
295
|
+
function getPropertyMetadata(target) {
|
|
296
|
+
return (Reflect.getMetadata(SCHEMA_PROPERTIES_METADATA, target) ?? []);
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Gets all property metadata for a class including inherited properties.
|
|
300
|
+
*
|
|
301
|
+
* @param target - The class constructor
|
|
302
|
+
* @returns Array of all property metadata
|
|
303
|
+
*/
|
|
304
|
+
function getAllPropertyMetadata(target) {
|
|
305
|
+
return collectAllProperties(target);
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Checks if a class has been decorated with @ApiSchema.
|
|
309
|
+
*
|
|
310
|
+
* @param target - The class constructor
|
|
311
|
+
* @returns True if the class has schema metadata
|
|
312
|
+
*/
|
|
313
|
+
function hasSchemaMetadata(target) {
|
|
314
|
+
return getSchemaMetadata(target) !== undefined;
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Manually registers a schema from a decorated class.
|
|
318
|
+
* Useful when you need to re-register or update a schema.
|
|
319
|
+
*
|
|
320
|
+
* @param target - The class constructor decorated with @ApiSchema
|
|
321
|
+
*/
|
|
322
|
+
function registerSchema(target) {
|
|
323
|
+
const metadata = getSchemaMetadata(target);
|
|
324
|
+
if (metadata) {
|
|
325
|
+
const openApiSchema = buildOpenAPISchema(metadata);
|
|
326
|
+
schemas_1.OpenAPISchemaRegistry.registerSchema(metadata.name, openApiSchema);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-express-suite/src/decorators/schema.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAsCH,8BA0BC;AAmCD,kCAgCC;AA2ND,8CAEC;AAQD,kDAOC;AAQD,wDAIC;AAQD,8CAEC;AAQD,wCAQC;AAnZD,4BAA0B;AAO1B,gDAA2D;AAC3D,mDAAkD;AAClD,6DAAgE;AAEhE;;GAEG;AACH,MAAM,0BAA0B,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAC;AAE/D;;;;;;;;;;;;;;;;;;;GAm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AChB,CAAC;AAED;;;;;GAKG;AACH,SAAgB,iBAAiB,CAAC,MAAc;IAC9C,OAAO,IAAA,gCAAW,EAAiB,+BAAe,EAAE,MAAM,CAAC,CAAC;AAC9D,CAAC;AAED;;;;;GAKG;AACH,SAAgB,mBAAmB,CAAC,MAAc;IAChD,OAAO,CACJ,OAAO,CAAC,WAAW,CAClB,0BAA0B,EAC1B,MAAM,CACsB,IAAI,EAAE,CACrC,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,SAAgB,sBAAsB,CACpC,MAA2C;IAE3C,OAAO,oBAAoB,CAAC,MAAM,CAAC,CAAC;AACtC,CAAC;AAED;;;;;GAKG;AACH,SAAgB,iBAAiB,CAAC,MAAc;IAC9C,OAAO,iBAAiB,CAAC,MAAM,CAAC,KAAK,SAAS,CAAC;AACjD,CAAC;AAED;;;;;GAKG;AACH,SAAgB,cAAc,CAC5B,MAA2C;IAE3C,MAAM,QAAQ,GAAG,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAC3C,IAAI,QAAQ,EAAE,CAAC;QACb,MAAM,aAAa,GAAG,kBAAkB,CAAC,QAAQ,CAAC,CAAC;QACnD,+BAAqB,CAAC,cAAc,CAAC,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;IACrE,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Transaction decorator for Express Suite.
|
|
3
|
+
* Provides @Transactional decorator for MongoDB transaction support.
|
|
4
|
+
* @module decorators/transaction
|
|
5
|
+
*/
|
|
6
|
+
import 'reflect-metadata';
|
|
7
|
+
import { TransactionalDecoratorOptions } from '../interfaces/openApi/decoratorOptions';
|
|
8
|
+
/**
|
|
9
|
+
* Metadata stored for transaction settings.
|
|
10
|
+
*/
|
|
11
|
+
export interface TransactionMetadata {
|
|
12
|
+
/**
|
|
13
|
+
* Whether the route should use a transaction.
|
|
14
|
+
*/
|
|
15
|
+
useTransaction: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Transaction timeout in milliseconds.
|
|
18
|
+
*/
|
|
19
|
+
timeout?: number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Decorator that wraps a route handler in a MongoDB transaction.
|
|
23
|
+
* The transaction is automatically committed on success and rolled back on error.
|
|
24
|
+
*
|
|
25
|
+
* @param options - Optional transaction options including timeout
|
|
26
|
+
* @returns Method decorator
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* @ApiController('/api/orders')
|
|
31
|
+
* class OrderController {
|
|
32
|
+
* // Basic transaction
|
|
33
|
+
* @Transactional()
|
|
34
|
+
* @Post('/')
|
|
35
|
+
* createOrder() {}
|
|
36
|
+
*
|
|
37
|
+
* // Transaction with timeout
|
|
38
|
+
* @Transactional({ timeout: 30000 })
|
|
39
|
+
* @Post('/bulk')
|
|
40
|
+
* bulkCreateOrders() {}
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare function Transactional(options?: TransactionalDecoratorOptions): MethodDecorator;
|
|
45
|
+
/**
|
|
46
|
+
* Gets transaction metadata for a method.
|
|
47
|
+
*
|
|
48
|
+
* @param target - The class constructor
|
|
49
|
+
* @param propertyKey - The method name
|
|
50
|
+
* @returns Transaction metadata or undefined if not transactional
|
|
51
|
+
*/
|
|
52
|
+
export declare function getTransactionMetadata(target: object, propertyKey: string | symbol): TransactionMetadata | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* Checks if a method is transactional.
|
|
55
|
+
*
|
|
56
|
+
* @param target - The class constructor
|
|
57
|
+
* @param propertyKey - The method name
|
|
58
|
+
* @returns True if the method uses transactions
|
|
59
|
+
*/
|
|
60
|
+
export declare function isTransactional(target: object, propertyKey: string | symbol): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Gets the transaction timeout for a method.
|
|
63
|
+
*
|
|
64
|
+
* @param target - The class constructor
|
|
65
|
+
* @param propertyKey - The method name
|
|
66
|
+
* @returns Transaction timeout in milliseconds or undefined
|
|
67
|
+
*/
|
|
68
|
+
export declare function getTransactionTimeout(target: object, propertyKey: string | symbol): number | undefined;
|
|
69
|
+
//# sourceMappingURL=transaction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-express-suite/src/decorators/transaction.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EAAE,6BAA6B,EAAE,MAAM,wCAAwC,CAAC;AAIvF;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,cAAc,EAAE,OAAO,CAAC;IAExB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,aAAa,CAC3B,OAAO,CAAC,EAAE,6BAA6B,GACtC,eAAe,CAoBjB;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,GAAG,MAAM,GAC3B,mBAAmB,GAAG,SAAS,CAMjC;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,GAAG,MAAM,GAC3B,OAAO,CAGT;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,GAAG,MAAM,GAC3B,MAAM,GAAG,SAAS,CAGpB"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Transaction decorator for Express Suite.
|
|
4
|
+
* Provides @Transactional decorator for MongoDB transaction support.
|
|
5
|
+
* @module decorators/transaction
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.Transactional = Transactional;
|
|
9
|
+
exports.getTransactionMetadata = getTransactionMetadata;
|
|
10
|
+
exports.isTransactional = isTransactional;
|
|
11
|
+
exports.getTransactionTimeout = getTransactionTimeout;
|
|
12
|
+
require("reflect-metadata");
|
|
13
|
+
const metadata_keys_1 = require("./metadata-keys");
|
|
14
|
+
const metadata_collector_1 = require("./metadata-collector");
|
|
15
|
+
/**
|
|
16
|
+
* Decorator that wraps a route handler in a MongoDB transaction.
|
|
17
|
+
* The transaction is automatically committed on success and rolled back on error.
|
|
18
|
+
*
|
|
19
|
+
* @param options - Optional transaction options including timeout
|
|
20
|
+
* @returns Method decorator
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* @ApiController('/api/orders')
|
|
25
|
+
* class OrderController {
|
|
26
|
+
* // Basic transaction
|
|
27
|
+
* @Transactional()
|
|
28
|
+
* @Post('/')
|
|
29
|
+
* createOrder() {}
|
|
30
|
+
*
|
|
31
|
+
* // Transaction with timeout
|
|
32
|
+
* @Transactional({ timeout: 30000 })
|
|
33
|
+
* @Post('/bulk')
|
|
34
|
+
* bulkCreateOrders() {}
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
function Transactional(options) {
|
|
39
|
+
return function (target, propertyKey, descriptor) {
|
|
40
|
+
const metadata = {
|
|
41
|
+
useTransaction: true,
|
|
42
|
+
timeout: options?.timeout,
|
|
43
|
+
};
|
|
44
|
+
(0, metadata_collector_1.setMetadata)(metadata_keys_1.TRANSACTION_METADATA, metadata, target.constructor, propertyKey);
|
|
45
|
+
return descriptor;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Gets transaction metadata for a method.
|
|
50
|
+
*
|
|
51
|
+
* @param target - The class constructor
|
|
52
|
+
* @param propertyKey - The method name
|
|
53
|
+
* @returns Transaction metadata or undefined if not transactional
|
|
54
|
+
*/
|
|
55
|
+
function getTransactionMetadata(target, propertyKey) {
|
|
56
|
+
return (0, metadata_collector_1.getMetadata)(metadata_keys_1.TRANSACTION_METADATA, target, propertyKey);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Checks if a method is transactional.
|
|
60
|
+
*
|
|
61
|
+
* @param target - The class constructor
|
|
62
|
+
* @param propertyKey - The method name
|
|
63
|
+
* @returns True if the method uses transactions
|
|
64
|
+
*/
|
|
65
|
+
function isTransactional(target, propertyKey) {
|
|
66
|
+
const metadata = getTransactionMetadata(target, propertyKey);
|
|
67
|
+
return metadata?.useTransaction === true;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Gets the transaction timeout for a method.
|
|
71
|
+
*
|
|
72
|
+
* @param target - The class constructor
|
|
73
|
+
* @param propertyKey - The method name
|
|
74
|
+
* @returns Transaction timeout in milliseconds or undefined
|
|
75
|
+
*/
|
|
76
|
+
function getTransactionTimeout(target, propertyKey) {
|
|
77
|
+
const metadata = getTransactionMetadata(target, propertyKey);
|
|
78
|
+
return metadata?.timeout;
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=transaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction.js","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-express-suite/src/decorators/transaction.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;AA6CH,sCAsBC;AASD,wDASC;AASD,0CAMC;AASD,sDAMC;AAjHD,4BAA0B;AAE1B,mDAAuD;AACvD,6DAAgE;AAiBhE;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,SAAgB,aAAa,CAC3B,OAAuC;IAEvC,OAAO,UACL,MAAc,EACd,WAA4B,EAC5B,UAA8B;QAE9B,MAAM,QAAQ,GAAwB;YACpC,cAAc,EAAE,IAAI;YACpB,OAAO,EAAE,OAAO,EAAE,OAAO;SAC1B,CAAC;QAEF,IAAA,gCAAW,EACT,oCAAoB,EACpB,QAAQ,EACR,MAAM,CAAC,WAAW,EAClB,WAAW,CACZ,CAAC;QAEF,OAAO,UAAU,CAAC;IACpB,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,sBAAsB,CACpC,MAAc,EACd,WAA4B;IAE5B,OAAO,IAAA,gCAAW,EAChB,oCAAoB,EACpB,MAAM,EACN,WAAW,CACZ,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,eAAe,CAC7B,MAAc,EACd,WAA4B;IAE5B,MAAM,QAAQ,GAAG,sBAAsB,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAC7D,OAAO,QAAQ,EAAE,cAAc,KAAK,IAAI,CAAC;AAC3C,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,qBAAqB,CACnC,MAAc,EACd,WAA4B;IAE5B,MAAM,QAAQ,GAAG,sBAAsB,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAC7D,OAAO,QAAQ,EAAE,OAAO,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Validation decorators for Express Suite.
|
|
3
|
+
* Provides @ValidateBody, @ValidateParams, @ValidateQuery decorators.
|
|
4
|
+
* Supports Zod schemas, express-validator chains, and language-aware validation functions.
|
|
5
|
+
* Automatically adds 400 response to OpenAPI spec.
|
|
6
|
+
* @module decorators/validation
|
|
7
|
+
*/
|
|
8
|
+
import 'reflect-metadata';
|
|
9
|
+
import { ValidationChain } from 'express-validator';
|
|
10
|
+
import { z } from 'zod';
|
|
11
|
+
import { CoreLanguageCode } from '@digitaldefiance/i18n-lib';
|
|
12
|
+
import { IConstants } from '../interfaces/constants';
|
|
13
|
+
import { ValidationContext, ValidationMetadata } from '../interfaces/openApi/decoratorOptions';
|
|
14
|
+
/**
|
|
15
|
+
* Type for validation input - can be Zod schema, validation chains, or language-aware function.
|
|
16
|
+
*/
|
|
17
|
+
export type ValidationInput<TLanguage extends CoreLanguageCode = CoreLanguageCode, TConstants extends IConstants = IConstants> = z.ZodSchema | ValidationChain[] | ((this: ValidationContext<TConstants>, lang: TLanguage) => ValidationChain[]);
|
|
18
|
+
/**
|
|
19
|
+
* Decorator that validates the request body.
|
|
20
|
+
* Supports Zod schemas, express-validator chains, and language-aware validation functions.
|
|
21
|
+
* Automatically adds 400 response to OpenAPI spec.
|
|
22
|
+
*
|
|
23
|
+
* @param validation - Zod schema, ValidationChain[], or language-aware validation function
|
|
24
|
+
* @returns Class or method decorator
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* // With Zod schema
|
|
29
|
+
* const CreateUserSchema = z.object({
|
|
30
|
+
* name: z.string().min(1),
|
|
31
|
+
* email: z.string().email(),
|
|
32
|
+
* });
|
|
33
|
+
*
|
|
34
|
+
* @ApiController('/api/users')
|
|
35
|
+
* class UserController {
|
|
36
|
+
* @ValidateBody(CreateUserSchema)
|
|
37
|
+
* @Post('/')
|
|
38
|
+
* createUser(@Body() data: z.infer<typeof CreateUserSchema>) {
|
|
39
|
+
* return this.userService.create(data);
|
|
40
|
+
* }
|
|
41
|
+
* }
|
|
42
|
+
*
|
|
43
|
+
* // With express-validator chains
|
|
44
|
+
* @ApiController('/api/items')
|
|
45
|
+
* class ItemController {
|
|
46
|
+
* @ValidateBody([
|
|
47
|
+
* body('name').isString().notEmpty(),
|
|
48
|
+
* body('price').isNumeric(),
|
|
49
|
+
* ])
|
|
50
|
+
* @Post('/')
|
|
51
|
+
* createItem(@Body() data: CreateItemDto) {
|
|
52
|
+
* return this.itemService.create(data);
|
|
53
|
+
* }
|
|
54
|
+
* }
|
|
55
|
+
*
|
|
56
|
+
* // With language-aware validation function
|
|
57
|
+
* @ApiController('/api/products')
|
|
58
|
+
* class ProductController {
|
|
59
|
+
* @ValidateBody(function(lang) {
|
|
60
|
+
* return [
|
|
61
|
+
* body('name').isString().withMessage(this.constants.messages[lang].nameRequired),
|
|
62
|
+
* ];
|
|
63
|
+
* })
|
|
64
|
+
* @Post('/')
|
|
65
|
+
* createProduct(@Body() data: CreateProductDto) {
|
|
66
|
+
* return this.productService.create(data);
|
|
67
|
+
* }
|
|
68
|
+
* }
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export declare function ValidateBody<TLanguage extends CoreLanguageCode = CoreLanguageCode, TConstants extends IConstants = IConstants>(validation: ValidationInput<TLanguage, TConstants>): ClassDecorator & MethodDecorator;
|
|
72
|
+
/**
|
|
73
|
+
* Decorator that validates path parameters.
|
|
74
|
+
* Supports Zod schemas, express-validator chains, and language-aware validation functions.
|
|
75
|
+
* Automatically adds 400 response to OpenAPI spec.
|
|
76
|
+
*
|
|
77
|
+
* @param validation - Zod schema, ValidationChain[], or language-aware validation function
|
|
78
|
+
* @returns Class or method decorator
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* // With Zod schema
|
|
83
|
+
* const IdParamSchema = z.object({
|
|
84
|
+
* id: z.string().uuid(),
|
|
85
|
+
* });
|
|
86
|
+
*
|
|
87
|
+
* @ApiController('/api/users')
|
|
88
|
+
* class UserController {
|
|
89
|
+
* @ValidateParams(IdParamSchema)
|
|
90
|
+
* @Get('/:id')
|
|
91
|
+
* getUser(@Param('id') id: string) {
|
|
92
|
+
* return this.userService.findById(id);
|
|
93
|
+
* }
|
|
94
|
+
* }
|
|
95
|
+
*
|
|
96
|
+
* // With express-validator chains
|
|
97
|
+
* @ApiController('/api/items')
|
|
98
|
+
* class ItemController {
|
|
99
|
+
* @ValidateParams([
|
|
100
|
+
* param('id').isMongoId().withMessage('Invalid item ID'),
|
|
101
|
+
* ])
|
|
102
|
+
* @Get('/:id')
|
|
103
|
+
* getItem(@Param('id') id: string) {
|
|
104
|
+
* return this.itemService.findById(id);
|
|
105
|
+
* }
|
|
106
|
+
* }
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
export declare function ValidateParams<TLanguage extends CoreLanguageCode = CoreLanguageCode, TConstants extends IConstants = IConstants>(validation: ValidationInput<TLanguage, TConstants>): ClassDecorator & MethodDecorator;
|
|
110
|
+
/**
|
|
111
|
+
* Decorator that validates query parameters.
|
|
112
|
+
* Supports Zod schemas, express-validator chains, and language-aware validation functions.
|
|
113
|
+
* Automatically adds 400 response to OpenAPI spec.
|
|
114
|
+
*
|
|
115
|
+
* @param validation - Zod schema, ValidationChain[], or language-aware validation function
|
|
116
|
+
* @returns Class or method decorator
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```typescript
|
|
120
|
+
* // With Zod schema
|
|
121
|
+
* const PaginationSchema = z.object({
|
|
122
|
+
* page: z.coerce.number().int().positive().optional().default(1),
|
|
123
|
+
* limit: z.coerce.number().int().positive().max(100).optional().default(10),
|
|
124
|
+
* });
|
|
125
|
+
*
|
|
126
|
+
* @ApiController('/api/users')
|
|
127
|
+
* class UserController {
|
|
128
|
+
* @ValidateQuery(PaginationSchema)
|
|
129
|
+
* @Get('/')
|
|
130
|
+
* listUsers(@Query('page') page: number, @Query('limit') limit: number) {
|
|
131
|
+
* return this.userService.findAll({ page, limit });
|
|
132
|
+
* }
|
|
133
|
+
* }
|
|
134
|
+
*
|
|
135
|
+
* // With express-validator chains
|
|
136
|
+
* @ApiController('/api/search')
|
|
137
|
+
* class SearchController {
|
|
138
|
+
* @ValidateQuery([
|
|
139
|
+
* query('q').isString().notEmpty().withMessage('Search query is required'),
|
|
140
|
+
* query('page').optional().isInt({ min: 1 }),
|
|
141
|
+
* ])
|
|
142
|
+
* @Get('/')
|
|
143
|
+
* search(@Query('q') q: string, @Query('page') page?: number) {
|
|
144
|
+
* return this.searchService.search(q, page);
|
|
145
|
+
* }
|
|
146
|
+
* }
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
export declare function ValidateQuery<TLanguage extends CoreLanguageCode = CoreLanguageCode, TConstants extends IConstants = IConstants>(validation: ValidationInput<TLanguage, TConstants>): ClassDecorator & MethodDecorator;
|
|
150
|
+
/**
|
|
151
|
+
* Gets the effective validation metadata for a method, merging class-level and method-level settings.
|
|
152
|
+
* Method-level settings override class-level settings for the same field.
|
|
153
|
+
*
|
|
154
|
+
* @param target - The class constructor
|
|
155
|
+
* @param propertyKey - The method name
|
|
156
|
+
* @returns The merged validation metadata
|
|
157
|
+
*/
|
|
158
|
+
export declare function getEffectiveValidationMetadata<TLanguage extends CoreLanguageCode = CoreLanguageCode, TConstants extends IConstants = IConstants>(target: object, propertyKey: string | symbol): ValidationMetadata<TLanguage, TConstants>;
|
|
159
|
+
/**
|
|
160
|
+
* Checks if a route has any validation configured.
|
|
161
|
+
*
|
|
162
|
+
* @param target - The class constructor
|
|
163
|
+
* @param propertyKey - The method name
|
|
164
|
+
* @returns True if the route has any validation
|
|
165
|
+
*/
|
|
166
|
+
export declare function hasValidation(target: object, propertyKey: string | symbol): boolean;
|
|
167
|
+
/**
|
|
168
|
+
* Checks if a validation input is a Zod schema.
|
|
169
|
+
*
|
|
170
|
+
* @param validation - The validation input to check
|
|
171
|
+
* @returns True if the validation is a Zod schema
|
|
172
|
+
*/
|
|
173
|
+
export declare function isZodSchema(validation: ValidationInput): validation is z.ZodSchema;
|
|
174
|
+
/**
|
|
175
|
+
* Checks if a validation input is an array of ValidationChains.
|
|
176
|
+
*
|
|
177
|
+
* @param validation - The validation input to check
|
|
178
|
+
* @returns True if the validation is an array of ValidationChains
|
|
179
|
+
*/
|
|
180
|
+
export declare function isValidationChainArray(validation: ValidationInput): validation is ValidationChain[];
|
|
181
|
+
/**
|
|
182
|
+
* Checks if a validation input is a language-aware validation function.
|
|
183
|
+
*
|
|
184
|
+
* @param validation - The validation input to check
|
|
185
|
+
* @returns True if the validation is a function
|
|
186
|
+
*/
|
|
187
|
+
export declare function isValidationFunction<TLanguage extends CoreLanguageCode = CoreLanguageCode, TConstants extends IConstants = IConstants>(validation: ValidationInput<TLanguage, TConstants>): validation is (this: ValidationContext<TConstants>, lang: TLanguage) => ValidationChain[];
|
|
188
|
+
//# sourceMappingURL=validation.d.ts.map
|