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

Sign up to get free protection for your applications and to get access to all the features.
Files changed (168) 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 +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 +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 +3 -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 +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 +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 +13 -12
  86. package/dist/models/buildSchema.js.map +1 -1
  87. package/dist/predefinedMigrations/versions-v1-v2.js.map +1 -1
  88. package/dist/queries/buildAndOrConditions.d.ts +1 -2
  89. package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
  90. package/dist/queries/buildAndOrConditions.js +0 -2
  91. package/dist/queries/buildAndOrConditions.js.map +1 -1
  92. package/dist/queries/buildQuery.d.ts +1 -2
  93. package/dist/queries/buildQuery.d.ts.map +1 -1
  94. package/dist/queries/buildQuery.js +1 -1
  95. package/dist/queries/buildQuery.js.map +1 -1
  96. package/dist/queries/buildSearchParams.d.ts +1 -2
  97. package/dist/queries/buildSearchParams.d.ts.map +1 -1
  98. package/dist/queries/buildSearchParams.js +2 -2
  99. package/dist/queries/buildSearchParams.js.map +1 -1
  100. package/dist/queries/buildSortParam.d.ts +2 -28
  101. package/dist/queries/buildSortParam.d.ts.map +1 -1
  102. package/dist/queries/buildSortParam.js.map +1 -1
  103. package/dist/queries/getLocalizedSortProperty.d.ts +1 -2
  104. package/dist/queries/getLocalizedSortProperty.d.ts.map +1 -1
  105. package/dist/queries/getLocalizedSortProperty.js +2 -2
  106. package/dist/queries/getLocalizedSortProperty.js.map +1 -1
  107. package/dist/queries/getLocalizedSortProperty.spec.js +43 -43
  108. package/dist/queries/getLocalizedSortProperty.spec.js.map +1 -1
  109. package/dist/queries/mock.js.map +1 -1
  110. package/dist/queries/operatorMap.js.map +1 -1
  111. package/dist/queries/parseParams.d.ts +1 -3
  112. package/dist/queries/parseParams.d.ts.map +1 -1
  113. package/dist/queries/parseParams.js +3 -6
  114. package/dist/queries/parseParams.js.map +1 -1
  115. package/dist/queries/sanitizeQueryValue.d.ts +1 -1
  116. package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
  117. package/dist/queries/sanitizeQueryValue.js +1 -1
  118. package/dist/queries/sanitizeQueryValue.js.map +1 -1
  119. package/dist/queryDrafts.d.ts +1 -1
  120. package/dist/queryDrafts.d.ts.map +1 -1
  121. package/dist/queryDrafts.js +9 -3
  122. package/dist/queryDrafts.js.map +1 -1
  123. package/dist/testCredentials.js.map +1 -1
  124. package/dist/transactions/beginTransaction.d.ts +1 -1
  125. package/dist/transactions/beginTransaction.d.ts.map +1 -1
  126. package/dist/transactions/beginTransaction.js +1 -1
  127. package/dist/transactions/beginTransaction.js.map +1 -1
  128. package/dist/transactions/commitTransaction.d.ts +1 -1
  129. package/dist/transactions/commitTransaction.d.ts.map +1 -1
  130. package/dist/transactions/commitTransaction.js +1 -0
  131. package/dist/transactions/commitTransaction.js.map +1 -1
  132. package/dist/transactions/rollbackTransaction.d.ts +1 -1
  133. package/dist/transactions/rollbackTransaction.d.ts.map +1 -1
  134. package/dist/transactions/rollbackTransaction.js +13 -7
  135. package/dist/transactions/rollbackTransaction.js.map +1 -1
  136. package/dist/types.d.ts +1 -28
  137. package/dist/types.d.ts.map +1 -1
  138. package/dist/types.js.map +1 -1
  139. package/dist/updateGlobal.d.ts +1 -1
  140. package/dist/updateGlobal.d.ts.map +1 -1
  141. package/dist/updateGlobal.js +1 -1
  142. package/dist/updateGlobal.js.map +1 -1
  143. package/dist/updateGlobalVersion.d.ts +1 -2
  144. package/dist/updateGlobalVersion.d.ts.map +1 -1
  145. package/dist/updateGlobalVersion.js +1 -1
  146. package/dist/updateGlobalVersion.js.map +1 -1
  147. package/dist/updateOne.d.ts +1 -1
  148. package/dist/updateOne.d.ts.map +1 -1
  149. package/dist/updateOne.js +7 -3
  150. package/dist/updateOne.js.map +1 -1
  151. package/dist/updateVersion.d.ts +1 -1
  152. package/dist/updateVersion.d.ts.map +1 -1
  153. package/dist/updateVersion.js +1 -1
  154. package/dist/updateVersion.js.map +1 -1
  155. package/dist/utilities/getDBName.d.ts +1 -1
  156. package/dist/utilities/getDBName.d.ts.map +1 -1
  157. package/dist/utilities/getDBName.js.map +1 -1
  158. package/dist/utilities/handleError.d.ts +6 -2
  159. package/dist/utilities/handleError.d.ts.map +1 -1
  160. package/dist/utilities/handleError.js +12 -9
  161. package/dist/utilities/handleError.js.map +1 -1
  162. package/dist/utilities/sanitizeInternalFields.d.ts.map +1 -1
  163. package/dist/utilities/sanitizeInternalFields.js.map +1 -1
  164. package/dist/withSession.d.ts +3 -27
  165. package/dist/withSession.d.ts.map +1 -1
  166. package/dist/withSession.js +6 -2
  167. package/dist/withSession.js.map +1 -1
  168. package/package.json +9 -10
