@payloadcms/db-mongodb 3.10.0 → 3.11.1-canary.053fca8

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 (125) hide show
  1. package/dist/count.d.ts.map +1 -1
  2. package/dist/count.js +22 -18
  3. package/dist/count.js.map +1 -1
  4. package/dist/countGlobalVersions.d.ts.map +1 -1
  5. package/dist/countGlobalVersions.js +22 -18
  6. package/dist/countGlobalVersions.js.map +1 -1
  7. package/dist/countVersions.d.ts.map +1 -1
  8. package/dist/countVersions.js +22 -18
  9. package/dist/countVersions.js.map +1 -1
  10. package/dist/create.d.ts.map +1 -1
  11. package/dist/create.js +24 -21
  12. package/dist/create.js.map +1 -1
  13. package/dist/createGlobal.d.ts.map +1 -1
  14. package/dist/createGlobal.js +20 -20
  15. package/dist/createGlobal.js.map +1 -1
  16. package/dist/createGlobalVersion.d.ts.map +1 -1
  17. package/dist/createGlobalVersion.js +30 -33
  18. package/dist/createGlobalVersion.js.map +1 -1
  19. package/dist/createVersion.d.ts.map +1 -1
  20. package/dist/createVersion.js +31 -34
  21. package/dist/createVersion.js.map +1 -1
  22. package/dist/deleteMany.d.ts.map +1 -1
  23. package/dist/deleteMany.js +4 -5
  24. package/dist/deleteMany.js.map +1 -1
  25. package/dist/deleteOne.d.ts.map +1 -1
  26. package/dist/deleteOne.js +14 -18
  27. package/dist/deleteOne.js.map +1 -1
  28. package/dist/deleteVersions.d.ts.map +1 -1
  29. package/dist/deleteVersions.js +1 -2
  30. package/dist/deleteVersions.js.map +1 -1
  31. package/dist/find.d.ts.map +1 -1
  32. package/dist/find.js +74 -39
  33. package/dist/find.js.map +1 -1
  34. package/dist/findGlobal.d.ts.map +1 -1
  35. package/dist/findGlobal.js +17 -18
  36. package/dist/findGlobal.js.map +1 -1
  37. package/dist/findGlobalVersions.d.ts.map +1 -1
  38. package/dist/findGlobalVersions.js +62 -32
  39. package/dist/findGlobalVersions.js.map +1 -1
  40. package/dist/findOne.d.ts.map +1 -1
  41. package/dist/findOne.js +20 -29
  42. package/dist/findOne.js.map +1 -1
  43. package/dist/findVersions.d.ts.map +1 -1
  44. package/dist/findVersions.js +61 -32
  45. package/dist/findVersions.js.map +1 -1
  46. package/dist/index.d.ts +0 -1
  47. package/dist/index.d.ts.map +1 -1
  48. package/dist/index.js +0 -1
  49. package/dist/index.js.map +1 -1
  50. package/dist/migrateFresh.d.ts.map +1 -1
  51. package/dist/migrateFresh.js.map +1 -1
  52. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.d.ts.map +1 -1
  53. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js +14 -18
  54. package/dist/predefinedMigrations/migrateRelationshipsV2_V3.js.map +1 -1
  55. package/dist/queries/buildAndOrConditions.d.ts +1 -3
  56. package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
  57. package/dist/queries/buildAndOrConditions.js +1 -2
  58. package/dist/queries/buildAndOrConditions.js.map +1 -1
  59. package/dist/queries/buildQuery.d.ts +0 -2
  60. package/dist/queries/buildQuery.d.ts.map +1 -1
  61. package/dist/queries/buildQuery.js +6 -2
  62. package/dist/queries/buildQuery.js.map +1 -1
  63. package/dist/queries/buildSearchParams.d.ts +1 -3
  64. package/dist/queries/buildSearchParams.d.ts.map +1 -1
  65. package/dist/queries/buildSearchParams.js +10 -14
  66. package/dist/queries/buildSearchParams.js.map +1 -1
  67. package/dist/queries/buildSortParam.d.ts +7 -1
  68. package/dist/queries/buildSortParam.d.ts.map +1 -1
  69. package/dist/queries/buildSortParam.js +2 -2
  70. package/dist/queries/buildSortParam.js.map +1 -1
  71. package/dist/queries/getLocalizedSortProperty.js +2 -2
  72. package/dist/queries/getLocalizedSortProperty.js.map +1 -1
  73. package/dist/queries/parseParams.d.ts +1 -3
  74. package/dist/queries/parseParams.d.ts.map +1 -1
  75. package/dist/queries/parseParams.js +1 -2
  76. package/dist/queries/parseParams.js.map +1 -1
  77. package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
  78. package/dist/queries/sanitizeQueryValue.js +0 -16
  79. package/dist/queries/sanitizeQueryValue.js.map +1 -1
  80. package/dist/queryDrafts.d.ts.map +1 -1
  81. package/dist/queryDrafts.js +66 -40
  82. package/dist/queryDrafts.js.map +1 -1
  83. package/dist/updateGlobal.d.ts.map +1 -1
  84. package/dist/updateGlobal.js +21 -24
  85. package/dist/updateGlobal.js.map +1 -1
  86. package/dist/updateGlobalVersion.d.ts.map +1 -1
  87. package/dist/updateGlobalVersion.js +26 -28
  88. package/dist/updateGlobalVersion.js.map +1 -1
  89. package/dist/updateOne.d.ts.map +1 -1
  90. package/dist/updateOne.js +23 -28
  91. package/dist/updateOne.js.map +1 -1
  92. package/dist/updateVersion.d.ts.map +1 -1
  93. package/dist/updateVersion.js +24 -27
  94. package/dist/updateVersion.js.map +1 -1
  95. package/dist/utilities/buildJoinAggregation.d.ts +4 -4
  96. package/dist/utilities/buildJoinAggregation.d.ts.map +1 -1
  97. package/dist/utilities/buildJoinAggregation.js +28 -7
  98. package/dist/utilities/buildJoinAggregation.js.map +1 -1
  99. package/dist/utilities/buildProjectionFromSelect.d.ts.map +1 -1
  100. package/dist/utilities/buildProjectionFromSelect.js +1 -18
  101. package/dist/utilities/buildProjectionFromSelect.js.map +1 -1
  102. package/dist/utilities/sanitizeInternalFields.d.ts +2 -0
  103. package/dist/utilities/sanitizeInternalFields.d.ts.map +1 -0
  104. package/dist/utilities/sanitizeInternalFields.js +20 -0
  105. package/dist/utilities/sanitizeInternalFields.js.map +1 -0
  106. package/dist/utilities/sanitizeRelationshipIDs.d.ts +9 -0
  107. package/dist/utilities/sanitizeRelationshipIDs.d.ts.map +1 -0
  108. package/dist/utilities/sanitizeRelationshipIDs.js +125 -0
  109. package/dist/utilities/sanitizeRelationshipIDs.js.map +1 -0
  110. package/dist/utilities/{transform.spec.js → sanitizeRelationshipIDs.spec.js} +7 -23
  111. package/dist/utilities/sanitizeRelationshipIDs.spec.js.map +1 -0
  112. package/package.json +4 -4
  113. package/dist/utilities/findMany.d.ts +0 -20
  114. package/dist/utilities/findMany.d.ts.map +0 -1
  115. package/dist/utilities/findMany.js +0 -84
  116. package/dist/utilities/findMany.js.map +0 -1
  117. package/dist/utilities/getHasNearConstraint.d.ts +0 -3
  118. package/dist/utilities/getHasNearConstraint.d.ts.map +0 -1
  119. package/dist/utilities/getHasNearConstraint.js +0 -26
  120. package/dist/utilities/getHasNearConstraint.js.map +0 -1
  121. package/dist/utilities/transform.d.ts +0 -25
  122. package/dist/utilities/transform.d.ts.map +0 -1
  123. package/dist/utilities/transform.js +0 -254
  124. package/dist/utilities/transform.js.map +0 -1
  125. package/dist/utilities/transform.spec.js.map +0 -1
@@ -1,7 +1,7 @@
1
1
  import { buildVersionCollectionFields, buildVersionGlobalFields } from 'payload';
2
2
  import { getSession } from '../utilities/getSession.js';
