@effect/platform 0.58.26 → 0.59.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 (85) hide show
  1. package/dist/cjs/Error.js +1 -25
  2. package/dist/cjs/Error.js.map +1 -1
  3. package/dist/cjs/HttpClientError.js +5 -6
  4. package/dist/cjs/HttpClientError.js.map +1 -1
  5. package/dist/cjs/HttpServerError.js +6 -5
  6. package/dist/cjs/HttpServerError.js.map +1 -1
  7. package/dist/cjs/Multipart.js.map +1 -1
  8. package/dist/cjs/Socket.js +11 -11
  9. package/dist/cjs/Socket.js.map +1 -1
  10. package/dist/cjs/Worker.js +10 -1
  11. package/dist/cjs/Worker.js.map +1 -1
  12. package/dist/cjs/WorkerError.js +13 -4
  13. package/dist/cjs/WorkerError.js.map +1 -1
  14. package/dist/cjs/WorkerRunner.js +6 -1
  15. package/dist/cjs/WorkerRunner.js.map +1 -1
  16. package/dist/cjs/internal/httpClient.js +7 -7
  17. package/dist/cjs/internal/httpClient.js.map +1 -1
  18. package/dist/cjs/internal/httpClientResponse.js +13 -13
  19. package/dist/cjs/internal/httpClientResponse.js.map +1 -1
  20. package/dist/cjs/internal/httpServerRequest.js +16 -16
  21. package/dist/cjs/internal/httpServerRequest.js.map +1 -1
  22. package/dist/cjs/internal/multipart.js +16 -16
  23. package/dist/cjs/internal/multipart.js.map +1 -1
  24. package/dist/cjs/internal/worker.js +126 -59
  25. package/dist/cjs/internal/worker.js.map +1 -1
  26. package/dist/cjs/internal/workerRunner.js +43 -64
  27. package/dist/cjs/internal/workerRunner.js.map +1 -1
  28. package/dist/dts/Error.d.ts +0 -10
  29. package/dist/dts/Error.d.ts.map +1 -1
  30. package/dist/dts/HttpClientError.d.ts +6 -8
  31. package/dist/dts/HttpClientError.d.ts.map +1 -1
  32. package/dist/dts/HttpServerError.d.ts +10 -13
  33. package/dist/dts/HttpServerError.d.ts.map +1 -1
  34. package/dist/dts/Multipart.d.ts +3 -2
  35. package/dist/dts/Multipart.d.ts.map +1 -1
  36. package/dist/dts/Socket.d.ts +2 -4
  37. package/dist/dts/Socket.d.ts.map +1 -1
  38. package/dist/dts/Worker.d.ts +27 -27
  39. package/dist/dts/Worker.d.ts.map +1 -1
  40. package/dist/dts/WorkerError.d.ts +2 -2
  41. package/dist/dts/WorkerError.d.ts.map +1 -1
  42. package/dist/dts/WorkerRunner.d.ts +8 -5
  43. package/dist/dts/WorkerRunner.d.ts.map +1 -1
  44. package/dist/esm/Error.js +0 -23
  45. package/dist/esm/Error.js.map +1 -1
  46. package/dist/esm/HttpClientError.js +5 -6
  47. package/dist/esm/HttpClientError.js.map +1 -1
  48. package/dist/esm/HttpServerError.js +7 -6
  49. package/dist/esm/HttpServerError.js.map +1 -1
  50. package/dist/esm/Multipart.js.map +1 -1
  51. package/dist/esm/Socket.js +12 -12
  52. package/dist/esm/Socket.js.map +1 -1
  53. package/dist/esm/Worker.js +9 -0
  54. package/dist/esm/Worker.js.map +1 -1
  55. package/dist/esm/WorkerError.js +13 -4
  56. package/dist/esm/WorkerError.js.map +1 -1
  57. package/dist/esm/WorkerRunner.js +5 -0
  58. package/dist/esm/WorkerRunner.js.map +1 -1
  59. package/dist/esm/internal/httpClient.js +7 -7
  60. package/dist/esm/internal/httpClient.js.map +1 -1
  61. package/dist/esm/internal/httpClientResponse.js +13 -13
  62. package/dist/esm/internal/httpClientResponse.js.map +1 -1
  63. package/dist/esm/internal/httpServerRequest.js +16 -16
  64. package/dist/esm/internal/httpServerRequest.js.map +1 -1
  65. package/dist/esm/internal/multipart.js +17 -17
  66. package/dist/esm/internal/multipart.js.map +1 -1
  67. package/dist/esm/internal/worker.js +124 -57
  68. package/dist/esm/internal/worker.js.map +1 -1
  69. package/dist/esm/internal/workerRunner.js +42 -64
  70. package/dist/esm/internal/workerRunner.js.map +1 -1
  71. package/package.json +3 -3
  72. package/src/Error.ts +0 -38
  73. package/src/HttpClientError.ts +13 -6
  74. package/src/HttpServerError.ts +17 -6
  75. package/src/Multipart.ts +3 -2
  76. package/src/Socket.ts +10 -9
  77. package/src/Worker.ts +32 -29
  78. package/src/WorkerError.ts +15 -8
  79. package/src/WorkerRunner.ts +15 -8
  80. package/src/internal/httpClient.ts +7 -7
  81. package/src/internal/httpClientResponse.ts +13 -13
  82. package/src/internal/httpServerRequest.ts +15 -15
  83. package/src/internal/multipart.ts +16 -15
  84. package/src/internal/worker.ts +193 -146
  85. package/src/internal/workerRunner.ts +106 -136
