@beignet/cli 0.0.46 → 0.0.48

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.
Files changed (97) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +50 -21
  3. package/dist/check.d.ts +8 -1
  4. package/dist/check.d.ts.map +1 -1
  5. package/dist/check.js +18 -6
  6. package/dist/check.js.map +1 -1
  7. package/dist/db.d.ts +38 -0
  8. package/dist/db.d.ts.map +1 -1
  9. package/dist/db.js +52 -0
  10. package/dist/db.js.map +1 -1
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +73 -6
  13. package/dist/index.js.map +1 -1
  14. package/dist/inspect.d.ts.map +1 -1
  15. package/dist/inspect.js +39 -2
  16. package/dist/inspect.js.map +1 -1
  17. package/dist/lib.d.ts +2 -2
  18. package/dist/lib.d.ts.map +1 -1
  19. package/dist/lib.js +1 -1
  20. package/dist/lib.js.map +1 -1
  21. package/dist/make/inbox.js +1 -1
  22. package/dist/make/inbox.js.map +1 -1
  23. package/dist/make/payments.js +1 -1
  24. package/dist/make/payments.js.map +1 -1
  25. package/dist/make/tenancy.d.ts.map +1 -1
  26. package/dist/make/tenancy.js +3 -2
  27. package/dist/make/tenancy.js.map +1 -1
  28. package/dist/mcp.d.ts.map +1 -1
  29. package/dist/mcp.js +39 -2
  30. package/dist/mcp.js.map +1 -1
  31. package/dist/preflight.d.ts +11 -3
  32. package/dist/preflight.d.ts.map +1 -1
  33. package/dist/preflight.js +139 -16
  34. package/dist/preflight.js.map +1 -1
  35. package/dist/provider-add.d.ts.map +1 -1
  36. package/dist/provider-add.js +7 -2
  37. package/dist/provider-add.js.map +1 -1
  38. package/dist/provider-audit.d.ts +13 -0
  39. package/dist/provider-audit.d.ts.map +1 -1
  40. package/dist/provider-audit.js +122 -8
  41. package/dist/provider-audit.js.map +1 -1
  42. package/dist/templates/agents.d.ts.map +1 -1
  43. package/dist/templates/agents.js +14 -7
  44. package/dist/templates/agents.js.map +1 -1
  45. package/dist/templates/base.d.ts +1 -0
  46. package/dist/templates/base.d.ts.map +1 -1
  47. package/dist/templates/base.js +11 -5
  48. package/dist/templates/base.js.map +1 -1
  49. package/dist/templates/db/index.d.ts +1 -0
  50. package/dist/templates/db/index.d.ts.map +1 -1
  51. package/dist/templates/db/index.js.map +1 -1
  52. package/dist/templates/db/migration-status.d.ts +9 -0
  53. package/dist/templates/db/migration-status.d.ts.map +1 -0
  54. package/dist/templates/db/migration-status.js +117 -0
  55. package/dist/templates/db/migration-status.js.map +1 -0
  56. package/dist/templates/db/mysql.d.ts.map +1 -1
  57. package/dist/templates/db/mysql.js +23 -0
  58. package/dist/templates/db/mysql.js.map +1 -1
  59. package/dist/templates/db/postgres.d.ts.map +1 -1
  60. package/dist/templates/db/postgres.js +21 -0
  61. package/dist/templates/db/postgres.js.map +1 -1
  62. package/dist/templates/db/sqlite.d.ts.map +1 -1
  63. package/dist/templates/db/sqlite.js +53 -0
  64. package/dist/templates/db/sqlite.js.map +1 -1
  65. package/dist/templates/index.d.ts.map +1 -1
  66. package/dist/templates/index.js +5 -0
  67. package/dist/templates/index.js.map +1 -1
  68. package/dist/templates/server.d.ts.map +1 -1
  69. package/dist/templates/server.js +4 -1
  70. package/dist/templates/server.js.map +1 -1
  71. package/dist/templates/shared.d.ts.map +1 -1
  72. package/dist/templates/shared.js +1 -0
  73. package/dist/templates/shared.js.map +1 -1
  74. package/package.json +2 -2
  75. package/skills/app-structure/SKILL.md +11 -7
  76. package/src/check.ts +35 -7
  77. package/src/db.ts +97 -0
  78. package/src/index.ts +108 -7
  79. package/src/inspect.ts +76 -1
  80. package/src/lib.ts +9 -1
  81. package/src/make/inbox.ts +1 -1
  82. package/src/make/payments.ts +1 -1
  83. package/src/make/tenancy.ts +3 -2
  84. package/src/mcp.ts +56 -1
  85. package/src/preflight.ts +195 -16
  86. package/src/provider-add.ts +7 -2
  87. package/src/provider-audit.ts +210 -18
  88. package/src/templates/agents.ts +14 -7
  89. package/src/templates/base.ts +12 -3
  90. package/src/templates/db/index.ts +1 -0
  91. package/src/templates/db/migration-status.ts +126 -0
  92. package/src/templates/db/mysql.ts +23 -0
  93. package/src/templates/db/postgres.ts +21 -0
  94. package/src/templates/db/sqlite.ts +53 -0
  95. package/src/templates/index.ts +5 -0
  96. package/src/templates/server.ts +4 -1
  97. package/src/templates/shared.ts +1 -0
