@eloxiv/cli 0.0.0-stage → 0.1.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 (294) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +12 -2
  3. package/dist/AgentSkills.d.ts +51 -0
  4. package/dist/AgentSkills.d.ts.map +1 -0
  5. package/dist/AgentSkills.js +264 -0
  6. package/dist/AgentSkills.js.map +1 -0
  7. package/dist/AgentWeb.d.ts +83 -0
  8. package/dist/AgentWeb.d.ts.map +1 -0
  9. package/dist/AgentWeb.js +436 -0
  10. package/dist/AgentWeb.js.map +1 -0
  11. package/dist/App.d.ts +213 -0
  12. package/dist/App.d.ts.map +1 -0
  13. package/dist/App.js +357 -0
  14. package/dist/App.js.map +1 -0
  15. package/dist/Blueprint.d.ts +47 -0
  16. package/dist/Blueprint.d.ts.map +1 -0
  17. package/dist/Blueprint.js +241 -0
  18. package/dist/Blueprint.js.map +1 -0
  19. package/dist/Brand.d.ts +42 -0
  20. package/dist/Brand.d.ts.map +1 -0
  21. package/dist/Brand.js +370 -0
  22. package/dist/Brand.js.map +1 -0
  23. package/dist/Changelog.d.ts +22 -0
  24. package/dist/Changelog.d.ts.map +1 -0
  25. package/dist/Changelog.js +117 -0
  26. package/dist/Changelog.js.map +1 -0
  27. package/dist/Cli.d.ts +17 -0
  28. package/dist/Cli.d.ts.map +1 -0
  29. package/dist/Cli.js +810 -0
  30. package/dist/Cli.js.map +1 -0
  31. package/dist/DbAdmin.d.ts +18 -0
  32. package/dist/DbAdmin.d.ts.map +1 -0
  33. package/dist/DbAdmin.js +91 -0
  34. package/dist/DbAdmin.js.map +1 -0
  35. package/dist/Dependencies.d.ts +53 -0
  36. package/dist/Dependencies.d.ts.map +1 -0
  37. package/dist/Dependencies.js +132 -0
  38. package/dist/Dependencies.js.map +1 -0
  39. package/dist/Deploy.d.ts +39 -0
  40. package/dist/Deploy.d.ts.map +1 -0
  41. package/dist/Deploy.js +458 -0
  42. package/dist/Deploy.js.map +1 -0
  43. package/dist/Docs.d.ts +71 -0
  44. package/dist/Docs.d.ts.map +1 -0
  45. package/dist/Docs.js +240 -0
  46. package/dist/Docs.js.map +1 -0
  47. package/dist/Doctor.d.ts +56 -0
  48. package/dist/Doctor.d.ts.map +1 -0
  49. package/dist/Doctor.js +368 -0
  50. package/dist/Doctor.js.map +1 -0
  51. package/dist/Dossier.d.ts +23 -0
  52. package/dist/Dossier.d.ts.map +1 -0
  53. package/dist/Dossier.js +92 -0
  54. package/dist/Dossier.js.map +1 -0
  55. package/dist/Emit.d.ts +26 -0
  56. package/dist/Emit.d.ts.map +1 -0
  57. package/dist/Emit.js +51 -0
  58. package/dist/Emit.js.map +1 -0
  59. package/dist/Errors.d.ts +26 -0
  60. package/dist/Errors.d.ts.map +1 -0
  61. package/dist/Errors.js +17 -0
  62. package/dist/Errors.js.map +1 -0
  63. package/dist/Evals.d.ts +52 -0
  64. package/dist/Evals.d.ts.map +1 -0
  65. package/dist/Evals.js +126 -0
  66. package/dist/Evals.js.map +1 -0
  67. package/dist/Files.d.ts +47 -0
  68. package/dist/Files.d.ts.map +1 -0
  69. package/dist/Files.js +145 -0
  70. package/dist/Files.js.map +1 -0
  71. package/dist/Generate.d.ts +80 -0
  72. package/dist/Generate.d.ts.map +1 -0
  73. package/dist/Generate.js +310 -0
  74. package/dist/Generate.js.map +1 -0
  75. package/dist/Guards.d.ts +45 -0
  76. package/dist/Guards.d.ts.map +1 -0
  77. package/dist/Guards.js +530 -0
  78. package/dist/Guards.js.map +1 -0
  79. package/dist/Inspect.d.ts +125 -0
  80. package/dist/Inspect.d.ts.map +1 -0
  81. package/dist/Inspect.js +270 -0
  82. package/dist/Inspect.js.map +1 -0
  83. package/dist/Keychain.d.ts +57 -0
  84. package/dist/Keychain.d.ts.map +1 -0
  85. package/dist/Keychain.js +73 -0
  86. package/dist/Keychain.js.map +1 -0
  87. package/dist/Lock.d.ts +13 -0
  88. package/dist/Lock.d.ts.map +1 -0
  89. package/dist/Lock.js +145 -0
  90. package/dist/Lock.js.map +1 -0
  91. package/dist/Mcp.d.ts +91 -0
  92. package/dist/Mcp.d.ts.map +1 -0
  93. package/dist/Mcp.js +128 -0
  94. package/dist/Mcp.js.map +1 -0
  95. package/dist/Merge.d.ts +18 -0
  96. package/dist/Merge.d.ts.map +1 -0
  97. package/dist/Merge.js +43 -0
  98. package/dist/Merge.js.map +1 -0
  99. package/dist/Migrate.d.ts +78 -0
  100. package/dist/Migrate.d.ts.map +1 -0
  101. package/dist/Migrate.js +288 -0
  102. package/dist/Migrate.js.map +1 -0
  103. package/dist/Plugins.d.ts +36 -0
  104. package/dist/Plugins.d.ts.map +1 -0
  105. package/dist/Plugins.js +304 -0
  106. package/dist/Plugins.js.map +1 -0
  107. package/dist/Postgres.d.ts +73 -0
  108. package/dist/Postgres.d.ts.map +1 -0
  109. package/dist/Postgres.js +294 -0
  110. package/dist/Postgres.js.map +1 -0
  111. package/dist/Publish.d.ts +23 -0
  112. package/dist/Publish.d.ts.map +1 -0
  113. package/dist/Publish.js +59 -0
  114. package/dist/Publish.js.map +1 -0
  115. package/dist/Registry.d.ts +539 -0
  116. package/dist/Registry.d.ts.map +1 -0
  117. package/dist/Registry.js +340 -0
  118. package/dist/Registry.js.map +1 -0
  119. package/dist/Remote.d.ts +90 -0
  120. package/dist/Remote.d.ts.map +1 -0
  121. package/dist/Remote.js +1006 -0
  122. package/dist/Remote.js.map +1 -0
  123. package/dist/Run.d.ts +120 -0
  124. package/dist/Run.d.ts.map +1 -0
  125. package/dist/Run.js +477 -0
  126. package/dist/Run.js.map +1 -0
  127. package/dist/SyncGen.d.ts +118 -0
  128. package/dist/SyncGen.d.ts.map +1 -0
  129. package/dist/SyncGen.js +392 -0
  130. package/dist/SyncGen.js.map +1 -0
  131. package/dist/Update.d.ts +301 -0
  132. package/dist/Update.d.ts.map +1 -0
  133. package/dist/Update.js +627 -0
  134. package/dist/Update.js.map +1 -0
  135. package/dist/bin.d.ts +3 -0
  136. package/dist/bin.d.ts.map +1 -0
  137. package/dist/bin.js +42 -0
  138. package/dist/bin.js.map +1 -0
  139. package/dist/docs/backlog.md +56 -0
  140. package/dist/docs/ci.md +277 -0
  141. package/dist/docs/cli.md +696 -0
  142. package/dist/docs/connectors/google.md +115 -0
  143. package/dist/docs/connectors/http-openapi.md +7 -0
  144. package/dist/docs/connectors/mcp.md +8 -0
  145. package/dist/docs/connectors/microsoft-graph.md +75 -0
  146. package/dist/docs/connectors/openai.md +25 -0
  147. package/dist/docs/connectors/slack.md +162 -0
  148. package/dist/docs/connectors/workos.md +39 -0
  149. package/dist/docs/contracts/README.md +173 -0
  150. package/dist/docs/contracts/action-consent.md +92 -0
  151. package/dist/docs/contracts/action-registry.md +85 -0
  152. package/dist/docs/contracts/actor.md +100 -0
  153. package/dist/docs/contracts/agent-resources.md +90 -0
  154. package/dist/docs/contracts/agent-runtime.md +257 -0
  155. package/dist/docs/contracts/approvals.md +126 -0
  156. package/dist/docs/contracts/audit.md +75 -0
  157. package/dist/docs/contracts/auth-provider.md +74 -0
  158. package/dist/docs/contracts/calendar-provider.md +46 -0
  159. package/dist/docs/contracts/client-sdk.md +245 -0
  160. package/dist/docs/contracts/collab-document.md +151 -0
  161. package/dist/docs/contracts/command.md +44 -0
  162. package/dist/docs/contracts/connections.md +235 -0
  163. package/dist/docs/contracts/context-accounting.md +50 -0
  164. package/dist/docs/contracts/daemon.md +243 -0
  165. package/dist/docs/contracts/db-tx.md +53 -0
  166. package/dist/docs/contracts/delegation.md +68 -0
  167. package/dist/docs/contracts/device-control.md +103 -0
  168. package/dist/docs/contracts/directory-provider.md +36 -0
  169. package/dist/docs/contracts/directory.md +161 -0
  170. package/dist/docs/contracts/document-source.md +33 -0
  171. package/dist/docs/contracts/files.md +115 -0
  172. package/dist/docs/contracts/flags.md +83 -0
  173. package/dist/docs/contracts/host.md +68 -0
  174. package/dist/docs/contracts/http-api.md +43 -0
  175. package/dist/docs/contracts/ingestion.md +130 -0
  176. package/dist/docs/contracts/ingress.md +141 -0
  177. package/dist/docs/contracts/invocation.md +260 -0
  178. package/dist/docs/contracts/local-client.md +108 -0
  179. package/dist/docs/contracts/locale.md +56 -0
  180. package/dist/docs/contracts/machine-identity.md +117 -0
  181. package/dist/docs/contracts/mail-provider.md +49 -0
  182. package/dist/docs/contracts/memory.md +53 -0
  183. package/dist/docs/contracts/messaging.md +40 -0
  184. package/dist/docs/contracts/metering.md +139 -0
  185. package/dist/docs/contracts/model-provider.md +84 -0
  186. package/dist/docs/contracts/module-manifest.md +213 -0
  187. package/dist/docs/contracts/notification-channel.md +90 -0
  188. package/dist/docs/contracts/notifications.md +123 -0
  189. package/dist/docs/contracts/outbox.md +80 -0
  190. package/dist/docs/contracts/privacy.md +110 -0
  191. package/dist/docs/contracts/progress.md +52 -0
  192. package/dist/docs/contracts/query-surface.md +108 -0
  193. package/dist/docs/contracts/readiness.md +63 -0
  194. package/dist/docs/contracts/release.md +142 -0
  195. package/dist/docs/contracts/result-rendering.md +61 -0
  196. package/dist/docs/contracts/sandbox.md +186 -0
  197. package/dist/docs/contracts/scheduler.md +148 -0
  198. package/dist/docs/contracts/screen-context.md +81 -0
  199. package/dist/docs/contracts/search.md +120 -0
  200. package/dist/docs/contracts/secrets.md +74 -0
  201. package/dist/docs/contracts/settings.md +109 -0
  202. package/dist/docs/contracts/sharing.md +77 -0
  203. package/dist/docs/contracts/slot.md +48 -0
  204. package/dist/docs/contracts/space.md +67 -0
  205. package/dist/docs/contracts/storage-adapter.md +45 -0
  206. package/dist/docs/contracts/storage-backend.md +56 -0
  207. package/dist/docs/contracts/sync.md +213 -0
  208. package/dist/docs/contracts/telemetry.md +80 -0
  209. package/dist/docs/contracts/theme-tokens.md +50 -0
  210. package/dist/docs/contracts/tool-source.md +58 -0
  211. package/dist/docs/contracts/versioning.md +99 -0
  212. package/dist/docs/contracts/view.md +65 -0
  213. package/dist/docs/contracts/work-items.md +99 -0
  214. package/dist/docs/contracts/workflow.md +82 -0
  215. package/dist/docs/decisions.md +163 -0
  216. package/dist/docs/example-app.md +192 -0
  217. package/dist/docs/getting-started.md +927 -0
  218. package/dist/docs/goal.md +54 -0
  219. package/dist/docs/parity.md +29 -0
  220. package/dist/docs/performance.md +129 -0
  221. package/dist/docs/registry/README.md +74 -0
  222. package/dist/docs/registry/app.md +38 -0
  223. package/dist/docs/registry/approvals-ui-foldkit.md +28 -0
  224. package/dist/docs/registry/calendar-ui-foldkit.md +27 -0
  225. package/dist/docs/registry/calendar.md +35 -0
  226. package/dist/docs/registry/chat-ui-foldkit.md +30 -0
  227. package/dist/docs/registry/desktop-rune.md +49 -0
  228. package/dist/docs/registry/desktop.md +32 -0
  229. package/dist/docs/registry/eloxiv-action.md +25 -0
  230. package/dist/docs/registry/eloxiv-connector.md +25 -0
  231. package/dist/docs/registry/eloxiv-module.md +25 -0
  232. package/dist/docs/registry/eloxiv-policy.md +25 -0
  233. package/dist/docs/registry/eloxiv-view.md +25 -0
  234. package/dist/docs/registry/hello-ui-foldkit.md +29 -0
  235. package/dist/docs/registry/hello.md +39 -0
  236. package/dist/docs/registry/home-ui-foldkit.md +27 -0
  237. package/dist/docs/registry/home.md +29 -0
  238. package/dist/docs/registry/inbox-ui-foldkit.md +27 -0
  239. package/dist/docs/registry/mail-ui-foldkit.md +27 -0
  240. package/dist/docs/registry/mail.md +34 -0
  241. package/dist/docs/registry/meeting-prep.md +26 -0
  242. package/dist/docs/registry/members-ui-foldkit.md +28 -0
  243. package/dist/docs/registry/mobile.md +37 -0
  244. package/dist/docs/registry/notes-ui-foldkit.md +27 -0
  245. package/dist/docs/registry/notes.md +26 -0
  246. package/dist/docs/registry/people-ui-foldkit.md +28 -0
  247. package/dist/docs/registry/people.md +38 -0
  248. package/dist/docs/registry/shell-foldkit.md +34 -0
  249. package/dist/docs/registry/theme.md +25 -0
  250. package/dist/docs/registry/ui-conformance.md +30 -0
  251. package/dist/docs/release.md +100 -0
  252. package/dist/docs/scaffold.md +826 -0
  253. package/dist/docs/security/threat-model.md +299 -0
  254. package/dist/docs/upstream/zero-cache-socket-handoff.md +105 -0
  255. package/dist/index.d.ts +8 -0
  256. package/dist/index.d.ts.map +1 -0
  257. package/dist/index.js +8 -0
  258. package/dist/index.js.map +1 -0
  259. package/package.json +48 -3
  260. package/src/AgentSkills.ts +329 -0
  261. package/src/AgentWeb.ts +507 -0
  262. package/src/App.ts +435 -0
  263. package/src/Blueprint.ts +276 -0
  264. package/src/Brand.ts +415 -0
  265. package/src/Changelog.ts +136 -0
  266. package/src/Cli.ts +1458 -0
  267. package/src/DbAdmin.ts +115 -0
  268. package/src/Dependencies.ts +170 -0
  269. package/src/Deploy.ts +563 -0
  270. package/src/Docs.ts +309 -0
  271. package/src/Doctor.ts +424 -0
  272. package/src/Dossier.ts +148 -0
  273. package/src/Emit.ts +68 -0
  274. package/src/Errors.ts +18 -0
  275. package/src/Evals.ts +153 -0
  276. package/src/Files.ts +152 -0
  277. package/src/Generate.ts +402 -0
  278. package/src/Guards.ts +541 -0
  279. package/src/Inspect.ts +358 -0
  280. package/src/Keychain.ts +107 -0
  281. package/src/Lock.ts +174 -0
  282. package/src/Mcp.ts +159 -0
  283. package/src/Merge.ts +70 -0
  284. package/src/Migrate.ts +331 -0
  285. package/src/Plugins.ts +347 -0
  286. package/src/Postgres.ts +353 -0
  287. package/src/Publish.ts +64 -0
  288. package/src/Registry.ts +405 -0
  289. package/src/Remote.ts +1158 -0
  290. package/src/Run.ts +541 -0
  291. package/src/SyncGen.ts +570 -0
  292. package/src/Update.ts +873 -0
  293. package/src/bin.ts +46 -0
  294. package/src/index.ts +7 -0
