@effect/platform 0.68.5 → 0.69.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 (229) hide show
  1. package/HttpApiMiddleware/package.json +6 -0
  2. package/README.md +306 -233
  3. package/dist/cjs/Headers.js +7 -2
  4. package/dist/cjs/Headers.js.map +1 -1
  5. package/dist/cjs/HttpApi.js +90 -78
  6. package/dist/cjs/HttpApi.js.map +1 -1
  7. package/dist/cjs/HttpApiBuilder.js +243 -255
  8. package/dist/cjs/HttpApiBuilder.js.map +1 -1
  9. package/dist/cjs/HttpApiClient.js +64 -59
  10. package/dist/cjs/HttpApiClient.js.map +1 -1
  11. package/dist/cjs/HttpApiEndpoint.js +74 -109
  12. package/dist/cjs/HttpApiEndpoint.js.map +1 -1
  13. package/dist/cjs/HttpApiError.js +3 -4
  14. package/dist/cjs/HttpApiError.js.map +1 -1
  15. package/dist/cjs/HttpApiGroup.js +103 -100
  16. package/dist/cjs/HttpApiGroup.js.map +1 -1
  17. package/dist/cjs/HttpApiMiddleware.js +67 -0
  18. package/dist/cjs/HttpApiMiddleware.js.map +1 -0
  19. package/dist/cjs/HttpApiSchema.js +33 -7
  20. package/dist/cjs/HttpApiSchema.js.map +1 -1
  21. package/dist/cjs/HttpApiSecurity.js +2 -2
  22. package/dist/cjs/HttpApiSecurity.js.map +1 -1
  23. package/dist/cjs/HttpApiSwagger.js +3 -1
  24. package/dist/cjs/HttpApiSwagger.js.map +1 -1
  25. package/dist/cjs/HttpBody.js.map +1 -1
  26. package/dist/cjs/HttpIncomingMessage.js +5 -1
  27. package/dist/cjs/HttpIncomingMessage.js.map +1 -1
  28. package/dist/cjs/HttpServer.js +12 -1
  29. package/dist/cjs/HttpServer.js.map +1 -1
  30. package/dist/cjs/HttpServerRespondable.js +1 -1
  31. package/dist/cjs/HttpServerRespondable.js.map +1 -1
  32. package/dist/cjs/OpenApi.js +102 -63
  33. package/dist/cjs/OpenApi.js.map +1 -1
  34. package/dist/cjs/OpenApiJsonSchema.js +58 -47
  35. package/dist/cjs/OpenApiJsonSchema.js.map +1 -1
  36. package/dist/cjs/Transferable.js +2 -2
  37. package/dist/cjs/Transferable.js.map +1 -1
  38. package/dist/cjs/UrlParams.js +5 -1
  39. package/dist/cjs/UrlParams.js.map +1 -1
  40. package/dist/cjs/Worker.js.map +1 -1
  41. package/dist/cjs/WorkerError.js +1 -5
  42. package/dist/cjs/WorkerError.js.map +1 -1
  43. package/dist/cjs/WorkerRunner.js.map +1 -1
  44. package/dist/cjs/index.js +3 -1
  45. package/dist/cjs/internal/httpBody.js +1 -1
  46. package/dist/cjs/internal/httpBody.js.map +1 -1
  47. package/dist/cjs/internal/httpClientRequest.js.map +1 -1
  48. package/dist/cjs/internal/httpClientResponse.js +1 -1
  49. package/dist/cjs/internal/httpClientResponse.js.map +1 -1
  50. package/dist/cjs/internal/httpRouter.js +1 -1
  51. package/dist/cjs/internal/httpRouter.js.map +1 -1
  52. package/dist/cjs/internal/httpServer.js +7 -1
  53. package/dist/cjs/internal/httpServer.js.map +1 -1
  54. package/dist/cjs/internal/httpServerRequest.js +1 -1
  55. package/dist/cjs/internal/httpServerRequest.js.map +1 -1
  56. package/dist/cjs/internal/httpServerResponse.js.map +1 -1
  57. package/dist/cjs/internal/keyValueStore.js +1 -1
  58. package/dist/cjs/internal/keyValueStore.js.map +1 -1
  59. package/dist/cjs/internal/multipart.js +1 -1
  60. package/dist/cjs/internal/multipart.js.map +1 -1
  61. package/dist/cjs/internal/worker.js +6 -7
  62. package/dist/cjs/internal/worker.js.map +1 -1
  63. package/dist/cjs/internal/workerRunner.js +3 -4
  64. package/dist/cjs/internal/workerRunner.js.map +1 -1
  65. package/dist/dts/Headers.d.ts +4 -6
  66. package/dist/dts/Headers.d.ts.map +1 -1
  67. package/dist/dts/HttpApi.d.ts +64 -140
  68. package/dist/dts/HttpApi.d.ts.map +1 -1
  69. package/dist/dts/HttpApiBuilder.d.ts +84 -167
  70. package/dist/dts/HttpApiBuilder.d.ts.map +1 -1
  71. package/dist/dts/HttpApiClient.d.ts +34 -11
  72. package/dist/dts/HttpApiClient.d.ts.map +1 -1
  73. package/dist/dts/HttpApiEndpoint.d.ts +119 -273
  74. package/dist/dts/HttpApiEndpoint.d.ts.map +1 -1
  75. package/dist/dts/HttpApiError.d.ts +5 -2
  76. package/dist/dts/HttpApiError.d.ts.map +1 -1
  77. package/dist/dts/HttpApiGroup.d.ts +96 -194
  78. package/dist/dts/HttpApiGroup.d.ts.map +1 -1
  79. package/dist/dts/HttpApiMiddleware.d.ts +231 -0
  80. package/dist/dts/HttpApiMiddleware.d.ts.map +1 -0
  81. package/dist/dts/HttpApiSchema.d.ts +6 -2
  82. package/dist/dts/HttpApiSchema.d.ts.map +1 -1
  83. package/dist/dts/HttpApiSecurity.d.ts +1 -1
  84. package/dist/dts/HttpApiSecurity.d.ts.map +1 -1
  85. package/dist/dts/HttpApiSwagger.d.ts +2 -2
  86. package/dist/dts/HttpApiSwagger.d.ts.map +1 -1
  87. package/dist/dts/HttpBody.d.ts +2 -2
  88. package/dist/dts/HttpBody.d.ts.map +1 -1
  89. package/dist/dts/HttpClientRequest.d.ts +2 -2
  90. package/dist/dts/HttpClientRequest.d.ts.map +1 -1
  91. package/dist/dts/HttpClientResponse.d.ts +3 -3
  92. package/dist/dts/HttpClientResponse.d.ts.map +1 -1
  93. package/dist/dts/HttpIncomingMessage.d.ts +3 -3
  94. package/dist/dts/HttpIncomingMessage.d.ts.map +1 -1
  95. package/dist/dts/HttpRouter.d.ts +3 -3
  96. package/dist/dts/HttpRouter.d.ts.map +1 -1
  97. package/dist/dts/HttpServer.d.ts +15 -0
  98. package/dist/dts/HttpServer.d.ts.map +1 -1
  99. package/dist/dts/HttpServerRequest.d.ts +3 -3
  100. package/dist/dts/HttpServerRequest.d.ts.map +1 -1
  101. package/dist/dts/HttpServerRespondable.d.ts.map +1 -1
  102. package/dist/dts/HttpServerResponse.d.ts +2 -2
  103. package/dist/dts/HttpServerResponse.d.ts.map +1 -1
  104. package/dist/dts/KeyValueStore.d.ts +2 -2
  105. package/dist/dts/KeyValueStore.d.ts.map +1 -1
  106. package/dist/dts/Multipart.d.ts +3 -3
  107. package/dist/dts/Multipart.d.ts.map +1 -1
  108. package/dist/dts/OpenApi.d.ts +17 -39
  109. package/dist/dts/OpenApi.d.ts.map +1 -1
  110. package/dist/dts/OpenApiJsonSchema.d.ts +10 -5
  111. package/dist/dts/OpenApiJsonSchema.d.ts.map +1 -1
  112. package/dist/dts/Transferable.d.ts +4 -1
  113. package/dist/dts/Transferable.d.ts.map +1 -1
  114. package/dist/dts/UrlParams.d.ts +3 -6
  115. package/dist/dts/UrlParams.d.ts.map +1 -1
  116. package/dist/dts/Worker.d.ts +7 -8
  117. package/dist/dts/Worker.d.ts.map +1 -1
  118. package/dist/dts/WorkerError.d.ts +1 -1
  119. package/dist/dts/WorkerError.d.ts.map +1 -1
  120. package/dist/dts/WorkerRunner.d.ts +2 -3
  121. package/dist/dts/WorkerRunner.d.ts.map +1 -1
  122. package/dist/dts/index.d.ts +4 -0
  123. package/dist/dts/index.d.ts.map +1 -1
  124. package/dist/dts/internal/httpRouter.d.ts.map +1 -1
  125. package/dist/esm/Headers.js +7 -2
  126. package/dist/esm/Headers.js.map +1 -1
  127. package/dist/esm/HttpApi.js +88 -77
  128. package/dist/esm/HttpApi.js.map +1 -1
  129. package/dist/esm/HttpApiBuilder.js +236 -244
  130. package/dist/esm/HttpApiBuilder.js.map +1 -1
  131. package/dist/esm/HttpApiClient.js +64 -59
  132. package/dist/esm/HttpApiClient.js.map +1 -1
  133. package/dist/esm/HttpApiEndpoint.js +73 -106
  134. package/dist/esm/HttpApiEndpoint.js.map +1 -1
  135. package/dist/esm/HttpApiError.js +3 -4
  136. package/dist/esm/HttpApiError.js.map +1 -1
  137. package/dist/esm/HttpApiGroup.js +102 -99
  138. package/dist/esm/HttpApiGroup.js.map +1 -1
  139. package/dist/esm/HttpApiMiddleware.js +56 -0
  140. package/dist/esm/HttpApiMiddleware.js.map +1 -0
  141. package/dist/esm/HttpApiSchema.js +31 -5
  142. package/dist/esm/HttpApiSchema.js.map +1 -1
  143. package/dist/esm/HttpApiSecurity.js +1 -1
  144. package/dist/esm/HttpApiSecurity.js.map +1 -1
  145. package/dist/esm/HttpApiSwagger.js +4 -2
  146. package/dist/esm/HttpApiSwagger.js.map +1 -1
  147. package/dist/esm/HttpBody.js.map +1 -1
  148. package/dist/esm/HttpIncomingMessage.js +4 -1
  149. package/dist/esm/HttpIncomingMessage.js.map +1 -1
  150. package/dist/esm/HttpServer.js +11 -0
  151. package/dist/esm/HttpServer.js.map +1 -1
  152. package/dist/esm/HttpServerRespondable.js +1 -1
  153. package/dist/esm/HttpServerRespondable.js.map +1 -1
  154. package/dist/esm/OpenApi.js +97 -59
  155. package/dist/esm/OpenApi.js.map +1 -1
  156. package/dist/esm/OpenApiJsonSchema.js +56 -46
  157. package/dist/esm/OpenApiJsonSchema.js.map +1 -1
  158. package/dist/esm/Transferable.js +2 -2
  159. package/dist/esm/Transferable.js.map +1 -1
  160. package/dist/esm/UrlParams.js +4 -1
  161. package/dist/esm/UrlParams.js.map +1 -1
  162. package/dist/esm/Worker.js.map +1 -1
  163. package/dist/esm/WorkerError.js +1 -4
  164. package/dist/esm/WorkerError.js.map +1 -1
  165. package/dist/esm/WorkerRunner.js.map +1 -1
  166. package/dist/esm/index.js +4 -0
  167. package/dist/esm/index.js.map +1 -1
  168. package/dist/esm/internal/httpBody.js +1 -1
  169. package/dist/esm/internal/httpBody.js.map +1 -1
  170. package/dist/esm/internal/httpClientRequest.js.map +1 -1
  171. package/dist/esm/internal/httpClientResponse.js +1 -1
  172. package/dist/esm/internal/httpClientResponse.js.map +1 -1
  173. package/dist/esm/internal/httpRouter.js +1 -1
  174. package/dist/esm/internal/httpRouter.js.map +1 -1
  175. package/dist/esm/internal/httpServer.js +6 -0
  176. package/dist/esm/internal/httpServer.js.map +1 -1
  177. package/dist/esm/internal/httpServerRequest.js +1 -1
  178. package/dist/esm/internal/httpServerRequest.js.map +1 -1
  179. package/dist/esm/internal/httpServerResponse.js.map +1 -1
  180. package/dist/esm/internal/keyValueStore.js +1 -1
  181. package/dist/esm/internal/keyValueStore.js.map +1 -1
  182. package/dist/esm/internal/multipart.js +1 -1
  183. package/dist/esm/internal/multipart.js.map +1 -1
  184. package/dist/esm/internal/worker.js +6 -7
  185. package/dist/esm/internal/worker.js.map +1 -1
  186. package/dist/esm/internal/workerRunner.js +3 -4
  187. package/dist/esm/internal/workerRunner.js.map +1 -1
  188. package/package.json +10 -3
  189. package/src/Headers.ts +12 -4
  190. package/src/HttpApi.ts +183 -258
  191. package/src/HttpApiBuilder.ts +532 -481
  192. package/src/HttpApiClient.ts +163 -112
  193. package/src/HttpApiEndpoint.ts +443 -564
  194. package/src/HttpApiError.ts +4 -6
  195. package/src/HttpApiGroup.ts +277 -325
  196. package/src/HttpApiMiddleware.ts +318 -0
  197. package/src/HttpApiSchema.ts +39 -2
  198. package/src/HttpApiSecurity.ts +1 -1
  199. package/src/HttpApiSwagger.ts +3 -3
  200. package/src/HttpBody.ts +2 -2
  201. package/src/HttpClientRequest.ts +2 -2
  202. package/src/HttpClientResponse.ts +3 -3
  203. package/src/HttpIncomingMessage.ts +3 -3
  204. package/src/HttpRouter.ts +3 -3
  205. package/src/HttpServer.ts +21 -0
  206. package/src/HttpServerRequest.ts +3 -3
  207. package/src/HttpServerRespondable.ts +1 -1
  208. package/src/HttpServerResponse.ts +2 -2
  209. package/src/KeyValueStore.ts +2 -2
  210. package/src/Multipart.ts +3 -3
  211. package/src/OpenApi.ts +113 -104
  212. package/src/OpenApiJsonSchema.ts +67 -53
  213. package/src/Transferable.ts +2 -2
  214. package/src/UrlParams.ts +3 -3
  215. package/src/Worker.ts +7 -8
  216. package/src/WorkerError.ts +1 -1
  217. package/src/WorkerRunner.ts +2 -3
  218. package/src/index.ts +5 -0
  219. package/src/internal/httpBody.ts +2 -2
  220. package/src/internal/httpClientRequest.ts +2 -2
  221. package/src/internal/httpClientResponse.ts +3 -3
  222. package/src/internal/httpRouter.ts +2 -2
  223. package/src/internal/httpServer.ts +13 -0
  224. package/src/internal/httpServerRequest.ts +3 -3
  225. package/src/internal/httpServerResponse.ts +2 -2
  226. package/src/internal/keyValueStore.ts +1 -1
  227. package/src/internal/multipart.ts +3 -3
  228. package/src/internal/worker.ts +6 -7
  229. package/src/internal/workerRunner.ts +3 -4
