@payloadcms/db-mongodb 3.24.0-canary.72057b1 → 3.24.0-canary.a62d86f
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 +225 -103
- package/dist/models/buildSchema.js.map +1 -1
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts.map +1 -1
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js +9 -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 +14 -4
- 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 +14 -5
- 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 +20 -18
- 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 +8 -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,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.
|
|
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 (
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
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(
|
|
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(
|
|
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 &&
|
|
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 (
|
|
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(
|
|
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 (
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
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(
|
|
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(
|
|
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 (
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
624
|
+
...formatBaseSchema({
|
|
625
|
+
buildSchemaOptions,
|
|
626
|
+
field,
|
|
627
|
+
parentIsLocalized
|
|
628
|
+
}),
|
|
507
629
|
type: valueType,
|
|
508
630
|
ref: field.relationTo
|
|
509
631
|
};
|