@beignet/cli 0.0.36 → 0.0.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/README.md +18 -0
- package/dist/config.d.ts +14 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +29 -0
- package/dist/config.js.map +1 -1
- package/dist/inspect.js +6 -2
- package/dist/inspect.js.map +1 -1
- package/dist/provider-audit.d.ts.map +1 -1
- package/dist/provider-audit.js +8 -3
- package/dist/provider-audit.js.map +1 -1
- package/dist/templates/base.d.ts.map +1 -1
- package/dist/templates/base.js +6 -1
- package/dist/templates/base.js.map +1 -1
- package/dist/templates/db/index.d.ts +1 -0
- package/dist/templates/db/index.d.ts.map +1 -1
- package/dist/templates/db/index.js.map +1 -1
- package/dist/templates/db/mysql.d.ts.map +1 -1
- package/dist/templates/db/mysql.js +16 -0
- package/dist/templates/db/mysql.js.map +1 -1
- package/dist/templates/db/postgres.d.ts.map +1 -1
- package/dist/templates/db/postgres.js +16 -0
- package/dist/templates/db/postgres.js.map +1 -1
- package/dist/templates/db/sqlite.d.ts.map +1 -1
- package/dist/templates/db/sqlite.js +16 -0
- package/dist/templates/db/sqlite.js.map +1 -1
- package/dist/templates/index.d.ts.map +1 -1
- package/dist/templates/index.js +2 -1
- package/dist/templates/index.js.map +1 -1
- package/dist/templates/server.d.ts +1 -1
- package/dist/templates/server.d.ts.map +1 -1
- package/dist/templates/server.js +51 -35
- package/dist/templates/server.js.map +1 -1
- package/dist/templates/shared.js +3 -3
- package/dist/templates/shared.js.map +1 -1
- package/package.json +2 -2
- package/src/config.ts +64 -0
- package/src/inspect.ts +16 -2
- package/src/provider-audit.ts +25 -8
- package/src/templates/base.ts +6 -1
- package/src/templates/db/index.ts +1 -0
- package/src/templates/db/mysql.ts +16 -0
- package/src/templates/db/postgres.ts +16 -0
- package/src/templates/db/sqlite.ts +16 -0
- package/src/templates/index.ts +2 -1
- package/src/templates/server.ts +51 -37
- package/src/templates/shared.ts +3 -3
package/src/templates/server.ts
CHANGED
|
@@ -23,6 +23,7 @@ export function serverProviders(ctx: TemplateContext): string {
|
|
|
23
23
|
? 'import { createUpstashRateLimitProvider } from "@beignet/provider-rate-limit-upstash";'
|
|
24
24
|
: undefined,
|
|
25
25
|
'import * as schema from "@/infra/db/schema";',
|
|
26
|
+
'import { databaseClient } from "@/infra/db/client";',
|
|
26
27
|
'import { starterDatabaseProvider } from "@/infra/db/provider";',
|
|
27
28
|
'import { auth } from "@/lib/better-auth";',
|
|
28
29
|
'import type { AuthSessionMetadata, AuthUser } from "@/ports/auth";',
|
|
@@ -45,7 +46,10 @@ export function serverProviders(ctx: TemplateContext): string {
|
|
|
45
46
|
|
|
46
47
|
return `${imports.join("\n")}
|
|
47
48
|
|
|
48
|
-
const ${db.providerInstance} = ${db.providerFactory}({
|
|
49
|
+
const ${db.providerInstance} = ${db.providerFactory}({
|
|
50
|
+
schema,
|
|
51
|
+
client: databaseClient,
|
|
52
|
+
});
|
|
49
53
|
|
|
50
54
|
export const providers = [
|
|
51
55
|
${entries.join("\n")}
|
|
@@ -151,7 +155,8 @@ export function env(ctx: TemplateContext): string {
|
|
|
151
155
|
\t\tSQLITE_DB_AUTH_TOKEN: z.string().optional(),`
|
|
152
156
|
: `\t\t${databaseDescriptor(ctx).urlEnvVar}: z
|
|
153
157
|
\t\t\t.string()
|
|
154
|
-
\t\t\t.default("${databaseLocalUrl(ctx.database, ctx.name)}")
|
|
158
|
+
\t\t\t.default("${databaseLocalUrl(ctx.database, ctx.name)}"),
|
|
159
|
+
\t\t${ctx.database === "postgres" ? "POSTGRES" : "MYSQL"}_DB_POOL_MAX: z.coerce.number().int().positive().default(5),`;
|
|
155
160
|
|
|
156
161
|
return `import { createEnv } from "@beignet/core/config";
|
|
157
162
|
import { z } from "zod";
|
|
@@ -202,54 +207,45 @@ export const isDevtoolsEnabled =
|
|
|
202
207
|
|
|
203
208
|
export function betterAuth(ctx: TemplateContext): string {
|
|
204
209
|
const connectionByDatabase = {
|
|
205
|
-
sqlite: `import {
|
|
206
|
-
import { betterAuth } from "better-auth";
|
|
210
|
+
sqlite: `import { betterAuth } from "better-auth";
|
|
207
211
|
import { drizzleAdapter } from "better-auth/adapters/drizzle";
|
|
208
212
|
import { drizzle } from "drizzle-orm/libsql";
|
|
213
|
+
import { databaseClient } from "@/infra/db/client";
|
|
209
214
|
import { ensureDatabaseReady } from "@/infra/db/database-ready";
|
|
210
215
|
import * as schema from "@/infra/db/schema";
|
|
211
216
|
import { env } from "@/lib/env";
|
|
212
217
|
|
|
213
|
-
const client = createClient({
|
|
214
|
-
url: env.SQLITE_DB_URL,
|
|
215
|
-
authToken: env.SQLITE_DB_AUTH_TOKEN,
|
|
216
|
-
});
|
|
217
|
-
|
|
218
218
|
// Auth routes can be the first thing to touch the database, before any
|
|
219
219
|
// Beignet provider boots, so readiness is enforced here too.
|
|
220
|
-
await ensureDatabaseReady(
|
|
220
|
+
await ensureDatabaseReady(databaseClient);
|
|
221
221
|
|
|
222
|
-
const db = drizzle(
|
|
222
|
+
const db = drizzle(databaseClient, { schema });`,
|
|
223
223
|
postgres: `import { betterAuth } from "better-auth";
|
|
224
224
|
import { drizzleAdapter } from "better-auth/adapters/drizzle";
|
|
225
225
|
import { drizzle } from "drizzle-orm/node-postgres";
|
|
226
|
-
import
|
|
226
|
+
import { databaseClient } from "@/infra/db/client";
|
|
227
227
|
import { ensureDatabaseReady } from "@/infra/db/database-ready";
|
|
228
228
|
import * as schema from "@/infra/db/schema";
|
|
229
229
|
import { env } from "@/lib/env";
|
|
230
230
|
|
|
231
|
-
const pool = new pg.Pool({ connectionString: env.POSTGRES_DB_URL });
|
|
232
|
-
|
|
233
231
|
// Auth routes can be the first thing to touch the database, before any
|
|
234
232
|
// Beignet provider boots, so readiness is enforced here too.
|
|
235
|
-
await ensureDatabaseReady(
|
|
233
|
+
await ensureDatabaseReady(databaseClient);
|
|
236
234
|
|
|
237
|
-
const db = drizzle(
|
|
235
|
+
const db = drizzle(databaseClient, { schema });`,
|
|
238
236
|
mysql: `import { betterAuth } from "better-auth";
|
|
239
237
|
import { drizzleAdapter } from "better-auth/adapters/drizzle";
|
|
240
238
|
import { drizzle } from "drizzle-orm/mysql2";
|
|
241
|
-
import
|
|
239
|
+
import { databaseClient } from "@/infra/db/client";
|
|
242
240
|
import { ensureDatabaseReady } from "@/infra/db/database-ready";
|
|
243
241
|
import * as schema from "@/infra/db/schema";
|
|
244
242
|
import { env } from "@/lib/env";
|
|
245
243
|
|
|
246
|
-
const pool = mysql.createPool({ uri: env.MYSQL_DB_URL });
|
|
247
|
-
|
|
248
244
|
// Auth routes can be the first thing to touch the database, before any
|
|
249
245
|
// Beignet provider boots, so readiness is enforced here too.
|
|
250
|
-
await ensureDatabaseReady(
|
|
246
|
+
await ensureDatabaseReady(databaseClient);
|
|
251
247
|
|
|
252
|
-
const db = drizzle(
|
|
248
|
+
const db = drizzle(databaseClient, { schema, mode: "default" });`,
|
|
253
249
|
} as const;
|
|
254
250
|
|
|
255
251
|
return `${connectionByDatabase[ctx.database]}
|
|
@@ -285,18 +281,7 @@ export const auth = betterAuth({
|
|
|
285
281
|
`;
|
|
286
282
|
}
|
|
287
283
|
|
|
288
|
-
export function server(
|
|
289
|
-
const db = databaseDescriptor(ctx);
|
|
290
|
-
const providerConfigEntries =
|
|
291
|
-
ctx.database === "sqlite"
|
|
292
|
-
? `\t\t"drizzle-sqlite": {
|
|
293
|
-
\t\t\tDB_URL: env.SQLITE_DB_URL,
|
|
294
|
-
\t\t\tDB_AUTH_TOKEN: env.SQLITE_DB_AUTH_TOKEN,
|
|
295
|
-
\t\t},`
|
|
296
|
-
: `\t\t"${db.providerName}": {
|
|
297
|
-
\t\t\tDB_URL: env.${db.urlEnvVar},
|
|
298
|
-
\t\t},`;
|
|
299
|
-
|
|
284
|
+
export function server(): string {
|
|
300
285
|
return `import "@beignet/core/server-only";
|
|
301
286
|
import { createNextServer, createNextServerLoader } from "@beignet/next";
|
|
302
287
|
import {
|
|
@@ -306,6 +291,7 @@ import {
|
|
|
306
291
|
} from "@beignet/core/server";
|
|
307
292
|
import type { AppContext } from "@/app-context";
|
|
308
293
|
import { appPorts } from "@/infra/app-ports";
|
|
294
|
+
import { closeDatabaseClient } from "@/infra/db/client";
|
|
309
295
|
import { env } from "@/lib/env";
|
|
310
296
|
import { appContext } from "./context";
|
|
311
297
|
import { routes } from "./routes";
|
|
@@ -313,12 +299,9 @@ import { routes } from "./routes";
|
|
|
313
299
|
export const getServer = createNextServerLoader(async () => {
|
|
314
300
|
const { providers } = await import("./providers");
|
|
315
301
|
|
|
316
|
-
|
|
302
|
+
const server = await createNextServer({
|
|
317
303
|
ports: appPorts,
|
|
318
304
|
providers,
|
|
319
|
-
providerConfig: {
|
|
320
|
-
${providerConfigEntries}
|
|
321
|
-
},
|
|
322
305
|
hooks: [
|
|
323
306
|
createSecurityHeadersHooks<AppContext>(),
|
|
324
307
|
createErrorReportingHooks<AppContext>(),
|
|
@@ -343,7 +326,38 @@ ${providerConfigEntries}
|
|
|
343
326
|
};
|
|
344
327
|
},
|
|
345
328
|
});
|
|
329
|
+
let stopPromise: Promise<void> | undefined;
|
|
330
|
+
|
|
331
|
+
return {
|
|
332
|
+
...server,
|
|
333
|
+
stop() {
|
|
334
|
+
stopPromise ??= stopServerAndDatabase(server);
|
|
335
|
+
return stopPromise;
|
|
336
|
+
},
|
|
337
|
+
};
|
|
346
338
|
});
|
|
339
|
+
|
|
340
|
+
async function stopServerAndDatabase(server: {
|
|
341
|
+
stop(): Promise<void>;
|
|
342
|
+
}): Promise<void> {
|
|
343
|
+
const errors: unknown[] = [];
|
|
344
|
+
try {
|
|
345
|
+
await server.stop();
|
|
346
|
+
} catch (error) {
|
|
347
|
+
errors.push(error);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
try {
|
|
351
|
+
await closeDatabaseClient();
|
|
352
|
+
} catch (error) {
|
|
353
|
+
errors.push(error);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
if (errors.length === 1) throw errors[0];
|
|
357
|
+
if (errors.length > 1) {
|
|
358
|
+
throw new AggregateError(errors, "Server and database shutdown failed");
|
|
359
|
+
}
|
|
360
|
+
}
|
|
347
361
|
`;
|
|
348
362
|
}
|
|
349
363
|
|
package/src/templates/shared.ts
CHANGED
|
@@ -32,7 +32,7 @@ export type TemplateContext = {
|
|
|
32
32
|
|
|
33
33
|
export const externalVersions = {
|
|
34
34
|
biome: "^2.4.14",
|
|
35
|
-
next: "^16.2.
|
|
35
|
+
next: "^16.2.10",
|
|
36
36
|
react: "^19.2.5",
|
|
37
37
|
reactDom: "^19.2.5",
|
|
38
38
|
tsx: "^4.22.4",
|
|
@@ -48,7 +48,7 @@ export const externalVersions = {
|
|
|
48
48
|
bullmq: "^5.0.0",
|
|
49
49
|
drizzleKit: "^0.31.10",
|
|
50
50
|
drizzleOrm: "^0.45.2",
|
|
51
|
-
inngest: "^3.
|
|
51
|
+
inngest: "^3.54.0",
|
|
52
52
|
libsqlClient: "^0.14.0",
|
|
53
53
|
vercelBlob: "^2.5.0",
|
|
54
54
|
mysql2: "^3.12.0",
|
|
@@ -58,7 +58,7 @@ export const externalVersions = {
|
|
|
58
58
|
resend: "^6.14.0",
|
|
59
59
|
sentryNode: "^10.58.0",
|
|
60
60
|
stripe: "^22.2.1",
|
|
61
|
-
nodemailer: "^
|
|
61
|
+
nodemailer: "^9.0.1",
|
|
62
62
|
openFeatureServerSdk: "^1.22.0",
|
|
63
63
|
typesPg: "^8.11.0",
|
|
64
64
|
ioredis: "^5.0.0",
|