@payloadcms/db-mongodb 3.0.0-canary.ee6d727 → 3.0.0-canary.ef0a8d0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (167) 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 +1 -1
  5. package/dist/connect.js.map +1 -1
  6. package/dist/count.d.ts +1 -1
  7. package/dist/count.d.ts.map +1 -1
  8. package/dist/count.js +2 -2
  9. package/dist/count.js.map +1 -1
  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 +2 -2
  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 +2 -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 +2 -4
  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 +2 -3
  64. package/dist/findVersions.js.map +1 -1
  65. package/dist/index.d.ts +5 -30
  66. package/dist/index.d.ts.map +1 -1
  67. package/dist/index.js +1 -1
  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 +2 -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.map +1 -1
  79. package/dist/models/buildGlobalModel.d.ts +1 -1
  80. package/dist/models/buildGlobalModel.d.ts.map +1 -1
  81. package/dist/models/buildGlobalModel.js.map +1 -1
  82. package/dist/models/buildSchema.d.ts +1 -27
  83. package/dist/models/buildSchema.d.ts.map +1 -1
  84. package/dist/models/buildSchema.js +2 -4
  85. package/dist/models/buildSchema.js.map +1 -1
  86. package/dist/predefinedMigrations/versions-v1-v2.js.map +1 -1
  87. package/dist/queries/buildAndOrConditions.d.ts +1 -2
  88. package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
  89. package/dist/queries/buildAndOrConditions.js +0 -2
  90. package/dist/queries/buildAndOrConditions.js.map +1 -1
  91. package/dist/queries/buildQuery.d.ts +1 -2
  92. package/dist/queries/buildQuery.d.ts.map +1 -1
  93. package/dist/queries/buildQuery.js +1 -1
  94. package/dist/queries/buildQuery.js.map +1 -1
  95. package/dist/queries/buildSearchParams.d.ts +1 -2
  96. package/dist/queries/buildSearchParams.d.ts.map +1 -1
  97. package/dist/queries/buildSearchParams.js +2 -2
  98. package/dist/queries/buildSearchParams.js.map +1 -1
  99. package/dist/queries/buildSortParam.d.ts +2 -28
  100. package/dist/queries/buildSortParam.d.ts.map +1 -1
  101. package/dist/queries/buildSortParam.js.map +1 -1
  102. package/dist/queries/getLocalizedSortProperty.d.ts +1 -2
  103. package/dist/queries/getLocalizedSortProperty.d.ts.map +1 -1
  104. package/dist/queries/getLocalizedSortProperty.js +2 -2
  105. package/dist/queries/getLocalizedSortProperty.js.map +1 -1
  106. package/dist/queries/getLocalizedSortProperty.spec.js +43 -43
  107. package/dist/queries/getLocalizedSortProperty.spec.js.map +1 -1
  108. package/dist/queries/mock.js.map +1 -1
  109. package/dist/queries/operatorMap.js.map +1 -1
  110. package/dist/queries/parseParams.d.ts +1 -3
  111. package/dist/queries/parseParams.d.ts.map +1 -1
  112. package/dist/queries/parseParams.js +3 -3
  113. package/dist/queries/parseParams.js.map +1 -1
  114. package/dist/queries/sanitizeQueryValue.d.ts +1 -1
  115. package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
  116. package/dist/queries/sanitizeQueryValue.js +1 -1
  117. package/dist/queries/sanitizeQueryValue.js.map +1 -1
  118. package/dist/queryDrafts.d.ts +1 -1
  119. package/dist/queryDrafts.d.ts.map +1 -1
  120. package/dist/queryDrafts.js +2 -3
  121. package/dist/queryDrafts.js.map +1 -1
  122. package/dist/testCredentials.js.map +1 -1
  123. package/dist/transactions/beginTransaction.d.ts +1 -1
  124. package/dist/transactions/beginTransaction.d.ts.map +1 -1
  125. package/dist/transactions/beginTransaction.js +1 -1
  126. package/dist/transactions/beginTransaction.js.map +1 -1
  127. package/dist/transactions/commitTransaction.d.ts +1 -1
  128. package/dist/transactions/commitTransaction.d.ts.map +1 -1
  129. package/dist/transactions/commitTransaction.js +1 -0
  130. package/dist/transactions/commitTransaction.js.map +1 -1
  131. package/dist/transactions/rollbackTransaction.d.ts +1 -1
  132. package/dist/transactions/rollbackTransaction.d.ts.map +1 -1
  133. package/dist/transactions/rollbackTransaction.js +13 -7
  134. package/dist/transactions/rollbackTransaction.js.map +1 -1
  135. package/dist/types.d.ts +1 -28
  136. package/dist/types.d.ts.map +1 -1
  137. package/dist/types.js.map +1 -1
  138. package/dist/updateGlobal.d.ts +1 -1
  139. package/dist/updateGlobal.d.ts.map +1 -1
  140. package/dist/updateGlobal.js +1 -1
  141. package/dist/updateGlobal.js.map +1 -1
  142. package/dist/updateGlobalVersion.d.ts +1 -2
  143. package/dist/updateGlobalVersion.d.ts.map +1 -1
  144. package/dist/updateGlobalVersion.js +1 -1
  145. package/dist/updateGlobalVersion.js.map +1 -1
  146. package/dist/updateOne.d.ts +1 -1
  147. package/dist/updateOne.d.ts.map +1 -1
  148. package/dist/updateOne.js +7 -3
  149. package/dist/updateOne.js.map +1 -1
  150. package/dist/updateVersion.d.ts +1 -1
  151. package/dist/updateVersion.d.ts.map +1 -1
  152. package/dist/updateVersion.js +1 -1
  153. package/dist/updateVersion.js.map +1 -1
  154. package/dist/utilities/getDBName.d.ts +1 -1
  155. package/dist/utilities/getDBName.d.ts.map +1 -1
  156. package/dist/utilities/getDBName.js.map +1 -1
  157. package/dist/utilities/handleError.d.ts +6 -2
  158. package/dist/utilities/handleError.d.ts.map +1 -1
  159. package/dist/utilities/handleError.js +12 -9
  160. package/dist/utilities/handleError.js.map +1 -1
  161. package/dist/utilities/sanitizeInternalFields.d.ts.map +1 -1
  162. package/dist/utilities/sanitizeInternalFields.js.map +1 -1
  163. package/dist/withSession.d.ts +3 -27
  164. package/dist/withSession.d.ts.map +1 -1
  165. package/dist/withSession.js +6 -2
  166. package/dist/withSession.js.map +1 -1
  167. package/package.json +9 -9
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/findGlobalVersions.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { FindGlobalVersions } from 'payload/database'\nimport type { PayloadRequestWithData } from 'payload/types'\n\nimport { flattenWhereToOperators } from 'payload/database'\nimport { buildVersionGlobalFields } from 'payload/versions'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport sanitizeInternalFields from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const findGlobalVersions: FindGlobalVersions = async function findGlobalVersions(\n this: MongooseAdapter,\n {\n global,\n limit,\n locale,\n page,\n pagination,\n req = {} as PayloadRequestWithData,\n skip,\n sort: sortArg,\n where,\n },\n) {\n const Model = this.versions[global]\n const versionFields = buildVersionGlobalFields(\n this.payload.globals.config.find(({ slug }) => slug === global),\n )\n const options = {\n ...withSession(this, req.transactionID),\n limit,\n skip,\n }\n\n let hasNearConstraint = false\n\n if (where) {\n const constraints = flattenWhereToOperators(where)\n hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n }\n\n let sort\n if (!hasNearConstraint) {\n sort = buildSortParam({\n config: this.payload.config,\n fields: versionFields,\n locale,\n sort: sortArg || '-updatedAt',\n timestamps: true,\n })\n }\n\n const query = await Model.buildQuery({\n globalSlug: global,\n locale,\n payload: this.payload,\n where,\n })\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0\n const paginationOptions: PaginateOptions = {\n forceCountFn: hasNearConstraint,\n lean: true,\n leanWithId: true,\n offset: skip,\n options,\n page,\n pagination,\n sort,\n useEstimatedCount,\n }\n\n if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n paginationOptions.useCustomCountFn = () => {\n return Promise.resolve(\n Model.countDocuments(query, {\n ...options,\n hint: { _id: 1 },\n }),\n )\n }\n }\n\n if (limit >= 0) {\n paginationOptions.limit = limit\n // limit must also be set here, it's ignored when pagination is false\n paginationOptions.options.limit = limit\n\n // Disable pagination if limit is 0\n if (limit === 0) {\n paginationOptions.pagination = false\n }\n }\n\n const result = await Model.paginate(query, paginationOptions)\n const docs = JSON.parse(JSON.stringify(result.docs))\n\n return {\n ...result,\n docs: docs.map((doc) => {\n // eslint-disable-next-line no-param-reassign\n doc.id = doc._id\n return sanitizeInternalFields(doc)\n }),\n }\n}\n"],"names":["flattenWhereToOperators","buildVersionGlobalFields","buildSortParam","sanitizeInternalFields","withSession","findGlobalVersions","global","limit","locale","page","pagination","req","skip","sort","sortArg","where","Model","versions","versionFields","payload","globals","config","find","slug","options","transactionID","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","timestamps","query","buildQuery","globalSlug","useEstimatedCount","length","paginationOptions","forceCountFn","lean","leanWithId","offset","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","paginate","docs","JSON","parse","stringify","map","doc","id"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAIA,SAASA,uBAAuB,QAAQ,mBAAkB;AAC1D,SAASC,wBAAwB,QAAQ,mBAAkB;AAI3D,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,OAAOC,4BAA4B,wCAAuC;AAC1E,SAASC,WAAW,QAAQ,mBAAkB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AK,MAAM;QAC5F,mHAAmH;QACnH,qHAAqH;QACrH,mHAAmH;QACnH,4BAA4B;QAC5BL,kBAAkBM,gBAAgB,GAAG;YACnC,OAAOC,QAAQC,OAAO,CACpBhC,MAAMiC,cAAc,CAACd,OAAO;gBAC1B,GAAGX,OAAO;gBACV0B,MAAM;oBAAEC,KAAK;gBAAE;YACjB;QAEJ;IACF;IAEA,IAAI5C,SAAS,GAAG;QACdiC,kBAAkBjC,KAAK,GAAGA;QAC1B,qEAAqE;QACrEiC,kBAAkBhB,OAAO,CAACjB,KAAK,GAAGA;QAElC,mCAAmC;QACnC,IAAIA,UAAU,GAAG;YACfiC,kBAAkB9B,UAAU,GAAG;QACjC;IACF;IAEA,MAAM0C,SAAS,MAAMpC,MAAMqC,QAAQ,CAAClB,OAAOK;IAC3C,MAAMc,OAAOC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL,OAAOE,IAAI;IAElD,OAAO;QACL,GAAGF,MAAM;QACTE,MAAMA,KAAKI,GAAG,CAAC,CAACC;YACd,6CAA6C;YAC7CA,IAAIC,EAAE,GAAGD,IAAIR,GAAG;YAChB,OAAOhD,uBAAuBwD;QAChC;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../src/findGlobalVersions.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { FindGlobalVersions, PayloadRequest } from 'payload'\n\nimport { buildVersionGlobalFields, flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport sanitizeInternalFields from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const findGlobalVersions: FindGlobalVersions = async function findGlobalVersions(\n this: MongooseAdapter,\n {\n global,\n limit,\n locale,\n page,\n pagination,\n req = {} as PayloadRequest,\n skip,\n sort: sortArg,\n where,\n },\n) {\n const Model = this.versions[global]\n const versionFields = buildVersionGlobalFields(\n this.payload.globals.config.find(({ slug }) => slug === global),\n )\n const options = {\n ...(await withSession(this, req)),\n limit,\n skip,\n }\n\n let hasNearConstraint = false\n\n if (where) {\n const constraints = flattenWhereToOperators(where)\n hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n }\n\n let sort\n if (!hasNearConstraint) {\n sort = buildSortParam({\n config: this.payload.config,\n fields: versionFields,\n locale,\n sort: sortArg || '-updatedAt',\n timestamps: true,\n })\n }\n\n const query = await Model.buildQuery({\n globalSlug: global,\n locale,\n payload: this.payload,\n where,\n })\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0\n const paginationOptions: PaginateOptions = {\n forceCountFn: hasNearConstraint,\n lean: true,\n leanWithId: true,\n offset: skip,\n options,\n page,\n pagination,\n sort,\n useEstimatedCount,\n }\n\n if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n paginationOptions.useCustomCountFn = () => {\n return Promise.resolve(\n Model.countDocuments(query, {\n ...options,\n hint: { _id: 1 },\n }),\n )\n }\n }\n\n if (limit >= 0) {\n paginationOptions.limit = limit\n // limit must also be set here, it's ignored when pagination is false\n paginationOptions.options.limit = limit\n\n // Disable pagination if limit is 0\n if (limit === 0) {\n paginationOptions.pagination = false\n }\n }\n\n const result = await Model.paginate(query, paginationOptions)\n const docs = JSON.parse(JSON.stringify(result.docs))\n\n return {\n ...result,\n docs: docs.map((doc) => {\n doc.id = doc._id\n return sanitizeInternalFields(doc)\n }),\n }\n}\n"],"names":["buildVersionGlobalFields","flattenWhereToOperators","buildSortParam","sanitizeInternalFields","withSession","findGlobalVersions","global","limit","locale","page","pagination","req","skip","sort","sortArg","where","Model","versions","versionFields","payload","globals","config","find","slug","options","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","timestamps","query","buildQuery","globalSlug","useEstimatedCount","length","paginationOptions","forceCountFn","lean","leanWithId","offset","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","paginate","docs","JSON","parse","stringify","map","doc","id"],"mappings":"AAGA,SAASA,wBAAwB,EAAEC,uBAAuB,QAAQ,UAAS;AAI3E,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,OAAOC,4BAA4B,wCAAuC;AAC1E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,qBAAyC,eAAeA,mBAEnE,EACEC,MAAM,EACNC,KAAK,EACLC,MAAM,EACNC,IAAI,EACJC,UAAU,EACVC,MAAM,CAAC,CAAmB,EAC1BC,IAAI,EACJC,MAAMC,OAAO,EACbC,KAAK,EACN;IAED,MAAMC,QAAQ,IAAI,CAACC,QAAQ,CAACX,OAAO;IACnC,MAAMY,gBAAgBlB,yBACpB,IAAI,CAACmB,OAAO,CAACC,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,CAAC,EAAEC,IAAI,EAAE,GAAKA,SAASjB;IAE1D,MAAMkB,UAAU;QACd,GAAI,MAAMpB,YAAY,IAAI,EAAEO,IAAI;QAChCJ;QACAK;IACF;IAEA,IAAIa,oBAAoB;IAExB,IAAIV,OAAO;QACT,MAAMW,cAAczB,wBAAwBc;QAC5CU,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,IAAIlB;IACJ,IAAI,CAACY,mBAAmB;QACtBZ,OAAOX,eAAe;YACpBmB,QAAQ,IAAI,CAACF,OAAO,CAACE,MAAM;YAC3BW,QAAQd;YACRV;YACAK,MAAMC,WAAW;YACjBmB,YAAY;QACd;IACF;IAEA,MAAMC,QAAQ,MAAMlB,MAAMmB,UAAU,CAAC;QACnCC,YAAY9B;QACZE;QACAW,SAAS,IAAI,CAACA,OAAO;QACrBJ;IACF;IAEA,4HAA4H;IAC5H,MAAMsB,oBAAoBZ,qBAAqB,CAACS,SAASL,OAAOC,IAAI,CAACI,OAAOI,MAAM,KAAK;IACvF,MAAMC,oBAAqC;QACzCC,cAAcf;QACdgB,MAAM;QACNC,YAAY;QACZC,QAAQ/B;QACRY;QACAf;QACAC;QACAG;QACAwB;IACF;IAEA,IAAI,CAACA,qBAAqBR,OAAOC,IAAI,CAACI,OAAOI,MAAM,KAAK,KAAK,IAAI,CAACM,iBAAiB,KAAK,MAAM;QAC5F,mHAAmH;QACnH,qHAAqH;QACrH,mHAAmH;QACnH,4BAA4B;QAC5BL,kBAAkBM,gBAAgB,GAAG;YACnC,OAAOC,QAAQC,OAAO,CACpB/B,MAAMgC,cAAc,CAACd,OAAO;gBAC1B,GAAGV,OAAO;gBACVyB,MAAM;oBAAEC,KAAK;gBAAE;YACjB;QAEJ;IACF;IAEA,IAAI3C,SAAS,GAAG;QACdgC,kBAAkBhC,KAAK,GAAGA;QAC1B,qEAAqE;QACrEgC,kBAAkBf,OAAO,CAACjB,KAAK,GAAGA;QAElC,mCAAmC;QACnC,IAAIA,UAAU,GAAG;YACfgC,kBAAkB7B,UAAU,GAAG;QACjC;IACF;IAEA,MAAMyC,SAAS,MAAMnC,MAAMoC,QAAQ,CAAClB,OAAOK;IAC3C,MAAMc,OAAOC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL,OAAOE,IAAI;IAElD,OAAO;QACL,GAAGF,MAAM;QACTE,MAAMA,KAAKI,GAAG,CAAC,CAACC;YACdA,IAAIC,EAAE,GAAGD,IAAIR,GAAG;YAChB,OAAO/C,uBAAuBuD;QAChC;IACF;AACF,EAAC"}
package/dist/findOne.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import type { FindOne } from 'payload/database';
1
+ import type { FindOne } from 'payload';
2
2
  export declare const findOne: FindOne;
3
3
  //# sourceMappingURL=findOne.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"findOne.d.ts","sourceRoot":"","sources":["../src/findOne.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAS/C,eAAO,MAAM,OAAO,EAAE,OA6BrB,CAAA"}
1
+ {"version":3,"file":"findOne.d.ts","sourceRoot":"","sources":["../src/findOne.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAY,OAAO,EAAkB,MAAM,SAAS,CAAA;AAOhE,eAAO,MAAM,OAAO,EAAE,OA6BrB,CAAA"}
package/dist/findOne.js CHANGED
@@ -3,7 +3,7 @@ import { withSession } from './withSession.js';
3
3
  export const findOne = async function findOne({ collection, locale, req = {}, where }) {
4
4
  const Model = this.collections[collection];
5
5
  const options = {
6
- ...withSession(this, req.transactionID),
6
+ ...await withSession(this, req),
7
7
  lean: true
8
8
  };
9
9
  const query = await Model.buildQuery({
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/findOne.ts"],"sourcesContent":["import type { MongooseQueryOptions } from 'mongoose'\nimport type { FindOne } from 'payload/database'\nimport type { PayloadRequestWithData } 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 findOne: FindOne = async function findOne(\n this: MongooseAdapter,\n { collection, locale, req = {} as PayloadRequestWithData, where },\n) {\n const Model = this.collections[collection]\n const options: MongooseQueryOptions = {\n ...withSession(this, req.transactionID),\n lean: true,\n }\n\n const query = await Model.buildQuery({\n locale,\n payload: this.payload,\n where,\n })\n\n const doc = await Model.findOne(query, {}, options)\n\n if (!doc) {\n return null\n }\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","findOne","collection","locale","req","where","Model","collections","options","transactionID","lean","query","buildQuery","payload","doc","result","JSON","parse","stringify","id","_id"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;","mappings":"AAOA,OAAOA,4BAA4B,wCAAuC;AAC1E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,UAAmB,eAAeA,QAE7C,EAAEC,UAAU,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAA2B,EAAEC,KAAK,EAAE;IAEjE,MAAMC,QAAQ,IAAI,CAACC,WAAW,CAACL,WAAW;IAC1C,MAAMM,UAAgC;QACpC,GAAGR,YAAY,IAAI,EAAEI,IAAIK,aAAa,CAAC;QACvCC,MAAM;IACR;IAEA,MAAMC,QAAQ,MAAML,MAAMM,UAAU,CAAC;QACnCT;QACAU,SAAS,IAAI,CAACA,OAAO;QACrBR;IACF;IAEA,MAAMS,MAAM,MAAMR,MAAML,OAAO,CAACU,OAAO,CAAC,GAAGH;IAE3C,IAAI,CAACM,KAAK;QACR,OAAO;IACT;IAEA,IAAIC,SAAmBC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACJ;IAEjD,uBAAuB;IACvBC,OAAOI,EAAE,GAAGJ,OAAOK,GAAG;IACtBL,SAAShB,uBAAuBgB;IAEhC,OAAOA;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/findOne.ts"],"sourcesContent":["import type { MongooseQueryOptions } from 'mongoose'\nimport type { Document, FindOne, PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport sanitizeInternalFields from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const findOne: FindOne = async function findOne(\n this: MongooseAdapter,\n { collection, locale, req = {} as PayloadRequest, where },\n) {\n const Model = this.collections[collection]\n const options: MongooseQueryOptions = {\n ...(await withSession(this, req)),\n lean: true,\n }\n\n const query = await Model.buildQuery({\n locale,\n payload: this.payload,\n where,\n })\n\n const doc = await Model.findOne(query, {}, options)\n\n if (!doc) {\n return null\n }\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","findOne","collection","locale","req","where","Model","collections","options","lean","query","buildQuery","payload","doc","result","JSON","parse","stringify","id","_id"],"mappings":"AAKA,OAAOA,4BAA4B,wCAAuC;AAC1E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,UAAmB,eAAeA,QAE7C,EAAEC,UAAU,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAAmB,EAAEC,KAAK,EAAE;IAEzD,MAAMC,QAAQ,IAAI,CAACC,WAAW,CAACL,WAAW;IAC1C,MAAMM,UAAgC;QACpC,GAAI,MAAMR,YAAY,IAAI,EAAEI,IAAI;QAChCK,MAAM;IACR;IAEA,MAAMC,QAAQ,MAAMJ,MAAMK,UAAU,CAAC;QACnCR;QACAS,SAAS,IAAI,CAACA,OAAO;QACrBP;IACF;IAEA,MAAMQ,MAAM,MAAMP,MAAML,OAAO,CAACS,OAAO,CAAC,GAAGF;IAE3C,IAAI,CAACK,KAAK;QACR,OAAO;IACT;IAEA,IAAIC,SAAmBC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACJ;IAEjD,uBAAuB;IACvBC,OAAOI,EAAE,GAAGJ,OAAOK,GAAG;IACtBL,SAASf,uBAAuBe;IAEhC,OAAOA;AACT,EAAC"}
@@ -1,3 +1,3 @@
1
- import type { FindVersions } from 'payload/database';
1
+ import type { FindVersions } from 'payload';
2
2
  export declare const findVersions: FindVersions;
3
3
  //# sourceMappingURL=findVersions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"findVersions.d.ts","sourceRoot":"","sources":["../src/findVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAWpD,eAAO,MAAM,YAAY,EAAE,YAiG1B,CAAA"}
1
+ {"version":3,"file":"findVersions.d.ts","sourceRoot":"","sources":["../src/findVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAkB,MAAM,SAAS,CAAA;AAU3D,eAAO,MAAM,YAAY,EAAE,YAgG1B,CAAA"}
@@ -1,4 +1,4 @@
1
- import { flattenWhereToOperators } from 'payload/database';
1
+ import { flattenWhereToOperators } from 'payload';
2
2
  import { buildSortParam } from './queries/buildSortParam.js';
3
3
  import sanitizeInternalFields from './utilities/sanitizeInternalFields.js';
4
4
  import { withSession } from './withSession.js';
@@ -6,7 +6,7 @@ export const findVersions = async function findVersions({ collection, limit, loc
6
6
  const Model = this.versions[collection];
7
7
  const collectionConfig = this.payload.collections[collection].config;
8
8
  const options = {
9
- ...withSession(this, req.transactionID),
9
+ ...await withSession(this, req),
10
10
  limit,
11
11
  skip
12
12
  };
@@ -71,7 +71,6 @@ export const findVersions = async function findVersions({ collection, limit, loc
71
71
  return {
72
72
  ...result,
73
73
  docs: docs.map((doc)=>{
74
- // eslint-disable-next-line no-param-reassign
75
74
  doc.id = doc._id;
76
75
  return sanitizeInternalFields(doc);
77
76
  })
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/findVersions.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { FindVersions } from 'payload/database'\nimport type { PayloadRequestWithData } from 'payload/types'\n\nimport { flattenWhereToOperators } from 'payload/database'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport sanitizeInternalFields from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const findVersions: FindVersions = async function findVersions(\n this: MongooseAdapter,\n {\n collection,\n limit,\n locale,\n page,\n pagination,\n req = {} as PayloadRequestWithData,\n skip,\n sort: sortArg,\n where,\n },\n) {\n const Model = this.versions[collection]\n const collectionConfig = this.payload.collections[collection].config\n const options = {\n ...withSession(this, req.transactionID),\n limit,\n skip,\n }\n\n let hasNearConstraint = false\n\n if (where) {\n const constraints = flattenWhereToOperators(where)\n hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n }\n\n let sort\n if (!hasNearConstraint) {\n sort = buildSortParam({\n config: this.payload.config,\n fields: collectionConfig.fields,\n locale,\n sort: sortArg || '-updatedAt',\n timestamps: true,\n })\n }\n\n const query = await Model.buildQuery({\n locale,\n payload: this.payload,\n where,\n })\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0\n const paginationOptions: PaginateOptions = {\n forceCountFn: hasNearConstraint,\n lean: true,\n leanWithId: true,\n limit,\n options,\n page,\n pagination,\n sort,\n useEstimatedCount,\n }\n\n if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n paginationOptions.useCustomCountFn = () => {\n return Promise.resolve(\n Model.countDocuments(query, {\n ...options,\n hint: { _id: 1 },\n }),\n )\n }\n }\n\n if (limit >= 0) {\n paginationOptions.limit = limit\n // limit must also be set here, it's ignored when pagination is false\n paginationOptions.options.limit = limit\n\n // Disable pagination if limit is 0\n if (limit === 0) {\n paginationOptions.pagination = false\n }\n }\n\n const result = await Model.paginate(query, paginationOptions)\n const docs = JSON.parse(JSON.stringify(result.docs))\n\n return {\n ...result,\n docs: docs.map((doc) => {\n // eslint-disable-next-line no-param-reassign\n doc.id = doc._id\n return sanitizeInternalFields(doc)\n }),\n }\n}\n"],"names":["flattenWhereToOperators","buildSortParam","sanitizeInternalFields","withSession","findVersions","collection","limit","locale","page","pagination","req","skip","sort","sortArg","where","Model","versions","collectionConfig","payload","collections","config","options","transactionID","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","timestamps","query","buildQuery","useEstimatedCount","length","paginationOptions","forceCountFn","lean","leanWithId","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","paginate","docs","JSON","parse","stringify","map","doc","id"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAIA,SAASA,uBAAuB,QAAQ,mBAAkB;AAI1D,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,OAAOC,4BAA4B,wCAAuC;AAC1E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,eAA6B,eAAeA,aAEvD,EACEC,UAAU,EACVC,KAAK,EACLC,MAAM,EACNC,IAAI,EACJC,UAAU,EACVC,MAAM,CAAC,CAA2B,EAClCC,IAAI,EACJC,MAAMC,OAAO,EACbC,KAAK,EACN;IAED,MAAMC,QAAQ,IAAI,CAACC,QAAQ,CAACX,WAAW;IACvC,MAAMY,mBAAmB,IAAI,CAACC,OAAO,CAACC,WAAW,CAACd,WAAW,CAACe,MAAM;IACpE,MAAMC,UAAU;QACd,GAAGlB,YAAY,IAAI,EAAEO,IAAIY,aAAa,CAAC;QACvChB;QACAK;IACF;IAEA,IAAIY,oBAAoB;IAExB,IAAIT,OAAO;QACT,MAAMU,cAAcxB,wBAAwBc;QAC5CS,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,IAAIjB;IACJ,IAAI,CAACW,mBAAmB;QACtBX,OAAOX,eAAe;YACpBmB,QAAQ,IAAI,CAACF,OAAO,CAACE,MAAM;YAC3BU,QAAQb,iBAAiBa,MAAM;YAC/BvB;YACAK,MAAMC,WAAW;YACjBkB,YAAY;QACd;IACF;IAEA,MAAMC,QAAQ,MAAMjB,MAAMkB,UAAU,CAAC;QACnC1B;QACAW,SAAS,IAAI,CAACA,OAAO;QACrBJ;IACF;IAEA,4HAA4H;IAC5H,MAAMoB,oBAAoBX,qBAAqB,CAACS,SAASL,OAAOC,IAAI,CAACI,OAAOG,MAAM,KAAK;IACvF,MAAMC,oBAAqC;QACzCC,cAAcd;QACde,MAAM;QACNC,YAAY;QACZjC;QACAe;QACAb;QACAC;QACAG;QACAsB;IACF;IAEA,IAAI,CAACA,qBAAqBP,OAAOC,IAAI,CAACI,OAAOG,MAAM,KAAK,KAAK,IAAI,CAACK,iBAAiB,KAAK,MAAM;QAC5F,mHAAmH;QACnH,qHAAqH;QACrH,mHAAmH;QACnH,4BAA4B;QAC5BJ,kBAAkBK,gBAAgB,GAAG;YACnC,OAAOC,QAAQC,OAAO,CACpB5B,MAAM6B,cAAc,CAACZ,OAAO;gBAC1B,GAAGX,OAAO;gBACVwB,MAAM;oBAAEC,KAAK;gBAAE;YACjB;QAEJ;IACF;IAEA,IAAIxC,SAAS,GAAG;QACd8B,kBAAkB9B,KAAK,GAAGA;QAC1B,qEAAqE;QACrE8B,kBAAkBf,OAAO,CAACf,KAAK,GAAGA;QAElC,mCAAmC;QACnC,IAAIA,UAAU,GAAG;YACf8B,kBAAkB3B,UAAU,GAAG;QACjC;IACF;IAEA,MAAMsC,SAAS,MAAMhC,MAAMiC,QAAQ,CAAChB,OAAOI;IAC3C,MAAMa,OAAOC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL,OAAOE,IAAI;IAElD,OAAO;QACL,GAAGF,MAAM;QACTE,MAAMA,KAAKI,GAAG,CAAC,CAACC;YACd,6CAA6C;YAC7CA,IAAIC,EAAE,GAAGD,IAAIR,GAAG;YAChB,OAAO5C,uBAAuBoD;QAChC;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../src/findVersions.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { FindVersions, PayloadRequest } from 'payload'\n\nimport { flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport sanitizeInternalFields from './utilities/sanitizeInternalFields.js'\nimport { withSession } from './withSession.js'\n\nexport const findVersions: FindVersions = async function findVersions(\n this: MongooseAdapter,\n {\n collection,\n limit,\n locale,\n page,\n pagination,\n req = {} as PayloadRequest,\n skip,\n sort: sortArg,\n where,\n },\n) {\n const Model = this.versions[collection]\n const collectionConfig = this.payload.collections[collection].config\n const options = {\n ...(await withSession(this, req)),\n limit,\n skip,\n }\n\n let hasNearConstraint = false\n\n if (where) {\n const constraints = flattenWhereToOperators(where)\n hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n }\n\n let sort\n if (!hasNearConstraint) {\n sort = buildSortParam({\n config: this.payload.config,\n fields: collectionConfig.fields,\n locale,\n sort: sortArg || '-updatedAt',\n timestamps: true,\n })\n }\n\n const query = await Model.buildQuery({\n locale,\n payload: this.payload,\n where,\n })\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0\n const paginationOptions: PaginateOptions = {\n forceCountFn: hasNearConstraint,\n lean: true,\n leanWithId: true,\n limit,\n options,\n page,\n pagination,\n sort,\n useEstimatedCount,\n }\n\n if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n paginationOptions.useCustomCountFn = () => {\n return Promise.resolve(\n Model.countDocuments(query, {\n ...options,\n hint: { _id: 1 },\n }),\n )\n }\n }\n\n if (limit >= 0) {\n paginationOptions.limit = limit\n // limit must also be set here, it's ignored when pagination is false\n paginationOptions.options.limit = limit\n\n // Disable pagination if limit is 0\n if (limit === 0) {\n paginationOptions.pagination = false\n }\n }\n\n const result = await Model.paginate(query, paginationOptions)\n const docs = JSON.parse(JSON.stringify(result.docs))\n\n return {\n ...result,\n docs: docs.map((doc) => {\n doc.id = doc._id\n return sanitizeInternalFields(doc)\n }),\n }\n}\n"],"names":["flattenWhereToOperators","buildSortParam","sanitizeInternalFields","withSession","findVersions","collection","limit","locale","page","pagination","req","skip","sort","sortArg","where","Model","versions","collectionConfig","payload","collections","config","options","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","timestamps","query","buildQuery","useEstimatedCount","length","paginationOptions","forceCountFn","lean","leanWithId","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","paginate","docs","JSON","parse","stringify","map","doc","id"],"mappings":"AAGA,SAASA,uBAAuB,QAAQ,UAAS;AAIjD,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,OAAOC,4BAA4B,wCAAuC;AAC1E,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,MAAMC,eAA6B,eAAeA,aAEvD,EACEC,UAAU,EACVC,KAAK,EACLC,MAAM,EACNC,IAAI,EACJC,UAAU,EACVC,MAAM,CAAC,CAAmB,EAC1BC,IAAI,EACJC,MAAMC,OAAO,EACbC,KAAK,EACN;IAED,MAAMC,QAAQ,IAAI,CAACC,QAAQ,CAACX,WAAW;IACvC,MAAMY,mBAAmB,IAAI,CAACC,OAAO,CAACC,WAAW,CAACd,WAAW,CAACe,MAAM;IACpE,MAAMC,UAAU;QACd,GAAI,MAAMlB,YAAY,IAAI,EAAEO,IAAI;QAChCJ;QACAK;IACF;IAEA,IAAIW,oBAAoB;IAExB,IAAIR,OAAO;QACT,MAAMS,cAAcvB,wBAAwBc;QAC5CQ,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,IAAIhB;IACJ,IAAI,CAACU,mBAAmB;QACtBV,OAAOX,eAAe;YACpBmB,QAAQ,IAAI,CAACF,OAAO,CAACE,MAAM;YAC3BS,QAAQZ,iBAAiBY,MAAM;YAC/BtB;YACAK,MAAMC,WAAW;YACjBiB,YAAY;QACd;IACF;IAEA,MAAMC,QAAQ,MAAMhB,MAAMiB,UAAU,CAAC;QACnCzB;QACAW,SAAS,IAAI,CAACA,OAAO;QACrBJ;IACF;IAEA,4HAA4H;IAC5H,MAAMmB,oBAAoBX,qBAAqB,CAACS,SAASL,OAAOC,IAAI,CAACI,OAAOG,MAAM,KAAK;IACvF,MAAMC,oBAAqC;QACzCC,cAAcd;QACde,MAAM;QACNC,YAAY;QACZhC;QACAe;QACAb;QACAC;QACAG;QACAqB;IACF;IAEA,IAAI,CAACA,qBAAqBP,OAAOC,IAAI,CAACI,OAAOG,MAAM,KAAK,KAAK,IAAI,CAACK,iBAAiB,KAAK,MAAM;QAC5F,mHAAmH;QACnH,qHAAqH;QACrH,mHAAmH;QACnH,4BAA4B;QAC5BJ,kBAAkBK,gBAAgB,GAAG;YACnC,OAAOC,QAAQC,OAAO,CACpB3B,MAAM4B,cAAc,CAACZ,OAAO;gBAC1B,GAAGV,OAAO;gBACVuB,MAAM;oBAAEC,KAAK;gBAAE;YACjB;QAEJ;IACF;IAEA,IAAIvC,SAAS,GAAG;QACd6B,kBAAkB7B,KAAK,GAAGA;QAC1B,qEAAqE;QACrE6B,kBAAkBd,OAAO,CAACf,KAAK,GAAGA;QAElC,mCAAmC;QACnC,IAAIA,UAAU,GAAG;YACf6B,kBAAkB1B,UAAU,GAAG;QACjC;IACF;IAEA,MAAMqC,SAAS,MAAM/B,MAAMgC,QAAQ,CAAChB,OAAOI;IAC3C,MAAMa,OAAOC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACL,OAAOE,IAAI;IAElD,OAAO;QACL,GAAGF,MAAM;QACTE,MAAMA,KAAKI,GAAG,CAAC,CAACC;YACdA,IAAIC,EAAE,GAAGD,IAAIR,GAAG;YAChB,OAAO3C,uBAAuBmD;QAChC;IACF;AACF,EAAC"}
package/dist/index.d.ts CHANGED
@@ -1,42 +1,17 @@
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 { TransactionOptions } from 'mongodb';
27
2
  import type { MongoMemoryReplSet } from 'mongodb-memory-server';
28
3
  import type { ClientSession, ConnectOptions, Connection } from 'mongoose';
29
- import type { BaseDatabaseAdapter, DatabaseAdapterObj } from 'payload/database';
4
+ import type { BaseDatabaseAdapter, DatabaseAdapterObj } from 'payload';
30
5
  import type { CollectionModel, GlobalModel } from './types.js';
31
6
  export type { MigrateDownArgs, MigrateUpArgs } from './types.js';
32
7
  export interface Args {
33
8
  /** Set to false to disable auto-pluralization of collection names, Defaults to true */
34
9
  autoPluralization?: boolean;
35
10
  /** Extra configuration options */
36
- connectOptions?: ConnectOptions & {
11
+ connectOptions?: {
37
12
  /** Set false to disable $facet aggregation in non-supporting databases, Defaults to true */
38
13
  useFacet?: boolean;
39
- };
14
+ } & ConnectOptions;
40
15
  /** 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 */
41
16
  disableIndexHints?: boolean;
42
17
  migrationDir?: string;
@@ -48,7 +23,7 @@ export interface Args {
48
23
  /** The URL to connect to MongoDB or false to start payload and prevent connecting */
49
24
  url: false | string;
50
25
  }
51
- export type MongooseAdapter = BaseDatabaseAdapter & Args & {
26
+ export type MongooseAdapter = {
52
27
  collections: {
53
28
  [slug: string]: CollectionModel;
54
29
  };
@@ -59,7 +34,7 @@ export type MongooseAdapter = BaseDatabaseAdapter & Args & {
59
34
  versions: {
60
35
  [slug: string]: CollectionModel;
61
36
  };
62
- };
37
+ } & Args & BaseDatabaseAdapter;
63
38
  declare module 'payload' {
64
39
  interface DatabaseAdapter extends Omit<BaseDatabaseAdapter, 'sessions'>, Omit<Args, 'migrationDir'> {
65
40
  collections: {
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AACjD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAC/D,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAEzE,OAAO,KAAK,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAO/E,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AA6B9D,YAAY,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAEhE,MAAM,WAAW,IAAI;IACnB,uFAAuF;IACvF,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B,kCAAkC;IAClC,cAAc,CAAC,EAAE,cAAc,GAAG;QAChC,4FAA4F;QAC5F,QAAQ,CAAC,EAAE,OAAO,CAAA;KACnB,CAAA;IACD,gOAAgO;IAChO,iBAAiB,CAAC,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E,aAAa,CAAC,CAAA;IAChD,QAAQ,EAAE;QACR,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,CAAA;KAChC,CAAA;CACF,GAAG,IAAI,GACN,mBAAmB,CAAA;AAErB,OAAO,QAAQ,SAAS,CAAC;IACvB,UAAiB,eACf,SAAQ,IAAI,CAAC,mBAAmB,EAAE,UAAU,CAAC,EAC3C,IAAI,CAAC,IAAI,EAAE,cAAc,CAAC;QAC5B,WAAW,EAAE;YACX,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,CAAA;SAChC,CAAA;QACD,UAAU,EAAE,UAAU,CAAA;QACtB,OAAO,EAAE,WAAW,CAAA;QACpB,iBAAiB,EAAE,kBAAkB,CAAA;QACrC,QAAQ,EAAE,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,aAAa,CAAC,CAAA;QAChD,kBAAkB,EAAE,kBAAkB,CAAA;QACtC,QAAQ,EAAE;YACR,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,CAAA;SAChC,CAAA;KACF;CACF;AAED,wBAAgB,eAAe,CAAC,EAC9B,iBAAwB,EACxB,cAAc,EACd,iBAAyB,EACzB,YAAY,EAAE,eAAe,EAC7B,iBAAiB,EACjB,kBAAuB,EACvB,GAAG,GACJ,EAAE,IAAI,GAAG,kBAAkB,CAyD3B"}
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import fs from 'fs';
2
2
  import mongoose from 'mongoose';
3
3
  import path from 'path';
4
- import { createDatabaseAdapter } from 'payload/database';
4
+ import { createDatabaseAdapter } from 'payload';
5
5
  import { connect } from './connect.js';
6
6
  import { count } from './count.js';
7
7
  import { create } from './create.js';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { TransactionOptions } from 'mongodb'\nimport type { MongoMemoryReplSet } from 'mongodb-memory-server'\nimport type { ClientSession, ConnectOptions, Connection } from 'mongoose'\nimport type { Payload } from 'payload'\nimport type { BaseDatabaseAdapter, DatabaseAdapterObj } from 'payload/database'\n\nimport fs from 'fs'\nimport mongoose from 'mongoose'\nimport path from 'path'\nimport { createDatabaseAdapter } from 'payload/database'\n\nimport type { CollectionModel, GlobalModel } from './types.js'\n\nimport { connect } from './connect.js'\nimport { count } from './count.js'\nimport { create } from './create.js'\nimport { createGlobal } from './createGlobal.js'\nimport { createGlobalVersion } from './createGlobalVersion.js'\nimport { createMigration } from './createMigration.js'\nimport { createVersion } from './createVersion.js'\nimport { deleteMany } from './deleteMany.js'\nimport { deleteOne } from './deleteOne.js'\nimport { deleteVersions } from './deleteVersions.js'\nimport { destroy } from './destroy.js'\nimport { find } from './find.js'\nimport { findGlobal } from './findGlobal.js'\nimport { findGlobalVersions } from './findGlobalVersions.js'\nimport { findOne } from './findOne.js'\nimport { findVersions } from './findVersions.js'\nimport { init } from './init.js'\nimport { migrateFresh } from './migrateFresh.js'\nimport { queryDrafts } from './queryDrafts.js'\nimport { beginTransaction } from './transactions/beginTransaction.js'\nimport { commitTransaction } from './transactions/commitTransaction.js'\nimport { rollbackTransaction } from './transactions/rollbackTransaction.js'\nimport { updateGlobal } from './updateGlobal.js'\nimport { updateGlobalVersion } from './updateGlobalVersion.js'\nimport { updateOne } from './updateOne.js'\nimport { updateVersion } from './updateVersion.js'\n\nexport type { MigrateDownArgs, MigrateUpArgs } from './types.js'\n\nexport interface Args {\n /** Set to false to disable auto-pluralization of collection names, Defaults to true */\n autoPluralization?: boolean\n /** Extra configuration options */\n connectOptions?: ConnectOptions & {\n /** Set false to disable $facet aggregation in non-supporting databases, Defaults to true */\n useFacet?: boolean\n }\n /** 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 */\n disableIndexHints?: boolean\n migrationDir?: string\n /**\n * typed as any to avoid dependency\n */\n mongoMemoryServer?: MongoMemoryReplSet\n transactionOptions?: TransactionOptions | false\n /** The URL to connect to MongoDB or false to start payload and prevent connecting */\n url: false | string\n}\n\nexport type MongooseAdapter = BaseDatabaseAdapter &\n Args & {\n collections: {\n [slug: string]: CollectionModel\n }\n connection: Connection\n globals: GlobalModel\n mongoMemoryServer: MongoMemoryReplSet\n sessions: Record<number | string, ClientSession>\n versions: {\n [slug: string]: CollectionModel\n }\n }\n\ndeclare module 'payload' {\n export interface DatabaseAdapter\n extends Omit<BaseDatabaseAdapter, 'sessions'>,\n Omit<Args, 'migrationDir'> {\n collections: {\n [slug: string]: CollectionModel\n }\n connection: Connection\n globals: GlobalModel\n mongoMemoryServer: MongoMemoryReplSet\n sessions: Record<number | string, ClientSession>\n transactionOptions: TransactionOptions\n versions: {\n [slug: string]: CollectionModel\n }\n }\n}\n\nexport function mongooseAdapter({\n autoPluralization = true,\n connectOptions,\n disableIndexHints = false,\n migrationDir: migrationDirArg,\n mongoMemoryServer,\n transactionOptions = {},\n url,\n}: Args): DatabaseAdapterObj {\n function adapter({ payload }: { payload: Payload }) {\n const migrationDir = findMigrationDir(migrationDirArg)\n mongoose.set('strictQuery', false)\n\n return createDatabaseAdapter<MongooseAdapter>({\n name: 'mongoose',\n\n // Mongoose-specific\n autoPluralization,\n collections: {},\n connectOptions: connectOptions || {},\n connection: undefined,\n count,\n disableIndexHints,\n globals: undefined,\n mongoMemoryServer,\n sessions: {},\n transactionOptions: transactionOptions === false ? undefined : transactionOptions,\n url,\n versions: {},\n // DatabaseAdapter\n beginTransaction: transactionOptions ? beginTransaction : undefined,\n commitTransaction,\n connect,\n create,\n createGlobal,\n createGlobalVersion,\n createMigration,\n createVersion,\n defaultIDType: 'text',\n deleteMany,\n deleteOne,\n deleteVersions,\n destroy,\n find,\n findGlobal,\n findGlobalVersions,\n findOne,\n findVersions,\n init,\n migrateFresh,\n migrationDir,\n payload,\n queryDrafts,\n rollbackTransaction,\n updateGlobal,\n updateGlobalVersion,\n updateOne,\n updateVersion,\n })\n }\n\n return {\n defaultIDType: 'text',\n init: adapter,\n }\n}\n\n/**\n * Attempt to find migrations directory.\n *\n * Checks for the following directories in order:\n * - `migrationDir` argument from Payload config\n * - `src/migrations`\n * - `dist/migrations`\n * - `migrations`\n *\n * Defaults to `src/migrations`\n *\n * @param migrationDir\n * @returns\n */\nfunction findMigrationDir(migrationDir?: string): string {\n const cwd = process.cwd()\n const srcDir = path.resolve(cwd, 'src/migrations')\n const distDir = path.resolve(cwd, 'dist/migrations')\n const relativeMigrations = path.resolve(cwd, 'migrations')\n\n // Use arg if provided\n if (migrationDir) return migrationDir\n\n // Check other common locations\n if (fs.existsSync(srcDir)) {\n return srcDir\n }\n\n if (fs.existsSync(distDir)) {\n return distDir\n }\n\n if (fs.existsSync(relativeMigrations)) {\n return relativeMigrations\n }\n\n return srcDir\n}\n"],"names":["fs","mongoose","path","createDatabaseAdapter","connect","count","create","createGlobal","createGlobalVersion","createMigration","createVersion","deleteMany","deleteOne","deleteVersions","destroy","find","findGlobal","findGlobalVersions","findOne","findVersions","init","migrateFresh","queryDrafts","beginTransaction","commitTransaction","rollbackTransaction","updateGlobal","updateGlobalVersion","updateOne","updateVersion","mongooseAdapter","autoPluralization","connectOptions","disableIndexHints","migrationDir","migrationDirArg","mongoMemoryServer","transactionOptions","url","adapter","payload","findMigrationDir","set","name","collections","connection","undefined","globals","sessions","versions","defaultIDType","cwd","process","srcDir","resolve","distDir","relativeMigrations","existsSync"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAMA,OAAOA,QAAQ,KAAI;AACnB,OAAOC,cAAc,WAAU;AAC/B,OAAOC,UAAU,OAAM;AACvB,SAASC,qBAAqB,QAAQ,mBAAkB;AAIxD,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,KAAK,QAAQ,aAAY;AAClC,SAASC,MAAM,QAAQ,cAAa;AACpC,SAASC,YAAY,QAAQ,oBAAmB;AACh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AAYT;YAC/DC;YACAW,UAAU,CAAC;YACX,kBAAkB;YAClB1B,kBAAkBc,qBAAqBd,mBAAmBuB;YAC1DtB;YACApB;YACAE;YACAC;YACAC;YACAC;YACAC;YACAwC,eAAe;YACfvC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAa;YACAM;YACAlB;YACAG;YACAC;YACAC;YACAC;YACAC;QACF;IACF;IAEA,OAAO;QACLqB,eAAe;QACf9B,MAAMmB;IACR;AACF;AAEA;;;;;;;;;;;;;CAaC,GACD,SAASE,iBAAiBP,YAAqB;IAC7C,MAAMiB,MAAMC,QAAQD,GAAG;IACvB,MAAME,SAASnD,KAAKoD,OAAO,CAACH,KAAK;IACjC,MAAMI,UAAUrD,KAAKoD,OAAO,CAACH,KAAK;IAClC,MAAMK,qBAAqBtD,KAAKoD,OAAO,CAACH,KAAK;IAE7C,sBAAsB;IACtB,IAAIjB,cAAc,OAAOA;IAEzB,+BAA+B;IAC/B,IAAIlC,GAAGyD,UAAU,CAACJ,SAAS;QACzB,OAAOA;IACT;IAEA,IAAIrD,GAAGyD,UAAU,CAACF,UAAU;QAC1B,OAAOA;IACT;IAEA,IAAIvD,GAAGyD,UAAU,CAACD,qBAAqB;QACrC,OAAOA;IACT;IAEA,OAAOH;AACT"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { TransactionOptions } from 'mongodb'\nimport type { MongoMemoryReplSet } from 'mongodb-memory-server'\nimport type { ClientSession, ConnectOptions, Connection } from 'mongoose'\nimport type { BaseDatabaseAdapter, DatabaseAdapterObj, Payload } from 'payload'\n\nimport fs from 'fs'\nimport mongoose from 'mongoose'\nimport path from 'path'\nimport { createDatabaseAdapter } from 'payload'\n\nimport type { CollectionModel, GlobalModel } from './types.js'\n\nimport { connect } from './connect.js'\nimport { count } from './count.js'\nimport { create } from './create.js'\nimport { createGlobal } from './createGlobal.js'\nimport { createGlobalVersion } from './createGlobalVersion.js'\nimport { createMigration } from './createMigration.js'\nimport { createVersion } from './createVersion.js'\nimport { deleteMany } from './deleteMany.js'\nimport { deleteOne } from './deleteOne.js'\nimport { deleteVersions } from './deleteVersions.js'\nimport { destroy } from './destroy.js'\nimport { find } from './find.js'\nimport { findGlobal } from './findGlobal.js'\nimport { findGlobalVersions } from './findGlobalVersions.js'\nimport { findOne } from './findOne.js'\nimport { findVersions } from './findVersions.js'\nimport { init } from './init.js'\nimport { migrateFresh } from './migrateFresh.js'\nimport { queryDrafts } from './queryDrafts.js'\nimport { beginTransaction } from './transactions/beginTransaction.js'\nimport { commitTransaction } from './transactions/commitTransaction.js'\nimport { rollbackTransaction } from './transactions/rollbackTransaction.js'\nimport { updateGlobal } from './updateGlobal.js'\nimport { updateGlobalVersion } from './updateGlobalVersion.js'\nimport { updateOne } from './updateOne.js'\nimport { updateVersion } from './updateVersion.js'\n\nexport type { MigrateDownArgs, MigrateUpArgs } from './types.js'\n\nexport interface Args {\n /** Set to false to disable auto-pluralization of collection names, Defaults to true */\n autoPluralization?: boolean\n /** Extra configuration options */\n connectOptions?: {\n /** Set false to disable $facet aggregation in non-supporting databases, Defaults to true */\n useFacet?: boolean\n } & ConnectOptions\n /** 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 */\n disableIndexHints?: boolean\n migrationDir?: string\n /**\n * typed as any to avoid dependency\n */\n mongoMemoryServer?: MongoMemoryReplSet\n transactionOptions?: TransactionOptions | false\n /** The URL to connect to MongoDB or false to start payload and prevent connecting */\n url: false | string\n}\n\nexport type MongooseAdapter = {\n collections: {\n [slug: string]: CollectionModel\n }\n connection: Connection\n globals: GlobalModel\n mongoMemoryServer: MongoMemoryReplSet\n sessions: Record<number | string, ClientSession>\n versions: {\n [slug: string]: CollectionModel\n }\n} & Args &\n BaseDatabaseAdapter\n\ndeclare module 'payload' {\n export interface DatabaseAdapter\n extends Omit<BaseDatabaseAdapter, 'sessions'>,\n Omit<Args, 'migrationDir'> {\n collections: {\n [slug: string]: CollectionModel\n }\n connection: Connection\n globals: GlobalModel\n mongoMemoryServer: MongoMemoryReplSet\n sessions: Record<number | string, ClientSession>\n transactionOptions: TransactionOptions\n versions: {\n [slug: string]: CollectionModel\n }\n }\n}\n\nexport function mongooseAdapter({\n autoPluralization = true,\n connectOptions,\n disableIndexHints = false,\n migrationDir: migrationDirArg,\n mongoMemoryServer,\n transactionOptions = {},\n url,\n}: Args): DatabaseAdapterObj {\n function adapter({ payload }: { payload: Payload }) {\n const migrationDir = findMigrationDir(migrationDirArg)\n mongoose.set('strictQuery', false)\n\n return createDatabaseAdapter<MongooseAdapter>({\n name: 'mongoose',\n\n // Mongoose-specific\n autoPluralization,\n collections: {},\n connectOptions: connectOptions || {},\n connection: undefined,\n count,\n disableIndexHints,\n globals: undefined,\n mongoMemoryServer,\n sessions: {},\n transactionOptions: transactionOptions === false ? undefined : transactionOptions,\n url,\n versions: {},\n // DatabaseAdapter\n beginTransaction: transactionOptions ? beginTransaction : undefined,\n commitTransaction,\n connect,\n create,\n createGlobal,\n createGlobalVersion,\n createMigration,\n createVersion,\n defaultIDType: 'text',\n deleteMany,\n deleteOne,\n deleteVersions,\n destroy,\n find,\n findGlobal,\n findGlobalVersions,\n findOne,\n findVersions,\n init,\n migrateFresh,\n migrationDir,\n payload,\n queryDrafts,\n rollbackTransaction,\n updateGlobal,\n updateGlobalVersion,\n updateOne,\n updateVersion,\n })\n }\n\n return {\n defaultIDType: 'text',\n init: adapter,\n }\n}\n\n/**\n * Attempt to find migrations directory.\n *\n * Checks for the following directories in order:\n * - `migrationDir` argument from Payload config\n * - `src/migrations`\n * - `dist/migrations`\n * - `migrations`\n *\n * Defaults to `src/migrations`\n *\n * @param migrationDir\n * @returns\n */\nfunction findMigrationDir(migrationDir?: string): string {\n const cwd = process.cwd()\n const srcDir = path.resolve(cwd, 'src/migrations')\n const distDir = path.resolve(cwd, 'dist/migrations')\n const relativeMigrations = path.resolve(cwd, 'migrations')\n\n // Use arg if provided\n if (migrationDir) return migrationDir\n\n // Check other common locations\n if (fs.existsSync(srcDir)) {\n return srcDir\n }\n\n if (fs.existsSync(distDir)) {\n return distDir\n }\n\n if (fs.existsSync(relativeMigrations)) {\n return relativeMigrations\n }\n\n return srcDir\n}\n"],"names":["fs","mongoose","path","createDatabaseAdapter","connect","count","create","createGlobal","createGlobalVersion","createMigration","createVersion","deleteMany","deleteOne","deleteVersions","destroy","find","findGlobal","findGlobalVersions","findOne","findVersions","init","migrateFresh","queryDrafts","beginTransaction","commitTransaction","rollbackTransaction","updateGlobal","updateGlobalVersion","updateOne","updateVersion","mongooseAdapter","autoPluralization","connectOptions","disableIndexHints","migrationDir","migrationDirArg","mongoMemoryServer","transactionOptions","url","adapter","payload","findMigrationDir","set","name","collections","connection","undefined","globals","sessions","versions","defaultIDType","cwd","process","srcDir","resolve","distDir","relativeMigrations","existsSync"],"mappings":"AAKA,OAAOA,QAAQ,KAAI;AACnB,OAAOC,cAAc,WAAU;AAC/B,OAAOC,UAAU,OAAM;AACvB,SAASC,qBAAqB,QAAQ,UAAS;AAI/C,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,KAAK,QAAQ,aAAY;AAClC,SAASC,MAAM,QAAQ,cAAa;AACpC,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,SAASC,eAAe,QAAQ,uBAAsB;AACtD,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,UAAU,QAAQ,kBAAiB;AAC5C,SAASC,SAAS,QAAQ,iBAAgB;AAC1C,SAASC,cAAc,QAAQ,sBAAqB;AACpD,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,IAAI,QAAQ,YAAW;AAChC,SAASC,UAAU,QAAQ,kBAAiB;AAC5C,SAASC,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC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,MAAME,SAASnD,KAAKoD,OAAO,CAACH,KAAK;IACjC,MAAMI,UAAUrD,KAAKoD,OAAO,CAACH,KAAK;IAClC,MAAMK,qBAAqBtD,KAAKoD,OAAO,CAACH,KAAK;IAE7C,sBAAsB;IACtB,IAAIjB,cAAc,OAAOA;IAEzB,+BAA+B;IAC/B,IAAIlC,GAAGyD,UAAU,CAACJ,SAAS;QACzB,OAAOA;IACT;IAEA,IAAIrD,GAAGyD,UAAU,CAACF,UAAU;QAC1B,OAAOA;IACT;IAEA,IAAIvD,GAAGyD,UAAU,CAACD,qBAAqB;QACrC,OAAOA;IACT;IAEA,OAAOH;AACT"}
package/dist/init.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import type { Init } from 'payload/database';
1
+ import type { Init } from 'payload';
2
2
  export declare const init: Init;
3
3
  //# sourceMappingURL=init.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAgB5C,eAAO,MAAM,IAAI,EAAE,IA0ElB,CAAA"}
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAA6B,MAAM,SAAS,CAAA;AAe9D,eAAO,MAAM,IAAI,EAAE,IA0ElB,CAAA"}
package/dist/init.js CHANGED
@@ -1,6 +1,6 @@
1
- /* eslint-disable no-param-reassign */ import mongoose from 'mongoose';
1
+ import mongoose from 'mongoose';
2
2
  import paginate from 'mongoose-paginate-v2';
3
- import { buildVersionCollectionFields, buildVersionGlobalFields } from 'payload/versions';
3
+ import { buildVersionCollectionFields, buildVersionGlobalFields } from 'payload';
4
4
  import buildCollectionSchema from './models/buildCollectionSchema.js';
5
5
  import { buildGlobalModel } from './models/buildGlobalModel.js';
6
6
  import buildSchema from './models/buildSchema.js';
package/dist/init.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/init.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport type { PaginateOptions } from 'mongoose'\nimport type { Init } from 'payload/database'\nimport type { SanitizedCollectionConfig } from 'payload/types'\n\nimport mongoose from 'mongoose'\nimport paginate from 'mongoose-paginate-v2'\nimport { buildVersionCollectionFields, buildVersionGlobalFields } from 'payload/versions'\n\nimport type { MongooseAdapter } from './index.js'\nimport type { CollectionModel } from './types.js'\n\nimport buildCollectionSchema from './models/buildCollectionSchema.js'\nimport { buildGlobalModel } from './models/buildGlobalModel.js'\nimport buildSchema from './models/buildSchema.js'\nimport getBuildQueryPlugin from './queries/buildQuery.js'\nimport { getDBName } from './utilities/getDBName.js'\n\nexport const init: Init = function init(this: MongooseAdapter) {\n this.payload.config.collections.forEach((collection: SanitizedCollectionConfig) => {\n const schema = buildCollectionSchema(collection, this.payload.config)\n\n if (collection.versions) {\n const versionModelName = getDBName({ config: collection, versions: true })\n\n const versionCollectionFields = buildVersionCollectionFields(collection)\n\n const versionSchema = buildSchema(this.payload.config, versionCollectionFields, {\n disableUnique: true,\n draftsEnabled: true,\n indexSortableFields: this.payload.config.indexSortableFields,\n options: {\n minimize: false,\n timestamps: false,\n },\n })\n\n versionSchema.plugin<any, PaginateOptions>(paginate, { useEstimatedCount: true }).plugin(\n getBuildQueryPlugin({\n collectionSlug: collection.slug,\n versionsFields: versionCollectionFields,\n }),\n )\n\n const model = mongoose.model(\n versionModelName,\n versionSchema,\n this.autoPluralization === true ? undefined : versionModelName,\n ) as CollectionModel\n // this.payload.versions[collection.slug] = model;\n this.versions[collection.slug] = model\n }\n\n const model = mongoose.model(\n getDBName({ config: collection }),\n schema,\n this.autoPluralization === true ? undefined : collection.slug,\n ) as CollectionModel\n this.collections[collection.slug] = model\n })\n\n const model = buildGlobalModel(this.payload.config)\n this.globals = model\n\n this.payload.config.globals.forEach((global) => {\n if (global.versions) {\n const versionModelName = getDBName({ config: global, versions: true })\n\n const versionGlobalFields = buildVersionGlobalFields(global)\n\n const versionSchema = buildSchema(this.payload.config, versionGlobalFields, {\n disableUnique: true,\n draftsEnabled: true,\n indexSortableFields: this.payload.config.indexSortableFields,\n options: {\n minimize: false,\n timestamps: false,\n },\n })\n\n versionSchema\n .plugin<any, PaginateOptions>(paginate, { useEstimatedCount: true })\n .plugin(getBuildQueryPlugin({ versionsFields: versionGlobalFields }))\n\n const versionsModel = mongoose.model(\n versionModelName,\n versionSchema,\n versionModelName,\n ) as CollectionModel\n this.versions[global.slug] = versionsModel\n }\n })\n}\n"],"names":["mongoose","paginate","buildVersionCollectionFields","buildVersionGlobalFields","buildCollectionSchema","buildGlobalModel","buildSchema","getBuildQueryPlugin","getDBName","init","payload","config","collections","forEach","collection","schema","versions","versionModelName","versionCollectionFields","versionSchema","disableUnique","draftsEnabled","indexSortableFields","options","minimize","timestamps","plugin","useEstimatedCount","collectionSlug","slug","versionsFields","model","autoPluralization","undefined","globals","global","versionGlobalFields","versionsModel"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,oCAAoC,GAKpC,OAAOA,cAAc,WAAU;AAC/B,OAAOC,cAAc,uBAAsB;AAC3C,SAASC,4BAA4B,EAAEC,wBAAwB,QAAQ,mBAAkB;AAKzF,OAAOC,2BAA2B,oCAAmC;AACrE,SAASC,gBAAgB,QAAQ,+BAA8B;AAC/D,OAAOC,iBAAiB,0BAAyB;AACjD,OAAOC,yBAAyB,0BAAyB;AACzD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,OAAa,SAASA;IACjC,IAAI,CAACC,OAAO,CAACC,MAAM,CAACC,WAAW,CAACC,OAAO,CAAC,CAACC;QACvC,MAAMC,SAASX,sBAAsBU,YAAY,IAAI,CAACJ,OAAO,CAACC,MAAM;QAEpE,IAAIG,WAAWE,QAAQ,EAAE;YACvB,MAAMC,mBAAmBT,UAAU;gB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C,eAAe;gBACfC,qBAAqB,IAAI,CAACZ,OAAO,CAACC,MAAM,CAACW,mBAAmB;gBAC5DC,SAAS;oBACPC,UAAU;oBACVC,YAAY;gBACd;YACF;YAEAN,cACGO,MAAM,CAAuBzB,UAAU;gBAAE0B,mBAAmB;YAAK,GACjED,MAAM,CAACnB,oBAAoB;gBAAEuB,gBAAgBM;YAAoB;YAEpE,MAAMC,gBAAgBrC,SAAS+B,KAAK,CAClCd,kBACAE,eACAF;YAEF,IAAI,CAACD,QAAQ,CAACmB,OAAON,IAAI,CAAC,GAAGQ;QAC/B;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../src/init.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { Init, SanitizedCollectionConfig } from 'payload'\n\nimport mongoose from 'mongoose'\nimport paginate from 'mongoose-paginate-v2'\nimport { buildVersionCollectionFields, buildVersionGlobalFields } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\nimport type { CollectionModel } from './types.js'\n\nimport buildCollectionSchema from './models/buildCollectionSchema.js'\nimport { buildGlobalModel } from './models/buildGlobalModel.js'\nimport buildSchema from './models/buildSchema.js'\nimport getBuildQueryPlugin from './queries/buildQuery.js'\nimport { getDBName } from './utilities/getDBName.js'\n\nexport const init: Init = function init(this: MongooseAdapter) {\n this.payload.config.collections.forEach((collection: SanitizedCollectionConfig) => {\n const schema = buildCollectionSchema(collection, this.payload.config)\n\n if (collection.versions) {\n const versionModelName = getDBName({ config: collection, versions: true })\n\n const versionCollectionFields = buildVersionCollectionFields(collection)\n\n const versionSchema = buildSchema(this.payload.config, versionCollectionFields, {\n disableUnique: true,\n draftsEnabled: true,\n indexSortableFields: this.payload.config.indexSortableFields,\n options: {\n minimize: false,\n timestamps: false,\n },\n })\n\n versionSchema.plugin<any, PaginateOptions>(paginate, { useEstimatedCount: true }).plugin(\n getBuildQueryPlugin({\n collectionSlug: collection.slug,\n versionsFields: versionCollectionFields,\n }),\n )\n\n const model = mongoose.model(\n versionModelName,\n versionSchema,\n this.autoPluralization === true ? undefined : versionModelName,\n ) as CollectionModel\n // this.payload.versions[collection.slug] = model;\n this.versions[collection.slug] = model\n }\n\n const model = mongoose.model(\n getDBName({ config: collection }),\n schema,\n this.autoPluralization === true ? undefined : collection.slug,\n ) as CollectionModel\n this.collections[collection.slug] = model\n })\n\n const model = buildGlobalModel(this.payload.config)\n this.globals = model\n\n this.payload.config.globals.forEach((global) => {\n if (global.versions) {\n const versionModelName = getDBName({ config: global, versions: true })\n\n const versionGlobalFields = buildVersionGlobalFields(global)\n\n const versionSchema = buildSchema(this.payload.config, versionGlobalFields, {\n disableUnique: true,\n draftsEnabled: true,\n indexSortableFields: this.payload.config.indexSortableFields,\n options: {\n minimize: false,\n timestamps: false,\n },\n })\n\n versionSchema\n .plugin<any, PaginateOptions>(paginate, { useEstimatedCount: true })\n .plugin(getBuildQueryPlugin({ versionsFields: versionGlobalFields }))\n\n const versionsModel = mongoose.model(\n versionModelName,\n versionSchema,\n versionModelName,\n ) as CollectionModel\n this.versions[global.slug] = versionsModel\n }\n })\n}\n"],"names":["mongoose","paginate","buildVersionCollectionFields","buildVersionGlobalFields","buildCollectionSchema","buildGlobalModel","buildSchema","getBuildQueryPlugin","getDBName","init","payload","config","collections","forEach","collection","schema","versions","versionModelName","versionCollectionFields","versionSchema","disableUnique","draftsEnabled","indexSortableFields","options","minimize","timestamps","plugin","useEstimatedCount","collectionSlug","slug","versionsFields","model","autoPluralization","undefined","globals","global","versionGlobalFields","versionsModel"],"mappings":"AAGA,OAAOA,cAAc,WAAU;AAC/B,OAAOC,cAAc,uBAAsB;AAC3C,SAASC,4BAA4B,EAAEC,wBAAwB,QAAQ,UAAS;AAKhF,OAAOC,2BAA2B,oCAAmC;AACrE,SAASC,gBAAgB,QAAQ,+BAA8B;AAC/D,OAAOC,iBAAiB,0BAAyB;AACjD,OAAOC,yBAAyB,0BAAyB;AACzD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,O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AAQ,EAAE;YACnB,MAAMC,mBAAmBT,UAAU;gBAAEG,QAAQwB;gBAAQnB,UAAU;YAAK;YAEpE,MAAMoB,sBAAsBjC,yBAAyBgC;YAErD,MAAMhB,gBAAgBb,YAAY,IAAI,CAACI,OAAO,CAACC,MAAM,EAAEyB,qBAAqB;gBAC1EhB,eAAe;gBACfC,eAAe;gBACfC,qBAAqB,IAAI,CAACZ,OAAO,CAACC,MAAM,CAACW,mBAAmB;gBAC5DC,SAAS;oBACPC,UAAU;oBACVC,YAAY;gBACd;YACF;YAEAN,cACGO,MAAM,CAAuBzB,UAAU;gBAAE0B,mBAAmB;YAAK,GACjED,MAAM,CAACnB,oBAAoB;gBAAEuB,gBAAgBM;YAAoB;YAEpE,MAAMC,gBAAgBrC,SAAS+B,KAAK,CAClCd,kBACAE,eACAF;YAEF,IAAI,CAACD,QAAQ,CAACmB,OAAON,IAAI,CAAC,GAAGQ;QAC/B;IACF;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"migrateFresh.d.ts","sourceRoot":"","sources":["../src/migrateFresh.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAEjD;;GAEG;AACH,wBAAsB,YAAY,CAChC,IAAI,EAAE,eAAe,EACrB,EAAE,kBAA0B,EAAE,EAAE;IAAE,kBAAkB,CAAC,EAAE,OAAO,CAAA;CAAE,GAC/D,OAAO,CAAC,IAAI,CAAC,CAgEf"}
1
+ {"version":3,"file":"migrateFresh.d.ts","sourceRoot":"","sources":["../src/migrateFresh.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAEjD;;GAEG;AACH,wBAAsB,YAAY,CAChC,IAAI,EAAE,eAAe,EACrB,EAAE,kBAA0B,EAAE,EAAE;IAAE,kBAAkB,CAAC,EAAE,OAAO,CAAA;CAAE,GAC/D,OAAO,CAAC,IAAI,CAAC,CAgEf"}
@@ -1,4 +1,4 @@
1
- import { commitTransaction, initTransaction, killTransaction, readMigrationFiles } from 'payload/database';
1
+ import { commitTransaction, initTransaction, killTransaction, readMigrationFiles } from 'payload';
2
2
  import prompts from 'prompts';
3
3
  /**
4
4
  * Drop the current database and run all migrate up functions
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/migrateFresh.ts"],"sourcesContent":["import type { PayloadRequestWithData } from 'payload/types'\n\nimport {\n commitTransaction,\n initTransaction,\n killTransaction,\n readMigrationFiles,\n} from 'payload/database'\nimport prompts from 'prompts'\n\nimport type { MongooseAdapter } from './index.js'\n\n/**\n * Drop the current database and run all migrate up functions\n */\nexport async function migrateFresh(\n this: MongooseAdapter,\n { forceAcceptWarning = false }: { forceAcceptWarning?: boolean },\n): Promise<void> {\n const { payload } = this\n\n if (!forceAcceptWarning) {\n const { confirm: acceptWarning } = await prompts(\n {\n name: 'confirm',\n type: 'confirm',\n initial: false,\n message: `WARNING: This will drop your database and run all migrations. Are you sure you want to proceed?`,\n },\n {\n onCancel: () => {\n process.exit(0)\n },\n },\n )\n\n if (!acceptWarning) {\n process.exit(0)\n }\n }\n\n payload.logger.info({\n msg: `Dropping database.`,\n })\n\n await this.connection.dropDatabase()\n\n const migrationFiles = await readMigrationFiles({ payload })\n payload.logger.debug({\n msg: `Found ${migrationFiles.length} migration files.`,\n })\n\n const req = { payload } as PayloadRequestWithData\n\n // Run all migrate up\n for (const migration of migrationFiles) {\n payload.logger.info({ msg: `Migrating: ${migration.name}` })\n try {\n const start = Date.now()\n await initTransaction(req)\n await migration.up({ payload, req })\n await payload.create({\n collection: 'payload-migrations',\n data: {\n name: migration.name,\n batch: 1,\n },\n req,\n })\n\n await commitTransaction(req)\n\n payload.logger.info({ msg: `Migrated: ${migration.name} (${Date.now() - start}ms)` })\n } catch (err: unknown) {\n await killTransaction(req)\n payload.logger.error({\n err,\n msg: `Error running migration ${migration.name}. Rolling back.`,\n })\n throw err\n }\n }\n}\n"],"names":["commitTransaction","initTransaction","killTransaction","readMigrationFiles","prompts","migrateFresh","forceAcceptWarning","payload","confirm","acceptWarning","name","type","initial","message","onCancel","process","exit","logger","info","msg","connection","dropDatabase","migrationFiles","debug","length","req","migration","start","Date","now","up","create","collection","data","batch","err","error"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,SACEA,iBAAiB,EACjBC,eAAe,EACfC,eAAe,EACfC,kBAAkB,QACb,mBAAkB;AACzB,OAAOC,aAAa,UAAS;AAI7B;;CAEC,GACD,OAAO,eAAeC,aAEpB,EAAEC,qBAAqB,KAAK,EAAoC;IAEhE,MAAM,EAAEC,OAAO,EAAE,GAAG,IAAI;IAExB,IAAI,CAACD,oBAAoB;QACvB,MAAM,EAAEE,SAASC,aAAa,EAAE,GAAG,MAAML,QACvC;YACEM,MAAM;YACNC,MAAM;YACNC,SAAS;YACTC,SAAS,CAAC,+FAA+F,CAAC;QAC5G,GACA;YACEC,UAAU;gBACRC,QAAQC,IAAI,CAAC;YACf;QACF;QAGF,IAAI,CAACP,eAAe;YAClBM,QAAQC,IAAI,CAAC;QACf;IACF;IAEAT,QAAQU,MAAM,CAACC,IAAI,CAAC;QAClBC,KAAK,CAAC,kBAAkB,CAAC;IAC3B;IAEA,MAAM,IAAI,CAACC,UAAU,CAACC,YAAY;IAElC,MAAMC,iBAAiB,MAAMnB,mBAAmB;QAAEI;IAAQ;IAC1DA,QAAQU,MAAM,CAACM,KAAK,CAAC;QACnBJ,KAAK,CAAC,MAAM,EAAEG,eAAeE,MAAM,CAAC,iBAAiB,CAAC;IACxD;IAEA,MAAMC,MAAM;QAAElB;IAAQ;IAEtB,qBAAqB;IACrB,KAAK,MAAMmB,aAAaJ,eAAgB;QACtCf,QAAQU,MAAM,CAACC,IAAI,CAAC;YAAEC,KAAK,CAAC,WAAW,EAAEO,UAAUhB,IAAI,CAAC,CAAC;QAAC;QAC1D,IAAI;YACF,MAAMiB,QAAQC,KAAKC,GAAG;YACtB,MAAM5B,gBAAgBwB;YACtB,MAAMC,UAAUI,EAAE,CAAC;gBAAEvB;gBAASkB;YAAI;YAClC,MAAMlB,QAAQwB,MAAM,CAAC;gBACnBC,YAAY;gBACZC,MAAM;oBACJvB,MAAMgB,UAAUhB,IAAI;oBACpBwB,OAAO;gBACT;gBACAT;YACF;YAEA,MAAMzB,kBAAkByB;YAExBlB,QAAQU,MAAM,CAACC,IAAI,CAAC;gBAAEC,KAAK,CAAC,WAAW,EAAEO,UAAUhB,IAAI,CAAC,EAAE,EAAEkB,KAAKC,GAAG,KAAKF,MAAM,GAAG,CAAC;YAAC;QACtF,EAAE,OAAOQ,KAAc;YACrB,MAAMjC,gBAAgBuB;YACtBlB,QAAQU,MAAM,CAACmB,KAAK,CAAC;gBACnBD;gBACAhB,KAAK,CAAC,wBAAwB,EAAEO,UAAUhB,IAAI,CAAC,eAAe,CAAC;YACjE;YACA,MAAMyB;QACR;IACF;AACF"}
1
+ {"version":3,"sources":["../src/migrateFresh.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\n\nimport { commitTransaction, initTransaction, killTransaction, readMigrationFiles } from 'payload'\nimport prompts from 'prompts'\n\nimport type { MongooseAdapter } from './index.js'\n\n/**\n * Drop the current database and run all migrate up functions\n */\nexport async function migrateFresh(\n this: MongooseAdapter,\n { forceAcceptWarning = false }: { forceAcceptWarning?: boolean },\n): Promise<void> {\n const { payload } = this\n\n if (!forceAcceptWarning) {\n const { confirm: acceptWarning } = await prompts(\n {\n name: 'confirm',\n type: 'confirm',\n initial: false,\n message: `WARNING: This will drop your database and run all migrations. Are you sure you want to proceed?`,\n },\n {\n onCancel: () => {\n process.exit(0)\n },\n },\n )\n\n if (!acceptWarning) {\n process.exit(0)\n }\n }\n\n payload.logger.info({\n msg: `Dropping database.`,\n })\n\n await this.connection.dropDatabase()\n\n const migrationFiles = await readMigrationFiles({ payload })\n payload.logger.debug({\n msg: `Found ${migrationFiles.length} migration files.`,\n })\n\n const req = { payload } as PayloadRequest\n\n // Run all migrate up\n for (const migration of migrationFiles) {\n payload.logger.info({ msg: `Migrating: ${migration.name}` })\n try {\n const start = Date.now()\n await initTransaction(req)\n await migration.up({ payload, req })\n await payload.create({\n collection: 'payload-migrations',\n data: {\n name: migration.name,\n batch: 1,\n },\n req,\n })\n\n await commitTransaction(req)\n\n payload.logger.info({ msg: `Migrated: ${migration.name} (${Date.now() - start}ms)` })\n } catch (err: unknown) {\n await killTransaction(req)\n payload.logger.error({\n err,\n msg: `Error running migration ${migration.name}. Rolling back.`,\n })\n throw err\n }\n }\n}\n"],"names":["commitTransaction","initTransaction","killTransaction","readMigrationFiles","prompts","migrateFresh","forceAcceptWarning","payload","confirm","acceptWarning","name","type","initial","message","onCancel","process","exit","logger","info","msg","connection","dropDatabase","migrationFiles","debug","length","req","migration","start","Date","now","up","create","collection","data","batch","err","error"],"mappings":"AAEA,SAASA,iBAAiB,EAAEC,eAAe,EAAEC,eAAe,EAAEC,kBAAkB,QAAQ,UAAS;AACjG,OAAOC,aAAa,UAAS;AAI7B;;CAEC,GACD,OAAO,eAAeC,aAEpB,EAAEC,qBAAqB,KAAK,EAAoC;IAEhE,MAAM,EAAEC,OAAO,EAAE,GAAG,IAAI;IAExB,IAAI,CAACD,oBAAoB;QACvB,MAAM,EAAEE,SAASC,aAAa,EAAE,GAAG,MAAML,QACvC;YACEM,MAAM;YACNC,MAAM;YACNC,SAAS;YACTC,SAAS,CAAC,+FAA+F,CAAC;QAC5G,GACA;YACEC,UAAU;gBACRC,QAAQC,IAAI,CAAC;YACf;QACF;QAGF,IAAI,CAACP,eAAe;YAClBM,QAAQC,IAAI,CAAC;QACf;IACF;IAEAT,QAAQU,MAAM,CAACC,IAAI,CAAC;QAClBC,KAAK,CAAC,kBAAkB,CAAC;IAC3B;IAEA,MAAM,IAAI,CAACC,UAAU,CAACC,YAAY;IAElC,MAAMC,iBAAiB,MAAMnB,mBAAmB;QAAEI;IAAQ;IAC1DA,QAAQU,MAAM,CAACM,KAAK,CAAC;QACnBJ,KAAK,CAAC,MAAM,EAAEG,eAAeE,MAAM,CAAC,iBAAiB,CAAC;IACxD;IAEA,MAAMC,MAAM;QAAElB;IAAQ;IAEtB,qBAAqB;IACrB,KAAK,MAAMmB,aAAaJ,eAAgB;QACtCf,QAAQU,MAAM,CAACC,IAAI,CAAC;YAAEC,KAAK,CAAC,WAAW,EAAEO,UAAUhB,IAAI,CAAC,CAAC;QAAC;QAC1D,IAAI;YACF,MAAMiB,QAAQC,KAAKC,GAAG;YACtB,MAAM5B,gBAAgBwB;YACtB,MAAMC,UAAUI,EAAE,CAAC;gBAAEvB;gBAASkB;YAAI;YAClC,MAAMlB,QAAQwB,MAAM,CAAC;gBACnBC,YAAY;gBACZC,MAAM;oBACJvB,MAAMgB,UAAUhB,IAAI;oBACpBwB,OAAO;gBACT;gBACAT;YACF;YAEA,MAAMzB,kBAAkByB;YAExBlB,QAAQU,MAAM,CAACC,IAAI,CAAC;gBAAEC,KAAK,CAAC,WAAW,EAAEO,UAAUhB,IAAI,CAAC,EAAE,EAAEkB,KAAKC,GAAG,KAAKF,MAAM,GAAG,CAAC;YAAC;QACtF,EAAE,OAAOQ,KAAc;YACrB,MAAMjC,gBAAgBuB;YACtBlB,QAAQU,MAAM,CAACmB,KAAK,CAAC;gBACnBD;gBACAhB,KAAK,CAAC,wBAAwB,EAAEO,UAAUhB,IAAI,CAAC,eAAe,CAAC;YACjE;YACA,MAAMyB;QACR;IACF;AACF"}
@@ -1,31 +1,5 @@
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 { Schema } from 'mongoose';
27
- import type { SanitizedConfig } from 'payload/config';
28
- import type { SanitizedCollectionConfig } from 'payload/types';
2
+ import type { SanitizedCollectionConfig, SanitizedConfig } from 'payload';
29
3
  declare const buildCollectionSchema: (collection: SanitizedCollectionConfig, config: SanitizedConfig, schemaOptions?: {}) => Schema;
30
4
  export default buildCollectionSchema;
31
5
  //# sourceMappingURL=buildCollectionSchema.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"buildCollectionSchema.d.ts","sourceRoot":"","sources":["../../src/models/buildCollectionSchema.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,KAAK,EAAmB,MAAM,EAAE,MAAM,UAAU,CAAA;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AACrD,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAA;AAO9D,QAAA,MAAM,qBAAqB,eACb,yBAAyB,UAC7B,eAAe,yBAEtB,MAqBF,CAAA;AAED,eAAe,qBAAqB,CAAA"}
1
+ {"version":3,"file":"buildCollectionSchema.d.ts","sourceRoot":"","sources":["../../src/models/buildCollectionSchema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAmB,MAAM,EAAE,MAAM,UAAU,CAAA;AACvD,OAAO,KAAK,EAAE,yBAAyB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAOzE,QAAA,MAAM,qBAAqB,eACb,yBAAyB,UAC7B,eAAe,yBAEtB,MAqBF,CAAA;AAED,eAAe,qBAAqB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/models/buildCollectionSchema.ts"],"sourcesContent":["import type { PaginateOptions, Schema } from 'mongoose'\nimport type { SanitizedConfig } from 'payload/config'\nimport type { SanitizedCollectionConfig } from 'payload/types'\n\nimport paginate from 'mongoose-paginate-v2'\n\nimport getBuildQueryPlugin from '../queries/buildQuery.js'\nimport buildSchema from './buildSchema.js'\n\nconst buildCollectionSchema = (\n collection: SanitizedCollectionConfig,\n config: SanitizedConfig,\n schemaOptions = {},\n): Schema => {\n const schema = buildSchema(config, collection.fields, {\n draftsEnabled: Boolean(typeof collection?.versions === 'object' && collection.versions.drafts),\n indexSortableFields: config.indexSortableFields,\n options: {\n minimize: false,\n timestamps: collection.timestamps !== false,\n ...schemaOptions,\n },\n })\n\n if (config.indexSortableFields && collection.timestamps !== false) {\n schema.index({ updatedAt: 1 })\n schema.index({ createdAt: 1 })\n }\n\n schema\n .plugin<any, PaginateOptions>(paginate, { useEstimatedCount: true })\n .plugin(getBuildQueryPlugin({ collectionSlug: collection.slug }))\n\n return schema\n}\n\nexport default buildCollectionSchema\n"],"names":["paginate","getBuildQueryPlugin","buildSchema","buildCollectionSchema","collection","config","schemaOptions","schema","fields","draftsEnabled","Boolean","versions","drafts","indexSortableFields","options","minimize","timestamps","index","updatedAt","createdAt","plugin","useEstimatedCount","collectionSlug","slug"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAIA,OAAOA,cAAc,uBAAsB;AAE3C,OAAOC,yBAAyB,2BAA0B;AAC1D,OAAOC,iBAAiB,mBAAkB;AAE1C,MAAMC,wBAAwB,CAC5BC,YACAC,QACAC,gBAAgB,CAAC,CAAC;IAElB,MAAMC,SAASL,YAAYG,QAAQD,WAAWI,MAAM,EAAE;QACpDC,eAAeC,QAAQ,OAAON,YAAYO,aAAa,YAAYP,WAAWO,QAAQ,CAACC,MAAM;QAC7FC,qBAAqBR,OAAOQ,mBAAmB;QAC/CC,SAAS;YACPC,UAAU;YACVC,YAAYZ,WAAWY,UAAU,KAAK;YACtC,GAAGV,aAAa;QAClB;IACF;IAEA,IAAID,OAAOQ,mBAAmB,IAAIT,WAAWY,UAAU,KAAK,OAAO;QACjET,OAAOU,KAAK,CAAC;YAAEC,WAAW;QAAE;QAC5BX,OAAOU,KAAK,CAAC;YAAEE,WAAW;QAAE;IAC9B;IAEAZ,OACGa,MAAM,CAAuBpB,UAAU;QAAEqB,mBAAmB;IAAK,GACjED,MAAM,CAACnB,oBAAoB;QAAEqB,gBAAgBlB,WAAWmB,IAAI;IAAC;IAEhE,OAAOhB;AACT;AAEA,eAAeJ,sBAAqB"}
1
+ {"version":3,"sources":["../../src/models/buildCollectionSchema.ts"],"sourcesContent":["import type { PaginateOptions, Schema } from 'mongoose'\nimport type { SanitizedCollectionConfig, SanitizedConfig } from 'payload'\n\nimport paginate from 'mongoose-paginate-v2'\n\nimport getBuildQueryPlugin from '../queries/buildQuery.js'\nimport buildSchema from './buildSchema.js'\n\nconst buildCollectionSchema = (\n collection: SanitizedCollectionConfig,\n config: SanitizedConfig,\n schemaOptions = {},\n): Schema => {\n const schema = buildSchema(config, collection.fields, {\n draftsEnabled: Boolean(typeof collection?.versions === 'object' && collection.versions.drafts),\n indexSortableFields: config.indexSortableFields,\n options: {\n minimize: false,\n timestamps: collection.timestamps !== false,\n ...schemaOptions,\n },\n })\n\n if (config.indexSortableFields && collection.timestamps !== false) {\n schema.index({ updatedAt: 1 })\n schema.index({ createdAt: 1 })\n }\n\n schema\n .plugin<any, PaginateOptions>(paginate, { useEstimatedCount: true })\n .plugin(getBuildQueryPlugin({ collectionSlug: collection.slug }))\n\n return schema\n}\n\nexport default buildCollectionSchema\n"],"names":["paginate","getBuildQueryPlugin","buildSchema","buildCollectionSchema","collection","config","schemaOptions","schema","fields","draftsEnabled","Boolean","versions","drafts","indexSortableFields","options","minimize","timestamps","index","updatedAt","createdAt","plugin","useEstimatedCount","collectionSlug","slug"],"mappings":"AAGA,OAAOA,cAAc,uBAAsB;AAE3C,OAAOC,yBAAyB,2BAA0B;AAC1D,OAAOC,iBAAiB,mBAAkB;AAE1C,MAAMC,wBAAwB,CAC5BC,YACAC,QACAC,gBAAgB,CAAC,CAAC;IAElB,MAAMC,SAASL,YAAYG,QAAQD,WAAWI,MAAM,EAAE;QACpDC,eAAeC,QAAQ,OAAON,YAAYO,aAAa,YAAYP,WAAWO,QAAQ,CAACC,MAAM;QAC7FC,qBAAqBR,OAAOQ,mBAAmB;QAC/CC,SAAS;YACPC,UAAU;YACVC,YAAYZ,WAAWY,UAAU,KAAK;YACtC,GAAGV,aAAa;QAClB;IACF;IAEA,IAAID,OAAOQ,mBAAmB,IAAIT,WAAWY,UAAU,KAAK,OAAO;QACjET,OAAOU,KAAK,CAAC;YAAEC,WAAW;QAAE;QAC5BX,OAAOU,KAAK,CAAC;YAAEE,WAAW;QAAE;IAC9B;IAEAZ,OACGa,MAAM,CAAuBpB,UAAU;QAAEqB,mBAAmB;IAAK,GACjED,MAAM,CAACnB,oBAAoB;QAAEqB,gBAAgBlB,WAAWmB,IAAI;IAAC;IAEhE,OAAOhB;AACT;AAEA,eAAeJ,sBAAqB"}
@@ -1,4 +1,4 @@
1
- import type { SanitizedConfig } from 'payload/config';
1
+ import type { SanitizedConfig } from 'payload';
2
2
  import type { GlobalModel } from '../types.js';
3
3
  export declare const buildGlobalModel: (config: SanitizedConfig) => GlobalModel | null;
4
4
  //# sourceMappingURL=buildGlobalModel.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"buildGlobalModel.d.ts","sourceRoot":"","sources":["../../src/models/buildGlobalModel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAIrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAK9C,eAAO,MAAM,gBAAgB,WAAY,eAAe,KAAG,WAAW,GAAG,IAwBxE,CAAA"}
1
+ {"version":3,"file":"buildGlobalModel.d.ts","sourceRoot":"","sources":["../../src/models/buildGlobalModel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAI9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAK9C,eAAO,MAAM,gBAAgB,WAAY,eAAe,KAAG,WAAW,GAAG,IAwBxE,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/models/buildGlobalModel.ts"],"sourcesContent":["import type { SanitizedConfig } from 'payload/config'\n\nimport mongoose from 'mongoose'\n\nimport type { GlobalModel } from '../types.js'\n\nimport getBuildQueryPlugin from '../queries/buildQuery.js'\nimport buildSchema from './buildSchema.js'\n\nexport const buildGlobalModel = (config: SanitizedConfig): GlobalModel | null => {\n if (config.globals && config.globals.length > 0) {\n const globalsSchema = new mongoose.Schema(\n {},\n { discriminatorKey: 'globalType', minimize: false, timestamps: true },\n )\n\n globalsSchema.plugin(getBuildQueryPlugin())\n\n const Globals = mongoose.model('globals', globalsSchema, 'globals') as unknown as GlobalModel\n\n Object.values(config.globals).forEach((globalConfig) => {\n const globalSchema = buildSchema(config, globalConfig.fields, {\n options: {\n minimize: false,\n },\n })\n Globals.discriminator(globalConfig.slug, globalSchema)\n })\n\n return Globals\n }\n\n return null\n}\n"],"names":["mongoose","getBuildQueryPlugin","buildSchema","buildGlobalModel","config","globals","length","globalsSchema","Schema","discriminatorKey","minimize","timestamps","plugin","Globals","model","Object","values","forEach","globalConfig","globalSchema","fields","options","discriminator","slug"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,OAAOA,cAAc,WAAU;AAI/B,OAAOC,yBAAyB,2BAA0B;AAC1D,OAAOC,iBAAiB,mBAAkB;AAE1C,OAAO,MAAMC,mBAAmB,CAACC;IAC/B,IAAIA,OAAOC,OAAO,IAAID,OAAOC,OAAO,CAACC,MAAM,GAAG,GAAG;QAC/C,MAAMC,gBAAgB,IAAIP,SAASQ,MAAM,CACvC,CAAC,GACD;YAAEC,kBAAkB;YAAcC,UAAU;YAAOC,YAAY;QAAK;QAGtEJ,cAAcK,MAAM,CAACX;QAErB,MAAMY,UAAUb,SAASc,KAAK,CAAC,WAAWP,eAAe;QAEzDQ,OAAOC,MAAM,CAACZ,OAAOC,OAAO,EAAEY,OAAO,CAAC,CAACC;YACrC,MAAMC,eAAejB,YAAYE,QAAQc,aAAaE,MAAM,EAAE;gBAC5DC,SAAS;oBACPX,UAAU;gBACZ;YACF;YACAG,QAAQS,aAAa,CAACJ,aAAaK,IAAI,EAAEJ;QAC3C;QAEA,OAAON;IACT;IAEA,OAAO;AACT,EAAC"}
1
+ {"version":3,"sources":["../../src/models/buildGlobalModel.ts"],"sourcesContent":["import type { SanitizedConfig } from 'payload'\n\nimport mongoose from 'mongoose'\n\nimport type { GlobalModel } from '../types.js'\n\nimport getBuildQueryPlugin from '../queries/buildQuery.js'\nimport buildSchema from './buildSchema.js'\n\nexport const buildGlobalModel = (config: SanitizedConfig): GlobalModel | null => {\n if (config.globals && config.globals.length > 0) {\n const globalsSchema = new mongoose.Schema(\n {},\n { discriminatorKey: 'globalType', minimize: false, timestamps: true },\n )\n\n globalsSchema.plugin(getBuildQueryPlugin())\n\n const Globals = mongoose.model('globals', globalsSchema, 'globals') as unknown as GlobalModel\n\n Object.values(config.globals).forEach((globalConfig) => {\n const globalSchema = buildSchema(config, globalConfig.fields, {\n options: {\n minimize: false,\n },\n })\n Globals.discriminator(globalConfig.slug, globalSchema)\n })\n\n return Globals\n }\n\n return null\n}\n"],"names":["mongoose","getBuildQueryPlugin","buildSchema","buildGlobalModel","config","globals","length","globalsSchema","Schema","discriminatorKey","minimize","timestamps","plugin","Globals","model","Object","values","forEach","globalConfig","globalSchema","fields","options","discriminator","slug"],"mappings":"AAEA,OAAOA,cAAc,WAAU;AAI/B,OAAOC,yBAAyB,2BAA0B;AAC1D,OAAOC,iBAAiB,mBAAkB;AAE1C,OAAO,MAAMC,mBAAmB,CAACC;IAC/B,IAAIA,OAAOC,OAAO,IAAID,OAAOC,OAAO,CAACC,MAAM,GAAG,GAAG;QAC/C,MAAMC,gBAAgB,IAAIP,SAASQ,MAAM,CACvC,CAAC,GACD;YAAEC,kBAAkB;YAAcC,UAAU;YAAOC,YAAY;QAAK;QAGtEJ,cAAcK,MAAM,CAACX;QAErB,MAAMY,UAAUb,SAASc,KAAK,CAAC,WAAWP,eAAe;QAEzDQ,OAAOC,MAAM,CAACZ,OAAOC,OAAO,EAAEY,OAAO,CAAC,CAACC;YACrC,MAAMC,eAAejB,YAAYE,QAAQc,aAAaE,MAAM,EAAE;gBAC5DC,SAAS;oBACPX,UAAU;gBACZ;YACF;YACAG,QAAQS,aAAa,CAACJ,aAAaK,IAAI,EAAEJ;QAC3C;QAEA,OAAON;IACT;IAEA,OAAO;AACT,EAAC"}
@@ -1,31 +1,5 @@
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 { Schema, SchemaOptions } from 'mongoose';
27
- import type { SanitizedConfig } from 'payload/config';
28
- import type { Field } from 'payload/types';
2
+ import type { Field, SanitizedConfig } from 'payload';
29
3
  export type BuildSchemaOptions = {
30
4
  allowIDField?: boolean;
31
5
  disableUnique?: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"buildSchema.d.ts","sourceRoot":"","sources":["../../src/models/buildSchema.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAGA,OAAO,KAAK,EAAgB,MAAM,EAAE,aAAa,EAAqB,MAAM,UAAU,CAAA;AACtF,OAAO,KAAK,EAAE,eAAe,EAA+B,MAAM,gBAAgB,CAAA;AAClF,OAAO,KAAK,EASV,KAAK,EAiBN,MAAM,eAAe,CAAA;AAUtB,MAAM,MAAM,kBAAkB,GAAG;IAC/B,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAC7B,OAAO,CAAC,EAAE,aAAa,CAAA;CACxB,CAAA;AA0DD,QAAA,MAAM,WAAW,WACP,eAAe,gBACT,KAAK,EAAE,uBACD,kBAAkB,KACrC,MA+BF,CAAA;AA+cD,eAAe,WAAW,CAAA"}
1
+ {"version":3,"file":"buildSchema.d.ts","sourceRoot":"","sources":["../../src/models/buildSchema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,MAAM,EAAE,aAAa,EAAqB,MAAM,UAAU,CAAA;AACtF,OAAO,KAAK,EASV,KAAK,EAWL,eAAe,EAQhB,MAAM,SAAS,CAAA;AAUhB,MAAM,MAAM,kBAAkB,GAAG;IAC/B,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAC7B,OAAO,CAAC,EAAE,aAAa,CAAA;CACxB,CAAA;AA0DD,QAAA,MAAM,WAAW,WACP,eAAe,gBACT,KAAK,EAAE,uBACD,kBAAkB,KACrC,MA+BF,CAAA;AA6cD,eAAe,WAAW,CAAA"}
@@ -1,5 +1,5 @@
1
- /* eslint-disable @typescript-eslint/ban-ts-comment */ /* eslint-disable class-methods-use-this */ /* eslint-disable @typescript-eslint/no-use-before-define */ import mongoose from 'mongoose';
2
- import { fieldAffectsData, fieldIsLocalized, fieldIsPresentationalOnly, tabHasName } from 'payload/types';
1
+ import mongoose from 'mongoose';
2
+ import { fieldAffectsData, fieldIsLocalized, fieldIsPresentationalOnly, tabHasName } from 'payload/shared';
3
3
  const formatBaseSchema = (field, buildSchemaOptions)=>{
4
4
  const { disableUnique, draftsEnabled, indexSortableFields } = buildSchemaOptions;
5
5
  const schema = {
@@ -101,12 +101,10 @@ const fieldToSchemaMap = {
101
101
  });
102
102
  if (field.localized && config.localization) {
103
103
  config.localization.localeCodes.forEach((localeCode)=>{
104
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
105
104
  // @ts-expect-error Possible incorrect typing in mongoose types, this works
106
105
  schema.path(`${field.name}.${localeCode}`).discriminator(blockItem.slug, blockSchema);
107
106
  });
108
107
  } else {
109
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
110
108
  // @ts-expect-error Possible incorrect typing in mongoose types, this works
111
109
  schema.path(field.name).discriminator(blockItem.slug, blockSchema);
112
110
  }