(source: Readable, headers: IncomingHttpHeaders): Stream.Stream<
Multipart.Part,
Multipart.MultipartError
>Parses multipart data from a Node readable request body and headers into a
stream of Multipart.Part values, converting parser failures to
MultipartError.
export const const stream: (
source: Readable,
headers: IncomingHttpHeaders
) => Stream.Stream<
Multipart.Part,
Multipart.MultipartError
>
Parses multipart data from a Node readable request body and headers into a
stream of Multipart.Part values, converting parser failures to
MultipartError.
stream = (
source: Readablesource: import ReadableReadable,
headers: IncomingHttpHeadersheaders: import IncomingHttpHeadersIncomingHttpHeaders
): import StreamStream.interface Stream<out A, out E = never, out R = never>A Stream<A, E, R> describes a program that can emit many A values, fail
with E, and require R.
Details
Streams are pull-based with backpressure and emit chunks to amortize effect
evaluation. They support monadic composition and error handling similar to
Effect, adapted for multiple values.
Example (Creating and consuming streams)
import { Console, Effect, Stream } from "effect"
const program = Effect.gen(function*() {
yield* Stream.make(1, 2, 3).pipe(
Stream.map((n) => n * 2),
Stream.runForEach((n) => Console.log(n))
)
})
Effect.runPromise(program)
// Output:
// 2
// 4
// 6
Stream<import MultipartMultipart.type Part = Multipart.Field | Multipart.FileA parsed multipart part.
Details
A part is either a text Field or a streamed File.
Namespace containing shared multipart part model types.
Part, import MultipartMultipart.class MultipartErrorclass MultipartError {
message: string;
name: string;
stack: string;
cause: unknown;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
_tag: Tag;
reason: Multipart.MultipartErrorReason;
}
Error raised while parsing, streaming, or persisting multipart form data.
Details
The reason field contains the concrete MultipartErrorReason.
MultipartError> =>
import MultipartMultipart.const makeConfig: (
headers: Record<string, string>
) => Effect.Effect<MP.BaseConfig>
Builds the low-level multipart parser configuration from request headers and
the current fiber context.
Details
Parser limits are read from the multipart references, including maximum parts,
field size, file size, total body size, and field MIME type overrides.
makeConfig(headers: IncomingHttpHeadersheaders as any).Pipeable.pipe<Effect.Effect<BaseConfig, never, never>, never, never, Stream.Stream<Multipart.Part, Multipart.MultipartError, never>>(this: Effect.Effect<BaseConfig, never, never>, ab: (_: Effect.Effect<BaseConfig, never, never>) => never, bc: (_: never) => never, cd: (_: never) => Stream.Stream<Multipart.Part, Multipart.MultipartError, never>): Stream.Stream<Multipart.Part, Multipart.MultipartError, never> (+21 overloads)pipe(
import EffectEffect.const map: {
<A, B>(f: (a: A) => B): <E, R>(
self: Effect<A, E, R>
) => Effect<B, E, R>
<A, E, R, B>(
self: Effect<A, E, R>,
f: (a: A) => B
): Effect<B, E, R>
}
Transforms the value inside an effect by applying a function to it.
When to use
Use to transform an effect's success value with a function that returns a
plain value, producing a new effect without changing the original effect's
typed error or context requirements.
Details
map takes a function and applies it to the value contained within an
effect, creating a new effect with the transformed value.
It's important to note that effects are immutable, meaning that the original
effect is not modified. Instead, a new effect is returned with the updated
value.
Example (Choosing map syntax variants)
import { Effect, pipe } from "effect"
const myEffect = Effect.succeed(1)
const transformation = (n: number) => n + 1
const mappedWithPipe = pipe(myEffect, Effect.map(transformation))
const mappedWithDataFirst = Effect.map(myEffect, transformation)
const mappedWithMethod = myEffect.pipe(Effect.map(transformation))
Example (Adding a service charge)
import { Effect, pipe } from "effect"
const addServiceCharge = (amount: number) => amount + 1
const fetchTransactionAmount = Effect.promise(() => Promise.resolve(100))
const finalAmount = pipe(
fetchTransactionAmount,
Effect.map(addServiceCharge)
)
Effect.runPromise(finalAmount).then(console.log)
// Output: 101
map((config: BaseConfigconfig) =>
import NodeStreamNodeStream.fromReadable<import MPMP.type Part = MP.Field | MP.FileStreamPart, import MultipartMultipart.class MultipartErrorclass MultipartError {
message: string;
name: string;
stack: string;
cause: unknown;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
_tag: Tag;
reason: Multipart.MultipartErrorReason;
}
Error raised while parsing, streaming, or persisting multipart form data.
Details
The reason field contains the concrete MultipartErrorReason.
MultipartError>({
function evaluate(): anyevaluate() {
const const parser: MP.MultipastaStreamparser = import MPMP.const make: (
config: MP.NodeConfig
) => MP.MultipastaStream
make(config: BaseConfigconfig)
source: Readablesource.pipe(const parser: MP.MultipastaStreamparser)
return const parser: MP.MultipastaStreamparser as any
},
onError: (error: any) => Multipart.MultipartErroronError: (error: anyerror) => function convertError(
cause: MP.MultipartError
): Multipart.MultipartError
convertError(error: anyerror as any)
})
),
import StreamStream.const unwrap: <A, E2, R2, E, R>(
effect: Effect.Effect<Stream<A, E2, R2>, E, R>
) => Stream<
A,
E | E2,
R2 | Exclude<R, Scope.Scope>
>
Creates a stream produced from an Effect.
Example (Unwrapping a stream effect)
import { Console, Effect, Stream } from "effect"
const effect = Effect.succeed(Stream.make(1, 2, 3))
const stream = Stream.unwrap(effect)
const program = Effect.gen(function*() {
const chunk = yield* Stream.runCollect(stream)
yield* Console.log(chunk)
})
// [1, 2, 3]
unwrap,
import StreamStream.const map: {
<A, B>(f: (a: A, i: number) => B): <E, R>(
self: Stream<A, E, R>
) => Stream<B, E, R>
<A, E, R, B>(
self: Stream<A, E, R>,
f: (a: A, i: number) => B
): Stream<B, E, R>
}
Transforms the elements of this stream using the supplied function.
Example (Mapping stream values)
import { Console, Effect, Stream } from "effect"
const stream = Stream.fromArray([1, 2, 3]).pipe(Stream.map((n, i) => n + i))
const program = Stream.runCollect(stream).pipe(
Effect.tap((values) => Console.log(values))
)
Effect.runPromise(program)
// [ 1, 3, 5 ]
map(const convertPart: (
part: MP.Part
) => Multipart.Part
convertPart)
)