@temporalio/common 0.17.1 → 0.19.0-rc.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 +2 -9
- package/lib/converter/data-converter.js +2 -14
- package/lib/converter/data-converter.js.map +1 -1
- package/lib/converter/payload-converter.d.ts +2 -34
- package/lib/converter/payload-converter.js +1 -137
- package/lib/converter/payload-converter.js.map +1 -1
- package/lib/converter/types.d.ts +0 -1
- package/lib/converter/types.js +1 -2
- package/lib/converter/types.js.map +1 -1
- package/lib/errors.d.ts +29 -4
- package/lib/errors.js +36 -13
- package/lib/errors.js.map +1 -1
- package/lib/failure.js +12 -6
- package/lib/failure.js.map +1 -1
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -1
- package/lib/index.js.map +1 -1
- package/lib/time.d.ts +1 -0
- package/lib/time.js +5 -1
- package/lib/time.js.map +1 -1
- package/lib/type-helpers.d.ts +2 -1
- package/lib/type-helpers.js +1 -5
- package/lib/type-helpers.js.map +1 -1
- package/lib/workflow-options.d.ts +6 -5
- package/lib/workflow-options.js +3 -3
- package/lib/workflow-options.js.map +1 -1
- package/package.json +4 -8
- package/src/converter/data-converter.ts +6 -29
- package/src/converter/payload-converter.ts +4 -155
- package/src/converter/types.ts +0 -2
- package/src/errors.ts +33 -18
- package/src/failure.ts +14 -7
- package/src/index.ts +0 -1
- package/src/time.ts +4 -0
- package/src/type-helpers.ts +4 -7
- package/src/workflow-options.ts +15 -14
- package/tsconfig.tsbuildinfo +1 -1
- package/lib/converter/helpers.d.ts +0 -1
- package/lib/converter/helpers.js +0 -33
- package/lib/converter/helpers.js.map +0 -1
- package/src/converter/helpers.ts +0 -38
package/lib/type-helpers.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.hasOwnProperties = exports.
|
|
3
|
+
exports.hasOwnProperties = exports.isRecord = exports.checkExtends = void 0;
|
|
4
4
|
/** Verify that an type _Copy extends _Orig */
|
|
5
5
|
function checkExtends() {
|
|
6
6
|
// noop, just type check
|
|
@@ -10,10 +10,6 @@ function isRecord(value) {
|
|
|
10
10
|
return typeof value === 'object' && value !== null;
|
|
11
11
|
}
|
|
12
12
|
exports.isRecord = isRecord;
|
|
13
|
-
function hasOwnProperty(record, prop) {
|
|
14
|
-
return prop in record;
|
|
15
|
-
}
|
|
16
|
-
exports.hasOwnProperty = hasOwnProperty;
|
|
17
13
|
function hasOwnProperties(record, props) {
|
|
18
14
|
return props.every((prop) => prop in record);
|
|
19
15
|
}
|
package/lib/type-helpers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-helpers.js","sourceRoot":"","sources":["../src/type-helpers.ts"],"names":[],"mappings":";;;AAOA,8CAA8C;AAC9C,SAAgB,YAAY;IAC1B,wBAAwB;AAC1B,CAAC;AAFD,oCAEC;
|
|
1
|
+
{"version":3,"file":"type-helpers.js","sourceRoot":"","sources":["../src/type-helpers.ts"],"names":[],"mappings":";;;AAOA,8CAA8C;AAC9C,SAAgB,YAAY;IAC1B,wBAAwB;AAC1B,CAAC;AAFD,oCAEC;AAMD,SAAgB,QAAQ,CAAC,KAAc;IACrC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC;AACrD,CAAC;AAFD,4BAEC;AAED,SAAgB,gBAAgB,CAC9B,MAAS,EACT,KAAU;IAEV,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,IAAI,MAAM,CAAC,CAAC;AAC/C,CAAC;AALD,4CAKC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { google } from '@temporalio/proto/lib/coresdk';
|
|
2
2
|
import { Workflow } from './interfaces';
|
|
3
|
+
import { Replace } from './type-helpers';
|
|
3
4
|
import { RetryPolicy } from './retry-policy';
|
|
4
5
|
export declare enum WorkflowIdReusePolicy {
|
|
5
6
|
WORKFLOW_ID_REUSE_POLICY_UNSPECIFIED = 0,
|
|
@@ -19,10 +20,10 @@ export interface BaseWorkflowOptions {
|
|
|
19
20
|
*/
|
|
20
21
|
workflowIdReusePolicy?: WorkflowIdReusePolicy;
|
|
21
22
|
/**
|
|
22
|
-
* Controls how a Workflow is retried.
|
|
23
|
+
* Controls how a Workflow Execution is retried.
|
|
23
24
|
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
25
|
+
* By default, Workflow Executions are not retried. Do not override this behavior unless you know what you're doing.
|
|
26
|
+
* [More information](https://docs.temporal.io/docs/concepts/what-is-a-retry-policy/).
|
|
26
27
|
*/
|
|
27
28
|
retry?: RetryPolicy;
|
|
28
29
|
/**
|
|
@@ -83,9 +84,9 @@ export interface WorkflowDurationOptions {
|
|
|
83
84
|
workflowTaskTimeout?: string | number;
|
|
84
85
|
}
|
|
85
86
|
export declare type CommonWorkflowOptions = BaseWorkflowOptions & WorkflowDurationOptions;
|
|
86
|
-
export declare type WithCompiledWorkflowDurationOptions<T extends WorkflowDurationOptions> =
|
|
87
|
+
export declare type WithCompiledWorkflowDurationOptions<T extends WorkflowDurationOptions> = Replace<T, {
|
|
87
88
|
workflowExecutionTimeout?: google.protobuf.IDuration;
|
|
88
89
|
workflowRunTimeout?: google.protobuf.IDuration;
|
|
89
90
|
workflowTaskTimeout?: google.protobuf.IDuration;
|
|
90
|
-
}
|
|
91
|
+
}>;
|
|
91
92
|
export declare function compileWorkflowOptions<T extends WorkflowDurationOptions>(options: T): WithCompiledWorkflowDurationOptions<T>;
|
package/lib/workflow-options.js
CHANGED
|
@@ -17,9 +17,9 @@ function compileWorkflowOptions(options) {
|
|
|
17
17
|
const { workflowExecutionTimeout, workflowRunTimeout, workflowTaskTimeout, ...rest } = options;
|
|
18
18
|
return {
|
|
19
19
|
...rest,
|
|
20
|
-
workflowExecutionTimeout:
|
|
21
|
-
workflowRunTimeout:
|
|
22
|
-
workflowTaskTimeout:
|
|
20
|
+
workflowExecutionTimeout: (0, time_1.falsyMsToTs)(workflowExecutionTimeout),
|
|
21
|
+
workflowRunTimeout: (0, time_1.falsyMsToTs)(workflowRunTimeout),
|
|
22
|
+
workflowTaskTimeout: (0, time_1.falsyMsToTs)(workflowTaskTimeout),
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
25
|
exports.compileWorkflowOptions = compileWorkflowOptions;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow-options.js","sourceRoot":"","sources":["../src/workflow-options.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"workflow-options.js","sourceRoot":"","sources":["../src/workflow-options.ts"],"names":[],"mappings":";;;AAEA,iCAAqC;AAGrC,iDAA8C;AAE9C,0EAA0E;AAC1E,mDAAmD;AACnD,IAAY,qBAKX;AALD,WAAY,qBAAqB;IAC/B,iIAAwC,CAAA;IACxC,yIAA4C,CAAA;IAC5C,iKAAwD,CAAA;IACxD,2IAA6C,CAAA;AAC/C,CAAC,EALW,qBAAqB,GAArB,6BAAqB,KAArB,6BAAqB,QAKhC;AAED,IAAA,2BAAY,GAA+D,CAAC;AAoG5E,SAAgB,sBAAsB,CACpC,OAAU;IAEV,MAAM,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,GAAG,IAAI,EAAE,GAAG,OAAO,CAAC;IAE/F,OAAO;QACL,GAAG,IAAI;QACP,wBAAwB,EAAE,IAAA,kBAAW,EAAC,wBAAwB,CAAC;QAC/D,kBAAkB,EAAE,IAAA,kBAAW,EAAC,kBAAkB,CAAC;QACnD,mBAAmB,EAAE,IAAA,kBAAW,EAAC,mBAAmB,CAAC;KACtD,CAAC;AACJ,CAAC;AAXD,wDAWC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@temporalio/common",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0-rc.0",
|
|
4
4
|
"description": "Temporal.io SDK common library for use in Workflow and normal code",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -13,9 +13,8 @@
|
|
|
13
13
|
"author": "Roey Berman <roey@temporal.io>",
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@temporalio/proto": "^0.
|
|
17
|
-
"ms": "^2.1.3"
|
|
18
|
-
"proto3-json-serializer": "^0.1.6"
|
|
16
|
+
"@temporalio/proto": "^0.18.0",
|
|
17
|
+
"ms": "^2.1.3"
|
|
19
18
|
},
|
|
20
19
|
"bugs": {
|
|
21
20
|
"url": "https://github.com/temporalio/sdk-typescript/issues"
|
|
@@ -24,8 +23,5 @@
|
|
|
24
23
|
"publishConfig": {
|
|
25
24
|
"access": "public"
|
|
26
25
|
},
|
|
27
|
-
"
|
|
28
|
-
"protobufjs": "^6.11.2"
|
|
29
|
-
},
|
|
30
|
-
"gitHead": "3ee26c92e9c18500f919654a402237a86e69652e"
|
|
26
|
+
"gitHead": "f55f02d343ac6db5d556fc1c7316013a8974c559"
|
|
31
27
|
}
|
|
@@ -5,15 +5,13 @@ import {
|
|
|
5
5
|
UndefinedPayloadConverter,
|
|
6
6
|
BinaryPayloadConverter,
|
|
7
7
|
JsonPayloadConverter,
|
|
8
|
-
ProtobufJsonPayloadConverter,
|
|
9
|
-
ProtobufBinaryPayloadConverter,
|
|
10
8
|
} from './payload-converter';
|
|
11
9
|
|
|
12
10
|
/**
|
|
13
11
|
* Used by the framework to serialize/deserialize method parameters that need to be sent over the
|
|
14
12
|
* wire.
|
|
15
13
|
*
|
|
16
|
-
* Implement this in order to customize worker data serialization or use the default data converter which supports `Uint8Array
|
|
14
|
+
* Implement this in order to customize worker data serialization or use the default data converter which supports `Uint8Array` and JSON serializables.
|
|
17
15
|
*/
|
|
18
16
|
export interface DataConverter {
|
|
19
17
|
toPayload<T>(value: T): Promise<Payload>;
|
|
@@ -68,13 +66,6 @@ export interface DataConverter {
|
|
|
68
66
|
fromPayloadsSync<T>(index: number, content?: Payload[] | null): T;
|
|
69
67
|
}
|
|
70
68
|
|
|
71
|
-
export const isValidDataConverter = (dataConverter: unknown): dataConverter is DataConverter =>
|
|
72
|
-
typeof dataConverter === 'object' &&
|
|
73
|
-
dataConverter !== null &&
|
|
74
|
-
['toPayload', 'toPayloads', 'fromPayload', 'fromPayloads'].every(
|
|
75
|
-
(method) => typeof (dataConverter as Record<string, unknown>)[method] === 'function'
|
|
76
|
-
);
|
|
77
|
-
|
|
78
69
|
export class CompositeDataConverter implements DataConverter {
|
|
79
70
|
readonly converters: PayloadConverter[];
|
|
80
71
|
readonly converterByEncoding: Map<string, PayloadConverter> = new Map();
|
|
@@ -191,22 +182,8 @@ export function mapToPayloadsSync<K extends string>(
|
|
|
191
182
|
) as Record<K, Payload>;
|
|
192
183
|
}
|
|
193
184
|
|
|
194
|
-
export
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
constructor({ root }: DefaultDataConverterOptions = {}) {
|
|
200
|
-
// Match the order used in other SDKs
|
|
201
|
-
// Go SDK: https://github.com/temporalio/sdk-go/blob/5e5645f0c550dcf717c095ae32c76a7087d2e985/converter/default_data_converter.go#L28
|
|
202
|
-
super(
|
|
203
|
-
new UndefinedPayloadConverter(),
|
|
204
|
-
new BinaryPayloadConverter(),
|
|
205
|
-
new ProtobufJsonPayloadConverter(root),
|
|
206
|
-
new ProtobufBinaryPayloadConverter(root),
|
|
207
|
-
new JsonPayloadConverter()
|
|
208
|
-
);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
export const defaultDataConverter = new DefaultDataConverter();
|
|
185
|
+
export const defaultDataConverter = new CompositeDataConverter(
|
|
186
|
+
new UndefinedPayloadConverter(),
|
|
187
|
+
new BinaryPayloadConverter(),
|
|
188
|
+
new JsonPayloadConverter()
|
|
189
|
+
);
|
|
@@ -1,17 +1,5 @@
|
|
|
1
|
-
import { ValueError
|
|
2
|
-
import {
|
|
3
|
-
u8,
|
|
4
|
-
str,
|
|
5
|
-
Payload,
|
|
6
|
-
encodingTypes,
|
|
7
|
-
encodingKeys,
|
|
8
|
-
METADATA_ENCODING_KEY,
|
|
9
|
-
METADATA_MESSAGE_TYPE_KEY,
|
|
10
|
-
} from './types';
|
|
11
|
-
import { isRecord, hasOwnProperty, hasOwnProperties } from '../type-helpers';
|
|
12
|
-
import { errorMessage } from '../errors';
|
|
13
|
-
import * as protoJsonSerializer from 'proto3-json-serializer';
|
|
14
|
-
import type { Root, Type, Namespace, Message } from 'protobufjs';
|
|
1
|
+
import { ValueError } from '../errors';
|
|
2
|
+
import { u8, str, Payload, encodingTypes, encodingKeys, METADATA_ENCODING_KEY } from './types';
|
|
15
3
|
|
|
16
4
|
/**
|
|
17
5
|
* Used by the framework to serialize/deserialize method parameters that need to be sent over the
|
|
@@ -27,7 +15,7 @@ export interface PayloadConverter {
|
|
|
27
15
|
* Implements conversion of value to payload
|
|
28
16
|
*
|
|
29
17
|
* @param value JS value to convert.
|
|
30
|
-
* @return converted value
|
|
18
|
+
* @return converted value
|
|
31
19
|
* @throws DataConverterException if conversion of the value passed as parameter failed for any
|
|
32
20
|
* reason.
|
|
33
21
|
*/
|
|
@@ -50,7 +38,7 @@ export interface PayloadConverter {
|
|
|
50
38
|
* Implements conversion of value to payload
|
|
51
39
|
*
|
|
52
40
|
* @param value JS value to convert.
|
|
53
|
-
* @return converted value
|
|
41
|
+
* @return converted value
|
|
54
42
|
* @throws DataConverterException if conversion of the value passed as parameter failed for any
|
|
55
43
|
* reason.
|
|
56
44
|
*/
|
|
@@ -152,142 +140,3 @@ export class BinaryPayloadConverter extends AsyncFacadePayloadConverter {
|
|
|
152
140
|
return content.data as any;
|
|
153
141
|
}
|
|
154
142
|
}
|
|
155
|
-
|
|
156
|
-
abstract class ProtobufPayloadConverter extends AsyncFacadePayloadConverter {
|
|
157
|
-
protected readonly root: Root | undefined;
|
|
158
|
-
|
|
159
|
-
// Don't use type Root here because root.d.ts doesn't export Root, so users would have to type assert
|
|
160
|
-
constructor(root?: unknown) {
|
|
161
|
-
super();
|
|
162
|
-
|
|
163
|
-
if (root) {
|
|
164
|
-
if (!isRoot(root)) {
|
|
165
|
-
throw new TypeError('root must be an instance of a protobufjs Root');
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
this.root = root;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
protected validatePayload(content: Payload): { messageType: Type; data: Uint8Array } {
|
|
173
|
-
if (content.data === undefined || content.data === null) {
|
|
174
|
-
throw new ValueError('Got payload with no data');
|
|
175
|
-
}
|
|
176
|
-
if (!content.metadata || !(METADATA_MESSAGE_TYPE_KEY in content.metadata)) {
|
|
177
|
-
throw new ValueError(`Got protobuf payload without metadata.${METADATA_MESSAGE_TYPE_KEY}`);
|
|
178
|
-
}
|
|
179
|
-
if (!this.root) {
|
|
180
|
-
throw new DataConverterError('Unable to deserialize protobuf message without `root` being provided');
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
const messageTypeName = str(content.metadata[METADATA_MESSAGE_TYPE_KEY]);
|
|
184
|
-
let messageType;
|
|
185
|
-
try {
|
|
186
|
-
messageType = this.root.lookupType(messageTypeName);
|
|
187
|
-
} catch (e) {
|
|
188
|
-
if (errorMessage(e)?.includes('no such type')) {
|
|
189
|
-
throw new DataConverterError(
|
|
190
|
-
`Got a \`${messageTypeName}\` protobuf message but cannot find corresponding message class in \`root\``
|
|
191
|
-
);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
throw e;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
return { messageType, data: content.data };
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
protected constructPayload({ messageTypeName, message }: { messageTypeName: string; message: Uint8Array }): Payload {
|
|
201
|
-
return {
|
|
202
|
-
metadata: {
|
|
203
|
-
[METADATA_ENCODING_KEY]: u8(this.encodingType),
|
|
204
|
-
[METADATA_MESSAGE_TYPE_KEY]: u8(messageTypeName),
|
|
205
|
-
},
|
|
206
|
-
data: message,
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* Converts between protobufjs Message instances and serialized Protobuf Payload
|
|
213
|
-
*/
|
|
214
|
-
export class ProtobufBinaryPayloadConverter extends ProtobufPayloadConverter {
|
|
215
|
-
public encodingType = encodingTypes.METADATA_ENCODING_PROTOBUF;
|
|
216
|
-
|
|
217
|
-
constructor(root?: unknown) {
|
|
218
|
-
super(root);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
public toDataSync(value: unknown): Payload | undefined {
|
|
222
|
-
if (!isProtobufMessage(value)) {
|
|
223
|
-
return undefined;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
return this.constructPayload({
|
|
227
|
-
messageTypeName: getNamespacedTypeName(value.$type),
|
|
228
|
-
message: value.$type.encode(value).finish(),
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
public fromDataSync<T>(content: Payload): T {
|
|
233
|
-
const { messageType, data } = this.validatePayload(content);
|
|
234
|
-
return messageType.decode(data) as unknown as T;
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* Converts between protobufjs Message instances and serialized JSON Payload
|
|
240
|
-
*/
|
|
241
|
-
export class ProtobufJsonPayloadConverter extends ProtobufPayloadConverter {
|
|
242
|
-
public encodingType = encodingTypes.METADATA_ENCODING_PROTOBUF_JSON;
|
|
243
|
-
|
|
244
|
-
constructor(root?: unknown) {
|
|
245
|
-
super(root);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
public toDataSync(value: unknown): Payload | undefined {
|
|
249
|
-
if (!isProtobufMessage(value)) {
|
|
250
|
-
return undefined;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
const jsonValue = protoJsonSerializer.toProto3JSON(value);
|
|
254
|
-
|
|
255
|
-
return this.constructPayload({
|
|
256
|
-
messageTypeName: getNamespacedTypeName(value.$type),
|
|
257
|
-
message: u8(JSON.stringify(jsonValue)),
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
public fromDataSync<T>(content: Payload): T {
|
|
262
|
-
const { messageType, data } = this.validatePayload(content);
|
|
263
|
-
return protoJsonSerializer.fromProto3JSON(messageType, JSON.parse(str(data))) as unknown as T;
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
function isProtobufType(type: unknown): type is Type {
|
|
268
|
-
return (
|
|
269
|
-
isRecord(type) &&
|
|
270
|
-
type.constructor.name === 'Type' &&
|
|
271
|
-
hasOwnProperties(type, ['parent', 'name', 'create', 'encode', 'decode']) &&
|
|
272
|
-
typeof type.name === 'string' &&
|
|
273
|
-
typeof type.create === 'function' &&
|
|
274
|
-
typeof type.encode === 'function' &&
|
|
275
|
-
typeof type.decode === 'function'
|
|
276
|
-
);
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
function isProtobufMessage(value: unknown): value is Message {
|
|
280
|
-
return isRecord(value) && hasOwnProperty(value, '$type') && isProtobufType(value.$type);
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
function getNamespacedTypeName(node: Type | Namespace): string {
|
|
284
|
-
if (node.parent && !isRoot(node.parent)) {
|
|
285
|
-
return getNamespacedTypeName(node.parent) + '.' + node.name;
|
|
286
|
-
} else {
|
|
287
|
-
return node.name;
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
function isRoot(root: unknown): root is Root {
|
|
292
|
-
return isRecord(root) && root.constructor.name === 'Root';
|
|
293
|
-
}
|
package/src/converter/types.ts
CHANGED
|
@@ -30,5 +30,3 @@ export const encodingKeys = {
|
|
|
30
30
|
METADATA_ENCODING_PROTOBUF_JSON: u8(encodingTypes.METADATA_ENCODING_PROTOBUF_JSON),
|
|
31
31
|
METADATA_ENCODING_PROTOBUF: u8(encodingTypes.METADATA_ENCODING_PROTOBUF),
|
|
32
32
|
} as const;
|
|
33
|
-
|
|
34
|
-
export const METADATA_MESSAGE_TYPE_KEY = 'messageType';
|
package/src/errors.ts
CHANGED
|
@@ -13,6 +13,39 @@ export class IllegalStateError extends Error {
|
|
|
13
13
|
public readonly name: string = 'IllegalStateError';
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* This exception is thrown in the following cases:
|
|
18
|
+
* - Workflow with the same WorkflowId is currently running
|
|
19
|
+
* - There is a closed workflow with the same ID and the {@link WorkflowOptions.workflowIdReusePolicy}
|
|
20
|
+
* is `WORKFLOW_ID_REUSE_POLICY_REJECT_DUPLICATE`
|
|
21
|
+
* - There is successfully closed workflow with the same ID and the {@link WorkflowOptions.workflowIdReusePolicy}
|
|
22
|
+
* is `WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE_FAILED_ONLY`
|
|
23
|
+
* - {@link Workflow.execute} is called *more than once* on a handle created through {@link createChildWorkflowHandle} and the
|
|
24
|
+
* {@link WorkflowOptions.workflowIdReusePolicy} is `WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE`
|
|
25
|
+
*/
|
|
26
|
+
export class WorkflowExecutionAlreadyStartedError extends Error {
|
|
27
|
+
public readonly name: string = 'WorkflowExecutionAlreadyStartedError';
|
|
28
|
+
|
|
29
|
+
constructor(message: string, public readonly workflowId: string, public readonly workflowType: string) {
|
|
30
|
+
super(message);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Thrown when workflow with the given id is not known to the Temporal service.
|
|
36
|
+
* It could be because:
|
|
37
|
+
* - ID passed is incorrect
|
|
38
|
+
* - Workflow execution is complete (for some calls e.g. terminate),
|
|
39
|
+
* - workflow was purged from the service after reaching its retention limit.
|
|
40
|
+
*/
|
|
41
|
+
export class WorkflowNotFoundError extends Error {
|
|
42
|
+
public readonly name: string = 'WorkflowNotFoundError';
|
|
43
|
+
|
|
44
|
+
constructor(message: string, public readonly workflowId: string, public readonly runId: string | undefined) {
|
|
45
|
+
super(message);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
16
49
|
/**
|
|
17
50
|
* Get error message from an Error or string or return undefined
|
|
18
51
|
*/
|
|
@@ -25,21 +58,3 @@ export function errorMessage(err: unknown): string | undefined {
|
|
|
25
58
|
}
|
|
26
59
|
return undefined;
|
|
27
60
|
}
|
|
28
|
-
|
|
29
|
-
interface ErrorWithCode {
|
|
30
|
-
code: string;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Get error code from an Error or return undefined
|
|
34
|
-
*/
|
|
35
|
-
export function errorCode(error: unknown): string | undefined {
|
|
36
|
-
if (
|
|
37
|
-
typeof error === 'object' &&
|
|
38
|
-
(error as ErrorWithCode).code !== undefined &&
|
|
39
|
-
typeof (error as ErrorWithCode).code === 'string'
|
|
40
|
-
) {
|
|
41
|
-
return (error as ErrorWithCode).code;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return undefined;
|
|
45
|
-
}
|
package/src/failure.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { temporal } from '@temporalio/proto/lib/coresdk';
|
|
2
2
|
import { DataConverter, arrayFromPayloads } from './converter/data-converter';
|
|
3
|
-
import { checkExtends } from './type-helpers';
|
|
3
|
+
import { checkExtends, hasOwnProperties, isRecord } from './type-helpers';
|
|
4
4
|
|
|
5
5
|
export const FAILURE_SOURCE = 'TypeScriptSDK';
|
|
6
6
|
export type ProtoFailure = temporal.api.failure.v1.IFailure;
|
|
@@ -220,7 +220,7 @@ export async function optionalErrorToOptionalFailure(
|
|
|
220
220
|
/**
|
|
221
221
|
* Stack traces will be cutoff when on of these patterns is matched
|
|
222
222
|
*/
|
|
223
|
-
const
|
|
223
|
+
const CUTOFF_STACK_PATTERNS = [
|
|
224
224
|
/** Activity execution */
|
|
225
225
|
/\s+at Activity\.execute \(.*[\\/]worker[\\/](?:src|lib)[\\/]activity\.[jt]s:\d+:\d+\)/,
|
|
226
226
|
/** Workflow activation */
|
|
@@ -234,7 +234,7 @@ export function cutoffStackTrace(stack?: string): string {
|
|
|
234
234
|
const lines = (stack ?? '').split(/\r?\n/);
|
|
235
235
|
const acc = Array<string>();
|
|
236
236
|
lineLoop: for (const line of lines) {
|
|
237
|
-
for (const pattern of
|
|
237
|
+
for (const pattern of CUTOFF_STACK_PATTERNS) {
|
|
238
238
|
if (pattern.test(line)) break lineLoop;
|
|
239
239
|
}
|
|
240
240
|
acc.push(line);
|
|
@@ -329,15 +329,22 @@ export async function errorToFailure(err: unknown, dataConverter: DataConverter)
|
|
|
329
329
|
source: FAILURE_SOURCE,
|
|
330
330
|
};
|
|
331
331
|
|
|
332
|
-
if (err
|
|
333
|
-
return {
|
|
332
|
+
if (isRecord(err) && hasOwnProperties(err, ['message', 'stack'])) {
|
|
333
|
+
return {
|
|
334
|
+
...base,
|
|
335
|
+
message: String(err.message) ?? '',
|
|
336
|
+
stackTrace: cutoffStackTrace(String(err.stack)),
|
|
337
|
+
cause: await optionalErrorToOptionalFailure(err.cause, dataConverter),
|
|
338
|
+
};
|
|
334
339
|
}
|
|
335
340
|
|
|
341
|
+
const recommendation = ` [A non-Error value was thrown from your code. We recommend throwing Error objects so that we can provide a stack trace.]`;
|
|
342
|
+
|
|
336
343
|
if (typeof err === 'string') {
|
|
337
|
-
return { ...base, message: err };
|
|
344
|
+
return { ...base, message: err + recommendation };
|
|
338
345
|
}
|
|
339
346
|
|
|
340
|
-
return { ...base, message:
|
|
347
|
+
return { ...base, message: JSON.stringify(err) + recommendation };
|
|
341
348
|
}
|
|
342
349
|
|
|
343
350
|
/**
|
package/src/index.ts
CHANGED
package/src/time.ts
CHANGED
|
@@ -44,6 +44,10 @@ export function msNumberToTs(millis: number): Timestamp {
|
|
|
44
44
|
return { seconds: Long.fromNumber(seconds), nanos };
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
export function falsyMsToTs(str: string | number | undefined): Timestamp | undefined {
|
|
48
|
+
return str ? msToTs(str) : undefined;
|
|
49
|
+
}
|
|
50
|
+
|
|
47
51
|
export function msToTs(str: string | number): Timestamp {
|
|
48
52
|
if (typeof str === 'number') {
|
|
49
53
|
return msNumberToTs(str);
|
package/src/type-helpers.ts
CHANGED
|
@@ -10,17 +10,14 @@ export function checkExtends<_Orig, _Copy extends _Orig>(): void {
|
|
|
10
10
|
// noop, just type check
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
export type Replace<Base, New> = Omit<Base, keyof New> & New;
|
|
14
|
+
|
|
15
|
+
export type MakeOptional<Base, Keys extends keyof Base> = Omit<Base, Keys> & Partial<Pick<Base, Keys>>;
|
|
16
|
+
|
|
13
17
|
export function isRecord(value: unknown): value is Record<string, unknown> {
|
|
14
18
|
return typeof value === 'object' && value !== null;
|
|
15
19
|
}
|
|
16
20
|
|
|
17
|
-
export function hasOwnProperty<X extends Record<string, unknown>, Y extends PropertyKey>(
|
|
18
|
-
record: X,
|
|
19
|
-
prop: Y
|
|
20
|
-
): record is X & Record<Y, unknown> {
|
|
21
|
-
return prop in record;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
21
|
export function hasOwnProperties<X extends Record<string, unknown>, Y extends PropertyKey>(
|
|
25
22
|
record: X,
|
|
26
23
|
props: Y[]
|
package/src/workflow-options.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { coresdk, google } from '@temporalio/proto/lib/coresdk';
|
|
2
2
|
import { Workflow } from './interfaces';
|
|
3
|
+
import { falsyMsToTs } from './time';
|
|
4
|
+
import { Replace } from './type-helpers';
|
|
3
5
|
import { RetryPolicy } from './retry-policy';
|
|
4
|
-
import { msToTs } from './time';
|
|
5
6
|
import { checkExtends } from './type-helpers';
|
|
6
7
|
|
|
7
8
|
// Avoid importing the proto implementation to reduce workflow bundle size
|
|
@@ -28,10 +29,10 @@ export interface BaseWorkflowOptions {
|
|
|
28
29
|
workflowIdReusePolicy?: WorkflowIdReusePolicy;
|
|
29
30
|
|
|
30
31
|
/**
|
|
31
|
-
* Controls how a Workflow is retried.
|
|
32
|
+
* Controls how a Workflow Execution is retried.
|
|
32
33
|
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
34
|
+
* By default, Workflow Executions are not retried. Do not override this behavior unless you know what you're doing.
|
|
35
|
+
* [More information](https://docs.temporal.io/docs/concepts/what-is-a-retry-policy/).
|
|
35
36
|
*/
|
|
36
37
|
retry?: RetryPolicy;
|
|
37
38
|
|
|
@@ -104,14 +105,14 @@ export interface WorkflowDurationOptions {
|
|
|
104
105
|
|
|
105
106
|
export type CommonWorkflowOptions = BaseWorkflowOptions & WorkflowDurationOptions;
|
|
106
107
|
|
|
107
|
-
export type WithCompiledWorkflowDurationOptions<T extends WorkflowDurationOptions> =
|
|
108
|
+
export type WithCompiledWorkflowDurationOptions<T extends WorkflowDurationOptions> = Replace<
|
|
108
109
|
T,
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
110
|
+
{
|
|
111
|
+
workflowExecutionTimeout?: google.protobuf.IDuration;
|
|
112
|
+
workflowRunTimeout?: google.protobuf.IDuration;
|
|
113
|
+
workflowTaskTimeout?: google.protobuf.IDuration;
|
|
114
|
+
}
|
|
115
|
+
>;
|
|
115
116
|
|
|
116
117
|
export function compileWorkflowOptions<T extends WorkflowDurationOptions>(
|
|
117
118
|
options: T
|
|
@@ -120,8 +121,8 @@ export function compileWorkflowOptions<T extends WorkflowDurationOptions>(
|
|
|
120
121
|
|
|
121
122
|
return {
|
|
122
123
|
...rest,
|
|
123
|
-
workflowExecutionTimeout:
|
|
124
|
-
workflowRunTimeout:
|
|
125
|
-
workflowTaskTimeout:
|
|
124
|
+
workflowExecutionTimeout: falsyMsToTs(workflowExecutionTimeout),
|
|
125
|
+
workflowRunTimeout: falsyMsToTs(workflowRunTimeout),
|
|
126
|
+
workflowTaskTimeout: falsyMsToTs(workflowTaskTimeout),
|
|
126
127
|
};
|
|
127
128
|
}
|