@payloadcms/db-mongodb 3.0.0-canary.f83d96a → 3.0.0-canary.fb04843

Sign up to get free protection for your applications and to get access to all the features.
Files changed (177) hide show
  1. package/dist/connect.d.ts.map +1 -1
  2. package/dist/connect.js +18 -4
  3. package/dist/connect.js.map +1 -1
  4. package/dist/count.d.ts.map +1 -1
  5. package/dist/count.js +9 -2
  6. package/dist/count.js.map +1 -1
  7. package/dist/countGlobalVersions.d.ts +3 -0
  8. package/dist/countGlobalVersions.d.ts.map +1 -0
  9. package/dist/countGlobalVersions.js +40 -0
  10. package/dist/countGlobalVersions.js.map +1 -0
  11. package/dist/countVersions.d.ts +3 -0
  12. package/dist/countVersions.d.ts.map +1 -0
  13. package/dist/countVersions.js +40 -0
  14. package/dist/countVersions.js.map +1 -0
  15. package/dist/create.d.ts.map +1 -1
  16. package/dist/create.js +11 -2
  17. package/dist/create.js.map +1 -1
  18. package/dist/createGlobal.d.ts.map +1 -1
  19. package/dist/createGlobal.js +11 -6
  20. package/dist/createGlobal.js.map +1 -1
  21. package/dist/createGlobalVersion.d.ts +1 -1
  22. package/dist/createGlobalVersion.d.ts.map +1 -1
  23. package/dist/createGlobalVersion.js +14 -5
  24. package/dist/createGlobalVersion.js.map +1 -1
  25. package/dist/createMigration.d.ts.map +1 -1
  26. package/dist/createMigration.js +9 -7
  27. package/dist/createMigration.js.map +1 -1
  28. package/dist/createVersion.d.ts +1 -1
  29. package/dist/createVersion.d.ts.map +1 -1
  30. package/dist/createVersion.js +32 -10
  31. package/dist/createVersion.js.map +1 -1
  32. package/dist/deleteMany.d.ts.map +1 -1
  33. package/dist/deleteMany.js +1 -1
  34. package/dist/deleteMany.js.map +1 -1
  35. package/dist/deleteOne.d.ts.map +1 -1
  36. package/dist/deleteOne.js +12 -4
  37. package/dist/deleteOne.js.map +1 -1
  38. package/dist/deleteVersions.d.ts.map +1 -1
  39. package/dist/deleteVersions.js +1 -1
  40. package/dist/deleteVersions.js.map +1 -1
  41. package/dist/exports/migration-utils.d.ts +3 -0
  42. package/dist/exports/migration-utils.d.ts.map +1 -0
  43. package/dist/exports/migration-utils.js +4 -0
  44. package/dist/exports/migration-utils.js.map +1 -0
  45. package/dist/find.d.ts.map +1 -1
  46. package/dist/find.js +35 -6
  47. package/dist/find.js.map +1 -1
  48. package/dist/findGlobal.d.ts.map +1 -1
  49. package/dist/findGlobal.js +10 -4
  50. package/dist/findGlobal.js.map +1 -1
  51. package/dist/findGlobalVersions.d.ts.map +1 -1
  52. package/dist/findGlobalVersions.js +18 -7
  53. package/dist/findGlobalVersions.js.map +1 -1
  54. package/dist/findOne.d.ts.map +1 -1
  55. package/dist/findOne.js +28 -4
  56. package/dist/findOne.js.map +1 -1
  57. package/dist/findVersions.d.ts.map +1 -1
  58. package/dist/findVersions.js +17 -6
  59. package/dist/findVersions.js.map +1 -1
  60. package/dist/index.d.ts +59 -10
  61. package/dist/index.d.ts.map +1 -1
  62. package/dist/index.js +18 -7
  63. package/dist/index.js.map +1 -1
  64. package/dist/init.d.ts.map +1 -1
  65. package/dist/init.js +18 -16
  66. package/dist/init.js.map +1 -1
  67. package/dist/migrateFresh.js.map +1 -1
  68. package/dist/models/buildCollectionSchema.d.ts +1 -2
  69. package/dist/models/buildCollectionSchema.d.ts.map +1 -1
  70. package/dist/models/buildCollectionSchema.js +16 -4
  71. package/dist/models/buildCollectionSchema.js.map +1 -1
  72. package/dist/models/buildGlobalModel.js +2 -2
  73. package/dist/models/buildGlobalModel.js.map +1 -1
  74. package/dist/models/buildSchema.d.ts +1 -2
  75. package/dist/models/buildSchema.d.ts.map +1 -1
  76. package/dist/models/buildSchema.js +116 -23
  77. package/dist/models/buildSchema.js.map +1 -1
  78. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts +6 -0
  79. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts.map +1 -0
  80. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js +141 -0
  81. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js.map +1 -0
  82. package/dist/predefinedMigrations/migrateVersionsV1_V2.d.ts +5 -0
  83. package/dist/predefinedMigrations/migrateVersionsV1_V2.d.ts.map +1 -0
  84. package/dist/predefinedMigrations/migrateVersionsV1_V2.js +107 -0
  85. package/dist/predefinedMigrations/migrateVersionsV1_V2.js.map +1 -0
  86. package/dist/predefinedMigrations/relationships-v2-v3.d.ts +4 -0
  87. package/dist/predefinedMigrations/relationships-v2-v3.d.ts.map +1 -0
  88. package/dist/predefinedMigrations/relationships-v2-v3.js +9 -0
  89. package/dist/predefinedMigrations/relationships-v2-v3.js.map +1 -0
  90. package/dist/predefinedMigrations/versions-v1-v2.d.ts +4 -0
  91. package/dist/predefinedMigrations/versions-v1-v2.d.ts.map +1 -0
  92. package/dist/predefinedMigrations/versions-v1-v2.js +5 -95
  93. package/dist/predefinedMigrations/versions-v1-v2.js.map +1 -1
  94. package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
  95. package/dist/queries/buildAndOrConditions.js +0 -2
  96. package/dist/queries/buildAndOrConditions.js.map +1 -1
  97. package/dist/queries/buildQuery.d.ts +2 -2
  98. package/dist/queries/buildQuery.d.ts.map +1 -1
  99. package/dist/queries/buildQuery.js +1 -2
  100. package/dist/queries/buildQuery.js.map +1 -1
  101. package/dist/queries/buildSearchParams.d.ts.map +1 -1
  102. package/dist/queries/buildSearchParams.js +28 -18
  103. package/dist/queries/buildSearchParams.js.map +1 -1
  104. package/dist/queries/buildSortParam.d.ts +2 -2
  105. package/dist/queries/buildSortParam.d.ts.map +1 -1
  106. package/dist/queries/buildSortParam.js +26 -17
  107. package/dist/queries/buildSortParam.js.map +1 -1
  108. package/dist/queries/getLocalizedSortProperty.spec.js +43 -43
  109. package/dist/queries/getLocalizedSortProperty.spec.js.map +1 -1
  110. package/dist/queries/parseParams.d.ts.map +1 -1
  111. package/dist/queries/parseParams.js +7 -5
  112. package/dist/queries/parseParams.js.map +1 -1
  113. package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
  114. package/dist/queries/sanitizeQueryValue.js +144 -27
  115. package/dist/queries/sanitizeQueryValue.js.map +1 -1
  116. package/dist/queryDrafts.d.ts.map +1 -1
  117. package/dist/queryDrafts.js +37 -10
  118. package/dist/queryDrafts.js.map +1 -1
  119. package/dist/transactions/beginTransaction.d.ts.map +1 -1
  120. package/dist/transactions/beginTransaction.js +2 -0
  121. package/dist/transactions/beginTransaction.js.map +1 -1
  122. package/dist/transactions/commitTransaction.d.ts.map +1 -1
  123. package/dist/transactions/commitTransaction.js +3 -0
  124. package/dist/transactions/commitTransaction.js.map +1 -1
  125. package/dist/transactions/rollbackTransaction.d.ts.map +1 -1
  126. package/dist/transactions/rollbackTransaction.js +13 -7
  127. package/dist/transactions/rollbackTransaction.js.map +1 -1
  128. package/dist/types.d.ts +7 -4
  129. package/dist/types.d.ts.map +1 -1
  130. package/dist/types.js.map +1 -1
  131. package/dist/updateGlobal.d.ts.map +1 -1
  132. package/dist/updateGlobal.js +18 -5
  133. package/dist/updateGlobal.js.map +1 -1
  134. package/dist/updateGlobalVersion.d.ts +2 -2
  135. package/dist/updateGlobalVersion.d.ts.map +1 -1
  136. package/dist/updateGlobalVersion.js +19 -5
  137. package/dist/updateGlobalVersion.js.map +1 -1
  138. package/dist/updateOne.d.ts.map +1 -1
  139. package/dist/updateOne.js +19 -5
  140. package/dist/updateOne.js.map +1 -1
  141. package/dist/updateVersion.d.ts +1 -1
  142. package/dist/updateVersion.d.ts.map +1 -1
  143. package/dist/updateVersion.js +18 -4
  144. package/dist/updateVersion.js.map +1 -1
  145. package/dist/upsert.d.ts +3 -0
  146. package/dist/upsert.d.ts.map +1 -0
  147. package/dist/upsert.js +15 -0
  148. package/dist/upsert.js.map +1 -0
  149. package/dist/utilities/buildJoinAggregation.d.ts +18 -0
  150. package/dist/utilities/buildJoinAggregation.d.ts.map +1 -0
  151. package/dist/utilities/buildJoinAggregation.js +159 -0
  152. package/dist/utilities/buildJoinAggregation.js.map +1 -0
  153. package/dist/utilities/buildProjectionFromSelect.d.ts +8 -0
  154. package/dist/utilities/buildProjectionFromSelect.d.ts.map +1 -0
  155. package/dist/utilities/buildProjectionFromSelect.js +171 -0
  156. package/dist/utilities/buildProjectionFromSelect.js.map +1 -0
  157. package/dist/utilities/getDBName.d.ts.map +1 -1
  158. package/dist/utilities/getDBName.js +3 -1
  159. package/dist/utilities/getDBName.js.map +1 -1
  160. package/dist/utilities/handleError.js +2 -2
  161. package/dist/utilities/handleError.js.map +1 -1
  162. package/dist/utilities/sanitizeInternalFields.d.ts +1 -2
  163. package/dist/utilities/sanitizeInternalFields.d.ts.map +1 -1
  164. package/dist/utilities/sanitizeInternalFields.js +1 -2
  165. package/dist/utilities/sanitizeInternalFields.js.map +1 -1
  166. package/dist/utilities/sanitizeRelationshipIDs.d.ts +9 -0
  167. package/dist/utilities/sanitizeRelationshipIDs.d.ts.map +1 -0
  168. package/dist/utilities/sanitizeRelationshipIDs.js +115 -0
  169. package/dist/utilities/sanitizeRelationshipIDs.js.map +1 -0
  170. package/dist/utilities/sanitizeRelationshipIDs.spec.js +383 -0
  171. package/dist/utilities/sanitizeRelationshipIDs.spec.js.map +1 -0
  172. package/dist/withSession.d.ts +3 -2
  173. package/dist/withSession.d.ts.map +1 -1
  174. package/dist/withSession.js +10 -4
  175. package/dist/withSession.js.map +1 -1
  176. package/license.md +22 -0
  177. package/package.json +24 -11
