Socket
Socket
Sign inDemoInstall

@temporalio/workflow

Package Overview
Dependencies
Maintainers
4
Versions
79
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@temporalio/workflow - npm Package Compare versions

Comparing version 0.3.0 to 0.3.1

4

lib/common.d.ts

@@ -5,2 +5,6 @@ import { coresdk } from '@temporalio/proto';

* Helper for creating promises which can be manually resolved
*
* TODO: Move this to a shared library for node packages
*
* Do not use this in Workflow code, use {@link Trigger} instead
*/

@@ -7,0 +11,0 @@ export declare class ResolvablePromise<T> implements PromiseLike<T> {

@@ -17,2 +17,6 @@ "use strict";

* Helper for creating promises which can be manually resolved
*
* TODO: Move this to a shared library for node packages
*
* Do not use this in Workflow code, use {@link Trigger} instead
*/

@@ -19,0 +23,0 @@ class ResolvablePromise {

2

lib/converter/payload-converter.js

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

fromData(_content) {
return undefined; // Just return undeinfed
return undefined; // Just return undefined
}

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

@@ -27,9 +27,2 @@ import * as iface from '@temporalio/proto';

/**
* Used to denote where the cancellation was originated
*
* - external - The workflow was cancelled by an external API call
* - internal - Cancellation was requested by using `cancel` from within a workflow
*/
export declare type CancellationSource = 'internal' | 'external';
/**
* Thrown in workflow when it is requested to be cancelled either externally or internally.

@@ -39,6 +32,5 @@ *

*/
export declare class CancellationError extends Error {
readonly source: CancellationSource;
export declare class CancelledError extends Error {
readonly name: string;
constructor(message: string, source: CancellationSource);
constructor(message: string);
}

@@ -45,0 +37,0 @@ /**

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DeterminismViolationError = exports.IllegalStateError = exports.CancellationError = exports.WorkflowExecutionContinuedAsNewError = exports.WorkflowExecutionCancelledError = exports.WorkflowExecutionFailedError = exports.WorkflowExecutionTimedOutError = exports.WorkflowExecutionTerminatedError = void 0;
exports.DeterminismViolationError = exports.IllegalStateError = exports.CancelledError = exports.WorkflowExecutionContinuedAsNewError = exports.WorkflowExecutionCancelledError = exports.WorkflowExecutionFailedError = exports.WorkflowExecutionTimedOutError = exports.WorkflowExecutionTerminatedError = void 0;
class WorkflowExecutionTerminatedError extends Error {

@@ -49,10 +49,9 @@ constructor(message, details, identity) {

*/
class CancellationError extends Error {
constructor(message, source) {
class CancelledError extends Error {
constructor(message) {
super(message);
this.source = source;
this.name = 'CancellationError';
this.name = 'CancelledError';
}
}
exports.CancellationError = CancellationError;
exports.CancelledError = CancelledError;
/**

@@ -59,0 +58,0 @@ * Used in different parts of the project to signal that something unexpected has happened

@@ -41,5 +41,4 @@ /**

* ### [Cancellation and scopes](https://docs.temporal.io/docs/node/workflow-scopes-and-cancellation)
* - {@link cancel}
* - {@link shield}
* - {@link cancellationScope}
* - {@link CancellationScope}
* - {@link Trigger}
*

@@ -54,5 +53,7 @@ * ### [External dependencies](https://docs.temporal.io/docs/node/workflow-external-dependencies)

export { ActivityFunction, ActivityOptions, ApplyMode, ExternalDependencyFunction, ExternalDependency, ExternalDependencies, LocalActivityOptions, RemoteActivityOptions, RetryOptions, Workflow, WorkflowInfo, } from './interfaces';
export { CancellationError, CancellationSource, DeterminismViolationError } from './errors';
export { Context, ContextImpl, sleep, cancel, cancellationScope, shield, uuid4, validateActivityOptions, scheduleActivity, } from './workflow';
export { CancelledError, DeterminismViolationError, IllegalStateError } from './errors';
export { Context, ContextImpl, sleep, uuid4, validateActivityOptions, scheduleActivity } from './workflow';
export * from './interceptors';
export { CancellationScope, CancellationScopeOptions } from './cancellation-scope';
export { Trigger } from './trigger';
export { defaultDataConverter, DataConverter } from './converter/data-converter';

@@ -42,5 +42,4 @@ "use strict";

* ### [Cancellation and scopes](https://docs.temporal.io/docs/node/workflow-scopes-and-cancellation)
* - {@link cancel}
* - {@link shield}
* - {@link cancellationScope}
* - {@link CancellationScope}
* - {@link Trigger}
*

@@ -64,3 +63,3 @@ * ### [External dependencies](https://docs.temporal.io/docs/node/workflow-external-dependencies)

Object.defineProperty(exports, "__esModule", { value: true });
exports.defaultDataConverter = exports.scheduleActivity = exports.validateActivityOptions = exports.uuid4 = exports.shield = exports.cancellationScope = exports.cancel = exports.sleep = exports.ContextImpl = exports.Context = exports.DeterminismViolationError = exports.CancellationError = exports.ApplyMode = void 0;
exports.defaultDataConverter = exports.Trigger = exports.CancellationScope = exports.scheduleActivity = exports.validateActivityOptions = exports.uuid4 = exports.sleep = exports.ContextImpl = exports.Context = exports.IllegalStateError = exports.DeterminismViolationError = exports.CancelledError = exports.ApplyMode = void 0;
require("./global-overrides");

@@ -70,4 +69,5 @@ var interfaces_1 = require("./interfaces");

var errors_1 = require("./errors");
Object.defineProperty(exports, "CancellationError", { enumerable: true, get: function () { return errors_1.CancellationError; } });
Object.defineProperty(exports, "CancelledError", { enumerable: true, get: function () { return errors_1.CancelledError; } });
Object.defineProperty(exports, "DeterminismViolationError", { enumerable: true, get: function () { return errors_1.DeterminismViolationError; } });
Object.defineProperty(exports, "IllegalStateError", { enumerable: true, get: function () { return errors_1.IllegalStateError; } });
var workflow_1 = require("./workflow");

@@ -77,5 +77,2 @@ Object.defineProperty(exports, "Context", { enumerable: true, get: function () { return workflow_1.Context; } });

Object.defineProperty(exports, "sleep", { enumerable: true, get: function () { return workflow_1.sleep; } });
Object.defineProperty(exports, "cancel", { enumerable: true, get: function () { return workflow_1.cancel; } });
Object.defineProperty(exports, "cancellationScope", { enumerable: true, get: function () { return workflow_1.cancellationScope; } });
Object.defineProperty(exports, "shield", { enumerable: true, get: function () { return workflow_1.shield; } });
Object.defineProperty(exports, "uuid4", { enumerable: true, get: function () { return workflow_1.uuid4; } });

@@ -85,4 +82,8 @@ Object.defineProperty(exports, "validateActivityOptions", { enumerable: true, get: function () { return workflow_1.validateActivityOptions; } });

__exportStar(require("./interceptors"), exports);
var cancellation_scope_1 = require("./cancellation-scope");
Object.defineProperty(exports, "CancellationScope", { enumerable: true, get: function () { return cancellation_scope_1.CancellationScope; } });
var trigger_1 = require("./trigger");
Object.defineProperty(exports, "Trigger", { enumerable: true, get: function () { return trigger_1.Trigger; } });
var data_converter_1 = require("./converter/data-converter");
Object.defineProperty(exports, "defaultDataConverter", { enumerable: true, get: function () { return data_converter_1.defaultDataConverter; } });
//# sourceMappingURL=index.js.map
import { Workflow, WorkflowInfo } from './interfaces';
import { IsolateExtension } from './internals';
import { WorkflowInterceptors } from './interceptors';
import { IsolateExtension } from './promise-hooks';
export declare function overrideGlobals(): void;
export declare function initWorkflow(workflow: Workflow, info: WorkflowInfo, randomnessSeed: number[], isolateExtension: IsolateExtension, interceptors: WorkflowInterceptors): void;

@@ -7,2 +7,3 @@ "use strict";

const alea_1 = require("./alea");
const promise_hooks_1 = require("./promise-hooks");
const errors_1 = require("./errors");

@@ -36,3 +37,2 @@ function overrideGlobals() {

reject: () => undefined /* ignore cancellation */,
scope: internals_1.currentScope(),
});

@@ -70,77 +70,5 @@ internals_1.state.commands.push({

internals_1.state.random = alea_1.alea(randomnessSeed);
internals_1.state.isolateExtension = isolateExtension;
isolateExtension.registerPromiseHook((t, p, pp) => {
switch (t) {
case 'init': {
const scope = internals_1.currentScope();
const cancellable = !scope.associated;
if (pp === undefined) {
isolateExtension.setPromiseData(p, { scope, cancellable });
}
else {
let parentScope;
let parentData = isolateExtension.getPromiseData(pp);
if (parentData === undefined) {
parentScope = scope;
parentData = { scope: parentScope, cancellable: false };
isolateExtension.setPromiseData(pp, parentData);
}
else {
parentScope = parentData.scope;
}
isolateExtension.setPromiseData(p, { scope: parentScope, cancellable });
}
scope.associated = true;
break;
}
case 'resolve': {
const data = isolateExtension.getPromiseData(p);
if (data === undefined) {
throw new errors_1.IllegalStateError('Expected promise to have an associated scope');
}
if (data.cancellable) {
if (data.scope.parent === undefined) {
throw new errors_1.IllegalStateError('Resolved promise for orphan scope');
}
const scopes = internals_1.state.childScopes.get(data.scope.parent);
if (scopes === undefined) {
break;
}
scopes.delete(data.scope);
if (scopes.size === 0) {
internals_1.state.childScopes.delete(data.scope.parent);
}
}
break;
}
case 'before': {
const data = isolateExtension.getPromiseData(p);
if (data === undefined) {
throw new errors_1.IllegalStateError('Expected promise to have an associated scope');
}
// TODO: All promises should have a scope attached to them,
// there's a bug where top level promises are not associated with the root scope
let scope = data.scope || internals_1.state.rootScope;
// If scope represents an Activity or Timer, push their parent onto the stack
while (scope.type !== 'scope') {
scope = scope.parent;
if (scope === undefined) {
throw new errors_1.IllegalStateError('Found parentless scope');
}
}
internals_1.pushScope(scope);
break;
}
case 'after': {
const data = isolateExtension.getPromiseData(p);
if (data === undefined) {
throw new errors_1.IllegalStateError('Expected promise to have an associated scope');
}
internals_1.popScope();
break;
}
}
});
new promise_hooks_1.ScopeHookManager(isolateExtension);
}
exports.initWorkflow = initWorkflow;
//# sourceMappingURL=init.js.map

@@ -108,12 +108,2 @@ export * from './dependencies';

}
export interface Scope {
idx: number;
parent?: Scope;
requestCancel: CancellationFunction;
completeCancel: CancellationFunction;
associated: boolean;
type: 'activity' | 'timer' | 'scope';
}
export declare type CancellationFunction = (err: any) => void;
export declare type CancellationFunctionFactory = (reject: CancellationFunction, scope: Scope) => CancellationFunction;
export declare type WorkflowReturnType = any;

@@ -120,0 +110,0 @@ export declare type WorkflowSignalType = (...args: any[]) => Promise<void> | void;

import ivm from 'isolated-vm';
import { coresdk } from '@temporalio/proto';
import { RNG } from './alea';
import { ActivityOptions, ApplyMode, CancellationFunctionFactory, ExternalDependencyFunction, ExternalDependencies, Scope, Workflow, WorkflowInfo } from './interfaces';
import { ActivityOptions, ApplyMode, ExternalDependencyFunction, ExternalDependencies, Workflow, WorkflowInfo } from './interfaces';
import { WorkflowInterceptors } from './interceptors';

@@ -11,18 +11,3 @@ export declare type ResolveFunction<T = any> = (val: T) => any;

reject: RejectFunction;
scope: Scope;
}
export declare type HookType = 'init' | 'resolve' | 'before' | 'after';
export declare type PromiseHook = (t: HookType, p: Promise<any>, pp?: Promise<any>) => void;
export interface PromiseData {
scope: Scope;
cancellable: boolean;
}
/**
* Interface for the native (c++) isolate extension, exposes method for working with the v8 Promise hook and custom Promise data
*/
export interface IsolateExtension {
registerPromiseHook(hook: PromiseHook): void;
setPromiseData(p: Promise<any>, s: PromiseData): void;
getPromiseData(p: Promise<any>): PromiseData | undefined;
}
export declare type ActivationHandlerFunction<K extends keyof coresdk.workflow_activation.IWFActivationJob> = (activation: NonNullable<coresdk.workflow_activation.IWFActivationJob[K]>) => void;

@@ -74,14 +59,2 @@ export declare type ActivationHandler = {

readonly completions: Map<number, Completion>;
/**
* A reference to the root scope object
*/
readonly rootScope: Scope;
/**
* A stack for keeping track of the chain of scopes
*/
readonly scopeStack: Scope[];
/**
* Mapping of parent to child scopes
*/
readonly childScopes: Map<Scope, Set<Scope>>;
interceptors: WorkflowInterceptors;

@@ -108,6 +81,2 @@ /**

nextSeq: number;
/**
* An incremental sequence assigned to each created scope for tracking purposes
*/
nextScopeIdx: number;
get now(): number;

@@ -120,6 +89,2 @@ set now(value: number);

/**
* Reference to the native isolate extension
*/
isolateExtension?: IsolateExtension;
/**
* Information about the current Workflow

@@ -170,7 +135,2 @@ */

export declare function resolveExternalDependencies(results: ExternalDependencyResult[]): void;
export declare function currentScope(): Scope;
export declare function pushScope(scope: Scope): Scope;
export declare function popScope(): void;
export declare function propagateCancellation(method: 'requestCancel' | 'completeCancel'): CancellationFunctionFactory;
export declare function childScope<T>(type: Scope['type'], makeRequestCancellation: CancellationFunctionFactory, makeCompleteCancellation: CancellationFunctionFactory, fn: () => Promise<T>): Promise<T>;
export {};

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.childScope = exports.propagateCancellation = exports.popScope = exports.pushScope = exports.currentScope = exports.resolveExternalDependencies = exports.inject = exports.getAndResetPendingExternalCalls = exports.concludeActivation = exports.state = exports.State = exports.activate = exports.Activator = void 0;
exports.resolveExternalDependencies = exports.inject = exports.getAndResetPendingExternalCalls = exports.concludeActivation = exports.state = exports.State = exports.activate = exports.Activator = void 0;
const long_1 = __importDefault(require("long"));

@@ -51,2 +51,3 @@ const protobufjs = __importStar(require("protobufjs/minimal"));

const time_1 = require("./time");
const cancellation_scope_1 = require("./cancellation-scope");
protobufjs.util.Long = long_1.default;

@@ -72,3 +73,3 @@ protobufjs.configure();

exports.state.cancelled = true;
rootScopeCancel(new errors_1.CancellationError('Workflow cancelled', 'external'));
cancellation_scope_1.ROOT_SCOPE.cancel();
}

@@ -83,12 +84,7 @@ fireTimer(activation) {

}
const { resolve, reject, scope } = consumeCompletion(idToSeq(activation.activityId));
const { resolve, reject } = consumeCompletion(idToSeq(activation.activityId));
if (activation.result.completed) {
const completed = activation.result.completed;
const result = completed.result ? data_converter_1.defaultDataConverter.fromPayload(completed.result) : undefined;
if (result === undefined) {
reject(new Error('Failed to convert from payload'));
}
else {
resolve(result);
}
resolve(result);
}

@@ -99,9 +95,3 @@ else if (activation.result.failed) {

else if (activation.result.canceled) {
try {
scope.completeCancel(new errors_1.CancellationError('Activity cancelled', 'internal'));
}
catch (e) {
if (!(e instanceof errors_1.CancellationError))
throw e;
}
reject(new errors_1.CancelledError('Activity cancelled'));
}

@@ -204,14 +194,2 @@ }

exports.activate = activate;
const rootScope = {
type: 'scope',
idx: 0,
associated: true,
requestCancel: () => {
throw new Error('Root scope cannot be cancelled from within a workflow');
},
completeCancel: (err) => {
rootScopeCancel(err);
},
};
const rootScopeCancel = propagateCancellation('completeCancel')(() => undefined, rootScope);
/**

@@ -232,14 +210,2 @@ * Keeps all of the Workflow runtime state like pending completions for activities and timers and the scope stack.

this.completions = new Map();
/**
* A reference to the root scope object
*/
this.rootScope = rootScope;
/**
* A stack for keeping track of the chain of scopes
*/
this.scopeStack = [rootScope];
/**
* Mapping of parent to child scopes
*/
this.childScopes = new Map();
this.interceptors = { inbound: [], outbound: [] };

@@ -267,6 +233,2 @@ /**

/**
* An incremental sequence assigned to each created scope for tracking purposes
*/
this.nextScopeIdx = rootScope.idx + 1;
/**
* This is set every time the workflow executes an activation

@@ -383,3 +345,2 @@ */

reject,
scope: currentScope(),
});