@@ -1,5 +1,4 @@
1
- import { flattenWhereToOperators } from 'payload/database';
2
- import { buildVersionGlobalFields } from 'payload/versions';
1
+ import { buildVersionGlobalFields, flattenWhereToOperators } from 'payload';
3
2
  import { buildSortParam } from './queries/buildSortParam.js';
4
3
  import sanitizeInternalFields from './utilities/sanitizeInternalFields.js';
5
4
  import { withSession } from './withSession.js';
@@ -7,7 +6,7 @@ export const findGlobalVersions = async function findGlobalVersions({ global, li
7
6
  const Model = this.versions[global];
8
7
  const versionFields = buildVersionGlobalFields(this.payload.globals.config.find(({ slug })=>slug === global));
9
8
  const options = {
10
- ...withSession(this, req.transactionID),
9
+ ...await withSession(this, req),
11
10
  limit,
12
11
  skip
13
12
  };
@@ -38,13 +37,20 @@ export const findGlobalVersions = async function findGlobalVersions({ global, li
38
37
  forceCountFn: hasNearConstraint,
39
38
  lean: true,
40
39
  leanWithId: true,
41
- offset: skip,
40
+ limit,
42
41
  options,
43
42
  page,
44
43
  pagination,
45
44
  sort,
46
45
  useEstimatedCount
47
46
  };
47
+ if (this.collation) {
48
+ const defaultLocale = 'en';
49
+ paginationOptions.collation = {
50
+ locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,
51
+ ...this.collation
52
+ };
53
+ }
48
54
  if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {
49
55
  // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding
50
56
  // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,
@@ -73,7 +79,6 @@ export const findGlobalVersions = async function findGlobalVersions({ global, li
73
79
  return {
74
80
  ...result,
75
81
  docs: docs.map((doc)=>{
76
- // eslint-disable-next-line no-param-reassign
77
82
  doc.id = doc._id;
78
83
  return sanitizeInternalFields(doc);
79
84
  })
@@ -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;AAE9C,OAAO,MAAMC,qBAAyC,eAAeA,mBAEnE,EACEC,MAAM,EACNC,KAAK,EACLC,MAAM,EACNC,IAAI,EACJC,UA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ACnC,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 limit,\n options,\n page,\n pagination,\n sort,\n useEstimatedCount,\n }\n\n if (this.collation) {\n const defaultLocale = 'en'\n paginationOptions.collation = {\n locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,\n ...this.collation,\n }\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","collation","defaultLocale","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;QACZ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;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,YAwG1B,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
  };
@@ -43,6 +43,13 @@ export const findVersions = async function findVersions({ collection, limit, loc
43
43
  sort,
44
44
  useEstimatedCount
45
45
  };
46
+ if (this.collation) {
47
+ const defaultLocale = 'en';
48
+ paginationOptions.collation = {
49
+ locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,
50
+ ...this.collation
51
+ };
52
+ }
46
53
  if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {
47
54
  // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding
48
55
  // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,
@@ -71,7 +78,6 @@ export const findVersions = async function findVersions({ collection, limit, loc
71
78
  return {
72
79
  ...result,
73
80
  docs: docs.map((doc)=>{
74
- // eslint-disable-next-line no-param-reassign
75
81
  doc.id = doc._id;
76
82
  return sanitizeInternalFields(doc);
77
83
  })
@@ -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;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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 (this.collation) {\n const defaultLocale = 'en'\n paginationOptions.collation = {\n locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,\n ...this.collation,\n }\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","collation","defaultLocale","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,CAA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,MAAM;QAC5F,mHAAmH;QACnH,qHAAqH;QACrH,mHAAmH;QACnH,4BAA4B;QAC5BN,kBAAkBO,gBAAgB,GAAG;YACnC,OAAOC,QAAQC,OAAO,CACpB7B,MAAM8B,cAAc,CAACd,OAAO;gBAC1B,GAAGV,OAAO;gBACVyB,MAAM;oBAAEC,KAAK;gBAAE;YACjB;QAEJ;IACF;IAEA,IAAIzC,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,MAAMuC,SAAS,MAAMjC,MAAMkC,QAAQ,CAAClB,OAAOI;IAC3C,MAAMe,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,OAAO7C,uBAAuBqD;QAChC;IACF;AACF,EAAC"}
package/dist/index.d.ts CHANGED
@@ -1,42 +1,41 @@
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
- import type { TransactionOptions } from 'mongodb';
1
+ import type { CollationOptions, 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';
30
- import type { CollectionModel, GlobalModel } from './types.js';
4
+ import type { BaseDatabaseAdapter, DatabaseAdapterObj } from 'payload';
5
+ import type { CollectionModel, GlobalModel, MigrateDownArgs, MigrateUpArgs } 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;
10
+ /**
11
+ * If enabled, collation allows for language-specific rules for string comparison.
12
+ * This configuration can include the following options:
13
+ *
14
+ * - `strength` (number): Comparison level (1: Primary, 2: Secondary, 3: Tertiary (default), 4: Quaternary, 5: Identical)
15
+ * - `caseLevel` (boolean): Include case comparison at strength level 1 or 2.
16
+ * - `caseFirst` (string): Sort order of case differences during tertiary level comparisons ("upper", "lower", "off").
17
+ * - `numericOrdering` (boolean): Compare numeric strings as numbers.
18
+ * - `alternate` (string): Consider whitespace and punctuation as base characters ("non-ignorable", "shifted").
19
+ * - `maxVariable` (string): Characters considered ignorable when `alternate` is "shifted" ("punct", "space").
20
+ * - `backwards` (boolean): Sort strings with diacritics from back of the string.
21
+ * - `normalization` (boolean): Check if text requires normalization and perform normalization.
22
+ *
23
+ * Available on MongoDB version 3.4 and up.
24
+ * The locale that gets passed is your current project's locale but defaults to "en".
25
+ *
26
+ * Example:
27
+ * {
28
+ * strength: 3
29
+ * }
30
+ *
31
+ * Defaults to disabled.
32
+ */
33
+ collation?: Omit<CollationOptions, 'locale'>;
35
34
  /** Extra configuration options */
36
- connectOptions?: ConnectOptions & {
35
+ connectOptions?: {
37
36
  /** Set false to disable $facet aggregation in non-supporting databases, Defaults to true */
38
37
  useFacet?: boolean;
39
- };
38
+ } & ConnectOptions;
40
39
  /** 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
40
  disableIndexHints?: boolean;
42
41
  migrationDir?: string;
@@ -44,22 +43,32 @@ export interface Args {
44
43
  * typed as any to avoid dependency
45
44
  */
46
45
  mongoMemoryServer?: MongoMemoryReplSet;
46
+ prodMigrations?: {
47
+ down: (args: MigrateDownArgs) => Promise<void>;
48
+ name: string;
49
+ up: (args: MigrateUpArgs) => Promise<void>;
50
+ }[];
47
51
  transactionOptions?: TransactionOptions | false;
48
52
  /** The URL to connect to MongoDB or false to start payload and prevent connecting */
49
53
  url: false | string;
50
54
  }
51
- export type MongooseAdapter = BaseDatabaseAdapter & Args & {
55
+ export type MongooseAdapter = {
52
56
  collections: {
53
57
  [slug: string]: CollectionModel;
54
58
  };
55
59
  connection: Connection;
56
60
  globals: GlobalModel;
57
61
  mongoMemoryServer: MongoMemoryReplSet;
62
+ prodMigrations?: {
63
+ down: (args: MigrateDownArgs) => Promise<void>;
64
+ name: string;
65
+ up: (args: MigrateUpArgs) => Promise<void>;
66
+ }[];
58
67
  sessions: Record<number | string, ClientSession>;
59
68
  versions: {
60
69
  [slug: string]: CollectionModel;
61
70
  };
62
- };
71
+ } & Args & BaseDatabaseAdapter;
63
72
  declare module 'payload' {
64
73
  interface DatabaseAdapter extends Omit<BaseDatabaseAdapter, 'sessions'>, Omit<Args, 'migrationDir'> {
65
74
  collections: {
@@ -68,6 +77,11 @@ declare module 'payload' {
68
77
  connection: Connection;
69
78
  globals: GlobalModel;
70
79
  mongoMemoryServer: MongoMemoryReplSet;
80
+ prodMigrations?: {
81
+ down: (args: MigrateDownArgs) => Promise<void>;
82
+ name: string;
83
+ up: (args: MigrateUpArgs) => Promise<void>;
84
+ }[];
71
85
  sessions: Record<number | string, ClientSession>;
72
86
  transactionOptions: TransactionOptions;
73
87
  versions: {
@@ -75,5 +89,5 @@ declare module 'payload' {
75
89
  };
76
90
  }
77
91
  }
78
- export declare function mongooseAdapter({ autoPluralization, connectOptions, disableIndexHints, migrationDir: migrationDirArg, mongoMemoryServer, transactionOptions, url, }: Args): DatabaseAdapterObj;
92
+ export declare function mongooseAdapter({ autoPluralization, connectOptions, disableIndexHints, migrationDir: migrationDirArg, mongoMemoryServer, prodMigrations, transactionOptions, url, }: Args): DatabaseAdapterObj;
79
93
  //# sourceMappingURL=index.d.ts.map
@@ -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,CAA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AE,MAAM,CAAA;YACZ,EAAE,EAAE,CAAC,IAAI,EAAE,aAAa,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;SAC3C,EAAE,CAAA;QACH,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,cAAc,EACd,kBAAuB,EACvB,GAAG,GACJ,EAAE,IAAI,GAAG,kBAAkB,CA0D3B"}
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';
@@ -28,7 +28,7 @@ import { updateGlobal } from './updateGlobal.js';
28
28
  import { updateGlobalVersion } from './updateGlobalVersion.js';
29
29
  import { updateOne } from './updateOne.js';
30
30
  import { updateVersion } from './updateVersion.js';
31
- export function mongooseAdapter({ autoPluralization = true, connectOptions, disableIndexHints = false, migrationDir: migrationDirArg, mongoMemoryServer, transactionOptions = {}, url }) {
31
+ export function mongooseAdapter({ autoPluralization = true, connectOptions, disableIndexHints = false, migrationDir: migrationDirArg, mongoMemoryServer, prodMigrations, transactionOptions = {}, url }) {
32
32
  function adapter({ payload }) {
33
33
  const migrationDir = findMigrationDir(migrationDirArg);
34
34
  mongoose.set('strictQuery', false);
@@ -70,6 +70,7 @@ export function mongooseAdapter({ autoPluralization = true, connectOptions, disa
70
70
  migrateFresh,
71
71
  migrationDir,
72
72
  payload,
73
+ prodMigrations,
73
74
  queryDrafts,
74
75
  rollbackTransaction,
75
76
  updateGlobal,
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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AeO,iBAAiBN;QACtClC,SAASyC,GAAG,CAAC,eAAe;QAE5B,OAAOvC,sBAAuC;YAC5CwC,MAAM;YAEN,oBAAoB;YACpBZ;YACAa,aAAa,CAAC;YACdZ,gBAAgBA,kBAAkB,CAAC;YACnCa,YAAYC;YACZzC;YACA4B;YACAc,SAASD;YACTV;YACAY,UAAU,CAAC;YACXX,oBAAoBA,uBAAuB,QAAQS,YAAYT;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 { CollationOptions, 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, MigrateDownArgs, MigrateUpArgs } 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 /**\n * If enabled, collation allows for language-specific rules for string comparison.\n * This configuration can include the following options:\n *\n * - `strength` (number): Comparison level (1: Primary, 2: Secondary, 3: Tertiary (default), 4: Quaternary, 5: Identical)\n * - `caseLevel` (boolean): Include case comparison at strength level 1 or 2.\n * - `caseFirst` (string): Sort order of case differences during tertiary level comparisons (\"upper\", \"lower\", \"off\").\n * - `numericOrdering` (boolean): Compare numeric strings as numbers.\n * - `alternate` (string): Consider whitespace and punctuation as base characters (\"non-ignorable\", \"shifted\").\n * - `maxVariable` (string): Characters considered ignorable when `alternate` is \"shifted\" (\"punct\", \"space\").\n * - `backwards` (boolean): Sort strings with diacritics from back of the string.\n * - `normalization` (boolean): Check if text requires normalization and perform normalization.\n *\n * Available on MongoDB version 3.4 and up.\n * The locale that gets passed is your current project's locale but defaults to \"en\".\n *\n * Example:\n * {\n * strength: 3\n * }\n *\n * Defaults to disabled.\n */\n collation?: Omit<CollationOptions, 'locale'>\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 prodMigrations?: {\n down: (args: MigrateDownArgs) => Promise<void>\n name: string\n up: (args: MigrateUpArgs) => Promise<void>\n }[]\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 prodMigrations?: {\n down: (args: MigrateDownArgs) => Promise<void>\n name: string\n up: (args: MigrateUpArgs) => Promise<void>\n }[]\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 prodMigrations?: {\n down: (args: MigrateDownArgs) => Promise<void>\n name: string\n up: (args: MigrateUpArgs) => Promise<void>\n }[]\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 prodMigrations,\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 prodMigrations,\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","prodMigrations","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,IAAI,QAAQ,YAAW;AAChC,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,WAAW,QAAQ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UtD,KAAKqD,OAAO,CAACH,KAAK;IAClC,MAAMK,qBAAqBvD,KAAKqD,OAAO,CAACH,KAAK;IAE7C,sBAAsB;IACtB,IAAIlB,cAAc,OAAOA;IAEzB,+BAA+B;IAC/B,IAAIlC,GAAG0D,UAAU,CAACJ,SAAS;QACzB,OAAOA;IACT;IAEA,IAAItD,GAAG0D,UAAU,CAACF,UAAU;QAC1B,OAAOA;IACT;IAEA,IAAIxD,GAAG0D,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;gBAAEG,QAAQG;gBAAYE,UAAU;YAAK;YAExE,MAAME,0BAA0BhB,6B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W,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,OAAa,SAASA;IACjC,IAAI,CAACC,OAAO,CAACC,MAAM,CAACC,WAAW,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BAAQnB,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,MAiCF,CAAA;AAED,eAAe,qBAAqB,CAAA"}
@@ -11,6 +11,15 @@ const buildCollectionSchema = (collection, config, schemaOptions = {})=>{
11
11
  ...schemaOptions
12
12
  }
13
13
  });
14
+ if (Array.isArray(collection.upload.filenameCompoundIndex)) {
15
+ const indexDefinition = collection.upload.filenameCompoundIndex.reduce((acc, index)=>{
16
+ acc[index] = 1;
17
+ return acc;
18
+ }, {});
19
+ schema.index(indexDefinition, {
20
+ unique: true
21
+ });
22
+ }
14
23
  if (config.indexSortableFields && collection.timestamps !== false) {
15
24
  schema.index({
16
25
  updatedAt: 1
@@ -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 (Array.isArray(collection.upload.filenameCompoundIndex)) {\n const indexDefinition: Record<string, 1> = collection.upload.filenameCompoundIndex.reduce(\n (acc, index) => {\n acc[index] = 1\n return acc\n },\n {},\n )\n\n schema.index(indexDefinition, { unique: true })\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","Array","isArray","upload","filenameCompoundIndex","indexDefinition","reduce","acc","index","unique","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,IAAIW,MAAMC,OAAO,CAACd,WAAWe,MAAM,CAACC,qBAAqB,GAAG;QAC1D,MAAMC,kBAAqCjB,WAAWe,MAAM,CAACC,qBAAqB,CAACE,MAAM,CACvF,CAACC,KAAKC;YACJD,GAAG,CAACC,MAAM,GAAG;YACb,OAAOD;QACT,GACA,CAAC;QAGHhB,OAAOiB,KAAK,CAACH,iBAAiB;YAAEI,QAAQ;QAAK;IAC/C;IAEA,IAAIpB,OAAOQ,mBAAmB,IAAIT,WAAWY,UAAU,KAAK,OAAO;QACjET,OAAOiB,KAAK,CAAC;YAAEE,WAAW;QAAE;QAC5BnB,OAAOiB,KAAK,CAAC;YAAEG,WAAW;QAAE;IAC9B;IAEApB,OACGqB,MAAM,CAAuB5B,UAAU;QAAE6B,mBAAmB;IAAK,GACjED,MAAM,CAAC3B,oBAAoB;QAAE6B,gBAAgB1B,WAAW2B,IAAI;IAAC;IAEhE,OAAOxB;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