payload-plugin-backup-postgres 0.0.0-stage → 0.1.0

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.
Files changed (187) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +355 -2
  3. package/dist/backup-dashboard.css +1149 -0
  4. package/dist/client.d.ts +3 -0
  5. package/dist/client.js +3 -0
  6. package/dist/client.js.map +1 -0
  7. package/dist/collections/BackupSettings.d.ts +6 -0
  8. package/dist/collections/BackupSettings.js +91 -0
  9. package/dist/collections/BackupSettings.js.map +1 -0
  10. package/dist/collections/BackupTasks.d.ts +2 -0
  11. package/dist/collections/BackupTasks.js +63 -0
  12. package/dist/collections/BackupTasks.js.map +1 -0
  13. package/dist/components/BackupDashboard/BackupItemActions.client.d.ts +7 -0
  14. package/dist/components/BackupDashboard/BackupItemActions.client.js +90 -0
  15. package/dist/components/BackupDashboard/BackupItemActions.client.js.map +1 -0
  16. package/dist/components/BackupDashboard/BackupListCollapsible.client.d.ts +16 -0
  17. package/dist/components/BackupDashboard/BackupListCollapsible.client.js +597 -0
  18. package/dist/components/BackupDashboard/BackupListCollapsible.client.js.map +1 -0
  19. package/dist/components/BackupDashboard/BackupSettingsModal.client.d.ts +2 -0
  20. package/dist/components/BackupDashboard/BackupSettingsModal.client.js +1027 -0
  21. package/dist/components/BackupDashboard/BackupSettingsModal.client.js.map +1 -0
  22. package/dist/components/BackupDashboard/CollectionBackupPreviewBody.client.d.ts +18 -0
  23. package/dist/components/BackupDashboard/CollectionBackupPreviewBody.client.js +267 -0
  24. package/dist/components/BackupDashboard/CollectionBackupPreviewBody.client.js.map +1 -0
  25. package/dist/components/BackupDashboard/ManualBackupDialog.client.d.ts +1 -0
  26. package/dist/components/BackupDashboard/ManualBackupDialog.client.js +276 -0
  27. package/dist/components/BackupDashboard/ManualBackupDialog.client.js.map +1 -0
  28. package/dist/components/BackupDashboard/RestoreBackupDialog.client.d.ts +6 -0
  29. package/dist/components/BackupDashboard/RestoreBackupDialog.client.js +551 -0
  30. package/dist/components/BackupDashboard/RestoreBackupDialog.client.js.map +1 -0
  31. package/dist/components/BackupDashboard/TaskActionButton.client.d.ts +29 -0
  32. package/dist/components/BackupDashboard/TaskActionButton.client.js +273 -0
  33. package/dist/components/BackupDashboard/TaskActionButton.client.js.map +1 -0
  34. package/dist/components/BackupDashboard/backupDashboardInlineCss.d.ts +1 -0
  35. package/dist/components/BackupDashboard/backupDashboardInlineCss.js +3 -0
  36. package/dist/components/BackupDashboard/backupDashboardInlineCss.js.map +1 -0
  37. package/dist/components/BackupDashboard/index.client.d.ts +8 -0
  38. package/dist/components/BackupDashboard/index.client.js +9 -0
  39. package/dist/components/BackupDashboard/index.client.js.map +1 -0
  40. package/dist/components/BackupDashboard/index.d.ts +15 -0
  41. package/dist/components/BackupDashboard/index.js +246 -0
  42. package/dist/components/BackupDashboard/index.js.map +1 -0
  43. package/dist/core/archive.d.ts +8 -0
  44. package/dist/core/archive.js +47 -0
  45. package/dist/core/archive.js.map +1 -0
  46. package/dist/core/backup.d.ts +54 -0
  47. package/dist/core/backup.js +282 -0
  48. package/dist/core/backup.js.map +1 -0
  49. package/dist/core/backupArchiveRead.d.ts +15 -0
  50. package/dist/core/backupArchiveRead.js +30 -0
  51. package/dist/core/backupArchiveRead.js.map +1 -0
  52. package/dist/core/backupBlobIO.d.ts +54 -0
  53. package/dist/core/backupBlobIO.js +179 -0
  54. package/dist/core/backupBlobIO.js.map +1 -0
  55. package/dist/core/backupBlobTransfer.d.ts +29 -0
  56. package/dist/core/backupBlobTransfer.js +85 -0
  57. package/dist/core/backupBlobTransfer.js.map +1 -0
  58. package/dist/core/backupSettings.d.ts +35 -0
  59. package/dist/core/backupSettings.js +100 -0
  60. package/dist/core/backupSettings.js.map +1 -0
  61. package/dist/core/backupSourcePreview.d.ts +10 -0
  62. package/dist/core/backupSourcePreview.js +46 -0
  63. package/dist/core/backupSourcePreview.js.map +1 -0
  64. package/dist/core/blobTokenValidate.d.ts +14 -0
  65. package/dist/core/blobTokenValidate.js +75 -0
  66. package/dist/core/blobTokenValidate.js.map +1 -0
  67. package/dist/core/db.d.ts +56 -0
  68. package/dist/core/db.js +161 -0
  69. package/dist/core/db.js.map +1 -0
  70. package/dist/core/pgArchive.d.ts +37 -0
  71. package/dist/core/pgArchive.js +57 -0
  72. package/dist/core/pgArchive.js.map +1 -0
  73. package/dist/core/restore.d.ts +46 -0
  74. package/dist/core/restore.js +439 -0
  75. package/dist/core/restore.js.map +1 -0
  76. package/dist/core/restorePreview.d.ts +76 -0
  77. package/dist/core/restorePreview.js +222 -0
  78. package/dist/core/restorePreview.js.map +1 -0
  79. package/dist/core/restoreResult.d.ts +34 -0
  80. package/dist/core/restoreResult.js +45 -0
  81. package/dist/core/restoreResult.js.map +1 -0
  82. package/dist/core/storage/config.d.ts +31 -0
  83. package/dist/core/storage/config.js +60 -0
  84. package/dist/core/storage/config.js.map +1 -0
  85. package/dist/core/storage/index.d.ts +23 -0
  86. package/dist/core/storage/index.js +25 -0
  87. package/dist/core/storage/index.js.map +1 -0
  88. package/dist/core/storage/s3.d.ts +35 -0
  89. package/dist/core/storage/s3.js +200 -0
  90. package/dist/core/storage/s3.js.map +1 -0
  91. package/dist/core/storage/types.d.ts +60 -0
  92. package/dist/core/storage/types.js +6 -0
  93. package/dist/core/storage/types.js.map +1 -0
  94. package/dist/core/storage/vercelBlob.d.ts +25 -0
  95. package/dist/core/storage/vercelBlob.js +53 -0
  96. package/dist/core/storage/vercelBlob.js.map +1 -0
  97. package/dist/core/tableGroups.d.ts +25 -0
  98. package/dist/core/tableGroups.js +80 -0
  99. package/dist/core/tableGroups.js.map +1 -0
  100. package/dist/core/taskProgress.d.ts +39 -0
  101. package/dist/core/taskProgress.js +104 -0
  102. package/dist/core/taskProgress.js.map +1 -0
  103. package/dist/core/vercelBackupCron.d.ts +8 -0
  104. package/dist/core/vercelBackupCron.js +38 -0
  105. package/dist/core/vercelBackupCron.js.map +1 -0
  106. package/dist/endpoints/index.d.ts +3 -0
  107. package/dist/endpoints/index.js +29 -0
  108. package/dist/endpoints/index.js.map +1 -0
  109. package/dist/endpoints/paths/admin-backup-download.d.ts +8 -0
  110. package/dist/endpoints/paths/admin-backup-download.js +73 -0
  111. package/dist/endpoints/paths/admin-backup-download.js.map +1 -0
  112. package/dist/endpoints/paths/admin-delete.d.ts +3 -0
  113. package/dist/endpoints/paths/admin-delete.js +61 -0
  114. package/dist/endpoints/paths/admin-delete.js.map +1 -0
  115. package/dist/endpoints/paths/admin-manual.d.ts +3 -0
  116. package/dist/endpoints/paths/admin-manual.js +62 -0
  117. package/dist/endpoints/paths/admin-manual.js.map +1 -0
  118. package/dist/endpoints/paths/admin-preview.d.ts +6 -0
  119. package/dist/endpoints/paths/admin-preview.js +109 -0
  120. package/dist/endpoints/paths/admin-preview.js.map +1 -0
  121. package/dist/endpoints/paths/admin-restore.d.ts +3 -0
  122. package/dist/endpoints/paths/admin-restore.js +77 -0
  123. package/dist/endpoints/paths/admin-restore.js.map +1 -0
  124. package/dist/endpoints/paths/admin-settings.d.ts +3 -0
  125. package/dist/endpoints/paths/admin-settings.js +263 -0
  126. package/dist/endpoints/paths/admin-settings.js.map +1 -0
  127. package/dist/endpoints/paths/admin-task.d.ts +3 -0
  128. package/dist/endpoints/paths/admin-task.js +34 -0
  129. package/dist/endpoints/paths/admin-task.js.map +1 -0
  130. package/dist/endpoints/paths/admin-validate-blob-token.d.ts +8 -0
  131. package/dist/endpoints/paths/admin-validate-blob-token.js +26 -0
  132. package/dist/endpoints/paths/admin-validate-blob-token.js.map +1 -0
  133. package/dist/endpoints/paths/cron-list.d.ts +2 -0
  134. package/dist/endpoints/paths/cron-list.js +34 -0
  135. package/dist/endpoints/paths/cron-list.js.map +1 -0
  136. package/dist/endpoints/paths/cron-restore.d.ts +2 -0
  137. package/dist/endpoints/paths/cron-restore.js +71 -0
  138. package/dist/endpoints/paths/cron-restore.js.map +1 -0
  139. package/dist/endpoints/paths/cron-run.d.ts +3 -0
  140. package/dist/endpoints/paths/cron-run.js +46 -0
  141. package/dist/endpoints/paths/cron-run.js.map +1 -0
  142. package/dist/endpoints/shared.d.ts +12 -0
  143. package/dist/endpoints/shared.js +52 -0
  144. package/dist/endpoints/shared.js.map +1 -0
  145. package/dist/exports/client.d.ts +1 -0
  146. package/dist/exports/client.js +3 -0
  147. package/dist/exports/client.js.map +1 -0
  148. package/dist/exports/rsc.d.ts +1 -0
  149. package/dist/exports/rsc.js +3 -0
  150. package/dist/exports/rsc.js.map +1 -0
  151. package/dist/index.d.ts +25 -0
  152. package/dist/index.js +18 -0
  153. package/dist/index.js.map +1 -0
  154. package/dist/plugin.d.ts +3 -0
  155. package/dist/plugin.js +69 -0
  156. package/dist/plugin.js.map +1 -0
  157. package/dist/publicApiPaths.d.ts +18 -0
  158. package/dist/publicApiPaths.js +19 -0
  159. package/dist/publicApiPaths.js.map +1 -0
  160. package/dist/types.d.ts +16 -0
  161. package/dist/types.js +3 -0
  162. package/dist/types.js.map +1 -0
  163. package/dist/utils/backupSelection.d.ts +6 -0
  164. package/dist/utils/backupSelection.js +16 -0
  165. package/dist/utils/backupSelection.js.map +1 -0
  166. package/dist/utils/blobName.d.ts +32 -0
  167. package/dist/utils/blobName.js +99 -0
  168. package/dist/utils/blobName.js.map +1 -0
  169. package/dist/utils/dashboardRoleAccess.d.ts +23 -0
  170. package/dist/utils/dashboardRoleAccess.js +64 -0
  171. package/dist/utils/dashboardRoleAccess.js.map +1 -0
  172. package/dist/utils/dialogBackdrop.d.ts +9 -0
  173. package/dist/utils/dialogBackdrop.js +17 -0
  174. package/dist/utils/dialogBackdrop.js.map +1 -0
  175. package/dist/utils/formatBytes.d.ts +2 -0
  176. package/dist/utils/formatBytes.js +20 -0
  177. package/dist/utils/formatBytes.js.map +1 -0
  178. package/dist/utils/hostname.d.ts +4 -0
  179. package/dist/utils/hostname.js +32 -0
  180. package/dist/utils/hostname.js.map +1 -0
  181. package/dist/utils/index.d.ts +5 -0
  182. package/dist/utils/index.js +7 -0
  183. package/dist/utils/index.js.map +1 -0
  184. package/dist/utils/maskBlobToken.d.ts +11 -0
  185. package/dist/utils/maskBlobToken.js +42 -0
  186. package/dist/utils/maskBlobToken.js.map +1 -0
  187. package/package.json +140 -3
