@temporalio/common
Advanced tools
Comparing version 1.4.4 to 1.5.0
@@ -36,6 +36,11 @@ import type { coresdk } from '@temporalio/proto'; | ||
/** | ||
* Maximum time of a single Activity execution attempt. | ||
Note that the Temporal Server doesn't detect Worker process failures directly. It relies on this timeout to detect that an Activity that didn't complete on time. So this timeout should be as short as the longest possible execution of the Activity body. Potentially long running Activities must specify {@link heartbeatTimeout} and call {@link activity.Context.heartbeat} periodically for timely failure detection. | ||
* Maximum time of a single Activity execution attempt. Note that the Temporal Server doesn't detect Worker process | ||
* failures directly. It relies on this timeout to detect that an Activity that didn't complete on time. So this | ||
* timeout should be as short as the longest possible execution of the Activity body. Potentially long running | ||
* Activities must specify {@link heartbeatTimeout} and call {@link activity.Context.heartbeat} periodically for | ||
* timely failure detection. | ||
* | ||
* Either this option or {@link scheduleToCloseTimeout} is required. | ||
* | ||
* @default `scheduleToCloseTimeout` or unlimited | ||
* @format number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string} | ||
@@ -47,3 +52,4 @@ */ | ||
* `scheduleToStartTimeout` is always non-retryable. Retrying after this timeout doesn't make sense as it would just put the Activity Task back into the same Task Queue. | ||
* @default unlimited | ||
* | ||
* @default `scheduleToCloseTimeout` or unlimited | ||
* @format number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string} | ||
@@ -56,3 +62,4 @@ */ | ||
* | ||
* Either this option or {@link startToCloseTimeout} is required | ||
* Either this option or {@link startToCloseTimeout} is required. | ||
* | ||
* @default unlimited | ||
@@ -59,0 +66,0 @@ * @format number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string} |
@@ -8,6 +8,6 @@ import { ProtoFailure, TemporalFailure } from '../failure'; | ||
/** | ||
* A `FailureConverter` is responsible to convert from proto `Failure` instances to JS `Errors` and back. | ||
* A `FailureConverter` is responsible for converting from proto `Failure` instances to JS `Errors` and back. | ||
* | ||
* It is recommended to use the {@link DefaultFailureConverter} and not attempt to customize the default implementation | ||
* in order to maintain cross language failure serialization compatibility. | ||
* We recommended using the {@link DefaultFailureConverter} instead of customizing the default implementation in order | ||
* to maintain cross-language Failure serialization compatibility. | ||
* | ||
@@ -20,7 +20,7 @@ * @experimental | ||
*/ | ||
errorToFailure(err: unknown): ProtoFailure; | ||
errorToFailure(err: unknown, payloadConverter: PayloadConverter): ProtoFailure; | ||
/** | ||
* Converts a Failure proto message to a JS Error object. | ||
*/ | ||
failureToError(err: ProtoFailure): TemporalFailure; | ||
failureToError(err: ProtoFailure, payloadConverter: PayloadConverter): Error; | ||
} | ||
@@ -40,6 +40,2 @@ /** | ||
/** | ||
* The {@link PayloadConverter} to use for converting failure attributes. | ||
*/ | ||
payloadConverter: PayloadConverter; | ||
/** | ||
* Whether to encode error messages and stack traces (for encrypting these attributes use a {@link PayloadCodec}). | ||
@@ -50,7 +46,8 @@ */ | ||
/** | ||
* Default cross language compatible failure converter. | ||
* Default, cross-language-compatible Failure converter. | ||
* | ||
* By default, it will leave error messages and stack traces as plain text. In order to encrypt those, set | ||
* `encodeCommonAttributes` to `true` in the constructor options and make sure to use a {@link PayloadCodec} that can | ||
* encrypt / decrypt payloads in your Worker and Client options. | ||
* By default, it will leave error messages and stack traces as plain text. In order to encrypt them, set | ||
* `encodeCommonAttributes` to `true` in the constructor options and use a {@link PayloadCodec} that can encrypt / | ||
* decrypt Payloads in your {@link WorkerOptions.dataConverter | Worker} and | ||
* {@link ClientOptions.dataConverter | Client options}. | ||
* | ||
@@ -67,14 +64,14 @@ * @experimental | ||
*/ | ||
failureToErrorInner(failure: ProtoFailure): TemporalFailure; | ||
failureToError(failure: ProtoFailure): TemporalFailure; | ||
errorToFailure(err: unknown): ProtoFailure; | ||
errorToFailureInner(err: unknown): ProtoFailure; | ||
failureToErrorInner(failure: ProtoFailure, payloadConverter: PayloadConverter): TemporalFailure; | ||
failureToError(failure: ProtoFailure, payloadConverter: PayloadConverter): Error; | ||
errorToFailure(err: unknown, payloadConverter: PayloadConverter): ProtoFailure; | ||
errorToFailureInner(err: unknown, payloadConverter: PayloadConverter): ProtoFailure; | ||
/** | ||
* Converts a Failure proto message to a JS Error object if defined or returns undefined. | ||
*/ | ||
optionalFailureToOptionalError(failure: ProtoFailure | undefined | null): TemporalFailure | undefined; | ||
optionalFailureToOptionalError(failure: ProtoFailure | undefined | null, payloadConverter: PayloadConverter): Error | undefined; | ||
/** | ||
* Converts an error to a Failure proto message if defined or returns undefined | ||
*/ | ||
optionalErrorToOptionalFailure(err: unknown): ProtoFailure | undefined; | ||
optionalErrorToOptionalFailure(err: unknown, payloadConverter: PayloadConverter): ProtoFailure | undefined; | ||
} |
@@ -35,7 +35,8 @@ "use strict"; | ||
/** | ||
* Default cross language compatible failure converter. | ||
* Default, cross-language-compatible Failure converter. | ||
* | ||
* By default, it will leave error messages and stack traces as plain text. In order to encrypt those, set | ||
* `encodeCommonAttributes` to `true` in the constructor options and make sure to use a {@link PayloadCodec} that can | ||
* encrypt / decrypt payloads in your Worker and Client options. | ||
* By default, it will leave error messages and stack traces as plain text. In order to encrypt them, set | ||
* `encodeCommonAttributes` to `true` in the constructor options and use a {@link PayloadCodec} that can encrypt / | ||
* decrypt Payloads in your {@link WorkerOptions.dataConverter | Worker} and | ||
* {@link ClientOptions.dataConverter | Client options}. | ||
* | ||
@@ -46,6 +47,5 @@ * @experimental | ||
constructor(options) { | ||
const { encodeCommonAttributes, payloadConverter } = options ?? {}; | ||
const { encodeCommonAttributes } = options ?? {}; | ||
this.options = { | ||
encodeCommonAttributes: encodeCommonAttributes ?? false, | ||
payloadConverter: payloadConverter ?? payload_converter_1.defaultPayloadConverter, | ||
}; | ||
@@ -58,20 +58,20 @@ } | ||
*/ | ||
failureToErrorInner(failure) { | ||
failureToErrorInner(failure, payloadConverter) { | ||
if (failure.applicationFailureInfo) { | ||
return new failure_1.ApplicationFailure(failure.message ?? undefined, failure.applicationFailureInfo.type, Boolean(failure.applicationFailureInfo.nonRetryable), (0, payload_converter_1.arrayFromPayloads)(this.options.payloadConverter, failure.applicationFailureInfo.details?.payloads), this.optionalFailureToOptionalError(failure.cause)); | ||
return new failure_1.ApplicationFailure(failure.message ?? undefined, failure.applicationFailureInfo.type, Boolean(failure.applicationFailureInfo.nonRetryable), (0, payload_converter_1.arrayFromPayloads)(payloadConverter, failure.applicationFailureInfo.details?.payloads), this.optionalFailureToOptionalError(failure.cause, payloadConverter)); | ||
} | ||
if (failure.serverFailureInfo) { | ||
return new failure_1.ServerFailure(failure.message ?? undefined, Boolean(failure.serverFailureInfo.nonRetryable), this.optionalFailureToOptionalError(failure.cause)); | ||
return new failure_1.ServerFailure(failure.message ?? undefined, Boolean(failure.serverFailureInfo.nonRetryable), this.optionalFailureToOptionalError(failure.cause, payloadConverter)); | ||
} | ||
if (failure.timeoutFailureInfo) { | ||
return new failure_1.TimeoutFailure(failure.message ?? undefined, (0, payload_converter_1.fromPayloadsAtIndex)(this.options.payloadConverter, 0, failure.timeoutFailureInfo.lastHeartbeatDetails?.payloads), failure.timeoutFailureInfo.timeoutType ?? failure_1.TimeoutType.TIMEOUT_TYPE_UNSPECIFIED); | ||
return new failure_1.TimeoutFailure(failure.message ?? undefined, (0, payload_converter_1.fromPayloadsAtIndex)(payloadConverter, 0, failure.timeoutFailureInfo.lastHeartbeatDetails?.payloads), failure.timeoutFailureInfo.timeoutType ?? failure_1.TimeoutType.TIMEOUT_TYPE_UNSPECIFIED); | ||
} | ||
if (failure.terminatedFailureInfo) { | ||
return new failure_1.TerminatedFailure(failure.message ?? undefined, this.optionalFailureToOptionalError(failure.cause)); | ||
return new failure_1.TerminatedFailure(failure.message ?? undefined, this.optionalFailureToOptionalError(failure.cause, payloadConverter)); | ||
} | ||
if (failure.canceledFailureInfo) { | ||
return new failure_1.CancelledFailure(failure.message ?? undefined, (0, payload_converter_1.arrayFromPayloads)(this.options.payloadConverter, failure.canceledFailureInfo.details?.payloads), this.optionalFailureToOptionalError(failure.cause)); | ||
return new failure_1.CancelledFailure(failure.message ?? undefined, (0, payload_converter_1.arrayFromPayloads)(payloadConverter, failure.canceledFailureInfo.details?.payloads), this.optionalFailureToOptionalError(failure.cause, payloadConverter)); | ||
} | ||
if (failure.resetWorkflowFailureInfo) { | ||
return new failure_1.ApplicationFailure(failure.message ?? undefined, 'ResetWorkflow', false, (0, payload_converter_1.arrayFromPayloads)(this.options.payloadConverter, failure.resetWorkflowFailureInfo.lastHeartbeatDetails?.payloads), this.optionalFailureToOptionalError(failure.cause)); | ||
return new failure_1.ApplicationFailure(failure.message ?? undefined, 'ResetWorkflow', false, (0, payload_converter_1.arrayFromPayloads)(payloadConverter, failure.resetWorkflowFailureInfo.lastHeartbeatDetails?.payloads), this.optionalFailureToOptionalError(failure.cause, payloadConverter)); | ||
} | ||
@@ -83,3 +83,3 @@ if (failure.childWorkflowExecutionFailureInfo) { | ||
} | ||
return new failure_1.ChildWorkflowFailure(namespace ?? undefined, workflowExecution, workflowType.name, retryState ?? failure_1.RetryState.RETRY_STATE_UNSPECIFIED, this.optionalFailureToOptionalError(failure.cause)); | ||
return new failure_1.ChildWorkflowFailure(namespace ?? undefined, workflowExecution, workflowType.name, retryState ?? failure_1.RetryState.RETRY_STATE_UNSPECIFIED, this.optionalFailureToOptionalError(failure.cause, payloadConverter)); | ||
} | ||
@@ -90,9 +90,9 @@ if (failure.activityFailureInfo) { | ||
} | ||
return new failure_1.ActivityFailure(failure.activityFailureInfo.activityType.name, failure.activityFailureInfo.activityId ?? undefined, failure.activityFailureInfo.retryState ?? failure_1.RetryState.RETRY_STATE_UNSPECIFIED, failure.activityFailureInfo.identity ?? undefined, this.optionalFailureToOptionalError(failure.cause)); | ||
return new failure_1.ActivityFailure(failure.activityFailureInfo.activityType.name, failure.activityFailureInfo.activityId ?? undefined, failure.activityFailureInfo.retryState ?? failure_1.RetryState.RETRY_STATE_UNSPECIFIED, failure.activityFailureInfo.identity ?? undefined, this.optionalFailureToOptionalError(failure.cause, payloadConverter)); | ||
} | ||
return new failure_1.TemporalFailure(failure.message ?? undefined, this.optionalFailureToOptionalError(failure.cause)); | ||
return new failure_1.TemporalFailure(failure.message ?? undefined, this.optionalFailureToOptionalError(failure.cause, payloadConverter)); | ||
} | ||
failureToError(failure) { | ||
failureToError(failure, payloadConverter) { | ||
if (failure.encodedAttributes) { | ||
const attrs = this.options.payloadConverter.fromPayload(failure.encodedAttributes); | ||
const attrs = payloadConverter.fromPayload(failure.encodedAttributes); | ||
// Don't apply encodedAttributes unless they conform to an expected schema | ||
@@ -111,3 +111,3 @@ if (typeof attrs === 'object' && attrs !== null) { | ||
} | ||
const err = this.failureToErrorInner(failure); | ||
const err = this.failureToErrorInner(failure, payloadConverter); | ||
err.stack = failure.stackTrace ?? ''; | ||
@@ -117,4 +117,4 @@ err.failure = failure; | ||
} | ||
errorToFailure(err) { | ||
const failure = this.errorToFailureInner(err); | ||
errorToFailure(err, payloadConverter) { | ||
const failure = this.errorToFailureInner(err, payloadConverter); | ||
if (this.options.encodeCommonAttributes) { | ||
@@ -124,7 +124,7 @@ const { message, stackTrace } = failure; | ||
failure.stackTrace = ''; | ||
failure.encodedAttributes = this.options.payloadConverter.toPayload({ message, stack_trace: stackTrace }); | ||
failure.encodedAttributes = payloadConverter.toPayload({ message, stack_trace: stackTrace }); | ||
} | ||
return failure; | ||
} | ||
errorToFailureInner(err) { | ||
errorToFailureInner(err, payloadConverter) { | ||
if (err instanceof failure_1.TemporalFailure) { | ||
@@ -136,3 +136,3 @@ if (err.failure) | ||
stackTrace: cutoffStackTrace(err.stack), | ||
cause: this.optionalErrorToOptionalFailure(err.cause), | ||
cause: this.optionalErrorToOptionalFailure(err.cause, payloadConverter), | ||
source: failure_1.FAILURE_SOURCE, | ||
@@ -166,3 +166,3 @@ }; | ||
details: err.details && err.details.length | ||
? { payloads: (0, payload_converter_1.toPayloads)(this.options.payloadConverter, ...err.details) } | ||
? { payloads: (0, payload_converter_1.toPayloads)(payloadConverter, ...err.details) } | ||
: undefined, | ||
@@ -177,3 +177,3 @@ }, | ||
details: err.details && err.details.length | ||
? { payloads: (0, payload_converter_1.toPayloads)(this.options.payloadConverter, ...err.details) } | ||
? { payloads: (0, payload_converter_1.toPayloads)(payloadConverter, ...err.details) } | ||
: undefined, | ||
@@ -189,3 +189,3 @@ }, | ||
lastHeartbeatDetails: err.lastHeartbeatDetails | ||
? { payloads: (0, payload_converter_1.toPayloads)(this.options.payloadConverter, err.lastHeartbeatDetails) } | ||
? { payloads: (0, payload_converter_1.toPayloads)(payloadConverter, err.lastHeartbeatDetails) } | ||
: undefined, | ||
@@ -218,3 +218,3 @@ }, | ||
stackTrace: cutoffStackTrace(String(err.stack)), | ||
cause: this.optionalErrorToOptionalFailure(err.cause), | ||
cause: this.optionalErrorToOptionalFailure(err.cause, payloadConverter), | ||
}; | ||
@@ -241,4 +241,4 @@ } | ||
*/ | ||
optionalFailureToOptionalError(failure) { | ||
return failure ? this.failureToError(failure) : undefined; | ||
optionalFailureToOptionalError(failure, payloadConverter) { | ||
return failure ? this.failureToError(failure, payloadConverter) : undefined; | ||
} | ||
@@ -248,4 +248,4 @@ /** | ||
*/ | ||
optionalErrorToOptionalFailure(err) { | ||
return err ? this.errorToFailure(err) : undefined; | ||
optionalErrorToOptionalFailure(err, payloadConverter) { | ||
return err ? this.errorToFailure(err, payloadConverter) : undefined; | ||
} | ||
@@ -252,0 +252,0 @@ } |
@@ -6,3 +6,2 @@ /** | ||
*/ | ||
export { Headers, Next } from './interceptors'; | ||
export * from './activity-options'; | ||
@@ -14,11 +13,11 @@ export * from './converter/data-converter'; | ||
export * from './converter/types'; | ||
export * from './deprecated-time'; | ||
export * from './errors'; | ||
export * from './failure'; | ||
export * from './failure'; | ||
export { Headers, Next } from './interceptors'; | ||
export * from './interfaces'; | ||
export * from './retry-policy'; | ||
export { Timestamp } from './time'; | ||
export * from './workflow-handle'; | ||
export * from './workflow-options'; | ||
export * from './workflow-handle'; | ||
export * from './deprecated-time'; | ||
/** | ||
@@ -25,0 +24,0 @@ * Encode a UTF-8 string into a Uint8Array |
"use strict"; | ||
/** | ||
* Common library for code that's used across the Client, Worker, and/or Workflow | ||
* | ||
* @module | ||
*/ | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
@@ -18,5 +23,2 @@ if (k2 === undefined) k2 = k; | ||
}); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
@@ -29,4 +31,9 @@ if (mod && mod.__esModule) return mod; | ||
}; | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.errorCode = exports.errorMessage = exports.str = exports.u8 = void 0; | ||
const encoding = __importStar(require("./encoding")); | ||
const helpers = __importStar(require("./type-helpers")); | ||
__exportStar(require("./activity-options"), exports); | ||
@@ -38,12 +45,9 @@ __exportStar(require("./converter/data-converter"), exports); | ||
__exportStar(require("./converter/types"), exports); | ||
__exportStar(require("./deprecated-time"), exports); | ||
__exportStar(require("./errors"), exports); | ||
__exportStar(require("./failure"), exports); | ||
__exportStar(require("./failure"), exports); | ||
__exportStar(require("./interfaces"), exports); | ||
__exportStar(require("./retry-policy"), exports); | ||
__exportStar(require("./workflow-handle"), exports); | ||
__exportStar(require("./workflow-options"), exports); | ||
__exportStar(require("./workflow-handle"), exports); | ||
__exportStar(require("./deprecated-time"), exports); | ||
const encoding = __importStar(require("./encoding")); | ||
const helpers = __importStar(require("./type-helpers")); | ||
/** | ||
@@ -50,0 +54,0 @@ * Encode a UTF-8 string into a Uint8Array |
@@ -11,2 +11,3 @@ "use strict"; | ||
*/ | ||
// ts-prune-ignore-next (imported via lib/interceptors) | ||
function composeInterceptors(interceptors, method, next) { | ||
@@ -13,0 +14,0 @@ for (let i = interceptors.length - 1; i >= 0; --i) { |
@@ -53,1 +53,8 @@ import type { temporal } from '@temporalio/proto'; | ||
export declare type UntypedActivities = Record<string, ActivityFunction>; | ||
/** | ||
* A workflow's history and ID. Useful for replay. | ||
*/ | ||
export interface HistoryAndWorkflowId { | ||
workflowId: string; | ||
history: temporal.api.history.v1.History | unknown | undefined; | ||
} |
@@ -90,4 +90,6 @@ "use strict"; | ||
async function decodeOptionalFailureToOptionalError(converter, failure) { | ||
const { failureConverter, payloadCodecs } = converter; | ||
return failure ? failureConverter.failureToError(await decodeFailure(payloadCodecs, failure)) : undefined; | ||
const { failureConverter, payloadConverter, payloadCodecs } = converter; | ||
return failure | ||
? failureConverter.failureToError(await decodeFailure(payloadCodecs, failure), payloadConverter) | ||
: undefined; | ||
} | ||
@@ -156,4 +158,4 @@ exports.decodeOptionalFailureToOptionalError = decodeOptionalFailureToOptionalError; | ||
async function encodeErrorToFailure(dataConverter, error) { | ||
const { failureConverter, payloadCodecs } = dataConverter; | ||
return await encodeFailure(payloadCodecs, failureConverter.errorToFailure(error)); | ||
const { failureConverter, payloadConverter, payloadCodecs } = dataConverter; | ||
return await encodeFailure(payloadCodecs, failureConverter.errorToFailure(error, payloadConverter)); | ||
} | ||
@@ -160,0 +162,0 @@ exports.encodeErrorToFailure = encodeErrorToFailure; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isLoadedDataConverter = exports.loadDataConverter = void 0; | ||
const payload_converter_1 = require("../converter/payload-converter"); | ||
const data_converter_1 = require("../converter/data-converter"); | ||
const payload_converter_1 = require("../converter/payload-converter"); | ||
const type_helpers_1 = require("../type-helpers"); | ||
@@ -7,0 +7,0 @@ const errors_1 = require("../errors"); |
@@ -1,2 +0,2 @@ | ||
import proto from '@temporalio/proto'; | ||
import * as proto from '@temporalio/proto'; | ||
export declare type History = proto.temporal.api.history.v1.IHistory; | ||
@@ -3,0 +3,0 @@ export declare type Payload = proto.temporal.api.common.v1.IPayload; |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.JSONToPayload = exports.payloadToJSON = exports.historyFromJSON = void 0; | ||
const proto_1 = __importDefault(require("@temporalio/proto")); | ||
const proto3_json_serializer_1 = require("proto3-json-serializer"); | ||
const proto = __importStar(require("@temporalio/proto")); | ||
const patch_protobuf_root_1 = require("@temporalio/proto/lib/patch-protobuf-root"); | ||
// Cast to any because the generated proto module types are missing the lookupType method | ||
const patched = (0, patch_protobuf_root_1.patchProtobufRoot)(proto_1.default); | ||
const patched = (0, patch_protobuf_root_1.patchProtobufRoot)(proto); | ||
const historyType = patched.lookupType('temporal.api.history.v1.History'); | ||
@@ -13,0 +33,0 @@ const payloadType = patched.lookupType('temporal.api.common.v1.Payload'); |
@@ -19,1 +19,2 @@ import type { google } from '@temporalio/proto'; | ||
export declare function optionalTsToDate(ts: Timestamp | null | undefined): Date | undefined; | ||
export declare function optionalDateToTs(date: Date | null | undefined): Timestamp | undefined; |
@@ -6,3 +6,4 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.optionalTsToDate = exports.tsToDate = exports.msToNumber = exports.msOptionalToNumber = exports.msOptionalToTs = exports.msToTs = exports.msNumberToTs = exports.tsToMs = exports.optionalTsToMs = void 0; | ||
exports.optionalDateToTs = exports.optionalTsToDate = exports.tsToDate = exports.msToNumber = exports.msOptionalToNumber = exports.msOptionalToTs = exports.msToTs = exports.msNumberToTs = exports.tsToMs = exports.optionalTsToMs = void 0; | ||
// eslint-disable-next-line import/no-named-as-default | ||
const long_1 = __importDefault(require("long")); | ||
@@ -80,2 +81,10 @@ const ms_1 = __importDefault(require("ms")); | ||
exports.optionalTsToDate = optionalTsToDate; | ||
// ts-prune-ignore-next (imported via schedule-helpers.ts) | ||
function optionalDateToTs(date) { | ||
if (date === undefined || date === null) { | ||
return undefined; | ||
} | ||
return msToTs(date.getTime()); | ||
} | ||
exports.optionalDateToTs = optionalDateToTs; | ||
//# sourceMappingURL=time.js.map |
@@ -10,3 +10,5 @@ /** Shorthand alias */ | ||
export declare type Replace<Base, New> = Omit<Base, keyof New> & New; | ||
export declare type MakeOptional<Base, Keys extends keyof Base> = Omit<Base, Keys> & Partial<Pick<Base, Keys>>; | ||
export declare type RequireAtLeastOne<Base, Keys extends keyof Base> = Omit<Base, Keys> & { | ||
[K in Keys]-?: Required<Pick<Base, K>> & Partial<Pick<Base, Exclude<Keys, K>>>; | ||
}[Keys]; | ||
export declare function isRecord(value: unknown): value is Record<string, unknown>; | ||
@@ -13,0 +15,0 @@ export declare function hasOwnProperty<X extends Record<string, unknown>, Y extends PropertyKey>(record: X, prop: Y): record is X & Record<Y, unknown>; |
@@ -13,2 +13,3 @@ "use strict"; | ||
exports.isRecord = isRecord; | ||
// ts-prune-ignore-next | ||
function hasOwnProperty(record, prop) { | ||
@@ -15,0 +16,0 @@ return prop in record; |
@@ -67,3 +67,3 @@ import type { google } from '@temporalio/proto'; | ||
*/ | ||
memo?: Record<string, any>; | ||
memo?: Record<string, unknown>; | ||
/** | ||
@@ -70,0 +70,0 @@ * Specifies additional indexed information to attach to the Workflow Execution. More info: |
{ | ||
"name": "@temporalio/common", | ||
"version": "1.4.4", | ||
"version": "1.5.0", | ||
"description": "Common library for code that's used across the Client, Worker, and/or Workflow", | ||
@@ -16,3 +16,3 @@ "main": "lib/index.js", | ||
"@opentelemetry/api": "^1.0.3", | ||
"@temporalio/proto": "~1.4.4", | ||
"@temporalio/proto": "~1.5.0", | ||
"long": "^5.2.0", | ||
@@ -34,3 +34,3 @@ "ms": "^2.1.3", | ||
], | ||
"gitHead": "7ae3fba6332000b35d521411404c11e32052f282" | ||
"gitHead": "b46426d8b9b342c052d53520b50dbb991b8d5e03" | ||
} |
@@ -48,13 +48,20 @@ import type { coresdk } from '@temporalio/proto'; | ||
/** | ||
* Maximum time of a single Activity execution attempt. | ||
Note that the Temporal Server doesn't detect Worker process failures directly. It relies on this timeout to detect that an Activity that didn't complete on time. So this timeout should be as short as the longest possible execution of the Activity body. Potentially long running Activities must specify {@link heartbeatTimeout} and call {@link activity.Context.heartbeat} periodically for timely failure detection. | ||
* Maximum time of a single Activity execution attempt. Note that the Temporal Server doesn't detect Worker process | ||
* failures directly. It relies on this timeout to detect that an Activity that didn't complete on time. So this | ||
* timeout should be as short as the longest possible execution of the Activity body. Potentially long running | ||
* Activities must specify {@link heartbeatTimeout} and call {@link activity.Context.heartbeat} periodically for | ||
* timely failure detection. | ||
* | ||
* Either this option or {@link scheduleToCloseTimeout} is required. | ||
* | ||
* @default `scheduleToCloseTimeout` or unlimited | ||
* @format number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string} | ||
*/ | ||
startToCloseTimeout?: string | number; | ||
/** | ||
* Time that the Activity Task can stay in the Task Queue before it is picked up by a Worker. Do not specify this timeout unless using host specific Task Queues for Activity Tasks are being used for routing. | ||
* `scheduleToStartTimeout` is always non-retryable. Retrying after this timeout doesn't make sense as it would just put the Activity Task back into the same Task Queue. | ||
* @default unlimited | ||
* | ||
* @default `scheduleToCloseTimeout` or unlimited | ||
* @format number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string} | ||
@@ -68,3 +75,4 @@ */ | ||
* | ||
* Either this option or {@link startToCloseTimeout} is required | ||
* Either this option or {@link startToCloseTimeout} is required. | ||
* | ||
* @default unlimited | ||
@@ -71,0 +79,0 @@ * @format number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string} |
@@ -16,9 +16,3 @@ import { | ||
import { hasOwnProperties, isRecord } from '../type-helpers'; | ||
import { | ||
arrayFromPayloads, | ||
defaultPayloadConverter, | ||
fromPayloadsAtIndex, | ||
PayloadConverter, | ||
toPayloads, | ||
} from './payload-converter'; | ||
import { arrayFromPayloads, fromPayloadsAtIndex, PayloadConverter, toPayloads } from './payload-converter'; | ||
@@ -53,6 +47,6 @@ /** | ||
/** | ||
* A `FailureConverter` is responsible to convert from proto `Failure` instances to JS `Errors` and back. | ||
* A `FailureConverter` is responsible for converting from proto `Failure` instances to JS `Errors` and back. | ||
* | ||
* It is recommended to use the {@link DefaultFailureConverter} and not attempt to customize the default implementation | ||
* in order to maintain cross language failure serialization compatibility. | ||
* We recommended using the {@link DefaultFailureConverter} instead of customizing the default implementation in order | ||
* to maintain cross-language Failure serialization compatibility. | ||
* | ||
@@ -65,7 +59,7 @@ * @experimental | ||
*/ | ||
errorToFailure(err: unknown): ProtoFailure; | ||
errorToFailure(err: unknown, payloadConverter: PayloadConverter): ProtoFailure; | ||
/** | ||
* Converts a Failure proto message to a JS Error object. | ||
*/ | ||
failureToError(err: ProtoFailure): TemporalFailure; | ||
failureToError(err: ProtoFailure, payloadConverter: PayloadConverter): Error; | ||
} | ||
@@ -87,6 +81,2 @@ | ||
/** | ||
* The {@link PayloadConverter} to use for converting failure attributes. | ||
*/ | ||
payloadConverter: PayloadConverter; | ||
/** | ||
* Whether to encode error messages and stack traces (for encrypting these attributes use a {@link PayloadCodec}). | ||
@@ -98,7 +88,8 @@ */ | ||
/** | ||
* Default cross language compatible failure converter. | ||
* Default, cross-language-compatible Failure converter. | ||
* | ||
* By default, it will leave error messages and stack traces as plain text. In order to encrypt those, set | ||
* `encodeCommonAttributes` to `true` in the constructor options and make sure to use a {@link PayloadCodec} that can | ||
* encrypt / decrypt payloads in your Worker and Client options. | ||
* By default, it will leave error messages and stack traces as plain text. In order to encrypt them, set | ||
* `encodeCommonAttributes` to `true` in the constructor options and use a {@link PayloadCodec} that can encrypt / | ||
* decrypt Payloads in your {@link WorkerOptions.dataConverter | Worker} and | ||
* {@link ClientOptions.dataConverter | Client options}. | ||
* | ||
@@ -111,6 +102,5 @@ * @experimental | ||
constructor(options?: Partial<DefaultFailureConverterOptions>) { | ||
const { encodeCommonAttributes, payloadConverter } = options ?? {}; | ||
const { encodeCommonAttributes } = options ?? {}; | ||
this.options = { | ||
encodeCommonAttributes: encodeCommonAttributes ?? false, | ||
payloadConverter: payloadConverter ?? defaultPayloadConverter, | ||
}; | ||
@@ -124,3 +114,3 @@ } | ||
*/ | ||
failureToErrorInner(failure: ProtoFailure): TemporalFailure { | ||
failureToErrorInner(failure: ProtoFailure, payloadConverter: PayloadConverter): TemporalFailure { | ||
if (failure.applicationFailureInfo) { | ||
@@ -131,4 +121,4 @@ return new ApplicationFailure( | ||
Boolean(failure.applicationFailureInfo.nonRetryable), | ||
arrayFromPayloads(this.options.payloadConverter, failure.applicationFailureInfo.details?.payloads), | ||
this.optionalFailureToOptionalError(failure.cause) | ||
arrayFromPayloads(payloadConverter, failure.applicationFailureInfo.details?.payloads), | ||
this.optionalFailureToOptionalError(failure.cause, payloadConverter) | ||
); | ||
@@ -140,3 +130,3 @@ } | ||
Boolean(failure.serverFailureInfo.nonRetryable), | ||
this.optionalFailureToOptionalError(failure.cause) | ||
this.optionalFailureToOptionalError(failure.cause, payloadConverter) | ||
); | ||
@@ -147,7 +137,3 @@ } | ||
failure.message ?? undefined, | ||
fromPayloadsAtIndex( | ||
this.options.payloadConverter, | ||
0, | ||
failure.timeoutFailureInfo.lastHeartbeatDetails?.payloads | ||
), | ||
fromPayloadsAtIndex(payloadConverter, 0, failure.timeoutFailureInfo.lastHeartbeatDetails?.payloads), | ||
failure.timeoutFailureInfo.timeoutType ?? TimeoutType.TIMEOUT_TYPE_UNSPECIFIED | ||
@@ -157,3 +143,6 @@ ); | ||
if (failure.terminatedFailureInfo) { | ||
return new TerminatedFailure(failure.message ?? undefined, this.optionalFailureToOptionalError(failure.cause)); | ||
return new TerminatedFailure( | ||
failure.message ?? undefined, | ||
this.optionalFailureToOptionalError(failure.cause, payloadConverter) | ||
); | ||
} | ||
@@ -163,4 +152,4 @@ if (failure.canceledFailureInfo) { | ||
failure.message ?? undefined, | ||
arrayFromPayloads(this.options.payloadConverter, failure.canceledFailureInfo.details?.payloads), | ||
this.optionalFailureToOptionalError(failure.cause) | ||
arrayFromPayloads(payloadConverter, failure.canceledFailureInfo.details?.payloads), | ||
this.optionalFailureToOptionalError(failure.cause, payloadConverter) | ||
); | ||
@@ -173,7 +162,4 @@ } | ||
false, | ||
arrayFromPayloads( | ||
this.options.payloadConverter, | ||
failure.resetWorkflowFailureInfo.lastHeartbeatDetails?.payloads | ||
), | ||
this.optionalFailureToOptionalError(failure.cause) | ||
arrayFromPayloads(payloadConverter, failure.resetWorkflowFailureInfo.lastHeartbeatDetails?.payloads), | ||
this.optionalFailureToOptionalError(failure.cause, payloadConverter) | ||
); | ||
@@ -191,3 +177,3 @@ } | ||
retryState ?? RetryState.RETRY_STATE_UNSPECIFIED, | ||
this.optionalFailureToOptionalError(failure.cause) | ||
this.optionalFailureToOptionalError(failure.cause, payloadConverter) | ||
); | ||
@@ -204,13 +190,14 @@ } | ||
failure.activityFailureInfo.identity ?? undefined, | ||
this.optionalFailureToOptionalError(failure.cause) | ||
this.optionalFailureToOptionalError(failure.cause, payloadConverter) | ||
); | ||
} | ||
return new TemporalFailure(failure.message ?? undefined, this.optionalFailureToOptionalError(failure.cause)); | ||
return new TemporalFailure( | ||
failure.message ?? undefined, | ||
this.optionalFailureToOptionalError(failure.cause, payloadConverter) | ||
); | ||
} | ||
failureToError(failure: ProtoFailure): TemporalFailure { | ||
failureToError(failure: ProtoFailure, payloadConverter: PayloadConverter): Error { | ||
if (failure.encodedAttributes) { | ||
const attrs = this.options.payloadConverter.fromPayload<DefaultEncodedFailureAttributes>( | ||
failure.encodedAttributes | ||
); | ||
const attrs = payloadConverter.fromPayload<DefaultEncodedFailureAttributes>(failure.encodedAttributes); | ||
// Don't apply encodedAttributes unless they conform to an expected schema | ||
@@ -229,3 +216,3 @@ if (typeof attrs === 'object' && attrs !== null) { | ||
} | ||
const err = this.failureToErrorInner(failure); | ||
const err = this.failureToErrorInner(failure, payloadConverter); | ||
err.stack = failure.stackTrace ?? ''; | ||
@@ -236,4 +223,4 @@ err.failure = failure; | ||
errorToFailure(err: unknown): ProtoFailure { | ||
const failure = this.errorToFailureInner(err); | ||
errorToFailure(err: unknown, payloadConverter: PayloadConverter): ProtoFailure { | ||
const failure = this.errorToFailureInner(err, payloadConverter); | ||
if (this.options.encodeCommonAttributes) { | ||
@@ -243,3 +230,3 @@ const { message, stackTrace } = failure; | ||
failure.stackTrace = ''; | ||
failure.encodedAttributes = this.options.payloadConverter.toPayload({ message, stack_trace: stackTrace }); | ||
failure.encodedAttributes = payloadConverter.toPayload({ message, stack_trace: stackTrace }); | ||
} | ||
@@ -249,3 +236,3 @@ return failure; | ||
errorToFailureInner(err: unknown): ProtoFailure { | ||
errorToFailureInner(err: unknown, payloadConverter: PayloadConverter): ProtoFailure { | ||
if (err instanceof TemporalFailure) { | ||
@@ -256,3 +243,3 @@ if (err.failure) return err.failure; | ||
stackTrace: cutoffStackTrace(err.stack), | ||
cause: this.optionalErrorToOptionalFailure(err.cause), | ||
cause: this.optionalErrorToOptionalFailure(err.cause, payloadConverter), | ||
source: FAILURE_SOURCE, | ||
@@ -288,3 +275,3 @@ }; | ||
err.details && err.details.length | ||
? { payloads: toPayloads(this.options.payloadConverter, ...err.details) } | ||
? { payloads: toPayloads(payloadConverter, ...err.details) } | ||
: undefined, | ||
@@ -300,3 +287,3 @@ }, | ||
err.details && err.details.length | ||
? { payloads: toPayloads(this.options.payloadConverter, ...err.details) } | ||
? { payloads: toPayloads(payloadConverter, ...err.details) } | ||
: undefined, | ||
@@ -312,3 +299,3 @@ }, | ||
lastHeartbeatDetails: err.lastHeartbeatDetails | ||
? { payloads: toPayloads(this.options.payloadConverter, err.lastHeartbeatDetails) } | ||
? { payloads: toPayloads(payloadConverter, err.lastHeartbeatDetails) } | ||
: undefined, | ||
@@ -343,3 +330,3 @@ }, | ||
stackTrace: cutoffStackTrace(String(err.stack)), | ||
cause: this.optionalErrorToOptionalFailure(err.cause), | ||
cause: this.optionalErrorToOptionalFailure(err.cause, payloadConverter), | ||
}; | ||
@@ -369,4 +356,7 @@ } | ||
*/ | ||
optionalFailureToOptionalError(failure: ProtoFailure | undefined | null): TemporalFailure | undefined { | ||
return failure ? this.failureToError(failure) : undefined; | ||
optionalFailureToOptionalError( | ||
failure: ProtoFailure | undefined | null, | ||
payloadConverter: PayloadConverter | ||
): Error | undefined { | ||
return failure ? this.failureToError(failure, payloadConverter) : undefined; | ||
} | ||
@@ -377,5 +367,5 @@ | ||
*/ | ||
optionalErrorToOptionalFailure(err: unknown): ProtoFailure | undefined { | ||
return err ? this.errorToFailure(err) : undefined; | ||
optionalErrorToOptionalFailure(err: unknown, payloadConverter: PayloadConverter): ProtoFailure | undefined { | ||
return err ? this.errorToFailure(err, payloadConverter) : undefined; | ||
} | ||
} |
@@ -6,4 +6,6 @@ /** | ||
*/ | ||
export { Headers, Next } from './interceptors'; | ||
import * as encoding from './encoding'; | ||
import * as helpers from './type-helpers'; | ||
export * from './activity-options'; | ||
@@ -15,15 +17,12 @@ export * from './converter/data-converter'; | ||
export * from './converter/types'; | ||
export * from './deprecated-time'; | ||
export * from './errors'; | ||
export * from './failure'; | ||
export * from './failure'; | ||
export { Headers, Next } from './interceptors'; | ||
export * from './interfaces'; | ||
export * from './retry-policy'; | ||
export { Timestamp } from './time'; | ||
export * from './workflow-handle'; | ||
export * from './workflow-options'; | ||
export * from './workflow-handle'; | ||
export * from './deprecated-time'; | ||
import * as encoding from './encoding'; | ||
import * as helpers from './type-helpers'; | ||
/** | ||
@@ -30,0 +29,0 @@ * Encode a UTF-8 string into a Uint8Array |
@@ -21,2 +21,3 @@ import { AnyFunc, OmitLastParam } from './type-helpers'; | ||
*/ | ||
// ts-prune-ignore-next (imported via lib/interceptors) | ||
export function composeInterceptors<I, M extends keyof I>(interceptors: I[], method: M, next: Next<I, M>): Next<I, M> { | ||
@@ -23,0 +24,0 @@ for (let i = interceptors.length - 1; i >= 0; --i) { |
@@ -65,1 +65,9 @@ import type { temporal } from '@temporalio/proto'; | ||
export type UntypedActivities = Record<string, ActivityFunction>; | ||
/** | ||
* A workflow's history and ID. Useful for replay. | ||
*/ | ||
export interface HistoryAndWorkflowId { | ||
workflowId: string; | ||
history: temporal.api.history.v1.History | unknown | undefined; | ||
} |
@@ -113,4 +113,6 @@ import { Payload } from '../interfaces'; | ||
): Promise<TemporalFailure | undefined> { | ||
const { failureConverter, payloadCodecs } = converter; | ||
return failure ? failureConverter.failureToError(await decodeFailure(payloadCodecs, failure)) : undefined; | ||
const { failureConverter, payloadConverter, payloadCodecs } = converter; | ||
return failure | ||
? failureConverter.failureToError(await decodeFailure(payloadCodecs, failure), payloadConverter) | ||
: undefined; | ||
} | ||
@@ -203,4 +205,4 @@ | ||
export async function encodeErrorToFailure(dataConverter: LoadedDataConverter, error: unknown): Promise<ProtoFailure> { | ||
const { failureConverter, payloadCodecs } = dataConverter; | ||
return await encodeFailure(payloadCodecs, failureConverter.errorToFailure(error)); | ||
const { failureConverter, payloadConverter, payloadCodecs } = dataConverter; | ||
return await encodeFailure(payloadCodecs, failureConverter.errorToFailure(error, payloadConverter)); | ||
} | ||
@@ -207,0 +209,0 @@ |
@@ -1,5 +0,4 @@ | ||
import { PayloadConverter } from '../converter/payload-converter'; | ||
import { PayloadConverter, defaultPayloadConverter } from '../converter/payload-converter'; | ||
import { DataConverter, defaultFailureConverter, LoadedDataConverter } from '../converter/data-converter'; | ||
import { FailureConverter } from '../converter/failure-converter'; | ||
import { defaultPayloadConverter } from '../converter/payload-converter'; | ||
import { errorCode, hasOwnProperty, isRecord } from '../type-helpers'; | ||
@@ -6,0 +5,0 @@ import { ValueError } from '../errors'; |
@@ -1,3 +0,3 @@ | ||
import proto from '@temporalio/proto'; | ||
import { fromProto3JSON, toProto3JSON } from 'proto3-json-serializer'; | ||
import * as proto from '@temporalio/proto'; | ||
import { patchProtobufRoot } from '@temporalio/proto/lib/patch-protobuf-root'; | ||
@@ -4,0 +4,0 @@ |
@@ -1,4 +0,5 @@ | ||
import type { google } from '@temporalio/proto'; | ||
// eslint-disable-next-line import/no-named-as-default | ||
import Long from 'long'; | ||
import ms from 'ms'; | ||
import type { google } from '@temporalio/proto'; | ||
import { ValueError } from './errors'; | ||
@@ -80,1 +81,9 @@ | ||
} | ||
// ts-prune-ignore-next (imported via schedule-helpers.ts) | ||
export function optionalDateToTs(date: Date | null | undefined): Timestamp | undefined { | ||
if (date === undefined || date === null) { | ||
return undefined; | ||
} | ||
return msToTs(date.getTime()); | ||
} |
@@ -15,3 +15,6 @@ /** Shorthand alias */ | ||
export type MakeOptional<Base, Keys extends keyof Base> = Omit<Base, Keys> & Partial<Pick<Base, Keys>>; | ||
export type RequireAtLeastOne<Base, Keys extends keyof Base> = Omit<Base, Keys> & | ||
{ | ||
[K in Keys]-?: Required<Pick<Base, K>> & Partial<Pick<Base, Exclude<Keys, K>>>; | ||
}[Keys]; | ||
@@ -22,2 +25,3 @@ export function isRecord(value: unknown): value is Record<string, unknown> { | ||
// ts-prune-ignore-next | ||
export function hasOwnProperty<X extends Record<string, unknown>, Y extends PropertyKey>( | ||
@@ -24,0 +28,0 @@ record: X, |
@@ -82,3 +82,3 @@ import type { temporal, google } from '@temporalio/proto'; | ||
*/ | ||
memo?: Record<string, any>; | ||
memo?: Record<string, unknown>; | ||
@@ -85,0 +85,0 @@ /** |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
346893
6809
+ Added@temporalio/proto@1.5.2(transitive)
- Removed@temporalio/proto@1.4.4(transitive)
Updated@temporalio/proto@~1.5.0