@temporalio/common 0.18.0 → 0.19.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.
Files changed (97) hide show
  1. package/README.md +5 -11
  2. package/lib/converter/data-converter.d.ts +35 -62
  3. package/lib/converter/data-converter.js +6 -100
  4. package/lib/converter/data-converter.js.map +1 -1
  5. package/lib/{encoding.d.ts → converter/encoding.d.ts} +0 -0
  6. package/lib/{encoding.js → converter/encoding.js} +0 -0
  7. package/lib/converter/encoding.js.map +1 -0
  8. package/lib/converter/patch-protobuf-root.d.ts +8 -0
  9. package/lib/converter/patch-protobuf-root.js +43 -0
  10. package/lib/converter/patch-protobuf-root.js.map +1 -0
  11. package/lib/converter/payload-codec.d.ts +27 -0
  12. package/lib/converter/payload-codec.js +11 -0
  13. package/lib/converter/payload-codec.js.map +1 -0
  14. package/lib/converter/payload-converter.d.ts +63 -62
  15. package/lib/converter/payload-converter.js +113 -68
  16. package/lib/converter/payload-converter.js.map +1 -1
  17. package/lib/converter/payload-converters.d.ts +31 -0
  18. package/lib/converter/payload-converters.js +85 -0
  19. package/lib/converter/payload-converters.js.map +1 -0
  20. package/lib/converter/protobuf-payload-converters.d.ts +53 -0
  21. package/lib/converter/protobuf-payload-converters.js +159 -0
  22. package/lib/converter/protobuf-payload-converters.js.map +1 -0
  23. package/lib/converter/types.d.ts +4 -2
  24. package/lib/converter/types.js +3 -2
  25. package/lib/converter/types.js.map +1 -1
  26. package/lib/failure.d.ts +7 -7
  27. package/lib/failure.js +30 -32
  28. package/lib/failure.js.map +1 -1
  29. package/lib/index.d.ts +9 -11
  30. package/lib/index.js +12 -16
  31. package/lib/index.js.map +1 -1
  32. package/lib/protobufs.d.ts +13 -0
  33. package/lib/protobufs.js +31 -0
  34. package/lib/protobufs.js.map +1 -0
  35. package/package.json +11 -8
  36. package/src/converter/data-converter.ts +39 -175
  37. package/src/{encoding.ts → converter/encoding.ts} +0 -0
  38. package/src/converter/patch-protobuf-root.ts +49 -0
  39. package/src/converter/payload-codec.ts +30 -0
  40. package/src/converter/payload-converter.ts +122 -102
  41. package/src/converter/payload-converters.ts +89 -0
  42. package/src/converter/protobuf-payload-converters.ts +192 -0
  43. package/src/converter/types.ts +6 -3
  44. package/src/failure.ts +35 -39
  45. package/src/index.ts +9 -11
  46. package/src/protobufs.ts +15 -0
  47. package/tsconfig.json +2 -2
  48. package/tsconfig.tsbuildinfo +1 -1
  49. package/lib/activity-options.d.ts +0 -81
  50. package/lib/activity-options.js +0 -14
  51. package/lib/activity-options.js.map +0 -1
  52. package/lib/encoding.js.map +0 -1
  53. package/lib/errors.d.ts +0 -45
  54. package/lib/errors.js +0 -76
  55. package/lib/errors.js.map +0 -1
  56. package/lib/interceptors.d.ts +0 -18
  57. package/lib/interceptors.js +0 -24
  58. package/lib/interceptors.js.map +0 -1
  59. package/lib/interfaces.d.ts +0 -31
  60. package/lib/interfaces.js +0 -3
  61. package/lib/interfaces.js.map +0 -1
  62. package/lib/otel.d.ts +0 -26
  63. package/lib/otel.js +0 -82
  64. package/lib/otel.js.map +0 -1
  65. package/lib/retry-policy.d.ts +0 -43
  66. package/lib/retry-policy.js +0 -36
  67. package/lib/retry-policy.js.map +0 -1
  68. package/lib/time.d.ts +0 -17
  69. package/lib/time.js +0 -77
  70. package/lib/time.js.map +0 -1
  71. package/lib/tls-config.d.ts +0 -32
  72. package/lib/tls-config.js +0 -11
  73. package/lib/tls-config.js.map +0 -1
  74. package/lib/type-helpers.d.ts +0 -12
  75. package/lib/type-helpers.js +0 -17
  76. package/lib/type-helpers.js.map +0 -1
  77. package/lib/utils.d.ts +0 -4
  78. package/lib/utils.js +0 -11
  79. package/lib/utils.js.map +0 -1
  80. package/lib/workflow-handle.d.ts +0 -27
  81. package/lib/workflow-handle.js +0 -3
  82. package/lib/workflow-handle.js.map +0 -1
  83. package/lib/workflow-options.d.ts +0 -92
  84. package/lib/workflow-options.js +0 -26
  85. package/lib/workflow-options.js.map +0 -1
  86. package/src/activity-options.ts +0 -97
  87. package/src/errors.ts +0 -60
  88. package/src/interceptors.ts +0 -32
  89. package/src/interfaces.ts +0 -37
  90. package/src/otel.ts +0 -61
  91. package/src/retry-policy.ts +0 -73
  92. package/src/time.ts +0 -76
  93. package/src/tls-config.ts +0 -35
  94. package/src/type-helpers.ts +0 -26
  95. package/src/utils.ts +0 -6
  96. package/src/workflow-handle.ts +0 -30
  97. package/src/workflow-options.ts +0 -128
