@supatype/cli 0.7.0 → 0.9.0

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 (671) hide show
  1. package/CHANGELOG.md +314 -0
  2. package/bin/supatype.js +40 -4
  3. package/deno.d.ts +1 -1
  4. package/dist/admin-prompt-state.d.ts +13 -0
  5. package/dist/admin-prompt-state.d.ts.map +1 -0
  6. package/dist/admin-prompt-state.js +30 -0
  7. package/dist/admin-prompt-state.js.map +1 -0
  8. package/dist/adopt-columns.d.ts.map +1 -1
  9. package/dist/adopt-columns.js +13 -17
  10. package/dist/adopt-columns.js.map +1 -1
  11. package/dist/after-hooks-health.d.ts +19 -0
  12. package/dist/after-hooks-health.d.ts.map +1 -0
  13. package/dist/after-hooks-health.js +69 -0
  14. package/dist/after-hooks-health.js.map +1 -0
  15. package/dist/app-config.d.ts +1 -1
  16. package/dist/app-config.d.ts.map +1 -1
  17. package/dist/app-config.js +103 -144
  18. package/dist/app-config.js.map +1 -1
  19. package/dist/app-vite-env.d.ts +5 -1
  20. package/dist/app-vite-env.d.ts.map +1 -1
  21. package/dist/app-vite-env.js +9 -15
  22. package/dist/app-vite-env.js.map +1 -1
  23. package/dist/applied-ast-artifacts.d.ts +16 -0
  24. package/dist/applied-ast-artifacts.d.ts.map +1 -0
  25. package/dist/applied-ast-artifacts.js +37 -0
  26. package/dist/applied-ast-artifacts.js.map +1 -0
  27. package/dist/archive-extract.d.ts +3 -0
  28. package/dist/archive-extract.d.ts.map +1 -0
  29. package/dist/archive-extract.js +19 -0
  30. package/dist/archive-extract.js.map +1 -0
  31. package/dist/augmentation-generator.d.ts +5 -0
  32. package/dist/augmentation-generator.d.ts.map +1 -1
  33. package/dist/augmentation-generator.js +13 -4
  34. package/dist/augmentation-generator.js.map +1 -1
  35. package/dist/binary-cache.d.ts +27 -3
  36. package/dist/binary-cache.d.ts.map +1 -1
  37. package/dist/binary-cache.js +117 -85
  38. package/dist/binary-cache.js.map +1 -1
  39. package/dist/binary-download-lock.d.ts.map +1 -1
  40. package/dist/binary-download-lock.js +1 -3
  41. package/dist/binary-download-lock.js.map +1 -1
  42. package/dist/byo-preflight.d.ts.map +1 -1
  43. package/dist/byo-preflight.js +2 -10
  44. package/dist/byo-preflight.js.map +1 -1
  45. package/dist/byte-size.d.ts +9 -0
  46. package/dist/byte-size.d.ts.map +1 -0
  47. package/dist/byte-size.js +36 -0
  48. package/dist/byte-size.js.map +1 -0
  49. package/dist/cache-clean.d.ts +0 -2
  50. package/dist/cache-clean.d.ts.map +1 -1
  51. package/dist/cache-clean.js +1 -27
  52. package/dist/cache-clean.js.map +1 -1
  53. package/dist/cache-pins.d.ts.map +1 -1
  54. package/dist/cache-pins.js +3 -20
  55. package/dist/cache-pins.js.map +1 -1
  56. package/dist/cache-root.d.ts +7 -0
  57. package/dist/cache-root.d.ts.map +1 -0
  58. package/dist/cache-root.js +11 -0
  59. package/dist/cache-root.js.map +1 -0
  60. package/dist/cli-artifacts.d.ts.map +1 -1
  61. package/dist/cli-artifacts.js +2 -1
  62. package/dist/cli-artifacts.js.map +1 -1
  63. package/dist/cli-install-method.d.ts.map +1 -1
  64. package/dist/cli-install-method.js +7 -1
  65. package/dist/cli-install-method.js.map +1 -1
  66. package/dist/cli-launcher.d.ts +21 -0
  67. package/dist/cli-launcher.d.ts.map +1 -0
  68. package/dist/cli-launcher.js +112 -0
  69. package/dist/cli-launcher.js.map +1 -0
  70. package/dist/cli-old-versions.d.ts +44 -0
  71. package/dist/cli-old-versions.d.ts.map +1 -0
  72. package/dist/cli-old-versions.js +83 -0
  73. package/dist/cli-old-versions.js.map +1 -0
  74. package/dist/cli-program-path.d.ts +20 -0
  75. package/dist/cli-program-path.d.ts.map +1 -0
  76. package/dist/cli-program-path.js +41 -0
  77. package/dist/cli-program-path.js.map +1 -0
  78. package/dist/cli-standalone.d.ts +2 -3
  79. package/dist/cli-standalone.d.ts.map +1 -1
  80. package/dist/cli-standalone.js +51 -24
  81. package/dist/cli-standalone.js.map +1 -1
  82. package/dist/cli-version-embedded.js +1 -1
  83. package/dist/cloud-credentials.d.ts +6 -0
  84. package/dist/cloud-credentials.d.ts.map +1 -1
  85. package/dist/cloud-credentials.js +13 -0
  86. package/dist/cloud-credentials.js.map +1 -1
  87. package/dist/commands/admin.d.ts.map +1 -1
  88. package/dist/commands/admin.js +18 -18
  89. package/dist/commands/admin.js.map +1 -1
  90. package/dist/commands/app.d.ts.map +1 -1
  91. package/dist/commands/app.js +27 -8
  92. package/dist/commands/app.js.map +1 -1
  93. package/dist/commands/cache.d.ts.map +1 -1
  94. package/dist/commands/cache.js +37 -11
  95. package/dist/commands/cache.js.map +1 -1
  96. package/dist/commands/cloud.js +2 -4
  97. package/dist/commands/cloud.js.map +1 -1
  98. package/dist/commands/db.d.ts.map +1 -1
  99. package/dist/commands/db.js +116 -106
  100. package/dist/commands/db.js.map +1 -1
  101. package/dist/commands/deploy.d.ts.map +1 -1
  102. package/dist/commands/deploy.js +3 -3
  103. package/dist/commands/deploy.js.map +1 -1
  104. package/dist/commands/dev.d.ts +50 -4
  105. package/dist/commands/dev.d.ts.map +1 -1
  106. package/dist/commands/dev.js +276 -267
  107. package/dist/commands/dev.js.map +1 -1
  108. package/dist/commands/doctor.d.ts +32 -0
  109. package/dist/commands/doctor.d.ts.map +1 -1
  110. package/dist/commands/doctor.js +66 -1
  111. package/dist/commands/doctor.js.map +1 -1
  112. package/dist/commands/functions.d.ts +30 -0
  113. package/dist/commands/functions.d.ts.map +1 -1
  114. package/dist/commands/functions.js +503 -507
  115. package/dist/commands/functions.js.map +1 -1
  116. package/dist/commands/generate.d.ts.map +1 -1
  117. package/dist/commands/generate.js +11 -8
  118. package/dist/commands/generate.js.map +1 -1
  119. package/dist/commands/hooks.d.ts.map +1 -1
  120. package/dist/commands/hooks.js +46 -23
  121. package/dist/commands/hooks.js.map +1 -1
  122. package/dist/commands/init.d.ts +37 -4
  123. package/dist/commands/init.d.ts.map +1 -1
  124. package/dist/commands/init.js +509 -386
  125. package/dist/commands/init.js.map +1 -1
  126. package/dist/commands/internal.d.ts.map +1 -1
  127. package/dist/commands/internal.js +2 -1
  128. package/dist/commands/internal.js.map +1 -1
  129. package/dist/commands/keys.d.ts +46 -20
  130. package/dist/commands/keys.d.ts.map +1 -1
  131. package/dist/commands/keys.js +196 -156
  132. package/dist/commands/keys.js.map +1 -1
  133. package/dist/commands/link-helpers.d.ts.map +1 -1
  134. package/dist/commands/link-helpers.js +30 -11
  135. package/dist/commands/link-helpers.js.map +1 -1
  136. package/dist/commands/logs.d.ts.map +1 -1
  137. package/dist/commands/logs.js +5 -4
  138. package/dist/commands/logs.js.map +1 -1
  139. package/dist/commands/migrate.js +1 -1
  140. package/dist/commands/migrate.js.map +1 -1
  141. package/dist/commands/pg.js +2 -0
  142. package/dist/commands/pg.js.map +1 -1
  143. package/dist/commands/plugins.d.ts.map +1 -1
  144. package/dist/commands/plugins.js +17 -7
  145. package/dist/commands/plugins.js.map +1 -1
  146. package/dist/commands/push.d.ts +39 -0
  147. package/dist/commands/push.d.ts.map +1 -1
  148. package/dist/commands/push.js +221 -77
  149. package/dist/commands/push.js.map +1 -1
  150. package/dist/commands/seed.d.ts +35 -0
  151. package/dist/commands/seed.d.ts.map +1 -1
  152. package/dist/commands/seed.js +72 -38
  153. package/dist/commands/seed.js.map +1 -1
  154. package/dist/commands/self-host.d.ts.map +1 -1
  155. package/dist/commands/self-host.js +71 -42
  156. package/dist/commands/self-host.js.map +1 -1
  157. package/dist/commands/self-update.d.ts.map +1 -1
  158. package/dist/commands/self-update.js +9 -3
  159. package/dist/commands/self-update.js.map +1 -1
  160. package/dist/commands/status.js +5 -5
  161. package/dist/commands/status.js.map +1 -1
  162. package/dist/commands/types.js +2 -5
  163. package/dist/commands/types.js.map +1 -1
  164. package/dist/commands/update.d.ts.map +1 -1
  165. package/dist/commands/update.js +212 -101
  166. package/dist/commands/update.js.map +1 -1
  167. package/dist/component-launch.d.ts +11 -0
  168. package/dist/component-launch.d.ts.map +1 -0
  169. package/dist/component-launch.js +35 -0
  170. package/dist/component-launch.js.map +1 -0
  171. package/dist/components.d.ts +7 -2
  172. package/dist/components.d.ts.map +1 -1
  173. package/dist/components.js +7 -2
  174. package/dist/components.js.map +1 -1
  175. package/dist/compose-db-roles.d.ts.map +1 -1
  176. package/dist/compose-db-roles.js +5 -14
  177. package/dist/compose-db-roles.js.map +1 -1
  178. package/dist/compose-engine-run.d.ts +6 -5
  179. package/dist/compose-engine-run.d.ts.map +1 -1
  180. package/dist/compose-engine-run.js +44 -37
  181. package/dist/compose-engine-run.js.map +1 -1
  182. package/dist/compose-engine-service.d.ts +10 -0
  183. package/dist/compose-engine-service.d.ts.map +1 -0
  184. package/dist/compose-engine-service.js +16 -0
  185. package/dist/compose-engine-service.js.map +1 -0
  186. package/dist/compose-host-path.d.ts +14 -0
  187. package/dist/compose-host-path.d.ts.map +1 -0
  188. package/dist/compose-host-path.js +18 -0
  189. package/dist/compose-host-path.js.map +1 -0
  190. package/dist/compose-image-pull.d.ts +43 -0
  191. package/dist/compose-image-pull.d.ts.map +1 -0
  192. package/dist/compose-image-pull.js +27 -0
  193. package/dist/compose-image-pull.js.map +1 -0
  194. package/dist/compose-kong.d.ts +4 -0
  195. package/dist/compose-kong.d.ts.map +1 -1
  196. package/dist/compose-kong.js +23 -9
  197. package/dist/compose-kong.js.map +1 -1
  198. package/dist/compose-local-server-image.d.ts.map +1 -1
  199. package/dist/compose-local-server-image.js +7 -3
  200. package/dist/compose-local-server-image.js.map +1 -1
  201. package/dist/compose-render-mode.d.ts.map +1 -1
  202. package/dist/compose-render-mode.js +7 -4
  203. package/dist/compose-render-mode.js.map +1 -1
  204. package/dist/compose-services.d.ts +12 -2
  205. package/dist/compose-services.d.ts.map +1 -1
  206. package/dist/compose-services.js +27 -12
  207. package/dist/compose-services.js.map +1 -1
  208. package/dist/config-snapshot.d.ts +6 -0
  209. package/dist/config-snapshot.d.ts.map +1 -0
  210. package/dist/config-snapshot.js +23 -0
  211. package/dist/config-snapshot.js.map +1 -0
  212. package/dist/config.d.ts +11 -1
  213. package/dist/config.d.ts.map +1 -1
  214. package/dist/config.js +20 -3
  215. package/dist/config.js.map +1 -1
  216. package/dist/database-url-owner.d.ts +59 -0
  217. package/dist/database-url-owner.d.ts.map +1 -0
  218. package/dist/database-url-owner.js +133 -0
  219. package/dist/database-url-owner.js.map +1 -0
  220. package/dist/db-port-offer.d.ts +18 -0
  221. package/dist/db-port-offer.d.ts.map +1 -0
  222. package/dist/db-port-offer.js +68 -0
  223. package/dist/db-port-offer.js.map +1 -0
  224. package/dist/db-port.d.ts +42 -18
  225. package/dist/db-port.d.ts.map +1 -1
  226. package/dist/db-port.js +34 -32
  227. package/dist/db-port.js.map +1 -1
  228. package/dist/db-preflight.d.ts +37 -0
  229. package/dist/db-preflight.d.ts.map +1 -1
  230. package/dist/db-preflight.js +219 -77
  231. package/dist/db-preflight.js.map +1 -1
  232. package/dist/db-rows.d.ts +11 -0
  233. package/dist/db-rows.d.ts.map +1 -1
  234. package/dist/db-rows.js +27 -0
  235. package/dist/db-rows.js.map +1 -1
  236. package/dist/debounce.d.ts +11 -0
  237. package/dist/debounce.d.ts.map +1 -0
  238. package/dist/debounce.js +23 -0
  239. package/dist/debounce.js.map +1 -0
  240. package/dist/dev-api-keys.d.ts +12 -2
  241. package/dist/dev-api-keys.d.ts.map +1 -1
  242. package/dist/dev-api-keys.js +33 -17
  243. package/dist/dev-api-keys.js.map +1 -1
  244. package/dist/dev-compose.d.ts +10 -12
  245. package/dist/dev-compose.d.ts.map +1 -1
  246. package/dist/dev-compose.js +252 -288
  247. package/dist/dev-compose.js.map +1 -1
  248. package/dist/dev-db-ready.d.ts.map +1 -1
  249. package/dist/dev-db-ready.js +2 -1
  250. package/dist/dev-db-ready.js.map +1 -1
  251. package/dist/dev-db-reset.d.ts.map +1 -1
  252. package/dist/dev-db-reset.js +5 -4
  253. package/dist/dev-db-reset.js.map +1 -1
  254. package/dist/dev-functions-watch.d.ts.map +1 -1
  255. package/dist/dev-functions-watch.js +5 -16
  256. package/dist/dev-functions-watch.js.map +1 -1
  257. package/dist/dev-log-bus.d.ts +8 -0
  258. package/dist/dev-log-bus.d.ts.map +1 -1
  259. package/dist/dev-log-bus.js +13 -0
  260. package/dist/dev-log-bus.js.map +1 -1
  261. package/dist/dev-ports.d.ts +27 -7
  262. package/dist/dev-ports.d.ts.map +1 -1
  263. package/dist/dev-ports.js +68 -41
  264. package/dist/dev-ports.js.map +1 -1
  265. package/dist/dev-schema-watch.d.ts.map +1 -1
  266. package/dist/dev-schema-watch.js +7 -12
  267. package/dist/dev-schema-watch.js.map +1 -1
  268. package/dist/dev-session-lock.js +4 -3
  269. package/dist/dev-session-lock.js.map +1 -1
  270. package/dist/dev-session.d.ts +15 -0
  271. package/dist/dev-session.d.ts.map +1 -1
  272. package/dist/dev-session.js +27 -1
  273. package/dist/dev-session.js.map +1 -1
  274. package/dist/dev-shutdown.d.ts +45 -0
  275. package/dist/dev-shutdown.d.ts.map +1 -1
  276. package/dist/dev-shutdown.js +221 -33
  277. package/dist/dev-shutdown.js.map +1 -1
  278. package/dist/diff-output.d.ts +7 -1
  279. package/dist/diff-output.d.ts.map +1 -1
  280. package/dist/diff-output.js +91 -2
  281. package/dist/diff-output.js.map +1 -1
  282. package/dist/docker-address-pool.d.ts +23 -0
  283. package/dist/docker-address-pool.d.ts.map +1 -0
  284. package/dist/docker-address-pool.js +56 -0
  285. package/dist/docker-address-pool.js.map +1 -0
  286. package/dist/docker-exec.d.ts +92 -0
  287. package/dist/docker-exec.d.ts.map +1 -0
  288. package/dist/docker-exec.js +139 -0
  289. package/dist/docker-exec.js.map +1 -0
  290. package/dist/docker-postgres.d.ts +1 -6
  291. package/dist/docker-postgres.d.ts.map +1 -1
  292. package/dist/docker-postgres.js +67 -85
  293. package/dist/docker-postgres.js.map +1 -1
  294. package/dist/docker-runtime.d.ts +14 -1
  295. package/dist/docker-runtime.d.ts.map +1 -1
  296. package/dist/docker-runtime.js +55 -24
  297. package/dist/docker-runtime.js.map +1 -1
  298. package/dist/dotenv-parse.d.ts +22 -0
  299. package/dist/dotenv-parse.d.ts.map +1 -0
  300. package/dist/dotenv-parse.js +63 -0
  301. package/dist/dotenv-parse.js.map +1 -0
  302. package/dist/engine-answers.d.ts +0 -2
  303. package/dist/engine-answers.d.ts.map +1 -1
  304. package/dist/engine-answers.js +4 -3
  305. package/dist/engine-answers.js.map +1 -1
  306. package/dist/engine-client.d.ts.map +1 -1
  307. package/dist/engine-client.js +13 -12
  308. package/dist/engine-client.js.map +1 -1
  309. package/dist/engine-floor.d.ts +29 -0
  310. package/dist/engine-floor.d.ts.map +1 -1
  311. package/dist/engine-floor.js +56 -0
  312. package/dist/engine-floor.js.map +1 -1
  313. package/dist/engine-ownership-gate.d.ts +13 -1
  314. package/dist/engine-ownership-gate.d.ts.map +1 -1
  315. package/dist/engine-ownership-gate.js +36 -6
  316. package/dist/engine-ownership-gate.js.map +1 -1
  317. package/dist/ensure-binary.d.ts +9 -0
  318. package/dist/ensure-binary.d.ts.map +1 -1
  319. package/dist/ensure-binary.js +38 -5
  320. package/dist/ensure-binary.js.map +1 -1
  321. package/dist/ensure-component-binaries.d.ts.map +1 -1
  322. package/dist/ensure-component-binaries.js +2 -1
  323. package/dist/ensure-component-binaries.js.map +1 -1
  324. package/dist/env-file.d.ts +30 -8
  325. package/dist/env-file.d.ts.map +1 -1
  326. package/dist/env-file.js +84 -57
  327. package/dist/env-file.js.map +1 -1
  328. package/dist/env-lines.d.ts +11 -0
  329. package/dist/env-lines.d.ts.map +1 -0
  330. package/dist/env-lines.js +36 -0
  331. package/dist/env-lines.js.map +1 -0
  332. package/dist/error-message.d.ts +34 -1
  333. package/dist/error-message.d.ts.map +1 -1
  334. package/dist/error-message.js +102 -2
  335. package/dist/error-message.js.map +1 -1
  336. package/dist/fetch-within.d.ts +10 -0
  337. package/dist/fetch-within.d.ts.map +1 -0
  338. package/dist/fetch-within.js +12 -0
  339. package/dist/fetch-within.js.map +1 -0
  340. package/dist/field-masking-tier.d.ts.map +1 -1
  341. package/dist/field-masking-tier.js +7 -5
  342. package/dist/field-masking-tier.js.map +1 -1
  343. package/dist/frontend-env.d.ts +43 -0
  344. package/dist/frontend-env.d.ts.map +1 -0
  345. package/dist/frontend-env.js +81 -0
  346. package/dist/frontend-env.js.map +1 -0
  347. package/dist/functions-context-refresh.d.ts +6 -2
  348. package/dist/functions-context-refresh.d.ts.map +1 -1
  349. package/dist/functions-context-refresh.js +11 -3
  350. package/dist/functions-context-refresh.js.map +1 -1
  351. package/dist/functions-deno-types.d.ts.map +1 -1
  352. package/dist/functions-deno-types.js +9 -2
  353. package/dist/functions-deno-types.js.map +1 -1
  354. package/dist/{functions-router-gen.d.ts → functions-discovery.d.ts} +8 -10
  355. package/dist/functions-discovery.d.ts.map +1 -0
  356. package/dist/functions-discovery.js +87 -0
  357. package/dist/functions-discovery.js.map +1 -0
  358. package/dist/functions-template.d.ts.map +1 -1
  359. package/dist/functions-template.js +20 -12
  360. package/dist/functions-template.js.map +1 -1
  361. package/dist/functions-worker-files.d.ts +55 -0
  362. package/dist/functions-worker-files.d.ts.map +1 -0
  363. package/dist/functions-worker-files.js +149 -0
  364. package/dist/functions-worker-files.js.map +1 -0
  365. package/dist/generated/functions-worker-source.d.ts +2 -0
  366. package/dist/generated/functions-worker-source.d.ts.map +1 -0
  367. package/dist/generated/functions-worker-source.js +12 -0
  368. package/dist/generated/functions-worker-source.js.map +1 -0
  369. package/dist/generated/release-images.d.ts +18 -0
  370. package/dist/generated/release-images.d.ts.map +1 -0
  371. package/dist/generated/release-images.js +8 -0
  372. package/dist/generated/release-images.js.map +1 -0
  373. package/dist/generated-files-engine.d.ts +33 -0
  374. package/dist/generated-files-engine.d.ts.map +1 -0
  375. package/dist/generated-files-engine.js +45 -0
  376. package/dist/generated-files-engine.js.map +1 -0
  377. package/dist/hook-actor.d.ts +17 -0
  378. package/dist/hook-actor.d.ts.map +1 -0
  379. package/dist/hook-actor.js +37 -0
  380. package/dist/hook-actor.js.map +1 -0
  381. package/dist/hook-columns.d.ts +30 -0
  382. package/dist/hook-columns.d.ts.map +1 -0
  383. package/dist/hook-columns.js +77 -0
  384. package/dist/hook-columns.js.map +1 -0
  385. package/dist/hook-events.d.ts +11 -0
  386. package/dist/hook-events.d.ts.map +1 -0
  387. package/dist/hook-events.js +11 -0
  388. package/dist/hook-events.js.map +1 -0
  389. package/dist/hook-upload.d.ts +29 -15
  390. package/dist/hook-upload.d.ts.map +1 -1
  391. package/dist/hook-upload.js +88 -59
  392. package/dist/hook-upload.js.map +1 -1
  393. package/dist/hooks-generator.d.ts +5 -0
  394. package/dist/hooks-generator.d.ts.map +1 -1
  395. package/dist/hooks-generator.js +92 -21
  396. package/dist/hooks-generator.js.map +1 -1
  397. package/dist/host-database.d.ts.map +1 -1
  398. package/dist/host-database.js +31 -4
  399. package/dist/host-database.js.map +1 -1
  400. package/dist/init-dependency-versions.d.ts +3 -1
  401. package/dist/init-dependency-versions.d.ts.map +1 -1
  402. package/dist/init-dependency-versions.js +32 -6
  403. package/dist/init-dependency-versions.js.map +1 -1
  404. package/dist/init-example.d.ts +48 -0
  405. package/dist/init-example.d.ts.map +1 -0
  406. package/dist/init-example.js +110 -0
  407. package/dist/init-example.js.map +1 -0
  408. package/dist/init-package-json.d.ts +38 -1
  409. package/dist/init-package-json.d.ts.map +1 -1
  410. package/dist/init-package-json.js +150 -37
  411. package/dist/init-package-json.js.map +1 -1
  412. package/dist/init-setup-steps.d.ts +37 -0
  413. package/dist/init-setup-steps.d.ts.map +1 -0
  414. package/dist/init-setup-steps.js +118 -0
  415. package/dist/init-setup-steps.js.map +1 -0
  416. package/dist/jwt-secret-length.d.ts +5 -13
  417. package/dist/jwt-secret-length.d.ts.map +1 -1
  418. package/dist/jwt-secret-length.js +7 -22
  419. package/dist/jwt-secret-length.js.map +1 -1
  420. package/dist/jwt-secret-rules.d.ts +24 -0
  421. package/dist/jwt-secret-rules.d.ts.map +1 -0
  422. package/dist/jwt-secret-rules.js +46 -0
  423. package/dist/jwt-secret-rules.js.map +1 -0
  424. package/dist/local-gateway.d.ts +3 -6
  425. package/dist/local-gateway.d.ts.map +1 -1
  426. package/dist/local-gateway.js +7 -9
  427. package/dist/local-gateway.js.map +1 -1
  428. package/dist/local-secrets.d.ts +95 -11
  429. package/dist/local-secrets.d.ts.map +1 -1
  430. package/dist/local-secrets.js +153 -18
  431. package/dist/local-secrets.js.map +1 -1
  432. package/dist/local-stack.d.ts.map +1 -1
  433. package/dist/local-stack.js +2 -7
  434. package/dist/local-stack.js.map +1 -1
  435. package/dist/local-storage.d.ts +7 -2
  436. package/dist/local-storage.d.ts.map +1 -1
  437. package/dist/local-storage.js +11 -3
  438. package/dist/local-storage.js.map +1 -1
  439. package/dist/mailer-env.d.ts +37 -0
  440. package/dist/mailer-env.d.ts.map +1 -0
  441. package/dist/mailer-env.js +98 -0
  442. package/dist/mailer-env.js.map +1 -0
  443. package/dist/model-cache.d.ts +4 -8
  444. package/dist/model-cache.d.ts.map +1 -1
  445. package/dist/model-cache.js.map +1 -1
  446. package/dist/model-hooks.d.ts +21 -7
  447. package/dist/model-hooks.d.ts.map +1 -1
  448. package/dist/model-hooks.js +62 -39
  449. package/dist/model-hooks.js.map +1 -1
  450. package/dist/native-dev-env.d.ts +37 -1
  451. package/dist/native-dev-env.d.ts.map +1 -1
  452. package/dist/native-dev-env.js +64 -2
  453. package/dist/native-dev-env.js.map +1 -1
  454. package/dist/native-functions-watch.d.ts +56 -5
  455. package/dist/native-functions-watch.d.ts.map +1 -1
  456. package/dist/native-functions-watch.js +119 -38
  457. package/dist/native-functions-watch.js.map +1 -1
  458. package/dist/native-keyspace.d.ts.map +1 -1
  459. package/dist/native-keyspace.js +2 -2
  460. package/dist/native-keyspace.js.map +1 -1
  461. package/dist/native-realtime.d.ts +11 -3
  462. package/dist/native-realtime.d.ts.map +1 -1
  463. package/dist/native-realtime.js +162 -10
  464. package/dist/native-realtime.js.map +1 -1
  465. package/dist/native-roles-sql.d.ts +14 -0
  466. package/dist/native-roles-sql.d.ts.map +1 -1
  467. package/dist/native-roles-sql.js +82 -1
  468. package/dist/native-roles-sql.js.map +1 -1
  469. package/dist/native-storage-import.d.ts +19 -0
  470. package/dist/native-storage-import.d.ts.map +1 -0
  471. package/dist/native-storage-import.js +327 -0
  472. package/dist/native-storage-import.js.map +1 -0
  473. package/dist/native-storage.d.ts +45 -0
  474. package/dist/native-storage.d.ts.map +1 -0
  475. package/dist/native-storage.js +140 -0
  476. package/dist/native-storage.js.map +1 -0
  477. package/dist/native-worker.d.ts +26 -0
  478. package/dist/native-worker.d.ts.map +1 -0
  479. package/dist/native-worker.js +63 -0
  480. package/dist/native-worker.js.map +1 -0
  481. package/dist/owner-default.d.ts +9 -1
  482. package/dist/owner-default.d.ts.map +1 -1
  483. package/dist/owner-default.js +17 -4
  484. package/dist/owner-default.js.map +1 -1
  485. package/dist/post-apply.d.ts +3 -0
  486. package/dist/post-apply.d.ts.map +1 -0
  487. package/dist/post-apply.js +17 -0
  488. package/dist/post-apply.js.map +1 -0
  489. package/dist/postgres-ctl.d.ts +98 -7
  490. package/dist/postgres-ctl.d.ts.map +1 -1
  491. package/dist/postgres-ctl.js +273 -40
  492. package/dist/postgres-ctl.js.map +1 -1
  493. package/dist/postgres-image.d.ts +15 -3
  494. package/dist/postgres-image.d.ts.map +1 -1
  495. package/dist/postgres-image.js +18 -15
  496. package/dist/postgres-image.js.map +1 -1
  497. package/dist/postgrest-release.d.ts +9 -0
  498. package/dist/postgrest-release.d.ts.map +1 -1
  499. package/dist/postgrest-release.js +23 -0
  500. package/dist/postgrest-release.js.map +1 -1
  501. package/dist/process-manager.d.ts.map +1 -1
  502. package/dist/process-manager.js +3 -1
  503. package/dist/process-manager.js.map +1 -1
  504. package/dist/project-config.d.ts +44 -7
  505. package/dist/project-config.d.ts.map +1 -1
  506. package/dist/project-config.js +48 -4
  507. package/dist/project-config.js.map +1 -1
  508. package/dist/pull-utils.d.ts +15 -0
  509. package/dist/pull-utils.d.ts.map +1 -1
  510. package/dist/pull-utils.js +149 -23
  511. package/dist/pull-utils.js.map +1 -1
  512. package/dist/push-refusal.d.ts.map +1 -1
  513. package/dist/push-refusal.js +3 -2
  514. package/dist/push-refusal.js.map +1 -1
  515. package/dist/realtime-launch.d.ts +2 -5
  516. package/dist/realtime-launch.d.ts.map +1 -1
  517. package/dist/realtime-launch.js +6 -23
  518. package/dist/realtime-launch.js.map +1 -1
  519. package/dist/recorded-field-masking-tier.d.ts.map +1 -1
  520. package/dist/recorded-field-masking-tier.js +4 -3
  521. package/dist/recorded-field-masking-tier.js.map +1 -1
  522. package/dist/release-images.d.ts +31 -0
  523. package/dist/release-images.d.ts.map +1 -0
  524. package/dist/release-images.js +90 -0
  525. package/dist/release-images.js.map +1 -0
  526. package/dist/required-host-components.d.ts.map +1 -1
  527. package/dist/required-host-components.js +4 -0
  528. package/dist/required-host-components.js.map +1 -1
  529. package/dist/resolve-api-url.d.ts +17 -3
  530. package/dist/resolve-api-url.d.ts.map +1 -1
  531. package/dist/resolve-api-url.js +71 -30
  532. package/dist/resolve-api-url.js.map +1 -1
  533. package/dist/resolve-target.d.ts +64 -0
  534. package/dist/resolve-target.d.ts.map +1 -1
  535. package/dist/resolve-target.js +75 -27
  536. package/dist/resolve-target.js.map +1 -1
  537. package/dist/rest-ready.d.ts.map +1 -1
  538. package/dist/rest-ready.js +2 -1
  539. package/dist/rest-ready.js.map +1 -1
  540. package/dist/route-manifest.d.ts +25 -2
  541. package/dist/route-manifest.d.ts.map +1 -1
  542. package/dist/route-manifest.js +48 -4
  543. package/dist/route-manifest.js.map +1 -1
  544. package/dist/run-until-stopped.d.ts +12 -0
  545. package/dist/run-until-stopped.d.ts.map +1 -0
  546. package/dist/run-until-stopped.js +42 -0
  547. package/dist/run-until-stopped.js.map +1 -0
  548. package/dist/schema-ast-v2.d.ts +2 -1
  549. package/dist/schema-ast-v2.d.ts.map +1 -1
  550. package/dist/schema-ast-v2.js.map +1 -1
  551. package/dist/schema-push-lock.d.ts.map +1 -1
  552. package/dist/schema-push-lock.js +59 -46
  553. package/dist/schema-push-lock.js.map +1 -1
  554. package/dist/schema-sources.d.ts +19 -4
  555. package/dist/schema-sources.d.ts.map +1 -1
  556. package/dist/schema-sources.js +56 -35
  557. package/dist/schema-sources.js.map +1 -1
  558. package/dist/seed-auth-connect.d.ts +14 -0
  559. package/dist/seed-auth-connect.d.ts.map +1 -0
  560. package/dist/seed-auth-connect.js +97 -0
  561. package/dist/seed-auth-connect.js.map +1 -0
  562. package/dist/seed-runner.d.ts.map +1 -1
  563. package/dist/seed-runner.js +22 -1
  564. package/dist/seed-runner.js.map +1 -1
  565. package/dist/seed.d.ts +6 -3
  566. package/dist/seed.d.ts.map +1 -1
  567. package/dist/self-host-compose.d.ts +44 -29
  568. package/dist/self-host-compose.d.ts.map +1 -1
  569. package/dist/self-host-compose.js +311 -159
  570. package/dist/self-host-compose.js.map +1 -1
  571. package/dist/service-role-key-file.d.ts +32 -0
  572. package/dist/service-role-key-file.d.ts.map +1 -0
  573. package/dist/service-role-key-file.js +90 -0
  574. package/dist/service-role-key-file.js.map +1 -0
  575. package/dist/shell-ports.d.ts +13 -2
  576. package/dist/shell-ports.d.ts.map +1 -1
  577. package/dist/shell-ports.js +20 -15
  578. package/dist/shell-ports.js.map +1 -1
  579. package/dist/stop-signals.d.ts +7 -0
  580. package/dist/stop-signals.d.ts.map +1 -0
  581. package/dist/stop-signals.js +12 -0
  582. package/dist/stop-signals.js.map +1 -0
  583. package/dist/storage-launch.d.ts +11 -0
  584. package/dist/storage-launch.d.ts.map +1 -0
  585. package/dist/storage-launch.js +41 -0
  586. package/dist/storage-launch.js.map +1 -0
  587. package/dist/storage-provision.d.ts +50 -5
  588. package/dist/storage-provision.d.ts.map +1 -1
  589. package/dist/storage-provision.js +101 -33
  590. package/dist/storage-provision.js.map +1 -1
  591. package/dist/systemd.d.ts +1 -1
  592. package/dist/systemd.d.ts.map +1 -1
  593. package/dist/systemd.js +26 -11
  594. package/dist/systemd.js.map +1 -1
  595. package/dist/tar-reader.d.ts +29 -0
  596. package/dist/tar-reader.d.ts.map +1 -0
  597. package/dist/tar-reader.js +99 -0
  598. package/dist/tar-reader.js.map +1 -0
  599. package/dist/target-client.d.ts +14 -1
  600. package/dist/target-client.d.ts.map +1 -1
  601. package/dist/target-client.js +134 -23
  602. package/dist/target-client.js.map +1 -1
  603. package/dist/target-request.d.ts +25 -0
  604. package/dist/target-request.d.ts.map +1 -0
  605. package/dist/target-request.js +33 -0
  606. package/dist/target-request.js.map +1 -0
  607. package/dist/target-warning.d.ts +7 -0
  608. package/dist/target-warning.d.ts.map +1 -0
  609. package/dist/target-warning.js +12 -0
  610. package/dist/target-warning.js.map +1 -0
  611. package/dist/tsx-runner.d.ts.map +1 -1
  612. package/dist/tsx-runner.js +2 -1
  613. package/dist/tsx-runner.js.map +1 -1
  614. package/dist/type-extractor.d.ts +6 -0
  615. package/dist/type-extractor.d.ts.map +1 -1
  616. package/dist/type-extractor.js +138 -70
  617. package/dist/type-extractor.js.map +1 -1
  618. package/dist/ui/clack.d.ts.map +1 -1
  619. package/dist/ui/clack.js +11 -1
  620. package/dist/ui/clack.js.map +1 -1
  621. package/dist/ui/dev/DevDashboard.d.ts.map +1 -1
  622. package/dist/ui/dev/DevDashboard.js +13 -5
  623. package/dist/ui/dev/DevDashboard.js.map +1 -1
  624. package/dist/ui/fatal.d.ts.map +1 -1
  625. package/dist/ui/fatal.js +6 -7
  626. package/dist/ui/fatal.js.map +1 -1
  627. package/dist/ui/flows/FlowApp.d.ts.map +1 -1
  628. package/dist/ui/flows/FlowApp.js +16 -1
  629. package/dist/ui/flows/FlowApp.js.map +1 -1
  630. package/dist/ui/flows/prompt-fields.d.ts +16 -6
  631. package/dist/ui/flows/prompt-fields.d.ts.map +1 -1
  632. package/dist/ui/flows/prompt-fields.js +19 -9
  633. package/dist/ui/flows/prompt-fields.js.map +1 -1
  634. package/dist/ui/messages.d.ts +6 -0
  635. package/dist/ui/messages.d.ts.map +1 -1
  636. package/dist/ui/messages.js +17 -0
  637. package/dist/ui/messages.js.map +1 -1
  638. package/dist/ui/progress.d.ts +7 -0
  639. package/dist/ui/progress.d.ts.map +1 -1
  640. package/dist/ui/progress.js +22 -8
  641. package/dist/ui/progress.js.map +1 -1
  642. package/dist/ui/runtime/command-chrome.d.ts.map +1 -1
  643. package/dist/ui/runtime/command-chrome.js +2 -0
  644. package/dist/ui/runtime/command-chrome.js.map +1 -1
  645. package/dist/ui/runtime/prompt-interrupt.d.ts +10 -0
  646. package/dist/ui/runtime/prompt-interrupt.d.ts.map +1 -0
  647. package/dist/ui/runtime/prompt-interrupt.js +24 -0
  648. package/dist/ui/runtime/prompt-interrupt.js.map +1 -0
  649. package/dist/ui/runtime/run-clack-flow.d.ts.map +1 -1
  650. package/dist/ui/runtime/run-clack-flow.js +5 -2
  651. package/dist/ui/runtime/run-clack-flow.js.map +1 -1
  652. package/dist/ui/runtime/stdin-after-ink.d.ts +14 -1
  653. package/dist/ui/runtime/stdin-after-ink.d.ts.map +1 -1
  654. package/dist/ui/runtime/stdin-after-ink.js +44 -3
  655. package/dist/ui/runtime/stdin-after-ink.js.map +1 -1
  656. package/dist/url-safe-passwords.d.ts +25 -0
  657. package/dist/url-safe-passwords.d.ts.map +1 -0
  658. package/dist/url-safe-passwords.js +70 -0
  659. package/dist/url-safe-passwords.js.map +1 -0
  660. package/dist/valkey-sidecar.d.ts +33 -6
  661. package/dist/valkey-sidecar.d.ts.map +1 -1
  662. package/dist/valkey-sidecar.js +90 -61
  663. package/dist/valkey-sidecar.js.map +1 -1
  664. package/dist/worker-module-files.d.ts +3 -0
  665. package/dist/worker-module-files.d.ts.map +1 -0
  666. package/dist/worker-module-files.js +18 -0
  667. package/dist/worker-module-files.js.map +1 -0
  668. package/package.json +22 -16
  669. package/dist/functions-router-gen.d.ts.map +0 -1
  670. package/dist/functions-router-gen.js +0 -302
  671. package/dist/functions-router-gen.js.map +0 -1
