@payloadcms/db-mongodb 3.24.0-canary.f229d8d → 3.25.0-canary.36940b2
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/create.js +15 -15
- package/dist/create.js.map +1 -1
- package/dist/createGlobal.d.ts.map +1 -1
- package/dist/createGlobal.js +15 -14
- package/dist/createGlobal.js.map +1 -1
- package/dist/createGlobalVersion.d.ts.map +1 -1
- package/dist/createGlobalVersion.js +26 -23
- package/dist/createGlobalVersion.js.map +1 -1
- package/dist/createVersion.d.ts.map +1 -1
- package/dist/createVersion.js +26 -31
- package/dist/createVersion.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 +17 -9
- 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 +13 -11
- package/dist/find.js.map +1 -1
- package/dist/findGlobal.d.ts.map +1 -1
- package/dist/findGlobal.js +15 -11
- package/dist/findGlobal.js.map +1 -1
- package/dist/findGlobalVersions.d.ts.map +1 -1
- package/dist/findGlobalVersions.js +14 -13
- package/dist/findGlobalVersions.js.map +1 -1
- package/dist/findOne.d.ts.map +1 -1
- package/dist/findOne.js +13 -8
- package/dist/findOne.js.map +1 -1
- package/dist/findVersions.d.ts.map +1 -1
- package/dist/findVersions.js +14 -12
- 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 -10
- 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 +222 -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 +17 -8
- 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 +20 -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 +19 -16
- 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 +15 -12
- package/dist/updateGlobal.js.map +1 -1
- package/dist/updateGlobalVersion.d.ts.map +1 -1
- package/dist/updateGlobalVersion.js +21 -15
- package/dist/updateGlobalVersion.js.map +1 -1
- package/dist/updateOne.js +20 -11
- package/dist/updateOne.js.map +1 -1
- package/dist/updateVersion.d.ts.map +1 -1
- package/dist/updateVersion.js +21 -15
- 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/transform.d.ts +27 -0
- package/dist/utilities/transform.d.ts.map +1 -0
- package/dist/utilities/transform.js +224 -0
- package/dist/utilities/transform.js.map +1 -0
- package/dist/utilities/{sanitizeRelationshipIDs.spec.js → transform.spec.js} +55 -5
- package/dist/utilities/transform.spec.js.map +1 -0
- package/package.json +3 -3
- package/dist/utilities/sanitizeInternalFields.d.ts +0 -2
- package/dist/utilities/sanitizeInternalFields.d.ts.map +0 -1
- package/dist/utilities/sanitizeInternalFields.js +0 -20
- package/dist/utilities/sanitizeInternalFields.js.map +0 -1
- package/dist/utilities/sanitizeRelationshipIDs.d.ts +0 -9
- package/dist/utilities/sanitizeRelationshipIDs.d.ts.map +0 -1
- package/dist/utilities/sanitizeRelationshipIDs.js +0 -126
- package/dist/utilities/sanitizeRelationshipIDs.js.map +0 -1
- package/dist/utilities/sanitizeRelationshipIDs.spec.js.map +0 -1
|
@@ -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,28 @@ 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 = {
|
|
338
|
+
_id: false,
|
|
273
339
|
type: payload.config.localization.localeCodes.reduce((locales, locale)=>{
|
|
274
340
|
let localeSchema = {};
|
|
275
341
|
if (hasManyRelations) {
|
|
276
342
|
localeSchema = {
|
|
277
|
-
...formatBaseSchema(
|
|
343
|
+
...formatBaseSchema({
|
|
344
|
+
buildSchemaOptions,
|
|
345
|
+
field,
|
|
346
|
+
parentIsLocalized
|
|
347
|
+
}),
|
|
278
348
|
_id: false,
|
|
279
349
|
type: mongoose.Schema.Types.Mixed,
|
|
280
350
|
relationTo: {
|
|
@@ -288,7 +358,11 @@ const fieldToSchemaMap = {
|
|
|
288
358
|
};
|
|
289
359
|
} else {
|
|
290
360
|
localeSchema = {
|
|
291
|
-
...formatBaseSchema(
|
|
361
|
+
...formatBaseSchema({
|
|
362
|
+
buildSchemaOptions,
|
|
363
|
+
field,
|
|
364
|
+
parentIsLocalized
|
|
365
|
+
}),
|
|
292
366
|
type: valueType,
|
|
293
367
|
ref: field.relationTo
|
|
294
368
|
};
|
|
@@ -307,7 +381,11 @@ const fieldToSchemaMap = {
|
|
|
307
381
|
};
|
|
308
382
|
} else if (hasManyRelations) {
|
|
309
383
|
schemaToReturn = {
|
|
310
|
-
...formatBaseSchema(
|
|
384
|
+
...formatBaseSchema({
|
|
385
|
+
buildSchemaOptions,
|
|
386
|
+
field,
|
|
387
|
+
parentIsLocalized
|
|
388
|
+
}),
|
|
311
389
|
_id: false,
|
|
312
390
|
type: mongoose.Schema.Types.Mixed,
|
|
313
391
|
relationTo: {
|
|
@@ -329,7 +407,11 @@ const fieldToSchemaMap = {
|
|
|
329
407
|
}
|
|
330
408
|
} else {
|
|
331
409
|
schemaToReturn = {
|
|
332
|
-
...formatBaseSchema(
|
|
410
|
+
...formatBaseSchema({
|
|
411
|
+
buildSchemaOptions,
|
|
412
|
+
field,
|
|
413
|
+
parentIsLocalized
|
|
414
|
+
}),
|
|
333
415
|
type: valueType,
|
|
334
416
|
ref: field.relationTo
|
|
335
417
|
};
|
|
@@ -346,29 +428,37 @@ const fieldToSchemaMap = {
|
|
|
346
428
|
[field.name]: schemaToReturn
|
|
347
429
|
});
|
|
348
430
|
},
|
|
349
|
-
richText: (field, schema, payload, buildSchemaOptions)=>{
|
|
431
|
+
richText: (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
|
|
350
432
|
const baseSchema = {
|
|
351
|
-
...formatBaseSchema(
|
|
433
|
+
...formatBaseSchema({
|
|
434
|
+
buildSchemaOptions,
|
|
435
|
+
field,
|
|
436
|
+
parentIsLocalized
|
|
437
|
+
}),
|
|
352
438
|
type: mongoose.Schema.Types.Mixed
|
|
353
439
|
};
|
|
354
440
|
schema.add({
|
|
355
|
-
[field.name]: localizeSchema(field, baseSchema, payload.config.localization)
|
|
441
|
+
[field.name]: localizeSchema(field, baseSchema, payload.config.localization, parentIsLocalized)
|
|
356
442
|
});
|
|
357
443
|
},
|
|
358
|
-
row: (field, schema, payload, buildSchemaOptions)=>{
|
|
444
|
+
row: (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
|
|
359
445
|
field.fields.forEach((subField)=>{
|
|
360
446
|
if (fieldIsVirtual(subField)) {
|
|
361
447
|
return;
|
|
362
448
|
}
|
|
363
449
|
const addFieldSchema = fieldToSchemaMap[subField.type];
|
|
364
450
|
if (addFieldSchema) {
|
|
365
|
-
addFieldSchema(subField, schema, payload, buildSchemaOptions);
|
|
451
|
+
addFieldSchema(subField, schema, payload, buildSchemaOptions, parentIsLocalized);
|
|
366
452
|
}
|
|
367
453
|
});
|
|
368
454
|
},
|
|
369
|
-
select: (field, schema, payload, buildSchemaOptions)=>{
|
|
455
|
+
select: (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
|
|
370
456
|
const baseSchema = {
|
|
371
|
-
...formatBaseSchema(
|
|
457
|
+
...formatBaseSchema({
|
|
458
|
+
buildSchemaOptions,
|
|
459
|
+
field,
|
|
460
|
+
parentIsLocalized
|
|
461
|
+
}),
|
|
372
462
|
type: String,
|
|
373
463
|
enum: field.options.map((option)=>{
|
|
374
464
|
if (typeof option === 'object') {
|
|
@@ -383,28 +473,33 @@ const fieldToSchemaMap = {
|
|
|
383
473
|
schema.add({
|
|
384
474
|
[field.name]: localizeSchema(field, field.hasMany ? [
|
|
385
475
|
baseSchema
|
|
386
|
-
] : baseSchema, payload.config.localization)
|
|
476
|
+
] : baseSchema, payload.config.localization, parentIsLocalized)
|
|
387
477
|
});
|
|
388
478
|
},
|
|
389
|
-
tabs: (field, schema, payload, buildSchemaOptions)=>{
|
|
479
|
+
tabs: (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
|
|
390
480
|
field.tabs.forEach((tab)=>{
|
|
391
481
|
if (tabHasName(tab)) {
|
|
392
482
|
if (fieldIsVirtual(tab)) {
|
|
393
483
|
return;
|
|
394
484
|
}
|
|
395
485
|
const baseSchema = {
|
|
396
|
-
type: buildSchema(
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
486
|
+
type: buildSchema({
|
|
487
|
+
buildSchemaOptions: {
|
|
488
|
+
disableUnique: buildSchemaOptions.disableUnique,
|
|
489
|
+
draftsEnabled: buildSchemaOptions.draftsEnabled,
|
|
490
|
+
options: {
|
|
491
|
+
_id: false,
|
|
492
|
+
id: false,
|
|
493
|
+
minimize: false
|
|
494
|
+
}
|
|
495
|
+
},
|
|
496
|
+
configFields: tab.fields,
|
|
497
|
+
parentIsLocalized: parentIsLocalized || tab.localized,
|
|
498
|
+
payload
|
|
404
499
|
})
|
|
405
500
|
};
|
|
406
501
|
schema.add({
|
|
407
|
-
[tab.name]: localizeSchema(tab, baseSchema, payload.config.localization)
|
|
502
|
+
[tab.name]: localizeSchema(tab, baseSchema, payload.config.localization, parentIsLocalized)
|
|
408
503
|
});
|
|
409
504
|
} else {
|
|
410
505
|
tab.fields.forEach((subField)=>{
|
|
@@ -413,43 +508,59 @@ const fieldToSchemaMap = {
|
|
|
413
508
|
}
|
|
414
509
|
const addFieldSchema = fieldToSchemaMap[subField.type];
|
|
415
510
|
if (addFieldSchema) {
|
|
416
|
-
addFieldSchema(subField, schema, payload, buildSchemaOptions);
|
|
511
|
+
addFieldSchema(subField, schema, payload, buildSchemaOptions, parentIsLocalized || tab.localized);
|
|
417
512
|
}
|
|
418
513
|
});
|
|
419
514
|
}
|
|
420
515
|
});
|
|
421
516
|
},
|
|
422
|
-
text: (field, schema, payload, buildSchemaOptions)=>{
|
|
517
|
+
text: (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
|
|
423
518
|
const baseSchema = {
|
|
424
|
-
...formatBaseSchema(
|
|
519
|
+
...formatBaseSchema({
|
|
520
|
+
buildSchemaOptions,
|
|
521
|
+
field,
|
|
522
|
+
parentIsLocalized
|
|
523
|
+
}),
|
|
425
524
|
type: field.hasMany ? [
|
|
426
525
|
String
|
|
427
526
|
] : String
|
|
428
527
|
};
|
|
429
528
|
schema.add({
|
|
430
|
-
[field.name]: localizeSchema(field, baseSchema, payload.config.localization)
|
|
529
|
+
[field.name]: localizeSchema(field, baseSchema, payload.config.localization, parentIsLocalized)
|
|
431
530
|
});
|
|
432
531
|
},
|
|
433
|
-
textarea: (field, schema, payload, buildSchemaOptions)=>{
|
|
532
|
+
textarea: (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
|
|
434
533
|
const baseSchema = {
|
|
435
|
-
...formatBaseSchema(
|
|
534
|
+
...formatBaseSchema({
|
|
535
|
+
buildSchemaOptions,
|
|
536
|
+
field,
|
|
537
|
+
parentIsLocalized
|
|
538
|
+
}),
|
|
436
539
|
type: String
|
|
437
540
|
};
|
|
438
541
|
schema.add({
|
|
439
|
-
[field.name]: localizeSchema(field, baseSchema, payload.config.localization)
|
|
542
|
+
[field.name]: localizeSchema(field, baseSchema, payload.config.localization, parentIsLocalized)
|
|
440
543
|
});
|
|
441
544
|
},
|
|
442
|
-
upload: (field, schema, payload, buildSchemaOptions)=>{
|
|
545
|
+
upload: (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
|
|
443
546
|
const hasManyRelations = Array.isArray(field.relationTo);
|
|
444
547
|
let schemaToReturn = {};
|
|
445
548
|
const valueType = getRelationshipValueType(field, payload);
|
|
446
|
-
if (
|
|
549
|
+
if (fieldShouldBeLocalized({
|
|
550
|
+
field,
|
|
551
|
+
parentIsLocalized
|
|
552
|
+
}) && payload.config.localization) {
|
|
447
553
|
schemaToReturn = {
|
|
554
|
+
_id: false,
|
|
448
555
|
type: payload.config.localization.localeCodes.reduce((locales, locale)=>{
|
|
449
556
|
let localeSchema = {};
|
|
450
557
|
if (hasManyRelations) {
|
|
451
558
|
localeSchema = {
|
|
452
|
-
...formatBaseSchema(
|
|
559
|
+
...formatBaseSchema({
|
|
560
|
+
buildSchemaOptions,
|
|
561
|
+
field,
|
|
562
|
+
parentIsLocalized
|
|
563
|
+
}),
|
|
453
564
|
_id: false,
|
|
454
565
|
type: mongoose.Schema.Types.Mixed,
|
|
455
566
|
relationTo: {
|
|
@@ -463,7 +574,11 @@ const fieldToSchemaMap = {
|
|
|
463
574
|
};
|
|
464
575
|
} else {
|
|
465
576
|
localeSchema = {
|
|
466
|
-
...formatBaseSchema(
|
|
577
|
+
...formatBaseSchema({
|
|
578
|
+
buildSchemaOptions,
|
|
579
|
+
field,
|
|
580
|
+
parentIsLocalized
|
|
581
|
+
}),
|
|
467
582
|
type: valueType,
|
|
468
583
|
ref: field.relationTo
|
|
469
584
|
};
|
|
@@ -482,7 +597,11 @@ const fieldToSchemaMap = {
|
|
|
482
597
|
};
|
|
483
598
|
} else if (hasManyRelations) {
|
|
484
599
|
schemaToReturn = {
|
|
485
|
-
...formatBaseSchema(
|
|
600
|
+
...formatBaseSchema({
|
|
601
|
+
buildSchemaOptions,
|
|
602
|
+
field,
|
|
603
|
+
parentIsLocalized
|
|
604
|
+
}),
|
|
486
605
|
_id: false,
|
|
487
606
|
type: mongoose.Schema.Types.Mixed,
|
|
488
607
|
relationTo: {
|
|
@@ -504,7 +623,11 @@ const fieldToSchemaMap = {
|
|
|
504
623
|
}
|
|
505
624
|
} else {
|
|
506
625
|
schemaToReturn = {
|
|
507
|
-
...formatBaseSchema(
|
|
626
|
+
...formatBaseSchema({
|
|
627
|
+
buildSchemaOptions,
|
|
628
|
+
field,
|
|
629
|
+
parentIsLocalized
|
|
630
|
+
}),
|
|
508
631
|
type: valueType,
|
|
509
632
|
ref: field.relationTo
|
|
510
633
|
};
|