@cloudsnorkel/cdk-github-runners 0.14.24 → 0.15.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 (142) hide show
  1. package/.jsii +5953 -602
  2. package/API.md +1349 -115
  3. package/README.md +53 -1
  4. package/assets/delete-failed-runner.lambda/index.js +122 -9
  5. package/assets/idle-runner-repear.lambda/index.js +153 -14
  6. package/assets/image-builders/aws-image-builder/delete-resources.lambda/index.js +1 -1
  7. package/assets/image-builders/build-image.lambda/index.js +1 -1
  8. package/assets/providers/ami-root-device.lambda/index.js +1 -1
  9. package/assets/setup.lambda/index.html +7 -7
  10. package/assets/setup.lambda/index.js +118 -8
  11. package/assets/status.lambda/index.js +121 -8
  12. package/assets/token-retriever.lambda/index.js +121 -8
  13. package/assets/warm-runner-manager.lambda/index.js +5909 -0
  14. package/assets/webhook-handler.lambda/index.js +126 -11
  15. package/assets/webhook-redelivery.lambda/index.js +139 -24
  16. package/lib/access.js +1 -1
  17. package/lib/delete-failed-runner.lambda.js +2 -2
  18. package/lib/idle-runner-repear.lambda.js +33 -7
  19. package/lib/image-builders/api.js +1 -1
  20. package/lib/image-builders/aws-image-builder/base-image.d.ts +13 -0
  21. package/lib/image-builders/aws-image-builder/base-image.js +36 -3
  22. package/lib/image-builders/aws-image-builder/builder.js +4 -4
  23. package/lib/image-builders/aws-image-builder/delete-resources.lambda.js +2 -2
  24. package/lib/image-builders/aws-image-builder/deprecated/ami.js +1 -1
  25. package/lib/image-builders/aws-image-builder/deprecated/container.js +1 -1
  26. package/lib/image-builders/aws-image-builder/deprecated/linux-components.js +1 -1
  27. package/lib/image-builders/aws-image-builder/deprecated/windows-components.js +1 -1
  28. package/lib/image-builders/build-image.lambda.js +2 -2
  29. package/lib/image-builders/codebuild-deprecated.js +1 -1
  30. package/lib/image-builders/components.js +3 -3
  31. package/lib/image-builders/static.js +1 -1
  32. package/lib/index.d.ts +1 -0
  33. package/lib/index.js +2 -1
  34. package/lib/lambda-github.d.ts +1 -1
  35. package/lib/lambda-github.js +3 -2
  36. package/lib/lambda-helpers.js +4 -4
  37. package/lib/providers/ami-root-device.lambda.js +2 -2
  38. package/lib/providers/codebuild.d.ts +18 -2
  39. package/lib/providers/codebuild.js +15 -4
  40. package/lib/providers/common.d.ts +47 -3
  41. package/lib/providers/common.js +29 -5
  42. package/lib/providers/composite.js +14 -19
  43. package/lib/providers/ec2.d.ts +9 -2
  44. package/lib/providers/ec2.js +84 -42
  45. package/lib/providers/ecs.d.ts +19 -2
  46. package/lib/providers/ecs.js +49 -44
  47. package/lib/providers/fargate.d.ts +2 -2
  48. package/lib/providers/fargate.js +19 -36
  49. package/lib/providers/lambda.d.ts +2 -2
  50. package/lib/providers/lambda.js +3 -3
  51. package/lib/runner.d.ts +31 -3
  52. package/lib/runner.js +171 -46
  53. package/lib/secrets.js +1 -1
  54. package/lib/setup.lambda.js +2 -2
  55. package/lib/utils.d.ts +10 -1
  56. package/lib/utils.js +15 -1
  57. package/lib/warm-runner-manager-function.d.ts +18 -0
  58. package/lib/warm-runner-manager-function.js +24 -0
  59. package/lib/warm-runner-manager.lambda.d.ts +41 -0
  60. package/lib/warm-runner-manager.lambda.js +487 -0
  61. package/lib/warm-runner.d.ts +155 -0
  62. package/lib/warm-runner.js +217 -0
  63. package/lib/webhook-handler.lambda.js +5 -3
  64. package/lib/webhook-redelivery.lambda.js +17 -16
  65. package/lib/webhook.d.ts +4 -0
  66. package/lib/webhook.js +2 -1
  67. package/node_modules/cron-parser/LICENSE +21 -0
  68. package/node_modules/cron-parser/README.md +408 -0
  69. package/node_modules/cron-parser/dist/CronDate.js +518 -0
  70. package/node_modules/cron-parser/dist/CronExpression.js +520 -0
  71. package/node_modules/cron-parser/dist/CronExpressionParser.js +382 -0
  72. package/node_modules/cron-parser/dist/CronFieldCollection.js +371 -0
  73. package/node_modules/cron-parser/dist/CronFileParser.js +109 -0
  74. package/node_modules/cron-parser/dist/fields/CronDayOfMonth.js +44 -0
  75. package/node_modules/cron-parser/dist/fields/CronDayOfWeek.js +51 -0
  76. package/node_modules/cron-parser/dist/fields/CronField.js +214 -0
  77. package/node_modules/cron-parser/dist/fields/CronHour.js +40 -0
  78. package/node_modules/cron-parser/dist/fields/CronMinute.js +40 -0
  79. package/node_modules/cron-parser/dist/fields/CronMonth.js +44 -0
  80. package/node_modules/cron-parser/dist/fields/CronSecond.js +40 -0
  81. package/node_modules/cron-parser/dist/fields/index.js +24 -0
  82. package/node_modules/cron-parser/dist/fields/types.js +2 -0
  83. package/node_modules/cron-parser/dist/index.js +31 -0
  84. package/node_modules/cron-parser/dist/types/CronDate.d.ts +288 -0
  85. package/node_modules/cron-parser/dist/types/CronExpression.d.ts +118 -0
  86. package/node_modules/cron-parser/dist/types/CronExpressionParser.d.ts +70 -0
  87. package/node_modules/cron-parser/dist/types/CronFieldCollection.d.ts +153 -0
  88. package/node_modules/cron-parser/dist/types/CronFileParser.d.ts +30 -0
  89. package/node_modules/cron-parser/dist/types/fields/CronDayOfMonth.d.ts +25 -0
  90. package/node_modules/cron-parser/dist/types/fields/CronDayOfWeek.d.ts +30 -0
  91. package/node_modules/cron-parser/dist/types/fields/CronField.d.ts +130 -0
  92. package/node_modules/cron-parser/dist/types/fields/CronHour.d.ts +23 -0
  93. package/node_modules/cron-parser/dist/types/fields/CronMinute.d.ts +23 -0
  94. package/node_modules/cron-parser/dist/types/fields/CronMonth.d.ts +24 -0
  95. package/node_modules/cron-parser/dist/types/fields/CronSecond.d.ts +23 -0
  96. package/node_modules/cron-parser/dist/types/fields/index.d.ts +8 -0
  97. package/node_modules/cron-parser/dist/types/fields/types.d.ts +18 -0
  98. package/node_modules/cron-parser/dist/types/index.d.ts +8 -0
  99. package/node_modules/cron-parser/dist/types/utils/random.d.ts +10 -0
  100. package/node_modules/cron-parser/dist/utils/random.js +38 -0
  101. package/node_modules/cron-parser/package.json +117 -0
  102. package/node_modules/luxon/LICENSE.md +7 -0
  103. package/node_modules/luxon/README.md +55 -0
  104. package/node_modules/luxon/build/amd/luxon.js +8741 -0
  105. package/node_modules/luxon/build/amd/luxon.js.map +1 -0
  106. package/node_modules/luxon/build/cjs-browser/luxon.js +8739 -0
  107. package/node_modules/luxon/build/cjs-browser/luxon.js.map +1 -0
  108. package/node_modules/luxon/build/es6/luxon.mjs +8133 -0
  109. package/node_modules/luxon/build/es6/luxon.mjs.map +1 -0
  110. package/node_modules/luxon/build/global/luxon.js +8744 -0
  111. package/node_modules/luxon/build/global/luxon.js.map +1 -0
  112. package/node_modules/luxon/build/global/luxon.min.js +1 -0
  113. package/node_modules/luxon/build/global/luxon.min.js.map +1 -0
  114. package/node_modules/luxon/build/node/luxon.js +7792 -0
  115. package/node_modules/luxon/build/node/luxon.js.map +1 -0
  116. package/node_modules/luxon/package.json +87 -0
  117. package/node_modules/luxon/src/datetime.js +2603 -0
  118. package/node_modules/luxon/src/duration.js +1009 -0
  119. package/node_modules/luxon/src/errors.js +61 -0
  120. package/node_modules/luxon/src/impl/conversions.js +206 -0
  121. package/node_modules/luxon/src/impl/diff.js +95 -0
  122. package/node_modules/luxon/src/impl/digits.js +94 -0
  123. package/node_modules/luxon/src/impl/english.js +233 -0
  124. package/node_modules/luxon/src/impl/formats.js +176 -0
  125. package/node_modules/luxon/src/impl/formatter.js +434 -0
  126. package/node_modules/luxon/src/impl/invalid.js +14 -0
  127. package/node_modules/luxon/src/impl/locale.js +569 -0
  128. package/node_modules/luxon/src/impl/regexParser.js +335 -0
  129. package/node_modules/luxon/src/impl/tokenParser.js +505 -0
  130. package/node_modules/luxon/src/impl/util.js +330 -0
  131. package/node_modules/luxon/src/impl/zoneUtil.js +34 -0
  132. package/node_modules/luxon/src/info.js +205 -0
  133. package/node_modules/luxon/src/interval.js +669 -0
  134. package/node_modules/luxon/src/luxon.js +26 -0
  135. package/node_modules/luxon/src/package.json +4 -0
  136. package/node_modules/luxon/src/settings.js +180 -0
  137. package/node_modules/luxon/src/zone.js +97 -0
  138. package/node_modules/luxon/src/zones/IANAZone.js +235 -0
  139. package/node_modules/luxon/src/zones/fixedOffsetZone.js +150 -0
  140. package/node_modules/luxon/src/zones/invalidZone.js +53 -0
  141. package/node_modules/luxon/src/zones/systemZone.js +61 -0
  142. package/package.json +33 -24