@@ -0,0 +1,192 @@
1
+ import {
2
+ errorMessage,
3
+ hasOwnProperties,
4
+ hasOwnProperty,
5
+ isRecord,
6
+ PayloadConverterError,
7
+ ValueError,
8
+ } from '@temporalio/internal-workflow-common';
9
+ import * as protoJsonSerializer from 'proto3-json-serializer';
10
+ import type { Message, Namespace, Root, Type } from 'protobufjs';
11
+ import { CompositePayloadConverter } from './payload-converter';
12
+ import {
13
+ BinaryPayloadConverter,
14
+ JsonPayloadConverter,
15
+ PayloadConverterWithEncoding,
16
+ UndefinedPayloadConverter,
17
+ } from './payload-converters';
18
+ import {
19
+ EncodingType,
20
+ encodingTypes,
21
+ METADATA_ENCODING_KEY,
22
+ METADATA_MESSAGE_TYPE_KEY,
23
+ Payload,
24
+ str,
25
+ u8,
26
+ } from './types';
27
+
28
+ abstract class ProtobufPayloadConverter implements PayloadConverterWithEncoding {
29
+ protected readonly root: Root | undefined;
30
+ public abstract encodingType: EncodingType;
31
+
32
+ public abstract toPayload<T>(value: T): Payload | undefined;
33
+ public abstract fromPayload<T>(payload: Payload): T;
34
+
35
+ // Don't use type Root here because root.d.ts doesn't export Root, so users would have to type assert
36
+ constructor(root?: unknown) {
37
+ if (root) {
38
+ if (!isRoot(root)) {
39
+ throw new TypeError('root must be an instance of a protobufjs Root');
40
+ }
41
+
42
+ this.root = root;
43
+ }
44
+ }
45
+
46
+ protected validatePayload(content: Payload): { messageType: Type; data: Uint8Array } {
47
+ if (content.data === undefined || content.data === null) {
48
+ throw new ValueError('Got payload with no data');
49
+ }
50
+ if (!content.metadata || !(METADATA_MESSAGE_TYPE_KEY in content.metadata)) {
51
+ throw new ValueError(`Got protobuf payload without metadata.${METADATA_MESSAGE_TYPE_KEY}`);
52
+ }
53
+ if (!this.root) {
54
+ throw new PayloadConverterError('Unable to deserialize protobuf message without `root` being provided');
55
+ }
56
+
57
+ const messageTypeName = str(content.metadata[METADATA_MESSAGE_TYPE_KEY]);
58
+ let messageType;
59
+ try {
60
+ messageType = this.root.lookupType(messageTypeName);
61
+ } catch (e) {
62
+ if (errorMessage(e)?.includes('no such type')) {
63
+ throw new PayloadConverterError(
64
+ `Got a \`${messageTypeName}\` protobuf message but cannot find corresponding message class in \`root\``
65
+ );
66
+ }
67
+
68
+ throw e;
69
+ }
70
+
71
+ return { messageType, data: content.data };
72
+ }
73
+
74
+ protected constructPayload({ messageTypeName, message }: { messageTypeName: string; message: Uint8Array }): Payload {
75
+ return {
76
+ metadata: {
77
+ [METADATA_ENCODING_KEY]: u8(this.encodingType),
78
+ [METADATA_MESSAGE_TYPE_KEY]: u8(messageTypeName),
79
+ },
80
+ data: message,
81
+ };
82
+ }
83
+ }
84
+
85
+ /**
86
+ * Converts between protobufjs Message instances and serialized Protobuf Payload
87
+ */
88
+ export class ProtobufBinaryPayloadConverter extends ProtobufPayloadConverter {
89
+ public encodingType = encodingTypes.METADATA_ENCODING_PROTOBUF;
90
+
91
+ /**
92
+ * @param root The value returned from {@link patchProtobufRoot}
93
+ */
94
+ constructor(root?: unknown) {
95
+ super(root);
96
+ }
97
+
98
+ public toPayload(value: unknown): Payload | undefined {
99
+ if (!isProtobufMessage(value)) return undefined;
100
+
101
+ return this.constructPayload({
102
+ messageTypeName: getNamespacedTypeName(value.$type),
103
+ message: value.$type.encode(value).finish(),
104
+ });
105
+ }
106
+
107
+ public fromPayload<T>(content: Payload): T {
108
+ const { messageType, data } = this.validatePayload(content);
109
+ return messageType.decode(data) as unknown as T;
110
+ }
111
+ }
112
+
113
+ /**
114
+ * Converts between protobufjs Message instances and serialized JSON Payload
115
+ */
116
+ export class ProtobufJsonPayloadConverter extends ProtobufPayloadConverter {
117
+ public encodingType = encodingTypes.METADATA_ENCODING_PROTOBUF_JSON;
118
+
119
+ /**
120
+ * @param root The value returned from {@link patchProtobufRoot}
121
+ */
122
+ constructor(root?: unknown) {
123
+ super(root);
124
+ }
125
+
126
+ public toPayload(value: unknown): Payload | undefined {
127
+ if (!isProtobufMessage(value)) return undefined;
128
+
129
+ const jsonValue = protoJsonSerializer.toProto3JSON(value);
130
+
131
+ return this.constructPayload({
132
+ messageTypeName: getNamespacedTypeName(value.$type),
133
+ message: u8(JSON.stringify(jsonValue)),
134
+ });
135
+ }
136
+
137
+ public fromPayload<T>(content: Payload): T {
138
+ const { messageType, data } = this.validatePayload(content);
139
+ return protoJsonSerializer.fromProto3JSON(messageType, JSON.parse(str(data))) as unknown as T;
140
+ }
141
+ }
142
+
143
+ function isProtobufType(type: unknown): type is Type {
144
+ return (
145
+ isRecord(type) &&
146
+ type.constructor.name === 'Type' &&
147
+ hasOwnProperties(type, ['parent', 'name', 'create', 'encode', 'decode']) &&
148
+ typeof type.name === 'string' &&
149
+ typeof type.create === 'function' &&
150
+ typeof type.encode === 'function' &&
151
+ typeof type.decode === 'function'
152
+ );
153
+ }
154
+
155
+ function isProtobufMessage(value: unknown): value is Message {
156
+ return isRecord(value) && hasOwnProperty(value, '$type') && isProtobufType(value.$type);
157
+ }
158
+
159
+ function getNamespacedTypeName(node: Type | Namespace): string {
160
+ if (node.parent && !isRoot(node.parent)) {
161
+ return getNamespacedTypeName(node.parent) + '.' + node.name;
162
+ } else {
163
+ return node.name;
164
+ }
165
+ }
166
+
167
+ function isRoot(root: unknown): root is Root {
168
+ return isRecord(root) && root.constructor.name === 'Root';
169
+ }
170
+
171
+ export interface DefaultPayloadConverterWithProtobufsOptions {
172
+ /**
173
+ * The `root` provided to {@link ProtobufJsonPayloadConverter} and {@link ProtobufBinaryPayloadConverter}
174
+ */
175
+ protobufRoot: Record<string, unknown>;
176
+ }
177
+
178
+ export class DefaultPayloadConverterWithProtobufs extends CompositePayloadConverter {
179
+ // Match the order used in other SDKs.
180
+ //
181
+ // Go SDK:
182
+ // https://github.com/temporalio/sdk-go/blob/5e5645f0c550dcf717c095ae32c76a7087d2e985/converter/default_data_converter.go#L28
183
+ constructor({ protobufRoot }: DefaultPayloadConverterWithProtobufsOptions) {
184
+ super(
185
+ new UndefinedPayloadConverter(),
186
+ new BinaryPayloadConverter(),
187
+ new ProtobufJsonPayloadConverter(protobufRoot),
188
+ new ProtobufBinaryPayloadConverter(protobufRoot),
189
+ new JsonPayloadConverter()
190
+ );
191
+ }
192
+ }
@@ -1,7 +1,7 @@
1
- import type * as iface from '@temporalio/proto/lib/coresdk';
2
- import { TextEncoder, TextDecoder } from '../encoding';
1
+ import type { coresdk } from '@temporalio/proto/lib/coresdk';
2
+ import { TextDecoder, TextEncoder } from './encoding';
3
3
 
