@temporalio/client 1.4.4 → 1.5.0

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 (57) hide show
  1. package/lib/async-completion-client.d.ts +5 -32
  2. package/lib/async-completion-client.js +6 -20
  3. package/lib/async-completion-client.js.map +1 -1
  4. package/lib/base-client.d.ts +53 -0
  5. package/lib/base-client.js +45 -0
  6. package/lib/base-client.js.map +1 -0
  7. package/lib/client.d.ts +12 -52
  8. package/lib/client.js +30 -49
  9. package/lib/client.js.map +1 -1
  10. package/lib/connection.d.ts +9 -9
  11. package/lib/connection.js +4 -3
  12. package/lib/connection.js.map +1 -1
  13. package/lib/errors.d.ts +0 -1
  14. package/lib/errors.js +1 -3
  15. package/lib/errors.js.map +1 -1
  16. package/lib/helpers.d.ts +3 -0
  17. package/lib/helpers.js +63 -0
  18. package/lib/helpers.js.map +1 -0
  19. package/lib/index.d.ts +2 -0
  20. package/lib/index.js +2 -0
  21. package/lib/index.js.map +1 -1
  22. package/lib/interceptors.d.ts +46 -10
  23. package/lib/iterators-utils.d.ts +31 -0
  24. package/lib/iterators-utils.js +80 -0
  25. package/lib/iterators-utils.js.map +1 -0
  26. package/lib/schedule-client.d.ts +175 -0
  27. package/lib/schedule-client.js +383 -0
  28. package/lib/schedule-client.js.map +1 -0
  29. package/lib/schedule-helpers.d.ts +20 -0
  30. package/lib/schedule-helpers.js +290 -0
  31. package/lib/schedule-helpers.js.map +1 -0
  32. package/lib/schedule-types.d.ts +691 -0
  33. package/lib/schedule-types.js +74 -0
  34. package/lib/schedule-types.js.map +1 -0
  35. package/lib/types.d.ts +8 -3
  36. package/lib/types.js.map +1 -1
  37. package/lib/workflow-client.d.ts +76 -59
  38. package/lib/workflow-client.js +87 -101
  39. package/lib/workflow-client.js.map +1 -1
  40. package/lib/workflow-options.d.ts +5 -1
  41. package/lib/workflow-options.js.map +1 -1
  42. package/package.json +7 -5
  43. package/src/async-completion-client.ts +16 -55
  44. package/src/base-client.ts +84 -0
  45. package/src/client.ts +41 -93
  46. package/src/connection.ts +12 -11
  47. package/src/errors.ts +0 -1
  48. package/src/helpers.ts +75 -0
  49. package/src/index.ts +2 -0
  50. package/src/interceptors.ts +54 -10
  51. package/src/iterators-utils.ts +116 -0
  52. package/src/schedule-client.ts +541 -0
  53. package/src/schedule-helpers.ts +414 -0
  54. package/src/schedule-types.ts +866 -0
  55. package/src/types.ts +12 -3
  56. package/src/workflow-client.ts +178 -180
  57. package/src/workflow-options.ts +12 -1
