@genesislcap/mock-server 15.74.0 → 15.76.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +296 -58
- package/dist/db/schema.d.ts +9 -1
- package/dist/db/schema.js +40 -11
- package/dist/db/store.d.ts +1 -0
- package/dist/db/store.js +4 -0
- package/dist/handlers/auth.d.ts +15 -6
- package/dist/handlers/auth.js +152 -33
- package/dist/handlers/commitEvent.js +43 -20
- package/dist/handlers/crudEvents.d.ts +3 -1
- package/dist/handlers/crudEvents.js +3 -2
- package/dist/handlers/eventValidation.js +6 -3
- package/dist/handlers/http.d.ts +2 -2
- package/dist/handlers/http.js +66 -43
- package/dist/handlers/jsonSchema.d.ts +1 -0
- package/dist/handlers/jsonSchema.js +72 -21
- package/dist/handlers/meta.d.ts +1 -1
- package/dist/handlers/meta.js +59 -10
- package/dist/handlers/requestReply.js +36 -9
- package/dist/index.d.ts +1 -1
- package/dist/presets/auth.d.ts +25 -0
- package/dist/presets/auth.js +855 -0
- package/dist/presets/cronExpression.d.ts +1 -0
- package/dist/presets/cronExpression.js +429 -0
- package/dist/presets/fileServer.d.ts +13 -0
- package/dist/presets/fileServer.js +399 -0
- package/dist/presets/gsf.d.ts +24 -0
- package/dist/presets/gsf.js +450 -0
- package/dist/presets/index.d.ts +1 -0
- package/dist/presets/index.js +1 -0
- package/dist/presets/javaTime.d.ts +7 -0
- package/dist/presets/javaTime.js +322 -0
- package/dist/presets/multipart.d.ts +14 -0
- package/dist/presets/multipart.js +91 -0
- package/dist/presets/notify.d.ts +27 -0
- package/dist/presets/notify.js +250 -0
- package/dist/presets/notifyDispatch.d.ts +28 -0
- package/dist/presets/notifyDispatch.js +570 -0
- package/dist/presets/notifyRules.d.ts +9 -0
- package/dist/presets/notifyRules.js +754 -0
- package/dist/presets/platform/backing.json +8058 -217
- package/dist/presets/platform/criteria-model.json +362 -0
- package/dist/presets/platform/time-zones.json +608 -0
- package/dist/presets/platform.d.ts +7 -0
- package/dist/presets/platform.js +145 -103
- package/dist/presets/products.d.ts +9 -7
- package/dist/presets/products.js +89 -21
- package/dist/presets/reconciliation.d.ts +18 -0
- package/dist/presets/reconciliation.js +721 -0
- package/dist/presets/reporting.d.ts +14 -0
- package/dist/presets/reporting.js +862 -0
- package/dist/protocol/connection.d.ts +2 -0
- package/dist/protocol/connection.js +4 -0
- package/dist/protocol/dtoTypes.d.ts +30 -0
- package/dist/protocol/dtoTypes.js +250 -0
- package/dist/protocol/errors.d.ts +3 -1
- package/dist/protocol/errors.js +2 -0
- package/dist/protocol/fieldTypes.js +5 -0
- package/dist/protocol/router.d.ts +1 -0
- package/dist/protocol/router.js +3 -3
- package/dist/protocol/schemaValidation.d.ts +1 -1
- package/dist/protocol/schemaValidation.js +53 -8
- package/dist/server.js +34 -2
- package/dist/types.d.ts +50 -2
- package/package.json +1 -1
- package/src/db/schema.ts +56 -13
- package/src/db/store.ts +5 -0
- package/src/handlers/auth.ts +211 -37
- package/src/handlers/commitEvent.ts +44 -19
- package/src/handlers/crudEvents.ts +9 -2
- package/src/handlers/eventValidation.ts +6 -3
- package/src/handlers/http.ts +83 -42
- package/src/handlers/jsonSchema.ts +86 -23
- package/src/handlers/meta.ts +77 -9
- package/src/handlers/requestReply.ts +42 -6
- package/src/index.ts +7 -0
- package/src/presets/auth.ts +961 -0
- package/src/presets/cronExpression.ts +445 -0
- package/src/presets/fileServer.ts +475 -0
- package/src/presets/gsf.ts +475 -0
- package/src/presets/index.ts +5 -0
- package/src/presets/javaTime.ts +354 -0
- package/src/presets/multipart.ts +110 -0
- package/src/presets/notify.ts +312 -0
- package/src/presets/notifyDispatch.ts +685 -0
- package/src/presets/notifyRules.ts +866 -0
- package/src/presets/platform/backing.json +8058 -217
- package/src/presets/platform/criteria-model.json +362 -0
- package/src/presets/platform/time-zones.json +608 -0
- package/src/presets/platform.ts +204 -115
- package/src/presets/products.ts +125 -19
- package/src/presets/reconciliation.ts +824 -0
- package/src/presets/reporting.ts +953 -0
- package/src/protocol/connection.ts +4 -0
- package/src/protocol/dtoTypes.ts +310 -0
- package/src/protocol/errors.ts +13 -1
- package/src/protocol/fieldTypes.ts +5 -0
- package/src/protocol/router.ts +3 -3
- package/src/protocol/schemaValidation.ts +61 -8
- package/src/server.ts +38 -2
- package/src/types.ts +147 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function cronExpressionError(expression: string): string | undefined;
|
|
@@ -0,0 +1,429 @@
|
|
|
1
|
+
// Whether log4j's CronExpression (org.apache.logging.log4j.core.util, log4j
|
|
2
|
+
// 2.25.4, a copy of Quartz's parser) takes a cron expression, and if not, its
|
|
3
|
+
// ParseException's message: what a product validating a schedule with it
|
|
4
|
+
// reports. A port of its buildExpression, storeExpressionVals, checkNext and
|
|
5
|
+
// addToSet, down to the Java exceptions their string handling throws, checked
|
|
6
|
+
// against the real class on a few thousand expressions
|
|
7
|
+
// (test/fixtures/java-verdicts.json keeps one per message).
|
|
8
|
+
// The fields, in the expression's order.
|
|
9
|
+
const Field = {
|
|
10
|
+
Second: 0,
|
|
11
|
+
Minute: 1,
|
|
12
|
+
Hour: 2,
|
|
13
|
+
DayOfMonth: 3,
|
|
14
|
+
Month: 4,
|
|
15
|
+
DayOfWeek: 5,
|
|
16
|
+
Year: 6,
|
|
17
|
+
};
|
|
18
|
+
const ALL_SPEC = 99;
|
|
19
|
+
const NO_SPEC = 98;
|
|
20
|
+
// A month or day name: JAN, MON.
|
|
21
|
+
const NAME_LENGTH = 3;
|
|
22
|
+
// The most days an L-n offset may take, and the most an nth day (#n) may be.
|
|
23
|
+
const MAX_LAST_DAY_OFFSET = 30;
|
|
24
|
+
const MAX_NTH_DAY = 5;
|
|
25
|
+
const FIRST_YEAR = 1970;
|
|
26
|
+
// The last year a range runs to: Calendar.getInstance().get(YEAR) + 100.
|
|
27
|
+
const YEARS_AHEAD = 100;
|
|
28
|
+
const MONTHS = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC'];
|
|
29
|
+
const DAYS = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT'];
|
|
30
|
+
const MINUTES = {
|
|
31
|
+
first: 0,
|
|
32
|
+
last: 59,
|
|
33
|
+
wrap: 60,
|
|
34
|
+
message: 'Minute and Second values must be between 0 and 59',
|
|
35
|
+
increment: { max: 59, label: 60 },
|
|
36
|
+
};
|
|
37
|
+
const RANGES = {
|
|
38
|
+
[Field.Second]: MINUTES,
|
|
39
|
+
[Field.Minute]: MINUTES,
|
|
40
|
+
[Field.Hour]: {
|
|
41
|
+
first: 0,
|
|
42
|
+
last: 23,
|
|
43
|
+
wrap: 24,
|
|
44
|
+
message: 'Hour values must be between 0 and 23',
|
|
45
|
+
increment: { max: 23, label: 24 },
|
|
46
|
+
},
|
|
47
|
+
[Field.DayOfMonth]: {
|
|
48
|
+
first: 1,
|
|
49
|
+
last: 31,
|
|
50
|
+
wrap: 31,
|
|
51
|
+
message: 'Day of month values must be between 1 and 31',
|
|
52
|
+
increment: { max: 31, label: 31 },
|
|
53
|
+
},
|
|
54
|
+
[Field.Month]: {
|
|
55
|
+
first: 1,
|
|
56
|
+
last: 12,
|
|
57
|
+
wrap: 12,
|
|
58
|
+
message: 'Month values must be between 1 and 12',
|
|
59
|
+
increment: { max: 12, label: 12 },
|
|
60
|
+
},
|
|
61
|
+
[Field.DayOfWeek]: {
|
|
62
|
+
first: 1,
|
|
63
|
+
last: 7,
|
|
64
|
+
wrap: 7,
|
|
65
|
+
message: 'Day-of-Week values must be between 1 and 7',
|
|
66
|
+
increment: { max: 7, label: 7 },
|
|
67
|
+
},
|
|
68
|
+
// No range check, and a range can't wrap.
|
|
69
|
+
[Field.Year]: { first: FIRST_YEAR, last: Number.POSITIVE_INFINITY, wrap: 0 },
|
|
70
|
+
};
|
|
71
|
+
const lastOf = (type) => type === Field.Year ? new Date().getFullYear() + YEARS_AHEAD : RANGES[type].last;
|
|
72
|
+
// java.text.ParseException: the message the product shows.
|
|
73
|
+
class ParseError extends Error {
|
|
74
|
+
}
|
|
75
|
+
// Any other Java exception, as its toString() prints it.
|
|
76
|
+
class JavaError extends Error {
|
|
77
|
+
}
|
|
78
|
+
// String.charAt, String.substring and Integer.parseInt as Java throws them.
|
|
79
|
+
function charAt(s, i) {
|
|
80
|
+
if (i < 0 || i >= s.length) {
|
|
81
|
+
throw new JavaError(`java.lang.StringIndexOutOfBoundsException: String index out of range: ${i}`);
|
|
82
|
+
}
|
|
83
|
+
return s[i];
|
|
84
|
+
}
|
|
85
|
+
function substring(s, begin, end = s.length) {
|
|
86
|
+
if (begin < 0 || begin > end || end > s.length) {
|
|
87
|
+
throw new JavaError(`java.lang.StringIndexOutOfBoundsException: begin ${begin}, end ${end}, length ${s.length}`);
|
|
88
|
+
}
|
|
89
|
+
return s.slice(begin, end);
|
|
90
|
+
}
|
|
91
|
+
const INT_MAX = 2_147_483_647;
|
|
92
|
+
function parseInt(s) {
|
|
93
|
+
const fail = () => new JavaError(`java.lang.NumberFormatException: For input string: "${s}"`);
|
|
94
|
+
if (!/^[+-]?\d+$/.test(s))
|
|
95
|
+
throw fail();
|
|
96
|
+
const value = Number(s);
|
|
97
|
+
if (value > INT_MAX || value < -INT_MAX - 1)
|
|
98
|
+
throw fail();
|
|
99
|
+
return value;
|
|
100
|
+
}
|
|
101
|
+
const isDigit = (c) => c >= '0' && c <= '9';
|
|
102
|
+
const isBlank = (c) => c === ' ' || c === '\t';
|
|
103
|
+
function checkIncrementRange(incr, type) {
|
|
104
|
+
const limit = RANGES[type].increment;
|
|
105
|
+
if (limit && incr > limit.max)
|
|
106
|
+
throw new ParseError(`Increment > ${limit.label} : ${incr}`);
|
|
107
|
+
}
|
|
108
|
+
function nthDay(s, i) {
|
|
109
|
+
let nth;
|
|
110
|
+
try {
|
|
111
|
+
nth = parseInt(substring(s, i));
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
throw new ParseError("A numeric value between 1 and 5 must follow the '#' option");
|
|
115
|
+
}
|
|
116
|
+
if (nth < 1 || nth > MAX_NTH_DAY) {
|
|
117
|
+
throw new ParseError("A numeric value between 1 and 5 must follow the '#' option");
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
class Parser {
|
|
121
|
+
sets = Array.from({ length: Field.Year + 1 }, () => new Set());
|
|
122
|
+
lastdayOfMonth = false;
|
|
123
|
+
expression;
|
|
124
|
+
constructor(expression) {
|
|
125
|
+
this.expression = expression;
|
|
126
|
+
}
|
|
127
|
+
build() {
|
|
128
|
+
let type = Field.Second;
|
|
129
|
+
const tokens = this.expression.split(/[ \t]+/).filter((token) => token !== '');
|
|
130
|
+
for (const token of tokens) {
|
|
131
|
+
if (type > Field.Year)
|
|
132
|
+
break;
|
|
133
|
+
// Java's trim(): every character up to U+0020, and only those.
|
|
134
|
+
// eslint-disable-next-line no-control-regex
|
|
135
|
+
const expr = token.replace(/^[\u0000-\u0020]+|[\u0000-\u0020]+$/g, '');
|
|
136
|
+
this.checkCombinations(expr, type);
|
|
137
|
+
for (const value of expr.split(',').filter((part) => part !== ''))
|
|
138
|
+
this.store(value, type);
|
|
139
|
+
type += 1;
|
|
140
|
+
}
|
|
141
|
+
if (type <= Field.DayOfWeek)
|
|
142
|
+
throw new ParseError('Unexpected end of expression.');
|
|
143
|
+
if (type <= Field.Year)
|
|
144
|
+
this.store('*', Field.Year);
|
|
145
|
+
const dayOfMonthSpec = !this.sets[Field.DayOfMonth].has(NO_SPEC);
|
|
146
|
+
const dayOfWeekSpec = !this.sets[Field.DayOfWeek].has(NO_SPEC);
|
|
147
|
+
if ((!dayOfMonthSpec || dayOfWeekSpec) && (!dayOfWeekSpec || dayOfMonthSpec)) {
|
|
148
|
+
throw new ParseError('Support for specifying both a day-of-week AND a day-of-month parameter is not implemented.');
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
checkCombinations(expr, type) {
|
|
152
|
+
const listsL = expr.includes('L') && expr.length > 1 && expr.includes(',');
|
|
153
|
+
if (type === Field.DayOfMonth && listsL) {
|
|
154
|
+
throw new ParseError("Support for specifying 'L' and 'LW' with other days of the month is not implemented");
|
|
155
|
+
}
|
|
156
|
+
if (type === Field.DayOfWeek && listsL) {
|
|
157
|
+
throw new ParseError("Support for specifying 'L' with other days of the week is not implemented");
|
|
158
|
+
}
|
|
159
|
+
const nth = expr.indexOf('#');
|
|
160
|
+
if (type === Field.DayOfWeek && nth !== -1 && expr.indexOf('#', nth + 1) !== -1) {
|
|
161
|
+
throw new ParseError('Support for specifying multiple "nth" days is not implemented.');
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
// storeExpressionVals.
|
|
165
|
+
store(s, type) {
|
|
166
|
+
let i = 0;
|
|
167
|
+
while (isBlank(s[i]))
|
|
168
|
+
i += 1;
|
|
169
|
+
if (i >= s.length)
|
|
170
|
+
return;
|
|
171
|
+
const c = charAt(s, i);
|
|
172
|
+
if (c >= 'A' && c <= 'Z' && s !== 'L' && s !== 'LW' && !/^L-[0-9]*[W]?$/.test(s)) {
|
|
173
|
+
this.storeName(s, i, type);
|
|
174
|
+
}
|
|
175
|
+
else if (c === '?') {
|
|
176
|
+
this.storeNoSpec(s, i + 1, type);
|
|
177
|
+
}
|
|
178
|
+
else if (c === '*' || c === '/') {
|
|
179
|
+
this.storeAll(s, i, type);
|
|
180
|
+
}
|
|
181
|
+
else if (c === 'L') {
|
|
182
|
+
this.storeLast(s, i + 1, type);
|
|
183
|
+
}
|
|
184
|
+
else if (isDigit(c)) {
|
|
185
|
+
this.storeNumber(s, i, type);
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
throw new ParseError(`Unexpected character: ${c}`);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
// A month or day name, a range of them, or a day's nth (MON#2).
|
|
192
|
+
storeName(s, start, type) {
|
|
193
|
+
let i = start;
|
|
194
|
+
let sub = substring(s, i, i + NAME_LENGTH);
|
|
195
|
+
const names = type === Field.Month ? MONTHS : type === Field.DayOfWeek ? DAYS : undefined;
|
|
196
|
+
if (!names)
|
|
197
|
+
throw new ParseError(`Illegal characters for this position: '${sub}'`);
|
|
198
|
+
const invalid = (name) => new ParseError(`Invalid ${type === Field.Month ? 'Month' : 'Day-of-Week'} value: '${name}'`);
|
|
199
|
+
const sval = names.indexOf(sub) + 1;
|
|
200
|
+
if (sval <= 0)
|
|
201
|
+
throw invalid(sub);
|
|
202
|
+
let eval_ = -1;
|
|
203
|
+
if (s.length > i + NAME_LENGTH) {
|
|
204
|
+
const c = charAt(s, i + NAME_LENGTH);
|
|
205
|
+
if (c === '-') {
|
|
206
|
+
i += NAME_LENGTH + 1;
|
|
207
|
+
sub = substring(s, i, i + NAME_LENGTH);
|
|
208
|
+
eval_ = names.indexOf(sub) + 1;
|
|
209
|
+
if (eval_ <= 0)
|
|
210
|
+
throw invalid(sub);
|
|
211
|
+
}
|
|
212
|
+
else if (type === Field.DayOfWeek && c === '#') {
|
|
213
|
+
nthDay(s, i + NAME_LENGTH + 1);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
this.add(sval, eval_, eval_ === -1 ? 0 : 1, type);
|
|
217
|
+
}
|
|
218
|
+
storeNoSpec(s, i, type) {
|
|
219
|
+
if (i + 1 < s.length && s[i] !== ' ' && s[i + 1] !== '\t') {
|
|
220
|
+
throw new ParseError(`Illegal character after '?': ${s[i]}`);
|
|
221
|
+
}
|
|
222
|
+
if (type !== Field.DayOfWeek && type !== Field.DayOfMonth) {
|
|
223
|
+
throw new ParseError("'?' can only be specfied for Day-of-Month or Day-of-Week.");
|
|
224
|
+
}
|
|
225
|
+
if (type === Field.DayOfWeek && !this.lastdayOfMonth) {
|
|
226
|
+
const dayOfMonth = this.sets[Field.DayOfMonth];
|
|
227
|
+
// TreeSet.last() on an empty set.
|
|
228
|
+
if (dayOfMonth.size === 0)
|
|
229
|
+
throw new JavaError('java.util.NoSuchElementException');
|
|
230
|
+
if (Math.max(...dayOfMonth) === NO_SPEC) {
|
|
231
|
+
throw new ParseError("'?' can only be specfied for Day-of-Month -OR- Day-of-Week.");
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
this.add(NO_SPEC, -1, 0, type);
|
|
235
|
+
}
|
|
236
|
+
// *, */n or /n.
|
|
237
|
+
storeAll(s, start, type) {
|
|
238
|
+
let i = start;
|
|
239
|
+
if (s[i] === '*' && i + 1 >= s.length) {
|
|
240
|
+
this.add(ALL_SPEC, -1, 0, type);
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
if (s[i] === '/' && (i + 1 >= s.length || isBlank(s[i + 1]))) {
|
|
244
|
+
throw new ParseError("'/' must be followed by an integer.");
|
|
245
|
+
}
|
|
246
|
+
if (s[i] === '*')
|
|
247
|
+
i += 1;
|
|
248
|
+
let incr = 1;
|
|
249
|
+
if (charAt(s, i) === '/') {
|
|
250
|
+
i += 1;
|
|
251
|
+
if (i >= s.length)
|
|
252
|
+
throw new ParseError('Unexpected end of string.');
|
|
253
|
+
incr = parseInt(substring(s, i));
|
|
254
|
+
checkIncrementRange(incr, type);
|
|
255
|
+
}
|
|
256
|
+
this.add(ALL_SPEC, -1, incr, type);
|
|
257
|
+
}
|
|
258
|
+
// L, L-n, LW in the day of month; L alone (Saturday) in the day of week.
|
|
259
|
+
storeLast(s, start, type) {
|
|
260
|
+
if (type === Field.DayOfMonth)
|
|
261
|
+
this.lastdayOfMonth = true;
|
|
262
|
+
const saturday = RANGES[Field.DayOfWeek].last;
|
|
263
|
+
if (type === Field.DayOfWeek)
|
|
264
|
+
this.add(saturday, saturday, 0, type);
|
|
265
|
+
if (type === Field.DayOfMonth && s.length > start && charAt(s, start) === '-') {
|
|
266
|
+
const offset = this.value(0, s, start + 1);
|
|
267
|
+
if (offset.value > MAX_LAST_DAY_OFFSET)
|
|
268
|
+
throw new ParseError('Offset from last day must be <= 30');
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
// A number, and what follows it (checkNext).
|
|
272
|
+
storeNumber(s, start, type) {
|
|
273
|
+
let val = Number(s[start]);
|
|
274
|
+
let i = start + 1;
|
|
275
|
+
if (i >= s.length) {
|
|
276
|
+
this.add(val, -1, -1, type);
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
if (isDigit(charAt(s, i))) {
|
|
280
|
+
const value = this.value(val, s, i);
|
|
281
|
+
val = value.value;
|
|
282
|
+
i = value.pos;
|
|
283
|
+
}
|
|
284
|
+
if (i >= s.length) {
|
|
285
|
+
this.add(val, -1, -1, type);
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
const c = charAt(s, i);
|
|
289
|
+
if (c === 'L')
|
|
290
|
+
this.lastDay(val, type, i);
|
|
291
|
+
else if (c === 'W')
|
|
292
|
+
this.weekday(val, type, i);
|
|
293
|
+
else if (c === '#') {
|
|
294
|
+
if (type !== Field.DayOfWeek)
|
|
295
|
+
throw new ParseError(`'#' option is not valid here. (pos=${i})`);
|
|
296
|
+
nthDay(s, i + 1);
|
|
297
|
+
this.sets[type].add(val);
|
|
298
|
+
}
|
|
299
|
+
else if (c === '-') {
|
|
300
|
+
this.range(i + 1, s, val, type);
|
|
301
|
+
}
|
|
302
|
+
else if (c === '/') {
|
|
303
|
+
this.add(val, -1, this.step(i + 1, s, true), type);
|
|
304
|
+
}
|
|
305
|
+
else {
|
|
306
|
+
this.add(val, -1, 0, type);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
// nL: the day of week's last in the month.
|
|
310
|
+
lastDay(val, type, pos) {
|
|
311
|
+
if (type !== Field.DayOfWeek)
|
|
312
|
+
throw new ParseError(`'L' option is not valid here. (pos=${pos})`);
|
|
313
|
+
if (val < 1 || val > RANGES[Field.DayOfWeek].last) {
|
|
314
|
+
throw new ParseError('Day-of-Week values must be between 1 and 7');
|
|
315
|
+
}
|
|
316
|
+
this.sets[type].add(val);
|
|
317
|
+
}
|
|
318
|
+
// nW: the weekday nearest the day of month.
|
|
319
|
+
weekday(val, type, pos) {
|
|
320
|
+
if (type !== Field.DayOfMonth)
|
|
321
|
+
throw new ParseError(`'W' option is not valid here. (pos=${pos})`);
|
|
322
|
+
if (val > RANGES[Field.DayOfMonth].last) {
|
|
323
|
+
throw new ParseError("The 'W' option does not make sense with values larger than 31 (max number of days in a month)");
|
|
324
|
+
}
|
|
325
|
+
this.sets[type].add(val);
|
|
326
|
+
}
|
|
327
|
+
// n-m, n-m/k.
|
|
328
|
+
range(start, s, val, type) {
|
|
329
|
+
let i = start;
|
|
330
|
+
let end = parseInt(charAt(s, i));
|
|
331
|
+
i += 1;
|
|
332
|
+
if (i >= s.length) {
|
|
333
|
+
this.add(val, end, 1, type);
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
if (isDigit(charAt(s, i))) {
|
|
337
|
+
const value = this.value(end, s, i);
|
|
338
|
+
end = value.value;
|
|
339
|
+
i = value.pos;
|
|
340
|
+
}
|
|
341
|
+
const step = i < s.length && s[i] === '/' ? this.step(i + 1, s, false) : 1;
|
|
342
|
+
this.add(val, end, step, type);
|
|
343
|
+
}
|
|
344
|
+
// The step after a /: one digit, or more. checkNext refuses any other
|
|
345
|
+
// character after a number's, not after a range's.
|
|
346
|
+
step(start, s, strict) {
|
|
347
|
+
const v = parseInt(charAt(s, start));
|
|
348
|
+
const i = start + 1;
|
|
349
|
+
if (i >= s.length)
|
|
350
|
+
return v;
|
|
351
|
+
const c = charAt(s, i);
|
|
352
|
+
if (isDigit(c))
|
|
353
|
+
return this.value(v, s, i).value;
|
|
354
|
+
if (strict)
|
|
355
|
+
throw new ParseError(`Unexpected character '${c}' after '/'`);
|
|
356
|
+
return v;
|
|
357
|
+
}
|
|
358
|
+
// getValue: the digits from i on, after v's.
|
|
359
|
+
value(v, s, start) {
|
|
360
|
+
let i = start;
|
|
361
|
+
let c = charAt(s, i);
|
|
362
|
+
let digits = String(v);
|
|
363
|
+
while (isDigit(c)) {
|
|
364
|
+
digits += c;
|
|
365
|
+
i += 1;
|
|
366
|
+
if (i >= s.length)
|
|
367
|
+
break;
|
|
368
|
+
c = charAt(s, i);
|
|
369
|
+
}
|
|
370
|
+
return { pos: i < s.length ? i : i + 1, value: parseInt(digits) };
|
|
371
|
+
}
|
|
372
|
+
// addToSet.
|
|
373
|
+
add(val, end, incr, type) {
|
|
374
|
+
const set = this.sets[type];
|
|
375
|
+
const { first, wrap, message } = RANGES[type];
|
|
376
|
+
const last = lastOf(type);
|
|
377
|
+
const days = type === Field.DayOfMonth || type === Field.DayOfWeek;
|
|
378
|
+
const spec = val === ALL_SPEC || (val === NO_SPEC && days);
|
|
379
|
+
if (message && !spec && (val < first || val > last || end > last))
|
|
380
|
+
throw new ParseError(message);
|
|
381
|
+
if ((incr === 0 || incr === -1) && val !== ALL_SPEC) {
|
|
382
|
+
set.add(val === -1 ? NO_SPEC : val);
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
let step = incr;
|
|
386
|
+
if (val === ALL_SPEC && step <= 0) {
|
|
387
|
+
step = 1;
|
|
388
|
+
set.add(ALL_SPEC);
|
|
389
|
+
}
|
|
390
|
+
const startAt = val === -1 || val === ALL_SPEC ? first : val;
|
|
391
|
+
let stopAt = end === -1 ? last : end;
|
|
392
|
+
let max = -1;
|
|
393
|
+
if (stopAt < startAt) {
|
|
394
|
+
if (type === Field.Year) {
|
|
395
|
+
throw new JavaError('java.lang.IllegalArgumentException: Start year must be less than stop year');
|
|
396
|
+
}
|
|
397
|
+
max = wrap;
|
|
398
|
+
stopAt += max;
|
|
399
|
+
}
|
|
400
|
+
// Nothing reads the years taken, and a range of them may be millions
|
|
401
|
+
// long: the first stands for them.
|
|
402
|
+
if (type === Field.Year) {
|
|
403
|
+
set.add(startAt);
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
const wrapsToMax = days || type === Field.Month;
|
|
407
|
+
for (let at = startAt; at <= stopAt; at += step) {
|
|
408
|
+
const wrapped = max === -1 ? at : at % max;
|
|
409
|
+
set.add(wrapped === 0 && max !== -1 && wrapsToMax ? max : wrapped);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
// The message new CronExpression(expression) throws with, or undefined when
|
|
414
|
+
// it takes it. It upper-cases the expression first; anything but its own
|
|
415
|
+
// ParseException is reported as "Illegal cron expression format (<the Java
|
|
416
|
+
// exception>)".
|
|
417
|
+
export function cronExpressionError(expression) {
|
|
418
|
+
try {
|
|
419
|
+
new Parser(expression.toUpperCase()).build();
|
|
420
|
+
return undefined;
|
|
421
|
+
}
|
|
422
|
+
catch (error) {
|
|
423
|
+
if (error instanceof ParseError)
|
|
424
|
+
return error.message;
|
|
425
|
+
if (error instanceof JavaError)
|
|
426
|
+
return `Illegal cron expression format (${error.message})`;
|
|
427
|
+
throw error;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { EventHandler, EventSchemaOverride, HttpRouteDef, RequestReplyDef } from '../types.ts';
|
|
2
|
+
import type { FileContent } from './reconciliation.ts';
|
|
3
|
+
export declare const newFileStorageId: () => string;
|
|
4
|
+
export declare const MAX_UPLOAD_BYTES: number;
|
|
5
|
+
export interface FileServerBacking {
|
|
6
|
+
eventHandlers: Record<string, EventHandler>;
|
|
7
|
+
eventSchemas: Record<string, EventSchemaOverride>;
|
|
8
|
+
requestReplies: Record<string, RequestReplyDef>;
|
|
9
|
+
httpRoutes: HttpRouteDef[];
|
|
10
|
+
contents: Map<string, Buffer>;
|
|
11
|
+
fileContent: FileContent;
|
|
12
|
+
}
|
|
13
|
+
export declare function fileServerBacking(): FileServerBacking;
|