4
- export type Payload = iface.coresdk.common.IPayload;
4
+ export type Payload = coresdk.common.IPayload;
5
5
 
6
6
  /**
7
7
  * Transform an *ascii* string into a Uint8Array
@@ -22,6 +22,7 @@ export const encodingTypes = {
22
22
  METADATA_ENCODING_PROTOBUF_JSON: 'json/protobuf',
23
23
  METADATA_ENCODING_PROTOBUF: 'binary/protobuf',
24
24
  } as const;
25
+ export type EncodingType = typeof encodingTypes[keyof typeof encodingTypes];
25
26
 
26
27
  export const encodingKeys = {
27
28
  METADATA_ENCODING_NULL: u8(encodingTypes.METADATA_ENCODING_NULL),
@@ -30,3 +31,5 @@ export const encodingKeys = {
30
31
  METADATA_ENCODING_PROTOBUF_JSON: u8(encodingTypes.METADATA_ENCODING_PROTOBUF_JSON),
31
32
  METADATA_ENCODING_PROTOBUF: u8(encodingTypes.METADATA_ENCODING_PROTOBUF),
32
33
  } as const;
34
+
35
+ export const METADATA_MESSAGE_TYPE_KEY = 'messageType';
package/src/failure.ts CHANGED
@@ -1,9 +1,10 @@
1
+ import { checkExtends, hasOwnProperties, isRecord } from '@temporalio/internal-workflow-common';
1
2
  import type { temporal } from '@temporalio/proto/lib/coresdk';
2
- import { DataConverter, arrayFromPayloads } from './converter/data-converter';
3
- import { checkExtends, hasOwnProperties, isRecord } from './type-helpers';
3
+ import { arrayFromPayloads, fromPayloadsAtIndex, PayloadConverter, toPayloads } from './converter/payload-converter';
4
4
 
5
5
  export const FAILURE_SOURCE = 'TypeScriptSDK';
6
6
  export type ProtoFailure = temporal.api.failure.v1.IFailure;
7
+
7
8
  // Avoid importing the proto implementation to reduce workflow bundle size
8
9
  // Copied from temporal.api.enums.v1.TimeoutType
9
10
  export enum TimeoutType {
@@ -78,7 +79,7 @@ export class ServerFailure extends TemporalFailure {
78
79
  * Any unhandled exception which doesn't extend {@link TemporalFailure} is converted to an
79
80
  * instance of this class before being returned to a caller.
80
81
  *
81
- * The {@link type} property is used by {@link io.temporal.common.RetryOptions} to determine if
82
+ * The {@link type} property is used by {@link temporal.common.RetryOptions} to determine if
82
83
  * an instance of this exception is non retryable. Another way to avoid retrying an exception of
83
84
  * this type is by setting {@link nonRetryable} flag to `true`.
84
85
  *
@@ -210,11 +211,11 @@ export class ChildWorkflowFailure extends TemporalFailure {
210
211
  /**
211
212
  * Converts an error to a Failure proto message if defined or returns undefined
212
213
  */