package/lib/helpers.js ADDED
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.executionInfoFromRaw = void 0;
4
+ const common_1 = require("@temporalio/common");
5
+ const time_1 = require("@temporalio/common/lib/time");
6
+ const codec_helpers_1 = require("@temporalio/common/lib/internal-non-workflow/codec-helpers");
7
+ const proto_1 = require("@temporalio/proto");
8
+ function workflowStatusCodeToName(code) {
9
+ return workflowStatusCodeToNameInternal(code) ?? 'UNKNOWN';
10
+ }
11
+ /**
12
+ * Intentionally leave out `default` branch to get compilation errors when new values are added
13
+ */
14
+ function workflowStatusCodeToNameInternal(code) {
15
+ switch (code) {
16
+ case proto_1.temporal.api.enums.v1.WorkflowExecutionStatus.WORKFLOW_EXECUTION_STATUS_UNSPECIFIED:
17
+ return 'UNSPECIFIED';
18
+ case proto_1.temporal.api.enums.v1.WorkflowExecutionStatus.WORKFLOW_EXECUTION_STATUS_RUNNING:
19
+ return 'RUNNING';
20
+ case proto_1.temporal.api.enums.v1.WorkflowExecutionStatus.WORKFLOW_EXECUTION_STATUS_FAILED:
21
+ return 'FAILED';
22
+ case proto_1.temporal.api.enums.v1.WorkflowExecutionStatus.WORKFLOW_EXECUTION_STATUS_TIMED_OUT:
23
+ return 'TIMED_OUT';
24
+ case proto_1.temporal.api.enums.v1.WorkflowExecutionStatus.WORKFLOW_EXECUTION_STATUS_CANCELED:
25
+ return 'CANCELLED';
26
+ case proto_1.temporal.api.enums.v1.WorkflowExecutionStatus.WORKFLOW_EXECUTION_STATUS_TERMINATED:
27
+ return 'TERMINATED';
28
+ case proto_1.temporal.api.enums.v1.WorkflowExecutionStatus.WORKFLOW_EXECUTION_STATUS_COMPLETED:
29
+ return 'COMPLETED';
30
+ case proto_1.temporal.api.enums.v1.WorkflowExecutionStatus.WORKFLOW_EXECUTION_STATUS_CONTINUED_AS_NEW:
31
+ return 'CONTINUED_AS_NEW';
32
+ }
33
+ }
34
+ async function executionInfoFromRaw(raw, dataConverter) {
35
+ return {
36
+ /* eslint-disable @typescript-eslint/no-non-null-assertion */
37
+ type: raw.type.name,
38
+ workflowId: raw.execution.workflowId,
39
+ runId: raw.execution.runId,
40
+ taskQueue: raw.taskQueue,
41
+ status: {
42
+ code: raw.status,
43
+ name: workflowStatusCodeToName(raw.status),
44
+ },
45
+ // Safe to convert to number, max history length is 50k, which is much less than Number.MAX_SAFE_INTEGER
46
+ historyLength: raw.historyLength.toNumber(),
47
+ startTime: (0, time_1.tsToDate)(raw.startTime),
48
+ executionTime: (0, time_1.optionalTsToDate)(raw.executionTime),
49
+ closeTime: (0, time_1.optionalTsToDate)(raw.closeTime),
50
+ memo: await (0, codec_helpers_1.decodeMapFromPayloads)(dataConverter, raw.memo?.fields),
51
+ searchAttributes: Object.fromEntries(Object.entries((0, common_1.mapFromPayloads)(common_1.searchAttributePayloadConverter, raw.searchAttributes?.indexedFields ?? {})).filter(([_, v]) => v && v.length > 0) // Filter out empty arrays returned by pre 1.18 servers
52
+ ),
53
+ parentExecution: raw.parentExecution
54
+ ? {
55
+ workflowId: raw.parentExecution.workflowId,
56
+ runId: raw.parentExecution.runId,
57
+ }
58
+ : undefined,
59
+ raw,
60
+ };
61
+ }
62
+ exports.executionInfoFromRaw = executionInfoFromRaw;
63
+ //# sourceMappingURL=helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":";;;AAAA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export * from './workflow-client';
24
24
  export * from './workflow-options';
25
+ export * from './schedule-types';
26
+ export * from './schedule-client';
package/lib/index.js CHANGED
@@ -49,4 +49,6 @@ __exportStar(require("./interceptors"), exports);
49
49
  __exportStar(require("./types"), exports);
50
50
  __exportStar(require("./workflow-client"), exports);
51
51
  __exportStar(require("./workflow-options"), exports);