package/src/Worker.ts CHANGED
@@ -5,17 +5,14 @@ import type * as ParseResult from "@effect/schema/ParseResult"
5
5
  import type * as Schema from "@effect/schema/Schema"
6
6
  import type * as Serializable from "@effect/schema/Serializable"
7
7
  import type * as Context from "effect/Context"
8
+ import type * as Deferred from "effect/Deferred"
8
9
  import type * as Duration from "effect/Duration"
9
10
  import type * as Effect from "effect/Effect"
10
- import type * as Fiber from "effect/Fiber"
11
11
  import type { LazyArg } from "effect/Function"
12
12
  import type * as Layer from "effect/Layer"
13
- import type * as Option from "effect/Option"
14
13
  import type * as Pool from "effect/Pool"
15
- import type * as Queue from "effect/Queue"
16
14
  import type * as Scope from "effect/Scope"
17
15
  import type * as Stream from "effect/Stream"
18
- import type * as Tracer from "effect/Tracer"
19
16
  import * as internal from "./internal/worker.js"
20
17
  import type { WorkerError, WorkerErrorFrom } from "./WorkerError.js"
21
18
 
@@ -24,9 +21,10 @@ import type { WorkerError, WorkerErrorFrom } from "./WorkerError.js"
24
21
  * @category models
25
22
  */
26
23
  export interface BackingWorker<I, O> {
27
- readonly fiber: Fiber.Fiber<never, WorkerError>
28
24
  readonly send: (message: I, transfers?: ReadonlyArray<unknown>) => Effect.Effect<void, WorkerError>
29
- readonly queue: Queue.Dequeue<BackingWorker.Message<O>>
25
+ readonly run: <A, E, R>(
26
+ handler: (_: BackingWorker.Message<O>) => Effect.Effect<A, E, R>
27
+ ) => Effect.Effect<never, E | WorkerError, R>
30
28
  }
31
29
 
32
30
  /**
@@ -59,9 +57,28 @@ export type PlatformWorkerTypeId = typeof PlatformWorkerTypeId
59
57
  */
60
58
  export interface PlatformWorker {
61
59
  readonly [PlatformWorkerTypeId]: PlatformWorkerTypeId
62
- readonly spawn: <I, O>(worker: unknown) => Effect.Effect<BackingWorker<I, O>, WorkerError, Scope.Scope>
60
+ readonly spawn: <I, O>(id: number) => Effect.Effect<BackingWorker<I, O>, WorkerError, Spawner>
63
61
  }