package/dist/db-port.d.ts CHANGED
@@ -1,3 +1,26 @@
1
+ /**
2
+ * Keep `DATABASE_URL` pointing at the port Postgres is actually published on.
3
+ *
4
+ * `SUPATYPE_DB_PORT` moves the host side of the compose port mapping, so a second project on one
5
+ * machine can avoid a clash. `DATABASE_URL` is what every host-side script uses: seeds, one-off
6
+ * psql, `supatype admin create-user --connection`. `init` writes the URL with 5432 in it and
7
+ * nothing has ever reconciled the two.
8
+ *
9
+ * The result is a project that starts cleanly, serves every request, and fails the first time
10
+ * someone runs `npm run seed`:
11
+ *
12
+ * AggregateError [ECONNREFUSED]: connect ECONNREFUSED 127.0.0.1:5432
13
+ *
14
+ * with the database listening on 5433 and nothing connecting the error to the port variable the
15
+ * person set half an hour earlier. The generated `.env` even carries a comment conceding the
16
+ * assumption: "Self-host compose uses the same DATABASE_URL when Postgres is published on
17
+ * localhost:5432."
18
+ *
19
+ * The variable compose binds for the stack's layout is the source of truth: `SUPATYPE_DB_PORT` for
20
+ * a self-host stack, `SUPATYPE_DEV_DB_PORT` for a dev one. The URL follows it, when the CLI wrote
21
+ * it: this file says where Postgres is published and reads connection strings, and the one writer
22
+ * of `.env`'s URL, which decides whose it is first, is database-url-owner.ts.
23
+ */
1
24
  /** The `.env` key that moves the published Postgres port for a self-host stack. */
