@effect/platform 0.11.3 → 0.11.5
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/Command.d.ts +3 -2
- package/Command.d.ts.map +1 -1
- package/Command.js.map +1 -1
- package/Http/Client.d.ts +7 -1
- package/Http/Client.d.ts.map +1 -1
- package/Http/Client.js +8 -2
- package/Http/Client.js.map +1 -1
- package/Http/ClientError.d.ts +1 -1
- package/Http/ClientError.d.ts.map +1 -1
- package/Http/IncomingMessage.d.ts +1 -1
- package/Http/IncomingMessage.d.ts.map +1 -1
- package/Http/UrlParams.d.ts +6 -0
- package/Http/UrlParams.d.ts.map +1 -1
- package/Http/UrlParams.js +25 -1
- package/Http/UrlParams.js.map +1 -1
- package/internal/command.js +9 -2
- package/internal/command.js.map +1 -1
- package/internal/http/client.d.ts.map +1 -1
- package/internal/http/client.js +29 -34
- package/internal/http/client.js.map +1 -1
- package/internal/http/clientResponse.js +2 -2
- package/internal/http/clientResponse.js.map +1 -1
- package/mjs/Command.mjs.map +1 -1
- package/mjs/Http/Client.mjs +5 -0
- package/mjs/Http/Client.mjs.map +1 -1
- package/mjs/Http/UrlParams.mjs +23 -0
- package/mjs/Http/UrlParams.mjs.map +1 -1
- package/mjs/internal/command.mjs +9 -2
- package/mjs/internal/command.mjs.map +1 -1
- package/mjs/internal/http/client.mjs +27 -33
- package/mjs/internal/http/client.mjs.map +1 -1
- package/mjs/internal/http/clientResponse.mjs +2 -2
- package/mjs/internal/http/clientResponse.mjs.map +1 -1
- package/package.json +1 -1
- package/src/Command.ts +3 -2
- package/src/Http/Client.ts +9 -1
- package/src/Http/ClientError.ts +1 -1
- package/src/Http/IncomingMessage.ts +1 -1
- package/src/Http/UrlParams.ts +26 -0
- package/src/internal/command.ts +9 -2
- package/src/internal/http/client.ts +79 -83
- package/src/internal/http/clientResponse.ts +2 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as Chunk from "@effect/data/Chunk"
|
|
2
1
|
import * as Context from "@effect/data/Context"
|
|
3
2
|
import { dual } from "@effect/data/Function"
|
|
3
|
+
import { pipeArguments } from "@effect/data/Pipeable"
|
|
4
4
|
import type * as Predicate from "@effect/data/Predicate"
|
|
5
5
|
import * as Effect from "@effect/io/Effect"
|
|
6
6
|
import * as Layer from "@effect/io/Layer"
|
|
@@ -10,6 +10,7 @@ import type * as Client from "@effect/platform/Http/Client"
|
|
|
10
10
|
import type * as Error from "@effect/platform/Http/ClientError"
|
|
11
11
|
import type * as ClientRequest from "@effect/platform/Http/ClientRequest"
|
|
12
12
|
import * as Method from "@effect/platform/Http/Method"
|
|
13
|
+
import * as UrlParams from "@effect/platform/Http/UrlParams"
|
|
13
14
|
import * as internalBody from "@effect/platform/internal/http/body"
|
|
14
15
|
import * as internalError from "@effect/platform/internal/http/clientError"
|
|
15
16
|
import * as internalRequest from "@effect/platform/internal/http/clientRequest"
|
|
@@ -21,71 +22,67 @@ import * as Stream from "@effect/stream/Stream"
|
|
|
21
22
|
/** @internal */
|
|
22
23
|
export const tag = Context.Tag<Client.Client.Default>("@effect/platform/Http/Client")
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
/** @internal */
|
|
26
|
+
export const make = <R, E, A>(
|
|
27
|
+
f: (request: ClientRequest.ClientRequest) => Effect.Effect<R, E, A>
|
|
28
|
+
): Client.Client<R, E, A> =>
|
|
29
|
+
Object.assign(f, {
|
|
30
|
+
pipe() {
|
|
31
|
+
return pipeArguments(this, arguments)
|
|
32
|
+
}
|
|
33
|
+
})
|
|
30
34
|
|
|
31
35
|
/** @internal */
|
|
32
36
|
export const fetch = (
|
|
33
37
|
options: RequestInit = {}
|
|
34
38
|
): Client.Client.Default =>
|
|
35
|
-
(request) =>
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
try: () => new URL(request.url, baseUrl()),
|
|
39
|
-
catch: (_) =>
|
|
39
|
+
make((request) =>
|
|
40
|
+
Effect.flatMap(
|
|
41
|
+
UrlParams.makeUrl(request.url, request.urlParams, (_) =>
|
|
40
42
|
internalError.requestError({
|
|
41
43
|
request,
|
|
42
|
-
reason: "
|
|
44
|
+
reason: "InvalidUrl",
|
|
43
45
|
error: _
|
|
46
|
+
})),
|
|
47
|
+
(url) =>
|
|
48
|
+
Effect.suspend(() => {
|
|
49
|
+
const headers = new Headers([...request.headers] as any)
|
|
50
|
+
const send = (body: BodyInit | undefined) =>
|
|
51
|
+
Effect.map(
|
|
52
|
+
Effect.tryPromise({
|
|
53
|
+
try: (signal) =>
|
|
54
|
+
globalThis.fetch(url, {
|
|
55
|
+
...options,
|
|
56
|
+
method: request.method,
|
|
57
|
+
headers,
|
|
58
|
+
body,
|
|
59
|
+
signal
|
|
60
|
+
}),
|
|
61
|
+
catch: (_) =>
|
|
62
|
+
internalError.requestError({
|
|
63
|
+
request,
|
|
64
|
+
reason: "Transport",
|
|
65
|
+
error: _
|
|
66
|
+
})
|
|
67
|
+
}),
|
|
68
|
+
(_) => internalResponse.fromWeb(request, _)
|
|
69
|
+
)
|
|
70
|
+
if (Method.hasBody(request.method)) {
|
|
71
|
+
return request.body._tag === "BytesEffect" ?
|
|
72
|
+
Effect.flatMap(
|
|
73
|
+
Effect.mapError(request.body.body, (error) =>
|
|
74
|
+
internalError.requestError({
|
|
75
|
+
reason: "Encode",
|
|
76
|
+
request,
|
|
77
|
+
error
|
|
78
|
+
})),
|
|
79
|
+
(body) => send(body)
|
|
80
|
+
) :
|
|
81
|
+
send(convertBody(request.body))
|
|
82
|
+
}
|
|
83
|
+
return send(undefined)
|
|
44
84
|
})
|
|
45
|
-
|
|
46
|
-
(url) =>
|
|
47
|
-
Effect.suspend(() => {
|
|
48
|
-
Chunk.forEach(request.urlParams, ([key, value]) => {
|
|
49
|
-
if (value === undefined) return
|
|
50
|
-
url.searchParams.append(key, value)
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
const headers = new Headers([...request.headers] as any)
|
|
54
|
-
const send = (body: BodyInit | undefined) =>
|
|
55
|
-
Effect.map(
|
|
56
|
-
Effect.tryPromise({
|
|
57
|
-
try: (signal) =>
|
|
58
|
-
globalThis.fetch(url, {
|
|
59
|
-
...options,
|
|
60
|
-
method: request.method,
|
|
61
|
-
headers,
|
|
62
|
-
body,
|
|
63
|
-
signal
|
|
64
|
-
}),
|
|
65
|
-
catch: (_) =>
|
|
66
|
-
internalError.requestError({
|
|
67
|
-
request,
|
|
68
|
-
reason: "Transport",
|
|
69
|
-
error: _
|
|
70
|
-
})
|
|
71
|
-
}),
|
|
72
|
-
(_) => internalResponse.fromWeb(request, _)
|
|
73
|
-
)
|
|
74
|
-
if (Method.hasBody(request.method)) {
|
|
75
|
-
return request.body._tag === "BytesEffect" ?
|
|
76
|
-
Effect.flatMap(
|
|
77
|
-
Effect.mapError(request.body.body, (error) =>
|
|
78
|
-
internalError.requestError({
|
|
79
|
-
reason: "Encode",
|
|
80
|
-
request,
|
|
81
|
-
error
|
|
82
|
-
})),
|
|
83
|
-
(body) => send(body)
|
|
84
|
-
) :
|
|
85
|
-
send(convertBody(request.body))
|
|
86
|
-
}
|
|
87
|
-
return send(undefined)
|
|
88
|
-
})
|
|
85
|
+
)
|
|
89
86
|
)
|
|
90
87
|
|
|
91
88
|
const convertBody = (body: Exclude<Body.Body, Body.BytesEffect>): BodyInit | undefined => {
|
|
@@ -130,7 +127,7 @@ export const catchTag: {
|
|
|
130
127
|
tag: K,
|
|
131
128
|
f: (e: Extract<E, { _tag: K }>) => Effect.Effect<R1, E1, A1>
|
|
132
129
|
): Client.Client<R1 | R, E1 | Exclude<E, { _tag: K }>, A1 | A> =>
|
|
133
|
-
|
|
130
|
+
make((request) => Effect.catchTag(self(request), tag, f))
|
|
134
131
|
)
|
|
135
132
|
|
|
136
133
|
/** @internal */
|
|
@@ -240,8 +237,7 @@ export const catchTags: {
|
|
|
240
237
|
) => Effect.Effect<any, any, infer A> ? A
|
|
241
238
|
: never
|
|
242
239
|
}[keyof Cases]
|
|
243
|
-
> =>
|
|
244
|
-
(request) => Effect.catchTags(self(request), cases)
|
|
240
|
+
> => make((request) => Effect.catchTags(self(request), cases))
|
|
245
241
|
)
|
|
246
242
|
|
|
247
243
|
/** @internal */
|
|
@@ -258,8 +254,7 @@ export const catchAll: {
|
|
|
258
254
|
<R, E, A, R2, E2, A2>(
|
|
259
255
|
self: Client.Client<R, E, A>,
|
|
260
256
|
f: (e: E) => Effect.Effect<R2, E2, A2>
|
|
261
|
-
): Client.Client<R | R2, E2, A2 | A> =>
|
|
262
|
-
(request) => Effect.catchAll(self(request), f)
|
|
257
|
+
): Client.Client<R | R2, E2, A2 | A> => make((request) => Effect.catchAll(self(request), f))
|
|
263
258
|
)
|
|
264
259
|
|
|
265
260
|
/** @internal */
|
|
@@ -272,7 +267,7 @@ export const filterOrElse = dual<
|
|
|
272
267
|
f: Predicate.Predicate<A>,
|
|
273
268
|
orElse: (a: A) => Effect.Effect<R2, E2, B>
|
|
274
269
|
) => Client.Client<R2 | R, E2 | E, A | B>
|
|
275
|
-
>(3, (self, f, orElse) => (request) => Effect.filterOrElse(self(request), f, orElse))
|
|
270
|
+
>(3, (self, f, orElse) => make((request) => Effect.filterOrElse(self(request), f, orElse)))
|
|
276
271
|
|
|
277
272
|
/** @internal */
|
|
278
273
|
export const filterOrFail = dual<
|
|
@@ -284,7 +279,7 @@ export const filterOrFail = dual<
|
|
|
284
279
|
f: Predicate.Predicate<A>,
|
|
285
280
|
orFailWith: (a: A) => E2
|
|
286
281
|
) => Client.Client<R, E2 | E, A>
|
|
287
|
-
>(3, (self, f, orFailWith) => (request) => Effect.filterOrFail(self(request), f, orFailWith))
|
|
282
|
+
>(3, (self, f, orFailWith) => make((request) => Effect.filterOrFail(self(request), f, orFailWith)))
|
|
288
283
|
|
|
289
284
|
/** @internal */
|
|
290
285
|
export const filterStatus = dual<
|
|
@@ -297,17 +292,19 @@ export const filterStatus = dual<
|
|
|
297
292
|
) => Client.Client.WithResponse<R, E | Error.ResponseError>
|
|
298
293
|
>(
|
|
299
294
|
2,
|
|
300
|
-
(self, f) =>
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
295
|
+
(self, f) =>
|
|
296
|
+
make((request) =>
|
|
297
|
+
Effect.filterOrFail(
|
|
298
|
+
self(request),
|
|
299
|
+
(response) => f(response.status),
|
|
300
|
+
(response) =>
|
|
301
|
+
internalError.responseError({
|
|
302
|
+
request,
|
|
303
|
+
response,
|
|
304
|
+
reason: "StatusCode",
|
|
305
|
+
error: "non 2xx status code"
|
|
306
|
+
})
|
|
307
|
+
)
|
|
311
308
|
)
|
|
312
309
|
)
|
|
313
310
|
|
|
@@ -325,7 +322,7 @@ export const map = dual<
|
|
|
325
322
|
self: Client.Client<R, E, A>,
|
|
326
323
|
f: (a: A) => B
|
|
327
324
|
) => Client.Client<R, E, B>
|
|
328
|
-
>(2, (self, f) => (request) => Effect.map(self(request), f))
|
|
325
|
+
>(2, (self, f) => make((request) => Effect.map(self(request), f)))
|
|
329
326
|
|
|
330
327
|
/** @internal */
|
|
331
328
|
export const mapEffect = dual<
|
|
@@ -336,7 +333,7 @@ export const mapEffect = dual<
|
|
|
336
333
|
self: Client.Client<R, E, A>,
|
|
337
334
|
f: (a: A) => Effect.Effect<R2, E2, B>
|
|
338
335
|
) => Client.Client<R | R2, E | E2, B>
|
|
339
|
-
>(2, (self, f) => (request) => Effect.flatMap(self(request), f))
|
|
336
|
+
>(2, (self, f) => make((request) => Effect.flatMap(self(request), f)))
|
|
340
337
|
|
|
341
338
|
/** @internal */
|
|
342
339
|
export const mapRequest = dual<
|
|
@@ -347,7 +344,7 @@ export const mapRequest = dual<
|
|
|
347
344
|
self: Client.Client<R, E, A>,
|
|
348
345
|
f: (a: ClientRequest.ClientRequest) => ClientRequest.ClientRequest
|
|
349
346
|
) => Client.Client<R, E, A>
|
|
350
|
-
>(2, (self, f) => (request) => self(f(request)))
|
|
347
|
+
>(2, (self, f) => make((request) => self(f(request))))
|
|
351
348
|
|
|
352
349
|
/** @internal */
|
|
353
350
|
export const mapRequestEffect = dual<
|
|
@@ -358,7 +355,7 @@ export const mapRequestEffect = dual<
|
|
|
358
355
|
self: Client.Client<R, E, A>,
|
|
359
356
|
f: (a: ClientRequest.ClientRequest) => Effect.Effect<R2, E2, ClientRequest.ClientRequest>
|
|
360
357
|
) => Client.Client<R | R2, E | E2, A>
|
|
361
|
-
>(2, (self, f) => (request) => Effect.flatMap(f(request), self))
|
|
358
|
+
>(2, (self, f) => make((request) => Effect.flatMap(f(request), self)))
|
|
362
359
|
|
|
363
360
|
/** @internal */
|
|
364
361
|
export const retry: {
|
|
@@ -374,8 +371,7 @@ export const retry: {
|
|
|
374
371
|
<R, E extends E0, E0, A, R1, B>(
|
|
375
372
|
self: Client.Client<R, E, A>,
|
|
376
373
|
policy: Schedule.Schedule<R1, E0, B>
|
|
377
|
-
): Client.Client<R | R1, E, A> =>
|
|
378
|
-
(request) => Effect.retry(self(request), policy)
|
|
374
|
+
): Client.Client<R | R1, E, A> => make((request) => Effect.retry(self(request), policy))
|
|
379
375
|
)
|
|
380
376
|
|
|
381
377
|
/** @internal */
|
|
@@ -423,7 +419,7 @@ export const tap = dual<
|
|
|
423
419
|
self: Client.Client<R, E, A>,
|
|
424
420
|
f: (a: A) => Effect.Effect<R2, E2, _>
|
|
425
421
|
) => Client.Client<R | R2, E | E2, A>
|
|
426
|
-
>(2, (self, f) => (request) => Effect.tap(self(request), f))
|
|
422
|
+
>(2, (self, f) => make((request) => Effect.tap(self(request), f)))
|
|
427
423
|
|
|
428
424
|
/** @internal */
|
|
429
425
|
export const tapRequest = dual<
|
|
@@ -434,4 +430,4 @@ export const tapRequest = dual<
|
|
|
434
430
|
self: Client.Client<R, E, A>,
|
|
435
431
|
f: (a: ClientRequest.ClientRequest) => Effect.Effect<R2, E2, _>
|
|
436
432
|
) => Client.Client<R | R2, E | E2, A>
|
|
437
|
-
>(2, (self, f) => (request) => Effect.zipRight(f(request), self(request)))
|
|
433
|
+
>(2, (self, f) => make((request) => Effect.zipRight(f(request), self(request))))
|
|
@@ -99,9 +99,9 @@ class ClientResponseImpl implements ClientResponse.ClientResponse {
|
|
|
99
99
|
}))
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
get
|
|
102
|
+
get arrayBuffer(): Effect.Effect<never, Error.ResponseError, ArrayBuffer> {
|
|
103
103
|
return Effect.tryPromise({
|
|
104
|
-
try: () => this.source.
|
|
104
|
+
try: () => this.source.arrayBuffer(),
|
|
105
105
|
catch: (_) =>
|
|
106
106
|
internalError.responseError({
|
|
107
107
|
request: this.request,
|