@effect/platform 0.47.0 → 0.48.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 (133) hide show
  1. package/dist/cjs/Error.js +40 -4
  2. package/dist/cjs/Error.js.map +1 -1
  3. package/dist/cjs/Http/Body.js +8 -1
  4. package/dist/cjs/Http/Body.js.map +1 -1
  5. package/dist/cjs/Http/ClientError.js +21 -2
  6. package/dist/cjs/Http/ClientError.js.map +1 -1
  7. package/dist/cjs/Http/Headers.js +22 -1
  8. package/dist/cjs/Http/Headers.js.map +1 -1
  9. package/dist/cjs/Http/IncomingMessage.js +1 -1
  10. package/dist/cjs/Http/IncomingMessage.js.map +1 -1
  11. package/dist/cjs/Http/Multipart.js +21 -6
  12. package/dist/cjs/Http/Multipart.js.map +1 -1
  13. package/dist/cjs/Http/ServerError.js +30 -7
  14. package/dist/cjs/Http/ServerError.js.map +1 -1
  15. package/dist/cjs/Http/UrlParams.js +7 -2
  16. package/dist/cjs/Http/UrlParams.js.map +1 -1
  17. package/dist/cjs/PlatformLogger.js +1 -1
  18. package/dist/cjs/Socket.js +104 -22
  19. package/dist/cjs/Socket.js.map +1 -1
  20. package/dist/cjs/Transferable.js +1 -1
  21. package/dist/cjs/Transferable.js.map +1 -1
  22. package/dist/cjs/WorkerError.js.map +1 -1
  23. package/dist/cjs/internal/http/body.js +1 -1
  24. package/dist/cjs/internal/http/body.js.map +1 -1
  25. package/dist/cjs/internal/http/client.js +5 -5
  26. package/dist/cjs/internal/http/client.js.map +1 -1
  27. package/dist/cjs/internal/http/clientError.js +1 -36
  28. package/dist/cjs/internal/http/clientError.js.map +1 -1
  29. package/dist/cjs/internal/http/clientResponse.js +8 -8
  30. package/dist/cjs/internal/http/clientResponse.js.map +1 -1
  31. package/dist/cjs/internal/http/multipart.js +15 -11
  32. package/dist/cjs/internal/http/multipart.js.map +1 -1
  33. package/dist/cjs/internal/http/multiplex.js +1 -1
  34. package/dist/cjs/internal/http/multiplex.js.map +1 -1
  35. package/dist/cjs/internal/http/router.js +1 -1
  36. package/dist/cjs/internal/http/router.js.map +1 -1
  37. package/dist/cjs/internal/http/serverError.js +1 -15
  38. package/dist/cjs/internal/http/serverError.js.map +1 -1
  39. package/dist/cjs/internal/http/serverRequest.js +8 -8
  40. package/dist/cjs/internal/http/serverRequest.js.map +1 -1
  41. package/dist/dts/Error.d.ts +22 -0
  42. package/dist/dts/Error.d.ts.map +1 -1
  43. package/dist/dts/Http/Body.d.ts +9 -1
  44. package/dist/dts/Http/Body.d.ts.map +1 -1
  45. package/dist/dts/Http/ClientError.d.ts +21 -33
  46. package/dist/dts/Http/ClientError.d.ts.map +1 -1
  47. package/dist/dts/Http/Headers.d.ts +19 -0
  48. package/dist/dts/Http/Headers.d.ts.map +1 -1
  49. package/dist/dts/Http/Multipart.d.ts +21 -6
  50. package/dist/dts/Http/Multipart.d.ts.map +1 -1
  51. package/dist/dts/Http/ServerError.d.ts +33 -47
  52. package/dist/dts/Http/ServerError.d.ts.map +1 -1
  53. package/dist/dts/Http/ServerRequest.d.ts +3 -3
  54. package/dist/dts/Http/ServerRequest.d.ts.map +1 -1
  55. package/dist/dts/Http/UrlParams.d.ts +5 -0
  56. package/dist/dts/Http/UrlParams.d.ts.map +1 -1
  57. package/dist/dts/PlatformLogger.d.ts +1 -1
  58. package/dist/dts/Runtime.d.ts +4 -1
  59. package/dist/dts/Runtime.d.ts.map +1 -1
  60. package/dist/dts/Socket.d.ts +89 -13
  61. package/dist/dts/Socket.d.ts.map +1 -1
  62. package/dist/dts/Worker.d.ts +6 -6
  63. package/dist/dts/Worker.d.ts.map +1 -1
  64. package/dist/dts/WorkerError.d.ts +10 -5
  65. package/dist/dts/WorkerError.d.ts.map +1 -1
  66. package/dist/dts/WorkerRunner.d.ts +1 -1
  67. package/dist/dts/WorkerRunner.d.ts.map +1 -1
  68. package/dist/esm/Error.js +38 -3
  69. package/dist/esm/Error.js.map +1 -1
  70. package/dist/esm/Http/Body.js +6 -0
  71. package/dist/esm/Http/Body.js.map +1 -1
  72. package/dist/esm/Http/ClientError.js +19 -2
  73. package/dist/esm/Http/ClientError.js.map +1 -1
  74. package/dist/esm/Http/Headers.js +21 -1
  75. package/dist/esm/Http/Headers.js.map +1 -1
  76. package/dist/esm/Http/IncomingMessage.js +1 -1
  77. package/dist/esm/Http/IncomingMessage.js.map +1 -1
  78. package/dist/esm/Http/Multipart.js +20 -5
  79. package/dist/esm/Http/Multipart.js.map +1 -1
  80. package/dist/esm/Http/ServerError.js +26 -7
  81. package/dist/esm/Http/ServerError.js.map +1 -1
  82. package/dist/esm/Http/UrlParams.js +5 -0
  83. package/dist/esm/Http/UrlParams.js.map +1 -1
  84. package/dist/esm/PlatformLogger.js +1 -1
  85. package/dist/esm/Socket.js +98 -20
  86. package/dist/esm/Socket.js.map +1 -1
  87. package/dist/esm/Transferable.js +1 -1
  88. package/dist/esm/Transferable.js.map +1 -1
  89. package/dist/esm/WorkerError.js.map +1 -1
  90. package/dist/esm/internal/http/body.js +1 -1
  91. package/dist/esm/internal/http/body.js.map +1 -1
  92. package/dist/esm/internal/http/client.js +5 -5
  93. package/dist/esm/internal/http/client.js.map +1 -1
  94. package/dist/esm/internal/http/clientError.js +0 -10
  95. package/dist/esm/internal/http/clientError.js.map +1 -1
  96. package/dist/esm/internal/http/clientResponse.js +8 -8
  97. package/dist/esm/internal/http/clientResponse.js.map +1 -1
  98. package/dist/esm/internal/http/multipart.js +10 -9
  99. package/dist/esm/internal/http/multipart.js.map +1 -1
  100. package/dist/esm/internal/http/multiplex.js +1 -1
  101. package/dist/esm/internal/http/multiplex.js.map +1 -1
  102. package/dist/esm/internal/http/router.js +1 -1
  103. package/dist/esm/internal/http/router.js.map +1 -1
  104. package/dist/esm/internal/http/serverError.js +0 -14
  105. package/dist/esm/internal/http/serverError.js.map +1 -1
  106. package/dist/esm/internal/http/serverRequest.js +8 -8
  107. package/dist/esm/internal/http/serverRequest.js.map +1 -1
  108. package/package.json +3 -3
  109. package/src/Error.ts +61 -0
  110. package/src/Http/Body.ts +14 -1
  111. package/src/Http/ClientError.ts +21 -38
  112. package/src/Http/Headers.ts +29 -1
  113. package/src/Http/IncomingMessage.ts +1 -1
  114. package/src/Http/Multipart.ts +25 -7
  115. package/src/Http/ServerError.ts +25 -56
  116. package/src/Http/ServerRequest.ts +5 -5
  117. package/src/Http/UrlParams.ts +10 -0
  118. package/src/PlatformLogger.ts +1 -1
  119. package/src/Runtime.ts +4 -1
  120. package/src/Socket.ts +179 -39
  121. package/src/Transferable.ts +1 -1
  122. package/src/Worker.ts +6 -6
  123. package/src/WorkerError.ts +9 -7
  124. package/src/WorkerRunner.ts +8 -8
  125. package/src/internal/http/body.ts +4 -2
  126. package/src/internal/http/client.ts +5 -6
  127. package/src/internal/http/clientError.ts +0 -14
  128. package/src/internal/http/clientResponse.ts +15 -14
  129. package/src/internal/http/multipart.ts +16 -12
  130. package/src/internal/http/multiplex.ts +1 -1
  131. package/src/internal/http/router.ts +1 -1
  132. package/src/internal/http/serverError.ts +0 -20
  133. package/src/internal/http/serverRequest.ts +22 -18
