@lucidcms/core
Version:
The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.
1 lines • 2.5 kB
Source Map (JSON)
{"version":3,"file":"migration-approval.mjs","names":[],"sources":["../../../../src/libs/cli/services/migration-approval.ts"],"sourcesContent":["import { getMigrationRiskPriority } from \"../../collection/migration/assess-migration-plan.js\";\nimport type {\n\tMigrationAssessment,\n\tMigrationRisk,\n} from \"../../collection/migration/types.js\";\n\n/** The next approval action required before migration execution can continue. */\nexport type MigrationApprovalAction =\n\t| \"proceed\"\n\t| \"prompt-warning\"\n\t| \"prompt-destructive\"\n\t| \"reject-destructive\";\n\n/** Inputs used to resolve the non-interactive and interactive migration policy. */\nexport type MigrationApprovalInput = {\n\tassessment: MigrationAssessment;\n\thasPendingDatabaseMigrations: boolean;\n\tyes: boolean;\n\tallowDestructive: boolean;\n};\n\n/** Combines collection and arbitrary database migration risk into one level. */\nexport const getEffectiveMigrationRisk = (\n\tassessment: MigrationAssessment,\n\thasPendingDatabaseMigrations: boolean,\n): MigrationRisk => {\n\tif (assessment.risk === \"destructive\") return \"destructive\";\n\tif (assessment.risk === \"warning\" || hasPendingDatabaseMigrations) {\n\t\treturn \"warning\";\n\t}\n\treturn \"safe\";\n};\n\n/** Resolves whether migration work can proceed or which approval gate is needed. */\nexport const resolveMigrationApproval = ({\n\tassessment,\n\thasPendingDatabaseMigrations,\n\tyes,\n\tallowDestructive,\n}: MigrationApprovalInput): MigrationApprovalAction => {\n\tif (allowDestructive) return \"proceed\";\n\n\tconst risk = getEffectiveMigrationRisk(\n\t\tassessment,\n\t\thasPendingDatabaseMigrations,\n\t);\n\tif (risk === \"destructive\") {\n\t\treturn yes ? \"reject-destructive\" : \"prompt-destructive\";\n\t}\n\tif (risk === \"warning\") {\n\t\treturn yes ? \"proceed\" : \"prompt-warning\";\n\t}\n\treturn \"proceed\";\n};\n\n/** Returns whether a post-database collection plan needs a new approval gate. */\nexport const requiresPostMigrationApproval = (\n\tinitial: MigrationAssessment,\n\tupdated: MigrationAssessment,\n): boolean =>\n\tgetMigrationRiskPriority(updated.risk) >\n\tgetMigrationRiskPriority(initial.risk);\n"],"mappings":"gGAsBA,MAAa,GACZ,EACA,IAEI,EAAW,OAAS,cAAsB,cAC1C,EAAW,OAAS,WAAa,EAC7B,UAED,OAIK,GAA4B,CACxC,aACA,+BACA,MACA,sBACsD,CACtD,GAAI,EAAkB,MAAO,UAE7B,IAAM,EAAO,EACZ,EACA,CACD,EAOA,OANI,IAAS,cACL,EAAM,qBAAuB,qBAEjC,IAAS,UACL,EAAM,UAAY,iBAEnB,SACR,EAGa,GACZ,EACA,IAEA,EAAyB,EAAQ,IAAI,EACrC,EAAyB,EAAQ,IAAI"}