52
+ __exportStar(require("./schedule-types"), exports);
53
+ __exportStar(require("./schedule-client"), exports);
52
54
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;;;;;;;;;;;;;;;AAEH,6CAa4B;AAZ1B,yGAAA,eAAe,OAAA;AACf,4GAAA,kBAAkB,OAAA;AAClB,0GAAA,gBAAgB,OAAA;AAChB,8GAAA,oBAAoB,OAAA;AAEpB,iHAAA,uBAAuB,OAAA;AAGvB,uGAAA,aAAa,OAAA;AACb,yGAAA,eAAe,OAAA;AACf,2GAAA,iBAAiB,OAAA;AACjB,wGAAA,cAAc,OAAA;AAGhB,gEAA8C;AAC9C,oEAAkD;AAClD,yEAAuD;AACvD,4DAA0C;AAC1C,2CAAyB;AACzB,2CAA0G;AAAjG,wGAAA,UAAU,OAAA;AAAoD,0GAAA,YAAY,OAAA;AACnF,2CAAyB;AACzB,+CAA6B;AAC7B,iDAA+B;AAC/B,0CAAwB;AACxB,oDAAkC;AAClC,qDAAmC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;;;;;;;;;;;;;;;AAEH,6CAa4B;AAZ1B,yGAAA,eAAe,OAAA;AACf,4GAAA,kBAAkB,OAAA;AAClB,0GAAA,gBAAgB,OAAA;AAChB,8GAAA,oBAAoB,OAAA;AAEpB,iHAAA,uBAAuB,OAAA;AAGvB,uGAAA,aAAa,OAAA;AACb,yGAAA,eAAe,OAAA;AACf,2GAAA,iBAAiB,OAAA;AACjB,wGAAA,cAAc,OAAA;AAGhB,gEAA8C;AAC9C,oEAAkD;AAClD,yEAAuD;AACvD,4DAA0C;AAC1C,2CAAyB;AACzB,2CAA0G;AAAjG,wGAAA,UAAU,OAAA;AAAoD,0GAAA,YAAY,OAAA;AACnF,2CAAyB;AACzB,+CAA6B;AAC7B,iDAA+B;AAC/B,0CAAwB;AACxB,oDAAkC;AAClC,qDAAmC;AACnC,mDAAiC;AACjC,oDAAkC"}
@@ -5,24 +5,25 @@
5
5
  */
6
6
  import { Headers, Next } from '@temporalio/common';
7
7
  import { temporal } from '@temporalio/proto';
8
+ import { CompiledScheduleOptions } from './schedule-types';
8
9
  import { DescribeWorkflowExecutionResponse, RequestCancelWorkflowExecutionResponse, TerminateWorkflowExecutionResponse, WorkflowExecution } from './types';
9
10
  import { CompiledWorkflowOptions } from './workflow-options';
10
11
  export { Next, Headers };
11
- /** Input for WorkflowClientCallsInterceptor.start */
12
+ /** Input for WorkflowClientInterceptor.start */
12
13
  export interface WorkflowStartInput {
13
14
  /** Name of Workflow to start */
14
15
  readonly workflowType: string;
15
16
  readonly headers: Headers;
16
17
  readonly options: CompiledWorkflowOptions;
17
18
  }
18
- /** Input for WorkflowClientCallsInterceptor.signal */
19
+ /** Input for WorkflowClientInterceptor.signal */
19
20
  export interface WorkflowSignalInput {
20
21
  readonly signalName: string;
21
22
  readonly args: unknown[];
22
23
  readonly workflowExecution: WorkflowExecution;
23
24
  readonly headers: Headers;
24
25
  }
