Socket
Socket
Sign inDemoInstall

@temporalio/common

Package Overview
Dependencies
Maintainers
4
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@temporalio/common - npm Package Compare versions

Comparing version 0.17.2 to 0.18.0

29

lib/errors.d.ts

@@ -14,4 +14,33 @@ export declare class ValueError extends Error {

/**
* This exception is thrown in the following cases:
* - Workflow with the same WorkflowId is currently running
* - There is a closed workflow with the same ID and the {@link WorkflowOptions.workflowIdReusePolicy}
* is `WORKFLOW_ID_REUSE_POLICY_REJECT_DUPLICATE`
* - There is successfully closed workflow with the same ID and the {@link WorkflowOptions.workflowIdReusePolicy}
* is `WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE_FAILED_ONLY`
* - {@link Workflow.execute} is called *more than once* on a handle created through {@link createChildWorkflowHandle} and the
* {@link WorkflowOptions.workflowIdReusePolicy} is `WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE`
*/
export declare class WorkflowExecutionAlreadyStartedError extends Error {
readonly workflowId: string;
readonly workflowType: string;
readonly name: string;
constructor(message: string, workflowId: string, workflowType: string);
}
/**
* Thrown when workflow with the given id is not known to the Temporal service.
* It could be because:
* - ID passed is incorrect
* - Workflow execution is complete (for some calls e.g. terminate),
* - workflow was purged from the service after reaching its retention limit.
*/
export declare class WorkflowNotFoundError extends Error {
readonly workflowId: string;
readonly runId: string | undefined;
readonly name: string;
constructor(message: string, workflowId: string, runId: string | undefined);
}
/**
* Get error message from an Error or string or return undefined
*/
export declare function errorMessage(err: unknown): string | undefined;

37

lib/errors.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.errorMessage = exports.IllegalStateError = exports.DataConverterError = exports.ValueError = void 0;
exports.errorMessage = exports.WorkflowNotFoundError = exports.WorkflowExecutionAlreadyStartedError = exports.IllegalStateError = exports.DataConverterError = exports.ValueError = void 0;
class ValueError extends Error {

@@ -29,2 +29,37 @@ constructor() {

/**
* This exception is thrown in the following cases:
* - Workflow with the same WorkflowId is currently running
* - There is a closed workflow with the same ID and the {@link WorkflowOptions.workflowIdReusePolicy}
* is `WORKFLOW_ID_REUSE_POLICY_REJECT_DUPLICATE`
* - There is successfully closed workflow with the same ID and the {@link WorkflowOptions.workflowIdReusePolicy}
* is `WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE_FAILED_ONLY`
* - {@link Workflow.execute} is called *more than once* on a handle created through {@link createChildWorkflowHandle} and the
* {@link WorkflowOptions.workflowIdReusePolicy} is `WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE`
*/
class WorkflowExecutionAlreadyStartedError extends Error {
constructor(message, workflowId, workflowType) {
super(message);
this.workflowId = workflowId;
this.workflowType = workflowType;
this.name = 'WorkflowExecutionAlreadyStartedError';
}
}
exports.WorkflowExecutionAlreadyStartedError = WorkflowExecutionAlreadyStartedError;
/**
* Thrown when workflow with the given id is not known to the Temporal service.
* It could be because:
* - ID passed is incorrect
* - Workflow execution is complete (for some calls e.g. terminate),
* - workflow was purged from the service after reaching its retention limit.
*/
class WorkflowNotFoundError extends Error {
constructor(message, workflowId, runId) {
super(message);
this.workflowId = workflowId;
this.runId = runId;
this.name = 'WorkflowNotFoundError';
}
}
exports.WorkflowNotFoundError = WorkflowNotFoundError;
/**
* Get error message from an Error or string or return undefined

@@ -31,0 +66,0 @@ */

18

lib/failure.js

@@ -196,3 +196,3 @@ "use strict";

*/
const CUTTOFF_STACK_PATTERNS = [
const CUTOFF_STACK_PATTERNS = [
/** Activity execution */

@@ -210,3 +210,3 @@ /\s+at Activity\.execute \(.*[\\/]worker[\\/](?:src|lib)[\\/]activity\.[jt]s:\d+:\d+\)/,

lineLoop: for (const line of lines) {
for (const pattern of CUTTOFF_STACK_PATTERNS) {
for (const pattern of CUTOFF_STACK_PATTERNS) {
if (pattern.test(line))

@@ -303,9 +303,15 @@ break lineLoop;

};
if (err instanceof Error) {
return { ...base, message: err.message ?? '', stackTrace: cutoffStackTrace(err.stack) };
if ((0, type_helpers_1.isRecord)(err) && (0, type_helpers_1.hasOwnProperties)(err, ['message', 'stack'])) {
return {
...base,
message: String(err.message) ?? '',
stackTrace: cutoffStackTrace(String(err.stack)),
cause: await optionalErrorToOptionalFailure(err.cause, dataConverter),
};
}
const recommendation = ` [A non-Error value was thrown from your code. We recommend throwing Error objects so that we can provide a stack trace.]`;
if (typeof err === 'string') {
return { ...base, message: err };
return { ...base, message: err + recommendation };
}
return { ...base, message: String(err) };
return { ...base, message: JSON.stringify(err) + recommendation };
}

@@ -312,0 +318,0 @@ exports.errorToFailure = errorToFailure;

@@ -13,2 +13,3 @@ import type * as iface from '@temporalio/proto/lib/coresdk';

export declare function msNumberToTs(millis: number): Timestamp;
export declare function falsyMsToTs(str: string | number | undefined): Timestamp | undefined;
export declare function msToTs(str: string | number): Timestamp;

@@ -15,0 +16,0 @@ export declare function msOptionalToTs(str: string | number | undefined): Timestamp | undefined;

@@ -6,3 +6,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.msToNumber = exports.msOptionalToNumber = exports.msOptionalToTs = exports.msToTs = exports.msNumberToTs = exports.tsToMs = exports.optionalTsToMs = void 0;
exports.msToNumber = exports.msOptionalToNumber = exports.msOptionalToTs = exports.msToTs = exports.falsyMsToTs = exports.msNumberToTs = exports.tsToMs = exports.optionalTsToMs = void 0;
const long_1 = __importDefault(require("long"));

@@ -45,2 +45,6 @@ const ms_1 = __importDefault(require("ms"));

exports.msNumberToTs = msNumberToTs;
function falsyMsToTs(str) {
return str ? msToTs(str) : undefined;
}
exports.falsyMsToTs = falsyMsToTs;
function msToTs(str) {

@@ -47,0 +51,0 @@ if (typeof str === 'number') {

@@ -9,1 +9,5 @@ /** Shorthand alias */

export declare function checkExtends<_Orig, _Copy extends _Orig>(): void;
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 function isRecord(value: unknown): value is Record<string, unknown>;
export declare function hasOwnProperties<X extends Record<string, unknown>, Y extends PropertyKey>(record: X, props: Y[]): record is X & Record<Y, unknown>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkExtends = void 0;
exports.hasOwnProperties = exports.isRecord = exports.checkExtends = void 0;
/** Verify that an type _Copy extends _Orig */

@@ -9,2 +9,10 @@ function checkExtends() {

exports.checkExtends = checkExtends;
function isRecord(value) {
return typeof value === 'object' && value !== null;
}
exports.isRecord = isRecord;
function hasOwnProperties(record, props) {
return props.every((prop) => prop in record);
}
exports.hasOwnProperties = hasOwnProperties;
//# sourceMappingURL=type-helpers.js.map
import type { google } from '@temporalio/proto/lib/coresdk';
import { Workflow } from './interfaces';
import { Replace } from './type-helpers';
import { RetryPolicy } from './retry-policy';

@@ -86,7 +87,7 @@ export declare enum WorkflowIdReusePolicy {

export declare type CommonWorkflowOptions = BaseWorkflowOptions & WorkflowDurationOptions;
export declare type WithCompiledWorkflowDurationOptions<T extends WorkflowDurationOptions> = Omit<T, 'workflowExecutionTimeout' | 'workflowRunTimeout' | 'workflowTaskTimeout'> & {
export declare type WithCompiledWorkflowDurationOptions<T extends WorkflowDurationOptions> = Replace<T, {
workflowExecutionTimeout?: google.protobuf.IDuration;
workflowRunTimeout?: google.protobuf.IDuration;
workflowTaskTimeout?: google.protobuf.IDuration;
};
}>;
export declare function compileWorkflowOptions<T extends WorkflowDurationOptions>(options: T): WithCompiledWorkflowDurationOptions<T>;

@@ -20,5 +20,5 @@ "use strict";

...rest,
workflowExecutionTimeout: workflowExecutionTimeout ? (0, time_1.msToTs)(workflowExecutionTimeout) : undefined,
workflowRunTimeout: workflowRunTimeout ? (0, time_1.msToTs)(workflowRunTimeout) : undefined,
workflowTaskTimeout: workflowTaskTimeout ? (0, time_1.msToTs)(workflowTaskTimeout) : undefined,
workflowExecutionTimeout: (0, time_1.falsyMsToTs)(workflowExecutionTimeout),
workflowRunTimeout: (0, time_1.falsyMsToTs)(workflowRunTimeout),
workflowTaskTimeout: (0, time_1.falsyMsToTs)(workflowTaskTimeout),
};

@@ -25,0 +25,0 @@ }

{
"name": "@temporalio/common",
"version": "0.17.2",
"version": "0.18.0",
"description": "Temporal.io SDK common library for use in Workflow and normal code",

@@ -16,3 +16,3 @@ "main": "lib/index.js",

"dependencies": {
"@temporalio/proto": "^0.17.2",
"@temporalio/proto": "^0.18.0",
"ms": "^2.1.3"

@@ -27,3 +27,3 @@ },

},
"gitHead": "2232465a4f9b0cade28f0c21c2d7856053678728"
"gitHead": "1f8030e0e003fac70969bee9bb816d9520910d02"
}

@@ -17,2 +17,35 @@ export class ValueError extends Error {

/**
* This exception is thrown in the following cases:
* - Workflow with the same WorkflowId is currently running
* - There is a closed workflow with the same ID and the {@link WorkflowOptions.workflowIdReusePolicy}
* is `WORKFLOW_ID_REUSE_POLICY_REJECT_DUPLICATE`
* - There is successfully closed workflow with the same ID and the {@link WorkflowOptions.workflowIdReusePolicy}
* is `WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE_FAILED_ONLY`
* - {@link Workflow.execute} is called *more than once* on a handle created through {@link createChildWorkflowHandle} and the
* {@link WorkflowOptions.workflowIdReusePolicy} is `WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE`
*/
export class WorkflowExecutionAlreadyStartedError extends Error {
public readonly name: string = 'WorkflowExecutionAlreadyStartedError';
constructor(message: string, public readonly workflowId: string, public readonly workflowType: string) {
super(message);
}
}
/**
* Thrown when workflow with the given id is not known to the Temporal service.
* It could be because:
* - ID passed is incorrect
* - Workflow execution is complete (for some calls e.g. terminate),
* - workflow was purged from the service after reaching its retention limit.
*/
export class WorkflowNotFoundError extends Error {
public readonly name: string = 'WorkflowNotFoundError';
constructor(message: string, public readonly workflowId: string, public readonly runId: string | undefined) {
super(message);
}
}
/**
* Get error message from an Error or string or return undefined

@@ -19,0 +52,0 @@ */

import type { temporal } from '@temporalio/proto/lib/coresdk';
import { DataConverter, arrayFromPayloads } from './converter/data-converter';
import { checkExtends } from './type-helpers';
import { checkExtends, hasOwnProperties, isRecord } from './type-helpers';

@@ -223,3 +223,3 @@ export const FAILURE_SOURCE = 'TypeScriptSDK';

*/
const CUTTOFF_STACK_PATTERNS = [
const CUTOFF_STACK_PATTERNS = [
/** Activity execution */

@@ -238,3 +238,3 @@ /\s+at Activity\.execute \(.*[\\/]worker[\\/](?:src|lib)[\\/]activity\.[jt]s:\d+:\d+\)/,

lineLoop: for (const line of lines) {
for (const pattern of CUTTOFF_STACK_PATTERNS) {
for (const pattern of CUTOFF_STACK_PATTERNS) {
if (pattern.test(line)) break lineLoop;

@@ -334,11 +334,18 @@ }

if (err instanceof Error) {
return { ...base, message: err.message ?? '', stackTrace: cutoffStackTrace(err.stack) };
if (isRecord(err) && hasOwnProperties(err, ['message', 'stack'])) {
return {
...base,
message: String(err.message) ?? '',
stackTrace: cutoffStackTrace(String(err.stack)),
cause: await optionalErrorToOptionalFailure(err.cause, dataConverter),
};
}
const recommendation = ` [A non-Error value was thrown from your code. We recommend throwing Error objects so that we can provide a stack trace.]`;
if (typeof err === 'string') {
return { ...base, message: err };
return { ...base, message: err + recommendation };
}
return { ...base, message: String(err) };
return { ...base, message: JSON.stringify(err) + recommendation };
}

@@ -345,0 +352,0 @@

@@ -47,2 +47,6 @@ import Long from 'long';

export function falsyMsToTs(str: string | number | undefined): Timestamp | undefined {
return str ? msToTs(str) : undefined;
}
export function msToTs(str: string | number): Timestamp {

@@ -49,0 +53,0 @@ if (typeof str === 'number') {

@@ -12,1 +12,16 @@ /** Shorthand alias */

}
export type Replace<Base, New> = Omit<Base, keyof New> & New;
export type MakeOptional<Base, Keys extends keyof Base> = Omit<Base, Keys> & Partial<Pick<Base, Keys>>;
export function isRecord(value: unknown): value is Record<string, unknown> {
return typeof value === 'object' && value !== null;
}
export function hasOwnProperties<X extends Record<string, unknown>, Y extends PropertyKey>(
record: X,
props: Y[]
): record is X & Record<Y, unknown> {
return props.every((prop) => prop in record);
}
import type { coresdk, google } from '@temporalio/proto/lib/coresdk';
import { Workflow } from './interfaces';
import { falsyMsToTs } from './time';
import { Replace } from './type-helpers';
import { RetryPolicy } from './retry-policy';
import { msToTs } from './time';
import { checkExtends } from './type-helpers';

@@ -107,10 +108,10 @@

export type WithCompiledWorkflowDurationOptions<T extends WorkflowDurationOptions> = Omit<
export type WithCompiledWorkflowDurationOptions<T extends WorkflowDurationOptions> = Replace<
T,
'workflowExecutionTimeout' | 'workflowRunTimeout' | 'workflowTaskTimeout'
> & {
workflowExecutionTimeout?: google.protobuf.IDuration;
workflowRunTimeout?: google.protobuf.IDuration;
workflowTaskTimeout?: google.protobuf.IDuration;
};
{
workflowExecutionTimeout?: google.protobuf.IDuration;
workflowRunTimeout?: google.protobuf.IDuration;
workflowTaskTimeout?: google.protobuf.IDuration;
}
>;

@@ -124,6 +125,6 @@ export function compileWorkflowOptions<T extends WorkflowDurationOptions>(

...rest,
workflowExecutionTimeout: workflowExecutionTimeout ? msToTs(workflowExecutionTimeout) : undefined,
workflowRunTimeout: workflowRunTimeout ? msToTs(workflowRunTimeout) : undefined,
workflowTaskTimeout: workflowTaskTimeout ? msToTs(workflowTaskTimeout) : undefined,
workflowExecutionTimeout: falsyMsToTs(workflowExecutionTimeout),
workflowRunTimeout: falsyMsToTs(workflowRunTimeout),
workflowTaskTimeout: falsyMsToTs(workflowTaskTimeout),
};
}

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc