Convert from one type of object to another.
Instantiate an instance with a AsyncObjectMapperSchema
. You must pass two type parameters:
TInput
: the type of the input objectTOutput
: the type of the desired output object
You can pass an optional third type parameter:
TContext
: an object with any additional data or functions. Useful when mapping multiple objects with some shared state, like a "now" timestamp.
Invoke the mapper with AsyncObjectMapper#map
.
If you want a plain (unbound) function, you can call AsyncObjectMapper#toFunction
.
There is a convenience method AsyncObjectMapper#array
, for mapping some iterable to an array.
Map multiple input objects from some iterable, and return an array of output objects.
Map multiple input objects from some iterable, and return an array of output objects.
If the input is null
, it will be returned as-is.
Map multiple input objects from some iterable, and return an array of output objects.
If the input is undefined
, it will be returned as-is.
array(): Promise<>
Map multiple input objects from some iterable, and return an array of output objects.
If the input is null
or undefined
, it will be returned as-is.
Maps an input object to an output object.
It does so by iterating each property in the object schema, and invoking the property's mapping function, passing the input and context.
Maps an input object to an output object.
It does so by iterating each property in the object schema, and invoking the property's mapping function, passing the input and context.
If input
is null
, it will be returned as-is.
Maps an input object to an output object.
It does so by iterating each property in the object schema, and invoking the property's mapping function, passing the input and context.
If input
is undefined
, it will be returned as-is.
map(): Promise<>
Maps an input object to an output object.
It does so by iterating each property in the object schema, and invoking the property's mapping function, passing the input and context.
If input
is null
or undefined
, it will be returned as-is.
toFunction(): AsyncObjectMapperFunction<TInput, TOutput, TContext>
Wrap this instance in a function, with a schema
property.
create<TInput extends object,TOutput extends object,TContext extends object | undefined = undefined,>()
Create an AsyncObjectMapper factory function. Invoke it immediately, with an object mapper schema, to create an AsyncObjectMapper instance.
We use this approach to trick TypeScript into requiring an exact type to be passed in. That is, the object mapper schema must only have properties that exist in the output type, and no additional properties.