semola 0.5.2 → 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.
Files changed (160) hide show
  1. package/README.md +88 -13
  2. package/dist/index-BhGNDjPq.d.mts +13 -0
  3. package/dist/index-DxSbeGP-.d.cts +13 -0
  4. package/dist/lib/api/index.cjs +522 -4
  5. package/dist/lib/api/index.d.cts +270 -4
  6. package/dist/lib/api/index.d.mts +270 -4
  7. package/dist/lib/api/index.mjs +520 -2
  8. package/dist/lib/cache/index.d.cts +19 -7
  9. package/dist/lib/cache/index.d.mts +19 -7
  10. package/dist/lib/cache/index.mjs +0 -2
  11. package/dist/lib/cron/index.cjs +470 -11
  12. package/dist/lib/cron/index.d.cts +112 -5
  13. package/dist/lib/cron/index.d.mts +112 -5
  14. package/dist/lib/cron/index.mjs +461 -12
  15. package/dist/lib/errors/index.d.cts +2 -13
  16. package/dist/lib/errors/index.d.mts +2 -13
  17. package/dist/lib/errors/index.mjs +0 -2
  18. package/dist/lib/i18n/index.cjs +6 -1
  19. package/dist/lib/i18n/index.d.cts +12 -4
  20. package/dist/lib/i18n/index.d.mts +12 -4
  21. package/dist/lib/i18n/index.mjs +6 -3
  22. package/dist/lib/logging/index.cjs +387 -0
  23. package/dist/lib/logging/index.d.cts +108 -0
  24. package/dist/lib/logging/index.d.mts +108 -0
  25. package/dist/lib/logging/index.mjs +374 -0
  26. package/dist/lib/policy/index.cjs +206 -20
  27. package/dist/lib/policy/index.d.cts +61 -5
  28. package/dist/lib/policy/index.d.mts +61 -5
  29. package/dist/lib/policy/index.mjs +187 -3
  30. package/dist/lib/prompts/index.cjs +374 -14
  31. package/dist/lib/prompts/index.d.cts +77 -12
  32. package/dist/lib/prompts/index.d.mts +77 -12
  33. package/dist/lib/prompts/index.mjs +362 -4
  34. package/dist/lib/pubsub/index.cjs +82 -13
  35. package/dist/lib/pubsub/index.d.cts +23 -9
  36. package/dist/lib/pubsub/index.d.mts +23 -9
  37. package/dist/lib/pubsub/index.mjs +82 -15
  38. package/dist/lib/queue/index.d.cts +46 -4
  39. package/dist/lib/queue/index.d.mts +46 -4
  40. package/dist/lib/queue/index.mjs +0 -2
  41. package/dist/lib/workflow/index.cjs +534 -0
  42. package/dist/lib/workflow/index.d.cts +85 -0
  43. package/dist/lib/workflow/index.d.mts +85 -0
  44. package/dist/lib/workflow/index.mjs +533 -0
  45. package/package.json +29 -3
  46. package/dist/api/core/index.cjs +0 -206
  47. package/dist/api/core/index.d.cts +0 -21
  48. package/dist/api/core/index.d.cts.map +0 -1
  49. package/dist/api/core/index.d.mts +0 -21
  50. package/dist/api/core/index.d.mts.map +0 -1
  51. package/dist/api/core/index.mjs +0 -208
  52. package/dist/api/core/index.mjs.map +0 -1
  53. package/dist/api/core/types.d.cts +0 -107
  54. package/dist/api/core/types.d.cts.map +0 -1
  55. package/dist/api/core/types.d.mts +0 -107
  56. package/dist/api/core/types.d.mts.map +0 -1
  57. package/dist/api/middleware/index.cjs +0 -8
  58. package/dist/api/middleware/index.d.cts +0 -11
  59. package/dist/api/middleware/index.d.cts.map +0 -1
  60. package/dist/api/middleware/index.d.mts +0 -11
  61. package/dist/api/middleware/index.d.mts.map +0 -1
  62. package/dist/api/middleware/index.mjs +0 -10
  63. package/dist/api/middleware/index.mjs.map +0 -1
  64. package/dist/api/middleware/types.d.cts +0 -16
  65. package/dist/api/middleware/types.d.cts.map +0 -1
  66. package/dist/api/middleware/types.d.mts +0 -16
  67. package/dist/api/middleware/types.d.mts.map +0 -1
  68. package/dist/api/openapi/index.cjs +0 -254
  69. package/dist/api/openapi/index.mjs +0 -256
  70. package/dist/api/openapi/index.mjs.map +0 -1
  71. package/dist/api/openapi/types.d.cts +0 -60
  72. package/dist/api/openapi/types.d.cts.map +0 -1
  73. package/dist/api/openapi/types.d.mts +0 -60
  74. package/dist/api/openapi/types.d.mts.map +0 -1
  75. package/dist/api/validation/index.cjs +0 -64
  76. package/dist/api/validation/index.mjs +0 -61
  77. package/dist/api/validation/index.mjs.map +0 -1
  78. package/dist/cache/types.d.cts +0 -17
  79. package/dist/cache/types.d.cts.map +0 -1
  80. package/dist/cache/types.d.mts +0 -17
  81. package/dist/cache/types.d.mts.map +0 -1
  82. package/dist/cron/scanner.cjs +0 -237
  83. package/dist/cron/scanner.mjs +0 -238
  84. package/dist/cron/scanner.mjs.map +0 -1
  85. package/dist/cron/types.d.cts +0 -11
  86. package/dist/cron/types.d.cts.map +0 -1
  87. package/dist/cron/types.d.mts +0 -11
  88. package/dist/cron/types.d.mts.map +0 -1
  89. package/dist/errors/types.d.cts +0 -5
  90. package/dist/errors/types.d.cts.map +0 -1
  91. package/dist/errors/types.d.mts +0 -5
  92. package/dist/errors/types.d.mts.map +0 -1
  93. package/dist/i18n/types.d.cts +0 -13
  94. package/dist/i18n/types.d.cts.map +0 -1
  95. package/dist/i18n/types.d.mts +0 -13
  96. package/dist/i18n/types.d.mts.map +0 -1
  97. package/dist/lib/cache/index.d.cts.map +0 -1
  98. package/dist/lib/cache/index.d.mts.map +0 -1
  99. package/dist/lib/cache/index.mjs.map +0 -1
  100. package/dist/lib/cron/index.d.cts.map +0 -1
  101. package/dist/lib/cron/index.d.mts.map +0 -1
  102. package/dist/lib/cron/index.mjs.map +0 -1
  103. package/dist/lib/errors/index.d.cts.map +0 -1
  104. package/dist/lib/errors/index.d.mts.map +0 -1
  105. package/dist/lib/errors/index.mjs.map +0 -1
  106. package/dist/lib/i18n/index.d.cts.map +0 -1
  107. package/dist/lib/i18n/index.d.mts.map +0 -1
  108. package/dist/lib/i18n/index.mjs.map +0 -1
  109. package/dist/lib/policy/index.d.cts.map +0 -1
  110. package/dist/lib/policy/index.d.mts.map +0 -1
  111. package/dist/lib/policy/index.mjs.map +0 -1
  112. package/dist/lib/prompts/index.d.cts.map +0 -1
  113. package/dist/lib/prompts/index.d.mts.map +0 -1
  114. package/dist/lib/prompts/index.mjs.map +0 -1
  115. package/dist/lib/pubsub/index.d.cts.map +0 -1
  116. package/dist/lib/pubsub/index.d.mts.map +0 -1
  117. package/dist/lib/pubsub/index.mjs.map +0 -1
  118. package/dist/lib/queue/index.d.cts.map +0 -1
  119. package/dist/lib/queue/index.d.mts.map +0 -1
  120. package/dist/lib/queue/index.mjs.map +0 -1
  121. package/dist/node_modules/@standard-schema/spec/dist/index.d.cts +0 -80
  122. package/dist/node_modules/@standard-schema/spec/dist/index.d.cts.map +0 -1
  123. package/dist/node_modules/@standard-schema/spec/dist/index.d.mts +0 -80
  124. package/dist/node_modules/@standard-schema/spec/dist/index.d.mts.map +0 -1
  125. package/dist/policy/helpers.cjs +0 -206
  126. package/dist/policy/helpers.d.cts +0 -50
  127. package/dist/policy/helpers.d.cts.map +0 -1
  128. package/dist/policy/helpers.d.mts +0 -50
  129. package/dist/policy/helpers.d.mts.map +0 -1
  130. package/dist/policy/helpers.mjs +0 -190
  131. package/dist/policy/helpers.mjs.map +0 -1
  132. package/dist/policy/types.d.cts +0 -16
  133. package/dist/policy/types.d.cts.map +0 -1
  134. package/dist/policy/types.d.mts +0 -16
  135. package/dist/policy/types.d.mts.map +0 -1
  136. package/dist/prompts/core/keys.cjs +0 -165
  137. package/dist/prompts/core/keys.mjs +0 -167
  138. package/dist/prompts/core/keys.mjs.map +0 -1
  139. package/dist/prompts/core/runtime.cjs +0 -104
  140. package/dist/prompts/core/runtime.mjs +0 -106
  141. package/dist/prompts/core/runtime.mjs.map +0 -1
  142. package/dist/prompts/core/session.cjs +0 -98
  143. package/dist/prompts/core/session.mjs +0 -100
  144. package/dist/prompts/core/session.mjs.map +0 -1
  145. package/dist/prompts/core/types.d.cts +0 -21
  146. package/dist/prompts/core/types.d.cts.map +0 -1
  147. package/dist/prompts/core/types.d.mts +0 -21
  148. package/dist/prompts/core/types.d.mts.map +0 -1
  149. package/dist/prompts/types.d.cts +0 -52
  150. package/dist/prompts/types.d.cts.map +0 -1
  151. package/dist/prompts/types.d.mts +0 -52
  152. package/dist/prompts/types.d.mts.map +0 -1
  153. package/dist/pubsub/types.d.cts +0 -10
  154. package/dist/pubsub/types.d.cts.map +0 -1
  155. package/dist/pubsub/types.d.mts +0 -10
  156. package/dist/pubsub/types.d.mts.map +0 -1
  157. package/dist/queue/types.d.cts +0 -47
  158. package/dist/queue/types.d.cts.map +0 -1
  159. package/dist/queue/types.d.mts +0 -47
  160. package/dist/queue/types.d.mts.map +0 -1
