alien-middleware 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -35,7 +35,14 @@ interface HattipContext<TPlatform, TEnv extends object> extends AdapterRequestCo
|
|
|
35
35
|
* Converts a type `T` to something that can be intersected with an object.
|
|
36
36
|
*/
|
|
37
37
|
type Intersectable<T extends object> = [T] extends [never] ? {} : [T] extends [Any] ? Record<PropertyKey, any> : T;
|
|
38
|
-
|
|
38
|
+
/**
|
|
39
|
+
* An extensible Hattip context object.
|
|
40
|
+
*
|
|
41
|
+
* NOTE: When using this type on the right side of an `extends` clause, you
|
|
42
|
+
* should prefer `RequestContext<any>` over `RequestContext` (no type
|
|
43
|
+
* parameters), as the default type is stricter.
|
|
44
|
+
*/
|
|
45
|
+
type RequestContext<TProperties extends object = never, TEnv extends object = any, TPlatform = any> = HattipContext<TPlatform, TEnv> & Intersectable<TProperties>;
|
|
39
46
|
/**
|
|
40
47
|
* Extract a `RequestContext` type from a `MiddlewareChain` type.
|
|
41
48
|
*
|
|
@@ -71,13 +78,14 @@ type ApplyRequestPlugin<TParent extends MiddlewareChain, TPlugin extends Request
|
|
|
71
78
|
* parent chain.
|
|
72
79
|
*/
|
|
73
80
|
type ApplyMiddleware<TParent extends MiddlewareChain, TMiddleware> = TMiddleware extends MiddlewareChain ? RequestHandler<Inputs<TParent>, Current<TParent>, Platform<TParent>> : TMiddleware extends () => Awaitable<infer TPlugin extends RequestPlugin> ? RequestHandler<Inputs<TParent>, ApplyRequestPlugin<TParent, TPlugin>, Platform<TParent>> : RequestHandler<Inputs<TParent>, Current<TParent>, Platform<TParent>>;
|
|
74
|
-
type
|
|
81
|
+
type EmptyMiddlewareChain = MiddlewareChain<{
|
|
75
82
|
properties: {};
|
|
76
83
|
env: {};
|
|
77
84
|
}, {
|
|
78
85
|
properties: {};
|
|
79
86
|
env: {};
|
|
80
|
-
}, unknown
|
|
87
|
+
}, unknown>;
|
|
88
|
+
type ApplyFirstMiddleware<T extends Middleware> = T extends MiddlewareChain ? T : ApplyMiddleware<EmptyMiddlewareChain, T>;
|
|
81
89
|
type MergeMiddleware<TFirst extends MiddlewareChain, TSecond extends Middleware<Properties<TFirst>, Env<TFirst>, Platform<TFirst>>> = RequestHandler<Inputs<TFirst>, TSecond extends MiddlewareChain ? {
|
|
82
90
|
properties: Merge<Properties<TFirst>, Properties<TSecond>>;
|
|
83
91
|
env: Merge<Env<TFirst>, Env<TSecond>>;
|
|
@@ -135,4 +143,4 @@ declare function chain<TProperties extends object = {}, TEnv extends object = {}
|
|
|
135
143
|
}, TPlatform>;
|
|
136
144
|
declare function chain<const T extends Middleware = Middleware>(middleware: T): ApplyFirstMiddleware<T>;
|
|
137
145
|
|
|
138
|
-
export { type ApplyMiddleware as A, type
|
|
146
|
+
export { type ApplyMiddleware as A, type EmptyMiddlewareChain as E, MiddlewareChain as M, type RouteHandler as R, type MiddlewareContext as a, type RouteMethod as b, type RouterContext as c, chain as d, type ExtractMiddleware as e, type MergeMiddleware as f, type Middleware as g, type RequestContext as h, type RequestHandler as i, type RequestMiddleware as j, type RequestPlugin as k, type ResponseMiddleware as l };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { A as ApplyMiddleware,
|
|
1
|
+
export { A as ApplyMiddleware, e as ExtractMiddleware, f as MergeMiddleware, g as Middleware, M as MiddlewareChain, a as MiddlewareContext, h as RequestContext, i as RequestHandler, j as RequestMiddleware, k as RequestPlugin, l as ResponseMiddleware, d as chain } from './index-65huFY4B.js';
|
|
2
2
|
import '@hattip/core';
|
|
3
3
|
import 'radashi';
|
package/dist/router.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { InferParams } from 'pathic';
|
|
2
|
-
import { M as MiddlewareChain, a as MiddlewareContext, R as RouteHandler, b as RouteMethod } from './index-
|
|
2
|
+
import { M as MiddlewareChain, E as EmptyMiddlewareChain, a as MiddlewareContext, R as RouteHandler, b as RouteMethod } from './index-65huFY4B.js';
|
|
3
|
+
export { c as RouterContext } from './index-65huFY4B.js';
|
|
3
4
|
import '@hattip/core';
|
|
4
5
|
import 'radashi';
|
|
5
6
|
|
|
6
7
|
type OneOrMany<T> = T | readonly T[];
|
|
7
8
|
type Router<T extends MiddlewareChain = any> = ReturnType<typeof routes<T>>;
|
|
8
|
-
declare function routes<T extends MiddlewareChain>(middlewares?: T): {
|
|
9
|
+
declare function routes<T extends MiddlewareChain = EmptyMiddlewareChain>(middlewares?: T): {
|
|
9
10
|
(context: MiddlewareContext<T>): void | Response | Promise<void | Response> | undefined;
|
|
10
11
|
use: {
|
|
11
12
|
<TPath extends string>(path: TPath, handler: RouteHandler<T, InferParams<TPath>>): /*elided*/ any;
|
|
@@ -13,4 +14,4 @@ declare function routes<T extends MiddlewareChain>(middlewares?: T): {
|
|
|
13
14
|
};
|
|
14
15
|
};
|
|
15
16
|
|
|
16
|
-
export { type Router, routes };
|
|
17
|
+
export { RouteHandler, type Router, routes };
|