@vercube/core 0.0.21 → 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 +632 -695
- package/package.json +8 -5
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 = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.77.3/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 = __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 = __toESM(require_decorate());
|
|
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
|
-
*
|
|
336
|
-
*
|
|
337
|
-
* @
|
|
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
|
+
*
|
|
155
|
+
* @param {RouterTypes.RouterEvent} event - The router event containing the request to process
|
|
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
|
|
@@ -766,10 +785,10 @@ var StaticRequestHandler = class {
|
|
|
766
785
|
|
|
767
786
|
//#endregion
|
|
768
787
|
//#region src/Services/HttpServer/HttpServer.ts
|
|
769
|
-
var import_decorate$15 = __toESM(require_decorate());
|
|
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) {
|
|
@@ -829,25 +848,27 @@ var HttpServer = class {
|
|
|
829
848
|
reusePort: true,
|
|
830
849
|
port,
|
|
831
850
|
fetch: this.handleRequest.bind(this),
|
|
832
|
-
plugins: this.fPlugins
|
|
851
|
+
plugins: this.fPlugins,
|
|
852
|
+
manual: true
|
|
833
853
|
});
|
|
834
854
|
}
|
|
835
855
|
/**
|
|
836
856
|
* Listens for incoming requests on the HTTP server
|
|
837
|
-
*
|
|
857
|
+
*
|
|
838
858
|
* @returns {Promise<void>} A promise that resolves when the server is ready to listen
|
|
839
859
|
*/
|
|
840
860
|
async listen() {
|
|
861
|
+
await this.fServer.serve();
|
|
841
862
|
await this.fServer.ready();
|
|
842
863
|
}
|
|
843
864
|
/**
|
|
844
865
|
* Processes an incoming HTTP request
|
|
845
|
-
*
|
|
866
|
+
*
|
|
846
867
|
* This method:
|
|
847
868
|
* 1. Resolves the route for the request
|
|
848
869
|
* 2. Returns a 404 response if no route is found
|
|
849
870
|
* 3. Delegates to the request handler for matched routes
|
|
850
|
-
*
|
|
871
|
+
*
|
|
851
872
|
* @param {Request} request - The incoming HTTP request
|
|
852
873
|
* @returns {Promise<Response>} The HTTP response
|
|
853
874
|
* @private
|
|
@@ -875,36 +896,66 @@ var HttpServer = class {
|
|
|
875
896
|
(0, import_decorate$15.default)([Inject(StaticRequestHandler)], HttpServer.prototype, "gStaticRequestHandler", void 0);
|
|
876
897
|
|
|
877
898
|
//#endregion
|
|
878
|
-
//#region src/Services/
|
|
899
|
+
//#region src/Services/Plugins/BasePlugin.ts
|
|
879
900
|
/**
|
|
880
|
-
*
|
|
881
|
-
* This class provides a centralized way to access and modify runtime configuration settings.
|
|
901
|
+
* Represents a Plugin.
|
|
882
902
|
*/
|
|
883
|
-
var
|
|
903
|
+
var BasePlugin = class {
|
|
884
904
|
/**
|
|
885
|
-
*
|
|
886
|
-
* @private
|
|
905
|
+
* The name of the plugin.
|
|
887
906
|
*/
|
|
888
|
-
|
|
907
|
+
name;
|
|
889
908
|
/**
|
|
890
|
-
*
|
|
891
|
-
* @
|
|
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.
|
|
892
912
|
*/
|
|
893
|
-
|
|
894
|
-
|
|
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
|
+
});
|
|
895
936
|
}
|
|
896
937
|
/**
|
|
897
|
-
*
|
|
898
|
-
*
|
|
938
|
+
* Gets the list of registered plugins.
|
|
939
|
+
*
|
|
940
|
+
* @returns {Plugin[]} The list of registered plugins.
|
|
899
941
|
*/
|
|
900
|
-
|
|
901
|
-
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);
|
|
902
952
|
}
|
|
903
953
|
};
|
|
954
|
+
(0, import_decorate$14.default)([Inject(Container)], PluginsRegistry.prototype, "gContainer", void 0);
|
|
904
955
|
|
|
905
956
|
//#endregion
|
|
906
957
|
//#region src/Common/App.ts
|
|
907
|
-
var import_decorate$
|
|
958
|
+
var import_decorate$13 = /* @__PURE__ */ __toESM(require_decorate(), 1);
|
|
908
959
|
/**
|
|
909
960
|
* Represents the main application class.
|
|
910
961
|
*/
|
|
@@ -984,7 +1035,7 @@ var App = class {
|
|
|
984
1035
|
/**
|
|
985
1036
|
* Handles an incoming HTTP request.
|
|
986
1037
|
* This method is an adapter for HttpServer.handleRequest method.
|
|
987
|
-
*
|
|
1038
|
+
*
|
|
988
1039
|
* @param {Request} request - The incoming HTTP request
|
|
989
1040
|
* @returns {Promise<Response>} The HTTP response
|
|
990
1041
|
*/
|
|
@@ -1000,42 +1051,11 @@ var App = class {
|
|
|
1000
1051
|
await this.gPluginsRegistry.init(this);
|
|
1001
1052
|
}
|
|
1002
1053
|
};
|
|
1003
|
-
(0, import_decorate$
|
|
1004
|
-
(0, import_decorate$
|
|
1005
|
-
(0, import_decorate$
|
|
1006
|
-
(0, import_decorate$
|
|
1007
|
-
(0, import_decorate$
|
|
1008
|
-
|
|
1009
|
-
//#endregion
|
|
1010
|
-
//#region src/Services/Validation/ValidationProvider.ts
|
|
1011
|
-
/**
|
|
1012
|
-
* Abstract class representing a validation provider
|
|
1013
|
-
* Provides a common interface for different validation implementations
|
|
1014
|
-
*
|
|
1015
|
-
* @abstract
|
|
1016
|
-
* @class ValidationProvider
|
|
1017
|
-
*/
|
|
1018
|
-
var ValidationProvider = class {};
|
|
1019
|
-
|
|
1020
|
-
//#endregion
|
|
1021
|
-
//#region src/Services/Validation/StandardSchemaValidationProvider.ts
|
|
1022
|
-
/**
|
|
1023
|
-
* StandardSchemaValidationProvider implements validation using StandardSchema schema validation
|
|
1024
|
-
* @see https://github.com/standard-schema/standard-schema
|
|
1025
|
-
* @class
|
|
1026
|
-
* @implements {ValidationProvider}
|
|
1027
|
-
*/
|
|
1028
|
-
var StandardSchemaValidationProvider = class {
|
|
1029
|
-
/**
|
|
1030
|
-
* Validates data against a schema
|
|
1031
|
-
* @param {ValidationTypes.Schema} schema - The schema to validate against
|
|
1032
|
-
* @param {ValidationTypes.Input} data - The data to validate
|
|
1033
|
-
* @return {ValidationTypes.Result | Promise<ValidationTypes.Result>} The validation result
|
|
1034
|
-
*/
|
|
1035
|
-
validate(schema, data) {
|
|
1036
|
-
return schema["~standard"].validate(data);
|
|
1037
|
-
}
|
|
1038
|
-
};
|
|
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);
|
|
1039
1059
|
|
|
1040
1060
|
//#endregion
|
|
1041
1061
|
//#region src/Errors/Http/InternalServerError.ts
|
|
@@ -1061,30 +1081,61 @@ var InternalServerError = class InternalServerError extends HttpError {
|
|
|
1061
1081
|
};
|
|
1062
1082
|
|
|
1063
1083
|
//#endregion
|
|
1064
|
-
//#region src/Services/ErrorHandler/DefaultErrorHandlerProvider.ts
|
|
1065
|
-
var import_decorate$
|
|
1084
|
+
//#region src/Services/ErrorHandler/DefaultErrorHandlerProvider.ts
|
|
1085
|
+
var import_decorate$12 = /* @__PURE__ */ __toESM(require_decorate(), 1);
|
|
1086
|
+
/**
|
|
1087
|
+
* Default error handler provider
|
|
1088
|
+
*
|
|
1089
|
+
* @class DefaultErrorHandlerProvider
|
|
1090
|
+
*/
|
|
1091
|
+
var DefaultErrorHandlerProvider = class extends ErrorHandlerProvider {
|
|
1092
|
+
gLogger;
|
|
1093
|
+
/**
|
|
1094
|
+
* Handles an error that occurred during request processing
|
|
1095
|
+
*
|
|
1096
|
+
* @param error - The Error object containing error details
|
|
1097
|
+
* @returns Promise<Response> | Response - The response to be sent to the client
|
|
1098
|
+
*/
|
|
1099
|
+
handleError(error) {
|
|
1100
|
+
const _internalError = new InternalServerError(error?.message ?? "Internal server error");
|
|
1101
|
+
const status = error?.status ?? 500;
|
|
1102
|
+
if (error instanceof HttpError) return new FastResponse(JSON.stringify({ ...error }, void 0, 2), { status });
|
|
1103
|
+
this.gLogger.error(error);
|
|
1104
|
+
return new FastResponse(JSON.stringify({ ...error?.cause ?? _internalError }, void 0, 2), { status });
|
|
1105
|
+
}
|
|
1106
|
+
};
|
|
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
|
|
1066
1122
|
/**
|
|
1067
|
-
*
|
|
1068
|
-
*
|
|
1069
|
-
* @class
|
|
1123
|
+
* StandardSchemaValidationProvider implements validation using StandardSchema schema validation
|
|
1124
|
+
* @see https://github.com/standard-schema/standard-schema
|
|
1125
|
+
* @class
|
|
1126
|
+
* @implements {ValidationProvider}
|
|
1070
1127
|
*/
|
|
1071
|
-
var
|
|
1072
|
-
gLogger;
|
|
1128
|
+
var StandardSchemaValidationProvider = class {
|
|
1073
1129
|
/**
|
|
1074
|
-
*
|
|
1075
|
-
*
|
|
1076
|
-
* @param
|
|
1077
|
-
* @
|
|
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
|
|
1078
1134
|
*/
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
const status = error?.status ?? 500;
|
|
1082
|
-
if (error instanceof HttpError) return new FastResponse(JSON.stringify({ ...error }, void 0, 2), { status });
|
|
1083
|
-
this.gLogger.error(error);
|
|
1084
|
-
return new FastResponse(JSON.stringify({ ...error?.cause ?? _internalError }, void 0, 2), { status });
|
|
1135
|
+
validate(schema, data) {
|
|
1136
|
+
return schema["~standard"].validate(data);
|
|
1085
1137
|
}
|
|
1086
1138
|
};
|
|
1087
|
-
(0, import_decorate$13.default)([Inject(Logger)], DefaultErrorHandlerProvider.prototype, "gLogger", void 0);
|
|
1088
1139
|
|
|
1089
1140
|
//#endregion
|
|
1090
1141
|
//#region src/Common/Container.ts
|
|
@@ -1215,7 +1266,7 @@ function defineConfig(config) {
|
|
|
1215
1266
|
|
|
1216
1267
|
//#endregion
|
|
1217
1268
|
//#region src/Middleware/ValidationMiddleware.ts
|
|
1218
|
-
var import_decorate$
|
|
1269
|
+
var import_decorate$11 = /* @__PURE__ */ __toESM(require_decorate(), 1);
|
|
1219
1270
|
/**
|
|
1220
1271
|
* Middleware for validating request data against a schema
|
|
1221
1272
|
* @class ValidationMiddleware
|
|
@@ -1226,6 +1277,7 @@ var import_decorate$12 = __toESM(require_decorate(), 1);
|
|
|
1226
1277
|
* await middleware.use(event, { schema: myValidationSchema });
|
|
1227
1278
|
*/
|
|
1228
1279
|
var ValidationMiddleware = class {
|
|
1280
|
+
gLogger;
|
|
1229
1281
|
gValidationProvider;
|
|
1230
1282
|
/**
|
|
1231
1283
|
* Middleware function that processes the HTTP event
|
|
@@ -1237,7 +1289,7 @@ var ValidationMiddleware = class {
|
|
|
1237
1289
|
*/
|
|
1238
1290
|
async onRequest(request, response, args) {
|
|
1239
1291
|
if (!this.gValidationProvider) {
|
|
1240
|
-
|
|
1292
|
+
this.gLogger?.warn("ValidationMiddleware::ValidationProvider", "Validation provider is not registered");
|
|
1241
1293
|
return;
|
|
1242
1294
|
}
|
|
1243
1295
|
const validators = args.methodArgs?.filter((arg) => arg.validate && arg.validationSchema) ?? [];
|
|
@@ -1247,7 +1299,8 @@ var ValidationMiddleware = class {
|
|
|
1247
1299
|
}
|
|
1248
1300
|
}
|
|
1249
1301
|
};
|
|
1250
|
-
(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);
|
|
1251
1304
|
|
|
1252
1305
|
//#endregion
|
|
1253
1306
|
//#region src/Utils/Utils.ts
|
|
@@ -1343,7 +1396,7 @@ function Body(options) {
|
|
|
1343
1396
|
|
|
1344
1397
|
//#endregion
|
|
1345
1398
|
//#region src/Decorators/Http/Connect.ts
|
|
1346
|
-
var import_decorate$
|
|
1399
|
+
var import_decorate$10 = /* @__PURE__ */ __toESM(require_decorate(), 1);
|
|
1347
1400
|
/**
|
|
1348
1401
|
* A decorator class for handling HTTP CONNECT requests.
|
|
1349
1402
|
*
|
|
@@ -1382,9 +1435,9 @@ var ConnectDecorator = class extends BaseDecorator {
|
|
|
1382
1435
|
});
|
|
1383
1436
|
}
|
|
1384
1437
|
};
|
|
1385
|
-
(0, import_decorate$
|
|
1386
|
-
(0, import_decorate$
|
|
1387
|
-
(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);
|
|
1388
1441
|
/**
|
|
1389
1442
|
* A factory function for creating a ConnectDecorator.
|
|
1390
1443
|
*
|
|
@@ -1421,7 +1474,7 @@ function Controller(path) {
|
|
|
1421
1474
|
|
|
1422
1475
|
//#endregion
|
|
1423
1476
|
//#region src/Decorators/Http/Delete.ts
|
|
1424
|
-
var import_decorate$
|
|
1477
|
+
var import_decorate$9 = /* @__PURE__ */ __toESM(require_decorate(), 1);
|
|
1425
1478
|
/**
|
|
1426
1479
|
* A decorator class for handling HTTP DELETE requests.
|
|
1427
1480
|
*
|
|
@@ -1460,9 +1513,9 @@ var DeleteDecorator = class extends BaseDecorator {
|
|
|
1460
1513
|
});
|
|
1461
1514
|
}
|
|
1462
1515
|
};
|
|
1463
|
-
(0, import_decorate$
|
|
1464
|
-
(0, import_decorate$
|
|
1465
|
-
(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);
|
|
1466
1519
|
/**
|
|
1467
1520
|
* A factory function for creating a DeleteDecorator.
|
|
1468
1521
|
*
|
|
@@ -1478,7 +1531,7 @@ function Delete(path) {
|
|
|
1478
1531
|
|
|
1479
1532
|
//#endregion
|
|
1480
1533
|
//#region src/Decorators/Http/Get.ts
|
|
1481
|
-
var import_decorate$
|
|
1534
|
+
var import_decorate$8 = /* @__PURE__ */ __toESM(require_decorate(), 1);
|
|
1482
1535
|
/**
|
|
1483
1536
|
* A decorator class for handling HTTP GET requests.
|
|
1484
1537
|
*
|
|
@@ -1517,9 +1570,9 @@ var GetDecorator = class extends BaseDecorator {
|
|
|
1517
1570
|
});
|
|
1518
1571
|
}
|
|
1519
1572
|
};
|
|
1520
|
-
(0, import_decorate$
|
|
1521
|
-
(0, import_decorate$
|
|
1522
|
-
(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);
|
|
1523
1576
|
/**
|
|
1524
1577
|
* A decorator function for handling HTTP GET requests.
|
|
1525
1578
|
*
|
|
@@ -1535,7 +1588,7 @@ function Get(path) {
|
|
|
1535
1588
|
|
|
1536
1589
|
//#endregion
|
|
1537
1590
|
//#region src/Decorators/Http/Head.ts
|
|
1538
|
-
var import_decorate$
|
|
1591
|
+
var import_decorate$7 = /* @__PURE__ */ __toESM(require_decorate(), 1);
|
|
1539
1592
|
/**
|
|
1540
1593
|
* A decorator class for handling HTTP HEAD requests.
|
|
1541
1594
|
*
|
|
@@ -1574,9 +1627,9 @@ var HeadDecorator = class extends BaseDecorator {
|
|
|
1574
1627
|
});
|
|
1575
1628
|
}
|
|
1576
1629
|
};
|
|
1577
|
-
(0, import_decorate$
|
|
1578
|
-
(0, import_decorate$
|
|
1579
|
-
(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);
|
|
1580
1633
|
/**
|
|
1581
1634
|
* A factory function for creating a HeadDecorator.
|
|
1582
1635
|
*
|
|
@@ -1673,7 +1726,7 @@ function Headers$1() {
|
|
|
1673
1726
|
|
|
1674
1727
|
//#endregion
|
|
1675
1728
|
//#region src/Decorators/Http/Options.ts
|
|
1676
|
-
var import_decorate$
|
|
1729
|
+
var import_decorate$6 = /* @__PURE__ */ __toESM(require_decorate(), 1);
|
|
1677
1730
|
/**
|
|
1678
1731
|
* A decorator class for handling HTTP OPTIONS requests.
|
|
1679
1732
|
*
|
|
@@ -1712,9 +1765,9 @@ var OptionsDecorator = class extends BaseDecorator {
|
|
|
1712
1765
|
});
|
|
1713
1766
|
}
|
|
1714
1767
|
};
|
|
1715
|
-
(0, import_decorate$
|
|
1716
|
-
(0, import_decorate$
|
|
1717
|
-
(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);
|
|
1718
1771
|
/**
|
|
1719
1772
|
* A factory function for creating an OptionsDecorator.
|
|
1720
1773
|
*
|
|
@@ -1730,7 +1783,7 @@ function Options(path) {
|
|
|
1730
1783
|
|
|
1731
1784
|
//#endregion
|
|
1732
1785
|
//#region src/Decorators/Http/Param.ts
|
|
1733
|
-
var import_decorate$
|
|
1786
|
+
var import_decorate$5 = /* @__PURE__ */ __toESM(require_decorate(), 1);
|
|
1734
1787
|
/**
|
|
1735
1788
|
* This class is responsible for managing parameter decorators.
|
|
1736
1789
|
*
|
|
@@ -1758,7 +1811,7 @@ var ParamDecorator = class extends BaseDecorator {
|
|
|
1758
1811
|
});
|
|
1759
1812
|
}
|
|
1760
1813
|
};
|
|
1761
|
-
(0, import_decorate$
|
|
1814
|
+
(0, import_decorate$5.default)([Inject(MetadataResolver)], ParamDecorator.prototype, "gMetadataResolver", void 0);
|
|
1762
1815
|
/**
|
|
1763
1816
|
* A factory function for creating a ParamDecorator.
|
|
1764
1817
|
*
|
|
@@ -1776,7 +1829,7 @@ function Param(name) {
|
|
|
1776
1829
|
|
|
1777
1830
|
//#endregion
|
|
1778
1831
|
//#region src/Decorators/Http/Patch.ts
|
|
1779
|
-
var import_decorate$
|
|
1832
|
+
var import_decorate$4 = /* @__PURE__ */ __toESM(require_decorate(), 1);
|
|
1780
1833
|
/**
|
|
1781
1834
|
* A decorator class for handling HTTP PATCH requests.
|
|
1782
1835
|
*
|
|
@@ -1815,9 +1868,9 @@ var PatchDecorator = class extends BaseDecorator {
|
|
|
1815
1868
|
});
|
|
1816
1869
|
}
|
|
1817
1870
|
};
|
|
1818
|
-
(0, import_decorate$
|
|
1819
|
-
(0, import_decorate$
|
|
1820
|
-
(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);
|
|
1821
1874
|
/**
|
|
1822
1875
|
* A factory function for creating a PatchDecorator.
|
|
1823
1876
|
*
|
|
@@ -1833,7 +1886,7 @@ function Patch(path) {
|
|
|
1833
1886
|
|
|
1834
1887
|
//#endregion
|
|
1835
1888
|
//#region src/Decorators/Http/Post.ts
|
|
1836
|
-
var import_decorate$
|
|
1889
|
+
var import_decorate$3 = /* @__PURE__ */ __toESM(require_decorate(), 1);
|
|
1837
1890
|
/**
|
|
1838
1891
|
* A decorator class for handling HTTP POST requests.
|
|
1839
1892
|
*
|
|
@@ -1872,9 +1925,9 @@ var PostDecorator = class extends BaseDecorator {
|
|
|
1872
1925
|
});
|
|
1873
1926
|
}
|
|
1874
1927
|
};
|
|
1875
|
-
(0, import_decorate$
|
|
1876
|
-
(0, import_decorate$
|
|
1877
|
-
(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);
|
|
1878
1931
|
/**
|
|
1879
1932
|
* A factory function for creating a PostDecorator.
|
|
1880
1933
|
*
|
|
@@ -1890,7 +1943,7 @@ function Post(path) {
|
|
|
1890
1943
|
|
|
1891
1944
|
//#endregion
|
|
1892
1945
|
//#region src/Decorators/Http/Put.ts
|
|
1893
|
-
var import_decorate$
|
|
1946
|
+
var import_decorate$2 = /* @__PURE__ */ __toESM(require_decorate(), 1);
|
|
1894
1947
|
/**
|
|
1895
1948
|
* A decorator class for handling HTTP PUT requests.
|
|
1896
1949
|
*
|
|
@@ -1929,9 +1982,9 @@ var PutDecorator = class extends BaseDecorator {
|
|
|
1929
1982
|
});
|
|
1930
1983
|
}
|
|
1931
1984
|
};
|
|
1932
|
-
(0, import_decorate$
|
|
1933
|
-
(0, import_decorate$
|
|
1934
|
-
(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);
|
|
1935
1988
|
/**
|
|
1936
1989
|
* A factory function for creating a PutDecorator.
|
|
1937
1990
|
*
|
|
@@ -2123,7 +2176,7 @@ function Response$1() {
|
|
|
2123
2176
|
|
|
2124
2177
|
//#endregion
|
|
2125
2178
|
//#region src/Decorators/Http/Trace.ts
|
|
2126
|
-
var import_decorate$
|
|
2179
|
+
var import_decorate$1 = /* @__PURE__ */ __toESM(require_decorate(), 1);
|
|
2127
2180
|
/**
|
|
2128
2181
|
* A decorator class for handling HTTP TRACE requests.
|
|
2129
2182
|
*
|
|
@@ -2162,9 +2215,9 @@ var TraceDecorator = class extends BaseDecorator {
|
|
|
2162
2215
|
});
|
|
2163
2216
|
}
|
|
2164
2217
|
};
|
|
2165
|
-
(0, import_decorate$
|
|
2166
|
-
(0, import_decorate$
|
|
2167
|
-
(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);
|
|
2168
2221
|
/**
|
|
2169
2222
|
* A factory function for creating a TraceDecorator.
|
|
2170
2223
|
*
|
|
@@ -2213,24 +2266,84 @@ function SetHeader(key, value) {
|
|
|
2213
2266
|
});
|
|
2214
2267
|
}
|
|
2215
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
|
+
|
|
2216
2336
|
//#endregion
|
|
2217
2337
|
//#region src/Decorators/Http/Status.ts
|
|
2218
2338
|
/**
|
|
2219
|
-
|
|
2220
2339
|
* A decorator that sets a status on the response.
|
|
2221
|
-
|
|
2222
2340
|
* @extends {BaseDecorator<StatusDecoratorOptions>}
|
|
2223
|
-
|
|
2224
2341
|
*/
|
|
2225
2342
|
var StatusDecorator = class extends BaseDecorator {
|
|
2226
2343
|
/**
|
|
2227
|
-
|
|
2228
2344
|
* Called when the decorator is created.
|
|
2229
|
-
|
|
2230
2345
|
* Sets a status on the response
|
|
2231
|
-
|
|
2232
2346
|
* @override
|
|
2233
|
-
|
|
2234
2347
|
*/
|
|
2235
2348
|
created() {
|
|
2236
2349
|
initializeMetadata(this.prototype);
|
|
@@ -2239,13 +2352,9 @@ var StatusDecorator = class extends BaseDecorator {
|
|
|
2239
2352
|
}
|
|
2240
2353
|
};
|
|
2241
2354
|
/**
|
|
2242
|
-
|
|
2243
2355
|
* Creates a Status decorator.
|
|
2244
|
-
|
|
2245
2356
|
* @param {number} code - The status value.
|
|
2246
|
-
|
|
2247
2357
|
* @returns {Function} The decorator function.
|
|
2248
|
-
|
|
2249
2358
|
*/
|
|
2250
2359
|
function Status(code) {
|
|
2251
2360
|
return createDecorator(StatusDecorator, { code });
|
|
@@ -2255,15 +2364,10 @@ function Status(code) {
|
|
|
2255
2364
|
//#region src/Decorators/Http/Redirect.ts
|
|
2256
2365
|
var RedirectDecorator = class extends BaseDecorator {
|
|
2257
2366
|
/**
|
|
2258
|
-
|
|
2259
2367
|
* Decorator responsible for redirecting to a specified URL.
|
|
2260
|
-
|
|
2261
2368
|
* Called when the decorator is created.
|
|
2262
|
-
|
|
2263
2369
|
* Sets the location header value and status code.
|
|
2264
|
-
|
|
2265
2370
|
* @override
|
|
2266
|
-
|
|
2267
2371
|
*/
|
|
2268
2372
|
created() {
|
|
2269
2373
|
initializeMetadata(this.prototype);
|
|
@@ -2271,21 +2375,16 @@ var RedirectDecorator = class extends BaseDecorator {
|
|
|
2271
2375
|
method.actions.push({ handler: () => {
|
|
2272
2376
|
return new FastResponse(void 0, {
|
|
2273
2377
|
status: this.options.code,
|
|
2274
|
-
headers: {
|
|
2378
|
+
headers: { Location: this.options.location }
|
|
2275
2379
|
});
|
|
2276
2380
|
} });
|
|
2277
2381
|
}
|
|
2278
2382
|
};
|
|
2279
2383
|
/**
|
|
2280
|
-
|
|
2281
2384
|
* Creates a Redirect decorator.
|
|
2282
|
-
|
|
2283
2385
|
* @param {string} location - The location header value.
|
|
2284
|
-
|
|
2285
2386
|
* @param {number} [code=301] - The status code.
|
|
2286
|
-
|
|
2287
2387
|
* @returns {Function} The decorator function.
|
|
2288
|
-
|
|
2289
2388
|
*/
|
|
2290
2389
|
function Redirect(location, code = 301) {
|
|
2291
2390
|
return createDecorator(RedirectDecorator, {
|
|
@@ -2356,10 +2455,10 @@ var MultipartFormDataDecorator = class extends BaseDecorator {
|
|
|
2356
2455
|
/**
|
|
2357
2456
|
* Decorator function that marks a parameter as multipart/form-data request body.
|
|
2358
2457
|
* This decorator will automatically parse incoming multipart form data
|
|
2359
|
-
*
|
|
2458
|
+
*
|
|
2360
2459
|
* @decorator
|
|
2361
2460
|
* @returns {Function} A decorator function that can be applied to method parameters
|
|
2362
|
-
*
|
|
2461
|
+
*
|
|
2363
2462
|
* @example
|
|
2364
2463
|
* class UserController {
|
|
2365
2464
|
* uploadFile(@MultipartFormData() formData: MyData) {
|
|
@@ -2371,56 +2470,9 @@ function MultipartFormData() {
|
|
|
2371
2470
|
return createDecorator(MultipartFormDataDecorator, {});
|
|
2372
2471
|
}
|
|
2373
2472
|
|
|
2374
|
-
//#endregion
|
|
2375
|
-
//#region src/Decorators/Http/Session.ts
|
|
2376
|
-
var import_decorate$1 = __toESM(require_decorate());
|
|
2377
|
-
/**
|
|
2378
|
-
* This class is responsible for managing session decorators.
|
|
2379
|
-
*
|
|
2380
|
-
* This class extends the BaseDecorator and is used to register session information
|
|
2381
|
-
* with the MetadataResolver. It ensures that the metadata for the property is created
|
|
2382
|
-
* and adds the session information to the metadata.
|
|
2383
|
-
*
|
|
2384
|
-
* @extends {BaseDecorator<{}>}
|
|
2385
|
-
*/
|
|
2386
|
-
var SessionDecorator = class extends BaseDecorator {
|
|
2387
|
-
gRuntimeConfig;
|
|
2388
|
-
/**
|
|
2389
|
-
* Called when the decorator is created.
|
|
2390
|
-
*
|
|
2391
|
-
* This method checks if metadata for the property exists, creates it if it doesn't,
|
|
2392
|
-
* and then adds the session information to the metadata.
|
|
2393
|
-
*/
|
|
2394
|
-
created() {
|
|
2395
|
-
initializeMetadata(this.prototype);
|
|
2396
|
-
const method = initializeMetadataMethod(this.prototype, this.propertyName);
|
|
2397
|
-
method.args.push({
|
|
2398
|
-
idx: this.propertyIndex,
|
|
2399
|
-
type: "session",
|
|
2400
|
-
data: {
|
|
2401
|
-
name: this.gRuntimeConfig.runtimeConfig.session?.name ?? "vercube_session",
|
|
2402
|
-
secret: this.gRuntimeConfig.runtimeConfig.session?.secret ?? generateRandomHash(),
|
|
2403
|
-
duration: this.gRuntimeConfig.runtimeConfig.session?.duration ?? 3600 * 24 * 7
|
|
2404
|
-
}
|
|
2405
|
-
});
|
|
2406
|
-
}
|
|
2407
|
-
};
|
|
2408
|
-
(0, import_decorate$1.default)([Inject(RuntimeConfig)], SessionDecorator.prototype, "gRuntimeConfig", void 0);
|
|
2409
|
-
/**
|
|
2410
|
-
* A factory function for creating a SessionDecorator.
|
|
2411
|
-
*
|
|
2412
|
-
* This function returns a decorator function that can be used to annotate
|
|
2413
|
-
* a method parameter with session information.
|
|
2414
|
-
*
|
|
2415
|
-
* @return {Function} The decorator function.
|
|
2416
|
-
*/
|
|
2417
|
-
function Session() {
|
|
2418
|
-
return createDecorator(SessionDecorator, {});
|
|
2419
|
-
}
|
|
2420
|
-
|
|
2421
2473
|
//#endregion
|
|
2422
2474
|
//#region src/Decorators/Hooks/Listen.ts
|
|
2423
|
-
var import_decorate = __toESM(require_decorate());
|
|
2475
|
+
var import_decorate = /* @__PURE__ */ __toESM(require_decorate(), 1);
|
|
2424
2476
|
/**
|
|
2425
2477
|
* This class is responsible for managing cache decorator.
|
|
2426
2478
|
*/
|
|
@@ -2453,31 +2505,6 @@ function Listen(hookType) {
|
|
|
2453
2505
|
return createDecorator(ListenDecorator, { hookType });
|
|
2454
2506
|
}
|
|
2455
2507
|
|
|
2456
|
-
//#endregion
|
|
2457
|
-
//#region src/Services/Plugins/BasePlugin.ts
|
|
2458
|
-
/**
|
|
2459
|
-
* Represents a Plugin.
|
|
2460
|
-
*/
|
|
2461
|
-
var BasePlugin = class {
|
|
2462
|
-
/**
|
|
2463
|
-
* The name of the plugin.
|
|
2464
|
-
*/
|
|
2465
|
-
name;
|
|
2466
|
-
/**
|
|
2467
|
-
* Uses the plugin with the given app.
|
|
2468
|
-
* @param {App} app - The application instance.
|
|
2469
|
-
* @returns {void | Promise<void>} - A void or a promise that resolves to void.
|
|
2470
|
-
*/
|
|
2471
|
-
use(app, options) {}
|
|
2472
|
-
};
|
|
2473
|
-
|
|
2474
|
-
//#endregion
|
|
2475
|
-
//#region src/Services/Middleware/BaseMiddleware.ts
|
|
2476
|
-
/**
|
|
2477
|
-
* BaseMiddleware class that serves as a base for all middleware implementations.
|
|
2478
|
-
*/
|
|
2479
|
-
var BaseMiddleware = class {};
|
|
2480
|
-
|
|
2481
2508
|
//#endregion
|
|
2482
2509
|
//#region src/Errors/Http/ForbiddenError.ts
|
|
2483
2510
|
/**
|
|
@@ -2547,29 +2574,6 @@ var NotAcceptableError = class NotAcceptableError extends HttpError {
|
|
|
2547
2574
|
}
|
|
2548
2575
|
};
|
|
2549
2576
|
|
|
2550
|
-
//#endregion
|
|
2551
|
-
//#region src/Errors/Http/NotFoundError.ts
|
|
2552
|
-
/**
|
|
2553
|
-
* Represents a Not Found error (HTTP 404).
|
|
2554
|
-
* @extends {HttpError}
|
|
2555
|
-
*/
|
|
2556
|
-
var NotFoundError = class NotFoundError extends HttpError {
|
|
2557
|
-
/**
|
|
2558
|
-
* The name of the error.
|
|
2559
|
-
* @type {string}
|
|
2560
|
-
*/
|
|
2561
|
-
name = "NotFoundError";
|
|
2562
|
-
/**
|
|
2563
|
-
* Creates an instance of NotFoundError.
|
|
2564
|
-
* @param {string} [message] - The error message.
|
|
2565
|
-
*/
|
|
2566
|
-
constructor(message) {
|
|
2567
|
-
super(404);
|
|
2568
|
-
Object.setPrototypeOf(this, NotFoundError.prototype);
|
|
2569
|
-
if (message) this.message = message;
|
|
2570
|
-
}
|
|
2571
|
-
};
|
|
2572
|
-
|
|
2573
2577
|
//#endregion
|
|
2574
2578
|
//#region src/Errors/Http/UnauthorizedError.ts
|
|
2575
2579
|
/**
|
|
@@ -2593,73 +2597,6 @@ var UnauthorizedError = class UnauthorizedError extends HttpError {
|
|
|
2593
2597
|
}
|
|
2594
2598
|
};
|
|
2595
2599
|
|
|
2596
|
-
//#endregion
|
|
2597
|
-
//#region src/Types/HttpTypes.ts
|
|
2598
|
-
let HTTPStatus = /* @__PURE__ */ function(HTTPStatus$1) {
|
|
2599
|
-
HTTPStatus$1[HTTPStatus$1["CONTINUE"] = 100] = "CONTINUE";
|
|
2600
|
-
HTTPStatus$1[HTTPStatus$1["SWITCHING_PROTOCOLS"] = 101] = "SWITCHING_PROTOCOLS";
|
|
2601
|
-
HTTPStatus$1[HTTPStatus$1["PROCESSING"] = 102] = "PROCESSING";
|
|
2602
|
-
HTTPStatus$1[HTTPStatus$1["OK"] = 200] = "OK";
|
|
2603
|
-
HTTPStatus$1[HTTPStatus$1["CREATED"] = 201] = "CREATED";
|
|
2604
|
-
HTTPStatus$1[HTTPStatus$1["ACCEPTED"] = 202] = "ACCEPTED";
|
|
2605
|
-
HTTPStatus$1[HTTPStatus$1["NON_AUTHORITATIVE_INFORMATION"] = 203] = "NON_AUTHORITATIVE_INFORMATION";
|
|
2606
|
-
HTTPStatus$1[HTTPStatus$1["NO_CONTENT"] = 204] = "NO_CONTENT";
|
|
2607
|
-
HTTPStatus$1[HTTPStatus$1["RESET_CONTENT"] = 205] = "RESET_CONTENT";
|
|
2608
|
-
HTTPStatus$1[HTTPStatus$1["PARTIAL_CONTENT"] = 206] = "PARTIAL_CONTENT";
|
|
2609
|
-
HTTPStatus$1[HTTPStatus$1["MULTI_STATUS"] = 207] = "MULTI_STATUS";
|
|
2610
|
-
HTTPStatus$1[HTTPStatus$1["ALREADY_REPORTED"] = 208] = "ALREADY_REPORTED";
|
|
2611
|
-
HTTPStatus$1[HTTPStatus$1["IM_USED"] = 226] = "IM_USED";
|
|
2612
|
-
HTTPStatus$1[HTTPStatus$1["MULTIPLE_CHOICES"] = 300] = "MULTIPLE_CHOICES";
|
|
2613
|
-
HTTPStatus$1[HTTPStatus$1["MOVED_PERMANENTLY"] = 301] = "MOVED_PERMANENTLY";
|
|
2614
|
-
HTTPStatus$1[HTTPStatus$1["FOUND"] = 302] = "FOUND";
|
|
2615
|
-
HTTPStatus$1[HTTPStatus$1["SEE_OTHER"] = 303] = "SEE_OTHER";
|
|
2616
|
-
HTTPStatus$1[HTTPStatus$1["NOT_MODIFIED"] = 304] = "NOT_MODIFIED";
|
|
2617
|
-
HTTPStatus$1[HTTPStatus$1["USE_PROXY"] = 305] = "USE_PROXY";
|
|
2618
|
-
HTTPStatus$1[HTTPStatus$1["TEMPORARY_REDIRECT"] = 307] = "TEMPORARY_REDIRECT";
|
|
2619
|
-
HTTPStatus$1[HTTPStatus$1["PERMANENT_REDIRECT"] = 308] = "PERMANENT_REDIRECT";
|
|
2620
|
-
HTTPStatus$1[HTTPStatus$1["BAD_REQUEST"] = 400] = "BAD_REQUEST";
|
|
2621
|
-
HTTPStatus$1[HTTPStatus$1["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
|
|
2622
|
-
HTTPStatus$1[HTTPStatus$1["PAYMENT_REQUIRED"] = 402] = "PAYMENT_REQUIRED";
|
|
2623
|
-
HTTPStatus$1[HTTPStatus$1["FORBIDDEN"] = 403] = "FORBIDDEN";
|
|
2624
|
-
HTTPStatus$1[HTTPStatus$1["NOT_FOUND"] = 404] = "NOT_FOUND";
|
|
2625
|
-
HTTPStatus$1[HTTPStatus$1["METHOD_NOT_ALLOWED"] = 405] = "METHOD_NOT_ALLOWED";
|
|
2626
|
-
HTTPStatus$1[HTTPStatus$1["NOT_ACCEPTABLE"] = 406] = "NOT_ACCEPTABLE";
|
|
2627
|
-
HTTPStatus$1[HTTPStatus$1["PROXY_AUTHENTICATION_REQUIRED"] = 407] = "PROXY_AUTHENTICATION_REQUIRED";
|
|
2628
|
-
HTTPStatus$1[HTTPStatus$1["REQUEST_TIMEOUT"] = 408] = "REQUEST_TIMEOUT";
|
|
2629
|
-
HTTPStatus$1[HTTPStatus$1["CONFLICT"] = 409] = "CONFLICT";
|
|
2630
|
-
HTTPStatus$1[HTTPStatus$1["GONE"] = 410] = "GONE";
|
|
2631
|
-
HTTPStatus$1[HTTPStatus$1["LENGTH_REQUIRED"] = 411] = "LENGTH_REQUIRED";
|
|
2632
|
-
HTTPStatus$1[HTTPStatus$1["PRECONDITION_FAILED"] = 412] = "PRECONDITION_FAILED";
|
|
2633
|
-
HTTPStatus$1[HTTPStatus$1["PAYLOAD_TOO_LARGE"] = 413] = "PAYLOAD_TOO_LARGE";
|
|
2634
|
-
HTTPStatus$1[HTTPStatus$1["URI_TOO_LONG"] = 414] = "URI_TOO_LONG";
|
|
2635
|
-
HTTPStatus$1[HTTPStatus$1["UNSUPPORTED_MEDIA_TYPE"] = 415] = "UNSUPPORTED_MEDIA_TYPE";
|
|
2636
|
-
HTTPStatus$1[HTTPStatus$1["RANGE_NOT_SATISFIABLE"] = 416] = "RANGE_NOT_SATISFIABLE";
|
|
2637
|
-
HTTPStatus$1[HTTPStatus$1["EXPECTATION_FAILED"] = 417] = "EXPECTATION_FAILED";
|
|
2638
|
-
HTTPStatus$1[HTTPStatus$1["I_AM_A_TEAPOT"] = 418] = "I_AM_A_TEAPOT";
|
|
2639
|
-
HTTPStatus$1[HTTPStatus$1["MISDIRECTED_REQUEST"] = 421] = "MISDIRECTED_REQUEST";
|
|
2640
|
-
HTTPStatus$1[HTTPStatus$1["UNPROCESSABLE_ENTITY"] = 422] = "UNPROCESSABLE_ENTITY";
|
|
2641
|
-
HTTPStatus$1[HTTPStatus$1["LOCKED"] = 423] = "LOCKED";
|
|
2642
|
-
HTTPStatus$1[HTTPStatus$1["FAILED_DEPENDENCY"] = 424] = "FAILED_DEPENDENCY";
|
|
2643
|
-
HTTPStatus$1[HTTPStatus$1["TOO_EARLY"] = 425] = "TOO_EARLY";
|
|
2644
|
-
HTTPStatus$1[HTTPStatus$1["UPGRADE_REQUIRED"] = 426] = "UPGRADE_REQUIRED";
|
|
2645
|
-
HTTPStatus$1[HTTPStatus$1["PRECONDITION_REQUIRED"] = 428] = "PRECONDITION_REQUIRED";
|
|
2646
|
-
HTTPStatus$1[HTTPStatus$1["TOO_MANY_REQUESTS"] = 429] = "TOO_MANY_REQUESTS";
|
|
2647
|
-
HTTPStatus$1[HTTPStatus$1["REQUEST_HEADER_FIELDS_TOO_LARGE"] = 431] = "REQUEST_HEADER_FIELDS_TOO_LARGE";
|
|
2648
|
-
HTTPStatus$1[HTTPStatus$1["UNAVAILABLE_FOR_LEGAL_REASONS"] = 451] = "UNAVAILABLE_FOR_LEGAL_REASONS";
|
|
2649
|
-
HTTPStatus$1[HTTPStatus$1["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
|
|
2650
|
-
HTTPStatus$1[HTTPStatus$1["NOT_IMPLEMENTED"] = 501] = "NOT_IMPLEMENTED";
|
|
2651
|
-
HTTPStatus$1[HTTPStatus$1["BAD_GATEWAY"] = 502] = "BAD_GATEWAY";
|
|
2652
|
-
HTTPStatus$1[HTTPStatus$1["SERVICE_UNAVAILABLE"] = 503] = "SERVICE_UNAVAILABLE";
|
|
2653
|
-
HTTPStatus$1[HTTPStatus$1["GATEWAY_TIMEOUT"] = 504] = "GATEWAY_TIMEOUT";
|
|
2654
|
-
HTTPStatus$1[HTTPStatus$1["HTTP_VERSION_NOT_SUPPORTED"] = 505] = "HTTP_VERSION_NOT_SUPPORTED";
|
|
2655
|
-
HTTPStatus$1[HTTPStatus$1["VARIANT_ALSO_NEGOTIATES"] = 506] = "VARIANT_ALSO_NEGOTIATES";
|
|
2656
|
-
HTTPStatus$1[HTTPStatus$1["INSUFFICIENT_STORAGE"] = 507] = "INSUFFICIENT_STORAGE";
|
|
2657
|
-
HTTPStatus$1[HTTPStatus$1["LOOP_DETECTED"] = 508] = "LOOP_DETECTED";
|
|
2658
|
-
HTTPStatus$1[HTTPStatus$1["NOT_EXTENDED"] = 510] = "NOT_EXTENDED";
|
|
2659
|
-
HTTPStatus$1[HTTPStatus$1["NETWORK_AUTHENTICATION_REQUIRED"] = 511] = "NETWORK_AUTHENTICATION_REQUIRED";
|
|
2660
|
-
return HTTPStatus$1;
|
|
2661
|
-
}({});
|
|
2662
|
-
|
|
2663
2600
|
//#endregion
|
|
2664
2601
|
//#region src/Types/HttpCodes.ts
|
|
2665
2602
|
/**
|
|
@@ -2991,4 +2928,4 @@ let HttpStatusCode = /* @__PURE__ */ function(HttpStatusCode$1) {
|
|
|
2991
2928
|
}({});
|
|
2992
2929
|
|
|
2993
2930
|
//#endregion
|
|
2994
|
-
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 };
|