{"version":3,"file":"db.mjs","names":[],"sources":["../../src/handlers/db.ts"],"sourcesContent":["import { findConfigPath, MISSING_CONFIG_MESSAGE } from \"../config\";\nimport { DbOpsService } from \"../services/db/ops\";\nimport type { BosBuilder } from \"./shared\";\n\nfunction missingConfig() {\n  return `${MISSING_CONFIG_MESSAGE} in current directory`;\n}\n\nexport function registerDb(builder: BosBuilder) {\n  return {\n    dbStudio: builder.dbStudio.effect(function* (_opts, input) {\n      if (!findConfigPath()) {\n        return {\n          status: \"error\",\n          plugin: input.plugin,\n          source: \"remote\",\n          section: \"\",\n          error: missingConfig(),\n        };\n      }\n      const db = yield* DbOpsService;\n      return yield* db.studio(input.plugin);\n    }),\n\n    dbDoctor: builder.dbDoctor.effect(function* (_opts, input) {\n      if (!findConfigPath()) {\n        return {\n          status: \"error\",\n          plugin: input.plugin,\n          slug: \"\",\n          journalTable: \"\",\n          journalSchema: \"\",\n          diagnosis: \"error\",\n          localMigrationCount: 0,\n          appliedHashCount: 0,\n          expectedTables: [],\n          missingTables: [],\n          error: missingConfig(),\n        };\n      }\n      const db = yield* DbOpsService;\n      return yield* db.doctor(input.plugin);\n    }),\n\n    dbRepair: builder.dbRepair.effect(function* (_opts, input) {\n      if (!findConfigPath()) {\n        return {\n          status: \"error\",\n          message: MISSING_CONFIG_MESSAGE,\n          diagnosis: null,\n          error: \"No config\",\n        };\n      }\n      const db = yield* DbOpsService;\n      return yield* db.repair(input.plugin, input.mode ?? \"history-reset\");\n    }),\n  };\n}\n"],"mappings":";;;;AAIA,SAAS,gBAAgB;CACvB,OAAO,GAAG,uBAAuB;AACnC;AAEA,SAAgB,WAAW,SAAqB;CAC9C,OAAO;EACL,UAAU,QAAQ,SAAS,OAAO,WAAW,OAAO,OAAO;GACzD,IAAI,CAAC,eAAe,GAClB,OAAO;IACL,QAAQ;IACR,QAAQ,MAAM;IACd,QAAQ;IACR,SAAS;IACT,OAAO,cAAc;GACvB;GAGF,OAAO,QAAO,OADI,aACF,CAAC,OAAO,MAAM,MAAM;EACtC,CAAC;EAED,UAAU,QAAQ,SAAS,OAAO,WAAW,OAAO,OAAO;GACzD,IAAI,CAAC,eAAe,GAClB,OAAO;IACL,QAAQ;IACR,QAAQ,MAAM;IACd,MAAM;IACN,cAAc;IACd,eAAe;IACf,WAAW;IACX,qBAAqB;IACrB,kBAAkB;IAClB,gBAAgB,CAAC;IACjB,eAAe,CAAC;IAChB,OAAO,cAAc;GACvB;GAGF,OAAO,QAAO,OADI,aACF,CAAC,OAAO,MAAM,MAAM;EACtC,CAAC;EAED,UAAU,QAAQ,SAAS,OAAO,WAAW,OAAO,OAAO;GACzD,IAAI,CAAC,eAAe,GAClB,OAAO;IACL,QAAQ;IACR,SAAS;IACT,WAAW;IACX,OAAO;GACT;GAGF,OAAO,QAAO,OADI,aACF,CAAC,OAAO,MAAM,QAAQ,MAAM,QAAQ,eAAe;EACrE,CAAC;CACH;AACF"}