@payloadcms/db-mongodb 3.0.0-canary.ff8c8fd → 3.0.1-canary.34c6cc0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (169) 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 +23 -4
  55. package/dist/index.d.ts.map +1 -1
  56. package/dist/index.js +16 -7
  57. package/dist/index.js.map +1 -1
  58. package/dist/init.d.ts.map +1 -1
  59. package/dist/init.js +20 -18
  60. package/dist/init.js.map +1 -1
  61. package/dist/models/buildCollectionSchema.d.ts +2 -3
  62. package/dist/models/buildCollectionSchema.d.ts.map +1 -1
  63. package/dist/models/buildCollectionSchema.js +10 -7
  64. package/dist/models/buildCollectionSchema.js.map +1 -1
  65. package/dist/models/buildGlobalModel.d.ts +2 -2
  66. package/dist/models/buildGlobalModel.d.ts.map +1 -1
  67. package/dist/models/buildGlobalModel.js +6 -6
  68. package/dist/models/buildGlobalModel.js.map +1 -1
  69. package/dist/models/buildSchema.d.ts +2 -3
  70. package/dist/models/buildSchema.d.ts.map +1 -1
  71. package/dist/models/buildSchema.js +108 -66
  72. package/dist/models/buildSchema.js.map +1 -1
  73. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts +6 -0
  74. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts.map +1 -0
  75. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js +141 -0
  76. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js.map +1 -0
  77. package/dist/predefinedMigrations/migrateVersionsV1_V2.d.ts +5 -0
  78. package/dist/predefinedMigrations/migrateVersionsV1_V2.d.ts.map +1 -0
  79. package/dist/predefinedMigrations/migrateVersionsV1_V2.js +107 -0
  80. package/dist/predefinedMigrations/migrateVersionsV1_V2.js.map +1 -0
  81. package/dist/predefinedMigrations/relationships-v2-v3.d.ts +4 -0
  82. package/dist/predefinedMigrations/relationships-v2-v3.d.ts.map +1 -0
  83. package/dist/predefinedMigrations/relationships-v2-v3.js +9 -0
  84. package/dist/predefinedMigrations/relationships-v2-v3.js.map +1 -0
  85. package/dist/predefinedMigrations/versions-v1-v2.d.ts +4 -0
  86. package/dist/predefinedMigrations/versions-v1-v2.d.ts.map +1 -0
  87. package/dist/predefinedMigrations/versions-v1-v2.js +5 -95
  88. package/dist/predefinedMigrations/versions-v1-v2.js.map +1 -1
  89. package/dist/queries/buildQuery.d.ts +2 -2
  90. package/dist/queries/buildQuery.d.ts.map +1 -1
  91. package/dist/queries/buildQuery.js +1 -2
  92. package/dist/queries/buildQuery.js.map +1 -1
  93. package/dist/queries/buildSearchParams.d.ts.map +1 -1
  94. package/dist/queries/buildSearchParams.js +29 -18
  95. package/dist/queries/buildSearchParams.js.map +1 -1
  96. package/dist/queries/buildSortParam.d.ts +2 -2
  97. package/dist/queries/buildSortParam.d.ts.map +1 -1
  98. package/dist/queries/buildSortParam.js +26 -17
  99. package/dist/queries/buildSortParam.js.map +1 -1
  100. package/dist/queries/getLocalizedSortProperty.spec.js +1 -1
  101. package/dist/queries/getLocalizedSortProperty.spec.js.map +1 -1
  102. package/dist/queries/parseParams.d.ts.map +1 -1
  103. package/dist/queries/parseParams.js +7 -2
  104. package/dist/queries/parseParams.js.map +1 -1
  105. package/dist/queries/sanitizeQueryValue.d.ts +3 -2
  106. package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
  107. package/dist/queries/sanitizeQueryValue.js +263 -37
  108. package/dist/queries/sanitizeQueryValue.js.map +1 -1
  109. package/dist/queryDrafts.d.ts.map +1 -1
  110. package/dist/queryDrafts.js +29 -8
  111. package/dist/queryDrafts.js.map +1 -1
  112. package/dist/transactions/beginTransaction.d.ts.map +1 -1
  113. package/dist/transactions/beginTransaction.js +2 -0
  114. package/dist/transactions/beginTransaction.js.map +1 -1
  115. package/dist/transactions/commitTransaction.d.ts.map +1 -1
  116. package/dist/transactions/commitTransaction.js +3 -1
  117. package/dist/transactions/commitTransaction.js.map +1 -1
  118. package/dist/types.d.ts +7 -4
  119. package/dist/types.d.ts.map +1 -1
  120. package/dist/types.js.map +1 -1
  121. package/dist/updateGlobal.d.ts.map +1 -1
  122. package/dist/updateGlobal.js +18 -4
  123. package/dist/updateGlobal.js.map +1 -1
  124. package/dist/updateGlobalVersion.d.ts +2 -2
  125. package/dist/updateGlobalVersion.d.ts.map +1 -1
  126. package/dist/updateGlobalVersion.js +19 -4
  127. package/dist/updateGlobalVersion.js.map +1 -1
  128. package/dist/updateOne.d.ts.map +1 -1
  129. package/dist/updateOne.js +18 -4
  130. package/dist/updateOne.js.map +1 -1
  131. package/dist/updateVersion.d.ts +1 -1
  132. package/dist/updateVersion.d.ts.map +1 -1
  133. package/dist/updateVersion.js +18 -3
  134. package/dist/updateVersion.js.map +1 -1
  135. package/dist/upsert.d.ts +3 -0
  136. package/dist/upsert.d.ts.map +1 -0
  137. package/dist/upsert.js +15 -0
  138. package/dist/upsert.js.map +1 -0
  139. package/dist/utilities/buildJoinAggregation.d.ts +18 -0
  140. package/dist/utilities/buildJoinAggregation.d.ts.map +1 -0
  141. package/dist/utilities/buildJoinAggregation.js +159 -0
  142. package/dist/utilities/buildJoinAggregation.js.map +1 -0
  143. package/dist/utilities/buildProjectionFromSelect.d.ts +8 -0
  144. package/dist/utilities/buildProjectionFromSelect.d.ts.map +1 -0
  145. package/dist/utilities/buildProjectionFromSelect.js +171 -0
  146. package/dist/utilities/buildProjectionFromSelect.js.map +1 -0
  147. package/dist/utilities/getDBName.d.ts.map +1 -1
  148. package/dist/utilities/getDBName.js +3 -1
  149. package/dist/utilities/getDBName.js.map +1 -1
  150. package/dist/utilities/handleError.js +2 -2
  151. package/dist/utilities/handleError.js.map +1 -1
  152. package/dist/utilities/sanitizeInternalFields.d.ts +1 -2
  153. package/dist/utilities/sanitizeInternalFields.d.ts.map +1 -1
  154. package/dist/utilities/sanitizeInternalFields.js +1 -2
  155. package/dist/utilities/sanitizeInternalFields.js.map +1 -1
  156. package/dist/utilities/sanitizeRelationshipIDs.d.ts +9 -0
  157. package/dist/utilities/sanitizeRelationshipIDs.d.ts.map +1 -0
  158. package/dist/utilities/sanitizeRelationshipIDs.js +125 -0
  159. package/dist/utilities/sanitizeRelationshipIDs.js.map +1 -0
  160. package/dist/utilities/sanitizeRelationshipIDs.spec.js +408 -0
  161. package/dist/utilities/sanitizeRelationshipIDs.spec.js.map +1 -0
  162. package/dist/withSession.d.ts +1 -1
  163. package/dist/withSession.d.ts.map +1 -1
  164. package/dist/withSession.js +5 -3
  165. package/dist/withSession.js.map +1 -1
  166. package/license.md +22 -0
  167. package/package.json +24 -11
  168. package/dist/queries/mock.js +0 -2
  169. package/dist/queries/mock.js.map +0 -1
