@payloadcms/db-mongodb 3.0.0-canary.ee6d727 → 3.0.0-canary.ef0a8d0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +1 -1
- package/dist/connect.d.ts +1 -1
- package/dist/connect.d.ts.map +1 -1
- package/dist/connect.js +1 -1
- package/dist/connect.js.map +1 -1
- package/dist/count.d.ts +1 -1
- package/dist/count.d.ts.map +1 -1
- package/dist/count.js +2 -2
- package/dist/count.js.map +1 -1
- package/dist/create.d.ts +1 -1
- package/dist/create.d.ts.map +1 -1
- package/dist/create.js +7 -3
- package/dist/create.js.map +1 -1
- package/dist/createGlobal.d.ts +1 -1
- package/dist/createGlobal.d.ts.map +1 -1
- package/dist/createGlobal.js +1 -1
- package/dist/createGlobal.js.map +1 -1
- package/dist/createGlobalVersion.d.ts +1 -1
- package/dist/createGlobalVersion.d.ts.map +1 -1
- package/dist/createGlobalVersion.js +1 -1
- package/dist/createGlobalVersion.js.map +1 -1
- package/dist/createMigration.d.ts +1 -1
- package/dist/createMigration.d.ts.map +1 -1
- package/dist/createMigration.js +2 -2
- package/dist/createMigration.js.map +1 -1
- package/dist/createVersion.d.ts +1 -1
- package/dist/createVersion.d.ts.map +1 -1
- package/dist/createVersion.js +1 -1
- package/dist/createVersion.js.map +1 -1
- package/dist/deleteMany.d.ts +1 -1
- package/dist/deleteMany.d.ts.map +1 -1
- package/dist/deleteMany.js +1 -1
- package/dist/deleteMany.js.map +1 -1
- package/dist/deleteOne.d.ts +1 -1
- package/dist/deleteOne.d.ts.map +1 -1
- package/dist/deleteOne.js +1 -1
- package/dist/deleteOne.js.map +1 -1
- package/dist/deleteVersions.d.ts +1 -1
- package/dist/deleteVersions.d.ts.map +1 -1
- package/dist/deleteVersions.js +1 -1
- package/dist/deleteVersions.js.map +1 -1
- package/dist/destroy.d.ts +1 -1
- package/dist/destroy.d.ts.map +1 -1
- package/dist/destroy.js.map +1 -1
- package/dist/find.d.ts +1 -1
- package/dist/find.d.ts.map +1 -1
- package/dist/find.js +2 -3
- package/dist/find.js.map +1 -1
- package/dist/findGlobal.d.ts +1 -1
- package/dist/findGlobal.d.ts.map +1 -1
- package/dist/findGlobal.js +2 -2
- package/dist/findGlobal.js.map +1 -1
- package/dist/findGlobalVersions.d.ts +1 -1
- package/dist/findGlobalVersions.d.ts.map +1 -1
- package/dist/findGlobalVersions.js +2 -4
- package/dist/findGlobalVersions.js.map +1 -1
- package/dist/findOne.d.ts +1 -1
- package/dist/findOne.d.ts.map +1 -1
- package/dist/findOne.js +1 -1
- package/dist/findOne.js.map +1 -1
- package/dist/findVersions.d.ts +1 -1
- package/dist/findVersions.d.ts.map +1 -1
- package/dist/findVersions.js +2 -3
- package/dist/findVersions.js.map +1 -1
- package/dist/index.d.ts +5 -30
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts +1 -1
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +2 -2
- package/dist/init.js.map +1 -1
- package/dist/migrateFresh.d.ts.map +1 -1
- package/dist/migrateFresh.js +1 -1
- package/dist/migrateFresh.js.map +1 -1
- package/dist/models/buildCollectionSchema.d.ts +1 -27
- package/dist/models/buildCollectionSchema.d.ts.map +1 -1
- package/dist/models/buildCollectionSchema.js.map +1 -1
- package/dist/models/buildGlobalModel.d.ts +1 -1
- package/dist/models/buildGlobalModel.d.ts.map +1 -1
- package/dist/models/buildGlobalModel.js.map +1 -1
- package/dist/models/buildSchema.d.ts +1 -27
- package/dist/models/buildSchema.d.ts.map +1 -1
- package/dist/models/buildSchema.js +2 -4
- package/dist/models/buildSchema.js.map +1 -1
- package/dist/predefinedMigrations/versions-v1-v2.js.map +1 -1
- package/dist/queries/buildAndOrConditions.d.ts +1 -2
- package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
- package/dist/queries/buildAndOrConditions.js +0 -2
- package/dist/queries/buildAndOrConditions.js.map +1 -1
- package/dist/queries/buildQuery.d.ts +1 -2
- package/dist/queries/buildQuery.d.ts.map +1 -1
- package/dist/queries/buildQuery.js +1 -1
- package/dist/queries/buildQuery.js.map +1 -1
- package/dist/queries/buildSearchParams.d.ts +1 -2
- package/dist/queries/buildSearchParams.d.ts.map +1 -1
- package/dist/queries/buildSearchParams.js +2 -2
- package/dist/queries/buildSearchParams.js.map +1 -1
- package/dist/queries/buildSortParam.d.ts +2 -28
- package/dist/queries/buildSortParam.d.ts.map +1 -1
- package/dist/queries/buildSortParam.js.map +1 -1
- package/dist/queries/getLocalizedSortProperty.d.ts +1 -2
- package/dist/queries/getLocalizedSortProperty.d.ts.map +1 -1
- package/dist/queries/getLocalizedSortProperty.js +2 -2
- package/dist/queries/getLocalizedSortProperty.js.map +1 -1
- package/dist/queries/getLocalizedSortProperty.spec.js +43 -43
- package/dist/queries/getLocalizedSortProperty.spec.js.map +1 -1
- package/dist/queries/mock.js.map +1 -1
- package/dist/queries/operatorMap.js.map +1 -1
- package/dist/queries/parseParams.d.ts +1 -3
- package/dist/queries/parseParams.d.ts.map +1 -1
- package/dist/queries/parseParams.js +3 -3
- package/dist/queries/parseParams.js.map +1 -1
- package/dist/queries/sanitizeQueryValue.d.ts +1 -1
- package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
- package/dist/queries/sanitizeQueryValue.js +1 -1
- package/dist/queries/sanitizeQueryValue.js.map +1 -1
- package/dist/queryDrafts.d.ts +1 -1
- package/dist/queryDrafts.d.ts.map +1 -1
- package/dist/queryDrafts.js +2 -3
- package/dist/queryDrafts.js.map +1 -1
- package/dist/testCredentials.js.map +1 -1
- package/dist/transactions/beginTransaction.d.ts +1 -1
- package/dist/transactions/beginTransaction.d.ts.map +1 -1
- package/dist/transactions/beginTransaction.js +1 -1
- package/dist/transactions/beginTransaction.js.map +1 -1
- package/dist/transactions/commitTransaction.d.ts +1 -1
- package/dist/transactions/commitTransaction.d.ts.map +1 -1
- package/dist/transactions/commitTransaction.js +1 -0
- package/dist/transactions/commitTransaction.js.map +1 -1
- package/dist/transactions/rollbackTransaction.d.ts +1 -1
- package/dist/transactions/rollbackTransaction.d.ts.map +1 -1
- package/dist/transactions/rollbackTransaction.js +13 -7
- package/dist/transactions/rollbackTransaction.js.map +1 -1
- package/dist/types.d.ts +1 -28
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/updateGlobal.d.ts +1 -1
- package/dist/updateGlobal.d.ts.map +1 -1
- package/dist/updateGlobal.js +1 -1
- package/dist/updateGlobal.js.map +1 -1
- package/dist/updateGlobalVersion.d.ts +1 -2
- package/dist/updateGlobalVersion.d.ts.map +1 -1
- package/dist/updateGlobalVersion.js +1 -1
- package/dist/updateGlobalVersion.js.map +1 -1
- package/dist/updateOne.d.ts +1 -1
- package/dist/updateOne.d.ts.map +1 -1
- package/dist/updateOne.js +7 -3
- package/dist/updateOne.js.map +1 -1
- package/dist/updateVersion.d.ts +1 -1
- package/dist/updateVersion.d.ts.map +1 -1
- package/dist/updateVersion.js +1 -1
- package/dist/updateVersion.js.map +1 -1
- package/dist/utilities/getDBName.d.ts +1 -1
- package/dist/utilities/getDBName.d.ts.map +1 -1
- package/dist/utilities/getDBName.js.map +1 -1
- package/dist/utilities/handleError.d.ts +6 -2
- package/dist/utilities/handleError.d.ts.map +1 -1
- package/dist/utilities/handleError.js +12 -9
- package/dist/utilities/handleError.js.map +1 -1
- package/dist/utilities/sanitizeInternalFields.d.ts.map +1 -1
- package/dist/utilities/sanitizeInternalFields.js.map +1 -1
- package/dist/withSession.d.ts +3 -27
- package/dist/withSession.d.ts.map +1 -1
- package/dist/withSession.js +6 -2
- package/dist/withSession.js.map +1 -1
- package/package.json +9 -9
package/README.md
CHANGED
package/dist/connect.d.ts
CHANGED
package/dist/connect.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../src/connect.ts"],"names":[],"mappings":"
|
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,OAsDrB,CAAA"}
|
package/dist/connect.js
CHANGED
package/dist/connect.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/connect.ts"],"sourcesContent":["
|
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,OAAOE,KAAK;QACZC,QAAQC,GAAG,CAACF;QACZ,IAAI,CAACJ,OAAO,CAACC,MAAM,CAACM,KAAK,CAAC,CAAC,2CAA2C,EAAEH,IAAII,OAAO,CAAC,CAAC,EAAEJ;QACvFP,QAAQY,IAAI,CAAC;IACf;AACF,EAAC"}
|
package/dist/count.d.ts
CHANGED
package/dist/count.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"count.d.ts","sourceRoot":"","sources":["../src/count.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,
|
1
|
+
{"version":3,"file":"count.d.ts","sourceRoot":"","sources":["../src/count.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAkB,MAAM,SAAS,CAAA;AAQpD,eAAO,MAAM,KAAK,EAAE,KAsCnB,CAAA"}
|
package/dist/count.js
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
import { flattenWhereToOperators } from 'payload
|
1
|
+
import { flattenWhereToOperators } from 'payload';
|
2
2
|
import { withSession } from './withSession.js';
|
3
3
|
export const count = async function count({ collection, locale, req = {}, where }) {
|
4
4
|
const Model = this.collections[collection];
|
5
|
-
const options = withSession(this, req
|
5
|
+
const options = await withSession(this, req);
|
6
6
|
let hasNearConstraint = false;
|
7
7
|
if (where) {
|
8
8
|
const constraints = flattenWhereToOperators(where);
|
package/dist/count.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/count.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { Count
|
1
|
+
{"version":3,"sources":["../src/count.ts"],"sourcesContent":["import type { QueryOptions } from 'mongoose'\nimport type { Count, PayloadRequest } from 'payload'\n\nimport { flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { withSession } from './withSession.js'\n\nexport const count: Count = async function count(\n this: MongooseAdapter,\n { collection, locale, req = {} as PayloadRequest, where },\n) {\n const Model = this.collections[collection]\n const options: QueryOptions = 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 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\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 options.hint = {\n _id: 1,\n }\n }\n\n const result = await Model.countDocuments(query, options)\n\n return {\n totalDocs: result,\n }\n}\n"],"names":["flattenWhereToOperators","withSession","count","collection","locale","req","where","Model","collections","options","hasNearConstraint","constraints","some","prop","Object","keys","key","query","buildQuery","payload","useEstimatedCount","length","disableIndexHints","hint","_id","result","countDocuments","totalDocs"],"mappings":"AAGA,SAASA,uBAAuB,QAAQ,UAAS;AAIjD,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,QAAe,eAAeA,MAEzC,EAAEC,UAAU,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAAmB,EAAEC,KAAK,EAAE;IAEzD,MAAMC,QAAQ,IAAI,CAACC,WAAW,CAACL,WAAW;IAC1C,MAAMM,UAAwB,MAAMR,YAAY,IAAI,EAAEI;IAEtD,IAAIK,oBAAoB;IAExB,IAAIJ,OAAO;QACT,MAAMK,cAAcX,wBAAwBM;QAC5CI,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,MAAMC,QAAQ,MAAMV,MAAMW,UAAU,CAAC;QACnCd;QACAe,SAAS,IAAI,CAACA,OAAO;QACrBb;IACF;IAEA,4HAA4H;IAC5H,MAAMc,oBAAoBV,qBAAqB,CAACO,SAASH,OAAOC,IAAI,CAACE,OAAOI,MAAM,KAAK;IAEvF,IAAI,CAACD,qBAAqBN,OAAOC,IAAI,CAACE,OAAOI,MAAM,KAAK,KAAK,IAAI,CAACC,iBAAiB,KAAK,MAAM;QAC5F,mHAAmH;QACnH,qHAAqH;QACrH,mHAAmH;QACnH,4BAA4B;QAC5Bb,QAAQc,IAAI,GAAG;YACbC,KAAK;QACP;IACF;IAEA,MAAMC,SAAS,MAAMlB,MAAMmB,cAAc,CAACT,OAAOR;IAEjD,OAAO;QACLkB,WAAWF;IACb;AACF,EAAC"}
|
package/dist/create.d.ts
CHANGED
package/dist/create.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,
|
1
|
+
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAA4B,MAAM,SAAS,CAAA;AAO/D,eAAO,MAAM,MAAM,EAAE,MAwBpB,CAAA"}
|
package/dist/create.js
CHANGED
@@ -1,15 +1,19 @@
|
|
1
|
-
import handleError from './utilities/handleError.js';
|
1
|
+
import { handleError } from './utilities/handleError.js';
|
2
2
|
import { withSession } from './withSession.js';
|
3
3
|
export const create = async function create({ collection, data, req = {} }) {
|
4
4
|
const Model = this.collections[collection];
|
5
|
-
const options = withSession(this, req
|
5
|
+
const options = await withSession(this, req);
|
6
6
|
let doc;
|
7
7
|
try {
|
8
8
|
[doc] = await Model.create([
|
9
9
|
data
|
10
10
|
], options);
|
11
11
|
} catch (error) {
|
12
|
-
handleError(
|
12
|
+
handleError({
|
13
|
+
collection,
|
14
|
+
error,
|
15
|
+
req
|
16
|
+
});
|
13
17
|
}
|
14
18
|
// doc.toJSON does not do stuff like converting ObjectIds to string, or date strings to date objects. That's why we use JSON.parse/stringify here
|
15
19
|
const result = JSON.parse(JSON.stringify(doc));
|
package/dist/create.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/create.ts"],"sourcesContent":["import type { Create
|
1
|
+
{"version":3,"sources":["../src/create.ts"],"sourcesContent":["import type { Create, Document, PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { handleError } from './utilities/handleError.js'\nimport { withSession } from './withSession.js'\n\nexport const create: Create = async function create(\n this: MongooseAdapter,\n { collection, data, req = {} as PayloadRequest },\n) {\n const Model = this.collections[collection]\n const options = await withSession(this, req)\n let doc\n try {\n ;[doc] = await Model.create([data], options)\n } catch (error) {\n handleError({ collection, error, req })\n }\n\n // doc.toJSON does not do stuff like converting ObjectIds to string, or date strings to date objects. That's why we use JSON.parse/stringify here\n const result: Document = JSON.parse(JSON.stringify(doc))\n const verificationToken = doc._verificationToken\n\n // custom id type reset\n result.id = result._id\n if (verificationToken) {\n result._verificationToken = verificationToken\n }\n\n return result\n}\n"],"names":["handleError","withSession","create","collection","data","req","Model","collections","options","doc","error","result","JSON","parse","stringify","verificationToken","_verificationToken","id","_id"],"mappings":"AAIA,SAASA,WAAW,QAAQ,6BAA4B;AACxD,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,SAAiB,eAAeA,OAE3C,EAAEC,UAAU,EAAEC,IAAI,EAAEC,MAAM,CAAC,CAAmB,EAAE;IAEhD,MAAMC,QAAQ,IAAI,CAACC,WAAW,CAACJ,WAAW;IAC1C,MAAMK,UAAU,MAAMP,YAAY,IAAI,EAAEI;IACxC,IAAII;IACJ,IAAI;QACD,CAACA,IAAI,GAAG,MAAMH,MAAMJ,MAAM,CAAC;YAACE;SAAK,EAAEI;IACtC,EAAE,OAAOE,OAAO;QACdV,YAAY;YAAEG;YAAYO;YAAOL;QAAI;IACvC;IAEA,iJAAiJ;IACjJ,MAAMM,SAAmBC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL;IACnD,MAAMM,oBAAoBN,IAAIO,kBAAkB;IAEhD,uBAAuB;IACvBL,OAAOM,EAAE,GAAGN,OAAOO,GAAG;IACtB,IAAIH,mBAAmB;QACrBJ,OAAOK,kBAAkB,GAAGD;IAC9B;IAEA,OAAOJ;AACT,EAAC"}
|
package/dist/createGlobal.d.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"createGlobal.d.ts","sourceRoot":"","sources":["../src/createGlobal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,
|
1
|
+
{"version":3,"file":"createGlobal.d.ts","sourceRoot":"","sources":["../src/createGlobal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAkB,MAAM,SAAS,CAAA;AAO3D,eAAO,MAAM,YAAY,EAAE,YAoB1B,CAAA"}
|
package/dist/createGlobal.js
CHANGED
@@ -6,7 +6,7 @@ export const createGlobal = async function createGlobal({ slug, data, req = {} }
|
|
6
6
|
globalType: slug,
|
7
7
|
...data
|
8
8
|
};
|
9
|
-
const options = withSession(this, req
|
9
|
+
const options = await withSession(this, req);
|
10
10
|
let [result] = await Model.create([
|
11
11
|
global
|
12
12
|
], options);
|
package/dist/createGlobal.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/createGlobal.ts"],"sourcesContent":["import type { CreateGlobal
|
1
|
+
{"version":3,"sources":["../src/createGlobal.ts"],"sourcesContent":["import type { CreateGlobal, PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport sanitizeInternalFields from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const createGlobal: CreateGlobal = async function createGlobal(\n this: MongooseAdapter,\n { slug, data, req = {} as PayloadRequest },\n) {\n const Model = this.globals\n const global = {\n globalType: slug,\n ...data,\n }\n const options = await withSession(this, req)\n\n let [result] = (await Model.create([global], options)) as any\n\n result = JSON.parse(JSON.stringify(result))\n\n // custom id type reset\n result.id = result._id\n result = sanitizeInternalFields(result)\n\n return result\n}\n"],"names":["sanitizeInternalFields","withSession","createGlobal","slug","data","req","Model","globals","global","globalType","options","result","create","JSON","parse","stringify","id","_id"],"mappings":"AAIA,OAAOA,4BAA4B,wCAAuC;AAC1E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,eAA6B,eAAeA,aAEvD,EAAEC,IAAI,EAAEC,IAAI,EAAEC,MAAM,CAAC,CAAmB,EAAE;IAE1C,MAAMC,QAAQ,IAAI,CAACC,OAAO;IAC1B,MAAMC,SAAS;QACbC,YAAYN;QACZ,GAAGC,IAAI;IACT;IACA,MAAMM,UAAU,MAAMT,YAAY,IAAI,EAAEI;IAExC,IAAI,CAACM,OAAO,GAAI,MAAML,MAAMM,MAAM,CAAC;QAACJ;KAAO,EAAEE;IAE7CC,SAASE,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACJ;IAEnC,uBAAuB;IACvBA,OAAOK,EAAE,GAAGL,OAAOM,GAAG;IACtBN,SAASX,uBAAuBW;IAEhC,OAAOA;AACT,EAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"createGlobalVersion.d.ts","sourceRoot":"","sources":["../src/createGlobalVersion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,
|
1
|
+
{"version":3,"file":"createGlobalVersion.d.ts","sourceRoot":"","sources":["../src/createGlobalVersion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAA4B,MAAM,SAAS,CAAA;AAM5E,eAAO,MAAM,mBAAmB,EAAE,mBAuDjC,CAAA"}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { withSession } from './withSession.js';
|
2
2
|
export const createGlobalVersion = async function createGlobalVersion({ autosave, createdAt, globalSlug, parent, req = {}, updatedAt, versionData }) {
|
3
3
|
const VersionModel = this.versions[globalSlug];
|
4
|
-
const options = withSession(this, req
|
4
|
+
const options = await withSession(this, req);
|
5
5
|
const [doc] = await VersionModel.create([
|
6
6
|
{
|
7
7
|
autosave,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/createGlobalVersion.ts"],"sourcesContent":["import type { CreateGlobalVersion
|
1
|
+
{"version":3,"sources":["../src/createGlobalVersion.ts"],"sourcesContent":["import type { CreateGlobalVersion, Document, PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { withSession } from './withSession.js'\n\nexport const createGlobalVersion: CreateGlobalVersion = async function createGlobalVersion(\n this: MongooseAdapter,\n { autosave, createdAt, globalSlug, parent, req = {} as PayloadRequest, updatedAt, versionData },\n) {\n const VersionModel = this.versions[globalSlug]\n const options = await withSession(this, req)\n\n const [doc] = await VersionModel.create(\n [\n {\n autosave,\n createdAt,\n latest: true,\n parent,\n updatedAt,\n version: versionData,\n },\n ],\n options,\n req,\n )\n\n await VersionModel.updateMany(\n {\n $and: [\n {\n _id: {\n $ne: doc._id,\n },\n },\n {\n parent: {\n $eq: parent,\n },\n },\n {\n latest: {\n $eq: true,\n },\n },\n ],\n },\n { $unset: { latest: 1 } },\n options,\n )\n\n const result: Document = JSON.parse(JSON.stringify(doc))\n const verificationToken = doc._verificationToken\n\n // custom id type reset\n result.id = result._id\n if (verificationToken) {\n result._verificationToken = verificationToken\n }\n return result\n}\n"],"names":["withSession","createGlobalVersion","autosave","createdAt","globalSlug","parent","req","updatedAt","versionData","VersionModel","versions","options","doc","create","latest","version","updateMany","$and","_id","$ne","$eq","$unset","result","JSON","parse","stringify","verificationToken","_verificationToken","id"],"mappings":"AAIA,SAASA,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,sBAA2C,eAAeA,oBAErE,EAAEC,QAAQ,EAAEC,SAAS,EAAEC,UAAU,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAAmB,EAAEC,SAAS,EAAEC,WAAW,EAAE;IAE/F,MAAMC,eAAe,IAAI,CAACC,QAAQ,CAACN,WAAW;IAC9C,MAAMO,UAAU,MAAMX,YAAY,IAAI,EAAEM;IAExC,MAAM,CAACM,IAAI,GAAG,MAAMH,aAAaI,MAAM,CACrC;QACE;YACEX;YACAC;YACAW,QAAQ;YACRT;YACAE;YACAQ,SAASP;QACX;KACD,EACDG,SACAL;IAGF,MAAMG,aAAaO,UAAU,CAC3B;QACEC,MAAM;YACJ;gBACEC,KAAK;oBACHC,KAAKP,IAAIM,GAAG;gBACd;YACF;YACA;gBACEb,QAAQ;oBACNe,KAAKf;gBACP;YACF;YACA;gBACES,QAAQ;oBACNM,KAAK;gBACP;YACF;SACD;IACH,GACA;QAAEC,QAAQ;YAAEP,QAAQ;QAAE;IAAE,GACxBH;IAGF,MAAMW,SAAmBC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACb;IACnD,MAAMc,oBAAoBd,IAAIe,kBAAkB;IAEhD,uBAAuB;IACvBL,OAAOM,EAAE,GAAGN,OAAOJ,GAAG;IACtB,IAAIQ,mBAAmB;QACrBJ,OAAOK,kBAAkB,GAAGD;IAC9B;IACA,OAAOJ;AACT,EAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"createMigration.d.ts","sourceRoot":"","sources":["../src/createMigration.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"createMigration.d.ts","sourceRoot":"","sources":["../src/createMigration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAyB,MAAM,SAAS,CAAA;AAsBrE,eAAO,MAAM,eAAe,EAAE,eAgC7B,CAAA"}
|
package/dist/createMigration.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
|
1
|
+
import fs from 'fs';
|
2
2
|
import path from 'path';
|
3
|
-
import { getPredefinedMigration } from 'payload
|
3
|
+
import { getPredefinedMigration } from 'payload';
|
4
4
|
import { fileURLToPath } from 'url';
|
5
5
|
const migrationTemplate = ({ downSQL, imports, upSQL })=>`import {
|
6
6
|
MigrateUpArgs,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/createMigration.ts"],"sourcesContent":["
|
1
|
+
{"version":3,"sources":["../src/createMigration.ts"],"sourcesContent":["import type { CreateMigration, MigrationTemplateArgs } from 'payload'\n\nimport fs from 'fs'\nimport path from 'path'\nimport { getPredefinedMigration } from 'payload'\nimport { fileURLToPath } from 'url'\n\nconst migrationTemplate = ({ downSQL, imports, upSQL }: MigrationTemplateArgs): string => `import {\n MigrateUpArgs,\n MigrateDownArgs,\n} from '@payloadcms/db-mongodb'\n${imports}\n\nexport async function up({ payload }: MigrateUpArgs): Promise<void> {\n${upSQL ?? ` // Migration code`}\n}\n\nexport async function down({ payload }: MigrateDownArgs): Promise<void> {\n${downSQL ?? ` // Migration code`}\n}\n`\n\nexport const createMigration: CreateMigration = async function createMigration({\n file,\n migrationName,\n payload,\n}) {\n const filename = fileURLToPath(import.meta.url)\n const dirname = path.dirname(filename)\n\n const dir = payload.db.migrationDir\n if (!fs.existsSync(dir)) {\n fs.mkdirSync(dir)\n }\n const predefinedMigration = await getPredefinedMigration({\n dirname,\n file,\n migrationName,\n payload,\n })\n\n const migrationFileContent = migrationTemplate(predefinedMigration)\n\n const [yyymmdd, hhmmss] = new Date().toISOString().split('T')\n const formattedDate = yyymmdd.replace(/\\D/g, '')\n const formattedTime = hhmmss.split('.')[0].replace(/\\D/g, '')\n\n const timestamp = `${formattedDate}_${formattedTime}`\n\n const formattedName = migrationName?.replace(/\\W/g, '_')\n const fileName = migrationName ? `${timestamp}_${formattedName}.ts` : `${timestamp}_migration.ts`\n const filePath = `${dir}/${fileName}`\n fs.writeFileSync(filePath, migrationFileContent)\n payload.logger.info({ msg: `Migration created at ${filePath}` })\n}\n"],"names":["fs","path","getPredefinedMigration","fileURLToPath","migrationTemplate","downSQL","imports","upSQL","createMigration","file","migrationName","payload","filename","url","dirname","dir","db","migrationDir","existsSync","mkdirSync","predefinedMigration","migrationFileContent","yyymmdd","hhmmss","Date","toISOString","split","formattedDate","replace","formattedTime","timestamp","formattedName","fileName","filePath","writeFileSync","logger","info","msg"],"mappings":"AAEA,OAAOA,QAAQ,KAAI;AACnB,OAAOC,UAAU,OAAM;AACvB,SAASC,sBAAsB,QAAQ,UAAS;AAChD,SAASC,aAAa,QAAQ,MAAK;AAEnC,MAAMC,oBAAoB,CAAC,EAAEC,OAAO,EAAEC,OAAO,EAAEC,KAAK,EAAyB,GAAa,CAAC;;;;AAI3F,EAAED,QAAQ;;;AAGV,EAAEC,SAAS,CAAC,mBAAmB,CAAC,CAAC;;;;AAIjC,EAAEF,WAAW,CAAC,mBAAmB,CAAC,CAAC;;AAEnC,CAAC;AAED,OAAO,MAAMG,kBAAmC,eAAeA,gBAAgB,EAC7EC,IAAI,EACJC,aAAa,EACbC,OAAO,EACR;IACC,MAAMC,WAAWT,cAAc,YAAYU,GAAG;IAC9C,MAAMC,UAAUb,KAAKa,OAAO,CAACF;IAE7B,MAAMG,MAAMJ,QAAQK,EAAE,CAACC,YAAY;IACnC,IAAI,CAACjB,GAAGkB,UAAU,CAACH,MAAM;QACvBf,GAAGmB,SAAS,CAACJ;IACf;IACA,MAAMK,sBAAsB,MAAMlB,uBAAuB;QACvDY;QACAL;QACAC;QACAC;IACF;IAEA,MAAMU,uBAAuBjB,kBAAkBgB;IAE/C,MAAM,CAACE,SAASC,OAAO,GAAG,IAAIC,OAAOC,WAAW,GAAGC,KAAK,CAAC;IACzD,MAAMC,gBAAgBL,QAAQM,OAAO,CAAC,OAAO;IAC7C,MAAMC,gBAAgBN,OAAOG,KAAK,CAAC,IAAI,CAAC,EAAE,CAACE,OAAO,CAAC,OAAO;IAE1D,MAAME,YAAY,CAAC,EAAEH,cAAc,CAAC,EAAEE,cAAc,CAAC;IAErD,MAAME,gBAAgBrB,eAAekB,QAAQ,OAAO;IACpD,MAAMI,WAAWtB,gBAAgB,CAAC,EAAEoB,UAAU,CAAC,EAAEC,cAAc,GAAG,CAAC,GAAG,CAAC,EAAED,UAAU,aAAa,CAAC;IACjG,MAAMG,WAAW,CAAC,EAAElB,IAAI,CAAC,EAAEiB,SAAS,CAAC;IACrChC,GAAGkC,aAAa,CAACD,UAAUZ;IAC3BV,QAAQwB,MAAM,CAACC,IAAI,CAAC;QAAEC,KAAK,CAAC,qBAAqB,EAAEJ,SAAS,CAAC;IAAC;AAChE,EAAC"}
|
package/dist/createVersion.d.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"createVersion.d.ts","sourceRoot":"","sources":["../src/createVersion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,
|
1
|
+
{"version":3,"file":"createVersion.d.ts","sourceRoot":"","sources":["../src/createVersion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAA4B,MAAM,SAAS,CAAA;AAMtE,eAAO,MAAM,aAAa,EAAE,aA+D3B,CAAA"}
|
package/dist/createVersion.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { withSession } from './withSession.js';
|
2
2
|
export const createVersion = async function createVersion({ autosave, collectionSlug, createdAt, parent, req = {}, updatedAt, versionData }) {
|
3
3
|
const VersionModel = this.versions[collectionSlug];
|
4
|
-
const options = withSession(this, req
|
4
|
+
const options = await withSession(this, req);
|
5
5
|
const [doc] = await VersionModel.create([
|
6
6
|
{
|
7
7
|
autosave,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/createVersion.ts"],"sourcesContent":["import type { CreateVersion
|
1
|
+
{"version":3,"sources":["../src/createVersion.ts"],"sourcesContent":["import type { CreateVersion, Document, PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { withSession } from './withSession.js'\n\nexport const createVersion: CreateVersion = async function createVersion(\n this: MongooseAdapter,\n {\n autosave,\n collectionSlug,\n createdAt,\n parent,\n req = {} as PayloadRequest,\n updatedAt,\n versionData,\n },\n) {\n const VersionModel = this.versions[collectionSlug]\n const options = await withSession(this, req)\n\n const [doc] = await VersionModel.create(\n [\n {\n autosave,\n createdAt,\n latest: true,\n parent,\n updatedAt,\n version: versionData,\n },\n ],\n options,\n req,\n )\n\n await VersionModel.updateMany(\n {\n $and: [\n {\n _id: {\n $ne: doc._id,\n },\n },\n {\n parent: {\n $eq: parent,\n },\n },\n {\n latest: {\n $eq: true,\n },\n },\n ],\n },\n { $unset: { latest: 1 } },\n options,\n )\n\n const result: Document = JSON.parse(JSON.stringify(doc))\n const verificationToken = doc._verificationToken\n\n // custom id type reset\n result.id = result._id\n if (verificationToken) {\n result._verificationToken = verificationToken\n }\n return result\n}\n"],"names":["withSession","createVersion","autosave","collectionSlug","createdAt","parent","req","updatedAt","versionData","VersionModel","versions","options","doc","create","latest","version","updateMany","$and","_id","$ne","$eq","$unset","result","JSON","parse","stringify","verificationToken","_verificationToken","id"],"mappings":"AAIA,SAASA,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,gBAA+B,eAAeA,cAEzD,EACEC,QAAQ,EACRC,cAAc,EACdC,SAAS,EACTC,MAAM,EACNC,MAAM,CAAC,CAAmB,EAC1BC,SAAS,EACTC,WAAW,EACZ;IAED,MAAMC,eAAe,IAAI,CAACC,QAAQ,CAACP,eAAe;IAClD,MAAMQ,UAAU,MAAMX,YAAY,IAAI,EAAEM;IAExC,MAAM,CAACM,IAAI,GAAG,MAAMH,aAAaI,MAAM,CACrC;QACE;YACEX;YACAE;YACAU,QAAQ;YACRT;YACAE;YACAQ,SAASP;QACX;KACD,EACDG,SACAL;IAGF,MAAMG,aAAaO,UAAU,CAC3B;QACEC,MAAM;YACJ;gBACEC,KAAK;oBACHC,KAAKP,IAAIM,GAAG;gBACd;YACF;YACA;gBACEb,QAAQ;oBACNe,KAAKf;gBACP;YACF;YACA;gBACES,QAAQ;oBACNM,KAAK;gBACP;YACF;SACD;IACH,GACA;QAAEC,QAAQ;YAAEP,QAAQ;QAAE;IAAE,GACxBH;IAGF,MAAMW,SAAmBC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACb;IACnD,MAAMc,oBAAoBd,IAAIe,kBAAkB;IAEhD,uBAAuB;IACvBL,OAAOM,EAAE,GAAGN,OAAOJ,GAAG;IACtB,IAAIQ,mBAAmB;QACrBJ,OAAOK,kBAAkB,GAAGD;IAC9B;IACA,OAAOJ;AACT,EAAC"}
|
package/dist/deleteMany.d.ts
CHANGED
package/dist/deleteMany.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"deleteMany.d.ts","sourceRoot":"","sources":["../src/deleteMany.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,
|
1
|
+
{"version":3,"file":"deleteMany.d.ts","sourceRoot":"","sources":["../src/deleteMany.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAkB,MAAM,SAAS,CAAA;AAMzD,eAAO,MAAM,UAAU,EAAE,UAgBxB,CAAA"}
|
package/dist/deleteMany.js
CHANGED
@@ -2,7 +2,7 @@ import { withSession } from './withSession.js';
|
|
2
2
|
export const deleteMany = async function deleteMany({ collection, req = {}, where }) {
|
3
3
|
const Model = this.collections[collection];
|
4
4
|
const options = {
|
5
|
-
...withSession(this, req
|
5
|
+
...await withSession(this, req),
|
6
6
|
lean: true
|
7
7
|
};
|
8
8
|
const query = await Model.buildQuery({
|
package/dist/deleteMany.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/deleteMany.ts"],"sourcesContent":["import type { DeleteMany
|
1
|
+
{"version":3,"sources":["../src/deleteMany.ts"],"sourcesContent":["import type { DeleteMany, PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { withSession } from './withSession.js'\n\nexport const deleteMany: DeleteMany = async function deleteMany(\n this: MongooseAdapter,\n { collection, req = {} as PayloadRequest, where },\n) {\n const Model = this.collections[collection]\n const options = {\n ...(await withSession(this, req)),\n lean: true,\n }\n\n const query = await Model.buildQuery({\n payload: this.payload,\n where,\n })\n\n await Model.deleteMany(query, options)\n}\n"],"names":["withSession","deleteMany","collection","req","where","Model","collections","options","lean","query","buildQuery","payload"],"mappings":"AAIA,SAASA,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,aAAyB,eAAeA,WAEnD,EAAEC,UAAU,EAAEC,MAAM,CAAC,CAAmB,EAAEC,KAAK,EAAE;IAEjD,MAAMC,QAAQ,IAAI,CAACC,WAAW,CAACJ,WAAW;IAC1C,MAAMK,UAAU;QACd,GAAI,MAAMP,YAAY,IAAI,EAAEG,IAAI;QAChCK,MAAM;IACR;IAEA,MAAMC,QAAQ,MAAMJ,MAAMK,UAAU,CAAC;QACnCC,SAAS,IAAI,CAACA,OAAO;QACrBP;IACF;IAEA,MAAMC,MAAMJ,UAAU,CAACQ,OAAOF;AAChC,EAAC"}
|
package/dist/deleteOne.d.ts
CHANGED
package/dist/deleteOne.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"deleteOne.d.ts","sourceRoot":"","sources":["../src/deleteOne.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,
|
1
|
+
{"version":3,"file":"deleteOne.d.ts","sourceRoot":"","sources":["../src/deleteOne.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAA4B,MAAM,SAAS,CAAA;AAOlE,eAAO,MAAM,SAAS,EAAE,SAqBvB,CAAA"}
|
package/dist/deleteOne.js
CHANGED
@@ -2,7 +2,7 @@ import sanitizeInternalFields from './utilities/sanitizeInternalFields.js';
|
|
2
2
|
import { withSession } from './withSession.js';
|
3
3
|
export const deleteOne = async function deleteOne({ collection, req = {}, where }) {
|
4
4
|
const Model = this.collections[collection];
|
5
|
-
const options = withSession(this, req
|
5
|
+
const options = await withSession(this, req);
|
6
6
|
const query = await Model.buildQuery({
|
7
7
|
payload: this.payload,
|
8
8
|
where
|
package/dist/deleteOne.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/deleteOne.ts"],"sourcesContent":["import type { DeleteOne
|
1
|
+
{"version":3,"sources":["../src/deleteOne.ts"],"sourcesContent":["import type { DeleteOne, Document, PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport sanitizeInternalFields from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const deleteOne: DeleteOne = async function deleteOne(\n this: MongooseAdapter,\n { collection, req = {} as PayloadRequest, where },\n) {\n const Model = this.collections[collection]\n const options = await withSession(this, req)\n\n const query = await Model.buildQuery({\n payload: this.payload,\n where,\n })\n\n const doc = await Model.findOneAndDelete(query, options).lean()\n\n let result: Document = JSON.parse(JSON.stringify(doc))\n\n // custom id type reset\n result.id = result._id\n result = sanitizeInternalFields(result)\n\n return result\n}\n"],"names":["sanitizeInternalFields","withSession","deleteOne","collection","req","where","Model","collections","options","query","buildQuery","payload","doc","findOneAndDelete","lean","result","JSON","parse","stringify","id","_id"],"mappings":"AAIA,OAAOA,4BAA4B,wCAAuC;AAC1E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,YAAuB,eAAeA,UAEjD,EAAEC,UAAU,EAAEC,MAAM,CAAC,CAAmB,EAAEC,KAAK,EAAE;IAEjD,MAAMC,QAAQ,IAAI,CAACC,WAAW,CAACJ,WAAW;IAC1C,MAAMK,UAAU,MAAMP,YAAY,IAAI,EAAEG;IAExC,MAAMK,QAAQ,MAAMH,MAAMI,UAAU,CAAC;QACnCC,SAAS,IAAI,CAACA,OAAO;QACrBN;IACF;IAEA,MAAMO,MAAM,MAAMN,MAAMO,gBAAgB,CAACJ,OAAOD,SAASM,IAAI;IAE7D,IAAIC,SAAmBC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACN;IAEjD,uBAAuB;IACvBG,OAAOI,EAAE,GAAGJ,OAAOK,GAAG;IACtBL,SAASf,uBAAuBe;IAEhC,OAAOA;AACT,EAAC"}
|
package/dist/deleteVersions.d.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"deleteVersions.d.ts","sourceRoot":"","sources":["../src/deleteVersions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,
|
1
|
+
{"version":3,"file":"deleteVersions.d.ts","sourceRoot":"","sources":["../src/deleteVersions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAkB,MAAM,SAAS,CAAA;AAM7D,eAAO,MAAM,cAAc,EAAE,cAiB5B,CAAA"}
|
package/dist/deleteVersions.js
CHANGED
@@ -2,7 +2,7 @@ import { withSession } from './withSession.js';
|
|
2
2
|
export const deleteVersions = async function deleteVersions({ collection, locale, req = {}, where }) {
|
3
3
|
const VersionsModel = this.versions[collection];
|
4
4
|
const options = {
|
5
|
-
...withSession(this, req
|
5
|
+
...await withSession(this, req),
|
6
6
|
lean: true
|
7
7
|
};
|
8
8
|
const query = await VersionsModel.buildQuery({
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/deleteVersions.ts"],"sourcesContent":["import type { DeleteVersions
|
1
|
+
{"version":3,"sources":["../src/deleteVersions.ts"],"sourcesContent":["import type { DeleteVersions, PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { withSession } from './withSession.js'\n\nexport const deleteVersions: DeleteVersions = async function deleteVersions(\n this: MongooseAdapter,\n { collection, locale, req = {} as PayloadRequest, where },\n) {\n const VersionsModel = this.versions[collection]\n const options = {\n ...(await withSession(this, req)),\n lean: true,\n }\n\n const query = await VersionsModel.buildQuery({\n locale,\n payload: this.payload,\n where,\n })\n\n await VersionsModel.deleteMany(query, options)\n}\n"],"names":["withSession","deleteVersions","collection","locale","req","where","VersionsModel","versions","options","lean","query","buildQuery","payload","deleteMany"],"mappings":"AAIA,SAASA,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,iBAAiC,eAAeA,eAE3D,EAAEC,UAAU,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAAmB,EAAEC,KAAK,EAAE;IAEzD,MAAMC,gBAAgB,IAAI,CAACC,QAAQ,CAACL,WAAW;IAC/C,MAAMM,UAAU;QACd,GAAI,MAAMR,YAAY,IAAI,EAAEI,IAAI;QAChCK,MAAM;IACR;IAEA,MAAMC,QAAQ,MAAMJ,cAAcK,UAAU,CAAC;QAC3CR;QACAS,SAAS,IAAI,CAACA,OAAO;QACrBP;IACF;IAEA,MAAMC,cAAcO,UAAU,CAACH,OAAOF;AACxC,EAAC"}
|
package/dist/destroy.d.ts
CHANGED
package/dist/destroy.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"destroy.d.ts","sourceRoot":"","sources":["../src/destroy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,
|
1
|
+
{"version":3,"file":"destroy.d.ts","sourceRoot":"","sources":["../src/destroy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAMtC,eAAO,MAAM,OAAO,EAAE,OAQrB,CAAA"}
|
package/dist/destroy.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/destroy.ts"],"sourcesContent":["import type { Destroy } from 'payload
|
1
|
+
{"version":3,"sources":["../src/destroy.ts"],"sourcesContent":["import type { Destroy } from 'payload'\n\nimport mongoose from 'mongoose'\n\nimport type { MongooseAdapter } from './index.js'\n\nexport const destroy: Destroy = async function destroy(this: MongooseAdapter) {\n if (this.mongoMemoryServer) {\n await this.mongoMemoryServer.stop()\n } else {\n await mongoose.disconnect()\n }\n\n Object.keys(mongoose.models).map((model) => mongoose.deleteModel(model))\n}\n"],"names":["mongoose","destroy","mongoMemoryServer","stop","disconnect","Object","keys","models","map","model","deleteModel"],"mappings":"AAEA,OAAOA,cAAc,WAAU;AAI/B,OAAO,MAAMC,UAAmB,eAAeA;IAC7C,IAAI,IAAI,CAACC,iBAAiB,EAAE;QAC1B,MAAM,IAAI,CAACA,iBAAiB,CAACC,IAAI;IACnC,OAAO;QACL,MAAMH,SAASI,UAAU;IAC3B;IAEAC,OAAOC,IAAI,CAACN,SAASO,MAAM,EAAEC,GAAG,CAAC,CAACC,QAAUT,SAASU,WAAW,CAACD;AACnE,EAAC"}
|
package/dist/find.d.ts
CHANGED
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,
|
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,IAiFlB,CAAA"}
|
package/dist/find.js
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
import { flattenWhereToOperators } from 'payload
|
1
|
+
import { flattenWhereToOperators } from 'payload';
|
2
2
|
import { buildSortParam } from './queries/buildSortParam.js';
|
3
3
|
import sanitizeInternalFields from './utilities/sanitizeInternalFields.js';
|
4
4
|
import { withSession } from './withSession.js';
|
5
5
|
export const find = async function find({ collection, limit, locale, page, pagination, req = {}, sort: sortArg, where }) {
|
6
6
|
const Model = this.collections[collection];
|
7
7
|
const collectionConfig = this.payload.collections[collection].config;
|
8
|
-
const options = withSession(this, req
|
8
|
+
const options = await withSession(this, req);
|
9
9
|
let hasNearConstraint = false;
|
10
10
|
if (where) {
|
11
11
|
const constraints = flattenWhereToOperators(where);
|
@@ -66,7 +66,6 @@ export const find = async function find({ collection, limit, locale, page, pagin
|
|
66
66
|
return {
|
67
67
|
...result,
|
68
68
|
docs: docs.map((doc)=>{
|
69
|
-
// eslint-disable-next-line no-param-reassign
|
70
69
|
doc.id = doc._id;
|
71
70
|
return sanitizeInternalFields(doc);
|
72
71
|
})
|
package/dist/find.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/find.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { Find
|
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,CAACA,qBAAqBR,OAAOC,IAAI,CAACK,OAAOG,MAAM,KAAK,KAAK,IAAI,CAACK,iBAAiB,KAAK,MAAM;QAC5F,mHAAmH;QACnH,qHAAqH;QACrH,mHAAmH;QACnH,4BAA4B;QAC5BJ,kBAAkBK,gBAAgB,GAAG;YACnC,OAAOC,QAAQC,OAAO,CACpB3B,MAAM4B,cAAc,CAACZ,OAAO;gBAC1B,GAAGX,OAAO;gBACVwB,MAAM;oBAAEC,KAAK;gBAAE;YACjB;QAEJ;IACF;IAEA,IAAItC,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,MAAMoC,SAAS,MAAM/B,MAAMgC,QAAQ,CAAChB,OAAOI;IAC3C,MAAMa,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,OAAO1C,uBAAuBkD;QAChC;IACF;AACF,EAAC"}
|
package/dist/findGlobal.d.ts
CHANGED
package/dist/findGlobal.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"findGlobal.d.ts","sourceRoot":"","sources":["../src/findGlobal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,
|
1
|
+
{"version":3,"file":"findGlobal.d.ts","sourceRoot":"","sources":["../src/findGlobal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAkB,MAAM,SAAS,CAAA;AASzD,eAAO,MAAM,UAAU,EAAE,UA+BxB,CAAA"}
|
package/dist/findGlobal.js
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
import { combineQueries } from 'payload
|
1
|
+
import { combineQueries } from 'payload';
|
2
2
|
import sanitizeInternalFields from './utilities/sanitizeInternalFields.js';
|
3
3
|
import { withSession } from './withSession.js';
|
4
4
|
export const findGlobal = async function findGlobal({ slug, locale, req = {}, where }) {
|
5
5
|
const Model = this.globals;
|
6
6
|
const options = {
|
7
|
-
...withSession(this, req
|
7
|
+
...await withSession(this, req),
|
8
8
|
lean: true
|
9
9
|
};
|
10
10
|
const query = await Model.buildQuery({
|
package/dist/findGlobal.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/findGlobal.ts"],"sourcesContent":["import type { FindGlobal
|
1
|
+
{"version":3,"sources":["../src/findGlobal.ts"],"sourcesContent":["import type { FindGlobal, PayloadRequest } from 'payload'\n\nimport { combineQueries } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport sanitizeInternalFields from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const findGlobal: FindGlobal = async function findGlobal(\n this: MongooseAdapter,\n { slug, locale, req = {} as PayloadRequest, where },\n) {\n const Model = this.globals\n const options = {\n ...(await withSession(this, req)),\n lean: true,\n }\n\n const query = await Model.buildQuery({\n globalSlug: slug,\n locale,\n payload: this.payload,\n where: combineQueries({ globalType: { equals: slug } }, where),\n })\n\n let doc = (await Model.findOne(query, {}, options)) as any\n\n if (!doc) {\n return null\n }\n if (doc._id) {\n doc.id = doc._id\n delete doc._id\n }\n\n doc = JSON.parse(JSON.stringify(doc))\n doc = sanitizeInternalFields(doc)\n\n return doc\n}\n"],"names":["combineQueries","sanitizeInternalFields","withSession","findGlobal","slug","locale","req","where","Model","globals","options","lean","query","buildQuery","globalSlug","payload","globalType","equals","doc","findOne","_id","id","JSON","parse","stringify"],"mappings":"AAEA,SAASA,cAAc,QAAQ,UAAS;AAIxC,OAAOC,4BAA4B,wCAAuC;AAC1E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,aAAyB,eAAeA,WAEnD,EAAEC,IAAI,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAAmB,EAAEC,KAAK,EAAE;IAEnD,MAAMC,QAAQ,IAAI,CAACC,OAAO;IAC1B,MAAMC,UAAU;QACd,GAAI,MAAMR,YAAY,IAAI,EAAEI,IAAI;QAChCK,MAAM;IACR;IAEA,MAAMC,QAAQ,MAAMJ,MAAMK,UAAU,CAAC;QACnCC,YAAYV;QACZC;QACAU,SAAS,IAAI,CAACA,OAAO;QACrBR,OAAOP,eAAe;YAAEgB,YAAY;gBAAEC,QAAQb;YAAK;QAAE,GAAGG;IAC1D;IAEA,IAAIW,MAAO,MAAMV,MAAMW,OAAO,CAACP,OAAO,CAAC,GAAGF;IAE1C,IAAI,CAACQ,KAAK;QACR,OAAO;IACT;IACA,IAAIA,IAAIE,GAAG,EAAE;QACXF,IAAIG,EAAE,GAAGH,IAAIE,GAAG;QAChB,OAAOF,IAAIE,GAAG;IAChB;IAEAF,MAAMI,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACN;IAChCA,MAAMjB,uBAAuBiB;IAE7B,OAAOA;AACT,EAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"findGlobalVersions.d.ts","sourceRoot":"","sources":["../src/findGlobalVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,
|
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,kBAmGhC,CAAA"}
|
@@ -1,5 +1,4 @@
|
|
1
|
-
import { flattenWhereToOperators } from 'payload
|
2
|
-
import { buildVersionGlobalFields } from 'payload/versions';
|
1
|
+
import { buildVersionGlobalFields, flattenWhereToOperators } from 'payload';
|
3
2
|
import { buildSortParam } from './queries/buildSortParam.js';
|
4
3
|
import sanitizeInternalFields from './utilities/sanitizeInternalFields.js';
|
5
4
|
import { withSession } from './withSession.js';
|
@@ -7,7 +6,7 @@ export const findGlobalVersions = async function findGlobalVersions({ global, li
|
|
7
6
|
const Model = this.versions[global];
|
8
7
|
const versionFields = buildVersionGlobalFields(this.payload.globals.config.find(({ slug })=>slug === global));
|
9
8
|
const options = {
|
10
|
-
...withSession(this, req
|
9
|
+
...await withSession(this, req),
|
11
10
|
limit,
|
12
11
|
skip
|
13
12
|
};
|
@@ -73,7 +72,6 @@ export const findGlobalVersions = async function findGlobalVersions({ global, li
|
|
73
72
|
return {
|
74
73
|
...result,
|
75
74
|
docs: docs.map((doc)=>{
|
76
|
-
// eslint-disable-next-line no-param-reassign
|
77
75
|
doc.id = doc._id;
|
78
76
|
return sanitizeInternalFields(doc);
|
79
77
|
})
|