@procedures/schedule 0.0.0-stage → 0.3.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 (75) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/LICENSE +21 -0
  3. package/README.md +98 -2
  4. package/dist/.tsbuildinfo +1 -0
  5. package/dist/cron.d.ts +47 -0
  6. package/dist/cron.d.ts.map +1 -0
  7. package/dist/cron.js +197 -0
  8. package/dist/cron.js.map +1 -0
  9. package/dist/errors.d.ts +22 -0
  10. package/dist/errors.d.ts.map +1 -0
  11. package/dist/errors.js +13 -0
  12. package/dist/errors.js.map +1 -0
  13. package/dist/index.d.ts +9 -0
  14. package/dist/index.d.ts.map +1 -0
  15. package/dist/index.js +11 -0
  16. package/dist/index.js.map +1 -0
  17. package/dist/module.d.ts +42 -0
  18. package/dist/module.d.ts.map +1 -0
  19. package/dist/module.js +174 -0
  20. package/dist/module.js.map +1 -0
  21. package/dist/procedures/schedule/add.d.ts +17 -0
  22. package/dist/procedures/schedule/add.d.ts.map +1 -0
  23. package/dist/procedures/schedule/add.js +66 -0
  24. package/dist/procedures/schedule/add.js.map +1 -0
  25. package/dist/procedures/schedule/index.d.ts +5 -0
  26. package/dist/procedures/schedule/index.d.ts.map +1 -0
  27. package/dist/procedures/schedule/index.js +5 -0
  28. package/dist/procedures/schedule/index.js.map +1 -0
  29. package/dist/procedures/schedule/list.d.ts +12 -0
  30. package/dist/procedures/schedule/list.d.ts.map +1 -0
  31. package/dist/procedures/schedule/list.js +18 -0
  32. package/dist/procedures/schedule/list.js.map +1 -0
  33. package/dist/procedures/schedule/next.d.ts +13 -0
  34. package/dist/procedures/schedule/next.d.ts.map +1 -0
  35. package/dist/procedures/schedule/next.js +24 -0
  36. package/dist/procedures/schedule/next.js.map +1 -0
  37. package/dist/procedures/schedule/remove.d.ts +12 -0
  38. package/dist/procedures/schedule/remove.d.ts.map +1 -0
  39. package/dist/procedures/schedule/remove.js +13 -0
  40. package/dist/procedures/schedule/remove.js.map +1 -0
  41. package/dist/programs.d.ts +26 -0
  42. package/dist/programs.d.ts.map +1 -0
  43. package/dist/programs.js +34 -0
  44. package/dist/programs.js.map +1 -0
  45. package/dist/register.d.ts +6 -0
  46. package/dist/register.d.ts.map +1 -0
  47. package/dist/register.js +8 -0
  48. package/dist/register.js.map +1 -0
  49. package/dist/scheduler.d.ts +106 -0
  50. package/dist/scheduler.d.ts.map +1 -0
  51. package/dist/scheduler.js +274 -0
  52. package/dist/scheduler.js.map +1 -0
  53. package/dist/store.d.ts +62 -0
  54. package/dist/store.d.ts.map +1 -0
  55. package/dist/store.js +188 -0
  56. package/dist/store.js.map +1 -0
  57. package/dist/types.d.ts +100 -0
  58. package/dist/types.d.ts.map +1 -0
  59. package/dist/types.js +8 -0
  60. package/dist/types.js.map +1 -0
  61. package/package.json +78 -3
  62. package/src/cron.ts +230 -0
  63. package/src/errors.ts +27 -0
  64. package/src/index.ts +10 -0
  65. package/src/module.ts +227 -0
  66. package/src/procedures/schedule/add.ts +66 -0
  67. package/src/procedures/schedule/index.ts +4 -0
  68. package/src/procedures/schedule/list.ts +20 -0
  69. package/src/procedures/schedule/next.ts +25 -0
  70. package/src/procedures/schedule/remove.ts +15 -0
  71. package/src/programs.ts +43 -0
  72. package/src/register.ts +10 -0
  73. package/src/scheduler.ts +331 -0
  74. package/src/store.ts +213 -0
  75. package/src/types.ts +122 -0
