UNPKG

everything-dev

Version:

A consolidated product package for building Module Federation apps with oRPC APIs.

1 lines • 2.85 kB
{"version":3,"file":"db-topology.cjs","names":[],"sources":["../../../../../src/services/scaffold/upgrade-audit/checks/db-topology.ts"],"sourcesContent":["import { Effect } from \"effect\";\nimport { Finding } from \"../domain\";\nimport { fileExists, readText } from \"../fs\";\n\nexport const LAYER_PATH = \"api/src/db/layer.ts\";\n\nexport type DbTopology = \"absent\" | \"plugin-namespaced\" | \"public-topology\" | \"unknown\";\n\n/** The unconditional sync-owned template form: every workspace gets plugin_<slug>. */\nexport const PLUGIN_NAMESPACED_RE = /const\\s+schemaName\\s*=\\s*`plugin_\\$\\{slug\\}`\\s*;/;\n\n/** The api=public special case: `slug === \"api\" ? undefined : `plugin_${slug}``. */\nexport const PUBLIC_TOPOLOGY_RE =\n /const\\s+schemaName\\s*=\\s*slug\\s*===\\s*\"api\"\\s*\\?\\s*undefined\\s*:\\s*`plugin_\\$\\{slug\\}`\\s*;/;\n\nexport const detectDbTopology = (source: string): DbTopology => {\n if (PUBLIC_TOPOLOGY_RE.test(source)) return \"public-topology\";\n if (PLUGIN_NAMESPACED_RE.test(source)) return \"plugin-namespaced\";\n return \"unknown\";\n};\n\nexport const readDbTopology = (projectDir: string): Effect.Effect<DbTopology, Error> =>\n Effect.gen(function* () {\n const exists = yield* fileExists(projectDir, LAYER_PATH);\n if (!exists) return \"absent\";\n return detectDbTopology(yield* readText(projectDir, LAYER_PATH));\n });\n\nexport const checkDbTopology = (projectDir: string): Effect.Effect<Finding[], Error> =>\n Effect.gen(function* () {\n const topology = yield* readDbTopology(projectDir);\n if (topology === \"public-topology\" || topology === \"absent\") return [];\n\n if (topology === \"unknown\") {\n return [\n new Finding({\n check: \"db-topology\",\n path: LAYER_PATH,\n severity: \"warn\",\n message:\n \"api/src/db/layer.ts matches neither the plugin-namespaced template nor the api=public fix — inspect manually; the patch step will not touch it\",\n }),\n ];\n }\n\n return [\n new Finding({\n check: \"db-topology\",\n path: LAYER_PATH,\n severity: \"warn\",\n message:\n \"the sync-owned db layer template namespaces the api's data into plugin_api — this contradicts `bos db doctor` (checks the public schema), the drizzle-kit config (no schemaNames → public), and every v1-upgraded database (tables in public with a full journal): hash-edited migrations re-run into plugin_api, drift goes drift-manual, and the api plugin refuses to boot. Run `pnpm db-topology` to patch, and see the upstream layer-template ticket\",\n }),\n ];\n });\n"],"mappings":";;;AAIA,MAAa,aAAa;;AAK1B,MAAa,uBAAuB;;AAGpC,MAAa,qBACX;AAEF,MAAa,oBAAoB,WAA+B;CAC9D,IAAI,mBAAmB,KAAK,MAAM,GAAG,OAAO;CAC5C,IAAI,qBAAqB,KAAK,MAAM,GAAG,OAAO;CAC9C,OAAO;AACT"}