chore(refs): sync Effect and Alchemy references to 4.0.1 and beta.80 (#16170)
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
1 parent
b12b3f706d
commit
6f9cea00ae
11290 files changed
+1139551
-216324
No files matched your search
@@ -90,6 +90,14 @@ jobs:
|
||||
- name: Run Typecheck
|
||||
run: pnpm tsc -b
|
||||
|
||||
# Must run after `tsc -b`: it reads distilled's emitted `lib/*.d.ts`,
|
||||
# and stale/missing declarations resolve to `any`.
|
||||
- name: Lint providers
|
||||
run: pnpm lint:providers
|
||||
|
||||
- name: Test CLI launcher
|
||||
run: timeout 240 pnpm test test/Cli/launcher.test.ts test/Cli/exitCodes.test.ts --retry 0 --concurrency 1
|
||||
|
||||
- name: Check API JSDocs
|
||||
run: pnpm docs:check-jsdoc
|
||||
|
||||
|
||||
+15
-2
@@ -22,6 +22,7 @@ on:
|
||||
- "tsconfig.json"
|
||||
- ".github/workflows/pkg.yml"
|
||||
pull_request:
|
||||
types: [opened, synchronize, reopened, labeled]
|
||||
paths:
|
||||
- "submodules/distilled"
|
||||
- "packages/**"
|
||||
@@ -54,6 +55,7 @@ jobs:
|
||||
# Pack the pull request head rather than the synthetic merge commit,
|
||||
# so every tarball is addressed by a commit that exists on the PR.
|
||||
ref: ${{ github.event.pull_request.head.sha || github.sha }}
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Checkout distilled
|
||||
run: git submodule update --init --depth=1 --checkout -- submodules/distilled
|
||||
@@ -69,19 +71,29 @@ jobs:
|
||||
install: true
|
||||
require-lockfile: true
|
||||
|
||||
# Cold-building the alchemy package peaks near 17 GB of heap, which
|
||||
# starves the runner agent on a 32 GB machine and drops the job. A soft
|
||||
# limit holds the peak near 11 GB for roughly twice the compile time.
|
||||
- name: Build packages
|
||||
env:
|
||||
GOMEMLIMIT: 6GiB
|
||||
GOGC: "40"
|
||||
run: pnpm build:pkg
|
||||
|
||||
# Keep the directory lists in sync with the `build:pkg` script.
|
||||
# The @distilled.cloud list is alchemy's dependency set, which `build:pkg`
|
||||
# derives with `--filter=alchemy...`; keep the @alchemy.run list in sync.
|
||||
- name: Pack packages
|
||||
id: pack
|
||||
run: >-
|
||||
pnpm exec pkg pack
|
||||
${{ contains(github.event.pull_request.labels.*.name, 'force-ci') && '--all' || '' }}
|
||||
--rebuild-all-path 'scripts/copy-package-files.ts'
|
||||
--group 'alchemy=./packages/alchemy'
|
||||
--group '@alchemy.run[Collapsed]=./packages/{better-auth,cloudflare-runtime,frontend-frameworks,node-utils,floci,pkg}'
|
||||
--group '@distilled.cloud[Collapsed]=./submodules/distilled/packages/{core,aws,axiom,cloudflare,fly-io,github,hetzner,neon,planetscale,railway,stripe}'
|
||||
--group '@distilled.cloud[Collapsed]=./submodules/distilled/packages/{core,acme,aws,axiom,cloudflare,doppler,fly-io,github,hetzner,infisical,neon,prisma,planetscale,railway,stripe,zerossl}'
|
||||
|
||||
- name: Vouch for the manifest
|
||||
if: steps.pack.outputs.package-count != '0'
|
||||
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||
with:
|
||||
name: ${{ steps.pack.outputs.artifact-name }}
|
||||
@@ -91,4 +103,5 @@ jobs:
|
||||
retention-days: 1
|
||||
|
||||
- name: Publish packages
|
||||
if: steps.pack.outputs.package-count != '0'
|
||||
run: pnpm exec pkg publish
|
||||
@@ -81,6 +81,11 @@ jobs:
|
||||
bun scripts/release/prepare.ts '${{ inputs.version }}' | tee -a "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Build release packages
|
||||
# Match preview CI: the cold tsgo build can starve the runner
|
||||
# without Go heap limits on this 32 GB machine.
|
||||
env:
|
||||
GOMEMLIMIT: 6GiB
|
||||
GOGC: "40"
|
||||
run: >-
|
||||
pnpm turbo run build
|
||||
$(jq -r '.[] | "--filter=\(.name)"' release-packages.json)
|
||||
|
||||
@@ -32,6 +32,11 @@ smoke
|
||||
*.d.ts
|
||||
!examples/prisma-tanstack-start/migrations/**/start-contract.d.ts
|
||||
!examples/prisma-tanstack-start/migrations/**/end-contract.d.ts
|
||||
# Emitted Prisma ORM v8 contract types: imported by the fixtures/example that
|
||||
# consume them, so a clean checkout must typecheck without running a deploy.
|
||||
!examples/cloudflare-neon-prisma/src/prisma/generated/contract.d.ts
|
||||
!packages/alchemy/test/Cloudflare/Workers/fixtures/prisma-orm/generated/contract.d.ts
|
||||
!packages/alchemy/test/Prisma/ORM/fixtures/client/generated/contract.d.ts
|
||||
# drizzle-kit's generated durable-sqlite migrations bundle (checked-in test fixture)
|
||||
!packages/alchemy/test/Cloudflare/Workers/fixtures/drizzle-do/drizzle/migrations.js
|
||||
# Container image contexts COPY these into the image; without the negation
|
||||
@@ -67,6 +72,8 @@ examples/cloudflare-worker/src/scratch.ts
|
||||
/packages/alchemy/README.md
|
||||
|
||||
!/packages/alchemy/bin/cli.js
|
||||
!/packages/alchemy/bin/alchemy.js
|
||||
!/packages/alchemy/bin/exec.js
|
||||
!/packages/alchemy/bin/register-dev-mode.js
|
||||
!/packages/alchemy/bin/register-oxc.js
|
||||
.tmp
|
||||
|
||||
@@ -857,8 +857,8 @@ Resolve the bindings, expose one route per behavior, default-export the class so
|
||||
// fixtures/worker.ts
|
||||
import * as Cloudflare from "@/Cloudflare/index.ts";
|
||||
import * as Effect from "effect/Effect";
|
||||
import { HttpServerRequest } from "effect/unstable/http/HttpServerRequest";
|
||||
import * as HttpServerResponse from "effect/unstable/http/HttpServerResponse";
|
||||
import { HttpServerRequest } from "effect/http/HttpServerRequest";
|
||||
import * as HttpServerResponse from "effect/http/HttpServerResponse";
|
||||
import { Gateway } from "./gateway.ts";
|
||||
|
||||
export default class TestWorker extends Cloudflare.Worker<TestWorker>()(
|
||||
@@ -895,7 +895,7 @@ import * as Test from "@/Test/Alchemy";
|
||||
import { expect } from "alchemy-test";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Schedule from "effect/Schedule";
|
||||
import * as HttpClient from "effect/unstable/http/HttpClient";
|
||||
import * as HttpClient from "effect/http/HttpClient";
|
||||
import TestWorker from "./fixtures/worker.ts";
|
||||
|
||||
const { test, beforeAll, afterAll, deploy, destroy } = Test.make({
|
||||
|
||||
@@ -1,3 +1,160 @@
|
||||
## v2.0.0-beta.80
|
||||
|
||||
### 🚨 Breaking Changes
|
||||
|
||||
- **better-auth**:
|
||||
- Support direct upgrades to 1.7.5 - by **sam** in https://github.com/alchemy-run/alchemy/issues/1732 [<samp>(c9400)</samp>](https://github.com/alchemy-run/alchemy/commit/c9400e4d4)
|
||||
- **cloudflare**:
|
||||
- Add durable callbacks with transactional alarms - by **sam** in https://github.com/alchemy-run/alchemy/issues/1668 [<samp>(258f6)</samp>](https://github.com/alchemy-run/alchemy/commit/258f63b13)
|
||||
- Support resource references in queue subscriptions - by **sam** in https://github.com/alchemy-run/alchemy/issues/1722 [<samp>(85955)</samp>](https://github.com/alchemy-run/alchemy/commit/85955dbf3)
|
||||
|
||||
### 🚀 Features
|
||||
|
||||
- **acme**:
|
||||
- Add independent certificates and Fly runtime management - by **sam** in https://github.com/alchemy-run/alchemy/issues/1702 [<samp>(a1a58)</samp>](https://github.com/alchemy-run/alchemy/commit/a1a58ac19)
|
||||
- **aws**:
|
||||
- Manage VPC default security group rules - by **Henning Pokriefke** and **sam** in https://github.com/alchemy-run/alchemy/issues/1630 [<samp>(8efa5)</samp>](https://github.com/alchemy-run/alchemy/commit/8efa50a45)
|
||||
- **ec2**: Add Client VPN resources - by **sam** in https://github.com/alchemy-run/alchemy/issues/1714 [<samp>(fdec4)</samp>](https://github.com/alchemy-run/alchemy/commit/fdec4ccf8)
|
||||
- **rds**: Manage the RDS master secret resource policy - by **Bjorn Pagen** and **sam** in https://github.com/alchemy-run/alchemy/issues/1598 [<samp>(95711)</samp>](https://github.com/alchemy-run/alchemy/commit/9571121c4)
|
||||
- **cloudflare**:
|
||||
- Reuse shared container images across deployments - by **Dan van der Merwe** and **sam** in https://github.com/alchemy-run/alchemy/issues/1692 [<samp>(20790)</samp>](https://github.com/alchemy-run/alchemy/commit/20790b3b0)
|
||||
- Default to new module registry and sync upstream runtime - by **BlankParticle** in https://github.com/alchemy-run/alchemy/issues/1663 [<samp>(631ca)</samp>](https://github.com/alchemy-run/alchemy/commit/631ca932c)
|
||||
- Support hibernating WebSocket Effect RPC - by **sam** in https://github.com/alchemy-run/alchemy/issues/1705 [<samp>(da5df)</samp>](https://github.com/alchemy-run/alchemy/commit/da5df5c79)
|
||||
- Preserve workflow errors and validate socket attachments - by **sam** in https://github.com/alchemy-run/alchemy/issues/1723 [<samp>(e24fd)</samp>](https://github.com/alchemy-run/alchemy/commit/e24fd61e9)
|
||||
- Load Durable Object SQL migrations at construction - by **sam** in https://github.com/alchemy-run/alchemy/issues/1736 [<samp>(34637)</samp>](https://github.com/alchemy-run/alchemy/commit/3463790dd)
|
||||
- Support credential-less local development - by **Rahul Mishra** in https://github.com/alchemy-run/alchemy/issues/1801 [<samp>(98022)</samp>](https://github.com/alchemy-run/alchemy/commit/9802260db)
|
||||
- **access**:
|
||||
- Add McpServer resource - by **Dillion Verma** and **BlankParticle** in https://github.com/alchemy-run/alchemy/issues/1658 [<samp>(1ad29)</samp>](https://github.com/alchemy-run/alchemy/commit/1ad293d85)
|
||||
- **r2**:
|
||||
- Presigned URLs with a local S3 endpoint in dev - by **sam** in https://github.com/alchemy-run/alchemy/issues/1793 [<samp>(0a3a4)</samp>](https://github.com/alchemy-run/alchemy/commit/0a3a41974)
|
||||
- **workflows**:
|
||||
- Support explicit physical names - by **Odysseas Papadimas** and **sam** in https://github.com/alchemy-run/alchemy/issues/1460 [<samp>(341e6)</samp>](https://github.com/alchemy-run/alchemy/commit/341e6a7fc)
|
||||
- Expose the Workflow's physical name on the binding output - by **Alex** and **sam** in https://github.com/alchemy-run/alchemy/issues/1505 [<samp>(1fd93)</samp>](https://github.com/alchemy-run/alchemy/commit/1fd93e143)
|
||||
- **cloudflare-runtime**:
|
||||
- Pass V8 flags to workerd - by **Alex** and **BlankParticle** in https://github.com/alchemy-run/alchemy/issues/1771 [<samp>(4264a)</samp>](https://github.com/alchemy-run/alchemy/commit/4264a1b73)
|
||||
- Restart workerd when it crashes after startup - by **Alex** and **BlankParticle** in https://github.com/alchemy-run/alchemy/issues/1772 [<samp>(de830)</samp>](https://github.com/alchemy-run/alchemy/commit/de83011fa)
|
||||
- **core**:
|
||||
- Filter stack reconciliation with include/exclude - by **sam** in https://github.com/alchemy-run/alchemy/issues/1757 [<samp>(45c9b)</samp>](https://github.com/alchemy-run/alchemy/commit/45c9bb945)
|
||||
- **fly**:
|
||||
- Wait for service checks before the next replica - by **Florian Bienefelt** and **sam** in https://github.com/alchemy-run/alchemy/issues/1670 [<samp>(023f9)</samp>](https://github.com/alchemy-run/alchemy/commit/023f96531)
|
||||
- Add blue/green deployments and graceful shutdown - by **sam** in https://github.com/alchemy-run/alchemy/issues/1706 [<samp>(3b5c9)</samp>](https://github.com/alchemy-run/alchemy/commit/3b5c9e24c)
|
||||
- Support native multi-container Machines - by **Florian Bienefelt** and **sam** in https://github.com/alchemy-run/alchemy/issues/1768 [<samp>(4eae8)</samp>](https://github.com/alchemy-run/alchemy/commit/4eae83e93)
|
||||
- Support blue/green multi-container Machines - by **Florian Bienefelt** and **sam** in https://github.com/alchemy-run/alchemy/issues/1769 [<samp>(1c369)</samp>](https://github.com/alchemy-run/alchemy/commit/1c369afba)
|
||||
- Allocate Flycast private addresses - by **Florian Bienefelt** and **sam** in https://github.com/alchemy-run/alchemy/issues/1749 [<samp>(7214e)</samp>](https://github.com/alchemy-run/alchemy/commit/7214e7b10)
|
||||
- A Service owns its App - by **sam** in https://github.com/alchemy-run/alchemy/issues/1794 [<samp>(76cde)</samp>](https://github.com/alchemy-run/alchemy/commit/76cde9ad8)
|
||||
- **frontend-frameworks**:
|
||||
- Build Cloudflare Octane without an adapter - by **sam** in https://github.com/alchemy-run/alchemy/issues/1755 [<samp>(1dc1d)</samp>](https://github.com/alchemy-run/alchemy/commit/1dc1d75a0)
|
||||
- **gcp**:
|
||||
- Add GCP resource providers, HTTP bindings, and nuke - by **Michael K** in https://github.com/alchemy-run/alchemy/issues/1336 [<samp>(e32ba)</samp>](https://github.com/alchemy-run/alchemy/commit/e32ba7fba)
|
||||
- **kubernetes**:
|
||||
- LocalCluster, connection registries, and a docs hub - by **sam** in https://github.com/alchemy-run/alchemy/issues/1779 [<samp>(a1ef6)</samp>](https://github.com/alchemy-run/alchemy/commit/a1ef6ba2f)
|
||||
- **neon**:
|
||||
- Add backend resources, Effect runtimes and websites - by **sam** in https://github.com/alchemy-run/alchemy/issues/1695 [<samp>(bcd41)</samp>](https://github.com/alchemy-run/alchemy/commit/bcd410418)
|
||||
- **pkg**:
|
||||
- Publish affected packages and their dependencies - by **BlankParticle** in https://github.com/alchemy-run/alchemy/issues/1727 [<samp>(16a0a)</samp>](https://github.com/alchemy-run/alchemy/commit/16a0a829b)
|
||||
- **planetscale**:
|
||||
- Add `withReplication` on PostgresRole - by **Makisuo** in https://github.com/alchemy-run/alchemy/issues/1777 [<samp>(8a284)</samp>](https://github.com/alchemy-run/alchemy/commit/8a284d039)
|
||||
- **prisma**:
|
||||
- Add Effect-native Prisma ORM v8 support - by **sam** in https://github.com/alchemy-run/alchemy/issues/1198 [<samp>(3b82f)</samp>](https://github.com/alchemy-run/alchemy/commit/3b82f222d)
|
||||
- **secrets**:
|
||||
- Stack secret providers with dotenv, Doppler, and Infisical - by **BlankParticle** in https://github.com/alchemy-run/alchemy/issues/1728 [<samp>(0f712)</samp>](https://github.com/alchemy-run/alchemy/commit/0f712f844)
|
||||
- **website**:
|
||||
- Add standardized vinext support across providers - by **Ray** and **sam** in https://github.com/alchemy-run/alchemy/issues/1515 [<samp>(c6779)</samp>](https://github.com/alchemy-run/alchemy/commit/c6779e86e)
|
||||
- Landing refresh, PR lifecycle benchmark, in-browser copy editing - by **Michael K** in https://github.com/alchemy-run/alchemy/issues/1797 [<samp>(9fbd6)</samp>](https://github.com/alchemy-run/alchemy/commit/9fbd6a2ba)
|
||||
|
||||
### 🐞 Bug Fixes
|
||||
|
||||
- Honor configured Alchemy runtime directories - by **BlankParticle** in https://github.com/alchemy-run/alchemy/issues/1726 [<samp>(4453c)</samp>](https://github.com/alchemy-run/alchemy/commit/4453c9b50)
|
||||
- Expose Stack and Worker declaration metadata - by **sam** in https://github.com/alchemy-run/alchemy/issues/1490 [<samp>(a42c2)</samp>](https://github.com/alchemy-run/alchemy/commit/a42c2e55a)
|
||||
- Upgrade Effect to 2.0.0-rc.117 and type constructors - by **BlankParticle** in https://github.com/alchemy-run/alchemy/issues/1758 [<samp>(1f251)</samp>](https://github.com/alchemy-run/alchemy/commit/1f251fa6a)
|
||||
- Catch and remove any/unknown leaks in providers() requirements - by **sam** in https://github.com/alchemy-run/alchemy/issues/1895 [<samp>(5bd17)</samp>](https://github.com/alchemy-run/alchemy/commit/5bd1711b4)
|
||||
- Provider test failures and Effect 4 stable compatibility - by **Rahul Mishra** in https://github.com/alchemy-run/alchemy/issues/1899 [<samp>(8cbd3)</samp>](https://github.com/alchemy-run/alchemy/commit/8cbd3ff4a)
|
||||
- **alchemy**:
|
||||
- Make @effect/vitest an optional peer again - by **Aman Varshney** in https://github.com/alchemy-run/alchemy/issues/1816 [<samp>(e2906)</samp>](https://github.com/alchemy-run/alchemy/commit/e2906a727)
|
||||
- **apply**:
|
||||
- Wait for cyclic upstream reconciliation outside cycles - by **Rahul Mishra** in https://github.com/alchemy-run/alchemy/issues/1921 [<samp>(9eb28)</samp>](https://github.com/alchemy-run/alchemy/commit/9eb28c9ea)
|
||||
- **auth**:
|
||||
- Defer provider credentials and fail with CredentialsRequired - by **Rahul Mishra** in https://github.com/alchemy-run/alchemy/issues/1902 [<samp>(1d13b)</samp>](https://github.com/alchemy-run/alchemy/commit/1d13bddb8)
|
||||
- **aws**:
|
||||
- Deploy ECS service after a previous deployment failed - by **Henning Pokriefke** and **sam** in https://github.com/alchemy-run/alchemy/issues/1650 [<samp>(9b642)</samp>](https://github.com/alchemy-run/alchemy/commit/9b6426e93)
|
||||
- Grant exact runtime capability actions - by **Saatvik Arya** and **sam** in https://github.com/alchemy-run/alchemy/issues/1357 [<samp>(e1d26)</samp>](https://github.com/alchemy-run/alchemy/commit/e1d26f85d)
|
||||
- **rds**:
|
||||
- Distinguish pending and blocked instance readiness - by **Bjorn Pagen** and **sam** in https://github.com/alchemy-run/alchemy/issues/1597 [<samp>(6236d)</samp>](https://github.com/alchemy-run/alchemy/commit/6236d078b)
|
||||
- Observe instance security drift and application state - by **Bjorn Pagen** and **sam** in https://github.com/alchemy-run/alchemy/issues/1599 [<samp>(ea601)</samp>](https://github.com/alchemy-run/alchemy/commit/ea60154e5)
|
||||
- **aws-sqs**:
|
||||
- Reconcile adoption and queue Standrd/FIFO changes - by **Saatvik Arya** and **sam** [<samp>(1b3d6)</samp>](https://github.com/alchemy-run/alchemy/commit/1b3d60dd1)
|
||||
- **cli**:
|
||||
- Simplify entrypoints and generate publish exports - by **BlankParticle** in https://github.com/alchemy-run/alchemy/issues/1707 [<samp>(c2e3b)</samp>](https://github.com/alchemy-run/alchemy/commit/c2e3bad1f)
|
||||
- Accept --adopt on alchemy plan - by **Pedro Toledo** in https://github.com/alchemy-run/alchemy/issues/1811 [<samp>(0b576)</samp>](https://github.com/alchemy-run/alchemy/commit/0b5761721)
|
||||
- **cloudflare**:
|
||||
- Support Worker aliases through Rolldown input options - by **sam** in https://github.com/alchemy-run/alchemy/issues/1700 [<samp>(020de)</samp>](https://github.com/alchemy-run/alchemy/commit/020de393d)
|
||||
- Scope Workflow attempts and batch alarm updates - by **sam** in https://github.com/alchemy-run/alchemy/issues/1701 [<samp>(04ad9)</samp>](https://github.com/alchemy-run/alchemy/commit/04ad9facc)
|
||||
- Preserve explicit prebuilt Worker compatibility flags - by **BlankParticle** in https://github.com/alchemy-run/alchemy/issues/1725 [<samp>(3281a)</samp>](https://github.com/alchemy-run/alchemy/commit/3281a6e7c)
|
||||
- Preserve version annotations on full deployments - by **Luke O'Malley** in https://github.com/alchemy-run/alchemy/issues/1754 [<samp>(a4a75)</samp>](https://github.com/alchemy-run/alchemy/commit/a4a755878)
|
||||
- Register website dev servers for service bindings - by **Rahul Mishra** in https://github.com/alchemy-run/alchemy/issues/1798 [<samp>(b2618)</samp>](https://github.com/alchemy-run/alchemy/commit/b261867f1)
|
||||
- Bypass assets for Vite module runner initialization - by **Rahul Mishra** in https://github.com/alchemy-run/alchemy/issues/1799 [<samp>(d14b4)</samp>](https://github.com/alchemy-run/alchemy/commit/d14b4a485)
|
||||
- Only ignore missing DNS record errors - by **Rahul Mishra** in https://github.com/alchemy-run/alchemy/issues/1800 [<samp>(36a27)</samp>](https://github.com/alchemy-run/alchemy/commit/36a278d7c)
|
||||
- Preserve asset rules in Workers-for-Platforms uploads - by **Rahul Mishra** in https://github.com/alchemy-run/alchemy/issues/1802 [<samp>(dc22a)</samp>](https://github.com/alchemy-run/alchemy/commit/dc22aa240)
|
||||
- Expose ref on Container so another stack can reference it - by **Cyberistic** and **sam** in https://github.com/alchemy-run/alchemy/issues/1750 [<samp>(2745d)</samp>](https://github.com/alchemy-run/alchemy/commit/2745d7943)
|
||||
- Prevent partial registry writes from breaking service discovery - by **sam** in https://github.com/alchemy-run/alchemy/issues/1924 [<samp>(a12d5)</samp>](https://github.com/alchemy-run/alchemy/commit/a12d5b8c7)
|
||||
- **workflows**: Omit step-config keys with no value - by **apostoli** and **sam** in https://github.com/alchemy-run/alchemy/issues/1142 [<samp>(1c28c)</samp>](https://github.com/alchemy-run/alchemy/commit/1c28c06ef)
|
||||
- **cloudflare-runtime**:
|
||||
- Prune the module runner callback maps - by **Alex** and **BlankParticle** in https://github.com/alchemy-run/alchemy/issues/1770 [<samp>(318c4)</samp>](https://github.com/alchemy-run/alchemy/commit/318c442ad)
|
||||
- **command**:
|
||||
- Gracefully clean up wrapper processes - by **sam** in https://github.com/alchemy-run/alchemy/issues/1760 [<samp>(d3e71)</samp>](https://github.com/alchemy-run/alchemy/commit/d3e7132e2)
|
||||
- **core**:
|
||||
- Reuse pure Action outputs when inputs are unchanged - by **Leonardo E. Dominguez** and **sam** in https://github.com/alchemy-run/alchemy/issues/1379 [<samp>(b7b65)</samp>](https://github.com/alchemy-run/alchemy/commit/b7b656e63)
|
||||
- Plan an update when an Init-captured value changes - by **sam** in https://github.com/alchemy-run/alchemy/issues/1837 [<samp>(467e1)</samp>](https://github.com/alchemy-run/alchemy/commit/467e1728a)
|
||||
- **deps**:
|
||||
- Bump distilled for Fly IP assignment networks - by **sam** in https://github.com/alchemy-run/alchemy/issues/1784 [<samp>(31400)</samp>](https://github.com/alchemy-run/alchemy/commit/31400f4d6)
|
||||
- **effect**:
|
||||
- Move to Effect 4.0.0-rc.118's flattened module layout - by **Rahul Mishra** and **Agustí Fernandez Pardo** in https://github.com/alchemy-run/alchemy/issues/1894 [<samp>(8e062)</samp>](https://github.com/alchemy-run/alchemy/commit/8e06298e2)
|
||||
- **engine**:
|
||||
- Clean up interrupted replacement generations - by **sam** in https://github.com/alchemy-run/alchemy/issues/1704 [<samp>(5edbe)</samp>](https://github.com/alchemy-run/alchemy/commit/5edbe41e3)
|
||||
- **fly**:
|
||||
- Transport binding values via RuntimeContext, not host.bind env - by **Michael K** and **sam** in https://github.com/alchemy-run/alchemy/issues/1554 [<samp>(124af)</samp>](https://github.com/alchemy-run/alchemy/commit/124af3d35)
|
||||
- **frontend-frameworks**:
|
||||
- Bump sveltekit to 3.0.0-next.27 - by **Cameron McEvenue** and **BlankParticle** in https://github.com/alchemy-run/alchemy/issues/1709 [<samp>(08354)</samp>](https://github.com/alchemy-run/alchemy/commit/08354d70d)
|
||||
- **gcp**:
|
||||
- Deployed-host binding tests, GCP.Website, and full-suite fixes - by **Michael K** in https://github.com/alchemy-run/alchemy/issues/1898 [<samp>(e354a)</samp>](https://github.com/alchemy-run/alchemy/commit/e354a4555)
|
||||
- **nextjs**:
|
||||
- Use shared built config to serve in node/neon - by **Aman Varshney** and **BlankParticle** in https://github.com/alchemy-run/alchemy/issues/1805 [<samp>(08110)</samp>](https://github.com/alchemy-run/alchemy/commit/081109293)
|
||||
- **pkg**:
|
||||
- Support fork previews and PR revision URLs - by **BlankParticle** in https://github.com/alchemy-run/alchemy/issues/1681 [<samp>(d6a6b)</samp>](https://github.com/alchemy-run/alchemy/commit/d6a6be1e8)
|
||||
- **prisma**:
|
||||
- Default dev commands to development mode - by **Aman Varshney** in https://github.com/alchemy-run/alchemy/issues/1703 [<samp>(dc750)</samp>](https://github.com/alchemy-run/alchemy/commit/dc75059b0)
|
||||
- **railway**:
|
||||
- Apply Service region through multiRegionConfig - by **sam** in https://github.com/alchemy-run/alchemy/issues/1766 [<samp>(3101a)</samp>](https://github.com/alchemy-run/alchemy/commit/3101aff24)
|
||||
- **sveltekit**:
|
||||
- Complete regression test build output - by **BlankParticle** [<samp>(c37b8)</samp>](https://github.com/alchemy-run/alchemy/commit/c37b8c37d)
|
||||
- Load Playwright tsconfig before fixture config - by **BlankParticle** [<samp>(547d2)</samp>](https://github.com/alchemy-run/alchemy/commit/547d2b4ee)
|
||||
- **website**:
|
||||
- Make OpenNext config and Node-hosted Octane adapters optional - by **sam** in https://github.com/alchemy-run/alchemy/issues/1747 [<samp>(7c1c6)</samp>](https://github.com/alchemy-run/alchemy/commit/7c1c6d2e0)
|
||||
- Consolidate generated reference pages - by **BlankParticle** in https://github.com/alchemy-run/alchemy/issues/1767 [<samp>(ed12d)</samp>](https://github.com/alchemy-run/alchemy/commit/ed12d29fb)
|
||||
- Organize API reference navigation by service and product - by **Rahul Mishra** in https://github.com/alchemy-run/alchemy/issues/1774 [<samp>(93c70)</samp>](https://github.com/alchemy-run/alchemy/commit/93c70aa0d)
|
||||
- Load frontend-frameworks lazily - by **Aman Varshney** and **BlankParticle** in https://github.com/alchemy-run/alchemy/issues/1815 [<samp>(08f84)</samp>](https://github.com/alchemy-run/alchemy/commit/08f84a57d)
|
||||
- Commit copy-editor virtual module types - by **Michael K** in https://github.com/alchemy-run/alchemy/issues/1824 [<samp>(983a8)</samp>](https://github.com/alchemy-run/alchemy/commit/983a8fbff)
|
||||
|
||||
##### [View changes on GitHub](https://github.com/alchemy-run/alchemy/compare/v2.0.0-beta.79...HEAD)
|
||||
|
||||
---
|
||||
|
||||
## v2.0.0-beta.79
|
||||
|
||||
### 🚀 Features
|
||||
|
||||
- **prisma**: Add Website framework support - by **sam** in https://github.com/alchemy-run/alchemy/issues/1683 [<samp>(530a2)</samp>](https://github.com/alchemy-run/alchemy/commit/530a201e4)
|
||||
|
||||
### 🐞 Bug Fixes
|
||||
|
||||
- **cli**: Start Bun with production JSX settings - by **sam** in https://github.com/alchemy-run/alchemy/issues/1694 [<samp>(eef2a)</samp>](https://github.com/alchemy-run/alchemy/commit/eef2a9123)
|
||||
- **cloudflare**: Infer env for external Worker classes - by **sam** in https://github.com/alchemy-run/alchemy/issues/1697 [<samp>(233da)</samp>](https://github.com/alchemy-run/alchemy/commit/233da74ef)
|
||||
- **cloudflare-runtime**: Declare mime as a dependency - by **Matthew Aylward** in https://github.com/alchemy-run/alchemy/issues/1690 [<samp>(85991)</samp>](https://github.com/alchemy-run/alchemy/commit/859911c14)
|
||||
|
||||
##### [View changes on GitHub](https://github.com/alchemy-run/alchemy/compare/v2.0.0-beta.78...HEAD)
|
||||
|
||||
---
|
||||
|
||||
## v2.0.0-beta.78
|
||||
|
||||
### 🚨 Breaking Changes
|
||||
|
||||
@@ -8,11 +8,11 @@
|
||||
|
||||
[](https://www.npmjs.com/package/alchemy)
|
||||
[](./LICENSE)
|
||||
[](https://discord.gg/jwKw8dBJdN)
|
||||
[](https://alchemy.run/discord)
|
||||
|
||||
**Infrastructure-as-Effects** — cloud infrastructure and application logic as a single, type-safe [Effect](https://effect.website) program.
|
||||
|
||||
[Docs](https://alchemy.run) · [Tutorial](https://alchemy.run/tutorial/part-1) · [Examples](./examples) · [Discord](https://discord.gg/jwKw8dBJdN)
|
||||
[Docs](https://alchemy.run) · [Tutorial](https://alchemy.run/tutorial/part-1) · [Examples](./examples) · [Discord](https://alchemy.run/discord)
|
||||
|
||||
</div>
|
||||
|
||||
@@ -93,7 +93,7 @@ dependencies or breaking conventions.
|
||||
- [Examples](./examples) — runnable projects on AWS and Cloudflare
|
||||
- [llms.txt](https://alchemy.run/llms.txt) — agent-ready documentation index
|
||||
|
||||
> **alchemy** is in alpha. Expect breaking changes. Come hang in our [Discord](https://discord.gg/jwKw8dBJdN).
|
||||
> **alchemy** is in alpha. Expect breaking changes. Come hang in our [Discord](https://alchemy.run/discord).
|
||||
|
||||
## Credits
|
||||
|
||||
|
||||
@@ -125,7 +125,8 @@ been dedicated to the public domain. See <https://www.sqlite.org/copyright.html>
|
||||
- Astro: [`a2240c43830e29c1d85667f4c610655d6b10253f`](https://github.com/withastro/astro/tree/a2240c43830e29c1d85667f4c610655d6b10253f)
|
||||
- SvelteKit: [`f36b3a4cd307bd8c89e03fa191becc175e7b3077`](https://github.com/sveltejs/kit/tree/f36b3a4cd307bd8c89e03fa191becc175e7b3077)
|
||||
- Waku: [`39e868f2638c27de9635c68ebf965e14a4112e9b`](https://github.com/wakujs/waku/tree/39e868f2638c27de9635c68ebf965e14a4112e9b)
|
||||
- Cloudflare Workers SDK: [`b7b4ff84477982e7c770bb93928287893fcf2e03`](https://github.com/cloudflare/workers-sdk/tree/b7b4ff84477982e7c770bb93928287893fcf2e03)
|
||||
- Cloudflare Workers SDK: [`f9e7727dbef58e71c6b297dc688d3c544cef87cb`](https://github.com/cloudflare/workers-sdk/tree/f9e7727dbef58e71c6b297dc688d3c544cef87cb)
|
||||
- Cloudflare Workers SDK (local R2 S3 endpoint, `R2BucketS3.worker.ts`): [`cd7508cccf2de1ea010320d6f3e70ec80e6e5e2e`](https://github.com/cloudflare/workers-sdk/tree/cd7508cccf2de1ea010320d6f3e70ec80e6e5e2e)
|
||||
- OpenNext for Cloudflare: [`da4b7fc8c89441a6f96205635fa70e329d1f0df7`](https://github.com/opennextjs/opennextjs-cloudflare/tree/da4b7fc8c89441a6f96205635fa70e329d1f0df7)
|
||||
- SST: <https://github.com/sst/sst>
|
||||
- node-sanitize-filename: <https://github.com/parshap/node-sanitize-filename>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import * as Cloudflare from "alchemy/Cloudflare";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Schedule from "effect/Schedule";
|
||||
import * as HttpClientRequest from "effect/unstable/http/HttpClientRequest";
|
||||
import * as HttpClientRequest from "effect/http/HttpClientRequest";
|
||||
import { BunContainer } from "./bun-container.ts";
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import * as Cloudflare from "alchemy/Cloudflare";
|
||||
import * as Effect from "effect/Effect";
|
||||
import { HttpServerRequest } from "effect/unstable/http/HttpServerRequest";
|
||||
import * as HttpServerResponse from "effect/unstable/http/HttpServerResponse";
|
||||
import { HttpServerRequest } from "effect/http/HttpServerRequest";
|
||||
import * as HttpServerResponse from "effect/http/HttpServerResponse";
|
||||
import { BunObject } from "./bun-object.ts";
|
||||
import { EffectfulObject } from "./effectful-object.ts";
|
||||
import { OpencodeObject } from "./opencode-object.ts";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as Cloudflare from "alchemy/Cloudflare";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as HttpServerResponse from "effect/unstable/http/HttpServerResponse";
|
||||
import * as HttpServerResponse from "effect/http/HttpServerResponse";
|
||||
|
||||
/**
|
||||
* Minimal Effect-native container for the cold-start benchmark. Alchemy bundles
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as Effect from "effect/Effect";
|
||||
import { HttpServerRequest } from "effect/unstable/http/HttpServerRequest";
|
||||
import * as HttpServerResponse from "effect/unstable/http/HttpServerResponse";
|
||||
import { HttpServerRequest } from "effect/http/HttpServerRequest";
|
||||
import * as HttpServerResponse from "effect/http/HttpServerResponse";
|
||||
|
||||
/**
|
||||
* The effectful MicroVM server, shared verbatim by the bun and node effectful
|
||||
|
||||
@@ -4,11 +4,11 @@ import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import type * as Redacted from "effect/Redacted";
|
||||
import * as Schedule from "effect/Schedule";
|
||||
import * as FetchHttpClient from "effect/unstable/http/FetchHttpClient";
|
||||
import * as HttpBody from "effect/unstable/http/HttpBody";
|
||||
import * as HttpClient from "effect/unstable/http/HttpClient";
|
||||
import { HttpServerRequest } from "effect/unstable/http/HttpServerRequest";
|
||||
import * as HttpServerResponse from "effect/unstable/http/HttpServerResponse";
|
||||
import * as FetchHttpClient from "effect/http/FetchHttpClient";
|
||||
import * as HttpBody from "effect/http/HttpBody";
|
||||
import * as HttpClient from "effect/http/HttpClient";
|
||||
import { HttpServerRequest } from "effect/http/HttpServerRequest";
|
||||
import * as HttpServerResponse from "effect/http/HttpServerResponse";
|
||||
import { BunMicrovm } from "./bun-image.ts";
|
||||
import { ExternalMicrovm } from "./external-image.ts";
|
||||
import { EffectfulBun } from "./effectful-bun.ts";
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import * as Cloudflare from "alchemy/Cloudflare";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Schedule from "effect/Schedule";
|
||||
import * as HttpClientRequest from "effect/unstable/http/HttpClientRequest";
|
||||
import * as HttpClientRequest from "effect/http/HttpClientRequest";
|
||||
import { OpencodeContainer } from "./opencode-container.ts";
|
||||
|
||||
// Matches OPENCODE_SERVER_PASSWORD=bench in contexts/opencode/Dockerfile
|
||||
|
||||
@@ -4,12 +4,12 @@ import * as Duration from "effect/Duration";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Schedule from "effect/Schedule";
|
||||
import * as FetchHttpClient from "effect/unstable/http/FetchHttpClient";
|
||||
import * as HttpBody from "effect/unstable/http/HttpBody";
|
||||
import * as HttpClient from "effect/unstable/http/HttpClient";
|
||||
import type * as HttpClientError from "effect/unstable/http/HttpClientError";
|
||||
import { HttpServerRequest } from "effect/unstable/http/HttpServerRequest";
|
||||
import * as HttpServerResponse from "effect/unstable/http/HttpServerResponse";
|
||||
import * as FetchHttpClient from "effect/http/FetchHttpClient";
|
||||
import * as HttpBody from "effect/http/HttpBody";
|
||||
import * as HttpClient from "effect/http/HttpClient";
|
||||
import type * as HttpClientError from "effect/http/HttpClientError";
|
||||
import { HttpServerRequest } from "effect/http/HttpServerRequest";
|
||||
import * as HttpServerResponse from "effect/http/HttpServerResponse";
|
||||
import { BunMicrovm } from "./bun-image.ts";
|
||||
import { ExternalMicrovm } from "./external-image.ts";
|
||||
import { EffectfulBun } from "./effectful-bun.ts";
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import * as Cloudflare from "alchemy/Cloudflare";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Schedule from "effect/Schedule";
|
||||
import * as HttpClientRequest from "effect/unstable/http/HttpClientRequest";
|
||||
import * as HttpClientRequest from "effect/http/HttpClientRequest";
|
||||
import { RemoteContainer } from "./remote-container.ts";
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,8 +8,8 @@ import * as FileSystem from "effect/FileSystem";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Path from "effect/Path";
|
||||
import * as Schedule from "effect/Schedule";
|
||||
import * as HttpClient from "effect/unstable/http/HttpClient";
|
||||
import * as HttpClientRequest from "effect/unstable/http/HttpClientRequest";
|
||||
import * as HttpClient from "effect/http/HttpClient";
|
||||
import * as HttpClientRequest from "effect/http/HttpClientRequest";
|
||||
import Stack, { benchMicrovm } from "../alchemy.run.ts";
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import * as Cloudflare from "alchemy/Cloudflare";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as HttpServerRequest from "effect/unstable/http/HttpServerRequest";
|
||||
import * as HttpServerResponse from "effect/unstable/http/HttpServerResponse";
|
||||
import * as HttpServerRequest from "effect/http/HttpServerRequest";
|
||||
import * as HttpServerResponse from "effect/http/HttpServerResponse";
|
||||
import { Uploads } from "./Uploads.ts";
|
||||
import { Visits } from "./Visits.ts";
|
||||
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
# Alchemy examples
|
||||
|
||||
[SQL clients](https://alchemy.run/sql) · [Providers](https://alchemy.run/sql#find-your-provider)
|
||||
|
||||
Examples create billable infrastructure. Follow each README's cleanup commands.
|
||||
|
||||
## SQL integrations
|
||||
|
||||
| Runtime | Database | Client | Runnable project |
|
||||
| --- | --- | --- | --- |
|
||||
| AWS Lambda | Aurora PostgreSQL | Drizzle | [aws-aurora-drizzle](./aws-aurora-drizzle) |
|
||||
| AWS Lambda | Aurora DSQL | Drizzle | [aws-dsql-drizzle](./aws-dsql-drizzle) |
|
||||
| AWS Lambda | Aurora PostgreSQL | `pg` | [aws-rds](./aws-rds) |
|
||||
| Cloudflare Workers | Neon Postgres through Hyperdrive | Drizzle | [cloudflare-neon-drizzle](./cloudflare-neon-drizzle) |
|
||||
| Cloudflare Durable Objects | SQLite per object | Drizzle | [cloudflare-durable-object-sql](./cloudflare-durable-object-sql) |
|
||||
| Cloudflare Workers | PlanetScale Postgres through Hyperdrive | Drizzle | [cloudflare-planetscale-postgres-drizzle](./cloudflare-planetscale-postgres-drizzle) |
|
||||
| Cloudflare Workers | Neon Postgres through Hyperdrive | Prisma ORM, TypeScript-first | [cloudflare-neon-prisma](./cloudflare-neon-prisma) |
|
||||
| Cloudflare Workers | Neon Postgres through Hyperdrive | Prisma ORM, PSL-first | [cloudflare-neon-prisma-psl](./cloudflare-neon-prisma-psl) |
|
||||
| Fly Service | Fly Managed Postgres | Drizzle | [fly-postgres](./fly-postgres) |
|
||||
| Hetzner Service | Neon Postgres | Drizzle | [hetzner-website-vite](./hetzner-website-vite) |
|
||||
| Railway Service | Railway Postgres | Drizzle | [railway-service](./railway-service) |
|
||||
|
||||
### Looking for Drizzle + Aurora?
|
||||
|
||||
[Aurora PostgreSQL guide](https://alchemy.run/aws/data/drizzle-aurora) · [Aurora DSQL guide](https://alchemy.run/aws/data/drizzle-dsql)
|
||||
|
||||
These are separate database integrations. `aws-rds` uses plain `pg`, not Drizzle.
|
||||
|
||||
## Guides and lifecycle
|
||||
|
||||
- [Choose a database](https://alchemy.run/sql/databases).
|
||||
- [Drizzle](https://alchemy.run/sql/drizzle/postgres) and [Prisma contracts](https://alchemy.run/sql/prisma/contracts).
|
||||
- [Connection lifecycle](https://alchemy.run/sql/effect-sql/lifecycle).
|
||||
- [AWS](https://alchemy.run/aws/setup), [Cloudflare](https://alchemy.run/cloudflare/setup), [Fly](https://alchemy.run/fly/setup), [Hetzner](https://alchemy.run/hetzner/setup), and [Railway](https://alchemy.run/railway/setup) credentials.
|
||||
@@ -0,0 +1,57 @@
|
||||
# Drizzle + Aurora PostgreSQL + Lambda
|
||||
|
||||
[Integration guide](https://alchemy.run/aws/data/drizzle-aurora/) · [AWS setup](https://alchemy.run/aws/setup/)
|
||||
|
||||
## Deploy
|
||||
|
||||
From the repository root:
|
||||
|
||||
```sh
|
||||
pnpm install
|
||||
cd examples/aws-aurora-drizzle
|
||||
pnpm deploy --profile testing --stage aurora-example
|
||||
```
|
||||
|
||||
Use `us-west-2`; changing region also requires changing the subnet availability zones. Aurora incurs charges until destroyed.
|
||||
|
||||
## Query
|
||||
|
||||
```sh
|
||||
aws lambda invoke --region us-west-2 \
|
||||
--function-name '<functionName>' \
|
||||
--cli-binary-format raw-in-base64-out \
|
||||
--payload file://health-event.json response.json
|
||||
cat response.json
|
||||
```
|
||||
|
||||
Use the printed function name and your AWS CLI credentials. The Function URL requires [SigV4-signed requests](./test/integ.test.ts).
|
||||
|
||||
| Method | Path | Body |
|
||||
| --- | --- | --- |
|
||||
| GET | `/health` | — |
|
||||
| GET | `/todos` | — |
|
||||
| POST | `/todos` | `{"id":"aaaaaaaa-0000-4000-8000-000000000001","title":"Ship it"}` |
|
||||
| PATCH | `/todos/<uuid>` | `{"done":true}` |
|
||||
| DELETE | `/todos/<uuid>` | — |
|
||||
|
||||
## Schema and connections
|
||||
|
||||
[Private network](./src/database.ts) · [Deployment-only bootstrap](./src/bootstrap.ts) · [IAM and verified TLS](./src/Api.ts)
|
||||
|
||||
The bootstrap creates the initial schema and restricted login. Later schema changes need versioned migrations.
|
||||
|
||||
## Live test
|
||||
|
||||
```sh
|
||||
AWS_TEST_SLOW=1 ALCHEMY_PROFILE=testing bun test test/integ.test.ts
|
||||
```
|
||||
|
||||
Creates real AWS resources and destroys them afterward. Setup and cleanup can each take several minutes.
|
||||
|
||||
## Destroy
|
||||
|
||||
```sh
|
||||
pnpm destroy --profile testing --stage aurora-example
|
||||
```
|
||||
|
||||
This deletes the database data. Wait for cleanup to finish; reuse the same profile and stage if interrupted.
|
||||
@@ -0,0 +1,21 @@
|
||||
import * as Alchemy from "alchemy";
|
||||
import * as AWS from "alchemy/AWS";
|
||||
import * as Effect from "effect/Effect";
|
||||
import Api from "./src/Api.ts";
|
||||
import { database } from "./src/database.ts";
|
||||
|
||||
export default Alchemy.Stack(
|
||||
"aws-aurora-drizzle",
|
||||
{ providers: AWS.providers(), state: Alchemy.localState() },
|
||||
Effect.gen(function* () {
|
||||
const api = yield* Api;
|
||||
const db = yield* database;
|
||||
return {
|
||||
url: api.functionUrl,
|
||||
functionName: api.functionName,
|
||||
clusterId: db.cluster.dbClusterIdentifier,
|
||||
writerId: db.writer.dbInstanceIdentifier,
|
||||
vpcId: db.vpc.vpcId,
|
||||
};
|
||||
}),
|
||||
);
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"version": "2.0",
|
||||
"routeKey": "$default",
|
||||
"rawPath": "/health",
|
||||
"rawQueryString": "",
|
||||
"headers": { "host": "example.invalid" },
|
||||
"requestContext": {
|
||||
"http": {
|
||||
"method": "GET",
|
||||
"path": "/health",
|
||||
"protocol": "HTTP/1.1",
|
||||
"sourceIp": "127.0.0.1",
|
||||
"userAgent": "aws-cli"
|
||||
}
|
||||
},
|
||||
"isBase64Encoded": false
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "aws-aurora-drizzle-example",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"license": "Apache-2.0",
|
||||
"scripts": {
|
||||
"build": "tsc -b",
|
||||
"deploy": "alchemy deploy",
|
||||
"destroy": "alchemy destroy",
|
||||
"test": "bun test"
|
||||
},
|
||||
"dependencies": {
|
||||
"@distilled.cloud/aws": "workspace:*",
|
||||
"@effect/platform-node": "catalog:",
|
||||
"@effect/sql-pg": "catalog:",
|
||||
"@types/pg": "catalog:",
|
||||
"alchemy": "workspace:*",
|
||||
"drizzle-orm": "catalog:",
|
||||
"effect": "catalog:",
|
||||
"pg": "catalog:"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
import * as AWS from "alchemy/AWS";
|
||||
import * as Drizzle from "alchemy/Drizzle/Postgres";
|
||||
import * as Duration from "effect/Duration";
|
||||
import { eq, sql } from "drizzle-orm";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Redacted from "effect/Redacted";
|
||||
import * as Schema from "effect/Schema";
|
||||
import { HttpServerRequest } from "effect/http/HttpServerRequest";
|
||||
import * as HttpServerResponse from "effect/http/HttpServerResponse";
|
||||
import { bootstrap } from "./bootstrap.ts";
|
||||
import { database } from "./database.ts";
|
||||
import { todos } from "./schema.ts";
|
||||
|
||||
export default class Api extends AWS.Lambda.Function<Api>()(
|
||||
"Api",
|
||||
Effect.gen(function* () {
|
||||
const schemaVersion = yield* bootstrap;
|
||||
return {
|
||||
main: import.meta.url,
|
||||
runtime: "nodejs22.x" as const,
|
||||
functionUrl: { authType: "AWS_IAM" as const },
|
||||
timeout: Duration.seconds(30),
|
||||
build: { install: ["pg"] },
|
||||
env: {
|
||||
SCHEMA_VERSION: schemaVersion,
|
||||
NODE_EXTRA_CA_CERTS: "/var/runtime/ca-cert.pem",
|
||||
},
|
||||
};
|
||||
}),
|
||||
Effect.gen(function* () {
|
||||
const { cluster, subnetIds, lambdaSecurityGroup } = yield* database;
|
||||
const connect = yield* AWS.RDS.Connect(cluster, {
|
||||
auth: "iam",
|
||||
username: "app_iam",
|
||||
database: "app",
|
||||
subnetIds,
|
||||
securityGroupIds: [lambdaSecurityGroup.groupId],
|
||||
});
|
||||
const db = yield* Drizzle.Postgres(
|
||||
connect.pipe(
|
||||
Effect.map((connection) => {
|
||||
const url = new URL(Redacted.value(connection.url));
|
||||
// Connect currently emits no-verify; require full certificate verification.
|
||||
url.searchParams.set("sslmode", "verify-full");
|
||||
return Redacted.make(url.toString());
|
||||
}),
|
||||
),
|
||||
);
|
||||
return {
|
||||
fetch: Effect.gen(function* () {
|
||||
const request = yield* HttpServerRequest;
|
||||
const url = new URL(request.originalUrl);
|
||||
if (request.method === "GET" && url.pathname === "/health") {
|
||||
const rows = yield* db.execute(sql`SELECT current_user AS username,
|
||||
(SELECT ssl FROM pg_stat_ssl WHERE pid = pg_backend_pid()) AS tls,
|
||||
has_table_privilege(current_user, 'todos', 'INSERT') AS can_insert,
|
||||
has_schema_privilege(current_user, 'public', 'CREATE') AS can_create`);
|
||||
return yield* HttpServerResponse.json(rows);
|
||||
}
|
||||
if (url.pathname === "/todos" && request.method === "GET") {
|
||||
return yield* HttpServerResponse.json(yield* db.select().from(todos));
|
||||
}
|
||||
if (url.pathname === "/todos" && request.method === "POST") {
|
||||
const input = yield* request.json.pipe(
|
||||
Effect.flatMap(
|
||||
Schema.decodeUnknownEffect(
|
||||
Schema.Struct({
|
||||
id: Schema.String.check(Schema.isUUID()),
|
||||
title: Schema.NonEmptyString,
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
return yield* HttpServerResponse.json(
|
||||
yield* db.insert(todos).values(input).returning(),
|
||||
{ status: 201 },
|
||||
);
|
||||
}
|
||||
if (url.pathname.startsWith("/todos/")) {
|
||||
const id = yield* Schema.decodeUnknownEffect(
|
||||
Schema.String.check(Schema.isUUID()),
|
||||
)(url.pathname.slice(7));
|
||||
if (request.method === "PATCH") {
|
||||
const input = yield* request.json.pipe(
|
||||
Effect.flatMap(
|
||||
Schema.decodeUnknownEffect(
|
||||
Schema.Struct({ done: Schema.Boolean }),
|
||||
),
|
||||
),
|
||||
);
|
||||
return yield* HttpServerResponse.json(
|
||||
yield* db
|
||||
.update(todos)
|
||||
.set(input)
|
||||
.where(eq(todos.id, id))
|
||||
.returning(),
|
||||
);
|
||||
}
|
||||
if (request.method === "DELETE") {
|
||||
yield* db.delete(todos).where(eq(todos.id, id));
|
||||
return HttpServerResponse.empty({ status: 204 });
|
||||
}
|
||||
}
|
||||
return HttpServerResponse.text("Not found", { status: 404 });
|
||||
}).pipe(
|
||||
Effect.catchTag("SchemaError", () =>
|
||||
Effect.succeed(
|
||||
HttpServerResponse.text("Invalid request", { status: 400 }),
|
||||
),
|
||||
),
|
||||
Effect.orDie,
|
||||
),
|
||||
};
|
||||
}).pipe(Effect.provide(AWS.RDS.ConnectHttp)),
|
||||
) {}
|
||||
@@ -0,0 +1,52 @@
|
||||
import * as Alchemy from "alchemy";
|
||||
import * as AWS from "alchemy/AWS";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Schedule from "effect/Schedule";
|
||||
import { database } from "./database.ts";
|
||||
|
||||
// One atomic, replay-safe initial migration. Application roles never own DDL.
|
||||
const initialMigration = `DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = 'app_iam') THEN
|
||||
CREATE ROLE app_iam LOGIN;
|
||||
END IF;
|
||||
GRANT rds_iam TO app_iam;
|
||||
REVOKE CREATE ON SCHEMA public FROM PUBLIC;
|
||||
CREATE TABLE IF NOT EXISTS public.todos (
|
||||
id uuid PRIMARY KEY,
|
||||
title text NOT NULL,
|
||||
done boolean NOT NULL DEFAULT false
|
||||
);
|
||||
GRANT CONNECT ON DATABASE app TO app_iam;
|
||||
GRANT USAGE ON SCHEMA public TO app_iam;
|
||||
GRANT SELECT, INSERT, UPDATE, DELETE ON public.todos TO app_iam;
|
||||
END $$`;
|
||||
|
||||
export const bootstrap = Effect.gen(function* () {
|
||||
const db = yield* database;
|
||||
const Bootstrap = Alchemy.Action(
|
||||
"BootstrapDatabase",
|
||||
Effect.gen(function* () {
|
||||
const execute = yield* AWS.RDSData.ExecuteStatement(db.cluster, {
|
||||
secret: db.secret,
|
||||
database: "app",
|
||||
});
|
||||
return Effect.fn(function* (input: { writer: string; sql: string }) {
|
||||
yield* execute({ sql: input.sql }).pipe(
|
||||
Effect.retry({
|
||||
while: (error) =>
|
||||
error._tag === "DatabaseUnavailableException" ||
|
||||
error._tag === "DatabaseResumingException",
|
||||
schedule: Schedule.spaced("5 seconds"),
|
||||
times: 8,
|
||||
}),
|
||||
);
|
||||
return "1";
|
||||
});
|
||||
}).pipe(Effect.provide(AWS.RDSData.ExecuteStatementHttp)),
|
||||
);
|
||||
return yield* Bootstrap({
|
||||
writer: db.writer.dbInstanceArn,
|
||||
sql: initialMigration,
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,54 @@
|
||||
import * as AWS from "alchemy/AWS";
|
||||
import * as Effect from "effect/Effect";
|
||||
|
||||
export const database = Effect.gen(function* () {
|
||||
const vpc = yield* AWS.EC2.Vpc("Vpc", { cidrBlock: "10.62.0.0/16" });
|
||||
const subnetA = yield* AWS.EC2.Subnet("SubnetA", {
|
||||
vpcId: vpc.vpcId,
|
||||
cidrBlock: "10.62.0.0/24",
|
||||
availabilityZone: "us-west-2a",
|
||||
});
|
||||
const subnetB = yield* AWS.EC2.Subnet("SubnetB", {
|
||||
vpcId: vpc.vpcId,
|
||||
cidrBlock: "10.62.1.0/24",
|
||||
availabilityZone: "us-west-2b",
|
||||
});
|
||||
const lambdaSecurityGroup = yield* AWS.EC2.SecurityGroup(
|
||||
"LambdaSecurityGroup",
|
||||
{
|
||||
vpcId: vpc.vpcId,
|
||||
description: "Aurora example application; no inbound connections",
|
||||
},
|
||||
);
|
||||
const dbSecurityGroup = yield* AWS.EC2.SecurityGroup(
|
||||
"DatabaseSecurityGroup",
|
||||
{
|
||||
vpcId: vpc.vpcId,
|
||||
description: "Postgres from the application security group only",
|
||||
ingress: [
|
||||
{
|
||||
ipProtocol: "tcp",
|
||||
fromPort: 5432,
|
||||
toPort: 5432,
|
||||
referencedGroupId: lambdaSecurityGroup.groupId,
|
||||
},
|
||||
],
|
||||
},
|
||||
);
|
||||
const subnetIds = [subnetA.subnetId, subnetB.subnetId];
|
||||
const aurora = yield* AWS.RDS.Aurora("Database", {
|
||||
databaseName: "app",
|
||||
engine: "aurora-postgresql",
|
||||
engineVersion: "17.5",
|
||||
subnetIds,
|
||||
securityGroupIds: [dbSecurityGroup.groupId],
|
||||
secret: { username: "dbadmin" },
|
||||
dataApi: true,
|
||||
cluster: {
|
||||
enableIAMDatabaseAuthentication: true,
|
||||
serverlessV2ScalingConfiguration: { MinCapacity: 0.5, MaxCapacity: 1 },
|
||||
},
|
||||
instance: { dbInstanceClass: "db.serverless", publiclyAccessible: false },
|
||||
});
|
||||
return { ...aurora, vpc, subnetIds, lambdaSecurityGroup };
|
||||
});
|
||||
@@ -0,0 +1,7 @@
|
||||
import { boolean, pgTable, text, uuid } from "drizzle-orm/pg-core";
|
||||
|
||||
export const todos = pgTable("todos", {
|
||||
id: uuid("id").primaryKey(),
|
||||
title: text("title").notNull(),
|
||||
done: boolean("done").notNull().default(false),
|
||||
});
|
||||
@@ -0,0 +1,119 @@
|
||||
import { Credentials } from "@distilled.cloud/aws/Credentials";
|
||||
import { sign } from "@distilled.cloud/aws/SigV4";
|
||||
import * as Alchemy from "alchemy";
|
||||
import * as AWS from "alchemy/AWS";
|
||||
import * as Test from "alchemy/Test/Bun";
|
||||
import { describe, expect } from "bun:test";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Redacted from "effect/Redacted";
|
||||
import * as HttpClient from "effect/http/HttpClient";
|
||||
import * as HttpClientRequest from "effect/http/HttpClientRequest";
|
||||
import Stack from "../alchemy.run.ts";
|
||||
|
||||
// Aurora provisioning/deletion is opt-in, as in the RDSData integration suite.
|
||||
describe.skipIf(!process.env.AWS_TEST_SLOW)(
|
||||
"Drizzle + Aurora PostgreSQL",
|
||||
() => {
|
||||
const { test, beforeAll, afterAll, deploy, destroy } = Test.make({
|
||||
providers: AWS.providers(),
|
||||
state: Alchemy.localState(),
|
||||
profile: process.env.ALCHEMY_PROFILE,
|
||||
});
|
||||
const stack = beforeAll(
|
||||
Effect.gen(function* () {
|
||||
yield* destroy(Stack);
|
||||
const outputs = yield* deploy(Stack);
|
||||
yield* deploy(Stack);
|
||||
return outputs;
|
||||
}),
|
||||
{ timeout: 1_500_000 },
|
||||
);
|
||||
afterAll(destroy(Stack), { timeout: 1_500_000 });
|
||||
|
||||
test.provider(
|
||||
"CRUD, TLS, least privilege, and repeated invocations",
|
||||
() =>
|
||||
Effect.gen(function* () {
|
||||
const { url } = yield* stack;
|
||||
if (!url)
|
||||
return yield* Effect.fail(new Error("Missing Function URL"));
|
||||
const client = yield* HttpClient.HttpClient;
|
||||
const getCredentials = yield* Credentials;
|
||||
expect((yield* client.get(`${url}health`)).status).toBe(403);
|
||||
const request = Effect.fn(function* (
|
||||
method: "GET" | "POST" | "PATCH" | "DELETE",
|
||||
path: string,
|
||||
body?: object,
|
||||
) {
|
||||
const credentials = yield* getCredentials;
|
||||
const payload =
|
||||
body === undefined ? undefined : JSON.stringify(body);
|
||||
const signed = yield* sign({
|
||||
method,
|
||||
url: new URL(path, url).toString(),
|
||||
body: payload,
|
||||
service: "lambda",
|
||||
region: credentials.region,
|
||||
accessKeyId: Redacted.value(credentials.accessKeyId),
|
||||
secretAccessKey: credentials.secretAccessKey,
|
||||
sessionToken: credentials.sessionToken,
|
||||
});
|
||||
const base = HttpClientRequest.make(method)(signed.url).pipe(
|
||||
HttpClientRequest.setHeaders(signed.headers),
|
||||
);
|
||||
const response = yield* client.execute(
|
||||
payload === undefined
|
||||
? base
|
||||
: base.pipe(
|
||||
HttpClientRequest.bodyText(payload, "application/json"),
|
||||
),
|
||||
);
|
||||
return { statusCode: response.status, body: yield* response.text };
|
||||
});
|
||||
const health = yield* request("GET", "/health");
|
||||
expect(health.statusCode).toBe(200);
|
||||
expect(JSON.parse(health.body).rows).toEqual([
|
||||
{
|
||||
username: "app_iam",
|
||||
tls: true,
|
||||
can_insert: true,
|
||||
can_create: false,
|
||||
},
|
||||
]);
|
||||
const id = "aaaaaaaa-0000-4000-8000-000000000001";
|
||||
yield* request("DELETE", `/todos/${id}`);
|
||||
expect((yield* request("GET", "/todos")).body).toBe("[]");
|
||||
const created = yield* request("POST", "/todos", {
|
||||
id,
|
||||
title: "Ship Aurora guide",
|
||||
});
|
||||
expect(created.statusCode).toBe(201);
|
||||
expect(JSON.parse(created.body)).toEqual([
|
||||
{ id, title: "Ship Aurora guide", done: false },
|
||||
]);
|
||||
const updated = yield* request("PATCH", `/todos/${id}`, {
|
||||
done: true,
|
||||
});
|
||||
expect(updated.statusCode).toBe(200);
|
||||
expect(JSON.parse(updated.body)[0].done).toBe(true);
|
||||
for (let i = 0; i < 3; i++) {
|
||||
const listed = yield* request("GET", "/todos");
|
||||
expect(listed.statusCode).toBe(200);
|
||||
expect(JSON.parse(listed.body)).toEqual([
|
||||
{ id, title: "Ship Aurora guide", done: true },
|
||||
]);
|
||||
}
|
||||
expect(
|
||||
(yield* request("POST", "/todos", { id: "invalid", title: "" }))
|
||||
.statusCode,
|
||||
).toBe(400);
|
||||
expect((yield* request("GET", "/setup")).statusCode).toBe(404);
|
||||
expect((yield* request("DELETE", `/todos/${id}`)).statusCode).toBe(
|
||||
204,
|
||||
);
|
||||
expect((yield* request("GET", "/todos")).body).toBe("[]");
|
||||
}),
|
||||
{ timeout: 120_000 },
|
||||
);
|
||||
},
|
||||
);
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"include": ["alchemy.run.ts", "src/**/*.ts", "test/**/*.ts"],
|
||||
"compilerOptions": {
|
||||
"noEmit": true,
|
||||
"rootDir": ".",
|
||||
"module": "Preserve",
|
||||
"moduleResolution": "Bundler",
|
||||
"customConditions": ["bun"],
|
||||
"target": "ESNext"
|
||||
},
|
||||
"references": [{ "path": "../../packages/alchemy/tsconfig.json" }]
|
||||
}
|
||||
@@ -7,9 +7,9 @@ import {
|
||||
LanguageModel as AiLanguageModel,
|
||||
Tool,
|
||||
Toolkit,
|
||||
} from "effect/unstable/ai";
|
||||
import { HttpServerRequest } from "effect/unstable/http/HttpServerRequest";
|
||||
import * as HttpServerResponse from "effect/unstable/http/HttpServerResponse";
|
||||
} from "effect/ai";
|
||||
import { HttpServerRequest } from "effect/http/HttpServerRequest";
|
||||
import * as HttpServerResponse from "effect/http/HttpServerResponse";
|
||||
|
||||
// Amazon Nova Micro through the us cross-region inference profile — cheap
|
||||
// and fast. Any conversational Bedrock model works here (Claude, Llama,
|
||||
|
||||
@@ -4,7 +4,7 @@ import * as Test from "alchemy/Test/Bun";
|
||||
import { expect } from "bun:test";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Schedule from "effect/Schedule";
|
||||
import * as HttpClient from "effect/unstable/http/HttpClient";
|
||||
import * as HttpClient from "effect/http/HttpClient";
|
||||
import Stack from "../alchemy.run.ts";
|
||||
|
||||
const { test, beforeAll, afterAll, deploy, destroy } = Test.make({
|
||||
|
||||
@@ -7,8 +7,8 @@ import * as Config from "effect/Config";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Stream from "effect/Stream";
|
||||
import { HttpServerRequest } from "effect/unstable/http/HttpServerRequest";
|
||||
import * as HttpServerResponse from "effect/unstable/http/HttpServerResponse";
|
||||
import { HttpServerRequest } from "effect/http/HttpServerRequest";
|
||||
import * as HttpServerResponse from "effect/http/HttpServerResponse";
|
||||
import { MARKER } from "./marker.ts";
|
||||
|
||||
/**
|
||||
|
||||
@@ -14,8 +14,8 @@ import * as Test from "alchemy/Test/Bun";
|
||||
import { expect } from "bun:test";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Schedule from "effect/Schedule";
|
||||
import * as HttpClient from "effect/unstable/http/HttpClient";
|
||||
import * as HttpClientRequest from "effect/unstable/http/HttpClientRequest";
|
||||
import * as HttpClient from "effect/http/HttpClient";
|
||||
import * as HttpClientRequest from "effect/http/HttpClientRequest";
|
||||
import Stack from "../alchemy.run.ts";
|
||||
|
||||
const { test, beforeAll, afterAll, deploy, destroy } = Test.make({
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
# Drizzle + Aurora DSQL + Lambda
|
||||
|
||||
[Integration guide](https://alchemy.run/aws/data/drizzle-dsql/) · [AWS setup](https://alchemy.run/aws/setup/)
|
||||
|
||||
## Deploy
|
||||
|
||||
From the repository root:
|
||||
|
||||
```sh
|
||||
pnpm install
|
||||
cd examples/aws-dsql-drizzle
|
||||
pnpm deploy --profile testing
|
||||
```
|
||||
|
||||
Use a DSQL region such as `us-west-2`. Deployment needs `dsql:DbConnectAdmin` and network access to port 5432; these resources incur AWS charges.
|
||||
|
||||
## Query
|
||||
|
||||
```sh
|
||||
aws lambda invoke --region us-west-2 \
|
||||
--function-name '<functionName>' \
|
||||
--cli-binary-format raw-in-base64-out \
|
||||
--payload file://health-event.json response.json
|
||||
cat response.json
|
||||
```
|
||||
|
||||
Use the printed function name. [Signed HTTP CRUD examples](./test/integ.test.ts).
|
||||
|
||||
## Schema and connections
|
||||
|
||||
[Cluster](./src/database.ts) · [Deployment-only bootstrap](./src/bootstrap.ts) · [Non-admin connection and verified TLS](./src/client.ts)
|
||||
|
||||
Initial setup creates `app.todos` and `app_user`. Later schema changes need versioned, [DSQL-compatible migrations](https://docs.aws.amazon.com/aurora-dsql/latest/userguide/working-with-postgresql-compatibility.html).
|
||||
|
||||
## Live test
|
||||
|
||||
```sh
|
||||
ALCHEMY_PROFILE=testing bun test test/integ.test.ts
|
||||
```
|
||||
|
||||
## Destroy
|
||||
|
||||
```sh
|
||||
pnpm destroy --profile testing
|
||||
aws dsql get-cluster --region us-west-2 --identifier '<clusterId>'
|
||||
```
|
||||
|
||||
Destroy deletes the database data. Deletion is asynchronous; wait for `DELETED` or `ResourceNotFoundException`.
|
||||
@@ -0,0 +1,27 @@
|
||||
import * as Alchemy from "alchemy";
|
||||
import * as AWS from "alchemy/AWS";
|
||||
import * as Effect from "effect/Effect";
|
||||
import Api from "./src/Api.ts";
|
||||
import { BootstrapDatabase } from "./src/bootstrap.ts";
|
||||
import { Database } from "./src/database.ts";
|
||||
|
||||
export default Alchemy.Stack(
|
||||
"aws-dsql-drizzle",
|
||||
{ providers: AWS.providers(), state: Alchemy.localState() },
|
||||
Effect.gen(function* () {
|
||||
const cluster = yield* Database;
|
||||
const api = yield* Api;
|
||||
const schemaVersion = yield* BootstrapDatabase({
|
||||
endpoint: cluster.endpoint,
|
||||
roleArn: api.roleArn,
|
||||
version: "1",
|
||||
});
|
||||
return {
|
||||
url: api.functionUrl,
|
||||
functionName: api.functionName,
|
||||
roleName: api.roleName,
|
||||
clusterId: cluster.clusterId,
|
||||
schemaVersion,
|
||||
};
|
||||
}),
|
||||
);
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"version": "2.0",
|
||||
"routeKey": "$default",
|
||||
"rawPath": "/health",
|
||||
"rawQueryString": "",
|
||||
"headers": { "host": "example.invalid" },
|
||||
"requestContext": {
|
||||
"http": {
|
||||
"method": "GET",
|
||||
"path": "/health",
|
||||
"protocol": "HTTP/1.1",
|
||||
"sourceIp": "127.0.0.1",
|
||||
"userAgent": "aws-cli"
|
||||
}
|
||||
},
|
||||
"isBase64Encoded": false
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "aws-dsql-drizzle-example",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"license": "Apache-2.0",
|
||||
"scripts": {
|
||||
"build": "tsc -b",
|
||||
"deploy": "alchemy deploy",
|
||||
"destroy": "alchemy destroy",
|
||||
"test": "bun test"
|
||||
},
|
||||
"dependencies": {
|
||||
"@distilled.cloud/aws": "workspace:*",
|
||||
"@effect/platform-node": "catalog:",
|
||||
"@effect/sql-pg": "catalog:",
|
||||
"@types/pg": "catalog:",
|
||||
"alchemy": "workspace:*",
|
||||
"drizzle-orm": "catalog:",
|
||||
"effect": "catalog:",
|
||||
"pg": "catalog:"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
import * as AWS from "alchemy/AWS";
|
||||
import { eq, sql } from "drizzle-orm";
|
||||
import * as Duration from "effect/Duration";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Schema from "effect/Schema";
|
||||
import { HttpServerRequest } from "effect/http/HttpServerRequest";
|
||||
import * as HttpServerResponse from "effect/http/HttpServerResponse";
|
||||
import { connectDatabase } from "./client.ts";
|
||||
import { Todos } from "./schema.ts";
|
||||
|
||||
export default class Api extends AWS.Lambda.Function<Api>()(
|
||||
"Api",
|
||||
{
|
||||
main: import.meta.url,
|
||||
runtime: "nodejs22.x",
|
||||
functionUrl: { authType: "AWS_IAM" },
|
||||
timeout: Duration.seconds(30),
|
||||
build: { install: ["pg"] },
|
||||
},
|
||||
Effect.gen(function* () {
|
||||
const db = yield* connectDatabase;
|
||||
return {
|
||||
fetch: Effect.gen(function* () {
|
||||
const request = yield* HttpServerRequest;
|
||||
const url = new URL(request.originalUrl);
|
||||
if (request.method === "GET" && url.pathname === "/health") {
|
||||
const result = yield* db.execute(
|
||||
sql`SELECT current_user AS username`,
|
||||
);
|
||||
return yield* HttpServerResponse.json(result);
|
||||
}
|
||||
if (url.pathname === "/todos" && request.method === "GET") {
|
||||
return yield* HttpServerResponse.json(yield* db.select().from(Todos));
|
||||
}
|
||||
if (url.pathname === "/todos" && request.method === "POST") {
|
||||
const input = yield* request.json.pipe(
|
||||
Effect.flatMap(
|
||||
Schema.decodeUnknownEffect(
|
||||
Schema.Struct({
|
||||
id: Schema.String.check(Schema.isUUID()),
|
||||
text: Schema.NonEmptyString,
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
return yield* HttpServerResponse.json(
|
||||
yield* db.insert(Todos).values(input).returning(),
|
||||
{ status: 201 },
|
||||
);
|
||||
}
|
||||
if (url.pathname.startsWith("/todos/")) {
|
||||
const id = yield* Schema.decodeUnknownEffect(
|
||||
Schema.String.check(Schema.isUUID()),
|
||||
)(url.pathname.slice(7));
|
||||
if (request.method === "PATCH") {
|
||||
const input = yield* request.json.pipe(
|
||||
Effect.flatMap(
|
||||
Schema.decodeUnknownEffect(
|
||||
Schema.Struct({ done: Schema.Boolean }),
|
||||
),
|
||||
),
|
||||
);
|
||||
return yield* HttpServerResponse.json(
|
||||
yield* db
|
||||
.update(Todos)
|
||||
.set(input)
|
||||
.where(eq(Todos.id, id))
|
||||
.returning(),
|
||||
);
|
||||
}
|
||||
if (request.method === "DELETE") {
|
||||
yield* db.delete(Todos).where(eq(Todos.id, id));
|
||||
return HttpServerResponse.empty({ status: 204 });
|
||||
}
|
||||
}
|
||||
return HttpServerResponse.text("Not found", { status: 404 });
|
||||
}).pipe(
|
||||
Effect.catchTag("SchemaError", () =>
|
||||
Effect.succeed(
|
||||
HttpServerResponse.text("Invalid request", { status: 400 }),
|
||||
),
|
||||
),
|
||||
Effect.orDie,
|
||||
),
|
||||
};
|
||||
}).pipe(Effect.provide(AWS.DSQL.ConnectHttp)),
|
||||
) {}
|
||||
@@ -0,0 +1,58 @@
|
||||
import * as Presign from "@distilled.cloud/aws/Presign";
|
||||
import * as PgClient from "@effect/sql-pg/PgClient";
|
||||
import * as Alchemy from "alchemy";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Redacted from "effect/Redacted";
|
||||
|
||||
export const BootstrapDatabase = Alchemy.Action(
|
||||
"BootstrapDatabase",
|
||||
Effect.fn(function* (input: {
|
||||
endpoint: string;
|
||||
roleArn: string;
|
||||
version: string;
|
||||
}) {
|
||||
const token = yield* Presign.presignUrl({
|
||||
method: "GET",
|
||||
url: `https://${input.endpoint}/?Action=DbConnectAdmin`,
|
||||
service: "dsql",
|
||||
expiresIn: 900,
|
||||
});
|
||||
yield* Effect.gen(function* () {
|
||||
const sql = yield* PgClient.PgClient;
|
||||
// DSQL requires separate autocommit statements for catalog changes.
|
||||
yield* sql`CREATE SCHEMA IF NOT EXISTS app`;
|
||||
const roles =
|
||||
yield* sql`SELECT rolname FROM pg_roles WHERE rolname = 'app_user'`;
|
||||
if (roles.length === 0) {
|
||||
yield* sql`CREATE ROLE app_user WITH LOGIN`;
|
||||
}
|
||||
yield* sql`CREATE TABLE IF NOT EXISTS app.todos (
|
||||
id uuid PRIMARY KEY,
|
||||
text text NOT NULL,
|
||||
done boolean NOT NULL DEFAULT false,
|
||||
created_at timestamptz NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
)`;
|
||||
yield* sql`GRANT USAGE ON SCHEMA app TO app_user`;
|
||||
yield* sql`GRANT SELECT, INSERT, UPDATE, DELETE ON app.todos TO app_user`;
|
||||
const mappings = yield* sql`SELECT arn FROM sys.iam_pg_role_mappings
|
||||
WHERE pg_role_name = 'app_user' AND arn = ${input.roleArn}`;
|
||||
if (mappings.length === 0) {
|
||||
yield* sql.unsafe(
|
||||
`AWS IAM GRANT app_user TO '${input.roleArn.replaceAll("'", "''")}'`,
|
||||
);
|
||||
}
|
||||
}).pipe(
|
||||
Effect.provide(
|
||||
PgClient.layer({
|
||||
host: input.endpoint,
|
||||
port: 5432,
|
||||
database: "postgres",
|
||||
username: "admin",
|
||||
password: Redacted.make(token.slice("https://".length)),
|
||||
ssl: { rejectUnauthorized: true, servername: input.endpoint },
|
||||
}),
|
||||
),
|
||||
);
|
||||
return input.version;
|
||||
}),
|
||||
);
|
||||
@@ -0,0 +1,19 @@
|
||||
import * as AWS from "alchemy/AWS";
|
||||
import * as Drizzle from "alchemy/Drizzle/Postgres";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Redacted from "effect/Redacted";
|
||||
import { Database } from "./database.ts";
|
||||
|
||||
export const connectDatabase = Effect.gen(function* () {
|
||||
const cluster = yield* Database;
|
||||
const connect = yield* AWS.DSQL.Connect(cluster, { username: "app_user" });
|
||||
return yield* Drizzle.Postgres(
|
||||
connect.pipe(
|
||||
Effect.map((connection) => {
|
||||
const url = new URL(Redacted.value(connection.url));
|
||||
url.searchParams.set("sslmode", "verify-full");
|
||||
return Redacted.make(url.toString());
|
||||
}),
|
||||
),
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,5 @@
|
||||
import * as AWS from "alchemy/AWS";
|
||||
|
||||
export const Database = AWS.DSQL.Cluster("Database", {
|
||||
deletionProtectionEnabled: false,
|
||||
});
|
||||
@@ -0,0 +1,10 @@
|
||||
import { boolean, pgSchema, text, timestamp, uuid } from "drizzle-orm/pg-core";
|
||||
|
||||
export const Todos = pgSchema("app").table("todos", {
|
||||
id: uuid("id").primaryKey(),
|
||||
text: text("text").notNull(),
|
||||
done: boolean("done").notNull().default(false),
|
||||
createdAt: timestamp("created_at", { withTimezone: true })
|
||||
.notNull()
|
||||
.defaultNow(),
|
||||
});
|
||||
@@ -0,0 +1,147 @@
|
||||
import { Credentials } from "@distilled.cloud/aws/Credentials";
|
||||
import { sign } from "@distilled.cloud/aws/SigV4";
|
||||
import * as dsql from "@distilled.cloud/aws/dsql";
|
||||
import * as iam from "@distilled.cloud/aws/iam";
|
||||
import * as Alchemy from "alchemy";
|
||||
import * as AWS from "alchemy/AWS";
|
||||
import * as Test from "alchemy/Test/Bun";
|
||||
import * as Core from "alchemy/Test/Core";
|
||||
import { describe, expect } from "bun:test";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Redacted from "effect/Redacted";
|
||||
import * as HttpClient from "effect/http/HttpClient";
|
||||
import * as HttpClientRequest from "effect/http/HttpClientRequest";
|
||||
import Stack from "../alchemy.run.ts";
|
||||
|
||||
describe("Drizzle + Aurora DSQL", () => {
|
||||
const { test, beforeAll, afterAll, deploy, destroy } = Test.make({
|
||||
providers: AWS.providers(),
|
||||
state: Alchemy.localState(),
|
||||
profile: process.env.ALCHEMY_PROFILE,
|
||||
});
|
||||
let clusterId: string | undefined;
|
||||
const stack = beforeAll(
|
||||
Effect.gen(function* () {
|
||||
yield* destroy(Stack);
|
||||
const outputs = yield* deploy(Stack);
|
||||
clusterId = outputs.clusterId;
|
||||
yield* deploy(Stack);
|
||||
return outputs;
|
||||
}),
|
||||
{ timeout: 600_000 },
|
||||
);
|
||||
afterAll(
|
||||
Effect.gen(function* () {
|
||||
yield* destroy(Stack);
|
||||
if (clusterId) {
|
||||
const status = yield* Core.withProviders(
|
||||
dsql.getCluster({ identifier: clusterId }).pipe(
|
||||
Effect.map((cluster) => cluster.status),
|
||||
Effect.catchTag("ResourceNotFoundException", () =>
|
||||
Effect.succeed("NOT_FOUND"),
|
||||
),
|
||||
),
|
||||
{ providers: AWS.providers() },
|
||||
"aws-dsql-drizzle",
|
||||
);
|
||||
expect(["DELETING", "DELETED", "NOT_FOUND"]).toContain(status);
|
||||
}
|
||||
}),
|
||||
{ timeout: 600_000 },
|
||||
);
|
||||
|
||||
test.provider(
|
||||
"signed HTTP CRUD with a non-admin database role and verified TLS",
|
||||
() =>
|
||||
Effect.gen(function* () {
|
||||
const { url, roleName } = yield* stack;
|
||||
if (!url) return yield* Effect.fail(new Error("Missing Function URL"));
|
||||
const policies = yield* iam.listRolePolicies({ RoleName: roleName });
|
||||
const documents = yield* Effect.forEach(
|
||||
policies.PolicyNames,
|
||||
(PolicyName) =>
|
||||
iam
|
||||
.getRolePolicy({ RoleName: roleName, PolicyName })
|
||||
.pipe(
|
||||
Effect.map((policy) =>
|
||||
decodeURIComponent(policy.PolicyDocument),
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(documents.join("\n")).toContain('"dsql:DbConnect"');
|
||||
expect(documents.join("\n")).not.toContain("DbConnectAdmin");
|
||||
|
||||
const client = yield* HttpClient.HttpClient;
|
||||
const getCredentials = yield* Credentials;
|
||||
expect((yield* client.get(`${url}health`)).status).toBe(403);
|
||||
const request = Effect.fn(function* (
|
||||
method: "GET" | "POST" | "PATCH" | "DELETE",
|
||||
path: string,
|
||||
body?: object,
|
||||
) {
|
||||
const credentials = yield* getCredentials;
|
||||
const payload = body === undefined ? undefined : JSON.stringify(body);
|
||||
const signed = yield* sign({
|
||||
method,
|
||||
url: new URL(path, url).toString(),
|
||||
body: payload,
|
||||
service: "lambda",
|
||||
region: credentials.region,
|
||||
accessKeyId: Redacted.value(credentials.accessKeyId),
|
||||
secretAccessKey: credentials.secretAccessKey,
|
||||
sessionToken: credentials.sessionToken,
|
||||
});
|
||||
const base = HttpClientRequest.make(method)(signed.url).pipe(
|
||||
HttpClientRequest.setHeaders(signed.headers),
|
||||
);
|
||||
const response = yield* client.execute(
|
||||
payload === undefined
|
||||
? base
|
||||
: base.pipe(
|
||||
HttpClientRequest.bodyText(payload, "application/json"),
|
||||
),
|
||||
);
|
||||
return { status: response.status, body: yield* response.text };
|
||||
});
|
||||
const health = yield* request("GET", "/health");
|
||||
expect(health.status).toBe(200);
|
||||
expect(JSON.parse(health.body).rows).toEqual([
|
||||
{ username: "app_user" },
|
||||
]);
|
||||
const id = "aaaaaaaa-0000-4000-8000-000000000001";
|
||||
yield* request("DELETE", `/todos/${id}`);
|
||||
expect((yield* request("GET", "/todos")).body).toBe("[]");
|
||||
const created = yield* request("POST", "/todos", {
|
||||
id,
|
||||
text: "Ship DSQL guide",
|
||||
});
|
||||
expect(created.status).toBe(201);
|
||||
expect(JSON.parse(created.body)[0]).toMatchObject({
|
||||
id,
|
||||
text: "Ship DSQL guide",
|
||||
done: false,
|
||||
});
|
||||
const updated = yield* request("PATCH", `/todos/${id}`, { done: true });
|
||||
expect(updated.status).toBe(200);
|
||||
expect(JSON.parse(updated.body)[0].done).toBe(true);
|
||||
for (let i = 0; i < 3; i++) {
|
||||
const listed = yield* request("GET", "/todos");
|
||||
expect(listed.status).toBe(200);
|
||||
expect(JSON.parse(listed.body)).toHaveLength(1);
|
||||
expect(JSON.parse(listed.body)[0]).toMatchObject({
|
||||
id,
|
||||
text: "Ship DSQL guide",
|
||||
done: true,
|
||||
});
|
||||
}
|
||||
expect(
|
||||
(yield* request("POST", "/todos", { id: "invalid", text: "" }))
|
||||
.status,
|
||||
).toBe(400);
|
||||
expect((yield* request("GET", "/setup")).status).toBe(404);
|
||||
expect((yield* request("DELETE", `/todos/${id}`)).status).toBe(204);
|
||||
expect((yield* request("GET", "/todos")).body).toBe("[]");
|
||||
}),
|
||||
{ timeout: 120_000 },
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"include": ["alchemy.run.ts", "src/**/*.ts", "test/**/*.ts"],
|
||||
"compilerOptions": {
|
||||
"noEmit": true,
|
||||
"rootDir": ".",
|
||||
"module": "Preserve",
|
||||
"moduleResolution": "Bundler",
|
||||
"customConditions": ["bun"],
|
||||
"target": "ESNext"
|
||||
},
|
||||
"references": [{ "path": "../../packages/alchemy/tsconfig.json" }]
|
||||
}
|
||||
@@ -3,8 +3,8 @@ import { SQSQueueEventSource } from "alchemy/Server/SQSQueueEventSource";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Stream from "effect/Stream";
|
||||
import * as HttpServerRequest from "effect/unstable/http/HttpServerRequest";
|
||||
import * as HttpServerResponse from "effect/unstable/http/HttpServerResponse";
|
||||
import * as HttpServerRequest from "effect/http/HttpServerRequest";
|
||||
import * as HttpServerResponse from "effect/http/HttpServerResponse";
|
||||
import { Network, NetworkLive } from "./Network.ts";
|
||||
|
||||
export default class Server extends AWS.EC2.Instance<Server>()(
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import * as AWS from "alchemy/AWS";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import { HttpServerRequest } from "effect/unstable/http/HttpServerRequest";
|
||||
import * as HttpServerResponse from "effect/unstable/http/HttpServerResponse";
|
||||
import { HttpServerRequest } from "effect/http/HttpServerRequest";
|
||||
import * as HttpServerResponse from "effect/http/HttpServerResponse";
|
||||
import {
|
||||
OrdersCluster,
|
||||
OrdersIngress,
|
||||
|
||||
@@ -14,7 +14,7 @@ import * as Test from "alchemy/Test/Bun";
|
||||
import { expect } from "bun:test";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Schedule from "effect/Schedule";
|
||||
import * as HttpClient from "effect/unstable/http/HttpClient";
|
||||
import * as HttpClient from "effect/http/HttpClient";
|
||||
import Stack from "../alchemy.run.ts";
|
||||
|
||||
const { test, beforeAll, afterAll, deploy, destroy } = Test.make({
|
||||
|
||||
@@ -2,8 +2,8 @@ import * as AWS from "alchemy/AWS";
|
||||
import * as Kubernetes from "alchemy/Kubernetes";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import { HttpServerRequest } from "effect/unstable/http/HttpServerRequest";
|
||||
import * as HttpServerResponse from "effect/unstable/http/HttpServerResponse";
|
||||
import { HttpServerRequest } from "effect/http/HttpServerRequest";
|
||||
import * as HttpServerResponse from "effect/http/HttpServerResponse";
|
||||
import { EntriesTable, GuestbookCluster, GuestbookNamespace } from "./infra.ts";
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,8 +3,8 @@ import * as Effect from "effect/Effect";
|
||||
import * as FileSystem from "effect/FileSystem";
|
||||
import * as Path from "effect/Path";
|
||||
import * as Stream from "effect/Stream";
|
||||
import * as ChildProcess from "effect/unstable/process/ChildProcess";
|
||||
import * as ChildProcessSpawner from "effect/unstable/process/ChildProcessSpawner";
|
||||
import * as ChildProcess from "effect/process/ChildProcess";
|
||||
import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
|
||||
|
||||
const run = Effect.fn(function* (bin: string, args: string[], cwd?: string) {
|
||||
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Schema from "effect/Schema";
|
||||
import * as HttpServerResponse from "effect/unstable/http/HttpServerResponse";
|
||||
import * as HttpApi from "effect/unstable/httpapi/HttpApi";
|
||||
import * as HttpApiBuilder from "effect/unstable/httpapi/HttpApiBuilder";
|
||||
import * as HttpApiEndpoint from "effect/unstable/httpapi/HttpApiEndpoint";
|
||||
import * as HttpApiGroup from "effect/unstable/httpapi/HttpApiGroup";
|
||||
import * as HttpServerResponse from "effect/http/HttpServerResponse";
|
||||
import * as HttpApi from "effect/http-api/HttpApi";
|
||||
import * as HttpApiBuilder from "effect/http-api/HttpApiBuilder";
|
||||
import * as HttpApiEndpoint from "effect/http-api/HttpApiEndpoint";
|
||||
import * as HttpApiGroup from "effect/http-api/HttpApiGroup";
|
||||
import { Job, JobId } from "./Job.ts";
|
||||
import { JobNotifications, NotifyJobError } from "./JobNotifications.ts";
|
||||
import { GetJobError, JobStorage, PutJobError } from "./JobStorage.ts";
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import * as AWS from "alchemy/AWS";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Etag from "effect/unstable/http/Etag";
|
||||
import * as HttpPlatform from "effect/unstable/http/HttpPlatform";
|
||||
import * as HttpRouter from "effect/unstable/http/HttpRouter";
|
||||
import * as Etag from "effect/http/Etag";
|
||||
import * as HttpPlatform from "effect/http/HttpPlatform";
|
||||
import * as HttpRouter from "effect/http/HttpRouter";
|
||||
import { JobApiLive } from "./JobApi.ts";
|
||||
import { JobNotificationsSNS } from "./JobNotifications.ts";
|
||||
import { JobStorageDynamoDB } from "./JobStorage.ts";
|
||||
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
RpcGroup,
|
||||
RpcSerialization,
|
||||
RpcServer,
|
||||
} from "effect/unstable/rpc";
|
||||
} from "effect/rpc";
|
||||
import { Job, JobId } from "./Job.ts";
|
||||
import { JobNotifications } from "./JobNotifications.ts";
|
||||
import { JobStorage } from "./JobStorage.ts";
|
||||
|
||||
@@ -2,8 +2,8 @@ import * as AWS from "alchemy/AWS";
|
||||
import { Stack } from "alchemy/Stack";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import { HttpServerRequest } from "effect/unstable/http/HttpServerRequest";
|
||||
import * as HttpServerResponse from "effect/unstable/http/HttpServerResponse";
|
||||
import { HttpServerRequest } from "effect/http/HttpServerRequest";
|
||||
import * as HttpServerResponse from "effect/http/HttpServerResponse";
|
||||
import {
|
||||
JobNotifications,
|
||||
JobNotificationsSNS,
|
||||
|
||||
@@ -2,8 +2,8 @@ import * as AWS from "alchemy/AWS";
|
||||
import { Stack } from "alchemy/Stack";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import { HttpServerRequest } from "effect/unstable/http/HttpServerRequest";
|
||||
import * as HttpServerResponse from "effect/unstable/http/HttpServerResponse";
|
||||
import { HttpServerRequest } from "effect/http/HttpServerRequest";
|
||||
import * as HttpServerResponse from "effect/http/HttpServerResponse";
|
||||
import { Database, DatabaseAurora } from "./Database.ts";
|
||||
import { NetworkLive } from "./Network.ts";
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as AWS from "alchemy/AWS";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as HttpServerResponse from "effect/unstable/http/HttpServerResponse";
|
||||
import * as HttpServerResponse from "effect/http/HttpServerResponse";
|
||||
|
||||
const main = import.meta.url;
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
"alchemy-test": "workspace:*",
|
||||
"svelte": "catalog:",
|
||||
"tailwindcss": "catalog:",
|
||||
"typescript": "catalog:",
|
||||
"typescript": "catalog:typescript-classic",
|
||||
"vite": "catalog:"
|
||||
},
|
||||
"repository": {
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
node_modules
|
||||
.next
|
||||
dist
|
||||
.alchemy
|
||||
next-env.d.ts
|
||||
@@ -0,0 +1,49 @@
|
||||
# vinext on AWS
|
||||
|
||||
Deploy a vinext App Router application with `AWS.Website.Vinext`.
|
||||
Production uses a streaming Lambda behind CloudFront, with assets and the data cache in S3.
|
||||
|
||||
```typescript
|
||||
const site = yield* AWS.Website.Vinext("Web", {
|
||||
env: { GREETING: "Hello from vinext on AWS!" },
|
||||
});
|
||||
```
|
||||
|
||||
The example includes client hydration, Home/ISR navigation, an environment-aware
|
||||
`/api/hello?name=Alchemy` endpoint, ISR, and public assets.
|
||||
The Website provisions its S3 data-cache bucket automatically.
|
||||
Alchemy injects the cache adapter automatically. Keep ordinary `vinext()`
|
||||
configuration in Vite; configure deployment on `Website.Vinext`.
|
||||
|
||||
## Run locally
|
||||
|
||||
```sh
|
||||
bun install
|
||||
bun alchemy dev
|
||||
```
|
||||
|
||||
The Website runs native `vinext dev` with hot reload and creates no cloud
|
||||
resources. Apply `Alchemy.remote()` to deploy live during development.
|
||||
|
||||
## Deploy
|
||||
|
||||
Configure [AWS credentials](https://alchemy.run/aws/setup), then run:
|
||||
|
||||
```sh
|
||||
bun alchemy deploy
|
||||
```
|
||||
|
||||
Shared props are `rootDir`, `env`, `memo`, `assets`, `dev`, and `domain`.
|
||||
The integration package must be installed in the application; it is loaded
|
||||
at build time.
|
||||
|
||||
## Test and clean up
|
||||
|
||||
```sh
|
||||
bun test test/dev.test.ts
|
||||
ALCHEMY_PROFILE=testing bun test test/integ.test.ts
|
||||
bun alchemy destroy
|
||||
```
|
||||
|
||||
The live suite destroys its previous stack before deploying and cleans up
|
||||
afterward. See the [vinext guide](https://alchemy.run/aws/frontend/vinext).
|
||||
@@ -0,0 +1,36 @@
|
||||
import * as Alchemy from "alchemy";
|
||||
import * as AWS from "alchemy/AWS";
|
||||
import * as Effect from "effect/Effect";
|
||||
|
||||
export default Alchemy.Stack(
|
||||
"AwsWebsiteVinextExample",
|
||||
{
|
||||
providers: AWS.providers(),
|
||||
state: AWS.state(),
|
||||
},
|
||||
Effect.gen(function* () {
|
||||
const site = yield* AWS.Website.Vinext("Vinext", {
|
||||
// Only hash the files that affect the build, so unchanged sources
|
||||
// skip the vinext build (and the deploy) entirely.
|
||||
memo: {
|
||||
lockfile: true,
|
||||
include: [
|
||||
"app/**",
|
||||
"public/**",
|
||||
"package.json",
|
||||
"vite.config.ts",
|
||||
"tsconfig.json",
|
||||
],
|
||||
},
|
||||
forceDestroy: true,
|
||||
env: {
|
||||
GREETING: "Hello from vinext on AWS!",
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
url: site.url,
|
||||
cacheBucketName: site.cacheBucket?.bucketName,
|
||||
};
|
||||
}),
|
||||
);
|
||||
@@ -0,0 +1,4 @@
|
||||
export function GET(request: Request) {
|
||||
const name = new URL(request.url).searchParams.get("name") ?? "world";
|
||||
return Response.json({ name, greeting: process.env.GREETING ?? "hello" });
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// A React component styled with Tailwind utility classes.
|
||||
export function Card({ title, body }: { title: string; body: string }) {
|
||||
return (
|
||||
<div className="mt-6 max-w-md rounded-xl border border-slate-200 bg-white p-6 shadow-sm">
|
||||
<h2 className="text-lg font-semibold">{title}</h2>
|
||||
<p className="mt-2 text-slate-600">{body}</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
|
||||
export function Counter() {
|
||||
const [count, setCount] = useState(0);
|
||||
const [greeting, setGreeting] = useState("");
|
||||
|
||||
async function loadGreeting() {
|
||||
try {
|
||||
const response = await fetch("/api/hello?name=browser");
|
||||
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
||||
const body = (await response.json()) as { greeting: string };
|
||||
setGreeting(body.greeting);
|
||||
} catch {
|
||||
setGreeting("Could not load the greeting. Try again.");
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<section className="mt-4 flex flex-col gap-2">
|
||||
<button type="button" onClick={() => setCount((value) => value + 1)}>
|
||||
count: {count}
|
||||
</button>
|
||||
<button type="button" onClick={loadGreeting}>
|
||||
Load greeting
|
||||
</button>
|
||||
<p role="status">{greeting}</p>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
@import "tailwindcss";
|
||||
@@ -0,0 +1,13 @@
|
||||
export const revalidate = 60;
|
||||
|
||||
export default function IsrPage() {
|
||||
return (
|
||||
<main>
|
||||
<h1 className="text-3xl font-bold">ISR</h1>
|
||||
<p className="mt-4 text-slate-600">
|
||||
Rendered at {new Date().toISOString()} (revalidate 60s). On AWS this is
|
||||
stored in S3; locally it stays in memory.
|
||||
</p>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import "./globals.css";
|
||||
import Link from "next/link";
|
||||
|
||||
export const metadata = {
|
||||
title: "vinext on AWS",
|
||||
};
|
||||
|
||||
export default function RootLayout({
|
||||
children,
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<html lang="en">
|
||||
<body className="bg-slate-50 p-8 text-slate-900">
|
||||
<nav className="mb-6 flex gap-4">
|
||||
<Link href="/">Home</Link>
|
||||
<Link href="/isr">ISR</Link>
|
||||
</nav>
|
||||
{children}
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { Counter } from "./components/Counter.tsx";
|
||||
import { Card } from "./components/Card.tsx";
|
||||
|
||||
export default function Home() {
|
||||
return (
|
||||
<main>
|
||||
<h1 className="text-3xl font-bold">Hello from vinext on AWS!</h1>
|
||||
<Card
|
||||
title="Styled with Tailwind CSS"
|
||||
body="This card is a React component styled with Tailwind utilities."
|
||||
/>
|
||||
<Counter />
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
{
|
||||
"name": "aws-website-vinext",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "alchemy dev",
|
||||
"deploy": "alchemy deploy",
|
||||
"destroy": "alchemy destroy",
|
||||
"test": "bun test"
|
||||
},
|
||||
"dependencies": {
|
||||
"alchemy": "workspace:*",
|
||||
"effect": "catalog:",
|
||||
"react": "catalog:",
|
||||
"react-dom": "catalog:",
|
||||
"react-server-dom-webpack": "catalog:",
|
||||
"vinext": "^1.0.0-beta.10"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@alchemy.run/frontend-frameworks": "workspace:*",
|
||||
"@distilled.cloud/aws": "workspace:*",
|
||||
"@effect/platform-node": "catalog:",
|
||||
"@tailwindcss/vite": "catalog:",
|
||||
"@types/react": "catalog:",
|
||||
"@types/react-dom": "catalog:",
|
||||
"@vitejs/plugin-react": "catalog:",
|
||||
"@vitejs/plugin-rsc": "^0.5.34",
|
||||
"alchemy": "workspace:*",
|
||||
"alchemy-test": "workspace:*",
|
||||
"effect": "catalog:",
|
||||
"tailwindcss": "catalog:",
|
||||
"typescript": "catalog:",
|
||||
"vite": "catalog:"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=22"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/alchemy-run/alchemy.git",
|
||||
"directory": "examples/aws-website-vinext"
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
@@ -0,0 +1,2 @@
|
||||
User-agent: *
|
||||
Allow: /
|
||||
@@ -0,0 +1,79 @@
|
||||
import * as Cloud from "alchemy/AWS";
|
||||
import * as Test from "alchemy/Test/Bun";
|
||||
import { expect } from "bun:test";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as FileSystem from "effect/FileSystem";
|
||||
import * as Path from "effect/Path";
|
||||
import * as Schedule from "effect/Schedule";
|
||||
|
||||
const { test } = Test.make({ providers: Cloud.providers(), dev: true });
|
||||
|
||||
test.provider(
|
||||
"native vinext development serves routes, environment, and hot reload",
|
||||
(stack) =>
|
||||
Effect.gen(function* () {
|
||||
yield* stack.destroy();
|
||||
const fs = yield* FileSystem.FileSystem;
|
||||
const path = yield* Path.Path;
|
||||
const rootDir = yield* path.fromFileUrl(new URL("../", import.meta.url));
|
||||
const { site } = yield* stack.deploy(
|
||||
Effect.gen(function* () {
|
||||
return {
|
||||
site: yield* Cloud.Website.Vinext("Web", {
|
||||
rootDir,
|
||||
env: { GREETING: "Hello from vinext on AWS!" },
|
||||
}),
|
||||
};
|
||||
}),
|
||||
);
|
||||
expect(site.url).toMatch(/^http:\/\/(localhost|127\.0\.0\.1):\d+/);
|
||||
const url = String(site.url).replace(/\/+$/, "");
|
||||
const home = yield* Test.getWhenReady(url).pipe(
|
||||
Effect.flatMap((response) => response.text),
|
||||
);
|
||||
expect(home).toContain("Hello from vinext on AWS!");
|
||||
const api = yield* Test.getWhenReady(`${url}/api/hello?name=Alchemy`);
|
||||
expect(yield* api.json).toEqual({
|
||||
name: "Alchemy",
|
||||
greeting: "Hello from vinext on AWS!",
|
||||
});
|
||||
const robots = yield* Test.getWhenReady(`${url}/robots.txt`);
|
||||
expect(yield* robots.text).toContain("User-agent:");
|
||||
const isr = yield* Test.getWhenReady(`${url}/isr`);
|
||||
expect(yield* isr.text).toContain("ISR");
|
||||
const page = path.join(rootDir, "app/page.tsx");
|
||||
const source = yield* fs.readFileString(page);
|
||||
const marker = "Updated by the vinext development test";
|
||||
yield* Effect.acquireUseRelease(
|
||||
fs.writeFileString(
|
||||
page,
|
||||
source.replace("Hello from vinext on AWS!", marker),
|
||||
),
|
||||
() =>
|
||||
Test.getWhenReady(url).pipe(
|
||||
Effect.flatMap((response) => response.text),
|
||||
Effect.repeat({
|
||||
schedule: Schedule.spaced("500 millis"),
|
||||
times: 20,
|
||||
until: (body) => body.includes(marker),
|
||||
}),
|
||||
Effect.tap((body) =>
|
||||
Effect.sync(() => expect(body).toContain(marker)),
|
||||
),
|
||||
),
|
||||
() => fs.writeFileString(page, source).pipe(Effect.orDie),
|
||||
);
|
||||
const restored = yield* Test.getWhenReady(url).pipe(
|
||||
Effect.flatMap((response) => response.text),
|
||||
Effect.repeat({
|
||||
schedule: Schedule.spaced("500 millis"),
|
||||
times: 20,
|
||||
until: (body) => !body.includes(marker),
|
||||
}),
|
||||
);
|
||||
expect(restored).toContain("Hello from vinext on AWS!");
|
||||
expect(restored).not.toContain(marker);
|
||||
yield* stack.destroy();
|
||||
}),
|
||||
{ timeout: 120_000 },
|
||||
);
|
||||
@@ -0,0 +1,143 @@
|
||||
import * as S3 from "@distilled.cloud/aws/s3";
|
||||
import * as Alchemy from "alchemy";
|
||||
import * as AWS from "alchemy/AWS";
|
||||
import * as Test from "alchemy/Test/Bun";
|
||||
import { expect } from "bun:test";
|
||||
import * as Console from "effect/Console";
|
||||
import * as Data from "effect/Data";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Schedule from "effect/Schedule";
|
||||
import Stack from "../alchemy.run.ts";
|
||||
|
||||
const { getWhenReady } = Test;
|
||||
|
||||
class AssetNotReady extends Data.TaggedError("AssetNotReady")<{
|
||||
body: string;
|
||||
}> {}
|
||||
|
||||
const getBodyWhenReady = (url: string, expected: string) =>
|
||||
Effect.gen(function* () {
|
||||
const res = yield* getWhenReady(url);
|
||||
expect(res.status).toBe(200);
|
||||
const body = yield* res.text;
|
||||
if (!body.includes(expected)) {
|
||||
return yield* Effect.fail(new AssetNotReady({ body }));
|
||||
}
|
||||
return body;
|
||||
}).pipe(
|
||||
Effect.retry({
|
||||
while: (error) => error instanceof AssetNotReady,
|
||||
schedule: Schedule.min([
|
||||
Schedule.exponential("500 millis"),
|
||||
Schedule.spaced("3 seconds"),
|
||||
]),
|
||||
times: 10,
|
||||
}),
|
||||
);
|
||||
|
||||
const { test, beforeAll, afterAll, deploy, destroy } = Test.make({
|
||||
profile: process.env.ALCHEMY_PROFILE,
|
||||
providers: AWS.providers(),
|
||||
state: AWS.state(),
|
||||
});
|
||||
|
||||
// Pre-deploy cleanup must not close the suite's shared runtime scope.
|
||||
const stack = beforeAll(
|
||||
Effect.sync(Test.defaultStage).pipe(
|
||||
Effect.flatMap((stage) => Alchemy.destroy({ stack: Stack, stage })),
|
||||
Effect.andThen(deploy(Stack)),
|
||||
Effect.tap(Console.log),
|
||||
),
|
||||
{
|
||||
timeout: 1_200_000,
|
||||
},
|
||||
);
|
||||
afterAll.skipIf(!!process.env.NO_DESTROY)(destroy(Stack), {
|
||||
timeout: 1_200_000,
|
||||
});
|
||||
|
||||
const base = Effect.map(stack, ({ url }) => {
|
||||
if (!url) throw new Error("expected the site to expose a CloudFront url");
|
||||
return String(url).replace(/\/+$/, "");
|
||||
});
|
||||
|
||||
test(
|
||||
"deploys and exposes a url",
|
||||
Effect.gen(function* () {
|
||||
const { url } = yield* stack;
|
||||
expect(url).toBeString();
|
||||
}),
|
||||
{ timeout: 180_000 },
|
||||
);
|
||||
|
||||
test(
|
||||
"serves the home page",
|
||||
Effect.gen(function* () {
|
||||
const url = yield* base;
|
||||
const html = yield* getBodyWhenReady(url, "Hello from vinext on AWS!");
|
||||
expect(html).toContain("vinext on AWS");
|
||||
}),
|
||||
{ timeout: 180_000 },
|
||||
);
|
||||
|
||||
test(
|
||||
"serves the ISR page",
|
||||
Effect.gen(function* () {
|
||||
const url = yield* base;
|
||||
const html = yield* getBodyWhenReady(`${url}/isr`, "ISR");
|
||||
expect(html).toContain("revalidate 60s");
|
||||
}),
|
||||
{ timeout: 180_000 },
|
||||
);
|
||||
|
||||
test.provider(
|
||||
"persists ISR entries in the S3 cache",
|
||||
() =>
|
||||
Effect.gen(function* () {
|
||||
const { cacheBucketName } = yield* stack;
|
||||
if (!cacheBucketName) {
|
||||
throw new Error("expected the site to expose its ISR cache bucket");
|
||||
}
|
||||
const url = yield* base;
|
||||
yield* getBodyWhenReady(`${url}/isr`, "ISR");
|
||||
const objects = yield* S3.listObjectsV2({
|
||||
Bucket: cacheBucketName,
|
||||
Prefix: "vinext-cache/",
|
||||
}).pipe(
|
||||
Effect.repeat({
|
||||
schedule: Schedule.spaced("1 second"),
|
||||
times: 10,
|
||||
until: (result) => (result.Contents?.length ?? 0) > 0,
|
||||
}),
|
||||
);
|
||||
expect(
|
||||
objects.Contents?.some((object) => object.Key?.includes("isr")),
|
||||
).toBe(true);
|
||||
}),
|
||||
{ timeout: 60_000 },
|
||||
);
|
||||
|
||||
test(
|
||||
"serves the dynamic API route",
|
||||
Effect.gen(function* () {
|
||||
const url = yield* base;
|
||||
const res = yield* getWhenReady(`${url}/api/hello?name=Alchemy`);
|
||||
expect(res.status).toBe(200);
|
||||
const body = yield* res.json;
|
||||
expect(body).toEqual({
|
||||
name: "Alchemy",
|
||||
greeting: "Hello from vinext on AWS!",
|
||||
});
|
||||
}),
|
||||
{ timeout: 180_000 },
|
||||
);
|
||||
|
||||
test(
|
||||
"serves a static asset from public/",
|
||||
Effect.gen(function* () {
|
||||
const url = yield* base;
|
||||
const body = yield* getBodyWhenReady(`${url}/robots.txt`, "User-agent: *");
|
||||
expect(body).toContain("User-agent: *");
|
||||
}),
|
||||
{ timeout: 180_000 },
|
||||
);
|
||||
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ESNext",
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "bundler",
|
||||
"lib": ["ESNext", "DOM", "DOM.Iterable"],
|
||||
"jsx": "react-jsx",
|
||||
"strict": true,
|
||||
"noEmit": true,
|
||||
"skipLibCheck": true,
|
||||
"isolatedModules": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"allowImportingTsExtensions": true,
|
||||
"types": ["bun", "vinext/types"]
|
||||
},
|
||||
"include": ["alchemy.run.ts", "vite.config.ts", "app", "test"],
|
||||
"references": [
|
||||
{
|
||||
"path": "../../packages/alchemy"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import tailwindcss from "@tailwindcss/vite";
|
||||
import { defineConfig } from "vite";
|
||||
import vinext from "vinext";
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [vinext({ prerender: true }), tailwindcss()],
|
||||
});
|
||||
@@ -13,5 +13,6 @@
|
||||
"verbatimModuleSyntax": true,
|
||||
"allowImportingTsExtensions": true
|
||||
},
|
||||
"include": ["alchemy.run.ts", "vite.config.ts", "src", "test"]
|
||||
"include": ["alchemy.run.ts", "vite.config.ts", "src", "test"],
|
||||
"references": [{ "path": "../../packages/alchemy" }]
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as FileSystem from "effect/FileSystem";
|
||||
import * as Stream from "effect/Stream";
|
||||
import * as ChildProcess from "effect/unstable/process/ChildProcess";
|
||||
import { ChildProcessSpawner } from "effect/unstable/process/ChildProcessSpawner";
|
||||
import * as ChildProcess from "effect/process/ChildProcess";
|
||||
import { ChildProcessSpawner } from "effect/process/ChildProcessSpawner";
|
||||
|
||||
import * as Cloudflare from "alchemy/Cloudflare";
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import * as Cloudflare from "alchemy/Cloudflare";
|
||||
import * as Github from "alchemy/GitHub";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as HttpServerResponse from "effect/unstable/http/HttpServerResponse";
|
||||
import * as HttpServerResponse from "effect/http/HttpServerResponse";
|
||||
import { ReleaseVersion } from "./ReleaseVersion.ts";
|
||||
|
||||
export default Cloudflare.Worker(
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as S from "effect/Schema";
|
||||
import { HttpClientRequest } from "effect/unstable/http";
|
||||
import { HttpClientRequest } from "effect/http";
|
||||
|
||||
import * as AI from "alchemy/AI";
|
||||
import * as Cloudflare from "alchemy/Cloudflare";
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
GITHUB_ENABLED=false
|
||||
GITHUB_CLIENT_ID=replace-with-your-github-oauth-client-id
|
||||
GITHUB_CLIENT_SECRET=replace-with-your-github-oauth-client-secret
|
||||
@@ -0,0 +1,5 @@
|
||||
/public/ui.js
|
||||
*.map
|
||||
.env
|
||||
node_modules/
|
||||
.alchemy/
|
||||
@@ -0,0 +1,71 @@
|
||||
# Cloudflare Better Auth
|
||||
|
||||
Executable companion to the [six-part Better Auth tutorial](https://alchemy.run/better-auth/tutorial/part-1).
|
||||
|
||||
## Run locally
|
||||
|
||||
From the repository root:
|
||||
|
||||
```sh
|
||||
pnpm install
|
||||
cd examples/cloudflare-better-auth
|
||||
bun run dev
|
||||
```
|
||||
|
||||
Use a [configured Cloudflare profile](https://alchemy.run/cloudflare/setup). Alchemy chooses an available port and prints the URL; the local Worker and D1 run without provisioning cloud resources.
|
||||
|
||||
Open that URL, create an account, and sign out and back in. The page displays the current user and the protected API response without exposing session tokens.
|
||||
|
||||
## Verify the HTTP flow
|
||||
|
||||
In another terminal in this example directory, paste the printed URL after `read` and press Enter:
|
||||
|
||||
```sh
|
||||
read -r BETTER_AUTH_TEST_URL
|
||||
export BETTER_AUTH_TEST_URL
|
||||
timeout 60 bun test
|
||||
```
|
||||
|
||||
The test creates a disposable account and checks cookies, sessions, public access, and sign-out rejection. Use a disposable database rather than production.
|
||||
|
||||
## Enable GitHub
|
||||
|
||||
```sh
|
||||
cp .env.example .env
|
||||
```
|
||||
|
||||
Replace the dummy credentials with your GitHub OAuth application's values and enable the provider:
|
||||
|
||||
```dotenv
|
||||
GITHUB_ENABLED=true
|
||||
GITHUB_CLIENT_ID=your-oauth-client-id
|
||||
GITHUB_CLIENT_SECRET=your-oauth-client-secret
|
||||
```
|
||||
|
||||
Use the running application's origin to construct the registered callback:
|
||||
|
||||
```sh
|
||||
printf '%s/api/auth/callback/github\n' "$BETTER_AUTH_TEST_URL"
|
||||
```
|
||||
|
||||
Restart the dev command after configuration changes and check its printed URL. Update the registered callback if that URL changed; no fixed local port is required.
|
||||
|
||||
The page shows the GitHub button only when enabled. The public provider endpoint exposes that flag, never credentials.
|
||||
|
||||
## Deploy
|
||||
|
||||
```sh
|
||||
bun run deploy --stage production
|
||||
```
|
||||
|
||||
Use separate production OAuth credentials and register the deployed callback URL. Optionally set `AUTH_BASE_URL` to your production origin; leave it unset locally to use the incoming request's origin.
|
||||
|
||||
Alchemy binds the database, migrates the schema, and preserves the generated signing secret through stack state. Keep that state for later deployments.
|
||||
|
||||
## Remove the deployment
|
||||
|
||||
```sh
|
||||
bun run destroy --stage production
|
||||
```
|
||||
|
||||
Use the exact stage and profile of the deployment you intend to remove. The generated browser bundle in `public/ui.js` is ignored by Git.
|
||||
@@ -0,0 +1,16 @@
|
||||
import * as Alchemy from "alchemy";
|
||||
import * as Cloudflare from "alchemy/Cloudflare";
|
||||
import * as Effect from "effect/Effect";
|
||||
import AuthApi from "./src/worker.ts";
|
||||
|
||||
export default Alchemy.Stack(
|
||||
"BetterAuthTutorial",
|
||||
{
|
||||
providers: Cloudflare.providers(),
|
||||
state: Alchemy.localState(),
|
||||
},
|
||||
Effect.gen(function* () {
|
||||
const worker = yield* AuthApi;
|
||||
return { url: worker.url.as<string>() };
|
||||
}),
|
||||
);
|
||||
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"name": "cloudflare-better-auth",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build:client": "bun build src/ui.ts --target browser --outdir public",
|
||||
"dev": "bun run build:client && alchemy dev",
|
||||
"deploy": "bun run build:client && alchemy deploy",
|
||||
"destroy": "alchemy destroy",
|
||||
"test": "bun test"
|
||||
},
|
||||
"dependencies": {
|
||||
"@alchemy.run/better-auth": "workspace:*",
|
||||
"alchemy": "workspace:*",
|
||||
"better-auth": "catalog:",
|
||||
"effect": "catalog:",
|
||||
"kysely": "catalog:"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/bun": "catalog:",
|
||||
"typescript": "catalog:"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>Better Auth on Cloudflare</title>
|
||||
<style>
|
||||
body {
|
||||
max-width: 44rem;
|
||||
margin: 3rem auto;
|
||||
padding: 0 1rem;
|
||||
font:
|
||||
1rem/1.5 system-ui,
|
||||
sans-serif;
|
||||
}
|
||||
label {
|
||||
display: block;
|
||||
margin-top: 1rem;
|
||||
}
|
||||
input {
|
||||
display: block;
|
||||
box-sizing: border-box;
|
||||
width: 100%;
|
||||
padding: 0.5rem;
|
||||
}
|
||||
button {
|
||||
margin: 1rem 0.5rem 0 0;
|
||||
padding: 0.5rem 0.75rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
output {
|
||||
display: block;
|
||||
margin-top: 1rem;
|
||||
}
|
||||
pre {
|
||||
padding: 1rem;
|
||||
background: #f2f4f6;
|
||||
overflow: auto;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Better Auth on Cloudflare</h1>
|
||||
<p>A same-origin client, an Effect HTTP API, and D1-backed sessions.</p>
|
||||
<form id="auth-form">
|
||||
<label for="name">Name (sign up only)</label>
|
||||
<input id="name" name="name" autocomplete="name" />
|
||||
<label for="email">Email</label>
|
||||
<input
|
||||
id="email"
|
||||
name="email"
|
||||
type="email"
|
||||
autocomplete="username"
|
||||
required
|
||||
/>
|
||||
<label for="password">Password (at least 8 characters)</label>
|
||||
<input
|
||||
id="password"
|
||||
name="password"
|
||||
type="password"
|
||||
autocomplete="current-password"
|
||||
minlength="8"
|
||||
required
|
||||
/>
|
||||
<button id="sign-up" type="button">Sign up</button>
|
||||
<button id="sign-in" type="button">Sign in</button>
|
||||
<button id="sign-out" type="button">Sign out</button>
|
||||
<button id="refresh" type="button">Refresh session</button>
|
||||
</form>
|
||||
<div id="providers"></div>
|
||||
<output id="status" role="status" aria-live="polite">Loading…</output>
|
||||
<h2>Session</h2>
|
||||
<pre id="session">Not loaded</pre>
|
||||
<h2>GET /api/me</h2>
|
||||
<pre id="me">Not loaded</pre>
|
||||
<script type="module" src="/ui.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,21 @@
|
||||
import * as Schema from "effect/Schema";
|
||||
import * as HttpApi from "effect/http-api/HttpApi";
|
||||
import * as HttpApiEndpoint from "effect/http-api/HttpApiEndpoint";
|
||||
import * as HttpApiGroup from "effect/http-api/HttpApiGroup";
|
||||
import { User } from "./current-user.ts";
|
||||
import { Authentication } from "./middleware.ts";
|
||||
|
||||
export class Public extends HttpApiGroup.make("public").add(
|
||||
HttpApiEndpoint.get("health", "/api/health", {
|
||||
success: Schema.Struct({ ok: Schema.Literal(true) }),
|
||||
}),
|
||||
HttpApiEndpoint.get("providers", "/api/providers", {
|
||||
success: Schema.Struct({ github: Schema.Boolean }),
|
||||
}),
|
||||
) {}
|
||||
|
||||
export class Private extends HttpApiGroup.make("private")
|
||||
.add(HttpApiEndpoint.get("me", "/api/me", { success: User }))
|
||||
.middleware(Authentication) {}
|
||||
|
||||
export class Api extends HttpApi.make("app").add(Public, Private) {}
|
||||
@@ -0,0 +1,36 @@
|
||||
import { BetterAuth } from "@alchemy.run/better-auth";
|
||||
import * as Config from "effect/Config";
|
||||
import * as Context from "effect/Context";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Option from "effect/Option";
|
||||
import * as Redacted from "effect/Redacted";
|
||||
|
||||
export const makeAuth = Effect.gen(function* () {
|
||||
const baseURL = yield* Config.String("AUTH_BASE_URL").pipe(Config.option);
|
||||
const githubEnabled = yield* Config.Boolean("GITHUB_ENABLED").pipe(
|
||||
Config.withDefault(false),
|
||||
);
|
||||
const github = githubEnabled
|
||||
? {
|
||||
clientId: yield* Config.String("GITHUB_CLIENT_ID"),
|
||||
clientSecret: Redacted.value(
|
||||
yield* Config.Redacted("GITHUB_CLIENT_SECRET"),
|
||||
),
|
||||
}
|
||||
: undefined;
|
||||
|
||||
return yield* BetterAuth({
|
||||
basePath: "/api/auth",
|
||||
emailAndPassword: { enabled: true },
|
||||
baseURL: Option.getOrUndefined(baseURL),
|
||||
socialProviders: github ? { github } : {},
|
||||
});
|
||||
});
|
||||
|
||||
export class Auth extends Context.Service<
|
||||
Auth,
|
||||
Effect.Success<typeof makeAuth>
|
||||
>()("app/Auth") {
|
||||
static readonly layer = Layer.effect(Auth, makeAuth);
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
import { createAuthClient } from "better-auth/client";
|
||||
|
||||
export const authClient = createAuthClient();
|
||||
@@ -0,0 +1,13 @@
|
||||
import * as Context from "effect/Context";
|
||||
import * as Schema from "effect/Schema";
|
||||
|
||||
export const User = Schema.Struct({
|
||||
id: Schema.String,
|
||||
name: Schema.String,
|
||||
email: Schema.String,
|
||||
});
|
||||
|
||||
export class CurrentUser extends Context.Service<
|
||||
CurrentUser,
|
||||
typeof User.Type
|
||||
>()("app/CurrentUser") {}
|
||||
@@ -0,0 +1,3 @@
|
||||
import * as Cloudflare from "alchemy/Cloudflare";
|
||||
|
||||
export const AuthDb = Cloudflare.D1.Database("AuthDb");
|
||||
@@ -0,0 +1,33 @@
|
||||
import * as Http from "alchemy/Http";
|
||||
import * as Config from "effect/Config";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as HttpApiBuilder from "effect/http-api/HttpApiBuilder";
|
||||
import { Api } from "./api.ts";
|
||||
import { CurrentUser } from "./current-user.ts";
|
||||
import { Authentication } from "./middleware.ts";
|
||||
|
||||
export const PublicLive = HttpApiBuilder.group(Api, "public", (handlers) =>
|
||||
Effect.gen(function* () {
|
||||
const github = yield* Config.Boolean("GITHUB_ENABLED").pipe(
|
||||
Config.withDefault(false),
|
||||
);
|
||||
return handlers
|
||||
.handle("health", () => Effect.succeed({ ok: true as const }))
|
||||
.handle("providers", () => Effect.succeed({ github }));
|
||||
}),
|
||||
);
|
||||
|
||||
export const PrivateLive = HttpApiBuilder.group(Api, "private", (handlers) =>
|
||||
handlers.handle("me", () =>
|
||||
Effect.gen(function* () {
|
||||
return yield* CurrentUser;
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
export const HttpLive = HttpApiBuilder.layer(Api).pipe(
|
||||
Layer.provide([PublicLive, PrivateLive]),
|
||||
Layer.provide(Authentication.layer),
|
||||
Layer.provide(Http.Platform),
|
||||
);
|
||||
@@ -0,0 +1,51 @@
|
||||
import { RuntimeContext } from "alchemy";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Schema from "effect/Schema";
|
||||
import * as HttpApiMiddleware from "effect/http-api/HttpApiMiddleware";
|
||||
import { Auth } from "./auth.ts";
|
||||
import { CurrentUser } from "./current-user.ts";
|
||||
|
||||
export class Unauthorized extends Schema.TaggedError<Unauthorized>()(
|
||||
"Unauthorized",
|
||||
{},
|
||||
{ httpApiStatus: 401 },
|
||||
) {}
|
||||
|
||||
export class AuthenticationUnavailable extends Schema.TaggedError<AuthenticationUnavailable>()(
|
||||
"AuthenticationUnavailable",
|
||||
{},
|
||||
{ httpApiStatus: 503 },
|
||||
) {}
|
||||
|
||||
export class Authentication extends HttpApiMiddleware.Service<
|
||||
Authentication,
|
||||
{ provides: CurrentUser }
|
||||
>()("app/Authentication", {
|
||||
error: [Unauthorized, AuthenticationUnavailable],
|
||||
}) {
|
||||
static readonly layer = Layer.effect(
|
||||
Authentication,
|
||||
Effect.gen(function* () {
|
||||
const auth = yield* Auth;
|
||||
return (httpEffect) =>
|
||||
Effect.gen(function* () {
|
||||
const session = yield* auth.getSession().pipe(
|
||||
Effect.mapError(() => new AuthenticationUnavailable()),
|
||||
Effect.catchDefect(() =>
|
||||
Effect.fail(new AuthenticationUnavailable()),
|
||||
),
|
||||
);
|
||||
if (session === null) return yield* new Unauthorized();
|
||||
return yield* Effect.provideService(
|
||||
httpEffect,
|
||||
CurrentUser,
|
||||
session.user,
|
||||
);
|
||||
}).pipe(
|
||||
// HttpApi does not carry Alchemy's runtime marker; the Worker owns request scope.
|
||||
Effect.provide(RuntimeContext.phantom),
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
import { authClient } from "./client.ts";
|
||||
|
||||
const form = document.querySelector<HTMLFormElement>("#auth-form")!;
|
||||
const status = document.querySelector<HTMLOutputElement>("#status")!;
|
||||
const sessionOutput = document.querySelector<HTMLPreElement>("#session")!;
|
||||
const meOutput = document.querySelector<HTMLPreElement>("#me")!;
|
||||
const providers = document.querySelector<HTMLDivElement>("#providers")!;
|
||||
const name = document.querySelector<HTMLInputElement>("#name")!;
|
||||
const email = document.querySelector<HTMLInputElement>("#email")!;
|
||||
const password = document.querySelector<HTMLInputElement>("#password")!;
|
||||
|
||||
async function refresh() {
|
||||
const session = await authClient.getSession();
|
||||
if (session.error)
|
||||
throw new Error(session.error.message ?? "Session lookup failed");
|
||||
sessionOutput.textContent = JSON.stringify(
|
||||
session.data
|
||||
? { user: session.data.user, expiresAt: session.data.session.expiresAt }
|
||||
: null,
|
||||
null,
|
||||
2,
|
||||
);
|
||||
const response = await fetch("/api/me");
|
||||
const body = await response.json();
|
||||
meOutput.textContent = `${response.status}\n${JSON.stringify(body, null, 2)}`;
|
||||
if (!response.ok && response.status !== 401) {
|
||||
throw new Error(`The private API returned ${response.status}`);
|
||||
}
|
||||
}
|
||||
|
||||
async function run(action: () => Promise<void>) {
|
||||
const buttons = document.querySelectorAll<HTMLButtonElement>("button");
|
||||
buttons.forEach((button) => {
|
||||
button.disabled = true;
|
||||
});
|
||||
status.textContent = "Working…";
|
||||
try {
|
||||
await action();
|
||||
status.textContent = "Ready";
|
||||
} catch (error) {
|
||||
status.textContent = error instanceof Error ? error.message : String(error);
|
||||
} finally {
|
||||
buttons.forEach((button) => {
|
||||
button.disabled = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
form.addEventListener("submit", (event) => event.preventDefault());
|
||||
|
||||
document.querySelector("#sign-up")!.addEventListener("click", () => {
|
||||
if (!form.reportValidity()) return;
|
||||
if (!name.value.trim()) {
|
||||
status.textContent = "Enter a name to sign up.";
|
||||
return;
|
||||
}
|
||||
void run(async () => {
|
||||
const result = await authClient.signUp.email({
|
||||
name: name.value.trim(),
|
||||
email: email.value,
|
||||
password: password.value,
|
||||
});
|
||||
if (result.error) throw new Error(result.error.message ?? "Sign up failed");
|
||||
password.value = "";
|
||||
await refresh();
|
||||
});
|
||||
});
|
||||
|
||||
document.querySelector("#sign-in")!.addEventListener("click", () => {
|
||||
if (!form.reportValidity()) return;
|
||||
void run(async () => {
|
||||
const result = await authClient.signIn.email({
|
||||
email: email.value,
|
||||
password: password.value,
|
||||
});
|
||||
if (result.error) throw new Error(result.error.message ?? "Sign in failed");
|
||||
password.value = "";
|
||||
await refresh();
|
||||
});
|
||||
});
|
||||
|
||||
document.querySelector("#sign-out")!.addEventListener("click", () => {
|
||||
void run(async () => {
|
||||
const result = await authClient.signOut();
|
||||
if (result.error)
|
||||
throw new Error(result.error.message ?? "Sign out failed");
|
||||
await refresh();
|
||||
});
|
||||
});
|
||||
|
||||
document
|
||||
.querySelector("#refresh")!
|
||||
.addEventListener("click", () => void run(refresh));
|
||||
|
||||
void run(async () => {
|
||||
const response = await fetch("/api/providers");
|
||||
if (!response.ok)
|
||||
throw new Error(`Provider lookup returned ${response.status}`);
|
||||
const enabled: { github: boolean } = await response.json();
|
||||
if (enabled.github) {
|
||||
const button = document.createElement("button");
|
||||
button.type = "button";
|
||||
button.textContent = "Continue with GitHub";
|
||||
button.addEventListener("click", () => {
|
||||
void run(async () => {
|
||||
const result = await authClient.signIn.social({
|
||||
provider: "github",
|
||||
callbackURL: "/",
|
||||
});
|
||||
if (result.error)
|
||||
throw new Error(result.error.message ?? "GitHub sign in failed");
|
||||
});
|
||||
});
|
||||
providers.append(button);
|
||||
}
|
||||
await refresh();
|
||||
});
|
||||
@@ -0,0 +1,32 @@
|
||||
import { CloudflareD1 } from "@alchemy.run/better-auth/CloudflareD1";
|
||||
import * as Cloudflare from "alchemy/Cloudflare";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as HttpRouter from "effect/http/HttpRouter";
|
||||
import { HttpServerRequest } from "effect/http/HttpServerRequest";
|
||||
import { Auth } from "./auth.ts";
|
||||
import { AuthDb } from "./database.ts";
|
||||
import { HttpLive } from "./http.ts";
|
||||
|
||||
export default class AuthApi extends Cloudflare.Worker<AuthApi>()(
|
||||
"AuthApi",
|
||||
{
|
||||
main: import.meta.url,
|
||||
compatibility: { flags: ["nodejs_compat"] },
|
||||
assets: { directory: "./public" },
|
||||
},
|
||||
Effect.gen(function* () {
|
||||
const auth = yield* Auth;
|
||||
const http = yield* HttpRouter.toHttpEffect(HttpLive);
|
||||
return {
|
||||
fetch: Effect.gen(function* () {
|
||||
const request = yield* HttpServerRequest;
|
||||
const pathname = new URL(request.url, "http://localhost").pathname;
|
||||
if (pathname === "/api/auth" || pathname.startsWith("/api/auth/")) {
|
||||
return yield* auth.fetch;
|
||||
}
|
||||
return yield* http;
|
||||
}),
|
||||
};
|
||||
}).pipe(Effect.provide(Auth.layer.pipe(Layer.provide(CloudflareD1(AuthDb))))),
|
||||
) {}
|
||||
@@ -0,0 +1,67 @@
|
||||
import { expect, test } from "bun:test";
|
||||
|
||||
const baseURL = process.env.BETTER_AUTH_TEST_URL;
|
||||
|
||||
test.skipIf(!baseURL)(
|
||||
"same-origin authentication lifecycle",
|
||||
async () => {
|
||||
const origin = new URL(baseURL!).origin;
|
||||
const cookies = new Map<string, string>();
|
||||
const request = async (path: string, body?: object) => {
|
||||
const response = await fetch(new URL(path, origin), {
|
||||
method: body ? "POST" : "GET",
|
||||
headers: {
|
||||
origin,
|
||||
"content-type": "application/json",
|
||||
cookie: [...cookies]
|
||||
.map(([name, value]) => `${name}=${value}`)
|
||||
.join("; "),
|
||||
},
|
||||
body: body ? JSON.stringify(body) : undefined,
|
||||
signal: AbortSignal.timeout(10_000),
|
||||
});
|
||||
for (const cookie of response.headers.getSetCookie()) {
|
||||
const pair = cookie.split(";", 1)[0]!;
|
||||
const separator = pair.indexOf("=");
|
||||
cookies.set(pair.slice(0, separator), pair.slice(separator + 1));
|
||||
}
|
||||
return response;
|
||||
};
|
||||
|
||||
expect(await (await request("/api/health")).json()).toEqual({ ok: true });
|
||||
expect((await request("/")).status).toBe(200);
|
||||
expect((await request("/ui.js")).status).toBe(200);
|
||||
expect((await request("/api/providers")).status).toBe(200);
|
||||
expect((await request("/api/auth-not-a-route")).status).toBe(404);
|
||||
expect((await request("/api/me")).status).toBe(401);
|
||||
|
||||
const user = {
|
||||
name: "Local Example User",
|
||||
email: `example-${crypto.randomUUID()}@example.com`,
|
||||
password: "local-example-password-123",
|
||||
};
|
||||
const signup = await request("/api/auth/sign-up/email", user);
|
||||
expect(signup.status).toBe(200);
|
||||
expect(cookies.size).toBeGreaterThan(0);
|
||||
const me = await request("/api/me");
|
||||
expect(me.status).toBe(200);
|
||||
expect(await me.json()).toMatchObject({
|
||||
name: user.name,
|
||||
email: user.email,
|
||||
});
|
||||
const session = await request("/api/auth/get-session");
|
||||
expect(session.status).toBe(200);
|
||||
expect(await session.json()).toMatchObject({ user: { email: user.email } });
|
||||
|
||||
expect((await request("/api/auth/sign-out", {})).status).toBe(200);
|
||||
expect((await request("/api/me")).status).toBe(401);
|
||||
expect(await (await request("/api/auth/get-session")).json()).toBeNull();
|
||||
expect((await request("/api/health")).status).toBe(200);
|
||||
|
||||
expect((await request("/api/auth/sign-in/email", user)).status).toBe(200);
|
||||
expect((await request("/api/me")).status).toBe(200);
|
||||
expect((await request("/api/auth/sign-out", {})).status).toBe(200);
|
||||
expect((await request("/api/me")).status).toBe(401);
|
||||
},
|
||||
45_000,
|
||||
);
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"include": ["alchemy.run.ts", "src/**/*", "test/**/*"],
|
||||
"compilerOptions": {
|
||||
"noEmit": true,
|
||||
"rootDir": ".",
|
||||
"declaration": false,
|
||||
"declarationMap": false
|
||||
},
|
||||
"references": [
|
||||
{ "path": "../../packages/alchemy/tsconfig.json" },
|
||||
{ "path": "../../packages/better-auth/tsconfig.json" }
|
||||
]
|
||||
}
|
||||
@@ -2,8 +2,8 @@ import * as Cloudflare from "alchemy/Cloudflare";
|
||||
import * as Drizzle from "alchemy/Drizzle";
|
||||
import { eq } from "drizzle-orm";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as HttpServerRequest from "effect/unstable/http/HttpServerRequest";
|
||||
import * as HttpServerResponse from "effect/unstable/http/HttpServerResponse";
|
||||
import * as HttpServerRequest from "effect/http/HttpServerRequest";
|
||||
import * as HttpServerResponse from "effect/http/HttpServerResponse";
|
||||
import { Database } from "./Db.ts";
|
||||
import { relations, Users } from "./schema.ts";
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@ import * as Test from "alchemy/Test/Bun";
|
||||
import { expect } from "bun:test";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as HttpClient from "effect/unstable/http/HttpClient";
|
||||
import * as HttpClientRequest from "effect/unstable/http/HttpClientRequest";
|
||||
import * as HttpClient from "effect/http/HttpClient";
|
||||
import * as HttpClientRequest from "effect/http/HttpClientRequest";
|
||||
import Stack from "../alchemy.run.ts";
|
||||
import type { Post, User } from "../src/schema.ts";
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@ import * as Config from "effect/Config";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Redacted from "effect/Redacted";
|
||||
import * as Stream from "effect/Stream";
|
||||
import * as HttpServerRequest from "effect/unstable/http/HttpServerRequest";
|
||||
import * as HttpServerResponse from "effect/unstable/http/HttpServerResponse";
|
||||
import * as HttpServerRequest from "effect/http/HttpServerRequest";
|
||||
import * as HttpServerResponse from "effect/http/HttpServerResponse";
|
||||
import { KV } from "./KV.ts";
|
||||
import NotifyWorkflow from "./NotifyWorkflow.ts";
|
||||
import SandboxDO from "./SandboxDO.ts";
|
||||
|
||||
@@ -13,8 +13,8 @@ import * as Cloudflare from "alchemy/Cloudflare";
|
||||
import * as SQL from "alchemy/SQL/Postgres";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Redacted from "effect/Redacted";
|
||||
import { HttpServerRequest } from "effect/unstable/http/HttpServerRequest";
|
||||
import * as HttpServerResponse from "effect/unstable/http/HttpServerResponse";
|
||||
import { HttpServerRequest } from "effect/http/HttpServerRequest";
|
||||
import * as HttpServerResponse from "effect/http/HttpServerResponse";
|
||||
|
||||
const parseOrigin = (raw: string | undefined) => {
|
||||
// The fallback keeps module evaluation safe inside workerd (where the env
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import * as Cloudflare from "alchemy/Cloudflare";
|
||||
import { Stack } from "alchemy/Stack";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as HttpServerResponse from "effect/unstable/http/HttpServerResponse";
|
||||
import * as HttpServerResponse from "effect/http/HttpServerResponse";
|
||||
|
||||
export class SandboxContainer extends Cloudflare.Container<
|
||||
SandboxContainer,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as Cloudflare from "alchemy/Cloudflare";
|
||||
import * as Effect from "effect/Effect";
|
||||
import { HttpClientRequest, HttpServerResponse } from "effect/unstable/http";
|
||||
import { HttpClientRequest, HttpServerResponse } from "effect/http";
|
||||
import { SandboxContainer } from "./SandboxContainer.ts";
|
||||
|
||||
export default class SandboxDO extends Cloudflare.DurableObject<SandboxDO>()(
|
||||
|
||||
Loaded 100 of 11290 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user