@vercube/core 0.0.1-alpha.15

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.
Files changed (74) hide show
  1. package/dist/Common/App.d.ts +56 -0
  2. package/dist/Common/Container.d.ts +8 -0
  3. package/dist/Common/CreateApp.d.ts +8 -0
  4. package/dist/Config/Config.d.ts +7 -0
  5. package/dist/Config/DefaultConfig.d.ts +6 -0
  6. package/dist/Config/Loader.d.ts +7 -0
  7. package/dist/Decorators/Hooks/Listen.d.ts +9 -0
  8. package/dist/Decorators/Http/Body.d.ts +15 -0
  9. package/dist/Decorators/Http/Connect.d.ts +10 -0
  10. package/dist/Decorators/Http/Controller.d.ts +10 -0
  11. package/dist/Decorators/Http/Delete.d.ts +10 -0
  12. package/dist/Decorators/Http/Get.d.ts +10 -0
  13. package/dist/Decorators/Http/Head.d.ts +10 -0
  14. package/dist/Decorators/Http/Header.d.ts +11 -0
  15. package/dist/Decorators/Http/Headers.d.ts +9 -0
  16. package/dist/Decorators/Http/Middleware.d.ts +27 -0
  17. package/dist/Decorators/Http/MultipartFormData.d.ts +15 -0
  18. package/dist/Decorators/Http/Options.d.ts +10 -0
  19. package/dist/Decorators/Http/Param.d.ts +12 -0
  20. package/dist/Decorators/Http/Patch.d.ts +10 -0
  21. package/dist/Decorators/Http/Post.d.ts +10 -0
  22. package/dist/Decorators/Http/Put.d.ts +10 -0
  23. package/dist/Decorators/Http/QueryParam.d.ts +16 -0
  24. package/dist/Decorators/Http/QueryParams.d.ts +15 -0
  25. package/dist/Decorators/Http/Redirect.d.ts +13 -0
  26. package/dist/Decorators/Http/Request.d.ts +9 -0
  27. package/dist/Decorators/Http/Response.d.ts +9 -0
  28. package/dist/Decorators/Http/Session.d.ts +9 -0
  29. package/dist/Decorators/Http/SetHeader.d.ts +7 -0
  30. package/dist/Decorators/Http/Status.d.ts +11 -0
  31. package/dist/Decorators/Http/Trace.d.ts +10 -0
  32. package/dist/Errors/Http/BadRequestError.d.ts +17 -0
  33. package/dist/Errors/Http/ForbiddenError.d.ts +17 -0
  34. package/dist/Errors/Http/InternalServerError.d.ts +17 -0
  35. package/dist/Errors/Http/MethodNotAllowedError.d.ts +17 -0
  36. package/dist/Errors/Http/NotAcceptableError.d.ts +17 -0
  37. package/dist/Errors/Http/NotFoundError.d.ts +17 -0
  38. package/dist/Errors/Http/UnauthorizedError.d.ts +17 -0
  39. package/dist/Errors/HttpError.d.ts +17 -0
  40. package/dist/Hooks/Router/RouterAfterInitHook.d.ts +1 -0
  41. package/dist/Hooks/Router/RouterBeforeInitHook.d.ts +1 -0
  42. package/dist/Middleware/ValidationMiddleware.d.ts +23 -0
  43. package/dist/Resolvers/Body.d.ts +22 -0
  44. package/dist/Resolvers/Headers.d.ts +14 -0
  45. package/dist/Resolvers/Query.d.ts +14 -0
  46. package/dist/Resolvers/RouterParam.d.ts +13 -0
  47. package/dist/Services/Config/RuntimeConfig.d.ts +22 -0
  48. package/dist/Services/ErrorHandler/DefaultErrorHandlerProvider.d.ts +16 -0
  49. package/dist/Services/ErrorHandler/ErrorHandlerProvider.d.ts +16 -0
  50. package/dist/Services/Hooks/HooksService.d.ts +76 -0
  51. package/dist/Services/HttpServer/HttpServer.d.ts +51 -0
  52. package/dist/Services/Metadata/MetadataResolver.d.ts +42 -0
  53. package/dist/Services/Middleware/BaseMiddleware.d.ts +31 -0
  54. package/dist/Services/Middleware/GlobalMiddlewareRegistry.d.ts +31 -0
  55. package/dist/Services/Plugins/BasePlugin.d.ts +16 -0
  56. package/dist/Services/Plugins/PluginsRegistry.d.ts +26 -0
  57. package/dist/Services/Router/RequestHandler.d.ts +65 -0
  58. package/dist/Services/Router/Router.d.ts +40 -0
  59. package/dist/Services/Router/StaticRequestHandler.d.ts +38 -0
  60. package/dist/Services/Validation/StandardSchemaValidationProvider.d.ts +17 -0
  61. package/dist/Services/Validation/ValidationProvider.d.ts +17 -0
  62. package/dist/Types/CommonTypes.d.ts +6 -0
  63. package/dist/Types/ConfigTypes.d.ts +120 -0
  64. package/dist/Types/HooksTypes.d.ts +17 -0
  65. package/dist/Types/HttpTypes.d.ts +63 -0
  66. package/dist/Types/MetadataTypes.d.ts +54 -0
  67. package/dist/Types/ValidationTypes.d.ts +6 -0
  68. package/dist/Utils/InternalUtils.d.ts +5 -0
  69. package/dist/Utils/Mine.d.ts +3 -0
  70. package/dist/Utils/Utils.d.ts +22 -0
  71. package/dist/index.cjs +2018 -0
  72. package/dist/index.d.ts +46 -0
  73. package/dist/index.mjs +1944 -0
  74. package/package.json +35 -0
