semola 0.5.3 → 0.5.4
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/index-BhGNDjPq.d.mts +13 -0
- package/dist/index-DxSbeGP-.d.cts +13 -0
- package/dist/lib/api/index.cjs +522 -4
- package/dist/lib/api/index.d.cts +270 -4
- package/dist/lib/api/index.d.mts +270 -4
- package/dist/lib/api/index.mjs +520 -2
- package/dist/lib/cache/index.d.cts +16 -4
- package/dist/lib/cache/index.d.mts +16 -4
- package/dist/lib/cache/index.mjs +0 -2
- package/dist/lib/cron/index.cjs +734 -12
- package/dist/lib/cron/index.d.cts +145 -3
- package/dist/lib/cron/index.d.mts +145 -3
- package/dist/lib/cron/index.mjs +725 -3
- package/dist/lib/errors/index.d.cts +2 -13
- package/dist/lib/errors/index.d.mts +2 -13
- package/dist/lib/errors/index.mjs +0 -2
- package/dist/lib/i18n/index.d.cts +12 -4
- package/dist/lib/i18n/index.d.mts +12 -4
- package/dist/lib/i18n/index.mjs +0 -2
- package/dist/lib/logging/index.cjs +386 -17
- package/dist/lib/logging/index.d.cts +107 -6
- package/dist/lib/logging/index.d.mts +107 -6
- package/dist/lib/logging/index.mjs +373 -4
- package/dist/lib/policy/index.cjs +206 -20
- package/dist/lib/policy/index.d.cts +61 -5
- package/dist/lib/policy/index.d.mts +61 -5
- package/dist/lib/policy/index.mjs +187 -3
- package/dist/lib/prompts/index.cjs +374 -14
- package/dist/lib/prompts/index.d.cts +69 -4
- package/dist/lib/prompts/index.d.mts +69 -4
- package/dist/lib/prompts/index.mjs +362 -4
- package/dist/lib/pubsub/index.d.cts +9 -4
- package/dist/lib/pubsub/index.d.mts +9 -4
- package/dist/lib/pubsub/index.mjs +0 -2
- package/dist/lib/queue/index.d.cts +48 -6
- package/dist/lib/queue/index.d.mts +48 -6
- package/dist/lib/queue/index.mjs +0 -2
- package/dist/lib/workflow/index.d.cts +82 -4
- package/dist/lib/workflow/index.d.mts +82 -4
- package/dist/lib/workflow/index.mjs +0 -2
- package/package.json +1 -1
- package/dist/api/core/index.cjs +0 -206
- package/dist/api/core/index.d.cts +0 -21
- package/dist/api/core/index.d.cts.map +0 -1
- package/dist/api/core/index.d.mts +0 -21
- package/dist/api/core/index.d.mts.map +0 -1
- package/dist/api/core/index.mjs +0 -208
- package/dist/api/core/index.mjs.map +0 -1
- package/dist/api/core/types.d.cts +0 -107
- package/dist/api/core/types.d.cts.map +0 -1
- package/dist/api/core/types.d.mts +0 -107
- package/dist/api/core/types.d.mts.map +0 -1
- package/dist/api/middleware/index.cjs +0 -8
- package/dist/api/middleware/index.d.cts +0 -11
- package/dist/api/middleware/index.d.cts.map +0 -1
- package/dist/api/middleware/index.d.mts +0 -11
- package/dist/api/middleware/index.d.mts.map +0 -1
- package/dist/api/middleware/index.mjs +0 -10
- package/dist/api/middleware/index.mjs.map +0 -1
- package/dist/api/middleware/types.d.cts +0 -16
- package/dist/api/middleware/types.d.cts.map +0 -1
- package/dist/api/middleware/types.d.mts +0 -16
- package/dist/api/middleware/types.d.mts.map +0 -1
- package/dist/api/openapi/index.cjs +0 -254
- package/dist/api/openapi/index.mjs +0 -256
- package/dist/api/openapi/index.mjs.map +0 -1
- package/dist/api/openapi/types.d.cts +0 -60
- package/dist/api/openapi/types.d.cts.map +0 -1
- package/dist/api/openapi/types.d.mts +0 -60
- package/dist/api/openapi/types.d.mts.map +0 -1
- package/dist/api/validation/index.cjs +0 -64
- package/dist/api/validation/index.mjs +0 -61
- package/dist/api/validation/index.mjs.map +0 -1
- package/dist/cache/types.d.cts +0 -17
- package/dist/cache/types.d.cts.map +0 -1
- package/dist/cache/types.d.mts +0 -17
- package/dist/cache/types.d.mts.map +0 -1
- package/dist/cron/builder/index.cjs +0 -166
- package/dist/cron/builder/index.d.cts +0 -28
- package/dist/cron/builder/index.d.cts.map +0 -1
- package/dist/cron/builder/index.d.mts +0 -28
- package/dist/cron/builder/index.d.mts.map +0 -1
- package/dist/cron/builder/index.mjs +0 -163
- package/dist/cron/builder/index.mjs.map +0 -1
- package/dist/cron/builder/types.cjs +0 -27
- package/dist/cron/builder/types.d.cts +0 -79
- package/dist/cron/builder/types.d.cts.map +0 -1
- package/dist/cron/builder/types.d.mts +0 -79
- package/dist/cron/builder/types.d.mts.map +0 -1
- package/dist/cron/builder/types.mjs +0 -28
- package/dist/cron/builder/types.mjs.map +0 -1
- package/dist/cron/core/index.cjs +0 -308
- package/dist/cron/core/index.d.cts +0 -39
- package/dist/cron/core/index.d.cts.map +0 -1
- package/dist/cron/core/index.d.mts +0 -39
- package/dist/cron/core/index.d.mts.map +0 -1
- package/dist/cron/core/index.mjs +0 -310
- package/dist/cron/core/index.mjs.map +0 -1
- package/dist/cron/core/scanner.cjs +0 -237
- package/dist/cron/core/scanner.mjs +0 -238
- package/dist/cron/core/scanner.mjs.map +0 -1
- package/dist/cron/core/types.d.cts +0 -11
- package/dist/cron/core/types.d.cts.map +0 -1
- package/dist/cron/core/types.d.mts +0 -11
- package/dist/cron/core/types.d.mts.map +0 -1
- package/dist/errors/types.d.cts +0 -5
- package/dist/errors/types.d.cts.map +0 -1
- package/dist/errors/types.d.mts +0 -5
- package/dist/errors/types.d.mts.map +0 -1
- package/dist/i18n/types.d.cts +0 -13
- package/dist/i18n/types.d.cts.map +0 -1
- package/dist/i18n/types.d.mts +0 -13
- package/dist/i18n/types.d.mts.map +0 -1
- package/dist/lib/cache/index.d.cts.map +0 -1
- package/dist/lib/cache/index.d.mts.map +0 -1
- package/dist/lib/cache/index.mjs.map +0 -1
- package/dist/lib/errors/index.d.cts.map +0 -1
- package/dist/lib/errors/index.d.mts.map +0 -1
- package/dist/lib/errors/index.mjs.map +0 -1
- package/dist/lib/i18n/index.d.cts.map +0 -1
- package/dist/lib/i18n/index.d.mts.map +0 -1
- package/dist/lib/i18n/index.mjs.map +0 -1
- package/dist/lib/orm/index.cjs +0 -20
- package/dist/lib/orm/index.d.cts +0 -7
- package/dist/lib/orm/index.d.mts +0 -7
- package/dist/lib/orm/index.mjs +0 -6
- package/dist/lib/policy/index.d.cts.map +0 -1
- package/dist/lib/policy/index.d.mts.map +0 -1
- package/dist/lib/policy/index.mjs.map +0 -1
- package/dist/lib/prompts/index.d.cts.map +0 -1
- package/dist/lib/prompts/index.d.mts.map +0 -1
- package/dist/lib/prompts/index.mjs.map +0 -1
- package/dist/lib/pubsub/index.d.cts.map +0 -1
- package/dist/lib/pubsub/index.d.mts.map +0 -1
- package/dist/lib/pubsub/index.mjs.map +0 -1
- package/dist/lib/queue/index.d.cts.map +0 -1
- package/dist/lib/queue/index.d.mts.map +0 -1
- package/dist/lib/queue/index.mjs.map +0 -1
- package/dist/lib/workflow/index.d.cts.map +0 -1
- package/dist/lib/workflow/index.d.mts.map +0 -1
- package/dist/lib/workflow/index.mjs.map +0 -1
- package/dist/logging/core/index.cjs +0 -99
- package/dist/logging/core/index.d.cts +0 -26
- package/dist/logging/core/index.d.cts.map +0 -1
- package/dist/logging/core/index.d.mts +0 -26
- package/dist/logging/core/index.d.mts.map +0 -1
- package/dist/logging/core/index.mjs +0 -99
- package/dist/logging/core/index.mjs.map +0 -1
- package/dist/logging/core/types.cjs +0 -10
- package/dist/logging/core/types.d.cts +0 -22
- package/dist/logging/core/types.d.cts.map +0 -1
- package/dist/logging/core/types.d.mts +0 -22
- package/dist/logging/core/types.d.mts.map +0 -1
- package/dist/logging/core/types.mjs +0 -12
- package/dist/logging/core/types.mjs.map +0 -1
- package/dist/logging/formatter/index.cjs +0 -119
- package/dist/logging/formatter/index.d.cts +0 -27
- package/dist/logging/formatter/index.d.cts.map +0 -1
- package/dist/logging/formatter/index.d.mts +0 -27
- package/dist/logging/formatter/index.d.mts.map +0 -1
- package/dist/logging/formatter/index.mjs +0 -115
- package/dist/logging/formatter/index.mjs.map +0 -1
- package/dist/logging/formatter/types.d.cts +0 -5
- package/dist/logging/formatter/types.d.cts.map +0 -1
- package/dist/logging/formatter/types.d.mts +0 -5
- package/dist/logging/formatter/types.d.mts.map +0 -1
- package/dist/logging/provider/index.cjs +0 -165
- package/dist/logging/provider/index.d.cts +0 -28
- package/dist/logging/provider/index.d.cts.map +0 -1
- package/dist/logging/provider/index.d.mts +0 -28
- package/dist/logging/provider/index.d.mts.map +0 -1
- package/dist/logging/provider/index.mjs +0 -165
- package/dist/logging/provider/index.mjs.map +0 -1
- package/dist/logging/provider/types.d.cts +0 -23
- package/dist/logging/provider/types.d.cts.map +0 -1
- package/dist/logging/provider/types.d.mts +0 -23
- package/dist/logging/provider/types.d.mts.map +0 -1
- package/dist/node_modules/@standard-schema/spec/dist/index.d.cts +0 -80
- package/dist/node_modules/@standard-schema/spec/dist/index.d.cts.map +0 -1
- package/dist/node_modules/@standard-schema/spec/dist/index.d.mts +0 -80
- package/dist/node_modules/@standard-schema/spec/dist/index.d.mts.map +0 -1
- package/dist/orm/column.cjs +0 -137
- package/dist/orm/column.d.cts +0 -121
- package/dist/orm/column.d.cts.map +0 -1
- package/dist/orm/column.d.mts +0 -121
- package/dist/orm/column.d.mts.map +0 -1
- package/dist/orm/column.mjs +0 -132
- package/dist/orm/column.mjs.map +0 -1
- package/dist/orm/dialect/index.cjs +0 -14
- package/dist/orm/dialect/index.mjs +0 -16
- package/dist/orm/dialect/index.mjs.map +0 -1
- package/dist/orm/dialect/mysql.cjs +0 -31
- package/dist/orm/dialect/mysql.mjs +0 -33
- package/dist/orm/dialect/mysql.mjs.map +0 -1
- package/dist/orm/dialect/postgres.cjs +0 -23
- package/dist/orm/dialect/postgres.mjs +0 -25
- package/dist/orm/dialect/postgres.mjs.map +0 -1
- package/dist/orm/dialect/sqlite.cjs +0 -31
- package/dist/orm/dialect/sqlite.mjs +0 -33
- package/dist/orm/dialect/sqlite.mjs.map +0 -1
- package/dist/orm/dialect/utils.cjs +0 -8
- package/dist/orm/dialect/utils.mjs +0 -10
- package/dist/orm/dialect/utils.mjs.map +0 -1
- package/dist/orm/internal/table-columns.cjs +0 -31
- package/dist/orm/internal/table-columns.mjs +0 -32
- package/dist/orm/internal/table-columns.mjs.map +0 -1
- package/dist/orm/internal/table-lookup.cjs +0 -35
- package/dist/orm/internal/table-lookup.mjs +0 -35
- package/dist/orm/internal/table-lookup.mjs.map +0 -1
- package/dist/orm/internal/table-relations.cjs +0 -28
- package/dist/orm/internal/table-relations.mjs +0 -29
- package/dist/orm/internal/table-relations.mjs.map +0 -1
- package/dist/orm/migration/config.cjs +0 -7
- package/dist/orm/migration/config.d.cts +0 -7
- package/dist/orm/migration/config.d.cts.map +0 -1
- package/dist/orm/migration/config.d.mts +0 -7
- package/dist/orm/migration/config.d.mts.map +0 -1
- package/dist/orm/migration/config.mjs +0 -8
- package/dist/orm/migration/config.mjs.map +0 -1
- package/dist/orm/migration/types.d.cts +0 -20
- package/dist/orm/migration/types.d.cts.map +0 -1
- package/dist/orm/migration/types.d.mts +0 -20
- package/dist/orm/migration/types.d.mts.map +0 -1
- package/dist/orm/orm.cjs +0 -41
- package/dist/orm/orm.d.cts +0 -18
- package/dist/orm/orm.d.cts.map +0 -1
- package/dist/orm/orm.d.mts +0 -18
- package/dist/orm/orm.d.mts.map +0 -1
- package/dist/orm/orm.mjs +0 -43
- package/dist/orm/orm.mjs.map +0 -1
- package/dist/orm/relation.cjs +0 -18
- package/dist/orm/relation.d.cts +0 -8
- package/dist/orm/relation.d.cts.map +0 -1
- package/dist/orm/relation.d.mts +0 -8
- package/dist/orm/relation.d.mts.map +0 -1
- package/dist/orm/relation.mjs +0 -19
- package/dist/orm/relation.mjs.map +0 -1
- package/dist/orm/runtime/builders/mutations.cjs +0 -29
- package/dist/orm/runtime/builders/mutations.mjs +0 -28
- package/dist/orm/runtime/builders/mutations.mjs.map +0 -1
- package/dist/orm/runtime/builders/select.cjs +0 -18
- package/dist/orm/runtime/builders/select.mjs +0 -19
- package/dist/orm/runtime/builders/select.mjs.map +0 -1
- package/dist/orm/runtime/client.cjs +0 -90
- package/dist/orm/runtime/client.mjs +0 -92
- package/dist/orm/runtime/client.mjs.map +0 -1
- package/dist/orm/runtime/context.cjs +0 -49
- package/dist/orm/runtime/context.mjs +0 -51
- package/dist/orm/runtime/context.mjs.map +0 -1
- package/dist/orm/runtime/dialect/index.cjs +0 -11
- package/dist/orm/runtime/dialect/index.mjs +0 -13
- package/dist/orm/runtime/dialect/index.mjs.map +0 -1
- package/dist/orm/runtime/dialect/mysql.cjs +0 -95
- package/dist/orm/runtime/dialect/mysql.mjs +0 -97
- package/dist/orm/runtime/dialect/mysql.mjs.map +0 -1
- package/dist/orm/runtime/dialect/postgres.cjs +0 -51
- package/dist/orm/runtime/dialect/postgres.mjs +0 -53
- package/dist/orm/runtime/dialect/postgres.mjs.map +0 -1
- package/dist/orm/runtime/dialect/sqlite.cjs +0 -4
- package/dist/orm/runtime/dialect/sqlite.mjs +0 -7
- package/dist/orm/runtime/dialect/sqlite.mjs.map +0 -1
- package/dist/orm/runtime/errors.cjs +0 -19
- package/dist/orm/runtime/errors.mjs +0 -21
- package/dist/orm/runtime/errors.mjs.map +0 -1
- package/dist/orm/runtime/hydrate/many.cjs +0 -46
- package/dist/orm/runtime/hydrate/many.mjs +0 -48
- package/dist/orm/runtime/hydrate/many.mjs.map +0 -1
- package/dist/orm/runtime/hydrate/one.cjs +0 -38
- package/dist/orm/runtime/hydrate/one.mjs +0 -40
- package/dist/orm/runtime/hydrate/one.mjs.map +0 -1
- package/dist/orm/runtime/hydrate.cjs +0 -49
- package/dist/orm/runtime/hydrate.mjs +0 -51
- package/dist/orm/runtime/hydrate.mjs.map +0 -1
- package/dist/orm/runtime/rows.cjs +0 -30
- package/dist/orm/runtime/rows.mjs +0 -31
- package/dist/orm/runtime/rows.mjs.map +0 -1
- package/dist/orm/runtime/utils.cjs +0 -27
- package/dist/orm/runtime/utils.mjs +0 -27
- package/dist/orm/runtime/utils.mjs.map +0 -1
- package/dist/orm/sql/parse-array.cjs +0 -64
- package/dist/orm/sql/parse-array.mjs +0 -66
- package/dist/orm/sql/parse-array.mjs.map +0 -1
- package/dist/orm/sql/plan/select.cjs +0 -36
- package/dist/orm/sql/plan/select.mjs +0 -38
- package/dist/orm/sql/plan/select.mjs.map +0 -1
- package/dist/orm/sql/plan/where/operators.cjs +0 -95
- package/dist/orm/sql/plan/where/operators.mjs +0 -97
- package/dist/orm/sql/plan/where/operators.mjs.map +0 -1
- package/dist/orm/sql/plan/where.cjs +0 -59
- package/dist/orm/sql/plan/where.mjs +0 -61
- package/dist/orm/sql/plan/where.mjs.map +0 -1
- package/dist/orm/sql/serialize/clauses.cjs +0 -36
- package/dist/orm/sql/serialize/clauses.mjs +0 -37
- package/dist/orm/sql/serialize/clauses.mjs.map +0 -1
- package/dist/orm/sql/serialize/joins.cjs +0 -31
- package/dist/orm/sql/serialize/joins.mjs +0 -33
- package/dist/orm/sql/serialize/joins.mjs.map +0 -1
- package/dist/orm/sql/serialize/values.cjs +0 -30
- package/dist/orm/sql/serialize/values.mjs +0 -32
- package/dist/orm/sql/serialize/values.mjs.map +0 -1
- package/dist/orm/sql/serialize/where/predicate.cjs +0 -73
- package/dist/orm/sql/serialize/where/predicate.mjs +0 -75
- package/dist/orm/sql/serialize/where/predicate.mjs.map +0 -1
- package/dist/orm/sql/serialize/where/tree.cjs +0 -26
- package/dist/orm/sql/serialize/where/tree.mjs +0 -28
- package/dist/orm/sql/serialize/where/tree.mjs.map +0 -1
- package/dist/orm/sql/serialize/where.cjs +0 -10
- package/dist/orm/sql/serialize/where.mjs +0 -12
- package/dist/orm/sql/serialize/where.mjs.map +0 -1
- package/dist/orm/sql/serialize.cjs +0 -24
- package/dist/orm/sql/serialize.mjs +0 -25
- package/dist/orm/sql/serialize.mjs.map +0 -1
- package/dist/orm/table.cjs +0 -12
- package/dist/orm/table.d.cts +0 -12
- package/dist/orm/table.d.cts.map +0 -1
- package/dist/orm/table.d.mts +0 -12
- package/dist/orm/table.d.mts.map +0 -1
- package/dist/orm/table.mjs +0 -14
- package/dist/orm/table.mjs.map +0 -1
- package/dist/orm/types.d.cts +0 -183
- package/dist/orm/types.d.cts.map +0 -1
- package/dist/orm/types.d.mts +0 -183
- package/dist/orm/types.d.mts.map +0 -1
- package/dist/policy/helpers.cjs +0 -206
- package/dist/policy/helpers.d.cts +0 -50
- package/dist/policy/helpers.d.cts.map +0 -1
- package/dist/policy/helpers.d.mts +0 -50
- package/dist/policy/helpers.d.mts.map +0 -1
- package/dist/policy/helpers.mjs +0 -190
- package/dist/policy/helpers.mjs.map +0 -1
- package/dist/policy/types.d.cts +0 -16
- package/dist/policy/types.d.cts.map +0 -1
- package/dist/policy/types.d.mts +0 -16
- package/dist/policy/types.d.mts.map +0 -1
- package/dist/prompts/core/keys.cjs +0 -165
- package/dist/prompts/core/keys.mjs +0 -167
- package/dist/prompts/core/keys.mjs.map +0 -1
- package/dist/prompts/core/runtime.cjs +0 -104
- package/dist/prompts/core/runtime.mjs +0 -106
- package/dist/prompts/core/runtime.mjs.map +0 -1
- package/dist/prompts/core/session.cjs +0 -98
- package/dist/prompts/core/session.mjs +0 -100
- package/dist/prompts/core/session.mjs.map +0 -1
- package/dist/prompts/core/types.d.cts +0 -21
- package/dist/prompts/core/types.d.cts.map +0 -1
- package/dist/prompts/core/types.d.mts +0 -21
- package/dist/prompts/core/types.d.mts.map +0 -1
- package/dist/prompts/types.d.cts +0 -52
- package/dist/prompts/types.d.cts.map +0 -1
- package/dist/prompts/types.d.mts +0 -52
- package/dist/prompts/types.d.mts.map +0 -1
- package/dist/pubsub/types.d.cts +0 -10
- package/dist/pubsub/types.d.cts.map +0 -1
- package/dist/pubsub/types.d.mts +0 -10
- package/dist/pubsub/types.d.mts.map +0 -1
- package/dist/queue/types.d.cts +0 -47
- package/dist/queue/types.d.cts.map +0 -1
- package/dist/queue/types.d.mts +0 -47
- package/dist/queue/types.d.mts.map +0 -1
- package/dist/workflow/types.d.cts +0 -83
- package/dist/workflow/types.d.cts.map +0 -1
- package/dist/workflow/types.d.mts +0 -83
- package/dist/workflow/types.d.mts.map +0 -1
package/dist/lib/cron/index.cjs
CHANGED
|
@@ -1,13 +1,735 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
2
|
+
const require_lib_errors_index = require("../errors/index.cjs");
|
|
3
|
+
//#region src/lib/cron/builder/index.ts
|
|
4
|
+
const CRON_FIELD_ORDER = [
|
|
5
|
+
"second",
|
|
6
|
+
"minute",
|
|
7
|
+
"hour",
|
|
8
|
+
"day",
|
|
9
|
+
"month",
|
|
10
|
+
"weekday"
|
|
11
|
+
];
|
|
12
|
+
var FieldWrapper = class {
|
|
13
|
+
fields = [];
|
|
14
|
+
add(expr) {
|
|
15
|
+
this.fields.push(expr);
|
|
16
|
+
}
|
|
17
|
+
read() {
|
|
18
|
+
return this.fields;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
var CronListBuilder = class {
|
|
22
|
+
wrapper;
|
|
23
|
+
constructor(wrapper) {
|
|
24
|
+
this.wrapper = wrapper;
|
|
25
|
+
}
|
|
26
|
+
any() {
|
|
27
|
+
this.wrapper.add({ type: "any" });
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
range(options) {
|
|
31
|
+
this.wrapper.add({
|
|
32
|
+
type: "range",
|
|
33
|
+
...options
|
|
34
|
+
});
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
37
|
+
step(options) {
|
|
38
|
+
this.wrapper.add({
|
|
39
|
+
type: "step",
|
|
40
|
+
...options
|
|
41
|
+
});
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
44
|
+
number(value) {
|
|
45
|
+
this.wrapper.add({
|
|
46
|
+
type: "value",
|
|
47
|
+
value
|
|
48
|
+
});
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
function range(options) {
|
|
53
|
+
return {
|
|
54
|
+
type: "range",
|
|
55
|
+
...options
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function any() {
|
|
59
|
+
return { type: "any" };
|
|
60
|
+
}
|
|
61
|
+
function step(options) {
|
|
62
|
+
return {
|
|
63
|
+
type: "step",
|
|
64
|
+
...options
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function list(builderFn) {
|
|
68
|
+
const wrapper = new FieldWrapper();
|
|
69
|
+
builderFn(new CronListBuilder(wrapper));
|
|
70
|
+
return {
|
|
71
|
+
type: "list",
|
|
72
|
+
values: wrapper.read()
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function number(value) {
|
|
76
|
+
return {
|
|
77
|
+
type: "value",
|
|
78
|
+
value
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function cronJobBuilder(buildFn) {
|
|
82
|
+
const fields = {
|
|
83
|
+
second: void 0,
|
|
84
|
+
minute: void 0,
|
|
85
|
+
hour: void 0,
|
|
86
|
+
day: void 0,
|
|
87
|
+
month: void 0,
|
|
88
|
+
weekday: void 0
|
|
89
|
+
};
|
|
90
|
+
const obj = {
|
|
91
|
+
second(expr) {
|
|
92
|
+
fields.second = checkExpr(expr);
|
|
93
|
+
return obj;
|
|
94
|
+
},
|
|
95
|
+
minute(expr) {
|
|
96
|
+
fields.minute = checkExpr(expr);
|
|
97
|
+
return obj;
|
|
98
|
+
},
|
|
99
|
+
hour(expr) {
|
|
100
|
+
fields.hour = checkExpr(expr);
|
|
101
|
+
return obj;
|
|
102
|
+
},
|
|
103
|
+
day(expr) {
|
|
104
|
+
fields.day = checkExpr(expr);
|
|
105
|
+
return obj;
|
|
106
|
+
},
|
|
107
|
+
month(expr) {
|
|
108
|
+
fields.month = checkExpr(expr);
|
|
109
|
+
return obj;
|
|
110
|
+
},
|
|
111
|
+
weekday(expr) {
|
|
112
|
+
fields.weekday = checkExpr(expr);
|
|
113
|
+
return obj;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
buildFn(obj);
|
|
117
|
+
return generate(fields);
|
|
118
|
+
}
|
|
119
|
+
function checkExpr(expr) {
|
|
120
|
+
if (expr.type === "list") {
|
|
121
|
+
const { values } = expr;
|
|
122
|
+
if (values.length === 0) throw new Error("EmptyListError: List expression cannot be empty");
|
|
123
|
+
return values.map((e) => handleSimpleExpression(e)).join(",");
|
|
124
|
+
}
|
|
125
|
+
return handleSimpleExpression(expr);
|
|
126
|
+
}
|
|
127
|
+
function handleSimpleExpression(expr) {
|
|
128
|
+
switch (expr.type) {
|
|
129
|
+
case "any": return "*";
|
|
130
|
+
case "value": return `${expr.value}`;
|
|
131
|
+
case "range": {
|
|
132
|
+
const { min, max } = expr;
|
|
133
|
+
if (min > max) throw new Error(`OutOfBoundError: Expected ${min} <= ${max}`);
|
|
134
|
+
return `${min}-${max}`;
|
|
135
|
+
}
|
|
136
|
+
case "step": {
|
|
137
|
+
const { step, range } = expr;
|
|
138
|
+
if (step === 0) throw new Error(`OutOfBoundError: Expected step value greater than zero`);
|
|
139
|
+
if (!range) return `*/${step}`;
|
|
140
|
+
const { min, max } = range;
|
|
141
|
+
if (max === 0) {
|
|
142
|
+
if (min > max) throw new Error(`OutOfBoundError: Expected max value greater than zero`);
|
|
143
|
+
return `${min}-${max}/${step}`;
|
|
144
|
+
}
|
|
145
|
+
if (!max) return `${min}/${step}`;
|
|
146
|
+
if (min > max) throw new Error(`OutOfBoundError: Expected ${min} <= ${max}`);
|
|
147
|
+
return `${min}-${max}/${step}`;
|
|
148
|
+
}
|
|
149
|
+
default: return "*";
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
function generate(fields) {
|
|
153
|
+
const parts = [];
|
|
154
|
+
for (let index = 0; index < CRON_FIELD_ORDER.length; index++) {
|
|
155
|
+
const key = CRON_FIELD_ORDER[index];
|
|
156
|
+
if (!key) return "";
|
|
157
|
+
if (key === "second" && !fields[key]) continue;
|
|
158
|
+
parts.push(fields[key] ?? "*");
|
|
159
|
+
}
|
|
160
|
+
return parts.join(" ");
|
|
161
|
+
}
|
|
162
|
+
//#endregion
|
|
163
|
+
//#region src/lib/cron/builder/types.ts
|
|
164
|
+
const WeekDay = {
|
|
165
|
+
sun: 0,
|
|
166
|
+
mon: 1,
|
|
167
|
+
tue: 2,
|
|
168
|
+
wed: 3,
|
|
169
|
+
thu: 4,
|
|
170
|
+
fri: 5,
|
|
171
|
+
sat: 6
|
|
172
|
+
};
|
|
173
|
+
const Month = {
|
|
174
|
+
jan: 1,
|
|
175
|
+
feb: 2,
|
|
176
|
+
mar: 3,
|
|
177
|
+
apr: 4,
|
|
178
|
+
may: 5,
|
|
179
|
+
jun: 6,
|
|
180
|
+
jul: 7,
|
|
181
|
+
aug: 8,
|
|
182
|
+
sep: 9,
|
|
183
|
+
oct: 10,
|
|
184
|
+
nov: 11,
|
|
185
|
+
dec: 12
|
|
186
|
+
};
|
|
187
|
+
//#endregion
|
|
188
|
+
//#region src/lib/cron/core/scanner.ts
|
|
189
|
+
const FieldAmount = {
|
|
190
|
+
min: 5,
|
|
191
|
+
max: 6
|
|
192
|
+
};
|
|
193
|
+
var Token = class {
|
|
194
|
+
type;
|
|
195
|
+
component;
|
|
196
|
+
value;
|
|
197
|
+
field;
|
|
198
|
+
constructor(component, type, value, field) {
|
|
199
|
+
this.component = component;
|
|
200
|
+
this.type = type;
|
|
201
|
+
this.value = value;
|
|
202
|
+
this.field = field;
|
|
203
|
+
}
|
|
204
|
+
getComponent() {
|
|
205
|
+
return this.component;
|
|
206
|
+
}
|
|
207
|
+
getTokenType() {
|
|
208
|
+
return this.type;
|
|
209
|
+
}
|
|
210
|
+
getTokenValue() {
|
|
211
|
+
return this.value;
|
|
212
|
+
}
|
|
213
|
+
getField() {
|
|
214
|
+
return this.field;
|
|
215
|
+
}
|
|
216
|
+
toString() {
|
|
217
|
+
return `Token{${`component="${this.component}", type=${this.type}`}, ${`field="${this.field}", value=${this.value}`}}`;
|
|
218
|
+
}
|
|
219
|
+
equals(other) {
|
|
220
|
+
if (!other) return false;
|
|
221
|
+
const isComponentEqual = this.component === other.getComponent();
|
|
222
|
+
const isTokenTypeEqual = this.type === other.getTokenType();
|
|
223
|
+
const isTokenValueEqual = this.value === other.getTokenValue();
|
|
224
|
+
const isFieldEqual = this.field === other.getField();
|
|
225
|
+
return isComponentEqual && isTokenTypeEqual && isTokenValueEqual && isFieldEqual;
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
var Scanner = class {
|
|
229
|
+
expression;
|
|
230
|
+
current;
|
|
231
|
+
start;
|
|
232
|
+
tokens;
|
|
233
|
+
constructor(expression) {
|
|
234
|
+
this.expression = expression;
|
|
235
|
+
this.current = 0;
|
|
236
|
+
this.start = 0;
|
|
237
|
+
this.tokens = [];
|
|
238
|
+
}
|
|
239
|
+
scan() {
|
|
240
|
+
if (this.expression.length === 0) return require_lib_errors_index.err("EmptyCronExpressionError", "Cron expression have zero length");
|
|
241
|
+
const fields = this.expression.trim().split(/\s+/);
|
|
242
|
+
const hasMinLen = fields.length === FieldAmount.min;
|
|
243
|
+
const hasMaxLen = fields.length === FieldAmount.max;
|
|
244
|
+
if (!hasMinLen && !hasMaxLen) return require_lib_errors_index.err("CronLengthError", `Invalid number of fields for '${this.expression}'. Expected 5 or 6 fields but got ${fields.length} field(s)`);
|
|
245
|
+
const components = this.createComponent(fields);
|
|
246
|
+
for (let idx = 0; idx < components.length; idx++) {
|
|
247
|
+
const component = components[idx];
|
|
248
|
+
if (!component) return require_lib_errors_index.err("CronExpressionError", `Invalid cron expression: ${this.expression}`);
|
|
249
|
+
this.current = 0;
|
|
250
|
+
this.start = 0;
|
|
251
|
+
const [error, _] = this.scanComponent(component);
|
|
252
|
+
if (error) return require_lib_errors_index.err(error.type, error.message);
|
|
253
|
+
}
|
|
254
|
+
return require_lib_errors_index.ok(this.tokens);
|
|
255
|
+
}
|
|
256
|
+
scanComponent(component) {
|
|
257
|
+
const { field, content } = component;
|
|
258
|
+
while (this.current < content.length) {
|
|
259
|
+
let currentCh = this.advance(content);
|
|
260
|
+
switch (currentCh) {
|
|
261
|
+
case "*": {
|
|
262
|
+
const ch = this.peek(content);
|
|
263
|
+
if (this.match(content, "/")) {
|
|
264
|
+
const [error, _] = this.handleStep(component);
|
|
265
|
+
if (error) return require_lib_errors_index.err(error.type, error.message);
|
|
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}'`);
|
|
268
|
+
break;
|
|
269
|
+
}
|
|
270
|
+
case "-":
|
|
271
|
+
currentCh = this.advance(content);
|
|
272
|
+
if (this.isDigit(currentCh)) {
|
|
273
|
+
const [error, _] = this.handleRangeWithStep(component);
|
|
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}'`);
|
|
276
|
+
break;
|
|
277
|
+
case ",": {
|
|
278
|
+
if (this.current === 1 && this.start === 0) return require_lib_errors_index.err("CronExpressionError", `Invalid list expression '${content}' for field '${field}'`);
|
|
279
|
+
const next = this.peek(content);
|
|
280
|
+
if (!next || next === ",") return require_lib_errors_index.err("CronExpressionError", `Invalid list expression '${content}' for field '${field}'`);
|
|
281
|
+
break;
|
|
282
|
+
}
|
|
283
|
+
default:
|
|
284
|
+
if (this.isDigit(currentCh)) {
|
|
285
|
+
const [error, _] = this.handleNumber(component);
|
|
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}'`);
|
|
288
|
+
break;
|
|
289
|
+
}
|
|
290
|
+
this.start = this.current;
|
|
291
|
+
}
|
|
292
|
+
return require_lib_errors_index.ok(true);
|
|
293
|
+
}
|
|
294
|
+
addToken(component, type, value, field) {
|
|
295
|
+
const token = new Token(component, type, value, field);
|
|
296
|
+
this.tokens.push(token);
|
|
297
|
+
}
|
|
298
|
+
advance(content) {
|
|
299
|
+
const currentCh = content.charAt(this.current);
|
|
300
|
+
this.current += 1;
|
|
301
|
+
return currentCh;
|
|
302
|
+
}
|
|
303
|
+
match(content, expected) {
|
|
304
|
+
if (this.current >= content.length) return false;
|
|
305
|
+
if (content.charAt(this.current) !== expected) return false;
|
|
306
|
+
this.current += 1;
|
|
307
|
+
return true;
|
|
308
|
+
}
|
|
309
|
+
peek(content) {
|
|
310
|
+
if (this.current >= content.length) return void 0;
|
|
311
|
+
return content.charAt(this.current);
|
|
312
|
+
}
|
|
313
|
+
handleStep(component) {
|
|
314
|
+
const { field, content } = component;
|
|
315
|
+
let ch = this.peek(content);
|
|
316
|
+
const slashIdx = this.current - 1;
|
|
317
|
+
while (ch && this.isDigit(ch)) {
|
|
318
|
+
this.advance(content);
|
|
319
|
+
ch = this.peek(content);
|
|
320
|
+
}
|
|
321
|
+
if (ch && ch !== ",") return require_lib_errors_index.err("CronExpressionError", `Invalid step expression '${content}' for field '${field}'`);
|
|
322
|
+
const tokenContent = content.substring(this.start, this.current);
|
|
323
|
+
const value = content.slice(slashIdx + 1, this.current);
|
|
324
|
+
if (value.length === 0) return require_lib_errors_index.err("CronExpressionError", `Invalid step expression '${content}' for field '${field}'`);
|
|
325
|
+
this.addToken(tokenContent, "step", Number(value), field);
|
|
326
|
+
return require_lib_errors_index.ok(true);
|
|
327
|
+
}
|
|
328
|
+
handleRangeWithStep(component) {
|
|
329
|
+
const { field, content } = component;
|
|
330
|
+
let ch = this.peek(content);
|
|
331
|
+
while (ch && this.isDigit(ch)) {
|
|
332
|
+
this.advance(content);
|
|
333
|
+
ch = this.peek(content);
|
|
334
|
+
}
|
|
335
|
+
if (!ch) return require_lib_errors_index.err("CronExpressionError", `Invalid range expression '${content}' for field '${field}'`);
|
|
336
|
+
if (this.match(content, "/")) {
|
|
337
|
+
const [error, _] = this.handleStep(component);
|
|
338
|
+
if (error) return require_lib_errors_index.err(error.type, error.message);
|
|
339
|
+
return require_lib_errors_index.ok(true);
|
|
340
|
+
}
|
|
341
|
+
return require_lib_errors_index.err("CronExpressionError", `Invalid range expression '${content}' for field '${field}'`);
|
|
342
|
+
}
|
|
343
|
+
handleNumber(component) {
|
|
344
|
+
const { field, content } = component;
|
|
345
|
+
let ch = this.peek(content);
|
|
346
|
+
this.start = this.current - 1;
|
|
347
|
+
while (ch && this.isDigit(ch)) {
|
|
348
|
+
this.advance(content);
|
|
349
|
+
ch = this.peek(content);
|
|
350
|
+
}
|
|
351
|
+
if (!ch) {
|
|
352
|
+
const item = content.substring(this.start);
|
|
353
|
+
this.addToken(item, "number", Number(item), field);
|
|
354
|
+
return require_lib_errors_index.ok(true);
|
|
355
|
+
}
|
|
356
|
+
if (this.match(content, "-")) {
|
|
357
|
+
const [error, _] = this.handleRange(component);
|
|
358
|
+
if (error) return require_lib_errors_index.err(error.type, error.message);
|
|
359
|
+
return require_lib_errors_index.ok(true);
|
|
360
|
+
}
|
|
361
|
+
if (this.match(content, "/")) {
|
|
362
|
+
const [error, _] = this.handleStep(component);
|
|
363
|
+
if (error) return require_lib_errors_index.err(error.type, error.message);
|
|
364
|
+
return require_lib_errors_index.ok(true);
|
|
365
|
+
}
|
|
366
|
+
if (!this.isDigit(ch) && ch !== ",") return require_lib_errors_index.err("CronExpressionError", `Invalid number '${content}' for field '${field}'`);
|
|
367
|
+
const item = content.substring(this.start, this.current);
|
|
368
|
+
this.addToken(item, "number", Number(item), field);
|
|
369
|
+
return require_lib_errors_index.ok(true);
|
|
370
|
+
}
|
|
371
|
+
handleRange(component) {
|
|
372
|
+
const { field, content } = component;
|
|
373
|
+
let ch = this.peek(content);
|
|
374
|
+
if (!ch) return require_lib_errors_index.err("CronExpressionError", `Invalid range expression '${content}' for field '${field}'`);
|
|
375
|
+
while (ch && this.isDigit(ch)) {
|
|
376
|
+
this.advance(content);
|
|
377
|
+
ch = this.peek(content);
|
|
378
|
+
}
|
|
379
|
+
if (!ch) {
|
|
380
|
+
const tokenContent = content.substring(this.start);
|
|
381
|
+
this.addToken(tokenContent, "range", tokenContent, field);
|
|
382
|
+
return require_lib_errors_index.ok(true);
|
|
383
|
+
}
|
|
384
|
+
if (this.match(content, "/")) {
|
|
385
|
+
const [error, _] = this.handleStep(component);
|
|
386
|
+
if (error) return require_lib_errors_index.err(error.type, error.message);
|
|
387
|
+
return require_lib_errors_index.ok(true);
|
|
388
|
+
}
|
|
389
|
+
if (ch && ch !== ",") return require_lib_errors_index.err("CronExpressionError", `Invalid range expression '${content}' for field '${field}'`);
|
|
390
|
+
const tokenContent = content.substring(this.start, this.current);
|
|
391
|
+
this.addToken(tokenContent, "range", tokenContent, field);
|
|
392
|
+
return require_lib_errors_index.ok(true);
|
|
393
|
+
}
|
|
394
|
+
isDigit(ch) {
|
|
395
|
+
return ch >= "0" && ch <= "9";
|
|
396
|
+
}
|
|
397
|
+
createComponent(fields) {
|
|
398
|
+
const fieldNames = [
|
|
399
|
+
"second",
|
|
400
|
+
"minute",
|
|
401
|
+
"hour",
|
|
402
|
+
"day",
|
|
403
|
+
"month",
|
|
404
|
+
"weekday"
|
|
405
|
+
];
|
|
406
|
+
const components = [];
|
|
407
|
+
let offset = 1;
|
|
408
|
+
if (fields.length === FieldAmount.max) offset = 0;
|
|
409
|
+
for (let idx = 0; idx < fields.length; idx++) {
|
|
410
|
+
const fieldName = fieldNames[idx + offset];
|
|
411
|
+
const content = fields[idx];
|
|
412
|
+
if (!fieldName || !content) break;
|
|
413
|
+
components.push({
|
|
414
|
+
content,
|
|
415
|
+
field: fieldName
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
return components;
|
|
419
|
+
}
|
|
420
|
+
};
|
|
421
|
+
//#endregion
|
|
422
|
+
//#region src/lib/cron/core/index.ts
|
|
423
|
+
const RETRY_DELAY_MS = 3600 * 1e3;
|
|
424
|
+
const MAX_YEARS = 4;
|
|
425
|
+
const ALIASES = {
|
|
426
|
+
"@yearly": "0 0 1 1 *",
|
|
427
|
+
"@monthly": "0 0 1 * *",
|
|
428
|
+
"@weekly": "0 0 * * 0",
|
|
429
|
+
"@daily": "0 0 * * *",
|
|
430
|
+
"@hourly": "0 * * * *",
|
|
431
|
+
"@minutely": "* * * * *"
|
|
432
|
+
};
|
|
433
|
+
const CronSecondRange = {
|
|
434
|
+
min: 0,
|
|
435
|
+
max: 59
|
|
436
|
+
};
|
|
437
|
+
const CronMinuteRange = {
|
|
438
|
+
min: 0,
|
|
439
|
+
max: 59
|
|
440
|
+
};
|
|
441
|
+
const CronHourRange = {
|
|
442
|
+
min: 0,
|
|
443
|
+
max: 23
|
|
444
|
+
};
|
|
445
|
+
const CronDayRange = {
|
|
446
|
+
min: 1,
|
|
447
|
+
max: 31
|
|
448
|
+
};
|
|
449
|
+
const CronMonthRange = {
|
|
450
|
+
min: 1,
|
|
451
|
+
max: 12
|
|
452
|
+
};
|
|
453
|
+
const CronDayOfWeekRange = {
|
|
454
|
+
min: 0,
|
|
455
|
+
max: 6
|
|
456
|
+
};
|
|
457
|
+
var Cron = class {
|
|
458
|
+
options;
|
|
459
|
+
status = "idle";
|
|
460
|
+
timeoutId = null;
|
|
461
|
+
second = Array(CronSecondRange.max + 1).fill(0);
|
|
462
|
+
minute = Array(CronMinuteRange.max + 1).fill(0);
|
|
463
|
+
hour = Array(CronHourRange.max + 1).fill(0);
|
|
464
|
+
day = Array(CronDayRange.max + 1).fill(0);
|
|
465
|
+
month = Array(CronMonthRange.max + 1).fill(0);
|
|
466
|
+
dayOfWeek = Array(CronDayOfWeekRange.max + 1).fill(0);
|
|
467
|
+
hasSeconds;
|
|
468
|
+
_dayWildcard = false;
|
|
469
|
+
_dowWildcard = false;
|
|
470
|
+
fillRange(values, min, max) {
|
|
471
|
+
for (let i = min; i <= max; i++) values[i] = 1;
|
|
472
|
+
}
|
|
473
|
+
handleStep(part, values, min, max) {
|
|
474
|
+
const [rangePart, stepStr] = part.split("/");
|
|
475
|
+
if (!rangePart) return require_lib_errors_index.err("InvalidValueError", `'${rangePart}' is empty`);
|
|
476
|
+
if (!stepStr) return require_lib_errors_index.err("InvalidValueError", `'${stepStr}' is empty`);
|
|
477
|
+
const step = Number(stepStr);
|
|
478
|
+
if (!Number.isInteger(step)) return require_lib_errors_index.err("InvalidValueError", `'${step}' is not a valid number`);
|
|
479
|
+
if (step <= 0) return require_lib_errors_index.err("OutOfBoundError", `Expected ${step} > 0`);
|
|
480
|
+
if (rangePart === "*") {
|
|
481
|
+
for (let i = min; i <= max; i += step) values[i] = 1;
|
|
482
|
+
return require_lib_errors_index.ok(true);
|
|
483
|
+
}
|
|
484
|
+
if (rangePart.includes("-")) return this.handleStepRange(rangePart, step, values, min, max);
|
|
485
|
+
return this.handleStepSingle(rangePart, step, values, min, max);
|
|
486
|
+
}
|
|
487
|
+
handleStepRange(range, step, values, min, max) {
|
|
488
|
+
const [startStr, endStr] = range.split("-");
|
|
489
|
+
if (!endStr) return require_lib_errors_index.err("InvalidValueError", `'${endStr}' is empty`);
|
|
490
|
+
let start = min;
|
|
491
|
+
if (startStr && startStr.length > 0) start = Number(startStr);
|
|
492
|
+
const end = Number(endStr);
|
|
493
|
+
if (!Number.isInteger(start)) return require_lib_errors_index.err("InvalidValueError", `'${start}' is not a valid number`);
|
|
494
|
+
if (!Number.isInteger(end)) return require_lib_errors_index.err("InvalidValueError", `'${end}' is not a valid number`);
|
|
495
|
+
if (start < min) return require_lib_errors_index.err("OutOfBoundError", `Expected ${start} >= ${min}`);
|
|
496
|
+
if (end > max) return require_lib_errors_index.err("OutOfBoundError", `Expected ${end} <= ${max}`);
|
|
497
|
+
if (start > end) return require_lib_errors_index.err("OutOfBoundError", `Expected ${start} <= ${end}`);
|
|
498
|
+
for (let i = start; i <= end; i += step) values[i] = 1;
|
|
499
|
+
return require_lib_errors_index.ok(true);
|
|
500
|
+
}
|
|
501
|
+
handleStepSingle(value, step, values, min, max) {
|
|
502
|
+
const start = Number(value);
|
|
503
|
+
if (!Number.isInteger(start)) return require_lib_errors_index.err("InvalidValueError", `'${start}' is not a valid number`);
|
|
504
|
+
if (start < min) return require_lib_errors_index.err("OutOfBoundError", `Expected ${start} >= ${min}`);
|
|
505
|
+
if (start > max) return require_lib_errors_index.err("OutOfBoundError", `Expected ${start} <= ${max}`);
|
|
506
|
+
for (let i = start; i <= max; i += step) values[i] = 1;
|
|
507
|
+
return require_lib_errors_index.ok(true);
|
|
508
|
+
}
|
|
509
|
+
handleRange(part, values, min, max) {
|
|
510
|
+
const [startStr, endStr] = part.split("-");
|
|
511
|
+
if (!startStr) return require_lib_errors_index.err("InvalidValueError", `'${startStr}' is empty`);
|
|
512
|
+
if (!endStr) return require_lib_errors_index.err("InvalidValueError", `'${endStr}' is empty`);
|
|
513
|
+
const start = Number(startStr);
|
|
514
|
+
const end = Number(endStr);
|
|
515
|
+
if (!Number.isInteger(start)) return require_lib_errors_index.err("InvalidValueError", `'${start}' is not a valid number`);
|
|
516
|
+
if (!Number.isInteger(end)) return require_lib_errors_index.err("InvalidValueError", `'${end}' is not a valid number`);
|
|
517
|
+
if (start < min) return require_lib_errors_index.err("OutOfBoundError", `Expected ${start} >= ${min}`);
|
|
518
|
+
if (end > max) return require_lib_errors_index.err("OutOfBoundError", `Expected ${end} <= ${max}`);
|
|
519
|
+
if (start > end) return require_lib_errors_index.err("OutOfBoundError", `Expected ${start} <= ${end}`);
|
|
520
|
+
for (let i = start; i <= end; i++) values[i] = 1;
|
|
521
|
+
return require_lib_errors_index.ok(true);
|
|
522
|
+
}
|
|
523
|
+
handleNumber(value, values, min, max) {
|
|
524
|
+
const n = Number(value);
|
|
525
|
+
if (!Number.isInteger(n)) return require_lib_errors_index.err("InvalidValueError", `'${value}' is not a valid number`);
|
|
526
|
+
if (n < min) return require_lib_errors_index.err("OutOfBoundError", `Expected ${n} >= ${min}`);
|
|
527
|
+
if (n > max) return require_lib_errors_index.err("OutOfBoundError", `Expected ${n} <= ${max}`);
|
|
528
|
+
values[n] = 1;
|
|
529
|
+
return require_lib_errors_index.ok(true);
|
|
530
|
+
}
|
|
531
|
+
constructor(options) {
|
|
532
|
+
this.options = options;
|
|
533
|
+
const expr = this.resolveAlias(options.schedule);
|
|
534
|
+
const [error, tokens] = new Scanner(expr).scan();
|
|
535
|
+
if (error) throw new Error(`${error.type}: ${error.message}`);
|
|
536
|
+
this.hasSeconds = expr.trim().split(/\s+/).length === FieldAmount.max;
|
|
537
|
+
const [parsingError, _] = this.parse(tokens);
|
|
538
|
+
if (parsingError) throw new Error(`${parsingError.type}: ${parsingError.message}`);
|
|
539
|
+
}
|
|
540
|
+
resolveAlias(schedule) {
|
|
541
|
+
return ALIASES[schedule] || schedule;
|
|
542
|
+
}
|
|
543
|
+
parse(tokens) {
|
|
544
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
545
|
+
const token = tokens[i];
|
|
546
|
+
if (!token) return require_lib_errors_index.err("InvalidValueError", "Undefined token");
|
|
547
|
+
const tokenType = token.getTokenType();
|
|
548
|
+
switch (token.getField()) {
|
|
549
|
+
case "second": {
|
|
550
|
+
const [error, _] = this.handleField(token, this.second, CronSecondRange.min, CronSecondRange.max);
|
|
551
|
+
if (error) return require_lib_errors_index.err(error.type, `${error.message} in field '${token.getField()}'`);
|
|
552
|
+
break;
|
|
553
|
+
}
|
|
554
|
+
case "minute": {
|
|
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()}'`);
|
|
557
|
+
break;
|
|
558
|
+
}
|
|
559
|
+
case "hour": {
|
|
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()}'`);
|
|
562
|
+
break;
|
|
563
|
+
}
|
|
564
|
+
case "day": {
|
|
565
|
+
if (tokenType === "any") this._dayWildcard = true;
|
|
566
|
+
const [error, _] = this.handleField(token, this.day, CronDayRange.min, CronDayRange.max);
|
|
567
|
+
if (error) return require_lib_errors_index.err(error.type, `${error.message} in field '${token.getField()}'`);
|
|
568
|
+
break;
|
|
569
|
+
}
|
|
570
|
+
case "month": {
|
|
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()}'`);
|
|
573
|
+
break;
|
|
574
|
+
}
|
|
575
|
+
case "weekday": {
|
|
576
|
+
if (tokenType === "any") this._dowWildcard = true;
|
|
577
|
+
const [error, _] = this.handleField(token, this.dayOfWeek, CronDayOfWeekRange.min, CronDayOfWeekRange.max);
|
|
578
|
+
if (error) return require_lib_errors_index.err(error.type, `${error.message} in field '${token.getField()}'`);
|
|
579
|
+
break;
|
|
580
|
+
}
|
|
581
|
+
default: return require_lib_errors_index.err("InvalidValueError", `Invalid field '${token.getField()}'`);
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
return require_lib_errors_index.ok(true);
|
|
585
|
+
}
|
|
586
|
+
handleField(token, field, min, max) {
|
|
587
|
+
switch (token.getTokenType()) {
|
|
588
|
+
case "any":
|
|
589
|
+
this.fillRange(field, min, max);
|
|
590
|
+
break;
|
|
591
|
+
case "number": {
|
|
592
|
+
const [error, _] = this.handleNumber(token.getComponent(), field, min, max);
|
|
593
|
+
if (error) return require_lib_errors_index.err(error.type, error.message);
|
|
594
|
+
break;
|
|
595
|
+
}
|
|
596
|
+
case "range": {
|
|
597
|
+
const component = token.getComponent();
|
|
598
|
+
const [error, _] = this.handleRange(component, field, min, max);
|
|
599
|
+
if (error) return require_lib_errors_index.err(error.type, error.message);
|
|
600
|
+
break;
|
|
601
|
+
}
|
|
602
|
+
case "step": {
|
|
603
|
+
const component = token.getComponent();
|
|
604
|
+
const [error, _] = this.handleStep(component, field, min, max);
|
|
605
|
+
if (error) return require_lib_errors_index.err(error.type, error.message);
|
|
606
|
+
break;
|
|
607
|
+
}
|
|
608
|
+
default: return require_lib_errors_index.err("InvalidValueError", `Invalid token type '${token.getTokenType()}'`);
|
|
609
|
+
}
|
|
610
|
+
return require_lib_errors_index.ok(true);
|
|
611
|
+
}
|
|
612
|
+
matches(date) {
|
|
613
|
+
const s = date.getSeconds();
|
|
614
|
+
const m = date.getMinutes();
|
|
615
|
+
const h = date.getHours();
|
|
616
|
+
const d = date.getDate();
|
|
617
|
+
const mon = date.getMonth();
|
|
618
|
+
const dow = date.getDay();
|
|
619
|
+
const isSecondMatch = this.hasSeconds ? this.second[s] === 1 : true;
|
|
620
|
+
const isMinuteMatch = this.minute[m] === 1;
|
|
621
|
+
const isHourMatch = this.hour[h] === 1;
|
|
622
|
+
const isMonthMatch = this.month[mon + 1] === 1;
|
|
623
|
+
let isDayOrDowMatch;
|
|
624
|
+
if (!this._dayWildcard && !this._dowWildcard) isDayOrDowMatch = this.day[d] === 1 || this.dayOfWeek[dow] === 1;
|
|
625
|
+
else isDayOrDowMatch = this.day[d] === 1 && this.dayOfWeek[dow] === 1;
|
|
626
|
+
return isSecondMatch && isMinuteMatch && isHourMatch && isDayOrDowMatch && isMonthMatch;
|
|
627
|
+
}
|
|
628
|
+
getNextRun() {
|
|
629
|
+
const date = /* @__PURE__ */ new Date();
|
|
630
|
+
if (this.hasSeconds) {
|
|
631
|
+
date.setMilliseconds(0);
|
|
632
|
+
date.setSeconds(date.getSeconds() + 1);
|
|
633
|
+
} else {
|
|
634
|
+
date.setSeconds(0, 0);
|
|
635
|
+
date.setMinutes(date.getMinutes() + 1);
|
|
636
|
+
}
|
|
637
|
+
const deadline = new Date(date);
|
|
638
|
+
deadline.setFullYear(deadline.getFullYear() + MAX_YEARS);
|
|
639
|
+
while (date < deadline) {
|
|
640
|
+
const s = date.getSeconds();
|
|
641
|
+
const m = date.getMinutes();
|
|
642
|
+
const h = date.getHours();
|
|
643
|
+
const d = date.getDate();
|
|
644
|
+
const mon = date.getMonth();
|
|
645
|
+
const dow = date.getDay();
|
|
646
|
+
if (this.month[mon + 1] === 0) {
|
|
647
|
+
date.setDate(1);
|
|
648
|
+
date.setMonth(mon + 1);
|
|
649
|
+
date.setHours(0, 0, 0, 0);
|
|
650
|
+
continue;
|
|
651
|
+
}
|
|
652
|
+
let isDayOrDowMatch;
|
|
653
|
+
if (!this._dayWildcard && !this._dowWildcard) isDayOrDowMatch = this.day[d] === 0 && this.dayOfWeek[dow] === 0;
|
|
654
|
+
else isDayOrDowMatch = this.day[d] === 0 || this.dayOfWeek[dow] === 0;
|
|
655
|
+
if (isDayOrDowMatch) {
|
|
656
|
+
date.setDate(d + 1);
|
|
657
|
+
date.setHours(0, 0, 0, 0);
|
|
658
|
+
continue;
|
|
659
|
+
}
|
|
660
|
+
if (this.hour[h] === 0) {
|
|
661
|
+
date.setHours(h + 1);
|
|
662
|
+
date.setMinutes(0, 0, 0);
|
|
663
|
+
continue;
|
|
664
|
+
}
|
|
665
|
+
if (this.minute[m] === 0) {
|
|
666
|
+
date.setMinutes(m + 1);
|
|
667
|
+
date.setSeconds(0, 0);
|
|
668
|
+
continue;
|
|
669
|
+
}
|
|
670
|
+
if (this.hasSeconds && this.second[s] === 0) {
|
|
671
|
+
date.setSeconds(s + 1);
|
|
672
|
+
date.setMilliseconds(0);
|
|
673
|
+
continue;
|
|
674
|
+
}
|
|
675
|
+
return new Date(date);
|
|
676
|
+
}
|
|
677
|
+
return null;
|
|
678
|
+
}
|
|
679
|
+
start() {
|
|
680
|
+
if (this.status !== "idle") return;
|
|
681
|
+
this.status = "running";
|
|
682
|
+
this.next();
|
|
683
|
+
}
|
|
684
|
+
stop() {
|
|
685
|
+
this.status = "idle";
|
|
686
|
+
if (this.timeoutId) {
|
|
687
|
+
clearTimeout(this.timeoutId);
|
|
688
|
+
this.timeoutId = null;
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
pause() {
|
|
692
|
+
if (this.status !== "running") return;
|
|
693
|
+
this.status = "paused";
|
|
694
|
+
if (this.timeoutId) {
|
|
695
|
+
clearTimeout(this.timeoutId);
|
|
696
|
+
this.timeoutId = null;
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
resume() {
|
|
700
|
+
if (this.status !== "paused") return;
|
|
701
|
+
this.status = "running";
|
|
702
|
+
this.next();
|
|
703
|
+
}
|
|
704
|
+
getStatus() {
|
|
705
|
+
return this.status;
|
|
706
|
+
}
|
|
707
|
+
next() {
|
|
708
|
+
if (this.status !== "running") return;
|
|
709
|
+
const nextRun = this.getNextRun();
|
|
710
|
+
if (!nextRun) {
|
|
711
|
+
this.timeoutId = setTimeout(() => this.next(), RETRY_DELAY_MS);
|
|
712
|
+
return;
|
|
713
|
+
}
|
|
714
|
+
const delay = nextRun.getTime() - Date.now();
|
|
715
|
+
this.timeoutId = setTimeout(() => {
|
|
716
|
+
this.run();
|
|
717
|
+
}, Math.max(0, delay));
|
|
718
|
+
}
|
|
719
|
+
async run() {
|
|
720
|
+
if (this.status !== "running") return;
|
|
721
|
+
const handlerResult = this.options.handler();
|
|
722
|
+
await require_lib_errors_index.mightThrow(Promise.resolve(handlerResult));
|
|
723
|
+
if (this.status === "running") this.next();
|
|
724
|
+
}
|
|
725
|
+
};
|
|
726
|
+
//#endregion
|
|
727
|
+
exports.Cron = Cron;
|
|
728
|
+
exports.Month = Month;
|
|
729
|
+
exports.WeekDay = WeekDay;
|
|
730
|
+
exports.any = any;
|
|
731
|
+
exports.cronJobBuilder = cronJobBuilder;
|
|
732
|
+
exports.list = list;
|
|
733
|
+
exports.number = number;
|
|
734
|
+
exports.range = range;
|
|
735
|
+
exports.step = step;
|