@payloadcms/db-mongodb 3.26.0-canary.bbb3083 → 3.26.0
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/connect.d.ts.map +1 -1
- package/dist/connect.js +5 -1
- package/dist/connect.js.map +1 -1
- package/dist/count.d.ts.map +1 -1
- package/dist/count.js +8 -4
- package/dist/count.js.map +1 -1
- package/dist/countGlobalVersions.d.ts.map +1 -1
- package/dist/countGlobalVersions.js +8 -3
- package/dist/countGlobalVersions.js.map +1 -1
- package/dist/countVersions.d.ts.map +1 -1
- package/dist/countVersions.js +8 -3
- package/dist/countVersions.js.map +1 -1
- package/dist/create.d.ts.map +1 -1
- package/dist/create.js +13 -6
- package/dist/create.js.map +1 -1
- package/dist/createGlobal.d.ts +1 -1
- package/dist/createGlobal.d.ts.map +1 -1
- package/dist/createGlobal.js +12 -5
- package/dist/createGlobal.js.map +1 -1
- package/dist/createGlobalVersion.d.ts.map +1 -1
- package/dist/createGlobalVersion.js +13 -5
- package/dist/createGlobalVersion.js.map +1 -1
- package/dist/createMigration.d.ts.map +1 -1
- package/dist/createMigration.js.map +1 -1
- package/dist/createVersion.d.ts.map +1 -1
- package/dist/createVersion.js +13 -5
- package/dist/createVersion.js.map +1 -1
- package/dist/deleteMany.d.ts +1 -1
- package/dist/deleteMany.d.ts.map +1 -1
- package/dist/deleteMany.js +8 -4
- package/dist/deleteMany.js.map +1 -1
- package/dist/deleteOne.d.ts.map +1 -1
- package/dist/deleteOne.js +14 -6
- package/dist/deleteOne.js.map +1 -1
- package/dist/deleteVersions.d.ts.map +1 -1
- package/dist/deleteVersions.js +9 -4
- package/dist/deleteVersions.js.map +1 -1
- package/dist/find.d.ts.map +1 -1
- package/dist/find.js +25 -8
- package/dist/find.js.map +1 -1
- package/dist/findGlobal.d.ts.map +1 -1
- package/dist/findGlobal.js +8 -5
- package/dist/findGlobal.js.map +1 -1
- package/dist/findGlobalVersions.d.ts.map +1 -1
- package/dist/findGlobalVersions.js +8 -4
- package/dist/findGlobalVersions.js.map +1 -1
- package/dist/findOne.d.ts +1 -1
- package/dist/findOne.d.ts.map +1 -1
- package/dist/findOne.js +18 -8
- package/dist/findOne.js.map +1 -1
- package/dist/findVersions.d.ts.map +1 -1
- package/dist/findVersions.js +8 -4
- package/dist/findVersions.js.map +1 -1
- package/dist/index.d.ts +6 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +1 -5
- package/dist/init.js.map +1 -1
- package/dist/migrateFresh.d.ts.map +1 -1
- package/dist/migrateFresh.js.map +1 -1
- package/dist/models/buildCollectionSchema.d.ts.map +1 -1
- package/dist/models/buildCollectionSchema.js +0 -4
- package/dist/models/buildCollectionSchema.js.map +1 -1
- package/dist/models/buildSchema.d.ts.map +1 -1
- package/dist/models/buildSchema.js +545 -515
- package/dist/models/buildSchema.js.map +1 -1
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts.map +1 -1
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js +21 -8
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js.map +1 -1
- package/dist/predefinedMigrations/migrateVersionsV1_V2.d.ts.map +1 -1
- package/dist/predefinedMigrations/migrateVersionsV1_V2.js +20 -8
- package/dist/predefinedMigrations/migrateVersionsV1_V2.js.map +1 -1
- package/dist/queries/buildSearchParams.d.ts +1 -1
- package/dist/queries/buildSearchParams.d.ts.map +1 -1
- package/dist/queries/buildSearchParams.js +42 -29
- package/dist/queries/buildSearchParams.js.map +1 -1
- package/dist/queries/buildSortParam.d.ts +2 -3
- package/dist/queries/buildSortParam.d.ts.map +1 -1
- package/dist/queries/buildSortParam.js +1 -1
- package/dist/queries/buildSortParam.js.map +1 -1
- package/dist/queries/getBuildQueryPlugin.d.ts.map +1 -1
- package/dist/queries/getBuildQueryPlugin.js +15 -8
- package/dist/queries/getBuildQueryPlugin.js.map +1 -1
- package/dist/queries/getLocalizedSortProperty.d.ts +1 -1
- package/dist/queries/getLocalizedSortProperty.d.ts.map +1 -1
- package/dist/queries/getLocalizedSortProperty.js +11 -6
- package/dist/queries/getLocalizedSortProperty.js.map +1 -1
- package/dist/queries/getLocalizedSortProperty.spec.js +8 -0
- package/dist/queries/getLocalizedSortProperty.spec.js.map +1 -1
- package/dist/queries/operatorMap.d.ts +1 -0
- package/dist/queries/operatorMap.d.ts.map +1 -1
- package/dist/queries/operatorMap.js.map +1 -1
- package/dist/queries/parseParams.d.ts +1 -1
- package/dist/queries/parseParams.d.ts.map +1 -1
- package/dist/queries/parseParams.js +3 -3
- package/dist/queries/parseParams.js.map +1 -1
- package/dist/queries/sanitizeQueryValue.d.ts +1 -1
- package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
- package/dist/queries/sanitizeQueryValue.js +30 -26
- package/dist/queries/sanitizeQueryValue.js.map +1 -1
- package/dist/queryDrafts.d.ts.map +1 -1
- package/dist/queryDrafts.js +26 -8
- package/dist/queryDrafts.js.map +1 -1
- package/dist/transactions/beginTransaction.d.ts.map +1 -1
- package/dist/transactions/beginTransaction.js +4 -2
- package/dist/transactions/beginTransaction.js.map +1 -1
- package/dist/transactions/commitTransaction.d.ts.map +1 -1
- package/dist/transactions/commitTransaction.js +1 -1
- package/dist/transactions/commitTransaction.js.map +1 -1
- package/dist/transactions/rollbackTransaction.d.ts.map +1 -1
- package/dist/transactions/rollbackTransaction.js +3 -3
- package/dist/transactions/rollbackTransaction.js.map +1 -1
- package/dist/types.d.ts +2 -2
- 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 +17 -7
- package/dist/updateGlobal.js.map +1 -1
- package/dist/updateGlobalVersion.d.ts +1 -1
- package/dist/updateGlobalVersion.d.ts.map +1 -1
- package/dist/updateGlobalVersion.js +14 -6
- package/dist/updateGlobalVersion.js.map +1 -1
- package/dist/updateMany.d.ts +3 -0
- package/dist/updateMany.d.ts.map +1 -0
- package/dist/updateMany.js +75 -0
- package/dist/updateMany.js.map +1 -0
- package/dist/updateOne.d.ts.map +1 -1
- package/dist/updateOne.js +17 -8
- package/dist/updateOne.js.map +1 -1
- package/dist/updateVersion.d.ts.map +1 -1
- package/dist/updateVersion.js +14 -5
- package/dist/updateVersion.js.map +1 -1
- package/dist/upsert.d.ts.map +1 -1
- package/dist/upsert.js +2 -1
- package/dist/upsert.js.map +1 -1
- package/dist/utilities/aggregatePaginate.d.ts +19 -0
- package/dist/utilities/aggregatePaginate.d.ts.map +1 -0
- package/dist/utilities/aggregatePaginate.js +78 -0
- package/dist/utilities/aggregatePaginate.js.map +1 -0
- package/dist/utilities/buildJoinAggregation.d.ts +5 -6
- package/dist/utilities/buildJoinAggregation.d.ts.map +1 -1
- package/dist/utilities/buildJoinAggregation.js +39 -36
- package/dist/utilities/buildJoinAggregation.js.map +1 -1
- package/dist/utilities/buildProjectionFromSelect.d.ts.map +1 -1
- package/dist/utilities/buildProjectionFromSelect.js +8 -4
- package/dist/utilities/buildProjectionFromSelect.js.map +1 -1
- package/dist/utilities/getDBName.d.ts +1 -1
- package/dist/utilities/getDBName.d.ts.map +1 -1
- package/dist/utilities/getDBName.js +6 -2
- package/dist/utilities/getDBName.js.map +1 -1
- package/dist/utilities/getEntity.d.ts +33 -0
- package/dist/utilities/getEntity.d.ts.map +1 -0
- package/dist/utilities/getEntity.js +49 -0
- package/dist/utilities/getEntity.js.map +1 -0
- package/dist/utilities/handleError.d.ts +1 -1
- package/dist/utilities/handleError.d.ts.map +1 -1
- package/dist/utilities/handleError.js +3 -2
- package/dist/utilities/handleError.js.map +1 -1
- package/dist/utilities/transform.d.ts.map +1 -1
- package/dist/utilities/transform.js +10 -9
- package/dist/utilities/transform.js.map +1 -1
- package/package.json +5 -4
|
@@ -60,160 +60,27 @@ export const buildSchema = (args)=>{
|
|
|
60
60
|
return;
|
|
61
61
|
}
|
|
62
62
|
if (!fieldIsPresentationalOnly(field)) {
|
|
63
|
-
const addFieldSchema =
|
|
63
|
+
const addFieldSchema = getSchemaGenerator(field.type);
|
|
64
64
|
if (addFieldSchema) {
|
|
65
|
-
addFieldSchema(field, schema, payload, buildSchemaOptions, parentIsLocalized);
|
|
65
|
+
addFieldSchema(field, schema, payload, buildSchemaOptions, parentIsLocalized ?? false);
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
});
|
|
69
69
|
return schema;
|
|
70
70
|
};
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
...formatBaseSchema({
|
|
75
|
-
buildSchemaOptions,
|
|
76
|
-
field,
|
|
77
|
-
parentIsLocalized
|
|
78
|
-
}),
|
|
79
|
-
type: [
|
|
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
|
|
94
|
-
})
|
|
95
|
-
]
|
|
96
|
-
};
|
|
97
|
-
schema.add({
|
|
98
|
-
[field.name]: localizeSchema(field, baseSchema, payload.config.localization, parentIsLocalized)
|
|
99
|
-
});
|
|
100
|
-
},
|
|
101
|
-
blocks: (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
|
|
102
|
-
const fieldSchema = {
|
|
103
|
-
type: [
|
|
104
|
-
new mongoose.Schema({}, {
|
|
105
|
-
_id: false,
|
|
106
|
-
discriminatorKey: 'blockType'
|
|
107
|
-
})
|
|
108
|
-
]
|
|
109
|
-
};
|
|
110
|
-
schema.add({
|
|
111
|
-
[field.name]: localizeSchema(field, fieldSchema, payload.config.localization, parentIsLocalized)
|
|
112
|
-
});
|
|
113
|
-
(field.blockReferences ?? field.blocks).forEach((blockItem)=>{
|
|
114
|
-
const blockSchema = new mongoose.Schema({}, {
|
|
115
|
-
_id: false,
|
|
116
|
-
id: false
|
|
117
|
-
});
|
|
118
|
-
const block = typeof blockItem === 'string' ? payload.blocks[blockItem] : blockItem;
|
|
119
|
-
block.fields.forEach((blockField)=>{
|
|
120
|
-
const addFieldSchema = fieldToSchemaMap[blockField.type];
|
|
121
|
-
if (addFieldSchema) {
|
|
122
|
-
addFieldSchema(blockField, blockSchema, payload, buildSchemaOptions, parentIsLocalized || field.localized);
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
if (fieldShouldBeLocalized({
|
|
126
|
-
field,
|
|
127
|
-
parentIsLocalized
|
|
128
|
-
}) && payload.config.localization) {
|
|
129
|
-
payload.config.localization.localeCodes.forEach((localeCode)=>{
|
|
130
|
-
// @ts-expect-error Possible incorrect typing in mongoose types, this works
|
|
131
|
-
schema.path(`${field.name}.${localeCode}`).discriminator(block.slug, blockSchema);
|
|
132
|
-
});
|
|
133
|
-
} else {
|
|
134
|
-
// @ts-expect-error Possible incorrect typing in mongoose types, this works
|
|
135
|
-
schema.path(field.name).discriminator(block.slug, blockSchema);
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
},
|
|
139
|
-
checkbox: (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
|
|
140
|
-
const baseSchema = {
|
|
141
|
-
...formatBaseSchema({
|
|
142
|
-
buildSchemaOptions,
|
|
143
|
-
field,
|
|
144
|
-
parentIsLocalized
|
|
145
|
-
}),
|
|
146
|
-
type: Boolean
|
|
147
|
-
};
|
|
148
|
-
schema.add({
|
|
149
|
-
[field.name]: localizeSchema(field, baseSchema, payload.config.localization, parentIsLocalized)
|
|
150
|
-
});
|
|
151
|
-
},
|
|
152
|
-
code: (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
|
|
153
|
-
const baseSchema = {
|
|
154
|
-
...formatBaseSchema({
|
|
155
|
-
buildSchemaOptions,
|
|
156
|
-
field,
|
|
157
|
-
parentIsLocalized
|
|
158
|
-
}),
|
|
159
|
-
type: String
|
|
160
|
-
};
|
|
161
|
-
schema.add({
|
|
162
|
-
[field.name]: localizeSchema(field, baseSchema, payload.config.localization, parentIsLocalized)
|
|
163
|
-
});
|
|
164
|
-
},
|
|
165
|
-
collapsible: (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
|
|
166
|
-
field.fields.forEach((subField)=>{
|
|
167
|
-
if (fieldIsVirtual(subField)) {
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
const addFieldSchema = fieldToSchemaMap[subField.type];
|
|
171
|
-
if (addFieldSchema) {
|
|
172
|
-
addFieldSchema(subField, schema, payload, buildSchemaOptions, parentIsLocalized);
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
},
|
|
176
|
-
date: (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
|
|
177
|
-
const baseSchema = {
|
|
178
|
-
...formatBaseSchema({
|
|
179
|
-
buildSchemaOptions,
|
|
180
|
-
field,
|
|
181
|
-
parentIsLocalized
|
|
182
|
-
}),
|
|
183
|
-
type: Date
|
|
184
|
-
};
|
|
185
|
-
schema.add({
|
|
186
|
-
[field.name]: localizeSchema(field, baseSchema, payload.config.localization, parentIsLocalized)
|
|
187
|
-
});
|
|
188
|
-
},
|
|
189
|
-
email: (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
|
|
190
|
-
const baseSchema = {
|
|
191
|
-
...formatBaseSchema({
|
|
192
|
-
buildSchemaOptions,
|
|
193
|
-
field,
|
|
194
|
-
parentIsLocalized
|
|
195
|
-
}),
|
|
196
|
-
type: String
|
|
197
|
-
};
|
|
198
|
-
schema.add({
|
|
199
|
-
[field.name]: localizeSchema(field, baseSchema, payload.config.localization, parentIsLocalized)
|
|
200
|
-
});
|
|
201
|
-
},
|
|
202
|
-
group: (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
|
|
203
|
-
const formattedBaseSchema = formatBaseSchema({
|
|
71
|
+
const array = (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
|
|
72
|
+
const baseSchema = {
|
|
73
|
+
...formatBaseSchema({
|
|
204
74
|
buildSchemaOptions,
|
|
205
75
|
field,
|
|
206
76
|
parentIsLocalized
|
|
207
|
-
})
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
const baseSchema = {
|
|
211
|
-
...formattedBaseSchema,
|
|
212
|
-
type: buildSchema({
|
|
77
|
+
}),
|
|
78
|
+
type: [
|
|
79
|
+
buildSchema({
|
|
213
80
|
buildSchemaOptions: {
|
|
81
|
+
allowIDField: true,
|
|
214
82
|
disableUnique: buildSchemaOptions.disableUnique,
|
|
215
83
|
draftsEnabled: buildSchemaOptions.draftsEnabled,
|
|
216
|
-
indexSortableFields,
|
|
217
84
|
options: {
|
|
218
85
|
_id: false,
|
|
219
86
|
id: false,
|
|
@@ -224,430 +91,593 @@ const fieldToSchemaMap = {
|
|
|
224
91
|
parentIsLocalized: parentIsLocalized || field.localized,
|
|
225
92
|
payload
|
|
226
93
|
})
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
94
|
+
]
|
|
95
|
+
};
|
|
96
|
+
schema.add({
|
|
97
|
+
[field.name]: localizeSchema(field, baseSchema, payload.config.localization, parentIsLocalized)
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
const blocks = (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
|
|
101
|
+
const fieldSchema = {
|
|
102
|
+
type: [
|
|
103
|
+
new mongoose.Schema({}, {
|
|
104
|
+
_id: false,
|
|
105
|
+
discriminatorKey: 'blockType'
|
|
106
|
+
})
|
|
107
|
+
]
|
|
108
|
+
};
|
|
109
|
+
schema.add({
|
|
110
|
+
[field.name]: localizeSchema(field, fieldSchema, payload.config.localization, parentIsLocalized)
|
|
111
|
+
});
|
|
112
|
+
(field.blockReferences ?? field.blocks).forEach((blockItem)=>{
|
|
113
|
+
const blockSchema = new mongoose.Schema({}, {
|
|
114
|
+
_id: false,
|
|
115
|
+
id: false
|
|
243
116
|
});
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
Number
|
|
254
|
-
] : Number
|
|
255
|
-
};
|
|
256
|
-
schema.add({
|
|
257
|
-
[field.name]: localizeSchema(field, baseSchema, payload.config.localization, parentIsLocalized)
|
|
117
|
+
const block = typeof blockItem === 'string' ? payload.blocks[blockItem] : blockItem;
|
|
118
|
+
if (!block) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
block.fields.forEach((blockField)=>{
|
|
122
|
+
const addFieldSchema = getSchemaGenerator(blockField.type);
|
|
123
|
+
if (addFieldSchema) {
|
|
124
|
+
addFieldSchema(blockField, blockSchema, payload, buildSchemaOptions, (parentIsLocalized || field.localized) ?? false);
|
|
125
|
+
}
|
|
258
126
|
});
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
127
|
+
if (fieldShouldBeLocalized({
|
|
128
|
+
field,
|
|
129
|
+
parentIsLocalized
|
|
130
|
+
}) && payload.config.localization) {
|
|
131
|
+
payload.config.localization.localeCodes.forEach((localeCode)=>{
|
|
132
|
+
// @ts-expect-error Possible incorrect typing in mongoose types, this works
|
|
133
|
+
schema.path(`${field.name}.${localeCode}`).discriminator(block.slug, blockSchema);
|
|
134
|
+
});
|
|
135
|
+
} else {
|
|
136
|
+
// @ts-expect-error Possible incorrect typing in mongoose types, this works
|
|
137
|
+
schema.path(field.name).discriminator(block.slug, blockSchema);
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
};
|
|
141
|
+
const checkbox = (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
|
|
142
|
+
const baseSchema = {
|
|
143
|
+
...formatBaseSchema({
|
|
144
|
+
buildSchemaOptions,
|
|
145
|
+
field,
|
|
146
|
+
parentIsLocalized
|
|
147
|
+
}),
|
|
148
|
+
type: Boolean
|
|
149
|
+
};
|
|
150
|
+
schema.add({
|
|
151
|
+
[field.name]: localizeSchema(field, baseSchema, payload.config.localization, parentIsLocalized)
|
|
152
|
+
});
|
|
153
|
+
};
|
|
154
|
+
const code = (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
|
|
155
|
+
const baseSchema = {
|
|
156
|
+
...formatBaseSchema({
|
|
157
|
+
buildSchemaOptions,
|
|
158
|
+
field,
|
|
159
|
+
parentIsLocalized
|
|
160
|
+
}),
|
|
161
|
+
type: String
|
|
162
|
+
};
|
|
163
|
+
schema.add({
|
|
164
|
+
[field.name]: localizeSchema(field, baseSchema, payload.config.localization, parentIsLocalized)
|
|
165
|
+
});
|
|
166
|
+
};
|
|
167
|
+
const collapsible = (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
|
|
168
|
+
field.fields.forEach((subField)=>{
|
|
169
|
+
if (fieldIsVirtual(subField)) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
const addFieldSchema = getSchemaGenerator(subField.type);
|
|
173
|
+
if (addFieldSchema) {
|
|
174
|
+
addFieldSchema(subField, schema, payload, buildSchemaOptions, parentIsLocalized);
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
};
|
|
178
|
+
const date = (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
|
|
179
|
+
const baseSchema = {
|
|
180
|
+
...formatBaseSchema({
|
|
181
|
+
buildSchemaOptions,
|
|
182
|
+
field,
|
|
183
|
+
parentIsLocalized
|
|
184
|
+
}),
|
|
185
|
+
type: Date
|
|
186
|
+
};
|
|
187
|
+
schema.add({
|
|
188
|
+
[field.name]: localizeSchema(field, baseSchema, payload.config.localization, parentIsLocalized)
|
|
189
|
+
});
|
|
190
|
+
};
|
|
191
|
+
const email = (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
|
|
192
|
+
const baseSchema = {
|
|
193
|
+
...formatBaseSchema({
|
|
194
|
+
buildSchemaOptions,
|
|
195
|
+
field,
|
|
196
|
+
parentIsLocalized
|
|
197
|
+
}),
|
|
198
|
+
type: String
|
|
199
|
+
};
|
|
200
|
+
schema.add({
|
|
201
|
+
[field.name]: localizeSchema(field, baseSchema, payload.config.localization, parentIsLocalized)
|
|
202
|
+
});
|
|
203
|
+
};
|
|
204
|
+
const group = (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
|
|
205
|
+
const formattedBaseSchema = formatBaseSchema({
|
|
206
|
+
buildSchemaOptions,
|
|
207
|
+
field,
|
|
208
|
+
parentIsLocalized
|
|
209
|
+
});
|
|
210
|
+
// carry indexSortableFields through to versions if drafts enabled
|
|
211
|
+
const indexSortableFields = buildSchemaOptions.indexSortableFields && field.name === 'version' && buildSchemaOptions.draftsEnabled;
|
|
212
|
+
const baseSchema = {
|
|
213
|
+
...formattedBaseSchema,
|
|
214
|
+
type: buildSchema({
|
|
215
|
+
buildSchemaOptions: {
|
|
216
|
+
disableUnique: buildSchemaOptions.disableUnique,
|
|
217
|
+
draftsEnabled: buildSchemaOptions.draftsEnabled,
|
|
218
|
+
indexSortableFields,
|
|
219
|
+
options: {
|
|
220
|
+
_id: false,
|
|
221
|
+
id: false,
|
|
222
|
+
minimize: false
|
|
269
223
|
}
|
|
270
224
|
},
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
225
|
+
configFields: field.fields,
|
|
226
|
+
parentIsLocalized: parentIsLocalized || field.localized,
|
|
227
|
+
payload
|
|
228
|
+
})
|
|
229
|
+
};
|
|
230
|
+
schema.add({
|
|
231
|
+
[field.name]: localizeSchema(field, baseSchema, payload.config.localization, parentIsLocalized)
|
|
232
|
+
});
|
|
233
|
+
};
|
|
234
|
+
const json = (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
|
|
235
|
+
const baseSchema = {
|
|
236
|
+
...formatBaseSchema({
|
|
237
|
+
buildSchemaOptions,
|
|
280
238
|
field,
|
|
281
239
|
parentIsLocalized
|
|
282
|
-
})
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
240
|
+
}),
|
|
241
|
+
type: mongoose.Schema.Types.Mixed
|
|
242
|
+
};
|
|
243
|
+
schema.add({
|
|
244
|
+
[field.name]: localizeSchema(field, baseSchema, payload.config.localization, parentIsLocalized)
|
|
245
|
+
});
|
|
246
|
+
};
|
|
247
|
+
const number = (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
|
|
248
|
+
const baseSchema = {
|
|
249
|
+
...formatBaseSchema({
|
|
250
|
+
buildSchemaOptions,
|
|
251
|
+
field,
|
|
252
|
+
parentIsLocalized
|
|
253
|
+
}),
|
|
254
|
+
type: field.hasMany ? [
|
|
255
|
+
Number
|
|
256
|
+
] : Number
|
|
257
|
+
};
|
|
258
|
+
schema.add({
|
|
259
|
+
[field.name]: localizeSchema(field, baseSchema, payload.config.localization, parentIsLocalized)
|
|
260
|
+
});
|
|
261
|
+
};
|
|
262
|
+
const point = (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
|
|
263
|
+
const baseSchema = {
|
|
264
|
+
type: {
|
|
265
|
+
type: String,
|
|
266
|
+
enum: [
|
|
267
|
+
'Point'
|
|
268
|
+
],
|
|
269
|
+
...typeof field.defaultValue !== 'undefined' && {
|
|
270
|
+
default: 'Point'
|
|
307
271
|
}
|
|
272
|
+
},
|
|
273
|
+
coordinates: {
|
|
274
|
+
type: [
|
|
275
|
+
Number
|
|
276
|
+
],
|
|
277
|
+
default: formatDefaultValue(field),
|
|
278
|
+
required: false
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
if (buildSchemaOptions.disableUnique && field.unique && fieldShouldBeLocalized({
|
|
282
|
+
field,
|
|
283
|
+
parentIsLocalized
|
|
284
|
+
})) {
|
|
285
|
+
baseSchema.coordinates.sparse = true;
|
|
286
|
+
}
|
|
287
|
+
schema.add({
|
|
288
|
+
[field.name]: localizeSchema(field, baseSchema, payload.config.localization, parentIsLocalized)
|
|
289
|
+
});
|
|
290
|
+
if (field.index === true || field.index === undefined) {
|
|
291
|
+
const indexOptions = {};
|
|
292
|
+
if (!buildSchemaOptions.disableUnique && field.unique) {
|
|
293
|
+
indexOptions.sparse = true;
|
|
294
|
+
indexOptions.unique = true;
|
|
308
295
|
}
|
|
309
|
-
},
|
|
310
|
-
radio: (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
|
|
311
|
-
const baseSchema = {
|
|
312
|
-
...formatBaseSchema({
|
|
313
|
-
buildSchemaOptions,
|
|
314
|
-
field,
|
|
315
|
-
parentIsLocalized
|
|
316
|
-
}),
|
|
317
|
-
type: String,
|
|
318
|
-
enum: field.options.map((option)=>{
|
|
319
|
-
if (typeof option === 'object') {
|
|
320
|
-
return option.value;
|
|
321
|
-
}
|
|
322
|
-
return option;
|
|
323
|
-
})
|
|
324
|
-
};
|
|
325
|
-
schema.add({
|
|
326
|
-
[field.name]: localizeSchema(field, baseSchema, payload.config.localization, parentIsLocalized)
|
|
327
|
-
});
|
|
328
|
-
},
|
|
329
|
-
relationship: (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
|
|
330
|
-
const hasManyRelations = Array.isArray(field.relationTo);
|
|
331
|
-
let schemaToReturn = {};
|
|
332
|
-
const valueType = getRelationshipValueType(field, payload);
|
|
333
296
|
if (fieldShouldBeLocalized({
|
|
334
297
|
field,
|
|
335
298
|
parentIsLocalized
|
|
336
299
|
}) && payload.config.localization) {
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
300
|
+
payload.config.localization.locales.forEach((locale)=>{
|
|
301
|
+
schema.index({
|
|
302
|
+
[`${field.name}.${locale.code}`]: '2dsphere'
|
|
303
|
+
}, indexOptions);
|
|
304
|
+
});
|
|
305
|
+
} else {
|
|
306
|
+
schema.index({
|
|
307
|
+
[field.name]: '2dsphere'
|
|
308
|
+
}, indexOptions);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
const radio = (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
|
|
313
|
+
const baseSchema = {
|
|
314
|
+
...formatBaseSchema({
|
|
315
|
+
buildSchemaOptions,
|
|
316
|
+
field,
|
|
317
|
+
parentIsLocalized
|
|
318
|
+
}),
|
|
319
|
+
type: String,
|
|
320
|
+
enum: field.options.map((option)=>{
|
|
321
|
+
if (typeof option === 'object') {
|
|
322
|
+
return option.value;
|
|
323
|
+
}
|
|
324
|
+
return option;
|
|
325
|
+
})
|
|
326
|
+
};
|
|
327
|
+
schema.add({
|
|
328
|
+
[field.name]: localizeSchema(field, baseSchema, payload.config.localization, parentIsLocalized)
|
|
329
|
+
});
|
|
330
|
+
};
|
|
331
|
+
const relationship = (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
|
|
332
|
+
const hasManyRelations = Array.isArray(field.relationTo);
|
|
333
|
+
let schemaToReturn = {};
|
|
334
|
+
const valueType = getRelationshipValueType(field, payload);
|
|
335
|
+
if (fieldShouldBeLocalized({
|
|
336
|
+
field,
|
|
337
|
+
parentIsLocalized
|
|
338
|
+
}) && payload.config.localization) {
|
|
339
|
+
schemaToReturn = {
|
|
340
|
+
_id: false,
|
|
341
|
+
type: payload.config.localization.localeCodes.reduce((locales, locale)=>{
|
|
342
|
+
let localeSchema = {};
|
|
343
|
+
if (hasManyRelations) {
|
|
344
|
+
localeSchema = {
|
|
345
|
+
...formatBaseSchema({
|
|
346
|
+
buildSchemaOptions,
|
|
347
|
+
field,
|
|
348
|
+
parentIsLocalized
|
|
349
|
+
}),
|
|
350
|
+
_id: false,
|
|
351
|
+
type: mongoose.Schema.Types.Mixed,
|
|
352
|
+
relationTo: {
|
|
353
|
+
type: String,
|
|
354
|
+
enum: field.relationTo
|
|
355
|
+
},
|
|
356
|
+
value: {
|
|
366
357
|
type: valueType,
|
|
367
|
-
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
358
|
+
refPath: `${field.name}.${locale}.relationTo`
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
} else {
|
|
362
|
+
localeSchema = {
|
|
363
|
+
...formatBaseSchema({
|
|
364
|
+
buildSchemaOptions,
|
|
365
|
+
field,
|
|
366
|
+
parentIsLocalized
|
|
367
|
+
}),
|
|
368
|
+
type: valueType,
|
|
369
|
+
ref: field.relationTo
|
|
378
370
|
};
|
|
379
|
-
}, {}),
|
|
380
|
-
localized: true
|
|
381
|
-
};
|
|
382
|
-
} else if (hasManyRelations) {
|
|
383
|
-
schemaToReturn = {
|
|
384
|
-
...formatBaseSchema({
|
|
385
|
-
buildSchemaOptions,
|
|
386
|
-
field,
|
|
387
|
-
parentIsLocalized
|
|
388
|
-
}),
|
|
389
|
-
_id: false,
|
|
390
|
-
type: mongoose.Schema.Types.Mixed,
|
|
391
|
-
relationTo: {
|
|
392
|
-
type: String,
|
|
393
|
-
enum: field.relationTo
|
|
394
|
-
},
|
|
395
|
-
value: {
|
|
396
|
-
type: valueType,
|
|
397
|
-
refPath: `${field.name}.relationTo`
|
|
398
371
|
}
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
372
|
+
return {
|
|
373
|
+
...locales,
|
|
374
|
+
[locale]: field.hasMany ? {
|
|
375
|
+
type: [
|
|
376
|
+
localeSchema
|
|
377
|
+
],
|
|
378
|
+
default: formatDefaultValue(field)
|
|
379
|
+
} : localeSchema
|
|
406
380
|
};
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
field,
|
|
413
|
-
parentIsLocalized
|
|
414
|
-
}),
|
|
415
|
-
type: valueType,
|
|
416
|
-
ref: field.relationTo
|
|
417
|
-
};
|
|
418
|
-
if (field.hasMany) {
|
|
419
|
-
schemaToReturn = {
|
|
420
|
-
type: [
|
|
421
|
-
schemaToReturn
|
|
422
|
-
],
|
|
423
|
-
default: formatDefaultValue(field)
|
|
424
|
-
};
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
schema.add({
|
|
428
|
-
[field.name]: schemaToReturn
|
|
429
|
-
});
|
|
430
|
-
},
|
|
431
|
-
richText: (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
|
|
432
|
-
const baseSchema = {
|
|
381
|
+
}, {}),
|
|
382
|
+
localized: true
|
|
383
|
+
};
|
|
384
|
+
} else if (hasManyRelations) {
|
|
385
|
+
schemaToReturn = {
|
|
433
386
|
...formatBaseSchema({
|
|
434
387
|
buildSchemaOptions,
|
|
435
388
|
field,
|
|
436
389
|
parentIsLocalized
|
|
437
390
|
}),
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
return;
|
|
448
|
-
}
|
|
449
|
-
const addFieldSchema = fieldToSchemaMap[subField.type];
|
|
450
|
-
if (addFieldSchema) {
|
|
451
|
-
addFieldSchema(subField, schema, payload, buildSchemaOptions, parentIsLocalized);
|
|
391
|
+
_id: false,
|
|
392
|
+
type: mongoose.Schema.Types.Mixed,
|
|
393
|
+
relationTo: {
|
|
394
|
+
type: String,
|
|
395
|
+
enum: field.relationTo
|
|
396
|
+
},
|
|
397
|
+
value: {
|
|
398
|
+
type: valueType,
|
|
399
|
+
refPath: `${field.name}.relationTo`
|
|
452
400
|
}
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
401
|
+
};
|
|
402
|
+
if (field.hasMany) {
|
|
403
|
+
schemaToReturn = {
|
|
404
|
+
type: [
|
|
405
|
+
schemaToReturn
|
|
406
|
+
],
|
|
407
|
+
default: formatDefaultValue(field)
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
} else {
|
|
411
|
+
schemaToReturn = {
|
|
457
412
|
...formatBaseSchema({
|
|
458
413
|
buildSchemaOptions,
|
|
459
414
|
field,
|
|
460
415
|
parentIsLocalized
|
|
461
416
|
}),
|
|
462
|
-
type:
|
|
463
|
-
|
|
464
|
-
if (typeof option === 'object') {
|
|
465
|
-
return option.value;
|
|
466
|
-
}
|
|
467
|
-
return option;
|
|
468
|
-
})
|
|
417
|
+
type: valueType,
|
|
418
|
+
ref: field.relationTo
|
|
469
419
|
};
|
|
470
|
-
if (
|
|
471
|
-
|
|
420
|
+
if (field.hasMany) {
|
|
421
|
+
schemaToReturn = {
|
|
422
|
+
type: [
|
|
423
|
+
schemaToReturn
|
|
424
|
+
],
|
|
425
|
+
default: formatDefaultValue(field)
|
|
426
|
+
};
|
|
472
427
|
}
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
428
|
+
}
|
|
429
|
+
schema.add({
|
|
430
|
+
[field.name]: schemaToReturn
|
|
431
|
+
});
|
|
432
|
+
};
|
|
433
|
+
const richText = (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
|
|
434
|
+
const baseSchema = {
|
|
435
|
+
...formatBaseSchema({
|
|
436
|
+
buildSchemaOptions,
|
|
437
|
+
field,
|
|
438
|
+
parentIsLocalized
|
|
439
|
+
}),
|
|
440
|
+
type: mongoose.Schema.Types.Mixed
|
|
441
|
+
};
|
|
442
|
+
schema.add({
|
|
443
|
+
[field.name]: localizeSchema(field, baseSchema, payload.config.localization, parentIsLocalized)
|
|
444
|
+
});
|
|
445
|
+
};
|
|
446
|
+
const row = (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
|
|
447
|
+
field.fields.forEach((subField)=>{
|
|
448
|
+
if (fieldIsVirtual(subField)) {
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
const addFieldSchema = getSchemaGenerator(subField.type);
|
|
452
|
+
if (addFieldSchema) {
|
|
453
|
+
addFieldSchema(subField, schema, payload, buildSchemaOptions, parentIsLocalized);
|
|
454
|
+
}
|
|
455
|
+
});
|
|
456
|
+
};
|
|
457
|
+
const select = (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
|
|
458
|
+
const baseSchema = {
|
|
459
|
+
...formatBaseSchema({
|
|
460
|
+
buildSchemaOptions,
|
|
461
|
+
field,
|
|
462
|
+
parentIsLocalized
|
|
463
|
+
}),
|
|
464
|
+
type: String,
|
|
465
|
+
enum: field.options.map((option)=>{
|
|
466
|
+
if (typeof option === 'object') {
|
|
467
|
+
return option.value;
|
|
468
|
+
}
|
|
469
|
+
return option;
|
|
470
|
+
})
|
|
471
|
+
};
|
|
472
|
+
if (buildSchemaOptions.draftsEnabled || !field.required) {
|
|
473
|
+
;
|
|
474
|
+
baseSchema.enum.push(null);
|
|
475
|
+
}
|
|
476
|
+
schema.add({
|
|
477
|
+
[field.name]: localizeSchema(field, field.hasMany ? [
|
|
478
|
+
baseSchema
|
|
479
|
+
] : baseSchema, payload.config.localization, parentIsLocalized)
|
|
480
|
+
});
|
|
481
|
+
};
|
|
482
|
+
const tabs = (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
|
|
483
|
+
field.tabs.forEach((tab)=>{
|
|
484
|
+
if (tabHasName(tab)) {
|
|
485
|
+
if (fieldIsVirtual(tab)) {
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
const baseSchema = {
|
|
489
|
+
type: buildSchema({
|
|
490
|
+
buildSchemaOptions: {
|
|
491
|
+
disableUnique: buildSchemaOptions.disableUnique,
|
|
492
|
+
draftsEnabled: buildSchemaOptions.draftsEnabled,
|
|
493
|
+
options: {
|
|
494
|
+
_id: false,
|
|
495
|
+
id: false,
|
|
496
|
+
minimize: false
|
|
497
|
+
}
|
|
498
|
+
},
|
|
499
|
+
configFields: tab.fields,
|
|
500
|
+
parentIsLocalized: parentIsLocalized || tab.localized,
|
|
501
|
+
payload
|
|
502
|
+
})
|
|
503
|
+
};
|
|
504
|
+
schema.add({
|
|
505
|
+
[tab.name]: localizeSchema(tab, baseSchema, payload.config.localization, parentIsLocalized)
|
|
506
|
+
});
|
|
507
|
+
} else {
|
|
508
|
+
tab.fields.forEach((subField)=>{
|
|
509
|
+
if (fieldIsVirtual(subField)) {
|
|
483
510
|
return;
|
|
484
511
|
}
|
|
485
|
-
const
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
512
|
+
const addFieldSchema = getSchemaGenerator(subField.type);
|
|
513
|
+
if (addFieldSchema) {
|
|
514
|
+
addFieldSchema(subField, schema, payload, buildSchemaOptions, (parentIsLocalized || tab.localized) ?? false);
|
|
515
|
+
}
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
});
|
|
519
|
+
};
|
|
520
|
+
const text = (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
|
|
521
|
+
const baseSchema = {
|
|
522
|
+
...formatBaseSchema({
|
|
523
|
+
buildSchemaOptions,
|
|
524
|
+
field,
|
|
525
|
+
parentIsLocalized
|
|
526
|
+
}),
|
|
527
|
+
type: field.hasMany ? [
|
|
528
|
+
String
|
|
529
|
+
] : String
|
|
530
|
+
};
|
|
531
|
+
schema.add({
|
|
532
|
+
[field.name]: localizeSchema(field, baseSchema, payload.config.localization, parentIsLocalized)
|
|
533
|
+
});
|
|
534
|
+
};
|
|
535
|
+
const textarea = (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
|
|
536
|
+
const baseSchema = {
|
|
537
|
+
...formatBaseSchema({
|
|
538
|
+
buildSchemaOptions,
|
|
539
|
+
field,
|
|
540
|
+
parentIsLocalized
|
|
541
|
+
}),
|
|
542
|
+
type: String
|
|
543
|
+
};
|
|
544
|
+
schema.add({
|
|
545
|
+
[field.name]: localizeSchema(field, baseSchema, payload.config.localization, parentIsLocalized)
|
|
546
|
+
});
|
|
547
|
+
};
|
|
548
|
+
const upload = (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
|
|
549
|
+
const hasManyRelations = Array.isArray(field.relationTo);
|
|
550
|
+
let schemaToReturn = {};
|
|
551
|
+
const valueType = getRelationshipValueType(field, payload);
|
|
552
|
+
if (fieldShouldBeLocalized({
|
|
553
|
+
field,
|
|
554
|
+
parentIsLocalized
|
|
555
|
+
}) && payload.config.localization) {
|
|
556
|
+
schemaToReturn = {
|
|
557
|
+
_id: false,
|
|
558
|
+
type: payload.config.localization.localeCodes.reduce((locales, locale)=>{
|
|
559
|
+
let localeSchema = {};
|
|
560
|
+
if (hasManyRelations) {
|
|
561
|
+
localeSchema = {
|
|
562
|
+
...formatBaseSchema({
|
|
563
|
+
buildSchemaOptions,
|
|
564
|
+
field,
|
|
565
|
+
parentIsLocalized
|
|
566
|
+
}),
|
|
567
|
+
_id: false,
|
|
568
|
+
type: mongoose.Schema.Types.Mixed,
|
|
569
|
+
relationTo: {
|
|
570
|
+
type: String,
|
|
571
|
+
enum: field.relationTo
|
|
495
572
|
},
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
573
|
+
value: {
|
|
574
|
+
type: valueType,
|
|
575
|
+
refPath: `${field.name}.${locale}.relationTo`
|
|
576
|
+
}
|
|
577
|
+
};
|
|
578
|
+
} else {
|
|
579
|
+
localeSchema = {
|
|
580
|
+
...formatBaseSchema({
|
|
581
|
+
buildSchemaOptions,
|
|
582
|
+
field,
|
|
583
|
+
parentIsLocalized
|
|
584
|
+
}),
|
|
585
|
+
type: valueType,
|
|
586
|
+
ref: field.relationTo
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
return {
|
|
590
|
+
...locales,
|
|
591
|
+
[locale]: field.hasMany ? {
|
|
592
|
+
type: [
|
|
593
|
+
localeSchema
|
|
594
|
+
],
|
|
595
|
+
default: formatDefaultValue(field)
|
|
596
|
+
} : localeSchema
|
|
500
597
|
};
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
if (fieldIsVirtual(subField)) {
|
|
507
|
-
return;
|
|
508
|
-
}
|
|
509
|
-
const addFieldSchema = fieldToSchemaMap[subField.type];
|
|
510
|
-
if (addFieldSchema) {
|
|
511
|
-
addFieldSchema(subField, schema, payload, buildSchemaOptions, parentIsLocalized || tab.localized);
|
|
512
|
-
}
|
|
513
|
-
});
|
|
514
|
-
}
|
|
515
|
-
});
|
|
516
|
-
},
|
|
517
|
-
text: (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
|
|
518
|
-
const baseSchema = {
|
|
598
|
+
}, {}),
|
|
599
|
+
localized: true
|
|
600
|
+
};
|
|
601
|
+
} else if (hasManyRelations) {
|
|
602
|
+
schemaToReturn = {
|
|
519
603
|
...formatBaseSchema({
|
|
520
604
|
buildSchemaOptions,
|
|
521
605
|
field,
|
|
522
606
|
parentIsLocalized
|
|
523
607
|
}),
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
608
|
+
_id: false,
|
|
609
|
+
type: mongoose.Schema.Types.Mixed,
|
|
610
|
+
relationTo: {
|
|
611
|
+
type: String,
|
|
612
|
+
enum: field.relationTo
|
|
613
|
+
},
|
|
614
|
+
value: {
|
|
615
|
+
type: valueType,
|
|
616
|
+
refPath: `${field.name}.relationTo`
|
|
617
|
+
}
|
|
527
618
|
};
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
619
|
+
if (field.hasMany) {
|
|
620
|
+
schemaToReturn = {
|
|
621
|
+
type: [
|
|
622
|
+
schemaToReturn
|
|
623
|
+
],
|
|
624
|
+
default: formatDefaultValue(field)
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
} else {
|
|
628
|
+
schemaToReturn = {
|
|
534
629
|
...formatBaseSchema({
|
|
535
630
|
buildSchemaOptions,
|
|
536
631
|
field,
|
|
537
632
|
parentIsLocalized
|
|
538
633
|
}),
|
|
539
|
-
type:
|
|
634
|
+
type: valueType,
|
|
635
|
+
ref: field.relationTo
|
|
540
636
|
};
|
|
541
|
-
|
|
542
|
-
[field.name]: localizeSchema(field, baseSchema, payload.config.localization, parentIsLocalized)
|
|
543
|
-
});
|
|
544
|
-
},
|
|
545
|
-
upload: (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
|
|
546
|
-
const hasManyRelations = Array.isArray(field.relationTo);
|
|
547
|
-
let schemaToReturn = {};
|
|
548
|
-
const valueType = getRelationshipValueType(field, payload);
|
|
549
|
-
if (fieldShouldBeLocalized({
|
|
550
|
-
field,
|
|
551
|
-
parentIsLocalized
|
|
552
|
-
}) && payload.config.localization) {
|
|
637
|
+
if (field.hasMany) {
|
|
553
638
|
schemaToReturn = {
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
localeSchema = {
|
|
559
|
-
...formatBaseSchema({
|
|
560
|
-
buildSchemaOptions,
|
|
561
|
-
field,
|
|
562
|
-
parentIsLocalized
|
|
563
|
-
}),
|
|
564
|
-
_id: false,
|
|
565
|
-
type: mongoose.Schema.Types.Mixed,
|
|
566
|
-
relationTo: {
|
|
567
|
-
type: String,
|
|
568
|
-
enum: field.relationTo
|
|
569
|
-
},
|
|
570
|
-
value: {
|
|
571
|
-
type: valueType,
|
|
572
|
-
refPath: `${field.name}.${locale}.relationTo`
|
|
573
|
-
}
|
|
574
|
-
};
|
|
575
|
-
} else {
|
|
576
|
-
localeSchema = {
|
|
577
|
-
...formatBaseSchema({
|
|
578
|
-
buildSchemaOptions,
|
|
579
|
-
field,
|
|
580
|
-
parentIsLocalized
|
|
581
|
-
}),
|
|
582
|
-
type: valueType,
|
|
583
|
-
ref: field.relationTo
|
|
584
|
-
};
|
|
585
|
-
}
|
|
586
|
-
return {
|
|
587
|
-
...locales,
|
|
588
|
-
[locale]: field.hasMany ? {
|
|
589
|
-
type: [
|
|
590
|
-
localeSchema
|
|
591
|
-
],
|
|
592
|
-
default: formatDefaultValue(field)
|
|
593
|
-
} : localeSchema
|
|
594
|
-
};
|
|
595
|
-
}, {}),
|
|
596
|
-
localized: true
|
|
597
|
-
};
|
|
598
|
-
} else if (hasManyRelations) {
|
|
599
|
-
schemaToReturn = {
|
|
600
|
-
...formatBaseSchema({
|
|
601
|
-
buildSchemaOptions,
|
|
602
|
-
field,
|
|
603
|
-
parentIsLocalized
|
|
604
|
-
}),
|
|
605
|
-
_id: false,
|
|
606
|
-
type: mongoose.Schema.Types.Mixed,
|
|
607
|
-
relationTo: {
|
|
608
|
-
type: String,
|
|
609
|
-
enum: field.relationTo
|
|
610
|
-
},
|
|
611
|
-
value: {
|
|
612
|
-
type: valueType,
|
|
613
|
-
refPath: `${field.name}.relationTo`
|
|
614
|
-
}
|
|
615
|
-
};
|
|
616
|
-
if (field.hasMany) {
|
|
617
|
-
schemaToReturn = {
|
|
618
|
-
type: [
|
|
619
|
-
schemaToReturn
|
|
620
|
-
],
|
|
621
|
-
default: formatDefaultValue(field)
|
|
622
|
-
};
|
|
623
|
-
}
|
|
624
|
-
} else {
|
|
625
|
-
schemaToReturn = {
|
|
626
|
-
...formatBaseSchema({
|
|
627
|
-
buildSchemaOptions,
|
|
628
|
-
field,
|
|
629
|
-
parentIsLocalized
|
|
630
|
-
}),
|
|
631
|
-
type: valueType,
|
|
632
|
-
ref: field.relationTo
|
|
639
|
+
type: [
|
|
640
|
+
schemaToReturn
|
|
641
|
+
],
|
|
642
|
+
default: formatDefaultValue(field)
|
|
633
643
|
};
|
|
634
|
-
if (field.hasMany) {
|
|
635
|
-
schemaToReturn = {
|
|
636
|
-
type: [
|
|
637
|
-
schemaToReturn
|
|
638
|
-
],
|
|
639
|
-
default: formatDefaultValue(field)
|
|
640
|
-
};
|
|
641
|
-
}
|
|
642
644
|
}
|
|
643
|
-
schema.add({
|
|
644
|
-
[field.name]: schemaToReturn
|
|
645
|
-
});
|
|
646
645
|
}
|
|
646
|
+
schema.add({
|
|
647
|
+
[field.name]: schemaToReturn
|
|
648
|
+
});
|
|
649
|
+
};
|
|
650
|
+
const getSchemaGenerator = (fieldType)=>{
|
|
651
|
+
if (fieldType in fieldToSchemaMap) {
|
|
652
|
+
return fieldToSchemaMap[fieldType];
|
|
653
|
+
}
|
|
654
|
+
return null;
|
|
655
|
+
};
|
|
656
|
+
const fieldToSchemaMap = {
|
|
657
|
+
array,
|
|
658
|
+
blocks,
|
|
659
|
+
checkbox,
|
|
660
|
+
code,
|
|
661
|
+
collapsible,
|
|
662
|
+
date,
|
|
663
|
+
email,
|
|
664
|
+
group,
|
|
665
|
+
json,
|
|
666
|
+
number,
|
|
667
|
+
point,
|
|
668
|
+
radio,
|
|
669
|
+
relationship,
|
|
670
|
+
richText,
|
|
671
|
+
row,
|
|
672
|
+
select,
|
|
673
|
+
tabs,
|
|
674
|
+
text,
|
|
675
|
+
textarea,
|
|
676
|
+
upload
|
|
647
677
|
};
|
|
648
678
|
const getRelationshipValueType = (field, payload)=>{
|
|
649
679
|
if (typeof field.relationTo === 'string') {
|
|
650
|
-
const
|
|
680
|
+
const customIDType = payload.collections[field.relationTo]?.customIDType;
|
|
651
681
|
if (!customIDType) {
|
|
652
682
|
return mongoose.Schema.Types.ObjectId;
|
|
653
683
|
}
|
|
@@ -658,7 +688,7 @@ const getRelationshipValueType = (field, payload)=>{
|
|
|
658
688
|
}
|
|
659
689
|
// has custom id relationTo
|
|
660
690
|
if (field.relationTo.some((relationTo)=>{
|
|
661
|
-
return !!payload.collections[relationTo]
|
|
691
|
+
return !!payload.collections[relationTo]?.customIDType;
|
|
662
692
|
})) {
|
|
663
693
|
return mongoose.Schema.Types.Mixed;
|
|
664
694
|
}
|