raiton 3.0.1 → 3.1.0

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 (93) hide show
  1. package/CHANGELOG.md +15 -15
  2. package/README.md +1 -1
  3. package/build/bin/index.mjs +240 -2
  4. package/package.json +3 -4
  5. package/scripts/update-version.ts +5 -5
  6. package/source/bin/bootstrapper.ts +3 -3
  7. package/source/bin/cli-tools.ts +1 -1
  8. package/source/bin/cli.ts +1 -1
  9. package/source/commands/artifact.command.ts +3 -3
  10. package/source/commands/build.command.ts +3 -3
  11. package/source/commands/develop.command.ts +3 -3
  12. package/source/commands/grafts.command.ts +1 -1
  13. package/source/commands/start.command.ts +3 -3
  14. package/source/core/application.ts +23 -18
  15. package/source/core/builder.ts +8 -8
  16. package/source/core/bytes.util.ts +2 -2
  17. package/source/core/config/config.ts +8 -8
  18. package/source/core/config/define.ts +4 -4
  19. package/source/core/context.ts +1 -1
  20. package/source/core/controller/builder.ts +6 -6
  21. package/source/core/controller/compiler.ts +5 -5
  22. package/source/core/controller/metadata.ts +2 -2
  23. package/source/core/directories.ts +1 -1
  24. package/source/core/guards.ts +43 -0
  25. package/source/core/hooks.ts +4 -4
  26. package/source/core/injection/injection.ts +8 -7
  27. package/source/core/middleware/compose.ts +2 -2
  28. package/source/core/middleware/pipeline.ts +2 -2
  29. package/source/core/plugins/plugin.ts +3 -3
  30. package/source/core/plugins/scope.ts +3 -3
  31. package/source/core/raiton.ts +2 -2
  32. package/source/core/router/handler.ts +7 -7
  33. package/source/core/router/matcher.ts +1 -1
  34. package/source/core/router/route.ts +3 -3
  35. package/source/core/router/router.ts +5 -5
  36. package/source/core/server.ts +3 -3
  37. package/source/core/thread.ts +14 -13
  38. package/source/sdk/artifacts.ts +5 -5
  39. package/source/sdk/decorators/controllable.decorator.ts +3 -3
  40. package/source/sdk/decorators/guard.decorator.ts +23 -0
  41. package/source/sdk/decorators/index.ts +2 -1
  42. package/source/sdk/decorators/injection.decorator.ts +4 -4
  43. package/source/sdk/decorators/middleware.decorator.ts +2 -2
  44. package/source/sdk/decorators/parametrable.ts +3 -3
  45. package/source/sdk/decorators/routable.decorator.ts +3 -3
  46. package/source/sdk/encryption.ts +15 -15
  47. package/source/sdk/env.ts +5 -5
  48. package/source/sdk/exceptions/http-exception.ts +3 -3
  49. package/source/sdk/parameter-bag.ts +1 -1
  50. package/source/sdk/plugins/body-parser.plugin.ts +5 -5
  51. package/source/sdk/plugins/security/body-limit.ts +3 -3
  52. package/source/sdk/plugins/security/cors.ts +3 -3
  53. package/source/sdk/plugins/security/headers.ts +3 -3
  54. package/source/sdk/plugins/security/method-guard.ts +3 -3
  55. package/source/sdk/plugins/security/rate-limit.ts +3 -3
  56. package/source/sdk/repositories.ts +1 -1
  57. package/source/sdk/responses/error.ts +2 -2
  58. package/source/sdk/responses/helpers.ts +3 -3
  59. package/source/sdk/responses/http-throwable.ts +3 -3
  60. package/source/sdk/responses/http.ts +3 -3
  61. package/source/sdk/runtime/bun/server.ts +1 -1
  62. package/source/sdk/runtime/deno/server.ts +1 -1
  63. package/source/sdk/runtime/index.ts +6 -6
  64. package/source/sdk/runtime/node/server.ts +1 -1
  65. package/source/sdk/runtime/web/server.ts +1 -1
  66. package/source/sdk/utilities/utilities.util.ts +2 -2
  67. package/source/types/application.ts +5 -5
  68. package/source/types/artifact.ts +2 -43
  69. package/source/types/builder.ts +5 -5
  70. package/source/types/config.ts +3 -3
  71. package/source/types/controller.ts +6 -6
  72. package/source/types/contruct.ts +1 -1
  73. package/source/types/core.ts +3 -5
  74. package/source/types/directory.ts +1 -1
  75. package/source/types/encryption.ts +21 -12
  76. package/source/types/generic.ts +2 -2
  77. package/source/types/guard.ts +12 -0
  78. package/source/types/index.ts +1 -3
  79. package/source/types/injection.ts +2 -2
  80. package/source/types/lifecycle.ts +3 -3
  81. package/source/types/middleware.ts +5 -5
  82. package/source/types/plugin.ts +4 -6
  83. package/source/types/raiton.ts +3 -3
  84. package/source/types/responses.ts +10 -7
  85. package/source/types/router.ts +5 -5
  86. package/source/types/runtime.ts +1 -1
  87. package/source/types/server.ts +3 -3
  88. package/source/types/thread.ts +7 -7
  89. package/source/types/utilities.ts +1 -1
  90. package/source/types/values.ts +2 -2
  91. package/source/types/access-guards.ts +0 -4
  92. package/source/types/http-responses.ts +0 -8
  93. package/source/types/scheme.ts +0 -153
