@payloadcms/db-mongodb 4.0.0-internal.183b315 → 4.0.0-internal.1a2a79e

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (211) hide show
  1. package/LICENSE.md +1 -1
  2. package/dist/connect.d.ts.map +1 -1
  3. package/dist/connect.js +9 -2
  4. package/dist/connect.js.map +1 -1
  5. package/dist/count.d.ts.map +1 -1
  6. package/dist/count.js +33 -4
  7. package/dist/count.js.map +1 -1
  8. package/dist/countGlobalVersions.d.ts.map +1 -1
  9. package/dist/countGlobalVersions.js +1 -0
  10. package/dist/countGlobalVersions.js.map +1 -1
  11. package/dist/countVersions.d.ts.map +1 -1
  12. package/dist/countVersions.js +36 -4
  13. package/dist/countVersions.js.map +1 -1
  14. package/dist/create.d.ts.map +1 -1
  15. package/dist/create.js +2 -1
  16. package/dist/create.js.map +1 -1
  17. package/dist/createGlobalVersion.d.ts +1 -1
  18. package/dist/createGlobalVersion.d.ts.map +1 -1
  19. package/dist/createGlobalVersion.js +23 -2
  20. package/dist/createGlobalVersion.js.map +1 -1
  21. package/dist/createMigration.d.ts.map +1 -1
  22. package/dist/createMigration.js +9 -2
  23. package/dist/createMigration.js.map +1 -1
  24. package/dist/createVersion.d.ts.map +1 -1
  25. package/dist/createVersion.js +17 -4
  26. package/dist/createVersion.js.map +1 -1
  27. package/dist/deleteBranchGlobal.d.ts +10 -0
  28. package/dist/deleteBranchGlobal.d.ts.map +1 -0
  29. package/dist/deleteBranchGlobal.js +22 -0
  30. package/dist/deleteBranchGlobal.js.map +1 -0
  31. package/dist/deleteMany.d.ts.map +1 -1
  32. package/dist/deleteMany.js +1 -0
  33. package/dist/deleteMany.js.map +1 -1
  34. package/dist/deleteOne.d.ts.map +1 -1
  35. package/dist/deleteOne.js +20 -1
  36. package/dist/deleteOne.js.map +1 -1
  37. package/dist/deleteVersions.d.ts.map +1 -1
  38. package/dist/deleteVersions.js +1 -0
  39. package/dist/deleteVersions.js.map +1 -1
  40. package/dist/exports/migration-utils.d.ts +3 -0
  41. package/dist/exports/migration-utils.d.ts.map +1 -1
  42. package/dist/exports/migration-utils.js +3 -0
  43. package/dist/exports/migration-utils.js.map +1 -1
  44. package/dist/find.d.ts.map +1 -1
  45. package/dist/find.js +44 -8
  46. package/dist/find.js.map +1 -1
  47. package/dist/findDistinct.d.ts.map +1 -1
  48. package/dist/findDistinct.js +115 -12
  49. package/dist/findDistinct.js.map +1 -1
  50. package/dist/findGlobal.d.ts.map +1 -1
  51. package/dist/findGlobal.js +34 -5
  52. package/dist/findGlobal.js.map +1 -1
  53. package/dist/findGlobalVersions.d.ts.map +1 -1
  54. package/dist/findGlobalVersions.js +10 -2
  55. package/dist/findGlobalVersions.js.map +1 -1
  56. package/dist/findOne.d.ts.map +1 -1
  57. package/dist/findOne.js +43 -5
  58. package/dist/findOne.js.map +1 -1
  59. package/dist/findVersions.d.ts.map +1 -1
  60. package/dist/findVersions.js +49 -5
  61. package/dist/findVersions.js.map +1 -1
  62. package/dist/index.d.ts.map +1 -1
  63. package/dist/index.js +4 -0
  64. package/dist/index.js.map +1 -1
  65. package/dist/init.d.ts.map +1 -1
  66. package/dist/init.js +89 -67
  67. package/dist/init.js.map +1 -1
  68. package/dist/migrateFresh.d.ts +4 -2
  69. package/dist/migrateFresh.d.ts.map +1 -1
  70. package/dist/migrateFresh.js +21 -6
  71. package/dist/migrateFresh.js.map +1 -1
  72. package/dist/models/buildCollectionSchema.d.ts +8 -2
  73. package/dist/models/buildCollectionSchema.d.ts.map +1 -1
  74. package/dist/models/buildCollectionSchema.js +4 -2
  75. package/dist/models/buildCollectionSchema.js.map +1 -1
  76. package/dist/models/buildGlobalModel.d.ts +5 -1
  77. package/dist/models/buildGlobalModel.d.ts.map +1 -1
  78. package/dist/models/buildGlobalModel.js +34 -3
  79. package/dist/models/buildGlobalModel.js.map +1 -1
  80. package/dist/models/buildSchema.d.ts +4 -0
  81. package/dist/models/buildSchema.d.ts.map +1 -1
  82. package/dist/models/buildSchema.js +115 -37
  83. package/dist/models/buildSchema.js.map +1 -1
  84. package/dist/models/schemaBuildContext.d.ts +21 -0
  85. package/dist/models/schemaBuildContext.d.ts.map +1 -0
  86. package/dist/models/schemaBuildContext.js +29 -0
  87. package/dist/models/schemaBuildContext.js.map +1 -0
  88. package/dist/predefinedMigrations/branching.d.ts +4 -0
  89. package/dist/predefinedMigrations/branching.d.ts.map +1 -0
  90. package/dist/predefinedMigrations/branching.js +9 -0
  91. package/dist/predefinedMigrations/branching.js.map +1 -0
  92. package/dist/predefinedMigrations/localize-status.d.ts +4 -0
  93. package/dist/predefinedMigrations/localize-status.d.ts.map +1 -0
  94. package/dist/predefinedMigrations/localize-status.js +9 -0
  95. package/dist/predefinedMigrations/localize-status.js.map +1 -0
  96. package/dist/predefinedMigrations/migrateBranching.d.ts +15 -0
  97. package/dist/predefinedMigrations/migrateBranching.d.ts.map +1 -0
  98. package/dist/predefinedMigrations/migrateBranching.js +88 -0
  99. package/dist/predefinedMigrations/migrateBranching.js.map +1 -0
  100. package/dist/predefinedMigrations/migrateLocalizeStatus.d.ts +27 -0
  101. package/dist/predefinedMigrations/migrateLocalizeStatus.d.ts.map +1 -0
  102. package/dist/predefinedMigrations/migrateLocalizeStatus.js +324 -0
  103. package/dist/predefinedMigrations/migrateLocalizeStatus.js.map +1 -0
  104. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts.map +1 -1
  105. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js +4 -4
  106. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js.map +1 -1
  107. package/dist/predefinedMigrations/migrateSizesToVariants.d.ts +13 -0
  108. package/dist/predefinedMigrations/migrateSizesToVariants.d.ts.map +1 -0
  109. package/dist/predefinedMigrations/migrateSizesToVariants.js +368 -0
  110. package/dist/predefinedMigrations/migrateSizesToVariants.js.map +1 -0
  111. package/dist/predefinedMigrations/sizes-to-variants.d.ts +5 -0
  112. package/dist/predefinedMigrations/sizes-to-variants.d.ts.map +1 -0
  113. package/dist/predefinedMigrations/sizes-to-variants.js +8 -0
  114. package/dist/predefinedMigrations/sizes-to-variants.js.map +1 -0
  115. package/dist/queries/buildAndOrConditions.d.ts +4 -2
  116. package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
  117. package/dist/queries/buildAndOrConditions.js +3 -1
  118. package/dist/queries/buildAndOrConditions.js.map +1 -1
  119. package/dist/queries/buildBranchVisibility.d.ts +11 -0
  120. package/dist/queries/buildBranchVisibility.d.ts.map +1 -0
  121. package/dist/queries/buildBranchVisibility.js +204 -0
  122. package/dist/queries/buildBranchVisibility.js.map +1 -0
  123. package/dist/queries/buildQuery.d.ts +4 -2
  124. package/dist/queries/buildQuery.d.ts.map +1 -1
  125. package/dist/queries/buildQuery.js +3 -1
  126. package/dist/queries/buildQuery.js.map +1 -1
  127. package/dist/queries/buildSearchParams.d.ts +4 -2
  128. package/dist/queries/buildSearchParams.d.ts.map +1 -1
  129. package/dist/queries/buildSearchParams.js +338 -24
  130. package/dist/queries/buildSearchParams.js.map +1 -1
  131. package/dist/queries/buildSortParam.d.ts.map +1 -1
  132. package/dist/queries/getBuildQueryPlugin.d.ts +3 -1
  133. package/dist/queries/getBuildQueryPlugin.d.ts.map +1 -1
  134. package/dist/queries/getBuildQueryPlugin.js +3 -1
  135. package/dist/queries/getBuildQueryPlugin.js.map +1 -1
  136. package/dist/queries/getLocalizedSortProperty.d.ts.map +1 -1
  137. package/dist/queries/getLocalizedSortProperty.js +1 -1
  138. package/dist/queries/getLocalizedSortProperty.js.map +1 -1
  139. package/dist/queries/operatorMap.d.ts.map +1 -1
  140. package/dist/queries/parseParams.d.ts +4 -2
  141. package/dist/queries/parseParams.d.ts.map +1 -1
  142. package/dist/queries/parseParams.js +5 -1
  143. package/dist/queries/parseParams.js.map +1 -1
  144. package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
  145. package/dist/queries/sanitizeQueryValue.js +2 -3
  146. package/dist/queries/sanitizeQueryValue.js.map +1 -1
  147. package/dist/queryDrafts.d.ts.map +1 -1
  148. package/dist/queryDrafts.js +38 -7
  149. package/dist/queryDrafts.js.map +1 -1
  150. package/dist/testCredentials.d.ts.map +1 -1
  151. package/dist/transactions/beginTransaction.d.ts.map +1 -1
  152. package/dist/transactions/beginTransaction.js +0 -1
  153. package/dist/transactions/beginTransaction.js.map +1 -1
  154. package/dist/transactions/commitTransaction.d.ts.map +1 -1
  155. package/dist/transactions/commitTransaction.js +68 -7
  156. package/dist/transactions/commitTransaction.js.map +1 -1
  157. package/dist/transactions/rollbackTransaction.d.ts.map +1 -1
  158. package/dist/transactions/rollbackTransaction.js +10 -9
  159. package/dist/transactions/rollbackTransaction.js.map +1 -1
  160. package/dist/updateGlobal.d.ts.map +1 -1
  161. package/dist/updateGlobal.js +89 -9
  162. package/dist/updateGlobal.js.map +1 -1
  163. package/dist/updateGlobalVersion.d.ts.map +1 -1
  164. package/dist/updateGlobalVersion.js +3 -2
  165. package/dist/updateGlobalVersion.js.map +1 -1
  166. package/dist/updateJobs.d.ts.map +1 -1
  167. package/dist/updateJobs.js +71 -14
  168. package/dist/updateJobs.js.map +1 -1
  169. package/dist/updateMany.d.ts.map +1 -1
  170. package/dist/updateMany.js +3 -2
  171. package/dist/updateMany.js.map +1 -1
  172. package/dist/updateOne.d.ts.map +1 -1
  173. package/dist/updateOne.js +30 -4
  174. package/dist/updateOne.js.map +1 -1
  175. package/dist/updateVersion.d.ts.map +1 -1
  176. package/dist/updateVersion.js +3 -2
  177. package/dist/updateVersion.js.map +1 -1
  178. package/dist/upsertBranchGlobalChange.d.ts +3 -0
  179. package/dist/upsertBranchGlobalChange.d.ts.map +1 -0
  180. package/dist/upsertBranchGlobalChange.js +28 -0
  181. package/dist/upsertBranchGlobalChange.js.map +1 -0
  182. package/dist/utilities/aggregatePaginate.d.ts +2 -1
  183. package/dist/utilities/aggregatePaginate.d.ts.map +1 -1
  184. package/dist/utilities/aggregatePaginate.js +21 -5
  185. package/dist/utilities/aggregatePaginate.js.map +1 -1
  186. package/dist/utilities/buildJoinAggregation.d.ts +4 -2
  187. package/dist/utilities/buildJoinAggregation.d.ts.map +1 -1
  188. package/dist/utilities/buildJoinAggregation.js +124 -21
  189. package/dist/utilities/buildJoinAggregation.js.map +1 -1
  190. package/dist/utilities/buildProjectionFromSelect.d.ts.map +1 -1
  191. package/dist/utilities/buildProjectionFromSelect.js +1 -1
  192. package/dist/utilities/buildProjectionFromSelect.js.map +1 -1
  193. package/dist/utilities/getDBName.d.ts.map +1 -1
  194. package/dist/utilities/getEntity.d.ts +1 -1
  195. package/dist/utilities/getEntity.d.ts.map +1 -1
  196. package/dist/utilities/handleError.d.ts.map +1 -1
  197. package/dist/utilities/isObjectID.d.ts.map +1 -1
  198. package/dist/utilities/resolveJoins.d.ts +6 -2
  199. package/dist/utilities/resolveJoins.d.ts.map +1 -1
  200. package/dist/utilities/resolveJoins.js +114 -26
  201. package/dist/utilities/resolveJoins.js.map +1 -1
  202. package/dist/utilities/transform.d.ts.map +1 -1
  203. package/dist/utilities/transform.js +25 -34
  204. package/dist/utilities/transform.js.map +1 -1
  205. package/package.json +18 -21
  206. package/dist/queries/buildSortParam.spec.js +0 -123
  207. package/dist/queries/buildSortParam.spec.js.map +0 -1
  208. package/dist/queries/getLocalizedSortProperty.spec.js +0 -215
  209. package/dist/queries/getLocalizedSortProperty.spec.js.map +0 -1
  210. package/dist/utilities/transform.spec.js +0 -479
  211. package/dist/utilities/transform.spec.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/predefinedMigrations/migrateRelationshipsV2_V3.ts"],"sourcesContent":["import type { ClientSession, Model } from 'mongoose'\nimport type { Field, PayloadRequest } from 'payload'\n\nimport { buildVersionCollectionFields, buildVersionGlobalFields } from 'payload'\n\nimport type { MongooseAdapter } from '../index.js'\n\nimport { getCollection, getGlobal } from '../utilities/getEntity.js'\nimport { getSession } from '../utilities/getSession.js'\nimport { transform } from '../utilities/transform.js'\n\nconst migrateModelWithBatching = async ({\n batchSize,\n db,\n fields,\n Model,\n parentIsLocalized,\n session,\n}: {\n batchSize: number\n db: MongooseAdapter\n fields: Field[]\n Model: Model<any>\n parentIsLocalized: boolean\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 transform({ adapter: db, data: doc, fields, operation: 'write', parentIsLocalized })\n }\n\n await Model.collection.bulkWrite(\n // @ts-expect-error bulkWrite has a weird type, insertOne, updateMany etc are required here as well.\n docs.map((doc) => ({\n updateOne: {\n filter: { _id: doc._id },\n update: {\n $set: doc,\n },\n },\n })),\n {\n session, // Timestamps are manually added by the write transform\n timestamps: false,\n },\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 (typeof block === 'string') {\n // Skip - string blocks have been added in v3 and thus don't need to be migrated\n continue\n }\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 getSession(db, req)\n\n for (const collection of payload.config.collections) {\n if (hasRelationshipOrUploadField(collection)) {\n payload.logger.info(`Migrating collection \"${collection.slug}\"`)\n\n const { Model } = getCollection({ adapter: db, collectionSlug: collection.slug })\n\n await migrateModelWithBatching({\n batchSize,\n db,\n fields: collection.fields,\n Model,\n parentIsLocalized: false,\n session,\n })\n\n payload.logger.info(`Migrated collection \"${collection.slug}\"`)\n }\n\n if (collection.versions) {\n payload.logger.info(`Migrating collection versions \"${collection.slug}\"`)\n\n const { Model } = getCollection({\n adapter: db,\n collectionSlug: collection.slug,\n versions: true,\n })\n\n await migrateModelWithBatching({\n batchSize,\n db,\n fields: buildVersionCollectionFields(config, collection),\n Model,\n parentIsLocalized: false,\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) {\n if (hasRelationshipOrUploadField(global)) {\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 // in case if the global doesn't exist in the database yet (not saved)\n if (doc) {\n transform({\n adapter: db,\n data: doc,\n fields: global.fields,\n operation: 'write',\n })\n\n await GlobalsModel.collection.updateOne(\n {\n globalType: global.slug,\n },\n { $set: doc },\n { session },\n )\n }\n\n payload.logger.info(`Migrated global \"${global.slug}\"`)\n }\n\n if (global.versions) {\n payload.logger.info(`Migrating global versions \"${global.slug}\"`)\n\n const { Model } = getGlobal({ adapter: db, globalSlug: global.slug, versions: true })\n\n await migrateModelWithBatching({\n batchSize,\n db,\n fields: buildVersionGlobalFields(config, global),\n Model,\n parentIsLocalized: false,\n session,\n })\n\n payload.logger.info(`Migrated global versions \"${global.slug}\"`)\n }\n }\n}\n"],"names":["buildVersionCollectionFields","buildVersionGlobalFields","getCollection","getGlobal","getSession","transform","migrateModelWithBatching","batchSize","db","fields","Model","parentIsLocalized","session","hasNext","skip","docs","find","lean","limit","length","pop","doc","adapter","data","operation","collection","bulkWrite","map","updateOne","filter","_id","update","$set","timestamps","hasRelationshipOrUploadField","field","type","block","blocks","tab","tabs","migrateRelationshipsV2_V3","req","payload","config","collections","logger","info","slug","collectionSlug","versions","globals","GlobalsModel","global","findOne","globalType","$eq","globalSlug"],"mappings":"AAGA,SAASA,4BAA4B,EAAEC,wBAAwB,QAAQ,UAAS;AAIhF,SAASC,aAAa,EAAEC,SAAS,QAAQ,4BAA2B;AACpE,SAASC,UAAU,QAAQ,6BAA4B;AACvD,SAASC,SAAS,QAAQ,4BAA2B;AAErD,MAAMC,2BAA2B,OAAO,EACtCC,SAAS,EACTC,EAAE,EACFC,MAAM,EACNC,KAAK,EACLC,iBAAiB,EACjBC,OAAO,EAQR;IACC,IAAIC,UAAU;IACd,IAAIC,OAAO;IAEX,MAAOD,QAAS;QACd,MAAME,OAAO,MAAML,MAAMM,IAAI,CAC3B,CAAC,GACD,CAAC,GACD;YACEC,MAAM;YACNC,OAAOX,YAAY;YACnBK;YACAE;QACF;QAGF,IAAIC,KAAKI,MAAM,KAAK,GAAG;YACrB;QACF;QAEAN,UAAUE,KAAKI,MAAM,GAAGZ;QAExB,IAAIM,SAAS;YACXE,KAAKK,GAAG;QACV;QAEA,KAAK,MAAMC,OAAON,KAAM;YACtBV,UAAU;gBAAEiB,SAASd;gBAAIe,MAAMF;gBAAKZ;gBAAQe,WAAW;gBAASb;YAAkB;QACpF;QAEA,MAAMD,MAAMe,UAAU,CAACC,SAAS,CAC9B,oGAAoG;QACpGX,KAAKY,GAAG,CAAC,CAACN,MAAS,CAAA;gBACjBO,WAAW;oBACTC,QAAQ;wBAAEC,KAAKT,IAAIS,GAAG;oBAAC;oBACvBC,QAAQ;wBACNC,MAAMX;oBACR;gBACF;YACF,CAAA,IACA;YACET;YACAqB,YAAY;QACd;QAGFnB,QAAQP;IACV;AACF;AAEA,MAAM2B,+BAA+B,CAAC,EAAEzB,MAAM,EAAuB;IACnE,KAAK,MAAM0B,SAAS1B,OAAQ;QAC1B,IAAI0B,MAAMC,IAAI,KAAK,kBAAkBD,M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,IAAI,CAAC,CAAC,CAAC;QACxD;QAEA,IAAIK,OAAOH,QAAQ,EAAE;YACnBP,QAAQG,MAAM,CAACC,IAAI,CAAC,CAAC,2BAA2B,EAAEM,OAAOL,IAAI,CAAC,CAAC,CAAC;YAEhE,MAAM,EAAEtC,KAAK,EAAE,GAAGP,UAAU;gBAAEmB,SAASd;gBAAIiD,YAAYJ,OAAOL,IAAI;gBAAEE,UAAU;YAAK;YAEnF,MAAM5C,yBAAyB;gBAC7BC;gBACAC;gBACAC,QAAQR,yBAAyB2C,QAAQS;gBACzC3C;gBACAC,mBAAmB;gBACnBC;YACF;YAEA+B,QAAQG,MAAM,CAACC,IAAI,CAAC,CAAC,0BAA0B,EAAEM,OAAOL,IAAI,CAAC,CAAC,CAAC;QACjE;IACF;AACF"}
1
+ {"version":3,"sources":["../../src/predefinedMigrations/migrateRelationshipsV2_V3.ts"],"sourcesContent":["import type { ClientSession, Model } from 'mongoose'\nimport type { Field, PayloadRequest } from 'payload'\n\nimport { buildVersionCollectionFields, buildVersionGlobalFields } from 'payload'\n\nimport type { MongooseAdapter } from '../index.js'\n\nimport { getCollection, getGlobal } from '../utilities/getEntity.js'\nimport { getSession } from '../utilities/getSession.js'\nimport { transform } from '../utilities/transform.js'\n\nconst migrateModelWithBatching = async ({\n batchSize,\n db,\n fields,\n Model,\n parentIsLocalized,\n session,\n}: {\n batchSize: number\n db: MongooseAdapter\n fields: Field[]\n Model: Model<any>\n parentIsLocalized: boolean\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 transform({ adapter: db, data: doc, fields, operation: 'write', parentIsLocalized })\n }\n\n // Writing through the driver collection skips Mongoose timestamps entirely,\n // which is what we want here - timestamps are added by the write transform above\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 (typeof block === 'string') {\n // Skip - string blocks have been added in v3 and thus don't need to be migrated\n continue\n }\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 getSession(db, req)\n\n for (const collection of payload.config.collections) {\n if (hasRelationshipOrUploadField(collection)) {\n payload.logger.info(`Migrating collection \"${collection.slug}\"`)\n\n const { Model } = getCollection({ adapter: db, collectionSlug: collection.slug })\n\n await migrateModelWithBatching({\n batchSize,\n db,\n fields: collection.fields,\n Model,\n parentIsLocalized: false,\n session,\n })\n\n payload.logger.info(`Migrated collection \"${collection.slug}\"`)\n }\n\n if (collection.versions) {\n payload.logger.info(`Migrating collection versions \"${collection.slug}\"`)\n\n const { Model } = getCollection({\n adapter: db,\n collectionSlug: collection.slug,\n versions: true,\n })\n\n await migrateModelWithBatching({\n batchSize,\n db,\n fields: buildVersionCollectionFields(config, collection),\n Model,\n parentIsLocalized: false,\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) {\n if (hasRelationshipOrUploadField(global)) {\n payload.logger.info(`Migrating global \"${global.slug}\"`)\n\n const doc = (await GlobalsModel.findOne(\n {\n globalType: {\n $eq: global.slug,\n },\n },\n {},\n { lean: true, session },\n )) as null | Record<string, unknown>\n\n // in case if the global doesn't exist in the database yet (not saved)\n if (doc) {\n transform({\n adapter: db,\n data: doc,\n fields: global.fields,\n operation: 'write',\n })\n\n await GlobalsModel.collection.updateOne(\n {\n globalType: global.slug,\n },\n { $set: doc },\n { session },\n )\n }\n\n payload.logger.info(`Migrated global \"${global.slug}\"`)\n }\n\n if (global.versions) {\n payload.logger.info(`Migrating global versions \"${global.slug}\"`)\n\n const { Model } = getGlobal({ adapter: db, globalSlug: global.slug, versions: true })\n\n await migrateModelWithBatching({\n batchSize,\n db,\n fields: buildVersionGlobalFields(config, global),\n Model,\n parentIsLocalized: false,\n session,\n })\n\n payload.logger.info(`Migrated global versions \"${global.slug}\"`)\n }\n }\n}\n"],"names":["buildVersionCollectionFields","buildVersionGlobalFields","getCollection","getGlobal","getSession","transform","migrateModelWithBatching","batchSize","db","fields","Model","parentIsLocalized","session","hasNext","skip","docs","find","lean","limit","length","pop","doc","adapter","data","operation","collection","bulkWrite","map","updateOne","filter","_id","update","$set","hasRelationshipOrUploadField","field","type","block","blocks","tab","tabs","migrateRelationshipsV2_V3","req","payload","config","collections","logger","info","slug","collectionSlug","versions","globals","GlobalsModel","global","findOne","globalType","$eq","globalSlug"],"mappings":"AAGA,SAASA,4BAA4B,EAAEC,wBAAwB,QAAQ,UAAS;AAIhF,SAASC,aAAa,EAAEC,SAAS,QAAQ,4BAA2B;AACpE,SAASC,UAAU,QAAQ,6BAA4B;AACvD,SAASC,SAAS,QAAQ,4BAA2B;AAErD,MAAMC,2BAA2B,OAAO,EACtCC,SAAS,EACTC,EAAE,EACFC,MAAM,EACNC,KAAK,EACLC,iBAAiB,EACjBC,OAAO,EAQR;IACC,IAAIC,UAAU;IACd,IAAIC,OAAO;IAEX,MAAOD,QAAS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jE;IACF;AACF"}
@@ -0,0 +1,13 @@
1
+ import type { Payload, PayloadRequest } from 'payload';
2
+ /**
3
+ * Moves every upload collection's stored image sizes between the legacy `sizes` field and
4
+ * `variants`, on each collection and its versions collection (`version.sizes`). Uses `$rename`,
5
+ * so no document is rewritten beyond the renamed key, and re-keys the indexes on those fields.
6
+ * Documents that are already renamed are left as they are, so it's safe to re-run.
7
+ */
8
+ export declare function migrateSizesToVariants({ direction, payload, req, }: {
9
+ direction?: 'down' | 'up';
10
+ payload: Payload;
11
+ req?: Partial<PayloadRequest>;
12
+ }): Promise<void>;
13
+ //# sourceMappingURL=migrateSizesToVariants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrateSizesToVariants.d.ts","sourceRoot":"","sources":["../../src/predefinedMigrations/migrateSizesToVariants.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAqBtD;;;;;GAKG;AACH,wBAAsB,sBAAsB,CAAC,EAC3C,SAAgB,EAChB,OAAO,EACP,GAAG,GACJ,EAAE;IACD,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACzB,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAA;CAC9B,GAAG,OAAO,CAAC,IAAI,CAAC,CA2EhB"}
@@ -0,0 +1,368 @@
1
+ import { isDeepStrictEqual } from 'node:util';
2
+ import { getSession } from '../utilities/getSession.js';
3
+ /** Mongo error codes for an index that conflicts with an existing index. */ const INDEX_CONFLICT_CODES = new Set([
4
+ 85,
5
+ 86
6
+ ]);
7
+ /** Mongo error code for a collection that hasn't been created yet. */ const NAMESPACE_NOT_FOUND_CODE = 26;
8
+ const GENERATED_VARIANT_METADATA_FIELDS = new Set([
9
+ 'filename',
10
+ 'filesize',
11
+ 'height',
12
+ 'mimeType',
13
+ 'url',
14
+ 'width'
15
+ ]);
16
+ /**
17
+ * Moves every upload collection's stored image sizes between the legacy `sizes` field and
18
+ * `variants`, on each collection and its versions collection (`version.sizes`). Uses `$rename`,
19
+ * so no document is rewritten beyond the renamed key, and re-keys the indexes on those fields.
20
+ * Documents that are already renamed are left as they are, so it's safe to re-run.
21
+ */ export async function migrateSizesToVariants({ direction = 'up', payload, req }) {
22
+ const adapter = payload.db;
23
+ const session = await getSession(adapter, req);
24
+ const [from, to] = direction === 'up' ? [
25
+ 'sizes',
26
+ 'variants'
27
+ ] : [
28
+ 'variants',
29
+ 'sizes'
30
+ ];
31
+ const targets = [];
32
+ for (const collection of payload.config.collections){
33
+ if (!collection.upload) {
34
+ continue;
35
+ }
36
+ const upload = typeof collection.upload === 'object' ? collection.upload : undefined;
37
+ const expectedVariantNames = (upload?.variants ?? []).map(({ name })=>name);
38
+ targets.push({
39
+ collection: adapter.collections[collection.slug].collection,
40
+ expectedVariantNames,
41
+ fromPath: from,
42
+ toPath: to
43
+ });
44
+ if (collection.versions && adapter.versions[collection.slug]) {
45
+ targets.push({
46
+ collection: adapter.versions[collection.slug].collection,
47
+ expectedVariantNames,
48
+ fromPath: `version.${from}`,
49
+ toPath: `version.${to}`
50
+ });
51
+ }
52
+ }
53
+ for (const { collection, expectedVariantNames, fromPath, toPath } of targets){
54
+ const [sourceData, directCollision] = await Promise.all([
55
+ collection.findOne({
56
+ [fromPath]: {
57
+ $exists: true
58
+ }
59
+ }, {
60
+ projection: {
61
+ _id: 1
62
+ }
63
+ }),
64
+ collection.findOne({
65
+ [fromPath]: {
66
+ $exists: true
67
+ },
68
+ [toPath]: {
69
+ $exists: true
70
+ }
71
+ }, {
72
+ projection: {
73
+ _id: 1
74
+ }
75
+ })
76
+ ]);
77
+ if (sourceData && (directCollision || await findUnexpectedDestinationData({
78
+ collection,
79
+ expectedVariantNames,
80
+ toPath
81
+ }))) {
82
+ throw new Error(`Cannot run the sizes-to-variants migration because collection "${collection.collectionName}" contains both "${fromPath}" and "${toPath}" data. Move or rename the existing destination data before running this migration.`);
83
+ }
84
+ }
85
+ // Index changes can't be part of a multi-document transaction, and one made after the
86
+ // migration's transaction has written to a collection aborts it. A transaction's snapshot starts
87
+ // at its first operation, so re-keying every index before any transactional write is safe.
88
+ for (const target of targets){
89
+ await rekeyIndexes(target);
90
+ }
91
+ for (const { collection, fromPath, toPath } of targets){
92
+ const result = await collection.updateMany({
93
+ [fromPath]: {
94
+ $exists: true
95
+ },
96
+ [toPath]: {
97
+ $exists: false
98
+ }
99
+ }, {
100
+ $rename: {
101
+ [fromPath]: toPath
102
+ }
103
+ }, {
104
+ session
105
+ });
106
+ payload.logger.info({
107
+ msg: `sizes-to-variants (${direction}): renamed ${fromPath} on ${result.modifiedCount} document(s) in "${collection.collectionName}"`
108
+ });
109
+ }
110
+ }
111
+ async function findUnexpectedDestinationData({ collection, expectedVariantNames, toPath }) {
112
+ const expectedVariantNameSet = new Set(expectedVariantNames);
113
+ const cursor = collection.find({
114
+ [toPath]: {
115
+ $exists: true
116
+ }
117
+ }, {
118
+ projection: {
119
+ _id: 1,
120
+ [toPath]: 1
121
+ }
122
+ });
123
+ try {
124
+ for await (const document of cursor){
125
+ const destinationData = getDocumentPath({
126
+ document,
127
+ path: toPath
128
+ });
129
+ if (hasUnexpectedVariantData({
130
+ destinationData,
131
+ expectedVariantNameSet
132
+ })) {
133
+ return document;
134
+ }
135
+ }
136
+ } finally{
137
+ await cursor.close();
138
+ }
139
+ return null;
140
+ }
141
+ function getDocumentPath({ document, path }) {
142
+ return path.split('.').reduce((value, pathSegment)=>{
143
+ if (!isRecord(value)) {
144
+ return undefined;
145
+ }
146
+ return value[pathSegment];
147
+ }, document);
148
+ }
149
+ function hasUnexpectedVariantData({ destinationData, expectedVariantNameSet }) {
150
+ if (!isRecord(destinationData)) {
151
+ return destinationData !== null && destinationData !== undefined;
152
+ }
153
+ for (const [variantName, variantData] of Object.entries(destinationData)){
154
+ if (!expectedVariantNameSet.has(variantName)) {
155
+ return true;
156
+ }
157
+ if (variantData === null || variantData === undefined) {
158
+ continue;
159
+ }
160
+ if (!isRecord(variantData) || Object.keys(variantData).some((metadataFieldName)=>!GENERATED_VARIANT_METADATA_FIELDS.has(metadataFieldName))) {
161
+ return true;
162
+ }
163
+ }
164
+ return false;
165
+ }
166
+ function isRecord(value) {
167
+ return value !== null && typeof value === 'object' && !Array.isArray(value);
168
+ }
169
+ async function rekeyIndexes({ collection, fromPath, toPath }) {
170
+ let indexes;
171
+ try {
172
+ indexes = await collection.indexes();
173
+ } catch (err) {
174
+ if (err.code === NAMESPACE_NOT_FOUND_CODE) {
175
+ return;
176
+ }
177
+ throw err;
178
+ }
179
+ for (const index of indexes){
180
+ const sourceKeys = getIndexKeysForCreate({
181
+ fromPath,
182
+ index,
183
+ toPath: fromPath
184
+ });
185
+ if (!Object.keys(sourceKeys).some((key)=>isPathAtOrBelow({
186
+ key,
187
+ path: fromPath
188
+ }))) {
189
+ continue;
190
+ }
191
+ const rekeyedKeys = getIndexKeysForCreate({
192
+ fromPath,
193
+ index,
194
+ toPath
195
+ });
196
+ const destinationOptions = getDestinationIndexOptions({
197
+ fromPath,
198
+ index,
199
+ toPath
200
+ });
201
+ if (index.weights && '_fts' in index.key && '_ftsx' in index.key) {
202
+ await rekeyTextIndex({
203
+ collection,
204
+ destinationOptions,
205
+ index,
206
+ rekeyedKeys,
207
+ sourceKeys
208
+ });
209
+ continue;
210
+ }
211
+ try {
212
+ await collection.createIndex(rekeyedKeys, destinationOptions);
213
+ } catch (err) {
214
+ if (!INDEX_CONFLICT_CODES.has(err.code ?? 0)) {
215
+ throw err;
216
+ }
217
+ const destinationIndex = (await collection.indexes()).find((candidate)=>isDeepStrictEqual(getIndexKeysForCreate({
218
+ fromPath: toPath,
219
+ index: candidate,
220
+ toPath
221
+ }), rekeyedKeys));
222
+ const existingDestinationOptions = destinationIndex ? getDestinationIndexOptions({
223
+ fromPath: toPath,
224
+ index: destinationIndex,
225
+ toPath
226
+ }) : undefined;
227
+ if (!destinationIndex || !isDeepStrictEqual(existingDestinationOptions, destinationOptions)) {
228
+ throw err;
229
+ }
230
+ }
231
+ await collection.dropIndex(index.name);
232
+ }
233
+ }
234
+ async function rekeyTextIndex({ collection, destinationOptions, index, rekeyedKeys, sourceKeys }) {
235
+ if (!index.name) {
236
+ throw new Error('Cannot re-key an unnamed MongoDB text index.');
237
+ }
238
+ const sourceOptions = {
239
+ ...getDestinationIndexOptions({
240
+ fromPath: '',
241
+ index,
242
+ toPath: ''
243
+ }),
244
+ name: index.name
245
+ };
246
+ await collection.dropIndex(index.name);
247
+ try {
248
+ await collection.createIndex(rekeyedKeys, destinationOptions);
249
+ } catch (err) {
250
+ try {
251
+ await collection.createIndex(sourceKeys, sourceOptions);
252
+ } catch (restoreErr) {
253
+ throw new AggregateError([
254
+ err,
255
+ restoreErr
256
+ ], `Failed to create the replacement for MongoDB text index "${index.name}" and failed to restore the source index.`);
257
+ }
258
+ throw err;
259
+ }
260
+ }
261
+ function getIndexKeysForCreate({ fromPath, index, toPath }) {
262
+ const keys = [];
263
+ const hasInternalTextKeys = '_fts' in index.key && '_ftsx' in index.key;
264
+ for (const [key, value] of Object.entries(index.key)){
265
+ if (hasInternalTextKeys && key === '_fts') {
266
+ for (const textPath of Object.keys(index.weights ?? {})){
267
+ keys.push([
268
+ rekeyPath({
269
+ fromPath,
270
+ path: textPath,
271
+ toPath
272
+ }),
273
+ 'text'
274
+ ]);
275
+ }
276
+ continue;
277
+ }
278
+ if (hasInternalTextKeys && key === '_ftsx') {
279
+ continue;
280
+ }
281
+ keys.push([
282
+ rekeyPath({
283
+ fromPath,
284
+ path: key,
285
+ toPath
286
+ }),
287
+ value
288
+ ]);
289
+ }
290
+ return Object.fromEntries(keys);
291
+ }
292
+ function getDestinationIndexOptions({ fromPath, index, toPath }) {
293
+ const options = {
294
+ '2dsphereIndexVersion': index['2dsphereIndexVersion'],
295
+ background: index.background,
296
+ bits: index.bits,
297
+ bucketSize: index.bucketSize,
298
+ collation: index.collation,
299
+ default_language: index.default_language,
300
+ expireAfterSeconds: index.expireAfterSeconds,
301
+ hidden: index.hidden,
302
+ language_override: index.language_override,
303
+ max: index.max,
304
+ min: index.min,
305
+ partialFilterExpression: index.partialFilterExpression ? rekeyDocumentPaths({
306
+ document: index.partialFilterExpression,
307
+ fromPath,
308
+ toPath
309
+ }) : undefined,
310
+ sparse: index.sparse,
311
+ storageEngine: index.storageEngine,
312
+ textIndexVersion: index.textIndexVersion,
313
+ unique: index.unique,
314
+ weights: index.weights ? rekeyDocumentPaths({
315
+ document: index.weights,
316
+ fromPath,
317
+ toPath
318
+ }) : undefined,
319
+ wildcardProjection: index.wildcardProjection ? rekeyDocumentPaths({
320
+ document: index.wildcardProjection,
321
+ fromPath,
322
+ toPath
323
+ }) : undefined
324
+ };
325
+ return Object.fromEntries(Object.entries(options).filter(([, value])=>value !== undefined));
326
+ }
327
+ function rekeyDocumentPaths({ document, fromPath, toPath }) {
328
+ return Object.fromEntries(Object.entries(document).map(([key, value])=>[
329
+ rekeyPath({
330
+ fromPath,
331
+ path: key,
332
+ toPath
333
+ }),
334
+ rekeyDocumentValue({
335
+ fromPath,
336
+ toPath,
337
+ value
338
+ })
339
+ ]));
340
+ }
341
+ function isPathAtOrBelow({ key, path }) {
342
+ return key === path || key.startsWith(`${path}.`);
343
+ }
344
+ function rekeyPath({ fromPath, path, toPath }) {
345
+ return isPathAtOrBelow({
346
+ key: path,
347
+ path: fromPath
348
+ }) ? `${toPath}${path.slice(fromPath.length)}` : path;
349
+ }
350
+ function rekeyDocumentValue({ fromPath, toPath, value }) {
351
+ if (Array.isArray(value)) {
352
+ return value.map((item)=>rekeyDocumentValue({
353
+ fromPath,
354
+ toPath,
355
+ value: item
356
+ }));
357
+ }
358
+ if (value !== null && typeof value === 'object' && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null)) {
359
+ return rekeyDocumentPaths({
360
+ document: value,
361
+ fromPath,
362
+ toPath
363
+ });
364
+ }
365
+ return value;
366
+ }
367
+
368
+ //# sourceMappingURL=migrateSizesToVariants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/predefinedMigrations/migrateSizesToVariants.ts"],"sourcesContent":["import type {\n Collection,\n CreateIndexesOptions,\n Document,\n IndexDescriptionInfo,\n IndexDirection,\n} from 'mongodb'\nimport type { Payload, PayloadRequest } from 'payload'\n\nimport { isDeepStrictEqual } from 'node:util'\n\nimport type { MongooseAdapter } from '../index.js'\n\nimport { getSession } from '../utilities/getSession.js'\n\n/** Mongo error codes for an index that conflicts with an existing index. */\nconst INDEX_CONFLICT_CODES = new Set([85, 86])\n/** Mongo error code for a collection that hasn't been created yet. */\nconst NAMESPACE_NOT_FOUND_CODE = 26\nconst GENERATED_VARIANT_METADATA_FIELDS = new Set([\n 'filename',\n 'filesize',\n 'height',\n 'mimeType',\n 'url',\n 'width',\n])\n\n/**\n * Moves every upload collection's stored image sizes between the legacy `sizes` field and\n * `variants`, on each collection and its versions collection (`version.sizes`). Uses `$rename`,\n * so no document is rewritten beyond the renamed key, and re-keys the indexes on those fields.\n * Documents that are already renamed are left as they are, so it's safe to re-run.\n */\nexport async function migrateSizesToVariants({\n direction = 'up',\n payload,\n req,\n}: {\n direction?: 'down' | 'up'\n payload: Payload\n req?: Partial<PayloadRequest>\n}): Promise<void> {\n const adapter = payload.db as unknown as MongooseAdapter\n const session = await getSession(adapter, req)\n const [from, to] = direction === 'up' ? ['sizes', 'variants'] : ['variants', 'sizes']\n\n const targets: {\n collection: Collection\n expectedVariantNames: string[]\n fromPath: string\n toPath: string\n }[] = []\n\n for (const collection of payload.config.collections) {\n if (!collection.upload) {\n continue\n }\n\n const upload = typeof collection.upload === 'object' ? collection.upload : undefined\n const expectedVariantNames = (upload?.variants ?? []).map(({ name }) => name)\n\n targets.push({\n collection: adapter.collections[collection.slug]!.collection,\n expectedVariantNames,\n fromPath: from,\n toPath: to,\n })\n\n if (collection.versions && adapter.versions[collection.slug]) {\n targets.push({\n collection: adapter.versions[collection.slug]!.collection,\n expectedVariantNames,\n fromPath: `version.${from}`,\n toPath: `version.${to}`,\n })\n }\n }\n\n for (const { collection, expectedVariantNames, fromPath, toPath } of targets) {\n const [sourceData, directCollision] = await Promise.all([\n collection.findOne({ [fromPath]: { $exists: true } }, { projection: { _id: 1 } }),\n collection.findOne(\n { [fromPath]: { $exists: true }, [toPath]: { $exists: true } },\n { projection: { _id: 1 } },\n ),\n ])\n\n if (\n sourceData &&\n (directCollision ||\n (await findUnexpectedDestinationData({ collection, expectedVariantNames, toPath })))\n ) {\n throw new Error(\n `Cannot run the sizes-to-variants migration because collection \"${collection.collectionName}\" contains both \"${fromPath}\" and \"${toPath}\" data. Move or rename the existing destination data before running this migration.`,\n )\n }\n }\n\n // Index changes can't be part of a multi-document transaction, and one made after the\n // migration's transaction has written to a collection aborts it. A transaction's snapshot starts\n // at its first operation, so re-keying every index before any transactional write is safe.\n for (const target of targets) {\n await rekeyIndexes(target)\n }\n\n for (const { collection, fromPath, toPath } of targets) {\n const result = await collection.updateMany(\n { [fromPath]: { $exists: true }, [toPath]: { $exists: false } },\n { $rename: { [fromPath]: toPath } },\n { session },\n )\n\n payload.logger.info({\n msg: `sizes-to-variants (${direction}): renamed ${fromPath} on ${result.modifiedCount} document(s) in \"${collection.collectionName}\"`,\n })\n }\n}\n\nasync function findUnexpectedDestinationData({\n collection,\n expectedVariantNames,\n toPath,\n}: {\n collection: Collection\n expectedVariantNames: string[]\n toPath: string\n}): Promise<Document | null> {\n const expectedVariantNameSet = new Set(expectedVariantNames)\n const cursor = collection.find(\n { [toPath]: { $exists: true } },\n { projection: { _id: 1, [toPath]: 1 } },\n )\n\n try {\n for await (const document of cursor) {\n const destinationData = getDocumentPath({ document, path: toPath })\n\n if (hasUnexpectedVariantData({ destinationData, expectedVariantNameSet })) {\n return document\n }\n }\n } finally {\n await cursor.close()\n }\n\n return null\n}\n\nfunction getDocumentPath({ document, path }: { document: Document; path: string }): unknown {\n return path.split('.').reduce<unknown>((value, pathSegment) => {\n if (!isRecord(value)) {\n return undefined\n }\n\n return value[pathSegment]\n }, document)\n}\n\nfunction hasUnexpectedVariantData({\n destinationData,\n expectedVariantNameSet,\n}: {\n destinationData: unknown\n expectedVariantNameSet: Set<string>\n}): boolean {\n if (!isRecord(destinationData)) {\n return destinationData !== null && destinationData !== undefined\n }\n\n for (const [variantName, variantData] of Object.entries(destinationData)) {\n if (!expectedVariantNameSet.has(variantName)) {\n return true\n }\n\n if (variantData === null || variantData === undefined) {\n continue\n }\n\n if (\n !isRecord(variantData) ||\n Object.keys(variantData).some(\n (metadataFieldName) => !GENERATED_VARIANT_METADATA_FIELDS.has(metadataFieldName),\n )\n ) {\n return true\n }\n }\n\n return false\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return value !== null && typeof value === 'object' && !Array.isArray(value)\n}\n\nasync function rekeyIndexes({\n collection,\n fromPath,\n toPath,\n}: {\n collection: Collection\n fromPath: string\n toPath: string\n}): Promise<void> {\n let indexes: IndexDescriptionInfo[]\n\n try {\n indexes = await collection.indexes()\n } catch (err) {\n if ((err as { code?: number }).code === NAMESPACE_NOT_FOUND_CODE) {\n return\n }\n\n throw err\n }\n\n for (const index of indexes) {\n const sourceKeys = getIndexKeysForCreate({ fromPath, index, toPath: fromPath })\n\n if (!Object.keys(sourceKeys).some((key) => isPathAtOrBelow({ key, path: fromPath }))) {\n continue\n }\n\n const rekeyedKeys = getIndexKeysForCreate({ fromPath, index, toPath })\n const destinationOptions = getDestinationIndexOptions({ fromPath, index, toPath })\n\n if (index.weights && '_fts' in index.key && '_ftsx' in index.key) {\n await rekeyTextIndex({\n collection,\n destinationOptions,\n index,\n rekeyedKeys,\n sourceKeys,\n })\n continue\n }\n\n try {\n await collection.createIndex(rekeyedKeys, destinationOptions)\n } catch (err) {\n if (!INDEX_CONFLICT_CODES.has((err as { code?: number }).code ?? 0)) {\n throw err\n }\n\n const destinationIndex = (await collection.indexes()).find((candidate) =>\n isDeepStrictEqual(\n getIndexKeysForCreate({ fromPath: toPath, index: candidate, toPath }),\n rekeyedKeys,\n ),\n )\n const existingDestinationOptions = destinationIndex\n ? getDestinationIndexOptions({\n fromPath: toPath,\n index: destinationIndex,\n toPath,\n })\n : undefined\n\n if (!destinationIndex || !isDeepStrictEqual(existingDestinationOptions, destinationOptions)) {\n throw err\n }\n }\n\n await collection.dropIndex(index.name!)\n }\n}\n\nasync function rekeyTextIndex({\n collection,\n destinationOptions,\n index,\n rekeyedKeys,\n sourceKeys,\n}: {\n collection: Collection\n destinationOptions: CreateIndexesOptions\n index: IndexDescriptionInfo\n rekeyedKeys: Record<string, IndexDirection>\n sourceKeys: Record<string, IndexDirection>\n}): Promise<void> {\n if (!index.name) {\n throw new Error('Cannot re-key an unnamed MongoDB text index.')\n }\n\n const sourceOptions: CreateIndexesOptions = {\n ...getDestinationIndexOptions({ fromPath: '', index, toPath: '' }),\n name: index.name,\n }\n\n await collection.dropIndex(index.name)\n\n try {\n await collection.createIndex(rekeyedKeys, destinationOptions)\n } catch (err) {\n try {\n await collection.createIndex(sourceKeys, sourceOptions)\n } catch (restoreErr) {\n throw new AggregateError(\n [err, restoreErr],\n `Failed to create the replacement for MongoDB text index \"${index.name}\" and failed to restore the source index.`,\n )\n }\n\n throw err\n }\n}\n\nfunction getIndexKeysForCreate({\n fromPath,\n index,\n toPath,\n}: {\n fromPath: string\n index: IndexDescriptionInfo\n toPath: string\n}): Record<string, IndexDirection> {\n const keys: [string, IndexDirection][] = []\n const hasInternalTextKeys = '_fts' in index.key && '_ftsx' in index.key\n\n for (const [key, value] of Object.entries(index.key)) {\n if (hasInternalTextKeys && key === '_fts') {\n for (const textPath of Object.keys(index.weights ?? {})) {\n keys.push([rekeyPath({ fromPath, path: textPath, toPath }), 'text'])\n }\n continue\n }\n\n if (hasInternalTextKeys && key === '_ftsx') {\n continue\n }\n\n keys.push([rekeyPath({ fromPath, path: key, toPath }), value])\n }\n\n return Object.fromEntries(keys)\n}\n\nfunction getDestinationIndexOptions({\n fromPath,\n index,\n toPath,\n}: {\n fromPath: string\n index: IndexDescriptionInfo\n toPath: string\n}): CreateIndexesOptions {\n const options: CreateIndexesOptions = {\n '2dsphereIndexVersion': index['2dsphereIndexVersion'],\n background: index.background,\n bits: index.bits,\n bucketSize: index.bucketSize,\n collation: index.collation,\n default_language: index.default_language,\n expireAfterSeconds: index.expireAfterSeconds,\n hidden: index.hidden,\n language_override: index.language_override,\n max: index.max,\n min: index.min,\n partialFilterExpression: index.partialFilterExpression\n ? rekeyDocumentPaths({ document: index.partialFilterExpression, fromPath, toPath })\n : undefined,\n sparse: index.sparse,\n storageEngine: index.storageEngine,\n textIndexVersion: index.textIndexVersion,\n unique: index.unique,\n weights: index.weights\n ? rekeyDocumentPaths({ document: index.weights, fromPath, toPath })\n : undefined,\n wildcardProjection: index.wildcardProjection\n ? rekeyDocumentPaths({ document: index.wildcardProjection, fromPath, toPath })\n : undefined,\n }\n\n return Object.fromEntries(Object.entries(options).filter(([, value]) => value !== undefined))\n}\n\nfunction rekeyDocumentPaths({\n document,\n fromPath,\n toPath,\n}: {\n document: Document\n fromPath: string\n toPath: string\n}): Document {\n return Object.fromEntries(\n Object.entries(document).map(([key, value]) => [\n rekeyPath({ fromPath, path: key, toPath }),\n rekeyDocumentValue({ fromPath, toPath, value }),\n ]),\n )\n}\n\nfunction isPathAtOrBelow({ key, path }: { key: string; path: string }): boolean {\n return key === path || key.startsWith(`${path}.`)\n}\n\nfunction rekeyPath({\n fromPath,\n path,\n toPath,\n}: {\n fromPath: string\n path: string\n toPath: string\n}): string {\n return isPathAtOrBelow({ key: path, path: fromPath })\n ? `${toPath}${path.slice(fromPath.length)}`\n : path\n}\n\nfunction rekeyDocumentValue({\n fromPath,\n toPath,\n value,\n}: {\n fromPath: string\n toPath: string\n value: unknown\n}): unknown {\n if (Array.isArray(value)) {\n return value.map((item) => rekeyDocumentValue({ fromPath, toPath, value: item }))\n }\n\n if (\n value !== null &&\n typeof value === 'object' &&\n (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null)\n ) {\n return rekeyDocumentPaths({ document: value, fromPath, toPath })\n }\n\n return value\n}\n"],"names":["isDeepStrictEqual","getSession","INDEX_CONFLICT_CODES","Set","NAMESPACE_NOT_FOUND_CODE","GENERATED_VARIANT_METADATA_FIELDS","migrateSizesToVariants","direction","payload","req","adapter","db","session","from","to","targets","collection","config","collections","upload","undefined","expectedVariantNames","variants","map","name","push","slug","fromPath","toPath","versions","sourceData","directCollision","Promise","all","findOne","$exists","projection","_id","findUnexpectedDestinationData","Error","collectionName","target","rekeyIndexes","result","updateMany","$rename","logger","info","msg","modifiedCount","expectedVariantNameSet","cursor","find","document","destinationData","getDocumentPath","path","hasUnexpectedVariantData","close","split","reduce","value","pathSegment","isRecord","variantName","variantData","Object","entries","has","keys","some","metadataFieldName","Array","isArray","indexes","err","code","index","sourceKeys","getIndexKeysForCreate","key","isPathAtOrBelow","rekeyedKeys","destinationOptions","getDestinationIndexOptions","weights","rekeyTextIndex","createIndex","destinationIndex","candidate","existingDestinationOptions","dropIndex","sourceOptions","restoreErr","AggregateError","hasInternalTextKeys","textPath","rekeyPath","fromEntries","options","background","bits","bucketSize","collation","default_language","expireAfterSeconds","hidden","language_override","max","min","partialFilterExpression","rekeyDocumentPaths","sparse","storageEngine","textIndexVersion","unique","wildcardProjection","filter","rekeyDocumentValue","startsWith","slice","length","item","getPrototypeOf","prototype"],"mappings":"AASA,SAASA,iBAAiB,QAAQ,YAAW;AAI7C,SAASC,UAAU,QAAQ,6BAA4B;AAEvD,0EAA0E,GAC1E,MAAMC,uBAAuB,IAAIC,IAAI;IAAC;IAAI;CAAG;AAC7C,oEAAoE,GACpE,MAAMC,2BAA2B;AACjC,MAAMC,oCAAoC,IAAIF,IAAI;IAChD;IACA;IACA;IACA;IACA;IACA;CACD;AAED;;;;;CAKC,GACD,OAAO,eAAeG,uBAAuB,EAC3CC,YAAY,IAAI,EAChBC,OAAO,EACPC,GAAG,EAKJ;IACC,MAAMC,UAAUF,QAAQG,EAAE;IAC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C,CAACyD,KAAKnB,MAAM,GAAK;YAC7CoC,UAAU;gBAAEtE;gBAAU6B,MAAMwB;gBAAKpD;YAAO;YACxC0F,mBAAmB;gBAAE3F;gBAAUC;gBAAQiC;YAAM;SAC9C;AAEL;AAEA,SAASoB,gBAAgB,EAAED,GAAG,EAAExB,IAAI,EAAiC;IACnE,OAAOwB,QAAQxB,QAAQwB,IAAIuC,UAAU,CAAC,GAAG/D,KAAK,CAAC,CAAC;AAClD;AAEA,SAASyC,UAAU,EACjBtE,QAAQ,EACR6B,IAAI,EACJ5B,MAAM,EAKP;IACC,OAAOqD,gBAAgB;QAAED,KAAKxB;QAAMA,MAAM7B;IAAS,KAC/C,GAAGC,SAAS4B,KAAKgE,KAAK,CAAC7F,SAAS8F,MAAM,GAAG,GACzCjE;AACN;AAEA,SAAS8D,mBAAmB,EAC1B3F,QAAQ,EACRC,MAAM,EACNiC,KAAK,EAKN;IACC,IAAIW,MAAMC,OAAO,CAACZ,QAAQ;QACxB,OAAOA,MAAMtC,GAAG,CAAC,CAACmG,OAASJ,mBAAmB;gBAAE3F;gBAAUC;gBAAQiC,OAAO6D;YAAK;IAChF;IAEA,IACE7D,UAAU,QACV,OAAOA,UAAU,YAChBK,CAAAA,OAAOyD,cAAc,CAAC9D,WAAWK,OAAO0D,SAAS,IAAI1D,OAAOyD,cAAc,CAAC9D,WAAW,IAAG,GAC1F;QACA,OAAOkD,mBAAmB;YAAE1D,UAAUQ;YAAOlC;YAAUC;QAAO;IAChE;IAEA,OAAOiC;AACT"}
@@ -0,0 +1,5 @@
1
+ declare const imports = "import { migrateSizesToVariants } from '@payloadcms/db-mongodb/migration-utils'";
2
+ declare const upSQL = " await migrateSizesToVariants({ payload, req })\n";
3
+ declare const downSQL = " await migrateSizesToVariants({ direction: 'down', payload, req })\n";
4
+ export { downSQL, imports, upSQL };
5
+ //# sourceMappingURL=sizes-to-variants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sizes-to-variants.d.ts","sourceRoot":"","sources":["../../src/predefinedMigrations/sizes-to-variants.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,OAAO,oFAAoF,CAAA;AACjG,QAAA,MAAM,KAAK,uDACV,CAAA;AACD,QAAA,MAAM,OAAO,0EACZ,CAAA;AAED,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAA"}
@@ -0,0 +1,8 @@
1
+ const imports = `import { migrateSizesToVariants } from '@payloadcms/db-mongodb/migration-utils'`;
2
+ const upSQL = ` await migrateSizesToVariants({ payload, req })
3
+ `;
4
+ const downSQL = ` await migrateSizesToVariants({ direction: 'down', payload, req })
5
+ `;
6
+ export { downSQL, imports, upSQL };
7
+
8
+ //# sourceMappingURL=sizes-to-variants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/predefinedMigrations/sizes-to-variants.ts"],"sourcesContent":["const imports = `import { migrateSizesToVariants } from '@payloadcms/db-mongodb/migration-utils'`\nconst upSQL = ` await migrateSizesToVariants({ payload, req })\n`\nconst downSQL = ` await migrateSizesToVariants({ direction: 'down', payload, req })\n`\n\nexport { downSQL, imports, upSQL }\n"],"names":["imports","upSQL","downSQL"],"mappings":"AAAA,MAAMA,UAAU,CAAC,+EAA+E,CAAC;AACjG,MAAMC,QAAQ,CAAC;AACf,CAAC;AACD,MAAMC,UAAU,CAAC;AACjB,CAAC;AAED,SAASA,OAAO,EAAEF,OAAO,EAAEC,KAAK,GAAE"}
@@ -1,11 +1,13 @@
1
- import type { FlattenedField, Payload, Where } from 'payload';
2
- export declare function buildAndOrConditions({ collectionSlug, fields, globalSlug, locale, parentIsLocalized, payload, where, }: {
1
+ import type { FlattenedField, Payload, PayloadRequest, Where } from 'payload';
2
+ export declare function buildAndOrConditions({ branch, collectionSlug, fields, globalSlug, locale, parentIsLocalized, payload, req, where, }: {
3
+ branch?: false | string;
3
4
  collectionSlug?: string;
4
5
  fields: FlattenedField[];
5
6
  globalSlug?: string;
6
7
  locale?: string;
7
8
  parentIsLocalized: boolean;
8
9
  payload: Payload;
10
+ req?: Partial<PayloadRequest>;
9
11
  where: Where[];
10
12
  }): Promise<Record<string, unknown>[]>;
11
13
  //# sourceMappingURL=buildAndOrConditions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"buildAndOrConditions.d.ts","sourceRoot":"","sources":["../../src/queries/buildAndOrConditions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAI7D,wBAAsB,oBAAoB,CAAC,EACzC,cAAc,EACd,MAAM,EACN,UAAU,EACV,MAAM,EACN,iBAAiB,EACjB,OAAO,EACP,KAAK,GACN,EAAE;IACD,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,iBAAiB,EAAE,OAAO,CAAA;IAC1B,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,KAAK,EAAE,CAAA;CACf,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,CAuBrC"}
1
+ {"version":3,"file":"buildAndOrConditions.d.ts","sourceRoot":"","sources":["../../src/queries/buildAndOrConditions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAI7E,wBAAsB,oBAAoB,CAAC,EACzC,MAAM,EACN,cAAc,EACd,MAAM,EACN,UAAU,EACV,MAAM,EACN,iBAAiB,EACjB,OAAO,EACP,GAAG,EACH,KAAK,GACN,EAAE;IACD,MAAM,CAAC,EAAE,KAAK,GAAG,MAAM,CAAA;IACvB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,iBAAiB,EAAE,OAAO,CAAA;IAC1B,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAA;IAC7B,KAAK,EAAE,KAAK,EAAE,CAAA;CACf,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,CAyBrC"}
@@ -1,5 +1,5 @@
1
1
  import { parseParams } from './parseParams.js';
2
- export async function buildAndOrConditions({ collectionSlug, fields, globalSlug, locale, parentIsLocalized, payload, where }) {
2
+ export async function buildAndOrConditions({ branch, collectionSlug, fields, globalSlug, locale, parentIsLocalized, payload, req, where }) {
3
3
  const completedConditions = [];
4
4
  // Loop over all AND / OR operations and add them to the AND / OR query param
5
5
  // Operations should come through as an array
@@ -7,12 +7,14 @@ export async function buildAndOrConditions({ collectionSlug, fields, globalSlug,
7
7
  // If the operation is properly formatted as an object
8
8
  if (typeof condition === 'object') {
9
9
  const result = await parseParams({
10
+ branch,
10
11
  collectionSlug,
11
12
  fields,
12
13
  globalSlug,
13
14
  locale,
14
15
  parentIsLocalized,
15
16
  payload,
17
+ req,
16
18
  where: condition
17
19
  });
18
20
  if (Object.keys(result).length > 0) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/queries/buildAndOrConditions.ts"],"sourcesContent":["import type { FlattenedField, Payload, Where } from 'payload'\n\nimport { parseParams } from './parseParams.js'\n\nexport async function buildAndOrConditions({\n collectionSlug,\n fields,\n globalSlug,\n locale,\n parentIsLocalized,\n payload,\n where,\n}: {\n collectionSlug?: string\n fields: FlattenedField[]\n globalSlug?: string\n locale?: string\n parentIsLocalized: boolean\n payload: Payload\n where: Where[]\n}): Promise<Record<string, unknown>[]> {\n const completedConditions = []\n // Loop over all AND / OR operations and add them to the AND / OR query param\n // Operations should come through as an array\n\n for (const condition of where) {\n // If the operation is properly formatted as an object\n if (typeof condition === 'object') {\n const result = await parseParams({\n collectionSlug,\n fields,\n globalSlug,\n locale,\n parentIsLocalized,\n payload,\n where: condition,\n })\n if (Object.keys(result).length > 0) {\n completedConditions.push(result)\n }\n }\n }\n return completedConditions\n}\n"],"names":["parseParams","buildAndOrConditions","collectionSlug","fields","globalSlug","locale","parentIsLocalized","payload","where","completedConditions","condition","result","Object","keys","length","push"],"mappings":"AAEA,SAASA,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,eAAeC,qBAAqB,EACzCC,cAAc,EACdC,MAAM,EACNC,UAAU,EACVC,MAAM,EACNC,iBAAiB,EACjBC,OAAO,EACPC,KAAK,EASN;IACC,MAAMC,sBAAsB,EAAE;IAC9B,6EAA6E;IAC7E,6CAA6C;IAE7C,KAAK,MAAMC,aAAaF,MAAO;QAC7B,sDAAsD;QACtD,IAAI,OAAOE,cAAc,UAAU;YACjC,MAAMC,SAAS,MAAMX,YAAY;gBAC/BE;gBACAC;gBACAC;gBACAC;gBACAC;gBACAC;gBACAC,OAAOE;YACT;YACA,IAAIE,OAAOC,IAAI,CAACF,QAAQG,MAAM,GAAG,GAAG;gBAClCL,oBAAoBM,IAAI,CAACJ;YAC3B;QACF;IACF;IACA,OAAOF;AACT"}
1
+ {"version":3,"sources":["../../src/queries/buildAndOrConditions.ts"],"sourcesContent":["import type { FlattenedField, Payload, PayloadRequest, Where } from 'payload'\n\nimport { parseParams } from './parseParams.js'\n\nexport async function buildAndOrConditions({\n branch,\n collectionSlug,\n fields,\n globalSlug,\n locale,\n parentIsLocalized,\n payload,\n req,\n where,\n}: {\n branch?: false | string\n collectionSlug?: string\n fields: FlattenedField[]\n globalSlug?: string\n locale?: string\n parentIsLocalized: boolean\n payload: Payload\n req?: Partial<PayloadRequest>\n where: Where[]\n}): Promise<Record<string, unknown>[]> {\n const completedConditions = []\n // Loop over all AND / OR operations and add them to the AND / OR query param\n // Operations should come through as an array\n\n for (const condition of where) {\n // If the operation is properly formatted as an object\n if (typeof condition === 'object') {\n const result = await parseParams({\n branch,\n collectionSlug,\n fields,\n globalSlug,\n locale,\n parentIsLocalized,\n payload,\n req,\n where: condition,\n })\n if (Object.keys(result).length > 0) {\n completedConditions.push(result)\n }\n }\n }\n return completedConditions\n}\n"],"names":["parseParams","buildAndOrConditions","branch","collectionSlug","fields","globalSlug","locale","parentIsLocalized","payload","req","where","completedConditions","condition","result","Object","keys","length","push"],"mappings":"AAEA,SAASA,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,eAAeC,qBAAqB,EACzCC,MAAM,EACNC,cAAc,EACdC,MAAM,EACNC,UAAU,EACVC,MAAM,EACNC,iBAAiB,EACjBC,OAAO,EACPC,GAAG,EACHC,KAAK,EAWN;IACC,MAAMC,sBAAsB,EAAE;IAC9B,6EAA6E;IAC7E,6CAA6C;IAE7C,KAAK,MAAMC,aAAaF,MAAO;QAC7B,sDAAsD;QACtD,IAAI,OAAOE,cAAc,UAAU;YACjC,MAAMC,SAAS,MAAMb,YAAY;gBAC/BE;gBACAC;gBACAC;gBACAC;gBACAC;gBACAC;gBACAC;gBACAC;gBACAC,OAAOE;YACT;YACA,IAAIE,OAAOC,IAAI,CAACF,QAAQG,MAAM,GAAG,GAAG;gBAClCL,oBAAoBM,IAAI,CAACJ;YAC3B;QACF;IACF;IACA,OAAOF;AACT"}
@@ -0,0 +1,11 @@
1
+ import type { PipelineStage } from 'mongoose';
2
+ import type { MongooseAdapter } from '../index.js';
3
+ type BranchVisibilityStage = Exclude<PipelineStage, PipelineStage.Merge | PipelineStage.Out>;
4
+ export declare const buildBranchVisibilityStages: ({ adapter, branch, collectionSlug, mode, }: {
5
+ adapter: MongooseAdapter;
6
+ branch: string;
7
+ collectionSlug: string;
8
+ mode?: 'documents' | 'drafts' | 'history';
9
+ }) => BranchVisibilityStage[];
10
+ export {};
11
+ //# sourceMappingURL=buildBranchVisibility.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildBranchVisibility.d.ts","sourceRoot":"","sources":["../../src/queries/buildBranchVisibility.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAI7C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAIlD,KAAK,qBAAqB,GAAG,OAAO,CAAC,aAAa,EAAE,aAAa,CAAC,KAAK,GAAG,aAAa,CAAC,GAAG,CAAC,CAAA;AAE5F,eAAO,MAAM,2BAA2B,+CAKrC;IACD,OAAO,EAAE,eAAe,CAAA;IACxB,MAAM,EAAE,MAAM,CAAA;IACd,cAAc,EAAE,MAAM,CAAA;IACtB,IAAI,CAAC,EAAE,WAAW,GAAG,QAAQ,GAAG,SAAS,CAAA;CAC1C,KAAG,qBAAqB,EAmGxB,CAAA"}