@payloadcms/db-mongodb 4.0.0-internal.38b7f1d → 4.0.0-internal.4c792ad
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.
- package/dist/connect.d.ts.map +1 -1
- package/dist/connect.js +1 -2
- package/dist/connect.js.map +1 -1
- package/dist/createMigration.d.ts.map +1 -1
- package/dist/createMigration.js +5 -44
- package/dist/createMigration.js.map +1 -1
- package/dist/deleteOne.js.map +1 -1
- package/dist/exports/migration-utils.d.ts +1 -0
- package/dist/exports/migration-utils.d.ts.map +1 -1
- package/dist/exports/migration-utils.js +1 -0
- package/dist/exports/migration-utils.js.map +1 -1
- package/dist/index.d.ts +1 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -6
- package/dist/index.js.map +1 -1
- package/dist/models/buildCollectionSchema.d.ts.map +1 -1
- package/dist/models/buildGlobalModel.d.ts.map +1 -1
- package/dist/models/buildSchema.d.ts.map +1 -1
- package/dist/models/buildSchema.js +1 -1
- package/dist/models/buildSchema.js.map +1 -1
- package/dist/predefinedMigrations/localize-status.d.ts +4 -0
- package/dist/predefinedMigrations/localize-status.d.ts.map +1 -0
- package/dist/predefinedMigrations/localize-status.js +9 -0
- package/dist/predefinedMigrations/localize-status.js.map +1 -0
- package/dist/predefinedMigrations/migrateLocalizeStatus.d.ts +27 -0
- package/dist/predefinedMigrations/migrateLocalizeStatus.d.ts.map +1 -0
- package/dist/predefinedMigrations/migrateLocalizeStatus.js +324 -0
- package/dist/predefinedMigrations/migrateLocalizeStatus.js.map +1 -0
- package/dist/queries/buildQuery.d.ts.map +1 -1
- package/dist/queries/buildSortParam.d.ts.map +1 -1
- package/dist/queries/getBuildQueryPlugin.d.ts.map +1 -1
- package/dist/queries/getLocalizedSortProperty.d.ts.map +1 -1
- package/dist/queries/getLocalizedSortProperty.js +1 -1
- package/dist/queries/getLocalizedSortProperty.js.map +1 -1
- package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
- package/dist/queries/sanitizeQueryValue.js +2 -3
- package/dist/queries/sanitizeQueryValue.js.map +1 -1
- package/dist/updateGlobal.d.ts.map +1 -1
- package/dist/updateGlobal.js +10 -7
- package/dist/updateGlobal.js.map +1 -1
- package/dist/updateGlobalVersion.d.ts.map +1 -1
- package/dist/updateGlobalVersion.js +10 -7
- package/dist/updateGlobalVersion.js.map +1 -1
- package/dist/updateJobs.d.ts.map +1 -1
- package/dist/updateJobs.js +11 -8
- package/dist/updateJobs.js.map +1 -1
- package/dist/updateMany.d.ts.map +1 -1
- package/dist/updateMany.js +11 -8
- package/dist/updateMany.js.map +1 -1
- package/dist/updateOne.d.ts.map +1 -1
- package/dist/updateOne.js +10 -7
- package/dist/updateOne.js.map +1 -1
- package/dist/updateVersion.d.ts.map +1 -1
- package/dist/updateVersion.js +10 -7
- package/dist/updateVersion.js.map +1 -1
- package/dist/utilities/aggregatePaginate.d.ts.map +1 -1
- package/dist/utilities/buildJoinAggregation.d.ts.map +1 -1
- package/dist/utilities/buildProjectionFromSelect.d.ts.map +1 -1
- package/dist/utilities/buildProjectionFromSelect.js +1 -1
- package/dist/utilities/buildProjectionFromSelect.js.map +1 -1
- package/dist/utilities/getDBName.d.ts.map +1 -1
- package/dist/utilities/getEntity.d.ts.map +1 -1
- package/dist/utilities/handleError.d.ts.map +1 -1
- package/dist/utilities/isObjectID.d.ts.map +1 -1
- package/dist/utilities/transform.d.ts.map +1 -1
- package/dist/utilities/transform.js +10 -34
- package/dist/utilities/transform.js.map +1 -1
- package/dist/utilities/transform.spec.js +3 -3
- package/dist/utilities/transform.spec.js.map +1 -1
- package/package.json +5 -5
- package/dist/migrateFieldDelocalized.d.ts +0 -10
- package/dist/migrateFieldDelocalized.d.ts.map +0 -1
- package/dist/migrateFieldDelocalized.js +0 -40
- package/dist/migrateFieldDelocalized.js.map +0 -1
- package/dist/migrateFieldLocalized.d.ts +0 -10
- package/dist/migrateFieldLocalized.d.ts.map +0 -1
- package/dist/migrateFieldLocalized.js +0 -43
- package/dist/migrateFieldLocalized.js.map +0 -1
- package/dist/migrateVersionsEnabled.d.ts +0 -9
- package/dist/migrateVersionsEnabled.d.ts.map +0 -1
- package/dist/migrateVersionsEnabled.js +0 -52
- package/dist/migrateVersionsEnabled.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/predefinedMigrations/localize-status.ts"],"sourcesContent":["const imports = `import { migrateLocalizeStatus } from '@payloadcms/db-mongodb/migration-utils'`\nconst upSQL = ` await migrateLocalizeStatus({\n payload,\n req,\n })\n`\n\nexport { imports, upSQL }\n"],"names":["imports","upSQL"],"mappings":"AAAA,MAAMA,UAAU,CAAC,8EAA8E,CAAC;AAChG,MAAMC,QAAQ,CAAC;;;;AAIf,CAAC;AAED,SAASD,OAAO,EAAEC,KAAK,GAAE"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ClientSession } from 'mongoose';
|
|
2
|
+
import type { Payload, PayloadRequest } from 'payload';
|
|
3
|
+
export type LocalizeStatusArgs = {
|
|
4
|
+
collectionSlug?: string;
|
|
5
|
+
globalSlug?: string;
|
|
6
|
+
payload: Payload;
|
|
7
|
+
req?: any;
|
|
8
|
+
session?: ClientSession;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Migrate all collections and globals with versions.drafts enabled to use per-locale _status.
|
|
12
|
+
*
|
|
13
|
+
* This migration:
|
|
14
|
+
* 1. Converts version._status from a scalar string to a locale-keyed object for each entity
|
|
15
|
+
* 2. Deletes all snapshot:true version documents from each versions collection
|
|
16
|
+
* 3. Unsets the `snapshot` field from remaining version documents
|
|
17
|
+
*/
|
|
18
|
+
export declare function migrateLocalizeStatus({ payload, req, }: {
|
|
19
|
+
payload: Payload;
|
|
20
|
+
req: PayloadRequest;
|
|
21
|
+
}): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Converts version._status (and the main document _status) from a scalar string to a
|
|
24
|
+
* per-locale object for a single collection or global.
|
|
25
|
+
*/
|
|
26
|
+
export declare function localizeStatus(args: LocalizeStatusArgs): Promise<void>;
|
|
27
|
+
//# sourceMappingURL=migrateLocalizeStatus.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrateLocalizeStatus.d.ts","sourceRoot":"","sources":["../../src/predefinedMigrations/migrateLocalizeStatus.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAC7C,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAQtD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,CAAC,EAAE,GAAG,CAAA;IACT,OAAO,CAAC,EAAE,aAAa,CAAA;CACxB,CAAA;AAED;;;;;;;GAOG;AACH,wBAAsB,qBAAqB,CAAC,EAC1C,OAAO,EACP,GAAG,GACJ,EAAE;IACD,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,EAAE,cAAc,CAAA;CACpB,GAAG,OAAO,CAAC,IAAI,CAAC,CAuChB;AAED;;;GAGG;AACH,wBAAsB,cAAc,CAAC,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAgQ5E"}
|
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
import { calculateVersionLocaleStatuses } from 'payload/migrations';
|
|
2
|
+
import { getSession } from '../utilities/getSession.js';
|
|
3
|
+
/**
|
|
4
|
+
* Migrate all collections and globals with versions.drafts enabled to use per-locale _status.
|
|
5
|
+
*
|
|
6
|
+
* This migration:
|
|
7
|
+
* 1. Converts version._status from a scalar string to a locale-keyed object for each entity
|
|
8
|
+
* 2. Deletes all snapshot:true version documents from each versions collection
|
|
9
|
+
* 3. Unsets the `snapshot` field from remaining version documents
|
|
10
|
+
*/ export async function migrateLocalizeStatus({ payload, req }) {
|
|
11
|
+
if (!payload.config.localization) {
|
|
12
|
+
payload.logger.info({
|
|
13
|
+
msg: 'Localization not enabled, skipping localize-status migration'
|
|
14
|
+
});
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const collections = payload.config.collections.filter((c)=>c.versions?.drafts && typeof c.versions.drafts === 'object' && c.versions.drafts.localizeStatus);
|
|
18
|
+
const globals = payload.config.globals.filter((g)=>g.versions?.drafts && typeof g.versions.drafts === 'object' && g.versions.drafts.localizeStatus);
|
|
19
|
+
payload.logger.info({
|
|
20
|
+
msg: `Starting localize-status migration for ${collections.length} collection(s) and ${globals.length} global(s)`
|
|
21
|
+
});
|
|
22
|
+
const connection = payload.db.connection;
|
|
23
|
+
const session = await getSession(payload.db, req);
|
|
24
|
+
for (const collection of collections){
|
|
25
|
+
await localizeStatus({
|
|
26
|
+
collectionSlug: collection.slug,
|
|
27
|
+
payload,
|
|
28
|
+
req,
|
|
29
|
+
session
|
|
30
|
+
});
|
|
31
|
+
await cleanupSnapshotDocuments({
|
|
32
|
+
connection,
|
|
33
|
+
entitySlug: collection.slug,
|
|
34
|
+
payload,
|
|
35
|
+
session
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
for (const global of globals){
|
|
39
|
+
await localizeStatus({
|
|
40
|
+
globalSlug: global.slug,
|
|
41
|
+
payload,
|
|
42
|
+
req,
|
|
43
|
+
session
|
|
44
|
+
});
|
|
45
|
+
await cleanupSnapshotDocuments({
|
|
46
|
+
connection,
|
|
47
|
+
entitySlug: global.slug,
|
|
48
|
+
payload,
|
|
49
|
+
session
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
payload.logger.info({
|
|
53
|
+
msg: 'localize-status migration completed successfully'
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Converts version._status (and the main document _status) from a scalar string to a
|
|
58
|
+
* per-locale object for a single collection or global.
|
|
59
|
+
*/ export async function localizeStatus(args) {
|
|
60
|
+
const { collectionSlug, globalSlug, payload, req, session } = args;
|
|
61
|
+
if (!collectionSlug && !globalSlug) {
|
|
62
|
+
throw new Error('Either collectionSlug or globalSlug must be provided');
|
|
63
|
+
}
|
|
64
|
+
if (collectionSlug && globalSlug) {
|
|
65
|
+
throw new Error('Cannot provide both collectionSlug and globalSlug');
|
|
66
|
+
}
|
|
67
|
+
const entitySlug = collectionSlug || globalSlug;
|
|
68
|
+
// MongoDB collection names are case-insensitive and stored as lowercase
|
|
69
|
+
const versionsCollection = `_${entitySlug}_versions`.toLowerCase();
|
|
70
|
+
if (!payload.config.localization) {
|
|
71
|
+
throw new Error('Localization is not enabled in payload config');
|
|
72
|
+
}
|
|
73
|
+
// Check if versions are enabled on this collection/global
|
|
74
|
+
let entityConfig;
|
|
75
|
+
if (collectionSlug) {
|
|
76
|
+
const collection = payload.config.collections.find((c)=>c.slug === collectionSlug);
|
|
77
|
+
if (collection) {
|
|
78
|
+
entityConfig = collection;
|
|
79
|
+
}
|
|
80
|
+
} else if (globalSlug) {
|
|
81
|
+
const global = payload.config.globals.find((g)=>g.slug === globalSlug);
|
|
82
|
+
if (global) {
|
|
83
|
+
entityConfig = global;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (!entityConfig) {
|
|
87
|
+
throw new Error(`${collectionSlug ? 'Collection' : 'Global'} not found: ${collectionSlug || globalSlug}`);
|
|
88
|
+
}
|
|
89
|
+
payload.logger.info({
|
|
90
|
+
msg: `Starting _status localization migration for ${collectionSlug ? 'collection' : 'global'}: ${entitySlug}`
|
|
91
|
+
});
|
|
92
|
+
// Check if versions are enabled in config (skip if not)
|
|
93
|
+
if (!entityConfig.versions) {
|
|
94
|
+
payload.logger.info({
|
|
95
|
+
msg: `Skipping migration for ${collectionSlug ? 'collection' : 'global'}: ${entitySlug} - versions not enabled`
|
|
96
|
+
});
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
// Get MongoDB connection
|
|
100
|
+
const connection = payload.db.connection;
|
|
101
|
+
// Get filtered locales if filterAvailableLocales is defined
|
|
102
|
+
let locales = payload.config.localization.localeCodes;
|
|
103
|
+
if (typeof payload.config.localization.filterAvailableLocales === 'function') {
|
|
104
|
+
const filteredLocaleObjects = await payload.config.localization.filterAvailableLocales({
|
|
105
|
+
locales: payload.config.localization.locales,
|
|
106
|
+
req
|
|
107
|
+
});
|
|
108
|
+
locales = filteredLocaleObjects.map((locale)=>locale.code);
|
|
109
|
+
}
|
|
110
|
+
payload.logger.info({
|
|
111
|
+
msg: `Locales: ${locales.join(', ')}`
|
|
112
|
+
});
|
|
113
|
+
// Check if version._status exists and is NOT already localized
|
|
114
|
+
const sampleDoc = await connection.collection(versionsCollection).findOne({}, {
|
|
115
|
+
session
|
|
116
|
+
});
|
|
117
|
+
if (!sampleDoc) {
|
|
118
|
+
payload.logger.info({
|
|
119
|
+
msg: 'No version documents found, nothing to migrate'
|
|
120
|
+
});
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
// Check if _status is already localized
|
|
124
|
+
if (sampleDoc.version?._status && typeof sampleDoc.version._status === 'object' && !Array.isArray(sampleDoc.version._status)) {
|
|
125
|
+
payload.logger.info({
|
|
126
|
+
msg: 'version._status is already localized, migration already completed'
|
|
127
|
+
});
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
// Validate that version._status exists and is a string
|
|
131
|
+
if (!sampleDoc.version || typeof sampleDoc.version._status !== 'string' || Array.isArray(sampleDoc.version._status)) {
|
|
132
|
+
throw new Error(`Migration aborted: version._status field not found or has unexpected format in ${versionsCollection}. ` + `This migration should only run on schemas that have NOT yet been migrated to per-locale status.`);
|
|
133
|
+
}
|
|
134
|
+
payload.logger.info({
|
|
135
|
+
msg: 'Fetching all version documents...'
|
|
136
|
+
});
|
|
137
|
+
// Get all versions, sorted chronologically
|
|
138
|
+
const allVersions = await connection.collection(versionsCollection).find({}, {
|
|
139
|
+
session
|
|
140
|
+
}).sort({
|
|
141
|
+
createdAt: 1,
|
|
142
|
+
parent: 1
|
|
143
|
+
}).toArray();
|
|
144
|
+
payload.logger.info({
|
|
145
|
+
msg: `Found ${allVersions.length} version documents`
|
|
146
|
+
});
|
|
147
|
+
// Transform MongoDB documents to VersionRecord format
|
|
148
|
+
const versionRecords = allVersions.map((doc)=>({
|
|
149
|
+
id: doc._id.toString(),
|
|
150
|
+
_status: doc.version._status,
|
|
151
|
+
createdAt: doc.createdAt,
|
|
152
|
+
parent: doc.parent?.toString(),
|
|
153
|
+
publishedLocale: doc.publishedLocale,
|
|
154
|
+
snapshot: doc.snapshot || false
|
|
155
|
+
}));
|
|
156
|
+
// Calculate status per locale using shared logic
|
|
157
|
+
const versionLocaleStatus = calculateVersionLocaleStatuses(versionRecords, locales, payload);
|
|
158
|
+
payload.logger.info({
|
|
159
|
+
msg: 'Updating version documents with per-locale status...'
|
|
160
|
+
});
|
|
161
|
+
// Update each version document
|
|
162
|
+
let updateCount = 0;
|
|
163
|
+
for (const doc of allVersions){
|
|
164
|
+
const versionId = doc._id.toString();
|
|
165
|
+
const localeStatusMap = versionLocaleStatus.get(versionId);
|
|
166
|
+
if (!localeStatusMap) {
|
|
167
|
+
payload.logger.warn({
|
|
168
|
+
msg: `No status map found for version ${versionId}, skipping`
|
|
169
|
+
});
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
// Build the new _status object: { en: 'published', es: 'draft', ... }
|
|
173
|
+
const newStatus = {};
|
|
174
|
+
for (const [locale, status] of localeStatusMap.entries()){
|
|
175
|
+
newStatus[locale] = status;
|
|
176
|
+
}
|
|
177
|
+
// Update the document: change version._status from string to object
|
|
178
|
+
await connection.collection(versionsCollection).updateOne({
|
|
179
|
+
_id: doc._id
|
|
180
|
+
}, {
|
|
181
|
+
$set: {
|
|
182
|
+
'version._status': newStatus
|
|
183
|
+
}
|
|
184
|
+
}, {
|
|
185
|
+
session
|
|
186
|
+
});
|
|
187
|
+
updateCount++;
|
|
188
|
+
}
|
|
189
|
+
payload.logger.info({
|
|
190
|
+
msg: `Updated ${updateCount} version documents`
|
|
191
|
+
});
|
|
192
|
+
// Migrate main collection/global document _status to per-locale status object
|
|
193
|
+
// Only if it has a status field
|
|
194
|
+
if (collectionSlug) {
|
|
195
|
+
const mainCollection = collectionSlug;
|
|
196
|
+
const mainDoc = await connection.collection(mainCollection).findOne({}, {
|
|
197
|
+
session
|
|
198
|
+
});
|
|
199
|
+
if (mainDoc && '_status' in mainDoc) {
|
|
200
|
+
payload.logger.info({
|
|
201
|
+
msg: `Migrating main collection documents for: ${mainCollection}`
|
|
202
|
+
});
|
|
203
|
+
const allDocs = await connection.collection(mainCollection).find({}, {
|
|
204
|
+
session
|
|
205
|
+
}).toArray();
|
|
206
|
+
for (const doc of allDocs){
|
|
207
|
+
if (!doc._id) {
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
// Get the latest version for this document to determine status per locale
|
|
211
|
+
const latestVersions = await connection.collection(versionsCollection).find({
|
|
212
|
+
parent: doc._id
|
|
213
|
+
}, {
|
|
214
|
+
session
|
|
215
|
+
}).sort({
|
|
216
|
+
createdAt: -1
|
|
217
|
+
}).limit(1).toArray();
|
|
218
|
+
let statusObj = {};
|
|
219
|
+
if (latestVersions.length > 0 && latestVersions[0]?.version?._status) {
|
|
220
|
+
// Use the status from the latest version
|
|
221
|
+
statusObj = latestVersions[0].version._status;
|
|
222
|
+
} else {
|
|
223
|
+
// Fallback: set all locales to draft
|
|
224
|
+
for (const locale of locales){
|
|
225
|
+
statusObj[locale] = 'draft';
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
// Update main document
|
|
229
|
+
await connection.collection(mainCollection).updateOne({
|
|
230
|
+
_id: doc._id
|
|
231
|
+
}, {
|
|
232
|
+
$set: {
|
|
233
|
+
_status: statusObj
|
|
234
|
+
}
|
|
235
|
+
}, {
|
|
236
|
+
session
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
payload.logger.info({
|
|
240
|
+
msg: `Migrated ${allDocs.length} collection documents`
|
|
241
|
+
});
|
|
242
|
+
} else {
|
|
243
|
+
payload.logger.info({
|
|
244
|
+
msg: 'Skipping main document status migration (no status field found)'
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
} else if (globalSlug) {
|
|
248
|
+
// Globals are stored in a single 'globals' collection with globalType discriminator
|
|
249
|
+
const globalDoc = await connection.collection('globals').findOne({
|
|
250
|
+
globalType: globalSlug
|
|
251
|
+
}, {
|
|
252
|
+
session
|
|
253
|
+
});
|
|
254
|
+
if (globalDoc && '_status' in globalDoc && globalDoc._id) {
|
|
255
|
+
payload.logger.info({
|
|
256
|
+
msg: `Migrating main global document for: ${globalSlug}`
|
|
257
|
+
});
|
|
258
|
+
// Get the latest version for the global
|
|
259
|
+
const latestVersions = await connection.collection(versionsCollection).find({}, {
|
|
260
|
+
session
|
|
261
|
+
}).sort({
|
|
262
|
+
createdAt: -1
|
|
263
|
+
}).limit(1).toArray();
|
|
264
|
+
let statusObj = {};
|
|
265
|
+
if (latestVersions.length > 0 && latestVersions[0]?.version?._status) {
|
|
266
|
+
statusObj = latestVersions[0].version._status;
|
|
267
|
+
} else {
|
|
268
|
+
for (const locale of locales){
|
|
269
|
+
statusObj[locale] = 'draft';
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
// Update global document
|
|
273
|
+
await connection.collection('globals').updateOne({
|
|
274
|
+
_id: globalDoc._id,
|
|
275
|
+
globalType: globalSlug
|
|
276
|
+
}, {
|
|
277
|
+
$set: {
|
|
278
|
+
_status: statusObj
|
|
279
|
+
}
|
|
280
|
+
}, {
|
|
281
|
+
session
|
|
282
|
+
});
|
|
283
|
+
payload.logger.info({
|
|
284
|
+
msg: 'Migrated global document'
|
|
285
|
+
});
|
|
286
|
+
} else {
|
|
287
|
+
payload.logger.info({
|
|
288
|
+
msg: 'Skipping main document status migration (no status field found)'
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
payload.logger.info({
|
|
293
|
+
msg: 'Migration completed successfully'
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
async function cleanupSnapshotDocuments({ connection, entitySlug, payload, session }) {
|
|
297
|
+
const versionsCollection = `_${entitySlug}_versions`.toLowerCase();
|
|
298
|
+
const col = connection.collection(versionsCollection);
|
|
299
|
+
// Delete all snapshot=true documents
|
|
300
|
+
const deleteResult = await col.deleteMany({
|
|
301
|
+
snapshot: true
|
|
302
|
+
}, {
|
|
303
|
+
session
|
|
304
|
+
});
|
|
305
|
+
if (deleteResult.deletedCount > 0) {
|
|
306
|
+
payload.logger.info({
|
|
307
|
+
msg: `Deleted ${deleteResult.deletedCount} snapshot documents from ${versionsCollection}`
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
// Unset the snapshot field from remaining documents
|
|
311
|
+
await col.updateMany({
|
|
312
|
+
snapshot: {
|
|
313
|
+
$exists: true
|
|
314
|
+
}
|
|
315
|
+
}, {
|
|
316
|
+
$unset: {
|
|
317
|
+
snapshot: ''
|
|
318
|
+
}
|
|
319
|
+
}, {
|
|
320
|
+
session
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
//# sourceMappingURL=migrateLocalizeStatus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/predefinedMigrations/migrateLocalizeStatus.ts"],"sourcesContent":["import type { ClientSession } from 'mongoose'\nimport type { Payload, PayloadRequest } from 'payload'\n\nimport { calculateVersionLocaleStatuses, type VersionRecord } from 'payload/migrations'\n\nimport type { MongooseAdapter } from '../index.js'\n\nimport { getSession } from '../utilities/getSession.js'\n\nexport type LocalizeStatusArgs = {\n collectionSlug?: string\n globalSlug?: string\n payload: Payload\n req?: any\n session?: ClientSession\n}\n\n/**\n * Migrate all collections and globals with versions.drafts enabled to use per-locale _status.\n *\n * This migration:\n * 1. Converts version._status from a scalar string to a locale-keyed object for each entity\n * 2. Deletes all snapshot:true version documents from each versions collection\n * 3. Unsets the `snapshot` field from remaining version documents\n */\nexport async function migrateLocalizeStatus({\n payload,\n req,\n}: {\n payload: Payload\n req: PayloadRequest\n}): Promise<void> {\n if (!payload.config.localization) {\n payload.logger.info({\n msg: 'Localization not enabled, skipping localize-status migration',\n })\n return\n }\n\n const collections = payload.config.collections.filter(\n (c) =>\n c.versions?.drafts &&\n typeof c.versions.drafts === 'object' &&\n c.versions.drafts.localizeStatus,\n )\n const globals = payload.config.globals.filter(\n (g) =>\n g.versions?.drafts &&\n typeof g.versions.drafts === 'object' &&\n g.versions.drafts.localizeStatus,\n )\n\n payload.logger.info({\n msg: `Starting localize-status migration for ${collections.length} collection(s) and ${globals.length} global(s)`,\n })\n\n const connection = (payload.db as any).connection\n const session = await getSession(payload.db as MongooseAdapter, req)\n\n for (const collection of collections) {\n await localizeStatus({ collectionSlug: collection.slug, payload, req, session })\n await cleanupSnapshotDocuments({ connection, entitySlug: collection.slug, payload, session })\n }\n\n for (const global of globals) {\n await localizeStatus({ globalSlug: global.slug, payload, req, session })\n await cleanupSnapshotDocuments({ connection, entitySlug: global.slug, payload, session })\n }\n\n payload.logger.info({ msg: 'localize-status migration completed successfully' })\n}\n\n/**\n * Converts version._status (and the main document _status) from a scalar string to a\n * per-locale object for a single collection or global.\n */\nexport async function localizeStatus(args: LocalizeStatusArgs): Promise<void> {\n const { collectionSlug, globalSlug, payload, req, session } = args\n\n if (!collectionSlug && !globalSlug) {\n throw new Error('Either collectionSlug or globalSlug must be provided')\n }\n\n if (collectionSlug && globalSlug) {\n throw new Error('Cannot provide both collectionSlug and globalSlug')\n }\n\n const entitySlug = collectionSlug || globalSlug\n // MongoDB collection names are case-insensitive and stored as lowercase\n const versionsCollection = `_${entitySlug}_versions`.toLowerCase()\n\n if (!payload.config.localization) {\n throw new Error('Localization is not enabled in payload config')\n }\n\n // Check if versions are enabled on this collection/global\n let entityConfig\n if (collectionSlug) {\n const collection = payload.config.collections.find((c) => c.slug === collectionSlug)\n if (collection) {\n entityConfig = collection\n }\n } else if (globalSlug) {\n const global = payload.config.globals.find((g) => g.slug === globalSlug)\n if (global) {\n entityConfig = global\n }\n }\n\n if (!entityConfig) {\n throw new Error(\n `${collectionSlug ? 'Collection' : 'Global'} not found: ${collectionSlug || globalSlug}`,\n )\n }\n\n payload.logger.info({\n msg: `Starting _status localization migration for ${collectionSlug ? 'collection' : 'global'}: ${entitySlug}`,\n })\n\n // Check if versions are enabled in config (skip if not)\n if (!entityConfig.versions) {\n payload.logger.info({\n msg: `Skipping migration for ${collectionSlug ? 'collection' : 'global'}: ${entitySlug} - versions not enabled`,\n })\n return\n }\n\n // Get MongoDB connection\n const connection = (payload.db as any).connection\n\n // Get filtered locales if filterAvailableLocales is defined\n let locales = payload.config.localization.localeCodes\n if (typeof payload.config.localization.filterAvailableLocales === 'function') {\n const filteredLocaleObjects = await payload.config.localization.filterAvailableLocales({\n locales: payload.config.localization.locales,\n req,\n })\n locales = filteredLocaleObjects.map((locale) => locale.code)\n }\n payload.logger.info({ msg: `Locales: ${locales.join(', ')}` })\n\n // Check if version._status exists and is NOT already localized\n const sampleDoc = await connection.collection(versionsCollection).findOne({}, { session })\n\n if (!sampleDoc) {\n payload.logger.info({ msg: 'No version documents found, nothing to migrate' })\n return\n }\n\n // Check if _status is already localized\n if (\n sampleDoc.version?._status &&\n typeof sampleDoc.version._status === 'object' &&\n !Array.isArray(sampleDoc.version._status)\n ) {\n payload.logger.info({\n msg: 'version._status is already localized, migration already completed',\n })\n return\n }\n\n // Validate that version._status exists and is a string\n if (\n !sampleDoc.version ||\n typeof sampleDoc.version._status !== 'string' ||\n Array.isArray(sampleDoc.version._status)\n ) {\n throw new Error(\n `Migration aborted: version._status field not found or has unexpected format in ${versionsCollection}. ` +\n `This migration should only run on schemas that have NOT yet been migrated to per-locale status.`,\n )\n }\n\n payload.logger.info({ msg: 'Fetching all version documents...' })\n\n // Get all versions, sorted chronologically\n const allVersions = await connection\n .collection(versionsCollection)\n .find({}, { session })\n .sort({ createdAt: 1, parent: 1 })\n .toArray()\n\n payload.logger.info({ msg: `Found ${allVersions.length} version documents` })\n\n // Transform MongoDB documents to VersionRecord format\n const versionRecords: VersionRecord[] = allVersions.map((doc: any) => ({\n id: doc._id.toString(),\n _status: doc.version._status as 'draft' | 'published',\n createdAt: doc.createdAt,\n parent: doc.parent?.toString(),\n publishedLocale: doc.publishedLocale,\n snapshot: doc.snapshot || false,\n }))\n\n // Calculate status per locale using shared logic\n const versionLocaleStatus = calculateVersionLocaleStatuses(versionRecords, locales, payload)\n\n payload.logger.info({ msg: 'Updating version documents with per-locale status...' })\n\n // Update each version document\n let updateCount = 0\n for (const doc of allVersions) {\n const versionId = doc._id.toString()\n const localeStatusMap = versionLocaleStatus.get(versionId)\n\n if (!localeStatusMap) {\n payload.logger.warn({ msg: `No status map found for version ${versionId}, skipping` })\n continue\n }\n\n // Build the new _status object: { en: 'published', es: 'draft', ... }\n const newStatus: Record<string, string> = {}\n for (const [locale, status] of localeStatusMap.entries()) {\n newStatus[locale] = status\n }\n\n // Update the document: change version._status from string to object\n await connection.collection(versionsCollection).updateOne(\n { _id: doc._id },\n {\n $set: {\n 'version._status': newStatus,\n },\n },\n { session },\n )\n\n updateCount++\n }\n\n payload.logger.info({ msg: `Updated ${updateCount} version documents` })\n\n // Migrate main collection/global document _status to per-locale status object\n // Only if it has a status field\n if (collectionSlug) {\n const mainCollection = collectionSlug\n const mainDoc = await connection.collection(mainCollection).findOne({}, { session })\n\n if (mainDoc && '_status' in mainDoc) {\n payload.logger.info({ msg: `Migrating main collection documents for: ${mainCollection}` })\n\n const allDocs = await connection.collection(mainCollection).find({}, { session }).toArray()\n\n for (const doc of allDocs) {\n if (!doc._id) {\n continue\n }\n\n // Get the latest version for this document to determine status per locale\n const latestVersions = await connection\n .collection(versionsCollection)\n .find({ parent: doc._id }, { session })\n .sort({ createdAt: -1 })\n .limit(1)\n .toArray()\n\n let statusObj: Record<string, string> = {}\n\n if (latestVersions.length > 0 && latestVersions[0]?.version?._status) {\n // Use the status from the latest version\n statusObj = latestVersions[0].version._status\n } else {\n // Fallback: set all locales to draft\n for (const locale of locales) {\n statusObj[locale] = 'draft'\n }\n }\n\n // Update main document\n await connection.collection(mainCollection).updateOne(\n { _id: doc._id },\n {\n $set: {\n _status: statusObj,\n },\n },\n { session },\n )\n }\n\n payload.logger.info({ msg: `Migrated ${allDocs.length} collection documents` })\n } else {\n payload.logger.info({\n msg: 'Skipping main document status migration (no status field found)',\n })\n }\n } else if (globalSlug) {\n // Globals are stored in a single 'globals' collection with globalType discriminator\n const globalDoc = await connection\n .collection('globals')\n .findOne({ globalType: globalSlug }, { session })\n if (globalDoc && '_status' in globalDoc && globalDoc._id) {\n payload.logger.info({ msg: `Migrating main global document for: ${globalSlug}` })\n\n // Get the latest version for the global\n const latestVersions = await connection\n .collection(versionsCollection)\n .find({}, { session })\n .sort({ createdAt: -1 })\n .limit(1)\n .toArray()\n\n let statusObj: Record<string, string> = {}\n\n if (latestVersions.length > 0 && latestVersions[0]?.version?._status) {\n statusObj = latestVersions[0].version._status\n } else {\n for (const locale of locales) {\n statusObj[locale] = 'draft'\n }\n }\n\n // Update global document\n await connection.collection('globals').updateOne(\n { _id: globalDoc._id, globalType: globalSlug },\n {\n $set: {\n _status: statusObj,\n },\n },\n { session },\n )\n\n payload.logger.info({ msg: 'Migrated global document' })\n } else {\n payload.logger.info({\n msg: 'Skipping main document status migration (no status field found)',\n })\n }\n }\n\n payload.logger.info({ msg: 'Migration completed successfully' })\n}\n\nasync function cleanupSnapshotDocuments({\n connection,\n entitySlug,\n payload,\n session,\n}: {\n connection: any\n entitySlug: string\n payload: Payload\n session?: ClientSession\n}): Promise<void> {\n const versionsCollection = `_${entitySlug}_versions`.toLowerCase()\n\n const col = connection.collection(versionsCollection)\n\n // Delete all snapshot=true documents\n const deleteResult = await col.deleteMany({ snapshot: true }, { session })\n\n if (deleteResult.deletedCount > 0) {\n payload.logger.info({\n msg: `Deleted ${deleteResult.deletedCount} snapshot documents from ${versionsCollection}`,\n })\n }\n\n // Unset the snapshot field from remaining documents\n await col.updateMany({ snapshot: { $exists: true } }, { $unset: { snapshot: '' } }, { session })\n}\n"],"names":["calculateVersionLocaleStatuses","getSession","migrateLocalizeStatus","payload","req","config","localization","logger","info","msg","collections","filter","c","versions","drafts","localizeStatus","globals","g","length","connection","db","session","collection","collectionSlug","slug","cleanupSnapshotDocuments","entitySlug","global","globalSlug","args","Error","versionsCollection","toLowerCase","entityConfig","find","locales","localeCodes","filterAvailableLocales","filteredLocaleObjects","map","locale","code","join","sampleDoc","findOne","version","_status","Array","isArray","allVersions","sort","createdAt","parent","toArray","versionRecords","doc","id","_id","toString","publishedLocale","snapshot","versionLocaleStatus","updateCount","versionId","localeStatusMap","get","warn","newStatus","status","entries","updateOne","$set","mainCollection","mainDoc","allDocs","latestVersions","limit","statusObj","globalDoc","globalType","col","deleteResult","deleteMany","deletedCount","updateMany","$exists","$unset"],"mappings":"AAGA,SAASA,8BAA8B,QAA4B,qBAAoB;AAIvF,SAASC,UAAU,QAAQ,6BAA4B;AAUvD;;;;;;;CAOC,GACD,OAAO,eAAeC,sBAAsB,EAC1CC,OAAO,EACPC,GAAG,EAIJ;IACC,IAAI,CAACD,QAAQE,MAAM,CAACC,YAAY,EAAE;QAChCH,QAAQI,MAAM,CAACC,IAAI,CAAC;YAClBC,KAAK;QACP;QACA;IACF;IAEA,MAAMC,cAAcP,QAAQE,MAAM,CAACK,WAAW,CAACC,MAAM,CACnD,CAACC,IACCA,EAAEC,QAAQ,EAAEC,UACZ,OAAOF,EAAEC,QAAQ,CAACC,MAAM,KAAK,YAC7BF,EAAEC,QAAQ,CAACC,MAAM,CAACC,cAAc;IAEpC,MAAMC,UAAUb,QAAQE,MAAM,CAACW,OAAO,CAACL,MAAM,CAC3C,CAACM,IACCA,EAAEJ,QAAQ,EAAEC,UACZ,OAAOG,EAAEJ,QAAQ,CAACC,MAAM,KAAK,YAC7BG,EAAEJ,QAAQ,CAACC,MAAM,CAACC,cAAc;IAGpCZ,QAAQI,M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WAAW,SAAS,CAAC,CAACM,WAAW;IAEhE,MAAMgD,MAAM7D,WAAWG,UAAU,CAACS;IAElC,qCAAqC;IACrC,MAAMkD,eAAe,MAAMD,IAAIE,UAAU,CAAC;QAAEtB,UAAU;IAAK,GAAG;QAAEvC;IAAQ;IAExE,IAAI4D,aAAaE,YAAY,GAAG,GAAG;QACjChF,QAAQI,MAAM,CAACC,IAAI,CAAC;YAClBC,KAAK,CAAC,QAAQ,EAAEwE,aAAaE,YAAY,CAAC,yBAAyB,EAAEpD,oBAAoB;QAC3F;IACF;IAEA,oDAAoD;IACpD,MAAMiD,IAAII,UAAU,CAAC;QAAExB,UAAU;YAAEyB,SAAS;QAAK;IAAE,GAAG;QAAEC,QAAQ;YAAE1B,UAAU;QAAG;IAAE,GAAG;QAAEvC;IAAQ;AAChG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildQuery.d.ts","sourceRoot":"","sources":["../../src/queries/buildQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAEpD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAIlD,eAAO,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"buildQuery.d.ts","sourceRoot":"","sources":["../../src/queries/buildQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAEpD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAIlD,eAAO,MAAM,UAAU,GAAU,iEAO9B;IACD,OAAO,EAAE,eAAe,CAAA;IACxB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,KAAK,CAAA;CACb,qCAYA,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildSortParam.d.ts","sourceRoot":"","sources":["../../src/queries/buildSortParam.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAE7C,OAAO,EAEL,KAAK,cAAc,EAEnB,KAAK,eAAe,EACpB,KAAK,IAAI,EACV,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAKlD,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,eAAe,CAAA;IACxB,MAAM,EAAE,eAAe,CAAA;IACvB,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B,IAAI,CAAC,EAAE,IAAI,CAAA;IACX,eAAe,CAAC,EAAE,aAAa,EAAE,CAAA;IACjC,UAAU,EAAE,OAAO,CAAA;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA;AAED,MAAM,MAAM,QAAQ,GAAG;IACrB,SAAS,EAAE,aAAa,CAAA;IACxB,QAAQ,EAAE,MAAM,CAAA;CACjB,EAAE,CAAA;AAEH,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,MAAM,CAAA;AAgH1C,eAAO,MAAM,cAAc,
|
|
1
|
+
{"version":3,"file":"buildSortParam.d.ts","sourceRoot":"","sources":["../../src/queries/buildSortParam.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAE7C,OAAO,EAEL,KAAK,cAAc,EAEnB,KAAK,eAAe,EACpB,KAAK,IAAI,EACV,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAKlD,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,eAAe,CAAA;IACxB,MAAM,EAAE,eAAe,CAAA;IACvB,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B,IAAI,CAAC,EAAE,IAAI,CAAA;IACX,eAAe,CAAC,EAAE,aAAa,EAAE,CAAA;IACjC,UAAU,EAAE,OAAO,CAAA;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA;AAED,MAAM,MAAM,QAAQ,GAAG;IACrB,SAAS,EAAE,aAAa,CAAA;IACxB,QAAQ,EAAE,MAAM,CAAA;CACjB,EAAE,CAAA;AAEH,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,MAAM,CAAA;AAgH1C,eAAO,MAAM,cAAc,GAAI,sGAU5B,IAAI,KAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAgF9B,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getBuildQueryPlugin.d.ts","sourceRoot":"","sources":["../../src/queries/getBuildQueryPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAM7D,KAAK,uBAAuB,GAAG;IAC7B,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,cAAc,CAAC,EAAE,cAAc,EAAE,CAAA;CAClC,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,KAAK,CAAA;CACb,CAAA;AAKD,eAAO,MAAM,mBAAmB,
|
|
1
|
+
{"version":3,"file":"getBuildQueryPlugin.d.ts","sourceRoot":"","sources":["../../src/queries/getBuildQueryPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAM7D,KAAK,uBAAuB,GAAG;IAC7B,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,cAAc,CAAC,EAAE,cAAc,EAAE,CAAA;CAClC,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,KAAK,CAAA;CACb,CAAA;AAKD,eAAO,MAAM,mBAAmB,GAAI,sCAGjC,uBAA4B,MACI,QAAQ,GAAG,SAmD7C,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getLocalizedSortProperty.d.ts","sourceRoot":"","sources":["../../src/queries/getLocalizedSortProperty.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAI9D,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,eAAe,CAAA;IACvB,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,iBAAiB,EAAE,OAAO,CAAA;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,EAAE,CAAA;CACnB,CAAA;AAED,eAAO,MAAM,wBAAwB,
|
|
1
|
+
{"version":3,"file":"getLocalizedSortProperty.d.ts","sourceRoot":"","sources":["../../src/queries/getLocalizedSortProperty.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAI9D,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,eAAe,CAAA;IACvB,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,iBAAiB,EAAE,OAAO,CAAA;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,EAAE,CAAA;CACnB,CAAA;AAED,eAAO,MAAM,wBAAwB,GAAI,oGAOtC,IAAI,KAAG,MA8FT,CAAA"}
|
|
@@ -45,7 +45,7 @@ export const getLocalizedSortProperty = ({ config, fields, locale, parentIsLocal
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
if (matchedField.type === 'blocks') {
|
|
48
|
-
nextFields =
|
|
48
|
+
nextFields = matchedField.blocks.reduce((flattenedBlockFields, _block)=>{
|
|
49
49
|
// TODO: iterate over blocks mapped to block slug in v4, or pass through payload.blocks
|
|
50
50
|
const block = typeof _block === 'string' ? config.blocks?.find((b)=>b.slug === _block) : _block;
|
|
51
51
|
if (!block) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/queries/getLocalizedSortProperty.ts"],"sourcesContent":["import type { FlattenedField, SanitizedConfig } from 'payload'\n\nimport { fieldAffectsData, fieldIsPresentationalOnly, fieldShouldBeLocalized } from 'payload/shared'\n\ntype Args = {\n config: SanitizedConfig\n fields: FlattenedField[]\n locale?: string\n parentIsLocalized: boolean\n result?: string\n segments: string[]\n}\n\nexport const getLocalizedSortProperty = ({\n config,\n fields,\n locale,\n parentIsLocalized,\n result: incomingResult,\n segments: incomingSegments,\n}: Args): string => {\n // If localization is not enabled, accept exactly\n // what is sent in\n if (!config.localization) {\n return incomingSegments.join('.')\n }\n\n const segments = [...incomingSegments]\n\n // Retrieve first segment, and remove from segments\n const firstSegment = segments.shift()\n\n // Attempt to find a matched field\n const matchedField = fields.find(\n (field) => fieldAffectsData(field) && field.name === firstSegment,\n )\n\n if (matchedField && !fieldIsPresentationalOnly(matchedField)) {\n let nextFields: FlattenedField[] | null = null\n let nextParentIsLocalized = parentIsLocalized\n const remainingSegments = [...segments]\n let localizedSegment = matchedField.name\n\n if (\n fieldShouldBeLocalized({ field: matchedField, parentIsLocalized: parentIsLocalized ?? false })\n ) {\n // Check to see if next segment is a locale\n if (segments.length > 0 && remainingSegments[0]) {\n const nextSegmentIsLocale = config.localization.localeCodes.includes(remainingSegments[0])\n\n // If next segment is locale, remove it from remaining segments\n // and use it to localize the current segment\n if (nextSegmentIsLocale) {\n const nextSegment = remainingSegments.shift()\n localizedSegment = `${matchedField.name}.${nextSegment}`\n }\n } else {\n // If no more segments, but field is localized, use default locale\n localizedSegment = `${matchedField.name}.${locale}`\n }\n }\n\n // If there are subfields, pass them through\n if (\n matchedField.type === 'tab' ||\n matchedField.type === 'group' ||\n matchedField.type === 'array'\n ) {\n nextFields = matchedField.flattenedFields\n if (!nextParentIsLocalized) {\n nextParentIsLocalized = matchedField.localized ?? false\n }\n }\n\n if (matchedField.type === 'blocks') {\n nextFields =
|
|
1
|
+
{"version":3,"sources":["../../src/queries/getLocalizedSortProperty.ts"],"sourcesContent":["import type { FlattenedField, SanitizedConfig } from 'payload'\n\nimport { fieldAffectsData, fieldIsPresentationalOnly, fieldShouldBeLocalized } from 'payload/shared'\n\ntype Args = {\n config: SanitizedConfig\n fields: FlattenedField[]\n locale?: string\n parentIsLocalized: boolean\n result?: string\n segments: string[]\n}\n\nexport const getLocalizedSortProperty = ({\n config,\n fields,\n locale,\n parentIsLocalized,\n result: incomingResult,\n segments: incomingSegments,\n}: Args): string => {\n // If localization is not enabled, accept exactly\n // what is sent in\n if (!config.localization) {\n return incomingSegments.join('.')\n }\n\n const segments = [...incomingSegments]\n\n // Retrieve first segment, and remove from segments\n const firstSegment = segments.shift()\n\n // Attempt to find a matched field\n const matchedField = fields.find(\n (field) => fieldAffectsData(field) && field.name === firstSegment,\n )\n\n if (matchedField && !fieldIsPresentationalOnly(matchedField)) {\n let nextFields: FlattenedField[] | null = null\n let nextParentIsLocalized = parentIsLocalized\n const remainingSegments = [...segments]\n let localizedSegment = matchedField.name\n\n if (\n fieldShouldBeLocalized({ field: matchedField, parentIsLocalized: parentIsLocalized ?? false })\n ) {\n // Check to see if next segment is a locale\n if (segments.length > 0 && remainingSegments[0]) {\n const nextSegmentIsLocale = config.localization.localeCodes.includes(remainingSegments[0])\n\n // If next segment is locale, remove it from remaining segments\n // and use it to localize the current segment\n if (nextSegmentIsLocale) {\n const nextSegment = remainingSegments.shift()\n localizedSegment = `${matchedField.name}.${nextSegment}`\n }\n } else {\n // If no more segments, but field is localized, use default locale\n localizedSegment = `${matchedField.name}.${locale}`\n }\n }\n\n // If there are subfields, pass them through\n if (\n matchedField.type === 'tab' ||\n matchedField.type === 'group' ||\n matchedField.type === 'array'\n ) {\n nextFields = matchedField.flattenedFields\n if (!nextParentIsLocalized) {\n nextParentIsLocalized = matchedField.localized ?? false\n }\n }\n\n if (matchedField.type === 'blocks') {\n nextFields = matchedField.blocks.reduce<FlattenedField[]>((flattenedBlockFields, _block) => {\n // TODO: iterate over blocks mapped to block slug in v4, or pass through payload.blocks\n const block =\n typeof _block === 'string' ? config.blocks?.find((b) => b.slug === _block) : _block\n\n if (!block) {\n return [...flattenedBlockFields]\n }\n\n return [\n ...flattenedBlockFields,\n ...block.flattenedFields.filter(\n (blockField) =>\n (fieldAffectsData(blockField) &&\n blockField.name !== 'blockType' &&\n blockField.name !== 'blockName') ||\n !fieldAffectsData(blockField),\n ),\n ]\n }, [])\n }\n\n const result = incomingResult ? `${incomingResult}.${localizedSegment}` : localizedSegment\n\n if (nextFields !== null) {\n return getLocalizedSortProperty({\n config,\n fields: nextFields,\n locale,\n parentIsLocalized: nextParentIsLocalized,\n result,\n segments: remainingSegments,\n })\n }\n\n return result\n }\n\n return incomingSegments.join('.')\n}\n"],"names":["fieldAffectsData","fieldIsPresentationalOnly","fieldShouldBeLocalized","getLocalizedSortProperty","config","fields","locale","parentIsLocalized","result","incomingResult","segments","incomingSegments","localization","join","firstSegment","shift","matchedField","find","field","name","nextFields","nextParentIsLocalized","remainingSegments","localizedSegment","length","nextSegmentIsLocale","localeCodes","includes","nextSegment","type","flattenedFields","localized","blocks","reduce","flattenedBlockFields","_block","block","b","slug","filter","blockField"],"mappings":"AAEA,SAASA,gBAAgB,EAAEC,yBAAyB,EAAEC,sBAAsB,QAAQ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ACAT,aAAaJ,aAAac,eAAe;YACzC,IAAI,CAACT,uBAAuB;gBAC1BA,wBAAwBL,aAAae,SAAS,IAAI;YACpD;QACF;QAEA,IAAIf,aAAaa,IAAI,KAAK,UAAU;YAClCT,aAAaJ,aAAagB,MAAM,CAACC,MAAM,CAAmB,CAACC,sBAAsBC;gBAC/E,uFAAuF;gBACvF,MAAMC,QACJ,OAAOD,WAAW,WAAW/B,OAAO4B,MAAM,EAAEf,KAAK,CAACoB,IAAMA,EAAEC,IAAI,KAAKH,UAAUA;gBAE/E,IAAI,CAACC,OAAO;oBACV,OAAO;2BAAIF;qBAAqB;gBAClC;gBAEA,OAAO;uBACFA;uBACAE,MAAMN,eAAe,CAACS,MAAM,CAC7B,CAACC,aACC,AAACxC,iBAAiBwC,eAChBA,WAAWrB,IAAI,KAAK,eACpBqB,WAAWrB,IAAI,KAAK,eACtB,CAACnB,iBAAiBwC;iBAEvB;YACH,GAAG,EAAE;QACP;QAEA,MAAMhC,SAASC,iBAAiB,GAAGA,eAAe,CAAC,EAAEc,kBAAkB,GAAGA;QAE1E,IAAIH,eAAe,MAAM;YACvB,OAAOjB,yBAAyB;gBAC9BC;gBACAC,QAAQe;gBACRd;gBACAC,mBAAmBc;gBACnBb;gBACAE,UAAUY;YACZ;QACF;QAEA,OAAOd;IACT;IAEA,OAAOG,iBAAiBE,IAAI,CAAC;AAC/B,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sanitizeQueryValue.d.ts","sourceRoot":"","sources":["../../src/queries/sanitizeQueryValue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"sanitizeQueryValue.d.ts","sourceRoot":"","sources":["../../src/queries/sanitizeQueryValue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,cAAc,EAAE,QAAQ,EAAE,OAAO,EAAqB,MAAM,SAAS,CAAA;AAMnG,KAAK,sBAAsB,GAAG;IAC5B,KAAK,EAAE,cAAc,CAAA;IACrB,WAAW,EAAE,OAAO,CAAA;IACpB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,QAAQ,CAAA;IAClB,iBAAiB,EAAE,OAAO,CAAA;IAC1B,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,EAAE,GAAG,CAAA;CACT,CAAA;AAmED,eAAO,MAAM,kBAAkB,GAAI,kFAShC,sBAAsB,KACrB;IACE,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,GAAG,CAAC,EAAE,OAAO,CAAA;CACd,GACD,SAycH,CAAA"}
|
|
@@ -54,9 +54,8 @@ const buildExistsQuery = (formattedValue, path, treatEmptyString = true)=>{
|
|
|
54
54
|
};
|
|
55
55
|
// returns nestedField Field object from blocks.nestedField path because getLocalizedPaths splits them only for relationships
|
|
56
56
|
const getFieldFromSegments = ({ field, payload, segments })=>{
|
|
57
|
-
if ('blocks' in field
|
|
58
|
-
const
|
|
59
|
-
for (const _block of _field.blockReferences ?? _field.blocks){
|
|
57
|
+
if ('blocks' in field) {
|
|
58
|
+
for (const _block of field.blocks){
|
|
60
59
|
const block = typeof _block === 'string' ? payload.blocks[_block] : _block;
|
|
61
60
|
if (block) {
|
|
62
61
|
const field = getFieldFromSegments({
|