@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.
Files changed (52) hide show
  1. package/dist/client/cron-jobs-table/AutoBackupTable.schema.d.ts +3 -2
  2. package/dist/client/index.js +2 -2
  3. package/dist/externalVersion.js +7 -7
  4. package/dist/node_modules/@hapi/topo/package.json +1 -1
  5. package/dist/node_modules/archiver/package.json +1 -1
  6. package/dist/node_modules/cron-parser/LICENSE +1 -1
  7. package/dist/node_modules/cron-parser/dist/CronDate.js +497 -0
  8. package/dist/node_modules/cron-parser/dist/CronExpression.js +376 -0
  9. package/dist/node_modules/cron-parser/dist/CronExpressionParser.js +384 -0
  10. package/dist/node_modules/cron-parser/dist/CronFieldCollection.js +371 -0
  11. package/dist/node_modules/cron-parser/dist/CronFileParser.js +109 -0
  12. package/dist/node_modules/cron-parser/dist/fields/CronDayOfMonth.js +44 -0
  13. package/dist/node_modules/cron-parser/dist/fields/CronDayOfWeek.js +51 -0
  14. package/dist/node_modules/cron-parser/dist/fields/CronField.js +183 -0
  15. package/dist/node_modules/cron-parser/dist/fields/CronHour.js +40 -0
  16. package/dist/node_modules/cron-parser/dist/fields/CronMinute.js +40 -0
  17. package/dist/node_modules/cron-parser/dist/fields/CronMonth.js +44 -0
  18. package/dist/node_modules/cron-parser/dist/fields/CronSecond.js +40 -0
  19. package/dist/node_modules/cron-parser/dist/fields/index.js +24 -0
  20. package/dist/node_modules/cron-parser/dist/fields/types.js +2 -0
  21. package/dist/node_modules/cron-parser/dist/index.js +1 -0
  22. package/dist/node_modules/cron-parser/dist/types/CronDate.d.ts +273 -0
  23. package/dist/node_modules/cron-parser/dist/types/CronExpression.d.ts +110 -0
  24. package/dist/node_modules/cron-parser/dist/types/CronExpressionParser.d.ts +70 -0
  25. package/dist/node_modules/cron-parser/dist/types/CronFieldCollection.d.ts +153 -0
  26. package/dist/node_modules/cron-parser/dist/types/CronFileParser.d.ts +30 -0
  27. package/dist/node_modules/cron-parser/dist/types/fields/CronDayOfMonth.d.ts +25 -0
  28. package/dist/node_modules/cron-parser/dist/types/fields/CronDayOfWeek.d.ts +30 -0
  29. package/dist/node_modules/cron-parser/dist/types/fields/CronField.d.ts +114 -0
  30. package/dist/node_modules/cron-parser/dist/types/fields/CronHour.d.ts +23 -0
  31. package/dist/node_modules/cron-parser/dist/types/fields/CronMinute.d.ts +23 -0
  32. package/dist/node_modules/cron-parser/dist/types/fields/CronMonth.d.ts +24 -0
  33. package/dist/node_modules/cron-parser/dist/types/fields/CronSecond.d.ts +23 -0
  34. package/dist/node_modules/cron-parser/dist/types/fields/index.d.ts +8 -0
  35. package/dist/node_modules/cron-parser/dist/types/fields/types.d.ts +18 -0
  36. package/dist/node_modules/cron-parser/dist/types/index.d.ts +8 -0
  37. package/dist/node_modules/cron-parser/dist/types/utils/random.d.ts +10 -0
  38. package/dist/node_modules/cron-parser/dist/utils/random.js +38 -0
  39. package/dist/node_modules/cron-parser/package.json +1 -1
  40. package/dist/node_modules/mkdirp/package.json +1 -1
  41. package/dist/node_modules/semver/package.json +1 -1
  42. package/dist/node_modules/yauzl/package.json +1 -1
  43. package/dist/server/server.d.ts +1 -1
  44. package/package.json +11 -12
  45. package/dist/node_modules/cron-parser/lib/date.js +0 -252
  46. package/dist/node_modules/cron-parser/lib/expression.js +0 -1002
  47. package/dist/node_modules/cron-parser/lib/field_compactor.js +0 -70
  48. package/dist/node_modules/cron-parser/lib/field_stringify.js +0 -58
  49. package/dist/node_modules/cron-parser/lib/parser.js +0 -1
  50. package/dist/node_modules/cron-parser/types/common.d.ts +0 -131
  51. package/dist/node_modules/cron-parser/types/index.d.ts +0 -45
  52. package/dist/node_modules/cron-parser/types/ts3/index.d.ts +0 -28
