bootifyjs 0.0.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/dist/application/Application.d.ts +43 -0
- package/dist/application/Application.d.ts.map +1 -0
- package/dist/application/Application.js +283 -0
- package/dist/application/Application.js.map +1 -0
- package/dist/container/container.d.ts +9 -0
- package/dist/container/container.d.ts.map +1 -0
- package/dist/container/container.js +23 -0
- package/dist/container/container.js.map +1 -0
- package/dist/decorators/cache/ICacheClient.d.ts +6 -0
- package/dist/decorators/cache/ICacheClient.d.ts.map +1 -0
- package/dist/decorators/cache/ICacheClient.js +3 -0
- package/dist/decorators/cache/ICacheClient.js.map +1 -0
- package/dist/decorators/cache/cache.decorator.d.ts +2 -0
- package/dist/decorators/cache/cache.decorator.d.ts.map +1 -0
- package/dist/decorators/cache/cache.decorator.js +38 -0
- package/dist/decorators/cache/cache.decorator.js.map +1 -0
- package/dist/decorators/controller.decorator.d.ts +9 -0
- package/dist/decorators/controller.decorator.d.ts.map +1 -0
- package/dist/decorators/controller.decorator.js +99 -0
- package/dist/decorators/controller.decorator.js.map +1 -0
- package/dist/decorators/http.decorator.d.ts +7 -0
- package/dist/decorators/http.decorator.d.ts.map +1 -0
- package/dist/decorators/http.decorator.js +26 -0
- package/dist/decorators/http.decorator.js.map +1 -0
- package/dist/decorators/timing.decorator.d.ts +2 -0
- package/dist/decorators/timing.decorator.d.ts.map +1 -0
- package/dist/decorators/timing.decorator.js +26 -0
- package/dist/decorators/timing.decorator.js.map +1 -0
- package/dist/decorators/transaction/IDatabaseClient.d.ts +9 -0
- package/dist/decorators/transaction/IDatabaseClient.d.ts.map +1 -0
- package/dist/decorators/transaction/IDatabaseClient.js +3 -0
- package/dist/decorators/transaction/IDatabaseClient.js.map +1 -0
- package/dist/decorators/transaction/transactional.decorator.d.ts +2 -0
- package/dist/decorators/transaction/transactional.decorator.d.ts.map +1 -0
- package/dist/decorators/transaction/transactional.decorator.js +27 -0
- package/dist/decorators/transaction/transactional.decorator.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -0
- package/dist/logger/Logger.d.ts +37 -0
- package/dist/logger/Logger.d.ts.map +1 -0
- package/dist/logger/Logger.js +142 -0
- package/dist/logger/Logger.js.map +1 -0
- package/dist/middleware/http.d.ts +2 -0
- package/dist/middleware/http.d.ts.map +1 -0
- package/dist/middleware/http.js +80 -0
- package/dist/middleware/http.js.map +1 -0
- package/dist/middleware/requestcontext.d.ts +12 -0
- package/dist/middleware/requestcontext.d.ts.map +1 -0
- package/dist/middleware/requestcontext.js +6 -0
- package/dist/middleware/requestcontext.js.map +1 -0
- package/package.json +24 -0
- package/src/application/Application.ts +355 -0
- package/src/container/container.ts +28 -0
- package/src/decorators/cache/ICacheClient.ts +5 -0
- package/src/decorators/cache/cache.decorator.ts +36 -0
- package/src/decorators/controller.decorator.ts +119 -0
- package/src/decorators/http.decorator.ts +25 -0
- package/src/decorators/timing.decorator.ts +23 -0
- package/src/decorators/transaction/IDatabaseClient.ts +9 -0
- package/src/decorators/transaction/transactional.decorator.ts +24 -0
- package/src/index.ts +10 -0
- package/src/logger/Logger.ts +179 -0
- package/src/middleware/http.ts +81 -0
- package/src/middleware/requestcontext.ts +12 -0
@@ -0,0 +1,43 @@
|
|
1
|
+
import { FastifyInstance, FastifyPluginAsync, FastifyPluginCallback } from 'fastify';
|
2
|
+
interface FastifyServerConfig {
|
3
|
+
port?: number;
|
4
|
+
host?: string;
|
5
|
+
route?: FastifyPluginCallback | FastifyPluginAsync;
|
6
|
+
enableCors?: boolean;
|
7
|
+
enableSwagger?: boolean;
|
8
|
+
enableLogging?: boolean;
|
9
|
+
enableErrorHandling?: boolean;
|
10
|
+
enableDatabase?: boolean;
|
11
|
+
enableRedis?: boolean;
|
12
|
+
corsOptions?: {
|
13
|
+
origin?: string | string[];
|
14
|
+
methods?: string[];
|
15
|
+
credentials?: boolean;
|
16
|
+
};
|
17
|
+
swaggerOptions?: {
|
18
|
+
routePrefix?: string;
|
19
|
+
swaggerDoc?: any;
|
20
|
+
};
|
21
|
+
enableMetrics?: boolean;
|
22
|
+
enableCookie?: boolean;
|
23
|
+
enableAuth?: boolean;
|
24
|
+
}
|
25
|
+
export declare class Application {
|
26
|
+
private server;
|
27
|
+
private config;
|
28
|
+
constructor(config?: FastifyServerConfig);
|
29
|
+
private setupServer;
|
30
|
+
private globalErrorHandler;
|
31
|
+
private addCommonSchemas;
|
32
|
+
private setupLogging;
|
33
|
+
private setupRouteLogging;
|
34
|
+
private printFastifyRoutes;
|
35
|
+
private colorMethod;
|
36
|
+
registerControllers(controllers: Function[]): void;
|
37
|
+
start(port?: number, host?: string): Promise<void>;
|
38
|
+
private setupGracefulShutdown;
|
39
|
+
getServer(): FastifyInstance;
|
40
|
+
updateConfig(newConfig: Partial<FastifyServerConfig>): void;
|
41
|
+
}
|
42
|
+
export {};
|
43
|
+
//# sourceMappingURL=Application.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"Application.d.ts","sourceRoot":"","sources":["../../src/application/Application.ts"],"names":[],"mappings":"AAAA,OAAgB,EACd,eAAe,EACf,kBAAkB,EAClB,qBAAqB,EAEtB,MAAM,SAAS,CAAC;AAMjB,UAAU,mBAAmB;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,qBAAqB,GAAG,kBAAkB,CAAC;IACnD,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,WAAW,CAAC,EAAE;QACZ,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;QAC3B,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;QACnB,WAAW,CAAC,EAAE,OAAO,CAAC;KACvB,CAAC;IACF,cAAc,CAAC,EAAE;QACf,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,UAAU,CAAC,EAAE,GAAG,CAAC;KAClB,CAAC;IACF,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,qBAAa,WAAW;IACtB,OAAO,CAAC,MAAM,CAAkB;IAChC,OAAO,CAAC,MAAM,CAAsB;gBAExB,MAAM,GAAE,mBAAwB;YAiD9B,WAAW;IA0DzB,OAAO,CAAC,kBAAkB,CAWxB;IAEF,OAAO,CAAC,gBAAgB;IAsBxB,OAAO,CAAC,YAAY;IA+CpB,OAAO,CAAC,iBAAiB;IAazB,OAAO,CAAC,kBAAkB;IAsB1B,OAAO,CAAC,WAAW;IAwBZ,mBAAmB,CAAC,WAAW,EAAE,QAAQ,EAAE;IAIrC,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM;IAiC/C,OAAO,CAAC,qBAAqB;IAuBtB,SAAS,IAAI,eAAe;IAI5B,YAAY,CAAC,SAAS,EAAE,OAAO,CAAC,mBAAmB,CAAC;CAG5D"}
|
@@ -0,0 +1,283 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.Application = void 0;
|
7
|
+
const fastify_1 = __importDefault(require("fastify"));
|
8
|
+
const controller_decorator_1 = require("../decorators/controller.decorator");
|
9
|
+
const Logger_1 = __importDefault(require("../logger/Logger"));
|
10
|
+
const requestcontext_1 = require("../middleware/requestcontext");
|
11
|
+
const http_1 = require("../middleware/http");
|
12
|
+
class Application {
|
13
|
+
constructor(config = {}) {
|
14
|
+
this.globalErrorHandler = (error, request, reply) => {
|
15
|
+
Logger_1.default.error('Global error handler:', error);
|
16
|
+
const statusCode = error.statusCode || 500;
|
17
|
+
const message = error.message || 'Internal Server Error';
|
18
|
+
reply.status(statusCode).send({
|
19
|
+
statusCode,
|
20
|
+
error: error.name || 'Error',
|
21
|
+
message,
|
22
|
+
});
|
23
|
+
};
|
24
|
+
this.config = {
|
25
|
+
port: 3000,
|
26
|
+
host: '0.0.0.0',
|
27
|
+
enableCors: true,
|
28
|
+
enableSwagger: false,
|
29
|
+
enableLogging: true,
|
30
|
+
enableErrorHandling: true,
|
31
|
+
enableDatabase: false,
|
32
|
+
enableRedis: false,
|
33
|
+
enableCookie: false,
|
34
|
+
enableAuth: false,
|
35
|
+
enableMetrics: false,
|
36
|
+
corsOptions: {
|
37
|
+
origin: [
|
38
|
+
'http://localhost:4000',
|
39
|
+
'http://localhost:3000',
|
40
|
+
'http://localhost:5173',
|
41
|
+
],
|
42
|
+
methods: ['GET', 'PUT', 'PATCH', 'POST', 'DELETE'],
|
43
|
+
credentials: true,
|
44
|
+
},
|
45
|
+
swaggerOptions: {
|
46
|
+
routePrefix: '/docs',
|
47
|
+
swaggerDoc: {
|
48
|
+
info: {
|
49
|
+
title: 'API Documentation',
|
50
|
+
version: '1.0.0',
|
51
|
+
},
|
52
|
+
},
|
53
|
+
},
|
54
|
+
...config,
|
55
|
+
};
|
56
|
+
this.server = (0, fastify_1.default)({
|
57
|
+
ajv: {
|
58
|
+
customOptions: {
|
59
|
+
strict: false,
|
60
|
+
},
|
61
|
+
},
|
62
|
+
genReqId: (req) => {
|
63
|
+
const requestId = req.headers['x-request-id'];
|
64
|
+
return Array.isArray(requestId) ? requestId[0] : requestId || crypto.randomUUID();
|
65
|
+
},
|
66
|
+
});
|
67
|
+
this.setupServer();
|
68
|
+
}
|
69
|
+
async setupServer() {
|
70
|
+
try {
|
71
|
+
// Register CORS
|
72
|
+
// if (this.config.enableCors) {
|
73
|
+
// Logger.info('Registering CORS');
|
74
|
+
// await this.server.register(require('@fastify/cors'), this.config.corsOptions);
|
75
|
+
// }
|
76
|
+
// Register Swagger
|
77
|
+
// if (this.config.enableSwagger) {
|
78
|
+
// await this.server.register(require('@fastify/swagger'), this.config.swaggerOptions?.swaggerDoc);
|
79
|
+
// await this.server.register(require('@fastify/swagger-ui'), {
|
80
|
+
// routePrefix: this.config.swaggerOptions?.routePrefix,
|
81
|
+
// });
|
82
|
+
// }
|
83
|
+
// Register Cookie support
|
84
|
+
// if (this.config.enableCookie) {
|
85
|
+
// await this.server.register(require('@fastify/cookie'), {
|
86
|
+
// hook: 'onRequest',
|
87
|
+
// parseOptions: {},
|
88
|
+
// });
|
89
|
+
// }
|
90
|
+
// Register Metrics
|
91
|
+
// if (this.config.enableMetrics) {
|
92
|
+
// await this.server.register(require('fastify-metrics'), {
|
93
|
+
// endpoint: '/metrics',
|
94
|
+
// });
|
95
|
+
// }
|
96
|
+
// Register error handling
|
97
|
+
if (this.config.enableErrorHandling) {
|
98
|
+
this.server.setErrorHandler(this.globalErrorHandler);
|
99
|
+
}
|
100
|
+
// Add common schemas
|
101
|
+
this.addCommonSchemas();
|
102
|
+
// Add logging hooks
|
103
|
+
if (this.config.enableLogging) {
|
104
|
+
this.setupLogging();
|
105
|
+
}
|
106
|
+
// Setup route logging
|
107
|
+
this.setupRouteLogging();
|
108
|
+
// Register custom routes
|
109
|
+
if (this.config.route) {
|
110
|
+
await this.server.register(this.config.route);
|
111
|
+
}
|
112
|
+
}
|
113
|
+
catch (error) {
|
114
|
+
Logger_1.default.error('Failed to setup server:', error);
|
115
|
+
throw error;
|
116
|
+
}
|
117
|
+
}
|
118
|
+
addCommonSchemas() {
|
119
|
+
this.server.addSchema({
|
120
|
+
$id: 'errorResponseSchema',
|
121
|
+
type: 'object',
|
122
|
+
description: 'Error Response',
|
123
|
+
properties: {
|
124
|
+
statusCode: { type: 'number' },
|
125
|
+
error: { type: 'string' },
|
126
|
+
message: { type: 'string' },
|
127
|
+
},
|
128
|
+
});
|
129
|
+
this.server.addSchema({
|
130
|
+
$id: 'messageResponseSchema',
|
131
|
+
type: 'object',
|
132
|
+
description: 'Message Response',
|
133
|
+
properties: {
|
134
|
+
message: { type: 'string' },
|
135
|
+
},
|
136
|
+
});
|
137
|
+
}
|
138
|
+
setupLogging() {
|
139
|
+
// requestContext.run
|
140
|
+
this.server.addHook('preHandler', (request, reply, done) => {
|
141
|
+
request.raw.id = request.id;
|
142
|
+
reply.header('x-request-id', request.id);
|
143
|
+
(0, http_1.httpLoggerMiddleware)(request.raw, reply.raw);
|
144
|
+
// console.log('Request ID:', request.id)
|
145
|
+
// console.log('User ID:', request.user)
|
146
|
+
requestcontext_1.requestContext.run({ requestId: request.id, userId: "pxpxpx", username: "priyadarship4@gmail.com" }, () => {
|
147
|
+
done();
|
148
|
+
});
|
149
|
+
});
|
150
|
+
// this.server.addHook('onRequest', async (request, reply) => {
|
151
|
+
// const startTime = Date.now();
|
152
|
+
// request.raw.startTime = startTime;
|
153
|
+
// reply.header('x-request-id', request.id);
|
154
|
+
// Logger.info({
|
155
|
+
// requestId: request.id,
|
156
|
+
// method: request.method,
|
157
|
+
// url: request.url,
|
158
|
+
// userAgent: request.headers['user-agent'],
|
159
|
+
// ip: request.ip,
|
160
|
+
// message: 'Incoming request'
|
161
|
+
// });
|
162
|
+
// });
|
163
|
+
// this.server.addHook('onResponse', async (request, reply) => {
|
164
|
+
// const duration = Date.now() - (request.raw.startTime || Date.now());
|
165
|
+
// Logger.info({
|
166
|
+
// requestId: request.id,
|
167
|
+
// method: request.method,
|
168
|
+
// url: request.url,
|
169
|
+
// statusCode: reply.statusCode,
|
170
|
+
// duration: `${duration}ms`,
|
171
|
+
// message: 'Request completed'
|
172
|
+
// });
|
173
|
+
// });
|
174
|
+
}
|
175
|
+
setupRouteLogging() {
|
176
|
+
const routeOptions = [];
|
177
|
+
this.server.addHook('onRoute', (routeOption) => {
|
178
|
+
routeOptions.push(routeOption);
|
179
|
+
});
|
180
|
+
this.server.addHook('onReady', (done) => {
|
181
|
+
this.printFastifyRoutes(routeOptions, { colors: true });
|
182
|
+
done();
|
183
|
+
});
|
184
|
+
}
|
185
|
+
printFastifyRoutes(routeOptions, opts) {
|
186
|
+
const { colors } = opts;
|
187
|
+
if (routeOptions.length === 0) {
|
188
|
+
return;
|
189
|
+
}
|
190
|
+
routeOptions.sort((a, b) => a.url.localeCompare(b.url));
|
191
|
+
const logEntries = [];
|
192
|
+
logEntries.push("Available routes:");
|
193
|
+
for (const routeOption of routeOptions) {
|
194
|
+
const { method, url } = routeOption;
|
195
|
+
if (method === "HEAD")
|
196
|
+
continue;
|
197
|
+
const formattedMethod = colors ? this.colorMethod(method) : method;
|
198
|
+
logEntries.push(`${formattedMethod}\t${url}`);
|
199
|
+
}
|
200
|
+
Logger_1.default.info(logEntries.join("\n"));
|
201
|
+
}
|
202
|
+
colorMethod(method) {
|
203
|
+
const COLORS = {
|
204
|
+
yellow: 33,
|
205
|
+
green: 32,
|
206
|
+
blue: 34,
|
207
|
+
red: 31,
|
208
|
+
grey: 90,
|
209
|
+
clear: 39,
|
210
|
+
};
|
211
|
+
const colorText = (color, string) => {
|
212
|
+
return `\u001b[${color}m${string}\u001b[${COLORS.clear}m`;
|
213
|
+
};
|
214
|
+
switch (method) {
|
215
|
+
case "POST": return colorText(COLORS.yellow, method);
|
216
|
+
case "GET": return colorText(COLORS.green, method);
|
217
|
+
case "PUT": return colorText(COLORS.blue, method);
|
218
|
+
case "DELETE": return colorText(COLORS.red, method);
|
219
|
+
case "PATCH": return colorText(COLORS.grey, method);
|
220
|
+
default: return method;
|
221
|
+
}
|
222
|
+
}
|
223
|
+
registerControllers(controllers) {
|
224
|
+
(0, controller_decorator_1.registerControllers)(this.server, controllers);
|
225
|
+
}
|
226
|
+
async start(port, host) {
|
227
|
+
const serverPort = port || this.config.port || 3000;
|
228
|
+
const serverHost = host || this.config.host || '0.0.0.0';
|
229
|
+
try {
|
230
|
+
// Initialize Redis if enabled
|
231
|
+
if (this.config.enableRedis) {
|
232
|
+
Logger_1.default.info('Connecting to Redis...');
|
233
|
+
// Add Redis initialization logic here
|
234
|
+
Logger_1.default.info('Redis connected');
|
235
|
+
}
|
236
|
+
// Initialize Database if enabled
|
237
|
+
if (this.config.enableDatabase) {
|
238
|
+
Logger_1.default.info('Connecting to database...');
|
239
|
+
// Add Database initialization logic here
|
240
|
+
Logger_1.default.info('Database connected');
|
241
|
+
}
|
242
|
+
Logger_1.default.info(`Starting server at http://${serverHost}:${serverPort}`);
|
243
|
+
await this.server.listen({ port: serverPort, host: serverHost });
|
244
|
+
Logger_1.default.info(`Server listening on http://${serverHost}:${serverPort}`);
|
245
|
+
// Setup graceful shutdown
|
246
|
+
this.setupGracefulShutdown();
|
247
|
+
}
|
248
|
+
catch (err) {
|
249
|
+
// Logger.error(err)
|
250
|
+
Logger_1.default.error('Failed to start server:', err);
|
251
|
+
process.exit(1);
|
252
|
+
}
|
253
|
+
}
|
254
|
+
setupGracefulShutdown() {
|
255
|
+
const signals = ['SIGINT', 'SIGTERM'];
|
256
|
+
signals.forEach((signal) => {
|
257
|
+
process.on(signal, async () => {
|
258
|
+
try {
|
259
|
+
await this.server.close();
|
260
|
+
Logger_1.default.info(`Closed application on ${signal}`);
|
261
|
+
process.exit(0);
|
262
|
+
}
|
263
|
+
catch (err) {
|
264
|
+
Logger_1.default.error(`Error closing application on ${signal}`, err);
|
265
|
+
process.exit(1);
|
266
|
+
}
|
267
|
+
});
|
268
|
+
});
|
269
|
+
process.on('unhandledRejection', (err) => {
|
270
|
+
// Logger.error(err)
|
271
|
+
Logger_1.default.error('Unhandled Rejection:', err);
|
272
|
+
process.exit(1);
|
273
|
+
});
|
274
|
+
}
|
275
|
+
getServer() {
|
276
|
+
return this.server;
|
277
|
+
}
|
278
|
+
updateConfig(newConfig) {
|
279
|
+
this.config = { ...this.config, ...newConfig };
|
280
|
+
}
|
281
|
+
}
|
282
|
+
exports.Application = Application;
|
283
|
+
//# sourceMappingURL=Application.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"Application.js","sourceRoot":"","sources":["../../src/application/Application.ts"],"names":[],"mappings":";;;;;;AAAA,sDAKiB;AACjB,6EAAyE;AACzE,8DAAsC;AACtC,iEAA8D;AAC9D,6CAA0D;AA0B1D,MAAa,WAAW;IAItB,YAAY,SAA8B,EAAE;QA2GpC,uBAAkB,GAAG,CAAC,KAAU,EAAE,OAAY,EAAE,KAAU,EAAE,EAAE;YACpE,gBAAM,CAAC,KAAK,CAAC,uBAAuB,EAAE,KAAK,CAAC,CAAC;YAE7C,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU,IAAI,GAAG,CAAC;YAC3C,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,IAAI,uBAAuB,CAAC;YAEzD,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC;gBAC5B,UAAU;gBACV,KAAK,EAAE,KAAK,CAAC,IAAI,IAAI,OAAO;gBAC5B,OAAO;aACR,CAAC,CAAC;QACL,CAAC,CAAC;QArHA,IAAI,CAAC,MAAM,GAAG;YACZ,IAAI,EAAE,IAAI;YACV,IAAI,EAAE,SAAS;YACf,UAAU,EAAE,IAAI;YAChB,aAAa,EAAE,KAAK;YACpB,aAAa,EAAE,IAAI;YACnB,mBAAmB,EAAE,IAAI;YACzB,cAAc,EAAE,KAAK;YACrB,WAAW,EAAE,KAAK;YAClB,YAAY,EAAE,KAAK;YACnB,UAAU,EAAE,KAAK;YACjB,aAAa,EAAE,KAAK;YACpB,WAAW,EAAE;gBACX,MAAM,EAAE;oBACN,uBAAuB;oBACvB,uBAAuB;oBACvB,uBAAuB;iBACxB;gBACD,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC;gBAClD,WAAW,EAAE,IAAI;aAClB;YACD,cAAc,EAAE;gBAC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CAAC,CAAC;YACnD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;IACL,CAAC;IAEM,SAAS;QACd,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAEM,YAAY,CAAC,SAAuC;QACzD,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,SAAS,EAAE,CAAC;IACjD,CAAC;CACF;AA/TD,kCA+TC"}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { Container } from "inversify";
|
2
|
+
declare const container: Container;
|
3
|
+
interface BeanOptions {
|
4
|
+
scope?: 'singleton' | 'transient';
|
5
|
+
bindTo?: Function[];
|
6
|
+
}
|
7
|
+
export declare function Bean(options: BeanOptions): (target: any) => void;
|
8
|
+
export default container;
|
9
|
+
//# sourceMappingURL=container.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"container.d.ts","sourceRoot":"","sources":["../../src/container/container.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAc,MAAM,WAAW,CAAC;AAClD,QAAA,MAAM,SAAS,WAAkB,CAAC;AAElC,UAAU,WAAW;IACjB,KAAK,CAAC,EAAE,WAAW,GAAG,WAAW,CAAC;IAClC,MAAM,CAAC,EAAE,QAAQ,EAAE,CAAC;CACvB;AACD,wBAAgB,IAAI,CAAC,OAAO,EAAE,WAAW,IACpB,QAAQ,GAAG,UAiB/B;AAED,eAAe,SAAS,CAAC"}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.Bean = Bean;
|
4
|
+
const inversify_1 = require("inversify");
|
5
|
+
const container = new inversify_1.Container();
|
6
|
+
function Bean(options) {
|
7
|
+
return function (target) {
|
8
|
+
const { scope = 'singleton', bindTo = [] } = options || {};
|
9
|
+
(0, inversify_1.injectable)()(target);
|
10
|
+
// Bind to self (class constructor)
|
11
|
+
const binding = container.bind(target).toSelf();
|
12
|
+
scope === 'singleton' ? binding.inSingletonScope() : binding.inTransientScope();
|
13
|
+
// Bind to each specified interface
|
14
|
+
bindTo.forEach(intrfc => {
|
15
|
+
const interfaceBinding = container.bind(intrfc).to(target);
|
16
|
+
scope === 'singleton'
|
17
|
+
? interfaceBinding.inSingletonScope()
|
18
|
+
: interfaceBinding.inTransientScope();
|
19
|
+
});
|
20
|
+
};
|
21
|
+
}
|
22
|
+
exports.default = container;
|
23
|
+
//# sourceMappingURL=container.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"container.js","sourceRoot":"","sources":["../../src/container/container.ts"],"names":[],"mappings":";;AAOA,oBAkBC;AAzBD,yCAAkD;AAClD,MAAM,SAAS,GAAG,IAAI,qBAAS,EAAE,CAAC;AAMlC,SAAgB,IAAI,CAAC,OAAoB;IACrC,OAAO,UAAU,MAAW;QACxB,MAAM,EAAE,KAAK,GAAG,WAAW,EAAE,MAAM,GAAG,EAAE,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;QAE3D,IAAA,sBAAU,GAAE,CAAC,MAAM,CAAC,CAAC;QAErB,mCAAmC;QACnC,MAAM,OAAO,GAAG,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,CAAC;QAChD,KAAK,KAAK,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,gBAAgB,EAAE,CAAC;QAEhF,mCAAmC;QACnC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;YACpB,MAAM,gBAAgB,GAAG,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC;YAC3D,KAAK,KAAK,WAAW;gBACjB,CAAC,CAAC,gBAAgB,CAAC,gBAAgB,EAAE;gBACrC,CAAC,CAAC,gBAAgB,CAAC,gBAAgB,EAAE,CAAC;QAC9C,CAAC,CAAC,CAAC;IACP,CAAC,CAAC;AACN,CAAC;AAED,kBAAe,SAAS,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"ICacheClient.d.ts","sourceRoot":"","sources":["../../../src/decorators/cache/ICacheClient.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IACzB,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IACzC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACpE,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACnC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"ICacheClient.js","sourceRoot":"","sources":["../../../src/decorators/cache/ICacheClient.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"cache.decorator.d.ts","sourceRoot":"","sources":["../../../src/decorators/cache/cache.decorator.ts"],"names":[],"mappings":"AAGA,wBAAgB,KAAK,CAAC,UAAU,GAAE,MAAW,EAAE,YAAY,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,MAAM,GAAG,eAAe,CAgCzG"}
|
@@ -0,0 +1,38 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.Cache = Cache;
|
7
|
+
const container_1 = __importDefault(require("../../container/container"));
|
8
|
+
function Cache(ttlSeconds = 60, keyGenerator) {
|
9
|
+
return (target, propertyKey, descriptor) => {
|
10
|
+
const originalMethod = descriptor.value;
|
11
|
+
const className = target.constructor.name;
|
12
|
+
const methodName = String(propertyKey);
|
13
|
+
descriptor.value = async function (...args) {
|
14
|
+
const cacheClient = container_1.default.get('CacheClient');
|
15
|
+
const cacheKey = keyGenerator
|
16
|
+
? keyGenerator(...args)
|
17
|
+
: `cache:${className}:${methodName}:${JSON.stringify(args)}`;
|
18
|
+
try {
|
19
|
+
const cached = await cacheClient.get(cacheKey);
|
20
|
+
if (cached)
|
21
|
+
return JSON.parse(cached);
|
22
|
+
}
|
23
|
+
catch (err) {
|
24
|
+
console.error('Cache read error:', err);
|
25
|
+
}
|
26
|
+
const result = await originalMethod.apply(this, args);
|
27
|
+
try {
|
28
|
+
await cacheClient.set(cacheKey, JSON.stringify(result), ttlSeconds);
|
29
|
+
}
|
30
|
+
catch (err) {
|
31
|
+
console.error('Cache write error:', err);
|
32
|
+
}
|
33
|
+
return result;
|
34
|
+
};
|
35
|
+
return descriptor;
|
36
|
+
};
|
37
|
+
}
|
38
|
+
//# sourceMappingURL=cache.decorator.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"cache.decorator.js","sourceRoot":"","sources":["../../../src/decorators/cache/cache.decorator.ts"],"names":[],"mappings":";;;;;AAGA,sBAgCC;AAnCD,0EAAkD;AAGlD,SAAgB,KAAK,CAAC,aAAqB,EAAE,EAAE,YAAyC;IACpF,OAAO,CAAC,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,EAAE;QACvC,MAAM,cAAc,GAAG,UAAU,CAAC,KAAgC,CAAC;QACnE,MAAM,SAAS,GAAG,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC;QAC1C,MAAM,UAAU,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC;QAEvC,UAAU,CAAC,KAAK,GAAG,KAAK,WAAsB,GAAG,IAAW;YACxD,MAAM,WAAW,GAAG,mBAAS,CAAC,GAAG,CAAe,aAAa,CAAC,CAAC;YAC/D,MAAM,QAAQ,GAAG,YAAY;gBACzB,CAAC,CAAC,YAAY,CAAC,GAAG,IAAI,CAAC;gBACvB,CAAC,CAAC,SAAS,SAAS,IAAI,UAAU,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;YAEjE,IAAI,CAAC;gBACD,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;gBAC/C,IAAI,MAAM;oBAAE,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;YAC1C,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACX,OAAO,CAAC,KAAK,CAAC,mBAAmB,EAAE,GAAG,CAAC,CAAC;YAC5C,CAAC;YAED,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YAEtD,IAAI,CAAC;gBACD,MAAM,WAAW,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,UAAU,CAAC,CAAC;YACxE,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACX,OAAO,CAAC,KAAK,CAAC,oBAAoB,EAAE,GAAG,CAAC,CAAC;YAC7C,CAAC;YAED,OAAO,MAAM,CAAC;QAClB,CAAQ,CAAC;QAET,OAAO,UAAU,CAAC;IACtB,CAAC,CAAC;AACN,CAAC"}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import 'reflect-metadata';
|
2
|
+
import { FastifyInstance } from 'fastify';
|
3
|
+
export declare const ROUTE_METADATA = "route:metadata";
|
4
|
+
export declare function Controller(prefix?: string): ClassDecorator;
|
5
|
+
export declare function registerControllers(fastify: FastifyInstance, controllers: Function[]): void;
|
6
|
+
export declare function printFastifyRoutes(routeOptions: any[], opts: {
|
7
|
+
colors: boolean;
|
8
|
+
}): void;
|
9
|
+
//# sourceMappingURL=controller.decorator.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"controller.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/controller.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EAAE,eAAe,EAA8C,MAAM,SAAS,CAAC;AAKtF,eAAO,MAAM,cAAc,mBAAmB,CAAC;AAW/C,wBAAgB,UAAU,CAAC,MAAM,GAAE,MAAW,GAAG,cAAc,CAI9D;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,QAAQ,EAAE,QAgDpF;AAED,wBAAgB,kBAAkB,CAAC,YAAY,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE;IAAE,MAAM,EAAE,OAAO,CAAA;CAAE,QAoBhF"}
|
@@ -0,0 +1,99 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.ROUTE_METADATA = void 0;
|
7
|
+
exports.Controller = Controller;
|
8
|
+
exports.registerControllers = registerControllers;
|
9
|
+
exports.printFastifyRoutes = printFastifyRoutes;
|
10
|
+
require("reflect-metadata");
|
11
|
+
const container_1 = __importDefault(require("../container/container"));
|
12
|
+
const Logger_1 = __importDefault(require("../logger/Logger"));
|
13
|
+
const CONTROLLER_METADATA = 'controller:metadata';
|
14
|
+
exports.ROUTE_METADATA = 'route:metadata';
|
15
|
+
function Controller(prefix = '') {
|
16
|
+
return (target) => {
|
17
|
+
Reflect.defineMetadata(CONTROLLER_METADATA, { prefix }, target);
|
18
|
+
};
|
19
|
+
}
|
20
|
+
function registerControllers(fastify, controllers) {
|
21
|
+
const routeOptions = [];
|
22
|
+
const fastifyWithHooks = fastify;
|
23
|
+
fastifyWithHooks.addHook("onRoute", (routeOption) => {
|
24
|
+
routeOptions.push(routeOption);
|
25
|
+
});
|
26
|
+
fastifyWithHooks.addHook("onReady", (done) => {
|
27
|
+
printFastifyRoutes(routeOptions, { colors: true });
|
28
|
+
done();
|
29
|
+
});
|
30
|
+
controllers.forEach(Controller => {
|
31
|
+
const controllerMetadata = Reflect.getMetadata(CONTROLLER_METADATA, Controller);
|
32
|
+
const routes = Reflect.getMetadata(exports.ROUTE_METADATA, Controller) || [];
|
33
|
+
const controllerInstance = container_1.default.get(Controller);
|
34
|
+
const prefix = controllerMetadata?.prefix || '';
|
35
|
+
routes.forEach(route => {
|
36
|
+
const fullPath = `${prefix}${route.path}`.replace(/\/\//g, '/');
|
37
|
+
const handler = async (request, reply) => {
|
38
|
+
try {
|
39
|
+
const result = await controllerInstance[route.handlerName](request, reply);
|
40
|
+
if (result !== undefined)
|
41
|
+
return result;
|
42
|
+
}
|
43
|
+
catch (error) {
|
44
|
+
Logger_1.default.error('Controller error:', error);
|
45
|
+
const statusCode = error.statusCode || 500;
|
46
|
+
const message = error.message || 'Internal Server Error';
|
47
|
+
reply.status(statusCode).send({ error: message });
|
48
|
+
}
|
49
|
+
};
|
50
|
+
const routeConfig = {
|
51
|
+
...route.options,
|
52
|
+
handler,
|
53
|
+
url: fullPath,
|
54
|
+
method: route.method
|
55
|
+
};
|
56
|
+
fastify.route(routeConfig);
|
57
|
+
});
|
58
|
+
});
|
59
|
+
}
|
60
|
+
function printFastifyRoutes(routeOptions, opts) {
|
61
|
+
const { colors } = opts;
|
62
|
+
if (routeOptions.length === 0) {
|
63
|
+
return;
|
64
|
+
}
|
65
|
+
routeOptions.sort((a, b) => a.url.localeCompare(b.url));
|
66
|
+
const logEntries = [];
|
67
|
+
logEntries.push("Available routes:");
|
68
|
+
for (const routeOption of routeOptions) {
|
69
|
+
const { method, url } = routeOption;
|
70
|
+
if (method === "HEAD")
|
71
|
+
continue;
|
72
|
+
const formattedMethod = colors ? colorMethod(method) : method;
|
73
|
+
logEntries.push(`${formattedMethod}\t${url}`);
|
74
|
+
}
|
75
|
+
Logger_1.default.info(logEntries.join("\n"));
|
76
|
+
}
|
77
|
+
const COLORS = {
|
78
|
+
yellow: 33,
|
79
|
+
green: 32,
|
80
|
+
blue: 34,
|
81
|
+
red: 31,
|
82
|
+
grey: 90,
|
83
|
+
magenta: 35,
|
84
|
+
clear: 39,
|
85
|
+
};
|
86
|
+
function colorText(color, string) {
|
87
|
+
return `\u001b[${color}m${string}\u001b[${COLORS.clear}m`;
|
88
|
+
}
|
89
|
+
function colorMethod(method) {
|
90
|
+
switch (method) {
|
91
|
+
case "POST": return colorText(COLORS.yellow, method);
|
92
|
+
case "GET": return colorText(COLORS.green, method);
|
93
|
+
case "PUT": return colorText(COLORS.blue, method);
|
94
|
+
case "DELETE": return colorText(COLORS.red, method);
|
95
|
+
case "PATCH": return colorText(COLORS.grey, method);
|
96
|
+
default: return method;
|
97
|
+
}
|
98
|
+
}
|
99
|
+
//# sourceMappingURL=controller.decorator.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"controller.decorator.js","sourceRoot":"","sources":["../../src/decorators/controller.decorator.ts"],"names":[],"mappings":";;;;;;AAiBA,gCAIC;AAED,kDAgDC;AAED,gDAoBC;AA7FD,4BAA0B;AAE1B,uEAA+C;AAC/C,8DAAsC;AAEtC,MAAM,mBAAmB,GAAG,qBAAqB,CAAC;AACrC,QAAA,cAAc,GAAG,gBAAgB,CAAC;AAW/C,SAAgB,UAAU,CAAC,SAAiB,EAAE;IAC5C,OAAO,CAAC,MAAgB,EAAE,EAAE;QAC1B,OAAO,CAAC,cAAc,CAAC,mBAAmB,EAAE,EAAE,MAAM,EAAE,EAAE,MAAM,CAAC,CAAC;IAClE,CAAC,CAAC;AACJ,CAAC;AAED,SAAgB,mBAAmB,CAAC,OAAwB,EAAE,WAAuB;IACnF,MAAM,YAAY,GAAU,EAAE,CAAC;IAE/B,MAAM,gBAAgB,GAAG,OAExB,CAAC;IAEF,gBAAgB,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,WAAW,EAAE,EAAE;QAClD,YAAY,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACjC,CAAC,CAAC,CAAC;IAE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KAAK,EAAE,EAAE;IACT,IAAI,EAAE,EAAE;IACR,GAAG,EAAE,EAAE;IACP,IAAI,EAAE,EAAE;IACR,OAAO,EAAE,EAAE;IACX,KAAK,EAAE,EAAE;CACV,CAAC;AAEF,SAAS,SAAS,CAAC,KAAa,EAAE,MAAc;IAC9C,OAAO,UAAU,KAAK,IAAI,MAAM,UAAU,MAAM,CAAC,KAAK,GAAG,CAAC;AAC5D,CAAC;AAED,SAAS,WAAW,CAAC,MAAc;IACjC,QAAQ,MAAM,EAAE,CAAC;QACf,KAAK,MAAM,CAAC,CAAC,OAAO,SAAS,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACrD,KAAK,KAAK,CAAC,CAAC,OAAO,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QACnD,KAAK,KAAK,CAAC,CAAC,OAAO,SAAS,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAClD,KAAK,QAAQ,CAAC,CAAC,OAAO,SAAS,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;QACpD,KAAK,OAAO,CAAC,CAAC,OAAO,SAAS,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACpD,OAAO,CAAC,CAAC,OAAO,MAAM,CAAC;IACzB,CAAC;AACH,CAAC"}
|
@@ -0,0 +1,7 @@
|
|
1
|
+
export declare function createMethodDecorator(method: string): (path?: string, options?: any) => MethodDecorator;
|
2
|
+
export declare const Get: (path?: string, options?: any) => MethodDecorator;
|
3
|
+
export declare const Post: (path?: string, options?: any) => MethodDecorator;
|
4
|
+
export declare const Put: (path?: string, options?: any) => MethodDecorator;
|
5
|
+
export declare const Delete: (path?: string, options?: any) => MethodDecorator;
|
6
|
+
export declare const Patch: (path?: string, options?: any) => MethodDecorator;
|
7
|
+
//# sourceMappingURL=http.decorator.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"http.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/http.decorator.ts"],"names":[],"mappings":"AAEA,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,IAC1C,OAAM,MAAW,EAAE,UAAU,GAAG,KAAG,eAAe,CAe3D;AAED,eAAO,MAAM,GAAG,UAjBA,MAAM,YAAiB,GAAG,KAAG,eAiBE,CAAC;AAChD,eAAO,MAAM,IAAI,UAlBD,MAAM,YAAiB,GAAG,KAAG,eAkBI,CAAC;AAClD,eAAO,MAAM,GAAG,UAnBA,MAAM,YAAiB,GAAG,KAAG,eAmBE,CAAC;AAChD,eAAO,MAAM,MAAM,UApBH,MAAM,YAAiB,GAAG,KAAG,eAoBQ,CAAC;AACtD,eAAO,MAAM,KAAK,UArBF,MAAM,YAAiB,GAAG,KAAG,eAqBM,CAAC"}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.Patch = exports.Delete = exports.Put = exports.Post = exports.Get = void 0;
|
4
|
+
exports.createMethodDecorator = createMethodDecorator;
|
5
|
+
const controller_decorator_1 = require("./controller.decorator");
|
6
|
+
function createMethodDecorator(method) {
|
7
|
+
return (path = '', options) => {
|
8
|
+
return (target, propertyKey, descriptor) => {
|
9
|
+
const routes = Reflect.getMetadata(controller_decorator_1.ROUTE_METADATA, target.constructor) || [];
|
10
|
+
routes.push({
|
11
|
+
path,
|
12
|
+
method: method.toUpperCase(),
|
13
|
+
handlerName: propertyKey,
|
14
|
+
options
|
15
|
+
});
|
16
|
+
Reflect.defineMetadata(controller_decorator_1.ROUTE_METADATA, routes, target.constructor);
|
17
|
+
return descriptor;
|
18
|
+
};
|
19
|
+
};
|
20
|
+
}
|
21
|
+
exports.Get = createMethodDecorator('GET');
|
22
|
+
exports.Post = createMethodDecorator('POST');
|
23
|
+
exports.Put = createMethodDecorator('PUT');
|
24
|
+
exports.Delete = createMethodDecorator('DELETE');
|
25
|
+
exports.Patch = createMethodDecorator('PATCH');
|
26
|
+
//# sourceMappingURL=http.decorator.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"http.decorator.js","sourceRoot":"","sources":["../../src/decorators/http.decorator.ts"],"names":[],"mappings":";;;AAEA,sDAgBC;AAlBD,iEAAwD;AAExD,SAAgB,qBAAqB,CAAC,MAAc;IAClD,OAAO,CAAC,OAAe,EAAE,EAAE,OAAa,EAAmB,EAAE;QAC3D,OAAO,CAAC,MAAW,EAAE,WAA4B,EAAE,UAA8B,EAAE,EAAE;YACnF,MAAM,MAAM,GAAU,OAAO,CAAC,WAAW,CAAC,qCAAc,EAAE,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC;YAEpF,MAAM,CAAC,IAAI,CAAC;gBACV,IAAI;gBACJ,MAAM,EAAE,MAAM,CAAC,WAAW,EAAE;gBAC5B,WAAW,EAAE,WAAW;gBACxB,OAAO;aACR,CAAC,CAAC;YAEH,OAAO,CAAC,cAAc,CAAC,qCAAc,EAAE,MAAM,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;YACnE,OAAO,UAAU,CAAC;QACpB,CAAC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAEY,QAAA,GAAG,GAAG,qBAAqB,CAAC,KAAK,CAAC,CAAC;AACnC,QAAA,IAAI,GAAG,qBAAqB,CAAC,MAAM,CAAC,CAAC;AACrC,QAAA,GAAG,GAAG,qBAAqB,CAAC,KAAK,CAAC,CAAC;AACnC,QAAA,MAAM,GAAG,qBAAqB,CAAC,QAAQ,CAAC,CAAC;AACzC,QAAA,KAAK,GAAG,qBAAqB,CAAC,OAAO,CAAC,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"timing.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/timing.decorator.ts"],"names":[],"mappings":"AAAA,wBAAgB,KAAK,IAAI,eAAe,CAsBvC"}
|