raiton 6.1.0-beta.4 → 6.3.0-beta.10

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.
@@ -21,12 +21,14 @@ var __toESM = (mod, isNodeMode, target) => {
21
21
  }
22
22
  target = mod != null ? __create(__getProtoOf(mod)) : {};
23
23
  const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
24
- for (let key of __getOwnPropNames(mod))
25
- if (!__hasOwnProp.call(to, key))
26
- __defProp(to, key, {
27
- get: __accessProp.bind(mod, key),
28
- enumerable: true
29
- });
24
+ if (mod && typeof mod === "object" || typeof mod === "function") {
25
+ for (let key of __getOwnPropNames(mod))
26
+ if (!__hasOwnProp.call(to, key))
27
+ __defProp(to, key, {
28
+ get: __accessProp.bind(mod, key),
29
+ enumerable: true
30
+ });
31
+ }
30
32
  if (canCache)
31
33
  cache.set(mod, to);
32
34
  return to;
@@ -35,7 +37,7 @@ var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports,
35
37
  var __require = /* @__PURE__ */ createRequire(import.meta.url);
36
38
 
37
39
  // node_modules/reflect-metadata/Reflect.js
38
- var require_Reflect = __commonJS(() => {
40
+ var require_Reflect = __commonJS(function() {
39
41
  /*! *****************************************************************************
40
42
  Copyright (C) Microsoft. All rights reserved.
41
43
  Licensed under the Apache License, Version 2.0 (the "License"); you may not use
@@ -1031,7 +1033,7 @@ var require_Reflect = __commonJS(() => {
1031
1033
  });
1032
1034
 
1033
1035
  // node_modules/commander/lib/error.js
1034
- var require_error = __commonJS((exports) => {
1036
+ var require_error = __commonJS(function(exports) {
1035
1037
  class CommanderError extends Error {
1036
1038
  constructor(exitCode, code, message) {
1037
1039
  super(message);
@@ -1055,7 +1057,7 @@ var require_error = __commonJS((exports) => {
1055
1057
  });
1056
1058
 
1057
1059
  // node_modules/commander/lib/argument.js
1058
- var require_argument = __commonJS((exports) => {
1060
+ var require_argument = __commonJS(function(exports) {
1059
1061
  var { InvalidArgumentError } = require_error();
1060
1062
 
1061
1063
  class Argument {
@@ -1135,7 +1137,7 @@ var require_argument = __commonJS((exports) => {
1135
1137
  });
1136
1138
 
1137
1139
  // node_modules/commander/lib/help.js
1138
- var require_help = __commonJS((exports) => {
1140
+ var require_help = __commonJS(function(exports) {
1139
1141
  var { humanReadableArgName } = require_argument();
1140
1142
 
1141
1143
  class Help {
@@ -1492,7 +1494,7 @@ ${itemIndentStr}`);
1492
1494
  });
1493
1495
 
1494
1496
  // node_modules/commander/lib/option.js
1495
- var require_option = __commonJS((exports) => {
1497
+ var require_option = __commonJS(function(exports) {
1496
1498
  var { InvalidArgumentError } = require_error();
1497
1499
 
1498
1500
  class Option {
@@ -1676,7 +1678,7 @@ var require_option = __commonJS((exports) => {
1676
1678
  });
1677
1679
 
1678
1680
  // node_modules/commander/lib/suggestSimilar.js
1679
- var require_suggestSimilar = __commonJS((exports) => {
1681
+ var require_suggestSimilar = __commonJS(function(exports) {
1680
1682
  var maxDistance = 3;
1681
1683
  function editDistance(a, b) {
1682
1684
  if (Math.abs(a.length - b.length) > maxDistance)
@@ -1749,7 +1751,7 @@ var require_suggestSimilar = __commonJS((exports) => {
1749
1751
  });
1750
1752
 
1751
1753
  // node_modules/commander/lib/command.js
1752
- var require_command = __commonJS((exports) => {
1754
+ var require_command = __commonJS(function(exports) {
1753
1755
  var EventEmitter = __require("node:events").EventEmitter;
1754
1756
  var childProcess = __require("node:child_process");
1755
1757
  var path = __require("node:path");
@@ -3104,7 +3106,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
3104
3106
  });
3105
3107
 
3106
3108
  // node_modules/commander/index.js
3107
- var require_commander = __commonJS((exports) => {
3109
+ var require_commander = __commonJS(function(exports) {
3108
3110
  var { Argument } = require_argument();
3109
3111
  var { Command } = require_command();
3110
3112
  var { CommanderError, InvalidArgumentError } = require_error();
@@ -3124,7 +3126,7 @@ var require_commander = __commonJS((exports) => {
3124
3126
  });
3125
3127
 
3126
3128
  // node_modules/reflect-metadata/Reflect.js
3127
- var require_Reflect2 = __commonJS(() => {
3129
+ var require_Reflect2 = __commonJS(function() {
3128
3130
  /*! *****************************************************************************
3129
3131
  Copyright (C) Microsoft. All rights reserved.
3130
3132
  Licensed under the Apache License, Version 2.0 (the "License"); you may not use
@@ -4120,7 +4122,7 @@ var require_Reflect2 = __commonJS(() => {
4120
4122
  });
4121
4123
 
4122
4124
  // node_modules/@phc/format/index.js
4123
- var require_format = __commonJS((exports, module) => {
4125
+ var require_format = __commonJS(function(exports, module) {
4124
4126
  var idRegex = /^[a-z0-9-]{1,32}$/;
4125
4127
  var nameRegex = /^[a-z0-9-]{1,32}$/;
4126
4128
  var valueRegex = /^[a-zA-Z0-9/+.-]+$/;
@@ -4277,7 +4279,7 @@ var require_format = __commonJS((exports, module) => {
4277
4279
  });
4278
4280
 
4279
4281
  // node_modules/node-gyp-build/node-gyp-build.js
4280
- var require_node_gyp_build = __commonJS((exports, module) => {
4282
+ var require_node_gyp_build = __commonJS(function(exports, module) {
4281
4283
  var fs2 = __require("fs");
4282
4284
  var path3 = __require("path");
4283
4285
  var os = __require("os");
@@ -4466,7 +4468,7 @@ var require_node_gyp_build = __commonJS((exports, module) => {
4466
4468
  });
4467
4469
 
4468
4470
  // node_modules/node-gyp-build/index.js
4469
- var require_node_gyp_build2 = __commonJS((exports, module) => {
4471
+ var require_node_gyp_build2 = __commonJS(function(exports, module) {
4470
4472
  var runtimeRequire = typeof __webpack_require__ === "function" ? __non_webpack_require__ : __require;
4471
4473
  if (typeof runtimeRequire.addon === "function") {
4472
4474
  module.exports = runtimeRequire.addon.bind(runtimeRequire);
@@ -4476,7 +4478,7 @@ var require_node_gyp_build2 = __commonJS((exports, module) => {
4476
4478
  });
4477
4479
 
4478
4480
  // node_modules/argon2/argon2.cjs
4479
- var require_argon2 = __commonJS((exports, module) => {
4481
+ var require_argon2 = __commonJS(function(exports, module) {
4480
4482
  var __dirname = "/home/runner/work/raiton/raiton/node_modules/argon2";
4481
4483
  var { randomBytes, timingSafeEqual } = __require("node:crypto");
4482
4484
  var { promisify } = __require("node:util");
@@ -4594,7 +4596,7 @@ var require_argon2 = __commonJS((exports, module) => {
4594
4596
  });
4595
4597
 
4596
4598
  // node_modules/bcrypt/promises.js
4597
- var require_promises = __commonJS((exports, module) => {
4599
+ var require_promises = __commonJS(function(exports, module) {
4598
4600
  var Promise2 = global.Promise;
4599
4601
  function promise(fn, context, args) {
4600
4602
  if (!Array.isArray(args)) {
@@ -4628,7 +4630,7 @@ var require_promises = __commonJS((exports, module) => {
4628
4630
  });
4629
4631
 
4630
4632
  // node_modules/bcrypt/bcrypt.js
4631
- var require_bcrypt = __commonJS((exports, module) => {
4633
+ var require_bcrypt = __commonJS(function(exports, module) {
4632
4634
  var __dirname = "/home/runner/work/raiton/raiton/node_modules/bcrypt";
4633
4635
  var path3 = __require("path");
4634
4636
  var bindings = require_node_gyp_build2()(path3.resolve(__dirname));
@@ -4817,7 +4819,7 @@ var {
4817
4819
  Help
4818
4820
  } = import__.default;
4819
4821
  // package.json
4820
- var version = "6.1.0-beta.4";
4822
+ var version = "6.3.0-beta.10";
4821
4823
 
4822
4824
  // source/bin/cli.ts
4823
4825
  var CLI = new Command;
@@ -5427,304 +5429,11 @@ var Environment;
5427
5429
  Environment2.iOS = Platform === "iOS" || globalThis.navigator?.platform === "MacIntel" && globalThis.navigator?.maxTouchPoints > 1 || /iPad|iPhone|iPod/.test(globalThis.navigator?.platform);
5428
5430
  Environment2.Android = Platform === "Android" || globalThis.navigator?.platform === "Android" || globalThis.navigator?.userAgent?.includes(" Android ") || globalThis.process?.platform === "android";
5429
5431
  })(Environment || (Environment = {}));
5430
- var EventDispatcher = class {
5431
- propagations = {};
5432
- entries = {};
5433
- listen(type, callback, force) {
5434
- this.entries[type] = this.entries[type] || [];
5435
- this.entries[type].push({ callback, force });
5436
- this.propagations[type] = false;
5437
- return this;
5438
- }
5439
- dispatch(type, data) {
5440
- if (this.entries[type]) {
5441
- this.entries[type].map((entry) => {
5442
- if (this.propagations[type] === true) {
5443
- return;
5444
- }
5445
- const stop = entry.callback(data);
5446
- if (stop === true) {
5447
- this.propagations[type] = true;
5448
- }
5449
- });
5450
- this.propagations[type] = false;
5451
- }
5452
- return this;
5453
- }
5454
- };
5455
5432
  var paramsObject = UrlUtility.paramsObject;
5456
5433
  var update = ObjectUtility.update;
5457
5434
  var ascendingPath = HtmlUtility.ascendingPath;
5458
5435
  var urlParams = UrlUtility.urlParams;
5459
- var Navigation = class {
5460
- options = {};
5461
- emitter = new EventDispatcher;
5462
- #oldRoute;
5463
- constructor() {
5464
- this.options.middlewares = this.options.middlewares || [];
5465
- }
5466
- currentRouteName() {
5467
- return (this.options.useHashtagParser ? (location.hash || "").split("?")[0] : location.pathname).substring(1);
5468
- }
5469
- oldRouteName() {
5470
- return this.#oldRoute;
5471
- }
5472
- currentQuery() {
5473
- if (this.options.useHashtagParser) {
5474
- return paramsObject((location.hash || location.search || "").split("?")[1] || "");
5475
- } else {
5476
- return paramsObject(location.search);
5477
- }
5478
- }
5479
- setOption(optionName, value) {
5480
- this.options[optionName] = value;
5481
- return this;
5482
- }
5483
- setOptions(options) {
5484
- this.options = update(this.options, options);
5485
- this.emitter.dispatch("options", this);
5486
- return this;
5487
- }
5488
- middleware(middleware) {
5489
- this.options.middlewares?.push(middleware);
5490
- return this;
5491
- }
5492
- observe() {
5493
- window.addEventListener("popstate", (ev) => this.dispatchNavigate(ev));
5494
- this.capturesActions();
5495
- return this;
5496
- }
5497
- capturesActions() {
5498
- if (this.options.capture) {
5499
- document.body.addEventListener("click", (ev) => {
5500
- const target = this.parseElementCaptured(ev);
5501
- if (target && !target.hasAttribute("navigate:no-detection")) {
5502
- const url = target.getAttribute("href") || target.getAttribute("navigate:view") || target.getAttribute("navigate-view");
5503
- const blank = (target.getAttribute("target") || "").toLowerCase() == "_blank";
5504
- const external = url ? this.isExternalURL(url) : false;
5505
- if (url && !blank && !external) {
5506
- ev.preventDefault();
5507
- this.navigate(this.parseRouteName(url), {}, ev);
5508
- }
5509
- }
5510
- }, false);
5511
- }
5512
- return this;
5513
- }
5514
- parseRouteName(routeName) {
5515
- const route = routeName.trim();
5516
- const firstChar = route.substring(0, 1);
5517
- return firstChar == "/" || firstChar == "#" ? route.substring(1) : route;
5518
- }
5519
- isExternalURL(url) {
5520
- return !!(url.match(/^http/gi) || url.match(/^\/\//gi));
5521
- }
5522
- parseElementCaptured(ev) {
5523
- if (ev.target instanceof HTMLElement) {
5524
- if (ev.target.hasAttribute("navigate:view") || ev.target.tagName == "A") {
5525
- return ev.target;
5526
- } else {
5527
- return ascendingPath(ev.target, (parent) => parent.tagName == "A" || parent.hasAttribute("navigate:view"));
5528
- }
5529
- }
5530
- return;
5531
- }
5532
- dispatchNavigate(ev) {
5533
- const routeName = this.currentRouteName();
5534
- const parser = this.options.useHashtagParser ? "hashtag" : "directory";
5535
- this.options.middlewares?.forEach((middleware) => middleware({
5536
- navigation: this,
5537
- event: ev,
5538
- routeName: this.currentRouteName(),
5539
- props: this.currentQuery() || undefined,
5540
- parser: this.options.useHashtagParser ? "hashtag" : "directory"
5541
- }));
5542
- this.emitter.dispatch("navigate", {
5543
- navigation: this,
5544
- routeName,
5545
- parser
5546
- });
5547
- this.#oldRoute = routeName;
5548
- return this;
5549
- }
5550
- navigate(route, props, ev) {
5551
- if (!route) {
5552
- return this;
5553
- }
5554
- const currentRoute = this.currentRouteName();
5555
- const routeName = route;
5556
- const hasProps = Object.keys(props || {}).length;
5557
- const query = hasProps ? `?${urlParams(props || {})}` : "";
5558
- if (currentRoute != routeName) {
5559
- if (this.options.useHashtagParser) {
5560
- location.hash = `${routeName}${query}`;
5561
- } else {
5562
- history.pushState(props || {}, document.title, `${routeName}${query}`);
5563
- this.dispatchNavigate(ev || undefined);
5564
- }
5565
- } else {
5566
- this.dispatchNavigate(ev || undefined);
5567
- }
5568
- return this;
5569
- }
5570
- };
5571
- var MetricRandom = class {
5572
- static ALPHA_NUMERIC = "a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9";
5573
- static ALPHA_NUMERIC_LOWER = "a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9";
5574
- static ALPHA_NUMERIC_UPPER = "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9";
5575
- static ALPHA_UPPER = "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z";
5576
- static ALPHA_LOWER = "a b c d e f g h i j k l m n o p q r s t u v w x y z";
5577
- static HEX_UPPER = "A B C D E F 0 1 2 3 4 5 6 7 8 9";
5578
- static HEX_LOWER = "a b c d e f 0 1 2 3 4 5 6 7 8 9";
5579
- static NUMERIC = "0 1 2 3 4 5 6 7 8 9";
5580
- static CreateRandom(min, max) {
5581
- return Math.floor(Math.random() * (max - min) + min);
5582
- }
5583
- static CreateBlock(base, length) {
5584
- let based, out = [];
5585
- based = base.split(" ");
5586
- if (Array.isArray(based)) {
5587
- for (let x = 0;x < length; x++) {
5588
- const k = this.CreateRandom(0, based.length - 1);
5589
- out[out.length] = based[k];
5590
- }
5591
- }
5592
- return out;
5593
- }
5594
- static CreateAlpha(length) {
5595
- return this.CreateBlock(`${this.ALPHA_LOWER} ${this.ALPHA_UPPER}`, length);
5596
- }
5597
- static CreateHEX(length) {
5598
- return this.CreateBlock(`${this.HEX_UPPER} ${this.HEX_LOWER}`, length);
5599
- }
5600
- static CreateNumeric(length) {
5601
- return this.CreateBlock(`${this.NUMERIC}`, length);
5602
- }
5603
- static Create(length) {
5604
- return this.CreateBlock(`${this.ALPHA_NUMERIC}`, length);
5605
- }
5606
- };
5607
5436
  var unCamelCase = TextUtility.unCamelCase;
5608
- function CoreAppearanceProps(name, value) {
5609
- const keys = [];
5610
- const parsed = {};
5611
- switch (name) {
5612
- case "paddingVertical":
5613
- keys.push("paddingTop");
5614
- keys.push("paddingBottom");
5615
- break;
5616
- case "paddingHorizontal":
5617
- keys.push("paddingLeft");
5618
- keys.push("paddingRight");
5619
- break;
5620
- case "marginVertical":
5621
- keys.push("marginTop");
5622
- keys.push("marginBottom");
5623
- break;
5624
- case "marginHorizontal":
5625
- keys.push("marginLeft");
5626
- keys.push("marginRight");
5627
- break;
5628
- default:
5629
- keys.push(name);
5630
- break;
5631
- }
5632
- keys.forEach((key) => {
5633
- parsed[unCamelCase(key)] = CoreAppearanceValues(value);
5634
- });
5635
- return parsed;
5636
- }
5637
- function CoreAppearanceValues(value) {
5638
- if (typeof value == "number") {
5639
- return `${value}`;
5640
- }
5641
- return value;
5642
- }
5643
- var CoreAppearance = class {
5644
- instance;
5645
- uid;
5646
- emitter = new EventDispatcher;
5647
- properties = {};
5648
- constructor() {
5649
- this.instance = document.createElement("style");
5650
- this.uid = `${MetricRandom.CreateAlpha(4).join("")}-${MetricRandom.Create(12).join("")}`;
5651
- }
5652
- sheet(stylesheet) {
5653
- const styleSheet = [];
5654
- Object.entries(stylesheet).forEach(({ 0: name, 1: props }) => {
5655
- const properties = {};
5656
- const selector = name.includes("&") ? name.replace(new RegExp("&", "g"), `.${this.uid}`) : `.${this.uid} ${name}`;
5657
- const data = this.insertProperties(properties, props);
5658
- styleSheet[styleSheet.length] = `${selector}{ ${ObjectUtility.toString(data, { joiner: "; " })} }`;
5659
- });
5660
- this.instance.innerHTML = styleSheet.join(" ");
5661
- this.mountImmediat();
5662
- return this;
5663
- }
5664
- inject(code) {
5665
- this.instance.innerHTML = typeof code != "string" ? code.join(" ") : code;
5666
- this.mountImmediat();
5667
- return this;
5668
- }
5669
- insertProperties(properties, data) {
5670
- Object.entries(data).forEach(({ 0: name, 1: value }) => {
5671
- Object.entries(CoreAppearanceProps(name, value)).forEach(({ 0: key, 1: data2 }) => properties[key] = data2);
5672
- });
5673
- this.emitter.dispatch("insertProperties", properties);
5674
- return properties;
5675
- }
5676
- removeProperties(properties, payload) {
5677
- Object.values(payload).forEach((name) => {
5678
- Object.entries(CoreAppearanceProps(name, undefined)).forEach(({ 0: key }) => properties[key] = undefined);
5679
- });
5680
- this.emitter.dispatch("removeProperties", properties);
5681
- return properties;
5682
- }
5683
- set(properties) {
5684
- this.insertProperties(this.properties, properties);
5685
- this.emitter.dispatch("set", properties);
5686
- return this.sync();
5687
- }
5688
- unset(properties) {
5689
- this.removeProperties(this.properties, properties);
5690
- this.emitter.dispatch("unset", properties);
5691
- return this.sync();
5692
- }
5693
- mount() {
5694
- const length = Object.values(this.properties).length;
5695
- if (!this.instance.isConnected && length) {
5696
- this.mountImmediat();
5697
- }
5698
- return this;
5699
- }
5700
- mountImmediat() {
5701
- let head = document.querySelector("head");
5702
- if (!head) {
5703
- head = document.createElement("head");
5704
- document.documentElement.append(head);
5705
- }
5706
- head.append(this.instance);
5707
- this.emitter.dispatch("mount", this);
5708
- return this;
5709
- }
5710
- destroy() {
5711
- this.instance.remove();
5712
- this.emitter.dispatch("destroy", undefined);
5713
- return this;
5714
- }
5715
- sync() {
5716
- const rendering = [];
5717
- Object.entries(this.properties).forEach(({ 0: name, 1: value }) => {
5718
- if (typeof value == "string" || typeof value == "number") {
5719
- rendering[rendering.length] = `${unCamelCase(name)} : ${value}`;
5720
- }
5721
- });
5722
- this.instance.innerHTML = `.${this.uid}{ ${rendering.join(";")} }`;
5723
- this.emitter.dispatch("sync", this);
5724
- this.mount();
5725
- return this;
5726
- }
5727
- };
5728
5437
  var Signal;
5729
5438
  ((Signal2) => {
5730
5439
 
@@ -6220,14 +5929,6 @@ function isArtifact(filename, artifact) {
6220
5929
  filename.endsWith(`.${artifact}.cjs`)
6221
5930
  ].some(Boolean);
6222
5931
  }
6223
- // source/framework/utilities/json.util.ts
6224
- function tryParseJson(obj) {
6225
- try {
6226
- return JSON.parse(obj);
6227
- } catch (e) {
6228
- return null;
6229
- }
6230
- }
6231
5932
  // source/framework/utilities/path.util.ts
6232
5933
  import path2 from "node:path";
6233
5934
  import { fileURLToPath } from "node:url";
@@ -6261,107 +5962,6 @@ var METADATA_KEYS = {
6261
5962
  API_PROPERTY: Symbol("api:property"),
6262
5963
  ROUTE_INTERACTION: Symbol("route:interaction")
6263
5964
  };
6264
- // source/framework/responses/http.ts
6265
- class HttpResponse {
6266
- response;
6267
- static push(response) {
6268
- throw new ThrowableResponse({
6269
- statusCode: response.statusCode || 400 /* BAD_REQUEST */,
6270
- message: response.message || "No response message provided",
6271
- data: response.data,
6272
- error: response.error,
6273
- errorStack: response.errorStack
6274
- });
6275
- }
6276
- constructor(response) {
6277
- this.response = response;
6278
- }
6279
- status(statusCode) {
6280
- this.response.statusCode = statusCode;
6281
- return this;
6282
- }
6283
- message(message) {
6284
- this.response.message = message;
6285
- return this;
6286
- }
6287
- data(data) {
6288
- this.response.data = data;
6289
- return this;
6290
- }
6291
- error(error) {
6292
- this.response.error = error;
6293
- return this;
6294
- }
6295
- stack(stack) {
6296
- this.response.errorStack = stack;
6297
- return this;
6298
- }
6299
- render() {
6300
- return new ThrowableResponse({ ...this.response }).render();
6301
- }
6302
- }
6303
-
6304
- // source/framework/responses/error.ts
6305
- class HttpErrorResponse {
6306
- stack = new Map;
6307
- get entries() {
6308
- return [...this.stack.values()];
6309
- }
6310
- add(input) {
6311
- this.stack.set(input.id, input);
6312
- return this;
6313
- }
6314
- remove(id) {
6315
- this.stack.delete(id);
6316
- return this;
6317
- }
6318
- get(id) {
6319
- return this.stack.get(id);
6320
- }
6321
- has(id) {
6322
- return this.stack.has(id);
6323
- }
6324
- clear() {
6325
- this.stack.clear();
6326
- return this;
6327
- }
6328
- get empty() {
6329
- return this.stack.size === 0;
6330
- }
6331
- get existence() {
6332
- return this.stack.size;
6333
- }
6334
- push() {
6335
- const first = this.stack.values().next().value;
6336
- HttpResponse.push({
6337
- statusCode: 500,
6338
- message: first?.message || "Internal server error",
6339
- error: true,
6340
- errorStack: this.entries
6341
- });
6342
- }
6343
- }
6344
- // source/framework/responses/http-throwable.ts
6345
- class ThrowableResponse extends Error {
6346
- input;
6347
- statusCode;
6348
- constructor(input, statusCode = 500 /* INTERNAL_SERVER_ERROR */) {
6349
- super(typeof input === "string" ? input : input.message);
6350
- this.input = input;
6351
- this.statusCode = statusCode;
6352
- }
6353
- render() {
6354
- const stack = typeof this.input === "object" ? this.input.errorStack : undefined;
6355
- return {
6356
- message: this.message,
6357
- statusCode: this.statusCode,
6358
- data: typeof this.input === "object" ? this.input.data : undefined,
6359
- error: typeof this.input === "object" ? this.input.error : false,
6360
- stack: stack instanceof Error ? Raiton.thread?.builder?.options?.serve ? this.stack?.split(`
6361
- `).map((e) => e.trim()) : undefined : stack
6362
- };
6363
- }
6364
- }
6365
5965
  // source/core/controller/metadata.ts
