@effect/platform 0.48.16 → 0.48.17

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 (102) hide show
  1. package/dist/cjs/Http/Client.js.map +1 -1
  2. package/dist/cjs/Http/ClientRequest.js.map +1 -1
  3. package/dist/cjs/Http/ClientResponse.js.map +1 -1
  4. package/dist/cjs/Http/Cookies.js +50 -27
  5. package/dist/cjs/Http/Cookies.js.map +1 -1
  6. package/dist/cjs/Http/IncomingMessage.js +12 -16
  7. package/dist/cjs/Http/IncomingMessage.js.map +1 -1
  8. package/dist/cjs/Http/Multipart.js.map +1 -1
  9. package/dist/cjs/Http/Router.js +11 -1
  10. package/dist/cjs/Http/Router.js.map +1 -1
  11. package/dist/cjs/Http/ServerRequest.js +6 -1
  12. package/dist/cjs/Http/ServerRequest.js.map +1 -1
  13. package/dist/cjs/Http/ServerResponse.js.map +1 -1
  14. package/dist/cjs/Http/UrlParams.js +2 -2
  15. package/dist/cjs/Http/UrlParams.js.map +1 -1
  16. package/dist/cjs/internal/http/body.js +2 -2
  17. package/dist/cjs/internal/http/body.js.map +1 -1
  18. package/dist/cjs/internal/http/client.js +4 -2
  19. package/dist/cjs/internal/http/client.js.map +1 -1
  20. package/dist/cjs/internal/http/clientRequest.js +2 -2
  21. package/dist/cjs/internal/http/clientRequest.js.map +1 -1
  22. package/dist/cjs/internal/http/clientResponse.js +8 -8
  23. package/dist/cjs/internal/http/clientResponse.js.map +1 -1
  24. package/dist/cjs/internal/http/multipart.js +4 -4
  25. package/dist/cjs/internal/http/multipart.js.map +1 -1
  26. package/dist/cjs/internal/http/router.js +34 -7
  27. package/dist/cjs/internal/http/router.js.map +1 -1
  28. package/dist/cjs/internal/http/serverRequest.js +22 -15
  29. package/dist/cjs/internal/http/serverRequest.js.map +1 -1
  30. package/dist/cjs/internal/http/serverResponse.js +19 -11
  31. package/dist/cjs/internal/http/serverResponse.js.map +1 -1
  32. package/dist/dts/Http/Client.d.ts +3 -2
  33. package/dist/dts/Http/Client.d.ts.map +1 -1
  34. package/dist/dts/Http/ClientRequest.d.ts +2 -1
  35. package/dist/dts/Http/ClientRequest.d.ts.map +1 -1
  36. package/dist/dts/Http/ClientResponse.d.ts +5 -4
  37. package/dist/dts/Http/ClientResponse.d.ts.map +1 -1
  38. package/dist/dts/Http/Cookies.d.ts +15 -7
  39. package/dist/dts/Http/Cookies.d.ts.map +1 -1
  40. package/dist/dts/Http/IncomingMessage.d.ts +7 -6
  41. package/dist/dts/Http/IncomingMessage.d.ts.map +1 -1
  42. package/dist/dts/Http/Multipart.d.ts +3 -2
  43. package/dist/dts/Http/Multipart.d.ts.map +1 -1
  44. package/dist/dts/Http/Router.d.ts +29 -3
  45. package/dist/dts/Http/Router.d.ts.map +1 -1
  46. package/dist/dts/Http/ServerRequest.d.ts +12 -6
  47. package/dist/dts/Http/ServerRequest.d.ts.map +1 -1
  48. package/dist/dts/Http/ServerResponse.d.ts +14 -13
  49. package/dist/dts/Http/ServerResponse.d.ts.map +1 -1
  50. package/dist/dts/Http/UrlParams.d.ts +2 -1
  51. package/dist/dts/Http/UrlParams.d.ts.map +1 -1
  52. package/dist/dts/internal/http/router.d.ts.map +1 -1
  53. package/dist/esm/Http/Client.js.map +1 -1
  54. package/dist/esm/Http/ClientRequest.js.map +1 -1
  55. package/dist/esm/Http/ClientResponse.js.map +1 -1
  56. package/dist/esm/Http/Cookies.js +47 -25
  57. package/dist/esm/Http/Cookies.js.map +1 -1
  58. package/dist/esm/Http/IncomingMessage.js +12 -15
  59. package/dist/esm/Http/IncomingMessage.js.map +1 -1
  60. package/dist/esm/Http/Multipart.js.map +1 -1
  61. package/dist/esm/Http/Router.js +10 -0
  62. package/dist/esm/Http/Router.js.map +1 -1
  63. package/dist/esm/Http/ServerRequest.js +5 -0
  64. package/dist/esm/Http/ServerRequest.js.map +1 -1
  65. package/dist/esm/Http/ServerResponse.js.map +1 -1
  66. package/dist/esm/Http/UrlParams.js +2 -2
  67. package/dist/esm/Http/UrlParams.js.map +1 -1
  68. package/dist/esm/internal/http/body.js +2 -2
  69. package/dist/esm/internal/http/body.js.map +1 -1
  70. package/dist/esm/internal/http/client.js +4 -2
  71. package/dist/esm/internal/http/client.js.map +1 -1
  72. package/dist/esm/internal/http/clientRequest.js +2 -2
  73. package/dist/esm/internal/http/clientRequest.js.map +1 -1
  74. package/dist/esm/internal/http/clientResponse.js +8 -8
  75. package/dist/esm/internal/http/clientResponse.js.map +1 -1
  76. package/dist/esm/internal/http/multipart.js +4 -4
  77. package/dist/esm/internal/http/multipart.js.map +1 -1
  78. package/dist/esm/internal/http/router.js +31 -6
  79. package/dist/esm/internal/http/router.js.map +1 -1
  80. package/dist/esm/internal/http/serverRequest.js +20 -14
  81. package/dist/esm/internal/http/serverRequest.js.map +1 -1
  82. package/dist/esm/internal/http/serverResponse.js +19 -11
  83. package/dist/esm/internal/http/serverResponse.js.map +1 -1
  84. package/package.json +3 -3
  85. package/src/Http/Client.ts +5 -2
  86. package/src/Http/ClientRequest.ts +3 -1
  87. package/src/Http/ClientResponse.ts +16 -7
  88. package/src/Http/Cookies.ts +60 -37
  89. package/src/Http/IncomingMessage.ts +17 -12
  90. package/src/Http/Multipart.ts +5 -2
  91. package/src/Http/Router.ts +50 -3
  92. package/src/Http/ServerRequest.ts +23 -7
  93. package/src/Http/ServerResponse.ts +19 -13
  94. package/src/Http/UrlParams.ts +3 -2
  95. package/src/internal/http/body.ts +3 -2
  96. package/src/internal/http/client.ts +10 -5
  97. package/src/internal/http/clientRequest.ts +3 -2
  98. package/src/internal/http/clientResponse.ts +9 -8
  99. package/src/internal/http/multipart.ts +7 -4
  100. package/src/internal/http/router.ts +80 -6
  101. package/src/internal/http/serverRequest.ts +31 -15
  102. package/src/internal/http/serverResponse.ts +32 -22
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * @since 1.0.0
3
3
  */