@@ -1,16 +1,16 @@
1
1
  /**
2
2
  * @since 1.0.0
3
3
  */
4
- import * as Schema from "@effect/schema/Schema"
5
4
  import type { Brand } from "effect/Brand"
6
5
  import * as Context from "effect/Context"
7
6
  import type { Effect } from "effect/Effect"
8
- import { dual } from "effect/Function"
7
+ import * as HashSet from "effect/HashSet"
9
8
  import * as Option from "effect/Option"
10
9
  import { type Pipeable, pipeArguments } from "effect/Pipeable"
11
10
  import * as Predicate from "effect/Predicate"
12
- import type { Redacted } from "effect/Redacted"
11
+ import * as Schema from "effect/Schema"
13
12
  import type * as Types from "effect/Types"
13
+ import type * as HttpApiMiddleware from "./HttpApiMiddleware.js"
14
14
  import * as HttpApiSchema from "./HttpApiSchema.js"
15
15
  import type { HttpMethod } from "./HttpMethod.js"
16
16
  import * as HttpRouter from "./HttpRouter.js"
@@ -45,22 +45,189 @@ export interface HttpApiEndpoint<
45
45
  out Name extends string,
46
46
  out Method extends HttpMethod,
47
47
  in out Path = never,
48
+ in out UrlParams = never,
48
49
  in out Payload = never,