2
25
  export declare const DB_PORT_ENV = "SUPATYPE_DB_PORT";
3
26
  /**
@@ -48,33 +71,34 @@ export interface ComposeDbPublish {
48
71
  * `SUPATYPE_DEV_DB_PORT` on a production stack that publishes `SUPATYPE_DB_PORT`).
49
72
  */
50
73
  export declare function composeDbPublish(devLocal: boolean): ComposeDbPublish;
51
- /** The port Postgres is published on for this project in one layout, from `.env`. */
52
- export declare function publishedDbPort(env: Record<string, string>, devLocal: boolean): number;
74
+ /** Hosts whose port is ours to correct. Anything else is somebody else's database. */
75
+ export declare const LOCAL_HOSTS: ReadonlySet<string>;
76
+ /** The port Postgres is published on for this project in one layout, from `.env` or the shell. */
77
+ export declare function publishedDbPort(env: Readonly<Record<string, string | undefined>>, devLocal: boolean): number;
53
78
  /** What changed, for the caller to report. */
54
79
  export interface DbPortSync {
55
80
  from: string;
56
81
  to: string;
57
82
  /** The variable the new port was read from, which is what the report must name. */
58
83
  envKey: ComposeDbPublish["envKey"];
84
+ /** The port came from the shell, so the URL changed for this run only and `.env` did not. */
85
+ runOnly?: true;
59
86
  }
