@effect/platform 0.11.4 → 0.12.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.
Files changed (201) hide show
  1. package/Command.d.ts +3 -2
  2. package/Command.d.ts.map +1 -1
  3. package/Command.js.map +1 -1
  4. package/FileSystem.d.ts +16 -9
  5. package/FileSystem.d.ts.map +1 -1
  6. package/FileSystem.js.map +1 -1
  7. package/Http/App.d.ts +18 -0
  8. package/Http/App.d.ts.map +1 -0
  9. package/Http/App.js +6 -0
  10. package/Http/App.js.map +1 -0
  11. package/Http/Body.d.ts +37 -14
  12. package/Http/Body.d.ts.map +1 -1
  13. package/Http/Body.js +17 -5
  14. package/Http/Body.js.map +1 -1
  15. package/Http/Client.d.ts +8 -2
  16. package/Http/Client.d.ts.map +1 -1
  17. package/Http/Client.js +10 -4
  18. package/Http/Client.js.map +1 -1
  19. package/Http/ClientRequest.d.ts +44 -1
  20. package/Http/ClientRequest.d.ts.map +1 -1
  21. package/Http/ClientRequest.js +21 -3
  22. package/Http/ClientRequest.js.map +1 -1
  23. package/Http/ClientResponse.d.ts +13 -1
  24. package/Http/ClientResponse.d.ts.map +1 -1
  25. package/Http/ClientResponse.js +14 -2
  26. package/Http/ClientResponse.js.map +1 -1
  27. package/Http/FormData.d.ts +97 -4
  28. package/Http/FormData.d.ts.map +1 -1
  29. package/Http/FormData.js +77 -2
  30. package/Http/FormData.js.map +1 -1
  31. package/Http/Headers.d.ts +29 -3
  32. package/Http/Headers.d.ts.map +1 -1
  33. package/Http/Headers.js +13 -1
  34. package/Http/Headers.js.map +1 -1
  35. package/Http/IncomingMessage.d.ts +26 -5
  36. package/Http/IncomingMessage.d.ts.map +1 -1
  37. package/Http/IncomingMessage.js +38 -3
  38. package/Http/IncomingMessage.js.map +1 -1
  39. package/Http/Middleware.d.ts +56 -0
  40. package/Http/Middleware.d.ts.map +1 -0
  41. package/Http/Middleware.js +46 -0
  42. package/Http/Middleware.js.map +1 -0
  43. package/Http/Router.d.ts +221 -0
  44. package/Http/Router.d.ts.map +1 -0
  45. package/Http/Router.js +148 -0
  46. package/Http/Router.js.map +1 -0
  47. package/Http/Server.d.ts +85 -0
  48. package/Http/Server.d.ts.map +1 -0
  49. package/Http/Server.js +34 -0
  50. package/Http/Server.js.map +1 -0
  51. package/Http/ServerError.d.ts +96 -0
  52. package/Http/ServerError.d.ts.map +1 -0
  53. package/Http/ServerError.js +40 -0
  54. package/Http/ServerError.js.map +1 -0
  55. package/Http/ServerRequest.d.ts +82 -0
  56. package/Http/ServerRequest.d.ts.map +1 -0
  57. package/Http/ServerRequest.js +66 -0
  58. package/Http/ServerRequest.js.map +1 -0
  59. package/Http/ServerResponse.d.ts +168 -0
  60. package/Http/ServerResponse.d.ts.map +1 -0
  61. package/Http/ServerResponse.js +116 -0
  62. package/Http/ServerResponse.js.map +1 -0
  63. package/Http/UrlParams.d.ts +20 -5
  64. package/Http/UrlParams.d.ts.map +1 -1
  65. package/Http/UrlParams.js.map +1 -1
  66. package/HttpServer.d.ts +44 -0
  67. package/HttpServer.d.ts.map +1 -0
  68. package/HttpServer.js +29 -0
  69. package/HttpServer.js.map +1 -0
  70. package/internal/command.js +9 -2
  71. package/internal/command.js.map +1 -1
  72. package/internal/fileSystem.js +15 -11
  73. package/internal/fileSystem.js.map +1 -1
  74. package/internal/http/body.js +28 -28
  75. package/internal/http/body.js.map +1 -1
  76. package/internal/http/client.d.ts.map +1 -1
  77. package/internal/http/client.js +41 -27
  78. package/internal/http/client.js.map +1 -1
  79. package/internal/http/clientRequest.js +22 -6
  80. package/internal/http/clientRequest.js.map +1 -1
  81. package/internal/http/clientResponse.js +15 -12
  82. package/internal/http/clientResponse.js.map +1 -1
  83. package/internal/http/formData.d.ts +8 -0
  84. package/internal/http/formData.d.ts.map +1 -0
  85. package/internal/http/formData.js +88 -0
  86. package/internal/http/formData.js.map +1 -0
  87. package/internal/http/middleware.d.ts +2 -0
  88. package/internal/http/middleware.d.ts.map +1 -0
  89. package/internal/http/middleware.js +43 -0
  90. package/internal/http/middleware.js.map +1 -0
  91. package/internal/http/router.d.ts +2 -0
  92. package/internal/http/router.d.ts.map +1 -0
  93. package/internal/http/router.js +187 -0
  94. package/internal/http/router.js.map +1 -0
  95. package/internal/http/server.d.ts +2 -0
  96. package/internal/http/server.d.ts.map +1 -0
  97. package/internal/http/server.js +30 -0
  98. package/internal/http/server.js.map +1 -0
  99. package/internal/http/serverError.d.ts +2 -0
  100. package/internal/http/serverError.d.ts.map +1 -0
  101. package/internal/http/serverError.js +30 -0
  102. package/internal/http/serverError.js.map +1 -0
  103. package/internal/http/serverRequest.d.ts +2 -0
  104. package/internal/http/serverRequest.d.ts.map +1 -0
  105. package/internal/http/serverRequest.js +57 -0
  106. package/internal/http/serverRequest.js.map +1 -0
  107. package/internal/http/serverResponse.d.ts +2 -0
  108. package/internal/http/serverResponse.d.ts.map +1 -0
  109. package/internal/http/serverResponse.js +109 -0
  110. package/internal/http/serverResponse.js.map +1 -0
  111. package/mjs/Command.mjs.map +1 -1
  112. package/mjs/FileSystem.mjs.map +1 -1
  113. package/mjs/Http/App.mjs +2 -0
  114. package/mjs/Http/App.mjs.map +1 -0
  115. package/mjs/Http/Body.mjs +12 -2
  116. package/mjs/Http/Body.mjs.map +1 -1
  117. package/mjs/Http/Client.mjs +6 -1
  118. package/mjs/Http/Client.mjs.map +1 -1
  119. package/mjs/Http/ClientRequest.mjs +16 -1
  120. package/mjs/Http/ClientRequest.mjs.map +1 -1
  121. package/mjs/Http/ClientResponse.mjs +11 -1
  122. package/mjs/Http/ClientResponse.mjs.map +1 -1
  123. package/mjs/Http/FormData.mjs +62 -1
  124. package/mjs/Http/FormData.mjs.map +1 -1
  125. package/mjs/Http/Headers.mjs +10 -0
  126. package/mjs/Http/Headers.mjs.map +1 -1
  127. package/mjs/Http/IncomingMessage.mjs +32 -1
  128. package/mjs/Http/IncomingMessage.mjs.map +1 -1
  129. package/mjs/Http/Middleware.mjs +32 -0
  130. package/mjs/Http/Middleware.mjs.map +1 -0
  131. package/mjs/Http/Router.mjs +117 -0
  132. package/mjs/Http/Router.mjs.map +1 -0
  133. package/mjs/Http/Server.mjs +22 -0
  134. package/mjs/Http/Server.mjs.map +1 -0
  135. package/mjs/Http/ServerError.mjs +27 -0
  136. package/mjs/Http/ServerError.mjs.map +1 -0
  137. package/mjs/Http/ServerRequest.mjs +48 -0
  138. package/mjs/Http/ServerRequest.mjs.map +1 -0
  139. package/mjs/Http/ServerResponse.mjs +90 -0
  140. package/mjs/Http/ServerResponse.mjs.map +1 -0
  141. package/mjs/Http/UrlParams.mjs.map +1 -1
  142. package/mjs/HttpServer.mjs +24 -0
  143. package/mjs/HttpServer.mjs.map +1 -0
  144. package/mjs/internal/command.mjs +9 -2
  145. package/mjs/internal/command.mjs.map +1 -1
  146. package/mjs/internal/fileSystem.mjs +15 -11
  147. package/mjs/internal/fileSystem.mjs.map +1 -1
  148. package/mjs/internal/http/body.mjs +23 -25
  149. package/mjs/internal/http/body.mjs.map +1 -1
  150. package/mjs/internal/http/client.mjs +37 -24
  151. package/mjs/internal/http/client.mjs.map +1 -1
  152. package/mjs/internal/http/clientRequest.mjs +16 -4
  153. package/mjs/internal/http/clientRequest.mjs.map +1 -1
  154. package/mjs/internal/http/clientResponse.mjs +15 -12
  155. package/mjs/internal/http/clientResponse.mjs.map +1 -1
  156. package/mjs/internal/http/formData.mjs +67 -0
  157. package/mjs/internal/http/formData.mjs.map +1 -0
  158. package/mjs/internal/http/middleware.mjs +29 -0
  159. package/mjs/internal/http/middleware.mjs.map +1 -0
  160. package/mjs/internal/http/router.mjs +155 -0
  161. package/mjs/internal/http/router.mjs.map +1 -0
  162. package/mjs/internal/http/server.mjs +17 -0
  163. package/mjs/internal/http/server.mjs.map +1 -0
  164. package/mjs/internal/http/serverError.mjs +17 -0
  165. package/mjs/internal/http/serverError.mjs.map +1 -0
  166. package/mjs/internal/http/serverRequest.mjs +41 -0
  167. package/mjs/internal/http/serverRequest.mjs.map +1 -0
  168. package/mjs/internal/http/serverResponse.mjs +82 -0
  169. package/mjs/internal/http/serverResponse.mjs.map +1 -0
  170. package/package.json +2 -1
  171. package/src/Command.ts +3 -2
  172. package/src/FileSystem.ts +20 -25
  173. package/src/Http/App.ts +19 -0
  174. package/src/Http/Body.ts +41 -14
  175. package/src/Http/Client.ts +13 -2
  176. package/src/Http/ClientRequest.ts +52 -2
  177. package/src/Http/ClientResponse.ts +13 -1
  178. package/src/Http/FormData.ts +121 -5
  179. package/src/Http/Headers.ts +37 -3
  180. package/src/Http/IncomingMessage.ts +46 -3
  181. package/src/Http/Middleware.ts +69 -0
  182. package/src/Http/Router.ts +342 -0
  183. package/src/Http/Server.ts +134 -0
  184. package/src/Http/ServerError.ts +111 -0
  185. package/src/Http/ServerRequest.ts +120 -0
  186. package/src/Http/ServerResponse.ts +202 -0
  187. package/src/Http/UrlParams.ts +20 -5
  188. package/src/HttpServer.ts +44 -0
  189. package/src/internal/command.ts +9 -2
  190. package/src/internal/fileSystem.ts +10 -7
  191. package/src/internal/http/body.ts +65 -39
  192. package/src/internal/http/client.ts +96 -76
  193. package/src/internal/http/clientRequest.ts +64 -4
  194. package/src/internal/http/clientResponse.ts +21 -13
  195. package/src/internal/http/formData.ts +140 -0
  196. package/src/internal/http/middleware.ts +72 -0
  197. package/src/internal/http/router.ts +298 -0
  198. package/src/internal/http/server.ts +80 -0
  199. package/src/internal/http/serverError.ts +26 -0
  200. package/src/internal/http/serverRequest.ts +71 -0
  201. 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