49
50
  in out Headers = never,
50
51
  in out Success = void,
51
52
  in out Error = never,
52
- out R = never
53
+ out R = never,
54
+ out RE = never
53
55
  > extends Pipeable {
54
56
  readonly [TypeId]: TypeId
55
57
  readonly name: Name
56
58
  readonly path: HttpRouter.PathInput
57
59
  readonly method: Method
58
60
  readonly pathSchema: Option.Option<Schema.Schema<Path, unknown, R>>
61
+ readonly urlParamsSchema: Option.Option<Schema.Schema<UrlParams, unknown, R>>
59
62
  readonly payloadSchema: Option.Option<Schema.Schema<Payload, unknown, R>>
60
63
  readonly headersSchema: Option.Option<Schema.Schema<Headers, unknown, R>>
61
64
  readonly successSchema: Schema.Schema<Success, unknown, R>
62
- readonly errorSchema: Schema.Schema<Error, unknown, R>
65
+ readonly errorSchema: Schema.Schema<Error, unknown, RE>
63
66
  readonly annotations: Context.Context<never>
67
+ readonly middlewares: HashSet.HashSet<HttpApiMiddleware.TagClassAny>
68
+
69
+ /**
70
+ * Add a schema for the success response of the endpoint. The status code
71
+ * will be inferred from the schema, otherwise it will default to 200.
72
+ */
73
+ addSuccess<S extends Schema.Schema.Any>(
74
+ schema: S,
75
+ annotations?: {
76
+ readonly status?: number | undefined
77
+ }
78
+ ): HttpApiEndpoint<
79
+ Name,
80
+ Method,
81
+ Path,
82
+ UrlParams,
83
+ Payload,
84
+ Headers,
85
+ Exclude<Success, void> | Schema.Schema.Type<S>,
86
+ Error,
87
+ R | Schema.Schema.Context<S>,
88
+ RE
89
+ >
90
+
91
+ /**
92
+ * Add an error response schema to the endpoint. The status code
93
+ * will be inferred from the schema, otherwise it will default to 500.
94
+ */
95
+ addError<E extends Schema.Schema.Any>(
96
+ schema: E,
97
+ annotations?: {
98
+ readonly status?: number | undefined
99
+ }
100
+ ): HttpApiEndpoint<
101
+ Name,
102
+ Method,
103
+ Path,
104
+ UrlParams,
105
+ Payload,
106
+ Headers,
107
+ Success,
108
+ Error | Schema.Schema.Type<E>,
109
+ R,
110
+ RE | Schema.Schema.Context<E>
111
+ >
112
+
113
+ /**
114
+ * Set the schema for the request body of the endpoint. The schema will be
115
+ * used to validate the request body before the handler is called.
116
+ *
117
+ * For endpoints with no request body, the payload will use the url search
118
+ * parameters.
119
+ *
120
+ * You can set a multipart schema to handle file uploads by using the
121
+ * `HttpApiSchema.Multipart` combinator.
122
+ */
123
+ setPayload<P extends Schema.Schema.Any>(
124
+ schema: P & HttpApiEndpoint.ValidatePayload<Method, P>
125
+ ): HttpApiEndpoint<
126
+ Name,
127
+ Method,
128
+ Path,
129
+ UrlParams,
130
+ Schema.Schema.Type<P>,
131
+ Headers,
132
+ Success,
133
+ Error,
134
+ R | Schema.Schema.Context<P>,
135
+ RE
136
+ >
137
+
138
+ /**
139
+ * Set the schema for the path parameters of the endpoint. The schema will be
140
+ * used to validate the path parameters before the handler is called.
141
+ */
142
+ setPath<Path extends Schema.Schema.Any>(
143
+ schema: Path & HttpApiEndpoint.ValidatePath<Path>
144
+ ): HttpApiEndpoint<
145
+ Name,
146
+ Method,
147
+ Schema.Schema.Type<Path>,
148
+ UrlParams,
149
+ Payload,
150
+ Headers,
151
+ Success,
152
+ Error,
153
+ R | Schema.Schema.Context<Path>,
154
+ RE
155
+ >
156
+
157
+ /**
158
+ * Set the schema for the url search parameters of the endpoint.
159
+ */
160
+ setUrlParams<UrlParams extends Schema.Schema.Any>(
161
+ schema: UrlParams & HttpApiEndpoint.ValidateUrlParams<UrlParams>
162
+ ): HttpApiEndpoint<
163
+ Name,
164
+ Method,
165
+ Path,
166
+ Schema.Schema.Type<UrlParams>,
167
+ Payload,
168
+ Headers,
169
+ Success,
170
+ Error,
171
+ R | Schema.Schema.Context<Path>,
172
+ RE
173
+ >
174
+
175
+ /**
176
+ * Set the schema for the headers of the endpoint. The schema will be
177
+ * used to validate the headers before the handler is called.
178
+ */
179
+ setHeaders<H extends Schema.Schema.Any>(
180
+ schema: H & HttpApiEndpoint.ValidateHeaders<H>
181
+ ): HttpApiEndpoint<
182
+ Name,
183
+ Method,
184
+ Path,
185
+ UrlParams,
186
+ Payload,
187
+ Schema.Schema.Type<H>,
188
+ Success,
189
+ Error,
190
+ R | Schema.Schema.Context<H>,
191
+ RE
192
+ >
193
+
194
+ /**
195
+ * Add a prefix to the path of the endpoint.
196
+ */
197
+ prefix(
198
+ prefix: HttpRouter.PathInput
199
+ ): HttpApiEndpoint<Name, Method, Path, UrlParams, Payload, Headers, Success, Error, R, RE>
200
+
201
+ /**
202
+ * Add an `HttpApiMiddleware` to the endpoint.
203
+ */
204
+ middleware<I extends HttpApiMiddleware.HttpApiMiddleware.AnyId, S>(middleware: Context.Tag<I, S>): HttpApiEndpoint<
205
+ Name,
206
+ Method,
207
+ Path,
208
+ UrlParams,
209
+ Payload,
210
+ Headers,
211
+ Success,
212
+ Error | HttpApiMiddleware.HttpApiMiddleware.Error<I>,
213
+ R | I,
214
+ RE | HttpApiMiddleware.HttpApiMiddleware.ErrorContext<I>
215
+ >
216
+
217
+ /**
218
+ * Add an annotation on the endpoint.
219
+ */
220
+ annotate<I, S>(
221
+ tag: Context.Tag<I, S>,
222
+ value: S
223
+ ): HttpApiEndpoint<Name, Method, Path, UrlParams, Payload, Headers, Success, Error, R, RE>
224
+
225
+ /**
226
+ * Merge the annotations of the endpoint with the provided context.
227
+ */
228
+ annotateContext<I>(
229
+ context: Context.Context<I>
230
+ ): HttpApiEndpoint<Name, Method, Path, UrlParams, Payload, Headers, Success, Error, R, RE>
64
231
  }
65
232
 
66
233
  /**
@@ -74,47 +241,47 @@ export declare namespace HttpApiEndpoint {
74
241
  */
75
242
  export interface Any extends Pipeable {
76
243
  readonly [TypeId]: TypeId
77
- readonly name: string
78
- readonly path: HttpRouter.PathInput
79
- readonly method: HttpMethod
80
- readonly pathSchema: Option.Option<Schema.Schema.Any>
81
- readonly payloadSchema: Option.Option<Schema.Schema.Any>
82
- readonly headersSchema: Option.Option<Schema.Schema.Any>
83
- readonly successSchema: Schema.Schema.Any
84
- readonly errorSchema: Schema.Schema.Any
85
- readonly annotations: Context.Context<never>
86
244
  }