@@ -1,8 +1,13 @@
1
- /* eslint-disable @typescript-eslint/ban-ts-comment */ /* eslint-disable class-methods-use-this */ /* eslint-disable @typescript-eslint/no-use-before-define */ import mongoose from 'mongoose';
2
- import { fieldAffectsData, fieldIsLocalized, fieldIsPresentationalOnly, tabHasName } from 'payload/shared';
1
+ import mongoose from 'mongoose';
2
+ import { fieldAffectsData, fieldIsLocalized, fieldIsPresentationalOnly, fieldIsVirtual, tabHasName } from 'payload/shared';
3
+ /**
4
+ * get a field's defaultValue only if defined and not dynamic so that it can be set on the field schema
5
+ * @param field
6
+ */ const formatDefaultValue = (field)=>typeof field.defaultValue !== 'undefined' && typeof field.defaultValue !== 'function' ? field.defaultValue : undefined;
3
7
  const formatBaseSchema = (field, buildSchemaOptions)=>{
4
8
  const { disableUnique, draftsEnabled, indexSortableFields } = buildSchemaOptions;
5
9
  const schema = {
10
+ default: formatDefaultValue(field),
6
11
  index: field.index || !disableUnique && field.unique || indexSortableFields || false,
7
12
  required: false,
8
13
  unique: !disableUnique && field.unique || false
@@ -29,7 +34,7 @@ const localizeSchema = (entity, schema, localization)=>{
29
34
  }
30
35
  return schema;
31
36
  };
32
- const buildSchema = (config, configFields, buildSchemaOptions = {})=>{
37
+ export const buildSchema = (config, configFields, buildSchemaOptions = {})=>{
33
38
  const { allowIDField, options } = buildSchemaOptions;
34
39
  let fields = {};
35
40
  let schemaFields = configFields;
@@ -44,6 +49,9 @@ const buildSchema = (config, configFields, buildSchemaOptions = {})=>{
44
49
  }
45
50
  const schema = new mongoose.Schema(fields, options);
46
51
  schemaFields.forEach((field)=>{
52
+ if (fieldIsVirtual(field)) {
53
+ return;
54
+ }
47
55
  if (!fieldIsPresentationalOnly(field)) {
48
56
  const addFieldSchema = fieldToSchemaMap[field.type];
49
57
  if (addFieldSchema) {
@@ -68,8 +76,7 @@ const fieldToSchemaMap = {
68
76
  minimize: false
69
77
  }
70
78
  })
71
- ],
72
- default: undefined
79
+ ]
73
80
  };
74
81
  schema.add({
75
82
  [field.name]: localizeSchema(field, baseSchema, config.localization)
@@ -82,8 +89,7 @@ const fieldToSchemaMap = {
82
89
  _id: false,
83
90
  discriminatorKey: 'blockType'
84
91
  })
85
- ],
86
- default: undefined
92
+ ]
87
93
  };
88
94
  schema.add({
89
95
  [field.name]: localizeSchema(field, fieldSchema, config.localization)
@@ -101,12 +107,10 @@ const fieldToSchemaMap = {
101
107
  });
102
108
  if (field.localized && config.localization) {
103
109
  config.localization.localeCodes.forEach((localeCode)=>{
104
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
105
110
  // @ts-expect-error Possible incorrect typing in mongoose types, this works
106
111
  schema.path(`${field.name}.${localeCode}`).discriminator(blockItem.slug, blockSchema);
107
112
  });
108
113
  } else {
109
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
110
114
  // @ts-expect-error Possible incorrect typing in mongoose types, this works
111
115
  schema.path(field.name).discriminator(blockItem.slug, blockSchema);
112
116
  }
@@ -132,6 +136,9 @@ const fieldToSchemaMap = {
132
136
  },
133
137
  collapsible: (field, schema, config, buildSchemaOptions)=>{
134
138
  field.fields.forEach((subField)=>{
139
+ if (fieldIsVirtual(subField)) {
140
+ return;
141
+ }
135
142
  const addFieldSchema = fieldToSchemaMap[subField.type];
136
143
  if (addFieldSchema) {
137
144
  addFieldSchema(subField, schema, config, buildSchemaOptions);
@@ -203,13 +210,16 @@ const fieldToSchemaMap = {
203
210
  type: String,
204
211
  enum: [
205
212
  'Point'
206
- ]
213
+ ],
214
+ ...typeof field.defaultValue !== 'undefined' && {
215
+ default: 'Point'
216
+ }
207
217
  },
208
218
  coordinates: {
209
219
  type: [
210
220
  Number
211
221
  ],
212
- default: field.defaultValue || undefined,
222
+ default: formatDefaultValue(field),
213
223
  required: false
214
224
  }
215
225
  };
@@ -243,7 +253,9 @@ const fieldToSchemaMap = {
243
253
  ...formatBaseSchema(field, buildSchemaOptions),
244
254
  type: String,
245
255
  enum: field.options.map((option)=>{
246
- if (typeof option === 'object') return option.value;
256
+ if (typeof option === 'object') {
257
+ return option.value;
258
+ }
247
259
  return option;
248
260
  })
249
261
  };
@@ -285,7 +297,7 @@ const fieldToSchemaMap = {
285
297
  type: [
286
298
  localeSchema
287
299
  ],
288
- default: undefined
300
+ default: formatDefaultValue(field)
289
301
  } : localeSchema
290
302
  };
291
303
  }, {}),
@@ -310,7 +322,7 @@ const fieldToSchemaMap = {
310
322
  type: [
311
323
  schemaToReturn
312
324
  ],
313
- default: undefined
325
+ default: formatDefaultValue(field)
314
326
  };
315
327
  }
316
328
  } else {
@@ -324,7 +336,7 @@ const fieldToSchemaMap = {
324
336
  type: [
325
337
  schemaToReturn
326
338
  ],
327
- default: undefined
339
+ default: formatDefaultValue(field)
328
340
  };
329
341
  }
330
342
  }
@@ -343,6 +355,9 @@ const fieldToSchemaMap = {
343
355
  },
