@supatype/cli 0.9.1 → 0.9.2

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 (359) hide show
  1. package/CHANGELOG.md +303 -91
  2. package/bin/node-version.js +28 -0
  3. package/bin/supatype.js +8 -4
  4. package/dist/app/port-holder.d.ts +33 -0
  5. package/dist/app/port-holder.d.ts.map +1 -0
  6. package/dist/app/port-holder.js +66 -0
  7. package/dist/app/port-holder.js.map +1 -0
  8. package/dist/app/proxy-dev-app.d.ts +21 -3
  9. package/dist/app/proxy-dev-app.d.ts.map +1 -1
  10. package/dist/app/proxy-dev-app.js +84 -46
  11. package/dist/app/proxy-dev-app.js.map +1 -1
  12. package/dist/app/vite-dev-args.d.ts +20 -0
  13. package/dist/app/vite-dev-args.d.ts.map +1 -0
  14. package/dist/app/vite-dev-args.js +65 -0
  15. package/dist/app/vite-dev-args.js.map +1 -0
  16. package/dist/app-config.d.ts +2 -0
  17. package/dist/app-config.d.ts.map +1 -1
  18. package/dist/app-config.js +27 -8
  19. package/dist/app-config.js.map +1 -1
  20. package/dist/augmentation-generator.d.ts +2 -0
  21. package/dist/augmentation-generator.d.ts.map +1 -1
  22. package/dist/augmentation-generator.js +7 -3
  23. package/dist/augmentation-generator.js.map +1 -1
  24. package/dist/binary-download-lock.d.ts.map +1 -1
  25. package/dist/binary-download-lock.js +2 -10
  26. package/dist/binary-download-lock.js.map +1 -1
  27. package/dist/cache-provider.d.ts +17 -2
  28. package/dist/cache-provider.d.ts.map +1 -1
  29. package/dist/cache-provider.js +28 -3
  30. package/dist/cache-provider.js.map +1 -1
  31. package/dist/cli-version-embedded.js +1 -1
  32. package/dist/cli.d.ts +7 -0
  33. package/dist/cli.d.ts.map +1 -1
  34. package/dist/cli.js +10 -1
  35. package/dist/cli.js.map +1 -1
  36. package/dist/commands/admin.js +5 -11
  37. package/dist/commands/admin.js.map +1 -1
  38. package/dist/commands/app.d.ts.map +1 -1
  39. package/dist/commands/app.js +22 -2
  40. package/dist/commands/app.js.map +1 -1
  41. package/dist/commands/dev.d.ts +21 -4
  42. package/dist/commands/dev.d.ts.map +1 -1
  43. package/dist/commands/dev.js +222 -68
  44. package/dist/commands/dev.js.map +1 -1
  45. package/dist/commands/doctor.js +1 -1
  46. package/dist/commands/doctor.js.map +1 -1
  47. package/dist/commands/generate.d.ts.map +1 -1
  48. package/dist/commands/generate.js +3 -0
  49. package/dist/commands/generate.js.map +1 -1
  50. package/dist/commands/init.d.ts +6 -8
  51. package/dist/commands/init.d.ts.map +1 -1
  52. package/dist/commands/init.js +193 -114
  53. package/dist/commands/init.js.map +1 -1
  54. package/dist/commands/link-helpers.js +1 -1
  55. package/dist/commands/link-helpers.js.map +1 -1
  56. package/dist/commands/push.d.ts.map +1 -1
  57. package/dist/commands/push.js +3 -1
  58. package/dist/commands/push.js.map +1 -1
  59. package/dist/commands/self-host.d.ts +3 -3
  60. package/dist/commands/self-host.d.ts.map +1 -1
  61. package/dist/commands/self-host.js +68 -269
  62. package/dist/commands/self-host.js.map +1 -1
  63. package/dist/commands/update.d.ts.map +1 -1
  64. package/dist/commands/update.js +156 -63
  65. package/dist/commands/update.js.map +1 -1
  66. package/dist/compose-db-roles.d.ts.map +1 -1
  67. package/dist/compose-db-roles.js +3 -0
  68. package/dist/compose-db-roles.js.map +1 -1
  69. package/dist/compose-rename.d.ts.map +1 -1
  70. package/dist/compose-rename.js +5 -0
  71. package/dist/compose-rename.js.map +1 -1
  72. package/dist/compose-render-mode.d.ts +8 -3
  73. package/dist/compose-render-mode.d.ts.map +1 -1
  74. package/dist/compose-render-mode.js +13 -5
  75. package/dist/compose-render-mode.js.map +1 -1
  76. package/dist/compose-services.d.ts.map +1 -1
  77. package/dist/compose-services.js +3 -2
  78. package/dist/compose-services.js.map +1 -1
  79. package/dist/config-mailer-env.d.ts +6 -2
  80. package/dist/config-mailer-env.d.ts.map +1 -1
  81. package/dist/config-mailer-env.js +9 -11
  82. package/dist/config-mailer-env.js.map +1 -1
  83. package/dist/config-version-pin.d.ts +42 -0
  84. package/dist/config-version-pin.d.ts.map +1 -0
  85. package/dist/config-version-pin.js +64 -0
  86. package/dist/config-version-pin.js.map +1 -0
  87. package/dist/config.d.ts +4 -0
  88. package/dist/config.d.ts.map +1 -1
  89. package/dist/config.js +6 -2
  90. package/dist/config.js.map +1 -1
  91. package/dist/dev-compose.d.ts +9 -4
  92. package/dist/dev-compose.d.ts.map +1 -1
  93. package/dist/dev-compose.js +87 -53
  94. package/dist/dev-compose.js.map +1 -1
  95. package/dist/dev-initial-push.d.ts.map +1 -1
  96. package/dist/dev-initial-push.js +6 -0
  97. package/dist/dev-initial-push.js.map +1 -1
  98. package/dist/dev-ports.d.ts +7 -2
  99. package/dist/dev-ports.d.ts.map +1 -1
  100. package/dist/dev-ports.js +44 -22
  101. package/dist/dev-ports.js.map +1 -1
  102. package/dist/dev-ready-panel.d.ts +26 -3
  103. package/dist/dev-ready-panel.d.ts.map +1 -1
  104. package/dist/dev-ready-panel.js +37 -5
  105. package/dist/dev-ready-panel.js.map +1 -1
  106. package/dist/dev-self-start.d.ts +16 -0
  107. package/dist/dev-self-start.d.ts.map +1 -0
  108. package/dist/dev-self-start.js +31 -0
  109. package/dist/dev-self-start.js.map +1 -0
  110. package/dist/dev-session-lock.d.ts +66 -2
  111. package/dist/dev-session-lock.d.ts.map +1 -1
  112. package/dist/dev-session-lock.js +104 -5
  113. package/dist/dev-session-lock.js.map +1 -1
  114. package/dist/dev-session.d.ts +6 -1
  115. package/dist/dev-session.d.ts.map +1 -1
  116. package/dist/dev-session.js +9 -3
  117. package/dist/dev-session.js.map +1 -1
  118. package/dist/dev-shutdown.d.ts +11 -2
  119. package/dist/dev-shutdown.d.ts.map +1 -1
  120. package/dist/dev-shutdown.js +23 -9
  121. package/dist/dev-shutdown.js.map +1 -1
  122. package/dist/docker-runtime.d.ts +31 -7
  123. package/dist/docker-runtime.d.ts.map +1 -1
  124. package/dist/docker-runtime.js +104 -36
  125. package/dist/docker-runtime.js.map +1 -1
  126. package/dist/engine-columns.d.ts +26 -0
  127. package/dist/engine-columns.d.ts.map +1 -0
  128. package/dist/engine-columns.js +67 -0
  129. package/dist/engine-columns.js.map +1 -0
  130. package/dist/env-file.d.ts +18 -3
  131. package/dist/env-file.d.ts.map +1 -1
  132. package/dist/env-file.js +23 -7
  133. package/dist/env-file.js.map +1 -1
  134. package/dist/frontend-env.d.ts +3 -2
  135. package/dist/frontend-env.d.ts.map +1 -1
  136. package/dist/frontend-env.js +1 -1
  137. package/dist/frontend-env.js.map +1 -1
  138. package/dist/functions-deno-types.d.ts.map +1 -1
  139. package/dist/functions-deno-types.js +5 -5
  140. package/dist/functions-deno-types.js.map +1 -1
  141. package/dist/functions-worker-files.d.ts.map +1 -1
  142. package/dist/functions-worker-files.js +2 -13
  143. package/dist/functions-worker-files.js.map +1 -1
  144. package/dist/generated/release-images.d.ts +6 -6
  145. package/dist/generated/release-images.js +3 -3
  146. package/dist/gitignore.d.ts +29 -2
  147. package/dist/gitignore.d.ts.map +1 -1
  148. package/dist/gitignore.js +86 -21
  149. package/dist/gitignore.js.map +1 -1
  150. package/dist/hooks-generator.d.ts.map +1 -1
  151. package/dist/hooks-generator.js +4 -2
  152. package/dist/hooks-generator.js.map +1 -1
  153. package/dist/host-database.d.ts +6 -2
  154. package/dist/host-database.d.ts.map +1 -1
  155. package/dist/host-database.js +10 -2
  156. package/dist/host-database.js.map +1 -1
  157. package/dist/init-dependency-versions.d.ts +2 -3
  158. package/dist/init-dependency-versions.d.ts.map +1 -1
  159. package/dist/init-dependency-versions.js +12 -9
  160. package/dist/init-dependency-versions.js.map +1 -1
  161. package/dist/init-example.d.ts.map +1 -1
  162. package/dist/init-example.js +13 -1
  163. package/dist/init-example.js.map +1 -1
  164. package/dist/init-expo-runtime-env.d.ts +25 -0
  165. package/dist/init-expo-runtime-env.d.ts.map +1 -0
  166. package/dist/init-expo-runtime-env.js +112 -0
  167. package/dist/init-expo-runtime-env.js.map +1 -0
  168. package/dist/init-next-runtime-env.d.ts +14 -1
  169. package/dist/init-next-runtime-env.d.ts.map +1 -1
  170. package/dist/init-next-runtime-env.js +116 -35
  171. package/dist/init-next-runtime-env.js.map +1 -1
  172. package/dist/init-package-json.d.ts +11 -3
  173. package/dist/init-package-json.d.ts.map +1 -1
  174. package/dist/init-package-json.js +20 -13
  175. package/dist/init-package-json.js.map +1 -1
  176. package/dist/init-port-registry.d.ts +19 -0
  177. package/dist/init-port-registry.d.ts.map +1 -0
  178. package/dist/init-port-registry.js +57 -0
  179. package/dist/init-port-registry.js.map +1 -0
  180. package/dist/init-project-detect.d.ts +20 -0
  181. package/dist/init-project-detect.d.ts.map +1 -1
  182. package/dist/init-project-detect.js +41 -8
  183. package/dist/init-project-detect.js.map +1 -1
  184. package/dist/init-vite-node.d.ts +21 -0
  185. package/dist/init-vite-node.d.ts.map +1 -0
  186. package/dist/init-vite-node.js +75 -0
  187. package/dist/init-vite-node.js.map +1 -0
  188. package/dist/jsx-first-child.d.ts +18 -0
  189. package/dist/jsx-first-child.d.ts.map +1 -0
  190. package/dist/jsx-first-child.js +53 -0
  191. package/dist/jsx-first-child.js.map +1 -0
  192. package/dist/keyspace-password-file.d.ts +46 -0
  193. package/dist/keyspace-password-file.d.ts.map +1 -0
  194. package/dist/keyspace-password-file.js +128 -0
  195. package/dist/keyspace-password-file.js.map +1 -0
  196. package/dist/kong-config.d.ts +1 -0
  197. package/dist/kong-config.d.ts.map +1 -1
  198. package/dist/kong-config.js +64 -20
  199. package/dist/kong-config.js.map +1 -1
  200. package/dist/local-gateway.d.ts +11 -3
  201. package/dist/local-gateway.d.ts.map +1 -1
  202. package/dist/local-gateway.js +16 -7
  203. package/dist/local-gateway.js.map +1 -1
  204. package/dist/local-secrets.d.ts +10 -0
  205. package/dist/local-secrets.d.ts.map +1 -1
  206. package/dist/local-secrets.js +13 -0
  207. package/dist/local-secrets.js.map +1 -1
  208. package/dist/local-stack-guard.d.ts.map +1 -1
  209. package/dist/local-stack-guard.js +3 -2
  210. package/dist/local-stack-guard.js.map +1 -1
  211. package/dist/local-stack.d.ts.map +1 -1
  212. package/dist/local-stack.js +7 -6
  213. package/dist/local-stack.js.map +1 -1
  214. package/dist/local-storage.d.ts +3 -5
  215. package/dist/local-storage.d.ts.map +1 -1
  216. package/dist/local-storage.js +10 -10
  217. package/dist/local-storage.js.map +1 -1
  218. package/dist/mailer-autoconfirm.d.ts +29 -24
  219. package/dist/mailer-autoconfirm.d.ts.map +1 -1
  220. package/dist/mailer-autoconfirm.js +47 -43
  221. package/dist/mailer-autoconfirm.js.map +1 -1
  222. package/dist/model-hooks.d.ts +4 -4
  223. package/dist/model-hooks.d.ts.map +1 -1
  224. package/dist/model-hooks.js +13 -7
  225. package/dist/model-hooks.js.map +1 -1
  226. package/dist/native-dev-env.d.ts +25 -2
  227. package/dist/native-dev-env.d.ts.map +1 -1
  228. package/dist/native-dev-env.js +39 -4
  229. package/dist/native-dev-env.js.map +1 -1
  230. package/dist/native-keyspace.d.ts +21 -6
  231. package/dist/native-keyspace.d.ts.map +1 -1
  232. package/dist/native-keyspace.js +48 -14
  233. package/dist/native-keyspace.js.map +1 -1
  234. package/dist/native-leftover-postgres.d.ts +23 -0
  235. package/dist/native-leftover-postgres.d.ts.map +1 -0
  236. package/dist/native-leftover-postgres.js +55 -0
  237. package/dist/native-leftover-postgres.js.map +1 -0
  238. package/dist/native-leftover-services.d.ts +17 -0
  239. package/dist/native-leftover-services.d.ts.map +1 -0
  240. package/dist/native-leftover-services.js +93 -0
  241. package/dist/native-leftover-services.js.map +1 -0
  242. package/dist/native-pg-auth.d.ts.map +1 -1
  243. package/dist/native-pg-auth.js +2 -1
  244. package/dist/native-pg-auth.js.map +1 -1
  245. package/dist/native-port-lock.d.ts +37 -0
  246. package/dist/native-port-lock.d.ts.map +1 -0
  247. package/dist/native-port-lock.js +78 -0
  248. package/dist/native-port-lock.js.map +1 -0
  249. package/dist/native-realtime.d.ts +6 -3
  250. package/dist/native-realtime.d.ts.map +1 -1
  251. package/dist/native-realtime.js +65 -24
  252. package/dist/native-realtime.js.map +1 -1
  253. package/dist/native-roles-sql.d.ts.map +1 -1
  254. package/dist/native-roles-sql.js +2 -1
  255. package/dist/native-roles-sql.js.map +1 -1
  256. package/dist/native-storage-import.d.ts.map +1 -1
  257. package/dist/native-storage-import.js +6 -5
  258. package/dist/native-storage-import.js.map +1 -1
  259. package/dist/native-storage.d.ts +42 -7
  260. package/dist/native-storage.d.ts.map +1 -1
  261. package/dist/native-storage.js +196 -50
  262. package/dist/native-storage.js.map +1 -1
  263. package/dist/parent-watch.d.ts.map +1 -1
  264. package/dist/parent-watch.js +4 -8
  265. package/dist/parent-watch.js.map +1 -1
  266. package/dist/postgres-ctl.d.ts +31 -5
  267. package/dist/postgres-ctl.d.ts.map +1 -1
  268. package/dist/postgres-ctl.js +49 -11
  269. package/dist/postgres-ctl.js.map +1 -1
  270. package/dist/postgres-image.d.ts +16 -0
  271. package/dist/postgres-image.d.ts.map +1 -1
  272. package/dist/postgres-image.js +34 -11
  273. package/dist/postgres-image.js.map +1 -1
  274. package/dist/process-info.d.ts +14 -0
  275. package/dist/process-info.d.ts.map +1 -0
  276. package/dist/process-info.js +41 -0
  277. package/dist/process-info.js.map +1 -0
  278. package/dist/process-manager.d.ts +73 -4
  279. package/dist/process-manager.d.ts.map +1 -1
  280. package/dist/process-manager.js +121 -45
  281. package/dist/process-manager.js.map +1 -1
  282. package/dist/process-tree.d.ts +48 -0
  283. package/dist/process-tree.d.ts.map +1 -0
  284. package/dist/process-tree.js +141 -0
  285. package/dist/process-tree.js.map +1 -0
  286. package/dist/project-config.d.ts +33 -4
  287. package/dist/project-config.d.ts.map +1 -1
  288. package/dist/project-config.js +5 -1
  289. package/dist/project-config.js.map +1 -1
  290. package/dist/required-host-components.d.ts.map +1 -1
  291. package/dist/required-host-components.js +3 -5
  292. package/dist/required-host-components.js.map +1 -1
  293. package/dist/route-manifest.d.ts +24 -0
  294. package/dist/route-manifest.d.ts.map +1 -1
  295. package/dist/route-manifest.js +60 -2
  296. package/dist/route-manifest.js.map +1 -1
  297. package/dist/run-captured.d.ts +3 -1
  298. package/dist/run-captured.d.ts.map +1 -1
  299. package/dist/run-captured.js.map +1 -1
  300. package/dist/run-until-stopped.d.ts +3 -0
  301. package/dist/run-until-stopped.d.ts.map +1 -1
  302. package/dist/run-until-stopped.js +25 -11
  303. package/dist/run-until-stopped.js.map +1 -1
  304. package/dist/runtime-routes.d.ts +5 -0
  305. package/dist/runtime-routes.d.ts.map +1 -1
  306. package/dist/runtime-routes.js +5 -1
  307. package/dist/runtime-routes.js.map +1 -1
  308. package/dist/secret-sql.d.ts +13 -0
  309. package/dist/secret-sql.d.ts.map +1 -0
  310. package/dist/secret-sql.js +13 -0
  311. package/dist/secret-sql.js.map +1 -0
  312. package/dist/seed-ir.d.ts +8 -1
  313. package/dist/seed-ir.d.ts.map +1 -1
  314. package/dist/seed-ir.js +92 -6
  315. package/dist/seed-ir.js.map +1 -1
  316. package/dist/seed.d.ts +15 -2
  317. package/dist/seed.d.ts.map +1 -1
  318. package/dist/self-host-compose.d.ts +15 -1
  319. package/dist/self-host-compose.d.ts.map +1 -1
  320. package/dist/self-host-compose.js +216 -51
  321. package/dist/self-host-compose.js.map +1 -1
  322. package/dist/stack-exit-watch.d.ts +15 -0
  323. package/dist/stack-exit-watch.d.ts.map +1 -1
  324. package/dist/stack-exit-watch.js +41 -13
  325. package/dist/stack-exit-watch.js.map +1 -1
  326. package/dist/stack-folder.d.ts +28 -0
  327. package/dist/stack-folder.d.ts.map +1 -0
  328. package/dist/stack-folder.js +123 -0
  329. package/dist/stack-folder.js.map +1 -0
  330. package/dist/stack-setting-warnings.d.ts +2 -1
  331. package/dist/stack-setting-warnings.d.ts.map +1 -1
  332. package/dist/stack-setting-warnings.js +6 -1
  333. package/dist/stack-setting-warnings.js.map +1 -1
  334. package/dist/storage-provision.d.ts +12 -2
  335. package/dist/storage-provision.d.ts.map +1 -1
  336. package/dist/storage-provision.js +36 -11
  337. package/dist/storage-provision.js.map +1 -1
  338. package/dist/type-extractor.d.ts.map +1 -1
  339. package/dist/type-extractor.js +27 -3
  340. package/dist/type-extractor.js.map +1 -1
  341. package/dist/ui/dev/DevReadyPanelView.js +1 -1
  342. package/dist/ui/dev/DevReadyPanelView.js.map +1 -1
  343. package/dist/valkey-sidecar.d.ts +24 -11
  344. package/dist/valkey-sidecar.d.ts.map +1 -1
  345. package/dist/valkey-sidecar.js +45 -25
  346. package/dist/valkey-sidecar.js.map +1 -1
  347. package/dist/windows-processes.d.ts +7 -0
  348. package/dist/windows-processes.d.ts.map +1 -0
  349. package/dist/windows-processes.js +31 -0
  350. package/dist/windows-processes.js.map +1 -0
  351. package/dist/write-if-changed.d.ts +12 -0
  352. package/dist/write-if-changed.d.ts.map +1 -0
  353. package/dist/write-if-changed.js +32 -0
  354. package/dist/write-if-changed.js.map +1 -0
  355. package/package.json +6 -4
  356. package/dist/systemd.d.ts +0 -26
  357. package/dist/systemd.d.ts.map +0 -1
  358. package/dist/systemd.js +0 -117
  359. package/dist/systemd.js.map +0 -1