6366
5966
  var import_reflect_metadata = __toESM(require_Reflect2(), 1);
6367
5967
  function getControllerMetadata(target) {
@@ -6372,162 +5972,6 @@ function getControllerMetadata(target) {
6372
5972
  }
6373
5973
  return metadata;
6374
5974
  }
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({
6475
- method,
6476
- path: path3,
6477
- handler,
6478
- version: version2
6479
- });
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
- }
6495
- }
6496
- // source/framework/exceptions/http-exception.ts
6497
- class HttpException extends Error {
6498
- statusCode;
6499
- errorCode;
6500
- constructor(error2, statusCode = 500 /* INTERNAL_SERVER_ERROR */, errorCode = undefined) {
6501
- super(typeof error2 === "string" ? error2 : error2.message);
6502
- this.statusCode = statusCode;
6503
- this.errorCode = errorCode;
6504
- }
6505
- setStatus(statusCode) {
6506
- this.statusCode = statusCode;
6507
- return this;
6508
- }
6509
- setErrorCode(code) {
6510
- this.errorCode = code;
6511
- return this;
6512
- }
6513
- setMessage(error2) {
6514
- this.message = typeof error2 === "string" ? error2 : error2.message;
6515
- return this;
6516
- }
6517
- render() {
6518
- return {
6519
- message: this.message,
6520
- statusCode: this.statusCode,
6521
- errorCode: this.errorCode,
6522
- error: true,
6523
- stack: Raiton.thread?.builder?.options?.serve ? this.stack?.split(`
6524
- `).map((e) => e.trim()) : undefined
6525
- };
6526
- }
6527
- toString() {
6528
- return `HttpException: ${this.message} with status code ${this.statusCode}`;
6529
- }
6530
- }
6531
5975
  // source/framework/exceptions/throwable.ts
