@payloadcms/db-mongodb 3.0.0-beta.130 → 3.0.0-beta.132
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 +1 -8
- package/dist/connect.js.map +1 -1
- package/dist/count.d.ts.map +1 -1
- package/dist/count.js +8 -1
- package/dist/count.js.map +1 -1
- package/dist/countGlobalVersions.d.ts.map +1 -1
- package/dist/countGlobalVersions.js +8 -1
- package/dist/countGlobalVersions.js.map +1 -1
- package/dist/countVersions.d.ts.map +1 -1
- package/dist/countVersions.js +8 -1
- package/dist/countVersions.js.map +1 -1
- package/dist/createVersion.js +2 -2
- package/dist/createVersion.js.map +1 -1
- package/dist/exports/migration-utils.d.ts +3 -0
- package/dist/exports/migration-utils.d.ts.map +1 -0
- package/dist/exports/migration-utils.js +4 -0
- package/dist/exports/migration-utils.js.map +1 -0
- package/dist/find.d.ts.map +1 -1
- package/dist/find.js +0 -1
- package/dist/find.js.map +1 -1
- package/dist/findGlobalVersions.d.ts.map +1 -1
- package/dist/findGlobalVersions.js +0 -1
- package/dist/findGlobalVersions.js.map +1 -1
- package/dist/findVersions.d.ts.map +1 -1
- package/dist/findVersions.js +0 -1
- package/dist/findVersions.js.map +1 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/init.js +4 -4
- package/dist/init.js.map +1 -1
- package/dist/models/buildCollectionSchema.d.ts +2 -2
- package/dist/models/buildCollectionSchema.d.ts.map +1 -1
- package/dist/models/buildCollectionSchema.js +4 -4
- package/dist/models/buildCollectionSchema.js.map +1 -1
- package/dist/models/buildGlobalModel.d.ts +2 -2
- package/dist/models/buildGlobalModel.d.ts.map +1 -1
- package/dist/models/buildGlobalModel.js +4 -4
- package/dist/models/buildGlobalModel.js.map +1 -1
- package/dist/models/buildSchema.d.ts +2 -2
- package/dist/models/buildSchema.d.ts.map +1 -1
- package/dist/models/buildSchema.js +82 -61
- package/dist/models/buildSchema.js.map +1 -1
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts +6 -0
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts.map +1 -0
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js +141 -0
- package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js.map +1 -0
- package/dist/predefinedMigrations/migrateVersionsV1_V2.d.ts +5 -0
- package/dist/predefinedMigrations/migrateVersionsV1_V2.d.ts.map +1 -0
- package/dist/predefinedMigrations/migrateVersionsV1_V2.js +107 -0
- package/dist/predefinedMigrations/migrateVersionsV1_V2.js.map +1 -0
- package/dist/predefinedMigrations/relationships-v2-v3.d.ts +4 -0
- package/dist/predefinedMigrations/relationships-v2-v3.d.ts.map +1 -0
- package/dist/predefinedMigrations/relationships-v2-v3.js +9 -0
- package/dist/predefinedMigrations/relationships-v2-v3.js.map +1 -0
- package/dist/predefinedMigrations/versions-v1-v2.d.ts +4 -0
- package/dist/predefinedMigrations/versions-v1-v2.d.ts.map +1 -0
- package/dist/predefinedMigrations/versions-v1-v2.js +5 -95
- package/dist/predefinedMigrations/versions-v1-v2.js.map +1 -1
- package/dist/queries/buildSearchParams.d.ts.map +1 -1
- package/dist/queries/buildSearchParams.js +5 -6
- package/dist/queries/buildSearchParams.js.map +1 -1
- package/dist/queries/parseParams.d.ts.map +1 -1
- package/dist/queries/parseParams.js +4 -1
- package/dist/queries/parseParams.js.map +1 -1
- package/dist/queries/sanitizeQueryValue.d.ts +3 -2
- package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
- package/dist/queries/sanitizeQueryValue.js +153 -46
- package/dist/queries/sanitizeQueryValue.js.map +1 -1
- package/dist/queryDrafts.d.ts.map +1 -1
- package/dist/queryDrafts.js +0 -1
- package/dist/queryDrafts.js.map +1 -1
- package/dist/updateGlobal.d.ts.map +1 -1
- package/dist/updateGlobal.js +2 -1
- 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 +2 -1
- package/dist/updateGlobalVersion.js.map +1 -1
- package/dist/updateVersion.d.ts.map +1 -1
- package/dist/updateVersion.js +2 -1
- package/dist/updateVersion.js.map +1 -1
- package/dist/utilities/buildProjectionFromSelect.d.ts.map +1 -1
- package/dist/utilities/buildProjectionFromSelect.js.map +1 -1
- package/dist/utilities/sanitizeRelationshipIDs.js +3 -2
- package/dist/utilities/sanitizeRelationshipIDs.js.map +1 -1
- package/dist/utilities/sanitizeRelationshipIDs.spec.js +408 -0
- package/dist/utilities/sanitizeRelationshipIDs.spec.js.map +1 -0
- package/package.json +13 -10
- package/dist/queries/mock.js +0 -2
- package/dist/queries/mock.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { Schema } from 'mongoose';
|
|
2
|
-
import type {
|
|
3
|
-
export declare const buildCollectionSchema: (collection: SanitizedCollectionConfig,
|
|
2
|
+
import type { Payload, SanitizedCollectionConfig } from 'payload';
|
|
3
|
+
export declare const buildCollectionSchema: (collection: SanitizedCollectionConfig, payload: Payload, schemaOptions?: {}) => Schema;
|
|
4
4
|
//# sourceMappingURL=buildCollectionSchema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildCollectionSchema.d.ts","sourceRoot":"","sources":["../../src/models/buildCollectionSchema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAmB,MAAM,EAAE,MAAM,UAAU,CAAA;AACvD,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"buildCollectionSchema.d.ts","sourceRoot":"","sources":["../../src/models/buildCollectionSchema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAmB,MAAM,EAAE,MAAM,UAAU,CAAA;AACvD,OAAO,KAAK,EAAE,OAAO,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAA;AAQjE,eAAO,MAAM,qBAAqB,eACpB,yBAAyB,WAC5B,OAAO,yBAEf,MAqCF,CAAA"}
|
|
@@ -2,10 +2,10 @@ import mongooseAggregatePaginate from 'mongoose-aggregate-paginate-v2';
|
|
|
2
2
|
import paginate from 'mongoose-paginate-v2';
|
|
3
3
|
import { getBuildQueryPlugin } from '../queries/buildQuery.js';
|
|
4
4
|
import { buildSchema } from './buildSchema.js';
|
|
5
|
-
export const buildCollectionSchema = (collection,
|
|
6
|
-
const schema = buildSchema(
|
|
5
|
+
export const buildCollectionSchema = (collection, payload, schemaOptions = {})=>{
|
|
6
|
+
const schema = buildSchema(payload, collection.fields, {
|
|
7
7
|
draftsEnabled: Boolean(typeof collection?.versions === 'object' && collection.versions.drafts),
|
|
8
|
-
indexSortableFields: config.indexSortableFields,
|
|
8
|
+
indexSortableFields: payload.config.indexSortableFields,
|
|
9
9
|
options: {
|
|
10
10
|
minimize: false,
|
|
11
11
|
timestamps: collection.timestamps !== false,
|
|
@@ -21,7 +21,7 @@ export const buildCollectionSchema = (collection, config, schemaOptions = {})=>{
|
|
|
21
21
|
unique: true
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
|
-
if (config.indexSortableFields && collection.timestamps !== false) {
|
|
24
|
+
if (payload.config.indexSortableFields && collection.timestamps !== false) {
|
|
25
25
|
schema.index({
|
|
26
26
|
updatedAt: 1
|
|
27
27
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/models/buildCollectionSchema.ts"],"sourcesContent":["import type { PaginateOptions, Schema } from 'mongoose'\nimport type {
|
|
1
|
+
{"version":3,"sources":["../../src/models/buildCollectionSchema.ts"],"sourcesContent":["import type { PaginateOptions, Schema } from 'mongoose'\nimport type { Payload, SanitizedCollectionConfig } from 'payload'\n\nimport mongooseAggregatePaginate from 'mongoose-aggregate-paginate-v2'\nimport paginate from 'mongoose-paginate-v2'\n\nimport { getBuildQueryPlugin } from '../queries/buildQuery.js'\nimport { buildSchema } from './buildSchema.js'\n\nexport const buildCollectionSchema = (\n collection: SanitizedCollectionConfig,\n payload: Payload,\n schemaOptions = {},\n): Schema => {\n const schema = buildSchema(payload, collection.fields, {\n draftsEnabled: Boolean(typeof collection?.versions === 'object' && collection.versions.drafts),\n indexSortableFields: payload.config.indexSortableFields,\n options: {\n minimize: false,\n timestamps: collection.timestamps !== false,\n ...schemaOptions,\n },\n })\n\n if (Array.isArray(collection.upload.filenameCompoundIndex)) {\n const indexDefinition: Record<string, 1> = collection.upload.filenameCompoundIndex.reduce(\n (acc, index) => {\n acc[index] = 1\n return acc\n },\n {},\n )\n\n schema.index(indexDefinition, { unique: true })\n }\n\n if (payload.config.indexSortableFields && collection.timestamps !== false) {\n schema.index({ updatedAt: 1 })\n schema.index({ createdAt: 1 })\n }\n\n schema\n .plugin<any, PaginateOptions>(paginate, { useEstimatedCount: true })\n .plugin(getBuildQueryPlugin({ collectionSlug: collection.slug }))\n\n if (Object.keys(collection.joins).length > 0) {\n schema.plugin(mongooseAggregatePaginate)\n }\n\n return schema\n}\n"],"names":["mongooseAggregatePaginate","paginate","getBuildQueryPlugin","buildSchema","buildCollectionSchema","collection","payload","schemaOptions","schema","fields","draftsEnabled","Boolean","versions","drafts","indexSortableFields","config","options","minimize","timestamps","Array","isArray","upload","filenameCompoundIndex","indexDefinition","reduce","acc","index","unique","updatedAt","createdAt","plugin","useEstimatedCount","collectionSlug","slug","Object","keys","joins","length"],"mappings":"AAGA,OAAOA,+BAA+B,iCAAgC;AACtE,OAAOC,cAAc,uBAAsB;AAE3C,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,wBAAwB,CACnCC,YACAC,SACAC,gBAAgB,CAAC,CAAC;IAElB,MAAMC,SAASL,YAAYG,SAASD,WAAWI,MAAM,EAAE;QACrDC,eAAeC,QAAQ,OAAON,YAAYO,aAAa,YAAYP,WAAWO,QAAQ,CAACC,MAAM;QAC7FC,qBAAqBR,QAAQS,MAAM,CAACD,mBAAmB;QACvDE,SAAS;YACPC,UAAU;YACVC,YAAYb,WAAWa,UAAU,KAAK;YACtC,GAAGX,aAAa;QAClB;IACF;IAEA,IAAIY,MAAMC,OAAO,CAACf,WAAWgB,MAAM,CAACC,qBAAqB,GAAG;QAC1D,MAAMC,kBAAqClB,WAAWgB,MAAM,CAACC,qBAAqB,CAACE,MAAM,CACvF,CAACC,KAAKC;YACJD,GAAG,CAACC,MAAM,GAAG;YACb,OAAOD;QACT,GACA,CAAC;QAGHjB,OAAOkB,KAAK,CAACH,iBAAiB;YAAEI,QAAQ;QAAK;IAC/C;IAEA,IAAIrB,QAAQS,MAAM,CAACD,mBAAmB,IAAIT,WAAWa,UAAU,KAAK,OAAO;QACzEV,OAAOkB,KAAK,CAAC;YAAEE,WAAW;QAAE;QAC5BpB,OAAOkB,KAAK,CAAC;YAAEG,WAAW;QAAE;IAC9B;IAEArB,OACGsB,MAAM,CAAuB7B,UAAU;QAAE8B,mBAAmB;IAAK,GACjED,MAAM,CAAC5B,oBAAoB;QAAE8B,gBAAgB3B,WAAW4B,IAAI;IAAC;IAEhE,IAAIC,OAAOC,IAAI,CAAC9B,WAAW+B,KAAK,EAAEC,MAAM,GAAG,GAAG;QAC5C7B,OAAOsB,MAAM,CAAC9B;IAChB;IAEA,OAAOQ;AACT,EAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Payload } from 'payload';
|
|
2
2
|
import type { GlobalModel } from '../types.js';
|
|
3
|
-
export declare const buildGlobalModel: (
|
|
3
|
+
export declare const buildGlobalModel: (payload: Payload) => GlobalModel | null;
|
|
4
4
|
//# sourceMappingURL=buildGlobalModel.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildGlobalModel.d.ts","sourceRoot":"","sources":["../../src/models/buildGlobalModel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"buildGlobalModel.d.ts","sourceRoot":"","sources":["../../src/models/buildGlobalModel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAItC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAK9C,eAAO,MAAM,gBAAgB,YAAa,OAAO,KAAG,WAAW,GAAG,IAwBjE,CAAA"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import mongoose from 'mongoose';
|
|
2
2
|
import { getBuildQueryPlugin } from '../queries/buildQuery.js';
|
|
3
3
|
import { buildSchema } from './buildSchema.js';
|
|
4
|
-
export const buildGlobalModel = (
|
|
5
|
-
if (config.globals && config.globals.length > 0) {
|
|
4
|
+
export const buildGlobalModel = (payload)=>{
|
|
5
|
+
if (payload.config.globals && payload.config.globals.length > 0) {
|
|
6
6
|
const globalsSchema = new mongoose.Schema({}, {
|
|
7
7
|
discriminatorKey: 'globalType',
|
|
8
8
|
minimize: false,
|
|
@@ -10,8 +10,8 @@ export const buildGlobalModel = (config)=>{
|
|
|
10
10
|
});
|
|
11
11
|
globalsSchema.plugin(getBuildQueryPlugin());
|
|
12
12
|
const Globals = mongoose.model('globals', globalsSchema, 'globals');
|
|
13
|
-
Object.values(config.globals).forEach((globalConfig)=>{
|
|
14
|
-
const globalSchema = buildSchema(
|
|
13
|
+
Object.values(payload.config.globals).forEach((globalConfig)=>{
|
|
14
|
+
const globalSchema = buildSchema(payload, globalConfig.fields, {
|
|
15
15
|
options: {
|
|
16
16
|
minimize: false
|
|
17
17
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/models/buildGlobalModel.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"sources":["../../src/models/buildGlobalModel.ts"],"sourcesContent":["import type { Payload } from 'payload'\n\nimport mongoose from 'mongoose'\n\nimport type { GlobalModel } from '../types.js'\n\nimport { getBuildQueryPlugin } from '../queries/buildQuery.js'\nimport { buildSchema } from './buildSchema.js'\n\nexport const buildGlobalModel = (payload: Payload): GlobalModel | null => {\n if (payload.config.globals && payload.config.globals.length > 0) {\n const globalsSchema = new mongoose.Schema(\n {},\n { discriminatorKey: 'globalType', minimize: false, timestamps: true },\n )\n\n globalsSchema.plugin(getBuildQueryPlugin())\n\n const Globals = mongoose.model('globals', globalsSchema, 'globals') as unknown as GlobalModel\n\n Object.values(payload.config.globals).forEach((globalConfig) => {\n const globalSchema = buildSchema(payload, globalConfig.fields, {\n options: {\n minimize: false,\n },\n })\n Globals.discriminator(globalConfig.slug, globalSchema)\n })\n\n return Globals\n }\n\n return null\n}\n"],"names":["mongoose","getBuildQueryPlugin","buildSchema","buildGlobalModel","payload","config","globals","length","globalsSchema","Schema","discriminatorKey","minimize","timestamps","plugin","Globals","model","Object","values","forEach","globalConfig","globalSchema","fields","options","discriminator","slug"],"mappings":"AAEA,OAAOA,cAAc,WAAU;AAI/B,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,mBAAmB,CAACC;IAC/B,IAAIA,QAAQC,MAAM,CAACC,OAAO,IAAIF,QAAQC,MAAM,CAACC,OAAO,CAACC,MAAM,GAAG,GAAG;QAC/D,MAAMC,gBAAgB,IAAIR,SAASS,MAAM,CACvC,CAAC,GACD;YAAEC,kBAAkB;YAAcC,UAAU;YAAOC,YAAY;QAAK;QAGtEJ,cAAcK,MAAM,CAACZ;QAErB,MAAMa,UAAUd,SAASe,KAAK,CAAC,WAAWP,eAAe;QAEzDQ,OAAOC,MAAM,CAACb,QAAQC,MAAM,CAACC,OAAO,EAAEY,OAAO,CAAC,CAACC;YAC7C,MAAMC,eAAelB,YAAYE,SAASe,aAAaE,MAAM,EAAE;gBAC7DC,SAAS;oBACPX,UAAU;gBACZ;YACF;YACAG,QAAQS,aAAa,CAACJ,aAAaK,IAAI,EAAEJ;QAC3C;QAEA,OAAON;IACT;IAEA,OAAO;AACT,EAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Schema, SchemaOptions } from 'mongoose';
|
|
2
|
-
import type
|
|
2
|
+
import { type Field, type Payload } from 'payload';
|
|
3
3
|
export type BuildSchemaOptions = {
|
|
4
4
|
allowIDField?: boolean;
|
|
5
5
|
disableUnique?: boolean;
|
|
@@ -7,5 +7,5 @@ export type BuildSchemaOptions = {
|
|
|
7
7
|
indexSortableFields?: boolean;
|
|
8
8
|
options?: SchemaOptions;
|
|
9
9
|
};
|
|
10
|
-
export declare const buildSchema: (
|
|
10
|
+
export declare const buildSchema: (payload: Payload, configFields: Field[], buildSchemaOptions?: BuildSchemaOptions) => Schema;
|
|
11
11
|
//# sourceMappingURL=buildSchema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildSchema.d.ts","sourceRoot":"","sources":["../../src/models/buildSchema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,MAAM,EAAE,aAAa,EAAqB,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"buildSchema.d.ts","sourceRoot":"","sources":["../../src/models/buildSchema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,MAAM,EAAE,aAAa,EAAqB,MAAM,UAAU,CAAA;AAGtF,OAAO,EASL,KAAK,KAAK,EAMV,KAAK,OAAO,EAab,MAAM,SAAS,CAAA;AAShB,MAAM,MAAM,kBAAkB,GAAG;IAC/B,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAC7B,OAAO,CAAC,EAAE,aAAa,CAAA;CACxB,CAAA;AAoED,eAAO,MAAM,WAAW,YACb,OAAO,gBACF,KAAK,EAAE,uBACD,kBAAkB,KACrC,MAmCF,CAAA"}
|
|
@@ -34,7 +34,7 @@ const localizeSchema = (entity, schema, localization)=>{
|
|
|
34
34
|
}
|
|
35
35
|
return schema;
|
|
36
36
|
};
|
|
37
|
-
export const buildSchema = (
|
|
37
|
+
export const buildSchema = (payload, configFields, buildSchemaOptions = {})=>{
|
|
38
38
|
const { allowIDField, options } = buildSchemaOptions;
|
|
39
39
|
let fields = {};
|
|
40
40
|
let schemaFields = configFields;
|
|
@@ -55,18 +55,18 @@ export const buildSchema = (config, configFields, buildSchemaOptions = {})=>{
|
|
|
55
55
|
if (!fieldIsPresentationalOnly(field)) {
|
|
56
56
|
const addFieldSchema = fieldToSchemaMap[field.type];
|
|
57
57
|
if (addFieldSchema) {
|
|
58
|
-
addFieldSchema(field, schema,
|
|
58
|
+
addFieldSchema(field, schema, payload, buildSchemaOptions);
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
});
|
|
62
62
|
return schema;
|
|
63
63
|
};
|
|
64
64
|
const fieldToSchemaMap = {
|
|
65
|
-
array: (field, schema,
|
|
65
|
+
array: (field, schema, payload, buildSchemaOptions)=>{
|
|
66
66
|
const baseSchema = {
|
|
67
67
|
...formatBaseSchema(field, buildSchemaOptions),
|
|
68
68
|
type: [
|
|
69
|
-
buildSchema(
|
|
69
|
+
buildSchema(payload, field.fields, {
|
|
70
70
|
allowIDField: true,
|
|
71
71
|
disableUnique: buildSchemaOptions.disableUnique,
|
|
72
72
|
draftsEnabled: buildSchemaOptions.draftsEnabled,
|
|
@@ -79,10 +79,10 @@ const fieldToSchemaMap = {
|
|
|
79
79
|
]
|
|
80
80
|
};
|
|
81
81
|
schema.add({
|
|
82
|
-
[field.name]: localizeSchema(field, baseSchema, config.localization)
|
|
82
|
+
[field.name]: localizeSchema(field, baseSchema, payload.config.localization)
|
|
83
83
|
});
|
|
84
84
|
},
|
|
85
|
-
blocks: (field, schema,
|
|
85
|
+
blocks: (field, schema, payload, buildSchemaOptions)=>{
|
|
86
86
|
const fieldSchema = {
|
|
87
87
|
type: [
|
|
88
88
|
new mongoose.Schema({}, {
|
|
@@ -92,7 +92,7 @@ const fieldToSchemaMap = {
|
|
|
92
92
|
]
|
|
93
93
|
};
|
|
94
94
|
schema.add({
|
|
95
|
-
[field.name]: localizeSchema(field, fieldSchema, config.localization)
|
|
95
|
+
[field.name]: localizeSchema(field, fieldSchema, payload.config.localization)
|
|
96
96
|
});
|
|
97
97
|
field.blocks.forEach((blockItem)=>{
|
|
98
98
|
const blockSchema = new mongoose.Schema({}, {
|
|
@@ -102,11 +102,11 @@ const fieldToSchemaMap = {
|
|
|
102
102
|
blockItem.fields.forEach((blockField)=>{
|
|
103
103
|
const addFieldSchema = fieldToSchemaMap[blockField.type];
|
|
104
104
|
if (addFieldSchema) {
|
|
105
|
-
addFieldSchema(blockField, blockSchema,
|
|
105
|
+
addFieldSchema(blockField, blockSchema, payload, buildSchemaOptions);
|
|
106
106
|
}
|
|
107
107
|
});
|
|
108
|
-
if (field.localized && config.localization) {
|
|
109
|
-
config.localization.localeCodes.forEach((localeCode)=>{
|
|
108
|
+
if (field.localized && payload.config.localization) {
|
|
109
|
+
payload.config.localization.localeCodes.forEach((localeCode)=>{
|
|
110
110
|
// @ts-expect-error Possible incorrect typing in mongoose types, this works
|
|
111
111
|
schema.path(`${field.name}.${localeCode}`).discriminator(blockItem.slug, blockSchema);
|
|
112
112
|
});
|
|
@@ -116,60 +116,60 @@ const fieldToSchemaMap = {
|
|
|
116
116
|
}
|
|
117
117
|
});
|
|
118
118
|
},
|
|
119
|
-
checkbox: (field, schema,
|
|
119
|
+
checkbox: (field, schema, payload, buildSchemaOptions)=>{
|
|
120
120
|
const baseSchema = {
|
|
121
121
|
...formatBaseSchema(field, buildSchemaOptions),
|
|
122
122
|
type: Boolean
|
|
123
123
|
};
|
|
124
124
|
schema.add({
|
|
125
|
-
[field.name]: localizeSchema(field, baseSchema, config.localization)
|
|
125
|
+
[field.name]: localizeSchema(field, baseSchema, payload.config.localization)
|
|
126
126
|
});
|
|
127
127
|
},
|
|
128
|
-
code: (field, schema,
|
|
128
|
+
code: (field, schema, payload, buildSchemaOptions)=>{
|
|
129
129
|
const baseSchema = {
|
|
130
130
|
...formatBaseSchema(field, buildSchemaOptions),
|
|
131
131
|
type: String
|
|
132
132
|
};
|
|
133
133
|
schema.add({
|
|
134
|
-
[field.name]: localizeSchema(field, baseSchema, config.localization)
|
|
134
|
+
[field.name]: localizeSchema(field, baseSchema, payload.config.localization)
|
|
135
135
|
});
|
|
136
136
|
},
|
|
137
|
-
collapsible: (field, schema,
|
|
137
|
+
collapsible: (field, schema, payload, buildSchemaOptions)=>{
|
|
138
138
|
field.fields.forEach((subField)=>{
|
|
139
139
|
if (fieldIsVirtual(subField)) {
|
|
140
140
|
return;
|
|
141
141
|
}
|
|
142
142
|
const addFieldSchema = fieldToSchemaMap[subField.type];
|
|
143
143
|
if (addFieldSchema) {
|
|
144
|
-
addFieldSchema(subField, schema,
|
|
144
|
+
addFieldSchema(subField, schema, payload, buildSchemaOptions);
|
|
145
145
|
}
|
|
146
146
|
});
|
|
147
147
|
},
|
|
148
|
-
date: (field, schema,
|
|
148
|
+
date: (field, schema, payload, buildSchemaOptions)=>{
|
|
149
149
|
const baseSchema = {
|
|
150
150
|
...formatBaseSchema(field, buildSchemaOptions),
|
|
151
151
|
type: Date
|
|
152
152
|
};
|
|
153
153
|
schema.add({
|
|
154
|
-
[field.name]: localizeSchema(field, baseSchema, config.localization)
|
|
154
|
+
[field.name]: localizeSchema(field, baseSchema, payload.config.localization)
|
|
155
155
|
});
|
|
156
156
|
},
|
|
157
|
-
email: (field, schema,
|
|
157
|
+
email: (field, schema, payload, buildSchemaOptions)=>{
|
|
158
158
|
const baseSchema = {
|
|
159
159
|
...formatBaseSchema(field, buildSchemaOptions),
|
|
160
160
|
type: String
|
|
161
161
|
};
|
|
162
162
|
schema.add({
|
|
163
|
-
[field.name]: localizeSchema(field, baseSchema, config.localization)
|
|
163
|
+
[field.name]: localizeSchema(field, baseSchema, payload.config.localization)
|
|
164
164
|
});
|
|
165
165
|
},
|
|
166
|
-
group: (field, schema,
|
|
166
|
+
group: (field, schema, payload, buildSchemaOptions)=>{
|
|
167
167
|
const formattedBaseSchema = formatBaseSchema(field, buildSchemaOptions);
|
|
168
168
|
// carry indexSortableFields through to versions if drafts enabled
|
|
169
169
|
const indexSortableFields = buildSchemaOptions.indexSortableFields && field.name === 'version' && buildSchemaOptions.draftsEnabled;
|
|
170
170
|
const baseSchema = {
|
|
171
171
|
...formattedBaseSchema,
|
|
172
|
-
type: buildSchema(
|
|
172
|
+
type: buildSchema(payload, field.fields, {
|
|
173
173
|
disableUnique: buildSchemaOptions.disableUnique,
|
|
174
174
|
draftsEnabled: buildSchemaOptions.draftsEnabled,
|
|
175
175
|
indexSortableFields,
|
|
@@ -181,19 +181,19 @@ const fieldToSchemaMap = {
|
|
|
181
181
|
})
|
|
182
182
|
};
|
|
183
183
|
schema.add({
|
|
184
|
-
[field.name]: localizeSchema(field, baseSchema, config.localization)
|
|
184
|
+
[field.name]: localizeSchema(field, baseSchema, payload.config.localization)
|
|
185
185
|
});
|
|
186
186
|
},
|
|
187
|
-
json: (field, schema,
|
|
187
|
+
json: (field, schema, payload, buildSchemaOptions)=>{
|
|
188
188
|
const baseSchema = {
|
|
189
189
|
...formatBaseSchema(field, buildSchemaOptions),
|
|
190
190
|
type: mongoose.Schema.Types.Mixed
|
|
191
191
|
};
|
|
192
192
|
schema.add({
|
|
193
|
-
[field.name]: localizeSchema(field, baseSchema, config.localization)
|
|
193
|
+
[field.name]: localizeSchema(field, baseSchema, payload.config.localization)
|
|
194
194
|
});
|
|
195
195
|
},
|
|
196
|
-
number: (field, schema,
|
|
196
|
+
number: (field, schema, payload, buildSchemaOptions)=>{
|
|
197
197
|
const baseSchema = {
|
|
198
198
|
...formatBaseSchema(field, buildSchemaOptions),
|
|
199
199
|
type: field.hasMany ? [
|
|
@@ -201,10 +201,10 @@ const fieldToSchemaMap = {
|
|
|
201
201
|
] : Number
|
|
202
202
|
};
|
|
203
203
|
schema.add({
|
|
204
|
-
[field.name]: localizeSchema(field, baseSchema, config.localization)
|
|
204
|
+
[field.name]: localizeSchema(field, baseSchema, payload.config.localization)
|
|
205
205
|
});
|
|
206
206
|
},
|
|
207
|
-
point: (field, schema,
|
|
207
|
+
point: (field, schema, payload, buildSchemaOptions)=>{
|
|
208
208
|
const baseSchema = {
|
|
209
209
|
type: {
|
|
210
210
|
type: String,
|
|
@@ -227,7 +227,7 @@ const fieldToSchemaMap = {
|
|
|
227
227
|
baseSchema.coordinates.sparse = true;
|
|
228
228
|
}
|
|
229
229
|
schema.add({
|
|
230
|
-
[field.name]: localizeSchema(field, baseSchema, config.localization)
|
|
230
|
+
[field.name]: localizeSchema(field, baseSchema, payload.config.localization)
|
|
231
231
|
});
|
|
232
232
|
if (field.index === true || field.index === undefined) {
|
|
233
233
|
const indexOptions = {};
|
|
@@ -235,8 +235,8 @@ const fieldToSchemaMap = {
|
|
|
235
235
|
indexOptions.sparse = true;
|
|
236
236
|
indexOptions.unique = true;
|
|
237
237
|
}
|
|
238
|
-
if (field.localized && config.localization) {
|
|
239
|
-
config.localization.locales.forEach((locale)=>{
|
|
238
|
+
if (field.localized && payload.config.localization) {
|
|
239
|
+
payload.config.localization.locales.forEach((locale)=>{
|
|
240
240
|
schema.index({
|
|
241
241
|
[`${field.name}.${locale.code}`]: '2dsphere'
|
|
242
242
|
}, indexOptions);
|
|
@@ -248,7 +248,7 @@ const fieldToSchemaMap = {
|
|
|
248
248
|
}
|
|
249
249
|
}
|
|
250
250
|
},
|
|
251
|
-
radio: (field, schema,
|
|
251
|
+
radio: (field, schema, payload, buildSchemaOptions)=>{
|
|
252
252
|
const baseSchema = {
|
|
253
253
|
...formatBaseSchema(field, buildSchemaOptions),
|
|
254
254
|
type: String,
|
|
@@ -260,15 +260,16 @@ const fieldToSchemaMap = {
|
|
|
260
260
|
})
|
|
261
261
|
};
|
|
262
262
|
schema.add({
|
|
263
|
-
[field.name]: localizeSchema(field, baseSchema, config.localization)
|
|
263
|
+
[field.name]: localizeSchema(field, baseSchema, payload.config.localization)
|
|
264
264
|
});
|
|
265
265
|
},
|
|
266
|
-
relationship: (field, schema,
|
|
266
|
+
relationship: (field, schema, payload, buildSchemaOptions)=>{
|
|
267
267
|
const hasManyRelations = Array.isArray(field.relationTo);
|
|
268
268
|
let schemaToReturn = {};
|
|
269
|
-
|
|
269
|
+
const valueType = getRelationshipValueType(field, payload);
|
|
270
|
+
if (field.localized && payload.config.localization) {
|
|
270
271
|
schemaToReturn = {
|
|
271
|
-
type: config.localization.localeCodes.reduce((locales, locale)=>{
|
|
272
|
+
type: payload.config.localization.localeCodes.reduce((locales, locale)=>{
|
|
272
273
|
let localeSchema = {};
|
|
273
274
|
if (hasManyRelations) {
|
|
274
275
|
localeSchema = {
|
|
@@ -280,14 +281,14 @@ const fieldToSchemaMap = {
|
|
|
280
281
|
enum: field.relationTo
|
|
281
282
|
},
|
|
282
283
|
value: {
|
|
283
|
-
type:
|
|
284
|
+
type: valueType,
|
|
284
285
|
refPath: `${field.name}.${locale}.relationTo`
|
|
285
286
|
}
|
|
286
287
|
};
|
|
287
288
|
} else {
|
|
288
289
|
localeSchema = {
|
|
289
290
|
...formatBaseSchema(field, buildSchemaOptions),
|
|
290
|
-
type:
|
|
291
|
+
type: valueType,
|
|
291
292
|
ref: field.relationTo
|
|
292
293
|
};
|
|
293
294
|
}
|
|
@@ -313,7 +314,7 @@ const fieldToSchemaMap = {
|
|
|
313
314
|
enum: field.relationTo
|
|
314
315
|
},
|
|
315
316
|
value: {
|
|
316
|
-
type:
|
|
317
|
+
type: valueType,
|
|
317
318
|
refPath: `${field.name}.relationTo`
|
|
318
319
|
}
|
|
319
320
|
};
|
|
@@ -328,7 +329,7 @@ const fieldToSchemaMap = {
|
|
|
328
329
|
} else {
|
|
329
330
|
schemaToReturn = {
|
|
330
331
|
...formatBaseSchema(field, buildSchemaOptions),
|
|
331
|
-
type:
|
|
332
|
+
type: valueType,
|
|
332
333
|
ref: field.relationTo
|
|
333
334
|
};
|
|
334
335
|
if (field.hasMany) {
|
|
@@ -344,27 +345,27 @@ const fieldToSchemaMap = {
|
|
|
344
345
|
[field.name]: schemaToReturn
|
|
345
346
|
});
|
|
346
347
|
},
|
|
347
|
-
richText: (field, schema,
|
|
348
|
+
richText: (field, schema, payload, buildSchemaOptions)=>{
|
|
348
349
|
const baseSchema = {
|
|
349
350
|
...formatBaseSchema(field, buildSchemaOptions),
|
|
350
351
|
type: mongoose.Schema.Types.Mixed
|
|
351
352
|
};
|
|
352
353
|
schema.add({
|
|
353
|
-
[field.name]: localizeSchema(field, baseSchema, config.localization)
|
|
354
|
+
[field.name]: localizeSchema(field, baseSchema, payload.config.localization)
|
|
354
355
|
});
|
|
355
356
|
},
|
|
356
|
-
row: (field, schema,
|
|
357
|
+
row: (field, schema, payload, buildSchemaOptions)=>{
|
|
357
358
|
field.fields.forEach((subField)=>{
|
|
358
359
|
if (fieldIsVirtual(subField)) {
|
|
359
360
|
return;
|
|
360
361
|
}
|
|
361
362
|
const addFieldSchema = fieldToSchemaMap[subField.type];
|
|
362
363
|
if (addFieldSchema) {
|
|
363
|
-
addFieldSchema(subField, schema,
|
|
364
|
+
addFieldSchema(subField, schema, payload, buildSchemaOptions);
|
|
364
365
|
}
|
|
365
366
|
});
|
|
366
367
|
},
|
|
367
|
-
select: (field, schema,
|
|
368
|
+
select: (field, schema, payload, buildSchemaOptions)=>{
|
|
368
369
|
const baseSchema = {
|
|
369
370
|
...formatBaseSchema(field, buildSchemaOptions),
|
|
370
371
|
type: String,
|
|
@@ -381,17 +382,17 @@ const fieldToSchemaMap = {
|
|
|
381
382
|
schema.add({
|
|
382
383
|
[field.name]: localizeSchema(field, field.hasMany ? [
|
|
383
384
|
baseSchema
|
|
384
|
-
] : baseSchema, config.localization)
|
|
385
|
+
] : baseSchema, payload.config.localization)
|
|
385
386
|
});
|
|
386
387
|
},
|
|
387
|
-
tabs: (field, schema,
|
|
388
|
+
tabs: (field, schema, payload, buildSchemaOptions)=>{
|
|
388
389
|
field.tabs.forEach((tab)=>{
|
|
389
390
|
if (tabHasName(tab)) {
|
|
390
391
|
if (fieldIsVirtual(tab)) {
|
|
391
392
|
return;
|
|
392
393
|
}
|
|
393
394
|
const baseSchema = {
|
|
394
|
-
type: buildSchema(
|
|
395
|
+
type: buildSchema(payload, tab.fields, {
|
|
395
396
|
disableUnique: buildSchemaOptions.disableUnique,
|
|
396
397
|
draftsEnabled: buildSchemaOptions.draftsEnabled,
|
|
397
398
|
options: {
|
|
@@ -402,7 +403,7 @@ const fieldToSchemaMap = {
|
|
|
402
403
|
})
|
|
403
404
|
};
|
|
404
405
|
schema.add({
|
|
405
|
-
[tab.name]: localizeSchema(tab, baseSchema, config.localization)
|
|
406
|
+
[tab.name]: localizeSchema(tab, baseSchema, payload.config.localization)
|
|
406
407
|
});
|
|
407
408
|
} else {
|
|
408
409
|
tab.fields.forEach((subField)=>{
|
|
@@ -411,13 +412,13 @@ const fieldToSchemaMap = {
|
|
|
411
412
|
}
|
|
412
413
|
const addFieldSchema = fieldToSchemaMap[subField.type];
|
|
413
414
|
if (addFieldSchema) {
|
|
414
|
-
addFieldSchema(subField, schema,
|
|
415
|
+
addFieldSchema(subField, schema, payload, buildSchemaOptions);
|
|
415
416
|
}
|
|
416
417
|
});
|
|
417
418
|
}
|
|
418
419
|
});
|
|
419
420
|
},
|
|
420
|
-
text: (field, schema,
|
|
421
|
+
text: (field, schema, payload, buildSchemaOptions)=>{
|
|
421
422
|
const baseSchema = {
|
|
422
423
|
...formatBaseSchema(field, buildSchemaOptions),
|
|
423
424
|
type: field.hasMany ? [
|
|
@@ -425,24 +426,25 @@ const fieldToSchemaMap = {
|
|
|
425
426
|
] : String
|
|
426
427
|
};
|
|
427
428
|
schema.add({
|
|
428
|
-
[field.name]: localizeSchema(field, baseSchema, config.localization)
|
|
429
|
+
[field.name]: localizeSchema(field, baseSchema, payload.config.localization)
|
|
429
430
|
});
|
|
430
431
|
},
|
|
431
|
-
textarea: (field, schema,
|
|
432
|
+
textarea: (field, schema, payload, buildSchemaOptions)=>{
|
|
432
433
|
const baseSchema = {
|
|
433
434
|
...formatBaseSchema(field, buildSchemaOptions),
|
|
434
435
|
type: String
|
|
435
436
|
};
|
|
436
437
|
schema.add({
|
|
437
|
-
[field.name]: localizeSchema(field, baseSchema, config.localization)
|
|
438
|
+
[field.name]: localizeSchema(field, baseSchema, payload.config.localization)
|
|
438
439
|
});
|
|
439
440
|
},
|
|
440
|
-
upload: (field, schema,
|
|
441
|
+
upload: (field, schema, payload, buildSchemaOptions)=>{
|
|
441
442
|
const hasManyRelations = Array.isArray(field.relationTo);
|
|
442
443
|
let schemaToReturn = {};
|
|
443
|
-
|
|
444
|
+
const valueType = getRelationshipValueType(field, payload);
|
|
445
|
+
if (field.localized && payload.config.localization) {
|
|
444
446
|
schemaToReturn = {
|
|
445
|
-
type: config.localization.localeCodes.reduce((locales, locale)=>{
|
|
447
|
+
type: payload.config.localization.localeCodes.reduce((locales, locale)=>{
|
|
446
448
|
let localeSchema = {};
|
|
447
449
|
if (hasManyRelations) {
|
|
448
450
|
localeSchema = {
|
|
@@ -454,14 +456,14 @@ const fieldToSchemaMap = {
|
|
|
454
456
|
enum: field.relationTo
|
|
455
457
|
},
|
|
456
458
|
value: {
|
|
457
|
-
type:
|
|
459
|
+
type: valueType,
|
|
458
460
|
refPath: `${field.name}.${locale}.relationTo`
|
|
459
461
|
}
|
|
460
462
|
};
|
|
461
463
|
} else {
|
|
462
464
|
localeSchema = {
|
|
463
465
|
...formatBaseSchema(field, buildSchemaOptions),
|
|
464
|
-
type:
|
|
466
|
+
type: valueType,
|
|
465
467
|
ref: field.relationTo
|
|
466
468
|
};
|
|
467
469
|
}
|
|
@@ -487,7 +489,7 @@ const fieldToSchemaMap = {
|
|
|
487
489
|
enum: field.relationTo
|
|
488
490
|
},
|
|
489
491
|
value: {
|
|
490
|
-
type:
|
|
492
|
+
type: valueType,
|
|
491
493
|
refPath: `${field.name}.relationTo`
|
|
492
494
|
}
|
|
493
495
|
};
|
|
@@ -502,7 +504,7 @@ const fieldToSchemaMap = {
|
|
|
502
504
|
} else {
|
|
503
505
|
schemaToReturn = {
|
|
504
506
|
...formatBaseSchema(field, buildSchemaOptions),
|
|
505
|
-
type:
|
|
507
|
+
type: valueType,
|
|
506
508
|
ref: field.relationTo
|
|
507
509
|
};
|
|
508
510
|
if (field.hasMany) {
|
|
@@ -519,5 +521,24 @@ const fieldToSchemaMap = {
|
|
|
519
521
|
});
|
|
520
522
|
}
|
|
521
523
|
};
|
|
524
|
+
const getRelationshipValueType = (field, payload)=>{
|
|
525
|
+
if (typeof field.relationTo === 'string') {
|
|
526
|
+
const { customIDType } = payload.collections[field.relationTo];
|
|
527
|
+
if (!customIDType) {
|
|
528
|
+
return mongoose.Schema.Types.ObjectId;
|
|
529
|
+
}
|
|
530
|
+
if (customIDType === 'number') {
|
|
531
|
+
return mongoose.Schema.Types.Number;
|
|
532
|
+
}
|
|
533
|
+
return mongoose.Schema.Types.String;
|
|
534
|
+
}
|
|
535
|
+
// has custom id relationTo
|
|
536
|
+
if (field.relationTo.some((relationTo)=>{
|
|
537
|
+
return !!payload.collections[relationTo].customIDType;
|
|
538
|
+
})) {
|
|
539
|
+
return mongoose.Schema.Types.Mixed;
|
|
540
|
+
}
|
|
541
|
+
return mongoose.Schema.Types.ObjectId;
|
|
542
|
+
};
|
|
522
543
|
|
|
523
544
|
//# sourceMappingURL=buildSchema.js.map
|