@@ -0,0 +1,141 @@
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
+ if (docs.length === 0) {
15
+ break;
16
+ }
17
+ hasNext = docs.length > batchSize;
18
+ if (hasNext) {
19
+ docs.pop();
20
+ }
21
+ for (const doc of docs){
22
+ sanitizeRelationshipIDs({
23
+ config,
24
+ data: doc,
25
+ fields
26
+ });
27
+ }
28
+ await Model.collection.bulkWrite(docs.map((doc)=>({
29
+ updateOne: {
30
+ filter: {
31
+ _id: doc._id
32
+ },
33
+ update: {
34
+ $set: doc
35
+ }
36
+ }
37
+ })), {
38
+ session
39
+ });
40
+ skip += batchSize;
41
+ }
42
+ };
43
+ const hasRelationshipOrUploadField = ({ fields })=>{
44
+ for (const field of fields){
45
+ if (field.type === 'relationship' || field.type === 'upload') {
46
+ return true;
47
+ }
48
+ if ('fields' in field) {
49
+ if (hasRelationshipOrUploadField({
50
+ fields: field.fields
51
+ })) {
52
+ return true;
53
+ }
54
+ }
55
+ if ('blocks' in field) {
56
+ for (const block of field.blocks){
57
+ if (hasRelationshipOrUploadField({
58
+ fields: block.fields
59
+ })) {
60
+ return true;
61
+ }
62
+ }
63
+ }
64
+ if ('tabs' in field) {
65
+ for (const tab of field.tabs){
66
+ if (hasRelationshipOrUploadField({
67
+ fields: tab.fields
68
+ })) {
69
+ return true;
70
+ }
71
+ }
72
+ }
73
+ }
74
+ return false;
75
+ };
76
+ export async function migrateRelationshipsV2_V3({ batchSize, req }) {
77
+ const { payload } = req;
78
+ const db = payload.db;
79
+ const config = payload.config;
80
+ const { session } = await withSession(db, req);
81
+ for (const collection of payload.config.collections.filter(hasRelationshipOrUploadField)){
82
+ payload.logger.info(`Migrating collection "${collection.slug}"`);
83
+ await migrateModelWithBatching({
84
+ batchSize,
85
+ config,
86
+ fields: collection.fields,
87
+ Model: db.collections[collection.slug],
88
+ session
89
+ });
90
+ payload.logger.info(`Migrated collection "${collection.slug}"`);
91
+ if (collection.versions) {
92
+ payload.logger.info(`Migrating collection versions "${collection.slug}"`);
93
+ await migrateModelWithBatching({
94
+ batchSize,
95
+ config,
96
+ fields: buildVersionCollectionFields(config, collection),
97
+ Model: db.versions[collection.slug],
98
+ session
99
+ });
100
+ payload.logger.info(`Migrated collection versions "${collection.slug}"`);
101
+ }
102
+ }
103
+ const { globals: GlobalsModel } = db;
104
+ for (const global of payload.config.globals.filter(hasRelationshipOrUploadField)){
105
+ payload.logger.info(`Migrating global "${global.slug}"`);
106
+ const doc = await GlobalsModel.findOne({
107
+ globalType: {
108
+ $eq: global.slug
109
+ }
110
+ }, {}, {
111
+ lean: true,
112
+ session
113
+ });
114
+ sanitizeRelationshipIDs({
115
+ config,
116
+ data: doc,
117
+ fields: global.fields
118
+ });
119
+ await GlobalsModel.collection.updateOne({
120
+ globalType: global.slug
121
+ }, {
122
+ $set: doc
123
+ }, {
124
+ session
125
+ });
126
+ payload.logger.info(`Migrated global "${global.slug}"`);
127
+ if (global.versions) {
128
+ payload.logger.info(`Migrating global versions "${global.slug}"`);
129
+ await migrateModelWithBatching({
130
+ batchSize,
131
+ config,
132
+ fields: buildVersionGlobalFields(config, global),
133
+ Model: db.versions[global.slug],
134
+ session
135
+ });
136
+ payload.logger.info(`Migrated global versions "${global.slug}"`);
137
+ }
138
+ }
139
+ }
140
+
141
+ //# 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(\n {},\n {},\n {\n lean: true,\n limit: batchSize + 1,\n session,\n skip,\n },\n )\n\n if (docs.length === 0) {\n break\n }\n\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.collection.bulkWrite(\n docs.map((doc) => ({\n updateOne: {\n filter: { _id: doc._id },\n update: {\n $set: doc,\n },\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.collection.updateOne(\n {\n globalType: global.slug,\n },\n { $set: 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","collection","bulkWrite","map","updateOne","filter","_id","update","$set","hasRelationshipOrUploadField","field","type","block","blocks","tab","tabs","migrateRelationshipsV2_V3","req","payload","db","collections","logger","info","slug","versions","globals","GlobalsModel","global","findOne","globalType","$eq"],"mappings":"AAGA,SAASA,4BAA4B,EAAEC,wBAAwB,QAAQ,UAAS;AAIhF,SAASC,uBAAuB,QAAQ,0CAAyC;AACjF,SAASC,WAAW,QAAQ,oBAAmB;AAE/C,MAAMC,2BAA2B,OAAO,EACtCC,SAAS,EACTC,MAAM,EACNC,MAAM,EACNC,KAAK,EACLC,OAAO,EAOR;IACC,IAAIC,UAAU;IACd,IAAIC,OAAO;IAEX,MAAOD,QAAS;QACd,MAAME,OAAO,MAAMJ,MAAMK,IAAI,CAC3B,CAAC,GACD,CAAC,GACD;YACEC,MAAM;YACNC,OAAOV,YAAY;YACnBI;YACAE;QACF;QAGF,IAAIC,KAAKI,MAAM,KAAK,GAAG;YACrB;QACF;QAEAN,UAAUE,KAAKI,MAAM,GAAGX;QAExB,IAAIK,SAAS;YACXE,KAAKK,GAAG;QACV;QAEA,KAAK,MAAMC,OAAON,KAAM;YACtBV,wBAAwB;gBAAEI;gBAAQa,MAAMD;gBAAKX;YAAO;QACtD;QAEA,MAAMC,MAAMY,UAAU,CAACC,SAAS,CAC9BT,KAAKU,GAAG,CAAC,CAACJ,MAAS,CAAA;gBACjBK,WAAW;oBACTC,QAAQ;wBAAEC,KAAKP,IAAIO,GAAG;oBAAC;oBACvBC,QAAQ;wBACNC,MAAMT;oBACR;gBACF;YACF,CAAA,IACA;YAAET;QAAQ;QAGZE,QAAQN;IACV;AACF;AAEA,MAAMuB,+BAA+B,CAAC,EAAErB,MAAM,EAAuB;IACnE,KAAK,MAAMsB,SAAStB,OAAQ;QAC1B,IAAIsB,MAAMC,IAAI,KAAK,kBAAkBD,MAAMC,IAAI,KAAK,UAAU;YAC5D,OAAO;QACT;QAEA,IAAI,YAAYD,OAAO;YACrB,IAAID,6BAA6B;gBAAErB,QAAQsB,MAAMtB,MAAM;YAAC,IAAI;gBAC1D,OAAO;YACT;QACF;QAEA,IAAI,YAAYsB,OAAO;YACrB,KAAK,MAAME,SAASF,MAAMG,MAAM,CAAE;gBAChC,IAAIJ,6BAA6B;oBAAErB,QAAQwB,MAAMxB,MAAM;gBAAC,IAAI;oBAC1D,OAAO;gBACT;YACF;QACF;QAEA,IAAI,UAAUsB,OAAO;YACnB,KAAK,MAAMI,OAAOJ,MAAMK,IAAI,CAAE;gBAC5B,IAAIN,6BAA6B;oBAAErB,QAAQ0B,IAAI1B,MAAM;gBAAC,IAAI;oBACxD,OAAO;gBACT;YACF;QACF;IACF;IAEA,OAAO;AACT;AAEA,OAAO,eAAe4B,0BAA0B,EAC9C9B,SAAS,EACT+B,GAAG,EAIJ;IACC,MAAM,EAAEC,OAAO,EAAE,GAAGD;IACpB,MAAME,KAAKD,QAAQC,EAAE;IACrB,MAAMhC,SAAS+B,QAAQ/B,MAAM;IAE7B,MAAM,EAAEG,OAAO,EAAE,GAAG,MAAMN,YAAYmC,IAAIF;IAE1C,KAAK,MAAMhB,cAAciB,QAAQ/B,MAAM,CAACiC,WAAW,CAACf,MAAM,CAACI,8BAA+B;QACxFS,QAAQG,MAAM,CAACC,IAAI,CAAC,CAAC,sBAAsB,EAAErB,WAAWsB,IAAI,CAAC,CAAC,CAAC;QAE/D,MAAMtC,yBAAyB;YAC7BC;YACAC;YACAC,QAAQa,WAAWb,MAAM;YACzBC,OAAO8B,GAAGC,WAAW,CAACnB,WAAWsB,IAAI,CAAC;YACtCjC;QACF;QAEA4B,QAAQG,MAAM,CAACC,IAAI,CAAC,CAAC,qBAAqB,EAAErB,WAAWsB,IAAI,CAAC,CAAC,CAAC;QAE9D,IAAItB,WAAWuB,QAAQ,EAAE;YACvBN,QAAQG,MAAM,CAACC,IAAI,CAAC,CAAC,+BAA+B,EAAErB,WAAWsB,IAAI,CAAC,CAAC,CAAC;YAExE,MAAMtC,yBAAyB;gBAC7BC;gBACAC;gBACAC,QAAQP,6BAA6BM,QAAQc;gBAC7CZ,OAAO8B,GAAGK,QAAQ,CAACvB,WAAWsB,IAAI,CAAC;gBACnCjC;YACF;YAEA4B,QAAQG,MAAM,CAACC,IAAI,CAAC,CAAC,8BAA8B,EAAErB,WAAWsB,IAAI,CAAC,CAAC,CAAC;QACzE;IACF;IAEA,MAAM,EAAEE,SAASC,YAAY,EAAE,GAAGP;IAElC,KAAK,MAAMQ,UAAUT,QAAQ/B,MAAM,CAACsC,OAAO,CAACpB,MAAM,CAACI,8BAA+B;QAChFS,QAAQG,MAAM,CAACC,IAAI,CAAC,CAAC,kBAAkB,EAAEK,OAAOJ,IAAI,CAAC,CAAC,CAAC;QAEvD,MAAMxB,MAAM,MAAM2B,aAAaE,OAAO,CACpC;YACEC,YAAY;gBACVC,KAAKH,OAAOJ,IAAI;YAClB;QACF,GACA,CAAC,GACD;YAAE5B,MAAM;YAAML;QAAQ;QAGxBP,wBAAwB;YAAEI;YAAQa,MAAMD;YAAKX,QAAQuC,OAAOvC,MAAM;QAAC;QAEnE,MAAMsC,aAAazB,UAAU,CAACG,SAAS,CACrC;YACEyB,YAAYF,OAAOJ,IAAI;QACzB,GACA;YAAEf,MAAMT;QAAI,GACZ;YAAET;QAAQ;QAGZ4B,QAAQG,MAAM,CAACC,IAAI,CAAC,CAAC,iBAAiB,EAAEK,OAAOJ,IAAI,CAAC,CAAC,CAAC;QAEtD,IAAII,OAAOH,QAAQ,EAAE;YACnBN,QAAQG,MAAM,CAACC,IAAI,CAAC,CAAC,2BAA2B,EAAEK,OAAOJ,IAAI,CAAC,CAAC,CAAC;YAEhE,MAAMtC,yBAAyB;gBAC7BC;gBACAC;gBACAC,QAAQN,yBAAyBK,QAAQwC;gBACzCtC,OAAO8B,GAAGK,QAAQ,CAACG,OAAOJ,IAAI,CAAC;gBAC/BjC;YACF;YAEA4B,QAAQG,MAAM,CAACC,IAAI,CAAC,CAAC,0BAA0B,EAAEK,OAAOJ,IAAI,CAAC,CAAC,CAAC;QACjE;IACF;AACF"}
@@ -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 };
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"],"names":["imports","upSQL"],"mappings":"AAAA,MAAMA,UAAU,CAAC,kFAAkF,CAAC;AACpG,MAAMC,QAAQ,CAAC;;;;AAIf,CAAC;AACD,SAASD,OAAO,EAAEC,KAAK,GAAE"}
@@ -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 };
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"],"names":["imports","upSQL"],"mappings":"AAAA,MAAMA,UAAU,CAAC,6EAA6E,CAAC;AAC/F,MAAMC,QAAQ,CAAC;;;AAGf,CAAC;AACD,SAASD,OAAO,EAAEC,KAAK,GAAE"}
@@ -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,23 @@ 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
+ payload,
53
54
  val
