@payloadcms/db-mongodb 3.0.0-canary.98cbdb9 → 3.0.0-canary.98e0119

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. package/dist/connect.d.ts.map +1 -1
  2. package/dist/connect.js +12 -3
  3. package/dist/connect.js.map +1 -1
  4. package/dist/count.d.ts.map +1 -1
  5. package/dist/count.js +8 -1
  6. package/dist/count.js.map +1 -1
  7. package/dist/countGlobalVersions.d.ts +3 -0
  8. package/dist/countGlobalVersions.d.ts.map +1 -0
  9. package/dist/countGlobalVersions.js +40 -0
  10. package/dist/countGlobalVersions.js.map +1 -0
  11. package/dist/countVersions.d.ts +3 -0
  12. package/dist/countVersions.d.ts.map +1 -0
  13. package/dist/countVersions.js +40 -0
  14. package/dist/countVersions.js.map +1 -0
  15. package/dist/create.d.ts.map +1 -1
  16. package/dist/create.js +10 -1
  17. package/dist/create.js.map +1 -1
  18. package/dist/createGlobal.d.ts.map +1 -1
  19. package/dist/createGlobal.js +10 -5
  20. package/dist/createGlobal.js.map +1 -1
  21. package/dist/createGlobalVersion.d.ts +1 -1
  22. package/dist/createGlobalVersion.d.ts.map +1 -1
  23. package/dist/createGlobalVersion.js +13 -4
  24. package/dist/createGlobalVersion.js.map +1 -1
  25. package/dist/createMigration.d.ts.map +1 -1
  26. package/dist/createMigration.js +8 -6
  27. package/dist/createMigration.js.map +1 -1
  28. package/dist/createVersion.d.ts +1 -1
  29. package/dist/createVersion.d.ts.map +1 -1
  30. package/dist/createVersion.js +31 -9
  31. package/dist/createVersion.js.map +1 -1
  32. package/dist/deleteOne.d.ts.map +1 -1
  33. package/dist/deleteOne.js +11 -3
  34. package/dist/deleteOne.js.map +1 -1
  35. package/dist/exports/migration-utils.d.ts +3 -0
  36. package/dist/exports/migration-utils.d.ts.map +1 -0
  37. package/dist/exports/migration-utils.js +4 -0
  38. package/dist/exports/migration-utils.js.map +1 -0
  39. package/dist/find.d.ts.map +1 -1
  40. package/dist/find.js +27 -4
  41. package/dist/find.js.map +1 -1
  42. package/dist/findGlobal.d.ts.map +1 -1
  43. package/dist/findGlobal.js +9 -3
  44. package/dist/findGlobal.js.map +1 -1
  45. package/dist/findGlobalVersions.d.ts.map +1 -1
  46. package/dist/findGlobalVersions.js +9 -4
  47. package/dist/findGlobalVersions.js.map +1 -1
  48. package/dist/findOne.d.ts.map +1 -1
  49. package/dist/findOne.js +27 -3
  50. package/dist/findOne.js.map +1 -1
  51. package/dist/findVersions.d.ts.map +1 -1
  52. package/dist/findVersions.js +9 -4
  53. package/dist/findVersions.js.map +1 -1
  54. package/dist/index.d.ts +14 -4
  55. package/dist/index.d.ts.map +1 -1
  56. package/dist/index.js +17 -7
  57. package/dist/index.js.map +1 -1
  58. package/dist/init.d.ts.map +1 -1
  59. package/dist/init.js +17 -15
  60. package/dist/init.js.map +1 -1
  61. package/dist/models/buildCollectionSchema.d.ts +1 -2
  62. package/dist/models/buildCollectionSchema.d.ts.map +1 -1
  63. package/dist/models/buildCollectionSchema.js +7 -4
  64. package/dist/models/buildCollectionSchema.js.map +1 -1
  65. package/dist/models/buildGlobalModel.js +2 -2
  66. package/dist/models/buildGlobalModel.js.map +1 -1
  67. package/dist/models/buildSchema.d.ts +1 -2
  68. package/dist/models/buildSchema.d.ts.map +1 -1
  69. package/dist/models/buildSchema.js +104 -12
  70. package/dist/models/buildSchema.js.map +1 -1
  71. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts +6 -0
  72. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts.map +1 -0
  73. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js +136 -0
  74. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js.map +1 -0
  75. package/dist/predefinedMigrations/migrateVersionsV1_V2.d.ts +5 -0
  76. package/dist/predefinedMigrations/migrateVersionsV1_V2.d.ts.map +1 -0
  77. package/dist/predefinedMigrations/migrateVersionsV1_V2.js +107 -0
  78. package/dist/predefinedMigrations/migrateVersionsV1_V2.js.map +1 -0
  79. package/dist/predefinedMigrations/relationships-v2-v3.d.ts +4 -0
  80. package/dist/predefinedMigrations/relationships-v2-v3.d.ts.map +1 -0
  81. package/dist/predefinedMigrations/relationships-v2-v3.js +9 -0
  82. package/dist/predefinedMigrations/relationships-v2-v3.js.map +1 -0
  83. package/dist/predefinedMigrations/versions-v1-v2.d.ts +4 -0
  84. package/dist/predefinedMigrations/versions-v1-v2.d.ts.map +1 -0
  85. package/dist/predefinedMigrations/versions-v1-v2.js +5 -95
  86. package/dist/predefinedMigrations/versions-v1-v2.js.map +1 -1
  87. package/dist/queries/buildQuery.d.ts +2 -2
  88. package/dist/queries/buildQuery.d.ts.map +1 -1
  89. package/dist/queries/buildQuery.js +1 -2
  90. package/dist/queries/buildQuery.js.map +1 -1
  91. package/dist/queries/buildSearchParams.d.ts.map +1 -1
  92. package/dist/queries/buildSearchParams.js +28 -18
  93. package/dist/queries/buildSearchParams.js.map +1 -1
  94. package/dist/queries/buildSortParam.d.ts +2 -2
  95. package/dist/queries/buildSortParam.d.ts.map +1 -1
  96. package/dist/queries/buildSortParam.js +26 -17
  97. package/dist/queries/buildSortParam.js.map +1 -1
  98. package/dist/queries/getLocalizedSortProperty.spec.js +1 -1
  99. package/dist/queries/getLocalizedSortProperty.spec.js.map +1 -1
  100. package/dist/queries/parseParams.d.ts.map +1 -1
  101. package/dist/queries/parseParams.js +7 -2
  102. package/dist/queries/parseParams.js.map +1 -1
  103. package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
  104. package/dist/queries/sanitizeQueryValue.js +144 -27
  105. package/dist/queries/sanitizeQueryValue.js.map +1 -1
  106. package/dist/queryDrafts.d.ts.map +1 -1
  107. package/dist/queryDrafts.js +29 -8
  108. package/dist/queryDrafts.js.map +1 -1
  109. package/dist/transactions/beginTransaction.d.ts.map +1 -1
  110. package/dist/transactions/beginTransaction.js +2 -0
  111. package/dist/transactions/beginTransaction.js.map +1 -1
  112. package/dist/transactions/commitTransaction.d.ts.map +1 -1
  113. package/dist/transactions/commitTransaction.js +3 -1
  114. package/dist/transactions/commitTransaction.js.map +1 -1
  115. package/dist/types.d.ts +7 -4
  116. package/dist/types.d.ts.map +1 -1
  117. package/dist/types.js.map +1 -1
  118. package/dist/updateGlobal.d.ts.map +1 -1
  119. package/dist/updateGlobal.js +17 -4
  120. package/dist/updateGlobal.js.map +1 -1
  121. package/dist/updateGlobalVersion.d.ts +2 -2
  122. package/dist/updateGlobalVersion.d.ts.map +1 -1
  123. package/dist/updateGlobalVersion.js +18 -4
  124. package/dist/updateGlobalVersion.js.map +1 -1
  125. package/dist/updateOne.d.ts.map +1 -1
  126. package/dist/updateOne.js +18 -4
  127. package/dist/updateOne.js.map +1 -1
  128. package/dist/updateVersion.d.ts +1 -1
  129. package/dist/updateVersion.d.ts.map +1 -1
  130. package/dist/updateVersion.js +17 -3
  131. package/dist/updateVersion.js.map +1 -1
  132. package/dist/upsert.d.ts +3 -0
  133. package/dist/upsert.d.ts.map +1 -0
  134. package/dist/upsert.js +15 -0
  135. package/dist/upsert.js.map +1 -0
  136. package/dist/utilities/buildJoinAggregation.d.ts +18 -0
  137. package/dist/utilities/buildJoinAggregation.d.ts.map +1 -0
  138. package/dist/utilities/buildJoinAggregation.js +159 -0
  139. package/dist/utilities/buildJoinAggregation.js.map +1 -0
  140. package/dist/utilities/buildProjectionFromSelect.d.ts +8 -0
  141. package/dist/utilities/buildProjectionFromSelect.d.ts.map +1 -0
  142. package/dist/utilities/buildProjectionFromSelect.js +171 -0
  143. package/dist/utilities/buildProjectionFromSelect.js.map +1 -0
  144. package/dist/utilities/getDBName.d.ts.map +1 -1
  145. package/dist/utilities/getDBName.js +3 -1
  146. package/dist/utilities/getDBName.js.map +1 -1
  147. package/dist/utilities/handleError.js +2 -2
  148. package/dist/utilities/handleError.js.map +1 -1
  149. package/dist/utilities/sanitizeInternalFields.d.ts +1 -2
  150. package/dist/utilities/sanitizeInternalFields.d.ts.map +1 -1
  151. package/dist/utilities/sanitizeInternalFields.js +1 -2
  152. package/dist/utilities/sanitizeInternalFields.js.map +1 -1
  153. package/dist/utilities/sanitizeRelationshipIDs.d.ts +9 -0
  154. package/dist/utilities/sanitizeRelationshipIDs.d.ts.map +1 -0
  155. package/dist/utilities/sanitizeRelationshipIDs.js +115 -0
  156. package/dist/utilities/sanitizeRelationshipIDs.js.map +1 -0
  157. package/dist/withSession.d.ts +1 -1
  158. package/dist/withSession.d.ts.map +1 -1
  159. package/dist/withSession.js +5 -3
  160. package/dist/withSession.js.map +1 -1
  161. package/license.md +22 -0
  162. package/package.json +24 -10
