@supatype/cli 0.1.0-alpha.10

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 (416) hide show
  1. package/.turbo/turbo-build.log +4 -0
  2. package/.turbo/turbo-test.log +221 -0
  3. package/.turbo/turbo-typecheck.log +4 -0
  4. package/assets/supatype-logo-wordmark.ascii.txt +6 -0
  5. package/bin/dev-entry.ts +2 -0
  6. package/bin/supatype.js +5 -0
  7. package/dist/app/framework.d.ts +44 -0
  8. package/dist/app/framework.d.ts.map +1 -0
  9. package/dist/app/framework.js +200 -0
  10. package/dist/app/framework.js.map +1 -0
  11. package/dist/app/proxy-dev-app.d.ts +13 -0
  12. package/dist/app/proxy-dev-app.d.ts.map +1 -0
  13. package/dist/app/proxy-dev-app.js +54 -0
  14. package/dist/app/proxy-dev-app.js.map +1 -0
  15. package/dist/app-config.d.ts +7 -0
  16. package/dist/app-config.d.ts.map +1 -0
  17. package/dist/app-config.js +113 -0
  18. package/dist/app-config.js.map +1 -0
  19. package/dist/assets/supatype-logo-wordmark.ascii.txt +6 -0
  20. package/dist/augmentation-generator.d.ts +2 -0
  21. package/dist/augmentation-generator.d.ts.map +1 -0
  22. package/dist/augmentation-generator.js +111 -0
  23. package/dist/augmentation-generator.js.map +1 -0
  24. package/dist/binary-cache.d.ts +98 -0
  25. package/dist/binary-cache.d.ts.map +1 -0
  26. package/dist/binary-cache.js +687 -0
  27. package/dist/binary-cache.js.map +1 -0
  28. package/dist/cli.d.ts +2 -0
  29. package/dist/cli.d.ts.map +1 -0
  30. package/dist/cli.js +61 -0
  31. package/dist/cli.js.map +1 -0
  32. package/dist/commands/admin.d.ts +4 -0
  33. package/dist/commands/admin.d.ts.map +1 -0
  34. package/dist/commands/admin.js +271 -0
  35. package/dist/commands/admin.js.map +1 -0
  36. package/dist/commands/app.d.ts +3 -0
  37. package/dist/commands/app.d.ts.map +1 -0
  38. package/dist/commands/app.js +82 -0
  39. package/dist/commands/app.js.map +1 -0
  40. package/dist/commands/cache.d.ts +6 -0
  41. package/dist/commands/cache.d.ts.map +1 -0
  42. package/dist/commands/cache.js +105 -0
  43. package/dist/commands/cache.js.map +1 -0
  44. package/dist/commands/cloud.d.ts +23 -0
  45. package/dist/commands/cloud.d.ts.map +1 -0
  46. package/dist/commands/cloud.js +254 -0
  47. package/dist/commands/cloud.js.map +1 -0
  48. package/dist/commands/db.d.ts +8 -0
  49. package/dist/commands/db.d.ts.map +1 -0
  50. package/dist/commands/db.js +116 -0
  51. package/dist/commands/db.js.map +1 -0
  52. package/dist/commands/deploy-types.d.ts +14 -0
  53. package/dist/commands/deploy-types.d.ts.map +1 -0
  54. package/dist/commands/deploy-types.js +38 -0
  55. package/dist/commands/deploy-types.js.map +1 -0
  56. package/dist/commands/deploy.d.ts +15 -0
  57. package/dist/commands/deploy.d.ts.map +1 -0
  58. package/dist/commands/deploy.js +322 -0
  59. package/dist/commands/deploy.js.map +1 -0
  60. package/dist/commands/dev.d.ts +14 -0
  61. package/dist/commands/dev.d.ts.map +1 -0
  62. package/dist/commands/dev.js +806 -0
  63. package/dist/commands/dev.js.map +1 -0
  64. package/dist/commands/diff.d.ts +3 -0
  65. package/dist/commands/diff.d.ts.map +1 -0
  66. package/dist/commands/diff.js +54 -0
  67. package/dist/commands/diff.js.map +1 -0
  68. package/dist/commands/engine.d.ts +7 -0
  69. package/dist/commands/engine.d.ts.map +1 -0
  70. package/dist/commands/engine.js +27 -0
  71. package/dist/commands/engine.js.map +1 -0
  72. package/dist/commands/functions.d.ts +3 -0
  73. package/dist/commands/functions.d.ts.map +1 -0
  74. package/dist/commands/functions.js +749 -0
  75. package/dist/commands/functions.js.map +1 -0
  76. package/dist/commands/generate.d.ts +3 -0
  77. package/dist/commands/generate.d.ts.map +1 -0
  78. package/dist/commands/generate.js +38 -0
  79. package/dist/commands/generate.js.map +1 -0
  80. package/dist/commands/init.d.ts +7 -0
  81. package/dist/commands/init.d.ts.map +1 -0
  82. package/dist/commands/init.js +228 -0
  83. package/dist/commands/init.js.map +1 -0
  84. package/dist/commands/keys.d.ts +4 -0
  85. package/dist/commands/keys.d.ts.map +1 -0
  86. package/dist/commands/keys.js +57 -0
  87. package/dist/commands/keys.js.map +1 -0
  88. package/dist/commands/logs.d.ts +6 -0
  89. package/dist/commands/logs.d.ts.map +1 -0
  90. package/dist/commands/logs.js +52 -0
  91. package/dist/commands/logs.js.map +1 -0
  92. package/dist/commands/migrate-from-v1.d.ts +5 -0
  93. package/dist/commands/migrate-from-v1.d.ts.map +1 -0
  94. package/dist/commands/migrate-from-v1.js +125 -0
  95. package/dist/commands/migrate-from-v1.js.map +1 -0
  96. package/dist/commands/migrate.d.ts +3 -0
  97. package/dist/commands/migrate.d.ts.map +1 -0
  98. package/dist/commands/migrate.js +75 -0
  99. package/dist/commands/migrate.js.map +1 -0
  100. package/dist/commands/pg.d.ts +8 -0
  101. package/dist/commands/pg.d.ts.map +1 -0
  102. package/dist/commands/pg.js +102 -0
  103. package/dist/commands/pg.js.map +1 -0
  104. package/dist/commands/plugins.d.ts +3 -0
  105. package/dist/commands/plugins.d.ts.map +1 -0
  106. package/dist/commands/plugins.js +431 -0
  107. package/dist/commands/plugins.js.map +1 -0
  108. package/dist/commands/pull.d.ts +3 -0
  109. package/dist/commands/pull.d.ts.map +1 -0
  110. package/dist/commands/pull.js +12 -0
  111. package/dist/commands/pull.js.map +1 -0
  112. package/dist/commands/push.d.ts +3 -0
  113. package/dist/commands/push.d.ts.map +1 -0
  114. package/dist/commands/push.js +179 -0
  115. package/dist/commands/push.js.map +1 -0
  116. package/dist/commands/seed.d.ts +5 -0
  117. package/dist/commands/seed.d.ts.map +1 -0
  118. package/dist/commands/seed.js +55 -0
  119. package/dist/commands/seed.js.map +1 -0
  120. package/dist/commands/self-host.d.ts +9 -0
  121. package/dist/commands/self-host.d.ts.map +1 -0
  122. package/dist/commands/self-host.js +310 -0
  123. package/dist/commands/self-host.js.map +1 -0
  124. package/dist/commands/self-update.d.ts +9 -0
  125. package/dist/commands/self-update.d.ts.map +1 -0
  126. package/dist/commands/self-update.js +33 -0
  127. package/dist/commands/self-update.js.map +1 -0
  128. package/dist/commands/status.d.ts +6 -0
  129. package/dist/commands/status.d.ts.map +1 -0
  130. package/dist/commands/status.js +70 -0
  131. package/dist/commands/status.js.map +1 -0
  132. package/dist/commands/types.d.ts +3 -0
  133. package/dist/commands/types.d.ts.map +1 -0
  134. package/dist/commands/types.js +62 -0
  135. package/dist/commands/types.js.map +1 -0
  136. package/dist/commands/update.d.ts +7 -0
  137. package/dist/commands/update.d.ts.map +1 -0
  138. package/dist/commands/update.js +118 -0
  139. package/dist/commands/update.js.map +1 -0
  140. package/dist/components.d.ts +5 -0
  141. package/dist/components.d.ts.map +1 -0
  142. package/dist/components.js +3 -0
  143. package/dist/components.js.map +1 -0
  144. package/dist/config.d.ts +65 -0
  145. package/dist/config.d.ts.map +1 -0
  146. package/dist/config.js +134 -0
  147. package/dist/config.js.map +1 -0
  148. package/dist/dev-compose.d.ts +19 -0
  149. package/dist/dev-compose.d.ts.map +1 -0
  150. package/dist/dev-compose.js +468 -0
  151. package/dist/dev-compose.js.map +1 -0
  152. package/dist/dev-log-bus.d.ts +30 -0
  153. package/dist/dev-log-bus.d.ts.map +1 -0
  154. package/dist/dev-log-bus.js +87 -0
  155. package/dist/dev-log-bus.js.map +1 -0
  156. package/dist/dev-log-filter.d.ts +10 -0
  157. package/dist/dev-log-filter.d.ts.map +1 -0
  158. package/dist/dev-log-filter.js +36 -0
  159. package/dist/dev-log-filter.js.map +1 -0
  160. package/dist/dev-logo.d.ts +12 -0
  161. package/dist/dev-logo.d.ts.map +1 -0
  162. package/dist/dev-logo.js +57 -0
  163. package/dist/dev-logo.js.map +1 -0
  164. package/dist/dev-session.d.ts +26 -0
  165. package/dist/dev-session.d.ts.map +1 -0
  166. package/dist/dev-session.js +106 -0
  167. package/dist/dev-session.js.map +1 -0
  168. package/dist/dev-shutdown.d.ts +9 -0
  169. package/dist/dev-shutdown.d.ts.map +1 -0
  170. package/dist/dev-shutdown.js +50 -0
  171. package/dist/dev-shutdown.js.map +1 -0
  172. package/dist/dev-task-colors.d.ts +14 -0
  173. package/dist/dev-task-colors.d.ts.map +1 -0
  174. package/dist/dev-task-colors.js +44 -0
  175. package/dist/dev-task-colors.js.map +1 -0
  176. package/dist/dev-tui.d.ts +24 -0
  177. package/dist/dev-tui.d.ts.map +1 -0
  178. package/dist/dev-tui.js +188 -0
  179. package/dist/dev-tui.js.map +1 -0
  180. package/dist/diff-output.d.ts +4 -0
  181. package/dist/diff-output.d.ts.map +1 -0
  182. package/dist/diff-output.js +12 -0
  183. package/dist/diff-output.js.map +1 -0
  184. package/dist/docker-postgres.d.ts +57 -0
  185. package/dist/docker-postgres.d.ts.map +1 -0
  186. package/dist/docker-postgres.js +208 -0
  187. package/dist/docker-postgres.js.map +1 -0
  188. package/dist/engine-client.d.ts +69 -0
  189. package/dist/engine-client.d.ts.map +1 -0
  190. package/dist/engine-client.js +157 -0
  191. package/dist/engine-client.js.map +1 -0
  192. package/dist/engine-push-output.d.ts +16 -0
  193. package/dist/engine-push-output.d.ts.map +1 -0
  194. package/dist/engine-push-output.js +61 -0
  195. package/dist/engine-push-output.js.map +1 -0
  196. package/dist/ensure-binary.d.ts +7 -0
  197. package/dist/ensure-binary.d.ts.map +1 -0
  198. package/dist/ensure-binary.js +17 -0
  199. package/dist/ensure-binary.js.map +1 -0
  200. package/dist/functions-router-gen.d.ts +14 -0
  201. package/dist/functions-router-gen.d.ts.map +1 -0
  202. package/dist/functions-router-gen.js +199 -0
  203. package/dist/functions-router-gen.js.map +1 -0
  204. package/dist/index.d.ts +11 -0
  205. package/dist/index.d.ts.map +1 -0
  206. package/dist/index.js +9 -0
  207. package/dist/index.js.map +1 -0
  208. package/dist/jwt.d.ts +3 -0
  209. package/dist/jwt.d.ts.map +1 -0
  210. package/dist/jwt.js +13 -0
  211. package/dist/jwt.js.map +1 -0
  212. package/dist/kong-config.d.ts +25 -0
  213. package/dist/kong-config.d.ts.map +1 -0
  214. package/dist/kong-config.js +71 -0
  215. package/dist/kong-config.js.map +1 -0
  216. package/dist/local-gateway.d.ts +7 -0
  217. package/dist/local-gateway.d.ts.map +1 -0
  218. package/dist/local-gateway.js +9 -0
  219. package/dist/local-gateway.js.map +1 -0
  220. package/dist/local-storage.d.ts +8 -0
  221. package/dist/local-storage.d.ts.map +1 -0
  222. package/dist/local-storage.js +14 -0
  223. package/dist/local-storage.js.map +1 -0
  224. package/dist/pgbouncer-userlist.d.ts +5 -0
  225. package/dist/pgbouncer-userlist.d.ts.map +1 -0
  226. package/dist/pgbouncer-userlist.js +14 -0
  227. package/dist/pgbouncer-userlist.js.map +1 -0
  228. package/dist/postgres-ctl.d.ts +44 -0
  229. package/dist/postgres-ctl.d.ts.map +1 -0
  230. package/dist/postgres-ctl.js +137 -0
  231. package/dist/postgres-ctl.js.map +1 -0
  232. package/dist/process-manager.d.ts +49 -0
  233. package/dist/process-manager.d.ts.map +1 -0
  234. package/dist/process-manager.js +177 -0
  235. package/dist/process-manager.js.map +1 -0
  236. package/dist/project-config.d.ts +238 -0
  237. package/dist/project-config.d.ts.map +1 -0
  238. package/dist/project-config.js +159 -0
  239. package/dist/project-config.js.map +1 -0
  240. package/dist/pull-utils.d.ts +31 -0
  241. package/dist/pull-utils.d.ts.map +1 -0
  242. package/dist/pull-utils.js +77 -0
  243. package/dist/pull-utils.js.map +1 -0
  244. package/dist/release-pins.d.ts +7 -0
  245. package/dist/release-pins.d.ts.map +1 -0
  246. package/dist/release-pins.js +27 -0
  247. package/dist/release-pins.js.map +1 -0
  248. package/dist/release-public-key.d.ts +8 -0
  249. package/dist/release-public-key.d.ts.map +1 -0
  250. package/dist/release-public-key.js +13 -0
  251. package/dist/release-public-key.js.map +1 -0
  252. package/dist/restore-system-relation-targets.d.ts +3 -0
  253. package/dist/restore-system-relation-targets.d.ts.map +1 -0
  254. package/dist/restore-system-relation-targets.js +45 -0
  255. package/dist/restore-system-relation-targets.js.map +1 -0
  256. package/dist/runtime-routes.d.ts +34 -0
  257. package/dist/runtime-routes.d.ts.map +1 -0
  258. package/dist/runtime-routes.js +252 -0
  259. package/dist/runtime-routes.js.map +1 -0
  260. package/dist/schema-ast-v2.d.ts +127 -0
  261. package/dist/schema-ast-v2.d.ts.map +1 -0
  262. package/dist/schema-ast-v2.js +226 -0
  263. package/dist/schema-ast-v2.js.map +1 -0
  264. package/dist/scripts/postinstall.d.ts +11 -0
  265. package/dist/scripts/postinstall.d.ts.map +1 -0
  266. package/dist/scripts/postinstall.js +47 -0
  267. package/dist/scripts/postinstall.js.map +1 -0
  268. package/dist/seed.d.ts +8 -0
  269. package/dist/seed.d.ts.map +1 -0
  270. package/dist/seed.js +32 -0
  271. package/dist/seed.js.map +1 -0
  272. package/dist/self-host-compose.d.ts +43 -0
  273. package/dist/self-host-compose.d.ts.map +1 -0
  274. package/dist/self-host-compose.js +400 -0
  275. package/dist/self-host-compose.js.map +1 -0
  276. package/dist/storage-provision.d.ts +24 -0
  277. package/dist/storage-provision.d.ts.map +1 -0
  278. package/dist/storage-provision.js +44 -0
  279. package/dist/storage-provision.js.map +1 -0
  280. package/dist/studio-admin-roles.d.ts +7 -0
  281. package/dist/studio-admin-roles.d.ts.map +1 -0
  282. package/dist/studio-admin-roles.js +14 -0
  283. package/dist/studio-admin-roles.js.map +1 -0
  284. package/dist/studio-dev-server.d.ts +22 -0
  285. package/dist/studio-dev-server.d.ts.map +1 -0
  286. package/dist/studio-dev-server.js +28 -0
  287. package/dist/studio-dev-server.js.map +1 -0
  288. package/dist/supatype-eval-1781522769253.d.mts +2 -0
  289. package/dist/supatype-eval-1781522769253.d.mts.map +1 -0
  290. package/dist/supatype-eval-1781522769253.mjs +3 -0
  291. package/dist/supatype-eval-1781522769253.mjs.map +1 -0
  292. package/dist/systemd.d.ts +26 -0
  293. package/dist/systemd.d.ts.map +1 -0
  294. package/dist/systemd.js +102 -0
  295. package/dist/systemd.js.map +1 -0
  296. package/dist/tsx-runner.d.ts +18 -0
  297. package/dist/tsx-runner.d.ts.map +1 -0
  298. package/dist/tsx-runner.js +69 -0
  299. package/dist/tsx-runner.js.map +1 -0
  300. package/dist/type-extractor.d.ts +4 -0
  301. package/dist/type-extractor.d.ts.map +1 -0
  302. package/dist/type-extractor.js +1213 -0
  303. package/dist/type-extractor.js.map +1 -0
  304. package/dist/type-resolver.d.ts +33 -0
  305. package/dist/type-resolver.d.ts.map +1 -0
  306. package/dist/type-resolver.js +338 -0
  307. package/dist/type-resolver.js.map +1 -0
  308. package/package.json +41 -0
  309. package/releases/deno/VERSION +1 -0
  310. package/scripts/mirror-deno-release.sh +76 -0
  311. package/src/TYPE-RESOLUTION.md +294 -0
  312. package/src/app/framework.ts +249 -0
  313. package/src/app/proxy-dev-app.ts +68 -0
  314. package/src/app-config.ts +128 -0
  315. package/src/augmentation-generator.ts +126 -0
  316. package/src/binary-cache.ts +845 -0
  317. package/src/cli.ts +63 -0
  318. package/src/commands/admin.ts +372 -0
  319. package/src/commands/app.ts +97 -0
  320. package/src/commands/cache.ts +117 -0
  321. package/src/commands/cloud.ts +325 -0
  322. package/src/commands/db.ts +136 -0
  323. package/src/commands/deploy-types.ts +49 -0
  324. package/src/commands/deploy.ts +400 -0
  325. package/src/commands/dev.ts +1009 -0
  326. package/src/commands/diff.ts +63 -0
  327. package/src/commands/engine.ts +30 -0
  328. package/src/commands/functions.ts +901 -0
  329. package/src/commands/generate.ts +44 -0
  330. package/src/commands/init.ts +253 -0
  331. package/src/commands/keys.ts +66 -0
  332. package/src/commands/logs.ts +58 -0
  333. package/src/commands/migrate-from-v1.ts +131 -0
  334. package/src/commands/migrate.ts +87 -0
  335. package/src/commands/pg.ts +133 -0
  336. package/src/commands/plugins.ts +508 -0
  337. package/src/commands/pull.ts +17 -0
  338. package/src/commands/push.ts +226 -0
  339. package/src/commands/seed.ts +68 -0
  340. package/src/commands/self-host.ts +364 -0
  341. package/src/commands/self-update.ts +45 -0
  342. package/src/commands/status.ts +84 -0
  343. package/src/commands/types.ts +76 -0
  344. package/src/commands/update.ts +136 -0
  345. package/src/components.ts +6 -0
  346. package/src/config.ts +223 -0
  347. package/src/dev-compose.ts +583 -0
  348. package/src/dev-log-bus.ts +101 -0
  349. package/src/dev-log-filter.ts +32 -0
  350. package/src/dev-logo.ts +62 -0
  351. package/src/dev-session.ts +130 -0
  352. package/src/dev-shutdown.ts +54 -0
  353. package/src/dev-task-colors.ts +47 -0
  354. package/src/dev-tui.ts +232 -0
  355. package/src/diff-output.ts +12 -0
  356. package/src/docker-postgres.ts +295 -0
  357. package/src/engine-client.ts +236 -0
  358. package/src/engine-push-output.ts +71 -0
  359. package/src/ensure-binary.ts +28 -0
  360. package/src/functions-router-gen.ts +224 -0
  361. package/src/index.ts +11 -0
  362. package/src/jwt.ts +14 -0
  363. package/src/kong-config.ts +93 -0
  364. package/src/local-gateway.ts +9 -0
  365. package/src/local-storage.ts +14 -0
  366. package/src/pgbouncer-userlist.ts +15 -0
  367. package/src/postgres-ctl.ts +171 -0
  368. package/src/process-manager.ts +220 -0
  369. package/src/project-config.ts +388 -0
  370. package/src/pull-utils.ts +81 -0
  371. package/src/release-pins.ts +31 -0
  372. package/src/release-public-key.ts +12 -0
  373. package/src/restore-system-relation-targets.ts +45 -0
  374. package/src/runtime-routes.ts +291 -0
  375. package/src/schema-ast-v2.ts +324 -0
  376. package/src/scripts/postinstall.ts +51 -0
  377. package/src/seed.ts +43 -0
  378. package/src/self-host-compose.ts +452 -0
  379. package/src/storage-provision.ts +58 -0
  380. package/src/studio-admin-roles.ts +16 -0
  381. package/src/studio-dev-server.ts +53 -0
  382. package/src/supatype-eval-1781522769253.mts +1 -0
  383. package/src/systemd.ts +137 -0
  384. package/src/tsx-runner.ts +89 -0
  385. package/src/type-extractor.ts +1479 -0
  386. package/src/type-resolver.ts +457 -0
  387. package/tests/app-command.test.ts +54 -0
  388. package/tests/augmentation-generator.test.ts +59 -0
  389. package/tests/binary-cache-cloud-overrides.test.ts +123 -0
  390. package/tests/cached-artifact-format.test.ts +84 -0
  391. package/tests/cli-help.test.ts +133 -0
  392. package/tests/config.test.ts +252 -0
  393. package/tests/dev-ui.test.ts +139 -0
  394. package/tests/docker-postgres.test.ts +39 -0
  395. package/tests/engine-distribution.test.ts +418 -0
  396. package/tests/engine-push-output.test.ts +67 -0
  397. package/tests/ensure-binary.test.ts +59 -0
  398. package/tests/init.test.ts +127 -0
  399. package/tests/keys.test.ts +160 -0
  400. package/tests/migrate-from-v1.test.ts +29 -0
  401. package/tests/normalize-admin-config.test.ts +48 -0
  402. package/tests/pg-spawn-env.test.ts +18 -0
  403. package/tests/postgres-archive-tag.test.ts +9 -0
  404. package/tests/proxy-dev-app.test.ts +33 -0
  405. package/tests/pull-utils.test.ts +150 -0
  406. package/tests/release-pins.test.ts +28 -0
  407. package/tests/runtime-contract.test.ts +370 -0
  408. package/tests/seed-discover.test.ts +31 -0
  409. package/tests/studio-admin-roles.test.ts +27 -0
  410. package/tests/tsconfig.json +9 -0
  411. package/tests/tsx-runner.test.ts +66 -0
  412. package/tests/type-extractor.test.ts +985 -0
  413. package/tests/type-resolver.test.ts +59 -0
  414. package/tsconfig.json +10 -0
  415. package/tsconfig.tsbuildinfo +1 -0
  416. package/vitest.config.ts +12 -0
