payload-plugin-backup-postgres 0.4.0 → 0.4.2

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 +1 @@
1
- {"version":3,"sources":["../../src/core/restorePreview.ts"],"sourcesContent":["import type { Payload } from 'payload'\n\nimport { readBackupArchiveBytes, resolveArchiveFileReference } from './backupArchiveRead'\nimport { type BackupBlobAccessLevel } from './backupBlobIO'\nimport { getPgDb } from './db'\nimport { loadPgArchive } from './pgArchive'\nimport { resolveTableOwners, rootTablesForSlug } from './tableGroups'\n\n/** Payload slugs whose replacement invalidates the current admin session. */\nconst AUTH_SESSION_SLUGS = new Set(['payload-preferences', 'roles', 'sessions', 'users'])\n\n/** Groups never listed in the UI (plugin-internal progress rows). */\nconst DEFAULT_EXCLUDED_GROUPS = new Set(['backup-numbers', 'backup-tasks'])\n\nexport type RestorePreviewFileKind = 'json' | 'tar-gzip'\n\nexport type RestorePreviewAdminHiddenReason = 'collection-config' | 'version-history'\n\nexport type RestorePreviewGroup = {\n adminHidden: boolean\n adminHiddenReasons: RestorePreviewAdminHiddenReason[]\n affectsAuthSession: boolean\n /** e.g. \"Seiten (pages)\" */\n displayTitle: string\n /** Stable id for UI: Payload collection/global slug when known, else the table name. */\n groupId: string\n /** Row count of the root table (one row per document). */\n main?: { docCount: number; tableName: string }\n /** All Postgres tables restored/skipped together when this group is toggled. */\n tableNames: string[]\n /** Row count of the `_<root>_v` versions table. */\n versions?: { docCount: number; tableName: string }\n}\n\nexport type RestorePreviewResponse = {\n /** Localized collection names represented by tables in the archive (excludes globals). */\n backupCollections: string[]\n fileKind: RestorePreviewFileKind\n groups: RestorePreviewGroup[]\n mediaBlobCount: number\n}\n\nfunction pickLocalizedLabel(labels: unknown, preferredLocales: string[]): string | undefined {\n if (!labels || typeof labels !== 'object') {\n return undefined\n }\n const l = labels as { plural?: unknown; singular?: unknown }\n\n const pickField = (field: unknown): string | undefined => {\n if (typeof field === 'string') {\n return field\n }\n if (field && typeof field === 'object') {\n const map = field as Record<string, string>\n for (const loc of preferredLocales) {\n const v = map[loc]\n if (v) {\n return v\n }\n }\n const first = Object.values(map).find(Boolean)\n return first\n }\n return undefined\n }\n\n return pickField(l.plural) || pickField(l.singular)\n}\n\nfunction humanizeSlug(slug: string): string {\n return slug\n .split('-')\n .map((w) => (w ? w.charAt(0).toUpperCase() + w.slice(1) : ''))\n .join(' ')\n}\n\n/** Collections shown in the default Payload admin sidebar: config order, skipping `admin.hidden`. */\nfunction getNavVisibleCollections(payload: Payload) {\n return payload.config.collections.filter((c) => c.admin?.hidden !== true)\n}\n\n/**\n * Index in sidebar order, or `null` if the group is not a visible nav collection\n * (hidden config, unknown table, global, etc.).\n */\nexport function navVisibleCollectionOrderIndex(payload: Payload, groupId: string): null | number {\n const visible = getNavVisibleCollections(payload)\n const idx = visible.findIndex((c) => c.slug === groupId)\n return idx === -1 ? null : idx\n}\n\nfunction sortPreviewGroupsLikeAdminNav(\n payload: Payload,\n groups: RestorePreviewGroup[],\n preferredLocales: string[],\n): void {\n const locale = preferredLocales[0] ?? 'en'\n groups.sort((a, b) => {\n const ia = navVisibleCollectionOrderIndex(payload, a.groupId)\n const ib = navVisibleCollectionOrderIndex(payload, b.groupId)\n if (ia !== null && ib !== null && ia !== ib) {\n return ia - ib\n }\n if (ia !== null && ib === null) {\n return -1\n }\n if (ia === null && ib !== null) {\n return 1\n }\n return a.displayTitle.localeCompare(b.displayTitle, locale)\n })\n}\n\nfunction buildDisplayTitle(\n payload: Payload,\n groupSlug: string,\n preferredLocales: string[],\n): string {\n const col = payload.config.collections.find((c) => c.slug === groupSlug)\n const glob = payload.config.globals?.find((g) => g.slug === groupSlug)\n const label =\n pickLocalizedLabel(col?.labels, preferredLocales) ||\n pickLocalizedLabel(glob ? { singular: glob.label } : undefined, preferredLocales) ||\n humanizeSlug(groupSlug)\n return `${label} (${groupSlug})`\n}\n\nexport async function loadRestoreBackupIndex(\n downloadUrl: string,\n options: {\n archivePathname?: string\n blobAccess?: BackupBlobAccessLevel\n blobToken?: string\n readAuth?: { pathname: string; token: string }\n } = {},\n): Promise<{\n countsByTable: Record<string, number>\n fileKind: RestorePreviewFileKind\n mediaBlobCount: number\n}> {\n const archiveRef = resolveArchiveFileReference(downloadUrl, options.archivePathname)\n const bytes = await readBackupArchiveBytes(downloadUrl, {\n archivePathname: options.archivePathname,\n backupRead: options.readAuth,\n blobAccess: options.blobAccess,\n blobToken: options.blobToken,\n })\n const archive = await loadPgArchive(bytes, archiveRef)\n const countsByTable: Record<string, number> = {}\n for (const [name, t] of Object.entries(archive.doc.tables)) {\n countsByTable[name] = t.rowCount\n }\n return { countsByTable, fileKind: archive.fileKind, mediaBlobCount: archive.media.length }\n}\n\ntype GroupAgg = {\n groupId: string\n kind: 'collection' | 'global' | 'unknown'\n main?: { docCount: number; tableName: string }\n tableNames: string[]\n versions?: { docCount: number; tableName: string }\n}\n\n/** Ensures every configured collection/global appears (0 rows if absent from the backup). */\nfunction mergeConfiguredZeros(\n payload: Payload,\n counts: Record<string, number>,\n excludeGroups: Set<string>,\n tableNameMap?: Map<string, string>,\n): Record<string, number> {\n const merged = { ...counts }\n const slugs = [\n ...(payload.config.collections ?? []).map((c) => c.slug),\n ...(payload.config.globals ?? []).map((g) => g.slug),\n ]\n for (const slug of slugs) {\n if (excludeGroups.has(slug)) {\n continue\n }\n const roots = rootTablesForSlug(payload, slug, tableNameMap)\n if (roots && !(roots.main in merged)) {\n merged[roots.main] = 0\n }\n }\n return merged\n}\n\nfunction safeTableNameMap(payload: Payload): Map<string, string> | undefined {\n try {\n return getPgDb(payload).tableNameMap\n } catch {\n return undefined\n }\n}\n\n/** Groups Postgres tables + row counts (live DB or backup file) by Payload collection/global. */\nexport function buildCollectionPreviewGroups(\n payload: Payload,\n countsByTable: Record<string, number>,\n options: {\n /** Payload slugs (or raw table names) to hide. Default: `backup-tasks`. */\n excludeGroups?: Set<string>\n /** When true, list groups whose tables are all empty (e.g. manual backup UI). Default false. */\n includeEmptyCollections?: boolean\n preferredLocales?: string[]\n /** When true, order like Payload admin sidebar; unknown / hidden-only groups last by title. */\n sortLikeAdminNav?: boolean\n } = {},\n): RestorePreviewGroup[] {\n const preferredLocales =\n options.preferredLocales?.length ? options.preferredLocales : ['de', 'en']\n const excludeGroups = options.excludeGroups ?? DEFAULT_EXCLUDED_GROUPS\n const includeEmptyCollections = options.includeEmptyCollections ?? false\n const sortLikeAdminNav = options.sortLikeAdminNav ?? false\n const tableNameMap = safeTableNameMap(payload)\n\n const owners = resolveTableOwners(payload, Object.keys(countsByTable), tableNameMap)\n const aggs = new Map<string, GroupAgg>()\n for (const [table, count] of Object.entries(countsByTable)) {\n const owner = owners.get(table)!\n if (excludeGroups.has(owner.slug)) {\n continue\n }\n const agg = aggs.get(owner.slug) ?? { groupId: owner.slug, kind: owner.kind, tableNames: [] }\n agg.tableNames.push(table)\n const roots =\n owner.kind === 'unknown' ? null : rootTablesForSlug(payload, owner.slug, tableNameMap)\n if (owner.kind === 'unknown' || table === roots?.main) {\n agg.main = { docCount: count, tableName: table }\n } else if (table === roots?.versions) {\n agg.versions = { docCount: count, tableName: table }\n }\n aggs.set(owner.slug, agg)\n }\n\n const authSlugs = new Set([\n ...(payload.config.collections ?? []).filter((c) => Boolean(c.auth)).map((c) => c.slug),\n ...AUTH_SESSION_SLUGS,\n ])\n\n const groups: RestorePreviewGroup[] = []\n for (const agg of aggs.values()) {\n const total = (agg.main?.docCount ?? 0) + (agg.versions?.docCount ?? 0)\n if (!includeEmptyCollections && total === 0) {\n continue\n }\n const reasons = new Set<RestorePreviewAdminHiddenReason>()\n const col = payload.config.collections?.find((c) => c.slug === agg.groupId)\n if (col?.admin?.hidden === true) {\n reasons.add('collection-config')\n }\n if (!agg.main && agg.versions) {\n reasons.add('version-history')\n }\n groups.push({\n adminHidden: reasons.size > 0,\n adminHiddenReasons: [...reasons],\n affectsAuthSession: authSlugs.has(agg.groupId),\n displayTitle:\n agg.kind === 'unknown' ?\n `${agg.groupId} (table)`\n : buildDisplayTitle(payload, agg.groupId, preferredLocales),\n groupId: agg.groupId,\n main: agg.main,\n tableNames: agg.tableNames.sort(),\n versions: agg.versions,\n })\n }\n\n if (sortLikeAdminNav) {\n sortPreviewGroupsLikeAdminNav(payload, groups, preferredLocales)\n } else {\n const locale = preferredLocales[0] ?? 'en'\n groups.sort((a, b) => a.displayTitle.localeCompare(b.displayTitle, locale))\n }\n return groups\n}\n\nexport function buildRestorePreviewGroups(\n payload: Payload,\n parsed: {\n countsByTable: Record<string, number>\n fileKind: RestorePreviewFileKind\n mediaBlobCount: number\n },\n options: { excludeGroups?: Set<string>; preferredLocales?: string[] } = {},\n): RestorePreviewResponse {\n const excludeGroups = options.excludeGroups ?? DEFAULT_EXCLUDED_GROUPS\n const counts = mergeConfiguredZeros(\n payload,\n parsed.countsByTable,\n excludeGroups,\n safeTableNameMap(payload),\n )\n const groups = buildCollectionPreviewGroups(payload, counts, {\n excludeGroups,\n includeEmptyCollections: true,\n preferredLocales: options.preferredLocales,\n sortLikeAdminNav: true,\n })\n const collectionSlugs = new Set(\n (payload.config.collections ?? []).map((collection) => collection.slug),\n )\n const backupCollections = buildCollectionPreviewGroups(payload, parsed.countsByTable, {\n excludeGroups,\n includeEmptyCollections: true,\n preferredLocales: options.preferredLocales,\n sortLikeAdminNav: true,\n })\n .filter((group) => collectionSlugs.has(group.groupId))\n .map((group) => group.displayTitle)\n return {\n backupCollections,\n fileKind: parsed.fileKind,\n groups,\n mediaBlobCount: parsed.mediaBlobCount,\n }\n}\n\nexport async function getRestorePreviewForAdminRestore(\n payload: Payload,\n downloadUrl: string,\n options: {\n archivePathname?: string\n backupRead?: { pathname: string; token: string }\n blobAccess?: BackupBlobAccessLevel\n blobToken?: string\n preferredLocales?: string[]\n } = {},\n): Promise<RestorePreviewResponse> {\n const parsed = await loadRestoreBackupIndex(downloadUrl, {\n archivePathname: options.archivePathname,\n blobAccess: options.blobAccess,\n blobToken: options.blobToken,\n readAuth: options.backupRead,\n })\n return buildRestorePreviewGroups(payload, parsed, options)\n}\n"],"names":["readBackupArchiveBytes","resolveArchiveFileReference","getPgDb","loadPgArchive","resolveTableOwners","rootTablesForSlug","AUTH_SESSION_SLUGS","Set","DEFAULT_EXCLUDED_GROUPS","pickLocalizedLabel","labels","preferredLocales","undefined","l","pickField","field","map","loc","v","first","Object","values","find","Boolean","plural","singular","humanizeSlug","slug","split","w","charAt","toUpperCase","slice","join","getNavVisibleCollections","payload","config","collections","filter","c","admin","hidden","navVisibleCollectionOrderIndex","groupId","visible","idx","findIndex","sortPreviewGroupsLikeAdminNav","groups","locale","sort","a","b","ia","ib","displayTitle","localeCompare","buildDisplayTitle","groupSlug","col","glob","globals","g","label","loadRestoreBackupIndex","downloadUrl","options","archiveRef","archivePathname","bytes","backupRead","readAuth","blobAccess","blobToken","archive","countsByTable","name","t","entries","doc","tables","rowCount","fileKind","mediaBlobCount","media","length","mergeConfiguredZeros","counts","excludeGroups","tableNameMap","merged","slugs","has","roots","main","safeTableNameMap","buildCollectionPreviewGroups","includeEmptyCollections","sortLikeAdminNav","owners","keys","aggs","Map","table","count","owner","get","agg","kind","tableNames","push","docCount","tableName","versions","set","authSlugs","auth","total","reasons","add","adminHidden","size","adminHiddenReasons","affectsAuthSession","buildRestorePreviewGroups","parsed","collectionSlugs","collection","backupCollections","group","getRestorePreviewForAdminRestore"],"mappings":"AAEA,SAASA,sBAAsB,EAAEC,2BAA2B,QAAQ,sBAAqB;AAEzF,SAASC,OAAO,QAAQ,OAAM;AAC9B,SAASC,aAAa,QAAQ,cAAa;AAC3C,SAASC,kBAAkB,EAAEC,iBAAiB,QAAQ,gBAAe;AAErE,2EAA2E,GAC3E,MAAMC,qBAAqB,IAAIC,IAAI;IAAC;IAAuB;IAAS;IAAY;CAAQ;AAExF,mEAAmE,GACnE,MAAMC,0BAA0B,IAAID,IAAI;IAAC;IAAkB;CAAe;AA8B1E,SAASE,mBAAmBC,MAAe,EAAEC,gBAA0B;IACrE,IAA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QAAQsB,aAAa,IAAIhF;IAC/C,MAAM+E,SAASD,qBACbnD,SACA0F,OAAOlD,aAAa,EACpBa,eACAO,iBAAiB5D;IAEnB,MAAMa,SAASgD,6BAA6B7D,SAASoD,QAAQ;QAC3DC;QACAS,yBAAyB;QACzBtF,kBAAkBuD,QAAQvD,gBAAgB;QAC1CuF,kBAAkB;IACpB;IACA,MAAM4B,kBAAkB,IAAIvH,IAC1B,AAAC4B,CAAAA,QAAQC,MAAM,CAACC,WAAW,IAAI,EAAE,AAAD,EAAGrB,GAAG,CAAC,CAAC+G,aAAeA,WAAWpG,IAAI;IAExE,MAAMqG,oBAAoBhC,6BAA6B7D,SAAS0F,OAAOlD,aAAa,EAAE;QACpFa;QACAS,yBAAyB;QACzBtF,kBAAkBuD,QAAQvD,gBAAgB;QAC1CuF,kBAAkB;IACpB,GACG5D,MAAM,CAAC,CAAC2F,QAAUH,gBAAgBlC,GAAG,CAACqC,MAAMtF,OAAO,GACnD3B,GAAG,CAAC,CAACiH,QAAUA,MAAM1E,YAAY;IACpC,OAAO;QACLyE;QACA9C,UAAU2C,OAAO3C,QAAQ;QACzBlC;QACAmC,gBAAgB0C,OAAO1C,cAAc;IACvC;AACF;AAEA,OAAO,eAAe+C,iCACpB/F,OAAgB,EAChB8B,WAAmB,EACnBC,UAMI,CAAC,CAAC;IAEN,MAAM2D,SAAS,MAAM7D,uBAAuBC,aAAa;QACvDG,iBAAiBF,QAAQE,eAAe;QACxCI,YAAYN,QAAQM,UAAU;QAC9BC,WAAWP,QAAQO,SAAS;QAC5BF,UAAUL,QAAQI,UAAU;IAC9B;IACA,OAAOsD,0BAA0BzF,SAAS0F,QAAQ3D;AACpD"}
1
+ {"version":3,"sources":["../../src/core/restorePreview.ts"],"sourcesContent":["import type { Payload } from 'payload'\n\nimport { readBackupArchiveBytes, resolveArchiveFileReference } from './backupArchiveRead'\nimport { type BackupBlobAccessLevel } from './backupBlobIO'\nimport { getPgDb } from './db'\nimport { loadPgArchive } from './pgArchive'\nimport {\n BACKUP_INTERNAL_COLLECTION_SLUGS,\n resolveTableOwners,\n rootTablesForSlug,\n} from './tableGroups'\n\n/** Payload slugs whose replacement invalidates the current admin session. */\nconst AUTH_SESSION_SLUGS = new Set(['payload-preferences', 'roles', 'sessions', 'users'])\n\nexport type RestorePreviewFileKind = 'json' | 'tar-gzip'\n\nexport type RestorePreviewAdminHiddenReason = 'collection-config' | 'version-history'\n\nexport type RestorePreviewGroup = {\n adminHidden: boolean\n adminHiddenReasons: RestorePreviewAdminHiddenReason[]\n affectsAuthSession: boolean\n /** e.g. \"Seiten (pages)\" */\n displayTitle: string\n /** Stable id for UI: Payload collection/global slug when known, else the table name. */\n groupId: string\n /** Row count of the root table (one row per document). */\n main?: { docCount: number; tableName: string }\n /** All Postgres tables restored/skipped together when this group is toggled. */\n tableNames: string[]\n /** Row count of the `_<root>_v` versions table. */\n versions?: { docCount: number; tableName: string }\n}\n\nexport type RestorePreviewResponse = {\n /** Localized collection names represented by tables in the archive (excludes globals). */\n backupCollections: string[]\n fileKind: RestorePreviewFileKind\n groups: RestorePreviewGroup[]\n mediaBlobCount: number\n}\n\nfunction pickLocalizedLabel(labels: unknown, preferredLocales: string[]): string | undefined {\n if (!labels || typeof labels !== 'object') {\n return undefined\n }\n const l = labels as { plural?: unknown; singular?: unknown }\n\n const pickField = (field: unknown): string | undefined => {\n if (typeof field === 'string') {\n return field\n }\n if (field && typeof field === 'object') {\n const map = field as Record<string, string>\n for (const loc of preferredLocales) {\n const v = map[loc]\n if (v) {\n return v\n }\n }\n const first = Object.values(map).find(Boolean)\n return first\n }\n return undefined\n }\n\n return pickField(l.plural) || pickField(l.singular)\n}\n\nfunction humanizeSlug(slug: string): string {\n return slug\n .split('-')\n .map((w) => (w ? w.charAt(0).toUpperCase() + w.slice(1) : ''))\n .join(' ')\n}\n\n/** Collections shown in the default Payload admin sidebar: config order, skipping `admin.hidden`. */\nfunction getNavVisibleCollections(payload: Payload) {\n return payload.config.collections.filter((c) => c.admin?.hidden !== true)\n}\n\n/**\n * Index in sidebar order, or `null` if the group is not a visible nav collection\n * (hidden config, unknown table, global, etc.).\n */\nexport function navVisibleCollectionOrderIndex(payload: Payload, groupId: string): null | number {\n const visible = getNavVisibleCollections(payload)\n const idx = visible.findIndex((c) => c.slug === groupId)\n return idx === -1 ? null : idx\n}\n\nfunction sortPreviewGroupsLikeAdminNav(\n payload: Payload,\n groups: RestorePreviewGroup[],\n preferredLocales: string[],\n): void {\n const locale = preferredLocales[0] ?? 'en'\n groups.sort((a, b) => {\n const ia = navVisibleCollectionOrderIndex(payload, a.groupId)\n const ib = navVisibleCollectionOrderIndex(payload, b.groupId)\n if (ia !== null && ib !== null && ia !== ib) {\n return ia - ib\n }\n if (ia !== null && ib === null) {\n return -1\n }\n if (ia === null && ib !== null) {\n return 1\n }\n return a.displayTitle.localeCompare(b.displayTitle, locale)\n })\n}\n\nfunction buildDisplayTitle(\n payload: Payload,\n groupSlug: string,\n preferredLocales: string[],\n): string {\n const col = payload.config.collections.find((c) => c.slug === groupSlug)\n const glob = payload.config.globals?.find((g) => g.slug === groupSlug)\n const label =\n pickLocalizedLabel(col?.labels, preferredLocales) ||\n pickLocalizedLabel(glob ? { singular: glob.label } : undefined, preferredLocales) ||\n humanizeSlug(groupSlug)\n return `${label} (${groupSlug})`\n}\n\nexport async function loadRestoreBackupIndex(\n downloadUrl: string,\n options: {\n archivePathname?: string\n blobAccess?: BackupBlobAccessLevel\n blobToken?: string\n readAuth?: { pathname: string; token: string }\n } = {},\n): Promise<{\n countsByTable: Record<string, number>\n fileKind: RestorePreviewFileKind\n mediaBlobCount: number\n}> {\n const archiveRef = resolveArchiveFileReference(downloadUrl, options.archivePathname)\n const bytes = await readBackupArchiveBytes(downloadUrl, {\n archivePathname: options.archivePathname,\n backupRead: options.readAuth,\n blobAccess: options.blobAccess,\n blobToken: options.blobToken,\n })\n const archive = await loadPgArchive(bytes, archiveRef)\n const countsByTable: Record<string, number> = {}\n for (const [name, t] of Object.entries(archive.doc.tables)) {\n countsByTable[name] = t.rowCount\n }\n return { countsByTable, fileKind: archive.fileKind, mediaBlobCount: archive.media.length }\n}\n\ntype GroupAgg = {\n groupId: string\n kind: 'collection' | 'global' | 'unknown'\n main?: { docCount: number; tableName: string }\n tableNames: string[]\n versions?: { docCount: number; tableName: string }\n}\n\n/** Ensures every configured collection/global appears (0 rows if absent from the backup). */\nfunction mergeConfiguredZeros(\n payload: Payload,\n counts: Record<string, number>,\n excludeGroups: ReadonlySet<string>,\n tableNameMap?: Map<string, string>,\n): Record<string, number> {\n const merged = { ...counts }\n const slugs = [\n ...(payload.config.collections ?? []).map((c) => c.slug),\n ...(payload.config.globals ?? []).map((g) => g.slug),\n ]\n for (const slug of slugs) {\n if (excludeGroups.has(slug)) {\n continue\n }\n const roots = rootTablesForSlug(payload, slug, tableNameMap)\n if (roots && !(roots.main in merged)) {\n merged[roots.main] = 0\n }\n }\n return merged\n}\n\nfunction safeTableNameMap(payload: Payload): Map<string, string> | undefined {\n try {\n return getPgDb(payload).tableNameMap\n } catch {\n return undefined\n }\n}\n\n/** Groups Postgres tables + row counts (live DB or backup file) by Payload collection/global. */\nexport function buildCollectionPreviewGroups(\n payload: Payload,\n countsByTable: Record<string, number>,\n options: {\n /** Payload slugs (or raw table names) to hide. Default: `backup-tasks`. */\n excludeGroups?: ReadonlySet<string>\n /** When true, list groups whose tables are all empty (e.g. manual backup UI). Default false. */\n includeEmptyCollections?: boolean\n preferredLocales?: string[]\n /** When true, order like Payload admin sidebar; unknown / hidden-only groups last by title. */\n sortLikeAdminNav?: boolean\n } = {},\n): RestorePreviewGroup[] {\n const preferredLocales =\n options.preferredLocales?.length ? options.preferredLocales : ['de', 'en']\n const excludeGroups = options.excludeGroups ?? BACKUP_INTERNAL_COLLECTION_SLUGS\n const includeEmptyCollections = options.includeEmptyCollections ?? false\n const sortLikeAdminNav = options.sortLikeAdminNav ?? false\n const tableNameMap = safeTableNameMap(payload)\n\n const owners = resolveTableOwners(payload, Object.keys(countsByTable), tableNameMap)\n const aggs = new Map<string, GroupAgg>()\n for (const [table, count] of Object.entries(countsByTable)) {\n const owner = owners.get(table)!\n if (excludeGroups.has(owner.slug)) {\n continue\n }\n const agg = aggs.get(owner.slug) ?? { groupId: owner.slug, kind: owner.kind, tableNames: [] }\n agg.tableNames.push(table)\n const roots =\n owner.kind === 'unknown' ? null : rootTablesForSlug(payload, owner.slug, tableNameMap)\n if (owner.kind === 'unknown' || table === roots?.main) {\n agg.main = { docCount: count, tableName: table }\n } else if (table === roots?.versions) {\n agg.versions = { docCount: count, tableName: table }\n }\n aggs.set(owner.slug, agg)\n }\n\n const authSlugs = new Set([\n ...(payload.config.collections ?? []).filter((c) => Boolean(c.auth)).map((c) => c.slug),\n ...AUTH_SESSION_SLUGS,\n ])\n\n const groups: RestorePreviewGroup[] = []\n for (const agg of aggs.values()) {\n const total = (agg.main?.docCount ?? 0) + (agg.versions?.docCount ?? 0)\n if (!includeEmptyCollections && total === 0) {\n continue\n }\n const reasons = new Set<RestorePreviewAdminHiddenReason>()\n const col = payload.config.collections?.find((c) => c.slug === agg.groupId)\n if (col?.admin?.hidden === true) {\n reasons.add('collection-config')\n }\n if (!agg.main && agg.versions) {\n reasons.add('version-history')\n }\n groups.push({\n adminHidden: reasons.size > 0,\n adminHiddenReasons: [...reasons],\n affectsAuthSession: authSlugs.has(agg.groupId),\n displayTitle:\n agg.kind === 'unknown' ?\n `${agg.groupId} (table)`\n : buildDisplayTitle(payload, agg.groupId, preferredLocales),\n groupId: agg.groupId,\n main: agg.main,\n tableNames: agg.tableNames.sort(),\n versions: agg.versions,\n })\n }\n\n if (sortLikeAdminNav) {\n sortPreviewGroupsLikeAdminNav(payload, groups, preferredLocales)\n } else {\n const locale = preferredLocales[0] ?? 'en'\n groups.sort((a, b) => a.displayTitle.localeCompare(b.displayTitle, locale))\n }\n return groups\n}\n\nexport function buildRestorePreviewGroups(\n payload: Payload,\n parsed: {\n countsByTable: Record<string, number>\n fileKind: RestorePreviewFileKind\n mediaBlobCount: number\n },\n options: { excludeGroups?: ReadonlySet<string>; preferredLocales?: string[] } = {},\n): RestorePreviewResponse {\n const excludeGroups = options.excludeGroups ?? BACKUP_INTERNAL_COLLECTION_SLUGS\n const counts = mergeConfiguredZeros(\n payload,\n parsed.countsByTable,\n excludeGroups,\n safeTableNameMap(payload),\n )\n const groups = buildCollectionPreviewGroups(payload, counts, {\n excludeGroups,\n includeEmptyCollections: true,\n preferredLocales: options.preferredLocales,\n sortLikeAdminNav: true,\n })\n const collectionSlugs = new Set(\n (payload.config.collections ?? []).map((collection) => collection.slug),\n )\n const backupCollections = buildCollectionPreviewGroups(payload, parsed.countsByTable, {\n excludeGroups,\n includeEmptyCollections: true,\n preferredLocales: options.preferredLocales,\n })\n .filter((group) => collectionSlugs.has(group.groupId))\n .map((group) => group.displayTitle)\n return {\n backupCollections,\n fileKind: parsed.fileKind,\n groups,\n mediaBlobCount: parsed.mediaBlobCount,\n }\n}\n\nexport async function getRestorePreviewForAdminRestore(\n payload: Payload,\n downloadUrl: string,\n options: {\n archivePathname?: string\n backupRead?: { pathname: string; token: string }\n blobAccess?: BackupBlobAccessLevel\n blobToken?: string\n preferredLocales?: string[]\n } = {},\n): Promise<RestorePreviewResponse> {\n const parsed = await loadRestoreBackupIndex(downloadUrl, {\n archivePathname: options.archivePathname,\n blobAccess: options.blobAccess,\n blobToken: options.blobToken,\n readAuth: options.backupRead,\n })\n return buildRestorePreviewGroups(payload, parsed, options)\n}\n"],"names":["readBackupArchiveBytes","resolveArchiveFileReference","getPgDb","loadPgArchive","BACKUP_INTERNAL_COLLECTION_SLUGS","resolveTableOwners","rootTablesForSlug","AUTH_SESSION_SLUGS","Set","pickLocalizedLabel","labels","preferredLocales","undefined","l","pickField","field","map","loc","v","first","Object","values","find","Boolean","plural","singular","humanizeSlug","slug","split","w","charAt","toUpperCase","slice","join","getNavVisibleCollections","payload","config","collections","filter","c","admin","hidden","navVisibleCollectionOrderIndex","groupId","visible","idx","findIndex","sortPreviewGroupsLikeAdminNav","groups","locale","sort","a","b","ia","ib","displayTitle","localeCompare","buildDisplayTitle","groupSlug","col","glob","globals","g","label","loadRestoreBackupIndex","downloadUrl","options","archiveRef","archivePathname","bytes","backupRead","readAuth","blobAccess","blobToken","archive","countsByTable","name","t","entries","doc","tables","rowCount","fileKind","mediaBlobCount","media","length","mergeConfiguredZeros","counts","excludeGroups","tableNameMap","merged","slugs","has","roots","main","safeTableNameMap","buildCollectionPreviewGroups","includeEmptyCollections","sortLikeAdminNav","owners","keys","aggs","Map","table","count","owner","get","agg","kind","tableNames","push","docCount","tableName","versions","set","authSlugs","auth","total","reasons","add","adminHidden","size","adminHiddenReasons","affectsAuthSession","buildRestorePreviewGroups","parsed","collectionSlugs","collection","backupCollections","group","getRestorePreviewForAdminRestore"],"mappings":"AAEA,SAASA,sBAAsB,EAAEC,2BAA2B,QAAQ,sBAAqB;AAEzF,SAASC,OAAO,QAAQ,OAAM;AAC9B,SAASC,aAAa,QAAQ,cAAa;AAC3C,SACEC,gCAAgC,EAChCC,kBAAkB,EAClBC,iBAAiB,QACZ,gBAAe;AAEtB,2EAA2E,GAC3E,MAAMC,qBAAqB,IAAIC,IAAI;IAAC;IAAuB;IAAS;IAAY;CAAQ;AA8BxF,SAASC,mBAAmBC,MAAe,EAAEC,gBAA0B;IACrE,IAAI,CAACD,UAAU,OAAOA,WAAW,UAAU;QACzC,OAAOE;IACT;IACA,MAAMC,IAAIH;IAEV,MAAMI,YAAY,CAACC;QACjB,IAAI,OAAOA,UAAU,UAAU;YAC7B,OAAOA;QACT;QACA,IAAIA,SAAS,OAAOA,UAAU,UAAU;YACtC,MAAMC,MAAMD;YACZ,KAAK,MAAME,OAAON,iBAAkB;gBAClC,MAAMO,IAAIF,GAAG,CAACC,IAAI;gBAClB,IAAIC,GAAG;oBACL,OAAOA;gBACT;YACF;YACA,MAAMC,QAAQC,OAAOC,MAAM,CAACL,KAAKM,IAAI,CAACC;YACtC,OAAOJ;QACT;QACA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6B7D,SAAS0F,OAAOlD,aAAa,EAAE;QACpFa;QACAS,yBAAyB;QACzBtF,kBAAkBuD,QAAQvD,gBAAgB;IAC5C,GACG2B,MAAM,CAAC,CAAC2F,QAAUH,gBAAgBlC,GAAG,CAACqC,MAAMtF,OAAO,GACnD3B,GAAG,CAAC,CAACiH,QAAUA,MAAM1E,YAAY;IACpC,OAAO;QACLyE;QACA9C,UAAU2C,OAAO3C,QAAQ;QACzBlC;QACAmC,gBAAgB0C,OAAO1C,cAAc;IACvC;AACF;AAEA,OAAO,eAAe+C,iCACpB/F,OAAgB,EAChB8B,WAAmB,EACnBC,UAMI,CAAC,CAAC;IAEN,MAAM2D,SAAS,MAAM7D,uBAAuBC,aAAa;QACvDG,iBAAiBF,QAAQE,eAAe;QACxCI,YAAYN,QAAQM,UAAU;QAC9BC,WAAWP,QAAQO,SAAS;QAC5BF,UAAUL,QAAQI,UAAU;IAC9B;IACA,OAAOsD,0BAA0BzF,SAAS0F,QAAQ3D;AACpD"}
@@ -13,9 +13,15 @@ export type TableOwner = {
13
13
  /** True when the table belongs to the `_<root>_v` version-history family. */
14
14
  versions: boolean;
15
15
  };
