Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions templates/create/_shared/service.ts.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ export default compute({
{{else if (eq template "turborepo")}}
build: node({ module: import.meta.url, entry: "./apps/server/dist/server.mjs" }),
{{else if (eq template "svelte")}}
build: node({ module: import.meta.url, dir: "./build", entry: "index.js" }),
build: node({ module: import.meta.url, dir: "./build", entry: "index.js", dependencies: "external" }),
{{else if (eq template "astro")}}
build: node({ module: import.meta.url, dir: "./dist", entry: "server/entry.mjs" }),
build: node({ module: import.meta.url, dir: "./dist", entry: "server/entry.mjs", dependencies: "external" }),
{{else if (eq template "nuxt")}}
build: node({ module: import.meta.url, dir: "./.output", entry: "server/index.mjs" }),
{{else if (eq template "tanstack-start")}}
Expand Down
10 changes: 0 additions & 10 deletions templates/create/_shared/src/prisma/db.ts.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,3 @@ const databaseUrl = getDatabaseUrl();

export const db = databaseUrl ? mongo({ contract, url: databaseUrl }) : mongo({ contract });
{{/if}}

let connection: Promise<void> | undefined;

export function connectDatabase(): Promise<void> {
connection ??= db.connect().then(() => undefined).catch((error: unknown) => {
connection = undefined;
throw error;
});
return connection;
}
4 changes: 1 addition & 3 deletions templates/create/_shared/src/prisma/seed.ts.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { connectDatabase, db } from "./db.ts";
import { db } from "./db.ts";

const users = [
{ email: "alice@prisma.io", username: "alice", name: "Alice" },
Expand All @@ -9,8 +9,6 @@ const users = [
let pendingSeed: Promise<void> | undefined;

async function runSeed(): Promise<void> {
await connectDatabase();

{{#if (eq provider "mongo")}}
for (const user of users) {
const existingUser = await db.orm.users.where({ email: user.email }).first();
Expand Down
9 changes: 6 additions & 3 deletions templates/create/astro/src/pages/index.astro.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ const formatter = new Intl.DateTimeFormat("en", {
timeStyle: "short",
});

const users = await listUsers(10).catch(() => undefined);
const users = await listUsers(10).catch((error: unknown) => {
console.error("Failed to query users:", error);
return undefined;
});

---

Expand Down Expand Up @@ -40,8 +43,8 @@ const users = await listUsers(10).catch(() => undefined);

{!users ? (
<p class="empty">
Could not query users yet. Run <code>contract:emit</code> and apply your schema,
then refresh.
Could not query users. Check the server log for the error. If the schema isn't
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
applied yet, run <code>contract:emit</code> and apply it, then refresh.
</p>
) : users.length === 0 ? (
<p class="empty">No users found.</p>
Expand Down
4 changes: 2 additions & 2 deletions templates/create/elysia/src/index.ts.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ const app = new Elysia({ adapter: "Bun" in globalThis ? undefined : node() })
})

.get("/users", async ({ set }) => {
const users = await listUsers(10).catch((error) => {
const users = await listUsers(10).catch((error: unknown) => {
console.error("Failed to query users:", error);
return undefined;
});

if (!users) {
set.status = 500;
return { error: "Could not query users yet. Run contract:emit and apply your schema first." };
return { error: "Could not query users. Check the server log for the error." };
}

return users;
Expand Down
4 changes: 2 additions & 2 deletions templates/create/hono/src/index.ts.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ app.get("/", (c) => {
});

app.get("/users", async (c) => {
const users = await listUsers(10).catch((error) => {
const users = await listUsers(10).catch((error: unknown) => {
console.error("Failed to query users:", error);
return undefined;
});

if (!users) {
return c.json({ error: "Could not query users yet. Run contract:emit and apply your schema first." }, 500);
return c.json({ error: "Could not query users. Check the server log for the error." }, 500);
}

return c.json(users);
Expand Down
7 changes: 0 additions & 7 deletions templates/create/next/next.config.ts

This file was deleted.

11 changes: 11 additions & 0 deletions templates/create/next/next.config.ts.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { NextConfig } from "next";

const nextConfig: NextConfig = {
output: "standalone",
{{#if (eq provider "mongo")}}
// Turbopack's ESM interop breaks mongodb-connection-string-url, which the Mongo runtime imports.
serverExternalPackages: ["@prisma/orm-mongo"],
{{/if}}
};

export default nextConfig;
9 changes: 6 additions & 3 deletions templates/create/next/src/app/page.tsx.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ export default async function Home() {
dateStyle: "medium",
timeStyle: "short",
});
const users = await listUsers(10).catch(() => undefined);
const users = await listUsers(10).catch((error: unknown) => {
console.error("Failed to query users:", error);
return undefined;
});

return (
<main className="shell">
Expand All @@ -29,8 +32,8 @@ export default async function Home() {

{!users ? (
<p className="empty">
Could not query users yet. Run <code>contract:emit</code> and apply your schema,
then refresh.
Could not query users. Check the server log for the error. If the schema isn't
applied yet, run <code>contract:emit</code> and apply it, then refresh.
</p>
) : users.length === 0 ? (
<p className="empty">No users found.</p>
Expand Down
3 changes: 2 additions & 1 deletion templates/create/nuxt/app/pages/index.vue.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ function formatCreatedAt(value: string): string {
</div>

<p v-if="data?.error" class="empty">
\{{ data.error }} Run <code>contract:emit</code> and apply your schema, then refresh.
\{{ data.error }} If the schema isn't applied yet, run <code>contract:emit</code> and apply
it, then refresh.
</p>
<p v-else-if="!data?.users?.length" class="empty">
No users found.
Expand Down
4 changes: 2 additions & 2 deletions templates/create/nuxt/server/api/users.get.ts.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ export default defineEventHandler(async () => {
createdAt: user.createdAt ?? null,
}))
)
.catch((error) => {
.catch((error: unknown) => {
console.error("Failed to query users:", error);
return undefined;
});

if (!users) {
return {
error: "Could not query users yet.",
error: "Could not query users. Check the server log for the error.",
users: [],
};
}
Expand Down
5 changes: 4 additions & 1 deletion templates/create/svelte/src/routes/+page.server.ts.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ export const load: PageServerLoad = async () => {
createdAt: user.createdAt ?? null,
}))
)
.catch(() => undefined);
.catch((error: unknown) => {
console.error("Failed to query users:", error);
return undefined;
});

return { users };
};
4 changes: 2 additions & 2 deletions templates/create/svelte/src/routes/+page.svelte.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@

{#if !data.users}
<p class="empty">
Could not query users yet. Run <code>contract:emit</code> and apply your schema, then
refresh.
Could not query users. Check the server log for the error. If the schema isn't applied
yet, run <code>contract:emit</code> and apply it, then refresh.
</p>
{:else if data.users.length === 0}
<p class="empty">No users found.</p>
Expand Down
3 changes: 0 additions & 3 deletions templates/create/svelte/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,4 @@ import { defineConfig } from "vite";

export default defineConfig({
plugins: [sveltekit({ adapter: adapter() })],
ssr: {
noExternal: true,
},
});
9 changes: 6 additions & 3 deletions templates/create/tanstack-start/src/routes/index.tsx.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ const listUsers = createServerFn({ method: "GET" }).handler(async () => {
createdAt: user.createdAt ?? null,
}))
)
.catch(() => undefined);
.catch((error: unknown) => {
console.error("Failed to query users:", error);
return undefined;
});
});

export const Route = createFileRoute("/")({
Expand Down Expand Up @@ -50,8 +53,8 @@ function Home() {

{!users ? (
<p className="empty">
Could not query users yet. Run <code>contract:emit</code> and apply your schema,
then refresh.
Could not query users. Check the server log for the error. If the schema isn't
applied yet, run <code>contract:emit</code> and apply it, then refresh.
</p>
) : users.length === 0 ? (
<p className="empty">No users found.</p>
Expand Down
12 changes: 8 additions & 4 deletions tests/install.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ describe("generated templates", () => {
expect(packageJson.scripts?.deploy).toBeUndefined();
expect(dbSource).toContain('Deno.env.get("DATABASE_URL")');
expect(dbSource).not.toContain('import service from "../../service.ts"');
expect(seedSource).toContain("await connectDatabase()");
expect(seedSource).not.toContain("connect()");
expect(usersSource).toContain("await seed()");
continue;
}
Expand Down Expand Up @@ -443,8 +443,8 @@ describe("generated templates", () => {
expect(prismaConfig.includes("nextjsBuild()")).toBe(template === "next");
expect(tsconfig).toContain('"node"');
expect(serviceSource).toContain("compute({");
expect(dbSource).toContain("export function connectDatabase()");
expect(seedSource).toContain("await connectDatabase()");
expect(dbSource).not.toContain(".connect(");
expect(seedSource).not.toContain("connect");
expect(seedSource).toContain("export function seed()");
expect(usersSource).toContain("await seed()");
expect(
Expand Down Expand Up @@ -547,7 +547,11 @@ describe("generated templates", () => {
}
if (template === "svelte") {
const viteConfig = await readFile(path.join(projectDir, "vite.config.ts"), "utf8");
expect(viteConfig).toContain("noExternal: true");
expect(viteConfig).not.toContain("noExternal");
expect(serviceSource).toContain('dependencies: "external"');
}
if (template === "astro") {
expect(serviceSource).toContain('dependencies: "external"');
}
if (template === "nuxt") {
expect(packageJson.scripts?.postinstall).toBe(
Expand Down
Loading