64
62
 
63
+ /**
64
+ * @since 1.0.0
65
+ */
66
+ export const makePlatform: <W>() => <
67
+ P extends { readonly postMessage: (message: any, transfers?: any | undefined) => void }
68
+ >(
69
+ options: {
70
+ readonly setup: (options: { readonly worker: W; readonly scope: Scope.Scope }) => Effect.Effect<P>
71
+ readonly listen: (
72
+ options: {
73
+ readonly port: P
74
+ readonly emit: (data: any) => void
75
+ readonly deferred: Deferred.Deferred<never, WorkerError>
76
+ readonly scope: Scope.Scope
77
+ }
78
+ ) => Effect.Effect<void>
79
+ }
80
+ ) => PlatformWorker = internal.makePlatform
81
+
65
82
  /**
66
83
  * @since 1.0.0
67
84
  * @category tags
@@ -86,6 +103,12 @@ export interface Spawner {
86
103
  readonly _: unique symbol
87
104
  }
88
105
 
106
+ /**
107
+ * @since 1.0.0
108
+ * @category tags
109
+ */
110
+ export const Spawner: Context.Tag<Spawner, SpawnerFn<unknown>> = internal.Spawner
111
+
89
112
  /**
90
113
  * @since 1.0.0
91
114
  * @category models
@@ -105,8 +128,6 @@ export declare namespace Worker {
105
128
  */
106
129
  export interface Options<I> {
107
130
  readonly encode?: ((message: I) => Effect.Effect<unknown, WorkerError>) | undefined
108
- readonly transfers?: ((message: I) => ReadonlyArray<unknown>) | undefined
109
- readonly queue?: WorkerQueue<I> | undefined
110
131
  readonly initialMessage?: LazyArg<I> | undefined
111
132
  }
112
133
 
@@ -173,16 +194,6 @@ export declare namespace WorkerPool {
173
194
  })
174
195
  }
175
196
 
176
- /**
177
- * @category models
178
- * @since 1.0.0
179
- */
180
- export interface WorkerQueue<I> {
181
- readonly offer: (id: number, item: I, span: Option.Option<Tracer.Span>) => Effect.Effect<void>
182
- readonly take: Effect.Effect<readonly [id: number, item: I, span: Option.Option<Tracer.Span>]>
183
- readonly shutdown: Effect.Effect<void>
184
- }
185
-
186
197
  /**
187
198
  * @since 1.0.0
188
199
  * @category type ids
@@ -268,20 +279,12 @@ export declare namespace SerializedWorker {
268
279
  * @since 1.0.0
269
280
  * @category models
270
281
  */