3
- import { transform } from '../utilities/transform.js';
4
- const migrateModelWithBatching = async ({ adapter, batchSize, fields, Model, session })=>{
3
+ import { sanitizeRelationshipIDs } from '../utilities/sanitizeRelationshipIDs.js';
4
+ const migrateModelWithBatching = async ({ batchSize, config, fields, Model, session })=>{
5
5
  let hasNext = true;
6
6
  let skip = 0;
7
7
  while(hasNext){
@@ -19,12 +19,10 @@ const migrateModelWithBatching = async ({ adapter, batchSize, fields, Model, ses
19
19
  docs.pop();
20
20
  }
21
21
  for (const doc of docs){
22
- transform({
23
- adapter,
22
+ sanitizeRelationshipIDs({
23
+ config,
24
24
  data: doc,
25
- fields,
26
- operation: 'update',
27
- validateRelationships: false
25
+ fields
28
26
  });
29
27
  }
30
28
  await Model.collection.bulkWrite(docs.map((doc)=>({
@@ -83,9 +81,9 @@ export async function migrateRelationshipsV2_V3({ batchSize, req }) {
83
81
  for (const collection of payload.config.collections.filter(hasRelationshipOrUploadField)){
84
82
  payload.logger.info(`Migrating collection "${collection.slug}"`);
85
83
  await migrateModelWithBatching({
86
- adapter: db,
87
84
  batchSize,
88
- fields: collection.flattenedFields,
85
+ config,
86
+ fields: collection.fields,
89
87
  Model: db.collections[collection.slug],
90
88
  session
91
89
  });
@@ -93,9 +91,9 @@ export async function migrateRelationshipsV2_V3({ batchSize, req }) {
93
91
  if (collection.versions) {
94
92
  payload.logger.info(`Migrating collection versions "${collection.slug}"`);
95
93
  await migrateModelWithBatching({
96
- adapter: db,
97
94
  batchSize,
98
- fields: buildVersionCollectionFields(config, collection, true),
95
+ config,
96
+ fields: buildVersionCollectionFields(config, collection),
99
97
  Model: db.versions[collection.slug],
100
98
  session
101
99
  });
@@ -115,12 +113,10 @@ export async function migrateRelationshipsV2_V3({ batchSize, req }) {
115
113
  });
116
114
  // in case if the global doesn't exist in the database yet (not saved)
117
115
  if (doc) {
118
- transform({
119
- adapter: db,
116
+ sanitizeRelationshipIDs({
117
+ config,
120
118
  data: doc,
121
- fields: global.flattenedFields,
122
- operation: 'update',
123
- validateRelationships: false
119
+ fields: global.fields
124
120
  });
125
121
  await GlobalsModel.collection.updateOne({
126
122
  globalType: global.slug
@@ -134,9 +130,9 @@ export async function migrateRelationshipsV2_V3({ batchSize, req }) {
134
130
  if (global.versions) {
135
131
  payload.logger.info(`Migrating global versions "${global.slug}"`);
136
132
  await migrateModelWithBatching({
137
- adapter: db,
138
133
  batchSize,
139
- fields: buildVersionGlobalFields(config, global, true),
134
+ config,
135
+ fields: buildVersionGlobalFields(config, global),
140
136
  Model: db.versions[global.slug],
141
137
  session
142
138
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/predefinedMigrations/migrateRelationshipsV2_V3.ts"],"sourcesContent":["import type { ClientSession, Model } from 'mongoose'\nimport type { Field, FlattenedField, PayloadRequest } from 'payload'\n\nimport { buildVersionCollectionFields, buildVersionGlobalFields } from 'payload'\n\nimport type { MongooseAdapter } from '../index.js'\n\nimport { getSession } from '../utilities/getSession.js'\nimport { transform } from '../utilities/transform.js'\n\nconst migrateModelWithBatching = async ({\n adapter,\n batchSize,\n fields,\n Model,\n session,\n}: {\n adapter: MongooseAdapter\n batchSize: number\n fields: FlattenedField[]\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 transform({ adapter, data: doc, fields, operation: 'update', validateRelationships: false })\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 getSession(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 adapter: db,\n batchSize,\n fields: collection.flattenedFields,\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 adapter: db,\n batchSize,\n fields: buildVersionCollectionFields(config, collection, true),\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 // 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.flattenedFields,\n operation: 'update',\n validateRelationships: false,\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 if (global.versions) {\n payload.logger.info(`Migrating global versions \"${global.slug}\"`)\n\n await migrateModelWithBatching({\n adapter: db,\n batchSize,\n fields: buildVersionGlobalFields(config, global, true),\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","getSession","transform","migrateModelWithBatching","adapter","batchSize","fields","Model","session","hasNext","skip","docs","find","lean","limit","length","pop","doc","data","operation","validateRelationships","collection","bulkWrite","map","updateOne","filter","_id","update","$set","hasRelationshipOrUploadField","field","type","block","blocks","tab","tabs","migrateRelationshipsV2_V3","req","payload","db","config","collections","logger","info","slug","flattenedFields","versions","globals","GlobalsModel","global","findOne","globalType","$eq"],"mappings":"AAGA,SAASA,4BAA4B,EAAEC,wBAAwB,QAAQ,UAAS;AAIhF,SAASC,UAAU,QAAQ,6BAA4B;AACvD,SAASC,SAAS,QAAQ,4BAA2B;AAErD,MAAMC,2BAA2B,OAAO,EACtCC,OAAO,EACPC,SAAS,EACTC,MAAM,EACNC,KAAK,EACLC,OAAO,EAOR;IACC,IAAIC,UAAU;IACd,IAAIC,OAAO;IAEX,MAAOD,QAAS;QACd,M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OAAOL,IAAI,CAAC,CAAC,CAAC;QAEvD,MAAM3B,MAAM,MAAM+B,aAAaE,OAAO,CACpC;YACEC,YAAY;gBACVC,KAAKH,OAAOL,IAAI;YAClB;QACF,GACA,CAAC,GACD;YAAE/B,MAAM;YAAML;QAAQ;QAGxB,uEAAuE;QACvE,IAAIS,KAAK;YACPf,UAAU;gBACRE,SAASmC;gBACTrB,MAAMD;gBACNX,QAAQ2C,OAAOJ,eAAe;gBAC9B1B,WAAW;gBACXC,uBAAuB;YACzB;YAEA,MAAM4B,aAAa3B,UAAU,CAACG,SAAS,CACrC;gBACE2B,YAAYF,OAAOL,IAAI;YACzB,GACA;gBAAEhB,MAAMX;YAAI,GACZ;gBAAET;YAAQ;QAEd;QAEA8B,QAAQI,MAAM,CAACC,IAAI,CAAC,CAAC,iBAAiB,EAAEM,OAAOL,IAAI,CAAC,CAAC,CAAC;QAEtD,IAAIK,OAAOH,QAAQ,EAAE;YACnBR,QAAQI,MAAM,CAACC,IAAI,CAAC,CAAC,2BAA2B,EAAEM,OAAOL,IAAI,CAAC,CAAC,CAAC;YAEhE,MAAMzC,yBAAyB;gBAC7BC,SAASmC;gBACTlC;gBACAC,QAAQN,yBAAyBwC,QAAQS,QAAQ;gBACjD1C,OAAOgC,GAAGO,QAAQ,CAACG,OAAOL,IAAI,CAAC;gBAC/BpC;YACF;YAEA8B,QAAQI,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, SanitizedConfig } from 'payload'\n\nimport { buildVersionCollectionFields, buildVersionGlobalFields } from 'payload'\n\nimport type { MongooseAdapter } from '../index.js'\n\nimport { getSession } from '../utilities/getSession.js'\nimport { sanitizeRelationshipIDs } from '../utilities/sanitizeRelationshipIDs.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 getSession(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 // in case if the global doesn't exist in the database yet (not saved)\n if (doc) {\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\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","getSession","sanitizeRelationshipIDs","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,UAAU,QAAQ,6BAA4B;AACvD,SAASC,uBAAuB,QAAQ,0CAAyC;AAEjF,MAAMC,2BAA2B,OAAO,EACtCC,SAAS,EACTC,MAAM,EACNC,MAAM,EACNC,KAAK,EACLC,OAAO,EAOR;IACC,IAAIC,UAAU;IACd,IAAIC,OAAO;IAEX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;QAEvD,MAAMxB,MAAM,MAAM2B,aAAaE,OAAO,CACpC;YACEC,YAAY;gBACVC,KAAKH,OAAOJ,IAAI;YAClB;QACF,GACA,CAAC,GACD;YAAE5B,MAAM;YAAML;QAAQ;QAGxB,uEAAuE;QACvE,IAAIS,KAAK;YACPf,wBAAwB;gBAAEG;gBAAQa,MAAMD;gBAAKX,QAAQuC,OAAOvC,MAAM;YAAC;YAEnE,MAAMsC,aAAazB,UAAU,CAACG,SAAS,CACrC;gBACEyB,YAAYF,OAAOJ,IAAI;YACzB,GACA;gBAAEf,MAAMT;YAAI,GACZ;gBAAET;YAAQ;QAEd;QAEA4B,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"}
@@ -1,12 +1,10 @@
1
- import type { ClientSession } from 'mongodb';
2
1
  import type { FlattenedField, Payload, Where } from 'payload';
3
- export declare function buildAndOrConditions({ collectionSlug, fields, globalSlug, locale, payload, session, where, }: {
2
+ export declare function buildAndOrConditions({ collectionSlug, fields, globalSlug, locale, payload, where, }: {
4
3
  collectionSlug?: string;
5
4
  fields: FlattenedField[];
6
5
  globalSlug?: string;
7
6
  locale?: string;
8
7
  payload: Payload;
9
- session?: ClientSession;
10
8
  where: Where[];
11
9
  }): Promise<Record<string, unknown>[]>;
12
10
  //# 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,aAAa,EAAE,MAAM,SAAS,CAAA;AAC5C,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,OAAO,EACP,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,OAAO,EAAE,OAAO,CAAA;IAChB,OAAO,CAAC,EAAE,aAAa,CAAA;IACvB,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,KAAK,EAAE,MAAM,SAAS,CAAA;AAI7D,wBAAsB,oBAAoB,CAAC,EACzC,cAAc,EACd,MAAM,EACN,UAAU,EACV,MAAM,EACN,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,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,KAAK,EAAE,CAAA;CACf,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,CAsBrC"}
@@ -1,5 +1,5 @@
1
1
  import { parseParams } from './parseParams.js';
2
- export async function buildAndOrConditions({ collectionSlug, fields, globalSlug, locale, payload, session, where }) {
2
+ export async function buildAndOrConditions({ collectionSlug, fields, globalSlug, locale, payload, 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
@@ -12,7 +12,6 @@ export async function buildAndOrConditions({ collectionSlug, fields, globalSlug,
12
12
  globalSlug,
13
13
  locale,
14
14
  payload,
15
- session,
16
15
  where: condition
17
16
  });
18
17
  if (Object.keys(result).length > 0) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/queries/buildAndOrConditions.ts"],"sourcesContent":["import type { ClientSession } from 'mongodb'\nimport 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 payload,\n session,\n where,\n}: {\n collectionSlug?: string\n fields: FlattenedField[]\n globalSlug?: string\n locale?: string\n payload: Payload\n session?: ClientSession\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 payload,\n session,\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","payload","session","where","completedConditions","condition","result","Object","keys","length","push"],"mappings":"AAGA,SAASA,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,eAAeC,qBAAqB,EACzCC,cAAc,EACdC,MAAM,EACNC,UAAU,EACVC,MAAM,EACNC,OAAO,EACPC,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, Where } from 'payload'\n\nimport { parseParams } from './parseParams.js'\n\nexport async function buildAndOrConditions({\n collectionSlug,\n fields,\n globalSlug,\n locale,\n payload,\n where,\n}: {\n collectionSlug?: string\n fields: FlattenedField[]\n globalSlug?: string\n locale?: string\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 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","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,OAAO,EACPC,KAAK,EAQN;IACC,MAAMC,sBAAsB,EAAE;IAC9B,6EAA6E;IAC7E,6CAA6C;IAE7C,KAAK,MAAMC,aAAaF,MAAO;QAC7B,sDAAsD;QACtD,IAAI,OAAOE,cAAc,UAAU;YACjC,MAAMC,SAAS,MAAMV,YAAY;gBAC/BE;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,4 +1,3 @@
1
- import type { ClientSession } from 'mongodb';
2
1
  import type { FlattenedField, Payload, Where } from 'payload';
3
2
  type GetBuildQueryPluginArgs = {
4
3
  collectionSlug?: string;
@@ -8,7 +7,6 @@ export type BuildQueryArgs = {
8
7
  globalSlug?: string;
9
8
  locale?: string;
10
9
  payload: Payload;
11
- session?: ClientSession;
12
10
  where: Where;
13
11
  };
14
12
  export declare const getBuildQueryPlugin: ({ collectionSlug, versionsFields, }?: GetBuildQueryPluginArgs) => (schema: any) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"buildQuery.d.ts","sourceRoot":"","sources":["../../src/queries/buildQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAC5C,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAI7D,KAAK,uBAAuB,GAAG;IAC7B,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,cAAc,CAAC,EAAE,cAAc,EAAE,CAAA;CAClC,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,OAAO,CAAA;IAChB,OAAO,CAAC,EAAE,aAAa,CAAA;IACvB,KAAK,EAAE,KAAK,CAAA;CACb,CAAA;AAID,eAAO,MAAM,mBAAmB,yCAG7B,uBAAuB,0BAoCzB,CAAA"}
1
+ {"version":3,"file":"buildQuery.d.ts","sourceRoot":"","sources":["../../src/queries/buildQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAM7D,KAAK,uBAAuB,GAAG;IAC7B,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,cAAc,CAAC,EAAE,cAAc,EAAE,CAAA;CAClC,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"}
@@ -1,10 +1,11 @@
1
+ import { QueryError } from 'payload';
1
2
  import { parseParams } from './parseParams.js';
2
3
  // This plugin asynchronously builds a list of Mongoose query constraints
3
4
  // which can then be used in subsequent Mongoose queries.
4
5
  export const getBuildQueryPlugin = ({ collectionSlug, versionsFields } = {})=>{
5
6
  return function buildQueryPlugin(schema) {
6
7
  const modifiedSchema = schema;
7
- async function buildQuery({ globalSlug, locale, payload, session, where }) {
8
+ async function buildQuery({ globalSlug, locale, payload, where }) {
8
9
  let fields = versionsFields;
9
10
  if (!fields) {
10
11
  if (globalSlug) {
@@ -16,15 +17,18 @@ export const getBuildQueryPlugin = ({ collectionSlug, versionsFields } = {})=>{
16
17
  fields = collectionConfig.flattenedFields;
17
18
  }
18
19
  }
20
+ const errors = [];
19
21
  const result = await parseParams({
20
22
  collectionSlug,
21
23
  fields,
22
24
  globalSlug,
23
25
  locale,
24
26
  payload,
25
- session,
26
27
  where
27
28
  });
29
+ if (errors.length > 0) {
30
+ throw new QueryError(errors);
31
+ }
28
32
  return result;
29
33
  }
30
34
  modifiedSchema.statics.buildQuery = buildQuery;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/queries/buildQuery.ts"],"sourcesContent":["import type { ClientSession } from 'mongodb'\nimport type { FlattenedField, Payload, Where } from 'payload'\n\nimport { parseParams } from './parseParams.js'\n\ntype GetBuildQueryPluginArgs = {\n collectionSlug?: string\n versionsFields?: FlattenedField[]\n}\n\nexport type BuildQueryArgs = {\n globalSlug?: string\n locale?: string\n payload: Payload\n session?: ClientSession\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 session,\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.flattenedFields\n }\n if (collectionSlug) {\n const collectionConfig = payload.collections[collectionSlug].config\n fields = collectionConfig.flattenedFields\n }\n }\n\n const result = await parseParams({\n collectionSlug,\n fields,\n globalSlug,\n locale,\n payload,\n session,\n where,\n })\n\n return result\n }\n modifiedSchema.statics.buildQuery = buildQuery\n }\n}\n"],"names":["parseParams","getBuildQueryPlugin","collectionSlug","versionsFields","buildQueryPlugin","schema","modifiedSchema","buildQuery","globalSlug","locale","payload","session","where","fields","globalConfig","globals","config","find","slug","flattenedFields","collectionConfig","collections","result","statics"],"mappings":"AAGA,SAASA,WAAW,QAAQ,mBAAkB;AAe9C,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,OAAO,EACPC,KAAK,EACU;YACf,IAAIC,SAASV;YACb,IAAI,CAACU,QAAQ;gBACX,IAAIL,YAAY;oBACd,MAAMM,eAAeJ,QAAQK,OAAO,CAACC,MAAM,CAACC,IAAI,CAAC,CAAC,EAAEC,IAAI,EAAE,GAAKA,SAASV;oBACxEK,SAASC,aAAaK,eAAe;gBACvC;gBACA,IAAIjB,gBAAgB;oBAClB,MAAMkB,mBAAmBV,QAAQW,WAAW,CAACnB,eAAe,CAACc,MAAM;oBACnEH,SAASO,iBAAiBD,eAAe;gBAC3C;YACF;YAEA,MAAMG,SAAS,MAAMtB,YAAY;gBAC/BE;gBACAW;gBACAL;gBACAC;gBACAC;gBACAC;gBACAC;YACF;YAEA,OAAOU;QACT;QACAhB,eAAeiB,OAAO,CAAChB,UAAU,GAAGA;IACtC;AACF,EAAC"}
1
+ {"version":3,"sources":["../../src/queries/buildQuery.ts"],"sourcesContent":["import type { FlattenedField, Payload, Where } from 'payload'\n\nimport { QueryError } from 'payload'\n\nimport { parseParams } from './parseParams.js'\n\ntype GetBuildQueryPluginArgs = {\n collectionSlug?: string\n versionsFields?: FlattenedField[]\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.flattenedFields\n }\n if (collectionSlug) {\n const collectionConfig = payload.collections[collectionSlug].config\n fields = collectionConfig.flattenedFields\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","flattenedFields","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,aAAaK,eAAe;gBACvC;gBACA,IAAIhB,gBAAgB;oBAClB,MAAMiB,mBAAmBT,QAAQU,WAAW,CAAClB,eAAe,CAACa,MAAM;oBACnEH,SAASO,iBAAiBD,eAAe;gBAC3C;YACF;YACA,MAAMG,SAAS,EAAE;YACjB,MAAMC,SAAS,MAAMtB,YAAY;gBAC/BE;gBACAU;gBACAJ;gBACAC;gBACAC;gBACAC;YACF;YAEA,IAAIU,OAAOE,MAAM,GAAG,GAAG;gBACrB,MAAM,IAAIxB,WAAWsB;YACvB;YAEA,OAAOC;QACT;QACAhB,eAAekB,OAAO,CAACjB,UAAU,GAAGA;IACtC;AACF,EAAC"}
@@ -1,4 +1,3 @@
1
- import type { ClientSession } from 'mongodb';
2
1
  import type { FlattenedField, Payload } from 'payload';
3
2
  type SearchParam = {
4
3
  path?: string;
@@ -8,7 +7,7 @@ type SearchParam = {
8
7
  /**
9
8
  * Convert the Payload key / value / operator into a MongoDB query
10
9
  */
11
- export declare function buildSearchParam({ collectionSlug, fields, globalSlug, incomingPath, locale, operator, payload, session, val, }: {
10
+ export declare function buildSearchParam({ collectionSlug, fields, globalSlug, incomingPath, locale, operator, payload, val, }: {
12
11
  collectionSlug?: string;
13
12
  fields: FlattenedField[];
14
13
  globalSlug?: string;
@@ -16,7 +15,6 @@ export declare function buildSearchParam({ collectionSlug, fields, globalSlug, i
16
15
  locale?: string;
17
16
  operator: string;
18
17
  payload: Payload;
19
- session?: ClientSession;
20
18
  val: unknown;
21
19
  }): Promise<SearchParam>;
22
20
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"buildSearchParams.d.ts","sourceRoot":"","sources":["../../src/queries/buildSearchParams.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAe,MAAM,SAAS,CAAA;AACzD,OAAO,KAAK,EAAE,cAAc,EAAyB,OAAO,EAAE,MAAM,SAAS,CAAA;AAW7E,KAAK,WAAW,GAAG;IACjB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB,CAAA;AASD;;GAEG;AACH,wBAAsB,gBAAgB,CAAC,EACrC,cAAc,EACd,MAAM,EACN,UAAU,EACV,YAAY,EACZ,MAAM,EACN,QAAQ,EACR,OAAO,EACP,OAAO,EACP,GAAG,GACJ,EAAE;IACD,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,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,OAAO,CAAC,EAAE,aAAa,CAAA;IACvB,GAAG,EAAE,OAAO,CAAA;CACb,GAAG,OAAO,CAAC,WAAW,CAAC,CAgOvB"}
1
+ {"version":3,"file":"buildSearchParams.d.ts","sourceRoot":"","sources":["../../src/queries/buildSearchParams.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAyB,OAAO,EAAE,MAAM,SAAS,CAAA;AAW7E,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,cAAc,EAAE,CAAA;IACxB,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,CAiOvB"}
@@ -4,14 +4,12 @@ import { validOperators } from 'payload/shared';
4
4
  import { operatorMap } from './operatorMap.js';
5
5
  import { sanitizeQueryValue } from './sanitizeQueryValue.js';
6
6
  const subQueryOptions = {
7
- limit: 50,
8
- projection: {
9
- _id: true
10
- }
7
+ lean: true,
8
+ limit: 50
11
9
  };
12
10
  /**
13
11
  * Convert the Payload key / value / operator into a MongoDB query
14
- */ export async function buildSearchParam({ collectionSlug, fields, globalSlug, incomingPath, locale, operator, payload, session, val }) {
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
15
  if (sanitizedPath === 'id') {
@@ -89,13 +87,14 @@ const subQueryOptions = {
89
87
  }
90
88
  }
91
89
  });
92
- const result = await SubModel.collection.find(subQuery, {
93
- session,
94
- ...subQueryOptions
95
- }).toArray();
90
+ const result = await SubModel.find(subQuery, subQueryOptions);
96
91
  const $in = [];
97
92
  result.forEach((doc)=>{
98
- $in.push(doc._id);
93
+ const stringID = doc._id.toString();
94
+ $in.push(stringID);
95
+ if (Types.ObjectId.isValid(stringID)) {
96
+ $in.push(doc._id);
97
+ }
99
98
  });
100
99
  if (pathsToQuery.length === 1) {
101
100
  return {
@@ -115,10 +114,7 @@ const subQueryOptions = {
115
114
  };
116
115
  }
117
116
  const subQuery = priorQueryResult.value;
118
- const result = await SubModel.collection.find(subQuery, {
119
- session,
120
- ...subQueryOptions
121
- }).toArray();
117
+ const result = await SubModel.find(subQuery, subQueryOptions);
122
118
  const $in = result.map((doc)=>doc._id);
123
119
  // If it is the last recursion
124
120
  // then pass through the search param
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/queries/buildSearchParams.ts"],"sourcesContent":["import type { ClientSession, FindOptions } from 'mongodb'\nimport type { FlattenedField, Operator, PathToQuery, Payload } from 'payload'\n\nimport { Types } from 'mongoose'\nimport { getLocalizedPaths } from 'payload'\nimport { validOperators } from 'payload/shared'\n\nimport type { MongooseAdapter } from '../index.js'\n\nimport { operatorMap } from './operatorMap.js'\nimport { sanitizeQueryValue } from './sanitizeQueryValue.js'\n\ntype SearchParam = {\n path?: string\n rawQuery?: unknown\n value?: unknown\n}\n\nconst subQueryOptions: FindOptions = {\n limit: 50,\n projection: {\n _id: true,\n },\n}\n\n/**\n * Convert the Payload key / value / operator into a MongoDB query\n */\nexport async function buildSearchParam({\n collectionSlug,\n fields,\n globalSlug,\n incomingPath,\n locale,\n operator,\n payload,\n session,\n val,\n}: {\n collectionSlug?: string\n fields: FlattenedField[]\n globalSlug?: string\n incomingPath: string\n locale?: string\n operator: string\n payload: Payload\n session?: ClientSession\n val: unknown\n}): Promise<SearchParam> {\n // Replace GraphQL nested field double underscore formatting\n let sanitizedPath = incomingPath.replace(/__/g, '.')\n if (sanitizedPath === 'id') {\n sanitizedPath = '_id'\n }\n\n let paths: PathToQuery[] = []\n\n let hasCustomID = false\n\n if (sanitizedPath === '_id') {\n const customIDFieldType = payload.collections[collectionSlug]?.customIDType\n\n let idFieldType: 'number' | 'text' = 'text'\n\n if (customIDFieldType) {\n idFieldType = customIDFieldType\n hasCustomID = true\n }\n\n paths.push({\n collectionSlug,\n complete: true,\n field: {\n name: 'id',\n type: idFieldType,\n } as FlattenedField,\n path: '_id',\n })\n } else {\n paths = getLocalizedPaths({\n collectionSlug,\n fields,\n globalSlug,\n incomingPath: sanitizedPath,\n locale,\n payload,\n })\n }\n\n const [{ field, path }] = paths\n if (path) {\n const sanitizedQueryValue = sanitizeQueryValue({\n field,\n hasCustomID,\n locale,\n operator,\n path,\n payload,\n val,\n })\n\n if (!sanitizedQueryValue) {\n return undefined\n }\n\n const { operator: formattedOperator, rawQuery, val: formattedValue } = sanitizedQueryValue\n\n if (rawQuery) {\n return { value: rawQuery }\n }\n\n // If there are multiple collections to search through,\n // Recursively build up a list of query constraints\n if (paths.length > 1) {\n // Remove top collection and reverse array\n // to work backwards from top\n const pathsToQuery = paths.slice(1).reverse()\n\n const initialRelationshipQuery = {\n value: {},\n } as SearchParam\n\n const relationshipQuery = await pathsToQuery.reduce(\n async (priorQuery, { collectionSlug: slug, path: subPath }, i) => {\n const priorQueryResult = await priorQuery\n\n const SubModel = (payload.db as MongooseAdapter).collections[slug]\n\n // On the \"deepest\" collection,\n // Search on the value passed through the query\n if (i === 0) {\n const subQuery = await SubModel.buildQuery({\n locale,\n payload,\n where: {\n [subPath]: {\n [formattedOperator]: val,\n },\n },\n })\n\n const result = await SubModel.collection\n .find(subQuery, { session, ...subQueryOptions })\n .toArray()\n\n const $in: unknown[] = []\n\n result.forEach((doc) => {\n $in.push(doc._id)\n })\n\n if (pathsToQuery.length === 1) {\n return {\n path,\n value: { $in },\n }\n }\n\n const nextSubPath = pathsToQuery[i + 1].path\n\n return {\n value: { [nextSubPath]: { $in } },\n }\n }\n\n const subQuery = priorQueryResult.value\n const result = await SubModel.collection\n .find(subQuery, { session, ...subQueryOptions })\n .toArray()\n\n const $in = result.map((doc) => doc._id)\n\n // If it is the last recursion\n // then pass through the search param\n if (i + 1 === pathsToQuery.length) {\n return {\n path,\n value: { $in },\n }\n }\n\n return {\n value: {\n _id: { $in },\n },\n }\n },\n Promise.resolve(initialRelationshipQuery),\n )\n\n return relationshipQuery\n }\n\n if (formattedOperator && validOperators.includes(formattedOperator as Operator)) {\n const operatorKey = operatorMap[formattedOperator]\n\n if (field.type === 'relationship' || field.type === 'upload') {\n let hasNumberIDRelation\n let multiIDCondition = '$or'\n if (operatorKey === '$ne') {\n multiIDCondition = '$and'\n }\n\n const result = {\n value: {\n [multiIDCondition]: [{ [path]: { [operatorKey]: formattedValue } }],\n },\n }\n\n if (typeof formattedValue === 'string') {\n if (Types.ObjectId.isValid(formattedValue)) {\n result.value[multiIDCondition].push({\n [path]: { [operatorKey]: new Types.ObjectId(formattedValue) },\n })\n } else {\n ;(Array.isArray(field.relationTo) ? field.relationTo : [field.relationTo]).forEach(\n (relationTo) => {\n const isRelatedToCustomNumberID =\n payload.collections[relationTo]?.customIDType === 'number'\n\n if (isRelatedToCustomNumberID) {\n hasNumberIDRelation = true\n }\n },\n )\n\n if (hasNumberIDRelation) {\n result.value[multiIDCondition].push({\n [path]: { [operatorKey]: parseFloat(formattedValue) },\n })\n }\n }\n }\n\n if (result.value[multiIDCondition].length > 1) {\n return result\n }\n }\n\n if (formattedOperator === 'like' && typeof formattedValue === 'string') {\n const words = formattedValue.split(' ')\n\n const result = {\n value: {\n $and: words.map((word) => ({\n [path]: {\n $options: 'i',\n $regex: word.replace(/[\\\\^$*+?.()|[\\]{}]/g, '\\\\$&'),\n },\n })),\n },\n }\n\n return result\n }\n\n // Some operators like 'near' need to define a full query\n // so if there is no operator key, just return the value\n if (!operatorKey) {\n return {\n path,\n value: formattedValue,\n }\n }\n\n return {\n path,\n value: { [operatorKey]: formattedValue },\n }\n }\n }\n return undefined\n}\n"],"names":["Types","getLocalizedPaths","validOperators","operatorMap","sanitizeQueryValue","subQueryOptions","limit","projection","_id","buildSearchParam","collectionSlug","fields","globalSlug","incomingPath","locale","operator","payload","session","val","sanitizedPath","replace","paths","hasCustomID","customIDFieldType","collections","customIDType","idFieldType","push","complete","field","name","type","path","sanitizedQueryValue","undefined","formattedOperator","rawQuery","formattedValue","value","length","pathsToQuery","slice","reverse","initialRelationshipQuery","relationshipQuery","reduce","priorQuery","slug","subPath","i","priorQueryResult","SubModel","db","subQuery","buildQuery","where","result","collection","find","toArray","$in","forEach","doc","nextSubPath","map","Promise","resolve","includes","operatorKey","hasNumberIDRelation","multiIDCondition","ObjectId","isValid","Array","isArray","relationTo","isRelatedToCustomNumberID","parseFloat","words","split","$and","word","$options","$regex"],"mappings":"AAGA,SAASA,KAAK,QAAQ,WAAU;AAChC,SAASC,iBAAiB,QAAQ,UAAS;AAC3C,SAASC,cAAc,QAAQ,iBAAgB;AAI/C,SAASC,WAAW,QAAQ,mBAAkB;AAC9C,SAASC,kBAAkB,QAAQ,0BAAyB;AAQ5D,MAAMC,kBAA+B;IACnCC,OAAO;IACPC,YAAY;QACVC,KAAK;IACP;AACF;AAEA;;CAEC,GACD,OAAO,eAAeC,iBAAiB,EACrCC,cAAc,EACdC,MAAM,EACNC,UAAU,EACVC,YAAY,EACZC,MAAM,EACNC,QAAQ,EACRC,OAAO,EACPC,OAAO,EACPC,GAAG,EAWJ;IACC,4DAA4D;IAC5D,IAAIC,gBAAgBN,aAAaO,OAAO,CAAC,OAAO;IAChD,IAAID,kBAAkB,MAAM;QAC1BA,gBAAgB;IAClB;IAEA,IAAIE,QAAuB,EAAE;IAE7B,IAAIC,cAAc;IAElB,IAAIH,kBAAkB,OAAO;QAC3B,MAAMI,oBAAoBP,QAAQQ,WAAW,CAACd,eAAe,EAAEe;QAE/D,IAAIC,cAA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AQF,KAAK7D,OAAO,CAAC,uBAAuB;gCAC9C;4BACF,CAAA;oBACF;gBACF;gBAEA,OAAOoC;YACT;YAEA,yDAAyD;YACzD,wDAAwD;YACxD,IAAI,CAACY,aAAa;gBAChB,OAAO;oBACLpC;oBACAM,OAAOD;gBACT;YACF;YAEA,OAAO;gBACLL;gBACAM,OAAO;oBAAE,CAAC8B,YAAY,EAAE/B;gBAAe;YACzC;QACF;IACF;IACA,OAAOH;AACT"}
1
+ {"version":3,"sources":["../../src/queries/buildSearchParams.ts"],"sourcesContent":["import type { FlattenedField, Operator, PathToQuery, Payload } from 'payload'\n\nimport { Types } from 'mongoose'\nimport { getLocalizedPaths } from 'payload'\nimport { validOperators } from 'payload/shared'\n\nimport type { MongooseAdapter } from '../index.js'\n\nimport { operatorMap } from './operatorMap.js'\nimport { sanitizeQueryValue } from './sanitizeQueryValue.js'\n\ntype SearchParam = {\n path?: string\n rawQuery?: unknown\n value?: unknown\n}\n\nconst subQueryOptions = {\n lean: true,\n limit: 50,\n}\n\n/**\n * Convert the Payload key / value / operator into a MongoDB query\n */\nexport async function buildSearchParam({\n collectionSlug,\n fields,\n globalSlug,\n incomingPath,\n locale,\n operator,\n payload,\n val,\n}: {\n collectionSlug?: string\n fields: FlattenedField[]\n globalSlug?: string\n incomingPath: string\n locale?: string\n operator: string\n payload: Payload\n val: unknown\n}): Promise<SearchParam> {\n // Replace GraphQL nested field double underscore formatting\n let sanitizedPath = incomingPath.replace(/__/g, '.')\n if (sanitizedPath === 'id') {\n sanitizedPath = '_id'\n }\n\n let paths: PathToQuery[] = []\n\n let hasCustomID = false\n\n if (sanitizedPath === '_id') {\n const customIDFieldType = payload.collections[collectionSlug]?.customIDType\n\n let idFieldType: 'number' | 'text' = 'text'\n\n if (customIDFieldType) {\n idFieldType = customIDFieldType\n hasCustomID = true\n }\n\n paths.push({\n collectionSlug,\n complete: true,\n field: {\n name: 'id',\n type: idFieldType,\n } as FlattenedField,\n path: '_id',\n })\n } else {\n paths = getLocalizedPaths({\n collectionSlug,\n fields,\n globalSlug,\n incomingPath: sanitizedPath,\n locale,\n payload,\n })\n }\n\n const [{ field, path }] = paths\n if (path) {\n const sanitizedQueryValue = sanitizeQueryValue({\n field,\n hasCustomID,\n locale,\n operator,\n path,\n payload,\n val,\n })\n\n if (!sanitizedQueryValue) {\n return undefined\n }\n\n const { operator: formattedOperator, rawQuery, val: formattedValue } = sanitizedQueryValue\n\n if (rawQuery) {\n return { value: rawQuery }\n }\n\n // If there are multiple collections to search through,\n // Recursively build up a list of query constraints\n if (paths.length > 1) {\n // Remove top collection and reverse array\n // to work backwards from top\n const pathsToQuery = paths.slice(1).reverse()\n\n const initialRelationshipQuery = {\n value: {},\n } as SearchParam\n\n const relationshipQuery = await pathsToQuery.reduce(\n async (priorQuery, { collectionSlug: slug, path: subPath }, i) => {\n const priorQueryResult = await priorQuery\n\n const SubModel = (payload.db as MongooseAdapter).collections[slug]\n\n // On the \"deepest\" collection,\n // Search on the value passed through the query\n if (i === 0) {\n const subQuery = await SubModel.buildQuery({\n locale,\n payload,\n where: {\n [subPath]: {\n [formattedOperator]: val,\n },\n },\n })\n\n const result = await SubModel.find(subQuery, subQueryOptions)\n\n const $in: unknown[] = []\n\n result.forEach((doc) => {\n const stringID = doc._id.toString()\n $in.push(stringID)\n\n if (Types.ObjectId.isValid(stringID)) {\n $in.push(doc._id)\n }\n })\n\n if (pathsToQuery.length === 1) {\n return {\n path,\n value: { $in },\n }\n }\n\n const nextSubPath = pathsToQuery[i + 1].path\n\n return {\n value: { [nextSubPath]: { $in } },\n }\n }\n\n const subQuery = priorQueryResult.value\n const result = await SubModel.find(subQuery, subQueryOptions)\n\n const $in = result.map((doc) => doc._id)\n\n // If it is the last recursion\n // then pass through the search param\n if (i + 1 === pathsToQuery.length) {\n return {\n path,\n value: { $in },\n }\n }\n\n return {\n value: {\n _id: { $in },\n },\n }\n },\n Promise.resolve(initialRelationshipQuery),\n )\n\n return relationshipQuery\n }\n\n if (formattedOperator && validOperators.includes(formattedOperator as Operator)) {\n const operatorKey = operatorMap[formattedOperator]\n\n if (field.type === 'relationship' || field.type === 'upload') {\n let hasNumberIDRelation\n let multiIDCondition = '$or'\n if (operatorKey === '$ne') {\n multiIDCondition = '$and'\n }\n\n const result = {\n value: {\n [multiIDCondition]: [{ [path]: { [operatorKey]: formattedValue } }],\n },\n }\n\n if (typeof formattedValue === 'string') {\n if (Types.ObjectId.isValid(formattedValue)) {\n result.value[multiIDCondition].push({\n [path]: { [operatorKey]: new Types.ObjectId(formattedValue) },\n })\n } else {\n ;(Array.isArray(field.relationTo) ? field.relationTo : [field.relationTo]).forEach(\n (relationTo) => {\n const isRelatedToCustomNumberID =\n payload.collections[relationTo]?.customIDType === 'number'\n\n if (isRelatedToCustomNumberID) {\n hasNumberIDRelation = true\n }\n },\n )\n\n if (hasNumberIDRelation) {\n result.value[multiIDCondition].push({\n [path]: { [operatorKey]: parseFloat(formattedValue) },\n })\n }\n }\n }\n\n if (result.value[multiIDCondition].length > 1) {\n return result\n }\n }\n\n if (formattedOperator === 'like' && typeof formattedValue === 'string') {\n const words = formattedValue.split(' ')\n\n const result = {\n value: {\n $and: words.map((word) => ({\n [path]: {\n $options: 'i',\n $regex: word.replace(/[\\\\^$*+?.()|[\\]{}]/g, '\\\\$&'),\n },\n })),\n },\n }\n\n return result\n }\n\n // Some operators like 'near' need to define a full query\n // so if there is no operator key, just return the value\n if (!operatorKey) {\n return {\n path,\n value: formattedValue,\n }\n }\n\n return {\n path,\n value: { [operatorKey]: formattedValue },\n }\n }\n }\n return undefined\n}\n"],"names":["Types","getLocalizedPaths","validOperators","operatorMap","sanitizeQueryValue","subQueryOptions","lean","limit","buildSearchParam","collectionSlug","fields","globalSlug","incomingPath","locale","operator","payload","val","sanitizedPath","replace","paths","hasCustomID","customIDFieldType","collections","customIDType","idFieldType","push","complete","field","name","type","path","sanitizedQueryValue","undefined","formattedOperator","rawQuery","formattedValue","value","length","pathsToQuery","slice","reverse","initialRelationshipQuery","relationshipQuery","reduce","priorQuery","slug","subPath","i","priorQueryResult","SubModel","db","subQuery","buildQuery","where","result","find","$in","forEach","doc","stringID","_id","toString","ObjectId","isValid","nextSubPath","map","Promise","resolve","includes","operatorKey","hasNumberIDRelation","multiIDCondition","Array","isArray","relationTo","isRelatedToCustomNumberID","parseFloat","words","split","$and","word","$options","$regex"],"mappings":"AAEA,SAASA,KAAK,QAAQ,WAAU;AAChC,SAASC,iBAAiB,QAAQ,UAAS;AAC3C,SAASC,cAAc,QAAQ,iBAAgB;AAI/C,SAASC,WAAW,QAAQ,mBAAkB;AAC9C,SAASC,kBAAkB,QAAQ,0BAAyB;AAQ5D,MAAMC,kBAAkB;IACtBC,MAAM;IACNC,OAAO;AACT;AAEA;;CAEC,GACD,OAAO,eAAeC,iBAAiB,EACrCC,cAAc,EACdC,MAAM,EACNC,UAAU,EACVC,YAAY,EACZC,MAAM,EACNC,QAAQ,EACRC,OAAO,EACPC,GAAG,EAUJ;IACC,4DAA4D;IAC5D,IAAIC,gBAAgBL,aAAaM,OAAO,CAAC,OAAO;IAChD,IAAID,kBAAkB,MAAM;QAC1BA,gBAAgB;IAClB;IAEA,IAAIE,QAAuB,EAAE;IAE7B,IAAIC,cAAc;IAElB,IAAIH,kBAAkB,OAAO;QAC3B,MAAMI,oBAAoBN,QAAQO,WAAW,CAACb,eAAe,EAAEc;QAE/D,IAAIC,cAAiC;QAErC,IAAIH,mBAAmB;YACrBG,cAAcH;YACdD,cAAc;QAChB;QAEAD,MAAMM,IAAI,CAAC;YACThB;YACAiB,UAAU;YACVC,OAAO;gBACLC,MAAM;gBACNC,MAAML;YACR;YACAM,MAAM;QACR;IACF,OAAO;QACLX,QAAQlB,kBAAkB;YACxBQ;YACAC;YACAC;YACAC,cAAcK;YACdJ;YACAE;QACF;IACF;IAEA,MAAM,CAAC,EAAEY,KAAK,EAAEG,IAAI,EAAE,CAAC,GAAGX;IAC1B,IAAIW,MAAM;QACR,MAAMC,sBAAsB3B,mBAAmB;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Field, SanitizedConfig, Sort } from 'payload';
2
3
  type Args = {
3
4
  config: SanitizedConfig;
@@ -6,6 +7,11 @@ type Args = {
6
7
  sort: Sort;
7
8
  timestamps: boolean;
8
9
  };
9
- export declare const buildSortParam: ({ config, fields, locale, sort, timestamps, }: Args) => Record<string, -1 | 1>;
10
+ export type SortArgs = {
11
+ direction: SortDirection;
12
+ property: string;
13
+ }[];
14
+ export type SortDirection = 'asc' | 'desc';
15
+ export declare const buildSortParam: ({ config, fields, locale, sort, timestamps, }: Args) => PaginateOptions["sort"];
10
16
  export {};
11
17
  //# sourceMappingURL=buildSortParam.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"buildSortParam.d.ts","sourceRoot":"","sources":["../../src/queries/buildSortParam.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAIpE,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,eAAe,CAAA;IACvB,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,IAAI,CAAA;IACV,UAAU,EAAE,OAAO,CAAA;CACpB,CAAA;AAED,eAAO,MAAM,cAAc,kDAMxB,IAAI,KAAG,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAsC9B,CAAA"}
1
+ {"version":3,"file":"buildSortParam.d.ts","sourceRoot":"","sources":["../../src/queries/buildSortParam.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAC/C,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAIpE,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,eAAe,CAAA;IACvB,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,IAAI,CAAA;IACV,UAAU,EAAE,OAAO,CAAA;CACpB,CAAA;AAED,MAAM,MAAM,QAAQ,GAAG;IACrB,SAAS,EAAE,aAAa,CAAA;IACxB,QAAQ,EAAE,MAAM,CAAA;CACjB,EAAE,CAAA;AAEH,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,MAAM,CAAA;AAE1C,eAAO,MAAM,cAAc,kDAMxB,IAAI,KAAG,eAAe,CAAC,MAAM,CAsC/B,CAAA"}
@@ -17,10 +17,10 @@ export const buildSortParam = ({ config, fields, locale, sort, timestamps })=>{
17
17
  let sortDirection;
18
18
  if (item.indexOf('-') === 0) {
19
19
  sortProperty = item.substring(1);
20
- sortDirection = -1;
20
+ sortDirection = 'desc';
21
21
  } else {
22
22
  sortProperty = item;
23
- sortDirection = 1;
23
+ sortDirection = 'asc';
24
24
  }
25
25
  if (sortProperty === 'id') {
26
26
  acc['_id'] = sortDirection;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/queries/buildSortParam.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { FlattenedField, SanitizedConfig, Sort } from 'payload'\n\nimport { getLocalizedSortProperty } from './getLocalizedSortProperty.js'\n\ntype Args = {\n config: SanitizedConfig\n fields: FlattenedField[]\n locale: string\n sort: Sort\n timestamps: boolean\n}\n\nexport const buildSortParam = ({\n config,\n fields,\n locale,\n sort,\n timestamps,\n}: Args): Record<string, -1 | 1> => {\n if (!sort) {\n if (timestamps) {\n sort = '-createdAt'\n } else {\n sort = '-id'\n }\n }\n\n if (typeof sort === 'string') {\n sort = [sort]\n }\n\n const sorting = sort.reduce<Record<string, -1 | 1>>((acc, item) => {\n let sortProperty: string\n let sortDirection: -1 | 1\n if (item.indexOf('-') === 0) {\n sortProperty = item.substring(1)\n sortDirection = -1\n } else {\n sortProperty = item\n sortDirection = 1\n }\n if (sortProperty === 'id') {\n acc['_id'] = sortDirection\n return acc\n }\n const localizedProperty = getLocalizedSortProperty({\n config,\n fields,\n locale,\n segments: sortProperty.split('.'),\n })\n acc[localizedProperty] = sortDirection\n return acc\n }, {})\n\n return sorting\n}\n"],"names":["getLocalizedSortProperty","buildSortParam","config","fields","locale","sort","timestamps","sorting","reduce","acc","item","sortProperty","sortDirection","indexOf","substring","localizedProperty","segments","split"],"mappings":"AAGA,SAASA,wBAAwB,QAAQ,gCAA+B;AAUxE,OAAO,MAAMC,iBAAiB,CAAC,EAC7BC,MAAM,EACNC,MAAM,EACNC,MAAM,EACNC,IAAI,EACJC,UAAU,EACL;IACL,IAAI,CAACD,MAAM;QACT,IAAIC,YAAY;YACdD,OAAO;QACT,OAAO;YACLA,OAAO;QACT;IACF;IAEA,IAAI,OAAOA,SAAS,UAAU;QAC5BA,OAAO;YAACA;SAAK;IACf;IAEA,MAAME,UAAUF,KAAKG,MAAM,CAAyB,CAACC,KAAKC;QACxD,IAAIC;QACJ,IAAIC;QACJ,IAAIF,KAAKG,OAAO,CAAC,SAAS,GAAG;YAC3BF,eAAeD,KAAKI,SAAS,CAAC;YAC9BF,gBAAgB,CAAC;QACnB,OAAO;YACLD,eAAeD;YACfE,gBAAgB;QAClB;QACA,IAAID,iBAAiB,MAAM;YACzBF,GAAG,CAAC,MAAM,GAAGG;YACb,OAAOH;QACT;QACA,MAAMM,oBAAoBf,yBAAyB;YACjDE;YACAC;YACAC;YACAY,UAAUL,aAAaM,KAAK,CAAC;QAC/B;QACAR,GAAG,CAACM,kBAAkB,GAAGH;QACzB,OAAOH;IACT,GAAG,CAAC;IAEJ,OAAOF;AACT,EAAC"}
1
+ {"version":3,"sources":["../../src/queries/buildSortParam.ts"],"sourcesContent":["import type { PaginateOptions } from 'mongoose'\nimport type { FlattenedField, SanitizedConfig, Sort } from 'payload'\n\nimport { getLocalizedSortProperty } from './getLocalizedSortProperty.js'\n\ntype Args = {\n config: SanitizedConfig\n fields: FlattenedField[]\n locale: string\n sort: Sort\n timestamps: boolean\n}\n\nexport type SortArgs = {\n direction: SortDirection\n property: string\n}[]\n\nexport type SortDirection = 'asc' | 'desc'\n\nexport const buildSortParam = ({\n config,\n fields,\n locale,\n sort,\n timestamps,\n}: Args): PaginateOptions['sort'] => {\n if (!sort) {\n if (timestamps) {\n sort = '-createdAt'\n } else {\n sort = '-id'\n }\n }\n\n if (typeof sort === 'string') {\n sort = [sort]\n }\n\n const sorting = sort.reduce<PaginateOptions['sort']>((acc, item) => {\n let sortProperty: string\n let sortDirection: SortDirection\n if (item.indexOf('-') === 0) {\n sortProperty = item.substring(1)\n sortDirection = 'desc'\n } else {\n sortProperty = item\n sortDirection = 'asc'\n }\n if (sortProperty === 'id') {\n acc['_id'] = sortDirection\n return acc\n }\n const localizedProperty = getLocalizedSortProperty({\n config,\n fields,\n locale,\n segments: sortProperty.split('.'),\n })\n acc[localizedProperty] = sortDirection\n return acc\n }, {})\n\n return sorting\n}\n"],"names":["getLocalizedSortProperty","buildSortParam","config","fields","locale","sort","timestamps","sorting","reduce","acc","item","sortProperty","sortDirection","indexOf","substring","localizedProperty","segments","split"],"mappings":"AAGA,SAASA,wBAAwB,QAAQ,gCAA+B;AAiBxE,OAAO,MAAMC,iBAAiB,CAAC,EAC7BC,MAAM,EACNC,MAAM,EACNC,MAAM,EACNC,IAAI,EACJC,UAAU,EACL;IACL,IAAI,CAACD,MAAM;QACT,IAAIC,YAAY;YACdD,OAAO;QACT,OAAO;YACLA,OAAO;QACT;IACF;IAEA,IAAI,OAAOA,SAAS,UAAU;QAC5BA,OAAO;YAACA;SAAK;IACf;IAEA,MAAME,UAAUF,KAAKG,MAAM,CAA0B,CAACC,KAAKC;QACzD,IAAIC;QACJ,IAAIC;QACJ,IAAIF,KAAKG,OAAO,CAAC,SAAS,GAAG;YAC3BF,eAAeD,KAAKI,SAAS,CAAC;YAC9BF,gBAAgB;QAClB,OAAO;YACLD,eAAeD;YACfE,gBAAgB;QAClB;QACA,IAAID,iBAAiB,MAAM;YACzBF,GAAG,CAAC,MAAM,GAAGG;YACb,OAAOH;QACT;QACA,MAAMM,oBAAoBf,yBAAyB;YACjDE;YACAC;YACAC;YACAY,UAAUL,aAAaM,KAAK,CAAC;QAC/B;QACAR,GAAG,CAACM,kBAAkB,GAAGH;QACzB,OAAOH;IACT,GAAG,CAAC;IAEJ,OAAOF;AACT,EAAC"}
@@ -1,4 +1,4 @@
1
- import { fieldAffectsData } from 'payload/shared';
1
+ import { fieldAffectsData, fieldIsPresentationalOnly } from 'payload/shared';
2
2
  export const getLocalizedSortProperty = ({ config, fields, locale, result: incomingResult, segments: incomingSegments })=>{
3
3
  // If localization is not enabled, accept exactly
4
4
  // what is sent in
@@ -12,7 +12,7 @@ export const getLocalizedSortProperty = ({ config, fields, locale, result: incom
12
12
  const firstSegment = segments.shift();
13
13
  // Attempt to find a matched field
14
14
  const matchedField = fields.find((field)=>fieldAffectsData(field) && field.name === firstSegment);
15
- if (matchedField) {
15
+ if (matchedField && !fieldIsPresentationalOnly(matchedField)) {
16
16
  let nextFields;
17
17
  const remainingSegments = [
18
18
  ...segments
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/queries/getLocalizedSortProperty.ts"],"sourcesContent":["import type { FlattenedField, SanitizedConfig } from 'payload'\n\nimport { fieldAffectsData } from 'payload/shared'\n\ntype Args = {\n config: SanitizedConfig\n fields: FlattenedField[]\n locale: string\n result?: string\n segments: string[]\n}\n\nexport const getLocalizedSortProperty = ({\n config,\n fields,\n locale,\n result: incomingResult,\n segments: incomingSegments,\n}: Args): string => {\n // If localization is not enabled, accept exactly\n // what is sent in\n if (!config.localization) {\n return incomingSegments.join('.')\n }\n\n const segments = [...incomingSegments]\n\n // Retrieve first segment, and remove from segments\n const firstSegment = segments.shift()\n\n // Attempt to find a matched field\n const matchedField = fields.find(\n (field) => fieldAffectsData(field) && field.name === firstSegment,\n )\n\n if (matchedField) {\n let nextFields: FlattenedField[]\n const remainingSegments = [...segments]\n let localizedSegment = matchedField.name\n\n if (matchedField.localized) {\n // Check to see if next segment is a locale\n if (segments.length > 0) {\n const nextSegmentIsLocale = config.localization.localeCodes.includes(remainingSegments[0])\n\n // If next segment is locale, remove it from remaining segments\n // and use it to localize the current segment\n if (nextSegmentIsLocale) {\n const nextSegment = remainingSegments.shift()\n localizedSegment = `${matchedField.name}.${nextSegment}`\n }\n } else {\n // If no more segments, but field is localized, use default locale\n localizedSegment = `${matchedField.name}.${locale}`\n }\n }\n\n // If there are subfields, pass them through\n if (\n matchedField.type === 'tab' ||\n matchedField.type === 'group' ||\n matchedField.type === 'array'\n ) {\n nextFields = matchedField.flattenedFields\n }\n\n if (matchedField.type === 'blocks') {\n nextFields = matchedField.blocks.reduce((flattenedBlockFields, block) => {\n return [\n ...flattenedBlockFields,\n ...block.flattenedFields.filter(\n (blockField) =>\n (fieldAffectsData(blockField) &&\n blockField.name !== 'blockType' &&\n blockField.name !== 'blockName') ||\n !fieldAffectsData(blockField),\n ),\n ]\n }, [])\n }\n\n const result = incomingResult ? `${incomingResult}.${localizedSegment}` : localizedSegment\n\n if (nextFields) {\n return getLocalizedSortProperty({\n config,\n fields: nextFields,\n locale,\n result,\n segments: remainingSegments,\n })\n }\n\n return result\n }\n\n return incomingSegments.join('.')\n}\n"],"names":["fieldAffectsData","getLocalizedSortProperty","config","fields","locale","result","incomingResult","segments","incomingSegments","localization","join","firstSegment","shift","matchedField","find","field","name","nextFields","remainingSegments","localizedSegment","localized","length","nextSegmentIsLocale","localeCodes","includes","nextSegment","type","flattenedFields","blocks","reduce","flattenedBlockFields","block","filter","blockField"],"mappings":"AAEA,SAASA,gBAAgB,QAAQ,iBAAgB;AAUjD,OAAO,MAAMC,2BAA2B,CAAC,EACvCC,MAAM,EACNC,MAAM,EACNC,MAAM,EACNC,QAAQC,cAAc,EACtBC,UAAUC,gBAAgB,EACrB;IACL,iDAAiD;IACjD,kBAAkB;IAClB,IAAI,CAACN,OAAOO,YAAY,EAAE;QACxB,OAAOD,iBAAiBE,IAAI,CAAC;IAC/B;IAEA,MAAMH,WAAW;WAAIC;KAAiB;IAEtC,mDAAmD;IACnD,MAAMG,eAAeJ,SAASK,KA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;gBACRb;gBACAC;gBACAE,UAAUW;YACZ;QACF;QAEA,OAAOb;IACT;IAEA,OAAOG,iBAAiBE,IAAI,CAAC;AAC/B,EAAC"}
1
+ {"version":3,"sources":["../../src/queries/getLocalizedSortProperty.ts"],"sourcesContent":["import type { FlattenedField, SanitizedConfig } from 'payload'\n\nimport { fieldAffectsData, fieldIsPresentationalOnly } from 'payload/shared'\n\ntype Args = {\n config: SanitizedConfig\n fields: FlattenedField[]\n locale: string\n result?: string\n segments: string[]\n}\n\nexport const getLocalizedSortProperty = ({\n config,\n fields,\n locale,\n result: incomingResult,\n segments: incomingSegments,\n}: Args): string => {\n // If localization is not enabled, accept exactly\n // what is sent in\n if (!config.localization) {\n return incomingSegments.join('.')\n }\n\n const segments = [...incomingSegments]\n\n // Retrieve first segment, and remove from segments\n const firstSegment = segments.shift()\n\n // Attempt to find a matched field\n const matchedField = fields.find(\n (field) => fieldAffectsData(field) && field.name === firstSegment,\n )\n\n if (matchedField && !fieldIsPresentationalOnly(matchedField)) {\n let nextFields: FlattenedField[]\n const remainingSegments = [...segments]\n let localizedSegment = matchedField.name\n\n if (matchedField.localized) {\n // Check to see if next segment is a locale\n if (segments.length > 0) {\n const nextSegmentIsLocale = config.localization.localeCodes.includes(remainingSegments[0])\n\n // If next segment is locale, remove it from remaining segments\n // and use it to localize the current segment\n if (nextSegmentIsLocale) {\n const nextSegment = remainingSegments.shift()\n localizedSegment = `${matchedField.name}.${nextSegment}`\n }\n } else {\n // If no more segments, but field is localized, use default locale\n localizedSegment = `${matchedField.name}.${locale}`\n }\n }\n\n // If there are subfields, pass them through\n if (\n matchedField.type === 'tab' ||\n matchedField.type === 'group' ||\n matchedField.type === 'array'\n ) {\n nextFields = matchedField.flattenedFields\n }\n\n if (matchedField.type === 'blocks') {\n nextFields = matchedField.blocks.reduce((flattenedBlockFields, block) => {\n return [\n ...flattenedBlockFields,\n ...block.flattenedFields.filter(\n (blockField) =>\n (fieldAffectsData(blockField) &&\n blockField.name !== 'blockType' &&\n blockField.name !== 'blockName') ||\n !fieldAffectsData(blockField),\n ),\n ]\n }, [])\n }\n\n const result = incomingResult ? `${incomingResult}.${localizedSegment}` : localizedSegment\n\n if (nextFields) {\n return getLocalizedSortProperty({\n config,\n fields: nextFields,\n locale,\n result,\n segments: remainingSegments,\n })\n }\n\n return result\n }\n\n return incomingSegments.join('.')\n}\n"],"names":["fieldAffectsData","fieldIsPresentationalOnly","getLocalizedSortProperty","config","fields","locale","result","incomingResult","segments","incomingSegments","localization","join","firstSegment","shift","matchedField","find","field","name","nextFields","remainingSegments","localizedSegment","localized","length","nextSegmentIsLocale","localeCodes","includes","nextSegment","type","flattenedFields","blocks","reduce","flattenedBlockFields","block","filter","blockField"],"mappings":"AAEA,SAASA,gBAAgB,EAAEC,yBAAyB,QAAQ,iBAAgB;AAU5E,OAAO,MAAMC,2BAA2B,CAAC,EACvCC,MAAM,EACNC,MAAM,EACNC,MAAM,EACNC,QAAQC,cAAc,EACtBC,UAAUC,gBAAgB,EACrB;IACL,iDAAiD;IACjD,kBAAkB;IAClB,IAAI,CAACN,OAAOO,YAAY,EAAE;QACxB,OAAOD,iBAAiBE,IAAI,CAAC;IAC/B;IAEA,MAAMH,WAAW;WAAIC;KAAiB;IAEtC,mDAAmD;IACnD,MAAMG,eAAeJ,SAASK,KAAK;IAEnC,kCAAkC;IAClC,MAAMC,eAAeV,OAAOW,IAAI,CAC9B,CAACC,QAAUhB,iBAAiBgB,UAAUA,MAAMC,IAAI,KAAKL;IAGvD,IAAIE,gBAAgB,CAACb,0BAA0Ba,eAAe;QAC5D,IAAII;QACJ,MAAMC,oBAAoB;eAAIX;SAAS;QACvC,IAAIY,mBAAmBN,aAAaG,IAAI;QAExC,IAAIH,aAAaO,SAAS,EAAE;YAC1B,2CAA2C;YAC3C,IAAIb,SAASc,MAAM,GAAG,GAAG;gBACvB,MAAMC,sBAAsBpB,OAAOO,YAAY,CAACc,WAAW,CAACC,QAAQ,CAACN,iBAAiB,CAAC,EAAE;gBAEzF,+DAA+D;gBAC/D,6CAA6C;gBAC7C,IAAII,qBAAqB;oBACvB,MAAMG,cAAcP,kBAAkBN,KAAK;oBAC3CO,mBAAmB,GAAGN,aAAaG,IAAI,CAAC,CAAC,EAAES,aAAa;gBAC1D;YACF,OAAO;gBACL,kEAAkE;gBAClEN,mBAAmB,GAAGN,aAAaG,IAAI,CAAC,CAAC,EAAEZ,QAAQ;YACrD;QACF;QAEA,4CAA4C;QAC5C,IACES,aAAaa,IAAI,KAAK,SACtBb,aAAaa,IAAI,KAAK,WACtBb,aAAaa,IAAI,KAAK,SACtB;YACAT,aAAaJ,aAAac,eAAe;QAC3C;QAEA,IAAId,aAAaa,IAAI,KAAK,UAAU;YAClCT,aAAaJ,aAAae,MAAM,CAACC,MAAM,CAAC,CAACC,sBAAsBC;gBAC7D,OAAO;uBACFD;uBACAC,MAAMJ,eAAe,CAACK,MAAM,CAC7B,CAACC,aACC,AAAClC,iBAAiBkC,eAChBA,WAAWjB,IAAI,KAAK,eACpBiB,WAAWjB,IAAI,KAAK,eACtB,CAACjB,iBAAiBkC;iBAEvB;YACH,GAAG,EAAE;QACP;QAEA,MAAM5B,SAASC,iBAAiB,GAAGA,eAAe,CAAC,EAAEa,kBAAkB,GAAGA;QAE1E,IAAIF,YAAY;YACd,OAAOhB,yBAAyB;gBAC9BC;gBACAC,QAAQc;gBACRb;gBACAC;gBACAE,UAAUW;YACZ;QACF;QAEA,OAAOb;IACT;IAEA,OAAOG,iBAAiBE,IAAI,CAAC;AAC/B,EAAC"}
@@ -1,12 +1,10 @@
1
- import type { ClientSession } from 'mongodb';
2
1
  import type { FlattenedField, Payload, Where } from 'payload';
3
- export declare function parseParams({ collectionSlug, fields, globalSlug, locale, payload, session, where, }: {
2
+ export declare function parseParams({ collectionSlug, fields, globalSlug, locale, payload, where, }: {
4
3
  collectionSlug?: string;
5
4
  fields: FlattenedField[];
6
5
  globalSlug?: string;
7
6
  locale: string;
8
7
  payload: Payload;
9
- session?: ClientSession;
10
8
  where: Where;
11
9
  }): Promise<Record<string, unknown>>;
12
10
  //# sourceMappingURL=parseParams.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"parseParams.d.ts","sourceRoot":"","sources":["../../src/queries/parseParams.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAE5C,OAAO,KAAK,EAAE,cAAc,EAAY,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAQvE,wBAAsB,WAAW,CAAC,EAChC,cAAc,EACd,MAAM,EACN,UAAU,EACV,MAAM,EACN,OAAO,EACP,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,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,OAAO,CAAA;IAChB,OAAO,CAAC,EAAE,aAAa,CAAA;IACvB,KAAK,EAAE,KAAK,CAAA;CACb,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAgEnC"}
1
+ {"version":3,"file":"parseParams.d.ts","sourceRoot":"","sources":["../../src/queries/parseParams.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAY,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAQvE,wBAAsB,WAAW,CAAC,EAChC,cAAc,EACd,MAAM,EACN,UAAU,EACV,MAAM,EACN,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,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,KAAK,CAAA;CACb,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CA+DnC"}
@@ -2,7 +2,7 @@ import { deepMergeWithCombinedArrays } from 'payload';
2
2
  import { validOperators } from 'payload/shared';
3
3
  import { buildAndOrConditions } from './buildAndOrConditions.js';
4
4
  import { buildSearchParam } from './buildSearchParams.js';
5
- export async function parseParams({ collectionSlug, fields, globalSlug, locale, payload, session, where }) {
5
+ export async function parseParams({ collectionSlug, fields, globalSlug, locale, payload, where }) {
6
6
  let result = {};
7
7
  if (typeof where === 'object') {
8
8
  // We need to determine if the whereKey is an AND, OR, or a schema path
@@ -42,7 +42,6 @@ export async function parseParams({ collectionSlug, fields, globalSlug, locale,
42
42
  locale,
43
43
  operator,
44
44
  payload,
45
- session,
46
45
  val: pathOperators[operator]
47
46
  });
48
47
  if (searchParam?.value && searchParam?.path) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/queries/parseParams.ts"],"sourcesContent":["import type { ClientSession } from 'mongodb'\nimport type { FilterQuery } from 'mongoose'\nimport type { FlattenedField, Operator, Payload, Where } from 'payload'\n\nimport { deepMergeWithCombinedArrays } from 'payload'\nimport { validOperators } from 'payload/shared'\n\nimport { buildAndOrConditions } from './buildAndOrConditions.js'\nimport { buildSearchParam } from './buildSearchParams.js'\n\nexport async function parseParams({\n collectionSlug,\n fields,\n globalSlug,\n locale,\n payload,\n session,\n where,\n}: {\n collectionSlug?: string\n fields: FlattenedField[]\n globalSlug?: string\n locale: string\n payload: Payload\n session?: ClientSession\n where: Where\n}): Promise<Record<string, unknown>> {\n let result = {} as FilterQuery<any>\n\n if (typeof where === 'object') {\n // We need to determine if the whereKey is an AND, OR, or a schema path\n for (const relationOrPath of Object.keys(where)) {\n const condition = where[relationOrPath]\n let conditionOperator: '$and' | '$or'\n if (relationOrPath.toLowerCase() === 'and') {\n conditionOperator = '$and'\n } else if (relationOrPath.toLowerCase() === 'or') {\n conditionOperator = '$or'\n }\n if (Array.isArray(condition)) {\n const builtConditions = await buildAndOrConditions({\n collectionSlug,\n fields,\n globalSlug,\n locale,\n payload,\n where: condition,\n })\n if (builtConditions.length > 0) {\n result[conditionOperator] = builtConditions\n }\n } else {\n // It's a path - and there can be multiple comparisons on a single path.\n // For example - title like 'test' and title not equal to 'tester'\n // So we need to loop on keys again here to handle each operator independently\n const pathOperators = where[relationOrPath]\n if (typeof pathOperators === 'object') {\n for (const operator of Object.keys(pathOperators)) {\n if (validOperators.includes(operator as Operator)) {\n const searchParam = await buildSearchParam({\n collectionSlug,\n fields,\n globalSlug,\n incomingPath: relationOrPath,\n locale,\n operator,\n payload,\n session,\n val: pathOperators[operator],\n })\n\n if (searchParam?.value && searchParam?.path) {\n result = {\n ...result,\n [searchParam.path]: searchParam.value,\n }\n } else if (typeof searchParam?.value === 'object') {\n result = deepMergeWithCombinedArrays(result, searchParam.value, {\n // dont clone Types.ObjectIDs\n clone: false,\n })\n }\n }\n }\n }\n }\n }\n }\n\n return result\n}\n"],"names":["deepMergeWithCombinedArrays","validOperators","buildAndOrConditions","buildSearchParam","parseParams","collectionSlug","fields","globalSlug","locale","payload","session","where","result","relationOrPath","Object","keys","condition","conditionOperator","toLowerCase","Array","isArray","builtConditions","length","pathOperators","operator","includes","searchParam","incomingPath","val","value","path","clone"],"mappings":"AAIA,SAASA,2BAA2B,QAAQ,UAAS;AACrD,SAASC,cAAc,QAAQ,iBAAgB;AAE/C,SAASC,oBAAoB,QAAQ,4BAA2B;AAChE,SAASC,gBAAgB,QAAQ,yBAAwB;AAEzD,OAAO,eAAeC,YAAY,EAChCC,cAAc,EACdC,MAAM,EACNC,UAAU,EACVC,MAAM,EACNC,OAAO,EACPC,OAAO,EACPC,KAAK,EASN;IACC,IAAIC,SAAS,CAAC;IAEd,IAAI,OAAOD,UAAU,UAAU;QAC7B,uEAAuE;QACvE,KAAK,MAAME,kBAAkBC,OAAOC,IAAI,CAACJ,OAAQ;YAC/C,MAAMK,YAAYL,KAAK,CAACE,eAAe;YACvC,IAAII;YACJ,IAAIJ,eAAeK,WAAW,OAAO,OAAO;gBAC1CD,oBAAoB;YACtB,OAAO,IAAIJ,eAAeK,WAAW,OAAO,MAAM;gBAChDD,oBAAoB;YACtB;YACA,IAAIE,MAAMC,OAAO,CAACJ,YAAY;gBAC5B,MAAMK,kBAAkB,MAAMnB,qBAAqB;oBACjDG;oBACAC;oBACAC;oBACAC;oBACAC;oBACAE,OAAOK;gBACT;gBACA,IAAIK,gBAAgBC,MAAM,GAAG,GAAG;oBAC9BV,MAAM,CAACK,kBAAkB,GAAGI;gBAC9B;YACF,OAAO;gBACL,wEAAwE;gBACxE,kEAAkE;gBAClE,8EAA8E;gBAC9E,MAAME,gBAAgBZ,KAAK,CAACE,eAAe;gBAC3C,IAAI,OAAOU,kBAAkB,UAAU;oBACrC,KAAK,MAAMC,YAAYV,OAAOC,IAAI,CAACQ,eAAgB;wBACjD,IAAItB,eAAewB,QAAQ,CAACD,WAAuB;4BACjD,MAAME,cAAc,MAAMvB,iBAAiB;gCACzCE;gCACAC;gCACAC;gCACAoB,cAAcd;gCACdL;gCACAgB;gCACAf;gCACAC;gCACAkB,KAAKL,aAAa,CAACC,SAAS;4BAC9B;4BAEA,IAAIE,aAAaG,SAASH,aAAaI,MAAM;gCAC3ClB,SAAS;oCACP,GAAGA,MAAM;oCACT,CAACc,YAAYI,IAAI,CAAC,EAAEJ,YAAYG,KAAK;gCACvC;4BACF,OAAO,IAAI,OAAOH,aAAaG,UAAU,UAAU;gCACjDjB,SAASZ,4BAA4BY,QAAQc,YAAYG,KAAK,EAAE;oCAC9D,6BAA6B;oCAC7BE,OAAO;gCACT;4BACF;wBACF;oBACF;gBACF;YACF;QACF;IACF;IAEA,OAAOnB;AACT"}
1
+ {"version":3,"sources":["../../src/queries/parseParams.ts"],"sourcesContent":["import type { FilterQuery } from 'mongoose'\nimport type { FlattenedField, Operator, Payload, Where } from 'payload'\n\nimport { deepMergeWithCombinedArrays } from 'payload'\nimport { validOperators } from 'payload/shared'\n\nimport { buildAndOrConditions } from './buildAndOrConditions.js'\nimport { buildSearchParam } from './buildSearchParams.js'\n\nexport async function parseParams({\n collectionSlug,\n fields,\n globalSlug,\n locale,\n payload,\n where,\n}: {\n collectionSlug?: string\n fields: FlattenedField[]\n globalSlug?: string\n locale: string\n payload: Payload\n where: Where\n}): Promise<Record<string, unknown>> {\n let result = {} as FilterQuery<any>\n\n if (typeof where === 'object') {\n // We need to determine if the whereKey is an AND, OR, or a schema path\n for (const relationOrPath of Object.keys(where)) {\n const condition = where[relationOrPath]\n let conditionOperator: '$and' | '$or'\n if (relationOrPath.toLowerCase() === 'and') {\n conditionOperator = '$and'\n } else if (relationOrPath.toLowerCase() === 'or') {\n conditionOperator = '$or'\n }\n if (Array.isArray(condition)) {\n const builtConditions = await buildAndOrConditions({\n collectionSlug,\n fields,\n globalSlug,\n locale,\n payload,\n where: condition,\n })\n if (builtConditions.length > 0) {\n result[conditionOperator] = builtConditions\n }\n } else {\n // It's a path - and there can be multiple comparisons on a single path.\n // For example - title like 'test' and title not equal to 'tester'\n // So we need to loop on keys again here to handle each operator independently\n const pathOperators = where[relationOrPath]\n if (typeof pathOperators === 'object') {\n for (const operator of Object.keys(pathOperators)) {\n if (validOperators.includes(operator as Operator)) {\n const searchParam = await buildSearchParam({\n collectionSlug,\n fields,\n globalSlug,\n incomingPath: relationOrPath,\n locale,\n operator,\n payload,\n val: pathOperators[operator],\n })\n\n if (searchParam?.value && searchParam?.path) {\n result = {\n ...result,\n [searchParam.path]: searchParam.value,\n }\n } else if (typeof searchParam?.value === 'object') {\n result = deepMergeWithCombinedArrays(result, searchParam.value, {\n // dont clone Types.ObjectIDs\n clone: false,\n })\n }\n }\n }\n }\n }\n }\n }\n\n return result\n}\n"],"names":["deepMergeWithCombinedArrays","validOperators","buildAndOrConditions","buildSearchParam","parseParams","collectionSlug","fields","globalSlug","locale","payload","where","result","relationOrPath","Object","keys","condition","conditionOperator","toLowerCase","Array","isArray","builtConditions","length","pathOperators","operator","includes","searchParam","incomingPath","val","value","path","clone"],"mappings":"AAGA,SAASA,2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,IAAI,CAAC,EAAEJ,YAAYG,KAAK;gCACvC;4BACF,OAAO,IAAI,OAAOH,aAAaG,UAAU,UAAU;gCACjDjB,SAASX,4BAA4BW,QAAQc,YAAYG,KAAK,EAAE;oCAC9D,6BAA6B;oCAC7BE,OAAO;gCACT;4BACF;wBACF;oBACF;gBACF;YACF;QACF;IACF;IAEA,OAAOnB;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"sanitizeQueryValue.d.ts","sourceRoot":"","sources":["../../src/queries/sanitizeQueryValue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,cAAc,EAAE,OAAO,EAAqB,MAAM,SAAS,CAAA;AAKzF,KAAK,sBAAsB,GAAG;IAC5B,KAAK,EAAE,cAAc,CAAA;IACrB,WAAW,EAAE,OAAO,CAAA;IACpB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,EAAE,GAAG,CAAA;CACT,CAAA;AA6ED,eAAO,MAAM,kBAAkB,kEAQ5B,sBAAsB,KAAG;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,GAAG,CAAC,EAAE,OAAO,CAAA;CAoVd,CAAA"}
1
+ {"version":3,"file":"sanitizeQueryValue.d.ts","sourceRoot":"","sources":["../../src/queries/sanitizeQueryValue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,cAAc,EAAE,OAAO,EAAqB,MAAM,SAAS,CAAA;AAKzF,KAAK,sBAAsB,GAAG;IAC5B,KAAK,EAAE,cAAc,CAAA;IACrB,WAAW,EAAE,OAAO,CAAA;IACpB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,EAAE,GAAG,CAAA;CACT,CAAA;AA6DD,eAAO,MAAM,kBAAkB,kEAQ5B,sBAAsB,KAAG;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,GAAG,CAAC,EAAE,OAAO,CAAA;CA4Ud,CAAA"}
@@ -51,19 +51,6 @@ const buildExistsQuery = (formattedValue, path, treatEmptyString = true)=>{
51
51
  };
52
52
  }
53
53
  };
54
- const sanitizeCoordinates = (coordinates)=>{
55
- const result = [];
56
- for (const value of coordinates){
57
- if (typeof value === 'string') {
58
- result.push(Number(value));
59
- } else if (Array.isArray(value)) {
60
- result.push(sanitizeCoordinates(value));
61
- } else {
62
- result.push(value);
63
- }
64
- }
65
- return result;
66
- };
67
54
  // returns nestedField Field object from blocks.nestedField path because getLocalizedPaths splits them only for relationships
68
55
  const getFieldFromSegments = ({ field, segments })=>{
69
56
  if ('blocks' in field) {
@@ -362,9 +349,6 @@ export const sanitizeQueryValue = ({ field, hasCustomID, locale, operator, path,
362
349
  }
363
350
  }
364
351
  if (operator === 'within' || operator === 'intersects') {
365
- if (formattedValue && typeof formattedValue === 'object' && Array.isArray(formattedValue.coordinates)) {
366
- formattedValue.coordinates = sanitizeCoordinates(formattedValue.coordinates);
367
- }
368
352
  formattedValue = {
369
353
  $geometry: formattedValue
370
354
  };