@temporalio/common 1.8.6 → 1.9.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 (50) hide show
  1. package/lib/activity-options.d.ts +2 -0
  2. package/lib/activity-options.js +1 -1
  3. package/lib/activity-options.js.map +1 -1
  4. package/lib/converter/failure-converter.js +24 -14
  5. package/lib/converter/failure-converter.js.map +1 -1
  6. package/lib/converter/payload-converter.js.map +1 -1
  7. package/lib/converter/protobuf-payload-converters.js +4 -2
  8. package/lib/converter/protobuf-payload-converters.js.map +1 -1
  9. package/lib/encoding.js.map +1 -1
  10. package/lib/errors.js +12 -12
  11. package/lib/errors.js.map +1 -1
  12. package/lib/failure.js +18 -18
  13. package/lib/failure.js.map +1 -1
  14. package/lib/interceptors.d.ts +4 -1
  15. package/lib/interceptors.js +5 -2
  16. package/lib/interceptors.js.map +1 -1
  17. package/lib/interfaces.d.ts +25 -3
  18. package/lib/internal-non-workflow/codec-helpers.js.map +1 -1
  19. package/lib/internal-non-workflow/data-converter-helpers.js.map +1 -1
  20. package/lib/internal-non-workflow/tls-config.d.ts +5 -3
  21. package/lib/internal-non-workflow/tls-config.js.map +1 -1
  22. package/lib/proto-utils.js.map +1 -1
  23. package/lib/retry-policy.js.map +1 -1
  24. package/lib/time.js.map +1 -1
  25. package/lib/type-helpers.d.ts +1 -0
  26. package/lib/type-helpers.js +23 -1
  27. package/lib/type-helpers.js.map +1 -1
  28. package/lib/versioning-intent-enum.js +1 -1
  29. package/lib/versioning-intent-enum.js.map +1 -1
  30. package/lib/versioning-intent.d.ts +8 -10
  31. package/lib/workflow-options.d.ts +0 -8
  32. package/lib/workflow-options.js +2 -13
  33. package/lib/workflow-options.js.map +1 -1
  34. package/package.json +7 -6
  35. package/src/activity-options.ts +2 -0
  36. package/src/converter/failure-converter.ts +21 -8
  37. package/src/converter/protobuf-payload-converters.ts +4 -2
  38. package/src/errors.ts +14 -3
  39. package/src/failure.ts +14 -3
  40. package/src/interceptors.ts +5 -2
  41. package/src/interfaces.ts +27 -3
  42. package/src/internal-non-workflow/codec-types.ts +10 -10
  43. package/src/internal-non-workflow/tls-config.ts +5 -3
  44. package/src/type-helpers.ts +23 -0
  45. package/src/versioning-intent.ts +8 -10
  46. package/src/workflow-options.ts +3 -23
  47. package/lib/otel.d.ts +0 -26
  48. package/lib/otel.js +0 -87
  49. package/lib/otel.js.map +0 -1
  50. package/src/otel.ts +0 -63
@@ -140,3 +140,26 @@ export function SymbolBasedInstanceOfError<E extends Error>(markerName: string):
140
140
  });
141
141
  };
142
142
  }
143
+
144
+ // Thanks MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze
145
+ export function deepFreeze<T>(object: T): T {
146
+ // Retrieve the property names defined on object
147
+ const propNames = Object.getOwnPropertyNames(object);
148
+
149
+ // Freeze properties before freezing self
150
+ for (const name of propNames) {
151
+ const value = (object as any)[name];
152
+
153
+ if (value && typeof value === 'object') {
154
+ try {
155
+ deepFreeze(value);
156
+ } catch (err) {
157
+ // This is okay, there are some typed arrays that cannot be frozen (encodingKeys)
158
+ }
159
+ } else if (typeof value === 'function') {
160
+ Object.freeze(value);
161
+ }
162
+ }
163
+
164
+ return Object.freeze(object);
165
+ }
@@ -1,17 +1,15 @@
1
1
  /**
2
- * Indicates whether the user intends certain commands to be run on a compatible worker Build Id
3
- * version or not.
2
+ * Indicates whether the user intends certain commands to be run on a compatible worker Build Id version or not.
4
3
  *
5
- * `COMPATIBLE` indicates that the command should run on a worker with compatible version if
6
- * possible. It may not be possible if the target task queue does not also have knowledge of the
7
- * current worker's Build Id.
4
+ * `COMPATIBLE` indicates that the command should run on a worker with compatible version if possible. It may not be
5
+ * possible if the target task queue does not also have knowledge of the current worker's Build Id.
8
6
  *
9
- * `DEFAULT` indicates that the command should run on the target task queue's current
10
- * overall-default Build Id.
7
+ * `DEFAULT` indicates that the command should run on the target task queue's current overall-default Build Id.
11
8
  *
12
- * Where this type is accepted optionally, an unset value indicates that the SDK should choose the
13
- * most sensible default behavior for the type of command, accounting for whether the command will
14
- * be run on the same task queue as the current worker.
9
+ * Where this type is accepted optionally, an unset value indicates that the SDK should choose the most sensible default
10
+ * behavior for the type of command, accounting for whether the command will be run on the same task queue as the
11
+ * current worker. The default behavior for starting Workflows is `DEFAULT`. The default behavior for Workflows starting
12
+ * Activities, starting Child Workflows, or Continuing As New is `COMPATIBLE`.
15
13
  *
16
14
  * @experimental
17
15
  */