60
87
  /** The line every caller prints for a {@link DbPortSync}, naming the variable it read. */
61
88
  export declare function databaseUrlSyncMessage(sync: DbPortSync): string;
62
- /**
63
- * Rewrite `DATABASE_URL`'s port to match the port the stack's layout publishes Postgres on, and
64
- * report it.
65
- *
66
- * `devLocal` is the layout of the stack the caller is working with, never a guess from which
67
- * variables happen to be in `.env`: a project that once ran `supatype dev` keeps
68
- * `SUPATYPE_DEV_DB_PORT` there, and preferring it on a self-host push repointed every host-side
69
- * command (seed, admin) at the dev database.
70
- *
71
- * Returns null when there is nothing to do, which is the common case.
72
- *
73
- * Only touches a URL pointing at this machine. A project whose `DATABASE_URL` names a managed
74
- * Postgres elsewhere has a port that is nothing to do with our compose mapping, and rewriting it
75
- * would repoint the whole project at a database that does not exist.
76
- */
77
- export declare function syncDatabaseUrlPort(cwd: string, devLocal: boolean): DbPortSync | null;
89
+ /** `value` with its port set to `port`, when it names this machine on a different port. */
90
+ export declare function databaseUrlWithPort(value: string | undefined, port: number): {
91
+ url: string;
92
+ from: string;
93
+ to: string;
94
+ } | null;
78
95
  /** True when `url` is a connection string to a database on this machine. */
