@vite-hub/schedule 0.0.4 → 0.3.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.
Files changed (62) hide show
  1. package/README.md +139 -58
  2. package/dist/console-wEhr0LWn.d.ts +330 -0
  3. package/dist/definition.d.ts +8 -6
  4. package/dist/definition.js +34 -28
  5. package/dist/due-BVMRQ93v.js +144 -0
  6. package/dist/durability.d.ts +14 -0
  7. package/dist/durability.js +23 -0
  8. package/dist/error-diagnostics-DSkCJC_L.js +266 -0
  9. package/dist/error-diagnostics-Mpeks7J0.js +166 -0
  10. package/dist/index.d.ts +61 -40
  11. package/dist/index.js +27 -7
  12. package/dist/inspect-DTfAo5gS.js +118 -0
  13. package/dist/invariant-DolT9EEx.js +22 -0
  14. package/dist/kv-storage-C0KZZB6v.d.ts +18 -0
  15. package/dist/{kv-storage-DWinmLLy.js → kv-storage-iJChCS5A.js} +2 -2
  16. package/dist/object-Da1zyPCR.js +11 -0
  17. package/dist/operation-definition-8gOe-ubD.d.ts +234 -0
  18. package/dist/operations-DwZWFIUX.js +184 -0
  19. package/dist/operations.d.ts +84 -0
  20. package/dist/operations.js +318 -0
  21. package/dist/os.d.ts +167 -0
  22. package/dist/os.js +1659 -0
  23. package/dist/registry-module.d.ts +0 -5
  24. package/dist/runtime/console.d.ts +12 -0
  25. package/dist/runtime/console.js +85 -0
  26. package/dist/runtime/kv.d.ts +4 -0
  27. package/dist/{kv-BJ1I9IlJ.js → runtime/kv.js} +1 -1
  28. package/dist/runtime/process.d.ts +53 -5
  29. package/dist/runtime/process.js +501 -251
  30. package/dist/runtime/state.d.ts +2 -13
  31. package/dist/runtime/state.js +2 -2
  32. package/dist/runtime/static.d.ts +44 -12
  33. package/dist/runtime/static.js +2 -150
  34. package/dist/runtime.d.ts +38 -4
  35. package/dist/runtime.js +6 -3
  36. package/dist/started-BuGmnus4.js +201 -0
  37. package/dist/started-Bx7MDbrl.js +146 -0
  38. package/dist/started-errors-p7cu_rI7.js +250 -0
  39. package/dist/state-B-Fuyfb4.js +468 -0
  40. package/dist/state-Do2wV4Tx.d.ts +49 -0
  41. package/dist/static-DQwzzvPg.js +266 -0
  42. package/dist/store-Df0-fzCl.d.ts +53 -0
  43. package/dist/time-zone-SBldrUgt.js +59 -0
  44. package/dist/types-Cw5LjPuc.d.ts +167 -0
  45. package/dist/vite.d.ts +214 -11
  46. package/dist/vite.js +5876 -3
  47. package/dist/wait-until-Dy4Bn3ZN.js +112 -0
  48. package/package.json +65 -24
  49. package/dist/client-DpCD4YFE.js +0 -233
  50. package/dist/discovery-DkFAN7Wd.d.ts +0 -15
  51. package/dist/discovery-DvU3B6iD.js +0 -753
  52. package/dist/due-Bbh4yIxq.js +0 -59
  53. package/dist/execute-B-pii4wf.js +0 -211
  54. package/dist/nuxt.d.ts +0 -19
  55. package/dist/nuxt.js +0 -26
  56. package/dist/runtime/driver.d.ts +0 -26
  57. package/dist/runtime/driver.js +0 -337
  58. package/dist/state-By7WU_ks.js +0 -472
  59. package/dist/store-t-74rsM_.d.ts +0 -48
  60. package/dist/types-Bcje4dLV.d.ts +0 -136
  61. package/dist/vite-BHs17nWX.js +0 -4166
  62. package/dist/wait-until-BzIwzXw4.js +0 -23
