@stacksjs/bun-router 0.0.18 → 0.0.19
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-2mx7fq49.js +4 -0
- package/dist/chunk-a8p83068.js +103 -0
- package/dist/{chunk-cgptvjdf.js → chunk-y3xq6wq6.js} +1 -1
- package/dist/cli.js +4 -3
- package/dist/container/index.js +1149 -211
- package/dist/index.js +369 -2209
- package/package.json +6 -5
- package/dist/chunk-1ahs68ys.js +0 -18
- package/dist/chunk-g3ybefhg.js +0 -1923
|
@@ -0,0 +1,103 @@
|
|
|
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 };
|
package/dist/cli.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
1
2
|
// @bun
|
|
2
3
|
import {
|
|
3
4
|
middleware
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import"./chunk-
|
|
5
|
+
} from "./chunk-y3xq6wq6.js";
|
|
6
|
+
import"./chunk-2mx7fq49.js";
|
|
6
7
|
|
|
7
8
|
// src/cli/index.ts
|
|
8
9
|
import process15 from "process";
|
|
@@ -2046,7 +2047,7 @@ function getPrefix() {
|
|
|
2046
2047
|
}
|
|
2047
2048
|
var prefix = getPrefix();
|
|
2048
2049
|
// package.json
|
|
2049
|
-
var version = "0.0.
|
|
2050
|
+
var version = "0.0.19";
|
|
2050
2051
|
|
|
2051
2052
|
// src/cli/middleware.ts
|
|
2052
2053
|
import fs2 from "fs/promises";
|