@supatype/cli 0.9.0 → 0.9.1

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 (373) hide show
  1. package/CHANGELOG.md +360 -0
  2. package/dist/app/proxy-dev-app.d.ts +13 -3
  3. package/dist/app/proxy-dev-app.d.ts.map +1 -1
  4. package/dist/app/proxy-dev-app.js +58 -62
  5. package/dist/app/proxy-dev-app.js.map +1 -1
  6. package/dist/auth-providers.d.ts +5 -4
  7. package/dist/auth-providers.d.ts.map +1 -1
  8. package/dist/auth-providers.js +3 -12
  9. package/dist/auth-providers.js.map +1 -1
  10. package/dist/build-spawn.d.ts +35 -0
  11. package/dist/build-spawn.d.ts.map +1 -0
  12. package/dist/build-spawn.js +75 -0
  13. package/dist/build-spawn.js.map +1 -0
  14. package/dist/cli-version-embedded.js +1 -1
  15. package/dist/cli.d.ts.map +1 -1
  16. package/dist/cli.js +4 -0
  17. package/dist/cli.js.map +1 -1
  18. package/dist/cloud-credentials.d.ts.map +1 -1
  19. package/dist/cloud-credentials.js +3 -1
  20. package/dist/cloud-credentials.js.map +1 -1
  21. package/dist/commands/admin.d.ts.map +1 -1
  22. package/dist/commands/admin.js +6 -4
  23. package/dist/commands/admin.js.map +1 -1
  24. package/dist/commands/adopt.js +1 -1
  25. package/dist/commands/adopt.js.map +1 -1
  26. package/dist/commands/build.d.ts +29 -0
  27. package/dist/commands/build.d.ts.map +1 -0
  28. package/dist/commands/build.js +69 -0
  29. package/dist/commands/build.js.map +1 -0
  30. package/dist/commands/cache.d.ts.map +1 -1
  31. package/dist/commands/cache.js +5 -0
  32. package/dist/commands/cache.js.map +1 -1
  33. package/dist/commands/db.d.ts.map +1 -1
  34. package/dist/commands/db.js +46 -23
  35. package/dist/commands/db.js.map +1 -1
  36. package/dist/commands/deploy.d.ts +14 -0
  37. package/dist/commands/deploy.d.ts.map +1 -1
  38. package/dist/commands/deploy.js +67 -52
  39. package/dist/commands/deploy.js.map +1 -1
  40. package/dist/commands/dev.d.ts.map +1 -1
  41. package/dist/commands/dev.js +23 -19
  42. package/dist/commands/dev.js.map +1 -1
  43. package/dist/commands/diff.d.ts +3 -0
  44. package/dist/commands/diff.d.ts.map +1 -1
  45. package/dist/commands/diff.js +28 -34
  46. package/dist/commands/diff.js.map +1 -1
  47. package/dist/commands/doctor.js +1 -1
  48. package/dist/commands/doctor.js.map +1 -1
  49. package/dist/commands/functions.d.ts.map +1 -1
  50. package/dist/commands/functions.js +21 -16
  51. package/dist/commands/functions.js.map +1 -1
  52. package/dist/commands/init.d.ts +10 -3
  53. package/dist/commands/init.d.ts.map +1 -1
  54. package/dist/commands/init.js +127 -57
  55. package/dist/commands/init.js.map +1 -1
  56. package/dist/commands/internal.d.ts.map +1 -1
  57. package/dist/commands/internal.js +27 -7
  58. package/dist/commands/internal.js.map +1 -1
  59. package/dist/commands/introspect.d.ts.map +1 -1
  60. package/dist/commands/introspect.js +3 -0
  61. package/dist/commands/introspect.js.map +1 -1
  62. package/dist/commands/keys-print.d.ts +20 -0
  63. package/dist/commands/keys-print.d.ts.map +1 -0
  64. package/dist/commands/keys-print.js +47 -0
  65. package/dist/commands/keys-print.js.map +1 -0
  66. package/dist/commands/keys.d.ts.map +1 -1
  67. package/dist/commands/keys.js +16 -12
  68. package/dist/commands/keys.js.map +1 -1
  69. package/dist/commands/link-helpers.d.ts.map +1 -1
  70. package/dist/commands/link-helpers.js +27 -5
  71. package/dist/commands/link-helpers.js.map +1 -1
  72. package/dist/commands/migrate.d.ts +5 -2
  73. package/dist/commands/migrate.d.ts.map +1 -1
  74. package/dist/commands/migrate.js +34 -36
  75. package/dist/commands/migrate.js.map +1 -1
  76. package/dist/commands/pull.d.ts.map +1 -1
  77. package/dist/commands/pull.js +6 -5
  78. package/dist/commands/pull.js.map +1 -1
  79. package/dist/commands/push.d.ts.map +1 -1
  80. package/dist/commands/push.js +27 -18
  81. package/dist/commands/push.js.map +1 -1
  82. package/dist/commands/rename.js +1 -1
  83. package/dist/commands/rename.js.map +1 -1
  84. package/dist/commands/seed.d.ts +2 -11
  85. package/dist/commands/seed.d.ts.map +1 -1
  86. package/dist/commands/seed.js +11 -38
  87. package/dist/commands/seed.js.map +1 -1
  88. package/dist/commands/self-host.d.ts.map +1 -1
  89. package/dist/commands/self-host.js +74 -12
  90. package/dist/commands/self-host.js.map +1 -1
  91. package/dist/commands/sso.d.ts +26 -0
  92. package/dist/commands/sso.d.ts.map +1 -0
  93. package/dist/commands/sso.js +362 -0
  94. package/dist/commands/sso.js.map +1 -0
  95. package/dist/commands/status.d.ts.map +1 -1
  96. package/dist/commands/status.js +25 -8
  97. package/dist/commands/status.js.map +1 -1
  98. package/dist/component-launch.d.ts.map +1 -1
  99. package/dist/component-launch.js +2 -1
  100. package/dist/component-launch.js.map +1 -1
  101. package/dist/compose-db-roles.d.ts +4 -4
  102. package/dist/compose-db-roles.d.ts.map +1 -1
  103. package/dist/compose-db-roles.js +11 -10
  104. package/dist/compose-db-roles.js.map +1 -1
  105. package/dist/compose-engine-run.d.ts +9 -2
  106. package/dist/compose-engine-run.d.ts.map +1 -1
  107. package/dist/compose-engine-run.js +30 -13
  108. package/dist/compose-engine-run.js.map +1 -1
  109. package/dist/compose-services.d.ts +18 -0
  110. package/dist/compose-services.d.ts.map +1 -1
  111. package/dist/compose-services.js +47 -22
  112. package/dist/compose-services.js.map +1 -1
  113. package/dist/config-mailer-env.d.ts +27 -0
  114. package/dist/config-mailer-env.d.ts.map +1 -0
  115. package/dist/config-mailer-env.js +47 -0
  116. package/dist/config-mailer-env.js.map +1 -0
  117. package/dist/db-rows.d.ts +3 -2
  118. package/dist/db-rows.d.ts.map +1 -1
  119. package/dist/db-rows.js +19 -4
  120. package/dist/db-rows.js.map +1 -1
  121. package/dist/dev-compose.d.ts +62 -7
  122. package/dist/dev-compose.d.ts.map +1 -1
  123. package/dist/dev-compose.js +202 -151
  124. package/dist/dev-compose.js.map +1 -1
  125. package/dist/dev-ports.d.ts +6 -4
  126. package/dist/dev-ports.d.ts.map +1 -1
  127. package/dist/dev-ports.js +80 -46
  128. package/dist/dev-ports.js.map +1 -1
  129. package/dist/dev-schema-watch.d.ts +8 -2
  130. package/dist/dev-schema-watch.d.ts.map +1 -1
  131. package/dist/dev-schema-watch.js +24 -13
  132. package/dist/dev-schema-watch.js.map +1 -1
  133. package/dist/dev-session.d.ts +13 -2
  134. package/dist/dev-session.d.ts.map +1 -1
  135. package/dist/dev-session.js +22 -5
  136. package/dist/dev-session.js.map +1 -1
  137. package/dist/dev-shutdown.d.ts.map +1 -1
  138. package/dist/dev-shutdown.js +4 -1
  139. package/dist/dev-shutdown.js.map +1 -1
  140. package/dist/diff-access.d.ts +10 -0
  141. package/dist/diff-access.d.ts.map +1 -0
  142. package/dist/diff-access.js +69 -0
  143. package/dist/diff-access.js.map +1 -0
  144. package/dist/diff-output.d.ts.map +1 -1
  145. package/dist/diff-output.js +2 -1
  146. package/dist/diff-output.js.map +1 -1
  147. package/dist/docker-exec.d.ts.map +1 -1
  148. package/dist/docker-exec.js +4 -4
  149. package/dist/docker-exec.js.map +1 -1
  150. package/dist/docker-runtime.d.ts +8 -2
  151. package/dist/docker-runtime.d.ts.map +1 -1
  152. package/dist/docker-runtime.js +64 -23
  153. package/dist/docker-runtime.js.map +1 -1
  154. package/dist/engine-answers.d.ts +2 -1
  155. package/dist/engine-answers.d.ts.map +1 -1
  156. package/dist/engine-answers.js +11 -0
  157. package/dist/engine-answers.js.map +1 -1
  158. package/dist/engine-client.d.ts +20 -0
  159. package/dist/engine-client.d.ts.map +1 -1
  160. package/dist/engine-client.js +9 -8
  161. package/dist/engine-client.js.map +1 -1
  162. package/dist/engine-floor.d.ts +3 -2
  163. package/dist/engine-floor.d.ts.map +1 -1
  164. package/dist/engine-floor.js +2 -2
  165. package/dist/engine-floor.js.map +1 -1
  166. package/dist/engine-push-output.d.ts +8 -1
  167. package/dist/engine-push-output.d.ts.map +1 -1
  168. package/dist/engine-push-output.js +8 -1
  169. package/dist/engine-push-output.js.map +1 -1
  170. package/dist/env-file.d.ts +5 -0
  171. package/dist/env-file.d.ts.map +1 -1
  172. package/dist/env-file.js +51 -33
  173. package/dist/env-file.js.map +1 -1
  174. package/dist/env-lines.d.ts +3 -2
  175. package/dist/env-lines.d.ts.map +1 -1
  176. package/dist/env-lines.js +5 -2
  177. package/dist/env-lines.js.map +1 -1
  178. package/dist/env-value.d.ts +15 -0
  179. package/dist/env-value.d.ts.map +1 -0
  180. package/dist/env-value.js +34 -0
  181. package/dist/env-value.js.map +1 -0
  182. package/dist/error-message.d.ts +20 -0
  183. package/dist/error-message.d.ts.map +1 -1
  184. package/dist/error-message.js +42 -0
  185. package/dist/error-message.js.map +1 -1
  186. package/dist/frontend-env.d.ts +10 -2
  187. package/dist/frontend-env.d.ts.map +1 -1
  188. package/dist/frontend-env.js +24 -4
  189. package/dist/frontend-env.js.map +1 -1
  190. package/dist/frontend-values-linked.d.ts +22 -0
  191. package/dist/frontend-values-linked.d.ts.map +1 -0
  192. package/dist/frontend-values-linked.js +143 -0
  193. package/dist/frontend-values-linked.js.map +1 -0
  194. package/dist/frontend-values.d.ts +90 -0
  195. package/dist/frontend-values.d.ts.map +1 -0
  196. package/dist/frontend-values.js +208 -0
  197. package/dist/frontend-values.js.map +1 -0
  198. package/dist/functions-env-local.d.ts +13 -0
  199. package/dist/functions-env-local.d.ts.map +1 -0
  200. package/dist/functions-env-local.js +20 -0
  201. package/dist/functions-env-local.js.map +1 -0
  202. package/dist/generated/release-images.d.ts +4 -4
  203. package/dist/generated/release-images.js +2 -2
  204. package/dist/generated/release-images.js.map +1 -1
  205. package/dist/generated/typescript-libs.d.ts +4 -0
  206. package/dist/generated/typescript-libs.d.ts.map +1 -0
  207. package/dist/generated/typescript-libs.js +64 -0
  208. package/dist/generated/typescript-libs.js.map +1 -0
  209. package/dist/host-database.d.ts +10 -10
  210. package/dist/host-database.d.ts.map +1 -1
  211. package/dist/host-database.js +18 -15
  212. package/dist/host-database.js.map +1 -1
  213. package/dist/init-answers.d.ts +18 -0
  214. package/dist/init-answers.d.ts.map +1 -0
  215. package/dist/init-answers.js +46 -0
  216. package/dist/init-answers.js.map +1 -0
  217. package/dist/init-next-runtime-env.d.ts +30 -0
  218. package/dist/init-next-runtime-env.d.ts.map +1 -0
  219. package/dist/init-next-runtime-env.js +180 -0
  220. package/dist/init-next-runtime-env.js.map +1 -0
  221. package/dist/jwt.d.ts +5 -0
  222. package/dist/jwt.d.ts.map +1 -1
  223. package/dist/jwt.js +16 -0
  224. package/dist/jwt.js.map +1 -1
  225. package/dist/local-secrets.d.ts +22 -0
  226. package/dist/local-secrets.d.ts.map +1 -1
  227. package/dist/local-secrets.js +36 -0
  228. package/dist/local-secrets.js.map +1 -1
  229. package/dist/local-stack-guard.d.ts +37 -0
  230. package/dist/local-stack-guard.d.ts.map +1 -0
  231. package/dist/local-stack-guard.js +84 -0
  232. package/dist/local-stack-guard.js.map +1 -0
  233. package/dist/mailer-env.d.ts +4 -0
  234. package/dist/mailer-env.d.ts.map +1 -1
  235. package/dist/mailer-env.js +12 -1
  236. package/dist/mailer-env.js.map +1 -1
  237. package/dist/node-executable.d.ts +6 -0
  238. package/dist/node-executable.d.ts.map +1 -0
  239. package/dist/node-executable.js +43 -0
  240. package/dist/node-executable.js.map +1 -0
  241. package/dist/parent-watch.d.ts +8 -3
  242. package/dist/parent-watch.d.ts.map +1 -1
  243. package/dist/parent-watch.js +8 -3
  244. package/dist/parent-watch.js.map +1 -1
  245. package/dist/postgres-ctl.d.ts +2 -0
  246. package/dist/postgres-ctl.d.ts.map +1 -1
  247. package/dist/postgres-ctl.js +11 -5
  248. package/dist/postgres-ctl.js.map +1 -1
  249. package/dist/process-manager.d.ts +37 -5
  250. package/dist/process-manager.d.ts.map +1 -1
  251. package/dist/process-manager.js +127 -65
  252. package/dist/process-manager.js.map +1 -1
  253. package/dist/project-config.d.ts +27 -0
  254. package/dist/project-config.d.ts.map +1 -1
  255. package/dist/project-config.js +18 -0
  256. package/dist/project-config.js.map +1 -1
  257. package/dist/push-audit.d.ts +4 -1
  258. package/dist/push-audit.d.ts.map +1 -1
  259. package/dist/push-audit.js +33 -4
  260. package/dist/push-audit.js.map +1 -1
  261. package/dist/recorded-field-masking-tier.d.ts +2 -2
  262. package/dist/recorded-field-masking-tier.d.ts.map +1 -1
  263. package/dist/recorded-field-masking-tier.js +6 -6
  264. package/dist/recorded-field-masking-tier.js.map +1 -1
  265. package/dist/rename-journal.d.ts +1 -1
  266. package/dist/rename-journal.d.ts.map +1 -1
  267. package/dist/resolve-api-url.d.ts +2 -0
  268. package/dist/resolve-api-url.d.ts.map +1 -1
  269. package/dist/resolve-api-url.js +5 -1
  270. package/dist/resolve-api-url.js.map +1 -1
  271. package/dist/resolve-target.d.ts +16 -1
  272. package/dist/resolve-target.d.ts.map +1 -1
  273. package/dist/resolve-target.js +20 -11
  274. package/dist/resolve-target.js.map +1 -1
  275. package/dist/run-captured.d.ts +31 -0
  276. package/dist/run-captured.d.ts.map +1 -0
  277. package/dist/run-captured.js +36 -0
  278. package/dist/run-captured.js.map +1 -0
  279. package/dist/saml-config.d.ts +53 -0
  280. package/dist/saml-config.d.ts.map +1 -0
  281. package/dist/saml-config.js +177 -0
  282. package/dist/saml-config.js.map +1 -0
  283. package/dist/saml-key-rotation.d.ts +5 -0
  284. package/dist/saml-key-rotation.d.ts.map +1 -0
  285. package/dist/saml-key-rotation.js +26 -0
  286. package/dist/saml-key-rotation.js.map +1 -0
  287. package/dist/saml-sp-certificate.d.ts +15 -0
  288. package/dist/saml-sp-certificate.d.ts.map +1 -0
  289. package/dist/saml-sp-certificate.js +34 -0
  290. package/dist/saml-sp-certificate.js.map +1 -0
  291. package/dist/schema-reset.d.ts +41 -0
  292. package/dist/schema-reset.d.ts.map +1 -0
  293. package/dist/schema-reset.js +98 -0
  294. package/dist/schema-reset.js.map +1 -0
  295. package/dist/seed-child.d.ts +25 -0
  296. package/dist/seed-child.d.ts.map +1 -0
  297. package/dist/seed-child.js +61 -0
  298. package/dist/seed-child.js.map +1 -0
  299. package/dist/seed-runner.d.ts +3 -5
  300. package/dist/seed-runner.d.ts.map +1 -1
  301. package/dist/seed-runner.js +20 -42
  302. package/dist/seed-runner.js.map +1 -1
  303. package/dist/self-host-compose.d.ts +9 -1
  304. package/dist/self-host-compose.d.ts.map +1 -1
  305. package/dist/self-host-compose.js +47 -14
  306. package/dist/self-host-compose.js.map +1 -1
  307. package/dist/serial-runs.d.ts +7 -0
  308. package/dist/serial-runs.d.ts.map +1 -0
  309. package/dist/serial-runs.js +29 -0
  310. package/dist/serial-runs.js.map +1 -0
  311. package/dist/sso-admin.d.ts +114 -0
  312. package/dist/sso-admin.d.ts.map +1 -0
  313. package/dist/sso-admin.js +256 -0
  314. package/dist/sso-admin.js.map +1 -0
  315. package/dist/stack-engine.d.ts +28 -0
  316. package/dist/stack-engine.d.ts.map +1 -0
  317. package/dist/stack-engine.js +59 -0
  318. package/dist/stack-engine.js.map +1 -0
  319. package/dist/stack-exit-watch.d.ts +37 -0
  320. package/dist/stack-exit-watch.d.ts.map +1 -0
  321. package/dist/stack-exit-watch.js +70 -0
  322. package/dist/stack-exit-watch.js.map +1 -0
  323. package/dist/stack-setting-warnings.d.ts +8 -0
  324. package/dist/stack-setting-warnings.d.ts.map +1 -0
  325. package/dist/stack-setting-warnings.js +14 -0
  326. package/dist/stack-setting-warnings.js.map +1 -0
  327. package/dist/studio-dev-server.d.ts.map +1 -1
  328. package/dist/studio-dev-server.js +2 -1
  329. package/dist/studio-dev-server.js.map +1 -1
  330. package/dist/target-client.d.ts +12 -2
  331. package/dist/target-client.d.ts.map +1 -1
  332. package/dist/target-client.js +14 -1
  333. package/dist/target-client.js.map +1 -1
  334. package/dist/tsx-runner.d.ts +5 -0
  335. package/dist/tsx-runner.d.ts.map +1 -1
  336. package/dist/tsx-runner.js +16 -16
  337. package/dist/tsx-runner.js.map +1 -1
  338. package/dist/type-generation.d.ts +1 -1
  339. package/dist/type-generation.d.ts.map +1 -1
  340. package/dist/type-generation.js +2 -4
  341. package/dist/type-generation.js.map +1 -1
  342. package/dist/type-resolver.d.ts.map +1 -1
  343. package/dist/type-resolver.js +31 -12
  344. package/dist/type-resolver.js.map +1 -1
  345. package/dist/ui/clack-api.d.ts.map +1 -1
  346. package/dist/ui/clack-api.js +45 -23
  347. package/dist/ui/clack-api.js.map +1 -1
  348. package/dist/ui/components/LineInput.d.ts +26 -0
  349. package/dist/ui/components/LineInput.d.ts.map +1 -0
  350. package/dist/ui/components/LineInput.js +60 -0
  351. package/dist/ui/components/LineInput.js.map +1 -0
  352. package/dist/ui/flows/FlowApp.d.ts +3 -1
  353. package/dist/ui/flows/FlowApp.d.ts.map +1 -1
  354. package/dist/ui/flows/FlowApp.js +14 -5
  355. package/dist/ui/flows/FlowApp.js.map +1 -1
  356. package/dist/ui/flows/prompt-fields.d.ts +3 -1
  357. package/dist/ui/flows/prompt-fields.d.ts.map +1 -1
  358. package/dist/ui/flows/prompt-fields.js +10 -5
  359. package/dist/ui/flows/prompt-fields.js.map +1 -1
  360. package/dist/ui/flows/types.d.ts +5 -1
  361. package/dist/ui/flows/types.d.ts.map +1 -1
  362. package/dist/ui/runtime/command-chrome.d.ts.map +1 -1
  363. package/dist/ui/runtime/command-chrome.js +2 -0
  364. package/dist/ui/runtime/command-chrome.js.map +1 -1
  365. package/dist/ui/runtime/flow-transcript.d.ts +17 -0
  366. package/dist/ui/runtime/flow-transcript.d.ts.map +1 -0
  367. package/dist/ui/runtime/flow-transcript.js +38 -0
  368. package/dist/ui/runtime/flow-transcript.js.map +1 -0
  369. package/dist/ui/runtime/run-clack-flow.d.ts +7 -0
  370. package/dist/ui/runtime/run-clack-flow.d.ts.map +1 -1
  371. package/dist/ui/runtime/run-clack-flow.js +131 -17
  372. package/dist/ui/runtime/run-clack-flow.js.map +1 -1
  373. package/package.json +4 -5
