@payloadcms/db-mongodb 3.0.0-canary.ca3dd1c → 3.0.0-canary.cdb9474
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/connect.d.ts.map +1 -1
- package/dist/connect.js +5 -0
- package/dist/connect.js.map +1 -1
- package/dist/find.d.ts.map +1 -1
- package/dist/find.js +7 -0
- package/dist/find.js.map +1 -1
- package/dist/findGlobalVersions.d.ts.map +1 -1
- package/dist/findGlobalVersions.js +8 -1
- package/dist/findGlobalVersions.js.map +1 -1
- package/dist/findVersions.d.ts.map +1 -1
- package/dist/findVersions.js +7 -0
- package/dist/findVersions.js.map +1 -1
- package/dist/index.d.ts +42 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/models/buildCollectionSchema.d.ts.map +1 -1
- package/dist/models/buildCollectionSchema.js +9 -0
- package/dist/models/buildCollectionSchema.js.map +1 -1
- package/dist/models/buildSchema.d.ts.map +1 -1
- package/dist/models/buildSchema.js +88 -14
- package/dist/models/buildSchema.js.map +1 -1
- package/dist/queries/parseParams.d.ts.map +1 -1
- package/dist/queries/parseParams.js +2 -5
- package/dist/queries/parseParams.js.map +1 -1
- package/dist/queryDrafts.d.ts.map +1 -1
- package/dist/queryDrafts.js +7 -0
- package/dist/queryDrafts.js.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +3 -4
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;AAMtC,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;AAMtC,eAAO,MAAM,OAAO,EAAE,OA0DrB,CAAA"}
|
package/dist/connect.js
CHANGED
@@ -35,6 +35,11 @@ export const connect = async function connect(options = {
|
|
35
35
|
this.payload.logger.info('---- DROPPED DATABASE ----');
|
36
36
|
}
|
37
37
|
}
|
38
|
+
if (process.env.NODE_ENV === 'production' && this.prodMigrations) {
|
39
|
+
await this.migrate({
|
40
|
+
migrations: this.prodMigrations
|
41
|
+
});
|
42
|
+
}
|
38
43
|
} catch (err) {
|
39
44
|
console.log(err);
|
40
45
|
this.payload.logger.error(`Error: cannot connect to MongoDB. Details: ${err.message}`, err);
|
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'\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) connectionOptions.autoIndex = false\n\n try {\n this.connection = (await mongoose.connect(urlToConnect, connectionOptions)).connection\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 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 = undefined\n }\n\n if (!this.mongoMemoryServer && !hotReload) {\n if (process.env.PAYLOAD_DROP_DATABASE === 'true') {\n this.payload.logger.info('---- DROPPING DATABASE ----')\n await mongoose.connection.dropDatabase()\n this.payload.logger.info('---- DROPPED DATABASE ----')\n }\n }\n } catch (err) {\n console.log(err)\n this.payload.logger.error(`Error: cannot connect to MongoDB. Details: ${err.message}`, err)\n process.exit(1)\n }\n}\n"],"names":["mongoose","connect","options","hotReload","url","Error","urlToConnect","connectionOptions","autoIndex","connectOptions","useFacet","undefined","connection","mongoMemoryServer","Promise","resolve","setTimeout","client","getClient","replicaSet","transactionOptions","beginTransaction","process","env","PAYLOAD_DROP_DATABASE","payload","logger","info","dropDatabase","err","console","log","error","message","exit"],"mappings":"AAGA,OAAOA,cAAc,WAAU;AAI/B,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,WAAWI,kBAAkBC,SAAS,GAAG;IAE7C,IAAI;QACF,IAAI,CAACI,UAAU,GAAG,AAAC,CAAA,MAAMZ,SAASC,OAAO,CAACK,cAAcC,kBAAiB,EAAGK,UAAU;QAEtF,8DAA8D;QAC9D,gEAAgE;QAChE,IAAI,IAAI,CAACC,iBAAiB,EAAE;YAC1B,MAAM,IAAIC,QAAQ,CAACC,UAAYC,WAAWD,SAAS;QACrD;QAEA,MAAME,SAAS,IAAI,CAACL,UAAU,CAACM,SAAS;QAExC,IAAI,CAACD,OAAOf,OAAO,CAACiB,UAAU,EAAE;YAC9B,IAAI,CAACC,kBAAkB,GAAG;YAC1B,IAAI,CAACC,gBAAgB,GAAGV;QAC1B;QAEA,IAAI,CAAC,IAAI,CAACE,iBAAiB,IAAI,CAACV,WAAW;YACzC,IAAImB,QAAQC,GAAG,CAACC,qBAAqB,KAAK,QAAQ;gBAChD,IAAI,CAACC,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;gBACzB,MAAM3B,SAASY,UAAU,CAACgB,YAAY;gBACtC,IAAI,CAACH,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;YAC3B;QACF;IACF,EAAE,
|
1
|
+
{"version":3,"sources":["../src/connect.ts"],"sourcesContent":["import type { ConnectOptions } from 'mongoose'\nimport type { Connect } from 'payload'\n\nimport mongoose from 'mongoose'\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) connectionOptions.autoIndex = false\n\n try {\n this.connection = (await mongoose.connect(urlToConnect, connectionOptions)).connection\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 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 = undefined\n }\n\n if (!this.mongoMemoryServer && !hotReload) {\n if (process.env.PAYLOAD_DROP_DATABASE === 'true') {\n this.payload.logger.info('---- DROPPING DATABASE ----')\n await mongoose.connection.dropDatabase()\n this.payload.logger.info('---- DROPPED DATABASE ----')\n }\n }\n\n if (process.env.NODE_ENV === 'production' && this.prodMigrations) {\n await this.migrate({ migrations: this.prodMigrations })\n }\n } catch (err) {\n console.log(err)\n this.payload.logger.error(`Error: cannot connect to MongoDB. Details: ${err.message}`, err)\n process.exit(1)\n }\n}\n"],"names":["mongoose","connect","options","hotReload","url","Error","urlToConnect","connectionOptions","autoIndex","connectOptions","useFacet","undefined","connection","mongoMemoryServer","Promise","resolve","setTimeout","client","getClient","replicaSet","transactionOptions","beginTransaction","process","env","PAYLOAD_DROP_DATABASE","payload","logger","info","dropDatabase","NODE_ENV","prodMigrations","migrate","migrations","err","console","log","error","message","exit"],"mappings":"AAGA,OAAOA,cAAc,WAAU;AAI/B,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,WAAWI,kBAAkBC,SAAS,GAAG;IAE7C,IAAI;QACF,IAAI,CAACI,UAAU,GAAG,AAAC,CAAA,MAAMZ,SAASC,OAAO,CAACK,cAAcC,kBAAiB,EAAGK,UAAU;QAEtF,8DAA8D;QAC9D,gEAAgE;QAChE,IAAI,IAAI,CAACC,iBAAiB,EAAE;YAC1B,MAAM,IAAIC,QAAQ,CAACC,UAAYC,WAAWD,SAAS;QACrD;QAEA,MAAME,SAAS,IAAI,CAACL,UAAU,CAACM,SAAS;QAExC,IAAI,CAACD,OAAOf,OAAO,CAACiB,UAAU,EAAE;YAC9B,IAAI,CAACC,kBAAkB,GAAG;YAC1B,IAAI,CAACC,gBAAgB,GAAGV;QAC1B;QAEA,IAAI,CAAC,IAAI,CAACE,iBAAiB,IAAI,CAACV,WAAW;YACzC,IAAImB,QAAQC,GAAG,CAACC,qBAAqB,KAAK,QAAQ;gBAChD,IAAI,CAACC,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;gBACzB,MAAM3B,SAASY,UAAU,CAACgB,YAAY;gBACtC,IAAI,CAACH,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC;YAC3B;QACF;QAEA,IAAIL,QAAQC,GAAG,CAACM,QAAQ,KAAK,gBAAgB,IAAI,CAACC,cAAc,EAAE;YAChE,MAAM,IAAI,CAACC,OAAO,CAAC;gBAAEC,YAAY,IAAI,CAACF,cAAc;YAAC;QACvD;IACF,EAAE,OAAOG,KAAK;QACZC,QAAQC,GAAG,CAACF;QACZ,IAAI,CAACR,OAAO,CAACC,MAAM,CAACU,KAAK,CAAC,CAAC,2CAA2C,EAAEH,IAAII,OAAO,CAAC,CAAC,EAAEJ;QACvFX,QAAQgB,IAAI,CAAC;IACf;AACF,EAAC"}
|
package/dist/find.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"find.d.ts","sourceRoot":"","sources":["../src/find.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAkB,MAAM,SAAS,CAAA;AAUnD,eAAO,MAAM,IAAI,EAAE,
|
1
|
+
{"version":3,"file":"find.d.ts","sourceRoot":"","sources":["../src/find.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAkB,MAAM,SAAS,CAAA;AAUnD,eAAO,MAAM,IAAI,EAAE,IAyFlB,CAAA"}
|
package/dist/find.js
CHANGED
@@ -38,6 +38,13 @@ export const find = async function find({ collection, limit, locale, page, pagin
|
|
38
38
|
sort,
|
39
39
|
useEstimatedCount
|
40
40
|
};
|
41
|
+
if (this.collation) {
|
42
|
+
const defaultLocale = 'en';
|
43
|
+
paginationOptions.collation = {
|
44
|
+
locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,
|
45
|
+
...this.collation
|
46
|
+
};
|
47
|
+
}
|
41
48
|
if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {
|
42
49
|
// Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding
|
43
50
|
// a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,
|
package/dist/find.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/find.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { Find, PayloadRequest } from 'payload'\n\nimport { flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport sanitizeInternalFields from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const find: Find = async function find(\n this: MongooseAdapter,\n { collection, limit, locale, page, pagination, req = {} as PayloadRequest, sort: sortArg, where },\n) {\n const Model = this.collections[collection]\n const collectionConfig = this.payload.collections[collection].config\n const options = await withSession(this, req)\n\n let hasNearConstraint = false\n\n if (where) {\n const constraints = flattenWhereToOperators(where)\n hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n }\n\n let sort\n if (!hasNearConstraint) {\n sort = buildSortParam({\n config: this.payload.config,\n fields: collectionConfig.fields,\n locale,\n sort: sortArg || collectionConfig.defaultSort,\n timestamps: true,\n })\n }\n\n const query = await Model.buildQuery({\n locale,\n payload: this.payload,\n where,\n })\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0\n const paginationOptions: PaginateOptions = {\n forceCountFn: hasNearConstraint,\n lean: true,\n leanWithId: true,\n options,\n page,\n pagination,\n sort,\n useEstimatedCount,\n }\n\n if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n paginationOptions.useCustomCountFn = () => {\n return Promise.resolve(\n Model.countDocuments(query, {\n ...options,\n hint: { _id: 1 },\n }),\n )\n }\n }\n\n if (limit >= 0) {\n paginationOptions.limit = limit\n // limit must also be set here, it's ignored when pagination is false\n paginationOptions.options.limit = limit\n\n // Disable pagination if limit is 0\n if (limit === 0) {\n paginationOptions.pagination = false\n }\n }\n\n const result = await Model.paginate(query, paginationOptions)\n const docs = JSON.parse(JSON.stringify(result.docs))\n\n return {\n ...result,\n docs: docs.map((doc) => {\n doc.id = doc._id\n return sanitizeInternalFields(doc)\n }),\n }\n}\n"],"names":["flattenWhereToOperators","buildSortParam","sanitizeInternalFields","withSession","find","collection","limit","locale","page","pagination","req","sort","sortArg","where","Model","collections","collectionConfig","payload","config","options","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","defaultSort","timestamps","query","buildQuery","useEstimatedCount","length","paginationOptions","forceCountFn","lean","leanWithId","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","paginate","docs","JSON","parse","stringify","map","doc","id"],"mappings":"AAGA,SAASA,uBAAuB,QAAQ,UAAS;AAIjD,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,OAAOC,4BAA4B,wCAAuC;AAC1E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,OAAa,eAAeA,KAEvC,EAAEC,UAAU,EAAEC,KAAK,EAAEC,MAAM,EAAEC,IAAI,EAAEC,UAAU,EAAEC,MAAM,CAAC,CAAmB,EAAEC,MAAMC,OAAO,EAAEC,KAAK,EAAE;IAEjG,MAAMC,QAAQ,IAAI,CAACC,WAAW,CAACV,WAAW;IAC1C,MAAMW,mBAAmB,IAAI,CAACC,OAAO,CAACF,WAAW,CAACV,WAAW,CAACa,MAAM;IACpE,MAAMC,UAAU,MAAMhB,YAAY,IAAI,EAAEO;IAExC,IAAIU,oBAAoB;IAExB,IAAIP,OAAO;QACT,MAAMQ,cAAcrB,wBAAwBa;QAC5CO,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,IAAIf;IACJ,IAAI,CAACS,mBAAmB;QACtBT,OAAOV,eAAe;YACpBiB,QAAQ,IAAI,CAACD,OAAO,CAACC,MAAM;YAC3BS,QAAQX,iBAAiBW,MAAM;YAC/BpB;YACAI,MAAMC,WAAWI,iBAAiBY,WAAW;YAC7CC,YAAY;QACd;IACF;IAEA,MAAMC,QAAQ,MAAMhB,MAAMiB,UAAU,CAAC;QACnCxB;QACAU,SAAS,IAAI,CAACA,OAAO;QACrBJ;IACF;IAEA,4HAA4H;IAC5H,MAAMmB,oBAAoBZ,qBAAqB,CAACU,SAASN,OAAOC,IAAI,CAACK,OAAOG,MAAM,KAAK;IACvF,MAAMC,oBAAqC;QACzCC,cAAcf;QACdgB,MAAM;QACNC,YAAY;QACZlB;QACAX;QACAC;QACAE;QACAqB;IACF;IAEA,IAAI,
|
1
|
+
{"version":3,"sources":["../src/find.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { Find, PayloadRequest } from 'payload'\n\nimport { flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport sanitizeInternalFields from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const find: Find = async function find(\n this: MongooseAdapter,\n { collection, limit, locale, page, pagination, req = {} as PayloadRequest, sort: sortArg, where },\n) {\n const Model = this.collections[collection]\n const collectionConfig = this.payload.collections[collection].config\n const options = await withSession(this, req)\n\n let hasNearConstraint = false\n\n if (where) {\n const constraints = flattenWhereToOperators(where)\n hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n }\n\n let sort\n if (!hasNearConstraint) {\n sort = buildSortParam({\n config: this.payload.config,\n fields: collectionConfig.fields,\n locale,\n sort: sortArg || collectionConfig.defaultSort,\n timestamps: true,\n })\n }\n\n const query = await Model.buildQuery({\n locale,\n payload: this.payload,\n where,\n })\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0\n const paginationOptions: PaginateOptions = {\n forceCountFn: hasNearConstraint,\n lean: true,\n leanWithId: true,\n options,\n page,\n pagination,\n sort,\n useEstimatedCount,\n }\n\n if (this.collation) {\n const defaultLocale = 'en'\n paginationOptions.collation = {\n locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,\n ...this.collation,\n }\n }\n\n if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n paginationOptions.useCustomCountFn = () => {\n return Promise.resolve(\n Model.countDocuments(query, {\n ...options,\n hint: { _id: 1 },\n }),\n )\n }\n }\n\n if (limit >= 0) {\n paginationOptions.limit = limit\n // limit must also be set here, it's ignored when pagination is false\n paginationOptions.options.limit = limit\n\n // Disable pagination if limit is 0\n if (limit === 0) {\n paginationOptions.pagination = false\n }\n }\n\n const result = await Model.paginate(query, paginationOptions)\n const docs = JSON.parse(JSON.stringify(result.docs))\n\n return {\n ...result,\n docs: docs.map((doc) => {\n doc.id = doc._id\n return sanitizeInternalFields(doc)\n }),\n }\n}\n"],"names":["flattenWhereToOperators","buildSortParam","sanitizeInternalFields","withSession","find","collection","limit","locale","page","pagination","req","sort","sortArg","where","Model","collections","collectionConfig","payload","config","options","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","defaultSort","timestamps","query","buildQuery","useEstimatedCount","length","paginationOptions","forceCountFn","lean","leanWithId","collation","defaultLocale","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","paginate","docs","JSON","parse","stringify","map","doc","id"],"mappings":"AAGA,SAASA,uBAAuB,QAAQ,UAAS;AAIjD,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,OAAOC,4BAA4B,wCAAuC;AAC1E,SAASC,WAAW,Q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nB;IACF;IAEA,IAAI,CAACN,qBAAqBR,OAAOC,IAAI,CAACK,OAAOG,MAAM,KAAK,KAAK,IAAI,CAACO,iBAAiB,KAAK,MAAM;QAC5F,mHAAmH;QACnH,qHAAqH;QACrH,mHAAmH;QACnH,4BAA4B;QAC5BN,kBAAkBO,gBAAgB,GAAG;YACnC,OAAOC,QAAQC,OAAO,CACpB7B,MAAM8B,cAAc,CAACd,OAAO;gBAC1B,GAAGX,OAAO;gBACV0B,MAAM;oBAAEC,KAAK;gBAAE;YACjB;QAEJ;IACF;IAEA,IAAIxC,SAAS,GAAG;QACd4B,kBAAkB5B,KAAK,GAAGA;QAC1B,qEAAqE;QACrE4B,kBAAkBf,OAAO,CAACb,KAAK,GAAGA;QAElC,mCAAmC;QACnC,IAAIA,UAAU,GAAG;YACf4B,kBAAkBzB,UAAU,GAAG;QACjC;IACF;IAEA,MAAMsC,SAAS,MAAMjC,MAAMkC,QAAQ,CAAClB,OAAOI;IAC3C,MAAMe,OAAOC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL,OAAOE,IAAI;IAElD,OAAO;QACL,GAAGF,MAAM;QACTE,MAAMA,KAAKI,GAAG,CAAC,CAACC;YACdA,IAAIC,EAAE,GAAGD,IAAIR,GAAG;YAChB,OAAO5C,uBAAuBoD;QAChC;IACF;AACF,EAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"findGlobalVersions.d.ts","sourceRoot":"","sources":["../src/findGlobalVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAkB,MAAM,SAAS,CAAA;AAUjE,eAAO,MAAM,kBAAkB,EAAE,
|
1
|
+
{"version":3,"file":"findGlobalVersions.d.ts","sourceRoot":"","sources":["../src/findGlobalVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAkB,MAAM,SAAS,CAAA;AAUjE,eAAO,MAAM,kBAAkB,EAAE,kBA2GhC,CAAA"}
|
@@ -37,13 +37,20 @@ export const findGlobalVersions = async function findGlobalVersions({ global, li
|
|
37
37
|
forceCountFn: hasNearConstraint,
|
38
38
|
lean: true,
|
39
39
|
leanWithId: true,
|
40
|
-
|
40
|
+
limit,
|
41
41
|
options,
|
42
42
|
page,
|
43
43
|
pagination,
|
44
44
|
sort,
|
45
45
|
useEstimatedCount
|
46
46
|
};
|
47
|
+
if (this.collation) {
|
48
|
+
const defaultLocale = 'en';
|
49
|
+
paginationOptions.collation = {
|
50
|
+
locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,
|
51
|
+
...this.collation
|
52
|
+
};
|
53
|
+
}
|
47
54
|
if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {
|
48
55
|
// Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding
|
49
56
|
// a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/findGlobalVersions.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { FindGlobalVersions, PayloadRequest } from 'payload'\n\nimport { buildVersionGlobalFields, flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport sanitizeInternalFields from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const findGlobalVersions: FindGlobalVersions = async function findGlobalVersions(\n this: MongooseAdapter,\n {\n global,\n limit,\n locale,\n page,\n pagination,\n req = {} as PayloadRequest,\n skip,\n sort: sortArg,\n where,\n },\n) {\n const Model = this.versions[global]\n const versionFields = buildVersionGlobalFields(\n this.payload.globals.config.find(({ slug }) => slug === global),\n )\n const options = {\n ...(await withSession(this, req)),\n limit,\n skip,\n }\n\n let hasNearConstraint = false\n\n if (where) {\n const constraints = flattenWhereToOperators(where)\n hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n }\n\n let sort\n if (!hasNearConstraint) {\n sort = buildSortParam({\n config: this.payload.config,\n fields: versionFields,\n locale,\n sort: sortArg || '-updatedAt',\n timestamps: true,\n })\n }\n\n const query = await Model.buildQuery({\n globalSlug: global,\n locale,\n payload: this.payload,\n where,\n })\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0\n const paginationOptions: PaginateOptions = {\n forceCountFn: hasNearConstraint,\n lean: true,\n leanWithId: true,\n
|
1
|
+
{"version":3,"sources":["../src/findGlobalVersions.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { FindGlobalVersions, PayloadRequest } from 'payload'\n\nimport { buildVersionGlobalFields, flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport sanitizeInternalFields from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const findGlobalVersions: FindGlobalVersions = async function findGlobalVersions(\n this: MongooseAdapter,\n {\n global,\n limit,\n locale,\n page,\n pagination,\n req = {} as PayloadRequest,\n skip,\n sort: sortArg,\n where,\n },\n) {\n const Model = this.versions[global]\n const versionFields = buildVersionGlobalFields(\n this.payload.globals.config.find(({ slug }) => slug === global),\n )\n const options = {\n ...(await withSession(this, req)),\n limit,\n skip,\n }\n\n let hasNearConstraint = false\n\n if (where) {\n const constraints = flattenWhereToOperators(where)\n hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n }\n\n let sort\n if (!hasNearConstraint) {\n sort = buildSortParam({\n config: this.payload.config,\n fields: versionFields,\n locale,\n sort: sortArg || '-updatedAt',\n timestamps: true,\n })\n }\n\n const query = await Model.buildQuery({\n globalSlug: global,\n locale,\n payload: this.payload,\n where,\n })\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0\n const paginationOptions: PaginateOptions = {\n forceCountFn: hasNearConstraint,\n lean: true,\n leanWithId: true,\n limit,\n options,\n page,\n pagination,\n sort,\n useEstimatedCount,\n }\n\n if (this.collation) {\n const defaultLocale = 'en'\n paginationOptions.collation = {\n locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,\n ...this.collation,\n }\n }\n\n if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n paginationOptions.useCustomCountFn = () => {\n return Promise.resolve(\n Model.countDocuments(query, {\n ...options,\n hint: { _id: 1 },\n }),\n )\n }\n }\n\n if (limit >= 0) {\n paginationOptions.limit = limit\n // limit must also be set here, it's ignored when pagination is false\n paginationOptions.options.limit = limit\n\n // Disable pagination if limit is 0\n if (limit === 0) {\n paginationOptions.pagination = false\n }\n }\n\n const result = await Model.paginate(query, paginationOptions)\n const docs = JSON.parse(JSON.stringify(result.docs))\n\n return {\n ...result,\n docs: docs.map((doc) => {\n doc.id = doc._id\n return sanitizeInternalFields(doc)\n }),\n }\n}\n"],"names":["buildVersionGlobalFields","flattenWhereToOperators","buildSortParam","sanitizeInternalFields","withSession","findGlobalVersions","global","limit","locale","page","pagination","req","skip","sort","sortArg","where","Model","versions","versionFields","payload","globals","config","find","slug","options","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","timestamps","query","buildQuery","globalSlug","useEstimatedCount","length","paginationOptions","forceCountFn","lean","leanWithId","collation","defaultLocale","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","paginate","docs","JSON","parse","stringify","map","doc","id"],"mappings":"AAGA,SAASA,wBAAwB,EAAEC,uBAAuB,QAAQ,UAAS;AAI3E,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,OAAOC,4BAA4B,w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,kBAAkBI,SAAS,GAAG;YAC5BnC,QAAQA,UAAUA,WAAW,SAASA,WAAW,MAAMA,SAASoC;YAChE,GAAG,IAAI,CAACD,SAAS;QACnB;IACF;IAEA,IAAI,CAACN,qBAAqBR,OAAOC,IAAI,CAACI,OAAOI,MAAM,KAAK,KAAK,IAAI,CAACO,iBAAiB,KAAK,MAAM;QAC5F,mHAAmH;QACnH,qHAAqH;QACrH,mHAAmH;QACnH,4BAA4B;QAC5BN,kBAAkBO,gBAAgB,GAAG;YACnC,OAAOC,QAAQC,OAAO,CACpBhC,MAAMiC,cAAc,CAACf,OAAO;gBAC1B,GAAGV,OAAO;gBACV0B,MAAM;oBAAEC,KAAK;gBAAE;YACjB;QAEJ;IACF;IAEA,IAAI5C,SAAS,GAAG;QACdgC,kBAAkBhC,KAAK,GAAGA;QAC1B,qEAAqE;QACrEgC,kBAAkBf,OAAO,CAACjB,KAAK,GAAGA;QAElC,mCAAmC;QACnC,IAAIA,UAAU,GAAG;YACfgC,kBAAkB7B,UAAU,GAAG;QACjC;IACF;IAEA,MAAM0C,SAAS,MAAMpC,MAAMqC,QAAQ,CAACnB,OAAOK;IAC3C,MAAMe,OAAOC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL,OAAOE,IAAI;IAElD,OAAO;QACL,GAAGF,MAAM;QACTE,MAAMA,KAAKI,GAAG,CAAC,CAACC;YACdA,IAAIC,EAAE,GAAGD,IAAIR,GAAG;YAChB,OAAOhD,uBAAuBwD;QAChC;IACF;AACF,EAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"findVersions.d.ts","sourceRoot":"","sources":["../src/findVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAkB,MAAM,SAAS,CAAA;AAU3D,eAAO,MAAM,YAAY,EAAE,
|
1
|
+
{"version":3,"file":"findVersions.d.ts","sourceRoot":"","sources":["../src/findVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAkB,MAAM,SAAS,CAAA;AAU3D,eAAO,MAAM,YAAY,EAAE,YAwG1B,CAAA"}
|
package/dist/findVersions.js
CHANGED
@@ -43,6 +43,13 @@ export const findVersions = async function findVersions({ collection, limit, loc
|
|
43
43
|
sort,
|
44
44
|
useEstimatedCount
|
45
45
|
};
|
46
|
+
if (this.collation) {
|
47
|
+
const defaultLocale = 'en';
|
48
|
+
paginationOptions.collation = {
|
49
|
+
locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,
|
50
|
+
...this.collation
|
51
|
+
};
|
52
|
+
}
|
46
53
|
if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {
|
47
54
|
// Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding
|
48
55
|
// a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,
|
package/dist/findVersions.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/findVersions.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { FindVersions, PayloadRequest } from 'payload'\n\nimport { flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport sanitizeInternalFields from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const findVersions: FindVersions = async function findVersions(\n this: MongooseAdapter,\n {\n collection,\n limit,\n locale,\n page,\n pagination,\n req = {} as PayloadRequest,\n skip,\n sort: sortArg,\n where,\n },\n) {\n const Model = this.versions[collection]\n const collectionConfig = this.payload.collections[collection].config\n const options = {\n ...(await withSession(this, req)),\n limit,\n skip,\n }\n\n let hasNearConstraint = false\n\n if (where) {\n const constraints = flattenWhereToOperators(where)\n hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n }\n\n let sort\n if (!hasNearConstraint) {\n sort = buildSortParam({\n config: this.payload.config,\n fields: collectionConfig.fields,\n locale,\n sort: sortArg || '-updatedAt',\n timestamps: true,\n })\n }\n\n const query = await Model.buildQuery({\n locale,\n payload: this.payload,\n where,\n })\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0\n const paginationOptions: PaginateOptions = {\n forceCountFn: hasNearConstraint,\n lean: true,\n leanWithId: true,\n limit,\n options,\n page,\n pagination,\n sort,\n useEstimatedCount,\n }\n\n if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n paginationOptions.useCustomCountFn = () => {\n return Promise.resolve(\n Model.countDocuments(query, {\n ...options,\n hint: { _id: 1 },\n }),\n )\n }\n }\n\n if (limit >= 0) {\n paginationOptions.limit = limit\n // limit must also be set here, it's ignored when pagination is false\n paginationOptions.options.limit = limit\n\n // Disable pagination if limit is 0\n if (limit === 0) {\n paginationOptions.pagination = false\n }\n }\n\n const result = await Model.paginate(query, paginationOptions)\n const docs = JSON.parse(JSON.stringify(result.docs))\n\n return {\n ...result,\n docs: docs.map((doc) => {\n doc.id = doc._id\n return sanitizeInternalFields(doc)\n }),\n }\n}\n"],"names":["flattenWhereToOperators","buildSortParam","sanitizeInternalFields","withSession","findVersions","collection","limit","locale","page","pagination","req","skip","sort","sortArg","where","Model","versions","collectionConfig","payload","collections","config","options","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","timestamps","query","buildQuery","useEstimatedCount","length","paginationOptions","forceCountFn","lean","leanWithId","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","paginate","docs","JSON","parse","stringify","map","doc","id"],"mappings":"AAGA,SAASA,uBAAuB,QAAQ,UAAS;AAIjD,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,OAAOC,4BAA4B,wCAAuC;AAC1E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,eAA6B,eAAeA,aAEvD,EACEC,UAAU,EACVC,KAAK,EACLC,MAAM,EACNC,IAAI,EACJC,UAAU,EACVC,MAAM,CAAC,CAAmB,EAC1BC,IAAI,EACJC,MAAMC,OAAO,EACbC,KAAK,EACN;IAED,MAAMC,QAAQ,IAAI,CAACC,QAAQ,CAACX,WAAW;IACvC,MAAMY,mBAAmB,IAAI,CAACC,OAAO,CAACC,WAAW,CAACd,WAAW,CAACe,MAAM;IACpE,MAAMC,UAAU;QACd,GAAI,MAAMlB,YAAY,IAAI,EAAEO,IAAI;QAChCJ;QACAK;IACF;IAEA,IAAIW,oBAAoB;IAExB,IAAIR,OAAO;QACT,MAAMS,cAAcvB,wBAAwBc;QAC5CQ,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,IAAIhB;IACJ,IAAI,CAACU,mBAAmB;QACtBV,OAAOX,eAAe;YACpBmB,QAAQ,IAAI,CAACF,OAAO,CAACE,MAAM;YAC3BS,QAAQZ,iBAAiBY,MAAM;YAC/BtB;YACAK,MAAMC,WAAW;YACjBiB,YAAY;QACd;IACF;IAEA,MAAMC,QAAQ,MAAMhB,MAAMiB,UAAU,CAAC;QACnCzB;QACAW,SAAS,IAAI,CAACA,OAAO;QACrBJ;IACF;IAEA,4HAA4H;IAC5H,MAAMmB,oBAAoBX,qBAAqB,CAACS,SAASL,OAAOC,IAAI,CAACI,OAAOG,MAAM,KAAK;IACvF,MAAMC,oBAAqC;QACzCC,cAAcd;QACde,MAAM;QACNC,YAAY;QACZhC;QACAe;QACAb;QACAC;QACAG;QACAqB;IACF;IAEA,IAAI,
|
1
|
+
{"version":3,"sources":["../src/findVersions.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { FindVersions, PayloadRequest } from 'payload'\n\nimport { flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport sanitizeInternalFields from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const findVersions: FindVersions = async function findVersions(\n this: MongooseAdapter,\n {\n collection,\n limit,\n locale,\n page,\n pagination,\n req = {} as PayloadRequest,\n skip,\n sort: sortArg,\n where,\n },\n) {\n const Model = this.versions[collection]\n const collectionConfig = this.payload.collections[collection].config\n const options = {\n ...(await withSession(this, req)),\n limit,\n skip,\n }\n\n let hasNearConstraint = false\n\n if (where) {\n const constraints = flattenWhereToOperators(where)\n hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n }\n\n let sort\n if (!hasNearConstraint) {\n sort = buildSortParam({\n config: this.payload.config,\n fields: collectionConfig.fields,\n locale,\n sort: sortArg || '-updatedAt',\n timestamps: true,\n })\n }\n\n const query = await Model.buildQuery({\n locale,\n payload: this.payload,\n where,\n })\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0\n const paginationOptions: PaginateOptions = {\n forceCountFn: hasNearConstraint,\n lean: true,\n leanWithId: true,\n limit,\n options,\n page,\n pagination,\n sort,\n useEstimatedCount,\n }\n\n if (this.collation) {\n const defaultLocale = 'en'\n paginationOptions.collation = {\n locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,\n ...this.collation,\n }\n }\n\n if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n paginationOptions.useCustomCountFn = () => {\n return Promise.resolve(\n Model.countDocuments(query, {\n ...options,\n hint: { _id: 1 },\n }),\n )\n }\n }\n\n if (limit >= 0) {\n paginationOptions.limit = limit\n // limit must also be set here, it's ignored when pagination is false\n paginationOptions.options.limit = limit\n\n // Disable pagination if limit is 0\n if (limit === 0) {\n paginationOptions.pagination = false\n }\n }\n\n const result = await Model.paginate(query, paginationOptions)\n const docs = JSON.parse(JSON.stringify(result.docs))\n\n return {\n ...result,\n docs: docs.map((doc) => {\n doc.id = doc._id\n return sanitizeInternalFields(doc)\n }),\n }\n}\n"],"names":["flattenWhereToOperators","buildSortParam","sanitizeInternalFields","withSession","findVersions","collection","limit","locale","page","pagination","req","skip","sort","sortArg","where","Model","versions","collectionConfig","payload","collections","config","options","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","timestamps","query","buildQuery","useEstimatedCount","length","paginationOptions","forceCountFn","lean","leanWithId","collation","defaultLocale","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","paginate","docs","JSON","parse","stringify","map","doc","id"],"mappings":"AAGA,SAASA,uBAAuB,QAAQ,UAAS;AAIjD,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,OAAOC,4BAA4B,wCAAuC;AAC1E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,eAA6B,eAAeA,aAEvD,EACEC,UAAU,EACVC,KAAK,EACLC,MAAM,EACNC,IAAI,EACJC,UAAU,EACVC,MAAM,CAAC,CAAmB,EAC1BC,IAAI,EACJC,MAAMC,OAAO,EACbC,KAAK,EACN;IAED,MAAMC,QAAQ,IAAI,CAACC,QAAQ,CAACX,WAAW;IACvC,MAAMY,mBAAmB,IAAI,CAACC,OAAO,CAACC,WAAW,CAACd,WAAW,CAACe,MAAM;IACpE,MAAMC,UAAU;QACd,GAAI,MAAMlB,YAAY,IAAI,EAAEO,IAAI;QAChCJ;QACAK;IACF;IAEA,IAAIW,oBAAoB;IAExB,IAAIR,OAAO;QACT,MAAMS,cAAcvB,wBAAwBc;QAC5CQ,oBAAoBC,YAAYC,IAAI,CAAC,CAACC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U,GAAG;YACf6B,kBAAkB1B,UAAU,GAAG;QACjC;IACF;IAEA,MAAMuC,SAAS,MAAMjC,MAAMkC,QAAQ,CAAClB,OAAOI;IAC3C,MAAMe,OAAOC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL,OAAOE,IAAI;IAElD,OAAO;QACL,GAAGF,MAAM;QACTE,MAAMA,KAAKI,GAAG,CAAC,CAACC;YACdA,IAAIC,EAAE,GAAGD,IAAIR,GAAG;YAChB,OAAO7C,uBAAuBqD;QAChC;IACF;AACF,EAAC"}
|
package/dist/index.d.ts
CHANGED
@@ -1,12 +1,36 @@
|
|
1
|
-
import type { TransactionOptions } from 'mongodb';
|
1
|
+
import type { CollationOptions, TransactionOptions } from 'mongodb';
|
2
2
|
import type { MongoMemoryReplSet } from 'mongodb-memory-server';
|
3
3
|
import type { ClientSession, ConnectOptions, Connection } from 'mongoose';
|
4
4
|
import type { BaseDatabaseAdapter, DatabaseAdapterObj } from 'payload';
|
5
|
-
import type { CollectionModel, GlobalModel } from './types.js';
|
5
|
+
import type { CollectionModel, GlobalModel, MigrateDownArgs, MigrateUpArgs } from './types.js';
|
6
6
|
export type { MigrateDownArgs, MigrateUpArgs } from './types.js';
|
7
7
|
export interface Args {
|
8
8
|
/** Set to false to disable auto-pluralization of collection names, Defaults to true */
|
9
9
|
autoPluralization?: boolean;
|
10
|
+
/**
|
11
|
+
* If enabled, collation allows for language-specific rules for string comparison.
|
12
|
+
* This configuration can include the following options:
|
13
|
+
*
|
14
|
+
* - `strength` (number): Comparison level (1: Primary, 2: Secondary, 3: Tertiary (default), 4: Quaternary, 5: Identical)
|
15
|
+
* - `caseLevel` (boolean): Include case comparison at strength level 1 or 2.
|
16
|
+
* - `caseFirst` (string): Sort order of case differences during tertiary level comparisons ("upper", "lower", "off").
|
17
|
+
* - `numericOrdering` (boolean): Compare numeric strings as numbers.
|
18
|
+
* - `alternate` (string): Consider whitespace and punctuation as base characters ("non-ignorable", "shifted").
|
19
|
+
* - `maxVariable` (string): Characters considered ignorable when `alternate` is "shifted" ("punct", "space").
|
20
|
+
* - `backwards` (boolean): Sort strings with diacritics from back of the string.
|
21
|
+
* - `normalization` (boolean): Check if text requires normalization and perform normalization.
|
22
|
+
*
|
23
|
+
* Available on MongoDB version 3.4 and up.
|
24
|
+
* The locale that gets passed is your current project's locale but defaults to "en".
|
25
|
+
*
|
26
|
+
* Example:
|
27
|
+
* {
|
28
|
+
* strength: 3
|
29
|
+
* }
|
30
|
+
*
|
31
|
+
* Defaults to disabled.
|
32
|
+
*/
|
33
|
+
collation?: Omit<CollationOptions, 'locale'>;
|
10
34
|
/** Extra configuration options */
|
11
35
|
connectOptions?: {
|
12
36
|
/** Set false to disable $facet aggregation in non-supporting databases, Defaults to true */
|
@@ -19,6 +43,11 @@ export interface Args {
|
|
19
43
|
* typed as any to avoid dependency
|
20
44
|
*/
|
21
45
|
mongoMemoryServer?: MongoMemoryReplSet;
|
46
|
+
prodMigrations?: {
|
47
|
+
down: (args: MigrateDownArgs) => Promise<void>;
|
48
|
+
name: string;
|
49
|
+
up: (args: MigrateUpArgs) => Promise<void>;
|
50
|
+
}[];
|
22
51
|
transactionOptions?: TransactionOptions | false;
|
23
52
|
/** The URL to connect to MongoDB or false to start payload and prevent connecting */
|
24
53
|
url: false | string;
|
@@ -30,6 +59,11 @@ export type MongooseAdapter = {
|
|
30
59
|
connection: Connection;
|
31
60
|
globals: GlobalModel;
|
32
61
|
mongoMemoryServer: MongoMemoryReplSet;
|
62
|
+
prodMigrations?: {
|
63
|
+
down: (args: MigrateDownArgs) => Promise<void>;
|
64
|
+
name: string;
|
65
|
+
up: (args: MigrateUpArgs) => Promise<void>;
|
66
|
+
}[];
|
33
67
|
sessions: Record<number | string, ClientSession>;
|
34
68
|
versions: {
|
35
69
|
[slug: string]: CollectionModel;
|
@@ -43,6 +77,11 @@ declare module 'payload' {
|
|
43
77
|
connection: Connection;
|
44
78
|
globals: GlobalModel;
|
45
79
|
mongoMemoryServer: MongoMemoryReplSet;
|
80
|
+
prodMigrations?: {
|
81
|
+
down: (args: MigrateDownArgs) => Promise<void>;
|
82
|
+
name: string;
|
83
|
+
up: (args: MigrateUpArgs) => Promise<void>;
|
84
|
+
}[];
|
46
85
|
sessions: Record<number | string, ClientSession>;
|
47
86
|
transactionOptions: TransactionOptions;
|
48
87
|
versions: {
|
@@ -50,5 +89,5 @@ declare module 'payload' {
|
|
50
89
|
};
|
51
90
|
}
|
52
91
|
}
|
53
|
-
export declare function mongooseAdapter({ autoPluralization, connectOptions, disableIndexHints, migrationDir: migrationDirArg, mongoMemoryServer, transactionOptions, url, }: Args): DatabaseAdapterObj;
|
92
|
+
export declare function mongooseAdapter({ autoPluralization, connectOptions, disableIndexHints, migrationDir: migrationDirArg, mongoMemoryServer, prodMigrations, transactionOptions, url, }: Args): DatabaseAdapterObj;
|
54
93
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AACnE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAC/D,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AACzE,OAAO,KAAK,EAAE,mBAAmB,EAAE,kBAAkB,EAAW,MAAM,SAAS,CAAA;AAO/E,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AA6B9F,YAAY,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAE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AE,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,aAAa,CAAC,CAAA;IAChD,QAAQ,EAAE;QACR,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,CAAA;KAChC,CAAA;CACF,GAAG,IAAI,GACN,mBAAmB,CAAA;AAErB,OAAO,QAAQ,SAAS,CAAC;IACvB,UAAiB,eACf,SAAQ,IAAI,CAAC,mBAAmB,EAAE,UAAU,CAAC,EAC3C,IAAI,CAAC,IAAI,EAAE,cAAc,CAAC;QAC5B,WAAW,EAAE;YACX,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,CAAA;SAChC,CAAA;QACD,UAAU,EAAE,UAAU,CAAA;QACtB,OAAO,EAAE,WAAW,CAAA;QACpB,iBAAiB,EAAE,kBAAkB,CAAA;QACrC,cAAc,CAAC,EAAE;YACf,IAAI,EAAE,CAAC,IAAI,EAAE,eAAe,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;YAC9C,IAAI,EAAE,MAAM,CAAA;YACZ,EAAE,EAAE,CAAC,IAAI,EAAE,aAAa,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;SAC3C,EAAE,CAAA;QACH,QAAQ,EAAE,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,aAAa,CAAC,CAAA;QAChD,kBAAkB,EAAE,kBAAkB,CAAA;QACtC,QAAQ,EAAE;YACR,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,CAAA;SAChC,CAAA;KACF;CACF;AAED,wBAAgB,eAAe,CAAC,EAC9B,iBAAwB,EACxB,cAAc,EACd,iBAAyB,EACzB,YAAY,EAAE,eAAe,EAC7B,iBAAiB,EACjB,cAAc,EACd,kBAAuB,EACvB,GAAG,GACJ,EAAE,IAAI,GAAG,kBAAkB,CA2D3B"}
|
package/dist/index.js
CHANGED
@@ -28,7 +28,7 @@ import { updateGlobal } from './updateGlobal.js';
|
|
28
28
|
import { updateGlobalVersion } from './updateGlobalVersion.js';
|
29
29
|
import { updateOne } from './updateOne.js';
|
30
30
|
import { updateVersion } from './updateVersion.js';
|
31
|
-
export function mongooseAdapter({ autoPluralization = true, connectOptions, disableIndexHints = false, migrationDir: migrationDirArg, mongoMemoryServer, transactionOptions = {}, url }) {
|
31
|
+
export function mongooseAdapter({ autoPluralization = true, connectOptions, disableIndexHints = false, migrationDir: migrationDirArg, mongoMemoryServer, prodMigrations, transactionOptions = {}, url }) {
|
32
32
|
function adapter({ payload }) {
|
33
33
|
const migrationDir = findMigrationDir(migrationDirArg);
|
34
34
|
mongoose.set('strictQuery', false);
|
@@ -69,7 +69,9 @@ export function mongooseAdapter({ autoPluralization = true, connectOptions, disa
|
|
69
69
|
init,
|
70
70
|
migrateFresh,
|
71
71
|
migrationDir,
|
72
|
+
packageName: '@payloadcms/db-mongodb',
|
72
73
|
payload,
|
74
|
+
prodMigrations,
|
73
75
|
queryDrafts,
|
74
76
|
rollbackTransaction,
|
75
77
|
updateGlobal,
|
package/dist/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { TransactionOptions } from 'mongodb'\nimport type { MongoMemoryReplSet } from 'mongodb-memory-server'\nimport type { ClientSession, ConnectOptions, Connection } from 'mongoose'\nimport type { BaseDatabaseAdapter, DatabaseAdapterObj, Payload } from 'payload'\n\nimport fs from 'fs'\nimport mongoose from 'mongoose'\nimport path from 'path'\nimport { createDatabaseAdapter } from 'payload'\n\nimport type { CollectionModel, GlobalModel } from './types.js'\n\nimport { connect } from './connect.js'\nimport { count } from './count.js'\nimport { create } from './create.js'\nimport { createGlobal } from './createGlobal.js'\nimport { createGlobalVersion } from './createGlobalVersion.js'\nimport { createMigration } from './createMigration.js'\nimport { createVersion } from './createVersion.js'\nimport { deleteMany } from './deleteMany.js'\nimport { deleteOne } from './deleteOne.js'\nimport { deleteVersions } from './deleteVersions.js'\nimport { destroy } from './destroy.js'\nimport { find } from './find.js'\nimport { findGlobal } from './findGlobal.js'\nimport { findGlobalVersions } from './findGlobalVersions.js'\nimport { findOne } from './findOne.js'\nimport { findVersions } from './findVersions.js'\nimport { init } from './init.js'\nimport { migrateFresh } from './migrateFresh.js'\nimport { queryDrafts } from './queryDrafts.js'\nimport { beginTransaction } from './transactions/beginTransaction.js'\nimport { commitTransaction } from './transactions/commitTransaction.js'\nimport { rollbackTransaction } from './transactions/rollbackTransaction.js'\nimport { updateGlobal } from './updateGlobal.js'\nimport { updateGlobalVersion } from './updateGlobalVersion.js'\nimport { updateOne } from './updateOne.js'\nimport { updateVersion } from './updateVersion.js'\n\nexport type { MigrateDownArgs, MigrateUpArgs } from './types.js'\n\nexport interface Args {\n /** Set to false to disable auto-pluralization of collection names, Defaults to true */\n autoPluralization?: boolean\n /** Extra configuration options */\n connectOptions?: {\n /** Set false to disable $facet aggregation in non-supporting databases, Defaults to true */\n useFacet?: boolean\n } & ConnectOptions\n /** Set to true to disable hinting to MongoDB to use 'id' as index. This is currently done when counting documents for pagination. Disabling this optimization might fix some problems with AWS DocumentDB. Defaults to false */\n disableIndexHints?: boolean\n migrationDir?: string\n /**\n * typed as any to avoid dependency\n */\n mongoMemoryServer?: MongoMemoryReplSet\n transactionOptions?: TransactionOptions | false\n /** The URL to connect to MongoDB or false to start payload and prevent connecting */\n url: false | string\n}\n\nexport type MongooseAdapter = {\n collections: {\n [slug: string]: CollectionModel\n }\n connection: Connection\n globals: GlobalModel\n mongoMemoryServer: MongoMemoryReplSet\n sessions: Record<number | string, ClientSession>\n versions: {\n [slug: string]: CollectionModel\n }\n} & Args &\n BaseDatabaseAdapter\n\ndeclare module 'payload' {\n export interface DatabaseAdapter\n extends Omit<BaseDatabaseAdapter, 'sessions'>,\n Omit<Args, 'migrationDir'> {\n collections: {\n [slug: string]: CollectionModel\n }\n connection: Connection\n globals: GlobalModel\n mongoMemoryServer: MongoMemoryReplSet\n sessions: Record<number | string, ClientSession>\n transactionOptions: TransactionOptions\n versions: {\n [slug: string]: CollectionModel\n }\n }\n}\n\nexport function mongooseAdapter({\n autoPluralization = true,\n connectOptions,\n disableIndexHints = false,\n migrationDir: migrationDirArg,\n mongoMemoryServer,\n transactionOptions = {},\n url,\n}: Args): DatabaseAdapterObj {\n function adapter({ payload }: { payload: Payload }) {\n const migrationDir = findMigrationDir(migrationDirArg)\n mongoose.set('strictQuery', false)\n\n return createDatabaseAdapter<MongooseAdapter>({\n name: 'mongoose',\n\n // Mongoose-specific\n autoPluralization,\n collections: {},\n connectOptions: connectOptions || {},\n connection: undefined,\n count,\n disableIndexHints,\n globals: undefined,\n mongoMemoryServer,\n sessions: {},\n transactionOptions: transactionOptions === false ? undefined : transactionOptions,\n url,\n versions: {},\n // DatabaseAdapter\n beginTransaction: transactionOptions ? beginTransaction : undefined,\n commitTransaction,\n connect,\n create,\n createGlobal,\n createGlobalVersion,\n createMigration,\n createVersion,\n defaultIDType: 'text',\n deleteMany,\n deleteOne,\n deleteVersions,\n destroy,\n find,\n findGlobal,\n findGlobalVersions,\n findOne,\n findVersions,\n init,\n migrateFresh,\n migrationDir,\n payload,\n queryDrafts,\n rollbackTransaction,\n updateGlobal,\n updateGlobalVersion,\n updateOne,\n updateVersion,\n })\n }\n\n return {\n defaultIDType: 'text',\n init: adapter,\n }\n}\n\n/**\n * Attempt to find migrations directory.\n *\n * Checks for the following directories in order:\n * - `migrationDir` argument from Payload config\n * - `src/migrations`\n * - `dist/migrations`\n * - `migrations`\n *\n * Defaults to `src/migrations`\n *\n * @param migrationDir\n * @returns\n */\nfunction findMigrationDir(migrationDir?: string): string {\n const cwd = process.cwd()\n const srcDir = path.resolve(cwd, 'src/migrations')\n const distDir = path.resolve(cwd, 'dist/migrations')\n const relativeMigrations = path.resolve(cwd, 'migrations')\n\n // Use arg if provided\n if (migrationDir) return migrationDir\n\n // Check other common locations\n if (fs.existsSync(srcDir)) {\n return srcDir\n }\n\n if (fs.existsSync(distDir)) {\n return distDir\n }\n\n if (fs.existsSync(relativeMigrations)) {\n return relativeMigrations\n }\n\n return srcDir\n}\n"],"names":["fs","mongoose","path","createDatabaseAdapter","connect","count","create","createGlobal","createGlobalVersion","createMigration","createVersion","deleteMany","deleteOne","deleteVersions","destroy","find","findGlobal","findGlobalVersions","findOne","findVersions","init","migrateFresh","queryDrafts","beginTransaction","commitTransaction","rollbackTransaction","updateGlobal","updateGlobalVersion","updateOne","updateVersion","mongooseAdapter","autoPluralization","connectOptions","disableIndexHints","migrationDir","migrationDirArg","mongoMemoryServer","transactionOptions","url","adapter","payload","findMigrationDir","set","name","collections","connection","undefined","globals","sessions","versions","defaultIDType","cwd","process","srcDir","resolve","distDir","relativeMigrations","existsSync"],"mappings":"AAKA,OAAOA,QAAQ,KAAI;AACnB,OAAOC,cAAc,WAAU;AAC/B,OAAOC,UAAU,OAAM;AACvB,SAASC,qBAAqB,QAAQ,UAAS;AAI/C,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,KAAK,QAAQ,aAAY;AAClC,SAASC,MAAM,QAAQ,cAAa;AACpC,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,SAASC,eAAe,QAAQ,uBAAsB;AACtD,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,UAAU,QAAQ,kBAAiB;AAC5C,SAASC,SAAS,QAAQ,iBAAgB;AAC1C,SAASC,cAAc,QAAQ,sBAAqB;AACpD,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,IAAI,QAAQ,YAAW;AAChC,SAASC,UAAU,QAAQ,kBAAiB;AAC5C,SAASC,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,IAAI,QAAQ,YAAW;AAChC,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,WAAW,QAAQ,mBAAkB;AAC9C,SAASC,gBAAgB,QAAQ,qCAAoC;AACrE,SAASC,iBAAiB,QAAQ,sCAAqC;AACvE,SAASC,mBAAmB,QAAQ,wCAAuC;A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IAC/B,IAAIlC,GAAGyD,UAAU,CAACJ,SAAS;QACzB,OAAOA;IACT;IAEA,IAAIrD,GAAGyD,UAAU,CAACF,UAAU;QAC1B,OAAOA;IACT;IAEA,IAAIvD,GAAGyD,UAAU,CAACD,qBAAqB;QACrC,OAAOA;IACT;IAEA,OAAOH;AACT"}
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { CollationOptions, TransactionOptions } from 'mongodb'\nimport type { MongoMemoryReplSet } from 'mongodb-memory-server'\nimport type { ClientSession, ConnectOptions, Connection } from 'mongoose'\nimport type { BaseDatabaseAdapter, DatabaseAdapterObj, Payload } from 'payload'\n\nimport fs from 'fs'\nimport mongoose from 'mongoose'\nimport path from 'path'\nimport { createDatabaseAdapter } from 'payload'\n\nimport type { CollectionModel, GlobalModel, MigrateDownArgs, MigrateUpArgs } from './types.js'\n\nimport { connect } from './connect.js'\nimport { count } from './count.js'\nimport { create } from './create.js'\nimport { createGlobal } from './createGlobal.js'\nimport { createGlobalVersion } from './createGlobalVersion.js'\nimport { createMigration } from './createMigration.js'\nimport { createVersion } from './createVersion.js'\nimport { deleteMany } from './deleteMany.js'\nimport { deleteOne } from './deleteOne.js'\nimport { deleteVersions } from './deleteVersions.js'\nimport { destroy } from './destroy.js'\nimport { find } from './find.js'\nimport { findGlobal } from './findGlobal.js'\nimport { findGlobalVersions } from './findGlobalVersions.js'\nimport { findOne } from './findOne.js'\nimport { findVersions } from './findVersions.js'\nimport { init } from './init.js'\nimport { migrateFresh } from './migrateFresh.js'\nimport { queryDrafts } from './queryDrafts.js'\nimport { beginTransaction } from './transactions/beginTransaction.js'\nimport { commitTransaction } from './transactions/commitTransaction.js'\nimport { rollbackTransaction } from './transactions/rollbackTransaction.js'\nimport { updateGlobal } from './updateGlobal.js'\nimport { updateGlobalVersion } from './updateGlobalVersion.js'\nimport { updateOne } from './updateOne.js'\nimport { updateVersion } from './updateVersion.js'\n\nexport type { MigrateDownArgs, MigrateUpArgs } from './types.js'\n\nexport interface Args {\n /** Set to false to disable auto-pluralization of collection names, Defaults to true */\n autoPluralization?: boolean\n /**\n * If enabled, collation allows for language-specific rules for string comparison.\n * This configuration can include the following options:\n *\n * - `strength` (number): Comparison level (1: Primary, 2: Secondary, 3: Tertiary (default), 4: Quaternary, 5: Identical)\n * - `caseLevel` (boolean): Include case comparison at strength level 1 or 2.\n * - `caseFirst` (string): Sort order of case differences during tertiary level comparisons (\"upper\", \"lower\", \"off\").\n * - `numericOrdering` (boolean): Compare numeric strings as numbers.\n * - `alternate` (string): Consider whitespace and punctuation as base characters (\"non-ignorable\", \"shifted\").\n * - `maxVariable` (string): Characters considered ignorable when `alternate` is \"shifted\" (\"punct\", \"space\").\n * - `backwards` (boolean): Sort strings with diacritics from back of the string.\n * - `normalization` (boolean): Check if text requires normalization and perform normalization.\n *\n * Available on MongoDB version 3.4 and up.\n * The locale that gets passed is your current project's locale but defaults to \"en\".\n *\n * Example:\n * {\n * strength: 3\n * }\n *\n * Defaults to disabled.\n */\n collation?: Omit<CollationOptions, 'locale'>\n /** Extra configuration options */\n connectOptions?: {\n /** Set false to disable $facet aggregation in non-supporting databases, Defaults to true */\n useFacet?: boolean\n } & ConnectOptions\n /** Set to true to disable hinting to MongoDB to use 'id' as index. This is currently done when counting documents for pagination. Disabling this optimization might fix some problems with AWS DocumentDB. Defaults to false */\n disableIndexHints?: boolean\n migrationDir?: string\n /**\n * typed as any to avoid dependency\n */\n mongoMemoryServer?: MongoMemoryReplSet\n prodMigrations?: {\n down: (args: MigrateDownArgs) => Promise<void>\n name: string\n up: (args: MigrateUpArgs) => Promise<void>\n }[]\n transactionOptions?: TransactionOptions | false\n /** The URL to connect to MongoDB or false to start payload and prevent connecting */\n url: false | string\n}\n\nexport type MongooseAdapter = {\n collections: {\n [slug: string]: CollectionModel\n }\n connection: Connection\n globals: GlobalModel\n mongoMemoryServer: MongoMemoryReplSet\n prodMigrations?: {\n down: (args: MigrateDownArgs) => Promise<void>\n name: string\n up: (args: MigrateUpArgs) => Promise<void>\n }[]\n sessions: Record<number | string, ClientSession>\n versions: {\n [slug: string]: CollectionModel\n }\n} & Args &\n BaseDatabaseAdapter\n\ndeclare module 'payload' {\n export interface DatabaseAdapter\n extends Omit<BaseDatabaseAdapter, 'sessions'>,\n Omit<Args, 'migrationDir'> {\n collections: {\n [slug: string]: CollectionModel\n }\n connection: Connection\n globals: GlobalModel\n mongoMemoryServer: MongoMemoryReplSet\n prodMigrations?: {\n down: (args: MigrateDownArgs) => Promise<void>\n name: string\n up: (args: MigrateUpArgs) => Promise<void>\n }[]\n sessions: Record<number | string, ClientSession>\n transactionOptions: TransactionOptions\n versions: {\n [slug: string]: CollectionModel\n }\n }\n}\n\nexport function mongooseAdapter({\n autoPluralization = true,\n connectOptions,\n disableIndexHints = false,\n migrationDir: migrationDirArg,\n mongoMemoryServer,\n prodMigrations,\n transactionOptions = {},\n url,\n}: Args): DatabaseAdapterObj {\n function adapter({ payload }: { payload: Payload }) {\n const migrationDir = findMigrationDir(migrationDirArg)\n mongoose.set('strictQuery', false)\n\n return createDatabaseAdapter<MongooseAdapter>({\n name: 'mongoose',\n\n // Mongoose-specific\n autoPluralization,\n collections: {},\n connectOptions: connectOptions || {},\n connection: undefined,\n count,\n disableIndexHints,\n globals: undefined,\n mongoMemoryServer,\n sessions: {},\n transactionOptions: transactionOptions === false ? undefined : transactionOptions,\n url,\n versions: {},\n // DatabaseAdapter\n beginTransaction: transactionOptions ? beginTransaction : undefined,\n commitTransaction,\n connect,\n create,\n createGlobal,\n createGlobalVersion,\n createMigration,\n createVersion,\n defaultIDType: 'text',\n deleteMany,\n deleteOne,\n deleteVersions,\n destroy,\n find,\n findGlobal,\n findGlobalVersions,\n findOne,\n findVersions,\n init,\n migrateFresh,\n migrationDir,\n packageName: '@payloadcms/db-mongodb',\n payload,\n prodMigrations,\n queryDrafts,\n rollbackTransaction,\n updateGlobal,\n updateGlobalVersion,\n updateOne,\n updateVersion,\n })\n }\n\n return {\n defaultIDType: 'text',\n init: adapter,\n }\n}\n\n/**\n * Attempt to find migrations directory.\n *\n * Checks for the following directories in order:\n * - `migrationDir` argument from Payload config\n * - `src/migrations`\n * - `dist/migrations`\n * - `migrations`\n *\n * Defaults to `src/migrations`\n *\n * @param migrationDir\n * @returns\n */\nfunction findMigrationDir(migrationDir?: string): string {\n const cwd = process.cwd()\n const srcDir = path.resolve(cwd, 'src/migrations')\n const distDir = path.resolve(cwd, 'dist/migrations')\n const relativeMigrations = path.resolve(cwd, 'migrations')\n\n // Use arg if provided\n if (migrationDir) return migrationDir\n\n // Check other common locations\n if (fs.existsSync(srcDir)) {\n return srcDir\n }\n\n if (fs.existsSync(distDir)) {\n return distDir\n }\n\n if (fs.existsSync(relativeMigrations)) {\n return relativeMigrations\n }\n\n return srcDir\n}\n"],"names":["fs","mongoose","path","createDatabaseAdapter","connect","count","create","createGlobal","createGlobalVersion","createMigration","createVersion","deleteMany","deleteOne","deleteVersions","destroy","find","findGlobal","findGlobalVersions","findOne","findVersions","init","migrateFresh","queryDrafts","beginTransaction","commitTransaction","rollbackTransaction","updateGlobal","updateGlobalVersion","updateOne","updateVersion","mongooseAdapter","autoPluralization","connectOptions","disableIndexHints","migrationDir","migrationDirArg","mongoMemoryServer","prodMigrations","transactionOptions","url","adapter","payload","findMigrationDir","set","name","collections","connection","undefined","globals","sessions","versions","defaultIDType","packageName","cwd","process","srcDir","resolve","distDir","relativeMigrations","existsSync"],"mappings":"AAKA,OAAOA,QAAQ,KAAI;AACnB,OAAOC,cAAc,WAAU;AAC/B,OAAOC,UAAU,OAAM;AACvB,SAASC,qBAAqB,QAAQ,UAAS;AAI/C,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,KAAK,QAAQ,aAAY;AAClC,SAASC,MAAM,QAAQ,cAAa;AACpC,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,SAASC,eAAe,QAAQ,uBAAsB;AACtD,SAASC,aAAa,QAAQ,qB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B;YAC1DvB;YACApB;YACAE;YACAC;YACAC;YACAC;YACAC;YACAyC,eAAe;YACfxC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAa;YACAkB,aAAa;YACbX;YACAJ;YACAf;YACAG;YACAC;YACAC;YACAC;YACAC;QACF;IACF;IAEA,OAAO;QACLsB,eAAe;QACf/B,MAAMoB;IACR;AACF;AAEA;;;;;;;;;;;;;CAaC,GACD,SAASE,iBAAiBR,YAAqB;IAC7C,MAAMmB,MAAMC,QAAQD,GAAG;IACvB,MAAME,SAASrD,KAAKsD,OAAO,CAACH,KAAK;IACjC,MAAMI,UAAUvD,KAAKsD,OAAO,CAACH,KAAK;IAClC,MAAMK,qBAAqBxD,KAAKsD,OAAO,CAACH,KAAK;IAE7C,sBAAsB;IACtB,IAAInB,cAAc,OAAOA;IAEzB,+BAA+B;IAC/B,IAAIlC,GAAG2D,UAAU,CAACJ,SAAS;QACzB,OAAOA;IACT;IAEA,IAAIvD,GAAG2D,UAAU,CAACF,UAAU;QAC1B,OAAOA;IACT;IAEA,IAAIzD,GAAG2D,UAAU,CAACD,qBAAqB;QACrC,OAAOA;IACT;IAEA,OAAOH;AACT"}
|
@@ -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,yBAAyB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAOzE,QAAA,MAAM,qBAAqB,eACb,yBAAyB,UAC7B,eAAe,yBAEtB,
|
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,yBAAyB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAOzE,QAAA,MAAM,qBAAqB,eACb,yBAAyB,UAC7B,eAAe,yBAEtB,MAiCF,CAAA;AAED,eAAe,qBAAqB,CAAA"}
|
@@ -11,6 +11,15 @@ const buildCollectionSchema = (collection, config, schemaOptions = {})=>{
|
|
11
11
|
...schemaOptions
|
12
12
|
}
|
13
13
|
});
|
14
|
+
if (Array.isArray(collection.upload.filenameCompoundIndex)) {
|
15
|
+
const indexDefinition = collection.upload.filenameCompoundIndex.reduce((acc, index)=>{
|
16
|
+
acc[index] = 1;
|
17
|
+
return acc;
|
18
|
+
}, {});
|
19
|
+
schema.index(indexDefinition, {
|
20
|
+
unique: true
|
21
|
+
});
|
22
|
+
}
|
14
23
|
if (config.indexSortableFields && collection.timestamps !== false) {
|
15
24
|
schema.index({
|
16
25
|
updatedAt: 1
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/models/buildCollectionSchema.ts"],"sourcesContent":["import type { PaginateOptions, Schema } from 'mongoose'\nimport type { SanitizedCollectionConfig, SanitizedConfig } from 'payload'\n\nimport paginate from 'mongoose-paginate-v2'\n\nimport getBuildQueryPlugin from '../queries/buildQuery.js'\nimport buildSchema from './buildSchema.js'\n\nconst buildCollectionSchema = (\n collection: SanitizedCollectionConfig,\n config: SanitizedConfig,\n schemaOptions = {},\n): Schema => {\n const schema = buildSchema(config, collection.fields, {\n draftsEnabled: Boolean(typeof collection?.versions === 'object' && collection.versions.drafts),\n indexSortableFields: config.indexSortableFields,\n options: {\n minimize: false,\n timestamps: collection.timestamps !== false,\n ...schemaOptions,\n },\n })\n\n if (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 return schema\n}\n\nexport default buildCollectionSchema\n"],"names":["paginate","getBuildQueryPlugin","buildSchema","buildCollectionSchema","collection","config","schemaOptions","schema","fields","draftsEnabled","Boolean","versions","drafts","indexSortableFields","options","minimize","timestamps","index","updatedAt","createdAt","plugin","useEstimatedCount","collectionSlug","slug"],"mappings":"AAGA,OAAOA,cAAc,uBAAsB;AAE3C,OAAOC,yBAAyB,2BAA0B;AAC1D,OAAOC,iBAAiB,mBAAkB;AAE1C,MAAMC,wBAAwB,CAC5BC,YACAC,QACAC,gBAAgB,CAAC,CAAC;IAElB,MAAMC,SAASL,YAAYG,QAAQD,WAAWI,MAAM,EAAE;QACpDC,eAAeC,QAAQ,OAAON,YAAYO,aAAa,YAAYP,WAAWO,QAAQ,CAACC,MAAM;QAC7FC,qBAAqBR,OAAOQ,mBAAmB;QAC/CC,SAAS;YACPC,UAAU;YACVC,YAAYZ,WAAWY,UAAU,KAAK;YACtC,GAAGV,aAAa;QAClB;IACF;IAEA,
|
1
|
+
{"version":3,"sources":["../../src/models/buildCollectionSchema.ts"],"sourcesContent":["import type { PaginateOptions, Schema } from 'mongoose'\nimport type { SanitizedCollectionConfig, SanitizedConfig } from 'payload'\n\nimport paginate from 'mongoose-paginate-v2'\n\nimport getBuildQueryPlugin from '../queries/buildQuery.js'\nimport buildSchema from './buildSchema.js'\n\nconst buildCollectionSchema = (\n collection: SanitizedCollectionConfig,\n config: SanitizedConfig,\n schemaOptions = {},\n): Schema => {\n const schema = buildSchema(config, collection.fields, {\n draftsEnabled: Boolean(typeof collection?.versions === 'object' && collection.versions.drafts),\n indexSortableFields: 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 (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 return schema\n}\n\nexport default buildCollectionSchema\n"],"names":["paginate","getBuildQueryPlugin","buildSchema","buildCollectionSchema","collection","config","schemaOptions","schema","fields","draftsEnabled","Boolean","versions","drafts","indexSortableFields","options","minimize","timestamps","Array","isArray","upload","filenameCompoundIndex","indexDefinition","reduce","acc","index","unique","updatedAt","createdAt","plugin","useEstimatedCount","collectionSlug","slug"],"mappings":"AAGA,OAAOA,cAAc,uBAAsB;AAE3C,OAAOC,yBAAyB,2BAA0B;AAC1D,OAAOC,iBAAiB,mBAAkB;AAE1C,MAAMC,wBAAwB,CAC5BC,YACAC,QACAC,gBAAgB,CAAC,CAAC;IAElB,MAAMC,SAASL,YAAYG,QAAQD,WAAWI,MAAM,EAAE;QACpDC,eAAeC,QAAQ,OAAON,YAAYO,aAAa,YAAYP,WAAWO,QAAQ,CAACC,MAAM;QAC7FC,qBAAqBR,OAAOQ,mBAAmB;QAC/CC,SAAS;YACPC,UAAU;YACVC,YAAYZ,WAAWY,UAAU,KAAK;YACtC,GAAGV,aAAa;QAClB;IACF;IAEA,IAAIW,MAAMC,OAAO,CAACd,WAAWe,MAAM,CAACC,qBAAqB,GAAG;QAC1D,MAAMC,kBAAqCjB,WAAWe,MAAM,CAACC,qBAAqB,CAACE,MAAM,CACvF,CAACC,KAAKC;YACJD,GAAG,CAACC,MAAM,GAAG;YACb,OAAOD;QACT,GACA,CAAC;QAGHhB,OAAOiB,KAAK,CAACH,iBAAiB;YAAEI,QAAQ;QAAK;IAC/C;IAEA,IAAIpB,OAAOQ,mBAAmB,IAAIT,WAAWY,UAAU,KAAK,OAAO;QACjET,OAAOiB,KAAK,CAAC;YAAEE,WAAW;QAAE;QAC5BnB,OAAOiB,KAAK,CAAC;YAAEG,WAAW;QAAE;IAC9B;IAEApB,OACGqB,MAAM,CAAuB5B,UAAU;QAAE6B,mBAAmB;IAAK,GACjED,MAAM,CAAC3B,oBAAoB;QAAE6B,gBAAgB1B,WAAW2B,IAAI;IAAC;IAEhE,OAAOxB;AACT;AAEA,eAAeJ,sBAAqB"}
|
@@ -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;AACtF,OAAO,KAAK,EASV,KAAK,EAWL,eAAe,EAQhB,MAAM,SAAS,CAAA;AAUhB,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;
|
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;AACtF,OAAO,KAAK,EASV,KAAK,EAWL,eAAe,EAQhB,MAAM,SAAS,CAAA;AAUhB,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,QAAA,MAAM,WAAW,WACP,eAAe,gBACT,KAAK,EAAE,uBACD,kBAAkB,KACrC,MA+BF,CAAA;AA4gBD,eAAe,WAAW,CAAA"}
|
@@ -1,8 +1,13 @@
|
|
1
1
|
import mongoose from 'mongoose';
|
2
2
|
import { fieldAffectsData, fieldIsLocalized, fieldIsPresentationalOnly, tabHasName } from 'payload/shared';
|
3
|
+
/**
|
4
|
+
* get a field's defaultValue only if defined and not dynamic so that it can be set on the field schema
|
5
|
+
* @param field
|
6
|
+
*/ const formatDefaultValue = (field)=>typeof field.defaultValue !== 'undefined' && typeof field.defaultValue !== 'function' ? field.defaultValue : undefined;
|
3
7
|
const formatBaseSchema = (field, buildSchemaOptions)=>{
|
4
8
|
const { disableUnique, draftsEnabled, indexSortableFields } = buildSchemaOptions;
|
5
9
|
const schema = {
|
10
|
+
default: formatDefaultValue(field),
|
6
11
|
index: field.index || !disableUnique && field.unique || indexSortableFields || false,
|
7
12
|
required: false,
|
8
13
|
unique: !disableUnique && field.unique || false
|
@@ -68,8 +73,7 @@ const fieldToSchemaMap = {
|
|
68
73
|
minimize: false
|
69
74
|
}
|
70
75
|
})
|
71
|
-
]
|
72
|
-
default: undefined
|
76
|
+
]
|
73
77
|
};
|
74
78
|
schema.add({
|
75
79
|
[field.name]: localizeSchema(field, baseSchema, config.localization)
|
@@ -82,8 +86,7 @@ const fieldToSchemaMap = {
|
|
82
86
|
_id: false,
|
83
87
|
discriminatorKey: 'blockType'
|
84
88
|
})
|
85
|
-
]
|
86
|
-
default: undefined
|
89
|
+
]
|
87
90
|
};
|
88
91
|
schema.add({
|
89
92
|
[field.name]: localizeSchema(field, fieldSchema, config.localization)
|
@@ -207,7 +210,7 @@ const fieldToSchemaMap = {
|
|
207
210
|
type: [
|
208
211
|
Number
|
209
212
|
],
|
210
|
-
default: field
|
213
|
+
default: formatDefaultValue(field),
|
211
214
|
required: false
|
212
215
|
}
|
213
216
|
};
|
@@ -283,7 +286,7 @@ const fieldToSchemaMap = {
|
|
283
286
|
type: [
|
284
287
|
localeSchema
|
285
288
|
],
|
286
|
-
default:
|
289
|
+
default: formatDefaultValue(field)
|
287
290
|
} : localeSchema
|
288
291
|
};
|
289
292
|
}, {}),
|
@@ -308,7 +311,7 @@ const fieldToSchemaMap = {
|
|
308
311
|
type: [
|
309
312
|
schemaToReturn
|
310
313
|
],
|
311
|
-
default:
|
314
|
+
default: formatDefaultValue(field)
|
312
315
|
};
|
313
316
|
}
|
314
317
|
} else {
|
@@ -322,7 +325,7 @@ const fieldToSchemaMap = {
|
|
322
325
|
type: [
|
323
326
|
schemaToReturn
|
324
327
|
],
|
325
|
-
default:
|
328
|
+
default: formatDefaultValue(field)
|
326
329
|
};
|
327
330
|
}
|
328
331
|
}
|
@@ -413,13 +416,84 @@ const fieldToSchemaMap = {
|
|
413
416
|
});
|
414
417
|
},
|
415
418
|
upload: (field, schema, config, buildSchemaOptions)=>{
|
416
|
-
const
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
419
|
+
const hasManyRelations = Array.isArray(field.relationTo);
|
420
|
+
let schemaToReturn = {};
|
421
|
+
if (field.localized && config.localization) {
|
422
|
+
schemaToReturn = {
|
423
|
+
type: config.localization.localeCodes.reduce((locales, locale)=>{
|
424
|
+
let localeSchema = {};
|
425
|
+
if (hasManyRelations) {
|
426
|
+
localeSchema = {
|
427
|
+
...formatBaseSchema(field, buildSchemaOptions),
|
428
|
+
_id: false,
|
429
|
+
type: mongoose.Schema.Types.Mixed,
|
430
|
+
relationTo: {
|
431
|
+
type: String,
|
432
|
+
enum: field.relationTo
|
433
|
+
},
|
434
|
+
value: {
|
435
|
+
type: mongoose.Schema.Types.Mixed,
|
436
|
+
refPath: `${field.name}.${locale}.relationTo`
|
437
|
+
}
|
438
|
+
};
|
439
|
+
} else {
|
440
|
+
localeSchema = {
|
441
|
+
...formatBaseSchema(field, buildSchemaOptions),
|
442
|
+
type: mongoose.Schema.Types.Mixed,
|
443
|
+
ref: field.relationTo
|
444
|
+
};
|
445
|
+
}
|
446
|
+
return {
|
447
|
+
...locales,
|
448
|
+
[locale]: field.hasMany ? {
|
449
|
+
type: [
|
450
|
+
localeSchema
|
451
|
+
],
|
452
|
+
default: formatDefaultValue(field)
|
453
|
+
} : localeSchema
|
454
|
+
};
|
455
|
+
}, {}),
|
456
|
+
localized: true
|
457
|
+
};
|
458
|
+
} else if (hasManyRelations) {
|
459
|
+
schemaToReturn = {
|
460
|
+
...formatBaseSchema(field, buildSchemaOptions),
|
461
|
+
_id: false,
|
462
|
+
type: mongoose.Schema.Types.Mixed,
|
463
|
+
relationTo: {
|
464
|
+
type: String,
|
465
|
+
enum: field.relationTo
|
466
|
+
},
|
467
|
+
value: {
|
468
|
+
type: mongoose.Schema.Types.Mixed,
|
469
|
+
refPath: `${field.name}.relationTo`
|
470
|
+
}
|
471
|
+
};
|
472
|
+
if (field.hasMany) {
|
473
|
+
schemaToReturn = {
|
474
|
+
type: [
|
475
|
+
schemaToReturn
|
476
|
+
],
|
477
|
+
default: formatDefaultValue(field)
|
478
|
+
};
|
479
|
+
}
|
480
|
+
} else {
|
481
|
+
schemaToReturn = {
|
482
|
+
...formatBaseSchema(field, buildSchemaOptions),
|
483
|
+
type: mongoose.Schema.Types.Mixed,
|
484
|
+
ref: field.relationTo
|
485
|
+
};
|
486
|
+
if (field.hasMany) {
|
487
|
+
schemaToReturn = {
|
488
|
+
type: [
|
489
|
+
schemaToReturn
|
490
|
+
],
|
491
|
+
default: formatDefaultValue(field)
|
492
|
+
};
|
493
|
+
}
|
494
|
+
}
|
421
495
|
schema.add({
|
422
|
-
[field.name]:
|
496
|
+
[field.name]: schemaToReturn
|
423
497
|
});
|
424
498
|
}
|
425
499
|
};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/models/buildSchema.ts"],"sourcesContent":["import type { IndexOptions, Schema, SchemaOptions, SchemaTypeOptions } from 'mongoose'\nimport type {\n ArrayField,\n Block,\n BlockField,\n CheckboxField,\n CodeField,\n CollapsibleField,\n DateField,\n EmailField,\n Field,\n FieldAffectingData,\n GroupField,\n JSONField,\n NonPresentationalField,\n NumberField,\n PointField,\n RadioField,\n RelationshipField,\n RichTextField,\n RowField,\n SanitizedConfig,\n SanitizedLocalizationConfig,\n SelectField,\n Tab,\n TabsField,\n TextField,\n TextareaField,\n UploadField,\n} from 'payload'\n\nimport mongoose from 'mongoose'\nimport {\n fieldAffectsData,\n fieldIsLocalized,\n fieldIsPresentationalOnly,\n tabHasName,\n} from 'payload/shared'\n\nexport type BuildSchemaOptions = {\n allowIDField?: boolean\n disableUnique?: boolean\n draftsEnabled?: boolean\n indexSortableFields?: boolean\n options?: SchemaOptions\n}\n\ntype FieldSchemaGenerator = (\n field: Field,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n) => void\n\nconst formatBaseSchema = (field: FieldAffectingData, buildSchemaOptions: BuildSchemaOptions) => {\n const { disableUnique, draftsEnabled, indexSortableFields } = buildSchemaOptions\n const schema: SchemaTypeOptions<unknown> = {\n index: field.index || (!disableUnique && field.unique) || indexSortableFields || false,\n required: false,\n unique: (!disableUnique && field.unique) || false,\n }\n\n if (\n schema.unique &&\n (field.localized ||\n draftsEnabled ||\n (fieldAffectsData(field) &&\n field.type !== 'group' &&\n field.type !== 'tab' &&\n field.required !== true))\n ) {\n schema.sparse = true\n }\n\n if (field.hidden) {\n schema.hidden = true\n }\n\n return schema\n}\n\nconst localizeSchema = (\n entity: NonPresentationalField | Tab,\n schema,\n localization: SanitizedLocalizationConfig | false,\n) => {\n if (fieldIsLocalized(entity) && localization && Array.isArray(localization.locales)) {\n return {\n type: localization.localeCodes.reduce(\n (localeSchema, locale) => ({\n ...localeSchema,\n [locale]: schema,\n }),\n {\n _id: false,\n },\n ),\n localized: true,\n }\n }\n return schema\n}\n\nconst buildSchema = (\n config: SanitizedConfig,\n configFields: Field[],\n buildSchemaOptions: BuildSchemaOptions = {},\n): Schema => {\n const { allowIDField, options } = buildSchemaOptions\n let fields = {}\n\n let schemaFields = configFields\n\n if (!allowIDField) {\n const idField = schemaFields.find((field) => fieldAffectsData(field) && field.name === 'id')\n if (idField) {\n fields = {\n _id: idField.type === 'number' ? Number : String,\n }\n schemaFields = schemaFields.filter(\n (field) => !(fieldAffectsData(field) && field.name === 'id'),\n )\n }\n }\n\n const schema = new mongoose.Schema(fields, options)\n\n schemaFields.forEach((field) => {\n if (!fieldIsPresentationalOnly(field)) {\n const addFieldSchema: FieldSchemaGenerator = fieldToSchemaMap[field.type]\n\n if (addFieldSchema) {\n addFieldSchema(field, schema, config, buildSchemaOptions)\n }\n }\n })\n\n return schema\n}\n\nconst fieldToSchemaMap: Record<string, FieldSchemaGenerator> = {\n array: (\n field: ArrayField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ) => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: [\n buildSchema(config, field.fields, {\n allowIDField: true,\n disableUnique: buildSchemaOptions.disableUnique,\n draftsEnabled: buildSchemaOptions.draftsEnabled,\n options: {\n _id: false,\n id: false,\n minimize: false,\n },\n }),\n ],\n default: undefined,\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n blocks: (\n field: BlockField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const fieldSchema = {\n type: [new mongoose.Schema({}, { _id: false, discriminatorKey: 'blockType' })],\n default: undefined,\n }\n\n schema.add({\n [field.name]: localizeSchema(field, fieldSchema, config.localization),\n })\n\n field.blocks.forEach((blockItem: Block) => {\n const blockSchema = new mongoose.Schema({}, { _id: false, id: false })\n\n blockItem.fields.forEach((blockField) => {\n const addFieldSchema: FieldSchemaGenerator = fieldToSchemaMap[blockField.type]\n if (addFieldSchema) {\n addFieldSchema(blockField, blockSchema, config, buildSchemaOptions)\n }\n })\n\n if (field.localized && config.localization) {\n config.localization.localeCodes.forEach((localeCode) => {\n // @ts-expect-error Possible incorrect typing in mongoose types, this works\n schema.path(`${field.name}.${localeCode}`).discriminator(blockItem.slug, blockSchema)\n })\n } else {\n // @ts-expect-error Possible incorrect typing in mongoose types, this works\n schema.path(field.name).discriminator(blockItem.slug, blockSchema)\n }\n })\n },\n checkbox: (\n field: CheckboxField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = { ...formatBaseSchema(field, buildSchemaOptions), type: Boolean }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n code: (\n field: CodeField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = { ...formatBaseSchema(field, buildSchemaOptions), type: String }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n collapsible: (\n field: CollapsibleField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n field.fields.forEach((subField: Field) => {\n const addFieldSchema: FieldSchemaGenerator = fieldToSchemaMap[subField.type]\n\n if (addFieldSchema) {\n addFieldSchema(subField, schema, config, buildSchemaOptions)\n }\n })\n },\n date: (\n field: DateField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = { ...formatBaseSchema(field, buildSchemaOptions), type: Date }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n email: (\n field: EmailField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = { ...formatBaseSchema(field, buildSchemaOptions), type: String }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n group: (\n field: GroupField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const formattedBaseSchema = formatBaseSchema(field, buildSchemaOptions)\n\n // carry indexSortableFields through to versions if drafts enabled\n const indexSortableFields =\n buildSchemaOptions.indexSortableFields &&\n field.name === 'version' &&\n buildSchemaOptions.draftsEnabled\n\n const baseSchema = {\n ...formattedBaseSchema,\n type: buildSchema(config, field.fields, {\n disableUnique: buildSchemaOptions.disableUnique,\n draftsEnabled: buildSchemaOptions.draftsEnabled,\n indexSortableFields,\n options: {\n _id: false,\n id: false,\n minimize: false,\n },\n }),\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n json: (\n field: JSONField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: mongoose.Schema.Types.Mixed,\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n number: (\n field: NumberField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: field.hasMany ? [Number] : Number,\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n point: (\n field: PointField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema: SchemaTypeOptions<unknown> = {\n type: {\n type: String,\n enum: ['Point'],\n },\n coordinates: {\n type: [Number],\n default: field.defaultValue || undefined,\n required: false,\n },\n }\n if (buildSchemaOptions.disableUnique && field.unique && field.localized) {\n baseSchema.coordinates.sparse = true\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n\n if (field.index === true || field.index === undefined) {\n const indexOptions: IndexOptions = {}\n if (!buildSchemaOptions.disableUnique && field.unique) {\n indexOptions.sparse = true\n indexOptions.unique = true\n }\n if (field.localized && config.localization) {\n config.localization.locales.forEach((locale) => {\n schema.index({ [`${field.name}.${locale.code}`]: '2dsphere' }, indexOptions)\n })\n } else {\n schema.index({ [field.name]: '2dsphere' }, indexOptions)\n }\n }\n },\n radio: (\n field: RadioField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: String,\n enum: field.options.map((option) => {\n if (typeof option === 'object') return option.value\n return option\n }),\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n relationship: (\n field: RelationshipField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ) => {\n const hasManyRelations = Array.isArray(field.relationTo)\n let schemaToReturn: { [key: string]: any } = {}\n\n if (field.localized && config.localization) {\n schemaToReturn = {\n type: config.localization.localeCodes.reduce((locales, locale) => {\n let localeSchema: { [key: string]: any } = {}\n\n if (hasManyRelations) {\n localeSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n _id: false,\n type: mongoose.Schema.Types.Mixed,\n relationTo: { type: String, enum: field.relationTo },\n value: {\n type: mongoose.Schema.Types.Mixed,\n refPath: `${field.name}.${locale}.relationTo`,\n },\n }\n } else {\n localeSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: mongoose.Schema.Types.Mixed,\n ref: field.relationTo,\n }\n }\n\n return {\n ...locales,\n [locale]: field.hasMany ? { type: [localeSchema], default: undefined } : localeSchema,\n }\n }, {}),\n localized: true,\n }\n } else if (hasManyRelations) {\n schemaToReturn = {\n ...formatBaseSchema(field, buildSchemaOptions),\n _id: false,\n type: mongoose.Schema.Types.Mixed,\n relationTo: { type: String, enum: field.relationTo },\n value: {\n type: mongoose.Schema.Types.Mixed,\n refPath: `${field.name}.relationTo`,\n },\n }\n\n if (field.hasMany) {\n schemaToReturn = {\n type: [schemaToReturn],\n default: undefined,\n }\n }\n } else {\n schemaToReturn = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: mongoose.Schema.Types.Mixed,\n ref: field.relationTo,\n }\n\n if (field.hasMany) {\n schemaToReturn = {\n type: [schemaToReturn],\n default: undefined,\n }\n }\n }\n\n schema.add({\n [field.name]: schemaToReturn,\n })\n },\n richText: (\n field: RichTextField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: mongoose.Schema.Types.Mixed,\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n row: (\n field: RowField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n field.fields.forEach((subField: Field) => {\n const addFieldSchema: FieldSchemaGenerator = fieldToSchemaMap[subField.type]\n\n if (addFieldSchema) {\n addFieldSchema(subField, schema, config, buildSchemaOptions)\n }\n })\n },\n select: (\n field: SelectField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: String,\n enum: field.options.map((option) => {\n if (typeof option === 'object') return option.value\n return option\n }),\n }\n\n if (buildSchemaOptions.draftsEnabled || !field.required) {\n baseSchema.enum.push(null)\n }\n\n schema.add({\n [field.name]: localizeSchema(\n field,\n field.hasMany ? [baseSchema] : baseSchema,\n config.localization,\n ),\n })\n },\n tabs: (\n field: TabsField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n field.tabs.forEach((tab) => {\n if (tabHasName(tab)) {\n const baseSchema = {\n type: buildSchema(config, tab.fields, {\n disableUnique: buildSchemaOptions.disableUnique,\n draftsEnabled: buildSchemaOptions.draftsEnabled,\n options: {\n _id: false,\n id: false,\n minimize: false,\n },\n }),\n }\n\n schema.add({\n [tab.name]: localizeSchema(tab, baseSchema, config.localization),\n })\n } else {\n tab.fields.forEach((subField: Field) => {\n const addFieldSchema: FieldSchemaGenerator = fieldToSchemaMap[subField.type]\n\n if (addFieldSchema) {\n addFieldSchema(subField, schema, config, buildSchemaOptions)\n }\n })\n }\n })\n },\n text: (\n field: TextField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: field.hasMany ? [String] : String,\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n textarea: (\n field: TextareaField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = { ...formatBaseSchema(field, buildSchemaOptions), type: String }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n upload: (\n field: UploadField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: mongoose.Schema.Types.Mixed,\n ref: field.relationTo,\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n}\n\nexport default buildSchema\n"],"names":["mongoose","fieldAffectsData","fieldIsLocalized","fieldIsPresentationalOnly","tabHasName","formatBaseSchema","field","buildSchemaOptions","disableUnique","draftsEnabled","indexSortableFields","schema","index","unique","required","localized","type","sparse","hidden","localizeSchema","entity","localization","Array","isArray","locales","localeCodes","reduce","localeSchema","locale","_id","buildSchema","config","configFields","allowIDField","options","fields","schemaFields","idField","find","name","Number","String","filter","Schema","forEach","addFieldSchema","fieldToSchemaMap","array","baseSchema","id","minimize","default","undefined","add","blocks","fieldSchema","discriminatorKey","blockItem","blockSchema","blockField","localeCode","path","discriminator","slug","checkbox","Boolean","code","collapsible","subField","date","Date","email","group","formattedBaseSchema","json","Types","Mixed","number","hasMany","point","enum","coordinates","defaultValue","indexOptions","radio","map","option","value","relationship","hasManyRelations","relationTo","schemaToReturn","refPath","ref","richText","row","select","push","tabs","tab","text","textarea","upload"],"mappings":"AA+BA,OAAOA,cAAc,WAAU;AAC/B,SACEC,gBAAgB,EAChBC,gBAAgB,EAChBC,yBAAyB,EACzBC,UAAU,QACL,iBAAgB;AAiBvB,MAAMC,mBAAmB,CAACC,OAA2BC;IACnD,MAAM,EAAEC,aAAa,EAAEC,aAAa,EAAE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CAACgC,KAAK,CAACC,KAAK;YACjCiB,KAAKvF,MAAMoF,UAAU;QACvB;QAEA/E,OAAO0C,GAAG,CAAC;YACT,CAAC/C,MAAMiC,IAAI,CAAC,EAAEpB,eAAeb,OAAO0C,YAAYjB,OAAOV,YAAY;QACrE;IACF;AACF;AAEA,eAAeS,YAAW"}
|
1
|
+
{"version":3,"sources":["../../src/models/buildSchema.ts"],"sourcesContent":["import type { IndexOptions, Schema, SchemaOptions, SchemaTypeOptions } from 'mongoose'\nimport type {\n ArrayField,\n Block,\n BlockField,\n CheckboxField,\n CodeField,\n CollapsibleField,\n DateField,\n EmailField,\n Field,\n FieldAffectingData,\n GroupField,\n JSONField,\n NonPresentationalField,\n NumberField,\n PointField,\n RadioField,\n RelationshipField,\n RichTextField,\n RowField,\n SanitizedConfig,\n SanitizedLocalizationConfig,\n SelectField,\n Tab,\n TabsField,\n TextField,\n TextareaField,\n UploadField,\n} from 'payload'\n\nimport mongoose from 'mongoose'\nimport {\n fieldAffectsData,\n fieldIsLocalized,\n fieldIsPresentationalOnly,\n tabHasName,\n} from 'payload/shared'\n\nexport type BuildSchemaOptions = {\n allowIDField?: boolean\n disableUnique?: boolean\n draftsEnabled?: boolean\n indexSortableFields?: boolean\n options?: SchemaOptions\n}\n\ntype FieldSchemaGenerator = (\n field: Field,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n) => void\n\n/**\n * get a field's defaultValue only if defined and not dynamic so that it can be set on the field schema\n * @param field\n */\nconst formatDefaultValue = (field: FieldAffectingData) =>\n typeof field.defaultValue !== 'undefined' && typeof field.defaultValue !== 'function'\n ? field.defaultValue\n : undefined\n\nconst formatBaseSchema = (field: FieldAffectingData, buildSchemaOptions: BuildSchemaOptions) => {\n const { disableUnique, draftsEnabled, indexSortableFields } = buildSchemaOptions\n const schema: SchemaTypeOptions<unknown> = {\n default: formatDefaultValue(field),\n index: field.index || (!disableUnique && field.unique) || indexSortableFields || false,\n required: false,\n unique: (!disableUnique && field.unique) || false,\n }\n\n if (\n schema.unique &&\n (field.localized ||\n draftsEnabled ||\n (fieldAffectsData(field) &&\n field.type !== 'group' &&\n field.type !== 'tab' &&\n field.required !== true))\n ) {\n schema.sparse = true\n }\n\n if (field.hidden) {\n schema.hidden = true\n }\n\n return schema\n}\n\nconst localizeSchema = (\n entity: NonPresentationalField | Tab,\n schema,\n localization: SanitizedLocalizationConfig | false,\n) => {\n if (fieldIsLocalized(entity) && localization && Array.isArray(localization.locales)) {\n return {\n type: localization.localeCodes.reduce(\n (localeSchema, locale) => ({\n ...localeSchema,\n [locale]: schema,\n }),\n {\n _id: false,\n },\n ),\n localized: true,\n }\n }\n return schema\n}\n\nconst buildSchema = (\n config: SanitizedConfig,\n configFields: Field[],\n buildSchemaOptions: BuildSchemaOptions = {},\n): Schema => {\n const { allowIDField, options } = buildSchemaOptions\n let fields = {}\n\n let schemaFields = configFields\n\n if (!allowIDField) {\n const idField = schemaFields.find((field) => fieldAffectsData(field) && field.name === 'id')\n if (idField) {\n fields = {\n _id: idField.type === 'number' ? Number : String,\n }\n schemaFields = schemaFields.filter(\n (field) => !(fieldAffectsData(field) && field.name === 'id'),\n )\n }\n }\n\n const schema = new mongoose.Schema(fields, options)\n\n schemaFields.forEach((field) => {\n if (!fieldIsPresentationalOnly(field)) {\n const addFieldSchema: FieldSchemaGenerator = fieldToSchemaMap[field.type]\n\n if (addFieldSchema) {\n addFieldSchema(field, schema, config, buildSchemaOptions)\n }\n }\n })\n\n return schema\n}\n\nconst fieldToSchemaMap: Record<string, FieldSchemaGenerator> = {\n array: (\n field: ArrayField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ) => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: [\n buildSchema(config, field.fields, {\n allowIDField: true,\n disableUnique: buildSchemaOptions.disableUnique,\n draftsEnabled: buildSchemaOptions.draftsEnabled,\n options: {\n _id: false,\n id: false,\n minimize: false,\n },\n }),\n ],\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n blocks: (\n field: BlockField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const fieldSchema = {\n type: [new mongoose.Schema({}, { _id: false, discriminatorKey: 'blockType' })],\n }\n\n schema.add({\n [field.name]: localizeSchema(field, fieldSchema, config.localization),\n })\n\n field.blocks.forEach((blockItem: Block) => {\n const blockSchema = new mongoose.Schema({}, { _id: false, id: false })\n\n blockItem.fields.forEach((blockField) => {\n const addFieldSchema: FieldSchemaGenerator = fieldToSchemaMap[blockField.type]\n if (addFieldSchema) {\n addFieldSchema(blockField, blockSchema, config, buildSchemaOptions)\n }\n })\n\n if (field.localized && config.localization) {\n config.localization.localeCodes.forEach((localeCode) => {\n // @ts-expect-error Possible incorrect typing in mongoose types, this works\n schema.path(`${field.name}.${localeCode}`).discriminator(blockItem.slug, blockSchema)\n })\n } else {\n // @ts-expect-error Possible incorrect typing in mongoose types, this works\n schema.path(field.name).discriminator(blockItem.slug, blockSchema)\n }\n })\n },\n checkbox: (\n field: CheckboxField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = { ...formatBaseSchema(field, buildSchemaOptions), type: Boolean }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n code: (\n field: CodeField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = { ...formatBaseSchema(field, buildSchemaOptions), type: String }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n collapsible: (\n field: CollapsibleField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n field.fields.forEach((subField: Field) => {\n const addFieldSchema: FieldSchemaGenerator = fieldToSchemaMap[subField.type]\n\n if (addFieldSchema) {\n addFieldSchema(subField, schema, config, buildSchemaOptions)\n }\n })\n },\n date: (\n field: DateField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = { ...formatBaseSchema(field, buildSchemaOptions), type: Date }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n email: (\n field: EmailField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = { ...formatBaseSchema(field, buildSchemaOptions), type: String }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n group: (\n field: GroupField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const formattedBaseSchema = formatBaseSchema(field, buildSchemaOptions)\n\n // carry indexSortableFields through to versions if drafts enabled\n const indexSortableFields =\n buildSchemaOptions.indexSortableFields &&\n field.name === 'version' &&\n buildSchemaOptions.draftsEnabled\n\n const baseSchema = {\n ...formattedBaseSchema,\n type: buildSchema(config, field.fields, {\n disableUnique: buildSchemaOptions.disableUnique,\n draftsEnabled: buildSchemaOptions.draftsEnabled,\n indexSortableFields,\n options: {\n _id: false,\n id: false,\n minimize: false,\n },\n }),\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n json: (\n field: JSONField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: mongoose.Schema.Types.Mixed,\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n number: (\n field: NumberField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: field.hasMany ? [Number] : Number,\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n point: (\n field: PointField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema: SchemaTypeOptions<unknown> = {\n type: {\n type: String,\n enum: ['Point'],\n },\n coordinates: {\n type: [Number],\n default: formatDefaultValue(field),\n required: false,\n },\n }\n if (buildSchemaOptions.disableUnique && field.unique && field.localized) {\n baseSchema.coordinates.sparse = true\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n\n if (field.index === true || field.index === undefined) {\n const indexOptions: IndexOptions = {}\n if (!buildSchemaOptions.disableUnique && field.unique) {\n indexOptions.sparse = true\n indexOptions.unique = true\n }\n if (field.localized && config.localization) {\n config.localization.locales.forEach((locale) => {\n schema.index({ [`${field.name}.${locale.code}`]: '2dsphere' }, indexOptions)\n })\n } else {\n schema.index({ [field.name]: '2dsphere' }, indexOptions)\n }\n }\n },\n radio: (\n field: RadioField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: String,\n enum: field.options.map((option) => {\n if (typeof option === 'object') return option.value\n return option\n }),\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n relationship: (\n field: RelationshipField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ) => {\n const hasManyRelations = Array.isArray(field.relationTo)\n let schemaToReturn: { [key: string]: any } = {}\n\n if (field.localized && config.localization) {\n schemaToReturn = {\n type: config.localization.localeCodes.reduce((locales, locale) => {\n let localeSchema: { [key: string]: any } = {}\n\n if (hasManyRelations) {\n localeSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n _id: false,\n type: mongoose.Schema.Types.Mixed,\n relationTo: { type: String, enum: field.relationTo },\n value: {\n type: mongoose.Schema.Types.Mixed,\n refPath: `${field.name}.${locale}.relationTo`,\n },\n }\n } else {\n localeSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: mongoose.Schema.Types.Mixed,\n ref: field.relationTo,\n }\n }\n\n return {\n ...locales,\n [locale]: field.hasMany\n ? { type: [localeSchema], default: formatDefaultValue(field) }\n : localeSchema,\n }\n }, {}),\n localized: true,\n }\n } else if (hasManyRelations) {\n schemaToReturn = {\n ...formatBaseSchema(field, buildSchemaOptions),\n _id: false,\n type: mongoose.Schema.Types.Mixed,\n relationTo: { type: String, enum: field.relationTo },\n value: {\n type: mongoose.Schema.Types.Mixed,\n refPath: `${field.name}.relationTo`,\n },\n }\n\n if (field.hasMany) {\n schemaToReturn = {\n type: [schemaToReturn],\n default: formatDefaultValue(field),\n }\n }\n } else {\n schemaToReturn = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: mongoose.Schema.Types.Mixed,\n ref: field.relationTo,\n }\n\n if (field.hasMany) {\n schemaToReturn = {\n type: [schemaToReturn],\n default: formatDefaultValue(field),\n }\n }\n }\n\n schema.add({\n [field.name]: schemaToReturn,\n })\n },\n richText: (\n field: RichTextField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: mongoose.Schema.Types.Mixed,\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n row: (\n field: RowField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n field.fields.forEach((subField: Field) => {\n const addFieldSchema: FieldSchemaGenerator = fieldToSchemaMap[subField.type]\n\n if (addFieldSchema) {\n addFieldSchema(subField, schema, config, buildSchemaOptions)\n }\n })\n },\n select: (\n field: SelectField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: String,\n enum: field.options.map((option) => {\n if (typeof option === 'object') return option.value\n return option\n }),\n }\n\n if (buildSchemaOptions.draftsEnabled || !field.required) {\n baseSchema.enum.push(null)\n }\n\n schema.add({\n [field.name]: localizeSchema(\n field,\n field.hasMany ? [baseSchema] : baseSchema,\n config.localization,\n ),\n })\n },\n tabs: (\n field: TabsField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n field.tabs.forEach((tab) => {\n if (tabHasName(tab)) {\n const baseSchema = {\n type: buildSchema(config, tab.fields, {\n disableUnique: buildSchemaOptions.disableUnique,\n draftsEnabled: buildSchemaOptions.draftsEnabled,\n options: {\n _id: false,\n id: false,\n minimize: false,\n },\n }),\n }\n\n schema.add({\n [tab.name]: localizeSchema(tab, baseSchema, config.localization),\n })\n } else {\n tab.fields.forEach((subField: Field) => {\n const addFieldSchema: FieldSchemaGenerator = fieldToSchemaMap[subField.type]\n\n if (addFieldSchema) {\n addFieldSchema(subField, schema, config, buildSchemaOptions)\n }\n })\n }\n })\n },\n text: (\n field: TextField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: field.hasMany ? [String] : String,\n }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n textarea: (\n field: TextareaField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const baseSchema = { ...formatBaseSchema(field, buildSchemaOptions), type: String }\n\n schema.add({\n [field.name]: localizeSchema(field, baseSchema, config.localization),\n })\n },\n upload: (\n field: UploadField,\n schema: Schema,\n config: SanitizedConfig,\n buildSchemaOptions: BuildSchemaOptions,\n ): void => {\n const hasManyRelations = Array.isArray(field.relationTo)\n let schemaToReturn: { [key: string]: any } = {}\n\n if (field.localized && config.localization) {\n schemaToReturn = {\n type: config.localization.localeCodes.reduce((locales, locale) => {\n let localeSchema: { [key: string]: any } = {}\n\n if (hasManyRelations) {\n localeSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n _id: false,\n type: mongoose.Schema.Types.Mixed,\n relationTo: { type: String, enum: field.relationTo },\n value: {\n type: mongoose.Schema.Types.Mixed,\n refPath: `${field.name}.${locale}.relationTo`,\n },\n }\n } else {\n localeSchema = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: mongoose.Schema.Types.Mixed,\n ref: field.relationTo,\n }\n }\n\n return {\n ...locales,\n [locale]: field.hasMany\n ? { type: [localeSchema], default: formatDefaultValue(field) }\n : localeSchema,\n }\n }, {}),\n localized: true,\n }\n } else if (hasManyRelations) {\n schemaToReturn = {\n ...formatBaseSchema(field, buildSchemaOptions),\n _id: false,\n type: mongoose.Schema.Types.Mixed,\n relationTo: { type: String, enum: field.relationTo },\n value: {\n type: mongoose.Schema.Types.Mixed,\n refPath: `${field.name}.relationTo`,\n },\n }\n\n if (field.hasMany) {\n schemaToReturn = {\n type: [schemaToReturn],\n default: formatDefaultValue(field),\n }\n }\n } else {\n schemaToReturn = {\n ...formatBaseSchema(field, buildSchemaOptions),\n type: mongoose.Schema.Types.Mixed,\n ref: field.relationTo,\n }\n\n if (field.hasMany) {\n schemaToReturn = {\n type: [schemaToReturn],\n default: formatDefaultValue(field),\n }\n }\n }\n\n schema.add({\n [field.name]: schemaToReturn,\n })\n },\n}\n\nexport default buildSchema\n"],"names":["mongoose","fieldAffectsData","fieldIsLocalized","fieldIsPresentationalOnly","tabHasName","formatDefaultValue","field","defaultValue","undefined","formatBaseSchema","buildSchemaOptions","disableUnique","draftsEnabled","indexSortableFields","schema","default","index","unique","required","localized","type","sparse","hidden","localizeSchema","entity","localization","Array","isArray","locales","localeCodes","reduce","localeSchema","locale","_id","buildSchema","config","configFields","allowIDField","options","fields","schemaFields","idField","find","name","Number","String","filter","Schema","forEach","addFieldSchema","fieldToSchemaMap","array","baseSchema","id","minimize","add","blocks","fieldSchema","discriminatorKey","blockItem","blockSchema","blockField","localeCode","path","discriminator","slug","checkbox","Boolean","code","collapsible","subField","date","Date","email","group","formattedBaseSchema","json","Types","Mixed","number","hasMany","point","enum","coordinates","indexOptions","radio","map","option","value","relationship","hasManyRelations","relationTo","schemaToReturn","refPath","ref","richText","row","select","push","tabs","tab","text","textarea","upload"],"mappings":"AA+BA,OAAOA,cAAc,WAAU;AAC/B,SACEC,gBAAgB,EAChBC,gBAAgB,EAChBC,yBAAyB,EACzBC,UAAU,QACL,iBAAgB;AAiBvB;;;CAGC,GACD,MAAMC,qBAAqB,CAACC,QAC1B,OAAOA,MAAMC,YAAY,KAAK,eAAe,OAAOD,MAAMC,YAAY,KAAK,aACvED,MAAMC,YAAY,GAClBC;AAEN,MAAMC,mBAAmB,CAACH,OAA2BI;IACnD,MAAM,EAAEC,aAAa,EAAEC,aAAa,EAAEC,mBAAmB,EAAE,GAAGH;IAC9D,MAAMI,SAAqC;QACzCC,SAASV,mBAAmBC;QAC5BU,OAAOV,MAAMU,KAAK,IAAK,CAACL,iBAAiBL,MAAMW,MAAM,IAAKJ,uBAAuB;QACjFK,UAAU;QACVD,QAAQ,AAAC,CAACN,iBAAiBL,MAAMW,MAAM,IAAK;IAC9C;IAEA,IACEH,OAAOG,MAAM,IACZX,CAAAA,MAAMa,SAAS,IACdP,iBACCX,iBAAiBK,UAChBA,MAAMc,IAAI,KAAK,WACfd,MAAMc,IAAI,KAAK,SACfd,MAAMY,QAAQ,KAAK,IAAI,GAC3B;QACAJ,OAAOO,MAAM,GAAG;IAClB;IAEA,IAAIf,MAAMgB,MAAM,EAAE;QAChBR,OAAOQ,MAAM,GAAG;IAClB;IAEA,OAAOR;AACT;AAEA,MAAMS,iBAAiB,CACrBC,QACAV,QACAW;IAEA,IAAIvB,iBAAiBsB,WAAWC,gBAAgBC,MAAMC,OAAO,CAACF,aAAaG,OAAO,GAAG;QACnF,OAAO;YACLR,MAAMK,aAAaI,WAAW,CAACC,MAAM,CACnC,CAACC,cAAcC,SAAY,CAAA;oBACzB,GAAGD,YAAY;oBACf,CAACC,OAAO,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,UAAU;wBACvB;oBACF;oBAEA,OAAO;wBACL,GAAG/D,OAAO;wBACV,CAACI,OAAO,EAAE1B,MAAM0E,OAAO,GACnB;4BAAE5D,MAAM;gCAACW;6BAAa;4BAAEhB,SAASV,mBAAmBC;wBAAO,IAC3DyB;oBACN;gBACF,GAAG,CAAC;gBACJZ,WAAW;YACb;QACF,OAAO,IAAIuE,kBAAkB;YAC3BE,iBAAiB;gBACf,GAAGnF,iBAAiBH,OAAOI,mBAAmB;gBAC9CuB,KAAK;gBACLb,MAAMpB,SAAS+C,MAAM,CAAC8B,KAAK,CAACC,KAAK;gBACjCa,YAAY;oBAAEvE,MAAMyB;oBAAQqC,MAAM5E,MAAMqF,UAAU;gBAAC;gBACnDH,OAAO;oBACLpE,MAAMpB,SAAS+C,MAAM,CAAC8B,KAAK,CAACC,KAAK;oBACjCe,SAAS,CAAC,EAAEvF,MAAMqC,IAAI,CAAC,WAAW,CAAC;gBACrC;YACF;YAEA,IAAIrC,MAAM0E,OAAO,EAAE;gBACjBY,iBAAiB;oBACfxE,MAAM;wBAACwE;qBAAe;oBACtB7E,SAASV,mBAAmBC;gBAC9B;YACF;QACF,OAAO;YACLsF,iBAAiB;gBACf,GAAGnF,iBAAiBH,OAAOI,mBAAmB;gBAC9CU,MAAMpB,SAAS+C,MAAM,CAAC8B,KAAK,CAACC,KAAK;gBACjCgB,KAAKxF,MAAMqF,UAAU;YACvB;YAEA,IAAIrF,MAAM0E,OAAO,EAAE;gBACjBY,iBAAiB;oBACfxE,MAAM;wBAACwE;qBAAe;oBACtB7E,SAASV,mBAAmBC;gBAC9B;YACF;QACF;QAEAQ,OAAOyC,GAAG,CAAC;YACT,CAACjD,MAAMqC,IAAI,CAAC,EAAEiD;QAChB;IACF;AACF;AAEA,eAAe1D,YAAW"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"parseParams.d.ts","sourceRoot":"","sources":["../../src/queries/parseParams.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAY,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;
|
1
|
+
{"version":3,"file":"parseParams.d.ts","sourceRoot":"","sources":["../../src/queries/parseParams.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAY,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAQ9D,wBAAsB,WAAW,CAAC,EAChC,cAAc,EACd,MAAM,EACN,UAAU,EACV,MAAM,EACN,OAAO,EACP,KAAK,GACN,EAAE;IACD,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,KAAK,CAAA;CACb,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CA0DnC"}
|
@@ -1,5 +1,4 @@
|
|
1
|
-
import
|
2
|
-
import { combineMerge } from 'payload';
|
1
|
+
import { deepMergeWithCombinedArrays } from 'payload';
|
3
2
|
import { validOperators } from 'payload/shared';
|
4
3
|
import { buildAndOrConditions } from './buildAndOrConditions.js';
|
5
4
|
import { buildSearchParam } from './buildSearchParams.js';
|
@@ -49,9 +48,7 @@ export async function parseParams({ collectionSlug, fields, globalSlug, locale,
|
|
49
48
|
[searchParam.path]: searchParam.value
|
50
49
|
};
|
51
50
|
} else if (typeof searchParam?.value === 'object') {
|
52
|
-
result =
|
53
|
-
arrayMerge: combineMerge
|
54
|
-
});
|
51
|
+
result = deepMergeWithCombinedArrays(result, searchParam.value);
|
55
52
|
}
|
56
53
|
}
|
57
54
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/queries/parseParams.ts"],"sourcesContent":["import type { FilterQuery } from 'mongoose'\nimport type { Field, Operator, Payload, Where } from 'payload'\n\nimport
|
1
|
+
{"version":3,"sources":["../../src/queries/parseParams.ts"],"sourcesContent":["import type { FilterQuery } from 'mongoose'\nimport type { Field, Operator, Payload, Where } from 'payload'\n\nimport { deepMergeWithCombinedArrays } from 'payload'\nimport { validOperators } from 'payload/shared'\n\nimport { buildAndOrConditions } from './buildAndOrConditions.js'\nimport { buildSearchParam } from './buildSearchParams.js'\n\nexport async function parseParams({\n collectionSlug,\n fields,\n globalSlug,\n locale,\n payload,\n where,\n}: {\n collectionSlug?: string\n fields: Field[]\n globalSlug?: string\n locale: string\n payload: Payload\n where: Where\n}): Promise<Record<string, unknown>> {\n let result = {} as FilterQuery<any>\n\n if (typeof where === 'object') {\n // We need to determine if the whereKey is an AND, OR, or a schema path\n for (const relationOrPath of Object.keys(where)) {\n const condition = where[relationOrPath]\n let conditionOperator: '$and' | '$or'\n if (relationOrPath.toLowerCase() === 'and') {\n conditionOperator = '$and'\n } else if (relationOrPath.toLowerCase() === 'or') {\n conditionOperator = '$or'\n }\n if (Array.isArray(condition)) {\n const builtConditions = await buildAndOrConditions({\n collectionSlug,\n fields,\n globalSlug,\n locale,\n payload,\n where: condition,\n })\n if (builtConditions.length > 0) result[conditionOperator] = builtConditions\n } else {\n // It's a path - and there can be multiple comparisons on a single path.\n // For example - title like 'test' and title not equal to 'tester'\n // So we need to loop on keys again here to handle each operator independently\n const pathOperators = where[relationOrPath]\n if (typeof pathOperators === 'object') {\n for (const operator of Object.keys(pathOperators)) {\n if (validOperators.includes(operator as Operator)) {\n const searchParam = await buildSearchParam({\n collectionSlug,\n fields,\n globalSlug,\n incomingPath: relationOrPath,\n locale,\n operator,\n payload,\n val: pathOperators[operator],\n })\n\n if (searchParam?.value && searchParam?.path) {\n result = {\n ...result,\n [searchParam.path]: searchParam.value,\n }\n } else if (typeof searchParam?.value === 'object') {\n result = deepMergeWithCombinedArrays(result, searchParam.value)\n }\n }\n }\n }\n }\n }\n }\n\n return result\n}\n"],"names":["deepMergeWithCombinedArrays","validOperators","buildAndOrConditions","buildSearchParam","parseParams","collectionSlug","fields","globalSlug","locale","payload","where","result","relationOrPath","Object","keys","condition","conditionOperator","toLowerCase","Array","isArray","builtConditions","length","pathOperators","operator","includes","searchParam","incomingPath","val","value","path"],"mappings":"AAGA,SAASA,2BAA2B,QAAQ,UAAS;AACrD,SAASC,cAAc,QAAQ,iBAAgB;AAE/C,SAASC,oBAAoB,QAAQ,4BAA2B;AAChE,SAASC,gBAAgB,QAAQ,yBAAwB;AAEzD,OAAO,eAAeC,YAAY,EAChCC,cAAc,EACdC,MAAM,EACNC,UAAU,EACVC,MAAM,EACNC,OAAO,EACPC,KAAK,EAQN;IACC,IAAIC,SAAS,CAAC;IAEd,IAAI,OAAOD,UAAU,UAAU;QAC7B,uEAAuE;QACvE,KAAK,MAAME,kBAAkBC,OAAOC,IAAI,CAACJ,OAAQ;YAC/C,MAAMK,YAAYL,KAAK,CAACE,eAAe;YACvC,IAAII;YACJ,IAAIJ,eAAeK,WAAW,OAAO,OAAO;gBAC1CD,oBAAoB;YACtB,OAAO,IAAIJ,eAAeK,WAAW,OAAO,MAAM;gBAChDD,oBAAoB;YACtB;YACA,IAAIE,MAAMC,OAAO,CAACJ,YAAY;gBAC5B,MAAMK,kBAAkB,MAAMlB,qBAAqB;oBACjDG;oBACAC;oBACAC;oBACAC;oBACAC;oBACAC,OAAOK;gBACT;gBACA,IAAIK,gBAAgBC,MAAM,GAAG,GAAGV,MAAM,CAACK,kBAAkB,GAAGI;YAC9D,OAAO;gBACL,wEAAwE;gBACxE,kEAAkE;gBAClE,8EAA8E;gBAC9E,MAAME,gBAAgBZ,KAAK,CAACE,eAAe;gBAC3C,IAAI,OAAOU,kBAAkB,UAAU;oBACrC,KAAK,MAAMC,YAAYV,OAAOC,IAAI,CAACQ,eAAgB;wBACjD,IAAIrB,eAAeuB,QAAQ,CAACD,WAAuB;4BACjD,MAAME,cAAc,MAAMtB,iBAAiB;gCACzCE;gCACAC;gCACAC;gCACAmB,cAAcd;gCACdJ;gCACAe;gCACAd;gCACAkB,KAAKL,aAAa,CAACC,SAAS;4BAC9B;4BAEA,IAAIE,aAAaG,SAASH,aAAaI,MAAM;gCAC3ClB,SAAS;oCACP,GAAGA,MAAM;oCACT,CAACc,YAAYI,IAAI,CAAC,EAAEJ,YAAYG,KAAK;gCACvC;4BACF,OAAO,IAAI,OAAOH,aAAaG,UAAU,UAAU;gCACjDjB,SAASX,4BAA4BW,QAAQc,YAAYG,KAAK;4BAChE;wBACF;oBACF;gBACF;YACF;QACF;IACF;IAEA,OAAOjB;AACT"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"queryDrafts.d.ts","sourceRoot":"","sources":["../src/queryDrafts.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAkB,WAAW,EAAE,MAAM,SAAS,CAAA;AAU1D,eAAO,MAAM,WAAW,EAAE,
|
1
|
+
{"version":3,"file":"queryDrafts.d.ts","sourceRoot":"","sources":["../src/queryDrafts.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAkB,WAAW,EAAE,MAAM,SAAS,CAAA;AAU1D,eAAO,MAAM,WAAW,EAAE,WAiGzB,CAAA"}
|
package/dist/queryDrafts.js
CHANGED
@@ -43,6 +43,13 @@ export const queryDrafts = async function queryDrafts({ collection, limit, local
|
|
43
43
|
sort,
|
44
44
|
useEstimatedCount
|
45
45
|
};
|
46
|
+
if (this.collation) {
|
47
|
+
const defaultLocale = 'en';
|
48
|
+
paginationOptions.collation = {
|
49
|
+
locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,
|
50
|
+
...this.collation
|
51
|
+
};
|
52
|
+
}
|
46
53
|
if (!useEstimatedCount && Object.keys(versionQuery).length === 0 && this.disableIndexHints !== true) {
|
47
54
|
// Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding
|
48
55
|
// a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,
|
package/dist/queryDrafts.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/queryDrafts.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { PayloadRequest, QueryDrafts } from 'payload'\n\nimport { combineQueries, flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport sanitizeInternalFields from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const queryDrafts: QueryDrafts = async function queryDrafts(\n this: MongooseAdapter,\n { collection, limit, locale, page, pagination, req = {} as PayloadRequest, sort: sortArg, where },\n) {\n const VersionModel = this.versions[collection]\n const collectionConfig = this.payload.collections[collection].config\n const options = await withSession(this, req)\n\n let hasNearConstraint\n let sort\n\n if (where) {\n const constraints = flattenWhereToOperators(where)\n hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n }\n\n if (!hasNearConstraint) {\n sort = buildSortParam({\n config: this.payload.config,\n fields: collectionConfig.fields,\n locale,\n sort: sortArg || collectionConfig.defaultSort,\n timestamps: true,\n })\n }\n\n const combinedWhere = combineQueries({ latest: { equals: true } }, where)\n\n const versionQuery = await VersionModel.buildQuery({\n locale,\n payload: this.payload,\n where: combinedWhere,\n })\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount =\n hasNearConstraint || !versionQuery || Object.keys(versionQuery).length === 0\n const paginationOptions: PaginateOptions = {\n forceCountFn: hasNearConstraint,\n lean: true,\n leanWithId: true,\n options,\n page,\n pagination,\n sort,\n useEstimatedCount,\n }\n\n if (\n !useEstimatedCount &&\n Object.keys(versionQuery).length === 0 &&\n this.disableIndexHints !== true\n ) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n paginationOptions.useCustomCountFn = () => {\n return Promise.resolve(\n VersionModel.countDocuments(versionQuery, {\n hint: { _id: 1 },\n }),\n )\n }\n }\n\n if (limit > 0) {\n paginationOptions.limit = limit\n // limit must also be set here, it's ignored when pagination is false\n paginationOptions.options.limit = limit\n }\n\n const result = await VersionModel.paginate(versionQuery, paginationOptions)\n const docs = JSON.parse(JSON.stringify(result.docs))\n\n return {\n ...result,\n docs: docs.map((doc) => {\n doc = {\n _id: doc.parent,\n id: doc.parent,\n ...doc.version,\n createdAt: doc.createdAt,\n updatedAt: doc.updatedAt,\n }\n\n return sanitizeInternalFields(doc)\n }),\n }\n}\n"],"names":["combineQueries","flattenWhereToOperators","buildSortParam","sanitizeInternalFields","withSession","queryDrafts","collection","limit","locale","page","pagination","req","sort","sortArg","where","VersionModel","versions","collectionConfig","payload","collections","config","options","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","defaultSort","timestamps","combinedWhere","latest","equals","versionQuery","buildQuery","useEstimatedCount","length","paginationOptions","forceCountFn","lean","leanWithId","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","paginate","docs","JSON","parse","stringify","map","doc","parent","id","version","createdAt","updatedAt"],"mappings":"AAGA,SAASA,cAAc,EAAEC,uBAAuB,QAAQ,UAAS;AAIjE,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,OAAOC,4BAA4B,wCAAuC;AAC1E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,cAA2B,eAAeA,YAErD,EAAEC,UAAU,EAAEC,KAAK,EAAEC,MAAM,EAAEC,IAAI,EAAEC,UAAU,EAAEC,MAAM,CAAC,CAAmB,EAAEC,MAAMC,OAAO,EAAEC,KAAK,EAAE;IAEjG,MAAMC,eAAe,IAAI,CAACC,QAAQ,CAACV,WAAW;IAC9C,MAAMW,mBAAmB,IAAI,CAACC,OAAO,CAACC,WAAW,CAACb,WAAW,CAACc,MAAM;IACpE,MAAMC,UAAU,MAAMjB,YAAY,IAAI,EAAEO;IAExC,IAAIW;IACJ,IAAIV;IAEJ,IAAIE,OAAO;QACT,MAAMS,cAActB,wBAAwBa;QAC5CQ,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,IAAI,CAACN,mBAAmB;QACtBV,OAAOV,eAAe;YACpBkB,QAAQ,IAAI,CAACF,OAAO,CAACE,MAAM;YAC3BS,QAAQZ,iBAAiBY,MAAM;YAC/BrB;YACAI,MAAMC,WAAWI,iBAAiBa,WAAW;YAC7CC,YAAY;QACd;IACF;IAEA,MAAMC,gBAAgBhC,eAAe;QAAEiC,QAAQ;YAAEC,QAAQ;QAAK;IAAE,GAAGpB;IAEnE,MAAMqB,eAAe,MAAMpB,aAAaqB,UAAU,CAAC;QACjD5B;QACAU,SAAS,IAAI,CAACA,OAAO;QACrBJ,OAAOkB;IACT;IAEA,4HAA4H;IAC5H,MAAMK,oBACJf,qBAAqB,CAACa,gBAAgBT,OAAOC,IAAI,CAACQ,cAAcG,MAAM,KAAK;IAC7E,MAAMC,oBAAqC;QACzCC,cAAclB;QACdmB,MAAM;QACNC,YAAY;QACZrB;QACAZ;QACAC;QACAE;QACAyB;IACF;IAEA,IACE,
|
1
|
+
{"version":3,"sources":["../src/queryDrafts.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { PayloadRequest, QueryDrafts } from 'payload'\n\nimport { combineQueries, flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport sanitizeInternalFields from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const queryDrafts: QueryDrafts = async function queryDrafts(\n this: MongooseAdapter,\n { collection, limit, locale, page, pagination, req = {} as PayloadRequest, sort: sortArg, where },\n) {\n const VersionModel = this.versions[collection]\n const collectionConfig = this.payload.collections[collection].config\n const options = await withSession(this, req)\n\n let hasNearConstraint\n let sort\n\n if (where) {\n const constraints = flattenWhereToOperators(where)\n hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n }\n\n if (!hasNearConstraint) {\n sort = buildSortParam({\n config: this.payload.config,\n fields: collectionConfig.fields,\n locale,\n sort: sortArg || collectionConfig.defaultSort,\n timestamps: true,\n })\n }\n\n const combinedWhere = combineQueries({ latest: { equals: true } }, where)\n\n const versionQuery = await VersionModel.buildQuery({\n locale,\n payload: this.payload,\n where: combinedWhere,\n })\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount =\n hasNearConstraint || !versionQuery || Object.keys(versionQuery).length === 0\n const paginationOptions: PaginateOptions = {\n forceCountFn: hasNearConstraint,\n lean: true,\n leanWithId: true,\n options,\n page,\n pagination,\n sort,\n useEstimatedCount,\n }\n\n if (this.collation) {\n const defaultLocale = 'en'\n paginationOptions.collation = {\n locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,\n ...this.collation,\n }\n }\n\n if (\n !useEstimatedCount &&\n Object.keys(versionQuery).length === 0 &&\n this.disableIndexHints !== true\n ) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n paginationOptions.useCustomCountFn = () => {\n return Promise.resolve(\n VersionModel.countDocuments(versionQuery, {\n hint: { _id: 1 },\n }),\n )\n }\n }\n\n if (limit > 0) {\n paginationOptions.limit = limit\n // limit must also be set here, it's ignored when pagination is false\n paginationOptions.options.limit = limit\n }\n\n const result = await VersionModel.paginate(versionQuery, paginationOptions)\n const docs = JSON.parse(JSON.stringify(result.docs))\n\n return {\n ...result,\n docs: docs.map((doc) => {\n doc = {\n _id: doc.parent,\n id: doc.parent,\n ...doc.version,\n createdAt: doc.createdAt,\n updatedAt: doc.updatedAt,\n }\n\n return sanitizeInternalFields(doc)\n }),\n }\n}\n"],"names":["combineQueries","flattenWhereToOperators","buildSortParam","sanitizeInternalFields","withSession","queryDrafts","collection","limit","locale","page","pagination","req","sort","sortArg","where","VersionModel","versions","collectionConfig","payload","collections","config","options","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","defaultSort","timestamps","combinedWhere","latest","equals","versionQuery","buildQuery","useEstimatedCount","length","paginationOptions","forceCountFn","lean","leanWithId","collation","defaultLocale","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","paginate","docs","JSON","parse","stringify","map","doc","parent","id","version","createdAt","updatedAt"],"mappings":"AAGA,SAASA,cAAc,EAAEC,uBAAuB,QAAQ,UAAS;AAIjE,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,OAAOC,4BAA4B,wCAAuC;AAC1E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,cAA2B,eAAeA,YAErD,EAAEC,UAAU,EAAEC,KAAK,EAAEC,MAAM,EAAEC,IAAI,EAAEC,UAAU,EAAEC,MAAM,CAAC,CAAmB,EAAEC,MAAMC,OAAO,EAAEC,KAAK,EAAE;IAEjG,MAAMC,eAAe,IAAI,CAACC,QAAQ,CAACV,WAAW;IAC9C,MAAMW,mBAAmB,IAAI,CAACC,OAAO,CAACC,WAAW,CAACb,WAAW,CAACc,MAAM;IACpE,MAAMC,UAAU,MAAMjB,YAAY,IAAI,EAAEO;IAExC,IAAIW;IACJ,IAAIV;IAEJ,IAAIE,OAAO;QACT,MAAMS,cAActB,wBAAwBa;QAC5CQ,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,IAAI,CAACN,mBAAmB;QACtBV,OAAOV,eAAe;YACpBkB,QAAQ,IAAI,CAACF,OAAO,CAACE,MAAM;YAC3BS,QAAQZ,iBAAiBY,MAAM;YAC/BrB;YACAI,MAAMC,WAAWI,iBAAiBa,WAAW;YAC7CC,YAAY;QACd;IACF;IAEA,MAAMC,gBA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BACfC,IAAIF,IAAIC,MAAM;gBACd,GAAGD,IAAIG,OAAO;gBACdC,WAAWJ,IAAII,SAAS;gBACxBC,WAAWL,IAAIK,SAAS;YAC1B;YAEA,OAAO7D,uBAAuBwD;QAChC;IACF;AACF,EAAC"}
|
package/dist/types.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAClG,OAAO,KAAK,EACV,UAAU,EACV,UAAU,EACV,aAAa,EACb,SAAS,EACT,gBAAgB,EAChB,SAAS,EACT,UAAU,EACV,KAAK,EACL,UAAU,EACV,SAAS,EACT,WAAW,EACX,OAAO,EACP,UAAU,EACV,UAAU,EACV,iBAAiB,EACjB,aAAa,EACb,QAAQ,EACR,eAAe,EACf,WAAW,EACX,SAAS,EACT,SAAS,EACT,aAAa,EACb,WAAW,EACZ,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAE7D,MAAM,WAAW,eAAgB,SAAQ,KAAK,CAAC,GAAG,CAAC,EAAE,aAAa,CAAC,GAAG,CAAC;IACrE,kHAAkH;IAClH,UAAU,EAAE,CAAC,IAAI,EAAE,cAAc,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;CACvE;AAED,MAAM,WAAW,mBAAoB,SAAQ,eAAe;IAC1D,uBAAuB,EAAE,IAAI,CAAA;IAC7B,kBAAkB,EAAE,MAAM,CAAA;CAC3B;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,EAAE,eAAe,CAAA;IACvB,OAAO,CAAC,EAAE,YAAY,CAAA;CACvB,CAAA;AAED,MAAM,WAAW,WAAY,SAAQ,KAAK,CAAC,QAAQ,CAAC;I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AE,WAAW,CAAC,CAAA;IACpD,IAAI,EAAE,sBAAsB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAA;IAChD,IAAI,EAAE,sBAAsB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAA;IAChD,QAAQ,EAAE,sBAAsB,CAAC,OAAO,EAAE,aAAa,CAAC,CAAA;IACxD,MAAM,EAAE,sBAAsB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAA;CACrD,CAAA;AAED,MAAM,MAAM,aAAa,GAAG;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,CAAA;AAChD,MAAM,MAAM,eAAe,GAAG;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,CAAA"}
|
package/dist/types.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { IndexDefinition, IndexOptions, Model, PaginateModel, SchemaOptions } from 'mongoose'\nimport type {\n ArrayField,\n BlockField,\n CheckboxField,\n CodeField,\n CollapsibleField,\n DateField,\n EmailField,\n Field,\n GroupField,\n JSONField,\n NumberField,\n Payload,\n PointField,\n RadioField,\n RelationshipField,\n RichTextField,\n RowField,\n SanitizedConfig,\n SelectField,\n TabsField,\n TextField,\n TextareaField,\n UploadField,\n} from 'payload'\n\nimport type { BuildQueryArgs } from './queries/buildQuery.js'\n\nexport interface CollectionModel extends Model<any>, PaginateModel<any> {\n /** buildQuery is used to transform payload's where operator into what can be used by mongoose (e.g. id => _id) */\n buildQuery: (args: BuildQueryArgs) => Promise<Record<string, unknown>> // TODO: Delete this\n}\n\nexport interface AuthCollectionModel extends CollectionModel {\n resetPasswordExpiration: Date\n resetPasswordToken: string\n}\n\nexport type TypeOfIndex = {\n fields: IndexDefinition\n options?: IndexOptions\n}\n\nexport interface GlobalModel extends Model<Document> {\n buildQuery: (query: unknown, locale?: string) => Promise<Record<string, unknown>>\n}\n\nexport type BuildSchema<TSchema> = (args: {\n config: SanitizedConfig\n fields: Field[]\n options: BuildSchemaOptions\n}) => TSchema\n\nexport type BuildSchemaOptions = {\n allowIDField?: boolean\n disableUnique?: boolean\n draftsEnabled?: boolean\n indexSortableFields?: boolean\n options?: SchemaOptions\n}\n\nexport type FieldGenerator<TSchema, TField> = {\n config: SanitizedConfig\n field: TField\n options: BuildSchemaOptions\n schema: TSchema\n}\n\
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { IndexDefinition, IndexOptions, Model, PaginateModel, SchemaOptions } from 'mongoose'\nimport type {\n ArrayField,\n BlockField,\n CheckboxField,\n CodeField,\n CollapsibleField,\n DateField,\n EmailField,\n Field,\n GroupField,\n JSONField,\n NumberField,\n Payload,\n PointField,\n RadioField,\n RelationshipField,\n RichTextField,\n RowField,\n SanitizedConfig,\n SelectField,\n TabsField,\n TextField,\n TextareaField,\n UploadField,\n} from 'payload'\n\nimport type { BuildQueryArgs } from './queries/buildQuery.js'\n\nexport interface CollectionModel extends Model<any>, PaginateModel<any> {\n /** buildQuery is used to transform payload's where operator into what can be used by mongoose (e.g. id => _id) */\n buildQuery: (args: BuildQueryArgs) => Promise<Record<string, unknown>> // TODO: Delete this\n}\n\nexport interface AuthCollectionModel extends CollectionModel {\n resetPasswordExpiration: Date\n resetPasswordToken: string\n}\n\nexport type TypeOfIndex = {\n fields: IndexDefinition\n options?: IndexOptions\n}\n\nexport interface GlobalModel extends Model<Document> {\n buildQuery: (query: unknown, locale?: string) => Promise<Record<string, unknown>>\n}\n\nexport type BuildSchema<TSchema> = (args: {\n config: SanitizedConfig\n fields: Field[]\n options: BuildSchemaOptions\n}) => TSchema\n\nexport type BuildSchemaOptions = {\n allowIDField?: boolean\n disableUnique?: boolean\n draftsEnabled?: boolean\n indexSortableFields?: boolean\n options?: SchemaOptions\n}\n\nexport type FieldGenerator<TSchema, TField> = {\n config: SanitizedConfig\n field: TField\n options: BuildSchemaOptions\n schema: TSchema\n}\n\nexport type FieldGeneratorFunction<TSchema, TField extends Field> = (\n args: FieldGenerator<TSchema, TField>,\n) => void\n\n/**\n * Object mapping types to a schema based on TSchema\n */\nexport type FieldToSchemaMap<TSchema> = {\n array: FieldGeneratorFunction<TSchema, ArrayField>\n blocks: FieldGeneratorFunction<TSchema, BlockField>\n checkbox: FieldGeneratorFunction<TSchema, CheckboxField>\n code: FieldGeneratorFunction<TSchema, CodeField>\n collapsible: FieldGeneratorFunction<TSchema, CollapsibleField>\n date: FieldGeneratorFunction<TSchema, DateField>\n email: FieldGeneratorFunction<TSchema, EmailField>\n group: FieldGeneratorFunction<TSchema, GroupField>\n json: FieldGeneratorFunction<TSchema, JSONField>\n number: FieldGeneratorFunction<TSchema, NumberField>\n point: FieldGeneratorFunction<TSchema, PointField>\n radio: FieldGeneratorFunction<TSchema, RadioField>\n relationship: FieldGeneratorFunction<TSchema, RelationshipField>\n richText: FieldGeneratorFunction<TSchema, RichTextField>\n row: FieldGeneratorFunction<TSchema, RowField>\n select: FieldGeneratorFunction<TSchema, SelectField>\n tabs: FieldGeneratorFunction<TSchema, TabsField>\n text: FieldGeneratorFunction<TSchema, TextField>\n textarea: FieldGeneratorFunction<TSchema, TextareaField>\n upload: FieldGeneratorFunction<TSchema, UploadField>\n}\n\nexport type MigrateUpArgs = { payload: Payload }\nexport type MigrateDownArgs = { payload: Payload }\n"],"names":[],"mappings":"AAoGA,WAAkD"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@payloadcms/db-mongodb",
|
3
|
-
"version": "3.0.0-canary.
|
3
|
+
"version": "3.0.0-canary.cdb9474",
|
4
4
|
"description": "The officially supported MongoDB database adapter for Payload",
|
5
5
|
"homepage": "https://payloadcms.com",
|
6
6
|
"repository": {
|
@@ -27,7 +27,6 @@
|
|
27
27
|
],
|
28
28
|
"dependencies": {
|
29
29
|
"bson-objectid": "2.0.4",
|
30
|
-
"deepmerge": "4.3.1",
|
31
30
|
"http-status": "1.6.2",
|
32
31
|
"mongoose": "6.12.3",
|
33
32
|
"mongoose-paginate-v2": "1.7.22",
|
@@ -39,10 +38,10 @@
|
|
39
38
|
"mongodb": "4.17.1",
|
40
39
|
"mongodb-memory-server": "^9",
|
41
40
|
"@payloadcms/eslint-config": "3.0.0-beta.59",
|
42
|
-
"payload": "3.0.0-canary.
|
41
|
+
"payload": "3.0.0-canary.cdb9474"
|
43
42
|
},
|
44
43
|
"peerDependencies": {
|
45
|
-
"payload": "3.0.0-canary.
|
44
|
+
"payload": "3.0.0-canary.cdb9474"
|
46
45
|
},
|
47
46
|
"scripts": {
|
48
47
|
"build": "pnpm build:types && pnpm build:swc",
|