raiton 4.0.0 → 5.4.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/README.md +37 -2
  3. package/build/bin/index.mjs +568 -275
  4. package/examples/user-controller.example.ts +53 -0
  5. package/package.json +6 -8
  6. package/source/bin/cli-tools.ts +2 -0
  7. package/source/commands/build.command.ts +2 -1
  8. package/source/commands/develop.command.ts +1 -0
  9. package/source/commands/start.command.ts +15 -10
  10. package/source/core/application.ts +40 -31
  11. package/source/core/artifacts/artifact.ts +10 -0
  12. package/source/core/artifacts/index.ts +1 -0
  13. package/source/core/artifacts/runner.ts +3 -0
  14. package/source/core/builder.ts +42 -13
  15. package/source/core/hooks.ts +0 -8
  16. package/source/core/index.ts +15 -15
  17. package/source/core/injection/injection.ts +7 -4
  18. package/source/core/middleware/pipeline.ts +2 -8
  19. package/source/core/plugins/scope.ts +18 -6
  20. package/source/core/router/handler.ts +24 -78
  21. package/source/core/router/handler.utils.ts +135 -0
  22. package/source/core/router/matcher.ts +13 -9
  23. package/source/core/router/router.ts +5 -1
  24. package/source/core/thread.ts +19 -16
  25. package/source/framework/artifacts.ts +7 -1
  26. package/source/framework/constants/decorators.constant.ts +7 -0
  27. package/source/framework/decorators/api-response.decorator.ts +127 -0
  28. package/source/framework/decorators/api.decorator.ts +185 -0
  29. package/source/framework/decorators/index.ts +4 -2
  30. package/source/framework/decorators/{parametrable.ts → parametrable.decorator.ts} +1 -1
  31. package/source/framework/encryption.ts +2 -1
  32. package/source/framework/enums/encrypted.enum.ts +2 -2
  33. package/source/framework/enums/http-parameters.enum.ts +1 -0
  34. package/source/framework/enums/runtime.enum.ts +2 -2
  35. package/source/framework/env.ts +2 -2
  36. package/source/framework/exceptions/http-exception.ts +1 -1
  37. package/source/framework/index.ts +1 -0
  38. package/source/framework/plugins/body-parser.plugin.ts +28 -11
  39. package/source/framework/plugins/index.ts +3 -2
  40. package/source/framework/plugins/openapi.plugin.ts +98 -0
  41. package/source/framework/plugins/security/cors.ts +59 -25
  42. package/source/framework/responses/helpers.ts +4 -3
  43. package/source/framework/responses/http-throwable.ts +2 -2
  44. package/source/framework/responses/http.ts +3 -3
  45. package/source/framework/runtime/bun/server.ts +6 -2
  46. package/source/framework/runtime/deno/server.ts +93 -42
  47. package/source/framework/runtime/index.ts +18 -13
  48. package/source/framework/runtime/node/reply.ts +37 -0
  49. package/source/framework/runtime/node/request.ts +47 -0
  50. package/source/framework/runtime/node/server.ts +5 -33
  51. package/source/framework/runtime/web/server.ts +73 -57
  52. package/source/framework/utilities/cookie.util.ts +11 -0
  53. package/source/framework/utilities/index.ts +3 -1
  54. package/source/framework/utilities/openapi.utils.ts +497 -0
  55. package/source/framework/view-model.ts +4 -0
  56. package/source/types/access-guards.ts +4 -0
  57. package/source/types/artifact.ts +42 -1
  58. package/source/types/builder.ts +6 -1
  59. package/source/types/http-responses.ts +8 -0
  60. package/source/types/runtime.ts +4 -2
  61. package/source/types/scheme.ts +153 -0
  62. package/source/types/thread.ts +3 -1