@@ -0,0 +1,166 @@
1
+ import { defineDiagnostics } from "nostics";
2
+ //#region src/error-diagnostics.ts
3
+ const dynamicError = { why: ({ message }) => message === void 0 ? "" : String(message) };
4
+ const scheduleErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
5
+ docsBase: "https://vitehub.dev/docs/schedule/diagnostics",
6
+ codes: {
7
+ SCHEDULE_DEFINITION_NOT_FOUND: {
8
+ why: "Schedule run is not available. Set manual: true on the Schedule Definition and enable Console invocation.",
9
+ fix: "Set `manual: true` in defineSchedule() and keep `console.invoke` on (it is on in development)."
10
+ },
11
+ SCHEDULE_HISTORY_INCOMPLETE: {
12
+ why: ({ maxRecords, recordCount }) => `Schedule run history is incomplete because ${recordCount} records have no usable metadata index (maximum fallback is ${maxRecords}). Rebuild the schedule run index before listing history.`,
13
+ fix: "Rebuild the Schedule run index of the store, as the message says, before you list the history."
14
+ },
15
+ SCHEDULE_OPERATION_FAILED: {
16
+ why: "Schedule operation failed.",
17
+ fix: "Read `error.cause` for the error of the Schedule store or handler. Check that the store is reachable, then retry."
18
+ },
19
+ SCHEDULE_RUN_NOT_FOUND: {
20
+ why: "Schedule Run was not found.",
21
+ fix: "List the runs of the Schedule with `vitehub schedule runs <name>` and pass one of their ids."
22
+ },
23
+ SCHEDULE_C0001: {
24
+ ...dynamicError,
25
+ fix: "Pass `cron` to `defineSchedule()` as a non-empty string without spaces around it, such as `defineSchedule({ cron: \"0 9 * * *\", handler })`. Remove `cron` for a Schedule that only `startSchedule()` starts."
26
+ },
27
+ SCHEDULE_C0002: {
28
+ ...dynamicError,
29
+ fix: "Write `cron` as five fields with one space between them (minute, hour, day of month, month, day of week), such as `\"0 9 * * 1-5\"`."
30
+ },
31
+ SCHEDULE_C0003: {
32
+ ...dynamicError,
33
+ fix: "Pass one object with a `handler` to `defineSchedule()`, such as `defineSchedule({ cron: \"0 9 * * *\", handler })`."
34
+ },
35
+ SCHEDULE_C0004: {
36
+ ...dynamicError,
37
+ fix: "Use only the `cron`, `handler`, `manual`, and `timeZone` options in `defineSchedule()`, written in the object itself. Remove the other options."
38
+ },
39
+ SCHEDULE_C0005: {
40
+ ...dynamicError,
41
+ fix: "Set `handler` in `defineSchedule()` to a function, such as `handler: async () => { ... }`."
42
+ },
43
+ SCHEDULE_C0006: {
44
+ ...dynamicError,
45
+ fix: "Set `manual` in `defineSchedule()` to `true` or `false`. Set `timeZone` only together with `cron`, and use an IANA time zone, such as `\"Europe/Madrid\"`."
46
+ },
47
+ SCHEDULE_C0007: {
48
+ ...dynamicError,
49
+ fix: "Write `defineSchedule({ cron, handler })`. Run `npx @vite-hub/codemods define-forms` to rewrite every Schedule."
50
+ },
51
+ SCHEDULE_R0003: {
52
+ ...dynamicError,
53
+ fix: "Write `cron` of `defineSchedule()` as a five-field cron string, such as `\"0 9 * * 1\"`, and `timeZone` as a string literal with an IANA name, such as `\"Europe/Madrid\"`."
54
+ },
55
+ SCHEDULE_R0004: {
56
+ ...dynamicError,
57
+ fix: "Write `cron` of `defineSchedule()` as a string literal, such as `cron: \"0 9 * * *\"`."
58
+ },
59
+ SCHEDULE_R0005: {
60
+ ...dynamicError,
61
+ fix: "Rename one of the two Schedule files that the message names, so that their Vercel function paths are different."
62
+ },
63
+ SCHEDULE_R0006: {
64
+ ...dynamicError,
65
+ fix: "Rename one of the two Schedule files that the message names, so that their Netlify function files are different."
66
+ },
67
+ SCHEDULE_R0022: {
68
+ ...dynamicError,
69
+ fix: "Set `timeZone` of the Schedule to an IANA time zone that the host supports, such as `\"Europe/Madrid\"`, or remove it to use UTC."
70
+ },
71
+ SCHEDULE_R0023: {
72
+ ...dynamicError,
73
+ fix: "Write `cron` of the Schedule as five fields: minute, hour, day of the month, month, and day of the week."
74
+ },
75
+ SCHEDULE_R0024: {
76
+ ...dynamicError,
77
+ fix: "Set Schedule `runtime.leaseTtlMs` and `runtime.intervalMs` to numbers greater than zero, with `intervalMs` at most 60000, and `runtime.catchUpMs` to 0 or more. Or omit them to use the defaults."
78
+ },
79
+ SCHEDULE_R0025: {
80
+ ...dynamicError,
81
+ fix: "Set Schedule `runtime.concurrency` to a whole number of 1 or more, or omit it to run one Schedule at a time."
82
+ },
83
+ SCHEDULE_R0026: {
84
+ ...dynamicError,
85
+ fix: "Do not call the Process Schedule Runtime after `close()`. Install a new runtime with `installProcessScheduleRuntime()` if the process must run Schedules again."
86
+ },
87
+ SCHEDULE_R0027: {
88
+ ...dynamicError,
89
+ fix: "Send the Cloudflare scheduled event with a cron string. With `wrangler dev --test-scheduled`, call `/__scheduled?cron=*+*+*+*+*`."
90
+ },
91
+ SCHEDULE_R0028: {
92
+ ...dynamicError,
93
+ fix: "Send the Cloudflare scheduled event with `scheduledTime` as a Unix time in milliseconds, or without `scheduledTime` to use the current time."
94
+ },
95
+ SCHEDULE_R0030: {
96
+ ...dynamicError,
97
+ fix: "Pass a new `id` to `createAttempt()` of the Schedule Run store."
98
+ },
99
+ SCHEDULE_R0031: {
100
+ ...dynamicError,
101
+ fix: "Pass a new `id` to `createRun()` of the Schedule Run store, or read the existing Run with `getRun(id)`."
102
+ },
103
+ SCHEDULE_R0032: {
104
+ ...dynamicError,
105
+ fix: "Pass a new `id` to `createAttempt()` of the Schedule Run store."
106
+ },
107
+ SCHEDULE_R0033: {
108
+ ...dynamicError,
109
+ fix: "Pass a new `id` to `createRun()` of the Schedule Run store, or read the existing Run with `getRun(id)`."
110
+ },
111
+ SCHEDULE_R0034: {
112
+ ...dynamicError,
113
+ fix: "Deploy the output of the current build, and keep the file under `server/schedules/` of each Schedule that the host still triggers."
114
+ },
115
+ SCHEDULE_R0035: {
116
+ ...dynamicError,
117
+ fix: "Read `error.cause` for the value that the Schedule handler threw, and fix the handler in `server/schedules/<name>.ts`. Throw an `Error` so that the run keeps its stack."
118
+ },
119
+ SCHEDULE_B0001: {
120
+ ...dynamicError,
121
+ fix: "Set `runtime: { driver: \"process\" }` in `hubSchedule()` or in `vitehub({ schedule })`, or remove `runtime` to let the host wake Schedules."
122
+ },
123
+ SCHEDULE_B0002: {
124
+ ...dynamicError,
125
+ fix: "Set `runtime.prefix` in `hubSchedule()` or in `vitehub({ schedule })` to a string, such as `\"my-app:schedule\"`, or remove it to use `vitehub:schedule`."
126
+ },
127
+ SCHEDULE_B0003: {
128
+ ...dynamicError,
129
+ fix: "Set `runtime.intervalMs` in `hubSchedule()` or in `vitehub({ schedule })` to a number greater than 0 and not more than `60000`, or remove it to use `60000`."
130
+ },
131
+ SCHEDULE_B0004: {
132
+ ...dynamicError,
133
+ fix: "Set `runtime.concurrency` in `hubSchedule()` or in `vitehub({ schedule })` to an integer of 1 or more, or remove it to use 1."
134
+ },
135
+ SCHEDULE_B0005: {
136
+ ...dynamicError,
137
+ fix: "Write the Schedule file that the message names as `export default defineSchedule({ cron: \"...\", handler })`, with literal option values and no spread or computed keys. If the file has a syntax error, correct it first."
138
+ },
139
+ SCHEDULE_B0006: {
140
+ ...dynamicError,
141
+ fix: "Rename or remove one of the two Schedule definitions that the message lists. Each Schedule name must have one file in `server/schedules/` or one plugin contribution."
142
+ },
143
+ SCHEDULE_B0007: {
144
+ ...dynamicError,
145
+ fix: "Correct the `vitehub.schedules` entry of the plugin that the message names. Give it a `name` and `definition: { module, export: \"default\" }`, where `module` is the absolute path or `file:` URL of a file that exists."
146
+ },
147
+ SCHEDULE_B0008: {
148
+ ...dynamicError,
149
+ fix: "Set `cron` in `hubSchedule()` or in `vitehub({ schedule })` to a map of Schedule names to cron strings, such as `{ cleanup: \"0 0 * * *\" }`, and use only the names of existing Schedules. With the Process Runtime, remove `cron`, or set `providerOutput` to `\"nitro\"` or `\"standalone\"`."
150
+ },
151
+ SCHEDULE_B0009: {
152
+ ...dynamicError,
153
+ fix: "Set Schedule `runtime.leaseTtlMs` to a finite number greater than zero, or omit it to use the 60000 ms default."
154
+ },
155
+ SCHEDULE_DEFINITION_EXPORT_INVALID: {
156
+ why: ({ name }) => `Schedule "${name}" has no default export of defineSchedule() with a cron and a handler.`,
157
+ fix: "Default-export `defineSchedule({ cron, handler })` from the Schedule file that the message names, in `server/schedules/`."
158
+ },
159
+ SCHEDULE_RUNTIME_CATCH_UP_INVALID: {
160
+ why: "Schedule Process Runtime catchUpMs must be a non-negative number.",
161
+ fix: "Set `runtime.catchUpMs` in `hubSchedule()` or in `vitehub({ schedule })` to a number of 0 or more, or remove it to use one hour (`3600000`)."
162
+ }
163
+ }
164
+ });
165
+ //#endregion
166
+ export { scheduleErrorDiagnostics as t };
package/dist/index.d.ts CHANGED
@@ -1,45 +1,66 @@
1
1
  /// <reference path="./registry-module.d.ts" />