@@ -412,82 +373,2 @@ exports.state.pendingExternalCalls.push({ ifaceName, fnName, args, seq });

exports.resolveExternalDependencies = resolveExternalDependencies;
function currentScope() {
const scope = exports.state.scopeStack[exports.state.scopeStack.length - 1];
if (scope === undefined) {
throw new Error('No scopes in stack');
}
return scope;
}
exports.currentScope = currentScope;
function pushScope(scope) {
exports.state.scopeStack.push(scope);
if (scope.parent === undefined) {
return scope;
}
let children = exports.state.childScopes.get(scope.parent);
if (children === undefined) {
children = new Set();
exports.state.childScopes.set(scope.parent, children);
}
children.add(scope);
return scope;
}
exports.pushScope = pushScope;
function popScope() {
exports.state.scopeStack.pop();
}
exports.popScope = popScope;
function propagateCancellation(method) {
return (reject, scope) => {
return (err) => {
const children = exports.state.childScopes.get(scope);
if (children === undefined) {
throw new Error('Expected to find child scope mapping, got undefined');
}
for (const child of children) {
try {
child[method](err);
}
catch (e) {
// TODO: aggregate errors?
if (e !== err)
reject(e);
}
}
// If no children throw, make sure to reject this promise
reject(err);
};
};
}
exports.propagateCancellation = propagateCancellation;
function cancellationNotSet() {
throw new Error('Cancellation function not set');
}
function childScope(type, makeRequestCancellation, makeCompleteCancellation, fn) {
let requestCancel = cancellationNotSet;
let completeCancel = cancellationNotSet;
const scope = pushScope({
type,
idx: exports.state.nextScopeIdx++,
parent: currentScope(),
requestCancel: (err) => requestCancel(err),
completeCancel: (err) => completeCancel(err),
associated: false,
});
// eslint-disable-next-line no-async-promise-executor
const promise = new Promise(async (resolve, reject) => {
try {
requestCancel = makeRequestCancellation(reject, scope);
completeCancel = makeCompleteCancellation(reject, scope);
const promise = fn();
const result = await promise;
resolve(result);
}
catch (e) {
reject(e);
}
});
popScope();
return promise;
}
exports.childScope = childScope;
//# sourceMappingURL=internals.js.map

