@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
@@ -0,0 +1,866 @@
1
+ import { checkExtends, Replace, RequireAtLeastOne } from '@temporalio/common/lib/type-helpers';
2
+ import { SearchAttributes, Workflow } from '@temporalio/common';
3
+ import type { temporal } from '@temporalio/proto';
4
+ import { WorkflowStartOptions } from './workflow-options';
5
+
6
+ /**
7
+ * The specification of a Schedule to be created, as expected by {@link ScheduleClient.create}.
8
+ *
9
+ * @experimental
10
+ */
11
+ export interface ScheduleOptions {
12
+ /**
13
+ * Schedule Id
14
+ *
15
+ * We recommend using a meaningful business identifier.
16
+ */
17
+ scheduleId: string;
18
+
19
+ /**
20
+ * When Actions should be taken
21
+ */
22
+ spec: RequireAtLeastOne<ScheduleSpec, 'calendars' | 'intervals' | 'cronExpressions'>;
23
+
24
+ /**
25
+ * Which Action to take
26
+ */
27
+ action: ScheduleOptionsAction;
28
+
29
+ policies?: {
30
+ /**
31
+ * Controls what happens when an Action would be started by a Schedule at the same time that an older Action is still
32
+ * running. This can be changed after a Schedule has taken some Actions, and some changes might produce
33
+ * unintuitive results. In general, the later policy overrides the earlier policy.
34
+ *
35
+ * @default {@link ScheduleOverlapPolicy.SKIP}
36
+ */
37
+ overlap?: ScheduleOverlapPolicy;
38
+
39
+ /**
40
+ * The Temporal Server might be down or unavailable at the time when a Schedule should take an Action. When the Server
41
+ * comes back up, `catchupWindow` controls which missed Actions should be taken at that point. The default is one
42
+ * minute, which means that the Schedule attempts to take any Actions that wouldn't be more than one minute late. It
43
+ * takes those Actions according to the {@link ScheduleOverlapPolicy}. An outage that lasts longer than the Catchup
44
+ * Window could lead to missed Actions. (But you can always {@link ScheduleHandle.backfill}.)
45
+ *
46
+ * @default 1 minute
47
+ * @format number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
48
+ */
49
+ catchupWindow?: number | string;
50
+
51
+ /**
52
+ * When an Action times out or reaches the end of its Retry Policy, {@link pause}.
53
+ *
54
+ * With {@link ScheduleOverlapPolicy.ALLOW_ALL}, this pause might not apply to the next Action, because the next Action
55
+ * might have already started previous to the failed one finishing. Pausing applies only to Actions that are scheduled
56
+ * to start after the failed one finishes.
57
+ *
58
+ * @default false
59
+ */
60
+ pauseOnFailure?: boolean;
61
+ };
62
+
63
+ /**
64
+ * Additional non-indexed information attached to the Schedule. The values can be anything that is
65
+ * serializable by the {@link DataConverter}.
66
+ */
67
+ memo?: Record<string, unknown>;
68
+
69
+ /**
70
+ * Additional indexed information attached to the Schedule. More info:
71
+ * https://docs.temporal.io/docs/typescript/search-attributes
72
+ *
73
+ * Values are always converted using {@link JsonPayloadConverter}, even when a custom Data Converter is provided.
74
+ */
75
+ searchAttributes?: SearchAttributes;
76
+
77
+ /**
78
+ * The initial state of the schedule, right after creation or update.
79
+ */
80
+ state?: {
81
+ /**
82
+ * Start in paused state.
83
+ *
84
+ * @default false
85
+ */
86
+ paused?: boolean;
87
+
88
+ /**
89
+ * Informative human-readable message with contextual notes, e.g. the reason
90
+ * a Schedule is paused. The system may overwrite this message on certain
91
+ * conditions, e.g. when pause-on-failure happens.
92
+ */
93
+ note?: string;
94
+
95
+ /**
96
+ * Limit the number of Actions to take.
97
+ *
98
+ * This number is decremented after each Action is taken, and Actions are not
99
+ * taken when the number is `0` (unless {@link ScheduleHandle.trigger} is called).
100
+ *
101
+ * If `undefined`, then no such limit applies.
102
+ *
103
+ * @default undefined, which allows for unlimited exections
104
+ */
105
+ remainingActions?: number;
106
+
107
+ /**
108
+ * Trigger one Action immediately on create.
109
+ *
110
+ * @default false
111
+ */
112
+ triggerImmediately?: boolean;
113
+
114
+ /**
115
+ * Runs though the specified time periods and takes Actions as if that time passed by right now, all at once. The
116
+ * overlap policy can be overridden for the scope of the backfill.
117
+ */
118
+ backfill?: Backfill[];
119
+ };
120
+ }
121
+
122
+ /** @experimental */
123
+ export type CompiledScheduleOptions = Replace<
124
+ ScheduleOptions,
125
+ {
126
+ action: CompiledScheduleAction;
127
+ }
128
+ >;
129
+
130
+ /**
131
+ * The specification of an updated Schedule, as expected by {@link ScheduleHandle.update}.
132
+ *
133
+ * @experimental
134
+ */
135
+ export type ScheduleUpdateOptions = Replace<
136
+ Omit<ScheduleOptions, 'scheduleId' | 'memo' | 'searchAttributes'>,
137
+ {
138
+ action: Replace<
139
+ ScheduleOptions['action'],
140
+ {
141
+ // No default value on update
142
+ workflowId: string;
143
+ }
144
+ >;
145
+ state: Omit<ScheduleOptions['state'], 'triggerImmediately' | 'backfill'>;
146
+ }
147
+ >;
148
+
149
+ /** @experimental */
150
+ export type CompiledScheduleUpdateOptions = Replace<
151
+ ScheduleUpdateOptions,
152
+ {
153
+ action: CompiledScheduleAction;
154
+ }
155
+ >;
156
+
157
+ /**
158
+ * A summary description of an existing Schedule, as returned by {@link ScheduleClient.list}.
159
+ *
160
+ * @experimental
161
+ */
162
+ export interface ScheduleSummary {
163
+ /**
164
+ * The Schedule Id. We recommend using a meaningful business identifier.
165
+ */
166
+ scheduleId: string;
167
+
168
+ /**
169
+ * When will Actions be taken.
170
+ */
171
+ spec: RequireAtLeastOne<ScheduleSpecDescription, 'calendars' | 'intervals'>;
172
+
173
+ /**
174
+ * The Action that will be taken.
175
+ */
176
+ action: ScheduleSummaryAction;
177
+
178
+ /**
179
+ * Additional non-indexed information attached to the Schedule.
180
+ * The values can be anything that is serializable by the {@link DataConverter}.
181
+ */
182
+ memo?: Record<string, unknown>;
183
+
184
+ /**
185
+ * Additional indexed information attached to the Schedule.
186
+ * More info: https://docs.temporal.io/docs/typescript/search-attributes
187
+ *
188
+ * Values are always converted using {@link JsonPayloadConverter}, even when a custom Data Converter is provided.
189
+ */
190
+ searchAttributes: SearchAttributes;
191
+
192
+ state: {
193
+ /**
194
+ * Whether Schedule is currently paused.
195
+ */
196
+ paused: boolean;
197
+
198
+ /**
199
+ * Informative human-readable message with contextual notes, e.g. the reason a Schedule is paused.
200
+ * The system may overwrite this message on certain conditions, e.g. when pause-on-failure happens.
201
+ */
202
+ note?: string;
203
+ };
204
+
205
+ info: {
206
+ /**
207
+ * Most recent 10 Actions started (including manual triggers), sorted from older start time to newer.
208
+ */
209
+ recentActions: ScheduleExecutionResult[];
210
+
211
+ /**
212
+ * Scheduled time of the next 10 executions of this Schedule
213
+ */
214
+ nextActionTimes: Date[];
215
+ };
216
+ }
217
+
218
+ /** @experimental */
219
+ export interface ScheduleExecutionResult {
220
+ /** Time that the Action was scheduled for, including jitter */
221
+ scheduledAt: Date;
222
+
223
+ /** Time that the Action was actually taken */
224
+ takenAt: Date;
225
+
226
+ /** The Action that was taken */
227
+ action: ScheduleExecutionActionResult;
228
+ }
229
+
230
+ /** @experimental */
231
+ export type ScheduleExecutionActionResult = ScheduleExecutionStartWorkflowActionResult;
232
+
233
+ /** @experimental */
234
+ export interface ScheduleExecutionStartWorkflowActionResult {
235
+ type: 'startWorkflow';
236
+ workflow: {
237
+ workflowId: string;
238
+
239
+ /**
240
+ * The Run Id of the original execution that was started by the Schedule. If the Workflow retried, did
241
+ * Continue-As-New, or was Reset, the following runs would have different Run Ids.
242
+ */
243
+ firstExecutionRunId: string;
244
+ };
245
+ }
246
+
247
+ /**
248
+ * A detailed description of an exisiting Schedule, as returned by {@link ScheduleHandle.describe}.
249
+ *
250
+ * @experimental
251
+ */
252
+ export type ScheduleDescription = ScheduleSummary & {
253
+ /**
254
+ * The Action that will be taken.
255
+ */
256
+ action: ScheduleDescriptionAction;
257
+
258
+ policies: {
259
+ /**
260
+ * Controls what happens when an Action would be started by a Schedule at the same time that an older Action is still
261
+ * running.
262
+ */
263
+ overlap: ScheduleOverlapPolicy;
264
+
265
+ /**
266
+ * The Temporal Server might be down or unavailable at the time when a Schedule should take an Action.
267
+ * When the Server comes back up, `catchupWindow` controls which missed Actions should be taken at that point.
268
+ * It takes those Actions according to the {@link ScheduleOverlapPolicy}. An outage that lasts longer than the
269
+ * Catchup Window could lead to missed Actions. (But you can always {@link ScheduleHandle.backfill}.)
270
+ *
271
+ * Unit is miliseconds.
272
+ */
273
+ catchupWindow: number;
274
+
275
+ /**
276
+ * When an Action times out or reaches the end of its Retry Policy, {@link pause}.
277
+ *
278
+ * With {@link ScheduleOverlapPolicy.ALLOW_ALL}, this pause might not apply to the next Action, because the next Action
279
+ * might have already started previous to the failed one finishing. Pausing applies only to Actions that are scheduled
280
+ * to start after the failed one finishes.
281
+ */
282
+ pauseOnFailure: boolean;
283
+ };
284
+
285
+ state: ScheduleSummary['state'] & {
286
+ /**
287
+ * The Actions remaining in this Schedule.
288
+ * Once this number hits `0`, no further Actions are taken (unless {@link ScheduleHandle.trigger} is called).
289
+ *
290
+ * If `undefined`, then no such limit applies.
291
+ */
292
+ remainingActions?: number;
293
+ };
294
+
295
+ info: ScheduleSummary['info'] & {
296
+ /**
297
+ * Number of Actions taken so far.
298
+ */
299
+ numActionsTaken: number;
300
+
301
+ /**
302
+ * Number of times a scheduled Action was skipped due to missing the catchup window.
303
+ */
304
+ numActionsMissedCatchupWindow: number;
305
+
306
+ /**
307
+ * Number of Actions skipped due to overlap.
308
+ */
309
+ numActionsSkippedOverlap: number;
310
+
311
+ createdAt: Date;
312
+ lastUpdatedAt: Date | undefined;
313
+
314
+ /**
315
+ * Currently-running workflows started by this schedule. (There might be
316
+ * more than one if the overlap policy allows overlaps.)
317
+ */
318
+ runningActions: ScheduleExecutionActionResult[];
319
+ };
320
+
321
+ /** @internal */
322
+ raw: temporal.api.workflowservice.v1.IDescribeScheduleResponse;
323
+ };
324
+
325
+ // Invariant: An existing ScheduleDescription can be used as template to create a new Schedule
326
+ checkExtends<ScheduleOptions, ScheduleDescription>();
327
+
328
+ // Invariant: An existing ScheduleDescription can be used as template to update that Schedule
329
+ checkExtends<ScheduleUpdateOptions, ScheduleDescription>();
330
+
331
+ /**
332
+ * A complete description of a set of absolute times (possibly infinite) that an Action should occur at.
333
+ * The times are the union of `calendars`, `intervals`, and `cronExpressions`, minus the `skip` times. These times
334
+ * never change, except that the definition of a time zone can change over time (most commonly, when daylight saving
335
+ * time policy changes for an area). To create a totally self-contained `ScheduleSpec`, use UTC.
336
+ *
337
+ * @experimental
338
+ */
339
+ export interface ScheduleSpec {
340
+ /** Calendar-based specifications of times. */
341
+ calendars?: CalendarSpec[];
342
+
343
+ /** Interval-based specifications of times. */
344
+ intervals?: IntervalSpec[];
345
+
346
+ /**
347
+ * [Cron expressions](https://crontab.guru/). This is provided for easy migration from legacy Cron Workflows. For new
348
+ * use cases, we recommend using {@link calendars} or {@link intervals} for readability and maintainability.
349
+ *
350
+ * For example, `0 12 * * MON-WED,FRI` is every M/Tu/W/F at noon, and is equivalent to this {@link CalendarSpec}:
351
+ *
352
+ * ```ts
353
+ * {
354
+ * hour: 12,
355
+ * dayOfWeek: [{
356
+ * start: 'MONDAY'
357
+ * end: 'WEDNESDAY'
358
+ * }, 'FRIDAY']
359
+ * }
360
+ * ```
361
+ *
362
+ * The string can have 5, 6, or 7 fields, separated by spaces, and they are interpreted in the
363
+ * same way as a {@link CalendarSpec}.
364
+ *
365
+ * - 5 fields: minute, hour, day_of_month, month, day_of_week
366
+ * - 6 fields: minute, hour, day_of_month, month, day_of_week, year
367
+ * - 7 fields: second, minute, hour, day_of_month, month, day_of_week, year
368
+ *
369
+ * Notes:
370
+ *
371
+ * - If year is not given, it defaults to *.
372
+ * - If second is not given, it defaults to 0.
373
+ * - Shorthands `@yearly`, `@monthly`, `@weekly`, `@daily`, and `@hourly` are also
374
+ * accepted instead of the 5-7 time fields.
375
+ * - `@every interval[/<phase>]` is accepted and gets compiled into an
376
+ * IntervalSpec instead. `<interval>` and `<phase>` should be a decimal integer
377
+ * with a unit suffix s, m, h, or d.
378
+ * - Optionally, the string can be preceded by `CRON_TZ=<timezone name>` or
379
+ * `TZ=<timezone name>`, which will get copied to {@link timezone}.
380
+ * (In which case the {@link timezone} field should be left empty.)
381
+ * - Optionally, "#" followed by a comment can appear at the end of the string.
382
+ * - Note that the special case that some cron implementations have for
383
+ * treating day_of_month and day_of_week as "or" instead of "and" when both
384
+ * are set is not implemented.
385
+ */
386
+ cronExpressions?: string[];
387
+
388
+ /**
389
+ * Any matching times will be skipped.
390
+ *
391
+ * All aspects of the CalendarSpec—including seconds—must match a time for the time to be skipped.
392
+ */
393
+ skip?: CalendarSpec[];
394
+ // TODO see if users want to be able to skip an IntervalSpec
395
+ // https://github.com/temporalio/api/pull/230/files#r956434347
396
+
397
+ /**
398
+ * Any times before `startAt` will be skipped. Together, `startAt` and `endAt` make an inclusive interval.
399
+ *
400
+ * @default The beginning of time
401
+ */
402
+ startAt?: Date;
403
+
404
+ /**
405
+ * Any times after `endAt` will be skipped.
406
+ *
407
+ * @default The end of time
408
+ */
409
+ endAt?: Date;
410
+
411
+ /**
412
+ * All times will be incremented by a random value from 0 to this amount of jitter.
413
+ *
414
+ * @default 0
415
+ * @format number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
416
+ */
417
+ jitter?: number | string;
418
+
419
+ /**
420
+ * IANA timezone name, for example `US/Pacific`.
421
+ *
422
+ * https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
423
+ *
424
+ * The definition will be loaded by Temporal Server from the environment it runs in.
425
+ *
426
+ * Calendar spec matching is based on literal matching of the clock time
427
+ * with no special handling of DST: if you write a calendar spec that fires
428
+ * at 2:30am and specify a time zone that follows DST, that action will not
429
+ * be triggered on the day that has no 2:30am. Similarly, an action that
430
+ * fires at 1:30am will be triggered twice on the day that has two 1:30s.
431
+ *
432
+ * Also note that no actions are taken on leap-seconds (e.g. 23:59:60 UTC).
433
+ *
434
+ * @default UTC
435
+ */
436
+ timezone?: string;
437
+ }
438
+
439
+ /**
440
+ * The version of {@link ScheduleSpec} that you get back from {@link ScheduleHandle.describe} and {@link ScheduleClient.list}
441
+ *
442
+ * @experimental
443
+ */
444
+ export type ScheduleSpecDescription = Omit<
445
+ ScheduleSpec,
446
+ 'calendars' | 'intervals' | 'cronExpressions' | 'skip' | 'jitter'
447
+ > & {
448
+ /** Calendar-based specifications of times. */
449
+ calendars?: CalendarSpecDescription[];
450
+
451
+ /** Interval-based specifications of times. */
452
+ intervals?: IntervalSpecDescription[];
453
+
454
+ /** Any matching times will be skipped. */
455
+ skip?: CalendarSpecDescription[];
456
+
457
+ /**
458
+ * All times will be incremented by a random value from 0 to this amount of jitter.
459
+ *
460
+ * @default 1 second
461
+ * @format number of milliseconds
462
+ */
463
+ jitter?: number;
464
+ };
465
+
466
+ // Invariant: An existing ScheduleSpec can be used as is to create or update a Schedule
467
+ checkExtends<ScheduleSpec, ScheduleSpecDescription>();
468
+
469
+ /**
470
+ * An event specification relative to the calendar, similar to a traditional cron specification.
471
+ *
472
+ * A second in time matches if all fields match. This includes `dayOfMonth` and `dayOfWeek`.
473
+ *
474
+ * @experimental
475
+ */
476
+ export interface CalendarSpec {
477
+ /**
478
+ * Valid values: 0–59
479
+ *
480
+ * @default 0
481
+ */
482
+ second?: LooseRange<number> | LooseRange<number>[] | '*';
483
+
484
+ /**
485
+ * Valid values: 0–59
486
+ *
487
+ * @default 0
488
+ */
489
+ minute?: LooseRange<number> | LooseRange<number>[] | '*';
490
+
491
+ /**
492
+ * Valid values: 0–59
493
+ *
494
+ * @default 0
495
+ */
496
+ hour?: LooseRange<number> | LooseRange<number>[] | '*';
497
+
498
+ /**
499
+ * Valid values: 1–31
500
+ *
501
+ * @default '*'
502
+ */
503
+ dayOfMonth?: LooseRange<number> | LooseRange<number>[] | '*';
504
+
505
+ /**
506
+ * @default '*'
507
+ */
508
+ month?: LooseRange<Month> | LooseRange<Month>[] | '*';
509
+
510
+ /**
511
+ * Use full years, like `2030`
512
+ *
513
+ * @default '*'
514
+ */
515
+ year?: LooseRange<number> | LooseRange<number>[] | '*';
516
+
517
+ /**
518
+ * @default '*'
519
+ */
520
+ dayOfWeek?: LooseRange<DayOfWeek> | LooseRange<DayOfWeek>[] | '*';
521
+
522
+ /**
523
+ * Description of the intention of this spec.
524
+ */
525
+ comment?: string;
526
+ }
527
+
528
+ /**
529
+ * An event specification relative to the calendar, similar to a traditional cron specification.
530
+ *
531
+ * A second in time matches if all fields match. This includes `dayOfMonth` and `dayOfWeek`.
532
+ *
533
+ * @experimental
534
+ */
535
+ export interface CalendarSpecDescription {
536
+ /**
537
+ * Valid values: 0–59
538
+ *
539
+ * @default Match only when second is 0 (ie. `[{ start: 0, end: 0, step: 0 }]`)
540
+ */
541
+ second: Range<number>[];
542
+
543
+ /**
544
+ * Valid values: 0–59
545
+ *
546
+ * @default Match only when minute is 0 (ie. `[{ start: 0, end: 0, step: 0 }]`)
547
+ */
548
+ minute: Range<number>[];
549
+
550
+ /**
551
+ * Valid values: 0–23
552
+ *
553
+ * @default Match only when hour is 0 (ie. `[{ start: 0, end: 0, step: 0 }]`)
554
+ */
555
+ hour: Range<number>[];
556
+
557
+ /**
558
+ * Valid values: 1–31
559
+ *
560
+ * @default Match on any day (ie. `[{ start: 1, end: 31, step: 1 }]`)
561
+ */
562
+ dayOfMonth: Range<number>[];
563
+
564
+ /**
565
+ * Valid values are 'JANUARY' to 'DECEMBER'.
566
+ *
567
+ * @default Match on any month (ie. `[{ start: 'JANUARY', end: 'DECEMBER', step: 1 }]`)
568
+ */
569
+ month: Range<Month>[];
570
+
571
+ /**
572
+ * Use full years, like `2030`
573
+ *
574
+ * @default Match on any year
575
+ */
576
+ year: Range<number>[];
577
+
578
+ /**
579
+ * Valid values are 'SUNDAY' to 'SATURDAY'.
580
+ *
581
+ * @default Match on any day of the week (ie. `[{ start: 'SUNDAY', end: 'SATURDAY', step: 1 }]`)
582
+ */
583
+ dayOfWeek: Range<DayOfWeek>[];
584
+
585
+ /**
586
+ * Description of the intention of this spec.
587
+ */
588
+ comment?: string;
589
+ }
590
+
591
+ /**
592
+ * IntervalSpec matches times that can be expressed as:
593
+ *
594
+ * `Epoch + (n * every) + offset`
595
+ *
596
+ * where `n` is all integers ≥ 0.
597
+ *
598
+ * For example, an `every` of 1 hour with `offset` of zero would match every hour, on the hour. The same `every` but an `offset`
599
+ * of 19 minutes would match every `xx:19:00`. An `every` of 28 days with `offset` zero would match `2022-02-17T00:00:00Z`
600
+ * (among other times). The same `every` with `offset` of 3 days, 5 hours, and 23 minutes would match `2022-02-20T05:23:00Z`
601
+ * instead.
602
+ *
603
+ * @experimental
604
+ */
605
+ export interface IntervalSpec {
606
+ /**
607
+ * Value is rounded to the nearest second.
608
+ *
609
+ * @format number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
610
+ */
611
+ every: number | string;
612
+
613
+ /**
614
+ * Value is rounded to the nearest second.
615
+ *
616
+ * @default 0
617
+ * @format number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
618
+ */
619
+ offset?: number | string;
620
+ }
621
+
622
+ /**
623
+ * IntervalSpec matches times that can be expressed as:
624
+ *
625
+ * `Epoch + (n * every) + offset`
626
+ *
627
+ * where `n` is all integers ≥ 0.
628
+ *
629
+ * For example, an `every` of 1 hour with `offset` of zero would match every hour, on the hour. The same `every` but an `offset`
630
+ * of 19 minutes would match every `xx:19:00`. An `every` of 28 days with `offset` zero would match `2022-02-17T00:00:00Z`
631
+ * (among other times). The same `every` with `offset` of 3 days, 5 hours, and 23 minutes would match `2022-02-20T05:23:00Z`
632
+ * instead.
633
+ *
634
+ * This is the version of {@link IntervalSpec} that you get back from {@link ScheduleHandle.describe} and {@link ScheduleClient.list}
635
+ *
636
+ * @experimental
637
+ */
638
+ export interface IntervalSpecDescription {
639
+ /**
640
+ * Value is rounded to the nearest second.
641
+ *
642
+ * @format number of milliseconds
643
+ */
644
+ every: number;
645
+
646
+ /**
647
+ * Value is rounded to the nearest second.
648
+ *
649
+ * @format number of milliseconds
650
+ */
651
+ offset: number;
652
+ }
653
+
654
+ /**
655
+ * Range represents a set of values, used to match fields of a calendar. If end < start, then end is
656
+ * interpreted as equal to start. Similarly, if step is less than 1, then step is interpreted as 1.
657
+ *
658
+ * @experimental
659
+ */
660
+ export interface Range<Unit> {
661
+ /**
662
+ * Start of range (inclusive)
663
+ */
664
+ start: Unit;
665
+
666
+ /**
667
+ * End of range (inclusive)
668
+ *
669
+ * @default `start`
670
+ */
671
+ end: Unit;
672
+
673
+ /**
674
+ * The step to take between each value.
675
+ *
676
+ * @default 1
677
+ */
678
+ step: number;
679
+ }
680
+
681
+ /**
682
+ * A {@link Range} definition, with support for loose syntax.
683
+ *
684
+ * For example:
685
+ * ```
686
+ * 3 ➡️ 3
687
+ * { start: 2 } ➡️ 2
688
+ * { start: 2, end: 4 } ➡️ 2, 3, 4
689
+ * { start: 2, end: 10, step: 3 } ➡️ 2, 5, 8
690
+ * ```
691
+ *
692
+ * @experimental
693
+ */
694
+ export type LooseRange<Unit> =
695
+ | Range<Unit>
696
+ | { start: Range<Unit>['start']; end?: Range<Unit>['end']; step?: never }
697
+ | Unit;
698
+
699
+ /** @experimental */
700
+ export const MONTHS = [
701
+ 'JANUARY',
702
+ 'FEBRUARY',
703
+ 'MARCH',
704
+ 'APRIL',
705
+ 'MAY',
706
+ 'JUNE',
707
+ 'JULY',
708
+ 'AUGUST',
709
+ 'SEPTEMBER',
710
+ 'OCTOBER',
711
+ 'NOVEMBER',
712
+ 'DECEMBER',
713
+ ] as const;
714
+
715
+ /** @experimental */
716
+ export type Month = typeof MONTHS[number];
717
+
718
+ /** @experimental */
719
+ export const DAYS_OF_WEEK = ['SUNDAY', 'MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY', 'SATURDAY'] as const;
720
+
721
+ /** @experimental */
722
+ export type DayOfWeek = typeof DAYS_OF_WEEK[number];
723
+
724
+ /** @experimental */
725
+ export type ScheduleOptionsAction = ScheduleOptionsStartWorkflowAction<Workflow>;
726
+
727
+ /** @experimental */
728
+ export type ScheduleOptionsStartWorkflowAction<W extends Workflow> = {
729
+ type: 'startWorkflow';
730
+ workflowType: string | W;
731
+ } & Pick<
732
+ WorkflowStartOptions<W>,
733
+ | 'taskQueue'
734
+ | 'args'
735
+ | 'memo'
736
+ | 'searchAttributes'
737
+ | 'retry'
738
+ | 'workflowExecutionTimeout'
739
+ | 'workflowRunTimeout'
740
+ | 'workflowTaskTimeout'
741
+ > & {
742
+ /**
743
+ * Workflow id to use when starting. Assign a meaningful business id.
744
+ * This ID can be used to ensure starting Workflows is idempotent.
745
+ *
746
+ * @default `${scheduleId}-workflow`
747
+ */
748
+ workflowId?: string;
749
+ };
750
+
751
+ /** @experimental */
752
+ export type ScheduleSummaryAction = ScheduleSummaryStartWorkflowAction;
753
+
754
+ /** @experimental */
755
+ export interface ScheduleSummaryStartWorkflowAction {
756
+ type: 'startWorkflow';
757
+ workflowType: string;
758
+ }
759
+ /** @experimental */
760
+ export type ScheduleDescriptionAction = ScheduleDescriptionStartWorkflowAction;
761
+
762
+ /** @experimental */
763
+ export type ScheduleDescriptionStartWorkflowAction = ScheduleSummaryStartWorkflowAction &
764
+ Pick<
765
+ WorkflowStartOptions<Workflow>,
766
+ | 'taskQueue'
767
+ | 'workflowId'
768
+ | 'args'
769
+ | 'memo'
770
+ | 'searchAttributes'
771
+ | 'retry'
772
+ | 'workflowExecutionTimeout'
773
+ | 'workflowRunTimeout'
774
+ | 'workflowTaskTimeout'
775
+ >;
776
+
777
+ // Invariant: an existing ScheduleDescriptionAction can be used as is to create or update a schedule
778
+ checkExtends<ScheduleOptionsAction, ScheduleDescriptionAction>();
779
+
780
+ /** @experimental */
781
+ export type CompiledScheduleAction = Replace<
782
+ ScheduleDescriptionAction,
783
+ {
784
+ workflowType: string;
785
+ args: unknown[];
786
+ }
787
+ >;
788
+
789
+ /**
790
+ * Policy for overlapping Actions.
791
+ *
792
+ * @experimental
793
+ */
794
+ export enum ScheduleOverlapPolicy {
795
+ /**
796
+ * Use server default (currently SKIP).
797
+ *
798
+ * FIXME: remove this field if this issue is implemented: https://github.com/temporalio/temporal/issues/3240
799
+ */
800
+ UNSPECIFIED = 0,
801
+
802
+ /**
803
+ * Don't start a new Action.
804
+ */
805
+ SKIP,
806
+
807
+ /**
808
+ * Start another Action as soon as the current Action completes, but only buffer one Action in this way. If another
809
+ * Action is supposed to start, but one Action is running and one is already buffered, then only the buffered one will
810
+ * be started after the running Action finishes.
811
+ */
812
+ BUFFER_ONE,
813
+
814
+ /**
815
+ * Allows an unlimited number of Actions to buffer. They are started sequentially.
816
+ */
817
+ BUFFER_ALL,
818
+
819
+ /**
820
+ * Cancels the running Action, and then starts the new Action once the cancelled one completes.
821
+ */
822
+ CANCEL_OTHER,
823
+
824
+ /**
825
+ * Terminate the running Action and start the new Action immediately.
826
+ */
827
+ TERMINATE_OTHER,
828
+
829
+ /**
830
+ * Allow any number of Actions to start immediately.
831
+ *
832
+ * This is the only policy under which multiple Actions can run concurrently.
833
+ */
834
+ ALLOW_ALL,
835
+ }
836
+
837
+ export type ScheduleOverlapPolicy2 = keyof typeof temporal.api.enums.v1.ScheduleOverlapPolicy;
838
+
839
+ checkExtends<
840
+ keyof typeof temporal.api.enums.v1.ScheduleOverlapPolicy,
841
+ `SCHEDULE_OVERLAP_POLICY_${keyof typeof ScheduleOverlapPolicy}`
842
+ >();
843
+ checkExtends<
844
+ `SCHEDULE_OVERLAP_POLICY_${keyof typeof ScheduleOverlapPolicy}`,
845
+ keyof typeof temporal.api.enums.v1.ScheduleOverlapPolicy
846
+ >();
847
+
848
+ /** @experimental */
849
+ export interface Backfill {
850
+ /**
851
+ * Start of the time range to evaluate Schedule in.
852
+ */
853
+ start: Date;
854
+
855
+ /**
856
+ * End of the time range to evaluate Schedule in.
857
+ */
858
+ end: Date;
859
+
860
+ /**
861
+ * Override the Overlap Policy for this request.
862
+ *
863
+ * @default SKIP
864
+ */
865
+ overlap?: ScheduleOverlapPolicy;
866
+ }