@@ -22,6 +22,7 @@
22
22
  import { databaseLocalUrl } from "../../choices.js";
23
23
  import type { TemplateContext } from "../shared.js";
24
24
  import type { DbTemplateFiles } from "./index.js";
25
+ import { migrationStatusTemplate } from "./migration-status.js";
25
26
 
26
27
  export function postgresDbFiles(ctx: TemplateContext): DbTemplateFiles {
27
28
  return {
@@ -259,6 +260,26 @@ async function prepare(pool: Pool): Promise<void> {
259
260
  await migrate(drizzle(pool), { migrationsFolder: "drizzle" });
260
261
  }
261
262
  `,
263
+ dbMigrationStatus: migrationStatusTemplate({
264
+ imports: `import pg from "pg";
265
+ import { env } from "@/lib/env";`,
266
+ open: `const pool = new pg.Pool({ connectionString: env.POSTGRES_DB_URL });`,
267
+ loadApplied: `const table = await pool.query<{ name: string | null }>(
268
+ "SELECT to_regclass('drizzle.__drizzle_migrations')::text AS name",
269
+ );
270
+ const applied: AppliedMigration[] =
271
+ table.rows[0]?.name == null
272
+ ? []
273
+ : (
274
+ await pool.query<{ hash: string; created_at: string }>(
275
+ 'SELECT hash, created_at FROM "drizzle"."__drizzle_migrations" ORDER BY created_at',
276
+ )
277
+ ).rows.map((row) => ({
278
+ hash: row.hash,
279
+ createdAt: Number(row.created_at),
280
+ }));`,
281
+ close: "await pool.end();",
282
+ }),
262
283
  dbProvider: `import "@beignet/core/server-only";
263
284
  import { createProvider } from "@beignet/core/providers";
264
285
  import {
@@ -13,6 +13,7 @@
13
13
  // lives outside the app schema, so `db generate` never diffs against it.
14
14
 
15
15
  import type { DbTemplateFiles } from "./index.js";
16
+ import { migrationStatusTemplate } from "./migration-status.js";
16
17
 
17
18
  const files = {
18
19
  drizzleConfig: `export default {
@@ -264,6 +265,58 @@ async function prepare(client: Client): Promise<void> {
264
265
  await migrate(drizzle(client), { migrationsFolder: "drizzle" });
265
266
  }
266
267
  `,
268
+ dbMigrationStatus: migrationStatusTemplate({
269
+ imports: `import { statSync } from "node:fs";
270
+ import path from "node:path";
271
+ import { fileURLToPath } from "node:url";
272
+ import { createClient } from "@libsql/client";
273
+ import { env } from "@/lib/env";`,
274
+ open: `const databaseFile = sqliteDatabaseFile(env.SQLITE_DB_URL);
275
+ const client =
276
+ databaseFile !== undefined && !databaseFileExists(databaseFile)
277
+ ? undefined
278
+ : createClient({
279
+ url: env.SQLITE_DB_URL,
280
+ authToken: env.SQLITE_DB_AUTH_TOKEN,
281
+ });
282
+
283
+ function sqliteDatabaseFile(url: string): string | undefined {
284
+ if (!url.startsWith("file:")) return undefined;
285
+ const rawPath = url.slice("file:".length).split(/[?#]/, 1)[0];
286
+ if (!rawPath || rawPath === ":memory:") return undefined;
287
+ return rawPath.startsWith("//")
288
+ ? fileURLToPath(url)
289
+ : path.resolve(decodeURIComponent(rawPath));
290
+ }
291
+
292
+ function databaseFileExists(file: string): boolean {
293
+ try {
294
+ statSync(file);
295
+ return true;
296
+ } catch (error) {
297
+ if ((error as NodeJS.ErrnoException).code === "ENOENT") return false;
298
+ throw error;
299
+ }
300
+ }`,
301
+ loadApplied: `let applied: AppliedMigration[] = [];
302
+ if (client !== undefined) {
303
+ const table = await client.execute(
304
+ "SELECT name FROM sqlite_master WHERE type = 'table' AND name = '__drizzle_migrations' LIMIT 1",
305
+ );
306
+ applied =
307
+ table.rows.length === 0
308
+ ? []
309
+ : (
310
+ await client.execute(
311
+ "SELECT hash, created_at FROM __drizzle_migrations ORDER BY created_at",
312
+ )
313
+ ).rows.map((row) => ({
314
+ hash: String(row.hash),
315
+ createdAt: Number(row.created_at),
316
+ }));
317
+ }`,
318
+ close: "client?.close();",
319
+ }),
267
320
  dbProvider: `import "@beignet/core/server-only";
268
321
  import { createProvider } from "@beignet/core/providers";
269
322
  import {
@@ -53,6 +53,7 @@ export function getTemplateFiles(ctx: TemplateContext): TemplateFile[] {
53
53
  { path: "AGENTS.md", content: agentsMd(ctx) },
54
54
  { path: "CLAUDE.md", content: agentsMd(ctx) },
55
55
  { path: ".mcp.json", content: mcpJson(ctx) },
56
+ { path: ".gitattributes", content: baseFiles.gitattributes },
56
57
  { path: ".gitignore", content: baseFiles.gitignore },
57
58
  { path: ".env.example", content: envExample(ctx) },
58
59
  { path: "next-env.d.ts", content: baseFiles.nextEnv },
@@ -118,6 +119,10 @@ export function getTemplateFiles(ctx: TemplateContext): TemplateFile[] {
118
119
  { path: "infra/port-wiring.ts", content: portWiring(ctx) },
119
120
  { path: "infra/db/client.ts", content: db.dbClient },
120
121
  { path: "infra/db/database-ready.ts", content: db.databaseReady },
122
+ {
123
+ path: "infra/db/migration-status.ts",
124
+ content: db.dbMigrationStatus,
125
+ },
121
126
  { path: "infra/db/provider.ts", content: db.dbProvider },
122
127
  { path: "infra/db/repositories.ts", content: db.dbRepositories },
123
128
  { path: "infra/db/reset.ts", content: db.dbReset },
@@ -416,6 +416,7 @@ async function stopServerAndDatabase(server: {
416
416
  const files = {
417
417
  appContext: `import type { ActivityActor, ActivityTenant } from "@beignet/core/ports";
418
418
  import type { InferProviderPorts } from "@beignet/core/providers";
419
+ import type { TrustedRequestInfo } from "@beignet/core/server";
419
420
  import type { TraceContext } from "@beignet/core/tracing";
420
421
  import type { AppGate, AppPorts } from "@/ports";
421
422
  import type { AuthSession } from "@/ports/auth";
@@ -432,6 +433,7 @@ export type AppContext = {
432
433
  auth: AuthSession | null;
433
434
  gate: AppGate;
434
435
  ports: AppRuntimePorts;
436
+ requestInfo?: TrustedRequestInfo;
435
437
  tenant?: ActivityTenant;
436
438
  } & Partial<TraceContext>;
437
439
  `,
@@ -552,7 +554,7 @@ export type AppServiceContextInput =
552
554
  */
553
555
  export const appContext = defineServerContext<AppContext, AppRuntimePorts>()({
554
556
  gate: (ports) => ports.gate,
555
- request: async ({ req, ports, requestId, trace }) => {
557
+ request: async ({ req, requestInfo, ports, requestId, trace }) => {
556
558
  const auth = await ports.auth.getSession(req);
557
559
  const tenant = resolveRequestTenant({ auth });
558
560
 
@@ -562,6 +564,7 @@ export const appContext = defineServerContext<AppContext, AppRuntimePorts>()({
562
564
  ? createUserActor(auth.user.id, { displayName: auth.user.name })
563
565
  : createAnonymousActor(),
564
566
  auth,
567
+ requestInfo,
565
568
  ...trace,
566
569
  ports,
567
570
  ...(tenant ? { tenant } : {}),
@@ -77,6 +77,7 @@ export const legacyGeneratedPackageScripts: Record<string, readonly string[]> =
77
77
  export const currentGeneratedPackageScripts: Record<string, string> = {
78
78
  "db:reset": "tsx infra/db/reset.ts",
79
79
  "db:seed": "tsx server/seed.ts",
80
+ "db:status": "tsx infra/db/migration-status.ts",
80
81
  test: "node --import tsx lib/beignet-test-runner.ts",
81
82
  };
82
83