@@ -1,8 +1,427 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_lib_errors_index = require("../errors/index.cjs");
3
- const require_scanner = require("../../cron/scanner.cjs");
4
- //#region src/lib/cron/index.ts
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
5
423
  const RETRY_DELAY_MS = 3600 * 1e3;
424
+ const MAX_YEARS = 4;
6
425
  const ALIASES = {
7
426
  "@yearly": "0 0 1 1 *",
8
427
  "@monthly": "0 0 1 * *",
@@ -112,9 +531,9 @@ var Cron = class {
112
531
  constructor(options) {
113
532
  this.options = options;
114
533
  const expr = this.resolveAlias(options.schedule);
115
- const [error, tokens] = new require_scanner.Scanner(expr).scan();
534
+ const [error, tokens] = new Scanner(expr).scan();
116
535
  if (error) throw new Error(`${error.type}: ${error.message}`);
117
- this.hasSeconds = expr.trim().split(/\s+/).length === require_scanner.FieldAmount.max;
536
+ this.hasSeconds = expr.trim().split(/\s+/).length === FieldAmount.max;
118
537
  const [parsingError, _] = this.parse(tokens);
119
538
  if (parsingError) throw new Error(`${parsingError.type}: ${parsingError.message}`);
120
539
  }
@@ -207,7 +626,7 @@ var Cron = class {
207
626
  return isSecondMatch && isMinuteMatch && isHourMatch && isDayOrDowMatch && isMonthMatch;
208
627
  }
209
628
  getNextRun() {
210
- const date = /* @__PURE__ */ new Date(/* @__PURE__ */ new Date());
629
+ const date = /* @__PURE__ */ new Date();
211
630
  if (this.hasSeconds) {
212
631
  date.setMilliseconds(0);
213
632
  date.setSeconds(date.getSeconds() + 1);
@@ -215,13 +634,45 @@ var Cron = class {
215
634
  date.setSeconds(0, 0);
216
635
  date.setMinutes(date.getMinutes() + 1);
217
636
  }
218
- const maxIterations = this.hasSeconds ? 366 * 4 * 24 * 3600 : 366 * 4 * 24 * 60;
219
- for (let i = 0; i < maxIterations; i++) {
220
- if (this.matches(date)) {
221
- if (date > /* @__PURE__ */ new Date()) return new Date(date);
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;
222
674
  }
223
- if (this.hasSeconds) date.setSeconds(date.getSeconds() + 1);
224
- else date.setMinutes(date.getMinutes() + 1);
675
+ return new Date(date);
225
676
  }
226
677
  return null;
227
678
  }
@@ -274,3 +725,11 @@ var Cron = class {
274
725
  };
275
726
  //#endregion
276
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;
@@ -1,6 +1,114 @@
1
- import { CronOptions, CronStatus } from "../../cron/types.cjs";
2
-
3
- //#region src/lib/cron/index.d.ts
1
+ //#region src/lib/cron/builder/types.d.ts
2
+ declare const WeekDay: {
3
+ readonly sun: 0;
4
+ readonly mon: 1;
5
+ readonly tue: 2;
6
+ readonly wed: 3;
7
+ readonly thu: 4;
8
+ readonly fri: 5;
9
+ readonly sat: 6;
10
+ };
11
+ declare const Month: {
12
+ readonly jan: 1;
13
+ readonly feb: 2;
14
+ readonly mar: 3;
15
+ readonly apr: 4;
16
+ readonly may: 5;
17
+ readonly jun: 6;
18
+ readonly jul: 7;
19
+ readonly aug: 8;
20
+ readonly sep: 9;
21
+ readonly oct: 10;
22
+ readonly nov: 11;
23
+ readonly dec: 12;
24
+ };
25
+ type Enumerate<N extends number, Acc extends number[] = []> = Acc["length"] extends N ? Acc[number] : Enumerate<N, [...Acc, Acc["length"]]>;
26
+ type IntRange<F extends number, T extends number> = Exclude<Enumerate<T>, Enumerate<F>>;
27
+ type TimeType = IntRange<0, 60>;
28
+ type HourType = IntRange<0, 24>;
29
+ type DayType = IntRange<1, 32>;
30
+ type MonthType = IntRange<1, 13>;
31
+ type WeekDayType = IntRange<0, 7>;
32
+ type CronRange<T> = {
33
+ min: NoInfer<T>;
34
+ max: NoInfer<T>;
35
+ };
36
+ type CronStep<T> = {
37
+ step: NoInfer<T>;
38
+ range?: {
39
+ min: NoInfer<T>;
40
+ max?: NoInfer<T>;
41
+ };
42
+ };
43
+ type CronField = "second" | "minute" | "hour" | "day" | "month" | "weekday";
44
+ type CronListExpr<T> = Exclude<CronExpr<T>, {
45
+ type: "list";
46
+ }>;
47
+ type CronExpr<T> = {
48
+ type: "any";
49
+ } | {
50
+ type: "value";
51
+ value: T;
52
+ } | {
53
+ type: "range";
54
+ min: T;
55
+ max: T;
56
+ } | {
57
+ type: "step";
58
+ step: T;
59
+ range?: {
60
+ min: T;
61
+ max?: T;
62
+ };
63
+ } | {
64
+ type: "list";
65
+ values: CronListExpr<T>[];
66
+ };
67
+ interface IBuilder<Used extends CronField> {
68
+ second(expr: CronExpr<TimeType>): CronBuilderType<Used | "second">;
69
+ minute(expr: CronExpr<TimeType>): CronBuilderType<Used | "minute">;
70
+ hour(expr: CronExpr<HourType>): CronBuilderType<Used | "hour">;
71
+ day(expr: CronExpr<DayType>): CronBuilderType<Used | "day">;
72
+ month(expr: CronExpr<MonthType>): CronBuilderType<Used | "month">;
73
+ weekday(expr: CronExpr<WeekDayType>): CronBuilderType<Used | "weekday">;
74
+ }
75
+ type CronBuilderType<Used extends CronField = never> = Omit<IBuilder<Used>, Used>;
76
+ type BuilderFn = (builder: CronBuilderType) => void;
77
+ //#endregion
78
+ //#region src/lib/cron/builder/index.d.ts
79
+ declare class FieldWrapper<T> {
80
+ private fields;
81
+ add(expr: CronListExpr<T>): void;
82
+ read(): CronListExpr<T>[];
83
+ }
84
+ declare class CronListBuilder<T> {
85
+ private wrapper;
86
+ constructor(wrapper: FieldWrapper<T>);
87
+ any(): CronListBuilder<T>;
88
+ range(options: CronRange<T>): CronListBuilder<T>;
89
+ step(options: CronStep<T>): CronListBuilder<T>;
90
+ number(value: T): CronListBuilder<T>;
91
+ }
92
+ declare function range<T>(options: CronRange<T>): CronExpr<T>;
93
+ declare function any<T>(): CronExpr<T>;
94
+ declare function step<T>(options: CronStep<T>): CronExpr<T>;
95
+ declare function list<T>(builderFn: (builder: CronListBuilder<T>) => CronListBuilder<T>): CronExpr<T>;
96
+ declare function number<T>(value: T): {
97
+ type: "value";
98
+ value: T;
99
+ };
100
+ declare function cronJobBuilder(buildFn: BuilderFn): string;
101
+ //#endregion
102
+ //#region src/lib/cron/core/types.d.ts
103
+ type CronAlias = "@yearly" | "@monthly" | "@weekly" | "@daily" | "@hourly" | "@minutely";
104
+ type CronStatus = "idle" | "running" | "paused";
105
+ type CronOptions = {
106
+ name: string;
107
+ schedule: CronAlias | (string & {});
108
+ handler: () => void | Promise<void>;
109
+ };
110
+ //#endregion
111
+ //#region src/lib/cron/core/index.d.ts
4
112
  declare class Cron {
5
113
  private options;
6
114
  private status;
@@ -35,5 +143,4 @@ declare class Cron {
35
143
  private run;
36
144
  }
37
145
  //#endregion
38
- export { Cron };
39
- //# sourceMappingURL=index.d.cts.map
146
+ export { Cron, Month, WeekDay, any, cronJobBuilder, list, number, range, step };