@payloadcms/db-mongodb 3.24.0-canary.72057b1 → 3.24.0-canary.7d9fbaf

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/dist/find.d.ts.map +1 -1
  2. package/dist/find.js +1 -0
  3. package/dist/find.js.map +1 -1
  4. package/dist/findGlobalVersions.d.ts.map +1 -1
  5. package/dist/findGlobalVersions.js +1 -0
  6. package/dist/findGlobalVersions.js.map +1 -1
  7. package/dist/findVersions.d.ts.map +1 -1
  8. package/dist/findVersions.js +1 -0
  9. package/dist/findVersions.js.map +1 -1
  10. package/dist/init.d.ts.map +1 -1
  11. package/dist/init.js +26 -16
  12. package/dist/init.js.map +1 -1
  13. package/dist/models/buildCollectionSchema.d.ts.map +1 -1
  14. package/dist/models/buildCollectionSchema.js +13 -16
  15. package/dist/models/buildCollectionSchema.js.map +1 -1
  16. package/dist/models/buildGlobalModel.d.ts.map +1 -1
  17. package/dist/models/buildGlobalModel.js +9 -4
  18. package/dist/models/buildGlobalModel.js.map +1 -1
  19. package/dist/models/buildSchema.d.ts +6 -1
  20. package/dist/models/buildSchema.d.ts.map +1 -1
  21. package/dist/models/buildSchema.js +225 -103
  22. package/dist/models/buildSchema.js.map +1 -1
  23. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts.map +1 -1
  24. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js +9 -2
  25. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js.map +1 -1
  26. package/dist/queries/buildAndOrConditions.d.ts +2 -1
  27. package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
  28. package/dist/queries/buildAndOrConditions.js +2 -1
  29. package/dist/queries/buildAndOrConditions.js.map +1 -1
  30. package/dist/queries/buildQuery.d.ts.map +1 -1
  31. package/dist/queries/buildQuery.js +1 -0
  32. package/dist/queries/buildQuery.js.map +1 -1
  33. package/dist/queries/buildSearchParams.d.ts +2 -1
  34. package/dist/queries/buildSearchParams.d.ts.map +1 -1
  35. package/dist/queries/buildSearchParams.js +4 -1
  36. package/dist/queries/buildSearchParams.js.map +1 -1
  37. package/dist/queries/buildSortParam.d.ts +2 -1
  38. package/dist/queries/buildSortParam.d.ts.map +1 -1
  39. package/dist/queries/buildSortParam.js +2 -1
  40. package/dist/queries/buildSortParam.js.map +1 -1
  41. package/dist/queries/getLocalizedSortProperty.d.ts +2 -1
  42. package/dist/queries/getLocalizedSortProperty.d.ts.map +1 -1
  43. package/dist/queries/getLocalizedSortProperty.js +14 -4
  44. package/dist/queries/getLocalizedSortProperty.js.map +1 -1
  45. package/dist/queries/parseParams.d.ts +2 -1
  46. package/dist/queries/parseParams.d.ts.map +1 -1
  47. package/dist/queries/parseParams.js +3 -1
  48. package/dist/queries/parseParams.js.map +1 -1
  49. package/dist/queries/sanitizeQueryValue.d.ts +2 -1
  50. package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
  51. package/dist/queries/sanitizeQueryValue.js +14 -5
  52. package/dist/queries/sanitizeQueryValue.js.map +1 -1
  53. package/dist/queryDrafts.d.ts.map +1 -1
  54. package/dist/queryDrafts.js +1 -0
  55. package/dist/queryDrafts.js.map +1 -1
  56. package/dist/utilities/buildJoinAggregation.d.ts.map +1 -1
  57. package/dist/utilities/buildJoinAggregation.js +6 -1
  58. package/dist/utilities/buildJoinAggregation.js.map +1 -1
  59. package/dist/utilities/buildProjectionFromSelect.d.ts.map +1 -1
  60. package/dist/utilities/buildProjectionFromSelect.js +7 -3
  61. package/dist/utilities/buildProjectionFromSelect.js.map +1 -1
  62. package/dist/utilities/sanitizeRelationshipIDs.d.ts +2 -1
  63. package/dist/utilities/sanitizeRelationshipIDs.d.ts.map +1 -1
  64. package/dist/utilities/sanitizeRelationshipIDs.js +8 -3
  65. package/dist/utilities/sanitizeRelationshipIDs.js.map +1 -1
  66. package/dist/utilities/sanitizeRelationshipIDs.spec.js +44 -0
  67. package/dist/utilities/sanitizeRelationshipIDs.spec.js.map +1 -1
  68. package/package.json +3 -3