@@ -0,0 +1,325 @@
1
+ import type { Command } from "commander"
2
+ import { readFileSync, writeFileSync, existsSync } from "node:fs"
3
+ import { resolve } from "node:path"
4
+ import { createInterface } from "node:readline"
5
+
6
+ interface CloudConfig {
7
+ apiUrl: string
8
+ token: string
9
+ projectSlug?: string
10
+ /** Organisation UUID — required for schema routes (`X-Org-Id`). */
11
+ orgId?: string
12
+ }
13
+
14
+ export function loadCloudConfig(cwd: string): CloudConfig | null {
15
+ const configPath = resolve(cwd, ".supatype/cloud.json")
16
+ if (!existsSync(configPath)) return null
17
+ return JSON.parse(readFileSync(configPath, "utf8")) as CloudConfig
18
+ }
19
+
20
+ function saveCloudConfig(cwd: string, config: CloudConfig): void {
21
+ const dir = resolve(cwd, ".supatype")
22
+ if (!existsSync(dir)) {
23
+ const { mkdirSync } = require("node:fs") as typeof import("node:fs")
24
+ mkdirSync(dir, { recursive: true })
25
+ }
26
+ writeFileSync(resolve(cwd, ".supatype/cloud.json"), JSON.stringify(config, null, 2) + "\n", "utf8")
27
+ }
28
+
29
+ async function cloudFetch<T>(config: CloudConfig, method: string, path: string, body?: unknown): Promise<T> {
30
+ const headers: Record<string, string> = {
31
+ "Content-Type": "application/json",
32
+ Authorization: `Bearer ${config.token}`,
33
+ }
34
+ if (config.orgId) {
35
+ headers["X-Org-Id"] = config.orgId
36
+ }
37
+ const res = await fetch(`${config.apiUrl}/api/v1${path}`, {
38
+ method,
39
+ headers,
40
+ ...(body !== undefined ? { body: JSON.stringify(body) } : {}),
41
+ })
42
+
43
+ const json = await res.json() as { data?: T; error?: string; message?: string }
44
+ if (!res.ok) {
45
+ throw new Error(json.message ?? json.error ?? `API error: ${res.status}`)
46
+ }
47
+ return json.data as T
48
+ }
49
+
50
+ /** True when `.supatype/cloud.json` exists with a linked project slug. */
51
+ export function isCloudLinked(cwd: string): boolean {
52
+ const cfg = loadCloudConfig(cwd)
53
+ return Boolean(cfg?.projectSlug && cfg.token)
54
+ }
55
+
56
+ /**
57
+ * Push schema AST to the linked cloud project (`POST /api/v1/projects/:ref/schema/push`).
58
+ * Credentials stay server-side; only AST is sent.
59
+ */
60
+ export async function pushSchemaToLinkedProject(cwd: string, opts?: { force?: boolean }): Promise<void> {
61
+ const config = loadCloudConfig(cwd)
62
+ if (!config?.projectSlug) {
63
+ console.error("Not linked to a cloud project. Run: supatype link")
64
+ process.exit(1)
65
+ }
66
+ if (!config.orgId) {
67
+ console.error(
68
+ "Missing orgId in .supatype/cloud.json. Re-run: supatype link --project <slug> (after cloud login).",
69
+ )
70
+ process.exit(1)
71
+ }
72
+
73
+ const { loadConfig: loadAppConfig, loadSchemaAst } = await import("../config.js")
74
+ const { schemaPathFromProject } = await import("../project-config.js")
75
+
76
+ const appConfig = loadAppConfig(cwd)
77
+ const ast = loadSchemaAst(schemaPathFromProject(appConfig, cwd), cwd)
78
+
79
+ console.log(`Pushing schema to cloud project ${config.projectSlug}...`)
80
+
81
+ const result = await cloudFetch<{ message?: string }>(config, "POST", `/projects/${config.projectSlug}/schema/push`, {
82
+ ast,
83
+ force: opts?.force ?? true,
84
+ })
85
+
86
+ console.log(result.message ?? "Schema push completed.")
87
+ }
88
+
89
+ /** @deprecated Use pushSchemaToLinkedProject — kept for deploy command alias */
90
+ export async function deploySchemaToLinkedProject(cwd: string, _environment: string): Promise<void> {
91
+ await pushSchemaToLinkedProject(cwd)
92
+ }
93
+
94
+ function prompt(question: string): Promise<string> {
95
+ const rl = createInterface({ input: process.stdin, output: process.stdout })
96
+ return new Promise((resolve) => {
97
+ rl.question(question, (answer) => {
98
+ rl.close()
99
+ resolve(answer.trim())
100
+ })
101
+ })
102
+ }
103
+
104
+ // ─── Registration ──────────────────────────────────────────────────────────────
105
+
106
+ export function registerCloud(program: Command): void {
107
+ // ── Link ───────────────────────────────────────────────────────────────────
108
+ program
109
+ .command("link")
110
+ .description("Link this local project to a Supatype cloud project")
111
+ .option("--project <slug>", "Project slug to link to")
112
+ .option("--api-url <url>", "Control plane API URL", "https://api.supatype.com")
113
+ .option("--token <token>", "Authentication token")
114
+ .action(async (opts: { project?: string; apiUrl: string; token?: string }) => {
115
+ const cwd = process.cwd()
116
+ const token = opts.token ?? process.env["SUPATYPE_TOKEN"]
117
+ if (!token) {
118
+ console.error("Authentication required. Set SUPATYPE_TOKEN or pass --token.")
119
+ process.exit(1)
120
+ }
121
+
122
+ const config: CloudConfig = { apiUrl: opts.apiUrl, token }
123
+
124
+ if (opts.project) {
125
+ config.projectSlug = opts.project
126
+ const one = await cloudFetch<{ slug: string; orgId: string }>(config, "GET", `/projects/${opts.project}`)
127
+ config.orgId = one.orgId
128
+ } else {
129
+ const projects = await cloudFetch<Array<{ slug: string; name: string; status: string; tier: string; orgId: string }>>(
130
+ config, "GET", "/projects",
131
+ )
132
+ if (projects.length === 0) {
133
+ console.error("No projects found. Create one with: supatype projects create <name>")
134
+ process.exit(1)
135
+ }
136
+
137
+ console.log("\nAvailable projects:\n")
138
+ projects.forEach((p, i) => {
139
+ console.log(` ${i + 1}. ${p.name} (${p.slug}) [${p.tier}] — ${p.status}`)
140
+ })
141
+
142
+ const answer = await prompt(`\nSelect project (1-${projects.length}): `)
143
+ const idx = parseInt(answer, 10) - 1
144
+ if (isNaN(idx) || idx < 0 || idx >= projects.length) {
145
+ console.error("Invalid selection.")
146
+ process.exit(1)
147
+ }
148
+ const picked = projects[idx]!
149
+ config.projectSlug = picked.slug
150
+ config.orgId = picked.orgId
151
+ }
152
+
153
+ saveCloudConfig(cwd, config)
154
+ console.log(`\nLinked to project: ${config.projectSlug}`)
155
+ console.log(`Config saved to .supatype/cloud.json\n`)
156
+ })
157
+
158
+ // ── Projects ───────────────────────────────────────────────────────────────
159
+ const projectsCmd = program
160
+ .command("projects")
161
+ .description("Manage cloud projects")
162
+
163
+ projectsCmd
164
+ .command("list")
165
+ .description("List all projects in your organisation")
166
+ .action(async () => {
167
+ const config = getCloudConfigOrExit()
168
+
169
+ const projects = await cloudFetch<Array<{
170
+ name: string; slug: string; tier: string; region: string; status: string
171
+ }>>(config, "GET", "/projects")
172
+
173
+ if (projects.length === 0) {
174
+ console.log("No projects. Create one with: supatype projects create <name>")
175
+ return
176
+ }
177
+
178
+ console.log("\n Name Slug Tier Region Status")
179
+ console.log(" " + "─".repeat(80))
180
+ for (const p of projects) {
181
+ console.log(
182
+ ` ${p.name.padEnd(24)}${p.slug.padEnd(25)}${p.tier.padEnd(8)}${p.region.padEnd(10)}${p.status}`,
183
+ )
184
+ }
185
+ console.log()
186
+ })
187
+
188
+ projectsCmd
189
+ .command("create <name>")
190
+ .description("Create a new project")
191
+ .option("--tier <tier>", "Project tier (free, pro, team)", "free")
192
+ .option("--region <region>", "Region (eu-fsn, eu-nbg, eu-hel)", "eu-fsn")
193
+ .action(async (name: string, opts: { tier: string; region: string }) => {
194
+ const config = getCloudConfigOrExit()
195
+
196
+ console.log(`Creating project "${name}" (${opts.tier}, ${opts.region})...`)
197
+
198
+ const project = await cloudFetch<{ slug: string; name: string; status: string }>(
199
+ config, "POST", "/projects",
200
+ { name, tier: opts.tier, region: opts.region },
201
+ )
202
+
203
+ console.log(`\nProject created: ${project.name} (${project.slug})`)
204
+ console.log(`Status: ${project.status}`)
205
+ console.log(`\nTo link this project: supatype link --project ${project.slug}\n`)
206
+ })
207
+
208
+ projectsCmd
209
+ .command("pause <slug>")
210
+ .description("Pause a project")
211
+ .action(async (slug: string) => {
212
+ const config = getCloudConfigOrExit()
213
+ await cloudFetch(config, "POST", `/projects/${slug}/pause`)
214
+ console.log(`Project ${slug} paused.`)
215
+ })
216
+
217
+ projectsCmd
218
+ .command("resume <slug>")
219
+ .description("Resume a paused project")
220
+ .action(async (slug: string) => {
221
+ const config = getCloudConfigOrExit()
222
+ await cloudFetch(config, "POST", `/projects/${slug}/resume`)
223
+ console.log(`Project ${slug} resumed.`)
224
+ })
225
+
226
+ // ── Domains ────────────────────────────────────────────────────────────────
227
+ const domainsCmd = program
228
+ .command("domains")
229
+ .description("Manage custom domains for a project")
230
+
231
+ domainsCmd
232
+ .command("list")
233
+ .description("List domains for the linked project")
234
+ .action(async () => {
235
+ const config = getCloudConfigOrExit()
236
+ if (!config.projectSlug) {
237
+ console.error("Not linked to a project. Run: supatype link")
238
+ process.exit(1)
239
+ }
240
+
241
+ const domains = await cloudFetch<Array<{
242
+ domain: string; status: string; cnameTarget: string; sslExpiresAt: string | null
243
+ }>>(config, "GET", `/projects/${config.projectSlug}/domains`)
244
+
245
+ if (domains.length === 0) {
246
+ console.log("No custom domains configured.")
247
+ return
248
+ }
249
+
250
+ console.log("\n Domain Status CNAME Target")
251
+ console.log(" " + "─".repeat(80))
252
+ for (const d of domains) {
253
+ console.log(
254
+ ` ${d.domain.padEnd(34)}${d.status.padEnd(21)}${d.cnameTarget}`,
255
+ )
256
+ }
257
+ console.log()
258
+ })
259
+
260
+ domainsCmd
261
+ .command("add <domain>")
262
+ .description("Add a custom domain")
263
+ .action(async (domain: string) => {
264
+ const config = getCloudConfigOrExit()
265
+ if (!config.projectSlug) {
266
+ console.error("Not linked to a project. Run: supatype link")
267
+ process.exit(1)
268
+ }
269
+
270
+ const result = await cloudFetch<{ domain: string; cnameTarget: string; instructions: string }>(
271
+ config, "POST", `/projects/${config.projectSlug}/domains`,
272
+ { domain },
273
+ )
274
+
275
+ console.log(`\nDomain added: ${result.domain}`)
276
+ console.log(`\n${result.instructions}`)
277
+ console.log(`\nAfter adding the CNAME record, verify with: supatype domains verify ${domain}\n`)
278
+ })
279
+
280
+ domainsCmd
281
+ .command("remove <domainId>")
282
+ .description("Remove a custom domain")
283
+ .action(async (domainId: string) => {
284
+ const config = getCloudConfigOrExit()
285
+ if (!config.projectSlug) {
286
+ console.error("Not linked to a project. Run: supatype link")
287
+ process.exit(1)
288
+ }
289
+
290
+ await cloudFetch(config, "DELETE", `/projects/${config.projectSlug}/domains/${domainId}`)
291
+ console.log("Domain removed.")
292
+ })
293
+
294
+ domainsCmd
295
+ .command("verify <domainId>")
296
+ .description("Verify CNAME and provision SSL for a domain")
297
+ .action(async (domainId: string) => {
298
+ const config = getCloudConfigOrExit()
299
+ if (!config.projectSlug) {
300
+ console.error("Not linked to a project. Run: supatype link")
301
+ process.exit(1)
302
+ }
303
+
304
+ const result = await cloudFetch<{ domain: string; status: string }>(
305
+ config, "POST", `/projects/${config.projectSlug}/domains/${domainId}/verify`,
306
+ )
307
+
308
+ console.log(`Domain ${result.domain}: ${result.status}`)
309
+ })
310
+ }
311
+
312
+ function getCloudConfigOrExit(): CloudConfig {
313
+ const cwd = process.cwd()
314
+ let config = loadCloudConfig(cwd)
315
+ if (!config) {
316
+ const token = process.env["SUPATYPE_TOKEN"]
317
+ const apiUrl = process.env["SUPATYPE_API_URL"] ?? "https://api.supatype.com"
318
+ if (!token) {
319
+ console.error("Not connected to Supatype Cloud. Run: supatype link, or set SUPATYPE_TOKEN.")
320
+ process.exit(1)
321
+ }
322
+ config = { apiUrl, token }
323
+ }
324
+ return config
325
+ }
@@ -0,0 +1,136 @@
1
+ /**
2
+ * Database connection commands:
3
+ * supatype db connection-string — show the connection string for the linked project
4
+ * supatype db reset-password — reset the database password
5
+ */
6
+
7
+ import type { Command } from "commander"
8
+ import { loadConfig } from "../config.js"
9
+ import { connectionString } from "../project-config.js"
10
+ import { loadCloudConfig } from "./cloud.js"
11
+
12
+ export function registerDb(program: Command): void {
13
+ const db = program
14
+ .command("db")
15
+ .description("Database connection management")
16
+
17
+ // supatype db connection-string
18
+ db
19
+ .command("connection-string")
20
+ .description("Show the database connection string for the linked project")
21
+ .option("--transaction", "Show the transaction pool URL (for serverless/edge functions)")
22
+ .option("--env <name>", "Environment name", "production")
23
+ .action(async (opts: { transaction?: boolean; env?: string }) => {
24
+ const cwd = process.cwd()
25
+ const config = loadConfig(cwd)
26
+ const cloudCfg = loadCloudConfig(cwd)
27
+ const localConn = connectionString(config)
28
+
29
+ // If no cloud project linked, show the local connection string.
30
+ if (!cloudCfg?.projectSlug) {
31
+ const connStr = opts.transaction ? localConn.replace(/:5432\//, ":6432/") : localConn
32
+ console.log(connStr)
33
+ console.log()
34
+ console.log("Session mode (port 5432): for interactive tools (psql, DataGrip, TablePlus)")
35
+ console.log("Transaction mode (port 6432): for application servers and serverless functions")
36
+ return
37
+ }
38
+
39
+ // If linked to a cloud project, fetch from the API
40
+ const apiUrl = cloudCfg.apiUrl || "https://api.supatype.com"
41
+ const token = cloudCfg.token || process.env["SUPATYPE_ACCESS_TOKEN"] || ""
42
+ const envName = opts.env || "production"
43
+
44
+ try {
45
+ const res = await fetch(
46
+ `${apiUrl}/platform/v1/projects/${cloudCfg.projectSlug}/environments`,
47
+ {
48
+ headers: {
49
+ Authorization: `Bearer ${token}`,
50
+ },
51
+ },
52
+ )
53
+
54
+ if (!res.ok) {
55
+ console.error(`Failed to fetch project info: ${res.status}`)
56
+ process.exitCode = 1
57
+ return
58
+ }
59
+
60
+ const { data } = (await res.json()) as { data: Array<{ name: string; databaseUrl?: string }> }
61
+ const env = data.find((e) => e.name === envName)
62
+
63
+ if (!env) {
64
+ console.error(`Environment "${envName}" not found`)
65
+ process.exitCode = 1
66
+ return
67
+ }
68
+
69
+ const connStr = env.databaseUrl || "Connection string not available"
70
+ if (opts.transaction) {
71
+ console.log(connStr.replace(/:5432\//, ":6432/"))
72
+ } else {
73
+ console.log(connStr)
74
+ }
75
+
76
+ console.log()
77
+ console.log("Session mode (port 5432): for interactive tools (psql, DataGrip, TablePlus)")
78
+ console.log("Transaction mode (port 6432): for application servers and serverless functions")
79
+ } catch (err) {
80
+ console.error("Failed to fetch connection string:", (err as Error).message)
81
+ process.exitCode = 1
82
+ }
83
+ })
84
+
85
+ // supatype db reset-password
86
+ db
87
+ .command("reset-password")
88
+ .description("Reset the database password for the linked project")
89
+ .option("--env <name>", "Environment name", "production")
90
+ .action(async (opts: { env?: string }) => {
91
+ const cwd = process.cwd()
92
+ const cloudCfg = loadCloudConfig(cwd)
93
+
94
+ if (!cloudCfg?.projectSlug) {
95
+ console.error("Not linked to a cloud project. Run: supatype link --project <ref>")
96
+ process.exitCode = 1
97
+ return
98
+ }
99
+
100
+ const apiUrl = cloudCfg.apiUrl || "https://api.supatype.com"
101
+ const token = cloudCfg.token || process.env["SUPATYPE_ACCESS_TOKEN"] || ""
102
+ const envName = opts.env || "production"
103
+
104
+ try {
105
+ const res = await fetch(
106
+ `${apiUrl}/platform/v1/projects/${cloudCfg.projectSlug}/environments/${envName}/reset-db-password`,
107
+ {
108
+ method: "POST",
109
+ headers: {
110
+ Authorization: `Bearer ${token}`,
111
+ "Content-Type": "application/json",
112
+ },
113
+ },
114
+ )
115
+
116
+ if (!res.ok) {
117
+ const body = await res.text()
118
+ console.error(`Failed to reset password: ${res.status} ${body}`)
119
+ process.exitCode = 1
120
+ return
121
+ }
122
+
123
+ const { data } = (await res.json()) as { data: { password: string; connectionString: string } }
124
+ console.log("Database password reset successfully.")
125
+ console.log()
126
+ console.log(`New password: ${data.password}`)
127
+ console.log(`Connection string: ${data.connectionString}`)
128
+ console.log()
129
+ console.log("Warning: Existing database connections have been terminated.")
130
+ console.log("Update your application with the new connection string.")
131
+ } catch (err) {
132
+ console.error("Failed to reset password:", (err as Error).message)
133
+ process.exitCode = 1
134
+ }
135
+ })
136
+ }
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Deployment tier limits for static site hosting.
3
+ */
4
+
5
+ export type Tier = "free" | "pro" | "team" | "enterprise"
6
+
7
+ export interface DeploymentLimits {
8
+ maxBuildOutputMb: number
9
+ buildMinutesPerMonth: number
10
+ maxPreviewDeployments: number
11
+ deploymentRetention: number
12
+ cdnEnabled: boolean
13
+ buildMinuteOverageRate: number // £ per minute, 0 = no overage allowed
14
+ }
15
+
16
+ export const TIER_LIMITS: Record<Tier, DeploymentLimits> = {
17
+ free: {
18
+ maxBuildOutputMb: 50,
19
+ buildMinutesPerMonth: 100,
20
+ maxPreviewDeployments: 1,
21
+ deploymentRetention: 3,
22
+ cdnEnabled: false,
23
+ buildMinuteOverageRate: 0,
24
+ },
25
+ pro: {
26
+ maxBuildOutputMb: 500,
27
+ buildMinutesPerMonth: 1000,
28
+ maxPreviewDeployments: 5,
29
+ deploymentRetention: 10,
30
+ cdnEnabled: true,
31
+ buildMinuteOverageRate: 0.01,
32
+ },
33
+ team: {
34
+ maxBuildOutputMb: 2048,
35
+ buildMinutesPerMonth: 5000,
36
+ maxPreviewDeployments: 20,
37
+ deploymentRetention: 25,
38
+ cdnEnabled: true,
39
+ buildMinuteOverageRate: 0.01,
40
+ },
41
+ enterprise: {
42
+ maxBuildOutputMb: -1,
43
+ buildMinutesPerMonth: -1,
44
+ maxPreviewDeployments: -1,
45
+ deploymentRetention: -1,
46
+ cdnEnabled: true,
47
+ buildMinuteOverageRate: 0,
48
+ },
49
+ }