@@ -0,0 +1,408 @@
1
+ # cron-parser
2
+
3
+ [![Build Status](https://github.com/harrisiirak/cron-parser/actions/workflows/push.yml/badge.svg?branch=master)](https://github.com/harrisiirak/cron-parser/actions/workflows/push.yml)
4
+ [![NPM version](https://badge.fury.io/js/cron-parser.png)](http://badge.fury.io/js/cron-parser)
5
+ ![Statements](./coverage/badge-statements.svg)
6
+
7
+ A JavaScript library for parsing and manipulating cron expressions. Features timezone support, DST handling, and iterator capabilities.
8
+
9
+ [API documentation](https://harrisiirak.github.io/cron-parser/)
10
+
11
+ ## Requirements
12
+
13
+ - Node.js >= 18
14
+ - TypeScript >= 5
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ npm install cron-parser
20
+ ```
21
+
22
+ ## Cron Format
23
+
24
+ ```
25
+ * * * * * *
26
+ ┬ ┬ ┬ ┬ ┬ ┬
27
+ │ │ │ │ │ │
28
+ │ │ │ │ │ └─ day of week (0-7, 1L-7L) (0 or 7 is Sun)
29
+ │ │ │ │ └────── month (1-12, JAN-DEC)
30
+ │ │ │ └─────────── day of month (1-31, L)
31
+ │ │ └──────────────── hour (0-23)
32
+ │ └───────────────────── minute (0-59)
33
+ └────────────────────────── second (0-59, optional)
34
+ ```
35
+
36
+ ### Special Characters
37
+
38
+ | Character | Description | Example |
39
+ | --------- | ------------------------- | ---------------------------------------------------------------------- |
40
+ | `*` | Any value | `* * * * *` (every minute) |
41
+ | `?` | Any value (alias for `*`) | `? * * * *` (every minute) |
42
+ | `,` | Value list separator | `1,2,3 * * * *` (1st, 2nd, and 3rd minute) |
43
+ | `-` | Range of values | `1-5 * * * *` (every minute from 1 through 5) |
44
+ | `/` | Step values | `*/5 * * * *` (every 5th minute) |
45
+ | `L` | Last day of month/week | `0 0 L * *` (midnight on last day of month) |
46
+ | `#` | Nth day of month | `0 0 * * 1#1` (first Monday of month) |
47
+ | `H` | Randomized value | `H * * * *` (every n minute where n is randomly picked within [0, 59]) |
48
+
49
+ ### Predefined Expressions
50
+
51
+ | Expression | Description | Equivalent |
52
+ | ----------- | ----------------------------------------- | --------------- |
53
+ | `@yearly` | Once a year at midnight of January 1 | `0 0 0 1 1 *` |
54
+ | `@monthly` | Once a month at midnight of first day | `0 0 0 1 * *` |
55
+ | `@weekly` | Once a week at midnight on Sunday | `0 0 0 * * 0` |
56
+ | `@daily` | Once a day at midnight | `0 0 0 * * *` |
57
+ | `@hourly` | Once an hour at the beginning of the hour | `0 0 * * * *` |
58
+ | `@minutely` | Once a minute | `0 * * * * *` |
59
+ | `@secondly` | Once a second | `* * * * * *` |
60
+ | `@weekdays` | Every weekday at midnight | `0 0 0 * * 1-5` |
61
+ | `@weekends` | Every weekend at midnight | `0 0 0 * * 0,6` |
62
+
63
+ ### Field Values
64
+
65
+ | Field | Values | Special Characters | Aliases |
66
+ | ------------ | ------ | ------------------------------- | ------------------------------ |
67
+ | second | 0-59 | `*` `?` `,` `-` `/` `H` | |
68
+ | minute | 0-59 | `*` `?` `,` `-` `/` `H` | |
69
+ | hour | 0-23 | `*` `?` `,` `-` `/` `H` | |
70
+ | day of month | 1-31 | `*` `?` `,` `-` `/` `H` `L` | |
71
+ | month | 1-12 | `*` `?` `,` `-` `/` `H` | `JAN`-`DEC` |
72
+ | day of week | 0-7 | `*` `?` `,` `-` `/` `H` `L` `#` | `SUN`-`SAT` (0 or 7 is Sunday) |
73
+
74
+ ## Options
75
+
76
+ | Option | Type | Description |
77
+ | ----------- | ------------------------ | --------------------------------------------------------------------------------------------------------------------------- |
78
+ | currentDate | Date \| string \| number | Current date. Defaults to current local time in UTC. If not provided but startDate is set, startDate is used as currentDate |
79
+ | endDate | Date \| string \| number | End date of iteration range. Sets iteration range end point |
80
+ | startDate | Date \| string \| number | Start date of iteration range. Set iteration range start point |
81
+ | tz | string | Timezone (e.g., 'Europe/London') |
82
+ | hashSeed | string | A seed to be used in conjunction with the `H` special character |
83
+ | strict | boolean | Enable strict mode validation |
84
+
85
+ When using string dates, the following formats are supported:
86
+
87
+ - ISO8601
88
+ - HTTP and RFC2822
89
+ - SQL
90
+
91
+ ## Basic Usage
92
+
93
+ ### Expression Parsing
94
+
95
+ ```typescript
96
+ import { CronExpressionParser } from 'cron-parser';
97
+
98
+ try {
99
+ const interval = CronExpressionParser.parse('*/2 * * * *');
100
+
101
+ // Get next date
102
+ console.log('Next:', interval.next().toString());
103
+ // Get next 3 dates
104
+ console.log(
105
+ 'Next 3:',
106
+ interval.take(3).map((date) => date.toString()),
107
+ );
108
+
109
+ // Get previous date
110
+ console.log('Previous:', interval.prev().toString());
111
+ } catch (err) {
112
+ console.log('Error:', err.message);
113
+ }
114
+ ```
115
+
116
+ ### With Options
117
+
118
+ ```typescript
119
+ import { CronExpressionParser } from 'cron-parser';
120
+
121
+ const options = {
122
+ currentDate: '2023-01-01T00:00:00Z',
123
+ endDate: '2024-01-01T00:00:00Z',
124
+ tz: 'Europe/London',
125
+ };
126
+
127
+ try {
128
+ const interval = CronExpressionParser.parse('0 0 * * *', options);
129
+ console.log('Next:', interval.next().toString());
130
+ } catch (err) {
131
+ console.log('Error:', err.message);
132
+ }
133
+ ```
134
+
135
+ ### Date Range Handling
136
+
137
+ The library provides handling of date ranges with automatic adjustment of the `currentDate`:
138
+
139
+ **startDate as fallback**: If `currentDate` is not provided but `startDate` is, the `startDate` will be used as the `currentDate`.
140
+
141
+ ```typescript
142
+ const options = {
143
+ startDate: '2023-01-01T00:00:00Z', // No currentDate provided
144
+ };
145
+ // currentDate will be set to 2023-01-01T00:00:00Z automatically
146
+ const interval = CronExpressionParser.parse('0 0 * * *', options);
147
+ ```
148
+
149
+ **Automatic clamping**: If `currentDate` is outside the bounds defined by `startDate` and `endDate`, it will be automatically adjusted:
150
+
151
+ ```typescript
152
+ const options = {
153
+ currentDate: '2022-01-01T00:00:00Z', // Before startDate
154
+ startDate: '2023-01-01T00:00:00Z',
155
+ endDate: '2024-01-01T00:00:00Z',
156
+ };
157
+ // currentDate will be clamped to startDate (2023-01-01T00:00:00Z)
158
+ const interval = CronExpressionParser.parse('0 0 * * *', options);
159
+ ```
160
+
161
+ **Validation during iteration**: While the initial `currentDate` is automatically adjusted, the library still validates date bounds during iteration:
162
+
163
+ ```typescript
164
+ const options = {
165
+ currentDate: '2023-12-31T00:00:00Z',
166
+ endDate: '2024-01-01T00:00:00Z', // Very close end date
167
+ };
168
+
169
+ const interval = CronExpressionParser.parse('0 0 * * *', options);
170
+ console.log('Next:', interval.next().toString()); // Works fine
171
+
172
+ // This will throw an error because it would exceed endDate
173
+ try {
174
+ console.log('Next:', interval.next().toString());
175
+ } catch (err) {
176
+ console.log('Error:', err.message); // "Out of the time span range"
177
+ }
178
+ ```
179
+
180
+ This behavior simplifies working with date ranges by removing the need to manually ensure that `currentDate` is within bounds, reducing confusion and making the API more intuitive.
181
+
182
+ ### Crontab File Operations
183
+
184
+ For working with crontab files, use the CronFileParser:
185
+
186
+ ```typescript
187
+ import { CronFileParser } from 'cron-parser';
188
+
189
+ // Async file parsing
190
+ try {
191
+ const result = await CronFileParser.parseFile('/path/to/crontab');
192
+ console.log('Variables:', result.variables);
193
+ console.log('Expressions:', result.expressions);
194
+ console.log('Errors:', result.errors);
195
+ } catch (err) {
196
+ console.log('Error:', err.message);
197
+ }
198
+
199
+ // Sync file parsing
200
+ try {
201
+ const result = CronFileParser.parseFileSync('/path/to/crontab');
202
+ console.log('Variables:', result.variables);
203
+ console.log('Expressions:', result.expressions);
204
+ console.log('Errors:', result.errors);
205
+ } catch (err) {
206
+ console.log('Error:', err.message);
207
+ }
208
+ ```
209
+
210
+ ## Advanced Features
211
+
212
+ ### Strict Mode
213
+
214
+ In several implementations of CRON, it's ambiguous to specify both the Day Of Month and Day Of Week parameters simultaneously, as it's unclear which one should take precedence. Despite this ambiguity, this library allows both parameters to be set by default, although the resultant behavior might not align with your expectations.
215
+
216
+ To resolve this ambiguity, you can activate the strict mode of the library. When strict mode is enabled, the library enforces several validation rules:
217
+
218
+ 1. **Day Of Month and Day Of Week**: Prevents the simultaneous setting of both Day Of Month and Day Of Week fields
219
+ 2. **Complete Expression**: Requires all 6 fields to be present in the expression (second, minute, hour, day of month, month, day of week)
220
+ 3. **Non-empty Expression**: Rejects empty expressions that would otherwise default to '0 \* \* \* \* \*'
221
+
222
+ These validations help ensure that your cron expressions are unambiguous and correctly formatted.
223
+
224
+ ```typescript
225
+ import { CronExpressionParser } from 'cron-parser';
226
+
227
+ // This will throw an error in strict mode because it uses both dayOfMonth and dayOfWeek
228
+ const options = {
229
+ currentDate: new Date('Mon, 12 Sep 2022 14:00:00'),
230
+ strict: true,
231
+ };
232
+
233
+ try {
234
+ // This will throw an error in strict mode
235
+ CronExpressionParser.parse('0 0 12 1-31 * 1', options);
236
+ } catch (err) {
237
+ console.log('Error:', err.message);
238
+ // Error: Cannot use both dayOfMonth and dayOfWeek together in strict mode!
239
+ }
240
+
241
+ // This will also throw an error in strict mode because it has fewer than 6 fields
242
+ try {
243
+ CronExpressionParser.parse('0 20 15 * *', { strict: true });
244
+ } catch (err) {
245
+ console.log('Error:', err.message);
246
+ // Error: Invalid cron expression, expected 6 fields
247
+ }
248
+ ```
249
+
250
+ ### Last Day of Month/Week Support
251
+
252
+ The library supports parsing the range `0L - 7L` in the `weekday` position of the cron expression, where the `L` means "last occurrence of this weekday for the month in progress".
253
+
254
+ For example, the following expression will run on the last Monday of the month at midnight:
255
+
256
+ ```typescript
257
+ import { CronExpressionParser } from 'cron-parser';
258
+
259
+ // Last Monday of every month at midnight
260
+ const lastMonday = CronExpressionParser.parse('0 0 0 * * 1L');
261
+
262
+ // You can also combine L expressions with other weekday expressions
263
+ // This will run every Monday and the last Wednesday of the month
264
+ const mixedWeekdays = CronExpressionParser.parse('0 0 0 * * 1,3L');
265
+
266
+ // Last day of every month
267
+ const lastDay = CronExpressionParser.parse('0 0 L * *');
268
+ ```
269
+
270
+ ### Using Iterator
271
+
272
+ ```typescript
273
+ import { CronExpressionParser } from 'cron-parser';
274
+
275
+ const interval = CronExpressionParser.parse('0 */2 * * *');
276
+
277
+ // Using for...of
278
+ for (const date of interval) {
279
+ console.log('Iterator value:', date.toString());
280
+ if (someCondition) break;
281
+ }
282
+
283
+ // Using take() for a specific number of iterations
284
+ const nextFiveDates = interval.take(5);
285
+ console.log(
286
+ 'Next 5 dates:',
287
+ nextFiveDates.map((date) => date.toString()),
288
+ );
289
+ ```
290
+
291
+ ### Timezone Support
292
+
293
+ The library provides robust timezone support using Luxon, handling DST transitions correctly:
294
+
295
+ ```typescript
296
+ import { CronExpressionParser } from 'cron-parser';
297
+
298
+ const options = {
299
+ currentDate: '2023-03-26T01:00:00',
300
+ tz: 'Europe/London',
301
+ };
302
+
303
+ const interval = CronExpressionParser.parse('0 * * * *', options);
304
+
305
+ // Will correctly handle DST transition
306
+ console.log('Next dates during DST transition:');
307
+ console.log(interval.next().toString());
308
+ console.log(interval.next().toString());
309
+ console.log(interval.next().toString());
310
+ ```
311
+
312
+ ### Field Manipulation
313
+
314
+ You can modify cron fields programmatically using `CronFieldCollection.from` and construct a new expression:
315
+
316
+ ```typescript
317
+ import { CronExpressionParser, CronFieldCollection, CronHour, CronMinute } from 'cron-parser';
318
+
319
+ // Parse original expression
320
+ const interval = CronExpressionParser.parse('0 7 * * 1-5');
321
+
322
+ // Create new collection with modified fields using raw values
323
+ const modified = CronFieldCollection.from(interval.fields, {
324
+ hour: [8],
325
+ minute: [30],
326
+ dayOfWeek: [1, 3, 5],
327
+ });
328
+
329
+ console.log(modified.stringify()); // "30 8 * * 1,3,5"
330
+
331
+ // You can also use CronField instances
332
+ const modified2 = CronFieldCollection.from(interval.fields, {
333
+ hour: new CronHour([15]),
334
+ minute: new CronMinute([30]),
335
+ });
336
+
337
+ console.log(modified2.stringify()); // "30 15 * * 1-5"
338
+ ```
339
+
340
+ The `CronFieldCollection.from` method accepts either CronField instances or raw values that would be valid for creating new CronField instances. This is particularly useful when you need to modify only specific fields while keeping others unchanged.
341
+
342
+ ### Hash support
343
+
344
+ The library supports adding [jitter](https://en.wikipedia.org/wiki/Jitter) to the returned intervals using the `H` special character in a field. When `H` is specified instead of `*`, a random value is used (`H` is replaced by `23`, where 23 is picked randomly, within the valid range of the field).
345
+
346
+ This jitter allows to spread the load when it comes to job scheduling. This feature is inspired by Jenkins's cron syntax.
347
+
348
+ ```typescript
349
+ import { CronExpressionParser } from 'cron-parser';
350
+
351
+ // At 23:<randomized> on every day-of-week from Monday through Friday.
352
+ const interval = CronExpressionParser.parse('H 23 * * 1-5');
353
+
354
+ // At <randomized>:30 everyday.
355
+ const interval = CronExpressionParser.parse('30 H * * *');
356
+
357
+ // At every minutes of <randomized> hour at <randomized> second everyday.
358
+ const interval = CronExpressionParser.parse('H * H * * *');
359
+
360
+ // At every 5th minute starting from a random offset.
361
+ // For example, if the random offset is 3, it will run at minutes 3, 8, 13, 18, etc.
362
+ const interval = CronExpressionParser.parse('H/5 * * * *');
363
+
364
+ // At a random minute within the range 0-10 everyday.
365
+ const interval = CronExpressionParser.parse('H(0-10) * * * *');
366
+
367
+ // At every 5th minute starting from a random offset within the range 0-4.
368
+ // For example, if the random offset is 2, it will run at minutes 2, 7, 12, 17, etc.
369
+ // The random offset is constrained to be less than the step value.
370
+ const interval = CronExpressionParser.parse('H(0-29)/5 * * * *');
371
+
372
+ // At every minute of the third <randomized> day of the month
373
+ const interval = CronExpressionParser.parse('* * * * H#3');
374
+ ```
375
+
376
+ The randomness is seed-able using the `hashSeed` option of `CronExpressionOptions`:
377
+
378
+ ```typescript
379
+ import { CronExpressionParser } from 'cron-parser';
380
+
381
+ const options = {
382
+ currentDate: '2023-03-26T01:00:00',
383
+ hashSeed: 'main-backup', // Generally, hashSeed would be a job name for example
384
+ };
385
+
386
+ const interval = CronExpressionParser.parse('H * * * H', options);
387
+
388
+ console.log(interval.stringify()); // "12 * * * 4"
389
+
390
+ const otherInterval = CronExpressionParser.parse('H * * * H', options);
391
+
392
+ // Using the same seed will always return the same jitter
393
+ console.log(otherInterval.stringify()); // "12 * * * 4"
394
+ ```
395
+
396
+ ## Contributing
397
+
398
+ We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details on:
399
+
400
+ - Setting up the development environment
401
+ - Code style and standards
402
+ - Testing requirements
403
+ - Pull request process
404
+ - Reporting bugs and requesting features
405
+
406
+ ## License
407
+
408
+ MIT