@stacksjs/bun-router 0.0.19 → 0.0.21
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/dist/chunk-1ahs68ys.js +18 -0
- package/dist/{chunk-y3xq6wq6.js → chunk-cgptvjdf.js} +1 -1
- package/dist/chunk-g3ybefhg.js +1923 -0
- package/dist/cli.js +3 -3
- package/dist/container/index.js +211 -1149
- package/dist/index.js +2222 -366
- package/dist/types.d.ts +5 -0
- package/package.json +1 -2
- package/dist/chunk-2mx7fq49.js +0 -4
- package/dist/chunk-a8p83068.js +0 -103
package/dist/types.d.ts
CHANGED
|
@@ -695,6 +695,11 @@ export interface EnhancedRequest extends Request, Omit<RequestMacroMethods, 'ip'
|
|
|
695
695
|
* `$request->route('name')` ergonomics.
|
|
696
696
|
*/
|
|
697
697
|
getParam: <T = string>(name: string, defaultValue?: T) => T | undefined;
|
|
698
|
+
/**
|
|
699
|
+
* Read a route parameter as a safe integer. Missing, fractional, and
|
|
700
|
+
* otherwise invalid numeric values return null.
|
|
701
|
+
*/
|
|
702
|
+
getParamAsInt: (name: string) => number | null;
|
|
698
703
|
/**
|
|
699
704
|
* Query parameters from the URL
|
|
700
705
|
*/
|
package/package.json
CHANGED
package/dist/chunk-2mx7fq49.js
DELETED
package/dist/chunk-a8p83068.js
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
// src/errors/exceptions.ts
|
|
3
|
-
class RouterException extends Error {
|
|
4
|
-
code;
|
|
5
|
-
statusCode;
|
|
6
|
-
context;
|
|
7
|
-
retryable;
|
|
8
|
-
severity;
|
|
9
|
-
category;
|
|
10
|
-
timestamp;
|
|
11
|
-
cause;
|
|
12
|
-
constructor(details) {
|
|
13
|
-
super(details.message);
|
|
14
|
-
this.name = this.constructor.name;
|
|
15
|
-
this.code = details.code;
|
|
16
|
-
this.statusCode = details.statusCode || 500;
|
|
17
|
-
this.context = details.context || {};
|
|
18
|
-
this.retryable = details.retryable || false;
|
|
19
|
-
this.severity = details.severity || "medium";
|
|
20
|
-
this.category = details.category || "system";
|
|
21
|
-
this.timestamp = new Date;
|
|
22
|
-
this.cause = details.cause;
|
|
23
|
-
if (Error.captureStackTrace) {
|
|
24
|
-
Error.captureStackTrace(this, this.constructor);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
toJSON() {
|
|
28
|
-
return {
|
|
29
|
-
name: this.name,
|
|
30
|
-
code: this.code,
|
|
31
|
-
message: this.message,
|
|
32
|
-
statusCode: this.statusCode,
|
|
33
|
-
context: this.context,
|
|
34
|
-
retryable: this.retryable,
|
|
35
|
-
severity: this.severity,
|
|
36
|
-
category: this.category,
|
|
37
|
-
timestamp: this.timestamp.toISOString(),
|
|
38
|
-
stack: this.stack,
|
|
39
|
-
cause: this.cause ? {
|
|
40
|
-
name: this.cause.name,
|
|
41
|
-
message: this.cause.message,
|
|
42
|
-
stack: this.cause.stack
|
|
43
|
-
} : undefined
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
toResponse() {
|
|
47
|
-
const body = {
|
|
48
|
-
error: {
|
|
49
|
-
code: this.code,
|
|
50
|
-
message: this.message,
|
|
51
|
-
statusCode: this.statusCode,
|
|
52
|
-
timestamp: this.timestamp.toISOString(),
|
|
53
|
-
requestId: this.context.requestId
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
return new Response(JSON.stringify(body), {
|
|
57
|
-
status: this.statusCode,
|
|
58
|
-
headers: {
|
|
59
|
-
"Content-Type": "application/json",
|
|
60
|
-
"X-Error-Code": this.code,
|
|
61
|
-
"X-Request-ID": this.context.requestId || ""
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
class ValidationException extends RouterException {
|
|
68
|
-
fields;
|
|
69
|
-
constructor(message, fields = {}, context) {
|
|
70
|
-
super({
|
|
71
|
-
code: "VALIDATION_ERROR",
|
|
72
|
-
message,
|
|
73
|
-
statusCode: 400,
|
|
74
|
-
context,
|
|
75
|
-
retryable: false,
|
|
76
|
-
severity: "low",
|
|
77
|
-
category: "validation"
|
|
78
|
-
});
|
|
79
|
-
this.fields = fields;
|
|
80
|
-
}
|
|
81
|
-
toResponse() {
|
|
82
|
-
const body = {
|
|
83
|
-
error: {
|
|
84
|
-
code: this.code,
|
|
85
|
-
message: this.message,
|
|
86
|
-
statusCode: this.statusCode,
|
|
87
|
-
timestamp: this.timestamp.toISOString(),
|
|
88
|
-
requestId: this.context.requestId,
|
|
89
|
-
fields: this.fields
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
return new Response(JSON.stringify(body), {
|
|
93
|
-
status: this.statusCode,
|
|
94
|
-
headers: {
|
|
95
|
-
"Content-Type": "application/json",
|
|
96
|
-
"X-Error-Code": this.code,
|
|
97
|
-
"X-Request-ID": this.context.requestId || ""
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export { RouterException, ValidationException };
|