-
Notifications
You must be signed in to change notification settings - Fork 164
feat: add sveltekit support #131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
75 commits
Select commit
Hold shift + click to select a range
39c6294
add workbench sveltekit
adriandlam 8955e2b
add sveltekit package
adriandlam 4b6a19a
fix: use js for generated server routes in svelte
adriandlam dfa6f6e
add test routes for sveltekit workbench
adriandlam 2ae3503
updates from debugging
ijjk 252339f
feat: add sveltekit build target
adriandlam 09e49db
update user sign up workflow workbench sveltekit
adriandlam 91fb404
fix: base builder missing GET route handler for sveltekit
adriandlam 9502bf5
feat: add vercel builder and check for vercel env
adriandlam a52d521
refactor: workflowPlugin for sveltekit
adriandlam 38d5410
ci: add tests to workbench sveltekit
adriandlam 004e042
fix: no start command and vercel builder outputs
adriandlam f7b9115
fix: base builder conditions
adriandlam 7b0268b
.
adriandlam f62bbdb
add auto adapter sveltekit
adriandlam 86e59fc
fix: disable checking origin for cross site ci stuff
adriandlam eff0730
allow all trusted origins in svelte config
adriandlam e500bfb
fix: add catch for error thrown when waiting for ops
adriandlam 84d4f70
fix: sveltekit workbench adapter
adriandlam 450a2f1
test
adriandlam 91db702
test
adriandlam 2a29c72
refactor: move vercel builder on config resolved
adriandlam 881d0d6
update package json
adriandlam 2693d7b
add demo workflow trigger
adriandlam 9a920d0
test letting sveltekit handle route generation
adriandlam b91f8ed
fix: exclude git ignore for local builder outputs
adriandlam 5a9417e
update config
ijjk 90acfdd
add debug logs
ijjk c109c21
update debug
ijjk 5eddb04
update turbo.json
ijjk 23ef645
fix env check
ijjk 203e03a
another output
ijjk 518712e
use top-level await
ijjk 971ac50
ensure vercel functions are patched
ijjk c2b8192
change hook
ijjk bac5a5e
update
ijjk 8e63f00
fix spread
ijjk da1e842
debug
ijjk 870cdb6
update
ijjk 4b8297d
chore: remove vercel builder
adriandlam 6577c06
chore: update comments in sveltekit workflow package
adriandlam 52d60e3
chore: remove console comment
adriandlam f80dab1
refactor: workflow svelte plugin
adriandlam c10d87b
refactor: simplify local builder config
adriandlam 5852ffb
chore: remove unused deps
adriandlam 4e2749f
chore: add comment for workbench svelte app
adriandlam f754595
chore: add sveltekit export to workflow
adriandlam 9b4a561
export sveltekit from workflow
adriandlam 91597e1
lockfile
adriandlam 741093a
chore: remove unused deps svelte workbench
adriandlam 4751a2a
update styling
adriandlam fc84338
add sveltekit getting started docs
adriandlam 50704e9
update sveltekit docs getting started
adriandlam 724e095
changeset
adriandlam f005eba
Apply suggestion from @vercel[bot]
adriandlam cd73314
use proper env var
adriandlam 9b838e6
Update packages/sveltekit/src/index.ts
adriandlam 45b5cc6
Update docs/content/docs/getting-started/sveltekit.mdx
adriandlam 3ea99d1
Document CSRF protection bypass in SvelteKit workbench config (#157)
Copilot 1dc1439
refactor: deduplicate SvelteKit request conversion logic (#156)
Copilot dba3fb7
docs: fix getting staretd sveltekit missing folder
adriandlam 96f21ef
chore: cleanup sveltekit builder after rebase
adriandlam c1cd6a5
lockfile
adriandlam e0a4e0d
fix: sveltekit building logic in base builder
adriandlam b91e97f
refactor: move sveltekit builder logic to its own package
adriandlam a9f08ae
fix: console log base builder
adriandlam a3aaf42
changeset
adriandlam 1581bac
test
adriandlam 74d367b
feat: create hmr plugin
adriandlam b81f1a0
fix: add initial build on load
adriandlam 831f648
fix: check all files for workflows and steps
adriandlam d9523c6
add comments for plugin todo
adriandlam 2105c0c
remove catching error
adriandlam 79712e4
fix: missing context for nodejs envs causing waitUntil to fail
adriandlam 3ca91e3
fix: setting global request conext in vercel environments
adriandlam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| --- | ||
| "@workflow/world-local": patch | ||
| "@workflow/sveltekit": patch | ||
| "@workflow/builders": patch | ||
| "workflow": patch | ||
| "@workflow/core": patch | ||
| "@workflow/cli": patch | ||
| --- | ||
|
|
||
| Add sveltekit workflow integration |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,7 +34,7 @@ function Card({ title, href, className, children, disabled }: CardProps) { | |
| <a | ||
| href={href} | ||
| className={cn( | ||
| 'block rounded-lg border border-border p-6 transition hover:border-primary/25 hover:bg-accent no-underline duration-200', | ||
| 'block rounded-lg border border-border p-6 transition hover:border-primary/25 hover:bg-accent no-underline duration-150 ease-out', | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👨🍳 |
||
| className | ||
| )} | ||
| > | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,10 +25,9 @@ Start by choosing your framework. Each guide will walk you through the steps to | |
| <Nitro className="size-16" /> | ||
| <span className="font-medium">Nitro</span> | ||
| </Card> | ||
| <Card href="/docs/getting-started/sveltekit" disabled className="flex flex-col items-center justify-center text-center gap-2"> | ||
| <Card href="/docs/getting-started/sveltekit" className="flex flex-col items-center justify-center text-center gap-2"> | ||
| <SvelteKit className="size-16" /> | ||
| <span className="font-medium">SvelteKit</span> | ||
| <Badge variant="secondary">Coming soon</Badge> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚀 |
||
| </Card> | ||
| <Card href="/docs/getting-started/nuxt" disabled className="flex flex-col items-center justify-center text-center gap-2"> | ||
| <Nuxt className="size-16" /> | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,258 @@ | ||
| --- | ||
| title: SvelteKit | ||
| --- | ||
|
|
||
| # SvelteKit | ||
|
|
||
| This guide will walk through setting up your first workflow in a SvelteKit app. Along the way, you'll learn more about the concepts that are fundamental to using the development kit in your own projects. | ||
|
|
||
| --- | ||
|
|
||
| <Steps> | ||
|
|
||
| <Step> | ||
| ## Create Your SvelteKit Project | ||
|
|
||
| Start by creating a new SvelteKit project. This command will create a new directory named `my-workflow-app` with a minimal setup and setup a SvelteKit project inside it. | ||
|
|
||
| ```bash | ||
| npx sv create my-workflow-app --template=minimal --types=ts --no-add-ons | ||
| ``` | ||
|
|
||
| Enter the newly made directory: | ||
|
|
||
| ```bash | ||
| cd my-workflow-app | ||
| ``` | ||
|
|
||
| ### Install `workflow` | ||
|
|
||
| <Tabs items={['npm', 'pnpm', 'yarn']}> | ||
| <Tab value="npm"> | ||
| <CodeBlock> | ||
| npm i workflow | ||
| </CodeBlock> | ||
| </Tab> | ||
| <Tab value="pnpm"> | ||
| <CodeBlock> | ||
| pnpm i workflow | ||
| </CodeBlock> | ||
| </Tab> | ||
| <Tab value="yarn"> | ||
| <CodeBlock> | ||
| yarn add workflow | ||
| </CodeBlock> | ||
| </Tab> | ||
| </Tabs> | ||
|
|
||
| ### Configure Vite | ||
|
|
||
| Add `workflowPlugin()` to your Vite config. This enables usage of the `"use workflow"` and `"use step"` directives. | ||
|
|
||
| ```typescript title="vite.config.ts" lineNumbers | ||
| import { sveltekit } from "@sveltejs/kit/vite"; | ||
| import { defineConfig } from "vite"; | ||
| import { workflowPlugin } from "workflow/sveltekit"; // [!code highlight] | ||
|
|
||
| export default defineConfig({ | ||
| plugins: [sveltekit(), workflowPlugin()], // [!code highlight] | ||
| }); | ||
| ``` | ||
|
|
||
| ### Update `package.json` | ||
|
|
||
| Update your `package.json` to include port `3000` for the development server: | ||
|
|
||
| ```json title="package.json" lineNumbers | ||
| { | ||
| // ... | ||
| "scripts": { | ||
| "dev": "vite dev --port 3000" | ||
| // ... | ||
| }, | ||
| } | ||
| ``` | ||
|
|
||
| <Accordion type="single" collapsible> | ||
| <AccordionItem value="typescript-intellisense" className="[&_h3]:my-0"> | ||
| <AccordionTrigger className="text-sm"> | ||
| ### Setup IntelliSense for TypeScript (Optional) | ||
| </AccordionTrigger> | ||
| <AccordionContent className="[&_p]:my-2"> | ||
|
|
||
| To enable helpful hints in your IDE, setup the workflow plugin in `tsconfig.json`: | ||
|
|
||
| ```json title="tsconfig.json" lineNumbers | ||
| { | ||
| "compilerOptions": { | ||
| // ... rest of your TypeScript config | ||
| "plugins": [ | ||
| { | ||
| "name": "workflow" // [!code highlight] | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| </AccordionContent> | ||
| </AccordionItem> | ||
| </Accordion> | ||
|
|
||
| </Step> | ||
|
|
||
| <Step> | ||
|
|
||
| ## Create Your First Workflow | ||
|
|
||
| Create a new file for our first workflow: | ||
|
|
||
| ```typescript title="workflows/user-signup.ts" lineNumbers | ||
| import { sleep } from "workflow"; | ||
|
|
||
| export async function handleUserSignup(email: string) { | ||
| "use workflow"; // [!code highlight] | ||
|
|
||
| const user = await createUser(email); | ||
| await sendWelcomeEmail(user); | ||
|
|
||
| await sleep("5s"); // Pause for 5s - doesn't consume any resources | ||
| await sendOnboardingEmail(user); | ||
|
|
||
| return { userId: user.id, status: "onboarded" }; | ||
| } | ||
|
|
||
| ``` | ||
|
|
||
| We'll fill in those functions next, but let's take a look at this code: | ||
|
|
||
| * We define a **workflow** function with the directive `"use workflow"`. Think of the workflow function as the _orchestrator_ of individual **steps**. | ||
| * The Workflow DevKit's `sleep` function allows us to suspend execution of the workflow without using up any resources. A sleep can be a few seconds, hours, days, or even months long. | ||
|
|
||
| ## Create Your Workflow Steps | ||
|
|
||
| Let's now define those missing functions. | ||
|
|
||
| ```typescript title="workflows/user-signup.ts" lineNumbers | ||
| import { FatalError } from "workflow" | ||
|
|
||
| // Our workflow function defined earlier | ||
|
|
||
| async function createUser(email: string) { | ||
| "use step"; // [!code highlight] | ||
|
|
||
| console.log(`Creating user with email: ${email}`); | ||
|
|
||
| // Full Node.js access - database calls, APIs, etc. | ||
| return { id: crypto.randomUUID(), email }; | ||
| } | ||
|
|
||
| async function sendWelcomeEmail(user: { id: string; email: string; }) { | ||
| "use step"; // [!code highlight] | ||
|
|
||
| console.log(`Sending welcome email to user: ${user.id}`); | ||
|
|
||
| if (Math.random() < 0.3) { | ||
| // By default, steps will be retried for unhandled errors | ||
| throw new Error("Retryable!"); | ||
| } | ||
| } | ||
|
|
||
| async function sendOnboardingEmail(user: { id: string; email: string}) { | ||
| "use step"; // [!code highlight] | ||
|
|
||
| if (!user.email.includes("@")) { | ||
| // To skip retrying, throw a FatalError instead | ||
| throw new FatalError("Invalid Email"); | ||
| } | ||
|
|
||
| console.log(`Sending onboarding email to user: ${user.id}`); | ||
| } | ||
| ``` | ||
|
|
||
| Taking a look at this code: | ||
|
|
||
| * Business logic lives inside **steps**. When a step is invoked inside a **workflow**, it gets enqueued to run on a separate request while the workflow is suspended, just like `sleep`. | ||
| * If a step throws an error, like in `sendWelcomeEmail`, the step will automatically be retried until it succeeds (or hits the step's max retry count). | ||
| * Steps can throw a `FatalError` if an error is intentional and should not be retried. | ||
|
|
||
| <Callout> | ||
| We'll dive deeper into workflows, steps, and other ways to suspend or handle events in [Foundations](/docs/foundations). | ||
| </Callout> | ||
|
|
||
| </Step> | ||
|
|
||
| <Step> | ||
|
|
||
| ## Create Your Route Handler | ||
|
|
||
| To invoke your new workflow, we'll have to add your workflow to a `POST` API route handler, `src/routes/api/signup/+server.ts` with the following code: | ||
|
|
||
| ```typescript title="src/routes/api/signup/+server.ts" | ||
| import { start } from "workflow/api"; | ||
| import { handleUserSignup } from "../../../../workflows/user-signup"; | ||
| import { json, type RequestHandler } from "@sveltejs/kit"; | ||
|
|
||
| export const POST: RequestHandler = async ({ | ||
| request, | ||
| }: { | ||
| request: Request; | ||
| }) => { | ||
| const { email } = await request.json(); | ||
|
|
||
| // Executes asynchronously and doesn't block your app | ||
| await start(handleUserSignup, [email]); | ||
|
|
||
| return json({ message: "User signup workflow started" }); | ||
| }; | ||
|
|
||
| ``` | ||
|
|
||
| This route handler creates a `POST` request endpoint at `/api/signup` that will trigger your workflow. | ||
|
|
||
| <Callout> | ||
| Workflows can be triggered from API routes or any server-side code. | ||
| </Callout> | ||
|
|
||
| </Step> | ||
|
|
||
| </Steps> | ||
|
|
||
| ## Run in development | ||
|
|
||
| To start your development server, run the following command in your terminal in the SvelteKit root directory: | ||
|
|
||
| ```bash | ||
| npm run dev | ||
| ``` | ||
|
|
||
| Once your development server is running, you can trigger your workflow by running this command in the terminal: | ||
|
|
||
| ```bash | ||
| curl -X POST --json '{"email":"[email protected]"}' http://localhost:3000/api/signup | ||
| ``` | ||
|
|
||
| Check the SvelteKit development server logs to see your workflow execute as well as the steps that are being processed. | ||
|
|
||
| Additionally, you can use the [Workflow DevKit CLI or Web UI](/docs/observability) to inspect your workflow runs and steps in detail. | ||
|
|
||
| ```bash | ||
| npx workflow inspect runs | ||
| # or add '--web' for an interactive Web based UI | ||
| ``` | ||
|
|
||
| <img src="/o11y-ui.png" alt="Workflow DevKit Web UI" /> | ||
|
|
||
| --- | ||
|
|
||
| ## Deploying to production | ||
|
|
||
| Workflow DevKit apps currently work best when deployed to [Vercel](https://vercel.com/home) and needs no special configuration. | ||
|
|
||
| Check the [Deploying](/docs/deploying) section to learn how your workflows can be deployed elsewhere. | ||
|
|
||
| ## Next Steps | ||
|
|
||
| * Learn more about the [Foundations](/docs/foundations). | ||
| * Check [Errors](/docs/errors) if you encounter issues. | ||
| * Explore the [API Reference](/docs/api-reference). |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.