@@ -0,0 +1,136 @@
1
+ import { buildVersionCollectionFields, buildVersionGlobalFields } from 'payload';
2
+ import { sanitizeRelationshipIDs } from '../utilities/sanitizeRelationshipIDs.js';
3
+ import { withSession } from '../withSession.js';
4
+ const migrateModelWithBatching = async ({ batchSize, config, fields, Model, session })=>{
5
+ let hasNext = true;
6
+ let skip = 0;
7
+ while(hasNext){
8
+ const docs = await Model.find({}, {}, {
9
+ lean: true,
10
+ limit: batchSize + 1,
11
+ session,
12
+ skip
13
+ });
14
+ hasNext = docs.length > batchSize;
15
+ if (hasNext) {
16
+ docs.pop();
17
+ }
18
+ for (const doc of docs){
19
+ sanitizeRelationshipIDs({
20
+ config,
21
+ data: doc,
22
+ fields
23
+ });
24
+ }
25
+ await Model.bulkWrite(docs.map((doc)=>({
26
+ updateOne: {
27
+ filter: {
28
+ _id: doc._id
29
+ },
30
+ update: doc
31
+ }
32
+ })), {
33
+ session
34
+ });
35
+ skip += batchSize;
36
+ }
37
+ };
38
+ const hasRelationshipOrUploadField = ({ fields })=>{
39
+ for (const field of fields){
40
+ if (field.type === 'relationship' || field.type === 'upload') {
41
+ return true;
42
+ }
43
+ if ('fields' in field) {
44
+ if (hasRelationshipOrUploadField({
45
+ fields: field.fields
46
+ })) {
47
+ return true;
48
+ }
49
+ }
50
+ if ('blocks' in field) {
51
+ for (const block of field.blocks){
52
+ if (hasRelationshipOrUploadField({
53
+ fields: block.fields
54
+ })) {
55
+ return true;
56
+ }
57
+ }
58
+ }
59
+ if ('tabs' in field) {
60
+ for (const tab of field.tabs){
61
+ if (hasRelationshipOrUploadField({
62
+ fields: tab.fields
63
+ })) {
64
+ return true;
65
+ }
66
+ }
67
+ }
68
+ }
69
+ return false;
70
+ };
71
+ export async function migrateRelationshipsV2_V3({ batchSize, req }) {
72
+ const { payload } = req;
73
+ const db = payload.db;
74
+ const config = payload.config;
75
+ const { session } = await withSession(db, req);
76
+ for (const collection of payload.config.collections.filter(hasRelationshipOrUploadField)){
77
+ payload.logger.info(`Migrating collection "${collection.slug}"`);
78
+ await migrateModelWithBatching({
79
+ batchSize,
80
+ config,
81
+ fields: collection.fields,
82
+ Model: db.collections[collection.slug],
83
+ session
84
+ });
85
+ payload.logger.info(`Migrated collection "${collection.slug}"`);
86
+ if (collection.versions) {
87
+ payload.logger.info(`Migrating collection versions "${collection.slug}"`);
88
+ await migrateModelWithBatching({
89
+ batchSize,
90
+ config,
91
+ fields: buildVersionCollectionFields(config, collection),
92
+ Model: db.versions[collection.slug],
93
+ session
94
+ });
95
+ payload.logger.info(`Migrated collection versions "${collection.slug}"`);
96
+ }
97
+ }
98
+ const { globals: GlobalsModel } = db;
99
+ for (const global of payload.config.globals.filter(hasRelationshipOrUploadField)){
100
+ payload.logger.info(`Migrating global "${global.slug}"`);
101
+ const doc = await GlobalsModel.findOne({
102
+ globalType: {
103
+ $eq: global.slug
104
+ }
105
+ }, {}, {
106
+ lean: true,
107
+ session
108
+ });
109
+ sanitizeRelationshipIDs({
110
+ config,
111
+ data: doc,
112
+ fields: global.fields
113
+ });
114
+ await GlobalsModel.updateOne({
115
+ globalType: {
116
+ $eq: global.slug
117
+ }
118
+ }, doc, {
119
+ session
120
+ });
121
+ payload.logger.info(`Migrated global "${global.slug}"`);
122
+ if (global.versions) {
123
+ payload.logger.info(`Migrating global versions "${global.slug}"`);
124
+ await migrateModelWithBatching({
125
+ batchSize,
126
+ config,
127
+ fields: buildVersionGlobalFields(config, global),
128
+ Model: db.versions[global.slug],
129
+ session
130
+ });
131
+ payload.logger.info(`Migrated global versions "${global.slug}"`);
132
+ }
133
+ }
134
+ }
135
+
136
+ //# sourceMappingURL=migrateRelationshipsV2_V3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/predefinedMigrations/migrateRelationshipsV2_V3.ts"],"sourcesContent":["import type { ClientSession, Model } from 'mongoose'\nimport type { Field, PayloadRequest, SanitizedConfig } from 'payload'\n\nimport { buildVersionCollectionFields, buildVersionGlobalFields } from 'payload'\n\nimport type { MongooseAdapter } from '../index.js'\n\nimport { sanitizeRelationshipIDs } from '../utilities/sanitizeRelationshipIDs.js'\nimport { withSession } from '../withSession.js'\n\nconst migrateModelWithBatching = async ({\n batchSize,\n config,\n fields,\n Model,\n session,\n}: {\n batchSize: number\n config: SanitizedConfig\n fields: Field[]\n Model: Model<any>\n session: ClientSession\n}): Promise<void> => {\n let hasNext = true\n let skip = 0\n\n while (hasNext) {\n const docs = await Model.find({}, {}, { lean: true, limit: batchSize + 1, session, skip })\n hasNext = docs.length > batchSize\n\n if (hasNext) {\n docs.pop()\n }\n\n for (const doc of docs) {\n sanitizeRelationshipIDs({ config, data: doc, fields })\n }\n\n await Model.bulkWrite(\n docs.map((doc) => ({\n updateOne: {\n filter: { _id: doc._id },\n update: doc,\n },\n })),\n { session },\n )\n\n skip += batchSize\n }\n}\n\nconst hasRelationshipOrUploadField = ({ fields }: { fields: Field[] }): boolean => {\n for (const field of fields) {\n if (field.type === 'relationship' || field.type === 'upload') {\n return true\n }\n\n if ('fields' in field) {\n if (hasRelationshipOrUploadField({ fields: field.fields })) {\n return true\n }\n }\n\n if ('blocks' in field) {\n for (const block of field.blocks) {\n if (hasRelationshipOrUploadField({ fields: block.fields })) {\n return true\n }\n }\n }\n\n if ('tabs' in field) {\n for (const tab of field.tabs) {\n if (hasRelationshipOrUploadField({ fields: tab.fields })) {\n return true\n }\n }\n }\n }\n\n return false\n}\n\nexport async function migrateRelationshipsV2_V3({\n batchSize,\n req,\n}: {\n batchSize: number\n req: PayloadRequest\n}): Promise<void> {\n const { payload } = req\n const db = payload.db as MongooseAdapter\n const config = payload.config\n\n const { session } = await withSession(db, req)\n\n for (const collection of payload.config.collections.filter(hasRelationshipOrUploadField)) {\n payload.logger.info(`Migrating collection \"${collection.slug}\"`)\n\n await migrateModelWithBatching({\n batchSize,\n config,\n fields: collection.fields,\n Model: db.collections[collection.slug],\n session,\n })\n\n payload.logger.info(`Migrated collection \"${collection.slug}\"`)\n\n if (collection.versions) {\n payload.logger.info(`Migrating collection versions \"${collection.slug}\"`)\n\n await migrateModelWithBatching({\n batchSize,\n config,\n fields: buildVersionCollectionFields(config, collection),\n Model: db.versions[collection.slug],\n session,\n })\n\n payload.logger.info(`Migrated collection versions \"${collection.slug}\"`)\n }\n }\n\n const { globals: GlobalsModel } = db\n\n for (const global of payload.config.globals.filter(hasRelationshipOrUploadField)) {\n payload.logger.info(`Migrating global \"${global.slug}\"`)\n\n const doc = await GlobalsModel.findOne<Record<string, unknown>>(\n {\n globalType: {\n $eq: global.slug,\n },\n },\n {},\n { lean: true, session },\n )\n\n sanitizeRelationshipIDs({ config, data: doc, fields: global.fields })\n\n await GlobalsModel.updateOne(\n {\n globalType: {\n $eq: global.slug,\n },\n },\n doc,\n { session },\n )\n\n payload.logger.info(`Migrated global \"${global.slug}\"`)\n\n if (global.versions) {\n payload.logger.info(`Migrating global versions \"${global.slug}\"`)\n\n await migrateModelWithBatching({\n batchSize,\n config,\n fields: buildVersionGlobalFields(config, global),\n Model: db.versions[global.slug],\n session,\n })\n\n payload.logger.info(`Migrated global versions \"${global.slug}\"`)\n }\n }\n}\n"],"names":["buildVersionCollectionFields","buildVersionGlobalFields","sanitizeRelationshipIDs","withSession","migrateModelWithBatching","batchSize","config","fields","Model","session","hasNext","skip","docs","find","lean","limit","length","pop","doc","data","bulkWrite","map","updateOne","filter","_id","update","hasRelationshipOrUploadField","field","type","block","blocks","tab","tabs","migrateRelationshipsV2_V3","req","payload","db","collection","collections","logger","info","slug","versions","globals","GlobalsModel","global","findOne","globalType","$eq"],"mappings":"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"}
@@ -0,0 +1,5 @@
1
+ import type { PayloadRequest } from 'payload';
2
+ export declare function migrateVersionsV1_V2({ req }: {
3
+ req: PayloadRequest;
4
+ }): Promise<void>;
5
+ //# sourceMappingURL=migrateVersionsV1_V2.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrateVersionsV1_V2.d.ts","sourceRoot":"","sources":["../../src/predefinedMigrations/migrateVersionsV1_V2.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAW,cAAc,EAAE,MAAM,SAAS,CAAA;AAMtD,wBAAsB,oBAAoB,CAAC,EAAE,GAAG,EAAE,EAAE;IAAE,GAAG,EAAE,cAAc,CAAA;CAAE,iBAgC1E"}
@@ -0,0 +1,107 @@
1
+ import { withSession } from '../withSession.js';
2
+ export async function migrateVersionsV1_V2({ req }) {
3
+ const { payload } = req;
4
+ const { session } = await withSession(payload.db, req);
5
+ // For each collection
6
+ for (const { slug, versions } of payload.config.collections){
7
+ if (versions?.drafts) {
8
+ await migrateCollectionDocs({
9
+ slug,
10
+ payload,
11
+ session
12
+ });
13
+ payload.logger.info(`Migrated the "${slug}" collection.`);
14
+ }
15
+ }
16
+ // For each global
17
+ for (const { slug, versions } of payload.config.globals){
18
+ if (versions) {
19
+ const VersionsModel = payload.db.versions[slug];
20
+ await VersionsModel.findOneAndUpdate({}, {
21
+ latest: true
22
+ }, {
23
+ session,
24
+ sort: {
25
+ updatedAt: -1
26
+ }
27
+ }).exec();
28
+ payload.logger.info(`Migrated the "${slug}" global.`);
29
+ }
30
+ }
31
+ }
32
+ async function migrateCollectionDocs({ slug, docsAtATime = 100, payload, session }) {
33
+ const VersionsModel = payload.db.versions[slug];
34
+ const remainingDocs = await VersionsModel.aggregate([
35
+ // Sort so that newest are first
36
+ {
37
+ $sort: {
38
+ updatedAt: -1
39
+ }
40
+ },
41
+ // Group by parent ID
42
+ // take the $first of each
43
+ {
44
+ $group: {
45
+ _id: '$parent',
46
+ _versionID: {
47
+ $first: '$_id'
48
+ },
49
+ createdAt: {
50
+ $first: '$createdAt'
51
+ },
52
+ latest: {
53
+ $first: '$latest'
54
+ },
55
+ updatedAt: {
56
+ $first: '$updatedAt'
57
+ },
58
+ version: {
59
+ $first: '$version'
60
+ }
61
+ }
62
+ },
63
+ {
64
+ $match: {
65
+ latest: {
66
+ $eq: null
67
+ }
68
+ }
69
+ },
70
+ {
71
+ $limit: docsAtATime
72
+ }
73
+ ], {
74
+ allowDiskUse: true,
75
+ session
76
+ }).exec();
77
+ if (!remainingDocs || remainingDocs.length === 0) {
78
+ const newVersions = await VersionsModel.find({
79
+ latest: {
80
+ $eq: true
81
+ }
82
+ }, undefined, {
83
+ session
84
+ });
85
+ if (newVersions?.length) {
86
+ payload.logger.info(`Migrated ${newVersions.length} documents in the "${slug}" versions collection.`);
87
+ }
88
+ return;
89
+ }
90
+ const remainingDocIds = remainingDocs.map((doc)=>doc._versionID);
91
+ await VersionsModel.updateMany({
92
+ _id: {
93
+ $in: remainingDocIds
94
+ }
95
+ }, {
96
+ latest: true
97
+ }, {
98
+ session
99
+ });
100
+ await migrateCollectionDocs({
101
+ slug,
102
+ payload,
103
+ session
104
+ });
105
+ }
106
+
107
+ //# sourceMappingURL=migrateVersionsV1_V2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/predefinedMigrations/migrateVersionsV1_V2.ts"],"sourcesContent":["import type { ClientSession } from 'mongoose'\nimport type { Payload, PayloadRequest } from 'payload'\n\nimport type { MongooseAdapter } from '../index.js'\n\nimport { withSession } from '../withSession.js'\n\nexport async function migrateVersionsV1_V2({ req }: { req: PayloadRequest }) {\n const { payload } = req\n\n const { session } = await withSession(payload.db as MongooseAdapter, req)\n\n // For each collection\n\n for (const { slug, versions } of payload.config.collections) {\n if (versions?.drafts) {\n await migrateCollectionDocs({ slug, payload, session })\n\n payload.logger.info(`Migrated the \"${slug}\" collection.`)\n }\n }\n\n // For each global\n for (const { slug, versions } of payload.config.globals) {\n if (versions) {\n const VersionsModel = payload.db.versions[slug]\n\n await VersionsModel.findOneAndUpdate(\n {},\n { latest: true },\n {\n session,\n sort: { updatedAt: -1 },\n },\n ).exec()\n\n payload.logger.info(`Migrated the \"${slug}\" global.`)\n }\n }\n}\n\nasync function migrateCollectionDocs({\n slug,\n docsAtATime = 100,\n payload,\n session,\n}: {\n docsAtATime?: number\n payload: Payload\n session: ClientSession\n slug: string\n}) {\n const VersionsModel = payload.db.versions[slug]\n const remainingDocs = await VersionsModel.aggregate(\n [\n // Sort so that newest are first\n {\n $sort: {\n updatedAt: -1,\n },\n },\n // Group by parent ID\n // take the $first of each\n {\n $group: {\n _id: '$parent',\n _versionID: { $first: '$_id' },\n createdAt: { $first: '$createdAt' },\n latest: { $first: '$latest' },\n updatedAt: { $first: '$updatedAt' },\n version: { $first: '$version' },\n },\n },\n {\n $match: {\n latest: { $eq: null },\n },\n },\n {\n $limit: docsAtATime,\n },\n ],\n {\n allowDiskUse: true,\n session,\n },\n ).exec()\n\n if (!remainingDocs || remainingDocs.length === 0) {\n const newVersions = await VersionsModel.find(\n {\n latest: {\n $eq: true,\n },\n },\n undefined,\n { session },\n )\n\n if (newVersions?.length) {\n payload.logger.info(\n `Migrated ${newVersions.length} documents in the \"${slug}\" versions collection.`,\n )\n }\n\n return\n }\n\n const remainingDocIds = remainingDocs.map((doc) => doc._versionID)\n\n await VersionsModel.updateMany(\n {\n _id: {\n $in: remainingDocIds,\n },\n },\n {\n latest: true,\n },\n {\n session,\n },\n )\n\n await migrateCollectionDocs({ slug, payload, session })\n}\n"],"names":["withSession","migrateVersionsV1_V2","req","payload","session","db","slug","versions","config","collections","drafts","migrateCollectionDocs","logger","info","globals","VersionsModel","findOneAndUpdate","latest","sort","updatedAt","exec","docsAtATime","remainingDocs","aggregate","$sort","$group","_id","_versionID","$first","createdAt","version","$match","$eq","$limit","allowDiskUse","length","newVersions","find","undefined","remainingDocIds","map","doc","updateMany","$in"],"mappings":"AAKA,SAASA,WAAW,QAAQ,oBAAmB;AAE/C,OAAO,eAAeC,qBAAqB,EAAEC,GAAG,EAA2B;IACzE,MAAM,EAAEC,OAAO,EAAE,GAAGD;IAEpB,MAAM,EAAEE,OAAO,EAAE,GAAG,MAAMJ,YAAYG,QAAQE,EAAE,EAAqBH;IAErE,sBAAsB;IAEtB,KAAK,MAAM,EAAEI,IAAI,EAAEC,QAAQ,EAAE,IAAIJ,QAAQK,MAAM,CAACC,WAAW,CAAE;QAC3D,IAAIF,UAAUG,QAAQ;YACpB,MAAMC,sBAAsB;gBAAEL;gBAAMH;gBAASC;YAAQ;YAErDD,QAAQS,MAAM,CAACC,IAAI,CAAC,CAAC,cAAc,EAAEP,KAAK,aAAa,CAAC;QAC1D;IACF;IAEA,kBAAkB;IAClB,KAAK,MAAM,EAAEA,IAAI,EAAEC,QAAQ,EAAE,IAAIJ,QAAQK,MAAM,CAACM,OAAO,CAAE;QACvD,IAAIP,UAAU;YACZ,MAAMQ,gBAAgBZ,QAAQE,EAAE,CAACE,QAAQ,CAACD,KAAK;YAE/C,MAAMS,cAAcC,gBAAgB,CAClC,CAAC,GACD;gBAAEC,QAAQ;YAAK,GACf;gBACEb;gBACAc,MAAM;oBAAEC,WAAW,CAAC;gBAAE;YACxB,GACAC,IAAI;YAENjB,QAAQS,MAAM,CAACC,IAAI,CAAC,CAAC,cAAc,EAAEP,KAAK,SAAS,CAAC;QACtD;IACF;AACF;AAEA,eAAeK,sBAAsB,EACnCL,IAAI,EACJe,cAAc,GAAG,EACjBlB,OAAO,EACPC,OAAO,EAMR;IACC,MAAMW,gBAAgBZ,QAAQE,EAAE,CAACE,QAAQ,CAACD,KAAK;IAC/C,MAAMgB,gBAAgB,MAAMP,cAAcQ,SAAS,CACjD;QACE,gCAAgC;QAChC;YACEC,OAAO;gBACLL,WAAW,CAAC;YACd;QACF;QACA,qBAAqB;QACrB,0BAA0B;QAC1B;YACEM,QAAQ;gBACNC,KAAK;gBACLC,YAAY;oBAAEC,QAAQ;gBAAO;gBAC7BC,WAAW;oBAAED,QAAQ;gBAAa;gBAClCX,QAAQ;oBAAEW,QAAQ;gBAAU;gBAC5BT,WAAW;oBAAES,QAAQ;gBAAa;gBAClCE,SAAS;oBAAEF,QAAQ;gBAAW;YAChC;QACF;QACA;YACEG,QAAQ;gBACNd,QAAQ;oBAAEe,KAAK;gBAAK;YACtB;QACF;QACA;YACEC,QAAQZ;QACV;KACD,EACD;QACEa,cAAc;QACd9B;IACF,GACAgB,IAAI;IAEN,IAAI,CAACE,iBAAiBA,cAAca,MAAM,KAAK,GAAG;QAChD,MAAMC,cAAc,MAAMrB,cAAcsB,IAAI,CAC1C;YACEpB,QAAQ;gBACNe,KAAK;YACP;QACF,GACAM,WACA;YAAElC;QAAQ;QAGZ,IAAIgC,aAAaD,QAAQ;YACvBhC,QAAQS,MAAM,CAACC,IAAI,CACjB,CAAC,SAAS,EAAEuB,YAAYD,MAAM,CAAC,mBAAmB,EAAE7B,KAAK,sBAAsB,CAAC;QAEpF;QAEA;IACF;IAEA,MAAMiC,kBAAkBjB,cAAckB,GAAG,CAAC,CAACC,MAAQA,IAAId,UAAU;IAEjE,MAAMZ,cAAc2B,UAAU,CAC5B;QACEhB,KAAK;YACHiB,KAAKJ;QACP;IACF,GACA;QACEtB,QAAQ;IACV,GACA;QACEb;IACF;IAGF,MAAMO,sBAAsB;QAAEL;QAAMH;QAASC;IAAQ;AACvD"}
@@ -0,0 +1,4 @@
1
+ declare const imports = "import { migrateRelationshipsV2_V3 } from '@payloadcms/db-mongodb/migration-utils'";
2
+ declare const upSQL = " await migrateRelationshipsV2_V3({\n batchSize: 100,\n req,\n })\n";
3
+ export { imports, upSQL };
4
+ //# sourceMappingURL=relationships-v2-v3.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"relationships-v2-v3.d.ts","sourceRoot":"","sources":["../../src/predefinedMigrations/relationships-v2-v3.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,OAAO,uFAAuF,CAAA;AACpG,QAAA,MAAM,KAAK,8FAIV,CAAA;AACD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAA"}
@@ -0,0 +1,9 @@
1
+ const imports = `import { migrateRelationshipsV2_V3 } from '@payloadcms/db-mongodb/migration-utils'`;
2
+ const upSQL = ` await migrateRelationshipsV2_V3({
3
+ batchSize: 100,
4
+ req,
5
+ })
6
+ `;
7
+ export { imports, upSQL }; //# sourceMappingURL=versions-v2-v3.js.map
8
+
9
+ //# sourceMappingURL=relationships-v2-v3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/predefinedMigrations/relationships-v2-v3.ts"],"sourcesContent":["const imports = `import { migrateRelationshipsV2_V3 } from '@payloadcms/db-mongodb/migration-utils'`\nconst upSQL = ` await migrateRelationshipsV2_V3({\n batchSize: 100,\n req,\n })\n`\nexport { imports, upSQL }\n\n//# sourceMappingURL=versions-v2-v3.js.map\n"],"names":["imports","upSQL"],"mappings":"AAAA,MAAMA,UAAU,CAAC,kFAAkF,CAAC;AACpG,MAAMC,QAAQ,CAAC;;;;AAIf,CAAC;AACD,SAASD,OAAO,EAAEC,KAAK,GAAE,CAEzB,0CAA0C"}
@@ -0,0 +1,4 @@
1
+ declare const imports = "import { migrateVersionsV1_V2 } from '@payloadcms/db-mongodb/migration-utils'";
2
+ declare const upSQL = " await migrateVersionsV1_V2({\n req,\n })\n";
3
+ export { imports, upSQL };
4
+ //# sourceMappingURL=versions-v1-v2.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"versions-v1-v2.d.ts","sourceRoot":"","sources":["../../src/predefinedMigrations/versions-v1-v2.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,OAAO,kFAAkF,CAAA;AAC/F,QAAA,MAAM,KAAK,gEAGV,CAAA;AACD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAA"}
@@ -1,98 +1,8 @@
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
- )
1
+ const imports = `import { migrateVersionsV1_V2 } from '@payloadcms/db-mongodb/migration-utils'`;
2
+ const upSQL = ` await migrateVersionsV1_V2({
3
+ req,
4
+ })
96
5
  `;
