@temporalio/common 1.12.2 → 1.13.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 (42) hide show
  1. package/lib/activity-cancellation-details.d.ts +25 -0
  2. package/lib/activity-cancellation-details.js +37 -0
  3. package/lib/activity-cancellation-details.js.map +1 -0
  4. package/lib/activity-options.d.ts +2 -2
  5. package/lib/converter/failure-converter.d.ts +2 -2
  6. package/lib/converter/failure-converter.js +106 -3
  7. package/lib/converter/failure-converter.js.map +1 -1
  8. package/lib/failure.d.ts +13 -0
  9. package/lib/failure.js +26 -1
  10. package/lib/failure.js.map +1 -1
  11. package/lib/index.d.ts +1 -0
  12. package/lib/index.js +3 -1
  13. package/lib/index.js.map +1 -1
  14. package/lib/internal-non-workflow/codec-helpers.d.ts +4 -0
  15. package/lib/internal-non-workflow/codec-helpers.js +20 -0
  16. package/lib/internal-non-workflow/codec-helpers.js.map +1 -1
  17. package/lib/logger.d.ts +5 -0
  18. package/lib/logger.js +5 -0
  19. package/lib/logger.js.map +1 -1
  20. package/lib/priority.d.ts +26 -1
  21. package/lib/priority.js +7 -1
  22. package/lib/priority.js.map +1 -1
  23. package/lib/proto-utils.d.ts +8 -0
  24. package/lib/proto-utils.js +21 -16
  25. package/lib/proto-utils.js.map +1 -1
  26. package/lib/user-metadata.d.ts +1 -4
  27. package/lib/user-metadata.js +0 -21
  28. package/lib/user-metadata.js.map +1 -1
  29. package/lib/workflow-options.d.ts +2 -2
  30. package/package.json +5 -4
  31. package/src/activity-cancellation-details.ts +52 -0
  32. package/src/activity-options.ts +2 -2
  33. package/src/converter/failure-converter.ts +108 -4
  34. package/src/failure.ts +22 -0
  35. package/src/index.ts +1 -0
  36. package/src/internal-non-workflow/codec-helpers.ts +37 -1
  37. package/src/internal-non-workflow/codec-types.ts +1 -1
  38. package/src/logger.ts +6 -0
  39. package/src/priority.ts +35 -2
  40. package/src/proto-utils.ts +18 -15
  41. package/src/user-metadata.ts +1 -32
  42. package/src/workflow-options.ts +2 -2
