@effect/platform 0.48.8 → 0.48.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/dist/cjs/Command.js.map +1 -1
- package/dist/cjs/CommandExecutor.js +6 -1
- package/dist/cjs/CommandExecutor.js.map +1 -1
- package/dist/cjs/Error.js +1 -1
- package/dist/cjs/Error.js.map +1 -1
- package/dist/cjs/Http/Body.js.map +1 -1
- package/dist/cjs/Http/Client.js.map +1 -1
- package/dist/cjs/Http/ClientRequest.js.map +1 -1
- package/dist/cjs/Http/IncomingMessage.js +31 -1
- package/dist/cjs/Http/IncomingMessage.js.map +1 -1
- package/dist/cjs/Http/Multipart.js.map +1 -1
- package/dist/cjs/Http/Multiplex.js.map +1 -1
- package/dist/cjs/Http/Router.js.map +1 -1
- package/dist/cjs/Http/ServerResponse.js.map +1 -1
- package/dist/cjs/Path.js +6 -1
- package/dist/cjs/Path.js.map +1 -1
- package/dist/cjs/WorkerError.js +2 -1
- package/dist/cjs/WorkerError.js.map +1 -1
- package/dist/cjs/internal/command.js +60 -31
- package/dist/cjs/internal/command.js.map +1 -1
- package/dist/cjs/internal/commandExecutor.js +4 -1
- package/dist/cjs/internal/commandExecutor.js.map +1 -1
- package/dist/cjs/internal/http/body.js +59 -14
- package/dist/cjs/internal/http/body.js.map +1 -1
- package/dist/cjs/internal/http/clientRequest.js +13 -1
- package/dist/cjs/internal/http/clientRequest.js.map +1 -1
- package/dist/cjs/internal/http/clientResponse.js +10 -1
- package/dist/cjs/internal/http/clientResponse.js.map +1 -1
- package/dist/cjs/internal/http/multipart.js +80 -24
- package/dist/cjs/internal/http/multipart.js.map +1 -1
- package/dist/cjs/internal/http/multiplex.js +12 -0
- package/dist/cjs/internal/http/multiplex.js.map +1 -1
- package/dist/cjs/internal/http/router.js +10 -1
- package/dist/cjs/internal/http/router.js.map +1 -1
- package/dist/cjs/internal/http/serverRequest.js +14 -2
- package/dist/cjs/internal/http/serverRequest.js.map +1 -1
- package/dist/cjs/internal/http/serverResponse.js +9 -2
- package/dist/cjs/internal/http/serverResponse.js.map +1 -1
- package/dist/cjs/internal/path.js +4 -1
- package/dist/cjs/internal/path.js.map +1 -1
- package/dist/dts/Command.d.ts +5 -3
- package/dist/dts/Command.d.ts.map +1 -1
- package/dist/dts/CommandExecutor.d.ts +13 -1
- package/dist/dts/CommandExecutor.d.ts.map +1 -1
- package/dist/dts/Error.d.ts.map +1 -1
- package/dist/dts/Http/Body.d.ts +2 -1
- package/dist/dts/Http/Body.d.ts.map +1 -1
- package/dist/dts/Http/Client.d.ts +2 -1
- package/dist/dts/Http/Client.d.ts.map +1 -1
- package/dist/dts/Http/ClientRequest.d.ts +2 -1
- package/dist/dts/Http/ClientRequest.d.ts.map +1 -1
- package/dist/dts/Http/IncomingMessage.d.ts +6 -1
- package/dist/dts/Http/IncomingMessage.d.ts.map +1 -1
- package/dist/dts/Http/Multipart.d.ts +8 -3
- package/dist/dts/Http/Multipart.d.ts.map +1 -1
- package/dist/dts/Http/Multiplex.d.ts +2 -1
- package/dist/dts/Http/Multiplex.d.ts.map +1 -1
- package/dist/dts/Http/Router.d.ts +3 -2
- package/dist/dts/Http/Router.d.ts.map +1 -1
- package/dist/dts/Http/ServerResponse.d.ts +2 -1
- package/dist/dts/Http/ServerResponse.d.ts.map +1 -1
- package/dist/dts/Path.d.ts +11 -0
- package/dist/dts/Path.d.ts.map +1 -1
- package/dist/dts/WorkerError.d.ts.map +1 -1
- package/dist/dts/internal/http/router.d.ts.map +1 -1
- package/dist/esm/Command.js.map +1 -1
- package/dist/esm/CommandExecutor.js +5 -0
- package/dist/esm/CommandExecutor.js.map +1 -1
- package/dist/esm/Error.js +1 -1
- package/dist/esm/Error.js.map +1 -1
- package/dist/esm/Http/Body.js.map +1 -1
- package/dist/esm/Http/Client.js.map +1 -1
- package/dist/esm/Http/ClientRequest.js.map +1 -1
- package/dist/esm/Http/IncomingMessage.js +29 -0
- package/dist/esm/Http/IncomingMessage.js.map +1 -1
- package/dist/esm/Http/Multipart.js.map +1 -1
- package/dist/esm/Http/Multiplex.js.map +1 -1
- package/dist/esm/Http/Router.js.map +1 -1
- package/dist/esm/Http/ServerResponse.js.map +1 -1
- package/dist/esm/Path.js +5 -0
- package/dist/esm/Path.js.map +1 -1
- package/dist/esm/WorkerError.js +2 -1
- package/dist/esm/WorkerError.js.map +1 -1
- package/dist/esm/internal/command.js +60 -31
- package/dist/esm/internal/command.js.map +1 -1
- package/dist/esm/internal/commandExecutor.js +3 -0
- package/dist/esm/internal/commandExecutor.js.map +1 -1
- package/dist/esm/internal/http/body.js +59 -14
- package/dist/esm/internal/http/body.js.map +1 -1
- package/dist/esm/internal/http/clientRequest.js +13 -1
- package/dist/esm/internal/http/clientRequest.js.map +1 -1
- package/dist/esm/internal/http/clientResponse.js +10 -1
- package/dist/esm/internal/http/clientResponse.js.map +1 -1
- package/dist/esm/internal/http/multipart.js +80 -24
- package/dist/esm/internal/http/multipart.js.map +1 -1
- package/dist/esm/internal/http/multiplex.js +12 -0
- package/dist/esm/internal/http/multiplex.js.map +1 -1
- package/dist/esm/internal/http/router.js +10 -1
- package/dist/esm/internal/http/router.js.map +1 -1
- package/dist/esm/internal/http/serverRequest.js +14 -2
- package/dist/esm/internal/http/serverRequest.js.map +1 -1
- package/dist/esm/internal/http/serverResponse.js +9 -2
- package/dist/esm/internal/http/serverResponse.js.map +1 -1
- package/dist/esm/internal/path.js +3 -0
- package/dist/esm/internal/path.js.map +1 -1
- package/package.json +3 -3
- package/src/Command.ts +5 -3
- package/src/CommandExecutor.ts +16 -1
- package/src/Error.ts +5 -1
- package/src/Http/Body.ts +2 -1
- package/src/Http/Client.ts +2 -1
- package/src/Http/ClientRequest.ts +2 -1
- package/src/Http/IncomingMessage.ts +32 -1
- package/src/Http/Multipart.ts +9 -5
- package/src/Http/Multiplex.ts +2 -1
- package/src/Http/Router.ts +3 -2
- package/src/Http/ServerResponse.ts +2 -1
- package/src/Path.ts +13 -0
- package/src/WorkerError.ts +2 -1
- package/src/internal/command.ts +72 -34
- package/src/internal/commandExecutor.ts +4 -0
- package/src/internal/http/body.ts +62 -14
- package/src/internal/http/clientRequest.ts +13 -1
- package/src/internal/http/clientResponse.ts +11 -1
- package/src/internal/http/multipart.ts +61 -24
- package/src/internal/http/multiplex.ts +13 -0
- package/src/internal/http/router.ts +10 -1
- package/src/internal/http/serverRequest.ts +11 -2
- package/src/internal/http/serverResponse.ts +11 -2
- package/src/internal/path.ts +6 -2
|
@@ -2,6 +2,7 @@ import * as Schema from "@effect/schema/Schema"
|
|
|
2
2
|
import * as Data from "effect/Data"
|
|
3
3
|
import * as Effect from "effect/Effect"
|
|
4
4
|
import { identity } from "effect/Function"
|
|
5
|
+
import * as Inspectable from "effect/Inspectable"
|
|
5
6
|
import * as Stream_ from "effect/Stream"
|
|
6
7
|
import type * as PlatformError from "../../Error.js"
|
|
7
8
|
import * as FileSystem from "../../FileSystem.js"
|
|
@@ -24,26 +25,51 @@ const bodyError = Data.tagged<Body.BodyError>("BodyError")
|
|
|
24
25
|
export const BodyError = (reason: Body.BodyErrorReason): Body.BodyError =>
|
|
25
26
|
bodyError({ [ErrorTypeId]: ErrorTypeId, reason })
|
|
26
27
|
|
|
27
|
-
class
|
|
28
|
+
abstract class BodyBase implements Body.Body.Proto {
|
|
28
29
|
readonly [TypeId]: Body.TypeId
|
|
29
|
-
readonly _tag
|
|
30
|
+
abstract readonly _tag: string
|
|
30
31
|
constructor() {
|
|
31
32
|
this[TypeId] = TypeId
|
|
32
33
|
}
|
|
34
|
+
abstract toJSON(): unknown
|
|
35
|
+
[Inspectable.NodeInspectSymbol](): unknown {
|
|
36
|
+
return this.toJSON()
|
|
37
|
+
}
|
|
38
|
+
toString(): string {
|
|
39
|
+
return Inspectable.format(this)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
class EmptyImpl extends BodyBase implements Body.Empty {
|
|
44
|
+
readonly _tag = "Empty"
|
|
45
|
+
toJSON(): unknown {
|
|
46
|
+
return {
|
|
47
|
+
_id: "@effect/platform/Http/Body",
|
|
48
|
+
_tag: "Empty"
|
|
49
|
+
}
|
|
50
|
+
}
|
|
33
51
|
}
|
|
34
52
|
|
|
35
53
|
/** @internal */
|
|
36
54
|
export const empty: Body.Empty = new EmptyImpl()
|
|
37
55
|
|
|
38
|
-
class RawImpl implements Body.Raw {
|
|
39
|
-
readonly [TypeId]: Body.TypeId
|
|
56
|
+
class RawImpl extends BodyBase implements Body.Raw {
|
|
40
57
|
readonly _tag = "Raw"
|
|
41
58
|
constructor(
|
|
42
59
|
readonly body: unknown,
|
|
43
60
|
readonly contentType?: string | undefined,
|
|
44
61
|
readonly contentLength?: number | undefined
|
|
45
62
|
) {
|
|
46
|
-
|
|
63
|
+
super()
|
|
64
|
+
}
|
|
65
|
+
toJSON(): unknown {
|
|
66
|
+
return {
|
|
67
|
+
_id: "@effect/platform/Http/Body",
|
|
68
|
+
_tag: "Raw",
|
|
69
|
+
body: this.body,
|
|
70
|
+
contentType: this.contentType,
|
|
71
|
+
contentLength: this.contentLength
|
|
72
|
+
}
|
|
47
73
|
}
|
|
48
74
|
}
|
|
49
75
|
|
|
@@ -53,18 +79,27 @@ export const raw = (body: unknown, options?: {
|
|
|
53
79
|
readonly contentLength?: number | undefined
|
|
54
80
|
}): Body.Raw => new RawImpl(body, options?.contentType, options?.contentLength)
|
|
55
81
|
|
|
56
|
-
class Uint8ArrayImpl implements Body.Uint8Array {
|
|
57
|
-
readonly [TypeId]: Body.TypeId
|
|
82
|
+
class Uint8ArrayImpl extends BodyBase implements Body.Uint8Array {
|
|
58
83
|
readonly _tag = "Uint8Array"
|
|
59
84
|
constructor(
|
|
60
85
|
readonly body: Uint8Array,
|
|
61
86
|
readonly contentType: string
|
|
62
87
|
) {
|
|
63
|
-
|
|
88
|
+
super()
|
|
64
89
|
}
|
|
65
90
|
get contentLength(): number {
|
|
66
91
|
return this.body.length
|
|
67
92
|
}
|
|
93
|
+
toJSON(): unknown {
|
|
94
|
+
const toString = this.contentType.startsWith("text/") || this.contentType.endsWith("json")
|
|
95
|
+
return {
|
|
96
|
+
_id: "@effect/platform/Http/Body",
|
|
97
|
+
_tag: "Uint8Array",
|
|
98
|
+
body: toString ? new TextDecoder().decode(this.body) : `Uint8Array(${this.body.length})`,
|
|
99
|
+
contentType: this.contentType,
|
|
100
|
+
contentLength: this.contentLength
|
|
101
|
+
}
|
|
102
|
+
}
|
|
68
103
|
}
|
|
69
104
|
|
|
70
105
|
/** @internal */
|
|
@@ -137,28 +172,41 @@ export const fileInfo = (
|
|
|
137
172
|
export const fileWeb = (file: Body.Body.FileLike): Body.Stream =>
|
|
138
173
|
stream(Stream_.fromReadableStream(() => file.stream() as ReadableStream<Uint8Array>, identity), file.type, file.size)
|
|
139
174
|
|
|
140
|
-
class FormDataImpl implements Body.FormData {
|
|
141
|
-
readonly [TypeId]: Body.TypeId
|
|
175
|
+
class FormDataImpl extends BodyBase implements Body.FormData {
|
|
142
176
|
readonly _tag = "FormData"
|
|
143
177
|
constructor(
|
|
144
178
|
readonly formData: FormData
|
|
145
179
|
) {
|
|
146
|
-
|
|
180
|
+
super()
|
|
181
|
+
}
|
|
182
|
+
toJSON(): unknown {
|
|
183
|
+
return {
|
|
184
|
+
_id: "@effect/platform/Http/Body",
|
|
185
|
+
_tag: "FormData",
|
|
186
|
+
formData: this.formData
|
|
187
|
+
}
|
|
147
188
|
}
|
|
148
189
|
}
|
|
149
190
|
|
|
150
191
|
/** @internal */
|
|
151
192
|
export const formData = (body: FormData): Body.FormData => new FormDataImpl(body)
|
|
152
193
|
|
|
153
|
-
class StreamImpl implements Body.Stream {
|
|
154
|
-
readonly [TypeId]: Body.TypeId
|
|
194
|
+
class StreamImpl extends BodyBase implements Body.Stream {
|
|
155
195
|
readonly _tag = "Stream"
|
|
156
196
|
constructor(
|
|
157
197
|
readonly stream: Stream_.Stream<Uint8Array, unknown>,
|
|
158
198
|
readonly contentType: string,
|
|
159
199
|
readonly contentLength?: number | undefined
|
|
160
200
|
) {
|
|
161
|
-
|
|
201
|
+
super()
|
|
202
|
+
}
|
|
203
|
+
toJSON(): unknown {
|
|
204
|
+
return {
|
|
205
|
+
_id: "@effect/platform/Http/Body",
|
|
206
|
+
_tag: "Stream",
|
|
207
|
+
contentType: this.contentType,
|
|
208
|
+
contentLength: this.contentLength
|
|
209
|
+
}
|
|
162
210
|
}
|
|
163
211
|
}
|
|
164
212
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type * as Schema from "@effect/schema/Schema"
|
|
2
2
|
import * as Effect from "effect/Effect"
|
|
3
3
|
import { dual } from "effect/Function"
|
|
4
|
+
import * as Inspectable from "effect/Inspectable"
|
|
4
5
|
import { pipeArguments } from "effect/Pipeable"
|
|
5
6
|
import type * as Stream from "effect/Stream"
|
|
6
7
|
import type * as PlatformError from "../../Error.js"
|
|
@@ -15,7 +16,7 @@ import * as internalBody from "./body.js"
|
|
|
15
16
|
/** @internal */
|
|
16
17
|
export const TypeId: ClientRequest.TypeId = Symbol.for("@effect/platform/Http/ClientRequest") as ClientRequest.TypeId
|
|
17
18
|
|
|
18
|
-
class ClientRequestImpl implements ClientRequest.ClientRequest {
|
|
19
|
+
class ClientRequestImpl extends Inspectable.Class implements ClientRequest.ClientRequest {
|
|
19
20
|
readonly [TypeId]: ClientRequest.TypeId
|
|
20
21
|
constructor(
|
|
21
22
|
readonly method: Method,
|
|
@@ -24,11 +25,22 @@ class ClientRequestImpl implements ClientRequest.ClientRequest {
|
|
|
24
25
|
readonly headers: Headers.Headers,
|
|
25
26
|
readonly body: Body.Body
|
|
26
27
|
) {
|
|
28
|
+
super()
|
|
27
29
|
this[TypeId] = TypeId
|
|
28
30
|
}
|
|
29
31
|
pipe() {
|
|
30
32
|
return pipeArguments(this, arguments)
|
|
31
33
|
}
|
|
34
|
+
toJSON(): unknown {
|
|
35
|
+
return {
|
|
36
|
+
_id: "@effect/platform/Http/ClientRequest",
|
|
37
|
+
method: this.method,
|
|
38
|
+
url: this.url,
|
|
39
|
+
urlParams: this.urlParams,
|
|
40
|
+
headers: this.headers,
|
|
41
|
+
body: this.body.toJSON()
|
|
42
|
+
}
|
|
43
|
+
}
|
|
32
44
|
}
|
|
33
45
|
|
|
34
46
|
/** @internal */
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type * as ParseResult from "@effect/schema/ParseResult"
|
|
2
2
|
import * as Schema from "@effect/schema/Schema"
|
|
3
3
|
import * as Effect from "effect/Effect"
|
|
4
|
+
import * as Inspectable from "effect/Inspectable"
|
|
4
5
|
import * as Option from "effect/Option"
|
|
5
6
|
import * as Stream from "effect/Stream"
|
|
6
7
|
import * as Error from "../../Http/ClientError.js"
|
|
@@ -19,7 +20,7 @@ export const fromWeb = (
|
|
|
19
20
|
source: globalThis.Response
|
|
20
21
|
): ClientResponse.ClientResponse => new ClientResponseImpl(request, source)
|
|
21
22
|
|
|
22
|
-
class ClientResponseImpl implements ClientResponse.ClientResponse {
|
|
23
|
+
class ClientResponseImpl extends Inspectable.Class implements ClientResponse.ClientResponse {
|
|
23
24
|
readonly [IncomingMessage.TypeId]: IncomingMessage.TypeId
|
|
24
25
|
readonly [TypeId]: ClientResponse.TypeId
|
|
25
26
|
|
|
@@ -27,10 +28,19 @@ class ClientResponseImpl implements ClientResponse.ClientResponse {
|
|
|
27
28
|
private readonly request: ClientRequest.ClientRequest,
|
|
28
29
|
private readonly source: globalThis.Response
|
|
29
30
|
) {
|
|
31
|
+
super()
|
|
30
32
|
this[IncomingMessage.TypeId] = IncomingMessage.TypeId
|
|
31
33
|
this[TypeId] = TypeId
|
|
32
34
|
}
|
|
33
35
|
|
|
36
|
+
toJSON(): unknown {
|
|
37
|
+
return IncomingMessage.inspect(this, {
|
|
38
|
+
_id: "@effect/platform/Http/ClientResponse",
|
|
39
|
+
request: this.request.toJSON(),
|
|
40
|
+
status: this.status
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
|
|
34
44
|
get status(): number {
|
|
35
45
|
return this.source.status
|
|
36
46
|
}
|
|
@@ -3,11 +3,11 @@ import * as Schema from "@effect/schema/Schema"
|
|
|
3
3
|
import * as Cause from "effect/Cause"
|
|
4
4
|
import * as Channel from "effect/Channel"
|
|
5
5
|
import * as Chunk from "effect/Chunk"
|
|
6
|
-
import * as Data from "effect/Data"
|
|
7
6
|
import * as Effect from "effect/Effect"
|
|
8
7
|
import * as FiberRef from "effect/FiberRef"
|
|
9
8
|
import { dual, flow, pipe } from "effect/Function"
|
|
10
9
|
import { globalValue } from "effect/GlobalValue"
|
|
10
|
+
import * as Inspectable from "effect/Inspectable"
|
|
11
11
|
import * as Option from "effect/Option"
|
|
12
12
|
import * as Predicate from "effect/Predicate"
|
|
13
13
|
import * as Queue from "effect/Queue"
|
|
@@ -15,6 +15,7 @@ import type * as Scope from "effect/Scope"
|
|
|
15
15
|
import type * as AsyncInput from "effect/SingleProducerAsyncInput"
|
|
16
16
|
import * as Stream from "effect/Stream"
|
|
17
17
|
import * as MP from "multipasta"
|
|
18
|
+
import { RefailError } from "../../Error.js"
|
|
18
19
|
import * as FileSystem from "../../FileSystem.js"
|
|
19
20
|
import * as IncomingMessage from "../../Http/IncomingMessage.js"
|
|
20
21
|
import type * as Multipart from "../../Http/Multipart.js"
|
|
@@ -42,13 +43,13 @@ export const ErrorTypeId: Multipart.ErrorTypeId = Symbol.for(
|
|
|
42
43
|
) as Multipart.ErrorTypeId
|
|
43
44
|
|
|
44
45
|
/** @internal */
|
|
45
|
-
export
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
reason
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
export class MultipartError extends RefailError(ErrorTypeId, "MultipartError")<{
|
|
47
|
+
readonly reason: "FileTooLarge" | "FieldTooLarge" | "BodyTooLarge" | "TooManyParts" | "InternalError" | "Parse"
|
|
48
|
+
}> {
|
|
49
|
+
get message() {
|
|
50
|
+
return `${this.reason}: ${super.message}`
|
|
51
|
+
}
|
|
52
|
+
}
|
|
52
53
|
|
|
53
54
|
/** @internal */
|
|
54
55
|
export const maxParts: FiberRef.FiberRef<Option.Option<number>> = globalValue(
|
|
@@ -310,27 +311,34 @@ function convertError(error: MP.MultipartError): Multipart.MultipartError {
|
|
|
310
311
|
case "ReachedLimit": {
|
|
311
312
|
switch (error.limit) {
|
|
312
313
|
case "MaxParts": {
|
|
313
|
-
return MultipartError("TooManyParts", error)
|
|
314
|
+
return new MultipartError({ reason: "TooManyParts", error })
|
|
314
315
|
}
|
|
315
316
|
case "MaxFieldSize": {
|
|
316
|
-
return MultipartError("FieldTooLarge", error)
|
|
317
|
+
return new MultipartError({ reason: "FieldTooLarge", error })
|
|
317
318
|
}
|
|
318
319
|
case "MaxPartSize": {
|
|
319
|
-
return MultipartError("FileTooLarge", error)
|
|
320
|
+
return new MultipartError({ reason: "FileTooLarge", error })
|
|
320
321
|
}
|
|
321
322
|
case "MaxTotalSize": {
|
|
322
|
-
return MultipartError("BodyTooLarge", error)
|
|
323
|
+
return new MultipartError({ reason: "BodyTooLarge", error })
|
|
323
324
|
}
|
|
324
325
|
}
|
|
325
326
|
}
|
|
326
327
|
default: {
|
|
327
|
-
return MultipartError("Parse", error)
|
|
328
|
+
return new MultipartError({ reason: "Parse", error })
|
|
328
329
|
}
|
|
329
330
|
}
|
|
330
331
|
}
|
|
331
332
|
|
|
332
|
-
class
|
|
333
|
+
abstract class PartBase extends Inspectable.Class {
|
|
333
334
|
readonly [TypeId]: Multipart.TypeId
|
|
335
|
+
constructor() {
|
|
336
|
+
super()
|
|
337
|
+
this[TypeId] = TypeId
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
class FieldImpl extends PartBase implements Multipart.Field {
|
|
334
342
|
readonly _tag = "Field"
|
|
335
343
|
|
|
336
344
|
constructor(
|
|
@@ -338,13 +346,22 @@ class FieldImpl implements Multipart.Field {
|
|
|
338
346
|
readonly contentType: string,
|
|
339
347
|
readonly value: string
|
|
340
348
|
) {
|
|
341
|
-
|
|
349
|
+
super()
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
toJSON(): unknown {
|
|
353
|
+
return {
|
|
354
|
+
_id: "@effect/platform/Http/Multipart/Part",
|
|
355
|
+
_tag: "Field",
|
|
356
|
+
key: this.key,
|
|
357
|
+
contentType: this.contentType,
|
|
358
|
+
value: this.value
|
|
359
|
+
}
|
|
342
360
|
}
|
|
343
361
|
}
|
|
344
362
|
|
|
345
|
-
class FileImpl implements Multipart.File {
|
|
363
|
+
class FileImpl extends PartBase implements Multipart.File {
|
|
346
364
|
readonly _tag = "File"
|
|
347
|
-
readonly [TypeId]: Multipart.TypeId
|
|
348
365
|
readonly key: string
|
|
349
366
|
readonly name: string
|
|
350
367
|
readonly contentType: string
|
|
@@ -354,12 +371,22 @@ class FileImpl implements Multipart.File {
|
|
|
354
371
|
info: MP.PartInfo,
|
|
355
372
|
channel: Channel.Channel<Chunk.Chunk<Uint8Array>, unknown, never, unknown, void, unknown>
|
|
356
373
|
) {
|
|
357
|
-
|
|
374
|
+
super()
|
|
358
375
|
this.key = info.name
|
|
359
376
|
this.name = info.filename ?? info.name
|
|
360
377
|
this.contentType = info.contentType
|
|
361
378
|
this.content = Stream.fromChannel(channel)
|
|
362
379
|
}
|
|
380
|
+
|
|
381
|
+
toJSON(): unknown {
|
|
382
|
+
return {
|
|
383
|
+
_id: "@effect/platform/Http/Multipart/Part",
|
|
384
|
+
_tag: "File",
|
|
385
|
+
key: this.key,
|
|
386
|
+
name: this.name,
|
|
387
|
+
contentType: this.contentType
|
|
388
|
+
}
|
|
389
|
+
}
|
|
363
390
|
}
|
|
364
391
|
|
|
365
392
|
const defaultWriteFile = (path: string, file: Multipart.File) =>
|
|
@@ -368,7 +395,7 @@ const defaultWriteFile = (path: string, file: Multipart.File) =>
|
|
|
368
395
|
(fs) =>
|
|
369
396
|
Effect.mapError(
|
|
370
397
|
Stream.run(file.content, fs.sink(path)),
|
|
371
|
-
(error) => MultipartError("InternalError", error)
|
|
398
|
+
(error) => new MultipartError({ reason: "InternalError", error })
|
|
372
399
|
)
|
|
373
400
|
)
|
|
374
401
|
|
|
@@ -409,13 +436,12 @@ export const toPersisted = (
|
|
|
409
436
|
)
|
|
410
437
|
),
|
|
411
438
|
Effect.catchTags({
|
|
412
|
-
SystemError: (
|
|
413
|
-
BadArgument: (
|
|
439
|
+
SystemError: (error) => Effect.fail(new MultipartError({ reason: "InternalError", error })),
|
|
440
|
+
BadArgument: (error) => Effect.fail(new MultipartError({ reason: "InternalError", error }))
|
|
414
441
|
})
|
|
415
442
|
)
|
|
416
443
|
|
|
417
|
-
class PersistedFileImpl implements Multipart.PersistedFile {
|
|
418
|
-
readonly [TypeId]: Multipart.TypeId
|
|
444
|
+
class PersistedFileImpl extends PartBase implements Multipart.PersistedFile {
|
|
419
445
|
readonly _tag = "PersistedFile"
|
|
420
446
|
|
|
421
447
|
constructor(
|
|
@@ -424,6 +450,17 @@ class PersistedFileImpl implements Multipart.PersistedFile {
|
|
|
424
450
|
readonly contentType: string,
|
|
425
451
|
readonly path: string
|
|
426
452
|
) {
|
|
427
|
-
|
|
453
|
+
super()
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
toJSON(): unknown {
|
|
457
|
+
return {
|
|
458
|
+
_id: "@effect/platform/Http/Multipart/Part",
|
|
459
|
+
_tag: "PersistedFile",
|
|
460
|
+
key: this.key,
|
|
461
|
+
name: this.name,
|
|
462
|
+
contentType: this.contentType,
|
|
463
|
+
path: this.path
|
|
464
|
+
}
|
|
428
465
|
}
|
|
429
466
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as Effect from "effect/Effect"
|
|
2
2
|
import * as Effectable from "effect/Effectable"
|
|
3
3
|
import { dual } from "effect/Function"
|
|
4
|
+
import * as Inspectable from "effect/Inspectable"
|
|
4
5
|
import * as ReadonlyArray from "effect/ReadonlyArray"
|
|
5
6
|
import type * as App from "../../Http/App.js"
|
|
6
7
|
import type * as Multiplex from "../../Http/Multiplex.js"
|
|
@@ -49,6 +50,18 @@ class MultiplexImpl<R, E>
|
|
|
49
50
|
commit() {
|
|
50
51
|
return this.execute
|
|
51
52
|
}
|
|
53
|
+
|
|
54
|
+
[Inspectable.NodeInspectSymbol]() {
|
|
55
|
+
return Inspectable.toJSON(this)
|
|
56
|
+
}
|
|
57
|
+
toString(): string {
|
|
58
|
+
return Inspectable.format(this)
|
|
59
|
+
}
|
|
60
|
+
toJSON(): unknown {
|
|
61
|
+
return {
|
|
62
|
+
_id: "@effect/platform/Http/Multiplex"
|
|
63
|
+
}
|
|
64
|
+
}
|
|
52
65
|
}
|
|
53
66
|
|
|
54
67
|
/** @internal */
|
|
@@ -179,7 +179,7 @@ function sliceRequestUrl(request: ServerRequest.ServerRequest, prefix: string) {
|
|
|
179
179
|
return request.modify({ url: request.url.length <= prefexLen ? "/" : request.url.slice(prefexLen) })
|
|
180
180
|
}
|
|
181
181
|
|
|
182
|
-
class RouteImpl<R, E> implements Router.Route<R, E> {
|
|
182
|
+
class RouteImpl<R, E> extends Inspectable.Class implements Router.Route<R, E> {
|
|
183
183
|
readonly [RouteTypeId]: Router.RouteTypeId
|
|
184
184
|
constructor(
|
|
185
185
|
readonly method: Method.Method | "*",
|
|
@@ -187,8 +187,17 @@ class RouteImpl<R, E> implements Router.Route<R, E> {
|
|
|
187
187
|
readonly handler: Router.Route.Handler<R, E>,
|
|
188
188
|
readonly prefix = Option.none<string>()
|
|
189
189
|
) {
|
|
190
|
+
super()
|
|
190
191
|
this[RouteTypeId] = RouteTypeId
|
|
191
192
|
}
|
|
193
|
+
toJSON(): unknown {
|
|
194
|
+
return {
|
|
195
|
+
_id: "@effect/platform/Http/Router/Route",
|
|
196
|
+
method: this.method,
|
|
197
|
+
path: this.path,
|
|
198
|
+
prefix: this.prefix.toJSON()
|
|
199
|
+
}
|
|
200
|
+
}
|
|
192
201
|
}
|
|
193
202
|
|
|
194
203
|
class RouteContextImpl implements Router.RouteContext {
|
|
@@ -3,6 +3,7 @@ import type * as Schema from "@effect/schema/Schema"
|
|
|
3
3
|
import * as Channel from "effect/Channel"
|
|
4
4
|
import * as Context from "effect/Context"
|
|
5
5
|
import * as Effect from "effect/Effect"
|
|
6
|
+
import * as Inspectable from "effect/Inspectable"
|
|
6
7
|
import * as Option from "effect/Option"
|
|
7
8
|
import type * as Scope from "effect/Scope"
|
|
8
9
|
import * as Stream from "effect/Stream"
|
|
@@ -115,7 +116,7 @@ export const schemaBodyFormJson = <A, I, R>(schema: Schema.Schema<A, I, R>) => {
|
|
|
115
116
|
export const fromWeb = (request: globalThis.Request): ServerRequest.ServerRequest =>
|
|
116
117
|
new ServerRequestImpl(request, request.url)
|
|
117
118
|
|
|
118
|
-
class ServerRequestImpl implements ServerRequest.ServerRequest {
|
|
119
|
+
class ServerRequestImpl extends Inspectable.Class implements ServerRequest.ServerRequest {
|
|
119
120
|
readonly [TypeId]: ServerRequest.TypeId
|
|
120
121
|
readonly [IncomingMessage.TypeId]: IncomingMessage.TypeId
|
|
121
122
|
constructor(
|
|
@@ -124,9 +125,17 @@ class ServerRequestImpl implements ServerRequest.ServerRequest {
|
|
|
124
125
|
public headersOverride?: Headers.Headers,
|
|
125
126
|
private remoteAddressOverride?: string
|
|
126
127
|
) {
|
|
128
|
+
super()
|
|
127
129
|
this[TypeId] = TypeId
|
|
128
130
|
this[IncomingMessage.TypeId] = IncomingMessage.TypeId
|
|
129
131
|
}
|
|
132
|
+
toJSON(): unknown {
|
|
133
|
+
return IncomingMessage.inspect(this, {
|
|
134
|
+
_id: "@effect/platform/Http/ServerRequest",
|
|
135
|
+
method: this.method,
|
|
136
|
+
url: this.originalUrl
|
|
137
|
+
})
|
|
138
|
+
}
|
|
130
139
|
modify(
|
|
131
140
|
options: {
|
|
132
141
|
readonly url?: string | undefined
|
|
@@ -239,7 +248,7 @@ class ServerRequestImpl implements ServerRequest.ServerRequest {
|
|
|
239
248
|
|
|
240
249
|
get multipartStream(): Stream.Stream<Multipart.Part, Multipart.MultipartError> {
|
|
241
250
|
return Stream.pipeThroughChannel(
|
|
242
|
-
Stream.mapError(this.stream, (error) => Multipart.MultipartError("InternalError", error)),
|
|
251
|
+
Stream.mapError(this.stream, (error) => new Multipart.MultipartError({ reason: "InternalError", error })),
|
|
243
252
|
Multipart.makeChannel(this.headers)
|
|
244
253
|
)
|
|
245
254
|
}
|
|
@@ -2,6 +2,7 @@ import type * as Schema from "@effect/schema/Schema"
|
|
|
2
2
|
import * as Effect from "effect/Effect"
|
|
3
3
|
import * as Effectable from "effect/Effectable"
|
|
4
4
|
import { dual } from "effect/Function"
|
|
5
|
+
import * as Inspectable from "effect/Inspectable"
|
|
5
6
|
import * as Stream from "effect/Stream"
|
|
6
7
|
import type * as PlatformError from "../../Error.js"
|
|
7
8
|
import type * as FileSystem from "../../FileSystem.js"
|
|
@@ -47,13 +48,21 @@ class ServerResponseImpl extends Effectable.StructuralClass<ServerResponse.Serve
|
|
|
47
48
|
return Effect.succeed(this)
|
|
48
49
|
}
|
|
49
50
|
|
|
51
|
+
[Inspectable.NodeInspectSymbol]() {
|
|
52
|
+
return this.toJSON()
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
toString(): string {
|
|
56
|
+
return Inspectable.format(this)
|
|
57
|
+
}
|
|
58
|
+
|
|
50
59
|
toJSON() {
|
|
51
60
|
return {
|
|
52
|
-
_id: "ServerResponse",
|
|
61
|
+
_id: "@effect/platform/Http/ServerResponse",
|
|
53
62
|
status: this.status,
|
|
54
63
|
statusText: this.statusText,
|
|
55
64
|
headers: this.headers,
|
|
56
|
-
body: this.body
|
|
65
|
+
body: this.body.toJSON()
|
|
57
66
|
}
|
|
58
67
|
}
|
|
59
68
|
}
|
package/src/internal/path.ts
CHANGED
|
@@ -4,15 +4,19 @@ import { identity } from "effect/Function"
|
|
|
4
4
|
import * as Layer from "effect/Layer"
|
|
5
5
|
import PathB from "path-browserify"
|
|
6
6
|
import { BadArgument } from "../Error.js"
|
|
7
|
-
import type
|
|
7
|
+
import type * as Api from "../Path.js"
|
|
8
8
|
|
|
9
9
|
/** @internal */
|
|
10
|
-
export const
|
|
10
|
+
export const TypeId: Api.TypeId = Symbol.for("@effect/platform/Path") as Api.TypeId
|
|
11
|
+
|
|
12
|
+
/** @internal */
|
|
13
|
+
export const Path = GenericTag<Api.Path>("@effect/platform/Path")
|
|
11
14
|
|
|
12
15
|
/** @internal */
|
|
13
16
|
export const layer = Layer.succeed(
|
|
14
17
|
Path,
|
|
15
18
|
Path.of({
|
|
19
|
+
[TypeId]: TypeId,
|
|
16
20
|
...PathB,
|
|
17
21
|
fromFileUrl,
|
|
18
22
|
toFileUrl,
|