2
- import { C as ScheduleTargetName, S as ScheduleTargetDefinitionInput, _ as ScheduleRunError, a as RuntimeScheduleStore, b as ScheduleRunStore, c as ScheduleDefinition, d as ScheduleDefinitionRegistry, f as ScheduleHandler, g as ScheduleRunContext, h as ScheduleRunAttemptStatus, i as RuntimeScheduleRecord, l as ScheduleDefinitionInput, m as ScheduleRunAttemptRecord, n as RuntimeScheduleCreateInput, o as RuntimeScheduleUpdateInput, p as ScheduleRegistryDefinition, r as RuntimeScheduleMetadata, t as DiscoveredScheduleDefinition, v as ScheduleRunRecord, x as ScheduleTargetDefinition, y as ScheduleRunStatus } from "./types-Bcje4dLV.js";
3
- import { defineSchedule, defineScheduleTarget } from "./definition.js";
4
- import { t as discoverScheduleDefinitions } from "./discovery-DkFAN7Wd.js";
5
- import { a as createMemoryScheduleRunStore, c as schedules, i as createMemoryRuntimeScheduleStore, l as validateRuntimeScheduleCron, n as createKVRuntimeScheduleStore, o as ScheduleKVStorage, r as createKVScheduleRunStore, s as createScheduleKVStorage, t as KVScheduleStoreOptions } from "./store-t-74rsM_.js";
6
- import { getRuntimeScheduleStore, getScheduleRunStore, getScheduleRuntimeRegistry, loadScheduleDefinition, resetScheduleRuntime, setRuntimeScheduleStore, setScheduleRunStore, setScheduleRuntimeRegistry } from "./runtime/state.js";
7
- import { ViteHubError } from "@vite-hub/runtime";
8
-
9
- //#region src/runtime/execute.d.ts
10
- interface ExecuteScheduleOptions {
11
- definition: ScheduleRegistryDefinition;
12
- input?: unknown;
13
- runStore?: ScheduleRunStore;
14
- scheduleId: string;
15
- source?: "direct" | "runtime" | "static";
16
- scheduledAt?: Date;
17
- target: ScheduleTargetName;
18
- waitUntil?: (promise: PromiseLike<unknown>) => void;
19
- }
20
- interface ExecuteStaticScheduleOptions {
21
- cron: string;
22
- definition: ScheduleDefinition;
23
- name: string;
24
- scheduledAt?: Date;
25
- waitUntil?: (promise: PromiseLike<unknown>) => void;
26
- }
27
- interface ExecuteRuntimeScheduleOptions {
28
- id: string;
29
- requireDue?: boolean;
30
- runtimeScheduleStore?: RuntimeScheduleStore;
31
- scheduledAt?: Date;
32
- scheduleRunStore?: ScheduleRunStore;
33
- waitUntil?: (promise: PromiseLike<unknown>) => void;
34
- }
35
- declare function createScheduleRun(options: Omit<ExecuteScheduleOptions, "definition" | "waitUntil">): Promise<ScheduleRunRecord>;
36
- declare function executeSchedule(options: ExecuteScheduleOptions): Promise<ScheduleRunRecord>;
37
- declare function executeStaticSchedule(options: ExecuteStaticScheduleOptions): Promise<ScheduleRunRecord>;
38
- declare function executeRuntimeSchedule(options: ExecuteRuntimeScheduleOptions | string): Promise<ScheduleRunRecord>;
2
+ import { _ as StartScheduleOptions, a as ScheduleDefinitionRegistry, b as StartedScheduleStore, c as ScheduleRunAttemptRecord, d as ScheduleRunError, f as ScheduleRunListOptions, g as ScheduleRunStore, h as ScheduleRunStatus, l as ScheduleRunAttemptStatus, m as ScheduleRunResponse, n as ScheduleDefinition, o as ScheduleHandler, p as ScheduleRunRecord, r as ScheduleDefinitionInput, s as ScheduleRegistryDefinition, t as DiscoveredScheduleDefinition, u as ScheduleRunContext, v as StartScheduleTiming, y as StartedSchedule } from "./types-Cw5LjPuc.js";
3
+ import { defineSchedule } from "./definition.js";
4
+ import { i as RunScheduleOptions, t as KVScheduleStoreOptions } from "./store-Df0-fzCl.js";
5
+ import { t as ScheduleKVStorage } from "./kv-storage-C0KZZB6v.js";
6
+ import { ErrorCatalog, Result, ViteHubError } from "@vite-hub/runtime";
7
+ //#region src/run.d.ts
8
+ /**
9
+ * Runs a Static Schedule Definition that sets `manual: true` now, as if its cron fired at `scheduledAt` (default: now).
10
+ * It resolves with the Schedule Run, also when the handler fails.
11
+ */
12
+ export declare function runSchedule(name: string, options?: RunScheduleOptions): Promise<ScheduleRunRecord>;
13
+ //#endregion
14
+ //#region src/started-errors.d.ts
15
+ type StartedScheduleErrorCodes = {
16
+ SCHEDULE_INVALID_OPTIONS: {
17
+ fix: string;
18
+ why: (data: {
19
+ problem: string;
20
+ }) => string;
21
+ };
22
+ SCHEDULE_NOT_FOUND: {
23
+ fix: string;
24
+ why: (data: {
25
+ id: string;
26
+ }) => string;
27
+ };
28
+ SCHEDULE_NOT_STARTABLE: {
29
+ fix: string;
30
+ why: (data: {
31
+ name: string;
32
+ }) => string;
33
+ };
34
+ SCHEDULE_STORE_FAILED: {
35
+ fix: string;
36
+ why: string;
37
+ };
38
+ SCHEDULE_STORE_MISSING: {
39
+ fix: string;
40
+ why: string;
41
+ };
42
+ };
43
+ type StartedScheduleErrorCode = keyof StartedScheduleErrorCodes;
44
+ //#endregion
45
+ //#region src/started.d.ts
46
+ /**
47
+ * Starts the Schedule Definition `name`, which declares no `cron`, at a time that code picks: once at `at`, or on each
48
+ * occurrence of `cron` in `timeZone` until `cancelSchedule()`. The store keeps it across restarts and deploys. The handler
49
+ * receives `payload` as `context.payload`.
50
+ */
51
+ export declare function startSchedule(name: string, options: StartScheduleOptions): Promise<Result<StartedSchedule, StartedScheduleErrorCode>>;
52
+ /** Reads one started Schedule. */
53
+ export declare function getSchedule(id: string): Promise<Result<StartedSchedule, StartedScheduleErrorCode>>;
54
+ /** Lists the started Schedules, oldest first. `name` keeps the Schedules of one Definition. */
55
+ export declare function listSchedules(options?: {
56
+ name?: string;
57
+ }): Promise<Result<StartedSchedule[], StartedScheduleErrorCode>>;
58
+ /** Removes a started Schedule, so it does not run again. A run that already started finishes. */
59
+ export declare function cancelSchedule(id: string): Promise<Result<StartedSchedule, StartedScheduleErrorCode>>;
39
60
  //#endregion
