@effect/platform 0.47.0 → 0.48.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/dist/cjs/Error.js +40 -4
- package/dist/cjs/Error.js.map +1 -1
- package/dist/cjs/Http/Body.js +8 -1
- package/dist/cjs/Http/Body.js.map +1 -1
- package/dist/cjs/Http/ClientError.js +21 -2
- package/dist/cjs/Http/ClientError.js.map +1 -1
- package/dist/cjs/Http/Headers.js +22 -1
- package/dist/cjs/Http/Headers.js.map +1 -1
- package/dist/cjs/Http/IncomingMessage.js +1 -1
- package/dist/cjs/Http/IncomingMessage.js.map +1 -1
- package/dist/cjs/Http/Multipart.js +21 -6
- package/dist/cjs/Http/Multipart.js.map +1 -1
- package/dist/cjs/Http/ServerError.js +30 -7
- package/dist/cjs/Http/ServerError.js.map +1 -1
- package/dist/cjs/Http/UrlParams.js +7 -2
- package/dist/cjs/Http/UrlParams.js.map +1 -1
- package/dist/cjs/PlatformLogger.js +1 -1
- package/dist/cjs/Socket.js +104 -22
- package/dist/cjs/Socket.js.map +1 -1
- package/dist/cjs/Transferable.js +1 -1
- package/dist/cjs/Transferable.js.map +1 -1
- package/dist/cjs/WorkerError.js.map +1 -1
- package/dist/cjs/internal/http/body.js +1 -1
- package/dist/cjs/internal/http/body.js.map +1 -1
- package/dist/cjs/internal/http/client.js +5 -5
- package/dist/cjs/internal/http/client.js.map +1 -1
- package/dist/cjs/internal/http/clientError.js +1 -36
- package/dist/cjs/internal/http/clientError.js.map +1 -1
- package/dist/cjs/internal/http/clientResponse.js +8 -8
- package/dist/cjs/internal/http/clientResponse.js.map +1 -1
- package/dist/cjs/internal/http/multipart.js +15 -11
- package/dist/cjs/internal/http/multipart.js.map +1 -1
- package/dist/cjs/internal/http/multiplex.js +1 -1
- package/dist/cjs/internal/http/multiplex.js.map +1 -1
- package/dist/cjs/internal/http/router.js +1 -1
- package/dist/cjs/internal/http/router.js.map +1 -1
- package/dist/cjs/internal/http/serverError.js +1 -15
- package/dist/cjs/internal/http/serverError.js.map +1 -1
- package/dist/cjs/internal/http/serverRequest.js +8 -8
- package/dist/cjs/internal/http/serverRequest.js.map +1 -1
- package/dist/dts/Error.d.ts +22 -0
- package/dist/dts/Error.d.ts.map +1 -1
- package/dist/dts/Http/Body.d.ts +9 -1
- package/dist/dts/Http/Body.d.ts.map +1 -1
- package/dist/dts/Http/ClientError.d.ts +21 -33
- package/dist/dts/Http/ClientError.d.ts.map +1 -1
- package/dist/dts/Http/Headers.d.ts +19 -0
- package/dist/dts/Http/Headers.d.ts.map +1 -1
- package/dist/dts/Http/Multipart.d.ts +21 -6
- package/dist/dts/Http/Multipart.d.ts.map +1 -1
- package/dist/dts/Http/ServerError.d.ts +33 -47
- package/dist/dts/Http/ServerError.d.ts.map +1 -1
- package/dist/dts/Http/ServerRequest.d.ts +3 -3
- package/dist/dts/Http/ServerRequest.d.ts.map +1 -1
- package/dist/dts/Http/UrlParams.d.ts +5 -0
- package/dist/dts/Http/UrlParams.d.ts.map +1 -1
- package/dist/dts/PlatformLogger.d.ts +1 -1
- package/dist/dts/Runtime.d.ts +4 -1
- package/dist/dts/Runtime.d.ts.map +1 -1
- package/dist/dts/Socket.d.ts +89 -13
- package/dist/dts/Socket.d.ts.map +1 -1
- package/dist/dts/Worker.d.ts +6 -6
- package/dist/dts/Worker.d.ts.map +1 -1
- package/dist/dts/WorkerError.d.ts +10 -5
- package/dist/dts/WorkerError.d.ts.map +1 -1
- package/dist/dts/WorkerRunner.d.ts +1 -1
- package/dist/dts/WorkerRunner.d.ts.map +1 -1
- package/dist/esm/Error.js +38 -3
- package/dist/esm/Error.js.map +1 -1
- package/dist/esm/Http/Body.js +6 -0
- package/dist/esm/Http/Body.js.map +1 -1
- package/dist/esm/Http/ClientError.js +19 -2
- package/dist/esm/Http/ClientError.js.map +1 -1
- package/dist/esm/Http/Headers.js +21 -1
- package/dist/esm/Http/Headers.js.map +1 -1
- package/dist/esm/Http/IncomingMessage.js +1 -1
- package/dist/esm/Http/IncomingMessage.js.map +1 -1
- package/dist/esm/Http/Multipart.js +20 -5
- package/dist/esm/Http/Multipart.js.map +1 -1
- package/dist/esm/Http/ServerError.js +26 -7
- package/dist/esm/Http/ServerError.js.map +1 -1
- package/dist/esm/Http/UrlParams.js +5 -0
- package/dist/esm/Http/UrlParams.js.map +1 -1
- package/dist/esm/PlatformLogger.js +1 -1
- package/dist/esm/Socket.js +98 -20
- package/dist/esm/Socket.js.map +1 -1
- package/dist/esm/Transferable.js +1 -1
- package/dist/esm/Transferable.js.map +1 -1
- package/dist/esm/WorkerError.js.map +1 -1
- package/dist/esm/internal/http/body.js +1 -1
- package/dist/esm/internal/http/body.js.map +1 -1
- package/dist/esm/internal/http/client.js +5 -5
- package/dist/esm/internal/http/client.js.map +1 -1
- package/dist/esm/internal/http/clientError.js +0 -10
- package/dist/esm/internal/http/clientError.js.map +1 -1
- package/dist/esm/internal/http/clientResponse.js +8 -8
- package/dist/esm/internal/http/clientResponse.js.map +1 -1
- package/dist/esm/internal/http/multipart.js +10 -9
- package/dist/esm/internal/http/multipart.js.map +1 -1
- package/dist/esm/internal/http/multiplex.js +1 -1
- package/dist/esm/internal/http/multiplex.js.map +1 -1
- package/dist/esm/internal/http/router.js +1 -1
- package/dist/esm/internal/http/router.js.map +1 -1
- package/dist/esm/internal/http/serverError.js +0 -14
- package/dist/esm/internal/http/serverError.js.map +1 -1
- package/dist/esm/internal/http/serverRequest.js +8 -8
- package/dist/esm/internal/http/serverRequest.js.map +1 -1
- package/package.json +3 -3
- package/src/Error.ts +61 -0
- package/src/Http/Body.ts +14 -1
- package/src/Http/ClientError.ts +21 -38
- package/src/Http/Headers.ts +29 -1
- package/src/Http/IncomingMessage.ts +1 -1
- package/src/Http/Multipart.ts +25 -7
- package/src/Http/ServerError.ts +25 -56
- package/src/Http/ServerRequest.ts +5 -5
- package/src/Http/UrlParams.ts +10 -0
- package/src/PlatformLogger.ts +1 -1
- package/src/Runtime.ts +4 -1
- package/src/Socket.ts +179 -39
- package/src/Transferable.ts +1 -1
- package/src/Worker.ts +6 -6
- package/src/WorkerError.ts +9 -7
- package/src/WorkerRunner.ts +8 -8
- package/src/internal/http/body.ts +4 -2
- package/src/internal/http/client.ts +5 -6
- package/src/internal/http/clientError.ts +0 -14
- package/src/internal/http/clientResponse.ts +15 -14
- package/src/internal/http/multipart.ts +16 -12
- package/src/internal/http/multiplex.ts +1 -1
- package/src/internal/http/router.ts +1 -1
- package/src/internal/http/serverError.ts +0 -20
- package/src/internal/http/serverRequest.ts +22 -18
package/src/WorkerError.ts
CHANGED
|
@@ -55,22 +55,24 @@ export class WorkerError extends Schema.TaggedError<WorkerError>()("WorkerError"
|
|
|
55
55
|
*/
|
|
56
56
|
static readonly Cause: Schema.Schema<
|
|
57
57
|
Cause.Cause<WorkerError>,
|
|
58
|
-
Schema.
|
|
58
|
+
Schema.CauseEncoded<WorkerErrorFrom>
|
|
59
59
|
> = Schema.cause({ defect: causeDefectPretty, error: this })
|
|
60
60
|
|
|
61
61
|
/**
|
|
62
62
|
* @since 1.0.0
|
|
63
63
|
*/
|
|
64
|
-
static readonly encodeCause: (a: Cause.Cause<WorkerError>) => Schema.
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
static readonly encodeCause: (a: Cause.Cause<WorkerError>) => Schema.CauseEncoded<WorkerErrorFrom> = Schema
|
|
65
|
+
.encodeSync(
|
|
66
|
+
this.Cause
|
|
67
|
+
)
|
|
67
68
|
|
|
68
69
|
/**
|
|
69
70
|
* @since 1.0.0
|
|
70
71
|
*/
|
|
71
|
-
static readonly decodeCause: (u: Schema.
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
static readonly decodeCause: (u: Schema.CauseEncoded<WorkerErrorFrom>) => Cause.Cause<WorkerError> = Schema
|
|
73
|
+
.decodeSync(
|
|
74
|
+
this.Cause
|
|
75
|
+
)
|
|
74
76
|
|
|
75
77
|
/**
|
|
76
78
|
* @since 1.0.0
|
package/src/WorkerRunner.ts
CHANGED
|
@@ -121,19 +121,19 @@ export declare namespace SerializedRunner {
|
|
|
121
121
|
A,
|
|
122
122
|
{ readonly _tag: K }
|
|
123
123
|
> extends Serializable.SerializableWithResult<
|
|
124
|
-
infer _RS,
|
|
125
|
-
infer _IS,
|
|
126
124
|
infer S,
|
|
127
|
-
infer
|
|
128
|
-
infer
|
|
125
|
+
infer _SI,
|
|
126
|
+
infer _SR,
|
|
127
|
+
infer A,
|
|
128
|
+
infer _AI,
|
|
129
129
|
infer E,
|
|
130
|
-
infer
|
|
131
|
-
infer
|
|
130
|
+
infer _EI,
|
|
131
|
+
infer _RR
|
|
132
132
|
> ? (
|
|
133
133
|
_: S
|
|
134
134
|
) =>
|
|
135
|
-
| Stream.Stream<
|
|
136
|
-
| Effect.Effect<
|
|
135
|
+
| Stream.Stream<A, E, any>
|
|
136
|
+
| Effect.Effect<A, E, any>
|
|
137
137
|
| Layer.Layer<any, E, any>
|
|
138
138
|
| Layer.Layer<never, E, any>
|
|
139
139
|
: never
|
|
@@ -48,8 +48,10 @@ class RawImpl implements Body.Raw {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
/** @internal */
|
|
51
|
-
export const raw = (body: unknown,
|
|
52
|
-
|
|
51
|
+
export const raw = (body: unknown, options?: {
|
|
52
|
+
readonly contentType?: string
|
|
53
|
+
readonly contentLength?: number
|
|
54
|
+
}): Body.Raw => new RawImpl(body, options?.contentType, options?.contentLength)
|
|
53
55
|
|
|
54
56
|
class Uint8ArrayImpl implements Body.Uint8Array {
|
|
55
57
|
readonly [TypeId]: Body.TypeId
|
|
@@ -11,13 +11,12 @@ import type * as Scope from "effect/Scope"
|
|
|
11
11
|
import * as Stream from "effect/Stream"
|
|
12
12
|
import type * as Body from "../../Http/Body.js"
|
|
13
13
|
import type * as Client from "../../Http/Client.js"
|
|
14
|
-
import
|
|
14
|
+
import * as Error from "../../Http/ClientError.js"
|
|
15
15
|
import type * as ClientRequest from "../../Http/ClientRequest.js"
|
|
16
16
|
import type * as ClientResponse from "../../Http/ClientResponse.js"
|
|
17
17
|
import * as Method from "../../Http/Method.js"
|
|
18
18
|
import * as UrlParams from "../../Http/UrlParams.js"
|
|
19
19
|
import * as internalBody from "./body.js"
|
|
20
|
-
import * as internalError from "./clientError.js"
|
|
21
20
|
import * as internalRequest from "./clientRequest.js"
|
|
22
21
|
import * as internalResponse from "./clientResponse.js"
|
|
23
22
|
|
|
@@ -82,7 +81,7 @@ export const fetch = (options?: RequestInit): Client.Client.Default =>
|
|
|
82
81
|
makeDefault((request) =>
|
|
83
82
|
Effect.flatMap(
|
|
84
83
|
UrlParams.makeUrl(request.url, request.urlParams, (_) =>
|
|
85
|
-
|
|
84
|
+
new Error.RequestError({
|
|
86
85
|
request,
|
|
87
86
|
reason: "InvalidUrl",
|
|
88
87
|
error: _
|
|
@@ -109,7 +108,7 @@ export const fetch = (options?: RequestInit): Client.Client.Default =>
|
|
|
109
108
|
signal: controller.signal
|
|
110
109
|
} as any),
|
|
111
110
|
catch: (_) =>
|
|
112
|
-
|
|
111
|
+
new Error.RequestError({
|
|
113
112
|
request,
|
|
114
113
|
reason: "Transport",
|
|
115
114
|
error: _
|
|
@@ -419,7 +418,7 @@ export const filterStatus = dual<
|
|
|
419
418
|
effect,
|
|
420
419
|
(response) => f(response.status),
|
|
421
420
|
(response) =>
|
|
422
|
-
|
|
421
|
+
new Error.ResponseError({
|
|
423
422
|
request,
|
|
424
423
|
response,
|
|
425
424
|
reason: "StatusCode",
|
|
@@ -571,7 +570,7 @@ export const schemaFunction = dual<
|
|
|
571
570
|
Effect.tryMap(encode(a), {
|
|
572
571
|
try: (body) => new TextEncoder().encode(JSON.stringify(body)),
|
|
573
572
|
catch: (error) =>
|
|
574
|
-
|
|
573
|
+
new Error.RequestError({
|
|
575
574
|
request,
|
|
576
575
|
reason: "Encode",
|
|
577
576
|
error
|
|
@@ -1,20 +1,6 @@
|
|
|
1
|
-
import * as Data from "effect/Data"
|
|
2
1
|
import type * as Error from "../../Http/ClientError.js"
|
|
3
2
|
|
|
4
3
|
/** @internal */
|
|
5
4
|
export const TypeId: Error.TypeId = Symbol.for(
|
|
6
5
|
"@effect/platform/Http/Error"
|
|
7
6
|
) as Error.TypeId
|
|
8
|
-
|
|
9
|
-
const make = <A extends Error.HttpClientError>(tag: A["_tag"]) => (props: Omit<A, Error.HttpError.ProvidedFields>): A =>
|
|
10
|
-
Data.struct({
|
|
11
|
-
[TypeId]: TypeId,
|
|
12
|
-
_tag: tag,
|
|
13
|
-
...props
|
|
14
|
-
} as A)
|
|
15
|
-
|
|
16
|
-
/** @internal */
|
|
17
|
-
export const requestError = make<Error.RequestError>("RequestError")
|
|
18
|
-
|
|
19
|
-
/** @internal */
|
|
20
|
-
export const responseError = make<Error.ResponseError>("ResponseError")
|
|
@@ -3,13 +3,12 @@ import * as Schema from "@effect/schema/Schema"
|
|
|
3
3
|
import * as Effect from "effect/Effect"
|
|
4
4
|
import * as Option from "effect/Option"
|
|
5
5
|
import * as Stream from "effect/Stream"
|
|
6
|
-
import
|
|
6
|
+
import * as Error from "../../Http/ClientError.js"
|
|
7
7
|
import type * as ClientRequest from "../../Http/ClientRequest.js"
|
|
8
8
|
import type * as ClientResponse from "../../Http/ClientResponse.js"
|
|
9
9
|
import * as Headers from "../../Http/Headers.js"
|
|
10
10
|
import * as IncomingMessage from "../../Http/IncomingMessage.js"
|
|
11
11
|
import * as UrlParams from "../../Http/UrlParams.js"
|
|
12
|
-
import * as internalError from "./clientError.js"
|
|
13
12
|
|
|
14
13
|
/** @internal */
|
|
15
14
|
export const TypeId: ClientResponse.TypeId = Symbol.for("@effect/platform/Http/ClientResponse") as ClientResponse.TypeId
|
|
@@ -47,25 +46,27 @@ class ClientResponseImpl implements ClientResponse.ClientResponse {
|
|
|
47
46
|
get stream(): Stream.Stream<Uint8Array, Error.ResponseError> {
|
|
48
47
|
return this.source.body
|
|
49
48
|
? Stream.fromReadableStream(() => this.source.body!, (_) =>
|
|
50
|
-
|
|
49
|
+
new Error.ResponseError({
|
|
51
50
|
request: this.request,
|
|
52
51
|
response: this,
|
|
53
52
|
reason: "Decode",
|
|
54
53
|
error: _
|
|
55
54
|
}))
|
|
56
|
-
: Stream.fail(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
55
|
+
: Stream.fail(
|
|
56
|
+
new Error.ResponseError({
|
|
57
|
+
request: this.request,
|
|
58
|
+
response: this,
|
|
59
|
+
reason: "EmptyBody",
|
|
60
|
+
error: "can not create stream from empty body"
|
|
61
|
+
})
|
|
62
|
+
)
|
|
62
63
|
}
|
|
63
64
|
|
|
64
65
|
get json(): Effect.Effect<unknown, Error.ResponseError> {
|
|
65
66
|
return Effect.tryMap(this.text, {
|
|
66
67
|
try: (text) => text === "" ? null : JSON.parse(text) as unknown,
|
|
67
68
|
catch: (_) =>
|
|
68
|
-
|
|
69
|
+
new Error.ResponseError({
|
|
69
70
|
request: this.request,
|
|
70
71
|
response: this,
|
|
71
72
|
reason: "Decode",
|
|
@@ -79,7 +80,7 @@ class ClientResponseImpl implements ClientResponse.ClientResponse {
|
|
|
79
80
|
return this.textBody ??= Effect.tryPromise({
|
|
80
81
|
try: () => this.source.text(),
|
|
81
82
|
catch: (_) =>
|
|
82
|
-
|
|
83
|
+
new Error.ResponseError({
|
|
83
84
|
request: this.request,
|
|
84
85
|
response: this,
|
|
85
86
|
reason: "Decode",
|
|
@@ -93,7 +94,7 @@ class ClientResponseImpl implements ClientResponse.ClientResponse {
|
|
|
93
94
|
Effect.try({
|
|
94
95
|
try: () => UrlParams.fromInput(new URLSearchParams(_)),
|
|
95
96
|
catch: (_) =>
|
|
96
|
-
|
|
97
|
+
new Error.ResponseError({
|
|
97
98
|
request: this.request,
|
|
98
99
|
response: this,
|
|
99
100
|
reason: "Decode",
|
|
@@ -107,7 +108,7 @@ class ClientResponseImpl implements ClientResponse.ClientResponse {
|
|
|
107
108
|
return this.formDataBody ??= Effect.tryPromise({
|
|
108
109
|
try: () => this.source.formData(),
|
|
109
110
|
catch: (_) =>
|
|
110
|
-
|
|
111
|
+
new Error.ResponseError({
|
|
111
112
|
request: this.request,
|
|
112
113
|
response: this,
|
|
113
114
|
reason: "Decode",
|
|
@@ -121,7 +122,7 @@ class ClientResponseImpl implements ClientResponse.ClientResponse {
|
|
|
121
122
|
return this.arrayBufferBody ??= Effect.tryPromise({
|
|
122
123
|
try: () => this.source.arrayBuffer(),
|
|
123
124
|
catch: (_) =>
|
|
124
|
-
|
|
125
|
+
new Error.ResponseError({
|
|
125
126
|
request: this.request,
|
|
126
127
|
response: this,
|
|
127
128
|
reason: "Decode",
|
|
@@ -23,6 +23,19 @@ import * as Path from "../../Path.js"
|
|
|
23
23
|
/** @internal */
|
|
24
24
|
export const TypeId: Multipart.TypeId = Symbol.for("@effect/platform/Http/Multipart") as Multipart.TypeId
|
|
25
25
|
|
|
26
|
+
/** @internal */
|
|
27
|
+
export const isPart = (u: unknown): u is Multipart.Part => Predicate.hasProperty(u, TypeId)
|
|
28
|
+
|
|
29
|
+
/** @internal */
|
|
30
|
+
export const isField = (u: unknown): u is Multipart.Field => isPart(u) && u._tag === "Field"
|
|
31
|
+
|
|
32
|
+
/** @internal */
|
|
33
|
+
export const isFile = (u: unknown): u is Multipart.File => isPart(u) && u._tag === "File"
|
|
34
|
+
|
|
35
|
+
/** @internal */
|
|
36
|
+
export const isPersistedFile = (u: unknown): u is Multipart.PersistedFile =>
|
|
37
|
+
Predicate.hasProperty(u, TypeId) && Predicate.isTagged(u, "PersistedFile")
|
|
38
|
+
|
|
26
39
|
/** @internal */
|
|
27
40
|
export const ErrorTypeId: Multipart.ErrorTypeId = Symbol.for(
|
|
28
41
|
"@effect/platform/Http/Multipart/MultipartError"
|
|
@@ -37,10 +50,6 @@ export const MultipartError = (reason: Multipart.MultipartError["reason"], error
|
|
|
37
50
|
error
|
|
38
51
|
})
|
|
39
52
|
|
|
40
|
-
/** @internal */
|
|
41
|
-
export const isField = (u: unknown): u is Multipart.Field =>
|
|
42
|
-
Predicate.hasProperty(u, TypeId) && Predicate.isTagged(u, "Field")
|
|
43
|
-
|
|
44
53
|
/** @internal */
|
|
45
54
|
export const maxParts: FiberRef.FiberRef<Option.Option<number>> = globalValue(
|
|
46
55
|
"@effect/platform/Http/Multipart/maxParts",
|
|
@@ -89,20 +98,15 @@ export const withFieldMimeTypes = dual<
|
|
|
89
98
|
<R, E, A>(effect: Effect.Effect<A, E, R>, mimeTypes: ReadonlyArray<string>) => Effect.Effect<A, E, R>
|
|
90
99
|
>(2, (effect, mimeTypes) => Effect.locally(effect, fieldMimeTypes, Chunk.fromIterable(mimeTypes)))
|
|
91
100
|
|
|
92
|
-
const fileSchema: Schema.Schema<Multipart.PersistedFile> = Schema.
|
|
93
|
-
|
|
94
|
-
_tag: Schema.literal("PersistedFile"),
|
|
95
|
-
key: Schema.string,
|
|
96
|
-
name: Schema.string,
|
|
97
|
-
contentType: Schema.string,
|
|
98
|
-
path: Schema.string
|
|
101
|
+
const fileSchema: Schema.Schema<Multipart.PersistedFile> = Schema.declare(isPersistedFile, {
|
|
102
|
+
identifier: "PersistedFile"
|
|
99
103
|
})
|
|
100
104
|
|
|
101
105
|
/** @internal */
|
|
102
106
|
export const filesSchema: Schema.Schema<ReadonlyArray<Multipart.PersistedFile>> = Schema.array(fileSchema)
|
|
103
107
|
|
|
104
108
|
/** @internal */
|
|
105
|
-
export const schemaPersisted = <R, I extends Multipart.Persisted
|
|
109
|
+
export const schemaPersisted = <R, I extends Partial<Multipart.Persisted>, A>(
|
|
106
110
|
schema: Schema.Schema<A, I, R>
|
|
107
111
|
) => {
|
|
108
112
|
const parse = Schema.decodeUnknown(schema)
|
|
@@ -29,7 +29,7 @@ class MultiplexImpl<R, E>
|
|
|
29
29
|
this[TypeId] = TypeId
|
|
30
30
|
|
|
31
31
|
let execute: (request: ServerRequest.ServerRequest) => App.Default<R, E | Error.RouteNotFound> = (request) =>
|
|
32
|
-
Effect.fail(Error.RouteNotFound({ request }))
|
|
32
|
+
Effect.fail(new Error.RouteNotFound({ request }))
|
|
33
33
|
|
|
34
34
|
for (let i = apps.length - 1; i >= 0; i--) {
|
|
35
35
|
const [predicate, app] = apps[i]
|
|
@@ -151,7 +151,7 @@ const toHttpApp = <R, E>(
|
|
|
151
151
|
result = router.find("GET", request.url)
|
|
152
152
|
}
|
|
153
153
|
if (result === undefined) {
|
|
154
|
-
return Effect.fail(Error.RouteNotFound({ request }))
|
|
154
|
+
return Effect.fail(new Error.RouteNotFound({ request }))
|
|
155
155
|
}
|
|
156
156
|
const route = result.handler
|
|
157
157
|
if (route.prefix._tag === "Some") {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import * as Cause from "effect/Cause"
|
|
2
|
-
import * as Data from "effect/Data"
|
|
3
2
|
import * as FiberId from "effect/FiberId"
|
|
4
3
|
import { globalValue } from "effect/GlobalValue"
|
|
5
4
|
import * as Option from "effect/Option"
|
|
@@ -11,28 +10,9 @@ export const TypeId: Error.TypeId = Symbol.for(
|
|
|
11
10
|
"@effect/platform/Http/Error"
|
|
12
11
|
) as Error.TypeId
|
|
13
12
|
|
|
14
|
-
const make = <A extends Error.HttpServerError>(tag: A["_tag"]) => (props: Omit<A, Error.HttpError.ProvidedFields>): A =>
|
|
15
|
-
Data.struct({
|
|
16
|
-
[TypeId]: TypeId,
|
|
17
|
-
_tag: tag,
|
|
18
|
-
...props
|
|
19
|
-
} as A)
|
|
20
|
-
|
|
21
13
|
/** @internal */
|
|
22
14
|
export const isServerError = (u: unknown): u is Error.HttpServerError => Predicate.hasProperty(u, TypeId)
|
|
23
15
|
|
|
24
|
-
/** @internal */
|
|
25
|
-
export const requestError = make<Error.RequestError>("RequestError")
|
|
26
|
-
|
|
27
|
-
/** @internal */
|
|
28
|
-
export const responseError = make<Error.ResponseError>("ResponseError")
|
|
29
|
-
|
|
30
|
-
/** @internal */
|
|
31
|
-
export const routeNotFound = make<Error.RouteNotFound>("RouteNotFound")
|
|
32
|
-
|
|
33
|
-
/** @internal */
|
|
34
|
-
export const serveError = make<Error.ServeError>("ServeError")
|
|
35
|
-
|
|
36
16
|
/** @internal */
|
|
37
17
|
export const clientAbortFiberId = globalValue(
|
|
38
18
|
"@effect/platform/Http/ServerError/clientAbortFiberId",
|
|
@@ -48,7 +48,7 @@ const isMultipart = (request: ServerRequest.ServerRequest) =>
|
|
|
48
48
|
request.headers["content-type"]?.toLowerCase().includes("multipart/form-data")
|
|
49
49
|
|
|
50
50
|
/** @internal */
|
|
51
|
-
export const schemaBodyForm = <R, I extends Multipart.Persisted
|
|
51
|
+
export const schemaBodyForm = <R, I extends Partial<Multipart.Persisted>, A>(
|
|
52
52
|
schema: Schema.Schema<A, I, R>
|
|
53
53
|
) => {
|
|
54
54
|
const parseMultipart = Multipart.schemaPersisted(schema)
|
|
@@ -74,7 +74,7 @@ export const schemaBodyUrlParams = <R, I extends Readonly<Record<string, string>
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
/** @internal */
|
|
77
|
-
export const schemaBodyMultipart = <R, I extends Multipart.Persisted
|
|
77
|
+
export const schemaBodyMultipart = <R, I extends Partial<Multipart.Persisted>, A>(
|
|
78
78
|
schema: Schema.Schema<A, I, R>
|
|
79
79
|
) => {
|
|
80
80
|
const parse = Multipart.schemaPersisted(schema)
|
|
@@ -98,7 +98,7 @@ export const schemaBodyFormJson = <A, I, R>(schema: Schema.Schema<A, I, R>) => {
|
|
|
98
98
|
if (isMultipart(request)) {
|
|
99
99
|
return Effect.flatMap(
|
|
100
100
|
Effect.mapError(request.multipart, (error) =>
|
|
101
|
-
Error.RequestError({
|
|
101
|
+
new Error.RequestError({
|
|
102
102
|
request,
|
|
103
103
|
reason: "Decode",
|
|
104
104
|
error
|
|
@@ -158,16 +158,18 @@ class ServerRequestImpl implements ServerRequest.ServerRequest {
|
|
|
158
158
|
get stream(): Stream.Stream<Uint8Array, Error.RequestError> {
|
|
159
159
|
return this.source.body
|
|
160
160
|
? Stream.fromReadableStream(() => this.source.body as any, (_) =>
|
|
161
|
-
Error.RequestError({
|
|
161
|
+
new Error.RequestError({
|
|
162
162
|
request: this,
|
|
163
163
|
reason: "Decode",
|
|
164
164
|
error: _
|
|
165
165
|
}))
|
|
166
|
-
: Stream.fail(
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
166
|
+
: Stream.fail(
|
|
167
|
+
new Error.RequestError({
|
|
168
|
+
request: this,
|
|
169
|
+
reason: "Decode",
|
|
170
|
+
error: "can not create stream from empty body"
|
|
171
|
+
})
|
|
172
|
+
)
|
|
171
173
|
}
|
|
172
174
|
|
|
173
175
|
private textEffect: Effect.Effect<string, Error.RequestError> | undefined
|
|
@@ -179,7 +181,7 @@ class ServerRequestImpl implements ServerRequest.ServerRequest {
|
|
|
179
181
|
Effect.tryPromise({
|
|
180
182
|
try: () => this.source.text(),
|
|
181
183
|
catch: (error) =>
|
|
182
|
-
Error.RequestError({
|
|
184
|
+
new Error.RequestError({
|
|
183
185
|
request: this,
|
|
184
186
|
reason: "Decode",
|
|
185
187
|
error
|
|
@@ -193,7 +195,7 @@ class ServerRequestImpl implements ServerRequest.ServerRequest {
|
|
|
193
195
|
return Effect.tryMap(this.text, {
|
|
194
196
|
try: (_) => JSON.parse(_) as unknown,
|
|
195
197
|
catch: (error) =>
|
|
196
|
-
Error.RequestError({
|
|
198
|
+
new Error.RequestError({
|
|
197
199
|
request: this,
|
|
198
200
|
reason: "Decode",
|
|
199
201
|
error
|
|
@@ -206,7 +208,7 @@ class ServerRequestImpl implements ServerRequest.ServerRequest {
|
|
|
206
208
|
Effect.try({
|
|
207
209
|
try: () => UrlParams.fromInput(new URLSearchParams(_)),
|
|
208
210
|
catch: (error) =>
|
|
209
|
-
Error.RequestError({
|
|
211
|
+
new Error.RequestError({
|
|
210
212
|
request: this,
|
|
211
213
|
reason: "Decode",
|
|
212
214
|
error
|
|
@@ -251,7 +253,7 @@ class ServerRequestImpl implements ServerRequest.ServerRequest {
|
|
|
251
253
|
Effect.tryPromise({
|
|
252
254
|
try: () => this.source.arrayBuffer(),
|
|
253
255
|
catch: (error) =>
|
|
254
|
-
Error.RequestError({
|
|
256
|
+
new Error.RequestError({
|
|
255
257
|
request: this,
|
|
256
258
|
reason: "Decode",
|
|
257
259
|
error
|
|
@@ -262,10 +264,12 @@ class ServerRequestImpl implements ServerRequest.ServerRequest {
|
|
|
262
264
|
}
|
|
263
265
|
|
|
264
266
|
get upgrade(): Effect.Effect<Socket.Socket, Error.RequestError> {
|
|
265
|
-
return Effect.fail(
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
267
|
+
return Effect.fail(
|
|
268
|
+
new Error.RequestError({
|
|
269
|
+
request: this,
|
|
270
|
+
reason: "Decode",
|
|
271
|
+
error: "Not an upgradeable ServerRequest"
|
|
272
|
+
})
|
|
273
|
+
)
|
|
270
274
|
}
|
|
271
275
|
}
|