@vite-hub/workflow 0.1.0 → 0.4.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 (66) hide show
  1. package/README.md +173 -55
  2. package/dist/{app-CzPoP84f.js → app-He0GTrYZ.js} +1 -1
  3. package/dist/client-DkwOxEiT.js +707 -0
  4. package/dist/{cloudflare-nF4abPd4.js → cloudflare-BHfClPvT.js} +2 -2
  5. package/dist/{cloudflare-env-BNrYo29x.js → cloudflare-env-CGLx7lUd.js} +44 -42
  6. package/dist/cloudflare-env-lookup-CfX6wZKb.d.ts +4 -0
  7. package/dist/{cloudflare-env-CIjdFTv6.d.ts → cloudflare-shared-CTqh_a2s.d.ts} +2 -2
  8. package/dist/{config-IJMb0eeZ.js → config-C3DvtjfJ.js} +41 -40
  9. package/dist/definition.d.ts +18 -0
  10. package/dist/definition.js +33 -0
  11. package/dist/delay-D1-nq_VE.js +46 -0
  12. package/dist/dev-recorder-CTN5Fkao.js +10 -0
  13. package/dist/durability.d.ts +23 -0
  14. package/dist/durability.js +62 -0
  15. package/dist/error-diagnostics-0V2T3JFw.js +317 -0
  16. package/dist/error-diagnostics-CQ4BUqRe.js +270 -0
  17. package/dist/errors-DCqRnZpN.js +35 -0
  18. package/dist/errors-uhP8DZTi.d.ts +67 -0
  19. package/dist/index.d.ts +35 -63
  20. package/dist/index.js +15 -19
  21. package/dist/object-Da1zyPCR.js +11 -0
  22. package/dist/openworkflow-BhzxV_Y3.d.ts +52 -0
  23. package/dist/openworkflow-defaults-DDig2M4s.js +26 -0
  24. package/dist/openworkflow-storage-Dj9zUAsk.js +28 -0
  25. package/dist/openworkflow.d.ts +2 -0
  26. package/dist/openworkflow.js +2 -0
  27. package/dist/{operations-tNUdj3G4.d.ts → operation-definition-nmRu_O3V.d.ts} +42 -15
  28. package/dist/operations-D_WJwjrS.js +333 -0
  29. package/dist/operations.d.ts +40 -6
  30. package/dist/operations.js +163 -736
  31. package/dist/{out-CsaJxg8m.js → out-DxLKolA0.js} +32 -1430
  32. package/dist/{rolldown-runtime-CMFfr-1z.js → rolldown-runtime-B4iAMlE-.js} +10 -1
  33. package/dist/run-error-DBWqiJHH.js +110 -0
  34. package/dist/run-failed-gVGo1BaF.js +18 -0
  35. package/dist/runtime/cloudflare-runner.d.ts +3 -5
  36. package/dist/runtime/cloudflare-runner.js +39 -45
  37. package/dist/runtime/cloudflare-shared.d.ts +2 -2
  38. package/dist/runtime/cloudflare-shared.js +1 -1
  39. package/dist/runtime/cloudflare-vite.d.ts +3 -2
  40. package/dist/runtime/cloudflare-vite.js +47 -1
  41. package/dist/runtime/dev-runs.d.ts +4 -0
  42. package/dist/runtime/dev-runs.js +73 -0
  43. package/dist/runtime/execute.d.ts +42 -5
  44. package/dist/runtime/execute.js +216 -17
  45. package/dist/runtime/openworkflow-worker.d.ts +29 -2
  46. package/dist/runtime/openworkflow-worker.js +156 -38
  47. package/dist/runtime/openworkflow.d.ts +2 -21
  48. package/dist/runtime/openworkflow.js +307 -44
  49. package/dist/runtime/state.d.ts +3 -1
  50. package/dist/runtime/state.js +6 -6
  51. package/dist/runtime/vercel-vite.d.ts +1 -1
  52. package/dist/runtime/vercel-vite.js +7 -4
  53. package/dist/types-Dsmwsdlv.d.ts +282 -0
  54. package/dist/{vercel-D-ZNtB_u.js → vercel-DTvm61iY.js} +53 -24
  55. package/dist/vite.d.ts +228 -30
  56. package/dist/vite.js +2640 -1449
  57. package/package.json +28 -50
  58. package/dist/client-DsGM3M4U.js +0 -389
  59. package/dist/cloudflare-shared-CaxrMD1A.d.ts +0 -1
  60. package/dist/cloudflare-vite-B3IabBsv.js +0 -47
  61. package/dist/error-diagnostics-A_8Kp-48.js +0 -116
  62. package/dist/error-diagnostics-pwNFvAHP.js +0 -67
  63. package/dist/operations-B_rYG71W.js +0 -230
  64. package/dist/provider-operation-CW2cYfVy.js +0 -65
  65. package/dist/runtime-type-DBCvIh5x.js +0 -7
  66. package/dist/types-D82WmfZa.d.ts +0 -180
