@temporalio/workflow 1.17.2 → 1.17.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@temporalio/workflow",
3
- "version": "1.17.2",
3
+ "version": "1.17.3",
4
4
  "description": "Temporal.io SDK Workflow sub-package",
5
5
  "keywords": [
6
6
  "temporal",
@@ -27,8 +27,8 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "nexus-rpc": "^0.0.2",
30
- "@temporalio/proto": "1.17.2",
31
- "@temporalio/common": "1.17.2"
30
+ "@temporalio/common": "1.17.3",
31
+ "@temporalio/proto": "1.17.3"
32
32
  },
33
33
  "devDependencies": {
34
34
  "ava": "^5.3.1",
@@ -0,0 +1,5 @@
1
+ import { assertInWorkflowContext } from './global-attributes';
2
+
3
+ export function currentRandom(): number {
4
+ return assertInWorkflowContext('Workflow random APIs may only be used from workflow context.').currentRandom();
5
+ }
package/src/flags.ts CHANGED
@@ -114,7 +114,7 @@ type AltConditionFn = (ctx: { info: WorkflowInfo; sdkVersion?: string }) => bool
114
114
 
115
115
  function buildIdSdkVersionMatches(version: RegExp): AltConditionFn {
116
116
  const regex = new RegExp(`^@temporalio/worker@(${version.source})[+]`);
117
- return ({ info }) => info.currentBuildId != null && regex.test(info.currentBuildId); // eslint-disable-line @typescript-eslint/no-deprecated
117
+ return ({ info }) => info.currentBuildId != null && regex.test(info.currentBuildId);
118
118
  }
119
119
 
120
120
  type SemVer = {
@@ -5,6 +5,7 @@
5
5
  */
6
6
  import { msToTs } from '@temporalio/common/lib/time';
7
7
  import { CancellationScope } from './cancellation-scope';
8
+ import { currentRandom } from './current-random';
8
9
  import { DeterminismViolationError } from './errors';
9
10
  import { getActivator } from './global-attributes';
10
11
  import { SdkFlags } from './flags';
@@ -103,6 +104,6 @@ export function overrideGlobals(): void {
103
104
  }
104
105
  };
105
106
 
106
- // activator.random is mutable, don't hardcode its reference
107
- Math.random = () => getActivator().random();
107
+ // currentRandom() dispatches to a scoped stream when WorkflowRandomStream.with(...) is active.
108
+ Math.random = currentRandom;
108
109
  }