6
+ export { imports, upSQL }; //# sourceMappingURL=versions-v2-v3.js.map
97
7
 
98
8
  //# sourceMappingURL=versions-v1-v2.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/predefinedMigrations/versions-v1-v2.js"],"sourcesContent":["module.exports.up = ` async function migrateCollectionDocs(slug: string, docsAtATime = 100) {\n const VersionsModel = payload.db.versions[slug]\n const remainingDocs = await VersionsModel.aggregate(\n [\n // Sort so that newest are first\n {\n $sort: {\n updatedAt: -1,\n },\n },\n // Group by parent ID\n // take the $first of each\n {\n $group: {\n _id: '$parent',\n _versionID: { $first: '$_id' },\n createdAt: { $first: '$createdAt' },\n latest: { $first: '$latest' },\n updatedAt: { $first: '$updatedAt' },\n version: { $first: '$version' },\n },\n },\n {\n $match: {\n latest: { $eq: null },\n },\n },\n {\n $limit: docsAtATime,\n },\n ],\n {\n allowDiskUse: true,\n },\n ).exec()\n\n if (!remainingDocs || remainingDocs.length === 0) {\n const newVersions = await VersionsModel.find({\n latest: {\n $eq: true,\n },\n })\n\n if (newVersions?.length) {\n payload.logger.info(\n \\`Migrated \\${newVersions.length} documents in the \"\\${slug}\" versions collection.\\`,\n )\n }\n\n return\n }\n\n const remainingDocIds = remainingDocs.map((doc) => doc._versionID)\n\n await VersionsModel.updateMany(\n {\n _id: {\n $in: remainingDocIds,\n },\n },\n {\n latest: true,\n },\n )\n\n await migrateCollectionDocs(slug)\n }\n\n // For each collection\n await Promise.all(\n payload.config.collections.map(async ({ slug, versions }) => {\n if (versions?.drafts) {\n return migrateCollectionDocs(slug)\n }\n }),\n )\n\n // For each global\n await Promise.all(\n payload.config.globals.map(async ({ slug, versions }) => {\n if (versions) {\n const VersionsModel = payload.db.versions[slug]\n\n await VersionsModel.findOneAndUpdate(\n {},\n { latest: true },\n {\n sort: { updatedAt: -1 },\n },\n ).exec()\n\n payload.logger.info(\\`Migrated the \"\\${slug}\" global.\\`)\n }\n }),\n )\n`\n"],"names":["module","exports","up"],"mappings":"AAAAA,OAAOC,OAAO,CAACC,EAAE,GAAG,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+FrB,CAAC"}
