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