4
+ import type { ParseOptions } from "@effect/schema/AST"
4
5
  import type * as ParseResult from "@effect/schema/ParseResult"
5
6
  import type * as Schema from "@effect/schema/Schema"
6
7
  import type * as Cause from "effect/Cause"
@@ -148,12 +149,56 @@ export const searchParams: Effect.Effect<
148
149
  RouteContext
149
150
  > = internal.searchParams
150
151
 
152
+ /**
153
+ * @since 1.0.0
154
+ * @category route context
155
+ */
156
+ export const schemaJson: <
157
+ R,
158
+ I extends {
159
+ readonly method?: Method.Method | undefined
160
+ readonly url?: string | undefined
161
+ readonly cookies?: Readonly<Record<string, string>> | undefined
162
+ readonly headers?: Readonly<Record<string, string>> | undefined
163
+ readonly pathParams?: Readonly<Record<string, string>> | undefined
164
+ readonly searchParams?: Readonly<Record<string, string>> | undefined
165
+ readonly body?: any
166
+ },
167
+ A
168
+ >(
169
+ schema: Schema.Schema<A, I, R>,
170
+ options?: ParseOptions | undefined
171
+ ) => Effect.Effect<A, ParseResult.ParseError | Error.RequestError, RouteContext | R | ServerRequest.ServerRequest> =
172
+ internal.schemaJson
173
+
174
+ /**
175
+ * @since 1.0.0
176
+ * @category route context
177
+ */
178
+ export const schemaNoBody: <
179
+ R,
180
+ I extends {
181
+ readonly method?: Method.Method | undefined
182
+ readonly url?: string | undefined
183
+ readonly cookies?: Readonly<Record<string, string>> | undefined
184
+ readonly headers?: Readonly<Record<string, string>> | undefined
185
+ readonly pathParams?: Readonly<Record<string, string>> | undefined
186
+ readonly searchParams?: Readonly<Record<string, string>> | undefined
187
+ },
188
+ A
189
+ >(
190
+ schema: Schema.Schema<A, I, R>,
191
+ options?: ParseOptions | undefined
192
+ ) => Effect.Effect<A, ParseResult.ParseError | Error.RequestError, RouteContext | R | ServerRequest.ServerRequest> =
193
+ internal.schemaNoBody
194
+
151
195
  /**
152
196
  * @since 1.0.0
153
197
  * @category route context
154
198
  */
155
199
  export const schemaParams: <R, I extends Readonly<Record<string, string>>, A>(
156
- schema: Schema.Schema<A, I, R>
200
+ schema: Schema.Schema<A, I, R>,
201
+ options?: ParseOptions | undefined
157
202
  ) => Effect.Effect<A, ParseResult.ParseError, RouteContext | R> = internal.schemaParams
158
203
 
159
204
  /**
@@ -161,7 +206,8 @@ export const schemaParams: <R, I extends Readonly<Record<string, string>>, A>(
161
206
  * @category route context
162
207
  */
163
208
  export const schemaPathParams: <R, I extends Readonly<Record<string, string>>, A>(
164
- schema: Schema.Schema<A, I, R>
209
+ schema: Schema.Schema<A, I, R>,
210
+ options?: ParseOptions | undefined
165
211
  ) => Effect.Effect<A, ParseResult.ParseError, RouteContext | R> = internal.schemaPathParams