@@ -0,0 +1,353 @@
1
+ /**
2
+ * PostgreSQL host recipes (docs/cli.md, "Database hosts"):
3
+ *
4
+ * eloxiv db host <provider> what to enable on a host and which URL goes where (Neon, Supabase, RDS, Azure,
5
+ * Cloud SQL, plain PostgreSQL)
6
+ * eloxiv db check [--live] the deployment's database URLs classified (direct, session or transaction pooler,
7
+ * proxy) against what each connection needs; with --live, the host itself (logical
8
+ * replication, the setup role's attributes)
9
+ *
10
+ * What the kernel needs is fixed by setup and sync (docs/contracts/release.md, "Database hosts"): setup's admin
11
+ * connection and zero-cache's replication need real sessions on the database itself (session advisory locks,
12
+ * logical replication), so neither may go through a transaction pooler or a proxy; the kernel's runtime connection
13
+ * may use a session pooler. Nothing here changes a host: recipes are text, and the live check only reads.
14
+ */
15
+ import { spawnSync } from "node:child_process"
16
+
17
+ export const PROVIDERS = ["neon", "supabase", "rds", "azure", "cloud-sql", "postgres"] as const
18
+ export type Provider = (typeof PROVIDERS)[number]
19
+
20
+ /** How a URL reaches PostgreSQL. */
21
+ export type Mode = "direct" | "session-pooler" | "transaction-pooler" | "proxy" | "unknown"
22
+
23
+ export interface Classified {
24
+ readonly provider: Provider
25
+ readonly mode: Mode
26
+ readonly host: string
27
+ readonly port: number
28
+ readonly sslmode: string | undefined
29
+ }
30
+
31
+ export interface Recipe {
32
+ readonly provider: Provider
33
+ readonly title: string
34
+ /** What to turn on at the host before setup runs. */
35
+ readonly enable: ReadonlyArray<string>
36
+ /** Which endpoint each URL uses. */
37
+ readonly urls: { readonly admin: string; readonly kernel: string; readonly zero: string }
38
+ /** Environment the deployment sets for this host (beyond the URLs). */
39
+ readonly env: Readonly<Record<string, string>>
40
+ readonly notes: ReadonlyArray<string>
41
+ }
42
+
43
+ const portOf = (url: URL) => (url.port === "" ? 5432 : Number(url.port))
44
+
45
+ /** Which provider and mode a PostgreSQL URL points at, from its host and port (nothing is contacted). */
46
+ export const classify = (raw: string): Classified => {
47
+ const url = new URL(raw)
48
+ const host = url.hostname.toLowerCase()
49
+ const port = portOf(url)
50
+ const sslmode = url.searchParams.get("sslmode") ?? undefined
51
+ const base = { host, port, sslmode }
52
+ if (host.endsWith(".neon.tech")) {
53
+ // Neon's pooled endpoint is PgBouncer in transaction mode: `<endpoint>-pooler.<region>...`.
54
+ return {
55
+ ...base,
56
+ provider: "neon",
57
+ mode: host.split(".")[0]!.endsWith("-pooler") ? "transaction-pooler" : "direct",
58
+ }
59
+ }
60
+ if (host.endsWith(".pooler.supabase.com")) {
61
+ // Supavisor: 6543 is transaction mode, 5432 session mode.
62
+ return { ...base, provider: "supabase", mode: port === 6543 ? "transaction-pooler" : "session-pooler" }
63
+ }
64
+ if (host.endsWith(".supabase.co"))
65
+ return { ...base, provider: "supabase", mode: port === 6543 ? "transaction-pooler" : "direct" }
66
+ if (host.endsWith(".rds.amazonaws.com")) {
67
+ // RDS Proxy endpoints: `<name>.proxy-<id>.<region>.rds.amazonaws.com`.
68
+ return { ...base, provider: "rds", mode: host.includes(".proxy-") ? "proxy" : "direct" }
69
+ }
70
+ if (host.endsWith(".postgres.database.azure.com")) {
71
+ // Flexible Server's built-in PgBouncer listens on 6432 (transaction mode by default).
72
+ return { ...base, provider: "azure", mode: port === 6432 ? "transaction-pooler" : "direct" }
73
+ }
74
+ const socket = url.searchParams.get("host") ?? ""
75
+ if (socket.startsWith("/cloudsql/")) return { ...base, provider: "cloud-sql", mode: "proxy" }
76
+ return { ...base, provider: "postgres", mode: port === 6432 ? "transaction-pooler" : "direct" }
77
+ }
78
+
79
+ /** The connections a deployment makes and what each needs. */
80
+ export const CONNECTIONS = {
81
+ admin: {
82
+ env: "ELOXIV_ADMIN_DATABASE_URL",
83
+ what: "setup's admin connection (session advisory locks, owner sessions)",
84
+ allowed: ["direct"] as ReadonlyArray<Mode>,
85
+ },
86
+ kernel: {
87
+ env: "ELOXIV_DATABASE_URL",
88
+ what: "the kernel's runtime connection (LISTEN/NOTIFY, session settings)",
89
+ allowed: ["direct", "session-pooler", "proxy"] as ReadonlyArray<Mode>,
90
+ },
91
+ zero: {
92
+ env: "ZERO_UPSTREAM_DB",
93
+ what: "zero-cache's logical replication",
94
+ allowed: ["direct"] as ReadonlyArray<Mode>,
95
+ },
96
+ } as const
97
+
98
+ /** Cloud SQL's Auth Proxy is a direct session to PostgreSQL (it tunnels, it does not pool): allowed everywhere. */
99
+ const allows = (connection: keyof typeof CONNECTIONS, classified: Classified) =>
100
+ CONNECTIONS[connection].allowed.includes(classified.mode) ||
101
+ (classified.provider === "cloud-sql" && classified.mode === "proxy")
102
+
103
+ export interface UrlCheck {
104
+ readonly connection: keyof typeof CONNECTIONS
105
+ readonly env: string
106
+ readonly status: "pass" | "warn" | "fail" | "not-run"
107
+ readonly detail: string
108
+ }
109
+
110
+ const hostedProviders: ReadonlySet<Provider> = new Set(["neon", "supabase", "rds", "azure"])
111
+
112
+ /**
113
+ * The deployment's database URLs (from `env`) against what each connection needs: a transaction pooler or a proxy
114
+ * where a real session is needed fails, a hosted database without `sslmode=require` (or stricter) warns.
115
+ * `ZERO_UPSTREAM_DB` defaults, as `eloxiv start zero` does, to the admin URL on the app's database.
116
+ */
117
+ export const checkUrls = (env: NodeJS.ProcessEnv): ReadonlyArray<UrlCheck> =>
118
+ (Object.keys(CONNECTIONS) as Array<keyof typeof CONNECTIONS>).map((connection): UrlCheck => {
119
+ const spec = CONNECTIONS[connection]
120
+ const raw = env[spec.env] ?? (connection === "zero" ? env["ELOXIV_ADMIN_DATABASE_URL"] : undefined)
121
+ if (raw === undefined) return { connection, env: spec.env, status: "not-run", detail: `${spec.env} is not set` }
122
+ let classified: Classified
123
+ try {
124
+ classified = classify(raw)
125
+ } catch {
126
+ return { connection, env: spec.env, status: "fail", detail: `${spec.env} is not a URL` }
127
+ }
128
+ const where = `${classified.provider}, ${classified.mode} (${classified.host}:${classified.port})`
129
+ if (!allows(connection, classified)) {
130
+ return {
131
+ connection,
132
+ env: spec.env,
133
+ status: "fail",
134
+ detail: `${where}: ${spec.what} needs ${spec.allowed.join(" or ")}; ${recipe(classified.provider).urls[connection]}`,
135
+ }
136
+ }
137
+ if (
138
+ hostedProviders.has(classified.provider) &&
139
+ !["require", "verify-ca", "verify-full"].includes(classified.sslmode ?? "")
140
+ ) {
141
+ return { connection, env: spec.env, status: "warn", detail: `${where}: add sslmode=require (or verify-full)` }
142
+ }
143
+ return { connection, env: spec.env, status: "pass", detail: where }
144
+ })
145
+
146
+ /** The recipe for `provider`. */
147
+ export const recipe = (provider: Provider): Recipe => RECIPES[provider]
148
+
149
+ const RECIPES: Record<Provider, Recipe> = {
150
+ neon: {
151
+ provider: "neon",
152
+ title: "Neon",
153
+ enable: ["Logical replication (project settings → Beta → Logical replication); it restarts the compute once"],
154
+ urls: {
155
+ admin: "neondb_owner on the direct endpoint (no -pooler in the host), with an explicit :5432",
156
+ kernel:
157
+ "a role setup creates (name it in ELOXIV_DATABASE_URL; do not create it in the console: such roles are members of neon_superuser and refused), direct endpoint",
158
+ zero: "neondb_owner on the direct endpoint; the pooled endpoint cannot replicate",
159
+ },
160
+ env: { ELOXIV_DATABASE_ROLE_PASSWORDS: "plaintext" },
161
+ notes: [
162
+ 'Neon accepts only plaintext role passwords: ELOXIV_DATABASE_ROLE_PASSWORDS=plaintext is the operator\'s choice; read docs/contracts/release.md, "Plaintext role passwords", first',
163
+ "Neon's proxy drops unknown startup parameters; the kernel already sends session settings as options=-c ...",
164
+ "Eloxiv's CI runs setup, sync and MAKE against a fresh Neon branch (live postgres (neon)): the one managed host proven end to end",
165
+ ],
166
+ },
167
+ supabase: {
168
+ provider: "supabase",
169
+ title: "Supabase",
170
+ enable: [
171
+ "Nothing to switch on: wal_level is logical. Setup runs as the postgres role",
172
+ "Network restrictions: allow where setup, the kernel and zero-cache run",
173
+ ],
174
+ urls: {
175
+ admin:
176
+ "the direct connection db.<project>.supabase.co:5432 (setup's owner sessions log in to the database itself, which no pooler passes)",
177
+ kernel:
178
+ "the direct connection, or Supavisor in session mode (<region>.pooler.supabase.com:5432); never transaction mode (port 6543)",
179
+ zero: "the direct connection db.<project>.supabase.co:5432 (replication does not pass Supavisor)",
180
+ },
181
+ env: {},
182
+ notes: [
183
+ "Supabase's own roles and schemas (auth, storage, realtime) are left alone; Eloxiv's Better Auth tables live in the auth schema of its own database, so give Eloxiv its own database (CREATE DATABASE through setup), not Supabase's postgres database",
184
+ "The direct connection is IPv6-only unless you buy the IPv4 add-on",
185
+ ],
186
+ },
187
+ rds: {
188
+ provider: "rds",
189
+ title: "Amazon RDS for PostgreSQL",
190
+ enable: [
191
+ "A custom parameter group with rds.logical_replication = 1 (static: reboot the instance)",
192
+ "max_replication_slots and max_wal_senders of at least 10",
193
+ ],
194
+ urls: {
195
+ admin: "the instance endpoint (<name>.<id>.<region>.rds.amazonaws.com:5432) as the master user (rds_superuser)",
196
+ kernel: "the instance endpoint; RDS Proxy pins sessions that set session state, so prefer the instance",
197
+ zero: "the instance endpoint as a role with rds_replication; RDS Proxy cannot replicate",
198
+ },
199
+ env: {},
200
+ notes: ["Require TLS: sslmode=verify-full with the RDS CA bundle (sslrootcert)"],
201
+ },
202
+ azure: {
203
+ provider: "azure",
204
+ title: "Azure Database for PostgreSQL (Flexible Server)",
205
+ enable: [
206
+ "Server parameters: wal_level = logical (restart), max_replication_slots ≥ 10, max_wal_senders ≥ 10",
207
+ "The admin user needs REPLICATION for zero-cache: ALTER ROLE <admin> WITH REPLICATION",
208
+ ],
209
+ urls: {
210
+ admin: "<server>.postgres.database.azure.com:5432 as the server admin (azure_pg_admin)",
211
+ kernel: "port 5432; the built-in PgBouncer (6432) runs in transaction mode",
212
+ zero: "port 5432 as the server admin with REPLICATION",
213
+ },
214
+ env: {},
215
+ notes: ["sslmode=require is enforced by default (require_secure_transport)"],
216
+ },
217
+ "cloud-sql": {
218
+ provider: "cloud-sql",
219
+ title: "Google Cloud SQL for PostgreSQL",
220
+ enable: [
221
+ "Database flag cloudsql.logical_decoding = on (restarts the instance)",
222
+ "The postgres user (cloudsqlsuperuser) with REPLICATION for zero-cache: ALTER USER postgres WITH REPLICATION",
223
+ ],
224
+ urls: {
225
+ admin:
226
+ "through the Cloud SQL Auth Proxy (127.0.0.1:5432, or ?host=/cloudsql/<project>:<region>:<instance>) as postgres",
227
+ kernel: "through the Auth Proxy (it tunnels sessions; it does not pool)",
228
+ zero: "through the Auth Proxy as postgres with REPLICATION",
229
+ },
230
+ env: {},
231
+ notes: ["Private IP with the proxy's --private-ip, or a public IP with authorised networks and sslmode=verify-ca"],
232
+ },
233
+ postgres: {
234
+ provider: "postgres",
235
+ title: "PostgreSQL you run (VM, container, Kubernetes)",
236
+ enable: [
237
+ "wal_level = logical (restart), max_replication_slots ≥ 10, max_wal_senders ≥ 10",
238
+ "pg_hba.conf: scram-sha-256 for the eloxiv_own_* roles from where setup runs (setup refuses trust for them in production)",
239
+ ],
240
+ urls: {
241
+ admin: "a superuser (every protection applies), directly; not through PgBouncer",
242
+ kernel: "directly, or PgBouncer in session mode",
243
+ zero: "a superuser or a role with REPLICATION, directly",
244
+ },
245
+ env: {},
246
+ notes: ["PostgreSQL 15 or later; 17 is what Eloxiv's CI runs"],
247
+ },
248
+ }
249
+
250
+ /** A recipe as text for an operator. */
251
+ export const formatRecipe = (r: Recipe) =>
252
+ [
253
+ `# ${r.title}`,
254
+ "",
255
+ "Enable before setup runs:",
256
+ ...r.enable.map((line) => `- ${line}`),
257
+ "",
258
+ "URLs:",
259
+ `- ELOXIV_ADMIN_DATABASE_URL (setup): ${r.urls.admin}`,
260
+ `- ELOXIV_DATABASE_URL (kernel): ${r.urls.kernel}`,
261
+ `- ZERO_UPSTREAM_DB (zero-cache): ${r.urls.zero}`,
262
+ ...(Object.keys(r.env).length === 0
263
+ ? []
264
+ : ["", "Environment:", ...Object.entries(r.env).map(([k, v]) => `- ${k}=${v}`)]),
265
+ "",
266
+ "Notes:",
267
+ ...r.notes.map((line) => `- ${line}`),
268
+ `- Setup requires of its role CREATEROLE, CREATEDB, BYPASSRLS and reading pg_authid (or a superuser), and checks them before it changes anything${r.provider === "neon" || r.provider === "postgres" ? "" : "; this host's recipe follows its provider's documentation and is not run by Eloxiv's CI, so check the role with --live first"}`,
269
+ "",
270
+ "Then: eloxiv db check --live, eloxiv setup (or the deployment's release step).",
271
+ ].join("\n")
272
+
273
+ export interface LiveCheck {
274
+ readonly id: string
275
+ readonly status: "pass" | "warn" | "fail" | "not-run"
276
+ readonly detail: string
277
+ }
278
+
279
+ /**
280
+ * Read the host through `url` (the admin URL) with psql: logical replication, replication capacity and what setup
281
+ * requires of its role. Nothing is changed.
282
+ */
283
+ export const checkLive = (url: string, psql = "psql"): ReadonlyArray<LiveCheck> => {
284
+ const result = spawnSync(
285
+ psql,
286
+ [
287
+ url,
288
+ "-XAtq",
289
+ "-F",
290
+ "|",
291
+ "-c",
292
+ `SELECT current_setting('wal_level'), current_setting('max_replication_slots'), current_setting('max_wal_senders'),
293
+ current_setting('server_version_num'), r.rolsuper, r.rolcreaterole, r.rolcreatedb, r.rolbypassrls,
294
+ r.rolreplication OR r.rolsuper,
295
+ pg_catalog.has_table_privilege('pg_catalog.pg_authid', 'SELECT')
296
+ FROM pg_catalog.pg_roles r WHERE r.rolname = session_user`,
297
+ ],
298
+ { encoding: "utf8", timeout: 20_000, env: { ...process.env, PGCONNECT_TIMEOUT: "10" } },
299
+ )
300
+ if (result.error !== undefined)
301
+ return [{ id: "live", status: "not-run", detail: `psql could not run: ${result.error.message}` }]
302
+ if (result.status !== 0)
303
+ return [
304
+ { id: "live", status: "fail", detail: `could not query the host: ${result.stderr.trim().split("\n")[0] ?? ""}` },
305
+ ]
306
+ const [wal, slots, senders, version, superuser, createrole, createdb, bypassrls, replication, authid] = result.stdout
307
+ .trim()
308
+ .split("|")
309
+ const yes = (value: string | undefined) => value === "t"
310
+ const missing = yes(superuser)
311
+ ? []
312
+ : [
313
+ ...(yes(createrole) ? [] : ["CREATEROLE"]),
314
+ ...(yes(createdb) ? [] : ["CREATEDB"]),
315
+ ...(yes(bypassrls) ? [] : ["BYPASSRLS"]),
316
+ ...(yes(authid) ? [] : ["SELECT on pg_authid (pg_read_all_data)"]),
317
+ ]
318
+ return [
319
+ {
320
+ id: "logical replication",
321
+ status: wal === "logical" ? "pass" : "fail",
322
+ detail:
323
+ wal === "logical" ? "wal_level=logical" : `wal_level=${wal}: zero-cache needs logical (see the host's recipe)`,
324
+ },
325
+ {
326
+ id: "replication capacity",
327
+ status: Number(slots) >= 4 && Number(senders) >= 4 ? "pass" : "warn",
328
+ detail: `max_replication_slots=${slots}, max_wal_senders=${senders} (each zero-cache replica holds one slot; keep room for a rolling deploy)`,
329
+ },
330
+ {
331
+ id: "server version",
332
+ status: Number(version) >= 150000 ? "pass" : "fail",
333
+ detail: `server_version_num=${version} (PostgreSQL 15 or later)`,
334
+ },
335
+ {
336
+ id: "setup role",
337
+ status: missing.length === 0 ? "pass" : "fail",
338
+ detail:
339
+ missing.length === 0
340
+ ? yes(superuser)
341
+ ? "superuser"
342
+ : "CREATEROLE, CREATEDB, BYPASSRLS, pg_authid"
343
+ : `lacks ${missing.join(", ")}`,
344
+ },
345
+ {
346
+ id: "replication role",
347
+ status: yes(replication) ? "pass" : "warn",
348
+ detail: yes(replication)
349
+ ? "can replicate"
350
+ : "has no REPLICATION: give zero-cache a role that has it (ZERO_UPSTREAM_DB)",
351
+ },
352
+ ]
353
+ }
package/src/Publish.ts ADDED
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Publishing a built registry immutably. `shadcn build` writes the latest version of every item to
3
+ * `<out>/<name>.json`; `publishVersions` then keeps a copy of each at `<out>/<name>/<version>.json`.
4
+ *
5
+ * A version, once published, never changes: if `<name>/<version>.json` already exists with different
6
+ * content, publishing fails and the item's `meta.eloxiv.version` must be bumped. Apps rely on this to fetch
7
+ * the exact version they installed (the base of a three-way merge) again.
8
+ */
9
+ import { Effect, FileSystem, Path, Schema } from "effect"
10
+ import { decodeItem, RegistryError, versionPath, type RegistryItem } from "./Registry.ts"
11
+
12
+ const RegistryIndex = Schema.Struct({ items: Schema.Array(Schema.Struct({ name: Schema.String })) })
13
+
14
+ export interface Published {
15
+ readonly name: string
16
+ readonly version: string
17
+ readonly status: "new" | "unchanged"
18
+ }
19
+
20
+ /** Canonical text of an item as published: what a version's immutability is checked against. */
21
+ export const publishedText = (item: unknown) => `${JSON.stringify(item, null, 2)}\n`
22
+
23
+ /**
24
+ * Write `<out>/<name>/<version>.json` for every item listed in `<out>/registry.json`, refusing to change a
25
+ * version that is already published. Returns what was published.
26
+ */
27
+ export const publishVersions = Effect.fn("Publish.publishVersions")(function* (out: string) {
28
+ const fs = yield* FileSystem.FileSystem
29
+ const path = yield* Path.Path
30
+ const indexText = yield* fs
31
+ .readFileString(path.join(out, "registry.json"))
32
+ .pipe(Effect.mapError(() => new RegistryError({ message: `No registry.json in ${out}` })))
33
+ const index = yield* Schema.decodeUnknownEffect(Schema.fromJsonString(RegistryIndex))(indexText).pipe(
34
+ Effect.mapError((e) => new RegistryError({ message: `${out}/registry.json is invalid: ${String(e)}` })),
35
+ )
36
+ const plan: Array<Published & { readonly target: string; readonly canonical: string }> = []
37
+ const refused: Array<string> = []
38
+ for (const { name } of index.items) {
39
+ const text = yield* fs
40
+ .readFileString(path.join(out, `${name}.json`))
41
+ .pipe(Effect.mapError(() => new RegistryError({ message: `${name}.json was not built in ${out}` })))
42
+ const item: RegistryItem = yield* decodeItem(text, name)
43
+ const version = item.meta.eloxiv.version
44
+ const canonical = publishedText(JSON.parse(text))
45
+ const target = path.join(out, versionPath(name, version))
46
+ if (yield* fs.exists(target)) {
47
+ const existing = publishedText(JSON.parse(yield* fs.readFileString(target)))
48
+ if (existing !== canonical) refused.push(`${name}@${version}`)
49
+ else plan.push({ name, version, status: "unchanged", target, canonical })
50
+ } else plan.push({ name, version, status: "new", target, canonical })
51
+ }
52
+ // Nothing is written unless every item can be published.
53
+ if (refused.length > 0) {
54
+ return yield* new RegistryError({
55
+ message: `Already published with different content: ${refused.join(", ")}. A published version is immutable: bump meta.eloxiv.version for each changed item.`,
56
+ })
57
+ }
58
+ for (const entry of plan) {
59
+ if (entry.status === "unchanged") continue
60
+ yield* fs.makeDirectory(path.dirname(entry.target), { recursive: true })
61
+ yield* fs.writeFileString(entry.target, entry.canonical)
62
+ }
63
+ return plan.map(({ name, version, status }): Published => ({ name, version, status }))
64
+ })