@stacksjs/bun-router 0.1.11 → 0.1.13
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/dist/chunk-7s1kcj7w.js +357 -0
- package/dist/{chunk-7g1et0fb.js → chunk-sccx6r6k.js} +16 -16
- package/dist/cli.js +1 -1
- package/dist/container/index.js +1 -1
- package/dist/crypto.d.ts +2 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +29 -29
- package/dist/request/context.d.ts +6 -0
- package/dist/response/compression.d.ts +11 -10
- package/dist/router/handler-resolver.d.ts +1 -1
- package/dist/router/router.d.ts +3 -5
- package/dist/types.d.ts +2 -0
- package/package.json +2 -2
- package/bin/cli.ts +0 -9
- package/dist/chunk-trm3jyqk.js +0 -357
|
@@ -21,6 +21,12 @@ export declare function enableRequestContext(): void;
|
|
|
21
21
|
* each request automatically.
|
|
22
22
|
*/
|
|
23
23
|
export declare function runWithRequest<T>(initial: EnhancedRequest | Request, fn: () => T | Promise<T>): T | Promise<T>;
|
|
24
|
+
/**
|
|
25
|
+
* Run a two-argument dispatcher inside request context without allocating a
|
|
26
|
+
* callback closure. This is useful for routing adapters whose dispatcher and
|
|
27
|
+
* request-local state are already available as stable arguments.
|
|
28
|
+
*/
|
|
29
|
+
export declare function runWithRequestArguments<T, A, B>(initial: EnhancedRequest | Request, fn: (first: A, second: B) => T | Promise<T>, first: A, second: B): T | Promise<T>;
|
|
24
30
|
/**
|
|
25
31
|
* Update the request stored in the current context. The Router calls this
|
|
26
32
|
* after enhancing the request with matched route params, so subsequent
|
|
@@ -14,7 +14,9 @@
|
|
|
14
14
|
* is a cache that breaks that client.
|
|
15
15
|
* - **Only when it is worth it.** Below a kilobyte the header costs more than
|
|
16
16
|
* the saving, and already-compressed bytes (an image, a woff2, a zip) get
|
|
17
|
-
* bigger rather than smaller.
|
|
17
|
+
* bigger rather than smaller. A client that excludes identity still needs
|
|
18
|
+
* an acceptable encoding for small text bodies, or an empty 406 when the
|
|
19
|
+
* available response cannot be encoded.
|
|
18
20
|
* - **Never by buffering.** The body is piped through a `CompressionStream`
|
|
19
21
|
* rather than read into memory, so a response that streams keeps streaming:
|
|
20
22
|
* the diff manifest that sends a hundred files as they parse still arrives a
|
|
@@ -41,7 +43,7 @@ export interface CompressionOptions {
|
|
|
41
43
|
* does not make.
|
|
42
44
|
*/
|
|
43
45
|
level?: CompressionLevel;
|
|
44
|
-
/** Bodies below this many bytes
|
|
46
|
+
/** Bodies below this many bytes stay unencoded when identity is acceptable. */
|
|
45
47
|
threshold?: number;
|
|
46
48
|
}
|
|
47
49
|
export declare const DEFAULT_COMPRESSION: Required<CompressionOptions>;
|
|
@@ -58,13 +60,10 @@ export declare function isCompressible(contentType: string | null): boolean;
|
|
|
58
60
|
/**
|
|
59
61
|
* The encoding to use, from what the client offered.
|
|
60
62
|
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
* Brotli is not offered even though Bun can produce it: `Bun.gzipSync` is
|
|
66
|
-
* synchronous and brotli is not, and a compression step that awaits inside the
|
|
67
|
-
* response path is a different change from this one.
|
|
63
|
+
* Highest quality first, with gzip before deflate on ties. Only these two
|
|
64
|
+
* codings are supported by this CompressionStream path. An explicit identity
|
|
65
|
+
* preference can win; an implicit identity offer remains the fallback.
|
|
66
|
+
* Malformed named weights are unavailable, including through a wildcard.
|
|
68
67
|
*/
|
|
69
68
|
export declare function negotiateEncoding(header: string | null): 'gzip' | 'deflate' | null;
|
|
70
69
|
/**
|
|
@@ -82,7 +81,9 @@ export declare function shouldCompress(response: Response, encoding: string | nu
|
|
|
82
81
|
* The response, compressed when that is the right thing to do.
|
|
83
82
|
*
|
|
84
83
|
* Returns the response it was given when it is not, so a caller can apply this
|
|
85
|
-
* unconditionally at the end of the pipeline.
|
|
84
|
+
* unconditionally at the end of the pipeline. When identity is refused and
|
|
85
|
+
* no available coding is acceptable, replaces an unencoded body with an empty
|
|
86
|
+
* 406. Caller-encoded responses and explicit disable options remain untouched.
|
|
86
87
|
*/
|
|
87
88
|
export declare function applyResponseCompression(response: Response, request: Request, options?: CompressionOptions): Response | Promise<Response>;
|
|
88
89
|
/**
|
|
@@ -29,4 +29,4 @@ export declare function createHandlerResolver(config: RouterConfig): (handler: u
|
|
|
29
29
|
* resolves the branch once and returns a specialized invoker for the
|
|
30
30
|
* per-request hot path.
|
|
31
31
|
*/
|
|
32
|
-
export declare function createHandlerInvoker(handler: unknown, config: RouterConfig): (req: EnhancedRequest) => Promise<Response>;
|
|
32
|
+
export declare function createHandlerInvoker(handler: unknown, config: RouterConfig): (req: EnhancedRequest) => Response | Promise<Response>;
|
package/dist/router/router.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Server } from 'bun';
|
|
2
2
|
import type { MiddlewareDependency, MiddlewarePipeline, MiddlewarePipelineStats, MiddlewareSkipCondition } from '../middleware/pipeline';
|
|
3
|
-
import type { ActionHandler, CookieOptions, EnhancedRequest, MiddlewareHandler, MiddlewareReference, Route, RouteGroup, RouteHandler, RouterConfig, TypedRouteHandler, WebSocketConfig, WebSocketData } from '../types';
|
|
3
|
+
import type { ActionHandler, CookieOptions, EnhancedRequest, MiddlewareHandler, MiddlewareReference, Route, RouteGroup, RouteHandler, RouterConfig, ServerOptions, TypedRouteHandler, WebSocketConfig, WebSocketData } from '../types';
|
|
4
4
|
/**
|
|
5
5
|
* Route compiler interface for pattern matching
|
|
6
6
|
*/
|
|
@@ -43,6 +43,7 @@ export declare class Router {
|
|
|
43
43
|
precompiledPatterns: Map<string, RegExp>;
|
|
44
44
|
domainPatternCache: Map<string, RegExp>;
|
|
45
45
|
routeCompiler: RouteCompiler | null;
|
|
46
|
+
_hasDomainRoutes: boolean;
|
|
46
47
|
private middlewareGroups;
|
|
47
48
|
private namedMiddleware;
|
|
48
49
|
private conditionalMiddleware;
|
|
@@ -170,10 +171,7 @@ export declare class Router {
|
|
|
170
171
|
/**
|
|
171
172
|
* Start the HTTP server
|
|
172
173
|
*/
|
|
173
|
-
serve(options?:
|
|
174
|
-
port?: number;
|
|
175
|
-
hostname?: string;
|
|
176
|
-
}): Promise<Server<WebSocketData>>;
|
|
174
|
+
serve(options?: ServerOptions): Promise<Server<WebSocketData>>;
|
|
177
175
|
/**
|
|
178
176
|
* Handle an HTTP request
|
|
179
177
|
*/
|
package/dist/types.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { Server } from 'bun';
|
|
|
2
2
|
import type { Router } from './router/router';
|
|
3
3
|
import type { KnownActionPath, MiddlewareReference } from './types/registry';
|
|
4
4
|
import type { SessionManager } from './session/index';
|
|
5
|
+
import type { CompressionOptions } from './response/compression';
|
|
5
6
|
import type { QueryPreservationConfig } from './utils/query-preservation';
|
|
6
7
|
import type { AuthContext, AuthenticatedUser, BoundModels, CacheAdapter, CacheStats, CookieToDelete, CookieToSet, ErrorMetadata, FallbackError, FileInfo, FlashMessages, FormBody, InputValidationSchemas, InputValue, JsonBodyData, JwtHeader, JwtPayload, MetricEntry, MiddlewareParams, OAuth2Flows, OAuth2Profile, RequestContext, RequestInput, RouteMetadata, SanitizationOptions, SanitizationRule, SessionData, SessionSerializer, SessionStore, SSEConnection, StaticResponseBody, TemplateHelper, TemplateHelpers, TraceAttributes, TraceSpan, TypedServerWebSocket, User, ValidatedBody, ValidatedData, ValidationSchema, WebSocketData } from './types/core';
|
|
7
8
|
export type { QueryPreservationConfig } from './utils/query-preservation';
|
|
@@ -614,6 +615,7 @@ export interface ViewRenderOptions {
|
|
|
614
615
|
}
|
|
615
616
|
export interface RouterConfig {
|
|
616
617
|
verbose: boolean;
|
|
618
|
+
compression?: CompressionOptions;
|
|
617
619
|
routesPath?: string;
|
|
618
620
|
apiRoutesPath?: string;
|
|
619
621
|
webRoutesPath?: string;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacksjs/bun-router",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.13",
|
|
5
5
|
"description": "A fast, type-safe router for Bun.",
|
|
6
6
|
"author": "Chris Breuer <chris@stacksjs.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"types": "./dist/index.d.ts",
|
|
61
61
|
"bin": {
|
|
62
62
|
"bun-router": "./dist/cli.js",
|
|
63
|
-
"router": "./
|
|
63
|
+
"router": "./dist/cli.js"
|
|
64
64
|
},
|
|
65
65
|
"files": [
|
|
66
66
|
"README.md",
|
package/bin/cli.ts
DELETED