271
- export type Options<I> = Extract<I, { readonly _tag: "InitialMessage" }> extends never ? BaseOptions<I> & {
282
+ export type Options<I> = Extract<I, { readonly _tag: "InitialMessage" }> extends never ? {
272
283
  readonly initialMessage?: LazyArg<I>
273
284
  }
274
- : BaseOptions<I> & {
285
+ : {
275
286
  readonly initialMessage: LazyArg<Extract<I, { readonly _tag: "InitialMessage" }>>
276
287
  }
277
-
278
- /**
279
- * @since 1.0.0
280
- * @category models
281
- */
282
- export interface BaseOptions<I> {
283
- readonly queue?: WorkerQueue<I> | undefined
284
- }
285
288
  }
286
289
 
287
290
  /**
@@ -3,7 +3,6 @@
3
3
  */
4
4
  import * as Schema from "@effect/schema/Schema"
5
5
  import type * as Cause from "effect/Cause"
6
- import * as Inspectable from "effect/Inspectable"
7
6
  import * as Predicate from "effect/Predicate"
8
7
  import * as internal from "./internal/workerError.js"
9
8
 
@@ -31,7 +30,7 @@ export const isWorkerError = (u: unknown): u is WorkerError => Predicate.hasProp
31
30
  */
32
31
  export class WorkerError extends Schema.TaggedError<WorkerError>()("WorkerError", {
33
32
  reason: Schema.Literal("spawn", "decode", "send", "unknown", "encode"),
34
- error: Schema.CauseDefectUnknown
33
+ cause: Schema.CauseDefectUnknown
35
34
  }) {
36
35
  /**
37
36
  * @since 1.0.0
@@ -61,11 +60,19 @@ export class WorkerError extends Schema.TaggedError<WorkerError>()("WorkerError"
61
60
  /**
62
61
  * @since 1.0.0
63
62
  */
64
- get message() {
65
- const message = Predicate.hasProperty(this.error, "message")
66
- ? this.error.message
67
- : Inspectable.toStringUnknown(this.error, undefined)
68
- return `${this.reason}: ${message}`
63
+ get message(): string {
64
+ switch (this.reason) {
65
+ case "send":
66
+ return "An error occurred calling .postMessage"
67
+ case "spawn":
68
+ return "An error occurred while spawning a worker"
69
+ case "decode":
70
+ return "An error occurred during decoding"
71
+ case "encode":
72
+ return "An error occurred during encoding"
73
+ case "unknown":
74
+ return "An unexpected error occurred"
75
+ }
69
76
  }
70
77
  }
71
78
 
@@ -76,5 +83,5 @@ export class WorkerError extends Schema.TaggedError<WorkerError>()("WorkerError"
76
83
  export interface WorkerErrorFrom {
77
84
  readonly _tag: "WorkerError"
78
85
  readonly reason: "spawn" | "decode" | "send" | "unknown" | "encode"
79
- readonly error: unknown
86
+ readonly cause: unknown
80
87
  }
@@ -6,7 +6,6 @@ import type * as Serializable from "@effect/schema/Serializable"
6
6
  import type * as Context from "effect/Context"
7
7
  import type * as Effect from "effect/Effect"
8
8
  import type * as Layer from "effect/Layer"
9
- import type * as Queue from "effect/Queue"
10
9
  import type * as Scope from "effect/Scope"
11
10
  import type * as Stream from "effect/Stream"
12
11
  import * as internal from "./internal/workerRunner.js"
@@ -17,7 +16,9 @@ import type { WorkerError } from "./WorkerError.js"
17
16
  * @category models
18
17
  */
19
18
  export interface BackingRunner<I, O> {
20
- readonly queue: Queue.Dequeue<readonly [portId: number, message: I]>
19
+ readonly run: <A, E, R>(
20
+ handler: (portId: number, message: I) => Effect.Effect<A, E, R>
21
+ ) => Effect.Effect<never, E | WorkerError, R>
21
22
  readonly send: (
22
23
  portId: number,
23
24
  message: O,
@@ -55,9 +56,7 @@ export type PlatformRunnerTypeId = typeof PlatformRunnerTypeId
55
56
  */
56
57
  export interface PlatformRunner {
57
58
  readonly [PlatformRunnerTypeId]: PlatformRunnerTypeId
58
- readonly start: <I, O>(
59
- shutdown: Effect.Effect<void>
60
- ) => Effect.Effect<BackingRunner<I, O>, WorkerError, Scope.Scope>
59
+ readonly start: <I, O>() => Effect.Effect<BackingRunner<I, O>, WorkerError>
61
60
  }
62
61
 
63
62
  /**
@@ -87,18 +86,26 @@ export declare namespace Runner {
87
86
  request: I,
88
87
  error: E
89
88
  ) => Effect.Effect<unknown, WorkerError>
90
- readonly transfers?: (message: O | E) => ReadonlyArray<unknown>
91
89
  }
92
90
  }
93
91
 
92
+ /**
93
+ * @since 1.0.0
94
+ * @category constructors
95
+ */
96
+ export const run: <I, E, R, O>(
97
+ process: (request: I) => Stream.Stream<O, E, R> | Effect.Effect<O, E, R>,
98
+ options?: Runner.Options<I, O, E>
99
+ ) => Effect.Effect<never, WorkerError, PlatformRunner | R> = internal.run
100
+
94
101
  /**
95
102
  * @since 1.0.0
96
103
  * @category constructors
97
104
  */
98
105
  export const make: <I, E, R, O>(
99
106
  process: (request: I) => Stream.Stream<O, E, R> | Effect.Effect<O, E, R>,
100
- options?: Runner.Options<I, O, E> | undefined
101
- ) => Effect.Effect<void, WorkerError, Scope.Scope | R | PlatformRunner> = internal.make
107
+ options?: Runner.Options<I, O, E>
108
+ ) => Effect.Effect<void, WorkerError, PlatformRunner | R | Scope.Scope> = internal.make
102
109
 
103
110
  /**
104
111
  * @since 1.0.0
@@ -128,7 +128,7 @@ export const makeDefault = (
128
128
  const addAbort = Scope.addFinalizer(scope, Effect.sync(() => controller.abort()))
129
129
  const urlResult = UrlParams.makeUrl(request.url, request.urlParams, request.hash)
130
130
  if (urlResult._tag === "Left") {
131
- return Effect.fail(new Error.RequestError({ request, reason: "InvalidUrl", error: urlResult.left }))
131
+ return Effect.fail(new Error.RequestError({ request, reason: "InvalidUrl", cause: urlResult.left }))
132
132
  }
133
133
  const url = urlResult.right
134
134
  const tracerDisabled = !fiber.getFiberRef(FiberRef.currentTracerEnabled) ||
@@ -211,11 +211,11 @@ export const fetch: Client.HttpClient.Default = makeDefault((request, url, signa
211
211
  duplex: request.body._tag === "Stream" ? "half" : undefined,
212
212
  signal
213
213
  } as any),
214
- catch: (error) =>
214
+ catch: (cause) =>
215
215
  new Error.RequestError({
216
216
  request,
217
217
  reason: "Transport",
218
- error
218
+ cause
219
219
  })
220
220
  }),
221
221
  (response) => internalResponse.fromWeb(request, response)
@@ -276,7 +276,7 @@ export const filterStatus = dual<
276
276
  request,
277
277
  response,
278
278
  reason: "StatusCode",
279
- error: "invalid status code"
279
+ description: "invalid status code"
280
280
  })
281
281
  )))
282
282
 
@@ -293,7 +293,7 @@ export const filterStatusOk = <E, R>(
293
293
  request,
294
294
  response,
295
295
  reason: "StatusCode",
296
- error: "non 2xx status code"
296
+ description: "non 2xx status code"
297
297
  })
298
298
  ))
299
299
 
@@ -675,11 +675,11 @@ export const schemaFunction = dual<
675
675
  Effect.flatMap(
676
676
  Effect.tryMap(encode(a), {
677
677
  try: (body) => new TextEncoder().encode(JSON.stringify(body)),
678
- catch: (error) =>
678
+ catch: (cause) =>
679
679
  new Error.RequestError({
680
680
  request,
681
681
  reason: "Encode",
682
- error
682
+ cause
683
683
  })
684
684
  }),
685
685
  (body) =>
@@ -67,19 +67,19 @@ class ClientResponseImpl extends Inspectable.Class implements ClientResponse.Htt
67
67
 
68
68
  get stream(): Stream.Stream<Uint8Array, Error.ResponseError> {
69
69
  return this.source.body
70
- ? Stream.fromReadableStream(() => this.source.body!, (_) =>
70
+ ? Stream.fromReadableStream(() => this.source.body!, (cause) =>
71
71
  new Error.ResponseError({
72
72
  request: this.request,
73
73
  response: this,
74
74
  reason: "Decode",
75
- error: _
75
+ cause
76
76
  }))
77
77
  : Stream.fail(
78
78
  new Error.ResponseError({
79
79
  request: this.request,
80
80
  response: this,
81
81
  reason: "EmptyBody",
82
- error: "can not create stream from empty body"
82
+ description: "can not create stream from empty body"
83
83
  })
84
84
  )
85
85
  }
@@ -87,12 +87,12 @@ class ClientResponseImpl extends Inspectable.Class implements ClientResponse.Htt
87
87
  get json(): Effect.Effect<unknown, Error.ResponseError> {
88
88
  return Effect.tryMap(this.text, {
89
89
  try: (text) => text === "" ? null : JSON.parse(text) as unknown,
90
- catch: (_) =>
90
+ catch: (cause) =>
91
91
  new Error.ResponseError({
92
92
  request: this.request,
93
93
  response: this,
94
94
  reason: "Decode",
95
- error: _
95
+ cause
96
96
  })
97
97
  })
98
98
  }
@@ -101,12 +101,12 @@ class ClientResponseImpl extends Inspectable.Class implements ClientResponse.Htt
101
101
  get text(): Effect.Effect<string, Error.ResponseError> {
102
102
  return this.textBody ??= Effect.tryPromise({
103
103
  try: () => this.source.text(),
104
- catch: (_) =>
104
+ catch: (cause) =>
105
105
  new Error.ResponseError({
106
106
  request: this.request,
107
107
  response: this,
108
108
  reason: "Decode",
109
- error: _
109
+ cause
110
110
  })
111
111
  }).pipe(Effect.cached, Effect.runSync)
112
112
  }
@@ -115,12 +115,12 @@ class ClientResponseImpl extends Inspectable.Class implements ClientResponse.Htt
115
115
  return Effect.flatMap(this.text, (_) =>
116
116
  Effect.try({
117
117
  try: () => UrlParams.fromInput(new URLSearchParams(_)),
118
- catch: (_) =>
118
+ catch: (cause) =>
119
119
  new Error.ResponseError({
120
120
  request: this.request,
121
121
  response: this,
122
122
  reason: "Decode",
123
- error: _
123
+ cause
124
124
  })
125
125
  }))
126
126
  }
@@ -129,12 +129,12 @@ class ClientResponseImpl extends Inspectable.Class implements ClientResponse.Htt
129
129
  get formData(): Effect.Effect<FormData, Error.ResponseError> {
130
130
  return this.formDataBody ??= Effect.tryPromise({
131
131
  try: () => this.source.formData(),
132
- catch: (_) =>
132
+ catch: (cause) =>
133
133
  new Error.ResponseError({
134
134
  request: this.request,
135
135
  response: this,
136
136
  reason: "Decode",
137
- error: _
137
+ cause
138
138
  })
139
139
  }).pipe(Effect.cached, Effect.runSync)
140
140
  }
@@ -143,12 +143,12 @@ class ClientResponseImpl extends Inspectable.Class implements ClientResponse.Htt
143
143
  get arrayBuffer(): Effect.Effect<ArrayBuffer, Error.ResponseError> {
144
144
  return this.arrayBufferBody ??= Effect.tryPromise({
145
145
  try: () => this.source.arrayBuffer(),
146
- catch: (_) =>
146
+ catch: (cause) =>
147
147
  new Error.ResponseError({
148
148
  request: this.request,
149
149
  response: this,
150
150
  reason: "Decode",
151
- error: _
151
+ cause
152
152
  })
153
153
  }).pipe(Effect.cached, Effect.runSync)
154
154
  }
@@ -151,11 +151,11 @@ export const schemaBodyFormJson = <A, I, R>(schema: Schema.Schema<A, I, R>, opti
151
151
  > => {
152
152
  if (isMultipart(request)) {
153
153
  return Effect.flatMap(
154
- Effect.mapError(request.multipart, (error) =>
154
+ Effect.mapError(request.multipart, (cause) =>
155
155
  new Error.RequestError({
156
156
  request,
157
157
  reason: "Decode",
158
- error
158
+ cause
159
159
  })),
160
160
  parseMultipart(field)
161
161
  )
@@ -227,17 +227,17 @@ class ServerRequestImpl extends Inspectable.Class implements ServerRequest.HttpS
227
227
 
228
228
  get stream(): Stream.Stream<Uint8Array, Error.RequestError> {
229
229
  return this.source.body
230
- ? Stream.fromReadableStream(() => this.source.body as any, (_) =>
230
+ ? Stream.fromReadableStream(() => this.source.body as any, (cause) =>
231
231
  new Error.RequestError({
232
232
  request: this,
233
233
  reason: "Decode",
234
- error: _
234
+ cause
235
235
  }))
236
236
  : Stream.fail(
237
237
  new Error.RequestError({
238
238
  request: this,
239
239
  reason: "Decode",
240
- error: "can not create stream from empty body"
240
+ description: "can not create stream from empty body"
241
241
  })
242
242
  )
243
243
  }
@@ -250,11 +250,11 @@ class ServerRequestImpl extends Inspectable.Class implements ServerRequest.HttpS
250
250
  this.textEffect = Effect.runSync(Effect.cached(
251
251
  Effect.tryPromise({
252
252
  try: () => this.source.text(),
253
- catch: (error) =>
253
+ catch: (cause) =>
254
254
  new Error.RequestError({
255
255
  request: this,
256
256
  reason: "Decode",
257
- error
257
+ cause
258
258
  })
259
259
  })
260
260
  ))
@@ -264,11 +264,11 @@ class ServerRequestImpl extends Inspectable.Class implements ServerRequest.HttpS
264
264
  get json(): Effect.Effect<unknown, Error.RequestError> {
265
265
  return Effect.tryMap(this.text, {
266
266
  try: (_) => JSON.parse(_) as unknown,
267
- catch: (error) =>
267
+ catch: (cause) =>
268
268
  new Error.RequestError({
269
269
  request: this,
270
270
  reason: "Decode",
271
- error
271
+ cause
272
272
  })
273
273
  })
274
274
  }
@@ -277,11 +277,11 @@ class ServerRequestImpl extends Inspectable.Class implements ServerRequest.HttpS
277
277
  return Effect.flatMap(this.text, (_) =>
278
278
  Effect.try({
279
279
  try: () => UrlParams.fromInput(new URLSearchParams(_)),
280
- catch: (error) =>
280
+ catch: (cause) =>
281
281
  new Error.RequestError({
282
282
  request: this,
283
283
  reason: "Decode",
284
- error
284
+ cause
285
285
  })
286
286
  }))
287
287
  }
@@ -309,7 +309,7 @@ class ServerRequestImpl extends Inspectable.Class implements ServerRequest.HttpS
309
309
 
310
310
  get multipartStream(): Stream.Stream<Multipart.Part, Multipart.MultipartError> {
311
311
  return Stream.pipeThroughChannel(
312
- Stream.mapError(this.stream, (error) => new Multipart.MultipartError({ reason: "InternalError", error })),
312
+ Stream.mapError(this.stream, (cause) => new Multipart.MultipartError({ reason: "InternalError", cause })),
313
313
  Multipart.makeChannel(this.headers)
314
314
  )
315
315
  }
@@ -322,11 +322,11 @@ class ServerRequestImpl extends Inspectable.Class implements ServerRequest.HttpS
322
322
  this.arrayBufferEffect = Effect.runSync(Effect.cached(
323
323
  Effect.tryPromise({
324
324
  try: () => this.source.arrayBuffer(),
325
- catch: (error) =>
325
+ catch: (cause) =>
326
326
  new Error.RequestError({
327
327
  request: this,
328
328
  reason: "Decode",
329
- error
329
+ cause
330
330
  })
331
331
  })
332
332
  ))
@@ -338,7 +338,7 @@ class ServerRequestImpl extends Inspectable.Class implements ServerRequest.HttpS
338
338
  new Error.RequestError({
339
339
  request: this,
340
340
  reason: "Decode",
341
- error: "Not an upgradeable ServerRequest"
341
+ description: "Not an upgradeable ServerRequest"
342
342
  })
343
343
  )
344
344
  }
@@ -16,7 +16,7 @@ import type * as Scope from "effect/Scope"
16
16
  import type * as AsyncInput from "effect/SingleProducerAsyncInput"
17
17
  import * as Stream from "effect/Stream"
18
18
  import * as MP from "multipasta"
19
- import { RefailError } from "../Error.js"
19
+ import { TypeIdError } from "../Error.js"
20
20
  import * as FileSystem from "../FileSystem.js"
21
21
  import * as IncomingMessage from "../HttpIncomingMessage.js"
22
22
  import type * as Multipart from "../Multipart.js"
@@ -44,11 +44,12 @@ export const ErrorTypeId: Multipart.ErrorTypeId = Symbol.for(
44
44
  ) as Multipart.ErrorTypeId
45
45
 
46
46
  /** @internal */
47
- export class MultipartError extends RefailError(ErrorTypeId, "MultipartError")<{
47
+ export class MultipartError extends TypeIdError(ErrorTypeId, "MultipartError")<{
48
48
  readonly reason: "FileTooLarge" | "FieldTooLarge" | "BodyTooLarge" | "TooManyParts" | "InternalError" | "Parse"
49
+ readonly cause: unknown
49
50
  }> {
50
- get message() {
51
- return `${this.reason}: ${super.message}`
51
+ get message(): string {
52
+ return this.reason
52
53
  }
53
54
  }
54
55
 
@@ -320,26 +321,26 @@ const makeFromQueue = <IE>(
320
321
  return Channel.embedInput(partsChannel, input)
321
322
  })
322
323
 
323
- function convertError(error: MP.MultipartError): Multipart.MultipartError {
324
- switch (error._tag) {
324
+ function convertError(cause: MP.MultipartError): Multipart.MultipartError {
325
+ switch (cause._tag) {
325
326
  case "ReachedLimit": {
326
- switch (error.limit) {
327
+ switch (cause.limit) {
327
328
  case "MaxParts": {
328
- return new MultipartError({ reason: "TooManyParts", error })
329
+ return new MultipartError({ reason: "TooManyParts", cause })
329
330
  }
330
331
  case "MaxFieldSize": {
331
- return new MultipartError({ reason: "FieldTooLarge", error })
332
+ return new MultipartError({ reason: "FieldTooLarge", cause })
332
333
  }
333
334
  case "MaxPartSize": {
334
- return new MultipartError({ reason: "FileTooLarge", error })
335
+ return new MultipartError({ reason: "FileTooLarge", cause })
335
336
  }
336
337
  case "MaxTotalSize": {
337
- return new MultipartError({ reason: "BodyTooLarge", error })
338
+ return new MultipartError({ reason: "BodyTooLarge", cause })
338
339
  }
339
340
  }
340
341
  }
341
342
  default: {
342
- return new MultipartError({ reason: "Parse", error })
343
+ return new MultipartError({ reason: "Parse", cause })
343
344
  }
344
345
  }
345
346
  }
@@ -409,7 +410,7 @@ const defaultWriteFile = (path: string, file: Multipart.File) =>
409
410
  (fs) =>
410
411
  Effect.mapError(
411
412
  Stream.run(file.content, fs.sink(path)),
412
- (error) => new MultipartError({ reason: "InternalError", error })
413
+ (cause) => new MultipartError({ reason: "InternalError", cause })
413
414
  )
414
415
  )
415
416
 
@@ -450,8 +451,8 @@ export const toPersisted = (
450
451
  )
451
452
  ),
452
453
  Effect.catchTags({
453
- SystemError: (error) => Effect.fail(new MultipartError({ reason: "InternalError", error })),
454
- BadArgument: (error) => Effect.fail(new MultipartError({ reason: "InternalError", error }))
454
+ SystemError: (cause) => Effect.fail(new MultipartError({ reason: "InternalError", cause })),
455
+ BadArgument: (cause) => Effect.fail(new MultipartError({ reason: "InternalError", cause }))
455
456
  })
456
457
  )
457
458