@@ -55,22 +55,24 @@ export class WorkerError extends Schema.TaggedError<WorkerError>()("WorkerError"
55
55
  */
56
56
  static readonly Cause: Schema.Schema<
57
57
  Cause.Cause<WorkerError>,
58
- Schema.CauseFrom<WorkerErrorFrom>
58
+ Schema.CauseEncoded<WorkerErrorFrom>
59
59
  > = Schema.cause({ defect: causeDefectPretty, error: this })
60
60
 
61
61
  /**
62
62
  * @since 1.0.0
63
63
  */
64
- static readonly encodeCause: (a: Cause.Cause<WorkerError>) => Schema.CauseFrom<WorkerErrorFrom> = Schema.encodeSync(
65
- this.Cause
66
- )
64
+ static readonly encodeCause: (a: Cause.Cause<WorkerError>) => Schema.CauseEncoded<WorkerErrorFrom> = Schema
65
+ .encodeSync(
66
+ this.Cause
67
+ )
67
68
 
68
69
  /**
69
70
  * @since 1.0.0
70
71
  */
71
- static readonly decodeCause: (u: Schema.CauseFrom<WorkerErrorFrom>) => Cause.Cause<WorkerError> = Schema.decodeSync(
72
- this.Cause
73
- )
72
+ static readonly decodeCause: (u: Schema.CauseEncoded<WorkerErrorFrom>) => Cause.Cause<WorkerError> = Schema
73
+ .decodeSync(
74
+ this.Cause
75
+ )
74
76
 
75
77
  /**
76
78
  * @since 1.0.0
@@ -121,19 +121,19 @@ export declare namespace SerializedRunner {
121
121
  A,
122
122
  { readonly _tag: K }
123
123
  > extends Serializable.SerializableWithResult<
124
- infer _RS,
125
- infer _IS,
126
124
  infer S,
127
- infer _RR,
128
- infer _IE,
125
+ infer _SI,
126
+ infer _SR,
127
+ infer A,
128
+ infer _AI,
129
129
  infer E,
130
- infer _IO,
131
- infer O
130
+ infer _EI,
131
+ infer _RR
132
132
  > ? (
133
133
  _: S
134
134
  ) =>
135
- | Stream.Stream<O, E, any>
136
- | Effect.Effect<O, E, any>
135
+ | Stream.Stream<A, E, any>
136
+ | Effect.Effect<A, E, any>
137
137
  | Layer.Layer<any, E, any>
138
138
  | Layer.Layer<never, E, any>
139
139
  : never
@@ -48,8 +48,10 @@ class RawImpl implements Body.Raw {
48
48
  }
49
49
 
50
50
  /** @internal */
51
- export const raw = (body: unknown, contentType?: string, contentLength?: number): Body.Raw =>
52
- new RawImpl(body, contentType, contentLength)
51
+ export const raw = (body: unknown, options?: {
52
+ readonly contentType?: string
53
+ readonly contentLength?: number
54
+ }): Body.Raw => new RawImpl(body, options?.contentType, options?.contentLength)
53
55
 
54
56
  class Uint8ArrayImpl implements Body.Uint8Array {
55
57
  readonly [TypeId]: Body.TypeId
@@ -11,13 +11,12 @@ import type * as Scope from "effect/Scope"
11
11
  import * as Stream from "effect/Stream"
12
12
  import type * as Body from "../../Http/Body.js"
13
13
  import type * as Client from "../../Http/Client.js"
14
- import type * as Error from "../../Http/ClientError.js"
14
+ import * as Error from "../../Http/ClientError.js"
15
15
  import type * as ClientRequest from "../../Http/ClientRequest.js"
16
16
  import type * as ClientResponse from "../../Http/ClientResponse.js"
17
17
  import * as Method from "../../Http/Method.js"
18
18
  import * as UrlParams from "../../Http/UrlParams.js"
19
19
  import * as internalBody from "./body.js"
20
- import * as internalError from "./clientError.js"
21
20
  import * as internalRequest from "./clientRequest.js"
22
21
  import * as internalResponse from "./clientResponse.js"
23
22
 
@@ -82,7 +81,7 @@ export const fetch = (options?: RequestInit): Client.Client.Default =>
82
81
  makeDefault((request) =>
83
82
  Effect.flatMap(
84
83
  UrlParams.makeUrl(request.url, request.urlParams, (_) =>
85
- internalError.requestError({
84
+ new Error.RequestError({
86
85
  request,
87
86
  reason: "InvalidUrl",
88
87
  error: _
@@ -109,7 +108,7 @@ export const fetch = (options?: RequestInit): Client.Client.Default =>
109
108
  signal: controller.signal
110
109
  } as any),
111
110
  catch: (_) =>
112
- internalError.requestError({
111
+ new Error.RequestError({
113
112
  request,
114
113
  reason: "Transport",
115
114
  error: _
@@ -419,7 +418,7 @@ export const filterStatus = dual<
419
418
  effect,
420
419
  (response) => f(response.status),
421
420
  (response) =>
422
- internalError.responseError({
421
+ new Error.ResponseError({
423
422
  request,
424
423
  response,
425
424
  reason: "StatusCode",
@@ -571,7 +570,7 @@ export const schemaFunction = dual<
571
570
  Effect.tryMap(encode(a), {
572
571
  try: (body) => new TextEncoder().encode(JSON.stringify(body)),
573
572
  catch: (error) =>
574
- internalError.requestError({
573
+ new Error.RequestError({
575
574
  request,
576
575
  reason: "Encode",
577
576
  error
@@ -1,20 +1,6 @@
1
- import * as Data from "effect/Data"
2
1
  import type * as Error from "../../Http/ClientError.js"
3
2
 
4
3
  /** @internal */
5
4
  export const TypeId: Error.TypeId = Symbol.for(
6
5
  "@effect/platform/Http/Error"
7
6
  ) as Error.TypeId
8
-
9
- const make = <A extends Error.HttpClientError>(tag: A["_tag"]) => (props: Omit<A, Error.HttpError.ProvidedFields>): A =>
10
- Data.struct({
11
- [TypeId]: TypeId,
12
- _tag: tag,
13
- ...props
14
- } as A)
15
-
16
- /** @internal */
17
- export const requestError = make<Error.RequestError>("RequestError")
18
-
19
- /** @internal */
20
- export const responseError = make<Error.ResponseError>("ResponseError")
@@ -3,13 +3,12 @@ import * as Schema from "@effect/schema/Schema"
3
3
  import * as Effect from "effect/Effect"
4
4
  import * as Option from "effect/Option"
5
5
  import * as Stream from "effect/Stream"
6
- import type * as Error from "../../Http/ClientError.js"
6
+ import * as Error from "../../Http/ClientError.js"
7
7
  import type * as ClientRequest from "../../Http/ClientRequest.js"
8
8
  import type * as ClientResponse from "../../Http/ClientResponse.js"
9
9
  import * as Headers from "../../Http/Headers.js"
10
10
  import * as IncomingMessage from "../../Http/IncomingMessage.js"
11
11
  import * as UrlParams from "../../Http/UrlParams.js"
12
- import * as internalError from "./clientError.js"
13
12
 
14
13
  /** @internal */
15
14
  export const TypeId: ClientResponse.TypeId = Symbol.for("@effect/platform/Http/ClientResponse") as ClientResponse.TypeId
@@ -47,25 +46,27 @@ class ClientResponseImpl implements ClientResponse.ClientResponse {
47
46
  get stream(): Stream.Stream<Uint8Array, Error.ResponseError> {
48
47
  return this.source.body
49
48
  ? Stream.fromReadableStream(() => this.source.body!, (_) =>
50
- internalError.responseError({
49
+ new Error.ResponseError({
51
50
  request: this.request,
52
51
  response: this,
53
52
  reason: "Decode",
54
53
  error: _
55
54
  }))
56
- : Stream.fail(internalError.responseError({
57
- request: this.request,
58
- response: this,
59
- reason: "EmptyBody",
60
- error: "can not create stream from empty body"
61
- }))
55
+ : Stream.fail(
56
+ new Error.ResponseError({
57
+ request: this.request,
58
+ response: this,
59
+ reason: "EmptyBody",
60
+ error: "can not create stream from empty body"
61
+ })
62
+ )
62
63
  }
63
64
 
64
65
  get json(): Effect.Effect<unknown, Error.ResponseError> {
65
66
  return Effect.tryMap(this.text, {
66
67
  try: (text) => text === "" ? null : JSON.parse(text) as unknown,
67
68
  catch: (_) =>
68
- internalError.responseError({
69
+ new Error.ResponseError({
69
70
  request: this.request,
70
71
  response: this,
71
72
  reason: "Decode",
@@ -79,7 +80,7 @@ class ClientResponseImpl implements ClientResponse.ClientResponse {
79
80
  return this.textBody ??= Effect.tryPromise({
80
81
  try: () => this.source.text(),
81
82
  catch: (_) =>
82
- internalError.responseError({
83
+ new Error.ResponseError({
83
84
  request: this.request,
84
85
  response: this,
85
86
  reason: "Decode",
@@ -93,7 +94,7 @@ class ClientResponseImpl implements ClientResponse.ClientResponse {
93
94
  Effect.try({
94
95
  try: () => UrlParams.fromInput(new URLSearchParams(_)),
95
96
  catch: (_) =>
96
- internalError.responseError({
97
+ new Error.ResponseError({
97
98
  request: this.request,
98
99
  response: this,
99
100
  reason: "Decode",
@@ -107,7 +108,7 @@ class ClientResponseImpl implements ClientResponse.ClientResponse {
107
108
  return this.formDataBody ??= Effect.tryPromise({
108
109
  try: () => this.source.formData(),
109
110
  catch: (_) =>
110
- internalError.responseError({
111
+ new Error.ResponseError({
111
112
  request: this.request,
112
113
  response: this,
113
114
  reason: "Decode",
@@ -121,7 +122,7 @@ class ClientResponseImpl implements ClientResponse.ClientResponse {
121
122
  return this.arrayBufferBody ??= Effect.tryPromise({
122
123
  try: () => this.source.arrayBuffer(),
123
124
  catch: (_) =>
124
- internalError.responseError({
125
+ new Error.ResponseError({
125
126
  request: this.request,
126
127
  response: this,
127
128
  reason: "Decode",
@@ -23,6 +23,19 @@ import * as Path from "../../Path.js"
23
23
  /** @internal */
24
24
  export const TypeId: Multipart.TypeId = Symbol.for("@effect/platform/Http/Multipart") as Multipart.TypeId
25
25
 
26
+ /** @internal */
27
+ export const isPart = (u: unknown): u is Multipart.Part => Predicate.hasProperty(u, TypeId)
28
+
29
+ /** @internal */
30
+ export const isField = (u: unknown): u is Multipart.Field => isPart(u) && u._tag === "Field"
31
+
32
+ /** @internal */
33
+ export const isFile = (u: unknown): u is Multipart.File => isPart(u) && u._tag === "File"
34
+
35
+ /** @internal */
36
+ export const isPersistedFile = (u: unknown): u is Multipart.PersistedFile =>
37
+ Predicate.hasProperty(u, TypeId) && Predicate.isTagged(u, "PersistedFile")
38
+
26
39
  /** @internal */
27
40
  export const ErrorTypeId: Multipart.ErrorTypeId = Symbol.for(
28
41
  "@effect/platform/Http/Multipart/MultipartError"
@@ -37,10 +50,6 @@ export const MultipartError = (reason: Multipart.MultipartError["reason"], error
37
50
  error
38
51
  })
39
52
 
40
- /** @internal */
41
- export const isField = (u: unknown): u is Multipart.Field =>
42
- Predicate.hasProperty(u, TypeId) && Predicate.isTagged(u, "Field")
43
-
44
53
  /** @internal */
45
54
  export const maxParts: FiberRef.FiberRef<Option.Option<number>> = globalValue(
46
55
  "@effect/platform/Http/Multipart/maxParts",
@@ -89,20 +98,15 @@ export const withFieldMimeTypes = dual<
89
98
  <R, E, A>(effect: Effect.Effect<A, E, R>, mimeTypes: ReadonlyArray<string>) => Effect.Effect<A, E, R>
90
99
  >(2, (effect, mimeTypes) => Effect.locally(effect, fieldMimeTypes, Chunk.fromIterable(mimeTypes)))
91
100
 
92
- const fileSchema: Schema.Schema<Multipart.PersistedFile> = Schema.struct({
93
- [TypeId]: Schema.uniqueSymbol(TypeId),
94
- _tag: Schema.literal("PersistedFile"),
95
- key: Schema.string,
96
- name: Schema.string,
97
- contentType: Schema.string,
98
- path: Schema.string
101
+ const fileSchema: Schema.Schema<Multipart.PersistedFile> = Schema.declare(isPersistedFile, {
102
+ identifier: "PersistedFile"
99
103
  })
100
104
 
101
105
  /** @internal */
102
106
  export const filesSchema: Schema.Schema<ReadonlyArray<Multipart.PersistedFile>> = Schema.array(fileSchema)
103
107
 
104
108
  /** @internal */
105
- export const schemaPersisted = <R, I extends Multipart.Persisted, A>(
109
+ export const schemaPersisted = <R, I extends Partial<Multipart.Persisted>, A>(
106
110
  schema: Schema.Schema<A, I, R>
107
111
  ) => {
108
112
  const parse = Schema.decodeUnknown(schema)
@@ -29,7 +29,7 @@ class MultiplexImpl<R, E>
29
29
  this[TypeId] = TypeId
30
30
 
31
31
  let execute: (request: ServerRequest.ServerRequest) => App.Default<R, E | Error.RouteNotFound> = (request) =>
32
- Effect.fail(Error.RouteNotFound({ request }))
32
+ Effect.fail(new Error.RouteNotFound({ request }))
33
33
 
34
34
  for (let i = apps.length - 1; i >= 0; i--) {
35
35
  const [predicate, app] = apps[i]
@@ -151,7 +151,7 @@ const toHttpApp = <R, E>(
151
151
  result = router.find("GET", request.url)
152
152
  }
153
153
  if (result === undefined) {
154
- return Effect.fail(Error.RouteNotFound({ request }))
154
+ return Effect.fail(new Error.RouteNotFound({ request }))
155
155
  }
156
156
  const route = result.handler
157
157
  if (route.prefix._tag === "Some") {
@@ -1,5 +1,4 @@
1
1
  import * as Cause from "effect/Cause"
2
- import * as Data from "effect/Data"
3
2
  import * as FiberId from "effect/FiberId"
4
3
  import { globalValue } from "effect/GlobalValue"
5
4
  import * as Option from "effect/Option"
@@ -11,28 +10,9 @@ export const TypeId: Error.TypeId = Symbol.for(
11
10
  "@effect/platform/Http/Error"
12
11
  ) as Error.TypeId
13
12
 
14
- const make = <A extends Error.HttpServerError>(tag: A["_tag"]) => (props: Omit<A, Error.HttpError.ProvidedFields>): A =>
15
- Data.struct({
16
- [TypeId]: TypeId,
17
- _tag: tag,
18
- ...props
19
- } as A)
20
-
21
13
  /** @internal */
22
14
  export const isServerError = (u: unknown): u is Error.HttpServerError => Predicate.hasProperty(u, TypeId)
23
15
 
24
- /** @internal */
25
- export const requestError = make<Error.RequestError>("RequestError")
26
-
27
- /** @internal */
28
- export const responseError = make<Error.ResponseError>("ResponseError")
29
-
30
- /** @internal */
31
- export const routeNotFound = make<Error.RouteNotFound>("RouteNotFound")
32
-
33
- /** @internal */
34
- export const serveError = make<Error.ServeError>("ServeError")
35
-
36
16
  /** @internal */
37
17
  export const clientAbortFiberId = globalValue(
38
18
  "@effect/platform/Http/ServerError/clientAbortFiberId",
@@ -48,7 +48,7 @@ const isMultipart = (request: ServerRequest.ServerRequest) =>
48
48
  request.headers["content-type"]?.toLowerCase().includes("multipart/form-data")
49
49
 
50
50
  /** @internal */
51
- export const schemaBodyForm = <R, I extends Multipart.Persisted, A>(
51
+ export const schemaBodyForm = <R, I extends Partial<Multipart.Persisted>, A>(
52
52
  schema: Schema.Schema<A, I, R>
53
53
  ) => {
54
54
  const parseMultipart = Multipart.schemaPersisted(schema)
@@ -74,7 +74,7 @@ export const schemaBodyUrlParams = <R, I extends Readonly<Record<string, string>
74
74
  }
75
75
 
76
76
  /** @internal */
77
- export const schemaBodyMultipart = <R, I extends Multipart.Persisted, A>(
77
+ export const schemaBodyMultipart = <R, I extends Partial<Multipart.Persisted>, A>(
78
78
  schema: Schema.Schema<A, I, R>
79
79
  ) => {
80
80
  const parse = Multipart.schemaPersisted(schema)
@@ -98,7 +98,7 @@ export const schemaBodyFormJson = <A, I, R>(schema: Schema.Schema<A, I, R>) => {
98
98
  if (isMultipart(request)) {
99
99
  return Effect.flatMap(
100
100
  Effect.mapError(request.multipart, (error) =>
101
- Error.RequestError({
101
+ new Error.RequestError({
102
102
  request,
103
103
  reason: "Decode",
104
104
  error
@@ -158,16 +158,18 @@ class ServerRequestImpl implements ServerRequest.ServerRequest {
158
158
  get stream(): Stream.Stream<Uint8Array, Error.RequestError> {
159
159
  return this.source.body
160
160
  ? Stream.fromReadableStream(() => this.source.body as any, (_) =>
161
- Error.RequestError({
161
+ new Error.RequestError({
162
162
  request: this,
163
163
  reason: "Decode",
164
164
  error: _
165
165
  }))
166
- : Stream.fail(Error.RequestError({
167
- request: this,
168
- reason: "Decode",
169
- error: "can not create stream from empty body"
170
- }))
166
+ : Stream.fail(
167
+ new Error.RequestError({
168
+ request: this,
169
+ reason: "Decode",
170
+ error: "can not create stream from empty body"
171
+ })
172
+ )
171
173
  }
172
174
 
173
175
  private textEffect: Effect.Effect<string, Error.RequestError> | undefined
@@ -179,7 +181,7 @@ class ServerRequestImpl implements ServerRequest.ServerRequest {
179
181
  Effect.tryPromise({
180
182
  try: () => this.source.text(),
181
183
  catch: (error) =>
182
- Error.RequestError({
184
+ new Error.RequestError({
183
185
  request: this,
184
186
  reason: "Decode",
185
187
  error
@@ -193,7 +195,7 @@ class ServerRequestImpl implements ServerRequest.ServerRequest {
193
195
  return Effect.tryMap(this.text, {
194
196
  try: (_) => JSON.parse(_) as unknown,
195
197
  catch: (error) =>
196
- Error.RequestError({
198
+ new Error.RequestError({
197
199
  request: this,
198
200
  reason: "Decode",
199
201
  error
@@ -206,7 +208,7 @@ class ServerRequestImpl implements ServerRequest.ServerRequest {
206
208
  Effect.try({
207
209
  try: () => UrlParams.fromInput(new URLSearchParams(_)),
208
210
  catch: (error) =>
209
- Error.RequestError({
211
+ new Error.RequestError({
210
212
  request: this,
211
213
  reason: "Decode",
212
214
  error
@@ -251,7 +253,7 @@ class ServerRequestImpl implements ServerRequest.ServerRequest {
251
253
  Effect.tryPromise({
252
254
  try: () => this.source.arrayBuffer(),
253
255
  catch: (error) =>
254
- Error.RequestError({
256
+ new Error.RequestError({
255
257
  request: this,
256
258
  reason: "Decode",
257
259
  error
@@ -262,10 +264,12 @@ class ServerRequestImpl implements ServerRequest.ServerRequest {
262
264
  }
263
265
 
264
266
  get upgrade(): Effect.Effect<Socket.Socket, Error.RequestError> {
265
- return Effect.fail(Error.RequestError({
266
- request: this,
267
- reason: "Decode",
268
- error: "Not an upgradeable ServerRequest"
269
- }))
267
+ return Effect.fail(
268
+ new Error.RequestError({
269
+ request: this,
270
+ reason: "Decode",
271
+ error: "Not an upgradeable ServerRequest"
272
+ })
273
+ )
270
274
  }
271
275
  }