@rebasepro/cli 0.25.0-canary.g70dad01 → 0.25.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.
@@ -1 +0,0 @@
1
- {"version":3,"file":"connection-banner-CCIyvjpW.js","names":[],"sources":["../src/dev-db/connection-banner.ts"],"sourcesContent":["/**\n * The boxed banner the database commands print when a connection fails.\n *\n * ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n * ❌ Cannot connect to PostgreSQL at 127.0.0.1:5508\n * ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n *\n * The driver said: connect ECONNREFUSED 127.0.0.1:5508\n * …\n *\n * The driver prints it for the commands it runs (`cli-errors.ts` in\n * `@rebasepro/server-postgres`, which its entry does not export); this is the\n * same box for the commands the CLI answers in its own process — `db pull`\n * and `auth reset-password`'s database fallback — as plain lines for the\n * caller to print. Never with the connection string in it: it carries the\n * password.\n */\nimport type { DevDatabaseSource } from \"./resolve\";\n\nconst RULE = \"━\".repeat(60);\n\n/** The banner, as lines: a title, what the driver or tool said, then the body. */\nexport function banner(title: string, said: string | null, body: readonly string[]): string[] {\n return [\"\", RULE, ` ❌ ${title}`, RULE, \"\", ...(said ? [` ${said}`, \"\"] : []), ...body.map(line => ` ${line}`), \"\", RULE];\n}\n\n/** `host:port` of a connection string, for a message: never the string, which carries the password. */\nexport function hostOf(connectionString: string): string {\n try {\n const url = new URL(connectionString);\n\n return `${url.hostname || \"localhost\"}:${url.port || \"5432\"}`;\n } catch {\n return \"(unparseable connection string)\";\n }\n}\n\n/**\n * A connection error's own sentence. A refused connection on a dual-stack\n * host is an `AggregateError` with an empty message, and its sentence —\n * `connect ECONNREFUSED 127.0.0.1:5432` — is in the attempts it holds.\n */\nexport function connectionErrorText(error: unknown): string {\n if (error instanceof AggregateError && error.errors.length > 0 && !error.message) {\n return connectionErrorText(error.errors[0]);\n }\n\n return error instanceof Error && error.message ? error.message : String(error);\n}\n\n/** The `code` a `pg` or `net` error carries, looking inside an `AggregateError`'s attempts. */\nfunction codeOf(error: unknown): string | undefined {\n if (error instanceof AggregateError && error.errors.length > 0) {\n for (const inner of error.errors) {\n const code = codeOf(inner);\n if (code) return code;\n }\n }\n if (error && typeof error === \"object\" && \"code\" in error && typeof error.code === \"string\") return error.code;\n\n return undefined;\n}\n\n/** A server that is not there, or not reachable from here. */\nconst UNREACHABLE = new Set([\"ECONNREFUSED\", \"ENOTFOUND\", \"EAI_AGAIN\", \"ETIMEDOUT\", \"EHOSTUNREACH\", \"ENETUNREACH\", \"ECONNRESET\"]);\n\n/**\n * What to print when opening `url` failed with `error`: the banner, in the\n * case it is — the server not answering, credentials refused, or a database\n * of that name not there — or `null` when it is none of those three.\n *\n * `consequence` is the line saying what did not happen (\"The password was not\n * reset.\"); `fixes` is what to do about a server that does not answer, which\n * depends on what named the database.\n */\nexport function connectionFailureBanner(\n url: string,\n error: unknown,\n options: { consequence: string; fixes: readonly string[] }\n): string[] | null {\n const code = codeOf(error);\n const text = connectionErrorText(error);\n const said = `The driver said: ${text}${code && !text.includes(code) ? ` (${code})` : \"\"}`;\n const host = hostOf(url);\n\n if ((code && UNREACHABLE.has(code)) || /timeout expired|Connection terminated due to connection timeout/i.test(text)) {\n return banner(`Cannot connect to PostgreSQL at ${host}`, said, [\n \"The database server is not running or is not accepting connections.\",\n options.consequence,\n \"\",\n ...options.fixes.map(fix => ` • ${fix}`)\n ]);\n }\n if (code === \"28P01\" || code === \"28000\") {\n let user = \"unknown\";\n try {\n user = decodeURIComponent(new URL(url).username) || \"unknown\";\n } catch { /* named as unknown */ }\n return banner(`Authentication failed for user \"${user}\" at ${host}`, said, [\n \"PostgreSQL rejected the credentials in the connection string.\",\n options.consequence\n ]);\n }\n if (code === \"3D000\") {\n let database = \"(default)\";\n try {\n database = decodeURIComponent(new URL(url).pathname.replace(/^\\//, \"\")) || database;\n } catch { /* named as the default */ }\n return banner(`Database \"${database}\" does not exist at ${host}`, said, [\n \"The server answered, and has no database of that name.\",\n options.consequence\n ]);\n }\n\n return null;\n}\n\n/**\n * What to do about a database that does not answer, for what named it — the\n * list the driver's banner gives for the same `REBASE_DATABASE_SOURCE`.\n */\nexport function connectionRefusedFixes(source: DevDatabaseSource): string[] {\n switch (source) {\n case \"flag\": return [\"Check the URL passed with --database-url, and that its server is running\"];\n case \"environment\": return [\"Check DATABASE_URL in this shell's environment, and that its server is running\"];\n case \"env-file\": return [\"Check DATABASE_URL in .env, and that its server is running\"];\n case \"branch\": return [\n \"The branch's database is on the server DATABASE_URL names: start that server\",\n \"Or leave the branch: rebase db branch switch --off\"\n ];\n case \"docker\":\n case \"last-dev\": return [\"docker compose up -d db (the project's Postgres in Docker)\"];\n case \"managed\": return [\"Restart the managed development database: rebase db stop, then run the command again\"];\n }\n}\n"],"mappings":";;;;;;;;;AAmBA,IAAM,OAAO,IAAI,OAAO,EAAE;;AAG1B,SAAgB,OAAO,OAAe,MAAqB,MAAmC;CAC1F,OAAO;EAAC;EAAI;EAAM,QAAQ;EAAS;EAAM;EAAI,GAAI,OAAO,CAAC,KAAK,QAAQ,EAAE,IAAI,CAAC;EAAI,GAAG,KAAK,KAAI,SAAQ,KAAK,MAAM;EAAG;EAAI;CAAI;AAC/H;;AAGA,SAAgB,OAAO,kBAAkC;CACrD,IAAI;EACA,MAAM,MAAM,IAAI,IAAI,gBAAgB;EAEpC,OAAO,GAAG,IAAI,YAAY,YAAY,GAAG,IAAI,QAAQ;CACzD,QAAQ;EACJ,OAAO;CACX;AACJ;;;;;;AAOA,SAAgB,oBAAoB,OAAwB;CACxD,IAAI,iBAAiB,kBAAkB,MAAM,OAAO,SAAS,KAAK,CAAC,MAAM,SACrE,OAAO,oBAAoB,MAAM,OAAO,EAAE;CAG9C,OAAO,iBAAiB,SAAS,MAAM,UAAU,MAAM,UAAU,OAAO,KAAK;AACjF;;AAGA,SAAS,OAAO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