@tachybase/module-backup 1.3.17 → 1.3.18
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.
- package/dist/client/cron-jobs-table/AutoBackupTable.schema.d.ts +3 -2
- package/dist/client/index.js +2 -2
- package/dist/externalVersion.js +7 -7
- package/dist/node_modules/@hapi/topo/package.json +1 -1
- package/dist/node_modules/archiver/package.json +1 -1
- package/dist/node_modules/cron-parser/LICENSE +1 -1
- package/dist/node_modules/cron-parser/dist/CronDate.js +497 -0
- package/dist/node_modules/cron-parser/dist/CronExpression.js +376 -0
- package/dist/node_modules/cron-parser/dist/CronExpressionParser.js +384 -0
- package/dist/node_modules/cron-parser/dist/CronFieldCollection.js +371 -0
- package/dist/node_modules/cron-parser/dist/CronFileParser.js +109 -0
- package/dist/node_modules/cron-parser/dist/fields/CronDayOfMonth.js +44 -0
- package/dist/node_modules/cron-parser/dist/fields/CronDayOfWeek.js +51 -0
- package/dist/node_modules/cron-parser/dist/fields/CronField.js +183 -0
- package/dist/node_modules/cron-parser/dist/fields/CronHour.js +40 -0
- package/dist/node_modules/cron-parser/dist/fields/CronMinute.js +40 -0
- package/dist/node_modules/cron-parser/dist/fields/CronMonth.js +44 -0
- package/dist/node_modules/cron-parser/dist/fields/CronSecond.js +40 -0
- package/dist/node_modules/cron-parser/dist/fields/index.js +24 -0
- package/dist/node_modules/cron-parser/dist/fields/types.js +2 -0
- package/dist/node_modules/cron-parser/dist/index.js +1 -0
- package/dist/node_modules/cron-parser/dist/types/CronDate.d.ts +273 -0
- package/dist/node_modules/cron-parser/dist/types/CronExpression.d.ts +110 -0
- package/dist/node_modules/cron-parser/dist/types/CronExpressionParser.d.ts +70 -0
- package/dist/node_modules/cron-parser/dist/types/CronFieldCollection.d.ts +153 -0
- package/dist/node_modules/cron-parser/dist/types/CronFileParser.d.ts +30 -0
- package/dist/node_modules/cron-parser/dist/types/fields/CronDayOfMonth.d.ts +25 -0
- package/dist/node_modules/cron-parser/dist/types/fields/CronDayOfWeek.d.ts +30 -0
- package/dist/node_modules/cron-parser/dist/types/fields/CronField.d.ts +114 -0
- package/dist/node_modules/cron-parser/dist/types/fields/CronHour.d.ts +23 -0
- package/dist/node_modules/cron-parser/dist/types/fields/CronMinute.d.ts +23 -0
- package/dist/node_modules/cron-parser/dist/types/fields/CronMonth.d.ts +24 -0
- package/dist/node_modules/cron-parser/dist/types/fields/CronSecond.d.ts +23 -0
- package/dist/node_modules/cron-parser/dist/types/fields/index.d.ts +8 -0
- package/dist/node_modules/cron-parser/dist/types/fields/types.d.ts +18 -0
- package/dist/node_modules/cron-parser/dist/types/index.d.ts +8 -0
- package/dist/node_modules/cron-parser/dist/types/utils/random.d.ts +10 -0
- package/dist/node_modules/cron-parser/dist/utils/random.js +38 -0
- package/dist/node_modules/cron-parser/package.json +1 -1
- package/dist/node_modules/mkdirp/package.json +1 -1
- package/dist/node_modules/semver/package.json +1 -1
- package/dist/node_modules/yauzl/package.json +1 -1
- package/dist/server/server.d.ts +1 -1
- package/package.json +11 -12
- package/dist/node_modules/cron-parser/lib/date.js +0 -252
- package/dist/node_modules/cron-parser/lib/expression.js +0 -1002
- package/dist/node_modules/cron-parser/lib/field_compactor.js +0 -70
- package/dist/node_modules/cron-parser/lib/field_stringify.js +0 -58
- package/dist/node_modules/cron-parser/lib/parser.js +0 -1
- package/dist/node_modules/cron-parser/types/common.d.ts +0 -131
- package/dist/node_modules/cron-parser/types/index.d.ts +0 -45
- package/dist/node_modules/cron-parser/types/ts3/index.d.ts +0 -28
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CronFieldCollection = void 0;
|
|
4
|
+
const fields_1 = require("./fields");
|
|
5
|
+
/**
|
|
6
|
+
* Represents a complete set of cron fields.
|
|
7
|
+
* @class CronFieldCollection
|
|
8
|
+
*/
|
|
9
|
+
class CronFieldCollection {
|
|
10
|
+
#second;
|
|
11
|
+
#minute;
|
|
12
|
+
#hour;
|
|
13
|
+
#dayOfMonth;
|
|
14
|
+
#month;
|
|
15
|
+
#dayOfWeek;
|
|
16
|
+
/**
|
|
17
|
+
* Creates a new CronFieldCollection instance by partially overriding fields from an existing one.
|
|
18
|
+
* @param {CronFieldCollection} base - The base CronFieldCollection to copy fields from
|
|
19
|
+
* @param {CronFieldOverride} fields - The fields to override, can be CronField instances or raw values
|
|
20
|
+
* @returns {CronFieldCollection} A new CronFieldCollection instance
|
|
21
|
+
* @example
|
|
22
|
+
* const base = new CronFieldCollection({
|
|
23
|
+
* second: new CronSecond([0]),
|
|
24
|
+
* minute: new CronMinute([0]),
|
|
25
|
+
* hour: new CronHour([12]),
|
|
26
|
+
* dayOfMonth: new CronDayOfMonth([1]),
|
|
27
|
+
* month: new CronMonth([1]),
|
|
28
|
+
* dayOfWeek: new CronDayOfWeek([1])
|
|
29
|
+
* });
|
|
30
|
+
*
|
|
31
|
+
* // Using CronField instances
|
|
32
|
+
* const modified1 = CronFieldCollection.from(base, {
|
|
33
|
+
* hour: new CronHour([15]),
|
|
34
|
+
* minute: new CronMinute([30])
|
|
35
|
+
* });
|
|
36
|
+
*
|
|
37
|
+
* // Using raw values
|
|
38
|
+
* const modified2 = CronFieldCollection.from(base, {
|
|
39
|
+
* hour: [15], // Will create new CronHour
|
|
40
|
+
* minute: [30] // Will create new CronMinute
|
|
41
|
+
* });
|
|
42
|
+
*/
|
|
43
|
+
static from(base, fields) {
|
|
44
|
+
return new CronFieldCollection({
|
|
45
|
+
second: this.resolveField(fields_1.CronSecond, base.second, fields.second),
|
|
46
|
+
minute: this.resolveField(fields_1.CronMinute, base.minute, fields.minute),
|
|
47
|
+
hour: this.resolveField(fields_1.CronHour, base.hour, fields.hour),
|
|
48
|
+
dayOfMonth: this.resolveField(fields_1.CronDayOfMonth, base.dayOfMonth, fields.dayOfMonth),
|
|
49
|
+
month: this.resolveField(fields_1.CronMonth, base.month, fields.month),
|
|
50
|
+
dayOfWeek: this.resolveField(fields_1.CronDayOfWeek, base.dayOfWeek, fields.dayOfWeek),
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Resolves a field value, either using the provided CronField instance or creating a new one from raw values.
|
|
55
|
+
* @param constructor - The constructor for creating new field instances
|
|
56
|
+
* @param baseField - The base field to use if no override is provided
|
|
57
|
+
* @param fieldValue - The override value, either a CronField instance or raw values
|
|
58
|
+
* @returns The resolved CronField instance
|
|
59
|
+
* @private
|
|
60
|
+
*/
|
|
61
|
+
static resolveField(constructor, baseField, fieldValue) {
|
|
62
|
+
if (!fieldValue) {
|
|
63
|
+
return baseField;
|
|
64
|
+
}
|
|
65
|
+
if (fieldValue instanceof fields_1.CronField) {
|
|
66
|
+
return fieldValue;
|
|
67
|
+
}
|
|
68
|
+
return new constructor(fieldValue);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* CronFieldCollection constructor. Initializes the cron fields with the provided values.
|
|
72
|
+
* @param {CronFields} param0 - The cron fields values
|
|
73
|
+
* @throws {Error} if validation fails
|
|
74
|
+
* @example
|
|
75
|
+
* const cronFields = new CronFieldCollection({
|
|
76
|
+
* second: new CronSecond([0]),
|
|
77
|
+
* minute: new CronMinute([0, 30]),
|
|
78
|
+
* hour: new CronHour([9]),
|
|
79
|
+
* dayOfMonth: new CronDayOfMonth([15]),
|
|
80
|
+
* month: new CronMonth([1]),
|
|
81
|
+
* dayOfWeek: new CronDayOfTheWeek([1, 2, 3, 4, 5]),
|
|
82
|
+
* })
|
|
83
|
+
*
|
|
84
|
+
* console.log(cronFields.second.values); // [0]
|
|
85
|
+
* console.log(cronFields.minute.values); // [0, 30]
|
|
86
|
+
* console.log(cronFields.hour.values); // [9]
|
|
87
|
+
* console.log(cronFields.dayOfMonth.values); // [15]
|
|
88
|
+
* console.log(cronFields.month.values); // [1]
|
|
89
|
+
* console.log(cronFields.dayOfWeek.values); // [1, 2, 3, 4, 5]
|
|
90
|
+
*/
|
|
91
|
+
constructor({ second, minute, hour, dayOfMonth, month, dayOfWeek }) {
|
|
92
|
+
if (!second) {
|
|
93
|
+
throw new Error('Validation error, Field second is missing');
|
|
94
|
+
}
|
|
95
|
+
if (!minute) {
|
|
96
|
+
throw new Error('Validation error, Field minute is missing');
|
|
97
|
+
}
|
|
98
|
+
if (!hour) {
|
|
99
|
+
throw new Error('Validation error, Field hour is missing');
|
|
100
|
+
}
|
|
101
|
+
if (!dayOfMonth) {
|
|
102
|
+
throw new Error('Validation error, Field dayOfMonth is missing');
|
|
103
|
+
}
|
|
104
|
+
if (!month) {
|
|
105
|
+
throw new Error('Validation error, Field month is missing');
|
|
106
|
+
}
|
|
107
|
+
if (!dayOfWeek) {
|
|
108
|
+
throw new Error('Validation error, Field dayOfWeek is missing');
|
|
109
|
+
}
|
|
110
|
+
if (month.values.length === 1 && !dayOfMonth.hasLastChar) {
|
|
111
|
+
if (!(parseInt(dayOfMonth.values[0], 10) <= fields_1.CronMonth.daysInMonth[month.values[0] - 1])) {
|
|
112
|
+
throw new Error('Invalid explicit day of month definition');
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
this.#second = second;
|
|
116
|
+
this.#minute = minute;
|
|
117
|
+
this.#hour = hour;
|
|
118
|
+
this.#month = month;
|
|
119
|
+
this.#dayOfWeek = dayOfWeek;
|
|
120
|
+
this.#dayOfMonth = dayOfMonth;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Returns the second field.
|
|
124
|
+
* @returns {CronSecond}
|
|
125
|
+
*/
|
|
126
|
+
get second() {
|
|
127
|
+
return this.#second;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Returns the minute field.
|
|
131
|
+
* @returns {CronMinute}
|
|
132
|
+
*/
|
|
133
|
+
get minute() {
|
|
134
|
+
return this.#minute;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Returns the hour field.
|
|
138
|
+
* @returns {CronHour}
|
|
139
|
+
*/
|
|
140
|
+
get hour() {
|
|
141
|
+
return this.#hour;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Returns the day of the month field.
|
|
145
|
+
* @returns {CronDayOfMonth}
|
|
146
|
+
*/
|
|
147
|
+
get dayOfMonth() {
|
|
148
|
+
return this.#dayOfMonth;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Returns the month field.
|
|
152
|
+
* @returns {CronMonth}
|
|
153
|
+
*/
|
|
154
|
+
get month() {
|
|
155
|
+
return this.#month;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Returns the day of the week field.
|
|
159
|
+
* @returns {CronDayOfWeek}
|
|
160
|
+
*/
|
|
161
|
+
get dayOfWeek() {
|
|
162
|
+
return this.#dayOfWeek;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Returns a string representation of the cron fields.
|
|
166
|
+
* @param {(number | CronChars)[]} input - The cron fields values
|
|
167
|
+
* @static
|
|
168
|
+
* @returns {FieldRange[]} - The compacted cron fields
|
|
169
|
+
*/
|
|
170
|
+
static compactField(input) {
|
|
171
|
+
if (input.length === 0) {
|
|
172
|
+
return [];
|
|
173
|
+
}
|
|
174
|
+
// Initialize the output array and current IFieldRange
|
|
175
|
+
const output = [];
|
|
176
|
+
let current = undefined;
|
|
177
|
+
input.forEach((item, i, arr) => {
|
|
178
|
+
// If the current FieldRange is undefined, create a new one with the current item as the start.
|
|
179
|
+
if (current === undefined) {
|
|
180
|
+
current = { start: item, count: 1 };
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
// Cache the previous and next items in the array.
|
|
184
|
+
const prevItem = arr[i - 1] || current.start;
|
|
185
|
+
const nextItem = arr[i + 1];
|
|
186
|
+
// If the current item is 'L' or 'W', push the current FieldRange to the output and
|
|
187
|
+
// create a new FieldRange with the current item as the start.
|
|
188
|
+
// 'L' and 'W' characters are special cases that need to be handled separately.
|
|
189
|
+
if (item === 'L' || item === 'W') {
|
|
190
|
+
output.push(current);
|
|
191
|
+
output.push({ start: item, count: 1 });
|
|
192
|
+
current = undefined;
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
// If the current step is undefined and there is a next item, update the current IFieldRange.
|
|
196
|
+
// This block checks if the current step needs to be updated and does so if needed.
|
|
197
|
+
if (current.step === undefined && nextItem !== undefined) {
|
|
198
|
+
const step = item - prevItem;
|
|
199
|
+
const nextStep = nextItem - item;
|
|
200
|
+
// If the current step is less or equal to the next step, update the current FieldRange to include the current item.
|
|
201
|
+
if (step <= nextStep) {
|
|
202
|
+
current = { ...current, count: 2, end: item, step };
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
current.step = 1;
|
|
206
|
+
}
|
|
207
|
+
// If the difference between the current item and the current end is equal to the current step,
|
|
208
|
+
// update the current IFieldRange's count and end.
|
|
209
|
+
// This block checks if the current item is part of the current range and updates the range accordingly.
|
|
210
|
+
if (item - (current.end ?? 0) === current.step) {
|
|
211
|
+
current.count++;
|
|
212
|
+
current.end = item;
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
// If the count is 1, push a new FieldRange with the current start.
|
|
216
|
+
// This handles the case where the current range has only one element.
|
|
217
|
+
if (current.count === 1) {
|
|
218
|
+
// If the count is 2, push two separate IFieldRanges, one for each element.
|
|
219
|
+
output.push({ start: current.start, count: 1 });
|
|
220
|
+
}
|
|
221
|
+
else if (current.count === 2) {
|
|
222
|
+
output.push({ start: current.start, count: 1 });
|
|
223
|
+
// current.end can never be undefined here but typescript doesn't know that
|
|
224
|
+
// this is why we ?? it and then ignore the prevItem in the coverage
|
|
225
|
+
output.push({
|
|
226
|
+
start: current.end ?? /* istanbul ignore next - see above */ prevItem,
|
|
227
|
+
count: 1,
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
// Otherwise, push the current FieldRange to the output.
|
|
232
|
+
output.push(current);
|
|
233
|
+
}
|
|
234
|
+
// Reset the current FieldRange with the current item as the start.
|
|
235
|
+
current = { start: item, count: 1 };
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
// Push the final IFieldRange, if any, to the output array.
|
|
239
|
+
if (current) {
|
|
240
|
+
output.push(current);
|
|
241
|
+
}
|
|
242
|
+
return output;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Handles a single range.
|
|
246
|
+
* @param {CronField} field - The cron field to stringify
|
|
247
|
+
* @param {FieldRange} range {start: number, end: number, step: number, count: number} The range to handle.
|
|
248
|
+
* @param {number} max The maximum value for the field.
|
|
249
|
+
* @returns {string | null} The stringified range or null if it cannot be stringified.
|
|
250
|
+
* @private
|
|
251
|
+
*/
|
|
252
|
+
static #handleSingleRange(field, range, max) {
|
|
253
|
+
const step = range.step;
|
|
254
|
+
if (!step) {
|
|
255
|
+
return null;
|
|
256
|
+
}
|
|
257
|
+
if (step === 1 && range.start === field.min && range.end && range.end >= max) {
|
|
258
|
+
return field.hasQuestionMarkChar ? '?' : '*';
|
|
259
|
+
}
|
|
260
|
+
if (step !== 1 && range.start === field.min && range.end && range.end >= max - step + 1) {
|
|
261
|
+
return `*/${step}`;
|
|
262
|
+
}
|
|
263
|
+
return null;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Handles multiple ranges.
|
|
267
|
+
* @param {FieldRange} range {start: number, end: number, step: number, count: number} The range to handle.
|
|
268
|
+
* @param {number} max The maximum value for the field.
|
|
269
|
+
* @returns {string} The stringified range.
|
|
270
|
+
* @private
|
|
271
|
+
*/
|
|
272
|
+
static #handleMultipleRanges(range, max) {
|
|
273
|
+
const step = range.step;
|
|
274
|
+
if (step === 1) {
|
|
275
|
+
return `${range.start}-${range.end}`;
|
|
276
|
+
}
|
|
277
|
+
const multiplier = range.start === 0 ? range.count - 1 : range.count;
|
|
278
|
+
/* istanbul ignore if */
|
|
279
|
+
if (!step) {
|
|
280
|
+
throw new Error('Unexpected range step');
|
|
281
|
+
}
|
|
282
|
+
/* istanbul ignore if */
|
|
283
|
+
if (!range.end) {
|
|
284
|
+
throw new Error('Unexpected range end');
|
|
285
|
+
}
|
|
286
|
+
if (step * multiplier > range.end) {
|
|
287
|
+
const mapFn = (_, index) => {
|
|
288
|
+
/* istanbul ignore if */
|
|
289
|
+
if (typeof range.start !== 'number') {
|
|
290
|
+
throw new Error('Unexpected range start');
|
|
291
|
+
}
|
|
292
|
+
return index % step === 0 ? range.start + index : null;
|
|
293
|
+
};
|
|
294
|
+
/* istanbul ignore if */
|
|
295
|
+
if (typeof range.start !== 'number') {
|
|
296
|
+
throw new Error('Unexpected range start');
|
|
297
|
+
}
|
|
298
|
+
const seed = { length: range.end - range.start + 1 };
|
|
299
|
+
return Array.from(seed, mapFn)
|
|
300
|
+
.filter((value) => value !== null)
|
|
301
|
+
.join(',');
|
|
302
|
+
}
|
|
303
|
+
return range.end === max - step + 1 ? `${range.start}/${step}` : `${range.start}-${range.end}/${step}`;
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Returns a string representation of the cron fields.
|
|
307
|
+
* @param {CronField} field - The cron field to stringify
|
|
308
|
+
* @static
|
|
309
|
+
* @returns {string} - The stringified cron field
|
|
310
|
+
*/
|
|
311
|
+
stringifyField(field) {
|
|
312
|
+
let max = field.max;
|
|
313
|
+
let values = field.values;
|
|
314
|
+
if (field instanceof fields_1.CronDayOfWeek) {
|
|
315
|
+
max = 6;
|
|
316
|
+
const dayOfWeek = this.#dayOfWeek.values;
|
|
317
|
+
values = dayOfWeek[dayOfWeek.length - 1] === 7 ? dayOfWeek.slice(0, -1) : dayOfWeek;
|
|
318
|
+
}
|
|
319
|
+
if (field instanceof fields_1.CronDayOfMonth) {
|
|
320
|
+
max = this.#month.values.length === 1 ? fields_1.CronMonth.daysInMonth[this.#month.values[0] - 1] : field.max;
|
|
321
|
+
}
|
|
322
|
+
const ranges = CronFieldCollection.compactField(values);
|
|
323
|
+
if (ranges.length === 1) {
|
|
324
|
+
const singleRangeResult = CronFieldCollection.#handleSingleRange(field, ranges[0], max);
|
|
325
|
+
if (singleRangeResult) {
|
|
326
|
+
return singleRangeResult;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
return ranges
|
|
330
|
+
.map((range) => {
|
|
331
|
+
const value = range.count === 1 ? range.start.toString() : CronFieldCollection.#handleMultipleRanges(range, max);
|
|
332
|
+
if (field instanceof fields_1.CronDayOfWeek && field.nthDay > 0) {
|
|
333
|
+
return `${value}#${field.nthDay}`;
|
|
334
|
+
}
|
|
335
|
+
return value;
|
|
336
|
+
})
|
|
337
|
+
.join(',');
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Returns a string representation of the cron field values.
|
|
341
|
+
* @param {boolean} includeSeconds - Whether to include seconds in the output
|
|
342
|
+
* @returns {string} The formatted cron string
|
|
343
|
+
*/
|
|
344
|
+
stringify(includeSeconds = false) {
|
|
345
|
+
const arr = [];
|
|
346
|
+
if (includeSeconds) {
|
|
347
|
+
arr.push(this.stringifyField(this.#second)); // second
|
|
348
|
+
}
|
|
349
|
+
arr.push(this.stringifyField(this.#minute), // minute
|
|
350
|
+
this.stringifyField(this.#hour), // hour
|
|
351
|
+
this.stringifyField(this.#dayOfMonth), // dayOfMonth
|
|
352
|
+
this.stringifyField(this.#month), // month
|
|
353
|
+
this.stringifyField(this.#dayOfWeek));
|
|
354
|
+
return arr.join(' ');
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Returns a serialized representation of the cron fields values.
|
|
358
|
+
* @returns {SerializedCronFields} An object containing the cron field values
|
|
359
|
+
*/
|
|
360
|
+
serialize() {
|
|
361
|
+
return {
|
|
362
|
+
second: this.#second.serialize(),
|
|
363
|
+
minute: this.#minute.serialize(),
|
|
364
|
+
hour: this.#hour.serialize(),
|
|
365
|
+
dayOfMonth: this.#dayOfMonth.serialize(),
|
|
366
|
+
month: this.#month.serialize(),
|
|
367
|
+
dayOfWeek: this.#dayOfWeek.serialize(),
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
exports.CronFieldCollection = CronFieldCollection;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.CronFileParser = void 0;
|
|
37
|
+
const CronExpressionParser_1 = require("./CronExpressionParser");
|
|
38
|
+
/**
|
|
39
|
+
* Parser for crontab files that handles both synchronous and asynchronous operations.
|
|
40
|
+
*/
|
|
41
|
+
class CronFileParser {
|
|
42
|
+
/**
|
|
43
|
+
* Parse a crontab file asynchronously
|
|
44
|
+
* @param filePath Path to crontab file
|
|
45
|
+
* @returns Promise resolving to parse results
|
|
46
|
+
* @throws If file cannot be read
|
|
47
|
+
*/
|
|
48
|
+
static async parseFile(filePath) {
|
|
49
|
+
const { readFile } = await Promise.resolve().then(() => __importStar(require('fs/promises')));
|
|
50
|
+
const data = await readFile(filePath, 'utf8');
|
|
51
|
+
return CronFileParser.#parseContent(data);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Parse a crontab file synchronously
|
|
55
|
+
* @param filePath Path to crontab file
|
|
56
|
+
* @returns Parse results
|
|
57
|
+
* @throws If file cannot be read
|
|
58
|
+
*/
|
|
59
|
+
static parseFileSync(filePath) {
|
|
60
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
61
|
+
const { readFileSync } = require('fs');
|
|
62
|
+
const data = readFileSync(filePath, 'utf8');
|
|
63
|
+
return CronFileParser.#parseContent(data);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Internal method to parse crontab file content
|
|
67
|
+
* @private
|
|
68
|
+
*/
|
|
69
|
+
static #parseContent(data) {
|
|
70
|
+
const blocks = data.split('\n');
|
|
71
|
+
const result = {
|
|
72
|
+
variables: {},
|
|
73
|
+
expressions: [],
|
|
74
|
+
errors: {},
|
|
75
|
+
};
|
|
76
|
+
for (const block of blocks) {
|
|
77
|
+
const entry = block.trim();
|
|
78
|
+
if (entry.length === 0 || entry.startsWith('#')) {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
const variableMatch = entry.match(/^(.*)=(.*)$/);
|
|
82
|
+
if (variableMatch) {
|
|
83
|
+
const [, key, value] = variableMatch;
|
|
84
|
+
result.variables[key] = value.replace(/["']/g, ''); // Remove quotes
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
try {
|
|
88
|
+
const parsedEntry = CronFileParser.#parseEntry(entry);
|
|
89
|
+
result.expressions.push(parsedEntry.interval);
|
|
90
|
+
}
|
|
91
|
+
catch (err) {
|
|
92
|
+
result.errors[entry] = err;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return result;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Parse a single crontab entry
|
|
99
|
+
* @private
|
|
100
|
+
*/
|
|
101
|
+
static #parseEntry(entry) {
|
|
102
|
+
const atoms = entry.split(' ');
|
|
103
|
+
return {
|
|
104
|
+
interval: CronExpressionParser_1.CronExpressionParser.parse(atoms.slice(0, 5).join(' ')),
|
|
105
|
+
command: atoms.slice(5, atoms.length),
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
exports.CronFileParser = CronFileParser;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CronDayOfMonth = void 0;
|
|
4
|
+
const CronField_1 = require("./CronField");
|
|
5
|
+
const MIN_DAY = 1;
|
|
6
|
+
const MAX_DAY = 31;
|
|
7
|
+
const DAY_CHARS = Object.freeze(['L']);
|
|
8
|
+
/**
|
|
9
|
+
* Represents the "day of the month" field within a cron expression.
|
|
10
|
+
* @class CronDayOfMonth
|
|
11
|
+
* @extends CronField
|
|
12
|
+
*/
|
|
13
|
+
class CronDayOfMonth extends CronField_1.CronField {
|
|
14
|
+
static get min() {
|
|
15
|
+
return MIN_DAY;
|
|
16
|
+
}
|
|
17
|
+
static get max() {
|
|
18
|
+
return MAX_DAY;
|
|
19
|
+
}
|
|
20
|
+
static get chars() {
|
|
21
|
+
return DAY_CHARS;
|
|
22
|
+
}
|
|
23
|
+
static get validChars() {
|
|
24
|
+
return /^[?,*\dLH/-]+$|^.*H\(\d+-\d+\)\/\d+.*$|^.*H\(\d+-\d+\).*$|^.*H\/\d+.*$/;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* CronDayOfMonth constructor. Initializes the "day of the month" field with the provided values.
|
|
28
|
+
* @param {DayOfMonthRange[]} values - Values for the "day of the month" field
|
|
29
|
+
* @param {CronFieldOptions} [options] - Options provided by the parser
|
|
30
|
+
* @throws {Error} if validation fails
|
|
31
|
+
*/
|
|
32
|
+
constructor(values, options) {
|
|
33
|
+
super(values, options);
|
|
34
|
+
this.validate();
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Returns an array of allowed values for the "day of the month" field.
|
|
38
|
+
* @returns {DayOfMonthRange[]}
|
|
39
|
+
*/
|
|
40
|
+
get values() {
|
|
41
|
+
return super.values;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.CronDayOfMonth = CronDayOfMonth;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CronDayOfWeek = void 0;
|
|
4
|
+
const CronField_1 = require("./CronField");
|
|
5
|
+
const MIN_DAY = 0;
|
|
6
|
+
const MAX_DAY = 7;
|
|
7
|
+
const DAY_CHARS = Object.freeze(['L']);
|
|
8
|
+
/**
|
|
9
|
+
* Represents the "day of the week" field within a cron expression.
|
|
10
|
+
* @class CronDayOfTheWeek
|
|
11
|
+
* @extends CronField
|
|
12
|
+
*/
|
|
13
|
+
class CronDayOfWeek extends CronField_1.CronField {
|
|
14
|
+
static get min() {
|
|
15
|
+
return MIN_DAY;
|
|
16
|
+
}
|
|
17
|
+
static get max() {
|
|
18
|
+
return MAX_DAY;
|
|
19
|
+
}
|
|
20
|
+
static get chars() {
|
|
21
|
+
return DAY_CHARS;
|
|
22
|
+
}
|
|
23
|
+
static get validChars() {
|
|
24
|
+
return /^[?,*\dLH#/-]+$|^.*H\(\d+-\d+\)\/\d+.*$|^.*H\(\d+-\d+\).*$|^.*H\/\d+.*$/;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* CronDayOfTheWeek constructor. Initializes the "day of the week" field with the provided values.
|
|
28
|
+
* @param {DayOfWeekRange[]} values - Values for the "day of the week" field
|
|
29
|
+
* @param {CronFieldOptions} [options] - Options provided by the parser
|
|
30
|
+
*/
|
|
31
|
+
constructor(values, options) {
|
|
32
|
+
super(values, options);
|
|
33
|
+
this.validate();
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Returns an array of allowed values for the "day of the week" field.
|
|
37
|
+
* @returns {DayOfWeekRange[]}
|
|
38
|
+
*/
|
|
39
|
+
get values() {
|
|
40
|
+
return super.values;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Returns the nth day of the week if specified in the cron expression.
|
|
44
|
+
* This is used for the '#' character in the cron expression.
|
|
45
|
+
* @returns {number} The nth day of the week (1-5) or 0 if not specified.
|
|
46
|
+
*/
|
|
47
|
+
get nthDay() {
|
|
48
|
+
return this.options.nthDayOfWeek ?? 0;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.CronDayOfWeek = CronDayOfWeek;
|