@@ -4279,7 +4279,7 @@ var require_format = __commonJS((exports, module) => {
4279
4279
  // node_modules/node-gyp-build/node-gyp-build.js
4280
4280
  var require_node_gyp_build = __commonJS((exports, module) => {
4281
4281
  var fs2 = __require("fs");
4282
- var path5 = __require("path");
4282
+ var path3 = __require("path");
4283
4283
  var os = __require("os");
4284
4284
  var runtimeRequire = typeof __webpack_require__ === "function" ? __non_webpack_require__ : __require;
4285
4285
  var vars = process.config && process.config.variables || {};
@@ -4296,24 +4296,24 @@ var require_node_gyp_build = __commonJS((exports, module) => {
4296
4296
  return runtimeRequire(load.resolve(dir));
4297
4297
  }
4298
4298
  load.resolve = load.path = function(dir) {
4299
- dir = path5.resolve(dir || ".");
4299
+ dir = path3.resolve(dir || ".");
4300
4300
  try {
4301
- var name = runtimeRequire(path5.join(dir, "package.json")).name.toUpperCase().replace(/-/g, "_");
4301
+ var name = runtimeRequire(path3.join(dir, "package.json")).name.toUpperCase().replace(/-/g, "_");
4302
4302
  if (process.env[name + "_PREBUILD"])
4303
4303
  dir = process.env[name + "_PREBUILD"];
4304
4304
  } catch (err) {}
4305
4305
  if (!prebuildsOnly) {
4306
- var release = getFirst(path5.join(dir, "build/Release"), matchBuild);
4306
+ var release = getFirst(path3.join(dir, "build/Release"), matchBuild);
4307
4307
  if (release)
4308
4308
  return release;
4309
- var debug = getFirst(path5.join(dir, "build/Debug"), matchBuild);
4309
+ var debug = getFirst(path3.join(dir, "build/Debug"), matchBuild);
4310
4310
  if (debug)
4311
4311
  return debug;
4312
4312
  }
4313
4313
  var prebuild = resolve(dir);
4314
4314
  if (prebuild)
4315
4315
  return prebuild;
4316
- var nearby = resolve(path5.dirname(process.execPath));
4316
+ var nearby = resolve(path3.dirname(process.execPath));
4317
4317
  if (nearby)
4318
4318
  return nearby;
4319
4319
  var target = [
@@ -4332,16 +4332,16 @@ var require_node_gyp_build = __commonJS((exports, module) => {
4332
4332
  loaded from: ` + dir + `
4333
4333
  `);
4334
4334
  function resolve(dir2) {
4335
- var tuples = readdirSync(path5.join(dir2, "prebuilds")).map(parseTuple);
4335
+ var tuples = readdirSync(path3.join(dir2, "prebuilds")).map(parseTuple);
4336
4336
  var tuple = tuples.filter(matchTuple(platform, arch)).sort(compareTuples)[0];
4337
4337
  if (!tuple)
4338
4338
  return;
4339
- var prebuilds = path5.join(dir2, "prebuilds", tuple.name);
4339
+ var prebuilds = path3.join(dir2, "prebuilds", tuple.name);
4340
4340
  var parsed = readdirSync(prebuilds).map(parseTags);
4341
4341
  var candidates = parsed.filter(matchTags(runtime2, abi));
4342
4342
  var winner = candidates.sort(compareTags(runtime2))[0];
4343
4343
  if (winner)
4344
- return path5.join(prebuilds, winner.file);
4344
+ return path3.join(prebuilds, winner.file);
4345
4345
  }
4346
4346
  };
4347
4347
  function readdirSync(dir) {
@@ -4353,7 +4353,7 @@ var require_node_gyp_build = __commonJS((exports, module) => {
4353
4353
  }
4354
4354
  function getFirst(dir, filter) {
4355
4355
  var files = readdirSync(dir).filter(filter);
4356
- return files[0] && path5.join(dir, files[0]);
4356
+ return files[0] && path3.join(dir, files[0]);
4357
4357
  }
4358
4358
  function matchBuild(name) {
4359
4359
  return /\.node$/.test(name);
@@ -4630,8 +4630,8 @@ var require_promises = __commonJS((exports, module) => {
4630
4630
  // node_modules/bcrypt/bcrypt.js
4631
4631
  var require_bcrypt = __commonJS((exports, module) => {
4632
4632
  var __dirname = "/home/runner/work/raiton/raiton/node_modules/bcrypt";
4633
- var path5 = __require("path");
4634
- var bindings = require_node_gyp_build2()(path5.resolve(__dirname));
4633
+ var path3 = __require("path");
4634
+ var bindings = require_node_gyp_build2()(path3.resolve(__dirname));
4635
4635
  var crypto2 = __require("crypto");
4636
4636
  var promises = require_promises();
4637
4637
  function genSaltSync(rounds, minor) {
@@ -4799,7 +4799,7 @@ var require_bcrypt = __commonJS((exports, module) => {
4799
4799
  });
4800
4800
 
4801
4801
  // source/bin/index.ts
4802
- var import_reflect_metadata6 = __toESM(require_Reflect(), 1);
4802
+ var import_reflect_metadata8 = __toESM(require_Reflect(), 1);
4803
4803
 
4804
4804
  // node_modules/commander/esm.mjs
4805
4805
  var import__ = __toESM(require_commander(), 1);
@@ -4817,7 +4817,7 @@ var {
4817
4817
  Help
4818
4818
  } = import__.default;
4819
4819
  // package.json
4820
- var version = "4.0.0";
4820
+ var version = "5.4.0-beta.2";
4821
4821
 
4822
4822
  // source/bin/cli.ts
4823
4823
  var CLI = new Command;
@@ -6223,6 +6223,14 @@ function isArtifact(filename, artifact) {
6223
6223
  filename.endsWith(`.${artifact}.cjs`)
6224
6224
  ].some(Boolean);
6225
6225
  }
6226
+ // source/framework/utilities/json.util.ts
6227
+ function tryParseJson(obj) {
6228
+ try {
6229
+ return JSON.parse(obj);
6230
+ } catch (e) {
6231
+ return null;
6232
+ }
6233
+ }
6226
6234
  // source/framework/utilities/path.util.ts
6227
6235
  import path2 from "node:path";
6228
6236
  import { fileURLToPath } from "node:url";
@@ -6236,27 +6244,6 @@ function getPackageRoot(importMetaUrl) {
6236
6244
  }
6237
6245
  return dirname;
6238
6246
  }
6239
- // source/core/directories.ts
6240
- import path4 from "node:path";
6241
- class RaitonDirectories {
6242
- static index = `.${Raiton.identifier}`;
6243
- static bootstrapFile = "main.ts";
6244
- static caches(workdir) {
6245
- return path4.join(workdir, this.index, "caches");
6246
- }
6247
- static artifacts(workdir) {
6248
- return path4.join(workdir, this.index, "artifacts");
6249
- }
6250
- static server(workdir) {
6251
- return path4.join(workdir, this.index, "server");
6252
- }
6253
- static root(workdir) {
6254
- return path4.join(workdir, this.index);
6255
- }
6256
- static app() {
6257
- return path4.join(Raiton.thread?.builder.workdir || "", RaitonConfig.get("rootDir") || "./");
6258
- }
6259
- }
6260
6247
  // source/framework/constants/decorators.constant.ts
6261
6248
  var METADATA_KEYS = {
6262
6249
  CONTROLLERS: Symbol("controller:meta"),
@@ -6266,7 +6253,13 @@ var METADATA_KEYS = {
6266
6253
  GRAFTS: Symbol("graft:meta"),
6267
6254
  CONTAINER: Symbol("container:meta"),
6268
6255
  INJECT_PARAMETERS: Symbol("inject:parameters"),
6269
- INJECT_PROPERTIES: Symbol("inject:properties")
6256
+ INJECT_PROPERTIES: Symbol("inject:properties"),
6257
+ API_RESPONSES: Symbol("api:responses"),
6258
+ API_REQUEST_BODY: Symbol("api:requestBody"),
6259
+ API_PARAMETERS: Symbol("api:parameters"),
6260
+ API_TAGS: Symbol("api:tags"),
6261
+ API_OPERATION: Symbol("api:operation"),
6262
+ API_SECURITY: Symbol("api:security")
6270
6263
  };
6271
6264
  // source/framework/responses/http.ts
6272
6265
  class HttpResponse {
@@ -6364,69 +6357,142 @@ class ThrowableResponse extends Error {
6364
6357
  statusCode: this.statusCode,
6365
6358
  data: typeof this.input === "object" ? this.input.data : undefined,
6366
6359
  error: typeof this.input === "object" ? this.input.error : false,
6367
- stack: stack instanceof Error ? Raiton.thread?.builder?.options?.development ? this.stack?.split(`
6360
+ stack: stack instanceof Error ? Raiton.thread?.builder?.options?.serve ? this.stack?.split(`
6368
6361
  `).map((e) => e.trim()) : undefined : stack
6369
6362
  };
6370
6363
  }
6371
6364
  }
6372
- // source/core/socket/metadata.ts
6365
+ // source/core/controller/metadata.ts
6373
6366
  var import_reflect_metadata = __toESM(require_Reflect2(), 1);
6374
- // source/framework/decorators/routable.decorator.ts
6375
- function stabilizeRoute(meta, { path: path5, method, propertyKey }) {
6376
- return {
6377
- ...meta.routes.filter((route) => route.path === path5 && route.method === method || route.propertyKey === propertyKey)[0] || {},
6378
- method,
6379
- path: path5,
6380
- propertyKey
6381
- };
6367
+ function getControllerMetadata(target) {
6368
+ let metadata = Reflect.getMetadata(METADATA_KEYS.CONTROLLERS, target);
6369
+ if (!metadata) {
6370
+ metadata = { routes: [], middlewares: {} };
6371
+ Reflect.defineMetadata(METADATA_KEYS.CONTROLLERS, metadata, target);
6372
+ }
6373
+ return metadata;
6382
6374
  }
6383
- function createRoutableDecorator(method) {
6384
- return (path5 = "") => (target, propertyKey) => {
6385
- const meta = getControllerMetadata(target);
6386
- const route = stabilizeRoute(meta, {
6375
+ // source/core/router/route.ts
6376
+ class Route {
6377
+ method;
6378
+ path;
6379
+ version;
6380
+ handler;
6381
+ parameters = {};
6382
+ constructor(def) {
6383
+ this.method = def.method;
6384
+ this.path = def.path;
6385
+ this.version = def.version;
6386
+ this.handler = def.handler;
6387
+ }
6388
+ get params() {
6389
+ const fullPath = this.version ? `/${this.version}${this.path}` : this.path;
6390
+ const matches = fullPath.match(/:[a-zA-Z0-9_]+/g);
6391
+ return matches ? matches.map((m) => m.substring(1)) : [];
6392
+ }
6393
+ get name() {
6394
+ return this.handler.name;
6395
+ }
6396
+ extractParams(url) {
6397
+ const fullPath = (this.version ? `/${this.version}${this.path}` : this.path).replace(/\/+$/, "");
6398
+ const paramNames = this.params;
6399
+ if (paramNames.length === 0)
6400
+ return this;
6401
+ const regexPath = fullPath.replace(/:[a-zA-Z0-9_]+/g, "([^/]+)");
6402
+ const regex = new RegExp(`^${regexPath || "/"}/?$`);
6403
+ const matches = url.match(regex);
6404
+ if (matches) {
6405
+ const params = {};
6406
+ paramNames.forEach((name, index) => {
6407
+ params[name] = matches[index + 1];
6408
+ });
6409
+ this.parameters = params;
6410
+ }
6411
+ return this;
6412
+ }
6413
+ match(method, url) {
6414
+ if (method !== this.method)
6415
+ return false;
6416
+ const fullPath = (this.version ? `/${this.version}${this.path}` : this.path).replace(/\/+$/, "");
6417
+ const cleanUrl = url.replace(/\/+$/, "");
6418
+ if (!fullPath.includes(":")) {
6419
+ return (fullPath || "/") === (cleanUrl || "/");
6420
+ }
6421
+ const regexPath = fullPath.replace(/:[a-zA-Z0-9_]+/g, "([^/]+)");
6422
+ const regex = new RegExp(`^${regexPath || "/"}/?$`);
6423
+ return regex.test(url);
6424
+ }
6425
+ }
6426
+ // source/core/router/matcher.ts
6427
+ class RouteMatcher {
6428
+ _routes = new Map;
6429
+ getKey(route) {
6430
+ return `${route.method}:${route.path}`;
6431
+ }
6432
+ get routes() {
6433
+ return this._routes;
6434
+ }
6435
+ add(route) {
6436
+ this._routes.set(this.getKey(route), route);
6437
+ return this;
6438
+ }
6439
+ has(route) {
6440
+ return this._routes.has(this.getKey(route));
6441
+ }
6442
+ find(route) {
6443
+ return this._routes.get(this.getKey(route));
6444
+ }
6445
+ replace(route) {
6446
+ if (this.has(route)) {
6447
+ this._routes.set(this.getKey(route), route);
6448
+ }
6449
+ return this;
6450
+ }
6451
+ upsert(route) {
6452
+ this._routes.set(this.getKey(route), route);
6453
+ return this;
6454
+ }
6455
+ remove(route) {
6456
+ this._routes.delete(this.getKey(route));
6457
+ return this;
6458
+ }
6459
+ match(method, url) {
6460
+ for (const route of this._routes.values())
6461
+ if (route.match(method, url))
6462
+ return route.extractParams(url);
6463
+ return null;
6464
+ }
6465
+ clear() {
6466
+ this._routes.clear();
6467
+ return this;
6468
+ }
6469
+ }
6470
+ // source/core/router/router.ts
6471
+ class Router {
6472
+ matcher = new RouteMatcher;
6473
+ add(method, path3, handler, version2) {
6474
+ const route = new Route({
6387
6475
  method,
6388
- path: path5,
6389
- propertyKey
6476
+ path: path3,
6477
+ handler,
6478
+ version: version2
6390
6479
  });
6391
- meta.routes.push(route);
6392
- };
6393
- }
6394
- var Get = createRoutableDecorator("GET" /* GET */);
6395
- var Post = createRoutableDecorator("POST" /* POST */);
6396
- var Put = createRoutableDecorator("PUT" /* PUT */);
6397
- var Patch = createRoutableDecorator("PATCH" /* PATCH */);
6398
- var Options = createRoutableDecorator("OPTIONS" /* OPTIONS */);
6399
- var Trace = createRoutableDecorator("TRACE" /* TRACE */);
6400
- var Delete = createRoutableDecorator("DELETE" /* DELETE */);
6401
- var Head = createRoutableDecorator("HEAD" /* HEAD */);
6402
- // source/framework/decorators/parametrable.ts
6403
- var import_reflect_metadata2 = __toESM(require_Reflect2(), 1);
6404
- function createRouteParametrableDecorator(type, callable2) {
6405
- return (key) => {
6406
- return (target, propertyKey, index) => {
6407
- const params = Reflect.getMetadata(METADATA_KEYS.ROUTE_PARAMETERS, target.constructor) || {};
6408
- const metatypes = Reflect.getMetadata("design:paramtypes", target, propertyKey);
6409
- const metatype = metatypes ? metatypes[index] : undefined;
6410
- if (!params[propertyKey]) {
6411
- params[propertyKey] = [];
6412
- }
6413
- params[propertyKey].push({ index, type, key, callable: callable2, metatype });
6414
- Reflect.defineMetadata(METADATA_KEYS.ROUTE_PARAMETERS, params, target.constructor);
6415
- };
6416
- };
6480
+ this.matcher.add(route);
6481
+ return route;
6482
+ }
6483
+ remove(route) {
6484
+ this.matcher.remove(route);
6485
+ }
6486
+ match(method, url) {
6487
+ return this.matcher.match(method, url);
6488
+ }
6489
+ reset() {
6490
+ this.matcher.clear();
6491
+ }
6492
+ getRoutes() {
6493
+ return Array.from(this.matcher.routes.values());
6494
+ }
6417
6495
  }
6418
- var Query = createRouteParametrableDecorator("query" /* QUERY */);
6419
- var Param = createRouteParametrableDecorator("param" /* PARAM */);
6420
- var Body = createRouteParametrableDecorator("body" /* BODY */);
6421
- var UploadedFile = createRouteParametrableDecorator("upload" /* UPLOAD_FILE */);
6422
- var Headers2 = createRouteParametrableDecorator("header" /* HEADER */);
6423
- var Req = createRouteParametrableDecorator("req" /* REQ */);
6424
- var Reply = createRouteParametrableDecorator("reply" /* REPLY */);
6425
- // source/framework/decorators/injection.decorator.ts
6426
- var import_reflect_metadata4 = __toESM(require_Reflect2(), 1);
6427
-
6428
- // source/core/injection/injection.ts
6429
- var import_reflect_metadata3 = __toESM(require_Reflect2(), 1);
6430
6496
  // source/framework/exceptions/throwable.ts
6431
6497
  class Throwable extends Error {
6432
6498
  statusCode;
@@ -6455,6 +6521,7 @@ class Throwable extends Error {
6455
6521
  }
6456
6522
  }
6457
6523
  // source/core/injection/injection.ts
6524
+ var import_reflect_metadata2 = __toESM(require_Reflect2(), 1);
6458
6525
  var camelCase = TextUtility.camelCase;
6459
6526
 
6460
6527
  class Injection {
@@ -6498,8 +6565,8 @@ class Injection {
6498
6565
  static getDependents(name) {
6499
6566
  return Array.from(this._dependents.get(this.normalizeName(name)) || []);
6500
6567
  }
6501
- static registerArtifactPath(name, path5) {
6502
- this._artifactPaths.set(this.normalizeName(name), path5);
6568
+ static registerArtifactPath(name, path3) {
6569
+ this._artifactPaths.set(this.normalizeName(name), path3);
6503
6570
  return this;
6504
6571
  }
6505
6572
  static getArtifactPath(name) {
@@ -6523,16 +6590,16 @@ class Injection {
6523
6590
  continue;
6524
6591
  }
6525
6592
  if (typeof param === "function") {
6526
- const metadata2 = Reflect.getMetadata(METADATA_KEYS.CONTAINER, param);
6527
- const token2 = metadata2?.name || param.name;
6593
+ const metadata = Reflect.getMetadata(METADATA_KEYS.CONTAINER, param);
6594
+ const token2 = metadata?.name || param.name;
6528
6595
  this.addDependent(token2, definition.name);
6529
6596
  args.push(this.get(token2, effectiveScope));
6530
6597
  continue;
6531
6598
  }
6532
6599
  }
6533
6600
  if (designParam && typeof designParam === "function" && designParam.name) {
6534
- const metadata2 = Reflect.getMetadata(METADATA_KEYS.CONTAINER, designParam);
6535
- const token = metadata2?.name || designParam.name;
6601
+ const metadata = Reflect.getMetadata(METADATA_KEYS.CONTAINER, designParam);
6602
+ const token = metadata?.name || designParam.name;
6536
6603
  this.addDependent(token, definition.name);
6537
6604
  args.push(this.get(token, effectiveScope));
6538
6605
  continue;
@@ -6556,7 +6623,7 @@ class Injection {
6556
6623
  const name_ = this.normalizeName(name);
6557
6624
  const cls = this._classes.get(name_);
6558
6625
  if (!cls)
6559
- throw new Throwable(`Dependency ${name} not registered`);
6626
+ throw new Throwable(`Dependency ${name_} not registered`);
6560
6627
  const effectiveScope = scope || cls.scope || this.defaultScope;
6561
6628
  if (this._resolutionStack.includes(name_)) {
6562
6629
  throw new Throwable(`Circular dependency detected: ${this._resolutionStack.join(" -> ")} -> ${name}`);
@@ -6597,8 +6664,8 @@ class Injection {
6597
6664
  this.addDependent(token, definition.name);
6598
6665
  instance[propertyKey] = this.get(token, scope);
6599
6666
  } else if (typeof type === "function") {
6600
- const metadata2 = Reflect.getMetadata(METADATA_KEYS.CONTAINER, type);
6601
- const token_ = metadata2?.name || type.name;
6667
+ const metadata = Reflect.getMetadata(METADATA_KEYS.CONTAINER, type);
6668
+ const token_ = metadata?.name || type.name;
6602
6669
  this.addDependent(token_, definition.name);
6603
6670
  instance[propertyKey] = this.get(token_, scope);
6604
6671
  }
@@ -6624,12 +6691,224 @@ class Injection {
6624
6691
  this.clear();
6625
6692
  }
6626
6693
  static resolve(construct) {
6627
- const metadata2 = Reflect.getMetadata(METADATA_KEYS.CONTAINER, construct);
6628
- if (!metadata2)
6629
- throw new Throwable(`Cannot resolve ${construct.name} as dependency`);
6630
- return this.get(metadata2.name);
6694
+ const metadata = Reflect.getMetadata(METADATA_KEYS.CONTAINER, construct);
6695
+ const name = metadata?.name || ("constructor" in construct ? construct.constructor.name || false : false) || construct.name;
6696
+ if (!metadata) {
6697
+ if (typeof name === "undefined")
6698
+ Logger.debug("Cannot resolve", construct);
6699
+ throw new Throwable(`Cannot resolve ${name} as dependency`);
6700
+ }
6701
+ return this.get(name);
6702
+ }
6703
+ }
6704
+ // source/framework/plugins/body-parser.plugin.ts
6705
+ function bodyParserPlugin() {
6706
+ return {
6707
+ name: "body-parser-plugin",
6708
+ setup: (scope) => {
6709
+ scope.use(async ({ context, next }) => {
6710
+ readQueryBody(context);
6711
+ const isGetOrHead = ["GET", "HEAD"].includes(context.req.method.toUpperCase());
6712
+ if (isGetOrHead) {
6713
+ context.req.body = context.req.query;
6714
+ }
6715
+ const hasBody = context.req.body !== undefined && context.req.body !== null;
6716
+ if (hasBody && !context.state.bodyParsed && !isGetOrHead) {
6717
+ try {
6718
+ const contentType = context.req.headers.get("content-type") || "";
6719
+ const rawBody = await readRawBody(context.req.body);
6720
+ const bodyString = decode(rawBody);
6721
+ await readMultipartBody(context, contentType, rawBody);
6722
+ readJsonBody(context, contentType, bodyString);
6723
+ readUrlEncodedBody(context, contentType, bodyString);
6724
+ readTextBody(context, contentType, bodyString);
6725
+ if (!context.state.bodyParsed) {
6726
+ context.req.body = rawBody;
6727
+ context.state.bodyParsed = true;
6728
+ }
6729
+ } catch (e) {
6730
+ Logger.error("Error parsing body:", e);
6731
+ }
6732
+ }
6733
+ await next();
6734
+ });
6735
+ }
6736
+ };
6737
+ }
6738
+ function readJsonBody(ctx, contentType, body) {
6739
+ if (contentType.includes("application/json")) {
6740
+ ctx.req.body = tryParseJson(body) || {};
6741
+ ctx.state.bodyParsed = true;
6742
+ }
6743
+ }
6744
+ async function readMultipartBody(ctx, contentType, rawBody) {
6745
+ if (contentType.includes("multipart/form-data")) {
6746
+ try {
6747
+ const tempRequest = new Request(ctx.req.url, {
6748
+ method: ctx.req.method,
6749
+ headers: ctx.req.headers,
6750
+ body: rawBody
6751
+ });
6752
+ const formData = await tempRequest.formData();
6753
+ const record = {};
6754
+ const files = {};
6755
+ for (const [key, value] of formData.entries()) {
6756
+ const v = value;
6757
+ if (v && v instanceof File) {
6758
+ files[key] = {
6759
+ name: v.name,
6760
+ type: v.type,
6761
+ size: v.size,
6762
+ lastModified: v.lastModified,
6763
+ buffer: Buffer.from(await v.arrayBuffer())
6764
+ };
6765
+ } else {
6766
+ record[key] = value;
6767
+ }
6768
+ }
6769
+ ctx.req.body = record;
6770
+ ctx.req.files = files;
6771
+ ctx.req.file = Object.values(files)[0] || null;
6772
+ ctx.state.bodyParsed = true;
6773
+ } catch (e) {
6774
+ Logger.error("Error parsing multipart body:", e);
6775
+ }
6776
+ }
6777
+ }
6778
+ function readUrlEncodedBody(ctx, contentType, body) {
6779
+ if (contentType.includes("application/x-www-form-urlencoded")) {
6780
+ const params = new URLSearchParams(body);
6781
+ const record = {};
6782
+ params.forEach((value, key) => {
6783
+ record[key] = value;
6784
+ });
6785
+ ctx.req.body = record;
6786
+ ctx.state.bodyParsed = true;
6787
+ }
6788
+ }
6789
+ function readTextBody(ctx, contentType, body) {
6790
+ if (contentType.includes("text/")) {
6791
+ ctx.req.body = body;
6792
+ ctx.state.bodyParsed = true;
6793
+ }
6794
+ }
6795
+ function readQueryBody(ctx) {
6796
+ const searchParams = new URLSearchParams(ctx.req.url.split("?")[1] || "");
6797
+ const record = {};
6798
+ searchParams.forEach((value, key) => record[key] = value);
6799
+ ctx.req.query = record;
6800
+ }
6801
+ async function readRawBody(body) {
6802
+ if (!body)
6803
+ return new Uint8Array(0);
6804
+ if (body instanceof Uint8Array || typeof body === "string") {
6805
+ return body;
6806
+ }
6807
+ if (typeof body === "object" && !("on" in body) && !(body instanceof ReadableStream)) {
6808
+ return JSON.stringify(body);
6809
+ }
6810
+ if (body instanceof ReadableStream) {
6811
+ const reader = body.getReader();
6812
+ const chunks = [];
6813
+ while (true) {
6814
+ const { done, value } = await reader.read();
6815
+ if (done)
6816
+ break;
6817
+ chunks.push(value);
6818
+ }
6819
+ const totalLength = chunks.reduce((acc, chunk) => acc + chunk.length, 0);
6820
+ const result = new Uint8Array(totalLength);
6821
+ let offset = 0;
6822
+ for (const chunk of chunks) {
6823
+ result.set(chunk, offset);
6824
+ offset += chunk.length;
6825
+ }
6826
+ return result;
6827
+ }
6828
+ if (typeof body === "object" && body !== null && "on" in body && typeof body.on === "function") {
6829
+ return new Promise((resolve, reject) => {
6830
+ const chunks = [];
6831
+ body.on("data", (chunk) => chunks.push(chunk));
6832
+ body.on("end", () => {
6833
+ if (chunks.length > 0 && typeof chunks[0] === "string") {
6834
+ resolve(chunks.join(""));
6835
+ } else {
6836
+ const totalLength = chunks.reduce((acc, chunk) => acc + chunk.length, 0);
6837
+ const result = new Uint8Array(totalLength);
6838
+ let offset = 0;
6839
+ for (const chunk of chunks) {
6840
+ result.set(new Uint8Array(chunk), offset);
6841
+ offset += chunk.length;
6842
+ }
6843
+ resolve(result);
6844
+ }
6845
+ });
6846
+ body.on("error", reject);
6847
+ });
6631
6848
  }
6849
+ return body;
6632
6850
  }
6851
+ function decode(data) {
6852
+ if (typeof data === "string")
6853
+ return data;
6854
+ return new TextDecoder().decode(data);
6855
+ }
6856
+ // source/core/socket/metadata.ts
6857
+ var import_reflect_metadata3 = __toESM(require_Reflect2(), 1);
6858
+ // source/framework/decorators/routable.decorator.ts
6859
+ function stabilizeRoute(meta, { path: path3, method, propertyKey }) {
6860
+ return {
6861
+ ...meta.routes.filter((route2) => route2.path === path3 && route2.method === method || route2.propertyKey === propertyKey)[0] || {},
6862
+ method,
6863
+ path: path3,
6864
+ propertyKey
6865
+ };
6866
+ }
6867
+ function createRoutableDecorator(method) {
6868
+ return (path3 = "") => (target, propertyKey) => {
6869
+ const meta = getControllerMetadata(target);
6870
+ const route2 = stabilizeRoute(meta, {
6871
+ method,
6872
+ path: path3,
6873
+ propertyKey
6874
+ });
6875
+ meta.routes.push(route2);
6876
+ };
6877
+ }
6878
+ var Get = createRoutableDecorator("GET" /* GET */);
6879
+ var Post = createRoutableDecorator("POST" /* POST */);
6880
+ var Put = createRoutableDecorator("PUT" /* PUT */);
6881
+ var Patch = createRoutableDecorator("PATCH" /* PATCH */);
6882
+ var Options = createRoutableDecorator("OPTIONS" /* OPTIONS */);
6883
+ var Trace = createRoutableDecorator("TRACE" /* TRACE */);
6884
+ var Delete = createRoutableDecorator("DELETE" /* DELETE */);
6885
+ var Head = createRoutableDecorator("HEAD" /* HEAD */);
6886
+ // source/framework/decorators/parametrable.decorator.ts
6887
+ var import_reflect_metadata4 = __toESM(require_Reflect2(), 1);
6888
+ function createRouteParametrableDecorator(type, callable) {
6889
+ return (key) => {
6890
+ return (target, propertyKey, index) => {
6891
+ const params = Reflect.getMetadata(METADATA_KEYS.ROUTE_PARAMETERS, target.constructor) || {};
6892
+ const metatypes = Reflect.getMetadata("design:paramtypes", target, propertyKey);
6893
+ const metatype = metatypes ? metatypes[index] : undefined;
6894
+ if (!params[propertyKey]) {
6895
+ params[propertyKey] = [];
6896
+ }
6897
+ params[propertyKey].push({ index, type, key, callable, metatype });
6898
+ Reflect.defineMetadata(METADATA_KEYS.ROUTE_PARAMETERS, params, target.constructor);
6899
+ };
6900
+ };
6901
+ }
6902
+ var Query = createRouteParametrableDecorator("query" /* QUERY */);
6903
+ var Param = createRouteParametrableDecorator("param" /* PARAM */);
6904
+ var Body = createRouteParametrableDecorator("body" /* BODY */);
6905
+ var UploadedFile = createRouteParametrableDecorator("upload" /* UPLOAD_FILE */);
6906
+ var Headers2 = createRouteParametrableDecorator("header" /* HEADER */);
6907
+ var Cookie = createRouteParametrableDecorator("cookie" /* COOKIE */);
6908
+ var Req = createRouteParametrableDecorator("req" /* REQ */);
6909
+ var Reply = createRouteParametrableDecorator("reply" /* REPLY */);
6910
+ // source/framework/decorators/injection.decorator.ts
6911
+ var import_reflect_metadata5 = __toESM(require_Reflect2(), 1);
6633
6912
  // source/core/guards.ts
6634
6913
  class RaitonGuards {
6635
6914
  static _map = new Map;
@@ -6666,12 +6945,16 @@ class RaitonGuards {
6666
6945
  return this;
6667
6946
  }
6668
6947
  }
6948
+ // source/framework/decorators/api-response.decorator.ts
6949
+ var import_reflect_metadata6 = __toESM(require_Reflect2(), 1);
6950
+ // source/framework/decorators/api.decorator.ts
6951
+ var import_reflect_metadata7 = __toESM(require_Reflect2(), 1);
6669
6952
  // source/core/hooks.ts
6670
6953
  class HookStore {
6671
6954
  hooks = new Map;
6672
- add(name, handler) {
6955
+ add(name, handler2) {
6673
6956
  const list = this.hooks.get(name) ?? [];
6674
- list.push(handler);
6957
+ list.push(handler2);
6675
6958
  this.hooks.set(name, list);
6676
6959
  }
6677
6960
  async run(name, ctx) {
@@ -6682,13 +6965,6 @@ class HookStore {
6682
6965
  await hook(ctx);
6683
6966
  }
6684
6967
  }
6685
- clone() {
6686
- const store = new HookStore;
6687
- for (const [key, value] of this.hooks) {
6688
- store.hooks.set(key, [...value]);
6689
- }
6690
- return store;
6691
- }
6692
6968
  }
6693
6969
 
6694
6970
  // source/core/middleware/compose.ts
@@ -6733,139 +7009,21 @@ class MiddlewarePipeline {
6733
7009
  this.stack = [];
6734
7010
  return this;
6735
7011
  }
6736
- run(ctx) {
6737
- const fn = middlewareCompose(this.stack);
7012
+ run(ctx, ...extra) {
7013
+ const fn = middlewareCompose([...this.stack, ...extra]);
6738
7014
  return typeof fn == "function" ? fn(ctx) : undefined;
6739
7015
  }
6740
- clone() {
6741
- const pipeline = new MiddlewarePipeline;
6742
- pipeline.stack = [...this.stack];
6743
- return pipeline;
6744
- }
6745
- }
6746
- // source/core/router/route.ts
6747
- class Route {
6748
- method;
6749
- path;
6750
- version;
6751
- handler;
6752
- parameters = {};
6753
- constructor(def) {
6754
- this.method = def.method;
6755
- this.path = def.path;
6756
- this.version = def.version;
6757
- this.handler = def.handler;
6758
- }
6759
- get params() {
6760
- const fullPath = this.version ? `/${this.version}${this.path}` : this.path;
6761
- const matches = fullPath.match(/:[a-zA-Z0-9_]+/g);
6762
- return matches ? matches.map((m) => m.substring(1)) : [];
6763
- }
6764
- get name() {
6765
- return this.handler.name;
6766
- }
6767
- extractParams(url) {
6768
- const fullPath = (this.version ? `/${this.version}${this.path}` : this.path).replace(/\/+$/, "");
6769
- const paramNames = this.params;
6770
- if (paramNames.length === 0)
6771
- return this;
6772
- const regexPath = fullPath.replace(/:[a-zA-Z0-9_]+/g, "([^/]+)");
6773
- const regex = new RegExp(`^${regexPath || "/"}/?$`);
6774
- const matches = url.match(regex);
6775
- if (matches) {
6776
- const params = {};
6777
- paramNames.forEach((name, index) => {
6778
- params[name] = matches[index + 1];
6779
- });
6780
- this.parameters = params;
6781
- }
6782
- return this;
6783
- }
6784
- match(method, url) {
6785
- if (method !== this.method)
6786
- return false;
6787
- const fullPath = (this.version ? `/${this.version}${this.path}` : this.path).replace(/\/+$/, "");
6788
- const cleanUrl = url.replace(/\/+$/, "");
6789
- if (!fullPath.includes(":")) {
6790
- return (fullPath || "/") === (cleanUrl || "/");
6791
- }
6792
- const regexPath = fullPath.replace(/:[a-zA-Z0-9_]+/g, "([^/]+)");
6793
- const regex = new RegExp(`^${regexPath || "/"}/?$`);
6794
- return regex.test(url);
6795
- }
6796
- }
6797
- // source/core/router/matcher.ts
6798
- class RouteMatcher {
6799
- routes = new Map;
6800
- getKey(route) {
6801
- return `${route.method}:${route.path}`;
6802
- }
6803
- add(route) {
6804
- this.routes.set(this.getKey(route), route);
6805
- return this;
6806
- }
6807
- has(route) {
6808
- return this.routes.has(this.getKey(route));
6809
- }
6810
- find(route) {
6811
- return this.routes.get(this.getKey(route));
6812
- }
6813
- replace(route) {
6814
- if (this.has(route)) {
6815
- this.routes.set(this.getKey(route), route);
6816
- }
6817
- return this;
6818
- }
6819
- upsert(route) {
6820
- this.routes.set(this.getKey(route), route);
6821
- return this;
6822
- }
6823
- remove(route) {
6824
- this.routes.delete(this.getKey(route));
6825
- return this;
6826
- }
6827
- match(method, url) {
6828
- for (const route of this.routes.values())
6829
- if (route.match(method, url))
6830
- return route.extractParams(url);
6831
- return null;
6832
- }
6833
- clear() {
6834
- this.routes.clear();
6835
- return this;
6836
- }
6837
- }
6838
- // source/core/router/router.ts
6839
- class Router {
6840
- matcher = new RouteMatcher;
6841
- add(method, path5, handler, version2) {
6842
- const route = new Route({
6843
- method,
6844
- path: path5,
6845
- handler,
6846
- version: version2
6847
- });
6848
- this.matcher.add(route);
6849
- return route;
6850
- }
6851
- remove(route) {
6852
- this.matcher.remove(route);
6853
- }
6854
- match(method, url) {
6855
- return this.matcher.match(method, url);
6856
- }
6857
- reset() {
6858
- this.matcher.clear();
6859
- }
6860
7016
  }
6861
7017
  // source/core/plugins/scope.ts
6862
7018
  class PluginScope {
6863
7019
  hooks;
6864
7020
  middleware;
6865
7021
  router;
7022
+ parent;
6866
7023
  constructor(parent) {
6867
- this.hooks = parent ? parent.hooks.clone() : new HookStore;
6868
- this.middleware = parent ? parent.middleware.clone() : new MiddlewarePipeline;
7024
+ this.parent = parent;
7025
+ this.hooks = parent ? parent.hooks : new HookStore;
7026
+ this.middleware = parent ? parent.middleware : new MiddlewarePipeline;
6869
7027
  this.router = parent ? parent.router : new Router;
6870
7028
  }
6871
7029
  addHook(name, fn) {
@@ -6880,13 +7038,20 @@ class PluginScope {
6880
7038
  this.middleware.use(mw);
6881
7039
  return this;
6882
7040
  }
6883
- route(method, path5, handler2, version2) {
6884
- return this.router.add(method, path5, handler2, version2);
7041
+ route(method, path3, handler2, version2) {
7042
+ return this.router.add(method, path3, handler2, version2);
7043
+ }
7044
+ get(path3, handler2, version2) {
7045
+ return this.route("GET" /* GET */, path3, handler2, version2);
6885
7046
  }
6886
7047
  register(plugin) {
7048
+ if (typeof plugin === "object" && plugin !== null && "setup" in plugin && typeof plugin.setup === "function" && plugin.setup.length === 1) {
7049
+ plugin.setup(this);
7050
+ return this;
7051
+ }
6887
7052
  const child = new PluginScope(this);
6888
7053
  plugin.setup(child);
6889
- return child;
7054
+ return this;
6890
7055
  }
6891
7056
  }
6892
7057
  // source/core/plugins/plugin.ts
@@ -6903,19 +7068,135 @@ var secureHeaders = definePlugin((scope2) => {
6903
7068
  await next();
6904
7069
  });
6905
7070
  }, "security-headers");
7071
+
7072
+ // source/framework/plugins/security/cors.ts
7073
+ var secureCors = (opts = {}) => {
7074
+ return async ({ context, next }) => {
7075
+ const origin = context.req.headers.get("origin");
7076
+ if (origin) {
7077
+ context.reply.header("Vary", "Origin");
7078
+ }
7079
+ let allowedOrigin = null;
7080
+ if (opts.origin === undefined || opts.origin === "*") {
7081
+ allowedOrigin = "*";
7082
+ } else if (opts.origin === true) {
7083
+ allowedOrigin = origin || "*";
7084
+ } else if (typeof opts.origin === "function") {
7085
+ if (origin && await opts.origin(origin)) {
7086
+ allowedOrigin = origin;
7087
+ }
7088
+ } else if (Array.isArray(opts.origin)) {
7089
+ if (origin && opts.origin.includes(origin)) {
7090
+ allowedOrigin = origin;
7091
+ }
7092
+ } else if (typeof opts.origin === "string") {
7093
+ if (opts.origin === origin) {
7094
+ allowedOrigin = origin;
7095
+ } else if (opts.origin === "*") {
7096
+ allowedOrigin = "*";
7097
+ }
7098
+ }
7099
+ if (allowedOrigin) {
7100
+ context.reply.header("Access-Control-Allow-Origin", allowedOrigin);
7101
+ }
7102
+ if (opts.credentials) {
7103
+ context.reply.header("Access-Control-Allow-Credentials", "true");
7104
+ }
7105
+ if (opts.exposeHeaders) {
7106
+ context.reply.header("Access-Control-Expose-Headers", opts.exposeHeaders.join(","));
7107
+ }
7108
+ if (context.req.method === "OPTIONS") {
7109
+ context.reply.header("Access-Control-Allow-Methods", (opts.methods ?? ["GET", "POST", "PUT", "DELETE", "PATCH"]).join(","));
7110
+ context.reply.header("Access-Control-Allow-Headers", (opts.headers ?? ["Content-Type", "Authorization", "X-Requested-With"]).join(","));
7111
+ if (opts.maxAge) {
7112
+ context.reply.header("Access-Control-Max-Age", opts.maxAge.toString());
7113
+ }
7114
+ context.reply.status(204);
7115
+ return context.send(null);
7116
+ }
7117
+ await next();
7118
+ };
7119
+ };
7120
+
7121
+ // source/framework/plugins/security/rate-limit.ts
7122
+ var secureRateLimit = (opts = {}) => definePlugin((scope2) => {
7123
+ const hits = new Map;
7124
+ const windowMs = opts.windowMs ?? 60000;
7125
+ const max = opts.max ?? 100;
7126
+ scope2.use(async ({ context, next }) => {
7127
+ const ip = context.req.remoteAddress ?? "unknown";
7128
+ const now = Date.now();
7129
+ const entry = hits.get(ip) ?? { count: 0, ts: now };
7130
+ if (now - entry.ts > windowMs) {
7131
+ entry.count = 0;
7132
+ entry.ts = now;
7133
+ }
7134
+ entry.count++;
7135
+ hits.set(ip, entry);
7136
+ if (entry.count > max) {
7137
+ context.reply.status(429);
7138
+ return context.send({ error: "Too many requests" });
7139
+ }
7140
+ await next();
7141
+ });
7142
+ }, "rate-limit");
7143
+
7144
+ // source/framework/plugins/security/body-limit.ts
7145
+ var secureBodyLimit = (maxBytes = 1e6) => definePlugin((scope2) => {
7146
+ scope2.use(async ({ context, next }) => {
7147
+ const len = Number(context.req.headers.get("content-length") ?? 0);
7148
+ if (len > maxBytes) {
7149
+ context.reply.status(413);
7150
+ return context.send({ error: "Payload too large" });
7151
+ }
7152
+ await next();
7153
+ });
7154
+ }, "body-limit");
7155
+
7156
+ // source/framework/plugins/security/method-guard.ts
7157
+ var secureMethodGuard = (allowed) => definePlugin((scope2) => {
7158
+ scope2.use(async ({ context, next }) => {
7159
+ if (!allowed.includes(context.req.method)) {
7160
+ context.reply.status(405);
7161
+ return context.send({ error: "Method not allowed" });
7162
+ }
7163
+ await next();
7164
+ });
7165
+ }, "method-guard");
7166
+
7167
+ // source/framework/plugins/security/index.ts
7168
+ class Security {
7169
+ static headers = secureHeaders;
7170
+ static cors = secureCors;
7171
+ static rateLimit = secureRateLimit;
7172
+ static bodyLimit = secureBodyLimit;
7173
+ static methodGuard = secureMethodGuard;
7174
+ }
6906
7175
  // source/framework/encryption.ts
6907
7176
  var import_argon2 = __toESM(require_argon2(), 1);
6908
7177
  var import_bcrypt = __toESM(require_bcrypt(), 1);
6909
- // source/core/controller/metadata.ts
6910
- var import_reflect_metadata5 = __toESM(require_Reflect2(), 1);
6911
- function getControllerMetadata(target) {
6912
- let metadata2 = Reflect.getMetadata(METADATA_KEYS.CONTROLLERS, target);
6913
- if (!metadata2) {
6914
- metadata2 = { routes: [], middlewares: {} };
6915
- Reflect.defineMetadata(METADATA_KEYS.CONTROLLERS, metadata2, target);
7178
+ // source/core/directories.ts
7179
+ import path4 from "node:path";
7180
+ class RaitonDirectories {
7181
+ static index = `.${Raiton.identifier}`;
7182
+ static bootstrapFile = "main.ts";
7183
+ static caches(workdir) {
7184
+ return path4.join(workdir, this.index, "caches");
7185
+ }
7186
+ static artifacts(workdir) {
7187
+ return path4.join(workdir, this.index, "artifacts");
7188
+ }
7189
+ static server(workdir) {
7190
+ return path4.join(workdir, this.index, "server");
7191
+ }
7192
+ static root(workdir) {
7193
+ return path4.join(workdir, this.index);
7194
+ }
7195
+ static app() {
7196
+ return path4.join(Raiton.thread?.builder.workdir || "", RaitonConfig.get("rootDir") || "./");
6916
7197
  }
6917
- return metadata2;
6918
7198
  }
7199
+
6919
7200
  // source/framework/artifacts.ts
6920
7201
  class Artifacts {
6921
7202
  static types = new Set;
@@ -6923,6 +7204,7 @@ class Artifacts {
6923
7204
  "service",
6924
7205
  "provider",
6925
7206
  "type",
7207
+ "interface",
6926
7208
  "repository",
6927
7209
  "database",
6928
7210
  "db",
@@ -6938,7 +7220,12 @@ class Artifacts {
6938
7220
  "validator",
6939
7221
  "strategy",
6940
7222
  "strategy-provider",
6941
- "strategy-type"
7223
+ "strategy-type",
7224
+ "use-case",
7225
+ "dto",
7226
+ "entity",
7227
+ "model",
7228
+ "schema"
6942
7229
  ];
6943
7230
  static register(type) {
6944
7231
  this.types.add(type);
@@ -6953,7 +7240,7 @@ class Artifacts {
6953
7240
  return [...this.types].map((type) => isArtifact(filename, type)).some(Boolean);
6954
7241
  }
6955
7242
  static reload(modulo, filename) {
6956
- if (Raiton.thread?.builder.options.development === false)
7243
+ if (Raiton.thread?.builder.options.serve === false)
6957
7244
  return Logger.warn("Artifact reload is only available in development mode");
6958
7245
  for (const mod of Object.values(modulo)) {
6959
7246
  const name = mod && typeof mod === "object" && "name" in mod ? mod.name : typeof mod === "function" ? mod.name ?? mod.constructor.name : undefined;
@@ -7066,7 +7353,9 @@ class Application {
7066
7353
  config;
7067
7354
  root;
7068
7355
  version = RaitonConfig.get("version") || "0.0.1";
7069
- container = Injection;
7356
+ static get container() {
7357
+ return Injection;
7358
+ }
7070
7359
  constructor(config2) {
7071
7360
  this.config = config2;
7072
7361
  this.root = new PluginScope;
@@ -7079,6 +7368,8 @@ class Application {
7079
7368
  const artifacts = RaitonConfig.get("artifacts");
7080
7369
  const artifactTypes = [...artifacts?.types || [], ...Artifacts.defaultTypes];
7081
7370
  Artifacts.registerMany(...artifactTypes);
7371
+ this.register(Security.headers);
7372
+ this.register(bodyParserPlugin());
7082
7373
  return this;
7083
7374
  }
7084
7375
  get hostname() {
@@ -7136,32 +7427,34 @@ class Application {
7136
7427
  Logger.info(`Incoming request: ${req.method} ${req.url}`);
7137
7428
  }
7138
7429
  await this.root.hooks.run("onRequest", ctx);
7139
- const url = new URL(req.url, this.hostname);
7140
- let pathname = url.pathname;
7141
- if (this.config.pathname && this.config.pathname !== "/") {
7142
- const appPathname = this.config.pathname.endsWith("/") ? this.config.pathname : `${this.config.pathname}/`;
7143
- if (pathname.startsWith(appPathname)) {
7144
- pathname = pathname.substring(appPathname.length - 1) || "/";
7145
- } else if (pathname === this.config.pathname) {
7146
- pathname = "/";
7147
- } else {
7148
- if (this.config.verbose) {
7149
- Logger.warn(`Request out of application pathname: ${pathname} (expected prefix: ${this.config.pathname})`);
7430
+ const handler2 = async (param) => {
7431
+ const context = param.context ?? param;
7432
+ const req2 = context.req;
7433
+ const reply2 = context.reply;
7434
+ const url = new URL(req2.url, this.hostname);
7435
+ let pathname = url.pathname;
7436
+ if (this.config.pathname && this.config.pathname !== "/") {
7437
+ const appPathname = this.config.pathname.endsWith("/") ? this.config.pathname : `${this.config.pathname}/`;
7438
+ if (pathname.startsWith(appPathname)) {
7439
+ pathname = pathname.substring(appPathname.length - 1) || "/";
7440
+ } else if (pathname === this.config.pathname) {
7441
+ pathname = "/";
7442
+ } else {
7443
+ if (this.config.verbose) {
7444
+ Logger.warn(`Request out of application pathname: ${pathname} (expected prefix: ${this.config.pathname})`);
7445
+ }
7446
+ reply2.status(404);
7447
+ return reply2.send({ error: false, statusCode: 404 });
7150
7448
  }
7151
- reply.status(404);
7152
- return reply.send({ error: false, statusCode: 404 });
7153
7449
  }
7154
- }
7155
- const route2 = this.root.router.match(req.method, pathname);
7156
- if (!route2) {
7157
- if (this.config.verbose) {
7158
- Logger.warn(`Route not found: ${req.method} ${pathname}`);
7450
+ const route2 = this.root.router.match(req2.method, pathname);
7451
+ if (!route2) {
7452
+ if (this.config.verbose) {
7453
+ Logger.warn(`Route not found: ${req2.method} ${pathname}`);
7454
+ }
7455
+ reply2.status(404);
7456
+ return reply2.send({ error: false, statusCode: 404 });
7159
7457
  }
7160
- reply.status(404);
7161
- return reply.send({ error: false, statusCode: 404 });
7162
- }
7163
- const pipeline2 = this.root.middleware.clone();
7164
- pipeline2.use(async ({ context }) => {
7165
7458
  try {
7166
7459
  context.params = route2.parameters;
7167
7460
  let responses2 = await route2.handler(context);
@@ -7172,8 +7465,8 @@ class Application {
7172
7465
  console.error(e);
7173
7466
  }
7174
7467
  }
7175
- });
7176
- await pipeline2.run(ctx);
7468
+ };
7469
+ await this.root.middleware.run(ctx, handler2);
7177
7470
  await this.root.hooks.run("onResponse", ctx);
7178
7471
  }
7179
7472
  }