raiton 1.0.0-alpha.2 → 1.0.0-alpha.3

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 (72) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +1 -2
  3. package/build/bin/index.mjs +3798 -3644
  4. package/build/raiton-1.0.0-alpha.3.tgz +0 -0
  5. package/deno.json +9 -0
  6. package/package.json +2 -1
  7. package/source/bin/cli-tools.ts +1 -6
  8. package/source/bin/constants.ts +5 -0
  9. package/source/bin/index.ts +1 -1
  10. package/source/commands/develop.command.ts +3 -3
  11. package/source/commands/start.command.ts +1 -1
  12. package/source/core/application.ts +66 -18
  13. package/source/core/builder.ts +27 -21
  14. package/source/core/controller/builder.ts +8 -5
  15. package/source/core/controller/metadata.ts +1 -1
  16. package/source/core/directories.ts +1 -1
  17. package/source/core/index.ts +0 -1
  18. package/source/core/injection/injection.ts +67 -5
  19. package/source/core/middleware/compose.ts +1 -1
  20. package/source/core/raiton.ts +2 -3
  21. package/source/core/router/handler.ts +100 -44
  22. package/source/core/thread.ts +18 -8
  23. package/source/sdk/artifacts.ts +65 -41
  24. package/source/sdk/constants/decorators.constant.ts +1 -0
  25. package/source/sdk/data-transfer-object.ts +11 -3
  26. package/source/sdk/decorators/parametrable.ts +19 -15
  27. package/source/sdk/decorators/routable.decorator.ts +0 -3
  28. package/source/sdk/encryption.ts +5 -6
  29. package/source/sdk/enums/encrypted.enum.ts +10 -0
  30. package/source/sdk/enums/http-status.enum.ts +73 -0
  31. package/source/sdk/enums/index.ts +2 -1
  32. package/source/sdk/exceptions/http-exception.ts +28 -0
  33. package/source/sdk/exceptions/index.ts +2 -0
  34. package/source/sdk/index.ts +7 -0
  35. package/source/sdk/parameter-bag.ts +55 -0
  36. package/source/sdk/repositories.ts +1 -1
  37. package/source/sdk/responses/error.ts +52 -0
  38. package/source/sdk/responses/helpers.ts +28 -0
  39. package/source/sdk/responses/http-throwable.ts +28 -0
  40. package/source/sdk/responses/http.ts +48 -0
  41. package/source/sdk/responses/index.ts +4 -0
  42. package/source/sdk/runtime/bun/server.ts +2 -1
  43. package/source/sdk/runtime/deno/server.ts +2 -2
  44. package/source/sdk/runtime/node/server.ts +2 -2
  45. package/source/sdk/utilities/artifact.util.ts +18 -0
  46. package/source/sdk/utilities/index.ts +1 -3
  47. package/source/types/application.ts +3 -3
  48. package/source/types/artifact.ts +36 -32
  49. package/source/types/builder.ts +0 -4
  50. package/source/types/config.ts +2 -2
  51. package/source/types/controller.ts +1 -2
  52. package/source/types/index.ts +2 -3
  53. package/source/types/lifecycle.ts +11 -0
  54. package/source/types/responses.ts +17 -7
  55. package/source/types/runtime.ts +1 -1
  56. package/build/raiton-1.0.0-alpha.2.tgz +0 -0
  57. package/source/core/artifacts/artifact.ts +0 -109
  58. package/source/core/artifacts/artifacts.ts +0 -10
  59. package/source/core/artifacts/index.ts +0 -1
  60. package/source/core/artifacts/runner.ts +0 -3
  61. package/source/core/hmr.ts +0 -106
  62. package/source/sdk/decorators/payload.decorator.ts +0 -77
  63. package/source/sdk/json.ts +0 -55
  64. package/source/sdk/request.ts +0 -3
  65. package/source/sdk/responses.ts +0 -45
  66. package/source/sdk/schemes.ts +0 -178
  67. package/source/sdk/utilities/artifacts.util.ts +0 -62
  68. package/source/sdk/utilities/controller.util.ts +0 -8
  69. package/source/types/data-transfer-object.ts +0 -4
  70. package/source/types/hmr.ts +0 -39
  71. /package/source/sdk/enums/{http.enum.ts → http-method.enum.ts} +0 -0
  72. /package/source/sdk/{throwable.ts → exceptions/throwable.ts} +0 -0
