@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.
Files changed (200) hide show
  1. package/.turbo/turbo-build.log +4 -0
  2. package/.turbo/turbo-test.log +7 -0
  3. package/.turbo/turbo-typecheck.log +4 -0
  4. package/bin/dev-entry.ts +2 -0
  5. package/bin/supatype.js +5 -0
  6. package/dist/app/framework.d.ts +44 -0
  7. package/dist/app/framework.d.ts.map +1 -0
  8. package/dist/app/framework.js +200 -0
  9. package/dist/app/framework.js.map +1 -0
  10. package/dist/cli.d.ts +2 -0
  11. package/dist/cli.d.ts.map +1 -0
  12. package/dist/cli.js +55 -0
  13. package/dist/cli.js.map +1 -0
  14. package/dist/commands/admin.d.ts +4 -0
  15. package/dist/commands/admin.d.ts.map +1 -0
  16. package/dist/commands/admin.js +270 -0
  17. package/dist/commands/admin.js.map +1 -0
  18. package/dist/commands/app.d.ts +3 -0
  19. package/dist/commands/app.d.ts.map +1 -0
  20. package/dist/commands/app.js +235 -0
  21. package/dist/commands/app.js.map +1 -0
  22. package/dist/commands/cloud.d.ts +3 -0
  23. package/dist/commands/cloud.d.ts.map +1 -0
  24. package/dist/commands/cloud.js +256 -0
  25. package/dist/commands/cloud.js.map +1 -0
  26. package/dist/commands/db.d.ts +8 -0
  27. package/dist/commands/db.d.ts.map +1 -0
  28. package/dist/commands/db.js +123 -0
  29. package/dist/commands/db.js.map +1 -0
  30. package/dist/commands/deploy-types.d.ts +14 -0
  31. package/dist/commands/deploy-types.d.ts.map +1 -0
  32. package/dist/commands/deploy-types.js +38 -0
  33. package/dist/commands/deploy-types.js.map +1 -0
  34. package/dist/commands/deploy.d.ts +14 -0
  35. package/dist/commands/deploy.d.ts.map +1 -0
  36. package/dist/commands/deploy.js +295 -0
  37. package/dist/commands/deploy.js.map +1 -0
  38. package/dist/commands/dev.d.ts +3 -0
  39. package/dist/commands/dev.d.ts.map +1 -0
  40. package/dist/commands/dev.js +428 -0
  41. package/dist/commands/dev.js.map +1 -0
  42. package/dist/commands/diff.d.ts +3 -0
  43. package/dist/commands/diff.d.ts.map +1 -0
  44. package/dist/commands/diff.js +39 -0
  45. package/dist/commands/diff.js.map +1 -0
  46. package/dist/commands/engine.d.ts +9 -0
  47. package/dist/commands/engine.d.ts.map +1 -0
  48. package/dist/commands/engine.js +99 -0
  49. package/dist/commands/engine.js.map +1 -0
  50. package/dist/commands/functions.d.ts +3 -0
  51. package/dist/commands/functions.d.ts.map +1 -0
  52. package/dist/commands/functions.js +762 -0
  53. package/dist/commands/functions.js.map +1 -0
  54. package/dist/commands/generate.d.ts +3 -0
  55. package/dist/commands/generate.d.ts.map +1 -0
  56. package/dist/commands/generate.js +28 -0
  57. package/dist/commands/generate.js.map +1 -0
  58. package/dist/commands/init.d.ts +7 -0
  59. package/dist/commands/init.d.ts.map +1 -0
  60. package/dist/commands/init.js +515 -0
  61. package/dist/commands/init.js.map +1 -0
  62. package/dist/commands/keys.d.ts +4 -0
  63. package/dist/commands/keys.d.ts.map +1 -0
  64. package/dist/commands/keys.js +57 -0
  65. package/dist/commands/keys.js.map +1 -0
  66. package/dist/commands/logs.d.ts +6 -0
  67. package/dist/commands/logs.d.ts.map +1 -0
  68. package/dist/commands/logs.js +52 -0
  69. package/dist/commands/logs.js.map +1 -0
  70. package/dist/commands/migrate.d.ts +3 -0
  71. package/dist/commands/migrate.d.ts.map +1 -0
  72. package/dist/commands/migrate.js +71 -0
  73. package/dist/commands/migrate.js.map +1 -0
  74. package/dist/commands/plugins.d.ts +3 -0
  75. package/dist/commands/plugins.d.ts.map +1 -0
  76. package/dist/commands/plugins.js +431 -0
  77. package/dist/commands/plugins.js.map +1 -0
  78. package/dist/commands/pull.d.ts +3 -0
  79. package/dist/commands/pull.d.ts.map +1 -0
  80. package/dist/commands/pull.js +73 -0
  81. package/dist/commands/pull.js.map +1 -0
  82. package/dist/commands/push.d.ts +3 -0
  83. package/dist/commands/push.d.ts.map +1 -0
  84. package/dist/commands/push.js +87 -0
  85. package/dist/commands/push.js.map +1 -0
  86. package/dist/commands/seed.d.ts +3 -0
  87. package/dist/commands/seed.d.ts.map +1 -0
  88. package/dist/commands/seed.js +22 -0
  89. package/dist/commands/seed.js.map +1 -0
  90. package/dist/commands/self-host.d.ts +3 -0
  91. package/dist/commands/self-host.d.ts.map +1 -0
  92. package/dist/commands/self-host.js +796 -0
  93. package/dist/commands/self-host.js.map +1 -0
  94. package/dist/commands/status.d.ts +6 -0
  95. package/dist/commands/status.d.ts.map +1 -0
  96. package/dist/commands/status.js +69 -0
  97. package/dist/commands/status.js.map +1 -0
  98. package/dist/config.d.ts +106 -0
  99. package/dist/config.d.ts.map +1 -0
  100. package/dist/config.js +66 -0
  101. package/dist/config.js.map +1 -0
  102. package/dist/engine/cache.d.ts +37 -0
  103. package/dist/engine/cache.d.ts.map +1 -0
  104. package/dist/engine/cache.js +121 -0
  105. package/dist/engine/cache.js.map +1 -0
  106. package/dist/engine/download.d.ts +19 -0
  107. package/dist/engine/download.d.ts.map +1 -0
  108. package/dist/engine/download.js +108 -0
  109. package/dist/engine/download.js.map +1 -0
  110. package/dist/engine/platform.d.ts +24 -0
  111. package/dist/engine/platform.d.ts.map +1 -0
  112. package/dist/engine/platform.js +50 -0
  113. package/dist/engine/platform.js.map +1 -0
  114. package/dist/engine/resolve.d.ts +37 -0
  115. package/dist/engine/resolve.d.ts.map +1 -0
  116. package/dist/engine/resolve.js +133 -0
  117. package/dist/engine/resolve.js.map +1 -0
  118. package/dist/engine/update-notify.d.ts +11 -0
  119. package/dist/engine/update-notify.d.ts.map +1 -0
  120. package/dist/engine/update-notify.js +43 -0
  121. package/dist/engine/update-notify.js.map +1 -0
  122. package/dist/engine/verify.d.ts +50 -0
  123. package/dist/engine/verify.d.ts.map +1 -0
  124. package/dist/engine/verify.js +161 -0
  125. package/dist/engine/verify.js.map +1 -0
  126. package/dist/engine-version.d.ts +35 -0
  127. package/dist/engine-version.d.ts.map +1 -0
  128. package/dist/engine-version.js +35 -0
  129. package/dist/engine-version.js.map +1 -0
  130. package/dist/engine.d.ts +34 -0
  131. package/dist/engine.d.ts.map +1 -0
  132. package/dist/engine.js +76 -0
  133. package/dist/engine.js.map +1 -0
  134. package/dist/index.d.ts +12 -0
  135. package/dist/index.d.ts.map +1 -0
  136. package/dist/index.js +10 -0
  137. package/dist/index.js.map +1 -0
  138. package/dist/jwt.d.ts +3 -0
  139. package/dist/jwt.d.ts.map +1 -0
  140. package/dist/jwt.js +13 -0
  141. package/dist/jwt.js.map +1 -0
  142. package/dist/pull-utils.d.ts +16 -0
  143. package/dist/pull-utils.d.ts.map +1 -0
  144. package/dist/pull-utils.js +65 -0
  145. package/dist/pull-utils.js.map +1 -0
  146. package/dist/scripts/postinstall.d.ts +12 -0
  147. package/dist/scripts/postinstall.d.ts.map +1 -0
  148. package/dist/scripts/postinstall.js +31 -0
  149. package/dist/scripts/postinstall.js.map +1 -0
  150. package/dist/tsx-runner.d.ts +18 -0
  151. package/dist/tsx-runner.d.ts.map +1 -0
  152. package/dist/tsx-runner.js +62 -0
  153. package/dist/tsx-runner.js.map +1 -0
  154. package/package.json +36 -0
  155. package/src/app/framework.ts +249 -0
  156. package/src/cli.ts +58 -0
  157. package/src/commands/admin.ts +371 -0
  158. package/src/commands/app.ts +261 -0
  159. package/src/commands/cloud.ts +326 -0
  160. package/src/commands/db.ts +145 -0
  161. package/src/commands/deploy-types.ts +49 -0
  162. package/src/commands/deploy.ts +366 -0
  163. package/src/commands/dev.ts +477 -0
  164. package/src/commands/diff.ts +61 -0
  165. package/src/commands/engine.ts +133 -0
  166. package/src/commands/functions.ts +919 -0
  167. package/src/commands/generate.ts +31 -0
  168. package/src/commands/init.ts +532 -0
  169. package/src/commands/keys.ts +66 -0
  170. package/src/commands/logs.ts +58 -0
  171. package/src/commands/migrate.ts +83 -0
  172. package/src/commands/plugins.ts +508 -0
  173. package/src/commands/pull.ts +96 -0
  174. package/src/commands/push.ts +119 -0
  175. package/src/commands/seed.ts +26 -0
  176. package/src/commands/self-host.ts +932 -0
  177. package/src/commands/status.ts +83 -0
  178. package/src/config.ts +190 -0
  179. package/src/engine/cache.ts +135 -0
  180. package/src/engine/download.ts +143 -0
  181. package/src/engine/platform.ts +66 -0
  182. package/src/engine/resolve.ts +197 -0
  183. package/src/engine/update-notify.ts +50 -0
  184. package/src/engine/verify.ts +206 -0
  185. package/src/engine-version.ts +39 -0
  186. package/src/engine.ts +99 -0
  187. package/src/index.ts +19 -0
  188. package/src/jwt.ts +14 -0
  189. package/src/pull-utils.ts +57 -0
  190. package/src/scripts/postinstall.ts +40 -0
  191. package/src/tsx-runner.ts +79 -0
  192. package/tests/cli-help.test.ts +107 -0
  193. package/tests/config.test.ts +117 -0
  194. package/tests/engine-distribution.test.ts +418 -0
  195. package/tests/init.test.ts +184 -0
  196. package/tests/keys.test.ts +160 -0
  197. package/tests/pull-utils.test.ts +115 -0
  198. package/tests/tsx-runner.test.ts +66 -0
  199. package/tsconfig.json +10 -0
  200. 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
+ }