@@ -0,0 +1,384 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CronExpressionParser = exports.DayOfWeek = exports.Months = exports.CronUnit = exports.PredefinedExpressions = void 0;
4
+ const CronFieldCollection_1 = require("./CronFieldCollection");
5
+ const CronDate_1 = require("./CronDate");
6
+ const CronExpression_1 = require("./CronExpression");
7
+ const random_1 = require("./utils/random");
8
+ const fields_1 = require("./fields");
9
+ var PredefinedExpressions;
10
+ (function (PredefinedExpressions) {
11
+ PredefinedExpressions["@yearly"] = "0 0 0 1 1 *";
12
+ PredefinedExpressions["@annually"] = "0 0 0 1 1 *";
13
+ PredefinedExpressions["@monthly"] = "0 0 0 1 * *";
14
+ PredefinedExpressions["@weekly"] = "0 0 0 * * 0";
15
+ PredefinedExpressions["@daily"] = "0 0 0 * * *";
16
+ PredefinedExpressions["@hourly"] = "0 0 * * * *";
17
+ PredefinedExpressions["@minutely"] = "0 * * * * *";
18
+ PredefinedExpressions["@secondly"] = "* * * * * *";
19
+ PredefinedExpressions["@weekdays"] = "0 0 0 * * 1-5";
20
+ PredefinedExpressions["@weekends"] = "0 0 0 * * 0,6";
21
+ })(PredefinedExpressions || (exports.PredefinedExpressions = PredefinedExpressions = {}));
22
+ var CronUnit;
23
+ (function (CronUnit) {
24
+ CronUnit["Second"] = "Second";
25
+ CronUnit["Minute"] = "Minute";
26
+ CronUnit["Hour"] = "Hour";
27
+ CronUnit["DayOfMonth"] = "DayOfMonth";
28
+ CronUnit["Month"] = "Month";
29
+ CronUnit["DayOfWeek"] = "DayOfWeek";
30
+ })(CronUnit || (exports.CronUnit = CronUnit = {}));
31
+ // these need to be lowercase for the parser to work
32
+ var Months;
33
+ (function (Months) {
34
+ Months[Months["jan"] = 1] = "jan";
35
+ Months[Months["feb"] = 2] = "feb";
36
+ Months[Months["mar"] = 3] = "mar";
37
+ Months[Months["apr"] = 4] = "apr";
38
+ Months[Months["may"] = 5] = "may";
39
+ Months[Months["jun"] = 6] = "jun";
40
+ Months[Months["jul"] = 7] = "jul";
41
+ Months[Months["aug"] = 8] = "aug";
42
+ Months[Months["sep"] = 9] = "sep";
43
+ Months[Months["oct"] = 10] = "oct";
44
+ Months[Months["nov"] = 11] = "nov";
45
+ Months[Months["dec"] = 12] = "dec";
46
+ })(Months || (exports.Months = Months = {}));
47
+ // these need to be lowercase for the parser to work
48
+ var DayOfWeek;
49
+ (function (DayOfWeek) {
50
+ DayOfWeek[DayOfWeek["sun"] = 0] = "sun";
51
+ DayOfWeek[DayOfWeek["mon"] = 1] = "mon";
52
+ DayOfWeek[DayOfWeek["tue"] = 2] = "tue";
53
+ DayOfWeek[DayOfWeek["wed"] = 3] = "wed";
54
+ DayOfWeek[DayOfWeek["thu"] = 4] = "thu";
55
+ DayOfWeek[DayOfWeek["fri"] = 5] = "fri";
56
+ DayOfWeek[DayOfWeek["sat"] = 6] = "sat";
57
+ })(DayOfWeek || (exports.DayOfWeek = DayOfWeek = {}));
58
+ /**
59
+ * Static class that parses a cron expression and returns a CronExpression object.
60
+ * @static
61
+ * @class CronExpressionParser
62
+ */
63
+ class CronExpressionParser {
64
+ /**
65
+ * Parses a cron expression and returns a CronExpression object.
66
+ * @param {string} expression - The cron expression to parse.
67
+ * @param {CronExpressionOptions} [options={}] - The options to use when parsing the expression.
68
+ * @param {boolean} [options.strict=false] - If true, will throw an error if the expression contains both dayOfMonth and dayOfWeek.
69
+ * @param {CronDate} [options.currentDate=new CronDate(undefined, 'UTC')] - The date to use when calculating the next/previous occurrence.
70
+ *
71
+ * @returns {CronExpression} A CronExpression object.
72
+ */
73
+ static parse(expression, options = {}) {
74
+ const { strict = false } = options;
75
+ const currentDate = options.currentDate || new CronDate_1.CronDate();
76
+ const rand = (0, random_1.seededRandom)(options.hashSeed);
77
+ expression = PredefinedExpressions[expression] || expression;
78
+ const rawFields = CronExpressionParser.#getRawFields(expression, strict);
79
+ if (!(rawFields.dayOfMonth === '*' || rawFields.dayOfWeek === '*' || !strict)) {
80
+ throw new Error('Cannot use both dayOfMonth and dayOfWeek together in strict mode!');
81
+ }
82
+ const second = CronExpressionParser.#parseField(CronUnit.Second, rawFields.second, fields_1.CronSecond.constraints, rand);
83
+ const minute = CronExpressionParser.#parseField(CronUnit.Minute, rawFields.minute, fields_1.CronMinute.constraints, rand);
84
+ const hour = CronExpressionParser.#parseField(CronUnit.Hour, rawFields.hour, fields_1.CronHour.constraints, rand);
85
+ const month = CronExpressionParser.#parseField(CronUnit.Month, rawFields.month, fields_1.CronMonth.constraints, rand);
86
+ const dayOfMonth = CronExpressionParser.#parseField(CronUnit.DayOfMonth, rawFields.dayOfMonth, fields_1.CronDayOfMonth.constraints, rand);
87
+ const { dayOfWeek: _dayOfWeek, nthDayOfWeek } = CronExpressionParser.#parseNthDay(rawFields.dayOfWeek);
88
+ const dayOfWeek = CronExpressionParser.#parseField(CronUnit.DayOfWeek, _dayOfWeek, fields_1.CronDayOfWeek.constraints, rand);
89
+ const fields = new CronFieldCollection_1.CronFieldCollection({
90
+ second: new fields_1.CronSecond(second, { rawValue: rawFields.second }),
91
+ minute: new fields_1.CronMinute(minute, { rawValue: rawFields.minute }),
92
+ hour: new fields_1.CronHour(hour, { rawValue: rawFields.hour }),
93
+ dayOfMonth: new fields_1.CronDayOfMonth(dayOfMonth, { rawValue: rawFields.dayOfMonth }),
94
+ month: new fields_1.CronMonth(month, { rawValue: rawFields.month }),
95
+ dayOfWeek: new fields_1.CronDayOfWeek(dayOfWeek, { rawValue: rawFields.dayOfWeek, nthDayOfWeek }),
96
+ });
97
+ return new CronExpression_1.CronExpression(fields, { ...options, expression, currentDate });
98
+ }
99
+ /**
100
+ * Get the raw fields from a cron expression.
101
+ * @param {string} expression - The cron expression to parse.
102
+ * @param {boolean} strict - If true, will throw an error if the expression contains both dayOfMonth and dayOfWeek.
103
+ * @private
104
+ * @returns {RawCronFields} The raw fields.
105
+ */
106
+ static #getRawFields(expression, strict) {
107
+ if (strict && !expression.length) {
108
+ throw new Error('Invalid cron expression');
109
+ }
110
+ expression = expression || '0 * * * * *';
111
+ const atoms = expression.trim().split(/\s+/);
112
+ if (strict && atoms.length < 6) {
113
+ throw new Error('Invalid cron expression, expected 6 fields');
114
+ }
115
+ if (atoms.length > 6) {
116
+ throw new Error('Invalid cron expression, too many fields');
117
+ }
118
+ const defaults = ['*', '*', '*', '*', '*', '0'];
119
+ if (atoms.length < defaults.length) {
120
+ atoms.unshift(...defaults.slice(atoms.length));
121
+ }
122
+ const [second, minute, hour, dayOfMonth, month, dayOfWeek] = atoms;
123
+ return { second, minute, hour, dayOfMonth, month, dayOfWeek };
124
+ }
125
+ /**
126
+ * Parse a field from a cron expression.
127
+ * @param {CronUnit} field - The field to parse.
128
+ * @param {string} value - The value of the field.
129
+ * @param {CronConstraints} constraints - The constraints for the field.
130
+ * @private
131
+ * @returns {(number | string)[]} The parsed field.
132
+ */
133
+ static #parseField(field, value, constraints, rand) {
134
+ // Replace aliases for month and dayOfWeek
135
+ if (field === CronUnit.Month || field === CronUnit.DayOfWeek) {
136
+ value = value.replace(/[a-z]{3}/gi, (match) => {
137
+ match = match.toLowerCase();
138
+ const replacer = Months[match] || DayOfWeek[match];
139
+ if (replacer === undefined) {
140
+ throw new Error(`Validation error, cannot resolve alias "${match}"`);
141
+ }
142
+ return replacer.toString();
143
+ });
144
+ }
145
+ // Check for valid characters
146
+ if (!constraints.validChars.test(value)) {
147
+ throw new Error(`Invalid characters, got value: ${value}`);
148
+ }
149
+ value = this.#parseWildcard(value, constraints);
150
+ value = this.#parseHashed(value, constraints, rand);
151
+ return this.#parseSequence(field, value, constraints);
152
+ }
153
+ /**
154
+ * Parse a wildcard from a cron expression.
155
+ * @param {string} value - The value to parse.
156
+ * @param {CronConstraints} constraints - The constraints for the field.
157
+ * @private
158
+ */
159
+ static #parseWildcard(value, constraints) {
160
+ return value.replace(/[*?]/g, constraints.min + '-' + constraints.max);
161
+ }
162
+ /**
163
+ * Parse a hashed value from a cron expression.
164
+ * @param {string} value - The value to parse.
165
+ * @param {CronConstraints} constraints - The constraints for the field.
166
+ * @param {PRNG} rand - The random number generator to use.
167
+ * @private
168
+ */
169
+ static #parseHashed(value, constraints, rand) {
170
+ const randomValue = rand();
171
+ return value.replace(/H(?:\((\d+)-(\d+)\))?(?:\/(\d+))?/g, (_, min, max, step) => {
172
+ // H(range)/step
173
+ if (min && max && step) {
174
+ const minNum = parseInt(min, 10);
175
+ const maxNum = parseInt(max, 10);
176
+ const stepNum = parseInt(step, 10);
177
+ if (minNum > maxNum) {
178
+ throw new Error(`Invalid range: ${minNum}-${maxNum}, min > max`);
179
+ }
180
+ if (stepNum <= 0) {
181
+ throw new Error(`Invalid step: ${stepNum}, must be positive`);
182
+ }
183
+ const minStart = Math.max(minNum, constraints.min);
184
+ const offset = Math.floor(randomValue * stepNum);
185
+ const values = [];
186
+ for (let i = Math.floor(minStart / stepNum) * stepNum + offset; i <= maxNum; i += stepNum) {
187
+ if (i >= minStart) {
188
+ values.push(i);
189
+ }
190
+ }
191
+ return values.join(',');
192
+ }
193
+ // H(range)
194
+ else if (min && max) {
195
+ const minNum = parseInt(min, 10);
196
+ const maxNum = parseInt(max, 10);
197
+ if (minNum > maxNum) {
198
+ throw new Error(`Invalid range: ${minNum}-${maxNum}, min > max`);
199
+ }
200
+ return String(Math.floor(randomValue * (maxNum - minNum + 1)) + minNum);
201
+ }
202
+ // H/step
203
+ else if (step) {
204
+ const stepNum = parseInt(step, 10);
205
+ // Validate step
206
+ if (stepNum <= 0) {
207
+ throw new Error(`Invalid step: ${stepNum}, must be positive`);
208
+ }
209
+ const offset = Math.floor(randomValue * stepNum);
210
+ const values = [];
211
+ for (let i = Math.floor(constraints.min / stepNum) * stepNum + offset; i <= constraints.max; i += stepNum) {
212
+ if (i >= constraints.min) {
213
+ values.push(i);
214
+ }
215
+ }
216
+ return values.join(',');
217
+ }
218
+ // H
219
+ else {
220
+ return String(Math.floor(randomValue * (constraints.max - constraints.min + 1) + constraints.min));
221
+ }
222
+ });
223
+ }
224
+ /**
225
+ * Parse a sequence from a cron expression.
226
+ * @param {CronUnit} field - The field to parse.
227
+ * @param {string} val - The sequence to parse.
228
+ * @param {CronConstraints} constraints - The constraints for the field.
229
+ * @private
230
+ */
231
+ static #parseSequence(field, val, constraints) {
232
+ const stack = [];
233
+ function handleResult(result, constraints) {
234
+ if (Array.isArray(result)) {
235
+ stack.push(...result);
236
+ }
237
+ else {
238
+ if (CronExpressionParser.#isValidConstraintChar(constraints, result)) {
239
+ stack.push(result);
240
+ }
241
+ else {
242
+ const v = parseInt(result.toString(), 10);
243
+ const isValid = v >= constraints.min && v <= constraints.max;
244
+ if (!isValid) {
245
+ throw new Error(`Constraint error, got value ${result} expected range ${constraints.min}-${constraints.max}`);
246
+ }
247
+ stack.push(field === CronUnit.DayOfWeek ? v % 7 : result);
248
+ }
249
+ }
250
+ }
251
+ const atoms = val.split(',');
252
+ atoms.forEach((atom) => {
253
+ if (!(atom.length > 0)) {
254
+ throw new Error('Invalid list value format');
255
+ }
256
+ handleResult(CronExpressionParser.#parseRepeat(field, atom, constraints), constraints);
257
+ });
258
+ return stack;
259
+ }
260
+ /**
261
+ * Parse repeat from a cron expression.
262
+ * @param {CronUnit} field - The field to parse.
263
+ * @param {string} val - The repeat to parse.
264
+ * @param {CronConstraints} constraints - The constraints for the field.
265
+ * @private
266
+ * @returns {(number | string)[]} The parsed repeat.
267
+ */
268
+ static #parseRepeat(field, val, constraints) {
269
+ const atoms = val.split('/');
270
+ if (atoms.length > 2) {
271
+ throw new Error(`Invalid repeat: ${val}`);
272
+ }
273
+ if (atoms.length === 2) {
274
+ if (!isNaN(parseInt(atoms[0], 10))) {
275
+ atoms[0] = `${atoms[0]}-${constraints.max}`;
276
+ }
277
+ return CronExpressionParser.#parseRange(field, atoms[0], parseInt(atoms[1], 10), constraints);
278
+ }
279
+ return CronExpressionParser.#parseRange(field, val, 1, constraints);
280
+ }
281
+ /**
282
+ * Validate a cron range.
283
+ * @param {number} min - The minimum value of the range.
284
+ * @param {number} max - The maximum value of the range.
285
+ * @param {CronConstraints} constraints - The constraints for the field.
286
+ * @private
287
+ * @returns {void}
288
+ * @throws {Error} Throws an error if the range is invalid.
289
+ */
290
+ static #validateRange(min, max, constraints) {
291
+ const isValid = !isNaN(min) && !isNaN(max) && min >= constraints.min && max <= constraints.max;
292
+ if (!isValid) {
293
+ throw new Error(`Constraint error, got range ${min}-${max} expected range ${constraints.min}-${constraints.max}`);
294
+ }
295
+ if (min > max) {
296
+ throw new Error(`Invalid range: ${min}-${max}, min(${min}) > max(${max})`);
297
+ }
298
+ }
299
+ /**
300
+ * Validate a cron repeat interval.
301
+ * @param {number} repeatInterval - The repeat interval to validate.
302
+ * @private
303
+ * @returns {void}
304
+ * @throws {Error} Throws an error if the repeat interval is invalid.
305
+ */
306
+ static #validateRepeatInterval(repeatInterval) {
307
+ if (!(!isNaN(repeatInterval) && repeatInterval > 0)) {
308
+ throw new Error(`Constraint error, cannot repeat at every ${repeatInterval} time.`);
309
+ }
310
+ }
311
+ /**
312
+ * Create a range from a cron expression.
313
+ * @param {CronUnit} field - The field to parse.
314
+ * @param {number} min - The minimum value of the range.
315
+ * @param {number} max - The maximum value of the range.
316
+ * @param {number} repeatInterval - The repeat interval of the range.
317
+ * @private
318
+ * @returns {number[]} The created range.
319
+ */
320
+ static #createRange(field, min, max, repeatInterval) {
321
+ const stack = [];
322
+ if (field === CronUnit.DayOfWeek && max % 7 === 0) {
323
+ stack.push(0);
324
+ }
325
+ for (let index = min; index <= max; index += repeatInterval) {
326
+ if (stack.indexOf(index) === -1) {
327
+ stack.push(index);
328
+ }
329
+ }
330
+ return stack;
331
+ }
332
+ /**
333
+ * Parse a range from a cron expression.
334
+ * @param {CronUnit} field - The field to parse.
335
+ * @param {string} val - The range to parse.
336
+ * @param {number} repeatInterval - The repeat interval of the range.
337
+ * @param {CronConstraints} constraints - The constraints for the field.
338
+ * @private
339
+ * @returns {number[] | string[] | number | string} The parsed range.
340
+ */
341
+ static #parseRange(field, val, repeatInterval, constraints) {
342
+ const atoms = val.split('-');
343
+ if (atoms.length <= 1) {
344
+ return isNaN(+val) ? val : +val;
345
+ }
346
+ const [min, max] = atoms.map((num) => parseInt(num, 10));
347
+ this.#validateRange(min, max, constraints);
348
+ this.#validateRepeatInterval(repeatInterval);
349
+ // Create range
350
+ return this.#createRange(field, min, max, repeatInterval);
351
+ }
352
+ /**
353
+ * Parse a cron expression.
354
+ * @param {string} val - The cron expression to parse.
355
+ * @private
356
+ * @returns {string} The parsed cron expression.
357
+ */
358
+ static #parseNthDay(val) {
359
+ const atoms = val.split('#');
360
+ if (atoms.length <= 1) {
361
+ return { dayOfWeek: atoms[0] };
362
+ }
363
+ const nthValue = +atoms[atoms.length - 1];
364
+ const matches = val.match(/([,-/])/);
365
+ if (matches !== null) {
366
+ throw new Error(`Constraint error, invalid dayOfWeek \`#\` and \`${matches?.[0]}\` special characters are incompatible`);
367
+ }
368
+ if (!(atoms.length <= 2 && !isNaN(nthValue) && nthValue >= 1 && nthValue <= 5)) {
369
+ throw new Error('Constraint error, invalid dayOfWeek occurrence number (#)');
370
+ }
371
+ return { dayOfWeek: atoms[0], nthDayOfWeek: nthValue };
372
+ }
373
+ /**
374
+ * Checks if a character is valid for a field.
375
+ * @param {CronConstraints} constraints - The constraints for the field.
376
+ * @param {string | number} value - The value to check.
377
+ * @private
378
+ * @returns {boolean} Whether the character is valid for the field.
379
+ */
380
+ static #isValidConstraintChar(constraints, value) {
381
+ return constraints.chars.some((char) => value.toString().includes(char));
382
+ }
383
+ }
384
+ exports.CronExpressionParser = CronExpressionParser;