6532
5976
  class Throwable extends Error {
6533
5977
  statusCode;
@@ -6576,7 +6020,7 @@ class Injection {
6576
6020
  return this._classes.has(this.normalizeName(name));
6577
6021
  }
6578
6022
  static clear() {
6579
- Logger.error("Clearing injection container");
6023
+ Logger.info("Clearing injection container");
6580
6024
  this._classes.clear();
6581
6025
  this._instances.clear();
6582
6026
  this._dependents.clear();
@@ -6764,158 +6208,6 @@ var controllerRouteMap = new Map;
6764
6208
  // source/core/socket/metadata.ts
6765
6209
  var import_reflect_metadata3 = __toESM(require_Reflect2(), 1);
6766
6210
  var registry = new Map;
6767
- // source/framework/plugins/body-parser.plugin.ts
6768
- function bodyParserPlugin() {
6769
- return {
6770
- name: "body-parser-plugin",
6771
- setup: (scope) => {
6772
- scope.use(async ({ context, next }) => {
6773
- readQueryBody(context);
6774
- const isGetOrHead = ["GET", "HEAD"].includes(context.req.method.toUpperCase());
6775
- if (isGetOrHead) {
6776
- context.req.body = context.req.query;
6777
- }
6778
- const hasBody = context.req.body !== undefined && context.req.body !== null;
6779
- if (hasBody && !context.state.bodyParsed && !isGetOrHead) {
6780
- try {
6781
- const contentType = context.req.headers.get("content-type") || "";
6782
- const rawBody = await readRawBody(context.req.body);
6783
- const bodyString = decode(rawBody);
6784
- await readMultipartBody(context, contentType, rawBody);
6785
- readJsonBody(context, contentType, bodyString);
6786
- readUrlEncodedBody(context, contentType, bodyString);
6787
- readTextBody(context, contentType, bodyString);
6788
- if (!context.state.bodyParsed) {
6789
- context.req.body = rawBody;
6790
- context.state.bodyParsed = true;
6791
- }
6792
- } catch (e) {
6793
- Logger.error("Error parsing body:", e);
6794
- }
6795
- }
6796
- await next();
6797
- });
6798
- }
6799
- };
6800
- }
6801
- function readJsonBody(ctx, contentType, body) {
6802
- if (contentType.includes("application/json")) {
6803
- ctx.req.body = tryParseJson(body) || {};
6804
- ctx.state.bodyParsed = true;
6805
- }
6806
- }
6807
- async function readMultipartBody(ctx, contentType, rawBody) {
6808
- if (contentType.includes("multipart/form-data")) {
6809
- try {
6810
- const tempRequest = new Request(ctx.req.url, {
6811
- method: ctx.req.method,
6812
- headers: ctx.req.headers,
6813
- body: rawBody
6814
- });
6815
- const formData = await tempRequest.formData();
6816
- const record = {};
6817
- const files = {};
6818
- for (const [key, value] of formData.entries()) {
6819
- const v = value;
6820
- if (v && v instanceof File) {
6821
- files[key] = {
6822
- name: v.name,
6823
- type: v.type,
6824
- size: v.size,
6825
- lastModified: v.lastModified,
6826
- buffer: Buffer.from(await v.arrayBuffer())
6827
- };
6828
- } else {
6829
- record[key] = value;
6830
- }
6831
- }
6832
- ctx.req.body = record;
6833
- ctx.req.files = files;
6834
- ctx.req.file = Object.values(files)[0] || null;
6835
- ctx.state.bodyParsed = true;
6836
- } catch (e) {
6837
- Logger.error("Error parsing multipart body:", e);
6838
- }
6839
- }
6840
- }
6841
- function readUrlEncodedBody(ctx, contentType, body) {
6842
- if (contentType.includes("application/x-www-form-urlencoded")) {
6843
- const params = new URLSearchParams(body);
6844
- const record = {};
6845
- params.forEach((value, key) => {
6846
- record[key] = value;
6847
- });
6848
- ctx.req.body = record;
6849
- ctx.state.bodyParsed = true;
6850
- }
6851
- }
6852
- function readTextBody(ctx, contentType, body) {
6853
- if (contentType.includes("text/")) {
6854
- ctx.req.body = body;
6855
- ctx.state.bodyParsed = true;
6856
- }
6857
- }
6858
- function readQueryBody(ctx) {
6859
- const searchParams = new URLSearchParams(ctx.req.url.split("?")[1] || "");
6860
- const record = {};
6861
- searchParams.forEach((value, key) => record[key] = value);
6862
- ctx.req.query = record;
6863
- }
6864
- async function readRawBody(body) {
6865
- if (!body)
6866
- return new Uint8Array(0);
6867
- if (body instanceof Uint8Array || typeof body === "string") {
6868
- return body;
6869
- }
6870
- if (typeof body === "object" && !("on" in body) && !(body instanceof ReadableStream)) {
6871
- return JSON.stringify(body);
6872
- }
6873
- if (body instanceof ReadableStream) {
6874
- const reader = body.getReader();
6875
- const chunks = [];
6876
- while (true) {
6877
- const { done, value } = await reader.read();
6878
- if (done)
6879
- break;
6880
- chunks.push(value);
6881
- }
6882
- const totalLength = chunks.reduce((acc, chunk) => acc + chunk.length, 0);
6883
- const result = new Uint8Array(totalLength);
6884
- let offset = 0;
6885
- for (const chunk of chunks) {
6886
- result.set(chunk, offset);
6887
- offset += chunk.length;
6888
- }
6889
- return result;
6890
- }
6891
- if (typeof body === "object" && body !== null && "on" in body && typeof body.on === "function") {
6892
- return new Promise((resolve, reject) => {
6893
- const chunks = [];
6894
- body.on("data", (chunk) => chunks.push(chunk));
6895
- body.on("end", () => {
6896
- if (chunks.length > 0 && typeof chunks[0] === "string") {
6897
- resolve(chunks.join(""));
6898
- } else {
6899
- const totalLength = chunks.reduce((acc, chunk) => acc + chunk.length, 0);
6900
- const result = new Uint8Array(totalLength);
6901
- let offset = 0;
6902
- for (const chunk of chunks) {
6903
- result.set(new Uint8Array(chunk), offset);
6904
- offset += chunk.length;
6905
- }
6906
- resolve(result);
6907
- }
6908
- });
6909
- body.on("error", reject);
6910
- });
6911
- }
6912
- return body;
6913
- }
6914
- function decode(data) {
6915
- if (typeof data === "string")
6916
- return data;
6917
- return new TextDecoder().decode(data);
6918
- }
6919
6211
  // source/framework/decorators/routable.decorator.ts
6920
6212
  function stabilizeRoute(meta, { path: path3, method, propertyKey }) {
6921
6213
  return {
@@ -7036,170 +6328,6 @@ class RouteInteractionsRegistry {
7036
6328
  return this.interactions.has(fullPath);
7037
6329
  }
7038
6330
  }
7039
- // source/core/hooks.ts
7040
- class HookStore {
7041
- hooks = new Map;
7042
- add(name, handler2) {
7043
- const list = this.hooks.get(name) ?? [];
7044
- list.push(handler2);
7045
- this.hooks.set(name, list);
7046
- }
7047
- remove(name, handler2) {
7048
- if (!this.hooks.has(name))
7049
- return;
7050
- if (!handler2) {
7051
- this.hooks.delete(name);
7052
- return;
7053
- }
7054
- const list = this.hooks.get(name);
7055
- const idx = list.indexOf(handler2);
7056
- if (idx !== -1)
7057
- list.splice(idx, 1);
7058
- if (list.length === 0)
7059
- this.hooks.delete(name);
7060
- else
7061
- this.hooks.set(name, list);
7062
- }
7063
- replace(name, oldHandler, newHandler) {
7064
- if (!this.hooks.has(name)) {
7065
- this.add(name, newHandler);
7066
- return;
7067
- }
7068
- const list = this.hooks.get(name);
7069
- const idx = list.indexOf(oldHandler);
7070
- if (idx !== -1) {
7071
- list[idx] = newHandler;
7072
- } else {
7073
- list.push(newHandler);
7074
- }
7075
- this.hooks.set(name, list);
7076
- }
7077
- async run(name, ctx) {
7078
- const list = this.hooks.get(name);
7079
- if (!list)
7080
- return;
7081
- for (const hook of list) {
7082
- await hook(ctx);
7083
- }
7084
- }
7085
- }
7086
-
7087
- // source/core/middleware/compose.ts
7088
- function middlewareCompose(middlewares) {
7089
- return function(request) {
7090
- let index = -1;
7091
- return dispatch(0);
7092
- async function dispatch(i) {
7093
- if (i <= index) {
7094
- return Promise.reject(new Throwable("next() called multiple times"));
7095
- }
7096
- index = i;
7097
- const fn = middlewares[i];
7098
- try {
7099
- if (!fn)
7100
- return Promise.resolve();
7101
- if (typeof fn === "function") {
7102
- return Promise.resolve(fn({ context: request, next: () => dispatch(i + 1) }));
7103
- }
7104
- if (typeof fn === "object" && "setup" in fn && typeof fn.setup == "function") {
7105
- if (fn.setup.length === 1) {
7106
- await Promise.resolve(fn.setup(request));
7107
- return await dispatch(i + 1);
7108
- }
7109
- return Promise.resolve(fn.setup(request, () => dispatch(i + 1)));
7110
- }
7111
- return Promise.resolve();
7112
- } catch (err) {
7113
- return Promise.reject(err);
7114
- }
7115
- }
7116
- };
7117
- }
7118
- // source/core/middleware/pipeline.ts
7119
- class MiddlewarePipeline {
7120
- stack = [];
7121
- use(mw) {
7122
- this.stack.push(mw);
7123
- return this;
7124
- }
7125
- replace(name, mw) {
7126
- const normalized = name.toLowerCase();
7127
- for (let i = 0;i < this.stack.length; i++) {
7128
- const entry = this.stack[i];
7129
- let entryName;
7130
- if (typeof entry === "function") {
7131
- entryName = entry.name?.toLowerCase();
7132
- } else if (typeof entry === "object" && entry !== null && "name" in entry) {
7133
- entryName = entry.name?.toLowerCase();
7134
- }
7135
- if (entryName === normalized) {
7136
- this.stack[i] = mw;
7137
- return this;
7138
- }
7139
- }
7140
- this.stack.push(mw);
7141
- return this;
7142
- }
7143
- remove(name) {
7144
- const normalized = name.toLowerCase();
7145
- this.stack = this.stack.filter((entry) => {
7146
- if (typeof entry === "function")
7147
- return entry.name?.toLowerCase() !== normalized;
7148
- if (typeof entry === "object" && entry !== null && "name" in entry)
7149
- return entry.name?.toLowerCase() !== normalized;
7150
- return true;
7151
- });
7152
- return this;
7153
- }
7154
- clear() {
7155
- this.stack = [];
7156
- return this;
7157
- }
7158
- run(ctx, ...extra) {
7159
- const fn = middlewareCompose([...this.stack, ...extra]);
7160
- return typeof fn == "function" ? fn(ctx) : undefined;
7161
- }
7162
- }
7163
- // source/core/plugins/scope.ts
7164
- class PluginScope {
7165
- hooks;
7166
- middleware;
7167
- router;
7168
- parent;
7169
- constructor(parent) {
7170
- this.parent = parent;
7171
- this.hooks = parent ? parent.hooks : new HookStore;
7172
- this.middleware = parent ? parent.middleware : new MiddlewarePipeline;
7173
- this.router = parent ? parent.router : new Router;
7174
- }
7175
- addHook(name, fn) {
7176
- this.hooks.add(name, fn);
7177
- return this;
7178
- }
7179
- use(mw) {
7180
- if (typeof mw === "object" && mw !== null && "setup" in mw && typeof mw.setup === "function" && mw.setup.length === 1) {
7181
- mw.setup(this);
7182
- return this;
7183
- }
7184
- this.middleware.use(mw);
7185
- return this;
7186
- }
7187
- route(method, path3, handler2, version2) {
7188
- return this.router.add(method, path3, handler2, version2);
7189
- }
7190
- get(path3, handler2, version2) {
7191
- return this.route("GET" /* GET */, path3, handler2, version2);
7192
- }
7193
- register(plugin) {
7194
- if (typeof plugin === "object" && plugin !== null && "setup" in plugin && typeof plugin.setup === "function" && plugin.setup.length === 1) {
7195
- plugin.setup(this);
7196
- return this;
7197
- }
7198
- const child = new PluginScope(this);
7199
- plugin.setup(child);
7200
- return this;
7201
- }
7202
- }
7203
6331
  // source/core/plugins/plugin.ts
7204
6332
  function definePlugin(setup, name) {
7205
6333
  return { setup, name };
@@ -7214,110 +6342,6 @@ var secureHeaders = definePlugin((scope2) => {
7214
6342
  await next();
7215
6343
  });
7216
6344
  }, "security-headers");
7217
-
7218
- // source/framework/plugins/security/cors.ts
7219
- var secureCors = (opts = {}) => {
7220
- return async ({ context, next }) => {
7221
- const origin = context.req.headers.get("origin");
7222
- if (origin) {
7223
- context.reply.header("Vary", "Origin");
7224
- }
7225
- let allowedOrigin = null;
7226
- if (opts.origin === undefined || opts.origin === "*") {
7227
- allowedOrigin = "*";
7228
- } else if (opts.origin === true) {
7229
- allowedOrigin = origin || "*";
7230
- } else if (typeof opts.origin === "function") {
7231
- if (origin && await opts.origin(origin)) {
7232
- allowedOrigin = origin;
7233
- }
7234
- } else if (Array.isArray(opts.origin)) {
7235
- if (origin && opts.origin.includes(origin)) {
7236
- allowedOrigin = origin;
7237
- }
7238
- } else if (typeof opts.origin === "string") {
7239
- if (opts.origin === origin) {
7240
- allowedOrigin = origin;
7241
- } else if (opts.origin === "*") {
7242
- allowedOrigin = "*";
7243
- }
7244
- }
7245
- if (allowedOrigin) {
7246
- context.reply.header("Access-Control-Allow-Origin", allowedOrigin);
7247
- }
7248
- if (opts.credentials) {
7249
- context.reply.header("Access-Control-Allow-Credentials", "true");
7250
- }
7251
- if (opts.exposeHeaders) {
7252
- context.reply.header("Access-Control-Expose-Headers", opts.exposeHeaders.join(","));
7253
- }
7254
- if (context.req.method === "OPTIONS") {
7255
- context.reply.header("Access-Control-Allow-Methods", (opts.methods ?? ["GET", "POST", "PUT", "DELETE", "PATCH"]).join(","));
7256
- context.reply.header("Access-Control-Allow-Headers", (opts.headers ?? ["Content-Type", "Authorization", "X-Requested-With"]).join(","));
7257
- if (opts.maxAge) {
7258
- context.reply.header("Access-Control-Max-Age", opts.maxAge.toString());
7259
- }
7260
- context.reply.status(204);
7261
- return context.send(null);
7262
- }
7263
- await next();
7264
- };
7265
- };
7266
-
7267
- // source/framework/plugins/security/rate-limit.ts
7268
- var secureRateLimit = (opts = {}) => definePlugin((scope2) => {
7269
- const hits = new Map;
7270
- const windowMs = opts.windowMs ?? 60000;
7271
- const max = opts.max ?? 100;
7272
- scope2.use(async ({ context, next }) => {
7273
- const ip = context.req.remoteAddress ?? "unknown";
7274
- const now = Date.now();
7275
- const entry = hits.get(ip) ?? { count: 0, ts: now };
7276
- if (now - entry.ts > windowMs) {
7277
- entry.count = 0;
7278
- entry.ts = now;
7279
- }
7280
- entry.count++;
7281
- hits.set(ip, entry);
7282
- if (entry.count > max) {
7283
- context.reply.status(429);
7284
- return context.send({ error: "Too many requests" });
7285
- }
7286
- await next();
7287
- });
7288
- }, "rate-limit");
7289
-
7290
- // source/framework/plugins/security/body-limit.ts
7291
- var secureBodyLimit = (maxBytes = 1e6) => definePlugin((scope2) => {
7292
- scope2.use(async ({ context, next }) => {
7293
- const len = Number(context.req.headers.get("content-length") ?? 0);
7294
- if (len > maxBytes) {
7295
- context.reply.status(413);
7296
- return context.send({ error: "Payload too large" });
7297
- }
7298
- await next();
7299
- });
7300
- }, "body-limit");
7301
-
7302
- // source/framework/plugins/security/method-guard.ts
7303
- var secureMethodGuard = (allowed) => definePlugin((scope2) => {
7304
- scope2.use(async ({ context, next }) => {
7305
- if (!allowed.includes(context.req.method)) {
7306
- context.reply.status(405);
7307
- return context.send({ error: "Method not allowed" });
7308
- }
7309
- await next();
7310
- });
7311
- }, "method-guard");
7312
-
7313
- // source/framework/plugins/security/index.ts
7314
- class Security {
7315
- static headers = secureHeaders;
7316
- static cors = secureCors;
7317
- static rateLimit = secureRateLimit;
7318
- static bodyLimit = secureBodyLimit;
7319
- static methodGuard = secureMethodGuard;
7320
- }
7321
6345
  // source/framework/encryption.ts
7322
6346
  var import_argon2 = __toESM(require_argon2(), 1);
7323
6347
  var import_bcrypt = __toESM(require_bcrypt(), 1);
@@ -7550,181 +6574,6 @@ class RaitonCommands {
7550
6574
  }
7551
6575
  }
7552
6576
  }