213
- export async function optionalErrorToOptionalFailure(
214
+ export function optionalErrorToOptionalFailure(
214
215
  err: unknown,
215
- dataConverter: DataConverter
216
- ): Promise<ProtoFailure | undefined> {
217
- return err ? await errorToFailure(err, dataConverter) : undefined;
216
+ payloadConverter: PayloadConverter
217
+ ): ProtoFailure | undefined {
218
+ return err ? errorToFailure(err, payloadConverter) : undefined;
218
219
  }
219
220
 
220
221
  /**
@@ -225,6 +226,8 @@ const CUTOFF_STACK_PATTERNS = [
225
226
  /\s+at Activity\.execute \(.*[\\/]worker[\\/](?:src|lib)[\\/]activity\.[jt]s:\d+:\d+\)/,
226
227
  /** Workflow activation */
227
228
  /\s+at Activator\.\S+NextHandler \(webpack-internal:\/\/\/.*\/internals\.[jt]s:\d+:\d+\)/,
229
+ /** Workflow run anything in context */
230
+ /\s+at Script\.runInContext/,
228
231
  ];
229
232
 
230
233
  /**
@@ -245,14 +248,14 @@ export function cutoffStackTrace(stack?: string): string {
245
248
  /**
246
249
  * Converts a caught error to a Failure proto message
247
250
  */