79
96
  export declare function isLocalDatabaseUrl(url: string): boolean;
97
+ /** `DATABASE_URL` parsed, when it names this machine; null when it is unset, malformed or remote. */
98
+ export declare function localDatabaseUrl(value: string | undefined): URL | null;
99
+ /** The host and port a Postgres URL names, the port defaulting to 5432; undefined when it does not parse. */
100
+ export declare function databaseUrlHostPort(value: string | undefined): {
101
+ host: string;
102
+ port: number;
103
+ } | undefined;
80
104
  //# sourceMappingURL=db-port.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"db-port.d.ts","source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AE,EAAE,MAAM,CAAA;IACV,mFAAmF;IACnF,MAAM,EAAE,gBAAgB,CAAC,QAAQ,CAAC,CAAA;IAClC,6FAA6F;IAC7F,OAAO,CAAC,EAAE,IAAI,CAAA;CACf;AAED,0FAA0F;AAC1F,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CAI/D;AAED,2FAA2F;AAC3F,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,IAAI,EAAE,MAAM,GACX;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAQlD;AAED,4EAA4E;AAC5E,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAEvD;AAED,qGAAqG;AACrG,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,GAAG,GAAG,IAAI,CAGtE;AAED,6GAA6G;AAC7G,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAGzG"}
package/dist/db-port.js CHANGED
@@ -17,9 +17,10 @@
17
17
  * localhost:5432."
18
18
  *
19
19
  * The variable compose binds for the stack's layout is the source of truth: `SUPATYPE_DB_PORT` for
20
- * a self-host stack, `SUPATYPE_DEV_DB_PORT` for a dev one. The URL follows it.
20
+ * a self-host stack, `SUPATYPE_DEV_DB_PORT` for a dev one. The URL follows it, when the CLI wrote
21
+ * it: this file says where Postgres is published and reads connection strings, and the one writer
22
+ * of `.env`'s URL, which decides whose it is first, is database-url-owner.ts.
21
23
  */
22
- import { readEnvFile, upsertEnvFile } from "./env-file.js";
23
24
  /** The `.env` key that moves the published Postgres port for a self-host stack. */
24
25
  export const DB_PORT_ENV = "SUPATYPE_DB_PORT";
25
26
  /**
@@ -66,8 +67,8 @@ export function composeDbPublish(devLocal) {
66
67
  : { envKey: DB_PORT_ENV, defaultPort: DEFAULT_DB_PORT, bindAddress: SELF_HOST_BIND };
67
68
  }
68
69
  /** Hosts whose port is ours to correct. Anything else is somebody else's database. */
