Skip to content

Compute

Source: src/Prisma/Compute.ts

Build and deploy an application to Prisma Compute.

Prisma’s create-deployment API exposes neither an idempotency key nor a caller-defined recovery key. If the API commits a deployment but its create response is lost before Alchemy persists the returned ID, that deployment can remain orphaned and a later deploy may create another one. Alchemy does not guess that the App’s latest deployment is owned, because it could belong to another actor. Use a durable, locked state backend and inspect the App’s deployment history after an interrupted create.

Deploy a directory with an entrypoint

const app = yield* Prisma.Compute("api", {
project: project.projectId,
path: "./apps/api",
entrypoint: "server.ts",
port: 3000,
});

Deploy an Effect-native HTTP app

export default Prisma.Compute(
"api",
{
project,
appName: "api",
main: import.meta.filename,
port: 8080,
},
Effect.gen(function* () {
return {
fetch: Effect.succeed(HttpServerResponse.text("ok")),
};
}),
);

main is bundled with rolldown at deploy time. Unused code is tree-shaken. effect, alchemy, and @distilled.cloud are marked pure so unused parts prune more aggressively. Your app is not marked pure.

Mark additional packages as pure

Only list packages with no top-level side effects.

{
main: "./src/app.ts",
bundle: {
extra: { pure: { packages: ["my-lib", "@my-scope/*"] } },
},
}

Turn it off

{
main: "./src/app.ts",
bundle: { extra: { pure: false } },
}

Bind a Prisma Connection

export default Prisma.Compute(
"api",
{
project,
appName: "api",
main: import.meta.filename,
},
Effect.gen(function* () {
const db = yield* Prisma.Connect(connection);
const sql = yield* SQL.Postgres({ url: db.databaseUrl });
return {
fetch: Effect.gen(function* () {
const users = yield* sql`SELECT * FROM users`;
return yield* HttpServerResponse.json(users);
}),
};
}).pipe(Effect.provide(Prisma.ConnectBinding)),
);

Build before upload and replace old versions

const app = yield* Prisma.Compute("api", {
project: project.projectId,
path: "./apps/api",
build: {
command: "bun build src/server.ts --target bun --outdir dist",
outdir: "dist",
entrypoint: "server.js",
},
port: 8080,
env: {
// Use this for a standalone Connection. A project's default database
// is injected by Prisma without an explicit DATABASE_URL entry.
DATABASE_URL: connection.databaseUrl,
},
destroyOldDeployment: true,
});

Auto-build a framework app

const app = yield* Prisma.Compute("api", {
project: project.projectId,
path: "./apps/web",
build: "auto",
destroyOldDeployment: true,
});

Deploy a prebuilt tar.gz artifact

const app = yield* Prisma.Compute("api", {
project: project.projectId,
artifactPath: "./dist/app.tar.gz",
port: 8080,
});
const app = yield* Prisma.Compute("api", {
project,
path: "./apps/api",
entrypoint: "server.ts",
healthCheck: {
path: "/api/health",
// Defaults to any 2xx response when omitted.
statusCodes: [200, 204],
},
});
const app = yield* Prisma.Compute("api", {
project: project.projectId,
path: "./apps/api",
entrypoint: "server.ts",
dev: {
command: "bun run dev",
port: 3000,
},
});