248
- export async function errorToFailure(err: unknown, dataConverter: DataConverter): Promise<ProtoFailure> {
251
+ export function errorToFailure(err: unknown, payloadConverter: PayloadConverter): ProtoFailure {
249
252
  if (err instanceof TemporalFailure) {
250
253
  if (err.failure) return err.failure;
251
254
 
252
255
  const base = {
253
256
  message: err.message,
254
257
  stackTrace: cutoffStackTrace(err.stack),
255
- cause: await optionalErrorToOptionalFailure(err.cause, dataConverter),
258
+ cause: optionalErrorToOptionalFailure(err.cause, payloadConverter),
256
259
  source: FAILURE_SOURCE,
257
260
  };
258
261
  if (err instanceof ActivityFailure) {
@@ -281,9 +284,7 @@ export async function errorToFailure(err: unknown, dataConverter: DataConverter)
281
284
  type: err.type,
282
285
  nonRetryable: err.nonRetryable,
283
286
  details:
284
- err.details && err.details.length
285
- ? { payloads: await dataConverter.toPayloads(...err.details) }
286
- : undefined,
287
+ err.details && err.details.length ? { payloads: toPayloads(payloadConverter, ...err.details) } : undefined,
287
288
  },
288
289
  };
289
290
  }
@@ -292,9 +293,7 @@ export async function errorToFailure(err: unknown, dataConverter: DataConverter)
292
293
  ...base,
293
294
  canceledFailureInfo: {
294
295
  details:
295
- err.details && err.details.length
296
- ? { payloads: await dataConverter.toPayloads(...err.details) }
297
- : undefined,
296
+ err.details && err.details.length ? { payloads: toPayloads(payloadConverter, ...err.details) } : undefined,
298
297
  },
299
298
  };
300
299
  }
@@ -304,7 +303,7 @@ export async function errorToFailure(err: unknown, dataConverter: DataConverter)
304
303
  timeoutFailureInfo: {
305
304
  timeoutType: err.timeoutType,
306
305
  lastHeartbeatDetails: err.lastHeartbeatDetails
307
- ? { payloads: await dataConverter.toPayloads(err.lastHeartbeatDetails) }
306
+ ? { payloads: toPayloads(payloadConverter, err.lastHeartbeatDetails) }
308
307
  : undefined,
309
308
  },
310
309
  };
@@ -334,7 +333,7 @@ export async function errorToFailure(err: unknown, dataConverter: DataConverter)
334
333
  ...base,
335
334
  message: String(err.message) ?? '',
336
335
  stackTrace: cutoffStackTrace(String(err.stack)),
337
- cause: await optionalErrorToOptionalFailure(err.cause, dataConverter),
336
+ cause: optionalErrorToOptionalFailure(err.cause, payloadConverter),
338
337
  };
339
338
  }
340
339
 