69
- const LOCAL_HOSTS = new Set(["localhost", "127.0.0.1", "::1", "[::1]"]);
70
- /** The port Postgres is published on for this project in one layout, from `.env`. */
70
+ export const LOCAL_HOSTS = new Set(["localhost", "127.0.0.1", "::1", "[::1]"]);
71
+ /** The port Postgres is published on for this project in one layout, from `.env` or the shell. */
71
72
  export function publishedDbPort(env, devLocal) {
72
73
  const { envKey, defaultPort } = composeDbPublish(devLocal);
73
74
  const raw = (env[envKey] ?? "").trim();
@@ -78,52 +79,53 @@ export function publishedDbPort(env, devLocal) {
78
79
  }
79
80
  /** The line every caller prints for a {@link DbPortSync}, naming the variable it read. */
80
81
  export function databaseUrlSyncMessage(sync) {
81
- return `DATABASE_URL port ${sync.from} -> ${sync.to} in .env, to match ${sync.envKey}.`;
82
+ return sync.runOnly === true
83
+ ? `DATABASE_URL port ${sync.from} -> ${sync.to} for this run, to match ${sync.envKey} in your shell. .env is unchanged.`
84
+ : `DATABASE_URL port ${sync.from} -> ${sync.to} in .env, to match ${sync.envKey}.`;
82
85
  }
83
- /**
84
- * Rewrite `DATABASE_URL`'s port to match the port the stack's layout publishes Postgres on, and
85
- * report it.
86
- *
87
- * `devLocal` is the layout of the stack the caller is working with, never a guess from which
88
- * variables happen to be in `.env`: a project that once ran `supatype dev` keeps
89
- * `SUPATYPE_DEV_DB_PORT` there, and preferring it on a self-host push repointed every host-side
90
- * command (seed, admin) at the dev database.
91
- *
92
- * Returns null when there is nothing to do, which is the common case.
93
- *
94
- * Only touches a URL pointing at this machine. A project whose `DATABASE_URL` names a managed
95
- * Postgres elsewhere has a port that is nothing to do with our compose mapping, and rewriting it
96
- * would repoint the whole project at a database that does not exist.
97
- */
98
- export function syncDatabaseUrlPort(cwd, devLocal) {
99
- const env = readEnvFile(cwd);
100
- const url = localDatabaseUrl(env["DATABASE_URL"]);
86
+ /** `value` with its port set to `port`, when it names this machine on a different port. */
87
+ export function databaseUrlWithPort(value, port) {
88
+ const url = localDatabaseUrl(value);
101
89
  if (url === null)
102
90
  return null;
103
- const wanted = String(publishedDbPort(env, devLocal));
104
- const current = url.port === "" ? String(DEFAULT_DB_PORT) : url.port;
91
+ const wanted = String(port);
92
+ const current = String(urlPort(url));
105
93
  if (current === wanted)
106
94
  return null;
107
95
  url.port = wanted;
108
- upsertEnvFile(cwd, { DATABASE_URL: url.toString() });
109
- return { from: current, to: wanted, envKey: composeDbPublish(devLocal).envKey };
96
+ return { url: url.toString(), from: current, to: wanted };
110
97
  }
111
98
  /** True when `url` is a connection string to a database on this machine. */
112
99
  export function isLocalDatabaseUrl(url) {
113
100
  return localDatabaseUrl(url) !== null;
114
101
  }
115
102
  /** `DATABASE_URL` parsed, when it names this machine; null when it is unset, malformed or remote. */
116
- function localDatabaseUrl(value) {
103
+ export function localDatabaseUrl(value) {
104
+ const url = parsedDatabaseUrl(value);
105
+ return url !== null && LOCAL_HOSTS.has(url.hostname) ? url : null;
106
+ }
107
+ /** The host and port a Postgres URL names, the port defaulting to 5432; undefined when it does not parse. */
108
+ export function databaseUrlHostPort(value) {
109
+ const url = parsedDatabaseUrl(value);
110
+ return url === null ? undefined : { host: url.hostname.replace(/^\[|\]$/g, ""), port: urlPort(url) };
111
+ }
112
+ /** The port `url` names, or the one Postgres listens on when it names none. */
113
+ function urlPort(url) {
114
+ return url.port === "" ? DEFAULT_DB_PORT : Number(url.port);
115
+ }
116
+ /**
117
+ * A connection string parsed, or null when it is blank or malformed. Malformed is never ours to
118
+ * rewrite: a partial edit would turn a typo into a URL that parses and points somewhere wrong,
119
+ * which is harder to spot than the typo.
120
+ */
121
+ function parsedDatabaseUrl(value) {
117
122
  const raw = (value ?? "").trim();
118
123
  if (raw === "")
119
124
  return null;
120
125
  try {
121
- const url = new URL(raw);
122
- return LOCAL_HOSTS.has(url.hostname) ? url : null;
126
+ return new URL(raw);
123
127
  }
124
128
  catch {
125
- // Malformed, so not ours to rewrite: a partial edit here would turn a typo into a URL that
126
- // parses and points somewhere wrong, which is harder to spot than the typo.
127
129
  return null;
128
130
  }
129
131
  }
@@ -1 +1 @@
1
- {"version":3,"file":"db-port.js","sourceRoot":"","sources":["../src/db-port.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAE1D,mFAAmF;AACnF,MAAM,CAAC,MAAM,WAAW,GAAG,kBAAkB,CAAA;AAE7C;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,sBAAsB,CAAA;AAErD;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,yBAAyB,CAAA;AAE3D,4FAA4F;AAC5F,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,CAAA;AAEnC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,0BAA0B,CAAA;AAE7D,oFAAoF;AACpF,MAAM,CAAC,MAAM,cAAc,GAAG,yCAAyC,CAAA;AAEvE,mFAAmF;AACnF,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,CAAA;AAYxC;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,QAAiB;IAChD,OAAO,QAAQ;QACb,CAAC,CAAC,EAAE,MAAM,EAAE,eAAe,EAAE,WAAW,EAAE,mBAAmB,EAAE,WAAW,EAAE,YAAY,EAAE;QAC1F,CAAC,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,eAAe,EAAE,WAAW,EAAE,cAAc,EAAE,CAAA;AACxF,CAAC;AAED,sFAAsF;AACtF,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,WAAW,EAAE,KAAK,EAAE,OAAO,CA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AAyB;IAC3D,MAAM,GAAG,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAA;IACpC,OAAO,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,EAAE,CAAA;AACtG,CAAC;AAED,+EAA+E;AAC/E,SAAS,OAAO,CAAC,GAAQ;IACvB,OAAO,GAAG,CAAC,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;AAC7D,CAAC;AAED;;;;GAIG;AACH,SAAS,iBAAiB,CAAC,KAAyB;IAClD,MAAM,GAAG,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAA;IAChC,IAAI,GAAG,KAAK,EAAE;QAAE,OAAO,IAAI,CAAA;IAC3B,IAAI,CAAC;QACH,OAAO,IAAI,GAAG,CAAC,GAAG,CAAC,CAAA;IACrB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAA;IACb,CAAC;AACH,CAAC"}
@@ -47,6 +47,43 @@ type QueryFn = (sql: string, params?: unknown[]) => Promise<UnknownRow[]>;
47
47
  * ledger is only read where it exists, since SQL cannot name a table that is not there.
48
48
  */
49
49
  export declare function foreignTables(q: QueryFn, schema: string): Promise<string[]>;
50
+ /**
51
+ * Why the database cannot give realtime logical decoding, or undefined when it can: the same checks
52
+ * `supatype db check` runs, so the two cannot disagree. For native dev to name the cause when
53
+ * realtime exits without a word, instead of guessing at it (local test round 3), and for doctor.
54
+ */
55
+ export declare function decodingProblem(q: QueryFn): Promise<string | undefined>;
56
+ /** {@link decodingChecks} for the database at `databaseUrl`, on a connection of its own. */
57
+ export declare function logicalDecodingChecks(databaseUrl: string): Promise<CheckResult[]>;
58
+ /** {@link decodingProblem} for the database at `databaseUrl`, on a connection of its own. */
59
+ export declare function logicalDecodingProblem(databaseUrl: string): Promise<string | undefined>;
60
+ /**
61
+ * Which path after-hooks take on this database, from {@link decodingChecks}. The change log sees
62
+ * every writer; the fallback is the server reading the written rows back after an API request,
63
+ * which cannot see a write that never went through the API.
64
+ */
65
+ export declare function afterHooksSourceCheck(decoding: readonly CheckResult[]): CheckResult;
66
+ /** What after-hooks on the request path miss, said the same way by `db check` and `doctor`. */
67
+ export declare const REQUEST_PATH_IMPACT: string;
68
+ /**
69
+ * WAL a slot may hold before it is worth saying: a quarter of the `max_slot_wal_keep_size` the
70
+ * supatype/postgres image sets (4096 MB), past which Postgres gives up on the slot and its reader
71
+ * has to start again from now, losing what it had not read.
72
+ */
73
+ export declare const RETAINED_WAL_WARN_BYTES: number;
74
+ /** Bytes as a reader would say them, in GiB to one place. */
75
+ export declare function gibibytes(bytes: number): string;
76
+ /** One of Supatype's slots and the WAL it holds, in bytes as Postgres prints them. */
77
+ export interface SlotRetention {
78
+ slot_name: string;
79
+ retained: string;
80
+ }
81
+ /**
82
+ * Whether a Supatype slot holds a lot of WAL. A reader that stopped (a stopped server, a listener
83
+ * stuck on a hook that never answers) keeps WAL on disk until it reads again, and on a small
84
+ * volume that is how the database fills its disk with nothing saying why.
85
+ */
86
+ export declare function retainedWalCheck(slots: readonly SlotRetention[]): CheckResult;
50
87
  /** One row per API role that exists, for the schema named in the query. */
51
88
  export interface ClaimsSchemaUsageRow {
52
89
  rolname: string | null;
@@ -1 +1 @@
1
- {"version":3,"file":"db-preflight.d.ts","sourceRoot":"","sources":["../src/db-preflight.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,MAAM,IAAI,CAAA;AAEnB,OAAO,EAAa,KAAK,UAAU,EAAE,MAAM,cAAc,CAAA;AAGzD,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,MAAM,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AAA;IACtB,SAAS,EAAE,OAAO,GAAG,IAAI,CAAA;IACzB,KAAK,EAAE,MAAM,CAAA;CACd;AAQD;;;;;;;GAOG;AACH,eAAO,MAAM,oBAAoB,wBAAwB,CAAA;AAEzD,yFAAyF;AACzF,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,SAAS,WAAW,EAAE,GAAG,OAAO,CAE/E;AAcD,MAAM,WAAW,gBAAgB;IAC/B,+DAA+D;IAC/D,MAAM,EAAE,MAAM,CAAA;IACd,iFAAiF;IACjF,qBAAqB,CAAC,EAAE,MAAM,CAAA;CAC/B;AAED,wBAAsB,YAAY,CAChC,MAAM,EAAE,EAAE,CAAC,UAAU,EACrB,IAAI,EAAE,gBAAgB,GACrB,OAAO,CAAC,eAAe,CAAC,CAiQ1B;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,oBAAoB,EAAE,EAC5B,KAAK,EAAE;IAAE,YAAY,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,GACjD,WAAW,CA+Cb;AAyDD,6EAA6E;AAC7E,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAI/C;AAkBD;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,eAAe,GAAG,WAAW,EAAE,CAE5E;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,eAAe,GAAG,WAAW,EAAE,CAEvE;AAED;;;;;;;;;GASG;AACH,wBAAsB,aAAa,CACjC,MAAM,EAAE,EAAE,CAAC,UAAU,EACrB,QAAQ,EAAE,SAAS,WAAW,EAAE,GAC/B,OAAO,CAAC,IAAI,CAAC,CAef"}
@@ -16,8 +16,8 @@
16
16
  * should know something, and nothing is wrong.
17
17
  */
18
18
  import { isBoolean, isShape, isString, nullable } from "@supatype/shared";
19
- import { queryRows } from "./db-rows.js";
20
- import { errorCode } from "./error-message.js";
19
+ import { queryRows, withDatabase } from "./db-rows.js";
20
+ import { errorCode, errorMessage } from "./error-message.js";
21
21
  /** Slot name for the decoding probe. Dropped immediately; never left behind. */
22
22
  const PROBE_SLOT = "supatype_preflight_probe";
23
23
  /**
@@ -30,6 +30,13 @@ async function queryAs(q, guard, sql, params = []) {
30
30
  throw new Error(`Preflight probe returned a row it cannot read: ${sql}`);
31
31
  return rows;
32
32
  }
33
+ /** The one row of a probe that always returns exactly one. */
34
+ async function queryOne(q, guard, sql, params = []) {
35
+ const [row] = await queryAs(q, guard, sql, params);
36
+ if (row === undefined)
37
+ throw new Error(`Preflight probe returned no rows: ${sql}`);
38
+ return row;
39
+ }
33
40
  /**
34
41
  * Tables in `schema` Supatype did not create: not in its ledger (`_supatype.managed_objects`), and
35
42
  * not stamped `supatype:managed` by an engine from before the ledger. Since the engine stopped
@@ -51,43 +58,218 @@ export async function foreignTables(q, schema) {
51
58
  ORDER BY c.relname`, [schema]);
52
59
  return rows.map((t) => t.relname);
53
60
  }
61
+ /** The first decoding check that rules decoding out, or undefined when none does. */
62
+ function decodingBlocker(decoding) {
63
+ return decoding.find((r) => r.severity === "degrade" || r.severity === "fail");
64
+ }
65
+ /**
66
+ * Why the database cannot give realtime logical decoding, or undefined when it can: the same checks
67
+ * `supatype db check` runs, so the two cannot disagree. For native dev to name the cause when
68
+ * realtime exits without a word, instead of guessing at it (local test round 3), and for doctor.
69
+ */
70
+ export async function decodingProblem(q) {
71
+ return decodingBlocker(await decodingChecks(q))?.detail;
72
+ }
73
+ /** {@link decodingChecks} for the database at `databaseUrl`, on a connection of its own. */
74
+ export async function logicalDecodingChecks(databaseUrl) {
75
+ return withDatabase(databaseUrl, (client) => decodingChecks((sql, params = []) => queryRows(client, sql, params)));
76
+ }
77
+ /** {@link decodingProblem} for the database at `databaseUrl`, on a connection of its own. */
78
+ export async function logicalDecodingProblem(databaseUrl) {
79
+ return decodingBlocker(await logicalDecodingChecks(databaseUrl))?.detail;
80
+ }
81
+ /** What a database that cannot decode loses, said the same way by every check that finds it. */
82
+ const NO_DECODING_IMPACT = "Realtime subscriptions are unavailable, and after-hooks fall back to the request path; everything " +
83
+ "else is unaffected.";
84
+ /**
85
+ * What logical decoding needs, which realtime and the after-hook listener share: `wal_level`, a
86
+ * spare slot, and a wal2json slot the connected role may create.
87
+ */
88
+ async function decodingChecks(q) {
89
+ const { wal_level } = await queryOne(q, isShape({ wal_level: isString }), "SHOW wal_level");
90
+ const slots = await queryOne(q, isShape({ used: isString, max: isString, existing: isString, role: isString }), `SELECT (SELECT count(*) FROM pg_replication_slots)::text AS used,
91
+ current_setting('max_replication_slots') AS max,
92
+ coalesce((SELECT string_agg(slot_name, ',') FROM pg_replication_slots
93
+ WHERE slot_name = ANY($1)), '') AS existing,
94
+ current_user::text AS role`, [[...SUPATYPE_SLOTS]]);
95
+ const existing = slots.existing === "" ? [] : slots.existing.split(",");
96
+ const results = [walLevelCheck(wal_level), slotsCheck(slots.used, slots.max, existing)];
97
+ // The definitive check: create the slot realtime would create, then drop it.
98
+ //
99
+ // There is no catalog to consult. `wal2json` is a shared library, not an extension, so it never
100
+ // appears in `pg_available_extensions`: the only way to know whether this database can decode is
101
+ // to ask it to. Cloud SQL does not ship the plugin at all; plenty of managed Postgres will not
102
+ // grant `REPLICATION`. Both produce a stack that looks healthy until the first subscription.
103
+ //
104
+ // Skipped when `wal_level` or the slot budget already rules it out, since the probe would fail for
105
+ // that reason and report it a second time under a less specific heading.
106
+ if (results.every((r) => r.severity === "pass"))
107
+ results.push(await probeLogicalDecoding(q, slots.role));
108
+ return results;
109
+ }
110
+ function walLevelCheck(walLevel) {
111
+ const logical = walLevel === "logical";
112
+ return {
113
+ id: "wal-level",
114
+ title: "wal_level = logical (realtime, after-hooks)",
115
+ severity: logical ? "pass" : "degrade",
116
+ detail: logical ? `wal_level is "${walLevel}"` : `wal_level is "${walLevel}", not logical`,
117
+ ...(!logical && {
118
+ impact: NO_DECODING_IMPACT,
119
+ remedy: "-- Requires a server restart, and on managed Postgres a parameter-group change\n" +
120
+ "-- rather than SQL. Shown for a self-managed server:\n" +
121
+ "ALTER SYSTEM SET wal_level = 'logical';",
122
+ remedyNeedsOperator: true,
123
+ }),
124
+ };
125
+ }
126
+ /**
127
+ * Room for the slots Supatype has not created yet. Realtime and the after-hook listener each keep a
128
+ * slot of their own, so a database with one free slot has room for only one of them.
129
+ */
130
+ function slotsCheck(used, max, existing) {
131
+ const free = Math.max(Number(max) - Number(used), 0);
132
+ const needed = SUPATYPE_SLOTS.filter((slot) => !existing.includes(slot));
133
+ const leftOut = needed.slice(free);
134
+ return {
135
+ id: "replication-slots",
136
+ title: "A replication slot each for realtime and after-hooks",
137
+ severity: leftOut.length === 0 ? "pass" : "degrade",
138
+ detail: `${used} of ${max} in use` +
139
+ (leftOut.length === 0 ? "" : `, no room for ${leftOut.join(" or ")} (${needed.length} needed, ${free} free)`),
140
+ ...(leftOut.length > 0 && {
141
+ impact: "Realtime and the after-hook listener each need a slot of their own, and the ones named cannot create one.",
142
+ remedy: `ALTER SYSTEM SET max_replication_slots = ${Number(used) + needed.length + 5};`,
143
+ remedyNeedsOperator: true,
144
+ }),
145
+ };
146
+ }
147
+ /**
148
+ * Which path after-hooks take on this database, from {@link decodingChecks}. The change log sees
149
+ * every writer; the fallback is the server reading the written rows back after an API request,
150
+ * which cannot see a write that never went through the API.
151
+ */
152
+ export function afterHooksSourceCheck(decoding) {
153
+ const base = { id: "after-hooks-source", title: "Where after-hooks read writes from" };
154
+ const blocker = decodingBlocker(decoding);
155
+ if (blocker === undefined) {
156
+ return { ...base, severity: "pass", detail: "the change log: afterChange and afterDelete see every writer" };
157
+ }
158
+ return {
159
+ ...base,
160
+ severity: "degrade",
161
+ detail: `the request path, because ${blocker.detail}`,
162
+ impact: `${REQUEST_PATH_IMPACT} Fix "${blocker.title}" above to move them to the change log.`,
163
+ };
164
+ }
165
+ /** What after-hooks on the request path miss, said the same way by `db check` and `doctor`. */
166
+ export const REQUEST_PATH_IMPACT = "afterChange and afterDelete fire only for writes made through the API. A write made outside the " +
167
+ "API (SQL, a migration, a function's own database connection) does not reach them.";
168
+ /** The replication slots Supatype's own services read: realtime's and the after-hook listener's. */
169
+ const SUPATYPE_SLOTS = ["supatype_realtime", "supatype_hooks"];
170
+ /**
171
+ * WAL a slot may hold before it is worth saying: a quarter of the `max_slot_wal_keep_size` the
172
+ * supatype/postgres image sets (4096 MB), past which Postgres gives up on the slot and its reader
173
+ * has to start again from now, losing what it had not read.
174
+ */
175
+ export const RETAINED_WAL_WARN_BYTES = 1024 ** 3;
176
+ /** Bytes as a reader would say them, in GiB to one place. */
177
+ export function gibibytes(bytes) {
178
+ return `${(bytes / 1024 ** 3).toFixed(1)} GiB`;
179
+ }
54
180
  /**
55
- * Ask the database to do the one thing realtime needs, then undo it.
181
+ * Whether a Supatype slot holds a lot of WAL. A reader that stopped (a stopped server, a listener
182
+ * stuck on a hook that never answers) keeps WAL on disk until it reads again, and on a small
183
+ * volume that is how the database fills its disk with nothing saying why.
184
+ */
185
+ export function retainedWalCheck(slots) {
186
+ const base = { id: "slot-retained-wal", title: "WAL held by Supatype's replication slots" };
187
+ const heavy = slots.filter((slot) => Number(slot.retained) > RETAINED_WAL_WARN_BYTES);
188
+ if (heavy.length === 0) {
189
+ return { ...base, severity: "pass", detail: `none holds more than ${gibibytes(RETAINED_WAL_WARN_BYTES)}` };
190
+ }
191
+ return {
192
+ ...base,
193
+ severity: "warn",
194
+ detail: heavy.map((slot) => `${slot.slot_name} holds ${gibibytes(Number(slot.retained))}`).join(", "),
195
+ impact: "Its reader is behind or stopped. Start the stack so it catches up; one that stays behind is " +
196
+ "dropped by Postgres at max_slot_wal_keep_size, and its reader starts again from now.",
197
+ };
198
+ }
199
+ /** {@link retainedWalCheck} for the database `q` reaches. */
200
+ async function slotRetention(q) {
201
+ const slots = await queryAs(q, isShape({ slot_name: isString, retained: isString }), `SELECT slot_name, coalesce(pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn), 0)::bigint::text AS retained
202
+ FROM pg_replication_slots WHERE slot_name = ANY($1)`, [[...SUPATYPE_SLOTS]]);
203
+ return retainedWalCheck(slots);
204
+ }
205
+ /**
206
+ * Who the answer is about. The probe runs as the role `db check` connected as, while the server's
207
+ * listener connects with SUPATYPE_SQL_DATABASE_URL, which a generated stack sets to its owner URL
208
+ * (POSTGRES_USER, or DATABASE_URL for an external database).
209
+ */
210
+ const SERVER_ROLE_NOTE = "The server's after-hook listener connects with SUPATYPE_SQL_DATABASE_URL; check that role if it is not this one.";
211
+ /** Postgres's words when `output_plugin_libraries` does not name the plugin a slot asked for. */
212
+ const NOT_AN_ALLOWED_PLUGIN = "may not be used as an output plugin";
213
+ /**
214
+ * Why the probe slot was refused, and what fixes it. Both refusals that share `42501` are told
215
+ * apart by Postgres's message: the allowlist one has no SQLSTATE of its own.
216
+ */
217
+ /** How to let a slot decode with wal2json when output_plugin_libraries leaves it out. */
218
+ const ALLOW_WAL2JSON_REMEDY = [
219
+ "-- This sets the whole list: name any plugin it already allows as well, as in",
220
+ "-- 'wal2json, other_plugin'. Then reload:",
221
+ "ALTER SYSTEM SET output_plugin_libraries = 'wal2json';",
222
+ "SELECT pg_reload_conf();",
223
+ ].join("\n");
224
+ /** What to do when the server has no wal2json library. */
225
+ const INSTALL_WAL2JSON_REMEDY = [
226
+ "-- wal2json is a server library, not an extension: it must be installed on the host",
227
+ "-- (or offered by your provider) and cannot be added over SQL. Supatype's own image",
228
+ "-- ships it. Set database.external.realtime: false to stop starting the service.",
229
+ ].join("\n");
230
+ function decodingRefusal(error, role) {
231
+ const code = errorCode(error);
232
+ const message = errorMessage(error);
233
+ if (code === "42501" && message.includes(NOT_AN_ALLOWED_PLUGIN)) {
234
+ return {
235
+ detail: "output_plugin_libraries does not name wal2json, so no slot may decode with it",
236
+ remedy: ALLOW_WAL2JSON_REMEDY,
237
+ };
238
+ }
239
+ if (code === "42501") {
240
+ return {
241
+ detail: `role "${role}" may not use replication slots (no REPLICATION attribute)`,
242
+ remedy: [
243
+ `-- ${SERVER_ROLE_NOTE}`,
244
+ `ALTER ROLE ${ident(role)} WITH REPLICATION;`,
245
+ ].join("\n"),
246
+ };
247
+ }
248
+ return {
249
+ detail: code === "58P01" ? "the wal2json output plugin is not installed on this server" : message,
250
+ remedy: INSTALL_WAL2JSON_REMEDY,
251
+ };
252
+ }
253
+ /**
254
+ * Ask the database to do the one thing realtime and the after-hook listener need, then undo it.
56
255
  *
57
256
  * SQLSTATEs measured against `supatype/postgres` rather than recalled:
58
- * `55000` wal_level too low, `58P01` the plugin's library is absent, `42501` the role may not use
59
- * replication slots.
257
+ * `55000` wal_level too low, `58P01` the plugin's library is absent, `42501` either the role may
258
+ * not use replication slots or `output_plugin_libraries` does not name wal2json.
60
259
  */
61
- async function probeLogicalDecoding(q) {
62
- const base = { id: "logical-decoding", title: "wal2json logical decoding (realtime)" };
260
+ async function probeLogicalDecoding(q, role) {
261
+ const base = { id: "logical-decoding", title: "wal2json logical decoding (realtime, after-hooks)" };
63
262
  try {
64
263
  await q(`SELECT pg_create_logical_replication_slot($1, 'wal2json')`, [PROBE_SLOT]);
65
264
  }
66
265
  catch (error) {
67
- const code = errorCode(error);
68
- const detail = code === "58P01"
69
- ? "the wal2json output plugin is not installed on this server"
70
- : code === "42501"
71
- ? "this role may not use replication slots (no REPLICATION attribute)"
72
- : error instanceof Error
73
- ? error.message
74
- : String(error);
75
266
  return {
76
267
  ...base,
77
268
  severity: "degrade",
78
- detail,
79
- impact: "Realtime subscriptions are unavailable; everything else is unaffected. The service still " +
80
- "starts, reports this reason on /health/ready, and serves nothing else differently.",
81
- ...(code === "42501"
82
- ? { remedy: `ALTER ROLE CURRENT_USER WITH REPLICATION;`, remedyNeedsOperator: true }
83
- : {
84
- remedy: [
85
- "-- wal2json is a server library, not an extension: it must be installed on the host",
86
- "-- (or offered by your provider) and cannot be added over SQL. Supatype's own image",
87
- "-- ships it. Set database.external.realtime: false to stop starting the service.",
88
- ].join("\n"),
89
- remedyNeedsOperator: true,
90
- }),
269
+ ...decodingRefusal(error, role),
270
+ impact: `${NO_DECODING_IMPACT} The realtime service still starts, reports this reason on ` +
271
+ "/health/ready, and serves nothing else differently.",
272
+ remedyNeedsOperator: true,
91
273
  };
92
274
  }
93
275
  // Leave nothing behind. A slot that is never read holds WAL forever, which on a database Supatype
@@ -105,7 +287,11 @@ async function probeLogicalDecoding(q) {
105
287
  remedy: `SELECT pg_drop_replication_slot('${PROBE_SLOT}');`,
106
288
  };
107
289
  }
108
- return { ...base, severity: "pass", detail: "a wal2json slot can be created and dropped" };
290
+ return {
291
+ ...base,
292
+ severity: "pass",
293
+ detail: `role "${role}" can create and drop a wal2json slot. ${SERVER_ROLE_NOTE}`,
294
+ };
109
295
  }
110
296
  const REQUIRED_ROLES = ["anon", "authenticated", "service_role", "authenticator"];
111
297
  /** The three roles PostgREST switches to per request. `authenticator` only connects and switches. */
@@ -144,12 +330,7 @@ export async function runPreflight(client, opts) {
144
330
  const results = [];
145
331
  const q = (sql, params = []) => queryRows(client, sql, params);
146
332
  /** For probes that always return exactly one row. */
147
- const one = async (guard, sql, params = []) => {
148
- const [row] = await queryAs(q, guard, sql, params);
149
- if (row === undefined)
150
- throw new Error(`Preflight probe returned no rows: ${sql}`);
151
- return row;
152
- };
333
+ const one = (guard, sql, params = []) => queryOne(q, guard, sql, params);
153
334
  // ── Server version ─────────────────────────────────────────────────────────
154
335
  const { server_version_num } = await one(isShape({ server_version_num: isString }), "SHOW server_version_num");
155
336
  const major = Math.floor(Number(server_version_num) / 10000);
@@ -327,48 +508,9 @@ export async function runPreflight(client, opts) {
327
508
  }),
328
509
  }),
329
510
  });
330
- // ── Realtime ───────────────────────────────────────────────────────────────
331
- const { wal_level } = await one(isShape({ wal_level: isString }), "SHOW wal_level");
332
- const walLogical = wal_level === "logical";
333
- results.push({
334
- id: "wal-level",
335
- title: "wal_level = logical (realtime)",
336
- severity: walLogical ? "pass" : "degrade",
337
- detail: `wal_level is "${wal_level}"`,
338
- ...(!walLogical && {
339
- impact: "Realtime subscriptions are unavailable; everything else is unaffected.",
340
- remedy: "-- Requires a server restart, and on managed Postgres a parameter-group change\n" +
341
- "-- rather than SQL. Shown for a self-managed server:\n" +
342
- "ALTER SYSTEM SET wal_level = 'logical';",
343
- remedyNeedsOperator: true,
344
- }),
345
- });
346
- const slots = await one(isShape({ used: isString, max: isString }), `SELECT (SELECT count(*) FROM pg_replication_slots)::text AS used,
347
- current_setting('max_replication_slots') AS max`);
348
- const slotsFree = Number(slots.max) - Number(slots.used);
349
- results.push({
350
- id: "replication-slots",
351
- title: "A spare replication slot (realtime)",
352
- severity: slotsFree > 0 ? "pass" : "degrade",
353
- detail: `${slots.used} of ${slots.max} in use`,
354
- ...(slotsFree <= 0 && {
355
- impact: "Realtime cannot create its slot.",
356
- remedy: "ALTER SYSTEM SET max_replication_slots = 10;",
357
- remedyNeedsOperator: true,
358
- }),
359
- });
360
- // The definitive realtime check: create the slot realtime would create, then drop it.
361
- //
362
- // There is no catalog to consult. `wal2json` is a shared library, not an extension, so it never
363
- // appears in `pg_available_extensions`: the only way to know whether this database can decode is
364
- // to ask it to. Cloud SQL does not ship the plugin at all; plenty of managed Postgres will not
365
- // grant `REPLICATION`. Both produce a stack that looks healthy until the first subscription.
366
- //
367
- // Skipped when `wal_level` or the slot budget already rules it out, since the probe would fail for
368
- // that reason and report it a second time under a less specific heading.
369
- if (walLogical && slotsFree > 0) {
370
- results.push(await probeLogicalDecoding(q));
371
- }
511
+ // ── Realtime and after-hooks ───────────────────────────────────────────────
512
+ const decoding = await decodingChecks(q);
513
+ results.push(...decoding, afterHooksSourceCheck(decoding), await slotRetention(q));
372
514
  // ── Existing tables in the target schema ───────────────────────────────────
373
515
  if (schemaExists) {
374
516
  const names = await foreignTables(q, opts.schema);