@@ -0,0 +1,200 @@
1
+ /** Presigned download URLs are valid this long — long enough to start a restore/download. */ const SIGNED_URL_TTL_SECONDS = 3600;
2
+ function contentTypeFor(pathname) {
3
+ if (pathname.endsWith('.json')) {
4
+ return 'application/json';
5
+ }
6
+ if (pathname.endsWith('.gz') || pathname.endsWith('.tar.gz')) {
7
+ return 'application/gzip';
8
+ }
9
+ return 'application/octet-stream';
10
+ }
11
+ /**
12
+ * AWS S3 backup target. The same implementation serves any S3-compatible store (Cloudflare R2,
13
+ * MinIO, …) — only the `endpoint`/`forcePathStyle` config differs, never the code. The AWS SDK is
14
+ * loaded lazily via dynamic import so it stays an optional dependency for Vercel-only installs.
15
+ */ export class S3BackupStorage {
16
+ cfg;
17
+ clientPromise = null;
18
+ presignerPromise = null;
19
+ kind = 's3';
20
+ constructor(cfg){
21
+ this.cfg = cfg;
22
+ }
23
+ async buildClient() {
24
+ const { S3Client } = await this.sdk();
25
+ const { accessKeyId, secretAccessKey, sessionToken } = this.cfg;
26
+ return new S3Client({
27
+ ...this.cfg.endpoint ? {
28
+ endpoint: this.cfg.endpoint
29
+ } : {},
30
+ forcePathStyle: this.cfg.forcePathStyle,
31
+ region: this.cfg.region,
32
+ // When keys are absent, fall back to the SDK's default credential provider chain
33
+ // (env vars, shared config, instance/role credentials).
34
+ ...accessKeyId && secretAccessKey ? {
35
+ credentials: {
36
+ accessKeyId,
37
+ secretAccessKey,
38
+ sessionToken
39
+ }
40
+ } : {}
41
+ });
42
+ }
43
+ async client() {
44
+ if (!this.clientPromise) {
45
+ this.clientPromise = this.buildClient();
46
+ }
47
+ return this.clientPromise;
48
+ }
49
+ /** Strip the configured key prefix, returning the provider-agnostic `backups/...` pathname. */ fromKey(key) {
50
+ if (!this.cfg.prefix) {
51
+ return key;
52
+ }
53
+ const lead = `${this.cfg.prefix}/`;
54
+ return key.startsWith(lead) ? key.slice(lead.length) : key;
55
+ }
56
+ async presigner() {
57
+ if (!this.presignerPromise) {
58
+ this.presignerPromise = import('@aws-sdk/s3-request-presigner');
59
+ }
60
+ return this.presignerPromise;
61
+ }
62
+ async presignGet(key) {
63
+ const { GetObjectCommand } = await this.sdk();
64
+ const { getSignedUrl } = await this.presigner();
65
+ const client = await this.client();
66
+ return getSignedUrl(client, new GetObjectCommand({
67
+ Bucket: this.cfg.bucket,
68
+ Key: key
69
+ }), {
70
+ expiresIn: SIGNED_URL_TTL_SECONDS
71
+ });
72
+ }
73
+ async sdk() {
74
+ try {
75
+ return await import('@aws-sdk/client-s3');
76
+ } catch {
77
+ throw new Error('BACKUP_STORAGE=s3 requires the AWS SDK. Install it with: ' + 'pnpm add @aws-sdk/client-s3 @aws-sdk/lib-storage @aws-sdk/s3-request-presigner');
78
+ }
79
+ }
80
+ /** Prepend the configured key prefix to a provider-agnostic `backups/...` pathname. */ toKey(pathname) {
81
+ return this.cfg.prefix ? `${this.cfg.prefix}/${pathname}` : pathname;
82
+ }
83
+ async del(ref) {
84
+ const { DeleteObjectCommand } = await this.sdk();
85
+ const client = await this.client();
86
+ await client.send(new DeleteObjectCommand({
87
+ Bucket: this.cfg.bucket,
88
+ Key: this.toKey(ref.pathname)
89
+ }));
90
+ }
91
+ async list(prefix) {
92
+ const { ListObjectsV2Command } = await this.sdk();
93
+ const client = await this.client();
94
+ const keyPrefix = this.toKey(prefix);
95
+ const objects = [];
96
+ let continuationToken;
97
+ do {
98
+ const res = await client.send(new ListObjectsV2Command({
99
+ Bucket: this.cfg.bucket,
100
+ ContinuationToken: continuationToken,
101
+ Prefix: keyPrefix
102
+ }));
103
+ const pageEntries = [];
104
+ for (const obj of res.Contents ?? []){
105
+ if (!obj.Key) {
106
+ continue;
107
+ }
108
+ pageEntries.push({
109
+ key: obj.Key,
110
+ pathname: this.fromKey(obj.Key),
111
+ size: obj.Size ?? 0,
112
+ uploadedAt: obj.LastModified ?? new Date(0)
113
+ });
114
+ }
115
+ const signed = await Promise.all(pageEntries.map(async (entry)=>{
116
+ const url = await this.presignGet(entry.key);
117
+ return {
118
+ downloadUrl: url,
119
+ pathname: entry.pathname,
120
+ size: entry.size,
121
+ uploadedAt: entry.uploadedAt,
122
+ url
123
+ };
124
+ }));
125
+ objects.push(...signed);
126
+ continuationToken = res.IsTruncated ? res.NextContinuationToken : undefined;
127
+ }while (continuationToken)
128
+ return objects;
129
+ }
130
+ async openDownloadStream(ref) {
131
+ const { GetObjectCommand } = await this.sdk();
132
+ const client = await this.client();
133
+ try {
134
+ const res = await client.send(new GetObjectCommand({
135
+ Bucket: this.cfg.bucket,
136
+ Key: this.toKey(ref.pathname)
137
+ }));
138
+ if (!res.Body) {
139
+ return null;
140
+ }
141
+ const stream = res.Body.transformToWebStream();
142
+ return {
143
+ contentType: res.ContentType || contentTypeFor(ref.pathname),
144
+ stream
145
+ };
146
+ } catch {
147
+ return null;
148
+ }
149
+ }
150
+ async put(pathname, body) {
151
+ const { Upload } = await import('@aws-sdk/lib-storage');
152
+ const client = await this.client();
153
+ const key = this.toKey(pathname);
154
+ await new Upload({
155
+ client,
156
+ params: {
157
+ Body: typeof body === 'string' ? Buffer.from(body) : body,
158
+ Bucket: this.cfg.bucket,
159
+ ContentType: contentTypeFor(pathname),
160
+ Key: key
161
+ }
162
+ }).done();
163
+ return {
164
+ pathname,
165
+ url: await this.presignGet(key)
166
+ };
167
+ }
168
+ async read(ref) {
169
+ const { GetObjectCommand } = await this.sdk();
170
+ const client = await this.client();
171
+ const res = await client.send(new GetObjectCommand({
172
+ Bucket: this.cfg.bucket,
173
+ Key: this.toKey(ref.pathname)
174
+ }));
175
+ if (!res.Body) {
176
+ throw new Error(`Failed to read backup object (${ref.pathname}): empty body`);
177
+ }
178
+ const bytes = await res.Body.transformToByteArray();
179
+ return Buffer.from(bytes);
180
+ }
181
+ async validate() {
182
+ try {
183
+ const { HeadBucketCommand } = await this.sdk();
184
+ const client = await this.client();
185
+ await client.send(new HeadBucketCommand({
186
+ Bucket: this.cfg.bucket
187
+ }));
188
+ return {
189
+ ok: true
190
+ };
191
+ } catch (error) {
192
+ return {
193
+ error: error instanceof Error ? error.message : 'S3 bucket not reachable',
194
+ ok: false
195
+ };
196
+ }
197
+ }
198
+ }
199
+
200
+ //# sourceMappingURL=s3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/core/storage/s3.ts"],"sourcesContent":["import type { S3Client } from '@aws-sdk/client-s3'\n\nimport type { BackupS3Config } from './config'\nimport type {\n BackupStorageAdapter,\n BackupStorageObject,\n BackupStorageRef,\n BackupStorageValidation,\n} from './types'\n\n/** Presigned download URLs are valid this long — long enough to start a restore/download. */\nconst SIGNED_URL_TTL_SECONDS = 3600\n\ntype S3PresignerModule = {\n getSignedUrl: (\n client: S3Client,\n command: unknown,\n options: { expiresIn: number },\n ) => Promise<string>\n}\n\nfunction contentTypeFor(pathname: string): string {\n if (pathname.endsWith('.json')) {\n return 'application/json'\n }\n if (pathname.endsWith('.gz') || pathname.endsWith('.tar.gz')) {\n return 'application/gzip'\n }\n return 'application/octet-stream'\n}\n\n/**\n * AWS S3 backup target. The same implementation serves any S3-compatible store (Cloudflare R2,\n * MinIO, …) — only the `endpoint`/`forcePathStyle` config differs, never the code. The AWS SDK is\n * loaded lazily via dynamic import so it stays an optional dependency for Vercel-only installs.\n */\nexport class S3BackupStorage implements BackupStorageAdapter {\n private readonly cfg: BackupS3Config\n\n private clientPromise: null | Promise<S3Client> = null\n private presignerPromise: null | Promise<S3PresignerModule> = null\n readonly kind = 's3'\n\n constructor(cfg: BackupS3Config) {\n this.cfg = cfg\n }\n\n private async buildClient(): Promise<S3Client> {\n const { S3Client } = await this.sdk()\n const { accessKeyId, secretAccessKey, sessionToken } = this.cfg\n return new S3Client({\n ...(this.cfg.endpoint ? { endpoint: this.cfg.endpoint } : {}),\n forcePathStyle: this.cfg.forcePathStyle,\n region: this.cfg.region,\n // When keys are absent, fall back to the SDK's default credential provider chain\n // (env vars, shared config, instance/role credentials).\n ...(accessKeyId && secretAccessKey ?\n { credentials: { accessKeyId, secretAccessKey, sessionToken } }\n : {}),\n })\n }\n\n private async client(): Promise<S3Client> {\n if (!this.clientPromise) {\n this.clientPromise = this.buildClient()\n }\n return this.clientPromise\n }\n\n /** Strip the configured key prefix, returning the provider-agnostic `backups/...` pathname. */\n private fromKey(key: string): string {\n if (!this.cfg.prefix) {\n return key\n }\n const lead = `${this.cfg.prefix}/`\n return key.startsWith(lead) ? key.slice(lead.length) : key\n }\n\n private async presigner() {\n if (!this.presignerPromise) {\n this.presignerPromise = import('@aws-sdk/s3-request-presigner')\n }\n return this.presignerPromise\n }\n\n private async presignGet(key: string): Promise<string> {\n const { GetObjectCommand } = await this.sdk()\n const { getSignedUrl } = await this.presigner()\n const client = await this.client()\n return getSignedUrl(client, new GetObjectCommand({ Bucket: this.cfg.bucket, Key: key }), {\n expiresIn: SIGNED_URL_TTL_SECONDS,\n })\n }\n\n private async sdk() {\n try {\n return await import('@aws-sdk/client-s3')\n } catch {\n throw new Error(\n 'BACKUP_STORAGE=s3 requires the AWS SDK. Install it with: ' +\n 'pnpm add @aws-sdk/client-s3 @aws-sdk/lib-storage @aws-sdk/s3-request-presigner',\n )\n }\n }\n\n /** Prepend the configured key prefix to a provider-agnostic `backups/...` pathname. */\n private toKey(pathname: string): string {\n return this.cfg.prefix ? `${this.cfg.prefix}/${pathname}` : pathname\n }\n\n async del(ref: BackupStorageRef): Promise<void> {\n const { DeleteObjectCommand } = await this.sdk()\n const client = await this.client()\n await client.send(\n new DeleteObjectCommand({ Bucket: this.cfg.bucket, Key: this.toKey(ref.pathname) }),\n )\n }\n\n async list(prefix: string): Promise<BackupStorageObject[]> {\n const { ListObjectsV2Command } = await this.sdk()\n const client = await this.client()\n const keyPrefix = this.toKey(prefix)\n\n const objects: BackupStorageObject[] = []\n let continuationToken: string | undefined\n do {\n const res = await client.send(\n new ListObjectsV2Command({\n Bucket: this.cfg.bucket,\n ContinuationToken: continuationToken,\n Prefix: keyPrefix,\n }),\n )\n const pageEntries: Array<{\n key: string\n pathname: string\n size: number\n uploadedAt: Date\n }> = []\n for (const obj of res.Contents ?? []) {\n if (!obj.Key) {\n continue\n }\n pageEntries.push({\n key: obj.Key,\n pathname: this.fromKey(obj.Key),\n size: obj.Size ?? 0,\n uploadedAt: obj.LastModified ?? new Date(0),\n })\n }\n const signed = await Promise.all(\n pageEntries.map(async (entry) => {\n const url = await this.presignGet(entry.key)\n return {\n downloadUrl: url,\n pathname: entry.pathname,\n size: entry.size,\n uploadedAt: entry.uploadedAt,\n url,\n }\n }),\n )\n objects.push(...signed)\n continuationToken = res.IsTruncated ? res.NextContinuationToken : undefined\n } while (continuationToken)\n\n return objects\n }\n\n async openDownloadStream(ref: BackupStorageRef) {\n const { GetObjectCommand } = await this.sdk()\n const client = await this.client()\n try {\n const res = await client.send(\n new GetObjectCommand({ Bucket: this.cfg.bucket, Key: this.toKey(ref.pathname) }),\n )\n if (!res.Body) {\n return null\n }\n const stream = (\n res.Body as { transformToWebStream: () => ReadableStream<Uint8Array> }\n ).transformToWebStream()\n return {\n contentType: res.ContentType || contentTypeFor(ref.pathname),\n stream,\n }\n } catch {\n return null\n }\n }\n\n async put(pathname: string, body: Buffer | string | Uint8Array) {\n const { Upload } = await import('@aws-sdk/lib-storage')\n const client = await this.client()\n const key = this.toKey(pathname)\n await new Upload({\n client,\n params: {\n Body: typeof body === 'string' ? Buffer.from(body) : body,\n Bucket: this.cfg.bucket,\n ContentType: contentTypeFor(pathname),\n Key: key,\n },\n }).done()\n return { pathname, url: await this.presignGet(key) }\n }\n\n async read(ref: BackupStorageRef): Promise<Buffer> {\n const { GetObjectCommand } = await this.sdk()\n const client = await this.client()\n const res = await client.send(\n new GetObjectCommand({ Bucket: this.cfg.bucket, Key: this.toKey(ref.pathname) }),\n )\n if (!res.Body) {\n throw new Error(`Failed to read backup object (${ref.pathname}): empty body`)\n }\n const bytes = await (\n res.Body as { transformToByteArray: () => Promise<Uint8Array> }\n ).transformToByteArray()\n return Buffer.from(bytes)\n }\n\n async validate(): Promise<BackupStorageValidation> {\n try {\n const { HeadBucketCommand } = await this.sdk()\n const client = await this.client()\n await client.send(new HeadBucketCommand({ Bucket: this.cfg.bucket }))\n return { ok: true }\n } catch (error) {\n return {\n error: error instanceof Error ? error.message : 'S3 bucket not reachable',\n ok: false,\n }\n }\n }\n}\n"],"names":["SIGNED_URL_TTL_SECONDS","contentTypeFor","pathname","endsWith","S3BackupStorage","cfg","clientPromise","presignerPromise","kind","buildClient","S3Client","sdk","accessKeyId","secretAccessKey","sessionToken","endpoint","forcePathStyle","region","credentials","client","fromKey","key","prefix","lead","startsWith","slice","length","presigner","presignGet","GetObjectCommand","getSignedUrl","Bucket","bucket","Key","expiresIn","Error","toKey","del","ref","DeleteObjectCommand","send","list","ListObjectsV2Command","keyPrefix","objects","continuationToken","res","ContinuationToken","Prefix","pageEntries","obj","Contents","push","size","Size","uploadedAt","LastModified","Date","signed","Promise","all","map","entry","url","downloadUrl","IsTruncated","NextContinuationToken","undefined","openDownloadStream","Body","stream","transformToWebStream","contentType","ContentType","put","body","Upload","params","Buffer","from","done","read","bytes","transformToByteArray","validate","HeadBucketCommand","ok","error","message"],"mappings":"AAUA,2FAA2F,GAC3F,MAAMA,yBAAyB;AAU/B,SAASC,eAAeC,QAAgB;IACtC,IAAIA,SAASC,QAAQ,CAAC,UAAU;QAC9B,OAAO;IACT;IACA,IAAID,SAASC,QAAQ,CAAC,UAAUD,SAASC,QAAQ,CAAC,YAAY;QAC5D,OAAO;IACT;IACA,OAAO;AACT;AAEA;;;;CAIC,GACD,OAAO,MAAMC;IACMC,IAAmB;IAE5BC,gBAA0C,KAAI;IAC9CC,mBAAsD,KAAI;IACzDC,OAAO,KAAI;IAEpB,YAAYH,GAAmB,CAAE;QAC/B,IAAI,CAACA,GAAG,GAAGA;I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;YACF,MAAM,EAAEC,iBAAiB,EAAE,GAAG,MAAM,IAAI,CAAC1E,GAAG;YAC5C,MAAMQ,SAAS,MAAM,IAAI,CAACA,MAAM;YAChC,MAAMA,OAAOqB,IAAI,CAAC,IAAI6C,kBAAkB;gBAAEtD,QAAQ,IAAI,CAAC1B,GAAG,CAAC2B,MAAM;YAAC;YAClE,OAAO;gBAAEsD,IAAI;YAAK;QACpB,EAAE,OAAOC,OAAO;YACd,OAAO;gBACLA,OAAOA,iBAAiBpD,QAAQoD,MAAMC,OAAO,GAAG;gBAChDF,IAAI;YACN;QACF;IACF;AACF"}
@@ -0,0 +1,60 @@
1
+ import type { BackupBlobAccessLevel } from '../backupBlobIO.js';
2
+ /** Selectable backup target. Vercel Blob is the historical default; `s3` covers AWS S3 and any
3
+ * S3-compatible store (Cloudflare R2, MinIO, …) — they share one implementation. */
4
+ export type BackupStorageKind = 's3' | 'vercel-blob';
5
+ /**
6
+ * Backup archive as seen by the dashboard and the cron/list endpoints. The field names match the
7
+ * objects Vercel Blob's `list()` returns so existing consumers (UI, restore-by-`url`) keep working;
8
+ * the S3 adapter synthesizes the same shape (with a presigned `downloadUrl`/`url`).
9
+ */
10
+ export interface BackupStorageObject {
11
+ /** Time-limited URL suitable for downloading the object (presigned for S3). */
12
+ downloadUrl: string;
13
+ /** Object key without any provider prefix, e.g. `backups/manual---db---host---2-1700.json`. */
14
+ pathname: string;
15
+ /** Object size in bytes. */
16
+ size: number;
17
+ /** Upload/last-modified time. */
18
+ uploadedAt: Date | string;
19
+ /** Stable reference used for download/delete (Vercel blob URL; presigned GET for S3). */
20
+ url: string;
21
+ }
22
+ /** Result of probing the target's credentials/reachability. */
23
+ export interface BackupStorageValidation {
24
+ /** Detected Vercel Blob access level, when applicable. */
25
+ access?: BackupBlobAccessLevel;
26
+ /** Short description when validation fails. */
27
+ error?: string;
28
+ ok: boolean;
29
+ }
30
+ /** A reference good enough to read or delete a single archive across providers. */
31
+ export interface BackupStorageRef {
32
+ downloadUrl?: null | string;
33
+ pathname: string;
34
+ url?: null | string;
35
+ }
36
+ /**
37
+ * Provider-agnostic operations the plugin performs on backup archives. Implementations live in
38
+ * `vercelBlob.ts` and `s3.ts`; callers obtain one via {@link resolveBackupStorage}.
39
+ */
40
+ export interface BackupStorageAdapter {
41
+ /** Delete a single archive. */
42
+ del(ref: BackupStorageRef): Promise<void>;
43
+ readonly kind: BackupStorageKind;
44
+ /** List archives under a pathname prefix (e.g. `backups/` or `backups/cron-`). */
45
+ list(prefix: string): Promise<BackupStorageObject[]>;
46
+ /** Open a readable stream for streaming a download response, or null when not found. */
47
+ openDownloadStream(ref: BackupStorageRef): Promise<{
48
+ contentType: string;
49
+ stream: ReadableStream<Uint8Array>;
50
+ } | null>;
51
+ /** Upload an archive at `pathname`. */
52
+ put(pathname: string, body: Buffer | string | Uint8Array): Promise<{
53
+ pathname: string;
54
+ url: string;
55
+ }>;
56
+ /** Read the full bytes of an archive. */
57
+ read(ref: BackupStorageRef): Promise<Buffer>;
58
+ /** Probe credentials / reachability without persisting anything. */
59
+ validate(): Promise<BackupStorageValidation>;
60
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Provider-agnostic operations the plugin performs on backup archives. Implementations live in
3
+ * `vercelBlob.ts` and `s3.ts`; callers obtain one via {@link resolveBackupStorage}.
4
+ */ export { };
5
+
6
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/core/storage/types.ts"],"sourcesContent":["import type { BackupBlobAccessLevel } from '../backupBlobIO'\n\n/** Selectable backup target. Vercel Blob is the historical default; `s3` covers AWS S3 and any\n * S3-compatible store (Cloudflare R2, MinIO, …) — they share one implementation. */\nexport type BackupStorageKind = 's3' | 'vercel-blob'\n\n/**\n * Backup archive as seen by the dashboard and the cron/list endpoints. The field names match the\n * objects Vercel Blob's `list()` returns so existing consumers (UI, restore-by-`url`) keep working;\n * the S3 adapter synthesizes the same shape (with a presigned `downloadUrl`/`url`).\n */\nexport interface BackupStorageObject {\n /** Time-limited URL suitable for downloading the object (presigned for S3). */\n downloadUrl: string\n /** Object key without any provider prefix, e.g. `backups/manual---db---host---2-1700.json`. */\n pathname: string\n /** Object size in bytes. */\n size: number\n /** Upload/last-modified time. */\n uploadedAt: Date | string\n /** Stable reference used for download/delete (Vercel blob URL; presigned GET for S3). */\n url: string\n}\n\n/** Result of probing the target's credentials/reachability. */\nexport interface BackupStorageValidation {\n /** Detected Vercel Blob access level, when applicable. */\n access?: BackupBlobAccessLevel\n /** Short description when validation fails. */\n error?: string\n ok: boolean\n}\n\n/** A reference good enough to read or delete a single archive across providers. */\nexport interface BackupStorageRef {\n downloadUrl?: null | string\n pathname: string\n url?: null | string\n}\n\n/**\n * Provider-agnostic operations the plugin performs on backup archives. Implementations live in\n * `vercelBlob.ts` and `s3.ts`; callers obtain one via {@link resolveBackupStorage}.\n */\nexport interface BackupStorageAdapter {\n /** Delete a single archive. */\n del(ref: BackupStorageRef): Promise<void>\n readonly kind: BackupStorageKind\n /** List archives under a pathname prefix (e.g. `backups/` or `backups/cron-`). */\n list(prefix: string): Promise<BackupStorageObject[]>\n /** Open a readable stream for streaming a download response, or null when not found. */\n openDownloadStream(\n ref: BackupStorageRef,\n ): Promise<{ contentType: string; stream: ReadableStream<Uint8Array> } | null>\n /** Upload an archive at `pathname`. */\n put(\n pathname: string,\n body: Buffer | string | Uint8Array,\n ): Promise<{ pathname: string; url: string }>\n /** Read the full bytes of an archive. */\n read(ref: BackupStorageRef): Promise<Buffer>\n /** Probe credentials / reachability without persisting anything. */\n validate(): Promise<BackupStorageValidation>\n}\n"],"names":[],"mappings":"AAwCA;;;CAGC,GACD,WAmBC"}
@@ -0,0 +1,25 @@
1
+ import type { BackupStorageAdapter, BackupStorageObject, BackupStorageRef, BackupStorageValidation } from './types.js';
2
+ import { type BackupBlobAccessLevel } from '../backupBlobIO.js';
3
+ /**
4
+ * Vercel Blob backup target — the historical default. This is a thin wrapper around the existing
5
+ * `@vercel/blob` helpers so behaviour (and the test seams that mock `@vercel/blob`) is unchanged;
6
+ * the adapter only generalizes the call shape so S3 can slot in alongside it.
7
+ */
8
+ export declare class VercelBlobStorage implements BackupStorageAdapter {
9
+ private readonly access;
10
+ private readonly token;
11
+ readonly kind = "vercel-blob";
12
+ constructor(options: {
13
+ access?: BackupBlobAccessLevel;
14
+ token?: string;
15
+ });
16
+ del(ref: BackupStorageRef): Promise<void>;
17
+ list(prefix: string): Promise<BackupStorageObject[]>;
18
+ openDownloadStream(ref: BackupStorageRef): Promise<import("../backupBlobIO.js").BackupBlobDownloadStream | null>;
19
+ put(pathname: string, body: Buffer | string | Uint8Array): Promise<{
20
+ pathname: string;
21
+ url: string;
22
+ }>;
23
+ read(ref: BackupStorageRef): Promise<Buffer>;
24
+ validate(): Promise<BackupStorageValidation>;
25
+ }
@@ -0,0 +1,53 @@
1
+ import { del, list } from '@vercel/blob';
2
+ import { putBackupBlobContent, readBackupBlobContentFlexible, streamBackupBlobForDownload } from '../backupBlobIO.js';
3
+ import { validateBackupBlobToken } from '../blobTokenValidate.js';
4
+ /**
5
+ * Vercel Blob backup target — the historical default. This is a thin wrapper around the existing
6
+ * `@vercel/blob` helpers so behaviour (and the test seams that mock `@vercel/blob`) is unchanged;
7
+ * the adapter only generalizes the call shape so S3 can slot in alongside it.
8
+ */ export class VercelBlobStorage {
9
+ access;
10
+ token;
11
+ kind = 'vercel-blob';
12
+ constructor(options){
13
+ this.token = options.token;
14
+ this.access = options.access ?? 'public';
15
+ }
16
+ async del(ref) {
17
+ await del(ref.url ?? ref.pathname, {
18
+ token: this.token
19
+ });
20
+ }
21
+ async list(prefix) {
22
+ const { blobs } = await list({
23
+ limit: 1000,
24
+ prefix,
25
+ token: this.token
26
+ });
27
+ return blobs;
28
+ }
29
+ async openDownloadStream(ref) {
30
+ return streamBackupBlobForDownload({
31
+ blobUrl: ref.url,
32
+ downloadUrl: ref.downloadUrl,
33
+ pathname: ref.pathname,
34
+ preferredAccess: this.access,
35
+ token: this.token ?? ''
36
+ });
37
+ }
38
+ async put(pathname, body) {
39
+ await putBackupBlobContent(pathname, body, this.token, this.access);
40
+ return {
41
+ pathname,
42
+ url: ''
43
+ };
44
+ }
45
+ async read(ref) {
46
+ return readBackupBlobContentFlexible(ref.pathname, ref.downloadUrl ?? ref.url ?? '', this.token ?? '');
47
+ }
48
+ async validate() {
49
+ return validateBackupBlobToken(this.token ?? '');
50
+ }
51
+ }
52
+
53
+ //# sourceMappingURL=vercelBlob.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/core/storage/vercelBlob.ts"],"sourcesContent":["import { del, list } from '@vercel/blob'\n\nimport type {\n BackupStorageAdapter,\n BackupStorageObject,\n BackupStorageRef,\n BackupStorageValidation,\n} from './types'\n\nimport {\n type BackupBlobAccessLevel,\n putBackupBlobContent,\n readBackupBlobContentFlexible,\n streamBackupBlobForDownload,\n} from '../backupBlobIO'\nimport { validateBackupBlobToken } from '../blobTokenValidate'\n\n/**\n * Vercel Blob backup target — the historical default. This is a thin wrapper around the existing\n * `@vercel/blob` helpers so behaviour (and the test seams that mock `@vercel/blob`) is unchanged;\n * the adapter only generalizes the call shape so S3 can slot in alongside it.\n */\nexport class VercelBlobStorage implements BackupStorageAdapter {\n private readonly access: BackupBlobAccessLevel\n\n private readonly token: string | undefined\n readonly kind = 'vercel-blob'\n\n constructor(options: { access?: BackupBlobAccessLevel; token?: string }) {\n this.token = options.token\n this.access = options.access ?? 'public'\n }\n\n async del(ref: BackupStorageRef): Promise<void> {\n await del(ref.url ?? ref.pathname, { token: this.token })\n }\n\n async list(prefix: string): Promise<BackupStorageObject[]> {\n const { blobs } = await list({ limit: 1000, prefix, token: this.token })\n return blobs as unknown as BackupStorageObject[]\n }\n\n async openDownloadStream(ref: BackupStorageRef) {\n return streamBackupBlobForDownload({\n blobUrl: ref.url,\n downloadUrl: ref.downloadUrl,\n pathname: ref.pathname,\n preferredAccess: this.access,\n token: this.token ?? '',\n })\n }\n\n async put(pathname: string, body: Buffer | string | Uint8Array) {\n await putBackupBlobContent(pathname, body, this.token, this.access)\n return { pathname, url: '' }\n }\n\n async read(ref: BackupStorageRef): Promise<Buffer> {\n return readBackupBlobContentFlexible(\n ref.pathname,\n ref.downloadUrl ?? ref.url ?? '',\n this.token ?? '',\n )\n }\n\n async validate(): Promise<BackupStorageValidation> {\n return validateBackupBlobToken(this.token ?? '')\n }\n}\n"],"names":["del","list","putBackupBlobContent","readBackupBlobContentFlexible","streamBackupBlobForDownload","validateBackupBlobToken","VercelBlobStorage","access","token","kind","options","ref","url","pathname","prefix","blobs","limit","openDownloadStream","blobUrl","downloadUrl","preferredAccess","put","body","read","validate"],"mappings":"AAAA,SAASA,GAAG,EAAEC,IAAI,QAAQ,eAAc;AASxC,SAEEC,oBAAoB,EACpBC,6BAA6B,EAC7BC,2BAA2B,QACtB,kBAAiB;AACxB,SAASC,uBAAuB,QAAQ,uBAAsB;AAE9D;;;;CAIC,GACD,OAAO,MAAMC;IACMC,OAA6B;IAE7BC,MAAyB;IACjCC,OAAO,cAAa;IAE7B,YAAYC,OAA2D,CAAE;QACvE,IAAI,CAACF,KAAK,GAAGE,QAAQF,KAAK;QAC1B,IAAI,CAACD,MAAM,GAAGG,QAAQH,MAAM,IAAI;IAClC;IAEA,MAAMP,IAAIW,GAAqB,EAAiB;QAC9C,MAAMX,IAAIW,IAAIC,GAAG,IAAID,IAAIE,QAAQ,EAAE;YAAEL,OAAO,IAAI,CAACA,KAAK;QAAC;IACzD;IAEA,MAAMP,KAAKa,MAAc,EAAkC;QACzD,MAAM,EAAEC,KAAK,EAAE,GAAG,MAAMd,KAAK;YAAEe,OAAO;YAAMF;YAAQN,OAAO,IAAI,CAACA,KAAK;QAAC;QACtE,OAAOO;IACT;IAEA,MAAME,mBAAmBN,GAAqB,EAAE;QAC9C,OAAOP,4BAA4B;YACjCc,SAASP,IAAIC,GAAG;YAChBO,aAAaR,IAAIQ,WAAW;YAC5BN,UAAUF,IAAIE,QAAQ;YACtBO,iBAAiB,IAAI,CAACb,MAAM;YAC5BC,OAAO,IAAI,CAACA,KAAK,IAAI;QACvB;IACF;IAEA,MAAMa,IAAIR,QAAgB,EAAES,IAAkC,EAAE;QAC9D,MAAMpB,qBAAqBW,UAAUS,MAAM,IAAI,CAACd,KAAK,EAAE,IAAI,CAACD,MAAM;QAClE,OAAO;YAAEM;YAAUD,KAAK;QAAG;IAC7B;IAEA,MAAMW,KAAKZ,GAAqB,EAAmB;QACjD,OAAOR,8BACLQ,IAAIE,QAAQ,EACZF,IAAIQ,WAAW,IAAIR,IAAIC,GAAG,IAAI,IAC9B,IAAI,CAACJ,KAAK,IAAI;IAElB;IAEA,MAAMgB,WAA6C;QACjD,OAAOnB,wBAAwB,IAAI,CAACG,KAAK,IAAI;IAC/C;AACF"}
@@ -0,0 +1,25 @@
1
+ import type { Payload } from 'payload';
2
+ /**
3
+ * Payload's Postgres adapter spreads one collection/global over several tables:
4
+ * `posts`, `posts_rels`, `posts_locales`, `posts_blocks_hero`, … (main data)
5
+ * `_posts_v`, `_posts_v_rels`, … (version history)
6
+ * This module maps physical tables back to the owning Payload slug so the admin UI can
7
+ * keep showing one checkbox per collection, like the MongoDB plugin.
8
+ */
9
+ export type TableOwner = {
10
+ kind: 'collection' | 'global' | 'unknown';
11
+ /** Collection/global slug, or the table name for tables not owned by Payload config. */
12
+ slug: string;
13
+ /** True when the table belongs to the `_<root>_v` version-history family. */
14
+ versions: boolean;
15
+ };
16
+ /** Mirrors Payload's `toSnakeCase` for slugs (`my-posts` / `myPosts` → `my_posts`). */
17
+ export declare function slugToSnake(slug: string): string;
18
+ export declare function resolveTableOwners(payload: Payload, tables: string[], tableNameMap?: Map<string, string>): Map<string, TableOwner>;
19
+ /** Main + version root table names for a slug (used for row counts in the UI). */
20
+ export declare function rootTablesForSlug(payload: Payload, slug: string, tableNameMap?: Map<string, string>): {
21
+ main: string;
22
+ versions: string;
23
+ } | null;
24
+ /** All tables (from `tables`) that belong to the given slugs. */
25
+ export declare function tablesForSlugs(payload: Payload, slugs: string[], tables: string[], tableNameMap?: Map<string, string>): string[];
@@ -0,0 +1,80 @@
1
+ /** Mirrors Payload's `toSnakeCase` for slugs (`my-posts` / `myPosts` → `my_posts`). */ export function slugToSnake(slug) {
2
+ return slug.replace(/([a-z0-9])([A-Z])/g, '$1_$2').replace(/[-\s]+/g, '_').toLowerCase();
3
+ }
4
+ function rootTableName(entity, tableNameMap) {
5
+ if (typeof entity.dbName === 'string' && entity.dbName) {
6
+ return entity.dbName;
7
+ }
8
+ const snake = slugToSnake(entity.slug);
9
+ return tableNameMap?.get(snake) ?? snake;
10
+ }
11
+ function collectRoots(payload, tableNameMap) {
12
+ const roots = [];
13
+ for (const c of payload.config.collections ?? []){
14
+ const root = rootTableName(c, tableNameMap);
15
+ roots.push({
16
+ slug: c.slug,
17
+ kind: 'collection',
18
+ root,
19
+ versions: false
20
+ });
21
+ roots.push({
22
+ slug: c.slug,
23
+ kind: 'collection',
24
+ root: `_${root}_v`,
25
+ versions: true
26
+ });
27
+ }
28
+ for (const g of payload.config.globals ?? []){
29
+ const root = rootTableName(g, tableNameMap);
30
+ roots.push({
31
+ slug: g.slug,
32
+ kind: 'global',
33
+ root,
34
+ versions: false
35
+ });
36
+ roots.push({
37
+ slug: g.slug,
38
+ kind: 'global',
39
+ root: `_${root}_v`,
40
+ versions: true
41
+ });
42
+ }
43
+ // Longest root first so `media_folders` wins over `media` for `media_folders_rels`.
44
+ return roots.sort((a, b)=>b.root.length - a.root.length);
45
+ }
46
+ export function resolveTableOwners(payload, tables, tableNameMap) {
47
+ const roots = collectRoots(payload, tableNameMap);
48
+ const out = new Map();
49
+ for (const t of tables){
50
+ const hit = roots.find((r)=>t === r.root || t.startsWith(`${r.root}_`));
51
+ out.set(t, hit ? {
52
+ slug: hit.slug,
53
+ kind: hit.kind,
54
+ versions: hit.versions
55
+ } : {
56
+ slug: t,
57
+ kind: 'unknown',
58
+ versions: false
59
+ });
60
+ }
61
+ return out;
62
+ }
63
+ /** Main + version root table names for a slug (used for row counts in the UI). */ export function rootTablesForSlug(payload, slug, tableNameMap) {
64
+ const entity = payload.config.collections?.find((c)=>c.slug === slug) ?? payload.config.globals?.find((g)=>g.slug === slug);
65
+ if (!entity) {
66
+ return null;
67
+ }
68
+ const root = rootTableName(entity, tableNameMap);
69
+ return {
70
+ main: root,
71
+ versions: `_${root}_v`
72
+ };
73
+ }
74
+ /** All tables (from `tables`) that belong to the given slugs. */ export function tablesForSlugs(payload, slugs, tables, tableNameMap) {
75
+ const wanted = new Set(slugs);
76
+ const owners = resolveTableOwners(payload, tables, tableNameMap);
77
+ return tables.filter((t)=>wanted.has(owners.get(t).slug));
78
+ }
79
+
80
+ //# sourceMappingURL=tableGroups.js.map
@@ -0,0 +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;YAAEG,UAAU;QAAK;IACpF;IACA,KAAK,MAAMC,KAAKT,QAAQG,MAAM,CAACO,OAAO,IAAI,EAAE,CAAE;QAC5C,MAAML,OAAOZ,cAAcgB,GAAyCd;QACpEM,MAAMK,IAAI,CAAC;YAAEhB,MAAMmB,EAAEnB,IAAI;YAAEiB,MAAM;YAAUF;YAAMG,UAAU;QAAM;QACjEP,MAAMK,IAAI,CAAC;YAAEhB,MAAMmB,EAAEnB,IAAI;YAAEi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BrB,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"}
@@ -0,0 +1,39 @@
1
+ import type { Payload } from 'payload';
2
+ import type { RestoreBackupResult } from './restoreResult.js';
3
+ export type BackupTaskKind = 'backup' | 'blobTransfer' | 'delete' | 'restore';
4
+ export type BackupTaskStatus = 'completed' | 'completed_with_warnings' | 'failed' | 'queued' | 'running';
5
+ export type BackupTaskProgress = {
6
+ createdAt: string;
7
+ error?: null | string;
8
+ id: string;
9
+ kind: BackupTaskKind;
10
+ message: string;
11
+ status: BackupTaskStatus;
12
+ updatedAt: string;
13
+ warnings?: null | string;
14
+ };
15
+ /** Task row as stored / returned from Payload (includes server-only poll secret). */
16
+ export type BackupTaskWithPollSecret = {
17
+ pollSecret?: null | string;
18
+ } & BackupTaskProgress;
19
+ export declare function pollSecretsMatch(provided: string, stored: null | string | undefined): boolean;
20
+ export declare function stripPollSecretForClient(task: BackupTaskWithPollSecret): BackupTaskProgress;
21
+ export declare function createBackupTask(payload: Payload, kind: BackupTaskKind, message: string): Promise<{
22
+ pollSecret: string;
23
+ taskId: string;
24
+ }>;
25
+ export declare function getBackupTask(payload: Payload, id: string): Promise<BackupTaskWithPollSecret | undefined>;
26
+ export declare function updateBackupTask(payload: Payload, id: string, patch: Partial<Pick<BackupTaskProgress, 'error' | 'message' | 'status' | 'warnings'>>): Promise<BackupTaskProgress | undefined>;
27
+ export declare function completeBackupTask(payload: Payload, id: string, message: string, options?: {
28
+ status?: 'completed' | 'completed_with_warnings';
29
+ warnings?: string;
30
+ }): Promise<BackupTaskProgress | undefined>;
31
+ export declare function completeRestoreBackupTask(payload: Payload, id: string, result: RestoreBackupResult): Promise<BackupTaskProgress | undefined>;
32
+ export declare function failBackupTask(payload: Payload, id: string, error: unknown): Promise<BackupTaskProgress | undefined>;
33
+ /** Default age after which progress rows are deleted (matches the MongoDB plugin's TTL index). */
34
+ export declare const BACKUP_TASK_TTL_MS: number;
35
+ /**
36
+ * Postgres has no TTL indexes, so stale `backup-tasks` rows are pruned explicitly on start-up
37
+ * and whenever a new task is created. Never throws.
38
+ */
39
+ export declare function pruneStaleBackupTasks(payload: Payload, maxAgeMs?: number): Promise<void>;