@temporalio/common 1.7.4 → 1.8.1

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.
Files changed (52) hide show
  1. package/lib/activity-options.d.ts +18 -10
  2. package/lib/activity-options.js.map +1 -1
  3. package/lib/converter/failure-converter.d.ts +5 -3
  4. package/lib/converter/failure-converter.js +10 -10
  5. package/lib/converter/failure-converter.js.map +1 -1
  6. package/lib/converter/payload-converter.js +5 -3
  7. package/lib/converter/payload-converter.js.map +1 -1
  8. package/lib/converter/protobuf-payload-converters.js +3 -1
  9. package/lib/converter/protobuf-payload-converters.js.map +1 -1
  10. package/lib/deprecated-time.d.ts +5 -5
  11. package/lib/deprecated-time.js.map +1 -1
  12. package/lib/errors.d.ts +18 -0
  13. package/lib/errors.js +26 -1
  14. package/lib/errors.js.map +1 -1
  15. package/lib/failure.d.ts +73 -0
  16. package/lib/failure.js +100 -3
  17. package/lib/failure.js.map +1 -1
  18. package/lib/index.d.ts +3 -1
  19. package/lib/index.js +2 -0
  20. package/lib/index.js.map +1 -1
  21. package/lib/logger.d.ts +13 -0
  22. package/lib/logger.js +3 -0
  23. package/lib/logger.js.map +1 -0
  24. package/lib/retry-policy.d.ts +3 -2
  25. package/lib/retry-policy.js.map +1 -1
  26. package/lib/time.d.ts +10 -4
  27. package/lib/time.js +9 -5
  28. package/lib/time.js.map +1 -1
  29. package/lib/type-helpers.d.ts +8 -0
  30. package/lib/type-helpers.js +8 -1
  31. package/lib/type-helpers.js.map +1 -1
  32. package/lib/versioning-intent.d.ts +18 -0
  33. package/lib/versioning-intent.js +3 -0
  34. package/lib/versioning-intent.js.map +1 -0
  35. package/lib/workflow-options.d.ts +5 -3
  36. package/lib/workflow-options.js +12 -1
  37. package/lib/workflow-options.js.map +1 -1
  38. package/package.json +4 -4
  39. package/src/activity-options.ts +19 -10
  40. package/src/converter/failure-converter.ts +15 -13
  41. package/src/converter/payload-converter.ts +9 -4
  42. package/src/converter/protobuf-payload-converters.ts +3 -1
  43. package/src/deprecated-time.ts +5 -5
  44. package/src/errors.ts +28 -0
  45. package/src/failure.ts +115 -3
  46. package/src/index.ts +3 -1
  47. package/src/logger.ts +15 -0
  48. package/src/retry-policy.ts +3 -3
  49. package/src/time.ts +22 -10
  50. package/src/type-helpers.ts +12 -0
  51. package/src/versioning-intent.ts +18 -0
  52. package/src/workflow-options.ts +15 -4
@@ -4,6 +4,11 @@ export type AnyFunc = (...args: any[]) => any;
4
4
  export type OmitLast<T> = T extends [...infer REST, any] ? REST : never;
5
5
  /** F with all arguments but the last */
6
6
  export type OmitLastParam<F extends AnyFunc> = (...args: OmitLast<Parameters<F>>) => ReturnType<F>;
7
+ /** Require that T has at least one of the provided properties defined */
8
+ export type RequireAtLeastOne<T, Keys extends keyof T = keyof T> = Pick<T, Exclude<keyof T, Keys>> &
9
+ {
10
+ [K in Keys]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<Keys, K>>>;
11
+ }[Keys];
7
12
 
8
13
  /** Verify that an type _Copy extends _Orig */
9
14
  export function checkExtends<_Orig, _Copy extends _Orig>(): void {
@@ -61,3 +66,10 @@ export function errorCode(error: unknown): string | undefined {
61
66
 
62
67
  return undefined;
63
68
  }
69
+
70
+ /**
71
+ * Asserts that some type is the never type
72
+ */
73
+ export function assertNever(msg: string, x: never): never {
74
+ throw new TypeError(msg + ': ' + x);
75
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Indicates whether the user intends certain commands to be run on a compatible worker Build Id
3
+ * version or not.
4
+ *
5
+ * `COMPATIBLE` indicates that the command should run on a worker with compatible version if
6
+ * possible. It may not be possible if the target task queue does not also have knowledge of the
7
+ * current worker's Build Id.
8
+ *
9
+ * `DEFAULT` indicates that the command should run on the target task queue's current
10
+ * overall-default Build Id.
11
+ *
12
+ * Where this type is accepted optionally, an unset value indicates that the SDK should choose the
13
+ * most sensible default behavior for the type of command, accounting for whether the command will
14
+ * be run on the same task queue as the current worker.
15
+ *
16
+ * @experimental
17
+ */
18
+ export type VersioningIntent = 'COMPATIBLE' | 'DEFAULT';
@@ -1,7 +1,7 @@
1
1
  import type { temporal, google } from '@temporalio/proto';
2
2
  import { SearchAttributes, Workflow } from './interfaces';
3
3
  import { RetryPolicy } from './retry-policy';
4
- import { msOptionalToTs } from './time';
4
+ import { Duration, msOptionalToTs } from './time';
5
5
  import { checkExtends, Replace } from './type-helpers';
6
6
 
7
7
  // Avoid importing the proto implementation to reduce workflow bundle size
@@ -113,7 +113,7 @@ export interface WorkflowDurationOptions {
113
113
  *
114
114
  * @format number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
115
115
  */
116
- workflowRunTimeout?: string | number;
116
+ workflowRunTimeout?: Duration;
117
117
 
118
118
  /**
119
119
  *
@@ -123,14 +123,14 @@ export interface WorkflowDurationOptions {
123
123
  *
124
124
  * @format number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
125
125
  */
126
- workflowExecutionTimeout?: string | number;
126
+ workflowExecutionTimeout?: Duration;
127
127
 
128
128
  /**
129
129
  * Maximum execution time of a single workflow task. Default is 10 seconds.
130
130
  *
131
131
  * @format number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
132
132
  */
133
- workflowTaskTimeout?: string | number;
133
+ workflowTaskTimeout?: Duration;
134
134
  }
135
135
 
136
136
  export type CommonWorkflowOptions = BaseWorkflowOptions & WorkflowDurationOptions;
@@ -154,3 +154,14 @@ export function compileWorkflowOptions<T extends CommonWorkflowOptions>(options:
154
154
  workflowTaskTimeout: msOptionalToTs(workflowTaskTimeout),
155
155
  };
156
156
  }
157
+
158
+ export function extractWorkflowType<T extends Workflow>(workflowTypeOrFunc: string | T): string {
159
+ if (typeof workflowTypeOrFunc === 'string') return workflowTypeOrFunc as string;
160
+ if (typeof workflowTypeOrFunc === 'function') {
161
+ if (workflowTypeOrFunc?.name) return workflowTypeOrFunc.name;
162
+ throw new TypeError('Invalid workflow type: the workflow function is anonymous');
163
+ }
164
+ throw new TypeError(
165
+ `Invalid workflow type: expected either a string or a function, got '${typeof workflowTypeOrFunc}'`
166
+ );
167
+ }