@payloadcms/db-mongodb 3.0.0-alpha.6 → 3.0.0-alpha.61
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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateGlobalVersion.d.ts","sourceRoot":"","sources":["../src/updateGlobalVersion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAA;AAC/D,OAAO,KAAK,EAAkB,UAAU,EAAE,MAAM,eAAe,CAAA;AAE/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"updateGlobalVersion.d.ts","sourceRoot":"","sources":["../src/updateGlobalVersion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAA;AAC/D,OAAO,KAAK,EAAkB,UAAU,EAAE,MAAM,eAAe,CAAA;AAE/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAIjD,wBAAsB,mBAAmB,CAAC,CAAC,SAAS,UAAU,EAC5D,IAAI,EAAE,eAAe,EACrB,EACE,EAAE,EACF,MAAM,EACN,MAAM,EACN,GAA0B,EAC1B,WAAW,EACX,KAAK,GACN,EAAE,uBAAuB,CAAC,CAAC,CAAC,gBA4B9B"}
|
|
@@ -1,15 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "updateGlobalVersion", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return updateGlobalVersion;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _withSession = require("./withSession");
|
|
12
|
-
async function updateGlobalVersion({ id, global, locale, req = {}, versionData, where }) {
|
|
1
|
+
import { withSession } from './withSession.js';
|
|
2
|
+
export async function updateGlobalVersion({ id, global, locale, req = {}, versionData, where }) {
|
|
13
3
|
const VersionModel = this.versions[global];
|
|
14
4
|
const whereToUse = where || {
|
|
15
5
|
id: {
|
|
@@ -17,7 +7,7 @@ async function updateGlobalVersion({ id, global, locale, req = {}, versionData,
|
|
|
17
7
|
}
|
|
18
8
|
};
|
|
19
9
|
const options = {
|
|
20
|
-
...
|
|
10
|
+
...withSession(this, req.transactionID),
|
|
21
11
|
lean: true,
|
|
22
12
|
new: true
|
|
23
13
|
};
|
|
@@ -37,4 +27,4 @@ async function updateGlobalVersion({ id, global, locale, req = {}, versionData,
|
|
|
37
27
|
return result;
|
|
38
28
|
}
|
|
39
29
|
|
|
40
|
-
//# sourceMappingURL=
|
|
30
|
+
//# sourceMappingURL=updateGlobalVersion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/updateGlobalVersion.ts"],"sourcesContent":["import type { UpdateGlobalVersionArgs } from 'payload/database'\nimport type { PayloadRequest, TypeWithID } from 'payload/types'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { withSession } from './withSession.js'\n\nexport async function updateGlobalVersion<T extends TypeWithID>(\n this: MongooseAdapter,\n {\n id,\n global,\n locale,\n req = {} as PayloadRequest,\n versionData,\n where,\n }: UpdateGlobalVersionArgs<T>,\n) {\n const VersionModel = this.versions[global]\n const whereToUse = where || { id: { equals: id } }\n const options = {\n ...withSession(this, req.transactionID),\n lean: true,\n new: true,\n }\n\n const query = await VersionModel.buildQuery({\n locale,\n payload: this.payload,\n where: whereToUse,\n })\n\n const doc = await VersionModel.findOneAndUpdate(query, versionData, options)\n\n const result = JSON.parse(JSON.stringify(doc))\n\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","updateGlobalVersion","id","global","locale","req","versionData","where","VersionModel","versions","whereToUse","equals","options","transactionID","lean","new","query","buildQuery","payload","doc","findOneAndUpdate","result","JSON","parse","stringify","verificationToken","_verificationToken","_id"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAKA,SAASA,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,eAAeC,oBAEpB,EACEC,EAAE,EACFC,MAAM,EACNC,MAAM,EACNC,MAAM,CAAC,CAAmB,EAC1BC,WAAW,EACXC,KAAK,EACsB;IAE7B,MAAMC,eAAe,IAAI,CAACC,QAAQ,CAACN,OAAO;IAC1C,MAAMO,aAAaH,SAAS;QAAEL,IAAI;YAAES,QAAQT;QAAG;IAAE;IACjD,MAAMU,UAAU;QACd,GAAGZ,YAAY,IAAI,EAAEK,IAAIQ,aAAa,CAAC;QACvCC,MAAM;QACNC,KAAK;IACP;IAEA,MAAMC,QAAQ,MAAMR,aAAaS,UAAU,CAAC;QAC1Cb;QACAc,SAAS,IAAI,CAACA,OAAO;QACrBX,OAAOG;IACT;IAEA,MAAMS,MAAM,MAAMX,aAAaY,gBAAgB,CAACJ,OAAOV,aAAaM;IAEpE,MAAMS,SAASC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL;IAEzC,MAAMM,oBAAoBN,IAAIO,kBAAkB;IAEhD,uBAAuB;IACvBL,OAAOnB,EAAE,GAAGmB,OAAOM,GAAG;IACtB,IAAIF,mBAAmB;QACrBJ,OAAOK,kBAAkB,GAAGD;IAC9B;IACA,OAAOJ;AACT"}
|
package/dist/updateOne.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateOne.d.ts","sourceRoot":"","sources":["../src/updateOne.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AASjD,eAAO,MAAM,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"updateOne.d.ts","sourceRoot":"","sources":["../src/updateOne.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AASjD,eAAO,MAAM,SAAS,EAAE,SA+BvB,CAAA"}
|
package/dist/updateOne.js
CHANGED
|
@@ -1,22 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
})
|
|
5
|
-
Object.defineProperty(exports, "updateOne", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return updateOne;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _handleError = /*#__PURE__*/ _interop_require_default(require("./utilities/handleError"));
|
|
12
|
-
const _sanitizeInternalFields = /*#__PURE__*/ _interop_require_default(require("./utilities/sanitizeInternalFields"));
|
|
13
|
-
const _withSession = require("./withSession");
|
|
14
|
-
function _interop_require_default(obj) {
|
|
15
|
-
return obj && obj.__esModule ? obj : {
|
|
16
|
-
default: obj
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
const updateOne = async function updateOne({ id, collection, data, locale, req = {}, where: whereArg }) {
|
|
1
|
+
import handleError from './utilities/handleError.js';
|
|
2
|
+
import sanitizeInternalFields from './utilities/sanitizeInternalFields.js';
|
|
3
|
+
import { withSession } from './withSession.js';
|
|
4
|
+
export const updateOne = async function updateOne({ id, collection, data, locale, req = {}, where: whereArg }) {
|
|
20
5
|
const where = id ? {
|
|
21
6
|
id: {
|
|
22
7
|
equals: id
|
|
@@ -24,7 +9,7 @@ const updateOne = async function updateOne({ id, collection, data, locale, req =
|
|
|
24
9
|
} : whereArg;
|
|
25
10
|
const Model = this.collections[collection];
|
|
26
11
|
const options = {
|
|
27
|
-
...
|
|
12
|
+
...withSession(this, req.transactionID),
|
|
28
13
|
lean: true,
|
|
29
14
|
new: true
|
|
30
15
|
};
|
|
@@ -37,12 +22,12 @@ const updateOne = async function updateOne({ id, collection, data, locale, req =
|
|
|
37
22
|
try {
|
|
38
23
|
result = await Model.findOneAndUpdate(query, data, options);
|
|
39
24
|
} catch (error) {
|
|
40
|
-
(
|
|
25
|
+
handleError(error, req);
|
|
41
26
|
}
|
|
42
27
|
result = JSON.parse(JSON.stringify(result));
|
|
43
28
|
result.id = result._id;
|
|
44
|
-
result = (
|
|
29
|
+
result = sanitizeInternalFields(result);
|
|
45
30
|
return result;
|
|
46
31
|
};
|
|
47
32
|
|
|
48
|
-
//# sourceMappingURL=
|
|
33
|
+
//# sourceMappingURL=updateOne.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/updateOne.ts"],"sourcesContent":["import type { UpdateOne } from 'payload/database'\nimport type { PayloadRequest } from 'payload/types'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport handleError from './utilities/handleError.js'\nimport sanitizeInternalFields from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const updateOne: UpdateOne = async function updateOne(\n this: MongooseAdapter,\n { id, collection, data, locale, req = {} as PayloadRequest, where: whereArg },\n) {\n const where = id ? { id: { equals: id } } : whereArg\n const Model = this.collections[collection]\n const options = {\n ...withSession(this, req.transactionID),\n lean: true,\n new: true,\n }\n\n const query = await Model.buildQuery({\n locale,\n payload: this.payload,\n where,\n })\n\n let result\n\n try {\n result = await Model.findOneAndUpdate(query, data, options)\n } catch (error) {\n handleError(error, req)\n }\n\n result = JSON.parse(JSON.stringify(result))\n result.id = result._id\n result = sanitizeInternalFields(result)\n\n return result\n}\n"],"names":["handleError","sanitizeInternalFields","withSession","updateOne","id","collection","data","locale","req","where","whereArg","equals","Model","collections","options","transactionID","lean","new","query","buildQuery","payload","result","findOneAndUpdate","error","JSON","parse","stringify","_id"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAKA,OAAOA,iBAAiB,6BAA4B;AACpD,OAAOC,4BAA4B,wCAAuC;AAC1E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,YAAuB,eAAeA,UAEjD,EAAEC,EAAE,EAAEC,UAAU,EAAEC,IAAI,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAAmB,EAAEC,OAAOC,QAAQ,EAAE;IAE7E,MAAMD,QAAQL,KAAK;QAAEA,IAAI;YAAEO,QAAQP;QAAG;IAAE,IAAIM;IAC5C,MAAME,QAAQ,IAAI,CAACC,WAAW,CAACR,WAAW;IAC1C,MAAMS,UAAU;QACd,GAAGZ,YAAY,IAAI,EAAEM,IAAIO,aAAa,CAAC;QACvCC,MAAM;QACNC,KAAK;IACP;IAEA,MAAMC,QAAQ,MAAMN,MAAMO,UAAU,CAAC;QACnCZ;QACAa,SAAS,IAAI,CAACA,OAAO;QACrBX;IACF;IAEA,IAAIY;IAEJ,IAAI;QACFA,SAAS,MAAMT,MAAMU,gBAAgB,CAACJ,OAAOZ,MAAMQ;IACrD,EAAE,OAAOS,OAAO;QACdvB,YAAYuB,OAAOf;IACrB;IAEAa,SAASG,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL;IACnCA,OAAOjB,EAAE,GAAGiB,OAAOM,GAAG;IACtBN,SAASpB,uBAAuBoB;IAEhC,OAAOA;AACT,EAAC"}
|
package/dist/updateVersion.js
CHANGED
|
@@ -1,15 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "updateVersion", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return updateVersion;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _withSession = require("./withSession");
|
|
12
|
-
const updateVersion = async function updateVersion({ id, collection, locale, req = {}, versionData, where }) {
|
|
1
|
+
import { withSession } from './withSession.js';
|
|
2
|
+
export const updateVersion = async function updateVersion({ id, collection, locale, req = {}, versionData, where }) {
|
|
13
3
|
const VersionModel = this.versions[collection];
|
|
14
4
|
const whereToUse = where || {
|
|
15
5
|
id: {
|
|
@@ -17,7 +7,7 @@ const updateVersion = async function updateVersion({ id, collection, locale, req
|
|
|
17
7
|
}
|
|
18
8
|
};
|
|
19
9
|
const options = {
|
|
20
|
-
...
|
|
10
|
+
...withSession(this, req.transactionID),
|
|
21
11
|
lean: true,
|
|
22
12
|
new: true
|
|
23
13
|
};
|
|
@@ -37,4 +27,4 @@ const updateVersion = async function updateVersion({ id, collection, locale, req
|
|
|
37
27
|
return result;
|
|
38
28
|
};
|
|
39
29
|
|
|
40
|
-
//# sourceMappingURL=
|
|
30
|
+
//# sourceMappingURL=updateVersion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/updateVersion.ts"],"sourcesContent":["import type { UpdateVersion } 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 updateVersion: UpdateVersion = async function updateVersion(\n this: MongooseAdapter,\n { id, collection, locale, req = {} as PayloadRequest, versionData, where },\n) {\n const VersionModel = this.versions[collection]\n const whereToUse = where || { id: { equals: id } }\n const options = {\n ...withSession(this, req.transactionID),\n lean: true,\n new: true,\n }\n\n const query = await VersionModel.buildQuery({\n locale,\n payload: this.payload,\n where: whereToUse,\n })\n\n const doc = await VersionModel.findOneAndUpdate(query, versionData, options)\n\n const result = JSON.parse(JSON.stringify(doc))\n\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","updateVersion","id","collection","locale","req","versionData","where","VersionModel","versions","whereToUse","equals","options","transactionID","lean","new","query","buildQuery","payload","doc","findOneAndUpdate","result","JSON","parse","stringify","verificationToken","_verificationToken","_id"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAKA,SAASA,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,gBAA+B,eAAeA,cAEzD,EAAEC,EAAE,EAAEC,UAAU,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAAmB,EAAEC,WAAW,EAAEC,KAAK,EAAE;IAE1E,MAAMC,eAAe,IAAI,CAACC,QAAQ,CAACN,WAAW;IAC9C,MAAMO,aAAaH,SAAS;QAAEL,IAAI;YAAES,QAAQT;QAAG;IAAE;IACjD,MAAMU,UAAU;QACd,GAAGZ,YAAY,IAAI,EAAEK,IAAIQ,aAAa,CAAC;QACvCC,MAAM;QACNC,KAAK;IACP;IAEA,MAAMC,QAAQ,MAAMR,aAAaS,UAAU,CAAC;QAC1Cb;QACAc,SAAS,IAAI,CAACA,OAAO;QACrBX,OAAOG;IACT;IAEA,MAAMS,MAAM,MAAMX,aAAaY,gBAAgB,CAACJ,OAAOV,aAAaM;IAEpE,MAAMS,SAASC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL;IAEzC,MAAMM,oBAAoBN,IAAIO,kBAAkB;IAEhD,uBAAuB;IACvBL,OAAOnB,EAAE,GAAGmB,OAAOM,GAAG;IACtB,IAAIF,mBAAmB;QACrBJ,OAAOK,kBAAkB,GAAGD;IAC9B;IACA,OAAOJ;AACT,EAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { DBIdentifierName } from 'payload/database';
|
|
2
|
+
type Args = {
|
|
3
|
+
config: {
|
|
4
|
+
dbName?: DBIdentifierName;
|
|
5
|
+
enumName?: DBIdentifierName;
|
|
6
|
+
name?: string;
|
|
7
|
+
slug?: string;
|
|
8
|
+
};
|
|
9
|
+
locales?: boolean;
|
|
10
|
+
target?: 'dbName' | 'enumName';
|
|
11
|
+
versions?: boolean;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Used to name database enums and collections
|
|
15
|
+
* Returns the collection or enum name for a given entity
|
|
16
|
+
*/
|
|
17
|
+
export declare const getDBName: ({ config: { name, slug }, config, target, versions, }: Args) => string;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=getDBName.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getDBName.d.ts","sourceRoot":"","sources":["../../src/utilities/getDBName.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAExD,KAAK,IAAI,GAAG;IACV,MAAM,EAAE;QACN,MAAM,CAAC,EAAE,gBAAgB,CAAA;QACzB,QAAQ,CAAC,EAAE,gBAAgB,CAAA;QAC3B,IAAI,CAAC,EAAE,MAAM,CAAA;QACb,IAAI,CAAC,EAAE,MAAM,CAAA;KACd,CAAA;IACD,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,MAAM,CAAC,EAAE,QAAQ,GAAG,UAAU,CAAA;IAC9B,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,SAAS,0DAKnB,IAAI,KAAG,MAiBT,CAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Used to name database enums and collections
|
|
3
|
+
* Returns the collection or enum name for a given entity
|
|
4
|
+
*/ export const getDBName = ({ config: { name, slug }, config, target = 'dbName', versions = false })=>{
|
|
5
|
+
let result;
|
|
6
|
+
let custom = config[target];
|
|
7
|
+
if (!custom && target === 'enumName') {
|
|
8
|
+
custom = config['dbName'];
|
|
9
|
+
}
|
|
10
|
+
if (custom) {
|
|
11
|
+
result = typeof custom === 'function' ? custom({}) : custom;
|
|
12
|
+
} else {
|
|
13
|
+
result = name ?? slug;
|
|
14
|
+
}
|
|
15
|
+
if (versions) result = `_${result}_versions`;
|
|
16
|
+
return result;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=getDBName.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/getDBName.ts"],"sourcesContent":["import type { DBIdentifierName } from 'payload/database'\n\ntype Args = {\n config: {\n dbName?: DBIdentifierName\n enumName?: DBIdentifierName\n name?: string\n slug?: string\n }\n locales?: boolean\n target?: 'dbName' | 'enumName'\n versions?: boolean\n}\n\n/**\n * Used to name database enums and collections\n * Returns the collection or enum name for a given entity\n */\nexport const getDBName = ({\n config: { name, slug },\n config,\n target = 'dbName',\n versions = false,\n}: Args): string => {\n let result: string\n let custom = config[target]\n\n if (!custom && target === 'enumName') {\n custom = config['dbName']\n }\n\n if (custom) {\n result = typeof custom === 'function' ? custom({}) : custom\n } else {\n result = name ?? slug\n }\n\n if (versions) result = `_${result}_versions`\n\n return result\n}\n"],"names":["getDBName","config","name","slug","target","versions","result","custom"],"rangeMappings":";;;;;;;;;;;;;;;;","mappings":"AAcA;;;CAGC,GACD,OAAO,MAAMA,YAAY,CAAC,EACxBC,QAAQ,EAAEC,IAAI,EAAEC,IAAI,EAAE,EACtBF,MAAM,EACNG,SAAS,QAAQ,EACjBC,WAAW,KAAK,EACX;IACL,IAAIC;IACJ,IAAIC,SAASN,MAAM,CAACG,OAAO;IAE3B,IAAI,CAACG,UAAUH,WAAW,YAAY;QACpCG,SAASN,MAAM,CAAC,SAAS;IAC3B;IAEA,IAAIM,QAAQ;QACVD,SAAS,OAAOC,WAAW,aAAaA,OAAO,CAAC,KAAKA;IACvD,OAAO;QACLD,SAASJ,QAAQC;IACnB;IAEA,IAAIE,UAAUC,SAAS,CAAC,CAAC,EAAEA,OAAO,SAAS,CAAC;IAE5C,OAAOA;AACT,EAAC"}
|
|
@@ -1,35 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "default", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return _default;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _httpstatus = /*#__PURE__*/ _interop_require_default(require("http-status"));
|
|
12
|
-
const _errors = require("payload/errors");
|
|
13
|
-
function _interop_require_default(obj) {
|
|
14
|
-
return obj && obj.__esModule ? obj : {
|
|
15
|
-
default: obj
|
|
16
|
-
};
|
|
17
|
-
}
|
|
1
|
+
import httpStatus from 'http-status';
|
|
2
|
+
import { APIError, ValidationError } from 'payload/errors';
|
|
18
3
|
const handleError = (error, req)=>{
|
|
19
4
|
// Handle uniqueness error from MongoDB
|
|
20
5
|
if (error.code === 11000 && error.keyValue) {
|
|
21
|
-
throw new
|
|
6
|
+
throw new ValidationError([
|
|
22
7
|
{
|
|
23
8
|
field: Object.keys(error.keyValue)[0],
|
|
24
9
|
message: req.t('error:valueMustBeUnique')
|
|
25
10
|
}
|
|
26
11
|
], req.t);
|
|
27
12
|
} else if (error.code === 11000) {
|
|
28
|
-
throw new
|
|
13
|
+
throw new APIError(req.t('error:valueMustBeUnique'), httpStatus.BAD_REQUEST);
|
|
29
14
|
} else {
|
|
30
15
|
throw error;
|
|
31
16
|
}
|
|
32
17
|
};
|
|
33
|
-
|
|
18
|
+
export default handleError;
|
|
34
19
|
|
|
35
|
-
//# sourceMappingURL=
|
|
20
|
+
//# sourceMappingURL=handleError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/handleError.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { APIError, ValidationError } from 'payload/errors'\n\nconst handleError = (error, req) => {\n // Handle uniqueness error from MongoDB\n if (error.code === 11000 && error.keyValue) {\n throw new ValidationError(\n [\n {\n field: Object.keys(error.keyValue)[0],\n message: req.t('error:valueMustBeUnique'),\n },\n ],\n req.t,\n )\n } else if (error.code === 11000) {\n throw new APIError(req.t('error:valueMustBeUnique'), httpStatus.BAD_REQUEST)\n } else {\n throw error\n }\n}\n\nexport default handleError\n"],"names":["httpStatus","APIError","ValidationError","handleError","error","req","code","keyValue","field","Object","keys","message","t","BAD_REQUEST"],"rangeMappings":";;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,gBAAgB,cAAa;AACpC,SAASC,QAAQ,EAAEC,eAAe,QAAQ,iBAAgB;AAE1D,MAAMC,cAAc,CAACC,OAAOC;IAC1B,uCAAuC;IACvC,IAAID,MAAME,IAAI,KAAK,SAASF,MAAMG,QAAQ,EAAE;QAC1C,MAAM,IAAIL,gBACR;YACE;gBACEM,OAAOC,OAAOC,IAAI,CAACN,MAAMG,QAAQ,CAAC,CAAC,EAAE;gBACrCI,SAASN,IAAIO,CAAC,CAAC;YACjB;SACD,EACDP,IAAIO,CAAC;IAET,OAAO,IAAIR,MAAME,IAAI,KAAK,OAAO;QAC/B,MAAM,IAAIL,SAASI,IAAIO,CAAC,CAAC,4BAA4BZ,WAAWa,WAAW;IAC7E,OAAO;QACL,MAAMT;IACR;AACF;AAEA,eAAeD,YAAW"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sanitizeInternalFields.d.ts","sourceRoot":"","sources":["../../src/utilities/sanitizeInternalFields.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,sBAAsB,
|
|
1
|
+
{"version":3,"file":"sanitizeInternalFields.d.ts","sourceRoot":"","sources":["../../src/utilities/sanitizeInternalFields.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,sBAAsB,mDAAoD,CAAC,KAAG,CAiBvE,CAAA;AAEb,eAAe,sBAAsB,CAAA"}
|
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "default", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return _default;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
1
|
const internalFields = [
|
|
12
2
|
'__v'
|
|
13
3
|
];
|
|
@@ -26,6 +16,6 @@ const sanitizeInternalFields = (incomingDoc)=>Object.entries(incomingDoc).reduce
|
|
|
26
16
|
[key]: val
|
|
27
17
|
};
|
|
28
18
|
}, {});
|
|
29
|
-
|
|
19
|
+
export default sanitizeInternalFields;
|
|
30
20
|
|
|
31
|
-
//# sourceMappingURL=
|
|
21
|
+
//# sourceMappingURL=sanitizeInternalFields.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/sanitizeInternalFields.ts"],"sourcesContent":["const internalFields = ['__v']\n\nconst sanitizeInternalFields = <T extends Record<string, unknown>>(incomingDoc: T): T =>\n Object.entries(incomingDoc).reduce((newDoc, [key, val]): T => {\n if (key === '_id') {\n return {\n ...newDoc,\n id: val,\n }\n }\n\n if (internalFields.indexOf(key) > -1) {\n return newDoc\n }\n\n return {\n ...newDoc,\n [key]: val,\n }\n }, {} as T)\n\nexport default sanitizeInternalFields\n"],"names":["internalFields","sanitizeInternalFields","incomingDoc","Object","entries","reduce","newDoc","key","val","id","indexOf"],"rangeMappings":";;;;;;;;;;;;;;;;;;","mappings":"AAAA,MAAMA,iBAAiB;IAAC;CAAM;AAE9B,MAAMC,yBAAyB,CAAoCC,cACjEC,OAAOC,OAAO,CAACF,aAAaG,MAAM,CAAC,CAACC,QAAQ,CAACC,KAAKC,IAAI;QACpD,IAAID,QAAQ,OAAO;YACjB,OAAO;gBACL,GAAGD,MAAM;gBACTG,IAAID;YACN;QACF;QAEA,IAAIR,eAAeU,OAAO,CAACH,OAAO,CAAC,GAAG;YACpC,OAAOD;QACT;QAEA,OAAO;YACL,GAAGA,MAAM;YACT,CAACC,IAAI,EAAEC;QACT;IACF,GAAG,CAAC;AAEN,eAAeP,uBAAsB"}
|
package/dist/withSession.d.ts
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
|
+
/// <reference types="mongoose/types/aggregate.js" />
|
|
2
|
+
/// <reference types="mongoose/types/callback.js" />
|
|
3
|
+
/// <reference types="mongoose/types/collection.js" />
|
|
4
|
+
/// <reference types="mongoose/types/connection.js" />
|
|
5
|
+
/// <reference types="mongoose/types/cursor.js" />
|
|
6
|
+
/// <reference types="mongoose/types/document.js" />
|
|
7
|
+
/// <reference types="mongoose/types/error.js" />
|
|
8
|
+
/// <reference types="mongoose/types/expressions.js" />
|
|
9
|
+
/// <reference types="mongoose/types/helpers.js" />
|
|
10
|
+
/// <reference types="mongoose/types/middlewares.js" />
|
|
11
|
+
/// <reference types="mongoose/types/indexes.js" />
|
|
12
|
+
/// <reference types="mongoose/types/models.js" />
|
|
13
|
+
/// <reference types="mongoose/types/mongooseoptions.js" />
|
|
14
|
+
/// <reference types="mongoose/types/pipelinestage.js" />
|
|
15
|
+
/// <reference types="mongoose/types/populate.js" />
|
|
16
|
+
/// <reference types="mongoose/types/query.js" />
|
|
17
|
+
/// <reference types="mongoose/types/schemaoptions.js" />
|
|
18
|
+
/// <reference types="mongoose/types/schematypes.js" />
|
|
19
|
+
/// <reference types="mongoose/types/session.js" />
|
|
20
|
+
/// <reference types="mongoose/types/types.js" />
|
|
21
|
+
/// <reference types="mongoose/types/utility.js" />
|
|
22
|
+
/// <reference types="mongoose/types/validation.js" />
|
|
23
|
+
/// <reference types="mongoose/types/virtuals.js" />
|
|
24
|
+
/// <reference types="mongoose/types/inferschematype.js" />
|
|
25
|
+
/// <reference types="mongoose-paginate-v2" />
|
|
1
26
|
import type { ClientSession } from 'mongoose';
|
|
2
|
-
import type { MongooseAdapter } from './index';
|
|
27
|
+
import type { MongooseAdapter } from './index.js';
|
|
3
28
|
/**
|
|
4
29
|
* returns the session belonging to the transaction of the req.session if exists
|
|
5
30
|
* @returns ClientSession
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withSession.d.ts","sourceRoot":"","sources":["../src/withSession.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAE7C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"withSession.d.ts","sourceRoot":"","sources":["../src/withSession.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAE7C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAEjD;;;GAGG;AACH,wBAAgB,WAAW,CACzB,EAAE,EAAE,eAAe,EACnB,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,GAC9B;IAAE,OAAO,EAAE,aAAa,CAAA;CAAE,GAAG,MAAM,CAErC"}
|
package/dist/withSession.js
CHANGED
|
@@ -1,17 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "withSession", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return withSession;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
function withSession(db, transactionID) {
|
|
1
|
+
/**
|
|
2
|
+
* returns the session belonging to the transaction of the req.session if exists
|
|
3
|
+
* @returns ClientSession
|
|
4
|
+
*/ export function withSession(db, transactionID) {
|
|
12
5
|
return db.sessions[transactionID] ? {
|
|
13
6
|
session: db.sessions[transactionID]
|
|
14
7
|
} : {};
|
|
15
8
|
}
|
|
16
9
|
|
|
17
|
-
//# sourceMappingURL=
|
|
10
|
+
//# sourceMappingURL=withSession.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/withSession.ts"],"sourcesContent":["import type { ClientSession } from 'mongoose'\n\nimport type { MongooseAdapter } from './index.js'\n\n/**\n * returns the session belonging to the transaction of the req.session if exists\n * @returns ClientSession\n */\nexport function withSession(\n db: MongooseAdapter,\n transactionID?: number | string,\n): { session: ClientSession } | object {\n return db.sessions[transactionID] ? { session: db.sessions[transactionID] } : {}\n}\n"],"names":["withSession","db","transactionID","sessions","session"],"rangeMappings":";;;;;;;","mappings":"AAIA;;;CAGC,GACD,OAAO,SAASA,YACdC,EAAmB,EACnBC,aAA+B;IAE/B,OAAOD,GAAGE,QAAQ,CAACD,cAAc,GAAG;QAAEE,SAASH,GAAGE,QAAQ,CAACD,cAAc;IAAC,IAAI,CAAC;AACjF"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/db-mongodb",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
4
|
-
"description": "The officially supported MongoDB database adapter for Payload
|
|
5
|
-
"repository":
|
|
3
|
+
"version": "3.0.0-alpha.61",
|
|
4
|
+
"description": "The officially supported MongoDB database adapter for Payload",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/payloadcms/payload.git",
|
|
8
|
+
"directory": "packages/db-mongodb"
|
|
9
|
+
},
|
|
6
10
|
"license": "MIT",
|
|
7
11
|
"homepage": "https://payloadcms.com",
|
|
12
|
+
"type": "module",
|
|
8
13
|
"author": {
|
|
9
14
|
"email": "info@payloadcms.com",
|
|
10
15
|
"name": "Payload",
|
|
@@ -18,7 +23,6 @@
|
|
|
18
23
|
"get-port": "5.1.1",
|
|
19
24
|
"http-status": "1.6.2",
|
|
20
25
|
"mongoose": "6.12.3",
|
|
21
|
-
"mongoose-aggregate-paginate-v2": "1.0.6",
|
|
22
26
|
"mongoose-paginate-v2": "1.7.22",
|
|
23
27
|
"prompts": "2.4.2",
|
|
24
28
|
"uuid": "9.0.0"
|
|
@@ -27,14 +31,18 @@
|
|
|
27
31
|
"@types/mongoose-aggregate-paginate-v2": "1.0.9",
|
|
28
32
|
"mongodb": "4.17.1",
|
|
29
33
|
"mongodb-memory-server": "^9",
|
|
30
|
-
"
|
|
31
|
-
"
|
|
34
|
+
"payload": "3.0.0-alpha.61",
|
|
35
|
+
"@payloadcms/eslint-config": "1.1.1"
|
|
32
36
|
},
|
|
33
37
|
"peerDependencies": {
|
|
34
|
-
"payload": "
|
|
38
|
+
"payload": "3.0.0-alpha.61"
|
|
35
39
|
},
|
|
36
|
-
"
|
|
37
|
-
"
|
|
40
|
+
"exports": {
|
|
41
|
+
".": {
|
|
42
|
+
"import": "./dist/index.js",
|
|
43
|
+
"require": "./dist/index.js",
|
|
44
|
+
"types": "./dist/index.d.ts"
|
|
45
|
+
}
|
|
38
46
|
},
|
|
39
47
|
"files": [
|
|
40
48
|
"dist",
|
|
@@ -43,7 +51,7 @@
|
|
|
43
51
|
],
|
|
44
52
|
"scripts": {
|
|
45
53
|
"build": "pnpm build:swc && pnpm build:types",
|
|
46
|
-
"build:swc": "swc ./src -d ./dist --config-file .swcrc",
|
|
54
|
+
"build:swc": "swc ./src -d ./dist --config-file .swcrc-build",
|
|
47
55
|
"build:types": "tsc --emitDeclarationOnly --outDir dist",
|
|
48
56
|
"clean": "rimraf {dist,*.tsbuildinfo}"
|
|
49
57
|
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import type { TransactionOptions } from 'mongodb'
|
|
2
|
+
import type { MongoMemoryReplSet } from 'mongodb-memory-server'
|
|
3
|
+
import type { ClientSession, ConnectOptions, Connection } from 'mongoose'
|
|
4
|
+
import type { Payload } from 'payload'
|
|
5
|
+
import type { BaseDatabaseAdapter, DatabaseAdapterObj } from 'payload/database'
|
|
6
|
+
|
|
7
|
+
import fs from 'fs'
|
|
8
|
+
import mongoose from 'mongoose'
|
|
9
|
+
import path from 'path'
|
|
10
|
+
import { createDatabaseAdapter } from 'payload/database'
|
|
11
|
+
|
|
12
|
+
import type { CollectionModel, GlobalModel } from './types.js'
|
|
13
|
+
|
|
14
|
+
import { connect } from './connect.js'
|
|
15
|
+
import { create } from './create.js'
|
|
16
|
+
import { createGlobal } from './createGlobal.js'
|
|
17
|
+
import { createGlobalVersion } from './createGlobalVersion.js'
|
|
18
|
+
import { createMigration } from './createMigration.js'
|
|
19
|
+
import { createVersion } from './createVersion.js'
|
|
20
|
+
import { deleteMany } from './deleteMany.js'
|
|
21
|
+
import { deleteOne } from './deleteOne.js'
|
|
22
|
+
import { deleteVersions } from './deleteVersions.js'
|
|
23
|
+
import { destroy } from './destroy.js'
|
|
24
|
+
import { find } from './find.js'
|
|
25
|
+
import { findGlobal } from './findGlobal.js'
|
|
26
|
+
import { findGlobalVersions } from './findGlobalVersions.js'
|
|
27
|
+
import { findOne } from './findOne.js'
|
|
28
|
+
import { findVersions } from './findVersions.js'
|
|
29
|
+
import { init } from './init.js'
|
|
30
|
+
import { migrateFresh } from './migrateFresh.js'
|
|
31
|
+
import { queryDrafts } from './queryDrafts.js'
|
|
32
|
+
import { beginTransaction } from './transactions/beginTransaction.js'
|
|
33
|
+
import { commitTransaction } from './transactions/commitTransaction.js'
|
|
34
|
+
import { rollbackTransaction } from './transactions/rollbackTransaction.js'
|
|
35
|
+
import { updateGlobal } from './updateGlobal.js'
|
|
36
|
+
import { updateGlobalVersion } from './updateGlobalVersion.js'
|
|
37
|
+
import { updateOne } from './updateOne.js'
|
|
38
|
+
import { updateVersion } from './updateVersion.js'
|
|
39
|
+
|
|
40
|
+
export type { MigrateDownArgs, MigrateUpArgs } from './types.js'
|
|
41
|
+
|
|
42
|
+
export interface Args {
|
|
43
|
+
/** Set to false to disable auto-pluralization of collection names, Defaults to true */
|
|
44
|
+
autoPluralization?: boolean
|
|
45
|
+
/** Extra configuration options */
|
|
46
|
+
connectOptions?: ConnectOptions & {
|
|
47
|
+
/** Set false to disable $facet aggregation in non-supporting databases, Defaults to true */
|
|
48
|
+
useFacet?: boolean
|
|
49
|
+
}
|
|
50
|
+
/** Set to true to disable hinting to MongoDB to use 'id' as index. This is currently done when counting documents for pagination. Disabling this optimization might fix some problems with AWS DocumentDB. Defaults to false */
|
|
51
|
+
disableIndexHints?: boolean
|
|
52
|
+
migrationDir?: string
|
|
53
|
+
/**
|
|
54
|
+
* typed as any to avoid dependency
|
|
55
|
+
*/
|
|
56
|
+
mongoMemoryServer?: MongoMemoryReplSet
|
|
57
|
+
transactionOptions?: TransactionOptions | false
|
|
58
|
+
/** The URL to connect to MongoDB or false to start payload and prevent connecting */
|
|
59
|
+
url: false | string
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export type MongooseAdapter = BaseDatabaseAdapter &
|
|
63
|
+
Args & {
|
|
64
|
+
collections: {
|
|
65
|
+
[slug: string]: CollectionModel
|
|
66
|
+
}
|
|
67
|
+
connection: Connection
|
|
68
|
+
globals: GlobalModel
|
|
69
|
+
mongoMemoryServer: MongoMemoryReplSet
|
|
70
|
+
sessions: Record<number | string, ClientSession>
|
|
71
|
+
versions: {
|
|
72
|
+
[slug: string]: CollectionModel
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
declare module 'payload' {
|
|
77
|
+
export interface DatabaseAdapter
|
|
78
|
+
extends Omit<BaseDatabaseAdapter, 'sessions'>,
|
|
79
|
+
Omit<Args, 'migrationDir'> {
|
|
80
|
+
collections: {
|
|
81
|
+
[slug: string]: CollectionModel
|
|
82
|
+
}
|
|
83
|
+
connection: Connection
|
|
84
|
+
globals: GlobalModel
|
|
85
|
+
mongoMemoryServer: MongoMemoryReplSet
|
|
86
|
+
sessions: Record<number | string, ClientSession>
|
|
87
|
+
transactionOptions: TransactionOptions
|
|
88
|
+
versions: {
|
|
89
|
+
[slug: string]: CollectionModel
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function mongooseAdapter({
|
|
95
|
+
autoPluralization = true,
|
|
96
|
+
connectOptions,
|
|
97
|
+
disableIndexHints = false,
|
|
98
|
+
migrationDir: migrationDirArg,
|
|
99
|
+
mongoMemoryServer,
|
|
100
|
+
transactionOptions = {},
|
|
101
|
+
url,
|
|
102
|
+
}: Args): DatabaseAdapterObj {
|
|
103
|
+
function adapter({ payload }: { payload: Payload }) {
|
|
104
|
+
const migrationDir = findMigrationDir(migrationDirArg)
|
|
105
|
+
mongoose.set('strictQuery', false)
|
|
106
|
+
|
|
107
|
+
return createDatabaseAdapter<MongooseAdapter>({
|
|
108
|
+
name: 'mongoose',
|
|
109
|
+
|
|
110
|
+
// Mongoose-specific
|
|
111
|
+
autoPluralization,
|
|
112
|
+
collections: {},
|
|
113
|
+
connectOptions: connectOptions || {},
|
|
114
|
+
connection: undefined,
|
|
115
|
+
disableIndexHints,
|
|
116
|
+
globals: undefined,
|
|
117
|
+
mongoMemoryServer,
|
|
118
|
+
sessions: {},
|
|
119
|
+
transactionOptions: transactionOptions === false ? undefined : transactionOptions,
|
|
120
|
+
url,
|
|
121
|
+
versions: {},
|
|
122
|
+
|
|
123
|
+
// DatabaseAdapter
|
|
124
|
+
beginTransaction: transactionOptions ? beginTransaction : undefined,
|
|
125
|
+
commitTransaction,
|
|
126
|
+
connect,
|
|
127
|
+
create,
|
|
128
|
+
createGlobal,
|
|
129
|
+
createGlobalVersion,
|
|
130
|
+
createMigration,
|
|
131
|
+
createVersion,
|
|
132
|
+
defaultIDType: 'text',
|
|
133
|
+
deleteMany,
|
|
134
|
+
deleteOne,
|
|
135
|
+
deleteVersions,
|
|
136
|
+
destroy,
|
|
137
|
+
find,
|
|
138
|
+
findGlobal,
|
|
139
|
+
findGlobalVersions,
|
|
140
|
+
findOne,
|
|
141
|
+
findVersions,
|
|
142
|
+
init,
|
|
143
|
+
migrateFresh,
|
|
144
|
+
migrationDir,
|
|
145
|
+
payload,
|
|
146
|
+
queryDrafts,
|
|
147
|
+
rollbackTransaction,
|
|
148
|
+
updateGlobal,
|
|
149
|
+
updateGlobalVersion,
|
|
150
|
+
updateOne,
|
|
151
|
+
updateVersion,
|
|
152
|
+
})
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return {
|
|
156
|
+
defaultIDType: 'text',
|
|
157
|
+
init: adapter,
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Attempt to find migrations directory.
|
|
163
|
+
*
|
|
164
|
+
* Checks for the following directories in order:
|
|
165
|
+
* - `migrationDir` argument from Payload config
|
|
166
|
+
* - `src/migrations`
|
|
167
|
+
* - `dist/migrations`
|
|
168
|
+
* - `migrations`
|
|
169
|
+
*
|
|
170
|
+
* Defaults to `src/migrations`
|
|
171
|
+
*
|
|
172
|
+
* @param migrationDir
|
|
173
|
+
* @returns
|
|
174
|
+
*/
|
|
175
|
+
function findMigrationDir(migrationDir?: string): string {
|
|
176
|
+
const cwd = process.cwd()
|
|
177
|
+
const srcDir = path.resolve(cwd, 'src/migrations')
|
|
178
|
+
const distDir = path.resolve(cwd, 'dist/migrations')
|
|
179
|
+
const relativeMigrations = path.resolve(cwd, 'migrations')
|
|
180
|
+
|
|
181
|
+
// Use arg if provided
|
|
182
|
+
if (migrationDir) return migrationDir
|
|
183
|
+
|
|
184
|
+
// Check other common locations
|
|
185
|
+
if (fs.existsSync(srcDir)) {
|
|
186
|
+
return srcDir
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (fs.existsSync(distDir)) {
|
|
190
|
+
return distDir
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (fs.existsSync(relativeMigrations)) {
|
|
194
|
+
return relativeMigrations
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return srcDir
|
|
198
|
+
}
|