@@ -1,4 +1,4 @@
1
- import { t as workflowErrorDiagnostics } from "./error-diagnostics-pwNFvAHP.js";
1
+ import { t as workflowErrorDiagnostics } from "./error-diagnostics-0V2T3JFw.js";
2
2
  //#region ../internal/src/integrations/hex.ts
3
3
  const textEncoder = new TextEncoder();
4
4
  new TextDecoder();
@@ -56,4 +56,4 @@ function createCloudflareWorkflowBindings(definitions, options) {
56
56
  }));
57
57
  }
58
58
  //#endregion
59
- export { getLegacyCloudflareWorkflowClassName as a, getCloudflareWorkflowName as i, getCloudflareWorkflowBindingName as n, encodeNameHex as o, getCloudflareWorkflowClassName as r, createCloudflareWorkflowBindings as t };
59
+ export { encodeNameHex as a, getLegacyCloudflareWorkflowClassName as i, getCloudflareWorkflowBindingName as n, getCloudflareWorkflowClassName as r, createCloudflareWorkflowBindings as t };
@@ -1,7 +1,46 @@
1
1
  import { AsyncLocalStorage } from "node:async_hooks";
2
- //#region ../internal/src/runtime/cloudflare-env.ts
3
- let activeEnv;
2
+ //#region ../internal/src/runtime/cloudflare-env-lookup.ts
3
+ /** The key of the AsyncLocalStorage store on `globalThis`. Every bundled copy of this module shares the store. */
4
4
  const activeEnvStorageKey = Symbol.for("vitehub.cloudflare.env-storage");
5
+ let activeEnv;
6
+ function setInstalledCloudflareEnv(env) {
7
+ activeEnv = env;
8
+ }
9
+ /** The store of the current `runWithActiveCloudflareEnv()` call, or undefined outside one. */
10
+ function getScopedCloudflareEnv() {
11
+ return globalThis[activeEnvStorageKey]?.getStore();
12
+ }
13
+ function getActiveCloudflareEnv() {
14
+ const scoped = getScopedCloudflareEnv();
15
+ if (scoped) return scoped.env;
16
+ const host = globalThis;
17
+ return Object.hasOwn(host, "__env__") && host.__env__ !== void 0 ? host.__env__ : activeEnv;
18
+ }
19
+ function ownValue(value, key) {
20
+ if (value === null || typeof value !== "object" && typeof value !== "function" || !Object.hasOwn(value, key)) return void 0;
21
+ return Reflect.get(value, key);
22
+ }
23
+ function ownObject(value) {
24
+ return value !== null && (typeof value === "object" || typeof value === "function") ? value : void 0;
25
+ }
26
+ /** The objects where H3 and Nitro hosts put Cloudflare `env` and `context`, in lookup order. */
27
+ function cloudflareOwners(target) {
28
+ const context = ownObject(ownValue(target, "context"));
29
+ const platform = ownObject(ownValue(context, "_platform"));
30
+ const req = ownObject(ownValue(target, "req"));
31
+ return [
32
+ ownObject(ownValue(context, "cloudflare")),
33
+ ownObject(ownValue(platform, "cloudflare")),
34
+ ownObject(ownValue(ownObject(ownValue(req, "runtime")), "cloudflare"))
35
+ ];
36
+ }
37
+ function getCloudflareEnv(event, options = {}) {
38
+ const target = ownObject(event);
39
+ for (const candidate of [ownValue(target, "env"), ...cloudflareOwners(target).map((owner) => ownValue(owner, "env"))]) if (candidate) return candidate;
40
+ return options.fallback === false ? void 0 : getActiveCloudflareEnv();
41
+ }
42
+ //#endregion
43
+ //#region ../internal/src/runtime/cloudflare-env.ts
5
44
  const runtimeGlobal = globalThis;
6
45
  const activeEnvStorage = runtimeGlobal[activeEnvStorageKey] ||= new AsyncLocalStorage();
7
46
  const globalEnvProbe = Symbol("vitehub.cloudflare.global-env-probe");
@@ -24,7 +63,7 @@ function readsGlobalEnv(env) {
24
63
  }
25
64
  }