@@ -1,19 +1,19 @@
1
1
  import path from "node:path";
2
2
  import fs from "node:fs";
3
- import {Configurable} from "@/types";
3
+ import {ConfigurableInterface} from "../../types";
4
4
  import {Logger} from "@protorians/logger";
5
- import {Raiton} from "@/core/raiton";
5
+ import {Raiton} from "../raiton";
6
6
 
7
7
  export class RaitonConfig {
8
- static readonly current: Map<keyof Configurable, Configurable[keyof Configurable]> = new Map();
8
+ static readonly current: Map<keyof ConfigurableInterface, ConfigurableInterface[keyof ConfigurableInterface]> = new Map();
9
9
 
10
10
  protected static _extensions: string[] = ['.js', '.mjs'];
11
11
 
12
- static get<K extends keyof Configurable>(key: K): Configurable[K] | undefined {
13
- return this.current.get(key) as Configurable[K];
12
+ static get<K extends keyof ConfigurableInterface>(key: K): ConfigurableInterface[K] | undefined {
13
+ return this.current.get(key) as ConfigurableInterface[K];
14
14
  }
15
15
 
16
- static defaultConfig: Configurable = {
16
+ static defaultConfig: ConfigurableInterface = {
17
17
  rootDir: '.',
18
18
  version: '0.0.1'
19
19
  }
@@ -26,7 +26,7 @@ export class RaitonConfig {
26
26
  if (fs.existsSync(configJsonPath)) {
27
27
  const configContent = fs.readFileSync(configJsonPath, 'utf-8');
28
28
  for (const [key, value] of Object.entries({...this.defaultConfig, ...(JSON.parse(configContent) || {})}))
29
- this.current.set(key as keyof Configurable, value as Configurable[keyof Configurable]);
29
+ this.current.set(key as keyof ConfigurableInterface, value as ConfigurableInterface[keyof ConfigurableInterface]);
30
30
  } else {
31
31
  for (const ext of this._extensions) {
32
32
  const configPath = path.join(workdir, `${Raiton.identifier}.config${ext}`);
@@ -34,7 +34,7 @@ export class RaitonConfig {
34
34
  const configModule = await import(configPath);
35
35
  const config = await configModule?.default || configModule;
36
36
  for (const [key, value] of Object.entries(config)) {
37
- this.current.set(key as keyof Configurable, value as Configurable[keyof Configurable]);
37
+ this.current.set(key as keyof ConfigurableInterface, value as ConfigurableInterface[keyof ConfigurableInterface]);
38
38
  }
39
39
  }
40
40
  }
@@ -1,11 +1,11 @@
1
- import {Configurable} from "@/types/config";
2
- import {JsonUtil} from "@/sdk/utilities";
1
+ import {ConfigurableInterface} from "../../types/config";
2
+ import {JsonUtil} from "../../sdk/utilities";
3
3
 
4
- export async function defineConfig(config?: Configurable) {
4
+ export async function defineConfig(config?: ConfigurableInterface) {
5
5
  const workdir = process.cwd();
6
6
  const pkg = JsonUtil.import(workdir + '/package.json');
7
7
 
8
- config = {...config || {}, ...pkg.raitonConfig || {}} as Configurable;
8
+ config = {...config || {}, ...pkg.raitonConfig || {}} as ConfigurableInterface;
9
9
  config.rootDir = config.rootDir || './';
10
10
  config.version = config.version || pkg.version || '0.0.1';
11
11
 
@@ -1,7 +1,7 @@
1
1
  import type {
2
2
  RuntimeRequestInterface,
3
3
  RuntimeReplyInterface
4
- } from '@/types'
4
+ } from '../types'
5
5
 
6
6
  export class RequestContext {
7
7
  public state: Record<string, any> = {}
@@ -1,10 +1,10 @@
1
1
  import fs from "node:fs";
2
- import {BuilderHMRDeclaration} from "@/types";
2
+ import {BuilderHMRDeclarationInterface} from "../../types";
3
3
  import {LBadge, Logger} from "@protorians/logger";
4
- import {compileController} from "@/core/controller/compiler";
5
- import {RaitonThread} from "@/core/thread";
6
- import {Injection} from "@/core/injection";
7
- import {isControllerArtifact} from "@/sdk";
4
+ import {compileController} from "./compiler";
5
+ import {RaitonThread} from "../thread";
6
+ import {Injection} from "../injection";
7
+ import {isControllerArtifact} from "../../sdk";
8
8
  import path from "node:path";
9
9
 
10
10
  export class ControllerBuilder {
@@ -21,7 +21,7 @@ export class ControllerBuilder {
21
21
  return output.filter(f => typeof f !== 'undefined');
22
22
  }
23
23
 
24
- static async build<T>({filename, version, timestamp}: BuilderHMRDeclaration): Promise<T | undefined> {
24
+ static async build<T>({filename, version, timestamp}: BuilderHMRDeclarationInterface): Promise<T | undefined> {
25
25
  if (!isControllerArtifact(filename))
26
26
  return undefined;
27
27
 
@@ -1,8 +1,8 @@
1
- import {ApplicationInterface} from "@/types/application";
2
- import {getControllerMetadata} from "@/core";
3
- import {createHandler} from "@/core/router";
4
- import {Injection} from "@/core/injection";
5
- import {ControllerMetaInterface} from "@/types";
1
+ import {ApplicationInterface} from "../../types/application";
2
+ import {getControllerMetadata} from "..";
3
+ import {createHandler} from "../router";
4
+ import {Injection} from "../injection";
5
+ import {ControllerMetaInterface} from "../../types";
6
6
 
7
7
  export function compileController(
8
8
  ControllerClass: any,
@@ -1,5 +1,5 @@
1
- import {ControllerMetaInterface} from "@/types";
2
- import {METADATA_KEYS} from "@/sdk";
1
+ import {ControllerMetaInterface} from "../../types";
2
+ import {METADATA_KEYS} from "../../sdk";
3
3
  import "reflect-metadata";
4
4
 
5
5
  export function getControllerMetadata(target: any): ControllerMetaInterface {
@@ -1,6 +1,6 @@
1
1
  import path from "node:path";
2
2
  import {RaitonConfig} from "./config";
3
- import {Raiton} from "@/core/raiton";
3
+ import {Raiton} from "./raiton";
4
4
 
5
5
 
6
6
  export class RaitonDirectories {
@@ -0,0 +1,43 @@
1
+ import {GuardDeclaration} from "../types";
2
+ import {Logger} from "@protorians/logger";
3
+
4
+ export class RaitonGuards {
5
+ protected static _map: Map<string, GuardDeclaration> = new Map();
6
+
7
+ static set(name: string, guard: GuardDeclaration): typeof this {
8
+ this._map.set(name, guard);
9
+ return this;
10
+ }
11
+
12
+ static get(name: string): GuardDeclaration | undefined {
13
+ return this._map.get(name);
14
+ }
15
+
16
+ static remove(name: string): typeof this {
17
+ this._map.delete(name);
18
+ return this;
19
+ }
20
+
21
+ static removeAll(): typeof this {
22
+ Logger.error('Removing all guards');
23
+ this._map.clear();
24
+ return this;
25
+ }
26
+
27
+ static enabled(name: string): boolean {
28
+ const guard = this.get(name);
29
+ return (!guard) ? false : guard.enabled;
30
+ }
31
+
32
+ static enable(name: string): typeof this {
33
+ const guard = this.get(name);
34
+ if(guard) guard.enabled = true;
35
+ return this;
36
+ }
37
+
38
+ static disable(name: string){
39
+ const guard = this.get(name);
40
+ if(guard) guard.enabled = false;
41
+ return this;
42
+ }
43
+ }
@@ -1,15 +1,15 @@
1
- import {HookName, HookHandler} from '@/types'
1
+ import {HookNameType, HookHandlerCallable} from '../types'
2
2
 
3
3
  export class HookStore {
4
- private hooks = new Map<HookName, HookHandler[]>()
4
+ private hooks = new Map<HookNameType, HookHandlerCallable[]>()
5
5
 
6
- add(name: HookName, handler: HookHandler) {
6
+ add(name: HookNameType, handler: HookHandlerCallable) {
7
7
  const list = this.hooks.get(name) ?? []
8
8
  list.push(handler)
9
9
  this.hooks.set(name, list)
10
10
  }
11
11
 
12
- async run(name: HookName, ctx: any) {
12
+ async run(name: HookNameType, ctx: any) {
13
13
  const list = this.hooks.get(name)
14
14
  if (!list) return
15
15
 
@@ -1,9 +1,9 @@
1
1
  import "reflect-metadata";
2
- import type {IConstructor, ContainerDefinitionInterface} from "@/types";
2
+ import type {ConstructorType, ContainerDefinitionInterface} from "../../types";
3
3
  import {LifetimeEnum, TextUtility} from "@protorians/core";
4
4
  import {Logger} from "@protorians/logger";
5
- import {METADATA_KEYS} from "@/sdk/constants";
6
- import {Throwable} from "@/sdk/exceptions";
5
+ import {METADATA_KEYS} from "../../sdk/constants";
6
+ import {Throwable} from "../../sdk/exceptions";
7
7
 
8
8
  const camelCase = TextUtility.camelCase;
9
9
 
@@ -30,20 +30,21 @@ export class Injection {
30
30
  }
31
31
 
32
32
  static clear(): void {
33
+ Logger.error('Clearing injection container');
33
34
  this._classes.clear();
34
35
  this._instances.clear();
35
36
  this._dependents.clear();
36
37
  this._artifactPaths.clear();
37
38
  }
38
39
 
39
- static normalizeName(name: string): string {
40
+ protected static normalizeName(name: string): string {
40
41
  const stableName = camelCase(name);
41
42
  return stableName[0].toLowerCase() + stableName.slice(1);
42
43
  }
43
44
 
44
45
  static registry(
45
46
  name: string,
46
- construct: IConstructor,
47
+ construct: ConstructorType,
47
48
  lifetime: LifetimeEnum = LifetimeEnum.SINGLETON,
48
49
  scope?: Symbol
49
50
  ): typeof this {
@@ -54,7 +55,7 @@ export class Injection {
54
55
  return this;
55
56
  }
56
57
 
57
- static updateConstruct(name: string, construct: IConstructor): typeof this {
58
+ static updateConstruct(name: string, construct: ConstructorType): typeof this {
58
59
  const name_ = this.normalizeName(name);
59
60
  this._classes.set(name_, {...this._classes.get(this.normalizeName(name))!, construct});
60
61
  return this;
@@ -208,7 +209,7 @@ export class Injection {
208
209
  this.clear();
209
210
  }
210
211
 
211
- static resolve<T>(construct: IConstructor<T>): T {
212
+ static resolve<T>(construct: ConstructorType<T>): T {
212
213
  const metadata: ContainerDefinitionInterface = Reflect.getMetadata(METADATA_KEYS.CONTAINER, construct);
213
214
 
214
215
  if (!metadata)
@@ -1,5 +1,5 @@
1
- import {MiddlewareType} from '@/types'
2
- import {Throwable} from "@/sdk/exceptions";
1
+ import {MiddlewareType} from '../../types'
2
+ import {Throwable} from "../../sdk/exceptions";
3
3
 
4
4
  export function middlewareCompose(middlewares: MiddlewareType[]) {
5
5
  return function (request: any) {
@@ -1,5 +1,5 @@
1
- import { MiddlewareType } from '@/types'
2
- import { middlewareCompose } from '@/core'
1
+ import { MiddlewareType } from '../../types'
2
+ import { middlewareCompose } from '..'
3
3
 
4
4
  export class MiddlewarePipeline {
5
5
  private stack: MiddlewareType[] = []
@@ -1,8 +1,8 @@
1
- import { Plugin, PluginFn } from '@/types'
1
+ import { PluginInterface, PluginCallable } from '../../types'
2
2
 
3
3
  export function definePlugin(
4
- setup: PluginFn,
4
+ setup: PluginCallable,
5
5
  name?: string
6
- ): Plugin {
6
+ ): PluginInterface {
7
7
  return { setup, name }
8
8
  }
@@ -1,6 +1,6 @@
1
- import {HookStore} from '@/core/hooks'
2
- import {MiddlewarePipeline} from '@/core/middleware'
3
- import {Route, Router} from '@/core/router'
1
+ import {HookStore} from '../hooks'
2
+ import {MiddlewarePipeline} from '../middleware'
3
+ import {Route, Router} from '../router'
4
4
 
5
5
  export class PluginScope {
6
6
  public hooks: HookStore
@@ -1,11 +1,11 @@
1
- import {RaitonSignalMap, ThreadInterface} from "@/types";
1
+ import {RaitonSignalMapInterface, ThreadInterface} from "../types";
2
2
  import {ISignalStack, Signal} from "@protorians/core";
3
3
 
4
4
 
5
5
  export class Raiton {
6
6
  protected static _thread: ThreadInterface | undefined;
7
7
 
8
- static readonly signals: ISignalStack<RaitonSignalMap> = new Signal.Stack<RaitonSignalMap>()
8
+ static readonly signals: ISignalStack<RaitonSignalMapInterface> = new Signal.Stack<RaitonSignalMapInterface>()
9
9
  static title: string = 'Protorians Raiton';
10
10
  static identifier: string = 'raiton';
11
11
 
@@ -1,11 +1,11 @@
1
- import {ControllerMetaInterface, MiddlewareCallable, ParamMetaInterface, RouteMetaInterface} from "@/types";
2
- import {METADATA_KEYS, Parametrable} from "@/sdk";
1
+ import {ControllerMetaInterface, MiddlewareCallable, ParamMetaInterface, RouteMetaInterface} from "../../types";
2
+ import {METADATA_KEYS, Parametrable} from "../../sdk";
3
3
  import {Logger} from "@protorians/logger";
4
- import {middlewareCompose, Raiton} from "@/core";
5
- import {DataTransferObject} from "@/sdk/data-transfer-object";
6
- import {Throwable} from "@/sdk/exceptions/throwable";
7
- import {HttpException} from "@/sdk/exceptions";
8
- import {ThrowableResponse} from "@/sdk/responses/http-throwable";
4
+ import {middlewareCompose, Raiton} from "..";
5
+ import {DataTransferObject} from "../../sdk/data-transfer-object";
6
+ import {Throwable} from "../../sdk/exceptions/throwable";
7
+ import {HttpException} from "../../sdk/exceptions";
8
+ import {ThrowableResponse} from "../../sdk/responses/http-throwable";
9
9
 
10
10
  export function createHandler(
11
11
  instance: any,
@@ -1,4 +1,4 @@
1
- import {Route} from '@/core/router'
1
+ import {Route} from '.'
2
2
 
3
3
  export class RouteMatcher {
4
4
  protected routes = new Map<string, Route>()
@@ -1,13 +1,13 @@
1
- import type {RouteDefinition} from '@/types/router'
1
+ import type {RouteDefinitionInterface} from '../../types/router'
2
2
 
3
3
  export class Route {
4
4
  method: string
5
5
  path: string
6
6
  version?: string
7
- handler: RouteDefinition['handler']
7
+ handler: RouteDefinitionInterface['handler']
8
8
  parameters: Record<string, string> = {}
9
9
 
10
- constructor(def: RouteDefinition) {
10
+ constructor(def: RouteDefinitionInterface) {
11
11
  this.method = def.method
12
12
  this.path = def.path
13
13
  this.version = def.version
@@ -1,12 +1,12 @@
1
- import {RouteHandler} from '@/types'
2
- import {HttpMethod} from "@/sdk/enums";
3
- import {Route} from '@/core/router/route'
4
- import {RouteMatcher} from '@/core/router/matcher'
1
+ import {RouteHandlerCallable} from '../../types'
2
+ import {HttpMethod} from "../../sdk/enums";
3
+ import {Route} from './route'
4
+ import {RouteMatcher} from './matcher'
5
5
 
6
6
  export class Router {
7
7
  private matcher = new RouteMatcher()
8
8
 
9
- add(method: HttpMethod, path: string, handler: RouteHandler, version?: string) {
9
+ add(method: HttpMethod, path: string, handler: RouteHandlerCallable, version?: string) {
10
10
  const route = new Route({
11
11
  method,
12
12
  path,
@@ -1,4 +1,4 @@
1
- import type {ServerInterface, ServerOptions} from "@/types";
1
+ import type {ServerInterface, ServerOptionsInterface} from "../types";
2
2
 
3
3
 
4
4
  export class Server implements ServerInterface {
@@ -14,12 +14,12 @@ export class Server implements ServerInterface {
14
14
  }
15
15
 
16
16
  constructor(
17
- public readonly options: ServerOptions
17
+ public readonly options: ServerOptionsInterface
18
18
  ) {
19
19
  Server.instance = this;
20
20
  }
21
21
 
22
- option<K extends keyof ServerOptions>(key: K): ServerOptions[K] {
22
+ option<K extends keyof ServerOptionsInterface>(key: K): ServerOptionsInterface[K] {
23
23
  return this.options[key];
24
24
  }
25
25
 
@@ -3,20 +3,20 @@ import type {
3
3
  RuntimeAdapterInterface,
4
4
  RuntimeServerInterface,
5
5
  ThreadInterface,
6
- ThreadOptions,
7
- ThreadSetupOptions,
6
+ ThreadOptionsInterface,
7
+ ThreadSetupOptionsInterface,
8
8
  ThreadWaitCallable,
9
- } from "@/types";
10
- import {EventMessageEnum, RuntimeType} from "@/sdk/enums";
9
+ } from "../types";
10
+ import {EventMessageEnum, RuntimeType} from "../sdk/enums";
11
11
  import {ProcessUtility} from "@protorians/core";
12
12
  import {until} from "./process.util";
13
- import {ApplicationInterface} from "@/types/application";
14
- import {Runtime} from "@/sdk/runtime";
13
+ import {ApplicationInterface} from "../types/application";
14
+ import {Runtime} from "../sdk/runtime";
15
15
  import {LBadge, Logger} from "@protorians/logger";
16
- import {ControllerBuilder} from "@/core/controller";
17
- import {bodyParserPlugin} from "@/sdk/plugins/body-parser.plugin";
18
- import {Injection} from "@/core/injection/injection";
19
- import {Throwable} from "@/sdk/exceptions";
16
+ import {ControllerBuilder} from "./controller";
17
+ import {bodyParserPlugin} from "../sdk/plugins/body-parser.plugin";
18
+ import {Injection} from "./injection/injection";
19
+ import {Throwable} from "../sdk/exceptions";
20
20
  import os from "os";
21
21
 
22
22
 
@@ -37,7 +37,7 @@ export class RaitonThread implements ThreadInterface {
37
37
 
38
38
  constructor(
39
39
  public readonly builder: BuilderInterface,
40
- protected _options: ThreadOptions = {}
40
+ protected _options: ThreadOptionsInterface = {}
41
41
  ) {
42
42
  this.appDir = process.cwd();
43
43
  RaitonThread.instance = this;
@@ -72,7 +72,7 @@ export class RaitonThread implements ThreadInterface {
72
72
  return null;
73
73
  }
74
74
 
75
- public setup({application, runtime}: ThreadSetupOptions): this {
75
+ public setup({application, runtime}: ThreadSetupOptionsInterface): this {
76
76
  const defaultRuntime = typeof Bun !== 'undefined' ? RuntimeType.Bun : RuntimeType.Node;
77
77
  this.runtime = new Runtime(runtime || defaultRuntime);
78
78
  this.application = application;
@@ -106,7 +106,8 @@ export class RaitonThread implements ThreadInterface {
106
106
  await this.runtimeServer.listen(port, hostname)
107
107
  if (this.builder.source) await ControllerBuilder.scan(this.builder.source)
108
108
 
109
- Logger.log(LBadge.info('Server Started'), `http://${displayHostname}:${port}${prefix ?? ''}`)
109
+ Logger.log(LBadge.info('Local access:'), `http://localhost:${port}${prefix ?? ''}`,)
110
+ Logger.log(LBadge.info('LAN access:'), `http://${displayHostname}:${port}${prefix ?? ''}`,)
110
111
  return this;
111
112
  }
112
113
  }
@@ -1,8 +1,8 @@
1
- import {Injection} from "@/core/injection";
1
+ import {Injection} from "../core/injection";
2
2
  import {Logger} from "@protorians/logger";
3
- import type {IConstructor} from "@/types";
4
- import {Raiton} from "@/core/raiton";
5
- import {isArtifact, isControllerArtifact} from "@/sdk/utilities";
3
+ import type {ConstructorType} from "../types";
4
+ import {Raiton} from "../core/raiton";
5
+ import {isArtifact, isControllerArtifact} from "./utilities";
6
6
 
7
7
  export class Artifacts {
8
8
 
@@ -59,7 +59,7 @@ export class Artifacts {
59
59
 
60
60
  if (typeof name === 'string' && Injection.has(name)) {
61
61
  if (filename) Injection.registerArtifactPath(name, filename);
62
- Injection.updateConstruct(name, mod as IConstructor)
62
+ Injection.updateConstruct(name, mod as ConstructorType)
63
63
 
64
64
  const dependents = Injection.getDependents(name);
65
65
  for (const dependent of dependents) {
@@ -1,7 +1,7 @@
1
- import {getControllerMetadata} from "@/core/controller";
2
- import {Injectable} from "@/sdk";
1
+ import {getControllerMetadata} from "../../core/controller";
2
+ import {Injectable} from "..";
3
3
  import {LifetimeEnum} from "@protorians/core";
4
- import {ControllerDecoratorCallable} from "@/types";
4
+ import {ControllerDecoratorCallable} from "../../types";
5
5
 
6
6
  export function Controllable(prefix = '') {
7
7
  return (target: any) => {
@@ -0,0 +1,23 @@
1
+ import {GuardOptions} from "../../types";
2
+ import {Middleware} from "./middleware.decorator";
3
+ import {RaitonGuards} from "../../core/guards";
4
+ import {HttpStatus} from "../enums";
5
+
6
+ export function createGuardDecoration({name, handler}: GuardOptions) {
7
+ return Middleware(async ({next, context}) => {
8
+ const guard = RaitonGuards.get(name);
9
+
10
+ if (!guard) RaitonGuards.set(name, {name, handler, enabled: true})
11
+ if (guard && !guard.enabled) return next();
12
+
13
+ const response = await handler({context, next})
14
+
15
+ if (response) return next()
16
+
17
+ context.reply.status(HttpStatus.FORBIDDEN)
18
+ return context.reply.send({
19
+ error: true,
20
+ message: 'Forbidden'
21
+ });
22
+ });
23
+ }
@@ -2,4 +2,5 @@ export * from "./controllable.decorator"
2
2
  export * from "./middleware.decorator"
3
3
  export * from "./routable.decorator"
4
4
  export * from "./parametrable"
5
- export * from "./injection.decorator"
5
+ export * from "./injection.decorator"
6
+ export * from "./guard.decorator"
@@ -1,13 +1,13 @@
1
1
  import "reflect-metadata";
2
- import type {IConstructor} from "@/types/contruct";
3
- import {Injection} from "@/core/injection";
2
+ import type {ConstructorType} from "../../types/contruct";
3
+ import {Injection} from "../../core/injection";
4
4
  import {LifetimeEnum} from "@protorians/core";
5
5
  import {Logger} from "@protorians/logger";
6
- import {METADATA_KEYS} from "@/sdk/constants";
6
+ import {METADATA_KEYS} from "../constants";
7
7
 
8
8
 
9
9
  export function Injectable(lifetime?: LifetimeEnum, name?: string, scope?: any) {
10
- return function <T extends IConstructor>(target: T) {
10
+ return function <T extends ConstructorType>(target: T) {
11
11
  const metadata = {
12
12
  name: name || target.name,
13
13
  construct: target,
@@ -1,5 +1,5 @@
1
- import {MiddlewareCallable} from "@/types";
2
- import {getControllerMetadata} from "@/core";
1
+ import {MiddlewareCallable} from "../../types";
2
+ import {getControllerMetadata} from "../../core";
3
3
 
4
4
 
5
5
  export function Middleware(middleware: MiddlewareCallable) {
@@ -1,8 +1,8 @@
1
1
  import "reflect-metadata";
2
- import type {Context, ParamMetaInterface} from "@/types";
3
- import {METADATA_KEYS, Parametrable} from "@/sdk";
2
+ import type {ContextInterface, ParamMetaInterface} from "../../types";
3
+ import {METADATA_KEYS, Parametrable} from "..";
4
4
 
5
- function createRouteParametrableDecorator(type: ParamMetaInterface['type'], callable?: (context: Context) => any) {
5
+ function createRouteParametrableDecorator(type: ParamMetaInterface['type'], callable?: (context: ContextInterface) => any) {
6
6
  return (key?: string) => {
7
7
  return (target: any, propertyKey: string, index: number) => {
8
8
  const params = Reflect.getMetadata(METADATA_KEYS.ROUTE_PARAMETERS, target.constructor) || {}
@@ -1,6 +1,6 @@
1
- import {getControllerMetadata} from "@/core";
2
- import {HttpMethod} from "@/sdk";
3
- import {ControllerMetaInterface, RouteDecoratorCallable, RouteMetaInterface} from "@/types";
1
+ import {getControllerMetadata} from "../../core";
2
+ import {HttpMethod} from "..";
3
+ import {ControllerMetaInterface, RouteDecoratorCallable, RouteMetaInterface} from "../../types";
4
4
 
5
5
 
6
6
  function stabilizeRoute(meta: ControllerMetaInterface, {path, method, propertyKey}: Partial<RouteMetaInterface>) {