7553
- // source/core/context.ts
7554
- class RequestContext {
7555
- req;
7556
- reply;
7557
- state = {};
7558
- decorations = new Map;
7559
- constructor(req, reply) {
7560
- this.req = req;
7561
- this.reply = reply;
7562
- }
7563
- decorate(key, value) {
7564
- if (this.decorations.has(key)) {
7565
- throw new Error(`Decoration "${key}" already exists`);
7566
- }
7567
- this.decorations.set(key, value);
7568
- }
7569
- get(key) {
7570
- if (key in this.state)
7571
- return this.state[key];
7572
- if (this.decorations.has(key)) {
7573
- return this.decorations.get(key);
7574
- }
7575
- throw new Error(`Context value "${key}" not found`);
7576
- }
7577
- send(body) {
7578
- this.reply.send(body);
7579
- }
7580
- }
7581
-
7582
- // source/core/application.ts
7583
- class Application {
7584
- config;
7585
- root;
7586
- version = RaitonConfig.get("version") || "0.0.1";
7587
- static get container() {
7588
- return Injection;
7589
- }
7590
- constructor(config2) {
7591
- this.config = config2;
7592
- this.root = new PluginScope;
7593
- if (this.config.workdir) {
7594
- process.chdir(this.config.workdir);
7595
- }
7596
- this.initialize();
7597
- }
7598
- initialize() {
7599
- const artifacts = RaitonConfig.get("artifacts");
7600
- const artifactTypes = [...artifacts?.types || [], ...Artifacts.defaultTypes];
7601
- Artifacts.registerMany(...artifactTypes);
7602
- this.register(Security.headers);
7603
- this.register(bodyParserPlugin());
7604
- return this;
7605
- }
7606
- get hostname() {
7607
- return `${this.config.protocole || "http"}://${this.config.hostname || "localhost"}${this.config.port ? `:${this.config.port}` : ""}${this.config.pathname || "/"}`;
7608
- }
7609
- setOption(key, value) {
7610
- this.config[key] = value;
7611
- return this;
7612
- }
7613
- setOptions(options) {
7614
- Object.assign(this.config, options);
7615
- return this;
7616
- }
7617
- register(plugin2) {
7618
- this.root.register(plugin2);
7619
- return this;
7620
- }
7621
- use(mw) {
7622
- this.root.use(mw);
7623
- return this;
7624
- }
7625
- route(method, path6, handler2, version2) {
7626
- const prefix = this.config.prefix ?? "";
7627
- const fullPath = `${prefix}${path6}`.replace(/\/+/g, "/") || "/";
7628
- this.root.route(method, fullPath, handler2, version2);
7629
- return this;
7630
- }
7631
- get(path6, handler2, version2) {
7632
- return this.route("GET" /* GET */, path6, handler2, version2);
7633
- }
7634
- post(path6, handler2, version2) {
7635
- return this.route("POST" /* POST */, path6, handler2, version2);
7636
- }
7637
- patch(path6, handler2, version2) {
7638
- return this.route("PATCH" /* PATCH */, path6, handler2, version2);
7639
- }
7640
- put(path6, handler2, version2) {
7641
- return this.route("PUT" /* PUT */, path6, handler2, version2);
7642
- }
7643
- delete(path6, handler2, version2) {
7644
- return this.route("DELETE" /* DELETE */, path6, handler2, version2);
7645
- }
7646
- options(path6, handler2, version2) {
7647
- return this.route("OPTIONS" /* OPTIONS */, path6, handler2, version2);
7648
- }
7649
- head(path6, handler2, version2) {
7650
- return this.route("HEAD" /* HEAD */, path6, handler2, version2);
7651
- }
7652
- trace(path6, handler2, version2) {
7653
- return this.route("TRACE" /* TRACE */, path6, handler2, version2);
7654
- }
7655
- async handle(req, reply) {
7656
- const ctx = new RequestContext(req, reply);
7657
- if (this.config.verbose) {
7658
- Logger.info(`Incoming request: ${req.method} ${req.url}`);
7659
- }
7660
- await this.root.hooks.run("onRequest", ctx);
7661
- const handler2 = async (param) => {
7662
- const context = param.context ?? param;
7663
- const req2 = context.req;
7664
- const reply2 = context.reply;
7665
- const url = new URL(req2.url, this.hostname);
7666
- let pathname = url.pathname;
7667
- if (this.config.pathname && this.config.pathname !== "/") {
7668
- const appPathname = this.config.pathname.endsWith("/") ? this.config.pathname : `${this.config.pathname}/`;
7669
- if (pathname.startsWith(appPathname)) {
7670
- pathname = pathname.substring(appPathname.length - 1) || "/";
7671
- } else if (pathname === this.config.pathname) {
7672
- pathname = "/";
7673
- } else {
7674
- if (this.config.verbose) {
7675
- Logger.warn(`Request out of application pathname: ${pathname} (expected prefix: ${this.config.pathname})`);
7676
- }
7677
- reply2.status(404);
7678
- return reply2.send({ error: false, statusCode: 404 });
7679
- }
7680
- }
7681
- const route2 = this.root.router.match(req2.method, pathname);
7682
- if (!route2) {
7683
- if (this.config.verbose) {
7684
- Logger.warn(`Route not found: ${req2.method} ${pathname}`);
7685
- }
7686
- reply2.status(404);
7687
- return reply2.send({ error: false, statusCode: 404 });
7688
- }
7689
- try {
7690
- context.params = route2.parameters;
7691
- let responses2 = await route2.handler(context);
7692
- if (responses2 instanceof ThrowableResponse) {
7693
- context.reply.status(responses2.statusCode ?? 500);
7694
- }
7695
- if (responses2 instanceof HttpException) {
7696
- context.reply.status(responses2.statusCode ?? 500);
7697
- }
7698
- context.reply.send(responses2);
7699
- } catch (e) {
7700
- Logger.info(`${req2.method} ${req2.url}`);
7701
- Logger.error("Failed to execute handle", e.message ?? e);
7702
- if (this.config.develop) {
7703
- console.error(e);
7704
- }
7705
- context.reply.status(500);
7706
- context.reply.send({ error: true, statusCode: 500, data: null });
7707
- }
7708
- };
7709
- try {
7710
- await this.root.middleware.run(ctx, handler2);
7711
- await this.root.hooks.run("onResponse", ctx);
7712
- } catch (err) {
7713
- Logger.info(`${req.method} ${req.url}`);
7714
- if (err instanceof HttpException || err instanceof ThrowableResponse) {
7715
- Logger.error(`Server error`, err.message ?? err);
7716
- ctx.reply.status(err.statusCode ?? 500);
7717
- return ctx.reply.send(err.render());
7718
- }
7719
- ctx.reply.send({
7720
- statusCode: 500,
7721
- error: true,
7722
- message: err.message ?? err,
7723
- data: null
7724
- });
7725
- }
7726
- }
7727
- }
7728
6577
  // source/bin/cli-tools.ts
7729
6578
  import { spawn } from "node:child_process";
7730
6579