@effect/platform 0.11.5 → 0.12.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/FileSystem.d.ts +43 -11
- package/FileSystem.d.ts.map +1 -1
- package/FileSystem.js +33 -3
- package/FileSystem.js.map +1 -1
- package/Http/App.d.ts +18 -0
- package/Http/App.d.ts.map +1 -0
- package/Http/App.js +6 -0
- package/Http/App.js.map +1 -0
- package/Http/Body.d.ts +37 -14
- package/Http/Body.d.ts.map +1 -1
- package/Http/Body.js +17 -5
- package/Http/Body.js.map +1 -1
- package/Http/Client.d.ts +2 -2
- package/Http/Client.d.ts.map +1 -1
- package/Http/Client.js +3 -3
- package/Http/Client.js.map +1 -1
- package/Http/ClientRequest.d.ts +44 -1
- package/Http/ClientRequest.d.ts.map +1 -1
- package/Http/ClientRequest.js +21 -3
- package/Http/ClientRequest.js.map +1 -1
- package/Http/ClientResponse.d.ts +13 -1
- package/Http/ClientResponse.d.ts.map +1 -1
- package/Http/ClientResponse.js +14 -2
- package/Http/ClientResponse.js.map +1 -1
- package/Http/FormData.d.ts +97 -4
- package/Http/FormData.d.ts.map +1 -1
- package/Http/FormData.js +77 -2
- package/Http/FormData.js.map +1 -1
- package/Http/Headers.d.ts +29 -3
- package/Http/Headers.d.ts.map +1 -1
- package/Http/Headers.js +13 -1
- package/Http/Headers.js.map +1 -1
- package/Http/IncomingMessage.d.ts +26 -5
- package/Http/IncomingMessage.d.ts.map +1 -1
- package/Http/IncomingMessage.js +38 -3
- package/Http/IncomingMessage.js.map +1 -1
- package/Http/Middleware.d.ts +56 -0
- package/Http/Middleware.d.ts.map +1 -0
- package/Http/Middleware.js +46 -0
- package/Http/Middleware.js.map +1 -0
- package/Http/Router.d.ts +221 -0
- package/Http/Router.d.ts.map +1 -0
- package/Http/Router.js +148 -0
- package/Http/Router.js.map +1 -0
- package/Http/Server.d.ts +85 -0
- package/Http/Server.d.ts.map +1 -0
- package/Http/Server.js +34 -0
- package/Http/Server.js.map +1 -0
- package/Http/ServerError.d.ts +96 -0
- package/Http/ServerError.d.ts.map +1 -0
- package/Http/ServerError.js +40 -0
- package/Http/ServerError.js.map +1 -0
- package/Http/ServerRequest.d.ts +82 -0
- package/Http/ServerRequest.d.ts.map +1 -0
- package/Http/ServerRequest.js +66 -0
- package/Http/ServerRequest.js.map +1 -0
- package/Http/ServerResponse.d.ts +168 -0
- package/Http/ServerResponse.d.ts.map +1 -0
- package/Http/ServerResponse.js +116 -0
- package/Http/ServerResponse.js.map +1 -0
- package/Http/UrlParams.d.ts +20 -5
- package/Http/UrlParams.d.ts.map +1 -1
- package/Http/UrlParams.js.map +1 -1
- package/HttpServer.d.ts +44 -0
- package/HttpServer.d.ts.map +1 -0
- package/HttpServer.js +29 -0
- package/HttpServer.js.map +1 -0
- package/internal/fileSystem.js +33 -12
- package/internal/fileSystem.js.map +1 -1
- package/internal/http/body.js +28 -28
- package/internal/http/body.js.map +1 -1
- package/internal/http/client.d.ts.map +1 -1
- package/internal/http/client.js +32 -26
- package/internal/http/client.js.map +1 -1
- package/internal/http/clientRequest.js +22 -6
- package/internal/http/clientRequest.js.map +1 -1
- package/internal/http/clientResponse.js +15 -12
- package/internal/http/clientResponse.js.map +1 -1
- package/internal/http/formData.d.ts +8 -0
- package/internal/http/formData.d.ts.map +1 -0
- package/internal/http/formData.js +88 -0
- package/internal/http/formData.js.map +1 -0
- package/internal/http/middleware.d.ts +2 -0
- package/internal/http/middleware.d.ts.map +1 -0
- package/internal/http/middleware.js +43 -0
- package/internal/http/middleware.js.map +1 -0
- package/internal/http/router.d.ts +2 -0
- package/internal/http/router.d.ts.map +1 -0
- package/internal/http/router.js +187 -0
- package/internal/http/router.js.map +1 -0
- package/internal/http/server.d.ts +2 -0
- package/internal/http/server.d.ts.map +1 -0
- package/internal/http/server.js +30 -0
- package/internal/http/server.js.map +1 -0
- package/internal/http/serverError.d.ts +2 -0
- package/internal/http/serverError.d.ts.map +1 -0
- package/internal/http/serverError.js +30 -0
- package/internal/http/serverError.js.map +1 -0
- package/internal/http/serverRequest.d.ts +2 -0
- package/internal/http/serverRequest.d.ts.map +1 -0
- package/internal/http/serverRequest.js +57 -0
- package/internal/http/serverRequest.js.map +1 -0
- package/internal/http/serverResponse.d.ts +2 -0
- package/internal/http/serverResponse.d.ts.map +1 -0
- package/internal/http/serverResponse.js +109 -0
- package/internal/http/serverResponse.js.map +1 -0
- package/mjs/FileSystem.mjs +26 -1
- package/mjs/FileSystem.mjs.map +1 -1
- package/mjs/Http/App.mjs +2 -0
- package/mjs/Http/App.mjs.map +1 -0
- package/mjs/Http/Body.mjs +12 -2
- package/mjs/Http/Body.mjs.map +1 -1
- package/mjs/Http/Client.mjs +1 -1
- package/mjs/Http/Client.mjs.map +1 -1
- package/mjs/Http/ClientRequest.mjs +16 -1
- package/mjs/Http/ClientRequest.mjs.map +1 -1
- package/mjs/Http/ClientResponse.mjs +11 -1
- package/mjs/Http/ClientResponse.mjs.map +1 -1
- package/mjs/Http/FormData.mjs +62 -1
- package/mjs/Http/FormData.mjs.map +1 -1
- package/mjs/Http/Headers.mjs +10 -0
- package/mjs/Http/Headers.mjs.map +1 -1
- package/mjs/Http/IncomingMessage.mjs +32 -1
- package/mjs/Http/IncomingMessage.mjs.map +1 -1
- package/mjs/Http/Middleware.mjs +32 -0
- package/mjs/Http/Middleware.mjs.map +1 -0
- package/mjs/Http/Router.mjs +117 -0
- package/mjs/Http/Router.mjs.map +1 -0
- package/mjs/Http/Server.mjs +22 -0
- package/mjs/Http/Server.mjs.map +1 -0
- package/mjs/Http/ServerError.mjs +27 -0
- package/mjs/Http/ServerError.mjs.map +1 -0
- package/mjs/Http/ServerRequest.mjs +48 -0
- package/mjs/Http/ServerRequest.mjs.map +1 -0
- package/mjs/Http/ServerResponse.mjs +90 -0
- package/mjs/Http/ServerResponse.mjs.map +1 -0
- package/mjs/Http/UrlParams.mjs.map +1 -1
- package/mjs/HttpServer.mjs +24 -0
- package/mjs/HttpServer.mjs.map +1 -0
- package/mjs/internal/fileSystem.mjs +27 -11
- package/mjs/internal/fileSystem.mjs.map +1 -1
- package/mjs/internal/http/body.mjs +23 -25
- package/mjs/internal/http/body.mjs.map +1 -1
- package/mjs/internal/http/client.mjs +30 -24
- package/mjs/internal/http/client.mjs.map +1 -1
- package/mjs/internal/http/clientRequest.mjs +16 -4
- package/mjs/internal/http/clientRequest.mjs.map +1 -1
- package/mjs/internal/http/clientResponse.mjs +15 -12
- package/mjs/internal/http/clientResponse.mjs.map +1 -1
- package/mjs/internal/http/formData.mjs +67 -0
- package/mjs/internal/http/formData.mjs.map +1 -0
- package/mjs/internal/http/middleware.mjs +29 -0
- package/mjs/internal/http/middleware.mjs.map +1 -0
- package/mjs/internal/http/router.mjs +155 -0
- package/mjs/internal/http/router.mjs.map +1 -0
- package/mjs/internal/http/server.mjs +17 -0
- package/mjs/internal/http/server.mjs.map +1 -0
- package/mjs/internal/http/serverError.mjs +17 -0
- package/mjs/internal/http/serverError.mjs.map +1 -0
- package/mjs/internal/http/serverRequest.mjs +41 -0
- package/mjs/internal/http/serverRequest.mjs.map +1 -0
- package/mjs/internal/http/serverResponse.mjs +82 -0
- package/mjs/internal/http/serverResponse.mjs.map +1 -0
- package/package.json +2 -1
- package/src/FileSystem.ts +52 -27
- package/src/Http/App.ts +19 -0
- package/src/Http/Body.ts +41 -14
- package/src/Http/Client.ts +6 -3
- package/src/Http/ClientRequest.ts +52 -2
- package/src/Http/ClientResponse.ts +13 -1
- package/src/Http/FormData.ts +121 -5
- package/src/Http/Headers.ts +37 -3
- package/src/Http/IncomingMessage.ts +46 -3
- package/src/Http/Middleware.ts +69 -0
- package/src/Http/Router.ts +342 -0
- package/src/Http/Server.ts +134 -0
- package/src/Http/ServerError.ts +111 -0
- package/src/Http/ServerRequest.ts +120 -0
- package/src/Http/ServerResponse.ts +202 -0
- package/src/Http/UrlParams.ts +20 -5
- package/src/HttpServer.ts +44 -0
- package/src/internal/fileSystem.ts +28 -7
- package/src/internal/http/body.ts +65 -39
- package/src/internal/http/client.ts +45 -36
- package/src/internal/http/clientRequest.ts +64 -4
- package/src/internal/http/clientResponse.ts +21 -13
- package/src/internal/http/formData.ts +140 -0
- package/src/internal/http/middleware.ts +72 -0
- package/src/internal/http/router.ts +298 -0
- package/src/internal/http/server.ts +80 -0
- package/src/internal/http/serverError.ts +26 -0
- package/src/internal/http/serverRequest.ts +71 -0
- package/src/internal/http/serverResponse.ts +255 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 1.0.0
|
|
3
|
+
*/
|
|
4
|
+
import type * as Context from "@effect/data/Context"
|
|
5
|
+
import type * as Effect from "@effect/io/Effect"
|
|
6
|
+
import type * as Scope from "@effect/io/Scope"
|
|
7
|
+
import type * as FileSystem from "@effect/platform/FileSystem"
|
|
8
|
+
import type * as FormData from "@effect/platform/Http/FormData"
|
|
9
|
+
import type * as Headers from "@effect/platform/Http/Headers"
|
|
10
|
+
import type * as IncomingMessage from "@effect/platform/Http/IncomingMessage"
|
|
11
|
+
import type { Method } from "@effect/platform/Http/Method"
|
|
12
|
+
import type * as Error from "@effect/platform/Http/ServerError"
|
|
13
|
+
import * as internal from "@effect/platform/internal/http/serverRequest"
|
|
14
|
+
import type * as Path from "@effect/platform/Path"
|
|
15
|
+
import type * as ParseResult from "@effect/schema/ParseResult"
|
|
16
|
+
import type * as Schema from "@effect/schema/Schema"
|
|
17
|
+
import type * as Stream from "@effect/stream/Stream"
|
|
18
|
+
|
|
19
|
+
export {
|
|
20
|
+
/**
|
|
21
|
+
* @since 1.0.0
|
|
22
|
+
* @category fiber refs
|
|
23
|
+
*/
|
|
24
|
+
maxBodySize
|
|
25
|
+
} from "@effect/platform/Http/IncomingMessage"
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @since 1.0.0
|
|
29
|
+
* @category type ids
|
|
30
|
+
*/
|
|
31
|
+
export const TypeId: unique symbol = internal.TypeId
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @since 1.0.0
|
|
35
|
+
* @category type ids
|
|
36
|
+
*/
|
|
37
|
+
export type TypeId = typeof TypeId
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @since 1.0.0
|
|
41
|
+
* @category models
|
|
42
|
+
*/
|
|
43
|
+
export interface ServerRequest extends IncomingMessage.IncomingMessage<Error.RequestError> {
|
|
44
|
+
readonly [TypeId]: TypeId
|
|
45
|
+
readonly url: string
|
|
46
|
+
readonly originalUrl: string
|
|
47
|
+
readonly method: Method
|
|
48
|
+
|
|
49
|
+
readonly formData: Effect.Effect<Scope.Scope | FileSystem.FileSystem | Path.Path, FormData.FormDataError, FormData>
|
|
50
|
+
readonly formDataStream: Stream.Stream<never, FormData.FormDataError, FormData.Part>
|
|
51
|
+
|
|
52
|
+
readonly setUrl: (url: string) => ServerRequest
|
|
53
|
+
readonly replaceHeaders: (headers: Headers.Headers) => ServerRequest
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @since 1.0.0
|
|
58
|
+
* @category context
|
|
59
|
+
*/
|
|
60
|
+
export const ServerRequest: Context.Tag<ServerRequest, ServerRequest> = internal.serverRequestTag
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* @since 1.0.0
|
|
64
|
+
* @category accessors
|
|
65
|
+
*/
|
|
66
|
+
export const formDataRecord: Effect.Effect<
|
|
67
|
+
Scope.Scope | FileSystem.FileSystem | Path.Path | ServerRequest,
|
|
68
|
+
FormData.FormDataError,
|
|
69
|
+
Record<string, string | Array<File>>
|
|
70
|
+
> = internal.formDataRecord
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @since 1.0.0
|
|
74
|
+
* @category schema
|
|
75
|
+
*/
|
|
76
|
+
export const schemaHeaders: <I extends Readonly<Record<string, string>>, A>(
|
|
77
|
+
schema: Schema.Schema<I, A>
|
|
78
|
+
) => Effect.Effect<ServerRequest, ParseResult.ParseError, A> = internal.schemaHeaders
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* @since 1.0.0
|
|
82
|
+
* @category schema
|
|
83
|
+
*/
|
|
84
|
+
export const schemaBodyJson: <I, A>(
|
|
85
|
+
schema: Schema.Schema<I, A>
|
|
86
|
+
) => Effect.Effect<ServerRequest, Error.RequestError | ParseResult.ParseError, A> = internal.schemaBodyJson
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* @since 1.0.0
|
|
90
|
+
* @category schema
|
|
91
|
+
*/
|
|
92
|
+
export const schemaBodyUrlParams: <I extends Readonly<Record<string, string>>, A>(
|
|
93
|
+
schema: Schema.Schema<I, A>
|
|
94
|
+
) => Effect.Effect<ServerRequest, Error.RequestError | ParseResult.ParseError, A> = internal.schemaBodyUrlParams
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @since 1.0.0
|
|
98
|
+
* @category schema
|
|
99
|
+
*/
|
|
100
|
+
export const schemaFormData: <I extends Readonly<Record<string, string | ReadonlyArray<File>>>, A>(
|
|
101
|
+
schema: Schema.Schema<I, A>
|
|
102
|
+
) => Effect.Effect<
|
|
103
|
+
ServerRequest | Scope.Scope | FileSystem.FileSystem | Path.Path,
|
|
104
|
+
FormData.FormDataError | ParseResult.ParseError,
|
|
105
|
+
A
|
|
106
|
+
> = internal.schemaFormData
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* @since 1.0.0
|
|
110
|
+
* @category schema
|
|
111
|
+
*/
|
|
112
|
+
export const schemaFormDataJson: <I, A>(
|
|
113
|
+
schema: Schema.Schema<I, A>
|
|
114
|
+
) => (
|
|
115
|
+
field: string
|
|
116
|
+
) => Effect.Effect<
|
|
117
|
+
ServerRequest | Scope.Scope | FileSystem.FileSystem | Path.Path,
|
|
118
|
+
Error.RequestError | FormData.FormDataError | ParseResult.ParseError,
|
|
119
|
+
A
|
|
120
|
+
> = internal.schemaFormDataJson
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 1.0.0
|
|
3
|
+
*/
|
|
4
|
+
import type { Pipeable } from "@effect/data/Pipeable"
|
|
5
|
+
import type * as Effect from "@effect/io/Effect"
|
|
6
|
+
import type * as PlatformError from "@effect/platform/Error"
|
|
7
|
+
import type * as FileSystem from "@effect/platform/FileSystem"
|
|
8
|
+
import type * as Body from "@effect/platform/Http/Body"
|
|
9
|
+
import type * as Headers from "@effect/platform/Http/Headers"
|
|
10
|
+
import type * as Error from "@effect/platform/Http/ServerError"
|
|
11
|
+
import type * as ServerRequest from "@effect/platform/Http/ServerRequest"
|
|
12
|
+
import type * as UrlParams from "@effect/platform/Http/UrlParams"
|
|
13
|
+
import * as internal from "@effect/platform/internal/http/serverResponse"
|
|
14
|
+
import type * as Schema from "@effect/schema/Schema"
|
|
15
|
+
import type * as Stream from "@effect/stream/Stream"
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @since 1.0.0
|
|
19
|
+
* @category type ids
|
|
20
|
+
*/
|
|
21
|
+
export const TypeId = Symbol.for("@effect/platform/Http/ServerResponse")
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @since 1.0.0
|
|
25
|
+
* @category type ids
|
|
26
|
+
*/
|
|
27
|
+
export type TypeId = typeof TypeId
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @since 1.0.0
|
|
31
|
+
* @category models
|
|
32
|
+
*/
|
|
33
|
+
export interface ServerResponse extends Pipeable {
|
|
34
|
+
readonly [TypeId]: TypeId
|
|
35
|
+
readonly status: number
|
|
36
|
+
readonly statusText?: string
|
|
37
|
+
readonly headers: Headers.Headers
|
|
38
|
+
readonly body: Body.Body
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @since 1.0.0
|
|
43
|
+
*/
|
|
44
|
+
export namespace ServerResponse {
|
|
45
|
+
/**
|
|
46
|
+
* @since 1.0.0
|
|
47
|
+
* @category models
|
|
48
|
+
*/
|
|
49
|
+
export interface NonEffectBody extends ServerResponse {
|
|
50
|
+
readonly body: Body.NonEffect
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @since 1.0.0
|
|
56
|
+
* @category models
|
|
57
|
+
*/
|
|
58
|
+
export interface Options {
|
|
59
|
+
readonly status?: number
|
|
60
|
+
readonly statusText?: string
|
|
61
|
+
readonly headers?: Headers.Headers
|
|
62
|
+
readonly contentType?: string
|
|
63
|
+
readonly contentLength?: number
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* @since 1.0.0
|
|
68
|
+
*/
|
|
69
|
+
export namespace Options {
|
|
70
|
+
/**
|
|
71
|
+
* @since 1.0.0
|
|
72
|
+
* @category models
|
|
73
|
+
*/
|
|
74
|
+
export interface WithContent extends Omit<Options, "contentType" | "contentLength"> {}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* @since 1.0.0
|
|
78
|
+
* @category models
|
|
79
|
+
*/
|
|
80
|
+
export interface WithContentType extends Omit<Options, "contentLength"> {}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* @since 1.0.0
|
|
85
|
+
*/
|
|
86
|
+
export const isServerResponse: (u: unknown) => u is ServerResponse = internal.isServerResponse
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* @since 1.0.0
|
|
90
|
+
*/
|
|
91
|
+
export const toNonEffectBody: (
|
|
92
|
+
self: ServerResponse
|
|
93
|
+
) => Effect.Effect<ServerRequest.ServerRequest, Error.ResponseError, ServerResponse.NonEffectBody> =
|
|
94
|
+
internal.toNonEffectBody
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @since 1.0.0
|
|
98
|
+
* @category constructors
|
|
99
|
+
*/
|
|
100
|
+
export const empty: (options?: Options.WithContent) => ServerResponse = internal.empty
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* @since 1.0.0
|
|
104
|
+
* @category constructors
|
|
105
|
+
*/
|
|
106
|
+
export const uint8Array: (body: Uint8Array, options?: Options.WithContentType) => ServerResponse = internal.uint8Array
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* @since 1.0.0
|
|
110
|
+
* @category constructors
|
|
111
|
+
*/
|
|
112
|
+
export const text: (body: string, options?: Options.WithContentType) => ServerResponse = internal.text
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* @since 1.0.0
|
|
116
|
+
* @category constructors
|
|
117
|
+
*/
|
|
118
|
+
export const json: (body: unknown, options?: Options.WithContent) => ServerResponse = internal.json
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* @since 1.0.0
|
|
122
|
+
* @category constructors
|
|
123
|
+
*/
|
|
124
|
+
export const schemaJson: <I, A>(
|
|
125
|
+
schema: Schema.Schema<I, A>
|
|
126
|
+
) => (body: A, options?: Options.WithContent) => ServerResponse = internal.schemaJson
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* @since 1.0.0
|
|
130
|
+
* @category constructors
|
|
131
|
+
*/
|
|
132
|
+
export const unsafeJson: (body: unknown, options?: Options.WithContent) => ServerResponse = internal.unsafeJson
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* @since 1.0.0
|
|
136
|
+
* @category constructors
|
|
137
|
+
*/
|
|
138
|
+
export const urlParams: (body: UrlParams.Input, options?: Options.WithContent) => ServerResponse = internal.urlParams
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* @since 1.0.0
|
|
142
|
+
* @category constructors
|
|
143
|
+
*/
|
|
144
|
+
export const effect: (
|
|
145
|
+
body: Effect.Effect<never, unknown, Body.NonEffect>,
|
|
146
|
+
options?: Options.WithContent
|
|
147
|
+
) => ServerResponse = internal.effect
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* @since 1.0.0
|
|
151
|
+
* @category constructors
|
|
152
|
+
*/
|
|
153
|
+
export const raw: (body: unknown, options?: Options) => ServerResponse = internal.raw
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* @since 1.0.0
|
|
157
|
+
* @category constructors
|
|
158
|
+
*/
|
|
159
|
+
export const formData: (body: FormData, options?: Options.WithContent) => ServerResponse = internal.formData
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* @since 1.0.0
|
|
163
|
+
* @category constructors
|
|
164
|
+
*/
|
|
165
|
+
export const stream: (body: Stream.Stream<never, unknown, Uint8Array>, options?: Options) => ServerResponse =
|
|
166
|
+
internal.stream
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* @since 1.0.0
|
|
170
|
+
* @category constructors
|
|
171
|
+
*/
|
|
172
|
+
export const file: (
|
|
173
|
+
path: string,
|
|
174
|
+
options?: Options & FileSystem.StreamOptions
|
|
175
|
+
) => Effect.Effect<FileSystem.FileSystem, PlatformError.PlatformError, ServerResponse> = internal.file
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* @since 1.0.0
|
|
179
|
+
* @category combinators
|
|
180
|
+
*/
|
|
181
|
+
export const setHeader: {
|
|
182
|
+
(key: string, value: string): (self: ServerResponse) => ServerResponse
|
|
183
|
+
(self: ServerResponse, key: string, value: string): ServerResponse
|
|
184
|
+
} = internal.setHeader
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* @since 1.0.0
|
|
188
|
+
* @category combinators
|
|
189
|
+
*/
|
|
190
|
+
export const setHeaders: {
|
|
191
|
+
(input: Headers.Input): (self: ServerResponse) => ServerResponse
|
|
192
|
+
(self: ServerResponse, input: Headers.Input): ServerResponse
|
|
193
|
+
} = internal.setHeaders
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* @since 1.0.0
|
|
197
|
+
* @category combinators
|
|
198
|
+
*/
|
|
199
|
+
export const setBody: {
|
|
200
|
+
(body: Body.Body): (self: ServerResponse) => ServerResponse
|
|
201
|
+
(self: ServerResponse, body: Body.Body): ServerResponse
|
|
202
|
+
} = internal.setBody
|
package/src/Http/UrlParams.ts
CHANGED
|
@@ -40,7 +40,10 @@ export const empty: UrlParams = Chunk.empty()
|
|
|
40
40
|
* @since 1.0.0
|
|
41
41
|
* @category combinators
|
|
42
42
|
*/
|
|
43
|
-
export const set
|
|
43
|
+
export const set: {
|
|
44
|
+
(key: string, value: string): (self: UrlParams) => UrlParams
|
|
45
|
+
(self: UrlParams, key: string, value: string): UrlParams
|
|
46
|
+
} = dual<
|
|
44
47
|
(key: string, value: string) => (self: UrlParams) => UrlParams,
|
|
45
48
|
(self: UrlParams, key: string, value: string) => UrlParams
|
|
46
49
|
>(3, (self, key, value) =>
|
|
@@ -53,7 +56,10 @@ export const set = dual<
|
|
|
53
56
|
* @since 1.0.0
|
|
54
57
|
* @category combinators
|
|
55
58
|
*/
|
|
56
|
-
export const setAll
|
|
59
|
+
export const setAll: {
|
|
60
|
+
(input: Input): (self: UrlParams) => UrlParams
|
|
61
|
+
(self: UrlParams, input: Input): UrlParams
|
|
62
|
+
} = dual<
|
|
57
63
|
(input: Input) => (self: UrlParams) => UrlParams,
|
|
58
64
|
(self: UrlParams, input: Input) => UrlParams
|
|
59
65
|
>(2, (self, input) => {
|
|
@@ -69,7 +75,10 @@ export const setAll = dual<
|
|
|
69
75
|
* @since 1.0.0
|
|
70
76
|
* @category combinators
|
|
71
77
|
*/
|
|
72
|
-
export const append
|
|
78
|
+
export const append: {
|
|
79
|
+
(key: string, value: string): (self: UrlParams) => UrlParams
|
|
80
|
+
(self: UrlParams, key: string, value: string): UrlParams
|
|
81
|
+
} = dual<
|
|
73
82
|
(key: string, value: string) => (self: UrlParams) => UrlParams,
|
|
74
83
|
(self: UrlParams, key: string, value: string) => UrlParams
|
|
75
84
|
>(3, (self, key, value) =>
|
|
@@ -82,7 +91,10 @@ export const append = dual<
|
|
|
82
91
|
* @since 1.0.0
|
|
83
92
|
* @category combinators
|
|
84
93
|
*/
|
|
85
|
-
export const appendAll
|
|
94
|
+
export const appendAll: {
|
|
95
|
+
(input: Input): (self: UrlParams) => UrlParams
|
|
96
|
+
(self: UrlParams, input: Input): UrlParams
|
|
97
|
+
} = dual<
|
|
86
98
|
(input: Input) => (self: UrlParams) => UrlParams,
|
|
87
99
|
(self: UrlParams, input: Input) => UrlParams
|
|
88
100
|
>(2, (self, input) =>
|
|
@@ -95,7 +107,10 @@ export const appendAll = dual<
|
|
|
95
107
|
* @since 1.0.0
|
|
96
108
|
* @category combinators
|
|
97
109
|
*/
|
|
98
|
-
export const remove
|
|
110
|
+
export const remove: {
|
|
111
|
+
(key: string): (self: UrlParams) => UrlParams
|
|
112
|
+
(self: UrlParams, key: string): UrlParams
|
|
113
|
+
} = dual<
|
|
99
114
|
(key: string) => (self: UrlParams) => UrlParams,
|
|
100
115
|
(self: UrlParams, key: string) => UrlParams
|
|
101
116
|
>(2, (self, key) => Chunk.filter(self, ([k]) => k !== key))
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 1.0.0
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @since 1.0.0
|
|
7
|
+
*/
|
|
8
|
+
export * as app from "@effect/platform/Http/App"
|
|
9
|
+
/**
|
|
10
|
+
* @since 1.0.0
|
|
11
|
+
*/
|
|
12
|
+
export * as middleware from "@effect/platform/Http/Middleware"
|
|
13
|
+
/**
|
|
14
|
+
* @since 1.0.0
|
|
15
|
+
*/
|
|
16
|
+
export * as request from "@effect/platform/Http/ServerRequest"
|
|
17
|
+
/**
|
|
18
|
+
* @since 1.0.0
|
|
19
|
+
*/
|
|
20
|
+
export * as response from "@effect/platform/Http/ServerResponse"
|
|
21
|
+
/**
|
|
22
|
+
* @since 1.0.0
|
|
23
|
+
*/
|
|
24
|
+
export * as error from "@effect/platform/Http/ServerError"
|
|
25
|
+
/**
|
|
26
|
+
* @since 1.0.0
|
|
27
|
+
*/
|
|
28
|
+
export * as body from "@effect/platform/Http/Body"
|
|
29
|
+
/**
|
|
30
|
+
* @since 1.0.0
|
|
31
|
+
*/
|
|
32
|
+
export * as formData from "@effect/platform/Http/FormData"
|
|
33
|
+
/**
|
|
34
|
+
* @since 1.0.0
|
|
35
|
+
*/
|
|
36
|
+
export * as headers from "@effect/platform/Http/Headers"
|
|
37
|
+
/**
|
|
38
|
+
* @since 1.0.0
|
|
39
|
+
*/
|
|
40
|
+
export * as router from "@effect/platform/Http/Router"
|
|
41
|
+
/**
|
|
42
|
+
* @since 1.0.0
|
|
43
|
+
*/
|
|
44
|
+
export * as urlParams from "@effect/platform/Http/UrlParams"
|
|
@@ -3,7 +3,7 @@ import { identity, pipe } from "@effect/data/Function"
|
|
|
3
3
|
import * as Option from "@effect/data/Option"
|
|
4
4
|
import * as Effect from "@effect/io/Effect"
|
|
5
5
|
import * as Error from "@effect/platform/Error"
|
|
6
|
-
import type { File, FileSystem, Size as Size_, StreamOptions } from "@effect/platform/FileSystem"
|
|
6
|
+
import type { File, FileSystem, Size as Size_, SizeInput, StreamOptions } from "@effect/platform/FileSystem"
|
|
7
7
|
import * as Sink from "@effect/stream/Sink"
|
|
8
8
|
import * as Stream from "@effect/stream/Stream"
|
|
9
9
|
|
|
@@ -11,7 +11,25 @@ import * as Stream from "@effect/stream/Stream"
|
|
|
11
11
|
export const tag = Tag<FileSystem>("@effect/platform/FileSystem")
|
|
12
12
|
|
|
13
13
|
/** @internal */
|
|
14
|
-
export const Size = (bytes:
|
|
14
|
+
export const Size = (bytes: SizeInput) => typeof bytes === "bigint" ? bytes as Size_ : BigInt(bytes) as Size_
|
|
15
|
+
|
|
16
|
+
/** @internal */
|
|
17
|
+
export const KiB = (n: number) => Size(n * 1024)
|
|
18
|
+
|
|
19
|
+
/** @internal */
|
|
20
|
+
export const MiB = (n: number) => Size(n * 1024 * 1024)
|
|
21
|
+
|
|
22
|
+
/** @internal */
|
|
23
|
+
export const GiB = (n: number) => Size(n * 1024 * 1024 * 1024)
|
|
24
|
+
|
|
25
|
+
/** @internal */
|
|
26
|
+
export const TiB = (n: number) => Size(n * 1024 * 1024 * 1024 * 1024)
|
|
27
|
+
|
|
28
|
+
const bigint1024 = BigInt(1024)
|
|
29
|
+
const bigintPiB = bigint1024 * bigint1024 * bigint1024 * bigint1024 * bigint1024
|
|
30
|
+
|
|
31
|
+
/** @internal */
|
|
32
|
+
export const PiB = (n: number) => Size(BigInt(n) * bigintPiB)
|
|
15
33
|
|
|
16
34
|
/** @internal */
|
|
17
35
|
export const make = (
|
|
@@ -69,10 +87,12 @@ export const make = (
|
|
|
69
87
|
/** @internal */
|
|
70
88
|
const stream = (file: File, {
|
|
71
89
|
bufferSize = 4,
|
|
72
|
-
bytesToRead,
|
|
73
|
-
chunkSize = Size(64 * 1024)
|
|
74
|
-
}: StreamOptions = {}) =>
|
|
75
|
-
|
|
90
|
+
bytesToRead: bytesToRead_,
|
|
91
|
+
chunkSize: chunkSize_ = Size(64 * 1024)
|
|
92
|
+
}: StreamOptions = {}) => {
|
|
93
|
+
const bytesToRead = bytesToRead_ !== undefined ? Size(bytesToRead_) : undefined
|
|
94
|
+
const chunkSize = Size(chunkSize_)
|
|
95
|
+
return Stream.bufferChunks(
|
|
76
96
|
Stream.unfoldEffect(BigInt(0), (totalBytesRead) => {
|
|
77
97
|
if (bytesToRead !== undefined && bytesToRead <= totalBytesRead) {
|
|
78
98
|
return Effect.succeed(Option.none())
|
|
@@ -83,9 +103,10 @@ const stream = (file: File, {
|
|
|
83
103
|
: chunkSize
|
|
84
104
|
|
|
85
105
|
return Effect.map(
|
|
86
|
-
file.readAlloc(toRead
|
|
106
|
+
file.readAlloc(toRead),
|
|
87
107
|
Option.map((buf) => [buf, Size(totalBytesRead + BigInt(buf.length))] as const)
|
|
88
108
|
)
|
|
89
109
|
}),
|
|
90
110
|
{ capacity: bufferSize }
|
|
91
111
|
)
|
|
112
|
+
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import * as Effect from "@effect/io/Effect"
|
|
2
|
+
import type * as PlatformError from "@effect/platform/Error"
|
|
3
|
+
import * as FileSystem from "@effect/platform/FileSystem"
|
|
2
4
|
import type * as Body from "@effect/platform/Http/Body"
|
|
3
5
|
import * as Schema from "@effect/schema/Schema"
|
|
4
6
|
import type * as Stream_ from "@effect/stream/Stream"
|
|
@@ -9,100 +11,124 @@ export const TypeId: Body.TypeId = Symbol.for(
|
|
|
9
11
|
) as Body.TypeId
|
|
10
12
|
|
|
11
13
|
class EmptyImpl implements Body.Empty {
|
|
12
|
-
readonly [TypeId]: Body.TypeId
|
|
14
|
+
readonly [TypeId]: Body.TypeId
|
|
13
15
|
readonly _tag = "Empty"
|
|
16
|
+
constructor() {
|
|
17
|
+
this[TypeId] = TypeId
|
|
18
|
+
}
|
|
14
19
|
}
|
|
15
20
|
|
|
16
21
|
/** @internal */
|
|
17
22
|
export const empty: Body.Empty = new EmptyImpl()
|
|
18
23
|
|
|
19
24
|
class RawImpl implements Body.Raw {
|
|
20
|
-
readonly [TypeId]: Body.TypeId
|
|
25
|
+
readonly [TypeId]: Body.TypeId
|
|
21
26
|
readonly _tag = "Raw"
|
|
22
27
|
constructor(
|
|
23
28
|
readonly body: unknown,
|
|
24
29
|
readonly contentType?: string,
|
|
25
30
|
readonly contentLength?: number
|
|
26
|
-
) {
|
|
31
|
+
) {
|
|
32
|
+
this[TypeId] = TypeId
|
|
33
|
+
}
|
|
27
34
|
}
|
|
28
35
|
|
|
29
36
|
/** @internal */
|
|
30
37
|
export const raw = (body: unknown, contentType?: string, contentLength?: number): Body.Raw =>
|
|
31
38
|
new RawImpl(body, contentType, contentLength)
|
|
32
39
|
|
|
33
|
-
class
|
|
34
|
-
readonly [TypeId]: Body.TypeId
|
|
35
|
-
readonly _tag = "
|
|
40
|
+
class Uint8ArrayImpl implements Body.Uint8Array {
|
|
41
|
+
readonly [TypeId]: Body.TypeId
|
|
42
|
+
readonly _tag = "Uint8Array"
|
|
36
43
|
constructor(
|
|
37
44
|
readonly body: Uint8Array,
|
|
38
|
-
readonly contentType
|
|
39
|
-
) {
|
|
45
|
+
readonly contentType: string
|
|
46
|
+
) {
|
|
47
|
+
this[TypeId] = TypeId
|
|
48
|
+
}
|
|
40
49
|
get contentLength(): number {
|
|
41
50
|
return this.body.length
|
|
42
51
|
}
|
|
43
52
|
}
|
|
44
53
|
|
|
45
54
|
/** @internal */
|
|
46
|
-
export const
|
|
55
|
+
export const uint8Array = (body: Uint8Array, contentType?: string): Body.Uint8Array =>
|
|
56
|
+
new Uint8ArrayImpl(body, contentType ?? "application/octet-stream")
|
|
47
57
|
|
|
48
58
|
/** @internal */
|
|
49
|
-
export const text = (body: string, contentType?: string): Body.
|
|
50
|
-
|
|
59
|
+
export const text = (body: string, contentType?: string): Body.Uint8Array =>
|
|
60
|
+
uint8Array(new TextEncoder().encode(body), contentType ?? "text/plain")
|
|
51
61
|
|
|
52
|
-
class
|
|
53
|
-
readonly [TypeId]: Body.TypeId
|
|
54
|
-
readonly _tag = "
|
|
62
|
+
class EffectBodyImpl implements Body.EffectBody {
|
|
63
|
+
readonly [TypeId]: Body.TypeId
|
|
64
|
+
readonly _tag = "Effect"
|
|
55
65
|
constructor(
|
|
56
|
-
readonly
|
|
66
|
+
readonly effect: Effect.Effect<never, unknown, Body.NonEffect>,
|
|
57
67
|
readonly contentType?: string
|
|
58
|
-
) {
|
|
68
|
+
) {
|
|
69
|
+
this[TypeId] = TypeId
|
|
70
|
+
}
|
|
59
71
|
}
|
|
60
72
|
|
|
61
73
|
/** @internal */
|
|
62
|
-
export const
|
|
63
|
-
body: Effect.Effect<never, unknown,
|
|
64
|
-
|
|
65
|
-
): Body.BytesEffect => new BytesEffectImpl(body, contentType)
|
|
74
|
+
export const effect = (
|
|
75
|
+
body: Effect.Effect<never, unknown, Body.NonEffect>
|
|
76
|
+
): Body.EffectBody => new EffectBodyImpl(body)
|
|
66
77
|
|
|
67
78
|
/** @internal */
|
|
68
|
-
export const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
79
|
+
export const unsafeJson = (body: unknown): Body.Uint8Array =>
|
|
80
|
+
uint8Array(new TextEncoder().encode(JSON.stringify(body)), "application/json")
|
|
81
|
+
|
|
82
|
+
/** @internal */
|
|
83
|
+
export const json = (body: unknown): Body.EffectBody => effect(Effect.try(() => unsafeJson(body)))
|
|
73
84
|
|
|
74
85
|
/** @internal */
|
|
75
86
|
export const jsonSchema = <I, A>(schema: Schema.Schema<I, A>) => {
|
|
76
87
|
const encode = Schema.encode(schema)
|
|
77
|
-
return (body: A): Body.
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
),
|
|
83
|
-
"application/json"
|
|
84
|
-
)
|
|
88
|
+
return (body: A): Body.EffectBody =>
|
|
89
|
+
effect(Effect.flatMap(
|
|
90
|
+
encode(body),
|
|
91
|
+
(json) => Effect.try(() => unsafeJson(json))
|
|
92
|
+
))
|
|
85
93
|
}
|
|
86
94
|
|
|
95
|
+
/** @internal */
|
|
96
|
+
export const file = (
|
|
97
|
+
path: string,
|
|
98
|
+
options?: FileSystem.StreamOptions & { readonly contentType?: string }
|
|
99
|
+
): Effect.Effect<FileSystem.FileSystem, PlatformError.PlatformError, Body.Stream> =>
|
|
100
|
+
Effect.flatMap(
|
|
101
|
+
FileSystem.FileSystem,
|
|
102
|
+
(fs) =>
|
|
103
|
+
Effect.map(
|
|
104
|
+
fs.stat(path),
|
|
105
|
+
(stat) => stream(fs.stream(path, options), options?.contentType, Number(stat.size))
|
|
106
|
+
)
|
|
107
|
+
)
|
|
108
|
+
|
|
87
109
|
class FormDataImpl implements Body.FormData {
|
|
88
|
-
readonly [TypeId]: Body.TypeId
|
|
110
|
+
readonly [TypeId]: Body.TypeId
|
|
89
111
|
readonly _tag = "FormData"
|
|
90
112
|
constructor(
|
|
91
113
|
readonly formData: FormData
|
|
92
|
-
) {
|
|
114
|
+
) {
|
|
115
|
+
this[TypeId] = TypeId
|
|
116
|
+
}
|
|
93
117
|
}
|
|
94
118
|
|
|
95
119
|
/** @internal */
|
|
96
120
|
export const formData = (body: FormData): Body.FormData => new FormDataImpl(body)
|
|
97
121
|
|
|
98
122
|
class StreamImpl implements Body.Stream {
|
|
99
|
-
readonly [TypeId]: Body.TypeId
|
|
123
|
+
readonly [TypeId]: Body.TypeId
|
|
100
124
|
readonly _tag = "Stream"
|
|
101
125
|
constructor(
|
|
102
126
|
readonly stream: Stream_.Stream<never, unknown, Uint8Array>,
|
|
103
|
-
readonly contentType
|
|
127
|
+
readonly contentType: string,
|
|
104
128
|
readonly contentLength?: number
|
|
105
|
-
) {
|
|
129
|
+
) {
|
|
130
|
+
this[TypeId] = TypeId
|
|
131
|
+
}
|
|
106
132
|
}
|
|
107
133
|
|
|
108
134
|
/** @internal */
|
|
@@ -110,4 +136,4 @@ export const stream = (
|
|
|
110
136
|
body: Stream_.Stream<never, unknown, Uint8Array>,
|
|
111
137
|
contentType?: string,
|
|
112
138
|
contentLength?: number
|
|
113
|
-
): Body.Stream => new StreamImpl(body, contentType, contentLength)
|
|
139
|
+
): Body.Stream => new StreamImpl(body, contentType ?? "application/octet-stream", contentLength)
|