@vite-hub/workflow 0.4.1 → 0.5.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.
- package/README.md +28 -10
- package/dist/{app-He0GTrYZ.js → app-DXUHElAz.js} +2 -3
- package/dist/{app-BojnC_yf.d.ts → app-wkVFd7m-.d.ts} +0 -2
- package/dist/{client-DkwOxEiT.js → client-CbBg4HlH.js} +88 -67
- package/dist/{cloudflare-BHfClPvT.js → cloudflare-Sgywkm1N.js} +3 -5
- package/dist/{cloudflare-env-CGLx7lUd.js → cloudflare-env-DHhzRZOs.js} +2 -4
- package/dist/cloudflare-env-lookup-BqomAHN5.d.ts +2 -0
- package/dist/{cloudflare-shared-CTqh_a2s.d.ts → cloudflare-shared-B9cY3-jD.d.ts} +1 -3
- package/dist/{config-C3DvtjfJ.js → config-CizNRTMi.js} +4 -7
- package/dist/definition.d.ts +2 -4
- package/dist/definition.js +3 -4
- package/dist/{delay-D1-nq_VE.js → delay-CtT3442d.js} +2 -4
- package/dist/{dev-recorder-CTN5Fkao.js → dev-recorder-Dltdmlkv.js} +1 -2
- package/dist/durability.d.ts +2 -4
- package/dist/durability.js +2 -3
- package/dist/{error-diagnostics-0V2T3JFw.js → error-diagnostics--2cV_ER1.js} +24 -7
- package/dist/{error-diagnostics-CQ4BUqRe.js → error-diagnostics-kKXseq8d.js} +10 -3
- package/dist/{errors-uhP8DZTi.d.ts → errors-CJZuvOcx.d.ts} +0 -7
- package/dist/{errors-DCqRnZpN.js → errors-CZf7oz4k.js} +1 -6
- package/dist/index.d.ts +7 -11
- package/dist/index.js +5 -6
- package/dist/{inspect-B72iFyj-.js → inspect-NBCAwsxi.js} +1 -2
- package/dist/{object-Da1zyPCR.js → object-CAK6UYR5.js} +1 -2
- package/dist/{openworkflow-BhzxV_Y3.d.ts → openworkflow-CdKbUGGa.d.ts} +7 -10
- package/dist/{openworkflow-defaults-DDig2M4s.js → openworkflow-defaults-DfQWtSRU.js} +2 -4
- package/dist/{openworkflow-storage-Dj9zUAsk.js → openworkflow-storage-Dde_f0es.js} +1 -2
- package/dist/openworkflow.js +1 -2
- package/dist/{operation-definition-nmRu_O3V.d.ts → operation-definition-CqZkx1Rm.d.ts} +8 -6
- package/dist/{operations-D_WJwjrS.js → operations-BBTmDm2H.js} +31 -44
- package/dist/operations.d.ts +5 -12
- package/dist/operations.js +33 -43
- package/dist/{out-DxLKolA0.js → out-r9T3bhTE.js} +2933 -2301
- package/dist/{rolldown-runtime-B4iAMlE-.js → rolldown-runtime-DYf_mQCB.js} +2 -3
- package/dist/{run-error-DBWqiJHH.js → run-error-8p4BtTMv.js} +5 -8
- package/dist/{run-failed-gVGo1BaF.js → run-failed-BcSjSU2t.js} +1 -2
- package/dist/runtime/cloudflare-runner.d.ts +14 -6
- package/dist/runtime/cloudflare-runner.js +16 -10
- package/dist/runtime/cloudflare-shared.d.ts +2 -2
- package/dist/runtime/cloudflare-shared.js +1 -2
- package/dist/runtime/cloudflare-vite.d.ts +5 -7
- package/dist/runtime/cloudflare-vite.js +5 -7
- package/dist/runtime/dev-runs.d.ts +1 -3
- package/dist/runtime/dev-runs.js +3 -3
- package/dist/runtime/execute.d.ts +3 -5
- package/dist/runtime/execute.js +66 -35
- package/dist/runtime/openworkflow-worker.d.ts +3 -4
- package/dist/runtime/openworkflow-worker.js +4 -10
- package/dist/runtime/openworkflow.d.ts +2 -2
- package/dist/runtime/openworkflow.js +37 -53
- package/dist/runtime/state.d.ts +2 -4
- package/dist/runtime/state.js +5 -4
- package/dist/runtime/vercel-vite.d.ts +3 -6
- package/dist/runtime/vercel-vite.js +4 -6
- package/dist/signals-BHQdxoJo.js +79 -0
- package/dist/{types-Dsmwsdlv.d.ts → types-DvYcvbPG.d.ts} +34 -6
- package/dist/{vercel-DTvm61iY.js → vercel-Cw_Z9-j4.js} +5 -14
- package/dist/vite.d.ts +12 -29
- package/dist/vite.js +4492 -2125
- package/package.json +13 -13
- package/dist/cloudflare-env-lookup-CfX6wZKb.d.ts +0 -4
package/README.md
CHANGED
|
@@ -52,7 +52,7 @@ Both external operations receive keys derived from stable input. Preserve that i
|
|
|
52
52
|
|
|
53
53
|
ViteHub discovers `server/workflows/<name>.ts`, folder workflows such as `server/workflows/onboard-user/index.ts`, and `src/<name>.workflow.ts`. The file or folder path is the Workflow name. `defineWorkflow()` takes one object and no name. Pass the name to the runtime helpers.
|
|
54
54
|
|
|
55
|
-
The handler gets one object with `payload`, `id`, `name`, `provider`, `sleep`, and `steps`. Pass the payload type as the type argument of `defineWorkflow()`. ViteHub writes the names and payload types to `.vitehub/workflow.d.ts`, so `startWorkflow("onboard-user", payload)` checks both.
|
|
55
|
+
The handler gets one object with `payload`, `id`, `name`, `provider`, `sleep`, `createSignal`, and `steps`. Pass the payload type as the type argument of `defineWorkflow()`. ViteHub writes the names and payload types to `.vitehub/workflow.d.ts`, so `startWorkflow("onboard-user", payload)` checks both.
|
|
56
56
|
|
|
57
57
|
## Call typed steps
|
|
58
58
|
|
|
@@ -197,18 +197,18 @@ The other runtime helpers are:
|
|
|
197
197
|
|
|
198
198
|
- `deferWorkflow()` starts a run after the response, through `waitUntil`. It returns nothing and logs a failure. Call `startWorkflow()` when you need the run id.
|
|
199
199
|
- `cancelWorkflow()` cancels a Cloudflare run with `instance.terminate()`, a native Vercel run, or a pending or running OpenWorkflow run. A finished run keeps its status, and a missing run reports `unknown`.
|
|
200
|
-
- `resumeWorkflow()`
|
|
200
|
+
- `resumeWorkflow(token, value)` sends `value` to a run that waits on `context.createSignal()`, or resumes a Workflow DevKit hook token on Vercel.
|
|
201
201
|
- `createWorkflow()` creates a named handle with `start`, `defer`, `getRun`, and `cancel` methods.
|
|
202
202
|
|
|
203
203
|
Unsupported provider operations fail with `WORKFLOW_OPERATION_UNSUPPORTED`; ViteHub does not pretend that an inline run was cancelled or resumed.
|
|
204
204
|
|
|
205
|
-
`hubWorkflow()` contributes the `workflow.start`, `get`, `cancel`, `resume`, `runs-list`,
|
|
205
|
+
`hubWorkflow()` contributes the `workflow.start`, `get`, `cancel`, `resume`, `runs-list`, and `runs-clear` operations. In `vite dev`, the dev Nitro plugin records every inline run in the memory of the dev server: its status, times, result, error, and each step of a folder Workflow. `vitehub workflow runs list` lists the newest runs first, `vitehub workflow runs get <runId>` shows one with its steps, and `vitehub workflow runs clear --yes` removes them all. The history keeps the newest 200 runs until the dev server restarts. It does not include runs that a Cloudflare binding, OpenWorkflow, or a native Vercel Workflow executes. Only the dev Nitro plugin imports the `runtime/dev-runs` module, by file path. It holds the history. The production runtime has only an empty recorder slot, so a build does not include the history code and never records runs. `runs list` and `runs clear` fail there with `WORKFLOW_RUNS_UNAVAILABLE`, and `runs get` reads the run from the provider, without steps.
|
|
206
206
|
|
|
207
207
|
The `result` of a completed run is the value that the handler returned, stored as JSON. Every provider returns the same plain value, so a `Date` comes back as a string and `undefined` fields are dropped. Return a JSON-safe value, or return a `Response` for binary data or for status and headers. When the handler returns a `Response`, `result` is a `Response`.
|
|
208
208
|
|
|
209
209
|
Inline runs buffer a returned `Response` body before completion. Each inspection and duplicate start returns a fresh `Response`, so reading or cancelling one result does not consume later results. A body read failure marks the run as failed.
|
|
210
210
|
|
|
211
|
-
Inline run inspection uses weak references while execution is active. A reachable execution remains inspectable; an abandoned execution with no remaining owner can be garbage-collected and then reports `unknown`. Completed inline runs are retained for five minutes, up to 1,024 entries per runtime. Completed history does not evict active executions. If either `WeakRef` or `FinalizationRegistry` is unavailable, active inspection uses strong references capped at 1,024 entries. Starting another run evicts the oldest active inspection entry, even if execution is still reachable; it reports `unknown` and completion does not restore it. Use a durable provider when inspection must survive abandonment or a process restart.
|
|
211
|
+
Inline run inspection uses weak references while execution is active. A reachable execution remains inspectable; an abandoned execution with no remaining owner can be garbage-collected and then reports `unknown`. Completed inline runs are retained for five minutes, up to 1,024 entries per runtime. In `vite dev`, `getWorkflowRun()` also reads the dev run history, which keeps the newest 200 runs until the dev server restarts. Completed history does not evict active executions. If either `WeakRef` or `FinalizationRegistry` is unavailable, active inspection uses strong references capped at 1,024 entries. Starting another run evicts the oldest active inspection entry, even if execution is still reachable; it reports `unknown` and completion does not restore it. Use a durable provider when inspection must survive abandonment or a process restart.
|
|
212
212
|
|
|
213
213
|
## Start a run later
|
|
214
214
|
|
|
@@ -222,9 +222,9 @@ const [error, run] = await startWorkflow("send-reminder", { email }, { delay: "3
|
|
|
222
222
|
| --- | --- | --- |
|
|
223
223
|
| OpenWorkflow | The run stays pending in storage until its start time (`availableAt`). | `queued` |
|
|
224
224
|
| Cloudflare | The run sleeps with `step.sleepUntil()` before the handler. A waiting instance does not count toward the concurrency limit. | `running` |
|
|
225
|
-
| Vercel
|
|
225
|
+
| Vercel, generated native entry for numbered steps without an index handler | The generated entry calls Workflow DevKit `sleep()` before the first step. | `running` |
|
|
226
226
|
| Vercel `native` entry that you wrote | Not supported. `startWorkflow()` returns the error `WORKFLOW_OPERATION_UNSUPPORTED`. | |
|
|
227
|
-
| Inline runs (`vite dev`, normal Vercel handlers) | A timer in the process. It is not durable: a restart loses the run. | `queued` |
|
|
227
|
+
| Inline runs (`vite dev`, normal Vercel handlers) | A timer in the process. It is not durable: a restart loses the run. Outside `vite dev`, the first delayed run of each Workflow logs a warning. | `queued` |
|
|
228
228
|
|
|
229
229
|
For a recurring run, call `startWorkflow()` from a [Schedule](https://vitehub.dev/docs/schedule) handler.
|
|
230
230
|
|
|
@@ -299,7 +299,7 @@ export const timeout = "2 minutes";
|
|
|
299
299
|
|
|
300
300
|
Cloudflare gets both in `step.do()`. OpenWorkflow gets `retries` as its `retryPolicy`, and a generated Vercel step gets `limit` as `maxRetries`. Vercel steps cannot set `delay` or `backoff`, so the build fails with `WORKFLOW_STEP_RETRY_DELAY_UNSUPPORTED`. Outside Cloudflare, ViteHub enforces `timeout` itself: it aborts the `signal` that the step function gets as its second argument and fails the attempt. Code that ignores the signal keeps running. An inline run does not retry. See [Retries and sleeps](https://vitehub.dev/docs/workflows/limits-and-errors#retries-and-sleeps).
|
|
301
301
|
|
|
302
|
-
Throw `NonRetryableError` when another attempt cannot succeed. The run fails at once on every provider. `getWorkflowRun()` reports the error `message` and `name` in `
|
|
302
|
+
Throw `NonRetryableError` when another attempt cannot succeed. The run fails at once on every provider. `getWorkflowRun()` reports the error `message` and `name` in `error` on every provider, and inline runs also keep `code`. OpenWorkflow also reports the original message on the failed step in `steps`. Native Vercel can report a generic step error if it cannot read the provider's step error message. Cloudflare also keeps the error in its status record in `metadata`.
|
|
303
303
|
|
|
304
304
|
```ts fragment
|
|
305
305
|
import { NonRetryableError } from "@vite-hub/workflow";
|
|
@@ -329,6 +329,25 @@ After a sleep, the provider runs `index.ts` again from the start, and completed
|
|
|
329
329
|
|
|
330
330
|
A single-file Workflow runs as one root step, and a replay after a sleep would run the code before the sleep again. So `context.sleep()` in a single-file Workflow throws `WORKFLOW_ROOT_STEP_SLEEP` on every provider, and the run fails without a retry. A duration that is not in the form above throws `WORKFLOW_SLEEP_DURATION_INVALID`.
|
|
331
331
|
|
|
332
|
+
A folder Workflow can wait for a value from outside the run, such as a webhook. `context.createSignal<T>()` returns `{ token, wait() }`. Give `token` to the other service, then call `wait()`. `resumeWorkflow(token, value)` sends a JSON value, and `wait()` returns it.
|
|
333
|
+
|
|
334
|
+
```ts fragment
|
|
335
|
+
// server/workflows/summary/index.ts
|
|
336
|
+
export default defineWorkflow<{ callId: string }>({
|
|
337
|
+
handler: async ({ createSignal, payload, steps }) => {
|
|
338
|
+
const transcript = createSignal<{ text: string }>();
|
|
339
|
+
await steps.requestTranscript({ callId: payload.callId, token: transcript.token });
|
|
340
|
+
const { text } = await transcript.wait();
|
|
341
|
+
return await steps.summarize({ text });
|
|
342
|
+
},
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
// server/api/webhooks/transcript.post.ts, after the webhook signature check
|
|
346
|
+
const [error] = await resumeWorkflow(body.token, { text: body.text });
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
ViteHub makes the token from the Workflow name, the run id, and the call order (`signal-1`, `signal-2`), so a replay gets the same token. The token is not a secret: check the caller before you pass a token from a request. Cloudflare waits with `step.waitForEvent()` for at most 365 days, and `resumeWorkflow()` calls `instance.sendEvent()`. OpenWorkflow waits with `step.waitForSignal()` for one year, then fails the run with `WORKFLOW_SIGNAL_TIMEOUT`. It drops a value that comes before the wait, so `resumeWorkflow()` returns `WORKFLOW_SIGNAL_NOT_WAITING` and the caller retries later. Inline runs wait in memory and keep an early value. Vercel does not support signals yet: `createSignal()` throws `WORKFLOW_SIGNAL_VERCEL_UNSUPPORTED`, and a `native` entry uses `defineHook()` from Workflow DevKit instead. A token of another provider returns `WORKFLOW_SIGNAL_TOKEN_INVALID`, and `wait()` in a single-file Workflow throws `WORKFLOW_ROOT_STEP_SIGNAL`.
|
|
350
|
+
|
|
332
351
|
## Production checklist
|
|
333
352
|
|
|
334
353
|
- Confirm that the selected provider is durable enough for the work; inline Vercel handlers are not durable.
|
|
@@ -354,8 +373,7 @@ A typed Workflow handle requires a payload when its handler requires one. Both `
|
|
|
354
373
|
const welcome = createWorkflow<{ email: string }>("welcome", async ({ payload }) => {
|
|
355
374
|
await sendWelcomeEmail(payload.email)
|
|
356
375
|
})
|
|
357
|
-
await welcome.start({ email: "ada@example.com" })
|
|
358
|
-
// welcome.start() is a type error.
|
|
376
|
+
const [error, run] = await welcome.start({ email: "ada@example.com" })
|
|
359
377
|
```
|
|
360
378
|
|
|
361
|
-
|
|
379
|
+
For a Workflow created outside discovery, use its handle. For a discovered Workflow, use its discovered name with `startWorkflow()` or `deferWorkflow()`, even if its file exports a `createWorkflow()` handle with a different name. These functions read the payload type from `.vitehub/workflow.d.ts` when the default export has a typed handler. A handle export does not supply that handler type. Stored run results stay `unknown`.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as internalErrorDiagnostics } from "./error-diagnostics-
|
|
2
|
-
|
|
1
|
+
import { t as internalErrorDiagnostics } from "./error-diagnostics-kKXseq8d.js";
|
|
2
|
+
// ../internal/src/runtime/app.ts
|
|
3
3
|
function resolveAppFetch(label, app) {
|
|
4
4
|
if (!app) return;
|
|
5
5
|
if (typeof app === "function") return app;
|
|
@@ -7,5 +7,4 @@ function resolveAppFetch(label, app) {
|
|
|
7
7
|
if (typeof app.fetch === "function") return app.fetch.bind(app);
|
|
8
8
|
throw internalErrorDiagnostics.INTERNAL_R0011({ message: `Invalid ${label} app. Expected an h3 app or a fetch-compatible handler.` });
|
|
9
9
|
}
|
|
10
|
-
//#endregion
|
|
11
10
|
export { resolveAppFetch as t };
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
//#region ../internal/src/runtime/app.d.ts
|
|
2
1
|
type AppHandler = (request: Request, context?: Record<string, unknown>) => Response | Promise<Response>;
|
|
3
2
|
type VitehubApp = AppHandler | {
|
|
4
3
|
fetch?: AppHandler;
|
|
5
4
|
request?: (request: Request, options?: RequestInit, context?: Record<string, unknown>) => Response | Promise<Response>;
|
|
6
5
|
};
|
|
7
|
-
//#endregion
|
|
8
6
|
export { VitehubApp as t };
|
|
@@ -1,30 +1,42 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { i as toCloudflareStartParams, r as resolveWorkflowStartAt } from "./delay-
|
|
7
|
-
import { t as getWorkflowDevRecorder } from "./dev-recorder-
|
|
1
|
+
import { a as getCloudflareEnv, n as resolveWaitUntil } from "./cloudflare-env-DHhzRZOs.js";
|
|
2
|
+
import { t as normalizeWorkflowOptions } from "./config-CizNRTMi.js";
|
|
3
|
+
import { n as createWorkflowError } from "./errors-CZf7oz4k.js";
|
|
4
|
+
import { t as workflowErrorDiagnostics } from "./error-diagnostics--2cV_ER1.js";
|
|
5
|
+
import { a as encodeNameHex, n as getCloudflareWorkflowBindingName } from "./cloudflare-Sgywkm1N.js";
|
|
6
|
+
import { i as toCloudflareStartParams, r as resolveWorkflowStartAt } from "./delay-CtT3442d.js";
|
|
7
|
+
import { t as getWorkflowDevRecorder } from "./dev-recorder-Dltdmlkv.js";
|
|
8
8
|
import { runSerializedWorkflowHandler } from "./runtime/execute.js";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
9
|
+
import { cloudflareSignalEventType } from "./runtime/cloudflare-runner.js";
|
|
10
|
+
import { cancelOpenWorkflowRun, getOpenWorkflowRun, resumeOpenWorkflowSignal, runOpenWorkflow } from "./runtime/openworkflow.js";
|
|
11
|
+
import { a as safeWorkflowName, i as runWorkflowProviderOperation, t as toWorkflowRunError } from "./run-error-8p4BtTMv.js";
|
|
12
|
+
import { t as emitWorkflowFailed } from "./run-failed-BcSjSU2t.js";
|
|
13
|
+
import { i as readWorkflowSignalToken, o as resumeInlineWorkflowSignal } from "./signals-BHQdxoJo.js";
|
|
12
14
|
import { getInlineWorkflowDefinitions, getWorkflowRunState, getWorkflowRuntimeConfig, getWorkflowRuntimeEvent, getWorkflowRuntimeRegistry, loadWorkflowDefinition, registerInlineWorkflowDefinition, runWithWorkflowRuntimeEvent, setWorkflowRun } from "./runtime/state.js";
|
|
13
|
-
import { a as startVercelWorkflow, n as inspectVercelWorkflowRun, r as resumeVercelWorkflowSignal, t as cancelVercelWorkflow } from "./vercel-
|
|
14
|
-
import {
|
|
15
|
+
import { a as startVercelWorkflow, n as inspectVercelWorkflowRun, r as resumeVercelWorkflowSignal, t as cancelVercelWorkflow } from "./vercel-Cw_Z9-j4.js";
|
|
16
|
+
import { getViteHubErrorShape, isRuntimeDiagnostic, toResultError } from "@vite-hub/runtime";
|
|
15
17
|
import { getViteHubTestMode } from "@vite-hub/runtime/internal/test-mode";
|
|
16
|
-
|
|
18
|
+
import { deserializeResponse, isSerializedResponse } from "@vite-hub/runtime/internal/response";
|
|
19
|
+
// ../internal/src/runtime/random.ts
|
|
17
20
|
function randomId(prefix) {
|
|
18
21
|
const body = `${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 10)}`;
|
|
19
22
|
return prefix ? `${prefix}_${body}` : body;
|
|
20
23
|
}
|
|
21
|
-
|
|
22
|
-
//#region src/integrations/vercel.ts
|
|
24
|
+
// src/integrations/vercel.ts
|
|
23
25
|
function getVercelWorkflowName(name) {
|
|
24
26
|
return `workflow--${encodeNameHex(name)}`;
|
|
25
27
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
// src/runtime/adapters.ts
|
|
29
|
+
async function resumeViteHubSignal(config, token, payload, durable) {
|
|
30
|
+
const address = readWorkflowSignalToken(token);
|
|
31
|
+
if (!address) throw workflowErrorDiagnostics.WORKFLOW_SIGNAL_TOKEN_INVALID({ provider: config.driver });
|
|
32
|
+
if (address.host === "inline") resumeInlineWorkflowSignal(token, address, payload);
|
|
33
|
+
else if (address.host === config.driver && durable) await durable(address);
|
|
34
|
+
else throw workflowErrorDiagnostics.WORKFLOW_SIGNAL_TOKEN_INVALID({ provider: config.driver });
|
|
35
|
+
return {
|
|
36
|
+
id: address.run,
|
|
37
|
+
provider: config.driver
|
|
38
|
+
};
|
|
39
|
+
}
|
|
28
40
|
function resolveDispatchObserver(event) {
|
|
29
41
|
if (!event || typeof event !== "object") return void 0;
|
|
30
42
|
const candidate = Object.hasOwn(event, "onDispatch") ? Reflect.get(event, "onDispatch") : void 0;
|
|
@@ -49,19 +61,11 @@ function unsupportedOperation(provider, operation) {
|
|
|
49
61
|
}
|
|
50
62
|
});
|
|
51
63
|
}
|
|
52
|
-
/**
|
|
53
|
-
* True on a development server: `vite dev` installs the run history. Code that ViteHub did not start, such as a test
|
|
54
|
-
* runner, has no history, so `NODE_ENV` decides there.
|
|
55
|
-
*/
|
|
56
64
|
function isDevelopmentServer() {
|
|
57
65
|
if (getWorkflowDevRecorder()) return true;
|
|
58
66
|
const mode = globalThis.process?.env?.NODE_ENV;
|
|
59
67
|
return mode === "development" || mode === "test";
|
|
60
68
|
}
|
|
61
|
-
/**
|
|
62
|
-
* The Cloudflare Workflow binding of `name`. Only a development server runs the Workflow inline without it. Elsewhere,
|
|
63
|
-
* a missing binding fails, because an inline run is not durable.
|
|
64
|
-
*/
|
|
65
69
|
function resolveCloudflareBinding(event, binding, name, definition) {
|
|
66
70
|
const env = getCloudflareEnv(event);
|
|
67
71
|
const bindingName = definition?.internalAgentInvocationRecovery ? getCloudflareWorkflowBindingName(name) : binding || getCloudflareWorkflowBindingName(name);
|
|
@@ -75,7 +79,6 @@ function resolveCloudflareBinding(event, binding, name, definition) {
|
|
|
75
79
|
function resolveCloudflareInspectionBinding(event, binding, name) {
|
|
76
80
|
return resolveCloudflareBinding(event, binding, name, getWorkflowRuntimeRegistry()?.[name]);
|
|
77
81
|
}
|
|
78
|
-
/** The start can have reached Cloudflare, so the acknowledgement is unknown. */
|
|
79
82
|
function invalidCloudflareWorkflowStart(cause) {
|
|
80
83
|
return createWorkflowError({
|
|
81
84
|
...cause === void 0 ? {} : { cause },
|
|
@@ -100,7 +103,6 @@ function normalizeCloudflareWorkflowStart(value, expectedId) {
|
|
|
100
103
|
return { id };
|
|
101
104
|
}
|
|
102
105
|
const cloudflareInstanceIdPattern = /^[a-zA-Z0-9_][a-zA-Z0-9_-]{0,99}$/;
|
|
103
|
-
/** The array-form `createBatch` accepts reserved ids, unlike the object form. */
|
|
104
106
|
function isCloudflareInstanceId(id) {
|
|
105
107
|
return cloudflareInstanceIdPattern.test(id);
|
|
106
108
|
}
|
|
@@ -123,18 +125,15 @@ function normalizeCloudflareStatus(status) {
|
|
|
123
125
|
const normalized = String(value || "").toLowerCase();
|
|
124
126
|
return Object.hasOwn(cloudflareStatusMap, normalized) ? cloudflareStatusMap[normalized] : "unknown";
|
|
125
127
|
}
|
|
126
|
-
/** The run result from Cloudflare status: the stored value, or a `Response` when the handler returned one. */
|
|
127
128
|
function cloudflareRunResult(metadata) {
|
|
128
129
|
if (typeof metadata !== "object" || metadata === null || !Object.hasOwn(metadata, "output")) return void 0;
|
|
129
130
|
const output = metadata.output;
|
|
130
131
|
return isSerializedResponse(output) ? deserializeResponse(output) : output;
|
|
131
132
|
}
|
|
132
|
-
/** The `error` member of a Cloudflare `status()` record. */
|
|
133
133
|
function ownStatusError(metadata) {
|
|
134
134
|
if (typeof metadata !== "object" || metadata === null || !Object.hasOwn(metadata, "error")) return void 0;
|
|
135
135
|
return Reflect.get(metadata, "error");
|
|
136
136
|
}
|
|
137
|
-
/** Cloudflare `get(id)` rejects with `instance.not_found` when no instance has the id. */
|
|
138
137
|
function isCloudflareInstanceNotFound(error) {
|
|
139
138
|
if (typeof error !== "object" || error === null) return false;
|
|
140
139
|
try {
|
|
@@ -144,10 +143,6 @@ function isCloudflareInstanceNotFound(error) {
|
|
|
144
143
|
return false;
|
|
145
144
|
}
|
|
146
145
|
}
|
|
147
|
-
/**
|
|
148
|
-
* The Cloudflare Workflows service refused the call: its error carries a service code such as `(instance.already_exists)`,
|
|
149
|
-
* or local Miniflare rejected the instance id. A lost connection has neither.
|
|
150
|
-
*/
|
|
151
146
|
function isCloudflareRejection(error) {
|
|
152
147
|
if (typeof error !== "object" || error === null) return false;
|
|
153
148
|
try {
|
|
@@ -162,7 +157,6 @@ function hasUnknownWorkflowAcknowledgement(error) {
|
|
|
162
157
|
const details = error.details;
|
|
163
158
|
return Boolean(details && typeof details === "object" && details.acknowledgement === "unknown");
|
|
164
159
|
}
|
|
165
|
-
/** Reads a Cloudflare Workflow instance and its run. A missing instance has no `instance` and reports `unknown`. */
|
|
166
160
|
async function readCloudflareRun(binding, id) {
|
|
167
161
|
const instance = await runWorkflowProviderOperation("cloudflare", "get", async () => {
|
|
168
162
|
try {
|
|
@@ -196,10 +190,6 @@ const finishedRunStatuses = /* @__PURE__ */ new Set([
|
|
|
196
190
|
"completed",
|
|
197
191
|
"failed"
|
|
198
192
|
]);
|
|
199
|
-
/**
|
|
200
|
-
* Terminates a Cloudflare Workflow instance that has not finished and returns its run afterwards. A finished run keeps
|
|
201
|
-
* and reports its status, and a missing run reports `unknown`, as on OpenWorkflow.
|
|
202
|
-
*/
|
|
203
193
|
async function cancelCloudflareRun(binding, id) {
|
|
204
194
|
const { instance, run } = await readCloudflareRun(binding, id);
|
|
205
195
|
if (!instance || run.status === "unknown" || finishedRunStatuses.has(run.status)) return run;
|
|
@@ -268,18 +258,28 @@ function createCloudflareAdapter(config) {
|
|
|
268
258
|
}
|
|
269
259
|
return await inlineAdapter(config).run(context);
|
|
270
260
|
},
|
|
271
|
-
resume: () =>
|
|
261
|
+
resume: async (token, payload) => await resumeViteHubSignal(config, token, payload, async ({ run, signal, workflow }) => {
|
|
262
|
+
const binding = resolveCloudflareInspectionBinding(getWorkflowRuntimeEvent(), config.binding, workflow);
|
|
263
|
+
if (!binding) throw workflowErrorDiagnostics.WORKFLOW_SIGNAL_NOT_WAITING({ run });
|
|
264
|
+
const { instance, run: current } = await readCloudflareRun(binding, run);
|
|
265
|
+
if (!instance || finishedRunStatuses.has(current.status)) throw workflowErrorDiagnostics.WORKFLOW_SIGNAL_NOT_WAITING({ run });
|
|
266
|
+
await runWorkflowProviderOperation("cloudflare", "resume-signal", async () => {
|
|
267
|
+
if (!instance.sendEvent) unsupportedOperation("cloudflare", "signals");
|
|
268
|
+
try {
|
|
269
|
+
await instance.sendEvent({
|
|
270
|
+
payload,
|
|
271
|
+
type: cloudflareSignalEventType(signal)
|
|
272
|
+
});
|
|
273
|
+
} catch (error) {
|
|
274
|
+
if (isCloudflareInstanceNotFound(error)) throw workflowErrorDiagnostics.WORKFLOW_SIGNAL_NOT_WAITING({ run });
|
|
275
|
+
throw error;
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
})
|
|
272
279
|
};
|
|
273
280
|
return adapter;
|
|
274
281
|
}
|
|
275
282
|
const warnedInlineOpenWorkflowNames = /* @__PURE__ */ new Set();
|
|
276
|
-
/**
|
|
277
|
-
* Every OpenWorkflow worker registers the Workflow Definitions of the build registry when it starts: discovered
|
|
278
|
-
* Workflows and discovered Agent Workflows. Any worker can claim a run, so a run of an inline
|
|
279
|
-
* `createWorkflow(name, handler)` could wait in storage on a worker that never registers it. Those runs execute inline
|
|
280
|
-
* in this process. A turn of an Agent that is not discovered fails with `WORKFLOW_AGENT_NOT_DISCOVERED`, so Agent turns are
|
|
281
|
-
* never inline.
|
|
282
|
-
*/
|
|
283
283
|
function isDurableOpenWorkflowDefinition(name) {
|
|
284
284
|
const registry = getWorkflowRuntimeRegistry();
|
|
285
285
|
return Boolean(registry && Object.hasOwn(registry, name));
|
|
@@ -297,7 +297,9 @@ function createOpenWorkflowAdapter(config) {
|
|
|
297
297
|
id,
|
|
298
298
|
name
|
|
299
299
|
}),
|
|
300
|
-
resume: () =>
|
|
300
|
+
resume: async (token, payload) => await resumeViteHubSignal(config, token, payload, async ({ run, workflow }) => {
|
|
301
|
+
if (!await resumeOpenWorkflowSignal(config, workflow, run, token, payload)) throw workflowErrorDiagnostics.WORKFLOW_SIGNAL_NOT_WAITING({ run });
|
|
302
|
+
}),
|
|
301
303
|
run: async (context) => {
|
|
302
304
|
const { definition, event, name, options, payload, startAt } = context;
|
|
303
305
|
if (isDurableOpenWorkflowDefinition(name)) return await runOpenWorkflow(config, name, payload, definition, options, resolveDispatchObserver(event), startAt);
|
|
@@ -316,11 +318,27 @@ function createOpenWorkflowAdapter(config) {
|
|
|
316
318
|
}
|
|
317
319
|
};
|
|
318
320
|
}
|
|
319
|
-
/** `setTimeout` fires at once for a delay above 2^31 - 1 ms (about 24.8 days), so a long wait uses several timers. */
|
|
320
321
|
const maximumTimerDelay = 2147483647;
|
|
322
|
+
const warnedDelayedInlineWorkflowNames = /* @__PURE__ */ new Set();
|
|
323
|
+
function warnDelayedInlineRun(name, startAt) {
|
|
324
|
+
if (startAt === void 0 || startAt <= Date.now() || isDevelopmentServer() || warnedDelayedInlineWorkflowNames.has(name)) return;
|
|
325
|
+
warnedDelayedInlineWorkflowNames.add(name);
|
|
326
|
+
console.warn(`[vitehub:workflow] The Workflow ${JSON.stringify(name)} starts later in an inline run. A timer in this process holds the run, so a restart loses it. Use OpenWorkflow, Cloudflare, or a Vercel \`native\` entry for a durable delay.`);
|
|
327
|
+
}
|
|
321
328
|
async function waitUntilTime(startAt) {
|
|
322
329
|
while (startAt !== void 0 && startAt > Date.now()) await new Promise((resolve) => setTimeout(resolve, Math.min(startAt - Date.now(), maximumTimerDelay)));
|
|
323
330
|
}
|
|
331
|
+
function recordedDevRun(config, name, id) {
|
|
332
|
+
const record = getWorkflowDevRecorder()?.get(name, id);
|
|
333
|
+
if (record?.status !== "completed" && record?.status !== "failed") return;
|
|
334
|
+
return {
|
|
335
|
+
...record.status === "failed" ? { error: toWorkflowRunError(record.error) } : {},
|
|
336
|
+
id,
|
|
337
|
+
provider: config.driver,
|
|
338
|
+
result: isSerializedResponse(record.result) ? deserializeResponse(record.result) : record.result,
|
|
339
|
+
status: record.status
|
|
340
|
+
};
|
|
341
|
+
}
|
|
324
342
|
function inlineAdapter(config) {
|
|
325
343
|
return {
|
|
326
344
|
cancel: () => unsupportedOperation(config.driver, "cancellation"),
|
|
@@ -340,6 +358,8 @@ function inlineAdapter(config) {
|
|
|
340
358
|
status: run.status
|
|
341
359
|
};
|
|
342
360
|
}
|
|
361
|
+
const recorded = recordedDevRun(config, name, id);
|
|
362
|
+
if (recorded) return recorded;
|
|
343
363
|
return {
|
|
344
364
|
id,
|
|
345
365
|
provider: config.driver,
|
|
@@ -348,6 +368,14 @@ function inlineAdapter(config) {
|
|
|
348
368
|
},
|
|
349
369
|
async run({ definition, event, id, name, payload, startAt }) {
|
|
350
370
|
const existing = getWorkflowRunState(name, id);
|
|
371
|
+
const recorded = existing ? void 0 : recordedDevRun(config, name, id);
|
|
372
|
+
if (recorded) return {
|
|
373
|
+
...recorded,
|
|
374
|
+
metadata: config.driver === "vercel" ? {
|
|
375
|
+
mode: "inline",
|
|
376
|
+
workflow: getVercelWorkflowName(name)
|
|
377
|
+
} : void 0
|
|
378
|
+
};
|
|
351
379
|
if (existing) return {
|
|
352
380
|
...existing.status === "failed" ? { error: toWorkflowRunError(existing.error) } : {},
|
|
353
381
|
id,
|
|
@@ -368,6 +396,7 @@ function inlineAdapter(config) {
|
|
|
368
396
|
payload,
|
|
369
397
|
provider: config.driver
|
|
370
398
|
}, definition);
|
|
399
|
+
warnDelayedInlineRun(name, startAt);
|
|
371
400
|
const run = waitUntilTime(startAt).then(() => {
|
|
372
401
|
runState.startAt = void 0;
|
|
373
402
|
return recordRun ? recordRun(execute) : execute();
|
|
@@ -395,17 +424,12 @@ function inlineAdapter(config) {
|
|
|
395
424
|
status: "queued"
|
|
396
425
|
};
|
|
397
426
|
},
|
|
398
|
-
resume: () =>
|
|
427
|
+
resume: async (token, payload) => await resumeViteHubSignal(config, token, payload)
|
|
399
428
|
};
|
|
400
429
|
}
|
|
401
|
-
/**
|
|
402
|
-
* True when Workflow DevKit runs the `native` entry. `vite dev` does not run the Workflow DevKit transform, so the
|
|
403
|
-
* dev server runs the normal handler inline, as for every other Workflow there.
|
|
404
|
-
*/
|
|
405
430
|
function runsNatively(definition) {
|
|
406
431
|
return Boolean(definition?.native) && !getWorkflowDevRecorder();
|
|
407
432
|
}
|
|
408
|
-
/** Whether a registered Workflow has a native Vercel entry, so a run of it can wait for a signal. */
|
|
409
433
|
async function hasNativeWorkflowDefinition() {
|
|
410
434
|
const names = /* @__PURE__ */ new Set([...Object.keys(getWorkflowRuntimeRegistry() ?? {}), ...getInlineWorkflowDefinitions().keys()]);
|
|
411
435
|
for (const name of names) if ((await loadWorkflowDefinition(name))?.native) return true;
|
|
@@ -432,6 +456,7 @@ function createVercelAdapter(config) {
|
|
|
432
456
|
});
|
|
433
457
|
},
|
|
434
458
|
async resume(token, payload) {
|
|
459
|
+
if (readWorkflowSignalToken(token)) throw workflowErrorDiagnostics.WORKFLOW_SIGNAL_TOKEN_INVALID({ provider: config.driver });
|
|
435
460
|
if (getWorkflowDevRecorder()) unsupportedOperation(config.driver, "signals");
|
|
436
461
|
try {
|
|
437
462
|
return await resumeVercelWorkflowSignal(token, payload);
|
|
@@ -452,8 +477,7 @@ function getWorkflowRuntimeAdapter(config) {
|
|
|
452
477
|
if (config.driver === "openworkflow") return createOpenWorkflowAdapter(config);
|
|
453
478
|
return createVercelAdapter(config);
|
|
454
479
|
}
|
|
455
|
-
|
|
456
|
-
//#region src/runtime/test-client.ts
|
|
480
|
+
// src/runtime/test-client.ts
|
|
457
481
|
/** The started runs of the current test. `vite-hub/test` reads the same list. */
|
|
458
482
|
function workflowTestRuns(test) {
|
|
459
483
|
return test.backend("workflow", () => []);
|
|
@@ -492,8 +516,7 @@ function getWorkflowTestRun(test, provider, name, id, cancel = false) {
|
|
|
492
516
|
if (cancel) run.status = "cancelled";
|
|
493
517
|
return toWorkflowRun(run, provider);
|
|
494
518
|
}
|
|
495
|
-
|
|
496
|
-
//#region src/runtime/client.ts
|
|
519
|
+
// src/runtime/client.ts
|
|
497
520
|
const resultErrorCodes = /* @__PURE__ */ new Set([
|
|
498
521
|
"RUNTIME_DURATION_INVALID",
|
|
499
522
|
"WORKFLOW_CLOUDFLARE_RUN_ID_INVALID",
|
|
@@ -501,15 +524,13 @@ const resultErrorCodes = /* @__PURE__ */ new Set([
|
|
|
501
524
|
"WORKFLOW_PROVIDER_OPERATION_FAILED",
|
|
502
525
|
"WORKFLOW_R0014",
|
|
503
526
|
"WORKFLOW_RUN_ID_UNSUPPORTED",
|
|
527
|
+
"WORKFLOW_SIGNAL_NOT_WAITING",
|
|
528
|
+
"WORKFLOW_SIGNAL_TOKEN_INVALID",
|
|
504
529
|
"WORKFLOW_START_DELAY_INVALID"
|
|
505
530
|
]);
|
|
506
531
|
function resultError(diagnostic) {
|
|
507
532
|
return toResultError(diagnostic);
|
|
508
533
|
}
|
|
509
|
-
/**
|
|
510
|
-
* Returns a runtime failure of a Workflow call as a catalog error. The providers throw `ViteHubError` inside the
|
|
511
|
-
* package. The catalog error keeps its `details` in `data` and the provider error in `cause`. Config errors throw.
|
|
512
|
-
*/
|
|
513
534
|
function toWorkflowResultError(error) {
|
|
514
535
|
if (isRuntimeDiagnostic(error) && resultErrorCodes.has(error.code)) return resultError(error);
|
|
515
536
|
const shape = getViteHubErrorShape(error);
|
|
@@ -527,7 +548,6 @@ function toWorkflowResultError(error) {
|
|
|
527
548
|
provider: details.provider
|
|
528
549
|
}));
|
|
529
550
|
}
|
|
530
|
-
/** Runs one Workflow call and returns its runtime failure as `[error, undefined]`. */
|
|
531
551
|
async function toWorkflowResult(run) {
|
|
532
552
|
try {
|
|
533
553
|
return [void 0, await run()];
|
|
@@ -676,8 +696,10 @@ async function cancelWorkflow(name, id) {
|
|
|
676
696
|
}));
|
|
677
697
|
}
|
|
678
698
|
/**
|
|
679
|
-
* Resumes a run that waits for a signal and returns `[error, signal]`. `token` is
|
|
680
|
-
*
|
|
699
|
+
* Resumes a run that waits for a signal and returns `[error, signal]`. `token` is `signal.token` from
|
|
700
|
+
* `context.createSignal()`, or the hook token of a native Vercel entry. `payload` is the value that `signal.wait()`
|
|
701
|
+
* returns: send a JSON value. An invalid token, a run that does not wait for the token, or a provider failure is
|
|
702
|
+
* `error`. Config errors throw.
|
|
681
703
|
*/
|
|
682
704
|
async function resumeWorkflow(token, payload) {
|
|
683
705
|
if (!token || typeof token !== "string") return [resultError(workflowErrorDiagnostics.WORKFLOW_R0014({ message: "`resumeWorkflow()` requires an opaque signal token." })), void 0];
|
|
@@ -703,5 +725,4 @@ function deferWorkflowStart(name, start) {
|
|
|
703
725
|
function deferWorkflow(...[name, payload, options = {}]) {
|
|
704
726
|
deferWorkflowStart(name, () => startWorkflowRun(name, payload, options, true));
|
|
705
727
|
}
|
|
706
|
-
//#endregion
|
|
707
728
|
export { resumeWorkflow as a, getWorkflowRun as i, createWorkflow as n, startWorkflow as o, deferWorkflow as r, cancelWorkflow as t };
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { t as workflowErrorDiagnostics } from "./error-diagnostics
|
|
2
|
-
|
|
1
|
+
import { t as workflowErrorDiagnostics } from "./error-diagnostics--2cV_ER1.js";
|
|
2
|
+
// ../internal/src/integrations/hex.ts
|
|
3
3
|
const textEncoder = new TextEncoder();
|
|
4
4
|
new TextDecoder();
|
|
5
5
|
function encodeNameHex(name) {
|
|
6
6
|
return [...textEncoder.encode(name)].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
//#region src/integrations/cloudflare.ts
|
|
8
|
+
// src/integrations/cloudflare.ts
|
|
10
9
|
const cloudflareWorkflowNameMaxLength = 64;
|
|
11
10
|
function shortHash(value) {
|
|
12
11
|
let hash = 14695981039346656037n;
|
|
@@ -55,5 +54,4 @@ function createCloudflareWorkflowBindings(definitions, options) {
|
|
|
55
54
|
name: configurable.length === 1 && configurable[0] === definition && options ? options.name || getCloudflareWorkflowName(definition.name) : getCloudflareWorkflowName(definition.name)
|
|
56
55
|
}));
|
|
57
56
|
}
|
|
58
|
-
//#endregion
|
|
59
57
|
export { encodeNameHex as a, getLegacyCloudflareWorkflowClassName as i, getCloudflareWorkflowBindingName as n, getCloudflareWorkflowClassName as r, createCloudflareWorkflowBindings as t };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
-
|
|
2
|
+
// ../internal/src/runtime/cloudflare-env-lookup.ts
|
|
3
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
5
|
let activeEnv;
|
|
@@ -39,8 +39,7 @@ function getCloudflareEnv(event, options = {}) {
|
|
|
39
39
|
for (const candidate of [ownValue(target, "env"), ...cloudflareOwners(target).map((owner) => ownValue(owner, "env"))]) if (candidate) return candidate;
|
|
40
40
|
return options.fallback === false ? void 0 : getActiveCloudflareEnv();
|
|
41
41
|
}
|
|
42
|
-
|
|
43
|
-
//#region ../internal/src/runtime/cloudflare-env.ts
|
|
42
|
+
// ../internal/src/runtime/cloudflare-env.ts
|
|
44
43
|
const runtimeGlobal = globalThis;
|
|
45
44
|
const activeEnvStorage = runtimeGlobal[activeEnvStorageKey] ||= new AsyncLocalStorage();
|
|
46
45
|
const globalEnvProbe = Symbol("vitehub.cloudflare.global-env-probe");
|
|
@@ -111,5 +110,4 @@ function createCloudflareRuntimeEvent(env, context) {
|
|
|
111
110
|
waitUntil
|
|
112
111
|
};
|
|
113
112
|
}
|
|
114
|
-
//#endregion
|
|
115
113
|
export { getCloudflareEnv as a, setActiveCloudflareEnv as i, resolveWaitUntil as n, runWithActiveCloudflareEnv as r, createCloudflareRuntimeEvent as t };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { t as CloudflareWorkerEnv } from "./cloudflare-env-lookup-
|
|
2
|
-
//#region ../internal/src/runtime/cloudflare-env.d.ts
|
|
1
|
+
import { t as CloudflareWorkerEnv } from "./cloudflare-env-lookup-BqomAHN5.js";
|
|
3
2
|
interface CloudflareWorkerExecutionContext {
|
|
4
3
|
waitUntil?: (promise: Promise<unknown>) => void;
|
|
5
4
|
}
|
|
@@ -18,5 +17,4 @@ interface CloudflareRuntimeEvent {
|
|
|
18
17
|
waitUntil?: WaitUntilFn;
|
|
19
18
|
}
|
|
20
19
|
declare function createCloudflareRuntimeEvent(env: CloudflareWorkerEnv, context: CloudflareWorkerExecutionContext | undefined): CloudflareRuntimeEvent;
|
|
21
|
-
//#endregion
|
|
22
20
|
export { setActiveCloudflareEnv as i, createCloudflareRuntimeEvent as n, runWithActiveCloudflareEnv as r, CloudflareWorkerExecutionContext as t };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as isRecord } from "./object-
|
|
2
|
-
import { t as workflowErrorDiagnostics } from "./error-diagnostics
|
|
1
|
+
import { t as isRecord } from "./object-CAK6UYR5.js";
|
|
2
|
+
import { t as workflowErrorDiagnostics } from "./error-diagnostics--2cV_ER1.js";
|
|
3
3
|
import { defu } from "defu";
|
|
4
4
|
/** Maps a host name or a Nitro preset name, such as `cloudflare-module` or `node-server`, to its ViteHub host. */
|
|
5
5
|
function hostFromNitroPreset(value) {
|
|
@@ -11,8 +11,7 @@ function hostFromNitroPreset(value) {
|
|
|
11
11
|
if (normalized === "node" || normalized.startsWith("node-")) return "node";
|
|
12
12
|
if (normalized.startsWith("vercel")) return "vercel";
|
|
13
13
|
}
|
|
14
|
-
|
|
15
|
-
//#region ../internal/src/hosting.ts
|
|
14
|
+
// ../internal/src/hosting.ts
|
|
16
15
|
function normalizeHosting(hosting) {
|
|
17
16
|
const normalized = hosting?.trim().toLowerCase().replaceAll("_", "-") || "";
|
|
18
17
|
if (normalized === "cloudflare") return "cloudflare-module";
|
|
@@ -23,8 +22,7 @@ function getHostingProvider(hosting) {
|
|
|
23
22
|
const host = hostFromNitroPreset(hosting);
|
|
24
23
|
if (host === "cloudflare" || host === "netlify" || host === "vercel") return host;
|
|
25
24
|
}
|
|
26
|
-
|
|
27
|
-
//#region src/config.ts
|
|
25
|
+
// src/config.ts
|
|
28
26
|
const knownDrivers = /* @__PURE__ */ new Set([
|
|
29
27
|
"cloudflare",
|
|
30
28
|
"openworkflow",
|
|
@@ -141,5 +139,4 @@ function normalizeWorkflowOptions(options, input = {}) {
|
|
|
141
139
|
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." });
|
|
142
140
|
return resolveDriver(options || {}, normalizeHosting(input.hosting), input.inline === true);
|
|
143
141
|
}
|
|
144
|
-
//#endregion
|
|
145
142
|
export { getHostingProvider as n, normalizeHosting as r, normalizeWorkflowOptions as t };
|
package/dist/definition.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { f as WorkflowDefinition } from "./types-
|
|
2
|
-
//#region src/definition.d.ts
|
|
1
|
+
import { f as WorkflowDefinition } from "./types-DvYcvbPG.js";
|
|
3
2
|
/**
|
|
4
3
|
* Defines a Workflow from one object: `defineWorkflow({ handler, ...options })`. The file path is the Workflow name.
|
|
5
4
|
* The handler receives one object, `{ payload, steps, sleep, ...context }`. Pass the payload type as the type argument.
|
|
@@ -14,5 +13,4 @@ import { f as WorkflowDefinition } from "./types-Dsmwsdlv.js";
|
|
|
14
13
|
* })
|
|
15
14
|
* ```
|
|
16
15
|
*/
|
|
17
|
-
export declare function defineWorkflow<TPayload = undefined, TResult = unknown>(definition: WorkflowDefinition<TPayload, TResult>, ...removed: unknown[]): WorkflowDefinition<TPayload, TResult>;
|
|
18
|
-
//#endregion
|
|
16
|
+
export declare function defineWorkflow<TPayload = undefined, TResult = unknown>(definition: WorkflowDefinition<TPayload, TResult>, ...removed: unknown[]): WorkflowDefinition<TPayload, TResult>;
|
package/dist/definition.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as isRecord } from "./object-
|
|
2
|
-
import { t as workflowErrorDiagnostics } from "./error-diagnostics
|
|
3
|
-
|
|
1
|
+
import { t as isRecord } from "./object-CAK6UYR5.js";
|
|
2
|
+
import { t as workflowErrorDiagnostics } from "./error-diagnostics--2cV_ER1.js";
|
|
3
|
+
// src/definition.ts
|
|
4
4
|
const workflowDefinitionKeys = /* @__PURE__ */ new Set([
|
|
5
5
|
"handler",
|
|
6
6
|
"native",
|
|
@@ -29,5 +29,4 @@ function defineWorkflow(definition, ...removed) {
|
|
|
29
29
|
if (definition.native !== void 0 && typeof definition.native !== "function") throw workflowErrorDiagnostics.WORKFLOW_C0016({ message: "`defineWorkflow()` native entry must be a workflow handler." });
|
|
30
30
|
return definition;
|
|
31
31
|
}
|
|
32
|
-
//#endregion
|
|
33
32
|
export { defineWorkflow };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { t as workflowErrorDiagnostics } from "./error-diagnostics
|
|
1
|
+
import { t as workflowErrorDiagnostics } from "./error-diagnostics--2cV_ER1.js";
|
|
2
2
|
import { parseDuration } from "@vite-hub/runtime";
|
|
3
|
-
|
|
4
|
-
/** The largest time that a JavaScript Date can hold. */
|
|
3
|
+
// src/runtime/delay.ts
|
|
5
4
|
const maximumTime = 864e13;
|
|
6
5
|
function isDate(value) {
|
|
7
6
|
return Object.prototype.toString.call(value) === "[object Date]";
|
|
@@ -42,5 +41,4 @@ function fromCloudflareStartParams(params) {
|
|
|
42
41
|
startAt
|
|
43
42
|
};
|
|
44
43
|
}
|
|
45
|
-
//#endregion
|
|
46
44
|
export { workflowStartAtKey as a, toCloudflareStartParams as i, generatedNativeEntryKey as n, resolveWorkflowStartAt as r, fromCloudflareStartParams as t };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/runtime/dev-recorder.ts
|
|
2
2
|
let recorder;
|
|
3
3
|
function setWorkflowDevRecorder(value) {
|
|
4
4
|
recorder = value;
|
|
@@ -6,5 +6,4 @@ function setWorkflowDevRecorder(value) {
|
|
|
6
6
|
function getWorkflowDevRecorder() {
|
|
7
7
|
return recorder;
|
|
8
8
|
}
|
|
9
|
-
//#endregion
|
|
10
9
|
export { setWorkflowDevRecorder as n, getWorkflowDevRecorder as t };
|
package/dist/durability.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { P as WorkflowRuntimeConfigValue } from "./types-
|
|
1
|
+
import { P as WorkflowRuntimeConfigValue } from "./types-DvYcvbPG.js";
|
|
2
2
|
import { Durability, DurabilityContext } from "@vite-hub/runtime/durability";
|
|
3
|
-
//#region src/durability.d.ts
|
|
4
3
|
/** What the build passes to `workflowDurability()`. The storage values may name runtime environment variables. */
|
|
5
4
|
export interface WorkflowDurabilityInput {
|
|
6
5
|
/** OpenWorkflow uses the Postgres Default Database after the explicit storage and its environment variables. */
|
|
@@ -19,5 +18,4 @@ export declare function workflowDurability(input: WorkflowDurabilityInput, conte
|
|
|
19
18
|
* A Postgres URL for the durability input, which the build writes into the server. The reporter only needs to know
|
|
20
19
|
* that it is set: environment variable names stay, and a literal URL or default becomes `set`.
|
|
21
20
|
*/
|
|
22
|
-
export declare function workflowDurabilityUrl(value: WorkflowRuntimeConfigValue): WorkflowRuntimeConfigValue;
|
|
23
|
-
//#endregion
|
|
21
|
+
export declare function workflowDurabilityUrl(value: WorkflowRuntimeConfigValue): WorkflowRuntimeConfigValue;
|