@effect/platform 0.37.7 → 0.37.8
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/cjs/Http/App.js +20 -4
- package/dist/cjs/Http/App.js.map +1 -1
- package/dist/cjs/Http/ClientResponse.js.map +1 -1
- package/dist/cjs/Http/Router.js.map +1 -1
- package/dist/cjs/Http/Server.js.map +1 -1
- package/dist/cjs/Http/ServerError.js +14 -1
- package/dist/cjs/Http/ServerError.js.map +1 -1
- package/dist/cjs/Http/ServerRequest.js.map +1 -1
- package/dist/cjs/internal/http/middleware.js +5 -4
- package/dist/cjs/internal/http/middleware.js.map +1 -1
- package/dist/cjs/internal/http/router.js.map +1 -1
- package/dist/cjs/internal/http/serverError.js +14 -1
- package/dist/cjs/internal/http/serverError.js.map +1 -1
- package/dist/dts/Http/App.d.ts +5 -7
- package/dist/dts/Http/App.d.ts.map +1 -1
- package/dist/dts/Http/ClientResponse.d.ts +2 -3
- package/dist/dts/Http/ClientResponse.d.ts.map +1 -1
- package/dist/dts/Http/Router.d.ts +45 -40
- package/dist/dts/Http/Router.d.ts.map +1 -1
- package/dist/dts/Http/Server.d.ts +4 -4
- package/dist/dts/Http/Server.d.ts.map +1 -1
- package/dist/dts/Http/ServerError.d.ts +15 -0
- package/dist/dts/Http/ServerError.d.ts.map +1 -1
- package/dist/dts/Http/ServerRequest.d.ts +1 -0
- package/dist/dts/Http/ServerRequest.d.ts.map +1 -1
- package/dist/dts/internal/http/router.d.ts +1 -1
- package/dist/dts/internal/http/router.d.ts.map +1 -1
- package/dist/esm/Http/App.js +20 -4
- package/dist/esm/Http/App.js.map +1 -1
- package/dist/esm/Http/ClientResponse.js.map +1 -1
- package/dist/esm/Http/Router.js.map +1 -1
- package/dist/esm/Http/Server.js.map +1 -1
- package/dist/esm/Http/ServerError.js +13 -0
- package/dist/esm/Http/ServerError.js.map +1 -1
- package/dist/esm/Http/ServerRequest.js.map +1 -1
- package/dist/esm/internal/http/middleware.js +5 -4
- package/dist/esm/internal/http/middleware.js.map +1 -1
- package/dist/esm/internal/http/router.js.map +1 -1
- package/dist/esm/internal/http/serverError.js +11 -0
- package/dist/esm/internal/http/serverError.js.map +1 -1
- package/package.json +1 -1
- package/src/Http/App.ts +26 -12
- package/src/Http/ClientResponse.ts +1 -2
- package/src/Http/Router.ts +79 -43
- package/src/Http/Server.ts +12 -4
- package/src/Http/ServerError.ts +18 -0
- package/src/Http/ServerRequest.ts +1 -0
- package/src/internal/http/middleware.ts +9 -4
- package/src/internal/http/router.ts +1 -1
- package/src/internal/http/server.ts +5 -5
- package/src/internal/http/serverError.ts +22 -0
package/src/Http/Server.ts
CHANGED
|
@@ -104,17 +104,25 @@ export const make: (
|
|
|
104
104
|
* @category accessors
|
|
105
105
|
*/
|
|
106
106
|
export const serve: {
|
|
107
|
-
(): <R, E>(
|
|
107
|
+
(): <R, E>(
|
|
108
|
+
httpApp: App.Default<R, E>
|
|
109
|
+
) => Layer.Layer<Server | Exclude<R, ServerRequest.ServerRequest | Scope.Scope>, never, never>
|
|
108
110
|
<R, E, App extends App.Default<any, any>>(
|
|
109
111
|
middleware: Middleware.Middleware.Applied<R, E, App>
|
|
110
112
|
): (
|
|
111
113
|
httpApp: App.Default<R, E>
|
|
112
|
-
) => Layer.Layer<
|
|
113
|
-
|
|
114
|
+
) => Layer.Layer<
|
|
115
|
+
Server | Exclude<Effect.Effect.Context<App>, ServerRequest.ServerRequest | Scope.Scope>,
|
|
116
|
+
never,
|
|
117
|
+
never
|
|
118
|
+
>
|
|
119
|
+
<R, E>(
|
|
120
|
+
httpApp: App.Default<R, E>
|
|
121
|
+
): Layer.Layer<Server | Exclude<R, ServerRequest.ServerRequest | Scope.Scope>, never, never>
|
|
114
122
|
<R, E, App extends App.Default<any, any>>(
|
|
115
123
|
httpApp: App.Default<R, E>,
|
|
116
124
|
middleware: Middleware.Middleware.Applied<R, E, App>
|
|
117
|
-
): Layer.Layer<Server | Exclude<Effect.Effect.Context<App>, ServerRequest.ServerRequest>, never, never>
|
|
125
|
+
): Layer.Layer<Server | Exclude<Effect.Effect.Context<App>, ServerRequest.ServerRequest | Scope.Scope>, never, never>
|
|
118
126
|
} = internal.serve
|
|
119
127
|
|
|
120
128
|
/**
|
package/src/Http/ServerError.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @since 1.0.0
|
|
3
3
|
*/
|
|
4
|
+
import type * as Cause from "effect/Cause"
|
|
4
5
|
import type * as Data from "effect/Data"
|
|
6
|
+
import type * as FiberId from "effect/FiberId"
|
|
5
7
|
import * as internal from "../internal/http/serverError.js"
|
|
6
8
|
import type * as ServerRequest from "./ServerRequest.js"
|
|
7
9
|
import type * as ServerResponse from "./ServerResponse.js"
|
|
@@ -54,6 +56,12 @@ export interface RequestError extends HttpError.Proto {
|
|
|
54
56
|
readonly error: unknown
|
|
55
57
|
}
|
|
56
58
|
|
|
59
|
+
/**
|
|
60
|
+
* @since 1.0.0
|
|
61
|
+
* @category predicates
|
|
62
|
+
*/
|
|
63
|
+
export const isServerError: (u: unknown) => u is HttpServerError = internal.isServerError
|
|
64
|
+
|
|
57
65
|
/**
|
|
58
66
|
* @since 1.0.0
|
|
59
67
|
* @category error
|
|
@@ -109,3 +117,13 @@ export interface ServeError extends HttpError.Proto {
|
|
|
109
117
|
* @category error
|
|
110
118
|
*/
|
|
111
119
|
export const ServeError: (props: Omit<ServeError, HttpError.ProvidedFields>) => ServeError = internal.serveError
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* @since 1.0.0
|
|
123
|
+
*/
|
|
124
|
+
export const clientAbortFiberId: FiberId.FiberId = internal.clientAbortFiberId
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* @since 1.0.0
|
|
128
|
+
*/
|
|
129
|
+
export const isClientAbortCause: <E>(cause: Cause.Cause<E>) => boolean = internal.isClientAbortCause
|
|
@@ -42,6 +42,7 @@ export type TypeId = typeof TypeId
|
|
|
42
42
|
*/
|
|
43
43
|
export interface ServerRequest extends IncomingMessage.IncomingMessage<Error.RequestError> {
|
|
44
44
|
readonly [TypeId]: TypeId
|
|
45
|
+
readonly source: unknown
|
|
45
46
|
readonly url: string
|
|
46
47
|
readonly originalUrl: string
|
|
47
48
|
readonly method: Method
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import * as Cause from "effect/Cause"
|
|
2
2
|
import * as Effect from "effect/Effect"
|
|
3
3
|
import * as FiberRef from "effect/FiberRef"
|
|
4
|
-
import
|
|
4
|
+
import { constFalse, dual } from "effect/Function"
|
|
5
5
|
import { globalValue } from "effect/GlobalValue"
|
|
6
6
|
import type * as Predicate from "effect/Predicate"
|
|
7
7
|
import * as Headers from "../../Http/Headers.js"
|
|
8
8
|
import * as IncomingMessage from "../../Http/IncomingMessage.js"
|
|
9
9
|
import type * as Middleware from "../../Http/Middleware.js"
|
|
10
|
+
import * as ServerError from "../../Http/ServerError.js"
|
|
10
11
|
import * as ServerRequest from "../../Http/ServerRequest.js"
|
|
11
12
|
|
|
12
13
|
/** @internal */
|
|
@@ -28,11 +29,11 @@ export const withLoggerDisabled = <R, E, A>(self: Effect.Effect<R, E, A>): Effec
|
|
|
28
29
|
/** @internal */
|
|
29
30
|
export const currentTracerDisabledWhen = globalValue(
|
|
30
31
|
Symbol.for("@effect/platform/Http/Middleware/tracerDisabledWhen"),
|
|
31
|
-
() => FiberRef.unsafeMake<Predicate.Predicate<ServerRequest.ServerRequest>>(
|
|
32
|
+
() => FiberRef.unsafeMake<Predicate.Predicate<ServerRequest.ServerRequest>>(constFalse)
|
|
32
33
|
)
|
|
33
34
|
|
|
34
35
|
/** @internal */
|
|
35
|
-
export const withTracerDisabledWhen =
|
|
36
|
+
export const withTracerDisabledWhen = dual<
|
|
36
37
|
(
|
|
37
38
|
predicate: Predicate.Predicate<ServerRequest.ServerRequest>
|
|
38
39
|
) => <R, E, A>(effect: Effect.Effect<R, E, A>) => Effect.Effect<R, E, A>,
|
|
@@ -60,7 +61,11 @@ export const logger = make((httpApp) => {
|
|
|
60
61
|
Effect.annotateLogs(Effect.log(exit.cause), {
|
|
61
62
|
"http.method": request.method,
|
|
62
63
|
"http.url": request.url,
|
|
63
|
-
"http.status": Cause.isInterruptedOnly(exit.cause)
|
|
64
|
+
"http.status": Cause.isInterruptedOnly(exit.cause)
|
|
65
|
+
? ServerError.isClientAbortCause(exit.cause)
|
|
66
|
+
? 499
|
|
67
|
+
: 503
|
|
68
|
+
: 500
|
|
64
69
|
}) :
|
|
65
70
|
Effect.annotateLogs(Effect.log(""), {
|
|
66
71
|
"http.method": request.method,
|
|
@@ -185,7 +185,7 @@ export const makeRoute = <R, E>(
|
|
|
185
185
|
path: Router.PathInput,
|
|
186
186
|
handler: Router.Route.Handler<R, E>,
|
|
187
187
|
prefix: Option.Option<string> = Option.none()
|
|
188
|
-
): Router.Route<R
|
|
188
|
+
): Router.Route<Router.Router.ExcludeProvided<R>, E> => new RouteImpl(method, path, handler, prefix) as any
|
|
189
189
|
|
|
190
190
|
/** @internal */
|
|
191
191
|
export const concat = dual<
|
|
@@ -38,14 +38,14 @@ export const serve = dual<
|
|
|
38
38
|
(): <R, E>(
|
|
39
39
|
httpApp: App.Default<R, E>
|
|
40
40
|
) => Layer.Layer<
|
|
41
|
-
Server.Server | Exclude<R, ServerRequest.ServerRequest>,
|
|
41
|
+
Server.Server | Exclude<R, ServerRequest.ServerRequest | Scope.Scope>,
|
|
42
42
|
never,
|
|
43
43
|
never
|
|
44
44
|
>
|
|
45
45
|
<R, E, App extends App.Default<any, any>>(middleware: Middleware.Middleware.Applied<R, E, App>): (
|
|
46
46
|
httpApp: App.Default<R, E>
|
|
47
47
|
) => Layer.Layer<
|
|
48
|
-
Server.Server | Exclude<Effect.Effect.Context<App>, ServerRequest.ServerRequest>,
|
|
48
|
+
Server.Server | Exclude<Effect.Effect.Context<App>, ServerRequest.ServerRequest | Scope.Scope>,
|
|
49
49
|
never,
|
|
50
50
|
never
|
|
51
51
|
>
|
|
@@ -53,12 +53,12 @@ export const serve = dual<
|
|
|
53
53
|
{
|
|
54
54
|
<R, E>(
|
|
55
55
|
httpApp: App.Default<R, E>
|
|
56
|
-
): Layer.Layer<Server.Server | Exclude<R, ServerRequest.ServerRequest>, never, never>
|
|
56
|
+
): Layer.Layer<Server.Server | Exclude<R, ServerRequest.ServerRequest | Scope.Scope>, never, never>
|
|
57
57
|
<R, E, App extends App.Default<any, any>>(
|
|
58
58
|
httpApp: App.Default<R, E>,
|
|
59
59
|
middleware: Middleware.Middleware.Applied<R, E, App>
|
|
60
60
|
): Layer.Layer<
|
|
61
|
-
Server.Server | Exclude<Effect.Effect.Context<App>, ServerRequest.ServerRequest>,
|
|
61
|
+
Server.Server | Exclude<Effect.Effect.Context<App>, ServerRequest.ServerRequest | Scope.Scope>,
|
|
62
62
|
never,
|
|
63
63
|
never
|
|
64
64
|
>
|
|
@@ -69,7 +69,7 @@ export const serve = dual<
|
|
|
69
69
|
httpApp: App.Default<R, E>,
|
|
70
70
|
middleware?: Middleware.Middleware.Applied<R, E, App>
|
|
71
71
|
): Layer.Layer<
|
|
72
|
-
Server.Server | Exclude<Effect.Effect.Context<App>, ServerRequest.ServerRequest>,
|
|
72
|
+
Server.Server | Exclude<Effect.Effect.Context<App>, ServerRequest.ServerRequest | Scope.Scope>,
|
|
73
73
|
never,
|
|
74
74
|
never
|
|
75
75
|
> =>
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
+
import * as Cause from "effect/Cause"
|
|
1
2
|
import * as Data from "effect/Data"
|
|
3
|
+
import * as FiberId from "effect/FiberId"
|
|
4
|
+
import { globalValue } from "effect/GlobalValue"
|
|
5
|
+
import * as Option from "effect/Option"
|
|
6
|
+
import * as Predicate from "effect/Predicate"
|
|
2
7
|
import type * as Error from "../../Http/ServerError.js"
|
|
3
8
|
|
|
4
9
|
/** @internal */
|
|
@@ -13,6 +18,9 @@ const make = <A extends Error.HttpServerError>(tag: A["_tag"]) => (props: Omit<A
|
|
|
13
18
|
...props
|
|
14
19
|
} as A)
|
|
15
20
|
|
|
21
|
+
/** @internal */
|
|
22
|
+
export const isServerError = (u: unknown): u is Error.HttpServerError => Predicate.hasProperty(u, TypeId)
|
|
23
|
+
|
|
16
24
|
/** @internal */
|
|
17
25
|
export const requestError = make<Error.RequestError>("RequestError")
|
|
18
26
|
|
|
@@ -24,3 +32,17 @@ export const routeNotFound = make<Error.RouteNotFound>("RouteNotFound")
|
|
|
24
32
|
|
|
25
33
|
/** @internal */
|
|
26
34
|
export const serveError = make<Error.ServeError>("ServeError")
|
|
35
|
+
|
|
36
|
+
/** @internal */
|
|
37
|
+
export const clientAbortFiberId = globalValue(
|
|
38
|
+
"@effect/platform/Http/ServerError/clientAbortFiberId",
|
|
39
|
+
() => FiberId.runtime(-499, 0)
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
/** @internal */
|
|
43
|
+
export const isClientAbortCause = <E>(cause: Cause.Cause<E>): boolean =>
|
|
44
|
+
Cause.reduce(
|
|
45
|
+
cause,
|
|
46
|
+
false,
|
|
47
|
+
(_, cause) => cause._tag === "Interrupt" && cause.fiberId === clientAbortFiberId ? Option.some(true) : Option.none()
|
|
48
|
+
)
|