@digitaldefiance/node-express-suite 3.11.32 → 3.12.1
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 +874 -8
- package/package.json +5 -5
- 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 +1 -0
- package/src/index.d.ts.map +1 -1
- package/src/index.js +1 -0
- package/src/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 +1 -0
- package/src/interfaces/openApi/index.d.ts.map +1 -1
- package/src/interfaces/openApi/index.js +23 -0
- package/src/interfaces/openApi/index.js.map +1 -1
- package/src/interfaces/openApi/parameter.d.ts +2 -0
- package/src/interfaces/openApi/parameter.d.ts.map +1 -1
- package/src/interfaces/openApi/parameter.js +3 -1
- package/src/interfaces/openApi/parameter.js.map +1 -1
- package/src/interfaces/openApi/parameterSchema.d.ts +2 -0
- package/src/interfaces/openApi/parameterSchema.d.ts.map +1 -1
- package/src/interfaces/openApi/parameterSchema.js +3 -0
- package/src/interfaces/openApi/parameterSchema.js.map +1 -1
- 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/types.d.ts +1 -0
- package/src/types.d.ts.map +1 -1
- package/src/types.js +1 -0
- package/src/types.js.map +1 -1
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Enhanced HTTP method decorators with OpenAPI support.
|
|
4
|
+
* Provides @Get, @Post, @Put, @Delete, @Patch decorators with inline OpenAPI metadata.
|
|
5
|
+
* @module decorators/http-methods
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.Get = Get;
|
|
9
|
+
exports.Post = Post;
|
|
10
|
+
exports.Put = Put;
|
|
11
|
+
exports.Delete = Delete;
|
|
12
|
+
exports.Patch = Patch;
|
|
13
|
+
require("reflect-metadata");
|
|
14
|
+
const metadata_keys_1 = require("./metadata-keys");
|
|
15
|
+
const metadata_collector_1 = require("./metadata-collector");
|
|
16
|
+
/**
|
|
17
|
+
* Extracts path parameters from an Express-style route path.
|
|
18
|
+
* @param path - Route path (e.g., '/users/:id/posts/:postId')
|
|
19
|
+
* @returns Array of parameter names
|
|
20
|
+
*/
|
|
21
|
+
function extractPathParameters(path) {
|
|
22
|
+
const paramRegex = /:([a-zA-Z_][a-zA-Z0-9_]*)/g;
|
|
23
|
+
const params = [];
|
|
24
|
+
let match;
|
|
25
|
+
while ((match = paramRegex.exec(path)) !== null) {
|
|
26
|
+
params.push(match[1]);
|
|
27
|
+
}
|
|
28
|
+
return params;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Builds OpenAPI metadata from route decorator options.
|
|
32
|
+
* Merges inline options (summary, description, tags, etc.) with explicit openapi object.
|
|
33
|
+
* @param path - Route path for extracting parameters
|
|
34
|
+
* @param options - Route decorator options
|
|
35
|
+
* @returns Partial OpenAPI route metadata
|
|
36
|
+
*/
|
|
37
|
+
function buildOpenAPIMetadata(path, options) {
|
|
38
|
+
const metadata = {};
|
|
39
|
+
// Extract inline OpenAPI options
|
|
40
|
+
if (options.summary !== undefined) {
|
|
41
|
+
metadata.summary = options.summary;
|
|
42
|
+
}
|
|
43
|
+
if (options.description !== undefined) {
|
|
44
|
+
metadata.description = options.description;
|
|
45
|
+
}
|
|
46
|
+
if (options.tags !== undefined) {
|
|
47
|
+
metadata.tags = options.tags;
|
|
48
|
+
}
|
|
49
|
+
if (options.operationId !== undefined) {
|
|
50
|
+
metadata.operationId = options.operationId;
|
|
51
|
+
}
|
|
52
|
+
if (options.deprecated !== undefined) {
|
|
53
|
+
metadata.deprecated = options.deprecated;
|
|
54
|
+
}
|
|
55
|
+
// Auto-extract path parameters for OpenAPI
|
|
56
|
+
const pathParams = extractPathParameters(path);
|
|
57
|
+
if (pathParams.length > 0) {
|
|
58
|
+
metadata.parameters = pathParams.map((name) => ({
|
|
59
|
+
name,
|
|
60
|
+
in: 'path',
|
|
61
|
+
required: true,
|
|
62
|
+
schema: { type: 'string' },
|
|
63
|
+
}));
|
|
64
|
+
}
|
|
65
|
+
// Merge with explicit openapi object (explicit takes precedence)
|
|
66
|
+
if (options.openapi) {
|
|
67
|
+
// Merge tags (concatenate arrays)
|
|
68
|
+
if (options.openapi.tags) {
|
|
69
|
+
metadata.tags = [...(metadata.tags ?? []), ...options.openapi.tags];
|
|
70
|
+
}
|
|
71
|
+
// Merge parameters (concatenate, explicit params can override auto-extracted)
|
|
72
|
+
if (options.openapi.parameters) {
|
|
73
|
+
const existingParams = metadata.parameters ?? [];
|
|
74
|
+
const explicitParams = options.openapi.parameters;
|
|
75
|
+
// Remove auto-extracted params that are overridden by explicit params
|
|
76
|
+
const explicitParamNames = new Set(explicitParams.map((p) => p.name));
|
|
77
|
+
const filteredExisting = existingParams.filter((p) => !explicitParamNames.has(p.name));
|
|
78
|
+
metadata.parameters = [...filteredExisting, ...explicitParams];
|
|
79
|
+
}
|
|
80
|
+
// Override scalar values
|
|
81
|
+
if (options.openapi.summary !== undefined) {
|
|
82
|
+
metadata.summary = options.openapi.summary;
|
|
83
|
+
}
|
|
84
|
+
if (options.openapi.description !== undefined) {
|
|
85
|
+
metadata.description = options.openapi.description;
|
|
86
|
+
}
|
|
87
|
+
if (options.openapi.operationId !== undefined) {
|
|
88
|
+
metadata.operationId = options.openapi.operationId;
|
|
89
|
+
}
|
|
90
|
+
if (options.openapi.deprecated !== undefined) {
|
|
91
|
+
metadata.deprecated = options.openapi.deprecated;
|
|
92
|
+
}
|
|
93
|
+
if (options.openapi.requestBody !== undefined) {
|
|
94
|
+
metadata.requestBody = options.openapi.requestBody;
|
|
95
|
+
}
|
|
96
|
+
if (options.openapi.responses !== undefined) {
|
|
97
|
+
metadata.responses = options.openapi.responses;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return metadata;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Creates an HTTP method decorator with OpenAPI support.
|
|
104
|
+
* @param method - HTTP method (get, post, put, delete, patch)
|
|
105
|
+
* @param path - Route path
|
|
106
|
+
* @param options - Route decorator options
|
|
107
|
+
* @returns Method decorator function
|
|
108
|
+
*/
|
|
109
|
+
function createHttpMethodDecorator(method, path, options = {}) {
|
|
110
|
+
return function (target, propertyKey, descriptor) {
|
|
111
|
+
const constructor = target.constructor;
|
|
112
|
+
const handlerName = String(propertyKey);
|
|
113
|
+
// Get existing routes or initialize empty array
|
|
114
|
+
const existingRoutes = (0, metadata_collector_1.getMetadataOrDefault)(metadata_keys_1.ROUTES_METADATA, constructor, undefined, []);
|
|
115
|
+
// Create route metadata
|
|
116
|
+
const route = {
|
|
117
|
+
method,
|
|
118
|
+
path,
|
|
119
|
+
handlerName,
|
|
120
|
+
options,
|
|
121
|
+
};
|
|
122
|
+
// Add to routes array
|
|
123
|
+
existingRoutes.push(route);
|
|
124
|
+
Reflect.defineMetadata(metadata_keys_1.ROUTES_METADATA, existingRoutes, constructor);
|
|
125
|
+
// Build and store OpenAPI metadata for this method
|
|
126
|
+
const openApiMetadata = buildOpenAPIMetadata(path, options);
|
|
127
|
+
if (Object.keys(openApiMetadata).length > 0) {
|
|
128
|
+
// Deep merge with any existing OpenAPI metadata on this method
|
|
129
|
+
// (from other decorators like @ApiSummary, @ApiTags, etc.)
|
|
130
|
+
(0, metadata_collector_1.deepMergeMetadata)(metadata_keys_1.OPENAPI_METADATA, openApiMetadata, constructor, propertyKey);
|
|
131
|
+
}
|
|
132
|
+
return descriptor;
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* GET method decorator with OpenAPI support.
|
|
137
|
+
* Registers a GET route handler with optional OpenAPI metadata.
|
|
138
|
+
*
|
|
139
|
+
* @param path - Route path (e.g., '/users/:id')
|
|
140
|
+
* @param options - Route options including validation, auth, and OpenAPI metadata
|
|
141
|
+
* @returns Method decorator
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* @ApiController('/api/users')
|
|
146
|
+
* class UserController {
|
|
147
|
+
* @Get('/:id', {
|
|
148
|
+
* summary: 'Get user by ID',
|
|
149
|
+
* tags: ['Users'],
|
|
150
|
+
* auth: true,
|
|
151
|
+
* })
|
|
152
|
+
* async getUser(@Param('id') id: string) {
|
|
153
|
+
* return this.userService.findById(id);
|
|
154
|
+
* }
|
|
155
|
+
* }
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
function Get(path, options = {}) {
|
|
159
|
+
return createHttpMethodDecorator('get', path, options);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* POST method decorator with OpenAPI support.
|
|
163
|
+
* Registers a POST route handler with optional OpenAPI metadata.
|
|
164
|
+
*
|
|
165
|
+
* @param path - Route path (e.g., '/users')
|
|
166
|
+
* @param options - Route options including validation, auth, and OpenAPI metadata
|
|
167
|
+
* @returns Method decorator
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```typescript
|
|
171
|
+
* @ApiController('/api/users')
|
|
172
|
+
* class UserController {
|
|
173
|
+
* @Post('/', {
|
|
174
|
+
* summary: 'Create a new user',
|
|
175
|
+
* tags: ['Users'],
|
|
176
|
+
* schema: createUserSchema,
|
|
177
|
+
* })
|
|
178
|
+
* async createUser(@Body() data: CreateUserDto) {
|
|
179
|
+
* return this.userService.create(data);
|
|
180
|
+
* }
|
|
181
|
+
* }
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
184
|
+
function Post(path, options = {}) {
|
|
185
|
+
return createHttpMethodDecorator('post', path, options);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* PUT method decorator with OpenAPI support.
|
|
189
|
+
* Registers a PUT route handler with optional OpenAPI metadata.
|
|
190
|
+
*
|
|
191
|
+
* @param path - Route path (e.g., '/users/:id')
|
|
192
|
+
* @param options - Route options including validation, auth, and OpenAPI metadata
|
|
193
|
+
* @returns Method decorator
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* ```typescript
|
|
197
|
+
* @ApiController('/api/users')
|
|
198
|
+
* class UserController {
|
|
199
|
+
* @Put('/:id', {
|
|
200
|
+
* summary: 'Update user',
|
|
201
|
+
* tags: ['Users'],
|
|
202
|
+
* auth: true,
|
|
203
|
+
* })
|
|
204
|
+
* async updateUser(@Param('id') id: string, @Body() data: UpdateUserDto) {
|
|
205
|
+
* return this.userService.update(id, data);
|
|
206
|
+
* }
|
|
207
|
+
* }
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
210
|
+
function Put(path, options = {}) {
|
|
211
|
+
return createHttpMethodDecorator('put', path, options);
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* DELETE method decorator with OpenAPI support.
|
|
215
|
+
* Registers a DELETE route handler with optional OpenAPI metadata.
|
|
216
|
+
*
|
|
217
|
+
* @param path - Route path (e.g., '/users/:id')
|
|
218
|
+
* @param options - Route options including validation, auth, and OpenAPI metadata
|
|
219
|
+
* @returns Method decorator
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
* ```typescript
|
|
223
|
+
* @ApiController('/api/users')
|
|
224
|
+
* class UserController {
|
|
225
|
+
* @Delete('/:id', {
|
|
226
|
+
* summary: 'Delete user',
|
|
227
|
+
* tags: ['Users'],
|
|
228
|
+
* auth: true,
|
|
229
|
+
* })
|
|
230
|
+
* async deleteUser(@Param('id') id: string) {
|
|
231
|
+
* return this.userService.delete(id);
|
|
232
|
+
* }
|
|
233
|
+
* }
|
|
234
|
+
* ```
|
|
235
|
+
*/
|
|
236
|
+
function Delete(path, options = {}) {
|
|
237
|
+
return createHttpMethodDecorator('delete', path, options);
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* PATCH method decorator with OpenAPI support.
|
|
241
|
+
* Registers a PATCH route handler with optional OpenAPI metadata.
|
|
242
|
+
*
|
|
243
|
+
* @param path - Route path (e.g., '/users/:id')
|
|
244
|
+
* @param options - Route options including validation, auth, and OpenAPI metadata
|
|
245
|
+
* @returns Method decorator
|
|
246
|
+
*
|
|
247
|
+
* @example
|
|
248
|
+
* ```typescript
|
|
249
|
+
* @ApiController('/api/users')
|
|
250
|
+
* class UserController {
|
|
251
|
+
* @Patch('/:id', {
|
|
252
|
+
* summary: 'Partially update user',
|
|
253
|
+
* tags: ['Users'],
|
|
254
|
+
* auth: true,
|
|
255
|
+
* })
|
|
256
|
+
* async patchUser(@Param('id') id: string, @Body() data: PatchUserDto) {
|
|
257
|
+
* return this.userService.patch(id, data);
|
|
258
|
+
* }
|
|
259
|
+
* }
|
|
260
|
+
* ```
|
|
261
|
+
*/
|
|
262
|
+
function Patch(path, options = {}) {
|
|
263
|
+
return createHttpMethodDecorator('patch', path, options);
|
|
264
|
+
}
|
|
265
|
+
//# sourceMappingURL=http-methods.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-methods.js","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-express-suite/src/decorators/http-methods.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;AA4MH,kBAKC;AAyBD,oBAKC;AAyBD,kBAKC;AAyBD,wBAKC;AAyBD,sBAKC;AAtUD,4BAA0B;AAG1B,mDAAoE;AACpE,6DAA+E;AAkB/E;;;;GAIG;AACH,SAAS,qBAAqB,CAAC,IAAY;IACzC,MAAM,UAAU,GAAG,4BAA4B,CAAC;IAChD,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,IAAI,KAA6B,CAAC;IAClC,OAAO,CAAC,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;QAChD,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACxB,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;GAMG;AACH,SAAS,oBAAoB,CAC3B,IAAY,EACZ,OAAyC;IAEzC,MAAM,QAAQ,GAAkC,EAAE,CAAC;IAEnD,iCAAiC;IACjC,IAAI,OAAO,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;QAClC,QAAQ,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IACrC,CAAC;IACD,IAAI,OAAO,CAAC,WAAW,KAAK,SAAS,EAAE,CAAC;QACtC,QAAQ,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IAC7C,CAAC;IACD,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QAC/B,QAAQ,CA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AAC,CAAC;AAC1D,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,SAAgB,GAAG,CACjB,IAAY,EACZ,UAA4C,EAAE;IAE9C,OAAO,yBAAyB,CAAC,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;AACzD,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,SAAgB,MAAM,CACpB,IAAY,EACZ,UAA4C,EAAE;IAE9C,OAAO,yBAAyB,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;AAC5D,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,SAAgB,KAAK,CACnB,IAAY,EACZ,UAA4C,EAAE;IAE9C,OAAO,yBAAyB,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;AAC3D,CAAC"}
|
|
@@ -1,4 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Decorator module exports.
|
|
3
|
+
* Provides all decorator exports for Express Suite.
|
|
4
|
+
* @module decorators
|
|
5
|
+
*/
|
|
6
|
+
export * from './auth';
|
|
1
7
|
export * from './base-controller';
|
|
2
8
|
export * from './controller';
|
|
9
|
+
export * from './handler-args';
|
|
10
|
+
export { Get, Post, Put, Delete, Patch } from './http-methods';
|
|
11
|
+
export type { EnhancedRouteMetadata, RouteDecoratorOptions, } from './http-methods';
|
|
12
|
+
export { OnSuccess, OnError, Before, After, getLifecycleMetadata, getClassLifecycleMetadata, getEffectiveLifecycleMetadata, hasLifecycleHooks, executeBeforeHooks, executeAfterHooks, executeOnSuccessHooks, executeOnErrorHooks, } from './lifecycle';
|
|
13
|
+
export type { LifecycleContext, LifecycleCallback, LifecycleMetadata, } from './lifecycle';
|
|
14
|
+
export * from './metadata-collector';
|
|
15
|
+
export * from './metadata-keys';
|
|
16
|
+
export * from './middleware';
|
|
17
|
+
export * from './openapi';
|
|
18
|
+
export * from './openapi-params';
|
|
19
|
+
export * from './params';
|
|
20
|
+
export * from './response';
|
|
21
|
+
export * from './schema';
|
|
22
|
+
export { Transactional, getTransactionMetadata, isTransactional, getTransactionTimeout, } from './transaction';
|
|
23
|
+
export type { TransactionMetadata } from './transaction';
|
|
24
|
+
export * from './validation';
|
|
3
25
|
export * from './zod-validation';
|
|
4
26
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-express-suite/src/decorators/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-express-suite/src/decorators/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,cAAc,QAAQ,CAAC;AAGvB,cAAc,mBAAmB,CAAC;AAGlC,cAAc,cAAc,CAAC;AAG7B,cAAc,gBAAgB,CAAC;AAG/B,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAC/D,YAAY,EACV,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACL,SAAS,EACT,OAAO,EACP,MAAM,EACN,KAAK,EACL,oBAAoB,EACpB,yBAAyB,EACzB,6BAA6B,EAC7B,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EACjB,qBAAqB,EACrB,mBAAmB,GACpB,MAAM,aAAa,CAAC;AACrB,YAAY,EACV,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,aAAa,CAAC;AAGrB,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC;AAGhC,cAAc,cAAc,CAAC;AAG7B,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AAGjC,cAAc,UAAU,CAAC;AAGzB,cAAc,YAAY,CAAC;AAG3B,cAAc,UAAU,CAAC;AAGzB,OAAO,EACL,aAAa,EACb,sBAAsB,EACtB,eAAe,EACf,qBAAqB,GACtB,MAAM,eAAe,CAAC;AACvB,YAAY,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAGzD,cAAc,cAAc,CAAC;AAG7B,cAAc,kBAAkB,CAAC"}
|
package/src/decorators/index.js
CHANGED
|
@@ -1,7 +1,63 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Decorator module exports.
|
|
4
|
+
* Provides all decorator exports for Express Suite.
|
|
5
|
+
* @module decorators
|
|
6
|
+
*/
|
|
2
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.getTransactionTimeout = exports.isTransactional = exports.getTransactionMetadata = exports.Transactional = exports.executeOnErrorHooks = exports.executeOnSuccessHooks = exports.executeAfterHooks = exports.executeBeforeHooks = exports.hasLifecycleHooks = exports.getEffectiveLifecycleMetadata = exports.getClassLifecycleMetadata = exports.getLifecycleMetadata = exports.After = exports.Before = exports.OnError = exports.OnSuccess = exports.Patch = exports.Delete = exports.Put = exports.Post = exports.Get = void 0;
|
|
3
9
|
const tslib_1 = require("tslib");
|
|
10
|
+
// Auth decorators
|
|
11
|
+
tslib_1.__exportStar(require("./auth"), exports);
|
|
12
|
+
// Base controller with decorator support
|
|
4
13
|
tslib_1.__exportStar(require("./base-controller"), exports);
|
|
14
|
+
// Controller decorators
|
|
5
15
|
tslib_1.__exportStar(require("./controller"), exports);
|
|
16
|
+
// Handler args decorator
|
|
17
|
+
tslib_1.__exportStar(require("./handler-args"), exports);
|
|
18
|
+
// HTTP method decorators - export specific items to avoid conflicts
|
|
19
|
+
var http_methods_1 = require("./http-methods");
|
|
20
|
+
Object.defineProperty(exports, "Get", { enumerable: true, get: function () { return http_methods_1.Get; } });
|
|
21
|
+
Object.defineProperty(exports, "Post", { enumerable: true, get: function () { return http_methods_1.Post; } });
|
|
22
|
+
Object.defineProperty(exports, "Put", { enumerable: true, get: function () { return http_methods_1.Put; } });
|
|
23
|
+
Object.defineProperty(exports, "Delete", { enumerable: true, get: function () { return http_methods_1.Delete; } });
|
|
24
|
+
Object.defineProperty(exports, "Patch", { enumerable: true, get: function () { return http_methods_1.Patch; } });
|
|
25
|
+
// Lifecycle decorators - export specific items to avoid conflicts with interfaces
|
|
26
|
+
var lifecycle_1 = require("./lifecycle");
|
|
27
|
+
Object.defineProperty(exports, "OnSuccess", { enumerable: true, get: function () { return lifecycle_1.OnSuccess; } });
|
|
28
|
+
Object.defineProperty(exports, "OnError", { enumerable: true, get: function () { return lifecycle_1.OnError; } });
|
|
29
|
+
Object.defineProperty(exports, "Before", { enumerable: true, get: function () { return lifecycle_1.Before; } });
|
|
30
|
+
Object.defineProperty(exports, "After", { enumerable: true, get: function () { return lifecycle_1.After; } });
|
|
31
|
+
Object.defineProperty(exports, "getLifecycleMetadata", { enumerable: true, get: function () { return lifecycle_1.getLifecycleMetadata; } });
|
|
32
|
+
Object.defineProperty(exports, "getClassLifecycleMetadata", { enumerable: true, get: function () { return lifecycle_1.getClassLifecycleMetadata; } });
|
|
33
|
+
Object.defineProperty(exports, "getEffectiveLifecycleMetadata", { enumerable: true, get: function () { return lifecycle_1.getEffectiveLifecycleMetadata; } });
|
|
34
|
+
Object.defineProperty(exports, "hasLifecycleHooks", { enumerable: true, get: function () { return lifecycle_1.hasLifecycleHooks; } });
|
|
35
|
+
Object.defineProperty(exports, "executeBeforeHooks", { enumerable: true, get: function () { return lifecycle_1.executeBeforeHooks; } });
|
|
36
|
+
Object.defineProperty(exports, "executeAfterHooks", { enumerable: true, get: function () { return lifecycle_1.executeAfterHooks; } });
|
|
37
|
+
Object.defineProperty(exports, "executeOnSuccessHooks", { enumerable: true, get: function () { return lifecycle_1.executeOnSuccessHooks; } });
|
|
38
|
+
Object.defineProperty(exports, "executeOnErrorHooks", { enumerable: true, get: function () { return lifecycle_1.executeOnErrorHooks; } });
|
|
39
|
+
// Metadata utilities
|
|
40
|
+
tslib_1.__exportStar(require("./metadata-collector"), exports);
|
|
41
|
+
tslib_1.__exportStar(require("./metadata-keys"), exports);
|
|
42
|
+
// Middleware decorators
|
|
43
|
+
tslib_1.__exportStar(require("./middleware"), exports);
|
|
44
|
+
// OpenAPI decorators
|
|
45
|
+
tslib_1.__exportStar(require("./openapi"), exports);
|
|
46
|
+
tslib_1.__exportStar(require("./openapi-params"), exports);
|
|
47
|
+
// Parameter injection decorators
|
|
48
|
+
tslib_1.__exportStar(require("./params"), exports);
|
|
49
|
+
// Response decorators
|
|
50
|
+
tslib_1.__exportStar(require("./response"), exports);
|
|
51
|
+
// Schema decorators
|
|
52
|
+
tslib_1.__exportStar(require("./schema"), exports);
|
|
53
|
+
// Transaction decorator - export specific items to avoid conflicts with interfaces
|
|
54
|
+
var transaction_1 = require("./transaction");
|
|
55
|
+
Object.defineProperty(exports, "Transactional", { enumerable: true, get: function () { return transaction_1.Transactional; } });
|
|
56
|
+
Object.defineProperty(exports, "getTransactionMetadata", { enumerable: true, get: function () { return transaction_1.getTransactionMetadata; } });
|
|
57
|
+
Object.defineProperty(exports, "isTransactional", { enumerable: true, get: function () { return transaction_1.isTransactional; } });
|
|
58
|
+
Object.defineProperty(exports, "getTransactionTimeout", { enumerable: true, get: function () { return transaction_1.getTransactionTimeout; } });
|
|
59
|
+
// Validation decorators
|
|
60
|
+
tslib_1.__exportStar(require("./validation"), exports);
|
|
61
|
+
// Zod validation utilities
|
|
6
62
|
tslib_1.__exportStar(require("./zod-validation"), exports);
|
|
7
63
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-express-suite/src/decorators/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-express-suite/src/decorators/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;AAEH,kBAAkB;AAClB,iDAAuB;AAEvB,yCAAyC;AACzC,4DAAkC;AAElC,wBAAwB;AACxB,uDAA6B;AAE7B,yBAAyB;AACzB,yDAA+B;AAE/B,oEAAoE;AACpE,+CAA+D;AAAtD,mGAAA,GAAG,OAAA;AAAE,oGAAA,IAAI,OAAA;AAAE,mGAAA,GAAG,OAAA;AAAE,sGAAA,MAAM,OAAA;AAAE,qGAAA,KAAK,OAAA;AAMtC,kFAAkF;AAClF,yCAaqB;AAZnB,sGAAA,SAAS,OAAA;AACT,oGAAA,OAAO,OAAA;AACP,mGAAA,MAAM,OAAA;AACN,kGAAA,KAAK,OAAA;AACL,iHAAA,oBAAoB,OAAA;AACpB,sHAAA,yBAAyB,OAAA;AACzB,0HAAA,6BAA6B,OAAA;AAC7B,8GAAA,iBAAiB,OAAA;AACjB,+GAAA,kBAAkB,OAAA;AAClB,8GAAA,iBAAiB,OAAA;AACjB,kHAAA,qBAAqB,OAAA;AACrB,gHAAA,mBAAmB,OAAA;AAQrB,qBAAqB;AACrB,+DAAqC;AACrC,0DAAgC;AAEhC,wBAAwB;AACxB,uDAA6B;AAE7B,qBAAqB;AACrB,oDAA0B;AAC1B,2DAAiC;AAEjC,iCAAiC;AACjC,mDAAyB;AAEzB,sBAAsB;AACtB,qDAA2B;AAE3B,oBAAoB;AACpB,mDAAyB;AAEzB,mFAAmF;AACnF,6CAKuB;AAJrB,4GAAA,aAAa,OAAA;AACb,qHAAA,sBAAsB,OAAA;AACtB,8GAAA,eAAe,OAAA;AACf,oHAAA,qBAAqB,OAAA;AAIvB,wBAAwB;AACxB,uDAA6B;AAE7B,2BAA2B;AAC3B,2DAAiC"}
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Lifecycle decorators for Express Suite.
|
|
3
|
+
* Provides @OnSuccess, @OnError, @Before, and @After decorators
|
|
4
|
+
* for hooking into request lifecycle events.
|
|
5
|
+
* Supports both class-level and method-level application.
|
|
6
|
+
* @module decorators/lifecycle
|
|
7
|
+
*/
|
|
8
|
+
import 'reflect-metadata';
|
|
9
|
+
import { Request, Response } from 'express';
|
|
10
|
+
/**
|
|
11
|
+
* Context passed to lifecycle callbacks.
|
|
12
|
+
*/
|
|
13
|
+
export interface LifecycleContext<TResult = unknown, TError = Error> {
|
|
14
|
+
/**
|
|
15
|
+
* The Express request object.
|
|
16
|
+
*/
|
|
17
|
+
req: Request;
|
|
18
|
+
/**
|
|
19
|
+
* The Express response object.
|
|
20
|
+
*/
|
|
21
|
+
res: Response;
|
|
22
|
+
/**
|
|
23
|
+
* The result from the handler (available in onSuccess and after hooks).
|
|
24
|
+
*/
|
|
25
|
+
result?: TResult;
|
|
26
|
+
/**
|
|
27
|
+
* The error that occurred (available in onError and after hooks).
|
|
28
|
+
*/
|
|
29
|
+
error?: TError;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Lifecycle callback function type.
|
|
33
|
+
*/
|
|
34
|
+
export type LifecycleCallback<TResult = unknown, TError = Error> = (context: LifecycleContext<TResult, TError>) => void | Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Metadata stored for lifecycle hooks.
|
|
37
|
+
*/
|
|
38
|
+
export interface LifecycleMetadata {
|
|
39
|
+
/**
|
|
40
|
+
* Callbacks to execute on successful response.
|
|
41
|
+
*/
|
|
42
|
+
onSuccess: LifecycleCallback[];
|
|
43
|
+
/**
|
|
44
|
+
* Callbacks to execute on error.
|
|
45
|
+
*/
|
|
46
|
+
onError: LifecycleCallback[];
|
|
47
|
+
/**
|
|
48
|
+
* Callbacks to execute before the handler.
|
|
49
|
+
*/
|
|
50
|
+
before: LifecycleCallback[];
|
|
51
|
+
/**
|
|
52
|
+
* Callbacks to execute after the handler (success or error).
|
|
53
|
+
*/
|
|
54
|
+
after: LifecycleCallback[];
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Decorator that registers a callback to execute after a successful response.
|
|
58
|
+
* Can be applied at class level (affects all methods) or method level.
|
|
59
|
+
*
|
|
60
|
+
* @param callback - Function to execute on success, receives context with req, res, and result
|
|
61
|
+
* @returns Class or method decorator
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* // Method-level usage
|
|
66
|
+
* @ApiController('/api/users')
|
|
67
|
+
* class UserController {
|
|
68
|
+
* @OnSuccess(({ req, result }) => {
|
|
69
|
+
* console.log(`User ${req.params.id} fetched successfully:`, result);
|
|
70
|
+
* })
|
|
71
|
+
* @Get('/:id')
|
|
72
|
+
* getUser() {}
|
|
73
|
+
* }
|
|
74
|
+
*
|
|
75
|
+
* // Class-level usage (applies to all methods)
|
|
76
|
+
* @OnSuccess(({ req }) => {
|
|
77
|
+
* console.log(`Request to ${req.path} completed successfully`);
|
|
78
|
+
* })
|
|
79
|
+
* @ApiController('/api/items')
|
|
80
|
+
* class ItemController {
|
|
81
|
+
* @Get('/')
|
|
82
|
+
* listItems() {}
|
|
83
|
+
* }
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
export declare function OnSuccess<TResult = unknown>(callback: LifecycleCallback<TResult>): ClassDecorator & MethodDecorator;
|
|
87
|
+
/**
|
|
88
|
+
* Decorator that registers a callback to execute when an error occurs.
|
|
89
|
+
* Can be applied at class level (affects all methods) or method level.
|
|
90
|
+
*
|
|
91
|
+
* @param callback - Function to execute on error, receives context with req, res, and error
|
|
92
|
+
* @returns Class or method decorator
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* // Method-level usage
|
|
97
|
+
* @ApiController('/api/users')
|
|
98
|
+
* class UserController {
|
|
99
|
+
* @OnError(({ req, error }) => {
|
|
100
|
+
* console.error(`Error fetching user ${req.params.id}:`, error);
|
|
101
|
+
* })
|
|
102
|
+
* @Get('/:id')
|
|
103
|
+
* getUser() {}
|
|
104
|
+
* }
|
|
105
|
+
*
|
|
106
|
+
* // Class-level usage for logging all errors
|
|
107
|
+
* @OnError(({ req, error }) => {
|
|
108
|
+
* logger.error(`Request to ${req.path} failed:`, error);
|
|
109
|
+
* })
|
|
110
|
+
* @ApiController('/api/items')
|
|
111
|
+
* class ItemController {
|
|
112
|
+
* @Get('/')
|
|
113
|
+
* listItems() {}
|
|
114
|
+
* }
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
export declare function OnError<TError = Error>(callback: LifecycleCallback<unknown, TError>): ClassDecorator & MethodDecorator;
|
|
118
|
+
/**
|
|
119
|
+
* Decorator that registers a callback to execute before the handler.
|
|
120
|
+
* Can be applied at class level (affects all methods) or method level.
|
|
121
|
+
* Useful for logging, auditing, or pre-processing.
|
|
122
|
+
*
|
|
123
|
+
* @param callback - Function to execute before handler, receives context with req and res
|
|
124
|
+
* @returns Class or method decorator
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```typescript
|
|
128
|
+
* // Method-level usage
|
|
129
|
+
* @ApiController('/api/users')
|
|
130
|
+
* class UserController {
|
|
131
|
+
* @Before(({ req }) => {
|
|
132
|
+
* console.log(`Fetching user ${req.params.id}`);
|
|
133
|
+
* })
|
|
134
|
+
* @Get('/:id')
|
|
135
|
+
* getUser() {}
|
|
136
|
+
* }
|
|
137
|
+
*
|
|
138
|
+
* // Class-level usage for request logging
|
|
139
|
+
* @Before(({ req }) => {
|
|
140
|
+
* console.log(`Incoming ${req.method} request to ${req.path}`);
|
|
141
|
+
* })
|
|
142
|
+
* @ApiController('/api/items')
|
|
143
|
+
* class ItemController {
|
|
144
|
+
* @Get('/')
|
|
145
|
+
* listItems() {}
|
|
146
|
+
* }
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
export declare function Before(callback: LifecycleCallback): ClassDecorator & MethodDecorator;
|
|
150
|
+
/**
|
|
151
|
+
* Decorator that registers a callback to execute after the handler completes.
|
|
152
|
+
* Executes regardless of success or error.
|
|
153
|
+
* Can be applied at class level (affects all methods) or method level.
|
|
154
|
+
* Useful for cleanup, metrics, or finalization.
|
|
155
|
+
*
|
|
156
|
+
* @param callback - Function to execute after handler, receives context with req, res, result, and error
|
|
157
|
+
* @returns Class or method decorator
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```typescript
|
|
161
|
+
* // Method-level usage
|
|
162
|
+
* @ApiController('/api/users')
|
|
163
|
+
* class UserController {
|
|
164
|
+
* @After(({ req, result, error }) => {
|
|
165
|
+
* const status = error ? 'failed' : 'succeeded';
|
|
166
|
+
* console.log(`Request to ${req.path} ${status}`);
|
|
167
|
+
* })
|
|
168
|
+
* @Get('/:id')
|
|
169
|
+
* getUser() {}
|
|
170
|
+
* }
|
|
171
|
+
*
|
|
172
|
+
* // Class-level usage for metrics
|
|
173
|
+
* @After(({ req }) => {
|
|
174
|
+
* metrics.recordRequest(req.path);
|
|
175
|
+
* })
|
|
176
|
+
* @ApiController('/api/items')
|
|
177
|
+
* class ItemController {
|
|
178
|
+
* @Get('/')
|
|
179
|
+
* listItems() {}
|
|
180
|
+
* }
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
export declare function After(callback: LifecycleCallback): ClassDecorator & MethodDecorator;
|
|
184
|
+
/**
|
|
185
|
+
* Gets lifecycle metadata for a specific method.
|
|
186
|
+
*
|
|
187
|
+
* @param target - The class constructor
|
|
188
|
+
* @param propertyKey - The method name
|
|
189
|
+
* @returns Lifecycle metadata or undefined if not set
|
|
190
|
+
*/
|
|
191
|
+
export declare function getLifecycleMetadata(target: object, propertyKey: string | symbol): LifecycleMetadata | undefined;
|
|
192
|
+
/**
|
|
193
|
+
* Gets class-level lifecycle metadata.
|
|
194
|
+
*
|
|
195
|
+
* @param target - The class constructor
|
|
196
|
+
* @returns Lifecycle metadata or undefined if not set
|
|
197
|
+
*/
|
|
198
|
+
export declare function getClassLifecycleMetadata(target: object): LifecycleMetadata | undefined;
|
|
199
|
+
/**
|
|
200
|
+
* Gets the effective lifecycle metadata for a method, merging class-level and method-level hooks.
|
|
201
|
+
* Class-level hooks run first, then method-level hooks.
|
|
202
|
+
*
|
|
203
|
+
* @param target - The class constructor
|
|
204
|
+
* @param propertyKey - The method name
|
|
205
|
+
* @returns Merged lifecycle metadata
|
|
206
|
+
*/
|
|
207
|
+
export declare function getEffectiveLifecycleMetadata(target: object, propertyKey: string | symbol): LifecycleMetadata;
|
|
208
|
+
/**
|
|
209
|
+
* Checks if a method has any lifecycle hooks defined.
|
|
210
|
+
*
|
|
211
|
+
* @param target - The class constructor
|
|
212
|
+
* @param propertyKey - The method name
|
|
213
|
+
* @returns True if any lifecycle hooks are defined
|
|
214
|
+
*/
|
|
215
|
+
export declare function hasLifecycleHooks(target: object, propertyKey: string | symbol): boolean;
|
|
216
|
+
/**
|
|
217
|
+
* Executes all before hooks for a method.
|
|
218
|
+
*
|
|
219
|
+
* @param target - The class constructor
|
|
220
|
+
* @param propertyKey - The method name
|
|
221
|
+
* @param context - The lifecycle context
|
|
222
|
+
*/
|
|
223
|
+
export declare function executeBeforeHooks(target: object, propertyKey: string | symbol, context: LifecycleContext): Promise<void>;
|
|
224
|
+
/**
|
|
225
|
+
* Executes all after hooks for a method.
|
|
226
|
+
*
|
|
227
|
+
* @param target - The class constructor
|
|
228
|
+
* @param propertyKey - The method name
|
|
229
|
+
* @param context - The lifecycle context
|
|
230
|
+
*/
|
|
231
|
+
export declare function executeAfterHooks(target: object, propertyKey: string | symbol, context: LifecycleContext): Promise<void>;
|
|
232
|
+
/**
|
|
233
|
+
* Executes all onSuccess hooks for a method.
|
|
234
|
+
*
|
|
235
|
+
* @param target - The class constructor
|
|
236
|
+
* @param propertyKey - The method name
|
|
237
|
+
* @param context - The lifecycle context with result
|
|
238
|
+
*/
|
|
239
|
+
export declare function executeOnSuccessHooks(target: object, propertyKey: string | symbol, context: LifecycleContext): Promise<void>;
|
|
240
|
+
/**
|
|
241
|
+
* Executes all onError hooks for a method.
|
|
242
|
+
*
|
|
243
|
+
* @param target - The class constructor
|
|
244
|
+
* @param propertyKey - The method name
|
|
245
|
+
* @param context - The lifecycle context with error
|
|
246
|
+
*/
|
|
247
|
+
export declare function executeOnErrorHooks(target: object, propertyKey: string | symbol, context: LifecycleContext): Promise<void>;
|
|
248
|
+
//# sourceMappingURL=lifecycle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-express-suite/src/decorators/lifecycle.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAQ5C;;GAEG;AACH,MAAM,WAAW,gBAAgB,CAAC,OAAO,GAAG,OAAO,EAAE,MAAM,GAAG,KAAK;IACjE;;OAEG;IACH,GAAG,EAAE,OAAO,CAAC;IAEb;;OAEG;IACH,GAAG,EAAE,QAAQ,CAAC;IAEd;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,MAAM,iBAAiB,CAAC,OAAO,GAAG,OAAO,EAAE,MAAM,GAAG,KAAK,IAAI,CACjE,OAAO,EAAE,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC,KACvC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAE1B;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,SAAS,EAAE,iBAAiB,EAAE,CAAC;IAE/B;;OAEG;IACH,OAAO,EAAE,iBAAiB,EAAE,CAAC;IAE7B;;OAEG;IACH,MAAM,EAAE,iBAAiB,EAAE,CAAC;IAE5B;;OAEG;IACH,KAAK,EAAE,iBAAiB,EAAE,CAAC;CAC5B;AA4ED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,SAAS,CAAC,OAAO,GAAG,OAAO,EACzC,QAAQ,EAAE,iBAAiB,CAAC,OAA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