@lucidcms/core
Version:
The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.
1 lines • 2.29 kB
Source Map (JSON)
{"version":3,"file":"delete-expired-revisions.mjs","names":["documentServices.checks.checkCollection"],"sources":["../../../../src/services/documents-versions/jobs/delete-expired-revisions.ts"],"sourcesContent":["import { getTableNames } from \"../../../libs/collection/schema/runtime/runtime-schema-selectors.js\";\nimport { DocumentVersionsRepository } from \"../../../libs/repositories/index.js\";\nimport type { ServiceFn } from \"../../../utils/services/types.js\";\nimport { documentServices } from \"../../index.js\";\n\n/**\n * Deletes expired revisions for a specific collection.\n * A revision is considered expired if:\n * 1. It is older than the collection's revisionRetentionDays\n * 2. It is not referenced by any non-revision version's promoted_from field\n */\nconst deleteExpiredRevisions: ServiceFn<\n\t[\n\t\t{\n\t\t\tcollectionKey: string;\n\t\t\tretentionDays: number;\n\t\t},\n\t],\n\tundefined\n> = async (context, data) => {\n\tconst collectionRes = await documentServices.checks.checkCollection(context, {\n\t\tkey: data.collectionKey,\n\t});\n\tif (collectionRes.error) return collectionRes;\n\n\tconst tableNamesRes = await getTableNames(context, data.collectionKey);\n\tif (tableNamesRes.error) return tableNamesRes;\n\n\tconst DocumentVersions = new DocumentVersionsRepository(\n\t\tcontext.db.client,\n\t\tcontext.config.db,\n\t);\n\tconst cutoffDate = new Date();\n\tcutoffDate.setDate(cutoffDate.getDate() - data.retentionDays);\n\n\tconst deleteRes = await DocumentVersions.deleteExpiredRevisions(\n\t\t{\n\t\t\tcutoffDate: cutoffDate.toISOString(),\n\t\t},\n\t\t{\n\t\t\ttableName: tableNamesRes.data.version,\n\t\t},\n\t);\n\tif (deleteRes.error) return deleteRes;\n\n\treturn {\n\t\terror: undefined,\n\t\tdata: undefined,\n\t};\n};\n\nexport default deleteExpiredRevisions;\n"],"mappings":"gOAWA,MAAM,EAQF,MAAO,EAAS,IAAS,CAC5B,IAAM,EAAgB,MAAMA,EAAwC,EAAS,CAC5E,IAAK,EAAK,aACX,CAAC,EACD,GAAI,EAAc,MAAO,OAAO,EAEhC,IAAM,EAAgB,MAAM,EAAc,EAAS,EAAK,aAAa,EACrE,GAAI,EAAc,MAAO,OAAO,EAEhC,IAAM,EAAmB,IAAI,EAC5B,EAAQ,GAAG,OACX,EAAQ,OAAO,EAChB,EACM,EAAa,IAAI,KACvB,EAAW,QAAQ,EAAW,QAAQ,EAAI,EAAK,aAAa,EAE5D,IAAM,EAAY,MAAM,EAAiB,uBACxC,CACC,WAAY,EAAW,YAAY,CACpC,EACA,CACC,UAAW,EAAc,KAAK,OAC/B,CACD,EAGA,OAFI,EAAU,MAAc,EAErB,CACN,MAAO,IAAA,GACP,KAAM,IAAA,EACP,CACD"}