40
61
  //#region src/errors.d.ts
41
- declare const scheduleErrorCodes: readonly ["SCHEDULE_ALREADY_EXISTS", "SCHEDULE_DISABLED", "SCHEDULE_INVALID_CRON", "SCHEDULE_INVALID_ENABLED", "SCHEDULE_INVALID_ID", "SCHEDULE_INVALID_INPUT", "SCHEDULE_INVALID_SCHEDULED_AT", "SCHEDULE_INVALID_TARGET", "SCHEDULE_INVALID_TIME_ZONE", "SCHEDULE_NOT_DUE", "SCHEDULE_NOT_FOUND", "SCHEDULE_RUN_NOT_FOUND", "SCHEDULE_TARGET_NOT_ELIGIBLE", "SCHEDULE_TARGET_NOT_FOUND"];
42
- declare const scheduleErrorFields: readonly ["cron", "enabled", "id", "input", "options", "scheduledAt", "target", "timeZone"];
62
+ declare const scheduleErrorCodes: readonly ["SCHEDULE_DEFINITION_NOT_FOUND", "SCHEDULE_INVALID_CRON", "SCHEDULE_INVALID_SCHEDULED_AT", "SCHEDULE_MANUAL_RUN_DISABLED", "SCHEDULE_NOT_DUE", "SCHEDULE_RUN_NOT_FOUND"];
63
+ declare const scheduleErrorFields: readonly ["cron", "scheduledAt"];
43
64
  declare const scheduleErrorValueTypes: readonly ["array", "bigint", "boolean", "date", "function", "null", "number", "object", "string", "symbol", "undefined", "unknown"];