@@ -19,21 +19,25 @@ import { serialRuns } from "../serial-runs.js";
19
19
  import { existsSync, mkdirSync, writeFileSync } from "node:fs";
20
20
  import { join, resolve } from "node:path";
21
21
  import { hasEnvValue, readDotEnvFiles } from "../env-file.js";
22
+ import { retireCliMailerAutoconfirm } from "../mailer-autoconfirm.js";
22
23
  import { requireUrlSafeComposePasswords } from "../url-safe-passwords.js";
23
24
  import { loadConfig, PROJECT_CONFIG_FILES } from "../config.js";
24
- import { bucketSpecsFromAst, isParsedBuckets, nativeBucketRow, provisionBuckets, withPublicFromMode, } from "../storage-provision.js";
25
+ import { bucketSpecsFromAst, isParsedBuckets, nativeBucketRow, provisionBuckets, unprovisionedBuckets, warnBucketsLeft, withPublicFromMode, } from "../storage-provision.js";
25
26
  import { readJsonFile } from "../json-file.js";
26
27
  import { isArrayOf, isJsonObject } from "@supatype/shared";
27
28
  import { pgSchema, localDSN, nativeDataDir, nativeDbPort, nativeRealtimePort, nativeDenoPort, nativeStoragePort, STORAGE_PORT_ENV, DENO_PORT_ENV, nativeStateRoot, nativeServerPort, REALTIME_PORT_ENV, publicEnvServerEnv, resolveRuntimeProvider, schemaPathFromProject, serviceRoleRoutes, } from "../project-config.js";
