@payloadcms/db-mongodb 3.90.2 → 3.91.0-internal.07e4582
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/init.d.ts.map +1 -1
- package/dist/init.js +89 -67
- package/dist/init.js.map +1 -1
- package/dist/models/buildCollectionSchema.d.ts +8 -2
- package/dist/models/buildCollectionSchema.d.ts.map +1 -1
- package/dist/models/buildCollectionSchema.js +4 -2
- package/dist/models/buildCollectionSchema.js.map +1 -1
- package/dist/models/buildGlobalModel.d.ts +5 -1
- package/dist/models/buildGlobalModel.d.ts.map +1 -1
- package/dist/models/buildGlobalModel.js +4 -2
- package/dist/models/buildGlobalModel.js.map +1 -1
- package/dist/models/buildSchema.d.ts +4 -0
- package/dist/models/buildSchema.d.ts.map +1 -1
- package/dist/models/buildSchema.js +64 -26
- package/dist/models/buildSchema.js.map +1 -1
- package/dist/models/buildSchema.spec.js +387 -0
- package/dist/models/buildSchema.spec.js.map +1 -0
- package/dist/models/schemaBuildContext.d.ts +21 -0
- package/dist/models/schemaBuildContext.d.ts.map +1 -0
- package/dist/models/schemaBuildContext.js +29 -0
- package/dist/models/schemaBuildContext.js.map +1 -0
- package/dist/models/schemaBuildContext.spec.js +72 -0
- package/dist/models/schemaBuildContext.spec.js.map +1 -0
- package/package.json +3 -3
package/dist/init.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAA6B,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAA6B,MAAM,SAAS,CAAA;AAoB9D,eAAO,MAAM,IAAI,EAAE,IAqHlB,CAAA"}
|
package/dist/init.js
CHANGED
|
@@ -4,6 +4,7 @@ import { buildVersionCollectionFields, buildVersionCompoundIndexes, buildVersion
|
|
|
4
4
|
import { buildCollectionSchema } from './models/buildCollectionSchema.js';
|
|
5
5
|
import { buildGlobalModel } from './models/buildGlobalModel.js';
|
|
6
6
|
import { buildSchema } from './models/buildSchema.js';
|
|
7
|
+
import { createMongoSchemaBuildContext } from './models/schemaBuildContext.js';
|
|
7
8
|
import { getBuildQueryPlugin } from './queries/getBuildQueryPlugin.js';
|
|
8
9
|
import { getDBName } from './utilities/getDBName.js';
|
|
9
10
|
export const init = async function init() {
|
|
@@ -13,76 +14,97 @@ export const init = async function init() {
|
|
|
13
14
|
if (this.afterCreateConnection) {
|
|
14
15
|
await this.afterCreateConnection(this);
|
|
15
16
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const schema = buildCollectionSchema(collection, this.payload, schemaOptions);
|
|
19
|
-
if (collection.versions) {
|
|
20
|
-
const versionModelName = getDBName({
|
|
21
|
-
config: collection,
|
|
22
|
-
versions: true
|
|
23
|
-
});
|
|
24
|
-
const versionCollectionFields = buildVersionCollectionFields(this.payload.config, collection);
|
|
25
|
-
const versionSchema = buildSchema({
|
|
26
|
-
buildSchemaOptions: {
|
|
27
|
-
disableUnique: true,
|
|
28
|
-
draftsEnabled: true,
|
|
29
|
-
indexSortableFields: this.payload.config.indexSortableFields,
|
|
30
|
-
options: {
|
|
31
|
-
minimize: false,
|
|
32
|
-
timestamps: false,
|
|
33
|
-
...schemaOptions
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
|
-
compoundIndexes: buildVersionCompoundIndexes({
|
|
37
|
-
indexes: collection.sanitizedIndexes
|
|
38
|
-
}),
|
|
39
|
-
configFields: versionCollectionFields,
|
|
40
|
-
payload: this.payload
|
|
41
|
-
});
|
|
42
|
-
versionSchema.plugin(paginate, {
|
|
43
|
-
useEstimatedCount: true
|
|
44
|
-
}).plugin(getBuildQueryPlugin({
|
|
45
|
-
collectionSlug: collection.slug,
|
|
46
|
-
versionsFields: buildVersionCollectionFields(this.payload.config, collection, true)
|
|
47
|
-
}));
|
|
48
|
-
const versionCollectionName = this.autoPluralization === true && !collection.dbName ? undefined : versionModelName;
|
|
49
|
-
this.versions[collection.slug] = this.connection.model(versionModelName, versionSchema, versionCollectionName);
|
|
50
|
-
}
|
|
51
|
-
const modelName = getDBName({
|
|
52
|
-
config: collection
|
|
53
|
-
});
|
|
54
|
-
const collectionName = this.autoPluralization === true && !collection.dbName ? undefined : modelName;
|
|
55
|
-
this.collections[collection.slug] = this.connection.model(modelName, schema, collectionName);
|
|
17
|
+
const schemaBuildContext = createMongoSchemaBuildContext({
|
|
18
|
+
connection: this.connection
|
|
56
19
|
});
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
20
|
+
try {
|
|
21
|
+
this.payload.config.collections.forEach((collection)=>{
|
|
22
|
+
const schemaOptions = this.collectionsSchemaOptions?.[collection.slug];
|
|
23
|
+
const schema = buildCollectionSchema({
|
|
24
|
+
collection,
|
|
25
|
+
payload: this.payload,
|
|
26
|
+
schemaBuildContext,
|
|
27
|
+
schemaOptions
|
|
63
28
|
});
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
29
|
+
if (collection.versions) {
|
|
30
|
+
const versionModelName = getDBName({
|
|
31
|
+
config: collection,
|
|
32
|
+
versions: true
|
|
33
|
+
});
|
|
34
|
+
const versionCollectionFields = buildVersionCollectionFields(this.payload.config, collection);
|
|
35
|
+
const versionSchema = buildSchema({
|
|
36
|
+
buildSchemaOptions: {
|
|
37
|
+
disableUnique: true,
|
|
38
|
+
draftsEnabled: true,
|
|
39
|
+
indexSortableFields: this.payload.config.indexSortableFields,
|
|
40
|
+
options: {
|
|
41
|
+
minimize: false,
|
|
42
|
+
timestamps: false,
|
|
43
|
+
...schemaOptions
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
compoundIndexes: buildVersionCompoundIndexes({
|
|
47
|
+
indexes: collection.sanitizedIndexes
|
|
48
|
+
}),
|
|
49
|
+
configFields: versionCollectionFields,
|
|
50
|
+
isVersion: true,
|
|
51
|
+
payload: this.payload,
|
|
52
|
+
schemaBuildContext,
|
|
53
|
+
schemaPath: `collection:${collection.slug}`
|
|
54
|
+
});
|
|
55
|
+
versionSchema.plugin(paginate, {
|
|
56
|
+
useEstimatedCount: true
|
|
57
|
+
}).plugin(getBuildQueryPlugin({
|
|
58
|
+
collectionSlug: collection.slug,
|
|
59
|
+
versionsFields: buildVersionCollectionFields(this.payload.config, collection, true)
|
|
60
|
+
}));
|
|
61
|
+
const versionCollectionName = this.autoPluralization === true && !collection.dbName ? undefined : versionModelName;
|
|
62
|
+
this.versions[collection.slug] = this.connection.model(versionModelName, versionSchema, versionCollectionName);
|
|
63
|
+
}
|
|
64
|
+
const modelName = getDBName({
|
|
65
|
+
config: collection
|
|
77
66
|
});
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
|
|
67
|
+
const collectionName = this.autoPluralization === true && !collection.dbName ? undefined : modelName;
|
|
68
|
+
this.collections[collection.slug] = this.connection.model(modelName, schema, collectionName);
|
|
69
|
+
});
|
|
70
|
+
this.globals = buildGlobalModel({
|
|
71
|
+
adapter: this,
|
|
72
|
+
schemaBuildContext
|
|
73
|
+
});
|
|
74
|
+
this.payload.config.globals.forEach((global)=>{
|
|
75
|
+
if (global.versions) {
|
|
76
|
+
const versionModelName = getDBName({
|
|
77
|
+
config: global,
|
|
78
|
+
versions: true
|
|
79
|
+
});
|
|
80
|
+
const versionGlobalFields = buildVersionGlobalFields(this.payload.config, global);
|
|
81
|
+
const versionSchema = buildSchema({
|
|
82
|
+
buildSchemaOptions: {
|
|
83
|
+
disableUnique: true,
|
|
84
|
+
draftsEnabled: true,
|
|
85
|
+
indexSortableFields: this.payload.config.indexSortableFields,
|
|
86
|
+
options: {
|
|
87
|
+
minimize: false,
|
|
88
|
+
timestamps: false
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
configFields: versionGlobalFields,
|
|
92
|
+
isVersion: true,
|
|
93
|
+
payload: this.payload,
|
|
94
|
+
schemaBuildContext,
|
|
95
|
+
schemaPath: `global:${global.slug}`
|
|
96
|
+
});
|
|
97
|
+
versionSchema.plugin(paginate, {
|
|
98
|
+
useEstimatedCount: true
|
|
99
|
+
}).plugin(getBuildQueryPlugin({
|
|
100
|
+
versionsFields: buildVersionGlobalFields(this.payload.config, global, true)
|
|
101
|
+
}));
|
|
102
|
+
this.versions[global.slug] = this.connection.model(versionModelName, versionSchema, versionModelName);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
} finally{
|
|
106
|
+
schemaBuildContext.clear();
|
|
107
|
+
}
|
|
86
108
|
};
|
|
87
109
|
|
|
88
110
|
//# sourceMappingURL=init.js.map
|
package/dist/init.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/init.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { Init, SanitizedCollectionConfig } from 'payload'\n\nimport mongoose from 'mongoose'\nimport paginate from 'mongoose-paginate-v2'\nimport {\n buildVersionCollectionFields,\n buildVersionCompoundIndexes,\n buildVersionGlobalFields,\n} from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\nimport type { CollectionModel, GlobalModel } from './types.js'\n\nimport { buildCollectionSchema } from './models/buildCollectionSchema.js'\nimport { buildGlobalModel } from './models/buildGlobalModel.js'\nimport { buildSchema } from './models/buildSchema.js'\nimport { getBuildQueryPlugin } from './queries/getBuildQueryPlugin.js'\nimport { getDBName } from './utilities/getDBName.js'\n\nexport const init: Init = async function init(this: MongooseAdapter) {\n // Always create a scoped, **unopened** connection object\n // (no URI here; models compile per-connection and do not require an open socket)\n this.connection ??= mongoose.createConnection()\n\n if (this.afterCreateConnection) {\n await this.afterCreateConnection(this)\n }\n\n this.payload.config.collections.forEach((collection: SanitizedCollectionConfig) => {\n
|
|
1
|
+
{"version":3,"sources":["../src/init.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { Init, SanitizedCollectionConfig } from 'payload'\n\nimport mongoose from 'mongoose'\nimport paginate from 'mongoose-paginate-v2'\nimport {\n buildVersionCollectionFields,\n buildVersionCompoundIndexes,\n buildVersionGlobalFields,\n} from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\nimport type { CollectionModel, GlobalModel } from './types.js'\n\nimport { buildCollectionSchema } from './models/buildCollectionSchema.js'\nimport { buildGlobalModel } from './models/buildGlobalModel.js'\nimport { buildSchema } from './models/buildSchema.js'\nimport { createMongoSchemaBuildContext } from './models/schemaBuildContext.js'\nimport { getBuildQueryPlugin } from './queries/getBuildQueryPlugin.js'\nimport { getDBName } from './utilities/getDBName.js'\n\nexport const init: Init = async function init(this: MongooseAdapter) {\n // Always create a scoped, **unopened** connection object\n // (no URI here; models compile per-connection and do not require an open socket)\n this.connection ??= mongoose.createConnection()\n\n if (this.afterCreateConnection) {\n await this.afterCreateConnection(this)\n }\n\n const schemaBuildContext = createMongoSchemaBuildContext({ connection: this.connection })\n\n try {\n this.payload.config.collections.forEach((collection: SanitizedCollectionConfig) => {\n const schemaOptions = this.collectionsSchemaOptions?.[collection.slug]\n\n const schema = buildCollectionSchema({\n collection,\n payload: this.payload,\n schemaBuildContext,\n schemaOptions,\n })\n if (collection.versions) {\n const versionModelName = getDBName({ config: collection, versions: true })\n\n const versionCollectionFields = buildVersionCollectionFields(\n this.payload.config,\n collection,\n )\n\n const versionSchema = buildSchema({\n buildSchemaOptions: {\n disableUnique: true,\n draftsEnabled: true,\n indexSortableFields: this.payload.config.indexSortableFields,\n options: {\n minimize: false,\n timestamps: false,\n ...schemaOptions,\n },\n },\n compoundIndexes: buildVersionCompoundIndexes({ indexes: collection.sanitizedIndexes }),\n configFields: versionCollectionFields,\n isVersion: true,\n payload: this.payload,\n schemaBuildContext,\n schemaPath: `collection:${collection.slug}`,\n })\n\n versionSchema.plugin<any, PaginateOptions>(paginate, { useEstimatedCount: true }).plugin(\n getBuildQueryPlugin({\n collectionSlug: collection.slug,\n versionsFields: buildVersionCollectionFields(this.payload.config, collection, true),\n }),\n )\n\n const versionCollectionName =\n this.autoPluralization === true && !collection.dbName ? undefined : versionModelName\n\n this.versions[collection.slug] = this.connection.model(\n versionModelName,\n versionSchema,\n versionCollectionName,\n ) as unknown as CollectionModel\n }\n\n const modelName = getDBName({ config: collection })\n const collectionName =\n this.autoPluralization === true && !collection.dbName ? undefined : modelName\n\n this.collections[collection.slug] = this.connection.model<any>(\n modelName,\n schema,\n collectionName,\n ) as CollectionModel\n })\n\n this.globals = buildGlobalModel({ adapter: this, schemaBuildContext }) as GlobalModel\n\n this.payload.config.globals.forEach((global) => {\n if (global.versions) {\n const versionModelName = getDBName({ config: global, versions: true })\n\n const versionGlobalFields = buildVersionGlobalFields(this.payload.config, global)\n\n const versionSchema = buildSchema({\n buildSchemaOptions: {\n disableUnique: true,\n draftsEnabled: true,\n indexSortableFields: this.payload.config.indexSortableFields,\n options: {\n minimize: false,\n timestamps: false,\n },\n },\n configFields: versionGlobalFields,\n isVersion: true,\n payload: this.payload,\n schemaBuildContext,\n schemaPath: `global:${global.slug}`,\n })\n\n versionSchema.plugin<any, PaginateOptions>(paginate, { useEstimatedCount: true }).plugin(\n getBuildQueryPlugin({\n versionsFields: buildVersionGlobalFields(this.payload.config, global, true),\n }),\n )\n\n this.versions[global.slug] = this.connection.model<any>(\n versionModelName,\n versionSchema,\n versionModelName,\n ) as CollectionModel\n }\n })\n } finally {\n schemaBuildContext.clear()\n }\n}\n"],"names":["mongoose","paginate","buildVersionCollectionFields","buildVersionCompoundIndexes","buildVersionGlobalFields","buildCollectionSchema","buildGlobalModel","buildSchema","createMongoSchemaBuildContext","getBuildQueryPlugin","getDBName","init","connection","createConnection","afterCreateConnection","schemaBuildContext","payload","config","collections","forEach","collection","schemaOptions","collectionsSchemaOptions","slug","schema","versions","versionModelName","versionCollectionFields","versionSchema","buildSchemaOptions","disableUnique","draftsEnabled","indexSortableFields","options","minimize","timestamps","compoundIndexes","indexes","sanitizedIndexes","configFields","isVersion","schemaPath","plugin","useEstimatedCount","collectionSlug","versionsFields","versionCollectionName","autoPluralization","dbName","undefined","model","modelName","collectionName","globals","adapter","global","versionGlobalFields","clear"],"mappings":"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"}
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import type { Schema } from 'mongoose';
|
|
1
|
+
import type { Schema, SchemaOptions } from 'mongoose';
|
|
2
2
|
import type { Payload, SanitizedCollectionConfig } from 'payload';
|
|
3
|
-
|
|
3
|
+
import type { MongoSchemaBuildContext } from './schemaBuildContext.js';
|
|
4
|
+
export declare const buildCollectionSchema: ({ collection, payload, schemaBuildContext, schemaOptions, }: {
|
|
5
|
+
collection: SanitizedCollectionConfig;
|
|
6
|
+
payload: Payload;
|
|
7
|
+
schemaBuildContext: MongoSchemaBuildContext;
|
|
8
|
+
schemaOptions?: SchemaOptions;
|
|
9
|
+
}) => Schema;
|
|
4
10
|
//# 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;
|
|
1
|
+
{"version":3,"file":"buildCollectionSchema.d.ts","sourceRoot":"","sources":["../../src/models/buildCollectionSchema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAmB,MAAM,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACtE,OAAO,KAAK,EAAE,OAAO,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAA;AAIjE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAA;AAKtE,eAAO,MAAM,qBAAqB,gEAK/B;IACD,UAAU,EAAE,yBAAyB,CAAA;IACrC,OAAO,EAAE,OAAO,CAAA;IAChB,kBAAkB,EAAE,uBAAuB,CAAA;IAC3C,aAAa,CAAC,EAAE,aAAa,CAAA;CAC9B,KAAG,MAsCH,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import paginate from 'mongoose-paginate-v2';
|
|
2
2
|
import { getBuildQueryPlugin } from '../queries/getBuildQueryPlugin.js';
|
|
3
3
|
import { buildSchema } from './buildSchema.js';
|
|
4
|
-
export const buildCollectionSchema = (collection, payload, schemaOptions = {})=>{
|
|
4
|
+
export const buildCollectionSchema = ({ collection, payload, schemaBuildContext, schemaOptions = {} })=>{
|
|
5
5
|
const schema = buildSchema({
|
|
6
6
|
buildSchemaOptions: {
|
|
7
7
|
draftsEnabled: Boolean(typeof collection?.versions === 'object' && collection.versions.drafts),
|
|
@@ -15,7 +15,9 @@ export const buildCollectionSchema = (collection, payload, schemaOptions = {})=>
|
|
|
15
15
|
compoundIndexes: collection.sanitizedIndexes,
|
|
16
16
|
configFields: collection.fields,
|
|
17
17
|
flattenedFields: collection.flattenedFields,
|
|
18
|
-
payload
|
|
18
|
+
payload,
|
|
19
|
+
schemaBuildContext,
|
|
20
|
+
schemaPath: `collection:${collection.slug}`
|
|
19
21
|
});
|
|
20
22
|
if (Array.isArray(collection.upload.filenameCompoundIndex)) {
|
|
21
23
|
const indexDefinition = collection.upload.filenameCompoundIndex.reduce((acc, index)=>{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/models/buildCollectionSchema.ts"],"sourcesContent":["import type { PaginateOptions, Schema } from 'mongoose'\nimport type { Payload, SanitizedCollectionConfig } from 'payload'\n\nimport paginate from 'mongoose-paginate-v2'\n\nimport { getBuildQueryPlugin } from '../queries/getBuildQueryPlugin.js'\nimport { buildSchema } from './buildSchema.js'\n\nexport const buildCollectionSchema = (\n collection
|
|
1
|
+
{"version":3,"sources":["../../src/models/buildCollectionSchema.ts"],"sourcesContent":["import type { PaginateOptions, Schema, SchemaOptions } from 'mongoose'\nimport type { Payload, SanitizedCollectionConfig } from 'payload'\n\nimport paginate from 'mongoose-paginate-v2'\n\nimport type { MongoSchemaBuildContext } from './schemaBuildContext.js'\n\nimport { getBuildQueryPlugin } from '../queries/getBuildQueryPlugin.js'\nimport { buildSchema } from './buildSchema.js'\n\nexport const buildCollectionSchema = ({\n collection,\n payload,\n schemaBuildContext,\n schemaOptions = {},\n}: {\n collection: SanitizedCollectionConfig\n payload: Payload\n schemaBuildContext: MongoSchemaBuildContext\n schemaOptions?: SchemaOptions\n}): Schema => {\n const schema = buildSchema({\n buildSchemaOptions: {\n draftsEnabled: Boolean(\n typeof collection?.versions === 'object' && collection.versions.drafts,\n ),\n indexSortableFields: payload.config.indexSortableFields,\n options: {\n minimize: false,\n timestamps: collection.timestamps !== false,\n ...schemaOptions,\n },\n },\n compoundIndexes: collection.sanitizedIndexes,\n configFields: collection.fields,\n flattenedFields: collection.flattenedFields,\n payload,\n schemaBuildContext,\n schemaPath: `collection:${collection.slug}`,\n })\n\n if (Array.isArray(collection.upload.filenameCompoundIndex)) {\n const indexDefinition = collection.upload.filenameCompoundIndex.reduce<Record<string, 1>>(\n (acc, index) => {\n acc[index] = 1\n return acc\n },\n {},\n )\n\n schema.index(indexDefinition, { unique: true })\n }\n\n schema\n .plugin<any, PaginateOptions>(paginate, { useEstimatedCount: true })\n .plugin(getBuildQueryPlugin({ collectionSlug: collection.slug }))\n\n return schema\n}\n"],"names":["paginate","getBuildQueryPlugin","buildSchema","buildCollectionSchema","collection","payload","schemaBuildContext","schemaOptions","schema","buildSchemaOptions","draftsEnabled","Boolean","versions","drafts","indexSortableFields","config","options","minimize","timestamps","compoundIndexes","sanitizedIndexes","configFields","fields","flattenedFields","schemaPath","slug","Array","isArray","upload","filenameCompoundIndex","indexDefinition","reduce","acc","index","unique","plugin","useEstimatedCount","collectionSlug"],"mappings":"AAGA,OAAOA,cAAc,uBAAsB;AAI3C,SAASC,mBAAmB,QAAQ,oCAAmC;AACvE,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,wBAAwB,CAAC,EACpCC,UAAU,EACVC,OAAO,EACPC,kBAAkB,EAClBC,gBAAgB,CAAC,CAAC,EAMnB;IACC,MAAMC,SAASN,YAAY;QACzBO,oBAAoB;YAClBC,eAAeC,QACb,OAAOP,YAAYQ,aAAa,YAAYR,WAAWQ,QAAQ,CAACC,MAAM;YAExEC,qBAAqBT,QAAQU,MAAM,CAACD,mBAAmB;YACvDE,SAAS;gBACPC,UAAU;gBACVC,YAAYd,WAAWc,UAAU,KAAK;gBACtC,GAAGX,aAAa;YAClB;QACF;QACAY,iBAAiBf,WAAWgB,gBAAgB;QAC5CC,cAAcjB,WAAWkB,MAAM;QAC/BC,iBAAiBnB,WAAWmB,eAAe;QAC3ClB;QACAC;QACAkB,YAAY,CAAC,WAAW,EAAEpB,WAAWqB,IAAI,EAAE;IAC7C;IAEA,IAAIC,MAAMC,OAAO,CAACvB,WAAWwB,MAAM,CAACC,qBAAqB,GAAG;QAC1D,MAAMC,kBAAkB1B,WAAWwB,MAAM,CAACC,qBAAqB,CAACE,MAAM,CACpE,CAACC,KAAKC;YACJD,GAAG,CAACC,MAAM,GAAG;YACb,OAAOD;QACT,GACA,CAAC;QAGHxB,OAAOyB,KAAK,CAACH,iBAAiB;YAAEI,QAAQ;QAAK;IAC/C;IAEA1B,OACG2B,MAAM,CAAuBnC,UAAU;QAAEoC,mBAAmB;IAAK,GACjED,MAAM,CAAClC,oBAAoB;QAAEoC,gBAAgBjC,WAAWqB,IAAI;IAAC;IAEhE,OAAOjB;AACT,EAAC"}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import type { MongooseAdapter } from '../index.js';
|
|
2
2
|
import type { GlobalModel } from '../types.js';
|
|
3
|
-
|
|
3
|
+
import type { MongoSchemaBuildContext } from './schemaBuildContext.js';
|
|
4
|
+
export declare const buildGlobalModel: ({ adapter, schemaBuildContext, }: {
|
|
5
|
+
adapter: MongooseAdapter;
|
|
6
|
+
schemaBuildContext: MongoSchemaBuildContext;
|
|
7
|
+
}) => GlobalModel | null;
|
|
4
8
|
//# sourceMappingURL=buildGlobalModel.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildGlobalModel.d.ts","sourceRoot":"","sources":["../../src/models/buildGlobalModel.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"buildGlobalModel.d.ts","sourceRoot":"","sources":["../../src/models/buildGlobalModel.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAA;AAKtE,eAAO,MAAM,gBAAgB,qCAG1B;IACD,OAAO,EAAE,eAAe,CAAA;IACxB,kBAAkB,EAAE,uBAAuB,CAAA;CAC5C,KAAG,WAAW,GAAG,IAkCjB,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import mongoose from 'mongoose';
|
|
2
2
|
import { getBuildQueryPlugin } from '../queries/getBuildQueryPlugin.js';
|
|
3
3
|
import { buildSchema } from './buildSchema.js';
|
|
4
|
-
export const buildGlobalModel = (adapter)=>{
|
|
4
|
+
export const buildGlobalModel = ({ adapter, schemaBuildContext })=>{
|
|
5
5
|
if (adapter.payload.config.globals && adapter.payload.config.globals.length > 0) {
|
|
6
6
|
const globalsSchema = new mongoose.Schema({}, {
|
|
7
7
|
discriminatorKey: 'globalType',
|
|
@@ -18,7 +18,9 @@ export const buildGlobalModel = (adapter)=>{
|
|
|
18
18
|
}
|
|
19
19
|
},
|
|
20
20
|
configFields: globalConfig.fields,
|
|
21
|
-
payload: adapter.payload
|
|
21
|
+
payload: adapter.payload,
|
|
22
|
+
schemaBuildContext,
|
|
23
|
+
schemaPath: `global:${globalConfig.slug}`
|
|
22
24
|
});
|
|
23
25
|
Globals.discriminator(globalConfig.slug, globalSchema);
|
|
24
26
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/models/buildGlobalModel.ts"],"sourcesContent":["import mongoose from 'mongoose'\n\nimport type { MongooseAdapter } from '../index.js'\nimport type { GlobalModel } from '../types.js'\n\nimport { getBuildQueryPlugin } from '../queries/getBuildQueryPlugin.js'\nimport { buildSchema } from './buildSchema.js'\n\nexport const buildGlobalModel = (adapter: MongooseAdapter): GlobalModel | null => {\n if (adapter.payload.config.globals && adapter.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 = adapter.connection.model(\n 'globals',\n globalsSchema,\n 'globals',\n ) as unknown as GlobalModel\n\n Object.values(adapter.payload.config.globals).forEach((globalConfig) => {\n const globalSchema = buildSchema({\n buildSchemaOptions: {\n options: {\n minimize: false,\n },\n },\n configFields: globalConfig.fields,\n payload: adapter.payload,\n })\n Globals.discriminator(globalConfig.slug, globalSchema)\n })\n\n return Globals\n }\n\n return null\n}\n"],"names":["mongoose","getBuildQueryPlugin","buildSchema","buildGlobalModel","adapter","payload","config","globals","length","globalsSchema","Schema","discriminatorKey","minimize","timestamps","plugin","Globals","connection","model","Object","values","forEach","globalConfig","globalSchema","buildSchemaOptions","options","configFields","fields","
|
|
1
|
+
{"version":3,"sources":["../../src/models/buildGlobalModel.ts"],"sourcesContent":["import mongoose from 'mongoose'\n\nimport type { MongooseAdapter } from '../index.js'\nimport type { GlobalModel } from '../types.js'\nimport type { MongoSchemaBuildContext } from './schemaBuildContext.js'\n\nimport { getBuildQueryPlugin } from '../queries/getBuildQueryPlugin.js'\nimport { buildSchema } from './buildSchema.js'\n\nexport const buildGlobalModel = ({\n adapter,\n schemaBuildContext,\n}: {\n adapter: MongooseAdapter\n schemaBuildContext: MongoSchemaBuildContext\n}): GlobalModel | null => {\n if (adapter.payload.config.globals && adapter.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 = adapter.connection.model(\n 'globals',\n globalsSchema,\n 'globals',\n ) as unknown as GlobalModel\n\n Object.values(adapter.payload.config.globals).forEach((globalConfig) => {\n const globalSchema = buildSchema({\n buildSchemaOptions: {\n options: {\n minimize: false,\n },\n },\n configFields: globalConfig.fields,\n payload: adapter.payload,\n schemaBuildContext,\n schemaPath: `global:${globalConfig.slug}`,\n })\n Globals.discriminator(globalConfig.slug, globalSchema)\n })\n\n return Globals\n }\n\n return null\n}\n"],"names":["mongoose","getBuildQueryPlugin","buildSchema","buildGlobalModel","adapter","schemaBuildContext","payload","config","globals","length","globalsSchema","Schema","discriminatorKey","minimize","timestamps","plugin","Globals","connection","model","Object","values","forEach","globalConfig","globalSchema","buildSchemaOptions","options","configFields","fields","schemaPath","slug","discriminator"],"mappings":"AAAA,OAAOA,cAAc,WAAU;AAM/B,SAASC,mBAAmB,QAAQ,oCAAmC;AACvE,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,mBAAmB,CAAC,EAC/BC,OAAO,EACPC,kBAAkB,EAInB;IACC,IAAID,QAAQE,OAAO,CAACC,MAAM,CAACC,OAAO,IAAIJ,QAAQE,OAAO,CAACC,MAAM,CAACC,OAAO,CAACC,MAAM,GAAG,GAAG;QAC/E,MAAMC,gBAAgB,IAAIV,SAASW,MAAM,CACvC,CAAC,GACD;YAAEC,kBAAkB;YAAcC,UAAU;YAAOC,YAAY;QAAK;QAGtEJ,cAAcK,MAAM,CAACd;QAErB,MAAMe,UAAUZ,QAAQa,UAAU,CAACC,KAAK,CACtC,WACAR,eACA;QAGFS,OAAOC,MAAM,CAAChB,QAAQE,OAAO,CAACC,MAAM,CAACC,OAAO,EAAEa,OAAO,CAAC,CAACC;YACrD,MAAMC,eAAerB,YAAY;gBAC/BsB,oBAAoB;oBAClBC,SAAS;wBACPZ,UAAU;oBACZ;gBACF;gBACAa,cAAcJ,aAAaK,MAAM;gBACjCrB,SAASF,QAAQE,OAAO;gBACxBD;gBACAuB,YAAY,CAAC,OAAO,EAAEN,aAAaO,IAAI,EAAE;YAC3C;YACAb,QAAQc,aAAa,CAACR,aAAaO,IAAI,EAAEN;QAC3C;QAEA,OAAOP;IACT;IAEA,OAAO;AACT,EAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Schema, SchemaOptions } from 'mongoose';
|
|
2
2
|
import { type Field, type FlattenedField, type Payload, type SanitizedCompoundIndex } from 'payload';
|
|
3
|
+
import type { MongoSchemaBuildContext } from './schemaBuildContext.js';
|
|
3
4
|
export type BuildSchemaOptions = {
|
|
4
5
|
allowIDField?: boolean;
|
|
5
6
|
disableUnique?: boolean;
|
|
@@ -12,7 +13,10 @@ export declare const buildSchema: (args: {
|
|
|
12
13
|
compoundIndexes?: SanitizedCompoundIndex[];
|
|
13
14
|
configFields: Field[];
|
|
14
15
|
flattenedFields?: FlattenedField[];
|
|
16
|
+
isVersion?: boolean;
|
|
15
17
|
parentIsLocalized?: boolean;
|
|
16
18
|
payload: Payload;
|
|
19
|
+
schemaBuildContext?: MongoSchemaBuildContext;
|
|
20
|
+
schemaPath?: string;
|
|
17
21
|
}) => Schema;
|
|
18
22
|
//# 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;AAGtF,OAAO,EAQL,KAAK,KAAK,EAEV,KAAK,cAAc,EAKnB,KAAK,OAAO,EAMZ,KAAK,sBAAsB,EAQ5B,MAAM,SAAS,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,EAQL,KAAK,KAAK,EAEV,KAAK,cAAc,EAKnB,KAAK,OAAO,EAMZ,KAAK,sBAAsB,EAQ5B,MAAM,SAAS,CAAA;AAUhB,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAA;AAItE,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;AAyFD,eAAO,MAAM,WAAW,SAAU;IAChC,kBAAkB,EAAE,kBAAkB,CAAA;IACtC,eAAe,CAAC,EAAE,sBAAsB,EAAE,CAAA;IAC1C,YAAY,EAAE,KAAK,EAAE,CAAA;IACrB,eAAe,CAAC,EAAE,cAAc,EAAE,CAAA;IAClC,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B,OAAO,EAAE,OAAO,CAAA;IAChB,kBAAkB,CAAC,EAAE,uBAAuB,CAAA;IAC5C,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB,KAAG,MAkFH,CAAA"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import mongoose from 'mongoose';
|
|
2
|
+
import { createSchemaBuildContext } from 'payload/internal';
|
|
2
3
|
import { fieldAffectsData, fieldIsPresentationalOnly, fieldIsVirtual, fieldShouldBeLocalized, tabHasName } from 'payload/shared';
|
|
4
|
+
import { getBlockSchemaCacheKey } from './schemaBuildContext.js';
|
|
3
5
|
/**
|
|
4
6
|
* get a field's defaultValue only if defined and not dynamic so that it can be set on the field schema
|
|
5
7
|
* @param field
|
|
@@ -42,6 +44,12 @@ const localizeSchema = (entity, schema, localization, parentIsLocalized)=>{
|
|
|
42
44
|
};
|
|
43
45
|
export const buildSchema = (args)=>{
|
|
44
46
|
const { buildSchemaOptions = {}, configFields, flattenedFields, parentIsLocalized, payload } = args;
|
|
47
|
+
const schemaBuildContext = args.schemaBuildContext ?? createSchemaBuildContext();
|
|
48
|
+
const schemaBuildState = {
|
|
49
|
+
context: schemaBuildContext,
|
|
50
|
+
isVersion: args.isVersion ?? false,
|
|
51
|
+
path: args.schemaPath ?? 'schema'
|
|
52
|
+
};
|
|
45
53
|
const { allowIDField, options } = buildSchemaOptions;
|
|
46
54
|
let fields = {};
|
|
47
55
|
let schemaFields = configFields;
|
|
@@ -64,7 +72,7 @@ export const buildSchema = (args)=>{
|
|
|
64
72
|
if (!fieldIsPresentationalOnly(field)) {
|
|
65
73
|
const addFieldSchema = getSchemaGenerator(field.type);
|
|
66
74
|
if (addFieldSchema) {
|
|
67
|
-
addFieldSchema(field, schema, payload, buildSchemaOptions, parentIsLocalized ?? false);
|
|
75
|
+
addFieldSchema(field, schema, payload, buildSchemaOptions, parentIsLocalized ?? false, schemaBuildState);
|
|
68
76
|
}
|
|
69
77
|
}
|
|
70
78
|
});
|
|
@@ -87,7 +95,7 @@ export const buildSchema = (args)=>{
|
|
|
87
95
|
}
|
|
88
96
|
return schema;
|
|
89
97
|
};
|
|
90
|
-
const array = (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
|
|
98
|
+
const array = (field, schema, payload, buildSchemaOptions, parentIsLocalized, schemaBuildState)=>{
|
|
91
99
|
const baseSchema = {
|
|
92
100
|
...formatBaseSchema({
|
|
93
101
|
buildSchemaOptions,
|
|
@@ -107,8 +115,11 @@ const array = (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
|
|
|
107
115
|
}
|
|
108
116
|
},
|
|
109
117
|
configFields: field.fields,
|
|
118
|
+
isVersion: schemaBuildState.isVersion,
|
|
110
119
|
parentIsLocalized: parentIsLocalized || field.localized,
|
|
111
|
-
payload
|
|
120
|
+
payload,
|
|
121
|
+
schemaBuildContext: schemaBuildState.context,
|
|
122
|
+
schemaPath: `${schemaBuildState.path}/field:${field.name}`
|
|
112
123
|
})
|
|
113
124
|
]
|
|
114
125
|
};
|
|
@@ -116,7 +127,7 @@ const array = (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
|
|
|
116
127
|
[field.name]: localizeSchema(field, baseSchema, payload.config.localization, parentIsLocalized)
|
|
117
128
|
});
|
|
118
129
|
};
|
|
119
|
-
const blocks = (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
|
|
130
|
+
const blocks = (field, schema, payload, buildSchemaOptions, parentIsLocalized, schemaBuildState)=>{
|
|
120
131
|
const fieldSchema = {
|
|
121
132
|
...formatBaseSchema({
|
|
122
133
|
buildSchemaOptions,
|
|
@@ -134,22 +145,43 @@ const blocks = (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>
|
|
|
134
145
|
[field.name]: localizeSchema(field, fieldSchema, payload.config.localization, parentIsLocalized)
|
|
135
146
|
});
|
|
136
147
|
(field.blockReferences ?? field.blocks).forEach((blockItem)=>{
|
|
137
|
-
const blockSchema = new mongoose.Schema({}, {
|
|
138
|
-
_id: false,
|
|
139
|
-
id: false
|
|
140
|
-
});
|
|
141
148
|
const block = typeof blockItem === 'string' ? payload.blocks[blockItem] : blockItem;
|
|
142
149
|
if (!block) {
|
|
143
150
|
return;
|
|
144
151
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
152
|
+
const isLocalized = Boolean(parentIsLocalized || field.localized);
|
|
153
|
+
const isReference = typeof blockItem === 'string';
|
|
154
|
+
const fieldPath = `${schemaBuildState.path}/field:${field.name}`;
|
|
155
|
+
const blockSchema = schemaBuildState.context.getOrCreate({
|
|
156
|
+
build: ()=>{
|
|
157
|
+
const template = new mongoose.Schema({}, {
|
|
158
|
+
_id: false,
|
|
159
|
+
id: false
|
|
160
|
+
});
|
|
161
|
+
block.fields.forEach((blockField)=>{
|
|
162
|
+
if (fieldIsVirtual(blockField)) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
const addFieldSchema = getSchemaGenerator(blockField.type);
|
|
166
|
+
if (addFieldSchema) {
|
|
167
|
+
addFieldSchema(blockField, template, payload, buildSchemaOptions, isLocalized, {
|
|
168
|
+
context: schemaBuildState.context,
|
|
169
|
+
isVersion: schemaBuildState.isVersion,
|
|
170
|
+
path: isReference ? `block:${block.slug}` : `${fieldPath}/block:${block.slug}`
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
return template;
|
|
175
|
+
},
|
|
176
|
+
cacheKey: getBlockSchemaCacheKey({
|
|
177
|
+
blockSlug: block.slug,
|
|
178
|
+
buildSchemaOptions,
|
|
179
|
+
fieldPath,
|
|
180
|
+
isLocalized,
|
|
181
|
+
isReference,
|
|
182
|
+
isVersion: schemaBuildState.isVersion
|
|
183
|
+
}),
|
|
184
|
+
definition: block
|
|
153
185
|
});
|
|
154
186
|
if (fieldShouldBeLocalized({
|
|
155
187
|
field,
|
|
@@ -191,14 +223,14 @@ const code = (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
|
|
|
191
223
|
[field.name]: localizeSchema(field, baseSchema, payload.config.localization, parentIsLocalized)
|
|
192
224
|
});
|
|
193
225
|
};
|
|
194
|
-
const collapsible = (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
|
|
226
|
+
const collapsible = (field, schema, payload, buildSchemaOptions, parentIsLocalized, schemaBuildState)=>{
|
|
195
227
|
field.fields.forEach((subField)=>{
|
|
196
228
|
if (fieldIsVirtual(subField)) {
|
|
197
229
|
return;
|
|
198
230
|
}
|
|
199
231
|
const addFieldSchema = getSchemaGenerator(subField.type);
|
|
200
232
|
if (addFieldSchema) {
|
|
201
|
-
addFieldSchema(subField, schema, payload, buildSchemaOptions, parentIsLocalized);
|
|
233
|
+
addFieldSchema(subField, schema, payload, buildSchemaOptions, parentIsLocalized, schemaBuildState);
|
|
202
234
|
}
|
|
203
235
|
});
|
|
204
236
|
};
|
|
@@ -228,7 +260,7 @@ const email = (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
|
|
|
228
260
|
[field.name]: localizeSchema(field, baseSchema, payload.config.localization, parentIsLocalized)
|
|
229
261
|
});
|
|
230
262
|
};
|
|
231
|
-
const group = (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
|
|
263
|
+
const group = (field, schema, payload, buildSchemaOptions, parentIsLocalized, schemaBuildState)=>{
|
|
232
264
|
if (fieldAffectsData(field)) {
|
|
233
265
|
const formattedBaseSchema = formatBaseSchema({
|
|
234
266
|
buildSchemaOptions,
|
|
@@ -251,8 +283,11 @@ const group = (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
|
|
|
251
283
|
}
|
|
252
284
|
},
|
|
253
285
|
configFields: field.fields,
|
|
286
|
+
isVersion: schemaBuildState.isVersion,
|
|
254
287
|
parentIsLocalized: parentIsLocalized || field.localized,
|
|
255
|
-
payload
|
|
288
|
+
payload,
|
|
289
|
+
schemaBuildContext: schemaBuildState.context,
|
|
290
|
+
schemaPath: `${schemaBuildState.path}/field:${field.name}`
|
|
256
291
|
})
|
|
257
292
|
};
|
|
258
293
|
schema.add({
|
|
@@ -265,7 +300,7 @@ const group = (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
|
|
|
265
300
|
}
|
|
266
301
|
const addFieldSchema = getSchemaGenerator(subField.type);
|
|
267
302
|
if (addFieldSchema) {
|
|
268
|
-
addFieldSchema(subField, schema, payload, buildSchemaOptions, (parentIsLocalized || field.localized) ?? false);
|
|
303
|
+
addFieldSchema(subField, schema, payload, buildSchemaOptions, (parentIsLocalized || field.localized) ?? false, schemaBuildState);
|
|
269
304
|
}
|
|
270
305
|
});
|
|
271
306
|
}
|
|
@@ -482,14 +517,14 @@ const richText = (field, schema, payload, buildSchemaOptions, parentIsLocalized)
|
|
|
482
517
|
[field.name]: localizeSchema(field, baseSchema, payload.config.localization, parentIsLocalized)
|
|
483
518
|
});
|
|
484
519
|
};
|
|
485
|
-
const row = (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
|
|
520
|
+
const row = (field, schema, payload, buildSchemaOptions, parentIsLocalized, schemaBuildState)=>{
|
|
486
521
|
field.fields.forEach((subField)=>{
|
|
487
522
|
if (fieldIsVirtual(subField)) {
|
|
488
523
|
return;
|
|
489
524
|
}
|
|
490
525
|
const addFieldSchema = getSchemaGenerator(subField.type);
|
|
491
526
|
if (addFieldSchema) {
|
|
492
|
-
addFieldSchema(subField, schema, payload, buildSchemaOptions, parentIsLocalized);
|
|
527
|
+
addFieldSchema(subField, schema, payload, buildSchemaOptions, parentIsLocalized, schemaBuildState);
|
|
493
528
|
}
|
|
494
529
|
});
|
|
495
530
|
};
|
|
@@ -518,7 +553,7 @@ const select = (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>
|
|
|
518
553
|
] : baseSchema, payload.config.localization, parentIsLocalized)
|
|
519
554
|
});
|
|
520
555
|
};
|
|
521
|
-
const tabs = (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
|
|
556
|
+
const tabs = (field, schema, payload, buildSchemaOptions, parentIsLocalized, schemaBuildState)=>{
|
|
522
557
|
field.tabs.forEach((tab)=>{
|
|
523
558
|
if (tabHasName(tab)) {
|
|
524
559
|
if (fieldIsVirtual(tab)) {
|
|
@@ -536,8 +571,11 @@ const tabs = (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
|
|
|
536
571
|
}
|
|
537
572
|
},
|
|
538
573
|
configFields: tab.fields,
|
|
574
|
+
isVersion: schemaBuildState.isVersion,
|
|
539
575
|
parentIsLocalized: parentIsLocalized || tab.localized,
|
|
540
|
-
payload
|
|
576
|
+
payload,
|
|
577
|
+
schemaBuildContext: schemaBuildState.context,
|
|
578
|
+
schemaPath: `${schemaBuildState.path}/tab:${tab.name}`
|
|
541
579
|
})
|
|
542
580
|
};
|
|
543
581
|
schema.add({
|
|
@@ -550,7 +588,7 @@ const tabs = (field, schema, payload, buildSchemaOptions, parentIsLocalized)=>{
|
|
|
550
588
|
}
|
|
551
589
|
const addFieldSchema = getSchemaGenerator(subField.type);
|
|
552
590
|
if (addFieldSchema) {
|
|
553
|
-
addFieldSchema(subField, schema, payload, buildSchemaOptions, (parentIsLocalized || tab.localized) ?? false);
|
|
591
|
+
addFieldSchema(subField, schema, payload, buildSchemaOptions, (parentIsLocalized || tab.localized) ?? false, schemaBuildState);
|
|
554
592
|
}
|
|
555
593
|
});
|
|
556
594
|
}
|