44
65
  type ScheduleErrorCode = typeof scheduleErrorCodes[number];
45
66
  type ScheduleErrorField = typeof scheduleErrorFields[number];
@@ -50,4 +71,4 @@ type ScheduleErrorDetails = {
50
71
  valueType: ScheduleErrorValueType;
51
72
  };
52
73
  //#endregion
53
- export { type DiscoveredScheduleDefinition, type KVScheduleStoreOptions, type RuntimeScheduleCreateInput, type RuntimeScheduleMetadata, type RuntimeScheduleRecord, type RuntimeScheduleStore, type RuntimeScheduleUpdateInput, type ScheduleDefinition, type ScheduleDefinitionInput, type ScheduleDefinitionRegistry, type ScheduleErrorCode, type ScheduleErrorDetails, type ScheduleErrorField, type ScheduleErrorValueType, type ScheduleHandler, type ScheduleKVStorage, type ScheduleRegistryDefinition, type ScheduleRunAttemptRecord, type ScheduleRunAttemptStatus, type ScheduleRunContext, type ScheduleRunError, type ScheduleRunRecord, type ScheduleRunStatus, type ScheduleRunStore, type ScheduleTargetDefinition, type ScheduleTargetDefinitionInput, type ScheduleTargetName, type ScheduleValidationErrorCode, createKVRuntimeScheduleStore, createKVScheduleRunStore, createMemoryRuntimeScheduleStore, createMemoryScheduleRunStore, createScheduleKVStorage, createScheduleRun, defineSchedule, defineScheduleTarget, discoverScheduleDefinitions, executeRuntimeSchedule, executeSchedule, executeStaticSchedule, getRuntimeScheduleStore, getScheduleRunStore, getScheduleRuntimeRegistry, loadScheduleDefinition, resetScheduleRuntime, schedules, setRuntimeScheduleStore, setScheduleRunStore, setScheduleRuntimeRegistry, validateRuntimeScheduleCron };
74
+ export { type DiscoveredScheduleDefinition, type KVScheduleStoreOptions, type RunScheduleOptions, type ScheduleDefinition, type ScheduleDefinitionInput, type ScheduleDefinitionRegistry, type ScheduleErrorCode, type ScheduleErrorDetails, type ScheduleErrorField, type ScheduleErrorValueType, type ScheduleHandler, type ScheduleKVStorage, type ScheduleRegistryDefinition, type ScheduleRunAttemptRecord, type ScheduleRunAttemptStatus, type ScheduleRunContext, type ScheduleRunError, type ScheduleRunListOptions, type ScheduleRunRecord, type ScheduleRunResponse, type ScheduleRunStatus, type ScheduleRunStore, type ScheduleValidationErrorCode, type StartScheduleOptions, type StartScheduleTiming, type StartedSchedule, type StartedScheduleErrorCode, type StartedScheduleStore, defineSchedule };
package/dist/index.js CHANGED
@@ -1,7 +1,27 @@
1
- import { defineSchedule, defineScheduleTarget } from "./definition.js";
2
- import { t as discoverScheduleDefinitions } from "./discovery-DvU3B6iD.js";
3
- import { a as executeStaticSchedule, i as executeSchedule, n as executeRuntimeSchedule, t as createScheduleRun } from "./execute-B-pii4wf.js";
4
- import { a as resetScheduleRuntime, c as setScheduleRuntimeRegistry, d as createMemoryRuntimeScheduleStore, f as createMemoryScheduleRunStore, i as loadScheduleDefinition, l as createKVRuntimeScheduleStore, n as getScheduleRunStore, o as setRuntimeScheduleStore, r as getScheduleRuntimeRegistry, s as setScheduleRunStore, t as getRuntimeScheduleStore, u as createKVScheduleRunStore } from "./state-By7WU_ks.js";
5
- import { n as validateRuntimeScheduleCron, t as schedules } from "./client-DpCD4YFE.js";
6
- import { t as createScheduleKVStorage } from "./kv-storage-DWinmLLy.js";
7
- export { createKVRuntimeScheduleStore, createKVScheduleRunStore, createMemoryRuntimeScheduleStore, createMemoryScheduleRunStore, createScheduleKVStorage, createScheduleRun, defineSchedule, defineScheduleTarget, discoverScheduleDefinitions, executeRuntimeSchedule, executeSchedule, executeStaticSchedule, getRuntimeScheduleStore, getScheduleRunStore, getScheduleRuntimeRegistry, loadScheduleDefinition, resetScheduleRuntime, schedules, setRuntimeScheduleStore, setScheduleRunStore, setScheduleRuntimeRegistry, validateRuntimeScheduleCron };
1
+ import { defineSchedule } from "./definition.js";
2
+ import { o as createScheduleError } from "./wait-until-Dy4Bn3ZN.js";
3
+ import { a as runScheduleFrom } from "./started-errors-p7cu_rI7.js";
4
+ import { i as startSchedule, n as getSchedule, r as listSchedules, t as cancelSchedule } from "./started-Bx7MDbrl.js";
5
+ //#region src/run.ts
6
+ const registryModule = "#vitehub/schedule/registry";
7
+ /** The registry that the Schedule Vite plugin generates. It loads on the first run, so importing the root stays cheap. */
8
+ async function loadRegistry() {
9
+ try {
10
+ return (await import(
11
+ /* @vite-ignore */
12
+ /* @vitehub-schedule-registry */
13
+ registryModule
14
+ )).default;
15
+ } catch (cause) {
16
+ throw createScheduleError("SCHEDULE_DEFINITION_NOT_FOUND", { cause });
17
+ }
18
+ }
19
+ /**
20
+ * Runs a Static Schedule Definition that sets `manual: true` now, as if its cron fired at `scheduledAt` (default: now).
21
+ * It resolves with the Schedule Run, also when the handler fails.
22
+ */
23
+ async function runSchedule(name, options = {}) {
24
+ return await runScheduleFrom(await loadRegistry(), name, options);
25
+ }
26
+ //#endregion
27
+ export { cancelSchedule, defineSchedule, getSchedule, listSchedules, runSchedule, startSchedule };
@@ -0,0 +1,118 @@
1
+ //#region ../../node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs
2
+ const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
3
+ function normalizeWindowsPath(input = "") {
4
+ if (!input) return input;
5
+ return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
6
+ }
7
+ const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
8
+ const _DRIVE_LETTER_RE = /^[A-Za-z]:$/;
9
+ const _ROOT_FOLDER_RE = /^\/([A-Za-z]:)?$/;
10
+ function cwd() {
11
+ if (typeof process !== "undefined" && typeof process.cwd === "function") return process.cwd().replace(/\\/g, "/");
12
+ return "/";
13
+ }
14
+ const resolve = function(...arguments_) {
15
+ arguments_ = arguments_.map((argument) => normalizeWindowsPath(argument));
16
+ let resolvedPath = "";
17
+ let resolvedAbsolute = false;
18
+ for (let index = arguments_.length - 1; index >= -1 && !resolvedAbsolute; index--) {
19
+ const path = index >= 0 ? arguments_[index] : cwd();
20
+ if (!path || path.length === 0) continue;
21
+ resolvedPath = `${path}/${resolvedPath}`;
22
+ resolvedAbsolute = isAbsolute(path);
23
+ }
24
+ resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
25
+ if (resolvedAbsolute && !isAbsolute(resolvedPath)) return `/${resolvedPath}`;
26
+ return resolvedPath.length > 0 ? resolvedPath : ".";
27
+ };
28
+ function normalizeString(path, allowAboveRoot) {
29
+ let res = "";
30
+ let lastSegmentLength = 0;
31
+ let lastSlash = -1;
32
+ let dots = 0;
33
+ let char = null;
34
+ for (let index = 0; index <= path.length; ++index) {
35
+ if (index < path.length) char = path[index];
36
+ else if (char === "/") break;
37
+ else char = "/";
38
+ if (char === "/") {
39
+ if (lastSlash === index - 1 || dots === 1);
40
+ else if (dots === 2) {
41
+ if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
42
+ if (res.length > 2) {
43
+ const lastSlashIndex = res.lastIndexOf("/");
44
+ if (lastSlashIndex === -1) {
45
+ res = "";
46
+ lastSegmentLength = 0;
47
+ } else {
48
+ res = res.slice(0, lastSlashIndex);
49
+ lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
50
+ }
51
+ lastSlash = index;
52
+ dots = 0;
53
+ continue;
54
+ } else if (res.length > 0) {
55
+ res = "";
56
+ lastSegmentLength = 0;
57
+ lastSlash = index;
58
+ dots = 0;
59
+ continue;
60
+ }
61
+ }
62
+ if (allowAboveRoot) {
63
+ res += res.length > 0 ? "/.." : "..";
64
+ lastSegmentLength = 2;
65
+ }
66
+ } else {
67
+ if (res.length > 0) res += `/${path.slice(lastSlash + 1, index)}`;
68
+ else res = path.slice(lastSlash + 1, index);
69
+ lastSegmentLength = index - lastSlash - 1;
70
+ }
71
+ lastSlash = index;
72
+ dots = 0;
73
+ } else if (char === "." && dots !== -1) ++dots;
74
+ else dots = -1;
75
+ }
76
+ return res;
77
+ }
78
+ const isAbsolute = function(p) {
79
+ return _IS_ABSOLUTE_RE.test(p);
80
+ };
81
+ const relative = function(from, to) {
82
+ const _from = resolve(from).replace(_ROOT_FOLDER_RE, "$1").split("/");
83
+ const _to = resolve(to).replace(_ROOT_FOLDER_RE, "$1").split("/");
84
+ if (_to[0][1] === ":" && _from[0][1] === ":" && _from[0] !== _to[0]) return _to.join("/");
85
+ const _fromCopy = [..._from];
86
+ for (const segment of _fromCopy) {
87
+ if (_to[0] !== segment) break;
88
+ _from.shift();
89
+ _to.shift();
90
+ }
91
+ return [..._from.map(() => ".."), ..._to].join("/");
92
+ };
93
+ const dirname = function(p) {
94
+ const segments = normalizeWindowsPath(p).replace(/\/$/, "").split("/").slice(0, -1);
95
+ if (segments.length === 1 && _DRIVE_LETTER_RE.test(segments[0])) segments[0] += "/";
96
+ return segments.join("/") || (isAbsolute(p) ? "/" : ".");
97
+ };
98
+ //#endregion
99
+ //#region ../internal/src/inspect.ts
100
+ function relativeDefinitionFile(projectRoot, file) {
101
+ return relative(projectRoot, file).replaceAll("\\", "/");
102
+ }
103
+ const redactedInspectionValue = "[redacted]";
104
+ const secretKeyPattern = /secret|token|passw(?:or)?d|credential|api[-_\s]?key|private[-_\s]?key|authorization|cookie|signature|dsn|connection[-_\s]?string/i;
105
+ const embeddedUrlCredentialPattern = /\b([a-z][a-z0-9+.-]*:\/\/)[^/\s?#]*@/gi;
106
+ const embeddedCookiePattern = /\b([\w-]*cookie[\w-]*["']?\s*[:=]\s*)(?:"(?:\\[^\r\n]|[^"\\\r\n])*"(?:\s*;\s*[\w.-]+\s*=[^;\r\n]*)*|'(?:\\[^\r\n]|[^'\\\r\n])*'(?:\s*;\s*[\w.-]+\s*=[^;\r\n]*)*|[^\r\n]+?(?=\s*(?:;\s*[^;=\r\n/]+\s*(?:\r?\n|$)|&|\r?\n|$)))/gi;
107
+ const embeddedBearerPattern = /\bbearer\s+[^\s,;]+/gi;
108
+ const embeddedAuthorizationPattern = new RegExp(String.raw`\b([\w-]*authorization[\w-]*["']?\s*[:=]\s*)(?!\[redacted\](?=$|[\s,;}&]))(?:"(?:\\[^\r\n]|[^"\\\r\n])*"|'(?:\\[^\r\n]|[^'\\\r\n])*'|[^\r\n]+?(?=\s*(?:[,;])?\s*(?:${secretKeyPattern.source})[\w-]*\s*[:=]|\s+rejected\b|$))`, "gi");
109
+ const embeddedSecretAssignmentPattern = new RegExp(String.raw`\b([\w-]*(?:${secretKeyPattern.source})[\w-]*["']?\s*[:=]\s*)(?!\[redacted\](?=$|[\s,;}&]))(?:"(?:\\[^\r\n]|[^"\\\r\n])*"|'(?:\\[^\r\n]|[^'\\\r\n])*'|[^\s,;&#&]+)`, "gi");
110
+ /**
111
+ * Removes credentials inside free text, for example an error message. URL credentials, bearer tokens, and
112
+ * `name=value` pairs with a secret name are replaced with `[redacted]`.
113
+ */
114
+ function redactInspectionText(value) {
115
+ return value.replace(embeddedUrlCredentialPattern, `$1${redactedInspectionValue}@`).replace(embeddedAuthorizationPattern, `$1${redactedInspectionValue}`).replace(embeddedCookiePattern, `$1${redactedInspectionValue}`).replace(embeddedBearerPattern, `Bearer ${redactedInspectionValue}`).replace(embeddedSecretAssignmentPattern, `$1${redactedInspectionValue}`);
116
+ }
117
+ //#endregion
118
+ export { relative as a, isAbsolute as i, relativeDefinitionFile as n, resolve as o, dirname as r, redactInspectionText as t };
@@ -0,0 +1,22 @@
1
+ import { defineDiagnostics } from "nostics";
2
+ //#region ../internal/src/invariant.ts
3
+ const invariantDiagnostics = /*#__PURE__*/ defineDiagnostics({
4
+ docsBase: "https://vitehub.dev/docs/development/diagnostics",
5
+ codes: { INTERNAL_INVARIANT_FAILED: {
6
+ why: ({ what }) => `ViteHub reached a state that it does not expect: ${what}`,
7
+ fix: "This is a ViteHub bug. Open an issue at https://github.com/vite-hub/vitehub/issues with this error message and its stack trace."
8
+ } }
9
+ });
10
+ /**
11
+ * The error for a state that only a ViteHub bug can reach, such as an impossible branch. `what` says which rule broke.
12
+ * Use a code from the package catalog when a developer can cause the error or fix it.
13
+ */
14
+ function invariantError(what) {
15
+ return invariantDiagnostics.INTERNAL_INVARIANT_FAILED({ what });
16
+ }
17
+ /** Throws `INTERNAL_INVARIANT_FAILED` when `condition` is falsy. */
18
+ function invariant(condition, what) {
19
+ if (!condition) throw invariantError(what);
20
+ }
21
+ //#endregion
22
+ export { invariantError as n, invariant as t };
@@ -0,0 +1,18 @@
1
+ //#region src/runtime/kv-storage.d.ts
2
+ interface ScheduleKVStorage {
3
+ delete(key: string): boolean | Promise<boolean> | Promise<void> | void;
4
+ get<T = unknown>(key: string): Promise<T | null | undefined> | T | null | undefined;
5
+ has(key: string): boolean | Promise<boolean>;
6
+ keys(base?: string): Promise<string[]> | string[];
7
+ set<T = unknown>(key: string, value: T): Promise<void> | void;
8
+ }
9
+ interface ViteHubKVStorage {
10
+ delete(key: string): Promise<readonly [unknown, unknown]>;
11
+ get<T = unknown>(key: string): Promise<readonly [unknown, T | null | undefined]>;
12
+ has(key: string): Promise<readonly [unknown, boolean | undefined]>;
13
+ keys(base?: string): Promise<readonly [unknown, string[] | undefined]>;
14
+ set<T = unknown>(key: string, value: T): Promise<readonly [unknown, unknown]>;
15
+ }
16
+ declare function createScheduleKVStorage(kvStore: ViteHubKVStorage): ScheduleKVStorage;
17
+ //#endregion
18
+ export { createScheduleKVStorage as n, ScheduleKVStorage as t };
@@ -1,8 +1,8 @@
1
1
  //#region src/runtime/kv-storage.ts
2
2
  function createScheduleKVStorage(kvStore) {
3
3
  return {
4
- async del(key) {
5
- const [error] = await kvStore.del(key);
4
+ async delete(key) {
5
+ const [error] = await kvStore.delete(key);
6
6
  if (error) throw error;
7
7
  },
8
8
  async get(key) {
@@ -0,0 +1,11 @@
1
+ //#region ../internal/src/object.ts
2
+ /** A non-null object that is not an array. Functions do not pass. */
3
+ function isRecord(value) {
4
+ return typeof value === "object" && value !== null && !Array.isArray(value);
5
+ }
6
+ /** A non-null object or a function that is not an array. */
7
+ function isRecordOrFunction(value) {
8
+ return Object(value) === value && !Array.isArray(value);
9
+ }
10
+ //#endregion
11
+ export { isRecordOrFunction as n, isRecord as t };