@effect/platform 0.64.1 → 0.65.0
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/FetchHttpClient/package.json +6 -0
- package/README.md +173 -195
- package/dist/cjs/FetchHttpClient.js +32 -0
- package/dist/cjs/FetchHttpClient.js.map +1 -0
- package/dist/cjs/HttpApiClient.js +1 -1
- package/dist/cjs/HttpApiClient.js.map +1 -1
- package/dist/cjs/HttpClient.js +5 -36
- package/dist/cjs/HttpClient.js.map +1 -1
- package/dist/cjs/HttpClientRequest.js +11 -11
- package/dist/cjs/HttpClientRequest.js.map +1 -1
- package/dist/cjs/HttpClientResponse.js +2 -61
- package/dist/cjs/HttpClientResponse.js.map +1 -1
- package/dist/cjs/HttpIncomingMessage.js +2 -29
- package/dist/cjs/HttpIncomingMessage.js.map +1 -1
- package/dist/cjs/Runtime.js +1 -1
- package/dist/cjs/Runtime.js.map +1 -1
- package/dist/cjs/Socket.js +42 -53
- package/dist/cjs/Socket.js.map +1 -1
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/internal/fetchHttpClient.js +52 -0
- package/dist/cjs/internal/fetchHttpClient.js.map +1 -0
- package/dist/cjs/internal/httpClient.js +82 -71
- package/dist/cjs/internal/httpClient.js.map +1 -1
- package/dist/cjs/internal/httpClientRequest.js +13 -13
- package/dist/cjs/internal/httpClientRequest.js.map +1 -1
- package/dist/cjs/internal/httpClientResponse.js +1 -33
- package/dist/cjs/internal/httpClientResponse.js.map +1 -1
- package/dist/cjs/internal/worker.js +21 -29
- package/dist/cjs/internal/worker.js.map +1 -1
- package/dist/dts/FetchHttpClient.d.ts +27 -0
- package/dist/dts/FetchHttpClient.d.ts.map +1 -0
- package/dist/dts/HttpApiClient.d.ts +2 -2
- package/dist/dts/HttpClient.d.ts +53 -61
- package/dist/dts/HttpClient.d.ts.map +1 -1
- package/dist/dts/HttpClientRequest.d.ts +11 -11
- package/dist/dts/HttpClientRequest.d.ts.map +1 -1
- package/dist/dts/HttpClientResponse.d.ts +4 -90
- package/dist/dts/HttpClientResponse.d.ts.map +1 -1
- package/dist/dts/HttpIncomingMessage.d.ts +0 -16
- package/dist/dts/HttpIncomingMessage.d.ts.map +1 -1
- package/dist/dts/HttpServer.d.ts +1 -1
- package/dist/dts/Socket.d.ts +3 -3
- package/dist/dts/Socket.d.ts.map +1 -1
- package/dist/dts/index.d.ts +4 -0
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/dts/internal/fetchHttpClient.d.ts +2 -0
- package/dist/dts/internal/fetchHttpClient.d.ts.map +1 -0
- package/dist/esm/FetchHttpClient.js +21 -0
- package/dist/esm/FetchHttpClient.js.map +1 -0
- package/dist/esm/HttpApiClient.js +1 -1
- package/dist/esm/HttpApiClient.js.map +1 -1
- package/dist/esm/HttpClient.js +4 -35
- package/dist/esm/HttpClient.js.map +1 -1
- package/dist/esm/HttpClientRequest.js +10 -10
- package/dist/esm/HttpClientRequest.js.map +1 -1
- package/dist/esm/HttpClientResponse.js +1 -63
- package/dist/esm/HttpClientResponse.js.map +1 -1
- package/dist/esm/HttpIncomingMessage.js +0 -24
- package/dist/esm/HttpIncomingMessage.js.map +1 -1
- package/dist/esm/Runtime.js +1 -1
- package/dist/esm/Runtime.js.map +1 -1
- package/dist/esm/Socket.js +42 -53
- package/dist/esm/Socket.js.map +1 -1
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/internal/fetchHttpClient.js +44 -0
- package/dist/esm/internal/fetchHttpClient.js.map +1 -0
- package/dist/esm/internal/httpClient.js +79 -69
- package/dist/esm/internal/httpClient.js.map +1 -1
- package/dist/esm/internal/httpClientRequest.js +11 -11
- package/dist/esm/internal/httpClientRequest.js.map +1 -1
- package/dist/esm/internal/httpClientResponse.js +0 -24
- package/dist/esm/internal/httpClientResponse.js.map +1 -1
- package/dist/esm/internal/worker.js +21 -29
- package/dist/esm/internal/worker.js.map +1 -1
- package/package.json +11 -3
- package/src/FetchHttpClient.ts +25 -0
- package/src/HttpApiClient.ts +5 -5
- package/src/HttpClient.ts +79 -85
- package/src/HttpClientRequest.ts +21 -21
- package/src/HttpClientResponse.ts +4 -162
- package/src/HttpIncomingMessage.ts +0 -43
- package/src/HttpServer.ts +1 -1
- package/src/Runtime.ts +1 -1
- package/src/Socket.ts +42 -58
- package/src/index.ts +5 -0
- package/src/internal/fetchHttpClient.ts +53 -0
- package/src/internal/httpClient.ts +149 -125
- package/src/internal/httpClientRequest.ts +12 -12
- package/src/internal/httpClientResponse.ts +6 -96
- package/src/internal/worker.ts +40 -55
|
@@ -7,25 +7,23 @@ import type * as Fiber from "effect/Fiber"
|
|
|
7
7
|
import * as FiberRef from "effect/FiberRef"
|
|
8
8
|
import { constFalse, dual } from "effect/Function"
|
|
9
9
|
import { globalValue } from "effect/GlobalValue"
|
|
10
|
+
import * as Inspectable from "effect/Inspectable"
|
|
10
11
|
import * as Layer from "effect/Layer"
|
|
11
12
|
import { pipeArguments } from "effect/Pipeable"
|
|
12
13
|
import * as Predicate from "effect/Predicate"
|
|
13
14
|
import * as Ref from "effect/Ref"
|
|
14
15
|
import type * as Schedule from "effect/Schedule"
|
|
15
16
|
import * as Scope from "effect/Scope"
|
|
16
|
-
import * as Stream from "effect/Stream"
|
|
17
17
|
import * as Cookies from "../Cookies.js"
|
|
18
18
|
import * as Headers from "../Headers.js"
|
|
19
19
|
import type * as Client from "../HttpClient.js"
|
|
20
20
|
import * as Error from "../HttpClientError.js"
|
|
21
21
|
import type * as ClientRequest from "../HttpClientRequest.js"
|
|
22
22
|
import type * as ClientResponse from "../HttpClientResponse.js"
|
|
23
|
-
import * as Method from "../HttpMethod.js"
|
|
24
23
|
import * as TraceContext from "../HttpTraceContext.js"
|
|
25
24
|
import * as UrlParams from "../UrlParams.js"
|
|
26
25
|
import * as internalBody from "./httpBody.js"
|
|
27
26
|
import * as internalRequest from "./httpClientRequest.js"
|
|
28
|
-
import * as internalResponse from "./httpClientResponse.js"
|
|
29
27
|
|
|
30
28
|
/** @internal */
|
|
31
29
|
export const TypeId: Client.TypeId = Symbol.for(
|
|
@@ -33,7 +31,7 @@ export const TypeId: Client.TypeId = Symbol.for(
|
|
|
33
31
|
) as Client.TypeId
|
|
34
32
|
|
|
35
33
|
/** @internal */
|
|
36
|
-
export const tag = Context.GenericTag<Client.HttpClient.
|
|
34
|
+
export const tag = Context.GenericTag<Client.HttpClient.Service>("@effect/platform/HttpClient")
|
|
37
35
|
|
|
38
36
|
/** @internal */
|
|
39
37
|
export const currentTracerDisabledWhen = globalValue(
|
|
@@ -69,57 +67,72 @@ export const withTracerPropagation = dual<
|
|
|
69
67
|
) => Effect.Effect<A, E, R>
|
|
70
68
|
>(2, (self, enabled) => Effect.locally(self, currentTracerPropagation, enabled))
|
|
71
69
|
|
|
72
|
-
|
|
73
|
-
export const currentFetchOptions = globalValue(
|
|
74
|
-
Symbol.for("@effect/platform/HttpClient/currentFetchOptions"),
|
|
75
|
-
() => FiberRef.unsafeMake<RequestInit>({})
|
|
76
|
-
)
|
|
77
|
-
|
|
78
|
-
/** @internal */
|
|
79
|
-
export const withFetchOptions = dual<
|
|
80
|
-
(
|
|
81
|
-
options: RequestInit
|
|
82
|
-
) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>,
|
|
83
|
-
<A, E, R>(
|
|
84
|
-
effect: Effect.Effect<A, E, R>,
|
|
85
|
-
options: RequestInit
|
|
86
|
-
) => Effect.Effect<A, E, R>
|
|
87
|
-
>(2, (self, options) => Effect.locally(self, currentFetchOptions, options))
|
|
88
|
-
|
|
89
|
-
const clientProto = {
|
|
70
|
+
const ClientProto = {
|
|
90
71
|
[TypeId]: TypeId,
|
|
91
72
|
pipe() {
|
|
92
73
|
return pipeArguments(this, arguments)
|
|
74
|
+
},
|
|
75
|
+
...Inspectable.BaseProto,
|
|
76
|
+
toJSON() {
|
|
77
|
+
return {
|
|
78
|
+
_id: "@effect/platform/HttpClient"
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
get(this: Client.HttpClient.Service, url: string | URL, options?: ClientRequest.Options.NoBody) {
|
|
82
|
+
return this.execute(internalRequest.get(url, options))
|
|
83
|
+
},
|
|
84
|
+
head(this: Client.HttpClient.Service, url: string | URL, options?: ClientRequest.Options.NoBody) {
|
|
85
|
+
return this.execute(internalRequest.head(url, options))
|
|
86
|
+
},
|
|
87
|
+
post(this: Client.HttpClient.Service, url: string | URL, options: ClientRequest.Options.NoUrl) {
|
|
88
|
+
return this.execute(internalRequest.post(url, options))
|
|
89
|
+
},
|
|
90
|
+
put(this: Client.HttpClient.Service, url: string | URL, options: ClientRequest.Options.NoUrl) {
|
|
91
|
+
return this.execute(internalRequest.put(url, options))
|
|
92
|
+
},
|
|
93
|
+
patch(this: Client.HttpClient.Service, url: string | URL, options: ClientRequest.Options.NoUrl) {
|
|
94
|
+
return this.execute(internalRequest.patch(url, options))
|
|
95
|
+
},
|
|
96
|
+
del(this: Client.HttpClient.Service, url: string | URL, options?: ClientRequest.Options.NoUrl) {
|
|
97
|
+
return this.execute(internalRequest.del(url, options))
|
|
98
|
+
},
|
|
99
|
+
options(this: Client.HttpClient.Service, url: string | URL, options?: ClientRequest.Options.NoBody) {
|
|
100
|
+
return this.execute(internalRequest.options(url, options))
|
|
93
101
|
}
|
|
94
102
|
}
|
|
95
103
|
|
|
96
104
|
const isClient = (u: unknown): u is Client.HttpClient<unknown, unknown, unknown> => Predicate.hasProperty(u, TypeId)
|
|
97
105
|
|
|
106
|
+
interface HttpClientImpl<A, E, R> extends Client.HttpClient<A, E, R> {
|
|
107
|
+
readonly preprocess: Client.HttpClient.Preprocess<E, R>
|
|
108
|
+
readonly postprocess: Client.HttpClient.Postprocess<A, E, R>
|
|
109
|
+
}
|
|
110
|
+
|
|
98
111
|
/** @internal */
|
|
99
112
|
export const make = <E2, R2, A, E, R>(
|
|
100
|
-
|
|
113
|
+
postprocess: (
|
|
101
114
|
request: Effect.Effect<ClientRequest.HttpClientRequest, E2, R2>
|
|
102
115
|
) => Effect.Effect<A, E, R>,
|
|
103
116
|
preprocess: Client.HttpClient.Preprocess<E2, R2>
|
|
104
117
|
): Client.HttpClient<A, E, R> => {
|
|
105
|
-
|
|
106
|
-
|
|
118
|
+
const self = Object.create(ClientProto)
|
|
119
|
+
self.preprocess = preprocess
|
|
120
|
+
self.postprocess = postprocess
|
|
121
|
+
self.execute = function(request: ClientRequest.HttpClientRequest) {
|
|
122
|
+
return postprocess(preprocess(request))
|
|
107
123
|
}
|
|
108
|
-
|
|
109
|
-
;(client as any).preprocess = preprocess
|
|
110
|
-
;(client as any).execute = execute
|
|
111
|
-
return client as any
|
|
124
|
+
return self
|
|
112
125
|
}
|
|
113
126
|
|
|
114
127
|
/** @internal */
|
|
115
|
-
export const
|
|
128
|
+
export const makeService = (
|
|
116
129
|
f: (
|
|
117
130
|
request: ClientRequest.HttpClientRequest,
|
|
118
131
|
url: URL,
|
|
119
132
|
signal: AbortSignal,
|
|
120
133
|
fiber: Fiber.RuntimeFiber<ClientResponse.HttpClientResponse, Error.HttpClientError>
|
|
121
134
|
) => Effect.Effect<ClientResponse.HttpClientResponse, Error.HttpClientError, Scope.Scope>
|
|
122
|
-
): Client.HttpClient.
|
|
135
|
+
): Client.HttpClient.Service =>
|
|
123
136
|
make((effect) =>
|
|
124
137
|
Effect.flatMap(effect, (request) =>
|
|
125
138
|
Effect.withFiberRuntime((fiber) => {
|
|
@@ -188,52 +201,6 @@ export const makeDefault = (
|
|
|
188
201
|
)
|
|
189
202
|
})), Effect.succeed as Client.HttpClient.Preprocess<never, never>)
|
|
190
203
|
|
|
191
|
-
/** @internal */
|
|
192
|
-
export const Fetch = Context.GenericTag<Client.Fetch, typeof globalThis.fetch>(
|
|
193
|
-
"@effect/platform/HttpClient/Fetch"
|
|
194
|
-
)
|
|
195
|
-
|
|
196
|
-
/** @internal */
|
|
197
|
-
export const fetch: Client.HttpClient.Default = makeDefault((request, url, signal, fiber) => {
|
|
198
|
-
const context = fiber.getFiberRef(FiberRef.currentContext)
|
|
199
|
-
const fetch: typeof globalThis.fetch = context.unsafeMap.get(Fetch.key) ?? globalThis.fetch
|
|
200
|
-
const options = fiber.getFiberRef(currentFetchOptions)
|
|
201
|
-
const headers = new globalThis.Headers(request.headers)
|
|
202
|
-
const send = (body: BodyInit | undefined) =>
|
|
203
|
-
Effect.map(
|
|
204
|
-
Effect.tryPromise({
|
|
205
|
-
try: () =>
|
|
206
|
-
fetch(url, {
|
|
207
|
-
...options,
|
|
208
|
-
method: request.method,
|
|
209
|
-
headers,
|
|
210
|
-
body,
|
|
211
|
-
duplex: request.body._tag === "Stream" ? "half" : undefined,
|
|
212
|
-
signal
|
|
213
|
-
} as any),
|
|
214
|
-
catch: (cause) =>
|
|
215
|
-
new Error.RequestError({
|
|
216
|
-
request,
|
|
217
|
-
reason: "Transport",
|
|
218
|
-
cause
|
|
219
|
-
})
|
|
220
|
-
}),
|
|
221
|
-
(response) => internalResponse.fromWeb(request, response)
|
|
222
|
-
)
|
|
223
|
-
if (Method.hasBody(request.method)) {
|
|
224
|
-
switch (request.body._tag) {
|
|
225
|
-
case "Raw":
|
|
226
|
-
case "Uint8Array":
|
|
227
|
-
return send(request.body.body as any)
|
|
228
|
-
case "FormData":
|
|
229
|
-
return send(request.body.formData)
|
|
230
|
-
case "Stream":
|
|
231
|
-
return Effect.flatMap(Stream.toReadableStreamEffect(request.body.stream), send)
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
return send(undefined)
|
|
235
|
-
})
|
|
236
|
-
|
|
237
204
|
/** @internal */
|
|
238
205
|
export const transform = dual<
|
|
239
206
|
<A, E, R, A1, E1, R1>(
|
|
@@ -249,11 +216,13 @@ export const transform = dual<
|
|
|
249
216
|
request: ClientRequest.HttpClientRequest
|
|
250
217
|
) => Effect.Effect<A1, E1, R1>
|
|
251
218
|
) => Client.HttpClient<A1, E | E1, R | R1>
|
|
252
|
-
>(2, (self, f) =>
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
219
|
+
>(2, (self, f) => {
|
|
220
|
+
const client = self as HttpClientImpl<any, any, any>
|
|
221
|
+
return make(
|
|
222
|
+
Effect.flatMap((request) => f(client.postprocess(Effect.succeed(request)), request)),
|
|
223
|
+
client.preprocess
|
|
224
|
+
)
|
|
225
|
+
})
|
|
257
226
|
|
|
258
227
|
/** @internal */
|
|
259
228
|
export const filterStatus = dual<
|
|
@@ -297,12 +266,6 @@ export const filterStatusOk = <E, R>(
|
|
|
297
266
|
})
|
|
298
267
|
))
|
|
299
268
|
|
|
300
|
-
/** @internal */
|
|
301
|
-
export const fetchOk: Client.HttpClient.Default = filterStatusOk(fetch)
|
|
302
|
-
|
|
303
|
-
/** @internal */
|
|
304
|
-
export const layer = Layer.succeed(tag, fetch)
|
|
305
|
-
|
|
306
269
|
/** @internal */
|
|
307
270
|
export const transformResponse = dual<
|
|
308
271
|
<A, E, R, A1, E1, R1>(
|
|
@@ -312,7 +275,10 @@ export const transformResponse = dual<
|
|
|
312
275
|
self: Client.HttpClient<A, E, R>,
|
|
313
276
|
f: (effect: Effect.Effect<A, E, R>) => Effect.Effect<A1, E1, R1>
|
|
314
277
|
) => Client.HttpClient<A1, E1, R1>
|
|
315
|
-
>(2, (self, f) =>
|
|
278
|
+
>(2, (self, f) => {
|
|
279
|
+
const client = self as HttpClientImpl<any, any, any>
|
|
280
|
+
return make((request) => f(client.postprocess(request)), client.preprocess)
|
|
281
|
+
})
|
|
316
282
|
|
|
317
283
|
/** @internal */
|
|
318
284
|
export const catchTag: {
|
|
@@ -510,32 +476,50 @@ export const catchAll: {
|
|
|
510
476
|
)
|
|
511
477
|
|
|
512
478
|
/** @internal */
|
|
513
|
-
export const filterOrElse
|
|
479
|
+
export const filterOrElse: {
|
|
480
|
+
<A, B extends A, C, E2, R2>(
|
|
481
|
+
refinement: Predicate.Refinement<NoInfer<A>, B>,
|
|
482
|
+
orElse: (a: NoInfer<A>) => Effect.Effect<C, E2, R2>
|
|
483
|
+
): <E, R>(self: Client.HttpClient<A, E, R>) => Client.HttpClient<B | C, E | E2, R | R2>
|
|
514
484
|
<A, B, E2, R2>(
|
|
515
|
-
|
|
516
|
-
orElse: (a: A) => Effect.Effect<B, E2, R2>
|
|
517
|
-
)
|
|
485
|
+
predicate: Predicate.Predicate<NoInfer<A>>,
|
|
486
|
+
orElse: (a: NoInfer<A>) => Effect.Effect<B, E2, R2>
|
|
487
|
+
): <E, R>(
|
|
518
488
|
self: Client.HttpClient<A, E, R>
|
|
519
|
-
) => Client.HttpClient<A | B, E2 | E, R2 | R
|
|
489
|
+
) => Client.HttpClient<A | B, E2 | E, R2 | R>
|
|
490
|
+
<A, E, R, B extends A, C, E2, R2>(
|
|
491
|
+
self: Client.HttpClient<A, E, R>,
|
|
492
|
+
refinement: Predicate.Refinement<A, B>,
|
|
493
|
+
orElse: (a: A) => Effect.Effect<C, E2, R2>
|
|
494
|
+
): Client.HttpClient<B | C, E | E2, R | R2>
|
|
520
495
|
<A, E, R, B, E2, R2>(
|
|
521
496
|
self: Client.HttpClient<A, E, R>,
|
|
522
|
-
|
|
497
|
+
predicate: Predicate.Predicate<A>,
|
|
523
498
|
orElse: (a: A) => Effect.Effect<B, E2, R2>
|
|
524
|
-
)
|
|
525
|
-
|
|
499
|
+
): Client.HttpClient<A | B, E2 | E, R2 | R>
|
|
500
|
+
} = dual(3, (self, f, orElse) => transformResponse(self, Effect.filterOrElse(f, orElse)))
|
|
526
501
|
|
|
527
502
|
/** @internal */
|
|
528
|
-
export const filterOrFail
|
|
503
|
+
export const filterOrFail: {
|
|
504
|
+
<A, B extends A, E2>(
|
|
505
|
+
refinement: Predicate.Refinement<NoInfer<A>, B>,
|
|
506
|
+
orFailWith: (a: NoInfer<A>) => E2
|
|
507
|
+
): <E, R>(self: Client.HttpClient<A, E, R>) => Client.HttpClient<B, E | E2, R>
|
|
529
508
|
<A, E2>(
|
|
530
|
-
|
|
509
|
+
predicate: Predicate.Predicate<NoInfer<A>>,
|
|
510
|
+
orFailWith: (a: NoInfer<A>) => E2
|
|
511
|
+
): <E, R>(self: Client.HttpClient<A, E, R>) => Client.HttpClient<A, E2 | E, R>
|
|
512
|
+
<A, B extends A, E, R, E2>(
|
|
513
|
+
self: Client.HttpClient<A, E, R>,
|
|
514
|
+
refinement: Predicate.Refinement<A, B>,
|
|
531
515
|
orFailWith: (a: A) => E2
|
|
532
|
-
)
|
|
516
|
+
): Client.HttpClient<B, E2 | E, R>
|
|
533
517
|
<A, E, R, E2>(
|
|
534
518
|
self: Client.HttpClient<A, E, R>,
|
|
535
|
-
|
|
519
|
+
predicate: Predicate.Predicate<A>,
|
|
536
520
|
orFailWith: (a: A) => E2
|
|
537
|
-
)
|
|
538
|
-
|
|
521
|
+
): Client.HttpClient<A, E2 | E, R>
|
|
522
|
+
} = dual(3, (self, f, orFailWith) => transformResponse(self, Effect.filterOrFail(f, orFailWith)))
|
|
539
523
|
|
|
540
524
|
/** @internal */
|
|
541
525
|
export const map = dual<
|
|
@@ -584,7 +568,10 @@ export const mapRequest = dual<
|
|
|
584
568
|
self: Client.HttpClient<A, E, R>,
|
|
585
569
|
f: (a: ClientRequest.HttpClientRequest) => ClientRequest.HttpClientRequest
|
|
586
570
|
) => Client.HttpClient<A, E, R>
|
|
587
|
-
>(2, (self, f) =>
|
|
571
|
+
>(2, (self, f) => {
|
|
572
|
+
const client = self as HttpClientImpl<any, any, any>
|
|
573
|
+
return make(client.postprocess, (request) => Effect.map(client.preprocess(request), f))
|
|
574
|
+
})
|
|
588
575
|
|
|
589
576
|
/** @internal */
|
|
590
577
|
export const mapRequestEffect = dual<
|
|
@@ -601,10 +588,13 @@ export const mapRequestEffect = dual<
|
|
|
601
588
|
a: ClientRequest.HttpClientRequest
|
|
602
589
|
) => Effect.Effect<ClientRequest.HttpClientRequest, E2, R2>
|
|
603
590
|
) => Client.HttpClient<A, E | E2, R | R2>
|
|
604
|
-
>(2, (self, f) =>
|
|
591
|
+
>(2, (self, f) => {
|
|
592
|
+
const client = self as HttpClientImpl<any, any, any>
|
|
593
|
+
return make(client.postprocess as any, (request) => Effect.flatMap(client.preprocess(request), f))
|
|
594
|
+
})
|
|
605
595
|
|
|
606
596
|
/** @internal */
|
|
607
|
-
export const
|
|
597
|
+
export const mapRequestInput = dual<
|
|
608
598
|
(
|
|
609
599
|
f: (a: ClientRequest.HttpClientRequest) => ClientRequest.HttpClientRequest
|
|
610
600
|
) => <A, E, R>(self: Client.HttpClient<A, E, R>) => Client.HttpClient<A, E, R>,
|
|
@@ -612,10 +602,13 @@ export const mapInputRequest = dual<
|
|
|
612
602
|
self: Client.HttpClient<A, E, R>,
|
|
613
603
|
f: (a: ClientRequest.HttpClientRequest) => ClientRequest.HttpClientRequest
|
|
614
604
|
) => Client.HttpClient<A, E, R>
|
|
615
|
-
>(2, (self, f) =>
|
|
605
|
+
>(2, (self, f) => {
|
|
606
|
+
const client = self as HttpClientImpl<any, any, any>
|
|
607
|
+
return make(client.postprocess, (request) => client.preprocess(f(request)))
|
|
608
|
+
})
|
|
616
609
|
|
|
617
610
|
/** @internal */
|
|
618
|
-
export const
|
|
611
|
+
export const mapRequestInputEffect = dual<
|
|
619
612
|
<E2, R2>(
|
|
620
613
|
f: (
|
|
621
614
|
a: ClientRequest.HttpClientRequest
|
|
@@ -629,17 +622,29 @@ export const mapInputRequestEffect = dual<
|
|
|
629
622
|
a: ClientRequest.HttpClientRequest
|
|
630
623
|
) => Effect.Effect<ClientRequest.HttpClientRequest, E2, R2>
|
|
631
624
|
) => Client.HttpClient<A, E | E2, R | R2>
|
|
632
|
-
>(2, (self, f) =>
|
|
625
|
+
>(2, (self, f) => {
|
|
626
|
+
const client = self as HttpClientImpl<any, any, any>
|
|
627
|
+
return make(client.postprocess as any, (request) => Effect.flatMap(f(request), client.preprocess))
|
|
628
|
+
})
|
|
633
629
|
|
|
634
630
|
/** @internal */
|
|
635
631
|
export const retry: {
|
|
636
|
-
<
|
|
637
|
-
|
|
632
|
+
<E, O extends Effect.Retry.Options<E>>(
|
|
633
|
+
options: O
|
|
634
|
+
): <A, R>(
|
|
635
|
+
self: Client.HttpClient<A, E, R>
|
|
636
|
+
) => Client.Retry.Return<R, E, A, O>
|
|
637
|
+
<B, E, R1>(
|
|
638
|
+
policy: Schedule.Schedule<B, NoInfer<E>, R1>
|
|
638
639
|
): <A, R>(self: Client.HttpClient<A, E, R>) => Client.HttpClient<A, E, R1 | R>
|
|
639
|
-
<A, E
|
|
640
|
+
<A, E, R, O extends Effect.Retry.Options<E>>(
|
|
640
641
|
self: Client.HttpClient<A, E, R>,
|
|
641
|
-
|
|
642
|
-
): Client.
|
|
642
|
+
options: O
|
|
643
|
+
): Client.Retry.Return<R, E, A, O>
|
|
644
|
+
<A, E, R, B, R1>(
|
|
645
|
+
self: Client.HttpClient<A, E, R>,
|
|
646
|
+
policy: Schedule.Schedule<B, E, R1>
|
|
647
|
+
): Client.HttpClient<A, E, R1 | R>
|
|
643
648
|
} = dual(
|
|
644
649
|
2,
|
|
645
650
|
<A, E extends E0, E0, R, R1, B>(
|
|
@@ -683,7 +688,7 @@ export const schemaFunction = dual<
|
|
|
683
688
|
})
|
|
684
689
|
}),
|
|
685
690
|
(body) =>
|
|
686
|
-
self(
|
|
691
|
+
self.execute(
|
|
687
692
|
internalRequest.setBody(
|
|
688
693
|
request,
|
|
689
694
|
internalBody.uint8Array(body, "application/json")
|
|
@@ -714,7 +719,10 @@ export const tapRequest = dual<
|
|
|
714
719
|
self: Client.HttpClient<A, E, R>,
|
|
715
720
|
f: (a: ClientRequest.HttpClientRequest) => Effect.Effect<_, E2, R2>
|
|
716
721
|
) => Client.HttpClient<A, E | E2, R | R2>
|
|
717
|
-
>(2, (self, f) =>
|
|
722
|
+
>(2, (self, f) => {
|
|
723
|
+
const client = self as HttpClientImpl<any, any, any>
|
|
724
|
+
return make(client.postprocess as any, (request) => Effect.tap(client.preprocess(request), f))
|
|
725
|
+
})
|
|
718
726
|
|
|
719
727
|
/** @internal */
|
|
720
728
|
export const withCookiesRef = dual<
|
|
@@ -730,15 +738,16 @@ export const withCookiesRef = dual<
|
|
|
730
738
|
<E, R>(
|
|
731
739
|
self: Client.HttpClient.WithResponse<E, R>,
|
|
732
740
|
ref: Ref.Ref<Cookies.Cookies>
|
|
733
|
-
): Client.HttpClient.WithResponse<E, R> =>
|
|
734
|
-
|
|
741
|
+
): Client.HttpClient.WithResponse<E, R> => {
|
|
742
|
+
const client = self as HttpClientImpl<ClientResponse.HttpClientResponse, E, R>
|
|
743
|
+
return make(
|
|
735
744
|
(request: Effect.Effect<ClientRequest.HttpClientRequest, E, R>) =>
|
|
736
745
|
Effect.tap(
|
|
737
|
-
|
|
746
|
+
client.postprocess(request),
|
|
738
747
|
(response) => Ref.update(ref, (cookies) => Cookies.merge(cookies, response.cookies))
|
|
739
748
|
),
|
|
740
749
|
(request) =>
|
|
741
|
-
Effect.flatMap(
|
|
750
|
+
Effect.flatMap(client.preprocess(request), (request) =>
|
|
742
751
|
Effect.map(
|
|
743
752
|
Ref.get(ref),
|
|
744
753
|
(cookies) =>
|
|
@@ -747,6 +756,7 @@ export const withCookiesRef = dual<
|
|
|
747
756
|
: internalRequest.setHeader(request, "cookie", Cookies.toCookieHeader(cookies))
|
|
748
757
|
))
|
|
749
758
|
)
|
|
759
|
+
}
|
|
750
760
|
)
|
|
751
761
|
|
|
752
762
|
/** @internal */
|
|
@@ -761,15 +771,16 @@ export const followRedirects = dual<
|
|
|
761
771
|
>((args) => isClient(args[0]), <E, R>(
|
|
762
772
|
self: Client.HttpClient.WithResponse<E, R>,
|
|
763
773
|
maxRedirects?: number | undefined
|
|
764
|
-
): Client.HttpClient.WithResponse<E, R> =>
|
|
765
|
-
|
|
774
|
+
): Client.HttpClient.WithResponse<E, R> => {
|
|
775
|
+
const client = self as HttpClientImpl<ClientResponse.HttpClientResponse, E, R>
|
|
776
|
+
return make(
|
|
766
777
|
(request) => {
|
|
767
778
|
const loop = (
|
|
768
779
|
request: ClientRequest.HttpClientRequest,
|
|
769
780
|
redirects: number
|
|
770
781
|
): Effect.Effect<ClientResponse.HttpClientResponse, E, R> =>
|
|
771
782
|
Effect.flatMap(
|
|
772
|
-
|
|
783
|
+
client.postprocess(Effect.succeed(request)),
|
|
773
784
|
(response) =>
|
|
774
785
|
response.status >= 300 && response.status < 400 && response.headers.location &&
|
|
775
786
|
redirects < (maxRedirects ?? 10)
|
|
@@ -784,5 +795,18 @@ export const followRedirects = dual<
|
|
|
784
795
|
)
|
|
785
796
|
return Effect.flatMap(request, (request) => loop(request, 0))
|
|
786
797
|
},
|
|
787
|
-
|
|
788
|
-
)
|
|
798
|
+
client.preprocess
|
|
799
|
+
)
|
|
800
|
+
})
|
|
801
|
+
|
|
802
|
+
/** @internal */
|
|
803
|
+
export const layerMergedContext = <E, R>(effect: Effect.Effect<Client.HttpClient.Service, E, R>) =>
|
|
804
|
+
Layer.effect(
|
|
805
|
+
tag,
|
|
806
|
+
Effect.flatMap(Effect.context<never>(), (context) =>
|
|
807
|
+
Effect.map(effect, (client) =>
|
|
808
|
+
transformResponse(
|
|
809
|
+
client,
|
|
810
|
+
Effect.mapInputContext((input: Context.Context<Scope.Scope>) => Context.merge(context, input))
|
|
811
|
+
)))
|
|
812
|
+
)
|
|
@@ -21,14 +21,14 @@ import * as internalBody from "./httpBody.js"
|
|
|
21
21
|
export const TypeId: ClientRequest.TypeId = Symbol.for("@effect/platform/HttpClientRequest") as ClientRequest.TypeId
|
|
22
22
|
|
|
23
23
|
/** @internal */
|
|
24
|
-
export const clientTag = Context.GenericTag<HttpClient.
|
|
24
|
+
export const clientTag = Context.GenericTag<HttpClient.Service>("@effect/platform/HttpClient")
|
|
25
25
|
|
|
26
26
|
const Proto = {
|
|
27
27
|
[TypeId]: TypeId,
|
|
28
28
|
...Effectable.CommitPrototype,
|
|
29
29
|
...Inspectable.BaseProto,
|
|
30
30
|
commit(this: ClientRequest.HttpClientRequest) {
|
|
31
|
-
return Effect.flatMap(clientTag, (client) => client(this))
|
|
31
|
+
return Effect.flatMap(clientTag, (client) => client.execute(this))
|
|
32
32
|
},
|
|
33
33
|
toJSON(this: ClientRequest.HttpClientRequest): unknown {
|
|
34
34
|
return {
|
|
@@ -393,7 +393,7 @@ export const setBody = dual<
|
|
|
393
393
|
})
|
|
394
394
|
|
|
395
395
|
/** @internal */
|
|
396
|
-
export const
|
|
396
|
+
export const bodyUint8Array = dual<
|
|
397
397
|
(
|
|
398
398
|
body: Uint8Array,
|
|
399
399
|
contentType?: string
|
|
@@ -405,7 +405,7 @@ export const uint8ArrayBody = dual<
|
|
|
405
405
|
)
|
|
406
406
|
|
|
407
407
|
/** @internal */
|
|
408
|
-
export const
|
|
408
|
+
export const bodyText = dual<
|
|
409
409
|
(body: string, contentType?: string) => (self: ClientRequest.HttpClientRequest) => ClientRequest.HttpClientRequest,
|
|
410
410
|
(self: ClientRequest.HttpClientRequest, body: string, contentType?: string) => ClientRequest.HttpClientRequest
|
|
411
411
|
>(
|
|
@@ -414,7 +414,7 @@ export const textBody = dual<
|
|
|
414
414
|
)
|
|
415
415
|
|
|
416
416
|
/** @internal */
|
|
417
|
-
export const
|
|
417
|
+
export const bodyJson = dual<
|
|
418
418
|
(
|
|
419
419
|
body: unknown
|
|
420
420
|
) => (self: ClientRequest.HttpClientRequest) => Effect.Effect<ClientRequest.HttpClientRequest, Body.HttpBodyError>,
|
|
@@ -425,13 +425,13 @@ export const jsonBody = dual<
|
|
|
425
425
|
>(2, (self, body) => Effect.map(internalBody.json(body), (body) => setBody(self, body)))
|
|
426
426
|
|
|
427
427
|
/** @internal */
|
|
428
|
-
export const
|
|
428
|
+
export const bodyUnsafeJson = dual<
|
|
429
429
|
(body: unknown) => (self: ClientRequest.HttpClientRequest) => ClientRequest.HttpClientRequest,
|
|
430
430
|
(self: ClientRequest.HttpClientRequest, body: unknown) => ClientRequest.HttpClientRequest
|
|
431
431
|
>(2, (self, body) => setBody(self, internalBody.unsafeJson(body)))
|
|
432
432
|
|
|
433
433
|
/** @internal */
|
|
434
|
-
export const
|
|
434
|
+
export const bodyFile = dual<
|
|
435
435
|
(
|
|
436
436
|
path: string,
|
|
437
437
|
options?: FileSystem.StreamOptions & { readonly contentType?: string }
|
|
@@ -449,13 +449,13 @@ export const fileBody = dual<
|
|
|
449
449
|
)
|
|
450
450
|
|
|
451
451
|
/** @internal */
|
|
452
|
-
export const
|
|
452
|
+
export const bodyFileWeb = dual<
|
|
453
453
|
(file: Body.HttpBody.FileLike) => (self: ClientRequest.HttpClientRequest) => ClientRequest.HttpClientRequest,
|
|
454
454
|
(self: ClientRequest.HttpClientRequest, file: Body.HttpBody.FileLike) => ClientRequest.HttpClientRequest
|
|
455
455
|
>(2, (self, file) => setBody(self, internalBody.fileWeb(file)))
|
|
456
456
|
|
|
457
457
|
/** @internal */
|
|
458
|
-
export const
|
|
458
|
+
export const schemaBodyJson = <A, I, R>(schema: Schema.Schema<A, I, R>, options?: ParseOptions | undefined): {
|
|
459
459
|
(
|
|
460
460
|
body: A
|
|
461
461
|
): (self: ClientRequest.HttpClientRequest) => Effect.Effect<ClientRequest.HttpClientRequest, Body.HttpBodyError, R>
|
|
@@ -479,7 +479,7 @@ export const schemaBody = <A, I, R>(schema: Schema.Schema<A, I, R>, options?: Pa
|
|
|
479
479
|
}
|
|
480
480
|
|
|
481
481
|
/** @internal */
|
|
482
|
-
export const
|
|
482
|
+
export const bodyUrlParams = dual<
|
|
483
483
|
(input: UrlParams.Input) => (self: ClientRequest.HttpClientRequest) => ClientRequest.HttpClientRequest,
|
|
484
484
|
(self: ClientRequest.HttpClientRequest, input: UrlParams.Input) => ClientRequest.HttpClientRequest
|
|
485
485
|
>(2, (self, body) =>
|
|
@@ -492,13 +492,13 @@ export const urlParamsBody = dual<
|
|
|
492
492
|
))
|
|
493
493
|
|
|
494
494
|
/** @internal */
|
|
495
|
-
export const
|
|
495
|
+
export const bodyFormData = dual<
|
|
496
496
|
(body: FormData) => (self: ClientRequest.HttpClientRequest) => ClientRequest.HttpClientRequest,
|
|
497
497
|
(self: ClientRequest.HttpClientRequest, body: FormData) => ClientRequest.HttpClientRequest
|
|
498
498
|
>(2, (self, body) => setBody(self, internalBody.formData(body)))
|
|
499
499
|
|
|
500
500
|
/** @internal */
|
|
501
|
-
export const
|
|
501
|
+
export const bodyStream = dual<
|
|
502
502
|
(
|
|
503
503
|
body: Stream.Stream<Uint8Array, unknown>,
|
|
504
504
|
options?: {
|