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.
- package/CHANGELOG.md +15 -15
- package/README.md +1 -1
- package/build/bin/index.mjs +240 -2
- package/package.json +3 -4
- package/scripts/update-version.ts +5 -5
- package/source/bin/bootstrapper.ts +3 -3
- package/source/bin/cli-tools.ts +1 -1
- package/source/bin/cli.ts +1 -1
- package/source/commands/artifact.command.ts +3 -3
- package/source/commands/build.command.ts +3 -3
- package/source/commands/develop.command.ts +3 -3
- package/source/commands/grafts.command.ts +1 -1
- package/source/commands/start.command.ts +3 -3
- package/source/core/application.ts +23 -18
- package/source/core/builder.ts +8 -8
- package/source/core/bytes.util.ts +2 -2
- package/source/core/config/config.ts +8 -8
- package/source/core/config/define.ts +4 -4
- package/source/core/context.ts +1 -1
- package/source/core/controller/builder.ts +6 -6
- package/source/core/controller/compiler.ts +5 -5
- package/source/core/controller/metadata.ts +2 -2
- package/source/core/directories.ts +1 -1
- package/source/core/guards.ts +43 -0
- package/source/core/hooks.ts +4 -4
- package/source/core/injection/injection.ts +8 -7
- package/source/core/middleware/compose.ts +2 -2
- package/source/core/middleware/pipeline.ts +2 -2
- package/source/core/plugins/plugin.ts +3 -3
- package/source/core/plugins/scope.ts +3 -3
- package/source/core/raiton.ts +2 -2
- package/source/core/router/handler.ts +7 -7
- package/source/core/router/matcher.ts +1 -1
- package/source/core/router/route.ts +3 -3
- package/source/core/router/router.ts +5 -5
- package/source/core/server.ts +3 -3
- package/source/core/thread.ts +14 -13
- package/source/sdk/artifacts.ts +5 -5
- package/source/sdk/decorators/controllable.decorator.ts +3 -3
- package/source/sdk/decorators/guard.decorator.ts +23 -0
- package/source/sdk/decorators/index.ts +2 -1
- package/source/sdk/decorators/injection.decorator.ts +4 -4
- package/source/sdk/decorators/middleware.decorator.ts +2 -2
- package/source/sdk/decorators/parametrable.ts +3 -3
- package/source/sdk/decorators/routable.decorator.ts +3 -3
- package/source/sdk/encryption.ts +15 -15
- package/source/sdk/env.ts +5 -5
- package/source/sdk/exceptions/http-exception.ts +3 -3
- package/source/sdk/parameter-bag.ts +1 -1
- package/source/sdk/plugins/body-parser.plugin.ts +5 -5
- package/source/sdk/plugins/security/body-limit.ts +3 -3
- package/source/sdk/plugins/security/cors.ts +3 -3
- package/source/sdk/plugins/security/headers.ts +3 -3
- package/source/sdk/plugins/security/method-guard.ts +3 -3
- package/source/sdk/plugins/security/rate-limit.ts +3 -3
- package/source/sdk/repositories.ts +1 -1
- package/source/sdk/responses/error.ts +2 -2
- package/source/sdk/responses/helpers.ts +3 -3
- package/source/sdk/responses/http-throwable.ts +3 -3
- package/source/sdk/responses/http.ts +3 -3
- package/source/sdk/runtime/bun/server.ts +1 -1
- package/source/sdk/runtime/deno/server.ts +1 -1
- package/source/sdk/runtime/index.ts +6 -6
- package/source/sdk/runtime/node/server.ts +1 -1
- package/source/sdk/runtime/web/server.ts +1 -1
- package/source/sdk/utilities/utilities.util.ts +2 -2
- package/source/types/application.ts +5 -5
- package/source/types/artifact.ts +2 -43
- package/source/types/builder.ts +5 -5
- package/source/types/config.ts +3 -3
- package/source/types/controller.ts +6 -6
- package/source/types/contruct.ts +1 -1
- package/source/types/core.ts +3 -5
- package/source/types/directory.ts +1 -1
- package/source/types/encryption.ts +21 -12
- package/source/types/generic.ts +2 -2
- package/source/types/guard.ts +12 -0
- package/source/types/index.ts +1 -3
- package/source/types/injection.ts +2 -2
- package/source/types/lifecycle.ts +3 -3
- package/source/types/middleware.ts +5 -5
- package/source/types/plugin.ts +4 -6
- package/source/types/raiton.ts +3 -3
- package/source/types/responses.ts +10 -7
- package/source/types/router.ts +5 -5
- package/source/types/runtime.ts +1 -1
- package/source/types/server.ts +3 -3
- package/source/types/thread.ts +7 -7
- package/source/types/utilities.ts +1 -1
- package/source/types/values.ts +2 -2
- package/source/types/access-guards.ts +0 -4
- package/source/types/http-responses.ts +0 -8
- 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 {
|
|
3
|
+
import {ConfigurableInterface} from "../../types";
|
|
4
4
|
import {Logger} from "@protorians/logger";
|
|
5
|
-
import {Raiton} from "
|
|
5
|
+
import {Raiton} from "../raiton";
|
|
6
6
|
|
|
7
7
|
export class RaitonConfig {
|
|
8
|
-
static readonly current: Map<keyof
|
|
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
|
|
13
|
-
return this.current.get(key) as
|
|
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:
|
|
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
|
|
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
|
|
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 {
|
|
2
|
-
import {JsonUtil} from "
|
|
1
|
+
import {ConfigurableInterface} from "../../types/config";
|
|
2
|
+
import {JsonUtil} from "../../sdk/utilities";
|
|
3
3
|
|
|
4
|
-
export async function defineConfig(config?:
|
|
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
|
|
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
|
|
package/source/core/context.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
|
-
import {
|
|
2
|
+
import {BuilderHMRDeclarationInterface} from "../../types";
|
|
3
3
|
import {LBadge, Logger} from "@protorians/logger";
|
|
4
|
-
import {compileController} from "
|
|
5
|
-
import {RaitonThread} from "
|
|
6
|
-
import {Injection} from "
|
|
7
|
-
import {isControllerArtifact} from "
|
|
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}:
|
|
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 "
|
|
2
|
-
import {getControllerMetadata} from "
|
|
3
|
-
import {createHandler} from "
|
|
4
|
-
import {Injection} from "
|
|
5
|
-
import {ControllerMetaInterface} from "
|
|
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 "
|
|
2
|
-
import {METADATA_KEYS} from "
|
|
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 {
|
|
@@ -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
|
+
}
|
package/source/core/hooks.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {HookNameType, HookHandlerCallable} from '../types'
|
|
2
2
|
|
|
3
3
|
export class HookStore {
|
|
4
|
-
private hooks = new Map<
|
|
4
|
+
private hooks = new Map<HookNameType, HookHandlerCallable[]>()
|
|
5
5
|
|
|
6
|
-
add(name:
|
|
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:
|
|
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 {
|
|
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 "
|
|
6
|
-
import {Throwable} from "
|
|
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:
|
|
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:
|
|
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:
|
|
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 '
|
|
2
|
-
import {Throwable} from "
|
|
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,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PluginInterface, PluginCallable } from '../../types'
|
|
2
2
|
|
|
3
3
|
export function definePlugin(
|
|
4
|
-
setup:
|
|
4
|
+
setup: PluginCallable,
|
|
5
5
|
name?: string
|
|
6
|
-
):
|
|
6
|
+
): PluginInterface {
|
|
7
7
|
return { setup, name }
|
|
8
8
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {HookStore} from '
|
|
2
|
-
import {MiddlewarePipeline} from '
|
|
3
|
-
import {Route, Router} from '
|
|
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
|
package/source/core/raiton.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
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<
|
|
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 "
|
|
2
|
-
import {METADATA_KEYS, Parametrable} from "
|
|
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 "
|
|
5
|
-
import {DataTransferObject} from "
|
|
6
|
-
import {Throwable} from "
|
|
7
|
-
import {HttpException} from "
|
|
8
|
-
import {ThrowableResponse} from "
|
|
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,13 +1,13 @@
|
|
|
1
|
-
import type {
|
|
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:
|
|
7
|
+
handler: RouteDefinitionInterface['handler']
|
|
8
8
|
parameters: Record<string, string> = {}
|
|
9
9
|
|
|
10
|
-
constructor(def:
|
|
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 {
|
|
2
|
-
import {HttpMethod} from "
|
|
3
|
-
import {Route} from '
|
|
4
|
-
import {RouteMatcher} from '
|
|
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:
|
|
9
|
+
add(method: HttpMethod, path: string, handler: RouteHandlerCallable, version?: string) {
|
|
10
10
|
const route = new Route({
|
|
11
11
|
method,
|
|
12
12
|
path,
|
package/source/core/server.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {ServerInterface,
|
|
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:
|
|
17
|
+
public readonly options: ServerOptionsInterface
|
|
18
18
|
) {
|
|
19
19
|
Server.instance = this;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
option<K extends keyof
|
|
22
|
+
option<K extends keyof ServerOptionsInterface>(key: K): ServerOptionsInterface[K] {
|
|
23
23
|
return this.options[key];
|
|
24
24
|
}
|
|
25
25
|
|
package/source/core/thread.ts
CHANGED
|
@@ -3,20 +3,20 @@ import type {
|
|
|
3
3
|
RuntimeAdapterInterface,
|
|
4
4
|
RuntimeServerInterface,
|
|
5
5
|
ThreadInterface,
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
ThreadOptionsInterface,
|
|
7
|
+
ThreadSetupOptionsInterface,
|
|
8
8
|
ThreadWaitCallable,
|
|
9
|
-
} from "
|
|
10
|
-
import {EventMessageEnum, RuntimeType} from "
|
|
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 "
|
|
14
|
-
import {Runtime} from "
|
|
13
|
+
import {ApplicationInterface} from "../types/application";
|
|
14
|
+
import {Runtime} from "../sdk/runtime";
|
|
15
15
|
import {LBadge, Logger} from "@protorians/logger";
|
|
16
|
-
import {ControllerBuilder} from "
|
|
17
|
-
import {bodyParserPlugin} from "
|
|
18
|
-
import {Injection} from "
|
|
19
|
-
import {Throwable} from "
|
|
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:
|
|
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}:
|
|
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('
|
|
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
|
}
|
package/source/sdk/artifacts.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {Injection} from "
|
|
1
|
+
import {Injection} from "../core/injection";
|
|
2
2
|
import {Logger} from "@protorians/logger";
|
|
3
|
-
import type {
|
|
4
|
-
import {Raiton} from "
|
|
5
|
-
import {isArtifact, isControllerArtifact} from "
|
|
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
|
|
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 "
|
|
2
|
-
import {Injectable} from "
|
|
1
|
+
import {getControllerMetadata} from "../../core/controller";
|
|
2
|
+
import {Injectable} from "..";
|
|
3
3
|
import {LifetimeEnum} from "@protorians/core";
|
|
4
|
-
import {ControllerDecoratorCallable} from "
|
|
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
|
+
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
|
-
import type {
|
|
3
|
-
import {Injection} from "
|
|
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 "
|
|
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
|
|
10
|
+
return function <T extends ConstructorType>(target: T) {
|
|
11
11
|
const metadata = {
|
|
12
12
|
name: name || target.name,
|
|
13
13
|
construct: target,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
|
-
import type {
|
|
3
|
-
import {METADATA_KEYS, Parametrable} from "
|
|
2
|
+
import type {ContextInterface, ParamMetaInterface} from "../../types";
|
|
3
|
+
import {METADATA_KEYS, Parametrable} from "..";
|
|
4
4
|
|
|
5
|
-
function createRouteParametrableDecorator(type: ParamMetaInterface['type'], callable?: (context:
|
|
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 "
|
|
2
|
-
import {HttpMethod} from "
|
|
3
|
-
import {ControllerMetaInterface, RouteDecoratorCallable, RouteMetaInterface} from "
|
|
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>) {
|