@@ -4,6 +4,7 @@
4
4
  import { setTimeout as sleep } from "node:timers/promises";
5
5
  import { projectOutputPaths, writeAstDerivedOutputs, writeSeedBuilder } from "./type-generation.js";
6
6
  import { errorMessage } from "./error-message.js";
7
+ import { printRoleAccess } from "./diff-access.js";
7
8
  import { warn } from "./ui/messages.js";
8
9
  import { FRONTEND_URL_KEYS, frontendEnv, writeFrontendEnv } from "./frontend-env.js";
9
10
  import { withPublishing } from "./model-versioning.js";
@@ -26,7 +27,7 @@ import { ensureDevDbPort, ensureKongPort } from "./dev-ports.js";
26
27
  import { applyForThisRun, splitShellPortUpdates } from "./shell-ports.js";
27
28
  import { handleComposeProjectRename } from "./compose-rename.js";
28
29
  import { devSessionLockFor, recoverStaleDevSession, writeDevSessionLock } from "./dev-session-lock.js";
29
- import { endDevSession, showDevStep, startDevSession } from "./dev-session.js";
30
+ import { endDevSession, showDevStep, startDevSession, withSavePushOutput } from "./dev-session.js";
30
31
  import { ensureDevApiConfig } from "./ensure-dev-api-config.js";
