@payloadcms/db-mongodb 3.0.0-canary.0017c67 → 3.0.0-canary.0cf6f1e

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. package/dist/connect.d.ts.map +1 -1
  2. package/dist/connect.js +1 -1
  3. package/dist/connect.js.map +1 -1
  4. package/dist/count.d.ts.map +1 -1
  5. package/dist/count.js +1 -1
  6. package/dist/count.js.map +1 -1
  7. package/dist/create.d.ts.map +1 -1
  8. package/dist/create.js +7 -3
  9. package/dist/create.js.map +1 -1
  10. package/dist/createGlobal.d.ts.map +1 -1
  11. package/dist/createGlobal.js +1 -1
  12. package/dist/createGlobal.js.map +1 -1
  13. package/dist/createGlobalVersion.d.ts.map +1 -1
  14. package/dist/createGlobalVersion.js +1 -1
  15. package/dist/createGlobalVersion.js.map +1 -1
  16. package/dist/createMigration.d.ts.map +1 -1
  17. package/dist/createMigration.js +1 -1
  18. package/dist/createMigration.js.map +1 -1
  19. package/dist/createVersion.d.ts.map +1 -1
  20. package/dist/createVersion.js +1 -1
  21. package/dist/createVersion.js.map +1 -1
  22. package/dist/deleteMany.d.ts.map +1 -1
  23. package/dist/deleteMany.js +1 -1
  24. package/dist/deleteMany.js.map +1 -1
  25. package/dist/deleteOne.d.ts.map +1 -1
  26. package/dist/deleteOne.js +1 -1
  27. package/dist/deleteOne.js.map +1 -1
  28. package/dist/deleteVersions.d.ts.map +1 -1
  29. package/dist/deleteVersions.js +1 -1
  30. package/dist/deleteVersions.js.map +1 -1
  31. package/dist/find.d.ts.map +1 -1
  32. package/dist/find.js +8 -2
  33. package/dist/find.js.map +1 -1
  34. package/dist/findGlobal.d.ts.map +1 -1
  35. package/dist/findGlobal.js +1 -1
  36. package/dist/findGlobal.js.map +1 -1
  37. package/dist/findGlobalVersions.d.ts.map +1 -1
  38. package/dist/findGlobalVersions.js +9 -3
  39. package/dist/findGlobalVersions.js.map +1 -1
  40. package/dist/findOne.d.ts.map +1 -1
  41. package/dist/findOne.js +1 -1
  42. package/dist/findOne.js.map +1 -1
  43. package/dist/findVersions.d.ts.map +1 -1
  44. package/dist/findVersions.js +8 -2
  45. package/dist/findVersions.js.map +1 -1
  46. package/dist/index.d.ts +29 -5
  47. package/dist/index.d.ts.map +1 -1
  48. package/dist/index.js.map +1 -1
  49. package/dist/init.d.ts.map +1 -1
  50. package/dist/init.js +1 -1
  51. package/dist/init.js.map +1 -1
  52. package/dist/migrateFresh.js.map +1 -1
  53. package/dist/models/buildSchema.d.ts.map +1 -1
  54. package/dist/models/buildSchema.js +12 -11
  55. package/dist/models/buildSchema.js.map +1 -1
  56. package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
  57. package/dist/queries/buildAndOrConditions.js +0 -2
  58. package/dist/queries/buildAndOrConditions.js.map +1 -1
  59. package/dist/queries/getLocalizedSortProperty.spec.js +42 -42
  60. package/dist/queries/getLocalizedSortProperty.spec.js.map +1 -1
  61. package/dist/queries/parseParams.d.ts.map +1 -1
  62. package/dist/queries/parseParams.js +2 -5
  63. package/dist/queries/parseParams.js.map +1 -1
  64. package/dist/queryDrafts.d.ts.map +1 -1
  65. package/dist/queryDrafts.js +8 -2
  66. package/dist/queryDrafts.js.map +1 -1
  67. package/dist/transactions/commitTransaction.d.ts.map +1 -1
  68. package/dist/transactions/commitTransaction.js +1 -0
  69. package/dist/transactions/commitTransaction.js.map +1 -1
  70. package/dist/transactions/rollbackTransaction.d.ts.map +1 -1
  71. package/dist/transactions/rollbackTransaction.js +13 -7
  72. package/dist/transactions/rollbackTransaction.js.map +1 -1
  73. package/dist/updateGlobal.d.ts.map +1 -1
  74. package/dist/updateGlobal.js +1 -1
  75. package/dist/updateGlobal.js.map +1 -1
  76. package/dist/updateGlobalVersion.d.ts.map +1 -1
  77. package/dist/updateGlobalVersion.js +1 -1
  78. package/dist/updateGlobalVersion.js.map +1 -1
  79. package/dist/updateOne.d.ts.map +1 -1
  80. package/dist/updateOne.js +7 -3
  81. package/dist/updateOne.js.map +1 -1
  82. package/dist/updateVersion.d.ts.map +1 -1
  83. package/dist/updateVersion.js +1 -1
  84. package/dist/updateVersion.js.map +1 -1
  85. package/dist/utilities/handleError.d.ts +6 -2
  86. package/dist/utilities/handleError.d.ts.map +1 -1
  87. package/dist/utilities/handleError.js +11 -8
  88. package/dist/utilities/handleError.js.map +1 -1
  89. package/dist/withSession.d.ts +3 -2
  90. package/dist/withSession.d.ts.map +1 -1
  91. package/dist/withSession.js +6 -2
  92. package/dist/withSession.js.map +1 -1
  93. package/package.json +4 -5
