semola 0.5.4 → 0.6.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 +18 -45
- package/dist/chunk-CKQMccvm.cjs +28 -0
- package/dist/lib/api/index.cjs +29 -15
- package/dist/lib/api/index.mjs +30 -16
- package/dist/lib/cache/index.cjs +47 -22
- package/dist/lib/cache/index.d.cts +3 -24
- package/dist/lib/cache/index.d.mts +3 -24
- package/dist/lib/cache/index.mjs +48 -23
- package/dist/lib/cron/index.cjs +117 -117
- package/dist/lib/cron/index.mjs +118 -118
- package/dist/lib/errors/index.d.cts +12 -1
- package/dist/lib/errors/index.d.mts +12 -1
- package/dist/lib/logging/index.cjs +1 -0
- package/dist/lib/orm/index.cjs +1642 -0
- package/dist/lib/orm/index.d.cts +402 -0
- package/dist/lib/orm/index.d.mts +402 -0
- package/dist/lib/orm/index.mjs +1630 -0
- package/dist/lib/prompts/index.cjs +89 -89
- package/dist/lib/prompts/index.d.cts +12 -33
- package/dist/lib/prompts/index.d.mts +12 -33
- package/dist/lib/prompts/index.mjs +89 -90
- package/dist/lib/pubsub/index.cjs +43 -19
- package/dist/lib/pubsub/index.d.cts +3 -18
- package/dist/lib/pubsub/index.d.mts +3 -18
- package/dist/lib/pubsub/index.mjs +44 -20
- package/dist/lib/queue/index.cjs +40 -10
- package/dist/lib/queue/index.d.cts +11 -4
- package/dist/lib/queue/index.d.mts +11 -4
- package/dist/lib/queue/index.mjs +39 -11
- package/dist/lib/workflow/index.cjs +285 -282
- package/dist/lib/workflow/index.d.cts +76 -11
- package/dist/lib/workflow/index.d.mts +76 -11
- package/dist/lib/workflow/index.mjs +278 -284
- package/package.json +11 -1
- package/dist/index-BhGNDjPq.d.mts +0 -13
- package/dist/index-DxSbeGP-.d.cts +0 -13
package/dist/lib/cache/index.mjs
CHANGED
|
@@ -1,4 +1,36 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { mightThrow, mightThrowSync } from "../errors/index.mjs";
|
|
2
|
+
//#region src/lib/cache/errors.ts
|
|
3
|
+
var CacheError = class extends Error {
|
|
4
|
+
constructor(message) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.name = "CacheError";
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
var InvalidTTLError = class extends Error {
|
|
10
|
+
constructor(message) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = "InvalidTTLError";
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
var NotFoundError = class extends Error {
|
|
16
|
+
constructor(message) {
|
|
17
|
+
super(message);
|
|
18
|
+
this.name = "NotFoundError";
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
var SerializationError = class extends Error {
|
|
22
|
+
constructor(message) {
|
|
23
|
+
super(message);
|
|
24
|
+
this.name = "SerializationError";
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
var DeserializationError = class extends Error {
|
|
28
|
+
constructor(message) {
|
|
29
|
+
super(message);
|
|
30
|
+
this.name = "DeserializationError";
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
//#endregion
|
|
2
34
|
//#region src/lib/cache/index.ts
|
|
3
35
|
var Cache = class {
|
|
4
36
|
options;
|
|
@@ -10,41 +42,34 @@ var Cache = class {
|
|
|
10
42
|
this.deserialize = options.deserializer ?? ((raw) => JSON.parse(raw));
|
|
11
43
|
}
|
|
12
44
|
async get(key) {
|
|
13
|
-
if (!this.isEnabled)
|
|
45
|
+
if (!this.isEnabled) throw new NotFoundError(`Key ${key} not found`);
|
|
14
46
|
const resolvedKey = this.resolveKey(key);
|
|
15
47
|
const [error, value] = await mightThrow(this.options.redis.get(resolvedKey));
|
|
16
|
-
if (error)
|
|
17
|
-
if (value === null || value === void 0)
|
|
48
|
+
if (error) throw new CacheError(`Unable to get value for key ${key}`);
|
|
49
|
+
if (value === null || value === void 0) throw new NotFoundError(`Key ${key} not found`);
|
|
18
50
|
const [deserializeErr, deserialized] = mightThrowSync(() => this.deserialize(value));
|
|
19
|
-
if (deserializeErr)
|
|
20
|
-
return
|
|
51
|
+
if (deserializeErr) throw new DeserializationError(`Unable to deserialize value for key ${key}`);
|
|
52
|
+
return deserialized;
|
|
21
53
|
}
|
|
22
54
|
async set(key, value) {
|
|
23
|
-
if (!this.isEnabled) return
|
|
55
|
+
if (!this.isEnabled) return value;
|
|
24
56
|
const [serializeErr, serialized] = mightThrowSync(() => this.serialize(value));
|
|
25
|
-
if (serializeErr)
|
|
26
|
-
if (serialized === null || serialized === void 0)
|
|
57
|
+
if (serializeErr) throw new SerializationError(`Unable to serialize value for key ${key}`);
|
|
58
|
+
if (serialized === null || serialized === void 0) throw new SerializationError(`Unable to serialize value for key ${key}`);
|
|
27
59
|
const [ttlErr, ttl] = mightThrowSync(() => this.resolveTTL(key, value));
|
|
28
|
-
if (ttlErr)
|
|
29
|
-
if (!this.isTTLValid(ttl))
|
|
60
|
+
if (ttlErr) throw new InvalidTTLError(`Unable to resolve ttl for key ${key}`);
|
|
61
|
+
if (!this.isTTLValid(ttl)) throw new InvalidTTLError(`Unable to save records with ttl equal to ${ttl}`);
|
|
30
62
|
const resolvedKey = this.resolveKey(key);
|
|
31
63
|
const [setError] = await mightThrow(this.getSetPromise(resolvedKey, serialized, ttl));
|
|
32
|
-
if (setError)
|
|
33
|
-
return
|
|
64
|
+
if (setError) throw new CacheError(`Unable to set value for key ${key}`);
|
|
65
|
+
return value;
|
|
34
66
|
}
|
|
35
67
|
async delete(key) {
|
|
36
|
-
if (!this.isEnabled) return
|
|
68
|
+
if (!this.isEnabled) return 0;
|
|
37
69
|
const resolvedKey = this.resolveKey(key);
|
|
38
70
|
const [error, data] = await mightThrow(this.options.redis.del(resolvedKey));
|
|
39
|
-
if (error)
|
|
40
|
-
return
|
|
41
|
-
}
|
|
42
|
-
fail(type, message) {
|
|
43
|
-
this.options.onError?.({
|
|
44
|
-
type,
|
|
45
|
-
message
|
|
46
|
-
});
|
|
47
|
-
return err(type, message);
|
|
71
|
+
if (error) throw new CacheError(`Unable to delete key ${key}`);
|
|
72
|
+
return data;
|
|
48
73
|
}
|
|
49
74
|
get isEnabled() {
|
|
50
75
|
return this.options.enabled !== false;
|
package/dist/lib/cron/index.cjs
CHANGED
|
@@ -185,6 +185,38 @@ const Month = {
|
|
|
185
185
|
dec: 12
|
|
186
186
|
};
|
|
187
187
|
//#endregion
|
|
188
|
+
//#region src/lib/cron/errors.ts
|
|
189
|
+
var InvalidValueError = class extends Error {
|
|
190
|
+
constructor(message) {
|
|
191
|
+
super(message);
|
|
192
|
+
this.name = "InvalidValueError";
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
var OutOfBoundError = class extends Error {
|
|
196
|
+
constructor(message) {
|
|
197
|
+
super(message);
|
|
198
|
+
this.name = "OutOfBoundError";
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
var CronExpressionError = class extends Error {
|
|
202
|
+
constructor(message) {
|
|
203
|
+
super(message);
|
|
204
|
+
this.name = "CronExpressionError";
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
var EmptyCronExpressionError = class extends Error {
|
|
208
|
+
constructor(message) {
|
|
209
|
+
super(message);
|
|
210
|
+
this.name = "EmptyCronExpressionError";
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
var CronLengthError = class extends Error {
|
|
214
|
+
constructor(message) {
|
|
215
|
+
super(message);
|
|
216
|
+
this.name = "CronLengthError";
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
//#endregion
|
|
188
220
|
//#region src/lib/cron/core/scanner.ts
|
|
189
221
|
const FieldAmount = {
|
|
190
222
|
min: 5,
|
|
@@ -237,21 +269,20 @@ var Scanner = class {
|
|
|
237
269
|
this.tokens = [];
|
|
238
270
|
}
|
|
239
271
|
scan() {
|
|
240
|
-
if (this.expression.length === 0)
|
|
272
|
+
if (this.expression.length === 0) throw new EmptyCronExpressionError("Cron expression have zero length");
|
|
241
273
|
const fields = this.expression.trim().split(/\s+/);
|
|
242
274
|
const hasMinLen = fields.length === FieldAmount.min;
|
|
243
275
|
const hasMaxLen = fields.length === FieldAmount.max;
|
|
244
|
-
if (!hasMinLen && !hasMaxLen)
|
|
276
|
+
if (!hasMinLen && !hasMaxLen) throw new CronLengthError(`Invalid number of fields for '${this.expression}'. Expected 5 or 6 fields but got ${fields.length} field(s)`);
|
|
245
277
|
const components = this.createComponent(fields);
|
|
246
278
|
for (let idx = 0; idx < components.length; idx++) {
|
|
247
279
|
const component = components[idx];
|
|
248
|
-
if (!component)
|
|
280
|
+
if (!component) throw new CronExpressionError(`Invalid cron expression: ${this.expression}`);
|
|
249
281
|
this.current = 0;
|
|
250
282
|
this.start = 0;
|
|
251
|
-
|
|
252
|
-
if (error) return require_lib_errors_index.err(error.type, error.message);
|
|
283
|
+
this.scanComponent(component);
|
|
253
284
|
}
|
|
254
|
-
return
|
|
285
|
+
return this.tokens;
|
|
255
286
|
}
|
|
256
287
|
scanComponent(component) {
|
|
257
288
|
const { field, content } = component;
|
|
@@ -260,36 +291,30 @@ var Scanner = class {
|
|
|
260
291
|
switch (currentCh) {
|
|
261
292
|
case "*": {
|
|
262
293
|
const ch = this.peek(content);
|
|
263
|
-
if (this.match(content, "/"))
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
} else if (!ch || ch === ",") this.addToken("*", "any", "*", field);
|
|
267
|
-
else return require_lib_errors_index.err("CronExpressionError", `Invalid any expression '${content}' for field '${field}'`);
|
|
294
|
+
if (this.match(content, "/")) this.handleStep(component);
|
|
295
|
+
else if (!ch || ch === ",") this.addToken("*", "any", "*", field);
|
|
296
|
+
else throw new CronExpressionError(`Invalid any expression '${content}' for field '${field}'`);
|
|
268
297
|
break;
|
|
269
298
|
}
|
|
270
299
|
case "-":
|
|
271
300
|
currentCh = this.advance(content);
|
|
272
|
-
if (this.isDigit(currentCh))
|
|
273
|
-
|
|
274
|
-
if (error) return require_lib_errors_index.err(error.type, error.message);
|
|
275
|
-
} else return require_lib_errors_index.err("CronExpressionError", `Invalid range expression '${content}' for field '${field}'`);
|
|
301
|
+
if (this.isDigit(currentCh)) this.handleRangeWithStep(component);
|
|
302
|
+
else throw new CronExpressionError(`Invalid range expression '${content}' for field '${field}'`);
|
|
276
303
|
break;
|
|
277
304
|
case ",": {
|
|
278
|
-
if (this.current === 1 && this.start === 0)
|
|
305
|
+
if (this.current === 1 && this.start === 0) throw new CronExpressionError(`Invalid list expression '${content}' for field '${field}'`);
|
|
279
306
|
const next = this.peek(content);
|
|
280
|
-
if (!next || next === ",")
|
|
307
|
+
if (!next || next === ",") throw new CronExpressionError(`Invalid list expression '${content}' for field '${field}'`);
|
|
281
308
|
break;
|
|
282
309
|
}
|
|
283
310
|
default:
|
|
284
|
-
if (this.isDigit(currentCh))
|
|
285
|
-
|
|
286
|
-
if (error) return require_lib_errors_index.err(error.type, error.message);
|
|
287
|
-
} else return require_lib_errors_index.err("CronExpressionError", `Invalid cron expression '${this.expression}' in field '${field}'`);
|
|
311
|
+
if (this.isDigit(currentCh)) this.handleNumber(component);
|
|
312
|
+
else throw new CronExpressionError(`Invalid cron expression '${this.expression}' in field '${field}'`);
|
|
288
313
|
break;
|
|
289
314
|
}
|
|
290
315
|
this.start = this.current;
|
|
291
316
|
}
|
|
292
|
-
return
|
|
317
|
+
return true;
|
|
293
318
|
}
|
|
294
319
|
addToken(component, type, value, field) {
|
|
295
320
|
const token = new Token(component, type, value, field);
|
|
@@ -318,12 +343,12 @@ var Scanner = class {
|
|
|
318
343
|
this.advance(content);
|
|
319
344
|
ch = this.peek(content);
|
|
320
345
|
}
|
|
321
|
-
if (ch && ch !== ",")
|
|
346
|
+
if (ch && ch !== ",") throw new CronExpressionError(`Invalid step expression '${content}' for field '${field}'`);
|
|
322
347
|
const tokenContent = content.substring(this.start, this.current);
|
|
323
348
|
const value = content.slice(slashIdx + 1, this.current);
|
|
324
|
-
if (value.length === 0)
|
|
349
|
+
if (value.length === 0) throw new CronExpressionError(`Invalid step expression '${content}' for field '${field}'`);
|
|
325
350
|
this.addToken(tokenContent, "step", Number(value), field);
|
|
326
|
-
return
|
|
351
|
+
return true;
|
|
327
352
|
}
|
|
328
353
|
handleRangeWithStep(component) {
|
|
329
354
|
const { field, content } = component;
|
|
@@ -332,13 +357,12 @@ var Scanner = class {
|
|
|
332
357
|
this.advance(content);
|
|
333
358
|
ch = this.peek(content);
|
|
334
359
|
}
|
|
335
|
-
if (!ch)
|
|
360
|
+
if (!ch) throw new CronExpressionError(`Invalid range expression '${content}' for field '${field}'`);
|
|
336
361
|
if (this.match(content, "/")) {
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
return require_lib_errors_index.ok(true);
|
|
362
|
+
this.handleStep(component);
|
|
363
|
+
return true;
|
|
340
364
|
}
|
|
341
|
-
|
|
365
|
+
throw new CronExpressionError(`Invalid range expression '${content}' for field '${field}'`);
|
|
342
366
|
}
|
|
343
367
|
handleNumber(component) {
|
|
344
368
|
const { field, content } = component;
|
|
@@ -351,27 +375,25 @@ var Scanner = class {
|
|
|
351
375
|
if (!ch) {
|
|
352
376
|
const item = content.substring(this.start);
|
|
353
377
|
this.addToken(item, "number", Number(item), field);
|
|
354
|
-
return
|
|
378
|
+
return true;
|
|
355
379
|
}
|
|
356
380
|
if (this.match(content, "-")) {
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
return require_lib_errors_index.ok(true);
|
|
381
|
+
this.handleRange(component);
|
|
382
|
+
return true;
|
|
360
383
|
}
|
|
361
384
|
if (this.match(content, "/")) {
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
return require_lib_errors_index.ok(true);
|
|
385
|
+
this.handleStep(component);
|
|
386
|
+
return true;
|
|
365
387
|
}
|
|
366
|
-
if (!this.isDigit(ch) && ch !== ",")
|
|
388
|
+
if (!this.isDigit(ch) && ch !== ",") throw new CronExpressionError(`Invalid number '${content}' for field '${field}'`);
|
|
367
389
|
const item = content.substring(this.start, this.current);
|
|
368
390
|
this.addToken(item, "number", Number(item), field);
|
|
369
|
-
return
|
|
391
|
+
return true;
|
|
370
392
|
}
|
|
371
393
|
handleRange(component) {
|
|
372
394
|
const { field, content } = component;
|
|
373
395
|
let ch = this.peek(content);
|
|
374
|
-
if (!ch)
|
|
396
|
+
if (!ch) throw new CronExpressionError(`Invalid range expression '${content}' for field '${field}'`);
|
|
375
397
|
while (ch && this.isDigit(ch)) {
|
|
376
398
|
this.advance(content);
|
|
377
399
|
ch = this.peek(content);
|
|
@@ -379,17 +401,16 @@ var Scanner = class {
|
|
|
379
401
|
if (!ch) {
|
|
380
402
|
const tokenContent = content.substring(this.start);
|
|
381
403
|
this.addToken(tokenContent, "range", tokenContent, field);
|
|
382
|
-
return
|
|
404
|
+
return true;
|
|
383
405
|
}
|
|
384
406
|
if (this.match(content, "/")) {
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
return require_lib_errors_index.ok(true);
|
|
407
|
+
this.handleStep(component);
|
|
408
|
+
return true;
|
|
388
409
|
}
|
|
389
|
-
if (ch && ch !== ",")
|
|
410
|
+
if (ch && ch !== ",") throw new CronExpressionError(`Invalid range expression '${content}' for field '${field}'`);
|
|
390
411
|
const tokenContent = content.substring(this.start, this.current);
|
|
391
412
|
this.addToken(tokenContent, "range", tokenContent, field);
|
|
392
|
-
return
|
|
413
|
+
return true;
|
|
393
414
|
}
|
|
394
415
|
isDigit(ch) {
|
|
395
416
|
return ch >= "0" && ch <= "9";
|
|
@@ -472,70 +493,67 @@ var Cron = class {
|
|
|
472
493
|
}
|
|
473
494
|
handleStep(part, values, min, max) {
|
|
474
495
|
const [rangePart, stepStr] = part.split("/");
|
|
475
|
-
if (!rangePart)
|
|
476
|
-
if (!stepStr)
|
|
496
|
+
if (!rangePart) throw new InvalidValueError(`'${rangePart}' is empty`);
|
|
497
|
+
if (!stepStr) throw new InvalidValueError(`'${stepStr}' is empty`);
|
|
477
498
|
const step = Number(stepStr);
|
|
478
|
-
if (!Number.isInteger(step))
|
|
479
|
-
if (step <= 0)
|
|
499
|
+
if (!Number.isInteger(step)) throw new InvalidValueError(`'${step}' is not a valid number`);
|
|
500
|
+
if (step <= 0) throw new OutOfBoundError(`Expected ${step} > 0`);
|
|
480
501
|
if (rangePart === "*") {
|
|
481
502
|
for (let i = min; i <= max; i += step) values[i] = 1;
|
|
482
|
-
return
|
|
503
|
+
return;
|
|
483
504
|
}
|
|
484
|
-
if (rangePart.includes("-"))
|
|
485
|
-
|
|
505
|
+
if (rangePart.includes("-")) {
|
|
506
|
+
this.handleStepRange(rangePart, step, values, min, max);
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
this.handleStepSingle(rangePart, step, values, min, max);
|
|
486
510
|
}
|
|
487
511
|
handleStepRange(range, step, values, min, max) {
|
|
488
512
|
const [startStr, endStr] = range.split("-");
|
|
489
|
-
if (!endStr)
|
|
513
|
+
if (!endStr) throw new InvalidValueError(`'${endStr}' is empty`);
|
|
490
514
|
let start = min;
|
|
491
515
|
if (startStr && startStr.length > 0) start = Number(startStr);
|
|
492
516
|
const end = Number(endStr);
|
|
493
|
-
if (!Number.isInteger(start))
|
|
494
|
-
if (!Number.isInteger(end))
|
|
495
|
-
if (start < min)
|
|
496
|
-
if (end > max)
|
|
497
|
-
if (start > end)
|
|
517
|
+
if (!Number.isInteger(start)) throw new InvalidValueError(`'${start}' is not a valid number`);
|
|
518
|
+
if (!Number.isInteger(end)) throw new InvalidValueError(`'${end}' is not a valid number`);
|
|
519
|
+
if (start < min) throw new OutOfBoundError(`Expected ${start} >= ${min}`);
|
|
520
|
+
if (end > max) throw new OutOfBoundError(`Expected ${end} <= ${max}`);
|
|
521
|
+
if (start > end) throw new OutOfBoundError(`Expected ${start} <= ${end}`);
|
|
498
522
|
for (let i = start; i <= end; i += step) values[i] = 1;
|
|
499
|
-
return require_lib_errors_index.ok(true);
|
|
500
523
|
}
|
|
501
524
|
handleStepSingle(value, step, values, min, max) {
|
|
502
525
|
const start = Number(value);
|
|
503
|
-
if (!Number.isInteger(start))
|
|
504
|
-
if (start < min)
|
|
505
|
-
if (start > max)
|
|
526
|
+
if (!Number.isInteger(start)) throw new InvalidValueError(`'${start}' is not a valid number`);
|
|
527
|
+
if (start < min) throw new OutOfBoundError(`Expected ${start} >= ${min}`);
|
|
528
|
+
if (start > max) throw new OutOfBoundError(`Expected ${start} <= ${max}`);
|
|
506
529
|
for (let i = start; i <= max; i += step) values[i] = 1;
|
|
507
|
-
return require_lib_errors_index.ok(true);
|
|
508
530
|
}
|
|
509
531
|
handleRange(part, values, min, max) {
|
|
510
532
|
const [startStr, endStr] = part.split("-");
|
|
511
|
-
if (!startStr)
|
|
512
|
-
if (!endStr)
|
|
533
|
+
if (!startStr) throw new InvalidValueError(`'${startStr}' is empty`);
|
|
534
|
+
if (!endStr) throw new InvalidValueError(`'${endStr}' is empty`);
|
|
513
535
|
const start = Number(startStr);
|
|
514
536
|
const end = Number(endStr);
|
|
515
|
-
if (!Number.isInteger(start))
|
|
516
|
-
if (!Number.isInteger(end))
|
|
517
|
-
if (start < min)
|
|
518
|
-
if (end > max)
|
|
519
|
-
if (start > end)
|
|
537
|
+
if (!Number.isInteger(start)) throw new InvalidValueError(`'${start}' is not a valid number`);
|
|
538
|
+
if (!Number.isInteger(end)) throw new InvalidValueError(`'${end}' is not a valid number`);
|
|
539
|
+
if (start < min) throw new OutOfBoundError(`Expected ${start} >= ${min}`);
|
|
540
|
+
if (end > max) throw new OutOfBoundError(`Expected ${end} <= ${max}`);
|
|
541
|
+
if (start > end) throw new OutOfBoundError(`Expected ${start} <= ${end}`);
|
|
520
542
|
for (let i = start; i <= end; i++) values[i] = 1;
|
|
521
|
-
return require_lib_errors_index.ok(true);
|
|
522
543
|
}
|
|
523
544
|
handleNumber(value, values, min, max) {
|
|
524
545
|
const n = Number(value);
|
|
525
|
-
if (!Number.isInteger(n))
|
|
526
|
-
if (n < min)
|
|
527
|
-
if (n > max)
|
|
546
|
+
if (!Number.isInteger(n)) throw new InvalidValueError(`'${value}' is not a valid number`);
|
|
547
|
+
if (n < min) throw new OutOfBoundError(`Expected ${n} >= ${min}`);
|
|
548
|
+
if (n > max) throw new OutOfBoundError(`Expected ${n} <= ${max}`);
|
|
528
549
|
values[n] = 1;
|
|
529
|
-
return require_lib_errors_index.ok(true);
|
|
530
550
|
}
|
|
531
551
|
constructor(options) {
|
|
532
552
|
this.options = options;
|
|
533
553
|
const expr = this.resolveAlias(options.schedule);
|
|
534
|
-
const
|
|
535
|
-
if (error) throw new Error(`${error.type}: ${error.message}`);
|
|
554
|
+
const tokens = new Scanner(expr).scan();
|
|
536
555
|
this.hasSeconds = expr.trim().split(/\s+/).length === FieldAmount.max;
|
|
537
|
-
|
|
538
|
-
if (parsingError) throw new Error(`${parsingError.type}: ${parsingError.message}`);
|
|
556
|
+
this.parse(tokens);
|
|
539
557
|
}
|
|
540
558
|
resolveAlias(schedule) {
|
|
541
559
|
return ALIASES[schedule] || schedule;
|
|
@@ -543,71 +561,53 @@ var Cron = class {
|
|
|
543
561
|
parse(tokens) {
|
|
544
562
|
for (let i = 0; i < tokens.length; i++) {
|
|
545
563
|
const token = tokens[i];
|
|
546
|
-
if (!token)
|
|
564
|
+
if (!token) throw new InvalidValueError("Undefined token");
|
|
547
565
|
const tokenType = token.getTokenType();
|
|
548
566
|
switch (token.getField()) {
|
|
549
|
-
case "second":
|
|
550
|
-
|
|
551
|
-
if (error) return require_lib_errors_index.err(error.type, `${error.message} in field '${token.getField()}'`);
|
|
567
|
+
case "second":
|
|
568
|
+
this.handleField(token, this.second, CronSecondRange.min, CronSecondRange.max);
|
|
552
569
|
break;
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
const [error, _] = this.handleField(token, this.minute, CronMinuteRange.min, CronMinuteRange.max);
|
|
556
|
-
if (error) return require_lib_errors_index.err(error.type, `${error.message} in field '${token.getField()}'`);
|
|
570
|
+
case "minute":
|
|
571
|
+
this.handleField(token, this.minute, CronMinuteRange.min, CronMinuteRange.max);
|
|
557
572
|
break;
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
const [error, _] = this.handleField(token, this.hour, CronHourRange.min, CronHourRange.max);
|
|
561
|
-
if (error) return require_lib_errors_index.err(error.type, `${error.message} in field '${token.getField()}'`);
|
|
573
|
+
case "hour":
|
|
574
|
+
this.handleField(token, this.hour, CronHourRange.min, CronHourRange.max);
|
|
562
575
|
break;
|
|
563
|
-
|
|
564
|
-
case "day": {
|
|
576
|
+
case "day":
|
|
565
577
|
if (tokenType === "any") this._dayWildcard = true;
|
|
566
|
-
|
|
567
|
-
if (error) return require_lib_errors_index.err(error.type, `${error.message} in field '${token.getField()}'`);
|
|
578
|
+
this.handleField(token, this.day, CronDayRange.min, CronDayRange.max);
|
|
568
579
|
break;
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
const [error, _] = this.handleField(token, this.month, CronMonthRange.min, CronMonthRange.max);
|
|
572
|
-
if (error) return require_lib_errors_index.err(error.type, `${error.message} in field '${token.getField()}'`);
|
|
580
|
+
case "month":
|
|
581
|
+
this.handleField(token, this.month, CronMonthRange.min, CronMonthRange.max);
|
|
573
582
|
break;
|
|
574
|
-
|
|
575
|
-
case "weekday": {
|
|
583
|
+
case "weekday":
|
|
576
584
|
if (tokenType === "any") this._dowWildcard = true;
|
|
577
|
-
|
|
578
|
-
if (error) return require_lib_errors_index.err(error.type, `${error.message} in field '${token.getField()}'`);
|
|
585
|
+
this.handleField(token, this.dayOfWeek, CronDayOfWeekRange.min, CronDayOfWeekRange.max);
|
|
579
586
|
break;
|
|
580
|
-
}
|
|
581
|
-
default: return require_lib_errors_index.err("InvalidValueError", `Invalid field '${token.getField()}'`);
|
|
587
|
+
default: throw new InvalidValueError(`Invalid field '${token.getField()}'`);
|
|
582
588
|
}
|
|
583
589
|
}
|
|
584
|
-
return require_lib_errors_index.ok(true);
|
|
585
590
|
}
|
|
586
591
|
handleField(token, field, min, max) {
|
|
587
592
|
switch (token.getTokenType()) {
|
|
588
593
|
case "any":
|
|
589
594
|
this.fillRange(field, min, max);
|
|
590
595
|
break;
|
|
591
|
-
case "number":
|
|
592
|
-
|
|
593
|
-
if (error) return require_lib_errors_index.err(error.type, error.message);
|
|
596
|
+
case "number":
|
|
597
|
+
this.handleNumber(token.getComponent(), field, min, max);
|
|
594
598
|
break;
|
|
595
|
-
}
|
|
596
599
|
case "range": {
|
|
597
600
|
const component = token.getComponent();
|
|
598
|
-
|
|
599
|
-
if (error) return require_lib_errors_index.err(error.type, error.message);
|
|
601
|
+
this.handleRange(component, field, min, max);
|
|
600
602
|
break;
|
|
601
603
|
}
|
|
602
604
|
case "step": {
|
|
603
605
|
const component = token.getComponent();
|
|
604
|
-
|
|
605
|
-
if (error) return require_lib_errors_index.err(error.type, error.message);
|
|
606
|
+
this.handleStep(component, field, min, max);
|
|
606
607
|
break;
|
|
607
608
|
}
|
|
608
|
-
default:
|
|
609
|
+
default: throw new InvalidValueError(`Invalid token type '${token.getTokenType()}'`);
|
|
609
610
|
}
|
|
610
|
-
return require_lib_errors_index.ok(true);
|
|
611
611
|
}
|
|
612
612
|
matches(date) {
|
|
613
613
|
const s = date.getSeconds();
|