@payloadcms/db-mongodb 3.0.0-alpha.9 → 3.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -2
- package/dist/connect.d.ts.map +1 -1
- package/dist/connect.js +20 -25
- package/dist/connect.js.map +1 -0
- package/dist/create.js +6 -21
- package/dist/create.js.map +1 -0
- package/dist/createGlobal.js +6 -21
- package/dist/createGlobal.js.map +1 -0
- package/dist/createGlobalVersion.js +4 -14
- package/dist/createGlobalVersion.js.map +1 -0
- package/dist/createMigration.d.ts.map +1 -1
- package/dist/createMigration.js +15 -25
- package/dist/createMigration.js.map +1 -0
- package/dist/createVersion.js +4 -14
- package/dist/createVersion.js.map +1 -0
- package/dist/deleteMany.js +4 -14
- package/dist/deleteMany.js.map +1 -0
- package/dist/deleteOne.js +6 -21
- package/dist/deleteOne.js.map +1 -0
- package/dist/deleteVersions.js +4 -14
- package/dist/deleteVersions.js.map +1 -0
- package/dist/destroy.js +5 -21
- package/dist/destroy.js.map +1 -0
- package/dist/find.js +10 -25
- package/dist/find.js.map +1 -0
- package/dist/findGlobal.js +8 -23
- package/dist/findGlobal.js.map +1 -0
- package/dist/findGlobalVersions.js +12 -27
- package/dist/findGlobalVersions.js.map +1 -0
- package/dist/findOne.js +6 -21
- package/dist/findOne.js.map +1 -0
- package/dist/findVersions.js +10 -25
- package/dist/findVersions.js.map +1 -0
- package/dist/index.d.ts +36 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +65 -80
- package/dist/index.js.map +1 -0
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +33 -39
- package/dist/init.js.map +1 -0
- package/dist/migrateFresh.d.ts +1 -1
- package/dist/migrateFresh.d.ts.map +1 -1
- package/dist/migrateFresh.js +13 -26
- package/dist/migrateFresh.js.map +1 -0
- package/dist/models/buildCollectionSchema.d.ts +25 -0
- package/dist/models/buildCollectionSchema.d.ts.map +1 -1
- package/dist/models/buildCollectionSchema.js +8 -23
- package/dist/models/buildCollectionSchema.js.map +1 -0
- package/dist/models/buildGlobalModel.d.ts +1 -1
- package/dist/models/buildGlobalModel.d.ts.map +1 -1
- package/dist/models/buildGlobalModel.js +9 -24
- package/dist/models/buildGlobalModel.js.map +1 -0
- package/dist/models/buildSchema.d.ts +26 -2
- package/dist/models/buildSchema.d.ts.map +1 -1
- package/dist/models/buildSchema.js +23 -33
- package/dist/models/buildSchema.js.map +1 -0
- package/dist/queries/buildAndOrConditions.js +4 -14
- package/dist/queries/buildAndOrConditions.js.map +1 -0
- package/dist/queries/buildQuery.js +6 -16
- package/dist/queries/buildQuery.js.map +1 -0
- package/dist/queries/buildSearchParams.d.ts.map +1 -1
- package/dist/queries/buildSearchParams.js +21 -32
- package/dist/queries/buildSearchParams.js.map +1 -0
- package/dist/queries/buildSortParam.d.ts +25 -0
- package/dist/queries/buildSortParam.d.ts.map +1 -1
- package/dist/queries/buildSortParam.js +4 -14
- package/dist/queries/buildSortParam.js.map +1 -0
- package/dist/queries/getLocalizedSortProperty.js +8 -18
- package/dist/queries/getLocalizedSortProperty.js.map +1 -0
- package/dist/queries/getLocalizedSortProperty.spec.js +19 -23
- package/dist/queries/getLocalizedSortProperty.spec.js.map +1 -0
- package/dist/queries/mock.js +1 -2
- package/dist/queries/mock.js.map +1 -0
- package/dist/queries/operatorMap.js +2 -12
- package/dist/queries/operatorMap.js.map +1 -0
- package/dist/queries/parseParams.js +12 -27
- package/dist/queries/parseParams.js.map +1 -0
- package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
- package/dist/queries/sanitizeQueryValue.js +9 -24
- package/dist/queries/sanitizeQueryValue.js.map +1 -0
- package/dist/queryDrafts.js +11 -26
- package/dist/queryDrafts.js.map +1 -0
- package/dist/testCredentials.js +4 -25
- package/dist/testCredentials.js.map +1 -0
- package/dist/transactions/beginTransaction.js +6 -16
- package/dist/transactions/beginTransaction.js.map +1 -0
- package/dist/transactions/commitTransaction.js +2 -12
- package/dist/transactions/commitTransaction.js.map +1 -0
- package/dist/transactions/rollbackTransaction.js +2 -12
- package/dist/transactions/rollbackTransaction.js.map +1 -0
- package/dist/types.d.ts +26 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +2 -5
- package/dist/types.js.map +1 -0
- package/dist/updateGlobal.js +6 -21
- package/dist/updateGlobal.js.map +1 -0
- package/dist/updateGlobalVersion.d.ts +1 -1
- package/dist/updateGlobalVersion.d.ts.map +1 -1
- package/dist/updateGlobalVersion.js +4 -14
- package/dist/updateGlobalVersion.js.map +1 -0
- package/dist/updateOne.d.ts.map +1 -1
- package/dist/updateOne.js +8 -23
- package/dist/updateOne.js.map +1 -0
- package/dist/updateVersion.js +4 -14
- package/dist/updateVersion.js.map +1 -0
- package/dist/utilities/getDBName.d.ts +19 -0
- package/dist/utilities/getDBName.d.ts.map +1 -0
- package/dist/utilities/getDBName.js +19 -0
- package/dist/utilities/getDBName.js.map +1 -0
- package/dist/utilities/handleError.js +6 -21
- package/dist/utilities/handleError.js.map +1 -0
- package/dist/utilities/sanitizeInternalFields.d.ts.map +1 -1
- package/dist/utilities/sanitizeInternalFields.js +2 -12
- package/dist/utilities/sanitizeInternalFields.js.map +1 -0
- package/dist/withSession.d.ts +26 -1
- package/dist/withSession.d.ts.map +1 -1
- package/dist/withSession.js +5 -12
- package/dist/withSession.js.map +1 -0
- package/package.json +18 -10
- package/src/index.ts +198 -0
package/README.md
CHANGED
package/dist/connect.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../src/connect.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAM/C,eAAO,MAAM,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../src/connect.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAM/C,eAAO,MAAM,OAAO,EAAE,OAsDrB,CAAA"}
|
package/dist/connect.js
CHANGED
|
@@ -1,20 +1,8 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
})
|
|
5
|
-
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return connect;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _mongoose = /*#__PURE__*/ _interop_require_default(require("mongoose"));
|
|
12
|
-
function _interop_require_default(obj) {
|
|
13
|
-
return obj && obj.__esModule ? obj : {
|
|
14
|
-
default: obj
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
const connect = async function connect() {
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-var-requires */ import mongoose from 'mongoose';
|
|
2
|
+
export const connect = async function connect(options = {
|
|
3
|
+
hotReload: false
|
|
4
|
+
}) {
|
|
5
|
+
const { hotReload } = options;
|
|
18
6
|
if (this.url === false) {
|
|
19
7
|
return;
|
|
20
8
|
}
|
|
@@ -22,29 +10,36 @@ const connect = async function connect() {
|
|
|
22
10
|
throw new Error('Error: missing MongoDB connection URL.');
|
|
23
11
|
}
|
|
24
12
|
const urlToConnect = this.url;
|
|
25
|
-
const successfulConnectionMessage = 'Connected to MongoDB server successfully!';
|
|
26
13
|
const connectionOptions = {
|
|
27
14
|
autoIndex: true,
|
|
28
15
|
...this.connectOptions,
|
|
29
16
|
useFacet: undefined
|
|
30
17
|
};
|
|
18
|
+
if (hotReload) connectionOptions.autoIndex = false;
|
|
31
19
|
try {
|
|
32
|
-
this.connection = (await
|
|
20
|
+
this.connection = (await mongoose.connect(urlToConnect, connectionOptions)).connection;
|
|
21
|
+
// If we are running a replica set with MongoDB Memory Server,
|
|
22
|
+
// wait until the replica set elects a primary before proceeding
|
|
23
|
+
if (this.mongoMemoryServer) {
|
|
24
|
+
await new Promise((resolve)=>setTimeout(resolve, 2000));
|
|
25
|
+
}
|
|
33
26
|
const client = this.connection.getClient();
|
|
34
27
|
if (!client.options.replicaSet) {
|
|
35
28
|
this.transactionOptions = false;
|
|
36
29
|
this.beginTransaction = undefined;
|
|
37
30
|
}
|
|
38
|
-
if (
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
31
|
+
if (!this.mongoMemoryServer && !hotReload) {
|
|
32
|
+
if (process.env.PAYLOAD_DROP_DATABASE === 'true') {
|
|
33
|
+
this.payload.logger.info('---- DROPPING DATABASE ----');
|
|
34
|
+
await mongoose.connection.dropDatabase();
|
|
35
|
+
this.payload.logger.info('---- DROPPED DATABASE ----');
|
|
36
|
+
}
|
|
42
37
|
}
|
|
43
|
-
this.payload.logger.info(successfulConnectionMessage);
|
|
44
38
|
} catch (err) {
|
|
39
|
+
console.log(err);
|
|
45
40
|
this.payload.logger.error(`Error: cannot connect to MongoDB. Details: ${err.message}`, err);
|
|
46
41
|
process.exit(1);
|
|
47
42
|
}
|
|
48
43
|
};
|
|
49
44
|
|
|
50
|
-
//# sourceMappingURL=
|
|
45
|
+
//# sourceMappingURL=connect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/connect.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-var-requires */\nimport type { ConnectOptions } from 'mongoose'\nimport type { Connect } from 'payload/database'\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: ConnectOptions & { useFacet: undefined } = {\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"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,qDAAqD,GAIrD,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/create.js
CHANGED
|
@@ -1,30 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "create", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return create;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _handleError = /*#__PURE__*/ _interop_require_default(require("./utilities/handleError"));
|
|
12
|
-
const _withSession = require("./withSession");
|
|
13
|
-
function _interop_require_default(obj) {
|
|
14
|
-
return obj && obj.__esModule ? obj : {
|
|
15
|
-
default: obj
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
const create = async function create({ collection, data, req = {} }) {
|
|
1
|
+
import handleError from './utilities/handleError.js';
|
|
2
|
+
import { withSession } from './withSession.js';
|
|
3
|
+
export const create = async function create({ collection, data, req = {} }) {
|
|
19
4
|
const Model = this.collections[collection];
|
|
20
|
-
const options =
|
|
5
|
+
const options = withSession(this, req.transactionID);
|
|
21
6
|
let doc;
|
|
22
7
|
try {
|
|
23
8
|
[doc] = await Model.create([
|
|
24
9
|
data
|
|
25
10
|
], options);
|
|
26
11
|
} catch (error) {
|
|
27
|
-
(
|
|
12
|
+
handleError(error, req);
|
|
28
13
|
}
|
|
29
14
|
// 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
|
|
30
15
|
const result = JSON.parse(JSON.stringify(doc));
|
|
@@ -37,4 +22,4 @@ const create = async function create({ collection, data, req = {} }) {
|
|
|
37
22
|
return result;
|
|
38
23
|
};
|
|
39
24
|
|
|
40
|
-
//# sourceMappingURL=
|
|
25
|
+
//# sourceMappingURL=create.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/create.ts"],"sourcesContent":["import type { Create } from 'payload/database'\nimport type { Document, PayloadRequest } from 'payload/types'\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 = withSession(this, req.transactionID)\n let doc\n try {\n ;[doc] = await Model.create([data], options)\n } catch (error) {\n handleError(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","transactionID","doc","error","result","JSON","parse","stringify","verificationToken","_verificationToken","id","_id"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;","mappings":"AAKA,OAAOA,iBAAiB,6BAA4B;AACpD,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,UAAUP,YAAY,IAAI,EAAEI,IAAII,aAAa;IACnD,IAAIC;IACJ,IAAI;QACD,CAACA,IAAI,GAAG,MAAMJ,MAAMJ,MAAM,CAAC;YAACE;SAAK,EAAEI;IACtC,EAAE,OAAOG,OAAO;QACdX,YAAYW,OAAON;IACrB;IAEA,iJAAiJ;IACjJ,MAAMO,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.js
CHANGED
|
@@ -1,35 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "createGlobal", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return createGlobal;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _sanitizeInternalFields = /*#__PURE__*/ _interop_require_default(require("./utilities/sanitizeInternalFields"));
|
|
12
|
-
const _withSession = require("./withSession");
|
|
13
|
-
function _interop_require_default(obj) {
|
|
14
|
-
return obj && obj.__esModule ? obj : {
|
|
15
|
-
default: obj
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
const createGlobal = async function createGlobal({ data, req = {}, slug }) {
|
|
1
|
+
import sanitizeInternalFields from './utilities/sanitizeInternalFields.js';
|
|
2
|
+
import { withSession } from './withSession.js';
|
|
3
|
+
export const createGlobal = async function createGlobal({ slug, data, req = {} }) {
|
|
19
4
|
const Model = this.globals;
|
|
20
5
|
const global = {
|
|
21
6
|
globalType: slug,
|
|
22
7
|
...data
|
|
23
8
|
};
|
|
24
|
-
const options =
|
|
9
|
+
const options = withSession(this, req.transactionID);
|
|
25
10
|
let [result] = await Model.create([
|
|
26
11
|
global
|
|
27
12
|
], options);
|
|
28
13
|
result = JSON.parse(JSON.stringify(result));
|
|
29
14
|
// custom id type reset
|
|
30
15
|
result.id = result._id;
|
|
31
|
-
result = (
|
|
16
|
+
result = sanitizeInternalFields(result);
|
|
32
17
|
return result;
|
|
33
18
|
};
|
|
34
19
|
|
|
35
|
-
//# sourceMappingURL=
|
|
20
|
+
//# sourceMappingURL=createGlobal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/createGlobal.ts"],"sourcesContent":["import type { CreateGlobal } from 'payload/database'\nimport type { PayloadRequest } from 'payload/types'\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 = withSession(this, req.transactionID)\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","transactionID","result","create","JSON","parse","stringify","id","_id"],"rangeMappings":";;;;;;;;;;;;;;;;;","mappings":"AAKA,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,UAAUT,YAAY,IAAI,EAAEI,IAAIM,aAAa;IAEnD,IAAI,CAACC,OAAO,GAAI,MAAMN,MAAMO,MAAM,CAAC;QAACL;KAAO,EAAEE;IAE7CE,SAASE,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACJ;IAEnC,uBAAuB;IACvBA,OAAOK,EAAE,GAAGL,OAAOM,GAAG;IACtBN,SAASZ,uBAAuBY;IAEhC,OAAOA;AACT,EAAC"}
|
|
@@ -1,17 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "createGlobalVersion", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return createGlobalVersion;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _withSession = require("./withSession");
|
|
12
|
-
const createGlobalVersion = async function createGlobalVersion({ autosave, createdAt, globalSlug, parent, req = {}, updatedAt, versionData }) {
|
|
1
|
+
import { withSession } from './withSession.js';
|
|
2
|
+
export const createGlobalVersion = async function createGlobalVersion({ autosave, createdAt, globalSlug, parent, req = {}, updatedAt, versionData }) {
|
|
13
3
|
const VersionModel = this.versions[globalSlug];
|
|
14
|
-
const options =
|
|
4
|
+
const options = withSession(this, req.transactionID);
|
|
15
5
|
const [doc] = await VersionModel.create([
|
|
16
6
|
{
|
|
17
7
|
autosave,
|
|
@@ -55,4 +45,4 @@ const createGlobalVersion = async function createGlobalVersion({ autosave, creat
|
|
|
55
45
|
return result;
|
|
56
46
|
};
|
|
57
47
|
|
|
58
|
-
//# sourceMappingURL=
|
|
48
|
+
//# sourceMappingURL=createGlobalVersion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/createGlobalVersion.ts"],"sourcesContent":["import type { CreateGlobalVersion } from 'payload/database'\nimport type { PayloadRequest } from 'payload/types'\nimport type { Document } from 'payload/types'\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 = withSession(this, req.transactionID)\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","transactionID","doc","create","latest","version","updateMany","$and","_id","$ne","$eq","$unset","result","JSON","parse","stringify","verificationToken","_verificationToken","id"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAMA,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,UAAUX,YAAY,IAAI,EAAEM,IAAIM,aAAa;IAEnD,MAAM,CAACC,IAAI,GAAG,MAAMJ,aAAaK,MAAM,CACrC;QACE;YACEZ;YACAC;YACAY,QAAQ;YACRV;YACAE;YACAS,SAASR;QACX;KACD,EACDG,SACAL;IAGF,MAAMG,aAAaQ,UAAU,CAC3B;QACEC,MAAM;YACJ;gBACEC,KAAK;oBACHC,KAAKP,IAAIM,GAAG;gBACd;YACF;YACA;gBACEd,QAAQ;oBACNgB,KAAKhB;gBACP;YACF;YACA;gBACEU,QAAQ;oBACNM,KAAK;gBACP;YACF;SACD;IACH,GACA;QAAEC,QAAQ;YAAEP,QAAQ;QAAE;IAAE,GACxBJ;IAGF,MAAMY,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":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"createMigration.d.ts","sourceRoot":"","sources":["../src/createMigration.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAoBvD,eAAO,MAAM,eAAe,EAAE,eAsD7B,CAAA"}
|
package/dist/createMigration.js
CHANGED
|
@@ -1,20 +1,6 @@
|
|
|
1
|
-
/* eslint-disable no-restricted-syntax, no-await-in-loop */
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "createMigration", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return createMigration;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
|
|
12
|
-
const _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
13
|
-
function _interop_require_default(obj) {
|
|
14
|
-
return obj && obj.__esModule ? obj : {
|
|
15
|
-
default: obj
|
|
16
|
-
};
|
|
17
|
-
}
|
|
1
|
+
/* eslint-disable no-restricted-syntax, no-await-in-loop */ import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
18
4
|
const migrationTemplate = (upSQL, downSQL)=>`import {
|
|
19
5
|
MigrateUpArgs,
|
|
20
6
|
MigrateDownArgs,
|
|
@@ -28,10 +14,12 @@ export async function down({ payload }: MigrateDownArgs): Promise<void> {
|
|
|
28
14
|
${downSQL ?? ` // Migration code`}
|
|
29
15
|
};
|
|
30
16
|
`;
|
|
31
|
-
const createMigration = async function createMigration({ file, migrationName, payload }) {
|
|
17
|
+
export const createMigration = async function createMigration({ file, migrationName, payload }) {
|
|
18
|
+
const filename = fileURLToPath(import.meta.url);
|
|
19
|
+
const dirname = path.dirname(filename);
|
|
32
20
|
const dir = payload.db.migrationDir;
|
|
33
|
-
if (!
|
|
34
|
-
|
|
21
|
+
if (!fs.existsSync(dir)) {
|
|
22
|
+
fs.mkdirSync(dir);
|
|
35
23
|
}
|
|
36
24
|
let migrationFileContent;
|
|
37
25
|
// Check for predefined migration.
|
|
@@ -40,10 +28,12 @@ const createMigration = async function createMigration({ file, migrationName, pa
|
|
|
40
28
|
if (!file) file = migrationName;
|
|
41
29
|
const predefinedMigrationName = file.replace('@payloadcms/db-mongodb/', '');
|
|
42
30
|
migrationName = predefinedMigrationName;
|
|
43
|
-
const cleanPath =
|
|
31
|
+
const cleanPath = path.join(dirname, `../predefinedMigrations/${predefinedMigrationName}.js`);
|
|
44
32
|
// Check if predefined migration exists
|
|
45
|
-
if (
|
|
46
|
-
|
|
33
|
+
if (fs.existsSync(cleanPath)) {
|
|
34
|
+
let migration = await eval(`${typeof require === 'function' ? 'require' : 'import'}(${cleanPath})`);
|
|
35
|
+
if ('default' in migration) migration = migration.default;
|
|
36
|
+
const { down, up } = migration;
|
|
47
37
|
migrationFileContent = migrationTemplate(up, down);
|
|
48
38
|
} else {
|
|
49
39
|
payload.logger.error({
|
|
@@ -61,10 +51,10 @@ const createMigration = async function createMigration({ file, migrationName, pa
|
|
|
61
51
|
const formattedName = migrationName?.replace(/\W/g, '_');
|
|
62
52
|
const fileName = migrationName ? `${timestamp}_${formattedName}.ts` : `${timestamp}_migration.ts`;
|
|
63
53
|
const filePath = `${dir}/${fileName}`;
|
|
64
|
-
|
|
54
|
+
fs.writeFileSync(filePath, migrationFileContent);
|
|
65
55
|
payload.logger.info({
|
|
66
56
|
msg: `Migration created at ${filePath}`
|
|
67
57
|
});
|
|
68
58
|
};
|
|
69
59
|
|
|
70
|
-
//# sourceMappingURL=
|
|
60
|
+
//# sourceMappingURL=createMigration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/createMigration.ts"],"sourcesContent":["/* eslint-disable no-restricted-syntax, no-await-in-loop */\nimport type { CreateMigration } from 'payload/database'\n\nimport fs from 'fs'\nimport path from 'path'\nimport { fileURLToPath } from 'url'\n\nconst migrationTemplate = (upSQL?: string, downSQL?: string) => `import {\n MigrateUpArgs,\n MigrateDownArgs,\n} from \"@payloadcms/db-mongodb\";\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\n let migrationFileContent: string | undefined\n\n // Check for predefined migration.\n // Either passed in via --file or prefixed with @payloadcms/db-mongodb/\n if (file || migrationName?.startsWith('@payloadcms/db-mongodb/')) {\n if (!file) file = migrationName\n\n const predefinedMigrationName = file.replace('@payloadcms/db-mongodb/', '')\n migrationName = predefinedMigrationName\n const cleanPath = path.join(dirname, `../predefinedMigrations/${predefinedMigrationName}.js`)\n\n // Check if predefined migration exists\n if (fs.existsSync(cleanPath)) {\n let migration = await eval(\n `${typeof require === 'function' ? 'require' : 'import'}(${cleanPath})`,\n )\n if ('default' in migration) migration = migration.default\n const { down, up } = migration\n\n migrationFileContent = migrationTemplate(up, down)\n } else {\n payload.logger.error({\n msg: `Canned migration ${predefinedMigrationName} not found.`,\n })\n process.exit(1)\n }\n } else {\n migrationFileContent = migrationTemplate()\n }\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","fileURLToPath","migrationTemplate","upSQL","downSQL","createMigration","file","migrationName","payload","filename","url","dirname","dir","db","migrationDir","existsSync","mkdirSync","migrationFileContent","startsWith","predefinedMigrationName","replace","cleanPath","join","migration","eval","require","default","down","up","logger","error","msg","process","exit","yyymmdd","hhmmss","Date","toISOString","split","formattedDate","formattedTime","timestamp","formattedName","fileName","filePath","writeFileSync","info"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,yDAAyD,GAGzD,OAAOA,QAAQ,KAAI;AACnB,OAAOC,UAAU,OAAM;AACvB,SAASC,aAAa,QAAQ,MAAK;AAEnC,MAAMC,oBAAoB,CAACC,OAAgBC,UAAqB,CAAC;;;;;;AAMjE,EAAED,SAAS,CAAC,mBAAmB,CAAC,CAAC;;;;AAIjC,EAAEC,WAAW,CAAC,mBAAmB,CAAC,CAAC;;AAEnC,CAAC;AAED,OAAO,MAAMC,kBAAmC,eAAeA,gBAAgB,EAC7EC,IAAI,EACJC,aAAa,EACbC,OAAO,EACR;IACC,MAAMC,WAAWR,cAAc,YAAYS,GAAG;IAC9C,MAAMC,UAAUX,KAAKW,OAAO,CAACF;IAE7B,MAAMG,MAAMJ,QAAQK,EAAE,CAACC,YAAY;IACnC,IAAI,CAACf,GAAGgB,UAAU,CAACH,MAAM;QACvBb,GAAGiB,SAAS,CAACJ;IACf;IAEA,IAAIK;IAEJ,kCAAkC;IAClC,uEAAuE;IACvE,IAAIX,QAAQC,eAAeW,WAAW,4BAA4B;QAChE,IAAI,CAACZ,MAAMA,OAAOC;QAElB,MAAMY,0BAA0Bb,KAAKc,OAAO,CAAC,2BAA2B;QACxEb,gBAAgBY;QAChB,MAAME,YAAYrB,KAAKsB,IAAI,CAACX,SAAS,CAAC,wBAAwB,EAAEQ,wBAAwB,GAAG,CAAC;QAE5F,uCAAuC;QACvC,IAAIpB,GAAGgB,UAAU,CAACM,YAAY;YAC5B,IAAIE,YAAY,MAAMC,KACpB,CAAC,EAAE,OAAOC,YAAY,aAAa,YAAY,SAAS,CAAC,EAAEJ,UAAU,CAAC,CAAC;YAEzE,IAAI,aAAaE,WAAWA,YAAYA,UAAUG,OAAO;YACzD,MAAM,EAAEC,IAAI,EAAEC,EAAE,EAAE,GAAGL;YAErBN,uBAAuBf,kBAAkB0B,IAAID;QAC/C,OAAO;YACLnB,QAAQqB,MAAM,CAACC,KAAK,CAAC;gBACnBC,KAAK,CAAC,iBAAiB,EAAEZ,wBAAwB,WAAW,CAAC;YAC/D;YACAa,QAAQC,IAAI,CAAC;QACf;IACF,OAAO;QACLhB,uBAAuBf;IACzB;IAEA,MAAM,CAACgC,SAASC,OAAO,GAAG,IAAIC,OAAOC,WAAW,GAAGC,KAAK,CAAC;IACzD,MAAMC,gBAAgBL,QAAQd,OAAO,CAAC,OAAO;IAC7C,MAAMoB,gBAAgBL,OAAOG,KAAK,CAAC,IAAI,CAAC,EAAE,CAAClB,OAAO,CAAC,OAAO;IAE1D,MAAMqB,YAAY,CAAC,EAAEF,cAAc,CAAC,EAAEC,cAAc,CAAC;IAErD,MAAME,gBAAgBnC,eAAea,QAAQ,OAAO;IACpD,MAAMuB,WAAWpC,gBAAgB,CAAC,EAAEkC,UAAU,CAAC,EAAEC,cAAc,GAAG,CAAC,GAAG,CAAC,EAAED,UAAU,aAAa,CAAC;IACjG,MAAMG,WAAW,CAAC,EAAEhC,IAAI,CAAC,EAAE+B,SAAS,CAAC;IACrC5C,GAAG8C,aAAa,CAACD,UAAU3B;IAC3BT,QAAQqB,MAAM,CAACiB,IAAI,CAAC;QAAEf,KAAK,CAAC,qBAAqB,EAAEa,SAAS,CAAC;IAAC;AAChE,EAAC"}
|
package/dist/createVersion.js
CHANGED
|
@@ -1,17 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "createVersion", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return createVersion;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _withSession = require("./withSession");
|
|
12
|
-
const createVersion = async function createVersion({ autosave, collectionSlug, createdAt, parent, req = {}, updatedAt, versionData }) {
|
|
1
|
+
import { withSession } from './withSession.js';
|
|
2
|
+
export const createVersion = async function createVersion({ autosave, collectionSlug, createdAt, parent, req = {}, updatedAt, versionData }) {
|
|
13
3
|
const VersionModel = this.versions[collectionSlug];
|
|
14
|
-
const options =
|
|
4
|
+
const options = withSession(this, req.transactionID);
|
|
15
5
|
const [doc] = await VersionModel.create([
|
|
16
6
|
{
|
|
17
7
|
autosave,
|
|
@@ -55,4 +45,4 @@ const createVersion = async function createVersion({ autosave, collectionSlug, c
|
|
|
55
45
|
return result;
|
|
56
46
|
};
|
|
57
47
|
|
|
58
|
-
//# sourceMappingURL=
|
|
48
|
+
//# sourceMappingURL=createVersion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/createVersion.ts"],"sourcesContent":["import type { CreateVersion } from 'payload/database'\nimport type { PayloadRequest } from 'payload/types'\nimport type { Document } from 'payload/types'\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 = withSession(this, req.transactionID)\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","transactionID","doc","create","latest","version","updateMany","$and","_id","$ne","$eq","$unset","result","JSON","parse","stringify","verificationToken","_verificationToken","id"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAMA,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,UAAUX,YAAY,IAAI,EAAEM,IAAIM,aAAa;IAEnD,MAAM,CAACC,IAAI,GAAG,MAAMJ,aAAaK,MAAM,CACrC;QACE;YACEZ;YACAE;YACAW,QAAQ;YACRV;YACAE;YACAS,SAASR;QACX;KACD,EACDG,SACAL;IAGF,MAAMG,aAAaQ,UAAU,CAC3B;QACEC,MAAM;YACJ;gBACEC,KAAK;oBACHC,KAAKP,IAAIM,GAAG;gBACd;YACF;YACA;gBACEd,QAAQ;oBACNgB,KAAKhB;gBACP;YACF;YACA;gBACEU,QAAQ;oBACNM,KAAK;gBACP;YACF;SACD;IACH,GACA;QAAEC,QAAQ;YAAEP,QAAQ;QAAE;IAAE,GACxBJ;IAGF,MAAMY,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.js
CHANGED
|
@@ -1,18 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "deleteMany", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return deleteMany;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _withSession = require("./withSession");
|
|
12
|
-
const deleteMany = async function deleteMany({ collection, req = {}, where }) {
|
|
1
|
+
import { withSession } from './withSession.js';
|
|
2
|
+
export const deleteMany = async function deleteMany({ collection, req = {}, where }) {
|
|
13
3
|
const Model = this.collections[collection];
|
|
14
4
|
const options = {
|
|
15
|
-
...
|
|
5
|
+
...withSession(this, req.transactionID),
|
|
16
6
|
lean: true
|
|
17
7
|
};
|
|
18
8
|
const query = await Model.buildQuery({
|
|
@@ -22,4 +12,4 @@ const deleteMany = async function deleteMany({ collection, req = {}, where }) {
|
|
|
22
12
|
await Model.deleteMany(query, options);
|
|
23
13
|
};
|
|
24
14
|
|
|
25
|
-
//# sourceMappingURL=
|
|
15
|
+
//# sourceMappingURL=deleteMany.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/deleteMany.ts"],"sourcesContent":["import type { DeleteMany } from 'payload/database'\nimport type { PayloadRequest } from 'payload/types'\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 ...withSession(this, req.transactionID),\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","transactionID","lean","query","buildQuery","payload"],"rangeMappings":";;;;;;;;;;;;","mappings":"AAKA,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,GAAGP,YAAY,IAAI,EAAEG,IAAIK,aAAa,CAAC;QACvCC,MAAM;IACR;IAEA,MAAMC,QAAQ,MAAML,MAAMM,UAAU,CAAC;QACnCC,SAAS,IAAI,CAACA,OAAO;QACrBR;IACF;IAEA,MAAMC,MAAMJ,UAAU,CAACS,OAAOH;AAChC,EAAC"}
|
package/dist/deleteOne.js
CHANGED
|
@@ -1,23 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "deleteOne", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return deleteOne;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _sanitizeInternalFields = /*#__PURE__*/ _interop_require_default(require("./utilities/sanitizeInternalFields"));
|
|
12
|
-
const _withSession = require("./withSession");
|
|
13
|
-
function _interop_require_default(obj) {
|
|
14
|
-
return obj && obj.__esModule ? obj : {
|
|
15
|
-
default: obj
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
const deleteOne = async function deleteOne({ collection, req = {}, where }) {
|
|
1
|
+
import sanitizeInternalFields from './utilities/sanitizeInternalFields.js';
|
|
2
|
+
import { withSession } from './withSession.js';
|
|
3
|
+
export const deleteOne = async function deleteOne({ collection, req = {}, where }) {
|
|
19
4
|
const Model = this.collections[collection];
|
|
20
|
-
const options =
|
|
5
|
+
const options = withSession(this, req.transactionID);
|
|
21
6
|
const query = await Model.buildQuery({
|
|
22
7
|
payload: this.payload,
|
|
23
8
|
where
|
|
@@ -26,8 +11,8 @@ const deleteOne = async function deleteOne({ collection, req = {}, where }) {
|
|
|
26
11
|
let result = JSON.parse(JSON.stringify(doc));
|
|
27
12
|
// custom id type reset
|
|
28
13
|
result.id = result._id;
|
|
29
|
-
result = (
|
|
14
|
+
result = sanitizeInternalFields(result);
|
|
30
15
|
return result;
|
|
31
16
|
};
|
|
32
17
|
|
|
33
|
-
//# sourceMappingURL=
|
|
18
|
+
//# sourceMappingURL=deleteOne.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/deleteOne.ts"],"sourcesContent":["import type { DeleteOne } from 'payload/database'\nimport type { PayloadRequest } from 'payload/types'\nimport type { Document } from 'payload/types'\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 = withSession(this, req.transactionID)\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","transactionID","query","buildQuery","payload","doc","findOneAndDelete","lean","result","JSON","parse","stringify","id","_id"],"rangeMappings":";;;;;;;;;;;;;;;","mappings":"AAMA,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,UAAUP,YAAY,IAAI,EAAEG,IAAIK,aAAa;IAEnD,MAAMC,QAAQ,MAAMJ,MAAMK,UAAU,CAAC;QACnCC,SAAS,IAAI,CAACA,OAAO;QACrBP;IACF;IAEA,MAAMQ,MAAM,MAAMP,MAAMQ,gBAAgB,CAACJ,OAAOF,SAASO,IAAI;IAE7D,IAAIC,SAAmBC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACN;IAEjD,uBAAuB;IACvBG,OAAOI,EAAE,GAAGJ,OAAOK,GAAG;IACtBL,SAAShB,uBAAuBgB;IAEhC,OAAOA;AACT,EAAC"}
|
package/dist/deleteVersions.js
CHANGED
|
@@ -1,18 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "deleteVersions", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return deleteVersions;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _withSession = require("./withSession");
|
|
12
|
-
const deleteVersions = async function deleteVersions({ collection, locale, req = {}, where }) {
|
|
1
|
+
import { withSession } from './withSession.js';
|
|
2
|
+
export const deleteVersions = async function deleteVersions({ collection, locale, req = {}, where }) {
|
|
13
3
|
const VersionsModel = this.versions[collection];
|
|
14
4
|
const options = {
|
|
15
|
-
...
|
|
5
|
+
...withSession(this, req.transactionID),
|
|
16
6
|
lean: true
|
|
17
7
|
};
|
|
18
8
|
const query = await VersionsModel.buildQuery({
|
|
@@ -23,4 +13,4 @@ const deleteVersions = async function deleteVersions({ collection, locale, req =
|
|
|
23
13
|
await VersionsModel.deleteMany(query, options);
|
|
24
14
|
};
|
|
25
15
|
|
|
26
|
-
//# sourceMappingURL=
|
|
16
|
+
//# sourceMappingURL=deleteVersions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/deleteVersions.ts"],"sourcesContent":["import type { DeleteVersions } from 'payload/database'\nimport type { PayloadRequest } from 'payload/types'\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 ...withSession(this, req.transactionID),\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","transactionID","lean","query","buildQuery","payload","deleteMany"],"rangeMappings":";;;;;;;;;;;;;","mappings":"AAKA,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,GAAGR,YAAY,IAAI,EAAEI,IAAIK,aAAa,CAAC;QACvCC,MAAM;IACR;IAEA,MAAMC,QAAQ,MAAML,cAAcM,UAAU,CAAC;QAC3CT;QACAU,SAAS,IAAI,CAACA,OAAO;QACrBR;IACF;IAEA,MAAMC,cAAcQ,UAAU,CAACH,OAAOH;AACxC,EAAC"}
|
package/dist/destroy.js
CHANGED
|
@@ -1,27 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "destroy", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return destroy;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _mongoose = /*#__PURE__*/ _interop_require_default(require("mongoose"));
|
|
12
|
-
function _interop_require_default(obj) {
|
|
13
|
-
return obj && obj.__esModule ? obj : {
|
|
14
|
-
default: obj
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
const destroy = async function destroy() {
|
|
1
|
+
import mongoose from 'mongoose';
|
|
2
|
+
export const destroy = async function destroy() {
|
|
18
3
|
if (this.mongoMemoryServer) {
|
|
19
|
-
await _mongoose.default.connection.dropDatabase();
|
|
20
|
-
await _mongoose.default.connection.close();
|
|
21
4
|
await this.mongoMemoryServer.stop();
|
|
22
5
|
} else {
|
|
23
|
-
await
|
|
6
|
+
await mongoose.disconnect();
|
|
24
7
|
}
|
|
8
|
+
Object.keys(mongoose.models).map((model)=>mongoose.deleteModel(model));
|
|
25
9
|
};
|
|
26
10
|
|
|
27
|
-
//# sourceMappingURL=
|
|
11
|
+
//# sourceMappingURL=destroy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/destroy.ts"],"sourcesContent":["import type { Destroy } from 'payload/database'\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"],"rangeMappings":";;;;;;;;","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"}
|