28
29
  import { DEV_DB_PORT_ENV } from "../db-port.js";
30
+ import { devSessionLockFor, writeDevSessionLock } from "../dev-session-lock.js";
31
+ import { composeProjectName, selfHostComposePaths } from "../self-host-compose.js";
29
32
  import { devServiceRoleRoutesPath, functionsWorkerEnv, writeServiceRoleRoutesFile } from "../functions-worker-files.js";
30
33
  import { devServiceRoleKeyPath } from "../service-role-key-file.js";
31
34
  import { requireUsableJwtSecret } from "../jwt-secret-length.js";
32
- import { ensureNativeAuthenticatorPassword, devJwtSecret, ensureNativeSuperuserPassword, givenJwtSecret, ignoredJwtSecretWarning, secretFingerprint, } from "../local-secrets.js";
35
+ import { ensureNativeAuthenticatorPassword, devJwtSecret, ensureNativeSuperuserPassword, givenJwtSecret, ignoredJwtSecretWarning, KEYSPACE_USERNAME, secretFingerprint, } from "../local-secrets.js";
36
+ import { keyspacePasswordOrigin, projectKeyspacePassword } from "../keyspace-password-file.js";
33
37
  import { normalisePlatformPath, cachePath, currentPlatform, hasMeaningfulOverrides, describeActiveOverrides, postgresArchiveTag, } from "../binary-cache.js";
