@teammy/server 0.2.20 → 0.2.22
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/main.js +8784 -7601
- package/dist/web/assets/Assistant-Dm68Y4gs.js +1 -0
- package/dist/web/assets/Computers-BtcIsnDD.css +1 -0
- package/dist/web/assets/Computers-mf4P8Wjw.js +13 -0
- package/dist/web/assets/{Conversation-BjRCD81A.js → Conversation-ClLZZ3fG.js} +1 -1
- package/dist/web/assets/{Dashboard-DmtWx-WI.js → Dashboard-pokwbwJV.js} +1 -1
- package/dist/web/assets/{Dropdown-DXEtBxVr.js → Dropdown-DGFI68Vd.js} +1 -1
- package/dist/web/assets/Files-CtxaCO6n.js +1 -0
- package/dist/web/assets/{Help-BeJ09zt7.js → Help-B_1p7Xir.js} +87 -25
- package/dist/web/assets/Markdown-gPLWRWEJ.js +29 -0
- package/dist/web/assets/{MessageComposer-0eprbRl2.js → MessageComposer-BoOgfyPA.js} +1 -1
- package/dist/web/assets/ResourceLibrary-Cr_Emgq2.js +6 -0
- package/dist/web/assets/{TerminalPane-CEaXud0k.js → TerminalPane-5Gw9ZNxq.js} +2 -2
- package/dist/web/assets/WorkspaceTree-DZ6DN_OX.js +1 -0
- package/dist/web/assets/{file-links-Bo7XBz3i.js → file-links-CoVqmrXg.js} +1 -1
- package/dist/web/assets/index-BZEKT27U.js +10 -0
- package/dist/web/assets/task-links-DTqf18C2.js +1 -0
- package/dist/web/downloads/teammy-inbox-skill.zip +0 -0
- package/dist/web/downloads/teammy-skill.zip +0 -0
- package/dist/web/index.html +2 -2
- package/dist/web/notification-worker.js +126 -0
- package/node_modules/cron-parser/LICENSE +21 -0
- package/node_modules/cron-parser/README.md +437 -0
- package/node_modules/cron-parser/dist/CronDate.js +558 -0
- package/node_modules/cron-parser/dist/CronExpression.js +531 -0
- package/node_modules/cron-parser/dist/CronExpressionParser.js +482 -0
- package/node_modules/cron-parser/dist/CronFieldCollection.js +380 -0
- package/node_modules/cron-parser/dist/CronFileParser.js +92 -0
- package/node_modules/cron-parser/dist/fields/CronDayOfMonth.js +60 -0
- package/node_modules/cron-parser/dist/fields/CronDayOfWeek.js +57 -0
- package/node_modules/cron-parser/dist/fields/CronField.js +222 -0
- package/node_modules/cron-parser/dist/fields/CronHour.js +40 -0
- package/node_modules/cron-parser/dist/fields/CronMinute.js +40 -0
- package/node_modules/cron-parser/dist/fields/CronMonth.js +44 -0
- package/node_modules/cron-parser/dist/fields/CronSecond.js +40 -0
- package/node_modules/cron-parser/dist/fields/index.js +24 -0
- package/node_modules/cron-parser/dist/fields/types.js +2 -0
- package/node_modules/cron-parser/dist/index.js +31 -0
- package/node_modules/cron-parser/dist/types/CronDate.d.ts +293 -0
- package/node_modules/cron-parser/dist/types/CronExpression.d.ts +118 -0
- package/node_modules/cron-parser/dist/types/CronExpressionParser.d.ts +65 -0
- package/node_modules/cron-parser/dist/types/CronFieldCollection.d.ts +153 -0
- package/node_modules/cron-parser/dist/types/CronFileParser.d.ts +30 -0
- package/node_modules/cron-parser/dist/types/fields/CronDayOfMonth.d.ts +33 -0
- package/node_modules/cron-parser/dist/types/fields/CronDayOfWeek.d.ts +31 -0
- package/node_modules/cron-parser/dist/types/fields/CronField.d.ts +136 -0
- package/node_modules/cron-parser/dist/types/fields/CronHour.d.ts +23 -0
- package/node_modules/cron-parser/dist/types/fields/CronMinute.d.ts +23 -0
- package/node_modules/cron-parser/dist/types/fields/CronMonth.d.ts +24 -0
- package/node_modules/cron-parser/dist/types/fields/CronSecond.d.ts +23 -0
- package/node_modules/cron-parser/dist/types/fields/index.d.ts +8 -0
- package/node_modules/cron-parser/dist/types/fields/types.d.ts +18 -0
- package/node_modules/cron-parser/dist/types/index.d.ts +8 -0
- package/node_modules/cron-parser/dist/types/utils/random.d.ts +10 -0
- package/node_modules/cron-parser/dist/utils/random.js +38 -0
- package/node_modules/cron-parser/package.json +117 -0
- package/node_modules/luxon/LICENSE.md +7 -0
- package/node_modules/luxon/README.md +55 -0
- package/node_modules/luxon/build/amd/luxon.js +8741 -0
- package/node_modules/luxon/build/amd/luxon.js.map +1 -0
- package/node_modules/luxon/build/cjs-browser/luxon.js +8739 -0
- package/node_modules/luxon/build/cjs-browser/luxon.js.map +1 -0
- package/node_modules/luxon/build/es6/luxon.mjs +8133 -0
- package/node_modules/luxon/build/es6/luxon.mjs.map +1 -0
- package/node_modules/luxon/build/global/luxon.js +8744 -0
- package/node_modules/luxon/build/global/luxon.js.map +1 -0
- package/node_modules/luxon/build/global/luxon.min.js +1 -0
- package/node_modules/luxon/build/global/luxon.min.js.map +1 -0
- package/node_modules/luxon/build/node/luxon.js +7792 -0
- package/node_modules/luxon/build/node/luxon.js.map +1 -0
- package/node_modules/luxon/package.json +87 -0
- package/node_modules/luxon/src/datetime.js +2603 -0
- package/node_modules/luxon/src/duration.js +1009 -0
- package/node_modules/luxon/src/errors.js +61 -0
- package/node_modules/luxon/src/impl/conversions.js +206 -0
- package/node_modules/luxon/src/impl/diff.js +95 -0
- package/node_modules/luxon/src/impl/digits.js +94 -0
- package/node_modules/luxon/src/impl/english.js +233 -0
- package/node_modules/luxon/src/impl/formats.js +176 -0
- package/node_modules/luxon/src/impl/formatter.js +434 -0
- package/node_modules/luxon/src/impl/invalid.js +14 -0
- package/node_modules/luxon/src/impl/locale.js +569 -0
- package/node_modules/luxon/src/impl/regexParser.js +335 -0
- package/node_modules/luxon/src/impl/tokenParser.js +505 -0
- package/node_modules/luxon/src/impl/util.js +330 -0
- package/node_modules/luxon/src/impl/zoneUtil.js +34 -0
- package/node_modules/luxon/src/info.js +205 -0
- package/node_modules/luxon/src/interval.js +669 -0
- package/node_modules/luxon/src/luxon.js +26 -0
- package/node_modules/luxon/src/package.json +4 -0
- package/node_modules/luxon/src/settings.js +180 -0
- package/node_modules/luxon/src/zone.js +97 -0
- package/node_modules/luxon/src/zones/IANAZone.js +235 -0
- package/node_modules/luxon/src/zones/fixedOffsetZone.js +150 -0
- package/node_modules/luxon/src/zones/invalidZone.js +53 -0
- package/node_modules/luxon/src/zones/systemZone.js +61 -0
- package/package.json +3 -1
- package/dist/web/assets/Assistant-By7rPMl2.js +0 -1
- package/dist/web/assets/Computers-B4ZMJ8tu.js +0 -13
- package/dist/web/assets/Computers-CBnQX-2p.css +0 -1
- package/dist/web/assets/Files-4IxSFpqk.js +0 -1
- package/dist/web/assets/Markdown-DGF8VSqv.js +0 -29
- package/dist/web/assets/ResourceLibrary-rlrdDWGo.js +0 -6
- package/dist/web/assets/WorkspaceTree-CwGvdfr0.js +0 -1
- package/dist/web/assets/index-Cr9kdjwc.js +0 -10
- package/dist/web/assets/task-links-B7fExlHK.js +0 -1
|
@@ -0,0 +1,482 @@
|
|
|
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 CronExpression_1 = require("./CronExpression");
|
|
6
|
+
const random_1 = require("./utils/random");
|
|
7
|
+
const fields_1 = require("./fields");
|
|
8
|
+
var PredefinedExpressions;
|
|
9
|
+
(function (PredefinedExpressions) {
|
|
10
|
+
PredefinedExpressions["@yearly"] = "0 0 0 1 1 *";
|
|
11
|
+
PredefinedExpressions["@annually"] = "0 0 0 1 1 *";
|
|
12
|
+
PredefinedExpressions["@monthly"] = "0 0 0 1 * *";
|
|
13
|
+
PredefinedExpressions["@weekly"] = "0 0 0 * * 0";
|
|
14
|
+
PredefinedExpressions["@daily"] = "0 0 0 * * *";
|
|
15
|
+
PredefinedExpressions["@hourly"] = "0 0 * * * *";
|
|
16
|
+
PredefinedExpressions["@minutely"] = "0 * * * * *";
|
|
17
|
+
PredefinedExpressions["@secondly"] = "* * * * * *";
|
|
18
|
+
PredefinedExpressions["@weekdays"] = "0 0 0 * * 1-5";
|
|
19
|
+
PredefinedExpressions["@weekends"] = "0 0 0 * * 0,6";
|
|
20
|
+
})(PredefinedExpressions || (exports.PredefinedExpressions = PredefinedExpressions = {}));
|
|
21
|
+
var CronUnit;
|
|
22
|
+
(function (CronUnit) {
|
|
23
|
+
CronUnit["Second"] = "Second";
|
|
24
|
+
CronUnit["Minute"] = "Minute";
|
|
25
|
+
CronUnit["Hour"] = "Hour";
|
|
26
|
+
CronUnit["DayOfMonth"] = "DayOfMonth";
|
|
27
|
+
CronUnit["Month"] = "Month";
|
|
28
|
+
CronUnit["DayOfWeek"] = "DayOfWeek";
|
|
29
|
+
})(CronUnit || (exports.CronUnit = CronUnit = {}));
|
|
30
|
+
// these need to be lowercase for the parser to work
|
|
31
|
+
var Months;
|
|
32
|
+
(function (Months) {
|
|
33
|
+
Months[Months["jan"] = 1] = "jan";
|
|
34
|
+
Months[Months["feb"] = 2] = "feb";
|
|
35
|
+
Months[Months["mar"] = 3] = "mar";
|
|
36
|
+
Months[Months["apr"] = 4] = "apr";
|
|
37
|
+
Months[Months["may"] = 5] = "may";
|
|
38
|
+
Months[Months["jun"] = 6] = "jun";
|
|
39
|
+
Months[Months["jul"] = 7] = "jul";
|
|
40
|
+
Months[Months["aug"] = 8] = "aug";
|
|
41
|
+
Months[Months["sep"] = 9] = "sep";
|
|
42
|
+
Months[Months["oct"] = 10] = "oct";
|
|
43
|
+
Months[Months["nov"] = 11] = "nov";
|
|
44
|
+
Months[Months["dec"] = 12] = "dec";
|
|
45
|
+
})(Months || (exports.Months = Months = {}));
|
|
46
|
+
// these need to be lowercase for the parser to work
|
|
47
|
+
var DayOfWeek;
|
|
48
|
+
(function (DayOfWeek) {
|
|
49
|
+
DayOfWeek[DayOfWeek["sun"] = 0] = "sun";
|
|
50
|
+
DayOfWeek[DayOfWeek["mon"] = 1] = "mon";
|
|
51
|
+
DayOfWeek[DayOfWeek["tue"] = 2] = "tue";
|
|
52
|
+
DayOfWeek[DayOfWeek["wed"] = 3] = "wed";
|
|
53
|
+
DayOfWeek[DayOfWeek["thu"] = 4] = "thu";
|
|
54
|
+
DayOfWeek[DayOfWeek["fri"] = 5] = "fri";
|
|
55
|
+
DayOfWeek[DayOfWeek["sat"] = 6] = "sat";
|
|
56
|
+
})(DayOfWeek || (exports.DayOfWeek = DayOfWeek = {}));
|
|
57
|
+
/**
|
|
58
|
+
* Static class that parses a cron expression and returns a CronExpression object.
|
|
59
|
+
* @static
|
|
60
|
+
* @class CronExpressionParser
|
|
61
|
+
*/
|
|
62
|
+
/**
|
|
63
|
+
* Upper bound on the number of values a single field may expand to.
|
|
64
|
+
* No field can hold this many distinct values, so exceeding it always means the list repeats values.
|
|
65
|
+
*/
|
|
66
|
+
const MAX_FIELD_VALUES = 256;
|
|
67
|
+
/**
|
|
68
|
+
* Upper bound on the length of a cron expression.
|
|
69
|
+
* Listing every value of every field needs about half of this, so a longer expression is never meaningful.
|
|
70
|
+
*/
|
|
71
|
+
const MAX_EXPRESSION_LENGTH = 1024;
|
|
72
|
+
class CronExpressionParser {
|
|
73
|
+
/**
|
|
74
|
+
* Parses a cron expression and returns a CronExpression object.
|
|
75
|
+
* @param {string} expression - The cron expression to parse.
|
|
76
|
+
* @param {CronExpressionOptions} [options={}] - The options to use when parsing the expression.
|
|
77
|
+
* @param {boolean} [options.strict=false] - If true, will throw an error if the expression contains both dayOfMonth and dayOfWeek, or a hashed range or step the field cannot satisfy.
|
|
78
|
+
* @param {CronDate} [options.currentDate=new CronDate(undefined, 'UTC')] - The date to use when calculating the next/previous occurrence.
|
|
79
|
+
*
|
|
80
|
+
* @returns {CronExpression} A CronExpression object.
|
|
81
|
+
*/
|
|
82
|
+
static parse(expression, options = {}) {
|
|
83
|
+
const { strict = false, hashSeed } = options;
|
|
84
|
+
const rand = (0, random_1.seededRandom)(hashSeed);
|
|
85
|
+
if (Object.hasOwn(PredefinedExpressions, expression)) {
|
|
86
|
+
expression = PredefinedExpressions[expression];
|
|
87
|
+
}
|
|
88
|
+
const rawFields = CronExpressionParser.#getRawFields(expression, strict);
|
|
89
|
+
if (!(rawFields.dayOfMonth === '*' || rawFields.dayOfWeek === '*' || !strict)) {
|
|
90
|
+
throw new Error('Cannot use both dayOfMonth and dayOfWeek together in strict mode!');
|
|
91
|
+
}
|
|
92
|
+
const second = CronExpressionParser.#parseField(CronUnit.Second, rawFields.second, fields_1.CronSecond.constraints, rand, strict);
|
|
93
|
+
const minute = CronExpressionParser.#parseField(CronUnit.Minute, rawFields.minute, fields_1.CronMinute.constraints, rand, strict);
|
|
94
|
+
const hour = CronExpressionParser.#parseField(CronUnit.Hour, rawFields.hour, fields_1.CronHour.constraints, rand, strict);
|
|
95
|
+
const month = CronExpressionParser.#parseField(CronUnit.Month, rawFields.month, fields_1.CronMonth.constraints, rand, strict);
|
|
96
|
+
const dayOfMonth = CronExpressionParser.#parseField(CronUnit.DayOfMonth, rawFields.dayOfMonth, fields_1.CronDayOfMonth.constraints, rand, strict);
|
|
97
|
+
const { dayOfWeek: _dayOfWeek, nthDayOfWeek } = CronExpressionParser.#parseNthDay(rawFields.dayOfWeek);
|
|
98
|
+
const dayOfWeek = CronExpressionParser.#parseField(CronUnit.DayOfWeek, _dayOfWeek, fields_1.CronDayOfWeek.constraints, rand, strict);
|
|
99
|
+
const fields = new CronFieldCollection_1.CronFieldCollection({
|
|
100
|
+
second: new fields_1.CronSecond(second, { rawValue: rawFields.second }),
|
|
101
|
+
minute: new fields_1.CronMinute(minute, { rawValue: rawFields.minute }),
|
|
102
|
+
hour: new fields_1.CronHour(hour, { rawValue: rawFields.hour }),
|
|
103
|
+
dayOfMonth: fields_1.CronDayOfMonth.fromMonth(month, dayOfMonth, { rawValue: rawFields.dayOfMonth }),
|
|
104
|
+
month: new fields_1.CronMonth(month, { rawValue: rawFields.month }),
|
|
105
|
+
dayOfWeek: new fields_1.CronDayOfWeek(dayOfWeek, { rawValue: rawFields.dayOfWeek, nthDayOfWeek }),
|
|
106
|
+
});
|
|
107
|
+
return new CronExpression_1.CronExpression(fields, { ...options, expression });
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Get the raw fields from a cron expression.
|
|
111
|
+
* @param {string} expression - The cron expression to parse.
|
|
112
|
+
* @param {boolean} strict - If true, will throw an error if the expression contains both dayOfMonth and dayOfWeek.
|
|
113
|
+
* @private
|
|
114
|
+
* @returns {RawCronFields} The raw fields.
|
|
115
|
+
*/
|
|
116
|
+
static #getRawFields(expression, strict) {
|
|
117
|
+
if (strict && !expression.length) {
|
|
118
|
+
throw new Error('Invalid cron expression');
|
|
119
|
+
}
|
|
120
|
+
expression = expression || '0 * * * * *';
|
|
121
|
+
if (expression.length > MAX_EXPRESSION_LENGTH) {
|
|
122
|
+
throw new Error(`Invalid cron expression, too long, expected at most ${MAX_EXPRESSION_LENGTH} characters`);
|
|
123
|
+
}
|
|
124
|
+
const atoms = expression.trim().split(/\s+/);
|
|
125
|
+
if (strict && atoms.length < 6) {
|
|
126
|
+
throw new Error('Invalid cron expression, expected 6 fields');
|
|
127
|
+
}
|
|
128
|
+
if (atoms.length > 6) {
|
|
129
|
+
throw new Error('Invalid cron expression, too many fields');
|
|
130
|
+
}
|
|
131
|
+
const defaults = ['0', '*', '*', '*', '*', '*'];
|
|
132
|
+
if (atoms.length < defaults.length) {
|
|
133
|
+
atoms.unshift(...defaults.slice(0, defaults.length - atoms.length));
|
|
134
|
+
}
|
|
135
|
+
const [second, minute, hour, dayOfMonth, month, dayOfWeek] = atoms;
|
|
136
|
+
return { second, minute, hour, dayOfMonth, month, dayOfWeek };
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Parse a field from a cron expression.
|
|
140
|
+
* @param {CronUnit} field - The field to parse.
|
|
141
|
+
* @param {string} value - The value of the field.
|
|
142
|
+
* @param {CronConstraints} constraints - The constraints for the field.
|
|
143
|
+
* @param {PRNG} rand - The random number generator to use.
|
|
144
|
+
* @param {boolean} strict - If true, will throw an error on an unusable hashed range or step.
|
|
145
|
+
* @private
|
|
146
|
+
* @returns {(number | string)[]} The parsed field.
|
|
147
|
+
*/
|
|
148
|
+
static #parseField(field, value, constraints, rand, strict) {
|
|
149
|
+
// Replace aliases for month and dayOfWeek
|
|
150
|
+
if (field === CronUnit.Month || field === CronUnit.DayOfWeek) {
|
|
151
|
+
const aliases = field === CronUnit.Month ? Months : DayOfWeek;
|
|
152
|
+
value = value.replace(/[a-z]{3}/gi, (match) => {
|
|
153
|
+
match = match.toLowerCase();
|
|
154
|
+
const replacer = aliases[match];
|
|
155
|
+
if (replacer === undefined) {
|
|
156
|
+
throw new Error(`Validation error, cannot resolve alias "${match}"`);
|
|
157
|
+
}
|
|
158
|
+
return replacer.toString();
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
// Check for valid characters
|
|
162
|
+
if (!constraints.validChars.test(value)) {
|
|
163
|
+
throw new Error(`Invalid characters, got value: ${value}`);
|
|
164
|
+
}
|
|
165
|
+
value = this.#parseWildcard(value, constraints);
|
|
166
|
+
value = this.#parseHashed(value, constraints, rand, field, strict);
|
|
167
|
+
return this.#parseSequence(field, value, constraints);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Parse a wildcard from a cron expression.
|
|
171
|
+
* @param {string} value - The value to parse.
|
|
172
|
+
* @param {CronConstraints} constraints - The constraints for the field.
|
|
173
|
+
* @private
|
|
174
|
+
*/
|
|
175
|
+
static #parseWildcard(value, constraints) {
|
|
176
|
+
// Only a whole list item (optionally with a step) stands for the full range
|
|
177
|
+
const parsed = value.replace(/(^|,)[*?](?=\/|,|$)/g, (_, separator) => `${separator}${constraints.min}-${constraints.max}`);
|
|
178
|
+
if (/[*?]/.test(parsed)) {
|
|
179
|
+
throw new Error(`Invalid wildcard, got value: ${value}`);
|
|
180
|
+
}
|
|
181
|
+
return parsed;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Parse a hashed value from a cron expression.
|
|
185
|
+
* @param {string} value - The value to parse.
|
|
186
|
+
* @param {CronConstraints} constraints - The constraints for the field.
|
|
187
|
+
* @param {PRNG} rand - The random number generator to use.
|
|
188
|
+
* @param {CronUnit} field - The field being parsed, used when reporting an unusable range or step.
|
|
189
|
+
* @param {boolean} strict - If true, will throw an error on an unusable hashed range or step.
|
|
190
|
+
* @private
|
|
191
|
+
*/
|
|
192
|
+
static #parseHashed(value, constraints, rand, field, strict) {
|
|
193
|
+
const randomValue = rand();
|
|
194
|
+
let count = 0;
|
|
195
|
+
return value.replace(/H(?:\((\d+)-(\d+)\))?(?:\/(\d+))?/g, (_, min, max, step) => {
|
|
196
|
+
// H(range)/step
|
|
197
|
+
if (min && max && step) {
|
|
198
|
+
const minNum = parseInt(min, 10);
|
|
199
|
+
const maxNum = parseInt(max, 10);
|
|
200
|
+
const stepNum = parseInt(step, 10);
|
|
201
|
+
if (stepNum <= 0) {
|
|
202
|
+
throw new Error(`Invalid step: ${stepNum}, must be positive`);
|
|
203
|
+
}
|
|
204
|
+
const range = CronExpressionParser.#hashedRange(minNum, maxNum, constraints, field, strict);
|
|
205
|
+
count += Math.ceil((range.max - range.min + 1) / stepNum);
|
|
206
|
+
CronExpressionParser.#assertMaxFieldValues(field, count);
|
|
207
|
+
return CronExpressionParser.#hashedStep(randomValue, range.min, range.max, stepNum, field, strict);
|
|
208
|
+
}
|
|
209
|
+
// H(range)
|
|
210
|
+
else if (min && max) {
|
|
211
|
+
const minNum = parseInt(min, 10);
|
|
212
|
+
const maxNum = parseInt(max, 10);
|
|
213
|
+
const range = CronExpressionParser.#hashedRange(minNum, maxNum, constraints, field, strict);
|
|
214
|
+
return String(CronExpressionParser.#hashedValue(randomValue, range.min, range.max));
|
|
215
|
+
}
|
|
216
|
+
// H/step
|
|
217
|
+
else if (step) {
|
|
218
|
+
const stepNum = parseInt(step, 10);
|
|
219
|
+
// Validate step
|
|
220
|
+
if (stepNum <= 0) {
|
|
221
|
+
throw new Error(`Invalid step: ${stepNum}, must be positive`);
|
|
222
|
+
}
|
|
223
|
+
count += Math.ceil((constraints.max - constraints.min + 1) / stepNum);
|
|
224
|
+
CronExpressionParser.#assertMaxFieldValues(field, count);
|
|
225
|
+
return CronExpressionParser.#hashedStep(randomValue, constraints.min, constraints.max, stepNum, field, strict);
|
|
226
|
+
}
|
|
227
|
+
// H
|
|
228
|
+
else {
|
|
229
|
+
return String(CronExpressionParser.#hashedValue(randomValue, constraints.min, constraints.max));
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Pick a single hashed value within an inclusive range.
|
|
235
|
+
* @param {number} randomValue - The seeded random value in [0, 1).
|
|
236
|
+
* @param {number} min - Lowest value that may be picked.
|
|
237
|
+
* @param {number} max - Highest value that may be picked.
|
|
238
|
+
* @private
|
|
239
|
+
*/
|
|
240
|
+
static #hashedValue(randomValue, min, max) {
|
|
241
|
+
return Math.floor(randomValue * (max - min + 1)) + min;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Name a field the way the expression object does, rather than the Pascal case of CronUnit.
|
|
245
|
+
* @param {CronUnit} field - The field to name.
|
|
246
|
+
* @private
|
|
247
|
+
*/
|
|
248
|
+
static #fieldName(field) {
|
|
249
|
+
return field.charAt(0).toLowerCase() + field.slice(1);
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Narrow an explicit hashed range to the values the field can hold, so that values are only
|
|
253
|
+
* ever drawn from the range a step is measured against. In strict mode a bound outside the
|
|
254
|
+
* field constraints is rejected instead of clamped, which keeps the range reported in the
|
|
255
|
+
* error the one that was written.
|
|
256
|
+
* @param {number} min - Lowest value the expression asks for.
|
|
257
|
+
* @param {number} max - Highest value the expression asks for.
|
|
258
|
+
* @param {CronConstraints} constraints - The constraints for the field.
|
|
259
|
+
* @param {CronUnit} field - The field being parsed, used when reporting an unusable range.
|
|
260
|
+
* @param {boolean} strict - If true, will throw an error on a range outside the constraints.
|
|
261
|
+
* @private
|
|
262
|
+
*/
|
|
263
|
+
static #hashedRange(min, max, constraints, field, strict) {
|
|
264
|
+
if (min > max) {
|
|
265
|
+
throw new Error(`Invalid range: ${min}-${max}, min > max`);
|
|
266
|
+
}
|
|
267
|
+
if (strict && (min < constraints.min || max > constraints.max)) {
|
|
268
|
+
throw new Error(`Invalid range: ${min}-${max}, outside the ${constraints.min}-${constraints.max} range of the ${CronExpressionParser.#fieldName(field)} field`);
|
|
269
|
+
}
|
|
270
|
+
const rangeMin = Math.max(min, constraints.min);
|
|
271
|
+
const rangeMax = Math.min(max, constraints.max);
|
|
272
|
+
if (rangeMin > rangeMax) {
|
|
273
|
+
throw new Error(`Invalid range: ${min}-${max}, no usable value in the ${CronExpressionParser.#fieldName(field)} field`);
|
|
274
|
+
}
|
|
275
|
+
return { min: rangeMin, max: rangeMax };
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Build the hashed values of a stepped range, offset from the start of the step by the seeded
|
|
279
|
+
* jitter. A step wider than the range leaves no step-aligned value inside it, so a single
|
|
280
|
+
* hashed occurrence within the range is used instead of an empty field, or in strict mode the
|
|
281
|
+
* expression is rejected as unsatisfiable.
|
|
282
|
+
* @param {number} randomValue - The seeded random value in [0, 1).
|
|
283
|
+
* @param {number} min - Lowest value the range allows.
|
|
284
|
+
* @param {number} max - Highest value the range allows.
|
|
285
|
+
* @param {number} step - The step between values, already validated as positive.
|
|
286
|
+
* @param {CronUnit} field - The field being parsed, used when reporting an unusable step.
|
|
287
|
+
* @param {boolean} strict - If true, will throw an error on a step wider than its range.
|
|
288
|
+
* @private
|
|
289
|
+
*/
|
|
290
|
+
static #hashedStep(randomValue, min, max, step, field, strict) {
|
|
291
|
+
if (strict && step > max - min + 1) {
|
|
292
|
+
throw new Error(`Invalid step: ${step}, wider than the ${min}-${max} range of the ${CronExpressionParser.#fieldName(field)} field`);
|
|
293
|
+
}
|
|
294
|
+
const offset = Math.floor(randomValue * step);
|
|
295
|
+
const values = [];
|
|
296
|
+
for (let i = Math.floor(min / step) * step + offset; i <= max; i += step) {
|
|
297
|
+
if (i >= min) {
|
|
298
|
+
values.push(i);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
if (values.length === 0) {
|
|
302
|
+
return String(CronExpressionParser.#hashedValue(randomValue, min, max));
|
|
303
|
+
}
|
|
304
|
+
return values.join(',');
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Throw once a field has expanded to more than MAX_FIELD_VALUES values.
|
|
308
|
+
* @param {CronUnit} field - The field being parsed.
|
|
309
|
+
* @param {number} count - The number of values collected so far.
|
|
310
|
+
* @private
|
|
311
|
+
*/
|
|
312
|
+
static #assertMaxFieldValues(field, count) {
|
|
313
|
+
if (count > MAX_FIELD_VALUES) {
|
|
314
|
+
throw new Error(`Constraint error, too many values in ${field} field, expected at most ${MAX_FIELD_VALUES}`);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Parse a sequence from a cron expression.
|
|
319
|
+
* @param {CronUnit} field - The field to parse.
|
|
320
|
+
* @param {string} val - The sequence to parse.
|
|
321
|
+
* @param {CronConstraints} constraints - The constraints for the field.
|
|
322
|
+
* @private
|
|
323
|
+
*/
|
|
324
|
+
static #parseSequence(field, val, constraints) {
|
|
325
|
+
const stack = [];
|
|
326
|
+
function handleResult(result, constraints) {
|
|
327
|
+
if (Array.isArray(result)) {
|
|
328
|
+
stack.push(...result);
|
|
329
|
+
}
|
|
330
|
+
else {
|
|
331
|
+
if (CronExpressionParser.#isValidConstraintChar(constraints, result)) {
|
|
332
|
+
stack.push(result);
|
|
333
|
+
}
|
|
334
|
+
else {
|
|
335
|
+
const v = parseInt(result.toString(), 10);
|
|
336
|
+
const isValid = v >= constraints.min && v <= constraints.max;
|
|
337
|
+
if (!isValid) {
|
|
338
|
+
throw new Error(`Constraint error, got value ${result} expected range ${constraints.min}-${constraints.max}`);
|
|
339
|
+
}
|
|
340
|
+
stack.push(field === CronUnit.DayOfWeek ? v % 7 : result);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
const atoms = val.split(',');
|
|
345
|
+
for (const atom of atoms) {
|
|
346
|
+
CronExpressionParser.#assertMaxFieldValues(field, stack.length);
|
|
347
|
+
if (!(atom.length > 0)) {
|
|
348
|
+
throw new Error('Invalid list value format');
|
|
349
|
+
}
|
|
350
|
+
handleResult(CronExpressionParser.#parseRepeat(field, atom, constraints), constraints);
|
|
351
|
+
}
|
|
352
|
+
return stack;
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Parse repeat from a cron expression.
|
|
356
|
+
* @param {CronUnit} field - The field to parse.
|
|
357
|
+
* @param {string} val - The repeat to parse.
|
|
358
|
+
* @param {CronConstraints} constraints - The constraints for the field.
|
|
359
|
+
* @private
|
|
360
|
+
* @returns {(number | string)[]} The parsed repeat.
|
|
361
|
+
*/
|
|
362
|
+
static #parseRepeat(field, val, constraints) {
|
|
363
|
+
const atoms = val.split('/');
|
|
364
|
+
if (atoms.length > 2) {
|
|
365
|
+
throw new Error(`Invalid repeat: ${val}`);
|
|
366
|
+
}
|
|
367
|
+
if (atoms.length === 2) {
|
|
368
|
+
if (!atoms[0].includes('-')) {
|
|
369
|
+
atoms[0] = `${atoms[0]}-${constraints.max}`;
|
|
370
|
+
}
|
|
371
|
+
return CronExpressionParser.#parseRange(field, atoms[0], +atoms[1], constraints);
|
|
372
|
+
}
|
|
373
|
+
return CronExpressionParser.#parseRange(field, val, 1, constraints);
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Validate a cron range.
|
|
377
|
+
* @param {number} min - The minimum value of the range.
|
|
378
|
+
* @param {number} max - The maximum value of the range.
|
|
379
|
+
* @param {CronConstraints} constraints - The constraints for the field.
|
|
380
|
+
* @private
|
|
381
|
+
* @returns {void}
|
|
382
|
+
* @throws {Error} Throws an error if the range is invalid.
|
|
383
|
+
*/
|
|
384
|
+
static #validateRange(min, max, constraints) {
|
|
385
|
+
const isValid = !isNaN(min) && !isNaN(max) && min >= constraints.min && max <= constraints.max;
|
|
386
|
+
if (!isValid) {
|
|
387
|
+
throw new Error(`Constraint error, got range ${min}-${max} expected range ${constraints.min}-${constraints.max}`);
|
|
388
|
+
}
|
|
389
|
+
if (min > max) {
|
|
390
|
+
throw new Error(`Invalid range: ${min}-${max}, min(${min}) > max(${max})`);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Validate a cron repeat interval.
|
|
395
|
+
* @param {number} repeatInterval - The repeat interval to validate.
|
|
396
|
+
* @private
|
|
397
|
+
* @returns {void}
|
|
398
|
+
* @throws {Error} Throws an error if the repeat interval is invalid.
|
|
399
|
+
*/
|
|
400
|
+
static #validateRepeatInterval(repeatInterval) {
|
|
401
|
+
if (!(!isNaN(repeatInterval) && repeatInterval > 0)) {
|
|
402
|
+
throw new Error(`Constraint error, cannot repeat at every ${repeatInterval} time.`);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Create a range from a cron expression.
|
|
407
|
+
* @param {CronUnit} field - The field to parse.
|
|
408
|
+
* @param {number} min - The minimum value of the range.
|
|
409
|
+
* @param {number} max - The maximum value of the range.
|
|
410
|
+
* @param {number} repeatInterval - The repeat interval of the range.
|
|
411
|
+
* @private
|
|
412
|
+
* @returns {number[]} The created range.
|
|
413
|
+
*/
|
|
414
|
+
static #createRange(field, min, max, repeatInterval) {
|
|
415
|
+
const stack = [];
|
|
416
|
+
if (field === CronUnit.DayOfWeek && max % 7 === 0 && (max - min) % repeatInterval === 0) {
|
|
417
|
+
stack.push(0);
|
|
418
|
+
}
|
|
419
|
+
for (let index = min; index <= max; index += repeatInterval) {
|
|
420
|
+
if (stack.indexOf(index) === -1) {
|
|
421
|
+
stack.push(index);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
return stack;
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* Parse a range from a cron expression.
|
|
428
|
+
* @param {CronUnit} field - The field to parse.
|
|
429
|
+
* @param {string} val - The range to parse.
|
|
430
|
+
* @param {number} repeatInterval - The repeat interval of the range.
|
|
431
|
+
* @param {CronConstraints} constraints - The constraints for the field.
|
|
432
|
+
* @private
|
|
433
|
+
* @returns {number[] | string[] | number | string} The parsed range.
|
|
434
|
+
*/
|
|
435
|
+
static #parseRange(field, val, repeatInterval, constraints) {
|
|
436
|
+
const atoms = val.split('-');
|
|
437
|
+
if (atoms.length <= 1) {
|
|
438
|
+
return isNaN(+val) ? val : +val;
|
|
439
|
+
}
|
|
440
|
+
if (atoms.length > 2) {
|
|
441
|
+
throw new Error(`Invalid range: ${val}`);
|
|
442
|
+
}
|
|
443
|
+
// digits only: parseInt would read 3L as 3, and +'' would be 0
|
|
444
|
+
const [min, max] = atoms.map((atom) => (/^\d+$/.test(atom) ? +atom : NaN));
|
|
445
|
+
this.#validateRange(min, max, constraints);
|
|
446
|
+
this.#validateRepeatInterval(repeatInterval);
|
|
447
|
+
// Create range
|
|
448
|
+
return this.#createRange(field, min, max, repeatInterval);
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* Parse a cron expression.
|
|
452
|
+
* @param {string} val - The cron expression to parse.
|
|
453
|
+
* @private
|
|
454
|
+
* @returns {string} The parsed cron expression.
|
|
455
|
+
*/
|
|
456
|
+
static #parseNthDay(val) {
|
|
457
|
+
const atoms = val.split('#');
|
|
458
|
+
if (atoms.length <= 1) {
|
|
459
|
+
return { dayOfWeek: atoms[0] };
|
|
460
|
+
}
|
|
461
|
+
const nthValue = +atoms[atoms.length - 1];
|
|
462
|
+
const matches = val.match(/([,\-/L])/);
|
|
463
|
+
if (matches !== null) {
|
|
464
|
+
throw new Error(`Constraint error, invalid dayOfWeek \`#\` and \`${matches?.[0]}\` special characters are incompatible`);
|
|
465
|
+
}
|
|
466
|
+
if (!(atoms.length <= 2 && !isNaN(nthValue) && nthValue >= 1 && nthValue <= 5)) {
|
|
467
|
+
throw new Error('Constraint error, invalid dayOfWeek occurrence number (#)');
|
|
468
|
+
}
|
|
469
|
+
return { dayOfWeek: atoms[0], nthDayOfWeek: nthValue };
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* Checks if a character is valid for a field.
|
|
473
|
+
* @param {CronConstraints} constraints - The constraints for the field.
|
|
474
|
+
* @param {string | number} value - The value to check.
|
|
475
|
+
* @private
|
|
476
|
+
* @returns {boolean} Whether the character is valid for the field.
|
|
477
|
+
*/
|
|
478
|
+
static #isValidConstraintChar(constraints, value) {
|
|
479
|
+
return constraints.chars.some((char) => value.toString().includes(char));
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
exports.CronExpressionParser = CronExpressionParser;
|