31
32
  import { cacheSeedingNotes } from "./api-config-cache.js";
32
33
  import { restartComposeFunctionsWorker, watchFunctionSources } from "./dev-functions-watch.js";
@@ -41,6 +42,7 @@ import { auditFlags, auditWhenSupported } from "./push-audit.js";
41
42
  import { consentRefusal, reportDevPushFailure } from "./push-refusal.js";
42
43
  import { COMPOSE_PINNED_IMAGE_ENV_KEYS, composeDockerImageEnv, composeProjectName, exitComposeFailed, noteUnpinnedImages, publishesDbToHost, runDockerCompose, runDockerComposeQuietly, settleComposeRuns, schemaEngineImageForPush, writeSelfHostCompose, composeFieldMaskingTier, selfHostComposePaths, } from "./self-host-compose.js";
43
44
  import { composeServiceIsRunning } from "./compose-kong.js";
45
+ import { requireStackDatabase } from "./local-stack-guard.js";
44
46
  import { hasEngineOverride } from "./binary-cache.js";
45
47
  import { STUDIO_DEV_PORT, startStudioViteDevServer } from "./studio-dev-server.js";
46
48
  import { ensureLocalServerDockerImage, usesLocalServerImage, LOCAL_SERVER_DOCKER_IMAGE, } from "./compose-local-server-image.js";
