@effect/platform 0.13.9 → 0.13.10
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/Body.d.ts +40 -21
- package/Http/Body.d.ts.map +1 -1
- package/Http/Body.js +14 -8
- package/Http/Body.js.map +1 -1
- package/Http/Client.d.ts +1 -1
- package/Http/Client.d.ts.map +1 -1
- package/Http/ClientRequest.d.ts +4 -24
- package/Http/ClientRequest.d.ts.map +1 -1
- package/Http/ClientRequest.js +1 -7
- package/Http/ClientRequest.js.map +1 -1
- package/Http/ServerResponse.d.ts +2 -25
- package/Http/ServerResponse.d.ts.map +1 -1
- package/Http/ServerResponse.js +2 -13
- package/Http/ServerResponse.js.map +1 -1
- package/internal/http/body.js +24 -15
- package/internal/http/body.js.map +1 -1
- package/internal/http/client.d.ts.map +1 -1
- package/internal/http/client.js +1 -6
- package/internal/http/client.js.map +1 -1
- package/internal/http/clientRequest.js +3 -14
- package/internal/http/clientRequest.js.map +1 -1
- package/internal/http/serverResponse.js +3 -16
- package/internal/http/serverResponse.js.map +1 -1
- package/mjs/Http/Body.mjs +10 -5
- package/mjs/Http/Body.mjs.map +1 -1
- package/mjs/Http/ClientRequest.mjs +0 -5
- package/mjs/Http/ClientRequest.mjs.map +1 -1
- package/mjs/Http/ServerResponse.mjs +0 -9
- package/mjs/Http/ServerResponse.mjs.map +1 -1
- package/mjs/internal/http/body.mjs +20 -12
- package/mjs/internal/http/body.mjs.map +1 -1
- package/mjs/internal/http/client.mjs +1 -6
- package/mjs/internal/http/client.mjs.map +1 -1
- package/mjs/internal/http/clientRequest.mjs +2 -11
- package/mjs/internal/http/clientRequest.mjs.map +1 -1
- package/mjs/internal/http/serverResponse.mjs +2 -13
- package/mjs/internal/http/serverResponse.mjs.map +1 -1
- package/package.json +1 -1
- package/src/Http/Body.ts +46 -24
- package/src/Http/Client.ts +1 -1
- package/src/Http/ClientRequest.ts +7 -27
- package/src/Http/ServerResponse.ts +6 -34
- package/src/internal/http/body.ts +22 -22
- package/src/internal/http/client.ts +3 -11
- package/src/internal/http/clientRequest.ts +15 -39
- package/src/internal/http/serverResponse.ts +22 -52
|
@@ -43,17 +43,9 @@ const setProto = <R, E, A>(
|
|
|
43
43
|
/** @internal */
|
|
44
44
|
export const make = (
|
|
45
45
|
f: (
|
|
46
|
-
request: ClientRequest.ClientRequest
|
|
46
|
+
request: ClientRequest.ClientRequest
|
|
47
47
|
) => Effect.Effect<never, Error.HttpClientError, ClientResponse.ClientResponse>
|
|
48
|
-
): Client.Client.Default =>
|
|
49
|
-
function client(request: ClientRequest.ClientRequest) {
|
|
50
|
-
return Effect.flatMap(
|
|
51
|
-
internalRequest.resolveBody(request),
|
|
52
|
-
(request) => f(request)
|
|
53
|
-
)
|
|
54
|
-
}
|
|
55
|
-
return setProto(client)
|
|
56
|
-
}
|
|
48
|
+
): Client.Client.Default => setProto(f)
|
|
57
49
|
|
|
58
50
|
/** @internal */
|
|
59
51
|
export const fetch = (
|
|
@@ -98,7 +90,7 @@ export const fetch = (
|
|
|
98
90
|
)
|
|
99
91
|
)
|
|
100
92
|
|
|
101
|
-
const convertBody = (body: Body.
|
|
93
|
+
const convertBody = (body: Body.Body): BodyInit | undefined => {
|
|
102
94
|
switch (body._tag) {
|
|
103
95
|
case "Empty":
|
|
104
96
|
return undefined
|
|
@@ -10,7 +10,6 @@ import * as Headers from "@effect/platform/Http/Headers"
|
|
|
10
10
|
import type { Method } from "@effect/platform/Http/Method"
|
|
11
11
|
import * as UrlParams from "@effect/platform/Http/UrlParams"
|
|
12
12
|
import * as internalBody from "@effect/platform/internal/http/body"
|
|
13
|
-
import * as internalError from "@effect/platform/internal/http/clientError"
|
|
14
13
|
import type * as Schema from "@effect/schema/Schema"
|
|
15
14
|
import type * as Stream from "@effect/stream/Stream"
|
|
16
15
|
|
|
@@ -313,20 +312,6 @@ export const uint8ArrayBody = dual<
|
|
|
313
312
|
(self, body, contentType = "application/octet-stream") => setBody(self, internalBody.uint8Array(body, contentType))
|
|
314
313
|
)
|
|
315
314
|
|
|
316
|
-
/** @internal */
|
|
317
|
-
export const effectBody = dual<
|
|
318
|
-
(
|
|
319
|
-
body: Effect.Effect<never, unknown, Body.NonEffect>
|
|
320
|
-
) => (self: ClientRequest.ClientRequest) => ClientRequest.ClientRequest,
|
|
321
|
-
(
|
|
322
|
-
self: ClientRequest.ClientRequest,
|
|
323
|
-
body: Effect.Effect<never, unknown, Body.NonEffect>
|
|
324
|
-
) => ClientRequest.ClientRequest
|
|
325
|
-
>(
|
|
326
|
-
2,
|
|
327
|
-
(self, body) => setBody(self, internalBody.effect(body))
|
|
328
|
-
)
|
|
329
|
-
|
|
330
315
|
/** @internal */
|
|
331
316
|
export const textBody = dual<
|
|
332
317
|
(body: string, contentType?: string) => (self: ClientRequest.ClientRequest) => ClientRequest.ClientRequest,
|
|
@@ -338,9 +323,14 @@ export const textBody = dual<
|
|
|
338
323
|
|
|
339
324
|
/** @internal */
|
|
340
325
|
export const jsonBody = dual<
|
|
341
|
-
(
|
|
342
|
-
|
|
343
|
-
|
|
326
|
+
(
|
|
327
|
+
body: unknown
|
|
328
|
+
) => (self: ClientRequest.ClientRequest) => Effect.Effect<never, Body.BodyError, ClientRequest.ClientRequest>,
|
|
329
|
+
(
|
|
330
|
+
self: ClientRequest.ClientRequest,
|
|
331
|
+
body: unknown
|
|
332
|
+
) => Effect.Effect<never, Body.BodyError, ClientRequest.ClientRequest>
|
|
333
|
+
>(2, (self, body) => Effect.map(internalBody.json(body), (body) => setBody(self, body)))
|
|
344
334
|
|
|
345
335
|
/** @internal */
|
|
346
336
|
export const unsafeJsonBody = dual<
|
|
@@ -368,14 +358,16 @@ export const fileBody = dual<
|
|
|
368
358
|
|
|
369
359
|
/** @internal */
|
|
370
360
|
export const schemaBody = <I, A>(schema: Schema.Schema<I, A>): {
|
|
371
|
-
(body: A): (self: ClientRequest.ClientRequest) => ClientRequest.ClientRequest
|
|
372
|
-
(self: ClientRequest.ClientRequest, body: A): ClientRequest.ClientRequest
|
|
361
|
+
(body: A): (self: ClientRequest.ClientRequest) => Effect.Effect<never, Body.BodyError, ClientRequest.ClientRequest>
|
|
362
|
+
(self: ClientRequest.ClientRequest, body: A): Effect.Effect<never, Body.BodyError, ClientRequest.ClientRequest>
|
|
373
363
|
} => {
|
|
374
364
|
const encode = internalBody.jsonSchema(schema)
|
|
375
365
|
return dual<
|
|
376
|
-
(
|
|
377
|
-
|
|
378
|
-
|
|
366
|
+
(
|
|
367
|
+
body: A
|
|
368
|
+
) => (self: ClientRequest.ClientRequest) => Effect.Effect<never, Body.BodyError, ClientRequest.ClientRequest>,
|
|
369
|
+
(self: ClientRequest.ClientRequest, body: A) => Effect.Effect<never, Body.BodyError, ClientRequest.ClientRequest>
|
|
370
|
+
>(2, (self, body) => Effect.map(encode(body), (body) => setBody(self, body)))
|
|
379
371
|
}
|
|
380
372
|
|
|
381
373
|
/** @internal */
|
|
@@ -419,19 +411,3 @@ export const streamBody = dual<
|
|
|
419
411
|
(self, body, { contentLength, contentType = "application/octet-stream" } = {}) =>
|
|
420
412
|
setBody(self, internalBody.stream(body, contentType, contentLength))
|
|
421
413
|
)
|
|
422
|
-
|
|
423
|
-
/** @internal */
|
|
424
|
-
export const resolveBody = (
|
|
425
|
-
self: ClientRequest.ClientRequest
|
|
426
|
-
): Effect.Effect<never, Error.RequestError, ClientRequest.ClientRequest.NonEffectBody> =>
|
|
427
|
-
self.body._tag === "Effect"
|
|
428
|
-
? Effect.map(
|
|
429
|
-
Effect.mapError(self.body.effect, (error) =>
|
|
430
|
-
internalError.requestError({
|
|
431
|
-
reason: "Encode",
|
|
432
|
-
request: self,
|
|
433
|
-
error
|
|
434
|
-
})),
|
|
435
|
-
(body) => setBody(self, body) as ClientRequest.ClientRequest.NonEffectBody
|
|
436
|
-
)
|
|
437
|
-
: Effect.succeed(self as ClientRequest.ClientRequest.NonEffectBody)
|
|
@@ -6,12 +6,9 @@ import * as FileSystem from "@effect/platform/FileSystem"
|
|
|
6
6
|
import type * as Body from "@effect/platform/Http/Body"
|
|
7
7
|
import * as Etag from "@effect/platform/Http/Etag"
|
|
8
8
|
import * as Headers from "@effect/platform/Http/Headers"
|
|
9
|
-
import type * as Error from "@effect/platform/Http/ServerError"
|
|
10
|
-
import * as ServerRequest from "@effect/platform/Http/ServerRequest"
|
|
11
9
|
import type * as ServerResponse from "@effect/platform/Http/ServerResponse"
|
|
12
10
|
import * as UrlParams from "@effect/platform/Http/UrlParams"
|
|
13
11
|
import * as internalBody from "@effect/platform/internal/http/body"
|
|
14
|
-
import * as internalError from "@effect/platform/internal/http/serverError"
|
|
15
12
|
import type * as Schema from "@effect/schema/Schema"
|
|
16
13
|
import type * as Stream from "@effect/stream/Stream"
|
|
17
14
|
import * as Mime from "mime"
|
|
@@ -51,29 +48,6 @@ class ServerResponseImpl implements ServerResponse.ServerResponse {
|
|
|
51
48
|
export const isServerResponse = (u: unknown): u is ServerResponse.ServerResponse =>
|
|
52
49
|
typeof u === "object" && u !== null && TypeId in u
|
|
53
50
|
|
|
54
|
-
/** @internal */
|
|
55
|
-
export const toNonEffectBody = (
|
|
56
|
-
self: ServerResponse.ServerResponse
|
|
57
|
-
): Effect.Effect<ServerRequest.ServerRequest, Error.ResponseError, ServerResponse.ServerResponse.NonEffectBody> =>
|
|
58
|
-
self.body._tag === "Effect" ?
|
|
59
|
-
Effect.map(
|
|
60
|
-
Effect.catchAll(self.body.effect, (error) =>
|
|
61
|
-
Effect.flatMap(
|
|
62
|
-
ServerRequest.ServerRequest,
|
|
63
|
-
(request) =>
|
|
64
|
-
Effect.fail(
|
|
65
|
-
internalError.responseError({
|
|
66
|
-
reason: "Decode",
|
|
67
|
-
request,
|
|
68
|
-
response: self,
|
|
69
|
-
error
|
|
70
|
-
})
|
|
71
|
-
)
|
|
72
|
-
)),
|
|
73
|
-
(body) => setBody(self, body) as ServerResponse.ServerResponse.NonEffectBody
|
|
74
|
-
) :
|
|
75
|
-
Effect.succeed(self as ServerResponse.ServerResponse.NonEffectBody)
|
|
76
|
-
|
|
77
51
|
/** @internal */
|
|
78
52
|
export const empty = (options?: ServerResponse.Options.WithContent): ServerResponse.ServerResponse =>
|
|
79
53
|
new ServerResponseImpl(
|
|
@@ -105,13 +79,17 @@ export const text = (body: string, options?: ServerResponse.Options.WithContentT
|
|
|
105
79
|
)
|
|
106
80
|
|
|
107
81
|
/** @internal */
|
|
108
|
-
export const json = (
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
82
|
+
export const json = (
|
|
83
|
+
body: unknown,
|
|
84
|
+
options?: ServerResponse.Options.WithContent
|
|
85
|
+
): Effect.Effect<never, Body.BodyError, ServerResponse.ServerResponse> =>
|
|
86
|
+
Effect.map(internalBody.json(body), (body) =>
|
|
87
|
+
new ServerResponseImpl(
|
|
88
|
+
options?.status ?? 200,
|
|
89
|
+
options?.statusText,
|
|
90
|
+
options?.headers ?? Headers.empty,
|
|
91
|
+
body
|
|
92
|
+
))
|
|
115
93
|
|
|
116
94
|
/** @internal */
|
|
117
95
|
export const unsafeJson = (
|
|
@@ -130,13 +108,17 @@ export const schemaJson = <I, A>(
|
|
|
130
108
|
schema: Schema.Schema<I, A>
|
|
131
109
|
) => {
|
|
132
110
|
const encode = internalBody.jsonSchema(schema)
|
|
133
|
-
return (
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
111
|
+
return (
|
|
112
|
+
body: A,
|
|
113
|
+
options?: ServerResponse.Options.WithContent
|
|
114
|
+
): Effect.Effect<never, Body.BodyError, ServerResponse.ServerResponse> =>
|
|
115
|
+
Effect.map(encode(body), (body) =>
|
|
116
|
+
new ServerResponseImpl(
|
|
117
|
+
options?.status ?? 200,
|
|
118
|
+
options?.statusText,
|
|
119
|
+
options?.headers ?? Headers.empty,
|
|
120
|
+
body
|
|
121
|
+
))
|
|
140
122
|
}
|
|
141
123
|
|
|
142
124
|
/** @internal */
|
|
@@ -189,18 +171,6 @@ export const urlParams = (
|
|
|
189
171
|
internalBody.text(UrlParams.toString(UrlParams.fromInput(body)), "application/x-www-form-urlencoded")
|
|
190
172
|
)
|
|
191
173
|
|
|
192
|
-
/** @internal */
|
|
193
|
-
export const effect = (
|
|
194
|
-
body: Effect.Effect<never, unknown, Body.NonEffect>,
|
|
195
|
-
options?: ServerResponse.Options.WithContent
|
|
196
|
-
): ServerResponse.ServerResponse =>
|
|
197
|
-
new ServerResponseImpl(
|
|
198
|
-
options?.status ?? 200,
|
|
199
|
-
options?.statusText,
|
|
200
|
-
options?.headers ?? Headers.empty,
|
|
201
|
-
internalBody.effect(body)
|
|
202
|
-
)
|
|
203
|
-
|
|
204
174
|
/** @internal */
|
|
205
175
|
export const raw = (body: unknown, options?: ServerResponse.Options): ServerResponse.ServerResponse =>
|
|
206
176
|
new ServerResponseImpl(
|