@@ -64,3 +64,3 @@ import { ActivityFunction, ActivityOptions, ExternalDependencies, RemoteActivityOptions, WorkflowInfo } from './interfaces';

*
* The workflow might still be running in case {@link CancellationError}s were caught.
* The workflow might still be running in case {@link CancelledError}s were caught.
*/

@@ -99,26 +99,2 @@ get cancelled(): boolean;

/**
* Wraps Promise returned from `fn` with a cancellation scope.
* The returned Promise may be be cancelled with `cancel()` and will be cancelled
* if a parent scope is cancelled, e.g. when the entire workflow is cancelled.
*
* @see {@link https://docs.temporal.io/docs/node/workflow-scopes-and-cancellation | Workflow scopes and cancellation}
*/
export declare function cancellationScope<T>(fn: () => Promise<T>): Promise<T>;
/**
* Wraps the Promise returned from `fn` with a shielded scope.
* Any child scopes of this scope will *not* be cancelled if `shield` is cancelled.
* By default `shield` throws the original {@link CancellationError} in order for any awaiter
* to immediately be notified of the cancellation.
* @param throwOnCancellation - Pass false in case the result of the shielded `Promise` is needed
* despite cancellation. To see if the workflow was cancelled while waiting, check `Context.cancelled`.
* @see {@link https://docs.temporal.io/docs/node/workflow-scopes-and-cancellation | Workflow scopes and cancellation}
*/
export declare function shield<T>(fn: () => Promise<T>, throwOnCancellation?: boolean): Promise<T>;
/**
* Cancel a scope created by an activity, timer or cancellationScope.
*
* @see {@link https://docs.temporal.io/docs/node/workflow-scopes-and-cancellation | Workflow scopes and cancellation}
*/
export declare function cancel(promise: Promise<any>, reason?: string): void;
/**
* Generate an RFC compliant V4 uuid.

@@ -125,0 +101,0 @@ * Uses the workflow's deterministic PRNG making it safe for use within a workflow.

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.uuid4 = exports.cancel = exports.shield = exports.cancellationScope = exports.Context = exports.ContextImpl = exports.scheduleActivity = exports.validateActivityOptions = exports.sleep = void 0;
exports.uuid4 = exports.Context = exports.ContextImpl = exports.scheduleActivity = exports.validateActivityOptions = exports.sleep = void 0;
const internals_1 = require("./internals");

@@ -9,2 +9,5 @@ const data_converter_1 = require("./converter/data-converter");

const interceptors_1 = require("./interceptors");
const cancellation_scope_1 = require("./cancellation-scope");
// Avoid a circular dependency
cancellation_scope_1.registerSleepImplementation(sleep);
/**

@@ -15,6 +18,23 @@ * Push a startTimer command into state accumulator and register completion

return new Promise((resolve, reject) => {
const scope = cancellation_scope_1.CancellationScope.current();
if (scope.consideredCancelled) {
scope.cancelRequested.catch(reject);
return;
}
if (scope.cancellable) {
scope.cancelRequested.catch((err) => {
if (!internals_1.state.completions.delete(input.seq)) {
return; // Already resolved
}
internals_1.state.commands.push({
cancelTimer: {
timerId: `${input.seq}`,
},
});
reject(err);
});
}
internals_1.state.completions.set(input.seq, {
resolve,
reject,
scope: internals_1.currentScope(),
});

@@ -39,19 +59,6 @@ internals_1.state.commands.push({

const seq = internals_1.state.nextSeq++;
const cancellation = (reject) => (err) => {
if (!internals_1.state.completions.delete(seq)) {
return; // Already resolved
}
internals_1.state.commands.push({
cancelTimer: {
timerId: `${seq}`,
},
});
reject(err);
};
return internals_1.childScope('timer', cancellation, cancellation, () => {
const execute = interceptors_1.composeInterceptors(internals_1.state.interceptors.outbound, 'startTimer', timerNextHandler);
return execute({
durationMs: ms,
seq,
});
const execute = interceptors_1.composeInterceptors(internals_1.state.interceptors.outbound, 'startTimer', timerNextHandler);
return execute({
durationMs: ms,
seq,
});

@@ -78,6 +85,19 @@ }

return new Promise((resolve, reject) => {
const scope = cancellation_scope_1.CancellationScope.current();
if (scope.consideredCancelled) {
scope.cancelRequested.catch(reject);
return;
}
if (scope.cancellable) {
scope.cancelRequested.catch(() => {
internals_1.state.commands.push({
requestCancelActivity: {
activityId: `${seq}`,
},
});
});
}
internals_1.state.completions.set(seq, {
resolve,
reject,
scope: internals_1.currentScope(),
});

@@ -115,18 +135,9 @@ internals_1.state.commands.push({

const seq = internals_1.state.nextSeq++;
return internals_1.childScope('activity', () => (_err) => {
internals_1.state.commands.push({
requestCancelActivity: {
activityId: `${seq}`,
// TODO: reason: err instanceof Error ? err.message : undefined,
},
});
}, (reject) => reject, () => {
const execute = interceptors_1.composeInterceptors(internals_1.state.interceptors.outbound, 'scheduleActivity', scheduleActivityNextHandler);
return execute({
activityType: activityType,
headers: new Map(),
options,
args,
seq,
});
const execute = interceptors_1.composeInterceptors(internals_1.state.interceptors.outbound, 'scheduleActivity', scheduleActivityNextHandler);
return execute({
activityType: activityType,
headers: new Map(),
options,
args,
seq,
});

@@ -202,3 +213,3 @@ }

*
* The workflow might still be running in case {@link CancellationError}s were caught.
* The workflow might still be running in case {@link CancelledError}s were caught.
*/