16
+ export declare const BACKUP_INTERNAL_COLLECTION_SLUGS: ReadonlySet<string>;
16
17
  /** Mirrors Payload's `toSnakeCase` for slugs (`my-posts` / `myPosts` → `my_posts`). */
17
18
  export declare function slugToSnake(slug: string): string;
18
19
  export declare function resolveTableOwners(payload: Payload, tables: string[], tableNameMap?: Map<string, string>): Map<string, TableOwner>;
20
+ /** Counts represented Payload collections, not their physical PostgreSQL tables. */
21
+ export declare function countCollectionGroups(payload: Payload, tables: string[], options?: {
22
+ excludeSlugs?: ReadonlySet<string>;
23
+ tableNameMap?: Map<string, string>;
24
+ }): number;
19
25
  /** Main + version root table names for a slug (used for row counts in the UI). */
20
26
  export declare function rootTablesForSlug(payload: Payload, slug: string, tableNameMap?: Map<string, string>): {
21
27
  main: string;
@@ -1,3 +1,7 @@
1
+ export const BACKUP_INTERNAL_COLLECTION_SLUGS = new Set([
2
+ 'backup-numbers',
3
+ 'backup-tasks'
4
+ ]);
1
5
  /** Mirrors Payload's `toSnakeCase` for slugs (`my-posts` / `myPosts` → `my_posts`). */ export function slugToSnake(slug) {
2
6
  return slug.replace(/([a-z0-9])([A-Z])/g, '$1_$2').replace(/[-\s]+/g, '_').toLowerCase();
3
7
  }
@@ -60,6 +64,13 @@ export function resolveTableOwners(payload, tables, tableNameMap) {
60
64
  }
61
65
  return out;
62
66
  }
