@supatype/cli 0.1.0-alpha.6
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/.turbo/turbo-build.log +4 -0
- package/.turbo/turbo-test.log +7 -0
- package/.turbo/turbo-typecheck.log +4 -0
- package/bin/dev-entry.ts +2 -0
- package/bin/supatype.js +5 -0
- package/dist/app/framework.d.ts +44 -0
- package/dist/app/framework.d.ts.map +1 -0
- package/dist/app/framework.js +200 -0
- package/dist/app/framework.js.map +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +55 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/admin.d.ts +4 -0
- package/dist/commands/admin.d.ts.map +1 -0
- package/dist/commands/admin.js +270 -0
- package/dist/commands/admin.js.map +1 -0
- package/dist/commands/app.d.ts +3 -0
- package/dist/commands/app.d.ts.map +1 -0
- package/dist/commands/app.js +235 -0
- package/dist/commands/app.js.map +1 -0
- package/dist/commands/cloud.d.ts +3 -0
- package/dist/commands/cloud.d.ts.map +1 -0
- package/dist/commands/cloud.js +256 -0
- package/dist/commands/cloud.js.map +1 -0
- package/dist/commands/db.d.ts +8 -0
- package/dist/commands/db.d.ts.map +1 -0
- package/dist/commands/db.js +123 -0
- package/dist/commands/db.js.map +1 -0
- package/dist/commands/deploy-types.d.ts +14 -0
- package/dist/commands/deploy-types.d.ts.map +1 -0
- package/dist/commands/deploy-types.js +38 -0
- package/dist/commands/deploy-types.js.map +1 -0
- package/dist/commands/deploy.d.ts +14 -0
- package/dist/commands/deploy.d.ts.map +1 -0
- package/dist/commands/deploy.js +295 -0
- package/dist/commands/deploy.js.map +1 -0
- package/dist/commands/dev.d.ts +3 -0
- package/dist/commands/dev.d.ts.map +1 -0
- package/dist/commands/dev.js +428 -0
- package/dist/commands/dev.js.map +1 -0
- package/dist/commands/diff.d.ts +3 -0
- package/dist/commands/diff.d.ts.map +1 -0
- package/dist/commands/diff.js +39 -0
- package/dist/commands/diff.js.map +1 -0
- package/dist/commands/engine.d.ts +9 -0
- package/dist/commands/engine.d.ts.map +1 -0
- package/dist/commands/engine.js +99 -0
- package/dist/commands/engine.js.map +1 -0
- package/dist/commands/functions.d.ts +3 -0
- package/dist/commands/functions.d.ts.map +1 -0
- package/dist/commands/functions.js +762 -0
- package/dist/commands/functions.js.map +1 -0
- package/dist/commands/generate.d.ts +3 -0
- package/dist/commands/generate.d.ts.map +1 -0
- package/dist/commands/generate.js +28 -0
- package/dist/commands/generate.js.map +1 -0
- package/dist/commands/init.d.ts +7 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +515 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/keys.d.ts +4 -0
- package/dist/commands/keys.d.ts.map +1 -0
- package/dist/commands/keys.js +57 -0
- package/dist/commands/keys.js.map +1 -0
- package/dist/commands/logs.d.ts +6 -0
- package/dist/commands/logs.d.ts.map +1 -0
- package/dist/commands/logs.js +52 -0
- package/dist/commands/logs.js.map +1 -0
- package/dist/commands/migrate.d.ts +3 -0
- package/dist/commands/migrate.d.ts.map +1 -0
- package/dist/commands/migrate.js +71 -0
- package/dist/commands/migrate.js.map +1 -0
- package/dist/commands/plugins.d.ts +3 -0
- package/dist/commands/plugins.d.ts.map +1 -0
- package/dist/commands/plugins.js +431 -0
- package/dist/commands/plugins.js.map +1 -0
- package/dist/commands/pull.d.ts +3 -0
- package/dist/commands/pull.d.ts.map +1 -0
- package/dist/commands/pull.js +73 -0
- package/dist/commands/pull.js.map +1 -0
- package/dist/commands/push.d.ts +3 -0
- package/dist/commands/push.d.ts.map +1 -0
- package/dist/commands/push.js +87 -0
- package/dist/commands/push.js.map +1 -0
- package/dist/commands/seed.d.ts +3 -0
- package/dist/commands/seed.d.ts.map +1 -0
- package/dist/commands/seed.js +22 -0
- package/dist/commands/seed.js.map +1 -0
- package/dist/commands/self-host.d.ts +3 -0
- package/dist/commands/self-host.d.ts.map +1 -0
- package/dist/commands/self-host.js +796 -0
- package/dist/commands/self-host.js.map +1 -0
- package/dist/commands/status.d.ts +6 -0
- package/dist/commands/status.d.ts.map +1 -0
- package/dist/commands/status.js +69 -0
- package/dist/commands/status.js.map +1 -0
- package/dist/config.d.ts +106 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +66 -0
- package/dist/config.js.map +1 -0
- package/dist/engine/cache.d.ts +37 -0
- package/dist/engine/cache.d.ts.map +1 -0
- package/dist/engine/cache.js +121 -0
- package/dist/engine/cache.js.map +1 -0
- package/dist/engine/download.d.ts +19 -0
- package/dist/engine/download.d.ts.map +1 -0
- package/dist/engine/download.js +108 -0
- package/dist/engine/download.js.map +1 -0
- package/dist/engine/platform.d.ts +24 -0
- package/dist/engine/platform.d.ts.map +1 -0
- package/dist/engine/platform.js +50 -0
- package/dist/engine/platform.js.map +1 -0
- package/dist/engine/resolve.d.ts +37 -0
- package/dist/engine/resolve.d.ts.map +1 -0
- package/dist/engine/resolve.js +133 -0
- package/dist/engine/resolve.js.map +1 -0
- package/dist/engine/update-notify.d.ts +11 -0
- package/dist/engine/update-notify.d.ts.map +1 -0
- package/dist/engine/update-notify.js +43 -0
- package/dist/engine/update-notify.js.map +1 -0
- package/dist/engine/verify.d.ts +50 -0
- package/dist/engine/verify.d.ts.map +1 -0
- package/dist/engine/verify.js +161 -0
- package/dist/engine/verify.js.map +1 -0
- package/dist/engine-version.d.ts +35 -0
- package/dist/engine-version.d.ts.map +1 -0
- package/dist/engine-version.js +35 -0
- package/dist/engine-version.js.map +1 -0
- package/dist/engine.d.ts +34 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +76 -0
- package/dist/engine.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/jwt.d.ts +3 -0
- package/dist/jwt.d.ts.map +1 -0
- package/dist/jwt.js +13 -0
- package/dist/jwt.js.map +1 -0
- package/dist/pull-utils.d.ts +16 -0
- package/dist/pull-utils.d.ts.map +1 -0
- package/dist/pull-utils.js +65 -0
- package/dist/pull-utils.js.map +1 -0
- package/dist/scripts/postinstall.d.ts +12 -0
- package/dist/scripts/postinstall.d.ts.map +1 -0
- package/dist/scripts/postinstall.js +31 -0
- package/dist/scripts/postinstall.js.map +1 -0
- package/dist/tsx-runner.d.ts +18 -0
- package/dist/tsx-runner.d.ts.map +1 -0
- package/dist/tsx-runner.js +62 -0
- package/dist/tsx-runner.js.map +1 -0
- package/package.json +36 -0
- package/src/app/framework.ts +249 -0
- package/src/cli.ts +58 -0
- package/src/commands/admin.ts +371 -0
- package/src/commands/app.ts +261 -0
- package/src/commands/cloud.ts +326 -0
- package/src/commands/db.ts +145 -0
- package/src/commands/deploy-types.ts +49 -0
- package/src/commands/deploy.ts +366 -0
- package/src/commands/dev.ts +477 -0
- package/src/commands/diff.ts +61 -0
- package/src/commands/engine.ts +133 -0
- package/src/commands/functions.ts +919 -0
- package/src/commands/generate.ts +31 -0
- package/src/commands/init.ts +532 -0
- package/src/commands/keys.ts +66 -0
- package/src/commands/logs.ts +58 -0
- package/src/commands/migrate.ts +83 -0
- package/src/commands/plugins.ts +508 -0
- package/src/commands/pull.ts +96 -0
- package/src/commands/push.ts +119 -0
- package/src/commands/seed.ts +26 -0
- package/src/commands/self-host.ts +932 -0
- package/src/commands/status.ts +83 -0
- package/src/config.ts +190 -0
- package/src/engine/cache.ts +135 -0
- package/src/engine/download.ts +143 -0
- package/src/engine/platform.ts +66 -0
- package/src/engine/resolve.ts +197 -0
- package/src/engine/update-notify.ts +50 -0
- package/src/engine/verify.ts +206 -0
- package/src/engine-version.ts +39 -0
- package/src/engine.ts +99 -0
- package/src/index.ts +19 -0
- package/src/jwt.ts +14 -0
- package/src/pull-utils.ts +57 -0
- package/src/scripts/postinstall.ts +40 -0
- package/src/tsx-runner.ts +79 -0
- package/tests/cli-help.test.ts +107 -0
- package/tests/config.test.ts +117 -0
- package/tests/engine-distribution.test.ts +418 -0
- package/tests/init.test.ts +184 -0
- package/tests/keys.test.ts +160 -0
- package/tests/pull-utils.test.ts +115 -0
- package/tests/tsx-runner.test.ts +66 -0
- package/tsconfig.json +10 -0
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import type { Command } from "commander"
|
|
2
|
+
import { createInterface } from "node:readline"
|
|
3
|
+
import { loadConfig, loadSchemaAst } from "../config.js"
|
|
4
|
+
import { ensureEngine, invokeEngine } from "../engine.js"
|
|
5
|
+
import { promptFirstAdminUser } from "./admin.js"
|
|
6
|
+
interface DiffResult {
|
|
7
|
+
operations: Operation[]
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface Operation {
|
|
11
|
+
kind: string
|
|
12
|
+
risk: "safe" | "cautious" | "destructive"
|
|
13
|
+
description: string
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function registerPush(program: Command): void {
|
|
17
|
+
program
|
|
18
|
+
.command("push")
|
|
19
|
+
.description(
|
|
20
|
+
"Push schema to the database: diff, prompt for destructive changes, apply migration, generate types",
|
|
21
|
+
)
|
|
22
|
+
.option("--yes", "Skip confirmation prompts for destructive changes")
|
|
23
|
+
.option("--connection <url>", "Database connection URL (overrides config)")
|
|
24
|
+
.action(async (opts: { yes?: boolean; connection?: string }) => {
|
|
25
|
+
const cwd = process.cwd()
|
|
26
|
+
const config = loadConfig(cwd)
|
|
27
|
+
const connection = opts.connection ?? config.connection
|
|
28
|
+
|
|
29
|
+
await ensureEngine()
|
|
30
|
+
|
|
31
|
+
console.log("Loading schema...")
|
|
32
|
+
const ast = loadSchemaAst(config.schema, cwd)
|
|
33
|
+
|
|
34
|
+
// Validate configured providers before diffing
|
|
35
|
+
console.log("Diffing against database...")
|
|
36
|
+
const diffResult = invokeEngine(
|
|
37
|
+
["diff", "--connection", connection, "--format", "json"],
|
|
38
|
+
JSON.stringify(ast),
|
|
39
|
+
)
|
|
40
|
+
if (diffResult.exitCode !== 0) {
|
|
41
|
+
console.error(diffResult.stderr || diffResult.stdout)
|
|
42
|
+
process.exit(1)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const diff = JSON.parse(diffResult.stdout) as DiffResult
|
|
46
|
+
const ops = diff.operations ?? []
|
|
47
|
+
|
|
48
|
+
if (ops.length === 0) {
|
|
49
|
+
console.log("Schema is up to date. Nothing to push.")
|
|
50
|
+
return
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
printDiff(ops)
|
|
54
|
+
|
|
55
|
+
const destructive = ops.filter((o) => o.risk === "destructive")
|
|
56
|
+
if (destructive.length > 0 && !opts.yes) {
|
|
57
|
+
const confirmed = await confirm(
|
|
58
|
+
`\n${destructive.length} destructive operation(s) above. Proceed? [y/N] `,
|
|
59
|
+
)
|
|
60
|
+
if (!confirmed) {
|
|
61
|
+
console.log("Aborted.")
|
|
62
|
+
return
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
console.log("\nApplying migration...")
|
|
67
|
+
const migrateResult = invokeEngine(
|
|
68
|
+
["migrate", "--connection", connection],
|
|
69
|
+
JSON.stringify(ast),
|
|
70
|
+
)
|
|
71
|
+
if (migrateResult.exitCode !== 0) {
|
|
72
|
+
console.error(migrateResult.stderr || migrateResult.stdout)
|
|
73
|
+
process.exit(1)
|
|
74
|
+
}
|
|
75
|
+
console.log(migrateResult.stdout || "Migration applied.")
|
|
76
|
+
|
|
77
|
+
// After migration, check if this is the first push and offer to create an
|
|
78
|
+
// admin user if none exist (Gap Appendices task 48).
|
|
79
|
+
await promptFirstAdminUser(connection)
|
|
80
|
+
|
|
81
|
+
if (config.output?.types ?? config.output?.client) {
|
|
82
|
+
console.log("Generating types...")
|
|
83
|
+
const genArgs = ["generate", "--connection", connection]
|
|
84
|
+
if (config.output?.types) genArgs.push("--types", config.output.types)
|
|
85
|
+
if (config.output?.client) genArgs.push("--client", config.output.client)
|
|
86
|
+
|
|
87
|
+
const genResult = invokeEngine(genArgs, JSON.stringify(ast))
|
|
88
|
+
if (genResult.exitCode !== 0) {
|
|
89
|
+
console.error(genResult.stderr || genResult.stdout)
|
|
90
|
+
process.exit(1)
|
|
91
|
+
}
|
|
92
|
+
console.log(genResult.stdout || "Types generated.")
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
console.log("\nDone.")
|
|
96
|
+
})
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function printDiff(ops: Operation[]): void {
|
|
100
|
+
const symbol: Record<Operation["risk"], string> = {
|
|
101
|
+
safe: "+",
|
|
102
|
+
cautious: "~",
|
|
103
|
+
destructive: "!",
|
|
104
|
+
}
|
|
105
|
+
console.log(`\n${ops.length} change(s) planned:\n`)
|
|
106
|
+
for (const op of ops) {
|
|
107
|
+
console.log(` [${symbol[op.risk]}] ${op.description}`)
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async function confirm(prompt: string): Promise<boolean> {
|
|
112
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout })
|
|
113
|
+
return new Promise((resolve) => {
|
|
114
|
+
rl.question(prompt, (answer) => {
|
|
115
|
+
rl.close()
|
|
116
|
+
resolve(answer.toLowerCase() === "y")
|
|
117
|
+
})
|
|
118
|
+
})
|
|
119
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Command } from "commander"
|
|
2
|
+
import { existsSync } from "node:fs"
|
|
3
|
+
import { resolve } from "node:path"
|
|
4
|
+
import { runTsFile } from "../tsx-runner.js"
|
|
5
|
+
|
|
6
|
+
export function registerSeed(program: Command): void {
|
|
7
|
+
program
|
|
8
|
+
.command("seed [file]")
|
|
9
|
+
.description("Run seed.ts (or a custom seed file) against the database")
|
|
10
|
+
.action((file?: string) => {
|
|
11
|
+
const cwd = process.cwd()
|
|
12
|
+
const seedFile = resolve(cwd, file ?? "seed.ts")
|
|
13
|
+
|
|
14
|
+
if (!existsSync(seedFile)) {
|
|
15
|
+
console.error(`Seed file not found: ${seedFile}`)
|
|
16
|
+
process.exit(1)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
console.log(`Running ${seedFile}...`)
|
|
20
|
+
const result = runTsFile(seedFile, { cwd, stdio: "inherit" })
|
|
21
|
+
|
|
22
|
+
if (result.exitCode !== 0) {
|
|
23
|
+
process.exit(result.exitCode)
|
|
24
|
+
}
|
|
25
|
+
})
|
|
26
|
+
}
|