@effect/platform 0.38.0 → 0.40.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/Http/Multipart/package.json +6 -0
- package/LICENSE +1 -1
- package/README.md +63 -2
- package/dist/cjs/Http/Body.js +6 -1
- package/dist/cjs/Http/Body.js.map +1 -1
- package/dist/cjs/Http/IncomingMessage.js +3 -1
- package/dist/cjs/Http/IncomingMessage.js.map +1 -1
- package/dist/cjs/Http/{FormData.js → Multipart.js} +5 -5
- package/dist/cjs/Http/Multipart.js.map +1 -0
- package/dist/cjs/Http/Router.js.map +1 -1
- package/dist/cjs/Http/ServerRequest.js +9 -4
- package/dist/cjs/Http/ServerRequest.js.map +1 -1
- package/dist/cjs/Http/UrlParams.js +32 -5
- package/dist/cjs/Http/UrlParams.js.map +1 -1
- package/dist/cjs/HttpServer.js +3 -3
- package/dist/cjs/HttpServer.js.map +1 -1
- package/dist/cjs/internal/http/body.js +9 -4
- package/dist/cjs/internal/http/body.js.map +1 -1
- package/dist/cjs/internal/http/client.js +6 -7
- package/dist/cjs/internal/http/client.js.map +1 -1
- package/dist/cjs/internal/http/clientRequest.js +1 -1
- package/dist/cjs/internal/http/clientRequest.js.map +1 -1
- package/dist/cjs/internal/http/{formData.js → multipart.js} +42 -35
- package/dist/cjs/internal/http/multipart.js.map +1 -0
- package/dist/cjs/internal/http/router.js +4 -2
- package/dist/cjs/internal/http/router.js.map +1 -1
- package/dist/cjs/internal/http/serverRequest.js +43 -24
- package/dist/cjs/internal/http/serverRequest.js.map +1 -1
- package/dist/cjs/internal/http/serverResponse.js.map +1 -1
- package/dist/cjs/internal/keyValueStore.js +1 -1
- package/dist/cjs/internal/keyValueStore.js.map +1 -1
- package/dist/dts/Error.d.ts +1 -1
- package/dist/dts/Error.d.ts.map +1 -1
- package/dist/dts/Http/Body.d.ts +6 -0
- package/dist/dts/Http/Body.d.ts.map +1 -1
- package/dist/dts/Http/{FormData.d.ts → Multipart.d.ts} +11 -11
- package/dist/dts/Http/Multipart.d.ts.map +1 -0
- package/dist/dts/Http/Router.d.ts +1 -0
- package/dist/dts/Http/Router.d.ts.map +1 -1
- package/dist/dts/Http/ServerRequest.d.ts +11 -6
- package/dist/dts/Http/ServerRequest.d.ts.map +1 -1
- package/dist/dts/Http/ServerResponse.d.ts +5 -5
- package/dist/dts/Http/ServerResponse.d.ts.map +1 -1
- package/dist/dts/Http/UrlParams.d.ts +35 -0
- package/dist/dts/Http/UrlParams.d.ts.map +1 -1
- package/dist/dts/HttpServer.d.ts +8 -8
- package/dist/dts/HttpServer.d.ts.map +1 -1
- package/dist/dts/internal/http/multipart.d.ts +2 -0
- package/dist/dts/internal/http/multipart.d.ts.map +1 -0
- package/dist/dts/internal/http/router.d.ts.map +1 -1
- package/dist/esm/Http/Body.js +5 -0
- package/dist/esm/Http/Body.js.map +1 -1
- package/dist/esm/Http/IncomingMessage.js +3 -1
- package/dist/esm/Http/IncomingMessage.js.map +1 -1
- package/dist/esm/Http/{FormData.js → Multipart.js} +4 -4
- package/dist/esm/Http/Multipart.js.map +1 -0
- package/dist/esm/Http/Router.js.map +1 -1
- package/dist/esm/Http/ServerRequest.js +8 -3
- package/dist/esm/Http/ServerRequest.js.map +1 -1
- package/dist/esm/Http/UrlParams.js +30 -3
- package/dist/esm/Http/UrlParams.js.map +1 -1
- package/dist/esm/HttpServer.js +8 -8
- package/dist/esm/HttpServer.js.map +1 -1
- package/dist/esm/internal/http/body.js +6 -2
- package/dist/esm/internal/http/body.js.map +1 -1
- package/dist/esm/internal/http/client.js +6 -7
- package/dist/esm/internal/http/client.js.map +1 -1
- package/dist/esm/internal/http/clientRequest.js +1 -1
- package/dist/esm/internal/http/clientRequest.js.map +1 -1
- package/dist/esm/internal/http/{formData.js → multipart.js} +39 -32
- package/dist/esm/internal/http/multipart.js.map +1 -0
- package/dist/esm/internal/http/router.js +4 -2
- package/dist/esm/internal/http/router.js.map +1 -1
- package/dist/esm/internal/http/serverRequest.js +38 -20
- package/dist/esm/internal/http/serverRequest.js.map +1 -1
- package/dist/esm/internal/http/serverResponse.js.map +1 -1
- package/dist/esm/internal/keyValueStore.js +1 -1
- package/dist/esm/internal/keyValueStore.js.map +1 -1
- package/package.json +13 -14
- package/src/Error.ts +1 -1
- package/src/Http/Body.ts +7 -0
- package/src/Http/IncomingMessage.ts +1 -1
- package/src/Http/{FormData.ts → Multipart.ts} +17 -18
- package/src/Http/Router.ts +1 -0
- package/src/Http/ServerRequest.ts +26 -14
- package/src/Http/ServerResponse.ts +5 -5
- package/src/Http/UrlParams.ts +79 -0
- package/src/HttpServer.ts +8 -8
- package/src/internal/http/body.ts +9 -3
- package/src/internal/http/client.ts +13 -17
- package/src/internal/http/clientRequest.ts +1 -1
- package/src/internal/http/{formData.ts → multipart.ts} +79 -80
- package/src/internal/http/router.ts +2 -1
- package/src/internal/http/serverRequest.ts +66 -37
- package/src/internal/http/serverResponse.ts +4 -1
- package/src/internal/keyValueStore.ts +1 -1
- package/Http/FormData/package.json +0 -6
- package/dist/cjs/Http/FormData.js.map +0 -1
- package/dist/cjs/internal/http/formData.js.map +0 -1
- package/dist/dts/Http/FormData.d.ts.map +0 -1
- package/dist/dts/internal/http/formData.d.ts +0 -2
- package/dist/dts/internal/http/formData.d.ts.map +0 -1
- package/dist/esm/Http/FormData.js.map +0 -1
- package/dist/esm/internal/http/formData.js.map +0 -1
|
@@ -13,7 +13,7 @@ import type * as Scope from "effect/Scope"
|
|
|
13
13
|
import type * as Stream from "effect/Stream"
|
|
14
14
|
import type * as Multipasta from "multipasta"
|
|
15
15
|
import type * as FileSystem from "../FileSystem.js"
|
|
16
|
-
import * as internal from "../internal/http/
|
|
16
|
+
import * as internal from "../internal/http/multipart.js"
|
|
17
17
|
import type * as Path from "../Path.js"
|
|
18
18
|
|
|
19
19
|
/**
|
|
@@ -68,7 +68,7 @@ export interface File extends Part.Proto {
|
|
|
68
68
|
readonly key: string
|
|
69
69
|
readonly name: string
|
|
70
70
|
readonly contentType: string
|
|
71
|
-
readonly content: Stream.Stream<never,
|
|
71
|
+
readonly content: Stream.Stream<never, MultipartError, Uint8Array>
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
/**
|
|
@@ -87,7 +87,7 @@ export interface PersistedFile extends Part.Proto {
|
|
|
87
87
|
* @since 1.0.0
|
|
88
88
|
* @category models
|
|
89
89
|
*/
|
|
90
|
-
export interface
|
|
90
|
+
export interface Persisted {
|
|
91
91
|
readonly [key: string]: ReadonlyArray<PersistedFile> | string
|
|
92
92
|
}
|
|
93
93
|
|
|
@@ -107,9 +107,9 @@ export type ErrorTypeId = typeof ErrorTypeId
|
|
|
107
107
|
* @since 1.0.0
|
|
108
108
|
* @category errors
|
|
109
109
|
*/
|
|
110
|
-
export interface
|
|
110
|
+
export interface MultipartError extends Data.Case {
|
|
111
111
|
readonly [ErrorTypeId]: ErrorTypeId
|
|
112
|
-
readonly _tag: "
|
|
112
|
+
readonly _tag: "MultipartError"
|
|
113
113
|
readonly reason: "FileTooLarge" | "FieldTooLarge" | "BodyTooLarge" | "TooManyParts" | "InternalError" | "Parse"
|
|
114
114
|
readonly error: unknown
|
|
115
115
|
}
|
|
@@ -118,10 +118,10 @@ export interface FormDataError extends Data.Case {
|
|
|
118
118
|
* @since 1.0.0
|
|
119
119
|
* @category errors
|
|
120
120
|
*/
|
|
121
|
-
export const
|
|
122
|
-
reason:
|
|
121
|
+
export const MultipartError: (
|
|
122
|
+
reason: MultipartError["reason"],
|
|
123
123
|
error: unknown
|
|
124
|
-
) =>
|
|
124
|
+
) => MultipartError = internal.MultipartError
|
|
125
125
|
|
|
126
126
|
/**
|
|
127
127
|
* @since 1.0.0
|
|
@@ -203,17 +203,17 @@ export const filesSchema: Schema.Schema<ReadonlyArray<PersistedFile>, ReadonlyAr
|
|
|
203
203
|
export const schemaJson: <I, A>(
|
|
204
204
|
schema: Schema.Schema<I, A>
|
|
205
205
|
) => {
|
|
206
|
-
(field: string): (
|
|
207
|
-
(
|
|
206
|
+
(field: string): (persisted: Persisted) => Effect.Effect<never, ParseResult.ParseError, A>
|
|
207
|
+
(persisted: Persisted, field: string): Effect.Effect<never, ParseResult.ParseError, A>
|
|
208
208
|
} = internal.schemaJson
|
|
209
209
|
|
|
210
210
|
/**
|
|
211
211
|
* @since 1.0.0
|
|
212
212
|
* @category schema
|
|
213
213
|
*/
|
|
214
|
-
export const schemaPersisted: <I extends
|
|
214
|
+
export const schemaPersisted: <I extends Persisted, A>(
|
|
215
215
|
schema: Schema.Schema<I, A>
|
|
216
|
-
) => (
|
|
216
|
+
) => (persisted: Persisted) => Effect.Effect<never, ParseResult.ParseError, A> = internal.schemaPersisted
|
|
217
217
|
|
|
218
218
|
/**
|
|
219
219
|
* @since 1.0.0
|
|
@@ -222,7 +222,7 @@ export const schemaPersisted: <I extends PersistedFormData, A>(
|
|
|
222
222
|
export const makeChannel: <IE>(
|
|
223
223
|
headers: Record<string, string>,
|
|
224
224
|
bufferSize?: number
|
|
225
|
-
) => Channel.Channel<never, IE, Chunk.Chunk<Uint8Array>, unknown,
|
|
225
|
+
) => Channel.Channel<never, IE, Chunk.Chunk<Uint8Array>, unknown, MultipartError | IE, Chunk.Chunk<Part>, unknown> =
|
|
226
226
|
internal.makeChannel
|
|
227
227
|
|
|
228
228
|
/**
|
|
@@ -236,8 +236,7 @@ export const makeConfig: (headers: Record<string, string>) => Effect.Effect<neve
|
|
|
236
236
|
* @since 1.0.0
|
|
237
237
|
* @category constructors
|
|
238
238
|
*/
|
|
239
|
-
export const
|
|
240
|
-
stream: Stream.Stream<never,
|
|
241
|
-
writeFile?: (path: string, file: File) => Effect.Effect<FileSystem.FileSystem,
|
|
242
|
-
) => Effect.Effect<FileSystem.FileSystem | Path.Path | Scope.Scope,
|
|
243
|
-
internal.formData
|
|
239
|
+
export const toPersisted: (
|
|
240
|
+
stream: Stream.Stream<never, MultipartError, Part>,
|
|
241
|
+
writeFile?: (path: string, file: File) => Effect.Effect<FileSystem.FileSystem, MultipartError, void>
|
|
242
|
+
) => Effect.Effect<FileSystem.FileSystem | Path.Path | Scope.Scope, MultipartError, Persisted> = internal.toPersisted
|
package/src/Http/Router.ts
CHANGED
|
@@ -111,6 +111,7 @@ export type RouteContextTypeId = typeof RouteContextTypeId
|
|
|
111
111
|
export interface RouteContext {
|
|
112
112
|
readonly [RouteContextTypeId]: RouteContextTypeId
|
|
113
113
|
readonly params: Readonly<Record<string, string | undefined>>
|
|
114
|
+
readonly route: Route<unknown, unknown>
|
|
114
115
|
readonly searchParams: Readonly<Record<string, string>>
|
|
115
116
|
}
|
|
116
117
|
|
|
@@ -10,10 +10,10 @@ import type * as Stream from "effect/Stream"
|
|
|
10
10
|
import type * as FileSystem from "../FileSystem.js"
|
|
11
11
|
import * as internal from "../internal/http/serverRequest.js"
|
|
12
12
|
import type * as Path from "../Path.js"
|
|
13
|
-
import type * as FormData from "./FormData.js"
|
|
14
13
|
import type * as Headers from "./Headers.js"
|
|
15
14
|
import type * as IncomingMessage from "./IncomingMessage.js"
|
|
16
15
|
import type { Method } from "./Method.js"
|
|
16
|
+
import type * as Multipart from "./Multipart.js"
|
|
17
17
|
import type * as Error from "./ServerError.js"
|
|
18
18
|
|
|
19
19
|
export {
|
|
@@ -47,12 +47,12 @@ export interface ServerRequest extends IncomingMessage.IncomingMessage<Error.Req
|
|
|
47
47
|
readonly originalUrl: string
|
|
48
48
|
readonly method: Method
|
|
49
49
|
|
|
50
|
-
readonly
|
|
50
|
+
readonly multipart: Effect.Effect<
|
|
51
51
|
Scope.Scope | FileSystem.FileSystem | Path.Path,
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
Multipart.MultipartError,
|
|
53
|
+
Multipart.Persisted
|
|
54
54
|
>
|
|
55
|
-
readonly
|
|
55
|
+
readonly multipartStream: Stream.Stream<never, Multipart.MultipartError, Multipart.Part>
|
|
56
56
|
|
|
57
57
|
readonly modify: (
|
|
58
58
|
options: {
|
|
@@ -73,11 +73,11 @@ export const ServerRequest: Context.Tag<ServerRequest, ServerRequest> = internal
|
|
|
73
73
|
* @since 1.0.0
|
|
74
74
|
* @category accessors
|
|
75
75
|
*/
|
|
76
|
-
export const
|
|
76
|
+
export const persistedMultipart: Effect.Effect<
|
|
77
77
|
Scope.Scope | FileSystem.FileSystem | Path.Path | ServerRequest,
|
|
78
|
-
|
|
78
|
+
Multipart.MultipartError,
|
|
79
79
|
unknown
|
|
80
|
-
> = internal.
|
|
80
|
+
> = internal.multipartPersisted
|
|
81
81
|
|
|
82
82
|
/**
|
|
83
83
|
* @since 1.0.0
|
|
@@ -95,6 +95,18 @@ export const schemaBodyJson: <I, A>(
|
|
|
95
95
|
schema: Schema.Schema<I, A>
|
|
96
96
|
) => Effect.Effect<ServerRequest, Error.RequestError | ParseResult.ParseError, A> = internal.schemaBodyJson
|
|
97
97
|
|
|
98
|
+
/**
|
|
99
|
+
* @since 1.0.0
|
|
100
|
+
* @category schema
|
|
101
|
+
*/
|
|
102
|
+
export const schemaBodyForm: <I extends Multipart.Persisted, A>(
|
|
103
|
+
schema: Schema.Schema<I, A>
|
|
104
|
+
) => Effect.Effect<
|
|
105
|
+
ServerRequest | Scope.Scope | FileSystem.FileSystem | Path.Path,
|
|
106
|
+
Multipart.MultipartError | Error.RequestError | ParseResult.ParseError,
|
|
107
|
+
A
|
|
108
|
+
> = internal.schemaBodyForm
|
|
109
|
+
|
|
98
110
|
/**
|
|
99
111
|
* @since 1.0.0
|
|
100
112
|
* @category schema
|
|
@@ -107,27 +119,27 @@ export const schemaBodyUrlParams: <I extends Readonly<Record<string, string>>, A
|
|
|
107
119
|
* @since 1.0.0
|
|
108
120
|
* @category schema
|
|
109
121
|
*/
|
|
110
|
-
export const
|
|
122
|
+
export const schemaBodyMultipart: <I extends Multipart.Persisted, A>(
|
|
111
123
|
schema: Schema.Schema<I, A>
|
|
112
124
|
) => Effect.Effect<
|
|
113
125
|
ServerRequest | Scope.Scope | FileSystem.FileSystem | Path.Path,
|
|
114
|
-
|
|
126
|
+
Multipart.MultipartError | ParseResult.ParseError,
|
|
115
127
|
A
|
|
116
|
-
> = internal.
|
|
128
|
+
> = internal.schemaBodyMultipart
|
|
117
129
|
|
|
118
130
|
/**
|
|
119
131
|
* @since 1.0.0
|
|
120
132
|
* @category schema
|
|
121
133
|
*/
|
|
122
|
-
export const
|
|
134
|
+
export const schemaBodyFormJson: <I, A>(
|
|
123
135
|
schema: Schema.Schema<I, A>
|
|
124
136
|
) => (
|
|
125
137
|
field: string
|
|
126
138
|
) => Effect.Effect<
|
|
127
139
|
ServerRequest | Scope.Scope | FileSystem.FileSystem | Path.Path,
|
|
128
|
-
Error.RequestError |
|
|
140
|
+
Error.RequestError | ParseResult.ParseError,
|
|
129
141
|
A
|
|
130
|
-
> = internal.
|
|
142
|
+
> = internal.schemaBodyFormJson
|
|
131
143
|
|
|
132
144
|
/**
|
|
133
145
|
* @since 1.0.0
|
|
@@ -41,11 +41,11 @@ export interface ServerResponse extends Effect.Effect<never, never, ServerRespon
|
|
|
41
41
|
* @category models
|
|
42
42
|
*/
|
|
43
43
|
export interface Options {
|
|
44
|
-
readonly status?: number
|
|
45
|
-
readonly statusText?: string
|
|
46
|
-
readonly headers?: Headers.Headers
|
|
47
|
-
readonly contentType?: string
|
|
48
|
-
readonly contentLength?: number
|
|
44
|
+
readonly status?: number | undefined
|
|
45
|
+
readonly statusText?: string | undefined
|
|
46
|
+
readonly headers?: Headers.Headers | undefined
|
|
47
|
+
readonly contentType?: string | undefined
|
|
48
|
+
readonly contentLength?: number | undefined
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
/**
|
package/src/Http/UrlParams.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @since 1.0.0
|
|
3
3
|
*/
|
|
4
|
+
import type * as ParseResult from "@effect/schema/ParseResult"
|
|
5
|
+
import * as Schema from "@effect/schema/Schema"
|
|
4
6
|
import * as Effect from "effect/Effect"
|
|
5
7
|
import { dual } from "effect/Function"
|
|
8
|
+
import * as Option from "effect/Option"
|
|
6
9
|
import * as ReadonlyArray from "effect/ReadonlyArray"
|
|
7
10
|
|
|
8
11
|
/**
|
|
@@ -34,6 +37,62 @@ export const fromInput = (input: Input): UrlParams => {
|
|
|
34
37
|
*/
|
|
35
38
|
export const empty: UrlParams = []
|
|
36
39
|
|
|
40
|
+
/**
|
|
41
|
+
* @since 1.0.0
|
|
42
|
+
* @category combinators
|
|
43
|
+
*/
|
|
44
|
+
export const getAll: {
|
|
45
|
+
(key: string): (self: UrlParams) => ReadonlyArray<string>
|
|
46
|
+
(self: UrlParams, key: string): ReadonlyArray<string>
|
|
47
|
+
} = dual<
|
|
48
|
+
(key: string) => (self: UrlParams) => ReadonlyArray<string>,
|
|
49
|
+
(self: UrlParams, key: string) => ReadonlyArray<string>
|
|
50
|
+
>(2, (self, key) =>
|
|
51
|
+
ReadonlyArray.reduce(self, [] as Array<string>, (acc, [k, value]) => {
|
|
52
|
+
if (k === key) {
|
|
53
|
+
acc.push(value)
|
|
54
|
+
}
|
|
55
|
+
return acc
|
|
56
|
+
}))
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @since 1.0.0
|
|
60
|
+
* @category combinators
|
|
61
|
+
*/
|
|
62
|
+
export const getFirst: {
|
|
63
|
+
(key: string): (self: UrlParams) => Option.Option<string>
|
|
64
|
+
(self: UrlParams, key: string): Option.Option<string>
|
|
65
|
+
} = dual<
|
|
66
|
+
(key: string) => (self: UrlParams) => Option.Option<string>,
|
|
67
|
+
(self: UrlParams, key: string) => Option.Option<string>
|
|
68
|
+
>(2, (self, key) =>
|
|
69
|
+
Option.map(
|
|
70
|
+
ReadonlyArray.findFirst(
|
|
71
|
+
self,
|
|
72
|
+
([k]) => k === key
|
|
73
|
+
),
|
|
74
|
+
([, value]) => value
|
|
75
|
+
))
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* @since 1.0.0
|
|
79
|
+
* @category combinators
|
|
80
|
+
*/
|
|
81
|
+
export const getLast: {
|
|
82
|
+
(key: string): (self: UrlParams) => Option.Option<string>
|
|
83
|
+
(self: UrlParams, key: string): Option.Option<string>
|
|
84
|
+
} = dual<
|
|
85
|
+
(key: string) => (self: UrlParams) => Option.Option<string>,
|
|
86
|
+
(self: UrlParams, key: string) => Option.Option<string>
|
|
87
|
+
>(2, (self, key) =>
|
|
88
|
+
Option.map(
|
|
89
|
+
ReadonlyArray.findLast(
|
|
90
|
+
self,
|
|
91
|
+
([k]) => k === key
|
|
92
|
+
),
|
|
93
|
+
([, value]) => value
|
|
94
|
+
))
|
|
95
|
+
|
|
37
96
|
/**
|
|
38
97
|
* @since 1.0.0
|
|
39
98
|
* @category combinators
|
|
@@ -143,3 +202,23 @@ const baseUrl = (): string | undefined => {
|
|
|
143
202
|
}
|
|
144
203
|
return undefined
|
|
145
204
|
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* @since 1.0.0
|
|
208
|
+
* @category schema
|
|
209
|
+
*/
|
|
210
|
+
export const schemaJson = <I, A>(schema: Schema.Schema<I, A>): {
|
|
211
|
+
(
|
|
212
|
+
field: string
|
|
213
|
+
): (self: UrlParams) => Effect.Effect<never, ParseResult.ParseError, A>
|
|
214
|
+
(
|
|
215
|
+
self: UrlParams,
|
|
216
|
+
field: string
|
|
217
|
+
): Effect.Effect<never, ParseResult.ParseError, A>
|
|
218
|
+
} => {
|
|
219
|
+
const parse = Schema.parse(Schema.parseJson(schema))
|
|
220
|
+
return dual<
|
|
221
|
+
(field: string) => (self: UrlParams) => Effect.Effect<never, ParseResult.ParseError, A>,
|
|
222
|
+
(self: UrlParams, field: string) => Effect.Effect<never, ParseResult.ParseError, A>
|
|
223
|
+
>(2, (self, field) => parse(Option.getOrElse(getLast(self, field), () => "")))
|
|
224
|
+
}
|
package/src/HttpServer.ts
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import * as app from "./Http/App.js"
|
|
5
5
|
import * as body from "./Http/Body.js"
|
|
6
|
-
import * as formData from "./Http/FormData.js"
|
|
7
6
|
import * as headers from "./Http/Headers.js"
|
|
8
7
|
import * as middleware from "./Http/Middleware.js"
|
|
8
|
+
import * as multipart from "./Http/Multipart.js"
|
|
9
9
|
import * as router from "./Http/Router.js"
|
|
10
10
|
import * as error from "./Http/ServerError.js"
|
|
11
11
|
import * as request from "./Http/ServerRequest.js"
|
|
@@ -34,13 +34,6 @@ export {
|
|
|
34
34
|
* - Module: `@effect/platform/Http/ServerError`
|
|
35
35
|
*/
|
|
36
36
|
error,
|
|
37
|
-
/**
|
|
38
|
-
* @since 1.0.0
|
|
39
|
-
*
|
|
40
|
-
* - Docs: [Http/FormData](https://effect-ts.github.io/platform/platform/Http/FormData.html)
|
|
41
|
-
* - Module: `@effect/platform/Http/FormData`
|
|
42
|
-
*/
|
|
43
|
-
formData,
|
|
44
37
|
/**
|
|
45
38
|
* @since 1.0.0
|
|
46
39
|
*
|
|
@@ -55,6 +48,13 @@ export {
|
|
|
55
48
|
* - Module: `@effect/platform/Http/Middleware`
|
|
56
49
|
*/
|
|
57
50
|
middleware,
|
|
51
|
+
/**
|
|
52
|
+
* @since 1.0.0
|
|
53
|
+
*
|
|
54
|
+
* - Docs: [Http/Multipart](https://effect-ts.github.io/platform/platform/Http/Multipart.html)
|
|
55
|
+
* - Module: `@effect/platform/Http/Multipart`
|
|
56
|
+
*/
|
|
57
|
+
multipart,
|
|
58
58
|
/**
|
|
59
59
|
* @since 1.0.0
|
|
60
60
|
*
|
|
@@ -6,6 +6,7 @@ import * as Stream_ from "effect/Stream"
|
|
|
6
6
|
import type * as PlatformError from "../../Error.js"
|
|
7
7
|
import * as FileSystem from "../../FileSystem.js"
|
|
8
8
|
import type * as Body from "../../Http/Body.js"
|
|
9
|
+
import * as UrlParams from "../../Http/UrlParams.js"
|
|
9
10
|
|
|
10
11
|
/** @internal */
|
|
11
12
|
export const TypeId: Body.TypeId = Symbol.for(
|
|
@@ -68,13 +69,14 @@ class Uint8ArrayImpl implements Body.Uint8Array {
|
|
|
68
69
|
export const uint8Array = (body: Uint8Array, contentType?: string): Body.Uint8Array =>
|
|
69
70
|
new Uint8ArrayImpl(body, contentType ?? "application/octet-stream")
|
|
70
71
|
|
|
72
|
+
const encoder = new TextEncoder()
|
|
73
|
+
|
|
71
74
|
/** @internal */
|
|
72
75
|
export const text = (body: string, contentType?: string): Body.Uint8Array =>
|
|
73
|
-
uint8Array(
|
|
76
|
+
uint8Array(encoder.encode(body), contentType ?? "text/plain")
|
|
74
77
|
|
|
75
78
|
/** @internal */
|
|
76
|
-
export const unsafeJson = (body: unknown): Body.Uint8Array =>
|
|
77
|
-
uint8Array(new TextEncoder().encode(JSON.stringify(body)), "application/json")
|
|
79
|
+
export const unsafeJson = (body: unknown): Body.Uint8Array => text(JSON.stringify(body), "application/json")
|
|
78
80
|
|
|
79
81
|
/** @internal */
|
|
80
82
|
export const json = (body: unknown): Effect.Effect<never, Body.BodyError, Body.Uint8Array> =>
|
|
@@ -83,6 +85,10 @@ export const json = (body: unknown): Effect.Effect<never, Body.BodyError, Body.U
|
|
|
83
85
|
catch: (error) => BodyError({ _tag: "JsonError", error })
|
|
84
86
|
})
|
|
85
87
|
|
|
88
|
+
/** @internal */
|
|
89
|
+
export const urlParams = (urlParams: UrlParams.UrlParams): Body.Uint8Array =>
|
|
90
|
+
text(UrlParams.toString(urlParams), "application/x-www-form-urlencoded")
|
|
91
|
+
|
|
86
92
|
/** @internal */
|
|
87
93
|
export const jsonSchema = <I, A>(schema: Schema.Schema<I, A>) => {
|
|
88
94
|
const encode = Schema.encode(schema)
|
|
@@ -4,7 +4,6 @@ import * as Context from "effect/Context"
|
|
|
4
4
|
import * as Effect from "effect/Effect"
|
|
5
5
|
import { dual } from "effect/Function"
|
|
6
6
|
import * as Layer from "effect/Layer"
|
|
7
|
-
import * as Option from "effect/Option"
|
|
8
7
|
import { pipeArguments } from "effect/Pipeable"
|
|
9
8
|
import type * as Predicate from "effect/Predicate"
|
|
10
9
|
import type * as Schedule from "effect/Schedule"
|
|
@@ -53,20 +52,17 @@ export const make = <R, E, A, R2, E2>(
|
|
|
53
52
|
}
|
|
54
53
|
|
|
55
54
|
const addB3Headers = (req: ClientRequest.ClientRequest) =>
|
|
56
|
-
Effect.
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
"
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
)
|
|
68
|
-
})
|
|
69
|
-
)
|
|
55
|
+
Effect.match(Effect.currentSpan, {
|
|
56
|
+
onFailure: () => req,
|
|
57
|
+
onSuccess: (span) =>
|
|
58
|
+
internalRequest.setHeader(
|
|
59
|
+
req,
|
|
60
|
+
"b3",
|
|
61
|
+
`${span.traceId}-${span.spanId}-${span.sampled ? "1" : "0"}${
|
|
62
|
+
span.parent._tag === "Some" ? `-${span.parent.value.spanId}` : ""
|
|
63
|
+
}`
|
|
64
|
+
)
|
|
65
|
+
})
|
|
70
66
|
|
|
71
67
|
/** @internal */
|
|
72
68
|
export const makeDefault = (
|
|
@@ -85,7 +81,7 @@ export const Fetch = Context.Tag<Client.Fetch, typeof globalThis.fetch>(
|
|
|
85
81
|
)
|
|
86
82
|
|
|
87
83
|
/** @internal */
|
|
88
|
-
export const fetch = (options
|
|
84
|
+
export const fetch = (options?: RequestInit): Client.Client.Default =>
|
|
89
85
|
makeDefault((request) =>
|
|
90
86
|
Effect.flatMap(
|
|
91
87
|
UrlParams.makeUrl(request.url, request.urlParams, (_) =>
|
|
@@ -142,7 +138,7 @@ const convertBody = (body: Body.Body): BodyInit | undefined => {
|
|
|
142
138
|
}
|
|
143
139
|
|
|
144
140
|
/** @internal */
|
|
145
|
-
export const fetchOk = (options
|
|
141
|
+
export const fetchOk = (options?: RequestInit): Client.Client.Default => filterStatusOk(fetch(options))
|
|
146
142
|
|
|
147
143
|
/** @internal */
|
|
148
144
|
export const layer = Layer.succeed(tag, fetch())
|