26
65
  function setActiveCloudflareEnv(env) {
27
- activeEnv = env;
66
+ setInstalledCloudflareEnv(env);
28
67
  if (!env || !readsGlobalEnv(env)) globalThis.__env__ = env;
29
68
  try {
30
69
  activeEnvStorage.enterWith({ env });
@@ -33,37 +72,6 @@ function setActiveCloudflareEnv(env) {
33
72
  function runWithActiveCloudflareEnv(env, callback) {
34
73
  return activeEnvStorage.run({ env }, callback);
35
74
  }
36
- function getActiveCloudflareEnv() {
37
- const scoped = activeEnvStorage.getStore();
38
- if (scoped) return scoped.env;
39
- const host = globalThis;
40
- return Object.hasOwn(host, "__env__") && host.__env__ !== void 0 ? host.__env__ : activeEnv;
41
- }
42
- function ownValue(value, key) {
43
- if (value === null || typeof value !== "object" && typeof value !== "function" || !Object.hasOwn(value, key)) return void 0;
44
- return Reflect.get(value, key);
45
- }
46
- function ownObject(value) {
47
- return value !== null && (typeof value === "object" || typeof value === "function") ? value : void 0;
48
- }
49
- /** The objects where H3 1, H3 2, and Nitro hosts put Cloudflare `env` and `context`, in lookup order. */
50
- function cloudflareOwners(target) {
51
- const context = ownObject(ownValue(target, "context"));
52
- const platform = ownObject(ownValue(context, "_platform"));
53
- const req = ownObject(ownValue(target, "req"));
54
- const nodeReq = ownObject(ownValue(ownObject(ownValue(target, "node")), "req"));
55
- return [
56
- ownObject(ownValue(context, "cloudflare")),
57
- ownObject(ownValue(platform, "cloudflare")),
58
- ownObject(ownValue(ownObject(ownValue(req, "runtime")), "cloudflare")),
59
- ownObject(ownValue(ownObject(ownValue(nodeReq, "runtime")), "cloudflare"))
60
- ];
61
- }
62
- function getCloudflareEnv(event, options = {}) {
63
- const target = ownObject(event);
64
- for (const candidate of [ownValue(target, "env"), ...cloudflareOwners(target).map((owner) => ownValue(owner, "env"))]) if (candidate) return candidate;
65
- return options.fallback === false ? void 0 : getActiveCloudflareEnv();
66
- }
67
75
  function resolveWaitUntil(event, options = {}) {
68
76
  const target = ownObject(event);
69
77
  const context = ownObject(ownValue(target, "context"));
@@ -73,9 +81,6 @@ function resolveWaitUntil(event, options = {}) {
73
81
  const platformCloudflareContext = ownObject(ownValue(platformCloudflare, "context"));
74
82
  const req = ownObject(ownValue(target, "req"));
75
83
  const reqCloudflare = ownObject(ownValue(ownObject(ownValue(req, "runtime")), "cloudflare"));
76
- const reqCloudflareContext = ownObject(ownValue(reqCloudflare, "context"));
77
- const nodeReq = ownObject(ownValue(ownObject(ownValue(target, "node")), "req"));
78
- const nodeCloudflare = ownObject(ownValue(ownObject(ownValue(nodeReq, "runtime")), "cloudflare"));
79
84
  const hosts = [
80
85
  context,
81
86
  cloudflare,
@@ -84,10 +89,7 @@ function resolveWaitUntil(event, options = {}) {
84
89
  platformCloudflareContext,
85
90
  req,
86
91
  reqCloudflare,
87
- reqCloudflareContext,
88
- nodeReq,
89
- nodeCloudflare,
90
- ownObject(ownValue(nodeCloudflare, "context"))
92
+ ownObject(ownValue(reqCloudflare, "context"))
91
93
  ];
92
94
  const owners = options.preferHost ? [...hosts, target] : [target, ...hosts];
93
95
  for (const owner of owners) {
@@ -110,4 +112,4 @@ function createCloudflareRuntimeEvent(env, context) {
110
112
  };
111
113
  }
112
114
  //#endregion
113
- export { setActiveCloudflareEnv as a, runWithActiveCloudflareEnv as i, getCloudflareEnv as n, resolveWaitUntil as r, createCloudflareRuntimeEvent as t };
115
+ export { getCloudflareEnv as a, setActiveCloudflareEnv as i, resolveWaitUntil as n, runWithActiveCloudflareEnv as r, createCloudflareRuntimeEvent as t };
@@ -0,0 +1,4 @@
1
+ //#region ../internal/src/runtime/cloudflare-env-lookup.d.ts
2
+ type CloudflareWorkerEnv = Record<string, unknown>;
3
+ //#endregion
4
+ export { CloudflareWorkerEnv as t };
@@ -1,5 +1,5 @@
1
+ import { t as CloudflareWorkerEnv } from "./cloudflare-env-lookup-CfX6wZKb.js";
1
2
  //#region ../internal/src/runtime/cloudflare-env.d.ts
2
- type CloudflareWorkerEnv = Record<string, unknown>;
3
3
  interface CloudflareWorkerExecutionContext {
4
4
  waitUntil?: (promise: Promise<unknown>) => void;
5
5
  }
@@ -19,4 +19,4 @@ interface CloudflareRuntimeEvent {
19
19
  }
20
20
  declare function createCloudflareRuntimeEvent(env: CloudflareWorkerEnv, context: CloudflareWorkerExecutionContext | undefined): CloudflareRuntimeEvent;
21
21
  //#endregion
22
- export { setActiveCloudflareEnv as a, runWithActiveCloudflareEnv as i, CloudflareWorkerExecutionContext as n, createCloudflareRuntimeEvent as r, CloudflareWorkerEnv as t };
22
+ export { setActiveCloudflareEnv as i, createCloudflareRuntimeEvent as n, runWithActiveCloudflareEnv as r, CloudflareWorkerExecutionContext as t };
@@ -1,6 +1,8 @@
1
- import { t as workflowErrorDiagnostics } from "./error-diagnostics-pwNFvAHP.js";
1
+ import { t as isRecord } from "./object-Da1zyPCR.js";
2
+ import { t as workflowErrorDiagnostics } from "./error-diagnostics-0V2T3JFw.js";
2
3
  import { defu } from "defu";
3
- function deploymentPresetFromNitro(value) {
4
+ /** Maps a host name or a Nitro preset name, such as `cloudflare-module` or `node-server`, to its ViteHub host. */
5
+ function hostFromNitroPreset(value) {
4
6
  const normalized = value?.trim().toLowerCase().replaceAll("_", "-");
5
7
  if (!normalized) return;
6
8
  if (normalized.startsWith("cloudflare")) return "cloudflare";
@@ -16,20 +18,14 @@ function normalizeHosting(hosting) {
16
18
  if (normalized === "cloudflare") return "cloudflare-module";
17
19
  return normalized;
18
20
  }
19
- /** Narrows a preset or host name to the hosts that have a native provider: Cloudflare, Netlify, or Vercel. */
21
+ /** Narrows a ViteHub host or Nitro preset name to the hosts that have a native provider: Cloudflare, Netlify, or Vercel. */
20
22
  function getHostingProvider(hosting) {
21
- const preset = deploymentPresetFromNitro(hosting);
22
- if (preset === "cloudflare" || preset === "netlify" || preset === "vercel") return preset;
23
- }
24
- //#endregion
25
- //#region ../internal/src/object.ts
26
- function isPlainObject(value) {
27
- if (value === null || Object(value) !== value || Array.isArray(value)) return false;
28
- return typeof value === "object";
23
+ const host = hostFromNitroPreset(hosting);
24
+ if (host === "cloudflare" || host === "netlify" || host === "vercel") return host;
29
25
  }
30
26
  //#endregion
31
27
  //#region src/config.ts
32
- const knownProviders = /* @__PURE__ */ new Set([
28
+ const knownDrivers = /* @__PURE__ */ new Set([
33
29
  "cloudflare",
34
30
  "openworkflow",
35
31
  "vercel"
@@ -54,10 +50,10 @@ function readBoolean(value, label) {
54
50
  return value;
55
51
  }
56
52
  function isRuntimeEnvDeclaration(value) {
57
- return isPlainObject(value) && value.kind === "env-variable" && (!("source" in value) || isRuntimeEnvSource(value.source));
53
+ return isRecord(value) && value.kind === "env-variable" && (!("source" in value) || isRuntimeEnvSource(value.source));
58
54
  }
59
55
  function isRuntimeEnvSource(value) {
60
- return isPlainObject(value) && value.kind === "env" && typeof value.name === "string" && (!("names" in value) || Array.isArray(value.names) && value.names.every((name) => typeof name === "string"));
56
+ return isRecord(value) && value.kind === "env" && typeof value.name === "string" && (!("names" in value) || Array.isArray(value.names) && value.names.every((name) => typeof name === "string"));
61
57
  }
62
58
  function readPositiveInteger(value, label) {
63
59
  if (typeof value === "undefined") return;
@@ -66,7 +62,7 @@ function readPositiveInteger(value, label) {
66
62
  }
67
63
  function normalizeOpenWorkflowPostgresOptions(value) {
68
64
  if (typeof value === "undefined") return;
69
- if (!isPlainObject(value)) throw workflowErrorDiagnostics.WORKFLOW_C0005({ message: "`workflow.postgres` must be a plain object." });
65
+ if (!isRecord(value)) throw workflowErrorDiagnostics.WORKFLOW_C0005({ message: "`workflow.postgres` must be a plain object." });
70
66
  const namespaceId = readString(value.namespaceId, "workflow.postgres.namespaceId");
71
67
  const runMigrations = readBoolean(value.runMigrations, "workflow.postgres.runMigrations");
72
68
  const schema = readString(value.schema, "workflow.postgres.schema");
@@ -80,7 +76,7 @@ function normalizeOpenWorkflowPostgresOptions(value) {
80
76
  }
81
77
  function normalizeOpenWorkflowSqliteOptions(value) {
82
78
  if (typeof value === "undefined") return;
83
- if (!isPlainObject(value)) throw workflowErrorDiagnostics.WORKFLOW_C0006({ message: "`workflow.sqlite` must be a plain object." });
79
+ if (!isRecord(value)) throw workflowErrorDiagnostics.WORKFLOW_C0006({ message: "`workflow.sqlite` must be a plain object." });
84
80
  const namespaceId = readString(value.namespaceId, "workflow.sqlite.namespaceId");
85
81
  const path = readRuntimeConfigValue(value.path, "workflow.sqlite.path", true);
86
82
  const runMigrations = readBoolean(value.runMigrations, "workflow.sqlite.runMigrations");
@@ -91,54 +87,59 @@ function normalizeOpenWorkflowSqliteOptions(value) {
91
87
  };
92
88
  }
93
89
  function normalizeOpenWorkflowWorkerOptions(value) {
94
- if (typeof value === "undefined") return;
95
- if (!isPlainObject(value)) throw workflowErrorDiagnostics.WORKFLOW_C0007({ message: "`workflow.worker` must be a plain object." });
90
+ if (typeof value === "undefined" || value === false) return value;
91
+ if (!isRecord(value)) throw workflowErrorDiagnostics.WORKFLOW_C0007({ message: "`workflow.worker` must be `false` or a plain object." });
96
92
  const concurrency = readPositiveInteger(value.concurrency, "workflow.worker.concurrency");
97
93
  return typeof concurrency === "number" ? { concurrency } : {};
98
94
  }
99
95
  function hasOpenWorkflowStorageConfig(options) {
100
- return isPlainObject(options.postgres) && isDefinedRuntimeConfigValue(options.postgres.url) || isPlainObject(options.sqlite) && isDefinedRuntimeConfigValue(options.sqlite.path);
96
+ return isRecord(options.postgres) && isDefinedRuntimeConfigValue(options.postgres.url) || isRecord(options.sqlite) && isDefinedRuntimeConfigValue(options.sqlite.path);
101
97
  }
102
98
  function isDefinedRuntimeConfigValue(value) {
103
99
  return typeof value === "string" && !!value.trim() || isRuntimeEnvDeclaration(value);
104
100
  }
105
- function inferProvider(provider, hosting) {
106
- if (provider === "cloudflare" || provider === "openworkflow" || provider === "vercel") return provider;
107
- if (hosting.includes("netlify")) throw workflowErrorDiagnostics.WORKFLOW_C0008({ message: "`workflow.provider` cannot be inferred for Netlify hosting. Set `workflow.provider` explicitly or disable `workflow`." });
108
- if (hosting.includes("cloudflare")) return "cloudflare";
109
- return "vercel";
110
- }
111
- function inferProviderFromOptions(options, hosting) {
112
- if (typeof options.provider === "undefined" && (hosting.includes("node") || hosting.includes("docker")) && hasOpenWorkflowStorageConfig(options)) return "openworkflow";
113
- return inferProvider(options.provider, hosting);
114
- }
115
- function resolveProvider(options, hosting) {
101
+ function inferDriver(options, hosting, inline) {
102
+ const driver = options.driver;
103
+ if (driver === "cloudflare" || driver === "openworkflow" || driver === "vercel") return driver;
104
+ const host = getHostingProvider(hosting);
105
+ if (host === "netlify") throw workflowErrorDiagnostics.WORKFLOW_C0008({ message: "`workflow.driver` cannot be inferred for Netlify hosting. Set `workflow.driver` explicitly or disable `workflow`." });
106
+ if (host === "cloudflare") return "cloudflare";
107
+ if (host === "vercel") return "vercel";
108
+ if (hosting.includes("node") || hosting.includes("docker")) return "openworkflow";
109
+ if (hasOpenWorkflowStorageConfig(options)) return "openworkflow";
110
+ if (!hosting || inline) return "vercel";
111
+ throw workflowErrorDiagnostics.WORKFLOW_C0020({ message: `\`workflow.driver\` cannot be inferred for ${JSON.stringify(hosting)} hosting. ViteHub infers Vercel Workflow only on Vercel. For durable runs, set \`workflow: { driver: "openworkflow", sqlite: { path: ".vitehub/data/workflow.sqlite" } }\`, or \`postgres: { url }\` instead of \`sqlite\`, and call \`startOpenWorkflowWorker()\` from \`@vite-hub/workflow/openworkflow\` in a long-lived process.` });
112
+ }
113
+ function resolveDriver(options, hosting, inline) {
116
114
  const shared = {
117
115
  ...typeof options.binding === "string" ? { binding: options.binding } : {},
118
116
  ...typeof options.name === "string" ? { name: options.name } : {}
119
117
  };
120
- const provider = options.provider;
121
- if (typeof provider === "string" && !knownProviders.has(provider)) throw workflowErrorDiagnostics.WORKFLOW_C0009({ message: `Unknown \`workflow.provider\`: ${JSON.stringify(provider)}. Expected "cloudflare", "openworkflow", or "vercel".` });
122
- const resolved = inferProviderFromOptions(options, hosting);
123
- if (resolved === "cloudflare") return defu(shared, { provider: "cloudflare" });
118
+ const driver = options.driver;
119
+ if (driver === void 0 && Object.hasOwn(options, "provider")) throw workflowErrorDiagnostics.WORKFLOW_RENAMED_PROVIDER_KEY({ value: JSON.stringify(options.provider) ?? String(options.provider) });
120
+ if (typeof driver === "string" && !knownDrivers.has(driver)) throw workflowErrorDiagnostics.WORKFLOW_C0009({ message: `Unknown \`workflow.driver\`: ${JSON.stringify(driver)}. Expected "cloudflare", "openworkflow", or "vercel".` });
121
+ const resolved = inferDriver(options, hosting, inline);
122
+ if (resolved === "cloudflare") return defu(shared, { driver: "cloudflare" });
124
123
  if (resolved === "openworkflow") {
125
124
  const postgres = normalizeOpenWorkflowPostgresOptions(options.postgres);
126
125
  const sqlite = normalizeOpenWorkflowSqliteOptions(options.sqlite);
127
126
  const worker = normalizeOpenWorkflowWorkerOptions(options.worker);
127
+ const remote = readBoolean(options.remote, "workflow.remote");
128
128
  if (postgres?.url && sqlite?.path) throw workflowErrorDiagnostics.WORKFLOW_C0012({ message: "`workflow.postgres.url` and `workflow.sqlite.path` cannot both configure OpenWorkflow storage." });
129
129
  return defu({
130
130
  ...postgres ? { postgres } : {},
131
131
  ...sqlite ? { sqlite } : {},
132
- ...worker ? { worker } : {}
133
- }, shared, { provider: "openworkflow" });
132
+ ...worker !== void 0 ? { worker } : {},
133
+ ...remote === true ? { remote } : {}
134
+ }, shared, { driver: "openworkflow" });
134
135
  }
135
- return defu(shared, { provider: "vercel" });
136
+ return defu(shared, { driver: "vercel" });
136
137
  }
137
138
  function normalizeWorkflowOptions(options, input = {}) {
138
139
  if (options === false) return void 0;
139
- if (typeof options !== "undefined" && !isPlainObject(options)) throw workflowErrorDiagnostics.WORKFLOW_C0013({ message: "`workflow` must be a plain object." });
140
+ if (typeof options !== "undefined" && !isRecord(options)) throw workflowErrorDiagnostics.WORKFLOW_C0013({ message: "`workflow` must be a plain object." });
140
141
  if (options && Object.hasOwn(options, "database") && options.database !== void 0) throw workflowErrorDiagnostics.WORKFLOW_C0017({ message: "`workflow.database` is not supported. Set `workflow.sqlite.path` or `workflow.postgres.url` explicitly." });
141
- return resolveProvider(options || {}, normalizeHosting(input.hosting));
142
+ return resolveDriver(options || {}, normalizeHosting(input.hosting), input.inline === true);
142
143
  }
143
144
  //#endregion
144
- export { normalizeHosting as i, isPlainObject as n, getHostingProvider as r, normalizeWorkflowOptions as t };
145
+ export { getHostingProvider as n, normalizeHosting as r, normalizeWorkflowOptions as t };
@@ -0,0 +1,18 @@
1
+ import { f as WorkflowDefinition } from "./types-Dsmwsdlv.js";
2
+ //#region src/definition.d.ts
3
+ /**
4
+ * Defines a Workflow from one object: `defineWorkflow({ handler, ...options })`. The file path is the Workflow name.
5
+ * The handler receives one object, `{ payload, steps, sleep, ...context }`. Pass the payload type as the type argument.
6
+ * It types `startWorkflow()` for this Workflow.
7
+ *
8
+ * ```ts
9
+ * export default defineWorkflow<{ email: string }>({
10
+ * handler: async ({ payload, steps }) => {
11
+ * const user = await steps.createUser(payload)
12
+ * return await steps.sendWelcome(user)
13
+ * },
14
+ * })
15
+ * ```
16
+ */
17
+ export declare function defineWorkflow<TPayload = undefined, TResult = unknown>(definition: WorkflowDefinition<TPayload, TResult>, ...removed: unknown[]): WorkflowDefinition<TPayload, TResult>;
18
+ //#endregion
@@ -0,0 +1,33 @@
1
+ import { t as isRecord } from "./object-Da1zyPCR.js";
2
+ import { t as workflowErrorDiagnostics } from "./error-diagnostics-0V2T3JFw.js";
3
+ //#region src/definition.ts
4
+ const workflowDefinitionKeys = /* @__PURE__ */ new Set([
5
+ "handler",
6
+ "native",
7
+ "rootStep"
8
+ ]);
9
+ /**
10
+ * Defines a Workflow from one object: `defineWorkflow({ handler, ...options })`. The file path is the Workflow name.
11
+ * The handler receives one object, `{ payload, steps, sleep, ...context }`. Pass the payload type as the type argument.
12
+ * It types `startWorkflow()` for this Workflow.
13
+ *
14
+ * ```ts
15
+ * export default defineWorkflow<{ email: string }>({
16
+ * handler: async ({ payload, steps }) => {
17
+ * const user = await steps.createUser(payload)
18
+ * return await steps.sendWelcome(user)
19
+ * },
20
+ * })
21
+ * ```
22
+ */
23
+ function defineWorkflow(definition, ...removed) {
24
+ if (typeof definition === "string" || typeof definition === "function" || removed.length) throw workflowErrorDiagnostics.WORKFLOW_C0015({ message: "`defineWorkflow(name, handler, options)` was removed. The file path is the Workflow name. Pass one object: `defineWorkflow({ handler, ...options })`." });
25
+ if (!isRecord(definition)) throw workflowErrorDiagnostics.WORKFLOW_C0015({ message: "`defineWorkflow()` expects one object with `handler`." });
26
+ const unknownKey = Object.keys(definition).find((key) => !workflowDefinitionKeys.has(key));
27
+ if (unknownKey) throw workflowErrorDiagnostics.WORKFLOW_C0015({ message: `\`defineWorkflow()\` does not support the ${JSON.stringify(unknownKey)} option.` });
28
+ if (typeof definition.handler !== "function") throw workflowErrorDiagnostics.WORKFLOW_C0014({ message: "`defineWorkflow()` requires a workflow handler." });
29
+ if (definition.native !== void 0 && typeof definition.native !== "function") throw workflowErrorDiagnostics.WORKFLOW_C0016({ message: "`defineWorkflow()` native entry must be a workflow handler." });
30
+ return definition;
31
+ }
32
+ //#endregion
33
+ export { defineWorkflow };
@@ -0,0 +1,46 @@
1
+ import { t as workflowErrorDiagnostics } from "./error-diagnostics-0V2T3JFw.js";
2
+ import { parseDuration } from "@vite-hub/runtime";
3
+ //#region src/runtime/delay.ts
4
+ /** The largest time that a JavaScript Date can hold. */
5
+ const maximumTime = 864e13;
6
+ function isDate(value) {
7
+ return Object.prototype.toString.call(value) === "[object Date]";
8
+ }
9
+ /**
10
+ * The time in milliseconds when a delayed run starts, or `undefined` when the run starts now. A `Date` in the past
11
+ * starts now. A duration that is not valid, such as a number, throws `RUNTIME_DURATION_INVALID`. An invalid `Date`, or
12
+ * a time that a `Date` cannot hold, throws `WORKFLOW_START_DELAY_INVALID`.
13
+ */
14
+ function resolveWorkflowStartAt(delay, now = Date.now()) {
15
+ if (delay === void 0) return void 0;
16
+ const startAt = isDate(delay) ? Date.prototype.getTime.call(delay) : now + parseDuration(delay, "delay");
17
+ if (!Number.isFinite(startAt) || startAt > maximumTime) throw workflowErrorDiagnostics.WORKFLOW_START_DELAY_INVALID({ delay: isDate(delay) ? "Invalid Date" : String(delay) });
18
+ return startAt > now ? startAt : void 0;
19
+ }
20
+ /**
21
+ * Holds the start time of a delayed run: in the Cloudflare params, next to the payload, and in the context of a
22
+ * generated Vercel native entry. The handler never sees it.
23
+ */
24
+ const workflowStartAtKey = "~vitehubStartAt";
25
+ /** Marks the Vercel native entry that ViteHub generates for a folder Workflow. Only that entry reads the start time. */
26
+ const generatedNativeEntryKey = "~vitehubGenerated";
27
+ /** Cloudflare `create()` has no delay, so a delayed run sends its start time next to the payload. */
28
+ function toCloudflareStartParams(payload, startAt) {
29
+ return startAt === void 0 ? payload : {
30
+ [workflowStartAtKey]: startAt,
31
+ payload
32
+ };
33
+ }
34
+ /** Reads the params of a Cloudflare run. The handler gets only the payload. */
35
+ function fromCloudflareStartParams(params) {
36
+ if (typeof params !== "object" || params === null || !Object.hasOwn(params, "~vitehubStartAt")) return { payload: params };
37
+ const startAt = Reflect.get(params, workflowStartAtKey);
38
+ const keys = Object.keys(params);
39
+ if (typeof startAt !== "number" || !keys.every((key) => key === "~vitehubStartAt" || key === "payload")) return { payload: params };
40
+ return {
41
+ payload: Reflect.get(params, "payload"),
42
+ startAt
43
+ };
44
+ }
45
+ //#endregion
46
+ export { workflowStartAtKey as a, toCloudflareStartParams as i, generatedNativeEntryKey as n, resolveWorkflowStartAt as r, fromCloudflareStartParams as t };
@@ -0,0 +1,10 @@
1
+ //#region src/runtime/dev-recorder.ts
2
+ let recorder;
3
+ function setWorkflowDevRecorder(value) {
4
+ recorder = value;
5
+ }
6
+ function getWorkflowDevRecorder() {
7
+ return recorder;
8
+ }
9
+ //#endregion
10
+ export { setWorkflowDevRecorder as n, getWorkflowDevRecorder as t };
@@ -0,0 +1,23 @@
1
+ import { P as WorkflowRuntimeConfigValue } from "./types-Dsmwsdlv.js";
2
+ import { Durability, DurabilityContext } from "@vite-hub/runtime/durability";
3
+ //#region src/durability.d.ts
4
+ /** What the build passes to `workflowDurability()`. The storage values may name runtime environment variables. */
5
+ export interface WorkflowDurabilityInput {
6
+ /** OpenWorkflow uses the Postgres Default Database after the explicit storage and its environment variables. */
7
+ defaultDatabase?: boolean;
8
+ postgresUrl?: WorkflowRuntimeConfigValue;
9
+ driver: string;
10
+ sqlitePath?: WorkflowRuntimeConfigValue;
11
+ }
12
+ /**
13
+ * The durability of Workflow runs. It follows the storage order of the OpenWorkflow runtime: the SQLite path, then
14
+ * `OPENWORKFLOW_SQLITE_PATH`, then the Postgres URL, `OPENWORKFLOW_POSTGRES_URL`, and the Postgres Default Database, then the default
15
+ * SQLite file. The runtime and reporter share this selection.
16
+ */
17
+ export declare function workflowDurability(input: WorkflowDurabilityInput, context: DurabilityContext): Durability[];
18
+ /**
19
+ * A Postgres URL for the durability input, which the build writes into the server. The reporter only needs to know
20
+ * that it is set: environment variable names stay, and a literal URL or default becomes `set`.
21
+ */
22
+ export declare function workflowDurabilityUrl(value: WorkflowRuntimeConfigValue): WorkflowRuntimeConfigValue;
23
+ //#endregion
@@ -0,0 +1,62 @@
1
+ import { t as resolveOpenWorkflowStorage } from "./openworkflow-storage-Dj9zUAsk.js";
2
+ import { resolveDurabilityValue } from "@vite-hub/runtime/durability";
3
+ //#region src/durability.ts
4
+ const sqliteFix = "Set OPENWORKFLOW_POSTGRES_URL to a Postgres URL, or set `workflow.postgres.url`.";
5
+ function sqlite(path) {
6
+ return [{
7
+ primitive: "workflow",
8
+ store: "openworkflow-sqlite",
9
+ scope: "host",
10
+ reason: `Runs in the SQLite file ${path} on this host.`,
11
+ fix: sqliteFix
12
+ }];
13
+ }
14
+ function postgres(source) {
15
+ return [{
16
+ primitive: "workflow",
17
+ store: "openworkflow-postgres",
18
+ scope: "shared",
19
+ reason: `Runs in Postgres, from ${source}.`
20
+ }];
21
+ }
22
+ /**
23
+ * The durability of Workflow runs. It follows the storage order of the OpenWorkflow runtime: the SQLite path, then
24
+ * `OPENWORKFLOW_SQLITE_PATH`, then the Postgres URL, `OPENWORKFLOW_POSTGRES_URL`, and the Postgres Default Database, then the default
25
+ * SQLite file. The runtime and reporter share this selection.
26
+ */
27
+ function workflowDurability(input, context) {
28
+ const { env } = context;
29
+ if (input.driver === "cloudflare") return [{
30
+ primitive: "workflow",
31
+ store: "cloudflare",
32
+ scope: "shared",
33
+ reason: "Cloudflare Workflows store each run."
34
+ }];
35
+ if (input.driver !== "openworkflow") return [{
36
+ primitive: "workflow",
37
+ store: "inline",
38
+ scope: "process",
39
+ reason: "Runs execute in the request process. A restart loses them.",
40
+ fix: "Set `workflow: { driver: \"openworkflow\" }` with a Postgres URL."
41
+ }];
42
+ const storage = resolveOpenWorkflowStorage({
43
+ postgresUrl: resolveDurabilityValue(input.postgresUrl, env),
44
+ sqlitePath: resolveDurabilityValue(input.sqlitePath, env)
45
+ }, (name) => env[name]?.trim() || void 0);
46
+ if (storage.backend === "postgres") return postgres(storage.source);
47
+ if (storage.source === "default" && input.defaultDatabase && context.find("database")?.store === "postgres") return postgres("the Default Database");
48
+ return sqlite(storage.path);
49
+ }
50
+ /**
51
+ * A Postgres URL for the durability input, which the build writes into the server. The reporter only needs to know
52
+ * that it is set: environment variable names stay, and a literal URL or default becomes `set`.
53
+ */
54
+ function workflowDurabilityUrl(value) {
55
+ if (typeof value === "string") return "set";
56
+ return typeof value.default === "string" ? {
57
+ ...value,
58
+ default: "set"
59
+ } : value;
60
+ }
61
+ //#endregion
62
+ export { workflowDurability, workflowDurabilityUrl };