@payloadcms/db-mongodb 4.0.0-internal.f05c47f → 4.0.0-internal.f15737c
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 +8 -2
- package/dist/connect.js.map +1 -1
- package/dist/count.d.ts.map +1 -1
- package/dist/count.js +2 -8
- package/dist/count.js.map +1 -1
- package/dist/create.d.ts.map +1 -1
- package/dist/create.js +2 -1
- package/dist/create.js.map +1 -1
- package/dist/createGlobalVersion.d.ts.map +1 -1
- package/dist/createGlobalVersion.js +1 -23
- package/dist/createGlobalVersion.js.map +1 -1
- package/dist/createMigration.d.ts.map +1 -1
- package/dist/createMigration.js +9 -2
- package/dist/createMigration.js.map +1 -1
- package/dist/createVersion.d.ts.map +1 -1
- package/dist/createVersion.js +4 -17
- package/dist/createVersion.js.map +1 -1
- package/dist/deleteOne.d.ts.map +1 -1
- package/dist/deleteOne.js +1 -18
- 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/find.d.ts.map +1 -1
- package/dist/find.js +4 -17
- package/dist/find.js.map +1 -1
- package/dist/findDistinct.d.ts.map +1 -1
- package/dist/findDistinct.js +52 -8
- package/dist/findDistinct.js.map +1 -1
- package/dist/findGlobal.d.ts.map +1 -1
- package/dist/findGlobal.js +4 -26
- package/dist/findGlobal.js.map +1 -1
- package/dist/findGlobalVersions.d.ts.map +1 -1
- package/dist/findGlobalVersions.js +2 -8
- package/dist/findGlobalVersions.js.map +1 -1
- package/dist/findOne.d.ts.map +1 -1
- package/dist/findOne.js +3 -19
- package/dist/findOne.js.map +1 -1
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +89 -67
- package/dist/init.js.map +1 -1
- package/dist/migrateFresh.d.ts +4 -2
- package/dist/migrateFresh.d.ts.map +1 -1
- package/dist/migrateFresh.js +21 -6
- package/dist/migrateFresh.js.map +1 -1
- package/dist/models/buildCollectionSchema.d.ts +8 -2
- package/dist/models/buildCollectionSchema.d.ts.map +1 -1
- package/dist/models/buildCollectionSchema.js +4 -2
- package/dist/models/buildCollectionSchema.js.map +1 -1
- package/dist/models/buildGlobalModel.d.ts +5 -1
- package/dist/models/buildGlobalModel.d.ts.map +1 -1
- package/dist/models/buildGlobalModel.js +4 -2
- package/dist/models/buildGlobalModel.js.map +1 -1
- package/dist/models/buildSchema.d.ts +4 -0
- package/dist/models/buildSchema.d.ts.map +1 -1
- package/dist/models/buildSchema.js +64 -26
- package/dist/models/buildSchema.js.map +1 -1
- package/dist/models/schemaBuildContext.d.ts +21 -0
- package/dist/models/schemaBuildContext.d.ts.map +1 -0
- package/dist/models/schemaBuildContext.js +29 -0
- package/dist/models/schemaBuildContext.js.map +1 -0
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts.map +1 -1
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js +4 -4
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js.map +1 -1
- package/dist/predefinedMigrations/migrateSizesToVariants.d.ts +13 -0
- package/dist/predefinedMigrations/migrateSizesToVariants.d.ts.map +1 -0
- package/dist/predefinedMigrations/migrateSizesToVariants.js +368 -0
- package/dist/predefinedMigrations/migrateSizesToVariants.js.map +1 -0
- package/dist/predefinedMigrations/sizes-to-variants.d.ts +5 -0
- package/dist/predefinedMigrations/sizes-to-variants.d.ts.map +1 -0
- package/dist/predefinedMigrations/sizes-to-variants.js +8 -0
- package/dist/predefinedMigrations/sizes-to-variants.js.map +1 -0
- package/dist/queries/buildSearchParams.d.ts.map +1 -1
- package/dist/queries/buildSearchParams.js +189 -6
- package/dist/queries/buildSearchParams.js.map +1 -1
- package/dist/queries/parseParams.js.map +1 -1
- package/dist/queryDrafts.d.ts.map +1 -1
- package/dist/queryDrafts.js +4 -12
- package/dist/queryDrafts.js.map +1 -1
- package/dist/updateGlobal.d.ts.map +1 -1
- package/dist/updateGlobal.js +9 -62
- package/dist/updateGlobal.js.map +1 -1
- package/dist/updateGlobalVersion.js +2 -2
- package/dist/updateGlobalVersion.js.map +1 -1
- package/dist/updateJobs.js +1 -1
- package/dist/updateJobs.js.map +1 -1
- package/dist/updateMany.d.ts.map +1 -1
- package/dist/updateMany.js +0 -1
- package/dist/updateMany.js.map +1 -1
- package/dist/updateOne.d.ts.map +1 -1
- package/dist/updateOne.js +3 -12
- package/dist/updateOne.js.map +1 -1
- package/dist/updateVersion.js +2 -2
- package/dist/updateVersion.js.map +1 -1
- package/dist/utilities/aggregatePaginate.d.ts.map +1 -1
- package/dist/utilities/aggregatePaginate.js +3 -1
- package/dist/utilities/aggregatePaginate.js.map +1 -1
- package/dist/utilities/buildJoinAggregation.d.ts +2 -3
- package/dist/utilities/buildJoinAggregation.d.ts.map +1 -1
- package/dist/utilities/buildJoinAggregation.js +6 -33
- package/dist/utilities/buildJoinAggregation.js.map +1 -1
- package/dist/utilities/resolveJoins.d.ts +2 -4
- package/dist/utilities/resolveJoins.d.ts.map +1 -1
- package/dist/utilities/resolveJoins.js +2 -16
- package/dist/utilities/resolveJoins.js.map +1 -1
- package/package.json +5 -5
- package/dist/queries/buildSortParam.spec.js +0 -123
- package/dist/queries/buildSortParam.spec.js.map +0 -1
- package/dist/queries/getLocalizedSortProperty.spec.js +0 -215
- package/dist/queries/getLocalizedSortProperty.spec.js.map +0 -1
- package/dist/utilities/transform.spec.js +0 -546
- package/dist/utilities/transform.spec.js.map +0 -1
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
2
|
+
import { getSession } from '../utilities/getSession.js';
|
|
3
|
+
/** Mongo error codes for an index that conflicts with an existing index. */ const INDEX_CONFLICT_CODES = new Set([
|
|
4
|
+
85,
|
|
5
|
+
86
|
|
6
|
+
]);
|
|
7
|
+
/** Mongo error code for a collection that hasn't been created yet. */ const NAMESPACE_NOT_FOUND_CODE = 26;
|
|
8
|
+
const GENERATED_VARIANT_METADATA_FIELDS = new Set([
|
|
9
|
+
'filename',
|
|
10
|
+
'filesize',
|
|
11
|
+
'height',
|
|
12
|
+
'mimeType',
|
|
13
|
+
'url',
|
|
14
|
+
'width'
|
|
15
|
+
]);
|
|
16
|
+
/**
|
|
17
|
+
* Moves every upload collection's stored image sizes between the legacy `sizes` field and
|
|
18
|
+
* `variants`, on each collection and its versions collection (`version.sizes`). Uses `$rename`,
|
|
19
|
+
* so no document is rewritten beyond the renamed key, and re-keys the indexes on those fields.
|
|
20
|
+
* Documents that are already renamed are left as they are, so it's safe to re-run.
|
|
21
|
+
*/ export async function migrateSizesToVariants({ direction = 'up', payload, req }) {
|
|
22
|
+
const adapter = payload.db;
|
|
23
|
+
const session = await getSession(adapter, req);
|
|
24
|
+
const [from, to] = direction === 'up' ? [
|
|
25
|
+
'sizes',
|
|
26
|
+
'variants'
|
|
27
|
+
] : [
|
|
28
|
+
'variants',
|
|
29
|
+
'sizes'
|
|
30
|
+
];
|
|
31
|
+
const targets = [];
|
|
32
|
+
for (const collection of payload.config.collections){
|
|
33
|
+
if (!collection.upload) {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
const upload = typeof collection.upload === 'object' ? collection.upload : undefined;
|
|
37
|
+
const expectedVariantNames = (upload?.variants ?? []).map(({ name })=>name);
|
|
38
|
+
targets.push({
|
|
39
|
+
collection: adapter.collections[collection.slug].collection,
|
|
40
|
+
expectedVariantNames,
|
|
41
|
+
fromPath: from,
|
|
42
|
+
toPath: to
|
|
43
|
+
});
|
|
44
|
+
if (collection.versions && adapter.versions[collection.slug]) {
|
|
45
|
+
targets.push({
|
|
46
|
+
collection: adapter.versions[collection.slug].collection,
|
|
47
|
+
expectedVariantNames,
|
|
48
|
+
fromPath: `version.${from}`,
|
|
49
|
+
toPath: `version.${to}`
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
for (const { collection, expectedVariantNames, fromPath, toPath } of targets){
|
|
54
|
+
const [sourceData, directCollision] = await Promise.all([
|
|
55
|
+
collection.findOne({
|
|
56
|
+
[fromPath]: {
|
|
57
|
+
$exists: true
|
|
58
|
+
}
|
|
59
|
+
}, {
|
|
60
|
+
projection: {
|
|
61
|
+
_id: 1
|
|
62
|
+
}
|
|
63
|
+
}),
|
|
64
|
+
collection.findOne({
|
|
65
|
+
[fromPath]: {
|
|
66
|
+
$exists: true
|
|
67
|
+
},
|
|
68
|
+
[toPath]: {
|
|
69
|
+
$exists: true
|
|
70
|
+
}
|
|
71
|
+
}, {
|
|
72
|
+
projection: {
|
|
73
|
+
_id: 1
|
|
74
|
+
}
|
|
75
|
+
})
|
|
76
|
+
]);
|
|
77
|
+
if (sourceData && (directCollision || await findUnexpectedDestinationData({
|
|
78
|
+
collection,
|
|
79
|
+
expectedVariantNames,
|
|
80
|
+
toPath
|
|
81
|
+
}))) {
|
|
82
|
+
throw new Error(`Cannot run the sizes-to-variants migration because collection "${collection.collectionName}" contains both "${fromPath}" and "${toPath}" data. Move or rename the existing destination data before running this migration.`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
// Index changes can't be part of a multi-document transaction, and one made after the
|
|
86
|
+
// migration's transaction has written to a collection aborts it. A transaction's snapshot starts
|
|
87
|
+
// at its first operation, so re-keying every index before any transactional write is safe.
|
|
88
|
+
for (const target of targets){
|
|
89
|
+
await rekeyIndexes(target);
|
|
90
|
+
}
|
|
91
|
+
for (const { collection, fromPath, toPath } of targets){
|
|
92
|
+
const result = await collection.updateMany({
|
|
93
|
+
[fromPath]: {
|
|
94
|
+
$exists: true
|
|
95
|
+
},
|
|
96
|
+
[toPath]: {
|
|
97
|
+
$exists: false
|
|
98
|
+
}
|
|
99
|
+
}, {
|
|
100
|
+
$rename: {
|
|
101
|
+
[fromPath]: toPath
|
|
102
|
+
}
|
|
103
|
+
}, {
|
|
104
|
+
session
|
|
105
|
+
});
|
|
106
|
+
payload.logger.info({
|
|
107
|
+
msg: `sizes-to-variants (${direction}): renamed ${fromPath} on ${result.modifiedCount} document(s) in "${collection.collectionName}"`
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
async function findUnexpectedDestinationData({ collection, expectedVariantNames, toPath }) {
|
|
112
|
+
const expectedVariantNameSet = new Set(expectedVariantNames);
|
|
113
|
+
const cursor = collection.find({
|
|
114
|
+
[toPath]: {
|
|
115
|
+
$exists: true
|
|
116
|
+
}
|
|
117
|
+
}, {
|
|
118
|
+
projection: {
|
|
119
|
+
_id: 1,
|
|
120
|
+
[toPath]: 1
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
try {
|
|
124
|
+
for await (const document of cursor){
|
|
125
|
+
const destinationData = getDocumentPath({
|
|
126
|
+
document,
|
|
127
|
+
path: toPath
|
|
128
|
+
});
|
|
129
|
+
if (hasUnexpectedVariantData({
|
|
130
|
+
destinationData,
|
|
131
|
+
expectedVariantNameSet
|
|
132
|
+
})) {
|
|
133
|
+
return document;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
} finally{
|
|
137
|
+
await cursor.close();
|
|
138
|
+
}
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
function getDocumentPath({ document, path }) {
|
|
142
|
+
return path.split('.').reduce((value, pathSegment)=>{
|
|
143
|
+
if (!isRecord(value)) {
|
|
144
|
+
return undefined;
|
|
145
|
+
}
|
|
146
|
+
return value[pathSegment];
|
|
147
|
+
}, document);
|
|
148
|
+
}
|
|
149
|
+
function hasUnexpectedVariantData({ destinationData, expectedVariantNameSet }) {
|
|
150
|
+
if (!isRecord(destinationData)) {
|
|
151
|
+
return destinationData !== null && destinationData !== undefined;
|
|
152
|
+
}
|
|
153
|
+
for (const [variantName, variantData] of Object.entries(destinationData)){
|
|
154
|
+
if (!expectedVariantNameSet.has(variantName)) {
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
if (variantData === null || variantData === undefined) {
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
if (!isRecord(variantData) || Object.keys(variantData).some((metadataFieldName)=>!GENERATED_VARIANT_METADATA_FIELDS.has(metadataFieldName))) {
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
function isRecord(value) {
|
|
167
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
168
|
+
}
|
|
169
|
+
async function rekeyIndexes({ collection, fromPath, toPath }) {
|
|
170
|
+
let indexes;
|
|
171
|
+
try {
|
|
172
|
+
indexes = await collection.indexes();
|
|
173
|
+
} catch (err) {
|
|
174
|
+
if (err.code === NAMESPACE_NOT_FOUND_CODE) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
throw err;
|
|
178
|
+
}
|
|
179
|
+
for (const index of indexes){
|
|
180
|
+
const sourceKeys = getIndexKeysForCreate({
|
|
181
|
+
fromPath,
|
|
182
|
+
index,
|
|
183
|
+
toPath: fromPath
|
|
184
|
+
});
|
|
185
|
+
if (!Object.keys(sourceKeys).some((key)=>isPathAtOrBelow({
|
|
186
|
+
key,
|
|
187
|
+
path: fromPath
|
|
188
|
+
}))) {
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
const rekeyedKeys = getIndexKeysForCreate({
|
|
192
|
+
fromPath,
|
|
193
|
+
index,
|
|
194
|
+
toPath
|
|
195
|
+
});
|
|
196
|
+
const destinationOptions = getDestinationIndexOptions({
|
|
197
|
+
fromPath,
|
|
198
|
+
index,
|
|
199
|
+
toPath
|
|
200
|
+
});
|
|
201
|
+
if (index.weights && '_fts' in index.key && '_ftsx' in index.key) {
|
|
202
|
+
await rekeyTextIndex({
|
|
203
|
+
collection,
|
|
204
|
+
destinationOptions,
|
|
205
|
+
index,
|
|
206
|
+
rekeyedKeys,
|
|
207
|
+
sourceKeys
|
|
208
|
+
});
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
try {
|
|
212
|
+
await collection.createIndex(rekeyedKeys, destinationOptions);
|
|
213
|
+
} catch (err) {
|
|
214
|
+
if (!INDEX_CONFLICT_CODES.has(err.code ?? 0)) {
|
|
215
|
+
throw err;
|
|
216
|
+
}
|
|
217
|
+
const destinationIndex = (await collection.indexes()).find((candidate)=>isDeepStrictEqual(getIndexKeysForCreate({
|
|
218
|
+
fromPath: toPath,
|
|
219
|
+
index: candidate,
|
|
220
|
+
toPath
|
|
221
|
+
}), rekeyedKeys));
|
|
222
|
+
const existingDestinationOptions = destinationIndex ? getDestinationIndexOptions({
|
|
223
|
+
fromPath: toPath,
|
|
224
|
+
index: destinationIndex,
|
|
225
|
+
toPath
|
|
226
|
+
}) : undefined;
|
|
227
|
+
if (!destinationIndex || !isDeepStrictEqual(existingDestinationOptions, destinationOptions)) {
|
|
228
|
+
throw err;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
await collection.dropIndex(index.name);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
async function rekeyTextIndex({ collection, destinationOptions, index, rekeyedKeys, sourceKeys }) {
|
|
235
|
+
if (!index.name) {
|
|
236
|
+
throw new Error('Cannot re-key an unnamed MongoDB text index.');
|
|
237
|
+
}
|
|
238
|
+
const sourceOptions = {
|
|
239
|
+
...getDestinationIndexOptions({
|
|
240
|
+
fromPath: '',
|
|
241
|
+
index,
|
|
242
|
+
toPath: ''
|
|
243
|
+
}),
|
|
244
|
+
name: index.name
|
|
245
|
+
};
|
|
246
|
+
await collection.dropIndex(index.name);
|
|
247
|
+
try {
|
|
248
|
+
await collection.createIndex(rekeyedKeys, destinationOptions);
|
|
249
|
+
} catch (err) {
|
|
250
|
+
try {
|
|
251
|
+
await collection.createIndex(sourceKeys, sourceOptions);
|
|
252
|
+
} catch (restoreErr) {
|
|
253
|
+
throw new AggregateError([
|
|
254
|
+
err,
|
|
255
|
+
restoreErr
|
|
256
|
+
], `Failed to create the replacement for MongoDB text index "${index.name}" and failed to restore the source index.`);
|
|
257
|
+
}
|
|
258
|
+
throw err;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
function getIndexKeysForCreate({ fromPath, index, toPath }) {
|
|
262
|
+
const keys = [];
|
|
263
|
+
const hasInternalTextKeys = '_fts' in index.key && '_ftsx' in index.key;
|
|
264
|
+
for (const [key, value] of Object.entries(index.key)){
|
|
265
|
+
if (hasInternalTextKeys && key === '_fts') {
|
|
266
|
+
for (const textPath of Object.keys(index.weights ?? {})){
|
|
267
|
+
keys.push([
|
|
268
|
+
rekeyPath({
|
|
269
|
+
fromPath,
|
|
270
|
+
path: textPath,
|
|
271
|
+
toPath
|
|
272
|
+
}),
|
|
273
|
+
'text'
|
|
274
|
+
]);
|
|
275
|
+
}
|
|
276
|
+
continue;
|
|
277
|
+
}
|
|
278
|
+
if (hasInternalTextKeys && key === '_ftsx') {
|
|
279
|
+
continue;
|
|
280
|
+
}
|
|
281
|
+
keys.push([
|
|
282
|
+
rekeyPath({
|
|
283
|
+
fromPath,
|
|
284
|
+
path: key,
|
|
285
|
+
toPath
|
|
286
|
+
}),
|
|
287
|
+
value
|
|
288
|
+
]);
|
|
289
|
+
}
|
|
290
|
+
return Object.fromEntries(keys);
|
|
291
|
+
}
|
|
292
|
+
function getDestinationIndexOptions({ fromPath, index, toPath }) {
|
|
293
|
+
const options = {
|
|
294
|
+
'2dsphereIndexVersion': index['2dsphereIndexVersion'],
|
|
295
|
+
background: index.background,
|
|
296
|
+
bits: index.bits,
|
|
297
|
+
bucketSize: index.bucketSize,
|
|
298
|
+
collation: index.collation,
|
|
299
|
+
default_language: index.default_language,
|
|
300
|
+
expireAfterSeconds: index.expireAfterSeconds,
|
|
301
|
+
hidden: index.hidden,
|
|
302
|
+
language_override: index.language_override,
|
|
303
|
+
max: index.max,
|
|
304
|
+
min: index.min,
|
|
305
|
+
partialFilterExpression: index.partialFilterExpression ? rekeyDocumentPaths({
|
|
306
|
+
document: index.partialFilterExpression,
|
|
307
|
+
fromPath,
|
|
308
|
+
toPath
|
|
309
|
+
}) : undefined,
|
|
310
|
+
sparse: index.sparse,
|
|
311
|
+
storageEngine: index.storageEngine,
|
|
312
|
+
textIndexVersion: index.textIndexVersion,
|
|
313
|
+
unique: index.unique,
|
|
314
|
+
weights: index.weights ? rekeyDocumentPaths({
|
|
315
|
+
document: index.weights,
|
|
316
|
+
fromPath,
|
|
317
|
+
toPath
|
|
318
|
+
}) : undefined,
|
|
319
|
+
wildcardProjection: index.wildcardProjection ? rekeyDocumentPaths({
|
|
320
|
+
document: index.wildcardProjection,
|
|
321
|
+
fromPath,
|
|
322
|
+
toPath
|
|
323
|
+
}) : undefined
|
|
324
|
+
};
|
|
325
|
+
return Object.fromEntries(Object.entries(options).filter(([, value])=>value !== undefined));
|
|
326
|
+
}
|
|
327
|
+
function rekeyDocumentPaths({ document, fromPath, toPath }) {
|
|
328
|
+
return Object.fromEntries(Object.entries(document).map(([key, value])=>[
|
|
329
|
+
rekeyPath({
|
|
330
|
+
fromPath,
|
|
331
|
+
path: key,
|
|
332
|
+
toPath
|
|
333
|
+
}),
|
|
334
|
+
rekeyDocumentValue({
|
|
335
|
+
fromPath,
|
|
336
|
+
toPath,
|
|
337
|
+
value
|
|
338
|
+
})
|
|
339
|
+
]));
|
|
340
|
+
}
|
|
341
|
+
function isPathAtOrBelow({ key, path }) {
|
|
342
|
+
return key === path || key.startsWith(`${path}.`);
|
|
343
|
+
}
|
|
344
|
+
function rekeyPath({ fromPath, path, toPath }) {
|
|
345
|
+
return isPathAtOrBelow({
|
|
346
|
+
key: path,
|
|
347
|
+
path: fromPath
|
|
348
|
+
}) ? `${toPath}${path.slice(fromPath.length)}` : path;
|
|
349
|
+
}
|
|
350
|
+
function rekeyDocumentValue({ fromPath, toPath, value }) {
|
|
351
|
+
if (Array.isArray(value)) {
|
|
352
|
+
return value.map((item)=>rekeyDocumentValue({
|
|
353
|
+
fromPath,
|
|
354
|
+
toPath,
|
|
355
|
+
value: item
|
|
356
|
+
}));
|
|
357
|
+
}
|
|
358
|
+
if (value !== null && typeof value === 'object' && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null)) {
|
|
359
|
+
return rekeyDocumentPaths({
|
|
360
|
+
document: value,
|
|
361
|
+
fromPath,
|
|
362
|
+
toPath
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
return value;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
//# sourceMappingURL=migrateSizesToVariants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/predefinedMigrations/migrateSizesToVariants.ts"],"sourcesContent":["import type {\n Collection,\n CreateIndexesOptions,\n Document,\n IndexDescriptionInfo,\n IndexDirection,\n} from 'mongodb'\nimport type { Payload, PayloadRequest } from 'payload'\n\nimport { isDeepStrictEqual } from 'node:util'\n\nimport type { MongooseAdapter } from '../index.js'\n\nimport { getSession } from '../utilities/getSession.js'\n\n/** Mongo error codes for an index that conflicts with an existing index. */\nconst INDEX_CONFLICT_CODES = new Set([85, 86])\n/** Mongo error code for a collection that hasn't been created yet. */\nconst NAMESPACE_NOT_FOUND_CODE = 26\nconst GENERATED_VARIANT_METADATA_FIELDS = new Set([\n 'filename',\n 'filesize',\n 'height',\n 'mimeType',\n 'url',\n 'width',\n])\n\n/**\n * Moves every upload collection's stored image sizes between the legacy `sizes` field and\n * `variants`, on each collection and its versions collection (`version.sizes`). Uses `$rename`,\n * so no document is rewritten beyond the renamed key, and re-keys the indexes on those fields.\n * Documents that are already renamed are left as they are, so it's safe to re-run.\n */\nexport async function migrateSizesToVariants({\n direction = 'up',\n payload,\n req,\n}: {\n direction?: 'down' | 'up'\n payload: Payload\n req?: Partial<PayloadRequest>\n}): Promise<void> {\n const adapter = payload.db as unknown as MongooseAdapter\n const session = await getSession(adapter, req)\n const [from, to] = direction === 'up' ? ['sizes', 'variants'] : ['variants', 'sizes']\n\n const targets: {\n collection: Collection\n expectedVariantNames: string[]\n fromPath: string\n toPath: string\n }[] = []\n\n for (const collection of payload.config.collections) {\n if (!collection.upload) {\n continue\n }\n\n const upload = typeof collection.upload === 'object' ? collection.upload : undefined\n const expectedVariantNames = (upload?.variants ?? []).map(({ name }) => name)\n\n targets.push({\n collection: adapter.collections[collection.slug]!.collection,\n expectedVariantNames,\n fromPath: from,\n toPath: to,\n })\n\n if (collection.versions && adapter.versions[collection.slug]) {\n targets.push({\n collection: adapter.versions[collection.slug]!.collection,\n expectedVariantNames,\n fromPath: `version.${from}`,\n toPath: `version.${to}`,\n })\n }\n }\n\n for (const { collection, expectedVariantNames, fromPath, toPath } of targets) {\n const [sourceData, directCollision] = await Promise.all([\n collection.findOne({ [fromPath]: { $exists: true } }, { projection: { _id: 1 } }),\n collection.findOne(\n { [fromPath]: { $exists: true }, [toPath]: { $exists: true } },\n { projection: { _id: 1 } },\n ),\n ])\n\n if (\n sourceData &&\n (directCollision ||\n (await findUnexpectedDestinationData({ collection, expectedVariantNames, toPath })))\n ) {\n throw new Error(\n `Cannot run the sizes-to-variants migration because collection \"${collection.collectionName}\" contains both \"${fromPath}\" and \"${toPath}\" data. Move or rename the existing destination data before running this migration.`,\n )\n }\n }\n\n // Index changes can't be part of a multi-document transaction, and one made after the\n // migration's transaction has written to a collection aborts it. A transaction's snapshot starts\n // at its first operation, so re-keying every index before any transactional write is safe.\n for (const target of targets) {\n await rekeyIndexes(target)\n }\n\n for (const { collection, fromPath, toPath } of targets) {\n const result = await collection.updateMany(\n { [fromPath]: { $exists: true }, [toPath]: { $exists: false } },\n { $rename: { [fromPath]: toPath } },\n { session },\n )\n\n payload.logger.info({\n msg: `sizes-to-variants (${direction}): renamed ${fromPath} on ${result.modifiedCount} document(s) in \"${collection.collectionName}\"`,\n })\n }\n}\n\nasync function findUnexpectedDestinationData({\n collection,\n expectedVariantNames,\n toPath,\n}: {\n collection: Collection\n expectedVariantNames: string[]\n toPath: string\n}): Promise<Document | null> {\n const expectedVariantNameSet = new Set(expectedVariantNames)\n const cursor = collection.find(\n { [toPath]: { $exists: true } },\n { projection: { _id: 1, [toPath]: 1 } },\n )\n\n try {\n for await (const document of cursor) {\n const destinationData = getDocumentPath({ document, path: toPath })\n\n if (hasUnexpectedVariantData({ destinationData, expectedVariantNameSet })) {\n return document\n }\n }\n } finally {\n await cursor.close()\n }\n\n return null\n}\n\nfunction getDocumentPath({ document, path }: { document: Document; path: string }): unknown {\n return path.split('.').reduce<unknown>((value, pathSegment) => {\n if (!isRecord(value)) {\n return undefined\n }\n\n return value[pathSegment]\n }, document)\n}\n\nfunction hasUnexpectedVariantData({\n destinationData,\n expectedVariantNameSet,\n}: {\n destinationData: unknown\n expectedVariantNameSet: Set<string>\n}): boolean {\n if (!isRecord(destinationData)) {\n return destinationData !== null && destinationData !== undefined\n }\n\n for (const [variantName, variantData] of Object.entries(destinationData)) {\n if (!expectedVariantNameSet.has(variantName)) {\n return true\n }\n\n if (variantData === null || variantData === undefined) {\n continue\n }\n\n if (\n !isRecord(variantData) ||\n Object.keys(variantData).some(\n (metadataFieldName) => !GENERATED_VARIANT_METADATA_FIELDS.has(metadataFieldName),\n )\n ) {\n return true\n }\n }\n\n return false\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return value !== null && typeof value === 'object' && !Array.isArray(value)\n}\n\nasync function rekeyIndexes({\n collection,\n fromPath,\n toPath,\n}: {\n collection: Collection\n fromPath: string\n toPath: string\n}): Promise<void> {\n let indexes: IndexDescriptionInfo[]\n\n try {\n indexes = await collection.indexes()\n } catch (err) {\n if ((err as { code?: number }).code === NAMESPACE_NOT_FOUND_CODE) {\n return\n }\n\n throw err\n }\n\n for (const index of indexes) {\n const sourceKeys = getIndexKeysForCreate({ fromPath, index, toPath: fromPath })\n\n if (!Object.keys(sourceKeys).some((key) => isPathAtOrBelow({ key, path: fromPath }))) {\n continue\n }\n\n const rekeyedKeys = getIndexKeysForCreate({ fromPath, index, toPath })\n const destinationOptions = getDestinationIndexOptions({ fromPath, index, toPath })\n\n if (index.weights && '_fts' in index.key && '_ftsx' in index.key) {\n await rekeyTextIndex({\n collection,\n destinationOptions,\n index,\n rekeyedKeys,\n sourceKeys,\n })\n continue\n }\n\n try {\n await collection.createIndex(rekeyedKeys, destinationOptions)\n } catch (err) {\n if (!INDEX_CONFLICT_CODES.has((err as { code?: number }).code ?? 0)) {\n throw err\n }\n\n const destinationIndex = (await collection.indexes()).find((candidate) =>\n isDeepStrictEqual(\n getIndexKeysForCreate({ fromPath: toPath, index: candidate, toPath }),\n rekeyedKeys,\n ),\n )\n const existingDestinationOptions = destinationIndex\n ? getDestinationIndexOptions({\n fromPath: toPath,\n index: destinationIndex,\n toPath,\n })\n : undefined\n\n if (!destinationIndex || !isDeepStrictEqual(existingDestinationOptions, destinationOptions)) {\n throw err\n }\n }\n\n await collection.dropIndex(index.name!)\n }\n}\n\nasync function rekeyTextIndex({\n collection,\n destinationOptions,\n index,\n rekeyedKeys,\n sourceKeys,\n}: {\n collection: Collection\n destinationOptions: CreateIndexesOptions\n index: IndexDescriptionInfo\n rekeyedKeys: Record<string, IndexDirection>\n sourceKeys: Record<string, IndexDirection>\n}): Promise<void> {\n if (!index.name) {\n throw new Error('Cannot re-key an unnamed MongoDB text index.')\n }\n\n const sourceOptions: CreateIndexesOptions = {\n ...getDestinationIndexOptions({ fromPath: '', index, toPath: '' }),\n name: index.name,\n }\n\n await collection.dropIndex(index.name)\n\n try {\n await collection.createIndex(rekeyedKeys, destinationOptions)\n } catch (err) {\n try {\n await collection.createIndex(sourceKeys, sourceOptions)\n } catch (restoreErr) {\n throw new AggregateError(\n [err, restoreErr],\n `Failed to create the replacement for MongoDB text index \"${index.name}\" and failed to restore the source index.`,\n )\n }\n\n throw err\n }\n}\n\nfunction getIndexKeysForCreate({\n fromPath,\n index,\n toPath,\n}: {\n fromPath: string\n index: IndexDescriptionInfo\n toPath: string\n}): Record<string, IndexDirection> {\n const keys: [string, IndexDirection][] = []\n const hasInternalTextKeys = '_fts' in index.key && '_ftsx' in index.key\n\n for (const [key, value] of Object.entries(index.key)) {\n if (hasInternalTextKeys && key === '_fts') {\n for (const textPath of Object.keys(index.weights ?? {})) {\n keys.push([rekeyPath({ fromPath, path: textPath, toPath }), 'text'])\n }\n continue\n }\n\n if (hasInternalTextKeys && key === '_ftsx') {\n continue\n }\n\n keys.push([rekeyPath({ fromPath, path: key, toPath }), value])\n }\n\n return Object.fromEntries(keys)\n}\n\nfunction getDestinationIndexOptions({\n fromPath,\n index,\n toPath,\n}: {\n fromPath: string\n index: IndexDescriptionInfo\n toPath: string\n}): CreateIndexesOptions {\n const options: CreateIndexesOptions = {\n '2dsphereIndexVersion': index['2dsphereIndexVersion'],\n background: index.background,\n bits: index.bits,\n bucketSize: index.bucketSize,\n collation: index.collation,\n default_language: index.default_language,\n expireAfterSeconds: index.expireAfterSeconds,\n hidden: index.hidden,\n language_override: index.language_override,\n max: index.max,\n min: index.min,\n partialFilterExpression: index.partialFilterExpression\n ? rekeyDocumentPaths({ document: index.partialFilterExpression, fromPath, toPath })\n : undefined,\n sparse: index.sparse,\n storageEngine: index.storageEngine,\n textIndexVersion: index.textIndexVersion,\n unique: index.unique,\n weights: index.weights\n ? rekeyDocumentPaths({ document: index.weights, fromPath, toPath })\n : undefined,\n wildcardProjection: index.wildcardProjection\n ? rekeyDocumentPaths({ document: index.wildcardProjection, fromPath, toPath })\n : undefined,\n }\n\n return Object.fromEntries(\n Object.entries(options).filter(([, value]) => value !== undefined),\n ) as CreateIndexesOptions\n}\n\nfunction rekeyDocumentPaths({\n document,\n fromPath,\n toPath,\n}: {\n document: Document\n fromPath: string\n toPath: string\n}): Document {\n return Object.fromEntries(\n Object.entries(document).map(([key, value]) => [\n rekeyPath({ fromPath, path: key, toPath }),\n rekeyDocumentValue({ fromPath, toPath, value }),\n ]),\n )\n}\n\nfunction isPathAtOrBelow({ key, path }: { key: string; path: string }): boolean {\n return key === path || key.startsWith(`${path}.`)\n}\n\nfunction rekeyPath({\n fromPath,\n path,\n toPath,\n}: {\n fromPath: string\n path: string\n toPath: string\n}): string {\n return isPathAtOrBelow({ key: path, path: fromPath })\n ? `${toPath}${path.slice(fromPath.length)}`\n : path\n}\n\nfunction rekeyDocumentValue({\n fromPath,\n toPath,\n value,\n}: {\n fromPath: string\n toPath: string\n value: unknown\n}): unknown {\n if (Array.isArray(value)) {\n return value.map((item) => rekeyDocumentValue({ fromPath, toPath, value: item }))\n }\n\n if (\n value !== null &&\n typeof value === 'object' &&\n (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null)\n ) {\n return rekeyDocumentPaths({ document: value as Document, fromPath, toPath })\n }\n\n return value\n}\n"],"names":["isDeepStrictEqual","getSession","INDEX_CONFLICT_CODES","Set","NAMESPACE_NOT_FOUND_CODE","GENERATED_VARIANT_METADATA_FIELDS","migrateSizesToVariants","direction","payload","req","adapter","db","session","from","to","targets","collection","config","collections","upload","undefined","expectedVariantNames","variants","map","name","push","slug","fromPath","toPath","versions","sourceData","directCollision","Promise","all","findOne","$exists","projection","_id","findUnexpectedDestinationData","Error","collectionName","target","rekeyIndexes","result","updateMany","$rename","logger","info","msg","modifiedCount","expectedVariantNameSet","cursor","find","document","destinationData","getDocumentPath","path","hasUnexpectedVariantData","close","split","reduce","value","pathSegment","isRecord","variantName","variantData","Object","entries","has","keys","some","metadataFieldName","Array","isArray","indexes","err","code","index","sourceKeys","getIndexKeysForCreate","key","isPathAtOrBelow","rekeyedKeys","destinationOptions","getDestinationIndexOptions","weights","rekeyTextIndex","createIndex","destinationIndex","candidate","existingDestinationOptions","dropIndex","sourceOptions","restoreErr","AggregateError","hasInternalTextKeys","textPath","rekeyPath","fromEntries","options","background","bits","bucketSize","collation","default_language","expireAfterSeconds","hidden","language_override","max","min","partialFilterExpression","rekeyDocumentPaths","sparse","storageEngine","textIndexVersion","unique","wildcardProjection","filter","rekeyDocumentValue","startsWith","slice","length","item","getPrototypeOf","prototype"],"mappings":"AASA,SAASA,iBAAiB,QAAQ,YAAW;AAI7C,SAASC,U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mBlC;YAAUC;QAAO;IAC5E;IAEA,OAAOiC;AACT"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
declare const imports = "import { migrateSizesToVariants } from '@payloadcms/db-mongodb/migration-utils'";
|
|
2
|
+
declare const upSQL = " await migrateSizesToVariants({ payload, req })\n";
|
|
3
|
+
declare const downSQL = " await migrateSizesToVariants({ direction: 'down', payload, req })\n";
|
|
4
|
+
export { downSQL, imports, upSQL };
|
|
5
|
+
//# sourceMappingURL=sizes-to-variants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sizes-to-variants.d.ts","sourceRoot":"","sources":["../../src/predefinedMigrations/sizes-to-variants.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,OAAO,oFAAoF,CAAA;AACjG,QAAA,MAAM,KAAK,uDACV,CAAA;AACD,QAAA,MAAM,OAAO,0EACZ,CAAA;AAED,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
const imports = `import { migrateSizesToVariants } from '@payloadcms/db-mongodb/migration-utils'`;
|
|
2
|
+
const upSQL = ` await migrateSizesToVariants({ payload, req })
|
|
3
|
+
`;
|
|
4
|
+
const downSQL = ` await migrateSizesToVariants({ direction: 'down', payload, req })
|
|
5
|
+
`;
|
|
6
|
+
export { downSQL, imports, upSQL };
|
|
7
|
+
|
|
8
|
+
//# sourceMappingURL=sizes-to-variants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/predefinedMigrations/sizes-to-variants.ts"],"sourcesContent":["const imports = `import { migrateSizesToVariants } from '@payloadcms/db-mongodb/migration-utils'`\nconst upSQL = ` await migrateSizesToVariants({ payload, req })\n`\nconst downSQL = ` await migrateSizesToVariants({ direction: 'down', payload, req })\n`\n\nexport { downSQL, imports, upSQL }\n"],"names":["imports","upSQL","downSQL"],"mappings":"AAAA,MAAMA,UAAU,CAAC,+EAA+E,CAAC;AACjG,MAAMC,QAAQ,CAAC;AACf,CAAC;AACD,MAAMC,UAAU,CAAC;AACjB,CAAC;AAED,SAASA,OAAO,EAAEF,OAAO,EAAEC,KAAK,GAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildSearchParams.d.ts","sourceRoot":"","sources":["../../src/queries/buildSearchParams.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"buildSearchParams.d.ts","sourceRoot":"","sources":["../../src/queries/buildSearchParams.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,cAAc,EAEd,QAAQ,EAER,OAAO,EACR,MAAM,SAAS,CAAA;AAkBhB,KAAK,WAAW,GAAG;IACjB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB,CAAA;AAMD;;GAEG;AACH,wBAAsB,gBAAgB,CAAC,EACrC,cAAc,EACd,MAAM,EACN,UAAU,EACV,YAAY,EACZ,MAAM,EACN,QAAQ,EACR,iBAAiB,EACjB,OAAO,EACP,GAAG,GACJ,EAAE;IACD,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,YAAY,EAAE,MAAM,CAAA;IACpB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,QAAQ,CAAA;IAClB,iBAAiB,EAAE,OAAO,CAAA;IAC1B,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,EAAE,OAAO,CAAA;CACb,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC,CAmZnC"}
|