@vercube/core 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +1193 -0
- package/dist/index.mjs +175 -174
- package/package.json +8 -23
- package/dist/Common/App.d.ts +0 -65
- package/dist/Common/Container.d.ts +0 -8
- package/dist/Common/CreateApp.d.ts +0 -8
- package/dist/Config/Config.d.ts +0 -7
- package/dist/Config/DefaultConfig.d.ts +0 -6
- package/dist/Config/Loader.d.ts +0 -7
- package/dist/Decorators/Hooks/Listen.d.ts +0 -9
- package/dist/Decorators/Http/Body.d.ts +0 -15
- package/dist/Decorators/Http/Connect.d.ts +0 -10
- package/dist/Decorators/Http/Controller.d.ts +0 -10
- package/dist/Decorators/Http/Delete.d.ts +0 -10
- package/dist/Decorators/Http/Get.d.ts +0 -10
- package/dist/Decorators/Http/Head.d.ts +0 -10
- package/dist/Decorators/Http/Header.d.ts +0 -11
- package/dist/Decorators/Http/Headers.d.ts +0 -9
- package/dist/Decorators/Http/Middleware.d.ts +0 -27
- package/dist/Decorators/Http/MultipartFormData.d.ts +0 -15
- package/dist/Decorators/Http/Options.d.ts +0 -10
- package/dist/Decorators/Http/Param.d.ts +0 -12
- package/dist/Decorators/Http/Patch.d.ts +0 -10
- package/dist/Decorators/Http/Post.d.ts +0 -10
- package/dist/Decorators/Http/Put.d.ts +0 -10
- package/dist/Decorators/Http/QueryParam.d.ts +0 -16
- package/dist/Decorators/Http/QueryParams.d.ts +0 -15
- package/dist/Decorators/Http/Redirect.d.ts +0 -13
- package/dist/Decorators/Http/Request.d.ts +0 -9
- package/dist/Decorators/Http/Response.d.ts +0 -9
- package/dist/Decorators/Http/Session.d.ts +0 -9
- package/dist/Decorators/Http/SetHeader.d.ts +0 -7
- package/dist/Decorators/Http/Status.d.ts +0 -11
- package/dist/Decorators/Http/Trace.d.ts +0 -10
- package/dist/Errors/Http/BadRequestError.d.ts +0 -17
- package/dist/Errors/Http/ForbiddenError.d.ts +0 -17
- package/dist/Errors/Http/InternalServerError.d.ts +0 -17
- package/dist/Errors/Http/MethodNotAllowedError.d.ts +0 -17
- package/dist/Errors/Http/NotAcceptableError.d.ts +0 -17
- package/dist/Errors/Http/NotFoundError.d.ts +0 -17
- package/dist/Errors/Http/UnauthorizedError.d.ts +0 -17
- package/dist/Errors/HttpError.d.ts +0 -17
- package/dist/Hooks/Router/RouterAfterInitHook.d.ts +0 -1
- package/dist/Hooks/Router/RouterBeforeInitHook.d.ts +0 -1
- package/dist/Middleware/ValidationMiddleware.d.ts +0 -23
- package/dist/Resolvers/Body.d.ts +0 -22
- package/dist/Resolvers/Headers.d.ts +0 -14
- package/dist/Resolvers/Query.d.ts +0 -14
- package/dist/Resolvers/RouterParam.d.ts +0 -13
- package/dist/Services/Config/RuntimeConfig.d.ts +0 -22
- package/dist/Services/ErrorHandler/DefaultErrorHandlerProvider.d.ts +0 -16
- package/dist/Services/ErrorHandler/ErrorHandlerProvider.d.ts +0 -16
- package/dist/Services/Hooks/HooksService.d.ts +0 -76
- package/dist/Services/HttpServer/HttpServer.d.ts +0 -57
- package/dist/Services/Metadata/MetadataResolver.d.ts +0 -42
- package/dist/Services/Middleware/BaseMiddleware.d.ts +0 -31
- package/dist/Services/Middleware/GlobalMiddlewareRegistry.d.ts +0 -31
- package/dist/Services/Plugins/BasePlugin.d.ts +0 -16
- package/dist/Services/Plugins/PluginsRegistry.d.ts +0 -26
- package/dist/Services/Router/RequestHandler.d.ts +0 -63
- package/dist/Services/Router/Router.d.ts +0 -40
- package/dist/Services/Router/StaticRequestHandler.d.ts +0 -38
- package/dist/Services/Validation/StandardSchemaValidationProvider.d.ts +0 -17
- package/dist/Services/Validation/ValidationProvider.d.ts +0 -17
- package/dist/Types/CommonTypes.d.ts +0 -7
- package/dist/Types/ConfigTypes.d.ts +0 -124
- package/dist/Types/HooksTypes.d.ts +0 -17
- package/dist/Types/HttpTypes.d.ts +0 -63
- package/dist/Types/MetadataTypes.d.ts +0 -56
- package/dist/Types/RouterTypes.d.ts +0 -37
- package/dist/Types/ValidationTypes.d.ts +0 -6
- package/dist/Utils/InternalUtils.d.ts +0 -1
- package/dist/Utils/Mine.d.ts +0 -3
- package/dist/Utils/Utils.d.ts +0 -22
- package/dist/index.cjs +0 -2704
- package/dist/index.d.ts +0 -52
package/dist/index.cjs
DELETED
|
@@ -1,2704 +0,0 @@
|
|
|
1
|
-
//#region rolldown:runtime
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __commonJS = (cb, mod) => function() {
|
|
9
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
13
|
-
key = keys[i];
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
15
|
-
get: ((k) => from[k]).bind(null, key),
|
|
16
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
return to;
|
|
20
|
-
};
|
|
21
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
22
|
-
value: mod,
|
|
23
|
-
enumerable: true
|
|
24
|
-
}) : target, mod));
|
|
25
|
-
|
|
26
|
-
//#endregion
|
|
27
|
-
const __vercube_di = __toESM(require("@vercube/di"));
|
|
28
|
-
const srvx = __toESM(require("srvx"));
|
|
29
|
-
const rou3 = __toESM(require("rou3"));
|
|
30
|
-
const node_fs = __toESM(require("node:fs"));
|
|
31
|
-
const node_path = __toESM(require("node:path"));
|
|
32
|
-
const node_fs_promises = __toESM(require("node:fs/promises"));
|
|
33
|
-
const __vercube_logger = __toESM(require("@vercube/logger"));
|
|
34
|
-
const c12 = __toESM(require("c12"));
|
|
35
|
-
const defu = __toESM(require("defu"));
|
|
36
|
-
|
|
37
|
-
//#region node_modules/.pnpm/@oxc-project+runtime@0.67.0/node_modules/@oxc-project/runtime/src/helpers/decorate.js
|
|
38
|
-
var require_decorate = __commonJS({ "node_modules/.pnpm/@oxc-project+runtime@0.67.0/node_modules/@oxc-project/runtime/src/helpers/decorate.js"(exports, module) {
|
|
39
|
-
function __decorate(decorators, target, key, desc) {
|
|
40
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
41
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
42
|
-
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;
|
|
43
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
44
|
-
}
|
|
45
|
-
module.exports = __decorate, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
46
|
-
} });
|
|
47
|
-
var import_decorate = __toESM(require_decorate(), 1);
|
|
48
|
-
|
|
49
|
-
//#endregion
|
|
50
|
-
//#region packages/core/src/Services/Plugins/PluginsRegistry.ts
|
|
51
|
-
var PluginsRegistry = class {
|
|
52
|
-
gContainer;
|
|
53
|
-
/** Holds the list of plugins */
|
|
54
|
-
fPlugins = new Map();
|
|
55
|
-
/**
|
|
56
|
-
* Registers a plugin.
|
|
57
|
-
*
|
|
58
|
-
* @param {Plugin} plugin - The plugin to register.
|
|
59
|
-
* @param {unknown} options - The options to pass to the plugin.
|
|
60
|
-
*/
|
|
61
|
-
register(plugin, options) {
|
|
62
|
-
const instance = this.gContainer.resolve(plugin);
|
|
63
|
-
this.fPlugins.set(instance.name, {
|
|
64
|
-
instance,
|
|
65
|
-
options
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Gets the list of registered plugins.
|
|
70
|
-
*
|
|
71
|
-
* @returns {Plugin[]} The list of registered plugins.
|
|
72
|
-
*/
|
|
73
|
-
get plugins() {
|
|
74
|
-
return [...this.fPlugins.values()].map((plugin) => plugin.instance);
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Resolves the plugins.
|
|
78
|
-
*
|
|
79
|
-
* @param {App} app - The application instance.
|
|
80
|
-
*/
|
|
81
|
-
async init(app) {
|
|
82
|
-
for (const { instance, options } of this.fPlugins.values()) await instance.use(app, options);
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
(0, import_decorate.default)([(0, __vercube_di.Inject)(__vercube_di.Container)], PluginsRegistry.prototype, "gContainer", void 0);
|
|
86
|
-
|
|
87
|
-
//#endregion
|
|
88
|
-
//#region packages/core/src/Services/Hooks/HooksService.ts
|
|
89
|
-
/**
|
|
90
|
-
* This class is responsible for managing events.
|
|
91
|
-
*/
|
|
92
|
-
var HooksService = class {
|
|
93
|
-
fLastId = 0;
|
|
94
|
-
fHandlers = new Map();
|
|
95
|
-
/**
|
|
96
|
-
* Registers listener for event of particular type. Everytime event is called, the listener
|
|
97
|
-
* will be executed.
|
|
98
|
-
*
|
|
99
|
-
* @param type type of event, simple class
|
|
100
|
-
* @param callback callback fired when event is triggered
|
|
101
|
-
* @returns unique ID for event listener, can be used to disable this listener
|
|
102
|
-
*/
|
|
103
|
-
on(type, callback) {
|
|
104
|
-
let handlersOfType = this.fHandlers.get(type);
|
|
105
|
-
if (!handlersOfType) {
|
|
106
|
-
handlersOfType = [];
|
|
107
|
-
this.fHandlers.set(type, handlersOfType);
|
|
108
|
-
}
|
|
109
|
-
const genId = this.fLastId++;
|
|
110
|
-
const handler = {
|
|
111
|
-
callback,
|
|
112
|
-
id: genId
|
|
113
|
-
};
|
|
114
|
-
handlersOfType.push(handler);
|
|
115
|
-
return {
|
|
116
|
-
__id: genId,
|
|
117
|
-
__type: type
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Waits for single event execution and removes the listener immediately after.
|
|
122
|
-
*
|
|
123
|
-
* @example
|
|
124
|
-
* this.gCart.addItem(product);
|
|
125
|
-
* await this.gEvents.waitFor(CartUpdatedEvent);
|
|
126
|
-
* console.log('here cart updated event is already called');
|
|
127
|
-
*
|
|
128
|
-
* @param type type of event to wait for
|
|
129
|
-
* @param timeout timeout param in ms - if event is not thrown until this time, it'll reject. passing null disables the timeout
|
|
130
|
-
* @returns promise with event data that resolves when event is finally called
|
|
131
|
-
*/
|
|
132
|
-
waitFor(type, timeout = 10 * 1e3) {
|
|
133
|
-
return new Promise((resolve, reject) => {
|
|
134
|
-
let waitTimeout;
|
|
135
|
-
const eventId = this.on(type, (data) => {
|
|
136
|
-
this.off(eventId);
|
|
137
|
-
resolve(data);
|
|
138
|
-
if (waitTimeout) clearTimeout(waitTimeout);
|
|
139
|
-
});
|
|
140
|
-
if (timeout !== null) waitTimeout = setTimeout(() => {
|
|
141
|
-
this.off(eventId);
|
|
142
|
-
reject(new Error(`Waiting for event timeout - ${type.name}`));
|
|
143
|
-
}, timeout);
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Removes listener from particular event.
|
|
148
|
-
* @param eventId eventId returned from .on() method.
|
|
149
|
-
* @throws Error if event was not registered
|
|
150
|
-
*/
|
|
151
|
-
off(eventId) {
|
|
152
|
-
const type = eventId.__type;
|
|
153
|
-
const handlersOfType = this.fHandlers.get(type);
|
|
154
|
-
if (!handlersOfType) throw new Error("Trying to unbind event that was not bound.");
|
|
155
|
-
const index = handlersOfType.findIndex((handler) => handler.id === eventId.__id);
|
|
156
|
-
if (index === -1) throw new Error("Trying to unbind event that was not bound.");
|
|
157
|
-
handlersOfType.splice(index, 1);
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* Triggers event, calling all listener callbacks. Will return Promise of number,
|
|
161
|
-
* that is resolved when all asynchronous listeners are called.
|
|
162
|
-
* @param type type of trigger, simple class
|
|
163
|
-
* @param data data which will be passed to listeners, based on event class
|
|
164
|
-
* @return number of listeners that were notified
|
|
165
|
-
*/
|
|
166
|
-
async trigger(type, data) {
|
|
167
|
-
const handlersOfType = this.fHandlers.get(type);
|
|
168
|
-
if (!handlersOfType) return 0;
|
|
169
|
-
const toProcessHandlers = [...handlersOfType];
|
|
170
|
-
const promises = toProcessHandlers.map((handler) => {
|
|
171
|
-
const instance = this.objectToClass(type, data);
|
|
172
|
-
const result = handler.callback(instance);
|
|
173
|
-
return result instanceof Promise ? result : Promise.resolve();
|
|
174
|
-
});
|
|
175
|
-
await Promise.all(promises);
|
|
176
|
-
return toProcessHandlers.length;
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* Converts plain object to it's class equivalent.
|
|
180
|
-
* It's NOT class-transformer, it performs basic key assigment.
|
|
181
|
-
*
|
|
182
|
-
* @param ClassConstructor event constructor
|
|
183
|
-
* @param data event data to be mapped to constructor
|
|
184
|
-
* @return class type of event
|
|
185
|
-
*/
|
|
186
|
-
objectToClass(ClassConstructor, data) {
|
|
187
|
-
const instance = new ClassConstructor();
|
|
188
|
-
if (data) for (const key of Object.keys(data)) {
|
|
189
|
-
const rawInstance = instance;
|
|
190
|
-
const rawData = data;
|
|
191
|
-
rawInstance[key] = rawData[key];
|
|
192
|
-
}
|
|
193
|
-
return instance;
|
|
194
|
-
}
|
|
195
|
-
};
|
|
196
|
-
|
|
197
|
-
//#endregion
|
|
198
|
-
//#region packages/core/src/Hooks/Router/RouterBeforeInitHook.ts
|
|
199
|
-
var RouterBeforeInitHook = class {};
|
|
200
|
-
|
|
201
|
-
//#endregion
|
|
202
|
-
//#region packages/core/src/Hooks/Router/RouterAfterInitHook.ts
|
|
203
|
-
var RouterAfterInitHook = class {};
|
|
204
|
-
|
|
205
|
-
//#endregion
|
|
206
|
-
//#region packages/core/src/Services/Router/Router.ts
|
|
207
|
-
/**
|
|
208
|
-
* Router service responsible for managing application routes
|
|
209
|
-
*
|
|
210
|
-
* This class provides functionality to initialize the router,
|
|
211
|
-
* register routes, and resolve incoming requests to their
|
|
212
|
-
* appropriate handlers.
|
|
213
|
-
*/
|
|
214
|
-
var Router = class {
|
|
215
|
-
/**
|
|
216
|
-
* Service for triggering application hooks
|
|
217
|
-
*/
|
|
218
|
-
gHooksService;
|
|
219
|
-
/**
|
|
220
|
-
* Internal router context that stores all registered routes
|
|
221
|
-
* @private
|
|
222
|
-
*/
|
|
223
|
-
fRouterContext;
|
|
224
|
-
/**
|
|
225
|
-
* Registers a new route in the router
|
|
226
|
-
*
|
|
227
|
-
* @param {RouterTypes.Route} route - The route configuration to add
|
|
228
|
-
* @throws {Error} If router is not initialized
|
|
229
|
-
*/
|
|
230
|
-
addRoute(route) {
|
|
231
|
-
if (!this.fRouterContext) throw new Error("Router not initialized. Please call init() before adding routes.");
|
|
232
|
-
(0, rou3.addRoute)(this.fRouterContext, route.method.toUpperCase(), route.path, route.handler);
|
|
233
|
-
}
|
|
234
|
-
/**
|
|
235
|
-
* Initializes the router and triggers related hooks
|
|
236
|
-
*
|
|
237
|
-
* This method creates a new router context and triggers
|
|
238
|
-
* the before and after initialization hooks.
|
|
239
|
-
*/
|
|
240
|
-
initialize() {
|
|
241
|
-
this.gHooksService.trigger(RouterBeforeInitHook);
|
|
242
|
-
this.fRouterContext = (0, rou3.createRouter)();
|
|
243
|
-
this.gHooksService.trigger(RouterAfterInitHook);
|
|
244
|
-
}
|
|
245
|
-
/**
|
|
246
|
-
* Resolves a route based on the HTTP method and path
|
|
247
|
-
*
|
|
248
|
-
* @param {RouterTypes.RouteFind} route - The route to resolve
|
|
249
|
-
* @returns {RouterTypes.RouteMatched<RouterTypes.RouterHandler> | undefined} The matched route or undefined if no match found
|
|
250
|
-
*/
|
|
251
|
-
resolve(route) {
|
|
252
|
-
let url = route.path;
|
|
253
|
-
try {
|
|
254
|
-
url = new URL(route.path).pathname;
|
|
255
|
-
} catch {}
|
|
256
|
-
return (0, rou3.findRoute)(this.fRouterContext, route.method.toUpperCase(), url);
|
|
257
|
-
}
|
|
258
|
-
};
|
|
259
|
-
(0, import_decorate.default)([(0, __vercube_di.Inject)(HooksService)], Router.prototype, "gHooksService", void 0);
|
|
260
|
-
|
|
261
|
-
//#endregion
|
|
262
|
-
//#region packages/core/src/Resolvers/RouterParam.ts
|
|
263
|
-
/**
|
|
264
|
-
* Resolves a router parameter from the event object
|
|
265
|
-
* @param param - The parameter name to resolve from the router event
|
|
266
|
-
* @param event - The router event object containing parameters
|
|
267
|
-
* @returns The resolved parameter value if it exists, null otherwise
|
|
268
|
-
* @example
|
|
269
|
-
* ```typescript
|
|
270
|
-
* const value = resolveRouterParam('id', routerEvent);
|
|
271
|
-
* // Returns the 'id' parameter value from routerEvent.params or null
|
|
272
|
-
* ```
|
|
273
|
-
*/
|
|
274
|
-
function resolveRouterParam(param, event) {
|
|
275
|
-
return event.params?.[param] ?? null;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
//#endregion
|
|
279
|
-
//#region packages/core/src/Errors/HttpError.ts
|
|
280
|
-
/**
|
|
281
|
-
* Represents an HTTP error.
|
|
282
|
-
* @extends {Error}
|
|
283
|
-
*/
|
|
284
|
-
var HttpError = class HttpError extends Error {
|
|
285
|
-
/**
|
|
286
|
-
* The HTTP status code associated with the error.
|
|
287
|
-
* @type {number}
|
|
288
|
-
*/
|
|
289
|
-
status;
|
|
290
|
-
/**
|
|
291
|
-
* Creates an instance of HttpError.
|
|
292
|
-
* @param {number} status - The HTTP status code.
|
|
293
|
-
* @param {string} [message] - The error message.
|
|
294
|
-
*/
|
|
295
|
-
constructor(status, message) {
|
|
296
|
-
super();
|
|
297
|
-
Object.setPrototypeOf(this, HttpError.prototype);
|
|
298
|
-
if (status) this.status = status;
|
|
299
|
-
if (message) this.message = message;
|
|
300
|
-
this.stack = new Error().stack;
|
|
301
|
-
}
|
|
302
|
-
};
|
|
303
|
-
|
|
304
|
-
//#endregion
|
|
305
|
-
//#region packages/core/src/Errors/Http/BadRequestError.ts
|
|
306
|
-
/**
|
|
307
|
-
* Represents a Bad Request error (HTTP 400).
|
|
308
|
-
* @extends {HttpError}
|
|
309
|
-
*/
|
|
310
|
-
var BadRequestError = class BadRequestError extends HttpError {
|
|
311
|
-
/**
|
|
312
|
-
* The name of the error.
|
|
313
|
-
* @type {string}
|
|
314
|
-
*/
|
|
315
|
-
name = "BadRequestError";
|
|
316
|
-
/**
|
|
317
|
-
* Creates an instance of BadRequestError.
|
|
318
|
-
* @param {string} [message] - The error message.
|
|
319
|
-
*/
|
|
320
|
-
constructor(message, errors) {
|
|
321
|
-
super(400);
|
|
322
|
-
Object.setPrototypeOf(this, BadRequestError.prototype);
|
|
323
|
-
if (message) this.message = message;
|
|
324
|
-
if (errors) this.errors = errors;
|
|
325
|
-
}
|
|
326
|
-
};
|
|
327
|
-
|
|
328
|
-
//#endregion
|
|
329
|
-
//#region packages/core/src/Resolvers/Body.ts
|
|
330
|
-
/**
|
|
331
|
-
* Resolves and parses the request body from a RouterEvent.
|
|
332
|
-
*
|
|
333
|
-
* @param {RouterTypes.RouterEvent} event - The router event containing the request to process
|
|
334
|
-
* @returns {Promise<unknown>} A promise that resolves to:
|
|
335
|
-
* - The parsed JSON body if the request contains valid JSON
|
|
336
|
-
* - undefined if the request body is empty
|
|
337
|
-
* @throws {BadRequestError} If the request body contains invalid JSON
|
|
338
|
-
*
|
|
339
|
-
* @example
|
|
340
|
-
* const body = await resolveRequestBody(event);
|
|
341
|
-
* if (body) {
|
|
342
|
-
* // Process the parsed body
|
|
343
|
-
* }
|
|
344
|
-
*
|
|
345
|
-
* @remarks
|
|
346
|
-
* - Currently only supports JSON content type
|
|
347
|
-
* - Returns undefined for empty request bodies
|
|
348
|
-
* - Throws BadRequestError for malformed JSON
|
|
349
|
-
*/
|
|
350
|
-
async function resolveRequestBody(event) {
|
|
351
|
-
const text = await event.request.text();
|
|
352
|
-
if (!text) return void 0;
|
|
353
|
-
try {
|
|
354
|
-
return JSON.parse(text);
|
|
355
|
-
} catch {
|
|
356
|
-
throw new BadRequestError("Invalid JSON body");
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
//#endregion
|
|
361
|
-
//#region packages/core/src/Resolvers/Query.ts
|
|
362
|
-
/**
|
|
363
|
-
* Resolves a single query parameter from the URL of a router event
|
|
364
|
-
* @param name - The name of the query parameter to resolve
|
|
365
|
-
* @param event - The router event containing the request URL
|
|
366
|
-
* @returns The value of the query parameter if found, null otherwise
|
|
367
|
-
*/
|
|
368
|
-
function resolveQueryParam(name, event) {
|
|
369
|
-
const url = new URL(event.request.url);
|
|
370
|
-
return url.searchParams.get(name);
|
|
371
|
-
}
|
|
372
|
-
/**
|
|
373
|
-
* Resolves all query parameters from the URL of a router event
|
|
374
|
-
* @param event - The router event containing the request URL
|
|
375
|
-
* @returns An object containing all query parameters as key-value pairs
|
|
376
|
-
*/
|
|
377
|
-
function resolveQueryParams(event) {
|
|
378
|
-
const url = new URL(event.request.url);
|
|
379
|
-
const params = {};
|
|
380
|
-
for (const [key, value] of url.searchParams) params[key] = value;
|
|
381
|
-
return params;
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
//#endregion
|
|
385
|
-
//#region packages/core/src/Resolvers/Headers.ts
|
|
386
|
-
/**
|
|
387
|
-
* Retrieves a specific header value from the request
|
|
388
|
-
* @param {string} header - The name of the header to retrieve
|
|
389
|
-
* @param {RouterTypes.RouterEvent} event - The router event containing the request
|
|
390
|
-
* @returns {string | null} The header value if found, null otherwise
|
|
391
|
-
*/
|
|
392
|
-
function getRequestHeader(header, event) {
|
|
393
|
-
return event.request.headers.get(header);
|
|
394
|
-
}
|
|
395
|
-
/**
|
|
396
|
-
* Retrieves all headers from the request
|
|
397
|
-
* @param {RouterTypes.RouterEvent} event - The router event containing the request
|
|
398
|
-
* @returns {Headers} The complete Headers object from the request
|
|
399
|
-
*/
|
|
400
|
-
function getRequestHeaders(event) {
|
|
401
|
-
return event.request.headers;
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
//#endregion
|
|
405
|
-
//#region packages/core/src/Services/Metadata/MetadataResolver.ts
|
|
406
|
-
/**
|
|
407
|
-
* Class responsible for resolving metadata for route handlers.
|
|
408
|
-
*/
|
|
409
|
-
var MetadataResolver = class {
|
|
410
|
-
/**
|
|
411
|
-
* Resolves the URL for a given instance and path.
|
|
412
|
-
*
|
|
413
|
-
* @param {MetadataTypes.ResolveUrlParams} params - The parameters for resolving the URL.
|
|
414
|
-
* @return {string} The resolved URL.
|
|
415
|
-
*/
|
|
416
|
-
resolveUrl(params) {
|
|
417
|
-
const { instance, propertyName, path: rawPath } = params;
|
|
418
|
-
const metadata = instance.__metadata;
|
|
419
|
-
const basePath = (metadata?.__controller?.path ?? "").replace(/\/$/, "");
|
|
420
|
-
const cleanPath = rawPath.replace(/^\//, "");
|
|
421
|
-
const url = `${basePath}/${cleanPath}`;
|
|
422
|
-
metadata.__methods[propertyName].url = url;
|
|
423
|
-
return url;
|
|
424
|
-
}
|
|
425
|
-
resolveMethod(ctx, propertyName) {
|
|
426
|
-
return ctx.__metadata.__methods[propertyName];
|
|
427
|
-
}
|
|
428
|
-
/**
|
|
429
|
-
* Resolves arguments for a given event.
|
|
430
|
-
*
|
|
431
|
-
* @param {MetadataTypes.Arg[]} args - The arguments to resolve.
|
|
432
|
-
* @param {RouterTypes.RouterEvent} event - The event to resolve arguments for.
|
|
433
|
-
* @return {unknown[]} The resolved arguments.
|
|
434
|
-
* @public
|
|
435
|
-
*/
|
|
436
|
-
async resolveArgs(args, event) {
|
|
437
|
-
args.sort((a, b) => a.idx - b.idx);
|
|
438
|
-
const resolvedArgs = args.map(async (arg) => ({
|
|
439
|
-
...arg,
|
|
440
|
-
resolved: await this.resolveArg(arg, event)
|
|
441
|
-
}));
|
|
442
|
-
return await Promise.all(resolvedArgs);
|
|
443
|
-
}
|
|
444
|
-
/**
|
|
445
|
-
* Resolves an argument for a given event.
|
|
446
|
-
*
|
|
447
|
-
* @param {MetadataTypes.Arg} arg - The argument to resolve.
|
|
448
|
-
*
|
|
449
|
-
* @return {unknown} The resolved argument.
|
|
450
|
-
* @private
|
|
451
|
-
*/
|
|
452
|
-
resolveArg(arg, event) {
|
|
453
|
-
switch (arg.type) {
|
|
454
|
-
case "param": return resolveRouterParam(arg?.data?.name ?? "", event);
|
|
455
|
-
case "body": return resolveRequestBody(event);
|
|
456
|
-
case "multipart-form-data": return null;
|
|
457
|
-
case "query-param": return resolveQueryParam(arg?.data?.name ?? "", event);
|
|
458
|
-
case "query-params": return resolveQueryParams(event);
|
|
459
|
-
case "header": return getRequestHeader(arg.data?.name ?? "", event);
|
|
460
|
-
case "headers": return getRequestHeaders(event);
|
|
461
|
-
case "request": return event.request;
|
|
462
|
-
case "response": return event.response;
|
|
463
|
-
case "custom": return arg.data?.resolve(event);
|
|
464
|
-
case "session": return null;
|
|
465
|
-
default: throw new Error(`Unknown argument type: ${arg.type}`);
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
/**
|
|
469
|
-
* Resolves middleware functions for a given context and property name.
|
|
470
|
-
*
|
|
471
|
-
* @param {MetadataTypes.Ctx} ctx - The metadata context object
|
|
472
|
-
* @param {string} propertyName - The name of the property to resolve middlewares for
|
|
473
|
-
* @returns {MetadataTypes.Middleware[]} Array of middleware functions that apply globally or to the specific property
|
|
474
|
-
* @public
|
|
475
|
-
*/
|
|
476
|
-
resolveMiddlewares(ctx, propertyName) {
|
|
477
|
-
const middlewares = ctx?.__metadata?.__middlewares?.filter((m) => m.target === "__global__" || m.target === propertyName) ?? [];
|
|
478
|
-
return middlewares.sort((a) => a.target === "__global__" ? -1 : 1);
|
|
479
|
-
}
|
|
480
|
-
};
|
|
481
|
-
|
|
482
|
-
//#endregion
|
|
483
|
-
//#region packages/core/src/Services/ErrorHandler/ErrorHandlerProvider.ts
|
|
484
|
-
/**
|
|
485
|
-
* Abstract class representing an error handler provider
|
|
486
|
-
* Provides a common interface for different error handler implementations
|
|
487
|
-
*
|
|
488
|
-
* @abstract
|
|
489
|
-
* @class ErrorHandlerProvider
|
|
490
|
-
*/
|
|
491
|
-
var ErrorHandlerProvider = class {};
|
|
492
|
-
|
|
493
|
-
//#endregion
|
|
494
|
-
//#region packages/core/src/Services/Middleware/GlobalMiddlewareRegistry.ts
|
|
495
|
-
/**
|
|
496
|
-
* Manages global middleware registration and retrieval
|
|
497
|
-
*
|
|
498
|
-
* This class provides functionality to register and retrieve global middleware
|
|
499
|
-
* configurations. It allows for adding middleware with specific options and
|
|
500
|
-
* retrieving them in a standardized format.
|
|
501
|
-
*/
|
|
502
|
-
var GlobalMiddlewareRegistry = class {
|
|
503
|
-
fMiddlewares = new Set();
|
|
504
|
-
/**
|
|
505
|
-
* Retrieves all registered global middleware configurations
|
|
506
|
-
*
|
|
507
|
-
* @returns {MetadataTypes.Middleware[]} An array of middleware configurations
|
|
508
|
-
*/
|
|
509
|
-
get middlewares() {
|
|
510
|
-
return [...this.fMiddlewares.values()].map((m) => ({
|
|
511
|
-
...m.opts,
|
|
512
|
-
target: "__global__",
|
|
513
|
-
middleware: m.middleware
|
|
514
|
-
}));
|
|
515
|
-
}
|
|
516
|
-
/**
|
|
517
|
-
* Registers a global middleware configuration
|
|
518
|
-
*
|
|
519
|
-
* @param {typeof BaseMiddleware<T, U>} middleware - The middleware class to register
|
|
520
|
-
* @param {GlobalMiddlewareParams<T>} opts - The middleware options
|
|
521
|
-
* @returns {void}
|
|
522
|
-
*/
|
|
523
|
-
registerGlobalMiddleware(middleware, opts) {
|
|
524
|
-
this.fMiddlewares.add({
|
|
525
|
-
middleware,
|
|
526
|
-
opts
|
|
527
|
-
});
|
|
528
|
-
}
|
|
529
|
-
};
|
|
530
|
-
|
|
531
|
-
//#endregion
|
|
532
|
-
//#region packages/core/src/Services/Router/RequestHandler.ts
|
|
533
|
-
/**
|
|
534
|
-
* Handles HTTP requests by preparing and executing route handlers with their associated middlewares
|
|
535
|
-
*
|
|
536
|
-
* The RequestHandler is responsible for:
|
|
537
|
-
* - Preparing route handlers with their metadata
|
|
538
|
-
* - Executing middleware chains (before and after)
|
|
539
|
-
* - Processing request/response lifecycle
|
|
540
|
-
* - Error handling during request processing
|
|
541
|
-
*/
|
|
542
|
-
var RequestHandler = class {
|
|
543
|
-
/** Resolver for extracting metadata from controller classes and methods */
|
|
544
|
-
gMetadataResolver;
|
|
545
|
-
/** DI container for resolving dependencies */
|
|
546
|
-
gContainer;
|
|
547
|
-
gGlobalMiddlewareRegistry;
|
|
548
|
-
/**
|
|
549
|
-
* Prepares a route handler by resolving its metadata and middlewares
|
|
550
|
-
*
|
|
551
|
-
* @param {RequestHandlerOptions} params - Configuration options for the handler
|
|
552
|
-
* @returns {RouterTypes.RouterHandler} A prepared handler with resolved metadata and middlewares
|
|
553
|
-
*/
|
|
554
|
-
prepareHandler(params) {
|
|
555
|
-
const { instance, propertyName } = params;
|
|
556
|
-
const prototype = Object.getPrototypeOf(instance);
|
|
557
|
-
const method = this.gMetadataResolver.resolveMethod(prototype, propertyName);
|
|
558
|
-
const middlewares = this.gMetadataResolver.resolveMiddlewares(prototype, propertyName);
|
|
559
|
-
const globalMiddlewares = this.gGlobalMiddlewareRegistry.middlewares;
|
|
560
|
-
const uniqueMiddlewares = [...middlewares, ...globalMiddlewares].filter((m, index, self) => self.findIndex((t) => t.middleware === m.middleware) === index);
|
|
561
|
-
const resolvedMiddlewares = uniqueMiddlewares.map((m) => ({
|
|
562
|
-
...m,
|
|
563
|
-
middleware: this.gContainer.resolve(m.middleware)
|
|
564
|
-
}));
|
|
565
|
-
const beforeMiddlewares = resolvedMiddlewares.filter((m) => !!m.middleware.onRequest);
|
|
566
|
-
const afterMiddlewares = resolvedMiddlewares.filter((m) => !!m.middleware.onResponse);
|
|
567
|
-
beforeMiddlewares.sort((a, b) => (a?.priority ?? 999) - (b?.priority ?? 999));
|
|
568
|
-
afterMiddlewares.sort((a, b) => (a?.priority ?? 999) - (b?.priority ?? 999));
|
|
569
|
-
return {
|
|
570
|
-
instance,
|
|
571
|
-
propertyName,
|
|
572
|
-
args: method.args,
|
|
573
|
-
middlewares: {
|
|
574
|
-
beforeMiddlewares,
|
|
575
|
-
afterMiddlewares
|
|
576
|
-
},
|
|
577
|
-
actions: method.actions
|
|
578
|
-
};
|
|
579
|
-
}
|
|
580
|
-
/**
|
|
581
|
-
* Processes an HTTP request through the middleware chain and route handler
|
|
582
|
-
*
|
|
583
|
-
* The request handling lifecycle:
|
|
584
|
-
* 1. Execute "before" middlewares
|
|
585
|
-
* 2. Apply route actions (status codes, redirects, etc.)
|
|
586
|
-
* 3. Resolve handler arguments
|
|
587
|
-
* 4. Execute the route handler
|
|
588
|
-
* 5. Execute "after" middlewares
|
|
589
|
-
* 6. Format and return the final response
|
|
590
|
-
*
|
|
591
|
-
* @param {Request} request - The incoming HTTP request
|
|
592
|
-
* @param {RouterTypes.RouteMatched<RouterTypes.RouterHandler>} route - The matched route with handler data
|
|
593
|
-
* @returns {Promise<Response>} The HTTP response
|
|
594
|
-
*/
|
|
595
|
-
async handleRequest(request, route) {
|
|
596
|
-
try {
|
|
597
|
-
const { instance, propertyName, actions = [], args = [], middlewares = {
|
|
598
|
-
beforeMiddlewares: [],
|
|
599
|
-
afterMiddlewares: []
|
|
600
|
-
} } = route.data;
|
|
601
|
-
let fakeResponse = new srvx.FastResponse(void 0, { headers: { "Content-Type": request.headers.get("Content-Type") ?? "application/json" } });
|
|
602
|
-
if (middlewares.beforeMiddlewares.length > 0) for await (const hook of middlewares.beforeMiddlewares) try {
|
|
603
|
-
const hookResponse = await hook.middleware.onRequest?.(request, fakeResponse, {
|
|
604
|
-
middlewareArgs: hook.args,
|
|
605
|
-
methodArgs: args
|
|
606
|
-
});
|
|
607
|
-
if (hookResponse instanceof Response) return hookResponse;
|
|
608
|
-
} catch (error_) {
|
|
609
|
-
this.gContainer.get(ErrorHandlerProvider).handleError(error_);
|
|
610
|
-
}
|
|
611
|
-
for (const action of actions) {
|
|
612
|
-
const actionResponse = action.handler(request, fakeResponse);
|
|
613
|
-
if (actionResponse !== null) fakeResponse = this.processOverrideResponse(actionResponse, fakeResponse);
|
|
614
|
-
}
|
|
615
|
-
const resolvedArgs = args.length > 0 ? await this.gMetadataResolver.resolveArgs(args, {
|
|
616
|
-
...route,
|
|
617
|
-
request,
|
|
618
|
-
response: fakeResponse
|
|
619
|
-
}) : [];
|
|
620
|
-
let handlerResponse = instance[propertyName].call(instance, ...resolvedArgs?.map((a) => a.resolved) ?? []);
|
|
621
|
-
if (handlerResponse instanceof Promise) handlerResponse = await handlerResponse;
|
|
622
|
-
if (middlewares.afterMiddlewares.length > 0) for await (const hook of middlewares.afterMiddlewares) try {
|
|
623
|
-
const hookResponse = await hook.middleware.onResponse?.(request, fakeResponse, handlerResponse);
|
|
624
|
-
if (hookResponse !== null) fakeResponse = this.processOverrideResponse(hookResponse, fakeResponse);
|
|
625
|
-
} catch (error_) {
|
|
626
|
-
this.gContainer.get(ErrorHandlerProvider).handleError(error_);
|
|
627
|
-
}
|
|
628
|
-
const body = fakeResponse?.body ?? JSON.stringify(handlerResponse);
|
|
629
|
-
const response = new Response(body, {
|
|
630
|
-
status: fakeResponse.status ?? 200,
|
|
631
|
-
statusText: fakeResponse.statusText ?? "OK",
|
|
632
|
-
headers: fakeResponse.headers
|
|
633
|
-
});
|
|
634
|
-
return response;
|
|
635
|
-
} catch (error_) {
|
|
636
|
-
return this.gContainer.get(ErrorHandlerProvider).handleError(error_);
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
/**
|
|
640
|
-
* Processes and merges response overrides from middlewares or actions
|
|
641
|
-
*
|
|
642
|
-
* This method handles different response formats:
|
|
643
|
-
* - If a full Response object is provided, it's used directly
|
|
644
|
-
* - If ResponseInit is provided, it's merged with the base response
|
|
645
|
-
*
|
|
646
|
-
* @param {Response | ResponseInit} response - The response or response options to apply
|
|
647
|
-
* @param {Response} [base] - The base response to extend (optional)
|
|
648
|
-
* @returns {Response} The processed response with applied overrides
|
|
649
|
-
* @private
|
|
650
|
-
*/
|
|
651
|
-
processOverrideResponse(response, base) {
|
|
652
|
-
let fakeResponse = base ?? new srvx.FastResponse();
|
|
653
|
-
if (response != null && response instanceof srvx.FastResponse) return response;
|
|
654
|
-
else if (response !== null) {
|
|
655
|
-
const responseInit = response;
|
|
656
|
-
fakeResponse = new srvx.FastResponse(void 0, {
|
|
657
|
-
status: responseInit?.status ?? fakeResponse.status,
|
|
658
|
-
headers: responseInit?.headers ?? fakeResponse.headers,
|
|
659
|
-
statusText: responseInit?.statusText ?? fakeResponse.statusText
|
|
660
|
-
});
|
|
661
|
-
}
|
|
662
|
-
return fakeResponse;
|
|
663
|
-
}
|
|
664
|
-
};
|
|
665
|
-
(0, import_decorate.default)([(0, __vercube_di.Inject)(MetadataResolver)], RequestHandler.prototype, "gMetadataResolver", void 0);
|
|
666
|
-
(0, import_decorate.default)([(0, __vercube_di.Inject)(__vercube_di.Container)], RequestHandler.prototype, "gContainer", void 0);
|
|
667
|
-
(0, import_decorate.default)([(0, __vercube_di.Inject)(GlobalMiddlewareRegistry)], RequestHandler.prototype, "gGlobalMiddlewareRegistry", void 0);
|
|
668
|
-
|
|
669
|
-
//#endregion
|
|
670
|
-
//#region packages/core/src/Utils/Mine.ts
|
|
671
|
-
const mime = { getType(ext) {
|
|
672
|
-
const types = {
|
|
673
|
-
".html": "text/html",
|
|
674
|
-
".css": "text/css",
|
|
675
|
-
".js": "application/javascript",
|
|
676
|
-
".json": "application/json",
|
|
677
|
-
".png": "image/png",
|
|
678
|
-
".jpg": "image/jpeg",
|
|
679
|
-
".jpeg": "image/jpeg",
|
|
680
|
-
".gif": "image/gif",
|
|
681
|
-
".svg": "image/svg+xml",
|
|
682
|
-
".ico": "image/x-icon"
|
|
683
|
-
};
|
|
684
|
-
return types[ext] || null;
|
|
685
|
-
} };
|
|
686
|
-
|
|
687
|
-
//#endregion
|
|
688
|
-
//#region packages/core/src/Services/Router/StaticRequestHandler.ts
|
|
689
|
-
/**
|
|
690
|
-
* Handles serving static files over HTTP
|
|
691
|
-
*
|
|
692
|
-
* The StaticRequestHandler is responsible for:
|
|
693
|
-
* - Serving static files from configured directories
|
|
694
|
-
* - Setting appropriate content types and headers
|
|
695
|
-
* - Handling caching and ETags
|
|
696
|
-
* - Processing GET requests for static assets
|
|
697
|
-
*/
|
|
698
|
-
var StaticRequestHandler = class {
|
|
699
|
-
/**
|
|
700
|
-
* The options for the static server
|
|
701
|
-
*/
|
|
702
|
-
fOptions;
|
|
703
|
-
/**
|
|
704
|
-
* Initializes the static server with the given options
|
|
705
|
-
*
|
|
706
|
-
* @param {ConfigTypes.ServerOptions['static']} options - The options for the static server
|
|
707
|
-
* @returns {void}
|
|
708
|
-
*/
|
|
709
|
-
initialize(options) {
|
|
710
|
-
this.fOptions = options;
|
|
711
|
-
}
|
|
712
|
-
/**
|
|
713
|
-
* Handles HTTP requests for static files
|
|
714
|
-
*
|
|
715
|
-
* @param {Request} request - The incoming HTTP request
|
|
716
|
-
* @returns {Promise<void | Response>} A promise that resolves to void or a Response object
|
|
717
|
-
*/
|
|
718
|
-
async handleRequest(request) {
|
|
719
|
-
const dirs = this.fOptions?.dirs ?? [];
|
|
720
|
-
if (!dirs) return;
|
|
721
|
-
if (request.method !== "GET") return;
|
|
722
|
-
const url = new URL(request.url);
|
|
723
|
-
const path = (0, node_path.normalize)(url.pathname);
|
|
724
|
-
let relativePath = path;
|
|
725
|
-
for (const dir of dirs) relativePath = relativePath.replace(dir, "");
|
|
726
|
-
for (const dir of dirs) {
|
|
727
|
-
const fullPath = (0, node_path.join)(process.cwd(), dir, relativePath);
|
|
728
|
-
try {
|
|
729
|
-
const stats = await (0, node_fs_promises.stat)(fullPath);
|
|
730
|
-
if (stats.isDirectory()) continue;
|
|
731
|
-
if (stats.isFile()) return this.serveFile(fullPath, stats);
|
|
732
|
-
} catch {
|
|
733
|
-
continue;
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
|
-
}
|
|
737
|
-
/**
|
|
738
|
-
* Serves a static file and returns a Response object
|
|
739
|
-
*
|
|
740
|
-
* @param {string} path - The path to the file to serve
|
|
741
|
-
* @param {any} stats - The stats object for the file
|
|
742
|
-
* @returns {Promise<Response>} A promise that resolves to a Response object
|
|
743
|
-
*/
|
|
744
|
-
async serveFile(path, stats) {
|
|
745
|
-
const headers = new Headers();
|
|
746
|
-
const ext = (0, node_path.extname)(path).toLowerCase();
|
|
747
|
-
const contentType = mime.getType(ext) || "application/octet-stream";
|
|
748
|
-
headers.set("Content-Type", contentType);
|
|
749
|
-
headers.set("Content-Length", stats.size.toString());
|
|
750
|
-
if (this.fOptions?.maxAge && this.fOptions.maxAge > 0) {
|
|
751
|
-
const directives = ["public", `max-age=${this.fOptions.maxAge}`];
|
|
752
|
-
if (this.fOptions?.immutable) directives.push("immutable");
|
|
753
|
-
headers.set("Cache-Control", directives.join(", "));
|
|
754
|
-
}
|
|
755
|
-
if (this.fOptions?.etag) headers.set("ETag", `W/"${stats.size}-${stats.mtime.getTime()}"`);
|
|
756
|
-
const stream = (0, node_fs.createReadStream)(path);
|
|
757
|
-
return new Response(stream, { headers });
|
|
758
|
-
}
|
|
759
|
-
};
|
|
760
|
-
|
|
761
|
-
//#endregion
|
|
762
|
-
//#region packages/core/src/Services/HttpServer/HttpServer.ts
|
|
763
|
-
/**
|
|
764
|
-
* HTTP server implementation for handling incoming web requests
|
|
765
|
-
*
|
|
766
|
-
* This class is responsible for:
|
|
767
|
-
* - Initializing and managing the HTTP server
|
|
768
|
-
* - Routing incoming requests to appropriate handlers
|
|
769
|
-
* - Processing HTTP responses
|
|
770
|
-
*/
|
|
771
|
-
var HttpServer = class {
|
|
772
|
-
/**
|
|
773
|
-
* DI container for resolving dependencies
|
|
774
|
-
*/
|
|
775
|
-
gContainer;
|
|
776
|
-
/**
|
|
777
|
-
* Router service for resolving routes
|
|
778
|
-
*/
|
|
779
|
-
gRouter;
|
|
780
|
-
/**
|
|
781
|
-
* Handler for processing HTTP requests
|
|
782
|
-
*/
|
|
783
|
-
gRequestHandler;
|
|
784
|
-
/**
|
|
785
|
-
* Static server for serving static files
|
|
786
|
-
*/
|
|
787
|
-
gStaticRequestHandler;
|
|
788
|
-
/**
|
|
789
|
-
* Underlying server instance
|
|
790
|
-
* @private
|
|
791
|
-
*/
|
|
792
|
-
fServer;
|
|
793
|
-
/**
|
|
794
|
-
* Initializes the HTTP server and starts listening for requests
|
|
795
|
-
*
|
|
796
|
-
* @returns {Promise<void>} A promise that resolves when the server is ready
|
|
797
|
-
*/
|
|
798
|
-
async initialize(config) {
|
|
799
|
-
const { port, host } = config.server ?? {};
|
|
800
|
-
this.fServer = (0, srvx.serve)({
|
|
801
|
-
bun: { error: (error) => {
|
|
802
|
-
return this.gContainer.get(ErrorHandlerProvider).handleError(error);
|
|
803
|
-
} },
|
|
804
|
-
deno: { onError: (error) => {
|
|
805
|
-
return this.gContainer.get(ErrorHandlerProvider).handleError(error);
|
|
806
|
-
} },
|
|
807
|
-
hostname: host,
|
|
808
|
-
port,
|
|
809
|
-
fetch: this.handleRequest.bind(this)
|
|
810
|
-
});
|
|
811
|
-
}
|
|
812
|
-
/**
|
|
813
|
-
* Listens for incoming requests on the HTTP server
|
|
814
|
-
*
|
|
815
|
-
* @returns {Promise<void>} A promise that resolves when the server is ready to listen
|
|
816
|
-
*/
|
|
817
|
-
async listen() {
|
|
818
|
-
await this.fServer.ready();
|
|
819
|
-
}
|
|
820
|
-
/**
|
|
821
|
-
* Processes an incoming HTTP request
|
|
822
|
-
*
|
|
823
|
-
* This method:
|
|
824
|
-
* 1. Resolves the route for the request
|
|
825
|
-
* 2. Returns a 404 response if no route is found
|
|
826
|
-
* 3. Delegates to the request handler for matched routes
|
|
827
|
-
*
|
|
828
|
-
* @param {Request} request - The incoming HTTP request
|
|
829
|
-
* @returns {Promise<Response>} The HTTP response
|
|
830
|
-
* @private
|
|
831
|
-
*/
|
|
832
|
-
async handleRequest(request) {
|
|
833
|
-
try {
|
|
834
|
-
const route = this.gRouter.resolve({
|
|
835
|
-
path: request.url,
|
|
836
|
-
method: request.method
|
|
837
|
-
});
|
|
838
|
-
if (!route) {
|
|
839
|
-
const response = await this.gStaticRequestHandler.handleRequest(request);
|
|
840
|
-
if (response) return response;
|
|
841
|
-
else throw new NotFoundError("Route not found");
|
|
842
|
-
}
|
|
843
|
-
return this.gRequestHandler.handleRequest(request, route);
|
|
844
|
-
} catch (error) {
|
|
845
|
-
return this.gContainer.get(ErrorHandlerProvider).handleError(error);
|
|
846
|
-
}
|
|
847
|
-
}
|
|
848
|
-
};
|
|
849
|
-
(0, import_decorate.default)([(0, __vercube_di.Inject)(__vercube_di.Container)], HttpServer.prototype, "gContainer", void 0);
|
|
850
|
-
(0, import_decorate.default)([(0, __vercube_di.Inject)(Router)], HttpServer.prototype, "gRouter", void 0);
|
|
851
|
-
(0, import_decorate.default)([(0, __vercube_di.Inject)(RequestHandler)], HttpServer.prototype, "gRequestHandler", void 0);
|
|
852
|
-
(0, import_decorate.default)([(0, __vercube_di.Inject)(StaticRequestHandler)], HttpServer.prototype, "gStaticRequestHandler", void 0);
|
|
853
|
-
|
|
854
|
-
//#endregion
|
|
855
|
-
//#region packages/core/src/Common/App.ts
|
|
856
|
-
/**
|
|
857
|
-
* Represents the main application class.
|
|
858
|
-
*/
|
|
859
|
-
var App = class {
|
|
860
|
-
gRouter;
|
|
861
|
-
gPluginsRegistry;
|
|
862
|
-
gHttpServer;
|
|
863
|
-
gStaticRequestHandler;
|
|
864
|
-
gLogger;
|
|
865
|
-
/** Holds the initialization status of the application */
|
|
866
|
-
fIsInitialized = false;
|
|
867
|
-
/** Holds the dependency injection container */
|
|
868
|
-
fInternalContainer;
|
|
869
|
-
/** Hold app config */
|
|
870
|
-
fConfig;
|
|
871
|
-
/**
|
|
872
|
-
* Gets the dependency injection container.
|
|
873
|
-
*
|
|
874
|
-
* @returns {Container} The dependency injection container.
|
|
875
|
-
*/
|
|
876
|
-
get container() {
|
|
877
|
-
return this.fInternalContainer;
|
|
878
|
-
}
|
|
879
|
-
/**
|
|
880
|
-
* Sets the dependency injection container.
|
|
881
|
-
*
|
|
882
|
-
* @param {Container} container - The dependency injection container.
|
|
883
|
-
*/
|
|
884
|
-
set container(container) {
|
|
885
|
-
this.fInternalContainer = container;
|
|
886
|
-
}
|
|
887
|
-
/**
|
|
888
|
-
* Initializes the application.
|
|
889
|
-
*
|
|
890
|
-
* @returns {Promise<void>} A promise that resolves when the application is initialized.
|
|
891
|
-
*/
|
|
892
|
-
async init(cfg) {
|
|
893
|
-
this.fConfig = cfg;
|
|
894
|
-
await this.gHttpServer.initialize(this.fConfig);
|
|
895
|
-
if (this.fConfig.server?.static) this.gStaticRequestHandler.initialize(this.fConfig.server?.static);
|
|
896
|
-
this.gRouter.initialize();
|
|
897
|
-
}
|
|
898
|
-
/**
|
|
899
|
-
* Registers a plugin.
|
|
900
|
-
*
|
|
901
|
-
* @param {typeof Plugin} plugin - The plugin to register.
|
|
902
|
-
* @param {unknown} options - The options to pass to the plugin.
|
|
903
|
-
*/
|
|
904
|
-
registerPlugin(plugin, options) {
|
|
905
|
-
this.gPluginsRegistry.register(plugin, options);
|
|
906
|
-
}
|
|
907
|
-
/**
|
|
908
|
-
* Starts the application and begins listening for incoming requests.
|
|
909
|
-
*
|
|
910
|
-
* @returns {Promise<void>} A promise that resolves when the application starts listening.
|
|
911
|
-
* @throws {Error} If the application is already initialized.
|
|
912
|
-
*/
|
|
913
|
-
async listen() {
|
|
914
|
-
if (this.fIsInitialized) throw new Error("App is already initialized");
|
|
915
|
-
await this.resolvePlugins();
|
|
916
|
-
(0, __vercube_di.initializeContainer)(this.container);
|
|
917
|
-
await this.gHttpServer.listen();
|
|
918
|
-
this.gLogger?.info(`\n${__vercube_logger.colors.green("➜")} App listening on port ${__vercube_logger.colors.bold(this.fConfig.server?.port?.toString() ?? "3000")}`);
|
|
919
|
-
this.fIsInitialized = true;
|
|
920
|
-
}
|
|
921
|
-
/**
|
|
922
|
-
* Handles an incoming HTTP request.
|
|
923
|
-
* This method is an adapter for HttpServer.handleRequest method.
|
|
924
|
-
*
|
|
925
|
-
* @param {Request} request - The incoming HTTP request
|
|
926
|
-
* @returns {Promise<Response>} The HTTP response
|
|
927
|
-
*/
|
|
928
|
-
async fetch(request) {
|
|
929
|
-
return this.gHttpServer.handleRequest(request);
|
|
930
|
-
}
|
|
931
|
-
/**
|
|
932
|
-
* Resolves and initializes the plugins for the application.
|
|
933
|
-
*
|
|
934
|
-
* @private
|
|
935
|
-
*/
|
|
936
|
-
async resolvePlugins() {
|
|
937
|
-
await this.gPluginsRegistry.init(this);
|
|
938
|
-
}
|
|
939
|
-
};
|
|
940
|
-
(0, import_decorate.default)([(0, __vercube_di.Inject)(Router)], App.prototype, "gRouter", void 0);
|
|
941
|
-
(0, import_decorate.default)([(0, __vercube_di.Inject)(PluginsRegistry)], App.prototype, "gPluginsRegistry", void 0);
|
|
942
|
-
(0, import_decorate.default)([(0, __vercube_di.Inject)(HttpServer)], App.prototype, "gHttpServer", void 0);
|
|
943
|
-
(0, import_decorate.default)([(0, __vercube_di.Inject)(StaticRequestHandler)], App.prototype, "gStaticRequestHandler", void 0);
|
|
944
|
-
(0, import_decorate.default)([(0, __vercube_di.InjectOptional)(__vercube_logger.Logger)], App.prototype, "gLogger", void 0);
|
|
945
|
-
|
|
946
|
-
//#endregion
|
|
947
|
-
//#region packages/logger/dist/Providers/index.mjs
|
|
948
|
-
/**
|
|
949
|
-
* Abstract base class for implementing log provider.
|
|
950
|
-
* Providers are responsible for processing and outputting log messages to various destinations.
|
|
951
|
-
* Each appender can be initialized with custom options and handles message processing according to its implementation.
|
|
952
|
-
*
|
|
953
|
-
* @template T - The type of options used to initialize the appender
|
|
954
|
-
*/
|
|
955
|
-
var LoggerProvider = class {};
|
|
956
|
-
const isColorAllowed = () => !process.env.NO_COLOR;
|
|
957
|
-
const colorIfAllowed = (colorFn) => {
|
|
958
|
-
const wrappedFn = (text) => {
|
|
959
|
-
return isColorAllowed() ? colorFn(text) : text;
|
|
960
|
-
};
|
|
961
|
-
return wrappedFn;
|
|
962
|
-
};
|
|
963
|
-
const colors = {
|
|
964
|
-
bold: colorIfAllowed((text) => `\x1B[1m${text}\x1B[0m`),
|
|
965
|
-
green: colorIfAllowed((text) => `\x1B[32m${text}\x1B[39m`),
|
|
966
|
-
yellow: colorIfAllowed((text) => `\x1B[33m${text}\x1B[39m`),
|
|
967
|
-
red: colorIfAllowed((text) => `\x1B[31m${text}\x1B[39m`),
|
|
968
|
-
magentaBright: colorIfAllowed((text) => `\x1B[95m${text}\x1B[39m`),
|
|
969
|
-
cyanBright: colorIfAllowed((text) => `\x1B[96m${text}\x1B[39m`)
|
|
970
|
-
};
|
|
971
|
-
const LOG_LEVEL_COLORS = {
|
|
972
|
-
debug: colors.green,
|
|
973
|
-
info: colors.bold,
|
|
974
|
-
warn: colors.yellow,
|
|
975
|
-
error: colors.red
|
|
976
|
-
};
|
|
977
|
-
/**
|
|
978
|
-
* ConsoleProvider class for logging messages to the console.
|
|
979
|
-
*/
|
|
980
|
-
var ConsoleProvider = class extends LoggerProvider {
|
|
981
|
-
/**
|
|
982
|
-
* Initializes the appender with the provided options.
|
|
983
|
-
* This method should be called before using the appender to process messages.
|
|
984
|
-
*/
|
|
985
|
-
initialize() {}
|
|
986
|
-
/**
|
|
987
|
-
* Prints a log message according to the specified format and level.
|
|
988
|
-
* @param message - The log message object containing level, tag, and arguments
|
|
989
|
-
* @protected
|
|
990
|
-
*/
|
|
991
|
-
processMessage(message) {
|
|
992
|
-
const date = message.timestamp ? new Date(message.timestamp) : new Date();
|
|
993
|
-
console[message.level](`%s%s${message?.tag ? "%s" : ""} %s`, LOG_LEVEL_COLORS[message.level](`[${date.toISOString().split("T")[1]?.replace("Z", "")}]`), LOG_LEVEL_COLORS[message.level](`[${message.level.toUpperCase().padEnd(5, " ")}]`), message?.tag ? LOG_LEVEL_COLORS[message.level](`[${message.tag}]`) : "", ...message.args);
|
|
994
|
-
}
|
|
995
|
-
};
|
|
996
|
-
|
|
997
|
-
//#endregion
|
|
998
|
-
//#region packages/core/src/Services/Validation/ValidationProvider.ts
|
|
999
|
-
/**
|
|
1000
|
-
* Abstract class representing a validation provider
|
|
1001
|
-
* Provides a common interface for different validation implementations
|
|
1002
|
-
*
|
|
1003
|
-
* @abstract
|
|
1004
|
-
* @class ValidationProvider
|
|
1005
|
-
*/
|
|
1006
|
-
var ValidationProvider = class {};
|
|
1007
|
-
|
|
1008
|
-
//#endregion
|
|
1009
|
-
//#region packages/core/src/Services/Validation/StandardSchemaValidationProvider.ts
|
|
1010
|
-
/**
|
|
1011
|
-
* StandardSchemaValidationProvider implements validation using StandardSchema schema validation
|
|
1012
|
-
* @see https://github.com/standard-schema/standard-schema
|
|
1013
|
-
* @class
|
|
1014
|
-
* @implements {ValidationProvider}
|
|
1015
|
-
*/
|
|
1016
|
-
var StandardSchemaValidationProvider = class {
|
|
1017
|
-
/**
|
|
1018
|
-
* Validates data against a schema
|
|
1019
|
-
* @param {ValidationTypes.Schema} schema - The schema to validate against
|
|
1020
|
-
* @param {ValidationTypes.Input} data - The data to validate
|
|
1021
|
-
* @return {ValidationTypes.Result | Promise<ValidationTypes.Result>} The validation result
|
|
1022
|
-
*/
|
|
1023
|
-
validate(schema, data) {
|
|
1024
|
-
return schema["~standard"].validate(data);
|
|
1025
|
-
}
|
|
1026
|
-
};
|
|
1027
|
-
|
|
1028
|
-
//#endregion
|
|
1029
|
-
//#region packages/core/src/Services/Config/RuntimeConfig.ts
|
|
1030
|
-
/**
|
|
1031
|
-
* RuntimeConfig class manages the runtime configuration for the Vercube application.
|
|
1032
|
-
* This class provides a centralized way to access and modify runtime configuration settings.
|
|
1033
|
-
*/
|
|
1034
|
-
var RuntimeConfig = class {
|
|
1035
|
-
/**
|
|
1036
|
-
* Private field to store the runtime configuration object.
|
|
1037
|
-
* @private
|
|
1038
|
-
*/
|
|
1039
|
-
fRuntimeConfig;
|
|
1040
|
-
/**
|
|
1041
|
-
* Gets the current runtime configuration.
|
|
1042
|
-
* @returns {ConfigTypes.RuntimeConfig} The current runtime configuration object.
|
|
1043
|
-
*/
|
|
1044
|
-
get runtimeConfig() {
|
|
1045
|
-
return this.fRuntimeConfig;
|
|
1046
|
-
}
|
|
1047
|
-
/**
|
|
1048
|
-
* Sets the runtime configuration.
|
|
1049
|
-
* @param {ConfigTypes.RuntimeConfig} value - The new runtime configuration object to set.
|
|
1050
|
-
*/
|
|
1051
|
-
set runtimeConfig(value) {
|
|
1052
|
-
this.fRuntimeConfig = value;
|
|
1053
|
-
}
|
|
1054
|
-
};
|
|
1055
|
-
|
|
1056
|
-
//#endregion
|
|
1057
|
-
//#region packages/core/src/Errors/Http/InternalServerError.ts
|
|
1058
|
-
/**
|
|
1059
|
-
* Represents an Internal Server error (HTTP 500).
|
|
1060
|
-
* @extends {HttpError}
|
|
1061
|
-
*/
|
|
1062
|
-
var InternalServerError = class InternalServerError extends HttpError {
|
|
1063
|
-
/**
|
|
1064
|
-
* The name of the error.
|
|
1065
|
-
* @type {string}
|
|
1066
|
-
*/
|
|
1067
|
-
name = "InternalServerError";
|
|
1068
|
-
/**
|
|
1069
|
-
* Creates an instance of InternalServerError.
|
|
1070
|
-
* @param {string} [message] - The error message.
|
|
1071
|
-
*/
|
|
1072
|
-
constructor(message) {
|
|
1073
|
-
super(500);
|
|
1074
|
-
Object.setPrototypeOf(this, InternalServerError.prototype);
|
|
1075
|
-
if (message) this.message = message;
|
|
1076
|
-
}
|
|
1077
|
-
};
|
|
1078
|
-
|
|
1079
|
-
//#endregion
|
|
1080
|
-
//#region packages/core/src/Services/ErrorHandler/DefaultErrorHandlerProvider.ts
|
|
1081
|
-
/**
|
|
1082
|
-
* Default error handler provider
|
|
1083
|
-
*
|
|
1084
|
-
* @class DefaultErrorHandlerProvider
|
|
1085
|
-
*/
|
|
1086
|
-
var DefaultErrorHandlerProvider = class extends ErrorHandlerProvider {
|
|
1087
|
-
gLogger;
|
|
1088
|
-
/**
|
|
1089
|
-
* Handles an error that occurred during request processing
|
|
1090
|
-
*
|
|
1091
|
-
* @param error - The Error object containing error details
|
|
1092
|
-
* @returns Promise<Response> | Response - The response to be sent to the client
|
|
1093
|
-
*/
|
|
1094
|
-
handleError(error) {
|
|
1095
|
-
const _internalError = new InternalServerError(error?.message ?? "Internal server error");
|
|
1096
|
-
const status = error?.status ?? 500;
|
|
1097
|
-
if (error instanceof HttpError) return new srvx.FastResponse(JSON.stringify({ ...error }, void 0, 2), { status });
|
|
1098
|
-
this.gLogger.error(error);
|
|
1099
|
-
return new srvx.FastResponse(JSON.stringify({ ...error?.cause ?? _internalError }, void 0, 2), { status });
|
|
1100
|
-
}
|
|
1101
|
-
};
|
|
1102
|
-
(0, import_decorate.default)([(0, __vercube_di.Inject)(__vercube_logger.Logger)], DefaultErrorHandlerProvider.prototype, "gLogger", void 0);
|
|
1103
|
-
|
|
1104
|
-
//#endregion
|
|
1105
|
-
//#region packages/core/src/Common/Container.ts
|
|
1106
|
-
/**
|
|
1107
|
-
* Creates and configures a new dependency injection container for the application.
|
|
1108
|
-
*
|
|
1109
|
-
* @returns {Container} A configured dependency injection container.
|
|
1110
|
-
*/
|
|
1111
|
-
function createContainer(config) {
|
|
1112
|
-
const container = new __vercube_di.Container();
|
|
1113
|
-
container.bindInstance(__vercube_di.Container, container);
|
|
1114
|
-
container.bind(__vercube_logger.Logger, __vercube_logger.BaseLogger);
|
|
1115
|
-
container.get(__vercube_logger.Logger).configure({
|
|
1116
|
-
logLevel: config.logLevel ?? "debug",
|
|
1117
|
-
providers: [{
|
|
1118
|
-
name: "console",
|
|
1119
|
-
provider: ConsoleProvider
|
|
1120
|
-
}]
|
|
1121
|
-
});
|
|
1122
|
-
container.bind(ErrorHandlerProvider, DefaultErrorHandlerProvider);
|
|
1123
|
-
container.bind(HttpServer);
|
|
1124
|
-
container.bind(StaticRequestHandler);
|
|
1125
|
-
container.bind(Router);
|
|
1126
|
-
container.bind(HooksService);
|
|
1127
|
-
container.bind(MetadataResolver);
|
|
1128
|
-
container.bind(PluginsRegistry);
|
|
1129
|
-
container.bind(RequestHandler);
|
|
1130
|
-
container.bind(RuntimeConfig);
|
|
1131
|
-
container.bind(GlobalMiddlewareRegistry);
|
|
1132
|
-
container.bind(ValidationProvider, StandardSchemaValidationProvider);
|
|
1133
|
-
return container;
|
|
1134
|
-
}
|
|
1135
|
-
|
|
1136
|
-
//#endregion
|
|
1137
|
-
//#region packages/core/src/Utils/InternalUtils.ts
|
|
1138
|
-
/**
|
|
1139
|
-
* Generate random hash
|
|
1140
|
-
* @returns string
|
|
1141
|
-
*/
|
|
1142
|
-
function generateRandomHash() {
|
|
1143
|
-
const hashByPerformance = Math.floor(Date.now() * 1e3).toString(16);
|
|
1144
|
-
const hashByMath = () => (Math.floor(Math.random() * 16777215) | 1048576).toString(16);
|
|
1145
|
-
return `${hashByPerformance}-${hashByMath()}-${hashByMath()}-${hashByMath()}`;
|
|
1146
|
-
}
|
|
1147
|
-
|
|
1148
|
-
//#endregion
|
|
1149
|
-
//#region packages/core/src/Config/DefaultConfig.ts
|
|
1150
|
-
/**
|
|
1151
|
-
* Default configuration for the Vercube application.
|
|
1152
|
-
* This configuration serves as the base settings and can be overridden by user configuration.
|
|
1153
|
-
*/
|
|
1154
|
-
const defaultConfig = {
|
|
1155
|
-
logLevel: "debug",
|
|
1156
|
-
production: false,
|
|
1157
|
-
dev: false,
|
|
1158
|
-
build: {
|
|
1159
|
-
root: process.cwd(),
|
|
1160
|
-
entry: "src/index.ts",
|
|
1161
|
-
output: {
|
|
1162
|
-
dir: "dist",
|
|
1163
|
-
publicDir: "public"
|
|
1164
|
-
},
|
|
1165
|
-
bundler: "rolldown"
|
|
1166
|
-
},
|
|
1167
|
-
server: {
|
|
1168
|
-
runtime: "node",
|
|
1169
|
-
host: "localhost",
|
|
1170
|
-
port: 3e3,
|
|
1171
|
-
https: false,
|
|
1172
|
-
static: { dirs: ["public"] }
|
|
1173
|
-
},
|
|
1174
|
-
experimental: {},
|
|
1175
|
-
runtime: { session: {
|
|
1176
|
-
secret: process.env?.SECRET ?? generateRandomHash(),
|
|
1177
|
-
name: "vercube_session",
|
|
1178
|
-
duration: 60 * 60 * 24 * 7
|
|
1179
|
-
} }
|
|
1180
|
-
};
|
|
1181
|
-
|
|
1182
|
-
//#endregion
|
|
1183
|
-
//#region packages/core/src/Config/Loader.ts
|
|
1184
|
-
/**
|
|
1185
|
-
* Loads the configuration object for the application
|
|
1186
|
-
* @param {ConfigTypes.Config} overrides - The configuration object to load
|
|
1187
|
-
* @returns {ConfigTypes.Config} The loaded configuration object
|
|
1188
|
-
*/
|
|
1189
|
-
async function loadVercubeConfig(overrides) {
|
|
1190
|
-
const config = await (0, c12.loadConfig)({
|
|
1191
|
-
name: "vercube",
|
|
1192
|
-
dotenv: true,
|
|
1193
|
-
rcFile: false,
|
|
1194
|
-
globalRc: false,
|
|
1195
|
-
defaults: defaultConfig
|
|
1196
|
-
});
|
|
1197
|
-
return (0, defu.defu)(overrides ?? {}, config?.config ?? {});
|
|
1198
|
-
}
|
|
1199
|
-
|
|
1200
|
-
//#endregion
|
|
1201
|
-
//#region packages/core/src/Common/CreateApp.ts
|
|
1202
|
-
/**
|
|
1203
|
-
* Creates and initializes an instance of the App.
|
|
1204
|
-
*
|
|
1205
|
-
* @returns {Promise<App>} A promise that resolves to an instance of the App.
|
|
1206
|
-
*/
|
|
1207
|
-
async function createApp(cfg) {
|
|
1208
|
-
const config = await loadVercubeConfig(cfg);
|
|
1209
|
-
const container = createContainer(config);
|
|
1210
|
-
const app = container.resolve(App);
|
|
1211
|
-
container.get(RuntimeConfig).runtimeConfig = config?.runtime ?? {};
|
|
1212
|
-
app.container = container;
|
|
1213
|
-
await app.init(config);
|
|
1214
|
-
(0, __vercube_di.initializeContainer)(container);
|
|
1215
|
-
return app;
|
|
1216
|
-
}
|
|
1217
|
-
|
|
1218
|
-
//#endregion
|
|
1219
|
-
//#region packages/core/src/Config/Config.ts
|
|
1220
|
-
/**
|
|
1221
|
-
* Defines a configuration object for the application
|
|
1222
|
-
* @param {ConfigTypes.Config} config - The configuration object to validate
|
|
1223
|
-
* @returns {ConfigTypes.Config} The validated configuration object
|
|
1224
|
-
*/
|
|
1225
|
-
function defineConfig(config) {
|
|
1226
|
-
return config;
|
|
1227
|
-
}
|
|
1228
|
-
|
|
1229
|
-
//#endregion
|
|
1230
|
-
//#region packages/core/src/Middleware/ValidationMiddleware.ts
|
|
1231
|
-
/**
|
|
1232
|
-
* Middleware for validating request data against a schema
|
|
1233
|
-
* @class ValidationMiddleware
|
|
1234
|
-
* @implements {BaseMiddleware}
|
|
1235
|
-
* @description Validates incoming request data against a provided schema
|
|
1236
|
-
* @example
|
|
1237
|
-
* const middleware = new ValidationMiddleware();
|
|
1238
|
-
* await middleware.use(event, { schema: myValidationSchema });
|
|
1239
|
-
*/
|
|
1240
|
-
var ValidationMiddleware = class {
|
|
1241
|
-
gValidationProvider;
|
|
1242
|
-
/**
|
|
1243
|
-
* Middleware function that processes the HTTP event
|
|
1244
|
-
* @param {Request} request - The HTTP request object
|
|
1245
|
-
* @param {Response} response - The HTTP response object
|
|
1246
|
-
* @param {MiddlewareOptions} args - Additional arguments for the middleware
|
|
1247
|
-
* @returns {Promise<void>} - A promise that resolves when the processing is complete
|
|
1248
|
-
* @throws {BadRequestError} - If validation fails
|
|
1249
|
-
*/
|
|
1250
|
-
async onRequest(request, response, args) {
|
|
1251
|
-
if (!this.gValidationProvider) {
|
|
1252
|
-
console.warn("ValidationMiddleware::ValidationProvider is not registered");
|
|
1253
|
-
return;
|
|
1254
|
-
}
|
|
1255
|
-
const validators = args.methodArgs?.filter((arg) => arg.validate && arg.validationSchema) ?? [];
|
|
1256
|
-
for (const validator of validators) {
|
|
1257
|
-
const result = await this.gValidationProvider.validate(validator.validationSchema, validator.resolved);
|
|
1258
|
-
if (result.issues?.length) throw new BadRequestError(`Validation error - ${validator.type}`, result.issues);
|
|
1259
|
-
}
|
|
1260
|
-
}
|
|
1261
|
-
};
|
|
1262
|
-
(0, import_decorate.default)([(0, __vercube_di.InjectOptional)(ValidationProvider)], ValidationMiddleware.prototype, "gValidationProvider", void 0);
|
|
1263
|
-
|
|
1264
|
-
//#endregion
|
|
1265
|
-
//#region packages/core/src/Utils/Utils.ts
|
|
1266
|
-
/**
|
|
1267
|
-
* Creates a new metadata context.
|
|
1268
|
-
* @returns {MetadataTypes.Ctx} The new metadata context.
|
|
1269
|
-
*/
|
|
1270
|
-
function createMetadataCtx() {
|
|
1271
|
-
return {
|
|
1272
|
-
__controller: { path: "" },
|
|
1273
|
-
__middlewares: [],
|
|
1274
|
-
__methods: {}
|
|
1275
|
-
};
|
|
1276
|
-
}
|
|
1277
|
-
/**
|
|
1278
|
-
* Creates a new metadata method.
|
|
1279
|
-
* @returns {MetadataTypes.Method} The new metadata method.
|
|
1280
|
-
*/
|
|
1281
|
-
function createMetadataMethod() {
|
|
1282
|
-
return {
|
|
1283
|
-
req: null,
|
|
1284
|
-
res: null,
|
|
1285
|
-
url: null,
|
|
1286
|
-
args: [],
|
|
1287
|
-
actions: []
|
|
1288
|
-
};
|
|
1289
|
-
}
|
|
1290
|
-
/**
|
|
1291
|
-
* Initializes the metadata for a given target and property name.
|
|
1292
|
-
* @param {any} target - The target to initialize metadata for.
|
|
1293
|
-
* @param {string} propertyName - The name of the property to initialize metadata for.
|
|
1294
|
-
*/
|
|
1295
|
-
function initializeMetadataMethod(target, propertyName) {
|
|
1296
|
-
if (!target.__metadata.__methods[propertyName]) target.__metadata.__methods[propertyName] = createMetadataMethod();
|
|
1297
|
-
return target.__metadata.__methods[propertyName];
|
|
1298
|
-
}
|
|
1299
|
-
/**
|
|
1300
|
-
* Initializes the metadata for a given target.
|
|
1301
|
-
* @param {any} target - The target to initialize metadata for.
|
|
1302
|
-
*/
|
|
1303
|
-
function initializeMetadata(target) {
|
|
1304
|
-
if (!target.__metadata) target.__metadata = createMetadataCtx();
|
|
1305
|
-
if (!target.__metadata.__methods) target.__metadata.__methods = {};
|
|
1306
|
-
if (!target.__metadata.__middlewares) target.__metadata.__middlewares = [];
|
|
1307
|
-
return target.__metadata;
|
|
1308
|
-
}
|
|
1309
|
-
|
|
1310
|
-
//#endregion
|
|
1311
|
-
//#region packages/core/src/Decorators/Http/Body.ts
|
|
1312
|
-
/**
|
|
1313
|
-
* @class BodyDecorator
|
|
1314
|
-
* @extends BaseDecorator<BodyDecoratorOptions>
|
|
1315
|
-
*
|
|
1316
|
-
* A decorator class that handles the metadata for HTTP request bodies.
|
|
1317
|
-
*/
|
|
1318
|
-
var BodyDecorator = class extends __vercube_di.BaseDecorator {
|
|
1319
|
-
/**
|
|
1320
|
-
* @method created
|
|
1321
|
-
* This method is called when the decorator is created. It ensures that the metadata
|
|
1322
|
-
* for the property exists and adds the body argument to the metadata.
|
|
1323
|
-
*/
|
|
1324
|
-
created() {
|
|
1325
|
-
const meta = initializeMetadata(this.prototype);
|
|
1326
|
-
const method = initializeMetadataMethod(this.prototype, this.propertyName);
|
|
1327
|
-
method.args.push({
|
|
1328
|
-
idx: this.propertyIndex,
|
|
1329
|
-
type: "body",
|
|
1330
|
-
validate: this.options?.validationSchema ? true : false,
|
|
1331
|
-
validationSchema: this.options?.validationSchema
|
|
1332
|
-
});
|
|
1333
|
-
meta.__middlewares.unshift({
|
|
1334
|
-
target: this.propertyName,
|
|
1335
|
-
priority: -1,
|
|
1336
|
-
args: {},
|
|
1337
|
-
middleware: ValidationMiddleware
|
|
1338
|
-
});
|
|
1339
|
-
}
|
|
1340
|
-
};
|
|
1341
|
-
/**
|
|
1342
|
-
* @function Body
|
|
1343
|
-
* @returns {Function} A decorator function that registers the BodyDecorator.
|
|
1344
|
-
*
|
|
1345
|
-
* This function creates and returns a decorator that can be used to annotate
|
|
1346
|
-
* a parameter in a method to indicate that it should be populated with the
|
|
1347
|
-
* body of an HTTP request. The decorator uses the BodyDecorator class to
|
|
1348
|
-
* handle the metadata associated with the parameter.
|
|
1349
|
-
*/
|
|
1350
|
-
function Body(options) {
|
|
1351
|
-
return (0, __vercube_di.createDecorator)(BodyDecorator, options);
|
|
1352
|
-
}
|
|
1353
|
-
|
|
1354
|
-
//#endregion
|
|
1355
|
-
//#region packages/core/src/Decorators/Http/Connect.ts
|
|
1356
|
-
/**
|
|
1357
|
-
* A decorator class for handling HTTP CONNECT requests.
|
|
1358
|
-
*
|
|
1359
|
-
* This class extends the BaseDecorator and is used to register CONNECT routes
|
|
1360
|
-
* with the Router. It also resolves metadata for the route handler
|
|
1361
|
-
* using the MetadataResolver.
|
|
1362
|
-
*
|
|
1363
|
-
* @extends {BaseDecorator<ConnectDecoratorOptions>}
|
|
1364
|
-
*/
|
|
1365
|
-
var ConnectDecorator = class extends __vercube_di.BaseDecorator {
|
|
1366
|
-
gRouter;
|
|
1367
|
-
gRequestHandler;
|
|
1368
|
-
gMetadataResolver;
|
|
1369
|
-
/**
|
|
1370
|
-
* Called when the decorator is created.
|
|
1371
|
-
*
|
|
1372
|
-
* This method constructs the full path for the route, registers the route
|
|
1373
|
-
* with the Router, and sets up the event handler for the CONNECT request.
|
|
1374
|
-
*/
|
|
1375
|
-
created() {
|
|
1376
|
-
this.options.path = this.gMetadataResolver.resolveUrl({
|
|
1377
|
-
instance: this.instance,
|
|
1378
|
-
path: this.options.path,
|
|
1379
|
-
propertyName: this.propertyName
|
|
1380
|
-
});
|
|
1381
|
-
this.gRouter.addRoute({
|
|
1382
|
-
path: this.options.path,
|
|
1383
|
-
method: "CONNECT",
|
|
1384
|
-
handler: this.gRequestHandler.prepareHandler({
|
|
1385
|
-
instance: this.instance,
|
|
1386
|
-
propertyName: this.propertyName
|
|
1387
|
-
})
|
|
1388
|
-
});
|
|
1389
|
-
}
|
|
1390
|
-
};
|
|
1391
|
-
(0, import_decorate.default)([(0, __vercube_di.Inject)(Router)], ConnectDecorator.prototype, "gRouter", void 0);
|
|
1392
|
-
(0, import_decorate.default)([(0, __vercube_di.Inject)(RequestHandler)], ConnectDecorator.prototype, "gRequestHandler", void 0);
|
|
1393
|
-
(0, import_decorate.default)([(0, __vercube_di.Inject)(MetadataResolver)], ConnectDecorator.prototype, "gMetadataResolver", void 0);
|
|
1394
|
-
/**
|
|
1395
|
-
* A factory function for creating a ConnectDecorator.
|
|
1396
|
-
*
|
|
1397
|
-
* This function returns a decorator function that can be used to annotate
|
|
1398
|
-
* a method with CONNECT route information.
|
|
1399
|
-
*
|
|
1400
|
-
* @param {string} path - The path for the CONNECT route.
|
|
1401
|
-
* @return {Function} The decorator function.
|
|
1402
|
-
*/
|
|
1403
|
-
function Connect(path) {
|
|
1404
|
-
return (0, __vercube_di.createDecorator)(ConnectDecorator, { path });
|
|
1405
|
-
}
|
|
1406
|
-
|
|
1407
|
-
//#endregion
|
|
1408
|
-
//#region packages/core/src/Decorators/Http/Controller.ts
|
|
1409
|
-
/**
|
|
1410
|
-
* A factory function for creating a Controller decorator.
|
|
1411
|
-
*
|
|
1412
|
-
* This function returns a decorator function that can be used to annotate
|
|
1413
|
-
* a class with controller metadata, including the base path for the controller.
|
|
1414
|
-
*
|
|
1415
|
-
* @param {string} path - The base path for the controller.
|
|
1416
|
-
* @return {Function} The decorator function.
|
|
1417
|
-
*/
|
|
1418
|
-
function Controller(path) {
|
|
1419
|
-
return function internalDecorator(target) {
|
|
1420
|
-
const meta = initializeMetadata(target.prototype);
|
|
1421
|
-
meta.__controller = {
|
|
1422
|
-
...meta?.__controller,
|
|
1423
|
-
path
|
|
1424
|
-
};
|
|
1425
|
-
};
|
|
1426
|
-
}
|
|
1427
|
-
|
|
1428
|
-
//#endregion
|
|
1429
|
-
//#region packages/core/src/Decorators/Http/Delete.ts
|
|
1430
|
-
/**
|
|
1431
|
-
* A decorator class for handling HTTP DELETE requests.
|
|
1432
|
-
*
|
|
1433
|
-
* This class extends the BaseDecorator and is used to register DELETE routes
|
|
1434
|
-
* with the Router. It also resolves metadata for the route handler
|
|
1435
|
-
* using the MetadataResolver.
|
|
1436
|
-
*
|
|
1437
|
-
* @extends {BaseDecorator<DeleteDecoratorOptions>}
|
|
1438
|
-
*/
|
|
1439
|
-
var DeleteDecorator = class extends __vercube_di.BaseDecorator {
|
|
1440
|
-
gRouter;
|
|
1441
|
-
gRequestHandler;
|
|
1442
|
-
gMetadataResolver;
|
|
1443
|
-
/**
|
|
1444
|
-
* Called when the decorator is created.
|
|
1445
|
-
*
|
|
1446
|
-
* This method constructs the full path for the route, registers the route
|
|
1447
|
-
* with the Router, and sets up the event handler for the DELETE request.
|
|
1448
|
-
*/
|
|
1449
|
-
created() {
|
|
1450
|
-
initializeMetadata(this.prototype);
|
|
1451
|
-
initializeMetadataMethod(this.prototype, this.propertyName);
|
|
1452
|
-
this.options.path = this.gMetadataResolver.resolveUrl({
|
|
1453
|
-
instance: this.instance,
|
|
1454
|
-
path: this.options.path,
|
|
1455
|
-
propertyName: this.propertyName
|
|
1456
|
-
});
|
|
1457
|
-
this.gRouter.addRoute({
|
|
1458
|
-
path: this.options.path,
|
|
1459
|
-
method: "DELETE",
|
|
1460
|
-
handler: this.gRequestHandler.prepareHandler({
|
|
1461
|
-
instance: this.instance,
|
|
1462
|
-
propertyName: this.propertyName
|
|
1463
|
-
})
|
|
1464
|
-
});
|
|
1465
|
-
}
|
|
1466
|
-
};
|
|
1467
|
-
(0, import_decorate.default)([(0, __vercube_di.Inject)(Router)], DeleteDecorator.prototype, "gRouter", void 0);
|
|
1468
|
-
(0, import_decorate.default)([(0, __vercube_di.Inject)(RequestHandler)], DeleteDecorator.prototype, "gRequestHandler", void 0);
|
|
1469
|
-
(0, import_decorate.default)([(0, __vercube_di.Inject)(MetadataResolver)], DeleteDecorator.prototype, "gMetadataResolver", void 0);
|
|
1470
|
-
/**
|
|
1471
|
-
* A factory function for creating a DeleteDecorator.
|
|
1472
|
-
*
|
|
1473
|
-
* This function returns a decorator function that can be used to annotate
|
|
1474
|
-
* a method with DELETE route information.
|
|
1475
|
-
*
|
|
1476
|
-
* @param {string} path - The path for the DELETE route.
|
|
1477
|
-
* @return {Function} The decorator function.
|
|
1478
|
-
*/
|
|
1479
|
-
function Delete(path) {
|
|
1480
|
-
return (0, __vercube_di.createDecorator)(DeleteDecorator, { path });
|
|
1481
|
-
}
|
|
1482
|
-
|
|
1483
|
-
//#endregion
|
|
1484
|
-
//#region packages/core/src/Decorators/Http/Get.ts
|
|
1485
|
-
/**
|
|
1486
|
-
* A decorator class for handling HTTP GET requests.
|
|
1487
|
-
*
|
|
1488
|
-
* This class extends the BaseDecorator and is used to register GET routes
|
|
1489
|
-
* with the Router. It also resolves metadata for the route handler
|
|
1490
|
-
* using the MetadataResolver.
|
|
1491
|
-
*
|
|
1492
|
-
* @extends {BaseDecorator<GetDecoratorOptions>}
|
|
1493
|
-
*/
|
|
1494
|
-
var GetDecorator = class extends __vercube_di.BaseDecorator {
|
|
1495
|
-
gRouter;
|
|
1496
|
-
gRequestHandler;
|
|
1497
|
-
gMetadataResolver;
|
|
1498
|
-
/**
|
|
1499
|
-
* Called when the decorator is created.
|
|
1500
|
-
*
|
|
1501
|
-
* This method constructs the full path for the route, registers the route
|
|
1502
|
-
* with the Router, and sets up the event handler for the GET request.
|
|
1503
|
-
*/
|
|
1504
|
-
created() {
|
|
1505
|
-
initializeMetadata(this.prototype);
|
|
1506
|
-
initializeMetadataMethod(this.prototype, this.propertyName);
|
|
1507
|
-
this.options.path = this.gMetadataResolver.resolveUrl({
|
|
1508
|
-
instance: this.instance,
|
|
1509
|
-
path: this.options.path,
|
|
1510
|
-
propertyName: this.propertyName
|
|
1511
|
-
});
|
|
1512
|
-
this.gRouter.addRoute({
|
|
1513
|
-
path: this.options.path,
|
|
1514
|
-
method: "GET",
|
|
1515
|
-
handler: this.gRequestHandler.prepareHandler({
|
|
1516
|
-
instance: this.instance,
|
|
1517
|
-
propertyName: this.propertyName
|
|
1518
|
-
})
|
|
1519
|
-
});
|
|
1520
|
-
}
|
|
1521
|
-
};
|
|
1522
|
-
(0, import_decorate.default)([(0, __vercube_di.Inject)(Router)], GetDecorator.prototype, "gRouter", void 0);
|
|
1523
|
-
(0, import_decorate.default)([(0, __vercube_di.Inject)(RequestHandler)], GetDecorator.prototype, "gRequestHandler", void 0);
|
|
1524
|
-
(0, import_decorate.default)([(0, __vercube_di.Inject)(MetadataResolver)], GetDecorator.prototype, "gMetadataResolver", void 0);
|
|
1525
|
-
/**
|
|
1526
|
-
* A decorator function for handling HTTP GET requests.
|
|
1527
|
-
*
|
|
1528
|
-
* This function creates an instance of the GetDecorator class and registers
|
|
1529
|
-
* the GET route with the specified path.
|
|
1530
|
-
*
|
|
1531
|
-
* @param {string} path - The path for the GET route.
|
|
1532
|
-
* @returns {Function} - The decorator function.
|
|
1533
|
-
*/
|
|
1534
|
-
function Get(path) {
|
|
1535
|
-
return (0, __vercube_di.createDecorator)(GetDecorator, { path });
|
|
1536
|
-
}
|
|
1537
|
-
|
|
1538
|
-
//#endregion
|
|
1539
|
-
//#region packages/core/src/Decorators/Http/Head.ts
|
|
1540
|
-
/**
|
|
1541
|
-
* A decorator class for handling HTTP HEAD requests.
|
|
1542
|
-
*
|
|
1543
|
-
* This class extends the BaseDecorator and is used to register HEAD routes
|
|
1544
|
-
* with the Router. It also resolves metadata for the route handler
|
|
1545
|
-
* using the MetadataResolver.
|
|
1546
|
-
*
|
|
1547
|
-
* @extends {BaseDecorator<HeadDecoratorOptions>}
|
|
1548
|
-
*/
|
|
1549
|
-
var HeadDecorator = class extends __vercube_di.BaseDecorator {
|
|
1550
|
-
gRouter;
|
|
1551
|
-
gRequestHandler;
|
|
1552
|
-
gMetadataResolver;
|
|
1553
|
-
/**
|
|
1554
|
-
* Called when the decorator is created.
|
|
1555
|
-
*
|
|
1556
|
-
* This method constructs the full path for the route, registers the route
|
|
1557
|
-
* with the Router, and sets up the event handler for the HEAD request.
|
|
1558
|
-
*/
|
|
1559
|
-
created() {
|
|
1560
|
-
initializeMetadata(this.prototype);
|
|
1561
|
-
initializeMetadataMethod(this.prototype, this.propertyName);
|
|
1562
|
-
this.options.path = this.gMetadataResolver.resolveUrl({
|
|
1563
|
-
instance: this.instance,
|
|
1564
|
-
path: this.options.path,
|
|
1565
|
-
propertyName: this.propertyName
|
|
1566
|
-
});
|
|
1567
|
-
this.gRouter.addRoute({
|
|
1568
|
-
path: this.options.path,
|
|
1569
|
-
method: "HEAD",
|
|
1570
|
-
handler: this.gRequestHandler.prepareHandler({
|
|
1571
|
-
instance: this.instance,
|
|
1572
|
-
propertyName: this.propertyName
|
|
1573
|
-
})
|
|
1574
|
-
});
|
|
1575
|
-
}
|
|
1576
|
-
};
|
|
1577
|
-
(0, import_decorate.default)([(0, __vercube_di.Inject)(Router)], HeadDecorator.prototype, "gRouter", void 0);
|
|
1578
|
-
(0, import_decorate.default)([(0, __vercube_di.Inject)(RequestHandler)], HeadDecorator.prototype, "gRequestHandler", void 0);
|
|
1579
|
-
(0, import_decorate.default)([(0, __vercube_di.Inject)(MetadataResolver)], HeadDecorator.prototype, "gMetadataResolver", void 0);
|
|
1580
|
-
/**
|
|
1581
|
-
* A factory function for creating a HeadDecorator.
|
|
1582
|
-
*
|
|
1583
|
-
* This function returns a decorator function that can be used to annotate
|
|
1584
|
-
* a method with HEAD route information.
|
|
1585
|
-
*
|
|
1586
|
-
* @param {string} path - The path for the HEAD route.
|
|
1587
|
-
* @return {Function} The decorator function.
|
|
1588
|
-
*/
|
|
1589
|
-
function Head(path) {
|
|
1590
|
-
return (0, __vercube_di.createDecorator)(HeadDecorator, { path });
|
|
1591
|
-
}
|
|
1592
|
-
|
|
1593
|
-
//#endregion
|
|
1594
|
-
//#region packages/core/src/Decorators/Http/Header.ts
|
|
1595
|
-
/**
|
|
1596
|
-
* A decorator class for handling HTTP header parameters.
|
|
1597
|
-
*
|
|
1598
|
-
* This class extends the BaseDecorator and is used to register header parameters
|
|
1599
|
-
* with the MetadataResolver. It ensures that the metadata for the property is created
|
|
1600
|
-
* and adds the header information to the metadata.
|
|
1601
|
-
*
|
|
1602
|
-
* @extends {BaseDecorator<HeaderDecoratorOptions>}
|
|
1603
|
-
*/
|
|
1604
|
-
var HeaderDecorator = class extends __vercube_di.BaseDecorator {
|
|
1605
|
-
/**
|
|
1606
|
-
* Called when the decorator is created.
|
|
1607
|
-
*
|
|
1608
|
-
* This method checks if metadata for the property exists, creates it if it doesn't,
|
|
1609
|
-
* and then adds the header information to the metadata.
|
|
1610
|
-
*/
|
|
1611
|
-
created() {
|
|
1612
|
-
initializeMetadata(this.prototype);
|
|
1613
|
-
const method = initializeMetadataMethod(this.prototype, this.propertyName);
|
|
1614
|
-
method.args.push({
|
|
1615
|
-
idx: this.propertyIndex,
|
|
1616
|
-
type: "header",
|
|
1617
|
-
data: { name: this.options.name }
|
|
1618
|
-
});
|
|
1619
|
-
}
|
|
1620
|
-
};
|
|
1621
|
-
/**
|
|
1622
|
-
* A decorator function for handling HTTP header parameters.
|
|
1623
|
-
*
|
|
1624
|
-
* This function creates a HeaderDecorator with the specified name and registers it.
|
|
1625
|
-
* It is used to annotate a parameter in a method to indicate that it should be
|
|
1626
|
-
* populated with the value of a specific HTTP header.
|
|
1627
|
-
*
|
|
1628
|
-
* @param {string} name - The name of the HTTP header to bind to the parameter.
|
|
1629
|
-
* @returns {Function} - A decorator function that registers the HeaderDecorator.
|
|
1630
|
-
*/
|
|
1631
|
-
function Header(name) {
|
|
1632
|
-
return (0, __vercube_di.createDecorator)(HeaderDecorator, { name });
|
|
1633
|
-
}
|
|
1634
|
-
|
|
1635
|
-
//#endregion
|
|
1636
|
-
//#region packages/core/src/Decorators/Http/Headers.ts
|
|
1637
|
-
/**
|
|
1638
|
-
* This class is responsible for managing headers decorator.
|
|
1639
|
-
*
|
|
1640
|
-
* This class extends the BaseDecorator and is used to register headers parameters
|
|
1641
|
-
* with the MetadataResolver. It ensures that the metadata for the property is created
|
|
1642
|
-
* and adds the headers information to the metadata.
|
|
1643
|
-
*
|
|
1644
|
-
* @extends {BaseDecorator<{}>}
|
|
1645
|
-
*/
|
|
1646
|
-
var HeadersDecorator = class extends __vercube_di.BaseDecorator {
|
|
1647
|
-
/**
|
|
1648
|
-
* Called when the decorator is created.
|
|
1649
|
-
*
|
|
1650
|
-
* This method checks if metadata for the property exists, creates it if it doesn't,
|
|
1651
|
-
* and then adds the headers information to the metadata.
|
|
1652
|
-
*/
|
|
1653
|
-
created() {
|
|
1654
|
-
initializeMetadata(this.prototype);
|
|
1655
|
-
const method = initializeMetadataMethod(this.prototype, this.propertyName);
|
|
1656
|
-
method.args.push({
|
|
1657
|
-
idx: this.propertyIndex,
|
|
1658
|
-
type: "headers"
|
|
1659
|
-
});
|
|
1660
|
-
}
|
|
1661
|
-
};
|
|
1662
|
-
/**
|
|
1663
|
-
* A factory function for creating a HeadersDecorator.
|
|
1664
|
-
*
|
|
1665
|
-
* This function returns a decorator function that can be used to annotate
|
|
1666
|
-
* a method parameter with headers information.
|
|
1667
|
-
*
|
|
1668
|
-
* @return {Function} The decorator function.
|
|
1669
|
-
*/
|
|
1670
|
-
function Headers$1() {
|
|
1671
|
-
return (0, __vercube_di.createDecorator)(HeadersDecorator, {});
|
|
1672
|
-
}
|
|
1673
|
-
|
|
1674
|
-
//#endregion
|
|
1675
|
-
//#region packages/core/src/Decorators/Http/Options.ts
|
|
1676
|
-
/**
|
|
1677
|
-
* A decorator class for handling HTTP OPTIONS requests.
|
|
1678
|
-
*
|
|
1679
|
-
* This class extends the BaseDecorator and is used to register OPTIONS routes
|
|
1680
|
-
* with the Router. It also resolves metadata for the route handler
|
|
1681
|
-
* using the MetadataResolver.
|
|
1682
|
-
*
|
|
1683
|
-
* @extends {BaseDecorator<OptionsDecoratorOptions>}
|
|
1684
|
-
*/
|
|
1685
|
-
var OptionsDecorator = class extends __vercube_di.BaseDecorator {
|
|
1686
|
-
gRouter;
|
|
1687
|
-
gRequestHandler;
|
|
1688
|
-
gMetadataResolver;
|
|
1689
|
-
/**
|
|
1690
|
-
* Called when the decorator is created.
|
|
1691
|
-
*
|
|
1692
|
-
* This method constructs the full path for the route, registers the route
|
|
1693
|
-
* with the Router, and sets up the event handler for the OPTIONS request.
|
|
1694
|
-
*/
|
|
1695
|
-
created() {
|
|
1696
|
-
initializeMetadata(this.prototype);
|
|
1697
|
-
initializeMetadataMethod(this.prototype, this.propertyName);
|
|
1698
|
-
this.options.path = this.gMetadataResolver.resolveUrl({
|
|
1699
|
-
instance: this.instance,
|
|
1700
|
-
path: this.options.path,
|
|
1701
|
-
propertyName: this.propertyName
|
|
1702
|
-
});
|
|
1703
|
-
this.gRouter.addRoute({
|
|
1704
|
-
path: this.options.path,
|
|
1705
|
-
method: "OPTIONS",
|
|
1706
|
-
handler: this.gRequestHandler.prepareHandler({
|
|
1707
|
-
instance: this.instance,
|
|
1708
|
-
propertyName: this.propertyName
|
|
1709
|
-
})
|
|
1710
|
-
});
|
|
1711
|
-
}
|
|
1712
|
-
};
|
|
1713
|
-
(0, import_decorate.default)([(0, __vercube_di.Inject)(Router)], OptionsDecorator.prototype, "gRouter", void 0);
|
|
1714
|
-
(0, import_decorate.default)([(0, __vercube_di.Inject)(RequestHandler)], OptionsDecorator.prototype, "gRequestHandler", void 0);
|
|
1715
|
-
(0, import_decorate.default)([(0, __vercube_di.Inject)(MetadataResolver)], OptionsDecorator.prototype, "gMetadataResolver", void 0);
|
|
1716
|
-
/**
|
|
1717
|
-
* A factory function for creating an OptionsDecorator.
|
|
1718
|
-
*
|
|
1719
|
-
* This function returns a decorator function that can be used to annotate
|
|
1720
|
-
* a method with OPTIONS route information.
|
|
1721
|
-
*
|
|
1722
|
-
* @param {string} path - The path for the OPTIONS route.
|
|
1723
|
-
* @return {Function} The decorator function.
|
|
1724
|
-
*/
|
|
1725
|
-
function Options(path) {
|
|
1726
|
-
return (0, __vercube_di.createDecorator)(OptionsDecorator, { path });
|
|
1727
|
-
}
|
|
1728
|
-
|
|
1729
|
-
//#endregion
|
|
1730
|
-
//#region packages/core/src/Decorators/Http/Param.ts
|
|
1731
|
-
/**
|
|
1732
|
-
* This class is responsible for managing parameter decorators.
|
|
1733
|
-
*
|
|
1734
|
-
* This class extends the BaseDecorator and is used to register parameter information
|
|
1735
|
-
* with the MetadataResolver. It ensures that the metadata for the property is created
|
|
1736
|
-
* and adds the parameter information to the metadata.
|
|
1737
|
-
*
|
|
1738
|
-
* @extends {BaseDecorator<ParamDecoratorOptions>}
|
|
1739
|
-
*/
|
|
1740
|
-
var ParamDecorator = class extends __vercube_di.BaseDecorator {
|
|
1741
|
-
gMetadataResolver;
|
|
1742
|
-
/**
|
|
1743
|
-
* Called when the decorator is created.
|
|
1744
|
-
*
|
|
1745
|
-
* This method checks if metadata for the property exists, creates it if it doesn't,
|
|
1746
|
-
* and then adds the parameter information to the metadata.
|
|
1747
|
-
*/
|
|
1748
|
-
created() {
|
|
1749
|
-
initializeMetadata(this.prototype);
|
|
1750
|
-
const method = initializeMetadataMethod(this.prototype, this.propertyName);
|
|
1751
|
-
method.args.push({
|
|
1752
|
-
idx: this.propertyIndex,
|
|
1753
|
-
type: "param",
|
|
1754
|
-
data: { name: this.options.name }
|
|
1755
|
-
});
|
|
1756
|
-
}
|
|
1757
|
-
};
|
|
1758
|
-
(0, import_decorate.default)([(0, __vercube_di.Inject)(MetadataResolver)], ParamDecorator.prototype, "gMetadataResolver", void 0);
|
|
1759
|
-
/**
|
|
1760
|
-
* A factory function for creating a ParamDecorator.
|
|
1761
|
-
*
|
|
1762
|
-
* This function returns a decorator function that can be used to annotate
|
|
1763
|
-
* a method parameter with parameter information.
|
|
1764
|
-
*
|
|
1765
|
-
* @param {string} name - The name of the parameter.
|
|
1766
|
-
* @param {Object} [opts] - Optional settings for the parameter.
|
|
1767
|
-
* @param {boolean} [opts.decode=false] - Whether to decode the parameter.
|
|
1768
|
-
* @return {Function} The decorator function.
|
|
1769
|
-
*/
|
|
1770
|
-
function Param(name) {
|
|
1771
|
-
return (0, __vercube_di.createDecorator)(ParamDecorator, { name });
|
|
1772
|
-
}
|
|
1773
|
-
|
|
1774
|
-
//#endregion
|
|
1775
|
-
//#region packages/core/src/Decorators/Http/Patch.ts
|
|
1776
|
-
/**
|
|
1777
|
-
* A decorator class for handling HTTP PATCH requests.
|
|
1778
|
-
*
|
|
1779
|
-
* This class extends the BaseDecorator and is used to register PATCH routes
|
|
1780
|
-
* with the Router. It also resolves metadata for the route handler
|
|
1781
|
-
* using the MetadataResolver.
|
|
1782
|
-
*
|
|
1783
|
-
* @extends {BaseDecorator<PatchDecoratorOptions>}
|
|
1784
|
-
*/
|
|
1785
|
-
var PatchDecorator = class extends __vercube_di.BaseDecorator {
|
|
1786
|
-
gRouter;
|
|
1787
|
-
gRequestHandler;
|
|
1788
|
-
gMetadataResolver;
|
|
1789
|
-
/**
|
|
1790
|
-
* Called when the decorator is created.
|
|
1791
|
-
*
|
|
1792
|
-
* This method constructs the full path for the route, registers the route
|
|
1793
|
-
* with the Router, and sets up the event handler for the PATCH request.
|
|
1794
|
-
*/
|
|
1795
|
-
created() {
|
|
1796
|
-
this.options.path = this.gMetadataResolver.resolveUrl({
|
|
1797
|
-
instance: this.instance,
|
|
1798
|
-
path: this.options.path,
|
|
1799
|
-
propertyName: this.propertyName
|
|
1800
|
-
});
|
|
1801
|
-
this.gRouter.addRoute({
|
|
1802
|
-
path: this.options.path,
|
|
1803
|
-
method: "PATCH",
|
|
1804
|
-
handler: this.gRequestHandler.prepareHandler({
|
|
1805
|
-
instance: this.instance,
|
|
1806
|
-
propertyName: this.propertyName
|
|
1807
|
-
})
|
|
1808
|
-
});
|
|
1809
|
-
}
|
|
1810
|
-
};
|
|
1811
|
-
(0, import_decorate.default)([(0, __vercube_di.Inject)(Router)], PatchDecorator.prototype, "gRouter", void 0);
|
|
1812
|
-
(0, import_decorate.default)([(0, __vercube_di.Inject)(RequestHandler)], PatchDecorator.prototype, "gRequestHandler", void 0);
|
|
1813
|
-
(0, import_decorate.default)([(0, __vercube_di.Inject)(MetadataResolver)], PatchDecorator.prototype, "gMetadataResolver", void 0);
|
|
1814
|
-
/**
|
|
1815
|
-
* A factory function for creating a PatchDecorator.
|
|
1816
|
-
*
|
|
1817
|
-
* This function returns a decorator function that can be used to annotate
|
|
1818
|
-
* a method with PATCH route information.
|
|
1819
|
-
*
|
|
1820
|
-
* @param {string} path - The path for the PATCH route.
|
|
1821
|
-
* @return {Function} The decorator function.
|
|
1822
|
-
*/
|
|
1823
|
-
function Patch(path) {
|
|
1824
|
-
return (0, __vercube_di.createDecorator)(PatchDecorator, { path });
|
|
1825
|
-
}
|
|
1826
|
-
|
|
1827
|
-
//#endregion
|
|
1828
|
-
//#region packages/core/src/Decorators/Http/Post.ts
|
|
1829
|
-
/**
|
|
1830
|
-
* A decorator class for handling HTTP POST requests.
|
|
1831
|
-
*
|
|
1832
|
-
* This class extends the BaseDecorator and is used to register POST routes
|
|
1833
|
-
* with the Router. It also resolves metadata for the route handler
|
|
1834
|
-
* using the MetadataResolver.
|
|
1835
|
-
*
|
|
1836
|
-
* @extends {BaseDecorator<PostDecoratorOptions>}
|
|
1837
|
-
*/
|
|
1838
|
-
var PostDecorator = class extends __vercube_di.BaseDecorator {
|
|
1839
|
-
gRouter;
|
|
1840
|
-
gMetadataResolver;
|
|
1841
|
-
gRequestHandler;
|
|
1842
|
-
/**
|
|
1843
|
-
* Called when the decorator is created.
|
|
1844
|
-
*
|
|
1845
|
-
* This method constructs the full path for the route, registers the route
|
|
1846
|
-
* with the Router, and sets up the event handler for the POST request.
|
|
1847
|
-
*/
|
|
1848
|
-
created() {
|
|
1849
|
-
initializeMetadata(this.prototype);
|
|
1850
|
-
initializeMetadataMethod(this.prototype, this.propertyName);
|
|
1851
|
-
this.options.path = this.gMetadataResolver.resolveUrl({
|
|
1852
|
-
instance: this.instance,
|
|
1853
|
-
path: this.options.path,
|
|
1854
|
-
propertyName: this.propertyName
|
|
1855
|
-
});
|
|
1856
|
-
this.gRouter.addRoute({
|
|
1857
|
-
path: this.options.path,
|
|
1858
|
-
method: "POST",
|
|
1859
|
-
handler: this.gRequestHandler.prepareHandler({
|
|
1860
|
-
instance: this.instance,
|
|
1861
|
-
propertyName: this.propertyName
|
|
1862
|
-
})
|
|
1863
|
-
});
|
|
1864
|
-
}
|
|
1865
|
-
};
|
|
1866
|
-
(0, import_decorate.default)([(0, __vercube_di.Inject)(Router)], PostDecorator.prototype, "gRouter", void 0);
|
|
1867
|
-
(0, import_decorate.default)([(0, __vercube_di.Inject)(MetadataResolver)], PostDecorator.prototype, "gMetadataResolver", void 0);
|
|
1868
|
-
(0, import_decorate.default)([(0, __vercube_di.Inject)(RequestHandler)], PostDecorator.prototype, "gRequestHandler", void 0);
|
|
1869
|
-
/**
|
|
1870
|
-
* A factory function for creating a PostDecorator.
|
|
1871
|
-
*
|
|
1872
|
-
* This function returns a decorator function that can be used to annotate
|
|
1873
|
-
* a method with POST route information.
|
|
1874
|
-
*
|
|
1875
|
-
* @param {string} path - The path for the POST route.
|
|
1876
|
-
* @return {Function} The decorator function.
|
|
1877
|
-
*/
|
|
1878
|
-
function Post(path) {
|
|
1879
|
-
return (0, __vercube_di.createDecorator)(PostDecorator, { path });
|
|
1880
|
-
}
|
|
1881
|
-
|
|
1882
|
-
//#endregion
|
|
1883
|
-
//#region packages/core/src/Decorators/Http/Put.ts
|
|
1884
|
-
/**
|
|
1885
|
-
* A decorator class for handling HTTP PUT requests.
|
|
1886
|
-
*
|
|
1887
|
-
* This class extends the BaseDecorator and is used to register PUT routes
|
|
1888
|
-
* with the Router. It also resolves metadata for the route handler
|
|
1889
|
-
* using the MetadataResolver.
|
|
1890
|
-
*
|
|
1891
|
-
* @extends {BaseDecorator<PutDecoratorOptions>}
|
|
1892
|
-
*/
|
|
1893
|
-
var PutDecorator = class extends __vercube_di.BaseDecorator {
|
|
1894
|
-
gRouter;
|
|
1895
|
-
gRequestHandler;
|
|
1896
|
-
gMetadataResolver;
|
|
1897
|
-
/**
|
|
1898
|
-
* Called when the decorator is created.
|
|
1899
|
-
*
|
|
1900
|
-
* This method constructs the full path for the route, registers the route
|
|
1901
|
-
* with the Router, and sets up the event handler for the PUT request.
|
|
1902
|
-
*/
|
|
1903
|
-
created() {
|
|
1904
|
-
initializeMetadata(this.prototype);
|
|
1905
|
-
initializeMetadataMethod(this.prototype, this.propertyName);
|
|
1906
|
-
this.options.path = this.gMetadataResolver.resolveUrl({
|
|
1907
|
-
instance: this.instance,
|
|
1908
|
-
path: this.options.path,
|
|
1909
|
-
propertyName: this.propertyName
|
|
1910
|
-
});
|
|
1911
|
-
this.gRouter.addRoute({
|
|
1912
|
-
path: this.options.path,
|
|
1913
|
-
method: "PUT",
|
|
1914
|
-
handler: this.gRequestHandler.prepareHandler({
|
|
1915
|
-
instance: this.instance,
|
|
1916
|
-
propertyName: this.propertyName
|
|
1917
|
-
})
|
|
1918
|
-
});
|
|
1919
|
-
}
|
|
1920
|
-
};
|
|
1921
|
-
(0, import_decorate.default)([(0, __vercube_di.Inject)(Router)], PutDecorator.prototype, "gRouter", void 0);
|
|
1922
|
-
(0, import_decorate.default)([(0, __vercube_di.Inject)(RequestHandler)], PutDecorator.prototype, "gRequestHandler", void 0);
|
|
1923
|
-
(0, import_decorate.default)([(0, __vercube_di.Inject)(MetadataResolver)], PutDecorator.prototype, "gMetadataResolver", void 0);
|
|
1924
|
-
/**
|
|
1925
|
-
* A factory function for creating a PutDecorator.
|
|
1926
|
-
*
|
|
1927
|
-
* This function returns a decorator function that can be used to annotate
|
|
1928
|
-
* a method with PUT route information.
|
|
1929
|
-
*
|
|
1930
|
-
* @param {string} path - The path for the PUT route.
|
|
1931
|
-
* @return {Function} The decorator function.
|
|
1932
|
-
*/
|
|
1933
|
-
function Put(path) {
|
|
1934
|
-
return (0, __vercube_di.createDecorator)(PutDecorator, { path });
|
|
1935
|
-
}
|
|
1936
|
-
|
|
1937
|
-
//#endregion
|
|
1938
|
-
//#region packages/core/src/Decorators/Http/QueryParam.ts
|
|
1939
|
-
/**
|
|
1940
|
-
* This class is responsible for managing query parameter decorators.
|
|
1941
|
-
*
|
|
1942
|
-
* This class extends the BaseDecorator and is used to register query parameter information
|
|
1943
|
-
* with the MetadataResolver. It ensures that the metadata for the property is created
|
|
1944
|
-
* and adds the query parameter information to the metadata.
|
|
1945
|
-
*
|
|
1946
|
-
* @extends {BaseDecorator<QueryDecoratorOptions>}
|
|
1947
|
-
*/
|
|
1948
|
-
var QueryParamDecorator = class extends __vercube_di.BaseDecorator {
|
|
1949
|
-
/**
|
|
1950
|
-
* Called when the decorator is created.
|
|
1951
|
-
*
|
|
1952
|
-
* This method checks if metadata for the property exists, creates it if it doesn't,
|
|
1953
|
-
* and then adds the query parameter information to the metadata.
|
|
1954
|
-
*/
|
|
1955
|
-
created() {
|
|
1956
|
-
const meta = initializeMetadata(this.prototype);
|
|
1957
|
-
const method = initializeMetadataMethod(this.prototype, this.propertyName);
|
|
1958
|
-
method.args.push({
|
|
1959
|
-
idx: this.propertyIndex,
|
|
1960
|
-
type: "query-param",
|
|
1961
|
-
data: { name: this.options.name },
|
|
1962
|
-
validate: this.options?.validationSchema ? true : false,
|
|
1963
|
-
validationSchema: this.options?.validationSchema
|
|
1964
|
-
});
|
|
1965
|
-
meta.__middlewares.unshift({
|
|
1966
|
-
target: this.propertyName,
|
|
1967
|
-
priority: -1,
|
|
1968
|
-
args: {},
|
|
1969
|
-
middleware: ValidationMiddleware
|
|
1970
|
-
});
|
|
1971
|
-
}
|
|
1972
|
-
};
|
|
1973
|
-
/**
|
|
1974
|
-
* A factory function for creating a QueryDecorator.
|
|
1975
|
-
*
|
|
1976
|
-
* This function returns a decorator function that can be used to annotate
|
|
1977
|
-
* a method parameter with query parameter information.
|
|
1978
|
-
*
|
|
1979
|
-
* @param {QueryParamDecoratorOptions} options - The options for the decorator.
|
|
1980
|
-
* @return {Function} The decorator function.
|
|
1981
|
-
*/
|
|
1982
|
-
function QueryParam(options) {
|
|
1983
|
-
return (0, __vercube_di.createDecorator)(QueryParamDecorator, options);
|
|
1984
|
-
}
|
|
1985
|
-
|
|
1986
|
-
//#endregion
|
|
1987
|
-
//#region packages/core/src/Decorators/Http/QueryParams.ts
|
|
1988
|
-
/**
|
|
1989
|
-
* This class is responsible for managing query parameters decorators.
|
|
1990
|
-
*
|
|
1991
|
-
* This class extends the BaseDecorator and is used to register query parameters information
|
|
1992
|
-
* with the MetadataResolver. It ensures that the metadata for the property is created
|
|
1993
|
-
* and adds the query parameters information to the metadata.
|
|
1994
|
-
*
|
|
1995
|
-
* @extends {BaseDecorator<QueryDecoratorOptions>}
|
|
1996
|
-
*/
|
|
1997
|
-
var QueryParamsDecorator = class extends __vercube_di.BaseDecorator {
|
|
1998
|
-
/**
|
|
1999
|
-
* Called when the decorator is created.
|
|
2000
|
-
*
|
|
2001
|
-
* This method checks if metadata for the property exists, creates it if it doesn't,
|
|
2002
|
-
* and then adds the query parameters information to the metadata.
|
|
2003
|
-
*/
|
|
2004
|
-
created() {
|
|
2005
|
-
const meta = initializeMetadata(this.prototype);
|
|
2006
|
-
const method = initializeMetadataMethod(this.prototype, this.propertyName);
|
|
2007
|
-
method.args.push({
|
|
2008
|
-
idx: this.propertyIndex,
|
|
2009
|
-
type: "query-params",
|
|
2010
|
-
data: {},
|
|
2011
|
-
validate: this.options?.validationSchema ? true : false,
|
|
2012
|
-
validationSchema: this.options?.validationSchema
|
|
2013
|
-
});
|
|
2014
|
-
meta.__middlewares.unshift({
|
|
2015
|
-
target: this.propertyName,
|
|
2016
|
-
priority: -1,
|
|
2017
|
-
args: {},
|
|
2018
|
-
middleware: ValidationMiddleware
|
|
2019
|
-
});
|
|
2020
|
-
}
|
|
2021
|
-
};
|
|
2022
|
-
/**
|
|
2023
|
-
* A factory function for creating a QueryParamsDecorator.
|
|
2024
|
-
*
|
|
2025
|
-
* This function returns a decorator function that can be used to annotate
|
|
2026
|
-
* a method parameter with query parameter information.
|
|
2027
|
-
*
|
|
2028
|
-
* @param {QueryParamsDecoratorOptions} options - The options for the decorator.
|
|
2029
|
-
* @return {Function} The decorator function.
|
|
2030
|
-
*/
|
|
2031
|
-
function QueryParams(options) {
|
|
2032
|
-
return (0, __vercube_di.createDecorator)(QueryParamsDecorator, options);
|
|
2033
|
-
}
|
|
2034
|
-
|
|
2035
|
-
//#endregion
|
|
2036
|
-
//#region packages/core/src/Decorators/Http/Request.ts
|
|
2037
|
-
/**
|
|
2038
|
-
* This class is responsible for managing request decorators.
|
|
2039
|
-
*
|
|
2040
|
-
* This class extends the BaseDecorator and is used to register request information
|
|
2041
|
-
* with the MetadataResolver. It ensures that the metadata for the property is created
|
|
2042
|
-
* and adds the request information to the metadata.
|
|
2043
|
-
*
|
|
2044
|
-
* @extends {BaseDecorator<{}>}
|
|
2045
|
-
*/
|
|
2046
|
-
var RequestDecorator = class extends __vercube_di.BaseDecorator {
|
|
2047
|
-
/**
|
|
2048
|
-
* Called when the decorator is created.
|
|
2049
|
-
*
|
|
2050
|
-
* This method checks if metadata for the property exists, creates it if it doesn't,
|
|
2051
|
-
* and then adds the request information to the metadata.
|
|
2052
|
-
*/
|
|
2053
|
-
created() {
|
|
2054
|
-
initializeMetadata(this.prototype);
|
|
2055
|
-
const method = initializeMetadataMethod(this.prototype, this.propertyName);
|
|
2056
|
-
method.args.push({
|
|
2057
|
-
idx: this.propertyIndex,
|
|
2058
|
-
type: "request"
|
|
2059
|
-
});
|
|
2060
|
-
}
|
|
2061
|
-
};
|
|
2062
|
-
/**
|
|
2063
|
-
* A factory function for creating a RequestDecorator.
|
|
2064
|
-
*
|
|
2065
|
-
* This function returns a decorator function that can be used to annotate
|
|
2066
|
-
* a method parameter with request information.
|
|
2067
|
-
*
|
|
2068
|
-
* @return {Function} The decorator function.
|
|
2069
|
-
*/
|
|
2070
|
-
function Request() {
|
|
2071
|
-
return (0, __vercube_di.createDecorator)(RequestDecorator, {});
|
|
2072
|
-
}
|
|
2073
|
-
|
|
2074
|
-
//#endregion
|
|
2075
|
-
//#region packages/core/src/Decorators/Http/Response.ts
|
|
2076
|
-
/**
|
|
2077
|
-
* This class is responsible for managing response decorators.
|
|
2078
|
-
*
|
|
2079
|
-
* This class extends the BaseDecorator and is used to register response information
|
|
2080
|
-
* with the MetadataResolver. It ensures that the metadata for the property is created
|
|
2081
|
-
* and adds the response information to the metadata.
|
|
2082
|
-
*
|
|
2083
|
-
* @extends {BaseDecorator<{}>}
|
|
2084
|
-
*/
|
|
2085
|
-
var ResponseDecorator = class extends __vercube_di.BaseDecorator {
|
|
2086
|
-
/**
|
|
2087
|
-
* Called when the decorator is created.
|
|
2088
|
-
*
|
|
2089
|
-
* This method checks if metadata for the property exists, creates it if it doesn't,
|
|
2090
|
-
* and then adds the response information to the metadata.
|
|
2091
|
-
*/
|
|
2092
|
-
created() {
|
|
2093
|
-
initializeMetadata(this.prototype);
|
|
2094
|
-
const method = initializeMetadataMethod(this.prototype, this.propertyName);
|
|
2095
|
-
method.args.push({
|
|
2096
|
-
idx: this.propertyIndex,
|
|
2097
|
-
type: "response"
|
|
2098
|
-
});
|
|
2099
|
-
}
|
|
2100
|
-
};
|
|
2101
|
-
/**
|
|
2102
|
-
* A factory function for creating a ResponseDecorator.
|
|
2103
|
-
*
|
|
2104
|
-
* This function returns a decorator function that can be used to annotate
|
|
2105
|
-
* a method parameter with response information.
|
|
2106
|
-
*
|
|
2107
|
-
* @return {Function} The decorator function.
|
|
2108
|
-
*/
|
|
2109
|
-
function Response$1() {
|
|
2110
|
-
return (0, __vercube_di.createDecorator)(ResponseDecorator, {});
|
|
2111
|
-
}
|
|
2112
|
-
|
|
2113
|
-
//#endregion
|
|
2114
|
-
//#region packages/core/src/Decorators/Http/Trace.ts
|
|
2115
|
-
/**
|
|
2116
|
-
* A decorator class for handling HTTP TRACE requests.
|
|
2117
|
-
*
|
|
2118
|
-
* This class extends the BaseDecorator and is used to register TRACE routes
|
|
2119
|
-
* with the Router. It also resolves metadata for the route handler
|
|
2120
|
-
* using the MetadataResolver.
|
|
2121
|
-
*
|
|
2122
|
-
* @extends {BaseDecorator<TraceDecoratorOptions>}
|
|
2123
|
-
*/
|
|
2124
|
-
var TraceDecorator = class extends __vercube_di.BaseDecorator {
|
|
2125
|
-
gRouter;
|
|
2126
|
-
gRequestHandler;
|
|
2127
|
-
gMetadataResolver;
|
|
2128
|
-
/**
|
|
2129
|
-
* Called when the decorator is created.
|
|
2130
|
-
*
|
|
2131
|
-
* This method constructs the full path for the route, registers the route
|
|
2132
|
-
* with the Router, and sets up the event handler for the TRACE request.
|
|
2133
|
-
*/
|
|
2134
|
-
created() {
|
|
2135
|
-
initializeMetadata(this.prototype);
|
|
2136
|
-
initializeMetadataMethod(this.prototype, this.propertyName);
|
|
2137
|
-
this.options.path = this.gMetadataResolver.resolveUrl({
|
|
2138
|
-
instance: this.instance,
|
|
2139
|
-
path: this.options.path,
|
|
2140
|
-
propertyName: this.propertyName
|
|
2141
|
-
});
|
|
2142
|
-
this.gRouter.addRoute({
|
|
2143
|
-
path: this.options.path,
|
|
2144
|
-
method: "TRACE",
|
|
2145
|
-
handler: this.gRequestHandler.prepareHandler({
|
|
2146
|
-
instance: this.instance,
|
|
2147
|
-
propertyName: this.propertyName
|
|
2148
|
-
})
|
|
2149
|
-
});
|
|
2150
|
-
}
|
|
2151
|
-
};
|
|
2152
|
-
(0, import_decorate.default)([(0, __vercube_di.Inject)(Router)], TraceDecorator.prototype, "gRouter", void 0);
|
|
2153
|
-
(0, import_decorate.default)([(0, __vercube_di.Inject)(RequestHandler)], TraceDecorator.prototype, "gRequestHandler", void 0);
|
|
2154
|
-
(0, import_decorate.default)([(0, __vercube_di.Inject)(MetadataResolver)], TraceDecorator.prototype, "gMetadataResolver", void 0);
|
|
2155
|
-
/**
|
|
2156
|
-
* A factory function for creating a TraceDecorator.
|
|
2157
|
-
*
|
|
2158
|
-
* This function returns a decorator function that can be used to annotate
|
|
2159
|
-
* a method with TRACE route information.
|
|
2160
|
-
*
|
|
2161
|
-
* @param {string} path - The path for the TRACE route.
|
|
2162
|
-
* @return {Function} The decorator function.
|
|
2163
|
-
*/
|
|
2164
|
-
function Trace(path) {
|
|
2165
|
-
return (0, __vercube_di.createDecorator)(TraceDecorator, { path });
|
|
2166
|
-
}
|
|
2167
|
-
|
|
2168
|
-
//#endregion
|
|
2169
|
-
//#region packages/core/src/Decorators/Http/SetHeader.ts
|
|
2170
|
-
/**
|
|
2171
|
-
* A decorator that sets a header on the response.
|
|
2172
|
-
* @extends {BaseDecorator<SetHeaderDecoratorOptions>}
|
|
2173
|
-
*/
|
|
2174
|
-
var SetHeaderDecorator = class extends __vercube_di.BaseDecorator {
|
|
2175
|
-
/**
|
|
2176
|
-
* Called when the decorator is created.
|
|
2177
|
-
* Adds a query parameter to the metadata.
|
|
2178
|
-
* @override
|
|
2179
|
-
*/
|
|
2180
|
-
created() {
|
|
2181
|
-
initializeMetadata(this.prototype);
|
|
2182
|
-
const method = initializeMetadataMethod(this.prototype, this.propertyName);
|
|
2183
|
-
method.actions.push({ handler: (req, res) => {
|
|
2184
|
-
res.headers.delete(this.options.key);
|
|
2185
|
-
res.headers.append(this.options.key, this.options.value);
|
|
2186
|
-
return res;
|
|
2187
|
-
} });
|
|
2188
|
-
}
|
|
2189
|
-
};
|
|
2190
|
-
/**
|
|
2191
|
-
* Creates a SetHeader decorator.
|
|
2192
|
-
* @param {string} key - The header key.
|
|
2193
|
-
* @param {string} value - The header value.
|
|
2194
|
-
* @returns {Function} The decorator function.
|
|
2195
|
-
*/
|
|
2196
|
-
function SetHeader(key, value) {
|
|
2197
|
-
return (0, __vercube_di.createDecorator)(SetHeaderDecorator, {
|
|
2198
|
-
key,
|
|
2199
|
-
value
|
|
2200
|
-
});
|
|
2201
|
-
}
|
|
2202
|
-
|
|
2203
|
-
//#endregion
|
|
2204
|
-
//#region packages/core/src/Decorators/Http/Status.ts
|
|
2205
|
-
/**
|
|
2206
|
-
|
|
2207
|
-
* A decorator that sets a status on the response.
|
|
2208
|
-
|
|
2209
|
-
* @extends {BaseDecorator<StatusDecoratorOptions>}
|
|
2210
|
-
|
|
2211
|
-
*/
|
|
2212
|
-
var StatusDecorator = class extends __vercube_di.BaseDecorator {
|
|
2213
|
-
/**
|
|
2214
|
-
|
|
2215
|
-
* Called when the decorator is created.
|
|
2216
|
-
|
|
2217
|
-
* Sets a status on the response
|
|
2218
|
-
|
|
2219
|
-
* @override
|
|
2220
|
-
|
|
2221
|
-
*/
|
|
2222
|
-
created() {
|
|
2223
|
-
initializeMetadata(this.prototype);
|
|
2224
|
-
const method = initializeMetadataMethod(this.prototype, this.propertyName);
|
|
2225
|
-
method.actions.push({ handler: () => ({ status: this.options.code }) });
|
|
2226
|
-
}
|
|
2227
|
-
};
|
|
2228
|
-
/**
|
|
2229
|
-
|
|
2230
|
-
* Creates a Status decorator.
|
|
2231
|
-
|
|
2232
|
-
* @param {number} code - The status value.
|
|
2233
|
-
|
|
2234
|
-
* @returns {Function} The decorator function.
|
|
2235
|
-
|
|
2236
|
-
*/
|
|
2237
|
-
function Status(code) {
|
|
2238
|
-
return (0, __vercube_di.createDecorator)(StatusDecorator, { code });
|
|
2239
|
-
}
|
|
2240
|
-
|
|
2241
|
-
//#endregion
|
|
2242
|
-
//#region packages/core/src/Decorators/Http/Redirect.ts
|
|
2243
|
-
var RedirectDecorator = class extends __vercube_di.BaseDecorator {
|
|
2244
|
-
/**
|
|
2245
|
-
|
|
2246
|
-
* Decorator responsible for redirecting to a specified URL.
|
|
2247
|
-
|
|
2248
|
-
* Called when the decorator is created.
|
|
2249
|
-
|
|
2250
|
-
* Sets the location header value and status code.
|
|
2251
|
-
|
|
2252
|
-
* @override
|
|
2253
|
-
|
|
2254
|
-
*/
|
|
2255
|
-
created() {
|
|
2256
|
-
initializeMetadata(this.prototype);
|
|
2257
|
-
const method = initializeMetadataMethod(this.prototype, this.propertyName);
|
|
2258
|
-
method.actions.push({ handler: () => {
|
|
2259
|
-
return new srvx.FastResponse(void 0, {
|
|
2260
|
-
status: this.options.code,
|
|
2261
|
-
headers: { "Location": this.options.location }
|
|
2262
|
-
});
|
|
2263
|
-
} });
|
|
2264
|
-
}
|
|
2265
|
-
};
|
|
2266
|
-
/**
|
|
2267
|
-
|
|
2268
|
-
* Creates a Redirect decorator.
|
|
2269
|
-
|
|
2270
|
-
* @param {string} location - The location header value.
|
|
2271
|
-
|
|
2272
|
-
* @param {number} [code=301] - The status code.
|
|
2273
|
-
|
|
2274
|
-
* @returns {Function} The decorator function.
|
|
2275
|
-
|
|
2276
|
-
*/
|
|
2277
|
-
function Redirect(location, code = 301) {
|
|
2278
|
-
return (0, __vercube_di.createDecorator)(RedirectDecorator, {
|
|
2279
|
-
location,
|
|
2280
|
-
code
|
|
2281
|
-
});
|
|
2282
|
-
}
|
|
2283
|
-
|
|
2284
|
-
//#endregion
|
|
2285
|
-
//#region packages/core/src/Decorators/Http/Middleware.ts
|
|
2286
|
-
/**
|
|
2287
|
-
* Decorator that applies middleware to a class or method
|
|
2288
|
-
* @param middleware - The middleware class to apply
|
|
2289
|
-
* @param opts - Optional configuration parameters
|
|
2290
|
-
* @param opts.type - The type of middleware ('before' or 'after')
|
|
2291
|
-
* @param opts.priority - Priority order for middleware execution (default: 999)
|
|
2292
|
-
* @returns A decorator function that can be applied to classes or methods
|
|
2293
|
-
*
|
|
2294
|
-
* @example
|
|
2295
|
-
* ```typescript
|
|
2296
|
-
* @Middleware(AuthMiddleware)
|
|
2297
|
-
* class UserController {
|
|
2298
|
-
* // ...
|
|
2299
|
-
* }
|
|
2300
|
-
*
|
|
2301
|
-
* // Or on a specific method:
|
|
2302
|
-
* @Middleware(ValidationMiddleware, { type: 'before', priority: 1 })
|
|
2303
|
-
* public async createUser() {
|
|
2304
|
-
* // ...
|
|
2305
|
-
* }
|
|
2306
|
-
* ```
|
|
2307
|
-
*/
|
|
2308
|
-
function Middleware(middleware, opts) {
|
|
2309
|
-
return function internalDecorator(target, propertyName) {
|
|
2310
|
-
const ctx = propertyName ? target : target.prototype;
|
|
2311
|
-
const meta = initializeMetadata(ctx);
|
|
2312
|
-
meta.__middlewares.push({
|
|
2313
|
-
target: propertyName ?? "__global__",
|
|
2314
|
-
priority: opts?.priority ?? 999,
|
|
2315
|
-
middleware
|
|
2316
|
-
});
|
|
2317
|
-
};
|
|
2318
|
-
}
|
|
2319
|
-
|
|
2320
|
-
//#endregion
|
|
2321
|
-
//#region packages/core/src/Decorators/Http/MultipartFormData.ts
|
|
2322
|
-
/**
|
|
2323
|
-
* @class MultipartFormDataDecorator
|
|
2324
|
-
* @extends BaseDecorator<MultipartFormDataOptions>
|
|
2325
|
-
*
|
|
2326
|
-
* A decorator class that handles the metadata for HTTP request bodies.
|
|
2327
|
-
*/
|
|
2328
|
-
var MultipartFormDataDecorator = class extends __vercube_di.BaseDecorator {
|
|
2329
|
-
/**
|
|
2330
|
-
* @method created
|
|
2331
|
-
* This method is called when the decorator is created. It ensures that the metadata
|
|
2332
|
-
* for the property exists and adds the body argument to the metadata.
|
|
2333
|
-
*/
|
|
2334
|
-
created() {
|
|
2335
|
-
initializeMetadata(this.prototype);
|
|
2336
|
-
const method = initializeMetadataMethod(this.prototype, this.propertyName);
|
|
2337
|
-
method.args.push({
|
|
2338
|
-
idx: this.propertyIndex,
|
|
2339
|
-
type: "multipart-form-data"
|
|
2340
|
-
});
|
|
2341
|
-
}
|
|
2342
|
-
};
|
|
2343
|
-
/**
|
|
2344
|
-
* Decorator function that marks a parameter as multipart/form-data request body.
|
|
2345
|
-
* This decorator will automatically parse incoming multipart form data
|
|
2346
|
-
*
|
|
2347
|
-
* @decorator
|
|
2348
|
-
* @returns {Function} A decorator function that can be applied to method parameters
|
|
2349
|
-
*
|
|
2350
|
-
* @example
|
|
2351
|
-
* class UserController {
|
|
2352
|
-
* uploadFile(@MultipartFormData() formData: MyData) {
|
|
2353
|
-
* // Handle multipart form data
|
|
2354
|
-
* }
|
|
2355
|
-
* }
|
|
2356
|
-
*/
|
|
2357
|
-
function MultipartFormData() {
|
|
2358
|
-
return (0, __vercube_di.createDecorator)(MultipartFormDataDecorator, {});
|
|
2359
|
-
}
|
|
2360
|
-
|
|
2361
|
-
//#endregion
|
|
2362
|
-
//#region packages/core/src/Decorators/Http/Session.ts
|
|
2363
|
-
/**
|
|
2364
|
-
* This class is responsible for managing session decorators.
|
|
2365
|
-
*
|
|
2366
|
-
* This class extends the BaseDecorator and is used to register session information
|
|
2367
|
-
* with the MetadataResolver. It ensures that the metadata for the property is created
|
|
2368
|
-
* and adds the session information to the metadata.
|
|
2369
|
-
*
|
|
2370
|
-
* @extends {BaseDecorator<{}>}
|
|
2371
|
-
*/
|
|
2372
|
-
var SessionDecorator = class extends __vercube_di.BaseDecorator {
|
|
2373
|
-
gRuntimeConfig;
|
|
2374
|
-
/**
|
|
2375
|
-
* Called when the decorator is created.
|
|
2376
|
-
*
|
|
2377
|
-
* This method checks if metadata for the property exists, creates it if it doesn't,
|
|
2378
|
-
* and then adds the session information to the metadata.
|
|
2379
|
-
*/
|
|
2380
|
-
created() {
|
|
2381
|
-
initializeMetadata(this.prototype);
|
|
2382
|
-
const method = initializeMetadataMethod(this.prototype, this.propertyName);
|
|
2383
|
-
method.args.push({
|
|
2384
|
-
idx: this.propertyIndex,
|
|
2385
|
-
type: "session",
|
|
2386
|
-
data: {
|
|
2387
|
-
name: this.gRuntimeConfig.runtimeConfig.session?.name ?? "vercube_session",
|
|
2388
|
-
secret: this.gRuntimeConfig.runtimeConfig.session?.secret ?? generateRandomHash(),
|
|
2389
|
-
duration: this.gRuntimeConfig.runtimeConfig.session?.duration ?? 60 * 60 * 24 * 7
|
|
2390
|
-
}
|
|
2391
|
-
});
|
|
2392
|
-
}
|
|
2393
|
-
};
|
|
2394
|
-
(0, import_decorate.default)([(0, __vercube_di.Inject)(RuntimeConfig)], SessionDecorator.prototype, "gRuntimeConfig", void 0);
|
|
2395
|
-
/**
|
|
2396
|
-
* A factory function for creating a SessionDecorator.
|
|
2397
|
-
*
|
|
2398
|
-
* This function returns a decorator function that can be used to annotate
|
|
2399
|
-
* a method parameter with session information.
|
|
2400
|
-
*
|
|
2401
|
-
* @return {Function} The decorator function.
|
|
2402
|
-
*/
|
|
2403
|
-
function Session() {
|
|
2404
|
-
return (0, __vercube_di.createDecorator)(SessionDecorator, {});
|
|
2405
|
-
}
|
|
2406
|
-
|
|
2407
|
-
//#endregion
|
|
2408
|
-
//#region packages/core/src/Decorators/Hooks/Listen.ts
|
|
2409
|
-
/**
|
|
2410
|
-
* This class is responsible for managing cache decorator.
|
|
2411
|
-
*/
|
|
2412
|
-
var ListenDecorator = class extends __vercube_di.BaseDecorator {
|
|
2413
|
-
gHooksService;
|
|
2414
|
-
fHook;
|
|
2415
|
-
/**
|
|
2416
|
-
* Called when decorator is initialized. It will register event listener that will call this function
|
|
2417
|
-
* once executed.
|
|
2418
|
-
*/
|
|
2419
|
-
created() {
|
|
2420
|
-
this.fHook = this.gHooksService.on(this.options.hookType, (data) => this.instance[this.propertyName](data));
|
|
2421
|
-
}
|
|
2422
|
-
/**
|
|
2423
|
-
* Called when decorator is destroyed. It will unregister event listener.
|
|
2424
|
-
*/
|
|
2425
|
-
destroyed() {
|
|
2426
|
-
this.gHooksService.off(this.fHook);
|
|
2427
|
-
}
|
|
2428
|
-
};
|
|
2429
|
-
(0, import_decorate.default)([(0, __vercube_di.Inject)(HooksService)], ListenDecorator.prototype, "gHooksService", void 0);
|
|
2430
|
-
/**
|
|
2431
|
-
* This decorator stores metadata about hook listeners. It can be later used along with function
|
|
2432
|
-
* applyEventListeners() to automatically register all listeners.
|
|
2433
|
-
*
|
|
2434
|
-
* @param hookType hook to listen for
|
|
2435
|
-
* @return decorator function
|
|
2436
|
-
*/
|
|
2437
|
-
function Listen(hookType) {
|
|
2438
|
-
return (0, __vercube_di.createDecorator)(ListenDecorator, { hookType });
|
|
2439
|
-
}
|
|
2440
|
-
|
|
2441
|
-
//#endregion
|
|
2442
|
-
//#region packages/core/src/Services/Plugins/BasePlugin.ts
|
|
2443
|
-
/**
|
|
2444
|
-
* Represents a Plugin.
|
|
2445
|
-
*/
|
|
2446
|
-
var BasePlugin = class {
|
|
2447
|
-
/**
|
|
2448
|
-
* The name of the plugin.
|
|
2449
|
-
*/
|
|
2450
|
-
name;
|
|
2451
|
-
/**
|
|
2452
|
-
* Uses the plugin with the given app.
|
|
2453
|
-
* @param {App} app - The application instance.
|
|
2454
|
-
* @returns {void | Promise<void>} - A void or a promise that resolves to void.
|
|
2455
|
-
*/
|
|
2456
|
-
use(app, options) {}
|
|
2457
|
-
};
|
|
2458
|
-
|
|
2459
|
-
//#endregion
|
|
2460
|
-
//#region packages/core/src/Services/Middleware/BaseMiddleware.ts
|
|
2461
|
-
/**
|
|
2462
|
-
* BaseMiddleware class that serves as a base for all middleware implementations.
|
|
2463
|
-
*/
|
|
2464
|
-
var BaseMiddleware = class {};
|
|
2465
|
-
|
|
2466
|
-
//#endregion
|
|
2467
|
-
//#region packages/core/src/Errors/Http/ForbiddenError.ts
|
|
2468
|
-
/**
|
|
2469
|
-
* Represents a Forbidden error (HTTP 403).
|
|
2470
|
-
* @extends {HttpError}
|
|
2471
|
-
*/
|
|
2472
|
-
var ForbiddenError = class ForbiddenError extends HttpError {
|
|
2473
|
-
/**
|
|
2474
|
-
* The name of the error.
|
|
2475
|
-
* @type {string}
|
|
2476
|
-
*/
|
|
2477
|
-
name = "ForbiddenError";
|
|
2478
|
-
/**
|
|
2479
|
-
* Creates an instance of ForbiddenError.
|
|
2480
|
-
* @param {string} [message] - The error message.
|
|
2481
|
-
*/
|
|
2482
|
-
constructor(message) {
|
|
2483
|
-
super(403);
|
|
2484
|
-
Object.setPrototypeOf(this, ForbiddenError.prototype);
|
|
2485
|
-
if (message) this.message = message;
|
|
2486
|
-
}
|
|
2487
|
-
};
|
|
2488
|
-
|
|
2489
|
-
//#endregion
|
|
2490
|
-
//#region packages/core/src/Errors/Http/MethodNotAllowedError.ts
|
|
2491
|
-
/**
|
|
2492
|
-
* Represents a Method Not Allowed error (HTTP 405).
|
|
2493
|
-
* @extends {HttpError}
|
|
2494
|
-
*/
|
|
2495
|
-
var MethodNotAllowedError = class MethodNotAllowedError extends HttpError {
|
|
2496
|
-
/**
|
|
2497
|
-
* The name of the error.
|
|
2498
|
-
* @type {string}
|
|
2499
|
-
*/
|
|
2500
|
-
name = "MethodNotAllowedError";
|
|
2501
|
-
/**
|
|
2502
|
-
* Creates an instance of MethodNotAllowedError.
|
|
2503
|
-
* @param {string} [message] - The error message.
|
|
2504
|
-
*/
|
|
2505
|
-
constructor(message) {
|
|
2506
|
-
super(405);
|
|
2507
|
-
Object.setPrototypeOf(this, MethodNotAllowedError.prototype);
|
|
2508
|
-
if (message) this.message = message;
|
|
2509
|
-
}
|
|
2510
|
-
};
|
|
2511
|
-
|
|
2512
|
-
//#endregion
|
|
2513
|
-
//#region packages/core/src/Errors/Http/NotAcceptableError.ts
|
|
2514
|
-
/**
|
|
2515
|
-
* Represents a Not Acceptable error (HTTP 406).
|
|
2516
|
-
* @extends {HttpError}
|
|
2517
|
-
*/
|
|
2518
|
-
var NotAcceptableError = class NotAcceptableError extends HttpError {
|
|
2519
|
-
/**
|
|
2520
|
-
* The name of the error.
|
|
2521
|
-
* @type {string}
|
|
2522
|
-
*/
|
|
2523
|
-
name = "NotAcceptableError";
|
|
2524
|
-
/**
|
|
2525
|
-
* Creates an instance of NotAcceptableError.
|
|
2526
|
-
* @param {string} [message] - The error message.
|
|
2527
|
-
*/
|
|
2528
|
-
constructor(message) {
|
|
2529
|
-
super(406);
|
|
2530
|
-
Object.setPrototypeOf(this, NotAcceptableError.prototype);
|
|
2531
|
-
if (message) this.message = message;
|
|
2532
|
-
}
|
|
2533
|
-
};
|
|
2534
|
-
|
|
2535
|
-
//#endregion
|
|
2536
|
-
//#region packages/core/src/Errors/Http/NotFoundError.ts
|
|
2537
|
-
/**
|
|
2538
|
-
* Represents a Not Found error (HTTP 404).
|
|
2539
|
-
* @extends {HttpError}
|
|
2540
|
-
*/
|
|
2541
|
-
var NotFoundError = class NotFoundError extends HttpError {
|
|
2542
|
-
/**
|
|
2543
|
-
* The name of the error.
|
|
2544
|
-
* @type {string}
|
|
2545
|
-
*/
|
|
2546
|
-
name = "NotFoundError";
|
|
2547
|
-
/**
|
|
2548
|
-
* Creates an instance of NotFoundError.
|
|
2549
|
-
* @param {string} [message] - The error message.
|
|
2550
|
-
*/
|
|
2551
|
-
constructor(message) {
|
|
2552
|
-
super(404);
|
|
2553
|
-
Object.setPrototypeOf(this, NotFoundError.prototype);
|
|
2554
|
-
if (message) this.message = message;
|
|
2555
|
-
}
|
|
2556
|
-
};
|
|
2557
|
-
|
|
2558
|
-
//#endregion
|
|
2559
|
-
//#region packages/core/src/Errors/Http/UnauthorizedError.ts
|
|
2560
|
-
/**
|
|
2561
|
-
* Represents an Unauthorized error (HTTP 401).
|
|
2562
|
-
* @extends {HttpError}
|
|
2563
|
-
*/
|
|
2564
|
-
var UnauthorizedError = class UnauthorizedError extends HttpError {
|
|
2565
|
-
/**
|
|
2566
|
-
* The name of the error.
|
|
2567
|
-
* @type {string}
|
|
2568
|
-
*/
|
|
2569
|
-
name = "UnauthorizedError";
|
|
2570
|
-
/**
|
|
2571
|
-
* Creates an instance of UnauthorizedError.
|
|
2572
|
-
* @param {string} [message] - The error message.
|
|
2573
|
-
*/
|
|
2574
|
-
constructor(message) {
|
|
2575
|
-
super(401);
|
|
2576
|
-
Object.setPrototypeOf(this, UnauthorizedError.prototype);
|
|
2577
|
-
if (message) this.message = message;
|
|
2578
|
-
}
|
|
2579
|
-
};
|
|
2580
|
-
|
|
2581
|
-
//#endregion
|
|
2582
|
-
//#region packages/core/src/Types/HttpTypes.ts
|
|
2583
|
-
let HTTPStatus = /* @__PURE__ */ function(HTTPStatus$1) {
|
|
2584
|
-
HTTPStatus$1[HTTPStatus$1["CONTINUE"] = 100] = "CONTINUE";
|
|
2585
|
-
HTTPStatus$1[HTTPStatus$1["SWITCHING_PROTOCOLS"] = 101] = "SWITCHING_PROTOCOLS";
|
|
2586
|
-
HTTPStatus$1[HTTPStatus$1["PROCESSING"] = 102] = "PROCESSING";
|
|
2587
|
-
HTTPStatus$1[HTTPStatus$1["OK"] = 200] = "OK";
|
|
2588
|
-
HTTPStatus$1[HTTPStatus$1["CREATED"] = 201] = "CREATED";
|
|
2589
|
-
HTTPStatus$1[HTTPStatus$1["ACCEPTED"] = 202] = "ACCEPTED";
|
|
2590
|
-
HTTPStatus$1[HTTPStatus$1["NON_AUTHORITATIVE_INFORMATION"] = 203] = "NON_AUTHORITATIVE_INFORMATION";
|
|
2591
|
-
HTTPStatus$1[HTTPStatus$1["NO_CONTENT"] = 204] = "NO_CONTENT";
|
|
2592
|
-
HTTPStatus$1[HTTPStatus$1["RESET_CONTENT"] = 205] = "RESET_CONTENT";
|
|
2593
|
-
HTTPStatus$1[HTTPStatus$1["PARTIAL_CONTENT"] = 206] = "PARTIAL_CONTENT";
|
|
2594
|
-
HTTPStatus$1[HTTPStatus$1["MULTI_STATUS"] = 207] = "MULTI_STATUS";
|
|
2595
|
-
HTTPStatus$1[HTTPStatus$1["ALREADY_REPORTED"] = 208] = "ALREADY_REPORTED";
|
|
2596
|
-
HTTPStatus$1[HTTPStatus$1["IM_USED"] = 226] = "IM_USED";
|
|
2597
|
-
HTTPStatus$1[HTTPStatus$1["MULTIPLE_CHOICES"] = 300] = "MULTIPLE_CHOICES";
|
|
2598
|
-
HTTPStatus$1[HTTPStatus$1["MOVED_PERMANENTLY"] = 301] = "MOVED_PERMANENTLY";
|
|
2599
|
-
HTTPStatus$1[HTTPStatus$1["FOUND"] = 302] = "FOUND";
|
|
2600
|
-
HTTPStatus$1[HTTPStatus$1["SEE_OTHER"] = 303] = "SEE_OTHER";
|
|
2601
|
-
HTTPStatus$1[HTTPStatus$1["NOT_MODIFIED"] = 304] = "NOT_MODIFIED";
|
|
2602
|
-
HTTPStatus$1[HTTPStatus$1["USE_PROXY"] = 305] = "USE_PROXY";
|
|
2603
|
-
HTTPStatus$1[HTTPStatus$1["TEMPORARY_REDIRECT"] = 307] = "TEMPORARY_REDIRECT";
|
|
2604
|
-
HTTPStatus$1[HTTPStatus$1["PERMANENT_REDIRECT"] = 308] = "PERMANENT_REDIRECT";
|
|
2605
|
-
HTTPStatus$1[HTTPStatus$1["BAD_REQUEST"] = 400] = "BAD_REQUEST";
|
|
2606
|
-
HTTPStatus$1[HTTPStatus$1["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
|
|
2607
|
-
HTTPStatus$1[HTTPStatus$1["PAYMENT_REQUIRED"] = 402] = "PAYMENT_REQUIRED";
|
|
2608
|
-
HTTPStatus$1[HTTPStatus$1["FORBIDDEN"] = 403] = "FORBIDDEN";
|
|
2609
|
-
HTTPStatus$1[HTTPStatus$1["NOT_FOUND"] = 404] = "NOT_FOUND";
|
|
2610
|
-
HTTPStatus$1[HTTPStatus$1["METHOD_NOT_ALLOWED"] = 405] = "METHOD_NOT_ALLOWED";
|
|
2611
|
-
HTTPStatus$1[HTTPStatus$1["NOT_ACCEPTABLE"] = 406] = "NOT_ACCEPTABLE";
|
|
2612
|
-
HTTPStatus$1[HTTPStatus$1["PROXY_AUTHENTICATION_REQUIRED"] = 407] = "PROXY_AUTHENTICATION_REQUIRED";
|
|
2613
|
-
HTTPStatus$1[HTTPStatus$1["REQUEST_TIMEOUT"] = 408] = "REQUEST_TIMEOUT";
|
|
2614
|
-
HTTPStatus$1[HTTPStatus$1["CONFLICT"] = 409] = "CONFLICT";
|
|
2615
|
-
HTTPStatus$1[HTTPStatus$1["GONE"] = 410] = "GONE";
|
|
2616
|
-
HTTPStatus$1[HTTPStatus$1["LENGTH_REQUIRED"] = 411] = "LENGTH_REQUIRED";
|
|
2617
|
-
HTTPStatus$1[HTTPStatus$1["PRECONDITION_FAILED"] = 412] = "PRECONDITION_FAILED";
|
|
2618
|
-
HTTPStatus$1[HTTPStatus$1["PAYLOAD_TOO_LARGE"] = 413] = "PAYLOAD_TOO_LARGE";
|
|
2619
|
-
HTTPStatus$1[HTTPStatus$1["URI_TOO_LONG"] = 414] = "URI_TOO_LONG";
|
|
2620
|
-
HTTPStatus$1[HTTPStatus$1["UNSUPPORTED_MEDIA_TYPE"] = 415] = "UNSUPPORTED_MEDIA_TYPE";
|
|
2621
|
-
HTTPStatus$1[HTTPStatus$1["RANGE_NOT_SATISFIABLE"] = 416] = "RANGE_NOT_SATISFIABLE";
|
|
2622
|
-
HTTPStatus$1[HTTPStatus$1["EXPECTATION_FAILED"] = 417] = "EXPECTATION_FAILED";
|
|
2623
|
-
HTTPStatus$1[HTTPStatus$1["I_AM_A_TEAPOT"] = 418] = "I_AM_A_TEAPOT";
|
|
2624
|
-
HTTPStatus$1[HTTPStatus$1["MISDIRECTED_REQUEST"] = 421] = "MISDIRECTED_REQUEST";
|
|
2625
|
-
HTTPStatus$1[HTTPStatus$1["UNPROCESSABLE_ENTITY"] = 422] = "UNPROCESSABLE_ENTITY";
|
|
2626
|
-
HTTPStatus$1[HTTPStatus$1["LOCKED"] = 423] = "LOCKED";
|
|
2627
|
-
HTTPStatus$1[HTTPStatus$1["FAILED_DEPENDENCY"] = 424] = "FAILED_DEPENDENCY";
|
|
2628
|
-
HTTPStatus$1[HTTPStatus$1["TOO_EARLY"] = 425] = "TOO_EARLY";
|
|
2629
|
-
HTTPStatus$1[HTTPStatus$1["UPGRADE_REQUIRED"] = 426] = "UPGRADE_REQUIRED";
|
|
2630
|
-
HTTPStatus$1[HTTPStatus$1["PRECONDITION_REQUIRED"] = 428] = "PRECONDITION_REQUIRED";
|
|
2631
|
-
HTTPStatus$1[HTTPStatus$1["TOO_MANY_REQUESTS"] = 429] = "TOO_MANY_REQUESTS";
|
|
2632
|
-
HTTPStatus$1[HTTPStatus$1["REQUEST_HEADER_FIELDS_TOO_LARGE"] = 431] = "REQUEST_HEADER_FIELDS_TOO_LARGE";
|
|
2633
|
-
HTTPStatus$1[HTTPStatus$1["UNAVAILABLE_FOR_LEGAL_REASONS"] = 451] = "UNAVAILABLE_FOR_LEGAL_REASONS";
|
|
2634
|
-
HTTPStatus$1[HTTPStatus$1["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
|
|
2635
|
-
HTTPStatus$1[HTTPStatus$1["NOT_IMPLEMENTED"] = 501] = "NOT_IMPLEMENTED";
|
|
2636
|
-
HTTPStatus$1[HTTPStatus$1["BAD_GATEWAY"] = 502] = "BAD_GATEWAY";
|
|
2637
|
-
HTTPStatus$1[HTTPStatus$1["SERVICE_UNAVAILABLE"] = 503] = "SERVICE_UNAVAILABLE";
|
|
2638
|
-
HTTPStatus$1[HTTPStatus$1["GATEWAY_TIMEOUT"] = 504] = "GATEWAY_TIMEOUT";
|
|
2639
|
-
HTTPStatus$1[HTTPStatus$1["HTTP_VERSION_NOT_SUPPORTED"] = 505] = "HTTP_VERSION_NOT_SUPPORTED";
|
|
2640
|
-
HTTPStatus$1[HTTPStatus$1["VARIANT_ALSO_NEGOTIATES"] = 506] = "VARIANT_ALSO_NEGOTIATES";
|
|
2641
|
-
HTTPStatus$1[HTTPStatus$1["INSUFFICIENT_STORAGE"] = 507] = "INSUFFICIENT_STORAGE";
|
|
2642
|
-
HTTPStatus$1[HTTPStatus$1["LOOP_DETECTED"] = 508] = "LOOP_DETECTED";
|
|
2643
|
-
HTTPStatus$1[HTTPStatus$1["NOT_EXTENDED"] = 510] = "NOT_EXTENDED";
|
|
2644
|
-
HTTPStatus$1[HTTPStatus$1["NETWORK_AUTHENTICATION_REQUIRED"] = 511] = "NETWORK_AUTHENTICATION_REQUIRED";
|
|
2645
|
-
return HTTPStatus$1;
|
|
2646
|
-
}({});
|
|
2647
|
-
|
|
2648
|
-
//#endregion
|
|
2649
|
-
exports.App = App
|
|
2650
|
-
exports.BadRequestError = BadRequestError
|
|
2651
|
-
exports.BaseMiddleware = BaseMiddleware
|
|
2652
|
-
exports.BasePlugin = BasePlugin
|
|
2653
|
-
exports.Body = Body
|
|
2654
|
-
exports.Connect = Connect
|
|
2655
|
-
exports.Controller = Controller
|
|
2656
|
-
exports.Delete = Delete
|
|
2657
|
-
exports.ErrorHandlerProvider = ErrorHandlerProvider
|
|
2658
|
-
Object.defineProperty(exports, 'FastResponse', {
|
|
2659
|
-
enumerable: true,
|
|
2660
|
-
get: function () {
|
|
2661
|
-
return srvx.FastResponse;
|
|
2662
|
-
}
|
|
2663
|
-
});
|
|
2664
|
-
exports.ForbiddenError = ForbiddenError
|
|
2665
|
-
exports.Get = Get
|
|
2666
|
-
exports.GlobalMiddlewareRegistry = GlobalMiddlewareRegistry
|
|
2667
|
-
exports.HTTPStatus = HTTPStatus
|
|
2668
|
-
exports.Head = Head
|
|
2669
|
-
exports.Header = Header
|
|
2670
|
-
exports.Headers = Headers$1
|
|
2671
|
-
exports.HooksService = HooksService
|
|
2672
|
-
exports.HttpError = HttpError
|
|
2673
|
-
exports.HttpServer = HttpServer
|
|
2674
|
-
exports.InternalServerError = InternalServerError
|
|
2675
|
-
exports.Listen = Listen
|
|
2676
|
-
exports.MetadataResolver = MetadataResolver
|
|
2677
|
-
exports.MethodNotAllowedError = MethodNotAllowedError
|
|
2678
|
-
exports.Middleware = Middleware
|
|
2679
|
-
exports.MultipartFormData = MultipartFormData
|
|
2680
|
-
exports.NotAcceptableError = NotAcceptableError
|
|
2681
|
-
exports.NotFoundError = NotFoundError
|
|
2682
|
-
exports.Options = Options
|
|
2683
|
-
exports.Param = Param
|
|
2684
|
-
exports.Patch = Patch
|
|
2685
|
-
exports.Post = Post
|
|
2686
|
-
exports.Put = Put
|
|
2687
|
-
exports.QueryParam = QueryParam
|
|
2688
|
-
exports.QueryParams = QueryParams
|
|
2689
|
-
exports.Redirect = Redirect
|
|
2690
|
-
exports.Request = Request
|
|
2691
|
-
exports.Response = Response$1
|
|
2692
|
-
exports.Router = Router
|
|
2693
|
-
exports.Session = Session
|
|
2694
|
-
exports.SetHeader = SetHeader
|
|
2695
|
-
exports.Status = Status
|
|
2696
|
-
exports.Trace = Trace
|
|
2697
|
-
exports.UnauthorizedError = UnauthorizedError
|
|
2698
|
-
exports.createApp = createApp
|
|
2699
|
-
exports.createMetadataCtx = createMetadataCtx
|
|
2700
|
-
exports.createMetadataMethod = createMetadataMethod
|
|
2701
|
-
exports.defineConfig = defineConfig
|
|
2702
|
-
exports.initializeMetadata = initializeMetadata
|
|
2703
|
-
exports.initializeMetadataMethod = initializeMetadataMethod
|
|
2704
|
-
exports.loadVercubeConfig = loadVercubeConfig
|