@@ -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 = dual<
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 = dual<
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 = dual<
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 = dual<
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 = dual<
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"
@@ -2,6 +2,7 @@ import * as Chunk from "@effect/data/Chunk"
2
2
  import { dual } from "@effect/data/Function"
3
3
  import * as HashMap from "@effect/data/HashMap"
4
4
  import * as Option from "@effect/data/Option"
5
+ import { pipeArguments } from "@effect/data/Pipeable"
5
6
  import type ReadonlyArray from "@effect/data/ReadonlyArray"
6
7
  import * as Effect from "@effect/io/Effect"
7
8
  import type * as Command from "@effect/platform/Command"
@@ -88,7 +89,10 @@ export const make = (command: string, ...args: Array<string>): Command.Command =
88
89
  stdout: "pipe",
89
90
  stderr: "pipe",
90
91
  gid: Option.none(),
91
- uid: Option.none()
92
+ uid: Option.none(),
93
+ pipe() {
94
+ return pipeArguments(this, arguments)
95
+ }
92
96
  })
93
97
 
94
98
  /** @internal */
@@ -99,7 +103,10 @@ export const pipeTo = dual<
99
103
  [CommandTypeId]: CommandTypeId,
100
104
  _tag: "PipedCommand",
101
105
  left: self,
102
- right: into
106
+ right: into,
107
+ pipe() {
108
+ return pipeArguments(this, arguments)
109
+ }
103
110
  }))