166
212
 
167
213
  /**
@@ -169,7 +215,8 @@ export const schemaPathParams: <R, I extends Readonly<Record<string, string>>, A
169
215
  * @category route context
170
216
  */
171
217
  export const schemaSearchParams: <R, I extends Readonly<Record<string, string>>, A>(
172
- schema: Schema.Schema<A, I, R>
218
+ schema: Schema.Schema<A, I, R>,
219
+ options?: ParseOptions | undefined
173
220
  ) => Effect.Effect<A, ParseResult.ParseError, RouteContext | R> = internal.schemaSearchParams
174
221
 
175
222
  /**
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * @since 1.0.0
3
3
  */
4
+ import type { ParseOptions } from "@effect/schema/AST"
4
5
  import type * as ParseResult from "@effect/schema/ParseResult"
5
6
  import type * as Schema from "@effect/schema/Schema"
6
7
  import type { Channel } from "effect/Channel"
@@ -106,12 +107,22 @@ export const upgradeChannel: <IE = never>() => Channel<
106
107
  ServerRequest
107
108
  > = internal.upgradeChannel
108
109
 
110
+ /**
111
+ * @since 1.0.0
112
+ * @category schema
113
+ */
114
+ export const schemaCookies: <R, I extends Readonly<Record<string, string>>, A>(
115
+ schema: Schema.Schema<A, I, R>,
116
+ options?: ParseOptions | undefined
117
+ ) => Effect.Effect<A, ParseResult.ParseError, ServerRequest | R> = internal.schemaCookies
118
+
109
119
  /**
110
120
  * @since 1.0.0
111
121
  * @category schema
112
122
  */
113
123
  export const schemaHeaders: <R, I extends Readonly<Record<string, string>>, A>(
114
- schema: Schema.Schema<A, I, R>
124
+ schema: Schema.Schema<A, I, R>,
125
+ options?: ParseOptions | undefined
115
126
  ) => Effect.Effect<A, ParseResult.ParseError, ServerRequest | R> = internal.schemaHeaders
116
127
 
117
128
  /**
@@ -119,7 +130,8 @@ export const schemaHeaders: <R, I extends Readonly<Record<string, string>>, A>(
119
130
  * @category schema
120
131
  */
121
132
  export const schemaBodyJson: <A, I, R>(
122
- schema: Schema.Schema<A, I, R>
133
+ schema: Schema.Schema<A, I, R>,
134
+ options?: ParseOptions | undefined
123
135
  ) => Effect.Effect<A, Error.RequestError | ParseResult.ParseError, ServerRequest | R> = internal.schemaBodyJson
124
136
 
125
137
  /**
@@ -127,7 +139,8 @@ export const schemaBodyJson: <A, I, R>(
127
139
  * @category schema
128
140
  */
129
141
  export const schemaBodyForm: <R, I extends Partial<Multipart.Persisted>, A>(
130
- schema: Schema.Schema<A, I, R>
142
+ schema: Schema.Schema<A, I, R>,
143
+ options?: ParseOptions | undefined
131
144
  ) => Effect.Effect<
132
145
  A,
133
146
  Multipart.MultipartError | ParseResult.ParseError | Error.RequestError,
@@ -139,15 +152,17 @@ export const schemaBodyForm: <R, I extends Partial<Multipart.Persisted>, A>(
139
152
  * @category schema
140
153
  */
141
154
  export const schemaBodyUrlParams: <R, I extends Readonly<Record<string, string>>, A>(
142
- schema: Schema.Schema<A, I, R>
143
- ) => Effect.Effect<A, Error.RequestError | ParseResult.ParseError, ServerRequest | R> = internal.schemaBodyUrlParams
155
+ schema: Schema.Schema<A, I, R>,
156
+ options?: ParseOptions | undefined
157
+ ) => Effect.Effect<A, ParseResult.ParseError | Error.RequestError, R | ServerRequest> = internal.schemaBodyUrlParams
144
158
 
145
159
  /**
146
160
  * @since 1.0.0
147
161
  * @category schema
148
162
  */
149
163
  export const schemaBodyMultipart: <R, I extends Partial<Multipart.Persisted>, A>(
150
- schema: Schema.Schema<A, I, R>
164
+ schema: Schema.Schema<A, I, R>,
165
+ options?: ParseOptions | undefined
151
166
  ) => Effect.Effect<
152
167
  A,
153
168
  Multipart.MultipartError | ParseResult.ParseError,
@@ -159,7 +174,8 @@ export const schemaBodyMultipart: <R, I extends Partial<Multipart.Persisted>, A>
159
174
  * @category schema
160
175
  */
161
176
  export const schemaBodyFormJson: <A, I, R>(
162
- schema: Schema.Schema<A, I, R>
177
+ schema: Schema.Schema<A, I, R>,
178
+ options?: ParseOptions | undefined
163
179
  ) => (
164
180
  field: string
165
181
  ) => Effect.Effect<
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * @since 1.0.0
3
3
  */
4
+ import type { ParseOptions } from "@effect/schema/AST"
4
5
  import type * as Schema from "@effect/schema/Schema"
5
6
  import type * as Effect from "effect/Effect"
6
7
  import type { Inspectable } from "effect/Inspectable"
