@vercube/core 0.0.22 → 0.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -7
- package/dist/index.d.mts +2 -13
- package/dist/index.mjs +609 -674
- package/package.json +7 -4
package/dist/index.mjs
CHANGED
|
@@ -3,8 +3,8 @@ import { BaseDecorator, Container, Inject, InjectOptional, createDecorator, init
|
|
|
3
3
|
import { FastResponse, serve } from "srvx";
|
|
4
4
|
import { addRoute, createRouter, findRoute } from "rou3";
|
|
5
5
|
import { createReadStream } from "node:fs";
|
|
6
|
-
import { extname, join, normalize } from "node:path";
|
|
7
6
|
import { stat } from "node:fs/promises";
|
|
7
|
+
import { extname, join, normalize } from "node:path";
|
|
8
8
|
import { BaseLogger, Logger } from "@vercube/logger";
|
|
9
9
|
import { ConsoleProvider } from "@vercube/logger/drivers/ConsoleProvider";
|
|
10
10
|
import { loadConfig, setupDotenv } from "c12";
|
|
@@ -36,247 +36,32 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
36
36
|
}) : target, mod));
|
|
37
37
|
|
|
38
38
|
//#endregion
|
|
39
|
-
//#region
|
|
40
|
-
var require_decorate = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.81.0/node_modules/@oxc-project/runtime/src/helpers/decorate.js": ((exports, module) => {
|
|
41
|
-
function __decorate(decorators, target, key, desc) {
|
|
42
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
43
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
44
|
-
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;
|
|
45
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
46
|
-
}
|
|
47
|
-
module.exports = __decorate, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
48
|
-
}) });
|
|
49
|
-
|
|
50
|
-
//#endregion
|
|
51
|
-
//#region src/Services/Plugins/PluginsRegistry.ts
|
|
52
|
-
var import_decorate$18 = /* @__PURE__ */ __toESM(require_decorate(), 1);
|
|
53
|
-
var PluginsRegistry = class {
|
|
54
|
-
gContainer;
|
|
55
|
-
/** Holds the list of plugins */
|
|
56
|
-
fPlugins = /* @__PURE__ */ new Map();
|
|
57
|
-
/**
|
|
58
|
-
* Registers a plugin.
|
|
59
|
-
*
|
|
60
|
-
* @param {Plugin} plugin - The plugin to register.
|
|
61
|
-
* @param {unknown} options - The options to pass to the plugin.
|
|
62
|
-
*/
|
|
63
|
-
register(plugin, options) {
|
|
64
|
-
const instance = this.gContainer.resolve(plugin);
|
|
65
|
-
this.fPlugins.set(instance.name, {
|
|
66
|
-
instance,
|
|
67
|
-
options
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Gets the list of registered plugins.
|
|
72
|
-
*
|
|
73
|
-
* @returns {Plugin[]} The list of registered plugins.
|
|
74
|
-
*/
|
|
75
|
-
get plugins() {
|
|
76
|
-
return [...this.fPlugins.values()].map((plugin) => plugin.instance);
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Resolves the plugins.
|
|
80
|
-
*
|
|
81
|
-
* @param {App} app - The application instance.
|
|
82
|
-
*/
|
|
83
|
-
async init(app) {
|
|
84
|
-
for (const { instance, options } of this.fPlugins.values()) await instance.use(app, options);
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
(0, import_decorate$18.default)([Inject(Container)], PluginsRegistry.prototype, "gContainer", void 0);
|
|
88
|
-
|
|
89
|
-
//#endregion
|
|
90
|
-
//#region src/Services/Hooks/HooksService.ts
|
|
91
|
-
/**
|
|
92
|
-
* This class is responsible for managing events.
|
|
93
|
-
*/
|
|
94
|
-
var HooksService = class {
|
|
95
|
-
fLastId = 0;
|
|
96
|
-
fHandlers = /* @__PURE__ */ new Map();
|
|
97
|
-
/**
|
|
98
|
-
* Registers listener for event of particular type. Everytime event is called, the listener
|
|
99
|
-
* will be executed.
|
|
100
|
-
*
|
|
101
|
-
* @param type type of event, simple class
|
|
102
|
-
* @param callback callback fired when event is triggered
|
|
103
|
-
* @returns unique ID for event listener, can be used to disable this listener
|
|
104
|
-
*/
|
|
105
|
-
on(type, callback) {
|
|
106
|
-
let handlersOfType = this.fHandlers.get(type);
|
|
107
|
-
if (!handlersOfType) {
|
|
108
|
-
handlersOfType = [];
|
|
109
|
-
this.fHandlers.set(type, handlersOfType);
|
|
110
|
-
}
|
|
111
|
-
const genId = this.fLastId++;
|
|
112
|
-
const handler = {
|
|
113
|
-
callback,
|
|
114
|
-
id: genId
|
|
115
|
-
};
|
|
116
|
-
handlersOfType.push(handler);
|
|
117
|
-
return {
|
|
118
|
-
__id: genId,
|
|
119
|
-
__type: type
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Waits for single event execution and removes the listener immediately after.
|
|
124
|
-
*
|
|
125
|
-
* @example
|
|
126
|
-
* this.gCart.addItem(product);
|
|
127
|
-
* await this.gEvents.waitFor(CartUpdatedEvent);
|
|
128
|
-
* console.log('here cart updated event is already called');
|
|
129
|
-
*
|
|
130
|
-
* @param type type of event to wait for
|
|
131
|
-
* @param timeout timeout param in ms - if event is not thrown until this time, it'll reject. passing null disables the timeout
|
|
132
|
-
* @returns promise with event data that resolves when event is finally called
|
|
133
|
-
*/
|
|
134
|
-
waitFor(type, timeout = 10 * 1e3) {
|
|
135
|
-
return new Promise((resolve, reject) => {
|
|
136
|
-
let waitTimeout;
|
|
137
|
-
const eventId = this.on(type, (data) => {
|
|
138
|
-
this.off(eventId);
|
|
139
|
-
resolve(data);
|
|
140
|
-
if (waitTimeout) clearTimeout(waitTimeout);
|
|
141
|
-
});
|
|
142
|
-
if (timeout !== null) waitTimeout = setTimeout(() => {
|
|
143
|
-
this.off(eventId);
|
|
144
|
-
reject(/* @__PURE__ */ new Error(`Waiting for event timeout - ${type.name}`));
|
|
145
|
-
}, timeout);
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Removes listener from particular event.
|
|
150
|
-
* @param eventId eventId returned from .on() method.
|
|
151
|
-
* @throws Error if event was not registered
|
|
152
|
-
*/
|
|
153
|
-
off(eventId) {
|
|
154
|
-
const type = eventId.__type;
|
|
155
|
-
const handlersOfType = this.fHandlers.get(type);
|
|
156
|
-
if (!handlersOfType) throw new Error("Trying to unbind event that was not bound.");
|
|
157
|
-
const index = handlersOfType.findIndex((handler) => handler.id === eventId.__id);
|
|
158
|
-
if (index === -1) throw new Error("Trying to unbind event that was not bound.");
|
|
159
|
-
handlersOfType.splice(index, 1);
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Triggers event, calling all listener callbacks. Will return Promise of number,
|
|
163
|
-
* that is resolved when all asynchronous listeners are called.
|
|
164
|
-
* @param type type of trigger, simple class
|
|
165
|
-
* @param data data which will be passed to listeners, based on event class
|
|
166
|
-
* @return number of listeners that were notified
|
|
167
|
-
*/
|
|
168
|
-
async trigger(type, data) {
|
|
169
|
-
const handlersOfType = this.fHandlers.get(type);
|
|
170
|
-
if (!handlersOfType) return 0;
|
|
171
|
-
const toProcessHandlers = [...handlersOfType];
|
|
172
|
-
const promises = toProcessHandlers.map((handler) => {
|
|
173
|
-
const instance = this.objectToClass(type, data);
|
|
174
|
-
const result = handler.callback(instance);
|
|
175
|
-
return result instanceof Promise ? result : Promise.resolve();
|
|
176
|
-
});
|
|
177
|
-
await Promise.all(promises);
|
|
178
|
-
return toProcessHandlers.length;
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* Converts plain object to it's class equivalent.
|
|
182
|
-
* It's NOT class-transformer, it performs basic key assigment.
|
|
183
|
-
*
|
|
184
|
-
* @param ClassConstructor event constructor
|
|
185
|
-
* @param data event data to be mapped to constructor
|
|
186
|
-
* @return class type of event
|
|
187
|
-
*/
|
|
188
|
-
objectToClass(ClassConstructor, data) {
|
|
189
|
-
const instance = new ClassConstructor();
|
|
190
|
-
if (data) for (const key of Object.keys(data)) {
|
|
191
|
-
const rawInstance = instance;
|
|
192
|
-
const rawData = data;
|
|
193
|
-
rawInstance[key] = rawData[key];
|
|
194
|
-
}
|
|
195
|
-
return instance;
|
|
196
|
-
}
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
//#endregion
|
|
200
|
-
//#region src/Hooks/Router/RouterBeforeInitHook.ts
|
|
201
|
-
var RouterBeforeInitHook = class {};
|
|
202
|
-
|
|
203
|
-
//#endregion
|
|
204
|
-
//#region src/Hooks/Router/RouterAfterInitHook.ts
|
|
205
|
-
var RouterAfterInitHook = class {};
|
|
206
|
-
|
|
207
|
-
//#endregion
|
|
208
|
-
//#region src/Services/Router/Router.ts
|
|
209
|
-
var import_decorate$17 = /* @__PURE__ */ __toESM(require_decorate(), 1);
|
|
39
|
+
//#region src/Services/Config/RuntimeConfig.ts
|
|
210
40
|
/**
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
* This class provides functionality to initialize the router,
|
|
214
|
-
* register routes, and resolve incoming requests to their
|
|
215
|
-
* appropriate handlers.
|
|
41
|
+
* RuntimeConfig class manages the runtime configuration for the Vercube application.
|
|
42
|
+
* This class provides a centralized way to access and modify runtime configuration settings.
|
|
216
43
|
*/
|
|
217
|
-
var
|
|
218
|
-
/**
|
|
219
|
-
* Service for triggering application hooks
|
|
220
|
-
*/
|
|
221
|
-
gHooksService;
|
|
44
|
+
var RuntimeConfig = class {
|
|
222
45
|
/**
|
|
223
|
-
*
|
|
46
|
+
* Private field to store the runtime configuration object.
|
|
224
47
|
* @private
|
|
225
48
|
*/
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* Registers a new route in the router
|
|
229
|
-
*
|
|
230
|
-
* @param {RouterTypes.Route} route - The route configuration to add
|
|
231
|
-
* @throws {Error} If router is not initialized
|
|
232
|
-
*/
|
|
233
|
-
addRoute(route) {
|
|
234
|
-
if (!this.fRouterContext) throw new Error("Router not initialized. Please call init() before adding routes.");
|
|
235
|
-
addRoute(this.fRouterContext, route.method.toUpperCase(), route.path, route.handler);
|
|
236
|
-
}
|
|
49
|
+
fRuntimeConfig;
|
|
237
50
|
/**
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
* This method creates a new router context and triggers
|
|
241
|
-
* the before and after initialization hooks.
|
|
51
|
+
* Gets the current runtime configuration.
|
|
52
|
+
* @returns {ConfigTypes.CreateRuntimeConfig<T> | undefined} The current runtime configuration object.
|
|
242
53
|
*/
|
|
243
|
-
|
|
244
|
-
this.
|
|
245
|
-
this.fRouterContext = createRouter();
|
|
246
|
-
this.gHooksService.trigger(RouterAfterInitHook);
|
|
54
|
+
get runtimeConfig() {
|
|
55
|
+
return this.fRuntimeConfig;
|
|
247
56
|
}
|
|
248
57
|
/**
|
|
249
|
-
*
|
|
250
|
-
*
|
|
251
|
-
* @param {RouterTypes.RouteFind} route - The route to resolve
|
|
252
|
-
* @returns {RouterTypes.RouteMatched<RouterTypes.RouterHandler> | undefined} The matched route or undefined if no match found
|
|
58
|
+
* Sets the runtime configuration.
|
|
59
|
+
* @param {ConfigTypes.CreateRuntimeConfig<T>} value - The new runtime configuration object to set.
|
|
253
60
|
*/
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
try {
|
|
257
|
-
url = new URL(route.path).pathname;
|
|
258
|
-
} catch {}
|
|
259
|
-
return findRoute(this.fRouterContext, route.method.toUpperCase(), url);
|
|
61
|
+
set runtimeConfig(value) {
|
|
62
|
+
this.fRuntimeConfig = value;
|
|
260
63
|
}
|
|
261
64
|
};
|
|
262
|
-
(0, import_decorate$17.default)([Inject(HooksService)], Router.prototype, "gHooksService", void 0);
|
|
263
|
-
|
|
264
|
-
//#endregion
|
|
265
|
-
//#region src/Resolvers/RouterParam.ts
|
|
266
|
-
/**
|
|
267
|
-
* Resolves a router parameter from the event object
|
|
268
|
-
* @param param - The parameter name to resolve from the router event
|
|
269
|
-
* @param event - The router event object containing parameters
|
|
270
|
-
* @returns The resolved parameter value if it exists, null otherwise
|
|
271
|
-
* @example
|
|
272
|
-
* ```typescript
|
|
273
|
-
* const value = resolveRouterParam('id', routerEvent);
|
|
274
|
-
* // Returns the 'id' parameter value from routerEvent.params or null
|
|
275
|
-
* ```
|
|
276
|
-
*/
|
|
277
|
-
function resolveRouterParam(param, event) {
|
|
278
|
-
return event.params?.[param] ?? null;
|
|
279
|
-
}
|
|
280
65
|
|
|
281
66
|
//#endregion
|
|
282
67
|
//#region src/Errors/HttpError.ts
|
|
@@ -305,46 +90,80 @@ var HttpError = class HttpError extends Error {
|
|
|
305
90
|
};
|
|
306
91
|
|
|
307
92
|
//#endregion
|
|
308
|
-
//#region src/Errors/Http/
|
|
93
|
+
//#region src/Errors/Http/NotFoundError.ts
|
|
309
94
|
/**
|
|
310
|
-
* Represents a
|
|
95
|
+
* Represents a Not Found error (HTTP 404).
|
|
311
96
|
* @extends {HttpError}
|
|
312
97
|
*/
|
|
313
|
-
var
|
|
98
|
+
var NotFoundError = class NotFoundError extends HttpError {
|
|
314
99
|
/**
|
|
315
100
|
* The name of the error.
|
|
316
101
|
* @type {string}
|
|
317
102
|
*/
|
|
318
|
-
name = "
|
|
103
|
+
name = "NotFoundError";
|
|
319
104
|
/**
|
|
320
|
-
* Creates an instance of
|
|
105
|
+
* Creates an instance of NotFoundError.
|
|
321
106
|
* @param {string} [message] - The error message.
|
|
322
107
|
*/
|
|
323
|
-
constructor(message
|
|
324
|
-
super(
|
|
325
|
-
Object.setPrototypeOf(this,
|
|
108
|
+
constructor(message) {
|
|
109
|
+
super(404);
|
|
110
|
+
Object.setPrototypeOf(this, NotFoundError.prototype);
|
|
326
111
|
if (message) this.message = message;
|
|
327
|
-
if (errors) this.errors = errors;
|
|
328
112
|
}
|
|
329
113
|
};
|
|
330
114
|
|
|
331
115
|
//#endregion
|
|
332
|
-
//#region src/
|
|
116
|
+
//#region src/Services/ErrorHandler/ErrorHandlerProvider.ts
|
|
333
117
|
/**
|
|
334
|
-
*
|
|
335
|
-
*
|
|
118
|
+
* Abstract class representing an error handler provider
|
|
119
|
+
* Provides a common interface for different error handler implementations
|
|
120
|
+
*
|
|
121
|
+
* @abstract
|
|
122
|
+
* @class ErrorHandlerProvider
|
|
123
|
+
*/
|
|
124
|
+
var ErrorHandlerProvider = class {};
|
|
125
|
+
|
|
126
|
+
//#endregion
|
|
127
|
+
//#region src/Errors/Http/BadRequestError.ts
|
|
128
|
+
/**
|
|
129
|
+
* Represents a Bad Request error (HTTP 400).
|
|
130
|
+
* @extends {HttpError}
|
|
131
|
+
*/
|
|
132
|
+
var BadRequestError = class BadRequestError extends HttpError {
|
|
133
|
+
/**
|
|
134
|
+
* The name of the error.
|
|
135
|
+
* @type {string}
|
|
136
|
+
*/
|
|
137
|
+
name = "BadRequestError";
|
|
138
|
+
/**
|
|
139
|
+
* Creates an instance of BadRequestError.
|
|
140
|
+
* @param {string} [message] - The error message.
|
|
141
|
+
*/
|
|
142
|
+
constructor(message, errors) {
|
|
143
|
+
super(400);
|
|
144
|
+
Object.setPrototypeOf(this, BadRequestError.prototype);
|
|
145
|
+
if (message) this.message = message;
|
|
146
|
+
if (errors) this.errors = errors;
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
//#endregion
|
|
151
|
+
//#region src/Resolvers/Body.ts
|
|
152
|
+
/**
|
|
153
|
+
* Resolves and parses the request body from a RouterEvent.
|
|
154
|
+
*
|
|
336
155
|
* @param {RouterTypes.RouterEvent} event - The router event containing the request to process
|
|
337
156
|
* @returns {Promise<unknown>} A promise that resolves to:
|
|
338
157
|
* - The parsed JSON body if the request contains valid JSON
|
|
339
158
|
* - undefined if the request body is empty
|
|
340
159
|
* @throws {BadRequestError} If the request body contains invalid JSON
|
|
341
|
-
*
|
|
160
|
+
*
|
|
342
161
|
* @example
|
|
343
162
|
* const body = await resolveRequestBody(event);
|
|
344
163
|
* if (body) {
|
|
345
164
|
* // Process the parsed body
|
|
346
165
|
* }
|
|
347
|
-
*
|
|
166
|
+
*
|
|
348
167
|
* @remarks
|
|
349
168
|
* - Currently only supports JSON content type
|
|
350
169
|
* - Returns undefined for empty request bodies
|
|
@@ -360,6 +179,26 @@ async function resolveRequestBody(event) {
|
|
|
360
179
|
}
|
|
361
180
|
}
|
|
362
181
|
|
|
182
|
+
//#endregion
|
|
183
|
+
//#region src/Resolvers/Headers.ts
|
|
184
|
+
/**
|
|
185
|
+
* Retrieves a specific header value from the request
|
|
186
|
+
* @param {string} header - The name of the header to retrieve
|
|
187
|
+
* @param {RouterTypes.RouterEvent} event - The router event containing the request
|
|
188
|
+
* @returns {string | null} The header value if found, null otherwise
|
|
189
|
+
*/
|
|
190
|
+
function getRequestHeader(header, event) {
|
|
191
|
+
return event.request.headers.get(header);
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Retrieves all headers from the request
|
|
195
|
+
* @param {RouterTypes.RouterEvent} event - The router event containing the request
|
|
196
|
+
* @returns {Headers} The complete Headers object from the request
|
|
197
|
+
*/
|
|
198
|
+
function getRequestHeaders(event) {
|
|
199
|
+
return event.request.headers;
|
|
200
|
+
}
|
|
201
|
+
|
|
363
202
|
//#endregion
|
|
364
203
|
//#region src/Resolvers/Query.ts
|
|
365
204
|
/**
|
|
@@ -385,23 +224,20 @@ function resolveQueryParams(event) {
|
|
|
385
224
|
}
|
|
386
225
|
|
|
387
226
|
//#endregion
|
|
388
|
-
//#region src/Resolvers/
|
|
389
|
-
/**
|
|
390
|
-
* Retrieves a specific header value from the request
|
|
391
|
-
* @param {string} header - The name of the header to retrieve
|
|
392
|
-
* @param {RouterTypes.RouterEvent} event - The router event containing the request
|
|
393
|
-
* @returns {string | null} The header value if found, null otherwise
|
|
394
|
-
*/
|
|
395
|
-
function getRequestHeader(header, event) {
|
|
396
|
-
return event.request.headers.get(header);
|
|
397
|
-
}
|
|
227
|
+
//#region src/Resolvers/RouterParam.ts
|
|
398
228
|
/**
|
|
399
|
-
*
|
|
400
|
-
* @param
|
|
401
|
-
* @
|
|
229
|
+
* Resolves a router parameter from the event object
|
|
230
|
+
* @param param - The parameter name to resolve from the router event
|
|
231
|
+
* @param event - The router event object containing parameters
|
|
232
|
+
* @returns The resolved parameter value if it exists, null otherwise
|
|
233
|
+
* @example
|
|
234
|
+
* ```typescript
|
|
235
|
+
* const value = resolveRouterParam('id', routerEvent);
|
|
236
|
+
* // Returns the 'id' parameter value from routerEvent.params or null
|
|
237
|
+
* ```
|
|
402
238
|
*/
|
|
403
|
-
function
|
|
404
|
-
return event.
|
|
239
|
+
function resolveRouterParam(param, event) {
|
|
240
|
+
return event.params?.[param] ?? null;
|
|
405
241
|
}
|
|
406
242
|
|
|
407
243
|
//#endregion
|
|
@@ -448,7 +284,7 @@ var MetadataResolver = class {
|
|
|
448
284
|
* Resolves an argument for a given event.
|
|
449
285
|
*
|
|
450
286
|
* @param {MetadataTypes.Arg} arg - The argument to resolve.
|
|
451
|
-
*
|
|
287
|
+
*
|
|
452
288
|
* @return {unknown} The resolved argument.
|
|
453
289
|
* @private
|
|
454
290
|
*/
|
|
@@ -483,21 +319,17 @@ var MetadataResolver = class {
|
|
|
483
319
|
};
|
|
484
320
|
|
|
485
321
|
//#endregion
|
|
486
|
-
//#region src/Services/
|
|
322
|
+
//#region src/Services/Middleware/BaseMiddleware.ts
|
|
487
323
|
/**
|
|
488
|
-
*
|
|
489
|
-
* Provides a common interface for different error handler implementations
|
|
490
|
-
*
|
|
491
|
-
* @abstract
|
|
492
|
-
* @class ErrorHandlerProvider
|
|
324
|
+
* BaseMiddleware class that serves as a base for all middleware implementations.
|
|
493
325
|
*/
|
|
494
|
-
var
|
|
326
|
+
var BaseMiddleware = class {};
|
|
495
327
|
|
|
496
328
|
//#endregion
|
|
497
329
|
//#region src/Services/Middleware/GlobalMiddlewareRegistry.ts
|
|
498
330
|
/**
|
|
499
331
|
* Manages global middleware registration and retrieval
|
|
500
|
-
*
|
|
332
|
+
*
|
|
501
333
|
* This class provides functionality to register and retrieve global middleware
|
|
502
334
|
* configurations. It allows for adding middleware with specific options and
|
|
503
335
|
* retrieving them in a standardized format.
|
|
@@ -506,7 +338,7 @@ var GlobalMiddlewareRegistry = class {
|
|
|
506
338
|
fMiddlewares = /* @__PURE__ */ new Set();
|
|
507
339
|
/**
|
|
508
340
|
* Retrieves all registered global middleware configurations
|
|
509
|
-
*
|
|
341
|
+
*
|
|
510
342
|
* @returns {MetadataTypes.Middleware[]} An array of middleware configurations
|
|
511
343
|
*/
|
|
512
344
|
get middlewares() {
|
|
@@ -518,7 +350,7 @@ var GlobalMiddlewareRegistry = class {
|
|
|
518
350
|
}
|
|
519
351
|
/**
|
|
520
352
|
* Registers a global middleware configuration
|
|
521
|
-
*
|
|
353
|
+
*
|
|
522
354
|
* @param {typeof BaseMiddleware<T, U>} middleware - The middleware class to register
|
|
523
355
|
* @param {GlobalMiddlewareParams<T>} opts - The middleware options
|
|
524
356
|
* @returns {void}
|
|
@@ -531,12 +363,24 @@ var GlobalMiddlewareRegistry = class {
|
|
|
531
363
|
}
|
|
532
364
|
};
|
|
533
365
|
|
|
366
|
+
//#endregion
|
|
367
|
+
//#region ../../node_modules/.pnpm/@oxc-project+runtime@0.82.3/node_modules/@oxc-project/runtime/src/helpers/decorate.js
|
|
368
|
+
var require_decorate = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.82.3/node_modules/@oxc-project/runtime/src/helpers/decorate.js": ((exports, module) => {
|
|
369
|
+
function __decorate(decorators, target, key, desc) {
|
|
370
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
371
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
372
|
+
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;
|
|
373
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
374
|
+
}
|
|
375
|
+
module.exports = __decorate, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
376
|
+
}) });
|
|
377
|
+
|
|
534
378
|
//#endregion
|
|
535
379
|
//#region src/Services/Router/RequestHandler.ts
|
|
536
|
-
var import_decorate$
|
|
380
|
+
var import_decorate$17 = /* @__PURE__ */ __toESM(require_decorate(), 1);
|
|
537
381
|
/**
|
|
538
382
|
* Handles HTTP requests by preparing and executing route handlers with their associated middlewares
|
|
539
|
-
*
|
|
383
|
+
*
|
|
540
384
|
* The RequestHandler is responsible for:
|
|
541
385
|
* - Preparing route handlers with their metadata
|
|
542
386
|
* - Executing middleware chains (before and after)
|
|
@@ -551,126 +395,301 @@ var RequestHandler = class {
|
|
|
551
395
|
gGlobalMiddlewareRegistry;
|
|
552
396
|
/**
|
|
553
397
|
* Prepares a route handler by resolving its metadata and middlewares
|
|
554
|
-
*
|
|
398
|
+
*
|
|
555
399
|
* @param {RequestHandlerOptions} params - Configuration options for the handler
|
|
556
400
|
* @returns {RouterTypes.RouterHandler} A prepared handler with resolved metadata and middlewares
|
|
557
401
|
*/
|
|
558
|
-
prepareHandler(params) {
|
|
559
|
-
const { instance, propertyName } = params;
|
|
560
|
-
const prototype = Object.getPrototypeOf(instance);
|
|
561
|
-
const method = this.gMetadataResolver.resolveMethod(prototype, propertyName);
|
|
562
|
-
const middlewares = this.gMetadataResolver.resolveMiddlewares(prototype, propertyName);
|
|
563
|
-
const globalMiddlewares = this.gGlobalMiddlewareRegistry.middlewares;
|
|
564
|
-
const uniqueMiddlewares = [...middlewares, ...globalMiddlewares].filter((m, index, self) => self.findIndex((t) => t.middleware === m.middleware) === index);
|
|
565
|
-
const resolvedMiddlewares = uniqueMiddlewares.map((m) => ({
|
|
566
|
-
...m,
|
|
567
|
-
middleware: this.gContainer.resolve(m.middleware)
|
|
568
|
-
}));
|
|
569
|
-
const beforeMiddlewares = resolvedMiddlewares.filter((m) => !!m.middleware.onRequest);
|
|
570
|
-
const afterMiddlewares = resolvedMiddlewares.filter((m) => !!m.middleware.onResponse);
|
|
571
|
-
beforeMiddlewares.sort((a, b) => (a?.priority ?? 999) - (b?.priority ?? 999));
|
|
572
|
-
afterMiddlewares.sort((a, b) => (a?.priority ?? 999) - (b?.priority ?? 999));
|
|
573
|
-
return {
|
|
574
|
-
instance,
|
|
575
|
-
propertyName,
|
|
576
|
-
args: method.args,
|
|
577
|
-
middlewares: {
|
|
578
|
-
beforeMiddlewares,
|
|
579
|
-
afterMiddlewares
|
|
580
|
-
},
|
|
581
|
-
actions: method.actions
|
|
582
|
-
};
|
|
402
|
+
prepareHandler(params) {
|
|
403
|
+
const { instance, propertyName } = params;
|
|
404
|
+
const prototype = Object.getPrototypeOf(instance);
|
|
405
|
+
const method = this.gMetadataResolver.resolveMethod(prototype, propertyName);
|
|
406
|
+
const middlewares = this.gMetadataResolver.resolveMiddlewares(prototype, propertyName);
|
|
407
|
+
const globalMiddlewares = this.gGlobalMiddlewareRegistry.middlewares;
|
|
408
|
+
const uniqueMiddlewares = [...middlewares, ...globalMiddlewares].filter((m, index, self) => self.findIndex((t) => t.middleware === m.middleware) === index);
|
|
409
|
+
const resolvedMiddlewares = uniqueMiddlewares.map((m) => ({
|
|
410
|
+
...m,
|
|
411
|
+
middleware: this.gContainer.resolve(m.middleware)
|
|
412
|
+
}));
|
|
413
|
+
const beforeMiddlewares = resolvedMiddlewares.filter((m) => !!m.middleware.onRequest);
|
|
414
|
+
const afterMiddlewares = resolvedMiddlewares.filter((m) => !!m.middleware.onResponse);
|
|
415
|
+
beforeMiddlewares.sort((a, b) => (a?.priority ?? 999) - (b?.priority ?? 999));
|
|
416
|
+
afterMiddlewares.sort((a, b) => (a?.priority ?? 999) - (b?.priority ?? 999));
|
|
417
|
+
return {
|
|
418
|
+
instance,
|
|
419
|
+
propertyName,
|
|
420
|
+
args: method.args,
|
|
421
|
+
middlewares: {
|
|
422
|
+
beforeMiddlewares,
|
|
423
|
+
afterMiddlewares
|
|
424
|
+
},
|
|
425
|
+
actions: method.actions
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* Processes an HTTP request through the middleware chain and route handler
|
|
430
|
+
*
|
|
431
|
+
* The request handling lifecycle:
|
|
432
|
+
* 1. Execute "before" middlewares
|
|
433
|
+
* 2. Apply route actions (status codes, redirects, etc.)
|
|
434
|
+
* 3. Resolve handler arguments
|
|
435
|
+
* 4. Execute the route handler
|
|
436
|
+
* 5. Execute "after" middlewares
|
|
437
|
+
* 6. Format and return the final response
|
|
438
|
+
*
|
|
439
|
+
* @param {Request} request - The incoming HTTP request
|
|
440
|
+
* @param {RouterTypes.RouteMatched<RouterTypes.RouterHandler>} route - The matched route with handler data
|
|
441
|
+
* @returns {Promise<Response>} The HTTP response
|
|
442
|
+
*/
|
|
443
|
+
async handleRequest(request, route) {
|
|
444
|
+
try {
|
|
445
|
+
const { instance, propertyName, actions = [], args = [], middlewares = {
|
|
446
|
+
beforeMiddlewares: [],
|
|
447
|
+
afterMiddlewares: []
|
|
448
|
+
} } = route.data;
|
|
449
|
+
let fakeResponse = new FastResponse(void 0, { headers: { "Content-Type": request.headers.get("Content-Type") ?? "application/json" } });
|
|
450
|
+
const resolvedArgs = args.length > 0 ? await this.gMetadataResolver.resolveArgs(args, {
|
|
451
|
+
...route,
|
|
452
|
+
request,
|
|
453
|
+
response: fakeResponse
|
|
454
|
+
}) : [];
|
|
455
|
+
if (middlewares.beforeMiddlewares.length > 0) for await (const hook of middlewares.beforeMiddlewares) try {
|
|
456
|
+
const hookResponse = await hook.middleware.onRequest?.(request, fakeResponse, {
|
|
457
|
+
middlewareArgs: hook.args,
|
|
458
|
+
methodArgs: resolvedArgs
|
|
459
|
+
});
|
|
460
|
+
if (hookResponse instanceof Response) return hookResponse;
|
|
461
|
+
} catch (error) {
|
|
462
|
+
const internalError = this.gContainer.get(ErrorHandlerProvider).handleError(error);
|
|
463
|
+
if (internalError instanceof Response) return internalError;
|
|
464
|
+
}
|
|
465
|
+
for (const action of actions) {
|
|
466
|
+
const actionResponse = action.handler(request, fakeResponse);
|
|
467
|
+
if (actionResponse !== null) fakeResponse = this.processOverrideResponse(actionResponse, fakeResponse);
|
|
468
|
+
}
|
|
469
|
+
let handlerResponse = instance[propertyName].call(instance, ...resolvedArgs?.map((a) => a.resolved) ?? []);
|
|
470
|
+
if (handlerResponse instanceof Promise) handlerResponse = await handlerResponse;
|
|
471
|
+
if (middlewares.afterMiddlewares.length > 0) for await (const hook of middlewares.afterMiddlewares) try {
|
|
472
|
+
const hookResponse = await hook.middleware.onResponse?.(request, fakeResponse, handlerResponse);
|
|
473
|
+
if (hookResponse !== null) fakeResponse = this.processOverrideResponse(hookResponse, fakeResponse);
|
|
474
|
+
} catch (error) {
|
|
475
|
+
const internalError = this.gContainer.get(ErrorHandlerProvider).handleError(error);
|
|
476
|
+
if (internalError instanceof Response) return internalError;
|
|
477
|
+
}
|
|
478
|
+
const body = fakeResponse?.body ?? JSON.stringify(handlerResponse);
|
|
479
|
+
const response = new Response(body, {
|
|
480
|
+
status: fakeResponse.status ?? 200,
|
|
481
|
+
statusText: fakeResponse.statusText ?? "OK",
|
|
482
|
+
headers: fakeResponse.headers
|
|
483
|
+
});
|
|
484
|
+
return response;
|
|
485
|
+
} catch (error) {
|
|
486
|
+
return this.gContainer.get(ErrorHandlerProvider).handleError(error);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* Processes and merges response overrides from middlewares or actions
|
|
491
|
+
*
|
|
492
|
+
* This method handles different response formats:
|
|
493
|
+
* - If a full Response object is provided, it's used directly
|
|
494
|
+
* - If ResponseInit is provided, it's merged with the base response
|
|
495
|
+
*
|
|
496
|
+
* @param {Response | ResponseInit} response - The response or response options to apply
|
|
497
|
+
* @param {Response} [base] - The base response to extend (optional)
|
|
498
|
+
* @returns {Response} The processed response with applied overrides
|
|
499
|
+
* @private
|
|
500
|
+
*/
|
|
501
|
+
processOverrideResponse(response, base) {
|
|
502
|
+
let fakeResponse = base ?? new FastResponse();
|
|
503
|
+
if (response != null && response instanceof FastResponse) return response;
|
|
504
|
+
else if (response !== null) {
|
|
505
|
+
const responseInit = response;
|
|
506
|
+
fakeResponse = new FastResponse(void 0, {
|
|
507
|
+
status: responseInit?.status ?? fakeResponse.status,
|
|
508
|
+
headers: responseInit?.headers ?? fakeResponse.headers,
|
|
509
|
+
statusText: responseInit?.statusText ?? fakeResponse.statusText
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
return fakeResponse;
|
|
513
|
+
}
|
|
514
|
+
};
|
|
515
|
+
(0, import_decorate$17.default)([Inject(MetadataResolver)], RequestHandler.prototype, "gMetadataResolver", void 0);
|
|
516
|
+
(0, import_decorate$17.default)([Inject(Container)], RequestHandler.prototype, "gContainer", void 0);
|
|
517
|
+
(0, import_decorate$17.default)([Inject(GlobalMiddlewareRegistry)], RequestHandler.prototype, "gGlobalMiddlewareRegistry", void 0);
|
|
518
|
+
|
|
519
|
+
//#endregion
|
|
520
|
+
//#region src/Hooks/Router/RouterAfterInitHook.ts
|
|
521
|
+
var RouterAfterInitHook = class {};
|
|
522
|
+
|
|
523
|
+
//#endregion
|
|
524
|
+
//#region src/Hooks/Router/RouterBeforeInitHook.ts
|
|
525
|
+
var RouterBeforeInitHook = class {};
|
|
526
|
+
|
|
527
|
+
//#endregion
|
|
528
|
+
//#region src/Services/Hooks/HooksService.ts
|
|
529
|
+
/**
|
|
530
|
+
* This class is responsible for managing events.
|
|
531
|
+
*/
|
|
532
|
+
var HooksService = class {
|
|
533
|
+
fLastId = 0;
|
|
534
|
+
fHandlers = /* @__PURE__ */ new Map();
|
|
535
|
+
/**
|
|
536
|
+
* Registers listener for event of particular type. Everytime event is called, the listener
|
|
537
|
+
* will be executed.
|
|
538
|
+
*
|
|
539
|
+
* @param type type of event, simple class
|
|
540
|
+
* @param callback callback fired when event is triggered
|
|
541
|
+
* @returns unique ID for event listener, can be used to disable this listener
|
|
542
|
+
*/
|
|
543
|
+
on(type, callback) {
|
|
544
|
+
let handlersOfType = this.fHandlers.get(type);
|
|
545
|
+
if (!handlersOfType) {
|
|
546
|
+
handlersOfType = [];
|
|
547
|
+
this.fHandlers.set(type, handlersOfType);
|
|
548
|
+
}
|
|
549
|
+
const genId = this.fLastId++;
|
|
550
|
+
const handler = {
|
|
551
|
+
callback,
|
|
552
|
+
id: genId
|
|
553
|
+
};
|
|
554
|
+
handlersOfType.push(handler);
|
|
555
|
+
return {
|
|
556
|
+
__id: genId,
|
|
557
|
+
__type: type
|
|
558
|
+
};
|
|
559
|
+
}
|
|
560
|
+
/**
|
|
561
|
+
* Waits for single event execution and removes the listener immediately after.
|
|
562
|
+
*
|
|
563
|
+
* @example
|
|
564
|
+
* this.gCart.addItem(product);
|
|
565
|
+
* await this.gEvents.waitFor(CartUpdatedEvent);
|
|
566
|
+
* console.log('here cart updated event is already called');
|
|
567
|
+
*
|
|
568
|
+
* @param type type of event to wait for
|
|
569
|
+
* @param timeout timeout param in ms - if event is not thrown until this time, it'll reject. passing null disables the timeout
|
|
570
|
+
* @returns promise with event data that resolves when event is finally called
|
|
571
|
+
*/
|
|
572
|
+
waitFor(type, timeout = 10 * 1e3) {
|
|
573
|
+
return new Promise((resolve, reject) => {
|
|
574
|
+
let waitTimeout;
|
|
575
|
+
const eventId = this.on(type, (data) => {
|
|
576
|
+
this.off(eventId);
|
|
577
|
+
resolve(data);
|
|
578
|
+
if (waitTimeout) clearTimeout(waitTimeout);
|
|
579
|
+
});
|
|
580
|
+
if (timeout !== null) waitTimeout = setTimeout(() => {
|
|
581
|
+
this.off(eventId);
|
|
582
|
+
reject(/* @__PURE__ */ new Error(`Waiting for event timeout - ${type.name}`));
|
|
583
|
+
}, timeout);
|
|
584
|
+
});
|
|
585
|
+
}
|
|
586
|
+
/**
|
|
587
|
+
* Removes listener from particular event.
|
|
588
|
+
* @param eventId eventId returned from .on() method.
|
|
589
|
+
* @throws Error if event was not registered
|
|
590
|
+
*/
|
|
591
|
+
off(eventId) {
|
|
592
|
+
const type = eventId.__type;
|
|
593
|
+
const handlersOfType = this.fHandlers.get(type);
|
|
594
|
+
if (!handlersOfType) throw new Error("Trying to unbind event that was not bound.");
|
|
595
|
+
const index = handlersOfType.findIndex((handler) => handler.id === eventId.__id);
|
|
596
|
+
if (index === -1) throw new Error("Trying to unbind event that was not bound.");
|
|
597
|
+
handlersOfType.splice(index, 1);
|
|
598
|
+
}
|
|
599
|
+
/**
|
|
600
|
+
* Triggers event, calling all listener callbacks. Will return Promise of number,
|
|
601
|
+
* that is resolved when all asynchronous listeners are called.
|
|
602
|
+
* @param type type of trigger, simple class
|
|
603
|
+
* @param data data which will be passed to listeners, based on event class
|
|
604
|
+
* @return number of listeners that were notified
|
|
605
|
+
*/
|
|
606
|
+
async trigger(type, data) {
|
|
607
|
+
const handlersOfType = this.fHandlers.get(type);
|
|
608
|
+
if (!handlersOfType) return 0;
|
|
609
|
+
const toProcessHandlers = [...handlersOfType];
|
|
610
|
+
const promises = toProcessHandlers.map((handler) => {
|
|
611
|
+
const instance = this.objectToClass(type, data);
|
|
612
|
+
const result = handler.callback(instance);
|
|
613
|
+
return result instanceof Promise ? result : Promise.resolve();
|
|
614
|
+
});
|
|
615
|
+
await Promise.all(promises);
|
|
616
|
+
return toProcessHandlers.length;
|
|
617
|
+
}
|
|
618
|
+
/**
|
|
619
|
+
* Converts plain object to it's class equivalent.
|
|
620
|
+
* It's NOT class-transformer, it performs basic key assigment.
|
|
621
|
+
*
|
|
622
|
+
* @param ClassConstructor event constructor
|
|
623
|
+
* @param data event data to be mapped to constructor
|
|
624
|
+
* @return class type of event
|
|
625
|
+
*/
|
|
626
|
+
objectToClass(ClassConstructor, data) {
|
|
627
|
+
const instance = new ClassConstructor();
|
|
628
|
+
if (data) for (const key of Object.keys(data)) {
|
|
629
|
+
const rawInstance = instance;
|
|
630
|
+
const rawData = data;
|
|
631
|
+
rawInstance[key] = rawData[key];
|
|
632
|
+
}
|
|
633
|
+
return instance;
|
|
634
|
+
}
|
|
635
|
+
};
|
|
636
|
+
|
|
637
|
+
//#endregion
|
|
638
|
+
//#region src/Services/Router/Router.ts
|
|
639
|
+
var import_decorate$16 = /* @__PURE__ */ __toESM(require_decorate(), 1);
|
|
640
|
+
/**
|
|
641
|
+
* Router service responsible for managing application routes
|
|
642
|
+
*
|
|
643
|
+
* This class provides functionality to initialize the router,
|
|
644
|
+
* register routes, and resolve incoming requests to their
|
|
645
|
+
* appropriate handlers.
|
|
646
|
+
*/
|
|
647
|
+
var Router = class {
|
|
648
|
+
/**
|
|
649
|
+
* Service for triggering application hooks
|
|
650
|
+
*/
|
|
651
|
+
gHooksService;
|
|
652
|
+
/**
|
|
653
|
+
* Internal router context that stores all registered routes
|
|
654
|
+
* @private
|
|
655
|
+
*/
|
|
656
|
+
fRouterContext;
|
|
657
|
+
/**
|
|
658
|
+
* Registers a new route in the router
|
|
659
|
+
*
|
|
660
|
+
* @param {RouterTypes.Route} route - The route configuration to add
|
|
661
|
+
* @throws {Error} If router is not initialized
|
|
662
|
+
*/
|
|
663
|
+
addRoute(route) {
|
|
664
|
+
if (!this.fRouterContext) throw new Error("Router not initialized. Please call init() before adding routes.");
|
|
665
|
+
addRoute(this.fRouterContext, route.method.toUpperCase(), route.path, route.handler);
|
|
583
666
|
}
|
|
584
667
|
/**
|
|
585
|
-
*
|
|
586
|
-
*
|
|
587
|
-
*
|
|
588
|
-
*
|
|
589
|
-
* 2. Apply route actions (status codes, redirects, etc.)
|
|
590
|
-
* 3. Resolve handler arguments
|
|
591
|
-
* 4. Execute the route handler
|
|
592
|
-
* 5. Execute "after" middlewares
|
|
593
|
-
* 6. Format and return the final response
|
|
594
|
-
*
|
|
595
|
-
* @param {Request} request - The incoming HTTP request
|
|
596
|
-
* @param {RouterTypes.RouteMatched<RouterTypes.RouterHandler>} route - The matched route with handler data
|
|
597
|
-
* @returns {Promise<Response>} The HTTP response
|
|
668
|
+
* Initializes the router and triggers related hooks
|
|
669
|
+
*
|
|
670
|
+
* This method creates a new router context and triggers
|
|
671
|
+
* the before and after initialization hooks.
|
|
598
672
|
*/
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
afterMiddlewares: []
|
|
604
|
-
} } = route.data;
|
|
605
|
-
let fakeResponse = new FastResponse(void 0, { headers: { "Content-Type": request.headers.get("Content-Type") ?? "application/json" } });
|
|
606
|
-
const resolvedArgs = args.length > 0 ? await this.gMetadataResolver.resolveArgs(args, {
|
|
607
|
-
...route,
|
|
608
|
-
request,
|
|
609
|
-
response: fakeResponse
|
|
610
|
-
}) : [];
|
|
611
|
-
if (middlewares.beforeMiddlewares.length > 0) for await (const hook of middlewares.beforeMiddlewares) try {
|
|
612
|
-
const hookResponse = await hook.middleware.onRequest?.(request, fakeResponse, {
|
|
613
|
-
middlewareArgs: hook.args,
|
|
614
|
-
methodArgs: resolvedArgs
|
|
615
|
-
});
|
|
616
|
-
if (hookResponse instanceof Response) return hookResponse;
|
|
617
|
-
} catch (error) {
|
|
618
|
-
const internalError = this.gContainer.get(ErrorHandlerProvider).handleError(error);
|
|
619
|
-
if (internalError instanceof Response) return internalError;
|
|
620
|
-
}
|
|
621
|
-
for (const action of actions) {
|
|
622
|
-
const actionResponse = action.handler(request, fakeResponse);
|
|
623
|
-
if (actionResponse !== null) fakeResponse = this.processOverrideResponse(actionResponse, fakeResponse);
|
|
624
|
-
}
|
|
625
|
-
let handlerResponse = instance[propertyName].call(instance, ...resolvedArgs?.map((a) => a.resolved) ?? []);
|
|
626
|
-
if (handlerResponse instanceof Promise) handlerResponse = await handlerResponse;
|
|
627
|
-
if (middlewares.afterMiddlewares.length > 0) for await (const hook of middlewares.afterMiddlewares) try {
|
|
628
|
-
const hookResponse = await hook.middleware.onResponse?.(request, fakeResponse, handlerResponse);
|
|
629
|
-
if (hookResponse !== null) fakeResponse = this.processOverrideResponse(hookResponse, fakeResponse);
|
|
630
|
-
} catch (error) {
|
|
631
|
-
const internalError = this.gContainer.get(ErrorHandlerProvider).handleError(error);
|
|
632
|
-
if (internalError instanceof Response) return internalError;
|
|
633
|
-
}
|
|
634
|
-
const body = fakeResponse?.body ?? JSON.stringify(handlerResponse);
|
|
635
|
-
const response = new Response(body, {
|
|
636
|
-
status: fakeResponse.status ?? 200,
|
|
637
|
-
statusText: fakeResponse.statusText ?? "OK",
|
|
638
|
-
headers: fakeResponse.headers
|
|
639
|
-
});
|
|
640
|
-
return response;
|
|
641
|
-
} catch (error) {
|
|
642
|
-
return this.gContainer.get(ErrorHandlerProvider).handleError(error);
|
|
643
|
-
}
|
|
673
|
+
initialize() {
|
|
674
|
+
this.gHooksService.trigger(RouterBeforeInitHook);
|
|
675
|
+
this.fRouterContext = createRouter();
|
|
676
|
+
this.gHooksService.trigger(RouterAfterInitHook);
|
|
644
677
|
}
|
|
645
678
|
/**
|
|
646
|
-
*
|
|
647
|
-
*
|
|
648
|
-
*
|
|
649
|
-
*
|
|
650
|
-
* - If ResponseInit is provided, it's merged with the base response
|
|
651
|
-
*
|
|
652
|
-
* @param {Response | ResponseInit} response - The response or response options to apply
|
|
653
|
-
* @param {Response} [base] - The base response to extend (optional)
|
|
654
|
-
* @returns {Response} The processed response with applied overrides
|
|
655
|
-
* @private
|
|
679
|
+
* Resolves a route based on the HTTP method and path
|
|
680
|
+
*
|
|
681
|
+
* @param {RouterTypes.RouteFind} route - The route to resolve
|
|
682
|
+
* @returns {RouterTypes.RouteMatched<RouterTypes.RouterHandler> | undefined} The matched route or undefined if no match found
|
|
656
683
|
*/
|
|
657
|
-
|
|
658
|
-
let
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
status: responseInit?.status ?? fakeResponse.status,
|
|
664
|
-
headers: responseInit?.headers ?? fakeResponse.headers,
|
|
665
|
-
statusText: responseInit?.statusText ?? fakeResponse.statusText
|
|
666
|
-
});
|
|
667
|
-
}
|
|
668
|
-
return fakeResponse;
|
|
684
|
+
resolve(route) {
|
|
685
|
+
let url = route.path;
|
|
686
|
+
try {
|
|
687
|
+
url = new URL(route.path).pathname;
|
|
688
|
+
} catch {}
|
|
689
|
+
return findRoute(this.fRouterContext, route.method.toUpperCase(), url);
|
|
669
690
|
}
|
|
670
691
|
};
|
|
671
|
-
(0, import_decorate$16.default)([Inject(
|
|
672
|
-
(0, import_decorate$16.default)([Inject(Container)], RequestHandler.prototype, "gContainer", void 0);
|
|
673
|
-
(0, import_decorate$16.default)([Inject(GlobalMiddlewareRegistry)], RequestHandler.prototype, "gGlobalMiddlewareRegistry", void 0);
|
|
692
|
+
(0, import_decorate$16.default)([Inject(HooksService)], Router.prototype, "gHooksService", void 0);
|
|
674
693
|
|
|
675
694
|
//#endregion
|
|
676
695
|
//#region src/Utils/Mine.ts
|
|
@@ -694,7 +713,7 @@ const mime = { getType(ext) {
|
|
|
694
713
|
//#region src/Services/Router/StaticRequestHandler.ts
|
|
695
714
|
/**
|
|
696
715
|
* Handles serving static files over HTTP
|
|
697
|
-
*
|
|
716
|
+
*
|
|
698
717
|
* The StaticRequestHandler is responsible for:
|
|
699
718
|
* - Serving static files from configured directories
|
|
700
719
|
* - Setting appropriate content types and headers
|
|
@@ -708,7 +727,7 @@ var StaticRequestHandler = class {
|
|
|
708
727
|
fOptions;
|
|
709
728
|
/**
|
|
710
729
|
* Initializes the static server with the given options
|
|
711
|
-
*
|
|
730
|
+
*
|
|
712
731
|
* @param {ConfigTypes.ServerOptions['static']} options - The options for the static server
|
|
713
732
|
* @returns {void}
|
|
714
733
|
*/
|
|
@@ -717,7 +736,7 @@ var StaticRequestHandler = class {
|
|
|
717
736
|
}
|
|
718
737
|
/**
|
|
719
738
|
* Handles HTTP requests for static files
|
|
720
|
-
*
|
|
739
|
+
*
|
|
721
740
|
* @param {Request} request - The incoming HTTP request
|
|
722
741
|
* @returns {Promise<void | Response>} A promise that resolves to void or a Response object
|
|
723
742
|
*/
|
|
@@ -742,7 +761,7 @@ var StaticRequestHandler = class {
|
|
|
742
761
|
}
|
|
743
762
|
/**
|
|
744
763
|
* Serves a static file and returns a Response object
|
|
745
|
-
*
|
|
764
|
+
*
|
|
746
765
|
* @param {string} path - The path to the file to serve
|
|
747
766
|
* @param {any} stats - The stats object for the file
|
|
748
767
|
* @returns {Promise<Response>} A promise that resolves to a Response object
|
|
@@ -769,7 +788,7 @@ var StaticRequestHandler = class {
|
|
|
769
788
|
var import_decorate$15 = /* @__PURE__ */ __toESM(require_decorate(), 1);
|
|
770
789
|
/**
|
|
771
790
|
* HTTP server implementation for handling incoming web requests
|
|
772
|
-
*
|
|
791
|
+
*
|
|
773
792
|
* This class is responsible for:
|
|
774
793
|
* - Initializing and managing the HTTP server
|
|
775
794
|
* - Routing incoming requests to appropriate handlers
|
|
@@ -804,7 +823,7 @@ var HttpServer = class {
|
|
|
804
823
|
fPlugins = [];
|
|
805
824
|
/**
|
|
806
825
|
* Adds a plugin to the HTTP server
|
|
807
|
-
*
|
|
826
|
+
*
|
|
808
827
|
* @param {ServerPlugin} plugin - The plugin to add
|
|
809
828
|
* @returns {void}
|
|
810
829
|
*/
|
|
@@ -813,7 +832,7 @@ var HttpServer = class {
|
|
|
813
832
|
}
|
|
814
833
|
/**
|
|
815
834
|
* Initializes the HTTP server and starts listening for requests
|
|
816
|
-
*
|
|
835
|
+
*
|
|
817
836
|
* @returns {Promise<void>} A promise that resolves when the server is ready
|
|
818
837
|
*/
|
|
819
838
|
async initialize(config) {
|
|
@@ -835,7 +854,7 @@ var HttpServer = class {
|
|
|
835
854
|
}
|
|
836
855
|
/**
|
|
837
856
|
* Listens for incoming requests on the HTTP server
|
|
838
|
-
*
|
|
857
|
+
*
|
|
839
858
|
* @returns {Promise<void>} A promise that resolves when the server is ready to listen
|
|
840
859
|
*/
|
|
841
860
|
async listen() {
|
|
@@ -844,12 +863,12 @@ var HttpServer = class {
|
|
|
844
863
|
}
|
|
845
864
|
/**
|
|
846
865
|
* Processes an incoming HTTP request
|
|
847
|
-
*
|
|
866
|
+
*
|
|
848
867
|
* This method:
|
|
849
868
|
* 1. Resolves the route for the request
|
|
850
869
|
* 2. Returns a 404 response if no route is found
|
|
851
870
|
* 3. Delegates to the request handler for matched routes
|
|
852
|
-
*
|
|
871
|
+
*
|
|
853
872
|
* @param {Request} request - The incoming HTTP request
|
|
854
873
|
* @returns {Promise<Response>} The HTTP response
|
|
855
874
|
* @private
|
|
@@ -877,36 +896,66 @@ var HttpServer = class {
|
|
|
877
896
|
(0, import_decorate$15.default)([Inject(StaticRequestHandler)], HttpServer.prototype, "gStaticRequestHandler", void 0);
|
|
878
897
|
|
|
879
898
|
//#endregion
|
|
880
|
-
//#region src/Services/
|
|
899
|
+
//#region src/Services/Plugins/BasePlugin.ts
|
|
881
900
|
/**
|
|
882
|
-
*
|
|
883
|
-
* This class provides a centralized way to access and modify runtime configuration settings.
|
|
901
|
+
* Represents a Plugin.
|
|
884
902
|
*/
|
|
885
|
-
var
|
|
903
|
+
var BasePlugin = class {
|
|
886
904
|
/**
|
|
887
|
-
*
|
|
888
|
-
* @private
|
|
905
|
+
* The name of the plugin.
|
|
889
906
|
*/
|
|
890
|
-
|
|
907
|
+
name;
|
|
891
908
|
/**
|
|
892
|
-
*
|
|
893
|
-
* @
|
|
909
|
+
* Uses the plugin with the given app.
|
|
910
|
+
* @param {App} app - The application instance.
|
|
911
|
+
* @returns {void | Promise<void>} - A void or a promise that resolves to void.
|
|
894
912
|
*/
|
|
895
|
-
|
|
896
|
-
|
|
913
|
+
use(app, options) {}
|
|
914
|
+
};
|
|
915
|
+
|
|
916
|
+
//#endregion
|
|
917
|
+
//#region src/Services/Plugins/PluginsRegistry.ts
|
|
918
|
+
var import_decorate$14 = /* @__PURE__ */ __toESM(require_decorate(), 1);
|
|
919
|
+
var PluginsRegistry = class {
|
|
920
|
+
gContainer;
|
|
921
|
+
/** Holds the list of plugins */
|
|
922
|
+
fPlugins = /* @__PURE__ */ new Map();
|
|
923
|
+
/**
|
|
924
|
+
* Registers a plugin.
|
|
925
|
+
*
|
|
926
|
+
* @param {Plugin} plugin - The plugin to register.
|
|
927
|
+
* @param {unknown} options - The options to pass to the plugin.
|
|
928
|
+
*/
|
|
929
|
+
register(plugin, options) {
|
|
930
|
+
const instance = this.gContainer.resolve(plugin);
|
|
931
|
+
if (!instance.name) throw new Error("Plugin must have a name");
|
|
932
|
+
this.fPlugins.set(instance.name, {
|
|
933
|
+
instance,
|
|
934
|
+
options
|
|
935
|
+
});
|
|
897
936
|
}
|
|
898
937
|
/**
|
|
899
|
-
*
|
|
900
|
-
*
|
|
938
|
+
* Gets the list of registered plugins.
|
|
939
|
+
*
|
|
940
|
+
* @returns {Plugin[]} The list of registered plugins.
|
|
901
941
|
*/
|
|
902
|
-
|
|
903
|
-
this.
|
|
942
|
+
get plugins() {
|
|
943
|
+
return [...this.fPlugins.values()].map((plugin) => plugin.instance);
|
|
944
|
+
}
|
|
945
|
+
/**
|
|
946
|
+
* Resolves the plugins.
|
|
947
|
+
*
|
|
948
|
+
* @param {App} app - The application instance.
|
|
949
|
+
*/
|
|
950
|
+
async init(app) {
|
|
951
|
+
for (const { instance, options } of this.fPlugins.values()) await instance.use(app, options);
|
|
904
952
|
}
|
|
905
953
|
};
|
|
954
|
+
(0, import_decorate$14.default)([Inject(Container)], PluginsRegistry.prototype, "gContainer", void 0);
|
|
906
955
|
|
|
907
956
|
//#endregion
|
|
908
957
|
//#region src/Common/App.ts
|
|
909
|
-
var import_decorate$
|
|
958
|
+
var import_decorate$13 = /* @__PURE__ */ __toESM(require_decorate(), 1);
|
|
910
959
|
/**
|
|
911
960
|
* Represents the main application class.
|
|
912
961
|
*/
|
|
@@ -986,7 +1035,7 @@ var App = class {
|
|
|
986
1035
|
/**
|
|
987
1036
|
* Handles an incoming HTTP request.
|
|
988
1037
|
* This method is an adapter for HttpServer.handleRequest method.
|
|
989
|
-
*
|
|
1038
|
+
*
|
|
990
1039
|
* @param {Request} request - The incoming HTTP request
|
|
991
1040
|
* @returns {Promise<Response>} The HTTP response
|
|
992
1041
|
*/
|
|
@@ -1002,42 +1051,11 @@ var App = class {
|
|
|
1002
1051
|
await this.gPluginsRegistry.init(this);
|
|
1003
1052
|
}
|
|
1004
1053
|
};
|
|
1005
|
-
(0, import_decorate$
|
|
1006
|
-
(0, import_decorate$
|
|
1007
|
-
(0, import_decorate$
|
|
1008
|
-
(0, import_decorate$
|
|
1009
|
-
(0, import_decorate$
|
|
1010
|
-
|
|
1011
|
-
//#endregion
|
|
1012
|
-
//#region src/Services/Validation/ValidationProvider.ts
|
|
1013
|
-
/**
|
|
1014
|
-
* Abstract class representing a validation provider
|
|
1015
|
-
* Provides a common interface for different validation implementations
|
|
1016
|
-
*
|
|
1017
|
-
* @abstract
|
|
1018
|
-
* @class ValidationProvider
|
|
1019
|
-
*/
|
|
1020
|
-
var ValidationProvider = class {};
|
|
1021
|
-
|
|
1022
|
-
//#endregion
|
|
1023
|
-
//#region src/Services/Validation/StandardSchemaValidationProvider.ts
|
|
1024
|
-
/**
|
|
1025
|
-
* StandardSchemaValidationProvider implements validation using StandardSchema schema validation
|
|
1026
|
-
* @see https://github.com/standard-schema/standard-schema
|
|
1027
|
-
* @class
|
|
1028
|
-
* @implements {ValidationProvider}
|
|
1029
|
-
*/
|
|
1030
|
-
var StandardSchemaValidationProvider = class {
|
|
1031
|
-
/**
|
|
1032
|
-
* Validates data against a schema
|
|
1033
|
-
* @param {ValidationTypes.Schema} schema - The schema to validate against
|
|
1034
|
-
* @param {ValidationTypes.Input} data - The data to validate
|
|
1035
|
-
* @return {ValidationTypes.Result | Promise<ValidationTypes.Result>} The validation result
|
|
1036
|
-
*/
|
|
1037
|
-
validate(schema, data) {
|
|
1038
|
-
return schema["~standard"].validate(data);
|
|
1039
|
-
}
|
|
1040
|
-
};
|
|
1054
|
+
(0, import_decorate$13.default)([Inject(Router)], App.prototype, "gRouter", void 0);
|
|
1055
|
+
(0, import_decorate$13.default)([Inject(PluginsRegistry)], App.prototype, "gPluginsRegistry", void 0);
|
|
1056
|
+
(0, import_decorate$13.default)([Inject(HttpServer)], App.prototype, "gHttpServer", void 0);
|
|
1057
|
+
(0, import_decorate$13.default)([Inject(StaticRequestHandler)], App.prototype, "gStaticRequestHandler", void 0);
|
|
1058
|
+
(0, import_decorate$13.default)([Inject(RuntimeConfig)], App.prototype, "gRuntimeConfig", void 0);
|
|
1041
1059
|
|
|
1042
1060
|
//#endregion
|
|
1043
1061
|
//#region src/Errors/Http/InternalServerError.ts
|
|
@@ -1064,7 +1082,7 @@ var InternalServerError = class InternalServerError extends HttpError {
|
|
|
1064
1082
|
|
|
1065
1083
|
//#endregion
|
|
1066
1084
|
//#region src/Services/ErrorHandler/DefaultErrorHandlerProvider.ts
|
|
1067
|
-
var import_decorate$
|
|
1085
|
+
var import_decorate$12 = /* @__PURE__ */ __toESM(require_decorate(), 1);
|
|
1068
1086
|
/**
|
|
1069
1087
|
* Default error handler provider
|
|
1070
1088
|
*
|
|
@@ -1086,7 +1104,38 @@ var DefaultErrorHandlerProvider = class extends ErrorHandlerProvider {
|
|
|
1086
1104
|
return new FastResponse(JSON.stringify({ ...error?.cause ?? _internalError }, void 0, 2), { status });
|
|
1087
1105
|
}
|
|
1088
1106
|
};
|
|
1089
|
-
(0, import_decorate$
|
|
1107
|
+
(0, import_decorate$12.default)([Inject(Logger)], DefaultErrorHandlerProvider.prototype, "gLogger", void 0);
|
|
1108
|
+
|
|
1109
|
+
//#endregion
|
|
1110
|
+
//#region src/Services/Validation/ValidationProvider.ts
|
|
1111
|
+
/**
|
|
1112
|
+
* Abstract class representing a validation provider
|
|
1113
|
+
* Provides a common interface for different validation implementations
|
|
1114
|
+
*
|
|
1115
|
+
* @abstract
|
|
1116
|
+
* @class ValidationProvider
|
|
1117
|
+
*/
|
|
1118
|
+
var ValidationProvider = class {};
|
|
1119
|
+
|
|
1120
|
+
//#endregion
|
|
1121
|
+
//#region src/Services/Validation/StandardSchemaValidationProvider.ts
|
|
1122
|
+
/**
|
|
1123
|
+
* StandardSchemaValidationProvider implements validation using StandardSchema schema validation
|
|
1124
|
+
* @see https://github.com/standard-schema/standard-schema
|
|
1125
|
+
* @class
|
|
1126
|
+
* @implements {ValidationProvider}
|
|
1127
|
+
*/
|
|
1128
|
+
var StandardSchemaValidationProvider = class {
|
|
1129
|
+
/**
|
|
1130
|
+
* Validates data against a schema
|
|
1131
|
+
* @param {ValidationTypes.Schema} schema - The schema to validate against
|
|
1132
|
+
* @param {ValidationTypes.Input} data - The data to validate
|
|
1133
|
+
* @return {ValidationTypes.Result | Promise<ValidationTypes.Result>} The validation result
|
|
1134
|
+
*/
|
|
1135
|
+
validate(schema, data) {
|
|
1136
|
+
return schema["~standard"].validate(data);
|
|
1137
|
+
}
|
|
1138
|
+
};
|
|
1090
1139
|
|
|
1091
1140
|
//#endregion
|
|
1092
1141
|
//#region src/Common/Container.ts
|
|
@@ -1217,7 +1266,7 @@ function defineConfig(config) {
|
|
|
1217
1266
|
|
|
1218
1267
|
//#endregion
|
|
1219
1268
|
//#region src/Middleware/ValidationMiddleware.ts
|
|
1220
|
-
var import_decorate$
|
|
1269
|
+
var import_decorate$11 = /* @__PURE__ */ __toESM(require_decorate(), 1);
|
|
1221
1270
|
/**
|
|
1222
1271
|
* Middleware for validating request data against a schema
|
|
1223
1272
|
* @class ValidationMiddleware
|
|
@@ -1228,6 +1277,7 @@ var import_decorate$12 = /* @__PURE__ */ __toESM(require_decorate(), 1);
|
|
|
1228
1277
|
* await middleware.use(event, { schema: myValidationSchema });
|
|
1229
1278
|
*/
|
|
1230
1279
|
var ValidationMiddleware = class {
|
|
1280
|
+
gLogger;
|
|
1231
1281
|
gValidationProvider;
|
|
1232
1282
|
/**
|
|
1233
1283
|
* Middleware function that processes the HTTP event
|
|
@@ -1239,7 +1289,7 @@ var ValidationMiddleware = class {
|
|
|
1239
1289
|
*/
|
|
1240
1290
|
async onRequest(request, response, args) {
|
|
1241
1291
|
if (!this.gValidationProvider) {
|
|
1242
|
-
|
|
1292
|
+
this.gLogger?.warn("ValidationMiddleware::ValidationProvider", "Validation provider is not registered");
|
|
1243
1293
|
return;
|
|
1244
1294
|
}
|
|
1245
1295
|
const validators = args.methodArgs?.filter((arg) => arg.validate && arg.validationSchema) ?? [];
|
|
@@ -1249,7 +1299,8 @@ var ValidationMiddleware = class {
|
|
|
1249
1299
|
}
|
|
1250
1300
|
}
|
|
1251
1301
|
};
|
|
1252
|
-
(0, import_decorate$
|
|
1302
|
+
(0, import_decorate$11.default)([InjectOptional(Logger)], ValidationMiddleware.prototype, "gLogger", void 0);
|
|
1303
|
+
(0, import_decorate$11.default)([InjectOptional(ValidationProvider)], ValidationMiddleware.prototype, "gValidationProvider", void 0);
|
|
1253
1304
|
|
|
1254
1305
|
//#endregion
|
|
1255
1306
|
//#region src/Utils/Utils.ts
|
|
@@ -1345,7 +1396,7 @@ function Body(options) {
|
|
|
1345
1396
|
|
|
1346
1397
|
//#endregion
|
|
1347
1398
|
//#region src/Decorators/Http/Connect.ts
|
|
1348
|
-
var import_decorate$
|
|
1399
|
+
var import_decorate$10 = /* @__PURE__ */ __toESM(require_decorate(), 1);
|
|
1349
1400
|
/**
|
|
1350
1401
|
* A decorator class for handling HTTP CONNECT requests.
|
|
1351
1402
|
*
|
|
@@ -1384,9 +1435,9 @@ var ConnectDecorator = class extends BaseDecorator {
|
|
|
1384
1435
|
});
|
|
1385
1436
|
}
|
|
1386
1437
|
};
|
|
1387
|
-
(0, import_decorate$
|
|
1388
|
-
(0, import_decorate$
|
|
1389
|
-
(0, import_decorate$
|
|
1438
|
+
(0, import_decorate$10.default)([Inject(Router)], ConnectDecorator.prototype, "gRouter", void 0);
|
|
1439
|
+
(0, import_decorate$10.default)([Inject(RequestHandler)], ConnectDecorator.prototype, "gRequestHandler", void 0);
|
|
1440
|
+
(0, import_decorate$10.default)([Inject(MetadataResolver)], ConnectDecorator.prototype, "gMetadataResolver", void 0);
|
|
1390
1441
|
/**
|
|
1391
1442
|
* A factory function for creating a ConnectDecorator.
|
|
1392
1443
|
*
|
|
@@ -1423,7 +1474,7 @@ function Controller(path) {
|
|
|
1423
1474
|
|
|
1424
1475
|
//#endregion
|
|
1425
1476
|
//#region src/Decorators/Http/Delete.ts
|
|
1426
|
-
var import_decorate$
|
|
1477
|
+
var import_decorate$9 = /* @__PURE__ */ __toESM(require_decorate(), 1);
|
|
1427
1478
|
/**
|
|
1428
1479
|
* A decorator class for handling HTTP DELETE requests.
|
|
1429
1480
|
*
|
|
@@ -1462,9 +1513,9 @@ var DeleteDecorator = class extends BaseDecorator {
|
|
|
1462
1513
|
});
|
|
1463
1514
|
}
|
|
1464
1515
|
};
|
|
1465
|
-
(0, import_decorate$
|
|
1466
|
-
(0, import_decorate$
|
|
1467
|
-
(0, import_decorate$
|
|
1516
|
+
(0, import_decorate$9.default)([Inject(Router)], DeleteDecorator.prototype, "gRouter", void 0);
|
|
1517
|
+
(0, import_decorate$9.default)([Inject(RequestHandler)], DeleteDecorator.prototype, "gRequestHandler", void 0);
|
|
1518
|
+
(0, import_decorate$9.default)([Inject(MetadataResolver)], DeleteDecorator.prototype, "gMetadataResolver", void 0);
|
|
1468
1519
|
/**
|
|
1469
1520
|
* A factory function for creating a DeleteDecorator.
|
|
1470
1521
|
*
|
|
@@ -1480,7 +1531,7 @@ function Delete(path) {
|
|
|
1480
1531
|
|
|
1481
1532
|
//#endregion
|
|
1482
1533
|
//#region src/Decorators/Http/Get.ts
|
|
1483
|
-
var import_decorate$
|
|
1534
|
+
var import_decorate$8 = /* @__PURE__ */ __toESM(require_decorate(), 1);
|
|
1484
1535
|
/**
|
|
1485
1536
|
* A decorator class for handling HTTP GET requests.
|
|
1486
1537
|
*
|
|
@@ -1519,9 +1570,9 @@ var GetDecorator = class extends BaseDecorator {
|
|
|
1519
1570
|
});
|
|
1520
1571
|
}
|
|
1521
1572
|
};
|
|
1522
|
-
(0, import_decorate$
|
|
1523
|
-
(0, import_decorate$
|
|
1524
|
-
(0, import_decorate$
|
|
1573
|
+
(0, import_decorate$8.default)([Inject(Router)], GetDecorator.prototype, "gRouter", void 0);
|
|
1574
|
+
(0, import_decorate$8.default)([Inject(RequestHandler)], GetDecorator.prototype, "gRequestHandler", void 0);
|
|
1575
|
+
(0, import_decorate$8.default)([Inject(MetadataResolver)], GetDecorator.prototype, "gMetadataResolver", void 0);
|
|
1525
1576
|
/**
|
|
1526
1577
|
* A decorator function for handling HTTP GET requests.
|
|
1527
1578
|
*
|
|
@@ -1537,7 +1588,7 @@ function Get(path) {
|
|
|
1537
1588
|
|
|
1538
1589
|
//#endregion
|
|
1539
1590
|
//#region src/Decorators/Http/Head.ts
|
|
1540
|
-
var import_decorate$
|
|
1591
|
+
var import_decorate$7 = /* @__PURE__ */ __toESM(require_decorate(), 1);
|
|
1541
1592
|
/**
|
|
1542
1593
|
* A decorator class for handling HTTP HEAD requests.
|
|
1543
1594
|
*
|
|
@@ -1576,9 +1627,9 @@ var HeadDecorator = class extends BaseDecorator {
|
|
|
1576
1627
|
});
|
|
1577
1628
|
}
|
|
1578
1629
|
};
|
|
1579
|
-
(0, import_decorate$
|
|
1580
|
-
(0, import_decorate$
|
|
1581
|
-
(0, import_decorate$
|
|
1630
|
+
(0, import_decorate$7.default)([Inject(Router)], HeadDecorator.prototype, "gRouter", void 0);
|
|
1631
|
+
(0, import_decorate$7.default)([Inject(RequestHandler)], HeadDecorator.prototype, "gRequestHandler", void 0);
|
|
1632
|
+
(0, import_decorate$7.default)([Inject(MetadataResolver)], HeadDecorator.prototype, "gMetadataResolver", void 0);
|
|
1582
1633
|
/**
|
|
1583
1634
|
* A factory function for creating a HeadDecorator.
|
|
1584
1635
|
*
|
|
@@ -1675,7 +1726,7 @@ function Headers$1() {
|
|
|
1675
1726
|
|
|
1676
1727
|
//#endregion
|
|
1677
1728
|
//#region src/Decorators/Http/Options.ts
|
|
1678
|
-
var import_decorate$
|
|
1729
|
+
var import_decorate$6 = /* @__PURE__ */ __toESM(require_decorate(), 1);
|
|
1679
1730
|
/**
|
|
1680
1731
|
* A decorator class for handling HTTP OPTIONS requests.
|
|
1681
1732
|
*
|
|
@@ -1714,9 +1765,9 @@ var OptionsDecorator = class extends BaseDecorator {
|
|
|
1714
1765
|
});
|
|
1715
1766
|
}
|
|
1716
1767
|
};
|
|
1717
|
-
(0, import_decorate$
|
|
1718
|
-
(0, import_decorate$
|
|
1719
|
-
(0, import_decorate$
|
|
1768
|
+
(0, import_decorate$6.default)([Inject(Router)], OptionsDecorator.prototype, "gRouter", void 0);
|
|
1769
|
+
(0, import_decorate$6.default)([Inject(RequestHandler)], OptionsDecorator.prototype, "gRequestHandler", void 0);
|
|
1770
|
+
(0, import_decorate$6.default)([Inject(MetadataResolver)], OptionsDecorator.prototype, "gMetadataResolver", void 0);
|
|
1720
1771
|
/**
|
|
1721
1772
|
* A factory function for creating an OptionsDecorator.
|
|
1722
1773
|
*
|
|
@@ -1732,7 +1783,7 @@ function Options(path) {
|
|
|
1732
1783
|
|
|
1733
1784
|
//#endregion
|
|
1734
1785
|
//#region src/Decorators/Http/Param.ts
|
|
1735
|
-
var import_decorate$
|
|
1786
|
+
var import_decorate$5 = /* @__PURE__ */ __toESM(require_decorate(), 1);
|
|
1736
1787
|
/**
|
|
1737
1788
|
* This class is responsible for managing parameter decorators.
|
|
1738
1789
|
*
|
|
@@ -1760,7 +1811,7 @@ var ParamDecorator = class extends BaseDecorator {
|
|
|
1760
1811
|
});
|
|
1761
1812
|
}
|
|
1762
1813
|
};
|
|
1763
|
-
(0, import_decorate$
|
|
1814
|
+
(0, import_decorate$5.default)([Inject(MetadataResolver)], ParamDecorator.prototype, "gMetadataResolver", void 0);
|
|
1764
1815
|
/**
|
|
1765
1816
|
* A factory function for creating a ParamDecorator.
|
|
1766
1817
|
*
|
|
@@ -1778,7 +1829,7 @@ function Param(name) {
|
|
|
1778
1829
|
|
|
1779
1830
|
//#endregion
|
|
1780
1831
|
//#region src/Decorators/Http/Patch.ts
|
|
1781
|
-
var import_decorate$
|
|
1832
|
+
var import_decorate$4 = /* @__PURE__ */ __toESM(require_decorate(), 1);
|
|
1782
1833
|
/**
|
|
1783
1834
|
* A decorator class for handling HTTP PATCH requests.
|
|
1784
1835
|
*
|
|
@@ -1817,9 +1868,9 @@ var PatchDecorator = class extends BaseDecorator {
|
|
|
1817
1868
|
});
|
|
1818
1869
|
}
|
|
1819
1870
|
};
|
|
1820
|
-
(0, import_decorate$
|
|
1821
|
-
(0, import_decorate$
|
|
1822
|
-
(0, import_decorate$
|
|
1871
|
+
(0, import_decorate$4.default)([Inject(Router)], PatchDecorator.prototype, "gRouter", void 0);
|
|
1872
|
+
(0, import_decorate$4.default)([Inject(RequestHandler)], PatchDecorator.prototype, "gRequestHandler", void 0);
|
|
1873
|
+
(0, import_decorate$4.default)([Inject(MetadataResolver)], PatchDecorator.prototype, "gMetadataResolver", void 0);
|
|
1823
1874
|
/**
|
|
1824
1875
|
* A factory function for creating a PatchDecorator.
|
|
1825
1876
|
*
|
|
@@ -1835,7 +1886,7 @@ function Patch(path) {
|
|
|
1835
1886
|
|
|
1836
1887
|
//#endregion
|
|
1837
1888
|
//#region src/Decorators/Http/Post.ts
|
|
1838
|
-
var import_decorate$
|
|
1889
|
+
var import_decorate$3 = /* @__PURE__ */ __toESM(require_decorate(), 1);
|
|
1839
1890
|
/**
|
|
1840
1891
|
* A decorator class for handling HTTP POST requests.
|
|
1841
1892
|
*
|
|
@@ -1874,9 +1925,9 @@ var PostDecorator = class extends BaseDecorator {
|
|
|
1874
1925
|
});
|
|
1875
1926
|
}
|
|
1876
1927
|
};
|
|
1877
|
-
(0, import_decorate$
|
|
1878
|
-
(0, import_decorate$
|
|
1879
|
-
(0, import_decorate$
|
|
1928
|
+
(0, import_decorate$3.default)([Inject(Router)], PostDecorator.prototype, "gRouter", void 0);
|
|
1929
|
+
(0, import_decorate$3.default)([Inject(MetadataResolver)], PostDecorator.prototype, "gMetadataResolver", void 0);
|
|
1930
|
+
(0, import_decorate$3.default)([Inject(RequestHandler)], PostDecorator.prototype, "gRequestHandler", void 0);
|
|
1880
1931
|
/**
|
|
1881
1932
|
* A factory function for creating a PostDecorator.
|
|
1882
1933
|
*
|
|
@@ -1892,7 +1943,7 @@ function Post(path) {
|
|
|
1892
1943
|
|
|
1893
1944
|
//#endregion
|
|
1894
1945
|
//#region src/Decorators/Http/Put.ts
|
|
1895
|
-
var import_decorate$
|
|
1946
|
+
var import_decorate$2 = /* @__PURE__ */ __toESM(require_decorate(), 1);
|
|
1896
1947
|
/**
|
|
1897
1948
|
* A decorator class for handling HTTP PUT requests.
|
|
1898
1949
|
*
|
|
@@ -1931,9 +1982,9 @@ var PutDecorator = class extends BaseDecorator {
|
|
|
1931
1982
|
});
|
|
1932
1983
|
}
|
|
1933
1984
|
};
|
|
1934
|
-
(0, import_decorate$
|
|
1935
|
-
(0, import_decorate$
|
|
1936
|
-
(0, import_decorate$
|
|
1985
|
+
(0, import_decorate$2.default)([Inject(Router)], PutDecorator.prototype, "gRouter", void 0);
|
|
1986
|
+
(0, import_decorate$2.default)([Inject(RequestHandler)], PutDecorator.prototype, "gRequestHandler", void 0);
|
|
1987
|
+
(0, import_decorate$2.default)([Inject(MetadataResolver)], PutDecorator.prototype, "gMetadataResolver", void 0);
|
|
1937
1988
|
/**
|
|
1938
1989
|
* A factory function for creating a PutDecorator.
|
|
1939
1990
|
*
|
|
@@ -2125,7 +2176,7 @@ function Response$1() {
|
|
|
2125
2176
|
|
|
2126
2177
|
//#endregion
|
|
2127
2178
|
//#region src/Decorators/Http/Trace.ts
|
|
2128
|
-
var import_decorate$
|
|
2179
|
+
var import_decorate$1 = /* @__PURE__ */ __toESM(require_decorate(), 1);
|
|
2129
2180
|
/**
|
|
2130
2181
|
* A decorator class for handling HTTP TRACE requests.
|
|
2131
2182
|
*
|
|
@@ -2164,9 +2215,9 @@ var TraceDecorator = class extends BaseDecorator {
|
|
|
2164
2215
|
});
|
|
2165
2216
|
}
|
|
2166
2217
|
};
|
|
2167
|
-
(0, import_decorate$
|
|
2168
|
-
(0, import_decorate$
|
|
2169
|
-
(0, import_decorate$
|
|
2218
|
+
(0, import_decorate$1.default)([Inject(Router)], TraceDecorator.prototype, "gRouter", void 0);
|
|
2219
|
+
(0, import_decorate$1.default)([Inject(RequestHandler)], TraceDecorator.prototype, "gRequestHandler", void 0);
|
|
2220
|
+
(0, import_decorate$1.default)([Inject(MetadataResolver)], TraceDecorator.prototype, "gMetadataResolver", void 0);
|
|
2170
2221
|
/**
|
|
2171
2222
|
* A factory function for creating a TraceDecorator.
|
|
2172
2223
|
*
|
|
@@ -2215,24 +2266,84 @@ function SetHeader(key, value) {
|
|
|
2215
2266
|
});
|
|
2216
2267
|
}
|
|
2217
2268
|
|
|
2269
|
+
//#endregion
|
|
2270
|
+
//#region src/Types/HttpTypes.ts
|
|
2271
|
+
let HTTPStatus = /* @__PURE__ */ function(HTTPStatus$1) {
|
|
2272
|
+
HTTPStatus$1[HTTPStatus$1["CONTINUE"] = 100] = "CONTINUE";
|
|
2273
|
+
HTTPStatus$1[HTTPStatus$1["SWITCHING_PROTOCOLS"] = 101] = "SWITCHING_PROTOCOLS";
|
|
2274
|
+
HTTPStatus$1[HTTPStatus$1["PROCESSING"] = 102] = "PROCESSING";
|
|
2275
|
+
HTTPStatus$1[HTTPStatus$1["OK"] = 200] = "OK";
|
|
2276
|
+
HTTPStatus$1[HTTPStatus$1["CREATED"] = 201] = "CREATED";
|
|
2277
|
+
HTTPStatus$1[HTTPStatus$1["ACCEPTED"] = 202] = "ACCEPTED";
|
|
2278
|
+
HTTPStatus$1[HTTPStatus$1["NON_AUTHORITATIVE_INFORMATION"] = 203] = "NON_AUTHORITATIVE_INFORMATION";
|
|
2279
|
+
HTTPStatus$1[HTTPStatus$1["NO_CONTENT"] = 204] = "NO_CONTENT";
|
|
2280
|
+
HTTPStatus$1[HTTPStatus$1["RESET_CONTENT"] = 205] = "RESET_CONTENT";
|
|
2281
|
+
HTTPStatus$1[HTTPStatus$1["PARTIAL_CONTENT"] = 206] = "PARTIAL_CONTENT";
|
|
2282
|
+
HTTPStatus$1[HTTPStatus$1["MULTI_STATUS"] = 207] = "MULTI_STATUS";
|
|
2283
|
+
HTTPStatus$1[HTTPStatus$1["ALREADY_REPORTED"] = 208] = "ALREADY_REPORTED";
|
|
2284
|
+
HTTPStatus$1[HTTPStatus$1["IM_USED"] = 226] = "IM_USED";
|
|
2285
|
+
HTTPStatus$1[HTTPStatus$1["MULTIPLE_CHOICES"] = 300] = "MULTIPLE_CHOICES";
|
|
2286
|
+
HTTPStatus$1[HTTPStatus$1["MOVED_PERMANENTLY"] = 301] = "MOVED_PERMANENTLY";
|
|
2287
|
+
HTTPStatus$1[HTTPStatus$1["FOUND"] = 302] = "FOUND";
|
|
2288
|
+
HTTPStatus$1[HTTPStatus$1["SEE_OTHER"] = 303] = "SEE_OTHER";
|
|
2289
|
+
HTTPStatus$1[HTTPStatus$1["NOT_MODIFIED"] = 304] = "NOT_MODIFIED";
|
|
2290
|
+
HTTPStatus$1[HTTPStatus$1["USE_PROXY"] = 305] = "USE_PROXY";
|
|
2291
|
+
HTTPStatus$1[HTTPStatus$1["TEMPORARY_REDIRECT"] = 307] = "TEMPORARY_REDIRECT";
|
|
2292
|
+
HTTPStatus$1[HTTPStatus$1["PERMANENT_REDIRECT"] = 308] = "PERMANENT_REDIRECT";
|
|
2293
|
+
HTTPStatus$1[HTTPStatus$1["BAD_REQUEST"] = 400] = "BAD_REQUEST";
|
|
2294
|
+
HTTPStatus$1[HTTPStatus$1["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
|
|
2295
|
+
HTTPStatus$1[HTTPStatus$1["PAYMENT_REQUIRED"] = 402] = "PAYMENT_REQUIRED";
|
|
2296
|
+
HTTPStatus$1[HTTPStatus$1["FORBIDDEN"] = 403] = "FORBIDDEN";
|
|
2297
|
+
HTTPStatus$1[HTTPStatus$1["NOT_FOUND"] = 404] = "NOT_FOUND";
|
|
2298
|
+
HTTPStatus$1[HTTPStatus$1["METHOD_NOT_ALLOWED"] = 405] = "METHOD_NOT_ALLOWED";
|
|
2299
|
+
HTTPStatus$1[HTTPStatus$1["NOT_ACCEPTABLE"] = 406] = "NOT_ACCEPTABLE";
|
|
2300
|
+
HTTPStatus$1[HTTPStatus$1["PROXY_AUTHENTICATION_REQUIRED"] = 407] = "PROXY_AUTHENTICATION_REQUIRED";
|
|
2301
|
+
HTTPStatus$1[HTTPStatus$1["REQUEST_TIMEOUT"] = 408] = "REQUEST_TIMEOUT";
|
|
2302
|
+
HTTPStatus$1[HTTPStatus$1["CONFLICT"] = 409] = "CONFLICT";
|
|
2303
|
+
HTTPStatus$1[HTTPStatus$1["GONE"] = 410] = "GONE";
|
|
2304
|
+
HTTPStatus$1[HTTPStatus$1["LENGTH_REQUIRED"] = 411] = "LENGTH_REQUIRED";
|
|
2305
|
+
HTTPStatus$1[HTTPStatus$1["PRECONDITION_FAILED"] = 412] = "PRECONDITION_FAILED";
|
|
2306
|
+
HTTPStatus$1[HTTPStatus$1["PAYLOAD_TOO_LARGE"] = 413] = "PAYLOAD_TOO_LARGE";
|
|
2307
|
+
HTTPStatus$1[HTTPStatus$1["URI_TOO_LONG"] = 414] = "URI_TOO_LONG";
|
|
2308
|
+
HTTPStatus$1[HTTPStatus$1["UNSUPPORTED_MEDIA_TYPE"] = 415] = "UNSUPPORTED_MEDIA_TYPE";
|
|
2309
|
+
HTTPStatus$1[HTTPStatus$1["RANGE_NOT_SATISFIABLE"] = 416] = "RANGE_NOT_SATISFIABLE";
|
|
2310
|
+
HTTPStatus$1[HTTPStatus$1["EXPECTATION_FAILED"] = 417] = "EXPECTATION_FAILED";
|
|
2311
|
+
HTTPStatus$1[HTTPStatus$1["I_AM_A_TEAPOT"] = 418] = "I_AM_A_TEAPOT";
|
|
2312
|
+
HTTPStatus$1[HTTPStatus$1["MISDIRECTED_REQUEST"] = 421] = "MISDIRECTED_REQUEST";
|
|
2313
|
+
HTTPStatus$1[HTTPStatus$1["UNPROCESSABLE_ENTITY"] = 422] = "UNPROCESSABLE_ENTITY";
|
|
2314
|
+
HTTPStatus$1[HTTPStatus$1["LOCKED"] = 423] = "LOCKED";
|
|
2315
|
+
HTTPStatus$1[HTTPStatus$1["FAILED_DEPENDENCY"] = 424] = "FAILED_DEPENDENCY";
|
|
2316
|
+
HTTPStatus$1[HTTPStatus$1["TOO_EARLY"] = 425] = "TOO_EARLY";
|
|
2317
|
+
HTTPStatus$1[HTTPStatus$1["UPGRADE_REQUIRED"] = 426] = "UPGRADE_REQUIRED";
|
|
2318
|
+
HTTPStatus$1[HTTPStatus$1["PRECONDITION_REQUIRED"] = 428] = "PRECONDITION_REQUIRED";
|
|
2319
|
+
HTTPStatus$1[HTTPStatus$1["TOO_MANY_REQUESTS"] = 429] = "TOO_MANY_REQUESTS";
|
|
2320
|
+
HTTPStatus$1[HTTPStatus$1["REQUEST_HEADER_FIELDS_TOO_LARGE"] = 431] = "REQUEST_HEADER_FIELDS_TOO_LARGE";
|
|
2321
|
+
HTTPStatus$1[HTTPStatus$1["UNAVAILABLE_FOR_LEGAL_REASONS"] = 451] = "UNAVAILABLE_FOR_LEGAL_REASONS";
|
|
2322
|
+
HTTPStatus$1[HTTPStatus$1["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
|
|
2323
|
+
HTTPStatus$1[HTTPStatus$1["NOT_IMPLEMENTED"] = 501] = "NOT_IMPLEMENTED";
|
|
2324
|
+
HTTPStatus$1[HTTPStatus$1["BAD_GATEWAY"] = 502] = "BAD_GATEWAY";
|
|
2325
|
+
HTTPStatus$1[HTTPStatus$1["SERVICE_UNAVAILABLE"] = 503] = "SERVICE_UNAVAILABLE";
|
|
2326
|
+
HTTPStatus$1[HTTPStatus$1["GATEWAY_TIMEOUT"] = 504] = "GATEWAY_TIMEOUT";
|
|
2327
|
+
HTTPStatus$1[HTTPStatus$1["HTTP_VERSION_NOT_SUPPORTED"] = 505] = "HTTP_VERSION_NOT_SUPPORTED";
|
|
2328
|
+
HTTPStatus$1[HTTPStatus$1["VARIANT_ALSO_NEGOTIATES"] = 506] = "VARIANT_ALSO_NEGOTIATES";
|
|
2329
|
+
HTTPStatus$1[HTTPStatus$1["INSUFFICIENT_STORAGE"] = 507] = "INSUFFICIENT_STORAGE";
|
|
2330
|
+
HTTPStatus$1[HTTPStatus$1["LOOP_DETECTED"] = 508] = "LOOP_DETECTED";
|
|
2331
|
+
HTTPStatus$1[HTTPStatus$1["NOT_EXTENDED"] = 510] = "NOT_EXTENDED";
|
|
2332
|
+
HTTPStatus$1[HTTPStatus$1["NETWORK_AUTHENTICATION_REQUIRED"] = 511] = "NETWORK_AUTHENTICATION_REQUIRED";
|
|
2333
|
+
return HTTPStatus$1;
|
|
2334
|
+
}({});
|
|
2335
|
+
|
|
2218
2336
|
//#endregion
|
|
2219
2337
|
//#region src/Decorators/Http/Status.ts
|
|
2220
2338
|
/**
|
|
2221
|
-
|
|
2222
2339
|
* A decorator that sets a status on the response.
|
|
2223
|
-
|
|
2224
2340
|
* @extends {BaseDecorator<StatusDecoratorOptions>}
|
|
2225
|
-
|
|
2226
2341
|
*/
|
|
2227
2342
|
var StatusDecorator = class extends BaseDecorator {
|
|
2228
2343
|
/**
|
|
2229
|
-
|
|
2230
2344
|
* Called when the decorator is created.
|
|
2231
|
-
|
|
2232
2345
|
* Sets a status on the response
|
|
2233
|
-
|
|
2234
2346
|
* @override
|
|
2235
|
-
|
|
2236
2347
|
*/
|
|
2237
2348
|
created() {
|
|
2238
2349
|
initializeMetadata(this.prototype);
|
|
@@ -2241,13 +2352,9 @@ var StatusDecorator = class extends BaseDecorator {
|
|
|
2241
2352
|
}
|
|
2242
2353
|
};
|
|
2243
2354
|
/**
|
|
2244
|
-
|
|
2245
2355
|
* Creates a Status decorator.
|
|
2246
|
-
|
|
2247
2356
|
* @param {number} code - The status value.
|
|
2248
|
-
|
|
2249
2357
|
* @returns {Function} The decorator function.
|
|
2250
|
-
|
|
2251
2358
|
*/
|
|
2252
2359
|
function Status(code) {
|
|
2253
2360
|
return createDecorator(StatusDecorator, { code });
|
|
@@ -2257,15 +2364,10 @@ function Status(code) {
|
|
|
2257
2364
|
//#region src/Decorators/Http/Redirect.ts
|
|
2258
2365
|
var RedirectDecorator = class extends BaseDecorator {
|
|
2259
2366
|
/**
|
|
2260
|
-
|
|
2261
2367
|
* Decorator responsible for redirecting to a specified URL.
|
|
2262
|
-
|
|
2263
2368
|
* Called when the decorator is created.
|
|
2264
|
-
|
|
2265
2369
|
* Sets the location header value and status code.
|
|
2266
|
-
|
|
2267
2370
|
* @override
|
|
2268
|
-
|
|
2269
2371
|
*/
|
|
2270
2372
|
created() {
|
|
2271
2373
|
initializeMetadata(this.prototype);
|
|
@@ -2273,21 +2375,16 @@ var RedirectDecorator = class extends BaseDecorator {
|
|
|
2273
2375
|
method.actions.push({ handler: () => {
|
|
2274
2376
|
return new FastResponse(void 0, {
|
|
2275
2377
|
status: this.options.code,
|
|
2276
|
-
headers: {
|
|
2378
|
+
headers: { Location: this.options.location }
|
|
2277
2379
|
});
|
|
2278
2380
|
} });
|
|
2279
2381
|
}
|
|
2280
2382
|
};
|
|
2281
2383
|
/**
|
|
2282
|
-
|
|
2283
2384
|
* Creates a Redirect decorator.
|
|
2284
|
-
|
|
2285
2385
|
* @param {string} location - The location header value.
|
|
2286
|
-
|
|
2287
2386
|
* @param {number} [code=301] - The status code.
|
|
2288
|
-
|
|
2289
2387
|
* @returns {Function} The decorator function.
|
|
2290
|
-
|
|
2291
2388
|
*/
|
|
2292
2389
|
function Redirect(location, code = 301) {
|
|
2293
2390
|
return createDecorator(RedirectDecorator, {
|
|
@@ -2358,10 +2455,10 @@ var MultipartFormDataDecorator = class extends BaseDecorator {
|
|
|
2358
2455
|
/**
|
|
2359
2456
|
* Decorator function that marks a parameter as multipart/form-data request body.
|
|
2360
2457
|
* This decorator will automatically parse incoming multipart form data
|
|
2361
|
-
*
|
|
2458
|
+
*
|
|
2362
2459
|
* @decorator
|
|
2363
2460
|
* @returns {Function} A decorator function that can be applied to method parameters
|
|
2364
|
-
*
|
|
2461
|
+
*
|
|
2365
2462
|
* @example
|
|
2366
2463
|
* class UserController {
|
|
2367
2464
|
* uploadFile(@MultipartFormData() formData: MyData) {
|
|
@@ -2373,53 +2470,6 @@ function MultipartFormData() {
|
|
|
2373
2470
|
return createDecorator(MultipartFormDataDecorator, {});
|
|
2374
2471
|
}
|
|
2375
2472
|
|
|
2376
|
-
//#endregion
|
|
2377
|
-
//#region src/Decorators/Http/Session.ts
|
|
2378
|
-
var import_decorate$1 = /* @__PURE__ */ __toESM(require_decorate(), 1);
|
|
2379
|
-
/**
|
|
2380
|
-
* This class is responsible for managing session decorators.
|
|
2381
|
-
*
|
|
2382
|
-
* This class extends the BaseDecorator and is used to register session information
|
|
2383
|
-
* with the MetadataResolver. It ensures that the metadata for the property is created
|
|
2384
|
-
* and adds the session information to the metadata.
|
|
2385
|
-
*
|
|
2386
|
-
* @extends {BaseDecorator<{}>}
|
|
2387
|
-
*/
|
|
2388
|
-
var SessionDecorator = class extends BaseDecorator {
|
|
2389
|
-
gRuntimeConfig;
|
|
2390
|
-
/**
|
|
2391
|
-
* Called when the decorator is created.
|
|
2392
|
-
*
|
|
2393
|
-
* This method checks if metadata for the property exists, creates it if it doesn't,
|
|
2394
|
-
* and then adds the session information to the metadata.
|
|
2395
|
-
*/
|
|
2396
|
-
created() {
|
|
2397
|
-
initializeMetadata(this.prototype);
|
|
2398
|
-
const method = initializeMetadataMethod(this.prototype, this.propertyName);
|
|
2399
|
-
method.args.push({
|
|
2400
|
-
idx: this.propertyIndex,
|
|
2401
|
-
type: "session",
|
|
2402
|
-
data: {
|
|
2403
|
-
name: this.gRuntimeConfig.runtimeConfig.session?.name ?? "vercube_session",
|
|
2404
|
-
secret: this.gRuntimeConfig.runtimeConfig.session?.secret ?? generateRandomHash(),
|
|
2405
|
-
duration: this.gRuntimeConfig.runtimeConfig.session?.duration ?? 3600 * 24 * 7
|
|
2406
|
-
}
|
|
2407
|
-
});
|
|
2408
|
-
}
|
|
2409
|
-
};
|
|
2410
|
-
(0, import_decorate$1.default)([Inject(RuntimeConfig)], SessionDecorator.prototype, "gRuntimeConfig", void 0);
|
|
2411
|
-
/**
|
|
2412
|
-
* A factory function for creating a SessionDecorator.
|
|
2413
|
-
*
|
|
2414
|
-
* This function returns a decorator function that can be used to annotate
|
|
2415
|
-
* a method parameter with session information.
|
|
2416
|
-
*
|
|
2417
|
-
* @return {Function} The decorator function.
|
|
2418
|
-
*/
|
|
2419
|
-
function Session() {
|
|
2420
|
-
return createDecorator(SessionDecorator, {});
|
|
2421
|
-
}
|
|
2422
|
-
|
|
2423
2473
|
//#endregion
|
|
2424
2474
|
//#region src/Decorators/Hooks/Listen.ts
|
|
2425
2475
|
var import_decorate = /* @__PURE__ */ __toESM(require_decorate(), 1);
|
|
@@ -2455,31 +2505,6 @@ function Listen(hookType) {
|
|
|
2455
2505
|
return createDecorator(ListenDecorator, { hookType });
|
|
2456
2506
|
}
|
|
2457
2507
|
|
|
2458
|
-
//#endregion
|
|
2459
|
-
//#region src/Services/Plugins/BasePlugin.ts
|
|
2460
|
-
/**
|
|
2461
|
-
* Represents a Plugin.
|
|
2462
|
-
*/
|
|
2463
|
-
var BasePlugin = class {
|
|
2464
|
-
/**
|
|
2465
|
-
* The name of the plugin.
|
|
2466
|
-
*/
|
|
2467
|
-
name;
|
|
2468
|
-
/**
|
|
2469
|
-
* Uses the plugin with the given app.
|
|
2470
|
-
* @param {App} app - The application instance.
|
|
2471
|
-
* @returns {void | Promise<void>} - A void or a promise that resolves to void.
|
|
2472
|
-
*/
|
|
2473
|
-
use(app, options) {}
|
|
2474
|
-
};
|
|
2475
|
-
|
|
2476
|
-
//#endregion
|
|
2477
|
-
//#region src/Services/Middleware/BaseMiddleware.ts
|
|
2478
|
-
/**
|
|
2479
|
-
* BaseMiddleware class that serves as a base for all middleware implementations.
|
|
2480
|
-
*/
|
|
2481
|
-
var BaseMiddleware = class {};
|
|
2482
|
-
|
|
2483
2508
|
//#endregion
|
|
2484
2509
|
//#region src/Errors/Http/ForbiddenError.ts
|
|
2485
2510
|
/**
|
|
@@ -2549,29 +2574,6 @@ var NotAcceptableError = class NotAcceptableError extends HttpError {
|
|
|
2549
2574
|
}
|
|
2550
2575
|
};
|
|
2551
2576
|
|
|
2552
|
-
//#endregion
|
|
2553
|
-
//#region src/Errors/Http/NotFoundError.ts
|
|
2554
|
-
/**
|
|
2555
|
-
* Represents a Not Found error (HTTP 404).
|
|
2556
|
-
* @extends {HttpError}
|
|
2557
|
-
*/
|
|
2558
|
-
var NotFoundError = class NotFoundError extends HttpError {
|
|
2559
|
-
/**
|
|
2560
|
-
* The name of the error.
|
|
2561
|
-
* @type {string}
|
|
2562
|
-
*/
|
|
2563
|
-
name = "NotFoundError";
|
|
2564
|
-
/**
|
|
2565
|
-
* Creates an instance of NotFoundError.
|
|
2566
|
-
* @param {string} [message] - The error message.
|
|
2567
|
-
*/
|
|
2568
|
-
constructor(message) {
|
|
2569
|
-
super(404);
|
|
2570
|
-
Object.setPrototypeOf(this, NotFoundError.prototype);
|
|
2571
|
-
if (message) this.message = message;
|
|
2572
|
-
}
|
|
2573
|
-
};
|
|
2574
|
-
|
|
2575
2577
|
//#endregion
|
|
2576
2578
|
//#region src/Errors/Http/UnauthorizedError.ts
|
|
2577
2579
|
/**
|
|
@@ -2595,73 +2597,6 @@ var UnauthorizedError = class UnauthorizedError extends HttpError {
|
|
|
2595
2597
|
}
|
|
2596
2598
|
};
|
|
2597
2599
|
|
|
2598
|
-
//#endregion
|
|
2599
|
-
//#region src/Types/HttpTypes.ts
|
|
2600
|
-
let HTTPStatus = /* @__PURE__ */ function(HTTPStatus$1) {
|
|
2601
|
-
HTTPStatus$1[HTTPStatus$1["CONTINUE"] = 100] = "CONTINUE";
|
|
2602
|
-
HTTPStatus$1[HTTPStatus$1["SWITCHING_PROTOCOLS"] = 101] = "SWITCHING_PROTOCOLS";
|
|
2603
|
-
HTTPStatus$1[HTTPStatus$1["PROCESSING"] = 102] = "PROCESSING";
|
|
2604
|
-
HTTPStatus$1[HTTPStatus$1["OK"] = 200] = "OK";
|
|
2605
|
-
HTTPStatus$1[HTTPStatus$1["CREATED"] = 201] = "CREATED";
|
|
2606
|
-
HTTPStatus$1[HTTPStatus$1["ACCEPTED"] = 202] = "ACCEPTED";
|
|
2607
|
-
HTTPStatus$1[HTTPStatus$1["NON_AUTHORITATIVE_INFORMATION"] = 203] = "NON_AUTHORITATIVE_INFORMATION";
|
|
2608
|
-
HTTPStatus$1[HTTPStatus$1["NO_CONTENT"] = 204] = "NO_CONTENT";
|
|
2609
|
-
HTTPStatus$1[HTTPStatus$1["RESET_CONTENT"] = 205] = "RESET_CONTENT";
|
|
2610
|
-
HTTPStatus$1[HTTPStatus$1["PARTIAL_CONTENT"] = 206] = "PARTIAL_CONTENT";
|
|
2611
|
-
HTTPStatus$1[HTTPStatus$1["MULTI_STATUS"] = 207] = "MULTI_STATUS";
|
|
2612
|
-
HTTPStatus$1[HTTPStatus$1["ALREADY_REPORTED"] = 208] = "ALREADY_REPORTED";
|
|
2613
|
-
HTTPStatus$1[HTTPStatus$1["IM_USED"] = 226] = "IM_USED";
|
|
2614
|
-
HTTPStatus$1[HTTPStatus$1["MULTIPLE_CHOICES"] = 300] = "MULTIPLE_CHOICES";
|
|
2615
|
-
HTTPStatus$1[HTTPStatus$1["MOVED_PERMANENTLY"] = 301] = "MOVED_PERMANENTLY";
|
|
2616
|
-
HTTPStatus$1[HTTPStatus$1["FOUND"] = 302] = "FOUND";
|
|
2617
|
-
HTTPStatus$1[HTTPStatus$1["SEE_OTHER"] = 303] = "SEE_OTHER";
|
|
2618
|
-
HTTPStatus$1[HTTPStatus$1["NOT_MODIFIED"] = 304] = "NOT_MODIFIED";
|
|
2619
|
-
HTTPStatus$1[HTTPStatus$1["USE_PROXY"] = 305] = "USE_PROXY";
|
|
2620
|
-
HTTPStatus$1[HTTPStatus$1["TEMPORARY_REDIRECT"] = 307] = "TEMPORARY_REDIRECT";
|
|
2621
|
-
HTTPStatus$1[HTTPStatus$1["PERMANENT_REDIRECT"] = 308] = "PERMANENT_REDIRECT";
|
|
2622
|
-
HTTPStatus$1[HTTPStatus$1["BAD_REQUEST"] = 400] = "BAD_REQUEST";
|
|
2623
|
-
HTTPStatus$1[HTTPStatus$1["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
|
|
2624
|
-
HTTPStatus$1[HTTPStatus$1["PAYMENT_REQUIRED"] = 402] = "PAYMENT_REQUIRED";
|
|
2625
|
-
HTTPStatus$1[HTTPStatus$1["FORBIDDEN"] = 403] = "FORBIDDEN";
|
|
2626
|
-
HTTPStatus$1[HTTPStatus$1["NOT_FOUND"] = 404] = "NOT_FOUND";
|
|
2627
|
-
HTTPStatus$1[HTTPStatus$1["METHOD_NOT_ALLOWED"] = 405] = "METHOD_NOT_ALLOWED";
|
|
2628
|
-
HTTPStatus$1[HTTPStatus$1["NOT_ACCEPTABLE"] = 406] = "NOT_ACCEPTABLE";
|
|
2629
|
-
HTTPStatus$1[HTTPStatus$1["PROXY_AUTHENTICATION_REQUIRED"] = 407] = "PROXY_AUTHENTICATION_REQUIRED";
|
|
2630
|
-
HTTPStatus$1[HTTPStatus$1["REQUEST_TIMEOUT"] = 408] = "REQUEST_TIMEOUT";
|
|
2631
|
-
HTTPStatus$1[HTTPStatus$1["CONFLICT"] = 409] = "CONFLICT";
|
|
2632
|
-
HTTPStatus$1[HTTPStatus$1["GONE"] = 410] = "GONE";
|
|
2633
|
-
HTTPStatus$1[HTTPStatus$1["LENGTH_REQUIRED"] = 411] = "LENGTH_REQUIRED";
|
|
2634
|
-
HTTPStatus$1[HTTPStatus$1["PRECONDITION_FAILED"] = 412] = "PRECONDITION_FAILED";
|
|
2635
|
-
HTTPStatus$1[HTTPStatus$1["PAYLOAD_TOO_LARGE"] = 413] = "PAYLOAD_TOO_LARGE";
|
|
2636
|
-
HTTPStatus$1[HTTPStatus$1["URI_TOO_LONG"] = 414] = "URI_TOO_LONG";
|
|
2637
|
-
HTTPStatus$1[HTTPStatus$1["UNSUPPORTED_MEDIA_TYPE"] = 415] = "UNSUPPORTED_MEDIA_TYPE";
|
|
2638
|
-
HTTPStatus$1[HTTPStatus$1["RANGE_NOT_SATISFIABLE"] = 416] = "RANGE_NOT_SATISFIABLE";
|
|
2639
|
-
HTTPStatus$1[HTTPStatus$1["EXPECTATION_FAILED"] = 417] = "EXPECTATION_FAILED";
|
|
2640
|
-
HTTPStatus$1[HTTPStatus$1["I_AM_A_TEAPOT"] = 418] = "I_AM_A_TEAPOT";
|
|
2641
|
-
HTTPStatus$1[HTTPStatus$1["MISDIRECTED_REQUEST"] = 421] = "MISDIRECTED_REQUEST";
|
|
2642
|
-
HTTPStatus$1[HTTPStatus$1["UNPROCESSABLE_ENTITY"] = 422] = "UNPROCESSABLE_ENTITY";
|
|
2643
|
-
HTTPStatus$1[HTTPStatus$1["LOCKED"] = 423] = "LOCKED";
|
|
2644
|
-
HTTPStatus$1[HTTPStatus$1["FAILED_DEPENDENCY"] = 424] = "FAILED_DEPENDENCY";
|
|
2645
|
-
HTTPStatus$1[HTTPStatus$1["TOO_EARLY"] = 425] = "TOO_EARLY";
|
|
2646
|
-
HTTPStatus$1[HTTPStatus$1["UPGRADE_REQUIRED"] = 426] = "UPGRADE_REQUIRED";
|
|
2647
|
-
HTTPStatus$1[HTTPStatus$1["PRECONDITION_REQUIRED"] = 428] = "PRECONDITION_REQUIRED";
|
|
2648
|
-
HTTPStatus$1[HTTPStatus$1["TOO_MANY_REQUESTS"] = 429] = "TOO_MANY_REQUESTS";
|
|
2649
|
-
HTTPStatus$1[HTTPStatus$1["REQUEST_HEADER_FIELDS_TOO_LARGE"] = 431] = "REQUEST_HEADER_FIELDS_TOO_LARGE";
|
|
2650
|
-
HTTPStatus$1[HTTPStatus$1["UNAVAILABLE_FOR_LEGAL_REASONS"] = 451] = "UNAVAILABLE_FOR_LEGAL_REASONS";
|
|
2651
|
-
HTTPStatus$1[HTTPStatus$1["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
|
|
2652
|
-
HTTPStatus$1[HTTPStatus$1["NOT_IMPLEMENTED"] = 501] = "NOT_IMPLEMENTED";
|
|
2653
|
-
HTTPStatus$1[HTTPStatus$1["BAD_GATEWAY"] = 502] = "BAD_GATEWAY";
|
|
2654
|
-
HTTPStatus$1[HTTPStatus$1["SERVICE_UNAVAILABLE"] = 503] = "SERVICE_UNAVAILABLE";
|
|
2655
|
-
HTTPStatus$1[HTTPStatus$1["GATEWAY_TIMEOUT"] = 504] = "GATEWAY_TIMEOUT";
|
|
2656
|
-
HTTPStatus$1[HTTPStatus$1["HTTP_VERSION_NOT_SUPPORTED"] = 505] = "HTTP_VERSION_NOT_SUPPORTED";
|
|
2657
|
-
HTTPStatus$1[HTTPStatus$1["VARIANT_ALSO_NEGOTIATES"] = 506] = "VARIANT_ALSO_NEGOTIATES";
|
|
2658
|
-
HTTPStatus$1[HTTPStatus$1["INSUFFICIENT_STORAGE"] = 507] = "INSUFFICIENT_STORAGE";
|
|
2659
|
-
HTTPStatus$1[HTTPStatus$1["LOOP_DETECTED"] = 508] = "LOOP_DETECTED";
|
|
2660
|
-
HTTPStatus$1[HTTPStatus$1["NOT_EXTENDED"] = 510] = "NOT_EXTENDED";
|
|
2661
|
-
HTTPStatus$1[HTTPStatus$1["NETWORK_AUTHENTICATION_REQUIRED"] = 511] = "NETWORK_AUTHENTICATION_REQUIRED";
|
|
2662
|
-
return HTTPStatus$1;
|
|
2663
|
-
}({});
|
|
2664
|
-
|
|
2665
2600
|
//#endregion
|
|
2666
2601
|
//#region src/Types/HttpCodes.ts
|
|
2667
2602
|
/**
|
|
@@ -2993,4 +2928,4 @@ let HttpStatusCode = /* @__PURE__ */ function(HttpStatusCode$1) {
|
|
|
2993
2928
|
}({});
|
|
2994
2929
|
|
|
2995
2930
|
//#endregion
|
|
2996
|
-
export { App, BadRequestError, BaseMiddleware, BasePlugin, Body, Connect, Controller, Delete, ErrorHandlerProvider, FastResponse, ForbiddenError, Get, GlobalMiddlewareRegistry, HTTPStatus, Head, Header, Headers$1 as Headers, HooksService, HttpError, HttpServer, HttpStatusCode, InternalServerError, Listen, MetadataResolver, MethodNotAllowedError, Middleware, MultipartFormData, NotAcceptableError, NotFoundError, Options, Param, Patch, Post, Put, QueryParam, QueryParams, Redirect, Request, Response$1 as Response, Router, RuntimeConfig,
|
|
2931
|
+
export { App, BadRequestError, BaseMiddleware, BasePlugin, Body, Connect, Controller, Delete, ErrorHandlerProvider, FastResponse, ForbiddenError, Get, GlobalMiddlewareRegistry, HTTPStatus, Head, Header, Headers$1 as Headers, HooksService, HttpError, HttpServer, HttpStatusCode, InternalServerError, Listen, MetadataResolver, MethodNotAllowedError, Middleware, MultipartFormData, NotAcceptableError, NotFoundError, Options, Param, Patch, Post, Put, QueryParam, QueryParams, Redirect, Request, Response$1 as Response, Router, RuntimeConfig, SetHeader, StandardSchemaValidationProvider, Status, Trace, UnauthorizedError, ValidationProvider, createApp, createMetadataCtx, createMetadataMethod, defineConfig, initializeMetadata, initializeMetadataMethod, loadVercubeConfig };
|