@@ -1,8 +1,11 @@
1
- import {ControllerMetaInterface, MiddlewareCallable, RouteMetaInterface} from "@/types";
2
- import {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 {Throwable} from "@/sdk/throwable";
5
- import {middlewareCompose} from "@/core";
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";
6
9
 
7
10
  export function createHandler(
8
11
  instance: any,
@@ -10,50 +13,103 @@ export function createHandler(
10
13
  controllerMeta: ControllerMetaInterface,
11
14
  ) {
12
15
  return async (ctx: any) => {
13
- const args: any[] = []
14
-
15
- for (const p of routeMeta.params) {
16
-
17
- switch (p.type) {
18
- case Parametrable.QUERY:
19
- args[p.index] =
20
- ctx.req.query?.[p.key!]
21
- break
22
- case Parametrable.PARAM:
23
- args[p.index] =
24
- ctx.req.params?.[p.key!] ?? ctx.params?.[p.key!]
25
- break
26
- case Parametrable.BODY:
27
- args[p.index] = ctx.req.body
28
- break
29
- case Parametrable.HEADER:
30
- args[p.index] = ctx.req.headers[p.key!.toLowerCase()] as any;
31
- break
32
- case Parametrable.REQ:
33
- args[p.index] = ctx.req
34
- break
35
- case Parametrable.REPLY:
36
- args[p.index] = ctx.REPLY
37
- break
38
- case Parametrable.UPLOAD_FILE:
39
- args[p.index] = ctx.req.file
40
- break
41
- case Parametrable.CUSTOM:
42
- args[p.index] = p.callable?.(ctx) ?? null;
43
- break;
16
+ const isDevelopment = Raiton.thread?.builder?.options?.development || false;
17
+ const handlerName = `${instance.constructor.name}.${routeMeta.propertyKey}`
18
+
19
+ try {
20
+ const args: any[] = []
21
+ const params: ParamMetaInterface[] = Reflect.getMetadata(METADATA_KEYS.ROUTE_PARAMETERS, instance.constructor)?.[routeMeta.propertyKey] || []
22
+
23
+ for (const p of params) {
24
+
25
+ switch (p.type) {
26
+ case Parametrable.QUERY:
27
+ args[p.index] =
28
+ ctx.req.query?.[p.key!]
29
+ break
30
+ case Parametrable.PARAM:
31
+ args[p.index] =
32
+ ctx.req.params?.[p.key!] ?? ctx.params?.[p.key!]
33
+ break
34
+ case Parametrable.BODY:
35
+ if (p.metatype && 'prototype' in p.metatype) {
36
+ ctx.req.body = new p.metatype(ctx.req.body)
37
+ }
38
+ args[p.index] = ctx.req.body
39
+ break
40
+ case Parametrable.HEADER:
41
+ args[p.index] = ctx.req.headers[p.key!.toLowerCase()] as any;
42
+ break
43
+ case Parametrable.REQ:
44
+ args[p.index] = ctx.req
45
+ break
46
+ case Parametrable.REPLY:
47
+ args[p.index] = ctx.REPLY
48
+ break
49
+ case Parametrable.UPLOAD_FILE:
50
+ args[p.index] = ctx.req.file
51
+ break
52
+ case Parametrable.CUSTOM:
53
+ args[p.index] = p.callable?.(ctx) ?? null;
54
+ break;
55
+ }
44
56
  }
45
- }
46
57
 
47
- if (!(routeMeta.propertyKey in instance))
48
- throw new Throwable(`${routeMeta.propertyKey} does not exist`)
58
+ if (!(routeMeta.propertyKey in instance))
59
+ throw new Throwable(`${routeMeta.propertyKey} does not exist`)
60
+
61
+ /**
62
+ * Middlewares running order
63
+ */
64
+ const middlewares: MiddlewareCallable[] = [
65
+ ...controllerMeta.middlewares['@'] || [],
66
+ ...controllerMeta.middlewares[routeMeta.propertyKey] || []
67
+ ]
68
+ if (middlewares.length > 0) await middlewareCompose(middlewares)(ctx)
69
+
70
+ /**
71
+ * Vérification des arguments
72
+ */
73
+ for (const input of args) {
74
+ /** DTO validation */
75
+ if (input instanceof DataTransferObject) {
76
+ const errors = await input.validation(false);
77
+ if (errors && errors.length) {
78
+ const stack = Object.values(errors[0].constraints || {})
79
+ throw new Throwable(stack.join(';'), 500)
80
+ }
81
+ }
82
+ }
83
+
84
+ let responses = instance[routeMeta.propertyKey](...args)
85
+ if (responses instanceof Promise) responses = await responses
86
+
87
+ return responses;
88
+ } catch (err: any) {
49
89
 
50
- const middlewares: MiddlewareCallable[] = [
51
- ...controllerMeta.middlewares['@'] || [],
52
- ...controllerMeta.middlewares[routeMeta.propertyKey] || []
53
- ]
90
+ if (!(err instanceof ThrowableResponse)) {
91
+ Logger.error(`Failed to execute ${handlerName} handler`, err.message ?? err);
92
+ ctx.reply.status(500)
93
+ }
54
94
 
55
- if (middlewares.length > 0) await middlewareCompose(middlewares)(ctx)
95
+ if (err instanceof ThrowableResponse) {
96
+ ctx.reply.status(err.statusCode || 201)
97
+ }
56
98
 
57
- return instance[routeMeta.propertyKey](...args)
99
+ if (err instanceof HttpException || err instanceof ThrowableResponse)
100
+ return err.render()
101
+
102
+ return {
103
+ statusCode: 500,
104
+ error: true,
105
+ message: err.message ?? err,
106
+ data: null,
107
+ stack: isDevelopment
108
+ ? (typeof err.stack === 'string' ? err.stack.split('\n')
109
+ : [String(err.stack || err.toString() || err.message || err.name || 'Unknown error')])
110
+ .map((l: any) => typeof l === 'string' ? l.trim() : String(l)) : undefined
111
+ ,
112
+ }
113
+ }
58
114
  }
59
115
  }
@@ -13,17 +13,18 @@ import {until} from "./process.util";
13
13
  import {ApplicationInterface} from "@/types/application";
14
14
  import {Runtime} from "@/sdk/runtime";
15
15
  import {LBadge, Logger} from "@protorians/logger";
16
- import {Throwable} from "@/sdk/throwable";
17
16
  import {ControllerBuilder} from "@/core/controller";
18
17
  import {bodyParserPlugin} from "@/sdk/plugins/body-parser.plugin";
18
+ import {Injection} from "@/core/injection/injection";
19
+ import {Throwable} from "@/sdk/exceptions";
19
20
 
20
21
 
21
22
  export class RaitonThread implements ThreadInterface {
22
23
 
23
24
  protected static instance: RaitonThread | null = null;
24
25
 
25
- public static get current(): RaitonThread {
26
- if (!RaitonThread.instance) throw new Throwable('Thread not initialized')
26
+ public static get current(): RaitonThread | null {
27
+ // if (!RaitonThread.instance) throw new Throwable('Thread not initialized')
27
28
  return RaitonThread.instance;
28
29
  }
29
30
 
@@ -45,7 +46,8 @@ export class RaitonThread implements ThreadInterface {
45
46
  process.send?.(EventMessageEnum.RESTART)
46
47
  }
47
48
 
48
- public stop(): void {
49
+ public async stop(): Promise<void> {
50
+ await Injection.shutdown();
49
51
  process.exit(0)
50
52
  }
51
53
 
@@ -73,15 +75,23 @@ export class RaitonThread implements ThreadInterface {
73
75
  if (!this.runtime)
74
76
  throw new Throwable('Runtime not defined');
75
77
 
78
+ process.on('SIGINT', async () => {
79
+ await this.stop();
80
+ });
81
+
82
+ process.on('SIGTERM', async () => {
83
+ await this.stop();
84
+ });
85
+
76
86
  const port = this.application.config.port || 5712;
87
+ const hostname = this.application.config.hostname || 'localhost';
77
88
 
78
89
  this.runtimeServer = this.runtime.createServer(this.application.handle.bind(this.application))
79
90
 
80
- await this.runtimeServer.listen(port)
81
- if (this.builder.out)
82
- await ControllerBuilder.scan(this.builder.out)
91
+ await this.runtimeServer.listen(port, hostname)
92
+ if (this.builder.source) await ControllerBuilder.scan(this.builder.source)
83
93
 
84
- Logger.log(LBadge.info('Server Started'), `http://localhost:${port}`)
94
+ Logger.log(LBadge.info('Server Started'), `http://${hostname}:${port}`)
85
95
  return this;
86
96
  }
87
97
  }
@@ -1,55 +1,79 @@
1
- import path from "node:path";
2
- import fs from "fs";
1
+ import {Injection} from "@/core/injection";
3
2
  import {Logger} from "@protorians/logger";
4
- import {IFileStatInfo} from "@/types";
3
+ import type {IConstructor} from "@/types";
5
4
  import {Raiton} from "@/core/raiton";
6
- import {RaitonDirectories} from "@/core";
5
+ import {isArtifact, isControllerArtifact} from "@/sdk/utilities";
7
6
 
8
- export class ArtifactFactory {
9
- protected static readonly stack: Map<string, Set<IFileStatInfo>> = new Map();
7
+ export class Artifacts {
10
8
 
11
- static getSource(key: string) {
12
- return path.join(
13
- RaitonDirectories.artifacts(Raiton.thread.builder.workdir),
14
- `${key}.json`
15
- );
16
- }
9
+ static readonly types: Set<string> = new Set();
17
10
 
18
- static add(key: string, file: IFileStatInfo) {
19
- if (!this.stack.has(key)) this.stack.set(key, new Set());
20
- this.stack.get(key)?.add(file);
21
- }
11
+ static readonly defaultTypes = [
12
+ 'service',
13
+ 'provider',
14
+ 'type',
15
+ 'repository',
16
+ 'database',
17
+ 'db',
18
+ 'util',
19
+ 'utility',
20
+ 'source',
21
+ 'controller',
22
+ 'middleware',
23
+ 'hook',
24
+ 'event',
25
+ 'listener',
26
+ 'validator',
27
+ 'strategy',
28
+ 'strategy-provider',
29
+ 'strategy-type',
30
+ ]
22
31
 
23
- static get(key: string): Set<IFileStatInfo> | undefined {
24
- return this.stack.get(key);
32
+ static register(type: string) {
33
+ this.types.add(type)
34
+ return this
25
35
  }
26
36
 
27
- static has(key: string): boolean {
28
- return this.stack.has(key);
37
+ static registerMany(...types: string[]) {
38
+ for (const type of types) this.register(type)
39
+ return this;
29
40
  }
30
41
 
31
- static load(key: string) {
32
- const outputFile = this.getSource(key)
33
- if (!fs.existsSync(outputFile)) return this;
34
- const content = fs.readFileSync(outputFile, "utf-8");
35
- const files = JSON.parse(content) as IFileStatInfo[];
36
- files.forEach(file => this.add(key, file));
37
- return this;
42
+ static is(filename: string) {
43
+ return [...this.types]
44
+ .map(type => isArtifact(filename, type))
45
+ .some(Boolean)
38
46
  }
39
47
 
40
- static save(key: string) {
41
- try {
42
- const set = this.stack.get(key);
43
- if (!set) return;
44
- const content = JSON.stringify([...set.values()]);
45
- const outputFile = this.getSource(key)
46
- const dir = path.dirname(outputFile);
47
- if (!fs.existsSync(dir)) fs.mkdirSync(dir, {recursive: true})
48
- fs.writeFileSync(outputFile, content, "utf-8");
49
- return true
50
- } catch (e) {
51
- Logger.error(`Failed to save artifacts for key ${key}:`, e);
52
- return false;
48
+ static reload(modulo: any, filename?: string) {
49
+
50
+ if (Raiton.thread?.builder.options.development === false)
51
+ return Logger.warn(
52
+ 'Artifact reload is only available in development mode'
53
+ )
54
+
55
+ for (const mod of Object.values(modulo)) {
56
+ const name = (mod && typeof mod === 'object' && 'name' in mod) ? mod.name : (
57
+ typeof mod === 'function' ? mod.name ?? mod.constructor.name : undefined
58
+ );
59
+
60
+ if (typeof name === 'string' && Injection.has(name)) {
61
+ if (filename) Injection.registerArtifactPath(name, filename);
62
+ Injection.updateConstruct(name, mod as IConstructor)
63
+
64
+ const dependents = Injection.getDependents(name);
65
+ for (const dependent of dependents) {
66
+ const dependentPath = Injection.getArtifactPath(dependent);
67
+ if (dependentPath && isControllerArtifact(dependentPath)) {
68
+ Raiton.signals.dispatch('hmr:controller', {
69
+ filename: dependentPath,
70
+ timestamp: Date.now(),
71
+ version: 1
72
+ })
73
+ }
74
+ }
75
+ }
53
76
  }
77
+
54
78
  }
55
- }
79
+ }
@@ -1,5 +1,6 @@
1
1
  export const METADATA_KEYS = {
2
2
  CONTROLLERS: Symbol('controller:meta'),
3
+ ROUTE_PARAMETERS: Symbol('route:meta'),
3
4
  GRAFTS: Symbol('graft:meta'),
4
5
  CONTAINER: Symbol('container:meta'),
5
6
  INJECT_PARAMETERS: Symbol('inject:parameters'),
@@ -1,7 +1,15 @@
1
- import {DynamicParameter} from "@protorians/parameters";
2
- import {IDataTransferObject} from "@/types";
1
+ import {validate, validateOrReject, ValidationError} from "class-validator";
2
+ import {Logger} from "@protorians/logger";
3
3
 
4
4
 
5
- export class DataTransferObject<T extends IDataTransferObject<T>> extends DynamicParameter<T> {
5
+ export class DataTransferObject {
6
+ constructor(initial: Record<string, any>) {
7
+ for (const [key, value] of Object.entries(initial)) {
8
+ if (typeof value !== 'function') this[key as keyof typeof this] = value;
9
+ }
10
+ }
6
11
 
12
+ async validation(strict: boolean = true): Promise<void | ValidationError[]> {
13
+ return await ((strict ? validateOrReject : validate)(this))
14
+ }
7
15
  }
@@ -1,24 +1,28 @@
1
+ import "reflect-metadata";
1
2
  import type {Context, ParamMetaInterface} from "@/types";
2
- import {getControllerMetadata} from "@/core";
3
- import {Parametrable} from "@/sdk";
4
- import {Logger} from "@protorians/logger";
3
+ import {METADATA_KEYS, Parametrable} from "@/sdk";
5
4
 
6
- function createParametrable(type: ParamMetaInterface['type'], callable?: (context: Context) => any) {
5
+ function createRouteParametrableDecorator(type: ParamMetaInterface['type'], callable?: (context: Context) => any) {
7
6
  return (key?: string) => {
8
7
  return (target: any, propertyKey: string, index: number) => {
9
- const meta = getControllerMetadata(target)
10
- if (!meta.params[propertyKey])
11
- meta.params[propertyKey] = []
12
- meta.params[propertyKey].push({index, type, key, callable})
8
+ const params = Reflect.getMetadata(METADATA_KEYS.ROUTE_PARAMETERS, target.constructor) || {}
9
+ const metatypes = Reflect.getMetadata("design:paramtypes", target, propertyKey);
10
+ const metatype = metatypes ? metatypes[index] : undefined;
11
+
12
+ if (!params[propertyKey]) {
13
+ params[propertyKey] = []
14
+ }
15
+ params[propertyKey].push({index, type, key, callable, metatype})
16
+ Reflect.defineMetadata(METADATA_KEYS.ROUTE_PARAMETERS, params, target.constructor)
13
17
  }
14
18
  }
15
19
  }
16
20
 
17
- export const Query = createParametrable(Parametrable.QUERY)
18
- export const Param = createParametrable(Parametrable.PARAM)
19
- export const Body = createParametrable(Parametrable.BODY)
20
- export const UploadedFile = createParametrable(Parametrable.UPLOAD_FILE)
21
- export const Headers = createParametrable(Parametrable.HEADER)
22
- export const Req = createParametrable(Parametrable.REQ)
23
- export const Reply = createParametrable(Parametrable.REPLY)
21
+ export const Query = createRouteParametrableDecorator(Parametrable.QUERY)
22
+ export const Param = createRouteParametrableDecorator(Parametrable.PARAM)
23
+ export const Body = createRouteParametrableDecorator(Parametrable.BODY)
24
+ export const UploadedFile = createRouteParametrableDecorator(Parametrable.UPLOAD_FILE)
25
+ export const Headers = createRouteParametrableDecorator(Parametrable.HEADER)
26
+ export const Req = createRouteParametrableDecorator(Parametrable.REQ)
27
+ export const Reply = createRouteParametrableDecorator(Parametrable.REPLY)
24
28
 
@@ -1,7 +1,6 @@
1
1
  import {getControllerMetadata} from "@/core";
2
2
  import {HttpMethod} from "@/sdk";
3
3
  import {ControllerMetaInterface, RouteDecoratorCallable, RouteMetaInterface} from "@/types";
4
- import path from "node:path";
5
4
 
6
5
 
7
6
  function stabilizeRoute(meta: ControllerMetaInterface, {path, method, propertyKey}: Partial<RouteMetaInterface>) {
@@ -10,7 +9,6 @@ function stabilizeRoute(meta: ControllerMetaInterface, {path, method, propertyKe
10
9
  method,
11
10
  path,
12
11
  propertyKey,
13
- params: (propertyKey ? meta.params[propertyKey] : []) || [],
14
12
  } as RouteMetaInterface;
15
13
  }
16
14
 
@@ -22,7 +20,6 @@ export function createRoutableDecorator(method: HttpMethod) {
22
20
  method,
23
21
  path,
24
22
  propertyKey,
25
- params: meta.params[propertyKey] || [],
26
23
  });
27
24
  meta.routes.push(route)
28
25
  }
@@ -1,7 +1,6 @@
1
-
2
1
  import crypto from "node:crypto";
3
2
  import argon2, {Options} from "argon2";
4
- import {HashAlgoEnum} from "./enums";
3
+ import {HashAlgoEnum, PasswordAlgoEnum} from "./enums";
5
4
  import bcrypt from "bcrypt";
6
5
  import {IDerivationOptions, IEncryptionResult, IScryptOptions} from "@/types";
7
6
 
@@ -10,14 +9,14 @@ export class Encryption {
10
9
  return HashAlgoEnum;
11
10
  }
12
11
 
13
- static randomAlgo() {
14
- return Object.values(this.algos)[
12
+ static randomAlgo(algo?: PasswordAlgoEnum[] | HashAlgoEnum[]) {
13
+ return (algo ?? Object.values(this.algos))[
15
14
  Math.floor(Math.random() * Object.values(this.algos).length)
16
15
  ];
17
16
  }
18
17
 
19
- constructor(public readonly algo: HashAlgoEnum) {
20
- if (!Object.values(HashAlgoEnum).includes(this.algo)) {
18
+ constructor(public readonly algo: HashAlgoEnum | PasswordAlgoEnum) {
19
+ if (![...Object.values(HashAlgoEnum), ...Object.values(PasswordAlgoEnum)].includes(this.algo)) {
21
20
  throw new Error(`Invalid hash algorithm: ${this.algo}`);
22
21
  }
23
22
  }
@@ -10,4 +10,14 @@ export enum HashAlgoEnum {
10
10
  BLAKE2B = 'BLAKE2B',
11
11
  SHA3_256 = 'SHA3_256',
12
12
  SHA3_512 = 'SHA3_512',
13
+ }
14
+
15
+ export enum CipherAlgoEnum {
16
+ AES_256_CBC = 'AES-256-CBC',
17
+ }
18
+
19
+ export enum PasswordAlgoEnum {
20
+ ARGON2ID = 'argon2id',
21
+ BCRYPT = 'BCRYPT',
22
+ SCRYPT = 'SCRYPT',
13
23
  }
@@ -0,0 +1,73 @@
1
+ export enum HttpStatus {
2
+
3
+ CONTINUE = 100,
4
+ SWITCHING_PROTOCOLS = 101,
5
+ PROCESSING = 102,
6
+ EARLY_HINTS = 103,
7
+
8
+
9
+ OK = 200,
10
+ CREATED = 201,
11
+ ACCEPTED = 202,
12
+ NON_AUTHORITATIVE_INFORMATION = 203,
13
+ NO_CONTENT = 204,
14
+ RESET_CONTENT = 205,
15
+ PARTIAL_CONTENT = 206,
16
+ MULTI_STATUS = 207,
17
+ ALREADY_REPORTED = 208,
18
+ IM_USED = 226,
19
+
20
+
21
+ MULTIPLE_CHOICES = 300,
22
+ MOVED_PERMANENTLY = 301,
23
+ FOUND = 302,
24
+ SEE_OTHER = 303,
25
+ NOT_MODIFIED = 304,
26
+ USE_PROXY = 305,
27
+ TEMPORARY_REDIRECT = 307,
28
+ PERMANENT_REDIRECT = 308,
29
+
30
+
31
+ BAD_REQUEST = 400,
32
+ UNAUTHORIZED = 401,
33
+ PAYMENT_REQUIRED = 402,
34
+ FORBIDDEN = 403,
35
+ NOT_FOUND = 404,
36
+ METHOD_NOT_ALLOWED = 405,
37
+ NOT_ACCEPTABLE = 406,
38
+ PROXY_AUTHENTICATION_REQUIRED = 407,
39
+ REQUEST_TIMEOUT = 408,
40
+ CONFLICT = 409,
41
+ GONE = 410,
42
+ LENGTH_REQUIRED = 411,
43
+ PRECONDITION_FAILED = 412,
44
+ PAYLOAD_TOO_LARGE = 413,
45
+ URI_TOO_LONG = 414,
46
+ UNSUPPORTED_MEDIA_TYPE = 415,
47
+ RANGE_NOT_SATISFIABLE = 416,
48
+ EXPECTATION_FAILED = 417,
49
+ IM_A_TEAPOT = 418,
50
+ MISDIRECTED_REQUEST = 421,
51
+ UNPROCESSABLE_ENTITY = 422,
52
+ LOCKED = 423,
53
+ FAILED_DEPENDENCY = 424,
54
+ TOO_EARLY = 425,
55
+ UPGRADE_REQUIRED = 426,
56
+ PRECONDITION_REQUIRED = 428,
57
+ TOO_MANY_REQUESTS = 429,
58
+ REQUEST_HEADER_FIELDS_TOO_LARGE = 431,
59
+ UNAVAILABLE_FOR_LEGAL_REASONS = 451,
60
+
61
+
62
+ INTERNAL_SERVER_ERROR = 500,
63
+ NOT_IMPLEMENTED = 501,
64
+ BAD_GATEWAY = 502,
65
+ SERVICE_UNAVAILABLE = 503,
66
+ GATEWAY_TIMEOUT = 504,
67
+ HTTP_VERSION_NOT_SUPPORTED = 505,
68
+ VARIANT_ALSO_NEGOTIATES = 506,
69
+ INSUFFICIENT_STORAGE = 507,
70
+ LOOP_DETECTED = 508,
71
+ NOT_EXTENDED = 510,
72
+ NETWORK_AUTHENTICATION_REQUIRED = 511,
73
+ }
@@ -1,5 +1,6 @@
1
- export * from "./http.enum"
1
+ export * from "./http-method.enum"
2
2
  export * from "./http-parameters.enum"
3
+ export * from "./http-status.enum"
3
4
  export * from "./encrypted.enum"
4
5
  export * from "./event.message.enum"
5
6
  export * from "./timestamp.enum"
@@ -0,0 +1,28 @@
1
+ import {HttpStatus} from "@/sdk/enums/http-status.enum";
2
+ import {Raiton} from "@/core";
3
+ import {HttpResponseBaseInterface} from "@/types";
4
+
5
+ export class HttpException extends Error {
6
+
7
+ constructor(
8
+ error: string | HttpResponseBaseInterface | Error,
9
+ public statusCode: HttpStatus = HttpStatus.INTERNAL_SERVER_ERROR,
10
+ ) {
11
+ super(typeof error === 'string' ? error : error.message);
12
+ }
13
+
14
+ render() {
15
+ return {
16
+ message: this.message,
17
+ statusCode: this.statusCode,
18
+ error: true,
19
+ stack: Raiton.thread?.builder?.options?.development
20
+ ? this.stack?.split('\n').map(e => e.trim())
21
+ : undefined
22
+ }
23
+ }
24
+
25
+ toString() {
26
+ return `HttpException: ${this.message} with status code ${this.statusCode}`
27
+ }
28
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./http-exception"
2
+ export * from "./throwable"
@@ -1,6 +1,13 @@
1
1
  export * from "./enums/index"
2
2
  export * from "./constants/index"
3
3
  export * from "./decorators/index"
4
+ export * from "./responses/index"
4
5
  export * from "./plugins/index"
5
6
  export * from "./utilities/index"
6
7
  export * from "./runtime/index"
8
+ export * from "./controllers"
9
+ export * from "./data-transfer-object"
10
+ export * from "./encryption"
11
+ export * from "./parameter-bag"
12
+ export * from "./repositories"
13
+ export * from "./services"