raiton 5.7.0-beta.5 → 5.9.4-beta.15
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/build/bin/index.mjs +90 -6
- package/package.json +1 -1
- package/scripts/update-version.ts +1 -0
- package/source/core/application.ts +28 -5
- package/source/core/artifacts/artifact.ts +1 -1
- package/source/core/router/handler.ts +3 -9
- package/source/core/router/handler.utils.ts +1 -2
- package/source/framework/constants/decorators.constant.ts +2 -0
- package/source/framework/decorators/index.ts +2 -1
- package/source/framework/decorators/route-interaction.decorator.ts +188 -0
- package/source/framework/decorators/socket.decorator.ts +4 -4
- package/source/framework/exceptions/http-exception.ts +17 -0
- package/source/types/router.ts +5 -0
- package/source/types/thread.ts +4 -1
- package/examples/user-controller.example.ts +0 -53
package/build/bin/index.mjs
CHANGED
|
@@ -4799,7 +4799,7 @@ var require_bcrypt = __commonJS((exports, module) => {
|
|
|
4799
4799
|
});
|
|
4800
4800
|
|
|
4801
4801
|
// source/bin/index.ts
|
|
4802
|
-
var
|
|
4802
|
+
var import_reflect_metadata9 = __toESM(require_Reflect(), 1);
|
|
4803
4803
|
|
|
4804
4804
|
// node_modules/commander/esm.mjs
|
|
4805
4805
|
var import__ = __toESM(require_commander(), 1);
|
|
@@ -4817,7 +4817,7 @@ var {
|
|
|
4817
4817
|
Help
|
|
4818
4818
|
} = import__.default;
|
|
4819
4819
|
// package.json
|
|
4820
|
-
var version = "5.
|
|
4820
|
+
var version = "5.9.4-beta.15";
|
|
4821
4821
|
|
|
4822
4822
|
// source/bin/cli.ts
|
|
4823
4823
|
var CLI = new Command;
|
|
@@ -6260,7 +6260,8 @@ var METADATA_KEYS = {
|
|
|
6260
6260
|
API_ENUMS: Symbol("api:enums"),
|
|
6261
6261
|
API_TAGS: Symbol("api:tags"),
|
|
6262
6262
|
API_OPERATION: Symbol("api:operation"),
|
|
6263
|
-
API_SECURITY: Symbol("api:security")
|
|
6263
|
+
API_SECURITY: Symbol("api:security"),
|
|
6264
|
+
ROUTE_INTERACTION: Symbol("route:interaction")
|
|
6264
6265
|
};
|
|
6265
6266
|
// source/framework/responses/http.ts
|
|
6266
6267
|
class HttpResponse {
|
|
@@ -6494,6 +6495,41 @@ class Router {
|
|
|
6494
6495
|
return Array.from(this.matcher.routes.values());
|
|
6495
6496
|
}
|
|
6496
6497
|
}
|
|
6498
|
+
// source/framework/exceptions/http-exception.ts
|
|
6499
|
+
class HttpException extends Error {
|
|
6500
|
+
statusCode;
|
|
6501
|
+
errorCode;
|
|
6502
|
+
constructor(error2, statusCode = 500 /* INTERNAL_SERVER_ERROR */, errorCode = undefined) {
|
|
6503
|
+
super(typeof error2 === "string" ? error2 : error2.message);
|
|
6504
|
+
this.statusCode = statusCode;
|
|
6505
|
+
this.errorCode = errorCode;
|
|
6506
|
+
}
|
|
6507
|
+
setStatus(statusCode) {
|
|
6508
|
+
this.statusCode = statusCode;
|
|
6509
|
+
return this;
|
|
6510
|
+
}
|
|
6511
|
+
setErrorCode(code) {
|
|
6512
|
+
this.errorCode = code;
|
|
6513
|
+
return this;
|
|
6514
|
+
}
|
|
6515
|
+
setMessage(error2) {
|
|
6516
|
+
this.message = typeof error2 === "string" ? error2 : error2.message;
|
|
6517
|
+
return this;
|
|
6518
|
+
}
|
|
6519
|
+
render() {
|
|
6520
|
+
return {
|
|
6521
|
+
message: this.message,
|
|
6522
|
+
statusCode: this.statusCode,
|
|
6523
|
+
errorCode: this.errorCode,
|
|
6524
|
+
error: true,
|
|
6525
|
+
stack: Raiton.thread?.builder?.options?.serve ? this.stack?.split(`
|
|
6526
|
+
`).map((e) => e.trim()) : undefined
|
|
6527
|
+
};
|
|
6528
|
+
}
|
|
6529
|
+
toString() {
|
|
6530
|
+
return `HttpException: ${this.message} with status code ${this.statusCode}`;
|
|
6531
|
+
}
|
|
6532
|
+
}
|
|
6497
6533
|
// source/framework/exceptions/throwable.ts
|
|
6498
6534
|
class Throwable extends Error {
|
|
6499
6535
|
statusCode;
|
|
@@ -6950,6 +6986,32 @@ class RaitonGuards {
|
|
|
6950
6986
|
var import_reflect_metadata6 = __toESM(require_Reflect2(), 1);
|
|
6951
6987
|
// source/framework/decorators/api.decorator.ts
|
|
6952
6988
|
var import_reflect_metadata7 = __toESM(require_Reflect2(), 1);
|
|
6989
|
+
// source/framework/decorators/route-interaction.decorator.ts
|
|
6990
|
+
var import_reflect_metadata8 = __toESM(require_Reflect2(), 1);
|
|
6991
|
+
class RouteInteractionsRegistry {
|
|
6992
|
+
static interactions = new Map;
|
|
6993
|
+
static subscribers = new Set;
|
|
6994
|
+
static subscribe(target, propertyKey) {
|
|
6995
|
+
this.subscribers.add({ target, propertyKey });
|
|
6996
|
+
return this;
|
|
6997
|
+
}
|
|
6998
|
+
static register(fullPath, descriptor) {
|
|
6999
|
+
this.interactions.set(fullPath, descriptor);
|
|
7000
|
+
return this;
|
|
7001
|
+
}
|
|
7002
|
+
static get(fullPath) {
|
|
7003
|
+
return this.interactions.get(fullPath);
|
|
7004
|
+
}
|
|
7005
|
+
static getAll() {
|
|
7006
|
+
return new Map(this.interactions);
|
|
7007
|
+
}
|
|
7008
|
+
static clear() {
|
|
7009
|
+
this.interactions.clear();
|
|
7010
|
+
}
|
|
7011
|
+
static has(fullPath) {
|
|
7012
|
+
return this.interactions.has(fullPath);
|
|
7013
|
+
}
|
|
7014
|
+
}
|
|
6953
7015
|
// source/core/hooks.ts
|
|
6954
7016
|
class HookStore {
|
|
6955
7017
|
hooks = new Map;
|
|
@@ -7459,16 +7521,38 @@ class Application {
|
|
|
7459
7521
|
try {
|
|
7460
7522
|
context.params = route2.parameters;
|
|
7461
7523
|
let responses2 = await route2.handler(context);
|
|
7524
|
+
if (responses2 instanceof ThrowableResponse) {
|
|
7525
|
+
context.reply.status(responses2.statusCode ?? 500);
|
|
7526
|
+
}
|
|
7527
|
+
if (responses2 instanceof HttpException) {
|
|
7528
|
+
context.reply.status(responses2.statusCode ?? 500);
|
|
7529
|
+
}
|
|
7462
7530
|
context.reply.send(responses2);
|
|
7463
7531
|
} catch (e) {
|
|
7464
|
-
Logger.error("Failed to handle
|
|
7532
|
+
Logger.error("Failed to execute handle", e.message ?? e);
|
|
7465
7533
|
if (this.config.develop) {
|
|
7466
7534
|
console.error(e);
|
|
7467
7535
|
}
|
|
7536
|
+
context.reply.status(500);
|
|
7537
|
+
context.reply.send({ error: true, statusCode: 500, data: null });
|
|
7468
7538
|
}
|
|
7469
7539
|
};
|
|
7470
|
-
|
|
7471
|
-
|
|
7540
|
+
try {
|
|
7541
|
+
await this.root.middleware.run(ctx, handler2);
|
|
7542
|
+
await this.root.hooks.run("onResponse", ctx);
|
|
7543
|
+
} catch (err) {
|
|
7544
|
+
if (err instanceof HttpException || err instanceof ThrowableResponse) {
|
|
7545
|
+
Logger.error(`Server error`, err.message ?? err);
|
|
7546
|
+
ctx.reply.status(err.statusCode ?? 500);
|
|
7547
|
+
return ctx.reply.send(err.render());
|
|
7548
|
+
}
|
|
7549
|
+
ctx.reply.send({
|
|
7550
|
+
statusCode: 500,
|
|
7551
|
+
error: true,
|
|
7552
|
+
message: err.message ?? err,
|
|
7553
|
+
data: null
|
|
7554
|
+
});
|
|
7555
|
+
}
|
|
7472
7556
|
}
|
|
7473
7557
|
}
|
|
7474
7558
|
// source/bin/cli-tools.ts
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@ import {Security, bodyParserPlugin} from "../framework/plugins";
|
|
|
2
2
|
import {PluginScope} from './plugins/scope'
|
|
3
3
|
import {RequestContext} from './context'
|
|
4
4
|
import {ApplicationConfigInterface, ApplicationInterface} from "../types/application";
|
|
5
|
-
import {HttpMethod} from "../framework";
|
|
5
|
+
import {HttpException, HttpMethod, ThrowableResponse} from "../framework";
|
|
6
6
|
import {RouteHandlerCallable} from "../types";
|
|
7
7
|
import {Logger} from "@protorians/logger";
|
|
8
8
|
import {RaitonConfig} from "./config";
|
|
@@ -14,7 +14,7 @@ export class Application implements ApplicationInterface {
|
|
|
14
14
|
|
|
15
15
|
readonly version: string = RaitonConfig.get('version') || '0.0.1'
|
|
16
16
|
|
|
17
|
-
static get container(): typeof Injection{
|
|
17
|
+
static get container(): typeof Injection {
|
|
18
18
|
return Injection;
|
|
19
19
|
}
|
|
20
20
|
|
|
@@ -162,16 +162,39 @@ export class Application implements ApplicationInterface {
|
|
|
162
162
|
(context as any).params = route.parameters;
|
|
163
163
|
let responses = await route.handler(context)
|
|
164
164
|
|
|
165
|
+
if (responses instanceof ThrowableResponse) {
|
|
166
|
+
context.reply.status(responses.statusCode ?? 500)
|
|
167
|
+
}
|
|
168
|
+
if (responses instanceof HttpException) {
|
|
169
|
+
context.reply.status(responses.statusCode ?? 500)
|
|
170
|
+
}
|
|
171
|
+
|
|
165
172
|
context.reply.send(responses)
|
|
166
173
|
} catch (e: any) {
|
|
167
|
-
Logger.error('Failed to handle
|
|
174
|
+
Logger.error('Failed to execute handle', e.message ?? e)
|
|
168
175
|
if (this.config.develop) {
|
|
169
176
|
console.error(e)
|
|
170
177
|
}
|
|
178
|
+
context.reply.status(500)
|
|
179
|
+
context.reply.send({error: true, statusCode: 500, data: null})
|
|
171
180
|
}
|
|
172
181
|
}
|
|
173
182
|
|
|
174
|
-
|
|
175
|
-
|
|
183
|
+
try {
|
|
184
|
+
await this.root.middleware.run(ctx, handler)
|
|
185
|
+
await this.root.hooks.run('onResponse', ctx)
|
|
186
|
+
} catch (err: any) {
|
|
187
|
+
if (err instanceof HttpException || err instanceof ThrowableResponse) {
|
|
188
|
+
Logger.error(`Server error`, err.message ?? err);
|
|
189
|
+
ctx.reply.status(err.statusCode ?? 500)
|
|
190
|
+
return ctx.reply.send(err.render())
|
|
191
|
+
}
|
|
192
|
+
ctx.reply.send({
|
|
193
|
+
statusCode: 500,
|
|
194
|
+
error: true,
|
|
195
|
+
message: err.message ?? err,
|
|
196
|
+
data: null
|
|
197
|
+
})
|
|
198
|
+
}
|
|
176
199
|
}
|
|
177
200
|
}
|
|
@@ -25,17 +25,11 @@ export function createHandler(
|
|
|
25
25
|
return responses;
|
|
26
26
|
} catch (err: any) {
|
|
27
27
|
|
|
28
|
-
if (
|
|
28
|
+
if (err instanceof HttpException || err instanceof ThrowableResponse) {
|
|
29
29
|
Logger.error(`Failed to execute ${handlerName} handler`, err.message ?? err);
|
|
30
|
-
ctx.reply.status(500)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (err instanceof ThrowableResponse) {
|
|
34
|
-
ctx.reply.status(err.statusCode || 201)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (err instanceof HttpException || err instanceof ThrowableResponse)
|
|
30
|
+
ctx.reply.status(err.statusCode ?? 500)
|
|
38
31
|
return err.render()
|
|
32
|
+
}
|
|
39
33
|
|
|
40
34
|
return {
|
|
41
35
|
statusCode: 500,
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import {MiddlewareCallable, ParamMetaInterface, RouteMetaInterface} from "../../types";
|
|
2
2
|
import {middlewareCompose} from "../../core";
|
|
3
3
|
import {validate} from "class-validator";
|
|
4
|
-
import {parseCookie} from "
|
|
5
|
-
import {DataTransferObject, METADATA_KEYS, Parametrable, Throwable, ViewModel} from "@/framework";
|
|
4
|
+
import {DataTransferObject, METADATA_KEYS, Parametrable, parseCookie, Throwable, ViewModel} from "../../framework";
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* Helper function for collecting arguments from route parameters
|
|
@@ -6,4 +6,5 @@ export * from "./parametrable.decorator"
|
|
|
6
6
|
export * from "./injection.decorator"
|
|
7
7
|
export * from "./guard.decorator"
|
|
8
8
|
export * from "./api-response.decorator"
|
|
9
|
-
export * from "./api.decorator"
|
|
9
|
+
export * from "./api.decorator"
|
|
10
|
+
export * from "./route-interaction.decorator"
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import {METADATA_KEYS} from "../constants/decorators.constant";
|
|
3
|
+
import {getControllerMetadata} from "../../core/controller";
|
|
4
|
+
import {RouteInteractionsSubscriber} from "../../types/router";
|
|
5
|
+
import { Raiton } from "../../core/raiton";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Represents a route interaction that can be rendered with context data
|
|
9
|
+
*/
|
|
10
|
+
export class RouteInteractionDescriptor {
|
|
11
|
+
constructor(private template: string) {
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Renders the interaction template with the provided context data
|
|
16
|
+
* Supports nested object paths using dot notation (e.g., [user.firstname])
|
|
17
|
+
* @param context Object containing values for template placeholders
|
|
18
|
+
* @returns Rendered interaction string with placeholders replaced by context values
|
|
19
|
+
*/
|
|
20
|
+
render(context: Record<string, any> = {}): string {
|
|
21
|
+
let result = this.template;
|
|
22
|
+
|
|
23
|
+
// Extract all placeholders from the template
|
|
24
|
+
const placeholderRegex = /\[([^\]]+)\]/g;
|
|
25
|
+
let match;
|
|
26
|
+
|
|
27
|
+
while ((match = placeholderRegex.exec(this.template)) !== null) {
|
|
28
|
+
const placeholder = match[0];
|
|
29
|
+
const path = match[1];
|
|
30
|
+
|
|
31
|
+
// Get the value from context using dot notation (e.g., user.firstname)
|
|
32
|
+
const value = this.getNestedValue(context, path);
|
|
33
|
+
const stringValue = value !== null && value !== undefined ? String(value) : '';
|
|
34
|
+
|
|
35
|
+
// result = result.replace(new RegExp(`\\${placeholder.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}`, 'g'), stringValue);
|
|
36
|
+
result = result.replace(new RegExp(placeholder.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'g'), stringValue);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Get a nested value from an object using dot notation
|
|
44
|
+
* @param obj The object to traverse
|
|
45
|
+
* @param path The dot-notation path (e.g., "user.firstname")
|
|
46
|
+
* @returns The value at the path, or undefined if not found
|
|
47
|
+
*/
|
|
48
|
+
private getNestedValue(obj: Record<string, any>, path: string): any {
|
|
49
|
+
return path.split('.').reduce((current, key) => {
|
|
50
|
+
return current?.[key];
|
|
51
|
+
}, obj);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Get the raw template string
|
|
56
|
+
*/
|
|
57
|
+
getTemplate(): string {
|
|
58
|
+
return this.template;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Global registry of route interactions indexed by their full paths
|
|
64
|
+
*/
|
|
65
|
+
class RouteInteractionsRegistry {
|
|
66
|
+
private static readonly interactions = new Map<string, RouteInteractionDescriptor>();
|
|
67
|
+
public static readonly subscribers = new Set<RouteInteractionsSubscriber>();
|
|
68
|
+
|
|
69
|
+
static subscribe(target: any, propertyKey: string) {
|
|
70
|
+
this.subscribers.add({target, propertyKey});
|
|
71
|
+
return this;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Register a route interaction
|
|
76
|
+
* @param fullPath The complete route path (prefix + method path)
|
|
77
|
+
* @param descriptor The route interaction descriptor
|
|
78
|
+
*/
|
|
79
|
+
static register(fullPath: string, descriptor: RouteInteractionDescriptor): typeof this {
|
|
80
|
+
this.interactions.set(fullPath, descriptor);
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Get a route interaction by its full path
|
|
86
|
+
* @param fullPath The complete route path
|
|
87
|
+
* @returns The interaction descriptor, or undefined if not found
|
|
88
|
+
*/
|
|
89
|
+
static get(fullPath: string): RouteInteractionDescriptor | undefined {
|
|
90
|
+
return this.interactions.get(fullPath);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Get all registered interactions
|
|
95
|
+
*/
|
|
96
|
+
static getAll(): Map<string, RouteInteractionDescriptor> {
|
|
97
|
+
return new Map(this.interactions);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Clear all registered interactions
|
|
102
|
+
*/
|
|
103
|
+
static clear(): void {
|
|
104
|
+
this.interactions.clear();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Check if an interaction is registered
|
|
109
|
+
*/
|
|
110
|
+
static has(fullPath: string): boolean {
|
|
111
|
+
return this.interactions.has(fullPath);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Public API for accessing route interactions
|
|
117
|
+
*/
|
|
118
|
+
export class RouteInteractions {
|
|
119
|
+
/**
|
|
120
|
+
* Get a route interaction by its full path
|
|
121
|
+
* @param path The complete route path (e.g., "/auth/sign-in/index")
|
|
122
|
+
* @returns The interaction descriptor with a render method, or undefined if not found
|
|
123
|
+
*/
|
|
124
|
+
static get(path: string): RouteInteractionDescriptor | undefined {
|
|
125
|
+
return RouteInteractionsRegistry.get(path) || this.upsert(path);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Get all registered route interactions
|
|
130
|
+
*/
|
|
131
|
+
static getAll(): Map<string, RouteInteractionDescriptor> {
|
|
132
|
+
return RouteInteractionsRegistry.getAll();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
private static upsert(pathname: string): RouteInteractionDescriptor | undefined {
|
|
136
|
+
const subscribers = RouteInteractionsRegistry.subscribers.values();
|
|
137
|
+
|
|
138
|
+
for (const subscriber of subscribers) {
|
|
139
|
+
const controller = getControllerMetadata(subscriber.target);
|
|
140
|
+
if (!controller) continue;
|
|
141
|
+
|
|
142
|
+
const route = controller.routes.find(r => r.propertyKey === subscriber.propertyKey);
|
|
143
|
+
|
|
144
|
+
if (!route) continue;
|
|
145
|
+
|
|
146
|
+
const interactions = Reflect.getMetadata(METADATA_KEYS.ROUTE_INTERACTION, subscriber.target)
|
|
147
|
+
if (!interactions) continue;
|
|
148
|
+
|
|
149
|
+
const description = interactions[subscriber.propertyKey]?.description ?? undefined;
|
|
150
|
+
if (!description) continue;
|
|
151
|
+
|
|
152
|
+
const appPrefix = Raiton.thread?.application?.config.prefix
|
|
153
|
+
const fullPath = appPrefix + (controller.prefix || '') + route.path;
|
|
154
|
+
|
|
155
|
+
if(fullPath !== pathname) continue;
|
|
156
|
+
|
|
157
|
+
const descriptor = new RouteInteractionDescriptor(description);
|
|
158
|
+
RouteInteractionsRegistry.register(fullPath, descriptor);
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
return descriptor;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return undefined;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Decorator to add interaction description to a route method
|
|
170
|
+
* @param description The interaction description template (e.g., "[user] est désormais connecté")
|
|
171
|
+
*/
|
|
172
|
+
export function RouteInteraction(description: string) {
|
|
173
|
+
return (target: any, propertyKey: string) => {
|
|
174
|
+
RouteInteractionsRegistry.subscribe(target, propertyKey);
|
|
175
|
+
|
|
176
|
+
// Also store it in metadata for reference during development/inspection
|
|
177
|
+
const interactions = Reflect.getMetadata(METADATA_KEYS.ROUTE_INTERACTION, target) || {};
|
|
178
|
+
interactions[propertyKey] = {
|
|
179
|
+
description,
|
|
180
|
+
// fullPath,
|
|
181
|
+
// descriptor,
|
|
182
|
+
};
|
|
183
|
+
Reflect.defineMetadata(METADATA_KEYS.ROUTE_INTERACTION, interactions, target);
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// Export the registry for internal use and testing
|
|
188
|
+
export {RouteInteractionsRegistry};
|
|
@@ -24,18 +24,18 @@ function createSocketEventDecorator(type: SocketEventType, name?: string) {
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
export function
|
|
27
|
+
export function OnSocketConnect() {
|
|
28
28
|
return createSocketEventDecorator('connect')
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
export function
|
|
31
|
+
export function OnSocketDisconnect() {
|
|
32
32
|
return createSocketEventDecorator('disconnect')
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
export function
|
|
35
|
+
export function OnSocketMessage(name?: string) {
|
|
36
36
|
return createSocketEventDecorator('message', name)
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
export function
|
|
39
|
+
export function OnSocketEvent(name: string) {
|
|
40
40
|
return createSocketEventDecorator('event', name)
|
|
41
41
|
}
|
|
@@ -7,14 +7,31 @@ export class HttpException extends Error {
|
|
|
7
7
|
constructor(
|
|
8
8
|
error: string | HttpResponseBaseInterface | Error,
|
|
9
9
|
public statusCode: HttpStatus = HttpStatus.INTERNAL_SERVER_ERROR,
|
|
10
|
+
public errorCode: number | string | symbol | undefined = undefined,
|
|
10
11
|
) {
|
|
11
12
|
super(typeof error === 'string' ? error : error.message);
|
|
12
13
|
}
|
|
13
14
|
|
|
15
|
+
setStatus(statusCode: HttpStatus) {
|
|
16
|
+
this.statusCode = statusCode;
|
|
17
|
+
return this;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
setErrorCode(code: number | string | symbol | undefined) {
|
|
21
|
+
this.errorCode = code;
|
|
22
|
+
return this;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
setMessage(error: string | HttpResponseBaseInterface | Error) {
|
|
26
|
+
this.message = typeof error === 'string' ? error : error.message;
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
|
|
14
30
|
render() {
|
|
15
31
|
return {
|
|
16
32
|
message: this.message,
|
|
17
33
|
statusCode: this.statusCode,
|
|
34
|
+
errorCode: this.errorCode,
|
|
18
35
|
error: true,
|
|
19
36
|
stack: Raiton.thread?.builder?.options?.serve
|
|
20
37
|
? this.stack?.split('\n').map(e => e.trim())
|
package/source/types/router.ts
CHANGED
package/source/types/thread.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {BuilderInterface} from "./builder";
|
|
2
|
-
import {RuntimeAdapterInterface} from "./runtime";
|
|
2
|
+
import {RuntimeAdapterInterface, RuntimeServerInterface} from "./runtime";
|
|
3
3
|
import {ApplicationInterface} from "./application";
|
|
4
4
|
import {RuntimeType} from "../framework/enums/runtime.enum";
|
|
5
5
|
|
|
@@ -13,6 +13,9 @@ export type ThreadWaitCallable = () => (boolean | Promise<boolean>)
|
|
|
13
13
|
export interface ThreadInterface {
|
|
14
14
|
readonly appDir: string;
|
|
15
15
|
readonly builder: BuilderInterface;
|
|
16
|
+
application: ApplicationInterface | null;
|
|
17
|
+
runtime: RuntimeAdapterInterface | null;
|
|
18
|
+
runtimeServer: RuntimeServerInterface | null;
|
|
16
19
|
|
|
17
20
|
setup(options: ThreadSetupOptionsInterface): this
|
|
18
21
|
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { Controller, Get } from '@protorians/framework';
|
|
2
|
-
import { ApiOkResponse, ApiCreatedResponse, ApiBadRequestResponse, ApiResponse } from '@protorians/framework/decorators';
|
|
3
|
-
|
|
4
|
-
@Controller('/users')
|
|
5
|
-
export class UserController {
|
|
6
|
-
// Example 1: Using ApiOkResponse to specify a 200 response with a specific type
|
|
7
|
-
@Get()
|
|
8
|
-
@ApiOkResponse({
|
|
9
|
-
description='Returns a list of users',
|
|
10
|
-
type: Array,
|
|
11
|
-
isArray: true
|
|
12
|
-
})
|
|
13
|
-
async getUsers() {
|
|
14
|
-
return [{ id: 1, name: 'John Doe' }, { id: 2, name: 'Jane Smith' }];
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// Example 2: Using ApiCreatedResponse for a POST endpoint (would need @Post decorator)
|
|
18
|
-
// @Post()
|
|
19
|
-
// @ApiCreatedResponse({
|
|
20
|
-
// description='User created successfully',
|
|
21
|
-
// type: Object
|
|
22
|
-
// })
|
|
23
|
-
// async createUser() {
|
|
24
|
-
// // ... implementation
|
|
25
|
-
// }
|
|
26
|
-
|
|
27
|
-
// Example 3: Using ApiResponse for multiple response types
|
|
28
|
-
@Get('/:id')
|
|
29
|
-
@ApiResponse({
|
|
30
|
-
status: 200,
|
|
31
|
-
description='Returns the user if found',
|
|
32
|
-
type: Object
|
|
33
|
-
})
|
|
34
|
-
@ApiResponse({
|
|
35
|
-
status: 404,
|
|
36
|
-
description='User not found'
|
|
37
|
-
})
|
|
38
|
-
@ApiResponse({
|
|
39
|
-
status: 500,
|
|
40
|
-
description='Internal server error'
|
|
41
|
-
})
|
|
42
|
-
async getUserById() {
|
|
43
|
-
// ... implementation
|
|
44
|
-
return { id: 1, name: 'John Doe' };
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// Example 4: Using the shorthand decorators
|
|
48
|
-
@Get('/health')
|
|
49
|
-
@ApiOkResponse({ description='API is healthy' })
|
|
50
|
-
async healthCheck() {
|
|
51
|
-
return { status: 'OK' };
|
|
52
|
-
}
|
|
53
|
-
}
|