@vite-hub/schedule 0.0.0 → 0.0.1

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.
@@ -0,0 +1,574 @@
1
+ import { readFileSync, readdirSync, realpathSync } from "node:fs";
2
+ import { mkdir, readFile, writeFile } from "node:fs/promises";
3
+ import "node:url";
4
+ //#region ../../node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs
5
+ const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
6
+ function normalizeWindowsPath(input = "") {
7
+ if (!input) return input;
8
+ return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
9
+ }
10
+ const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
11
+ const _DRIVE_LETTER_RE = /^[A-Za-z]:$/;
12
+ const _ROOT_FOLDER_RE = /^\/([A-Za-z]:)?$/;
13
+ function cwd() {
14
+ if (typeof process !== "undefined" && typeof process.cwd === "function") return process.cwd().replace(/\\/g, "/");
15
+ return "/";
16
+ }
17
+ const resolve = function(...arguments_) {
18
+ arguments_ = arguments_.map((argument) => normalizeWindowsPath(argument));
19
+ let resolvedPath = "";
20
+ let resolvedAbsolute = false;
21
+ for (let index = arguments_.length - 1; index >= -1 && !resolvedAbsolute; index--) {
22
+ const path = index >= 0 ? arguments_[index] : cwd();
23
+ if (!path || path.length === 0) continue;
24
+ resolvedPath = `${path}/${resolvedPath}`;
25
+ resolvedAbsolute = isAbsolute(path);
26
+ }
27
+ resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
28
+ if (resolvedAbsolute && !isAbsolute(resolvedPath)) return `/${resolvedPath}`;
29
+ return resolvedPath.length > 0 ? resolvedPath : ".";
30
+ };
31
+ function normalizeString(path, allowAboveRoot) {
32
+ let res = "";
33
+ let lastSegmentLength = 0;
34
+ let lastSlash = -1;
35
+ let dots = 0;
36
+ let char = null;
37
+ for (let index = 0; index <= path.length; ++index) {
38
+ if (index < path.length) char = path[index];
39
+ else if (char === "/") break;
40
+ else char = "/";
41
+ if (char === "/") {
42
+ if (lastSlash === index - 1 || dots === 1);
43
+ else if (dots === 2) {
44
+ if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
45
+ if (res.length > 2) {
46
+ const lastSlashIndex = res.lastIndexOf("/");
47
+ if (lastSlashIndex === -1) {
48
+ res = "";
49
+ lastSegmentLength = 0;
50
+ } else {
51
+ res = res.slice(0, lastSlashIndex);
52
+ lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
53
+ }
54
+ lastSlash = index;
55
+ dots = 0;
56
+ continue;
57
+ } else if (res.length > 0) {
58
+ res = "";
59
+ lastSegmentLength = 0;
60
+ lastSlash = index;
61
+ dots = 0;
62
+ continue;
63
+ }
64
+ }
65
+ if (allowAboveRoot) {
66
+ res += res.length > 0 ? "/.." : "..";
67
+ lastSegmentLength = 2;
68
+ }
69
+ } else {
70
+ if (res.length > 0) res += `/${path.slice(lastSlash + 1, index)}`;
71
+ else res = path.slice(lastSlash + 1, index);
72
+ lastSegmentLength = index - lastSlash - 1;
73
+ }
74
+ lastSlash = index;
75
+ dots = 0;
76
+ } else if (char === "." && dots !== -1) ++dots;
77
+ else dots = -1;
78
+ }
79
+ return res;
80
+ }
81
+ const isAbsolute = function(p) {
82
+ return _IS_ABSOLUTE_RE.test(p);
83
+ };
84
+ const relative = function(from, to) {
85
+ const _from = resolve(from).replace(_ROOT_FOLDER_RE, "$1").split("/");
86
+ const _to = resolve(to).replace(_ROOT_FOLDER_RE, "$1").split("/");
87
+ if (_to[0][1] === ":" && _from[0][1] === ":" && _from[0] !== _to[0]) return _to.join("/");
88
+ const _fromCopy = [..._from];
89
+ for (const segment of _fromCopy) {
90
+ if (_to[0] !== segment) break;
91
+ _from.shift();
92
+ _to.shift();
93
+ }
94
+ return [..._from.map(() => ".."), ..._to].join("/");
95
+ };
96
+ const dirname = function(p) {
97
+ const segments = normalizeWindowsPath(p).replace(/\/$/, "").split("/").slice(0, -1);
98
+ if (segments.length === 1 && _DRIVE_LETTER_RE.test(segments[0])) segments[0] += "/";
99
+ return segments.join("/") || (isAbsolute(p) ? "/" : ".");
100
+ };
101
+ //#endregion
102
+ //#region ../internal/src/build/paths.ts
103
+ function generatedDirSegments(productName) {
104
+ return [".vitehub", productName];
105
+ }
106
+ function ensureGeneratedDir(rootDir, productName) {
107
+ return resolve(rootDir, ...generatedDirSegments(productName));
108
+ }
109
+ function createImportPath(fromFile, targetFile) {
110
+ const importPath = relative(realpathIfExists(dirname(fromFile)), realpathIfExists(targetFile));
111
+ return importPath.startsWith(".") ? importPath : `./${importPath}`;
112
+ }
113
+ function realpathIfExists(path) {
114
+ try {
115
+ return realpathSync.native(path);
116
+ } catch {
117
+ return resolve(path);
118
+ }
119
+ }
120
+ //#endregion
121
+ //#region ../internal/src/definition-catalog.ts
122
+ const sourceFilePattern = /\.(?:c|m)?[jt]s$/i;
123
+ const declarationFilePattern = /\.d\.(?:c|m)?[jt]s$/i;
124
+ const ignoredDirs = new Set([
125
+ "node_modules",
126
+ "dist",
127
+ ".nitro",
128
+ ".output",
129
+ ".nuxt",
130
+ ".vercel",
131
+ ".git",
132
+ ".vitehub"
133
+ ]);
134
+ function resolveDefinitionScanRoots(rootDir, scanDirs = []) {
135
+ return [...new Set([rootDir, ...scanDirs].filter(Boolean))];
136
+ }
137
+ function createDirectoryDefinitionSource(source, scanDirs, subdir, options = {}) {
138
+ return {
139
+ ...options,
140
+ kind: "directory",
141
+ scanDirs,
142
+ source,
143
+ subdir
144
+ };
145
+ }
146
+ function createSuffixDefinitionSource(source, roots, pattern, normalizeName, options = {}) {
147
+ return {
148
+ ...options,
149
+ kind: "suffix",
150
+ normalizeName,
151
+ pattern,
152
+ roots,
153
+ source
154
+ };
155
+ }
156
+ function readDirEntries(root) {
157
+ try {
158
+ return readdirSync(root, { withFileTypes: true });
159
+ } catch (error) {
160
+ if (error.code === "ENOENT") return [];
161
+ throw error;
162
+ }
163
+ }
164
+ function listMatchingFiles(root, predicate, options = {}) {
165
+ const files = [];
166
+ for (const entry of readDirEntries(root)) {
167
+ const absolute = resolve(root, entry.name);
168
+ if (entry.isDirectory() && !entry.isSymbolicLink()) {
169
+ if (entry.name.startsWith(".")) continue;
170
+ if (ignoredDirs.has(entry.name)) continue;
171
+ files.push(...listMatchingFiles(absolute, predicate, options));
172
+ continue;
173
+ }
174
+ if (entry.name.startsWith(".") && !options.includeHidden) continue;
175
+ if (entry.isFile() && predicate(entry.name)) files.push(absolute);
176
+ }
177
+ return files.sort();
178
+ }
179
+ function listSourceFiles(root, options = {}) {
180
+ return listMatchingFiles(root, (name) => sourceFilePattern.test(name) && !declarationFilePattern.test(name), options);
181
+ }
182
+ function normalizePathDefinitionName(rootDir, file) {
183
+ return relative(rootDir, file).replace(sourceFilePattern, "").replace(/\/index$/i, "");
184
+ }
185
+ function normalizeSuffixDefinitionName(rootDir, file, pattern, options = {}) {
186
+ const normalized = relative(rootDir, file).replace(pattern, "");
187
+ if (options.stripPrefix && normalized.startsWith(options.stripPrefix)) return normalized.slice(options.stripPrefix.length);
188
+ return normalized;
189
+ }
190
+ function sortDefinitions(definitions) {
191
+ return [...definitions.values()].sort((left, right) => left.name.localeCompare(right.name));
192
+ }
193
+ function registerDefinition(definitions, definition, sourceLabel) {
194
+ const existing = definitions.get(definition.name);
195
+ if (existing) throw new Error(`Duplicate ${sourceLabel} name "${definition.name}":\n - ${existing.handler}\n - ${definition.handler}`);
196
+ definitions.set(definition.name, definition);
197
+ }
198
+ function mergeDefinitions(feature, ...sources) {
199
+ const definitions = /* @__PURE__ */ new Map();
200
+ for (const source of sources) {
201
+ if (!source) continue;
202
+ for (const definition of source) {
203
+ const existing = definitions.get(definition.name);
204
+ if (existing && existing.handler !== definition.handler) throw new Error(`Duplicate ${feature} name "${definition.name}" from multiple discovery sources:\n - ${existing.handler} (${existing.source ?? "unknown"})\n - ${definition.handler} (${definition.source ?? "unknown"})`);
205
+ if (!existing) definitions.set(definition.name, definition);
206
+ }
207
+ }
208
+ return sortDefinitions(definitions);
209
+ }
210
+ function createDefinition(source, file, name) {
211
+ if (source.createDefinition) return source.createDefinition({
212
+ file,
213
+ name
214
+ });
215
+ return {
216
+ handler: file,
217
+ name,
218
+ source: source.source
219
+ };
220
+ }
221
+ function scanSuffixDefinitions(feature, source) {
222
+ const definitions = /* @__PURE__ */ new Map();
223
+ for (const root of source.roots) for (const file of listMatchingFiles(root, (name) => source.pattern.test(name), { includeHidden: source.includeHidden })) {
224
+ const name = source.normalizeName(root, file);
225
+ if (!name) continue;
226
+ registerDefinition(definitions, createDefinition(source, file, name), feature);
227
+ }
228
+ return sortDefinitions(definitions);
229
+ }
230
+ function scanDirectoryDefinitions(feature, source) {
231
+ const definitions = /* @__PURE__ */ new Map();
232
+ for (const scanDir of source.scanDirs) {
233
+ const directory = resolve(scanDir, source.subdir);
234
+ for (const file of listSourceFiles(directory, { includeHidden: source.includeHidden })) {
235
+ const name = source.normalizeName ? source.normalizeName(directory, file) : normalizePathDefinitionName(directory, file);
236
+ if (!name) continue;
237
+ registerDefinition(definitions, createDefinition(source, file, name), feature);
238
+ }
239
+ }
240
+ return sortDefinitions(definitions);
241
+ }
242
+ function discoverDefinitions(feature, sources) {
243
+ return mergeDefinitions(feature, ...sources.map((source) => source.kind === "suffix" ? scanSuffixDefinitions(feature, source) : scanDirectoryDefinitions(feature, source)));
244
+ }
245
+ function createImportExpression(registryFile, file) {
246
+ const importPath = relative(resolve(registryFile, ".."), file);
247
+ return `import(${JSON.stringify(importPath.startsWith(".") ? importPath : `./${importPath}`)})`;
248
+ }
249
+ function createRuntimeRegistryContents(registryFile, definitions) {
250
+ const needsWorkflowRuntime = definitions.some((definition) => definition.steps?.length);
251
+ const runtimeImport = needsWorkflowRuntime ? [`import { createWorkflowSteps } from "@vite-hub/workflow/runtime/execute"`, `import { takeInlineWorkflowDefinitionForModule } from "@vite-hub/workflow/runtime/state"`] : [];
252
+ const imports = definitions.map((definition) => {
253
+ if (!definition.steps?.length) return ` ${JSON.stringify(definition.name)}: async () => ${createImportExpression(registryFile, definition.handler)},`;
254
+ const workflowDirectory = /\.(?:c|m)?[jt]s$/i.test(definition.handler) ? dirname(definition.handler) : definition.handler;
255
+ const stepImports = definition.steps.map((step) => {
256
+ const stepName = relative(workflowDirectory, step);
257
+ return `{ name: ${JSON.stringify(stepName)}, run: (await ${createImportExpression(registryFile, step)}).default }`;
258
+ });
259
+ const hasIndex = /\.(?:c|m)?[jt]s$/i.test(definition.handler);
260
+ const indexImport = hasIndex ? `const index = await ${createImportExpression(registryFile, definition.handler)}` : "";
261
+ const handler = hasIndex ? `index.default?.handler ? index.default : takeInlineWorkflowDefinitionForModule(${JSON.stringify(definition.name)}, index) || { handler: index.default }` : "{ handler: async (context) => { let value = context.payload; for (const step of Object.values(context.steps || {})) value = await step(value); return value } }";
262
+ return [
263
+ ` ${JSON.stringify(definition.name)}: async () => {`,
264
+ ` const cached = registryEntryCache.get(${JSON.stringify(definition.name)})`,
265
+ " if (cached) return cached",
266
+ indexImport ? ` ${indexImport}` : "",
267
+ ` const steps = [${stepImports.join(", ")}]`,
268
+ ` const definition = ${handler}`,
269
+ " const entry = {",
270
+ " ...definition,",
271
+ " options: { ...definition.options, rootStep: false },",
272
+ " handler: async (context) => {",
273
+ " const workflowSteps = createWorkflowSteps(context, steps)",
274
+ " return await definition.handler({ ...context, steps: workflowSteps })",
275
+ " },",
276
+ " }",
277
+ ` registryEntryCache.set(${JSON.stringify(definition.name)}, entry)`,
278
+ " return entry",
279
+ " },"
280
+ ].filter(Boolean).join("\n");
281
+ });
282
+ return [
283
+ ...runtimeImport,
284
+ runtimeImport.length ? "" : "",
285
+ ...needsWorkflowRuntime ? ["const registryEntryCache = new Map()", ""] : [],
286
+ "const registry = {",
287
+ ...imports,
288
+ "}",
289
+ "",
290
+ "export default registry",
291
+ ""
292
+ ].join("\n");
293
+ }
294
+ function createGeneratedDefinitionPath(rootDir, options) {
295
+ const segments = options.segments ?? generatedDirSegments(options.productName);
296
+ return resolve(...options.buildDir ? [
297
+ rootDir,
298
+ options.buildDir,
299
+ ...segments,
300
+ options.fileName
301
+ ] : [
302
+ rootDir,
303
+ ...segments,
304
+ options.fileName
305
+ ]);
306
+ }
307
+ function createNitroRuntimeFilePath(rootDir, options) {
308
+ return createGeneratedDefinitionPath(rootDir, options);
309
+ }
310
+ function applyNitroRuntimeAliases(nitro, aliases) {
311
+ nitro.options.alias ||= {};
312
+ Object.assign(nitro.options.alias, aliases);
313
+ }
314
+ function hookNitroRuntimeRegistryRefresh(nitro, refresh, onRefresh = () => {}) {
315
+ for (const hookName of ["build:before", "dev:reload"]) nitro.hooks.hook(hookName, async () => {
316
+ await onRefresh(await refresh(), hookName);
317
+ });
318
+ }
319
+ async function writeFileIfChanged(file, contents) {
320
+ if (await readFile(file, "utf8").catch(() => void 0) === contents) return;
321
+ await mkdir(resolve(file, ".."), { recursive: true });
322
+ await writeFile(file, contents, "utf8");
323
+ }
324
+ //#endregion
325
+ //#region src/discovery.ts
326
+ const scheduleSuffixPattern = /\.schedule\.(?:c|m)?[jt]s$/i;
327
+ function skipLineComment(source, index) {
328
+ const newline = source.indexOf("\n", index + 2);
329
+ return newline === -1 ? source.length : newline + 1;
330
+ }
331
+ function skipBlockComment(source, index) {
332
+ const close = source.indexOf("*/", index + 2);
333
+ return close === -1 ? source.length : close + 2;
334
+ }
335
+ function skipQuoted(source, index) {
336
+ const quote = source[index];
337
+ index += 1;
338
+ while (index < source.length) {
339
+ if (source[index] === "\\") {
340
+ index += 2;
341
+ continue;
342
+ }
343
+ if (source[index] === quote) return index + 1;
344
+ index += 1;
345
+ }
346
+ return source.length;
347
+ }
348
+ function skipIgnorable(source, index) {
349
+ while (index < source.length) {
350
+ if (/\s/.test(source[index])) {
351
+ index += 1;
352
+ continue;
353
+ }
354
+ if (source.startsWith("//", index)) {
355
+ index = skipLineComment(source, index);
356
+ continue;
357
+ }
358
+ if (source.startsWith("/*", index)) {
359
+ index = skipBlockComment(source, index);
360
+ continue;
361
+ }
362
+ break;
363
+ }
364
+ return index;
365
+ }
366
+ function previousSignificantToken(source, index) {
367
+ let cursor = index - 1;
368
+ while (cursor >= 0 && /\s/.test(source[cursor])) cursor -= 1;
369
+ if (cursor < 0) return "";
370
+ const wordEnd = cursor + 1;
371
+ while (cursor >= 0 && /[$\w]/.test(source[cursor])) cursor -= 1;
372
+ if (cursor < wordEnd - 1) return source.slice(cursor + 1, wordEnd);
373
+ return source[cursor];
374
+ }
375
+ function canStartRegexLiteral(source, index) {
376
+ const token = previousSignificantToken(source, index);
377
+ return token === "" || token === "await" || token === "case" || token === "delete" || token === "return" || token === "throw" || token === "typeof" || token === "void" || /^[({[=,:;!&|?+\-*%^~<>]$/.test(token);
378
+ }
379
+ function skipRegexLiteral(source, index) {
380
+ let inCharacterClass = false;
381
+ for (let cursor = index + 1; cursor < source.length; cursor += 1) {
382
+ const char = source[cursor];
383
+ if (char === "\\") {
384
+ cursor += 1;
385
+ continue;
386
+ }
387
+ if (char === "[") {
388
+ inCharacterClass = true;
389
+ continue;
390
+ }
391
+ if (char === "]") {
392
+ inCharacterClass = false;
393
+ continue;
394
+ }
395
+ if (char === "/" && !inCharacterClass) {
396
+ cursor += 1;
397
+ while (/[a-z]/i.test(source[cursor] ?? "")) cursor += 1;
398
+ return cursor;
399
+ }
400
+ }
401
+ return source.length;
402
+ }
403
+ function isInsideNonCode(source, targetIndex) {
404
+ for (let index = 0; index < targetIndex; index += 1) {
405
+ const char = source[index];
406
+ if (char === "\"" || char === "'" || char === "`") {
407
+ const quotedEnd = skipQuoted(source, index);
408
+ if (targetIndex < quotedEnd) return true;
409
+ index = quotedEnd - 1;
410
+ continue;
411
+ }
412
+ if (source.startsWith("//", index)) {
413
+ const commentEnd = skipLineComment(source, index);
414
+ if (targetIndex < commentEnd) return true;
415
+ index = commentEnd - 1;
416
+ continue;
417
+ }
418
+ if (source.startsWith("/*", index)) {
419
+ const commentEnd = skipBlockComment(source, index);
420
+ if (targetIndex < commentEnd) return true;
421
+ index = commentEnd - 1;
422
+ }
423
+ }
424
+ return false;
425
+ }
426
+ function readBalancedObject(source, openIndex) {
427
+ if (source[openIndex] !== "{") return void 0;
428
+ let depth = 0;
429
+ for (let index = openIndex; index < source.length; index += 1) {
430
+ const char = source[index];
431
+ if (char === "\"" || char === "'" || char === "`") {
432
+ index = skipQuoted(source, index) - 1;
433
+ continue;
434
+ }
435
+ if (source.startsWith("//", index)) {
436
+ index = skipLineComment(source, index) - 1;
437
+ continue;
438
+ }
439
+ if (source.startsWith("/*", index)) {
440
+ index = skipBlockComment(source, index) - 1;
441
+ continue;
442
+ }
443
+ if (char === "/" && canStartRegexLiteral(source, index)) {
444
+ index = skipRegexLiteral(source, index) - 1;
445
+ continue;
446
+ }
447
+ if (char === "{") depth += 1;
448
+ if (char === "}") {
449
+ depth -= 1;
450
+ if (depth === 0) return source.slice(openIndex + 1, index);
451
+ }
452
+ }
453
+ }
454
+ function splitTopLevelProperties(source) {
455
+ const properties = [];
456
+ let depth = 0;
457
+ let start = 0;
458
+ for (let index = 0; index < source.length; index += 1) {
459
+ const char = source[index];
460
+ if (char === "\"" || char === "'" || char === "`") {
461
+ index = skipQuoted(source, index) - 1;
462
+ continue;
463
+ }
464
+ if (source.startsWith("//", index)) {
465
+ index = skipLineComment(source, index) - 1;
466
+ continue;
467
+ }
468
+ if (source.startsWith("/*", index)) {
469
+ index = skipBlockComment(source, index) - 1;
470
+ continue;
471
+ }
472
+ if (char === "/" && canStartRegexLiteral(source, index)) {
473
+ index = skipRegexLiteral(source, index) - 1;
474
+ continue;
475
+ }
476
+ if (char === "{" || char === "[" || char === "(") depth += 1;
477
+ if (char === "}" || char === "]" || char === ")") depth -= 1;
478
+ if (char === "," && depth === 0) {
479
+ properties.push(source.slice(start, index));
480
+ start = index + 1;
481
+ }
482
+ }
483
+ properties.push(source.slice(start));
484
+ return properties;
485
+ }
486
+ function readTopLevelBooleanProperty(objectSource, propertyName) {
487
+ for (const property of splitTopLevelProperties(objectSource)) {
488
+ const colon = property.indexOf(":");
489
+ if (colon === -1) continue;
490
+ if (stripBoundaryComments(property.slice(0, colon)).replace(/^["'`](.*)["'`]$/s, "$1") !== propertyName) continue;
491
+ const value = stripBoundaryComments(property.slice(colon + 1));
492
+ if (value === "true") return true;
493
+ if (value === "false") return false;
494
+ }
495
+ }
496
+ function stripBoundaryComments(source) {
497
+ return source.replace(/^(?:\s|\/\/[^\n]*(?:\n|$)|\/\*[\s\S]*?\*\/)+/, "").replace(/(?:\s|\/\/[^\n]*(?:\n|$)|\/\*[\s\S]*?\*\/)+$/, "");
498
+ }
499
+ function findTypeParametersEnd(source, index) {
500
+ let depth = 0;
501
+ for (let cursor = index; cursor < source.length; cursor += 1) {
502
+ const char = source[cursor];
503
+ if (char === "<") depth += 1;
504
+ if (char === ">" && source[cursor - 1] === "=") continue;
505
+ if (char === ">") {
506
+ depth -= 1;
507
+ if (depth === 0) return cursor;
508
+ }
509
+ }
510
+ return -1;
511
+ }
512
+ function readDefineScheduleObjectAfterDefault(source, index) {
513
+ let cursor = skipIgnorable(source, index);
514
+ let openParens = 0;
515
+ while (source[cursor] === "(") {
516
+ openParens += 1;
517
+ cursor = skipIgnorable(source, cursor + 1);
518
+ }
519
+ if (!source.startsWith("defineSchedule", cursor)) return void 0;
520
+ cursor += 14;
521
+ cursor = skipIgnorable(source, cursor);
522
+ if (source[cursor] === "<") {
523
+ const close = findTypeParametersEnd(source, cursor);
524
+ if (close === -1) return void 0;
525
+ cursor = skipIgnorable(source, close + 1);
526
+ }
527
+ if (source[cursor] !== "(") return void 0;
528
+ cursor = skipIgnorable(source, cursor + 1);
529
+ const objectSource = readBalancedObject(source, cursor);
530
+ if (!objectSource) return void 0;
531
+ let afterObject = skipIgnorable(source, cursor + objectSource.length + 2);
532
+ if (source[afterObject] === ")") afterObject = skipIgnorable(source, afterObject + 1);
533
+ while (openParens > 0 && source[afterObject] === ")") {
534
+ openParens -= 1;
535
+ afterObject = skipIgnorable(source, afterObject + 1);
536
+ }
537
+ return openParens === 0 ? objectSource : void 0;
538
+ }
539
+ function readDefaultDefineScheduleObject(source) {
540
+ let match;
541
+ const pattern = /\bexport\s+default\b/g;
542
+ while (match = pattern.exec(source)) {
543
+ if (isInsideNonCode(source, match.index)) continue;
544
+ const objectSource = readDefineScheduleObjectAfterDefault(source, match.index + match[0].length);
545
+ if (objectSource) return objectSource;
546
+ }
547
+ }
548
+ function readAllowRuntimeSchedules(file) {
549
+ const objectSource = readDefaultDefineScheduleObject(readFileSync(file, "utf8"));
550
+ return objectSource ? readTopLevelBooleanProperty(objectSource, "allowRuntimeSchedules") === true : false;
551
+ }
552
+ function createDiscoveredScheduleDefinition(source) {
553
+ return (context) => ({
554
+ allowRuntimeSchedules: readAllowRuntimeSchedules(context.file),
555
+ handler: context.file,
556
+ name: context.name,
557
+ source
558
+ });
559
+ }
560
+ function normalizeSuffixScheduleName(rootDir, file) {
561
+ return normalizeSuffixDefinitionName(rootDir, file, scheduleSuffixPattern, { stripPrefix: "src/" });
562
+ }
563
+ function normalizeDirectoryScheduleName(directory, file) {
564
+ return normalizePathDefinitionName(directory, file);
565
+ }
566
+ function discoverScheduleDefinitions(options) {
567
+ if (options.mode === "nitro-server-schedules") return discoverDefinitions("schedule", [createDirectoryDefinitionSource("nitro-server-schedules", options.scanDirs, "schedules", {
568
+ createDefinition: createDiscoveredScheduleDefinition("nitro-server-schedules"),
569
+ normalizeName: normalizeDirectoryScheduleName
570
+ })]);
571
+ return discoverDefinitions("schedule", [createSuffixDefinitionSource("vite-suffix", resolveDefinitionScanRoots(options.rootDir, options.scanDirs), scheduleSuffixPattern, normalizeSuffixScheduleName, { createDefinition: createDiscoveredScheduleDefinition("vite-suffix") })]);
572
+ }
573
+ //#endregion
574
+ export { hookNitroRuntimeRegistryRefresh as a, ensureGeneratedDir as c, createRuntimeRegistryContents as i, applyNitroRuntimeAliases as n, writeFileIfChanged as o, createNitroRuntimeFilePath as r, createImportPath as s, discoverScheduleDefinitions as t };
@@ -0,0 +1,59 @@
1
+ import { _ as ScheduleRunStatus, a as RuntimeScheduleStore, c as ScheduleDefinitionInput, d as ScheduleHandler, f as ScheduleRunAttemptRecord, g as ScheduleRunRecord, h as ScheduleRunError, i as RuntimeScheduleRecord, m as ScheduleRunContext, n as RuntimeScheduleCreateInput, o as RuntimeScheduleUpdateInput, p as ScheduleRunAttemptStatus, r as RuntimeScheduleMetadata, s as ScheduleDefinition, t as DiscoveredScheduleDefinition, u as ScheduleDefinitionRegistry, v as ScheduleRunStore, y as ScheduleTargetName } from "./types-DOjXDq0s.js";
2
+ import { a as createMemoryRuntimeScheduleStore, c as validateRuntimeScheduleCron, i as createKVScheduleRunStore, l as ScheduleError, n as ScheduleKVStorage, o as createMemoryScheduleRunStore, r as createKVRuntimeScheduleStore, s as schedules, t as KVScheduleStoreOptions } from "./store-CeeSsInC.js";
3
+ import { getRuntimeScheduleStore, getScheduleRunStore, getScheduleRuntimeRegistry, loadScheduleDefinition, resetScheduleRuntime, setRuntimeScheduleStore, setScheduleRunStore, setScheduleRuntimeRegistry } from "./runtime/state.js";
4
+
5
+ //#region src/definition.d.ts
6
+ declare function defineSchedule<TResult = unknown>(input: ScheduleDefinitionInput<TResult>): ScheduleDefinition<TResult>;
7
+ //#endregion
8
+ //#region src/discovery.d.ts
9
+ declare function discoverScheduleDefinitions(options: {
10
+ mode?: "vite-suffix";
11
+ rootDir: string;
12
+ scanDirs?: string[];
13
+ } | {
14
+ mode: "nitro-server-schedules";
15
+ scanDirs: string[];
16
+ }): DiscoveredScheduleDefinition[];
17
+ //#endregion
18
+ //#region src/runtime/execute.d.ts
19
+ interface ExecuteScheduleOptions {
20
+ definition: ScheduleDefinition;
21
+ runStore?: ScheduleRunStore;
22
+ scheduleId: string;
23
+ source?: "direct" | "runtime" | "static";
24
+ scheduledAt?: Date;
25
+ target: ScheduleTargetName;
26
+ }
27
+ interface ExecuteStaticScheduleOptions {
28
+ cron: string;
29
+ definition: ScheduleDefinition;
30
+ name: string;
31
+ scheduledAt?: Date;
32
+ }
33
+ interface ExecuteRuntimeScheduleOptions {
34
+ id: string;
35
+ runtimeScheduleStore?: RuntimeScheduleStore;
36
+ scheduledAt?: Date;
37
+ scheduleRunStore?: ScheduleRunStore;
38
+ }
39
+ declare function createScheduleRun(options: Omit<ExecuteScheduleOptions, "definition">): Promise<ScheduleRunRecord>;
40
+ declare function executeSchedule(options: ExecuteScheduleOptions): Promise<ScheduleRunRecord>;
41
+ declare function executeStaticSchedule(options: ExecuteStaticScheduleOptions): Promise<ScheduleRunRecord>;
42
+ declare function executeRuntimeSchedule(options: ExecuteRuntimeScheduleOptions | string): Promise<ScheduleRunRecord>;
43
+ //#endregion
44
+ //#region src/runtime/runner.d.ts
45
+ interface ScheduleRunnerController {
46
+ readonly running: boolean;
47
+ stop: () => void;
48
+ }
49
+ interface ScheduleRunnerOptions {
50
+ concurrency?: number;
51
+ intervalMs?: number;
52
+ now?: () => Date;
53
+ onError?: (error: unknown) => void;
54
+ runtimeScheduleStore?: RuntimeScheduleStore;
55
+ scheduleRunStore?: ScheduleRunStore;
56
+ }
57
+ declare function startScheduleRunner(options?: ScheduleRunnerOptions): ScheduleRunnerController;
58
+ //#endregion
59
+ export { type DiscoveredScheduleDefinition, type KVScheduleStoreOptions, type RuntimeScheduleCreateInput, type RuntimeScheduleMetadata, type RuntimeScheduleRecord, type RuntimeScheduleStore, type RuntimeScheduleUpdateInput, type ScheduleDefinition, type ScheduleDefinitionInput, type ScheduleDefinitionRegistry, ScheduleError, type ScheduleHandler, type ScheduleKVStorage, type ScheduleRunAttemptRecord, type ScheduleRunAttemptStatus, type ScheduleRunContext, type ScheduleRunError, type ScheduleRunRecord, type ScheduleRunStatus, type ScheduleRunStore, type ScheduleRunnerController, type ScheduleRunnerOptions, type ScheduleTargetName, createKVRuntimeScheduleStore, createKVScheduleRunStore, createMemoryRuntimeScheduleStore, createMemoryScheduleRunStore, createScheduleRun, defineSchedule, discoverScheduleDefinitions, executeRuntimeSchedule, executeSchedule, executeStaticSchedule, getRuntimeScheduleStore, getScheduleRunStore, getScheduleRuntimeRegistry, loadScheduleDefinition, resetScheduleRuntime, schedules, setRuntimeScheduleStore, setScheduleRunStore, setScheduleRuntimeRegistry, startScheduleRunner, validateRuntimeScheduleCron };