344
356
  row: (field, schema, config, buildSchemaOptions)=>{
345
357
  field.fields.forEach((subField)=>{
358
+ if (fieldIsVirtual(subField)) {
359
+ return;
360
+ }
346
361
  const addFieldSchema = fieldToSchemaMap[subField.type];
347
362
  if (addFieldSchema) {
348
363
  addFieldSchema(subField, schema, config, buildSchemaOptions);
@@ -354,7 +369,9 @@ const fieldToSchemaMap = {
354
369
  ...formatBaseSchema(field, buildSchemaOptions),
355
370
  type: String,
356
371
  enum: field.options.map((option)=>{
357
- if (typeof option === 'object') return option.value;
372
+ if (typeof option === 'object') {
373
+ return option.value;
374
+ }
358
375
  return option;
359
376
  })
360
377
  };
@@ -370,6 +387,9 @@ const fieldToSchemaMap = {
370
387
  tabs: (field, schema, config, buildSchemaOptions)=>{
371
388
  field.tabs.forEach((tab)=>{
372
389
  if (tabHasName(tab)) {
390
+ if (fieldIsVirtual(tab)) {
391
+ return;
392
+ }
373
393
  const baseSchema = {
374
394
  type: buildSchema(config, tab.fields, {
375
395
  disableUnique: buildSchemaOptions.disableUnique,
@@ -386,6 +406,9 @@ const fieldToSchemaMap = {
386
406
  });
387
407
  } else {
388
408
  tab.fields.forEach((subField)=>{
409
+ if (fieldIsVirtual(subField)) {
410
+ return;
411
+ }
389
412
  const addFieldSchema = fieldToSchemaMap[subField.type];
390
413
  if (addFieldSchema) {
391
414
  addFieldSchema(subField, schema, config, buildSchemaOptions);
@@ -415,16 +438,86 @@ const fieldToSchemaMap = {
415
438
  });
416
439
  },
417
440
  upload: (field, schema, config, buildSchemaOptions)=>{
418
- const baseSchema = {
419
- ...formatBaseSchema(field, buildSchemaOptions),
420
- type: mongoose.Schema.Types.Mixed,
421
- ref: field.relationTo
422
- };
441
+ const hasManyRelations = Array.isArray(field.relationTo);
442
+ let schemaToReturn = {};
443
+ if (field.localized && config.localization) {
444
+ schemaToReturn = {
445
+ type: config.localization.localeCodes.reduce((locales, locale)=>{
446
+ let localeSchema = {};
447
+ if (hasManyRelations) {
448
+ localeSchema = {
449
+ ...formatBaseSchema(field, buildSchemaOptions),
450
+ _id: false,
451
+ type: mongoose.Schema.Types.Mixed,
452
+ relationTo: {
453
+ type: String,
454
+ enum: field.relationTo
455
+ },
456
+ value: {
457
+ type: mongoose.Schema.Types.Mixed,
458
+ refPath: `${field.name}.${locale}.relationTo`
459
+ }
460
+ };
461
+ } else {
462
+ localeSchema = {
463
+ ...formatBaseSchema(field, buildSchemaOptions),
464
+ type: mongoose.Schema.Types.Mixed,
465
+ ref: field.relationTo
466
+ };
467
+ }
468
+ return {
469
+ ...locales,
470
+ [locale]: field.hasMany ? {
471
+ type: [
472
+ localeSchema
473
+ ],
474
+ default: formatDefaultValue(field)
475
+ } : localeSchema
476
+ };
477
+ }, {}),
478
+ localized: true
479
+ };
480
+ } else if (hasManyRelations) {
481
+ schemaToReturn = {
482
+ ...formatBaseSchema(field, buildSchemaOptions),
483
+ _id: false,
484
+ type: mongoose.Schema.Types.Mixed,
485
+ relationTo: {
486
+ type: String,
487
+ enum: field.relationTo
488
+ },
489
+ value: {
490
+ type: mongoose.Schema.Types.Mixed,
491
+ refPath: `${field.name}.relationTo`
492
+ }
493
+ };
494
+ if (field.hasMany) {
495
+ schemaToReturn = {
496
+ type: [
497
+ schemaToReturn
498
+ ],
499
+ default: formatDefaultValue(field)
500
+ };
501
+ }
502
+ } else {
503
+ schemaToReturn = {
504
+ ...formatBaseSchema(field, buildSchemaOptions),
505
+ type: mongoose.Schema.Types.Mixed,
506
+ ref: field.relationTo
507
+ };
508
+ if (field.hasMany) {
509
+ schemaToReturn = {
510
+ type: [
511
+ schemaToReturn
512
+ ],
513
+ default: formatDefaultValue(field)
514
+ };
515
+ }
516
+ }
423
517
  schema.add({
424
- [field.name]: localizeSchema(field, baseSchema, config.localization)
518
+ [field.name]: schemaToReturn
425
519
  });
426
520
  }
427
521
  };
428
- export default buildSchema;
429
522
 
430
523
  //# sourceMappingURL=buildSchema.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/models/buildSchema.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/ban-ts-comment */\n/* eslint-disable class-methods-use-this */\n/* eslint-disable @typescript-eslint/no-use-before-define */\nimport type { IndexOptions, Schema, SchemaOptions, SchemaTypeOptions } from 'mongoose'\nimport type {\n ArrayField,\n Block,\n BlockField,\n CheckboxField,\n CodeField,\n CollapsibleField,\n DateField,\n EmailField,\n Field,\n FieldAffectingData,\n GroupField,\n JSONField,\n NonPresentationalField,\n NumberField,\n PointField,\n RadioField,\n RelationshipField,\n RichTextField,\n RowField,\n SanitizedConfig,\n SanitizedLocalizationConfig,\n SelectField,\n Tab,\n TabsField,\n TextField,\n TextareaField,\n UploadField,\n} from 'payload'\n\nimport mongoose from 'mongoose'\nimport {\n fieldAffectsData,\n fieldIsLocalized,\n fieldIsPresentationalOnly,\n tabHasName,\n} from 'payload/shared'\n\nexport type BuildSchemaOptions = {\n allowIDField?: boolean\n disableUnique?: boolean\n draftsEnabled?: boolean\n indexSortableFields?: boolean\n options?: SchemaOptions\n}\n\ntype FieldSchemaGenerator = (\n field: Field,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n) => void\n\nconst formatBaseSchema = (field: FieldAffectingData, buildSchemaOptions: BuildSchemaOptions) => {\n const { disableUnique, draftsEnabled, indexSortableFields } = buildSchemaOptions\n const schema: SchemaTypeOptions<unknown> = {\n index: field.index || (!disableUnique && field.unique) || indexSortableFields || false,\n required: false,\n unique: (!disableUnique && field.unique) || false,\n }\n\n if (\n schema.unique &&\n (field.localized ||\n draftsEnabled ||\n (fieldAffectsData(field) &&\n field.type !== 'group' &&\n field.type !== 'tab' &&\n field.required !== true))\n ) {\n schema.sparse = true\n }\n\n if (field.hidden) {\n schema.hidden = true\n }\n\n return schema\n}\n\nconst localizeSchema = (\n entity: NonPresentationalField | Tab,\n schema,\n localization: SanitizedLocalizationConfig | false,\n) => {\n if (fieldIsLocalized(entity) && localization && Array.isArray(localization.locales)) {\n return {\n type: localization.localeCodes.reduce(\n (localeSchema, locale) => ({\n ...localeSchema,\n [locale]: schema,\n }),\n {\n _id: false,\n },\n ),\n localized: true,\n }\n }\n return schema\n}\n\nconst buildSchema = (\n config: SanitizedConfig,\n configFields: Field[],\n buildSchemaOptions: BuildSchemaOptions = {},\n): Schema => {\n const { allowIDField, options } = buildSchemaOptions\n let fields = {}\n\n let schemaFields = configFields\n\n if (!allowIDField) {\n const idField = schemaFields.find((field) => fieldAffectsData(field) && field.name === 'id')\n if (idField) {\n fields = {\n _id: idField.type === 'number' ? Number : String,\n }\n schemaFields = schemaFields.filter(\n (field) => !(fieldAffectsData(field) && field.name === 'id'),\n )\n }\n }\n\n const schema = new mongoose.Schema(fields, options)\n\n schemaFields.forEach((field) => {\n if (!fieldIsPresentationalOnly(field)) {\n const addFieldSchema: FieldSchemaGenerator = fieldToSchemaMap[field.type]\n\n if (addFieldSchema) {\n addFieldSchema(field, schema, config, buildSchemaOptions)\n }\n }\n })\n\n return schema\n}\n\nconst fieldToSchemaMap: Record<string, FieldSchemaGenerator> = {\n array: (\n field: ArrayField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ) => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: [\n buildSchema(config, field.fields, {\n allowIDField: true,\n disableUnique: buildSchemaOptions.disableUnique,\n draftsEnabled: buildSchemaOptions.draftsEnabled,\n options: {\n _id: false,\n id: false,\n minimize: false,\n },\n }),\n ],\n default: undefined,\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n blocks: (\n field: BlockField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const fieldSchema = {\n type: [new mongoose.Schema({}, { _id: false, discriminatorKey: 'blockType' })],\n default: undefined,\n }\n\n schema.add({\n [field.name]: localizeSchema(field, fieldSchema, config.localization),\n })\n\n field.blocks.forEach((blockItem: Block) => {\n const blockSchema = new mongoose.Schema({}, { _id: false, id: false })\n\n blockItem.fields.forEach((blockField) => {\n const addFieldSchema: FieldSchemaGenerator = fieldToSchemaMap[blockField.type]\n if (addFieldSchema) {\n addFieldSchema(blockField, blockSchema, config, buildSchemaOptions)\n }\n })\n\n if (field.localized && config.localization) {\n config.localization.localeCodes.forEach((localeCode) => {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error Possible incorrect typing in mongoose types, this works\n schema.path(`${field.name}.${localeCode}`).discriminator(blockItem.slug, blockSchema)\n })\n } else {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error Possible incorrect typing in mongoose types, this works\n schema.path(field.name).discriminator(blockItem.slug, blockSchema)\n }\n })\n },\n checkbox: (\n field: CheckboxField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = { ...formatBaseSchema(field, buildSchemaOptions), type: Boolean }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n code: (\n field: CodeField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = { ...formatBaseSchema(field, buildSchemaOptions), type: String }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n collapsible: (\n field: CollapsibleField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n field.fields.forEach((subField: Field) => {\n const addFieldSchema: FieldSchemaGenerator = fieldToSchemaMap[subField.type]\n\n if (addFieldSchema) {\n addFieldSchema(subField, schema, config, buildSchemaOptions)\n }\n })\n },\n date: (\n field: DateField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = { ...formatBaseSchema(field, buildSchemaOptions), type: Date }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n email: (\n field: EmailField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = { ...formatBaseSchema(field, buildSchemaOptions), type: String }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n group: (\n field: GroupField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const formattedBaseSchema = formatBaseSchema(field, buildSchemaOptions)\n\n // carry indexSortableFields through to versions if drafts enabled\n const indexSortableFields =\n buildSchemaOptions.indexSortableFields &&\n field.name === 'version' &&\n buildSchemaOptions.draftsEnabled\n\n const baseSchema = {\n ...formattedBaseSchema,\n type: buildSchema(config, field.fields, {\n disableUnique: buildSchemaOptions.disableUnique,\n draftsEnabled: buildSchemaOptions.draftsEnabled,\n indexSortableFields,\n options: {\n _id: false,\n id: false,\n minimize: false,\n },\n }),\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n json: (\n field: JSONField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: mongoose.Schema.Types.Mixed,\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n number: (\n field: NumberField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: field.hasMany ? [Number] : Number,\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n point: (\n field: PointField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema: SchemaTypeOptions<unknown> = {\n type: {\n type: String,\n enum: ['Point'],\n },\n coordinates: {\n type: [Number],\n default: field.defaultValue || undefined,\n required: false,\n },\n }\n if (buildSchemaOptions.disableUnique && field.unique && field.localized) {\n baseSchema.coordinates.sparse = true\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n\n if (field.index === true || field.index === undefined) {\n const indexOptions: IndexOptions = {}\n if (!buildSchemaOptions.disableUnique && field.unique) {\n indexOptions.sparse = true\n indexOptions.unique = true\n }\n if (field.localized && config.localization) {\n config.localization.locales.forEach((locale) => {\n schema.index({ [`${field.name}.${locale.code}`]: '2dsphere' }, indexOptions)\n })\n } else {\n schema.index({ [field.name]: '2dsphere' }, indexOptions)\n }\n }\n },\n radio: (\n field: RadioField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: String,\n enum: field.options.map((option) => {\n if (typeof option === 'object') return option.value\n return option\n }),\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n relationship: (\n field: RelationshipField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ) => {\n const hasManyRelations = Array.isArray(field.relationTo)\n let schemaToReturn: { [key: string]: any } = {}\n\n if (field.localized && config.localization) {\n schemaToReturn = {\n type: config.localization.localeCodes.reduce((locales, locale) => {\n let localeSchema: { [key: string]: any } = {}\n\n if (hasManyRelations) {\n localeSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n _id: false,\n type: mongoose.Schema.Types.Mixed,\n relationTo: { type: String, enum: field.relationTo },\n value: {\n type: mongoose.Schema.Types.Mixed,\n refPath: `${field.name}.${locale}.relationTo`,\n },\n }\n } else {\n localeSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: mongoose.Schema.Types.Mixed,\n ref: field.relationTo,\n }\n }\n\n return {\n ...locales,\n [locale]: field.hasMany ? { type: [localeSchema], default: undefined } : localeSchema,\n }\n }, {}),\n localized: true,\n }\n } else if (hasManyRelations) {\n schemaToReturn = {\n ...formatBaseSchema(field, buildSchemaOptions),\n _id: false,\n type: mongoose.Schema.Types.Mixed,\n relationTo: { type: String, enum: field.relationTo },\n value: {\n type: mongoose.Schema.Types.Mixed,\n refPath: `${field.name}.relationTo`,\n },\n }\n\n if (field.hasMany) {\n schemaToReturn = {\n type: [schemaToReturn],\n default: undefined,\n }\n }\n } else {\n schemaToReturn = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: mongoose.Schema.Types.Mixed,\n ref: field.relationTo,\n }\n\n if (field.hasMany) {\n schemaToReturn = {\n type: [schemaToReturn],\n default: undefined,\n }\n }\n }\n\n schema.add({\n [field.name]: schemaToReturn,\n })\n },\n richText: (\n field: RichTextField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: mongoose.Schema.Types.Mixed,\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n row: (\n field: RowField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n field.fields.forEach((subField: Field) => {\n const addFieldSchema: FieldSchemaGenerator = fieldToSchemaMap[subField.type]\n\n if (addFieldSchema) {\n addFieldSchema(subField, schema, config, buildSchemaOptions)\n }\n })\n },\n select: (\n field: SelectField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: String,\n enum: field.options.map((option) => {\n if (typeof option === 'object') return option.value\n return option\n }),\n }\n\n if (buildSchemaOptions.draftsEnabled || !field.required) {\n baseSchema.enum.push(null)\n }\n\n schema.add({\n [field.name]: localizeSchema(\n field,\n field.hasMany ? [baseSchema] : baseSchema,\n config.localization,\n ),\n })\n },\n tabs: (\n field: TabsField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n field.tabs.forEach((tab) => {\n if (tabHasName(tab)) {\n const baseSchema = {\n type: buildSchema(config, tab.fields, {\n disableUnique: buildSchemaOptions.disableUnique,\n draftsEnabled: buildSchemaOptions.draftsEnabled,\n options: {\n _id: false,\n id: false,\n minimize: false,\n },\n }),\n }\n\n schema.add({\n [tab.name]: localizeSchema(tab, baseSchema, config.localization),\n })\n } else {\n tab.fields.forEach((subField: Field) => {\n const addFieldSchema: FieldSchemaGenerator = fieldToSchemaMap[subField.type]\n\n if (addFieldSchema) {\n addFieldSchema(subField, schema, config, buildSchemaOptions)\n }\n })\n }\n })\n },\n text: (\n field: TextField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: field.hasMany ? [String] : String,\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n textarea: (\n field: TextareaField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = { ...formatBaseSchema(field, buildSchemaOptions), type: String }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n upload: (\n field: UploadField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: mongoose.Schema.Types.Mixed,\n ref: field.relationTo,\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n}\n\nexport default buildSchema\n"],"names":["mongoose","fieldAffectsData","fieldIsLocalized","fieldIsPresentationalOnly","tabHasName","formatBaseSchema","field","buildSchemaOptions","disableUnique","draftsEnabled","indexSortableFields","schema","index","unique","required","localized","type","sparse","hidden","localizeSchema","entity","localization","Array","isArray","locales","localeCodes","reduce","localeSchema","locale","_id","buildSchema","config","configFields","allowIDField","options","fields","schemaFields","idField","find","name","Number","String","filter","Schema","forEach","addFieldSchema","fieldToSchemaMap","array","baseSchema","id","minimize","default","undefined","add","blocks","fieldSchema","discriminatorKey","blockItem","blockSchema","blockField","localeCode","path","discriminator","slug","checkbox","Boolean","code","collapsible","subField","date","Date","email","group","formattedBaseSchema","json","Types","Mixed","number","hasMany","point","enum","coordinates","defaultValue","indexOptions","radio","map","option","value","relationship","hasManyRelations","relationTo","schemaToReturn","refPath","ref","richText","row","select","push","tabs","tab","text","textarea","upload"],"mappings":"AAAA,oDAAoD,GACpD,yCAAyC,GACzC,0DAA0D,GAgC1D,OAAOA,cAAc,WAAU;AAC/B,SACEC,gBAAgB,EAChBC,gBAAgB,EAChBC,yBAAyB,EACzBC,UAAU,QACL,iBAAgB;AAiBvB,MAAMC,mBAAmB,CAACC,OAA2BC;IACnD,MAAM,EAAEC,aAAa,EAAEC,aAAa,EAAEC,mBAAmB,EAAE,GAAGH;IAC9D,MAAMI,SAAqC;QACzCC,OAAON,MAAMM,KAAK,IAAK,CAACJ,iBAAiBF,MAAMO,MAAM,IAAKH,uBAAuB;QACjFI,UAAU;QACVD,QAAQ,AAAC,CAACL,iBAAiBF,MAAMO,MAAM,IAAK;IAC9C;IAEA,IACEF,OAAOE,MAAM,IACZP,CAAAA,MAAMS,SAAS,IACdN,iBACCR,iBAAiBK,UAChBA,MAAMU,IAAI,KAAK,WACfV,MAAMU,IAAI,KAAK,SACfV,MAAMQ,QAAQ,KAAK,IAAI,GAC3B;QACAH,OAAOM,MAAM,GAAG;IAClB;IAEA,IAAIX,MAAMY,MAAM,EAAE;QAChBP,OAAOO,MAAM,GAAG;IAClB;IAEA,OAAOP;AACT;AAEA,MAAMQ,iBAAiB,CACrBC,QACAT,QACAU;IAEA,IAAInB,iBAAiBkB,WAAWC,gBAAgBC,MAAMC,OAAO,CAACF,aAAaG,OAAO,GAAG;QACnF,OAAO;YACLR,MAAMK,aA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ACAK,QACAoB,QACAxB;QAEA,MAAMyC,aAAa;YACjB,GAAG3C,iBAAiBC,OAAOC,mBAAmB;YAC9CS,MAAMV,MAAMwE,OAAO,GAAG;gBAACrC;aAAO,GAAGA;QACnC;QAEA9B,OAAO0C,GAAG,CAAC;YACT,CAAC/C,MAAMiC,IAAI,CAAC,EAAEpB,eAAeb,OAAO0C,YAAYjB,OAAOV,YAAY;QACrE;IACF;IACAgF,UAAU,CACR/F,OACAK,QACAoB,QACAxB;QAEA,MAAMyC,aAAa;YAAE,GAAG3C,iBAAiBC,OAAOC,mBAAmB;YAAES,MAAMyB;QAAO;QAElF9B,OAAO0C,GAAG,CAAC;YACT,CAAC/C,MAAMiC,IAAI,CAAC,EAAEpB,eAAeb,OAAO0C,YAAYjB,OAAOV,YAAY;QACrE;IACF;IACAiF,QAAQ,CACNhG,OACAK,QACAoB,QACAxB;QAEA,MAAMyC,aAAa;YACjB,GAAG3C,iBAAiBC,OAAOC,mBAAmB;YAC9CS,MAAMhB,SAAS2C,MAAM,CAACgC,KAAK,CAACC,KAAK;YACjCiB,KAAKvF,MAAMoF,UAAU;QACvB;QAEA/E,OAAO0C,GAAG,CAAC;YACT,CAAC/C,MAAMiC,IAAI,CAAC,EAAEpB,eAAeb,OAAO0C,YAAYjB,OAAOV,YAAY;QACrE;IACF;AACF;AAEA,eAAeS,YAAW"}
1
+ {"version":3,"sources":["../../src/models/buildSchema.ts"],"sourcesContent":["import type { IndexOptions, Schema, SchemaOptions, SchemaTypeOptions } from 'mongoose'\nimport type {\n ArrayField,\n Block,\n BlocksField,\n CheckboxField,\n CodeField,\n CollapsibleField,\n DateField,\n EmailField,\n Field,\n FieldAffectingData,\n GroupField,\n JSONField,\n NonPresentationalField,\n NumberField,\n PointField,\n RadioField,\n RelationshipField,\n RichTextField,\n RowField,\n SanitizedConfig,\n SanitizedLocalizationConfig,\n SelectField,\n Tab,\n TabsField,\n TextareaField,\n TextField,\n UploadField,\n} from 'payload'\n\nimport mongoose from 'mongoose'\nimport {\n fieldAffectsData,\n fieldIsLocalized,\n fieldIsPresentationalOnly,\n fieldIsVirtual,\n tabHasName,\n} from 'payload/shared'\n\nexport type BuildSchemaOptions = {\n allowIDField?: boolean\n disableUnique?: boolean\n draftsEnabled?: boolean\n indexSortableFields?: boolean\n options?: SchemaOptions\n}\n\ntype FieldSchemaGenerator = (\n field: Field,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n) => void\n\n/**\n * get a field's defaultValue only if defined and not dynamic so that it can be set on the field schema\n * @param field\n */\nconst formatDefaultValue = (field: FieldAffectingData) =>\n typeof field.defaultValue !== 'undefined' && typeof field.defaultValue !== 'function'\n ? field.defaultValue\n : undefined\n\nconst formatBaseSchema = (field: FieldAffectingData, buildSchemaOptions: BuildSchemaOptions) => {\n const { disableUnique, draftsEnabled, indexSortableFields } = buildSchemaOptions\n const schema: SchemaTypeOptions<unknown> = {\n default: formatDefaultValue(field),\n index: field.index || (!disableUnique && field.unique) || indexSortableFields || false,\n required: false,\n unique: (!disableUnique && field.unique) || false,\n }\n\n if (\n schema.unique &&\n (field.localized ||\n draftsEnabled ||\n (fieldAffectsData(field) &&\n field.type !== 'group' &&\n field.type !== 'tab' &&\n field.required !== true))\n ) {\n schema.sparse = true\n }\n\n if (field.hidden) {\n schema.hidden = true\n }\n\n return schema\n}\n\nconst localizeSchema = (\n entity: NonPresentationalField | Tab,\n schema,\n localization: false | SanitizedLocalizationConfig,\n) => {\n if (fieldIsLocalized(entity) && localization && Array.isArray(localization.locales)) {\n return {\n type: localization.localeCodes.reduce(\n (localeSchema, locale) => ({\n ...localeSchema,\n [locale]: schema,\n }),\n {\n _id: false,\n },\n ),\n localized: true,\n }\n }\n return schema\n}\n\nexport const buildSchema = (\n config: SanitizedConfig,\n configFields: Field[],\n buildSchemaOptions: BuildSchemaOptions = {},\n): Schema => {\n const { allowIDField, options } = buildSchemaOptions\n let fields = {}\n\n let schemaFields = configFields\n\n if (!allowIDField) {\n const idField = schemaFields.find((field) => fieldAffectsData(field) && field.name === 'id')\n if (idField) {\n fields = {\n _id: idField.type === 'number' ? Number : String,\n }\n schemaFields = schemaFields.filter(\n (field) => !(fieldAffectsData(field) && field.name === 'id'),\n )\n }\n }\n\n const schema = new mongoose.Schema(fields, options)\n\n schemaFields.forEach((field) => {\n if (fieldIsVirtual(field)) {\n return\n }\n\n if (!fieldIsPresentationalOnly(field)) {\n const addFieldSchema: FieldSchemaGenerator = fieldToSchemaMap[field.type]\n\n if (addFieldSchema) {\n addFieldSchema(field, schema, config, buildSchemaOptions)\n }\n }\n })\n\n return schema\n}\n\nconst fieldToSchemaMap: Record<string, FieldSchemaGenerator> = {\n array: (\n field: ArrayField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ) => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: [\n buildSchema(config, field.fields, {\n allowIDField: true,\n disableUnique: buildSchemaOptions.disableUnique,\n draftsEnabled: buildSchemaOptions.draftsEnabled,\n options: {\n _id: false,\n id: false,\n minimize: false,\n },\n }),\n ],\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n blocks: (\n field: BlocksField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const fieldSchema = {\n type: [new mongoose.Schema({}, { _id: false, discriminatorKey: 'blockType' })],\n }\n\n schema.add({\n [field.name]: localizeSchema(field, fieldSchema, config.localization),\n })\n\n field.blocks.forEach((blockItem: Block) => {\n const blockSchema = new mongoose.Schema({}, { _id: false, id: false })\n\n blockItem.fields.forEach((blockField) => {\n const addFieldSchema: FieldSchemaGenerator = fieldToSchemaMap[blockField.type]\n if (addFieldSchema) {\n addFieldSchema(blockField, blockSchema, config, buildSchemaOptions)\n }\n })\n\n if (field.localized && config.localization) {\n config.localization.localeCodes.forEach((localeCode) => {\n // @ts-expect-error Possible incorrect typing in mongoose types, this works\n schema.path(`${field.name}.${localeCode}`).discriminator(blockItem.slug, blockSchema)\n })\n } else {\n // @ts-expect-error Possible incorrect typing in mongoose types, this works\n schema.path(field.name).discriminator(blockItem.slug, blockSchema)\n }\n })\n },\n checkbox: (\n field: CheckboxField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = { ...formatBaseSchema(field, buildSchemaOptions), type: Boolean }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n code: (\n field: CodeField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = { ...formatBaseSchema(field, buildSchemaOptions), type: String }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n collapsible: (\n field: CollapsibleField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n field.fields.forEach((subField: Field) => {\n if (fieldIsVirtual(subField)) {\n return\n }\n\n const addFieldSchema: FieldSchemaGenerator = fieldToSchemaMap[subField.type]\n\n if (addFieldSchema) {\n addFieldSchema(subField, schema, config, buildSchemaOptions)\n }\n })\n },\n date: (\n field: DateField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = { ...formatBaseSchema(field, buildSchemaOptions), type: Date }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n email: (\n field: EmailField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = { ...formatBaseSchema(field, buildSchemaOptions), type: String }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n group: (\n field: GroupField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const formattedBaseSchema = formatBaseSchema(field, buildSchemaOptions)\n\n // carry indexSortableFields through to versions if drafts enabled\n const indexSortableFields =\n buildSchemaOptions.indexSortableFields &&\n field.name === 'version' &&\n buildSchemaOptions.draftsEnabled\n\n const baseSchema = {\n ...formattedBaseSchema,\n type: buildSchema(config, field.fields, {\n disableUnique: buildSchemaOptions.disableUnique,\n draftsEnabled: buildSchemaOptions.draftsEnabled,\n indexSortableFields,\n options: {\n _id: false,\n id: false,\n minimize: false,\n },\n }),\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n json: (\n field: JSONField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: mongoose.Schema.Types.Mixed,\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n number: (\n field: NumberField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: field.hasMany ? [Number] : Number,\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n point: (\n field: PointField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema: SchemaTypeOptions<unknown> = {\n type: {\n type: String,\n enum: ['Point'],\n ...(typeof field.defaultValue !== 'undefined' && {\n default: 'Point',\n }),\n },\n coordinates: {\n type: [Number],\n default: formatDefaultValue(field),\n required: false,\n },\n }\n if (buildSchemaOptions.disableUnique && field.unique && field.localized) {\n baseSchema.coordinates.sparse = true\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n\n if (field.index === true || field.index === undefined) {\n const indexOptions: IndexOptions = {}\n if (!buildSchemaOptions.disableUnique && field.unique) {\n indexOptions.sparse = true\n indexOptions.unique = true\n }\n if (field.localized && config.localization) {\n config.localization.locales.forEach((locale) => {\n schema.index({ [`${field.name}.${locale.code}`]: '2dsphere' }, indexOptions)\n })\n } else {\n schema.index({ [field.name]: '2dsphere' }, indexOptions)\n }\n }\n },\n radio: (\n field: RadioField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: String,\n enum: field.options.map((option) => {\n if (typeof option === 'object') {\n return option.value\n }\n return option\n }),\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n relationship: (\n field: RelationshipField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ) => {\n const hasManyRelations = Array.isArray(field.relationTo)\n let schemaToReturn: { [key: string]: any } = {}\n\n if (field.localized && config.localization) {\n schemaToReturn = {\n type: config.localization.localeCodes.reduce((locales, locale) => {\n let localeSchema: { [key: string]: any } = {}\n\n if (hasManyRelations) {\n localeSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n _id: false,\n type: mongoose.Schema.Types.Mixed,\n relationTo: { type: String, enum: field.relationTo },\n value: {\n type: mongoose.Schema.Types.Mixed,\n refPath: `${field.name}.${locale}.relationTo`,\n },\n }\n } else {\n localeSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: mongoose.Schema.Types.Mixed,\n ref: field.relationTo,\n }\n }\n\n return {\n ...locales,\n [locale]: field.hasMany\n ? { type: [localeSchema], default: formatDefaultValue(field) }\n : localeSchema,\n }\n }, {}),\n localized: true,\n }\n } else if (hasManyRelations) {\n schemaToReturn = {\n ...formatBaseSchema(field, buildSchemaOptions),\n _id: false,\n type: mongoose.Schema.Types.Mixed,\n relationTo: { type: String, enum: field.relationTo },\n value: {\n type: mongoose.Schema.Types.Mixed,\n refPath: `${field.name}.relationTo`,\n },\n }\n\n if (field.hasMany) {\n schemaToReturn = {\n type: [schemaToReturn],\n default: formatDefaultValue(field),\n }\n }\n } else {\n schemaToReturn = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: mongoose.Schema.Types.Mixed,\n ref: field.relationTo,\n }\n\n if (field.hasMany) {\n schemaToReturn = {\n type: [schemaToReturn],\n default: formatDefaultValue(field),\n }\n }\n }\n\n schema.add({\n [field.name]: schemaToReturn,\n })\n },\n richText: (\n field: RichTextField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: mongoose.Schema.Types.Mixed,\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n row: (\n field: RowField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n field.fields.forEach((subField: Field) => {\n if (fieldIsVirtual(subField)) {\n return\n }\n\n const addFieldSchema: FieldSchemaGenerator = fieldToSchemaMap[subField.type]\n\n if (addFieldSchema) {\n addFieldSchema(subField, schema, config, buildSchemaOptions)\n }\n })\n },\n select: (\n field: SelectField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: String,\n enum: field.options.map((option) => {\n if (typeof option === 'object') {\n return option.value\n }\n return option\n }),\n }\n\n if (buildSchemaOptions.draftsEnabled || !field.required) {\n baseSchema.enum.push(null)\n }\n\n schema.add({\n [field.name]: localizeSchema(\n field,\n field.hasMany ? [baseSchema] : baseSchema,\n config.localization,\n ),\n })\n },\n tabs: (\n field: TabsField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n field.tabs.forEach((tab) => {\n if (tabHasName(tab)) {\n if (fieldIsVirtual(tab)) {\n return\n }\n const baseSchema = {\n type: buildSchema(config, tab.fields, {\n disableUnique: buildSchemaOptions.disableUnique,\n draftsEnabled: buildSchemaOptions.draftsEnabled,\n options: {\n _id: false,\n id: false,\n minimize: false,\n },\n }),\n }\n\n schema.add({\n [tab.name]: localizeSchema(tab, baseSchema, config.localization),\n })\n } else {\n tab.fields.forEach((subField: Field) => {\n if (fieldIsVirtual(subField)) {\n return\n }\n const addFieldSchema: FieldSchemaGenerator = fieldToSchemaMap[subField.type]\n\n if (addFieldSchema) {\n addFieldSchema(subField, schema, config, buildSchemaOptions)\n }\n })\n }\n })\n },\n text: (\n field: TextField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: field.hasMany ? [String] : String,\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n textarea: (\n field: TextareaField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = { ...formatBaseSchema(field, buildSchemaOptions), type: String }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n upload: (\n field: UploadField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const hasManyRelations = Array.isArray(field.relationTo)\n let schemaToReturn: { [key: string]: any } = {}\n\n if (field.localized && config.localization) {\n schemaToReturn = {\n type: config.localization.localeCodes.reduce((locales, locale) => {\n let localeSchema: { [key: string]: any } = {}\n\n if (hasManyRelations) {\n localeSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n _id: false,\n type: mongoose.Schema.Types.Mixed,\n relationTo: { type: String, enum: field.relationTo },\n value: {\n type: mongoose.Schema.Types.Mixed,\n refPath: `${field.name}.${locale}.relationTo`,\n },\n }\n } else {\n localeSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: mongoose.Schema.Types.Mixed,\n ref: field.relationTo,\n }\n }\n\n return {\n ...locales,\n [locale]: field.hasMany\n ? { type: [localeSchema], default: formatDefaultValue(field) }\n : localeSchema,\n }\n }, {}),\n localized: true,\n }\n } else if (hasManyRelations) {\n schemaToReturn = {\n ...formatBaseSchema(field, buildSchemaOptions),\n _id: false,\n type: mongoose.Schema.Types.Mixed,\n relationTo: { type: String, enum: field.relationTo },\n value: {\n type: mongoose.Schema.Types.Mixed,\n refPath: `${field.name}.relationTo`,\n },\n }\n\n if (field.hasMany) {\n schemaToReturn = {\n type: [schemaToReturn],\n default: formatDefaultValue(field),\n }\n }\n } else {\n schemaToReturn = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: mongoose.Schema.Types.Mixed,\n ref: field.relationTo,\n }\n\n if (field.hasMany) {\n schemaToReturn = {\n type: [schemaToReturn],\n default: formatDefaultValue(field),\n }\n }\n }\n\n schema.add({\n [field.name]: schemaToReturn,\n })\n },\n}\n"],"names":["mongoose","fieldAffectsData","fieldIsLocalized","fieldIsPresentationalOnly","fieldIsVirtual","tabHasName","formatDefaultValue","field","defaultValue","undefined","formatBaseSchema","buildSchemaOptions","disableUnique","draftsEnabled","indexSortableFields","schema","default","index","unique","required","localized","type","sparse","hidden","localizeSchema","entity","localization","Array","isArray","locales","localeCodes","reduce","localeSchema","locale","_id","buildSchema","config","configFields","allowIDField","options","fields","schemaFields","idField","find","name","Number","String","filter","Schema","forEach","addFieldSchema","fieldToSchemaMap","array","baseSchema","id","minimize","add","blocks","fieldSchema","discriminatorKey","blockItem","blockSchema","blockField","localeCode","path","discriminator","slug","checkbox","Boolean","code","collapsible","subField","date","Date","email","group","formattedBaseSchema","json","Types","Mixed","number","hasMany","point","enum","coordinates","indexOptions","radio","map","option","value","relationship","hasManyRelations","relationTo","schemaToReturn","refPath","ref","richText","row","select","push","tabs","tab","text","textarea","upload"],"mappings":"AA+BA,OAAOA,cAAc,WAAU;AAC/B,SACEC,gBAAgB,EAChBC,gBAAgB,EAChBC,yBAAyB,EACzBC,cAAc,EACdC,UAAU,QACL,iBAAgB;AAiBvB;;;CAGC,GACD,MAAMC,qBAAqB,CAACC,QAC1B,OAAOA,MAAMC,YAAY,KAAK,eAAe,OAAOD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wBACV,CAACI,OAAO,EAAE1B,MAAM0E,OAAO,GACnB;4BAAE5D,MAAM;gCAACW;6BAAa;4BAAEhB,SAASV,mBAAmBC;wBAAO,IAC3DyB;oBACN;gBACF,GAAG,CAAC;gBACJZ,WAAW;YACb;QACF,OAAO,IAAIuE,kBAAkB;YAC3BE,iBAAiB;gBACf,GAAGnF,iBAAiBH,OAAOI,mBAAmB;gBAC9CuB,KAAK;gBACLb,MAAMrB,SAASgD,MAAM,CAAC8B,KAAK,CAACC,KAAK;gBACjCa,YAAY;oBAAEvE,MAAMyB;oBAAQqC,MAAM5E,MAAMqF,UAAU;gBAAC;gBACnDH,OAAO;oBACLpE,MAAMrB,SAASgD,MAAM,CAAC8B,KAAK,CAACC,KAAK;oBACjCe,SAAS,CAAC,EAAEvF,MAAMqC,IAAI,CAAC,WAAW,CAAC;gBACrC;YACF;YAEA,IAAIrC,MAAM0E,OAAO,EAAE;gBACjBY,iBAAiB;oBACfxE,MAAM;wBAACwE;qBAAe;oBACtB7E,SAASV,mBAAmBC;gBAC9B;YACF;QACF,OAAO;YACLsF,iBAAiB;gBACf,GAAGnF,iBAAiBH,OAAOI,mBAAmB;gBAC9CU,MAAMrB,SAASgD,MAAM,CAAC8B,KAAK,CAACC,KAAK;gBACjCgB,KAAKxF,MAAMqF,UAAU;YACvB;YAEA,IAAIrF,MAAM0E,OAAO,EAAE;gBACjBY,iBAAiB;oBACfxE,MAAM;wBAACwE;qBAAe;oBACtB7E,SAASV,mBAAmBC;gBAC9B;YACF;QACF;QAEAQ,OAAOyC,GAAG,CAAC;YACT,CAACjD,MAAMqC,IAAI,CAAC,EAAEiD;QAChB;IACF;AACF"}
@@ -0,0 +1,6 @@
1
+ import type { PayloadRequest } from 'payload';
2
+ export declare function migrateRelationshipsV2_V3({ batchSize, req, }: {
3
+ batchSize: number;
4
+ req: PayloadRequest;
5
+ }): Promise<void>;
6
+ //# sourceMappingURL=migrateRelationshipsV2_V3.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrateRelationshipsV2_V3.d.ts","sourceRoot":"","sources":["../../src/predefinedMigrations/migrateRelationshipsV2_V3.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAS,cAAc,EAAmB,MAAM,SAAS,CAAA;AAmGrE,wBAAsB,yBAAyB,CAAC,EAC9C,SAAS,EACT,GAAG,GACJ,EAAE;IACD,SAAS,EAAE,MAAM,CAAA;IACjB,GAAG,EAAE,cAAc,CAAA;CACpB,GAAG,OAAO,CAAC,IAAI,CAAC,CA4EhB"}
@@ -0,0 +1,141 @@
1
+ import { buildVersionCollectionFields, buildVersionGlobalFields } from 'payload';
2
+ import { sanitizeRelationshipIDs } from '../utilities/sanitizeRelationshipIDs.js';
3
+ import { withSession } from '../withSession.js';
4
+ const migrateModelWithBatching = async ({ batchSize, config, fields, Model, session })=>{
5
+ let hasNext = true;
6
+ let skip = 0;
7
+ while(hasNext){
8
+ const docs = await Model.find({}, {}, {
9
+ lean: true,
10
+ limit: batchSize + 1,
11
+ session,
12
+ skip
13
+ });
14
+ if (docs.length === 0) {
15
+ break;
16
+ }
17
+ hasNext = docs.length > batchSize;
18
+ if (hasNext) {
19
+ docs.pop();
20
+ }
21
+ for (const doc of docs){
22
+ sanitizeRelationshipIDs({
23
+ config,
24
+ data: doc,
25
+ fields
26
+ });
27
+ }
28
+ await Model.collection.bulkWrite(docs.map((doc)=>({
29
+ updateOne: {
30
+ filter: {
31
+ _id: doc._id
32
+ },
33
+ update: {
34
+ $set: doc
35
+ }
36
+ }
37
+ })), {
38
+ session
39
+ });
40
+ skip += batchSize;
41
+ }
42
+ };
43
+ const hasRelationshipOrUploadField = ({ fields })=>{
44
+ for (const field of fields){
45
+ if (field.type === 'relationship' || field.type === 'upload') {
46
+ return true;
47
+ }
48
+ if ('fields' in field) {
49
+ if (hasRelationshipOrUploadField({
50
+ fields: field.fields
51
+ })) {
52
+ return true;
53
+ }
54
+ }
55
+ if ('blocks' in field) {
56
+ for (const block of field.blocks){
57
+ if (hasRelationshipOrUploadField({
58
+ fields: block.fields
59
+ })) {
60
+ return true;
61
+ }
62
+ }
63
+ }
64
+ if ('tabs' in field) {
65
+ for (const tab of field.tabs){
66
+ if (hasRelationshipOrUploadField({
67
+ fields: tab.fields
68
+ })) {
69
+ return true;
70
+ }
71
+ }
72
+ }
73
+ }
74
+ return false;
75
+ };
76
+ export async function migrateRelationshipsV2_V3({ batchSize, req }) {
77
+ const { payload } = req;
78
+ const db = payload.db;
79
+ const config = payload.config;
80
+ const { session } = await withSession(db, req);
81
+ for (const collection of payload.config.collections.filter(hasRelationshipOrUploadField)){
82
+ payload.logger.info(`Migrating collection "${collection.slug}"`);
83
+ await migrateModelWithBatching({
84
+ batchSize,
85
+ config,
86
+ fields: collection.fields,
87
+ Model: db.collections[collection.slug],
88
+ session
89
+ });
90
+ payload.logger.info(`Migrated collection "${collection.slug}"`);
91
+ if (collection.versions) {
92
+ payload.logger.info(`Migrating collection versions "${collection.slug}"`);
93
+ await migrateModelWithBatching({
94
+ batchSize,
95
+ config,
96
+ fields: buildVersionCollectionFields(config, collection),
97
+ Model: db.versions[collection.slug],
98
+ session
99
+ });
100
+ payload.logger.info(`Migrated collection versions "${collection.slug}"`);
101
+ }
102
+ }
103
+ const { globals: GlobalsModel } = db;
104
+ for (const global of payload.config.globals.filter(hasRelationshipOrUploadField)){
105
+ payload.logger.info(`Migrating global "${global.slug}"`);
106
+ const doc = await GlobalsModel.findOne({
107
+ globalType: {
108
+ $eq: global.slug
109
+ }
110
+ }, {}, {
111
+ lean: true,
112
+ session
113
+ });
114
+ sanitizeRelationshipIDs({
115
+ config,
116
+ data: doc,
117
+ fields: global.fields
118
+ });
119
+ await GlobalsModel.collection.updateOne({
120
+ globalType: global.slug
121
+ }, {
122
+ $set: doc
123
+ }, {
124
+ session
125
+ });
126
+ payload.logger.info(`Migrated global "${global.slug}"`);
127
+ if (global.versions) {
128
+ payload.logger.info(`Migrating global versions "${global.slug}"`);
129
+ await migrateModelWithBatching({
130
+ batchSize,
131
+ config,
132
+ fields: buildVersionGlobalFields(config, global),
133
+ Model: db.versions[global.slug],
134
+ session
135
+ });
136
+ payload.logger.info(`Migrated global versions "${global.slug}"`);
137
+ }
138
+ }
139
+ }
140
+
141
+ //# sourceMappingURL=migrateRelationshipsV2_V3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/predefinedMigrations/migrateRelationshipsV2_V3.ts"],"sourcesContent":["import type { ClientSession, Model } from 'mongoose'\nimport type { Field, PayloadRequest, SanitizedConfig } from 'payload'\n\nimport { buildVersionCollectionFields, buildVersionGlobalFields } from 'payload'\n\nimport type { MongooseAdapter } from '../index.js'\n\nimport { sanitizeRelationshipIDs } from '../utilities/sanitizeRelationshipIDs.js'\nimport { withSession } from '../withSession.js'\n\nconst migrateModelWithBatching = async ({\n batchSize,\n config,\n fields,\n Model,\n session,\n}: {\n batchSize: number\n config: SanitizedConfig\n fields: Field[]\n Model: Model<any>\n session: ClientSession\n}): Promise<void> => {\n let hasNext = true\n let skip = 0\n\n while (hasNext) {\n const docs = await Model.find(\n {},\n {},\n {\n lean: true,\n limit: batchSize + 1,\n session,\n skip,\n },\n )\n\n if (docs.length === 0) {\n break\n }\n\n hasNext = docs.length > batchSize\n\n if (hasNext) {\n docs.pop()\n }\n\n for (const doc of docs) {\n sanitizeRelationshipIDs({ config, data: doc, fields })\n }\n\n await Model.collection.bulkWrite(\n docs.map((doc) => ({\n updateOne: {\n filter: { _id: doc._id },\n update: {\n $set: doc,\n },\n },\n })),\n { session },\n )\n\n skip += batchSize\n }\n}\n\nconst hasRelationshipOrUploadField = ({ fields }: { fields: Field[] }): boolean => {\n for (const field of fields) {\n if (field.type === 'relationship' || field.type === 'upload') {\n return true\n }\n\n if ('fields' in field) {\n if (hasRelationshipOrUploadField({ fields: field.fields })) {\n return true\n }\n }\n\n if ('blocks' in field) {\n for (const block of field.blocks) {\n if (hasRelationshipOrUploadField({ fields: block.fields })) {\n return true\n }\n }\n }\n\n if ('tabs' in field) {\n for (const tab of field.tabs) {\n if (hasRelationshipOrUploadField({ fields: tab.fields })) {\n return true\n }\n }\n }\n }\n\n return false\n}\n\nexport async function migrateRelationshipsV2_V3({\n batchSize,\n req,\n}: {\n batchSize: number\n req: PayloadRequest\n}): Promise<void> {\n const { payload } = req\n const db = payload.db as MongooseAdapter\n const config = payload.config\n\n const { session } = await withSession(db, req)\n\n for (const collection of payload.config.collections.filter(hasRelationshipOrUploadField)) {\n payload.logger.info(`Migrating collection \"${collection.slug}\"`)\n\n await migrateModelWithBatching({\n batchSize,\n config,\n fields: collection.fields,\n Model: db.collections[collection.slug],\n session,\n })\n\n payload.logger.info(`Migrated collection \"${collection.slug}\"`)\n\n if (collection.versions) {\n payload.logger.info(`Migrating collection versions \"${collection.slug}\"`)\n\n await migrateModelWithBatching({\n batchSize,\n config,\n fields: buildVersionCollectionFields(config, collection),\n Model: db.versions[collection.slug],\n session,\n })\n\n payload.logger.info(`Migrated collection versions \"${collection.slug}\"`)\n }\n }\n\n const { globals: GlobalsModel } = db\n\n for (const global of payload.config.globals.filter(hasRelationshipOrUploadField)) {\n payload.logger.info(`Migrating global \"${global.slug}\"`)\n\n const doc = await GlobalsModel.findOne<Record<string, unknown>>(\n {\n globalType: {\n $eq: global.slug,\n },\n },\n {},\n { lean: true, session },\n )\n\n sanitizeRelationshipIDs({ config, data: doc, fields: global.fields })\n\n await GlobalsModel.collection.updateOne(\n {\n globalType: global.slug,\n },\n { $set: doc },\n { session },\n )\n\n payload.logger.info(`Migrated global \"${global.slug}\"`)\n\n if (global.versions) {\n payload.logger.info(`Migrating global versions \"${global.slug}\"`)\n\n await migrateModelWithBatching({\n batchSize,\n config,\n fields: buildVersionGlobalFields(config, global),\n Model: db.versions[global.slug],\n session,\n })\n\n payload.logger.info(`Migrated global versions \"${global.slug}\"`)\n }\n }\n}\n"],"names":["buildVersionCollectionFields","buildVersionGlobalFields","sanitizeRelationshipIDs","withSession","migrateModelWithBatching","batchSize","config","fields","Model","session","hasNext","skip","docs","find","lean","limit","length","pop","doc","data","collection","bulkWrite","map","updateOne","filter","_id","update","$set","hasRelationshipOrUploadField","field","type","block","blocks","tab","tabs","migrateRelationshipsV2_V3","req","payload","db","collections","logger","info","slug","versions","globals","GlobalsModel","global","findOne","globalType","$eq"],"mappings":"AAGA,SAASA,4BAA4B,EAAEC,wBAAwB,QAAQ,UAAS;AAIhF,SAASC,uBAAuB,QAAQ,0CAAyC;AACjF,SAASC,WAAW,QAAQ,oBAAmB;AAE/C,MAAMC,2BAA2B,OAAO,EACtCC,SAAS,EACTC,MAAM,EACNC,MAAM,EACNC,KAAK,EACLC,OAAO,EAOR;IACC,IAAIC,UAAU;IACd,IAAIC,OAAO;IAEX,MAAOD,QAAS;QACd,MAAME,OAAO,MAAMJ,MAAMK,IAAI,CAC3B,CAAC,GACD,CAAC,GACD;YACEC,MAAM;YACNC,OAAOV,YAAY;YACnBI;YACAE;QACF;QAGF,IAAIC,KAAKI,MAAM,KAAK,GAAG;YACrB;QACF;QAEAN,UAAUE,KAAKI,MAAM,GAAGX;QAExB,IAAIK,SAAS;YACXE,KAAKK,GAAG;QACV;QAEA,KAAK,MAAMC,OAAON,KAAM;YACtBV,wBAAwB;gBAAEI;gBAAQa,MAAMD;gBAAKX;YAAO;QACtD;QAEA,MAAMC,MAAMY,UAAU,CAACC,SAAS,CAC9BT,KAAKU,GAAG,CAAC,CAACJ,MAAS,CAAA;gBACjBK,WAAW;oBACTC,QAAQ;wBAAEC,KAAKP,IAAIO,GAAG;oBAAC;oBACvBC,QAAQ;wBACNC,MAAMT;oBACR;gBACF;YACF,CAAA,IACA;YAAET;QAAQ;QAGZE,QAAQN;IACV;AACF;AAEA,MAAMuB,+BAA+B,CAAC,EAAErB,MAAM,EAAuB;IACnE,KAAK,MAAMsB,SAAStB,OAAQ;QAC1B,IAAIsB,MAAMC,IAAI,KAAK,kBAAkBD,MAAMC,IAAI,KAAK,UAAU;YAC5D,OAAO;QACT;QAEA,IAAI,YAAYD,OA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EAAEK,OAAOJ,IAAI,CAAC,CAAC,CAAC;QACjE;IACF;AACF"}
@@ -0,0 +1,5 @@
1
+ import type { PayloadRequest } from 'payload';
2
+ export declare function migrateVersionsV1_V2({ req }: {
3
+ req: PayloadRequest;
4
+ }): Promise<void>;
5
+ //# sourceMappingURL=migrateVersionsV1_V2.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrateVersionsV1_V2.d.ts","sourceRoot":"","sources":["../../src/predefinedMigrations/migrateVersionsV1_V2.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAW,cAAc,EAAE,MAAM,SAAS,CAAA;AAMtD,wBAAsB,oBAAoB,CAAC,EAAE,GAAG,EAAE,EAAE;IAAE,GAAG,EAAE,cAAc,CAAA;CAAE,iBAgC1E"}