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