@@ -1,20 +1,23 @@
1
1
  import httpStatus from 'http-status';
2
2
  import { APIError, ValidationError } from 'payload';
3
- const handleError = (error, req)=>{
3
+ export const handleError = ({ collection, error, global, req })=>{
4
4
  // Handle uniqueness error from MongoDB
5
5
  if (error.code === 11000 && error.keyValue) {
6
- throw new ValidationError([
7
- {
8
- field: Object.keys(error.keyValue)[0],
9
- message: req.t('error:valueMustBeUnique')
10
- }
11
- ], req.t);
6
+ throw new ValidationError({
7
+ collection,
8
+ errors: [
9
+ {
10
+ field: Object.keys(error.keyValue)[0],
11
+ message: req.t('error:valueMustBeUnique')
12
+ }
13
+ ],
14
+ global
15
+ }, req.t);
12
16
  } else if (error.code === 11000) {
13
17
  throw new APIError(req.t('error:valueMustBeUnique'), httpStatus.BAD_REQUEST);
14
18
  } else {
15
19
  throw error;
16
20
  }
17
21
  };
18
- export default handleError;
19
22
 
20
23
  //# sourceMappingURL=handleError.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/handleError.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { APIError, ValidationError } from 'payload'\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"],"mappings":"AAAA,OAAOA,gBAAgB,cAAa;AACpC,SAASC,QAAQ,EAAEC,eAAe,QAAQ,UAAS;AAEnD,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
+ {"version":3,"sources":["../../src/utilities/handleError.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { APIError, ValidationError } from 'payload'\n\nexport const handleError = ({\n collection,\n error,\n global,\n req,\n}: {\n collection?: string\n error\n global?: string\n req\n}) => {\n // Handle uniqueness error from MongoDB\n if (error.code === 11000 && error.keyValue) {\n throw new ValidationError(\n {\n collection,\n errors: [\n {\n field: Object.keys(error.keyValue)[0],\n message: req.t('error:valueMustBeUnique'),\n },\n ],\n global,\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"],"names":["httpStatus","APIError","ValidationError","handleError","collection","error","global","req","code","keyValue","errors","field","Object","keys","message","t","BAD_REQUEST"],"mappings":"AAAA,OAAOA,gBAAgB,cAAa;AACpC,SAASC,QAAQ,EAAEC,eAAe,QAAQ,UAAS;AAEnD,OAAO,MAAMC,cAAc,CAAC,EAC1BC,UAAU,EACVC,KAAK,EACLC,MAAM,EACNC,GAAG,EAMJ;IACC,uCAAuC;IACvC,IAAIF,MAAMG,IAAI,KAAK,SAASH,MAAMI,QAAQ,EAAE;QAC1C,MAAM,IAAIP,gBACR;YACEE;YACAM,QAAQ;gBACN;oBACEC,OAAOC,OAAOC,IAAI,CAACR,MAAMI,QAAQ,CAAC,CAAC,EAAE;oBACrCK,SAASP,IAAIQ,CAAC,CAAC;gBACjB;aACD;YACDT;QACF,GACAC,IAAIQ,CAAC;IAET,OAAO,IAAIV,MAAMG,IAAI,KAAK,OAAO;QAC/B,MAAM,IAAIP,SAASM,IAAIQ,CAAC,CAAC,4BAA4Bf,WAAWgB,WAAW;IAC7E,OAAO;QACL,MAAMX;IACR;AACF,EAAC"}
@@ -1,10 +1,11 @@
1
1
  import type { ClientSession } from 'mongoose';
2
+ import type { PayloadRequest } from 'payload';
2
3
  import type { MongooseAdapter } from './index.js';
3
4
  /**
4
5
  * returns the session belonging to the transaction of the req.session if exists
5
6
  * @returns ClientSession
6
7
  */
7
- export declare function withSession(db: MongooseAdapter, transactionID?: number | string): {
8
+ export declare function withSession(db: MongooseAdapter, req: PayloadRequest): Promise<{
8
9
  session: ClientSession;
9
- } | object;
10
+ } | object>;
10
11
  //# sourceMappingURL=withSession.d.ts.map
@@ -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,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"}
1
+ {"version":3,"file":"withSession.d.ts","sourceRoot":"","sources":["../src/withSession.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAC7C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAEjD;;;GAGG;AACH,wBAAsB,WAAW,CAC/B,EAAE,EAAE,eAAe,EACnB,GAAG,EAAE,cAAc,GAClB,OAAO,CAAC;IAAE,OAAO,EAAE,aAAa,CAAA;CAAE,GAAG,MAAM,CAAC,CAQ9C"}
@@ -1,8 +1,12 @@
1
1
  /**
2
2
  * returns the session belonging to the transaction of the req.session if exists
3
3
  * @returns ClientSession
4
- */ export function withSession(db, transactionID) {
5
- return db.sessions[transactionID] ? {
4
+ */ export async function withSession(db, req) {
5
+ let transactionID = req.transactionID;
6
+ if (transactionID instanceof Promise) {
7
+ transactionID = await req.transactionID;
8
+ }
9
+ if (req) return db.sessions[transactionID] ? {
6
10
  session: db.sessions[transactionID]
7
11
  } : {};
8
12
  }
@@ -1 +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"],"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"}
1
+ {"version":3,"sources":["../src/withSession.ts"],"sourcesContent":["import type { ClientSession } from 'mongoose'\nimport type { PayloadRequest } from 'payload'\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 async function withSession(\n db: MongooseAdapter,\n req: PayloadRequest,\n): Promise<{ session: ClientSession } | object> {\n let transactionID = req.transactionID\n\n if (transactionID instanceof Promise) {\n transactionID = await req.transactionID\n }\n\n if (req) return db.sessions[transactionID] ? { session: db.sessions[transactionID] } : {}\n}\n"],"names":["withSession","db","req","transactionID","Promise","sessions","session"],"mappings":"AAKA;;;CAGC,GACD,OAAO,eAAeA,YACpBC,EAAmB,EACnBC,GAAmB;IAEnB,IAAIC,gBAAgBD,IAAIC,aAAa;IAErC,IAAIA,yBAAyBC,SAAS;QACpCD,gBAAgB,MAAMD,IAAIC,aAAa;IACzC;IAEA,IAAID,KAAK,OAAOD,GAAGI,QAAQ,CAACF,cAAc,GAAG;QAAEG,SAASL,GAAGI,QAAQ,CAACF,cAAc;IAAC,IAAI,CAAC;AAC1F"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/db-mongodb",
3
- "version": "3.0.0-canary.0017c67",
3
+ "version": "3.0.0-canary.0cf6f1e",
4
4
  "description": "The officially supported MongoDB database adapter for Payload",
5
5
  "homepage": "https://payloadcms.com",
6
6
  "repository": {
@@ -27,7 +27,6 @@
27
27
  ],
28
28
  "dependencies": {
29
29
  "bson-objectid": "2.0.4",
30
- "deepmerge": "4.3.1",
31
30
  "http-status": "1.6.2",
32
31
  "mongoose": "6.12.3",
33
32
  "mongoose-paginate-v2": "1.7.22",
@@ -38,11 +37,11 @@
38
37
  "@types/mongoose-aggregate-paginate-v2": "1.0.9",
39
38
  "mongodb": "4.17.1",
40
39
  "mongodb-memory-server": "^9",
41
- "@payloadcms/eslint-config": "1.1.1",
42
- "payload": "3.0.0-canary.0017c67"
40
+ "@payloadcms/eslint-config": "3.0.0-beta.59",
41
+ "payload": "3.0.0-canary.0cf6f1e"
43
42
  },
44
43
  "peerDependencies": {
45
- "payload": "3.0.0-canary.0017c67"
44
+ "payload": "3.0.0-canary.0cf6f1e"
46
45
  },
47
46
  "scripts": {
48
47
  "build": "pnpm build:types && pnpm build:swc",