87
245
 
88
246
  /**
89
247
  * @since 1.0.0
90
248
  * @category models
91
249
  */
92
- export interface All extends Pipeable {
93
- readonly [TypeId]: TypeId
94
- readonly name: string
95
- readonly path: HttpRouter.PathInput
96
- readonly method: HttpMethod
97
- readonly pathSchema: Option.Option<Schema.Schema.All>
98
- readonly payloadSchema: Option.Option<Schema.Schema.All>
99
- readonly headersSchema: Option.Option<Schema.Schema.All>
100
- readonly successSchema: Schema.Schema.Any
101
- readonly errorSchema: Schema.Schema.All
102
- readonly annotations: Context.Context<never>
103
- }
250
+ export interface AnyWithProps extends HttpApiEndpoint<string, HttpMethod, any, any, any, any, any, any, any> {}
104
251
 
105
252
  /**
106
253
  * @since 1.0.0
107
254
  * @category models
108
255
  */
109
- export type Success<Endpoint extends All> = Endpoint extends HttpApiEndpoint<
256
+ export type Name<Endpoint> = Endpoint extends HttpApiEndpoint<
110
257
  infer _Name,
111
258
  infer _Method,
112
259
  infer _Path,
260
+ infer _UrlParams,
113
261
  infer _Payload,
114
262
  infer _Headers,
115
263
  infer _Success,
116
264
  infer _Error,
117
- infer _R
265
+ infer _R,
266
+ infer _RE
267
+ > ? _Name
268
+ : never
269
+
270
+ /**
271
+ * @since 1.0.0
272
+ * @category models
273
+ */
274
+ export type Success<Endpoint extends Any> = Endpoint extends HttpApiEndpoint<
275
+ infer _Name,
276
+ infer _Method,
277
+ infer _Path,
278
+ infer _UrlParams,
279
+ infer _Payload,
280
+ infer _Headers,
281
+ infer _Success,
282
+ infer _Error,
283
+ infer _R,
284
+ infer _RE
118
285
  > ? _Success
119
286
  : never
120
287
 