@@ -79,19 +80,20 @@ export const isServerResponse: (u: unknown) => u is ServerResponse = internal.is
79
80
  * @since 1.0.0
80
81
  * @category constructors
81
82
  */
82
- export const empty: (options?: Options.WithContent) => ServerResponse = internal.empty
83
+ export const empty: (options?: Options.WithContent | undefined) => ServerResponse = internal.empty
83
84
 
84
85
  /**
85
86
  * @since 1.0.0
86
87
  * @category constructors
87
88
  */
88
- export const uint8Array: (body: Uint8Array, options?: Options.WithContentType) => ServerResponse = internal.uint8Array
89
+ export const uint8Array: (body: Uint8Array, options?: Options.WithContentType | undefined) => ServerResponse =
90
+ internal.uint8Array
89
91
 
90
92
  /**
91
93
  * @since 1.0.0
92
94
  * @category constructors
93
95
  */
94
- export const text: (body: string, options?: Options.WithContentType) => ServerResponse = internal.text
96
+ export const text: (body: string, options?: Options.WithContentType | undefined) => ServerResponse = internal.text
95
97
 
96
98
  /**
97
99
  * @since 1.0.0
@@ -120,7 +122,7 @@ export const htmlStream: <A extends ReadonlyArray<Template.InterpolatedWithStrea
120
122
  */
121
123
  export const json: (
122
124
  body: unknown,
123
- options?: Options.WithContent
125
+ options?: Options.WithContent | undefined
124
126
  ) => Effect.Effect<ServerResponse, Body.BodyError> = internal.json
125
127
 
126
128
  /**
@@ -128,7 +130,8 @@ export const json: (
128
130
  * @category constructors
129
131
  */
130
132
  export const schemaJson: <A, I, R>(
131
- schema: Schema.Schema<A, I, R>
133
+ schema: Schema.Schema<A, I, R>,
134
+ options?: ParseOptions | undefined
132
135
  ) => (body: A, options?: Options.WithContent | undefined) => Effect.Effect<ServerResponse, Body.BodyError, R> =
133
136
  internal.schemaJson
134
137
 
