effect 4.0.0-beta.92 → 4.0.0-beta.94

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 (162) hide show
  1. package/dist/Cause.d.ts +3 -1
  2. package/dist/Cause.d.ts.map +1 -1
  3. package/dist/Cause.js.map +1 -1
  4. package/dist/Config.d.ts +1 -1
  5. package/dist/Config.d.ts.map +1 -1
  6. package/dist/Config.js.map +1 -1
  7. package/dist/Effect.d.ts +130 -0
  8. package/dist/Effect.d.ts.map +1 -1
  9. package/dist/Effect.js +43 -0
  10. package/dist/Effect.js.map +1 -1
  11. package/dist/FileSystem.d.ts +7 -0
  12. package/dist/FileSystem.d.ts.map +1 -1
  13. package/dist/FileSystem.js +3 -0
  14. package/dist/FileSystem.js.map +1 -1
  15. package/dist/Layer.d.ts +1 -1
  16. package/dist/Layer.d.ts.map +1 -1
  17. package/dist/Layer.js +6 -3
  18. package/dist/Layer.js.map +1 -1
  19. package/dist/LayerMap.js +1 -1
  20. package/dist/LayerMap.js.map +1 -1
  21. package/dist/LayerRef.d.ts +252 -0
  22. package/dist/LayerRef.d.ts.map +1 -0
  23. package/dist/LayerRef.js +171 -0
  24. package/dist/LayerRef.js.map +1 -0
  25. package/dist/Schema.d.ts +74 -30
  26. package/dist/Schema.d.ts.map +1 -1
  27. package/dist/Schema.js +3 -0
  28. package/dist/Schema.js.map +1 -1
  29. package/dist/SchemaParser.d.ts +1 -1
  30. package/dist/SchemaParser.d.ts.map +1 -1
  31. package/dist/SchemaParser.js.map +1 -1
  32. package/dist/internal/core.js +1 -1
  33. package/dist/internal/effect.js +10 -6
  34. package/dist/internal/effect.js.map +1 -1
  35. package/dist/testing/TestSchema.d.ts +2 -2
  36. package/dist/testing/TestSchema.d.ts.map +1 -1
  37. package/dist/testing/TestSchema.js.map +1 -1
  38. package/dist/unstable/ai/Chat.d.ts +1 -1
  39. package/dist/unstable/ai/Chat.d.ts.map +1 -1
  40. package/dist/unstable/ai/LanguageModel.d.ts +2 -2
  41. package/dist/unstable/ai/LanguageModel.d.ts.map +1 -1
  42. package/dist/unstable/cli/Argument.d.ts +2 -2
  43. package/dist/unstable/cli/Argument.d.ts.map +1 -1
  44. package/dist/unstable/cli/Argument.js.map +1 -1
  45. package/dist/unstable/cli/Flag.d.ts +2 -2
  46. package/dist/unstable/cli/Flag.d.ts.map +1 -1
  47. package/dist/unstable/cli/Flag.js.map +1 -1
  48. package/dist/unstable/cli/Param.d.ts +2 -2
  49. package/dist/unstable/cli/Param.d.ts.map +1 -1
  50. package/dist/unstable/cli/Param.js.map +1 -1
  51. package/dist/unstable/cli/Primitive.js.map +1 -1
  52. package/dist/unstable/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
  53. package/dist/unstable/cluster/ClusterWorkflowEngine.js +1 -0
  54. package/dist/unstable/cluster/ClusterWorkflowEngine.js.map +1 -1
  55. package/dist/unstable/cluster/Entity.d.ts.map +1 -1
  56. package/dist/unstable/cluster/Entity.js +5 -3
  57. package/dist/unstable/cluster/Entity.js.map +1 -1
  58. package/dist/unstable/cluster/Sharding.d.ts.map +1 -1
  59. package/dist/unstable/cluster/Sharding.js +3 -1
  60. package/dist/unstable/cluster/Sharding.js.map +1 -1
  61. package/dist/unstable/cluster/internal/entityManager.js +3 -2
  62. package/dist/unstable/cluster/internal/entityManager.js.map +1 -1
  63. package/dist/unstable/cluster/internal/resourceMap.js +39 -14
  64. package/dist/unstable/cluster/internal/resourceMap.js.map +1 -1
  65. package/dist/unstable/encoding/Sse.d.ts +2 -2
  66. package/dist/unstable/encoding/Sse.d.ts.map +1 -1
  67. package/dist/unstable/http/HttpBody.d.ts +1 -1
  68. package/dist/unstable/http/HttpBody.d.ts.map +1 -1
  69. package/dist/unstable/http/HttpBody.js +1 -1
  70. package/dist/unstable/http/HttpBody.js.map +1 -1
  71. package/dist/unstable/http/HttpClient.js +2 -2
  72. package/dist/unstable/http/HttpClient.js.map +1 -1
  73. package/dist/unstable/http/HttpClientRequest.d.ts +5 -4
  74. package/dist/unstable/http/HttpClientRequest.d.ts.map +1 -1
  75. package/dist/unstable/http/HttpClientRequest.js +5 -4
  76. package/dist/unstable/http/HttpClientRequest.js.map +1 -1
  77. package/dist/unstable/http/HttpClientResponse.d.ts +1 -1
  78. package/dist/unstable/http/HttpClientResponse.d.ts.map +1 -1
  79. package/dist/unstable/http/HttpClientResponse.js.map +1 -1
  80. package/dist/unstable/http/HttpIncomingMessage.d.ts +2 -2
  81. package/dist/unstable/http/HttpIncomingMessage.d.ts.map +1 -1
  82. package/dist/unstable/http/HttpIncomingMessage.js.map +1 -1
  83. package/dist/unstable/http/HttpRouter.d.ts +4 -4
  84. package/dist/unstable/http/HttpRouter.d.ts.map +1 -1
  85. package/dist/unstable/http/HttpRouter.js.map +1 -1
  86. package/dist/unstable/http/HttpServerRequest.d.ts +8 -8
  87. package/dist/unstable/http/HttpServerRequest.d.ts.map +1 -1
  88. package/dist/unstable/http/HttpServerRequest.js.map +1 -1
  89. package/dist/unstable/http/HttpServerResponse.d.ts +1 -1
  90. package/dist/unstable/http/HttpServerResponse.d.ts.map +1 -1
  91. package/dist/unstable/http/HttpServerResponse.js.map +1 -1
  92. package/dist/unstable/http/Multipart.d.ts +2 -2
  93. package/dist/unstable/http/Multipart.d.ts.map +1 -1
  94. package/dist/unstable/http/Multipart.js.map +1 -1
  95. package/dist/unstable/http/Url.d.ts +29 -4
  96. package/dist/unstable/http/Url.d.ts.map +1 -1
  97. package/dist/unstable/http/Url.js +44 -2
  98. package/dist/unstable/http/Url.js.map +1 -1
  99. package/dist/unstable/http/UrlParams.d.ts +2 -28
  100. package/dist/unstable/http/UrlParams.d.ts.map +1 -1
  101. package/dist/unstable/http/UrlParams.js +4 -46
  102. package/dist/unstable/http/UrlParams.js.map +1 -1
  103. package/dist/unstable/httpapi/HttpApi.d.ts.map +1 -1
  104. package/dist/unstable/httpapi/HttpApi.js +2 -4
  105. package/dist/unstable/httpapi/HttpApi.js.map +1 -1
  106. package/dist/unstable/httpapi/HttpApiBuilder.d.ts.map +1 -1
  107. package/dist/unstable/httpapi/HttpApiBuilder.js +30 -15
  108. package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
  109. package/dist/unstable/httpapi/HttpApiClient.js.map +1 -1
  110. package/dist/unstable/httpapi/HttpApiEndpoint.d.ts +7 -7
  111. package/dist/unstable/httpapi/HttpApiEndpoint.d.ts.map +1 -1
  112. package/dist/unstable/httpapi/HttpApiSchema.d.ts +1 -1
  113. package/dist/unstable/httpapi/HttpApiSchema.d.ts.map +1 -1
  114. package/dist/unstable/observability/OtlpTracer.d.ts.map +1 -1
  115. package/dist/unstable/observability/OtlpTracer.js +4 -3
  116. package/dist/unstable/observability/OtlpTracer.js.map +1 -1
  117. package/dist/unstable/reactivity/Atom.d.ts +4 -4
  118. package/dist/unstable/reactivity/Atom.d.ts.map +1 -1
  119. package/dist/unstable/reactivity/Atom.js.map +1 -1
  120. package/package.json +1 -1
  121. package/src/Cause.ts +3 -1
  122. package/src/Config.ts +1 -1
  123. package/src/Effect.ts +131 -0
  124. package/src/FileSystem.ts +13 -0
  125. package/src/Layer.ts +6 -6
  126. package/src/LayerMap.ts +1 -1
  127. package/src/LayerRef.ts +379 -0
  128. package/src/Schema.ts +83 -33
  129. package/src/SchemaParser.ts +2 -2
  130. package/src/internal/core.ts +1 -1
  131. package/src/internal/effect.ts +33 -6
  132. package/src/testing/TestSchema.ts +2 -2
  133. package/src/unstable/ai/Chat.ts +1 -1
  134. package/src/unstable/ai/LanguageModel.ts +3 -3
  135. package/src/unstable/cli/Argument.ts +14 -7
  136. package/src/unstable/cli/Flag.ts +6 -3
  137. package/src/unstable/cli/Param.ts +6 -3
  138. package/src/unstable/cli/Primitive.ts +2 -2
  139. package/src/unstable/cluster/ClusterWorkflowEngine.ts +1 -0
  140. package/src/unstable/cluster/Entity.ts +13 -14
  141. package/src/unstable/cluster/Sharding.ts +134 -131
  142. package/src/unstable/cluster/internal/entityManager.ts +11 -9
  143. package/src/unstable/cluster/internal/resourceMap.ts +59 -25
  144. package/src/unstable/encoding/Sse.ts +3 -3
  145. package/src/unstable/http/HttpBody.ts +2 -2
  146. package/src/unstable/http/HttpClient.ts +2 -2
  147. package/src/unstable/http/HttpClientRequest.ts +8 -7
  148. package/src/unstable/http/HttpClientResponse.ts +2 -3
  149. package/src/unstable/http/HttpIncomingMessage.ts +4 -5
  150. package/src/unstable/http/HttpRouter.ts +8 -10
  151. package/src/unstable/http/HttpServerRequest.ts +20 -19
  152. package/src/unstable/http/HttpServerResponse.ts +2 -2
  153. package/src/unstable/http/Multipart.ts +3 -3
  154. package/src/unstable/http/Url.ts +62 -7
  155. package/src/unstable/http/UrlParams.ts +5 -58
  156. package/src/unstable/httpapi/HttpApi.ts +2 -4
  157. package/src/unstable/httpapi/HttpApiBuilder.ts +33 -21
  158. package/src/unstable/httpapi/HttpApiClient.ts +2 -2
  159. package/src/unstable/httpapi/HttpApiEndpoint.ts +7 -7
  160. package/src/unstable/httpapi/HttpApiSchema.ts +1 -1
  161. package/src/unstable/observability/OtlpTracer.ts +4 -3
  162. package/src/unstable/reactivity/Atom.ts +10 -7