54
55
  });
55
- if (rawQuery) return {
56
- value: rawQuery
57
- };
56
+ if (!sanitizedQueryValue) {
57
+ return undefined;
58
+ }
59
+ const { operator: formattedOperator, rawQuery, val: formattedValue } = sanitizedQueryValue;
60
+ if (rawQuery) {
61
+ return {
62
+ value: rawQuery
63
+ };
64
+ }
58
65
  // If there are multiple collections to search through,
59
66
  // Recursively build up a list of query constraints
60
67
  if (paths.length > 1) {
@@ -84,7 +91,7 @@ const subQueryOptions = {
84
91
  result.forEach((doc)=>{
85
92
  const stringID = doc._id.toString();
86
93
  $in.push(stringID);
87
- if (mongoose.Types.ObjectId.isValid(stringID)) {
94
+ if (Types.ObjectId.isValid(stringID)) {
88
95
  $in.push(doc._id);
89
96
  }
90
97
  });
@@ -107,7 +114,7 @@ const subQueryOptions = {
107
114
  }
108
115
  const subQuery = priorQueryResult.value;
109
116
  const result = await SubModel.find(subQuery, subQueryOptions);
110
- const $in = result.map((doc)=>doc._id.toString());
117
+ const $in = result.map((doc)=>doc._id);
111
118
  // If it is the last recursion
112
119
  // then pass through the search param
113
120
  if (i + 1 === pathsToQuery.length) {
@@ -133,7 +140,9 @@ const subQueryOptions = {
133
140
  if (field.type === 'relationship' || field.type === 'upload') {
134
141
  let hasNumberIDRelation;
135
142
  let multiIDCondition = '$or';
136
- if (operatorKey === '$ne') multiIDCondition = '$and';
143
+ if (operatorKey === '$ne') {
144
+ multiIDCondition = '$and';
145
+ }
137
146
  const result = {
138
147
  value: {
139
148
  [multiIDCondition]: [
@@ -146,10 +155,10 @@ const subQueryOptions = {
146
155
  }
147
156
  };
148
157
  if (typeof formattedValue === 'string') {
149
- if (mongoose.Types.ObjectId.isValid(formattedValue)) {
158
+ if (Types.ObjectId.isValid(formattedValue)) {
150
159
  result.value[multiIDCondition].push({
151
160
  [path]: {
152
- [operatorKey]: ObjectId(formattedValue)
161
+ [operatorKey]: new Types.ObjectId(formattedValue)
153
162
  }
154
163
  });
155
164
  } else {
@@ -161,11 +170,13 @@ const subQueryOptions = {
161
170
  hasNumberIDRelation = true;
162
171
  }
163
172
  });
164
- if (hasNumberIDRelation) result.value[multiIDCondition].push({
165
- [path]: {
166
- [operatorKey]: parseFloat(formattedValue)
167
- }
168
- });
173
+ if (hasNumberIDRelation) {
174
+ result.value[multiIDCondition].push({
175
+ [path]: {
176
+ [operatorKey]: parseFloat(formattedValue)
177
+ }
178
+ });
179
+ }
169
180
  }
170
181
  }
171
182
  if (result.value[multiIDCondition].length > 1) {