package/src/types.ts ADDED
@@ -0,0 +1,122 @@
1
+ /**
2
+ * Type definitions of the procedures of this package
3
+ *
4
+ * mark procedure new adds the types of each new procedure here. The zod schemas are in
5
+ * `module.ts`: an exported schema needs a written type (isolatedDeclarations).
6
+ */
7
+
8
+ import type { PermittedEffects } from "@procedures/client";
9
+
10
+ /** The time zone of a cron expression: the UTC time, or the local time of the host. */
11
+ export type ScheduleTimeZone = "utc" | "local";
12
+
13
+ /** The last run of a schedule. */
14
+ export interface ScheduleRun {
15
+ /** The wall time of the start, in milliseconds since 1970. */
16
+ startedAt: number;
17
+ /** The time of the run, in milliseconds. */
18
+ durationMs: number;
19
+ outcome: "success" | "failure";
20
+ /** The error of a failure: its code, when it has one, and its message. */
21
+ error?: { code?: string | undefined; message: string } | undefined;
22
+ }
23
+
24
+ /** One stored schedule: a cron expression that starts a stored program with an input. */
25
+ export interface Schedule {
26
+ /** The name of the schedule. */
27
+ id: string;
28
+ /** The cron expression: 5 fields, or a name such as `@daily`. */
29
+ cron: string;
30
+ /** The dotted key of the stored program: `reports.weekly`. */
31
+ program: string;
32
+ /** The input of the program. */
33
+ input?: unknown;
34
+ timeZone: ScheduleTimeZone;
35
+ /** When the schedule was added, in milliseconds since 1970. A schedule starts no run for a time before it. */
36
+ createdAt: number;
37
+ /**
38
+ * The capability of the caller that added the schedule, without its deadline. A run gets the
39
+ * capability of the host, narrowed by this one: a caller cannot start more than it can do.
40
+ */
41
+ capability?: { clearance?: unknown; effects?: PermittedEffects } | undefined;
42
+ lastRun?: ScheduleRun | undefined;
43
+ /** The number of runs. */
44
+ runs: number;
45
+ /** The number of runs that failed. */
46
+ failures: number;
47
+ /** The number of times that came while a run of the schedule was not finished: no second run started. */
48
+ skipped: number;
49
+ }
50
+
51
+ /** A schedule as the procedures give it: with its next time. */
52
+ export interface ScheduleView extends Schedule {
53
+ /** The next time, as an ISO text in the time zone of the schedule, or null when the expression has no next time. */
54
+ nextRunAt: string | null;
55
+ }
56
+
57
+ // =============================================================================
58
+ // schedule.add
59
+ // =============================================================================
60
+
61
+ export interface ScheduleAddInput {
62
+ /** The name of the schedule. The default is the key of the program. */
63
+ id?: string | undefined;
64
+ cron: string;
65
+ /** The dotted key of the stored program. */
66
+ program: string;
67
+ input?: unknown;
68
+ /** The time zone of the expression. The default is `local`. */
69
+ timeZone?: ScheduleTimeZone | undefined;
70
+ /** True: replace a schedule of the same name. The default is false: a second schedule of a name is an error. */
71
+ replace?: boolean | undefined;
72
+ }
73
+
74
+ export interface ScheduleAddOutput {
75
+ schedule: ScheduleView;
76
+ }
77
+
78
+ // =============================================================================
79
+ // schedule.list
80
+ // =============================================================================
81
+
82
+ export interface ScheduleListInput {
83
+ /** Only the schedules of this program. */
84
+ program?: string | undefined;
85
+ }
86
+
87
+ export interface ScheduleListOutput {
88
+ /** The schedules, sorted by name. */
89
+ schedules: ScheduleView[];
90
+ }
91
+
92
+ // =============================================================================
93
+ // schedule.remove
94
+ // =============================================================================
95
+
96
+ export interface ScheduleRemoveInput {
97
+ id: string;
98
+ }
99
+
100
+ export interface ScheduleRemoveOutput {
101
+ /** True when the schedule existed. */
102
+ removed: boolean;
103
+ }
104
+
105
+ // =============================================================================
106
+ // schedule.next
107
+ // =============================================================================
108
+
109
+ export interface ScheduleNextInput {
110
+ cron: string;
111
+ /** The number of times: 1 to 100. The default is 5. */
112
+ count?: number | undefined;
113
+ /** The times come after this time: an ISO text. The default is now. */
114
+ after?: string | undefined;
115
+ /** The time zone of the expression. The default is `local`. */
116
+ timeZone?: ScheduleTimeZone | undefined;
117
+ }
118
+
119
+ export interface ScheduleNextOutput {
120
+ /** The next times, as ISO texts in the time zone of the expression. Fewer than `count` when the expression has fewer times in the next 9 years. */
121
+ times: string[];
122
+ }