@effect/platform 0.64.0 → 0.65.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/FetchHttpClient/package.json +6 -0
- package/README.md +175 -611
- package/dist/cjs/Command.js +3 -3
- package/dist/cjs/Command.js.map +1 -1
- package/dist/cjs/FetchHttpClient.js +32 -0
- package/dist/cjs/FetchHttpClient.js.map +1 -0
- package/dist/cjs/HttpApiClient.js +1 -1
- package/dist/cjs/HttpApiClient.js.map +1 -1
- package/dist/cjs/HttpClient.js +5 -36
- package/dist/cjs/HttpClient.js.map +1 -1
- package/dist/cjs/HttpClientRequest.js +11 -11
- package/dist/cjs/HttpClientRequest.js.map +1 -1
- package/dist/cjs/HttpClientResponse.js +2 -61
- package/dist/cjs/HttpClientResponse.js.map +1 -1
- package/dist/cjs/HttpIncomingMessage.js +2 -29
- package/dist/cjs/HttpIncomingMessage.js.map +1 -1
- package/dist/cjs/Runtime.js +1 -1
- package/dist/cjs/Runtime.js.map +1 -1
- package/dist/cjs/Socket.js +42 -53
- package/dist/cjs/Socket.js.map +1 -1
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/internal/command.js +2 -2
- package/dist/cjs/internal/command.js.map +1 -1
- package/dist/cjs/internal/fetchHttpClient.js +52 -0
- package/dist/cjs/internal/fetchHttpClient.js.map +1 -0
- package/dist/cjs/internal/httpClient.js +82 -71
- package/dist/cjs/internal/httpClient.js.map +1 -1
- package/dist/cjs/internal/httpClientRequest.js +13 -13
- package/dist/cjs/internal/httpClientRequest.js.map +1 -1
- package/dist/cjs/internal/httpClientResponse.js +1 -33
- package/dist/cjs/internal/httpClientResponse.js.map +1 -1
- package/dist/cjs/internal/worker.js +21 -29
- package/dist/cjs/internal/worker.js.map +1 -1
- package/dist/dts/Command.d.ts +4 -4
- package/dist/dts/Command.d.ts.map +1 -1
- package/dist/dts/FetchHttpClient.d.ts +27 -0
- package/dist/dts/FetchHttpClient.d.ts.map +1 -0
- package/dist/dts/HttpApiClient.d.ts +2 -2
- package/dist/dts/HttpClient.d.ts +53 -61
- package/dist/dts/HttpClient.d.ts.map +1 -1
- package/dist/dts/HttpClientRequest.d.ts +11 -11
- package/dist/dts/HttpClientRequest.d.ts.map +1 -1
- package/dist/dts/HttpClientResponse.d.ts +4 -90
- package/dist/dts/HttpClientResponse.d.ts.map +1 -1
- package/dist/dts/HttpIncomingMessage.d.ts +0 -16
- package/dist/dts/HttpIncomingMessage.d.ts.map +1 -1
- package/dist/dts/HttpServer.d.ts +1 -1
- package/dist/dts/Socket.d.ts +3 -3
- package/dist/dts/Socket.d.ts.map +1 -1
- package/dist/dts/index.d.ts +4 -0
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/dts/internal/fetchHttpClient.d.ts +2 -0
- package/dist/dts/internal/fetchHttpClient.d.ts.map +1 -0
- package/dist/esm/Command.js +3 -3
- package/dist/esm/Command.js.map +1 -1
- package/dist/esm/FetchHttpClient.js +21 -0
- package/dist/esm/FetchHttpClient.js.map +1 -0
- package/dist/esm/HttpApiClient.js +1 -1
- package/dist/esm/HttpApiClient.js.map +1 -1
- package/dist/esm/HttpClient.js +4 -35
- package/dist/esm/HttpClient.js.map +1 -1
- package/dist/esm/HttpClientRequest.js +10 -10
- package/dist/esm/HttpClientRequest.js.map +1 -1
- package/dist/esm/HttpClientResponse.js +1 -63
- package/dist/esm/HttpClientResponse.js.map +1 -1
- package/dist/esm/HttpIncomingMessage.js +0 -24
- package/dist/esm/HttpIncomingMessage.js.map +1 -1
- package/dist/esm/Runtime.js +1 -1
- package/dist/esm/Runtime.js.map +1 -1
- package/dist/esm/Socket.js +42 -53
- package/dist/esm/Socket.js.map +1 -1
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/internal/command.js +2 -2
- package/dist/esm/internal/command.js.map +1 -1
- package/dist/esm/internal/fetchHttpClient.js +44 -0
- package/dist/esm/internal/fetchHttpClient.js.map +1 -0
- package/dist/esm/internal/httpClient.js +79 -69
- package/dist/esm/internal/httpClient.js.map +1 -1
- package/dist/esm/internal/httpClientRequest.js +11 -11
- package/dist/esm/internal/httpClientRequest.js.map +1 -1
- package/dist/esm/internal/httpClientResponse.js +0 -24
- package/dist/esm/internal/httpClientResponse.js.map +1 -1
- package/dist/esm/internal/worker.js +21 -29
- package/dist/esm/internal/worker.js.map +1 -1
- package/package.json +11 -3
- package/src/Command.ts +7 -8
- package/src/FetchHttpClient.ts +25 -0
- package/src/HttpApiClient.ts +5 -5
- package/src/HttpClient.ts +79 -85
- package/src/HttpClientRequest.ts +21 -21
- package/src/HttpClientResponse.ts +4 -162
- package/src/HttpIncomingMessage.ts +0 -43
- package/src/HttpServer.ts +1 -1
- package/src/Runtime.ts +1 -1
- package/src/Socket.ts +42 -58
- package/src/index.ts +5 -0
- package/src/internal/command.ts +4 -3
- package/src/internal/fetchHttpClient.ts +53 -0
- package/src/internal/httpClient.ts +149 -125
- package/src/internal/httpClientRequest.ts +12 -12
- package/src/internal/httpClientResponse.ts +6 -96
- package/src/internal/worker.ts +40 -55
package/src/HttpClientRequest.ts
CHANGED
|
@@ -36,7 +36,7 @@ export type TypeId = typeof TypeId
|
|
|
36
36
|
* @category models
|
|
37
37
|
*/
|
|
38
38
|
export interface HttpClientRequest
|
|
39
|
-
extends Effect.Effect<HttpClientResponse, HttpClientError, HttpClient.
|
|
39
|
+
extends Effect.Effect<HttpClientResponse, HttpClientError, HttpClient.Service | Scope>, Inspectable
|
|
40
40
|
{
|
|
41
41
|
readonly [TypeId]: TypeId
|
|
42
42
|
readonly method: HttpMethod
|
|
@@ -301,73 +301,73 @@ export const setBody: {
|
|
|
301
301
|
* @since 1.0.0
|
|
302
302
|
* @category combinators
|
|
303
303
|
*/
|
|
304
|
-
export const
|
|
304
|
+
export const bodyUint8Array: {
|
|
305
305
|
(body: Uint8Array, contentType?: string): (self: HttpClientRequest) => HttpClientRequest
|
|
306
306
|
(self: HttpClientRequest, body: Uint8Array, contentType?: string): HttpClientRequest
|
|
307
|
-
} = internal.
|
|
307
|
+
} = internal.bodyUint8Array
|
|
308
308
|
|
|
309
309
|
/**
|
|
310
310
|
* @since 1.0.0
|
|
311
311
|
* @category combinators
|
|
312
312
|
*/
|
|
313
|
-
export const
|
|
313
|
+
export const bodyText: {
|
|
314
314
|
(body: string, contentType?: string): (self: HttpClientRequest) => HttpClientRequest
|
|
315
315
|
(self: HttpClientRequest, body: string, contentType?: string): HttpClientRequest
|
|
316
|
-
} = internal.
|
|
316
|
+
} = internal.bodyText
|
|
317
317
|
|
|
318
318
|
/**
|
|
319
319
|
* @since 1.0.0
|
|
320
320
|
* @category combinators
|
|
321
321
|
*/
|
|
322
|
-
export const
|
|
322
|
+
export const bodyJson: {
|
|
323
323
|
(body: unknown): (self: HttpClientRequest) => Effect.Effect<HttpClientRequest, Body.HttpBodyError>
|
|
324
324
|
(self: HttpClientRequest, body: unknown): Effect.Effect<HttpClientRequest, Body.HttpBodyError>
|
|
325
|
-
} = internal.
|
|
325
|
+
} = internal.bodyJson
|
|
326
326
|
|
|
327
327
|
/**
|
|
328
328
|
* @since 1.0.0
|
|
329
329
|
* @category combinators
|
|
330
330
|
*/
|
|
331
|
-
export const
|
|
331
|
+
export const bodyUnsafeJson: {
|
|
332
332
|
(body: unknown): (self: HttpClientRequest) => HttpClientRequest
|
|
333
333
|
(self: HttpClientRequest, body: unknown): HttpClientRequest
|
|
334
|
-
} = internal.
|
|
334
|
+
} = internal.bodyUnsafeJson
|
|
335
335
|
|
|
336
336
|
/**
|
|
337
337
|
* @since 1.0.0
|
|
338
338
|
* @category combinators
|
|
339
339
|
*/
|
|
340
|
-
export const
|
|
340
|
+
export const schemaBodyJson: <A, I, R>(
|
|
341
341
|
schema: Schema.Schema<A, I, R>,
|
|
342
342
|
options?: ParseOptions | undefined
|
|
343
343
|
) => {
|
|
344
344
|
(body: A): (self: HttpClientRequest) => Effect.Effect<HttpClientRequest, Body.HttpBodyError, R>
|
|
345
345
|
(self: HttpClientRequest, body: A): Effect.Effect<HttpClientRequest, Body.HttpBodyError, R>
|
|
346
|
-
} = internal.
|
|
346
|
+
} = internal.schemaBodyJson
|
|
347
347
|
|
|
348
348
|
/**
|
|
349
349
|
* @since 1.0.0
|
|
350
350
|
* @category combinators
|
|
351
351
|
*/
|
|
352
|
-
export const
|
|
352
|
+
export const bodyUrlParams: {
|
|
353
353
|
(input: UrlParams.Input): (self: HttpClientRequest) => HttpClientRequest
|
|
354
354
|
(self: HttpClientRequest, input: UrlParams.Input): HttpClientRequest
|
|
355
|
-
} = internal.
|
|
355
|
+
} = internal.bodyUrlParams
|
|
356
356
|
|
|
357
357
|
/**
|
|
358
358
|
* @since 1.0.0
|
|
359
359
|
* @category combinators
|
|
360
360
|
*/
|
|
361
|
-
export const
|
|
361
|
+
export const bodyFormData: {
|
|
362
362
|
(body: FormData): (self: HttpClientRequest) => HttpClientRequest
|
|
363
363
|
(self: HttpClientRequest, body: FormData): HttpClientRequest
|
|
364
|
-
} = internal.
|
|
364
|
+
} = internal.bodyFormData
|
|
365
365
|
|
|
366
366
|
/**
|
|
367
367
|
* @since 1.0.0
|
|
368
368
|
* @category combinators
|
|
369
369
|
*/
|
|
370
|
-
export const
|
|
370
|
+
export const bodyStream: {
|
|
371
371
|
(
|
|
372
372
|
body: Stream.Stream<Uint8Array, unknown>,
|
|
373
373
|
options?: { readonly contentType?: string | undefined; readonly contentLength?: number | undefined } | undefined
|
|
@@ -377,13 +377,13 @@ export const streamBody: {
|
|
|
377
377
|
body: Stream.Stream<Uint8Array, unknown>,
|
|
378
378
|
options?: { readonly contentType?: string | undefined; readonly contentLength?: number | undefined } | undefined
|
|
379
379
|
): HttpClientRequest
|
|
380
|
-
} = internal.
|
|
380
|
+
} = internal.bodyStream
|
|
381
381
|
|
|
382
382
|
/**
|
|
383
383
|
* @since 1.0.0
|
|
384
384
|
* @category combinators
|
|
385
385
|
*/
|
|
386
|
-
export const
|
|
386
|
+
export const bodyFile: {
|
|
387
387
|
(
|
|
388
388
|
path: string,
|
|
389
389
|
options?: FileSystem.StreamOptions & { readonly contentType?: string }
|
|
@@ -393,13 +393,13 @@ export const fileBody: {
|
|
|
393
393
|
path: string,
|
|
394
394
|
options?: FileSystem.StreamOptions & { readonly contentType?: string }
|
|
395
395
|
): Effect.Effect<HttpClientRequest, PlatformError.PlatformError, FileSystem.FileSystem>
|
|
396
|
-
} = internal.
|
|
396
|
+
} = internal.bodyFile
|
|
397
397
|
|
|
398
398
|
/**
|
|
399
399
|
* @since 1.0.0
|
|
400
400
|
* @category combinators
|
|
401
401
|
*/
|
|
402
|
-
export const
|
|
402
|
+
export const bodyFileWeb: {
|
|
403
403
|
(file: Body.HttpBody.FileLike): (self: HttpClientRequest) => HttpClientRequest
|
|
404
404
|
(self: HttpClientRequest, file: Body.HttpBody.FileLike): HttpClientRequest
|
|
405
|
-
} = internal.
|
|
405
|
+
} = internal.bodyFileWeb
|
|
@@ -7,12 +7,12 @@ import type * as Schema from "@effect/schema/Schema"
|
|
|
7
7
|
import type * as Effect from "effect/Effect"
|
|
8
8
|
import type * as Scope from "effect/Scope"
|
|
9
9
|
import type * as Stream from "effect/Stream"
|
|
10
|
+
import type { Unify } from "effect/Unify"
|
|
10
11
|
import type * as Cookies from "./Cookies.js"
|
|
11
12
|
import type * as Error from "./HttpClientError.js"
|
|
12
13
|
import type * as ClientRequest from "./HttpClientRequest.js"
|
|
13
14
|
import type * as IncomingMessage from "./HttpIncomingMessage.js"
|
|
14
15
|
import * as internal from "./internal/httpClientResponse.js"
|
|
15
|
-
import type * as UrlParams from "./UrlParams.js"
|
|
16
16
|
|
|
17
17
|
export {
|
|
18
18
|
/**
|
|
@@ -20,11 +20,6 @@ export {
|
|
|
20
20
|
* @category schema
|
|
21
21
|
*/
|
|
22
22
|
schemaBodyJson,
|
|
23
|
-
/**
|
|
24
|
-
* @since 1.0.0
|
|
25
|
-
* @category schema
|
|
26
|
-
*/
|
|
27
|
-
schemaBodyJsonScoped,
|
|
28
23
|
/**
|
|
29
24
|
* @since 1.0.0
|
|
30
25
|
* @category schema
|
|
@@ -34,17 +29,7 @@ export {
|
|
|
34
29
|
* @since 1.0.0
|
|
35
30
|
* @category schema
|
|
36
31
|
*/
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* @since 1.0.0
|
|
40
|
-
* @category schema
|
|
41
|
-
*/
|
|
42
|
-
schemaHeaders,
|
|
43
|
-
/**
|
|
44
|
-
* @since 1.0.0
|
|
45
|
-
* @category schema
|
|
46
|
-
*/
|
|
47
|
-
schemaHeadersScoped
|
|
32
|
+
schemaHeaders
|
|
48
33
|
} from "./HttpIncomingMessage.js"
|
|
49
34
|
|
|
50
35
|
/**
|
|
@@ -111,41 +96,6 @@ export const schemaNoBody: <
|
|
|
111
96
|
options?: ParseOptions | undefined
|
|
112
97
|
) => (self: HttpClientResponse) => Effect.Effect<A, ParseResult.ParseError, R> = internal.schemaNoBody
|
|
113
98
|
|
|
114
|
-
/**
|
|
115
|
-
* @since 1.0.0
|
|
116
|
-
* @category accessors
|
|
117
|
-
*/
|
|
118
|
-
export const arrayBuffer: <E, R>(
|
|
119
|
-
effect: Effect.Effect<HttpClientResponse, E, R>
|
|
120
|
-
) => Effect.Effect<ArrayBuffer, Error.ResponseError | E, Exclude<R, Scope.Scope>> = internal.arrayBuffer
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* @since 1.0.0
|
|
124
|
-
* @category accessors
|
|
125
|
-
*/
|
|
126
|
-
export const formData: <E, R>(
|
|
127
|
-
effect: Effect.Effect<HttpClientResponse, E, R>
|
|
128
|
-
) => Effect.Effect<FormData, Error.ResponseError | E, Exclude<R, Scope.Scope>> = internal.formData
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* @since 1.0.0
|
|
132
|
-
* @category accessors
|
|
133
|
-
*/
|
|
134
|
-
export const json: <E, R>(
|
|
135
|
-
effect: Effect.Effect<HttpClientResponse, E, R>
|
|
136
|
-
) => Effect.Effect<unknown, Error.ResponseError | E, Exclude<R, Scope.Scope>> = internal.json
|
|
137
|
-
|
|
138
|
-
const void_: <E, R>(
|
|
139
|
-
effect: Effect.Effect<HttpClientResponse, E, R>
|
|
140
|
-
) => Effect.Effect<void, E, Exclude<R, Scope.Scope>> = internal.void_
|
|
141
|
-
export {
|
|
142
|
-
/**
|
|
143
|
-
* @since 1.0.0
|
|
144
|
-
* @category accessors
|
|
145
|
-
*/
|
|
146
|
-
void_ as void
|
|
147
|
-
}
|
|
148
|
-
|
|
149
99
|
/**
|
|
150
100
|
* @since 1.0.0
|
|
151
101
|
* @category accessors
|
|
@@ -154,64 +104,6 @@ export const stream: <E, R>(
|
|
|
154
104
|
effect: Effect.Effect<HttpClientResponse, E, R>
|
|
155
105
|
) => Stream.Stream<Uint8Array, Error.ResponseError | E, Exclude<R, Scope.Scope>> = internal.stream
|
|
156
106
|
|
|
157
|
-
/**
|
|
158
|
-
* @since 1.0.0
|
|
159
|
-
* @category accessors
|
|
160
|
-
*/
|
|
161
|
-
export const text: <E, R>(
|
|
162
|
-
effect: Effect.Effect<HttpClientResponse, E, R>
|
|
163
|
-
) => Effect.Effect<string, Error.ResponseError | E, Exclude<R, Scope.Scope>> = internal.text
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* @since 1.0.0
|
|
167
|
-
* @category accessors
|
|
168
|
-
*/
|
|
169
|
-
export const urlParamsBody: <E, R>(
|
|
170
|
-
effect: Effect.Effect<HttpClientResponse, E, R>
|
|
171
|
-
) => Effect.Effect<UrlParams.UrlParams, Error.ResponseError | E, Exclude<R, Scope.Scope>> = internal.urlParamsBody
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* @since 1.0.0
|
|
175
|
-
* @category schema
|
|
176
|
-
*/
|
|
177
|
-
export const schemaJsonScoped: <
|
|
178
|
-
R,
|
|
179
|
-
I extends {
|
|
180
|
-
readonly status?: number | undefined
|
|
181
|
-
readonly headers?: Readonly<Record<string, string>> | undefined
|
|
182
|
-
readonly body?: unknown
|
|
183
|
-
},
|
|
184
|
-
A
|
|
185
|
-
>(
|
|
186
|
-
schema: Schema.Schema<A, I, R>,
|
|
187
|
-
options?: ParseOptions | undefined
|
|
188
|
-
) => <E, R2>(
|
|
189
|
-
effect: Effect.Effect<HttpClientResponse, E, R2>
|
|
190
|
-
) => Effect.Effect<
|
|
191
|
-
A,
|
|
192
|
-
E | Error.ResponseError | ParseResult.ParseError,
|
|
193
|
-
Exclude<R, Scope.Scope> | Exclude<R2, Scope.Scope>
|
|
194
|
-
> = internal.schemaJsonScoped
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* @since 1.0.0
|
|
198
|
-
* @category schema
|
|
199
|
-
*/
|
|
200
|
-
export const schemaNoBodyScoped: <
|
|
201
|
-
R,
|
|
202
|
-
I extends {
|
|
203
|
-
readonly status?: number | undefined
|
|
204
|
-
readonly headers?: Readonly<Record<string, string>> | undefined
|
|
205
|
-
},
|
|
206
|
-
A
|
|
207
|
-
>(
|
|
208
|
-
schema: Schema.Schema<A, I, R>,
|
|
209
|
-
options?: ParseOptions | undefined
|
|
210
|
-
) => <E, R2>(
|
|
211
|
-
effect: Effect.Effect<HttpClientResponse, E, R2>
|
|
212
|
-
) => Effect.Effect<A, E | ParseResult.ParseError, Exclude<R, Scope.Scope> | Exclude<R2, Scope.Scope>> =
|
|
213
|
-
internal.schemaNoBodyScoped
|
|
214
|
-
|
|
215
107
|
/**
|
|
216
108
|
* @since 1.0.0
|
|
217
109
|
* @category pattern matching
|
|
@@ -226,7 +118,7 @@ export const matchStatus: {
|
|
|
226
118
|
readonly "5xx"?: (_: HttpClientResponse) => any
|
|
227
119
|
readonly orElse: (_: HttpClientResponse) => any
|
|
228
120
|
}
|
|
229
|
-
>(cases: Cases): (self: HttpClientResponse) => Cases[keyof Cases] extends (_: any) => infer R ? R : never
|
|
121
|
+
>(cases: Cases): (self: HttpClientResponse) => Cases[keyof Cases] extends (_: any) => infer R ? Unify<R> : never
|
|
230
122
|
<
|
|
231
123
|
const Cases extends {
|
|
232
124
|
readonly [status: number]: (_: HttpClientResponse) => any
|
|
@@ -236,55 +128,5 @@ export const matchStatus: {
|
|
|
236
128
|
readonly "5xx"?: (_: HttpClientResponse) => any
|
|
237
129
|
readonly orElse: (_: HttpClientResponse) => any
|
|
238
130
|
}
|
|
239
|
-
>(self: HttpClientResponse, cases: Cases): Cases[keyof Cases] extends (_: any) => infer R ? R : never
|
|
131
|
+
>(self: HttpClientResponse, cases: Cases): Cases[keyof Cases] extends (_: any) => infer R ? Unify<R> : never
|
|
240
132
|
} = internal.matchStatus
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* @since 1.0.0
|
|
244
|
-
* @category pattern matching
|
|
245
|
-
*/
|
|
246
|
-
export const matchStatusScoped: {
|
|
247
|
-
<
|
|
248
|
-
const Cases extends {
|
|
249
|
-
readonly [status: number]: (_: HttpClientResponse) => Effect.Effect<any, any, any>
|
|
250
|
-
readonly "2xx"?: (_: HttpClientResponse) => Effect.Effect<any, any, any>
|
|
251
|
-
readonly "3xx"?: (_: HttpClientResponse) => Effect.Effect<any, any, any>
|
|
252
|
-
readonly "4xx"?: (_: HttpClientResponse) => Effect.Effect<any, any, any>
|
|
253
|
-
readonly "5xx"?: (_: HttpClientResponse) => Effect.Effect<any, any, any>
|
|
254
|
-
readonly orElse: (_: HttpClientResponse) => Effect.Effect<any, any, any>
|
|
255
|
-
}
|
|
256
|
-
>(
|
|
257
|
-
cases: Cases
|
|
258
|
-
): <E, R>(
|
|
259
|
-
self: Effect.Effect<HttpClientResponse, E, R>
|
|
260
|
-
) => Effect.Effect<
|
|
261
|
-
Cases[keyof Cases] extends (_: any) => Effect.Effect<infer _A, infer _E, infer _R> ? _A : never,
|
|
262
|
-
E | (Cases[keyof Cases] extends (_: any) => Effect.Effect<infer _A, infer _E, infer _R> ? _E : never),
|
|
263
|
-
Exclude<
|
|
264
|
-
R | (Cases[keyof Cases] extends (_: any) => Effect.Effect<infer _A, infer _E, infer _R> ? _R : never),
|
|
265
|
-
Scope.Scope
|
|
266
|
-
>
|
|
267
|
-
>
|
|
268
|
-
<
|
|
269
|
-
E,
|
|
270
|
-
R,
|
|
271
|
-
const Cases extends {
|
|
272
|
-
readonly [status: number]: (_: HttpClientResponse) => Effect.Effect<any, any, any>
|
|
273
|
-
readonly "2xx"?: (_: HttpClientResponse) => Effect.Effect<any, any, any>
|
|
274
|
-
readonly "3xx"?: (_: HttpClientResponse) => Effect.Effect<any, any, any>
|
|
275
|
-
readonly "4xx"?: (_: HttpClientResponse) => Effect.Effect<any, any, any>
|
|
276
|
-
readonly "5xx"?: (_: HttpClientResponse) => Effect.Effect<any, any, any>
|
|
277
|
-
readonly orElse: (_: HttpClientResponse) => Effect.Effect<any, any, any>
|
|
278
|
-
}
|
|
279
|
-
>(
|
|
280
|
-
self: Effect.Effect<HttpClientResponse, E, R>,
|
|
281
|
-
cases: Cases
|
|
282
|
-
): Effect.Effect<
|
|
283
|
-
Cases[keyof Cases] extends (_: any) => Effect.Effect<infer _A, infer _E, infer _R> ? _A : never,
|
|
284
|
-
E | (Cases[keyof Cases] extends (_: any) => Effect.Effect<infer _A, infer _E, infer _R> ? _E : never),
|
|
285
|
-
Exclude<
|
|
286
|
-
R | (Cases[keyof Cases] extends (_: any) => Effect.Effect<infer _A, infer _E, infer _R> ? _R : never),
|
|
287
|
-
Scope.Scope
|
|
288
|
-
>
|
|
289
|
-
>
|
|
290
|
-
} = internal.matchStatusScoped
|
|
@@ -10,7 +10,6 @@ import { dual } from "effect/Function"
|
|
|
10
10
|
import * as Global from "effect/GlobalValue"
|
|
11
11
|
import type { Inspectable } from "effect/Inspectable"
|
|
12
12
|
import * as Option from "effect/Option"
|
|
13
|
-
import type * as Scope from "effect/Scope"
|
|
14
13
|
import type * as Stream from "effect/Stream"
|
|
15
14
|
import * as FileSystem from "./FileSystem.js"
|
|
16
15
|
import type * as Headers from "./Headers.js"
|
|
@@ -53,18 +52,6 @@ export const schemaBodyJson = <A, I, R>(schema: Schema.Schema<A, I, R>, options?
|
|
|
53
52
|
Effect.flatMap(self.json, parse)
|
|
54
53
|
}
|
|
55
54
|
|
|
56
|
-
/**
|
|
57
|
-
* @since 1.0.0
|
|
58
|
-
* @category schema
|
|
59
|
-
*/
|
|
60
|
-
export const schemaBodyJsonScoped = <A, I, R>(schema: Schema.Schema<A, I, R>, options?: ParseOptions | undefined) => {
|
|
61
|
-
const decode = schemaBodyJson(schema, options)
|
|
62
|
-
return <E, E2, R2>(
|
|
63
|
-
effect: Effect.Effect<HttpIncomingMessage<E>, E2, R2>
|
|
64
|
-
): Effect.Effect<A, ParseResult.ParseError | E | E2, Exclude<R, Scope.Scope> | Exclude<R2, Scope.Scope>> =>
|
|
65
|
-
Effect.scoped(Effect.flatMap(effect, decode))
|
|
66
|
-
}
|
|
67
|
-
|
|
68
55
|
/**
|
|
69
56
|
* @since 1.0.0
|
|
70
57
|
* @category schema
|
|
@@ -78,21 +65,6 @@ export const schemaBodyUrlParams = <A, I extends Readonly<Record<string, string
|
|
|
78
65
|
Effect.flatMap(self.urlParamsBody, (_) => parse(Object.fromEntries(_)))
|
|
79
66
|
}
|
|
80
67
|
|
|
81
|
-
/**
|
|
82
|
-
* @since 1.0.0
|
|
83
|
-
* @category schema
|
|
84
|
-
*/
|
|
85
|
-
export const schemaBodyUrlParamsScoped = <A, I extends Readonly<Record<string, string | undefined>>, R>(
|
|
86
|
-
schema: Schema.Schema<A, I, R>,
|
|
87
|
-
options?: ParseOptions | undefined
|
|
88
|
-
) => {
|
|
89
|
-
const decode = schemaBodyUrlParams(schema, options)
|
|
90
|
-
return <E, E2, R2>(
|
|
91
|
-
effect: Effect.Effect<HttpIncomingMessage<E>, E2, R2>
|
|
92
|
-
): Effect.Effect<A, ParseResult.ParseError | E | E2, Exclude<R, Scope.Scope> | Exclude<R2, Scope.Scope>> =>
|
|
93
|
-
Effect.scoped(Effect.flatMap(effect, decode))
|
|
94
|
-
}
|
|
95
|
-
|
|
96
68
|
/**
|
|
97
69
|
* @since 1.0.0
|
|
98
70
|
* @category schema
|
|
@@ -105,21 +77,6 @@ export const schemaHeaders = <A, I extends Readonly<Record<string, string | unde
|
|
|
105
77
|
return <E>(self: HttpIncomingMessage<E>): Effect.Effect<A, ParseResult.ParseError, R> => parse(self.headers)
|
|
106
78
|
}
|
|
107
79
|
|
|
108
|
-
/**
|
|
109
|
-
* @since 1.0.0
|
|
110
|
-
* @category schema
|
|
111
|
-
*/
|
|
112
|
-
export const schemaHeadersScoped = <A, I extends Readonly<Record<string, string | undefined>>, R>(
|
|
113
|
-
schema: Schema.Schema<A, I, R>,
|
|
114
|
-
options?: ParseOptions | undefined
|
|
115
|
-
) => {
|
|
116
|
-
const decode = schemaHeaders(schema, options)
|
|
117
|
-
return <E, E2, R2>(
|
|
118
|
-
effect: Effect.Effect<HttpIncomingMessage<E>, E2, R2>
|
|
119
|
-
): Effect.Effect<A, ParseResult.ParseError | E2, Exclude<R, Scope.Scope> | Exclude<R2, Scope.Scope>> =>
|
|
120
|
-
Effect.scoped(Effect.flatMap(effect, decode))
|
|
121
|
-
}
|
|
122
|
-
|
|
123
80
|
/**
|
|
124
81
|
* @since 1.0.0
|
|
125
82
|
* @category fiber refs
|
package/src/HttpServer.ts
CHANGED
|
@@ -201,5 +201,5 @@ export const withLogAddress: <A, E, R>(layer: Layer.Layer<A, E, R>) => Layer.Lay
|
|
|
201
201
|
* @since 1.0.0
|
|
202
202
|
* @category layers
|
|
203
203
|
*/
|
|
204
|
-
export const layerTestClient: Layer.Layer<Client.HttpClient.
|
|
204
|
+
export const layerTestClient: Layer.Layer<Client.HttpClient.Service, never, Client.HttpClient.Service | HttpServer> =
|
|
205
205
|
internal.layerTestClient
|
package/src/Runtime.ts
CHANGED
|
@@ -63,7 +63,7 @@ const addPrettyLogger = (refs: FiberRefs.FiberRefs, fiberId: FiberId.Runtime) =>
|
|
|
63
63
|
fiberRef: FiberRef.currentLoggers,
|
|
64
64
|
value: loggers.pipe(
|
|
65
65
|
HashSet.remove(Logger.defaultLogger),
|
|
66
|
-
HashSet.add(Logger.
|
|
66
|
+
HashSet.add(Logger.prettyLoggerDefault)
|
|
67
67
|
)
|
|
68
68
|
})
|
|
69
69
|
}
|
package/src/Socket.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @since 1.0.0
|
|
3
3
|
*/
|
|
4
4
|
import * as Channel from "effect/Channel"
|
|
5
|
-
import * as Chunk from "effect/Chunk"
|
|
5
|
+
import type * as Chunk from "effect/Chunk"
|
|
6
6
|
import * as Context from "effect/Context"
|
|
7
7
|
import * as Deferred from "effect/Deferred"
|
|
8
8
|
import type { DurationInput } from "effect/Duration"
|
|
@@ -14,6 +14,7 @@ import * as FiberSet from "effect/FiberSet"
|
|
|
14
14
|
import { dual } from "effect/Function"
|
|
15
15
|
import { globalValue } from "effect/GlobalValue"
|
|
16
16
|
import * as Layer from "effect/Layer"
|
|
17
|
+
import * as Mailbox from "effect/Mailbox"
|
|
17
18
|
import * as Predicate from "effect/Predicate"
|
|
18
19
|
import * as Queue from "effect/Queue"
|
|
19
20
|
import * as Scope from "effect/Scope"
|
|
@@ -52,11 +53,11 @@ export const Socket: Context.Tag<Socket, Socket> = Context.GenericTag<Socket>(
|
|
|
52
53
|
*/
|
|
53
54
|
export interface Socket {
|
|
54
55
|
readonly [TypeId]: TypeId
|
|
55
|
-
readonly run: <_, E, R>(
|
|
56
|
-
handler: (_: Uint8Array) => Effect.Effect<_, E, R>
|
|
56
|
+
readonly run: <_, E = never, R = never>(
|
|
57
|
+
handler: (_: Uint8Array) => Effect.Effect<_, E, R> | void
|
|
57
58
|
) => Effect.Effect<void, SocketError | E, R>
|
|
58
|
-
readonly runRaw: <_, E, R>(
|
|
59
|
-
handler: (_: string | Uint8Array) => Effect.Effect<_, E, R>
|
|
59
|
+
readonly runRaw: <_, E = never, R = never>(
|
|
60
|
+
handler: (_: string | Uint8Array) => Effect.Effect<_, E, R> | void
|
|
60
61
|
) => Effect.Effect<void, SocketError | E, R>
|
|
61
62
|
readonly writer: Effect.Effect<
|
|
62
63
|
(chunk: Uint8Array | string | CloseEvent) => Effect.Effect<boolean>,
|
|
@@ -190,27 +191,25 @@ export const toChannelMap = <IE, A>(
|
|
|
190
191
|
> =>
|
|
191
192
|
Effect.scope.pipe(
|
|
192
193
|
Effect.bindTo("scope"),
|
|
193
|
-
Effect.
|
|
194
|
-
Effect.bind("semaphore", () => Effect.makeSemaphore(0)),
|
|
194
|
+
Effect.bind("mailbox", () => Mailbox.make<A, SocketError | IE>()),
|
|
195
195
|
Effect.bind("writeScope", ({ scope }) => Scope.fork(scope, ExecutionStrategy.sequential)),
|
|
196
196
|
Effect.bind("write", ({ writeScope }) => Scope.extend(self.writer, writeScope)),
|
|
197
|
-
Effect.bind("deferred", () => Deferred.make<void, SocketError | IE>()),
|
|
198
197
|
Effect.let(
|
|
199
198
|
"input",
|
|
200
199
|
(
|
|
201
|
-
{
|
|
200
|
+
{ mailbox, write, writeScope }
|
|
202
201
|
): AsyncProducer.AsyncInputProducer<IE, Chunk.Chunk<Uint8Array | string | CloseEvent>, unknown> => ({
|
|
203
202
|
awaitRead: () => Effect.void,
|
|
204
203
|
emit(chunk) {
|
|
205
204
|
return Effect.catchAllCause(
|
|
206
205
|
Effect.forEach(chunk, write, { discard: true }),
|
|
207
|
-
(cause) =>
|
|
206
|
+
(cause) => mailbox.failCause(cause)
|
|
208
207
|
)
|
|
209
208
|
},
|
|
210
209
|
error(error) {
|
|
211
210
|
return Effect.zipRight(
|
|
212
211
|
Scope.close(writeScope, Exit.void),
|
|
213
|
-
|
|
212
|
+
mailbox.failCause(error)
|
|
214
213
|
)
|
|
215
214
|
},
|
|
216
215
|
done() {
|
|
@@ -218,35 +217,16 @@ export const toChannelMap = <IE, A>(
|
|
|
218
217
|
}
|
|
219
218
|
})
|
|
220
219
|
),
|
|
221
|
-
Effect.tap(({
|
|
220
|
+
Effect.tap(({ mailbox, scope }) =>
|
|
222
221
|
self.runRaw((data) => {
|
|
223
|
-
|
|
224
|
-
return semaphore.release(1)
|
|
222
|
+
mailbox.unsafeOffer(f(data))
|
|
225
223
|
}).pipe(
|
|
226
|
-
|
|
227
|
-
Effect.raceFirst(Deferred.await(deferred)),
|
|
228
|
-
Effect.ensuring(Effect.suspend(() => {
|
|
229
|
-
state.finished = true
|
|
230
|
-
return semaphore.release(1)
|
|
231
|
-
})),
|
|
224
|
+
Mailbox.into(mailbox),
|
|
232
225
|
Effect.forkIn(scope),
|
|
233
226
|
Effect.interruptible
|
|
234
227
|
)
|
|
235
228
|
),
|
|
236
|
-
Effect.map(({
|
|
237
|
-
const loop: Channel.Channel<Chunk.Chunk<A>, unknown, SocketError | IE, unknown, void, unknown> = Channel.flatMap(
|
|
238
|
-
semaphore.take(1),
|
|
239
|
-
(_) => {
|
|
240
|
-
if (state.buffer.length === 0) {
|
|
241
|
-
return state.finished ? Deferred.await(deferred) : loop
|
|
242
|
-
}
|
|
243
|
-
const chunk = Chunk.unsafeFromArray(state.buffer)
|
|
244
|
-
state.buffer = []
|
|
245
|
-
return Channel.zipRight(Channel.write(chunk), state.finished ? Deferred.await(deferred) : loop)
|
|
246
|
-
}
|
|
247
|
-
)
|
|
248
|
-
return Channel.embedInput(loop, input)
|
|
249
|
-
}),
|
|
229
|
+
Effect.map(({ input, mailbox }) => Channel.embedInput(Mailbox.toChannel(mailbox), input)),
|
|
250
230
|
Channel.unwrapScoped
|
|
251
231
|
)
|
|
252
232
|
|
|
@@ -395,14 +375,7 @@ export const makeWebSocket = (url: string | Effect.Effect<string>, options?: {
|
|
|
395
375
|
(typeof url === "string" ? Effect.succeed(url) : url).pipe(
|
|
396
376
|
Effect.flatMap((url) => Effect.map(WebSocketConstructor, (f) => f(url)))
|
|
397
377
|
),
|
|
398
|
-
(ws) =>
|
|
399
|
-
Effect.sync(() => {
|
|
400
|
-
ws.onclose = null
|
|
401
|
-
ws.onerror = null
|
|
402
|
-
ws.onmessage = null
|
|
403
|
-
ws.onopen = null
|
|
404
|
-
return ws.close()
|
|
405
|
-
})
|
|
378
|
+
(ws) => Effect.sync(() => ws.close())
|
|
406
379
|
),
|
|
407
380
|
options
|
|
408
381
|
)
|
|
@@ -424,7 +397,7 @@ export const fromWebSocket = <R>(
|
|
|
424
397
|
(sendQueue) => {
|
|
425
398
|
const acquireContext = fiber.getFiberRef(FiberRef.currentContext) as Context.Context<R>
|
|
426
399
|
const closeCodeIsError = options?.closeCodeIsError ?? defaultCloseCodeIsError
|
|
427
|
-
const runRaw = <_, E, R>(handler: (_: string | Uint8Array) => Effect.Effect<_, E, R>) =>
|
|
400
|
+
const runRaw = <_, E, R>(handler: (_: string | Uint8Array) => Effect.Effect<_, E, R> | void) =>
|
|
428
401
|
acquire.pipe(
|
|
429
402
|
Effect.bindTo("ws"),
|
|
430
403
|
Effect.bind("fiberSet", () => FiberSet.make<any, E | SocketError>()),
|
|
@@ -433,16 +406,29 @@ export const fromWebSocket = <R>(
|
|
|
433
406
|
Effect.tap(({ fiberSet, run, ws }) => {
|
|
434
407
|
let open = false
|
|
435
408
|
|
|
436
|
-
|
|
437
|
-
|
|
409
|
+
function onMessage(event: MessageEvent) {
|
|
410
|
+
const result = handler(
|
|
438
411
|
typeof event.data === "string"
|
|
439
412
|
? event.data
|
|
440
413
|
: event.data instanceof Uint8Array
|
|
441
414
|
? event.data
|
|
442
415
|
: new Uint8Array(event.data)
|
|
443
|
-
)
|
|
416
|
+
)
|
|
417
|
+
if (Effect.isEffect(result)) {
|
|
418
|
+
run(result)
|
|
419
|
+
}
|
|
444
420
|
}
|
|
445
|
-
|
|
421
|
+
function onError(cause: Event) {
|
|
422
|
+
ws.removeEventListener("message", onMessage)
|
|
423
|
+
ws.removeEventListener("close", onClose)
|
|
424
|
+
Deferred.unsafeDone(
|
|
425
|
+
fiberSet.deferred,
|
|
426
|
+
Effect.fail(new SocketGenericError({ reason: open ? "Read" : "Open", cause }))
|
|
427
|
+
)
|
|
428
|
+
}
|
|
429
|
+
function onClose(event: globalThis.CloseEvent) {
|
|
430
|
+
ws.removeEventListener("message", onMessage)
|
|
431
|
+
ws.removeEventListener("error", onError)
|
|
446
432
|
Deferred.unsafeDone(
|
|
447
433
|
fiberSet.deferred,
|
|
448
434
|
Effect.fail(
|
|
@@ -454,19 +440,17 @@ export const fromWebSocket = <R>(
|
|
|
454
440
|
)
|
|
455
441
|
)
|
|
456
442
|
}
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
)
|
|
462
|
-
}
|
|
443
|
+
|
|
444
|
+
ws.addEventListener("close", onClose, { once: true })
|
|
445
|
+
ws.addEventListener("error", onError, { once: true })
|
|
446
|
+
ws.addEventListener("message", onMessage)
|
|
463
447
|
|
|
464
448
|
if (ws.readyState !== 1) {
|
|
465
449
|
const openDeferred = Deferred.unsafeMake<void>(fiber.id())
|
|
466
|
-
ws.
|
|
450
|
+
ws.addEventListener("open", () => {
|
|
467
451
|
open = true
|
|
468
452
|
Deferred.unsafeDone(openDeferred, Effect.void)
|
|
469
|
-
}
|
|
453
|
+
}, { once: true })
|
|
470
454
|
return Deferred.await(openDeferred).pipe(
|
|
471
455
|
Effect.timeoutFail({
|
|
472
456
|
duration: options?.openTimeout ?? 10000,
|
|
@@ -514,7 +498,7 @@ export const fromWebSocket = <R>(
|
|
|
514
498
|
)
|
|
515
499
|
|
|
516
500
|
const encoder = new TextEncoder()
|
|
517
|
-
const run = <_, E, R>(handler: (_: Uint8Array) => Effect.Effect<_, E, R>) =>
|
|
501
|
+
const run = <_, E, R>(handler: (_: Uint8Array) => Effect.Effect<_, E, R> | void) =>
|
|
518
502
|
runRaw((data) =>
|
|
519
503
|
typeof data === "string"
|
|
520
504
|
? handler(encoder.encode(data))
|
|
@@ -600,7 +584,7 @@ export const fromTransformStream = <R>(acquire: Effect.Effect<InputTransformStre
|
|
|
600
584
|
(sendQueue) => {
|
|
601
585
|
const acquireContext = fiber.getFiberRef(FiberRef.currentContext) as Context.Context<R>
|
|
602
586
|
const closeCodeIsError = options?.closeCodeIsError ?? defaultCloseCodeIsError
|
|
603
|
-
const runRaw = <_, E, R>(handler: (_: string | Uint8Array) => Effect.Effect<_, E, R>) =>
|
|
587
|
+
const runRaw = <_, E, R>(handler: (_: string | Uint8Array) => Effect.Effect<_, E, R> | void) =>
|
|
604
588
|
acquire.pipe(
|
|
605
589
|
Effect.bindTo("stream"),
|
|
606
590
|
Effect.bind("reader", ({ stream }) =>
|
|
@@ -681,7 +665,7 @@ export const fromTransformStream = <R>(acquire: Effect.Effect<InputTransformStre
|
|
|
681
665
|
)
|
|
682
666
|
|
|
683
667
|
const encoder = new TextEncoder()
|
|
684
|
-
const run = <_, E, R>(handler: (_: Uint8Array) => Effect.Effect<_, E, R>) =>
|
|
668
|
+
const run = <_, E, R>(handler: (_: Uint8Array) => Effect.Effect<_, E, R> | void) =>
|
|
685
669
|
runRaw((data) =>
|
|
686
670
|
typeof data === "string"
|
|
687
671
|
? handler(encoder.encode(data))
|
package/src/index.ts
CHANGED
package/src/internal/command.ts
CHANGED
|
@@ -241,13 +241,14 @@ export const start = (
|
|
|
241
241
|
export const stream = (
|
|
242
242
|
command: Command.Command
|
|
243
243
|
): Stream.Stream<Uint8Array, PlatformError, CommandExecutor.CommandExecutor> =>
|
|
244
|
-
Stream.flatMap(commandExecutor.CommandExecutor, (
|
|
244
|
+
Stream.flatMap(commandExecutor.CommandExecutor, (executor) => executor.stream(command))
|
|
245
245
|
|
|
246
246
|
/** @internal */
|
|
247
247
|
export const streamLines = (
|
|
248
|
-
command: Command.Command
|
|
248
|
+
command: Command.Command,
|
|
249
|
+
encoding?: string
|
|
249
250
|
): Stream.Stream<string, PlatformError, CommandExecutor.CommandExecutor> =>
|
|
250
|
-
Stream.flatMap(commandExecutor.CommandExecutor, (
|
|
251
|
+
Stream.flatMap(commandExecutor.CommandExecutor, (executor) => executor.streamLines(command, encoding))
|
|
251
252
|
|
|
252
253
|
/** @internal */
|
|
253
254
|
export const string = dual<
|