@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
package/lib/priority.js CHANGED
@@ -6,7 +6,11 @@ exports.compilePriority = compilePriority;
6
6
  * Turn a proto compatible Priority into a TS Priority
7
7
  */
8
8
  function decodePriority(priority) {
9
- return { priorityKey: priority?.priorityKey ?? undefined };
9
+ return {
10
+ priorityKey: priority?.priorityKey ?? undefined,
11
+ fairnessKey: priority?.fairnessKey ?? undefined,
12
+ fairnessWeight: priority?.fairnessWeight ?? undefined,
13
+ };
10
14
  }
11
15
  /**
12
16
  * Turn a TS Priority into a proto compatible Priority
@@ -22,6 +26,8 @@ function compilePriority(priority) {
22
26
  }
23
27
  return {
24
28
  priorityKey: priority.priorityKey ?? 0,
29
+ fairnessKey: priority.fairnessKey ?? '',
30
+ fairnessWeight: priority.fairnessWeight ?? 0,
25
31
  };
26
32
  }
27
33
  //# sourceMappingURL=priority.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"priority.js","sourceRoot":"","sources":["../src/priority.ts"],"names":[],"mappings":";;AAiCA,wCAEC;AAKD,0CAaC;AAvBD;;GAEG;AACH,SAAgB,cAAc,CAAC,QAAkD;IAC/E,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,WAAW,IAAI,SAAS,EAAE,CAAC;AAC7D,CAAC;AAED;;GAEG;AACH,SAAgB,eAAe,CAAC,QAAkB;IAChD,IAAI,QAAQ,CAAC,WAAW,KAAK,SAAS,IAAI,QAAQ,CAAC,WAAW,KAAK,IAAI,EAAE,CAAC;QACxE,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;YAC5C,MAAM,IAAI,SAAS,CAAC,gCAAgC,CAAC,CAAC;QACxD,CAAC;QACD,IAAI,QAAQ,CAAC,WAAW,GAAG,CAAC,EAAE,CAAC;YAC7B,MAAM,IAAI,UAAU,CAAC,wCAAwC,CAAC,CAAC;QACjE,CAAC;IACH,CAAC;IAED,OAAO;QACL,WAAW,EAAE,QAAQ,CAAC,WAAW,IAAI,CAAC;KACvC,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"priority.js","sourceRoot":"","sources":["../src/priority.ts"],"names":[],"mappings":";;AA4DA,wCAMC;AAKD,0CAeC;AA7BD;;GAEG;AACH,SAAgB,cAAc,CAAC,QAAkD;IAC/E,OAAO;QACL,WAAW,EAAE,QAAQ,EAAE,WAAW,IAAI,SAAS;QAC/C,WAAW,EAAE,QAAQ,EAAE,WAAW,IAAI,SAAS;QAC/C,cAAc,EAAE,QAAQ,EAAE,cAAc,IAAI,SAAS;KACtD,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAgB,eAAe,CAAC,QAAkB;IAChD,IAAI,QAAQ,CAAC,WAAW,KAAK,SAAS,IAAI,QAAQ,CAAC,WAAW,KAAK,IAAI,EAAE,CAAC;QACxE,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;YAC5C,MAAM,IAAI,SAAS,CAAC,gCAAgC,CAAC,CAAC;QACxD,CAAC;QACD,IAAI,QAAQ,CAAC,WAAW,GAAG,CAAC,EAAE,CAAC;YAC7B,MAAM,IAAI,UAAU,CAAC,wCAAwC,CAAC,CAAC;QACjE,CAAC;IACH,CAAC;IAED,OAAO;QACL,WAAW,EAAE,QAAQ,CAAC,WAAW,IAAI,CAAC;QACtC,WAAW,EAAE,QAAQ,CAAC,WAAW,IAAI,EAAE;QACvC,cAAc,EAAE,QAAQ,CAAC,cAAc,IAAI,CAAC;KAC7C,CAAC;AACJ,CAAC"}
@@ -23,6 +23,14 @@ export declare function historyFromJSON(history: unknown): History;
23
23
  * string that adheres to the same norm as JSON history files produced by other Temporal tools.
24
24
  */
25
25
  export declare function historyToJSON(history: History): string;
