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