@payloadcms/db-mongodb 3.0.0-beta.9 → 3.0.0-beta.91

Sign up to get free protection for your applications and to get access to all the features.
Files changed (170) hide show
  1. package/README.md +1 -1
  2. package/dist/connect.d.ts +1 -1
  3. package/dist/connect.d.ts.map +1 -1
  4. package/dist/connect.js +6 -1
  5. package/dist/connect.js.map +1 -1
  6. package/dist/count.d.ts +3 -0
  7. package/dist/count.d.ts.map +1 -0
  8. package/dist/count.js +33 -0
  9. package/dist/count.js.map +1 -0
  10. package/dist/create.d.ts +1 -1
  11. package/dist/create.d.ts.map +1 -1
  12. package/dist/create.js +7 -3
  13. package/dist/create.js.map +1 -1
  14. package/dist/createGlobal.d.ts +1 -1
  15. package/dist/createGlobal.d.ts.map +1 -1
  16. package/dist/createGlobal.js +1 -1
  17. package/dist/createGlobal.js.map +1 -1
  18. package/dist/createGlobalVersion.d.ts +1 -1
  19. package/dist/createGlobalVersion.d.ts.map +1 -1
  20. package/dist/createGlobalVersion.js +1 -1
  21. package/dist/createGlobalVersion.js.map +1 -1
  22. package/dist/createMigration.d.ts +1 -1
  23. package/dist/createMigration.d.ts.map +1 -1
  24. package/dist/createMigration.js +14 -28
  25. package/dist/createMigration.js.map +1 -1
  26. package/dist/createVersion.d.ts +1 -1
  27. package/dist/createVersion.d.ts.map +1 -1
  28. package/dist/createVersion.js +1 -1
  29. package/dist/createVersion.js.map +1 -1
  30. package/dist/deleteMany.d.ts +1 -1
  31. package/dist/deleteMany.d.ts.map +1 -1
  32. package/dist/deleteMany.js +1 -1
  33. package/dist/deleteMany.js.map +1 -1
  34. package/dist/deleteOne.d.ts +1 -1
  35. package/dist/deleteOne.d.ts.map +1 -1
  36. package/dist/deleteOne.js +1 -1
  37. package/dist/deleteOne.js.map +1 -1
  38. package/dist/deleteVersions.d.ts +1 -1
  39. package/dist/deleteVersions.d.ts.map +1 -1
  40. package/dist/deleteVersions.js +1 -1
  41. package/dist/deleteVersions.js.map +1 -1
  42. package/dist/destroy.d.ts +1 -1
  43. package/dist/destroy.d.ts.map +1 -1
  44. package/dist/destroy.js.map +1 -1
  45. package/dist/find.d.ts +1 -1
  46. package/dist/find.d.ts.map +1 -1
  47. package/dist/find.js +9 -3
  48. package/dist/find.js.map +1 -1
  49. package/dist/findGlobal.d.ts +1 -1
  50. package/dist/findGlobal.d.ts.map +1 -1
  51. package/dist/findGlobal.js +2 -2
  52. package/dist/findGlobal.js.map +1 -1
  53. package/dist/findGlobalVersions.d.ts +1 -1
  54. package/dist/findGlobalVersions.d.ts.map +1 -1
  55. package/dist/findGlobalVersions.js +10 -5
  56. package/dist/findGlobalVersions.js.map +1 -1
  57. package/dist/findOne.d.ts +1 -1
  58. package/dist/findOne.d.ts.map +1 -1
  59. package/dist/findOne.js +1 -1
  60. package/dist/findOne.js.map +1 -1
  61. package/dist/findVersions.d.ts +1 -1
  62. package/dist/findVersions.d.ts.map +1 -1
  63. package/dist/findVersions.js +9 -3
  64. package/dist/findVersions.js.map +1 -1
  65. package/dist/index.d.ts +47 -33
  66. package/dist/index.d.ts.map +1 -1
  67. package/dist/index.js +6 -2
  68. package/dist/index.js.map +1 -1
  69. package/dist/init.d.ts +1 -1
  70. package/dist/init.d.ts.map +1 -1
  71. package/dist/init.js +3 -2
  72. package/dist/init.js.map +1 -1
  73. package/dist/migrateFresh.d.ts.map +1 -1
  74. package/dist/migrateFresh.js +1 -1
  75. package/dist/migrateFresh.js.map +1 -1
  76. package/dist/models/buildCollectionSchema.d.ts +1 -27
  77. package/dist/models/buildCollectionSchema.d.ts.map +1 -1
  78. package/dist/models/buildCollectionSchema.js +9 -0
  79. package/dist/models/buildCollectionSchema.js.map +1 -1
  80. package/dist/models/buildGlobalModel.d.ts +1 -1
  81. package/dist/models/buildGlobalModel.d.ts.map +1 -1
  82. package/dist/models/buildGlobalModel.js.map +1 -1
  83. package/dist/models/buildSchema.d.ts +1 -27
  84. package/dist/models/buildSchema.d.ts.map +1 -1
  85. package/dist/models/buildSchema.js +90 -18
  86. package/dist/models/buildSchema.js.map +1 -1
  87. package/{predefinedMigrations → dist/predefinedMigrations}/versions-v1-v2.js +3 -1
  88. package/dist/predefinedMigrations/versions-v1-v2.js.map +1 -0
  89. package/dist/queries/buildAndOrConditions.d.ts +1 -2
  90. package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
  91. package/dist/queries/buildAndOrConditions.js +0 -2
  92. package/dist/queries/buildAndOrConditions.js.map +1 -1
  93. package/dist/queries/buildQuery.d.ts +1 -2
  94. package/dist/queries/buildQuery.d.ts.map +1 -1
  95. package/dist/queries/buildQuery.js +1 -1
  96. package/dist/queries/buildQuery.js.map +1 -1
  97. package/dist/queries/buildSearchParams.d.ts +1 -2
  98. package/dist/queries/buildSearchParams.d.ts.map +1 -1
  99. package/dist/queries/buildSearchParams.js +9 -7
  100. package/dist/queries/buildSearchParams.js.map +1 -1
  101. package/dist/queries/buildSortParam.d.ts +2 -28
  102. package/dist/queries/buildSortParam.d.ts.map +1 -1
  103. package/dist/queries/buildSortParam.js.map +1 -1
  104. package/dist/queries/getLocalizedSortProperty.d.ts +1 -2
  105. package/dist/queries/getLocalizedSortProperty.d.ts.map +1 -1
  106. package/dist/queries/getLocalizedSortProperty.js +2 -2
  107. package/dist/queries/getLocalizedSortProperty.js.map +1 -1
  108. package/dist/queries/getLocalizedSortProperty.spec.js +54 -51
  109. package/dist/queries/getLocalizedSortProperty.spec.js.map +1 -1
  110. package/dist/queries/mock.js.map +1 -1
  111. package/dist/queries/operatorMap.js.map +1 -1
  112. package/dist/queries/parseParams.d.ts +1 -3
  113. package/dist/queries/parseParams.d.ts.map +1 -1
  114. package/dist/queries/parseParams.js +3 -6
  115. package/dist/queries/parseParams.js.map +1 -1
  116. package/dist/queries/sanitizeQueryValue.d.ts +1 -1
  117. package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
  118. package/dist/queries/sanitizeQueryValue.js +2 -2
  119. package/dist/queries/sanitizeQueryValue.js.map +1 -1
  120. package/dist/queryDrafts.d.ts +1 -1
  121. package/dist/queryDrafts.d.ts.map +1 -1
  122. package/dist/queryDrafts.js +9 -3
  123. package/dist/queryDrafts.js.map +1 -1
  124. package/dist/testCredentials.js.map +1 -1
  125. package/dist/transactions/beginTransaction.d.ts +1 -1
  126. package/dist/transactions/beginTransaction.d.ts.map +1 -1
  127. package/dist/transactions/beginTransaction.js +1 -1
  128. package/dist/transactions/beginTransaction.js.map +1 -1
  129. package/dist/transactions/commitTransaction.d.ts +1 -1
  130. package/dist/transactions/commitTransaction.d.ts.map +1 -1
  131. package/dist/transactions/commitTransaction.js +6 -1
  132. package/dist/transactions/commitTransaction.js.map +1 -1
  133. package/dist/transactions/rollbackTransaction.d.ts +1 -1
  134. package/dist/transactions/rollbackTransaction.d.ts.map +1 -1
  135. package/dist/transactions/rollbackTransaction.js +13 -7
  136. package/dist/transactions/rollbackTransaction.js.map +1 -1
  137. package/dist/types.d.ts +1 -28
  138. package/dist/types.d.ts.map +1 -1
  139. package/dist/types.js.map +1 -1
  140. package/dist/updateGlobal.d.ts +1 -1
  141. package/dist/updateGlobal.d.ts.map +1 -1
  142. package/dist/updateGlobal.js +1 -1
  143. package/dist/updateGlobal.js.map +1 -1
  144. package/dist/updateGlobalVersion.d.ts +1 -2
  145. package/dist/updateGlobalVersion.d.ts.map +1 -1
  146. package/dist/updateGlobalVersion.js +1 -1
  147. package/dist/updateGlobalVersion.js.map +1 -1
  148. package/dist/updateOne.d.ts +1 -1
  149. package/dist/updateOne.d.ts.map +1 -1
  150. package/dist/updateOne.js +7 -3
  151. package/dist/updateOne.js.map +1 -1
  152. package/dist/updateVersion.d.ts +1 -1
  153. package/dist/updateVersion.d.ts.map +1 -1
  154. package/dist/updateVersion.js +1 -1
  155. package/dist/updateVersion.js.map +1 -1
  156. package/dist/utilities/getDBName.d.ts +1 -1
  157. package/dist/utilities/getDBName.d.ts.map +1 -1
  158. package/dist/utilities/getDBName.js.map +1 -1
  159. package/dist/utilities/handleError.d.ts +6 -2
  160. package/dist/utilities/handleError.d.ts.map +1 -1
  161. package/dist/utilities/handleError.js +12 -9
  162. package/dist/utilities/handleError.js.map +1 -1
  163. package/dist/utilities/sanitizeInternalFields.d.ts.map +1 -1
  164. package/dist/utilities/sanitizeInternalFields.js.map +1 -1
  165. package/dist/withSession.d.ts +3 -27
  166. package/dist/withSession.d.ts.map +1 -1
  167. package/dist/withSession.js +6 -2
  168. package/dist/withSession.js.map +1 -1
  169. package/package.json +20 -26
  170. package/src/index.ts +0 -198