26
+ /**
27
+ * toProto3JSON doesn't correctly handle some of our "bytes" fields, passing them untouched to the
28
+ * output, after which JSON.stringify() would convert them to an array of numbers. As a workaround,
29
+ * recursively walk the object and convert all Buffer instances to base64 strings. Note this only
30
+ * works on proto3-json-serializer v2.0.0. v2.0.2 throws an error before we even get the chance
31
+ * to fix the buffers. See https://github.com/googleapis/proto3-json-serializer-nodejs/issues/103.
32
+ */
33
+ export declare function fixBuffers<T>(e: T): T;
26
34
  /**
27
35
  * Convert from protobuf payload to JSON
28
36
  */
@@ -25,6 +25,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.historyFromJSON = historyFromJSON;
27
27
  exports.historyToJSON = historyToJSON;
28
+ exports.fixBuffers = fixBuffers;
28
29
  exports.payloadToJSON = payloadToJSON;
29
30
  exports.JSONToPayload = JSONToPayload;
30
31
  const proto3_json_serializer_1 = require("proto3-json-serializer");
@@ -113,29 +114,33 @@ function historyFromJSON(history) {
113
114
  * string that adheres to the same norm as JSON history files produced by other Temporal tools.
114
115
  */
115
116
  function historyToJSON(history) {
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(e) {
122
- if (e && typeof e === 'object') {
123
- if (e instanceof Buffer)
124
- return e.toString('base64');
125
- if (Array.isArray(e))
126
- return e.map(fixBuffers);
127
- return Object.fromEntries(Object.entries(e).map(([k, v]) => [k, fixBuffers(v)]));
128
- }
129
- return e;
130
- }
131
117
  const protoJson = (0, proto3_json_serializer_1.toProto3JSON)(proto.temporal.api.history.v1.History.fromObject(history));
132
118
  return JSON.stringify(fixBuffers(protoJson), null, 2);
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
+ function fixBuffers(e) {
128
+ if (e && typeof e === 'object') {
129
+ if (e instanceof Buffer)
130
+ return e.toString('base64');
131
+ if (e instanceof Uint8Array)
132
+ return Buffer.from(e).toString('base64');
133
+ if (Array.isArray(e))
134
+ return e.map(fixBuffers);
135
+ return Object.fromEntries(Object.entries(e).map(([k, v]) => [k, fixBuffers(v)]));
136
+ }
137
+ return e;
138
+ }
134
139
  /**
135
140
  * Convert from protobuf payload to JSON
136
141
  */
137
142
  function payloadToJSON(payload) {
138
- return (0, proto3_json_serializer_1.toProto3JSON)(patched.temporal.api.common.v1.Payload.create(payload));
143
+ return fixBuffers((0, proto3_json_serializer_1.toProto3JSON)(patched.temporal.api.common.v1.Payload.create(payload)));
139
144
  }
140
145
  /**
141
146
  * Convert from JSON to protobuf payload
@@ -1 +1 @@
1
- {"version":3,"file":"proto-utils.js","sourceRoot":"","sources":["../src/proto-utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,0CA+EC;AAMD,sCAiBC;AAKD,sCAEC;AAKD,sCAMC;AArJD,mEAAsE;AACtE,yDAA2C;AAC3C,mFAA8E;AAmB9E,yFAAyF;AACzF,MAAM,OAAO,GAAG,IAAA,uCAAiB,EAAC,KAAK,CAAQ,CAAC;AAChD,MAAM,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,iCAAiC,CAAC,CAAC;AAC1E,MAAM,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,gCAAgC,CAAC,CAAC;AAEzE;;GAEG;AACH,SAAgB,eAAe,CAAC,OAAgB;IAC9C,SAAS,wBAAwB,CAAC,CAAS;QACzC,OAAO,CAAC,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,C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,IAAI,EAAE,CAAC;QACpB,MAAM,IAAI,SAAS,CAAC,iBAAiB,CAAC,CAAC;IACzC,CAAC;IACD,OAAO,MAAa,CAAC;AACvB,CAAC"}
@@ -1,6 +1,5 @@
1
- import { temporal } from '@temporalio/proto';
1
+ import type { temporal } from '@temporalio/proto';
2
2
  import { PayloadConverter } from './converter/payload-converter';
3
- import { LoadedDataConverter } from './converter/data-converter';
4
3
  /**
5
4
  * User metadata that can be attached to workflow commands.
6
5
  */
@@ -11,5 +10,3 @@ export interface UserMetadata {
11
10
  staticDetails?: string;
12
11
  }
13
12
  export declare function userMetadataToPayload(payloadConverter: PayloadConverter, staticSummary: string | undefined, staticDetails: string | undefined): temporal.api.sdk.v1.IUserMetadata | undefined;
14
- export declare function encodeUserMetadata(dataConverter: LoadedDataConverter, staticSummary: string | undefined, staticDetails: string | undefined): Promise<temporal.api.sdk.v1.IUserMetadata | undefined>;
15
- export declare function decodeUserMetadata(dataConverter: LoadedDataConverter, metadata: temporal.api.sdk.v1.IUserMetadata | undefined | null): Promise<UserMetadata>;
@@ -1,10 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.userMetadataToPayload = userMetadataToPayload;
4
- exports.encodeUserMetadata = encodeUserMetadata;
5
- exports.decodeUserMetadata = decodeUserMetadata;
6
4
  const payload_converter_1 = require("./converter/payload-converter");
7
- const internal_non_workflow_1 = require("./internal-non-workflow");
8
5
  function userMetadataToPayload(payloadConverter, staticSummary, staticDetails) {
9
6
  if (staticSummary == null && staticDetails == null)
10
7
  return undefined;
@@ -14,22 +11,4 @@ function userMetadataToPayload(payloadConverter, staticSummary, staticDetails) {
14
11
  return undefined;
15
12
  return { summary, details };
16
13
  }
17
- async function encodeUserMetadata(dataConverter, staticSummary, staticDetails) {
18
- if (staticSummary == null && staticDetails == null)
19
- return undefined;
20
- const { payloadConverter, payloadCodecs } = dataConverter;
21
- const summary = await (0, internal_non_workflow_1.encodeOptionalSingle)(payloadCodecs, (0, payload_converter_1.convertOptionalToPayload)(payloadConverter, staticSummary));
22
- const details = await (0, internal_non_workflow_1.encodeOptionalSingle)(payloadCodecs, (0, payload_converter_1.convertOptionalToPayload)(payloadConverter, staticDetails));
23
- if (summary == null && details == null)
24
- return undefined;
25
- return { summary, details };
26
- }
27
- async function decodeUserMetadata(dataConverter, metadata) {
28
- const res = { staticSummary: undefined, staticDetails: undefined };
29
- if (metadata == null)
30
- return res;
31
- const staticSummary = (await (0, internal_non_workflow_1.decodeOptionalSinglePayload)(dataConverter, metadata.summary)) ?? undefined;
32
- const staticDetails = (await (0, internal_non_workflow_1.decodeOptionalSinglePayload)(dataConverter, metadata.details)) ?? undefined;
33
- return { staticSummary, staticDetails };
34
- }
35
14
  //# sourceMappingURL=user-metadata.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"user-metadata.js","sourceRoot":"","sources":["../src/user-metadata.ts"],"names":[],"mappings":";;AAeA,sDAaC;AAED,gDAcC;AAED,gDAWC;AAxDD,qEAA2F;AAE3F,mEAA4F;AAY5F,SAAgB,qBAAqB,CACnC,gBAAkC,EAClC,aAAiC,EACjC,aAAiC;IAEjC,IAAI,aAAa,IAAI,IAAI,IAAI,aAAa,IAAI,IAAI;QAAE,OAAO,SAAS,CAAC;IAErE,MAAM,OAAO,GAAG,IAAA,4CAAwB,EAAC,gBAAgB,EAAE,aAAa,CAAC,CAAC;IAC1E,MAAM,OAAO,GAAG,IAAA,4CAAwB,EAAC,gBAAgB,EAAE,aAAa,CAAC,CAAC;IAE1E,IAAI,OAAO,IAAI,IAAI,IAAI,OAAO,IAAI,IAAI;QAAE,OAAO,SAAS,CAAC;IAEzD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;AAC9B,CAAC;AAEM,KAAK,UAAU,kBAAkB,CACtC,aAAkC,EAClC,aAAiC,EACjC,aAAiC;IAEjC,IAAI,aAAa,IAAI,IAAI,IAAI,aAAa,IAAI,IAAI;QAAE,OAAO,SAAS,CAAC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,gBAAgB,EAAE,aAAa,CAAC,CAAC;IAC1E,MAAM,OAAO,GAAG,IAAA,4CAAwB,EAAC,gBAAgB,EAAE,aAAa,CAAC,CAAC;IAE1E,IAAI,OAAO,IAAI,IAAI,IAAI,OAAO,IAAI,IAAI;QAAE,OAAO,SAAS,CAAC;IAEzD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;AAC9B,CAAC"}
@@ -143,14 +143,14 @@ export interface BaseWorkflowOptions {
143
143
  * General fixed details for this workflow execution that may appear in UI/CLI.
144
144
  * This can be in Temporal markdown format and can span multiple lines.
145
145
  *
146
- * @experimental User metadata is a new API and suspectible to change.
146
+ * @experimental User metadata is a new API and susceptible to change.
147
147
  */
148
148
  staticDetails?: string;
149
149
  /**
150
150
  * A single-line fixed summary for this workflow execution that may appear in the UI/CLI.
151
151
  * This can be in single-line Temporal markdown format.
152
152
  *
153
- * @experimental User metadata is a new API and suspectible to change.
153
+ * @experimental User metadata is a new API and susceptible to change.
154
154
  */
155
155
  staticSummary?: string;
156
156
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@temporalio/common",
3
- "version": "1.12.2",
3
+ "version": "1.13.0",
4
4
  "description": "Common library for code that's used across the Client, Worker, and/or Workflow",
5
5
  "main": "lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -12,9 +12,10 @@
12
12
  "author": "Temporal Technologies Inc. <sdk@temporal.io>",
13
13
  "license": "MIT",
14
14
  "dependencies": {
15
- "@temporalio/proto": "1.12.2",
15
+ "@temporalio/proto": "1.13.0",
16
16
  "long": "^5.2.3",
17
- "ms": "^3.0.0-canary.1",
17
+ "ms": "3.0.0-canary.1",
18
+ "nexus-rpc": "^0.0.1",
18
19
  "proto3-json-serializer": "^2.0.0"
19
20
  },
20
21
  "devDependencies": {
@@ -39,5 +40,5 @@
39
40
  "src",
40
41
  "lib"
41
42
  ],
42
- "gitHead": "98393e00b714b8d44a3dc25714d313d3366f4c50"
43
+ "gitHead": "cf7c1e7d70f0c775f1382fd335b8bd721495f8cc"
43
44
  }
@@ -0,0 +1,52 @@
1
+ import type { coresdk } from '@temporalio/proto';
2
+
3
+ // ts-prune-ignore-next
4
+ export interface ActivityCancellationDetailsHolder {
5
+ details?: ActivityCancellationDetails;
6
+ }
7
+
8
+ export interface ActivityCancellationDetailsOptions {
9
+ notFound?: boolean;
10
+ cancelRequested?: boolean;
11
+ paused?: boolean;
12
+ timedOut?: boolean;
13
+ workerShutdown?: boolean;
14
+ reset?: boolean;
15
+ }
16
+
17
+ /**
18
+ * Provides the reasons for the activity's cancellation. Cancellation details are set once and do not change once set.
19
+ */
20
+ export class ActivityCancellationDetails {
21
+ readonly notFound: boolean;
22
+ readonly cancelRequested: boolean;
23
+ readonly paused: boolean;
24
+ readonly timedOut: boolean;
25
+ readonly workerShutdown: boolean;
26
+ readonly reset: boolean;
27
+
28
+ public constructor(options: ActivityCancellationDetailsOptions = {}) {
29
+ this.notFound = options.notFound ?? false;
30
+ this.cancelRequested = options.cancelRequested ?? false;
31
+ this.paused = options.paused ?? false;
32
+ this.timedOut = options.timedOut ?? false;
33
+ this.workerShutdown = options.workerShutdown ?? false;
34
+ this.reset = options.reset ?? false;
35
+ }
36
+
37
+ static fromProto(
38
+ proto: coresdk.activity_task.IActivityCancellationDetails | null | undefined
39
+ ): ActivityCancellationDetails {
40
+ if (proto == null) {
41
+ return new ActivityCancellationDetails();
42
+ }
43
+ return new ActivityCancellationDetails({
44
+ notFound: proto.isNotFound ?? false,
45
+ cancelRequested: proto.isCancelled ?? false,
46
+ paused: proto.isPaused ?? false,
47
+ timedOut: proto.isTimedOut ?? false,
48
+ workerShutdown: proto.isWorkerShutdown ?? false,
49
+ reset: proto.isReset ?? false,
50
+ });
51
+ }
52
+ }
@@ -129,7 +129,7 @@ export interface ActivityOptions {
129
129
  * A fixed, single-line summary for this workflow execution that may appear in the UI/CLI.
130
130
  * This can be in single-line Temporal markdown format.
131
131
  *
132
- * @experimental User metadata is a new API and suspectible to change.
132
+ * @experimental User metadata is a new API and susceptible to change.
133
133
  */
134
134
  summary?: string;
135
135
 
@@ -206,7 +206,7 @@ export interface LocalActivityOptions {
206
206
  * A fixed, single-line summary for this workflow execution that may appear in the UI/CLI.
207
207
  * This can be in single-line Temporal markdown format.
208
208
  *
209
- * @experimental User metadata is a new API and suspectible to change.
209
+ * @experimental User metadata is a new API and susceptible to change.
210
210
  */
211
211
  summary?: string;
212
212
  }
@@ -1,3 +1,6 @@
1
+ import * as nexus from 'nexus-rpc';
2
+ import Long from 'long';
3
+ import type { temporal } from '@temporalio/proto';
1
4
  import {
2
5
  ActivityFailure,
3
6
  ApplicationFailure,
@@ -10,16 +13,42 @@ import {
10
13
  encodeRetryState,
11
14
  encodeTimeoutType,
12
15
  FAILURE_SOURCE,
16
+ NexusOperationFailure,
13
17
  ProtoFailure,
14
18
  ServerFailure,
15
19
  TemporalFailure,
16
20
  TerminatedFailure,
17
21
  TimeoutFailure,
18
22
  } from '../failure';
23
+ import { makeProtoEnumConverters } from '../internal-workflow';
19
24
  import { isError } from '../type-helpers';
20
25
  import { msOptionalToTs } from '../time';
21
26
  import { arrayFromPayloads, fromPayloadsAtIndex, PayloadConverter, toPayloads } from './payload-converter';
22
27
 
28
+ // Can't import proto enums into the workflow sandbox, use this helper type and enum converter instead.
29
+ const NexusHandlerErrorRetryBehavior = {
30
+ RETRYABLE: 'RETRYABLE',
31
+ NON_RETRYABLE: 'NON_RETRYABLE',
32
+ } as const;
33
+
34
+ type NexusHandlerErrorRetryBehavior =
35
+ (typeof NexusHandlerErrorRetryBehavior)[keyof typeof NexusHandlerErrorRetryBehavior];
36
+
37
+ const [encodeNexusHandlerErrorRetryBehavior, decodeNexusHandlerErrorRetryBehavior] = makeProtoEnumConverters<
38
+ temporal.api.enums.v1.NexusHandlerErrorRetryBehavior,
39
+ typeof temporal.api.enums.v1.NexusHandlerErrorRetryBehavior,
40
+ keyof typeof temporal.api.enums.v1.NexusHandlerErrorRetryBehavior,
41
+ typeof NexusHandlerErrorRetryBehavior,
42
+ 'NEXUS_HANDLER_ERROR_RETRY_BEHAVIOR_'
43
+ >(
44
+ {
45
+ UNSPECIFIED: 0,
46
+ [NexusHandlerErrorRetryBehavior.RETRYABLE]: 1,
47
+ [NexusHandlerErrorRetryBehavior.NON_RETRYABLE]: 2,
48
+ } as const,
49
+ 'NEXUS_HANDLER_ERROR_RETRY_BEHAVIOR_'
50
+ );
51
+
23
52
  function combineRegExp(...regexps: RegExp[]): RegExp {
24
53
  return new RegExp(regexps.map((x) => `(?:${x.source})`).join('|'));
25
54
  }
@@ -30,6 +59,8 @@ function combineRegExp(...regexps: RegExp[]): RegExp {
30
59
  const CUTOFF_STACK_PATTERNS = combineRegExp(
31
60
  /** Activity execution */
32
61
  /\s+at Activity\.execute \(.*[\\/]worker[\\/](?:src|lib)[\\/]activity\.[jt]s:\d+:\d+\)/,
62
+ /** Nexus execution */
63
+ /\s+at( async)? NexusHandler\.invokeUserCode \(.*[\\/]worker[\\/](?:src|lib)[\\/]nexus[\\/]index\.[jt]s:\d+:\d+\)/,
33
64
  /** Workflow activation */
34
65
  /\s+at Activator\.\S+NextHandler \(.*[\\/]workflow[\\/](?:src|lib)[\\/]internals\.[jt]s:\d+:\d+\)/,
35
66
  /** Workflow run anything in context */
@@ -122,7 +153,7 @@ export class DefaultFailureConverter implements FailureConverter {
122
153
  *
123
154
  * Does not set common properties, that is done in {@link failureToError}.
124
155
  */
125
- failureToErrorInner(failure: ProtoFailure, payloadConverter: PayloadConverter): TemporalFailure {
156
+ failureToErrorInner(failure: ProtoFailure, payloadConverter: PayloadConverter): Error {
126
157
  if (failure.applicationFailureInfo) {
127
158
  return new ApplicationFailure(
128
159
  failure.message ?? undefined,
@@ -196,6 +227,41 @@ export class DefaultFailureConverter implements FailureConverter {
196
227
  this.optionalFailureToOptionalError(failure.cause, payloadConverter)
197
228
  );
198
229
  }
230
+ if (failure.nexusHandlerFailureInfo) {
231
+ let retryableOverride: boolean | undefined = undefined;
232
+ const retryBehavior = decodeNexusHandlerErrorRetryBehavior(failure.nexusHandlerFailureInfo.retryBehavior);
233
+ switch (retryBehavior) {
234
+ case 'RETRYABLE':
235
+ retryableOverride = true;
236
+ break;
237
+ case 'NON_RETRYABLE':
238
+ retryableOverride = false;
239
+ break;
240
+ }
241
+
242
+ return new nexus.HandlerError(
243
+ (failure.nexusHandlerFailureInfo.type as nexus.HandlerErrorType) ?? 'INTERNAL',
244
+ // TODO(nexus/error): Maybe set a default message here, once we've decided on error handling.
245
+ failure.message ?? undefined,
246
+ {
247
+ cause: this.optionalFailureToOptionalError(failure.cause, payloadConverter),
248
+ retryableOverride,
249
+ }
250
+ );
251
+ }
252
+ if (failure.nexusOperationExecutionFailureInfo) {
253
+ return new NexusOperationFailure(
254
+ // TODO(nexus/error): Maybe set a default message here, once we've decided on error handling.
255
+ failure.message ?? undefined,
256
+ failure.nexusOperationExecutionFailureInfo.scheduledEventId?.toNumber(),
257
+ // We assume these will always be set or gracefully set to empty strings.
258
+ failure.nexusOperationExecutionFailureInfo.endpoint ?? '',
259
+ failure.nexusOperationExecutionFailureInfo.service ?? '',
260
+ failure.nexusOperationExecutionFailureInfo.operation ?? '',
261
+ failure.nexusOperationExecutionFailureInfo.operationToken ?? undefined,
262
+ this.optionalFailureToOptionalError(failure.cause, payloadConverter)
263
+ );
264
+ }
199
265
  return new TemporalFailure(
200
266
  failure.message ?? undefined,
201
267
  this.optionalFailureToOptionalError(failure.cause, payloadConverter)
@@ -220,7 +286,9 @@ export class DefaultFailureConverter implements FailureConverter {
220
286
  }
221
287
  const err = this.failureToErrorInner(failure, payloadConverter);
222
288
  err.stack = failure.stackTrace ?? '';
223
- err.failure = failure;
289
+ if (err instanceof TemporalFailure) {
290
+ err.failure = failure;
291
+ }
224
292
  return err;
225
293
  }
226
294
 
@@ -236,8 +304,11 @@ export class DefaultFailureConverter implements FailureConverter {
236
304
  }
237
305
 
238
306
  errorToFailureInner(err: unknown, payloadConverter: PayloadConverter): ProtoFailure {
239
- if (err instanceof TemporalFailure) {
240
- if (err.failure) return err.failure;
307
+ // TODO(nexus/error): If we decide not to have a NexusHandlerFailure, we could still attach the
308
+ // failure proto to the Nexus HandlerError object, by using a private symbol
309
+ // property. To be considered once we have a decision on error handling.
310
+ if (err instanceof TemporalFailure || err instanceof nexus.HandlerError) {
311
+ if (err instanceof TemporalFailure && err.failure) return err.failure;
241
312
  const base = {
242
313
  message: err.message,
243
314
  stackTrace: cutoffStackTrace(err.stack),
@@ -315,6 +386,39 @@ export class DefaultFailureConverter implements FailureConverter {
315
386
  terminatedFailureInfo: {},
316
387
  };
317
388
  }
389
+ if (err instanceof nexus.HandlerError) {
390
+ let retryBehavior: temporal.api.enums.v1.NexusHandlerErrorRetryBehavior | undefined = undefined;
391
+ switch (err.retryableOverride) {
392
+ case true:
393
+ retryBehavior = encodeNexusHandlerErrorRetryBehavior('RETRYABLE');
394
+ break;
395
+ case false:
396
+ retryBehavior = encodeNexusHandlerErrorRetryBehavior('NON_RETRYABLE');
397
+ break;
398
+ }
399
+
400
+ return {
401
+ // TODO(nexus/error): Maybe set a default message here, once we've decided on error handling.
402
+ ...base,
403
+ nexusHandlerFailureInfo: {
404
+ type: err.type,
405
+ retryBehavior,
406
+ },
407
+ };
408
+ }
409
+ if (err instanceof NexusOperationFailure) {
410
+ return {
411
+ // TODO(nexus/error): Maybe set a default message here, once we've decided on error handling.
412
+ ...base,
413
+ nexusOperationExecutionFailureInfo: {
414
+ scheduledEventId: err.scheduledEventId ? Long.fromNumber(err.scheduledEventId) : undefined,
415
+ endpoint: err.endpoint,
416
+ service: err.service,
417
+ operation: err.operation,
418
+ operationToken: err.operationToken,
419
+ },
420
+ };
421
+ }
318
422
  // Just a TemporalFailure
319
423
  return base;
320
424
  }
package/src/failure.ts CHANGED
@@ -379,6 +379,28 @@ export class ChildWorkflowFailure extends TemporalFailure {
379
379
  }
380
380
  }
381
381
 
382
+ /**
383
+ * Thrown when a Nexus Operation executed inside a Workflow fails.
384
+ *
385
+ * @experimental Nexus support in Temporal SDK is experimental.
386
+ */
387
+ @SymbolBasedInstanceOfError('NexusOperationFailure')
388
+ export class NexusOperationFailure extends TemporalFailure {
389
+ public constructor(
390
+ message: string | undefined,
391
+ public readonly scheduledEventId: number | undefined,
392
+ public readonly endpoint: string,
393
+ public readonly service: string,
394
+ public readonly operation: string,
395
+ public readonly operationToken: string | undefined,
396
+ cause?: Error
397
+ ) {
398
+ super(message, cause);
399
+ }
400
+ }
401
+
402
+ // TODO(nexus/error): Maybe add a NexusHandlerFailure class here, once we've decided on error handling.
403
+
382
404
  /**
383
405
  * This exception is thrown in the following cases:
384
406
  * - Workflow with the same Workflow ID is currently running and the {@link WorkflowOptions.workflowIdConflictPolicy} is `WORKFLOW_ID_CONFLICT_POLICY_FAIL`
package/src/index.ts CHANGED
@@ -8,6 +8,7 @@ import * as encoding from './encoding';
8
8
  import * as helpers from './type-helpers';
9
9
 
10
10
  export * from './activity-options';
11
+ export { ActivityCancellationDetailsOptions, ActivityCancellationDetails } from './activity-cancellation-details';
11
12
  export * from './converter/data-converter';
12
13
  export * from './converter/failure-converter';
13
14
  export * from './converter/payload-codec';
@@ -1,9 +1,16 @@
1
+ import type { temporal } from '@temporalio/proto';
1
2
  import { Payload } from '../interfaces';
2
- import { arrayFromPayloads, fromPayloadsAtIndex, PayloadConverter, toPayloads } from '../converter/payload-converter';
3
+ import {
4
+ arrayFromPayloads,
5
+ convertOptionalToPayload,
6
+ fromPayloadsAtIndex,
7
+ toPayloads,
8
+ } from '../converter/payload-converter';
3
9
  import { PayloadConverterError } from '../errors';
4
10
  import { PayloadCodec } from '../converter/payload-codec';
5
11
  import { ProtoFailure } from '../failure';
6
12
  import { LoadedDataConverter } from '../converter/data-converter';
13
+ import { UserMetadata } from '../user-metadata';
7
14
  import { DecodedPayload, DecodedProtoFailure, EncodedPayload, EncodedProtoFailure } from './codec-types';
8
15
 
9
16
  /**
@@ -359,3 +366,32 @@ export function noopDecodeMap<K extends string>(
359
366
  ): Record<K, DecodedPayload> | null | undefined {
360
367
  return map as Record<K, DecodedPayload> | null | undefined;
361
368
  }
369
+
370
+ export async function encodeUserMetadata(
371
+ dataConverter: LoadedDataConverter,
372
+ staticSummary: string | undefined,
373
+ staticDetails: string | undefined
374
+ ): Promise<temporal.api.sdk.v1.IUserMetadata | undefined> {
375
+ if (staticSummary == null && staticDetails == null) return undefined;
376
+
377
+ const { payloadConverter, payloadCodecs } = dataConverter;
378
+ const summary = await encodeOptionalSingle(payloadCodecs, convertOptionalToPayload(payloadConverter, staticSummary));
379
+ const details = await encodeOptionalSingle(payloadCodecs, convertOptionalToPayload(payloadConverter, staticDetails));
380
+
381
+ if (summary == null && details == null) return undefined;
382
+
383
+ return { summary, details };
384
+ }
385
+
386
+ export async function decodeUserMetadata(
387
+ dataConverter: LoadedDataConverter,
388
+ metadata: temporal.api.sdk.v1.IUserMetadata | undefined | null
389
+ ): Promise<UserMetadata> {
390
+ const res = { staticSummary: undefined, staticDetails: undefined };
391
+ if (metadata == null) return res;
392
+
393
+ const staticSummary = (await decodeOptionalSinglePayload<string>(dataConverter, metadata.summary)) ?? undefined;
394
+ const staticDetails = (await decodeOptionalSinglePayload<string>(dataConverter, metadata.details)) ?? undefined;
395
+
396
+ return { staticSummary, staticDetails };
397
+ }
@@ -23,7 +23,7 @@ export type ReplaceNested<T, ToReplace, ReplaceWith> = T extends (...args: any[]
23
23
  ? T
24
24
  : [keyof T] extends [never]
25
25
  ? T
26
- : T extends Record<string, string> // Special exception for nexusHeader.
26
+ : T extends Record<string, string> // Special exception for Nexus Headers.
27
27
  ? T
28
28
  : T extends { [k: string]: ToReplace }
29
29
  ? {
package/src/logger.ts CHANGED
@@ -38,6 +38,12 @@ export enum SdkComponent {
38
38
  */
39
39
  activity = 'activity',
40
40
 
41
+ /**
42
+ * Component name for messages emited from a Nexus Operation Handler, using the Nexus context logger.
43
+ * The SDK itself never publishes messages with this component name.
44
+ */
45
+ nexus = 'nexus',
46
+
41
47
  /**
42
48
  * Component name for messages emited from a Temporal Worker instance.
43
49
  *
package/src/priority.ts CHANGED
@@ -11,7 +11,8 @@ import type { temporal } from '@temporalio/proto';
11
11
  * calling workflow, then use the default (documented on the field).
12
12
  * The overall semantics of Priority are:
13
13
  * 1. First, consider "priority_key": lower number goes first.
14
- * (more will be added here later)
14
+ * 2. Then, consider fairness: the fairness mechanism attempts to dispatch tasks for a given key in
15
+ * proportion to its weight.
15
16
  */
16
17
  export interface Priority {
17
18
  /**
@@ -26,13 +27,43 @@ export interface Priority {
26
27
  * The default priority is (min+max)/2. With the default max of 5 and min of 1, that comes out to 3.
27
28
  */
28
29
  priorityKey?: number;
30
+
31
+ /**
32
+ * FairnessKey is a short string that's used as a key for a fairness
33
+ * balancing mechanism. It may correspond to a tenant id, or to a fixed
34
+ * string like "high" or "low". The default is the empty string.
35
+ *
36
+ * The fairness mechanism attempts to dispatch tasks for a given key in
37
+ * proportion to its weight. For example, using a thousand distinct tenant
38
+ * ids, each with a weight of 1.0 (the default) will result in each tenant
39
+ * getting a roughly equal share of task dispatch throughput.
40
+ *
41
+ * Fairness keys are limited to 64 bytes.
42
+ */
43
+ fairnessKey?: string;
44
+
45
+ /**
46
+ * FairnessWeight for a task can come from multiple sources for
47
+ * flexibility. From highest to lowest precedence:
48
+ * 1. Weights for a small set of keys can be overridden in task queue
49
+ * configuration with an API.
50
+ * 2. It can be attached to the workflow/activity in this field.
51
+ * 3. The default weight of 1.0 will be used.
52
+ *
53
+ * Weight values are clamped to the range [0.001, 1000].
54
+ */
55
+ fairnessWeight?: number;
29
56
  }
30
57
 
31
58
  /**
32
59
  * Turn a proto compatible Priority into a TS Priority
33
60
  */
34
61
  export function decodePriority(priority?: temporal.api.common.v1.IPriority | null): Priority {
35
- return { priorityKey: priority?.priorityKey ?? undefined };
62
+ return {
63
+ priorityKey: priority?.priorityKey ?? undefined,
64
+ fairnessKey: priority?.fairnessKey ?? undefined,
65
+ fairnessWeight: priority?.fairnessWeight ?? undefined,
66
+ };
36
67
  }
37
68
 
38
69
  /**
@@ -50,5 +81,7 @@ export function compilePriority(priority: Priority): temporal.api.common.v1.IPri
50
81
 
51
82
  return {
52
83
  priorityKey: priority.priorityKey ?? 0,
84
+ fairnessKey: priority.fairnessKey ?? '',
85
+ fairnessWeight: priority.fairnessWeight ?? 0,
53
86
  };
54
87
  }