effect 4.0.0-beta.27 → 4.0.0-beta.29
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/Brand.d.ts +1 -1
- package/dist/Brand.d.ts.map +1 -1
- package/dist/Brand.js +1 -1
- package/dist/Brand.js.map +1 -1
- package/dist/ConfigProvider.d.ts +1 -1
- package/dist/Cron.d.ts +1 -1
- package/dist/Data.d.ts +1 -1
- package/dist/Data.d.ts.map +1 -1
- package/dist/Data.js.map +1 -1
- package/dist/Effect.d.ts +300 -184
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +99 -61
- package/dist/Effect.js.map +1 -1
- package/dist/Encoding.d.ts +1 -1
- package/dist/Exit.d.ts +24 -12
- package/dist/Exit.d.ts.map +1 -1
- package/dist/Exit.js +8 -4
- package/dist/Exit.js.map +1 -1
- package/dist/Fiber.d.ts +1 -0
- package/dist/Fiber.d.ts.map +1 -1
- package/dist/Fiber.js.map +1 -1
- package/dist/Function.d.ts +1 -9
- package/dist/Function.d.ts.map +1 -1
- package/dist/Function.js +2 -10
- package/dist/Function.js.map +1 -1
- package/dist/Graph.d.ts +1 -1
- package/dist/Newtype.d.ts +291 -0
- package/dist/Newtype.d.ts.map +1 -0
- package/dist/Newtype.js +161 -0
- package/dist/Newtype.js.map +1 -0
- package/dist/PlatformError.d.ts +2 -2
- package/dist/References.d.ts +6 -1
- package/dist/References.d.ts.map +1 -1
- package/dist/References.js +6 -1
- package/dist/References.js.map +1 -1
- package/dist/RequestResolver.d.ts +19 -19
- package/dist/RequestResolver.js +10 -10
- package/dist/RequestResolver.js.map +1 -1
- package/dist/Schedule.d.ts +142 -80
- package/dist/Schedule.d.ts.map +1 -1
- package/dist/Schedule.js +58 -32
- package/dist/Schedule.js.map +1 -1
- package/dist/Scheduler.d.ts +9 -0
- package/dist/Scheduler.d.ts.map +1 -1
- package/dist/Scheduler.js +11 -0
- package/dist/Scheduler.js.map +1 -1
- package/dist/Schema.d.ts +1 -1
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +3 -1
- package/dist/Schema.js.map +1 -1
- package/dist/SchemaAST.d.ts.map +1 -1
- package/dist/SchemaAST.js +1 -1
- package/dist/SchemaAST.js.map +1 -1
- package/dist/Stdio.d.ts +6 -2
- package/dist/Stdio.d.ts.map +1 -1
- package/dist/Stdio.js +2 -2
- package/dist/Stdio.js.map +1 -1
- package/dist/Stream.d.ts +8 -4
- package/dist/Stream.d.ts.map +1 -1
- package/dist/Stream.js +8 -4
- package/dist/Stream.js.map +1 -1
- package/dist/Types.d.ts +1 -22
- package/dist/Types.d.ts.map +1 -1
- package/dist/index.d.ts +71 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +71 -3
- package/dist/index.js.map +1 -1
- package/dist/internal/effect.js +3 -1
- package/dist/internal/effect.js.map +1 -1
- package/dist/unstable/ai/LanguageModel.d.ts +12 -28
- package/dist/unstable/ai/LanguageModel.d.ts.map +1 -1
- package/dist/unstable/ai/LanguageModel.js +4 -18
- package/dist/unstable/ai/LanguageModel.js.map +1 -1
- package/dist/unstable/ai/McpSchema.d.ts +20 -1
- package/dist/unstable/ai/McpSchema.d.ts.map +1 -1
- package/dist/unstable/ai/McpSchema.js +8 -0
- package/dist/unstable/ai/McpSchema.js.map +1 -1
- package/dist/unstable/ai/McpServer.d.ts +65 -12
- package/dist/unstable/ai/McpServer.d.ts.map +1 -1
- package/dist/unstable/ai/McpServer.js +159 -45
- package/dist/unstable/ai/McpServer.js.map +1 -1
- package/dist/unstable/ai/Toolkit.d.ts +1 -1
- package/dist/unstable/ai/Toolkit.d.ts.map +1 -1
- package/dist/unstable/ai/Toolkit.js +4 -11
- package/dist/unstable/ai/Toolkit.js.map +1 -1
- package/dist/unstable/ai/internal/codec-transformer.js +0 -5
- package/dist/unstable/ai/internal/codec-transformer.js.map +1 -1
- package/dist/unstable/cli/Prompt.js +35 -8
- package/dist/unstable/cli/Prompt.js.map +1 -1
- package/dist/unstable/cluster/Message.d.ts +5 -5
- package/dist/unstable/cluster/Reply.d.ts +3 -3
- package/dist/unstable/encoding/Msgpack.d.ts +1 -1
- package/dist/unstable/encoding/Ndjson.d.ts +1 -1
- package/dist/unstable/encoding/Sse.d.ts +1 -1
- package/dist/unstable/eventlog/EventJournal.d.ts +1 -1
- package/dist/unstable/eventlog/EventLogRemote.d.ts +1 -1
- package/dist/unstable/http/Cookies.d.ts +45 -1
- package/dist/unstable/http/Cookies.d.ts.map +1 -1
- package/dist/unstable/http/Cookies.js +22 -0
- package/dist/unstable/http/Cookies.js.map +1 -1
- package/dist/unstable/http/HttpBody.d.ts +1 -1
- package/dist/unstable/http/HttpClient.d.ts.map +1 -1
- package/dist/unstable/http/HttpClient.js +3 -7
- package/dist/unstable/http/HttpClient.js.map +1 -1
- package/dist/unstable/http/HttpClientError.d.ts +7 -7
- package/dist/unstable/http/HttpClientRequest.d.ts +5 -0
- package/dist/unstable/http/HttpClientRequest.d.ts.map +1 -1
- package/dist/unstable/http/HttpClientRequest.js +21 -17
- package/dist/unstable/http/HttpClientRequest.js.map +1 -1
- package/dist/unstable/http/HttpEffect.d.ts +7 -0
- package/dist/unstable/http/HttpEffect.d.ts.map +1 -1
- package/dist/unstable/http/HttpEffect.js +6 -0
- package/dist/unstable/http/HttpEffect.js.map +1 -1
- package/dist/unstable/http/HttpServerError.d.ts +6 -6
- package/dist/unstable/http/HttpServerRequest.d.ts +11 -0
- package/dist/unstable/http/HttpServerRequest.d.ts.map +1 -1
- package/dist/unstable/http/HttpServerRequest.js +291 -1
- package/dist/unstable/http/HttpServerRequest.js.map +1 -1
- package/dist/unstable/http/HttpServerResponse.d.ts +47 -1
- package/dist/unstable/http/HttpServerResponse.d.ts.map +1 -1
- package/dist/unstable/http/HttpServerResponse.js +227 -0
- package/dist/unstable/http/HttpServerResponse.js.map +1 -1
- package/dist/unstable/http/HttpStaticServer.d.ts +69 -0
- package/dist/unstable/http/HttpStaticServer.d.ts.map +1 -0
- package/dist/unstable/http/HttpStaticServer.js +353 -0
- package/dist/unstable/http/HttpStaticServer.js.map +1 -0
- package/dist/unstable/http/Multipart.d.ts +1 -1
- package/dist/unstable/http/UrlParams.d.ts +1 -1
- package/dist/unstable/http/index.d.ts +4 -0
- package/dist/unstable/http/index.d.ts.map +1 -1
- package/dist/unstable/http/index.js +4 -0
- package/dist/unstable/http/index.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiGroup.d.ts +1 -0
- package/dist/unstable/httpapi/HttpApiGroup.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiGroup.js.map +1 -1
- package/dist/unstable/persistence/KeyValueStore.d.ts +1 -1
- package/dist/unstable/reactivity/Atom.d.ts +7 -2
- package/dist/unstable/reactivity/Atom.d.ts.map +1 -1
- package/dist/unstable/reactivity/Atom.js +33 -15
- package/dist/unstable/reactivity/Atom.js.map +1 -1
- package/dist/unstable/reactivity/AtomHttpApi.d.ts +4 -6
- package/dist/unstable/reactivity/AtomHttpApi.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomHttpApi.js +39 -9
- package/dist/unstable/reactivity/AtomHttpApi.js.map +1 -1
- package/dist/unstable/reactivity/AtomRegistry.js +26 -2
- package/dist/unstable/reactivity/AtomRegistry.js.map +1 -1
- package/dist/unstable/reactivity/AtomRpc.d.ts +8 -8
- package/dist/unstable/reactivity/AtomRpc.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomRpc.js +46 -20
- package/dist/unstable/reactivity/AtomRpc.js.map +1 -1
- package/dist/unstable/rpc/Rpc.d.ts +1 -1
- package/dist/unstable/rpc/Rpc.d.ts.map +1 -1
- package/dist/unstable/rpc/Rpc.js.map +1 -1
- package/dist/unstable/rpc/RpcMiddleware.d.ts +5 -5
- package/dist/unstable/rpc/RpcMiddleware.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcMiddleware.js.map +1 -1
- package/dist/unstable/rpc/RpcServer.js +2 -2
- package/dist/unstable/rpc/RpcServer.js.map +1 -1
- package/dist/unstable/rpc/Utils.js +1 -1
- package/dist/unstable/rpc/Utils.js.map +1 -1
- package/dist/unstable/socket/SocketServer.d.ts +3 -3
- package/dist/unstable/sql/Migrator.d.ts +1 -1
- package/dist/unstable/sql/SqlResolver.js +2 -2
- package/dist/unstable/sql/SqlResolver.js.map +1 -1
- package/dist/unstable/workflow/Workflow.d.ts +1 -1
- package/package.json +1 -1
- package/src/Brand.ts +1 -1
- package/src/Data.ts +1 -2
- package/src/Effect.ts +300 -184
- package/src/Exit.ts +24 -12
- package/src/Fiber.ts +1 -0
- package/src/Function.ts +2 -10
- package/src/Newtype.ts +308 -0
- package/src/References.ts +6 -1
- package/src/RequestResolver.ts +20 -20
- package/src/Schedule.ts +142 -80
- package/src/Scheduler.ts +12 -0
- package/src/Schema.ts +4 -2
- package/src/SchemaAST.ts +1 -4
- package/src/Stdio.ts +8 -4
- package/src/Stream.ts +8 -4
- package/src/Types.ts +1 -23
- package/src/index.ts +72 -3
- package/src/internal/effect.ts +3 -0
- package/src/unstable/ai/LanguageModel.ts +16 -37
- package/src/unstable/ai/McpSchema.ts +14 -0
- package/src/unstable/ai/McpServer.ts +224 -53
- package/src/unstable/ai/Toolkit.ts +5 -14
- package/src/unstable/ai/internal/codec-transformer.ts +0 -7
- package/src/unstable/cli/Prompt.ts +31 -9
- package/src/unstable/http/Cookies.ts +84 -0
- package/src/unstable/http/HttpClient.ts +5 -6
- package/src/unstable/http/HttpClientRequest.ts +21 -17
- package/src/unstable/http/HttpEffect.ts +8 -0
- package/src/unstable/http/HttpServerRequest.ts +388 -1
- package/src/unstable/http/HttpServerResponse.ts +328 -1
- package/src/unstable/http/HttpStaticServer.ts +456 -0
- package/src/unstable/http/index.ts +5 -0
- package/src/unstable/httpapi/HttpApiGroup.ts +1 -0
- package/src/unstable/reactivity/Atom.ts +62 -35
- package/src/unstable/reactivity/AtomHttpApi.ts +45 -11
- package/src/unstable/reactivity/AtomRegistry.ts +30 -2
- package/src/unstable/reactivity/AtomRpc.ts +48 -17
- package/src/unstable/rpc/Rpc.ts +1 -3
- package/src/unstable/rpc/RpcMiddleware.ts +12 -6
- package/src/unstable/rpc/RpcServer.ts +2 -2
- package/src/unstable/rpc/Utils.ts +1 -1
- package/src/unstable/sql/SqlResolver.ts +2 -2
|
@@ -5,7 +5,7 @@ import * as Effect from "../../Effect.ts"
|
|
|
5
5
|
import * as ErrorReporter from "../../ErrorReporter.ts"
|
|
6
6
|
import type * as FileSystem from "../../FileSystem.ts"
|
|
7
7
|
import { dual } from "../../Function.ts"
|
|
8
|
-
import
|
|
8
|
+
import * as Inspectable from "../../Inspectable.ts"
|
|
9
9
|
import { PipeInspectableProto } from "../../internal/core.ts"
|
|
10
10
|
import type { Pipeable } from "../../Pipeable.ts"
|
|
11
11
|
import type { PlatformError } from "../../PlatformError.ts"
|
|
@@ -19,6 +19,10 @@ import type { Mutable } from "../../Types.ts"
|
|
|
19
19
|
import * as Cookies from "./Cookies.ts"
|
|
20
20
|
import * as Headers from "./Headers.ts"
|
|
21
21
|
import * as Body from "./HttpBody.ts"
|
|
22
|
+
import * as HttpClientError from "./HttpClientError.ts"
|
|
23
|
+
import * as HttpClientRequest from "./HttpClientRequest.ts"
|
|
24
|
+
import * as HttpClientResponse from "./HttpClientResponse.ts"
|
|
25
|
+
import * as HttpIncomingMessage from "./HttpIncomingMessage.ts"
|
|
22
26
|
import type { HttpPlatform } from "./HttpPlatform.ts"
|
|
23
27
|
import * as Template from "./Template.ts"
|
|
24
28
|
import * as UrlParams from "./UrlParams.ts"
|
|
@@ -524,6 +528,47 @@ export const setCookie: {
|
|
|
524
528
|
)
|
|
525
529
|
)
|
|
526
530
|
|
|
531
|
+
/**
|
|
532
|
+
* @since 4.0.0
|
|
533
|
+
* @category combinators
|
|
534
|
+
*/
|
|
535
|
+
export const expireCookie: {
|
|
536
|
+
/**
|
|
537
|
+
* @since 4.0.0
|
|
538
|
+
* @category combinators
|
|
539
|
+
*/
|
|
540
|
+
(
|
|
541
|
+
name: string,
|
|
542
|
+
options?: Omit<NonNullable<Cookies.Cookie["options"]>, "expires" | "maxAge">
|
|
543
|
+
): (
|
|
544
|
+
self: HttpServerResponse
|
|
545
|
+
) => Effect.Effect<HttpServerResponse, Cookies.CookiesError>
|
|
546
|
+
/**
|
|
547
|
+
* @since 4.0.0
|
|
548
|
+
* @category combinators
|
|
549
|
+
*/
|
|
550
|
+
(
|
|
551
|
+
self: HttpServerResponse,
|
|
552
|
+
name: string,
|
|
553
|
+
options?: Omit<NonNullable<Cookies.Cookie["options"]>, "expires" | "maxAge">
|
|
554
|
+
): Effect.Effect<HttpServerResponse, Cookies.CookiesError>
|
|
555
|
+
} = dual(
|
|
556
|
+
(args) => isHttpServerResponse(args[0]),
|
|
557
|
+
(
|
|
558
|
+
self: HttpServerResponse,
|
|
559
|
+
name: string,
|
|
560
|
+
options?: Omit<NonNullable<Cookies.Cookie["options"]>, "expires" | "maxAge">
|
|
561
|
+
): Effect.Effect<HttpServerResponse, Cookies.CookiesError> =>
|
|
562
|
+
Effect.map(
|
|
563
|
+
Cookies.expireCookie(self.cookies, name, options).asEffect(),
|
|
564
|
+
(cookies) =>
|
|
565
|
+
makeResponse({
|
|
566
|
+
...self,
|
|
567
|
+
cookies
|
|
568
|
+
})
|
|
569
|
+
)
|
|
570
|
+
)
|
|
571
|
+
|
|
527
572
|
/**
|
|
528
573
|
* @since 4.0.0
|
|
529
574
|
* @category combinators
|
|
@@ -558,6 +603,41 @@ export const setCookieUnsafe: {
|
|
|
558
603
|
})
|
|
559
604
|
)
|
|
560
605
|
|
|
606
|
+
/**
|
|
607
|
+
* @since 4.0.0
|
|
608
|
+
* @category combinators
|
|
609
|
+
*/
|
|
610
|
+
export const expireCookieUnsafe: {
|
|
611
|
+
/**
|
|
612
|
+
* @since 4.0.0
|
|
613
|
+
* @category combinators
|
|
614
|
+
*/
|
|
615
|
+
(
|
|
616
|
+
name: string,
|
|
617
|
+
options?: Omit<NonNullable<Cookies.Cookie["options"]>, "expires" | "maxAge">
|
|
618
|
+
): (self: HttpServerResponse) => HttpServerResponse
|
|
619
|
+
/**
|
|
620
|
+
* @since 4.0.0
|
|
621
|
+
* @category combinators
|
|
622
|
+
*/
|
|
623
|
+
(
|
|
624
|
+
self: HttpServerResponse,
|
|
625
|
+
name: string,
|
|
626
|
+
options?: Omit<NonNullable<Cookies.Cookie["options"]>, "expires" | "maxAge">
|
|
627
|
+
): HttpServerResponse
|
|
628
|
+
} = dual(
|
|
629
|
+
(args) => isHttpServerResponse(args[0]),
|
|
630
|
+
(
|
|
631
|
+
self: HttpServerResponse,
|
|
632
|
+
name: string,
|
|
633
|
+
options?: Omit<NonNullable<Cookies.Cookie["options"]>, "expires" | "maxAge">
|
|
634
|
+
): HttpServerResponse =>
|
|
635
|
+
makeResponse({
|
|
636
|
+
...self,
|
|
637
|
+
cookies: Cookies.expireCookieUnsafe(self.cookies, name, options)
|
|
638
|
+
})
|
|
639
|
+
)
|
|
640
|
+
|
|
561
641
|
/**
|
|
562
642
|
* @since 4.0.0
|
|
563
643
|
* @category combinators
|
|
@@ -829,6 +909,253 @@ export const toWeb = (
|
|
|
829
909
|
}
|
|
830
910
|
}
|
|
831
911
|
|
|
912
|
+
/**
|
|
913
|
+
* @since 4.0.0
|
|
914
|
+
* @category conversions
|
|
915
|
+
*/
|
|
916
|
+
export const toClientResponse = (
|
|
917
|
+
response: HttpServerResponse,
|
|
918
|
+
options?: {
|
|
919
|
+
readonly request?: HttpClientRequest.HttpClientRequest | undefined
|
|
920
|
+
}
|
|
921
|
+
): HttpClientResponse.HttpClientResponse =>
|
|
922
|
+
new ServerHttpClientResponse(
|
|
923
|
+
options?.request ?? HttpClientRequest.empty,
|
|
924
|
+
response
|
|
925
|
+
)
|
|
926
|
+
|
|
927
|
+
class ServerHttpClientResponse extends Inspectable.Class implements HttpClientResponse.HttpClientResponse {
|
|
928
|
+
readonly [HttpIncomingMessage.TypeId]: typeof HttpIncomingMessage.TypeId
|
|
929
|
+
readonly [HttpClientResponse.TypeId]: typeof HttpClientResponse.TypeId
|
|
930
|
+
|
|
931
|
+
readonly request: HttpClientRequest.HttpClientRequest
|
|
932
|
+
private readonly response: HttpServerResponse
|
|
933
|
+
|
|
934
|
+
constructor(
|
|
935
|
+
request: HttpClientRequest.HttpClientRequest,
|
|
936
|
+
response: HttpServerResponse
|
|
937
|
+
) {
|
|
938
|
+
super()
|
|
939
|
+
this.request = request
|
|
940
|
+
this.response = response
|
|
941
|
+
this[HttpIncomingMessage.TypeId] = HttpIncomingMessage.TypeId
|
|
942
|
+
this[HttpClientResponse.TypeId] = HttpClientResponse.TypeId
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
toJSON(): unknown {
|
|
946
|
+
return HttpIncomingMessage.inspect(this, {
|
|
947
|
+
_id: "HttpClientResponse",
|
|
948
|
+
request: this.request.toJSON(),
|
|
949
|
+
status: this.status
|
|
950
|
+
})
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
get status(): number {
|
|
954
|
+
return this.response.status
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
private cachedHeaders?: Headers.Headers
|
|
958
|
+
get headers(): Headers.Headers {
|
|
959
|
+
return this.cachedHeaders ??= this.response.body._tag === "FormData"
|
|
960
|
+
? Headers.merge(this.response.headers, Headers.fromInput(this.getFormDataResponse().headers))
|
|
961
|
+
: this.response.headers
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
get cookies(): Cookies.Cookies {
|
|
965
|
+
return this.response.cookies
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
get remoteAddress(): string | undefined {
|
|
969
|
+
return undefined
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
get stream(): Stream.Stream<Uint8Array, HttpClientError.HttpClientError> {
|
|
973
|
+
const body = this.response.body
|
|
974
|
+
switch (body._tag) {
|
|
975
|
+
case "Empty": {
|
|
976
|
+
return Stream.empty
|
|
977
|
+
}
|
|
978
|
+
case "Stream": {
|
|
979
|
+
return Stream.mapError(body.stream, (cause) => this.decodeError(cause))
|
|
980
|
+
}
|
|
981
|
+
case "Uint8Array": {
|
|
982
|
+
return Stream.succeed(body.body)
|
|
983
|
+
}
|
|
984
|
+
case "Raw": {
|
|
985
|
+
const rawBody = body.body
|
|
986
|
+
if (rawBody instanceof Response) {
|
|
987
|
+
return rawBody.body
|
|
988
|
+
? Stream.fromReadableStream({
|
|
989
|
+
evaluate: () => rawBody.body!,
|
|
990
|
+
onError: (cause) => this.decodeError(cause)
|
|
991
|
+
})
|
|
992
|
+
: Stream.empty
|
|
993
|
+
}
|
|
994
|
+
if (isReadableStream(rawBody)) {
|
|
995
|
+
return Stream.fromReadableStream({
|
|
996
|
+
evaluate: () => rawBody,
|
|
997
|
+
onError: (cause) => this.decodeError(cause)
|
|
998
|
+
})
|
|
999
|
+
}
|
|
1000
|
+
if (rawBody instanceof Blob) {
|
|
1001
|
+
return Stream.fromReadableStream({
|
|
1002
|
+
evaluate: () => rawBody.stream(),
|
|
1003
|
+
onError: (cause) => this.decodeError(cause)
|
|
1004
|
+
})
|
|
1005
|
+
}
|
|
1006
|
+
return Stream.unwrap(Effect.map(this.bytes, Stream.succeed))
|
|
1007
|
+
}
|
|
1008
|
+
case "FormData": {
|
|
1009
|
+
const response = this.getFormDataResponse()
|
|
1010
|
+
return Stream.fromReadableStream({
|
|
1011
|
+
evaluate: () => response.body!,
|
|
1012
|
+
onError: (cause) => this.decodeError(cause)
|
|
1013
|
+
})
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
get json(): Effect.Effect<unknown, HttpClientError.HttpClientError> {
|
|
1019
|
+
return Effect.flatMap(this.text, (text) =>
|
|
1020
|
+
Effect.try({
|
|
1021
|
+
try: () => text === "" ? null : JSON.parse(text) as unknown,
|
|
1022
|
+
catch: (cause) =>
|
|
1023
|
+
new HttpClientError.HttpClientError({
|
|
1024
|
+
reason: new HttpClientError.DecodeError({
|
|
1025
|
+
request: this.request,
|
|
1026
|
+
response: this,
|
|
1027
|
+
cause
|
|
1028
|
+
})
|
|
1029
|
+
})
|
|
1030
|
+
}))
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
private get bytes(): Effect.Effect<Uint8Array, HttpClientError.HttpClientError> {
|
|
1034
|
+
const body = this.response.body
|
|
1035
|
+
switch (body._tag) {
|
|
1036
|
+
case "Empty": {
|
|
1037
|
+
return Effect.succeed(new Uint8Array(0))
|
|
1038
|
+
}
|
|
1039
|
+
case "Uint8Array": {
|
|
1040
|
+
return Effect.succeed(body.body)
|
|
1041
|
+
}
|
|
1042
|
+
case "Stream": {
|
|
1043
|
+
return Stream.mkUint8Array(this.stream)
|
|
1044
|
+
}
|
|
1045
|
+
case "Raw": {
|
|
1046
|
+
const rawBody = body.body
|
|
1047
|
+
if (rawBody instanceof Response) {
|
|
1048
|
+
return Effect.tryPromise({
|
|
1049
|
+
try: () => rawBody.arrayBuffer().then((buffer) => new Uint8Array(buffer)),
|
|
1050
|
+
catch: (cause) => this.decodeError(cause)
|
|
1051
|
+
})
|
|
1052
|
+
}
|
|
1053
|
+
return Effect.tryPromise({
|
|
1054
|
+
try: () => new Response(rawBody as any).arrayBuffer().then((buffer) => new Uint8Array(buffer)),
|
|
1055
|
+
catch: (cause) => this.decodeError(cause)
|
|
1056
|
+
})
|
|
1057
|
+
}
|
|
1058
|
+
case "FormData": {
|
|
1059
|
+
return Effect.tryPromise({
|
|
1060
|
+
try: () => new Response(body.formData).arrayBuffer().then((buffer) => new Uint8Array(buffer)),
|
|
1061
|
+
catch: (cause) => this.decodeError(cause)
|
|
1062
|
+
})
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1067
|
+
get text(): Effect.Effect<string, HttpClientError.HttpClientError> {
|
|
1068
|
+
return Effect.map(this.bytes, (bytes) => textDecoder.decode(bytes))
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
get urlParamsBody(): Effect.Effect<UrlParams.UrlParams, HttpClientError.HttpClientError> {
|
|
1072
|
+
return Effect.flatMap(this.text, (_) =>
|
|
1073
|
+
Effect.try({
|
|
1074
|
+
try: () => UrlParams.fromInput(new URLSearchParams(_)),
|
|
1075
|
+
catch: (cause) =>
|
|
1076
|
+
new HttpClientError.HttpClientError({
|
|
1077
|
+
reason: new HttpClientError.DecodeError({
|
|
1078
|
+
request: this.request,
|
|
1079
|
+
response: this,
|
|
1080
|
+
cause
|
|
1081
|
+
})
|
|
1082
|
+
})
|
|
1083
|
+
}))
|
|
1084
|
+
}
|
|
1085
|
+
|
|
1086
|
+
get formData(): Effect.Effect<FormData, HttpClientError.HttpClientError> {
|
|
1087
|
+
const body = this.response.body
|
|
1088
|
+
if (body._tag === "FormData") {
|
|
1089
|
+
return Effect.succeed(body.formData)
|
|
1090
|
+
}
|
|
1091
|
+
return Effect.servicesWith((services: ServiceMap.ServiceMap<never>) => {
|
|
1092
|
+
const readableStream = Stream.toReadableStreamWith(this.stream, services)
|
|
1093
|
+
return Effect.tryPromise({
|
|
1094
|
+
try: () => new Response(readableStream, { headers: this.headers }).formData(),
|
|
1095
|
+
catch: (cause) => this.decodeError(cause)
|
|
1096
|
+
})
|
|
1097
|
+
})
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
get arrayBuffer(): Effect.Effect<ArrayBuffer, HttpClientError.HttpClientError> {
|
|
1101
|
+
return Effect.map(this.bytes, (bytes) => bytes.slice().buffer)
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
private decodeError(cause: unknown): HttpClientError.HttpClientError {
|
|
1105
|
+
return new HttpClientError.HttpClientError({
|
|
1106
|
+
reason: new HttpClientError.DecodeError({
|
|
1107
|
+
request: this.request,
|
|
1108
|
+
response: this,
|
|
1109
|
+
cause
|
|
1110
|
+
})
|
|
1111
|
+
})
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
private formDataResponse?: Response
|
|
1115
|
+
private getFormDataResponse(): Response {
|
|
1116
|
+
return this.formDataResponse ??= new Response((this.response.body as Body.FormData).formData)
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
const textDecoder = new TextDecoder()
|
|
1121
|
+
|
|
1122
|
+
/**
|
|
1123
|
+
* @since 4.0.0
|
|
1124
|
+
* @category conversions
|
|
1125
|
+
*/
|
|
1126
|
+
export const fromClientResponse = (
|
|
1127
|
+
response: HttpClientResponse.HttpClientResponse
|
|
1128
|
+
): HttpServerResponse => {
|
|
1129
|
+
const headers = Headers.remove(response.headers, "set-cookie")
|
|
1130
|
+
return makeResponse({
|
|
1131
|
+
status: response.status,
|
|
1132
|
+
headers,
|
|
1133
|
+
cookies: response.cookies,
|
|
1134
|
+
body: Body.stream(
|
|
1135
|
+
Stream.catchIf(response.stream, isEmptyBodyError, () => Stream.empty),
|
|
1136
|
+
Headers.get(headers, "content-type"),
|
|
1137
|
+
getContentLength(headers)
|
|
1138
|
+
)
|
|
1139
|
+
})
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
const isReadableStream = (u: unknown): u is ReadableStream<Uint8Array> =>
|
|
1143
|
+
typeof ReadableStream !== "undefined" && u instanceof ReadableStream
|
|
1144
|
+
|
|
1145
|
+
const isEmptyBodyError = (
|
|
1146
|
+
error: HttpClientError.HttpClientError
|
|
1147
|
+
): error is HttpClientError.HttpClientError =>
|
|
1148
|
+
HttpClientError.isHttpClientError(error) && error.reason._tag === "EmptyBodyError"
|
|
1149
|
+
|
|
1150
|
+
const getContentLength = (headers: Headers.Headers): number | undefined => {
|
|
1151
|
+
const contentLength = Headers.get(headers, "content-length")
|
|
1152
|
+
if (contentLength === undefined) {
|
|
1153
|
+
return undefined
|
|
1154
|
+
}
|
|
1155
|
+
const parsed = Number(contentLength)
|
|
1156
|
+
return Number.isFinite(parsed) && parsed >= 0 ? parsed : undefined
|
|
1157
|
+
}
|
|
1158
|
+
|
|
832
1159
|
const Proto: Omit<
|
|
833
1160
|
HttpServerResponse,
|
|
834
1161
|
"status" | "statusText" | "headers" | "cookies" | "body"
|