@effect/platform 0.13.1 → 0.13.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.
- package/Http/Headers.d.ts +3 -3
- package/Http/Headers.d.ts.map +1 -1
- package/Http/Headers.js +16 -11
- package/Http/Headers.js.map +1 -1
- package/Http/IncomingMessage.d.ts.map +1 -1
- package/Http/IncomingMessage.js +1 -1
- package/Http/IncomingMessage.js.map +1 -1
- package/internal/http/client.js +1 -1
- package/internal/http/client.js.map +1 -1
- package/internal/http/middleware.js +7 -6
- package/internal/http/middleware.js.map +1 -1
- package/internal/http/router.js +17 -16
- package/internal/http/router.js.map +1 -1
- package/internal/http/serverResponse.js +15 -12
- package/internal/http/serverResponse.js.map +1 -1
- package/mjs/Http/Headers.mjs +16 -11
- package/mjs/Http/Headers.mjs.map +1 -1
- package/mjs/Http/IncomingMessage.mjs +1 -1
- package/mjs/Http/IncomingMessage.mjs.map +1 -1
- package/mjs/internal/http/client.mjs +1 -1
- package/mjs/internal/http/client.mjs.map +1 -1
- package/mjs/internal/http/middleware.mjs +7 -6
- package/mjs/internal/http/middleware.mjs.map +1 -1
- package/mjs/internal/http/router.mjs +17 -16
- package/mjs/internal/http/router.mjs.map +1 -1
- package/mjs/internal/http/serverResponse.mjs +15 -12
- package/mjs/internal/http/serverResponse.mjs.map +1 -1
- package/package.json +4 -4
- package/src/Http/Headers.ts +23 -17
- package/src/Http/IncomingMessage.ts +1 -2
- package/src/internal/http/client.ts +18 -21
- package/src/internal/http/middleware.ts +21 -15
- package/src/internal/http/router.ts +30 -24
- package/src/internal/http/serverResponse.ts +15 -13
|
@@ -95,15 +95,12 @@ const toHttpApp = <R, E>(
|
|
|
95
95
|
self: Router.Router<R, E>
|
|
96
96
|
): App.Default<Exclude<R, Router.RouteContext>, E | Error.RouteNotFound> => {
|
|
97
97
|
const router = FindMyWay()
|
|
98
|
-
Chunk.
|
|
99
|
-
|
|
100
|
-
fn.handler = Effect.updateService(app, ServerRequest.ServerRequest, (request) => sliceRequestUrl(request, path))
|
|
101
|
-
router.all(path, fn)
|
|
102
|
-
router.all(path + "/*", fn)
|
|
103
|
-
})
|
|
98
|
+
const mounts = Chunk.toReadonlyArray(self.mounts)
|
|
99
|
+
const mountsLen = mounts.length
|
|
104
100
|
Chunk.forEach(self.routes, (route) => {
|
|
105
|
-
|
|
106
|
-
|
|
101
|
+
function fn(_: any, __: any) {
|
|
102
|
+
return route
|
|
103
|
+
}
|
|
107
104
|
if (route.method === "*") {
|
|
108
105
|
router.all(route.path, fn)
|
|
109
106
|
} else {
|
|
@@ -113,27 +110,36 @@ const toHttpApp = <R, E>(
|
|
|
113
110
|
return Effect.flatMap(
|
|
114
111
|
ServerRequest.ServerRequest,
|
|
115
112
|
(request): App.Default<Exclude<R, Router.RouteContext>, E | Error.RouteNotFound> => {
|
|
113
|
+
if (mountsLen > 0) {
|
|
114
|
+
for (let i = 0; i < mountsLen; i++) {
|
|
115
|
+
const [path, app] = mounts[i]
|
|
116
|
+
if (request.url.startsWith(path)) {
|
|
117
|
+
return Effect.provideService(
|
|
118
|
+
app,
|
|
119
|
+
ServerRequest.ServerRequest,
|
|
120
|
+
sliceRequestUrl(request, path)
|
|
121
|
+
) as App.Default<Exclude<R, Router.RouteContext>, E>
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
116
126
|
const result = router.find(request.method as HTTPMethod, request.url)
|
|
117
127
|
if (result === null) {
|
|
118
128
|
return Effect.fail(Error.RouteNotFound({ request }))
|
|
119
129
|
}
|
|
120
|
-
const
|
|
121
|
-
if (
|
|
122
|
-
|
|
123
|
-
if (route.prefix._tag === "Some") {
|
|
124
|
-
request = sliceRequestUrl(request, route.prefix.value)
|
|
125
|
-
}
|
|
126
|
-
return Effect.mapInputContext(
|
|
127
|
-
route.handler,
|
|
128
|
-
(context) =>
|
|
129
|
-
Context.add(
|
|
130
|
-
Context.add(context, ServerRequest.ServerRequest, request),
|
|
131
|
-
RouteContext,
|
|
132
|
-
new RouteContextImpl(result.params, result.searchParams)
|
|
133
|
-
) as Context.Context<R>
|
|
134
|
-
)
|
|
130
|
+
const route = (result.handler as any)() as Router.Route<R, E>
|
|
131
|
+
if (route.prefix._tag === "Some") {
|
|
132
|
+
request = sliceRequestUrl(request, route.prefix.value)
|
|
135
133
|
}
|
|
136
|
-
return (
|
|
134
|
+
return Effect.mapInputContext(
|
|
135
|
+
route.handler,
|
|
136
|
+
(context) =>
|
|
137
|
+
Context.add(
|
|
138
|
+
Context.add(context, ServerRequest.ServerRequest, request),
|
|
139
|
+
RouteContext,
|
|
140
|
+
new RouteContextImpl(result.params, result.searchParams)
|
|
141
|
+
) as Context.Context<R>
|
|
142
|
+
)
|
|
137
143
|
}
|
|
138
144
|
)
|
|
139
145
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { dual } from "@effect/data/Function"
|
|
2
|
-
import * as Option from "@effect/data/Option"
|
|
3
2
|
import { pipeArguments } from "@effect/data/Pipeable"
|
|
4
3
|
import * as Effect from "@effect/io/Effect"
|
|
5
4
|
import type * as PlatformError from "@effect/platform/Error"
|
|
@@ -20,13 +19,26 @@ export const TypeId: ServerResponse.TypeId = Symbol.for("@effect/platform/Http/S
|
|
|
20
19
|
|
|
21
20
|
class ServerResponseImpl implements ServerResponse.ServerResponse {
|
|
22
21
|
readonly [TypeId]: ServerResponse.TypeId
|
|
22
|
+
readonly headers: Headers.Headers
|
|
23
23
|
constructor(
|
|
24
24
|
readonly status: number,
|
|
25
25
|
readonly statusText: string | undefined,
|
|
26
|
-
|
|
26
|
+
headers: Headers.Headers,
|
|
27
27
|
readonly body: Body.Body
|
|
28
28
|
) {
|
|
29
29
|
this[TypeId] = TypeId
|
|
30
|
+
if (body.contentType || body.contentLength) {
|
|
31
|
+
const newHeaders = { ...headers }
|
|
32
|
+
if (body.contentType) {
|
|
33
|
+
newHeaders["content-type"] = body.contentType
|
|
34
|
+
}
|
|
35
|
+
if (body.contentLength) {
|
|
36
|
+
newHeaders["content-length"] = body.contentLength.toString()
|
|
37
|
+
}
|
|
38
|
+
this.headers = newHeaders
|
|
39
|
+
} else {
|
|
40
|
+
this.headers = headers
|
|
41
|
+
}
|
|
30
42
|
}
|
|
31
43
|
pipe() {
|
|
32
44
|
return pipeArguments(this, arguments)
|
|
@@ -197,7 +209,7 @@ export const getContentType = (options?: ServerResponse.Options): string | undef
|
|
|
197
209
|
if (options?.contentType) {
|
|
198
210
|
return options.contentType
|
|
199
211
|
} else if (options?.headers) {
|
|
200
|
-
return
|
|
212
|
+
return options.headers["content-type"]
|
|
201
213
|
} else {
|
|
202
214
|
return
|
|
203
215
|
}
|
|
@@ -247,16 +259,6 @@ export const setBody = dual<
|
|
|
247
259
|
let headers = self.headers
|
|
248
260
|
if (body._tag === "Empty") {
|
|
249
261
|
headers = Headers.remove(Headers.remove(headers, "Content-Type"), "Content-length")
|
|
250
|
-
} else {
|
|
251
|
-
const contentType = body.contentType
|
|
252
|
-
if (contentType) {
|
|
253
|
-
headers = Headers.set(headers, "content-type", contentType)
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
const contentLength = body.contentLength
|
|
257
|
-
if (contentLength) {
|
|
258
|
-
headers = Headers.set(headers, "content-length", contentLength.toString())
|
|
259
|
-
}
|
|
260
262
|
}
|
|
261
263
|
return new ServerResponseImpl(
|
|
262
264
|
self.status,
|