104
111
 
105
112
  /** @internal */
@@ -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,7 @@ 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: number | bigint) => typeof bytes === "bigint" ? bytes as Size_ : BigInt(bytes) as Size_
14
+ export const Size = (bytes: SizeInput) => typeof bytes === "bigint" ? bytes as Size_ : BigInt(bytes) as Size_
15
15
 
16
16
  /** @internal */
17
17
  export const make = (
@@ -69,10 +69,12 @@ export const make = (
69
69
  /** @internal */
70
70
  const stream = (file: File, {
71
71
  bufferSize = 4,
72
- bytesToRead,
73
- chunkSize = Size(64 * 1024)
74
- }: StreamOptions = {}) =>
75
- Stream.bufferChunks(
72
+ bytesToRead: bytesToRead_,
73
+ chunkSize: chunkSize_ = Size(64 * 1024)
74
+ }: StreamOptions = {}) => {
75
+ const bytesToRead = bytesToRead_ !== undefined ? Size(bytesToRead_) : undefined
76
+ const chunkSize = Size(chunkSize_)
77
+ return Stream.bufferChunks(
76
78
  Stream.unfoldEffect(BigInt(0), (totalBytesRead) => {
77
79
  if (bytesToRead !== undefined && bytesToRead <= totalBytesRead) {
78
80
  return Effect.succeed(Option.none())
@@ -83,9 +85,10 @@ const stream = (file: File, {
83
85
  : chunkSize
84
86
 
85
87
  return Effect.map(
86
- file.readAlloc(toRead as Size_),
88
+ file.readAlloc(toRead),
87
89
  Option.map((buf) => [buf, Size(totalBytesRead + BigInt(buf.length))] as const)
88
90
  )
89
91
  }),
90
92
  { capacity: bufferSize }
91
93
  )
94
+ }
@@ -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 = 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 = 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 BytesImpl implements Body.Bytes {
34
- readonly [TypeId]: Body.TypeId = TypeId
35
- readonly _tag = "Bytes"
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?: string
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 bytes = (body: Uint8Array, contentType?: string): Body.Bytes => new BytesImpl(body, contentType)
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.Bytes =>
50
- bytes(new TextEncoder().encode(body), contentType)
59
+ export const text = (body: string, contentType?: string): Body.Uint8Array =>
60
+ uint8Array(new TextEncoder().encode(body), contentType ?? "text/plain")
51
61
 
52
- class BytesEffectImpl implements Body.BytesEffect {
53
- readonly [TypeId]: Body.TypeId = TypeId
54
- readonly _tag = "BytesEffect"
62
+ class EffectBodyImpl implements Body.EffectBody {
63
+ readonly [TypeId]: Body.TypeId
64
+ readonly _tag = "Effect"
55
65
  constructor(
56
- readonly body: Effect.Effect<never, unknown, Uint8Array>,
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 bytesEffect = (
63
- body: Effect.Effect<never, unknown, Uint8Array>,
64
- contentType?: string
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 json = (body: unknown): Body.BytesEffect =>
69
- bytesEffect(
70
- Effect.try(() => new TextEncoder().encode(JSON.stringify(body))),
71
- "application/json"
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.BytesEffect =>
78
- bytesEffect(
79
- Effect.flatMap(
80
- encode(body),
81
- (json) => Effect.try(() => new TextEncoder().encode(JSON.stringify(json)))
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 = 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 = 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?: string,
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)