@@ -371,11 +370,11 @@ export function ensureTemporalFailure(err: unknown): TemporalFailure {
371
370
  /**
372
371
  * Converts a Failure proto message to a JS Error object if defined or returns undefined.
373
372
  */
374
- export async function optionalFailureToOptionalError(
373
+ export function optionalFailureToOptionalError(
375
374
  failure: ProtoFailure | undefined | null,
376
- dataConverter: DataConverter
377
- ): Promise<TemporalFailure | undefined> {
378
- return failure ? await failureToError(failure, dataConverter) : undefined;
375
+ payloadConverter: PayloadConverter
376
+ ): TemporalFailure | undefined {
377
+ return failure ? failureToError(failure, payloadConverter) : undefined;
379
378
  }
380
379
 
381
380
  /**
@@ -383,44 +382,41 @@ export async function optionalFailureToOptionalError(
383
382
  *
384
383
  * Does not set common properties, that is done in {@link failureToError}.
385
384
  */
386
- export async function failureToErrorInner(
387
- failure: ProtoFailure,
388
- dataConverter: DataConverter
389
- ): Promise<TemporalFailure> {
385
+ export function failureToErrorInner(failure: ProtoFailure, payloadConverter: PayloadConverter): TemporalFailure {
390
386
  if (failure.applicationFailureInfo) {
391
387
  return new ApplicationFailure(
392
388
  failure.message ?? undefined,
393
389
  failure.applicationFailureInfo.type,
394
390
  Boolean(failure.applicationFailureInfo.nonRetryable),
395
- await arrayFromPayloads(dataConverter, failure.applicationFailureInfo.details?.payloads),
396
- await optionalFailureToOptionalError(failure.cause, dataConverter)
391
+ arrayFromPayloads(payloadConverter, failure.applicationFailureInfo.details?.payloads),
392
+ optionalFailureToOptionalError(failure.cause, payloadConverter)
397
393
  );
398
394
  }
399
395
  if (failure.serverFailureInfo) {
400
396
  return new ServerFailure(
401
397
  failure.message ?? undefined,
402
398
  Boolean(failure.serverFailureInfo.nonRetryable),
403
- await optionalFailureToOptionalError(failure.cause, dataConverter)
399
+ optionalFailureToOptionalError(failure.cause, payloadConverter)
404
400
  );
405
401
  }
406
402
  if (failure.timeoutFailureInfo) {
407
403
  return new TimeoutFailure(
408
404
  failure.message ?? undefined,
409
- await dataConverter.fromPayloads(0, failure.timeoutFailureInfo.lastHeartbeatDetails?.payloads),
405
+ fromPayloadsAtIndex(payloadConverter, 0, failure.timeoutFailureInfo.lastHeartbeatDetails?.payloads),
410
406
  failure.timeoutFailureInfo.timeoutType ?? TimeoutType.TIMEOUT_TYPE_UNSPECIFIED
411
407
  );
412
408
  }
413
409
  if (failure.terminatedFailureInfo) {
414
410
  return new TerminatedFailure(
415
411
  failure.message ?? undefined,
416
- await optionalFailureToOptionalError(failure.cause, dataConverter)
412
+ optionalFailureToOptionalError(failure.cause, payloadConverter)
417
413
  );
418
414
  }
419
415
  if (failure.canceledFailureInfo) {
420
416
  return new CancelledFailure(
421
417
  failure.message ?? undefined,
422
- await arrayFromPayloads(dataConverter, failure.canceledFailureInfo.details?.payloads),
423
- await optionalFailureToOptionalError(failure.cause, dataConverter)
418
+ arrayFromPayloads(payloadConverter, failure.canceledFailureInfo.details?.payloads),
419
+ optionalFailureToOptionalError(failure.cause, payloadConverter)
424
420
  );
425
421
  }
426
422
  if (failure.resetWorkflowFailureInfo) {
@@ -428,8 +424,8 @@ export async function failureToErrorInner(
428
424
  failure.message ?? undefined,
429
425
  'ResetWorkflow',
430
426
  false,
431
- await arrayFromPayloads(dataConverter, failure.resetWorkflowFailureInfo.lastHeartbeatDetails?.payloads),
432
- await optionalFailureToOptionalError(failure.cause, dataConverter)
427
+ arrayFromPayloads(payloadConverter, failure.resetWorkflowFailureInfo.lastHeartbeatDetails?.payloads),
428
+ optionalFailureToOptionalError(failure.cause, payloadConverter)
433
429
  );
434
430
  }
435
431
  if (failure.childWorkflowExecutionFailureInfo) {
@@ -442,7 +438,7 @@ export async function failureToErrorInner(
442
438
  workflowExecution,
443
439
  workflowType.name,
444
440
  retryState ?? RetryState.RETRY_STATE_UNSPECIFIED,
445
- await optionalFailureToOptionalError(failure.cause, dataConverter)
441
+ optionalFailureToOptionalError(failure.cause, payloadConverter)
446
442
  );
447
443
  }
448
444
  if (failure.activityFailureInfo) {
@@ -454,20 +450,20 @@ export async function failureToErrorInner(
454
450
  failure.activityFailureInfo.activityId ?? undefined,
455
451
  failure.activityFailureInfo.retryState ?? RetryState.RETRY_STATE_UNSPECIFIED,
456
452
  failure.activityFailureInfo.identity ?? undefined,
457
- await optionalFailureToOptionalError(failure.cause, dataConverter)
453
+ optionalFailureToOptionalError(failure.cause, payloadConverter)
458
454
  );
459
455
  }
460
456
  return new TemporalFailure(
461
457
  failure.message ?? undefined,
462
- await optionalFailureToOptionalError(failure.cause, dataConverter)
458
+ optionalFailureToOptionalError(failure.cause, payloadConverter)
463
459
  );
464
460
  }
465
461
 
466
462
  /**
467
463
  * Converts a Failure proto message to a JS Error object.
468
464
  */
469
- export async function failureToError(failure: ProtoFailure, dataConverter: DataConverter): Promise<TemporalFailure> {
470
- const err = await failureToErrorInner(failure, dataConverter);
465
+ export function failureToError(failure: ProtoFailure, payloadConverter: PayloadConverter): TemporalFailure {
466
+ const err = failureToErrorInner(failure, payloadConverter);
471
467
  err.stack = failure.stackTrace ?? '';
472
468
  err.failure = failure;
473
469
  return err;
package/src/index.ts CHANGED
@@ -1,17 +1,15 @@
1
1
  /**
2
- * Common library for both isolated Workflow and normal non-Workflow code
2
+ * Common library for code that's used across the Client, Worker, and/or Workflow
3
3
  *
4
4
  * @module
5
5
  */
6
- export * from './activity-options';
6
+ export { ActivityFunction, ActivityInterface, Headers, Next, RetryPolicy } from '@temporalio/internal-workflow-common';
7
+ export * from '@temporalio/internal-workflow-common/lib/errors';
8
+ export * from '@temporalio/internal-workflow-common/lib/interfaces';
9
+ export * from '@temporalio/internal-workflow-common/lib/time';
7
10
  export * from './converter/data-converter';
8
- export * from './errors';
11
+ export * from './converter/payload-codec';
12
+ export * from './converter/payload-converter';
13
+ export * from './converter/payload-converters';
14
+ export * from './converter/types';
9
15
  export * from './failure';
10
- export * from './interceptors';
11
- export * from './interfaces';
12
- export * from './retry-policy';
13
- export * from './time';
14
- export * from './tls-config';
15
- export * from './workflow-handle';
16
- export * from './workflow-options';
17
- export * from './utils';
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Entry point for classes and utilities related to using
3
+ * [Protobufs](https://docs.temporal.io/docs/typescript/data-converters#protobufs) for serialization.
4
+ *
5
+ * Import from `@temporalio/common/lib/protobufs`, for example:
6
+ *
7
+ * ```
8
+ * import { patchProtobufRoot } from '@temporalio/common/lib/protobufs';
9
+ * ```
10
+ * @module
11
+ */
12
+
13
+ // Don't export from index, so we save space in Workflow bundles of users who don't use Protobufs
14
+ export * from './converter/protobuf-payload-converters';
15
+ export * from './converter/patch-protobuf-root';
package/tsconfig.json CHANGED
@@ -4,6 +4,6 @@
4
4
  "outDir": "./lib",
5
5
  "rootDir": "./src"
6
6
  },
7
- "include": ["./src/**/*.ts"],
8
- "exclude": ["node_modules"]
7
+ "references": [{ "path": "../internal-workflow-common" }],
8
+ "include": ["./src/**/*.ts"]
9
9
  }