34
38
  import { ensureBinary } from "../ensure-binary.js";
35
39
  import { assertSupported, binaryCapabilities, EngineProbeFailed, OVERWRITE_DRIFT_NEED, OwnershipUnsupportedError, requireEngineFeatures, } from "../engine-ownership-gate.js";
36
- import { startProxyDevApp } from "../app/proxy-dev-app.js";
40
+ import { appPanelLinks, startProxyDevApp } from "../app/proxy-dev-app.js";
37
41
  import { ProcessManager } from "../process-manager.js";
38
42
  import { markPostgrestUnpacked, POSTGREST_VERSION, postgrestArchiveName, postgrestArchiveUrl, postgrestRuntimeRepairDue, } from "../postgrest-release.js";
39
43
  import { STUDIO_DEV_PORT, startStudioViteDevServer } from "../studio-dev-server.js";
@@ -47,10 +51,11 @@ import { haltIfStopping, pushStartUndo, pushStartUndoLast, registerDevShutdown,
47
51
  import { startNativeRealtime } from "../native-realtime.js";
48
52
  import { nativeWorkerDenoEnv, prepareNativeWorker } from "../native-worker.js";
49
53
  import { configSnapshot } from "../config-snapshot.js";
54
+ import { refuseInsideDevApp } from "../dev-self-start.js";
50
55
  import { patchRouteManifest, recordNativeRoutes } from "../route-manifest.js";
51
56
  import { reconcileNativeDevDatabaseUrl } from "../db-port-offer.js";
52
57
  import { extractArchive } from "../archive-extract.js";
53
- import { serverStorageEnv, startNativeStorage } from "../native-storage.js";
58
+ import { nativeS3StorageEnv, serverStorageEnv, startNativeS3Storage, startNativeStorage, startsStorageService, } from "../native-storage.js";
54
59
  import { keepsObjectsLocally, serverStoreRoot } from "../local-storage.js";
55
60
  import { writeAppliedAstArtifacts } from "../applied-ast-artifacts.js";
56
61
  import { writeAppViteEnv } from "../app-vite-env.js";
@@ -58,10 +63,13 @@ import { nativeAuthProviderEnv, warnMissingAuthProviderSecrets } from "../auth-p
58
63
  import { warnSmtpWithoutHost } from "../config-mailer-env.js";
59
64
  import { nativeSamlEnv } from "../saml-config.js";
60
65
  import { AUTHENTICATOR_PASSWORD_ENV } from "../native-roles-sql.js";
61
- import { nativeAuthMailerEnv, nativeDevApiKeys, nativeDevRolesSql, nativePostgrestSchemaEnv, nativeServerCoreEnv, nativeServerDotEnvLayer, } from "../native-dev-env.js";
66
+ import { nativeAuthMailerEnv, nativeDevApiKeys, nativeDevRolesSql, nativePostgrestSchemaEnv, nativeKeyspaceServerEnv, nativeServerCoreEnv, nativeServerDotEnvLayer, } from "../native-dev-env.js";
62
67
  import { ensureValkeySidecar, externalValkey } from "../valkey-sidecar.js";
63
- import { nativeKeyspaceAddr as nativeKeyspaceAddrFor, nativeKeyspacePort } from "../native-keyspace.js";
64
- import { ensureCluster, createdbArgs, databaseEncoding, nonUtf8DatabaseWarning, pgBuild, start as pgStart, stop as pgStop, waitReady as pgWaitReady, isPortInUse, portCheckCommand, } from "../postgres-ctl.js";
68
+ import { nativeKeyspaceAddr, nativeKeyspacePort, writeKeyspacePasswordFile, } from "../native-keyspace.js";
69
+ import { ensureCluster, createdbArgs, databaseEncoding, nonUtf8DatabaseWarning, pgBuild, start as pgStart, stop as pgStop, waitReady as pgWaitReady, connectSucceeds, isPortInUse, portCheckCommand, } from "../postgres-ctl.js";
70
+ import { claimPortLock, isPortLock } from "../native-port-lock.js";
71
+ import { leftoverOwnPostgres, recordNativeDevPid } from "../native-leftover-postgres.js";
72
+ import { stopLeftoverServices } from "../native-leftover-services.js";
65
73
  import { isPasswordRejected, pgClientEnv, requirePasswordAuth, requireSuperuserPassword, superuserPasswordMissingMessage, } from "../native-pg-auth.js";
66
74
  const NATIVE_SERVICES = ["postgres", "server", "postgrest", "realtime", "deno", "storage"];
67
75
  export const NATIVE_PORT_HINTS = {
@@ -74,7 +82,7 @@ export const NATIVE_PORT_HINTS = {
74
82
  move: "Move this project's API server port with server.port in supatype.config.ts, or `supatype dev --port`.",
75
83
  },
76
84
  postgrest: {
77
- holder: "Another service may be running.",
85
+ holder: "Another service, or another project's native dev, may be running.",
78
86
  move: "Move this project's PostgREST port with server.postgrestPort in supatype.config.ts.",
79
87
  },
80
88
  realtime: {
@@ -90,17 +98,70 @@ export const NATIVE_PORT_HINTS = {
90
98
  move: `Move this project's storage port with ${STORAGE_PORT_ENV} in .env.`,
91
99
  },
92
100
  };
93
- /** Stop before anything starts when a port native dev binds is taken. Exported for tests. */
94
- export async function assertNativeDevPortsFree(ports) {
101
+ /**
102
+ * Stop before anything starts when a port native dev binds is taken, then claim PostgREST's for the
103
+ * session, refused to every other native dev's start (N-FF12, native-port-lock.ts). Exported for tests.
104
+ *
105
+ * Postgres's port held by this project's own Postgres, which a dev that did not stop cleanly left
106
+ * running, is not a refusal (FF12 remainder): the start restarts it (native-leftover-postgres.ts).
107
+ * Its services, left by a dev that was killed, are stopped first (native-leftover-services.ts).
108
+ */
109
+ export async function claimNativeDevPorts(ports, state) {
110
+ await stopLeftoverServices(state);
111
+ // Beside the checks below rather than after them: a refused connect on Windows takes its full wait.
112
+ const ipv6Checked = warnIfServerIpv6Held(ports.server);
113
+ const leftoverPostgres = leftoverOwnPostgres(state, ports.postgres);
95
114
  for (const service of NATIVE_SERVICES) {
96
115
  const port = ports[service];
97
- if (port === undefined || !(await isPortInUse(port)))
116
+ if (port === undefined || (service === "postgres" && leftoverPostgres !== null))
98
117
  continue;
99
- const { holder, move } = NATIVE_PORT_HINTS[service];
100
- fatalError(`Port ${port} is already in use.`, [holder, `Check: ${portCheckCommand(port)}`, move], {
101
- brand: { intro: "Local development" },
102
- });
118
+ if (await isPortInUse(port))
119
+ refuseNativePort(service, port);
103
120
  }
121
+ await ipv6Checked;
122
+ const postgrest = claimPortLock(ports.postgrest);
123
+ if (!isPortLock(postgrest))
124
+ refuseClaimedPort(ports.postgrest, postgrest);
125
+ return { postgrest, leftoverPostgres };
126
+ }
127
+ /**
128
+ * Says so when something else listens on [::1] at the API server's port. The server then serves on
129
+ * 127.0.0.1 alone, and a client resolving `localhost` to ::1 first (a browser on Windows) reaches
130
+ * the other listener. Dev started, and no pane said so (0.9.2 round 2, R2-S22).
131
+ */
132
+ async function warnIfServerIpv6Held(port) {
133
+ if (!(await connectSucceeds(port, 400, "::1")))
134
+ return;
135
+ console.warn(`[supatype] ⚠ Something else listens on [::1]:${port}, so the API server answers on IPv4 only: ` +
136
+ `use http://127.0.0.1:${port}, as http://localhost:${port} can reach the other listener.`);
137
+ }
138
+ /** Refuse to start for a port another running native dev has claimed, naming it and its claim. */
139
+ function refuseClaimedPort(port, claim) {
140
+ fatalError(`Port ${port} is claimed by another native dev (pid ${claim.holder}).`, [
141
+ `Its claim is ${claim.path}. If no native dev is running, delete that file.`,
142
+ NATIVE_PORT_HINTS.postgrest.move,
143
+ ], { brand: { intro: "Local development" } });
144
+ }
145
+ /** What native dev says of a port it binds that something else holds: what usually does, and how to move it. */
146
+ function portRefusalText(service, port) {
147
+ return { headline: `Port ${port} is already in use.`, ...NATIVE_PORT_HINTS[service] };
148
+ }
149
+ /** Refuse to start for a port native dev binds that something else holds. */
150
+ function refuseNativePort(service, port) {
151
+ const { headline, holder, move } = portRefusalText(service, port);
152
+ fatalError(headline, [holder, `Check: ${portCheckCommand(port)}`, move], {
153
+ brand: { intro: "Local development" },
154
+ });
155
+ }
156
+ /**
157
+ * Refuses PostgREST's port when something other than a native dev took it since the check, as the
158
+ * check would have (N-FF12). A throw rather than a fatal exit, so the start undoes what it began.
159
+ */
160
+ async function requirePostgrestPortFree(port) {
161
+ if (!(await isPortInUse(port)))
162
+ return;
163
+ const { headline, holder, move } = portRefusalText("postgrest", port);
164
+ throw new Error(`${headline} ${holder} ${move}`);
104
165
  }
105
166
  /**
106
167
  * `dev --overwrite-drift` only where the engine that will push can honour it: the compose
@@ -135,6 +196,7 @@ export function registerDev(program) {
135
196
  .option("--overwrite-drift", "Every push of this session puts back policies, grants, labels and RLS changed outside Supatype")
136
197
  // Ctrl+C during the start reaches its children too: it ends with one line, not their failure.
137
198
  .action(stopQuietlyDuringStart(async (opts) => {
199
+ refuseInsideDevApp();
138
200
  const cwd = process.cwd();
139
201
  // ── 1. Load project config (before TUI, fatal errors must hit real stderr) ──
140
202
  // Its bytes first: the functions.serviceRole watch, started much later, applies any edit since.
@@ -162,19 +224,25 @@ export function registerDev(program) {
162
224
  const realtimePort = String(nativeRealtimePort(config, cwd));
163
225
  const denoPort = nativeDenoPort(cwd);
164
226
  const storagePort = nativeStoragePort(cwd);
227
+ // A native project on S3: the storage service on the project's own bucket, unless .env names a
228
+ // service of its own. Read before anything starts, so a blank S3_BUCKET is the first thing said.
229
+ const s3StorageEnv = provider !== "docker" && !keepsObjectsLocally(config) ? s3StorageEnvOrExit(cwd) : null;
230
+ const nativeState = { dataDir: nativeDataDir(config), pidDir: join(nativeStateRoot(config), "pid") };
231
+ let portClaim = null;
165
232
  if (provider !== "docker") {
166
233
  // The functions worker runs on every native dev (native-worker.ts), so Deno's port is checked too.
167
- await assertNativeDevPortsFree({
234
+ portClaim = await claimNativeDevPorts({
168
235
  postgres: pgPort,
169
236
  server: Number(serverPort),
170
237
  postgrest: Number(postgrestPort),
171
238
  realtime: Number(realtimePort),
172
239
  deno: denoPort,
173
- ...(keepsObjectsLocally(config) && { storage: storagePort }),
174
- });
240
+ ...(startsStorageService(config, s3StorageEnv) && { storage: storagePort }),
241
+ }, nativeState);
242
+ pushStartUndoLast(portClaim.postgrest.release);
175
243
  // Before anything is generated: a missing password would otherwise be replaced in .env
176
244
  // with a new one the existing cluster has never heard of.
177
- requireSuperuserPassword(cwd, nativeDataDir(config));
245
+ requireSuperuserPassword(cwd, nativeState.dataDir);
178
246
  }
179
247
  // Before the session takes the terminal, so a refusal reaches it.
180
248
  const overwriteDrift = opts.overwriteDrift === true;
@@ -226,12 +294,14 @@ export function registerDev(program) {
226
294
  ]);
227
295
  // ── 3. Per-project state directories ─────────────────────────────────
228
296
  const stateRoot = nativeStateRoot(config);
229
- const pidDir = join(stateRoot, "pid");
297
+ const { pidDir } = nativeState;
230
298
  const logsDir = join(stateRoot, "logs");
231
299
  const tmpDir = join(stateRoot, "tmp");
232
300
  for (const d of [pidDir, logsDir, tmpDir]) {
233
301
  mkdirSync(d, { recursive: true });
234
302
  }
303
+ // Before Postgres starts, so a dev started meanwhile never takes this one's Postgres for a leftover.
304
+ pushStartUndoLast(recordNativeDevPid(pidDir));
235
305
  // ── 5–7. Start Postgres ───────────────────────────────────────────────
236
306
  let dbURL;
237
307
  /** What PostgREST connects as, deliberately not `dbURL`, which is a superuser. */
@@ -245,35 +315,41 @@ export function registerDev(program) {
245
315
  // pgBinDir is set on the native path and used to add DLL search path for
246
316
  // PostgREST on Windows (PostgREST links against libpq + SSL from MinGW).
247
317
  let pgBinDir = null;
248
- // The port the native Postgres serves RESP on, or null when this archive
249
- // has no pg_keyspace and the Valkey sidecar is what the cache talks to.
250
- let keyspacePort = null;
318
+ // The keyspace this Postgres serves and its login, or null when the Valkey sidecar is what
319
+ // the cache talks to (native-keyspace.ts).
320
+ let keyspace = null;
251
321
  {
252
322
  // native: resolve pg bin dir and manage with pg_ctl
253
- pgBinDir = await resolvePgBinDir(config);
254
- const dataDir = nativeDataDir(config);
323
+ const pgInstall = await resolvePgInstall(config);
324
+ pgBinDir = pgInstall.binDir;
325
+ const { dataDir } = nativeState;
255
326
  mkdirSync(dataDir, { recursive: true });
256
- // The RESP keyspace, when this archive carries it: one process instead
257
- // of a Postgres and a Valkey container. The port is chosen rather than
258
- // fixed because 6379 is the first thing a developer's own Redis or a
259
- // leftover sidecar takes, and a keyspace that cannot bind its port
260
- // fails inside the postmaster log where nobody is looking.
261
- keyspacePort = await nativeKeyspacePort(config, pgBinDir);
327
+ // The RESP keyspace, when this archive carries it and can require a password: one process
328
+ // instead of a Postgres and a Valkey container. The port is chosen rather than fixed
329
+ // because 6379 is the first thing a developer's own Redis or a leftover sidecar takes.
330
+ const keyspacePort = await nativeKeyspacePort(config, pgBinDir, pgInstall.version);
331
+ // The project's password, from .env or the file SUPATYPE_KEYSPACE_PASSWORD_FILE names
332
+ // (R2-S16), which the keyspace reads itself from a file only this user can read, and
333
+ // requires from its first client (N-RB2).
334
+ keyspace = keyspacePort === null ? null : { port: keyspacePort, login: { username: KEYSPACE_USERNAME, password: projectKeyspacePassword(cwd) } };
262
335
  const pgOpts = {
263
336
  pgBinDir,
264
337
  dataDir,
265
338
  port: pgPort,
266
339
  logPath: join(logsDir, "postgres.log"),
267
340
  database: projectName,
268
- ...(keyspacePort !== null
269
- ? { keyspacePort, keyspaceDatabase: projectName }
270
- : {}),
341
+ ...(keyspace !== null && {
342
+ keyspacePort: keyspace.port,
343
+ keyspaceDatabase: projectName,
344
+ keyspacePasswordFile: writeKeyspacePasswordFile(stateRoot, keyspace.login.password),
345
+ }),
271
346
  };
272
347
  // initdb, and createdb on a first start, need the archive's version and ICU support; asked once.
273
348
  let build;
274
349
  const buildOnce = () => (build ??= pgBuild(pgBinDir));
275
350
  // Before initdb, which a first start runs here and which takes the longest.
276
351
  await showDevStep("Starting Postgres");
352
+ restartLeftoverPostgres(portClaim, pgOpts);
277
353
  ensureCluster(pgOpts, pgPassword, buildOnce);
278
354
  console.log("[supatype] Starting Postgres...");
279
355
  pgStart(pgOpts);
@@ -366,21 +442,35 @@ export function registerDev(program) {
366
442
  writeAppViteEnv(cwd, config, `http://localhost:${serverPort}`, anonKey);
367
443
  // After the push, failed or not: init's manifest names the compose stack's services.
368
444
  recordNativeRoutes(manifestPath, worker.denoBin !== undefined);
369
- // Valkey, or the keyspace Postgres serves, alongside realtime and storage: none needs another.
370
- const valkeyStart = nativeValkey(keyspacePort, projectName);
445
+ // The cache, the keyspace or Valkey, alongside realtime and storage: none needs another.
446
+ const cacheStart = nativeCache(keyspace, projectName, cwd);
371
447
  const realtimeProc = await startNativeRealtime({
372
448
  config, cwd, manifestPath, pidDir, url: realtimeUrl, port: realtimePort,
373
449
  databaseUrl: dbURL, jwtSecret: LOCAL_JWT_SECRET,
374
450
  });
375
- const nativeStorage = keepsObjectsLocally(config)
376
- ? await startNativeStorage({
377
- config, cwd, manifestPath, pidDir, stateRoot, port: storagePort, databaseUrl: dbURL, jwtSecret: LOCAL_JWT_SECRET,
378
- })
379
- : null;
380
451
  // Later pushes create the buckets a schema declares in the service as well as in buckets.json.
452
+ // A project on S3 has no buckets.json for the service to import, so the buckets the first push
453
+ // declared, before the service ran, are created in it now. The same for a service switched on
454
+ // only once it answered, after its start deadline (N-FF2).
455
+ const useStorage = async (storage) => {
456
+ const storageApi = { url: storage.url, serviceRoleKey };
457
+ schemaPush.storageApi = storageApi;
458
+ if (s3StorageEnv !== null)
459
+ await provisionDeclaredBuckets(engineBin, cwd, join(supatypeDir, "schema.ast.json"), { storageApi });
460
+ };
461
+ const storageOptions = {
462
+ config, cwd, manifestPath, pidDir, stateRoot, port: storagePort, databaseUrl: dbURL, jwtSecret: LOCAL_JWT_SECRET,
463
+ onLateStart: useStorage,
464
+ };
465
+ const nativeStorage = keepsObjectsLocally(config)
466
+ ? await startNativeStorage(storageOptions)
467
+ : s3StorageEnv === null ? null : await startNativeS3Storage(storageOptions, s3StorageEnv);
381
468
  if (nativeStorage !== null)
382
- schemaPush.storageApi = { url: nativeStorage.url, serviceRoleKey };
383
- const valkeySidecar = await valkeyStart;
469
+ await useStorage(nativeStorage);
470
+ const cache = await cacheStart;
471
+ // Before .env is read: a SUPATYPE_MAILER_AUTOCONFIRM an earlier CLI wrote there would otherwise
472
+ // win over the config as if the developer had set it (FF7).
473
+ retireCliMailerAutoconfirm(cwd);
384
474
  // `.env` and `.env.local`, read once for everything the server's environment takes from them.
385
475
  const dotEnv = readDotEnvFiles(cwd);
386
476
  // What an env("NAME") in auth.providers resolves against: the shell over .env, as for the config.
@@ -393,7 +483,7 @@ export function registerDev(program) {
393
483
  const serverEnv = {
394
484
  ...nativeServerCoreEnv({
395
485
  mode: config.server.mode ?? "dev",
396
- valkeyAddr: valkeySidecar.addr,
486
+ valkeyAddr: cache.sidecar.addr,
397
487
  projectRef: projectName,
398
488
  manifestPath,
399
489
  adminConfigPath,
@@ -447,12 +537,14 @@ export function registerDev(program) {
447
537
  ...nativeAuthMailerEnv(config.email, serverPort),
448
538
  SUPATYPE_LOG_LEVEL: "info",
449
539
  SUPATYPE_DISABLE_SIGNUP: "false",
450
- ...serverStorageEnv(nativeStorage, config, stateRoot),
540
+ ...serverStorageEnv(nativeStorage, config),
451
541
  // .env last, so a SUPATYPE_EXTERNAL_* value there wins over auth.providers in the config.
452
542
  ...nativeAuthProviderEnv(config, `http://localhost:${serverPort}`, providerEnvironment),
453
543
  // auth.sso.saml, with the signing key from .env (generated there the first time SAML is on).
454
544
  ...nativeSamlEnv(cwd, config),
455
- ...nativeServerDotEnvLayer({ dotEnv, config, cwd, denoPort }),
545
+ ...nativeServerDotEnvLayer({ dotEnv, config, denoPort }),
546
+ // After .env, which can hold a keyspace password for a Docker phase of the project (N-RB2).
547
+ ...nativeKeyspaceServerEnv(cache),
456
548
  };
457
549
  await haltIfStopping();
458
550
  const serverProc = new ProcessManager(serverBin, [], {
@@ -468,6 +560,7 @@ export function registerDev(program) {
468
560
  await haltIfStopping();
469
561
  const postgrestBin = await resolvePostgrestBin(config.overrides?.postgrest);
470
562
  if (postgrestBin) {
563
+ await requirePostgrestPortFree(Number(postgrestPort));
471
564
  // Windows PostgREST builds are dynamically linked and require libpq/OpenSSL
472
565
  // DLLs from a Postgres bin directory, even when the database runs in Docker.
473
566
  let postgrestRuntimeBinDir = pgBinDir;
@@ -544,11 +637,16 @@ export function registerDev(program) {
544
637
  const appProc = startProxyDevApp(cwd, config, pidDir);
545
638
  if (appProc)
546
639
  pushStartUndo(() => appProc.stop());
640
+ // No built-in store stands in for a service that did not start (native-storage.ts), so the
641
+ // panel lists no storage URL and repeats that storage is off, in case the warning scrolled by.
642
+ // A project on S3 too: its panel listed Storage while a refused S3_BUCKET kept it off (R2-S2).
643
+ const storageOff = nativeStorage === null && startsStorageService(config, s3StorageEnv);
547
644
  const links = [
548
645
  { label: "API", url: `http://localhost:${serverPort}` },
549
646
  { label: "REST", url: `http://localhost:${serverPort}/rest/v1/` },
550
647
  { label: "Auth", url: `http://localhost:${serverPort}/auth/v1/` },
551
- { label: "Storage", url: `http://localhost:${serverPort}/storage/v1/` },
648
+ ...(storageOff ? [] : [{ label: "Storage", url: `http://localhost:${serverPort}/storage/v1/` }]),
649
+ ...appPanelLinks(config, `http://localhost:${serverPort}`),
552
650
  ];
553
651
  if (realtimeProc) {
554
652
  links.push({ label: "Realtime", url: `ws://localhost:${serverPort}/realtime/v1/` });
@@ -557,16 +655,32 @@ export function registerDev(program) {
557
655
  links.push({ label: "Studio", url: `http://localhost:${studioPort}` });
558
656
  }
559
657
  publishDevReady({
658
+ cwd,
560
659
  title: "Services running",
561
660
  links,
562
661
  anonKey,
563
662
  serviceRoleKey,
564
- hints: [`Postgres ${dbURL}`, `JWT secret: #${secretFingerprint(LOCAL_JWT_SECRET)} (in .env)`],
663
+ databaseUrl: dbURL,
664
+ hints: [
665
+ `JWT secret: #${secretFingerprint(LOCAL_JWT_SECRET)} (in .env)`,
666
+ ...(storageOff ? ["Storage is off: the storage service did not start (the reason is above)"] : []),
667
+ ],
565
668
  });
566
669
  // ── Shutdown handler ──────────────────────────────────────────────────
567
670
  // Everything the start began is undone after it, the services together and then Postgres
568
- // (pushStartUndo, pushStartUndoLast), so the shutdown has nothing of its own to stop.
569
- registerDevShutdown(async () => undefined);
671
+ // (pushStartUndo, pushStartUndoLast), so the shutdown has nothing of its own to stop. Its
672
+ // `cwd` clears the session record below when dev ends.
673
+ registerDevShutdown(async () => undefined, { cwd });
674
+ // The session's database port, for host commands run from another shell: they took that
675
+ // shell's SUPATYPE_DEV_DB_PORT, and a push applied its migration to another Postgres there
676
+ // (0.9.2 round 5, FF-7 on native). Written once ready, as Docker dev writes its own.
677
+ writeDevSessionLock(cwd, devSessionLockFor(config, {
678
+ provider: "native",
679
+ composeProject: composeProjectName(projectName),
680
+ composePath: selfHostComposePaths(cwd).composePath,
681
+ dbPort: pgPort,
682
+ runEnv: { [DEV_DB_PORT_ENV]: String(pgPort) },
683
+ }));
570
684
  // ── 10. Schema watch ──────────────────────────────────────────────────
571
685
  if (opts.watch) {
572
686
  const schemaDir = resolve(cwd, schemaPath, "..");
@@ -747,7 +861,7 @@ async function applyNativeSchema(cwd, schema, target) {
747
861
  */
748
862
  async function writeNativeSchemaArtifacts(paths, ast, config) {
749
863
  const { cwd, engineBin, astPath } = paths;
750
- if (paths.storagePath)
864
+ if (paths.storagePath || paths.storageApi)
751
865
  await provisionDeclaredBuckets(engineBin, cwd, astPath, paths);
752
866
  if (paths.adminConfigPath)
753
867
  await writeNativeAdminConfig(paths, paths.adminConfigPath, ast, config);
@@ -755,6 +869,18 @@ async function writeNativeSchemaArtifacts(paths, ast, config) {
755
869
  writeNativeAppliedAst(cwd, config, ast);
756
870
  await writeNativeTypes(cwd, ast, config);
757
871
  }
872
+ /**
873
+ * {@link nativeS3StorageEnv} from the shell over .env, as compose reads them. A blank S3_BUCKET ends
874
+ * dev here, before anything has started, saying what to set.
875
+ */
876
+ function s3StorageEnvOrExit(cwd) {
877
+ try {
878
+ return nativeS3StorageEnv({ ...readDotEnvFiles(cwd), ...process.env });
879
+ }
880
+ catch (err) {
881
+ fatalError(errorMessage(err));
882
+ }
883
+ }
758
884
  /** The storage buckets the schema declares, as the engine resolves them; none when it cannot say. */
759
885
  async function declaredBuckets(engineBin, cwd, astPath) {
760
886
  const parseResult = await runCaptured(engineBin, ["parse", "-i", astPath], { cwd });
@@ -769,24 +895,30 @@ async function declaredBuckets(engineBin, cwd, astPath) {
769
895
  }
770
896
  }
771
897
  /**
772
- * Create the storage buckets the schema declares: in buckets.json, which the server's store reads
773
- * and the storage service imports when it starts, and in the service itself once it runs.
898
+ * Create the storage buckets the schema declares: in buckets.json, which the storage service
899
+ * imports when it starts, and in the service itself once it runs. A project on S3 has the service
900
+ * alone.
774
901
  */
775
902
  async function provisionDeclaredBuckets(engineBin, cwd, astPath, paths) {
776
903
  const buckets = await declaredBuckets(engineBin, cwd, astPath);
777
- if (buckets.length === 0 || paths.storagePath === undefined)
904
+ if (buckets.length === 0)
778
905
  return;
779
- await provisionNativeBuckets(buckets, { storagePath: paths.storagePath, storageApi: paths.storageApi });
906
+ await provisionNativeBuckets(buckets, paths);
780
907
  }
781
908
  /**
782
909
  * `buckets` in buckets.json, and in the storage service while it runs, saying how many new ones
783
- * are ready: a bucket the service did not take is not, though buckets.json has it. Exported for tests.
910
+ * are ready: a bucket the service did not take is not, though buckets.json has it. A project on S3
911
+ * has no buckets.json, only the service, and is told which buckets it did not take. Exported for tests.
784
912
  */
785
913
  export async function provisionNativeBuckets(buckets, paths) {
786
- const added = provisionStorageBuckets(buckets, paths.storagePath);
914
+ const added = paths.storagePath === undefined ? null : provisionStorageBuckets(buckets, paths.storagePath);
787
915
  const failed = paths.storageApi
788
916
  ? await provisionBuckets(paths.storageApi.url, paths.storageApi.serviceRoleKey, bucketSpecsFromAst({ storageBuckets: buckets }))
789
917
  : [];
918
+ if (added === null) {
919
+ warnBucketsLeft(unprovisionedBuckets({ total: buckets.length, failed }));
920
+ return;
921
+ }
790
922
  const ready = added.filter((id) => !failed.includes(id)).length;
791
923
  if (ready > 0)
792
924
  console.log(`[supatype] Storage: provisioned ${ready} bucket(s).`);
@@ -850,6 +982,14 @@ function provisionStorageBuckets(declared, storagePath) {
850
982
  // Resolve Postgres bin dir
851
983
  // ---------------------------------------------------------------------------
852
984
  export async function resolvePgBinDir(config) {
985
+ return (await resolvePgInstall(config)).binDir;
986
+ }
987
+ /**
988
+ * Native Postgres's bin directory, and the version of the archive it came from: null for
989
+ * `overrides.postgres_dir`, a local build whose version nothing records. The version is resolved
990
+ * here once, since on a build that is not a release resolving it asks the CDN.
991
+ */
992
+ async function resolvePgInstall(config) {
853
993
  const override = config.overrides?.postgres_dir;
854
994
  if (override) {
855
995
  // Normalize Git Bash (/c/Users/...) paths to Win32 form (C:\Users\...) on Windows.
@@ -860,7 +1000,7 @@ export async function resolvePgBinDir(config) {
860
1000
  throw new Error(`[overrides] postgres_dir does not contain a bin/ directory: ${resolved}`);
861
1001
  }
862
1002
  console.warn(`\u26a0 Using local Postgres build: ${resolved}`);
863
- return binDir;
1003
+ return { binDir, version: null };
864
1004
  }
865
1005
  // Locate cached Postgres archive.
866
1006
  const { cachePath, currentPlatform, resolveVersionFor } = await import("../binary-cache.js");
@@ -873,7 +1013,7 @@ export async function resolvePgBinDir(config) {
873
1013
  // Try to extract the cached archive.
874
1014
  await extractPostgresArchive(pgCacheDir, version, platform, extractedDir);
875
1015
  }
876
- return join(extractedDir, "bin");
1016
+ return { binDir: join(extractedDir, "bin"), version };
877
1017
  }
878
1018
  async function extractPostgresArchive(pgCacheDir, version, platform, extractDir) {
879
1019
  const ext = platform.os === "windows" ? ".zip" : ".tar.gz";
@@ -1058,15 +1198,29 @@ function runAuthMigrations(serverBin, migrateEnv) {
1058
1198
  }
1059
1199
  }
1060
1200
  /**
1061
- * The keyspace native Postgres serves, when it answers RESP, else Valkey: one already running, or
1062
- * the sidecar container.
1201
+ * Native dev's REST cache: the keyspace native Postgres serves, on loopback and requiring its
1202
+ * password, when it answers a client that logs in; else Valkey, the project's own sidecar container
1203
+ * or the one SUPATYPE_VALKEY_ADDR names (valkey-sidecar.ts, N-S28). Windows archives carry no
1204
+ * pg_keyspace, so Windows is always Valkey.
1063
1205
  */
1064
- async function nativeValkey(keyspacePort, projectName) {
1065
- const keyspace = await nativeKeyspaceAddrFor(keyspacePort);
1066
- if (keyspace === null)
1067
- return ensureValkeySidecar(projectName);
1068
- console.log(`[supatype] Keyspace served by Postgres (${keyspace}).`);
1069
- return externalValkey(keyspace);
1206
+ async function nativeCache(keyspace, projectName, cwd) {
1207
+ const addr = keyspace === null ? null : await nativeKeyspaceAddr(keyspace.port, keyspace.login);
1208
+ if (addr === null || keyspace === null)
1209
+ return { sidecar: await ensureValkeySidecar(projectName, cwd), login: null };
1210
+ console.log(`[supatype] Keyspace served by Postgres (${addr}, loopback only, password ${keyspacePasswordOrigin(cwd)}).`);
1211
+ return { sidecar: externalValkey(addr), login: keyspace.login };
1212
+ }
1213
+ /**
1214
+ * Stops this project's own Postgres, left running by a dev that did not stop cleanly, so this run
1215
+ * starts it with its own settings and stops it when it ends (FF12 remainder,
1216
+ * native-leftover-postgres.ts).
1217
+ */
1218
+ function restartLeftoverPostgres(claim, pgOpts) {
1219
+ const pid = claim?.leftoverPostgres ?? null;
1220
+ if (pid === null)
1221
+ return;
1222
+ console.log(`[supatype] This project's Postgres (pid ${pid}) was still running from a dev that did not stop cleanly; restarting it.`);
1223
+ pgStop(pgOpts);
1070
1224
  }
1071
1225
  /**
1072
1226
  * The project database: left as it is when psql can report its encoding (with a warning when an
@@ -1101,7 +1255,7 @@ function ensureProjectDatabase(db) {
1101
1255
  * What push and Docker dev write from an applied AST (applied-ast-artifacts.ts), for native dev,
1102
1256
  * which has no row-cache container. The manifest is made first when there is none: the hook maps
1103
1257
  * only go into one that exists, and the first push runs before native dev records its functions,
1104
- * which sets `functions_enabled` before the server reads it.
1258
+ * which switches functions (`services.functions`) before the server reads it.
1105
1259
  */
1106
1260
  function writeNativeAppliedAst(cwd, config, ast) {
1107
1261
  const manifestPath = join(cwd, ".supatype", "manifest.json");