package/dist/index.mjs ADDED
@@ -0,0 +1,1944 @@
1
+ import { BaseDecorator, Container, Inject, InjectOptional, createDecorator, initializeContainer } from "@vercube/di";
2
+ import { serve } from "srvx";
3
+ import { addRoute, createRouter, findRoute } from "rou3";
4
+ import { createReadStream } from "node:fs";
5
+ import { extname, join, normalize } from "node:path";
6
+ import { stat } from "node:fs/promises";
7
+ import { BaseLogger, Logger } from "@vercube/logger";
8
+ import { loadConfig } from "c12";
9
+ import { defu } from "defu";
10
+
11
+ //#region node_modules/.pnpm/@oxc-project+runtime@0.62.0/node_modules/@oxc-project/runtime/src/helpers/esm/decorate.js
12
+ function __decorate(decorators, target, key, desc) {
13
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
14
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
15
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
16
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
17
+ }
18
+
19
+ //#endregion
20
+ //#region packages/core/src/Services/Plugins/PluginsRegistry.ts
21
+ var PluginsRegistry = class {
22
+ gContainer;
23
+ /** Holds the list of plugins */
24
+ fPlugins = new Map();
25
+ /**
26
+ * Registers a plugin.
27
+ *
28
+ * @param {Plugin} plugin - The plugin to register.
29
+ * @param {unknown} options - The options to pass to the plugin.
30
+ */
31
+ register(plugin, options) {
32
+ const instance = this.gContainer.resolve(plugin);
33
+ this.fPlugins.set(instance.name, {
34
+ instance,
35
+ options
36
+ });
37
+ }
38
+ /**
39
+ * Gets the list of registered plugins.
40
+ *
41
+ * @returns {Plugin[]} The list of registered plugins.
42
+ */
43
+ get plugins() {
44
+ return [...this.fPlugins.values()].map((plugin) => plugin.instance);
45
+ }
46
+ /**
47
+ * Resolves the plugins.
48
+ *
49
+ * @param {App} app - The application instance.
50
+ */
51
+ async init(app) {
52
+ for (const { instance, options } of this.fPlugins.values()) await instance.use(app, options);
53
+ }
54
+ };
55
+ __decorate([Inject(Container)], PluginsRegistry.prototype, "gContainer", void 0);
56
+
57
+ //#endregion
58
+ //#region packages/core/src/Services/Hooks/HooksService.ts
59
+ var HooksService = class {
60
+ fLastId = 0;
61
+ fHandlers = new Map();
62
+ /**
63
+ * Registers listener for event of particular type. Everytime event is called, the listener
64
+ * will be executed.
65
+ *
66
+ * @param type type of event, simple class
67
+ * @param callback callback fired when event is triggered
68
+ * @returns unique ID for event listener, can be used to disable this listener
69
+ */
70
+ on(type, callback) {
71
+ let handlersOfType = this.fHandlers.get(type);
72
+ if (!handlersOfType) {
73
+ handlersOfType = [];
74
+ this.fHandlers.set(type, handlersOfType);
75
+ }
76
+ const genId = this.fLastId++;
77
+ const handler = {
78
+ callback,
79
+ id: genId
80
+ };
81
+ handlersOfType.push(handler);
82
+ return {
83
+ __id: genId,
84
+ __type: type
85
+ };
86
+ }
87
+ /**
88
+ * Waits for single event execution and removes the listener immediately after.
89
+ *
90
+ * @example
91
+ * this.gCart.addItem(product);
92
+ * await this.gEvents.waitFor(CartUpdatedEvent);
93
+ * console.log('here cart updated event is already called');
94
+ *
95
+ * @param type type of event to wait for
96
+ * @param timeout timeout param in ms - if event is not thrown until this time, it'll reject. passing null disables the timeout
97
+ * @returns promise with event data that resolves when event is finally called
98
+ */
99
+ waitFor(type, timeout = 10 * 1e3) {
100
+ return new Promise((resolve, reject) => {
101
+ let waitTimeout;
102
+ const eventId = this.on(type, (data) => {
103
+ this.off(eventId);
104
+ resolve(data);
105
+ if (waitTimeout) clearTimeout(waitTimeout);
106
+ });
107
+ if (timeout !== null) waitTimeout = setTimeout(() => {
108
+ this.off(eventId);
109
+ reject(new Error(`Waiting for event timeout - ${type.name}`));
110
+ }, timeout);
111
+ });
112
+ }
113
+ /**
114
+ * Removes listener from particular event.
115
+ * @param eventId eventId returned from .on() method.
116
+ * @throws Error if event was not registered
117
+ */
118
+ off(eventId) {
119
+ const type = eventId.__type;
120
+ const handlersOfType = this.fHandlers.get(type);
121
+ if (!handlersOfType) throw new Error("Trying to unbind event that was not bound.");
122
+ const index = handlersOfType.findIndex((handler) => handler.id === eventId.__id);
123
+ if (index === -1) throw new Error("Trying to unbind event that was not bound.");
124
+ handlersOfType.splice(index, 1);
125
+ }
126
+ /**
127
+ * Triggers event, calling all listener callbacks. Will return Promise of number,
128
+ * that is resolved when all asynchronous listeners are called.
129
+ * @param type type of trigger, simple class
130
+ * @param data data which will be passed to listeners, based on event class
131
+ * @return number of listeners that were notified
132
+ */
133
+ async trigger(type, data) {
134
+ const handlersOfType = this.fHandlers.get(type);
135
+ if (!handlersOfType) return 0;
136
+ const toProcessHandlers = [...handlersOfType];
137
+ const promises = toProcessHandlers.map((handler) => {
138
+ const instance = this.objectToClass(type, data);
139
+ const result = handler.callback(instance);
140
+ return result instanceof Promise ? result : Promise.resolve();
141
+ });
142
+ await Promise.all(promises);
143
+ return toProcessHandlers.length;
144
+ }
145
+ /**
146
+ * Converts plain object to it's class equivalent.
147
+ * It's NOT class-transformer, it performs basic key assigment.
148
+ *
149
+ * @param ClassConstructor event constructor
150
+ * @param data event data to be mapped to constructor
151
+ * @return class type of event
152
+ */
153
+ objectToClass(ClassConstructor, data) {
154
+ const instance = new ClassConstructor();
155
+ if (data) for (const key of Object.keys(data)) {
156
+ const rawInstance = instance;
157
+ const rawData = data;
158
+ rawInstance[key] = rawData[key];
159
+ }
160
+ return instance;
161
+ }
162
+ };
163
+
164
+ //#endregion
165
+ //#region packages/core/src/Hooks/Router/RouterBeforeInitHook.ts
166
+ var RouterBeforeInitHook = class {};
167
+
168
+ //#endregion
169
+ //#region packages/core/src/Hooks/Router/RouterAfterInitHook.ts
170
+ var RouterAfterInitHook = class {};
171
+
172
+ //#endregion
173
+ //#region packages/core/src/Services/Router/Router.ts
174
+ var Router = class {
175
+ /**
176
+ * Service for triggering application hooks
177
+ */
178
+ gHooksService;
179
+ /**
180
+ * Internal router context that stores all registered routes
181
+ * @private
182
+ */
183
+ fRouterContext;
184
+ /**
185
+ * Registers a new route in the router
186
+ *
187
+ * @param {RouterTypes.Route} route - The route configuration to add
188
+ * @throws {Error} If router is not initialized
189
+ */
190
+ addRoute(route) {
191
+ if (!this.fRouterContext) throw new Error("Router not initialized. Please call init() before adding routes.");
192
+ addRoute(this.fRouterContext, route.method.toUpperCase(), route.path, route.handler);
193
+ }
194
+ /**
195
+ * Initializes the router and triggers related hooks
196
+ *
197
+ * This method creates a new router context and triggers
198
+ * the before and after initialization hooks.
199
+ */
200
+ init() {
201
+ this.gHooksService.trigger(RouterBeforeInitHook);
202
+ this.fRouterContext = createRouter();
203
+ this.gHooksService.trigger(RouterAfterInitHook);
204
+ }
205
+ /**
206
+ * Resolves a route based on the HTTP method and path
207
+ *
208
+ * @param {RouterTypes.RouteFind} route - The route to resolve
209
+ * @returns {RouterTypes.RouteMatched<RouterTypes.RouterHandler> | undefined} The matched route or undefined if no match found
210
+ */
211
+ resolve(route) {
212
+ let url = route.path;
213
+ try {
214
+ url = new URL(route.path).pathname;
215
+ } catch {}
216
+ return findRoute(this.fRouterContext, route.method.toUpperCase(), url);
217
+ }
218
+ };
219
+ __decorate([Inject(HooksService)], Router.prototype, "gHooksService", void 0);
220
+
221
+ //#endregion
222
+ //#region packages/core/src/Resolvers/RouterParam.ts
223
+ function resolveRouterParam(param, event) {
224
+ return event.params?.[param] ?? null;
225
+ }
226
+
227
+ //#endregion
228
+ //#region packages/core/src/Errors/HttpError.ts
229
+ var HttpError = class HttpError extends Error {
230
+ /**
231
+ * The HTTP status code associated with the error.
232
+ * @type {number}
233
+ */
234
+ status;
235
+ /**
236
+ * Creates an instance of HttpError.
237
+ * @param {number} status - The HTTP status code.
238
+ * @param {string} [message] - The error message.
239
+ */
240
+ constructor(status, message) {
241
+ super();
242
+ Object.setPrototypeOf(this, HttpError.prototype);
243
+ if (status) this.status = status;
244
+ if (message) this.message = message;
245
+ this.stack = new Error().stack;
246
+ }
247
+ };
248
+
249
+ //#endregion
250
+ //#region packages/core/src/Errors/Http/BadRequestError.ts
251
+ var BadRequestError = class BadRequestError extends HttpError {
252
+ /**
253
+ * The name of the error.
254
+ * @type {string}
255
+ */
256
+ name = "BadRequestError";
257
+ /**
258
+ * Creates an instance of BadRequestError.
259
+ * @param {string} [message] - The error message.
260
+ */
261
+ constructor(message, errors) {
262
+ super(400);
263
+ Object.setPrototypeOf(this, BadRequestError.prototype);
264
+ if (message) this.message = message;
265
+ if (errors) this.errors = errors;
266
+ }
267
+ };
268
+
269
+ //#endregion
270
+ //#region packages/core/src/Resolvers/Body.ts
271
+ async function resolveRequestBody(event) {
272
+ const text = await event.request.text();
273
+ if (!text) return void 0;
274
+ try {
275
+ return JSON.parse(text);
276
+ } catch {
277
+ throw new BadRequestError("Invalid JSON body");
278
+ }
279
+ }
280
+
281
+ //#endregion
282
+ //#region packages/core/src/Resolvers/Query.ts
283
+ function resolveQueryParam(name, event) {
284
+ const url = new URL(event.request.url);
285
+ return url.searchParams.get(name);
286
+ }
287
+ function resolveQueryParams(event) {
288
+ const url = new URL(event.request.url);
289
+ const params = {};
290
+ for (const [key, value] of url.searchParams) params[key] = value;
291
+ return params;
292
+ }
293
+
294
+ //#endregion
295
+ //#region packages/core/src/Resolvers/Headers.ts
296
+ function getRequestHeader(header, event) {
297
+ return event.request.headers.get(header);
298
+ }
299
+ function getRequestHeaders(event) {
300
+ return event.request.headers;
301
+ }
302
+
303
+ //#endregion
304
+ //#region packages/core/src/Services/Metadata/MetadataResolver.ts
305
+ var MetadataResolver = class {
306
+ /**
307
+ * Resolves the URL for a given instance and path.
308
+ *
309
+ * @param {MetadataTypes.ResolveUrlParams} params - The parameters for resolving the URL.
310
+ * @return {string} The resolved URL.
311
+ */
312
+ resolveUrl(params) {
313
+ const { instance, propertyName, path: rawPath } = params;
314
+ const metadata = instance.__metadata;
315
+ const basePath = (metadata?.__controller?.path ?? "").replace(/\/$/, "");
316
+ const cleanPath = rawPath.replace(/^\//, "");
317
+ const url = `${basePath}/${cleanPath}`;
318
+ metadata.__methods[propertyName].url = url;
319
+ return url;
320
+ }
321
+ resolveMethod(ctx, propertyName) {
322
+ return ctx.__metadata.__methods[propertyName];
323
+ }
324
+ /**
325
+ * Resolves arguments for a given event.
326
+ *
327
+ * @param {MetadataTypes.Arg[]} args - The arguments to resolve.
328
+ * @param {RouterTypes.RouterEvent} event - The event to resolve arguments for.
329
+ * @return {unknown[]} The resolved arguments.
330
+ * @public
331
+ */
332
+ async resolveArgs(args, event) {
333
+ args.sort((a, b) => a.idx - b.idx);
334
+ const resolvedArgs = args.map(async (arg) => ({
335
+ ...arg,
336
+ resolved: await this.resolveArg(arg, event)
337
+ }));
338
+ return await Promise.all(resolvedArgs);
339
+ }
340
+ /**
341
+ * Resolves an argument for a given event.
342
+ *
343
+ * @param {MetadataTypes.Arg} arg - The argument to resolve.
344
+ *
345
+ * @return {unknown} The resolved argument.
346
+ * @private
347
+ */
348
+ resolveArg(arg, event) {
349
+ switch (arg.type) {
350
+ case "param": return resolveRouterParam(arg?.data?.name ?? "", event);
351
+ case "body": return resolveRequestBody(event);
352
+ case "multipart-form-data": return null;
353
+ case "query-param": return resolveQueryParam(arg?.data?.name ?? "", event);
354
+ case "query-params": return resolveQueryParams(event);
355
+ case "header": return getRequestHeader(arg.data?.name ?? "", event);
356
+ case "headers": return getRequestHeaders(event);
357
+ case "request": return event.request;
358
+ case "response": return event.response;
359
+ case "session": return null;
360
+ default: throw new Error(`Unknown argument type: ${arg.type}`);
361
+ }
362
+ }
363
+ /**
364
+ * Resolves middleware functions for a given context and property name.
365
+ *
366
+ * @param {MetadataTypes.Ctx} ctx - The metadata context object
367
+ * @param {string} propertyName - The name of the property to resolve middlewares for
368
+ * @returns {MetadataTypes.Middleware[]} Array of middleware functions that apply globally or to the specific property
369
+ * @public
370
+ */
371
+ resolveMiddlewares(ctx, propertyName) {
372
+ const middlewares = ctx?.__metadata?.__middlewares?.filter((m) => m.target === "__global__" || m.target === propertyName) ?? [];
373
+ return middlewares.sort((a) => a.target === "__global__" ? -1 : 1);
374
+ }
375
+ };
376
+
377
+ //#endregion
378
+ //#region packages/core/src/Services/ErrorHandler/ErrorHandlerProvider.ts
379
+ var ErrorHandlerProvider = class {};
380
+
381
+ //#endregion
382
+ //#region packages/core/src/Services/Middleware/GlobalMiddlewareRegistry.ts
383
+ var GlobalMiddlewareRegistry = class {
384
+ fMiddlewares = new Set();
385
+ /**
386
+ * Retrieves all registered global middleware configurations
387
+ *
388
+ * @returns {MetadataTypes.Middleware[]} An array of middleware configurations
389
+ */
390
+ get middlewares() {
391
+ return [...this.fMiddlewares.values()].map((m) => ({
392
+ ...m.opts,
393
+ target: "__global__",
394
+ middleware: m.middleware
395
+ }));
396
+ }
397
+ /**
398
+ * Registers a global middleware configuration
399
+ *
400
+ * @param {typeof BaseMiddleware<T, U>} middleware - The middleware class to register
401
+ * @param {GlobalMiddlewareParams<T>} opts - The middleware options
402
+ * @returns {void}
403
+ */
404
+ registerGlobalMiddleware(middleware, opts) {
405
+ this.fMiddlewares.add({
406
+ middleware,
407
+ opts
408
+ });
409
+ }
410
+ };
411
+
412
+ //#endregion
413
+ //#region packages/core/src/Services/Router/RequestHandler.ts
414
+ var RequestHandler = class {
415
+ /** Resolver for extracting metadata from controller classes and methods */
416
+ gMetadataResolver;
417
+ /** DI container for resolving dependencies */
418
+ gContainer;
419
+ /** Provider for handling errors during request processing */
420
+ gErrorHandlerProvider;
421
+ gGlobalMiddlewareRegistry;
422
+ /**
423
+ * Prepares a route handler by resolving its metadata and middlewares
424
+ *
425
+ * @param {RequestHandlerOptions} params - Configuration options for the handler
426
+ * @returns {RouterTypes.RouterHandler} A prepared handler with resolved metadata and middlewares
427
+ */
428
+ prepareHandler(params) {
429
+ const { instance, propertyName } = params;
430
+ const prototype = Object.getPrototypeOf(instance);
431
+ const method = this.gMetadataResolver.resolveMethod(prototype, propertyName);
432
+ const middlewares = this.gMetadataResolver.resolveMiddlewares(prototype, propertyName);
433
+ const globalMiddlewares = this.gGlobalMiddlewareRegistry.middlewares;
434
+ const uniqueMiddlewares = [...middlewares, ...globalMiddlewares].filter((m, index, self) => self.findIndex((t) => t.middleware === m.middleware) === index);
435
+ const resolvedMiddlewares = uniqueMiddlewares.map((m) => ({
436
+ ...m,
437
+ middleware: this.gContainer.resolve(m.middleware)
438
+ }));
439
+ const beforeMiddlewares = resolvedMiddlewares.filter((m) => !!m.middleware.onRequest);
440
+ const afterMiddlewares = resolvedMiddlewares.filter((m) => !!m.middleware.onResponse);
441
+ beforeMiddlewares.sort((a, b) => (a?.priority ?? 999) - (b?.priority ?? 999));
442
+ afterMiddlewares.sort((a, b) => (a?.priority ?? 999) - (b?.priority ?? 999));
443
+ return {
444
+ instance,
445
+ propertyName,
446
+ args: method.args,
447
+ middlewares: {
448
+ beforeMiddlewares,
449
+ afterMiddlewares
450
+ },
451
+ actions: method.actions
452
+ };
453
+ }
454
+ /**
455
+ * Processes an HTTP request through the middleware chain and route handler
456
+ *
457
+ * The request handling lifecycle:
458
+ * 1. Execute "before" middlewares
459
+ * 2. Apply route actions (status codes, redirects, etc.)
460
+ * 3. Resolve handler arguments
461
+ * 4. Execute the route handler
462
+ * 5. Execute "after" middlewares
463
+ * 6. Format and return the final response
464
+ *
465
+ * @param {Request} request - The incoming HTTP request
466
+ * @param {RouterTypes.RouteMatched<RouterTypes.RouterHandler>} route - The matched route with handler data
467
+ * @returns {Promise<Response>} The HTTP response
468
+ */
469
+ async handleRequest(request, route) {
470
+ try {
471
+ const { instance, propertyName, actions, args, middlewares } = route.data;
472
+ let fakeResponse = new Response(void 0, { headers: { "Content-Type": request.headers.get("Content-Type") ?? "application/json" } });
473
+ for await (const hook of middlewares?.beforeMiddlewares ?? []) try {
474
+ const hookResponse = await hook.middleware.onRequest?.(request, fakeResponse, {
475
+ middlewareArgs: hook.args,
476
+ methodArgs: args
477
+ });
478
+ if (hookResponse instanceof Response) return hookResponse;
479
+ } catch (error) {
480
+ return this.gErrorHandlerProvider.handleError(error);
481
+ }
482
+ for (const action of actions) {
483
+ const actionResponse = action.handler(request, fakeResponse);
484
+ if (actionResponse !== null) fakeResponse = this.processOverrideResponse(actionResponse, fakeResponse);
485
+ }
486
+ const resolvedArgs = await this.gMetadataResolver.resolveArgs(args, {
487
+ ...route,
488
+ request,
489
+ response: fakeResponse
490
+ });
491
+ let handlerResponse = instance[propertyName].call(instance, ...resolvedArgs?.map((a) => a.resolved) ?? []);
492
+ if (handlerResponse instanceof Promise) handlerResponse = await handlerResponse;
493
+ for await (const hook of middlewares?.afterMiddlewares ?? []) try {
494
+ const hookResponse = await hook.middleware.onResponse?.(request, fakeResponse, handlerResponse);
495
+ if (hookResponse !== null) fakeResponse = this.processOverrideResponse(hookResponse, fakeResponse);
496
+ } catch (error) {
497
+ return this.gErrorHandlerProvider.handleError(error);
498
+ }
499
+ const body = fakeResponse?.body ?? JSON.stringify(handlerResponse);
500
+ return new Response(body, {
501
+ status: fakeResponse.status,
502
+ statusText: fakeResponse.statusText,
503
+ headers: fakeResponse.headers
504
+ });
505
+ } catch (error_) {
506
+ return this.gErrorHandlerProvider.handleError(error_);
507
+ }
508
+ }
509
+ /**
510
+ * Processes and merges response overrides from middlewares or actions
511
+ *
512
+ * This method handles different response formats:
513
+ * - If a full Response object is provided, it's used directly
514
+ * - If ResponseInit is provided, it's merged with the base response
515
+ *
516
+ * @param {Response | ResponseInit} response - The response or response options to apply
517
+ * @param {Response} [base] - The base response to extend (optional)
518
+ * @returns {Response} The processed response with applied overrides
519
+ * @private
520
+ */
521
+ processOverrideResponse(response, base) {
522
+ let fakeResponse = base ?? new Response();
523
+ if (response != null && response instanceof Response) return response;
524
+ else if (response !== null) {
525
+ const responseInit = response;
526
+ fakeResponse = new Response(void 0, {
527
+ status: responseInit?.status ?? fakeResponse.status,
528
+ headers: responseInit?.headers ?? fakeResponse.headers,
529
+ statusText: responseInit?.statusText ?? fakeResponse.statusText
530
+ });
531
+ }
532
+ return fakeResponse;
533
+ }
534
+ };
535
+ __decorate([Inject(MetadataResolver)], RequestHandler.prototype, "gMetadataResolver", void 0);
536
+ __decorate([Inject(Container)], RequestHandler.prototype, "gContainer", void 0);
537
+ __decorate([Inject(ErrorHandlerProvider)], RequestHandler.prototype, "gErrorHandlerProvider", void 0);
538
+ __decorate([Inject(GlobalMiddlewareRegistry)], RequestHandler.prototype, "gGlobalMiddlewareRegistry", void 0);
539
+
540
+ //#endregion
541
+ //#region packages/core/src/Utils/Mine.ts
542
+ const mime = { getType(ext) {
543
+ const types = {
544
+ ".html": "text/html",
545
+ ".css": "text/css",
546
+ ".js": "application/javascript",
547
+ ".json": "application/json",
548
+ ".png": "image/png",
549
+ ".jpg": "image/jpeg",
550
+ ".jpeg": "image/jpeg",
551
+ ".gif": "image/gif",
552
+ ".svg": "image/svg+xml",
553
+ ".ico": "image/x-icon"
554
+ };
555
+ return types[ext] || null;
556
+ } };
557
+
558
+ //#endregion
559
+ //#region packages/core/src/Services/Router/StaticRequestHandler.ts
560
+ var StaticRequestHandler = class {
561
+ /**
562
+ * The options for the static server
563
+ */
564
+ fOptions;
565
+ /**
566
+ * Initializes the static server with the given options
567
+ *
568
+ * @param {ConfigTypes.ServerOptions['static']} options - The options for the static server
569
+ * @returns {void}
570
+ */
571
+ initialize(options) {
572
+ this.fOptions = options;
573
+ }
574
+ /**
575
+ * Handles HTTP requests for static files
576
+ *
577
+ * @param {Request} request - The incoming HTTP request
578
+ * @returns {Promise<void | Response>} A promise that resolves to void or a Response object
579
+ */
580
+ async handleRequest(request) {
581
+ const dirs = this.fOptions?.dirs ?? [];
582
+ if (!dirs) return;
583
+ if (request.method !== "GET") return;
584
+ const url = new URL(request.url);
585
+ const path = normalize(url.pathname);
586
+ let relativePath = path;
587
+ for (const dir of dirs) relativePath = relativePath.replace(dir, "");
588
+ for (const dir of dirs) {
589
+ const fullPath = join(process.cwd(), dir, relativePath);
590
+ try {
591
+ const stats = await stat(fullPath);
592
+ if (stats.isDirectory()) continue;
593
+ if (stats.isFile()) return this.serveFile(fullPath, stats);
594
+ } catch {
595
+ continue;
596
+ }
597
+ }
598
+ }
599
+ /**
600
+ * Serves a static file and returns a Response object
601
+ *
602
+ * @param {string} path - The path to the file to serve
603
+ * @param {any} stats - The stats object for the file
604
+ * @returns {Promise<Response>} A promise that resolves to a Response object
605
+ */
606
+ async serveFile(path, stats) {
607
+ const headers = new Headers();
608
+ const ext = extname(path).toLowerCase();
609
+ const contentType = mime.getType(ext) || "application/octet-stream";
610
+ headers.set("Content-Type", contentType);
611
+ headers.set("Content-Length", stats.size.toString());
612
+ if (this.fOptions?.maxAge && this.fOptions.maxAge > 0) {
613
+ const directives = ["public", `max-age=${this.fOptions.maxAge}`];
614
+ if (this.fOptions?.immutable) directives.push("immutable");
615
+ headers.set("Cache-Control", directives.join(", "));
616
+ }
617
+ if (this.fOptions?.etag) headers.set("ETag", `W/"${stats.size}-${stats.mtime.getTime()}"`);
618
+ const stream = createReadStream(path);
619
+ return new Response(stream, { headers });
620
+ }
621
+ };
622
+
623
+ //#endregion
624
+ //#region packages/core/src/Services/HttpServer/HttpServer.ts
625
+ var HttpServer = class {
626
+ /**
627
+ * Router service for resolving routes
628
+ */
629
+ gRouter;
630
+ /**
631
+ * Handler for processing HTTP requests
632
+ */
633
+ gRequestHandler;
634
+ /**
635
+ * Error handler provider for managing error responses
636
+ */
637
+ gErrorHandlerProvider;
638
+ /**
639
+ * Static server for serving static files
640
+ */
641
+ gStaticRequestHandler;
642
+ /**
643
+ * Underlying server instance
644
+ * @private
645
+ */
646
+ fServer;
647
+ /**
648
+ * Initializes the HTTP server and starts listening for requests
649
+ *
650
+ * @returns {Promise<void>} A promise that resolves when the server is ready
651
+ */
652
+ async initialize(config) {
653
+ const { port, host } = config.server ?? {};
654
+ this.fServer = serve({
655
+ bun: { error: (error) => {
656
+ return this.gErrorHandlerProvider.handleError(error);
657
+ } },
658
+ deno: { onError: (error) => {
659
+ return this.gErrorHandlerProvider.handleError(error);
660
+ } },
661
+ hostname: host,
662
+ port,
663
+ fetch: this.handleRequest.bind(this)
664
+ });
665
+ await this.fServer.ready();
666
+ }
667
+ /**
668
+ * Processes an incoming HTTP request
669
+ *
670
+ * This method:
671
+ * 1. Resolves the route for the request
672
+ * 2. Returns a 404 response if no route is found
673
+ * 3. Delegates to the request handler for matched routes
674
+ *
675
+ * @param {Request} request - The incoming HTTP request
676
+ * @returns {Promise<Response>} The HTTP response
677
+ * @private
678
+ */
679
+ async handleRequest(request) {
680
+ try {
681
+ const route = this.gRouter.resolve({
682
+ path: request.url,
683
+ method: request.method
684
+ });
685
+ if (!route) {
686
+ const response = await this.gStaticRequestHandler.handleRequest(request);
687
+ if (response) return response;
688
+ else throw new NotFoundError("Route not found");
689
+ }
690
+ return this.gRequestHandler.handleRequest(request, route);
691
+ } catch (error) {
692
+ return this.gErrorHandlerProvider.handleError(error);
693
+ }
694
+ }
695
+ };
696
+ __decorate([Inject(Router)], HttpServer.prototype, "gRouter", void 0);
697
+ __decorate([Inject(RequestHandler)], HttpServer.prototype, "gRequestHandler", void 0);
698
+ __decorate([Inject(ErrorHandlerProvider)], HttpServer.prototype, "gErrorHandlerProvider", void 0);
699
+ __decorate([Inject(StaticRequestHandler)], HttpServer.prototype, "gStaticRequestHandler", void 0);
700
+
701
+ //#endregion
702
+ //#region packages/core/src/Common/App.ts
703
+ var App = class {
704
+ gRouter;
705
+ gPluginsRegistry;
706
+ gHttpServer;
707
+ gStaticRequestHandler;
708
+ /** Holds the initialization status of the application */
709
+ fIsInitialized = false;
710
+ /** Holds the dependency injection container */
711
+ fInternalContainer;
712
+ /** Hold app config */
713
+ fConfig;
714
+ /**
715
+ * Gets the dependency injection container.
716
+ *
717
+ * @returns {Container} The dependency injection container.
718
+ */
719
+ get container() {
720
+ return this.fInternalContainer;
721
+ }
722
+ /**
723
+ * Sets the dependency injection container.
724
+ *
725
+ * @param {Container} container - The dependency injection container.
726
+ */
727
+ set container(container) {
728
+ this.fInternalContainer = container;
729
+ }
730
+ /**
731
+ * Initializes the application.
732
+ *
733
+ * @returns {Promise<void>} A promise that resolves when the application is initialized.
734
+ */
735
+ async init(cfg) {
736
+ this.fConfig = cfg;
737
+ await this.gHttpServer.initialize(this.fConfig);
738
+ if (this.fConfig.server?.static) this.gStaticRequestHandler.initialize(this.fConfig.server?.static);
739
+ this.gRouter.init();
740
+ }
741
+ /**
742
+ * Registers a plugin.
743
+ *
744
+ * @param {typeof Plugin} plugin - The plugin to register.
745
+ * @param {unknown} options - The options to pass to the plugin.
746
+ */
747
+ registerPlugin(plugin, options) {
748
+ this.gPluginsRegistry.register(plugin, options);
749
+ }
750
+ /**
751
+ * Starts the application and begins listening for incoming requests.
752
+ *
753
+ * @returns {Promise<void>} A promise that resolves when the application starts listening.
754
+ * @throws {Error} If the application is already initialized.
755
+ */
756
+ async listen() {
757
+ if (this.fIsInitialized) throw new Error("App is already initialized");
758
+ await this.resolvePlugins();
759
+ initializeContainer(this.container);
760
+ }
761
+ /**
762
+ * Resolves and initializes the plugins for the application.
763
+ *
764
+ * @private
765
+ */
766
+ async resolvePlugins() {
767
+ await this.gPluginsRegistry.init(this);
768
+ }
769
+ };
770
+ __decorate([Inject(Router)], App.prototype, "gRouter", void 0);
771
+ __decorate([Inject(PluginsRegistry)], App.prototype, "gPluginsRegistry", void 0);
772
+ __decorate([Inject(HttpServer)], App.prototype, "gHttpServer", void 0);
773
+ __decorate([Inject(StaticRequestHandler)], App.prototype, "gStaticRequestHandler", void 0);
774
+
775
+ //#endregion
776
+ //#region packages/logger/dist/Providers/index.mjs
777
+ var LoggerProvider = class {};
778
+ const isColorAllowed = () => !process.env.NO_COLOR;
779
+ const colorIfAllowed = (colorFn) => {
780
+ const wrappedFn = (text) => {
781
+ return isColorAllowed() ? colorFn(text) : text;
782
+ };
783
+ return wrappedFn;
784
+ };
785
+ const colors = {
786
+ bold: colorIfAllowed((text) => `\x1B[1m${text}\x1B[0m`),
787
+ green: colorIfAllowed((text) => `\x1B[32m${text}\x1B[39m`),
788
+ yellow: colorIfAllowed((text) => `\x1B[33m${text}\x1B[39m`),
789
+ red: colorIfAllowed((text) => `\x1B[31m${text}\x1B[39m`),
790
+ magentaBright: colorIfAllowed((text) => `\x1B[95m${text}\x1B[39m`),
791
+ cyanBright: colorIfAllowed((text) => `\x1B[96m${text}\x1B[39m`)
792
+ };
793
+ const LOG_LEVEL_COLORS = {
794
+ debug: colors.green,
795
+ info: colors.bold,
796
+ warn: colors.yellow,
797
+ error: colors.red
798
+ };
799
+ var ConsoleProvider = class extends LoggerProvider {
800
+ /**
801
+ * Initializes the appender with the provided options.
802
+ * This method should be called before using the appender to process messages.
803
+ */
804
+ initialize() {}
805
+ /**
806
+ * Prints a log message according to the specified format and level.
807
+ * @param message - The log message object containing level, tag, and arguments
808
+ * @protected
809
+ */
810
+ processMessage(message) {
811
+ const date = message.timestamp ? new Date(message.timestamp) : new Date();
812
+ console[message.level](`%s%s${message?.tag ? "%s" : ""} %s`, LOG_LEVEL_COLORS[message.level](`[${date.toISOString().split("T")[1]?.replace("Z", "")}]`), LOG_LEVEL_COLORS[message.level](`[${message.level.toUpperCase().padEnd(5, " ")}]`), message?.tag ? LOG_LEVEL_COLORS[message.level](`[${message.tag}]`) : "", ...message.args);
813
+ }
814
+ };
815
+
816
+ //#endregion
817
+ //#region packages/core/src/Services/Validation/ValidationProvider.ts
818
+ var ValidationProvider = class {};
819
+
820
+ //#endregion
821
+ //#region packages/core/src/Services/Validation/StandardSchemaValidationProvider.ts
822
+ var StandardSchemaValidationProvider = class {
823
+ /**
824
+ * Validates data against a schema
825
+ * @param {ValidationTypes.Schema} schema - The schema to validate against
826
+ * @param {ValidationTypes.Input} data - The data to validate
827
+ * @return {ValidationTypes.Result | Promise<ValidationTypes.Result>} The validation result
828
+ */
829
+ validate(schema, data) {
830
+ return schema["~standard"].validate(data);
831
+ }
832
+ };
833
+
834
+ //#endregion
835
+ //#region packages/core/src/Services/Config/RuntimeConfig.ts
836
+ var RuntimeConfig = class {
837
+ /**
838
+ * Private field to store the runtime configuration object.
839
+ * @private
840
+ */
841
+ fRuntimeConfig;
842
+ /**
843
+ * Gets the current runtime configuration.
844
+ * @returns {ConfigTypes.RuntimeConfig} The current runtime configuration object.
845
+ */
846
+ get runtimeConfig() {
847
+ return this.fRuntimeConfig;
848
+ }
849
+ /**
850
+ * Sets the runtime configuration.
851
+ * @param {ConfigTypes.RuntimeConfig} value - The new runtime configuration object to set.
852
+ */
853
+ set runtimeConfig(value) {
854
+ this.fRuntimeConfig = value;
855
+ }
856
+ };
857
+
858
+ //#endregion
859
+ //#region packages/core/src/Errors/Http/InternalServerError.ts
860
+ var InternalServerError = class InternalServerError extends HttpError {
861
+ /**
862
+ * The name of the error.
863
+ * @type {string}
864
+ */
865
+ name = "InternalServerError";
866
+ /**
867
+ * Creates an instance of InternalServerError.
868
+ * @param {string} [message] - The error message.
869
+ */
870
+ constructor(message) {
871
+ super(500);
872
+ Object.setPrototypeOf(this, InternalServerError.prototype);
873
+ if (message) this.message = message;
874
+ }
875
+ };
876
+
877
+ //#endregion
878
+ //#region packages/core/src/Services/ErrorHandler/DefaultErrorHandlerProvider.ts
879
+ var DefaultErrorHandlerProvider = class extends ErrorHandlerProvider {
880
+ gLogger;
881
+ /**
882
+ * Handles an error that occurred during request processing
883
+ *
884
+ * @param error - The Error object containing error details
885
+ * @returns Promise<Response> | Response - The response to be sent to the client
886
+ */
887
+ handleError(error) {
888
+ const _internalError = new InternalServerError();
889
+ const status = error?.status ?? 500;
890
+ if (error instanceof HttpError) return new Response(JSON.stringify({ ...error }, void 0, 2), { status });
891
+ this.gLogger.error(error);
892
+ return new Response(JSON.stringify({ ...error?.cause ?? _internalError.cause }, void 0, 2), { status });
893
+ }
894
+ };
895
+ __decorate([Inject(Logger)], DefaultErrorHandlerProvider.prototype, "gLogger", void 0);
896
+
897
+ //#endregion
898
+ //#region packages/core/src/Common/Container.ts
899
+ function createContainer(config) {
900
+ const container = new Container();
901
+ container.bindInstance(Container, container);
902
+ container.bind(Logger, BaseLogger);
903
+ container.get(Logger).configure({
904
+ logLevel: config.logLevel ?? "debug",
905
+ providers: [{
906
+ name: "console",
907
+ provider: ConsoleProvider
908
+ }]
909
+ });
910
+ container.bind(ErrorHandlerProvider, DefaultErrorHandlerProvider);
911
+ container.bind(HttpServer);
912
+ container.bind(StaticRequestHandler);
913
+ container.bind(Router);
914
+ container.bind(HooksService);
915
+ container.bind(MetadataResolver);
916
+ container.bind(PluginsRegistry);
917
+ container.bind(RequestHandler);
918
+ container.bind(RuntimeConfig);
919
+ container.bind(GlobalMiddlewareRegistry);
920
+ container.bind(ValidationProvider, StandardSchemaValidationProvider);
921
+ return container;
922
+ }
923
+
924
+ //#endregion
925
+ //#region packages/core/src/Utils/InternalUtils.ts
926
+ function generateRandomHash() {
927
+ const hashByPerformance = Math.floor(Date.now() * 1e3).toString(16);
928
+ const hashByMath = () => (Math.floor(Math.random() * 16777215) | 1048576).toString(16);
929
+ return `${hashByPerformance}-${hashByMath()}-${hashByMath()}-${hashByMath()}`;
930
+ }
931
+
932
+ //#endregion
933
+ //#region packages/core/src/Config/DefaultConfig.ts
934
+ const defaultConfig = {
935
+ logLevel: "debug",
936
+ production: false,
937
+ dev: false,
938
+ build: {
939
+ root: process.cwd(),
940
+ entry: "src/index.ts",
941
+ output: {
942
+ dir: "dist",
943
+ publicDir: "public"
944
+ },
945
+ bundler: "rolldown"
946
+ },
947
+ server: {
948
+ runtime: "node",
949
+ host: "localhost",
950
+ port: 3e3,
951
+ https: false,
952
+ static: { dirs: ["public"] }
953
+ },
954
+ experimental: {},
955
+ runtime: { session: {
956
+ secret: process.env?.SECRET ?? generateRandomHash(),
957
+ name: "vercube_session",
958
+ duration: 60 * 60 * 24 * 7
959
+ } }
960
+ };
961
+
962
+ //#endregion
963
+ //#region packages/core/src/Config/Loader.ts
964
+ async function loadVercubeConfig(overrides) {
965
+ const config = await loadConfig({
966
+ name: "vercube",
967
+ dotenv: true,
968
+ rcFile: false,
969
+ globalRc: false,
970
+ defaults: defaultConfig
971
+ });
972
+ return defu(overrides ?? {}, config?.config ?? {});
973
+ }
974
+
975
+ //#endregion
976
+ //#region packages/core/src/Common/CreateApp.ts
977
+ async function createApp(cfg) {
978
+ const config = await loadVercubeConfig(cfg);
979
+ const container = createContainer(config);
980
+ const app = container.resolve(App);
981
+ container.get(RuntimeConfig).runtimeConfig = config?.runtime ?? {};
982
+ app.container = container;
983
+ await app.init(config);
984
+ initializeContainer(container);
985
+ return app;
986
+ }
987
+
988
+ //#endregion
989
+ //#region packages/core/src/Config/Config.ts
990
+ function defineConfig(config) {
991
+ return config;
992
+ }
993
+
994
+ //#endregion
995
+ //#region packages/core/src/Middleware/ValidationMiddleware.ts
996
+ var ValidationMiddleware = class {
997
+ gValidationProvider;
998
+ /**
999
+ * Middleware function that processes the HTTP event
1000
+ * @param {Request} request - The HTTP request object
1001
+ * @param {Response} response - The HTTP response object
1002
+ * @param {MiddlewareOptions} args - Additional arguments for the middleware
1003
+ * @returns {Promise<void>} - A promise that resolves when the processing is complete
1004
+ * @throws {BadRequestError} - If validation fails
1005
+ */
1006
+ async onRequest(request, response, args) {
1007
+ if (!this.gValidationProvider) {
1008
+ console.warn("ValidationMiddleware::ValidationProvider is not registered");
1009
+ return;
1010
+ }
1011
+ const validators = args.methodArgs?.filter((arg) => arg.validate && arg.validationSchema) ?? [];
1012
+ for (const validator of validators) {
1013
+ const result = await this.gValidationProvider.validate(validator.validationSchema, validator.resolved);
1014
+ if (result.issues?.length) throw new BadRequestError(`Validation error - ${validator.type}`, result.issues);
1015
+ }
1016
+ }
1017
+ };
1018
+ __decorate([InjectOptional(ValidationProvider)], ValidationMiddleware.prototype, "gValidationProvider", void 0);
1019
+
1020
+ //#endregion
1021
+ //#region packages/core/src/Utils/Utils.ts
1022
+ function createMetadataCtx() {
1023
+ return {
1024
+ __controller: { path: "" },
1025
+ __middlewares: [],
1026
+ __methods: {}
1027
+ };
1028
+ }
1029
+ function createMetadataMethod() {
1030
+ return {
1031
+ req: null,
1032
+ res: null,
1033
+ url: null,
1034
+ args: [],
1035
+ actions: []
1036
+ };
1037
+ }
1038
+ function initializeMetadataMethod(target, propertyName) {
1039
+ if (!target.__metadata.__methods[propertyName]) target.__metadata.__methods[propertyName] = createMetadataMethod();
1040
+ return target.__metadata.__methods[propertyName];
1041
+ }
1042
+ function initializeMetadata(target) {
1043
+ if (!target.__metadata) target.__metadata = createMetadataCtx();
1044
+ if (!target.__metadata.__methods) target.__metadata.__methods = {};
1045
+ if (!target.__metadata.__middlewares) target.__metadata.__middlewares = [];
1046
+ return target.__metadata;
1047
+ }
1048
+
1049
+ //#endregion
1050
+ //#region packages/core/src/Decorators/Http/Body.ts
1051
+ var BodyDecorator = class extends BaseDecorator {
1052
+ /**
1053
+ * @method created
1054
+ * This method is called when the decorator is created. It ensures that the metadata
1055
+ * for the property exists and adds the body argument to the metadata.
1056
+ */
1057
+ created() {
1058
+ const meta = initializeMetadata(this.prototype);
1059
+ const method = initializeMetadataMethod(this.prototype, this.propertyName);
1060
+ method.args.push({
1061
+ idx: this.propertyIndex,
1062
+ type: "body",
1063
+ validate: this.options?.validationSchema ? true : false,
1064
+ validationSchema: this.options?.validationSchema
1065
+ });
1066
+ meta.__middlewares.unshift({
1067
+ target: this.propertyName,
1068
+ priority: -1,
1069
+ args: {},
1070
+ middleware: ValidationMiddleware
1071
+ });
1072
+ }
1073
+ };
1074
+ function Body(options) {
1075
+ return createDecorator(BodyDecorator, options);
1076
+ }
1077
+
1078
+ //#endregion
1079
+ //#region packages/core/src/Decorators/Http/Connect.ts
1080
+ var ConnectDecorator = class extends BaseDecorator {
1081
+ gRouter;
1082
+ gRequestHandler;
1083
+ gMetadataResolver;
1084
+ /**
1085
+ * Called when the decorator is created.
1086
+ *
1087
+ * This method constructs the full path for the route, registers the route
1088
+ * with the Router, and sets up the event handler for the CONNECT request.
1089
+ */
1090
+ created() {
1091
+ this.options.path = this.gMetadataResolver.resolveUrl({
1092
+ instance: this.instance,
1093
+ path: this.options.path,
1094
+ propertyName: this.propertyName
1095
+ });
1096
+ this.gRouter.addRoute({
1097
+ path: this.options.path,
1098
+ method: "CONNECT",
1099
+ handler: this.gRequestHandler.prepareHandler({
1100
+ instance: this.instance,
1101
+ propertyName: this.propertyName
1102
+ })
1103
+ });
1104
+ }
1105
+ };
1106
+ __decorate([Inject(Router)], ConnectDecorator.prototype, "gRouter", void 0);
1107
+ __decorate([Inject(RequestHandler)], ConnectDecorator.prototype, "gRequestHandler", void 0);
1108
+ __decorate([Inject(MetadataResolver)], ConnectDecorator.prototype, "gMetadataResolver", void 0);
1109
+ function Connect(path) {
1110
+ return createDecorator(ConnectDecorator, { path });
1111
+ }
1112
+
1113
+ //#endregion
1114
+ //#region packages/core/src/Decorators/Http/Controller.ts
1115
+ function Controller(path) {
1116
+ return function internalDecorator(target) {
1117
+ const meta = initializeMetadata(target.prototype);
1118
+ meta.__controller = {
1119
+ ...meta?.__controller,
1120
+ path
1121
+ };
1122
+ };
1123
+ }
1124
+
1125
+ //#endregion
1126
+ //#region packages/core/src/Decorators/Http/Delete.ts
1127
+ var DeleteDecorator = class extends BaseDecorator {
1128
+ gRouter;
1129
+ gRequestHandler;
1130
+ gMetadataResolver;
1131
+ /**
1132
+ * Called when the decorator is created.
1133
+ *
1134
+ * This method constructs the full path for the route, registers the route
1135
+ * with the Router, and sets up the event handler for the DELETE request.
1136
+ */
1137
+ created() {
1138
+ initializeMetadata(this.prototype);
1139
+ initializeMetadataMethod(this.prototype, this.propertyName);
1140
+ this.options.path = this.gMetadataResolver.resolveUrl({
1141
+ instance: this.instance,
1142
+ path: this.options.path,
1143
+ propertyName: this.propertyName
1144
+ });
1145
+ this.gRouter.addRoute({
1146
+ path: this.options.path,
1147
+ method: "DELETE",
1148
+ handler: this.gRequestHandler.prepareHandler({
1149
+ instance: this.instance,
1150
+ propertyName: this.propertyName
1151
+ })
1152
+ });
1153
+ }
1154
+ };
1155
+ __decorate([Inject(Router)], DeleteDecorator.prototype, "gRouter", void 0);
1156
+ __decorate([Inject(RequestHandler)], DeleteDecorator.prototype, "gRequestHandler", void 0);
1157
+ __decorate([Inject(MetadataResolver)], DeleteDecorator.prototype, "gMetadataResolver", void 0);
1158
+ function Delete(path) {
1159
+ return createDecorator(DeleteDecorator, { path });
1160
+ }
1161
+
1162
+ //#endregion
1163
+ //#region packages/core/src/Decorators/Http/Get.ts
1164
+ var GetDecorator = class extends BaseDecorator {
1165
+ gRouter;
1166
+ gRequestHandler;
1167
+ gMetadataResolver;
1168
+ /**
1169
+ * Called when the decorator is created.
1170
+ *
1171
+ * This method constructs the full path for the route, registers the route
1172
+ * with the Router, and sets up the event handler for the GET request.
1173
+ */
1174
+ created() {
1175
+ initializeMetadata(this.prototype);
1176
+ initializeMetadataMethod(this.prototype, this.propertyName);
1177
+ this.options.path = this.gMetadataResolver.resolveUrl({
1178
+ instance: this.instance,
1179
+ path: this.options.path,
1180
+ propertyName: this.propertyName
1181
+ });
1182
+ this.gRouter.addRoute({
1183
+ path: this.options.path,
1184
+ method: "GET",
1185
+ handler: this.gRequestHandler.prepareHandler({
1186
+ instance: this.instance,
1187
+ propertyName: this.propertyName
1188
+ })
1189
+ });
1190
+ }
1191
+ };
1192
+ __decorate([Inject(Router)], GetDecorator.prototype, "gRouter", void 0);
1193
+ __decorate([Inject(RequestHandler)], GetDecorator.prototype, "gRequestHandler", void 0);
1194
+ __decorate([Inject(MetadataResolver)], GetDecorator.prototype, "gMetadataResolver", void 0);
1195
+ function Get(path) {
1196
+ return createDecorator(GetDecorator, { path });
1197
+ }
1198
+
1199
+ //#endregion
1200
+ //#region packages/core/src/Decorators/Http/Head.ts
1201
+ var HeadDecorator = class extends BaseDecorator {
1202
+ gRouter;
1203
+ gRequestHandler;
1204
+ gMetadataResolver;
1205
+ /**
1206
+ * Called when the decorator is created.
1207
+ *
1208
+ * This method constructs the full path for the route, registers the route
1209
+ * with the Router, and sets up the event handler for the HEAD request.
1210
+ */
1211
+ created() {
1212
+ initializeMetadata(this.prototype);
1213
+ initializeMetadataMethod(this.prototype, this.propertyName);
1214
+ this.options.path = this.gMetadataResolver.resolveUrl({
1215
+ instance: this.instance,
1216
+ path: this.options.path,
1217
+ propertyName: this.propertyName
1218
+ });
1219
+ this.gRouter.addRoute({
1220
+ path: this.options.path,
1221
+ method: "HEAD",
1222
+ handler: this.gRequestHandler.prepareHandler({
1223
+ instance: this.instance,
1224
+ propertyName: this.propertyName
1225
+ })
1226
+ });
1227
+ }
1228
+ };
1229
+ __decorate([Inject(Router)], HeadDecorator.prototype, "gRouter", void 0);
1230
+ __decorate([Inject(RequestHandler)], HeadDecorator.prototype, "gRequestHandler", void 0);
1231
+ __decorate([Inject(MetadataResolver)], HeadDecorator.prototype, "gMetadataResolver", void 0);
1232
+ function Head(path) {
1233
+ return createDecorator(HeadDecorator, { path });
1234
+ }
1235
+
1236
+ //#endregion
1237
+ //#region packages/core/src/Decorators/Http/Header.ts
1238
+ var HeaderDecorator = class extends BaseDecorator {
1239
+ /**
1240
+ * Called when the decorator is created.
1241
+ *
1242
+ * This method checks if metadata for the property exists, creates it if it doesn't,
1243
+ * and then adds the header information to the metadata.
1244
+ */
1245
+ created() {
1246
+ initializeMetadata(this.prototype);
1247
+ const method = initializeMetadataMethod(this.prototype, this.propertyName);
1248
+ method.args.push({
1249
+ idx: this.propertyIndex,
1250
+ type: "header",
1251
+ data: { name: this.options.name }
1252
+ });
1253
+ }
1254
+ };
1255
+ function Header(name) {
1256
+ return createDecorator(HeaderDecorator, { name });
1257
+ }
1258
+
1259
+ //#endregion
1260
+ //#region packages/core/src/Decorators/Http/Headers.ts
1261
+ var HeadersDecorator = class extends BaseDecorator {
1262
+ /**
1263
+ * Called when the decorator is created.
1264
+ *
1265
+ * This method checks if metadata for the property exists, creates it if it doesn't,
1266
+ * and then adds the headers information to the metadata.
1267
+ */
1268
+ created() {
1269
+ initializeMetadata(this.prototype);
1270
+ const method = initializeMetadataMethod(this.prototype, this.propertyName);
1271
+ method.args.push({
1272
+ idx: this.propertyIndex,
1273
+ type: "headers"
1274
+ });
1275
+ }
1276
+ };
1277
+ function Headers$1() {
1278
+ return createDecorator(HeadersDecorator, {});
1279
+ }
1280
+
1281
+ //#endregion
1282
+ //#region packages/core/src/Decorators/Http/Options.ts
1283
+ var OptionsDecorator = class extends BaseDecorator {
1284
+ gRouter;
1285
+ gRequestHandler;
1286
+ gMetadataResolver;
1287
+ /**
1288
+ * Called when the decorator is created.
1289
+ *
1290
+ * This method constructs the full path for the route, registers the route
1291
+ * with the Router, and sets up the event handler for the OPTIONS request.
1292
+ */
1293
+ created() {
1294
+ initializeMetadata(this.prototype);
1295
+ initializeMetadataMethod(this.prototype, this.propertyName);
1296
+ this.options.path = this.gMetadataResolver.resolveUrl({
1297
+ instance: this.instance,
1298
+ path: this.options.path,
1299
+ propertyName: this.propertyName
1300
+ });
1301
+ this.gRouter.addRoute({
1302
+ path: this.options.path,
1303
+ method: "OPTIONS",
1304
+ handler: this.gRequestHandler.prepareHandler({
1305
+ instance: this.instance,
1306
+ propertyName: this.propertyName
1307
+ })
1308
+ });
1309
+ }
1310
+ };
1311
+ __decorate([Inject(Router)], OptionsDecorator.prototype, "gRouter", void 0);
1312
+ __decorate([Inject(RequestHandler)], OptionsDecorator.prototype, "gRequestHandler", void 0);
1313
+ __decorate([Inject(MetadataResolver)], OptionsDecorator.prototype, "gMetadataResolver", void 0);
1314
+ function Options(path) {
1315
+ return createDecorator(OptionsDecorator, { path });
1316
+ }
1317
+
1318
+ //#endregion
1319
+ //#region packages/core/src/Decorators/Http/Param.ts
1320
+ var ParamDecorator = class extends BaseDecorator {
1321
+ gMetadataResolver;
1322
+ /**
1323
+ * Called when the decorator is created.
1324
+ *
1325
+ * This method checks if metadata for the property exists, creates it if it doesn't,
1326
+ * and then adds the parameter information to the metadata.
1327
+ */
1328
+ created() {
1329
+ initializeMetadata(this.prototype);
1330
+ const method = initializeMetadataMethod(this.prototype, this.propertyName);
1331
+ method.args.push({
1332
+ idx: this.propertyIndex,
1333
+ type: "param",
1334
+ data: { name: this.options.name }
1335
+ });
1336
+ }
1337
+ };
1338
+ __decorate([Inject(MetadataResolver)], ParamDecorator.prototype, "gMetadataResolver", void 0);
1339
+ function Param(name) {
1340
+ return createDecorator(ParamDecorator, { name });
1341
+ }
1342
+
1343
+ //#endregion
1344
+ //#region packages/core/src/Decorators/Http/Patch.ts
1345
+ var PatchDecorator = class extends BaseDecorator {
1346
+ gRouter;
1347
+ gRequestHandler;
1348
+ gMetadataResolver;
1349
+ /**
1350
+ * Called when the decorator is created.
1351
+ *
1352
+ * This method constructs the full path for the route, registers the route
1353
+ * with the Router, and sets up the event handler for the PATCH request.
1354
+ */
1355
+ created() {
1356
+ this.options.path = this.gMetadataResolver.resolveUrl({
1357
+ instance: this.instance,
1358
+ path: this.options.path,
1359
+ propertyName: this.propertyName
1360
+ });
1361
+ this.gRouter.addRoute({
1362
+ path: this.options.path,
1363
+ method: "PATCH",
1364
+ handler: this.gRequestHandler.prepareHandler({
1365
+ instance: this.instance,
1366
+ propertyName: this.propertyName
1367
+ })
1368
+ });
1369
+ }
1370
+ };
1371
+ __decorate([Inject(Router)], PatchDecorator.prototype, "gRouter", void 0);
1372
+ __decorate([Inject(RequestHandler)], PatchDecorator.prototype, "gRequestHandler", void 0);
1373
+ __decorate([Inject(MetadataResolver)], PatchDecorator.prototype, "gMetadataResolver", void 0);
1374
+ function Patch(path) {
1375
+ return createDecorator(PatchDecorator, { path });
1376
+ }
1377
+
1378
+ //#endregion
1379
+ //#region packages/core/src/Decorators/Http/Post.ts
1380
+ var PostDecorator = class extends BaseDecorator {
1381
+ gRouter;
1382
+ gMetadataResolver;
1383
+ gRequestHandler;
1384
+ /**
1385
+ * Called when the decorator is created.
1386
+ *
1387
+ * This method constructs the full path for the route, registers the route
1388
+ * with the Router, and sets up the event handler for the POST request.
1389
+ */
1390
+ created() {
1391
+ initializeMetadata(this.prototype);
1392
+ initializeMetadataMethod(this.prototype, this.propertyName);
1393
+ this.options.path = this.gMetadataResolver.resolveUrl({
1394
+ instance: this.instance,
1395
+ path: this.options.path,
1396
+ propertyName: this.propertyName
1397
+ });
1398
+ this.gRouter.addRoute({
1399
+ path: this.options.path,
1400
+ method: "POST",
1401
+ handler: this.gRequestHandler.prepareHandler({
1402
+ instance: this.instance,
1403
+ propertyName: this.propertyName
1404
+ })
1405
+ });
1406
+ }
1407
+ };
1408
+ __decorate([Inject(Router)], PostDecorator.prototype, "gRouter", void 0);
1409
+ __decorate([Inject(MetadataResolver)], PostDecorator.prototype, "gMetadataResolver", void 0);
1410
+ __decorate([Inject(RequestHandler)], PostDecorator.prototype, "gRequestHandler", void 0);
1411
+ function Post(path) {
1412
+ return createDecorator(PostDecorator, { path });
1413
+ }
1414
+
1415
+ //#endregion
1416
+ //#region packages/core/src/Decorators/Http/Put.ts
1417
+ var PutDecorator = class extends BaseDecorator {
1418
+ gRouter;
1419
+ gRequestHandler;
1420
+ gMetadataResolver;
1421
+ /**
1422
+ * Called when the decorator is created.
1423
+ *
1424
+ * This method constructs the full path for the route, registers the route
1425
+ * with the Router, and sets up the event handler for the PUT request.
1426
+ */
1427
+ created() {
1428
+ initializeMetadata(this.prototype);
1429
+ initializeMetadataMethod(this.prototype, this.propertyName);
1430
+ this.options.path = this.gMetadataResolver.resolveUrl({
1431
+ instance: this.instance,
1432
+ path: this.options.path,
1433
+ propertyName: this.propertyName
1434
+ });
1435
+ this.gRouter.addRoute({
1436
+ path: this.options.path,
1437
+ method: "PUT",
1438
+ handler: this.gRequestHandler.prepareHandler({
1439
+ instance: this.instance,
1440
+ propertyName: this.propertyName
1441
+ })
1442
+ });
1443
+ }
1444
+ };
1445
+ __decorate([Inject(Router)], PutDecorator.prototype, "gRouter", void 0);
1446
+ __decorate([Inject(RequestHandler)], PutDecorator.prototype, "gRequestHandler", void 0);
1447
+ __decorate([Inject(MetadataResolver)], PutDecorator.prototype, "gMetadataResolver", void 0);
1448
+ function Put(path) {
1449
+ return createDecorator(PutDecorator, { path });
1450
+ }
1451
+
1452
+ //#endregion
1453
+ //#region packages/core/src/Decorators/Http/QueryParam.ts
1454
+ var QueryParamDecorator = class extends BaseDecorator {
1455
+ /**
1456
+ * Called when the decorator is created.
1457
+ *
1458
+ * This method checks if metadata for the property exists, creates it if it doesn't,
1459
+ * and then adds the query parameter information to the metadata.
1460
+ */
1461
+ created() {
1462
+ const meta = initializeMetadata(this.prototype);
1463
+ const method = initializeMetadataMethod(this.prototype, this.propertyName);
1464
+ method.args.push({
1465
+ idx: this.propertyIndex,
1466
+ type: "query-param",
1467
+ data: { name: this.options.name },
1468
+ validate: this.options?.validationSchema ? true : false,
1469
+ validationSchema: this.options?.validationSchema
1470
+ });
1471
+ meta.__middlewares.unshift({
1472
+ target: this.propertyName,
1473
+ priority: -1,
1474
+ args: {},
1475
+ middleware: ValidationMiddleware
1476
+ });
1477
+ }
1478
+ };
1479
+ function QueryParam(options) {
1480
+ return createDecorator(QueryParamDecorator, options);
1481
+ }
1482
+
1483
+ //#endregion
1484
+ //#region packages/core/src/Decorators/Http/QueryParams.ts
1485
+ var QueryParamsDecorator = class extends BaseDecorator {
1486
+ /**
1487
+ * Called when the decorator is created.
1488
+ *
1489
+ * This method checks if metadata for the property exists, creates it if it doesn't,
1490
+ * and then adds the query parameters information to the metadata.
1491
+ */
1492
+ created() {
1493
+ const meta = initializeMetadata(this.prototype);
1494
+ const method = initializeMetadataMethod(this.prototype, this.propertyName);
1495
+ method.args.push({
1496
+ idx: this.propertyIndex,
1497
+ type: "query-params",
1498
+ data: {},
1499
+ validate: this.options?.validationSchema ? true : false,
1500
+ validationSchema: this.options?.validationSchema
1501
+ });
1502
+ meta.__middlewares.unshift({
1503
+ target: this.propertyName,
1504
+ priority: -1,
1505
+ args: {},
1506
+ middleware: ValidationMiddleware
1507
+ });
1508
+ }
1509
+ };
1510
+ function QueryParams(options) {
1511
+ return createDecorator(QueryParamsDecorator, options);
1512
+ }
1513
+
1514
+ //#endregion
1515
+ //#region packages/core/src/Decorators/Http/Request.ts
1516
+ var RequestDecorator = class extends BaseDecorator {
1517
+ /**
1518
+ * Called when the decorator is created.
1519
+ *
1520
+ * This method checks if metadata for the property exists, creates it if it doesn't,
1521
+ * and then adds the request information to the metadata.
1522
+ */
1523
+ created() {
1524
+ initializeMetadata(this.prototype);
1525
+ const method = initializeMetadataMethod(this.prototype, this.propertyName);
1526
+ method.args.push({
1527
+ idx: this.propertyIndex,
1528
+ type: "request"
1529
+ });
1530
+ }
1531
+ };
1532
+ function Request() {
1533
+ return createDecorator(RequestDecorator, {});
1534
+ }
1535
+
1536
+ //#endregion
1537
+ //#region packages/core/src/Decorators/Http/Response.ts
1538
+ var ResponseDecorator = class extends BaseDecorator {
1539
+ /**
1540
+ * Called when the decorator is created.
1541
+ *
1542
+ * This method checks if metadata for the property exists, creates it if it doesn't,
1543
+ * and then adds the response information to the metadata.
1544
+ */
1545
+ created() {
1546
+ initializeMetadata(this.prototype);
1547
+ const method = initializeMetadataMethod(this.prototype, this.propertyName);
1548
+ method.args.push({
1549
+ idx: this.propertyIndex,
1550
+ type: "response"
1551
+ });
1552
+ }
1553
+ };
1554
+ function Response$1() {
1555
+ return createDecorator(ResponseDecorator, {});
1556
+ }
1557
+
1558
+ //#endregion
1559
+ //#region packages/core/src/Decorators/Http/Trace.ts
1560
+ var TraceDecorator = class extends BaseDecorator {
1561
+ gRouter;
1562
+ gRequestHandler;
1563
+ gMetadataResolver;
1564
+ /**
1565
+ * Called when the decorator is created.
1566
+ *
1567
+ * This method constructs the full path for the route, registers the route
1568
+ * with the Router, and sets up the event handler for the TRACE request.
1569
+ */
1570
+ created() {
1571
+ initializeMetadata(this.prototype);
1572
+ initializeMetadataMethod(this.prototype, this.propertyName);
1573
+ this.options.path = this.gMetadataResolver.resolveUrl({
1574
+ instance: this.instance,
1575
+ path: this.options.path,
1576
+ propertyName: this.propertyName
1577
+ });
1578
+ this.gRouter.addRoute({
1579
+ path: this.options.path,
1580
+ method: "TRACE",
1581
+ handler: this.gRequestHandler.prepareHandler({
1582
+ instance: this.instance,
1583
+ propertyName: this.propertyName
1584
+ })
1585
+ });
1586
+ }
1587
+ };
1588
+ __decorate([Inject(Router)], TraceDecorator.prototype, "gRouter", void 0);
1589
+ __decorate([Inject(RequestHandler)], TraceDecorator.prototype, "gRequestHandler", void 0);
1590
+ __decorate([Inject(MetadataResolver)], TraceDecorator.prototype, "gMetadataResolver", void 0);
1591
+ function Trace(path) {
1592
+ return createDecorator(TraceDecorator, { path });
1593
+ }
1594
+
1595
+ //#endregion
1596
+ //#region packages/core/src/Decorators/Http/SetHeader.ts
1597
+ var SetHeaderDecorator = class extends BaseDecorator {
1598
+ /**
1599
+ * Called when the decorator is created.
1600
+ * Adds a query parameter to the metadata.
1601
+ * @override
1602
+ */
1603
+ created() {
1604
+ initializeMetadata(this.prototype);
1605
+ const method = initializeMetadataMethod(this.prototype, this.propertyName);
1606
+ method.actions.push({ handler: (req, res) => {
1607
+ res.headers.delete(this.options.key);
1608
+ res.headers.append(this.options.key, this.options.value);
1609
+ return res;
1610
+ } });
1611
+ }
1612
+ };
1613
+ function SetHeader(key, value) {
1614
+ return createDecorator(SetHeaderDecorator, {
1615
+ key,
1616
+ value
1617
+ });
1618
+ }
1619
+
1620
+ //#endregion
1621
+ //#region packages/core/src/Decorators/Http/Status.ts
1622
+ var StatusDecorator = class extends BaseDecorator {
1623
+ /**
1624
+
1625
+ * Called when the decorator is created.
1626
+
1627
+ * Sets a status on the response
1628
+
1629
+ * @override
1630
+
1631
+ */
1632
+ created() {
1633
+ initializeMetadata(this.prototype);
1634
+ const method = initializeMetadataMethod(this.prototype, this.propertyName);
1635
+ method.actions.push({ handler: () => ({ status: this.options.code }) });
1636
+ }
1637
+ };
1638
+ function Status(code) {
1639
+ return createDecorator(StatusDecorator, { code });
1640
+ }
1641
+
1642
+ //#endregion
1643
+ //#region packages/core/src/Decorators/Http/Redirect.ts
1644
+ var RedirectDecorator = class extends BaseDecorator {
1645
+ /**
1646
+
1647
+ * Decorator responsible for redirecting to a specified URL.
1648
+
1649
+ * Called when the decorator is created.
1650
+
1651
+ * Sets the location header value and status code.
1652
+
1653
+ * @override
1654
+
1655
+ */
1656
+ created() {
1657
+ initializeMetadata(this.prototype);
1658
+ const method = initializeMetadataMethod(this.prototype, this.propertyName);
1659
+ method.actions.push({ handler: () => {
1660
+ return new Response(void 0, {
1661
+ status: this.options.code,
1662
+ headers: { "Location": this.options.location }
1663
+ });
1664
+ } });
1665
+ }
1666
+ };
1667
+ function Redirect(location, code = 301) {
1668
+ return createDecorator(RedirectDecorator, {
1669
+ location,
1670
+ code
1671
+ });
1672
+ }
1673
+
1674
+ //#endregion
1675
+ //#region packages/core/src/Decorators/Http/Middleware.ts
1676
+ function Middleware(middleware, opts) {
1677
+ return function internalDecorator(target, propertyName) {
1678
+ const ctx = propertyName ? target : target.prototype;
1679
+ const meta = initializeMetadata(ctx);
1680
+ meta.__middlewares.push({
1681
+ target: propertyName ?? "__global__",
1682
+ priority: opts?.priority ?? 999,
1683
+ middleware
1684
+ });
1685
+ };
1686
+ }
1687
+
1688
+ //#endregion
1689
+ //#region packages/core/src/Decorators/Http/MultipartFormData.ts
1690
+ var MultipartFormDataDecorator = class extends BaseDecorator {
1691
+ /**
1692
+ * @method created
1693
+ * This method is called when the decorator is created. It ensures that the metadata
1694
+ * for the property exists and adds the body argument to the metadata.
1695
+ */
1696
+ created() {
1697
+ initializeMetadata(this.prototype);
1698
+ const method = initializeMetadataMethod(this.prototype, this.propertyName);
1699
+ method.args.push({
1700
+ idx: this.propertyIndex,
1701
+ type: "multipart-form-data"
1702
+ });
1703
+ }
1704
+ };
1705
+ function MultipartFormData() {
1706
+ return createDecorator(MultipartFormDataDecorator, {});
1707
+ }
1708
+
1709
+ //#endregion
1710
+ //#region packages/core/src/Decorators/Http/Session.ts
1711
+ var SessionDecorator = class extends BaseDecorator {
1712
+ gRuntimeConfig;
1713
+ /**
1714
+ * Called when the decorator is created.
1715
+ *
1716
+ * This method checks if metadata for the property exists, creates it if it doesn't,
1717
+ * and then adds the session information to the metadata.
1718
+ */
1719
+ created() {
1720
+ initializeMetadata(this.prototype);
1721
+ const method = initializeMetadataMethod(this.prototype, this.propertyName);
1722
+ method.args.push({
1723
+ idx: this.propertyIndex,
1724
+ type: "session",
1725
+ data: {
1726
+ name: this.gRuntimeConfig.runtimeConfig.session?.name ?? "vercube_session",
1727
+ secret: this.gRuntimeConfig.runtimeConfig.session?.secret ?? generateRandomHash(),
1728
+ duration: this.gRuntimeConfig.runtimeConfig.session?.duration ?? 60 * 60 * 24 * 7
1729
+ }
1730
+ });
1731
+ }
1732
+ };
1733
+ __decorate([Inject(RuntimeConfig)], SessionDecorator.prototype, "gRuntimeConfig", void 0);
1734
+ function Session() {
1735
+ return createDecorator(SessionDecorator, {});
1736
+ }
1737
+
1738
+ //#endregion
1739
+ //#region packages/core/src/Decorators/Hooks/Listen.ts
1740
+ var ListenDecorator = class extends BaseDecorator {
1741
+ gHooksService;
1742
+ fHook;
1743
+ /**
1744
+ * Called when decorator is initialized. It will register event listener that will call this function
1745
+ * once executed.
1746
+ */
1747
+ created() {
1748
+ this.fHook = this.gHooksService.on(this.options.hookType, (data) => this.instance[this.propertyName](data));
1749
+ }
1750
+ /**
1751
+ * Called when decorator is destroyed. It will unregister event listener.
1752
+ */
1753
+ destroyed() {
1754
+ this.gHooksService.off(this.fHook);
1755
+ }
1756
+ };
1757
+ __decorate([Inject(HooksService)], ListenDecorator.prototype, "gHooksService", void 0);
1758
+ function Listen(hookType) {
1759
+ return createDecorator(ListenDecorator, { hookType });
1760
+ }
1761
+
1762
+ //#endregion
1763
+ //#region packages/core/src/Services/Plugins/BasePlugin.ts
1764
+ var BasePlugin = class {
1765
+ /**
1766
+ * The name of the plugin.
1767
+ */
1768
+ name;
1769
+ /**
1770
+ * Uses the plugin with the given app.
1771
+ * @param {App} app - The application instance.
1772
+ * @returns {void | Promise<void>} - A void or a promise that resolves to void.
1773
+ */
1774
+ use(app, options) {}
1775
+ };
1776
+
1777
+ //#endregion
1778
+ //#region packages/core/src/Services/Middleware/BaseMiddleware.ts
1779
+ var BaseMiddleware = class {};
1780
+
1781
+ //#endregion
1782
+ //#region packages/core/src/Errors/Http/ForbiddenError.ts
1783
+ var ForbiddenError = class ForbiddenError extends HttpError {
1784
+ /**
1785
+ * The name of the error.
1786
+ * @type {string}
1787
+ */
1788
+ name = "ForbiddenError";
1789
+ /**
1790
+ * Creates an instance of ForbiddenError.
1791
+ * @param {string} [message] - The error message.
1792
+ */
1793
+ constructor(message) {
1794
+ super(403);
1795
+ Object.setPrototypeOf(this, ForbiddenError.prototype);
1796
+ if (message) this.message = message;
1797
+ }
1798
+ };
1799
+
1800
+ //#endregion
1801
+ //#region packages/core/src/Errors/Http/MethodNotAllowedError.ts
1802
+ var MethodNotAllowedError = class MethodNotAllowedError extends HttpError {
1803
+ /**
1804
+ * The name of the error.
1805
+ * @type {string}
1806
+ */
1807
+ name = "MethodNotAllowedError";
1808
+ /**
1809
+ * Creates an instance of MethodNotAllowedError.
1810
+ * @param {string} [message] - The error message.
1811
+ */
1812
+ constructor(message) {
1813
+ super(405);
1814
+ Object.setPrototypeOf(this, MethodNotAllowedError.prototype);
1815
+ if (message) this.message = message;
1816
+ }
1817
+ };
1818
+
1819
+ //#endregion
1820
+ //#region packages/core/src/Errors/Http/NotAcceptableError.ts
1821
+ var NotAcceptableError = class NotAcceptableError extends HttpError {
1822
+ /**
1823
+ * The name of the error.
1824
+ * @type {string}
1825
+ */
1826
+ name = "NotAcceptableError";
1827
+ /**
1828
+ * Creates an instance of NotAcceptableError.
1829
+ * @param {string} [message] - The error message.
1830
+ */
1831
+ constructor(message) {
1832
+ super(406);
1833
+ Object.setPrototypeOf(this, NotAcceptableError.prototype);
1834
+ if (message) this.message = message;
1835
+ }
1836
+ };
1837
+
1838
+ //#endregion
1839
+ //#region packages/core/src/Errors/Http/NotFoundError.ts
1840
+ var NotFoundError = class NotFoundError extends HttpError {
1841
+ /**
1842
+ * The name of the error.
1843
+ * @type {string}
1844
+ */
1845
+ name = "NotFoundError";
1846
+ /**
1847
+ * Creates an instance of NotFoundError.
1848
+ * @param {string} [message] - The error message.
1849
+ */
1850
+ constructor(message) {
1851
+ super(404);
1852
+ Object.setPrototypeOf(this, NotFoundError.prototype);
1853
+ if (message) this.message = message;
1854
+ }
1855
+ };
1856
+
1857
+ //#endregion
1858
+ //#region packages/core/src/Errors/Http/UnauthorizedError.ts
1859
+ var UnauthorizedError = class UnauthorizedError extends HttpError {
1860
+ /**
1861
+ * The name of the error.
1862
+ * @type {string}
1863
+ */
1864
+ name = "UnauthorizedError";
1865
+ /**
1866
+ * Creates an instance of UnauthorizedError.
1867
+ * @param {string} [message] - The error message.
1868
+ */
1869
+ constructor(message) {
1870
+ super(401);
1871
+ Object.setPrototypeOf(this, UnauthorizedError.prototype);
1872
+ if (message) this.message = message;
1873
+ }
1874
+ };
1875
+
1876
+ //#endregion
1877
+ //#region packages/core/src/Types/HttpTypes.ts
1878
+ let HTTPStatus = /* @__PURE__ */ function(HTTPStatus$1) {
1879
+ HTTPStatus$1[HTTPStatus$1["CONTINUE"] = 100] = "CONTINUE";
1880
+ HTTPStatus$1[HTTPStatus$1["SWITCHING_PROTOCOLS"] = 101] = "SWITCHING_PROTOCOLS";
1881
+ HTTPStatus$1[HTTPStatus$1["PROCESSING"] = 102] = "PROCESSING";
1882
+ HTTPStatus$1[HTTPStatus$1["OK"] = 200] = "OK";
1883
+ HTTPStatus$1[HTTPStatus$1["CREATED"] = 201] = "CREATED";
1884
+ HTTPStatus$1[HTTPStatus$1["ACCEPTED"] = 202] = "ACCEPTED";
1885
+ HTTPStatus$1[HTTPStatus$1["NON_AUTHORITATIVE_INFORMATION"] = 203] = "NON_AUTHORITATIVE_INFORMATION";
1886
+ HTTPStatus$1[HTTPStatus$1["NO_CONTENT"] = 204] = "NO_CONTENT";
1887
+ HTTPStatus$1[HTTPStatus$1["RESET_CONTENT"] = 205] = "RESET_CONTENT";
1888
+ HTTPStatus$1[HTTPStatus$1["PARTIAL_CONTENT"] = 206] = "PARTIAL_CONTENT";
1889
+ HTTPStatus$1[HTTPStatus$1["MULTI_STATUS"] = 207] = "MULTI_STATUS";
1890
+ HTTPStatus$1[HTTPStatus$1["ALREADY_REPORTED"] = 208] = "ALREADY_REPORTED";
1891
+ HTTPStatus$1[HTTPStatus$1["IM_USED"] = 226] = "IM_USED";
1892
+ HTTPStatus$1[HTTPStatus$1["MULTIPLE_CHOICES"] = 300] = "MULTIPLE_CHOICES";
1893
+ HTTPStatus$1[HTTPStatus$1["MOVED_PERMANENTLY"] = 301] = "MOVED_PERMANENTLY";
1894
+ HTTPStatus$1[HTTPStatus$1["FOUND"] = 302] = "FOUND";
1895
+ HTTPStatus$1[HTTPStatus$1["SEE_OTHER"] = 303] = "SEE_OTHER";
1896
+ HTTPStatus$1[HTTPStatus$1["NOT_MODIFIED"] = 304] = "NOT_MODIFIED";
1897
+ HTTPStatus$1[HTTPStatus$1["USE_PROXY"] = 305] = "USE_PROXY";
1898
+ HTTPStatus$1[HTTPStatus$1["TEMPORARY_REDIRECT"] = 307] = "TEMPORARY_REDIRECT";
1899
+ HTTPStatus$1[HTTPStatus$1["PERMANENT_REDIRECT"] = 308] = "PERMANENT_REDIRECT";
1900
+ HTTPStatus$1[HTTPStatus$1["BAD_REQUEST"] = 400] = "BAD_REQUEST";
1901
+ HTTPStatus$1[HTTPStatus$1["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
1902
+ HTTPStatus$1[HTTPStatus$1["PAYMENT_REQUIRED"] = 402] = "PAYMENT_REQUIRED";
1903
+ HTTPStatus$1[HTTPStatus$1["FORBIDDEN"] = 403] = "FORBIDDEN";
1904
+ HTTPStatus$1[HTTPStatus$1["NOT_FOUND"] = 404] = "NOT_FOUND";
1905
+ HTTPStatus$1[HTTPStatus$1["METHOD_NOT_ALLOWED"] = 405] = "METHOD_NOT_ALLOWED";
1906
+ HTTPStatus$1[HTTPStatus$1["NOT_ACCEPTABLE"] = 406] = "NOT_ACCEPTABLE";
1907
+ HTTPStatus$1[HTTPStatus$1["PROXY_AUTHENTICATION_REQUIRED"] = 407] = "PROXY_AUTHENTICATION_REQUIRED";
1908
+ HTTPStatus$1[HTTPStatus$1["REQUEST_TIMEOUT"] = 408] = "REQUEST_TIMEOUT";
1909
+ HTTPStatus$1[HTTPStatus$1["CONFLICT"] = 409] = "CONFLICT";
1910
+ HTTPStatus$1[HTTPStatus$1["GONE"] = 410] = "GONE";
1911
+ HTTPStatus$1[HTTPStatus$1["LENGTH_REQUIRED"] = 411] = "LENGTH_REQUIRED";
1912
+ HTTPStatus$1[HTTPStatus$1["PRECONDITION_FAILED"] = 412] = "PRECONDITION_FAILED";
1913
+ HTTPStatus$1[HTTPStatus$1["PAYLOAD_TOO_LARGE"] = 413] = "PAYLOAD_TOO_LARGE";
1914
+ HTTPStatus$1[HTTPStatus$1["URI_TOO_LONG"] = 414] = "URI_TOO_LONG";
1915
+ HTTPStatus$1[HTTPStatus$1["UNSUPPORTED_MEDIA_TYPE"] = 415] = "UNSUPPORTED_MEDIA_TYPE";
1916
+ HTTPStatus$1[HTTPStatus$1["RANGE_NOT_SATISFIABLE"] = 416] = "RANGE_NOT_SATISFIABLE";
1917
+ HTTPStatus$1[HTTPStatus$1["EXPECTATION_FAILED"] = 417] = "EXPECTATION_FAILED";
1918
+ HTTPStatus$1[HTTPStatus$1["I_AM_A_TEAPOT"] = 418] = "I_AM_A_TEAPOT";
1919
+ HTTPStatus$1[HTTPStatus$1["MISDIRECTED_REQUEST"] = 421] = "MISDIRECTED_REQUEST";
1920
+ HTTPStatus$1[HTTPStatus$1["UNPROCESSABLE_ENTITY"] = 422] = "UNPROCESSABLE_ENTITY";
1921
+ HTTPStatus$1[HTTPStatus$1["LOCKED"] = 423] = "LOCKED";
1922
+ HTTPStatus$1[HTTPStatus$1["FAILED_DEPENDENCY"] = 424] = "FAILED_DEPENDENCY";
1923
+ HTTPStatus$1[HTTPStatus$1["TOO_EARLY"] = 425] = "TOO_EARLY";
1924
+ HTTPStatus$1[HTTPStatus$1["UPGRADE_REQUIRED"] = 426] = "UPGRADE_REQUIRED";
1925
+ HTTPStatus$1[HTTPStatus$1["PRECONDITION_REQUIRED"] = 428] = "PRECONDITION_REQUIRED";
1926
+ HTTPStatus$1[HTTPStatus$1["TOO_MANY_REQUESTS"] = 429] = "TOO_MANY_REQUESTS";
1927
+ HTTPStatus$1[HTTPStatus$1["REQUEST_HEADER_FIELDS_TOO_LARGE"] = 431] = "REQUEST_HEADER_FIELDS_TOO_LARGE";
1928
+ HTTPStatus$1[HTTPStatus$1["UNAVAILABLE_FOR_LEGAL_REASONS"] = 451] = "UNAVAILABLE_FOR_LEGAL_REASONS";
1929
+ HTTPStatus$1[HTTPStatus$1["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
1930
+ HTTPStatus$1[HTTPStatus$1["NOT_IMPLEMENTED"] = 501] = "NOT_IMPLEMENTED";
1931
+ HTTPStatus$1[HTTPStatus$1["BAD_GATEWAY"] = 502] = "BAD_GATEWAY";
1932
+ HTTPStatus$1[HTTPStatus$1["SERVICE_UNAVAILABLE"] = 503] = "SERVICE_UNAVAILABLE";
1933
+ HTTPStatus$1[HTTPStatus$1["GATEWAY_TIMEOUT"] = 504] = "GATEWAY_TIMEOUT";
1934
+ HTTPStatus$1[HTTPStatus$1["HTTP_VERSION_NOT_SUPPORTED"] = 505] = "HTTP_VERSION_NOT_SUPPORTED";
1935
+ HTTPStatus$1[HTTPStatus$1["VARIANT_ALSO_NEGOTIATES"] = 506] = "VARIANT_ALSO_NEGOTIATES";
1936
+ HTTPStatus$1[HTTPStatus$1["INSUFFICIENT_STORAGE"] = 507] = "INSUFFICIENT_STORAGE";
1937
+ HTTPStatus$1[HTTPStatus$1["LOOP_DETECTED"] = 508] = "LOOP_DETECTED";
1938
+ HTTPStatus$1[HTTPStatus$1["NOT_EXTENDED"] = 510] = "NOT_EXTENDED";
1939
+ HTTPStatus$1[HTTPStatus$1["NETWORK_AUTHENTICATION_REQUIRED"] = 511] = "NETWORK_AUTHENTICATION_REQUIRED";
1940
+ return HTTPStatus$1;
1941
+ }({});
1942
+
1943
+ //#endregion
1944
+ export { App, BadRequestError, BaseMiddleware, BasePlugin, Body, Connect, Controller, Delete, ForbiddenError, Get, HTTPStatus, Head, Header, Headers$1 as Headers, HooksService, HttpError, InternalServerError, Listen, MethodNotAllowedError, Middleware, MultipartFormData, NotAcceptableError, NotFoundError, Options, Param, Patch, Post, Put, QueryParam, QueryParams, Redirect, Request, Response$1 as Response, Session, SetHeader, Status, Trace, UnauthorizedError, createApp, createMetadataCtx, createMetadataMethod, defineConfig, initializeMetadata, initializeMetadataMethod, loadVercubeConfig };