@temporalio/common 1.3.0 → 1.4.1
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/activity-options.d.ts +138 -0
- package/lib/activity-options.js +15 -0
- package/lib/activity-options.js.map +1 -0
- package/lib/converter/data-converter.d.ts +20 -1
- package/lib/converter/data-converter.js +14 -3
- package/lib/converter/data-converter.js.map +1 -1
- package/lib/converter/failure-converter.d.ts +75 -0
- package/lib/converter/failure-converter.js +239 -0
- package/lib/converter/failure-converter.js.map +1 -0
- package/lib/converter/payload-codec.d.ts +1 -1
- package/lib/converter/payload-converter.d.ts +85 -1
- package/lib/converter/payload-converter.js +210 -1
- package/lib/converter/payload-converter.js.map +1 -1
- package/lib/converter/protobuf-payload-converters.d.ts +3 -3
- package/lib/converter/protobuf-payload-converters.js +20 -19
- package/lib/converter/protobuf-payload-converters.js.map +1 -1
- package/lib/converter/types.d.ts +0 -6
- package/lib/converter/types.js +7 -18
- package/lib/converter/types.js.map +1 -1
- package/lib/deprecated-time.d.ts +52 -0
- package/lib/deprecated-time.js +106 -0
- package/lib/deprecated-time.js.map +1 -0
- package/lib/{converter/encoding.d.ts → encoding.d.ts} +8 -0
- package/lib/{converter/encoding.js → encoding.js} +15 -1
- package/lib/encoding.js.map +1 -0
- package/lib/errors.d.ts +47 -0
- package/lib/errors.js +68 -0
- package/lib/errors.js.map +1 -0
- package/lib/failure.d.ts +0 -27
- package/lib/failure.js +9 -205
- package/lib/failure.js.map +1 -1
- package/lib/index.d.ts +39 -8
- package/lib/index.js +64 -7
- package/lib/index.js.map +1 -1
- package/lib/interceptors.d.ts +18 -0
- package/lib/interceptors.js +24 -0
- package/lib/interceptors.js.map +1 -0
- package/lib/interfaces.d.ts +52 -0
- package/lib/interfaces.js +3 -0
- package/lib/interfaces.js.map +1 -0
- package/lib/internal-non-workflow/codec-helpers.d.ts +82 -0
- package/lib/internal-non-workflow/codec-helpers.js +295 -0
- package/lib/internal-non-workflow/codec-helpers.js.map +1 -0
- package/lib/internal-non-workflow/codec-types.d.ts +22 -0
- package/lib/internal-non-workflow/codec-types.js +3 -0
- package/lib/internal-non-workflow/codec-types.js.map +1 -0
- package/lib/internal-non-workflow/data-converter-helpers.d.ts +11 -0
- package/lib/internal-non-workflow/data-converter-helpers.js +66 -0
- package/lib/internal-non-workflow/data-converter-helpers.js.map +1 -0
- package/lib/internal-non-workflow/index.d.ts +10 -0
- package/lib/internal-non-workflow/index.js +27 -0
- package/lib/internal-non-workflow/index.js.map +1 -0
- package/lib/internal-non-workflow/tls-config.d.ts +32 -0
- package/lib/internal-non-workflow/tls-config.js +11 -0
- package/lib/internal-non-workflow/tls-config.js.map +1 -0
- package/lib/internal-non-workflow/utils.d.ts +4 -0
- package/lib/internal-non-workflow/utils.js +11 -0
- package/lib/internal-non-workflow/utils.js.map +1 -0
- package/lib/otel.d.ts +1 -1
- package/lib/otel.js +2 -2
- package/lib/otel.js.map +1 -1
- package/lib/retry-policy.d.ts +48 -0
- package/lib/retry-policy.js +62 -0
- package/lib/retry-policy.js.map +1 -0
- package/lib/time.d.ts +18 -0
- package/lib/time.js +79 -0
- package/lib/time.js.map +1 -0
- package/lib/type-helpers.d.ts +21 -0
- package/lib/type-helpers.js +46 -0
- package/lib/type-helpers.js.map +1 -0
- package/lib/workflow-handle.d.ts +27 -0
- package/lib/workflow-handle.js +3 -0
- package/lib/workflow-handle.js.map +1 -0
- package/lib/workflow-options.d.ts +118 -0
- package/lib/workflow-options.js +53 -0
- package/lib/workflow-options.js.map +1 -0
- package/package.json +5 -4
- package/src/activity-options.ts +159 -0
- package/src/converter/data-converter.ts +24 -3
- package/src/converter/failure-converter.ts +355 -0
- package/src/converter/payload-codec.ts +1 -1
- package/src/converter/payload-converter.ts +246 -1
- package/src/converter/protobuf-payload-converters.ts +14 -25
- package/src/converter/types.ts +6 -19
- package/src/deprecated-time.ts +80 -0
- package/src/{converter/encoding.ts → encoding.ts} +14 -0
- package/src/errors.ts +55 -0
- package/src/failure.ts +1 -251
- package/src/index.ts +55 -8
- package/src/interceptors.ts +32 -0
- package/src/interfaces.ts +64 -0
- package/src/internal-non-workflow/codec-helpers.ts +348 -0
- package/src/internal-non-workflow/codec-types.ts +34 -0
- package/src/internal-non-workflow/data-converter-helpers.ts +81 -0
- package/src/internal-non-workflow/index.ts +10 -0
- package/src/internal-non-workflow/tls-config.ts +35 -0
- package/src/internal-non-workflow/utils.ts +6 -0
- package/src/otel.ts +2 -2
- package/src/retry-policy.ts +101 -0
- package/src/time.ts +79 -0
- package/src/type-helpers.ts +64 -0
- package/src/workflow-handle.ts +30 -0
- package/src/workflow-options.ts +156 -0
- package/lib/converter/encoding.js.map +0 -1
- package/lib/converter/json-payload-converter.d.ts +0 -10
- package/lib/converter/json-payload-converter.js +0 -39
- package/lib/converter/json-payload-converter.js.map +0 -1
- package/lib/converter/payload-converters.d.ts +0 -67
- package/lib/converter/payload-converters.js +0 -124
- package/lib/converter/payload-converters.js.map +0 -1
- package/lib/converter/search-attribute-payload-converter.d.ts +0 -12
- package/lib/converter/search-attribute-payload-converter.js +0 -64
- package/lib/converter/search-attribute-payload-converter.js.map +0 -1
- package/src/converter/json-payload-converter.ts +0 -37
- package/src/converter/payload-converters.ts +0 -148
- package/src/converter/search-attribute-payload-converter.ts +0 -71
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import type { coresdk } from '@temporalio/proto';
|
|
2
|
+
import { RetryPolicy } from './retry-policy';
|
|
3
|
+
export declare enum ActivityCancellationType {
|
|
4
|
+
TRY_CANCEL = 0,
|
|
5
|
+
WAIT_CANCELLATION_COMPLETED = 1,
|
|
6
|
+
ABANDON = 2
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Options for remote activity invocation
|
|
10
|
+
*/
|
|
11
|
+
export interface ActivityOptions {
|
|
12
|
+
/**
|
|
13
|
+
* Identifier to use for tracking the activity in Workflow history.
|
|
14
|
+
* The `activityId` can be accessed by the activity function.
|
|
15
|
+
* Does not need to be unique.
|
|
16
|
+
*
|
|
17
|
+
* @default an incremental sequence number
|
|
18
|
+
*/
|
|
19
|
+
activityId?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Task queue name.
|
|
22
|
+
*
|
|
23
|
+
* @default current worker task queue
|
|
24
|
+
*/
|
|
25
|
+
taskQueue?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Heartbeat interval. Activity must heartbeat before this interval passes after a last heartbeat or activity start.
|
|
28
|
+
* @format number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
|
|
29
|
+
*/
|
|
30
|
+
heartbeatTimeout?: string | number;
|
|
31
|
+
/**
|
|
32
|
+
* RetryPolicy that define how activity is retried in case of failure. If this is not set, then the server-defined default activity retry policy will be used. To ensure zero retries, set maximum attempts to 1.
|
|
33
|
+
*/
|
|
34
|
+
retry?: RetryPolicy;
|
|
35
|
+
/**
|
|
36
|
+
* Maximum time of a single Activity execution attempt.
|
|
37
|
+
Note that the Temporal Server doesn't detect Worker process failures directly. It relies on this timeout to detect that an Activity that didn't complete on time. So this timeout should be as short as the longest possible execution of the Activity body. Potentially long running Activities must specify {@link heartbeatTimeout} and call {@link activity.Context.heartbeat} periodically for timely failure detection.
|
|
38
|
+
|
|
39
|
+
* Either this option or {@link scheduleToCloseTimeout} is required.
|
|
40
|
+
* @format number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
|
|
41
|
+
*/
|
|
42
|
+
startToCloseTimeout?: string | number;
|
|
43
|
+
/**
|
|
44
|
+
* Time that the Activity Task can stay in the Task Queue before it is picked up by a Worker. Do not specify this timeout unless using host specific Task Queues for Activity Tasks are being used for routing.
|
|
45
|
+
* `scheduleToStartTimeout` is always non-retryable. Retrying after this timeout doesn't make sense as it would just put the Activity Task back into the same Task Queue.
|
|
46
|
+
* @default unlimited
|
|
47
|
+
* @format number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
|
|
48
|
+
*/
|
|
49
|
+
scheduleToStartTimeout?: string | number;
|
|
50
|
+
/**
|
|
51
|
+
* Total time that a workflow is willing to wait for Activity to complete.
|
|
52
|
+
* `scheduleToCloseTimeout` limits the total time of an Activity's execution including retries (use {@link startToCloseTimeout} to limit the time of a single attempt).
|
|
53
|
+
*
|
|
54
|
+
* Either this option or {@link startToCloseTimeout} is required
|
|
55
|
+
* @default unlimited
|
|
56
|
+
* @format number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
|
|
57
|
+
*/
|
|
58
|
+
scheduleToCloseTimeout?: string | number;
|
|
59
|
+
/**
|
|
60
|
+
* Determines what the SDK does when the Activity is cancelled.
|
|
61
|
+
* - `TRY_CANCEL` - Initiate a cancellation request and immediately report cancellation to the workflow.
|
|
62
|
+
* - `WAIT_CANCELLATION_COMPLETED` - Wait for activity cancellation completion. Note that activity must heartbeat to receive a
|
|
63
|
+
* cancellation notification. This can block the cancellation for a long time if activity doesn't
|
|
64
|
+
* heartbeat or chooses to ignore the cancellation request.
|
|
65
|
+
* - `ABANDON` - Do not request cancellation of the activity and immediately report cancellation to the workflow.
|
|
66
|
+
*/
|
|
67
|
+
cancellationType?: ActivityCancellationType;
|
|
68
|
+
/**
|
|
69
|
+
* Eager dispatch is an optimization that improves the throughput and load on the server for scheduling Activities.
|
|
70
|
+
* When used, the server will hand out Activity tasks back to the Worker when it completes a Workflow task.
|
|
71
|
+
* It is available from server version 1.17 behind the `system.enableActivityEagerExecution` feature flag.
|
|
72
|
+
*
|
|
73
|
+
* Eager dispatch will only be used if `allowEagerDispatch` is enabled (the default) and {@link taskQueue} is either
|
|
74
|
+
* omitted or the same as the current Workflow.
|
|
75
|
+
*
|
|
76
|
+
* @default true
|
|
77
|
+
*/
|
|
78
|
+
allowEagerDispatch?: boolean;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Options for local activity invocation
|
|
82
|
+
*/
|
|
83
|
+
export interface LocalActivityOptions {
|
|
84
|
+
/**
|
|
85
|
+
* RetryPolicy that defines how an activity is retried in case of failure. If this is not set, then the SDK-defined default activity retry policy will be used.
|
|
86
|
+
* Note that local activities are always executed at least once, even if maximum attempts is set to 1 due to Workflow task retries.
|
|
87
|
+
*/
|
|
88
|
+
retry?: RetryPolicy;
|
|
89
|
+
/**
|
|
90
|
+
* Maximum time the local activity is allowed to execute after the task is dispatched. This
|
|
91
|
+
* timeout is always retryable.
|
|
92
|
+
*
|
|
93
|
+
* Either this option or {@link scheduleToCloseTimeout} is required.
|
|
94
|
+
* If set, this must be <= {@link scheduleToCloseTimeout}, otherwise, it will be clamped down.
|
|
95
|
+
*
|
|
96
|
+
* @format number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
|
|
97
|
+
*/
|
|
98
|
+
startToCloseTimeout?: string | number;
|
|
99
|
+
/**
|
|
100
|
+
* Limits time the local activity can idle internally before being executed. That can happen if
|
|
101
|
+
* the worker is currently at max concurrent local activity executions. This timeout is always
|
|
102
|
+
* non retryable as all a retry would achieve is to put it back into the same queue. Defaults
|
|
103
|
+
* to {@link scheduleToCloseTimeout} if not specified and that is set. Must be <=
|
|
104
|
+
* {@link scheduleToCloseTimeout} when set, otherwise, it will be clamped down.
|
|
105
|
+
*
|
|
106
|
+
* @default unlimited
|
|
107
|
+
* @format number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
|
|
108
|
+
*/
|
|
109
|
+
scheduleToStartTimeout?: string | number;
|
|
110
|
+
/**
|
|
111
|
+
* Indicates how long the caller is willing to wait for local activity completion. Limits how
|
|
112
|
+
* long retries will be attempted. When not specified defaults to the workflow execution
|
|
113
|
+
* timeout (which may be unset).
|
|
114
|
+
*
|
|
115
|
+
* Either this option or {@link startToCloseTimeout} is required.
|
|
116
|
+
*
|
|
117
|
+
* @default unlimited
|
|
118
|
+
* @format number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
|
|
119
|
+
*/
|
|
120
|
+
scheduleToCloseTimeout?: string | number;
|
|
121
|
+
/**
|
|
122
|
+
* If the activity is retrying and backoff would exceed this value, a server side timer will be scheduled for the next attempt.
|
|
123
|
+
* Otherwise, backoff will happen internally in the SDK.
|
|
124
|
+
*
|
|
125
|
+
* @default 1 minute
|
|
126
|
+
* @format number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
|
|
127
|
+
**/
|
|
128
|
+
localRetryThreshold?: string | number;
|
|
129
|
+
/**
|
|
130
|
+
* Determines what the SDK does when the Activity is cancelled.
|
|
131
|
+
* - `TRY_CANCEL` - Initiate a cancellation request and immediately report cancellation to the workflow.
|
|
132
|
+
* - `WAIT_CANCELLATION_COMPLETED` - Wait for activity cancellation completion. Note that activity must heartbeat to receive a
|
|
133
|
+
* cancellation notification. This can block the cancellation for a long time if activity doesn't
|
|
134
|
+
* heartbeat or chooses to ignore the cancellation request.
|
|
135
|
+
* - `ABANDON` - Do not request cancellation of the activity and immediately report cancellation to the workflow.
|
|
136
|
+
*/
|
|
137
|
+
cancellationType?: coresdk.workflow_commands.ActivityCancellationType;
|
|
138
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ActivityCancellationType = void 0;
|
|
4
|
+
const type_helpers_1 = require("./type-helpers");
|
|
5
|
+
// Avoid importing the proto implementation to reduce workflow bundle size
|
|
6
|
+
// Copied from coresdk.workflow_commands.ActivityCancellationType
|
|
7
|
+
var ActivityCancellationType;
|
|
8
|
+
(function (ActivityCancellationType) {
|
|
9
|
+
ActivityCancellationType[ActivityCancellationType["TRY_CANCEL"] = 0] = "TRY_CANCEL";
|
|
10
|
+
ActivityCancellationType[ActivityCancellationType["WAIT_CANCELLATION_COMPLETED"] = 1] = "WAIT_CANCELLATION_COMPLETED";
|
|
11
|
+
ActivityCancellationType[ActivityCancellationType["ABANDON"] = 2] = "ABANDON";
|
|
12
|
+
})(ActivityCancellationType = exports.ActivityCancellationType || (exports.ActivityCancellationType = {}));
|
|
13
|
+
(0, type_helpers_1.checkExtends)();
|
|
14
|
+
(0, type_helpers_1.checkExtends)();
|
|
15
|
+
//# sourceMappingURL=activity-options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"activity-options.js","sourceRoot":"","sources":["../src/activity-options.ts"],"names":[],"mappings":";;;AAEA,iDAA8C;AAE9C,0EAA0E;AAC1E,iEAAiE;AACjE,IAAY,wBAIX;AAJD,WAAY,wBAAwB;IAClC,mFAAc,CAAA;IACd,qHAA+B,CAAA;IAC/B,6EAAW,CAAA;AACb,CAAC,EAJW,wBAAwB,GAAxB,gCAAwB,KAAxB,gCAAwB,QAInC;AAED,IAAA,2BAAY,GAAgF,CAAC;AAC7F,IAAA,2BAAY,GAAgF,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { FailureConverter } from './failure-converter';
|
|
1
2
|
import { PayloadCodec } from './payload-codec';
|
|
2
3
|
import { PayloadConverter } from './payload-converter';
|
|
3
4
|
/**
|
|
@@ -27,10 +28,18 @@ import { PayloadConverter } from './payload-converter';
|
|
|
27
28
|
export interface DataConverter {
|
|
28
29
|
/**
|
|
29
30
|
* Path of a file that has a `payloadConverter` named export.
|
|
30
|
-
* `payloadConverter` should be an
|
|
31
|
+
* `payloadConverter` should be an object that implements {@link PayloadConverter}.
|
|
31
32
|
* If no path is provided, {@link defaultPayloadConverter} is used.
|
|
32
33
|
*/
|
|
33
34
|
payloadConverterPath?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Path of a file that has a `failureConverter` named export.
|
|
37
|
+
* `failureConverter` should be an object that implements {@link FailureConverter}.
|
|
38
|
+
* If no path is provided, {@link defaultFailureConverter} is used.
|
|
39
|
+
*
|
|
40
|
+
* @experimental
|
|
41
|
+
*/
|
|
42
|
+
failureConverterPath?: string;
|
|
34
43
|
/**
|
|
35
44
|
* An array of {@link PayloadCodec} instances.
|
|
36
45
|
*
|
|
@@ -45,6 +54,16 @@ export interface DataConverter {
|
|
|
45
54
|
*/
|
|
46
55
|
export interface LoadedDataConverter {
|
|
47
56
|
payloadConverter: PayloadConverter;
|
|
57
|
+
failureConverter: FailureConverter;
|
|
48
58
|
payloadCodecs: PayloadCodec[];
|
|
49
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* The default {@link FailureConverter} used by the SDK.
|
|
62
|
+
*
|
|
63
|
+
* Error messages and stack traces are serizalized as plain text.
|
|
64
|
+
*/
|
|
65
|
+
export declare const defaultFailureConverter: FailureConverter;
|
|
66
|
+
/**
|
|
67
|
+
* A "loaded" data converter that uses the default set of failure and payload converters.
|
|
68
|
+
*/
|
|
50
69
|
export declare const defaultDataConverter: LoadedDataConverter;
|
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.defaultDataConverter = void 0;
|
|
4
|
-
const
|
|
3
|
+
exports.defaultDataConverter = exports.defaultFailureConverter = void 0;
|
|
4
|
+
const failure_converter_1 = require("./failure-converter");
|
|
5
|
+
const payload_converter_1 = require("./payload-converter");
|
|
6
|
+
/**
|
|
7
|
+
* The default {@link FailureConverter} used by the SDK.
|
|
8
|
+
*
|
|
9
|
+
* Error messages and stack traces are serizalized as plain text.
|
|
10
|
+
*/
|
|
11
|
+
exports.defaultFailureConverter = new failure_converter_1.DefaultFailureConverter();
|
|
12
|
+
/**
|
|
13
|
+
* A "loaded" data converter that uses the default set of failure and payload converters.
|
|
14
|
+
*/
|
|
5
15
|
exports.defaultDataConverter = {
|
|
6
|
-
payloadConverter:
|
|
16
|
+
payloadConverter: payload_converter_1.defaultPayloadConverter,
|
|
17
|
+
failureConverter: exports.defaultFailureConverter,
|
|
7
18
|
payloadCodecs: [],
|
|
8
19
|
};
|
|
9
20
|
//# sourceMappingURL=data-converter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-converter.js","sourceRoot":"","sources":["../../src/converter/data-converter.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"data-converter.js","sourceRoot":"","sources":["../../src/converter/data-converter.ts"],"names":[],"mappings":";;;AAAA,2DAAgF;AAEhF,2DAAgF;AA8DhF;;;;GAIG;AACU,QAAA,uBAAuB,GAAqB,IAAI,2CAAuB,EAAE,CAAC;AAEvF;;GAEG;AACU,QAAA,oBAAoB,GAAwB;IACvD,gBAAgB,EAAE,2CAAuB;IACzC,gBAAgB,EAAE,+BAAuB;IACzC,aAAa,EAAE,EAAE;CAClB,CAAC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { ProtoFailure, TemporalFailure } from '../failure';
|
|
2
|
+
import { PayloadConverter } from './payload-converter';
|
|
3
|
+
/**
|
|
4
|
+
* Cuts out the framework part of a stack trace, leaving only user code entries
|
|
5
|
+
*/
|
|
6
|
+
export declare function cutoffStackTrace(stack?: string): string;
|
|
7
|
+
/**
|
|
8
|
+
* A `FailureConverter` is responsible to convert from proto `Failure` instances to JS `Errors` and back.
|
|
9
|
+
*
|
|
10
|
+
* It is recommended to use the {@link DefaultFailureConverter} and not attempt to customize the default implementation
|
|
11
|
+
* in order to maintain cross language failure serialization compatibility.
|
|
12
|
+
*
|
|
13
|
+
* @experimental
|
|
14
|
+
*/
|
|
15
|
+
export interface FailureConverter {
|
|
16
|
+
/**
|
|
17
|
+
* Converts a caught error to a Failure proto message.
|
|
18
|
+
*/
|
|
19
|
+
errorToFailure(err: unknown): ProtoFailure;
|
|
20
|
+
/**
|
|
21
|
+
* Converts a Failure proto message to a JS Error object.
|
|
22
|
+
*/
|
|
23
|
+
failureToError(err: ProtoFailure): TemporalFailure;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The "shape" of the attributes set as the {@link ProtoFailure.encodedAttributes} payload in case
|
|
27
|
+
* {@link DefaultEncodedFailureAttributes.encodeCommonAttributes} is set to `true`.
|
|
28
|
+
*/
|
|
29
|
+
export interface DefaultEncodedFailureAttributes {
|
|
30
|
+
message: string;
|
|
31
|
+
stack_trace: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Options for the {@link DefaultFailureConverter} constructor.
|
|
35
|
+
*/
|
|
36
|
+
export interface DefaultFailureConverterOptions {
|
|
37
|
+
/**
|
|
38
|
+
* The {@link PayloadConverter} to use for converting failure attributes.
|
|
39
|
+
*/
|
|
40
|
+
payloadConverter: PayloadConverter;
|
|
41
|
+
/**
|
|
42
|
+
* Whether to encode error messages and stack traces (for encrypting these attributes use a {@link PayloadCodec}).
|
|
43
|
+
*/
|
|
44
|
+
encodeCommonAttributes: boolean;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Default cross language compatible failure converter.
|
|
48
|
+
*
|
|
49
|
+
* By default, it will leave error messages and stack traces as plain text. In order to encrypt those, set
|
|
50
|
+
* `encodeCommonAttributes` to `true` in the constructor options and make sure to use a {@link PayloadCodec} that can
|
|
51
|
+
* encrypt / decrypt payloads in your Worker and Client options.
|
|
52
|
+
*
|
|
53
|
+
* @experimental
|
|
54
|
+
*/
|
|
55
|
+
export declare class DefaultFailureConverter implements FailureConverter {
|
|
56
|
+
readonly options: DefaultFailureConverterOptions;
|
|
57
|
+
constructor(options?: Partial<DefaultFailureConverterOptions>);
|
|
58
|
+
/**
|
|
59
|
+
* Converts a Failure proto message to a JS Error object.
|
|
60
|
+
*
|
|
61
|
+
* Does not set common properties, that is done in {@link failureToError}.
|
|
62
|
+
*/
|
|
63
|
+
failureToErrorInner(failure: ProtoFailure): TemporalFailure;
|
|
64
|
+
failureToError(failure: ProtoFailure): TemporalFailure;
|
|
65
|
+
errorToFailure(err: unknown): ProtoFailure;
|
|
66
|
+
errorToFailureInner(err: unknown): ProtoFailure;
|
|
67
|
+
/**
|
|
68
|
+
* Converts a Failure proto message to a JS Error object if defined or returns undefined.
|
|
69
|
+
*/
|
|
70
|
+
optionalFailureToOptionalError(failure: ProtoFailure | undefined | null): TemporalFailure | undefined;
|
|
71
|
+
/**
|
|
72
|
+
* Converts an error to a Failure proto message if defined or returns undefined
|
|
73
|
+
*/
|
|
74
|
+
optionalErrorToOptionalFailure(err: unknown): ProtoFailure | undefined;
|
|
75
|
+
}
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DefaultFailureConverter = exports.cutoffStackTrace = void 0;
|
|
4
|
+
const failure_1 = require("../failure");
|
|
5
|
+
const type_helpers_1 = require("../type-helpers");
|
|
6
|
+
const payload_converter_1 = require("./payload-converter");
|
|
7
|
+
/**
|
|
8
|
+
* Stack traces will be cutoff when on of these patterns is matched
|
|
9
|
+
*/
|
|
10
|
+
const CUTOFF_STACK_PATTERNS = [
|
|
11
|
+
/** Activity execution */
|
|
12
|
+
/\s+at Activity\.execute \(.*[\\/]worker[\\/](?:src|lib)[\\/]activity\.[jt]s:\d+:\d+\)/,
|
|
13
|
+
/** Workflow activation */
|
|
14
|
+
/\s+at Activator\.\S+NextHandler \(.*[\\/]workflow[\\/](?:src|lib)[\\/]internals\.[jt]s:\d+:\d+\)/,
|
|
15
|
+
/** Workflow run anything in context */
|
|
16
|
+
/\s+at Script\.runInContext \((?:node:vm|vm\.js):\d+:\d+\)/,
|
|
17
|
+
];
|
|
18
|
+
/**
|
|
19
|
+
* Cuts out the framework part of a stack trace, leaving only user code entries
|
|
20
|
+
*/
|
|
21
|
+
function cutoffStackTrace(stack) {
|
|
22
|
+
const lines = (stack ?? '').split(/\r?\n/);
|
|
23
|
+
const acc = Array();
|
|
24
|
+
lineLoop: for (const line of lines) {
|
|
25
|
+
for (const pattern of CUTOFF_STACK_PATTERNS) {
|
|
26
|
+
if (pattern.test(line))
|
|
27
|
+
break lineLoop;
|
|
28
|
+
}
|
|
29
|
+
acc.push(line);
|
|
30
|
+
}
|
|
31
|
+
return acc.join('\n');
|
|
32
|
+
}
|
|
33
|
+
exports.cutoffStackTrace = cutoffStackTrace;
|
|
34
|
+
/**
|
|
35
|
+
* Default cross language compatible failure converter.
|
|
36
|
+
*
|
|
37
|
+
* By default, it will leave error messages and stack traces as plain text. In order to encrypt those, set
|
|
38
|
+
* `encodeCommonAttributes` to `true` in the constructor options and make sure to use a {@link PayloadCodec} that can
|
|
39
|
+
* encrypt / decrypt payloads in your Worker and Client options.
|
|
40
|
+
*
|
|
41
|
+
* @experimental
|
|
42
|
+
*/
|
|
43
|
+
class DefaultFailureConverter {
|
|
44
|
+
constructor(options) {
|
|
45
|
+
const { encodeCommonAttributes, payloadConverter } = options ?? {};
|
|
46
|
+
this.options = {
|
|
47
|
+
encodeCommonAttributes: encodeCommonAttributes ?? false,
|
|
48
|
+
payloadConverter: payloadConverter ?? payload_converter_1.defaultPayloadConverter,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Converts a Failure proto message to a JS Error object.
|
|
53
|
+
*
|
|
54
|
+
* Does not set common properties, that is done in {@link failureToError}.
|
|
55
|
+
*/
|
|
56
|
+
failureToErrorInner(failure) {
|
|
57
|
+
if (failure.applicationFailureInfo) {
|
|
58
|
+
return new failure_1.ApplicationFailure(failure.message ?? undefined, failure.applicationFailureInfo.type, Boolean(failure.applicationFailureInfo.nonRetryable), (0, payload_converter_1.arrayFromPayloads)(this.options.payloadConverter, failure.applicationFailureInfo.details?.payloads), this.optionalFailureToOptionalError(failure.cause));
|
|
59
|
+
}
|
|
60
|
+
if (failure.serverFailureInfo) {
|
|
61
|
+
return new failure_1.ServerFailure(failure.message ?? undefined, Boolean(failure.serverFailureInfo.nonRetryable), this.optionalFailureToOptionalError(failure.cause));
|
|
62
|
+
}
|
|
63
|
+
if (failure.timeoutFailureInfo) {
|
|
64
|
+
return new failure_1.TimeoutFailure(failure.message ?? undefined, (0, payload_converter_1.fromPayloadsAtIndex)(this.options.payloadConverter, 0, failure.timeoutFailureInfo.lastHeartbeatDetails?.payloads), failure.timeoutFailureInfo.timeoutType ?? failure_1.TimeoutType.TIMEOUT_TYPE_UNSPECIFIED);
|
|
65
|
+
}
|
|
66
|
+
if (failure.terminatedFailureInfo) {
|
|
67
|
+
return new failure_1.TerminatedFailure(failure.message ?? undefined, this.optionalFailureToOptionalError(failure.cause));
|
|
68
|
+
}
|
|
69
|
+
if (failure.canceledFailureInfo) {
|
|
70
|
+
return new failure_1.CancelledFailure(failure.message ?? undefined, (0, payload_converter_1.arrayFromPayloads)(this.options.payloadConverter, failure.canceledFailureInfo.details?.payloads), this.optionalFailureToOptionalError(failure.cause));
|
|
71
|
+
}
|
|
72
|
+
if (failure.resetWorkflowFailureInfo) {
|
|
73
|
+
return new failure_1.ApplicationFailure(failure.message ?? undefined, 'ResetWorkflow', false, (0, payload_converter_1.arrayFromPayloads)(this.options.payloadConverter, failure.resetWorkflowFailureInfo.lastHeartbeatDetails?.payloads), this.optionalFailureToOptionalError(failure.cause));
|
|
74
|
+
}
|
|
75
|
+
if (failure.childWorkflowExecutionFailureInfo) {
|
|
76
|
+
const { namespace, workflowType, workflowExecution, retryState } = failure.childWorkflowExecutionFailureInfo;
|
|
77
|
+
if (!(workflowType?.name && workflowExecution)) {
|
|
78
|
+
throw new TypeError('Missing attributes on childWorkflowExecutionFailureInfo');
|
|
79
|
+
}
|
|
80
|
+
return new failure_1.ChildWorkflowFailure(namespace ?? undefined, workflowExecution, workflowType.name, retryState ?? failure_1.RetryState.RETRY_STATE_UNSPECIFIED, this.optionalFailureToOptionalError(failure.cause));
|
|
81
|
+
}
|
|
82
|
+
if (failure.activityFailureInfo) {
|
|
83
|
+
if (!failure.activityFailureInfo.activityType?.name) {
|
|
84
|
+
throw new TypeError('Missing activityType?.name on activityFailureInfo');
|
|
85
|
+
}
|
|
86
|
+
return new failure_1.ActivityFailure(failure.activityFailureInfo.activityType.name, failure.activityFailureInfo.activityId ?? undefined, failure.activityFailureInfo.retryState ?? failure_1.RetryState.RETRY_STATE_UNSPECIFIED, failure.activityFailureInfo.identity ?? undefined, this.optionalFailureToOptionalError(failure.cause));
|
|
87
|
+
}
|
|
88
|
+
return new failure_1.TemporalFailure(failure.message ?? undefined, this.optionalFailureToOptionalError(failure.cause));
|
|
89
|
+
}
|
|
90
|
+
failureToError(failure) {
|
|
91
|
+
if (failure.encodedAttributes) {
|
|
92
|
+
const attrs = this.options.payloadConverter.fromPayload(failure.encodedAttributes);
|
|
93
|
+
// Don't apply encodedAttributes unless they conform to an expected schema
|
|
94
|
+
if (typeof attrs === 'object' && attrs !== null) {
|
|
95
|
+
const { message, stack_trace } = attrs;
|
|
96
|
+
// Avoid mutating the argument
|
|
97
|
+
failure = { ...failure };
|
|
98
|
+
if (typeof message === 'string') {
|
|
99
|
+
failure.message = message;
|
|
100
|
+
}
|
|
101
|
+
if (typeof stack_trace === 'string') {
|
|
102
|
+
failure.stackTrace = stack_trace;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
const err = this.failureToErrorInner(failure);
|
|
107
|
+
err.stack = failure.stackTrace ?? '';
|
|
108
|
+
err.failure = failure;
|
|
109
|
+
return err;
|
|
110
|
+
}
|
|
111
|
+
errorToFailure(err) {
|
|
112
|
+
const failure = this.errorToFailureInner(err);
|
|
113
|
+
if (this.options.encodeCommonAttributes) {
|
|
114
|
+
const { message, stackTrace } = failure;
|
|
115
|
+
failure.message = 'Encoded failure';
|
|
116
|
+
failure.stackTrace = '';
|
|
117
|
+
failure.encodedAttributes = this.options.payloadConverter.toPayload({ message, stack_trace: stackTrace });
|
|
118
|
+
}
|
|
119
|
+
return failure;
|
|
120
|
+
}
|
|
121
|
+
errorToFailureInner(err) {
|
|
122
|
+
if (err instanceof failure_1.TemporalFailure) {
|
|
123
|
+
if (err.failure)
|
|
124
|
+
return err.failure;
|
|
125
|
+
const base = {
|
|
126
|
+
message: err.message,
|
|
127
|
+
stackTrace: cutoffStackTrace(err.stack),
|
|
128
|
+
cause: this.optionalErrorToOptionalFailure(err.cause),
|
|
129
|
+
source: failure_1.FAILURE_SOURCE,
|
|
130
|
+
};
|
|
131
|
+
if (err instanceof failure_1.ActivityFailure) {
|
|
132
|
+
return {
|
|
133
|
+
...base,
|
|
134
|
+
activityFailureInfo: {
|
|
135
|
+
...err,
|
|
136
|
+
activityType: { name: err.activityType },
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
if (err instanceof failure_1.ChildWorkflowFailure) {
|
|
141
|
+
return {
|
|
142
|
+
...base,
|
|
143
|
+
childWorkflowExecutionFailureInfo: {
|
|
144
|
+
...err,
|
|
145
|
+
workflowExecution: err.execution,
|
|
146
|
+
workflowType: { name: err.workflowType },
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
if (err instanceof failure_1.ApplicationFailure) {
|
|
151
|
+
return {
|
|
152
|
+
...base,
|
|
153
|
+
applicationFailureInfo: {
|
|
154
|
+
type: err.type,
|
|
155
|
+
nonRetryable: err.nonRetryable,
|
|
156
|
+
details: err.details && err.details.length
|
|
157
|
+
? { payloads: (0, payload_converter_1.toPayloads)(this.options.payloadConverter, ...err.details) }
|
|
158
|
+
: undefined,
|
|
159
|
+
},
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
if (err instanceof failure_1.CancelledFailure) {
|
|
163
|
+
return {
|
|
164
|
+
...base,
|
|
165
|
+
canceledFailureInfo: {
|
|
166
|
+
details: err.details && err.details.length
|
|
167
|
+
? { payloads: (0, payload_converter_1.toPayloads)(this.options.payloadConverter, ...err.details) }
|
|
168
|
+
: undefined,
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
if (err instanceof failure_1.TimeoutFailure) {
|
|
173
|
+
return {
|
|
174
|
+
...base,
|
|
175
|
+
timeoutFailureInfo: {
|
|
176
|
+
timeoutType: err.timeoutType,
|
|
177
|
+
lastHeartbeatDetails: err.lastHeartbeatDetails
|
|
178
|
+
? { payloads: (0, payload_converter_1.toPayloads)(this.options.payloadConverter, err.lastHeartbeatDetails) }
|
|
179
|
+
: undefined,
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
if (err instanceof failure_1.TerminatedFailure) {
|
|
184
|
+
return {
|
|
185
|
+
...base,
|
|
186
|
+
terminatedFailureInfo: {},
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
if (err instanceof failure_1.ServerFailure) {
|
|
190
|
+
return {
|
|
191
|
+
...base,
|
|
192
|
+
serverFailureInfo: { nonRetryable: err.nonRetryable },
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
// Just a TemporalFailure
|
|
196
|
+
return base;
|
|
197
|
+
}
|
|
198
|
+
const base = {
|
|
199
|
+
source: failure_1.FAILURE_SOURCE,
|
|
200
|
+
};
|
|
201
|
+
if ((0, type_helpers_1.isRecord)(err) && (0, type_helpers_1.hasOwnProperties)(err, ['message', 'stack'])) {
|
|
202
|
+
return {
|
|
203
|
+
...base,
|
|
204
|
+
message: String(err.message) ?? '',
|
|
205
|
+
stackTrace: cutoffStackTrace(String(err.stack)),
|
|
206
|
+
cause: this.optionalErrorToOptionalFailure(err.cause),
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
const recommendation = ` [A non-Error value was thrown from your code. We recommend throwing Error objects so that we can provide a stack trace]`;
|
|
210
|
+
if (typeof err === 'string') {
|
|
211
|
+
return { ...base, message: err + recommendation };
|
|
212
|
+
}
|
|
213
|
+
if (typeof err === 'object') {
|
|
214
|
+
let message = '';
|
|
215
|
+
try {
|
|
216
|
+
message = JSON.stringify(err);
|
|
217
|
+
}
|
|
218
|
+
catch (_err) {
|
|
219
|
+
message = String(err);
|
|
220
|
+
}
|
|
221
|
+
return { ...base, message: message + recommendation };
|
|
222
|
+
}
|
|
223
|
+
return { ...base, message: String(err) + recommendation };
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Converts a Failure proto message to a JS Error object if defined or returns undefined.
|
|
227
|
+
*/
|
|
228
|
+
optionalFailureToOptionalError(failure) {
|
|
229
|
+
return failure ? this.failureToError(failure) : undefined;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Converts an error to a Failure proto message if defined or returns undefined
|
|
233
|
+
*/
|
|
234
|
+
optionalErrorToOptionalFailure(err) {
|
|
235
|
+
return err ? this.errorToFailure(err) : undefined;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
exports.DefaultFailureConverter = DefaultFailureConverter;
|
|
239
|
+
//# sourceMappingURL=failure-converter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"failure-converter.js","sourceRoot":"","sources":["../../src/converter/failure-converter.ts"],"names":[],"mappings":";;;AAAA,wCAaoB;AACpB,kDAA6D;AAC7D,2DAM6B;AAE7B;;GAEG;AACH,MAAM,qBAAqB,GAAG;IAC5B,yBAAyB;IACzB,uFAAuF;IACvF,0BAA0B;IAC1B,kGAAkG;IAClG,uCAAuC;IACvC,2DAA2D;CAC5D,CAAC;AAEF;;GAEG;AACH,SAAgB,gBAAgB,CAAC,KAAc;IAC7C,MAAM,KAAK,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC3C,MAAM,GAAG,GAAG,KAAK,EAAU,CAAC;IAC5B,QAAQ,EAAE,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;QAClC,KAAK,MAAM,OAAO,IAAI,qBAAqB,EAAE;YAC3C,IAAI,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;gBAAE,MAAM,QAAQ,CAAC;SACxC;QACD,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;KAChB;IACD,OAAO,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACxB,CAAC;AAVD,4CAUC;AA4CD;;;;;;;;GAQG;AACH,MAAa,uBAAuB;IAGlC,YAAY,OAAiD;QAC3D,MAAM,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;QACnE,IAAI,CAAC,OAAO,GAAG;YACb,sBAAsB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,MAAM,CAAC,GAAG,CAAC,GAAG,cAAc,EAAE,CAAC;IAC5D,CAAC;IAED;;OAEG;IACH,8BAA8B,CAAC,OAAwC;QACrE,OAAO,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC5D,CAAC;IAED;;OAEG;IACH,8BAA8B,CAAC,GAAY;QACzC,OAAO,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACpD,CAAC;CACF;AA7PD,0DA6PC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Payload } from '
|
|
1
|
+
import { Payload } from '../interfaces';
|
|
2
2
|
/**
|
|
3
3
|
* Used by the framework to serialize/deserialize data like parameters and return values.
|
|
4
4
|
*
|
|
@@ -54,3 +54,87 @@ export declare function fromPayloadsAtIndex<T>(converter: PayloadConverter, inde
|
|
|
54
54
|
*/
|
|
55
55
|
export declare function arrayFromPayloads(converter: PayloadConverter, payloads?: Payload[] | null): unknown[];
|
|
56
56
|
export declare function mapFromPayloads<K extends string>(converter: PayloadConverter, map?: Record<K, Payload> | null | undefined): Record<K, unknown> | undefined | null;
|
|
57
|
+
export interface PayloadConverterWithEncoding {
|
|
58
|
+
/**
|
|
59
|
+
* Converts a value to a {@link Payload}.
|
|
60
|
+
*
|
|
61
|
+
* @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.
|
|
62
|
+
* @returns The {@link Payload}, or `undefined` if unable to convert.
|
|
63
|
+
*/
|
|
64
|
+
toPayload<T>(value: T): Payload | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* Converts a {@link Payload} back to a value.
|
|
67
|
+
*/
|
|
68
|
+
fromPayload<T>(payload: Payload): T;
|
|
69
|
+
readonly encodingType: string;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Tries to convert values to {@link Payload}s using the {@link PayloadConverterWithEncoding}s provided to the constructor, in the order provided.
|
|
73
|
+
*
|
|
74
|
+
* Converts Payloads to values based on the `Payload.metadata.encoding` field, which matches the {@link PayloadConverterWithEncoding.encodingType}
|
|
75
|
+
* of the converter that created the Payload.
|
|
76
|
+
*/
|
|
77
|
+
export declare class CompositePayloadConverter implements PayloadConverter {
|
|
78
|
+
readonly converters: PayloadConverterWithEncoding[];
|
|
79
|
+
readonly converterByEncoding: Map<string, PayloadConverterWithEncoding>;
|
|
80
|
+
constructor(...converters: PayloadConverterWithEncoding[]);
|
|
81
|
+
/**
|
|
82
|
+
* Tries to run `.toPayload(value)` on each converter in the order provided at construction.
|
|
83
|
+
* Returns the first successful result, throws {@link ValueError} if there is no converter that can handle the value.
|
|
84
|
+
*/
|
|
85
|
+
toPayload<T>(value: T): Payload;
|
|
86
|
+
/**
|
|
87
|
+
* Run {@link PayloadConverterWithEncoding.fromPayload} based on the `encoding` metadata of the {@link Payload}.
|
|
88
|
+
*/
|
|
89
|
+
fromPayload<T>(payload: Payload): T;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Converts between JS undefined and NULL Payload
|
|
93
|
+
*/
|
|
94
|
+
export declare class UndefinedPayloadConverter implements PayloadConverterWithEncoding {
|
|
95
|
+
encodingType: "binary/null";
|
|
96
|
+
toPayload(value: unknown): Payload | undefined;
|
|
97
|
+
fromPayload<T>(_content: Payload): T;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Converts between binary data types and RAW Payload
|
|
101
|
+
*/
|
|
102
|
+
export declare class BinaryPayloadConverter implements PayloadConverterWithEncoding {
|
|
103
|
+
encodingType: "binary/plain";
|
|
104
|
+
toPayload(value: unknown): Payload | undefined;
|
|
105
|
+
fromPayload<T>(content: Payload): T;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Converts between non-undefined values and serialized JSON Payload
|
|
109
|
+
*/
|
|
110
|
+
export declare class JsonPayloadConverter implements PayloadConverterWithEncoding {
|
|
111
|
+
encodingType: "json/plain";
|
|
112
|
+
toPayload(value: unknown): Payload | undefined;
|
|
113
|
+
fromPayload<T>(content: Payload): T;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Converts Search Attribute values using JsonPayloadConverter
|
|
117
|
+
*/
|
|
118
|
+
export declare class SearchAttributePayloadConverter implements PayloadConverter {
|
|
119
|
+
jsonConverter: JsonPayloadConverter;
|
|
120
|
+
validNonDateTypes: string[];
|
|
121
|
+
toPayload(values: unknown): Payload;
|
|
122
|
+
/**
|
|
123
|
+
* Datetime Search Attribute values are converted to `Date`s
|
|
124
|
+
*/
|
|
125
|
+
fromPayload<T>(payload: Payload): T;
|
|
126
|
+
}
|
|
127
|
+
export declare const searchAttributePayloadConverter: SearchAttributePayloadConverter;
|
|
128
|
+
export declare class DefaultPayloadConverter extends CompositePayloadConverter {
|
|
129
|
+
constructor();
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* The default {@link PayloadConverter} used by the SDK. Supports `Uint8Array` and JSON serializables (so if
|
|
133
|
+
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#description | `JSON.stringify(yourArgOrRetval)`}
|
|
134
|
+
* works, the default payload converter will work).
|
|
135
|
+
*
|
|
136
|
+
* To also support Protobufs, create a custom payload converter with {@link DefaultPayloadConverter}:
|
|
137
|
+
*
|
|
138
|
+
* `const myConverter = new DefaultPayloadConverter({ protobufRoot })`
|
|
139
|
+
*/
|
|
140
|
+
export declare const defaultPayloadConverter: DefaultPayloadConverter;
|