25
- /** Input for WorkflowClientCallsInterceptor.signalWithStart */
26
+ /** Input for WorkflowClientInterceptor.signalWithStart */
26
27
  export interface WorkflowSignalWithStartInput {
27
28
  readonly workflowType: string;
28
29
  readonly signalName: string;
@@ -30,7 +31,7 @@ export interface WorkflowSignalWithStartInput {
30
31
  readonly headers: Headers;
31
32
  readonly options: CompiledWorkflowOptions;
32
33
  }
33
- /** Input for WorkflowClientCallsInterceptor.query */
34
+ /** Input for WorkflowClientInterceptor.query */
34
35
  export interface WorkflowQueryInput {
35
36
  readonly queryType: string;
36
37
  readonly args: unknown[];
@@ -38,26 +39,26 @@ export interface WorkflowQueryInput {
38
39
  readonly queryRejectCondition?: temporal.api.enums.v1.QueryRejectCondition;
39
40
  readonly headers: Headers;
40
41
  }
41
- /** Input for WorkflowClientCallsInterceptor.terminate */
42
+ /** Input for WorkflowClientInterceptor.terminate */
42
43
  export interface WorkflowTerminateInput {
43
44
  readonly workflowExecution: WorkflowExecution;
44
45
  readonly reason?: string;
45
46
  readonly details?: unknown[];
46
47
  readonly firstExecutionRunId?: string;
47
48
  }
48
- /** Input for WorkflowClientCallsInterceptor.cancel */
49
+ /** Input for WorkflowClientInterceptor.cancel */
49
50
  export interface WorkflowCancelInput {
50
51
  readonly workflowExecution: WorkflowExecution;
51
52
  readonly firstExecutionRunId?: string;
52
53
  }
53
- /** Input for WorkflowClientCallsInterceptor.describe */
54
+ /** Input for WorkflowClientInterceptor.describe */
54
55
  export interface WorkflowDescribeInput {
55
56
  readonly workflowExecution: WorkflowExecution;
56
57
  }
57
58
  /**
58
59
  * Implement any of these methods to intercept WorkflowClient outbound calls
59
60
  */
60
- export interface WorkflowClientCallsInterceptor {
61
+ export interface WorkflowClientInterceptor {
61
62
  /**
62
63
  * Intercept a service call to startWorkflowExecution
63
64
  *
@@ -93,27 +94,62 @@ export interface WorkflowClientCallsInterceptor {
93
94
  */
94
95
  describe?: (input: WorkflowDescribeInput, next: Next<this, 'describe'>) => Promise<DescribeWorkflowExecutionResponse>;
95
96
  }
97
+ /** @deprecated: Use WorkflowClientInterceptor instead */
98
+ export declare type WorkflowClientCallsInterceptor = WorkflowClientInterceptor;
99
+ /** @deprecated */
96
100
  export interface WorkflowClientCallsInterceptorFactoryInput {
97
101
  workflowId: string;
98
102
  runId?: string;
99
103
  }
100
104
  /**
101
105
  * A function that takes {@link CompiledWorkflowOptions} and returns an interceptor
106
+ *
107
+ * @deprecated: Please define interceptors directly, without factory
102
108
  */
103
109
  export interface WorkflowClientCallsInterceptorFactory {
104
110
  (input: WorkflowClientCallsInterceptorFactoryInput): WorkflowClientCallsInterceptor;
105
111
  }
106
112
  /**
107
113
  * A mapping of interceptor type of a list of factory functions
114
+ *
115
+ * @deprecated: Please define interceptors directly, without factory
108
116
  */
109
117
  export interface WorkflowClientInterceptors {
118
+ /** @deprecated */
110
119
  calls?: WorkflowClientCallsInterceptorFactory[];
111
120
  }
121
+ /**
122
+ * Implement any of these methods to intercept ScheduleClient outbound calls
123
+ *
124
+ * @experimental
125
+ */
126
+ export interface ScheduleClientInterceptor {
127
+ /**
128
+ * Intercept a service call to CreateSchedule
129
+ */
130
+ create?: (input: CreateScheduleInput, next: Next<this, 'create'>) => Promise<CreateScheduleOutput>;
131
+ }
132
+ /**
133
+ * Input for {@link ScheduleClientInterceptor.create}
134
+ *
135
+ * @experimental
136
+ */
137
+ export interface CreateScheduleInput {
138
+ readonly headers: Headers;
139
+ readonly options: CompiledScheduleOptions;
140
+ }
141
+ export declare type CreateScheduleOutput = {
142
+ readonly conflictToken: Uint8Array;
143
+ };
112
144
  /**
113
145
  * Interceptors for any high-level SDK client.
114
146
  *
115
- * NOTE: Currently only for {@link WorkflowClient}. More will be added later as needed.
147
+ * NOTE: Currently only for {@link WorkflowClient} and {@link ScheduleClient}. More will be added later as needed.
116
148
  */
117
149
  export interface ClientInterceptors {
118
- workflow?: WorkflowClientInterceptors;
150
+ workflow?: WorkflowClientInterceptors | WorkflowClientInterceptor[];
151
+ /**
152
+ * @experimental
153
+ */
154
+ schedule?: ScheduleClientInterceptor[];
119
155
  }
@@ -0,0 +1,31 @@
1
+ export interface MapAsyncOptions {
2
+ /**
3
+ * How many items to map concurrently. If set to less than 2 (or not set), then items are not mapped concurrently.
4
+ *
5
+ * When items are mapped concurrently, mapped items are returned by the resulting iterator in the order they complete
6
+ * mapping, not the order in which the corresponding source items were obtained from the source iterator.
7
+ *
8
+ * @default 1 (ie. items are not mapped concurrently)
9
+ */
10
+ concurrency?: number;
11
+ /**
12
+ * Maximum number of mapped items to keep in buffer, ready for consumption.
13
+ *
14
+ * Ignored unless `concurrency > 1`. No limit applies if set to `undefined`.
15
+ *
16
+ * @default unlimited
17
+ */
18
+ bufferLimit?: number | undefined;
19
+ }
20
+ /**
21
+ * Return an async iterable that transforms items from a source iterable by mapping each item
22
+ * through a mapping function.
23
+ *
24
+ * If `concurrency > 1`, then up to `concurrency` items may be mapped concurrently. In that case,
25
+ * items are returned by the resulting iterator in the order they complete processing, not the order
26
+ * in which the corresponding source items were obtained from the source iterator.
27
+ *
28
+ * @param source the source async iterable
29
+ * @param mapFn a mapping function to apply on every item of the source iterable
30
+ */
31
+ export declare function mapAsyncIterable<A, B>(source: AsyncIterable<A>, mapFn: (val: A) => Promise<B>, options?: MapAsyncOptions): AsyncIterable<B>;
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mapAsyncIterable = void 0;
4
+ const node_events_1 = require("node:events");
5
+ const abort_controller_1 = require("abort-controller");
6
+ function toAsyncIterator(iterable) {
7
+ return iterable[Symbol.asyncIterator]();
8
+ }
9
+ /**
10
+ * Return an async iterable that transforms items from a source iterable by mapping each item
11
+ * through a mapping function.
12
+ *
13
+ * If `concurrency > 1`, then up to `concurrency` items may be mapped concurrently. In that case,
14
+ * items are returned by the resulting iterator in the order they complete processing, not the order
15
+ * in which the corresponding source items were obtained from the source iterator.
16
+ *
17
+ * @param source the source async iterable
18
+ * @param mapFn a mapping function to apply on every item of the source iterable
19
+ */
20
+ async function* mapAsyncIterable(source, mapFn, options) {
21
+ const { concurrency, bufferLimit } = options ?? {};
22
+ if (!concurrency || concurrency < 2) {
23
+ for await (const x of source) {
24
+ yield mapFn(x);
25
+ }
26
+ return;
27
+ }
28
+ const sourceIterator = toAsyncIterator(source);
29
+ const emitter = new node_events_1.EventEmitter();
30
+ const controller = new abort_controller_1.AbortController();
31
+ const emitterEventsIterable = (0, node_events_1.on)(emitter, 'result', { signal: controller.signal });
32
+ const emitterError = (0, node_events_1.once)(emitter, 'error');
33
+ const bufferLimitSemaphore = typeof bufferLimit === 'number'
34
+ ? (() => {
35
+ const releaseEvents = toAsyncIterator((0, node_events_1.on)(emitter, 'released', { signal: controller.signal }));
36
+ let value = bufferLimit + concurrency;
37
+ return {
38
+ acquire: async () => {
39
+ while (value <= 0) {
40
+ await Promise.race([releaseEvents.next(), emitterError]);
41
+ }
42
+ value--;
43
+ },
44
+ release: () => {
45
+ value++;
46
+ emitter.emit('released');
47
+ },
48
+ };
49
+ })()
50
+ : undefined;
51
+ const mapper = async () => {
52
+ for (;;) {
53
+ await bufferLimitSemaphore?.acquire();
54
+ const val = await Promise.race([sourceIterator.next(), emitterError]);
55
+ if (Array.isArray(val))
56
+ return;
57
+ if (val?.done)
58
+ return;
59
+ emitter.emit('result', await mapFn(val.value));
60
+ }
61
+ };
62
+ const mappers = Array(concurrency)
63
+ .fill(mapper)
64
+ .map((f) => f());
65
+ Promise.all(mappers).then(() => controller.abort(), (err) => emitter.emit('error', err));
66
+ try {
67
+ for await (const [res] of emitterEventsIterable) {
68
+ bufferLimitSemaphore?.release();
69
+ yield res;
70
+ }
71
+ }
72
+ catch (err) {
73
+ if (err?.name === 'AbortError') {
74
+ return;
75
+ }
76
+ throw err;
77
+ }
78
+ }
79
+ exports.mapAsyncIterable = mapAsyncIterable;
80
+ //# sourceMappingURL=iterators-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"iterators-utils.js","sourceRoot":"","sources":["../src/iterators-utils.ts"],"names":[],"mappings":";;;AAAA,6CAAqD;AACrD,uDAAmD;AAuBnD,SAAS,eAAe,CAAI,QAA0B;IACpD,OAAO,QAAQ,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC;AAC1C,CAAC;AAED;;;;;;;;;;GAUG;AACI,KAAK,SAAS,CAAC,CAAC,gBAAgB,CACrC,MAAwB,EACxB,KAA6B,EAC7B,OAAyB;IAEzB,MAAM,EAAE,WAA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EAAE;QACN,CAAC,CAAC,SAAS,CAAC;IAEhB,MAAM,MAAM,GAAG,KAAK,IAAI,EAAE;QACxB,SAAS;YACP,MAAM,oBAAoB,EAAE,OAAO,EAAE,CAAC;YACtC,MAAM,GAAG,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,cAAc,CAAC,IAAI,EAAE,EAAE,YAAY,CAAC,CAAC,CAAC;YAEtE,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC;gBAAE,OAAO;YAC/B,IAAK,GAA2B,EAAE,IAAI;gBAAE,OAAO;YAE/C,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;SAChD;IACH,CAAC,CAAC;IAEF,MAAM,OAAO,GAAG,KAAK,CAAC,WAAW,CAAC;SAC/B,IAAI,CAAC,MAAM,CAAC;SACZ,GAAG,CAAC,CAAC,CAAgB,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;IAElC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,IAAI,CACvB,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,EACxB,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,CAAC,CACpC,CAAC;IAEF,IAAI;QACF,IAAI,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC,IAAI,qBAAqB,EAAE;YAC/C,oBAAoB,EAAE,OAAO,EAAE,CAAC;YAChC,MAAM,GAAG,CAAC;SACX;KACF;IAAC,OAAO,GAAY,EAAE;QACrB,IAAK,GAAa,EAAE,IAAI,KAAK,YAAY,EAAE;YACzC,OAAO;SACR;QACD,MAAM,GAAG,CAAC;KACX;AACH,CAAC;AA5ED,4CA4EC"}
@@ -0,0 +1,175 @@
1
+ import { Headers } from '@temporalio/common/lib/interceptors';
2
+ import { temporal } from '@temporalio/proto';
3
+ import { CreateScheduleInput, CreateScheduleOutput, ScheduleClientInterceptor } from './interceptors';
4
+ import { WorkflowService } from './types';
5
+ import { Backfill, CompiledScheduleUpdateOptions, ScheduleSummary, ScheduleDescription, ScheduleOptions, ScheduleOverlapPolicy, ScheduleUpdateOptions } from './schedule-types';
6
+ import { BaseClient, BaseClientOptions, LoadedWithDefaults } from './base-client';
7
+ /**
8
+ * Handle to a single Schedule
9
+ *
10
+ * @experimental
11
+ */
12
+ export interface ScheduleHandle {
13
+ /**
14
+ * This Schedule's identifier
15
+ */
16
+ readonly scheduleId: string;
17
+ /**
18
+ * Fetch the Schedule's description from the Server
19
+ */
20
+ describe(): Promise<ScheduleDescription>;
21
+ /**
22
+ * Update the Schedule
23
+ *
24
+ * This function calls `.describe()`, provides the `Schedule` to the provided `updateFn`, and
25
+ * sends the returned `UpdatedSchedule` to the Server to update the Schedule definition. Note that,
26
+ * in the future, `updateFn` might be invoked multiple time, with identical or different input.
27
+ */
28
+ update(updateFn: (previous: ScheduleDescription) => ScheduleUpdateOptions): Promise<void>;
29
+ /**
30
+ * Delete the Schedule
31
+ */
32
+ delete(): Promise<void>;
33
+ /**
34
+ * Trigger an Action to be taken immediately
35
+ *
36
+ * @param overlap Override the Overlap Policy for this one trigger. Defaults to {@link ScheduleOverlapPolicy.ALLOW_ALL}.
37
+ */
38
+ trigger(overlap?: ScheduleOverlapPolicy): Promise<void>;
39
+ /**
40
+ * Run though the specified time period(s) and take Actions as if that time passed by right now, all at once.
41
+ * The Overlap Policy can be overridden for the scope of the Backfill.
42
+ */
43
+ backfill(options: Backfill | Backfill[]): Promise<void>;
44
+ /**
45
+ * Pause the Schedule
46
+ *
47
+ * @param note A new {@link ScheduleDescription.note}. Defaults to `"Paused via TypeScript SDK"`
48
+ */
49
+ pause(note?: string): Promise<void>;
50
+ /**
51
+ * Unpause the Schedule
52
+ *
53
+ * @param note A new {@link ScheduleDescription.note}. Defaults to `"Unpaused via TypeScript SDK"
54
+ */
55
+ unpause(note?: string): Promise<void>;
56
+ /**
57
+ * Readonly accessor to the underlying ScheduleClient
58
+ */
59
+ readonly client: ScheduleClient;
60
+ }
61
+ /**
62
+ * @experimental
63
+ */
64
+ export interface ScheduleClientOptions extends BaseClientOptions {
65
+ /**
66
+ * Used to override and extend default Connection functionality
67
+ *
68
+ * Useful for injecting auth headers and tracing Workflow executions
69
+ */
70
+ interceptors?: ScheduleClientInterceptor[];
71
+ }
72
+ /** @experimental */
73
+ export declare type LoadedScheduleClientOptions = LoadedWithDefaults<ScheduleClientOptions>;
74
+ /** @experimental */
75
+ export interface ListScheduleOptions {
76
+ /**
77
+ * How many results to fetch from the Server at a time.
78
+ * @default 1000
79
+ */
80
+ pageSize?: number;
81
+ }
82
+ /**
83
+ * Client for starting Workflow executions and creating Workflow handles
84
+ *
85
+ * @experimental
86
+ */
87
+ export declare class ScheduleClient extends BaseClient {
88
+ readonly options: LoadedScheduleClientOptions;
89
+ constructor(options?: ScheduleClientOptions);
90
+ /**
91
+ * Raw gRPC access to the Temporal service. Schedule-related methods are included in {@link WorkflowService}.
92
+ *
93
+ * **NOTE**: The namespace provided in {@link options} is **not** automatically set on requests made to the service.
94
+ */
95
+ get workflowService(): WorkflowService;
96
+ /**
97
+ * Create a new Schedule.
98
+ *
99
+ * @throws {@link ScheduleAlreadyRunning} if there's a running (not deleted) Schedule with the given `id`
100
+ * @returns a ScheduleHandle to the created Schedule
101
+ */
102
+ create(options: ScheduleOptions): Promise<ScheduleHandle>;
103
+ /**
104
+ * Create a new Schedule.
105
+ */
106
+ protected _createSchedule(options: ScheduleOptions): Promise<void>;
107
+ /**
108
+ * Create a new Schedule.
109
+ */
110
+ protected _createScheduleHandler(input: CreateScheduleInput): Promise<CreateScheduleOutput>;
111
+ /**
112
+ * Describe a Schedule.
113
+ */
114
+ protected _describeSchedule(scheduleId: string): Promise<temporal.api.workflowservice.v1.IDescribeScheduleResponse>;
115
+ /**
116
+ * Update a Schedule.
117
+ */
118
+ protected _updateSchedule(scheduleId: string, opts: CompiledScheduleUpdateOptions, header: Headers): Promise<temporal.api.workflowservice.v1.IUpdateScheduleResponse>;
119
+ /**
120
+ * Patch a Schedule.
121
+ */
122
+ protected _patchSchedule(scheduleId: string, patch: temporal.api.schedule.v1.ISchedulePatch): Promise<temporal.api.workflowservice.v1.IPatchScheduleResponse>;
123
+ /**
124
+ * Delete a Schedule.
125
+ */
126
+ protected _deleteSchedule(scheduleId: string): Promise<temporal.api.workflowservice.v1.IDeleteScheduleResponse>;
127
+ /**
128
+ * List Schedules with an `AsyncIterator`:
129
+ *
130
+ * ```ts
131
+ * for await (const schedule: Schedule of client.list()) {
132
+ * const { id, memo, searchAttributes } = schedule
133
+ * // ...
134
+ * }
135
+ * ```
136
+ *
137
+ * To list one page at a time, instead use the raw gRPC method {@link WorkflowService.listSchedules}:
138
+ *
139
+ * ```ts
140
+ * await { schedules, nextPageToken } = client.scheduleService.listSchedules()
141
+ * ```
142
+ */
143
+ list(options?: ListScheduleOptions): AsyncIterable<ScheduleSummary>;
144
+ /**
145
+ * Get a handle to a Schedule
146
+ *
147
+ * This method does not validate `scheduleId`. If there is no Schedule with the given `scheduleId`, handle
148
+ * methods like `handle.describe()` will throw a {@link ScheduleNotFoundError} error.
149
+ */
150
+ getHandle(scheduleId: string): ScheduleHandle;
151
+ protected rethrowGrpcError(err: unknown, scheduleId: string, fallbackMessage: string): never;
152
+ }
153
+ /**
154
+ * Thrown from {@link ScheduleClient.create} if there's a running (not deleted) Schedule with the given `id`.
155
+ *
156
+ * @experimental
157
+ */
158
+ export declare class ScheduleAlreadyRunning extends Error {
159
+ readonly scheduleId: string;
160
+ readonly name: string;
161
+ constructor(message: string, scheduleId: string);
162
+ }
163
+ /**
164
+ * Thrown when a Schedule with the given Id is not known to Temporal Server.
165
+ * It could be because:
166
+ * - Id passed is incorrect
167
+ * - Schedule was deleted
168
+ *
169
+ * @experimental
170
+ */
171
+ export declare class ScheduleNotFoundError extends Error {
172
+ readonly scheduleId: string;
173
+ readonly name: string;
174
+ constructor(message: string, scheduleId: string);
175
+ }