@@ -260,56 +271,2 @@ get cancelled() {

/**
* Wraps Promise returned from `fn` with a cancellation scope.
* The returned Promise may be be cancelled with `cancel()` and will be cancelled
* if a parent scope is cancelled, e.g. when the entire workflow is cancelled.
*
* @see {@link https://docs.temporal.io/docs/node/workflow-scopes-and-cancellation | Workflow scopes and cancellation}
*/
function cancellationScope(fn) {
return internals_1.childScope('scope', internals_1.propagateCancellation('requestCancel'), internals_1.propagateCancellation('completeCancel'), fn);
}
exports.cancellationScope = cancellationScope;
const ignoreCancellation = () => () => undefined;
/**
* Wraps the Promise returned from `fn` with a shielded scope.
* Any child scopes of this scope will *not* be cancelled if `shield` is cancelled.
* By default `shield` throws the original {@link CancellationError} in order for any awaiter
* to immediately be notified of the cancellation.
* @param throwOnCancellation - Pass false in case the result of the shielded `Promise` is needed
* despite cancellation. To see if the workflow was cancelled while waiting, check `Context.cancelled`.
* @see {@link https://docs.temporal.io/docs/node/workflow-scopes-and-cancellation | Workflow scopes and cancellation}
*/
function shield(fn, throwOnCancellation = true) {
const cancellationFunction = throwOnCancellation
? (cancel) => cancel
: ignoreCancellation;
return internals_1.childScope('scope', cancellationFunction, cancellationFunction, fn);
}
exports.shield = shield;
/**
* Cancel a scope created by an activity, timer or cancellationScope.
*
* @see {@link https://docs.temporal.io/docs/node/workflow-scopes-and-cancellation | Workflow scopes and cancellation}
*/
function cancel(promise, reason = 'Cancelled') {
if (internals_1.state.isolateExtension === undefined) {
// This shouldn't happen
throw new Error('Uninitialized workflow');
}
const data = internals_1.state.isolateExtension.getPromiseData(promise);
if (data === undefined) {
throw new Error('Expected to find promise scope, got undefined');
}
if (!data.cancellable) {
throw new Error('Promise is not cancellable');
}
try {
data.scope.requestCancel(new errors_1.CancellationError(reason, 'internal'));
}
catch (e) {
if (!(e instanceof errors_1.CancellationError))
throw e;
}
}
exports.cancel = cancel;
/**
* Generate an RFC compliant V4 uuid.

@@ -316,0 +273,0 @@ * Uses the workflow's deterministic PRNG making it safe for use within a workflow.

{
"name": "@temporalio/workflow",
"version": "0.3.0",
"version": "0.3.1",
"description": "Temporal.io SDK Workflow sub-package",

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

},
"gitHead": "d35439fbe6291d3ccda432572f142bd9537699fc"
"gitHead": "3e16d09a18550c04a797d73e95ad73b765b94c95"
}

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