@@ -1,20 +1,23 @@
1
1
  import httpStatus from 'http-status';
2
- import { APIError, ValidationError } from 'payload/errors';
3
- const handleError = (error, req)=>{
2
+ import { APIError, ValidationError } from 'payload';
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/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
+ {"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 +1 @@
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
+ {"version":3,"file":"sanitizeInternalFields.d.ts","sourceRoot":"","sources":["../../src/utilities/sanitizeInternalFields.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,sBAAsB,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,eAAe,CAAC,KAAG,CAiBvE,CAAA;AAEb,eAAe,sBAAsB,CAAA"}
@@ -1 +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"}
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"],"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"}
@@ -1,35 +1,11 @@
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" />
26
1
  import type { ClientSession } from 'mongoose';
2
+ import type { PayloadRequest } from 'payload';
27
3
  import type { MongooseAdapter } from './index.js';
28
4
  /**
29
5
  * returns the session belonging to the transaction of the req.session if exists
30
6
  * @returns ClientSession
31
7
  */
32
- export declare function withSession(db: MongooseAdapter, transactionID?: number | string): {
8
+ export declare function withSession(db: MongooseAdapter, req: PayloadRequest): Promise<{
33
9
  session: ClientSession;
34
- } | object;
10
+ } | object>;
35
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"],"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"}
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,57 +1,51 @@
1
1
  {
2
2
  "name": "@payloadcms/db-mongodb",
3
- "version": "3.0.0-beta.9",
3
+ "version": "3.0.0-beta.91",
4
4
  "description": "The officially supported MongoDB database adapter for Payload",
5
+ "homepage": "https://payloadcms.com",
5
6
  "repository": {
6
7
  "type": "git",
7
8
  "url": "https://github.com/payloadcms/payload.git",
8
9
  "directory": "packages/db-mongodb"
9
10
  },
10
11
  "license": "MIT",
11
- "homepage": "https://payloadcms.com",
12
+ "author": "Payload <dev@payloadcms.com> (https://payloadcms.com)",
12
13
  "type": "module",
13
- "author": {
14
- "email": "info@payloadcms.com",
15
- "name": "Payload",
16
- "url": "https://payloadcms.com"
14
+ "exports": {
15
+ ".": {
16
+ "import": "./dist/index.js",
17
+ "types": "./dist/index.d.ts",
18
+ "default": "./dist/index.js"
19
+ }
17
20
  },
18
21
  "main": "./dist/index.js",
19
22
  "types": "./dist/index.d.ts",
23
+ "files": [
24
+ "dist",
25
+ "mock.js",
26
+ "predefinedMigrations"
27
+ ],
20
28
  "dependencies": {
21
29
  "bson-objectid": "2.0.4",
22
- "deepmerge": "4.3.1",
23
- "get-port": "5.1.1",
24
30
  "http-status": "1.6.2",
25
31
  "mongoose": "6.12.3",
26
32
  "mongoose-paginate-v2": "1.7.22",
27
33
  "prompts": "2.4.2",
28
- "uuid": "9.0.0"
34
+ "uuid": "10.0.0"
29
35
  },
30
36
  "devDependencies": {
31
37
  "@types/mongoose-aggregate-paginate-v2": "1.0.9",
32
38
  "mongodb": "4.17.1",
33
39
  "mongodb-memory-server": "^9",
34
- "payload": "3.0.0-beta.9",
35
- "@payloadcms/eslint-config": "1.1.1"
40
+ "@payloadcms/eslint-config": "3.0.0-beta.59",
41
+ "payload": "3.0.0-beta.91"
36
42
  },
37
43
  "peerDependencies": {
38
- "payload": "3.0.0-beta.9"
44
+ "payload": "3.0.0-beta.91"
39
45
  },
40
- "exports": {
41
- ".": {
42
- "import": "./dist/index.js",
43
- "require": "./dist/index.js",
44
- "types": "./dist/index.d.ts"
45
- }
46
- },
47
- "files": [
48
- "dist",
49
- "mock.js",
50
- "predefinedMigrations"
51
- ],
52
46
  "scripts": {
53
- "build": "pnpm build:swc && pnpm build:types",
54
- "build:swc": "swc ./src -d ./dist --config-file .swcrc-build",
47
+ "build": "pnpm build:types && pnpm build:swc",
48
+ "build:swc": "swc ./src -d ./dist --config-file .swcrc-build --strip-leading-paths",
55
49
  "build:types": "tsc --emitDeclarationOnly --outDir dist",
56
50
  "clean": "rimraf {dist,*.tsbuildinfo}"
57
51
  }
package/src/index.ts DELETED
@@ -1,198 +0,0 @@
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
- }