@temporalio/common 0.22.0 → 0.23.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.
- package/lib/converter/data-converter.d.ts +9 -5
- package/lib/converter/data-converter.js +4 -4
- package/lib/converter/data-converter.js.map +1 -1
- package/lib/converter/payload-codec.d.ts +0 -7
- package/lib/converter/payload-codec.js +0 -8
- package/lib/converter/payload-codec.js.map +1 -1
- package/lib/converter/payload-converter.d.ts +15 -42
- package/lib/converter/payload-converter.js +6 -74
- package/lib/converter/payload-converter.js.map +1 -1
- package/lib/converter/payload-converters.d.ts +34 -2
- package/lib/converter/payload-converters.js +78 -8
- package/lib/converter/payload-converters.js.map +1 -1
- package/lib/converter/protobuf-payload-converters.d.ts +1 -2
- package/lib/converter/protobuf-payload-converters.js +5 -4
- package/lib/converter/protobuf-payload-converters.js.map +1 -1
- package/lib/converter/wrapped-payload-converter.d.ts +12 -0
- package/lib/converter/wrapped-payload-converter.js +28 -0
- package/lib/converter/wrapped-payload-converter.js.map +1 -0
- package/lib/failure.d.ts +6 -6
- package/lib/failure.js.map +1 -1
- package/package.json +4 -4
- package/src/converter/data-converter.ts +13 -8
- package/src/converter/payload-codec.ts +0 -8
- package/src/converter/payload-converter.ts +24 -92
- package/src/converter/payload-converters.ts +90 -12
- package/src/converter/protobuf-payload-converters.ts +7 -3
- package/src/converter/wrapped-payload-converter.ts +31 -0
- package/src/failure.ts +7 -6
- package/tsconfig.tsbuildinfo +1 -1
package/lib/failure.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { temporal } from '@temporalio/proto';
|
|
2
|
-
import {
|
|
2
|
+
import { WrappedPayloadConverter } from './converter/wrapped-payload-converter';
|
|
3
3
|
export declare const FAILURE_SOURCE = "TypeScriptSDK";
|
|
4
4
|
export declare type ProtoFailure = temporal.api.failure.v1.IFailure;
|
|
5
5
|
export declare enum TimeoutType {
|
|
@@ -155,7 +155,7 @@ export declare class ChildWorkflowFailure extends TemporalFailure {
|
|
|
155
155
|
/**
|
|
156
156
|
* Converts an error to a Failure proto message if defined or returns undefined
|
|
157
157
|
*/
|
|
158
|
-
export declare function optionalErrorToOptionalFailure(err: unknown, payloadConverter:
|
|
158
|
+
export declare function optionalErrorToOptionalFailure(err: unknown, payloadConverter: WrappedPayloadConverter): ProtoFailure | undefined;
|
|
159
159
|
/**
|
|
160
160
|
* Cuts out the framework part of a stack trace, leaving only user code entries
|
|
161
161
|
*/
|
|
@@ -163,7 +163,7 @@ export declare function cutoffStackTrace(stack?: string): string;
|
|
|
163
163
|
/**
|
|
164
164
|
* Converts a caught error to a Failure proto message
|
|
165
165
|
*/
|
|
166
|
-
export declare function errorToFailure(err: unknown, payloadConverter:
|
|
166
|
+
export declare function errorToFailure(err: unknown, payloadConverter: WrappedPayloadConverter): ProtoFailure;
|
|
167
167
|
/**
|
|
168
168
|
* If `err` is an Error it is turned into an `ApplicationFailure`.
|
|
169
169
|
*
|
|
@@ -175,17 +175,17 @@ export declare function ensureTemporalFailure(err: unknown): TemporalFailure;
|
|
|
175
175
|
/**
|
|
176
176
|
* Converts a Failure proto message to a JS Error object if defined or returns undefined.
|
|
177
177
|
*/
|
|
178
|
-
export declare function optionalFailureToOptionalError(failure: ProtoFailure | undefined | null, payloadConverter:
|
|
178
|
+
export declare function optionalFailureToOptionalError(failure: ProtoFailure | undefined | null, payloadConverter: WrappedPayloadConverter): TemporalFailure | undefined;
|
|
179
179
|
/**
|
|
180
180
|
* Converts a Failure proto message to a JS Error object.
|
|
181
181
|
*
|
|
182
182
|
* Does not set common properties, that is done in {@link failureToError}.
|
|
183
183
|
*/
|
|
184
|
-
export declare function failureToErrorInner(failure: ProtoFailure, payloadConverter:
|
|
184
|
+
export declare function failureToErrorInner(failure: ProtoFailure, payloadConverter: WrappedPayloadConverter): TemporalFailure;
|
|
185
185
|
/**
|
|
186
186
|
* Converts a Failure proto message to a JS Error object.
|
|
187
187
|
*/
|
|
188
|
-
export declare function failureToError(failure: ProtoFailure, payloadConverter:
|
|
188
|
+
export declare function failureToError(failure: ProtoFailure, payloadConverter: WrappedPayloadConverter): TemporalFailure;
|
|
189
189
|
/**
|
|
190
190
|
* Get the root cause (string) of given error `err`.
|
|
191
191
|
*
|
package/lib/failure.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"failure.js","sourceRoot":"","sources":["../src/failure.ts"],"names":[],"mappings":";;;AAAA,mFAAgG;AAEhG,
|
|
1
|
+
{"version":3,"file":"failure.js","sourceRoot":"","sources":["../src/failure.ts"],"names":[],"mappings":";;;AAAA,mFAAgG;AAEhG,qEAAmG;AAGtF,QAAA,cAAc,GAAG,eAAe,CAAC;AAG9C,0EAA0E;AAC1E,gDAAgD;AAChD,IAAY,WAMX;AAND,WAAY,WAAW;IACrB,qFAA4B,CAAA;IAC5B,2FAA+B,CAAA;IAC/B,iGAAkC,CAAA;IAClC,iGAAkC,CAAA;IAClC,iFAA0B,CAAA;AAC5B,CAAC,EANW,WAAW,GAAX,mBAAW,KAAX,mBAAW,QAMtB;AAED,IAAA,uCAAY,GAAkD,CAAC;AAE/D,0EAA0E;AAC1E,+CAA+C;AAC/C,IAAY,UASX;AATD,WAAY,UAAU;IACpB,iFAA2B,CAAA;IAC3B,iFAA2B,CAAA;IAC3B,qGAAqC,CAAA;IACrC,yEAAuB,CAAA;IACvB,2GAAwC,CAAA;IACxC,mGAAoC,CAAA;IACpC,qGAAqC,CAAA;IACrC,2FAAgC,CAAA;AAClC,CAAC,EATW,UAAU,GAAV,kBAAU,KAAV,kBAAU,QASrB;AAED,IAAA,uCAAY,GAAgD,CAAC;AAI7D;;;;;;;;;;;GAWG;AACH,MAAa,eAAgB,SAAQ,KAAK;IASxC,YAAY,OAA2B,EAAkB,KAAa;QACpE,KAAK,CAAC,OAAO,IAAI,SAAS,CAAC,CAAC;QAD2B,UAAK,GAAL,KAAK,CAAQ;QARtD,SAAI,GAAW,iBAAiB,CAAC;IAUjD,CAA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,CAAC;AACb,CAAC;AALD,wCAKC;AAED;;;;;GAKG;AACH,SAAgB,SAAS,CAAC,GAAY;IACpC,IAAI,GAAG,YAAY,eAAe,EAAE;QAClC,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC;KACvD;IACD,IAAI,GAAG,YAAY,KAAK,EAAE;QACxB,OAAO,GAAG,CAAC,OAAO,CAAC;KACpB;IACD,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;QAC3B,OAAO,GAAG,CAAC;KACZ;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAXD,8BAWC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@temporalio/common",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.0",
|
|
4
4
|
"description": "Common library for code that's used across the Client, Worker, and/or Workflow",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
"author": "Loren Sands-Ramshaw <loren@temporal.io>",
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@temporalio/internal-workflow-common": "^0.
|
|
16
|
-
"@temporalio/proto": "^0.
|
|
15
|
+
"@temporalio/internal-workflow-common": "^0.23.0",
|
|
16
|
+
"@temporalio/proto": "^0.23.0",
|
|
17
17
|
"proto3-json-serializer": "^0.1.6"
|
|
18
18
|
},
|
|
19
19
|
"bugs": {
|
|
@@ -26,5 +26,5 @@
|
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"protobufjs": "^6.11.2"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "81ee3fd09c2fd866b31b1dbfabce7ef221e338ea"
|
|
30
30
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { defaultPayloadConverter
|
|
1
|
+
import { PayloadCodec } from './payload-codec';
|
|
2
|
+
import { defaultPayloadConverter } from './payload-converters';
|
|
3
|
+
import { WrappedPayloadConverter } from './wrapped-payload-converter';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* When your data (arguments and return values) is sent over the wire and stored by Temporal Server, it is encoded in
|
|
@@ -34,20 +35,24 @@ export interface DataConverter {
|
|
|
34
35
|
payloadConverterPath?: string;
|
|
35
36
|
|
|
36
37
|
/**
|
|
37
|
-
*
|
|
38
|
+
* An array of {@link PayloadCodec} instances.
|
|
39
|
+
*
|
|
40
|
+
* Payloads are encoded in the order of the array and decoded in the opposite order. For example, if you have a
|
|
41
|
+
* compression codec and an encryption codec, then you want data to be encoded with the compression codec first, so
|
|
42
|
+
* you'd do `payloadCodecs: [compressionCodec, encryptionCodec]`.
|
|
38
43
|
*/
|
|
39
|
-
|
|
44
|
+
payloadCodecs?: PayloadCodec[];
|
|
40
45
|
}
|
|
41
46
|
|
|
42
47
|
/**
|
|
43
48
|
* A {@link DataConverter} that has been loaded via {@link loadDataConverter}.
|
|
44
49
|
*/
|
|
45
50
|
export interface LoadedDataConverter {
|
|
46
|
-
payloadConverter:
|
|
47
|
-
|
|
51
|
+
payloadConverter: WrappedPayloadConverter;
|
|
52
|
+
payloadCodecs: PayloadCodec[];
|
|
48
53
|
}
|
|
49
54
|
|
|
50
55
|
export const defaultDataConverter: LoadedDataConverter = {
|
|
51
|
-
payloadConverter: defaultPayloadConverter,
|
|
52
|
-
|
|
56
|
+
payloadConverter: new WrappedPayloadConverter(defaultPayloadConverter),
|
|
57
|
+
payloadCodecs: [],
|
|
53
58
|
};
|
|
@@ -20,11 +20,3 @@ export interface PayloadCodec {
|
|
|
20
20
|
*/
|
|
21
21
|
decode(payloads: Payload[]): Promise<Payload[]>;
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* No-op implementation of {@link PayloadCodec}.
|
|
26
|
-
*/
|
|
27
|
-
export const defaultPayloadCodec = {
|
|
28
|
-
encode: async (payloads: Payload[]): Promise<Payload[]> => payloads,
|
|
29
|
-
decode: async (payloads: Payload[]): Promise<Payload[]> => payloads,
|
|
30
|
-
};
|
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
BinaryPayloadConverter,
|
|
4
|
-
JsonPayloadConverter,
|
|
5
|
-
PayloadConverterWithEncoding,
|
|
6
|
-
UndefinedPayloadConverter,
|
|
7
|
-
} from './payload-converters';
|
|
8
|
-
import { METADATA_ENCODING_KEY, Payload, str } from './types';
|
|
1
|
+
import { Payload } from './types';
|
|
2
|
+
import { WrappedPayloadConverter } from './wrapped-payload-converter';
|
|
9
3
|
|
|
10
4
|
/**
|
|
11
|
-
* Used by the framework to serialize/deserialize parameters and return values.
|
|
5
|
+
* Used by the framework to serialize/deserialize data like parameters and return values.
|
|
12
6
|
*
|
|
13
7
|
* This is called inside the [Workflow isolate](https://docs.temporal.io/docs/typescript/determinism).
|
|
14
8
|
* To write async code or use Node APIs (or use packages that use Node APIs), use a {@link PayloadCodec}.
|
|
@@ -16,7 +10,9 @@ import { METADATA_ENCODING_KEY, Payload, str } from './types';
|
|
|
16
10
|
export interface PayloadConverter {
|
|
17
11
|
/**
|
|
18
12
|
* Converts a value to a {@link Payload}.
|
|
19
|
-
*
|
|
13
|
+
*
|
|
14
|
+
* @param value The value to convert. Example values include the Workflow args sent from the Client and the values returned by a Workflow or Activity.
|
|
15
|
+
* @returns The {@link Payload}, or `undefined` if unable to convert.
|
|
20
16
|
*/
|
|
21
17
|
toPayload<T>(value: T): Payload | undefined;
|
|
22
18
|
|
|
@@ -26,60 +22,13 @@ export interface PayloadConverter {
|
|
|
26
22
|
fromPayload<T>(payload: Payload): T;
|
|
27
23
|
}
|
|
28
24
|
|
|
29
|
-
export class CompositePayloadConverter implements PayloadConverter {
|
|
30
|
-
readonly converters: PayloadConverterWithEncoding[];
|
|
31
|
-
readonly converterByEncoding: Map<string, PayloadConverterWithEncoding> = new Map();
|
|
32
|
-
|
|
33
|
-
constructor(...converters: PayloadConverterWithEncoding[]) {
|
|
34
|
-
this.converters = converters;
|
|
35
|
-
for (const converter of converters) {
|
|
36
|
-
this.converterByEncoding.set(converter.encodingType, converter);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Tries to run `.toPayload(value)` on each converter in the order provided at construction.
|
|
42
|
-
* Returns the first successful result, or `undefined` if there is no converter that can handle the value.
|
|
43
|
-
*
|
|
44
|
-
* @throws UnsupportedJsonTypeError
|
|
45
|
-
*/
|
|
46
|
-
public toPayload<T>(value: T): Payload | undefined {
|
|
47
|
-
for (const converter of this.converters) {
|
|
48
|
-
const result = converter.toPayload(value);
|
|
49
|
-
if (result !== undefined) {
|
|
50
|
-
return result;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return undefined;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Run {@link PayloadConverterWithEncoding.fromPayload} based on the {@link encodingTypes | encoding type} of the {@link Payload}.
|
|
58
|
-
*/
|
|
59
|
-
public fromPayload<T>(payload: Payload): T {
|
|
60
|
-
if (payload.metadata === undefined || payload.metadata === null) {
|
|
61
|
-
throw new ValueError('Missing payload metadata');
|
|
62
|
-
}
|
|
63
|
-
const encoding = str(payload.metadata[METADATA_ENCODING_KEY]);
|
|
64
|
-
const converter = this.converterByEncoding.get(encoding);
|
|
65
|
-
if (converter === undefined) {
|
|
66
|
-
throw new ValueError(`Unknown encoding: ${encoding}`);
|
|
67
|
-
}
|
|
68
|
-
return converter.fromPayload(payload);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
25
|
/**
|
|
73
26
|
* Tries to convert `value` to a {@link Payload}. Throws if conversion fails.
|
|
74
27
|
*
|
|
75
|
-
* @throws {@link
|
|
28
|
+
* @throws {@link ValueError}
|
|
76
29
|
*/
|
|
77
|
-
export function toPayload(converter:
|
|
78
|
-
|
|
79
|
-
if (payload === undefined) {
|
|
80
|
-
throw new PayloadConverterError(`Failed to convert value: ${value}`);
|
|
81
|
-
}
|
|
82
|
-
return payload;
|
|
30
|
+
export function toPayload(converter: WrappedPayloadConverter, value: unknown): Payload {
|
|
31
|
+
return converter.toPayload(value);
|
|
83
32
|
}
|
|
84
33
|
|
|
85
34
|
/**
|
|
@@ -87,11 +36,11 @@ export function toPayload(converter: PayloadConverter, value: unknown): Payload
|
|
|
87
36
|
*
|
|
88
37
|
* @param converter
|
|
89
38
|
* @param values JS values to convert to Payloads
|
|
90
|
-
* @return
|
|
91
|
-
* @throws
|
|
39
|
+
* @return list of {@link Payload}s
|
|
40
|
+
* @throws {@link ValueError} if conversion of the value passed as parameter failed for any
|
|
92
41
|
* reason.
|
|
93
42
|
*/
|
|
94
|
-
export function toPayloads(converter:
|
|
43
|
+
export function toPayloads(converter: WrappedPayloadConverter, ...values: unknown[]): Payload[] | undefined {
|
|
95
44
|
if (values.length === 0) {
|
|
96
45
|
return undefined;
|
|
97
46
|
}
|
|
@@ -102,9 +51,12 @@ export function toPayloads(converter: PayloadConverter, ...values: unknown[]): P
|
|
|
102
51
|
/**
|
|
103
52
|
* Run {@link PayloadConverter.toPayload} on each value in the map.
|
|
104
53
|
*
|
|
105
|
-
* @throws {@link
|
|
54
|
+
* @throws {@link ValueError} if conversion of any value in the map fails
|
|
106
55
|
*/
|
|
107
|
-
export function mapToPayloads<K extends string>(
|
|
56
|
+
export function mapToPayloads<K extends string>(
|
|
57
|
+
converter: WrappedPayloadConverter,
|
|
58
|
+
map: Record<K, any>
|
|
59
|
+
): Record<K, Payload> {
|
|
108
60
|
return Object.fromEntries(
|
|
109
61
|
Object.entries(map).map(([k, v]): [K, Payload] => [k as K, toPayload(converter, v)])
|
|
110
62
|
) as Record<K, Payload>;
|
|
@@ -121,7 +73,11 @@ export function mapToPayloads<K extends string>(converter: PayloadConverter, map
|
|
|
121
73
|
* @throws {@link PayloadConverterError} if conversion of the data passed as parameter failed for any
|
|
122
74
|
* reason.
|
|
123
75
|
*/
|
|
124
|
-
export function fromPayloadsAtIndex<T>(
|
|
76
|
+
export function fromPayloadsAtIndex<T>(
|
|
77
|
+
converter: WrappedPayloadConverter,
|
|
78
|
+
index: number,
|
|
79
|
+
payloads?: Payload[] | null
|
|
80
|
+
): T {
|
|
125
81
|
// To make adding arguments a backwards compatible change
|
|
126
82
|
if (payloads === undefined || payloads === null || index >= payloads.length) {
|
|
127
83
|
return undefined as any;
|
|
@@ -132,7 +88,7 @@ export function fromPayloadsAtIndex<T>(converter: PayloadConverter, index: numbe
|
|
|
132
88
|
/**
|
|
133
89
|
* Run {@link PayloadConverter.fromPayload} on each value in the array.
|
|
134
90
|
*/
|
|
135
|
-
export function arrayFromPayloads(converter:
|
|
91
|
+
export function arrayFromPayloads(converter: WrappedPayloadConverter, payloads?: Payload[] | null): unknown[] {
|
|
136
92
|
if (!payloads) {
|
|
137
93
|
return [];
|
|
138
94
|
}
|
|
@@ -140,7 +96,7 @@ export function arrayFromPayloads(converter: PayloadConverter, payloads?: Payloa
|
|
|
140
96
|
}
|
|
141
97
|
|
|
142
98
|
export function mapFromPayloads<K extends string>(
|
|
143
|
-
converter:
|
|
99
|
+
converter: WrappedPayloadConverter,
|
|
144
100
|
map?: Record<K, Payload> | null | undefined
|
|
145
101
|
): Record<K, unknown> | undefined {
|
|
146
102
|
if (map === undefined || map === null) return undefined;
|
|
@@ -151,27 +107,3 @@ export function mapFromPayloads<K extends string>(
|
|
|
151
107
|
})
|
|
152
108
|
) as Record<K, unknown>;
|
|
153
109
|
}
|
|
154
|
-
|
|
155
|
-
export const searchAttributePayloadConverter = new JsonPayloadConverter();
|
|
156
|
-
|
|
157
|
-
export class DefaultPayloadConverter extends CompositePayloadConverter {
|
|
158
|
-
// Match the order used in other SDKs, but exclude Protobuf converters so that the code, including
|
|
159
|
-
// `proto3-json-serializer`, doesn't take space in Workflow bundles that don't use Protobufs. To use Protobufs, use
|
|
160
|
-
// {@link DefaultPayloadConverterWithProtobufs}.
|
|
161
|
-
//
|
|
162
|
-
// Go SDK:
|
|
163
|
-
// https://github.com/temporalio/sdk-go/blob/5e5645f0c550dcf717c095ae32c76a7087d2e985/converter/default_data_converter.go#L28
|
|
164
|
-
constructor() {
|
|
165
|
-
super(new UndefinedPayloadConverter(), new BinaryPayloadConverter(), new JsonPayloadConverter());
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* The default {@link PayloadConverter} used by the SDK.
|
|
171
|
-
* Supports `Uint8Array` and JSON serializables (so if [`JSON.stringify(yourArgOrRetval)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#description) works, the default payload converter will work).
|
|
172
|
-
*
|
|
173
|
-
* To also support Protobufs, create a custom payload converter with {@link DefaultPayloadConverter}:
|
|
174
|
-
*
|
|
175
|
-
* `const myConverter = new DefaultPayloadConverter({ protobufRoot })`
|
|
176
|
-
*/
|
|
177
|
-
export const defaultPayloadConverter = new DefaultPayloadConverter();
|
|
@@ -1,11 +1,64 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PayloadConverterError, ValueError } from '@temporalio/internal-workflow-common';
|
|
2
2
|
import { PayloadConverter } from './payload-converter';
|
|
3
3
|
import { encodingKeys, encodingTypes, METADATA_ENCODING_KEY, Payload, str, u8 } from './types';
|
|
4
|
+
import { WrappedPayloadConverter } from './wrapped-payload-converter';
|
|
4
5
|
|
|
5
6
|
export interface PayloadConverterWithEncoding extends PayloadConverter {
|
|
6
7
|
readonly encodingType: string;
|
|
7
8
|
}
|
|
8
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Tries to convert values to {@link Payload}s using the {@link PayloadConverterWithEncoding}s provided to the constructor, in the order provided.
|
|
12
|
+
*
|
|
13
|
+
* Converts Payloads to values based on the `Payload.metadata.encoding` field, which matches the {@link PayloadConverterWithEncoding.encodingType}
|
|
14
|
+
* of the converter that created the Payload.
|
|
15
|
+
*/
|
|
16
|
+
export class CompositePayloadConverter implements PayloadConverter {
|
|
17
|
+
readonly converters: PayloadConverterWithEncoding[];
|
|
18
|
+
readonly converterByEncoding: Map<string, PayloadConverterWithEncoding> = new Map();
|
|
19
|
+
|
|
20
|
+
constructor(...converters: PayloadConverterWithEncoding[]) {
|
|
21
|
+
if (converters.length === 0) {
|
|
22
|
+
throw new PayloadConverterError('Must provide at least one PayloadConverterWithEncoding');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
this.converters = converters;
|
|
26
|
+
for (const converter of converters) {
|
|
27
|
+
this.converterByEncoding.set(converter.encodingType, converter);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Tries to run `.toPayload(value)` on each converter in the order provided at construction.
|
|
33
|
+
* Returns the first successful result, or `undefined` if there is no converter that can handle the value.
|
|
34
|
+
*/
|
|
35
|
+
public toPayload<T>(value: T): Payload | undefined {
|
|
36
|
+
for (const converter of this.converters) {
|
|
37
|
+
const result = converter.toPayload(value);
|
|
38
|
+
if (result !== undefined) {
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Run {@link PayloadConverterWithEncoding.fromPayload} based on the {@link encodingTypes | encoding type} of the {@link Payload}.
|
|
48
|
+
*/
|
|
49
|
+
public fromPayload<T>(payload: Payload): T {
|
|
50
|
+
if (payload.metadata === undefined || payload.metadata === null) {
|
|
51
|
+
throw new ValueError('Missing payload metadata');
|
|
52
|
+
}
|
|
53
|
+
const encoding = str(payload.metadata[METADATA_ENCODING_KEY]);
|
|
54
|
+
const converter = this.converterByEncoding.get(encoding);
|
|
55
|
+
if (converter === undefined) {
|
|
56
|
+
throw new ValueError(`Unknown encoding: ${encoding}`);
|
|
57
|
+
}
|
|
58
|
+
return converter.fromPayload(payload);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
9
62
|
/**
|
|
10
63
|
* Converts between JS undefined and NULL Payload
|
|
11
64
|
*/
|
|
@@ -13,7 +66,10 @@ export class UndefinedPayloadConverter implements PayloadConverterWithEncoding {
|
|
|
13
66
|
public encodingType = encodingTypes.METADATA_ENCODING_NULL;
|
|
14
67
|
|
|
15
68
|
public toPayload(value: unknown): Payload | undefined {
|
|
16
|
-
if (value !== undefined)
|
|
69
|
+
if (value !== undefined) {
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
|
|
17
73
|
return {
|
|
18
74
|
metadata: {
|
|
19
75
|
[METADATA_ENCODING_KEY]: encodingKeys.METADATA_ENCODING_NULL,
|
|
@@ -28,25 +84,20 @@ export class UndefinedPayloadConverter implements PayloadConverterWithEncoding {
|
|
|
28
84
|
|
|
29
85
|
/**
|
|
30
86
|
* Converts between non-undefined values and serialized JSON Payload
|
|
31
|
-
*
|
|
32
|
-
* @throws UnsupportedJsonTypeError
|
|
33
87
|
*/
|
|
34
88
|
export class JsonPayloadConverter implements PayloadConverterWithEncoding {
|
|
35
89
|
public encodingType = encodingTypes.METADATA_ENCODING_JSON;
|
|
36
90
|
|
|
37
91
|
public toPayload(value: unknown): Payload | undefined {
|
|
38
|
-
if (value === undefined)
|
|
92
|
+
if (value === undefined) {
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
39
95
|
|
|
40
96
|
let json;
|
|
41
97
|
try {
|
|
42
98
|
json = JSON.stringify(value);
|
|
43
99
|
} catch (e) {
|
|
44
|
-
|
|
45
|
-
`Can't run JSON.stringify on this value: ${value}. Either convert it (or its properties) to JSON-serializable values (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#description ), or use a custom data converter: https://docs.temporal.io/docs/typescript/data-converters . JSON.stringify error message: ${errorMessage(
|
|
46
|
-
e
|
|
47
|
-
)}`,
|
|
48
|
-
e as Error
|
|
49
|
-
);
|
|
100
|
+
return undefined;
|
|
50
101
|
}
|
|
51
102
|
|
|
52
103
|
return {
|
|
@@ -73,7 +124,10 @@ export class BinaryPayloadConverter implements PayloadConverterWithEncoding {
|
|
|
73
124
|
|
|
74
125
|
public toPayload(value: unknown): Payload | undefined {
|
|
75
126
|
// TODO: support any DataView or ArrayBuffer?
|
|
76
|
-
if (!(value instanceof Uint8Array))
|
|
127
|
+
if (!(value instanceof Uint8Array)) {
|
|
128
|
+
return undefined;
|
|
129
|
+
}
|
|
130
|
+
|
|
77
131
|
return {
|
|
78
132
|
metadata: {
|
|
79
133
|
[METADATA_ENCODING_KEY]: encodingKeys.METADATA_ENCODING_RAW,
|
|
@@ -87,3 +141,27 @@ export class BinaryPayloadConverter implements PayloadConverterWithEncoding {
|
|
|
87
141
|
return content.data as any;
|
|
88
142
|
}
|
|
89
143
|
}
|
|
144
|
+
|
|
145
|
+
export const searchAttributePayloadConverter = new WrappedPayloadConverter(new JsonPayloadConverter());
|
|
146
|
+
|
|
147
|
+
export class DefaultPayloadConverter extends CompositePayloadConverter {
|
|
148
|
+
// Match the order used in other SDKs, but exclude Protobuf converters so that the code, including
|
|
149
|
+
// `proto3-json-serializer`, doesn't take space in Workflow bundles that don't use Protobufs. To use Protobufs, use
|
|
150
|
+
// {@link DefaultPayloadConverterWithProtobufs}.
|
|
151
|
+
//
|
|
152
|
+
// Go SDK:
|
|
153
|
+
// https://github.com/temporalio/sdk-go/blob/5e5645f0c550dcf717c095ae32c76a7087d2e985/converter/default_data_converter.go#L28
|
|
154
|
+
constructor() {
|
|
155
|
+
super(new UndefinedPayloadConverter(), new BinaryPayloadConverter(), new JsonPayloadConverter());
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* The default {@link PayloadConverter} used by the SDK.
|
|
161
|
+
* Supports `Uint8Array` and JSON serializables (so if [`JSON.stringify(yourArgOrRetval)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#description) works, the default payload converter will work).
|
|
162
|
+
*
|
|
163
|
+
* To also support Protobufs, create a custom payload converter with {@link DefaultPayloadConverter}:
|
|
164
|
+
*
|
|
165
|
+
* `const myConverter = new DefaultPayloadConverter({ protobufRoot })`
|
|
166
|
+
*/
|
|
167
|
+
export const defaultPayloadConverter = new DefaultPayloadConverter();
|
|
@@ -8,9 +8,9 @@ import {
|
|
|
8
8
|
} from '@temporalio/internal-workflow-common';
|
|
9
9
|
import * as protoJsonSerializer from 'proto3-json-serializer';
|
|
10
10
|
import type { Message, Namespace, Root, Type } from 'protobufjs';
|
|
11
|
-
import { CompositePayloadConverter } from './payload-converter';
|
|
12
11
|
import {
|
|
13
12
|
BinaryPayloadConverter,
|
|
13
|
+
CompositePayloadConverter,
|
|
14
14
|
JsonPayloadConverter,
|
|
15
15
|
PayloadConverterWithEncoding,
|
|
16
16
|
UndefinedPayloadConverter,
|
|
@@ -96,7 +96,9 @@ export class ProtobufBinaryPayloadConverter extends ProtobufPayloadConverter {
|
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
public toPayload(value: unknown): Payload | undefined {
|
|
99
|
-
if (!isProtobufMessage(value))
|
|
99
|
+
if (!isProtobufMessage(value)) {
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
100
102
|
|
|
101
103
|
return this.constructPayload({
|
|
102
104
|
messageTypeName: getNamespacedTypeName(value.$type),
|
|
@@ -124,7 +126,9 @@ export class ProtobufJsonPayloadConverter extends ProtobufPayloadConverter {
|
|
|
124
126
|
}
|
|
125
127
|
|
|
126
128
|
public toPayload(value: unknown): Payload | undefined {
|
|
127
|
-
if (!isProtobufMessage(value))
|
|
129
|
+
if (!isProtobufMessage(value)) {
|
|
130
|
+
return undefined;
|
|
131
|
+
}
|
|
128
132
|
|
|
129
133
|
const jsonValue = protoJsonSerializer.toProto3JSON(value);
|
|
130
134
|
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { hasOwnProperty, isRecord, ValueError } from '@temporalio/internal-workflow-common';
|
|
2
|
+
import { PayloadConverter } from './payload-converter';
|
|
3
|
+
import { Payload } from './types';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* When we call {@link PayloadConverter.toPayload}, we want it to either throw or return a Payload, so we wrap Payload
|
|
7
|
+
* Converters with this class before using them.
|
|
8
|
+
*/
|
|
9
|
+
export class WrappedPayloadConverter implements PayloadConverter {
|
|
10
|
+
constructor(private readonly payloadConverter: PayloadConverter) {}
|
|
11
|
+
|
|
12
|
+
public toPayload(value: unknown): Payload {
|
|
13
|
+
const result = this.payloadConverter.toPayload(value);
|
|
14
|
+
if (!isPayload(result)) {
|
|
15
|
+
throw new ValueError(
|
|
16
|
+
`The Payload Converter method ${
|
|
17
|
+
Object.getPrototypeOf(this.payloadConverter).constructor.name
|
|
18
|
+
}.toPayload must return a Payload. Received \`${result}\` of type \`${typeof result}\` when trying to convert \`${value}\` of type \`${typeof value}\`.`
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public fromPayload<T>(payload: Payload): T {
|
|
25
|
+
return this.payloadConverter.fromPayload(payload);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function isPayload(payload: unknown): payload is Payload {
|
|
30
|
+
return isRecord(payload) && (hasOwnProperty(payload, 'metadata') || hasOwnProperty(payload, 'data'));
|
|
31
|
+
}
|
package/src/failure.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { checkExtends, hasOwnProperties, isRecord } from '@temporalio/internal-workflow-common';
|
|
2
2
|
import type { temporal } from '@temporalio/proto';
|
|
3
|
-
import { arrayFromPayloads, fromPayloadsAtIndex,
|
|
3
|
+
import { arrayFromPayloads, fromPayloadsAtIndex, toPayloads } from './converter/payload-converter';
|
|
4
|
+
import { WrappedPayloadConverter } from './converter/wrapped-payload-converter';
|
|
4
5
|
|
|
5
6
|
export const FAILURE_SOURCE = 'TypeScriptSDK';
|
|
6
7
|
export type ProtoFailure = temporal.api.failure.v1.IFailure;
|
|
@@ -213,7 +214,7 @@ export class ChildWorkflowFailure extends TemporalFailure {
|
|
|
213
214
|
*/
|
|
214
215
|
export function optionalErrorToOptionalFailure(
|
|
215
216
|
err: unknown,
|
|
216
|
-
payloadConverter:
|
|
217
|
+
payloadConverter: WrappedPayloadConverter
|
|
217
218
|
): ProtoFailure | undefined {
|
|
218
219
|
return err ? errorToFailure(err, payloadConverter) : undefined;
|
|
219
220
|
}
|
|
@@ -248,7 +249,7 @@ export function cutoffStackTrace(stack?: string): string {
|
|
|
248
249
|
/**
|
|
249
250
|
* Converts a caught error to a Failure proto message
|
|
250
251
|
*/
|
|
251
|
-
export function errorToFailure(err: unknown, payloadConverter:
|
|
252
|
+
export function errorToFailure(err: unknown, payloadConverter: WrappedPayloadConverter): ProtoFailure {
|
|
252
253
|
if (err instanceof TemporalFailure) {
|
|
253
254
|
if (err.failure) return err.failure;
|
|
254
255
|
|
|
@@ -372,7 +373,7 @@ export function ensureTemporalFailure(err: unknown): TemporalFailure {
|
|
|
372
373
|
*/
|
|
373
374
|
export function optionalFailureToOptionalError(
|
|
374
375
|
failure: ProtoFailure | undefined | null,
|
|
375
|
-
payloadConverter:
|
|
376
|
+
payloadConverter: WrappedPayloadConverter
|
|
376
377
|
): TemporalFailure | undefined {
|
|
377
378
|
return failure ? failureToError(failure, payloadConverter) : undefined;
|
|
378
379
|
}
|
|
@@ -382,7 +383,7 @@ export function optionalFailureToOptionalError(
|
|
|
382
383
|
*
|
|
383
384
|
* Does not set common properties, that is done in {@link failureToError}.
|
|
384
385
|
*/
|
|
385
|
-
export function failureToErrorInner(failure: ProtoFailure, payloadConverter:
|
|
386
|
+
export function failureToErrorInner(failure: ProtoFailure, payloadConverter: WrappedPayloadConverter): TemporalFailure {
|
|
386
387
|
if (failure.applicationFailureInfo) {
|
|
387
388
|
return new ApplicationFailure(
|
|
388
389
|
failure.message ?? undefined,
|
|
@@ -462,7 +463,7 @@ export function failureToErrorInner(failure: ProtoFailure, payloadConverter: Pay
|
|
|
462
463
|
/**
|
|
463
464
|
* Converts a Failure proto message to a JS Error object.
|
|
464
465
|
*/
|
|
465
|
-
export function failureToError(failure: ProtoFailure, payloadConverter:
|
|
466
|
+
export function failureToError(failure: ProtoFailure, payloadConverter: WrappedPayloadConverter): TemporalFailure {
|
|
466
467
|
const err = failureToErrorInner(failure, payloadConverter);
|
|
467
468
|
err.stack = failure.stackTrace ?? '';
|
|
468
469
|
err.failure = failure;
|