@@ -136,31 +139,34 @@ export const schemaJson: <A, I, R>(
136
139
  * @since 1.0.0
137
140
  * @category constructors
138
141
  */
139
- export const unsafeJson: (body: unknown, options?: Options.WithContent) => ServerResponse = internal.unsafeJson
142
+ export const unsafeJson: (body: unknown, options?: Options.WithContent | undefined) => ServerResponse =
143
+ internal.unsafeJson
140
144
 
141
145
  /**
142
146
  * @since 1.0.0
143
147
  * @category constructors
144
148
  */
145
- export const urlParams: (body: UrlParams.Input, options?: Options.WithContent) => ServerResponse = internal.urlParams
149
+ export const urlParams: (body: UrlParams.Input, options?: Options.WithContent | undefined) => ServerResponse =
150
+ internal.urlParams
146
151
 
147
152
  /**
148
153
  * @since 1.0.0
149
154
  * @category constructors
150
155
  */
151
- export const raw: (body: unknown, options?: Options) => ServerResponse = internal.raw
156
+ export const raw: (body: unknown, options?: Options | undefined) => ServerResponse = internal.raw
152
157
 
153
158
  /**
154
159
  * @since 1.0.0
155
160
  * @category constructors
156
161
  */
157
- export const formData: (body: FormData, options?: Options.WithContent) => ServerResponse = internal.formData
162
+ export const formData: (body: FormData, options?: Options.WithContent | undefined) => ServerResponse = internal.formData
158
163
 
159
164
  /**
160
165
  * @since 1.0.0
161
166
  * @category constructors
162
167
  */
163
- export const stream: (body: Stream.Stream<Uint8Array, unknown>, options?: Options) => ServerResponse = internal.stream
168
+ export const stream: (body: Stream.Stream<Uint8Array, unknown>, options?: Options | undefined) => ServerResponse =
169
+ internal.stream
164
170
 
165
171
  /**
166
172
  * @since 1.0.0
@@ -168,7 +174,7 @@ export const stream: (body: Stream.Stream<Uint8Array, unknown>, options?: Option
168
174
  */
169
175
  export const file: (
170
176
  path: string,
171
- options?: Options & FileSystem.StreamOptions
177
+ options?: (Options & FileSystem.StreamOptions) | undefined
172
178
  ) => Effect.Effect<ServerResponse, PlatformError.PlatformError, Platform.Platform> = internal.file
173
179
 
174
180
  /**
@@ -177,7 +183,7 @@ export const file: (
177
183
  */
178
184
  export const fileWeb: (
179
185
  file: Body.Body.FileLike,
180
- options?: Options.WithContent & FileSystem.StreamOptions
186
+ options?: (Options.WithContent & FileSystem.StreamOptions) | undefined
181
187
  ) => Effect.Effect<ServerResponse, never, Platform.Platform> = internal.fileWeb
182
188
 
183
189
  /**
@@ -343,4 +349,4 @@ export const setStatus: {
343
349
  * @since 1.0.0
344
350
  * @category conversions
345
351
  */
346
- export const toWeb: (response: ServerResponse, withoutBody?: boolean) => Response = internal.toWeb
352
+ export const toWeb: (response: ServerResponse, withoutBody?: boolean | undefined) => Response = internal.toWeb
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * @since 1.0.0
3
3
  */
4
+ import type { ParseOptions } from "@effect/schema/AST"
4
5
  import type * as ParseResult from "@effect/schema/ParseResult"
5
6
  import * as Schema from "@effect/schema/Schema"
6
7
  import * as Effect from "effect/Effect"
@@ -217,7 +218,7 @@ const baseUrl = (): string | undefined => {
217
218
  * @since 1.0.0
218
219
  * @category schema
219
220
  */
220
- export const schemaJson = <A, I, R>(schema: Schema.Schema<A, I, R>): {
221
+ export const schemaJson = <A, I, R>(schema: Schema.Schema<A, I, R>, options?: ParseOptions | undefined): {
221
222
  (
222
223
  field: string
223
224
  ): (self: UrlParams) => Effect.Effect<A, ParseResult.ParseError, R>
@@ -226,7 +227,7 @@ export const schemaJson = <A, I, R>(schema: Schema.Schema<A, I, R>): {
226
227
  field: string
227
228
  ): Effect.Effect<A, ParseResult.ParseError, R>
228
229
  } => {
229
- const parse = Schema.decodeUnknown(Schema.parseJson(schema))
230
+ const parse = Schema.decodeUnknown(Schema.parseJson(schema), options)
230
231
  return dual<
231
232
  (field: string) => (self: UrlParams) => Effect.Effect<A, ParseResult.ParseError, R>,
232
233
  (self: UrlParams, field: string) => Effect.Effect<A, ParseResult.ParseError, R>
@@ -1,3 +1,4 @@
1
+ import type { ParseOptions } from "@effect/schema/AST"
1
2
  import * as Schema from "@effect/schema/Schema"
2
3
  import * as Data from "effect/Data"
3
4
  import * as Effect from "effect/Effect"
@@ -127,8 +128,8 @@ export const urlParams = (urlParams: UrlParams.UrlParams): Body.Uint8Array =>
127
128
  text(UrlParams.toString(urlParams), "application/x-www-form-urlencoded")
128
129
 
129
130
  /** @internal */
130
- export const jsonSchema = <A, I, R>(schema: Schema.Schema<A, I, R>) => {
131
- const encode = Schema.encode(schema)
131
+ export const jsonSchema = <A, I, R>(schema: Schema.Schema<A, I, R>, options?: ParseOptions) => {
132
+ const encode = Schema.encode(schema, options)
132
133
  return (body: A): Effect.Effect<Body.Uint8Array, Body.BodyError, R> =>
133
134
  Effect.flatMap(
134
135
  Effect.mapError(encode(body), (error) => BodyError({ _tag: "SchemaError", error })),
@@ -1,3 +1,4 @@
1
+ import type { ParseOptions } from "@effect/schema/AST"
1
2
  import type * as ParseResult from "@effect/schema/ParseResult"
2
3
  import * as Schema from "@effect/schema/Schema"
3
4
  import * as Context from "effect/Context"
@@ -5,7 +6,7 @@ import * as Effect from "effect/Effect"
5
6
  import { dual, pipe } from "effect/Function"
6
7
  import * as Layer from "effect/Layer"
7
8
  import { pipeArguments } from "effect/Pipeable"
8
- import type * as Predicate from "effect/Predicate"
9
+ import * as Predicate from "effect/Predicate"
9
10
  import * as Ref from "effect/Ref"
10
11
  import type * as Schedule from "effect/Schedule"
11
12
  import type * as Scope from "effect/Scope"
@@ -37,6 +38,8 @@ const clientProto = {
37
38
  }
38
39
  }
39
40
 
41
+ const isClient = (u: unknown): u is Client.Client<unknown, unknown, unknown> => Predicate.hasProperty(u, TypeId)
42
+
40
43
  /** @internal */
41
44
  export const make = <R, E, A, R2, E2>(
42
45
  execute: (
@@ -549,7 +552,8 @@ export const retry: {
549
552
  /** @internal */
550
553
  export const schemaFunction = dual<
551
554
  <SA, SI, SR>(
552
- schema: Schema.Schema<SA, SI, SR>
555
+ schema: Schema.Schema<SA, SI, SR>,
556
+ options?: ParseOptions | undefined
553
557
  ) => <R, E, A>(
554
558
  self: Client.Client<R, E, A>
555
559
  ) => (
@@ -559,14 +563,15 @@ export const schemaFunction = dual<
559
563
  ) => Effect.Effect<A, E | ParseResult.ParseError | Error.RequestError, SR | R>,
560
564
  <R, E, A, SA, SI, SR>(
561
565
  self: Client.Client<R, E, A>,
562
- schema: Schema.Schema<SA, SI, SR>
566
+ schema: Schema.Schema<SA, SI, SR>,
567
+ options?: ParseOptions | undefined
563
568
  ) => (
564
569
  request: ClientRequest.ClientRequest
565
570
  ) => (
566
571
  a: SA
567
572
  ) => Effect.Effect<A, E | ParseResult.ParseError | Error.RequestError, SR | R>
568
- >(2, (self, schema) => {
569
- const encode = Schema.encode(schema)
573
+ >((args) => isClient(args[0]), (self, schema, options) => {
574
+ const encode = Schema.encode(schema, options)
570
575
  return (request) => (a) =>
571
576
  Effect.flatMap(
572
577
  Effect.tryMap(encode(a), {
@@ -1,3 +1,4 @@
1
+ import type { ParseOptions } from "@effect/schema/AST"
1
2
  import type * as Schema from "@effect/schema/Schema"
2
3
  import * as Effect from "effect/Effect"
3
4
  import { dual } from "effect/Function"
@@ -373,11 +374,11 @@ export const fileWebBody = dual<
373
374
  >(2, (self, file) => setBody(self, internalBody.fileWeb(file)))
374
375
 
375
376
  /** @internal */
376
- export const schemaBody = <A, I, R>(schema: Schema.Schema<A, I, R>): {
377
+ export const schemaBody = <A, I, R>(schema: Schema.Schema<A, I, R>, options?: ParseOptions | undefined): {
377
378
  (body: A): (self: ClientRequest.ClientRequest) => Effect.Effect<ClientRequest.ClientRequest, Body.BodyError, R>
378
379
  (self: ClientRequest.ClientRequest, body: A): Effect.Effect<ClientRequest.ClientRequest, Body.BodyError, R>
379
380
  } => {
380
- const encode = internalBody.jsonSchema(schema)
381
+ const encode = internalBody.jsonSchema(schema, options)
381
382
  return dual<
382
383
  (
383
384
  body: A
@@ -1,3 +1,4 @@
1
+ import type { ParseOptions } from "@effect/schema/AST"
1
2
  import type * as ParseResult from "@effect/schema/ParseResult"
2
3
  import * as Schema from "@effect/schema/Schema"
3
4
  import * as Effect from "effect/Effect"
@@ -160,8 +161,8 @@ export const schemaJson = <
160
161
  readonly body?: unknown | undefined
161
162
  },
162
163
  A
163
- >(schema: Schema.Schema<A, I, R>) => {
164
- const parse = Schema.decodeUnknown(schema)
164
+ >(schema: Schema.Schema<A, I, R>, options?: ParseOptions | undefined) => {
165
+ const parse = Schema.decodeUnknown(schema, options)
165
166
  return (self: ClientResponse.ClientResponse): Effect.Effect<A, Error.ResponseError | ParseResult.ParseError, R> =>
166
167
  Effect.flatMap(
167
168
  self.json,
@@ -182,8 +183,8 @@ export const schemaNoBody = <
182
183
  readonly headers?: Readonly<Record<string, string>> | undefined
183
184
  },
184
185
  A
185
- >(schema: Schema.Schema<A, I, R>) => {
186
- const parse = Schema.decodeUnknown(schema)
186
+ >(schema: Schema.Schema<A, I, R>, options?: ParseOptions | undefined) => {
187
+ const parse = Schema.decodeUnknown(schema, options)
187
188
  return (self: ClientResponse.ClientResponse): Effect.Effect<A, ParseResult.ParseError, R> =>
188
189
  parse({
189
190
  status: self.status,
@@ -224,8 +225,8 @@ export const schemaJsonEffect = <
224
225
  readonly body?: unknown | undefined
225
226
  },
226
227
  A
227
- >(schema: Schema.Schema<A, I, R>) => {
228
- const decode = schemaJson(schema)
228
+ >(schema: Schema.Schema<A, I, R>, options?: ParseOptions | undefined) => {
229
+ const decode = schemaJson(schema, options)
229
230
  return <E, R2>(effect: Effect.Effect<ClientResponse.ClientResponse, E, R2>) =>
230
231
  Effect.scoped(Effect.flatMap(effect, decode))
231
232
  }
@@ -238,8 +239,8 @@ export const schemaNoBodyEffect = <
238
239
  readonly headers?: Readonly<Record<string, string>> | undefined
239
240
  },
240
241
  A
241
- >(schema: Schema.Schema<A, I, R>) => {
242
- const decode = schemaNoBody(schema)
242
+ >(schema: Schema.Schema<A, I, R>, options?: ParseOptions | undefined) => {
243
+ const decode = schemaNoBody(schema, options)
243
244
  return <E, R2>(effect: Effect.Effect<ClientResponse.ClientResponse, E, R2>) =>
244
245
  Effect.scoped(Effect.flatMap(effect, decode))
245
246
  }
@@ -1,3 +1,4 @@
1
+ import type { ParseOptions } from "@effect/schema/AST"
1
2
  import type * as ParseResult from "@effect/schema/ParseResult"
2
3
  import * as Schema from "@effect/schema/Schema"
3
4
  import * as Cause from "effect/Cause"
@@ -108,14 +109,15 @@ export const filesSchema: Schema.Schema<ReadonlyArray<Multipart.PersistedFile>>
108
109
 
109
110
  /** @internal */
110
111
  export const schemaPersisted = <R, I extends Partial<Multipart.Persisted>, A>(
111
- schema: Schema.Schema<A, I, R>
112
+ schema: Schema.Schema<A, I, R>,
113
+ options?: ParseOptions | undefined
112
114
  ) => {
113
- const parse = Schema.decodeUnknown(schema)
115
+ const parse = Schema.decodeUnknown(schema, options)
114
116
  return (persisted: Multipart.Persisted) => parse(persisted)
115
117
  }
116
118
 
117
119
  /** @internal */
118
- export const schemaJson = <A, I, R>(schema: Schema.Schema<A, I, R>): {
120
+ export const schemaJson = <A, I, R>(schema: Schema.Schema<A, I, R>, options?: ParseOptions | undefined): {
119
121
  (
120
122
  field: string
121
123
  ): (persisted: Multipart.Persisted) => Effect.Effect<A, ParseResult.ParseError, R>
@@ -140,7 +142,8 @@ export const schemaJson = <A, I, R>(schema: Schema.Schema<A, I, R>): {
140
142
  Schema.decodeUnknown(
141
143
  Schema.struct({
142
144
  [field]: fromJson
143
- })
145
+ }),
146
+ options
144
147
  )(persisted),
145
148
  (_) => _[field]
146
149
  ))
@@ -1,3 +1,4 @@
1
+ import type { ParseOptions } from "@effect/schema/AST"
1
2
  import * as Schema from "@effect/schema/Schema"
2
3
  import type * as Cause from "effect/Cause"
3
4
  import * as Chunk from "effect/Chunk"
@@ -37,22 +38,95 @@ export const params = Effect.map(RouteContext, (_) => _.params)
37
38
  export const searchParams = Effect.map(RouteContext, (_) => _.searchParams)
38
39
 
39
40
  /** @internal */
40
- export const schemaParams = <R, I extends Readonly<Record<string, string>>, A>(schema: Schema.Schema<A, I, R>) => {
41
- const parse = Schema.decodeUnknown(schema)
41
+ export const schemaJson = <
42
+ R,
43
+ I extends {
44
+ readonly method?: Method.Method
45
+ readonly url?: string
46
+ readonly cookies?: Readonly<Record<string, string>>
47
+ readonly headers?: Readonly<Record<string, string>>
48
+ readonly pathParams?: Readonly<Record<string, string>>
49
+ readonly searchParams?: Readonly<Record<string, string>>
50
+ readonly body?: any
51
+ },
52
+ A
53
+ >(
54
+ schema: Schema.Schema<A, I, R>,
55
+ options?: ParseOptions | undefined
56
+ ) => {
57
+ const parse = Schema.decodeUnknown(schema, options)
58
+ return Effect.flatMap(
59
+ ServerRequest.ServerRequest,
60
+ (request) =>
61
+ Effect.flatMap(Effect.zip(request.json, RouteContext), ([body, context]) =>
62
+ parse({
63
+ method: request.method,
64
+ url: request.url,
65
+ headers: request.headers,
66
+ cookies: request.cookies,
67
+ pathParams: context.params,
68
+ searchParams: context.searchParams,
69
+ body
70
+ }))
71
+ )
72
+ }
73
+
74
+ /** @internal */
75
+ export const schemaNoBody = <
76
+ R,
77
+ I extends {
78
+ readonly method?: Method.Method
79
+ readonly url?: string
80
+ readonly cookies?: Readonly<Record<string, string>>
81
+ readonly headers?: Readonly<Record<string, string>>
82
+ readonly pathParams?: Readonly<Record<string, string>>
83
+ readonly searchParams?: Readonly<Record<string, string>>
84
+ },
85
+ A
86
+ >(
87
+ schema: Schema.Schema<A, I, R>,
88
+ options?: ParseOptions | undefined
89
+ ) => {
90
+ const parse = Schema.decodeUnknown(schema, options)
91
+ return Effect.flatMap(
92
+ ServerRequest.ServerRequest,
93
+ (request) =>
94
+ Effect.flatMap(RouteContext, (context) =>
95
+ parse({
96
+ method: request.method,
97
+ url: request.url,
98
+ headers: request.headers,
99
+ cookies: request.cookies,
100
+ pathParams: context.params,
101
+ searchParams: context.searchParams
102
+ }))
103
+ )
104
+ }
105
+
106
+ /** @internal */
107
+ export const schemaParams = <R, I extends Readonly<Record<string, string>>, A>(
108
+ schema: Schema.Schema<A, I, R>,
109
+ options?: ParseOptions | undefined
110
+ ) => {
111
+ const parse = Schema.decodeUnknown(schema, options)
42
112
  return Effect.flatMap(RouteContext, (_) => parse({ ..._.searchParams, ..._.params }))
43
113
  }
44
114
 
45
115
  /** @internal */
46
- export const schemaPathParams = <R, I extends Readonly<Record<string, string>>, A>(schema: Schema.Schema<A, I, R>) => {
47
- const parse = Schema.decodeUnknown(schema)
116
+ export const schemaPathParams = <R, I extends Readonly<Record<string, string>>, A>(
117
+ schema: Schema.Schema<A, I, R>,
118
+ options?: ParseOptions | undefined
119
+ ) => {
120
+ const parse = Schema.decodeUnknown(schema, options)
48
121
  return Effect.flatMap(RouteContext, (_) => parse(_.params))
49
122
  }
50
123
 
51
124
  /** @internal */
52
125
  export const schemaSearchParams = <R, I extends Readonly<Record<string, string>>, A>(
53
- schema: Schema.Schema<A, I, R>
126
+ schema: Schema.Schema<A, I, R>,
127
+ options?: ParseOptions | undefined
54
128
  ) => {
55
- const parse = Schema.decodeUnknown(schema)
129
+ const parse = Schema.decodeUnknown(schema, options)
56
130
  return Effect.flatMap(RouteContext, (_) => parse(_.searchParams))
57
131
  }
58
132
 
@@ -1,5 +1,6 @@
1
+ import type { ParseOptions } from "@effect/schema/AST"
1
2
  import type * as ParseResult from "@effect/schema/ParseResult"
2
- import type * as Schema from "@effect/schema/Schema"
3
+ import * as Schema from "@effect/schema/Schema"
3
4
  import * as Channel from "effect/Channel"
4
5
  import * as Context from "effect/Context"
5
6
  import * as Effect from "effect/Effect"
@@ -36,14 +37,26 @@ export const upgradeChannel = <IE = never>() => Channel.unwrap(Effect.map(upgrad
36
37
  export const multipartPersisted = Effect.flatMap(serverRequestTag, (request) => request.multipart)
37
38
 
38
39
  /** @internal */
39
- export const schemaHeaders = <R, I extends Readonly<Record<string, string>>, A>(schema: Schema.Schema<A, I, R>) => {
40
- const parse = IncomingMessage.schemaHeaders(schema)
40
+ export const schemaCookies = <R, I extends Readonly<Record<string, string>>, A>(
41
+ schema: Schema.Schema<A, I, R>,
42
+ options?: ParseOptions | undefined
43
+ ) => {
44
+ const parse = Schema.decodeUnknown(schema, options)
45
+ return Effect.flatMap(serverRequestTag, (req) => parse(req.cookies))
46
+ }
47
+
48
+ /** @internal */
49
+ export const schemaHeaders = <R, I extends Readonly<Record<string, string>>, A>(
50
+ schema: Schema.Schema<A, I, R>,
51
+ options?: ParseOptions | undefined
52
+ ) => {
53
+ const parse = IncomingMessage.schemaHeaders(schema, options)
41
54
  return Effect.flatMap(serverRequestTag, parse)
42
55
  }
43
56
 
44
57
  /** @internal */
45
- export const schemaBodyJson = <A, I, R>(schema: Schema.Schema<A, I, R>) => {
46
- const parse = IncomingMessage.schemaBodyJson(schema)
58
+ export const schemaBodyJson = <A, I, R>(schema: Schema.Schema<A, I, R>, options?: ParseOptions | undefined) => {
59
+ const parse = IncomingMessage.schemaBodyJson(schema, options)
47
60
  return Effect.flatMap(serverRequestTag, parse)
48
61
  }
49
62
 
@@ -52,10 +65,11 @@ const isMultipart = (request: ServerRequest.ServerRequest) =>
52
65
 
53
66
  /** @internal */
54
67
  export const schemaBodyForm = <R, I extends Partial<Multipart.Persisted>, A>(
55
- schema: Schema.Schema<A, I, R>
68
+ schema: Schema.Schema<A, I, R>,
69
+ options?: ParseOptions | undefined
56
70
  ) => {
57
- const parseMultipart = Multipart.schemaPersisted(schema)
58
- const parseUrlParams = IncomingMessage.schemaBodyUrlParams(schema as Schema.Schema<A, any, R>)
71
+ const parseMultipart = Multipart.schemaPersisted(schema, options)
72
+ const parseUrlParams = IncomingMessage.schemaBodyUrlParams(schema as Schema.Schema<A, any, R>, options)
59
73
  return Effect.flatMap(serverRequestTag, (request): Effect.Effect<
60
74
  A,
61
75
  Multipart.MultipartError | ParseResult.ParseError | Error.RequestError,
@@ -70,24 +84,26 @@ export const schemaBodyForm = <R, I extends Partial<Multipart.Persisted>, A>(
70
84
 
71
85
  /** @internal */
72
86
  export const schemaBodyUrlParams = <R, I extends Readonly<Record<string, string>>, A>(
73
- schema: Schema.Schema<A, I, R>
87
+ schema: Schema.Schema<A, I, R>,
88
+ options?: ParseOptions | undefined
74
89
  ) => {
75
- const parse = IncomingMessage.schemaBodyUrlParams(schema)
90
+ const parse = IncomingMessage.schemaBodyUrlParams(schema, options)
76
91
  return Effect.flatMap(serverRequestTag, parse)
77
92
  }
78
93
 
79
94
  /** @internal */
80
95
  export const schemaBodyMultipart = <R, I extends Partial<Multipart.Persisted>, A>(
81
- schema: Schema.Schema<A, I, R>
96
+ schema: Schema.Schema<A, I, R>,
97
+ options?: ParseOptions | undefined
82
98
  ) => {
83
- const parse = Multipart.schemaPersisted(schema)
99
+ const parse = Multipart.schemaPersisted(schema, options)
84
100
  return Effect.flatMap(multipartPersisted, parse)
85
101
  }
86
102
 
87
103
  /** @internal */
88
- export const schemaBodyFormJson = <A, I, R>(schema: Schema.Schema<A, I, R>) => {
89
- const parseMultipart = Multipart.schemaJson(schema)
90
- const parseUrlParams = UrlParams.schemaJson(schema)
104
+ export const schemaBodyFormJson = <A, I, R>(schema: Schema.Schema<A, I, R>, options?: ParseOptions | undefined) => {
105
+ const parseMultipart = Multipart.schemaJson(schema, options)
106
+ const parseUrlParams = UrlParams.schemaJson(schema, options)
91
107
  return (field: string) =>
92
108
  Effect.flatMap(
93
109
  serverRequestTag,