@@ -80,15 +80,15 @@ export const decode = <IE, Done>(): Channel.Channel<
80
80
  * @since 4.0.0
81
81
  */
82
82
  export interface EventCodec extends
83
- Schema.Codec<
83
+ Schema.ConstraintCodec<
84
84
  any,
85
85
  {
86
86
  readonly id?: string | undefined
87
87
  readonly event?: string | undefined
88
88
  readonly data: string
89
89
  },
90
- any,
91
- any
90
+ unknown,
91
+ unknown
92
92
  >
93
93
  {}
94
94
 
@@ -335,8 +335,8 @@ export const jsonSchema = <S extends Schema.Constraint>(
335
335
  * @category constructors
336
336
  * @since 4.0.0
337
337
  */
338
- export const urlParams = (urlParams: UrlParams.UrlParams, contentType?: string): Uint8Array =>
339
- text(UrlParams.toString(urlParams), contentType ?? "application/x-www-form-urlencoded")
338
+ export const urlParams = (urlParams: UrlParams.Input, contentType?: string): Uint8Array =>
339
+ text(UrlParams.toString(UrlParams.fromInput(urlParams)), contentType ?? "application/x-www-form-urlencoded")
340
340
 
341
341
  /**
342
342
  * HTTP body variant backed by Web `FormData`.
@@ -40,7 +40,7 @@ import * as HttpClientResponse from "./HttpClientResponse.ts"
40
40
  import * as HttpIncomingMessage from "./HttpIncomingMessage.ts"
41
41
  import * as HttpMethod from "./HttpMethod.ts"
42
42
  import * as TraceContext from "./HttpTraceContext.ts"
43
- import * as UrlParams from "./UrlParams.ts"
43
+ import * as Url from "./Url.ts"
44
44
 
45
45
  const TypeId = "~effect/http/HttpClient"
46
46
 
@@ -790,7 +790,7 @@ export const make = (
790
790
  Effect.withFiber((fiber) => {
791
791
  const scopedController = scopedRequests.get(request)
792
792
  const controller = scopedController ?? new AbortController()
793
- const urlResult = UrlParams.makeUrl(request.url, request.urlParams, Option.getOrUndefined(request.hash))
793
+ const urlResult = Url.make(request.url, request.urlParams, Option.getOrUndefined(request.hash))
794
794
  if (Result.isFailure(urlResult)) {
795
795
  return Effect.fail(
796
796
  new Error.HttpClientError({
@@ -28,6 +28,7 @@ import * as Stream from "../../Stream.ts"
28
28
  import * as Headers from "./Headers.ts"
29
29
  import * as HttpBody from "./HttpBody.ts"
30
30
  import { hasBody, type HttpMethod } from "./HttpMethod.ts"
31
+ import * as Url from "./Url.ts"
31
32
  import * as UrlParams from "./UrlParams.ts"
32
33
 
33
34
  const TypeId = "~effect/http/HttpClientRequest"
@@ -116,7 +117,7 @@ const Proto = {
116
117
  export function makeWith(
117
118
  method: HttpMethod,
118
119
  url: string,
119
- urlParams: UrlParams.UrlParams,
120
+ urlParams: UrlParams.Input,
120
121
  hash: Option.Option<string>,
121
122
  headers: Headers.Headers,
122
123
  body: HttpBody.HttpBody
@@ -1180,7 +1181,7 @@ export const bodyFile: {
1180
1181
  * @since 4.0.0
1181
1182
  */
1182
1183
  export function toUrl(self: HttpClientRequest): Option.Option<URL> {
1183
- const r = UrlParams.makeUrl(self.url, self.urlParams, Option.getOrUndefined(self.hash))
1184
+ const r = Url.make(self.url, self.urlParams, Option.getOrUndefined(self.hash))
1184
1185
  if (Result.isSuccess(r)) {
1185
1186
  return Option.some(r.success)
1186
1187
  }
@@ -1230,8 +1231,8 @@ const parseContentLength = (contentLength: string | null): number | undefined =>
1230
1231
  export const toWebResult = (self: HttpClientRequest, options?: {
1231
1232
  readonly signal?: AbortSignal | undefined
1232
1233
  readonly context?: Context.Context<never> | undefined
1233
- }): Result.Result<Request, UrlParams.UrlParamsError> => {
1234
- const url = UrlParams.makeUrl(self.url, self.urlParams, Option.getOrUndefined(self.hash))
1234
+ }): Result.Result<Request, Url.UrlError> => {
1235
+ const url = Url.make(self.url, self.urlParams, Option.getOrUndefined(self.hash))
1235
1236
  if (Result.isFailure(url)) {
1236
1237
  return Result.fail(url.failure)
1237
1238
  }
@@ -1271,7 +1272,7 @@ export const toWebResult = (self: HttpClientRequest, options?: {
1271
1272
  }
1272
1273
  return Result.try({
1273
1274
  try: () => new Request(url.success, requestInit),
1274
- catch: (cause) => new UrlParams.UrlParamsError({ cause })
1275
+ catch: (cause) => new Url.UrlError({ cause })
1275
1276
  })
1276
1277
  }
1277
1278
 
@@ -1279,14 +1280,14 @@ const isReadableStream = (u: unknown): u is ReadableStream<Uint8Array> =>
1279
1280
  typeof ReadableStream !== "undefined" && u instanceof ReadableStream
1280
1281
 
1281
1282
  /**
1282
- * Converts an `HttpClientRequest` to a Web `Request`, failing with `UrlParamsError` when the request URL is invalid.
1283
+ * Converts an `HttpClientRequest` to a Web `Request`, failing with `UrlError` when the request URL is invalid.
1283
1284
  *
1284
1285
  * @category converting
1285
1286
  * @since 4.0.0
1286
1287
  */
1287
1288
  export const toWeb = (self: HttpClientRequest, options?: {
1288
1289
  readonly signal?: AbortSignal | undefined
1289
- }): Effect.Effect<Request, UrlParams.UrlParamsError> =>
1290
+ }): Effect.Effect<Request, Url.UrlError> =>
1290
1291
  Effect.contextWith((context) =>
1291
1292
  Effect.fromResult(toWebResult(self, {
1292
1293
  context: context,
@@ -93,10 +93,9 @@ export const schemaJson = <
93
93
  readonly headers?: Readonly<Record<string, string | undefined>> | undefined
94
94
  readonly body?: unknown
95
95
  },
96
- RD,
97
- RE
96
+ RD
98
97
  >(
99
- schema: Schema.Codec<A, I, RD, RE>,
98
+ schema: Schema.ConstraintCodec<A, I, RD, unknown>,
100
99
  options?: ParseOptions | undefined
101
100
  ) => {
102
101
  const decode = Schema.decodeEffect(Schema.toCodecJson(schema).annotate({ options }))
@@ -78,10 +78,9 @@ export const schemaBodyJson = <S extends Schema.Constraint>(schema: S, options?:
78
78
  export const schemaBodyUrlParams = <
79
79
  A,
80
80
  I extends Readonly<Record<string, string | ReadonlyArray<string> | undefined>>,
81
- RD,
82
- RE
81
+ RD
83
82
  >(
84
- schema: Schema.Codec<A, I, RD, RE>,
83
+ schema: Schema.ConstraintCodec<A, I, RD, unknown>,
85
84
  options?: ParseOptions | undefined
86
85
  ) => {
87
86
  const decode = UrlParams.schemaRecord.pipe(
@@ -98,8 +97,8 @@ export const schemaBodyUrlParams = <
98
97
  * @category schemas
99
98
  * @since 4.0.0
100
99
  */
101
- export const schemaHeaders = <A, I extends Readonly<Record<string, string | undefined>>, RD, RE>(
102
- schema: Schema.Codec<A, I, RD, RE>,
100
+ export const schemaHeaders = <A, I extends Readonly<Record<string, string | undefined>>, RD>(
101
+ schema: Schema.ConstraintCodec<A, I, RD, unknown>,
103
102
  options?: ParseOptions | undefined
104
103
  ) => {
105
104
  const decode = Schema.decodeUnknownEffect(schema)
@@ -313,10 +313,9 @@ export const schemaJson = <
313
313
  readonly searchParams: Readonly<Record<string, string | ReadonlyArray<string> | undefined>>
314
314
  readonly body: any
315
315
  }>,
316
- RD,
317
- RE
316
+ RD
318
317
  >(
319
- schema: Schema.Codec<A, I, RD, RE>,
318
+ schema: Schema.ConstraintCodec<A, I, RD, unknown>,
320
319
  options?: ParseOptions | undefined
321
320
  ): Effect.Effect<
322
321
  A,
@@ -368,10 +367,9 @@ export const schemaNoBody = <
368
367
  readonly pathParams: Readonly<Record<string, string | undefined>>
369
368
  readonly searchParams: Readonly<Record<string, string | ReadonlyArray<string> | undefined>>
370
369
  }>,
371
- RD,
372
- RE
370
+ RD
373
371
  >(
374
- schema: Schema.Codec<A, I, RD, RE>,
372
+ schema: Schema.ConstraintCodec<A, I, RD, unknown>,
375
373
  options?: ParseOptions | undefined
376
374
  ): Effect.Effect<
377
375
  A,
@@ -410,8 +408,8 @@ export const schemaNoBody = <
410
408
  * @category schemas
411
409
  * @since 4.0.0
412
410
  */
413
- export const schemaParams = <A, I extends Readonly<Record<string, string | ReadonlyArray<string> | undefined>>, RD, RE>(
414
- schema: Schema.Codec<A, I, RD, RE>,
411
+ export const schemaParams = <A, I extends Readonly<Record<string, string | ReadonlyArray<string> | undefined>>, RD>(
412
+ schema: Schema.ConstraintCodec<A, I, RD, unknown>,
415
413
  options?: ParseOptions | undefined
416
414
  ): Effect.Effect<A, Schema.SchemaError, HttpServerRequest.ParsedSearchParams | RouteContext | RD> => {
417
415
  const parse = Schema.decodeUnknownEffect(schema)
@@ -429,8 +427,8 @@ export const schemaParams = <A, I extends Readonly<Record<string, string | Reado
429
427
  * @category schemas
430
428
  * @since 4.0.0
431
429
  */
432
- export const schemaPathParams = <A, I extends Readonly<Record<string, string | undefined>>, RD, RE>(
433
- schema: Schema.Codec<A, I, RD, RE>,
430
+ export const schemaPathParams = <A, I extends Readonly<Record<string, string | undefined>>, RD>(
431
+ schema: Schema.ConstraintCodec<A, I, RD, unknown>,
434
432
  options?: ParseOptions | undefined
435
433
  ): Effect.Effect<A, Schema.SchemaError, RouteContext | RD> => {
436
434
  const parse = Schema.decodeUnknownEffect(schema)
@@ -191,8 +191,8 @@ export const upgradeChannel = <IE = never>(): Channel.Channel<
191
191
  * @category schemas
192
192
  * @since 4.0.0
193
193
  */
194
- export const schemaCookies = <A, I extends Readonly<Record<string, string | undefined>>, RD, RE>(
195
- schema: Schema.Codec<A, I, RD, RE>,
194
+ export const schemaCookies = <A, I extends Readonly<Record<string, string | undefined>>, RD>(
195
+ schema: Schema.ConstraintCodec<A, I, RD, unknown>,
196
196
  options?: ParseOptions | undefined
197
197
  ): Effect.Effect<A, Schema.SchemaError, RD | HttpServerRequest> => {
198
198
  const parse = Schema.decodeUnknownEffect(schema)
@@ -205,8 +205,8 @@ export const schemaCookies = <A, I extends Readonly<Record<string, string | unde
205
205
  * @category schemas
206
206
  * @since 4.0.0
207
207
  */
208
- export const schemaHeaders = <A, I extends Readonly<Record<string, string | undefined>>, RD, RE>(
209
- schema: Schema.Codec<A, I, RD, RE>,
208
+ export const schemaHeaders = <A, I extends Readonly<Record<string, string | undefined>>, RD>(
209
+ schema: Schema.ConstraintCodec<A, I, RD, unknown>,
210
210
  options?: ParseOptions | undefined
211
211
  ): Effect.Effect<A, Schema.SchemaError, HttpServerRequest | RD> => {
212
212
  const parse = Schema.decodeUnknownEffect(schema)
@@ -222,10 +222,9 @@ export const schemaHeaders = <A, I extends Readonly<Record<string, string | unde
222
222
  export const schemaSearchParams = <
223
223
  A,
224
224
  I extends Readonly<Record<string, string | ReadonlyArray<string> | undefined>>,
225
- RD,
226
- RE
225
+ RD
227
226
  >(
228
- schema: Schema.Codec<A, I, RD, RE>,
227
+ schema: Schema.ConstraintCodec<A, I, RD, unknown>,
229
228
  options?: ParseOptions | undefined
230
229
  ): Effect.Effect<A, Schema.SchemaError, ParsedSearchParams | RD> => {
231
230
  const parse = Schema.decodeUnknownEffect(schema)
@@ -242,8 +241,8 @@ export const schemaSearchParams = <
242
241
  * @category schemas
243
242
  * @since 4.0.0
244
243
  */
245
- export const schemaBodyJson = <A, I, RD, RE>(
246
- schema: Schema.Codec<A, I, RD, RE>,
244
+ export const schemaBodyJson = <A, RD>(
245
+ schema: Schema.ConstraintDecoder<A, RD>,
247
246
  options?: ParseOptions | undefined
248
247
  ): Effect.Effect<A, HttpServerError | Schema.SchemaError, HttpServerRequest | RD> => {
249
248
  const parse = HttpIncomingMessage.schemaBodyJson(schema, options)
@@ -265,12 +264,15 @@ const isMultipart = (request: HttpServerRequest) =>
265
264
  * @category schemas
266
265
  * @since 4.0.0
267
266
  */
268
- export const schemaBodyForm = <A, I extends Partial<Multipart.Persisted>, RD, RE>(
269
- schema: Schema.Codec<A, I, RD, RE>,
267
+ export const schemaBodyForm = <A, I extends Partial<Multipart.Persisted>, RD>(
268
+ schema: Schema.ConstraintCodec<A, I, RD, unknown>,
270
269
  options?: ParseOptions | undefined
271
270
  ) => {
272
271
  const parseMultipart = Multipart.schemaPersisted(schema)
273
- const parseUrlParams = HttpIncomingMessage.schemaBodyUrlParams(schema as Schema.Codec<A, any, RD, RE>, options)
272
+ const parseUrlParams = HttpIncomingMessage.schemaBodyUrlParams(
273
+ schema as Schema.ConstraintCodec<A, any, RD, unknown>,
274
+ options
275
+ )
274
276
  return Effect.flatMap(HttpServerRequest, (request): Effect.Effect<
275
277
  A,
276
278
  Multipart.MultipartError | Schema.SchemaError | HttpServerError,
@@ -293,10 +295,9 @@ export const schemaBodyForm = <A, I extends Partial<Multipart.Persisted>, RD, RE
293
295
  export const schemaBodyUrlParams = <
294
296
  A,
295
297
  I extends Readonly<Record<string, string | ReadonlyArray<string> | undefined>>,
296
- RD,
297
- RE
298
+ RD
298
299
  >(
299
- schema: Schema.Codec<A, I, RD, RE>,
300
+ schema: Schema.ConstraintCodec<A, I, RD, unknown>,
300
301
  options?: ParseOptions | undefined
301
302
  ): Effect.Effect<A, HttpServerError | Schema.SchemaError, HttpServerRequest | RD> => {
302
303
  const parse = HttpIncomingMessage.schemaBodyUrlParams(schema, options)
@@ -315,8 +316,8 @@ export const schemaBodyUrlParams = <
315
316
  * @category schemas
316
317
  * @since 4.0.0
317
318
  */
318
- export const schemaBodyMultipart = <A, I extends Partial<Multipart.Persisted>, RD, RE>(
319
- schema: Schema.Codec<A, I, RD, RE>,
319
+ export const schemaBodyMultipart = <A, I extends Partial<Multipart.Persisted>, RD>(
320
+ schema: Schema.ConstraintCodec<A, I, RD, unknown>,
320
321
  options?: ParseOptions | undefined
321
322
  ): Effect.Effect<
322
323
  A,
@@ -342,8 +343,8 @@ export const schemaBodyMultipart = <A, I extends Partial<Multipart.Persisted>, R
342
343
  * @category schemas
343
344
  * @since 4.0.0
344
345
  */
345
- export const schemaBodyFormJson = <A, I, RD, RE>(
346
- schema: Schema.Codec<A, I, RD, RE>,
346
+ export const schemaBodyFormJson = <A, RD>(
347
+ schema: Schema.ConstraintDecoder<A, RD>,
347
348
  options?: ParseOptions | undefined
348
349
  ) => {
349
350
  const parseMultipart = Multipart.schemaJson(schema, options)
@@ -334,8 +334,8 @@ export const json = (
334
334
  * @category constructors
335
335
  * @since 4.0.0
336
336
  */
337
- export const schemaJson = <A, I, RD, RE>(
338
- schema: Schema.Codec<A, I, RD, RE>,
337
+ export const schemaJson = <A, RE>(
338
+ schema: Schema.ConstraintCodec<A, unknown, unknown, RE>,
339
339
  options?: ParseOptions | undefined
340
340
  ) => {
341
341
  const encode = Body.jsonSchema(schema, options)
@@ -333,8 +333,8 @@ export const SingleFileSchema: Schema.decodeTo<PersistedFileSchema, Schema.$Arra
333
333
  * @category schemas
334
334
  * @since 4.0.0
335
335
  */
336
- export const schemaPersisted = <A, I extends Partial<Persisted>, RD, RE>(
337
- schema: Schema.Codec<A, I, RD, RE>
336
+ export const schemaPersisted = <A, I extends Partial<Persisted>, RD>(
337
+ schema: Schema.ConstraintCodec<A, I, RD, unknown>
338
338
  ): (input: unknown, options?: ParseOptions) => Effect.Effect<A, Schema.SchemaError, RD> =>
339
339
  Schema.decodeUnknownEffect(schema)
340
340
 
@@ -349,7 +349,7 @@ export const schemaPersisted = <A, I extends Partial<Persisted>, RD, RE>(
349
349
  * @category schemas
350
350
  * @since 4.0.0
351
351
  */
352
- export const schemaJson = <A, I, RD, RE>(schema: Schema.Codec<A, I, RD, RE>, options?: ParseOptions | undefined): {
352
+ export const schemaJson = <A, RD>(schema: Schema.ConstraintDecoder<A, RD>, options?: ParseOptions | undefined): {
353
353
  (
354
354
  field: string
355
355
  ): (persisted: Persisted) => Effect.Effect<A, Schema.SchemaError, RD>
@@ -9,11 +9,66 @@
9
9
  * @since 4.0.0
10
10
  */
11
11
  import * as Cause from "../../Cause.ts"
12
+ import * as Data from "../../Data.ts"
12
13
  import { dual } from "../../Function.ts"
13
14
  import * as Redacted from "../../Redacted.ts"
14
15
  import * as Result from "../../Result.ts"
15
16
  import * as UrlParams from "./UrlParams.ts"
16
17
 
18
+ /**
19
+ * Error returned when constructing a `URL` fails.
20
+ *
21
+ * @category errors
22
+ * @since 4.0.0
23
+ */
24
+ export class UrlError extends Data.TaggedError("UrlError")<{
25
+ readonly cause: unknown
26
+ }> {}
27
+
28
+ /**
29
+ * Creates a `URL` safely by appending `UrlParams` and an optional hash to a URL string.
30
+ *
31
+ * **Details**
32
+ *
33
+ * Returns a `Result` that fails with `UrlError` if the URL cannot be constructed.
34
+ *
35
+ * @category constructors
36
+ * @since 4.0.0
37
+ */
38
+ export const make = (
39
+ url: string,
40
+ params: UrlParams.UrlParams,
41
+ hash: string | undefined
42
+ ): Result.Result<URL, UrlError> =>
43
+ Result.try({
44
+ try: () => {
45
+ const urlInstance = new URL(url, baseUrl())
46
+ for (let i = 0; i < params.params.length; i++) {
47
+ const [key, value] = params.params[i]
48
+ if (value !== undefined) {
49
+ urlInstance.searchParams.append(key, value)
50
+ }
51
+ }
52
+ if (hash !== undefined) {
53
+ urlInstance.hash = hash
54
+ }
55
+ return urlInstance
56
+ },
57
+ catch: (cause) => new UrlError({ cause })
58
+ })
59
+
60
+ const baseUrl = (): string | undefined => {
61
+ if (
62
+ "location" in globalThis &&
63
+ globalThis.location !== undefined &&
64
+ globalThis.location.origin !== undefined &&
65
+ globalThis.location.pathname !== undefined
66
+ ) {
67
+ return location.origin + location.pathname
68
+ }
69
+ return undefined
70
+ }
71
+
17
72
  /**
18
73
  * Parses a URL string safely into a `URL` object, returning a `Result` type for
19
74
  * error handling.
@@ -502,7 +557,7 @@ export const setUrlParams: {
502
557
  * @category setters
503
558
  * @since 4.0.0
504
559
  */
505
- (urlParams: UrlParams.UrlParams): (url: URL) => URL
560
+ (urlParams: UrlParams.Input): (url: URL) => URL
506
561
  /**
507
562
  * Updates the query parameters of a URL.
508
563
  *
@@ -532,10 +587,10 @@ export const setUrlParams: {
532
587
  * @category setters
533
588
  * @since 4.0.0
534
589
  */
535
- (url: URL, urlParams: UrlParams.UrlParams): URL
536
- } = dual(2, (url: URL, searchParams: UrlParams.UrlParams) =>
590
+ (url: URL, urlParams: UrlParams.Input): URL
591
+ } = dual(2, (url: URL, urlParams: UrlParams.Input) =>
537
592
  mutate(url, (url) => {
538
- url.search = UrlParams.toString(searchParams)
593
+ url.search = UrlParams.toString(UrlParams.fromInput(urlParams))
539
594
  }))
540
595
 
541
596
  /**
@@ -619,7 +674,7 @@ export const modifyUrlParams: {
619
674
  * @category modifiers
620
675
  * @since 4.0.0
621
676
  */
622
- (f: (urlParams: UrlParams.UrlParams) => UrlParams.UrlParams): (url: URL) => URL
677
+ (f: (urlParams: UrlParams.UrlParams) => UrlParams.Input): (url: URL) => URL
623
678
  /**
624
679
  * Reads the query parameters of a URL, modifies them, and updates the URL.
625
680
  *
@@ -646,8 +701,8 @@ export const modifyUrlParams: {
646
701
  * @category modifiers
647
702
  * @since 4.0.0
648
703
  */
649
- (url: URL, f: (urlParams: UrlParams.UrlParams) => UrlParams.UrlParams): URL
650
- } = dual(2, (url: URL, f: (urlParams: UrlParams.UrlParams) => UrlParams.UrlParams) =>
704
+ (url: URL, f: (urlParams: UrlParams.UrlParams) => UrlParams.Input): URL
705
+ } = dual(2, (url: URL, f: (urlParams: UrlParams.UrlParams) => UrlParams.Input) =>
651
706
  mutate(url, (url) => {
652
707
  const params = f(UrlParams.fromInput(url.searchParams))
653
708
  url.search = UrlParams.toString(params)
@@ -9,7 +9,6 @@
9
9
  * @since 4.0.0
10
10
  */
11
11
  import * as Arr from "../../Array.ts"
12
- import * as Data from "../../Data.ts"
13
12
  import * as Effect from "../../Effect.ts"
14
13
  import * as Equal from "../../Equal.ts"
15
14
  import * as Equ from "../../Equivalence.ts"
@@ -21,7 +20,6 @@ import * as Option from "../../Option.ts"
21
20
  import type { Pipeable } from "../../Pipeable.ts"
22
21
  import { hasProperty } from "../../Predicate.ts"
23
22
  import type { ReadonlyRecord } from "../../Record.ts"
24
- import * as Result from "../../Result.ts"
25
23
  import * as Schema from "../../Schema.ts"
26
24
  import * as SchemaIssue from "../../SchemaIssue.ts"
27
25
  import * as SchemaTransformation from "../../SchemaTransformation.ts"
@@ -65,6 +63,7 @@ export const isUrlParams = (u: unknown): u is UrlParams => hasProperty(u, TypeId
65
63
  * @since 4.0.0
66
64
  */
67
65
  export type Input =
66
+ | UrlParams
68
67
  | CoercibleRecordInput
69
68
  | Iterable<readonly [string, Coercible]>
70
69
  | URLSearchParams
@@ -157,6 +156,9 @@ export const make = (params: ReadonlyArray<readonly [string, string]>): UrlParam
157
156
  * @since 4.0.0
158
157
  */
159
158
  export const fromInput = (input: Input): UrlParams => {
159
+ if (isUrlParams(input)) {
160
+ return input
161
+ }
160
162
  const parsed = fromInputNested(input)
161
163
  const out: Array<[string, string]> = []
162
164
  for (let i = 0; i < parsed.length; i++) {
@@ -634,68 +636,13 @@ export const remove: {
634
636
  (self: UrlParams, key: string): UrlParams
635
637
  } = dual(2, (self: UrlParams, key: string): UrlParams => transform(self, Arr.filter(([k]) => k !== key)))
636
638
 
637
- /**
638
- * Error returned when constructing a `URL` from `UrlParams` fails.
639
- *
640
- * @category errors
641
- * @since 4.0.0
642
- */
643
- export class UrlParamsError extends Data.TaggedError("UrlParamsError")<{
644
- cause: unknown
645
- }> {}
646
-
647
- /**
648
- * Creates a `URL` safely by appending `UrlParams` and an optional hash to a URL string.
649
- *
650
- * **Details**
651
- *
652
- * Returns a `Result` that fails with `UrlParamsError` if the URL cannot be
653
- * constructed.
654
- *
655
- * @category converting
656
- * @since 4.0.0
657
- */
658
- export const makeUrl = (
659
- url: string,
660
- params: UrlParams,
661
- hash: string | undefined
662
- ): Result.Result<URL, UrlParamsError> => {
663
- try {
664
- const urlInstance = new URL(url, baseUrl())
665
- for (let i = 0; i < params.params.length; i++) {
666
- const [key, value] = params.params[i]
667
- if (value !== undefined) {
668
- urlInstance.searchParams.append(key, value)
669
- }
670
- }
671
- if (hash !== undefined) {
672
- urlInstance.hash = hash
673
- }
674
- return Result.succeed(urlInstance)
675
- } catch (e) {
676
- return Result.fail(new UrlParamsError({ cause: e }))
677
- }
678
- }
679
-
680
639
  /**
681
640
  * Serializes `UrlParams` to a URL query string without a leading question mark.
682
641
  *
683
642
  * @category converting
684
643
  * @since 4.0.0
685
644
  */
686
- export const toString = (self: UrlParams): string => new URLSearchParams(self.params as any).toString()
687
-
688
- const baseUrl = (): string | undefined => {
689
- if (
690
- "location" in globalThis &&
691
- globalThis.location !== undefined &&
692
- globalThis.location.origin !== undefined &&
693
- globalThis.location.pathname !== undefined
694
- ) {
695
- return location.origin + location.pathname
696
- }
697
- return undefined
698
- }
645
+ export const toString = (input: Input): string => new URLSearchParams(fromInput(input).params as any).toString()
699
646
 
700
647
  /**
701
648
  * Builds a `Record` containing all the key-value pairs in the given `UrlParams`
@@ -186,9 +186,7 @@ const makeProto = <Id extends string, Groups extends HttpApiGroup.Any>(
186
186
  ): HttpApi<Id, Groups> => {
187
187
  function HttpApi() {}
188
188
  Object.setPrototypeOf(HttpApi, Proto)
189
- HttpApi.groups = options.groups
190
- HttpApi.annotations = options.annotations
191
- return HttpApi as any
189
+ return Object.assign(HttpApi, options) as any
192
190
  }
193
191
 
194
192
  /**
@@ -206,7 +204,7 @@ const makeProto = <Id extends string, Groups extends HttpApiGroup.Any>(
206
204
  export const make = <const Id extends string>(identifier: Id): HttpApi<Id, never> =>
207
205
  makeProto({
208
206
  identifier,
209
- groups: new Map() as any,
207
+ groups: {},
210
208
  annotations: Context.empty()
211
209
  })
212
210