@@ -1,10 +1,10 @@
1
1
  import mongoose from 'mongoose';
2
- import { fieldAffectsData, fieldIsLocalized, fieldIsPresentationalOnly, fieldIsVirtual, tabHasName } from 'payload/shared';
2
+ import { fieldAffectsData, fieldIsPresentationalOnly, fieldIsVirtual, fieldShouldBeLocalized, tabHasName } from 'payload/shared';
3
3
  /**
4
4
  * get a field's defaultValue only if defined and not dynamic so that it can be set on the field schema
5
5
  * @param field
6
6
  */ const formatDefaultValue = (field)=>typeof field.defaultValue !== 'undefined' && typeof field.defaultValue !== 'function' ? field.defaultValue : undefined;
7
- const formatBaseSchema = (field, buildSchemaOptions)=>{
7
+ const formatBaseSchema = ({ buildSchemaOptions, field, parentIsLocalized })=>{
8
8
  const { disableUnique, draftsEnabled, indexSortableFields } = buildSchemaOptions;
9
9
  const schema = {
10
10
  default: formatDefaultValue(field),
@@ -12,7 +12,10 @@ const formatBaseSchema = (field, buildSchemaOptions)=>{
12
12
  required: false,
13
13
  unique: !disableUnique && field.unique || false
14
14
  };
15
- if (schema.unique && (field.localized || draftsEnabled || fieldAffectsData(field) && field.type !== 'group' && field.type !== 'tab' && field.required !== true)) {
15
+ if (schema.unique && (fieldShouldBeLocalized({
16
+ field,
17
+ parentIsLocalized
18
+ }) || draftsEnabled || fieldAffectsData(field) && field.type !== 'group' && field.type !== 'tab' && field.required !== true)) {
16
19
  schema.sparse = true;
17
20
  }
18
21
  if (field.hidden) {
@@ -20,8 +23,11 @@ const formatBaseSchema = (field, buildSchemaOptions)=>{
20
23
  }
21
24
  return schema;
22
25
  };
23
- const localizeSchema = (entity, schema, localization)=>{
24
- if (fieldIsLocalized(entity) && localization && Array.isArray(localization.locales)) {
26
+ const localizeSchema = (entity, schema, localization, parentIsLocalized)=>{
27
+ if (fieldShouldBeLocalized({
28
+ field: entity,
29
+ parentIsLocalized
30
+ }) && localization && Array.isArray(localization.locales)) {
25
31
  return {
26
32
  type: localization.localeCodes.reduce((localeSchema, locale)=>({
27
33
  ...localeSchema,
@@ -34,7 +40,8 @@ const localizeSchema = (entity, schema, localization)=>{
34
40
  }
35
41
  return schema;
36
42
  };
37
- export const buildSchema = (payload, configFields, buildSchemaOptions = {})=>{
43
+ export const buildSchema = (args)=>{
44
+ const { buildSchemaOptions = {}, configFields, parentIsLocalized, payload } = args;
38
45
  const { allowIDField, options } = buildSchemaOptions;
39
46
  let fields = {};
40
47
  let schemaFields = configFields;
@@ -55,34 +62,43 @@ export const buildSchema = (payload, configFields, buildSchemaOptions = {})=>{
55
62
  if (!fieldIsPresentationalOnly(field)) {
56
63
  const addFieldSchema = fieldToSchemaMap[field.type];
57
64
  if (addFieldSchema) {
58
- addFieldSchema(field, schema, payload, buildSchemaOptions);
65
+ addFieldSchema(field, schema, payload, buildSchemaOptions, parentIsLocalized);
59
66
  }
60
67
  }
61
68
  });
62
69
  return schema;
63
70
  };
64
71
  const fieldToSchemaMap = {
65
- array: (field, schema, payload, buildSchemaOptions)=>{
72
+ array: (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
66
73
  const baseSchema = {
67
- ...formatBaseSchema(field, buildSchemaOptions),
74
+ ...formatBaseSchema({
75
+ buildSchemaOptions,
76
+ field,
77
+ parentIsLocalized
78
+ }),
68
79
  type: [
69
- buildSchema(payload, field.fields, {
70
- allowIDField: true,
71
- disableUnique: buildSchemaOptions.disableUnique,
72
- draftsEnabled: buildSchemaOptions.draftsEnabled,
73
- options: {
74
- _id: false,
75
- id: false,
76
- minimize: false
77
- }
80
+ buildSchema({
81
+ buildSchemaOptions: {
82
+ allowIDField: true,
83
+ disableUnique: buildSchemaOptions.disableUnique,
84
+ draftsEnabled: buildSchemaOptions.draftsEnabled,
85
+ options: {
86
+ _id: false,
87
+ id: false,
88
+ minimize: false
89
+ }
90
+ },
91
+ configFields: field.fields,
92
+ parentIsLocalized: parentIsLocalized || field.localized,
93
+ payload
78
94
  })
79
95
  ]
80
96
  };
81
97
  schema.add({
82
- [field.name]: localizeSchema(field, baseSchema, payload.config.localization)
98
+ [field.name]: localizeSchema(field, baseSchema, payload.config.localization, parentIsLocalized)
83
99
  });
84
100
  },
85
- blocks: (field, schema, payload, buildSchemaOptions)=>{
101
+ blocks: (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
86
102
  const fieldSchema = {
87
103
  type: [
88
104
  new mongoose.Schema({}, {
@@ -92,119 +108,156 @@ const fieldToSchemaMap = {
92
108
  ]
93
109
  };
94
110
  schema.add({
95
- [field.name]: localizeSchema(field, fieldSchema, payload.config.localization)
111
+ [field.name]: localizeSchema(field, fieldSchema, payload.config.localization, parentIsLocalized)
96
112
  });
97
- field.blocks.forEach((blockItem)=>{
113
+ (field.blockReferences ?? field.blocks).forEach((blockItem)=>{
98
114
  const blockSchema = new mongoose.Schema({}, {
99
115
  _id: false,
100
116
  id: false
101
117
  });
102
- blockItem.fields.forEach((blockField)=>{
118
+ const block = typeof blockItem === 'string' ? payload.blocks[blockItem] : blockItem;
119
+ block.fields.forEach((blockField)=>{
103
120
  const addFieldSchema = fieldToSchemaMap[blockField.type];
104
121
  if (addFieldSchema) {
105
- addFieldSchema(blockField, blockSchema, payload, buildSchemaOptions);
122
+ addFieldSchema(blockField, blockSchema, payload, buildSchemaOptions, parentIsLocalized || field.localized);
106
123
  }
107
124
  });
108
- if (field.localized && payload.config.localization) {
125
+ if (fieldShouldBeLocalized({
126
+ field,
127
+ parentIsLocalized
128
+ }) && payload.config.localization) {
109
129
  payload.config.localization.localeCodes.forEach((localeCode)=>{
110
130
  // @ts-expect-error Possible incorrect typing in mongoose types, this works
111
- schema.path(`${field.name}.${localeCode}`).discriminator(blockItem.slug, blockSchema);
131
+ schema.path(`${field.name}.${localeCode}`).discriminator(block.slug, blockSchema);
112
132
  });
113
133
  } else {
114
134
  // @ts-expect-error Possible incorrect typing in mongoose types, this works
115
- schema.path(field.name).discriminator(blockItem.slug, blockSchema);
135
+ schema.path(field.name).discriminator(block.slug, blockSchema);
116
136
  }
117
137
  });
118
138
  },
119
- checkbox: (field, schema, payload, buildSchemaOptions)=>{
139
+ checkbox: (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
120
140
  const baseSchema = {
121
- ...formatBaseSchema(field, buildSchemaOptions),
141
+ ...formatBaseSchema({
142
+ buildSchemaOptions,
143
+ field,
144
+ parentIsLocalized
145
+ }),
122
146
  type: Boolean
123
147
  };
124
148
  schema.add({
125
- [field.name]: localizeSchema(field, baseSchema, payload.config.localization)
149
+ [field.name]: localizeSchema(field, baseSchema, payload.config.localization, parentIsLocalized)
126
150
  });
127
151
  },
128
- code: (field, schema, payload, buildSchemaOptions)=>{
152
+ code: (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
129
153
  const baseSchema = {
130
- ...formatBaseSchema(field, buildSchemaOptions),
154
+ ...formatBaseSchema({
155
+ buildSchemaOptions,
156
+ field,
157
+ parentIsLocalized
158
+ }),
131
159
  type: String
132
160
  };
133
161
  schema.add({
134
- [field.name]: localizeSchema(field, baseSchema, payload.config.localization)
162
+ [field.name]: localizeSchema(field, baseSchema, payload.config.localization, parentIsLocalized)
135
163
  });
136
164
  },
137
- collapsible: (field, schema, payload, buildSchemaOptions)=>{
165
+ collapsible: (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
138
166
  field.fields.forEach((subField)=>{
139
167
  if (fieldIsVirtual(subField)) {
140
168
  return;
141
169
  }
142
170
  const addFieldSchema = fieldToSchemaMap[subField.type];
143
171
  if (addFieldSchema) {
144
- addFieldSchema(subField, schema, payload, buildSchemaOptions);
172
+ addFieldSchema(subField, schema, payload, buildSchemaOptions, parentIsLocalized);
145
173
  }
146
174
  });
147
175
  },
148
- date: (field, schema, payload, buildSchemaOptions)=>{
176
+ date: (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
149
177
  const baseSchema = {
150
- ...formatBaseSchema(field, buildSchemaOptions),
178
+ ...formatBaseSchema({
179
+ buildSchemaOptions,
180
+ field,
181
+ parentIsLocalized
182
+ }),
151
183
  type: Date
152
184
  };
153
185
  schema.add({
154
- [field.name]: localizeSchema(field, baseSchema, payload.config.localization)
186
+ [field.name]: localizeSchema(field, baseSchema, payload.config.localization, parentIsLocalized)
155
187
  });
156
188
  },
157
- email: (field, schema, payload, buildSchemaOptions)=>{
189
+ email: (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
158
190
  const baseSchema = {
159
- ...formatBaseSchema(field, buildSchemaOptions),
191
+ ...formatBaseSchema({
192
+ buildSchemaOptions,
193
+ field,
194
+ parentIsLocalized
195
+ }),
160
196
  type: String
161
197
  };
162
198
  schema.add({
163
- [field.name]: localizeSchema(field, baseSchema, payload.config.localization)
199
+ [field.name]: localizeSchema(field, baseSchema, payload.config.localization, parentIsLocalized)
164
200
  });
165
201
  },
166
- group: (field, schema, payload, buildSchemaOptions)=>{
167
- const formattedBaseSchema = formatBaseSchema(field, buildSchemaOptions);
202
+ group: (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
203
+ const formattedBaseSchema = formatBaseSchema({
204
+ buildSchemaOptions,
205
+ field,
206
+ parentIsLocalized
207
+ });
168
208
  // carry indexSortableFields through to versions if drafts enabled
169
209
  const indexSortableFields = buildSchemaOptions.indexSortableFields && field.name === 'version' && buildSchemaOptions.draftsEnabled;
170
210
  const baseSchema = {
171
211
  ...formattedBaseSchema,
172
- type: buildSchema(payload, field.fields, {
173
- disableUnique: buildSchemaOptions.disableUnique,
174
- draftsEnabled: buildSchemaOptions.draftsEnabled,
175
- indexSortableFields,
176
- options: {
177
- _id: false,
178
- id: false,
179
- minimize: false
180
- }
212
+ type: buildSchema({
213
+ buildSchemaOptions: {
214
+ disableUnique: buildSchemaOptions.disableUnique,
215
+ draftsEnabled: buildSchemaOptions.draftsEnabled,
216
+ indexSortableFields,
217
+ options: {
218
+ _id: false,
219
+ id: false,
220
+ minimize: false
221
+ }
222
+ },
223
+ configFields: field.fields,
224
+ parentIsLocalized: parentIsLocalized || field.localized,
225
+ payload
181
226
  })
182
227
  };
183
228
  schema.add({
184
- [field.name]: localizeSchema(field, baseSchema, payload.config.localization)
229
+ [field.name]: localizeSchema(field, baseSchema, payload.config.localization, parentIsLocalized)
185
230
  });
186
231
  },
187
- json: (field, schema, payload, buildSchemaOptions)=>{
232
+ json: (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
188
233
  const baseSchema = {
189
- ...formatBaseSchema(field, buildSchemaOptions),
234
+ ...formatBaseSchema({
235
+ buildSchemaOptions,
236
+ field,
237
+ parentIsLocalized
238
+ }),
190
239
  type: mongoose.Schema.Types.Mixed
191
240
  };
192
241
  schema.add({
193
- [field.name]: localizeSchema(field, baseSchema, payload.config.localization)
242
+ [field.name]: localizeSchema(field, baseSchema, payload.config.localization, parentIsLocalized)
194
243
  });
195
244
  },
196
- number: (field, schema, payload, buildSchemaOptions)=>{
245
+ number: (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
197
246
  const baseSchema = {
198
- ...formatBaseSchema(field, buildSchemaOptions),
247
+ ...formatBaseSchema({
248
+ buildSchemaOptions,
249
+ field,
250
+ parentIsLocalized
251
+ }),
199
252
  type: field.hasMany ? [
200
253
  Number
201
254
  ] : Number
202
255
  };
203
256
  schema.add({
204
- [field.name]: localizeSchema(field, baseSchema, payload.config.localization)
257
+ [field.name]: localizeSchema(field, baseSchema, payload.config.localization, parentIsLocalized)
205
258
  });
206
259
  },
207
- point: (field, schema, payload, buildSchemaOptions)=>{
260
+ point: (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
208
261
  const baseSchema = {
209
262
  type: {
210
263
  type: String,
@@ -223,11 +276,14 @@ const fieldToSchemaMap = {
223
276
  required: false
224
277
  }
225
278
  };
226
- if (buildSchemaOptions.disableUnique && field.unique && field.localized) {
279
+ if (buildSchemaOptions.disableUnique && field.unique && fieldShouldBeLocalized({
280
+ field,
281
+ parentIsLocalized
282
+ })) {
227
283
  baseSchema.coordinates.sparse = true;
228
284
  }
229
285
  schema.add({
230
- [field.name]: localizeSchema(field, baseSchema, payload.config.localization)
286
+ [field.name]: localizeSchema(field, baseSchema, payload.config.localization, parentIsLocalized)
231
287
  });
232
288
  if (field.index === true || field.index === undefined) {
233
289
  const indexOptions = {};
@@ -235,7 +291,10 @@ const fieldToSchemaMap = {
235
291
  indexOptions.sparse = true;
236
292
  indexOptions.unique = true;
237
293
  }
238
- if (field.localized && payload.config.localization) {
294
+ if (fieldShouldBeLocalized({
295
+ field,
296
+ parentIsLocalized
297
+ }) && payload.config.localization) {
239
298
  payload.config.localization.locales.forEach((locale)=>{
240
299
  schema.index({
241
300
  [`${field.name}.${locale.code}`]: '2dsphere'
@@ -248,9 +307,13 @@ const fieldToSchemaMap = {
248
307
  }
249
308
  }
250
309
  },
251
- radio: (field, schema, payload, buildSchemaOptions)=>{
310
+ radio: (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
252
311
  const baseSchema = {
253
- ...formatBaseSchema(field, buildSchemaOptions),
312
+ ...formatBaseSchema({
313
+ buildSchemaOptions,
314
+ field,
315
+ parentIsLocalized
316
+ }),
254
317
  type: String,
255
318
  enum: field.options.map((option)=>{
256
319
  if (typeof option === 'object') {
@@ -260,20 +323,27 @@ const fieldToSchemaMap = {
260
323
  })
261
324
  };
262
325
  schema.add({
263
- [field.name]: localizeSchema(field, baseSchema, payload.config.localization)
326
+ [field.name]: localizeSchema(field, baseSchema, payload.config.localization, parentIsLocalized)
264
327
  });
265
328
  },
266
- relationship: (field, schema, payload, buildSchemaOptions)=>{
329
+ relationship: (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
267
330
  const hasManyRelations = Array.isArray(field.relationTo);
268
331
  let schemaToReturn = {};
269
332
  const valueType = getRelationshipValueType(field, payload);
270
- if (field.localized && payload.config.localization) {
333
+ if (fieldShouldBeLocalized({
334
+ field,
335
+ parentIsLocalized
336
+ }) && payload.config.localization) {
271
337
  schemaToReturn = {
272
338
  type: payload.config.localization.localeCodes.reduce((locales, locale)=>{
273
339
  let localeSchema = {};
274
340
  if (hasManyRelations) {
275
341
  localeSchema = {
276
- ...formatBaseSchema(field, buildSchemaOptions),
342
+ ...formatBaseSchema({
343
+ buildSchemaOptions,
344
+ field,
345
+ parentIsLocalized
346
+ }),
277
347
  _id: false,
278
348
  type: mongoose.Schema.Types.Mixed,
279
349
  relationTo: {
@@ -287,7 +357,11 @@ const fieldToSchemaMap = {
287
357
  };
288
358
  } else {
289
359
  localeSchema = {
290
- ...formatBaseSchema(field, buildSchemaOptions),
360
+ ...formatBaseSchema({
361
+ buildSchemaOptions,
362
+ field,
363
+ parentIsLocalized
364
+ }),
291
365
  type: valueType,
292
366
  ref: field.relationTo
293
367
  };
@@ -306,7 +380,11 @@ const fieldToSchemaMap = {
306
380
  };
307
381
  } else if (hasManyRelations) {
308
382
  schemaToReturn = {
309
- ...formatBaseSchema(field, buildSchemaOptions),
383
+ ...formatBaseSchema({
384
+ buildSchemaOptions,
385
+ field,
386
+ parentIsLocalized
387
+ }),
310
388
  _id: false,
311
389
  type: mongoose.Schema.Types.Mixed,
312
390
  relationTo: {
@@ -328,7 +406,11 @@ const fieldToSchemaMap = {
328
406
  }
329
407
  } else {
330
408
  schemaToReturn = {
331
- ...formatBaseSchema(field, buildSchemaOptions),
409
+ ...formatBaseSchema({
410
+ buildSchemaOptions,
411
+ field,
412
+ parentIsLocalized
413
+ }),
332
414
  type: valueType,
333
415
  ref: field.relationTo
334
416
  };
@@ -345,29 +427,37 @@ const fieldToSchemaMap = {
345
427
  [field.name]: schemaToReturn
346
428
  });
347
429
  },
348
- richText: (field, schema, payload, buildSchemaOptions)=>{
430
+ richText: (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
349
431
  const baseSchema = {
350
- ...formatBaseSchema(field, buildSchemaOptions),
432
+ ...formatBaseSchema({
433
+ buildSchemaOptions,
434
+ field,
435
+ parentIsLocalized
436
+ }),
351
437
  type: mongoose.Schema.Types.Mixed
352
438
  };
353
439
  schema.add({
354
- [field.name]: localizeSchema(field, baseSchema, payload.config.localization)
440
+ [field.name]: localizeSchema(field, baseSchema, payload.config.localization, parentIsLocalized)
355
441
  });
356
442
  },
357
- row: (field, schema, payload, buildSchemaOptions)=>{
443
+ row: (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
358
444
  field.fields.forEach((subField)=>{
359
445
  if (fieldIsVirtual(subField)) {
360
446
  return;
361
447
  }
362
448
  const addFieldSchema = fieldToSchemaMap[subField.type];
363
449
  if (addFieldSchema) {
364
- addFieldSchema(subField, schema, payload, buildSchemaOptions);
450
+ addFieldSchema(subField, schema, payload, buildSchemaOptions, parentIsLocalized);
365
451
  }
366
452
  });
367
453
  },
368
- select: (field, schema, payload, buildSchemaOptions)=>{
454
+ select: (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
369
455
  const baseSchema = {
370
- ...formatBaseSchema(field, buildSchemaOptions),
456
+ ...formatBaseSchema({
457
+ buildSchemaOptions,
458
+ field,
459
+ parentIsLocalized
460
+ }),
371
461
  type: String,
372
462
  enum: field.options.map((option)=>{
373
463
  if (typeof option === 'object') {
@@ -382,28 +472,33 @@ const fieldToSchemaMap = {
382
472
  schema.add({
383
473
  [field.name]: localizeSchema(field, field.hasMany ? [
384
474
  baseSchema
385
- ] : baseSchema, payload.config.localization)
475
+ ] : baseSchema, payload.config.localization, parentIsLocalized)
386
476
  });
387
477
  },
388
- tabs: (field, schema, payload, buildSchemaOptions)=>{
478
+ tabs: (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
389
479
  field.tabs.forEach((tab)=>{
390
480
  if (tabHasName(tab)) {
391
481
  if (fieldIsVirtual(tab)) {
392
482
  return;
393
483
  }
394
484
  const baseSchema = {
395
- type: buildSchema(payload, tab.fields, {
396
- disableUnique: buildSchemaOptions.disableUnique,
397
- draftsEnabled: buildSchemaOptions.draftsEnabled,
398
- options: {
399
- _id: false,
400
- id: false,
401
- minimize: false
402
- }
485
+ type: buildSchema({
486
+ buildSchemaOptions: {
487
+ disableUnique: buildSchemaOptions.disableUnique,
488
+ draftsEnabled: buildSchemaOptions.draftsEnabled,
489
+ options: {
490
+ _id: false,
491
+ id: false,
492
+ minimize: false
493
+ }
494
+ },
495
+ configFields: tab.fields,
496
+ parentIsLocalized: parentIsLocalized || tab.localized,
497
+ payload
403
498
  })
404
499
  };
405
500
  schema.add({
406
- [tab.name]: localizeSchema(tab, baseSchema, payload.config.localization)
501
+ [tab.name]: localizeSchema(tab, baseSchema, payload.config.localization, parentIsLocalized)
407
502
  });
408
503
  } else {
409
504
  tab.fields.forEach((subField)=>{
@@ -412,43 +507,58 @@ const fieldToSchemaMap = {
412
507
  }
413
508
  const addFieldSchema = fieldToSchemaMap[subField.type];
414
509
  if (addFieldSchema) {
415
- addFieldSchema(subField, schema, payload, buildSchemaOptions);
510
+ addFieldSchema(subField, schema, payload, buildSchemaOptions, parentIsLocalized || tab.localized);
416
511
  }
417
512
  });
418
513
  }
419
514
  });
420
515
  },
421
- text: (field, schema, payload, buildSchemaOptions)=>{
516
+ text: (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
422
517
  const baseSchema = {
423
- ...formatBaseSchema(field, buildSchemaOptions),
518
+ ...formatBaseSchema({
519
+ buildSchemaOptions,
520
+ field,
521
+ parentIsLocalized
522
+ }),
424
523
  type: field.hasMany ? [
425
524
  String
426
525
  ] : String
427
526
  };
428
527
  schema.add({
429
- [field.name]: localizeSchema(field, baseSchema, payload.config.localization)
528
+ [field.name]: localizeSchema(field, baseSchema, payload.config.localization, parentIsLocalized)
430
529
  });
431
530
  },
432
- textarea: (field, schema, payload, buildSchemaOptions)=>{
531
+ textarea: (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
433
532
  const baseSchema = {
434
- ...formatBaseSchema(field, buildSchemaOptions),
533
+ ...formatBaseSchema({
534
+ buildSchemaOptions,
535
+ field,
536
+ parentIsLocalized
537
+ }),
435
538
  type: String
436
539
  };
437
540
  schema.add({
438
- [field.name]: localizeSchema(field, baseSchema, payload.config.localization)
541
+ [field.name]: localizeSchema(field, baseSchema, payload.config.localization, parentIsLocalized)
439
542
  });
440
543
  },
441
- upload: (field, schema, payload, buildSchemaOptions)=>{
544
+ upload: (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
442
545
  const hasManyRelations = Array.isArray(field.relationTo);
443
546
  let schemaToReturn = {};
444
547
  const valueType = getRelationshipValueType(field, payload);
445
- if (field.localized && payload.config.localization) {
548
+ if (fieldShouldBeLocalized({
549
+ field,
550
+ parentIsLocalized
551
+ }) && payload.config.localization) {
446
552
  schemaToReturn = {
447
553
  type: payload.config.localization.localeCodes.reduce((locales, locale)=>{
448
554
  let localeSchema = {};
449
555
  if (hasManyRelations) {
450
556
  localeSchema = {
451
- ...formatBaseSchema(field, buildSchemaOptions),
557
+ ...formatBaseSchema({
558
+ buildSchemaOptions,
559
+ field,
560
+ parentIsLocalized
561
+ }),
452
562
  _id: false,
453
563
  type: mongoose.Schema.Types.Mixed,
454
564
  relationTo: {
@@ -462,7 +572,11 @@ const fieldToSchemaMap = {
462
572
  };
463
573
  } else {
464
574
  localeSchema = {
465
- ...formatBaseSchema(field, buildSchemaOptions),
575
+ ...formatBaseSchema({
576
+ buildSchemaOptions,
577
+ field,
578
+ parentIsLocalized
579
+ }),
466
580
  type: valueType,
467
581
  ref: field.relationTo
468
582
  };
@@ -481,7 +595,11 @@ const fieldToSchemaMap = {
481
595
  };
482
596
  } else if (hasManyRelations) {
483
597
  schemaToReturn = {
484
- ...formatBaseSchema(field, buildSchemaOptions),
598
+ ...formatBaseSchema({
599
+ buildSchemaOptions,
600
+ field,
601
+ parentIsLocalized
602
+ }),
485
603
  _id: false,
486
604
  type: mongoose.Schema.Types.Mixed,
487
605
  relationTo: {
@@ -503,7 +621,11 @@ const fieldToSchemaMap = {
503
621
  }
504
622
  } else {
505
623
  schemaToReturn = {
506
- ...formatBaseSchema(field, buildSchemaOptions),
624
+ ...formatBaseSchema({
625
+ buildSchemaOptions,
626
+ field,
627
+ parentIsLocalized
628
+ }),
507
629
  type: valueType,
508
630
  ref: field.relationTo
509
631
  };