@payloadcms/db-mongodb 3.54.0-internal.84621da → 3.54.0-internal.90cf7d5
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 -2
- package/dist/connect.js.map +1 -1
- package/dist/destroy.d.ts.map +1 -1
- package/dist/destroy.js +4 -3
- package/dist/destroy.js.map +1 -1
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +7 -4
- package/dist/init.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 +5 -5
- package/dist/models/buildGlobalModel.js.map +1 -1
- package/package.json +3 -3
package/dist/connect.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../src/connect.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAOtC,eAAO,MAAM,OAAO,EAAE,
|
1
|
+
{"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../src/connect.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAOtC,eAAO,MAAM,OAAO,EAAE,OAwGrB,CAAA"}
|
package/dist/connect.js
CHANGED
@@ -20,7 +20,10 @@ export const connect = async function connect(options = {
|
|
20
20
|
connectionOptions.autoIndex = false;
|
21
21
|
}
|
22
22
|
try {
|
23
|
-
this.connection
|
23
|
+
if (!this.connection) {
|
24
|
+
this.connection = await mongoose.createConnection(urlToConnect, connectionOptions).asPromise();
|
25
|
+
}
|
26
|
+
await this.connection.openUri(urlToConnect, connectionOptions);
|
24
27
|
if (this.useAlternativeDropDatabase) {
|
25
28
|
if (this.connection.db) {
|
26
29
|
// Firestore doesn't support dropDatabase, so we monkey patch
|
@@ -52,7 +55,7 @@ export const connect = async function connect(options = {
|
|
52
55
|
if (!hotReload) {
|
53
56
|
if (process.env.PAYLOAD_DROP_DATABASE === 'true') {
|
54
57
|
this.payload.logger.info('---- DROPPING DATABASE ----');
|
55
|
-
await
|
58
|
+
await this.connection.dropDatabase();
|
56
59
|
this.payload.logger.info('---- DROPPED DATABASE ----');
|
57
60
|
}
|
58
61
|
}
|
package/dist/connect.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/connect.ts"],"sourcesContent":["import type { ConnectOptions } from 'mongoose'\nimport type { Connect } from 'payload'\n\nimport mongoose from 'mongoose'\nimport { defaultBeginTransaction } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nexport const connect: Connect = async function connect(\n this: MongooseAdapter,\n options = {\n hotReload: false,\n },\n) {\n const { hotReload } = options\n\n if (this.url === false) {\n return\n }\n\n if (typeof this.url !== 'string') {\n throw new Error('Error: missing MongoDB connection URL.')\n }\n\n const urlToConnect = this.url\n\n const connectionOptions: { useFacet: undefined } & ConnectOptions = {\n autoIndex: true,\n ...this.connectOptions,\n useFacet: undefined,\n }\n\n if (hotReload) {\n connectionOptions.autoIndex = false\n }\n\n try {\n this.connection =
|
1
|
+
{"version":3,"sources":["../src/connect.ts"],"sourcesContent":["import type { ConnectOptions } from 'mongoose'\nimport type { Connect } from 'payload'\n\nimport mongoose from 'mongoose'\nimport { defaultBeginTransaction } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nexport const connect: Connect = async function connect(\n this: MongooseAdapter,\n options = {\n hotReload: false,\n },\n) {\n const { hotReload } = options\n\n if (this.url === false) {\n return\n }\n\n if (typeof this.url !== 'string') {\n throw new Error('Error: missing MongoDB connection URL.')\n }\n\n const urlToConnect = this.url\n\n const connectionOptions: { useFacet: undefined } & ConnectOptions = {\n autoIndex: true,\n ...this.connectOptions,\n useFacet: undefined,\n }\n\n if (hotReload) {\n connectionOptions.autoIndex = false\n }\n\n try {\n if (!this.connection) {\n this.connection = await mongoose.createConnection(urlToConnect, connectionOptions).asPromise()\n }\n\n await this.connection.openUri(urlToConnect, connectionOptions)\n\n if (this.useAlternativeDropDatabase) {\n if (this.connection.db) {\n // Firestore doesn't support dropDatabase, so we monkey patch\n // dropDatabase to delete all documents from all collections instead\n this.connection.db.dropDatabase = async function (): Promise<boolean> {\n const existingCollections = await this.listCollections().toArray()\n await Promise.all(\n existingCollections.map(async (collectionInfo) => {\n const collection = this.collection(collectionInfo.name)\n await collection.deleteMany({})\n }),\n )\n return true\n }\n this.connection.dropDatabase = async function () {\n await this.db?.dropDatabase()\n }\n }\n }\n\n // If we are running a replica set with MongoDB Memory Server,\n // wait until the replica set elects a primary before proceeding\n if (this.mongoMemoryServer) {\n this.payload.logger.info(\n 'Waiting for MongoDB Memory Server replica set to elect a primary...',\n )\n await new Promise((resolve) => setTimeout(resolve, 2000))\n }\n\n const client = this.connection.getClient()\n\n if (!client.options.replicaSet) {\n this.transactionOptions = false\n this.beginTransaction = defaultBeginTransaction()\n }\n\n if (!hotReload) {\n if (process.env.PAYLOAD_DROP_DATABASE === 'true') {\n this.payload.logger.info('---- DROPPING DATABASE ----')\n await this.connection.dropDatabase()\n\n this.payload.logger.info('---- DROPPED DATABASE ----')\n }\n }\n\n if (this.ensureIndexes) {\n await Promise.all(\n this.payload.config.collections.map(async (coll) => {\n await this.collections[coll.slug]?.ensureIndexes()\n }),\n )\n }\n\n if (process.env.NODE_ENV === 'production' && this.prodMigrations) {\n await this.migrate({ migrations: this.prodMigrations })\n }\n } catch (err) {\n let msg = `Error: cannot connect to MongoDB.`\n\n if (typeof err === 'object' && err && 'message' in err && typeof err.message === 'string') {\n msg = `${msg} Details: ${err.message}`\n }\n\n this.payload.logger.error({\n err,\n msg,\n })\n process.exit(1)\n }\n}\n"],"names":["mongoose","defaultBeginTransaction","connect","options","hotReload","url","Error","urlToConnect","connectionOptions","autoIndex","connectOptions","useFacet","undefined","connection","createConnection","asPromise","openUri","useAlternativeDropDatabase","db","dropDatabase","existingCollections","listCollections","toArray","Promise","all","map","collectionInfo","collection","name","deleteMany","mongoMemoryServer","payload","logger","info","resolve","setTimeout","client","getClient","replicaSet","transactionOptions","beginTransaction","process","env","PAYLOAD_DROP_DATABASE","ensureIndexes","config","collections","coll","slug","NODE_ENV","prodMigrations","migrate","migrations","err","msg","message","error","exit"],"mappings":"AAGA,OAAOA,cAAc,WAAU;AAC/B,SAASC,uBAAuB,QAAQ,UAAS;AAIjD,OAAO,MAAMC,UAAmB,eAAeA,QAE7CC,UAAU;IACRC,WAAW;AACb,CAAC;IAED,MAAM,EAAEA,SAAS,EAAE,GAAGD;IAEtB,IAAI,IAAI,CAACE,GAAG,KAAK,OAAO;QACtB;IACF;IAEA,IAAI,OAAO,IAAI,CAACA,GAAG,KAAK,UAAU;QAChC,MAAM,IAAIC,MAAM;IAClB;IAEA,MAAMC,eAAe,IAAI,CAACF,GAAG;IAE7B,MAAMG,oBAA8D;QAClEC,WAAW;QACX,GAAG,IAAI,CAACC,cAAc;QACtBC,UAAUC;IACZ;IAEA,IAAIR,WAAW;QACbI,kBAAkBC,SAAS,GAAG;IAChC;IAEA,IAAI;QACF,IAAI,CAAC,IAAI,CAACI,UAAU,EAAE;YACpB,IAAI,CAACA,UAAU,GAAG,MAAMb,SAASc,gBAAgB,CAACP,cAAcC,mBAAmBO,SAAS;QAC9F;QAEA,MAAM,IAAI,CAACF,UAAU,CAACG,OAAO,CAACT,cAAcC;QAE5C,IAAI,IAAI,CAACS,0BAA0B,EAAE;YACnC,IAAI,IAAI,CAACJ,UAAU,CAACK,EAAE,EAAE;gBACtB,6DAA6D;gBAC7D,oEAAoE;gBACpE,IAAI,CAACL,UAAU,CAACK,EAAE,CAACC,YAAY,GAAG;oBAChC,MAAMC,sBAAsB,MAAM,IAAI,CAACC,eAAe,GAAGC,OAAO;oBAChE,MAAMC,QAAQC,GAAG,CACfJ,oBAAoBK,GAAG,CAAC,OAAOC;wBAC7B,MAAMC,aAAa,IAAI,CAACA,UAAU,CAACD,eAAeE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AI,OAAOD,QAAQ,YAAYA,OAAO,aAAaA,OAAO,OAAOA,IAAIE,OAAO,KAAK,UAAU;YACzFD,MAAM,GAAGA,IAAI,UAAU,EAAED,IAAIE,OAAO,EAAE;QACxC;QAEA,IAAI,CAACxB,OAAO,CAACC,MAAM,CAACwB,KAAK,CAAC;YACxBH;YACAC;QACF;QACAb,QAAQgB,IAAI,CAAC;IACf;AACF,EAAC"}
|
package/dist/destroy.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"destroy.d.ts","sourceRoot":"","sources":["../src/destroy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;
|
1
|
+
{"version":3,"file":"destroy.d.ts","sourceRoot":"","sources":["../src/destroy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAItC,eAAO,MAAM,OAAO,EAAE,OAMrB,CAAA"}
|
package/dist/destroy.js
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
import mongoose from 'mongoose';
|
2
1
|
export const destroy = async function destroy() {
|
3
|
-
await
|
4
|
-
Object.keys(
|
2
|
+
await this.connection.close();
|
3
|
+
for (const name of Object.keys(this.connection.models)){
|
4
|
+
this.connection.deleteModel(name);
|
5
|
+
}
|
5
6
|
};
|
6
7
|
|
7
8
|
//# sourceMappingURL=destroy.js.map
|
package/dist/destroy.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/destroy.ts"],"sourcesContent":["import type { Destroy } from 'payload'\n\nimport
|
1
|
+
{"version":3,"sources":["../src/destroy.ts"],"sourcesContent":["import type { Destroy } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nexport const destroy: Destroy = async function destroy(this: MongooseAdapter) {\n await this.connection.close()\n\n for (const name of Object.keys(this.connection.models)) {\n this.connection.deleteModel(name)\n }\n}\n"],"names":["destroy","connection","close","name","Object","keys","models","deleteModel"],"mappings":"AAIA,OAAO,MAAMA,UAAmB,eAAeA;IAC7C,MAAM,IAAI,CAACC,UAAU,CAACC,KAAK;IAE3B,KAAK,MAAMC,QAAQC,OAAOC,IAAI,CAAC,IAAI,CAACJ,UAAU,CAACK,MAAM,EAAG;QACtD,IAAI,CAACL,UAAU,CAACM,WAAW,CAACJ;IAC9B;AACF,EAAC"}
|
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;AAmB9D,eAAO,MAAM,IAAI,EAAE,
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAA6B,MAAM,SAAS,CAAA;AAmB9D,eAAO,MAAM,IAAI,EAAE,IA6FlB,CAAA"}
|
package/dist/init.js
CHANGED
@@ -7,6 +7,9 @@ import { buildSchema } from './models/buildSchema.js';
|
|
7
7
|
import { getBuildQueryPlugin } from './queries/getBuildQueryPlugin.js';
|
8
8
|
import { getDBName } from './utilities/getDBName.js';
|
9
9
|
export const init = function init() {
|
10
|
+
// Always create a scoped, **unopened** connection object
|
11
|
+
// (no URI here; models compile per-connection and do not require an open socket)
|
12
|
+
this.connection ??= mongoose.createConnection();
|
10
13
|
this.payload.config.collections.forEach((collection)=>{
|
11
14
|
const schemaOptions = this.collectionsSchemaOptions?.[collection.slug];
|
12
15
|
const schema = buildCollectionSchema(collection, this.payload, schemaOptions);
|
@@ -40,15 +43,15 @@ export const init = function init() {
|
|
40
43
|
versionsFields: buildVersionCollectionFields(this.payload.config, collection, true)
|
41
44
|
}));
|
42
45
|
const versionCollectionName = this.autoPluralization === true && !collection.dbName ? undefined : versionModelName;
|
43
|
-
this.versions[collection.slug] =
|
46
|
+
this.versions[collection.slug] = this.connection.model(versionModelName, versionSchema, versionCollectionName);
|
44
47
|
}
|
45
48
|
const modelName = getDBName({
|
46
49
|
config: collection
|
47
50
|
});
|
48
51
|
const collectionName = this.autoPluralization === true && !collection.dbName ? undefined : modelName;
|
49
|
-
this.collections[collection.slug] =
|
52
|
+
this.collections[collection.slug] = this.connection.model(modelName, schema, collectionName);
|
50
53
|
});
|
51
|
-
this.globals = buildGlobalModel(this
|
54
|
+
this.globals = buildGlobalModel(this);
|
52
55
|
this.payload.config.globals.forEach((global)=>{
|
53
56
|
if (global.versions) {
|
54
57
|
const versionModelName = getDBName({
|
@@ -74,7 +77,7 @@ export const init = function init() {
|
|
74
77
|
}).plugin(getBuildQueryPlugin({
|
75
78
|
versionsFields: buildVersionGlobalFields(this.payload.config, global, true)
|
76
79
|
}));
|
77
|
-
this.versions[global.slug] =
|
80
|
+
this.versions[global.slug] = this.connection.model(versionModelName, versionSchema, versionModelName);
|
78
81
|
}
|
79
82
|
});
|
80
83
|
};
|
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 = function init(this: MongooseAdapter) {\n this.payload.config.collections.forEach((collection: SanitizedCollectionConfig) => {\n const schemaOptions = this.collectionsSchemaOptions?.[collection.slug]\n\n const schema = buildCollectionSchema(collection, this.payload, schemaOptions)\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 { getBuildQueryPlugin } from './queries/getBuildQueryPlugin.js'\nimport { getDBName } from './utilities/getDBName.js'\n\nexport const init: Init = 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 this.payload.config.collections.forEach((collection: SanitizedCollectionConfig) => {\n const schemaOptions = this.collectionsSchemaOptions?.[collection.slug]\n\n const schema = buildCollectionSchema(collection, this.payload, schemaOptions)\n if (collection.versions) {\n const versionModelName = getDBName({ config: collection, versions: true })\n\n const versionCollectionFields = buildVersionCollectionFields(this.payload.config, collection)\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 payload: this.payload,\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(this) 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 payload: this.payload,\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}\n"],"names":["mongoose","paginate","buildVersionCollectionFields","buildVersionCompoundIndexes","buildVersionGlobalFields","buildCollectionSchema","buildGlobalModel","buildSchema","getBuildQueryPlugin","getDBName","init","connection","createConnection","payload","config","collections","forEach","collection","schemaOptions","collectionsSchemaOptions","slug","schema","versions","versionModelName","versionCollectionFields","versionSchema","buildSchemaOptions","disableUnique","draftsEnabled","indexSortableFields","options","minimize","timestamps","compoundIndexes","indexes","sanitizedIndexes","configFields","plugin","useEstimatedCount","collectionSlug","versionsFields","versionCollectionName","autoPluralization","dbName","undefined","model","modelName","collectionName","globals","global","versionGlobalFields"],"mappings":"AAGA,OAAOA,cAAc,WAAU;AAC/B,OAAOC,cAAc,uBAAsB;AAC3C,SACEC,4BAA4B,EAC5BC,2BAA2B,EAC3BC,wBAAwB,QACnB,UAAS;AAKhB,SAASC,qBAAqB,QAAQ,oCAAmC;AACz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;QAEJ;IACF;AACF,EAAC"}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import type {
|
1
|
+
import type { MongooseAdapter } from '../index.js';
|
2
2
|
import type { GlobalModel } from '../types.js';
|
3
|
-
export declare const buildGlobalModel: (
|
3
|
+
export declare const buildGlobalModel: (adapter: MongooseAdapter) => 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":"
|
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;AAK9C,eAAO,MAAM,gBAAgB,YAAa,eAAe,KAAG,WAAW,GAAG,IAgCzE,CAAA"}
|
@@ -1,16 +1,16 @@
|
|
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 = (
|
5
|
-
if (payload.config.globals && payload.config.globals.length > 0) {
|
4
|
+
export const buildGlobalModel = (adapter)=>{
|
5
|
+
if (adapter.payload.config.globals && adapter.payload.config.globals.length > 0) {
|
6
6
|
const globalsSchema = new mongoose.Schema({}, {
|
7
7
|
discriminatorKey: 'globalType',
|
8
8
|
minimize: false,
|
9
9
|
timestamps: true
|
10
10
|
});
|
11
11
|
globalsSchema.plugin(getBuildQueryPlugin());
|
12
|
-
const Globals =
|
13
|
-
Object.values(payload.config.globals).forEach((globalConfig)=>{
|
12
|
+
const Globals = adapter.connection.model('globals', globalsSchema, 'globals');
|
13
|
+
Object.values(adapter.payload.config.globals).forEach((globalConfig)=>{
|
14
14
|
const globalSchema = buildSchema({
|
15
15
|
buildSchemaOptions: {
|
16
16
|
options: {
|
@@ -18,7 +18,7 @@ export const buildGlobalModel = (payload)=>{
|
|
18
18
|
}
|
19
19
|
},
|
20
20
|
configFields: globalConfig.fields,
|
21
|
-
payload
|
21
|
+
payload: adapter.payload
|
22
22
|
});
|
23
23
|
Globals.discriminator(globalConfig.slug, globalSchema);
|
24
24
|
});
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/models/buildGlobalModel.ts"],"sourcesContent":["import
|
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","discriminator","slug"],"mappings":"AAAA,OAAOA,cAAc,WAAU;AAK/B,SAASC,mBAAmB,QAAQ,oCAAmC;AACvE,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,mBAAmB,CAACC;IAC/B,IAAIA,QAAQC,OAAO,CAACC,MAAM,CAACC,OAAO,IAAIH,QAAQC,OAAO,CAACC,MAAM,CAACC,OAAO,CAACC,MAAM,GAAG,GAAG;QAC/E,MAAMC,gBAAgB,IAAIT,SAASU,MAAM,CACvC,CAAC,GACD;YAAEC,kBAAkB;YAAcC,UAAU;YAAOC,YAAY;QAAK;QAGtEJ,cAAcK,MAAM,CAACb;QAErB,MAAMc,UAAUX,QAAQY,UAAU,CAACC,KAAK,CACtC,WACAR,eACA;QAGFS,OAAOC,MAAM,CAACf,QAAQC,OAAO,CAACC,MAAM,CAACC,OAAO,EAAEa,OAAO,CAAC,CAACC;YACrD,MAAMC,eAAepB,YAAY;gBAC/BqB,oBAAoB;oBAClBC,SAAS;wBACPZ,UAAU;oBACZ;gBACF;gBACAa,cAAcJ,aAAaK,MAAM;gBACjCrB,SAASD,QAAQC,OAAO;YAC1B;YACAU,QAAQY,aAAa,CAACN,aAAaO,IAAI,EAAEN;QAC3C;QAEA,OAAOP;IACT;IAEA,OAAO;AACT,EAAC"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@payloadcms/db-mongodb",
|
3
|
-
"version": "3.54.0-internal.
|
3
|
+
"version": "3.54.0-internal.90cf7d5",
|
4
4
|
"description": "The officially supported MongoDB database adapter for Payload",
|
5
5
|
"homepage": "https://payloadcms.com",
|
6
6
|
"repository": {
|
@@ -50,10 +50,10 @@
|
|
50
50
|
"mongodb": "6.16.0",
|
51
51
|
"mongodb-memory-server": "10.1.4",
|
52
52
|
"@payloadcms/eslint-config": "3.28.0",
|
53
|
-
"payload": "3.54.0-internal.
|
53
|
+
"payload": "3.54.0-internal.90cf7d5"
|
54
54
|
},
|
55
55
|
"peerDependencies": {
|
56
|
-
"payload": "3.54.0-internal.
|
56
|
+
"payload": "3.54.0-internal.90cf7d5"
|
57
57
|
},
|
58
58
|
"scripts": {
|
59
59
|
"build": "pnpm build:types && pnpm build:swc",
|