@temporalio/common 1.9.0 → 1.9.1

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.
@@ -4,8 +4,21 @@ export type Payload = temporal.api.common.v1.IPayload;
4
4
  export type WorkflowReturnType = Promise<any>;
5
5
  export type WorkflowUpdateType = (...args: any[]) => Promise<any> | any;
6
6
  export type WorkflowUpdateValidatorType = (...args: any[]) => void;
7
+ export type WorkflowUpdateAnnotatedType = {
8
+ handler: WorkflowUpdateType;
9
+ validator?: WorkflowUpdateValidatorType;
10
+ description?: string;
11
+ };
7
12
  export type WorkflowSignalType = (...args: any[]) => Promise<void> | void;
13
+ export type WorkflowSignalAnnotatedType = {
14
+ handler: WorkflowSignalType;
15
+ description?: string;
16
+ };
8
17
  export type WorkflowQueryType = (...args: any[]) => any;
18
+ export type WorkflowQueryAnnotatedType = {
19
+ handler: WorkflowQueryType;
20
+ description?: string;
21
+ };
9
22
  /**
10
23
  * Broad Workflow function definition, specific Workflows will typically use a narrower type definition, e.g:
11
24
  * ```ts
package/lib/otel.d.ts ADDED
@@ -0,0 +1,26 @@
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 ADDED
@@ -0,0 +1,87 @@
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"otel.js","sourceRoot":"","s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,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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@temporalio/common",
3
- "version": "1.9.0",
3
+ "version": "1.9.1",
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,7 +12,7 @@
12
12
  "author": "Temporal Technologies Inc. <sdk@temporal.io>",
13
13
  "license": "MIT",
14
14
  "dependencies": {
15
- "@temporalio/proto": "1.9.0",
15
+ "@temporalio/proto": "1.9.1",
16
16
  "long": "^5.2.3",
17
17
  "ms": "^3.0.0-canary.1",
18
18
  "proto3-json-serializer": "^2.0.0"
@@ -36,5 +36,5 @@
36
36
  "src",
37
37
  "lib"
38
38
  ],
39
- "gitHead": "5096976287616207edcd3e4281a2a5e1f7393e33"
39
+ "gitHead": "05f22004a0d877d8a128768016d5719adbc67de8"
40
40
  }
package/src/interfaces.ts CHANGED
@@ -6,8 +6,15 @@ export type Payload = temporal.api.common.v1.IPayload;
6
6
  export type WorkflowReturnType = Promise<any>;
7
7
  export type WorkflowUpdateType = (...args: any[]) => Promise<any> | any;
8
8
  export type WorkflowUpdateValidatorType = (...args: any[]) => void;
9
+ export type WorkflowUpdateAnnotatedType = {
10
+ handler: WorkflowUpdateType;
11
+ validator?: WorkflowUpdateValidatorType;
12
+ description?: string;
13
+ };
9
14
  export type WorkflowSignalType = (...args: any[]) => Promise<void> | void;
15
+ export type WorkflowSignalAnnotatedType = { handler: WorkflowSignalType; description?: string };
10
16
  export type WorkflowQueryType = (...args: any[]) => any;
17
+ export type WorkflowQueryAnnotatedType = { handler: WorkflowQueryType; description?: string };
11
18
 
12
19
  /**
13
20
  * Broad Workflow function definition, specific Workflows will typically use a narrower type definition, e.g: