@payloadcms/db-mongodb 3.0.0-canary.f6e77b8 → 3.0.0-canary.fb04843

Sign up to get free protection for your applications and to get access to all the features.
Files changed (220) 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 +18 -4
  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 +10 -3
  9. package/dist/count.js.map +1 -1
  10. package/dist/countGlobalVersions.d.ts +3 -0
  11. package/dist/countGlobalVersions.d.ts.map +1 -0
  12. package/dist/countGlobalVersions.js +40 -0
  13. package/dist/countGlobalVersions.js.map +1 -0
  14. package/dist/countVersions.d.ts +3 -0
  15. package/dist/countVersions.d.ts.map +1 -0
  16. package/dist/countVersions.js +40 -0
  17. package/dist/countVersions.js.map +1 -0
  18. package/dist/create.d.ts +1 -1
  19. package/dist/create.d.ts.map +1 -1
  20. package/dist/create.js +17 -4
  21. package/dist/create.js.map +1 -1
  22. package/dist/createGlobal.d.ts +1 -1
  23. package/dist/createGlobal.d.ts.map +1 -1
  24. package/dist/createGlobal.js +11 -6
  25. package/dist/createGlobal.js.map +1 -1
  26. package/dist/createGlobalVersion.d.ts +1 -1
  27. package/dist/createGlobalVersion.d.ts.map +1 -1
  28. package/dist/createGlobalVersion.js +14 -5
  29. package/dist/createGlobalVersion.js.map +1 -1
  30. package/dist/createMigration.d.ts +1 -1
  31. package/dist/createMigration.d.ts.map +1 -1
  32. package/dist/createMigration.js +20 -32
  33. package/dist/createMigration.js.map +1 -1
  34. package/dist/createVersion.d.ts +1 -1
  35. package/dist/createVersion.d.ts.map +1 -1
  36. package/dist/createVersion.js +32 -10
  37. package/dist/createVersion.js.map +1 -1
  38. package/dist/deleteMany.d.ts +1 -1
  39. package/dist/deleteMany.d.ts.map +1 -1
  40. package/dist/deleteMany.js +1 -1
  41. package/dist/deleteMany.js.map +1 -1
  42. package/dist/deleteOne.d.ts +1 -1
  43. package/dist/deleteOne.d.ts.map +1 -1
  44. package/dist/deleteOne.js +12 -4
  45. package/dist/deleteOne.js.map +1 -1
  46. package/dist/deleteVersions.d.ts +1 -1
  47. package/dist/deleteVersions.d.ts.map +1 -1
  48. package/dist/deleteVersions.js +1 -1
  49. package/dist/deleteVersions.js.map +1 -1
  50. package/dist/destroy.d.ts +1 -1
  51. package/dist/destroy.d.ts.map +1 -1
  52. package/dist/destroy.js.map +1 -1
  53. package/dist/exports/migration-utils.d.ts +3 -0
  54. package/dist/exports/migration-utils.d.ts.map +1 -0
  55. package/dist/exports/migration-utils.js +4 -0
  56. package/dist/exports/migration-utils.js.map +1 -0
  57. package/dist/find.d.ts +1 -1
  58. package/dist/find.d.ts.map +1 -1
  59. package/dist/find.js +36 -7
  60. package/dist/find.js.map +1 -1
  61. package/dist/findGlobal.d.ts +1 -1
  62. package/dist/findGlobal.d.ts.map +1 -1
  63. package/dist/findGlobal.js +11 -5
  64. package/dist/findGlobal.js.map +1 -1
  65. package/dist/findGlobalVersions.d.ts +1 -1
  66. package/dist/findGlobalVersions.d.ts.map +1 -1
  67. package/dist/findGlobalVersions.js +19 -9
  68. package/dist/findGlobalVersions.js.map +1 -1
  69. package/dist/findOne.d.ts +1 -1
  70. package/dist/findOne.d.ts.map +1 -1
  71. package/dist/findOne.js +28 -4
  72. package/dist/findOne.js.map +1 -1
  73. package/dist/findVersions.d.ts +1 -1
  74. package/dist/findVersions.d.ts.map +1 -1
  75. package/dist/findVersions.js +17 -6
  76. package/dist/findVersions.js.map +1 -1
  77. package/dist/index.d.ts +59 -35
  78. package/dist/index.d.ts.map +1 -1
  79. package/dist/index.js +18 -7
  80. package/dist/index.js.map +1 -1
  81. package/dist/init.d.ts +1 -1
  82. package/dist/init.d.ts.map +1 -1
  83. package/dist/init.js +19 -17
  84. package/dist/init.js.map +1 -1
  85. package/dist/migrateFresh.d.ts.map +1 -1
  86. package/dist/migrateFresh.js +1 -1
  87. package/dist/migrateFresh.js.map +1 -1
  88. package/dist/models/buildCollectionSchema.d.ts +2 -29
  89. package/dist/models/buildCollectionSchema.d.ts.map +1 -1
  90. package/dist/models/buildCollectionSchema.js +16 -4
  91. package/dist/models/buildCollectionSchema.js.map +1 -1
  92. package/dist/models/buildGlobalModel.d.ts +1 -1
  93. package/dist/models/buildGlobalModel.d.ts.map +1 -1
  94. package/dist/models/buildGlobalModel.js +2 -2
  95. package/dist/models/buildGlobalModel.js.map +1 -1
  96. package/dist/models/buildSchema.d.ts +2 -29
  97. package/dist/models/buildSchema.d.ts.map +1 -1
  98. package/dist/models/buildSchema.js +116 -23
  99. package/dist/models/buildSchema.js.map +1 -1
  100. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts +6 -0
  101. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts.map +1 -0
  102. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js +141 -0
  103. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js.map +1 -0
  104. package/dist/predefinedMigrations/migrateVersionsV1_V2.d.ts +5 -0
  105. package/dist/predefinedMigrations/migrateVersionsV1_V2.d.ts.map +1 -0
  106. package/dist/predefinedMigrations/migrateVersionsV1_V2.js +107 -0
  107. package/dist/predefinedMigrations/migrateVersionsV1_V2.js.map +1 -0
  108. package/dist/predefinedMigrations/relationships-v2-v3.d.ts +4 -0
  109. package/dist/predefinedMigrations/relationships-v2-v3.d.ts.map +1 -0
  110. package/dist/predefinedMigrations/relationships-v2-v3.js +9 -0
  111. package/dist/predefinedMigrations/relationships-v2-v3.js.map +1 -0
  112. package/dist/predefinedMigrations/versions-v1-v2.d.ts +4 -0
  113. package/dist/predefinedMigrations/versions-v1-v2.d.ts.map +1 -0
  114. package/dist/predefinedMigrations/versions-v1-v2.js +8 -0
  115. package/dist/predefinedMigrations/versions-v1-v2.js.map +1 -0
  116. package/dist/queries/buildAndOrConditions.d.ts +1 -2
  117. package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
  118. package/dist/queries/buildAndOrConditions.js +0 -2
  119. package/dist/queries/buildAndOrConditions.js.map +1 -1
  120. package/dist/queries/buildQuery.d.ts +3 -4
  121. package/dist/queries/buildQuery.d.ts.map +1 -1
  122. package/dist/queries/buildQuery.js +2 -3
  123. package/dist/queries/buildQuery.js.map +1 -1
  124. package/dist/queries/buildSearchParams.d.ts +1 -2
  125. package/dist/queries/buildSearchParams.d.ts.map +1 -1
  126. package/dist/queries/buildSearchParams.js +34 -22
  127. package/dist/queries/buildSearchParams.js.map +1 -1
  128. package/dist/queries/buildSortParam.d.ts +3 -29
  129. package/dist/queries/buildSortParam.d.ts.map +1 -1
  130. package/dist/queries/buildSortParam.js +26 -17
  131. package/dist/queries/buildSortParam.js.map +1 -1
  132. package/dist/queries/getLocalizedSortProperty.d.ts +1 -2
  133. package/dist/queries/getLocalizedSortProperty.d.ts.map +1 -1
  134. package/dist/queries/getLocalizedSortProperty.js +2 -2
  135. package/dist/queries/getLocalizedSortProperty.js.map +1 -1
  136. package/dist/queries/getLocalizedSortProperty.spec.js +44 -44
  137. package/dist/queries/getLocalizedSortProperty.spec.js.map +1 -1
  138. package/dist/queries/mock.js.map +1 -1
  139. package/dist/queries/operatorMap.js.map +1 -1
  140. package/dist/queries/parseParams.d.ts +1 -3
  141. package/dist/queries/parseParams.d.ts.map +1 -1
  142. package/dist/queries/parseParams.js +8 -6
  143. package/dist/queries/parseParams.js.map +1 -1
  144. package/dist/queries/sanitizeQueryValue.d.ts +1 -1
  145. package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
  146. package/dist/queries/sanitizeQueryValue.js +145 -28
  147. package/dist/queries/sanitizeQueryValue.js.map +1 -1
  148. package/dist/queryDrafts.d.ts +1 -1
  149. package/dist/queryDrafts.d.ts.map +1 -1
  150. package/dist/queryDrafts.js +37 -10
  151. package/dist/queryDrafts.js.map +1 -1
  152. package/dist/testCredentials.js.map +1 -1
  153. package/dist/transactions/beginTransaction.d.ts +1 -1
  154. package/dist/transactions/beginTransaction.d.ts.map +1 -1
  155. package/dist/transactions/beginTransaction.js +3 -1
  156. package/dist/transactions/beginTransaction.js.map +1 -1
  157. package/dist/transactions/commitTransaction.d.ts +1 -1
  158. package/dist/transactions/commitTransaction.d.ts.map +1 -1
  159. package/dist/transactions/commitTransaction.js +3 -0
  160. package/dist/transactions/commitTransaction.js.map +1 -1
  161. package/dist/transactions/rollbackTransaction.d.ts +1 -1
  162. package/dist/transactions/rollbackTransaction.d.ts.map +1 -1
  163. package/dist/transactions/rollbackTransaction.js +13 -7
  164. package/dist/transactions/rollbackTransaction.js.map +1 -1
  165. package/dist/types.d.ts +7 -31
  166. package/dist/types.d.ts.map +1 -1
  167. package/dist/types.js.map +1 -1
  168. package/dist/updateGlobal.d.ts +1 -1
  169. package/dist/updateGlobal.d.ts.map +1 -1
  170. package/dist/updateGlobal.js +18 -5
  171. package/dist/updateGlobal.js.map +1 -1
  172. package/dist/updateGlobalVersion.d.ts +2 -3
  173. package/dist/updateGlobalVersion.d.ts.map +1 -1
  174. package/dist/updateGlobalVersion.js +19 -5
  175. package/dist/updateGlobalVersion.js.map +1 -1
  176. package/dist/updateOne.d.ts +1 -1
  177. package/dist/updateOne.d.ts.map +1 -1
  178. package/dist/updateOne.js +25 -7
  179. package/dist/updateOne.js.map +1 -1
  180. package/dist/updateVersion.d.ts +1 -1
  181. package/dist/updateVersion.d.ts.map +1 -1
  182. package/dist/updateVersion.js +18 -4
  183. package/dist/updateVersion.js.map +1 -1
  184. package/dist/upsert.d.ts +3 -0
  185. package/dist/upsert.d.ts.map +1 -0
  186. package/dist/upsert.js +15 -0
  187. package/dist/upsert.js.map +1 -0
  188. package/dist/utilities/buildJoinAggregation.d.ts +18 -0
  189. package/dist/utilities/buildJoinAggregation.d.ts.map +1 -0
  190. package/dist/utilities/buildJoinAggregation.js +159 -0
  191. package/dist/utilities/buildJoinAggregation.js.map +1 -0
  192. package/dist/utilities/buildProjectionFromSelect.d.ts +8 -0
  193. package/dist/utilities/buildProjectionFromSelect.d.ts.map +1 -0
  194. package/dist/utilities/buildProjectionFromSelect.js +171 -0
  195. package/dist/utilities/buildProjectionFromSelect.js.map +1 -0
  196. package/dist/utilities/getDBName.d.ts +1 -1
  197. package/dist/utilities/getDBName.d.ts.map +1 -1
  198. package/dist/utilities/getDBName.js +3 -1
  199. package/dist/utilities/getDBName.js.map +1 -1
  200. package/dist/utilities/handleError.d.ts +6 -2
  201. package/dist/utilities/handleError.d.ts.map +1 -1
  202. package/dist/utilities/handleError.js +12 -9
  203. package/dist/utilities/handleError.js.map +1 -1
  204. package/dist/utilities/sanitizeInternalFields.d.ts +1 -2
  205. package/dist/utilities/sanitizeInternalFields.d.ts.map +1 -1
  206. package/dist/utilities/sanitizeInternalFields.js +1 -2
  207. package/dist/utilities/sanitizeInternalFields.js.map +1 -1
  208. package/dist/utilities/sanitizeRelationshipIDs.d.ts +9 -0
  209. package/dist/utilities/sanitizeRelationshipIDs.d.ts.map +1 -0
  210. package/dist/utilities/sanitizeRelationshipIDs.js +115 -0
  211. package/dist/utilities/sanitizeRelationshipIDs.js.map +1 -0
  212. package/dist/utilities/sanitizeRelationshipIDs.spec.js +383 -0
  213. package/dist/utilities/sanitizeRelationshipIDs.spec.js.map +1 -0
  214. package/dist/withSession.d.ts +3 -27
  215. package/dist/withSession.d.ts.map +1 -1
  216. package/dist/withSession.js +10 -4
  217. package/dist/withSession.js.map +1 -1
  218. package/license.md +22 -0
  219. package/package.json +29 -17
  220. package/predefinedMigrations/versions-v1-v2.js +0 -96
@@ -1,96 +0,0 @@
1
- module.exports.up = ` async function migrateCollectionDocs(slug: string, docsAtATime = 100) {
2
- const VersionsModel = payload.db.versions[slug]
3
- const remainingDocs = await VersionsModel.aggregate(
4
- [
5
- // Sort so that newest are first
6
- {
7
- $sort: {
8
- updatedAt: -1,
9
- },
10
- },
11
- // Group by parent ID
12
- // take the $first of each
13
- {
14
- $group: {
15
- _id: '$parent',
16
- _versionID: { $first: '$_id' },
17
- createdAt: { $first: '$createdAt' },
18
- latest: { $first: '$latest' },
19
- updatedAt: { $first: '$updatedAt' },
20
- version: { $first: '$version' },
21
- },
22
- },
23
- {
24
- $match: {
25
- latest: { $eq: null },
26
- },
27
- },
28
- {
29
- $limit: docsAtATime,
30
- },
31
- ],
32
- {
33
- allowDiskUse: true,
34
- },
35
- ).exec()
36
-
37
- if (!remainingDocs || remainingDocs.length === 0) {
38
- const newVersions = await VersionsModel.find({
39
- latest: {
40
- $eq: true,
41
- },
42
- })
43
-
44
- if (newVersions?.length) {
45
- payload.logger.info(
46
- \`Migrated \${newVersions.length} documents in the "\${slug}" versions collection.\`,
47
- )
48
- }
49
-
50
- return
51
- }
52
-
53
- const remainingDocIds = remainingDocs.map((doc) => doc._versionID)
54
-
55
- await VersionsModel.updateMany(
56
- {
57
- _id: {
58
- $in: remainingDocIds,
59
- },
60
- },
61
- {
62
- latest: true,
63
- },
64
- )
65
-
66
- await migrateCollectionDocs(slug)
67
- }
68
-
69
- // For each collection
70
- await Promise.all(
71
- payload.config.collections.map(async ({ slug, versions }) => {
72
- if (versions?.drafts) {
73
- return migrateCollectionDocs(slug)
74
- }
75
- }),
76
- )
77
-
78
- // For each global
79
- await Promise.all(
80
- payload.config.globals.map(async ({ slug, versions }) => {
81
- if (versions) {
82
- const VersionsModel = payload.db.versions[slug]
83
-
84
- await VersionsModel.findOneAndUpdate(
85
- {},
86
- { latest: true },
87
- {
88
- sort: { updatedAt: -1 },
89
- },
90
- ).exec()
91
-
92
- payload.logger.info(\`Migrated the "\${slug}" global.\`)
93
- }
94
- }),
95
- )
96
- `