@effect/platform 0.10.4 → 0.11.1
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/Effectify.d.ts.map +1 -1
- package/Http/Body.d.ts +129 -0
- package/Http/Body.d.ts.map +1 -0
- package/Http/Body.js +70 -0
- package/Http/Body.js.map +1 -0
- package/Http/Client.d.ts +213 -0
- package/Http/Client.d.ts.map +1 -0
- package/Http/Client.js +124 -0
- package/Http/Client.js.map +1 -0
- package/Http/ClientError.d.ts +70 -0
- package/Http/ClientError.d.ts.map +1 -0
- package/Http/ClientError.js +28 -0
- package/Http/ClientError.js.map +1 -0
- package/Http/ClientRequest.d.ts +317 -0
- package/Http/ClientRequest.d.ts.map +1 -0
- package/Http/ClientRequest.js +202 -0
- package/Http/ClientRequest.js.map +1 -0
- package/Http/ClientResponse.d.ts +36 -0
- package/Http/ClientResponse.d.ts.map +1 -0
- package/Http/ClientResponse.js +29 -0
- package/Http/ClientResponse.js.map +1 -0
- package/Http/FormData.d.ts +56 -0
- package/Http/FormData.d.ts.map +1 -0
- package/Http/FormData.js +13 -0
- package/Http/FormData.js.map +1 -0
- package/Http/Headers.d.ts +38 -0
- package/Http/Headers.d.ts.map +1 -0
- package/Http/Headers.js +54 -0
- package/Http/Headers.js.map +1 -0
- package/Http/IncomingMessage.d.ts +37 -0
- package/Http/IncomingMessage.d.ts.map +1 -0
- package/Http/IncomingMessage.js +30 -0
- package/Http/IncomingMessage.js.map +1 -0
- package/Http/Method.d.ts +10 -0
- package/Http/Method.d.ts.map +1 -0
- package/Http/Method.js +12 -0
- package/Http/Method.js.map +1 -0
- package/Http/UrlParams.d.ts +56 -0
- package/Http/UrlParams.d.ts.map +1 -0
- package/Http/UrlParams.js +74 -0
- package/Http/UrlParams.js.map +1 -0
- package/HttpClient.d.ts +32 -0
- package/HttpClient.d.ts.map +1 -0
- package/HttpClient.js +23 -0
- package/HttpClient.js.map +1 -0
- package/README.md +3 -0
- package/internal/console.js.map +1 -1
- package/internal/effectify.js.map +1 -1
- package/internal/error.js.map +1 -1
- package/internal/http/body.d.ts +2 -0
- package/internal/http/body.d.ts.map +1 -0
- package/internal/http/body.js +101 -0
- package/internal/http/body.js.map +1 -0
- package/internal/http/client.d.ts +3 -0
- package/internal/http/client.d.ts.map +1 -0
- package/internal/http/client.js +147 -0
- package/internal/http/client.js.map +1 -0
- package/internal/http/clientError.d.ts +2 -0
- package/internal/http/clientError.d.ts.map +1 -0
- package/internal/http/clientError.js +24 -0
- package/internal/http/clientError.js.map +1 -0
- package/internal/http/clientRequest.d.ts +2 -0
- package/internal/http/clientRequest.d.ts.map +1 -0
- package/internal/http/clientRequest.js +180 -0
- package/internal/http/clientRequest.js.map +1 -0
- package/internal/http/clientResponse.d.ts +2 -0
- package/internal/http/clientResponse.d.ts.map +1 -0
- package/internal/http/clientResponse.js +101 -0
- package/internal/http/clientResponse.js.map +1 -0
- package/mjs/Http/Body.mjs +52 -0
- package/mjs/Http/Body.mjs.map +1 -0
- package/mjs/Http/Client.mjs +97 -0
- package/mjs/Http/Client.mjs.map +1 -0
- package/mjs/Http/ClientError.mjs +17 -0
- package/mjs/Http/ClientError.mjs.map +1 -0
- package/mjs/Http/ClientRequest.mjs +162 -0
- package/mjs/Http/ClientRequest.mjs.map +1 -0
- package/mjs/Http/ClientResponse.mjs +18 -0
- package/mjs/Http/ClientResponse.mjs.map +1 -0
- package/mjs/Http/FormData.mjs +6 -0
- package/mjs/Http/FormData.mjs.map +1 -0
- package/mjs/Http/Headers.mjs +40 -0
- package/mjs/Http/Headers.mjs.map +1 -0
- package/mjs/Http/IncomingMessage.mjs +19 -0
- package/mjs/Http/IncomingMessage.mjs.map +1 -0
- package/mjs/Http/Method.mjs +5 -0
- package/mjs/Http/Method.mjs.map +1 -0
- package/mjs/Http/UrlParams.mjs +57 -0
- package/mjs/Http/UrlParams.mjs.map +1 -0
- package/mjs/HttpClient.mjs +18 -0
- package/mjs/HttpClient.mjs.map +1 -0
- package/mjs/internal/console.mjs.map +1 -1
- package/mjs/internal/effectify.mjs.map +1 -1
- package/mjs/internal/error.mjs.map +1 -1
- package/mjs/internal/http/body.mjs +83 -0
- package/mjs/internal/http/body.mjs.map +1 -0
- package/mjs/internal/http/client.mjs +120 -0
- package/mjs/internal/http/client.mjs.map +1 -0
- package/mjs/internal/http/clientError.mjs +13 -0
- package/mjs/internal/http/clientError.mjs.map +1 -0
- package/mjs/internal/http/clientRequest.mjs +138 -0
- package/mjs/internal/http/clientRequest.mjs.map +1 -0
- package/mjs/internal/http/clientResponse.mjs +91 -0
- package/mjs/internal/http/clientResponse.mjs.map +1 -0
- package/package.json +13 -8
- package/src/Effectify.ts +65 -65
- package/src/Http/Body.ts +148 -0
- package/src/Http/Client.ts +280 -0
- package/src/Http/ClientError.ts +80 -0
- package/src/Http/ClientRequest.ts +383 -0
- package/src/Http/ClientResponse.ts +42 -0
- package/src/Http/FormData.ts +61 -0
- package/src/Http/Headers.ts +69 -0
- package/src/Http/IncomingMessage.ts +45 -0
- package/src/Http/Method.ts +17 -0
- package/src/Http/UrlParams.ts +106 -0
- package/src/HttpClient.ts +32 -0
- package/src/internal/console.ts +6 -6
- package/src/internal/effectify.ts +14 -14
- package/src/internal/error.ts +2 -2
- package/src/internal/http/body.ts +113 -0
- package/src/internal/http/client.ts +437 -0
- package/src/internal/http/clientError.ts +20 -0
- package/src/internal/http/clientRequest.ts +390 -0
- package/src/internal/http/clientResponse.ts +114 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 1.0.0
|
|
3
|
+
*/
|
|
4
|
+
import * as Chunk from "@effect/data/Chunk"
|
|
5
|
+
import { dual } from "@effect/data/Function"
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @since 1.0.0
|
|
9
|
+
* @category models
|
|
10
|
+
*/
|
|
11
|
+
export interface UrlParams extends Chunk.Chunk<[string, string]> {}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @since 1.0.0
|
|
15
|
+
* @category models
|
|
16
|
+
*/
|
|
17
|
+
export type Input = UrlParams | Readonly<Record<string, string>> | Iterable<readonly [string, string]> | URLSearchParams
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @since 1.0.0
|
|
21
|
+
* @category constructors
|
|
22
|
+
*/
|
|
23
|
+
export const fromInput = (input: Input): UrlParams => {
|
|
24
|
+
if (Chunk.isChunk(input)) {
|
|
25
|
+
return input
|
|
26
|
+
} else if (Symbol.iterator in input) {
|
|
27
|
+
return Chunk.fromIterable(input) as UrlParams
|
|
28
|
+
}
|
|
29
|
+
return Chunk.fromIterable(Object.entries(input))
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @since 1.0.0
|
|
34
|
+
* @category constructors
|
|
35
|
+
*/
|
|
36
|
+
export const empty: UrlParams = Chunk.empty()
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @since 1.0.0
|
|
40
|
+
* @category combinators
|
|
41
|
+
*/
|
|
42
|
+
export const set = dual<
|
|
43
|
+
(key: string, value: string) => (self: UrlParams) => UrlParams,
|
|
44
|
+
(self: UrlParams, key: string, value: string) => UrlParams
|
|
45
|
+
>(3, (self, key, value) =>
|
|
46
|
+
Chunk.append(
|
|
47
|
+
Chunk.filter(self, ([k]) => k !== key),
|
|
48
|
+
[key, value]
|
|
49
|
+
))
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @since 1.0.0
|
|
53
|
+
* @category combinators
|
|
54
|
+
*/
|
|
55
|
+
export const setAll = dual<
|
|
56
|
+
(input: Input) => (self: UrlParams) => UrlParams,
|
|
57
|
+
(self: UrlParams, input: Input) => UrlParams
|
|
58
|
+
>(2, (self, input) => {
|
|
59
|
+
const toSet = fromInput(input)
|
|
60
|
+
const keys = Chunk.toReadonlyArray(toSet).map(([k]) => k)
|
|
61
|
+
return Chunk.appendAll(
|
|
62
|
+
Chunk.filter(self, ([k]) => keys.includes(k)),
|
|
63
|
+
toSet
|
|
64
|
+
)
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @since 1.0.0
|
|
69
|
+
* @category combinators
|
|
70
|
+
*/
|
|
71
|
+
export const append = dual<
|
|
72
|
+
(key: string, value: string) => (self: UrlParams) => UrlParams,
|
|
73
|
+
(self: UrlParams, key: string, value: string) => UrlParams
|
|
74
|
+
>(3, (self, key, value) =>
|
|
75
|
+
Chunk.append(
|
|
76
|
+
self,
|
|
77
|
+
[key, value]
|
|
78
|
+
))
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* @since 1.0.0
|
|
82
|
+
* @category combinators
|
|
83
|
+
*/
|
|
84
|
+
export const appendAll = dual<
|
|
85
|
+
(input: Input) => (self: UrlParams) => UrlParams,
|
|
86
|
+
(self: UrlParams, input: Input) => UrlParams
|
|
87
|
+
>(2, (self, input) =>
|
|
88
|
+
Chunk.appendAll(
|
|
89
|
+
self,
|
|
90
|
+
fromInput(input)
|
|
91
|
+
))
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @since 1.0.0
|
|
95
|
+
* @category combinators
|
|
96
|
+
*/
|
|
97
|
+
export const remove = dual<
|
|
98
|
+
(key: string) => (self: UrlParams) => UrlParams,
|
|
99
|
+
(self: UrlParams, key: string) => UrlParams
|
|
100
|
+
>(2, (self, key) => Chunk.filter(self, ([k]) => k !== key))
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* @since 1.0.0
|
|
104
|
+
* @category combinators
|
|
105
|
+
*/
|
|
106
|
+
export const toString = (self: UrlParams): string => new URLSearchParams(Chunk.toReadonlyArray(self) as any).toString()
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 1.0.0
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @since 1.0.0
|
|
7
|
+
*/
|
|
8
|
+
export * as body from "@effect/platform/Http/Body"
|
|
9
|
+
/**
|
|
10
|
+
* @since 1.0.0
|
|
11
|
+
*/
|
|
12
|
+
export * as client from "@effect/platform/Http/Client"
|
|
13
|
+
/**
|
|
14
|
+
* @since 1.0.0
|
|
15
|
+
*/
|
|
16
|
+
export * as request from "@effect/platform/Http/ClientRequest"
|
|
17
|
+
/**
|
|
18
|
+
* @since 1.0.0
|
|
19
|
+
*/
|
|
20
|
+
export * as response from "@effect/platform/Http/ClientResponse"
|
|
21
|
+
/**
|
|
22
|
+
* @since 1.0.0
|
|
23
|
+
*/
|
|
24
|
+
export * as error from "@effect/platform/Http/ClientError"
|
|
25
|
+
/**
|
|
26
|
+
* @since 1.0.0
|
|
27
|
+
*/
|
|
28
|
+
export * as headers from "@effect/platform/Http/Headers"
|
|
29
|
+
/**
|
|
30
|
+
* @since 1.0.0
|
|
31
|
+
*/
|
|
32
|
+
export * as urlParams from "@effect/platform/Http/UrlParams"
|
package/src/internal/console.ts
CHANGED
|
@@ -172,12 +172,12 @@ export const warn = (...args: ReadonlyArray<any>) => Effect.flatMap(Console, (_)
|
|
|
172
172
|
|
|
173
173
|
/** @internal */
|
|
174
174
|
export const withGroup = (options?: { label?: string; collapsed?: boolean }) =>
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
175
|
+
<R, E, A>(
|
|
176
|
+
self: Effect.Effect<R, E, A>
|
|
177
|
+
) => Effect.flatMap(Console, (_) => _.withGroup(options)(self))
|
|
178
178
|
|
|
179
179
|
/** @internal */
|
|
180
180
|
export const withTime = (label?: string) =>
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
181
|
+
<R, E, A>(
|
|
182
|
+
self: Effect.Effect<R, E, A>
|
|
183
|
+
) => Effect.flatMap(Console, (_) => _.withTime(label)(self))
|
|
@@ -15,17 +15,17 @@ export const effectify: {
|
|
|
15
15
|
): Effectify<F, E | E2>
|
|
16
16
|
} =
|
|
17
17
|
(<A>(fn: Function, onError?: (e: any, args: any) => any, onSyncError?: (e: any, args: any) => any) =>
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
18
|
+
(...args: Array<any>) =>
|
|
19
|
+
Effect.async<never, Error, A>((resume) => {
|
|
20
|
+
try {
|
|
21
|
+
fn(...args, (err: Error | null, result: A) => {
|
|
22
|
+
if (err) {
|
|
23
|
+
resume(Effect.fail(onError ? onError(err, args) : err))
|
|
24
|
+
} else {
|
|
25
|
+
resume(Effect.succeed(result))
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
} catch (err) {
|
|
29
|
+
resume(onSyncError ? Effect.fail(onSyncError(err, args)) : Effect.die(err))
|
|
30
|
+
}
|
|
31
|
+
})) as any
|
package/src/internal/error.ts
CHANGED
|
@@ -6,8 +6,8 @@ export const PlatformErrorTypeId: Error.PlatformErrorTypeId = Symbol.for(
|
|
|
6
6
|
"@effect/platform/Error/PlatformErrorTypeId"
|
|
7
7
|
) as Error.PlatformErrorTypeId
|
|
8
8
|
|
|
9
|
-
const make =
|
|
10
|
-
(props: Omit<A, Error.PlatformError.ProvidedFields>): A =>
|
|
9
|
+
const make =
|
|
10
|
+
<A extends Error.PlatformError>(tag: A["_tag"]) => (props: Omit<A, Error.PlatformError.ProvidedFields>): A =>
|
|
11
11
|
Data.struct({
|
|
12
12
|
[PlatformErrorTypeId]: PlatformErrorTypeId,
|
|
13
13
|
_tag: tag,
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import * as Effect from "@effect/io/Effect"
|
|
2
|
+
import type * as Body from "@effect/platform/Http/Body"
|
|
3
|
+
import * as Schema from "@effect/schema/Schema"
|
|
4
|
+
import type * as Stream_ from "@effect/stream/Stream"
|
|
5
|
+
|
|
6
|
+
/** @internal */
|
|
7
|
+
export const TypeId: Body.TypeId = Symbol.for(
|
|
8
|
+
"@effect/platform/Http/Body"
|
|
9
|
+
) as Body.TypeId
|
|
10
|
+
|
|
11
|
+
class EmptyImpl implements Body.Empty {
|
|
12
|
+
readonly [TypeId]: Body.TypeId = TypeId
|
|
13
|
+
readonly _tag = "Empty"
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** @internal */
|
|
17
|
+
export const empty: Body.Empty = new EmptyImpl()
|
|
18
|
+
|
|
19
|
+
class RawImpl implements Body.Raw {
|
|
20
|
+
readonly [TypeId]: Body.TypeId = TypeId
|
|
21
|
+
readonly _tag = "Raw"
|
|
22
|
+
constructor(
|
|
23
|
+
readonly body: unknown,
|
|
24
|
+
readonly contentType?: string,
|
|
25
|
+
readonly contentLength?: number
|
|
26
|
+
) {}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** @internal */
|
|
30
|
+
export const raw = (body: unknown, contentType?: string, contentLength?: number): Body.Raw =>
|
|
31
|
+
new RawImpl(body, contentType, contentLength)
|
|
32
|
+
|
|
33
|
+
class BytesImpl implements Body.Bytes {
|
|
34
|
+
readonly [TypeId]: Body.TypeId = TypeId
|
|
35
|
+
readonly _tag = "Bytes"
|
|
36
|
+
constructor(
|
|
37
|
+
readonly body: Uint8Array,
|
|
38
|
+
readonly contentType?: string
|
|
39
|
+
) {}
|
|
40
|
+
get contentLength(): number {
|
|
41
|
+
return this.body.length
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** @internal */
|
|
46
|
+
export const bytes = (body: Uint8Array, contentType?: string): Body.Bytes => new BytesImpl(body, contentType)
|
|
47
|
+
|
|
48
|
+
/** @internal */
|
|
49
|
+
export const text = (body: string, contentType?: string): Body.Bytes =>
|
|
50
|
+
bytes(new TextEncoder().encode(body), contentType)
|
|
51
|
+
|
|
52
|
+
class BytesEffectImpl implements Body.BytesEffect {
|
|
53
|
+
readonly [TypeId]: Body.TypeId = TypeId
|
|
54
|
+
readonly _tag = "BytesEffect"
|
|
55
|
+
constructor(
|
|
56
|
+
readonly body: Effect.Effect<never, unknown, Uint8Array>,
|
|
57
|
+
readonly contentType?: string
|
|
58
|
+
) {}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** @internal */
|
|
62
|
+
export const bytesEffect = (
|
|
63
|
+
body: Effect.Effect<never, unknown, Uint8Array>,
|
|
64
|
+
contentType?: string
|
|
65
|
+
): Body.BytesEffect => new BytesEffectImpl(body, contentType)
|
|
66
|
+
|
|
67
|
+
/** @internal */
|
|
68
|
+
export const json = (body: unknown): Body.BytesEffect =>
|
|
69
|
+
bytesEffect(
|
|
70
|
+
Effect.try(() => new TextEncoder().encode(JSON.stringify(body))),
|
|
71
|
+
"application/json"
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
/** @internal */
|
|
75
|
+
export const jsonSchema = <I, A>(schema: Schema.Schema<I, A>) => {
|
|
76
|
+
const encode = Schema.encode(schema)
|
|
77
|
+
return (body: A): Body.BytesEffect =>
|
|
78
|
+
bytesEffect(
|
|
79
|
+
Effect.flatMap(
|
|
80
|
+
encode(body),
|
|
81
|
+
(json) => Effect.try(() => new TextEncoder().encode(JSON.stringify(json)))
|
|
82
|
+
),
|
|
83
|
+
"application/json"
|
|
84
|
+
)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
class FormDataImpl implements Body.FormData {
|
|
88
|
+
readonly [TypeId]: Body.TypeId = TypeId
|
|
89
|
+
readonly _tag = "FormData"
|
|
90
|
+
constructor(
|
|
91
|
+
readonly formData: FormData
|
|
92
|
+
) {}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** @internal */
|
|
96
|
+
export const formData = (body: FormData): Body.FormData => new FormDataImpl(body)
|
|
97
|
+
|
|
98
|
+
class StreamImpl implements Body.Stream {
|
|
99
|
+
readonly [TypeId]: Body.TypeId = TypeId
|
|
100
|
+
readonly _tag = "Stream"
|
|
101
|
+
constructor(
|
|
102
|
+
readonly stream: Stream_.Stream<never, unknown, Uint8Array>,
|
|
103
|
+
readonly contentType?: string,
|
|
104
|
+
readonly contentLength?: number
|
|
105
|
+
) {}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** @internal */
|
|
109
|
+
export const stream = (
|
|
110
|
+
body: Stream_.Stream<never, unknown, Uint8Array>,
|
|
111
|
+
contentType?: string,
|
|
112
|
+
contentLength?: number
|
|
113
|
+
): Body.Stream => new StreamImpl(body, contentType, contentLength)
|