@supacloud/elysia 0.29.2 → 0.30.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 +5 -5
- package/compatibility.json +4 -4
- package/dist/framework.d.ts +2 -2
- package/dist/http-telemetry.d.ts +8 -2
- package/dist/index.d.ts +12 -12
- package/dist/index.js +22 -13
- package/package.json +16 -16
package/README.md
CHANGED
|
@@ -8,11 +8,11 @@ is a separately authorized business command, never an assumed rollback.
|
|
|
8
8
|
|
|
9
9
|
## Compatibility and Acceptance Boundary
|
|
10
10
|
|
|
11
|
-
The Elysia peer and development dependency are pinned to `2.0.0-beta.
|
|
12
|
-
The runtime adapter pins Effect `4.0.
|
|
11
|
+
The Elysia peer and development dependency are pinned to `2.0.0-beta.32`.
|
|
12
|
+
The runtime adapter pins Effect `4.0.5` and consumes its `Exit`-based
|
|
13
13
|
execution boundary.
|
|
14
|
-
`compatibility.json` records the acceptance target: Bun 1.4.
|
|
15
|
-
2.0.0-beta.
|
|
14
|
+
`compatibility.json` records the acceptance target: Bun 1.4.3, Elysia
|
|
15
|
+
2.0.0-beta.32, Effect 4.0.5, `typebox` 1.3.37, `exact-mirror` 1.2.6,
|
|
16
16
|
TypeScript CLI 7.0.2 and the compiler's separate TypeScript 6 semantic API 6.0.2.
|
|
17
17
|
The matrix is a
|
|
18
18
|
required target, not proof of an execution. See the dated, commit-specific
|
|
@@ -319,7 +319,7 @@ Runtime adapter that turns `@supacloud/compiler` output into a production-ready
|
|
|
319
319
|
## Installation
|
|
320
320
|
|
|
321
321
|
```bash
|
|
322
|
-
bun add --exact @supacloud/elysia elysia@2.0.0-beta.
|
|
322
|
+
bun add --exact @supacloud/elysia elysia@2.0.0-beta.32
|
|
323
323
|
```
|
|
324
324
|
|
|
325
325
|
## Usage
|
package/compatibility.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
|
-
"bun": "1.4.
|
|
2
|
+
"bun": "1.4.3",
|
|
3
3
|
"packages": {
|
|
4
|
-
"elysia": "2.0.0-beta.
|
|
5
|
-
"effect": "4.0.
|
|
4
|
+
"elysia": "2.0.0-beta.32",
|
|
5
|
+
"effect": "4.0.5",
|
|
6
6
|
"typescript": "7.0.2",
|
|
7
|
-
"typebox": "1.3.
|
|
7
|
+
"typebox": "1.3.37",
|
|
8
8
|
"exact-mirror": "1.2.6",
|
|
9
9
|
"@typescript/typescript6": "6.0.2"
|
|
10
10
|
}
|
package/dist/framework.d.ts
CHANGED
|
@@ -29,8 +29,8 @@ export declare function createSupaCloudFramework<const Http extends AnyElysia =
|
|
|
29
29
|
macro: (import("elysia").DefaultMetadata & Http["~Metadata"])["macro"];
|
|
30
30
|
macroFn: (import("elysia").DefaultMetadata & Http["~Metadata"])["macroFn"];
|
|
31
31
|
parser: (import("elysia").DefaultMetadata & Http["~Metadata"])["parser"];
|
|
32
|
-
response: import("elysia/types").UnionResponseStatus<(import("elysia").DefaultMetadata & Http["~Metadata"])["response"], import("elysia/types").UnionResponseStatus<
|
|
33
|
-
},
|
|
32
|
+
response: import("elysia/types").UnionResponseStatus<(import("elysia").DefaultMetadata & Http["~Metadata"])["response"], import("elysia/types").UnionResponseStatus<Http["~Ephemeral"]["response"], {}>>;
|
|
33
|
+
}, {} & Http["~Routes"], import("elysia").DefaultEphemeral, {
|
|
34
34
|
derive: {};
|
|
35
35
|
schema: {};
|
|
36
36
|
schemas: {};
|
package/dist/http-telemetry.d.ts
CHANGED
|
@@ -16,12 +16,18 @@ export declare function createHttpTelemetry(observe: HttpTelemetryObserver): Ely
|
|
|
16
16
|
derive: {};
|
|
17
17
|
}, {
|
|
18
18
|
typebox: {};
|
|
19
|
-
error: [
|
|
19
|
+
error: [{
|
|
20
|
+
error: Error;
|
|
21
|
+
response: {};
|
|
22
|
+
passes: true;
|
|
23
|
+
'~return': undefined;
|
|
24
|
+
'~catchAll': true;
|
|
25
|
+
}];
|
|
20
26
|
}, {
|
|
21
27
|
schema: {};
|
|
22
28
|
schemas: {};
|
|
23
29
|
macro: {};
|
|
24
30
|
macroFn: {};
|
|
25
31
|
parser: {};
|
|
26
|
-
response:
|
|
32
|
+
response: import("elysia/types").ExtractErrorFromHandle<undefined>;
|
|
27
33
|
}, {}, import("elysia").DefaultEphemeral, import("elysia").DefaultEphemeral>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Elysia, type AnyElysia, type Context, type StatusMap } from "elysia";
|
|
2
2
|
import type { CommandRuntimeAudit, CommandRuntimeAuthorizer, CommandRuntimeGovernance, CommandRuntimeInvocation, CommandRuntimeMiddleware } from "@supacloud/app";
|
|
3
3
|
import { PendingWorkRegistry } from "@supacloud/app/runtime";
|
|
4
|
-
import { type CommandPreview } from "@supacloud/contracts";
|
|
4
|
+
import { type CommandPreview, type ErrorMetadata } from "@supacloud/contracts";
|
|
5
5
|
import { type HttpPolicyRegistry } from "./http-policy";
|
|
6
6
|
export { HttpPolicyConfigurationError } from "./http-policy";
|
|
7
7
|
export type { HttpPolicy, HttpPolicyContext, HttpPolicyResponseContext, HttpPolicyDeclaration, HttpPolicyRegistry } from "./http-policy";
|
|
@@ -221,18 +221,21 @@ export interface ApplicationErrorOptions {
|
|
|
221
221
|
status?: number;
|
|
222
222
|
code?: string;
|
|
223
223
|
details?: unknown;
|
|
224
|
+
metadata?: ErrorMetadata;
|
|
224
225
|
}
|
|
225
226
|
export interface PublicApplicationError extends Error {
|
|
226
227
|
readonly expose: true;
|
|
227
228
|
readonly status: number;
|
|
228
229
|
readonly code: string;
|
|
229
230
|
readonly details?: unknown;
|
|
231
|
+
readonly metadata?: ErrorMetadata;
|
|
230
232
|
}
|
|
231
233
|
export declare class ApplicationError extends Error implements PublicApplicationError {
|
|
232
234
|
readonly expose: true;
|
|
233
235
|
readonly status: number;
|
|
234
236
|
readonly code: string;
|
|
235
237
|
readonly details?: unknown;
|
|
238
|
+
readonly metadata?: ErrorMetadata;
|
|
236
239
|
constructor(message: string, options?: ApplicationErrorOptions);
|
|
237
240
|
}
|
|
238
241
|
export type JsonResponseValidator<T> = (value: unknown) => value is T;
|
|
@@ -252,7 +255,7 @@ export interface ErrorContext {
|
|
|
252
255
|
*
|
|
253
256
|
* Declaring the runtime classes here lets Elysia's type system (and therefore
|
|
254
257
|
* Eden Treaty / generated clients) know these errors are *handled*: the generic
|
|
255
|
-
* `.
|
|
258
|
+
* `.onError(handler)` catch-all no longer widens every route's response schema
|
|
256
259
|
* with an untyped fallback. Each entry also documents the public `code` served
|
|
257
260
|
* by {@link defaultErrorResponse} when a caller does not install an
|
|
258
261
|
* `errorMapper`.
|
|
@@ -396,16 +399,13 @@ export declare function createModulePlugin<const Services extends Record<string,
|
|
|
396
399
|
}, {
|
|
397
400
|
typebox: {} & Http["~Definitions"]["typebox"];
|
|
398
401
|
error: [...Http["~Definitions"]["error"]];
|
|
399
|
-
}, import("elysia").DefaultMetadata & Http["~Metadata"],
|
|
402
|
+
}, import("elysia").DefaultMetadata & Http["~Metadata"], {} & Http["~Routes"], import("elysia").DefaultEphemeral, {
|
|
400
403
|
derive: {} & Http["~Ephemeral"]["derive"];
|
|
401
404
|
schema: {} & import("elysia/types").MergeSchema<{} & Http["~Ephemeral"]["schema"], {}, "", false>;
|
|
402
405
|
schemas: {} & Http["~Ephemeral"]["schemas"];
|
|
403
|
-
response:
|
|
406
|
+
response: Http["~Ephemeral"]["response"];
|
|
404
407
|
error: [...Http["~Ephemeral"]["error"]];
|
|
405
|
-
},
|
|
406
|
-
readonly services: Services;
|
|
407
|
-
readonly requestContext: unknown;
|
|
408
|
-
}>, {
|
|
408
|
+
}, {}, {
|
|
409
409
|
readonly services: Services;
|
|
410
410
|
readonly requestContext: unknown;
|
|
411
411
|
}>;
|
|
@@ -438,8 +438,8 @@ export declare function createApplication<const Http extends AnyElysia = Elysia>
|
|
|
438
438
|
macro: (import("elysia").DefaultMetadata & Http["~Metadata"])["macro"];
|
|
439
439
|
macroFn: (import("elysia").DefaultMetadata & Http["~Metadata"])["macroFn"];
|
|
440
440
|
parser: (import("elysia").DefaultMetadata & Http["~Metadata"])["parser"];
|
|
441
|
-
response: import("elysia/types").UnionResponseStatus<(import("elysia").DefaultMetadata & Http["~Metadata"])["response"], import("elysia/types").UnionResponseStatus<
|
|
442
|
-
},
|
|
441
|
+
response: import("elysia/types").UnionResponseStatus<(import("elysia").DefaultMetadata & Http["~Metadata"])["response"], import("elysia/types").UnionResponseStatus<Http["~Ephemeral"]["response"], {}>>;
|
|
442
|
+
}, {} & Http["~Routes"], import("elysia").DefaultEphemeral, {
|
|
443
443
|
derive: {};
|
|
444
444
|
schema: {};
|
|
445
445
|
schemas: {};
|
|
@@ -460,8 +460,8 @@ export declare function createTestApp<const Http extends AnyElysia = Elysia>(opt
|
|
|
460
460
|
macro: (import("elysia").DefaultMetadata & Http["~Metadata"])["macro"];
|
|
461
461
|
macroFn: (import("elysia").DefaultMetadata & Http["~Metadata"])["macroFn"];
|
|
462
462
|
parser: (import("elysia").DefaultMetadata & Http["~Metadata"])["parser"];
|
|
463
|
-
response: import("elysia/types").UnionResponseStatus<(import("elysia").DefaultMetadata & Http["~Metadata"])["response"], import("elysia/types").UnionResponseStatus<
|
|
464
|
-
},
|
|
463
|
+
response: import("elysia/types").UnionResponseStatus<(import("elysia").DefaultMetadata & Http["~Metadata"])["response"], import("elysia/types").UnionResponseStatus<Http["~Ephemeral"]["response"], {}>>;
|
|
464
|
+
}, {} & Http["~Routes"], import("elysia").DefaultEphemeral, {
|
|
465
465
|
derive: {};
|
|
466
466
|
schema: {};
|
|
467
467
|
schemas: {};
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import { Elysia as Elysia3, setupTypebox, Validator as Validator2 } from "elysia";
|
|
3
3
|
import { PendingWorkRegistry as PendingWorkRegistry2, PendingWorkTimeoutError, PendingWorkCapacityError } from "@supacloud/app/runtime";
|
|
4
|
-
import { decodeCommandPreview } from "@supacloud/contracts";
|
|
4
|
+
import { commandFailureMetadata as commandFailureMetadata2, decodeCommandPreview } from "@supacloud/contracts";
|
|
5
5
|
|
|
6
6
|
// src/command-errors.ts
|
|
7
7
|
function commandErrorCode(error) {
|
|
@@ -84,15 +84,15 @@ function httpRequestId(request) {
|
|
|
84
84
|
}
|
|
85
85
|
function createHttpTelemetry(observe) {
|
|
86
86
|
const starts = new WeakMap;
|
|
87
|
-
return new Elysia().
|
|
87
|
+
return new Elysia().onRequest(({ request, set }) => {
|
|
88
88
|
const supplied = request.headers.get("x-request-id");
|
|
89
89
|
const requestId = supplied && /^[A-Za-z0-9._:-]{1,128}$/.test(supplied) ? supplied : crypto.randomUUID();
|
|
90
90
|
starts.set(request, { time: performance.now(), requestId });
|
|
91
91
|
requestIds.set(request, requestId);
|
|
92
92
|
set.headers["x-request-id"] = requestId;
|
|
93
|
-
}).
|
|
93
|
+
}).onError(() => {
|
|
94
94
|
return;
|
|
95
|
-
}).
|
|
95
|
+
}).onAfterResponse(async ({ request, responseValue: response, set, route }) => {
|
|
96
96
|
const start = starts.get(request);
|
|
97
97
|
if (!start)
|
|
98
98
|
return;
|
|
@@ -861,7 +861,7 @@ function registerElysiaRoute(app, route) {
|
|
|
861
861
|
}
|
|
862
862
|
return value;
|
|
863
863
|
};
|
|
864
|
-
app.method(route.method, route.path, toElysiaRouteSchema(route.contract), handler);
|
|
864
|
+
app.method(route.method, route.path, { ...toElysiaRouteSchema(route.contract) }, handler);
|
|
865
865
|
return app;
|
|
866
866
|
}
|
|
867
867
|
|
|
@@ -1125,6 +1125,7 @@ function bindCompiledCommand(options) {
|
|
|
1125
1125
|
// src/persistent-command.ts
|
|
1126
1126
|
import {
|
|
1127
1127
|
CommandError,
|
|
1128
|
+
commandFailureMetadata,
|
|
1128
1129
|
decodeCommandIdentity
|
|
1129
1130
|
} from "@supacloud/contracts";
|
|
1130
1131
|
function createPersistentCommandAdapter(command, options) {
|
|
@@ -1143,7 +1144,7 @@ function createPersistentCommandAdapter(command, options) {
|
|
|
1143
1144
|
if (!(error instanceof CommandError))
|
|
1144
1145
|
throw error;
|
|
1145
1146
|
const status = commandErrorStatus(error.code);
|
|
1146
|
-
throw new ApplicationError(error.code, { code: error.code, status });
|
|
1147
|
+
throw new ApplicationError(error.code, { code: error.code, status, metadata: commandFailureMetadata(error.code) });
|
|
1147
1148
|
}
|
|
1148
1149
|
}
|
|
1149
1150
|
};
|
|
@@ -2024,12 +2025,14 @@ class ApplicationError extends Error {
|
|
|
2024
2025
|
status;
|
|
2025
2026
|
code;
|
|
2026
2027
|
details;
|
|
2028
|
+
metadata;
|
|
2027
2029
|
constructor(message, options = {}) {
|
|
2028
2030
|
super(message);
|
|
2029
2031
|
this.name = "ApplicationError";
|
|
2030
2032
|
this.status = options.status ?? 500;
|
|
2031
2033
|
this.code = options.code ?? "INTERNAL_ERROR";
|
|
2032
2034
|
this.details = options.details;
|
|
2035
|
+
this.metadata = options.metadata;
|
|
2033
2036
|
}
|
|
2034
2037
|
}
|
|
2035
2038
|
function validatedJsonResponse(validate, value, init) {
|
|
@@ -2489,7 +2492,7 @@ function createModulePlugin(compiled, services, ctxFactory = defaultRequestConte
|
|
|
2489
2492
|
});
|
|
2490
2493
|
const createRequestScope = compiled.createRequestScope;
|
|
2491
2494
|
const requestScopes = new WeakMap;
|
|
2492
|
-
plugin.
|
|
2495
|
+
plugin.onAfterResponse(async ({ request }) => {
|
|
2493
2496
|
const scope = requestScopes.get(request);
|
|
2494
2497
|
requestScopes.delete(request);
|
|
2495
2498
|
try {
|
|
@@ -2511,9 +2514,9 @@ function createModulePlugin(compiled, services, ctxFactory = defaultRequestConte
|
|
|
2511
2514
|
const mapped = await options.errorMapper?.(error, context);
|
|
2512
2515
|
return mapped ?? defaultErrorResponse(error, frameworkCode);
|
|
2513
2516
|
};
|
|
2514
|
-
plugin.
|
|
2515
|
-
plugin.
|
|
2516
|
-
plugin.
|
|
2517
|
+
plugin.onError(ApplicationError, ({ error, request }) => mapError(error, frameworkErrorCode(error), request));
|
|
2518
|
+
plugin.onError(SchemaContractError, ({ error, request }) => mapError(error, frameworkErrorCode(error), request));
|
|
2519
|
+
plugin.onError(({ error, request }) => mapError(error, frameworkErrorCode(error), request));
|
|
2517
2520
|
const routeRegistrar = plugin;
|
|
2518
2521
|
for (const controller of compiled.controllers) {
|
|
2519
2522
|
for (const route of controller.routes) {
|
|
@@ -2562,7 +2565,7 @@ function createModulePlugin(compiled, services, ctxFactory = defaultRequestConte
|
|
|
2562
2565
|
requestContext: requestContexts.get(context.request),
|
|
2563
2566
|
response,
|
|
2564
2567
|
encodeResponse: async (value) => {
|
|
2565
|
-
const validator = responseValidators?.
|
|
2568
|
+
const validator = responseValidators?.get(responseStatusOf(value, context.set.status));
|
|
2566
2569
|
if (!validator)
|
|
2567
2570
|
return value;
|
|
2568
2571
|
if (!("EncodeFrom" in validator) || typeof validator.EncodeFrom !== "function") {
|
|
@@ -2767,7 +2770,12 @@ async function executeJob(compiled, services, job, input, requestContext, import
|
|
|
2767
2770
|
function defaultErrorResponse(error, frameworkCode) {
|
|
2768
2771
|
const protocolCode = commandErrorCode(error);
|
|
2769
2772
|
if (protocolCode) {
|
|
2770
|
-
return Response.json({
|
|
2773
|
+
return Response.json({
|
|
2774
|
+
ok: false,
|
|
2775
|
+
code: protocolCode,
|
|
2776
|
+
message: protocolCode,
|
|
2777
|
+
metadata: commandFailureMetadata2(protocolCode)
|
|
2778
|
+
}, {
|
|
2771
2779
|
status: commandErrorStatus(protocolCode)
|
|
2772
2780
|
});
|
|
2773
2781
|
}
|
|
@@ -2776,7 +2784,8 @@ function defaultErrorResponse(error, frameworkCode) {
|
|
|
2776
2784
|
ok: false,
|
|
2777
2785
|
code: error.code,
|
|
2778
2786
|
message: error.message,
|
|
2779
|
-
...error.details === undefined ? {} : { details: error.details }
|
|
2787
|
+
...error.details === undefined ? {} : { details: error.details },
|
|
2788
|
+
...error.metadata === undefined ? {} : { metadata: error.metadata }
|
|
2780
2789
|
}, { status: error.status });
|
|
2781
2790
|
}
|
|
2782
2791
|
if (frameworkCode === "PARSE") {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@supacloud/elysia",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.30.1",
|
|
4
4
|
"description": "Elysia runtime adapter for SupaCloud compiled modules: application/request scopes, route registration and validation",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -49,29 +49,29 @@
|
|
|
49
49
|
"directory": "packages/elysia"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@supacloud/app": "0.
|
|
53
|
-
"@supacloud/contracts": "0.
|
|
54
|
-
"effect": "4.0.
|
|
52
|
+
"@supacloud/app": "0.27.1",
|
|
53
|
+
"@supacloud/contracts": "0.9.0",
|
|
54
|
+
"effect": "4.0.5",
|
|
55
55
|
"exact-mirror": "1.2.6",
|
|
56
56
|
"jose": "^6.2.12",
|
|
57
|
-
"typebox": "1.3.
|
|
57
|
+
"typebox": "1.3.37"
|
|
58
58
|
},
|
|
59
59
|
"overrides": {
|
|
60
|
-
"@supacloud/delivery": "0.
|
|
61
|
-
"@supacloud/contracts": "0.
|
|
62
|
-
"@supacloud/commands": "0.9.
|
|
63
|
-
"@graphql-tools/utils": "^12.0.
|
|
60
|
+
"@supacloud/delivery": "0.18.1",
|
|
61
|
+
"@supacloud/contracts": "0.9.0",
|
|
62
|
+
"@supacloud/commands": "0.9.3",
|
|
63
|
+
"@graphql-tools/utils": "^12.0.4"
|
|
64
64
|
},
|
|
65
65
|
"peerDependencies": {
|
|
66
|
-
"elysia": "2.0.0-beta.
|
|
66
|
+
"elysia": "2.0.0-beta.32"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
|
-
"@supacloud/compiler": "0.
|
|
70
|
-
"@supacloud/delivery": "0.
|
|
71
|
-
"@supacloud/commands": "0.9.
|
|
72
|
-
"@supacloud/db": "0.
|
|
73
|
-
"@types/bun": "^1.4.
|
|
74
|
-
"elysia": "2.0.0-beta.
|
|
69
|
+
"@supacloud/compiler": "0.46.2",
|
|
70
|
+
"@supacloud/delivery": "0.18.1",
|
|
71
|
+
"@supacloud/commands": "0.9.3",
|
|
72
|
+
"@supacloud/db": "0.17.1",
|
|
73
|
+
"@types/bun": "^1.4.3",
|
|
74
|
+
"elysia": "2.0.0-beta.32",
|
|
75
75
|
"typescript": "^7.0.2"
|
|
76
76
|
}
|
|
77
77
|
}
|