@payloadcms/db-postgres 3.0.0-canary.ce278e4 → 3.0.0-canary.d6053cd

Sign up to get free protection for your applications and to get access to all the features.
Files changed (160) hide show
  1. package/dist/connect.js.map +1 -1
  2. package/dist/count.js +1 -1
  3. package/dist/count.js.map +1 -1
  4. package/dist/create.js +1 -1
  5. package/dist/create.js.map +1 -1
  6. package/dist/createGlobal.d.ts +2 -2
  7. package/dist/createGlobal.d.ts.map +1 -1
  8. package/dist/createGlobal.js +1 -1
  9. package/dist/createGlobal.js.map +1 -1
  10. package/dist/createGlobalVersion.d.ts +2 -3
  11. package/dist/createGlobalVersion.d.ts.map +1 -1
  12. package/dist/createGlobalVersion.js +1 -1
  13. package/dist/createGlobalVersion.js.map +1 -1
  14. package/dist/createMigration.js.map +1 -1
  15. package/dist/createVersion.d.ts.map +1 -1
  16. package/dist/createVersion.js +1 -1
  17. package/dist/createVersion.js.map +1 -1
  18. package/dist/deleteMany.d.ts.map +1 -1
  19. package/dist/deleteMany.js +1 -1
  20. package/dist/deleteMany.js.map +1 -1
  21. package/dist/deleteOne.d.ts.map +1 -1
  22. package/dist/deleteOne.js +1 -1
  23. package/dist/deleteOne.js.map +1 -1
  24. package/dist/deleteVersions.d.ts.map +1 -1
  25. package/dist/deleteVersions.js +1 -1
  26. package/dist/deleteVersions.js.map +1 -1
  27. package/dist/destroy.js.map +1 -1
  28. package/dist/exports/migration-utils.js.map +1 -1
  29. package/dist/find/buildFindManyArgs.d.ts.map +1 -1
  30. package/dist/find/buildFindManyArgs.js.map +1 -1
  31. package/dist/find/chainMethods.d.ts.map +1 -1
  32. package/dist/find/chainMethods.js.map +1 -1
  33. package/dist/find/findMany.d.ts.map +1 -1
  34. package/dist/find/findMany.js +1 -1
  35. package/dist/find/findMany.js.map +1 -1
  36. package/dist/find/traverseFields.js.map +1 -1
  37. package/dist/find.d.ts.map +1 -1
  38. package/dist/find.js.map +1 -1
  39. package/dist/findGlobal.js.map +1 -1
  40. package/dist/findGlobalVersions.d.ts.map +1 -1
  41. package/dist/findGlobalVersions.js.map +1 -1
  42. package/dist/findOne.d.ts.map +1 -1
  43. package/dist/findOne.js.map +1 -1
  44. package/dist/findVersions.d.ts.map +1 -1
  45. package/dist/findVersions.js.map +1 -1
  46. package/dist/index.js.map +1 -1
  47. package/dist/init.js.map +1 -1
  48. package/dist/migrate.js.map +1 -1
  49. package/dist/migrateDown.js.map +1 -1
  50. package/dist/migrateFresh.js.map +1 -1
  51. package/dist/migrateRefresh.js.map +1 -1
  52. package/dist/migrateReset.js.map +1 -1
  53. package/dist/migrateStatus.js.map +1 -1
  54. package/dist/predefinedMigrations/relationships-v2-v3.js.map +1 -1
  55. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts +2 -2
  56. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts.map +1 -1
  57. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.js +0 -1
  58. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.js.map +1 -1
  59. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js.map +1 -1
  60. package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.d.ts.map +1 -1
  61. package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.js.map +1 -1
  62. package/dist/predefinedMigrations/v2-v3/index.d.ts +2 -2
  63. package/dist/predefinedMigrations/v2-v3/index.d.ts.map +1 -1
  64. package/dist/predefinedMigrations/v2-v3/index.js +1 -1
  65. package/dist/predefinedMigrations/v2-v3/index.js.map +1 -1
  66. package/dist/predefinedMigrations/v2-v3/migrateRelationships.d.ts +2 -2
  67. package/dist/predefinedMigrations/v2-v3/migrateRelationships.d.ts.map +1 -1
  68. package/dist/predefinedMigrations/v2-v3/migrateRelationships.js.map +1 -1
  69. package/dist/predefinedMigrations/v2-v3/traverseFields.js.map +1 -1
  70. package/dist/predefinedMigrations/v2-v3/types.js.map +1 -1
  71. package/dist/queries/buildAndOrConditions.js.map +1 -1
  72. package/dist/queries/buildQuery.d.ts.map +1 -1
  73. package/dist/queries/buildQuery.js.map +1 -1
  74. package/dist/queries/createJSONQuery/convertPathToJSONTraversal.js.map +1 -1
  75. package/dist/queries/createJSONQuery/formatJSONPathSegment.js.map +1 -1
  76. package/dist/queries/createJSONQuery/index.js.map +1 -1
  77. package/dist/queries/getTableColumnFromPath.js.map +1 -1
  78. package/dist/queries/operatorMap.js.map +1 -1
  79. package/dist/queries/parseParams.js.map +1 -1
  80. package/dist/queries/sanitizeQueryValue.js.map +1 -1
  81. package/dist/queries/selectDistinct.d.ts.map +1 -1
  82. package/dist/queries/selectDistinct.js.map +1 -1
  83. package/dist/queryDrafts.d.ts +1 -1
  84. package/dist/queryDrafts.d.ts.map +1 -1
  85. package/dist/queryDrafts.js.map +1 -1
  86. package/dist/schema/build.js.map +1 -1
  87. package/dist/schema/createIndex.js.map +1 -1
  88. package/dist/schema/createTableName.js.map +1 -1
  89. package/dist/schema/idToUUID.js.map +1 -1
  90. package/dist/schema/parentIDColumnMap.js.map +1 -1
  91. package/dist/schema/setColumnID.js.map +1 -1
  92. package/dist/schema/traverseFields.js.map +1 -1
  93. package/dist/schema/validateExistingBlockIsIdentical.js.map +1 -1
  94. package/dist/transactions/beginTransaction.js.map +1 -1
  95. package/dist/transactions/commitTransaction.d.ts.map +1 -1
  96. package/dist/transactions/commitTransaction.js +1 -0
  97. package/dist/transactions/commitTransaction.js.map +1 -1
  98. package/dist/transactions/rollbackTransaction.d.ts.map +1 -1
  99. package/dist/transactions/rollbackTransaction.js +5 -4
  100. package/dist/transactions/rollbackTransaction.js.map +1 -1
  101. package/dist/transform/read/hasManyNumber.js.map +1 -1
  102. package/dist/transform/read/hasManyText.js.map +1 -1
  103. package/dist/transform/read/index.d.ts +2 -3
  104. package/dist/transform/read/index.d.ts.map +1 -1
  105. package/dist/transform/read/index.js.map +1 -1
  106. package/dist/transform/read/relationship.js.map +1 -1
  107. package/dist/transform/read/traverseFields.d.ts.map +1 -1
  108. package/dist/transform/read/traverseFields.js.map +1 -1
  109. package/dist/transform/write/array.js.map +1 -1
  110. package/dist/transform/write/blocks.js.map +1 -1
  111. package/dist/transform/write/index.js.map +1 -1
  112. package/dist/transform/write/numbers.js.map +1 -1
  113. package/dist/transform/write/relationships.js.map +1 -1
  114. package/dist/transform/write/selects.js.map +1 -1
  115. package/dist/transform/write/texts.js.map +1 -1
  116. package/dist/transform/write/traverseFields.js.map +1 -1
  117. package/dist/transform/write/types.js.map +1 -1
  118. package/dist/types.d.ts +3 -3
  119. package/dist/types.d.ts.map +1 -1
  120. package/dist/types.js.map +1 -1
  121. package/dist/update.js +1 -1
  122. package/dist/update.js.map +1 -1
  123. package/dist/updateGlobal.d.ts +2 -2
  124. package/dist/updateGlobal.d.ts.map +1 -1
  125. package/dist/updateGlobal.js +1 -1
  126. package/dist/updateGlobal.js.map +1 -1
  127. package/dist/updateGlobalVersion.d.ts.map +1 -1
  128. package/dist/updateGlobalVersion.js +1 -1
  129. package/dist/updateGlobalVersion.js.map +1 -1
  130. package/dist/updateVersion.d.ts.map +1 -1
  131. package/dist/updateVersion.js +1 -1
  132. package/dist/updateVersion.js.map +1 -1
  133. package/dist/upsertRow/deleteExistingArrayRows.d.ts.map +1 -1
  134. package/dist/upsertRow/deleteExistingArrayRows.js.map +1 -1
  135. package/dist/upsertRow/deleteExistingRowsByPath.d.ts.map +1 -1
  136. package/dist/upsertRow/deleteExistingRowsByPath.js.map +1 -1
  137. package/dist/upsertRow/index.d.ts +1 -1
  138. package/dist/upsertRow/index.d.ts.map +1 -1
  139. package/dist/upsertRow/index.js +8 -6
  140. package/dist/upsertRow/index.js.map +1 -1
  141. package/dist/upsertRow/insertArrays.d.ts.map +1 -1
  142. package/dist/upsertRow/insertArrays.js.map +1 -1
  143. package/dist/upsertRow/types.d.ts +2 -2
  144. package/dist/upsertRow/types.d.ts.map +1 -1
  145. package/dist/upsertRow/types.js.map +1 -1
  146. package/dist/utilities/appendPrefixToKeys.d.ts.map +1 -1
  147. package/dist/utilities/appendPrefixToKeys.js.map +1 -1
  148. package/dist/utilities/createBlocksMap.d.ts.map +1 -1
  149. package/dist/utilities/createBlocksMap.js.map +1 -1
  150. package/dist/utilities/createMigrationTable.d.ts.map +1 -1
  151. package/dist/utilities/createMigrationTable.js.map +1 -1
  152. package/dist/utilities/createRelationshipMap.d.ts.map +1 -1
  153. package/dist/utilities/createRelationshipMap.js.map +1 -1
  154. package/dist/utilities/hasLocalesTable.js.map +1 -1
  155. package/dist/utilities/isArrayOfRows.js.map +1 -1
  156. package/dist/utilities/migrationTableExists.d.ts.map +1 -1
  157. package/dist/utilities/migrationTableExists.js.map +1 -1
  158. package/dist/utilities/parseError.js.map +1 -1
  159. package/dist/utilities/pushDevSchema.js.map +1 -1
  160. package/package.json +11 -11
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/predefinedMigrations/v2-v3/index.ts"],"sourcesContent":["import type { DrizzleSnapshotJSON } from 'drizzle-kit/payload'\nimport type { Payload, PayloadRequestWithData } from 'payload'\n\nimport { sql } from 'drizzle-orm'\nimport fs from 'fs'\nimport { createRequire } from 'module'\nimport { buildVersionCollectionFields, buildVersionGlobalFields } from 'payload'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from '../../types.js'\nimport type { PathsToQuery } from './types.js'\n\nimport { groupUpSQLStatements } from './groupUpSQLStatements.js'\nimport { migrateRelationships } from './migrateRelationships.js'\nimport { traverseFields } from './traverseFields.js'\n\nconst require = createRequire(import.meta.url)\n\ntype Args = {\n debug?: boolean\n payload: Payload\n req?: Partial<PayloadRequestWithData>\n}\n\n/**\n * Moves upload and relationship columns from the join table and into the tables while moving data\n * This is done in the following order:\n * ADD COLUMNs\n * -- manipulate data to move relationships to new columns\n * ADD CONSTRAINTs\n * NOT NULLs\n * DROP TABLEs\n * DROP CONSTRAINTs\n * DROP COLUMNs\n * @param debug\n * @param payload\n * @param req\n */\nexport const migratePostgresV2toV3 = async ({ debug, payload, req }: Args) => {\n const adapter = payload.db as PostgresAdapter\n const db = adapter.sessions[req.transactionID]?.db\n const dir = payload.db.migrationDir\n\n // get the drizzle migrateUpSQL from drizzle using the last schema\n const { generateDrizzleJson, generateMigration } = require('drizzle-kit/payload')\n const drizzleJsonAfter = generateDrizzleJson(adapter.schema)\n\n // Get the previous migration snapshot\n const previousSnapshot = fs\n .readdirSync(dir)\n .filter((file) => file.endsWith('.json') && !file.endsWith('relationships_v2_v3.json'))\n .sort()\n .reverse()?.[0]\n\n if (!previousSnapshot) {\n throw new Error(\n `No previous migration schema file found! A prior migration from v2 is required to migrate to v3.`,\n )\n }\n\n const drizzleJsonBefore = JSON.parse(\n fs.readFileSync(`${dir}/${previousSnapshot}`, 'utf8'),\n ) as DrizzleSnapshotJSON\n\n const generatedSQL = await generateMigration(drizzleJsonBefore, drizzleJsonAfter)\n\n if (!generatedSQL.length) {\n payload.logger.info(`No schema changes needed.`)\n process.exit(0)\n }\n\n const sqlUpStatements = groupUpSQLStatements(generatedSQL)\n\n const addColumnsStatement = sqlUpStatements.addColumn.join('\\n')\n\n if (debug) {\n payload.logger.info('CREATING NEW RELATIONSHIP COLUMNS')\n payload.logger.info(addColumnsStatement)\n }\n\n await db.execute(sql.raw(addColumnsStatement))\n\n for (const collection of payload.config.collections) {\n const tableName = adapter.tableNameMap.get(toSnakeCase(collection.slug))\n const pathsToQuery: PathsToQuery = new Set()\n\n traverseFields({\n adapter,\n collectionSlug: collection.slug,\n columnPrefix: '',\n db,\n disableNotNull: false,\n fields: collection.fields,\n isVersions: false,\n newTableName: tableName,\n parentTableName: tableName,\n path: '',\n pathsToQuery,\n payload,\n rootTableName: tableName,\n })\n\n await migrateRelationships({\n adapter,\n collectionSlug: collection.slug,\n db,\n debug,\n fields: collection.fields,\n isVersions: false,\n pathsToQuery,\n payload,\n req,\n tableName,\n })\n\n if (collection.versions) {\n const versionsTableName = adapter.tableNameMap.get(\n `_${toSnakeCase(collection.slug)}${adapter.versionsSuffix}`,\n )\n const versionFields = buildVersionCollectionFields(collection)\n const versionPathsToQuery: PathsToQuery = new Set()\n\n traverseFields({\n adapter,\n collectionSlug: collection.slug,\n columnPrefix: '',\n db,\n disableNotNull: true,\n fields: versionFields,\n isVersions: true,\n newTableName: versionsTableName,\n parentTableName: versionsTableName,\n path: '',\n pathsToQuery: versionPathsToQuery,\n payload,\n rootTableName: versionsTableName,\n })\n\n await migrateRelationships({\n adapter,\n collectionSlug: collection.slug,\n db,\n debug,\n fields: versionFields,\n isVersions: true,\n pathsToQuery: versionPathsToQuery,\n payload,\n req,\n tableName: versionsTableName,\n })\n }\n }\n\n for (const global of payload.config.globals) {\n const tableName = adapter.tableNameMap.get(toSnakeCase(global.slug))\n\n const pathsToQuery: PathsToQuery = new Set()\n\n traverseFields({\n adapter,\n columnPrefix: '',\n db,\n disableNotNull: false,\n fields: global.fields,\n globalSlug: global.slug,\n isVersions: false,\n newTableName: tableName,\n parentTableName: tableName,\n path: '',\n pathsToQuery,\n payload,\n rootTableName: tableName,\n })\n\n await migrateRelationships({\n adapter,\n db,\n debug,\n fields: global.fields,\n globalSlug: global.slug,\n isVersions: false,\n pathsToQuery,\n payload,\n req,\n tableName,\n })\n\n if (global.versions) {\n const versionsTableName = adapter.tableNameMap.get(\n `_${toSnakeCase(global.slug)}${adapter.versionsSuffix}`,\n )\n\n const versionFields = buildVersionGlobalFields(global)\n\n const versionPathsToQuery: PathsToQuery = new Set()\n\n traverseFields({\n adapter,\n columnPrefix: '',\n db,\n disableNotNull: true,\n fields: versionFields,\n globalSlug: global.slug,\n isVersions: true,\n newTableName: versionsTableName,\n parentTableName: versionsTableName,\n path: '',\n pathsToQuery: versionPathsToQuery,\n payload,\n rootTableName: versionsTableName,\n })\n\n await migrateRelationships({\n adapter,\n db,\n debug,\n fields: versionFields,\n globalSlug: global.slug,\n isVersions: true,\n pathsToQuery: versionPathsToQuery,\n payload,\n req,\n tableName: versionsTableName,\n })\n }\n }\n\n // ADD CONSTRAINT\n const addConstraintsStatement = sqlUpStatements.addConstraint.join('\\n')\n\n if (debug) {\n payload.logger.info('ADDING CONSTRAINTS')\n payload.logger.info(addConstraintsStatement)\n }\n\n await db.execute(sql.raw(addConstraintsStatement))\n\n // NOT NULL\n const notNullStatements = sqlUpStatements.notNull.join('\\n')\n\n if (debug) {\n payload.logger.info('NOT NULL CONSTRAINTS')\n payload.logger.info(notNullStatements)\n }\n\n await db.execute(sql.raw(notNullStatements))\n\n // DROP TABLE\n const dropTablesStatement = sqlUpStatements.dropTable.join('\\n')\n\n if (debug) {\n payload.logger.info('DROPPING TABLES')\n payload.logger.info(dropTablesStatement)\n }\n\n await db.execute(sql.raw(dropTablesStatement))\n\n // DROP CONSTRAINT\n const dropConstraintsStatement = sqlUpStatements.dropConstraint.join('\\n')\n\n if (debug) {\n payload.logger.info('DROPPING CONSTRAINTS')\n payload.logger.info(dropConstraintsStatement)\n }\n\n await db.execute(sql.raw(dropConstraintsStatement))\n\n // DROP COLUMN\n const dropColumnsStatement = sqlUpStatements.dropColumn.join('\\n')\n\n if (debug) {\n payload.logger.info('DROPPING COLUMNS')\n payload.logger.info(dropColumnsStatement)\n }\n\n await db.execute(sql.raw(dropColumnsStatement))\n}\n"],"names":["sql","fs","createRequire","buildVersionCollectionFields","buildVersionGlobalFields","toSnakeCase","groupUpSQLStatements","migrateRelationships","traverseFields","require","url","migratePostgresV2toV3","debug","payload","req","adapter","db","sessions","transactionID","dir","migrationDir","generateDrizzleJson","generateMigration","drizzleJsonAfter","schema","previousSnapshot","readdirSync","filter","file","endsWith","sort","reverse","Error","drizzleJsonBefore","JSON","parse","readFileSync","generatedSQL","length","logger","info","process","exit","sqlUpStatements","addColumnsStatement","addColumn","join","execute","raw","collection","config","collections","tableName","tableNameMap","get","slug","pathsToQuery","Set","collectionSlug","columnPrefix","disableNotNull","fields","isVersions","newTableName","parentTableName","path","rootTableName","versions","versionsTableName","versionsSuffix","versionFields","versionPathsToQuery","global","globals","globalSlug","addConstraintsStatement","addConstraint","notNullStatements","notNull","dropTablesStatement","dropTable","dropConstraintsStatement","drop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AO;QACTC,QAAQ0B,MAAM,CAACC,IAAI,CAAC;QACpB3B,QAAQ0B,MAAM,CAACC,IAAI,CAACyC;IACtB;IAEA,MAAMjE,GAAG+B,OAAO,CAAC/C,IAAIgD,GAAG,CAACiC;IAEzB,cAAc;IACd,MAAME,uBAAuBxC,gBAAgByC,UAAU,CAACtC,IAAI,CAAC;IAE7D,IAAIlC,OAAO;QACTC,QAAQ0B,MAAM,CAACC,IAAI,CAAC;QACpB3B,QAAQ0B,MAAM,CAACC,IAAI,CAAC2C;IACtB;IAEA,MAAMnE,GAAG+B,OAAO,CAAC/C,IAAIgD,GAAG,CAACmC;AAC3B,EAAC"}
1
+ {"version":3,"sources":["../../../src/predefinedMigrations/v2-v3/index.ts"],"sourcesContent":["import type { DrizzleSnapshotJSON } from 'drizzle-kit/payload'\nimport type { Payload, PayloadRequest } from 'payload'\n\nimport { sql } from 'drizzle-orm'\nimport fs from 'fs'\nimport { createRequire } from 'module'\nimport { buildVersionCollectionFields, buildVersionGlobalFields } from 'payload'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { PostgresAdapter } from '../../types.js'\nimport type { PathsToQuery } from './types.js'\n\nimport { groupUpSQLStatements } from './groupUpSQLStatements.js'\nimport { migrateRelationships } from './migrateRelationships.js'\nimport { traverseFields } from './traverseFields.js'\n\nconst require = createRequire(import.meta.url)\n\ntype Args = {\n debug?: boolean\n payload: Payload\n req?: Partial<PayloadRequest>\n}\n\n/**\n * Moves upload and relationship columns from the join table and into the tables while moving data\n * This is done in the following order:\n * ADD COLUMNs\n * -- manipulate data to move relationships to new columns\n * ADD CONSTRAINTs\n * NOT NULLs\n * DROP TABLEs\n * DROP CONSTRAINTs\n * DROP COLUMNs\n * @param debug\n * @param payload\n * @param req\n */\nexport const migratePostgresV2toV3 = async ({ debug, payload, req }: Args) => {\n const adapter = payload.db as PostgresAdapter\n const db = adapter.sessions[await req.transactionID]?.db\n const dir = payload.db.migrationDir\n\n // get the drizzle migrateUpSQL from drizzle using the last schema\n const { generateDrizzleJson, generateMigration } = require('drizzle-kit/payload')\n const drizzleJsonAfter = generateDrizzleJson(adapter.schema)\n\n // Get the previous migration snapshot\n const previousSnapshot = fs\n .readdirSync(dir)\n .filter((file) => file.endsWith('.json') && !file.endsWith('relationships_v2_v3.json'))\n .sort()\n .reverse()?.[0]\n\n if (!previousSnapshot) {\n throw new Error(\n `No previous migration schema file found! A prior migration from v2 is required to migrate to v3.`,\n )\n }\n\n const drizzleJsonBefore = JSON.parse(\n fs.readFileSync(`${dir}/${previousSnapshot}`, 'utf8'),\n ) as DrizzleSnapshotJSON\n\n const generatedSQL = await generateMigration(drizzleJsonBefore, drizzleJsonAfter)\n\n if (!generatedSQL.length) {\n payload.logger.info(`No schema changes needed.`)\n process.exit(0)\n }\n\n const sqlUpStatements = groupUpSQLStatements(generatedSQL)\n\n const addColumnsStatement = sqlUpStatements.addColumn.join('\\n')\n\n if (debug) {\n payload.logger.info('CREATING NEW RELATIONSHIP COLUMNS')\n payload.logger.info(addColumnsStatement)\n }\n\n await db.execute(sql.raw(addColumnsStatement))\n\n for (const collection of payload.config.collections) {\n const tableName = adapter.tableNameMap.get(toSnakeCase(collection.slug))\n const pathsToQuery: PathsToQuery = new Set()\n\n traverseFields({\n adapter,\n collectionSlug: collection.slug,\n columnPrefix: '',\n db,\n disableNotNull: false,\n fields: collection.fields,\n isVersions: false,\n newTableName: tableName,\n parentTableName: tableName,\n path: '',\n pathsToQuery,\n payload,\n rootTableName: tableName,\n })\n\n await migrateRelationships({\n adapter,\n collectionSlug: collection.slug,\n db,\n debug,\n fields: collection.fields,\n isVersions: false,\n pathsToQuery,\n payload,\n req,\n tableName,\n })\n\n if (collection.versions) {\n const versionsTableName = adapter.tableNameMap.get(\n `_${toSnakeCase(collection.slug)}${adapter.versionsSuffix}`,\n )\n const versionFields = buildVersionCollectionFields(collection)\n const versionPathsToQuery: PathsToQuery = new Set()\n\n traverseFields({\n adapter,\n collectionSlug: collection.slug,\n columnPrefix: '',\n db,\n disableNotNull: true,\n fields: versionFields,\n isVersions: true,\n newTableName: versionsTableName,\n parentTableName: versionsTableName,\n path: '',\n pathsToQuery: versionPathsToQuery,\n payload,\n rootTableName: versionsTableName,\n })\n\n await migrateRelationships({\n adapter,\n collectionSlug: collection.slug,\n db,\n debug,\n fields: versionFields,\n isVersions: true,\n pathsToQuery: versionPathsToQuery,\n payload,\n req,\n tableName: versionsTableName,\n })\n }\n }\n\n for (const global of payload.config.globals) {\n const tableName = adapter.tableNameMap.get(toSnakeCase(global.slug))\n\n const pathsToQuery: PathsToQuery = new Set()\n\n traverseFields({\n adapter,\n columnPrefix: '',\n db,\n disableNotNull: false,\n fields: global.fields,\n globalSlug: global.slug,\n isVersions: false,\n newTableName: tableName,\n parentTableName: tableName,\n path: '',\n pathsToQuery,\n payload,\n rootTableName: tableName,\n })\n\n await migrateRelationships({\n adapter,\n db,\n debug,\n fields: global.fields,\n globalSlug: global.slug,\n isVersions: false,\n pathsToQuery,\n payload,\n req,\n tableName,\n })\n\n if (global.versions) {\n const versionsTableName = adapter.tableNameMap.get(\n `_${toSnakeCase(global.slug)}${adapter.versionsSuffix}`,\n )\n\n const versionFields = buildVersionGlobalFields(global)\n\n const versionPathsToQuery: PathsToQuery = new Set()\n\n traverseFields({\n adapter,\n columnPrefix: '',\n db,\n disableNotNull: true,\n fields: versionFields,\n globalSlug: global.slug,\n isVersions: true,\n newTableName: versionsTableName,\n parentTableName: versionsTableName,\n path: '',\n pathsToQuery: versionPathsToQuery,\n payload,\n rootTableName: versionsTableName,\n })\n\n await migrateRelationships({\n adapter,\n db,\n debug,\n fields: versionFields,\n globalSlug: global.slug,\n isVersions: true,\n pathsToQuery: versionPathsToQuery,\n payload,\n req,\n tableName: versionsTableName,\n })\n }\n }\n\n // ADD CONSTRAINT\n const addConstraintsStatement = sqlUpStatements.addConstraint.join('\\n')\n\n if (debug) {\n payload.logger.info('ADDING CONSTRAINTS')\n payload.logger.info(addConstraintsStatement)\n }\n\n await db.execute(sql.raw(addConstraintsStatement))\n\n // NOT NULL\n const notNullStatements = sqlUpStatements.notNull.join('\\n')\n\n if (debug) {\n payload.logger.info('NOT NULL CONSTRAINTS')\n payload.logger.info(notNullStatements)\n }\n\n await db.execute(sql.raw(notNullStatements))\n\n // DROP TABLE\n const dropTablesStatement = sqlUpStatements.dropTable.join('\\n')\n\n if (debug) {\n payload.logger.info('DROPPING TABLES')\n payload.logger.info(dropTablesStatement)\n }\n\n await db.execute(sql.raw(dropTablesStatement))\n\n // DROP CONSTRAINT\n const dropConstraintsStatement = sqlUpStatements.dropConstraint.join('\\n')\n\n if (debug) {\n payload.logger.info('DROPPING CONSTRAINTS')\n payload.logger.info(dropConstraintsStatement)\n }\n\n await db.execute(sql.raw(dropConstraintsStatement))\n\n // DROP COLUMN\n const dropColumnsStatement = sqlUpStatements.dropColumn.join('\\n')\n\n if (debug) {\n payload.logger.info('DROPPING COLUMNS')\n payload.logger.info(dropColumnsStatement)\n }\n\n await db.execute(sql.raw(dropColumnsStatement))\n}\n"],"names":["sql","fs","createRequire","buildVersionCollectionFields","buildVersionGlobalFields","toSnakeCase","groupUpSQLStatements","migrateRelationships","traverseFields","require","url","migratePostgresV2toV3","debug","payload","req","adapter","db","sessions","transactionID","dir","migrationDir","generateDrizzleJson","generateMigration","drizzleJsonAfter","schema","previousSnapshot","readdirSync","filter","file","endsWith","sort","reverse","Error","drizzleJsonBefore","JSON","parse","readFileSync","generatedSQL","length","logger","info","process","exit","sqlUpStatements","addColumnsStatement","addColumn","join","execute","raw","collection","config","collections","tableName","tableNameMap","get","slug","pathsToQuery","Set","collectionSlug","columnPrefix","disableNotNull","fields","isVersions","newTableName","parentTableName","path","rootTableName","versions","versionsTableName","versionsSuffix","versionFields","versionPathsToQuery","global","globals","globalSlug","addConstraintsStatement","addConstraint","notNullStatements","notNull","dropTablesStatement","dropTable","dropConstraintsStatement","dropConstraint","dropColumnsStatement","dropColumn"],"mappings":"AAGA,SAASA,GAAG,QAAQ,cAAa;AACjC,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2C;IACtB;IAEA,MAAMnE,GAAG+B,OAAO,CAAC/C,IAAIgD,GAAG,CAACmC;AAC3B,EAAC"}
@@ -1,4 +1,4 @@
1
- import type { Field, Payload, PayloadRequestWithData } from 'payload';
1
+ import type { Field, Payload, PayloadRequest } from 'payload';
2
2
  import type { DrizzleTransaction, PostgresAdapter } from '../../types.js';
3
3
  import type { PathsToQuery } from './types.js';
4
4
  type Args = {
@@ -11,7 +11,7 @@ type Args = {
11
11
  isVersions: boolean;
12
12
  pathsToQuery: PathsToQuery;
13
13
  payload: Payload;
14
- req?: Partial<PayloadRequestWithData>;
14
+ req?: Partial<PayloadRequest>;
15
15
  tableName: string;
16
16
  };
17
17
  export declare const migrateRelationships: ({ adapter, collectionSlug, db, debug, fields, globalSlug, isVersions, pathsToQuery, payload, req, tableName, }: Args) => Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"migrateRelationships.d.ts","sourceRoot":"","sources":["../../../src/predefinedMigrations/v2-v3/migrateRelationships.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAA;AAIrE,OAAO,KAAK,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AACzE,OAAO,KAAK,EAAgB,YAAY,EAAE,MAAM,YAAY,CAAA;AAI5D,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,eAAe,CAAA;IACxB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,EAAE,EAAE,kBAAkB,CAAA;IACtB,KAAK,EAAE,OAAO,CAAA;IACd,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,UAAU,EAAE,OAAO,CAAA;IACnB,YAAY,EAAE,YAAY,CAAA;IAC1B,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,CAAC,EAAE,OAAO,CAAC,sBAAsB,CAAC,CAAA;IACrC,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,eAAO,MAAM,oBAAoB,mHAY9B,IAAI,kBAkEN,CAAA"}
1
+ {"version":3,"file":"migrateRelationships.d.ts","sourceRoot":"","sources":["../../../src/predefinedMigrations/v2-v3/migrateRelationships.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAI7D,OAAO,KAAK,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AACzE,OAAO,KAAK,EAAgB,YAAY,EAAE,MAAM,YAAY,CAAA;AAI5D,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,eAAe,CAAA;IACxB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,EAAE,EAAE,kBAAkB,CAAA;IACtB,KAAK,EAAE,OAAO,CAAA;IACd,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,UAAU,EAAE,OAAO,CAAA;IACnB,YAAY,EAAE,YAAY,CAAA;IAC1B,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAA;IAC7B,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,eAAO,MAAM,oBAAoB,mHAY9B,IAAI,kBAkEN,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/predefinedMigrations/v2-v3/migrateRelationships.ts"],"sourcesContent":["import type { Field, Payload, PayloadRequestWithData } from 'payload'\n\nimport { sql } from 'drizzle-orm'\n\nimport type { DrizzleTransaction, PostgresAdapter } from '../../types.js'\nimport type { DocsToResave, PathsToQuery } from './types.js'\n\nimport { fetchAndResave } from './fetchAndResave/index.js'\n\ntype Args = {\n adapter: PostgresAdapter\n collectionSlug?: string\n db: DrizzleTransaction\n debug: boolean\n fields: Field[]\n globalSlug?: string\n isVersions: boolean\n pathsToQuery: PathsToQuery\n payload: Payload\n req?: Partial<PayloadRequestWithData>\n tableName: string\n}\n\nexport const migrateRelationships = async ({\n adapter,\n collectionSlug,\n db,\n debug,\n fields,\n globalSlug,\n isVersions,\n pathsToQuery,\n payload,\n req,\n tableName,\n}: Args) => {\n if (pathsToQuery.size === 0) return\n\n let offset = 0\n\n let paginationResult\n\n const where = Array.from(pathsToQuery).reduce((statement, path, i) => {\n return (statement += `\n\"${tableName}${adapter.relationshipsSuffix}\".\"path\" LIKE '${path}'${pathsToQuery.size !== i + 1 ? ' OR' : ''}\n`)\n }, '')\n\n while (typeof paginationResult === 'undefined' || paginationResult.rows.length > 0) {\n const paginationStatement = `SELECT DISTINCT parent_id FROM ${tableName}${adapter.relationshipsSuffix} WHERE\n ${where} ORDER BY parent_id LIMIT 500 OFFSET ${offset * 500};\n `\n\n paginationResult = await adapter.drizzle.execute(sql.raw(`${paginationStatement}`))\n\n if (paginationResult.rows.length === 0) return\n\n offset += 1\n\n const statement = `SELECT * FROM ${tableName}${adapter.relationshipsSuffix} WHERE\n (${where}) AND parent_id IN (${paginationResult.rows.map((row) => row.parent_id).join(', ')});\n`\n if (debug) {\n payload.logger.info('FINDING ROWS TO MIGRATE')\n payload.logger.info(statement)\n }\n\n const result = await adapter.drizzle.execute(sql.raw(`${statement}`))\n\n const docsToResave: DocsToResave = {}\n\n result.rows.forEach((row) => {\n const parentID = row.parent_id\n\n if (typeof parentID === 'string' || typeof parentID === 'number') {\n if (!docsToResave[parentID]) docsToResave[parentID] = []\n docsToResave[parentID].push(row)\n }\n })\n\n await fetchAndResave({\n adapter,\n collectionSlug,\n db,\n debug,\n docsToResave,\n fields,\n globalSlug,\n isVersions,\n payload,\n req: req as unknown as PayloadRequestWithData,\n tableName,\n })\n }\n\n const deleteStatement = `DELETE FROM ${tableName}${adapter.relationshipsSuffix} WHERE ${where}`\n if (debug) {\n payload.logger.info('DELETING ROWS')\n payload.logger.info(deleteStatement)\n }\n await db.execute(sql.raw(`${deleteStatement}`))\n}\n"],"names":["sql","fetchAndResave","migrateRelationships","adapter","collectionSlug","db","debug","fields","globalSlug","isVersions","pathsToQuery","payload","req","tableName","size","offset","paginationResult","where","Array","from","reduce","statement","path","i","relationshipsSuffix","rows","length","paginationStatement","drizzle","execute","raw","map","row","parent_id","join","logger","info","result","docsToResave","forEach","parentID","push","deleteStatement"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,SAASA,GAAG,QAAQ,cAAa;AAKjC,SAASC,cAAc,QAAQ,4BAA2B;AAgB1D,OAAO,MAAMC,uBAAuB,OAAO,EACzCC,OAAO,EACPC,cAAc,EACdC,EAAE,EACFC,KAAK,EACLC,MAAM,EACNC,UAAU,EACVC,UAAU,EACVC,YAAY,EACZC,OAAO,EACPC,GAAG,EACHC,SAAS,EACJ;IACL,IAAIH,aAAaI,IAAI,KAAK,GAAG;IAE7B,IAAIC,SAAS;IAEb,IAAIC;IAEJ,MAAMC,QAAQC,MAAMC,IAAI,CAACT,cAAcU,MAAM,CAAC,CAACC,WAAWC,MAAMC;QAC9D,OAAQF,aAAa,CAAC;CACzB,EAAER,UAAU,EAAEV,QAAQqB,mBAAmB,CAAC,eAAe,EAAEF,KAAK,CAAC,EAAEZ,aAAaI,IAAI,KAAKS,IAAI,IAAI,QAAQ,GAAG;AAC7G,CAAC;IACC,GAAG;IAEH,MAAO,OAAOP,qBAAqB,eAAeA,iBAAiBS,IAAI,CAACC,MAAM,GAAG,EAAG;QAClF,MAAMC,sBAAsB,CAAC,+BAA+B,EAAEd,UAAU,EAAEV,QAAQqB,mBAAmB,CAAC;IACtG,EAAEP,MAAM,qCAAqC,EAAEF,SAAS,IAAI;EAC9D,CAAC;QAECC,mBAAmB,MAAMb,QAAQyB,OAAO,CAACC,OAAO,CAAC7B,IAAI8B,GAAG,CAAC,CAAC,EAAEH,oBAAoB,CAAC;QAEjF,IAAIX,iBAAiBS,IAAI,CAACC,MAAM,KAAK,GAAG;QAExCX,UAAU;QAEV,MAAMM,YAAY,CAAC,cAAc,EAAER,UAAU,EAAEV,QAAQqB,mBAAmB,CAAC;KAC1E,EAAEP,MAAM,oBAAoB,EAAED,iBAAiBS,IAAI,CAACM,GAAG,CAAC,CAACC,MAAQA,IAAIC,SAAS,EAAEC,IAAI,CAAC,MAAM;AAChG,CAAC;QACG,IAAI5B,OAAO;YACTK,QAAQwB,MAAM,CAACC,IAAI,CAAC;YACpBzB,QAAQwB,MAAM,CAACC,IAAI,CAACf;QACtB;QAEA,MAAMgB,SAAS,MAAMlC,QAAQyB,OAAO,CAACC,OAAO,CAAC7B,IAAI8B,GAAG,CAAC,CAAC,EAAET,UAAU,CAAC;QAEnE,MAAMiB,eAA6B,CAAC;QAEpCD,OAAOZ,IAAI,CAACc,OAAO,CAAC,CAACP;YACnB,MAAMQ,WAAWR,IAAIC,SAAS;YAE9B,IAAI,OAAOO,aAAa,YAAY,OAAOA,aAAa,UAAU;gBAChE,IAAI,CAACF,YAAY,CAACE,SAAS,EAAEF,YAAY,CAACE,SAAS,GAAG,EAAE;gBACxDF,YAAY,CAACE,SAAS,CAACC,IAAI,CAACT;YAC9B;QACF;QAEA,MAAM/B,eAAe;YACnBE;YACAC;YACAC;YACAC;YACAgC;YACA/B;YACAC;YACAC;YACAE;YACAC,KAAKA;YACLC;QACF;IACF;IAEA,MAAM6B,kBAAkB,CAAC,YAAY,EAAE7B,UAAU,EAAEV,QAAQqB,mBAAmB,CAAC,OAAO,EAAEP,MAAM,CAAC;IAC/F,IAAIX,OAAO;QACTK,QAAQwB,MAAM,CAACC,IAAI,CAAC;QACpBzB,QAAQwB,MAAM,CAACC,IAAI,CAACM;IACtB;IACA,MAAMrC,GAAGwB,OAAO,CAAC7B,IAAI8B,GAAG,CAAC,CAAC,EAAEY,gBAAgB,CAAC;AAC/C,EAAC"}
1
+ {"version":3,"sources":["../../../src/predefinedMigrations/v2-v3/migrateRelationships.ts"],"sourcesContent":["import type { Field, Payload, PayloadRequest } from 'payload'\n\nimport { sql } from 'drizzle-orm'\n\nimport type { DrizzleTransaction, PostgresAdapter } from '../../types.js'\nimport type { DocsToResave, PathsToQuery } from './types.js'\n\nimport { fetchAndResave } from './fetchAndResave/index.js'\n\ntype Args = {\n adapter: PostgresAdapter\n collectionSlug?: string\n db: DrizzleTransaction\n debug: boolean\n fields: Field[]\n globalSlug?: string\n isVersions: boolean\n pathsToQuery: PathsToQuery\n payload: Payload\n req?: Partial<PayloadRequest>\n tableName: string\n}\n\nexport const migrateRelationships = async ({\n adapter,\n collectionSlug,\n db,\n debug,\n fields,\n globalSlug,\n isVersions,\n pathsToQuery,\n payload,\n req,\n tableName,\n}: Args) => {\n if (pathsToQuery.size === 0) return\n\n let offset = 0\n\n let paginationResult\n\n const where = Array.from(pathsToQuery).reduce((statement, path, i) => {\n return (statement += `\n\"${tableName}${adapter.relationshipsSuffix}\".\"path\" LIKE '${path}'${pathsToQuery.size !== i + 1 ? ' OR' : ''}\n`)\n }, '')\n\n while (typeof paginationResult === 'undefined' || paginationResult.rows.length > 0) {\n const paginationStatement = `SELECT DISTINCT parent_id FROM ${tableName}${adapter.relationshipsSuffix} WHERE\n ${where} ORDER BY parent_id LIMIT 500 OFFSET ${offset * 500};\n `\n\n paginationResult = await adapter.drizzle.execute(sql.raw(`${paginationStatement}`))\n\n if (paginationResult.rows.length === 0) return\n\n offset += 1\n\n const statement = `SELECT * FROM ${tableName}${adapter.relationshipsSuffix} WHERE\n (${where}) AND parent_id IN (${paginationResult.rows.map((row) => row.parent_id).join(', ')});\n`\n if (debug) {\n payload.logger.info('FINDING ROWS TO MIGRATE')\n payload.logger.info(statement)\n }\n\n const result = await adapter.drizzle.execute(sql.raw(`${statement}`))\n\n const docsToResave: DocsToResave = {}\n\n result.rows.forEach((row) => {\n const parentID = row.parent_id\n\n if (typeof parentID === 'string' || typeof parentID === 'number') {\n if (!docsToResave[parentID]) docsToResave[parentID] = []\n docsToResave[parentID].push(row)\n }\n })\n\n await fetchAndResave({\n adapter,\n collectionSlug,\n db,\n debug,\n docsToResave,\n fields,\n globalSlug,\n isVersions,\n payload,\n req: req as unknown as PayloadRequest,\n tableName,\n })\n }\n\n const deleteStatement = `DELETE FROM ${tableName}${adapter.relationshipsSuffix} WHERE ${where}`\n if (debug) {\n payload.logger.info('DELETING ROWS')\n payload.logger.info(deleteStatement)\n }\n await db.execute(sql.raw(`${deleteStatement}`))\n}\n"],"names":["sql","fetchAndResave","migrateRelationships","adapter","collectionSlug","db","debug","fields","globalSlug","isVersions","pathsToQuery","payload","req","tableName","size","offset","paginationResult","where","Array","from","reduce","statement","path","i","relationshipsSuffix","rows","length","paginationStatement","drizzle","execute","raw","map","row","parent_id","join","logger","info","result","docsToResave","forEach","parentID","push","deleteStatement"],"mappings":"AAEA,SAASA,GAAG,QAAQ,cAAa;AAKjC,SAASC,cAAc,QAAQ,4BAA2B;AAgB1D,OAAO,MAAMC,uBAAuB,OAAO,EACzCC,OAAO,EACPC,cAAc,EACdC,EAAE,EACFC,KAAK,EACLC,MAAM,EACNC,UAAU,EACVC,UAAU,EACVC,YAAY,EACZC,OAAO,EACPC,GAAG,EACHC,SAAS,EACJ;IACL,IAAIH,aAAaI,IAAI,KAAK,GAAG;IAE7B,IAAIC,SAAS;IAEb,IAAIC;IAEJ,MAAMC,QAAQC,MAAMC,IAAI,CAACT,cAAcU,MAAM,CAAC,CAACC,WAAWC,MAAMC;QAC9D,OAAQF,aAAa,CAAC;CACzB,EAAER,UAAU,EAAEV,QAAQqB,mBAAmB,CAAC,eAAe,EAAEF,KAAK,CAAC,EAAEZ,aAAaI,IAAI,KAAKS,IAAI,IAAI,QAAQ,GAAG;AAC7G,CAAC;IACC,GAAG;IAEH,MAAO,OAAOP,qBAAqB,eAAeA,iBAAiBS,IAAI,CAACC,MAAM,GAAG,EAAG;QAClF,MAAMC,sBAAsB,CAAC,+BAA+B,EAAEd,UAAU,EAAEV,QAAQqB,mBAAmB,CAAC;IACtG,EAAEP,MAAM,qCAAqC,EAAEF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,MAAMrC,GAAGwB,OAAO,CAAC7B,IAAI8B,GAAG,CAAC,CAAC,EAAEY,gBAAgB,CAAC;AAC/C,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/predefinedMigrations/v2-v3/traverseFields.ts"],"sourcesContent":["import type { Field, Payload } from 'payload'\n\nimport { tabHasName } from 'payload/shared'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleTransaction, PostgresAdapter } from '../../types.js'\nimport type { PathsToQuery } from './types.js'\n\ntype Args = {\n adapter: PostgresAdapter\n collectionSlug?: string\n columnPrefix: string\n db: DrizzleTransaction\n disableNotNull: boolean\n fields: Field[]\n globalSlug?: string\n isVersions: boolean\n newTableName: string\n parentTableName: string\n path: string\n pathsToQuery: PathsToQuery\n payload: Payload\n rootTableName: string\n}\n\nexport const traverseFields = (args: Args) => {\n args.fields.forEach((field) => {\n switch (field.type) {\n case 'group': {\n let newTableName = `${args.newTableName}_${toSnakeCase(field.name)}`\n\n if (field.localized && args.payload.config.localization) {\n newTableName += args.adapter.localesSuffix\n }\n\n return traverseFields({\n ...args,\n columnPrefix: `${args.columnPrefix}${toSnakeCase(field.name)}_`,\n fields: field.fields,\n newTableName,\n path: `${args.path ? `${args.path}.` : ''}${field.name}`,\n })\n }\n\n case 'row':\n case 'collapsible': {\n return traverseFields({\n ...args,\n fields: field.fields,\n })\n }\n\n case 'array': {\n const newTableName = args.adapter.tableNameMap.get(\n `${args.newTableName}_${toSnakeCase(field.name)}`,\n )\n\n return traverseFields({\n ...args,\n columnPrefix: '',\n fields: field.fields,\n newTableName,\n parentTableName: newTableName,\n path: `${args.path ? `${args.path}.` : ''}${field.name}.%`,\n })\n }\n\n case 'blocks': {\n return field.blocks.forEach((block) => {\n const newTableName = args.adapter.tableNameMap.get(\n `${args.rootTableName}_blocks_${toSnakeCase(block.slug)}`,\n )\n\n traverseFields({\n ...args,\n columnPrefix: '',\n fields: block.fields,\n newTableName,\n parentTableName: newTableName,\n path: `${args.path ? `${args.path}.` : ''}${field.name}.%`,\n })\n })\n }\n\n case 'tabs': {\n return field.tabs.forEach((tab) => {\n if (tabHasName(tab)) {\n args.columnPrefix = `${args.columnPrefix}_${toSnakeCase(tab.name)}_`\n args.path = `${args.path ? `${args.path}.` : ''}${tab.name}`\n args.newTableName = `${args.newTableName}_${toSnakeCase(tab.name)}`\n\n if (tab.localized && args.payload.config.localization) {\n args.newTableName += args.adapter.localesSuffix\n }\n }\n\n traverseFields({\n ...args,\n fields: tab.fields,\n })\n })\n }\n\n case 'relationship':\n case 'upload': {\n if (typeof field.relationTo === 'string') {\n if (field.type === 'upload' || !field.hasMany) {\n args.pathsToQuery.add(`${args.path ? `${args.path}.` : ''}${field.name}`)\n }\n }\n\n return null\n }\n }\n })\n}\n"],"names":["tabHasName","toSnakeCase","traverseFields","args","fields","forEach","field","type","newTableName","name","localized","payload","config","localization","adapter","localesSuffix","columnPrefix","path","tableNameMap","get","parentTableName","blocks","block","rootTableName","slug","tabs","tab","relationTo","hasMany","pathsToQuery","add"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,SAASA,UAAU,QAAQ,iBAAgB;AAC3C,OAAOC,iBAAiB,gBAAe;AAsBvC,OAAO,MAAMC,iBAAiB,CAACC;IAC7BA,KAAKC,MAAM,CAACC,OAAO,CAAC,CAACC;QACnB,OAAQA,MAAMC,IAAI;YAChB,KAAK;gBAAS;oBACZ,IAAIC,eAAe,CAAC,EAAEL,KAAKK,YAAY,CAAC,CAAC,EAAEP,YAAYK,MAAMG,IAAI,EAAE,CAAC;oBAEpE,IAAIH,MAAMI,SAAS,IAAIP,KAAKQ,OAAO,CAACC,MAAM,CAACC,YAAY,EAAE;wBACvDL,gBAAgBL,KAAKW,OAAO,CAACC,aAAa;oBAC5C;oBAEA,OAAOb,eAAe;wBACpB,GAAGC,IAAI;wBACPa,cAAc,CA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GAAG,EAAEX,MAAMG,IAAI,CAAC,EAAE,CAAC;wBAC5D;oBACF;gBACF;YAEA,KAAK;gBAAQ;oBACX,OAAOH,MAAMmB,IAAI,CAACpB,OAAO,CAAC,CAACqB;wBACzB,IAAI1B,WAAW0B,MAAM;4BACnBvB,KAAKa,YAAY,GAAG,CAAC,EAAEb,KAAKa,YAAY,CAAC,CAAC,EAAEf,YAAYyB,IAAIjB,IAAI,EAAE,CAAC,CAAC;4BACpEN,KAAKc,IAAI,GAAG,CAAC,EAAEd,KAAKc,IAAI,GAAG,CAAC,EAAEd,KAAKc,IAAI,CAAC,CAAC,CAAC,GAAG,GAAG,EAAES,IAAIjB,IAAI,CAAC,CAAC;4BAC5DN,KAAKK,YAAY,GAAG,CAAC,EAAEL,KAAKK,YAAY,CAAC,CAAC,EAAEP,YAAYyB,IAAIjB,IAAI,EAAE,CAAC;4BAEnE,IAAIiB,IAAIhB,SAAS,IAAIP,KAAKQ,OAAO,CAACC,MAAM,CAACC,YAAY,EAAE;gCACrDV,KAAKK,YAAY,IAAIL,KAAKW,OAAO,CAACC,aAAa;4BACjD;wBACF;wBAEAb,eAAe;4BACb,GAAGC,IAAI;4BACPC,QAAQsB,IAAItB,MAAM;wBACpB;oBACF;gBACF;YAEA,KAAK;YACL,KAAK;gBAAU;oBACb,IAAI,OAAOE,MAAMqB,UAAU,KAAK,UAAU;wBACxC,IAAIrB,MAAMC,IAAI,KAAK,YAAY,CAACD,MAAMsB,OAAO,EAAE;4BAC7CzB,KAAK0B,YAAY,CAACC,GAAG,CAAC,CAAC,EAAE3B,KAAKc,IAAI,GAAG,CAAC,EAAEd,KAAKc,IAAI,CAAC,CAAC,CAAC,GAAG,GAAG,EAAEX,MAAMG,IAAI,CAAC,CAAC;wBAC1E;oBACF;oBAEA,OAAO;gBACT;QACF;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../src/predefinedMigrations/v2-v3/traverseFields.ts"],"sourcesContent":["import type { Field, Payload } from 'payload'\n\nimport { tabHasName } from 'payload/shared'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleTransaction, PostgresAdapter } from '../../types.js'\nimport type { PathsToQuery } from './types.js'\n\ntype Args = {\n adapter: PostgresAdapter\n collectionSlug?: string\n columnPrefix: string\n db: DrizzleTransaction\n disableNotNull: boolean\n fields: Field[]\n globalSlug?: string\n isVersions: boolean\n newTableName: string\n parentTableName: string\n path: string\n pathsToQuery: PathsToQuery\n payload: Payload\n rootTableName: string\n}\n\nexport const traverseFields = (args: Args) => {\n args.fields.forEach((field) => {\n switch (field.type) {\n case 'group': {\n let newTableName = `${args.newTableName}_${toSnakeCase(field.name)}`\n\n if (field.localized && args.payload.config.localization) {\n newTableName += args.adapter.localesSuffix\n }\n\n return traverseFields({\n ...args,\n columnPrefix: `${args.columnPrefix}${toSnakeCase(field.name)}_`,\n fields: field.fields,\n newTableName,\n path: `${args.path ? `${args.path}.` : ''}${field.name}`,\n })\n }\n\n case 'row':\n case 'collapsible': {\n return traverseFields({\n ...args,\n fields: field.fields,\n })\n }\n\n case 'array': {\n const newTableName = args.adapter.tableNameMap.get(\n `${args.newTableName}_${toSnakeCase(field.name)}`,\n )\n\n return traverseFields({\n ...args,\n columnPrefix: '',\n fields: field.fields,\n newTableName,\n parentTableName: newTableName,\n path: `${args.path ? `${args.path}.` : ''}${field.name}.%`,\n })\n }\n\n case 'blocks': {\n return field.blocks.forEach((block) => {\n const newTableName = args.adapter.tableNameMap.get(\n `${args.rootTableName}_blocks_${toSnakeCase(block.slug)}`,\n )\n\n traverseFields({\n ...args,\n columnPrefix: '',\n fields: block.fields,\n newTableName,\n parentTableName: newTableName,\n path: `${args.path ? `${args.path}.` : ''}${field.name}.%`,\n })\n })\n }\n\n case 'tabs': {\n return field.tabs.forEach((tab) => {\n if (tabHasName(tab)) {\n args.columnPrefix = `${args.columnPrefix}_${toSnakeCase(tab.name)}_`\n args.path = `${args.path ? `${args.path}.` : ''}${tab.name}`\n args.newTableName = `${args.newTableName}_${toSnakeCase(tab.name)}`\n\n if (tab.localized && args.payload.config.localization) {\n args.newTableName += args.adapter.localesSuffix\n }\n }\n\n traverseFields({\n ...args,\n fields: tab.fields,\n })\n })\n }\n\n case 'relationship':\n case 'upload': {\n if (typeof field.relationTo === 'string') {\n if (field.type === 'upload' || !field.hasMany) {\n args.pathsToQuery.add(`${args.path ? `${args.path}.` : ''}${field.name}`)\n }\n }\n\n return null\n }\n }\n })\n}\n"],"names":["tabHasName","toSnakeCase","traverseFields","args","fields","forEach","field","type","newTableName","name","localized","payload","config","localization","adapter","localesSuffix","columnPrefix","path","tableNameMap","get","parentTableName","blocks","block","rootTableName","slug","tabs","tab","relationTo","hasMany","pathsToQuery","add"],"mappings":"AAEA,SAASA,UAAU,QAAQ,iBAAgB;AAC3C,OAAOC,iBAAiB,gBAAe;AAsBvC,OAAO,MAAMC,iBAAiB,CAACC;IAC7BA,KAAKC,MAAM,CAACC,OAAO,CAAC,CAACC;QACnB,OAAQA,MAAMC,IAAI;YAChB,KAAK;gBAAS;oBACZ,IAAIC,eAAe,CAAC,EAAEL,KAAKK,YAAY,CAAC,CAAC,EAAEP,YAAYK,MAAMG,IAAI,EAAE,CAAC;oBAEpE,IAAIH,MAAMI,SAAS,IAAIP,KAAKQ,OAAO,CAACC,MAAM,CAACC,YAAY,EAAE;wBACvDL,gBAAgBL,KAAKW,OAAO,CAACC,aAAa;oBAC5C;oBAEA,OAAOb,eAAe;wBACpB,GAAGC,IAAI;wBACPa,cAAc,CAAC,EAAEb,KAAKa,YAAY,CAAC,EAAEf,YAAYK,MAAMG,IAAI,EAAE,CAAC,CAAC;wBAC/DL,QAAQE,MAAMF,MAAM;wBACpBI;wBACAS,MAAM,CAAC,EAAEd,KAAKc,IAAI,GAAG,CAAC,EAAEd,KAAKc,IAAI,CAAC,CAAC,CAAC,GAAG,GAAG,EAAEX,MAAMG,IAAI,CAAC,CAAC;oBAC1D;gBACF;YAEA,KAAK;YACL,KAAK;gBAAe;oBAClB,OAAOP,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AAG,CAAC,EAAEd,KAAKc,IAAI,GAAG,CAAC,EAAEd,KAAKc,IAAI,CAAC,CAAC,CAAC,GAAG,GAAG,EAAES,IAAIjB,IAAI,CAAC,CAAC;4BAC5DN,KAAKK,YAAY,GAAG,CAAC,EAAEL,KAAKK,YAAY,CAAC,CAAC,EAAEP,YAAYyB,IAAIjB,IAAI,EAAE,CAAC;4BAEnE,IAAIiB,IAAIhB,SAAS,IAAIP,KAAKQ,OAAO,CAACC,MAAM,CAACC,YAAY,EAAE;gCACrDV,KAAKK,YAAY,IAAIL,KAAKW,OAAO,CAACC,aAAa;4BACjD;wBACF;wBAEAb,eAAe;4BACb,GAAGC,IAAI;4BACPC,QAAQsB,IAAItB,MAAM;wBACpB;oBACF;gBACF;YAEA,KAAK;YACL,KAAK;gBAAU;oBACb,IAAI,OAAOE,MAAMqB,UAAU,KAAK,UAAU;wBACxC,IAAIrB,MAAMC,IAAI,KAAK,YAAY,CAACD,MAAMsB,OAAO,EAAE;4BAC7CzB,KAAK0B,YAAY,CAACC,GAAG,CAAC,CAAC,EAAE3B,KAAKc,IAAI,GAAG,CAAC,EAAEd,KAAKc,IAAI,CAAC,CAAC,CAAC,GAAG,GAAG,EAAEX,MAAMG,IAAI,CAAC,CAAC;wBAC1E;oBACF;oBAEA,OAAO;gBACT;QACF;IACF;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/predefinedMigrations/v2-v3/types.ts"],"sourcesContent":["/**\n * Set of all paths which should be moved\n * This will be built up into one WHERE query\n */\nexport type PathsToQuery = Set<string>\n\nexport type DocsToResave = {\n [id: number | string]: Record<string, unknown>[]\n}\n"],"names":[],"rangeMappings":";;;","mappings":"AAAA;;;CAGC,GAGD,WAEC"}
1
+ {"version":3,"sources":["../../../src/predefinedMigrations/v2-v3/types.ts"],"sourcesContent":["/**\n * Set of all paths which should be moved\n * This will be built up into one WHERE query\n */\nexport type PathsToQuery = Set<string>\n\nexport type DocsToResave = {\n [id: number | string]: Record<string, unknown>[]\n}\n"],"names":[],"mappings":"AAAA;;;CAGC,GAGD,WAEC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/queries/buildAndOrConditions.ts"],"sourcesContent":["import type { SQL } from 'drizzle-orm'\nimport type { Field, Where } from 'payload'\n\nimport type { GenericColumn, PostgresAdapter } from '../types.js'\nimport type { BuildQueryJoinAliases } from './buildQuery.js'\n\nimport { parseParams } from './parseParams.js'\n\nexport async function buildAndOrConditions({\n adapter,\n fields,\n joins,\n locale,\n selectFields,\n tableName,\n where,\n}: {\n adapter: PostgresAdapter\n collectionSlug?: string\n fields: Field[]\n globalSlug?: string\n joins: BuildQueryJoinAliases\n locale?: string\n selectFields: Record<string, GenericColumn>\n tableName: string\n where: Where[]\n}): Promise<SQL[]> {\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 // eslint-disable-next-line no-restricted-syntax\n for (const condition of where) {\n // If the operation is properly formatted as an object\n if (typeof condition === 'object') {\n // eslint-disable-next-line no-await-in-loop\n const result = await parseParams({\n adapter,\n fields,\n joins,\n locale,\n selectFields,\n tableName,\n where: condition,\n })\n if (result && Object.keys(result).length > 0) {\n completedConditions.push(result)\n }\n }\n }\n return completedConditions\n}\n"],"names":["parseParams","buildAndOrConditions","adapter","fields","joins","locale","selectFields","tableName","where","completedConditions","condition","result","Object","keys","length","push"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAMA,SAASA,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,eAAeC,qBAAqB,EACzCC,OAAO,EACPC,MAAM,EACNC,KAAK,EACLC,MAAM,EACNC,YAAY,EACZC,SAAS,EACTC,KAAK,EAWN;IACC,MAAMC,sBAAsB,EAAE;IAC9B,6EAA6E;IAC7E,6CAA6C;IAC7C,gDAAgD;IAChD,KAAK,MAAMC,aAAaF,MAAO;QAC7B,sDAAsD;QACtD,IAAI,OAAOE,cAAc,UAAU;YACjC,4CAA4C;YAC5C,MAAMC,SAAS,MAAMX,YAAY;gBAC/BE;gBACAC;gBACAC;gBACAC;gBACAC;gBACAC;gBACAC,OAAOE;YACT;YACA,IAAIC,UAAUC,OAAOC,IAAI,CAACF,QAAQG,MAAM,GAAG,GAAG;gBAC5CL,oBAAoBM,IAAI,CAACJ;YAC3B;QACF;IACF;IACA,OAAOF;AACT"}
1
+ {"version":3,"sources":["../../src/queries/buildAndOrConditions.ts"],"sourcesContent":["import type { SQL } from 'drizzle-orm'\nimport type { Field, Where } from 'payload'\n\nimport type { GenericColumn, PostgresAdapter } from '../types.js'\nimport type { BuildQueryJoinAliases } from './buildQuery.js'\n\nimport { parseParams } from './parseParams.js'\n\nexport async function buildAndOrConditions({\n adapter,\n fields,\n joins,\n locale,\n selectFields,\n tableName,\n where,\n}: {\n adapter: PostgresAdapter\n collectionSlug?: string\n fields: Field[]\n globalSlug?: string\n joins: BuildQueryJoinAliases\n locale?: string\n selectFields: Record<string, GenericColumn>\n tableName: string\n where: Where[]\n}): Promise<SQL[]> {\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 // eslint-disable-next-line no-restricted-syntax\n for (const condition of where) {\n // If the operation is properly formatted as an object\n if (typeof condition === 'object') {\n // eslint-disable-next-line no-await-in-loop\n const result = await parseParams({\n adapter,\n fields,\n joins,\n locale,\n selectFields,\n tableName,\n where: condition,\n })\n if (result && Object.keys(result).length > 0) {\n completedConditions.push(result)\n }\n }\n }\n return completedConditions\n}\n"],"names":["parseParams","buildAndOrConditions","adapter","fields","joins","locale","selectFields","tableName","where","completedConditions","condition","result","Object","keys","length","push"],"mappings":"AAMA,SAASA,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,eAAeC,qBAAqB,EACzCC,OAAO,EACPC,MAAM,EACNC,KAAK,EACLC,MAAM,EACNC,YAAY,EACZC,SAAS,EACTC,KAAK,EAWN;IACC,MAAMC,sBAAsB,EAAE;IAC9B,6EAA6E;IAC7E,6CAA6C;IAC7C,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IAC5B,OAAO,EAAE;QACP,MAAM,EAAE,aAAa,CAAA;QACrB,KAAK,EAAE,OAAO,GAAG,GAAG,OAAO,IAAI,CAAA;KAChC,CAAA;IACD,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;IAC3C,KAAK,EAAE,GAAG,CAAA;CACX,CAAA;AACD,QAAA,MAAM,UAAU,wEAOb,cAAc,KAAG,OAAO,CAAC,MAAM,CA2EjC,CAAA;AAED,eAAe,UAAU,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/queries/buildQuery.ts"],"sourcesContent":["import type { SQL } from 'drizzle-orm'\nimport type { PgTableWithColumns } from 'drizzle-orm/pg-core'\nimport type { Field, Where } from 'payload'\n\nimport { asc, desc } from 'drizzle-orm'\n\nimport type { GenericColumn, GenericTable, PostgresAdapter } from '../types.js'\n\nimport { getTableColumnFromPath } from './getTableColumnFromPath.js'\nimport { parseParams } from './parseParams.js'\n\nexport type BuildQueryJoins = Record<string, SQL>\n\nexport type BuildQueryJoinAliases = {\n condition: SQL\n table: GenericTable | PgTableWithColumns<any>\n}[]\n\ntype BuildQueryArgs = {\n adapter: PostgresAdapter\n fields: Field[]\n locale?: string\n sort?: string\n tableName: string\n where: Where\n}\n\ntype Result = {\n joins: BuildQueryJoinAliases\n orderBy: {\n column: GenericColumn\n order: typeof asc | typeof desc\n }\n selectFields: Record<string, GenericColumn>\n where: SQL\n}\nconst buildQuery = async function buildQuery({\n adapter,\n fields,\n locale,\n sort,\n tableName,\n where: incomingWhere,\n}: BuildQueryArgs): Promise<Result> {\n const selectFields: Record<string, GenericColumn> = {\n id: adapter.tables[tableName].id,\n }\n const joins: BuildQueryJoinAliases = []\n\n const orderBy: Result['orderBy'] = {\n column: null,\n order: null,\n }\n\n if (sort) {\n let sortPath\n\n if (sort[0] === '-') {\n sortPath = sort.substring(1)\n orderBy.order = desc\n } else {\n sortPath = sort\n orderBy.order = asc\n }\n\n try {\n const { columnName: sortTableColumnName, table: sortTable } = getTableColumnFromPath({\n adapter,\n collectionPath: sortPath,\n fields,\n joins,\n locale,\n pathSegments: sortPath.replace(/__/g, '.').split('.'),\n selectFields,\n tableName,\n value: sortPath,\n })\n orderBy.column = sortTable?.[sortTableColumnName]\n } catch (err) {\n // continue\n }\n }\n\n if (!orderBy?.column) {\n orderBy.order = desc\n const createdAt = adapter.tables[tableName]?.createdAt\n\n if (createdAt) {\n orderBy.column = createdAt\n } else {\n orderBy.column = adapter.tables[tableName].id\n }\n }\n\n if (orderBy.column) {\n selectFields.sort = orderBy.column\n }\n\n let where: SQL\n\n if (incomingWhere && Object.keys(incomingWhere).length > 0) {\n where = await parseParams({\n adapter,\n fields,\n joins,\n locale,\n selectFields,\n tableName,\n where: incomingWhere,\n })\n }\n\n return {\n joins,\n orderBy,\n selectFields,\n where,\n }\n}\n\nexport default buildQuery\n"],"names":["asc","desc","getTableColumnFromPath","parseParams","buildQuery","adapter","fields","locale","sort","tableName","where","incomingWhere","selectFields","id","tables","joins","orderBy","column","order","sortPath","substring","columnName","sortTableColumnName","table","sortTable","collectionPath","pathSegments","replace","split","value","err","createdAt","Object","keys","length"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAIA,SAASA,GAAG,EAAEC,IAAI,QAAQ,cAAa;AAIvC,SAASC,sBAAsB,QAAQ,8BAA6B;AACpE,SAASC,WAAW,QAAQ,mBAAkB;AA2B9C,MAAMC,aAAa,eAAeA,WAAW,EAC3CC,OAAO,EACPC,MAAM,EACNC,MAAM,EACNC,IAAI,EACJC,SAAS,EACTC,OAAOC,aAAa,EACL;IACf,MAAMC,eAA8C;QAClDC,IAAIR,QAAQS,MAAM,CAACL,UAAU,CAACI,EAAE;IAClC;IACA,MAAME,QAA+B,EAAE;IAEvC,MAAMC,UAA6B;QACjCC,QAAQ;QACRC,OAAO;IACT;IAEA,IAAIV,MAAM;QACR,IAAIW;QAEJ,IAAIX,IAAI,CAAC,EAAE,KAAK,KAAK;YACnBW,WAAWX,KAAKY,SAAS,CAAC;YAC1BJ,QAAQE,KAAK,GAAGjB;QAClB,OAAO;YACLkB,WAAWX;YACXQ,QAAQE,KAAK,GAAGlB;QAClB;QAEA,IAAI;YACF,MAAM,EAAEqB,YAAYC,mBAAmB,EAAEC,OAAOC,SAAS,EAAE,GAAGtB,uBAAuB;gBACnFG;gBACAoB,gBAAgBN;gBAChBb;gBACAS;gBACAR;gBACAmB,cAAcP,SAASQ,OAAO,CAAC,OAAO,KAAKC,KAAK,CAAC;gBACjDhB;gBACAH;gBACAoB,OAAOV;YACT;YACAH,QAAQC,MAAM,GAAGO,WAAW,CAACF,oBAAoB;QACnD,EAAE,OAAOQ,KAAK;QACZ,WAAW;QACb;IACF;IAEA,IAAI,CAACd,SAASC,QAAQ;QACpBD,QAAQE,KAAK,GAAGjB;QAChB,MAAM8B,YAAY1B,QAAQS,MAAM,CAACL,UAAU,EAAEsB;QAE7C,IAAIA,WAAW;YACbf,QAAQC,MAAM,GAAGc;QACnB,OAAO;YACLf,QAAQC,MAAM,GAAGZ,QAAQS,MAAM,CAACL,UAAU,CAACI,EAAE;QAC/C;IACF;IAEA,IAAIG,QAAQC,MAAM,EAAE;QAClBL,aAAaJ,IAAI,GAAGQ,QAAQC,MAAM;IACpC;IAEA,IAAIP;IAEJ,IAAIC,iBAAiBqB,OAAOC,IAAI,CAACtB,eAAeuB,MAAM,GAAG,GAAG;QAC1DxB,QAAQ,MAAMP,YAAY;YACxBE;YACAC;YACAS;YACAR;YACAK;YACAH;YACAC,OAAOC;QACT;IACF;IAEA,OAAO;QACLI;QACAC;QACAJ;QACAF;IACF;AACF;AAEA,eAAeN,WAAU"}
1
+ {"version":3,"sources":["../../src/queries/buildQuery.ts"],"sourcesContent":["import type { SQL } from 'drizzle-orm'\nimport type { PgTableWithColumns } from 'drizzle-orm/pg-core'\nimport type { Field, Where } from 'payload'\n\nimport { asc, desc } from 'drizzle-orm'\n\nimport type { GenericColumn, GenericTable, PostgresAdapter } from '../types.js'\n\nimport { getTableColumnFromPath } from './getTableColumnFromPath.js'\nimport { parseParams } from './parseParams.js'\n\nexport type BuildQueryJoins = Record<string, SQL>\n\nexport type BuildQueryJoinAliases = {\n condition: SQL\n table: GenericTable | PgTableWithColumns<any>\n}[]\n\ntype BuildQueryArgs = {\n adapter: PostgresAdapter\n fields: Field[]\n locale?: string\n sort?: string\n tableName: string\n where: Where\n}\n\ntype Result = {\n joins: BuildQueryJoinAliases\n orderBy: {\n column: GenericColumn\n order: typeof asc | typeof desc\n }\n selectFields: Record<string, GenericColumn>\n where: SQL\n}\nconst buildQuery = async function buildQuery({\n adapter,\n fields,\n locale,\n sort,\n tableName,\n where: incomingWhere,\n}: BuildQueryArgs): Promise<Result> {\n const selectFields: Record<string, GenericColumn> = {\n id: adapter.tables[tableName].id,\n }\n const joins: BuildQueryJoinAliases = []\n\n const orderBy: Result['orderBy'] = {\n column: null,\n order: null,\n }\n\n if (sort) {\n let sortPath\n\n if (sort[0] === '-') {\n sortPath = sort.substring(1)\n orderBy.order = desc\n } else {\n sortPath = sort\n orderBy.order = asc\n }\n\n try {\n const { columnName: sortTableColumnName, table: sortTable } = getTableColumnFromPath({\n adapter,\n collectionPath: sortPath,\n fields,\n joins,\n locale,\n pathSegments: sortPath.replace(/__/g, '.').split('.'),\n selectFields,\n tableName,\n value: sortPath,\n })\n orderBy.column = sortTable?.[sortTableColumnName]\n } catch (err) {\n // continue\n }\n }\n\n if (!orderBy?.column) {\n orderBy.order = desc\n const createdAt = adapter.tables[tableName]?.createdAt\n\n if (createdAt) {\n orderBy.column = createdAt\n } else {\n orderBy.column = adapter.tables[tableName].id\n }\n }\n\n if (orderBy.column) {\n selectFields.sort = orderBy.column\n }\n\n let where: SQL\n\n if (incomingWhere && Object.keys(incomingWhere).length > 0) {\n where = await parseParams({\n adapter,\n fields,\n joins,\n locale,\n selectFields,\n tableName,\n where: incomingWhere,\n })\n }\n\n return {\n joins,\n orderBy,\n selectFields,\n where,\n }\n}\n\nexport default buildQuery\n"],"names":["asc","desc","getTableColumnFromPath","parseParams","buildQuery","adapter","fields","locale","sort","tableName","where","incomingWhere","selectFields","id","tables","joins","orderBy","column","order","sortPath","substring","columnName","sortTableColumnName","table","sortTable","collectionPath","pathSegments","replace","split","value","err","createdAt","Object","keys","length"],"mappings":"AAIA,SAASA,GAAG,EAAEC,IAAI,QAAQ,cAAa;AAIvC,SAASC,sBAAsB,QAAQ,8BAA6B;AACpE,SAASC,WAAW,QAAQ,mBAAkB;AA2B9C,MAAMC,aAAa,eAAeA,WAAW,EAC3CC,OAAO,EACPC,MAAM,EACNC,MAAM,EACNC,IAAI,EACJC,SAAS,EACTC,OAAOC,aAAa,EACL;IACf,MAAMC,eAA8C;QAClDC,IAAIR,QAAQS,MAAM,CAACL,UAAU,CAACI,EAAE;IAClC;IACA,MAAME,QAA+B,EAAE;IAEvC,MAAMC,UAA6B;QACjCC,QAAQ;QACRC,OAAO;IACT;IAEA,IAAIV,MAAM;QACR,IAAIW;QAEJ,IAAIX,IAAI,CAAC,EAAE,KAAK,KAAK;YACnBW,WAAWX,KAAKY,SAAS,CAAC;YAC1BJ,QAAQE,KAAK,GAAGjB;QAClB,OAAO;YACLkB,WAAWX;YACXQ,QAAQE,KAAK,GAAGlB;QAClB;QAEA,IAAI;YACF,MAAM,EAAEqB,YAAYC,mBAAmB,EAAEC,OAAOC,SAAS,EAAE,GAAGtB,uBAAuB;gBACnFG;gBACAoB,gBAAgBN;gBAChBb;gBACAS;gBACAR;gBACAmB,cAAcP,SAASQ,OAAO,CAAC,OAAO,KAAKC,KAAK,CAAC;gBACjDhB;gBACAH;gBACAoB,OAAOV;YACT;YACAH,QAAQC,MAAM,GAAGO,WAAW,CAACF,oBAAoB;QACnD,EAAE,OAAOQ,KAAK;QACZ,WAAW;QACb;IACF;IAEA,IAAI,CAACd,SAASC,QAAQ;QACpBD,QAAQE,KAAK,GAAGjB;QAChB,MAAM8B,YAAY1B,QAAQS,MAAM,CAACL,UAAU,EAAEsB;QAE7C,IAAIA,WAAW;YACbf,QAAQC,MAAM,GAAGc;QACnB,OAAO;YACLf,QAAQC,MAAM,GAAGZ,QAAQS,MAAM,CAACL,UAAU,CAACI,EAAE;QAC/C;IACF;IAEA,IAAIG,QAAQC,MAAM,EAAE;QAClBL,aAAaJ,IAAI,GAAGQ,QAAQC,MAAM;IACpC;IAEA,IAAIP;IAEJ,IAAIC,iBAAiBqB,OAAOC,IAAI,CAACtB,eAAeuB,MAAM,GAAG,GAAG;QAC1DxB,QAAQ,MAAMP,YAAY;YACxBE;YACAC;YACAS;YACAR;YACAK;YACAH;YACAC,OAAOC;QACT;IACF;IAEA,OAAO;QACLI;QACAC;QACAJ;QACAF;IACF;AACF;AAEA,eAAeN,WAAU"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/queries/createJSONQuery/convertPathToJSONTraversal.ts"],"sourcesContent":["import { formatJSONPathSegment } from './formatJSONPathSegment.js'\n\nexport const convertPathToJSONTraversal = (incomingSegments: string[]) => {\n const segments = [...incomingSegments]\n segments.shift()\n\n return segments.reduce((res, segment, i) => {\n const formattedSegment = formatJSONPathSegment(segment)\n\n if (i + 1 === segments.length) return `${res}->>${formattedSegment}`\n return `${res}->${formattedSegment}`\n }, '')\n}\n"],"names":["formatJSONPathSegment","convertPathToJSONTraversal","incomingSegments","segments","shift","reduce","res","segment","i","formattedSegment","length"],"rangeMappings":";;;;;;;;;;;","mappings":"AAAA,SAASA,qBAAqB,QAAQ,6BAA4B;AAElE,OAAO,MAAMC,6BAA6B,CAACC;IACzC,MAAMC,WAAW;WAAID;KAAiB;IACtCC,SAASC,KAAK;IAEd,OAAOD,SAASE,MAAM,CAAC,CAACC,KAAKC,SAASC;QACpC,MAAMC,mBAAmBT,sBAAsBO;QAE/C,IAAIC,IAAI,MAAML,SAASO,MAAM,EAAE,OAAO,CAAC,EAAEJ,IAAI,GAAG,EAAEG,iBAAiB,CAAC;QACpE,OAAO,CAAC,EAAEH,IAAI,EAAE,EAAEG,iBAAiB,CAAC;IACtC,GAAG;AACL,EAAC"}
1
+ {"version":3,"sources":["../../../src/queries/createJSONQuery/convertPathToJSONTraversal.ts"],"sourcesContent":["import { formatJSONPathSegment } from './formatJSONPathSegment.js'\n\nexport const convertPathToJSONTraversal = (incomingSegments: string[]) => {\n const segments = [...incomingSegments]\n segments.shift()\n\n return segments.reduce((res, segment, i) => {\n const formattedSegment = formatJSONPathSegment(segment)\n\n if (i + 1 === segments.length) return `${res}->>${formattedSegment}`\n return `${res}->${formattedSegment}`\n }, '')\n}\n"],"names":["formatJSONPathSegment","convertPathToJSONTraversal","incomingSegments","segments","shift","reduce","res","segment","i","formattedSegment","length"],"mappings":"AAAA,SAASA,qBAAqB,QAAQ,6BAA4B;AAElE,OAAO,MAAMC,6BAA6B,CAACC;IACzC,MAAMC,WAAW;WAAID;KAAiB;IACtCC,SAASC,KAAK;IAEd,OAAOD,SAASE,MAAM,CAAC,CAACC,KAAKC,SAASC;QACpC,MAAMC,mBAAmBT,sBAAsBO;QAE/C,IAAIC,IAAI,MAAML,SAASO,MAAM,EAAE,OAAO,CAAC,EAAEJ,IAAI,GAAG,EAAEG,iBAAiB,CAAC;QACpE,OAAO,CAAC,EAAEH,IAAI,EAAE,EAAEG,iBAAiB,CAAC;IACtC,GAAG;AACL,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/queries/createJSONQuery/formatJSONPathSegment.ts"],"sourcesContent":["export const formatJSONPathSegment = (segment: string) => {\n return Number.isNaN(parseInt(segment)) ? `'${segment}'` : segment\n}\n"],"names":["formatJSONPathSegment","segment","Number","isNaN","parseInt"],"rangeMappings":";;","mappings":"AAAA,OAAO,MAAMA,wBAAwB,CAACC;IACpC,OAAOC,OAAOC,KAAK,CAACC,SAASH,YAAY,CAAC,CAAC,EAAEA,QAAQ,CAAC,CAAC,GAAGA;AAC5D,EAAC"}
1
+ {"version":3,"sources":["../../../src/queries/createJSONQuery/formatJSONPathSegment.ts"],"sourcesContent":["export const formatJSONPathSegment = (segment: string) => {\n return Number.isNaN(parseInt(segment)) ? `'${segment}'` : segment\n}\n"],"names":["formatJSONPathSegment","segment","Number","isNaN","parseInt"],"mappings":"AAAA,OAAO,MAAMA,wBAAwB,CAACC;IACpC,OAAOC,OAAOC,KAAK,CAACC,SAASH,YAAY,CAAC,CAAC,EAAEA,QAAQ,CAAC,CAAC,GAAGA;AAC5D,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/queries/createJSONQuery/index.ts"],"sourcesContent":["import { convertPathToJSONTraversal } from './convertPathToJSONTraversal.js'\nimport { formatJSONPathSegment } from './formatJSONPathSegment.js'\n\nconst operatorMap = {\n contains: '~*',\n equals: '=',\n like: '~*',\n}\n\ntype FromArrayArgs = {\n isRoot?: true\n operator: string\n pathSegments: string[]\n treatAsArray?: string[]\n value: unknown\n}\n\nconst fromArray = ({ isRoot, operator, pathSegments, treatAsArray, value }: FromArrayArgs) => {\n const newPathSegments = pathSegments.slice(isRoot ? 1 : 2)\n const alias = `${pathSegments[isRoot ? 0 : 1]}_alias_${newPathSegments.length}`\n\n newPathSegments.unshift(alias)\n\n const arrayElements = isRoot\n ? pathSegments[0]\n : `${pathSegments[0]} -> ${formatJSONPathSegment(pathSegments[1])}`\n\n return `EXISTS (\n SELECT 1\n FROM jsonb_array_elements(${arrayElements}) AS ${alias}\n WHERE ${createJSONQuery({\n operator,\n pathSegments: newPathSegments,\n treatAsArray,\n value,\n })}\n )`\n}\n\ntype CreateConstraintArgs = {\n operator: string\n pathSegments: string[]\n treatAsArray?: string[]\n value: unknown\n}\n\nconst createConstraint = ({ operator, pathSegments, value }: CreateConstraintArgs): string => {\n const jsonQuery = convertPathToJSONTraversal(pathSegments)\n return `${pathSegments[0]}${jsonQuery} ${operatorMap[operator]} '${value}'`\n}\n\ntype Args = {\n operator: string\n pathSegments: string[]\n treatAsArray?: string[]\n treatRootAsArray?: boolean\n value: unknown\n}\n\nexport const createJSONQuery = ({\n operator,\n pathSegments,\n treatAsArray,\n treatRootAsArray,\n value,\n}: Args): string => {\n if (treatRootAsArray) {\n return fromArray({\n isRoot: true,\n operator,\n pathSegments,\n treatAsArray,\n value,\n })\n }\n\n if (treatAsArray.includes(pathSegments[1])) {\n return fromArray({\n operator,\n pathSegments,\n treatAsArray,\n value,\n })\n }\n\n return createConstraint({ operator, pathSegments, treatAsArray, value })\n}\n"],"names":["convertPathToJSONTraversal","formatJSONPathSegment","operatorMap","contains","equals","like","fromArray","isRoot","operator","pathSegments","treatAsArray","value","newPathSegments","slice","alias","length","unshift","arrayElements","createJSONQuery","createConstraint","jsonQuery","treatRootAsArray","includes"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,0BAA0B,QAAQ,kCAAiC;AAC5E,SAASC,qBAAqB,QAAQ,6BAA4B;AAElE,MAAMC,cAAc;IAClBC,UAAU;IACVC,QAAQ;IACRC,MAAM;AACR;AAUA,MAAMC,YAAY,CAAC,EAAEC,MAAM,EAAEC,QAAQ,EAAEC,YAAY,EAAEC,YAAY,EAAEC,KAAK,EAAiB;IACvF,MAAMC,kBAAkBH,aAAaI,KAAK,CAACN,SAAS,IAAI;IACxD,MAAMO,QAAQ,CAAC,EAAEL,YAAY,CAACF,SAAS,IAAI,EAAE,CAAC,OAAO,EAAEK,gBAAgBG,MAAM,CAAC,CAAC;IAE/EH,gBAAgBI,OAAO,CAACF;IAExB,MAAMG,gBAAgBV,SAClBE,YAAY,CAAC,EAAE,GACf,CAAC,EAAEA,YAAY,CAAC,EAAE,CAAC,IAAI,EAAER,sBAAsBQ,YAAY,CAAC,EAAE,EAAE,CAAC;IAErE,OAAO,CAAC;;8BAEoB,EAAEQ,cAAc,KAAK,EAAEH,MAAM;UACjD,EAAEI,gBAAgB;QACtBV;QACAC,cAAcG;QACdF;QACAC;IACF,GAAG;GACJ,CAAC;AACJ;AASA,MAAMQ,mBAAmB,CAAC,EAAEX,QAAQ,EAAEC,YAAY,EAAEE,KAAK,EAAwB;IAC/E,MAAMS,YAAYpB,2BAA2BS;IAC7C,OAAO,CAAC,EAAEA,YAAY,CAAC,EAAE,CAAC,EAAEW,UAAU,CAAC,EAAElB,WAAW,CAACM,SAAS,CAAC,EAAE,EAAEG,MAAM,CAAC,CAAC;AAC7E;AAUA,OAAO,MAAMO,kBAAkB,CAAC,EAC9BV,QAAQ,EACRC,YAAY,EACZC,YAAY,EACZW,gBAAgB,EAChBV,KAAK,EACA;IACL,IAAIU,kBAAkB;QACpB,OAAOf,UAAU;YACfC,QAAQ;YACRC;YACAC;YACAC;YACAC;QACF;IACF;IAEA,IAAID,aAAaY,QAAQ,CAACb,YAAY,CAAC,EAAE,GAAG;QAC1C,OAAOH,UAAU;YACfE;YACAC;YACAC;YACAC;QACF;IACF;IAEA,OAAOQ,iBAAiB;QAAEX;QAAUC;QAAcC;QAAcC;IAAM;AACxE,EAAC"}
1
+ {"version":3,"sources":["../../../src/queries/createJSONQuery/index.ts"],"sourcesContent":["import { convertPathToJSONTraversal } from './convertPathToJSONTraversal.js'\nimport { formatJSONPathSegment } from './formatJSONPathSegment.js'\n\nconst operatorMap = {\n contains: '~*',\n equals: '=',\n like: '~*',\n}\n\ntype FromArrayArgs = {\n isRoot?: true\n operator: string\n pathSegments: string[]\n treatAsArray?: string[]\n value: unknown\n}\n\nconst fromArray = ({ isRoot, operator, pathSegments, treatAsArray, value }: FromArrayArgs) => {\n const newPathSegments = pathSegments.slice(isRoot ? 1 : 2)\n const alias = `${pathSegments[isRoot ? 0 : 1]}_alias_${newPathSegments.length}`\n\n newPathSegments.unshift(alias)\n\n const arrayElements = isRoot\n ? pathSegments[0]\n : `${pathSegments[0]} -> ${formatJSONPathSegment(pathSegments[1])}`\n\n return `EXISTS (\n SELECT 1\n FROM jsonb_array_elements(${arrayElements}) AS ${alias}\n WHERE ${createJSONQuery({\n operator,\n pathSegments: newPathSegments,\n treatAsArray,\n value,\n })}\n )`\n}\n\ntype CreateConstraintArgs = {\n operator: string\n pathSegments: string[]\n treatAsArray?: string[]\n value: unknown\n}\n\nconst createConstraint = ({ operator, pathSegments, value }: CreateConstraintArgs): string => {\n const jsonQuery = convertPathToJSONTraversal(pathSegments)\n return `${pathSegments[0]}${jsonQuery} ${operatorMap[operator]} '${value}'`\n}\n\ntype Args = {\n operator: string\n pathSegments: string[]\n treatAsArray?: string[]\n treatRootAsArray?: boolean\n value: unknown\n}\n\nexport const createJSONQuery = ({\n operator,\n pathSegments,\n treatAsArray,\n treatRootAsArray,\n value,\n}: Args): string => {\n if (treatRootAsArray) {\n return fromArray({\n isRoot: true,\n operator,\n pathSegments,\n treatAsArray,\n value,\n })\n }\n\n if (treatAsArray.includes(pathSegments[1])) {\n return fromArray({\n operator,\n pathSegments,\n treatAsArray,\n value,\n })\n }\n\n return createConstraint({ operator, pathSegments, treatAsArray, value })\n}\n"],"names":["convertPathToJSONTraversal","formatJSONPathSegment","operatorMap","contains","equals","like","fromArray","isRoot","operator","pathSegments","treatAsArray","value","newPathSegments","slice","alias","length","unshift","arrayElements","createJSONQuery","createConstraint","jsonQuery","treatRootAsArray","includes"],"mappings":"AAAA,SAASA,0BAA0B,QAAQ,kCAAiC;AAC5E,SAASC,qBAAqB,QAAQ,6BAA4B;AAElE,MAAMC,cAAc;IAClBC,UAAU;IACVC,QAAQ;IACRC,MAAM;AACR;AAUA,MAAMC,YAAY,CAAC,EAAEC,MAAM,EAAEC,QAAQ,EAAEC,YAAY,EAAEC,YAAY,EAAEC,KAAK,EAAiB;IACvF,MAAMC,kBAAkBH,aAAaI,KAAK,CAACN,SAAS,IAAI;IACxD,MAAMO,QAAQ,CAAC,EAAEL,YAAY,CAACF,SAAS,IAAI,EAAE,CAAC,OAAO,EAAEK,gBAAgBG,MAAM,CAAC,CAAC;IAE/EH,gBAAgBI,OAAO,CAACF;IAExB,MAAMG,gBAAgBV,SAClBE,YAAY,CAAC,EAAE,GACf,CAAC,EAAEA,YAAY,CAAC,EAAE,CAAC,IAAI,EAAER,sBAAsBQ,YAAY,CAAC,EAAE,EAAE,CAAC;IAErE,OAAO,CAAC;;8BAEoB,EAAEQ,cAAc,KAAK,EAAEH,MAAM;UACjD,EAAEI,gBAAgB;QACtBV;QACAC,cAAcG;QACdF;QACAC;IACF,GAAG;GACJ,CAAC;AACJ;AASA,MAAMQ,mBAAmB,CAAC,EAAEX,QAAQ,EAAEC,YAAY,EAAEE,KAAK,EAAwB;IAC/E,MAAMS,YAAYpB,2BAA2BS;IAC7C,OAAO,CAAC,EAAEA,YAAY,CAAC,EAAE,CAAC,EAAEW,UAAU,CAAC,EAAElB,WAAW,CAACM,SAAS,CAAC,EAAE,EAAEG,MAAM,CAAC,CAAC;AAC7E;AAUA,OAAO,MAAMO,kBAAkB,CAAC,EAC9BV,QAAQ,EACRC,YAAY,EACZC,YAAY,EACZW,gBAAgB,EAChBV,KAAK,EACA;IACL,IAAIU,kBAAkB;QACpB,OAAOf,UAAU;YACfC,QAAQ;YACRC;YACAC;YACAC;YACAC;QACF;IACF;IAEA,IAAID,aAAaY,QAAQ,CAACb,YAAY,CAAC,EAAE,GAAG;QAC1C,OAAOH,UAAU;YACfE;YACAC;YACAC;YACAC;QACF;IACF;IAEA,OAAOQ,iBAAiB;QAAEX;QAAUC;QAAcC;QAAcC;IAAM;AACxE,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/queries/getTableColumnFromPath.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport type { SQL } from 'drizzle-orm'\nimport type { PgTableWithColumns } from 'drizzle-orm/pg-core'\nimport type { Field, FieldAffectingData, NumberField, TabAsField, TextField } from 'payload'\n\nimport { and, eq, like, sql } from 'drizzle-orm'\nimport { alias } from 'drizzle-orm/pg-core'\nimport { APIError, flattenTopLevelFields } from 'payload'\nimport { fieldAffectsData, tabHasName } from 'payload/shared'\nimport toSnakeCase from 'to-snake-case'\nimport { v4 as uuid } from 'uuid'\n\nimport type { GenericColumn, GenericTable, PostgresAdapter } from '../types.js'\nimport type { BuildQueryJoinAliases } from './buildQuery.js'\n\ntype Constraint = {\n columnName: string\n table: GenericTable | PgTableWithColumns<any>\n value: unknown\n}\n\ntype TableColumn = {\n columnName?: string\n constraints: Constraint[]\n field: FieldAffectingData\n getNotNullColumnByValue?: (val: unknown) => string\n pathSegments?: string[]\n rawColumn?: SQL\n table: GenericTable | PgTableWithColumns<any>\n}\n\ntype Args = {\n adapter: PostgresAdapter\n aliasTable?: GenericTable | PgTableWithColumns<any>\n collectionPath: string\n columnPrefix?: string\n constraintPath?: string\n constraints?: Constraint[]\n fields: (Field | TabAsField)[]\n joins: BuildQueryJoinAliases\n locale?: string\n pathSegments: string[]\n rootTableName?: string\n selectFields: Record<string, GenericColumn>\n tableName: string\n /**\n * If creating a new table name for arrays and blocks, this suffix should be appended to the table name\n */\n tableNameSuffix?: string\n /**\n * The raw value of the query before sanitization\n */\n value: unknown\n}\n/**\n * Transforms path to table and column name\n * Adds tables to `join`\n * @returns TableColumn\n */\nexport const getTableColumnFromPath = ({\n adapter,\n aliasTable,\n collectionPath,\n columnPrefix = '',\n constraintPath: incomingConstraintPath,\n constraints = [],\n fields,\n joins,\n locale: incomingLocale,\n pathSegments: incomingSegments,\n rootTableName: incomingRootTableName,\n selectFields,\n tableName,\n tableNameSuffix = '',\n value,\n}: Args): TableColumn => {\n const fieldPath = incomingSegments[0]\n let locale = incomingLocale\n const rootTableName = incomingRootTableName || tableName\n let constraintPath = incomingConstraintPath || ''\n\n const field = flattenTopLevelFields(fields as Field[]).find(\n (fieldToFind) => fieldAffectsData(fieldToFind) && fieldToFind.name === fieldPath,\n ) as Field | TabAsField\n let newTableName = tableName\n\n if (!field && fieldPath === 'id') {\n selectFields.id = adapter.tables[newTableName].id\n return {\n columnName: 'id',\n constraints,\n field: {\n name: 'id',\n type: adapter.idType === 'uuid' ? 'text' : 'number',\n } as NumberField | TextField,\n table: adapter.tables[newTableName],\n }\n }\n\n if (field) {\n const pathSegments = [...incomingSegments]\n\n // If next segment is a locale,\n // we need to take it out and use it as the locale from this point on\n if ('localized' in field && field.localized && adapter.payload.config.localization) {\n const matchedLocale = adapter.payload.config.localization.localeCodes.find(\n (locale) => locale === pathSegments[1],\n )\n\n if (matchedLocale) {\n locale = matchedLocale\n pathSegments.splice(1, 1)\n }\n }\n\n switch (field.type) {\n case 'tabs': {\n return getTableColumnFromPath({\n adapter,\n aliasTable,\n collectionPath,\n columnPrefix,\n constraintPath,\n constraints,\n fields: field.tabs.map((tab) => ({\n ...tab,\n type: 'tab',\n })),\n joins,\n locale,\n pathSegments: pathSegments.slice(1),\n rootTableName,\n selectFields,\n tableName: newTableName,\n tableNameSuffix,\n value,\n })\n }\n case 'tab': {\n if (tabHasName(field)) {\n return getTableColumnFromPath({\n adapter,\n aliasTable,\n collectionPath,\n columnPrefix: `${columnPrefix}${field.name}_`,\n constraintPath: `${constraintPath}${field.name}.`,\n constraints,\n fields: field.fields,\n joins,\n locale,\n pathSegments: pathSegments.slice(1),\n rootTableName,\n selectFields,\n tableName: newTableName,\n tableNameSuffix: `${tableNameSuffix}${toSnakeCase(field.name)}_`,\n value,\n })\n }\n return getTableColumnFromPath({\n adapter,\n aliasTable,\n collectionPath,\n columnPrefix,\n constraintPath,\n constraints,\n fields: field.fields,\n joins,\n locale,\n pathSegments: pathSegments.slice(1),\n rootTableName,\n selectFields,\n tableName: newTableName,\n tableNameSuffix,\n value,\n })\n }\n\n case 'group': {\n if (locale && field.localized && adapter.payload.config.localization) {\n newTableName = `${tableName}${adapter.localesSuffix}`\n\n joins.push({\n condition: eq(adapter.tables[tableName].id, adapter.tables[newTableName]._parentID),\n table: adapter.tables[newTableName],\n })\n if (locale !== 'all') {\n constraints.push({\n columnName: '_locale',\n table: adapter.tables[newTableName],\n value: locale,\n })\n }\n }\n return getTableColumnFromPath({\n adapter,\n aliasTable,\n collectionPath,\n columnPrefix: `${columnPrefix}${field.name}_`,\n constraintPath: `${constraintPath}${field.name}.`,\n constraints,\n fields: field.fields,\n joins,\n locale,\n pathSegments: pathSegments.slice(1),\n rootTableName,\n selectFields,\n tableName: newTableName,\n tableNameSuffix: `${tableNameSuffix}${toSnakeCase(field.name)}_`,\n value,\n })\n }\n\n case 'select': {\n if (field.hasMany) {\n const newTableName = adapter.tableNameMap.get(\n `${tableName}_${tableNameSuffix}${toSnakeCase(field.name)}`,\n )\n\n if (locale && field.localized && adapter.payload.config.localization) {\n joins.push({\n condition: and(\n eq(adapter.tables[tableName].id, adapter.tables[newTableName].parent),\n eq(adapter.tables[newTableName]._locale, locale),\n ),\n table: adapter.tables[newTableName],\n })\n if (locale !== 'all') {\n constraints.push({\n columnName: '_locale',\n table: adapter.tables[newTableName],\n value: locale,\n })\n }\n } else {\n joins.push({\n condition: eq(adapter.tables[tableName].id, adapter.tables[newTableName].parent),\n table: adapter.tables[newTableName],\n })\n }\n\n return {\n columnName: 'value',\n constraints,\n field,\n table: adapter.tables[newTableName],\n }\n }\n break\n }\n\n case 'text':\n case 'number': {\n if (field.hasMany) {\n let tableType = 'texts'\n let columnName = 'text'\n if (field.type === 'number') {\n tableType = 'numbers'\n columnName = 'number'\n }\n newTableName = `${tableName}_${tableType}`\n const joinConstraints = [\n eq(adapter.tables[tableName].id, adapter.tables[newTableName].parent),\n eq(adapter.tables[newTableName].path, `${constraintPath}${field.name}`),\n ]\n\n if (locale && field.localized && adapter.payload.config.localization) {\n joins.push({\n condition: and(...joinConstraints, eq(adapter.tables[newTableName]._locale, locale)),\n table: adapter.tables[newTableName],\n })\n if (locale !== 'all') {\n constraints.push({\n columnName: 'locale',\n table: adapter.tables[newTableName],\n value: locale,\n })\n }\n } else {\n joins.push({\n condition: and(...joinConstraints),\n table: adapter.tables[newTableName],\n })\n }\n\n return {\n columnName,\n constraints,\n field,\n table: adapter.tables[newTableName],\n }\n }\n break\n }\n\n case 'array': {\n newTableName = adapter.tableNameMap.get(\n `${tableName}_${tableNameSuffix}${toSnakeCase(field.name)}`,\n )\n\n constraintPath = `${constraintPath}${field.name}.%.`\n if (locale && field.localized && adapter.payload.config.localization) {\n joins.push({\n condition: and(\n eq(adapter.tables[tableName].id, adapter.tables[newTableName]._parentID),\n eq(adapter.tables[newTableName]._locale, locale),\n ),\n table: adapter.tables[newTableName],\n })\n if (locale !== 'all') {\n constraints.push({\n columnName: '_locale',\n table: adapter.tables[newTableName],\n value: locale,\n })\n }\n } else {\n joins.push({\n condition: eq(adapter.tables[tableName].id, adapter.tables[newTableName]._parentID),\n table: adapter.tables[newTableName],\n })\n }\n return getTableColumnFromPath({\n adapter,\n collectionPath,\n constraintPath,\n constraints,\n fields: field.fields,\n joins,\n locale,\n pathSegments: pathSegments.slice(1),\n rootTableName,\n selectFields,\n tableName: newTableName,\n value,\n })\n }\n\n case 'blocks': {\n let blockTableColumn: TableColumn\n let newTableName: string\n\n // handle blockType queries\n if (pathSegments[1] === 'blockType') {\n // find the block config using the value\n const blockTypes = Array.isArray(value) ? value : [value]\n blockTypes.forEach((blockType) => {\n const block = field.blocks.find((block) => block.slug === blockType)\n newTableName = adapter.tableNameMap.get(\n `${tableName}_blocks_${toSnakeCase(block.slug)}`,\n )\n const newAliasTableName = toSnakeCase(uuid())\n const newAliasTable = alias(adapter.tables[newTableName], newAliasTableName)\n\n joins.push({\n condition: eq(adapter.tables[tableName].id, newAliasTable._parentID),\n table: newAliasTable,\n })\n constraints.push({\n columnName: '_path',\n table: newAliasTable,\n value: pathSegments[0],\n })\n })\n return {\n constraints,\n field,\n getNotNullColumnByValue: () => 'id',\n table: adapter.tables[tableName],\n }\n }\n\n const hasBlockField = field.blocks.some((block) => {\n newTableName = adapter.tableNameMap.get(`${tableName}_blocks_${toSnakeCase(block.slug)}`)\n constraintPath = `${constraintPath}${field.name}.%.`\n\n let result\n const blockConstraints = []\n const blockSelectFields = {}\n try {\n result = getTableColumnFromPath({\n adapter,\n collectionPath,\n constraintPath,\n constraints: blockConstraints,\n fields: block.fields,\n joins,\n locale,\n pathSegments: pathSegments.slice(1),\n rootTableName,\n selectFields: blockSelectFields,\n tableName: newTableName,\n value,\n })\n } catch (error) {\n // this is fine, not every block will have the field\n }\n if (!result) {\n return\n }\n blockTableColumn = result\n constraints = constraints.concat(blockConstraints)\n selectFields = { ...selectFields, ...blockSelectFields }\n if (field.localized && adapter.payload.config.localization) {\n joins.push({\n condition: and(\n eq(\n (aliasTable || adapter.tables[tableName]).id,\n adapter.tables[newTableName]._parentID,\n ),\n eq(adapter.tables[newTableName]._locale, locale),\n ),\n table: adapter.tables[newTableName],\n })\n if (locale) {\n constraints.push({\n columnName: '_locale',\n table: adapter.tables[newTableName],\n value: locale,\n })\n }\n } else {\n joins.push({\n condition: eq(\n (aliasTable || adapter.tables[tableName]).id,\n adapter.tables[newTableName]._parentID,\n ),\n table: adapter.tables[newTableName],\n })\n }\n return true\n })\n if (hasBlockField) {\n return {\n columnName: blockTableColumn.columnName,\n constraints,\n field: blockTableColumn.field,\n pathSegments: pathSegments.slice(1),\n rawColumn: blockTableColumn.rawColumn,\n table: blockTableColumn.table,\n }\n }\n break\n }\n\n case 'relationship':\n case 'upload': {\n const newCollectionPath = pathSegments.slice(1).join('.')\n if (Array.isArray(field.relationTo) || (field.type === 'relationship' && field.hasMany)) {\n let relationshipFields\n const relationTableName = `${rootTableName}${adapter.relationshipsSuffix}`\n const aliasRelationshipTableName = uuid()\n const aliasRelationshipTable = alias(\n adapter.tables[relationTableName],\n aliasRelationshipTableName,\n )\n\n // Join in the relationships table\n if (locale && field.localized && adapter.payload.config.localization) {\n joins.push({\n condition: and(\n eq((aliasTable || adapter.tables[rootTableName]).id, aliasRelationshipTable.parent),\n eq(aliasRelationshipTable.locale, locale),\n like(aliasRelationshipTable.path, `${constraintPath}${field.name}`),\n ),\n table: aliasRelationshipTable,\n })\n if (locale !== 'all') {\n constraints.push({\n columnName: 'locale',\n table: aliasRelationshipTable,\n value: locale,\n })\n }\n } else {\n // Join in the relationships table\n joins.push({\n condition: and(\n eq((aliasTable || adapter.tables[rootTableName]).id, aliasRelationshipTable.parent),\n like(aliasRelationshipTable.path, `${constraintPath}${field.name}`),\n ),\n table: aliasRelationshipTable,\n })\n }\n\n selectFields[`${relationTableName}.path`] = aliasRelationshipTable.path\n\n let newAliasTable\n\n if (typeof field.relationTo === 'string') {\n const relationshipConfig = adapter.payload.collections[field.relationTo].config\n\n newTableName = adapter.tableNameMap.get(toSnakeCase(relationshipConfig.slug))\n\n // parent to relationship join table\n relationshipFields = relationshipConfig.fields\n\n newAliasTable = alias(adapter.tables[newTableName], toSnakeCase(uuid()))\n\n joins.push({\n condition: eq(newAliasTable.id, aliasRelationshipTable[`${field.relationTo}ID`]),\n table: newAliasTable,\n })\n\n if (newCollectionPath === '' || newCollectionPath === 'id') {\n return {\n columnName: `${field.relationTo}ID`,\n constraints,\n field,\n table: aliasRelationshipTable,\n }\n }\n } else if (newCollectionPath === 'value') {\n const tableColumnsNames = field.relationTo.map((relationTo) => {\n const relationTableName = adapter.tableNameMap.get(\n toSnakeCase(adapter.payload.collections[relationTo].config.slug),\n )\n\n return `\"${aliasRelationshipTableName}\".\"${relationTableName}_id\"`\n })\n return {\n constraints,\n field,\n rawColumn: sql.raw(`COALESCE(${tableColumnsNames.join(', ')})`),\n table: aliasRelationshipTable,\n }\n } else if (newCollectionPath === 'relationTo') {\n const relationTo = Array.isArray(field.relationTo)\n ? field.relationTo\n : [field.relationTo]\n\n return {\n constraints,\n field,\n getNotNullColumnByValue: (val) => {\n const matchedRelation = relationTo.find((relation) => relation === val)\n if (matchedRelation) return `${matchedRelation}ID`\n return undefined\n },\n table: aliasRelationshipTable,\n }\n } else {\n throw new APIError('Not supported')\n }\n\n return getTableColumnFromPath({\n adapter,\n aliasTable: newAliasTable,\n collectionPath: newCollectionPath,\n constraints,\n fields: relationshipFields,\n joins,\n locale,\n pathSegments: pathSegments.slice(1),\n rootTableName: newTableName,\n selectFields,\n tableName: newTableName,\n value,\n })\n } else if (\n pathSegments.length > 1 &&\n !(pathSegments.length === 2 && pathSegments[1] === 'id')\n ) {\n // simple relationships\n const columnName = `${columnPrefix}${field.name}`\n const newTableName = adapter.tableNameMap.get(\n toSnakeCase(adapter.payload.collections[field.relationTo].config.slug),\n )\n const aliasTableName = uuid()\n const newAliasTable = alias(adapter.tables[newTableName], aliasTableName)\n\n if (field.localized && adapter.payload.config.localization) {\n const aliasLocaleTableName = uuid()\n const aliasLocaleTable = alias(\n adapter.tables[`${rootTableName}${adapter.localesSuffix}`],\n aliasLocaleTableName,\n )\n joins.push({\n condition: and(\n eq(aliasLocaleTable._parentID, adapter.tables[rootTableName].id),\n eq(aliasLocaleTable._locale, locale),\n ),\n table: aliasLocaleTable,\n })\n joins.push({\n condition: eq(aliasLocaleTable[columnName], newAliasTable.id),\n table: newAliasTable,\n })\n } else {\n joins.push({\n condition: eq(\n newAliasTable.id,\n aliasTable ? aliasTable[columnName] : adapter.tables[tableName][columnName],\n ),\n table: newAliasTable,\n })\n }\n\n return getTableColumnFromPath({\n adapter,\n aliasTable: newAliasTable,\n collectionPath: newCollectionPath,\n constraintPath: '',\n constraints,\n fields: adapter.payload.collections[field.relationTo].config.fields,\n joins,\n locale,\n pathSegments: pathSegments.slice(1),\n selectFields,\n tableName: newTableName,\n value,\n })\n }\n break\n }\n\n default: {\n // fall through\n break\n }\n }\n\n if (fieldAffectsData(field)) {\n if (field.localized && adapter.payload.config.localization) {\n // If localized, we go to localized table and set aliasTable to undefined\n // so it is not picked up below to be used as targetTable\n const parentTable = aliasTable || adapter.tables[tableName]\n newTableName = `${tableName}${adapter.localesSuffix}`\n\n joins.push({\n condition: eq(parentTable.id, adapter.tables[newTableName]._parentID),\n table: adapter.tables[newTableName],\n })\n\n aliasTable = undefined\n\n if (locale !== 'all') {\n constraints.push({\n columnName: '_locale',\n table: adapter.tables[newTableName],\n value: locale,\n })\n }\n }\n\n const targetTable = aliasTable || adapter.tables[newTableName]\n\n selectFields[`${newTableName}.${columnPrefix}${field.name}`] =\n targetTable[`${columnPrefix}${field.name}`]\n\n return {\n columnName: `${columnPrefix}${field.name}`,\n constraints,\n field,\n pathSegments,\n table: targetTable,\n }\n }\n }\n\n throw new APIError(`Cannot find field for path at ${fieldPath}`)\n}\n"],"names":["and","eq","like","sql","alias","APIError","flattenTopLevelFields","fieldAffectsData","tabHasName","toSnakeCase","v4","uuid","getTableColumnFromPath","adapter","aliasTable","collectionPath","columnPrefix","constraintPath","incomingConstraintPath","constraints","fields","joins","locale","incomingLocale","pathSegments","incomingSegments","rootTableName","incomingRootTableName","selectFields","tableName","tableNameSuffix","value","fieldPath","field","find","fieldToFind","name","newTableName","id","tables","columnName","type","idType","table","localized","payload","config","localization","matchedLocale","localeCodes","splice","tabs","map","tab","slice","localesSuffix","push","condition","_parentID","hasMany","tableNameMap","get","parent","_locale","tableType","joinConstraints","path","blockTableColumn","blockTypes","Array","isArray","forEach","blockType","block","blocks","slug","newAliasTableName","newAliasTable","getNotNullColumnByValue","hasBlockField","some","result","blockConstraints","blockSelectFields","error","concat","rawColumn","newCollectionPath","join","relationTo","relationshipFields","relationTableName","relationshipsSuffix","aliasRelationshipTableName","aliasRelationshipTable","relationshipConfig","collections","tableColumnsNames","raw","val","matchedRelation","relation","undefined","length","aliasTableName","aliasLocaleTableName","aliasLocaleTable","parentTable","targetTable"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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O9B,QAAQ0B,MAAM,CAACF,aAAa;wBACnCN,OAAOT;oBACT;gBACF;YACF;YAEA,MAAMsF,cAAc9F,cAAcD,QAAQ0B,MAAM,CAACF,aAAa;YAE9DT,YAAY,CAAC,CAAC,EAAES,aAAa,CAAC,EAAErB,aAAa,EAAEiB,MAAMG,IAAI,CAAC,CAAC,CAAC,GAC1DwE,WAAW,CAAC,CAAC,EAAE5F,aAAa,EAAEiB,MAAMG,IAAI,CAAC,CAAC,CAAC;YAE7C,OAAO;gBACLI,YAAY,CAAC,EAAExB,aAAa,EAAEiB,MAAMG,IAAI,CAAC,CAAC;gBAC1CjB;gBACAc;gBACAT;gBACAmB,OAAOiE;YACT;QACF;IACF;IAEA,MAAM,IAAIvG,SAAS,CAAC,8BAA8B,EAAE2B,UAAU,CAAC;AACjE,EAAC"}
1
+ {"version":3,"sources":["../../src/queries/getTableColumnFromPath.ts"],"sourcesContent":["/* eslint-disable no-param-reassign */\nimport type { SQL } from 'drizzle-orm'\nimport type { PgTableWithColumns } from 'drizzle-orm/pg-core'\nimport type { Field, FieldAffectingData, NumberField, TabAsField, TextField } from 'payload'\n\nimport { and, eq, like, sql } from 'drizzle-orm'\nimport { alias } from 'drizzle-orm/pg-core'\nimport { APIError, flattenTopLevelFields } from 'payload'\nimport { fieldAffectsData, tabHasName } from 'payload/shared'\nimport toSnakeCase from 'to-snake-case'\nimport { v4 as uuid } from 'uuid'\n\nimport type { GenericColumn, GenericTable, PostgresAdapter } from '../types.js'\nimport type { BuildQueryJoinAliases } from './buildQuery.js'\n\ntype Constraint = {\n columnName: string\n table: GenericTable | PgTableWithColumns<any>\n value: unknown\n}\n\ntype TableColumn = {\n columnName?: string\n constraints: Constraint[]\n field: FieldAffectingData\n getNotNullColumnByValue?: (val: unknown) => string\n pathSegments?: string[]\n rawColumn?: SQL\n table: GenericTable | PgTableWithColumns<any>\n}\n\ntype Args = {\n adapter: PostgresAdapter\n aliasTable?: GenericTable | PgTableWithColumns<any>\n collectionPath: string\n columnPrefix?: string\n constraintPath?: string\n constraints?: Constraint[]\n fields: (Field | TabAsField)[]\n joins: BuildQueryJoinAliases\n locale?: string\n pathSegments: string[]\n rootTableName?: string\n selectFields: Record<string, GenericColumn>\n tableName: string\n /**\n * If creating a new table name for arrays and blocks, this suffix should be appended to the table name\n */\n tableNameSuffix?: string\n /**\n * The raw value of the query before sanitization\n */\n value: unknown\n}\n/**\n * Transforms path to table and column name\n * Adds tables to `join`\n * @returns TableColumn\n */\nexport const getTableColumnFromPath = ({\n adapter,\n aliasTable,\n collectionPath,\n columnPrefix = '',\n constraintPath: incomingConstraintPath,\n constraints = [],\n fields,\n joins,\n locale: incomingLocale,\n pathSegments: incomingSegments,\n rootTableName: incomingRootTableName,\n selectFields,\n tableName,\n tableNameSuffix = '',\n value,\n}: Args): TableColumn => {\n const fieldPath = incomingSegments[0]\n let locale = incomingLocale\n const rootTableName = incomingRootTableName || tableName\n let constraintPath = incomingConstraintPath || ''\n\n const field = flattenTopLevelFields(fields as Field[]).find(\n (fieldToFind) => fieldAffectsData(fieldToFind) && fieldToFind.name === fieldPath,\n ) as Field | TabAsField\n let newTableName = tableName\n\n if (!field && fieldPath === 'id') {\n selectFields.id = adapter.tables[newTableName].id\n return {\n columnName: 'id',\n constraints,\n field: {\n name: 'id',\n type: adapter.idType === 'uuid' ? 'text' : 'number',\n } as NumberField | TextField,\n table: adapter.tables[newTableName],\n }\n }\n\n if (field) {\n const pathSegments = [...incomingSegments]\n\n // If next segment is a locale,\n // we need to take it out and use it as the locale from this point on\n if ('localized' in field && field.localized && adapter.payload.config.localization) {\n const matchedLocale = adapter.payload.config.localization.localeCodes.find(\n (locale) => locale === pathSegments[1],\n )\n\n if (matchedLocale) {\n locale = matchedLocale\n pathSegments.splice(1, 1)\n }\n }\n\n switch (field.type) {\n case 'tabs': {\n return getTableColumnFromPath({\n adapter,\n aliasTable,\n collectionPath,\n columnPrefix,\n constraintPath,\n constraints,\n fields: field.tabs.map((tab) => ({\n ...tab,\n type: 'tab',\n })),\n joins,\n locale,\n pathSegments: pathSegments.slice(1),\n rootTableName,\n selectFields,\n tableName: newTableName,\n tableNameSuffix,\n value,\n })\n }\n case 'tab': {\n if (tabHasName(field)) {\n return getTableColumnFromPath({\n adapter,\n aliasTable,\n collectionPath,\n columnPrefix: `${columnPrefix}${field.name}_`,\n constraintPath: `${constraintPath}${field.name}.`,\n constraints,\n fields: field.fields,\n joins,\n locale,\n pathSegments: pathSegments.slice(1),\n rootTableName,\n selectFields,\n tableName: newTableName,\n tableNameSuffix: `${tableNameSuffix}${toSnakeCase(field.name)}_`,\n value,\n })\n }\n return getTableColumnFromPath({\n adapter,\n aliasTable,\n collectionPath,\n columnPrefix,\n constraintPath,\n constraints,\n fields: field.fields,\n joins,\n locale,\n pathSegments: pathSegments.slice(1),\n rootTableName,\n selectFields,\n tableName: newTableName,\n tableNameSuffix,\n value,\n })\n }\n\n case 'group': {\n if (locale && field.localized && adapter.payload.config.localization) {\n newTableName = `${tableName}${adapter.localesSuffix}`\n\n joins.push({\n condition: eq(adapter.tables[tableName].id, adapter.tables[newTableName]._parentID),\n table: adapter.tables[newTableName],\n })\n if (locale !== 'all') {\n constraints.push({\n columnName: '_locale',\n table: adapter.tables[newTableName],\n value: locale,\n })\n }\n }\n return getTableColumnFromPath({\n adapter,\n aliasTable,\n collectionPath,\n columnPrefix: `${columnPrefix}${field.name}_`,\n constraintPath: `${constraintPath}${field.name}.`,\n constraints,\n fields: field.fields,\n joins,\n locale,\n pathSegments: pathSegments.slice(1),\n rootTableName,\n selectFields,\n tableName: newTableName,\n tableNameSuffix: `${tableNameSuffix}${toSnakeCase(field.name)}_`,\n value,\n })\n }\n\n case 'select': {\n if (field.hasMany) {\n const newTableName = adapter.tableNameMap.get(\n `${tableName}_${tableNameSuffix}${toSnakeCase(field.name)}`,\n )\n\n if (locale && field.localized && adapter.payload.config.localization) {\n joins.push({\n condition: and(\n eq(adapter.tables[tableName].id, adapter.tables[newTableName].parent),\n eq(adapter.tables[newTableName]._locale, locale),\n ),\n table: adapter.tables[newTableName],\n })\n if (locale !== 'all') {\n constraints.push({\n columnName: '_locale',\n table: adapter.tables[newTableName],\n value: locale,\n })\n }\n } else {\n joins.push({\n condition: eq(adapter.tables[tableName].id, adapter.tables[newTableName].parent),\n table: adapter.tables[newTableName],\n })\n }\n\n return {\n columnName: 'value',\n constraints,\n field,\n table: adapter.tables[newTableName],\n }\n }\n break\n }\n\n case 'text':\n case 'number': {\n if (field.hasMany) {\n let tableType = 'texts'\n let columnName = 'text'\n if (field.type === 'number') {\n tableType = 'numbers'\n columnName = 'number'\n }\n newTableName = `${tableName}_${tableType}`\n const joinConstraints = [\n eq(adapter.tables[tableName].id, adapter.tables[newTableName].parent),\n eq(adapter.tables[newTableName].path, `${constraintPath}${field.name}`),\n ]\n\n if (locale && field.localized && adapter.payload.config.localization) {\n joins.push({\n condition: and(...joinConstraints, eq(adapter.tables[newTableName]._locale, locale)),\n table: adapter.tables[newTableName],\n })\n if (locale !== 'all') {\n constraints.push({\n columnName: 'locale',\n table: adapter.tables[newTableName],\n value: locale,\n })\n }\n } else {\n joins.push({\n condition: and(...joinConstraints),\n table: adapter.tables[newTableName],\n })\n }\n\n return {\n columnName,\n constraints,\n field,\n table: adapter.tables[newTableName],\n }\n }\n break\n }\n\n case 'array': {\n newTableName = adapter.tableNameMap.get(\n `${tableName}_${tableNameSuffix}${toSnakeCase(field.name)}`,\n )\n\n constraintPath = `${constraintPath}${field.name}.%.`\n if (locale && field.localized && adapter.payload.config.localization) {\n joins.push({\n condition: and(\n eq(adapter.tables[tableName].id, adapter.tables[newTableName]._parentID),\n eq(adapter.tables[newTableName]._locale, locale),\n ),\n table: adapter.tables[newTableName],\n })\n if (locale !== 'all') {\n constraints.push({\n columnName: '_locale',\n table: adapter.tables[newTableName],\n value: locale,\n })\n }\n } else {\n joins.push({\n condition: eq(adapter.tables[tableName].id, adapter.tables[newTableName]._parentID),\n table: adapter.tables[newTableName],\n })\n }\n return getTableColumnFromPath({\n adapter,\n collectionPath,\n constraintPath,\n constraints,\n fields: field.fields,\n joins,\n locale,\n pathSegments: pathSegments.slice(1),\n rootTableName,\n selectFields,\n tableName: newTableName,\n value,\n })\n }\n\n case 'blocks': {\n let blockTableColumn: TableColumn\n let newTableName: string\n\n // handle blockType queries\n if (pathSegments[1] === 'blockType') {\n // find the block config using the value\n const blockTypes = Array.isArray(value) ? value : [value]\n blockTypes.forEach((blockType) => {\n const block = field.blocks.find((block) => block.slug === blockType)\n newTableName = adapter.tableNameMap.get(\n `${tableName}_blocks_${toSnakeCase(block.slug)}`,\n )\n const newAliasTableName = toSnakeCase(uuid())\n const newAliasTable = alias(adapter.tables[newTableName], newAliasTableName)\n\n joins.push({\n condition: eq(adapter.tables[tableName].id, newAliasTable._parentID),\n table: newAliasTable,\n })\n constraints.push({\n columnName: '_path',\n table: newAliasTable,\n value: pathSegments[0],\n })\n })\n return {\n constraints,\n field,\n getNotNullColumnByValue: () => 'id',\n table: adapter.tables[tableName],\n }\n }\n\n const hasBlockField = field.blocks.some((block) => {\n newTableName = adapter.tableNameMap.get(`${tableName}_blocks_${toSnakeCase(block.slug)}`)\n constraintPath = `${constraintPath}${field.name}.%.`\n\n let result\n const blockConstraints = []\n const blockSelectFields = {}\n try {\n result = getTableColumnFromPath({\n adapter,\n collectionPath,\n constraintPath,\n constraints: blockConstraints,\n fields: block.fields,\n joins,\n locale,\n pathSegments: pathSegments.slice(1),\n rootTableName,\n selectFields: blockSelectFields,\n tableName: newTableName,\n value,\n })\n } catch (error) {\n // this is fine, not every block will have the field\n }\n if (!result) {\n return\n }\n blockTableColumn = result\n constraints = constraints.concat(blockConstraints)\n selectFields = { ...selectFields, ...blockSelectFields }\n if (field.localized && adapter.payload.config.localization) {\n joins.push({\n condition: and(\n eq(\n (aliasTable || adapter.tables[tableName]).id,\n adapter.tables[newTableName]._parentID,\n ),\n eq(adapter.tables[newTableName]._locale, locale),\n ),\n table: adapter.tables[newTableName],\n })\n if (locale) {\n constraints.push({\n columnName: '_locale',\n table: adapter.tables[newTableName],\n value: locale,\n })\n }\n } else {\n joins.push({\n condition: eq(\n (aliasTable || adapter.tables[tableName]).id,\n adapter.tables[newTableName]._parentID,\n ),\n table: adapter.tables[newTableName],\n })\n }\n return true\n })\n if (hasBlockField) {\n return {\n columnName: blockTableColumn.columnName,\n constraints,\n field: blockTableColumn.field,\n pathSegments: pathSegments.slice(1),\n rawColumn: blockTableColumn.rawColumn,\n table: blockTableColumn.table,\n }\n }\n break\n }\n\n case 'relationship':\n case 'upload': {\n const newCollectionPath = pathSegments.slice(1).join('.')\n if (Array.isArray(field.relationTo) || (field.type === 'relationship' && field.hasMany)) {\n let relationshipFields\n const relationTableName = `${rootTableName}${adapter.relationshipsSuffix}`\n const aliasRelationshipTableName = uuid()\n const aliasRelationshipTable = alias(\n adapter.tables[relationTableName],\n aliasRelationshipTableName,\n )\n\n // Join in the relationships table\n if (locale && field.localized && adapter.payload.config.localization) {\n joins.push({\n condition: and(\n eq((aliasTable || adapter.tables[rootTableName]).id, aliasRelationshipTable.parent),\n eq(aliasRelationshipTable.locale, locale),\n like(aliasRelationshipTable.path, `${constraintPath}${field.name}`),\n ),\n table: aliasRelationshipTable,\n })\n if (locale !== 'all') {\n constraints.push({\n columnName: 'locale',\n table: aliasRelationshipTable,\n value: locale,\n })\n }\n } else {\n // Join in the relationships table\n joins.push({\n condition: and(\n eq((aliasTable || adapter.tables[rootTableName]).id, aliasRelationshipTable.parent),\n like(aliasRelationshipTable.path, `${constraintPath}${field.name}`),\n ),\n table: aliasRelationshipTable,\n })\n }\n\n selectFields[`${relationTableName}.path`] = aliasRelationshipTable.path\n\n let newAliasTable\n\n if (typeof field.relationTo === 'string') {\n const relationshipConfig = adapter.payload.collections[field.relationTo].config\n\n newTableName = adapter.tableNameMap.get(toSnakeCase(relationshipConfig.slug))\n\n // parent to relationship join table\n relationshipFields = relationshipConfig.fields\n\n newAliasTable = alias(adapter.tables[newTableName], toSnakeCase(uuid()))\n\n joins.push({\n condition: eq(newAliasTable.id, aliasRelationshipTable[`${field.relationTo}ID`]),\n table: newAliasTable,\n })\n\n if (newCollectionPath === '' || newCollectionPath === 'id') {\n return {\n columnName: `${field.relationTo}ID`,\n constraints,\n field,\n table: aliasRelationshipTable,\n }\n }\n } else if (newCollectionPath === 'value') {\n const tableColumnsNames = field.relationTo.map((relationTo) => {\n const relationTableName = adapter.tableNameMap.get(\n toSnakeCase(adapter.payload.collections[relationTo].config.slug),\n )\n\n return `\"${aliasRelationshipTableName}\".\"${relationTableName}_id\"`\n })\n return {\n constraints,\n field,\n rawColumn: sql.raw(`COALESCE(${tableColumnsNames.join(', ')})`),\n table: aliasRelationshipTable,\n }\n } else if (newCollectionPath === 'relationTo') {\n const relationTo = Array.isArray(field.relationTo)\n ? field.relationTo\n : [field.relationTo]\n\n return {\n constraints,\n field,\n getNotNullColumnByValue: (val) => {\n const matchedRelation = relationTo.find((relation) => relation === val)\n if (matchedRelation) return `${matchedRelation}ID`\n return undefined\n },\n table: aliasRelationshipTable,\n }\n } else {\n throw new APIError('Not supported')\n }\n\n return getTableColumnFromPath({\n adapter,\n aliasTable: newAliasTable,\n collectionPath: newCollectionPath,\n constraints,\n fields: relationshipFields,\n joins,\n locale,\n pathSegments: pathSegments.slice(1),\n rootTableName: newTableName,\n selectFields,\n tableName: newTableName,\n value,\n })\n } else if (\n pathSegments.length > 1 &&\n !(pathSegments.length === 2 && pathSegments[1] === 'id')\n ) {\n // simple relationships\n const columnName = `${columnPrefix}${field.name}`\n const newTableName = adapter.tableNameMap.get(\n toSnakeCase(adapter.payload.collections[field.relationTo].config.slug),\n )\n const aliasTableName = uuid()\n const newAliasTable = alias(adapter.tables[newTableName], aliasTableName)\n\n if (field.localized && adapter.payload.config.localization) {\n const aliasLocaleTableName = uuid()\n const aliasLocaleTable = alias(\n adapter.tables[`${rootTableName}${adapter.localesSuffix}`],\n aliasLocaleTableName,\n )\n joins.push({\n condition: and(\n eq(aliasLocaleTable._parentID, adapter.tables[rootTableName].id),\n eq(aliasLocaleTable._locale, locale),\n ),\n table: aliasLocaleTable,\n })\n joins.push({\n condition: eq(aliasLocaleTable[columnName], newAliasTable.id),\n table: newAliasTable,\n })\n } else {\n joins.push({\n condition: eq(\n newAliasTable.id,\n aliasTable ? aliasTable[columnName] : adapter.tables[tableName][columnName],\n ),\n table: newAliasTable,\n })\n }\n\n return getTableColumnFromPath({\n adapter,\n aliasTable: newAliasTable,\n collectionPath: newCollectionPath,\n constraintPath: '',\n constraints,\n fields: adapter.payload.collections[field.relationTo].config.fields,\n joins,\n locale,\n pathSegments: pathSegments.slice(1),\n selectFields,\n tableName: newTableName,\n value,\n })\n }\n break\n }\n\n default: {\n // fall through\n break\n }\n }\n\n if (fieldAffectsData(field)) {\n if (field.localized && adapter.payload.config.localization) {\n // If localized, we go to localized table and set aliasTable to undefined\n // so it is not picked up below to be used as targetTable\n const parentTable = aliasTable || adapter.tables[tableName]\n newTableName = `${tableName}${adapter.localesSuffix}`\n\n joins.push({\n condition: eq(parentTable.id, adapter.tables[newTableName]._parentID),\n table: adapter.tables[newTableName],\n })\n\n aliasTable = undefined\n\n if (locale !== 'all') {\n constraints.push({\n columnName: '_locale',\n table: adapter.tables[newTableName],\n value: locale,\n })\n }\n }\n\n const targetTable = aliasTable || adapter.tables[newTableName]\n\n selectFields[`${newTableName}.${columnPrefix}${field.name}`] =\n targetTable[`${columnPrefix}${field.name}`]\n\n return {\n columnName: `${columnPrefix}${field.name}`,\n constraints,\n field,\n pathSegments,\n table: targetTable,\n }\n }\n }\n\n throw new APIError(`Cannot find field for path at ${fieldPath}`)\n}\n"],"names":["and","eq","like","sql","alias","APIError","flattenTopLevelFields","fieldAffectsData","tabHasName","toSnakeCase","v4","uuid","getTableColumnFromPath","adapter","aliasTable","collectionPath","columnPrefix","constraintPath","incomingConstraintPath","constraints","fields","joins","locale","incomingLocale","pathSegments","incomingSegments","rootTableName","incomingRootTableName","selectFields","tableName","tableNameSuffix","value","fieldPath","field","find","fieldToFind","name","newTableName","id","tables","columnName","type","idType","table","localized","payload","config","localization","matchedLocale","localeCodes","splice","tabs","map","tab","slice","localesSuffix","push","condition","_parentID","hasMany","tableNameMap","get","parent","_locale","tableType","joinConstraints","path","blockTableColumn","blockTypes","Array","isArray","forEach","blockType","block","blocks","slug","newAliasTableName","newAliasTable","getNotNullColumnByValue","hasBlockField","some","result","blockConstraints","blockSelectFields","error","concat","rawColumn","newCollectionPath","join","relationTo","relationshipFields","relationTableName","relationshipsSuffix","aliasRelationshipTableName","aliasRelationshipTable","relationshipConfig","collections","tableColumnsNames","raw","val","matchedRelation","relation","undefined","length","aliasTableName","aliasLocaleTableName","aliasLocaleTable","parentTable","targetTable"],"mappings":"AAAA,oCAAoC,GAKpC,SAASA,GAAG,EAAEC,EAAE,EAAEC,IAAI,EAAEC,GAAG,QAAQ,cAAa;AAChD,SAASC,KAAK,QAAQ,sBAAqB;AAC3C,SAASC,QAAQ,EAAEC,qBAAqB,QAAQ,UAAS;AACzD,SAASC,gBAAgB,EAAEC,UAAU,QAAQ,iBAAgB;AAC7D,OAAOC,iBAAiB,gBAAe;AACvC,SAASC,MAAMC,IAAI,QAAQ,OAAM;AA4CjC;;;;CAIC,GACD,OAAO,MAAMC,yBAAyB,CAAC,EACrCC,OAAO,EACPC,UAAU,EACVC,cAAc,EACdC,eAAe,EAAE,EACjBC,gBAAgBC,sBAAsB,EACtCC,cAAc,EAAE,EAChBC,MAAM,EACNC,KAAK,EACLC,QAAQC,cAAc,EACtBC,cAAcC,gBAAgB,EAC9BC,eAAeC,qBAAqB,EACpCC,YAAY,EACZC,SAAS,EACTC,kBAAkB,EAAE,EACpBC,KAAK,EACA;IACL,MAAMC,YAAYP,gBAAgB,CAAC,EAAE;IACrC,IAAIH,SAASC;IACb,MAAMG,gBAAgBC,yBAAyBE;IAC/C,IAAIZ,iBAAiBC,0BAA0B;IAE/C,MAAMe,QAAQ3B,sBAAsBc,QAAmBc,IAAI,CACzD,CAACC,cAAgB5B,iB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ACTC,WAAWxD,GAAG0G,YAAYrE,EAAE,EAAEzB,QAAQ0B,MAAM,CAACF,aAAa,CAACqB,SAAS;oBACpEf,OAAO9B,QAAQ0B,MAAM,CAACF,aAAa;gBACrC;gBAEAvB,aAAawF;gBAEb,IAAIhF,WAAW,OAAO;oBACpBH,YAAYqC,IAAI,CAAC;wBACfhB,YAAY;wBACZG,OAAO9B,QAAQ0B,MAAM,CAACF,aAAa;wBACnCN,OAAOT;oBACT;gBACF;YACF;YAEA,MAAMsF,cAAc9F,cAAcD,QAAQ0B,MAAM,CAACF,aAAa;YAE9DT,YAAY,CAAC,CAAC,EAAES,aAAa,CAAC,EAAErB,aAAa,EAAEiB,MAAMG,IAAI,CAAC,CAAC,CAAC,GAC1DwE,WAAW,CAAC,CAAC,EAAE5F,aAAa,EAAEiB,MAAMG,IAAI,CAAC,CAAC,CAAC;YAE7C,OAAO;gBACLI,YAAY,CAAC,EAAExB,aAAa,EAAEiB,MAAMG,IAAI,CAAC,CAAC;gBAC1CjB;gBACAc;gBACAT;gBACAmB,OAAOiE;YACT;QACF;IACF;IAEA,MAAM,IAAIvG,SAAS,CAAC,8BAA8B,EAAE2B,UAAU,CAAC;AACjE,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/queries/operatorMap.ts"],"sourcesContent":["import {\n and,\n eq,\n gt,\n gte,\n ilike,\n inArray,\n isNotNull,\n isNull,\n lt,\n lte,\n ne,\n notInArray,\n or,\n} from 'drizzle-orm'\n\nexport const operatorMap = {\n // intersects: intersects,\n and,\n contains: ilike,\n equals: eq,\n exists: isNotNull,\n greater_than: gt,\n greater_than_equal: gte,\n in: inArray,\n isNull, // handles exists: false\n less_than: lt,\n less_than_equal: lte,\n like: ilike,\n not_equals: ne,\n // TODO: geojson queries\n // near: near,\n // within: within,\n // all: all,\n not_in: notInArray,\n or,\n}\n"],"names":["and","eq","gt","gte","ilike","inArray","isNotNull","isNull","lt","lte","ne","notInArray","or","operatorMap","contains","equals","exists","greater_than","greater_than_equal","in","less_than","less_than_equal","like","not_equals","not_in"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SACEA,GAAG,EACHC,EAAE,EACFC,EAAE,EACFC,GAAG,EACHC,KAAK,EACLC,OAAO,EACPC,SAAS,EACTC,MAAM,EACNC,EAAE,EACFC,GAAG,EACHC,EAAE,EACFC,UAAU,EACVC,EAAE,QACG,cAAa;AAEpB,OAAO,MAAMC,cAAc;IACzB,0BAA0B;IAC1Bb;IACAc,UAAUV;IACVW,QAAQd;IACRe,QAAQV;IACRW,cAAcf;IACdgB,oBAAoBf;IACpBgB,IAAId;IACJE;IACAa,WAAWZ;IACXa,iBAAiBZ;IACjBa,MAAMlB;IACNmB,YAAYb;IACZ,wBAAwB;IACxB,cAAc;IACd,kBAAkB;IAClB,YAAY;IACZc,QAAQb;IACRC;AACF,EAAC"}
1
+ {"version":3,"sources":["../../src/queries/operatorMap.ts"],"sourcesContent":["import {\n and,\n eq,\n gt,\n gte,\n ilike,\n inArray,\n isNotNull,\n isNull,\n lt,\n lte,\n ne,\n notInArray,\n or,\n} from 'drizzle-orm'\n\nexport const operatorMap = {\n // intersects: intersects,\n and,\n contains: ilike,\n equals: eq,\n exists: isNotNull,\n greater_than: gt,\n greater_than_equal: gte,\n in: inArray,\n isNull, // handles exists: false\n less_than: lt,\n less_than_equal: lte,\n like: ilike,\n not_equals: ne,\n // TODO: geojson queries\n // near: near,\n // within: within,\n // all: all,\n not_in: notInArray,\n or,\n}\n"],"names":["and","eq","gt","gte","ilike","inArray","isNotNull","isNull","lt","lte","ne","notInArray","or","operatorMap","contains","equals","exists","greater_than","greater_than_equal","in","less_than","less_than_equal","like","not_equals","not_in"],"mappings":"AAAA,SACEA,GAAG,EACHC,EAAE,EACFC,EAAE,EACFC,GAAG,EACHC,KAAK,EACLC,OAAO,EACPC,SAAS,EACTC,MAAM,EACNC,EAAE,EACFC,GAAG,EACHC,EAAE,EACFC,UAAU,EACVC,EAAE,QACG,cAAa;AAEpB,OAAO,MAAMC,cAAc;IACzB,0BAA0B;IAC1Bb;IACAc,UAAUV;IACVW,QAAQd;IACRe,QAAQV;IACRW,cAAcf;IACdgB,oBAAoBf;IACpBgB,IAAId;IACJE;IACAa,WAAWZ;IACXa,iBAAiBZ;IACjBa,MAAMlB;IACNmB,YAAYb;IACZ,wBAAwB;IACxB,cAAc;IACd,kBAAkB;IAClB,YAAY;IACZc,QAAQb;IACRC;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/queries/parseParams.ts"],"sourcesContent":["/* eslint-disable no-await-in-loop */\nimport type { SQL } from 'drizzle-orm'\nimport type { Field, Operator, Where } from 'payload'\n\nimport { and, ilike, isNotNull, isNull, ne, notInArray, or, sql } from 'drizzle-orm'\nimport { QueryError } from 'payload'\nimport { validOperators } from 'payload/shared'\n\nimport type { GenericColumn, PostgresAdapter } from '../types.js'\nimport type { BuildQueryJoinAliases } from './buildQuery.js'\n\nimport { buildAndOrConditions } from './buildAndOrConditions.js'\nimport { convertPathToJSONTraversal } from './createJSONQuery/convertPathToJSONTraversal.js'\nimport { createJSONQuery } from './createJSONQuery/index.js'\nimport { getTableColumnFromPath } from './getTableColumnFromPath.js'\nimport { operatorMap } from './operatorMap.js'\nimport { sanitizeQueryValue } from './sanitizeQueryValue.js'\n\ntype Args = {\n adapter: PostgresAdapter\n fields: Field[]\n joins: BuildQueryJoinAliases\n locale: string\n selectFields: Record<string, GenericColumn>\n tableName: string\n where: Where\n}\n\nexport async function parseParams({\n adapter,\n fields,\n joins,\n locale,\n selectFields,\n tableName,\n where,\n}: Args): Promise<SQL> {\n let result: SQL\n const constraints: SQL[] = []\n\n if (typeof where === 'object' && Object.keys(where).length > 0) {\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 if (relationOrPath) {\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 adapter,\n fields,\n joins,\n locale,\n selectFields,\n tableName,\n where: condition,\n })\n if (builtConditions.length > 0) {\n result = operatorMap[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 (let operator of Object.keys(pathOperators)) {\n if (validOperators.includes(operator as Operator)) {\n const val = where[relationOrPath][operator]\n const {\n columnName,\n constraints: queryConstraints,\n field,\n getNotNullColumnByValue,\n pathSegments,\n rawColumn,\n table,\n } = getTableColumnFromPath({\n adapter,\n collectionPath: relationOrPath,\n fields,\n joins,\n locale,\n pathSegments: relationOrPath.replace(/__/g, '.').split('.'),\n selectFields,\n tableName,\n value: val,\n })\n\n queryConstraints.forEach(({ columnName: col, table: constraintTable, value }) => {\n if (typeof value === 'string' && value.indexOf('%') > -1) {\n constraints.push(operatorMap.like(constraintTable[col], value))\n } else {\n constraints.push(operatorMap.equals(constraintTable[col], value))\n }\n })\n\n if (\n ['json', 'richText'].includes(field.type) &&\n Array.isArray(pathSegments) &&\n pathSegments.length > 1\n ) {\n const segments = pathSegments.slice(1)\n segments.unshift(table[columnName].name)\n\n if (field.type === 'richText') {\n const jsonQuery = createJSONQuery({\n operator,\n pathSegments: segments,\n treatAsArray: ['children'],\n treatRootAsArray: true,\n value: val,\n })\n\n constraints.push(sql.raw(jsonQuery))\n break\n }\n\n const jsonQuery = convertPathToJSONTraversal(pathSegments)\n const operatorKeys = {\n contains: { operator: 'ilike', wildcard: '%' },\n equals: { operator: '=', wildcard: '' },\n exists: { operator: val === true ? 'is not null' : 'is null' },\n like: { operator: 'like', wildcard: '%' },\n not_equals: { operator: '<>', wildcard: '' },\n }\n let formattedValue = `'${operatorKeys[operator].wildcard}${val}${operatorKeys[operator].wildcard}'`\n\n if (operator === 'exists') {\n formattedValue = ''\n }\n\n constraints.push(\n sql.raw(\n `${table[columnName].name}${jsonQuery} ${operatorKeys[operator].operator} ${formattedValue}`,\n ),\n )\n\n break\n }\n\n if (getNotNullColumnByValue) {\n const columnName = getNotNullColumnByValue(val)\n if (columnName) {\n constraints.push(isNotNull(table[columnName]))\n } else {\n throw new QueryError([{ path: relationOrPath }])\n }\n break\n }\n\n if (\n operator === 'like' &&\n (field.type === 'number' || table[columnName].columnType === 'PgUUID')\n ) {\n operator = 'equals'\n }\n\n if (operator === 'like') {\n constraints.push(\n and(...val.split(' ').map((word) => ilike(table[columnName], `%${word}%`))),\n )\n break\n }\n\n const sanitizedQueryValue = sanitizeQueryValue({\n adapter,\n field,\n operator,\n relationOrPath,\n val,\n })\n\n if (sanitizedQueryValue === null) {\n break\n }\n\n const { operator: queryOperator, value: queryValue } = sanitizedQueryValue\n\n if (queryOperator === 'not_equals' && queryValue !== null) {\n constraints.push(\n or(\n isNull(rawColumn || table[columnName]),\n /* eslint-disable @typescript-eslint/no-explicit-any */\n ne<any>(rawColumn || table[columnName], queryValue),\n ),\n )\n break\n }\n\n if (\n (field.type === 'relationship' || field.type === 'upload') &&\n Array.isArray(queryValue) &&\n operator === 'not_in'\n ) {\n constraints.push(\n sql`(${notInArray(table[columnName], queryValue)} OR\n ${table[columnName]}\n IS\n NULL)`,\n )\n\n break\n }\n\n if (operator === 'equals' && queryValue === null) {\n constraints.push(isNull(rawColumn || table[columnName]))\n break\n }\n\n if (operator === 'not_equals' && queryValue === null) {\n constraints.push(isNotNull(rawColumn || table[columnName]))\n break\n }\n\n constraints.push(\n operatorMap[queryOperator](rawColumn || table[columnName], queryValue),\n )\n }\n }\n }\n }\n }\n }\n }\n if (constraints.length > 0) {\n if (result) {\n result = and(result, ...constraints)\n } else {\n result = and(...constraints)\n }\n }\n if (constraints.length === 1 && !result) {\n ;[result] = constraints\n }\n\n return result\n}\n"],"names":["and","ilike","isNotNull","isNull","ne","notInArray","or","sql","QueryError","validOperators","buildAndOrConditions","convertPathToJSONTraversal","createJSONQuery","getTableColumnFromPath","operatorMap","sanitizeQueryValue","parseParams","adapter","fields","joins","locale","selectFields","tableName","where","result","constraints","Object","keys","length","relationOrPath","condition","conditionOperator","toLowerCase","Array","isArray","builtConditions","pathOperators","operator","includes","val","columnName","queryConstraints","field","getNotNullColumnByValue","pathSegments","rawColumn","table","collectionPath","replace","split","value","forEach","col","constraintTable","indexOf","push","like","equals","type","segments","slice","unshift","name","jsonQuery","treatAsArray","treatRootAsArray","raw","operatorKeys","contains","wildcard","exists","not_equals","formattedValue","path","columnType","map","word","sanitizedQueryValue","queryOperator","queryValue"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,mCAAmC,GAInC,SAASA,GAAG,EAAEC,KAAK,EAAEC,SAAS,EAAEC,MAAM,EAAEC,EAAE,EAAEC,UAAU,EAAEC,EAAE,EAAEC,GAAG,QAAQ,cAAa;AACpF,SAASC,UAAU,QAAQ,UAAS;AACpC,SAASC,cAAc,QAAQ,iBAAgB;AAK/C,SAASC,oBAAoB,QAAQ,4BAA2B;AAChE,SAASC,0BAA0B,QAAQ,kDAAiD;AAC5F,SAASC,eAAe,QAAQ,6BAA4B;AAC5D,SAASC,sBAAsB,QAAQ,8BAA6B;AACpE,SAASC,WAAW,QAAQ,mBAAkB;AAC9C,SAASC,kBAAkB,QAAQ,0BAAyB;AAY5D,OAAO,eAAeC,YAAY,EAChCC,OAAO,EACPC,MAAM,EACNC,KAAK,EACLC,MAAM,EACNC,YAAY,EACZC,SAAS,EACTC,KAAK,EACA;IACL,IAAIC;IACJ,MAAMC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,EAAEuC;oCAG5C;gCACF;gCAEA,IACE,AAACrC,CAAAA,MAAMgB,IAAI,KAAK,kBAAkBhB,MAAMgB,IAAI,KAAK,QAAO,KACxDzB,MAAMC,OAAO,CAAC6C,eACd1C,aAAa,UACb;oCACAZ,YAAY8B,IAAI,CACdhD,GAAG,CAAC,CAAC,EAAEF,WAAWyC,KAAK,CAACN,WAAW,EAAEuC,YAAY;oBACjD,EAAEjC,KAAK,CAACN,WAAW,CAAC;;yBAEf,CAAC;oCAGR;gCACF;gCAEA,IAAIH,aAAa,YAAY0C,eAAe,MAAM;oCAChDtD,YAAY8B,IAAI,CAACpD,OAAO0C,aAAaC,KAAK,CAACN,WAAW;oCACtD;gCACF;gCAEA,IAAIH,aAAa,gBAAgB0C,eAAe,MAAM;oCACpDtD,YAAY8B,IAAI,CAACrD,UAAU2C,aAAaC,KAAK,CAACN,WAAW;oCACzD;gCACF;gCAEAf,YAAY8B,IAAI,CACdzC,WAAW,CAACgE,cAAc,CAACjC,aAAaC,KAAK,CAACN,WAAW,EAAEuC;4BAE/D;wBACF;oBACF;gBACF;YACF;QACF;IACF;IACA,IAAItD,YAAYG,MAAM,GAAG,GAAG;QAC1B,IAAIJ,QAAQ;YACVA,SAASxB,IAAIwB,WAAWC;QAC1B,OAAO;YACLD,SAASxB,OAAOyB;QAClB;IACF;IACA,IAAIA,YAAYG,MAAM,KAAK,KAAK,CAACJ,QAAQ;QACtC,CAACA,OAAO,GAAGC;IACd;IAEA,OAAOD;AACT"}
1
+ {"version":3,"sources":["../../src/queries/parseParams.ts"],"sourcesContent":["/* eslint-disable no-await-in-loop */\nimport type { SQL } from 'drizzle-orm'\nimport type { Field, Operator, Where } from 'payload'\n\nimport { and, ilike, isNotNull, isNull, ne, notInArray, or, sql } from 'drizzle-orm'\nimport { QueryError } from 'payload'\nimport { validOperators } from 'payload/shared'\n\nimport type { GenericColumn, PostgresAdapter } from '../types.js'\nimport type { BuildQueryJoinAliases } from './buildQuery.js'\n\nimport { buildAndOrConditions } from './buildAndOrConditions.js'\nimport { convertPathToJSONTraversal } from './createJSONQuery/convertPathToJSONTraversal.js'\nimport { createJSONQuery } from './createJSONQuery/index.js'\nimport { getTableColumnFromPath } from './getTableColumnFromPath.js'\nimport { operatorMap } from './operatorMap.js'\nimport { sanitizeQueryValue } from './sanitizeQueryValue.js'\n\ntype Args = {\n adapter: PostgresAdapter\n fields: Field[]\n joins: BuildQueryJoinAliases\n locale: string\n selectFields: Record<string, GenericColumn>\n tableName: string\n where: Where\n}\n\nexport async function parseParams({\n adapter,\n fields,\n joins,\n locale,\n selectFields,\n tableName,\n where,\n}: Args): Promise<SQL> {\n let result: SQL\n const constraints: SQL[] = []\n\n if (typeof where === 'object' && Object.keys(where).length > 0) {\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 if (relationOrPath) {\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 adapter,\n fields,\n joins,\n locale,\n selectFields,\n tableName,\n where: condition,\n })\n if (builtConditions.length > 0) {\n result = operatorMap[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 (let operator of Object.keys(pathOperators)) {\n if (validOperators.includes(operator as Operator)) {\n const val = where[relationOrPath][operator]\n const {\n columnName,\n constraints: queryConstraints,\n field,\n getNotNullColumnByValue,\n pathSegments,\n rawColumn,\n table,\n } = getTableColumnFromPath({\n adapter,\n collectionPath: relationOrPath,\n fields,\n joins,\n locale,\n pathSegments: relationOrPath.replace(/__/g, '.').split('.'),\n selectFields,\n tableName,\n value: val,\n })\n\n queryConstraints.forEach(({ columnName: col, table: constraintTable, value }) => {\n if (typeof value === 'string' && value.indexOf('%') > -1) {\n constraints.push(operatorMap.like(constraintTable[col], value))\n } else {\n constraints.push(operatorMap.equals(constraintTable[col], value))\n }\n })\n\n if (\n ['json', 'richText'].includes(field.type) &&\n Array.isArray(pathSegments) &&\n pathSegments.length > 1\n ) {\n const segments = pathSegments.slice(1)\n segments.unshift(table[columnName].name)\n\n if (field.type === 'richText') {\n const jsonQuery = createJSONQuery({\n operator,\n pathSegments: segments,\n treatAsArray: ['children'],\n treatRootAsArray: true,\n value: val,\n })\n\n constraints.push(sql.raw(jsonQuery))\n break\n }\n\n const jsonQuery = convertPathToJSONTraversal(pathSegments)\n const operatorKeys = {\n contains: { operator: 'ilike', wildcard: '%' },\n equals: { operator: '=', wildcard: '' },\n exists: { operator: val === true ? 'is not null' : 'is null' },\n like: { operator: 'like', wildcard: '%' },\n not_equals: { operator: '<>', wildcard: '' },\n }\n let formattedValue = `'${operatorKeys[operator].wildcard}${val}${operatorKeys[operator].wildcard}'`\n\n if (operator === 'exists') {\n formattedValue = ''\n }\n\n constraints.push(\n sql.raw(\n `${table[columnName].name}${jsonQuery} ${operatorKeys[operator].operator} ${formattedValue}`,\n ),\n )\n\n break\n }\n\n if (getNotNullColumnByValue) {\n const columnName = getNotNullColumnByValue(val)\n if (columnName) {\n constraints.push(isNotNull(table[columnName]))\n } else {\n throw new QueryError([{ path: relationOrPath }])\n }\n break\n }\n\n if (\n operator === 'like' &&\n (field.type === 'number' || table[columnName].columnType === 'PgUUID')\n ) {\n operator = 'equals'\n }\n\n if (operator === 'like') {\n constraints.push(\n and(...val.split(' ').map((word) => ilike(table[columnName], `%${word}%`))),\n )\n break\n }\n\n const sanitizedQueryValue = sanitizeQueryValue({\n adapter,\n field,\n operator,\n relationOrPath,\n val,\n })\n\n if (sanitizedQueryValue === null) {\n break\n }\n\n const { operator: queryOperator, value: queryValue } = sanitizedQueryValue\n\n if (queryOperator === 'not_equals' && queryValue !== null) {\n constraints.push(\n or(\n isNull(rawColumn || table[columnName]),\n /* eslint-disable @typescript-eslint/no-explicit-any */\n ne<any>(rawColumn || table[columnName], queryValue),\n ),\n )\n break\n }\n\n if (\n (field.type === 'relationship' || field.type === 'upload') &&\n Array.isArray(queryValue) &&\n operator === 'not_in'\n ) {\n constraints.push(\n sql`(${notInArray(table[columnName], queryValue)} OR\n ${table[columnName]}\n IS\n NULL)`,\n )\n\n break\n }\n\n if (operator === 'equals' && queryValue === null) {\n constraints.push(isNull(rawColumn || table[columnName]))\n break\n }\n\n if (operator === 'not_equals' && queryValue === null) {\n constraints.push(isNotNull(rawColumn || table[columnName]))\n break\n }\n\n constraints.push(\n operatorMap[queryOperator](rawColumn || table[columnName], queryValue),\n )\n }\n }\n }\n }\n }\n }\n }\n if (constraints.length > 0) {\n if (result) {\n result = and(result, ...constraints)\n } else {\n result = and(...constraints)\n }\n }\n if (constraints.length === 1 && !result) {\n ;[result] = constraints\n }\n\n return result\n}\n"],"names":["and","ilike","isNotNull","isNull","ne","notInArray","or","sql","QueryError","validOperators","buildAndOrConditions","convertPathToJSONTraversal","createJSONQuery","getTableColumnFromPath","operatorMap","sanitizeQueryValue","parseParams","adapter","fields","joins","locale","selectFields","tableName","where","result","constraints","Object","keys","length","relationOrPath","condition","conditionOperator","toLowerCase","Array","isArray","builtConditions","pathOperators","operator","includes","val","columnName","queryConstraints","field","getNotNullColumnByValue","pathSegments","rawColumn","table","collectionPath","replace","split","value","forEach","col","constraintTable","indexOf","push","like","equals","type","segments","slice","unshift","name","jsonQuery","treatAsArray","treatRootAsArray","raw","operatorKeys","contains","wildcard","exists","not_equals","formattedValue","path","columnType","map","word","sanitizedQueryValue","queryOperator","queryValue"],"mappings":"AAAA,mCAAmC,GAInC,SAASA,GAAG,EAAEC,KAAK,EAAEC,SAAS,EAAEC,MAAM,EAAEC,EAAE,EAAEC,UAAU,EAAEC,EAAE,EAAEC,GAAG,QAAQ,cAAa;AACpF,SAASC,UAAU,QAAQ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AAIA,YAAYG,MAAM,KAAK,KAAK,CAACJ,QAAQ;QACtC,CAACA,OAAO,GAAGC;IACd;IAEA,OAAOD;AACT"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/queries/sanitizeQueryValue.ts"],"sourcesContent":["import { APIError, type Field, type TabAsField, createArrayFromCommaDelineated } from 'payload'\nimport { fieldAffectsData } from 'payload/shared'\n\nimport type { PostgresAdapter } from '../types.js'\n\ntype SanitizeQueryValueArgs = {\n adapter: PostgresAdapter\n field: Field | TabAsField\n operator: string\n relationOrPath: string\n val: any\n}\n\nexport const sanitizeQueryValue = ({\n adapter,\n field,\n operator: operatorArg,\n relationOrPath,\n val,\n}: SanitizeQueryValueArgs): { operator: string; value: unknown } => {\n let operator = operatorArg\n let formattedValue = val\n\n if (!fieldAffectsData(field)) return { operator, value: formattedValue }\n\n if (\n (field.type === 'relationship' || field.type === 'upload') &&\n !relationOrPath.endsWith('relationTo') &&\n Array.isArray(formattedValue)\n ) {\n const allPossibleIDTypes: (number | string)[] = []\n formattedValue.forEach((val) => {\n if (adapter.idType !== 'uuid' && typeof val === 'string') {\n allPossibleIDTypes.push(val, parseInt(val))\n } else if (typeof val === 'string') {\n allPossibleIDTypes.push(val)\n } else {\n allPossibleIDTypes.push(val, String(val))\n }\n })\n formattedValue = allPossibleIDTypes\n }\n\n // Cast incoming values as proper searchable types\n if (field.type === 'checkbox' && typeof val === 'string') {\n if (val.toLowerCase() === 'true') formattedValue = true\n if (val.toLowerCase() === 'false') formattedValue = false\n }\n\n if (['all', 'in', 'not_in'].includes(operator)) {\n if (typeof formattedValue === 'string') {\n formattedValue = createArrayFromCommaDelineated(formattedValue)\n\n if (field.type === 'number') {\n formattedValue = formattedValue.map((arrayVal) => parseFloat(arrayVal))\n }\n }\n\n if (!Array.isArray(formattedValue) || formattedValue.length === 0) {\n return null\n }\n }\n\n if (field.type === 'number' && typeof formattedValue === 'string') {\n formattedValue = Number(val)\n }\n\n if (field.type === 'date' && operator !== 'exists') {\n if (typeof val === 'string') {\n formattedValue = new Date(val)\n if (Number.isNaN(Date.parse(formattedValue))) {\n return { operator, value: undefined }\n }\n }\n\n if (typeof val === 'number') {\n formattedValue = new Date(val)\n }\n }\n\n if (['relationship', 'upload'].includes(field.type)) {\n if (val === 'null') {\n formattedValue = null\n }\n }\n\n if ('hasMany' in field && field.hasMany && operator === 'contains') {\n operator = 'equals'\n }\n\n if (operator === 'near' || operator === 'within' || operator === 'intersects') {\n throw new APIError(\n `Querying with '${operator}' is not supported with the postgres database adapter.`,\n )\n }\n\n if (operator === 'contains') {\n formattedValue = `%${formattedValue}%`\n }\n\n if (operator === 'exists') {\n formattedValue = formattedValue === 'true' || formattedValue === true\n if (formattedValue === false) {\n operator = 'isNull'\n }\n }\n\n return { operator, value: formattedValue }\n}\n"],"names":["APIError","createArrayFromCommaDelineated","fieldAffectsData","sanitizeQueryValue","adapter","field","operator","operatorArg","relationOrPath","val","formattedValue","value","type","endsWith","Array","isArray","allPossibleIDTypes","forEach","idType","push","parseInt","String","toLowerCase","includes","map","arrayVal","parseFloat","length","Number","Date","isNaN","parse","undefined","hasMany"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,QAAQ,EAA+BC,8BAA8B,QAAQ,UAAS;AAC/F,SAASC,gBAAgB,QAAQ,iBAAgB;AAYjD,OAAO,MAAMC,qBAAqB,CAAC,EACjCC,OAAO,EACPC,KAAK,EACLC,UAAUC,WAAW,EACrBC,cAAc,EACdC,GAAG,EACoB;IACvB,IAAIH,WAAWC;IACf,IAAIG,iBAAiBD;IAErB,IAAI,CAACP,iBAAiBG,QAAQ,OAAO;QAAEC;QAAUK,OAAOD;IAAe;IAEvE,IACE,AAACL,CAAAA,MAAMO,IAAI,KAAK,kBAAkBP,MAAMO,IAAI,KAAK,QAAO,KACxD,CAACJ,eAAeK,QAAQ,CA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3BC,iBAAiB,IAAImB,KAAKpB;QAC5B;IACF;IAEA,IAAI;QAAC;QAAgB;KAAS,CAACc,QAAQ,CAAClB,MAAMO,IAAI,GAAG;QACnD,IAAIH,QAAQ,QAAQ;YAClBC,iBAAiB;QACnB;IACF;IAEA,IAAI,aAAaL,SAASA,MAAM4B,OAAO,IAAI3B,aAAa,YAAY;QAClEA,WAAW;IACb;IAEA,IAAIA,aAAa,UAAUA,aAAa,YAAYA,aAAa,cAAc;QAC7E,MAAM,IAAIN,SACR,CAAC,eAAe,EAAEM,SAAS,sDAAsD,CAAC;IAEtF;IAEA,IAAIA,aAAa,YAAY;QAC3BI,iBAAiB,CAAC,CAAC,EAAEA,eAAe,CAAC,CAAC;IACxC;IAEA,IAAIJ,aAAa,UAAU;QACzBI,iBAAiBA,mBAAmB,UAAUA,mBAAmB;QACjE,IAAIA,mBAAmB,OAAO;YAC5BJ,WAAW;QACb;IACF;IAEA,OAAO;QAAEA;QAAUK,OAAOD;IAAe;AAC3C,EAAC"}
1
+ {"version":3,"sources":["../../src/queries/sanitizeQueryValue.ts"],"sourcesContent":["import { APIError, type Field, type TabAsField, createArrayFromCommaDelineated } from 'payload'\nimport { fieldAffectsData } from 'payload/shared'\n\nimport type { PostgresAdapter } from '../types.js'\n\ntype SanitizeQueryValueArgs = {\n adapter: PostgresAdapter\n field: Field | TabAsField\n operator: string\n relationOrPath: string\n val: any\n}\n\nexport const sanitizeQueryValue = ({\n adapter,\n field,\n operator: operatorArg,\n relationOrPath,\n val,\n}: SanitizeQueryValueArgs): { operator: string; value: unknown } => {\n let operator = operatorArg\n let formattedValue = val\n\n if (!fieldAffectsData(field)) return { operator, value: formattedValue }\n\n if (\n (field.type === 'relationship' || field.type === 'upload') &&\n !relationOrPath.endsWith('relationTo') &&\n Array.isArray(formattedValue)\n ) {\n const allPossibleIDTypes: (number | string)[] = []\n formattedValue.forEach((val) => {\n if (adapter.idType !== 'uuid' && typeof val === 'string') {\n allPossibleIDTypes.push(val, parseInt(val))\n } else if (typeof val === 'string') {\n allPossibleIDTypes.push(val)\n } else {\n allPossibleIDTypes.push(val, String(val))\n }\n })\n formattedValue = allPossibleIDTypes\n }\n\n // Cast incoming values as proper searchable types\n if (field.type === 'checkbox' && typeof val === 'string') {\n if (val.toLowerCase() === 'true') formattedValue = true\n if (val.toLowerCase() === 'false') formattedValue = false\n }\n\n if (['all', 'in', 'not_in'].includes(operator)) {\n if (typeof formattedValue === 'string') {\n formattedValue = createArrayFromCommaDelineated(formattedValue)\n\n if (field.type === 'number') {\n formattedValue = formattedValue.map((arrayVal) => parseFloat(arrayVal))\n }\n }\n\n if (!Array.isArray(formattedValue) || formattedValue.length === 0) {\n return null\n }\n }\n\n if (field.type === 'number' && typeof formattedValue === 'string') {\n formattedValue = Number(val)\n }\n\n if (field.type === 'date' && operator !== 'exists') {\n if (typeof val === 'string') {\n formattedValue = new Date(val)\n if (Number.isNaN(Date.parse(formattedValue))) {\n return { operator, value: undefined }\n }\n }\n\n if (typeof val === 'number') {\n formattedValue = new Date(val)\n }\n }\n\n if (['relationship', 'upload'].includes(field.type)) {\n if (val === 'null') {\n formattedValue = null\n }\n }\n\n if ('hasMany' in field && field.hasMany && operator === 'contains') {\n operator = 'equals'\n }\n\n if (operator === 'near' || operator === 'within' || operator === 'intersects') {\n throw new APIError(\n `Querying with '${operator}' is not supported with the postgres database adapter.`,\n )\n }\n\n if (operator === 'contains') {\n formattedValue = `%${formattedValue}%`\n }\n\n if (operator === 'exists') {\n formattedValue = formattedValue === 'true' || formattedValue === true\n if (formattedValue === false) {\n operator = 'isNull'\n }\n }\n\n return { operator, value: formattedValue }\n}\n"],"names":["APIError","createArrayFromCommaDelineated","fieldAffectsData","sanitizeQueryValue","adapter","field","operator","operatorArg","relationOrPath","val","formattedValue","value","type","endsWith","Array","isArray","allPossibleIDTypes","forEach","idType","push","parseInt","String","toLowerCase","includes","map","arrayVal","parseFloat","length","Number","Date","isNaN","parse","undefined","hasMany"],"mappings":"AAAA,SAASA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