@@ -1,8 +1,8 @@
1
- import type { temporal, google } from '@temporalio/proto';
1
+ import type { temporal } from '@temporalio/proto';
2
2
  import { SearchAttributes, Workflow } from './interfaces';
3
3
  import { RetryPolicy } from './retry-policy';
4
- import { Duration, msOptionalToTs } from './time';
5
- import { checkExtends, Replace } from './type-helpers';
4
+ import { Duration } from './time';
5
+ import { checkExtends } from './type-helpers';
6
6
 
7
7
  // Avoid importing the proto implementation to reduce workflow bundle size
8
8
  // Copied from temporal.api.enums.v1.WorkflowIdReusePolicy
@@ -135,26 +135,6 @@ export interface WorkflowDurationOptions {
135
135
 
136
136
  export type CommonWorkflowOptions = BaseWorkflowOptions & WorkflowDurationOptions;
137
137
 
138
- export type WithCompiledWorkflowOptions<T extends CommonWorkflowOptions> = Replace<
139
- T,
140
- {
141
- workflowExecutionTimeout?: google.protobuf.IDuration;
142
- workflowRunTimeout?: google.protobuf.IDuration;
143
- workflowTaskTimeout?: google.protobuf.IDuration;
144
- }
145
- >;
146
-
147
- export function compileWorkflowOptions<T extends CommonWorkflowOptions>(options: T): WithCompiledWorkflowOptions<T> {
148
- const { workflowExecutionTimeout, workflowRunTimeout, workflowTaskTimeout, ...rest } = options;
149
-
150
- return {
151
- ...rest,
152
- workflowExecutionTimeout: msOptionalToTs(workflowExecutionTimeout),
153
- workflowRunTimeout: msOptionalToTs(workflowRunTimeout),
154
- workflowTaskTimeout: msOptionalToTs(workflowTaskTimeout),
155
- };
156
- }
157
-
158
138
  export function extractWorkflowType<T extends Workflow>(workflowTypeOrFunc: string | T): string {
159
139
  if (typeof workflowTypeOrFunc === 'string') return workflowTypeOrFunc as string;
160
140
  if (typeof workflowTypeOrFunc === 'function') {
package/lib/otel.d.ts DELETED
@@ -1,26 +0,0 @@
1
- import * as otel from '@opentelemetry/api';
2
- import { Headers } from './interceptors';
3
- /** Default trace header for opentelemetry interceptors */
4
- export declare const TRACE_HEADER = "_tracer-data";
5
- /** As in workflow run id */
6
- export declare const RUN_ID_ATTR_KEY = "run_id";
7
- /** For a workflow or activity task */
8
- export declare const TASK_TOKEN_ATTR_KEY = "task_token";
9
- /** Number of jobs in a workflow activation */
10
- export declare const NUM_JOBS_ATTR_KEY = "num_jobs";
11
- /**
12
- * If found, return an otel Context deserialized from the provided headers
13
- */
14
- export declare function extractContextFromHeaders(headers: Headers): Promise<otel.Context | undefined>;
15
- /**
16
- * If found, return an otel SpanContext deserialized from the provided headers
17
- */
18
- export declare function extractSpanContextFromHeaders(headers: Headers): Promise<otel.SpanContext | undefined>;
19
- /**
20
- * Given headers, return new headers with the current otel context inserted
21
- */
22
- export declare function headersWithContext(headers: Headers): Promise<Headers>;
23
- /**
24
- * Link a span to an maybe-existing span context
25
- */
26
- export declare function linkSpans(fromSpan: otel.Span, toContext?: otel.SpanContext): void;
package/lib/otel.js DELETED
@@ -1,87 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.linkSpans = exports.headersWithContext = exports.extractSpanContextFromHeaders = exports.extractContextFromHeaders = exports.NUM_JOBS_ATTR_KEY = exports.TASK_TOKEN_ATTR_KEY = exports.RUN_ID_ATTR_KEY = exports.TRACE_HEADER = void 0;
27
- const otel = __importStar(require("@opentelemetry/api"));
28
- const payload_converter_1 = require("./converter/payload-converter");
29
- /** Default trace header for opentelemetry interceptors */
30
- exports.TRACE_HEADER = '_tracer-data';
31
- /** As in workflow run id */
32
- exports.RUN_ID_ATTR_KEY = 'run_id';
33
- /** For a workflow or activity task */
34
- exports.TASK_TOKEN_ATTR_KEY = 'task_token';
35
- /** Number of jobs in a workflow activation */
36
- exports.NUM_JOBS_ATTR_KEY = 'num_jobs';
37
- const payloadConverter = payload_converter_1.defaultPayloadConverter;
38
- /**
39
- * If found, return an otel Context deserialized from the provided headers
40
- */
41
- async function extractContextFromHeaders(headers) {
42
- const encodedSpanContext = headers[exports.TRACE_HEADER];
43
- if (encodedSpanContext === undefined) {
44
- return undefined;
45
- }
46
- const textMap = payloadConverter.fromPayload(encodedSpanContext);
47
- return otel.propagation.extract(otel.context.active(), textMap, otel.defaultTextMapGetter);
48
- }
49
- exports.extractContextFromHeaders = extractContextFromHeaders;
50
- /**
51
- * If found, return an otel SpanContext deserialized from the provided headers
52
- */
53
- async function extractSpanContextFromHeaders(headers) {
54
- const context = await extractContextFromHeaders(headers);
55
- if (context === undefined) {
56
- return undefined;
57
- }
58
- return otel.trace.getSpanContext(context);
59
- }
60
- exports.extractSpanContextFromHeaders = extractSpanContextFromHeaders;
61
- /**
62
- * Given headers, return new headers with the current otel context inserted
63
- */
64
- async function headersWithContext(headers) {
65
- const carrier = {};
66
- otel.propagation.inject(otel.context.active(), carrier, otel.defaultTextMapSetter);
67
- return { ...headers, [exports.TRACE_HEADER]: payloadConverter.toPayload(carrier) };
68
- }
69
- exports.headersWithContext = headersWithContext;
70
- /**
71
- * Link a span to an maybe-existing span context
72
- */
73
- function linkSpans(fromSpan, toContext) {
74
- if (toContext !== undefined) {
75
- // TODO: I have to go around typescript because otel api 😢
76
- // See https://github.com/open-telemetry/opentelemetry-js-api/issues/124
77
- const links = fromSpan.links;
78
- if (links === undefined) {
79
- fromSpan.links = [{ context: toContext }];
80
- }
81
- else {
82
- links.push({ context: toContext });
83
- }
84
- }
85
- }
86
- exports.linkSpans = linkSpans;
87
- //# sourceMappingURL=otel.js.map
package/lib/otel.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"otel.js","sourceRoot":"","sources":["../src/otel.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yDAA2C;AAE3C,qEAAwE;AAExE,0DAA0D;AAC7C,QAAA,YAAY,GAAG,cAAc,CAAC;AAC3C,4BAA4B;AACf,QAAA,eAAe,GAAG,QAAQ,CAAC;AACxC,sCAAsC;AACzB,QAAA,mBAAmB,GAAG,YAAY,CAAC;AAChD,8CAA8C;AACjC,QAAA,iBAAiB,GAAG,UAAU,CAAC;AAE5C,MAAM,gBAAgB,GAAG,2CAAuB,CAAC;AAEjD;;GAEG;AACI,KAAK,UAAU,yBAAyB,CAAC,OAAgB;IAC9D,MAAM,kBAAkB,GAAG,OAAO,CAAC,oBAAY,CAAC,CAAC;IACjD,IAAI,kBAAkB,KAAK,SAAS,EAAE;QACpC,OAAO,SAAS,CAAC;KAClB;IACD,MAAM,OAAO,GAA2B,gBAAgB,CAAC,WAAW,CAAC,kBAAkB,CAAC,CAAC;IACzF,OAAO,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,oBAAoB,CAAC,CAAC;AAC7F,CAAC;AAPD,8DAOC;AAED;;GAEG;AACI,KAAK,UAAU,6BAA6B,CAAC,OAAgB;IAClE,MAAM,OAAO,GAAG,MAAM,yBAAyB,CAAC,OAAO,CAAC,CAAC;IACzD,IAAI,OAAO,KAAK,SAAS,EAAE;QACzB,OAAO,SAAS,CAAC;KAClB;IAED,OAAO,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;AAC5C,CAAC;AAPD,sEAOC;AAED;;GAEG;AACI,KAAK,UAAU,kBAAkB,CAAC,OAAgB;IACvD,MAAM,OAAO,GAAG,EAAE,CAAC;IACnB,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,oBAAoB,CAAC,CAAC;IACnF,OAAO,EAAE,GAAG,OAAO,EAAE,CAAC,oBAAY,CAAC,EAAE,gBAAgB,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;AAC7E,CAAC;AAJD,gDAIC;AAED;;GAEG;AACH,SAAgB,SAAS,CAAC,QAAmB,EAAE,SAA4B;IACzE,IAAI,SAAS,KAAK,SAAS,EAAE;QAC3B,2DAA2D;QAC3D,yEAAyE;QACzE,MAAM,KAAK,GAAI,QAAgB,CAAC,KAAK,CAAC;QACtC,IAAI,KAAK,KAAK,SAAS,EAAE;YACtB,QAAgB,CAAC,KAAK,GAAG,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC;SACpD;aAAM;YACL,KAAK,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC;SACpC;KACF;AACH,CAAC;AAXD,8BAWC"}
package/src/otel.ts DELETED
@@ -1,63 +0,0 @@
1
- import * as otel from '@opentelemetry/api';
2
- import { Headers } from './interceptors';
3
- import { defaultPayloadConverter } from './converter/payload-converter';
4
-
5
- /** Default trace header for opentelemetry interceptors */
6
- export const TRACE_HEADER = '_tracer-data';
7
- /** As in workflow run id */
8
- export const RUN_ID_ATTR_KEY = 'run_id';
9
- /** For a workflow or activity task */
10
- export const TASK_TOKEN_ATTR_KEY = 'task_token';
11
- /** Number of jobs in a workflow activation */
12
- export const NUM_JOBS_ATTR_KEY = 'num_jobs';
13
-
14
- const payloadConverter = defaultPayloadConverter;
15
-
16
- /**
17
- * If found, return an otel Context deserialized from the provided headers
18
- */
19
- export async function extractContextFromHeaders(headers: Headers): Promise<otel.Context | undefined> {
20
- const encodedSpanContext = headers[TRACE_HEADER];
21
- if (encodedSpanContext === undefined) {
22
- return undefined;
23
- }
24
- const textMap: Record<string, string> = payloadConverter.fromPayload(encodedSpanContext);
25
- return otel.propagation.extract(otel.context.active(), textMap, otel.defaultTextMapGetter);
26
- }
27
-
28
- /**
29
- * If found, return an otel SpanContext deserialized from the provided headers
30
- */
31
- export async function extractSpanContextFromHeaders(headers: Headers): Promise<otel.SpanContext | undefined> {
32
- const context = await extractContextFromHeaders(headers);
33
- if (context === undefined) {
34
- return undefined;
35
- }
36
-
37
- return otel.trace.getSpanContext(context);
38
- }
39
-
40
- /**
41
- * Given headers, return new headers with the current otel context inserted
42
- */
43
- export async function headersWithContext(headers: Headers): Promise<Headers> {
44
- const carrier = {};
45
- otel.propagation.inject(otel.context.active(), carrier, otel.defaultTextMapSetter);
46
- return { ...headers, [TRACE_HEADER]: payloadConverter.toPayload(carrier) };
47
- }
48
-
49
- /**
50
- * Link a span to an maybe-existing span context
51
- */
52
- export function linkSpans(fromSpan: otel.Span, toContext?: otel.SpanContext): void {
53
- if (toContext !== undefined) {
54
- // TODO: I have to go around typescript because otel api 😢
55
- // See https://github.com/open-telemetry/opentelemetry-js-api/issues/124
56
- const links = (fromSpan as any).links;
57
- if (links === undefined) {
58
- (fromSpan as any).links = [{ context: toContext }];
59
- } else {
60
- links.push({ context: toContext });
61
- }
62
- }
63
- }