@@ -113,29 +113,32 @@ export function historyFromJSON(history: unknown): History {
113
113
  * string that adheres to the same norm as JSON history files produced by other Temporal tools.
114
114
  */
115
115
  export function historyToJSON(history: History): string {
116
- // toProto3JSON doesn't correctly handle some of our "bytes" fields, passing them untouched to the
117
- // output, after which JSON.stringify() would convert them to an array of numbers. As a workaround,
118
- // recursively walk the object and convert all Buffer instances to base64 strings. Note this only
119
- // works on proto3-json-serializer v2.0.0. v2.0.2 throws an error before we even get the chance
120
- // to fix the buffers. See https://github.com/googleapis/proto3-json-serializer-nodejs/issues/103.
121
- function fixBuffers<T>(e: T): T {
122
- if (e && typeof e === 'object') {
123
- if (e instanceof Buffer) return e.toString('base64') as any;
124
- if (Array.isArray(e)) return e.map(fixBuffers) as T;
125
- return Object.fromEntries(Object.entries(e as object).map(([k, v]) => [k, fixBuffers(v)])) as T;
126
- }
127
- return e;
128
- }
129
-
130
116
  const protoJson = toProto3JSON(proto.temporal.api.history.v1.History.fromObject(history) as any);
131
117
  return JSON.stringify(fixBuffers(protoJson), null, 2);
132
118
  }
133
119
 
120
+ /**
121
+ * toProto3JSON doesn't correctly handle some of our "bytes" fields, passing them untouched to the
122
+ * output, after which JSON.stringify() would convert them to an array of numbers. As a workaround,
123
+ * recursively walk the object and convert all Buffer instances to base64 strings. Note this only
124
+ * works on proto3-json-serializer v2.0.0. v2.0.2 throws an error before we even get the chance
125
+ * to fix the buffers. See https://github.com/googleapis/proto3-json-serializer-nodejs/issues/103.
126
+ */
127
+ export function fixBuffers<T>(e: T): T {
128
+ if (e && typeof e === 'object') {
129
+ if (e instanceof Buffer) return e.toString('base64') as any;
130
+ if (e instanceof Uint8Array) return Buffer.from(e).toString('base64') as any;
131
+ if (Array.isArray(e)) return e.map(fixBuffers) as T;
132
+ return Object.fromEntries(Object.entries(e as object).map(([k, v]) => [k, fixBuffers(v)])) as T;
133
+ }
134
+ return e;
135
+ }
136
+
134
137
  /**
135
138
  * Convert from protobuf payload to JSON
136
139
  */
137
140
  export function payloadToJSON(payload: Payload): JSONPayload {
138
- return toProto3JSON(patched.temporal.api.common.v1.Payload.create(payload)) as any;
141
+ return fixBuffers(toProto3JSON(patched.temporal.api.common.v1.Payload.create(payload))) as any;
139
142
  }
140
143
 
141
144
  /**
@@ -1,7 +1,5 @@
1
- import { temporal } from '@temporalio/proto';
1
+ import type { temporal } from '@temporalio/proto';
2
2
  import { convertOptionalToPayload, PayloadConverter } from './converter/payload-converter';
3
- import { LoadedDataConverter } from './converter/data-converter';
4
- import { decodeOptionalSinglePayload, encodeOptionalSingle } from './internal-non-workflow';
5
3
 
6
4
  /**
7
5
  * User metadata that can be attached to workflow commands.
@@ -27,32 +25,3 @@ export function userMetadataToPayload(
27
25
 
28
26
  return { summary, details };
29
27
  }
30
-
31
- export async function encodeUserMetadata(
32
- dataConverter: LoadedDataConverter,
33
- staticSummary: string | undefined,
34
- staticDetails: string | undefined
35
- ): Promise<temporal.api.sdk.v1.IUserMetadata | undefined> {
36
- if (staticSummary == null && staticDetails == null) return undefined;
37
-
38
- const { payloadConverter, payloadCodecs } = dataConverter;
39
- const summary = await encodeOptionalSingle(payloadCodecs, convertOptionalToPayload(payloadConverter, staticSummary));
40
- const details = await encodeOptionalSingle(payloadCodecs, convertOptionalToPayload(payloadConverter, staticDetails));
41
-
42
- if (summary == null && details == null) return undefined;
43
-
44
- return { summary, details };
45
- }
46
-
47
- export async function decodeUserMetadata(
48
- dataConverter: LoadedDataConverter,
49
- metadata: temporal.api.sdk.v1.IUserMetadata | undefined | null
50
- ): Promise<UserMetadata> {
51
- const res = { staticSummary: undefined, staticDetails: undefined };
52
- if (metadata == null) return res;
53
-
54
- const staticSummary = (await decodeOptionalSinglePayload<string>(dataConverter, metadata.summary)) ?? undefined;
55
- const staticDetails = (await decodeOptionalSinglePayload<string>(dataConverter, metadata.details)) ?? undefined;
56
-
57
- return { staticSummary, staticDetails };
58
- }
@@ -197,14 +197,14 @@ export interface BaseWorkflowOptions {
197
197
  * General fixed details for this workflow execution that may appear in UI/CLI.
198
198
  * This can be in Temporal markdown format and can span multiple lines.
199
199
  *
200
- * @experimental User metadata is a new API and suspectible to change.
200
+ * @experimental User metadata is a new API and susceptible to change.
201
201
  */
202
202
  staticDetails?: string;
203
203
  /**
204
204
  * A single-line fixed summary for this workflow execution that may appear in the UI/CLI.
205
205
  * This can be in single-line Temporal markdown format.
206
206
  *
207
- * @experimental User metadata is a new API and suspectible to change.
207
+ * @experimental User metadata is a new API and susceptible to change.
208
208
  */
209
209
  staticSummary?: string;
210
210