@@ -122,15 +289,17 @@ export declare namespace HttpApiEndpoint {
122
289
  * @since 1.0.0
123
290
  * @category models
124
291
  */
125
- export type Error<Endpoint extends All> = Endpoint extends HttpApiEndpoint<
292
+ export type Error<Endpoint extends Any> = Endpoint extends HttpApiEndpoint<
126
293
  infer _Name,
127
294
  infer _Method,
128
295
  infer _Path,
296
+ infer _UrlParams,
129
297
  infer _Payload,
130
298
  infer _Headers,
131
299
  infer _Success,
132
300
  infer _Error,
133
- infer _R
301
+ infer _R,
302
+ infer _RE
134
303
  > ? _Error
135
304
  : never
136
305
 
@@ -138,15 +307,17 @@ export declare namespace HttpApiEndpoint {
138
307
  * @since 1.0.0
139
308
  * @category models
140
309
  */
141
- export type PathParsed<Endpoint extends All> = Endpoint extends HttpApiEndpoint<
310
+ export type PathParsed<Endpoint extends Any> = Endpoint extends HttpApiEndpoint<
142
311
  infer _Name,
143
312
  infer _Method,
144
313
  infer _Path,
314
+ infer _UrlParams,
145
315
  infer _Payload,
146
316
  infer _Headers,
147
317
  infer _Success,
148
318
  infer _Error,
149
- infer _R
319
+ infer _R,
320
+ infer _RE
150
321
  > ? _Path
151
322
  : never
152
323
 
@@ -154,15 +325,35 @@ export declare namespace HttpApiEndpoint {
154
325
  * @since 1.0.0
155
326
  * @category models
156
327
  */
157
- export type Payload<Endpoint extends All> = Endpoint extends HttpApiEndpoint<
328
+ export type UrlParams<Endpoint extends Any> = Endpoint extends HttpApiEndpoint<
158
329
  infer _Name,
159
330
  infer _Method,
160
331
  infer _Path,
332
+ infer _UrlParams,
161
333
  infer _Payload,
162
334
  infer _Headers,
163
335
  infer _Success,
164
336
  infer _Error,
165
- infer _R
337
+ infer _R,
338
+ infer _RE
339
+ > ? _UrlParams
340
+ : never
341
+
342
+ /**
343
+ * @since 1.0.0
344
+ * @category models
345
+ */
346
+ export type Payload<Endpoint extends Any> = Endpoint extends HttpApiEndpoint<
347
+ infer _Name,
348
+ infer _Method,
349
+ infer _Path,
350
+ infer _UrlParams,
351
+ infer _Payload,
352
+ infer _Headers,
353
+ infer _Success,
354
+ infer _Error,
355
+ infer _R,
356
+ infer _RE
166
357
  > ? _Payload
167
358
  : never
168
359
 
@@ -170,15 +361,17 @@ export declare namespace HttpApiEndpoint {
170
361
  * @since 1.0.0
171
362
  * @category models
172
363
  */
173
- export type Headers<Endpoint extends All> = Endpoint extends HttpApiEndpoint<
364
+ export type Headers<Endpoint extends Any> = Endpoint extends HttpApiEndpoint<
174
365
  infer _Name,
175
366
  infer _Method,
176
367
  infer _Path,
368
+ infer _UrlParams,
177
369
  infer _Payload,
178
370
  infer _Headers,
179
371
  infer _Success,
180
372
  infer _Error,
181
- infer _R
373
+ infer _R,
374
+ infer _RE
182
375
  > ? _Headers
183
376
  : never
184
377
 
@@ -186,19 +379,31 @@ export declare namespace HttpApiEndpoint {
186
379
  * @since 1.0.0
187
380
  * @category models
188
381
  */
189
- export type Request<Endpoint extends All> =
190
- & {
191
- readonly path: PathParsed<Endpoint>
192
- }
193
- & ([Payload<Endpoint>] extends [infer P] ? [P] extends [never] ? {} : { readonly payload: P } : {})
194
- & ([Headers<Endpoint>] extends [infer H] ? [H] extends [never] ? {} : { readonly headers: H } : {})
382
+ export type Request<Endpoint extends Any> = Endpoint extends HttpApiEndpoint<
383
+ infer _Name,
384
+ infer _Method,
385
+ infer _Path,
386
+ infer _UrlParams,
387
+ infer _Payload,
388
+ infer _Headers,
389
+ infer _Success,
390
+ infer _Error,
391
+ infer _R,
392
+ infer _RE
393
+ > ?
394
+ & ([_Path] extends [never] ? {} : { readonly path: _Path })
395
+ & ([_UrlParams] extends [never] ? {} : { readonly urlParams: _UrlParams })
396
+ & ([_Payload] extends [never] ? {} : { readonly payload: _Payload })
397
+ & ([_Headers] extends [never] ? {} : { readonly headers: _Headers })
398
+ : {}
195
399
 
196
400
  /**
197
401
  * @since 1.0.0
198
402
  * @category models
199
403
  */
200
- export type ClientRequest<Path, Payload, Headers> = (
404
+ export type ClientRequest<Path, UrlParams, Payload, Headers> = (
201
405
  & ([Path] extends [void] ? {} : { readonly path: Path })
406
+ & ([UrlParams] extends [never] ? {} : { readonly urlParams: UrlParams })
202
407
  & ([Headers] extends [never] ? {} : { readonly headers: Headers })
203
408
  & ([Payload] extends [never] ? {}
204
409
  : [Payload] extends [Brand<HttpApiSchema.MultipartTypeId>] ? { readonly payload: FormData }
@@ -213,11 +418,13 @@ export declare namespace HttpApiEndpoint {
213
418
  infer _Name,
214
419
  infer _Method,
215
420
  infer _Path,
421
+ infer _UrlParams,
216
422
  infer _Payload,
217
423
  infer _Headers,
218
424
  infer _Success,
219
425
  infer _Error,
220
- infer _R
426
+ infer _R,
427
+ infer _RE
221
428
  > ? _R
222
429
  : never
223
430
 
@@ -225,45 +432,53 @@ export declare namespace HttpApiEndpoint {
225
432
  * @since 1.0.0
226
433
  * @category models
227
434
  */
228
- export type Handler<Endpoint extends All, E, R> = (
229
- request: Types.Simplify<Request<Endpoint>>
230
- ) => Effect<Success<Endpoint>, E, R>
435
+ export type ErrorContext<Endpoint> = Endpoint extends HttpApiEndpoint<
436
+ infer _Name,
437
+ infer _Method,
438
+ infer _Path,
439
+ infer _UrlParams,
440
+ infer _Payload,
441
+ infer _Headers,
442
+ infer _Success,
443
+ infer _Error,
444
+ infer _R,
445
+ infer _RE
446
+ > ? _RE
447
+ : never
231
448
 
232
449
  /**
233
450
  * @since 1.0.0
234
451
  * @category models
235
452
  */
236
- export type HandlerRedacted<Endpoint extends All, E, R> = (
453
+ export type Handler<Endpoint extends Any, E, R> = (
237
454
  request: Types.Simplify<Request<Endpoint>>
238
- ) => Effect<readonly [Success<Endpoint>, Redacted], E, R>
455
+ ) => Effect<Success<Endpoint>, Error<Endpoint> | E, R>
239
456
 
240
457
  /**
241
458
  * @since 1.0.0
242
459
  * @category models
243
460
  */
244
- export type HandlerResponse<Endpoint extends All, E, R> = (
461
+ export type HandlerResponse<Endpoint extends Any, E, R> = (
245
462
  request: Types.Simplify<Request<Endpoint>>
246
- ) => Effect<HttpServerResponse, E, R>
463
+ ) => Effect<HttpServerResponse, Error<Endpoint> | E, R>
247
464
 
248
465
  /**
249
466
  * @since 1.0.0
250
467
  * @category models
251
468
  */
252
- export type WithName<Endpoints extends All, Name extends string> = Endpoints extends infer Endpoint
253
- ? Endpoint extends { readonly name: Name } ? Endpoint : never
254
- : never
469
+ export type WithName<Endpoints extends Any, Name extends string> = Extract<Endpoints, { readonly name: Name }>
255
470
 
256
471
  /**
257
472
  * @since 1.0.0
258
473
  * @category models
259
474
  */
260
- export type ExcludeName<Endpoints extends All, Name extends string> = Exclude<Endpoints, { readonly name: Name }>
475
+ export type ExcludeName<Endpoints extends Any, Name extends string> = Exclude<Endpoints, { readonly name: Name }>
261
476
 
262
477
  /**
263
478
  * @since 1.0.0
264
479
  * @category models
265
480
  */
266
- export type HandlerWithName<Endpoints extends All, Name extends string, E, R> = Handler<
481
+ export type HandlerWithName<Endpoints extends Any, Name extends string, E, R> = Handler<
267
482
  WithName<Endpoints, Name>,
268
483
  E,
269
484
  R
@@ -273,7 +488,7 @@ export declare namespace HttpApiEndpoint {
273
488
  * @since 1.0.0
274
489
  * @category models
275
490
  */
276
- export type HandlerResponseWithName<Endpoints extends All, Name extends string, E, R> = HandlerResponse<
491
+ export type HandlerResponseWithName<Endpoints extends Any, Name extends string, E, R> = HandlerResponse<
277
492
  WithName<Endpoints, Name>,
278
493
  E,
279
494
  R
@@ -283,31 +498,29 @@ export declare namespace HttpApiEndpoint {
283
498
  * @since 1.0.0
284
499
  * @category models
285
500
  */
286
- export type HandlerRedactedWithName<Endpoints extends All, Name extends string, E, R> = HandlerRedacted<
287
- WithName<Endpoints, Name>,
288
- E,
289
- R
290
- >
501
+ export type SuccessWithName<Endpoints extends Any, Name extends string> = Success<WithName<Endpoints, Name>>
291
502
 
292
503
  /**
293
504
  * @since 1.0.0
294
505
  * @category models
295
506
  */
296
- export type SuccessWithName<Endpoints extends All, Name extends string> = Success<WithName<Endpoints, Name>>
507
+ export type ErrorWithName<Endpoints extends Any, Name extends string> = Error<WithName<Endpoints, Name>>
297
508
 
298
509
  /**
299
510
  * @since 1.0.0
300
511
  * @category models
301
512
  */
302
- export type ErrorWithName<Endpoints extends All, Name extends string> = Error<WithName<Endpoints, Name>>
513
+ export type ContextWithName<Endpoints extends Any, Name extends string> = Context<WithName<Endpoints, Name>>
303
514
 
304
515
  /**
305
516
  * @since 1.0.0
306
517
  * @category models
307
518
  */
308
- export type ExcludeProvided<R> = Exclude<
519
+ export type ExcludeProvided<Endpoints extends Any, Name extends string, R> = Exclude<
309
520
  R,
310
- HttpRouter.HttpRouter.DefaultServices | HttpRouter.HttpRouter.Provided
521
+ | HttpRouter.HttpRouter.DefaultServices
522
+ | HttpRouter.HttpRouter.Provided
523
+ | HttpApiMiddleware.HttpApiMiddleware.ExtractProvides<ContextWithName<Endpoints, Name>>
311
524
  >
312
525
 
313
526
  /**
@@ -319,6 +532,15 @@ export declare namespace HttpApiEndpoint {
319
532
  : `Path schema must be encodeable to strings`
320
533
  : {}
321
534
 
535
+ /**
536
+ * @since 1.0.0
537
+ * @category models
538
+ */
539
+ export type ValidateUrlParams<S extends Schema.Schema.Any> = S extends Schema.Schema<infer _A, infer _I, infer _R>
540
+ ? [_I] extends [Readonly<Record<string, string | undefined>>] ? {}
541
+ : `UrlParams schema must be encodeable to strings`
542
+ : {}
543
+
322
544
  /**
323
545
  * @since 1.0.0
324
546
  * @category models
@@ -332,19 +554,163 @@ export declare namespace HttpApiEndpoint {
332
554
  * @since 1.0.0
333
555
  * @category models
334
556
  */
335
- export type ValidatePayload<Method extends HttpMethod, P extends Schema.Schema.All> = Method extends
557
+ export type ValidatePayload<Method extends HttpMethod, P extends Schema.Schema.Any> = Method extends
336
558
  HttpMethod.NoBody ?
337
559
  P extends Schema.Schema<infer _A, infer _I, infer _R>
338
560
  ? [_I] extends [Readonly<Record<string, string | ReadonlyArray<string> | undefined>>] ? {}
339
561
  : `'${Method}' payload must be encodeable to strings`
340
562
  : {}
341
563
  : {}
564
+
565
+ /**
566
+ * @since 1.0.0
567
+ * @category models
568
+ */
569
+ export type AddError<Endpoint extends Any, E, R> = Endpoint extends HttpApiEndpoint<
570
+ infer _Name,
571
+ infer _Method,
572
+ infer _Path,
573
+ infer _UrlParams,
574
+ infer _Payload,
575
+ infer _Headers,
576
+ infer _Success,
577
+ infer _Error,
578
+ infer _R,
579
+ infer _RE
580
+ > ? HttpApiEndpoint<
581
+ _Name,
582
+ _Method,
583
+ _Path,
584
+ _UrlParams,
585
+ _Payload,
586
+ _Headers,
587
+ _Success,
588
+ _Error | E,
589
+ _R,
590
+ _RE | R
591
+ > :
592
+ never
593
+
594
+ /**
595
+ * @since 1.0.0
596
+ * @category models
597
+ */
598
+ export type AddContext<Endpoint extends Any, R> = Endpoint extends HttpApiEndpoint<
599
+ infer _Name,
600
+ infer _Method,
601
+ infer _Path,
602
+ infer _UrlParams,
603
+ infer _Payload,
604
+ infer _Headers,
605
+ infer _Success,
606
+ infer _Error,
607
+ infer _R,
608
+ infer _RE
609
+ > ? HttpApiEndpoint<
610
+ _Name,
611
+ _Method,
612
+ _Path,
613
+ _UrlParams,
614
+ _Payload,
615
+ _Headers,
616
+ _Success,
617
+ _Error | HttpApiMiddleware.HttpApiMiddleware.Error<R>,
618
+ _R | R,
619
+ _RE | HttpApiMiddleware.HttpApiMiddleware.ErrorContext<R>
620
+ > :
621
+ never
342
622
  }
343
623
 
344
624
  const Proto = {
345
625
  [TypeId]: TypeId,
346
626
  pipe() {
347
627
  return pipeArguments(this, arguments)
628
+ },
629
+ addSuccess(
630
+ this: HttpApiEndpoint.AnyWithProps,
631
+ schema: Schema.Schema.Any,
632
+ annotations?: { readonly status?: number }
633
+ ) {
634
+ schema = schema.pipe(
635
+ Schema.annotations(HttpApiSchema.annotations({
636
+ status: annotations?.status ?? HttpApiSchema.getStatusSuccess(schema)
637
+ }))
638
+ )
639
+ return makeProto({
640
+ ...this,
641
+ successSchema: this.successSchema === HttpApiSchema.NoContent ?
642
+ schema :
643
+ HttpApiSchema.UnionUnify(this.successSchema, schema)
644
+ })
645
+ },
646
+ addError(this: HttpApiEndpoint.AnyWithProps, schema: Schema.Schema.Any, annotations?: { readonly status?: number }) {
647
+ return makeProto({
648
+ ...this,
649
+ errorSchema: HttpApiSchema.UnionUnify(
650
+ this.errorSchema,
651
+ schema.pipe(
652
+ Schema.annotations(HttpApiSchema.annotations({
653
+ status: annotations?.status ?? HttpApiSchema.getStatusError(schema)
654
+ }))
655
+ )
656
+ )
657
+ })
658
+ },
659
+ setPayload(this: HttpApiEndpoint.AnyWithProps, schema: Schema.Schema.Any) {
660
+ return makeProto({
661
+ ...this,
662
+ payloadSchema: Option.some(schema)
663
+ })
664
+ },
665
+ setPath(this: HttpApiEndpoint.AnyWithProps, schema: Schema.Schema.Any) {
666
+ return makeProto({
667
+ ...this,
668
+ pathSchema: Option.some(schema)
669
+ })
670
+ },
671
+ setUrlParams(this: HttpApiEndpoint.AnyWithProps, schema: Schema.Schema.Any) {
672
+ return makeProto({
673
+ ...this,
674
+ urlParamsSchema: Option.some(schema)
675
+ })
676
+ },
677
+ setHeaders(this: HttpApiEndpoint.AnyWithProps, schema: Schema.Schema.Any) {
678
+ return makeProto({
679
+ ...this,
680
+ headersSchema: Option.some(schema)
681
+ })
682
+ },
683
+ prefix(this: HttpApiEndpoint.AnyWithProps, prefix: HttpRouter.PathInput) {
684
+ return makeProto({
685
+ ...this,
686
+ path: HttpRouter.prefixPath(this.path, prefix) as HttpRouter.PathInput
687
+ })
688
+ },
689
+ middleware(this: HttpApiEndpoint.AnyWithProps, middleware: HttpApiMiddleware.TagClassAny) {
690
+ return makeProto({
691
+ ...this,
692
+ errorSchema: HttpApiSchema.UnionUnify(
693
+ this.errorSchema,
694
+ middleware.failure.pipe(
695
+ Schema.annotations(HttpApiSchema.annotations({
696
+ status: HttpApiSchema.getStatusError(middleware.failure)
697
+ }))
698
+ )
699
+ ),
700
+ middlewares: HashSet.add(this.middlewares, middleware)
701
+ })
702
+ },
703
+ annotate(this: HttpApiEndpoint.AnyWithProps, tag: Context.Tag<any, any>, value: any) {
704
+ return makeProto({
705
+ ...this,
706
+ annotations: Context.add(this.annotations, tag, value)
707
+ })
708
+ },
709
+ annotateContext(this: HttpApiEndpoint.AnyWithProps, context: Context.Context<any>) {
710
+ return makeProto({
711
+ ...this,
712
+ annotations: Context.merge(this.annotations, context)
713
+ })
348
714
  }
349
715
  }
350
716
 
@@ -352,22 +718,26 @@ const makeProto = <
352
718
  Name extends string,
353
719
  Method extends HttpMethod,
354
720
  Path,
721
+ UrlParams,
355
722
  Payload,
356
723
  Headers,
357
724
  Success,
358
725
  Error,
359
- R
726
+ R,
727
+ RE
360
728
  >(options: {
361
729
  readonly name: Name
362
730
  readonly path: HttpRouter.PathInput
363
731
  readonly method: Method
364
732
  readonly pathSchema: Option.Option<Schema.Schema<Path, unknown, R>>
733
+ readonly urlParamsSchema: Option.Option<Schema.Schema<UrlParams, unknown, R>>
365
734
  readonly payloadSchema: Option.Option<Schema.Schema<Payload, unknown, R>>
366
735
  readonly headersSchema: Option.Option<Schema.Schema<Headers, unknown, R>>
367
736
  readonly successSchema: Schema.Schema<Success, unknown, R>
368
- readonly errorSchema: Schema.Schema<Error, unknown, R>
737
+ readonly errorSchema: Schema.Schema<Error, unknown, RE>
369
738
  readonly annotations: Context.Context<never>
370
- }): HttpApiEndpoint<Name, Method, Path, Payload, Headers, Success, Error, R> =>
739
+ readonly middlewares: HashSet.HashSet<HttpApiMiddleware.TagClassAny>
740
+ }): HttpApiEndpoint<Name, Method, Path, Payload, Headers, Success, Error, R, RE> =>
371
741
  Object.assign(Object.create(Proto), options)
372
742
 
373
743
  /**
@@ -384,11 +754,13 @@ export const make = <Method extends HttpMethod>(method: Method) =>
384
754
  path,
385
755
  method,
386
756
  pathSchema: Option.none(),
757
+ urlParamsSchema: Option.none(),
387
758
  payloadSchema: Option.none(),
388
759
  headersSchema: Option.none(),
389
760
  successSchema: HttpApiSchema.NoContent as any,
390
761
  errorSchema: Schema.Never as any,
391
- annotations: Context.empty()
762
+ annotations: Context.empty(),
763
+ middlewares: HashSet.empty()
392
764
  })
393
765
 
394
766
  /**
@@ -435,496 +807,3 @@ export const del: <const Name extends string>(
435
807
  name: Name,
436
808
  path: HttpRouter.PathInput
437
809
  ) => HttpApiEndpoint<Name, "DELETE"> = make("DELETE")
438
-
439
- /**
440
- * Set the schema for the success response of the endpoint. The status code
441
- * will be inferred from the schema, otherwise it will default to 200.
442
- *
443
- * @since 1.0.0
444
- * @category result
445
- */
446
- export const setSuccess: {
447
- /**
448
- * Set the schema for the success response of the endpoint. The status code
449
- * will be inferred from the schema, otherwise it will default to 200.
450
- *
451
- * @since 1.0.0
452
- * @category result
453
- */
454
- <S extends Schema.Schema.Any>(
455
- schema: S,
456
- annotations?: {
457
- readonly status?: number | undefined
458
- }
459
- ): <
460
- Name extends string,
461
- Method extends HttpMethod,
462
- _Path,
463
- _P,
464
- _H,
465
- _S,
466
- _E,
467
- _R
468
- >(
469
- self: HttpApiEndpoint<Name, Method, _Path, _P, _H, _S, _E, _R>
470
- ) => HttpApiEndpoint<Name, Method, _Path, _P, _H, Schema.Schema.Type<S>, _E, _R | Schema.Schema.Context<S>>
471
- /**
472
- * Set the schema for the success response of the endpoint. The status code
473
- * will be inferred from the schema, otherwise it will default to 200.
474
- *
475
- * @since 1.0.0
476
- * @category result
477
- */
478
- <
479
- Name extends string,
480
- Method extends HttpMethod,
481
- _Path,
482
- _P,
483
- _H,
484
- _S,
485
- _E,
486
- _R,
487
- S extends Schema.Schema.Any
488
- >(
489
- self: HttpApiEndpoint<Name, Method, _Path, _P, _H, _S, _E, _R>,
490
- schema: S,
491
- annotations?: {
492
- readonly status?: number | undefined
493
- }
494
- ): HttpApiEndpoint<Name, Method, _Path, _P, _H, Schema.Schema.Type<S>, _E, _R | Schema.Schema.Context<S>>
495
- } = dual(
496
- (args) => isHttpApiEndpoint(args[0]),
497
- <
498
- Name extends string,
499
- Method extends HttpMethod,
500
- _Path,
501
- _P,
502
- _H,
503
- _S,
504
- _E,
505
- _R,
506
- S extends Schema.Schema.Any
507
- >(
508
- self: HttpApiEndpoint<Name, Method, _Path, _P, _H, _S, _E, _R>,
509
- schema: S,
510
- annotations?: {
511
- readonly status?: number | undefined
512
- }
513
- ): HttpApiEndpoint<Name, Method, _Path, _P, Schema.Schema.Type<S>, _E, _R | Schema.Schema.Context<S>> =>
514
- makeProto({
515
- ...self as any,
516
- successSchema: schema.annotations(HttpApiSchema.annotations({
517
- status: annotations?.status ?? HttpApiSchema.getStatusSuccess(schema)
518
- }))
519
- })
520
- )
521
-
522
- /**
523
- * Add an error response schema to the endpoint. The status code
524
- * will be inferred from the schema, otherwise it will default to 500.
525
- *
526
- * @since 1.0.0
527
- * @category result
528
- */
529
- export const addError: {
530
- /**
531
- * Add an error response schema to the endpoint. The status code
532
- * will be inferred from the schema, otherwise it will default to 500.
533
- *
534
- * @since 1.0.0
535
- * @category result
536
- */
537
- <E extends Schema.Schema.All>(
538
- schema: E,
539
- annotations?: {
540
- readonly status?: number | undefined
541
- }
542
- ): <
543
- Name extends string,
544
- Method extends HttpMethod,
545
- _Path,
546
- _P,
547
- _H,
548
- _S,
549
- _E,
550
- _R
551
- >(
552
- self: HttpApiEndpoint<Name, Method, _Path, _P, _H, _S, _E, _R>
553
- ) => HttpApiEndpoint<Name, Method, _Path, _P, _H, _S, _E | Schema.Schema.Type<E>, _R | Schema.Schema.Context<E>>
554
- /**
555
- * Add an error response schema to the endpoint. The status code
556
- * will be inferred from the schema, otherwise it will default to 500.
557
- *
558
- * @since 1.0.0
559
- * @category result
560
- */
561
- <
562
- Name extends string,
563
- Method extends HttpMethod,
564
- _Path,
565
- _P,
566
- _H,
567
- _S,
568
- _E,
569
- _R,
570
- E extends Schema.Schema.All
571
- >(
572
- self: HttpApiEndpoint<Name, Method, _Path, _P, _H, _S, _E, _R>,
573
- schema: E,
574
- annotations?: {
575
- readonly status?: number | undefined
576
- }
577
- ): HttpApiEndpoint<Name, Method, _Path, _P, _H, _S, _E | Schema.Schema.Type<E>, _R | Schema.Schema.Context<E>>
578
- } = dual(
579
- (args) => isHttpApiEndpoint(args[0]),
580
- <
581
- Name extends string,
582
- Method extends HttpMethod,
583
- _Path,
584
- _P,
585
- _H,
586
- _S,
587
- _E,
588
- _R,
589
- E extends Schema.Schema.All
590
- >(
591
- self: HttpApiEndpoint<Name, Method, _Path, _P, _H, _S, _E, _R>,
592
- schema: E,
593
- annotations?: {
594
- readonly status?: number | undefined
595
- }
596
- ): HttpApiEndpoint<Name, Method, _Path, _P, _H, _S, _E | Schema.Schema.Type<E>, _R | Schema.Schema.Context<E>> =>
597
- makeProto({
598
- ...self as any,
599
- errorSchema: HttpApiSchema.UnionUnify(
600
- self.errorSchema,
601
- schema.pipe(
602
- Schema.annotations(HttpApiSchema.annotations({
603
- status: annotations?.status ?? HttpApiSchema.getStatusError(schema)
604
- }))
605
- )
606
- )
607
- })
608
- )
609
-
610
- /**
611
- * Set the schema for the request body of the endpoint. The schema will be
612
- * used to validate the request body before the handler is called.
613
- *
614
- * For endpoints with no request body, the payload will use the url search
615
- * parameters.
616
- *
617
- * You can set a multipart schema to handle file uploads by using the
618
- * `HttpApiSchema.Multipart` combinator.
619
- *
620
- * @since 1.0.0
621
- * @category request
622
- */
623
- export const setPayload: {
624
- /**
625
- * Set the schema for the request body of the endpoint. The schema will be
626
- * used to validate the request body before the handler is called.
627
- *
628
- * For endpoints with no request body, the payload will use the url search
629
- * parameters.
630
- *
631
- * You can set a multipart schema to handle file uploads by using the
632
- * `HttpApiSchema.Multipart` combinator.
633
- *
634
- * @since 1.0.0
635
- * @category request
636
- */
637
- <Method extends HttpMethod, P extends Schema.Schema.All>(schema: P & HttpApiEndpoint.ValidatePayload<Method, P>): <
638
- Name extends string,
639
- _Path,
640
- _P,
641
- _H,
642
- _S,
643
- _E,
644
- _R
645
- >(
646
- self: HttpApiEndpoint<Name, Method, _Path, _P, _H, _S, _E, _R>
647
- ) => HttpApiEndpoint<Name, Method, _Path, Schema.Schema.Type<P>, _H, _S, _E, _R | Schema.Schema.Context<P>>
648
- /**
649
- * Set the schema for the request body of the endpoint. The schema will be
650
- * used to validate the request body before the handler is called.
651
- *
652
- * For endpoints with no request body, the payload will use the url search
653
- * parameters.
654
- *
655
- * You can set a multipart schema to handle file uploads by using the
656
- * `HttpApiSchema.Multipart` combinator.
657
- *
658
- * @since 1.0.0
659
- * @category request
660
- */
661
- <
662
- Name extends string,
663
- Method extends HttpMethod,
664
- _Path,
665
- _P,
666
- _H,
667
- _S,
668
- _E,
669
- _R,
670
- P extends Schema.Schema.All
671
- >(
672
- self: HttpApiEndpoint<Name, Method, _Path, _P, _H, _S, _E, _R>,
673
- schema: P & HttpApiEndpoint.ValidatePayload<Method, P>
674
- ): HttpApiEndpoint<Name, Method, _Path, Schema.Schema.Type<P>, _H, _S, _E, _R | Schema.Schema.Context<P>>
675
- } = dual(
676
- 2,
677
- <
678
- Name extends string,
679
- Method extends HttpMethod,
680
- _Path,
681
- _P,
682
- _H,
683
- _S,
684
- _E,
685
- _R,
686
- P extends Schema.Schema.All
687
- >(
688
- self: HttpApiEndpoint<Name, Method, _Path, _P, _H, _S, _E, _R>,
689
- schema: P & HttpApiEndpoint.ValidatePayload<Method, P>
690
- ): HttpApiEndpoint<Name, Method, _Path, Schema.Schema.Type<P>, _H, _S, _E, _R | Schema.Schema.Context<P>> =>
691
- makeProto({
692
- ...self as any,
693
- payloadSchema: Option.some(schema)
694
- })
695
- )
696
-
697
- /**
698
- * Set the schema for the path parameters of the endpoint. The schema will be
699
- * used to validate the path parameters before the handler is called.
700
- *
701
- * @since 1.0.0
702
- * @category request
703
- */
704
- export const setPath: {
705
- /**
706
- * Set the schema for the path parameters of the endpoint. The schema will be
707
- * used to validate the path parameters before the handler is called.
708
- *
709
- * @since 1.0.0
710
- * @category request
711
- */
712
- <Path extends Schema.Schema.Any>(schema: Path & HttpApiEndpoint.ValidatePath<Path>): <
713
- Name extends string,
714
- Method extends HttpMethod,
715
- _Path,
716
- _P,
717
- _H,
718
- _S,
719
- _E,
720
- _R
721
- >(
722
- self: HttpApiEndpoint<Name, Method, _Path, _P, _H, _S, _E, _R>
723
- ) => HttpApiEndpoint<Name, Method, Schema.Schema.Type<Path>, _P, _H, _S, _E, _R | Schema.Schema.Context<Path>>
724
- /**
725
- * Set the schema for the path parameters of the endpoint. The schema will be
726
- * used to validate the path parameters before the handler is called.
727
- *
728
- * @since 1.0.0
729
- * @category request
730
- */
731
- <
732
- Name extends string,
733
- Method extends HttpMethod,
734
- _Path,
735
- _P,
736
- _H,
737
- _S,
738
- _E,
739
- _R,
740
- Path extends Schema.Schema.Any
741
- >(
742
- self: HttpApiEndpoint<Name, Method, _Path, _P, _H, _S, _E, _R>,
743
- schema: Path & HttpApiEndpoint.ValidatePath<Path>
744
- ): HttpApiEndpoint<Name, Method, Schema.Schema.Type<Path>, _P, _H, _S, _E, _R | Schema.Schema.Context<Path>>
745
- } = dual(
746
- 2,
747
- <
748
- Name extends string,
749
- Method extends HttpMethod,
750
- _Path,
751
- _P,
752
- _H,
753
- _S,
754
- _E,
755
- _R,
756
- Path extends Schema.Schema.Any
757
- >(
758
- self: HttpApiEndpoint<Name, Method, _Path, _P, _H, _S, _E, _R>,
759
- schema: Path & HttpApiEndpoint.ValidatePath<Path>
760
- ): HttpApiEndpoint<Name, Method, Schema.Schema.Type<Path>, _P, _H, _S, _E, _R | Schema.Schema.Context<Path>> =>
761
- makeProto({
762
- ...self as any,
763
- pathSchema: Option.some(schema)
764
- })
765
- )
766
-
767
- /**
768
- * Set the schema for the headers of the endpoint. The schema will be
769
- * used to validate the headers before the handler is called.
770
- *
771
- * @since 1.0.0
772
- * @category request
773
- */
774
- export const setHeaders: {
775
- /**
776
- * Set the schema for the headers of the endpoint. The schema will be
777
- * used to validate the headers before the handler is called.
778
- *
779
- * @since 1.0.0
780
- * @category request
781
- */
782
- <Method extends HttpMethod, H extends Schema.Schema.Any>(schema: H & HttpApiEndpoint.ValidateHeaders<H>): <
783
- Name extends string,
784
- _Path,
785
- _P,
786
- _H,
787
- _S,
788
- _E,
789
- _R
790
- >(
791
- self: HttpApiEndpoint<Name, Method, _Path, _P, _H, _S, _E, _R>
792
- ) => HttpApiEndpoint<Name, Method, _Path, _P, Schema.Schema.Type<H>, _S, _E, _R | Schema.Schema.Context<H>>
793
- /**
794
- * Set the schema for the headers of the endpoint. The schema will be
795
- * used to validate the headers before the handler is called.
796
- *
797
- * @since 1.0.0
798
- * @category request
799
- */
800
- <
801
- Name extends string,
802
- Method extends HttpMethod,
803
- _Path,
804
- _P,
805
- _H,
806
- _S,
807
- _E,
808
- _R,
809
- H extends Schema.Schema.Any
810
- >(
811
- self: HttpApiEndpoint<Name, Method, _Path, _P, _H, _S, _E, _R>,
812
- schema: H & HttpApiEndpoint.ValidateHeaders<H>
813
- ): HttpApiEndpoint<Name, Method, _Path, _P, Schema.Schema.Type<H>, _S, _E, _R | Schema.Schema.Context<H>>
814
- } = dual(
815
- 2,
816
- <
817
- Name extends string,
818
- Method extends HttpMethod,
819
- _Path,
820
- _P,
821
- _H,
822
- _S,
823
- _E,
824
- _R,
825
- H extends Schema.Schema.Any
826
- >(
827
- self: HttpApiEndpoint<Name, Method, _Path, _P, _H, _S, _E, _R>,
828
- schema: H & HttpApiEndpoint.ValidateHeaders<H>
829
- ): HttpApiEndpoint<Name, Method, _Path, _P, Schema.Schema.Type<H>, _S, _E, _R | Schema.Schema.Context<H>> =>
830
- makeProto({
831
- ...self as any,
832
- headersSchema: Option.some(schema)
833
- })
834
- )
835
-
836
- /**
837
- * Add a prefix to the path of the endpoint.
838
- *
839
- * @since 1.0.0
840
- * @category request
841
- */
842
- export const prefix: {
843
- /**
844
- * Add a prefix to the path of the endpoint.
845
- *
846
- * @since 1.0.0
847
- * @category request
848
- */
849
- (prefix: HttpRouter.PathInput): <A extends HttpApiEndpoint.All>(self: A) => A
850
- /**
851
- * Add a prefix to the path of the endpoint.
852
- *
853
- * @since 1.0.0
854
- * @category request
855
- */
856
- <A extends HttpApiEndpoint.All>(self: A, prefix: HttpRouter.PathInput): A
857
- } = dual(2, <A extends HttpApiEndpoint.All>(self: A, prefix: HttpRouter.PathInput): A =>
858
- makeProto({
859
- ...self as any,
860
- path: HttpRouter.prefixPath(self.path, prefix)
861
- }) as A)
862
-
863
- /**
864
- * @since 1.0.0
865
- * @category reflection
866
- */
867
- export const schemaSuccess = <A extends HttpApiEndpoint.All>(
868
- self: A
869
- ): Option.Option<Schema.Schema<HttpApiEndpoint.Success<A>, unknown, HttpApiEndpoint.Context<A>>> =>
870
- HttpApiSchema.isVoid(self.successSchema.ast) ? Option.none() : Option.some(self.successSchema as any)
871
-
872
- /**
873
- * Merge the annotations of the endpoint with the provided context.
874
- *
875
- * @since 1.0.0
876
- * @category annotations
877
- */
878
- export const annotateMerge: {
879
- /**
880
- * Merge the annotations of the endpoint with the provided context.
881
- *
882
- * @since 1.0.0
883
- * @category annotations
884
- */
885
- <I>(context: Context.Context<I>): <A extends HttpApiEndpoint.All>(self: A) => A
886
- /**
887
- * Merge the annotations of the endpoint with the provided context.
888
- *
889
- * @since 1.0.0
890
- * @category annotations
891
- */
892
- <A extends HttpApiEndpoint.All, I>(self: A, context: Context.Context<I>): A
893
- } = dual(
894
- 2,
895
- <A extends HttpApiEndpoint.All, I>(self: A, context: Context.Context<I>): A =>
896
- makeProto({
897
- ...self as any,
898
- annotations: Context.merge(self.annotations, context)
899
- }) as A
900
- )
901
-
902
- /**
903
- * Add an annotation to the endpoint.
904
- *
905
- * @since 1.0.0
906
- * @category annotations
907
- */
908
- export const annotate: {
909
- /**
910
- * Add an annotation to the endpoint.
911
- *
912
- * @since 1.0.0
913
- * @category annotations
914
- */
915
- <I, S>(tag: Context.Tag<I, S>, value: S): <A extends HttpApiEndpoint.All>(self: A) => A
916
- /**
917
- * Add an annotation to the endpoint.
918
- *
919
- * @since 1.0.0
920
- * @category annotations
921
- */
922
- <A extends HttpApiEndpoint.All, I, S>(self: A, tag: Context.Tag<I, S>, value: S): A
923
- } = dual(
924
- 3,
925
- <A extends HttpApiEndpoint.All, I, S>(self: A, tag: Context.Tag<I, S>, value: S): A =>
926
- makeProto({
927
- ...self as any,
928
- annotations: Context.add(self.annotations, tag, value)
929
- }) as A
930
- )