@supacloud/elysia 0.38.2 → 0.39.0
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 +40 -0
- package/dist/bun-aot.js +220 -201
- package/dist/fixtures/webhook-generated/application.d.ts +2 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +220 -201
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -8,6 +8,46 @@ is a separately authorized business command, never an assumed rollback.
|
|
|
8
8
|
|
|
9
9
|
## Compatibility and Acceptance Boundary
|
|
10
10
|
|
|
11
|
+
### Static route registration migration
|
|
12
|
+
|
|
13
|
+
HTTP modules now require compiler-emitted `registerRoutes(register)` calls.
|
|
14
|
+
The adapter has no descriptor-array registration fallback. A module with routes
|
|
15
|
+
and a missing or non-callable plan fails at startup with
|
|
16
|
+
`COMPILED_ROUTE_REGISTRATION_REQUIRED`. Modules containing only providers,
|
|
17
|
+
commands or jobs may omit this HTTP-only plan.
|
|
18
|
+
|
|
19
|
+
Upgrade `@supacloud/compiler` and `@supacloud/elysia` together using a matched
|
|
20
|
+
release, then regenerate application artifacts with the installed compiler:
|
|
21
|
+
|
|
22
|
+
```sh
|
|
23
|
+
bun run supacloud-compiler compile
|
|
24
|
+
bun run supacloud-compiler check --json
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Commit the regenerated `application.ts` and manifests together with the lockfile,
|
|
28
|
+
rebuild the application bundle, and exercise its affected HTTP entry points.
|
|
29
|
+
Do not patch generated files by hand or deploy a new adapter with an old bundle.
|
|
30
|
+
For rollback, restore the compiler, adapter, lockfile and compiled bundle as one
|
|
31
|
+
tested release. The package version numbers need not be identical.
|
|
32
|
+
|
|
33
|
+
Hand-authored test fixtures and custom integrations must register each route
|
|
34
|
+
explicitly, with its full path. Preserve descriptor identities and order:
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
registerRoutes(register) {
|
|
38
|
+
register(this.controllers[0]!, this.controllers[0]!.routes[0]!, '/orders')
|
|
39
|
+
register(this.controllers[0]!, this.controllers[0]!.routes[1]!, '/orders/:id')
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
The callback runs during plugin construction. The compiler emits full paths and
|
|
44
|
+
individual registrations; schema validation, HTTP policies, command governance,
|
|
45
|
+
scope cleanup and error handling stay in the adapter. Startup validation still
|
|
46
|
+
inspects descriptors. This is not a claim of zero overhead or a measured speedup.
|
|
47
|
+
The manifest describes static declarations; host options can add lifecycle hooks
|
|
48
|
+
or select the request pipeline. Native Elysia macros supplied by the host are
|
|
49
|
+
not inferred from application declarations.
|
|
50
|
+
|
|
11
51
|
The Elysia peer and development dependency are pinned to `2.0.0-rc.1`.
|
|
12
52
|
The runtime adapter pins Effect `4.0.5` and consumes its `Exit`-based
|
|
13
53
|
execution boundary.
|
package/dist/bun-aot.js
CHANGED
|
@@ -2678,8 +2678,15 @@ function createModulePlugin(compiled, services, ctxFactory = defaultRequestConte
|
|
|
2678
2678
|
"parse",
|
|
2679
2679
|
"allowDeleteBody"
|
|
2680
2680
|
]);
|
|
2681
|
+
const pendingRoutes = new Map;
|
|
2681
2682
|
for (const controller of compiled.controllers) {
|
|
2682
2683
|
for (const route of controller.routes) {
|
|
2684
|
+
if (pendingRoutes.has(route)) {
|
|
2685
|
+
throw new ApplicationError(`Duplicate route descriptor in module "${compiled.name}". Recompile the application.`, {
|
|
2686
|
+
code: "COMPILED_ROUTE_REGISTRATION_INVALID"
|
|
2687
|
+
});
|
|
2688
|
+
}
|
|
2689
|
+
pendingRoutes.set(route, { controller, path: joinPaths(controller.path, route.path) });
|
|
2683
2690
|
const unsupported = Object.keys(route).filter((field) => !supportedFields.has(field));
|
|
2684
2691
|
if (!supportedMethods.has(route.method) || unsupported.length > 0) {
|
|
2685
2692
|
throw new ApplicationError(`Unsupported compiled route ${route.method} ${controller.path}${route.path}` + (unsupported.length > 0 ? `: ${unsupported.join(", ")}` : ""), { code: "ROUTE_DESCRIPTOR_UNSUPPORTED" });
|
|
@@ -2695,6 +2702,9 @@ function createModulePlugin(compiled, services, ctxFactory = defaultRequestConte
|
|
|
2695
2702
|
}
|
|
2696
2703
|
}
|
|
2697
2704
|
}
|
|
2705
|
+
if ((compiled.controllers.some((controller) => controller.routes.length > 0) || compiled.registerRoutes !== undefined) && typeof compiled.registerRoutes !== "function") {
|
|
2706
|
+
throw new ApplicationError(`Module "${compiled.name}" requires a compiler-emitted registerRoutes plan. Upgrade @supacloud/compiler with @supacloud/elysia and recompile the application.`, { code: "COMPILED_ROUTE_REGISTRATION_REQUIRED" });
|
|
2707
|
+
}
|
|
2698
2708
|
const hasCommandRoutes = compiled.controllers.some((controller) => controller.routes.some((route) => route.command !== undefined));
|
|
2699
2709
|
if (hasCommandRoutes && !options.commandGovernance && !options.commandExecutor) {
|
|
2700
2710
|
throw new ApplicationError(`Module "${compiled.name}" has command routes but no commandGovernance`, { code: "COMMAND_GOVERNANCE_UNCONFIGURED" });
|
|
@@ -2778,225 +2788,234 @@ function createModulePlugin(compiled, services, ctxFactory = defaultRequestConte
|
|
|
2778
2788
|
plugin.onError(SchemaContractError, ({ error, request }) => mapError(error, frameworkErrorCode(error), request));
|
|
2779
2789
|
plugin.onError(({ error, request }) => mapError(error, frameworkErrorCode(error), request));
|
|
2780
2790
|
const routeRegistrar = plugin;
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
if (
|
|
2812
|
-
|
|
2791
|
+
const registerRoute = (controller, route, path) => {
|
|
2792
|
+
if (pendingRoutes.get(route)?.controller !== controller || pendingRoutes.get(route)?.path !== path) {
|
|
2793
|
+
throw new ApplicationError(`Invalid static route registration in module "${compiled.name}". Recompile the application.`, {
|
|
2794
|
+
code: "COMPILED_ROUTE_REGISTRATION_INVALID"
|
|
2795
|
+
});
|
|
2796
|
+
}
|
|
2797
|
+
pendingRoutes.delete(route);
|
|
2798
|
+
const documentation = route.data?.openapi;
|
|
2799
|
+
const hidden = documentation !== null && typeof documentation === "object" && "hide" in documentation && documentation.hide === true;
|
|
2800
|
+
const tags = documentation !== null && typeof documentation === "object" && "tags" in documentation && Array.isArray(documentation.tags) ? documentation.tags.filter((tag) => typeof tag === "string") : undefined;
|
|
2801
|
+
const schema = {
|
|
2802
|
+
...toElysiaRouteSchema(route),
|
|
2803
|
+
...route.parse === "none" ? { parse: "none" } : {},
|
|
2804
|
+
...route.title || hidden || tags ? { detail: {
|
|
2805
|
+
...route.title ? { summary: route.title } : {},
|
|
2806
|
+
...hidden ? { hide: true } : {},
|
|
2807
|
+
...tags ? { tags } : {}
|
|
2808
|
+
} } : {}
|
|
2809
|
+
};
|
|
2810
|
+
const policies = compileHttpPolicies(route, path, options.httpPolicies);
|
|
2811
|
+
if (policies.length > 0) {
|
|
2812
|
+
Object.assign(schema, {
|
|
2813
|
+
beforeHandle: async (context) => {
|
|
2814
|
+
for (const policy of policies) {
|
|
2815
|
+
const result = await policy({
|
|
2816
|
+
http: context,
|
|
2817
|
+
requestContext: requestContexts.get(context.request)
|
|
2818
|
+
});
|
|
2819
|
+
if (result instanceof Response)
|
|
2820
|
+
return result;
|
|
2821
|
+
if (result !== undefined) {
|
|
2822
|
+
throw new Error("HTTP policies must return Response or undefined");
|
|
2813
2823
|
}
|
|
2814
2824
|
}
|
|
2815
|
-
|
|
2816
|
-
} else if (route.idempotency === "required") {
|
|
2817
|
-
Object.assign(schema, {
|
|
2818
|
-
beforeHandle: (context) => {
|
|
2825
|
+
if (route.idempotency === "required") {
|
|
2819
2826
|
requireRouteIdempotencyKey(context.request);
|
|
2820
2827
|
}
|
|
2821
|
-
}
|
|
2822
|
-
}
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
return
|
|
2828
|
+
}
|
|
2829
|
+
});
|
|
2830
|
+
} else if (route.idempotency === "required") {
|
|
2831
|
+
Object.assign(schema, {
|
|
2832
|
+
beforeHandle: (context) => {
|
|
2833
|
+
requireRouteIdempotencyKey(context.request);
|
|
2834
|
+
}
|
|
2835
|
+
});
|
|
2836
|
+
}
|
|
2837
|
+
const responsePolicies = policies.filter((policy) => policy.afterResponse);
|
|
2838
|
+
const mappingPolicies = policies.filter((policy) => policy.mapResponse);
|
|
2839
|
+
const routePipeline = descriptorPipeline(route, "route", options.onExecution);
|
|
2840
|
+
const command = route.command ? commandsByClassName.get(route.command) : undefined;
|
|
2841
|
+
const commandPipeline = route.command ? descriptorPipeline(command ?? {}, "command", options.onExecution) : undefined;
|
|
2842
|
+
const routeInvoker = route.invoker;
|
|
2843
|
+
if (mappingPolicies.length > 0) {
|
|
2844
|
+
const responseValidators = Validator2.response(schema.response, { normalize: options.normalize ?? true });
|
|
2845
|
+
Object.assign(schema, {
|
|
2846
|
+
mapResponse: async (context) => {
|
|
2847
|
+
let response = context.responseValue;
|
|
2848
|
+
let mapped;
|
|
2849
|
+
for (const policy of mappingPolicies) {
|
|
2850
|
+
const result = await policy.mapResponse({
|
|
2851
|
+
http: context,
|
|
2852
|
+
requestContext: requestContexts.get(context.request),
|
|
2853
|
+
response,
|
|
2854
|
+
encodeResponse: (value) => {
|
|
2855
|
+
const validator = responseValidators?.get(responseStatusOf(value, context.set.status));
|
|
2856
|
+
if (!validator)
|
|
2857
|
+
return value;
|
|
2858
|
+
if (!("EncodeFrom" in validator) || typeof validator.EncodeFrom !== "function") {
|
|
2859
|
+
throw new ApplicationError("Response validation failed", { code: "RESPONSE_VALIDATION_FAILED" });
|
|
2860
|
+
}
|
|
2861
|
+
if ("mayReturnPromise" in validator && validator.mayReturnPromise && "From" in validator && typeof validator.From === "function") {
|
|
2862
|
+
return validator.From.call(validator, value, "response", true);
|
|
2851
2863
|
}
|
|
2852
|
-
|
|
2853
|
-
if (result !== undefined) {
|
|
2854
|
-
if (!(result instanceof Response))
|
|
2855
|
-
throw new Error("HTTP response policies must return Response or undefined");
|
|
2856
|
-
mapped = result;
|
|
2857
|
-
response = result;
|
|
2864
|
+
return validator.EncodeFrom.call(validator, value, "response");
|
|
2858
2865
|
}
|
|
2866
|
+
});
|
|
2867
|
+
if (result !== undefined) {
|
|
2868
|
+
if (!(result instanceof Response))
|
|
2869
|
+
throw new Error("HTTP response policies must return Response or undefined");
|
|
2870
|
+
mapped = result;
|
|
2871
|
+
response = result;
|
|
2859
2872
|
}
|
|
2860
|
-
return mapped;
|
|
2861
2873
|
}
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
+
return mapped;
|
|
2875
|
+
}
|
|
2876
|
+
});
|
|
2877
|
+
}
|
|
2878
|
+
if (responsePolicies.length > 0) {
|
|
2879
|
+
Object.assign(schema, {
|
|
2880
|
+
afterResponse: async (context) => {
|
|
2881
|
+
for (const policy of responsePolicies) {
|
|
2882
|
+
await policy.afterResponse({
|
|
2883
|
+
http: context,
|
|
2884
|
+
requestContext: requestContexts.get(context.request),
|
|
2885
|
+
response: context.responseValue
|
|
2886
|
+
});
|
|
2874
2887
|
}
|
|
2875
|
-
}
|
|
2876
|
-
}
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
|
|
2888
|
+
}
|
|
2889
|
+
});
|
|
2890
|
+
}
|
|
2891
|
+
const directRoute = canUseDirectRoute(compiled, controller, route) && options.onExecution === undefined && policies.length === 0 && responsePolicies.length === 0 && mappingPolicies.length === 0;
|
|
2892
|
+
const directController = directRoute && route.directInvokerFast !== undefined ? controllerInstance(services[controller.serviceKey]) : undefined;
|
|
2893
|
+
const directMethod = directController?.[route.handler];
|
|
2894
|
+
const directInvokerFast = route.directInvokerFast;
|
|
2895
|
+
const directHandler = directController && typeof directMethod === "function" && directInvokerFast ? (ctx) => directInvokerFast(directController, directMethod, ctx) : (ctx) => route.directInvoker(services[controller.serviceKey], ctx);
|
|
2896
|
+
const handler = directRoute ? directHandler : async (ctx) => {
|
|
2897
|
+
const requestContext = requestContexts.get(ctx.request);
|
|
2898
|
+
const execute = async () => {
|
|
2899
|
+
const requestScope = createRequestScope ? await createRequestScope(services, requestContext, imported) : undefined;
|
|
2900
|
+
if (requestScope && compiled.destroyRequestScope)
|
|
2901
|
+
requestScopes.set(ctx.request, requestScope);
|
|
2902
|
+
const source = controller.scope === "request" ? requestScope : services;
|
|
2903
|
+
const instance = source?.[controller.serviceKey];
|
|
2904
|
+
const normalizedCookie = ctx.cookie === undefined ? undefined : cookieValues(ctx.cookie);
|
|
2905
|
+
const input = {
|
|
2906
|
+
body: ctx.body,
|
|
2907
|
+
params: ctx.params,
|
|
2908
|
+
query: ctx.query,
|
|
2909
|
+
headers: ctx.headers ?? Object.fromEntries(ctx.request.headers.entries()),
|
|
2910
|
+
...normalizedCookie === undefined ? {} : { cookie: normalizedCookie },
|
|
2911
|
+
context: requestContext,
|
|
2912
|
+
request: ctx.request,
|
|
2913
|
+
...requestScope ? { scope: requestScope } : {},
|
|
2914
|
+
requestContext
|
|
2915
|
+
};
|
|
2916
|
+
const handlerCall = () => {
|
|
2917
|
+
if (route.invoker)
|
|
2918
|
+
return route.invoker(instance, input);
|
|
2919
|
+
if (!isRecord2(instance))
|
|
2920
|
+
throw new TypeError("Route controller is not an object");
|
|
2921
|
+
const method = instance[route.handler];
|
|
2922
|
+
if (typeof method !== "function")
|
|
2923
|
+
throw new TypeError(`Route handler ${route.handler} is not callable`);
|
|
2924
|
+
return method.call(instance, input);
|
|
2925
|
+
};
|
|
2926
|
+
const invokeHandler = async () => runCompiledEffect(await handlerCall(), route.effect, options.effectRuntime);
|
|
2927
|
+
const invoke = once(() => route.command && options.commandGovernance ? invokeHandler() : options.onExecution ? observeExecution(options.onExecution, {
|
|
2928
|
+
kind: route.command ? "command" : "route",
|
|
2929
|
+
operation: route.command ?? `${route.method} ${path}`,
|
|
2930
|
+
stage: "handler",
|
|
2931
|
+
...executionTrace(requestContext)
|
|
2932
|
+
}, invokeHandler) : invokeHandler());
|
|
2933
|
+
const routeContext = {
|
|
2934
|
+
kind: "route",
|
|
2935
|
+
name: `${route.method} ${path}`,
|
|
2936
|
+
input,
|
|
2937
|
+
request: ctx.request,
|
|
2938
|
+
requestContext,
|
|
2939
|
+
...requestScope ? { scope: requestScope } : {},
|
|
2940
|
+
services,
|
|
2941
|
+
metadata: route
|
|
2942
|
+
};
|
|
2943
|
+
const command = route.command === undefined ? undefined : resolveCompiledCommand(compiled, route.command);
|
|
2944
|
+
const commandContext = route.command === undefined ? routeContext : {
|
|
2945
|
+
kind: "command",
|
|
2946
|
+
name: command?.name ?? route.command,
|
|
2947
|
+
input,
|
|
2948
|
+
request: ctx.request,
|
|
2949
|
+
requestContext,
|
|
2950
|
+
...requestScope ? { scope: requestScope } : {},
|
|
2951
|
+
services,
|
|
2952
|
+
metadata: command ?? route
|
|
2953
|
+
};
|
|
2954
|
+
const invokeRoute = () => modulePipeline(route.command ? commandContext : routeContext, once(() => routePipeline(routeContext, once(() => route.command ? commandPipeline(commandContext, once(invoke)) : invoke()))));
|
|
2955
|
+
const invokeCommand = () => {
|
|
2956
|
+
if (!route.command)
|
|
2957
|
+
return invokeRoute();
|
|
2958
|
+
if (!command) {
|
|
2959
|
+
throw new ApplicationError(`Command "${route.command}" is not registered`, {
|
|
2960
|
+
code: "COMMAND_NOT_REGISTERED"
|
|
2961
|
+
});
|
|
2962
|
+
}
|
|
2963
|
+
if (!commandExecutor) {
|
|
2964
|
+
throw new ApplicationError(`Command "${command.name}" has no executor`, {
|
|
2965
|
+
status: 501,
|
|
2966
|
+
code: "COMMAND_EXECUTOR_UNAVAILABLE"
|
|
2967
|
+
});
|
|
2968
|
+
}
|
|
2969
|
+
const invocation = {
|
|
2970
|
+
command,
|
|
2922
2971
|
input,
|
|
2923
2972
|
request: ctx.request,
|
|
2924
2973
|
requestContext,
|
|
2925
2974
|
...requestScope ? { scope: requestScope } : {},
|
|
2926
|
-
services
|
|
2927
|
-
metadata: route
|
|
2975
|
+
services
|
|
2928
2976
|
};
|
|
2929
|
-
|
|
2930
|
-
const commandContext = route.command === undefined ? routeContext : {
|
|
2977
|
+
return observeExecution(options.onExecution, {
|
|
2931
2978
|
kind: "command",
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
...requestScope ? { scope: requestScope } : {},
|
|
2937
|
-
services,
|
|
2938
|
-
metadata: command ?? route
|
|
2939
|
-
};
|
|
2940
|
-
const invokeRoute = () => modulePipeline(route.command ? commandContext : routeContext, once(() => routePipeline(routeContext, once(() => route.command ? commandPipeline(commandContext, once(invoke)) : invoke()))));
|
|
2941
|
-
const invokeCommand = () => {
|
|
2942
|
-
if (!route.command)
|
|
2943
|
-
return invokeRoute();
|
|
2944
|
-
if (!command) {
|
|
2945
|
-
throw new ApplicationError(`Command "${route.command}" is not registered`, {
|
|
2946
|
-
code: "COMMAND_NOT_REGISTERED"
|
|
2947
|
-
});
|
|
2948
|
-
}
|
|
2949
|
-
if (!commandExecutor) {
|
|
2950
|
-
throw new ApplicationError(`Command "${command.name}" has no executor`, {
|
|
2951
|
-
status: 501,
|
|
2952
|
-
code: "COMMAND_EXECUTOR_UNAVAILABLE"
|
|
2953
|
-
});
|
|
2954
|
-
}
|
|
2955
|
-
const invocation = {
|
|
2956
|
-
command,
|
|
2957
|
-
input,
|
|
2958
|
-
request: ctx.request,
|
|
2959
|
-
requestContext,
|
|
2960
|
-
...requestScope ? { scope: requestScope } : {},
|
|
2961
|
-
services
|
|
2962
|
-
};
|
|
2963
|
-
return observeExecution(options.onExecution, {
|
|
2964
|
-
kind: "command",
|
|
2965
|
-
operation: command.name,
|
|
2966
|
-
stage: "commandExecutor",
|
|
2967
|
-
...executionTrace(requestContext)
|
|
2968
|
-
}, () => commandExecutor(invocation, once(invokeRoute)));
|
|
2969
|
-
};
|
|
2970
|
-
return invokeCommand();
|
|
2979
|
+
operation: command.name,
|
|
2980
|
+
stage: "commandExecutor",
|
|
2981
|
+
...executionTrace(requestContext)
|
|
2982
|
+
}, () => commandExecutor(invocation, once(invokeRoute)));
|
|
2971
2983
|
};
|
|
2972
|
-
|
|
2973
|
-
assertDeclaredResponseStatus(route, result, ctx.set.status);
|
|
2974
|
-
return result;
|
|
2984
|
+
return invokeCommand();
|
|
2975
2985
|
};
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2986
|
+
const result = await execute();
|
|
2987
|
+
assertDeclaredResponseStatus(route, result, ctx.set.status);
|
|
2988
|
+
return result;
|
|
2989
|
+
};
|
|
2990
|
+
switch (route.method) {
|
|
2991
|
+
case "GET":
|
|
2992
|
+
routeRegistrar.get(path, schema, handler);
|
|
2993
|
+
break;
|
|
2994
|
+
case "POST":
|
|
2995
|
+
routeRegistrar.post(path, schema, handler);
|
|
2996
|
+
break;
|
|
2997
|
+
case "PUT":
|
|
2998
|
+
routeRegistrar.put(path, schema, handler);
|
|
2999
|
+
break;
|
|
3000
|
+
case "PATCH":
|
|
3001
|
+
routeRegistrar.patch(path, schema, handler);
|
|
3002
|
+
break;
|
|
3003
|
+
case "DELETE":
|
|
3004
|
+
routeRegistrar.delete(path, schema, handler);
|
|
3005
|
+
break;
|
|
3006
|
+
case "HEAD":
|
|
3007
|
+
routeRegistrar.head(path, schema, handler);
|
|
3008
|
+
break;
|
|
3009
|
+
case "OPTIONS":
|
|
3010
|
+
routeRegistrar.options(path, schema, handler);
|
|
3011
|
+
break;
|
|
2999
3012
|
}
|
|
3013
|
+
};
|
|
3014
|
+
compiled.registerRoutes?.(registerRoute);
|
|
3015
|
+
if (pendingRoutes.size > 0) {
|
|
3016
|
+
throw new ApplicationError(`Incomplete static route registration in module "${compiled.name}". Recompile the application.`, {
|
|
3017
|
+
code: "COMPILED_ROUTE_REGISTRATION_INVALID"
|
|
3018
|
+
});
|
|
3000
3019
|
}
|
|
3001
3020
|
return plugin;
|
|
3002
3021
|
}
|
|
@@ -61,6 +61,7 @@ export interface CompiledRoute {
|
|
|
61
61
|
context?: unknown;
|
|
62
62
|
}) => Promise<unknown> | unknown;
|
|
63
63
|
directInvoker?: (controller: unknown, context: unknown) => Promise<unknown> | unknown;
|
|
64
|
+
directInvokerFast?: (controller: Record<string, unknown>, handler: (...args: unknown[]) => unknown, context: unknown) => Promise<unknown> | unknown;
|
|
64
65
|
executionMode?: "direct" | "pipeline";
|
|
65
66
|
}
|
|
66
67
|
export interface CompiledCommand {
|
|
@@ -129,6 +130,7 @@ export interface CompiledModule {
|
|
|
129
130
|
createJobScope?(services: Record<string, unknown>, ctx: unknown, imported?: Record<string, Record<string, unknown>>): Promise<Record<string, unknown>>;
|
|
130
131
|
destroyJobScope?(scope: Record<string, unknown>): Promise<void>;
|
|
131
132
|
controllers: CompiledController[];
|
|
133
|
+
registerRoutes?(register: (controller: CompiledController, route: CompiledRoute, path: string) => void): void;
|
|
132
134
|
commands: CompiledCommand[];
|
|
133
135
|
jobs: CompiledJob[];
|
|
134
136
|
aspects?: CompiledAspect[];
|
package/dist/index.d.ts
CHANGED
|
@@ -139,6 +139,7 @@ export interface CompiledController {
|
|
|
139
139
|
scope: "application" | "request" | "job";
|
|
140
140
|
routes: CompiledRoute[];
|
|
141
141
|
}
|
|
142
|
+
export type CompiledRouteRegistrar = (controller: CompiledController, route: CompiledRoute, path: string) => void;
|
|
142
143
|
export interface CompiledModule {
|
|
143
144
|
name: string;
|
|
144
145
|
createServices(deps: Record<string, unknown>, imported: Record<string, Record<string, unknown>>): Record<string, unknown>;
|
|
@@ -151,6 +152,8 @@ export interface CompiledModule {
|
|
|
151
152
|
createJobScope?(services: Record<string, unknown>, ctx: unknown, imported?: Record<string, Record<string, unknown>>): Record<string, unknown> | Promise<Record<string, unknown>>;
|
|
152
153
|
destroyJobScope?(scope: Record<string, unknown>): Promise<void>;
|
|
153
154
|
controllers: CompiledController[];
|
|
155
|
+
/** Required for HTTP modules. Recompile artifacts when upgrading the adapter. */
|
|
156
|
+
registerRoutes?(register: CompiledRouteRegistrar): void;
|
|
154
157
|
commands?: CompiledCommand[];
|
|
155
158
|
jobs?: CompiledJob[];
|
|
156
159
|
/** Statically generated module aspects. */
|
package/dist/index.js
CHANGED
|
@@ -2678,8 +2678,15 @@ function createModulePlugin(compiled, services, ctxFactory = defaultRequestConte
|
|
|
2678
2678
|
"parse",
|
|
2679
2679
|
"allowDeleteBody"
|
|
2680
2680
|
]);
|
|
2681
|
+
const pendingRoutes = new Map;
|
|
2681
2682
|
for (const controller of compiled.controllers) {
|
|
2682
2683
|
for (const route of controller.routes) {
|
|
2684
|
+
if (pendingRoutes.has(route)) {
|
|
2685
|
+
throw new ApplicationError(`Duplicate route descriptor in module "${compiled.name}". Recompile the application.`, {
|
|
2686
|
+
code: "COMPILED_ROUTE_REGISTRATION_INVALID"
|
|
2687
|
+
});
|
|
2688
|
+
}
|
|
2689
|
+
pendingRoutes.set(route, { controller, path: joinPaths(controller.path, route.path) });
|
|
2683
2690
|
const unsupported = Object.keys(route).filter((field) => !supportedFields.has(field));
|
|
2684
2691
|
if (!supportedMethods.has(route.method) || unsupported.length > 0) {
|
|
2685
2692
|
throw new ApplicationError(`Unsupported compiled route ${route.method} ${controller.path}${route.path}` + (unsupported.length > 0 ? `: ${unsupported.join(", ")}` : ""), { code: "ROUTE_DESCRIPTOR_UNSUPPORTED" });
|
|
@@ -2695,6 +2702,9 @@ function createModulePlugin(compiled, services, ctxFactory = defaultRequestConte
|
|
|
2695
2702
|
}
|
|
2696
2703
|
}
|
|
2697
2704
|
}
|
|
2705
|
+
if ((compiled.controllers.some((controller) => controller.routes.length > 0) || compiled.registerRoutes !== undefined) && typeof compiled.registerRoutes !== "function") {
|
|
2706
|
+
throw new ApplicationError(`Module "${compiled.name}" requires a compiler-emitted registerRoutes plan. Upgrade @supacloud/compiler with @supacloud/elysia and recompile the application.`, { code: "COMPILED_ROUTE_REGISTRATION_REQUIRED" });
|
|
2707
|
+
}
|
|
2698
2708
|
const hasCommandRoutes = compiled.controllers.some((controller) => controller.routes.some((route) => route.command !== undefined));
|
|
2699
2709
|
if (hasCommandRoutes && !options.commandGovernance && !options.commandExecutor) {
|
|
2700
2710
|
throw new ApplicationError(`Module "${compiled.name}" has command routes but no commandGovernance`, { code: "COMMAND_GOVERNANCE_UNCONFIGURED" });
|
|
@@ -2778,225 +2788,234 @@ function createModulePlugin(compiled, services, ctxFactory = defaultRequestConte
|
|
|
2778
2788
|
plugin.onError(SchemaContractError, ({ error, request }) => mapError(error, frameworkErrorCode(error), request));
|
|
2779
2789
|
plugin.onError(({ error, request }) => mapError(error, frameworkErrorCode(error), request));
|
|
2780
2790
|
const routeRegistrar = plugin;
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
if (
|
|
2812
|
-
|
|
2791
|
+
const registerRoute = (controller, route, path) => {
|
|
2792
|
+
if (pendingRoutes.get(route)?.controller !== controller || pendingRoutes.get(route)?.path !== path) {
|
|
2793
|
+
throw new ApplicationError(`Invalid static route registration in module "${compiled.name}". Recompile the application.`, {
|
|
2794
|
+
code: "COMPILED_ROUTE_REGISTRATION_INVALID"
|
|
2795
|
+
});
|
|
2796
|
+
}
|
|
2797
|
+
pendingRoutes.delete(route);
|
|
2798
|
+
const documentation = route.data?.openapi;
|
|
2799
|
+
const hidden = documentation !== null && typeof documentation === "object" && "hide" in documentation && documentation.hide === true;
|
|
2800
|
+
const tags = documentation !== null && typeof documentation === "object" && "tags" in documentation && Array.isArray(documentation.tags) ? documentation.tags.filter((tag) => typeof tag === "string") : undefined;
|
|
2801
|
+
const schema = {
|
|
2802
|
+
...toElysiaRouteSchema(route),
|
|
2803
|
+
...route.parse === "none" ? { parse: "none" } : {},
|
|
2804
|
+
...route.title || hidden || tags ? { detail: {
|
|
2805
|
+
...route.title ? { summary: route.title } : {},
|
|
2806
|
+
...hidden ? { hide: true } : {},
|
|
2807
|
+
...tags ? { tags } : {}
|
|
2808
|
+
} } : {}
|
|
2809
|
+
};
|
|
2810
|
+
const policies = compileHttpPolicies(route, path, options.httpPolicies);
|
|
2811
|
+
if (policies.length > 0) {
|
|
2812
|
+
Object.assign(schema, {
|
|
2813
|
+
beforeHandle: async (context) => {
|
|
2814
|
+
for (const policy of policies) {
|
|
2815
|
+
const result = await policy({
|
|
2816
|
+
http: context,
|
|
2817
|
+
requestContext: requestContexts.get(context.request)
|
|
2818
|
+
});
|
|
2819
|
+
if (result instanceof Response)
|
|
2820
|
+
return result;
|
|
2821
|
+
if (result !== undefined) {
|
|
2822
|
+
throw new Error("HTTP policies must return Response or undefined");
|
|
2813
2823
|
}
|
|
2814
2824
|
}
|
|
2815
|
-
|
|
2816
|
-
} else if (route.idempotency === "required") {
|
|
2817
|
-
Object.assign(schema, {
|
|
2818
|
-
beforeHandle: (context) => {
|
|
2825
|
+
if (route.idempotency === "required") {
|
|
2819
2826
|
requireRouteIdempotencyKey(context.request);
|
|
2820
2827
|
}
|
|
2821
|
-
}
|
|
2822
|
-
}
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
return
|
|
2828
|
+
}
|
|
2829
|
+
});
|
|
2830
|
+
} else if (route.idempotency === "required") {
|
|
2831
|
+
Object.assign(schema, {
|
|
2832
|
+
beforeHandle: (context) => {
|
|
2833
|
+
requireRouteIdempotencyKey(context.request);
|
|
2834
|
+
}
|
|
2835
|
+
});
|
|
2836
|
+
}
|
|
2837
|
+
const responsePolicies = policies.filter((policy) => policy.afterResponse);
|
|
2838
|
+
const mappingPolicies = policies.filter((policy) => policy.mapResponse);
|
|
2839
|
+
const routePipeline = descriptorPipeline(route, "route", options.onExecution);
|
|
2840
|
+
const command = route.command ? commandsByClassName.get(route.command) : undefined;
|
|
2841
|
+
const commandPipeline = route.command ? descriptorPipeline(command ?? {}, "command", options.onExecution) : undefined;
|
|
2842
|
+
const routeInvoker = route.invoker;
|
|
2843
|
+
if (mappingPolicies.length > 0) {
|
|
2844
|
+
const responseValidators = Validator2.response(schema.response, { normalize: options.normalize ?? true });
|
|
2845
|
+
Object.assign(schema, {
|
|
2846
|
+
mapResponse: async (context) => {
|
|
2847
|
+
let response = context.responseValue;
|
|
2848
|
+
let mapped;
|
|
2849
|
+
for (const policy of mappingPolicies) {
|
|
2850
|
+
const result = await policy.mapResponse({
|
|
2851
|
+
http: context,
|
|
2852
|
+
requestContext: requestContexts.get(context.request),
|
|
2853
|
+
response,
|
|
2854
|
+
encodeResponse: (value) => {
|
|
2855
|
+
const validator = responseValidators?.get(responseStatusOf(value, context.set.status));
|
|
2856
|
+
if (!validator)
|
|
2857
|
+
return value;
|
|
2858
|
+
if (!("EncodeFrom" in validator) || typeof validator.EncodeFrom !== "function") {
|
|
2859
|
+
throw new ApplicationError("Response validation failed", { code: "RESPONSE_VALIDATION_FAILED" });
|
|
2860
|
+
}
|
|
2861
|
+
if ("mayReturnPromise" in validator && validator.mayReturnPromise && "From" in validator && typeof validator.From === "function") {
|
|
2862
|
+
return validator.From.call(validator, value, "response", true);
|
|
2851
2863
|
}
|
|
2852
|
-
|
|
2853
|
-
if (result !== undefined) {
|
|
2854
|
-
if (!(result instanceof Response))
|
|
2855
|
-
throw new Error("HTTP response policies must return Response or undefined");
|
|
2856
|
-
mapped = result;
|
|
2857
|
-
response = result;
|
|
2864
|
+
return validator.EncodeFrom.call(validator, value, "response");
|
|
2858
2865
|
}
|
|
2866
|
+
});
|
|
2867
|
+
if (result !== undefined) {
|
|
2868
|
+
if (!(result instanceof Response))
|
|
2869
|
+
throw new Error("HTTP response policies must return Response or undefined");
|
|
2870
|
+
mapped = result;
|
|
2871
|
+
response = result;
|
|
2859
2872
|
}
|
|
2860
|
-
return mapped;
|
|
2861
2873
|
}
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
+
return mapped;
|
|
2875
|
+
}
|
|
2876
|
+
});
|
|
2877
|
+
}
|
|
2878
|
+
if (responsePolicies.length > 0) {
|
|
2879
|
+
Object.assign(schema, {
|
|
2880
|
+
afterResponse: async (context) => {
|
|
2881
|
+
for (const policy of responsePolicies) {
|
|
2882
|
+
await policy.afterResponse({
|
|
2883
|
+
http: context,
|
|
2884
|
+
requestContext: requestContexts.get(context.request),
|
|
2885
|
+
response: context.responseValue
|
|
2886
|
+
});
|
|
2874
2887
|
}
|
|
2875
|
-
}
|
|
2876
|
-
}
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
|
|
2888
|
+
}
|
|
2889
|
+
});
|
|
2890
|
+
}
|
|
2891
|
+
const directRoute = canUseDirectRoute(compiled, controller, route) && options.onExecution === undefined && policies.length === 0 && responsePolicies.length === 0 && mappingPolicies.length === 0;
|
|
2892
|
+
const directController = directRoute && route.directInvokerFast !== undefined ? controllerInstance(services[controller.serviceKey]) : undefined;
|
|
2893
|
+
const directMethod = directController?.[route.handler];
|
|
2894
|
+
const directInvokerFast = route.directInvokerFast;
|
|
2895
|
+
const directHandler = directController && typeof directMethod === "function" && directInvokerFast ? (ctx) => directInvokerFast(directController, directMethod, ctx) : (ctx) => route.directInvoker(services[controller.serviceKey], ctx);
|
|
2896
|
+
const handler = directRoute ? directHandler : async (ctx) => {
|
|
2897
|
+
const requestContext = requestContexts.get(ctx.request);
|
|
2898
|
+
const execute = async () => {
|
|
2899
|
+
const requestScope = createRequestScope ? await createRequestScope(services, requestContext, imported) : undefined;
|
|
2900
|
+
if (requestScope && compiled.destroyRequestScope)
|
|
2901
|
+
requestScopes.set(ctx.request, requestScope);
|
|
2902
|
+
const source = controller.scope === "request" ? requestScope : services;
|
|
2903
|
+
const instance = source?.[controller.serviceKey];
|
|
2904
|
+
const normalizedCookie = ctx.cookie === undefined ? undefined : cookieValues(ctx.cookie);
|
|
2905
|
+
const input = {
|
|
2906
|
+
body: ctx.body,
|
|
2907
|
+
params: ctx.params,
|
|
2908
|
+
query: ctx.query,
|
|
2909
|
+
headers: ctx.headers ?? Object.fromEntries(ctx.request.headers.entries()),
|
|
2910
|
+
...normalizedCookie === undefined ? {} : { cookie: normalizedCookie },
|
|
2911
|
+
context: requestContext,
|
|
2912
|
+
request: ctx.request,
|
|
2913
|
+
...requestScope ? { scope: requestScope } : {},
|
|
2914
|
+
requestContext
|
|
2915
|
+
};
|
|
2916
|
+
const handlerCall = () => {
|
|
2917
|
+
if (route.invoker)
|
|
2918
|
+
return route.invoker(instance, input);
|
|
2919
|
+
if (!isRecord2(instance))
|
|
2920
|
+
throw new TypeError("Route controller is not an object");
|
|
2921
|
+
const method = instance[route.handler];
|
|
2922
|
+
if (typeof method !== "function")
|
|
2923
|
+
throw new TypeError(`Route handler ${route.handler} is not callable`);
|
|
2924
|
+
return method.call(instance, input);
|
|
2925
|
+
};
|
|
2926
|
+
const invokeHandler = async () => runCompiledEffect(await handlerCall(), route.effect, options.effectRuntime);
|
|
2927
|
+
const invoke = once(() => route.command && options.commandGovernance ? invokeHandler() : options.onExecution ? observeExecution(options.onExecution, {
|
|
2928
|
+
kind: route.command ? "command" : "route",
|
|
2929
|
+
operation: route.command ?? `${route.method} ${path}`,
|
|
2930
|
+
stage: "handler",
|
|
2931
|
+
...executionTrace(requestContext)
|
|
2932
|
+
}, invokeHandler) : invokeHandler());
|
|
2933
|
+
const routeContext = {
|
|
2934
|
+
kind: "route",
|
|
2935
|
+
name: `${route.method} ${path}`,
|
|
2936
|
+
input,
|
|
2937
|
+
request: ctx.request,
|
|
2938
|
+
requestContext,
|
|
2939
|
+
...requestScope ? { scope: requestScope } : {},
|
|
2940
|
+
services,
|
|
2941
|
+
metadata: route
|
|
2942
|
+
};
|
|
2943
|
+
const command = route.command === undefined ? undefined : resolveCompiledCommand(compiled, route.command);
|
|
2944
|
+
const commandContext = route.command === undefined ? routeContext : {
|
|
2945
|
+
kind: "command",
|
|
2946
|
+
name: command?.name ?? route.command,
|
|
2947
|
+
input,
|
|
2948
|
+
request: ctx.request,
|
|
2949
|
+
requestContext,
|
|
2950
|
+
...requestScope ? { scope: requestScope } : {},
|
|
2951
|
+
services,
|
|
2952
|
+
metadata: command ?? route
|
|
2953
|
+
};
|
|
2954
|
+
const invokeRoute = () => modulePipeline(route.command ? commandContext : routeContext, once(() => routePipeline(routeContext, once(() => route.command ? commandPipeline(commandContext, once(invoke)) : invoke()))));
|
|
2955
|
+
const invokeCommand = () => {
|
|
2956
|
+
if (!route.command)
|
|
2957
|
+
return invokeRoute();
|
|
2958
|
+
if (!command) {
|
|
2959
|
+
throw new ApplicationError(`Command "${route.command}" is not registered`, {
|
|
2960
|
+
code: "COMMAND_NOT_REGISTERED"
|
|
2961
|
+
});
|
|
2962
|
+
}
|
|
2963
|
+
if (!commandExecutor) {
|
|
2964
|
+
throw new ApplicationError(`Command "${command.name}" has no executor`, {
|
|
2965
|
+
status: 501,
|
|
2966
|
+
code: "COMMAND_EXECUTOR_UNAVAILABLE"
|
|
2967
|
+
});
|
|
2968
|
+
}
|
|
2969
|
+
const invocation = {
|
|
2970
|
+
command,
|
|
2922
2971
|
input,
|
|
2923
2972
|
request: ctx.request,
|
|
2924
2973
|
requestContext,
|
|
2925
2974
|
...requestScope ? { scope: requestScope } : {},
|
|
2926
|
-
services
|
|
2927
|
-
metadata: route
|
|
2975
|
+
services
|
|
2928
2976
|
};
|
|
2929
|
-
|
|
2930
|
-
const commandContext = route.command === undefined ? routeContext : {
|
|
2977
|
+
return observeExecution(options.onExecution, {
|
|
2931
2978
|
kind: "command",
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
...requestScope ? { scope: requestScope } : {},
|
|
2937
|
-
services,
|
|
2938
|
-
metadata: command ?? route
|
|
2939
|
-
};
|
|
2940
|
-
const invokeRoute = () => modulePipeline(route.command ? commandContext : routeContext, once(() => routePipeline(routeContext, once(() => route.command ? commandPipeline(commandContext, once(invoke)) : invoke()))));
|
|
2941
|
-
const invokeCommand = () => {
|
|
2942
|
-
if (!route.command)
|
|
2943
|
-
return invokeRoute();
|
|
2944
|
-
if (!command) {
|
|
2945
|
-
throw new ApplicationError(`Command "${route.command}" is not registered`, {
|
|
2946
|
-
code: "COMMAND_NOT_REGISTERED"
|
|
2947
|
-
});
|
|
2948
|
-
}
|
|
2949
|
-
if (!commandExecutor) {
|
|
2950
|
-
throw new ApplicationError(`Command "${command.name}" has no executor`, {
|
|
2951
|
-
status: 501,
|
|
2952
|
-
code: "COMMAND_EXECUTOR_UNAVAILABLE"
|
|
2953
|
-
});
|
|
2954
|
-
}
|
|
2955
|
-
const invocation = {
|
|
2956
|
-
command,
|
|
2957
|
-
input,
|
|
2958
|
-
request: ctx.request,
|
|
2959
|
-
requestContext,
|
|
2960
|
-
...requestScope ? { scope: requestScope } : {},
|
|
2961
|
-
services
|
|
2962
|
-
};
|
|
2963
|
-
return observeExecution(options.onExecution, {
|
|
2964
|
-
kind: "command",
|
|
2965
|
-
operation: command.name,
|
|
2966
|
-
stage: "commandExecutor",
|
|
2967
|
-
...executionTrace(requestContext)
|
|
2968
|
-
}, () => commandExecutor(invocation, once(invokeRoute)));
|
|
2969
|
-
};
|
|
2970
|
-
return invokeCommand();
|
|
2979
|
+
operation: command.name,
|
|
2980
|
+
stage: "commandExecutor",
|
|
2981
|
+
...executionTrace(requestContext)
|
|
2982
|
+
}, () => commandExecutor(invocation, once(invokeRoute)));
|
|
2971
2983
|
};
|
|
2972
|
-
|
|
2973
|
-
assertDeclaredResponseStatus(route, result, ctx.set.status);
|
|
2974
|
-
return result;
|
|
2984
|
+
return invokeCommand();
|
|
2975
2985
|
};
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2986
|
+
const result = await execute();
|
|
2987
|
+
assertDeclaredResponseStatus(route, result, ctx.set.status);
|
|
2988
|
+
return result;
|
|
2989
|
+
};
|
|
2990
|
+
switch (route.method) {
|
|
2991
|
+
case "GET":
|
|
2992
|
+
routeRegistrar.get(path, schema, handler);
|
|
2993
|
+
break;
|
|
2994
|
+
case "POST":
|
|
2995
|
+
routeRegistrar.post(path, schema, handler);
|
|
2996
|
+
break;
|
|
2997
|
+
case "PUT":
|
|
2998
|
+
routeRegistrar.put(path, schema, handler);
|
|
2999
|
+
break;
|
|
3000
|
+
case "PATCH":
|
|
3001
|
+
routeRegistrar.patch(path, schema, handler);
|
|
3002
|
+
break;
|
|
3003
|
+
case "DELETE":
|
|
3004
|
+
routeRegistrar.delete(path, schema, handler);
|
|
3005
|
+
break;
|
|
3006
|
+
case "HEAD":
|
|
3007
|
+
routeRegistrar.head(path, schema, handler);
|
|
3008
|
+
break;
|
|
3009
|
+
case "OPTIONS":
|
|
3010
|
+
routeRegistrar.options(path, schema, handler);
|
|
3011
|
+
break;
|
|
2999
3012
|
}
|
|
3013
|
+
};
|
|
3014
|
+
compiled.registerRoutes?.(registerRoute);
|
|
3015
|
+
if (pendingRoutes.size > 0) {
|
|
3016
|
+
throw new ApplicationError(`Incomplete static route registration in module "${compiled.name}". Recompile the application.`, {
|
|
3017
|
+
code: "COMPILED_ROUTE_REGISTRATION_INVALID"
|
|
3018
|
+
});
|
|
3000
3019
|
}
|
|
3001
3020
|
return plugin;
|
|
3002
3021
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@supacloud/elysia",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.39.0",
|
|
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",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"directory": "packages/elysia"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@supacloud/app": "0.
|
|
57
|
+
"@supacloud/app": "0.37.0",
|
|
58
58
|
"@supacloud/commands": "0.11.2",
|
|
59
59
|
"@supacloud/contracts": "0.15.2",
|
|
60
60
|
"effect": "4.0.5",
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
"elysia": "2.0.0-rc.1"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
|
-
"@supacloud/compiler": "0.
|
|
75
|
+
"@supacloud/compiler": "0.56.0",
|
|
76
76
|
"@supacloud/delivery": "0.24.0",
|
|
77
77
|
"@supacloud/db": "0.20.5",
|
|
78
78
|
"@types/bun": "^1.4.4",
|