package/src/index.ts CHANGED
@@ -93,8 +93,8 @@ export {
93
93
  PayloadConverter,
94
94
  RetryPolicy,
95
95
  rootCause,
96
- SearchAttributes, // eslint-disable-line @typescript-eslint/no-deprecated
97
- SearchAttributeValue, // eslint-disable-line @typescript-eslint/no-deprecated
96
+ SearchAttributes,
97
+ SearchAttributeValue,
98
98
  ServerFailure,
99
99
  TemporalFailure,
100
100
  TerminatedFailure,
@@ -136,6 +136,8 @@ export {
136
136
  WorkflowInfo,
137
137
  } from './interfaces';
138
138
  export { proxySinks, Sink, SinkCall, SinkFunction, Sinks } from './sinks';
139
+ export type { WorkflowRandomStream } from './random-streams';
140
+ export { getRandomStream, workflowRandom } from './random-streams';
139
141
  export { log } from './logs';
140
142
  export { Trigger } from './trigger';
141
143
  export * from './workflow';
@@ -0,0 +1,31 @@
1
+ import { composeInterceptorsWith, type Next } from '@temporalio/common/lib/interceptors';
2
+ import { getActivator } from './global-attributes';
3
+
4
+ /**
5
+ * Compose workflow interceptors while making every `next(...)` continuation re-enter
6
+ * the workflow-random scope that was current when that continuation was created.
7
+ *
8
+ * This is intentionally a thin wrapper over the shared interceptor composition helper
9
+ * in `packages/common`. The shared helper owns the actual chain-construction algorithm,
10
+ * ordering, and `next(...)` wiring so workflow code cannot silently drift away from the
11
+ * semantics used by the rest of the SDK.
12
+ *
13
+ * The workflow-specific behavior lives entirely in the `wrapNext` hook we pass into that
14
+ * shared helper. Each `next(...)` continuation handed to a workflow interceptor is wrapped
15
+ * with `Activator.bindCurrentRandom(...)`, which captures the currently active workflow
16
+ * random scope, including the absence of any scoped override. When the interceptor later
17
+ * calls `next(...)`, the wrapper restores that captured scope before entering the rest of
18
+ * the interceptor chain or the base workflow/runtime handler.
19
+ *
20
+ * That is the behavior we need for `WorkflowRandomStream.with(...)`: a temporary
21
+ * plugin/interceptor scope should apply to the plugin's own code, but it must not
22
+ * leak through `next(...)` into downstream workflow code unless that downstream code
23
+ * explicitly establishes its own scope.
24
+ */
25
+ export function composeInterceptors<I, M extends keyof I>(interceptors: I[], method: M, next: Next<I, M>): Next<I, M> {
26
+ const activator = getActivator();
27
+ return composeInterceptorsWith(interceptors, method, next, ((wrappedNext) =>
28
+ activator.bindCurrentRandom(wrappedNext as any)) as <F extends (...args: any[]) => any>(
29
+ next: F
30
+ ) => F) as unknown as Next<I, M>;
31
+ }
package/src/interfaces.ts CHANGED
@@ -47,7 +47,7 @@ export interface WorkflowInfo {
47
47
  * This value may change during the lifetime of an Execution.
48
48
  * @deprecated Use {@link typedSearchAttributes} instead.
49
49
  */
50
- readonly searchAttributes: SearchAttributes; // eslint-disable-line @typescript-eslint/no-deprecated
50
+ readonly searchAttributes: SearchAttributes;
51
51
 
52
52
  /**
53
53
  * Indexed information attached to the Workflow Execution, exposed through an interface.
@@ -337,7 +337,7 @@ export interface ContinueAsNewOptions {
337
337
  * Searchable attributes to attach to next Workflow run
338
338
  * @deprecated Use {@link typedSearchAttributes} instead.
339
339
  */
340
- searchAttributes?: SearchAttributes; // eslint-disable-line @typescript-eslint/no-deprecated
340
+ searchAttributes?: SearchAttributes;
341
341
  /**
342
342
  * Specifies additional indexed information to attach to the Workflow Execution. More info:
343
343
  * https://docs.temporal.io/docs/typescript/search-attributes
@@ -357,7 +357,7 @@ export interface ContinueAsNewOptions {
357
357
  *
358
358
  * @deprecated Worker Versioning is now deprecated. Please use the Worker Deployment API instead: https://docs.temporal.io/worker-deployments
359
359
  */
360
- versioningIntent?: VersioningIntent; // eslint-disable-line @typescript-eslint/no-deprecated
360
+ versioningIntent?: VersioningIntent;
361
361
  /**
362
362
  * Defines the versioning behavior to be used by the first task of a new workflow run in a continue-as-new chain.
363
363
  *
@@ -567,7 +567,7 @@ export interface ChildWorkflowOptions extends Omit<CommonWorkflowOptions, 'workf
567
567
  *
568
568
  * @deprecated Worker Versioning is now deprecated. Please use the Worker Deployment API instead: https://docs.temporal.io/worker-deployments
569
569
  */
570
- versioningIntent?: VersioningIntent; // eslint-disable-line @typescript-eslint/no-deprecated
570
+ versioningIntent?: VersioningIntent;
571
571
  }
572
572
 
573
573
  export type RequiredChildWorkflowOptions = Required<Pick<ChildWorkflowOptions, 'workflowId' | 'cancellationType'>> & {
@@ -646,6 +646,7 @@ export interface WorkflowCreateOptions {
646
646
  randomnessSeed: number[];
647
647
  now: number;
648
648
  showStackTraceSources: boolean;
649
+ failureExceptionTypeNames?: string[];
649
650
  }
650
651
 
651
652
  export interface WorkflowCreateOptionsInternal extends WorkflowCreateOptions {