@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 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
- for (const controller of compiled.controllers) {
2782
- for (const route of controller.routes) {
2783
- const path = joinPaths(controller.path, route.path);
2784
- const documentation = route.data?.openapi;
2785
- const hidden = documentation !== null && typeof documentation === "object" && "hide" in documentation && documentation.hide === true;
2786
- const tags = documentation !== null && typeof documentation === "object" && "tags" in documentation && Array.isArray(documentation.tags) ? documentation.tags.filter((tag) => typeof tag === "string") : undefined;
2787
- const schema = {
2788
- ...toElysiaRouteSchema(route),
2789
- ...route.parse === "none" ? { parse: "none" } : {},
2790
- ...route.title || hidden || tags ? { detail: {
2791
- ...route.title ? { summary: route.title } : {},
2792
- ...hidden ? { hide: true } : {},
2793
- ...tags ? { tags } : {}
2794
- } } : {}
2795
- };
2796
- const policies = compileHttpPolicies(route, path, options.httpPolicies);
2797
- if (policies.length > 0) {
2798
- Object.assign(schema, {
2799
- beforeHandle: async (context) => {
2800
- for (const policy of policies) {
2801
- const result = await policy({
2802
- http: context,
2803
- requestContext: requestContexts.get(context.request)
2804
- });
2805
- if (result instanceof Response)
2806
- return result;
2807
- if (result !== undefined) {
2808
- throw new Error("HTTP policies must return Response or undefined");
2809
- }
2810
- }
2811
- if (route.idempotency === "required") {
2812
- requireRouteIdempotencyKey(context.request);
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
- const responsePolicies = policies.filter((policy) => policy.afterResponse);
2824
- const mappingPolicies = policies.filter((policy) => policy.mapResponse);
2825
- const routePipeline = descriptorPipeline(route, "route", options.onExecution);
2826
- const command = route.command ? commandsByClassName.get(route.command) : undefined;
2827
- const commandPipeline = route.command ? descriptorPipeline(command ?? {}, "command", options.onExecution) : undefined;
2828
- const routeInvoker = route.invoker;
2829
- if (mappingPolicies.length > 0) {
2830
- const responseValidators = Validator2.response(schema.response, { normalize: options.normalize ?? true });
2831
- Object.assign(schema, {
2832
- mapResponse: async (context) => {
2833
- let response = context.responseValue;
2834
- let mapped;
2835
- for (const policy of mappingPolicies) {
2836
- const result = await policy.mapResponse({
2837
- http: context,
2838
- requestContext: requestContexts.get(context.request),
2839
- response,
2840
- encodeResponse: (value) => {
2841
- const validator = responseValidators?.get(responseStatusOf(value, context.set.status));
2842
- if (!validator)
2843
- return value;
2844
- if (!("EncodeFrom" in validator) || typeof validator.EncodeFrom !== "function") {
2845
- throw new ApplicationError("Response validation failed", { code: "RESPONSE_VALIDATION_FAILED" });
2846
- }
2847
- if ("mayReturnPromise" in validator && validator.mayReturnPromise && "From" in validator && typeof validator.From === "function") {
2848
- return validator.From.call(validator, value, "response", true);
2849
- }
2850
- return validator.EncodeFrom.call(validator, value, "response");
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
- if (responsePolicies.length > 0) {
2865
- Object.assign(schema, {
2866
- afterResponse: async (context) => {
2867
- for (const policy of responsePolicies) {
2868
- await policy.afterResponse({
2869
- http: context,
2870
- requestContext: requestContexts.get(context.request),
2871
- response: context.responseValue
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
- const directRoute = canUseDirectRoute(compiled, controller, route) && options.onExecution === undefined && policies.length === 0 && responsePolicies.length === 0 && mappingPolicies.length === 0;
2878
- const directController = directRoute && route.directInvokerFast !== undefined ? controllerInstance(services[controller.serviceKey]) : undefined;
2879
- const directMethod = directController?.[route.handler];
2880
- const directInvokerFast = route.directInvokerFast;
2881
- const directHandler = directController && typeof directMethod === "function" && directInvokerFast ? (ctx) => directInvokerFast(directController, directMethod, ctx) : (ctx) => route.directInvoker(services[controller.serviceKey], ctx);
2882
- const handler = directRoute ? directHandler : async (ctx) => {
2883
- const requestContext = requestContexts.get(ctx.request);
2884
- const execute = async () => {
2885
- const requestScope = createRequestScope ? await createRequestScope(services, requestContext, imported) : undefined;
2886
- if (requestScope && compiled.destroyRequestScope)
2887
- requestScopes.set(ctx.request, requestScope);
2888
- const source = controller.scope === "request" ? requestScope : services;
2889
- const instance = source?.[controller.serviceKey];
2890
- const normalizedCookie = ctx.cookie === undefined ? undefined : cookieValues(ctx.cookie);
2891
- const input = {
2892
- body: ctx.body,
2893
- params: ctx.params,
2894
- query: ctx.query,
2895
- headers: ctx.headers ?? Object.fromEntries(ctx.request.headers.entries()),
2896
- ...normalizedCookie === undefined ? {} : { cookie: normalizedCookie },
2897
- context: requestContext,
2898
- request: ctx.request,
2899
- ...requestScope ? { scope: requestScope } : {},
2900
- requestContext
2901
- };
2902
- const handlerCall = () => {
2903
- if (route.invoker)
2904
- return route.invoker(instance, input);
2905
- if (!isRecord2(instance))
2906
- throw new TypeError("Route controller is not an object");
2907
- const method = instance[route.handler];
2908
- if (typeof method !== "function")
2909
- throw new TypeError(`Route handler ${route.handler} is not callable`);
2910
- return method.call(instance, input);
2911
- };
2912
- const invokeHandler = async () => runCompiledEffect(await handlerCall(), route.effect, options.effectRuntime);
2913
- const invoke = once(() => route.command && options.commandGovernance ? invokeHandler() : options.onExecution ? observeExecution(options.onExecution, {
2914
- kind: route.command ? "command" : "route",
2915
- operation: route.command ?? `${route.method} ${path}`,
2916
- stage: "handler",
2917
- ...executionTrace(requestContext)
2918
- }, invokeHandler) : invokeHandler());
2919
- const routeContext = {
2920
- kind: "route",
2921
- name: `${route.method} ${path}`,
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
- const command = route.command === undefined ? undefined : resolveCompiledCommand(compiled, route.command);
2930
- const commandContext = route.command === undefined ? routeContext : {
2977
+ return observeExecution(options.onExecution, {
2931
2978
  kind: "command",
2932
- name: command?.name ?? route.command,
2933
- input,
2934
- request: ctx.request,
2935
- requestContext,
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
- const result = await execute();
2973
- assertDeclaredResponseStatus(route, result, ctx.set.status);
2974
- return result;
2984
+ return invokeCommand();
2975
2985
  };
2976
- switch (route.method) {
2977
- case "GET":
2978
- routeRegistrar.get(path, schema, handler);
2979
- break;
2980
- case "POST":
2981
- routeRegistrar.post(path, schema, handler);
2982
- break;
2983
- case "PUT":
2984
- routeRegistrar.put(path, schema, handler);
2985
- break;
2986
- case "PATCH":
2987
- routeRegistrar.patch(path, schema, handler);
2988
- break;
2989
- case "DELETE":
2990
- routeRegistrar.delete(path, schema, handler);
2991
- break;
2992
- case "HEAD":
2993
- routeRegistrar.head(path, schema, handler);
2994
- break;
2995
- case "OPTIONS":
2996
- routeRegistrar.options(path, schema, handler);
2997
- break;
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
- for (const controller of compiled.controllers) {
2782
- for (const route of controller.routes) {
2783
- const path = joinPaths(controller.path, route.path);
2784
- const documentation = route.data?.openapi;
2785
- const hidden = documentation !== null && typeof documentation === "object" && "hide" in documentation && documentation.hide === true;
2786
- const tags = documentation !== null && typeof documentation === "object" && "tags" in documentation && Array.isArray(documentation.tags) ? documentation.tags.filter((tag) => typeof tag === "string") : undefined;
2787
- const schema = {
2788
- ...toElysiaRouteSchema(route),
2789
- ...route.parse === "none" ? { parse: "none" } : {},
2790
- ...route.title || hidden || tags ? { detail: {
2791
- ...route.title ? { summary: route.title } : {},
2792
- ...hidden ? { hide: true } : {},
2793
- ...tags ? { tags } : {}
2794
- } } : {}
2795
- };
2796
- const policies = compileHttpPolicies(route, path, options.httpPolicies);
2797
- if (policies.length > 0) {
2798
- Object.assign(schema, {
2799
- beforeHandle: async (context) => {
2800
- for (const policy of policies) {
2801
- const result = await policy({
2802
- http: context,
2803
- requestContext: requestContexts.get(context.request)
2804
- });
2805
- if (result instanceof Response)
2806
- return result;
2807
- if (result !== undefined) {
2808
- throw new Error("HTTP policies must return Response or undefined");
2809
- }
2810
- }
2811
- if (route.idempotency === "required") {
2812
- requireRouteIdempotencyKey(context.request);
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
- const responsePolicies = policies.filter((policy) => policy.afterResponse);
2824
- const mappingPolicies = policies.filter((policy) => policy.mapResponse);
2825
- const routePipeline = descriptorPipeline(route, "route", options.onExecution);
2826
- const command = route.command ? commandsByClassName.get(route.command) : undefined;
2827
- const commandPipeline = route.command ? descriptorPipeline(command ?? {}, "command", options.onExecution) : undefined;
2828
- const routeInvoker = route.invoker;
2829
- if (mappingPolicies.length > 0) {
2830
- const responseValidators = Validator2.response(schema.response, { normalize: options.normalize ?? true });
2831
- Object.assign(schema, {
2832
- mapResponse: async (context) => {
2833
- let response = context.responseValue;
2834
- let mapped;
2835
- for (const policy of mappingPolicies) {
2836
- const result = await policy.mapResponse({
2837
- http: context,
2838
- requestContext: requestContexts.get(context.request),
2839
- response,
2840
- encodeResponse: (value) => {
2841
- const validator = responseValidators?.get(responseStatusOf(value, context.set.status));
2842
- if (!validator)
2843
- return value;
2844
- if (!("EncodeFrom" in validator) || typeof validator.EncodeFrom !== "function") {
2845
- throw new ApplicationError("Response validation failed", { code: "RESPONSE_VALIDATION_FAILED" });
2846
- }
2847
- if ("mayReturnPromise" in validator && validator.mayReturnPromise && "From" in validator && typeof validator.From === "function") {
2848
- return validator.From.call(validator, value, "response", true);
2849
- }
2850
- return validator.EncodeFrom.call(validator, value, "response");
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
- if (responsePolicies.length > 0) {
2865
- Object.assign(schema, {
2866
- afterResponse: async (context) => {
2867
- for (const policy of responsePolicies) {
2868
- await policy.afterResponse({
2869
- http: context,
2870
- requestContext: requestContexts.get(context.request),
2871
- response: context.responseValue
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
- const directRoute = canUseDirectRoute(compiled, controller, route) && options.onExecution === undefined && policies.length === 0 && responsePolicies.length === 0 && mappingPolicies.length === 0;
2878
- const directController = directRoute && route.directInvokerFast !== undefined ? controllerInstance(services[controller.serviceKey]) : undefined;
2879
- const directMethod = directController?.[route.handler];
2880
- const directInvokerFast = route.directInvokerFast;
2881
- const directHandler = directController && typeof directMethod === "function" && directInvokerFast ? (ctx) => directInvokerFast(directController, directMethod, ctx) : (ctx) => route.directInvoker(services[controller.serviceKey], ctx);
2882
- const handler = directRoute ? directHandler : async (ctx) => {
2883
- const requestContext = requestContexts.get(ctx.request);
2884
- const execute = async () => {
2885
- const requestScope = createRequestScope ? await createRequestScope(services, requestContext, imported) : undefined;
2886
- if (requestScope && compiled.destroyRequestScope)
2887
- requestScopes.set(ctx.request, requestScope);
2888
- const source = controller.scope === "request" ? requestScope : services;
2889
- const instance = source?.[controller.serviceKey];
2890
- const normalizedCookie = ctx.cookie === undefined ? undefined : cookieValues(ctx.cookie);
2891
- const input = {
2892
- body: ctx.body,
2893
- params: ctx.params,
2894
- query: ctx.query,
2895
- headers: ctx.headers ?? Object.fromEntries(ctx.request.headers.entries()),
2896
- ...normalizedCookie === undefined ? {} : { cookie: normalizedCookie },
2897
- context: requestContext,
2898
- request: ctx.request,
2899
- ...requestScope ? { scope: requestScope } : {},
2900
- requestContext
2901
- };
2902
- const handlerCall = () => {
2903
- if (route.invoker)
2904
- return route.invoker(instance, input);
2905
- if (!isRecord2(instance))
2906
- throw new TypeError("Route controller is not an object");
2907
- const method = instance[route.handler];
2908
- if (typeof method !== "function")
2909
- throw new TypeError(`Route handler ${route.handler} is not callable`);
2910
- return method.call(instance, input);
2911
- };
2912
- const invokeHandler = async () => runCompiledEffect(await handlerCall(), route.effect, options.effectRuntime);
2913
- const invoke = once(() => route.command && options.commandGovernance ? invokeHandler() : options.onExecution ? observeExecution(options.onExecution, {
2914
- kind: route.command ? "command" : "route",
2915
- operation: route.command ?? `${route.method} ${path}`,
2916
- stage: "handler",
2917
- ...executionTrace(requestContext)
2918
- }, invokeHandler) : invokeHandler());
2919
- const routeContext = {
2920
- kind: "route",
2921
- name: `${route.method} ${path}`,
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
- const command = route.command === undefined ? undefined : resolveCompiledCommand(compiled, route.command);
2930
- const commandContext = route.command === undefined ? routeContext : {
2977
+ return observeExecution(options.onExecution, {
2931
2978
  kind: "command",
2932
- name: command?.name ?? route.command,
2933
- input,
2934
- request: ctx.request,
2935
- requestContext,
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
- const result = await execute();
2973
- assertDeclaredResponseStatus(route, result, ctx.set.status);
2974
- return result;
2984
+ return invokeCommand();
2975
2985
  };
2976
- switch (route.method) {
2977
- case "GET":
2978
- routeRegistrar.get(path, schema, handler);
2979
- break;
2980
- case "POST":
2981
- routeRegistrar.post(path, schema, handler);
2982
- break;
2983
- case "PUT":
2984
- routeRegistrar.put(path, schema, handler);
2985
- break;
2986
- case "PATCH":
2987
- routeRegistrar.patch(path, schema, handler);
2988
- break;
2989
- case "DELETE":
2990
- routeRegistrar.delete(path, schema, handler);
2991
- break;
2992
- case "HEAD":
2993
- routeRegistrar.head(path, schema, handler);
2994
- break;
2995
- case "OPTIONS":
2996
- routeRegistrar.options(path, schema, handler);
2997
- break;
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.38.2",
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.36.1",
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.55.1",
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",