@supacloud/elysia 0.8.0 → 0.8.1
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/README.md +11 -3
- package/dist/index.js +16 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -26,7 +26,8 @@ Runtime adapter that turns `@supacloud/compiler` output into a production-ready
|
|
|
26
26
|
performed.
|
|
27
27
|
- **Public error mapping**: transforms framework / application errors via
|
|
28
28
|
`errorMapper` with standard `ApplicationError` envelope support, preserving
|
|
29
|
-
|
|
29
|
+
HTTP 422 for request validation and HTTP 500 / `RESPONSE_VALIDATION_ERROR`
|
|
30
|
+
for invalid handler output, without exposing payloads or schema internals.
|
|
30
31
|
|
|
31
32
|
## Installation
|
|
32
33
|
|
|
@@ -83,8 +84,15 @@ sandbox.reset();
|
|
|
83
84
|
|
|
84
85
|
Route `body`, `params`, `query`, and `response` schemas are enforced by
|
|
85
86
|
Elysia before and after the handler. Invalid input returns the standard `422`
|
|
86
|
-
validation response; invalid handler output
|
|
87
|
-
|
|
87
|
+
validation response; invalid structured handler output returns HTTP 500 with
|
|
88
|
+
`RESPONSE_VALIDATION_ERROR`. A response validation failure can occur **after a
|
|
89
|
+
command has committed**; it does not imply rollback and must not trigger a blind
|
|
90
|
+
write retry. Confirm the outcome using the application's durable receipt or
|
|
91
|
+
read-back protocol. A custom `errorMapper` can override this public envelope.
|
|
92
|
+
|
|
93
|
+
Native `Response` objects are passed through by Elysia, including JSON responses.
|
|
94
|
+
Handlers returning a native `Response` must validate their JSON payload before
|
|
95
|
+
constructing it. The adapter does not consume or parse binary/streaming responses.
|
|
88
96
|
|
|
89
97
|
Jobs are executed explicitly with `executeJob(compiledModule, services, job,
|
|
90
98
|
input, requestContext)`. The asynchronous compiler-generated job scope is
|
package/dist/index.js
CHANGED
|
@@ -572,6 +572,15 @@ function createModulePlugin(compiled, services, ctxFactory = defaultRequestConte
|
|
|
572
572
|
requestContexts.set(request, requestContext);
|
|
573
573
|
return { requestContext };
|
|
574
574
|
});
|
|
575
|
+
plugin.onError(async ({ code, error, request }) => {
|
|
576
|
+
const context = {
|
|
577
|
+
request,
|
|
578
|
+
requestContext: requestContexts.get(request),
|
|
579
|
+
frameworkCode: code
|
|
580
|
+
};
|
|
581
|
+
const mapped = await options.errorMapper?.(error, context);
|
|
582
|
+
return mapped ?? defaultErrorResponse(error, code);
|
|
583
|
+
});
|
|
575
584
|
for (const controller of compiled.controllers) {
|
|
576
585
|
for (const route of controller.routes) {
|
|
577
586
|
const path = joinPaths(controller.path, route.path);
|
|
@@ -683,15 +692,6 @@ function createModulePlugin(compiled, services, ctxFactory = defaultRequestConte
|
|
|
683
692
|
}
|
|
684
693
|
}
|
|
685
694
|
}
|
|
686
|
-
plugin.onError({ as: "global" }, async ({ code, error, request }) => {
|
|
687
|
-
const context = {
|
|
688
|
-
request,
|
|
689
|
-
requestContext: requestContexts.get(request),
|
|
690
|
-
frameworkCode: code
|
|
691
|
-
};
|
|
692
|
-
const mapped = await options.errorMapper?.(error, context);
|
|
693
|
-
return mapped ?? defaultErrorResponse(error, code);
|
|
694
|
-
});
|
|
695
695
|
return plugin;
|
|
696
696
|
}
|
|
697
697
|
async function executeJob(compiled, services, job, input, requestContext, imported = {}, executor) {
|
|
@@ -738,6 +738,13 @@ function defaultErrorResponse(error, frameworkCode) {
|
|
|
738
738
|
}, { status: error.status });
|
|
739
739
|
}
|
|
740
740
|
if (frameworkCode === "VALIDATION") {
|
|
741
|
+
if (isRecord(error) && error.type === "response") {
|
|
742
|
+
return Response.json({
|
|
743
|
+
ok: false,
|
|
744
|
+
code: "RESPONSE_VALIDATION_ERROR",
|
|
745
|
+
message: "Response validation failed"
|
|
746
|
+
}, { status: 500 });
|
|
747
|
+
}
|
|
741
748
|
return Response.json({
|
|
742
749
|
ok: false,
|
|
743
750
|
code: "VALIDATION_ERROR",
|
package/package.json
CHANGED