@sourceregistry/sveltekit-enhance 1.7.2 → 1.8.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
@@ -80,6 +80,22 @@ export const handle = enhance.handle(
80
80
  );
81
81
  ```
82
82
 
83
+ An enhancer can bypass all remaining enhancers and the custom handler while still resolving the request through SvelteKit's normal routing with `resolveToRoute`:
84
+
85
+ ```ts
86
+ export const handle = enhance.handle(
87
+ async ({ event, resolveToRoute }) => {
88
+ if (event.url.pathname === '/healthz') {
89
+ return resolveToRoute(event);
90
+ }
91
+ },
92
+ enhancerA,
93
+ enhancerB,
94
+ );
95
+ ```
96
+
97
+ `resolveToRoute` invokes SvelteKit's native resolver, so the matching page or `+server.ts` endpoint still runs and normal headers and cookies are preserved. It skips the remaining `enhance.handle` enhancers and the custom handler. `resolve` continues through the remaining enhancers as usual. `resolveToRoute` may also be thrown when integrating with code that uses exception-based control flow.
98
+
83
99
  #### SSE / streaming responses
84
100
 
85
101
  `enhance.handle` automatically detects Server-Sent Events and other streaming requests (via `Accept: text/event-stream`) and bypasses the main handler entirely — going straight to SvelteKit's `resolve`. This prevents the handler from blocking indefinitely on `await resolve(event)`, which never settles for a streaming response.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type Action, type ActionResult, type Cookies, type Handle, type RequestEvent, type ResolveOptions, type ServerLoadEvent } from '@sveltejs/kit';
1
+ import { type Action, type ActionResult, type Cookies, redirect as SRedirect, type Handle, type RequestEvent, type ResolveOptions, type ServerLoadEvent } from '@sveltejs/kit';
2
2
  import type { RouteId as AppRouteId, LayoutParams as AppLayoutParams } from '$app/types';
3
3
  export type MaybePromise<T> = T | Promise<T>;
4
4
  export type EnhanceErrorHandler = <T = any>(err: unknown) => MaybePromise<T | Response | undefined | never | void>;
@@ -49,6 +49,11 @@ export type EnhanceInput<CallType extends EnhanceCallType = EnhanceCallType, Par
49
49
  } & (CallType extends 'handle' ? {
50
50
  get responseHandlers(): EnhanceResponseHandler[];
51
51
  resolve: (event?: RequestEvent, opts?: ResolveOptions) => MaybePromise<Response>;
52
+ /**
53
+ * Resolve the request through SvelteKit directly, bypassing all remaining
54
+ * enhancers and the custom handle function.
55
+ */
56
+ resolveToRoute: (event?: RequestEvent, opts?: ResolveOptions) => MaybePromise<Response>;
52
57
  readonly event: RequestEvent;
53
58
  } : CallType extends 'load' ? {
54
59
  parent: ServerLoadEvent<Params, ParentData, RouteId>['parent'];
@@ -89,6 +94,7 @@ export declare const error: (status: number, body?: {
89
94
  message: string;
90
95
  } extends App.Error ? App.Error | string | undefined : never) => never;
91
96
  export declare const success: <T extends Record<string, unknown> | undefined = undefined>(data: T) => T;
97
+ export declare const redirect: typeof SRedirect;
92
98
  export declare function not_good(input: {
93
99
  callType: EnhanceInput['callType'];
94
100
  }, status: number, arg?: App.Error | string | Record<string, unknown> | undefined): never;
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { error as SError, fail as SFail, isActionFailure, isHttpError, isRedirect } from '@sveltejs/kit';
1
+ import { error as SError, fail as SFail, redirect as SRedirect, isActionFailure, isHttpError, isRedirect } from '@sveltejs/kit';
2
2
  const EnhanceErrorHandle = async (e, contextInput) => {
3
3
  if (isRedirect(e) || isHttpError(e)) {
4
4
  throw e;
@@ -134,6 +134,10 @@ export const handle = (handle, ...contexts) => async (input) => {
134
134
  resolved = true;
135
135
  return apply_handle(contexts.length, event, opts);
136
136
  },
137
+ resolveToRoute: (event = input.event, opts) => {
138
+ resolved = true;
139
+ return input.resolve(event, opts);
140
+ },
137
141
  get event() {
138
142
  return input.event;
139
143
  }
@@ -159,10 +163,15 @@ export const handle = (handle, ...contexts) => async (input) => {
159
163
  if (i < contexts.length) {
160
164
  const context = contexts[i];
161
165
  const previous_resolve = contextInput.resolve;
166
+ const previous_resolveToRoute = contextInput.resolveToRoute;
162
167
  contextInput.resolve = (next_event = event, options) => {
163
168
  resolved = true;
164
169
  return apply_handle(i + 1, next_event, merge_options(parent_options, options));
165
170
  };
171
+ contextInput.resolveToRoute = (next_event = event, options) => {
172
+ resolved = true;
173
+ return input.resolve(next_event, merge_options(parent_options, options));
174
+ };
166
175
  try {
167
176
  resolved = false;
168
177
  const result = await context(contextInput);
@@ -179,6 +188,7 @@ export const handle = (handle, ...contexts) => async (input) => {
179
188
  }
180
189
  finally {
181
190
  contextInput.resolve = previous_resolve;
191
+ contextInput.resolveToRoute = previous_resolveToRoute;
182
192
  }
183
193
  }
184
194
  // SSE responses cannot be awaited — bypass the main handler to avoid blocking
@@ -223,6 +233,7 @@ export const fail = (status, data) => {
223
233
  };
224
234
  export const error = (status, body) => SError(status, body);
225
235
  export const success = (data) => data;
236
+ export const redirect = SRedirect;
226
237
  export function not_good(input, status, arg) {
227
238
  // Based on callType, call the appropriate function.
228
239
  return (input.callType === 'action' ? fail : error)(status, arg);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sourceregistry/sveltekit-enhance",
3
- "version": "1.7.2",
3
+ "version": "1.8.0",
4
4
  "description": "Composable enhance and form utilities for SvelteKit actions, loads, methods, and hooks.",
5
5
  "author": "A.P.A. Slaa (a.p.a.slaa@projectsource.nl)",
6
6
  "scripts": {