1
+ {"version":3,"sources":["../../src/predefinedMigrations/versions-v1-v2.ts"],"sourcesContent":["const imports = `import { migrateVersionsV1_V2 } from '@payloadcms/db-mongodb/migration-utils'`\nconst upSQL = ` await migrateVersionsV1_V2({\n req,\n })\n`\nexport { imports, upSQL }\n\n//# sourceMappingURL=versions-v2-v3.js.map\n"],"names":["imports","upSQL"],"mappings":"AAAA,MAAMA,UAAU,CAAC,6EAA6E,CAAC;AAC/F,MAAMC,QAAQ,CAAC;;;AAGf,CAAC;AACD,SAASD,OAAO,EAAEC,KAAK,GAAE,CAEzB,0CAA0C"}
@@ -9,6 +9,6 @@ export type BuildQueryArgs = {
9
9
  payload: Payload;
10
10
  where: Where;
11
11
  };
12
- declare const getBuildQueryPlugin: ({ collectionSlug, versionsFields }?: GetBuildQueryPluginArgs) => (schema: any) => void;
13
- export default getBuildQueryPlugin;
12
+ export declare const getBuildQueryPlugin: ({ collectionSlug, versionsFields, }?: GetBuildQueryPluginArgs) => (schema: any) => void;
13
+ export {};
14
14
  //# sourceMappingURL=buildQuery.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"buildQuery.d.ts","sourceRoot":"","sources":["../../src/queries/buildQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAMpD,KAAK,uBAAuB,GAAG;IAC7B,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,cAAc,CAAC,EAAE,KAAK,EAAE,CAAA;CACzB,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,KAAK,CAAA;CACb,CAAA;AAID,QAAA,MAAM,mBAAmB,wCAAwC,uBAAuB,0BAsCvF,CAAA;AAED,eAAe,mBAAmB,CAAA"}