67
+ /** Counts represented Payload collections, not their physical PostgreSQL tables. */ export function countCollectionGroups(payload, tables, options = {}) {
68
+ const collectionSlugs = new Set((payload.config.collections ?? []).map((collection)=>collection.slug));
69
+ const owners = resolveTableOwners(payload, tables, options.tableNameMap);
70
+ return new Set([
71
+ ...owners.values()
72
+ ].filter((owner)=>owner.kind === 'collection' && collectionSlugs.has(owner.slug) && !options.excludeSlugs?.has(owner.slug)).map((owner)=>owner.slug)).size;
73
+ }
63
74
  /** Main + version root table names for a slug (used for row counts in the UI). */ export function rootTablesForSlug(payload, slug, tableNameMap) {
64
75
  const entity = payload.config.collections?.find((c)=>c.slug === slug) ?? payload.config.globals?.find((g)=>g.slug === slug);
65
76
  if (!entity) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/core/tableGroups.ts"],"sourcesContent":["import type { Payload } from 'payload'\n\n/**\n * Payload's Postgres adapter spreads one collection/global over several tables:\n * `posts`, `posts_rels`, `posts_locales`, `posts_blocks_hero`, … (main data)\n * `_posts_v`, `_posts_v_rels`, … (version history)\n * This module maps physical tables back to the owning Payload slug so the admin UI can\n * keep showing one checkbox per collection, like the MongoDB plugin.\n */\n\nexport type TableOwner = {\n kind: 'collection' | 'global' | 'unknown'\n /** Collection/global slug, or the table name for tables not owned by Payload config. */\n slug: string\n /** True when the table belongs to the `_<root>_v` version-history family. */\n versions: boolean\n}\n\ntype Root = { kind: 'collection' | 'global'; root: string; slug: string; versions: boolean }\n\n/** Mirrors Payload's `toSnakeCase` for slugs (`my-posts` / `myPosts` → `my_posts`). */\nexport function slugToSnake(slug: string): string {\n return slug\n .replace(/([a-z0-9])([A-Z])/g, '$1_$2')\n .replace(/[-\\s]+/g, '_')\n .toLowerCase()\n}\n\nfunction rootTableName(\n entity: { dbName?: unknown; slug: string },\n tableNameMap?: Map<string, string>,\n): string {\n if (typeof entity.dbName === 'string' && entity.dbName) {\n return entity.dbName\n }\n const snake = slugToSnake(entity.slug)\n return tableNameMap?.get(snake) ?? snake\n}\n\nfunction collectRoots(payload: Payload, tableNameMap?: Map<string, string>): Root[] {\n const roots: Root[] = []\n for (const c of payload.config.collections ?? []) {\n const root = rootTableName(c as { dbName?: unknown; slug: string }, tableNameMap)\n roots.push({ slug: c.slug, kind: 'collection', root, versions: false })\n roots.push({ slug: c.slug, kind: 'collection', root: `_${root}_v`, versions: true })\n }\n for (const g of payload.config.globals ?? []) {\n const root = rootTableName(g as { dbName?: unknown; slug: string }, tableNameMap)\n roots.push({ slug: g.slug, kind: 'global', root, versions: false })\n roots.push({ slug: g.slug, kind: 'global', root: `_${root}_v`, versions: true })\n }\n // Longest root first so `media_folders` wins over `media` for `media_folders_rels`.\n return roots.sort((a, b) => b.root.length - a.root.length)\n}\n\nexport function resolveTableOwners(\n payload: Payload,\n tables: string[],\n tableNameMap?: Map<string, string>,\n): Map<string, TableOwner> {\n const roots = collectRoots(payload, tableNameMap)\n const out = new Map<string, TableOwner>()\n for (const t of tables) {\n const hit = roots.find((r) => t === r.root || t.startsWith(`${r.root}_`))\n out.set(\n t,\n hit ?\n { slug: hit.slug, kind: hit.kind, versions: hit.versions }\n : { slug: t, kind: 'unknown', versions: false },\n )\n }\n return out\n}\n\n/** Main + version root table names for a slug (used for row counts in the UI). */\nexport function rootTablesForSlug(\n payload: Payload,\n slug: string,\n tableNameMap?: Map<string, string>,\n): { main: string; versions: string } | null {\n const entity =\n payload.config.collections?.find((c) => c.slug === slug) ??\n payload.config.globals?.find((g) => g.slug === slug)\n if (!entity) {\n return null\n }\n const root = rootTableName(entity as { dbName?: unknown; slug: string }, tableNameMap)\n return { main: root, versions: `_${root}_v` }\n}\n\n/** All tables (from `tables`) that belong to the given slugs. */\nexport function tablesForSlugs(\n payload: Payload,\n slugs: string[],\n tables: string[],\n tableNameMap?: Map<string, string>,\n): string[] {\n const wanted = new Set(slugs)\n const owners = resolveTableOwners(payload, tables, tableNameMap)\n return tables.filter((t) => wanted.has(owners.get(t)!.slug))\n}\n"],"names":["slugToSnake","slug","replace","toLowerCase","rootTableName","entity","tableNameMap","dbName","snake","get","collectRoots","payload","roots","c","config","collections","root","push","kind","versions","g","globals","sort","a","b","length","resolveTableOwners","tables","out","Map","t","hit","find","r","startsWith","set","rootTablesForSlug","main","tablesForSlugs","slugs","wanted","Set","owners","filter","has"],"mappings":"AAoBA,qFAAqF,GACrF,OAAO,SAASA,YAAYC,IAAY;IACtC,OAAOA,KACJC,OAAO,CAAC,sBAAsB,SAC9BA,OAAO,CAAC,WAAW,KACnBC,WAAW;AAChB;AAEA,SAASC,cACPC,MAA0C,EAC1CC,YAAkC;IAElC,IAAI,OAAOD,OAAOE,MAAM,KAAK,YAAYF,OAAOE,MAAM,EAAE;QACtD,OAAOF,OAAOE,MAAM;IACtB;IACA,MAAMC,QAAQR,YAAYK,OAAOJ,IAAI;IACrC,OAAOK,cAAcG,IAAID,UAAUA;AACrC;AAEA,SAASE,aAAaC,OAAgB,EAAEL,YAAkC;IACxE,MAAMM,QAAgB,EAAE;IACxB,KAAK,MAAMC,KAAKF,QAAQG,MAAM,CAACC,WAAW,IAAI,EAAE,CAAE;QAChD,MAAMC,OAAOZ,cAAcS,GAAyCP;QACpEM,MAAMK,IAAI,CAAC;YAAEhB,MAAMY,EAAEZ,IAAI;YAAEiB,MAAM;YAAcF;YAAMG,UAAU;QAAM;QACrEP,MAAMK,IAAI,CAAC;YAAEhB,MAAMY,EAAEZ,IAAI;YAAEiB,MAAM;YAAcF,MAAM,CAAC,CAAC,EAAEA,KAAK,EAAE,CAAC;Y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KAAK,CAACZ,IAAMA,EAAEnB,IAAI,KAAKA;IACjD,IAAI,CAACI,QAAQ;QACX,OAAO;IACT;IACA,MAAMW,OAAOZ,cAAcC,QAA8CC;IACzE,OAAO;QAAE+B,MAAMrB;QAAMG,UAAU,CAAC,CAAC,EAAEH,KAAK,EAAE,CAAC;IAAC;AAC9C;AAEA,+DAA+D,GAC/D,OAAO,SAASsB,eACd3B,OAAgB,EAChB4B,KAAe,EACfZ,MAAgB,EAChBrB,YAAkC;IAElC,MAAMkC,SAAS,IAAIC,IAAIF;IACvB,MAAMG,SAAShB,mBAAmBf,SAASgB,QAAQrB;IACnD,OAAOqB,OAAOgB,MAAM,CAAC,CAACb,IAAMU,OAAOI,GAAG,CAACF,OAAOjC,GAAG,CAACqB,GAAI7B,IAAI;AAC5D"}
1
+ {"version":3,"sources":["../../src/core/tableGroups.ts"],"sourcesContent":["import type { Payload } from 'payload'\n\n/**\n * Payload's Postgres adapter spreads one collection/global over several tables:\n * `posts`, `posts_rels`, `posts_locales`, `posts_blocks_hero`, … (main data)\n * `_posts_v`, `_posts_v_rels`, … (version history)\n * This module maps physical tables back to the owning Payload slug so the admin UI can\n * keep showing one checkbox per collection, like the MongoDB plugin.\n */\n\nexport type TableOwner = {\n kind: 'collection' | 'global' | 'unknown'\n /** Collection/global slug, or the table name for tables not owned by Payload config. */\n slug: string\n /** True when the table belongs to the `_<root>_v` version-history family. */\n versions: boolean\n}\n\ntype Root = { kind: 'collection' | 'global'; root: string; slug: string; versions: boolean }\n\nexport const BACKUP_INTERNAL_COLLECTION_SLUGS: ReadonlySet<string> = new Set([\n 'backup-numbers',\n 'backup-tasks',\n])\n\n/** Mirrors Payload's `toSnakeCase` for slugs (`my-posts` / `myPosts` → `my_posts`). */\nexport function slugToSnake(slug: string): string {\n return slug\n .replace(/([a-z0-9])([A-Z])/g, '$1_$2')\n .replace(/[-\\s]+/g, '_')\n .toLowerCase()\n}\n\nfunction rootTableName(\n entity: { dbName?: unknown; slug: string },\n tableNameMap?: Map<string, string>,\n): string {\n if (typeof entity.dbName === 'string' && entity.dbName) {\n return entity.dbName\n }\n const snake = slugToSnake(entity.slug)\n return tableNameMap?.get(snake) ?? snake\n}\n\nfunction collectRoots(payload: Payload, tableNameMap?: Map<string, string>): Root[] {\n const roots: Root[] = []\n for (const c of payload.config.collections ?? []) {\n const root = rootTableName(c as { dbName?: unknown; slug: string }, tableNameMap)\n roots.push({ slug: c.slug, kind: 'collection', root, versions: false })\n roots.push({ slug: c.slug, kind: 'collection', root: `_${root}_v`, versions: true })\n }\n for (const g of payload.config.globals ?? []) {\n const root = rootTableName(g as { dbName?: unknown; slug: string }, tableNameMap)\n roots.push({ slug: g.slug, kind: 'global', root, versions: false })\n roots.push({ slug: g.slug, kind: 'global', root: `_${root}_v`, versions: true })\n }\n // Longest root first so `media_folders` wins over `media` for `media_folders_rels`.\n return roots.sort((a, b) => b.root.length - a.root.length)\n}\n\nexport function resolveTableOwners(\n payload: Payload,\n tables: string[],\n tableNameMap?: Map<string, string>,\n): Map<string, TableOwner> {\n const roots = collectRoots(payload, tableNameMap)\n const out = new Map<string, TableOwner>()\n for (const t of tables) {\n const hit = roots.find((r) => t === r.root || t.startsWith(`${r.root}_`))\n out.set(\n t,\n hit ?\n { slug: hit.slug, kind: hit.kind, versions: hit.versions }\n : { slug: t, kind: 'unknown', versions: false },\n )\n }\n return out\n}\n\n/** Counts represented Payload collections, not their physical PostgreSQL tables. */\nexport function countCollectionGroups(\n payload: Payload,\n tables: string[],\n options: { excludeSlugs?: ReadonlySet<string>; tableNameMap?: Map<string, string> } = {},\n): number {\n const collectionSlugs = new Set(\n (payload.config.collections ?? []).map((collection) => collection.slug),\n )\n const owners = resolveTableOwners(payload, tables, options.tableNameMap)\n return new Set(\n [...owners.values()]\n .filter(\n (owner) =>\n owner.kind === 'collection' &&\n collectionSlugs.has(owner.slug) &&\n !options.excludeSlugs?.has(owner.slug),\n )\n .map((owner) => owner.slug),\n ).size\n}\n\n/** Main + version root table names for a slug (used for row counts in the UI). */\nexport function rootTablesForSlug(\n payload: Payload,\n slug: string,\n tableNameMap?: Map<string, string>,\n): { main: string; versions: string } | null {\n const entity =\n payload.config.collections?.find((c) => c.slug === slug) ??\n payload.config.globals?.find((g) => g.slug === slug)\n if (!entity) {\n return null\n }\n const root = rootTableName(entity as { dbName?: unknown; slug: string }, tableNameMap)\n return { main: root, versions: `_${root}_v` }\n}\n\n/** All tables (from `tables`) that belong to the given slugs. */\nexport function tablesForSlugs(\n payload: Payload,\n slugs: string[],\n tables: string[],\n tableNameMap?: Map<string, string>,\n): string[] {\n const wanted = new Set(slugs)\n const owners = resolveTableOwners(payload, tables, tableNameMap)\n return tables.filter((t) => wanted.has(owners.get(t)!.slug))\n}\n"],"names":["BACKUP_INTERNAL_COLLECTION_SLUGS","Set","slugToSnake","slug","replace","toLowerCase","rootTableName","entity","tableNameMap","dbName","snake","get","collectRoots","payload","roots","c","config","collections","root","push","kind","versions","g","globals","sort","a","b","length","resolveTableOwners","tables","out","Map","t","hit","find","r","startsWith","set","countCollectionGroups","options","collectionSlugs","map","collection","owners","values","filter","owner","has","excludeSlugs","size","rootTablesForSlug","main","tablesForSlugs","slugs","wanted"],"mappings":"AAoBA,OAAO,MAAMA,mCAAwD,IAAIC,IAAI;IAC3E;IACA;CACD,EAAC;AAEF,qFAAqF,GACrF,OAAO,SAASC,YAAYC,IAAY;IACtC,OAAOA,KACJC,OAAO,CAAC,sBAAsB,SAC9BA,OAAO,CAAC,WAAW,KACnBC,WAAW;AAChB;AAEA,SAASC,cACPC,MAA0C,EAC1CC,YAAkC;IAElC,IAAI,OAAOD,OAAOE,MAAM,KAAK,YAAYF,OAAOE,MAAM,EAAE;QACtD,OAAOF,OAAOE,MAAM;IACtB;IACA,MAAMC,QAAQR,YAAYK,OAAOJ,IAAI;IACrC,OAAOK,cAAcG,IAAID,UAAUA;AACrC;AAEA,SAASE,aAAaC,OAAgB,EAAEL,YAAkC;IACxE,MAAMM,QAAgB,EAAE;IAC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vB,MAAMV,SAASf,mBAAmBf,SAASgB,QAAQrB;IACnD,OAAOqB,OAAOgB,MAAM,CAAC,CAACb,IAAMsB,OAAOP,GAAG,CAACJ,OAAOhC,GAAG,CAACqB,GAAI7B,IAAI;AAC5D"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "payload-plugin-backup-postgres",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "Payload CMS plugin for PostgreSQL backup and recovery via Vercel Blob or AWS S3 (S3-compatible: R2, MinIO)",
5
5
  "keywords": [
6
6
  "payload",