@temporalio/workflow
Advanced tools
Comparing version 1.0.0-rc.1 to 1.0.0
@@ -23,2 +23,4 @@ import { RetryPolicy, TemporalFailure } from '@temporalio/common'; | ||
* Indexed information attached to the Workflow Execution | ||
* | ||
* This value may change during the lifetime of an Execution. | ||
*/ | ||
@@ -45,2 +47,10 @@ searchAttributes: SearchAttributes; | ||
/** | ||
* Length of Workflow history up until the current Workflow Task. | ||
* | ||
* This value changes during the lifetime of an Execution. | ||
* | ||
* You may safely use this information to decide when to {@link continueAsNew}. | ||
*/ | ||
historyLength: number; | ||
/** | ||
* Task queue this Workflow is executing on | ||
@@ -96,3 +106,12 @@ */ | ||
cronScheduleToScheduleInterval?: number; | ||
unsafe: UnsafeWorkflowInfo; | ||
} | ||
/** | ||
* Unsafe information about the current Workflow Execution. | ||
* | ||
* Never rely on this information in Workflow logic as it will cause non-deterministic behavior. | ||
*/ | ||
export interface UnsafeWorkflowInfo { | ||
isReplaying: boolean; | ||
} | ||
export interface ParentWorkflowInfo { | ||
@@ -99,0 +118,0 @@ workflowId: string; |
@@ -149,10 +149,2 @@ import { PayloadConverter } from '@temporalio/common'; | ||
/** | ||
* Whether a Workflow is replaying history or processing new events | ||
*/ | ||
isReplaying?: boolean; | ||
/** | ||
* ID of last WorkflowTaskStarted event | ||
*/ | ||
historyLength?: number; | ||
/** | ||
* A deterministic RNG, used by the isolate's overridden Math.random | ||
@@ -159,0 +151,0 @@ */ |
@@ -17,4 +17,2 @@ /** | ||
patches: string[]; | ||
isReplaying: boolean; | ||
historyLength: number; | ||
} | ||
@@ -32,3 +30,3 @@ export interface ImportFunctions { | ||
*/ | ||
export declare function initRuntime({ info, randomnessSeed, now, patches, isReplaying, historyLength, }: WorkflowCreateOptions): Promise<void>; | ||
export declare function initRuntime({ info, randomnessSeed, now, patches }: WorkflowCreateOptions): Promise<void>; | ||
/** | ||
@@ -35,0 +33,0 @@ * Run a chunk of activation jobs |
@@ -103,3 +103,3 @@ "use strict"; | ||
*/ | ||
async function initRuntime({ info, randomnessSeed, now, patches, isReplaying, historyLength, }) { | ||
async function initRuntime({ info, randomnessSeed, now, patches }) { | ||
const global = globalThis; | ||
@@ -117,4 +117,3 @@ // Set the runId globally on the context so it can be retrieved in the case | ||
internals_1.state.random = (0, alea_1.alea)(randomnessSeed); | ||
internals_1.state.historyLength = historyLength; | ||
if (isReplaying) { | ||
if (info.unsafe.isReplaying) { | ||
for (const patch of patches) { | ||
@@ -177,4 +176,4 @@ internals_1.state.knownPresentPatches.add(patch); | ||
} | ||
internals_1.state.isReplaying = activation.isReplaying ?? false; | ||
internals_1.state.historyLength = activation.historyLength; | ||
internals_1.state.info.unsafe.isReplaying = activation.isReplaying ?? false; | ||
internals_1.state.info.historyLength = activation.historyLength; | ||
} | ||
@@ -181,0 +180,0 @@ // Cast from the interface to the class which has the `variant` attribute. |
@@ -209,3 +209,25 @@ import { ActivityFunction, ActivityOptions, LocalActivityOptions, QueryDefinition, SearchAttributes, SignalDefinition, UntypedActivities, WithWorkflowArgs, Workflow, WorkflowResultType, WorkflowReturnType } from '@temporalio/internal-workflow-common'; | ||
/** | ||
* Get information about the current Workflow | ||
* Get information about the current Workflow. | ||
* | ||
* ⚠️ We recommend calling `workflowInfo()` whenever accessing {@link WorkflowInfo} fields. Some WorkflowInfo fields | ||
* change during the lifetime of an Execution—like {@link WorkflowInfo.historyLength} and | ||
* {@link WorkflowInfo.searchAttributes}—and some may be changeable in the future—like {@link WorkflowInfo.taskQueue}. | ||
* | ||
* ```ts | ||
* // GOOD | ||
* function myWorkflow() { | ||
* doSomething(workflowInfo().searchAttributes) | ||
* ... | ||
* doSomethingElse(workflowInfo().searchAttributes) | ||
* } | ||
* ``` | ||
* | ||
* ```ts | ||
* // BAD | ||
* function myWorkflow() { | ||
* const attributes = workflowInfo().searchAttributes | ||
* doSomething(attributes) | ||
* ... | ||
* doSomethingElse(attributes) | ||
* } | ||
*/ | ||
@@ -386,30 +408,2 @@ export declare function workflowInfo(): WorkflowInfo; | ||
export declare function upsertSearchAttributes(searchAttributes: SearchAttributes): void; | ||
/** | ||
* Unsafe information about the currently executing Workflow Task. | ||
* | ||
* Never rely on this information in Workflow logic as it will cause non-deterministic behavior. | ||
*/ | ||
export interface UnsafeTaskInfo { | ||
isReplaying: boolean; | ||
} | ||
/** | ||
* Information about the currently executing Workflow Task. | ||
* | ||
* Meant for advanced usage. | ||
*/ | ||
export interface TaskInfo { | ||
/** | ||
* Length of Workflow history up until the current Workflow Task. | ||
* | ||
* You may safely use this information to decide when to {@link continueAsNew}. | ||
*/ | ||
historyLength: number; | ||
unsafe: UnsafeTaskInfo; | ||
} | ||
/** | ||
* Get information about the currently executing Workflow Task. | ||
* | ||
* See {@link TaskInfo} | ||
*/ | ||
export declare function taskInfo(): TaskInfo; | ||
export declare const stackTraceQuery: QueryDefinition<string, []>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.stackTraceQuery = exports.taskInfo = exports.upsertSearchAttributes = exports.setHandler = exports.defineQuery = exports.defineSignal = exports.condition = exports.deprecatePatch = exports.patched = exports.uuid4 = exports.continueAsNew = exports.makeContinueAsNewFunc = exports.proxySinks = exports.inWorkflowContext = exports.workflowInfo = exports.executeChild = exports.startChild = exports.getExternalWorkflowHandle = exports.proxyLocalActivities = exports.proxyActivities = exports.NotAnActivityMethod = exports.scheduleLocalActivity = exports.scheduleActivity = exports.sleep = exports.addDefaultWorkflowOptions = void 0; | ||
exports.stackTraceQuery = exports.upsertSearchAttributes = exports.setHandler = exports.defineQuery = exports.defineSignal = exports.condition = exports.deprecatePatch = exports.patched = exports.uuid4 = exports.continueAsNew = exports.makeContinueAsNewFunc = exports.proxySinks = exports.inWorkflowContext = exports.workflowInfo = exports.executeChild = exports.startChild = exports.getExternalWorkflowHandle = exports.proxyLocalActivities = exports.proxyActivities = exports.NotAnActivityMethod = exports.scheduleLocalActivity = exports.scheduleActivity = exports.sleep = exports.addDefaultWorkflowOptions = void 0; | ||
const common_1 = require("@temporalio/common"); | ||
@@ -564,3 +564,25 @@ const internal_workflow_common_1 = require("@temporalio/internal-workflow-common"); | ||
/** | ||
* Get information about the current Workflow | ||
* Get information about the current Workflow. | ||
* | ||
* ⚠️ We recommend calling `workflowInfo()` whenever accessing {@link WorkflowInfo} fields. Some WorkflowInfo fields | ||
* change during the lifetime of an Execution—like {@link WorkflowInfo.historyLength} and | ||
* {@link WorkflowInfo.searchAttributes}—and some may be changeable in the future—like {@link WorkflowInfo.taskQueue}. | ||
* | ||
* ```ts | ||
* // GOOD | ||
* function myWorkflow() { | ||
* doSomething(workflowInfo().searchAttributes) | ||
* ... | ||
* doSomethingElse(workflowInfo().searchAttributes) | ||
* } | ||
* ``` | ||
* | ||
* ```ts | ||
* // BAD | ||
* function myWorkflow() { | ||
* const attributes = workflowInfo().searchAttributes | ||
* doSomething(attributes) | ||
* ... | ||
* doSomethingElse(attributes) | ||
* } | ||
*/ | ||
@@ -774,3 +796,6 @@ function workflowInfo() { | ||
} | ||
const usePatch = !internals_1.state.isReplaying || internals_1.state.knownPresentPatches.has(patchId); | ||
if (internals_1.state.info === undefined) { | ||
throw new internal_workflow_common_1.IllegalStateError('Workflow uninitialized'); | ||
} | ||
const usePatch = !internals_1.state.info.unsafe.isReplaying || internals_1.state.knownPresentPatches.has(patchId); | ||
// Avoid sending commands for patches core already knows about. | ||
@@ -920,21 +945,3 @@ // This optimization enables development of automatic patching tools. | ||
exports.upsertSearchAttributes = upsertSearchAttributes; | ||
/** | ||
* Get information about the currently executing Workflow Task. | ||
* | ||
* See {@link TaskInfo} | ||
*/ | ||
function taskInfo() { | ||
const { isReplaying, historyLength } = internals_1.state; | ||
if (isReplaying == null || historyLength == null) { | ||
throw new internal_workflow_common_1.IllegalStateError('Workflow uninitialized'); | ||
} | ||
return { | ||
historyLength, | ||
unsafe: { | ||
isReplaying, | ||
}, | ||
}; | ||
} | ||
exports.taskInfo = taskInfo; | ||
exports.stackTraceQuery = defineQuery('__stack_trace'); | ||
//# sourceMappingURL=workflow.js.map |
@@ -5,3 +5,3 @@ Temporal TypeScript SDK | ||
Copyright (c) 2021 Temporal Technologies, Inc. All Rights Reserved | ||
Copyright (c) 2021 Temporal Technologies Inc. All Rights Reserved | ||
@@ -8,0 +8,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy |
{ | ||
"name": "@temporalio/workflow", | ||
"version": "1.0.0-rc.1", | ||
"version": "1.0.0", | ||
"description": "Temporal.io SDK Workflow sub-package", | ||
@@ -15,3 +15,3 @@ "keywords": [ | ||
"license": "MIT", | ||
"author": "Roey Berman <roey@temporal.io>", | ||
"author": "Temporal Technologies Inc. <sdk@temporal.io>", | ||
"main": "lib/index.js", | ||
@@ -21,5 +21,5 @@ "types": "lib/index.d.ts", | ||
"dependencies": { | ||
"@temporalio/common": "^1.0.0-rc.1", | ||
"@temporalio/internal-workflow-common": "^1.0.0-rc.1", | ||
"@temporalio/proto": "^1.0.0-rc.1" | ||
"@temporalio/common": "^1.0.0", | ||
"@temporalio/internal-workflow-common": "^1.0.0", | ||
"@temporalio/proto": "^1.0.0" | ||
}, | ||
@@ -33,3 +33,3 @@ "publishConfig": { | ||
], | ||
"gitHead": "723de0fbc7a04e68084ec99453578e7027eb3803" | ||
"gitHead": "c4fc4dc608bf58701c11b6ae02d1d63b4457718d" | ||
} |
@@ -27,2 +27,4 @@ import { RetryPolicy, TemporalFailure } from '@temporalio/common'; | ||
* Indexed information attached to the Workflow Execution | ||
* | ||
* This value may change during the lifetime of an Execution. | ||
*/ | ||
@@ -54,2 +56,11 @@ searchAttributes: SearchAttributes; | ||
/** | ||
* Length of Workflow history up until the current Workflow Task. | ||
* | ||
* This value changes during the lifetime of an Execution. | ||
* | ||
* You may safely use this information to decide when to {@link continueAsNew}. | ||
*/ | ||
historyLength: number; | ||
/** | ||
* Task queue this Workflow is executing on | ||
@@ -119,4 +130,15 @@ */ | ||
cronScheduleToScheduleInterval?: number; | ||
unsafe: UnsafeWorkflowInfo; | ||
} | ||
/** | ||
* Unsafe information about the current Workflow Execution. | ||
* | ||
* Never rely on this information in Workflow logic as it will cause non-deterministic behavior. | ||
*/ | ||
export interface UnsafeWorkflowInfo { | ||
isReplaying: boolean; | ||
} | ||
export interface ParentWorkflowInfo { | ||
@@ -123,0 +145,0 @@ workflowId: string; |
@@ -480,12 +480,2 @@ import { PayloadConverter } from '@temporalio/common'; | ||
/** | ||
* Whether a Workflow is replaying history or processing new events | ||
*/ | ||
isReplaying?: boolean; | ||
/** | ||
* ID of last WorkflowTaskStarted event | ||
*/ | ||
historyLength?: number; | ||
/** | ||
* A deterministic RNG, used by the isolate's overridden Math.random | ||
@@ -492,0 +482,0 @@ */ |
@@ -25,4 +25,2 @@ /** | ||
patches: string[]; | ||
isReplaying: boolean; | ||
historyLength: number; | ||
} | ||
@@ -112,10 +110,3 @@ | ||
*/ | ||
export async function initRuntime({ | ||
info, | ||
randomnessSeed, | ||
now, | ||
patches, | ||
isReplaying, | ||
historyLength, | ||
}: WorkflowCreateOptions): Promise<void> { | ||
export async function initRuntime({ info, randomnessSeed, now, patches }: WorkflowCreateOptions): Promise<void> { | ||
const global = globalThis as any; | ||
@@ -134,5 +125,4 @@ // Set the runId globally on the context so it can be retrieved in the case | ||
state.random = alea(randomnessSeed); | ||
state.historyLength = historyLength; | ||
if (isReplaying) { | ||
if (info.unsafe.isReplaying) { | ||
for (const patch of patches) { | ||
@@ -199,4 +189,4 @@ state.knownPresentPatches.add(patch); | ||
} | ||
state.isReplaying = activation.isReplaying ?? false; | ||
state.historyLength = activation.historyLength; | ||
state.info.unsafe.isReplaying = activation.isReplaying ?? false; | ||
state.info.historyLength = activation.historyLength; | ||
} | ||
@@ -203,0 +193,0 @@ |
@@ -820,3 +820,25 @@ import { mapToPayloads, searchAttributePayloadConverter, toPayloads } from '@temporalio/common'; | ||
/** | ||
* Get information about the current Workflow | ||
* Get information about the current Workflow. | ||
* | ||
* ⚠️ We recommend calling `workflowInfo()` whenever accessing {@link WorkflowInfo} fields. Some WorkflowInfo fields | ||
* change during the lifetime of an Execution—like {@link WorkflowInfo.historyLength} and | ||
* {@link WorkflowInfo.searchAttributes}—and some may be changeable in the future—like {@link WorkflowInfo.taskQueue}. | ||
* | ||
* ```ts | ||
* // GOOD | ||
* function myWorkflow() { | ||
* doSomething(workflowInfo().searchAttributes) | ||
* ... | ||
* doSomethingElse(workflowInfo().searchAttributes) | ||
* } | ||
* ``` | ||
* | ||
* ```ts | ||
* // BAD | ||
* function myWorkflow() { | ||
* const attributes = workflowInfo().searchAttributes | ||
* doSomething(attributes) | ||
* ... | ||
* doSomethingElse(attributes) | ||
* } | ||
*/ | ||
@@ -1041,3 +1063,6 @@ export function workflowInfo(): WorkflowInfo { | ||
} | ||
const usePatch = !state.isReplaying || state.knownPresentPatches.has(patchId); | ||
if (state.info === undefined) { | ||
throw new IllegalStateError('Workflow uninitialized'); | ||
} | ||
const usePatch = !state.info.unsafe.isReplaying || state.knownPresentPatches.has(patchId); | ||
// Avoid sending commands for patches core already knows about. | ||
@@ -1224,45 +1249,2 @@ // This optimization enables development of automatic patching tools. | ||
/** | ||
* Unsafe information about the currently executing Workflow Task. | ||
* | ||
* Never rely on this information in Workflow logic as it will cause non-deterministic behavior. | ||
*/ | ||
export interface UnsafeTaskInfo { | ||
isReplaying: boolean; | ||
} | ||
/** | ||
* Information about the currently executing Workflow Task. | ||
* | ||
* Meant for advanced usage. | ||
*/ | ||
export interface TaskInfo { | ||
/** | ||
* Length of Workflow history up until the current Workflow Task. | ||
* | ||
* You may safely use this information to decide when to {@link continueAsNew}. | ||
*/ | ||
historyLength: number; | ||
unsafe: UnsafeTaskInfo; | ||
} | ||
/** | ||
* Get information about the currently executing Workflow Task. | ||
* | ||
* See {@link TaskInfo} | ||
*/ | ||
export function taskInfo(): TaskInfo { | ||
const { isReplaying, historyLength } = state; | ||
if (isReplaying == null || historyLength == null) { | ||
throw new IllegalStateError('Workflow uninitialized'); | ||
} | ||
return { | ||
historyLength, | ||
unsafe: { | ||
isReplaying, | ||
}, | ||
}; | ||
} | ||
export const stackTraceQuery = defineQuery<string>('__stack_trace'); |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
310656
0
6597