1
+ {"version":3,"file":"buildQuery.d.ts","sourceRoot":"","sources":["../../src/queries/buildQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAMpD,KAAK,uBAAuB,GAAG;IAC7B,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,cAAc,CAAC,EAAE,KAAK,EAAE,CAAA;CACzB,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,KAAK,CAAA;CACb,CAAA;AAID,eAAO,MAAM,mBAAmB,yCAG7B,uBAAuB,0BAsCzB,CAAA"}
@@ -2,7 +2,7 @@ import { QueryError } from 'payload';
2
2
  import { parseParams } from './parseParams.js';
3
3
  // This plugin asynchronously builds a list of Mongoose query constraints
4
4
  // which can then be used in subsequent Mongoose queries.
5
- const getBuildQueryPlugin = ({ collectionSlug, versionsFields } = {})=>{
5
+ export const getBuildQueryPlugin = ({ collectionSlug, versionsFields } = {})=>{
6
6
  return function buildQueryPlugin(schema) {
7
7
  const modifiedSchema = schema;
8
8
  async function buildQuery({ globalSlug, locale, payload, where }) {
@@ -34,6 +34,5 @@ const getBuildQueryPlugin = ({ collectionSlug, versionsFields } = {})=>{
34
34
  modifiedSchema.statics.buildQuery = buildQuery;
35
35
  };
36
36
  };
37
- export default getBuildQueryPlugin;
38
37
 
39
38
  //# sourceMappingURL=buildQuery.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/queries/buildQuery.ts"],"sourcesContent":["import type { Field, Payload, Where } from 'payload'\n\nimport { QueryError } from 'payload'\n\nimport { parseParams } from './parseParams.js'\n\ntype GetBuildQueryPluginArgs = {\n collectionSlug?: string\n versionsFields?: Field[]\n}\n\nexport type BuildQueryArgs = {\n globalSlug?: string\n locale?: string\n payload: Payload\n where: Where\n}\n\n// This plugin asynchronously builds a list of Mongoose query constraints\n// which can then be used in subsequent Mongoose queries.\nconst getBuildQueryPlugin = ({ collectionSlug, versionsFields }: GetBuildQueryPluginArgs = {}) => {\n return function buildQueryPlugin(schema) {\n const modifiedSchema = schema\n async function buildQuery({\n globalSlug,\n locale,\n payload,\n where,\n }: BuildQueryArgs): Promise<Record<string, unknown>> {\n let fields = versionsFields\n if (!fields) {\n if (globalSlug) {\n const globalConfig = payload.globals.config.find(({ slug }) => slug === globalSlug)\n fields = globalConfig.fields\n }\n if (collectionSlug) {\n const collectionConfig = payload.collections[collectionSlug].config\n fields = collectionConfig.fields\n }\n }\n const errors = []\n const result = await parseParams({\n collectionSlug,\n fields,\n globalSlug,\n locale,\n payload,\n where,\n })\n\n if (errors.length > 0) {\n throw new QueryError(errors)\n }\n\n return result\n }\n modifiedSchema.statics.buildQuery = buildQuery\n }\n}\n\nexport default getBuildQueryPlugin\n"],"names":["QueryError","parseParams","getBuildQueryPlugin","collectionSlug","versionsFields","buildQueryPlugin","schema","modifiedSchema","buildQuery","globalSlug","locale","payload","where","fields","globalConfig","globals","config","find","slug","collectionConfig","collections","errors","result","length","statics"],"mappings":"AAEA,SAASA,UAAU,QAAQ,UAAS;AAEpC,SAASC,WAAW,QAAQ,mBAAkB;AAc9C,yEAAyE;AACzE,yDAAyD;AACzD,MAAMC,sBAAsB,CAAC,EAAEC,cAAc,EAAEC,cAAc,EAA2B,GAAG,CAAC,CAAC;IAC3F,OAAO,SAASC,iBAAiBC,MAAM;QACrC,MAAMC,iBAAiBD;QACvB,eAAeE,WAAW,EACxBC,UAAU,EACVC,MAAM,EACNC,OAAO,EACPC,KAAK,EACU;YACf,IAAIC,SAAST;YACb,IAAI,CAACS,QAAQ;gBACX,IAAIJ,YAAY;oBACd,MAAMK,eAAeH,QAAQI,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,CAAC,EAAEC,IAAI,EAAE,GAAKA,SAAST;oBACxEI,SAASC,aAAaD,MAAM;gBAC9B;gBACA,IAAIV,gBAAgB;oBAClB,MAAMgB,mBAAmBR,QAAQS,WAAW,CAACjB,eAAe,CAACa,MAAM;oBACnEH,SAASM,iBAAiBN,MAAM;gBAClC;YACF;YACA,MAAMQ,SAAS,EAAE;YACjB,MAAMC,SAAS,MAAMrB,YAAY;gBAC/BE;gBACAU;gBACAJ;gBACAC;gBACAC;gBACAC;YACF;YAEA,IAAIS,OAAOE,MAAM,GAAG,GAAG;gBACrB,MAAM,IAAIvB,WAAWqB;YACvB;YAEA,OAAOC;QACT;QACAf,eAAeiB,OAAO,CAAChB,UAAU,GAAGA;IACtC;AACF;AAEA,eAAeN,oBAAmB"}
1
+ {"version":3,"sources":["../../src/queries/buildQuery.ts"],"sourcesContent":["import type { Field, Payload, Where } from 'payload'\n\nimport { QueryError } from 'payload'\n\nimport { parseParams } from './parseParams.js'\n\ntype GetBuildQueryPluginArgs = {\n collectionSlug?: string\n versionsFields?: Field[]\n}\n\nexport type BuildQueryArgs = {\n globalSlug?: string\n locale?: string\n payload: Payload\n where: Where\n}\n\n// This plugin asynchronously builds a list of Mongoose query constraints\n// which can then be used in subsequent Mongoose queries.\nexport const getBuildQueryPlugin = ({\n collectionSlug,\n versionsFields,\n}: GetBuildQueryPluginArgs = {}) => {\n return function buildQueryPlugin(schema) {\n const modifiedSchema = schema\n async function buildQuery({\n globalSlug,\n locale,\n payload,\n where,\n }: BuildQueryArgs): Promise<Record<string, unknown>> {\n let fields = versionsFields\n if (!fields) {\n if (globalSlug) {\n const globalConfig = payload.globals.config.find(({ slug }) => slug === globalSlug)\n fields = globalConfig.fields\n }\n if (collectionSlug) {\n const collectionConfig = payload.collections[collectionSlug].config\n fields = collectionConfig.fields\n }\n }\n const errors = []\n const result = await parseParams({\n collectionSlug,\n fields,\n globalSlug,\n locale,\n payload,\n where,\n })\n\n if (errors.length > 0) {\n throw new QueryError(errors)\n }\n\n return result\n }\n modifiedSchema.statics.buildQuery = buildQuery\n }\n}\n"],"names":["QueryError","parseParams","getBuildQueryPlugin","collectionSlug","versionsFields","buildQueryPlugin","schema","modifiedSchema","buildQuery","globalSlug","locale","payload","where","fields","globalConfig","globals","config","find","slug","collectionConfig","collections","errors","result","length","statics"],"mappings":"AAEA,SAASA,UAAU,QAAQ,UAAS;AAEpC,SAASC,WAAW,QAAQ,mBAAkB;AAc9C,yEAAyE;AACzE,yDAAyD;AACzD,OAAO,MAAMC,sBAAsB,CAAC,EAClCC,cAAc,EACdC,cAAc,EACU,GAAG,CAAC,CAAC;IAC7B,OAAO,SAASC,iBAAiBC,MAAM;QACrC,MAAMC,iBAAiBD;QACvB,eAAeE,WAAW,EACxBC,UAAU,EACVC,MAAM,EACNC,OAAO,EACPC,KAAK,EACU;YACf,IAAIC,SAAST;YACb,IAAI,CAACS,QAAQ;gBACX,IAAIJ,YAAY;oBACd,MAAMK,eAAeH,QAAQI,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,CAAC,EAAEC,IAAI,EAAE,GAAKA,SAAST;oBACxEI,SAASC,aAAaD,MAAM;gBAC9B;gBACA,IAAIV,gBAAgB;oBAClB,MAAMgB,mBAAmBR,QAAQS,WAAW,CAACjB,eAAe,CAACa,MAAM;oBACnEH,SAASM,iBAAiBN,MAAM;gBAClC;YACF;YACA,MAAMQ,SAAS,EAAE;YACjB,MAAMC,SAAS,MAAMrB,YAAY;gBAC/BE;gBACAU;gBACAJ;gBACAC;gBACAC;gBACAC;YACF;YAEA,IAAIS,OAAOE,MAAM,GAAG,GAAG;gBACrB,MAAM,IAAIvB,WAAWqB;YACvB;YAEA,OAAOC;QACT;QACAf,eAAeiB,OAAO,CAAChB,UAAU,GAAGA;IACtC;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"buildSearchParams.d.ts","sourceRoot":"","sources":["../../src/queries/buildSearchParams.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAyB,OAAO,EAAE,MAAM,SAAS,CAAA;AAepE,KAAK,WAAW,GAAG;IACjB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB,CAAA;AAOD;;GAEG;AACH,wBAAsB,gBAAgB,CAAC,EACrC,cAAc,EACd,MAAM,EACN,UAAU,EACV,YAAY,EACZ,MAAM,EACN,QAAQ,EACR,OAAO,EACP,GAAG,GACJ,EAAE;IACD,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,YAAY,EAAE,MAAM,CAAA;IACpB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,EAAE,OAAO,CAAA;CACb,GAAG,OAAO,CAAC,WAAW,CAAC,CAuNvB"}
1
+ {"version":3,"file":"buildSearchParams.d.ts","sourceRoot":"","sources":["../../src/queries/buildSearchParams.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAyB,OAAO,EAAE,MAAM,SAAS,CAAA;AAWpE,KAAK,WAAW,GAAG;IACjB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB,CAAA;AAOD;;GAEG;AACH,wBAAsB,gBAAgB,CAAC,EACrC,cAAc,EACd,MAAM,EACN,UAAU,EACV,YAAY,EACZ,MAAM,EACN,QAAQ,EACR,OAAO,EACP,GAAG,GACJ,EAAE;IACD,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,YAAY,EAAE,MAAM,CAAA;IACpB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,EAAE,OAAO,CAAA;CACb,GAAG,OAAO,CAAC,WAAW,CAAC,CAgOvB"}
@@ -1,10 +1,8 @@
1
- import ObjectIdImport from 'bson-objectid';
2
- import mongoose from 'mongoose';
1
+ import { Types } from 'mongoose';
3
2
  import { getLocalizedPaths } from 'payload';
4
3
  import { validOperators } from 'payload/shared';
5
4
  import { operatorMap } from './operatorMap.js';
6
5
  import { sanitizeQueryValue } from './sanitizeQueryValue.js';
7
- const ObjectId = ObjectIdImport.default || ObjectIdImport;
8
6
  const subQueryOptions = {
9
7
  lean: true,
10
8
  limit: 50
@@ -14,7 +12,9 @@ const subQueryOptions = {
14
12
  */ export async function buildSearchParam({ collectionSlug, fields, globalSlug, incomingPath, locale, operator, payload, val }) {
15
13
  // Replace GraphQL nested field double underscore formatting
16
14
  let sanitizedPath = incomingPath.replace(/__/g, '.');
17
- if (sanitizedPath === 'id') sanitizedPath = '_id';
15
+ if (sanitizedPath === 'id') {
16
+ sanitizedPath = '_id';
17
+ }
18
18
  let paths = [];
19
19
  let hasCustomID = false;
20
20
  if (sanitizedPath === '_id') {
@@ -45,16 +45,22 @@ const subQueryOptions = {
45
45
  }
46
46
  const [{ field, path }] = paths;
47
47
  if (path) {
48
- const { operator: formattedOperator, rawQuery, val: formattedValue } = sanitizeQueryValue({
48
+ const sanitizedQueryValue = sanitizeQueryValue({
49
49
  field,
50
50
  hasCustomID,
51
51
  operator,
52
52
  path,
53
53
  val
54
54
  });
55
- if (rawQuery) return {
56
- value: rawQuery
57
- };
55
+ if (!sanitizedQueryValue) {
56
+ return undefined;
57
+ }
58
+ const { operator: formattedOperator, rawQuery, val: formattedValue } = sanitizedQueryValue;
59
+ if (rawQuery) {
60
+ return {
61
+ value: rawQuery
62
+ };
63
+ }
58
64
  // If there are multiple collections to search through,
59
65
  // Recursively build up a list of query constraints
60
66
  if (paths.length > 1) {
@@ -84,7 +90,7 @@ const subQueryOptions = {
84
90
  result.forEach((doc)=>{
85
91
  const stringID = doc._id.toString();
86
92
  $in.push(stringID);
87
- if (mongoose.Types.ObjectId.isValid(stringID)) {
93
+ if (Types.ObjectId.isValid(stringID)) {
88
94
  $in.push(doc._id);
89
95
  }
90
96
  });
@@ -107,7 +113,7 @@ const subQueryOptions = {
107
113
  }
108
114
  const subQuery = priorQueryResult.value;
109
115
  const result = await SubModel.find(subQuery, subQueryOptions);
110
- const $in = result.map((doc)=>doc._id.toString());
116
+ const $in = result.map((doc)=>doc._id);
111
117
  // If it is the last recursion
112
118
  // then pass through the search param
113
119
  if (i + 1 === pathsToQuery.length) {
@@ -133,7 +139,9 @@ const subQueryOptions = {
133
139
  if (field.type === 'relationship' || field.type === 'upload') {
134
140
  let hasNumberIDRelation;
135
141
  let multiIDCondition = '$or';
136
- if (operatorKey === '$ne') multiIDCondition = '$and';
142
+ if (operatorKey === '$ne') {
143
+ multiIDCondition = '$and';
144
+ }
137
145
  const result = {
138
146
  value: {
139
147
  [multiIDCondition]: [
@@ -146,10 +154,10 @@ const subQueryOptions = {
146
154
  }
147
155
  };
148
156
  if (typeof formattedValue === 'string') {
149
- if (mongoose.Types.ObjectId.isValid(formattedValue)) {
157
+ if (Types.ObjectId.isValid(formattedValue)) {
150
158
  result.value[multiIDCondition].push({
151
159
  [path]: {
152
- [operatorKey]: ObjectId(formattedValue)
160
+ [operatorKey]: new Types.ObjectId(formattedValue)
153
161
  }
154
162
  });
155
163
  } else {
@@ -161,11 +169,13 @@ const subQueryOptions = {
161
169
  hasNumberIDRelation = true;
162
170
  }
163
171
  });
164
- if (hasNumberIDRelation) result.value[multiIDCondition].push({
165
- [path]: {
166
- [operatorKey]: parseFloat(formattedValue)
167
- }
168
- });
172
+ if (hasNumberIDRelation) {
173
+ result.value[multiIDCondition].push({
174
+ [path]: {
175
+ [operatorKey]: parseFloat(formattedValue)
176
+ }
177
+ });
178
+ }
169
179
  }
170
180
  }
171
181
  if (result.value[multiIDCondition].length > 1) {