Create a custom payload converter using EJSON, which supports:
- Dates (
Date
) - Binary (
Uint8Array
) - Special numbers (
NaN
,Infinity
, and-Infinity
) - Regular expressions (
RegExp
)
EjsonPayloadConverter
: ejson-payload-converter.tspayloadConverter
: payload-converter.ts
The payload-converter.ts
file is supplied to the client.ts and worker.ts, and when the client sends a User
argument, workflow.ts can receive it.
If you are migrating to EjsonPayloadConverter
from the default Payload Converter in a production Temporal deployment, you can:
- Redeploy Workers with the new data converter.
- Then redeploy Client code with the new data converter.
Payloads that were encoded with JsonPayloadConverter
will be decoded by EjsonPayloadConverter
, as they share the same encodingType
.
If any of your production Workflows used Uint8Array
data, add BinaryPayloadConverter
so those Payloads can be decoded:
import { BinaryPayloadConverter, CompositePayloadConverter, UndefinedPayloadConverter } from '@temporalio/common';
import { EjsonPayloadConverter } from './ejson-payload-converter';
export const payloadConverter = new CompositePayloadConverter(
new UndefinedPayloadConverter(),
new BinaryPayloadConverter(),
new EjsonPayloadConverter()
);
temporal server start-dev
to start Temporal Server.npm install
to install dependencies.npm run start.watch
to start the Worker.- In another shell,
npm run workflow
to run the Workflow Client.
The client script should log:
Started workflow example-user-67904764-18eb-4011-93b0-85cb04880a69
{ success: true, at: 2022-03-24T00:11:07.509Z }