@@ -48,7 +50,7 @@ import { ensureEngine, enginePush, engineRequest } from "./engine-client.js";
48
50
  import { isAdoptOutcome, isAnyAnswer, isDiffResult, isEnginePushResult, isGenerateAnswer, } from "./engine-answers.js";
49
51
  import { writeSchemaSourcePushArtifacts } from "./schema-sources.js";
50
52
  import { readEnvFile, readEnvValue, upsertEnvFile } from "./env-file.js";
51
- import { warnProjectAuthProviderSecrets } from "./auth-providers.js";
53
+ import { warnMissingStackSettings } from "./stack-setting-warnings.js";
52
54
  import { devDatabaseIdentity, devDatabaseUrl, seedMissingDatabaseIdentity, seedMissingLocalSecrets, } from "./local-secrets.js";
53
55
  import { writeLocalEnvironment } from "./link.js";
54
56
  import { registerDevShutdown, waitForDevShutdown } from "./dev-shutdown.js";
@@ -65,15 +67,15 @@ import { adoptKeysNeed, assertSupported, engineCapabilities, identityColumnsNeed
65
67
  import { devPushConsentingToDrift } from "./drift-consent.js";
66
68
  import { capabilitiesCache, rememberCapabilitiesSync } from "@supatype/shared";
67
69
  import { waitForDatabaseAfterUp } from "./dev-db-ready.js";
68
- import { DERIVED_DSN_SOURCE, hostComposeDbUrl, requireRunningStack, resolveHostDatabaseUrl, stackHostDbUrl, } from "./host-database.js";
70
+ import { DERIVED_DSN_SOURCE, hostComposeDbUrl, NoStackRunning, requireRunningStack, resolveHostDatabaseUrl, stackHostDbUrl, } from "./host-database.js";
69
71
  import { studioUrlAt } from "./local-stack.js";
70
72
  import { grantAuthSchemaAccess, privatizeTableDefaults, reconcileAuthenticatorPassword, reconcileSqlEditorPassword, } from "./compose-db-roles.js";
71
- import { spawnComposeEngine } from "./compose-engine-run.js";
73
+ import { spawnComposeEngine, spawnComposeEngineSync } from "./compose-engine-run.js";
72
74
  import { waitForRestReady } from "./rest-ready.js";
73
- import { claimDevRenderMode, composeRenderMode, composeRenderOptions } from "./compose-render-mode.js";
74
- import { devMailerAutoconfirmUpdate, MAILER_AUTOCONFIRM_ENV } from "./mailer-autoconfirm.js";
75
- import { mailerProviderEnv } from "./mailer-env.js";
75
+ import { claimDevRenderMode, composeRenderMode, composeRenderOptions, runningStackMode } from "./compose-render-mode.js";
76
+ import { configMailerEnv } from "./config-mailer-env.js";
76
77
  import { fetchWithin } from "./fetch-within.js";
78
+ import { composeStackWatch, exitedServiceFailure } from "./stack-exit-watch.js";
77
79
  import { assertEngineVersionSupported, engineImageVersion } from "./engine-floor.js";
78
80
  /**
79
81
  * The image pins config asks for, once the engine's is known not to be older than this CLI needs.
@@ -116,10 +118,14 @@ function projectDatabaseUrl(cwd, config, inNetwork = false) {
116
118
  return inNetwork ? composeDbUrl(cwd) : stackHostDbUrl(cwd, config.project.name);
117
119
  }
118
120
  /**
119
- * When `provider: docker` and `overrides.engine` is set, ensure Postgres is published
120
- * on the host (SUPATYPE_DEV_DB_PORT) so the local engine binary can connect.
121
+ * When `provider: docker` and `overrides.engine` is set: the stack's Postgres, which the local
122
+ * engine binary reaches on the host port the compose file publishes. Every layout publishes `db`
123
+ * ({@link publishesDbToHost}), dev on SUPATYPE_DEV_DB_PORT and standalone on SUPATYPE_DB_PORT, so
124
+ * on a running stack it is already there. Nothing is started (issue 46): this ran `up -d db`, and
125
+ * on a dev stack moved the dev port first, under a database that was already up. A stack that is
126
+ * not running, or whose `db` container is not, is refused instead.
121
127
  */
122
- export async function ensureDockerDbPublishedForHostEngine(cwd, config, brand) {
128
+ export function ensureDockerDbPublishedForHostEngine(cwd, config, command) {
123
129
  if (resolveRuntimeProvider(config) !== "docker") {
124
130
  throw new Error("ensureDockerDbPublishedForHostEngine requires provider: docker");
125
131
  }
@@ -127,15 +133,9 @@ export async function ensureDockerDbPublishedForHostEngine(cwd, config, brand) {
127
133
  throw new Error("This project uses an external database, so there is no Docker Postgres to publish. " +
128
134
  "Point DATABASE_URL at it, or pass --connection.");
129
135
  }
130
- const project = composeProjectName(config.project.name);
131
- // A standalone stack already publishes its database (SUPATYPE_DB_PORT), and its .env is the
132
- // operator's: only a dev stack gets the dev port and the dev values (SH1). With no stack running
133
- // the URL the engine is handed cannot be derived, so refuse before starting anything (M1b).
134
- const mode = requireRunningStack(cwd, config.project.name);
135
- if (mode === "dev")
136
- await prepareDevComposeEnv(cwd, config, project, await resolveKongPort(cwd, project));
137
- const paths = writeSelfHostCompose(cwd, config, { devLocal: mode === "dev" });
138
- await startComposeDatabase(config, paths, cwd, project, brand);
136
+ // With no stack running the URL the engine is handed cannot be derived (M1b).
137
+ requireRunningStack(cwd, config.project.name);
138
+ requireStackDatabase(cwd, config, command);
139
139
  }
140
140
  /**
141
141
  * True when CLI should publish local Compose Postgres for the host-side engine
@@ -161,10 +161,10 @@ export async function resolveHostEngineDatabaseUrl(cwd, config, explicit) {
161
161
  // The URL comes from the one resolver every host-side command uses. It is resolved first so a
162
162
  // derived URL with no stack running refuses before anything starts (M1b), and a DATABASE_URL
163
163
  // someone set is used without one. Then, when it is this project's local docker Postgres, the
164
- // database is published so the URL reaches something.
164
+ // stack's database is checked to be running, which is what the URL reaches.
165
165
  const resolved = resolveHostDatabaseUrl(cwd, config, { connection: explicit, allowDerived: true });
166
166
  if (resolved.source === DERIVED_DSN_SOURCE && usesLocalDockerEngineDb(config, explicit)) {
167
- await ensureDockerDbPublishedForHostEngine(cwd, config);
167
+ ensureDockerDbPublishedForHostEngine(cwd, config);
168
168
  }
169
169
  return resolved.dsn;
170
170
  }
@@ -222,6 +222,7 @@ async function startComposeDatabase(config, paths, cwd, project, brand, timeoutM
222
222
  export function upsertDevComposeEnv(cwd, config, anonKey, serviceRoleKey, kongPort, devDbPort) {
223
223
  const apiUrl = `http://localhost:${kongPort}`;
224
224
  const imagePins = checkedImagePins(config);
225
+ const mailer = configMailerEnv(cwd, config);
225
226
  // `POSTGRES_PASSWORD` and `JWT_SECRET` are deliberately absent.
226
227
  //
227
228
  // They used to be pinned here to published constants on every `dev` run, against the same
@@ -247,12 +248,10 @@ export function upsertDevComposeEnv(cwd, config, anonKey, serviceRoleKey, kongPo
247
248
  SUPATYPE_KONG_PORT: String(kongPort),
248
249
  API_EXTERNAL_URL: apiUrl,
249
250
  SITE_URL: apiUrl,
250
- // From auth.email.enableConfirmations, unless the developer set their own in .env.
251
- ...devMailerAutoconfirmUpdate(cwd, config),
252
- // email.provider and its settings, which the compose file passes to the server. The compose
253
- // path used to carry none of them, so a project that asked for smtp, Resend or SES got the auth
254
- // service's noop client and no message at all.
255
- ...mailerProviderEnv(config.email),
251
+ // auth.email.enableConfirmations (unless the developer set their own in .env), email.provider
252
+ // and its settings, which the compose file passes to the server. The compose path used to carry
253
+ // none of them, so a project that asked for smtp, Resend or SES got the noop mailer.
254
+ ...mailer.updates,
256
255
  ...imagePins,
257
256
  };
258
257
  // Never for an external database: this URL describes the `db` container, which that project does
@@ -284,8 +283,8 @@ export function upsertDevComposeEnv(cwd, config, anonKey, serviceRoleKey, kongPo
284
283
  applyForThisRun(runOnly);
285
284
  const { urlsKept, rest } = takeFrontendUrls(persist);
286
285
  upsertEnvFile(cwd, rest, {
287
- removeManaged: removeImageKeys,
288
- managed: [...managedImageKeys, MAILER_AUTOCONFIRM_ENV],
286
+ removeManaged: [...removeImageKeys, ...mailer.removeManaged],
287
+ managed: [...managedImageKeys, ...mailer.managed],
289
288
  remove: [...retiredKeys, ...staleLocalServerImage(dotEnv["SUPATYPE_SERVER_IMAGE"], wantsLocalServer, imagePins)],
290
289
  });
291
290
  // The front end's copies go where a development build reads them, not .env, which a production
@@ -446,34 +445,49 @@ async function reportUnhealthyStack(composePath, cwd, project) {
446
445
  }
447
446
  console.error("");
448
447
  }
449
- async function waitKongReady(kongPort, maxSec, stack) {
448
+ /** One look at the gateway's two health routes: whether both answer OK, and what each said. */
449
+ async function gatewayHealth(base) {
450
+ try {
451
+ const [auth, realtime] = await Promise.all([
452
+ fetchWithin(`${base}/auth/v1/health`, 2000),
453
+ fetchWithin(`${base}/realtime/v1/health`, 2000),
454
+ ]);
455
+ return { ready: auth.ok && realtime.ok, auth: `HTTP ${auth.status}`, realtime: `HTTP ${realtime.status}` };
456
+ }
457
+ catch (err) {
458
+ return { ready: false, auth: errorMessage(err), realtime: errorMessage(err) };
459
+ }
460
+ }
461
+ /**
462
+ * Wait for the gateway at `kongPort`, watching `stack`'s essential services as it goes: one that
463
+ * has exited will not come back, so the wait stops there and prints its exit code and last log
464
+ * lines before the caller's cleanup removes them (issue 38). Either failure ends dev's dashboard
465
+ * first, so what it prints reaches the terminal rather than a screen that is about to close.
466
+ */
467
+ export async function waitKongReady(kongPort, maxSec, stack) {
450
468
  const base = loopbackBase(kongPort);
469
+ const watched = stack === undefined ? undefined : { watch: stack.watch ?? composeStackWatch(stack), cwd: stack.cwd };
451
470
  // Remembered so the failure can name the unhealthy upstream. Blaming "the
452
471
  // Kong gateway" sent more than one investigation after Kong when Kong was
453
472
  // fine and a service behind it was not.
454
- let lastAuth = "no response";
455
- let lastRealtime = "no response";
473
+ let last = { auth: "no response", realtime: "no response" };
456
474
  for (let i = 0; i < maxSec; i++) {
457
- try {
458
- const [auth, realtime] = await Promise.all([
459
- fetchWithin(`${base}/auth/v1/health`, 2000),
460
- fetchWithin(`${base}/realtime/v1/health`, 2000),
461
- ]);
462
- lastAuth = `HTTP ${auth.status}`;
463
- lastRealtime = `HTTP ${realtime.status}`;
464
- if (auth.ok && realtime.ok)
465
- return;
466
- }
467
- catch (err) {
468
- lastAuth = lastRealtime = errorMessage(err);
475
+ const [health, exited] = await Promise.all([gatewayHealth(base), watched?.watch.exited().catch(() => undefined)]);
476
+ if (health.ready)
477
+ return;
478
+ last = health;
479
+ if (exited !== undefined && watched !== undefined) {
480
+ endDevSession();
481
+ throw await exitedServiceFailure(exited, watched);
469
482
  }
470
483
  await sleep(1000);
471
484
  }
472
485
  if (stack !== undefined) {
486
+ endDevSession();
473
487
  await reportUnhealthyStack(stack.composePath, stack.cwd, stack.project);
474
488
  }
475
489
  throw new Error(`Gateway at ${base} did not become ready within ${maxSec}s ` +
476
- `(auth/v1/health: ${lastAuth}, realtime/v1/health: ${lastRealtime})`);
490
+ `(auth/v1/health: ${last.auth}, realtime/v1/health: ${last.realtime})`);
477
491
  }
478
492
  /** Kong may be up while server → storage is still starting (503 or upstream errors). */
479
493
  async function waitStorageApiReady(kongPort, serviceRoleKey, maxSec) {
@@ -680,6 +694,8 @@ export async function runComposeSchemaPush(cwd, config, paths, schemaPath, compo
680
694
  // asked by `engineRequest`).
681
695
  if (!hasEngineOverride(config))
682
696
  await requireDockerFeatures(cwd, config, identityColumnsNeed(ast));
697
+ if (opts.access === "plan")
698
+ await printPlannedAccess(cwd, config);
683
699
  try {
684
700
  if (hasEngineOverride(config))
685
701
  await applyViaHostEngine(cwd, config, ast, opts);
@@ -693,9 +709,27 @@ export async function runComposeSchemaPush(cwd, config, paths, schemaPath, compo
693
709
  _lastPushedAst = astJson;
694
710
  _lastFailedAst = null;
695
711
  if (astRelatesToAuthUsers(ast))
696
- grantAuthSchemaAccess(paths, cwd, composeProject);
712
+ await grantAuthSchemaAccess(paths, cwd, composeProject);
697
713
  await refreshSchemaArtifacts(cwd, config, ast);
698
714
  }
715
+ /**
716
+ * Each API role's access as the push about to apply leaves it, from a diff of the AST just written.
717
+ * Only a preview: a diff that fails says so and the push goes on, to report what is wrong itself.
718
+ */
719
+ async function printPlannedAccess(cwd, config) {
720
+ try {
721
+ const diff = await dockerDiff(cwd, config);
722
+ if (diff !== undefined)
723
+ printRoleAccess(diff);
724
+ }
725
+ catch (err) {
726
+ console.log(`[supatype] Could not read each role's access before the push: ${errorMessage(err)}`);
727
+ }
728
+ }
729
+ /** What a push reports of each role's access once applied: only `changes` prints anything. */
730
+ function appliedAccess(opts) {
731
+ return opts.access === undefined || opts.access === "changes" ? "changes" : "quiet";
732
+ }
699
733
  /** The schema on disk as a push sends it, and that AST serialized for comparing pushes. */
700
734
  function readSchemaToPush(schemaPath, cwd, config) {
701
735
  const ast = withPublishing(loadSchemaAst(schemaPath, cwd), config);
@@ -738,7 +772,7 @@ async function applyViaHostEngine(cwd, config, ast, opts) {
738
772
  schema_sources_manifest: sources.payload.manifest,
739
773
  }),
740
774
  };
741
- reportAppliedPush(await enginePush(cwd, body, isEnginePushResult));
775
+ reportAppliedPush(await enginePush(cwd, body, isEnginePushResult), appliedAccess(opts));
742
776
  }
743
777
  /** Apply the AST on disk with the stack's schema-engine container. Throws when it is not applied. */
744
778
  async function applyViaComposeEngine(cwd, config, stack, opts) {
@@ -777,7 +811,7 @@ async function runComposeSchemaPushQueued(cwd, config, paths, schemaPath, compos
777
811
  _composePushQueued = false;
778
812
  await runDevSchemaPush(cwd, config, paths, schemaPath, composeProject, opts);
779
813
  } while (_composePushQueued);
780
- followRecordedTier(cwd, config, { recreate: true });
814
+ await followRecordedTier(cwd, config, { recreate: true });
781
815
  }
782
816
  finally {
783
817
  _composePushInFlight = false;
@@ -791,13 +825,13 @@ async function runComposeSchemaPushQueued(cwd, config, paths, schemaPath, compos
791
825
  * recreated so a running stack serves the new search path now; a caller about to run
792
826
  * `compose up -d` leaves that to it.
793
827
  */
794
- export function followRecordedTier(cwd, config, opts) {
828
+ export async function followRecordedTier(cwd, config, opts) {
795
829
  if (usesExternalDatabase(config))
796
830
  return;
797
831
  const project = composeProjectName(config.project.name);
798
832
  const paths = selfHostComposePaths(cwd);
799
833
  const served = composeFieldMaskingTier(cwd, config);
800
- const recorded = recordDatabaseTier(cwd, { project, composePath: paths.composePath });
834
+ const recorded = await recordDatabaseTier(cwd, { project, composePath: paths.composePath });
801
835
  if (recorded === undefined || sameApiSurface(config, served, recorded))
802
836
  return;
803
837
  writeSelfHostCompose(cwd, config, composeRenderOptions(cwd, config.project.name));
@@ -858,7 +892,7 @@ async function runComposeEnginePush(paths, cwd, composeProject, config, sources,
858
892
  const pushResult = parseEnginePushOutput(output);
859
893
  if (exitStatus === 0) {
860
894
  if (pushResult) {
861
- reportAppliedPush(pushResult);
895
+ reportAppliedPush(pushResult, appliedAccess(opts));
862
896
  }
863
897
  else {
864
898
  console.log("[supatype] Schema applied.");
@@ -879,7 +913,7 @@ export async function dockerEngineCapabilities(cwd, config) {
879
913
  const paths = writeSelfHostCompose(cwd, config, composeRenderOptions(cwd, config.project.name));
880
914
  const target = { cwd, project: composeProjectName(config.project.name), composePath: paths.composePath, engineImage };
881
915
  return checkedCapabilities((args) => {
882
- const run = spawnComposeEngine(target, args, { runFlags: ["--no-deps"] });
916
+ const run = spawnComposeEngineSync(target, args, { runFlags: ["--no-deps"] });
883
917
  return { status: run.status, stdout: run.stdout, stderr: run.error ?? run.stderr };
884
918
  });
885
919
  };
@@ -959,7 +993,7 @@ async function runComposeEngineCommand(paths, cwd, composeProject, config, comma
959
993
  async function runComposeEngine(paths, cwd, composeProject, config, engineArgs) {
960
994
  const engineImage = await schemaEngineImageForPush(config, cwd);
961
995
  const target = { cwd, project: composeProject, composePath: paths.composePath, engineImage };
962
- const result = spawnComposeEngine(target, engineArgs, {
996
+ const result = await spawnComposeEngine(target, engineArgs, {
963
997
  secrets: { DATABASE_URL: projectDatabaseUrl(cwd, config, true) },
964
998
  });
965
999
  return {
@@ -1004,7 +1038,7 @@ export async function adoptSchemaDocker(cwd, config, yes, keys) {
1004
1038
  if (keys !== undefined)
1005
1039
  await requireDockerFeatures(cwd, config, [adoptKeysNeed(keys)]);
1006
1040
  if (hasEngineOverride(config)) {
1007
- await ensureDockerDbPublishedForHostEngine(cwd, config, { intro: "Adopt" });
1041
+ ensureDockerDbPublishedForHostEngine(cwd, config, "adopt");
1008
1042
  await ensureEngine();
1009
1043
  return engineRequest("/adopt", {
1010
1044
  ast: withPublishing(loadSchemaAst(schemaPathFromProject(config, cwd), cwd), config),
@@ -1029,60 +1063,30 @@ export async function adoptSchemaDocker(cwd, config, yes, keys) {
1029
1063
  * `overrides.engine` is set: then Postgres is published to the host and diff runs
1030
1064
  * through the local engine binary.
1031
1065
  *
1032
- * A dry run leaves the machine as it found it: a database the diff had to start is stopped again
1033
- * afterwards. It used to be left running.
1066
+ * Only against a stack that is running (issue 41): a stopped one is refused, not started. The diff
1067
+ * used to start Postgres itself, and stop it again afterwards.
1034
1068
  */
1035
1069
  export async function diffSchemaDocker(cwd, config) {
1036
1070
  if (resolveRuntimeProvider(config) !== "docker") {
1037
1071
  throw new Error("diffSchemaDocker requires provider: docker");
1038
1072
  }
1039
1073
  const project = composeProjectName(config.project.name);
1040
- const brand = { intro: "Schema diff" };
1041
1074
  if (hasEngineOverride(config)) {
1042
- return withComposeDatabaseStarted(cwd, config, project, () => ensureDockerDbPublishedForHostEngine(cwd, config, brand), () => diffWithHostEngine(cwd, config));
1075
+ ensureDockerDbPublishedForHostEngine(cwd, config, "diff");
1076
+ return diffWithHostEngine(cwd, config);
1043
1077
  }
1078
+ const running = runningStackMode(cwd, config.project.name);
1079
+ if (running === undefined && !usesExternalDatabase(config))
1080
+ throw new NoStackRunning("diff");
1044
1081
  // A diff of a standalone stack must not write dev values over the operator's .env (SH1). A dev
1045
- // stack's is brought up to date as push does: compose interpolates the whole file, so a project
1046
- // that has not yet run `dev` can lack values `up -d db` needs.
1047
- const mode = composeRenderMode(cwd, config.project.name);
1082
+ // stack's is brought up to date as push does: compose interpolates the whole file.
1083
+ const mode = running ?? "standalone";
1048
1084
  if (mode === "dev") {
1049
1085
  const { anonKey, serviceRoleKey } = devApiKeys(cwd);
1050
1086
  ensureDevComposeEnv(cwd, config, anonKey, serviceRoleKey, await resolveKongPort(cwd, project), undefined);
1051
1087
  }
1052
1088
  const paths = writeSelfHostCompose(cwd, config, { devLocal: mode === "dev" });
1053
- return withComposeDatabaseStarted(cwd, config, project, () => startComposeDatabase(config, paths, cwd, project, brand), () => diffWithComposeEngine(cwd, config, paths, project));
1054
- }
1055
- /**
1056
- * `run` with the stack's database up, `start` bringing it up, then stopped again when it was not
1057
- * running before. One that a `supatype dev` session or a running stack is using is left as it was.
1058
- */
1059
- async function withComposeDatabaseStarted(cwd, config, project, start, run) {
1060
- const stack = { project, composePath: selfHostComposePaths(cwd).composePath };
1061
- // An external database is not the stack's to start or stop.
1062
- const wasStopped = !usesExternalDatabase(config) && !composeServiceIsRunning(cwd, stack, "db");
1063
- let started = false;
1064
- try {
1065
- await start();
1066
- started = true;
1067
- return await run();
1068
- }
1069
- finally {
1070
- // A start that failed after `up -d db` (its health wait, the host publish) has still brought
1071
- // the container up; one refused before it (no stack running) has started nothing to stop.
1072
- if (wasStopped && (started || composeServiceIsRunning(cwd, stack, "db")))
1073
- stopComposeDatabase(cwd, stack);
1074
- }
1075
- }
1076
- /** Stop the stack's database, saying so rather than failing the command whose result is already in hand. */
1077
- function stopComposeDatabase(cwd, stack) {
1078
- try {
1079
- const status = runDockerCompose(stack.composePath, ["stop", "db"], cwd, stack.project, { quiet: true });
1080
- if (status !== 0)
1081
- warn("Could not stop the Postgres container this command started. Stop it with `supatype self-host compose stop db`.");
1082
- }
1083
- catch (err) {
1084
- warn(`Could not stop the Postgres container this command started: ${errorMessage(err)}`);
1085
- }
1089
+ return diffWithComposeEngine(cwd, config, paths, project);
1086
1090
  }
1087
1091
  /** The diff from the host engine binary, against the database published to the host. */
1088
1092
  async function diffWithHostEngine(cwd, config) {
@@ -1125,40 +1129,62 @@ function unparsedDiffError(rawOutput) {
1125
1129
  * `supatype push` when `provider: docker`. Uses in-compose schema-engine unless
1126
1130
  * `overrides.engine` is set: then Postgres is published to the host and push runs
1127
1131
  * through the local engine binary (AST v2, contributor builds).
1132
+ *
1133
+ * Only to a stack that is running (issue 41): a stopped one is refused, not started. The push used
1134
+ * to start Postgres, apply, then start the rest of the stack, and exited 1 with the schema applied
1135
+ * when that start failed. An external database is applied to with no stack running, and then no
1136
+ * stack is started.
1128
1137
  */
1129
1138
  export async function pushSchemaDocker(cwd, config, opts = {}) {
1130
1139
  if (resolveRuntimeProvider(config) !== "docker") {
1131
1140
  throw new Error("pushSchemaDocker requires provider: docker");
1132
1141
  }
1133
1142
  const project = composeProjectName(config.project.name);
1134
- // The stack's own mode, never dev by default: a push to a production stack used to render it as
1135
- // dev and recreate it that way, and write dev values over the operator's .env (SH1). A host
1136
- // engine is handed the database derived from the running stack, so with none running it refuses
1137
- // before anything starts (M1b).
1138
- const hostEngineDerivesDb = hasEngineOverride(config) && !usesExternalDatabase(config);
1139
- const mode = hostEngineDerivesDb
1140
- ? requireRunningStack(cwd, config.project.name)
1141
- : composeRenderMode(cwd, config.project.name);
1143
+ const running = pushStackMode(cwd, config);
1144
+ const mode = running ?? "standalone";
1142
1145
  const kongPort = await resolveKongPort(cwd, project);
1143
1146
  if (mode === "dev")
1144
1147
  await prepareDevComposeEnv(cwd, config, project, kongPort);
1145
- const gatewayPort = composeGatewayHostPort(config, mode, kongPort);
1146
- const { anonKey, serviceRoleKey } = devApiKeys(cwd);
1147
1148
  const paths = writeSelfHostCompose(cwd, config, { devLocal: mode === "dev" });
1148
- const pushBrand = { intro: "Push schema" };
1149
- await startComposeDatabase(config, paths, cwd, project, pushBrand);
1149
+ const stack = { paths, project, gatewayPort: composeGatewayHostPort(config, mode, kongPort), brand: { intro: "Push schema" } };
1150
1150
  if (!usesExternalDatabase(config))
1151
- privatizeTableDefaults(paths, cwd, project);
1151
+ await privatizeTableDefaults(paths, cwd, project);
1152
1152
  const schemaPath = schemaPathFromProject(config, cwd);
1153
1153
  const ast = withPublishing(loadSchemaAst(schemaPath, cwd), config);
1154
1154
  await runComposeSchemaPush(cwd, config, paths, schemaPath, project, opts);
1155
1155
  // `up -d` below recreates PostgREST when the tier changed its environment.
1156
- followRecordedTier(cwd, config, { recreate: false });
1157
- await bringPushedStackUp(cwd, config, { paths, project, gatewayPort, brand: pushBrand }, ast, {
1158
- anonKey,
1159
- serviceRoleKey,
1160
- });
1161
- console.log("[supatype] Schema pushed.");
1156
+ await followRecordedTier(cwd, config, { recreate: false });
1157
+ if (running === undefined) {
1158
+ console.log("[supatype] Schema pushed. The local stack isn't running, so nothing else was started.");
1159
+ return;
1160
+ }
1161
+ await bringUpAfterApply(() => bringPushedStackUp(cwd, config, stack, ast, devApiKeys(cwd)));
1162
+ }
1163
+ /**
1164
+ * The mode of the stack a push goes to, or undefined for an external database with no stack
1165
+ * running. A stopped stack with its own database is refused ({@link NoStackRunning}). The stack's
1166
+ * own mode, never dev by default: a push to a production stack used to render it as dev and
1167
+ * recreate it that way, and write dev values over the operator's .env (SH1).
1168
+ */
1169
+ function pushStackMode(cwd, config) {
1170
+ const running = runningStackMode(cwd, config.project.name);
1171
+ if (running === undefined && !usesExternalDatabase(config))
1172
+ throw new NoStackRunning("push");
1173
+ return running;
1174
+ }
1175
+ /**
1176
+ * What a push does on a running stack after it applied: `up -d` for what the schema changed, then
1177
+ * the buckets, the first admin and the REST wait. The schema is in by then, so a step that fails
1178
+ * does not fail the push (issue 41): it is warned about, and the push exits 0.
1179
+ */
1180
+ async function bringUpAfterApply(bringUp) {
1181
+ try {
1182
+ await bringUp();
1183
+ console.log("[supatype] Schema pushed.");
1184
+ }
1185
+ catch (err) {
1186
+ warn(`The schema was applied, but a step after it failed: ${errorMessage(err)}`);
1187
+ }
1162
1188
  }
1163
1189
  /**
1164
1190
  * The host port the stack's gateway answers plain HTTP on. A standalone stack with TLS publishes
@@ -1168,6 +1194,28 @@ export async function pushSchemaDocker(cwd, config, opts = {}) {
1168
1194
  export function composeGatewayHostPort(config, mode, kongPort) {
1169
1195
  return selfHostTlsEnabled(config, mode === "dev") ? 80 : kongPort;
1170
1196
  }
1197
+ /** A stack `up` started that never answered through its gateway: not up, whatever `up` said (issue 57). */
1198
+ export class StackNotServing extends Error {
1199
+ name = "StackNotServing";
1200
+ }
1201
+ /**
1202
+ * What a started stack needs once it answers: the gateway and storage waited for, then the schema's
1203
+ * declared buckets and the first admin user. A push to a running stack runs it after its `up -d`,
1204
+ * and `self-host compose up` after its own, so no command depends on a push to start the stack and
1205
+ * create them (issue 41).
1206
+ */
1207
+ export async function provisionStartedStack(cwd, config, stack, ast, serviceRoleKey) {
1208
+ const { composePath, project, gatewayPort } = stack;
1209
+ try {
1210
+ await waitKongReady(gatewayPort, 120, { composePath, cwd, project });
1211
+ }
1212
+ catch (err) {
1213
+ throw new StackNotServing(errorMessage(err), { cause: err });
1214
+ }
1215
+ await waitStorageApiReady(gatewayPort, serviceRoleKey, 90);
1216
+ await provisionDockerStorageBuckets(ast, gatewayPort, serviceRoleKey);
1217
+ await ensureFirstAdminUserForProject(cwd, config, { compose: { project, composePath } });
1218
+ }
1171
1219
  /**
1172
1220
  * After a compose push: the rest of the stack up, then what the schema asks of it once it answers
1173
1221
  * (buckets, the first admin), then REST, which is the last to catch up with the new schema.
@@ -1175,15 +1223,10 @@ export function composeGatewayHostPort(config, mode, kongPort) {
1175
1223
  async function bringPushedStackUp(cwd, config, stack, ast, keys) {
1176
1224
  const { paths, project, gatewayPort, brand } = stack;
1177
1225
  const upGateway = runDockerCompose(paths.composePath, ["up", "-d"], cwd, project, { quiet: true, brand });
1178
- if (upGateway !== 0) {
1179
- exitComposeFailed(upGateway, "Could not start the Compose gateway stack.", brand);
1180
- }
1181
- await waitKongReady(gatewayPort, 120, { composePath: paths.composePath, cwd, project });
1182
- await waitStorageApiReady(gatewayPort, keys.serviceRoleKey, 90);
1183
- await provisionDockerStorageBuckets(ast, gatewayPort, keys.serviceRoleKey);
1184
- await ensureFirstAdminUserForProject(cwd, config, {
1185
- compose: { project, composePath: paths.composePath },
1186
- });
1226
+ // Thrown, not exited: the schema is applied by now (bringUpAfterApply).
1227
+ if (upGateway !== 0)
1228
+ throw new Error(`docker compose up exited with status ${upGateway}`);
1229
+ await provisionStartedStack(cwd, config, { composePath: paths.composePath, project, gatewayPort }, ast, keys.serviceRoleKey);
1187
1230
  // Last, so the admin user and the buckets are not held up by it. `supatype dev` never comes
1188
1231
  // through here: it pushes before PostgREST starts, so PostgREST finds the schemas on its first try.
1189
1232
  await waitForRestReady(loopbackBase(gatewayPort), keys.anonKey);
@@ -1230,6 +1273,26 @@ async function devStackDbPort(cwd, config, project) {
1230
1273
  await offerToSaveShellDbPort(cwd);
1231
1274
  return port;
1232
1275
  }
1276
+ /** Stop the watchers and processes dev started, then bring the compose stack down. */
1277
+ export async function stopDevComposeStack(state, stack, cwd) {
1278
+ state.schemaWatcher?.close();
1279
+ state.schemaWatcher = null;
1280
+ state.functionsWatcher?.close();
1281
+ state.functionsWatcher = null;
1282
+ console.log("[supatype] Shutting down compose...");
1283
+ await state.studioProc?.stop();
1284
+ await state.appProc?.stop();
1285
+ await settleComposeRuns();
1286
+ // Docker was answering a moment ago, so the daemon probe is skipped: a slow `docker info` made it
1287
+ // report the daemon down and exit before `down` ran (issue 33).
1288
+ const downStatus = runDockerCompose(stack.composePath, ["down"], cwd, stack.project, { quiet: true, skipDaemonProbe: true });
1289
+ if (downStatus === 0) {
1290
+ console.log("[supatype] Compose stack stopped.");
1291
+ }
1292
+ else {
1293
+ console.warn(`[supatype] Compose down exited with status ${downStatus}.`);
1294
+ }
1295
+ }
1233
1296
  export async function runDevCompose(cwd, config, opts) {
1234
1297
  if (resolveRuntimeProvider(config) !== "docker") {
1235
1298
  throw new Error("runDevCompose requires provider: docker");
@@ -1253,7 +1316,7 @@ export async function runDevCompose(cwd, config, opts) {
1253
1316
  const devBrand = { intro: "Local development" };
1254
1317
  const localServerImage = await ensureLocalServerDockerImage(cwd, config, devBrand);
1255
1318
  ensureDevComposeEnv(cwd, config, anonKey, serviceRoleKey, kongPort, devDbPort);
1256
- warnProjectAuthProviderSecrets(cwd, config);
1319
+ warnMissingStackSettings(cwd, config);
1257
1320
  console.log(`[supatype] provider docker, starting self-host Compose stack (project ${project}, gateway :${kongPort})...`);
1258
1321
  await showDevStep("Preparing the Docker stack");
1259
1322
  noteUnpinnedImages(cwd);
@@ -1267,23 +1330,7 @@ export async function runDevCompose(cwd, config, opts) {
1267
1330
  schemaWatcher: null,
1268
1331
  functionsWatcher: null,
1269
1332
  };
1270
- registerDevShutdown(async () => {
1271
- shutdownState.schemaWatcher?.close();
1272
- shutdownState.schemaWatcher = null;
1273
- shutdownState.functionsWatcher?.close();
1274
- shutdownState.functionsWatcher = null;
1275
- console.log("[supatype] Shutting down compose...");
1276
- await shutdownState.studioProc?.stop();
1277
- await shutdownState.appProc?.stop();
1278
- await settleComposeRuns();
1279
- const downStatus = runDockerCompose(paths.composePath, ["down"], cwd, project, { quiet: true });
1280
- if (downStatus === 0) {
1281
- console.log("[supatype] Compose stack stopped.");
1282
- }
1283
- else {
1284
- console.warn(`[supatype] Compose down exited with status ${downStatus}.`);
1285
- }
1286
- }, {
1333
+ registerDevShutdown(() => stopDevComposeStack(shutdownState, { project, composePath: paths.composePath }, cwd), {
1287
1334
  cwd,
1288
1335
  compose: { cwd, composePath: paths.composePath, composeProject: project },
1289
1336
  });
@@ -1310,9 +1357,9 @@ export async function runDevCompose(cwd, config, opts) {
1310
1357
  // With the stack's database up, so a hand-written URL naming it is not reported as silent.
1311
1358
  await warnIfHandWrittenUrlSilent(cwd);
1312
1359
  if (!usesExternalDatabase(config)) {
1313
- reconcileAuthenticatorPassword(paths, cwd, project);
1314
- reconcileSqlEditorPassword(paths, cwd, project);
1315
- privatizeTableDefaults(paths, cwd, project);
1360
+ await reconcileAuthenticatorPassword(paths, cwd, project);
1361
+ await reconcileSqlEditorPassword(paths, cwd, project);
1362
+ await privatizeTableDefaults(paths, cwd, project);
1316
1363
  }
1317
1364
  // A: apply schema before realtime (and the rest of the stack) starts decoding WAL.
1318
1365
  const schemaPath = schemaPathFromProject(config, cwd);
@@ -1321,7 +1368,7 @@ export async function runDevCompose(cwd, config, opts) {
1321
1368
  await showDevStep("Applying the schema");
1322
1369
  const schemaApplied = await applyInitialSchema(cwd, config, paths, schemaPath, project, devBrand, pushOptions);
1323
1370
  // Before the stack starts, so PostgREST comes up on the tier the push actually produced.
1324
- followRecordedTier(cwd, config, { recreate: false });
1371
+ await followRecordedTier(cwd, config, { recreate: false });
1325
1372
  console.log("[supatype] Bringing up Docker Compose services...");
1326
1373
  await showDevStep("Starting services (the first start downloads their images)");
1327
1374
  const upStatus = await runDockerComposeQuietly(paths.composePath, ["up", "-d"], cwd, project, devBrand);
@@ -1446,14 +1493,18 @@ export async function runDevCompose(cwd, config, opts) {
1446
1493
  shutdownState.schemaWatcher = watchDevSchema({
1447
1494
  dir: schemaDir,
1448
1495
  changedSinceLastPush: () => schemaChangedSinceLastPush(schemaPath, cwd, config),
1496
+ // The failure is reported inside the scope too, so its hints reach the dashboard.
1449
1497
  push: (why) => {
1450
- console.log(`\n[supatype] ${why}, pushing schema...`);
1451
- runComposeSchemaPushQueued(cwd, config, paths, schemaPath, project, pushOptions)
1452
- .then(async () => {
1453
- const updatedAst = loadSchemaAst(schemaPath, cwd);
1454
- await provisionDockerStorageBuckets(updatedAst, kongPort, serviceRoleKey);
1455
- })
1456
- .catch(reportDevPushFailure);
1498
+ void withSavePushOutput(async () => {
1499
+ console.log(`\n[supatype] ${why}, pushing schema...`);
1500
+ try {
1501
+ await runComposeSchemaPushQueued(cwd, config, paths, schemaPath, project, pushOptions);
1502
+ await provisionDockerStorageBuckets(loadSchemaAst(schemaPath, cwd), kongPort, serviceRoleKey);
1503
+ }
1504
+ catch (err) {
1505
+ reportDevPushFailure(err);
1506
+ }
1507
+ });
1457
1508
  },
1458
1509
  });
1459
1510
  // The worker imports its handlers once; without this an edited function kept its old code.