alien-middleware 0.8.0 → 0.8.2
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.
|
@@ -81,7 +81,7 @@ type ApplyRequestPlugin<TParent extends MiddlewareChain, TPlugin extends Request
|
|
|
81
81
|
* chain, it's treated as a nested chain, which won't leak its plugins into the
|
|
82
82
|
* parent chain.
|
|
83
83
|
*/
|
|
84
|
-
type ApplyMiddleware<TFirst extends MiddlewareChain, TSecond extends Middleware<Env<TFirst>, Properties<TFirst>, Platform<TFirst>>> = RequestHandler<Inputs<TFirst>, TSecond extends MiddlewareChain ? MiddlewareTypes<Merge<Env<TFirst>, Env<TSecond>>, Merge<Properties<TFirst>, Properties<TSecond>>> : TSecond extends () => Awaitable<infer TResult> ? TResult extends RequestPlugin ? ApplyRequestPlugin<TFirst, TResult> : Current<TFirst> : Current<TFirst>, Platform<TFirst>>;
|
|
84
|
+
type ApplyMiddleware<TFirst extends MiddlewareChain, TSecond extends Middleware<Env<TFirst>, Properties<TFirst>, Platform<TFirst>>> = RequestHandler<Inputs<TFirst>, TSecond extends MiddlewareChain ? MiddlewareTypes<Merge<Env<TFirst>, Env<TSecond>>, Merge<Properties<TFirst>, Properties<TSecond>>> : TSecond extends (...args: any[]) => Awaitable<infer TResult> ? TResult extends RequestPlugin ? ApplyRequestPlugin<TFirst, TResult> : Current<TFirst> : Current<TFirst>, Platform<TFirst>>;
|
|
85
85
|
type EmptyMiddlewareChain = MiddlewareChain<MiddlewareTypes<{}, {}>, MiddlewareTypes<{}, {}>, unknown>;
|
|
86
86
|
type ApplyFirstMiddleware<T extends Middleware> = T extends MiddlewareChain ? T : ApplyMiddleware<EmptyMiddlewareChain, T>;
|
|
87
87
|
type RouteMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'OPTIONS' | 'HEAD';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import 'radashi';
|
|
2
|
-
export { A as ApplyMiddleware, e as ExtractMiddleware, f as Middleware, M as MiddlewareChain, a as MiddlewareContext, g as RequestContext, h as RequestHandler, i as RequestMiddleware, j as RequestPlugin, k as ResponseMiddleware, d as chain } from './index-
|
|
2
|
+
export { A as ApplyMiddleware, e as ExtractMiddleware, f as Middleware, M as MiddlewareChain, a as MiddlewareContext, g as RequestContext, h as RequestHandler, i as RequestMiddleware, j as RequestPlugin, k as ResponseMiddleware, d as chain } from './index-Bpx2B6hx.js';
|
|
3
3
|
import '@hattip/core';
|
package/dist/router.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { InferParams } from 'pathic';
|
|
2
|
-
import { M as MiddlewareChain, E as EmptyMiddlewareChain, a as MiddlewareContext, R as RouteHandler, b as RouteMethod } from './index-
|
|
3
|
-
export { c as RouterContext } from './index-
|
|
2
|
+
import { M as MiddlewareChain, E as EmptyMiddlewareChain, a as MiddlewareContext, R as RouteHandler, b as RouteMethod } from './index-Bpx2B6hx.js';
|
|
3
|
+
export { c as RouterContext } from './index-Bpx2B6hx.js';
|
|
4
4
|
import 'radashi';
|
|
5
5
|
import '@hattip/core';
|
|
6
6
|
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -121,7 +121,7 @@ Request middleware runs sequentially before a `Response` is generated.
|
|
|
121
121
|
return { user }
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
const greetUser = (context: RequestContext<{ user: User }>) => {
|
|
124
|
+
const greetUser = (context: RequestContext<{}, { user: User }>) => {
|
|
125
125
|
// The `user` property is now available thanks to `addUser`
|
|
126
126
|
return new Response(`Hello, ${context.user.name}!`)
|
|
127
127
|
}
|
|
@@ -138,7 +138,7 @@ Request middleware runs sequentially before a `Response` is generated.
|
|
|
138
138
|
return { env: { API_KEY: 'secret123' } }
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
-
const useApiKey = (context: RequestContext<
|
|
141
|
+
const useApiKey = (context: RequestContext<{ API_KEY: string }>) => {
|
|
142
142
|
const key = context.env('API_KEY')
|
|
143
143
|
console.log('API Key:', key) // Output: API Key: secret123
|
|
144
144
|
}
|
|
@@ -267,7 +267,7 @@ type Env = {
|
|
|
267
267
|
API_KEY: string
|
|
268
268
|
}
|
|
269
269
|
|
|
270
|
-
const app = chain<
|
|
270
|
+
const app = chain<Env>().use(context => {
|
|
271
271
|
const key = context.env('API_KEY')
|
|
272
272
|
// ^? string
|
|
273
273
|
})
|
|
@@ -279,7 +279,7 @@ When defining a middleware, you can declare env types that the middleware expect
|
|
|
279
279
|
import type { RequestContext } from 'alien-middleware'
|
|
280
280
|
|
|
281
281
|
// Assuming `Env` is defined like in the previous example.
|
|
282
|
-
const myMiddleware = (context: RequestContext<
|
|
282
|
+
const myMiddleware = (context: RequestContext<Env>) => {
|
|
283
283
|
const key = context.env('API_KEY')
|
|
284
284
|
}
|
|
285
285
|
```
|