payload 3.2.2 → 3.2.3-canary.3e78927

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/dist/admin/elements/DatePicker.d.ts +2 -2
  2. package/dist/admin/elements/DatePicker.d.ts.map +1 -1
  3. package/dist/admin/elements/DatePicker.js.map +1 -1
  4. package/dist/admin/types.js +3 -3
  5. package/dist/admin/types.js.map +1 -1
  6. package/dist/auth/cookies.js.map +1 -1
  7. package/dist/auth/crypto.js.map +1 -1
  8. package/dist/auth/extractJWT.js.map +1 -1
  9. package/dist/auth/operations/forgotPassword.js.map +1 -1
  10. package/dist/auth/operations/login.d.ts.map +1 -1
  11. package/dist/auth/operations/login.js +0 -12
  12. package/dist/auth/operations/login.js.map +1 -1
  13. package/dist/auth/operations/me.js.map +1 -1
  14. package/dist/auth/sendVerificationEmail.js.map +1 -1
  15. package/dist/auth/strategies/apiKey.js.map +1 -1
  16. package/dist/bin/generateImportMap/index.js.map +1 -1
  17. package/dist/bin/generateImportMap/parsePayloadComponent.js +1 -0
  18. package/dist/bin/generateImportMap/parsePayloadComponent.js.map +1 -1
  19. package/dist/bin/generateTypes.js.map +1 -1
  20. package/dist/bin/index.js.map +1 -1
  21. package/dist/bin/info.js.map +1 -1
  22. package/dist/bin/migrate.js.map +1 -1
  23. package/dist/collections/operations/findVersionByID.js +2 -0
  24. package/dist/collections/operations/findVersionByID.js.map +1 -1
  25. package/dist/collections/operations/findVersions.js +1 -0
  26. package/dist/collections/operations/findVersions.js.map +1 -1
  27. package/dist/config/client.js +2 -0
  28. package/dist/config/client.js.map +1 -1
  29. package/dist/config/defaults.js.map +1 -1
  30. package/dist/config/find.js.map +1 -1
  31. package/dist/config/sanitize.js.map +1 -1
  32. package/dist/database/getLocalizedPaths.js.map +1 -1
  33. package/dist/database/migrations/createMigration.js.map +1 -1
  34. package/dist/database/migrations/getPredefinedMigration.js.map +1 -1
  35. package/dist/database/migrations/migrate.js.map +1 -1
  36. package/dist/database/migrations/migrateDown.js.map +1 -1
  37. package/dist/database/migrations/migrateRefresh.js.map +1 -1
  38. package/dist/database/migrations/migrateReset.js.map +1 -1
  39. package/dist/database/migrations/readMigrationFiles.js.map +1 -1
  40. package/dist/database/migrations/writeMigrationIndex.js.map +1 -1
  41. package/dist/database/queryValidation/validateSearchParams.js.map +1 -1
  42. package/dist/email/sendEmail.js.map +1 -1
  43. package/dist/errors/AuthenticationError.js.map +1 -1
  44. package/dist/errors/FileRetrievalError.js.map +1 -1
  45. package/dist/errors/QueryError.js.map +1 -1
  46. package/dist/errors/ValidationError.js.map +1 -1
  47. package/dist/fields/config/client.js +1 -0
  48. package/dist/fields/config/client.js.map +1 -1
  49. package/dist/fields/config/sanitize.js +1 -1
  50. package/dist/fields/config/sanitize.js.map +1 -1
  51. package/dist/fields/config/sanitizeJoinField.js.map +1 -1
  52. package/dist/fields/config/types.d.ts +14 -0
  53. package/dist/fields/config/types.d.ts.map +1 -1
  54. package/dist/fields/config/types.js.map +1 -1
  55. package/dist/fields/getFieldPaths.js.map +1 -1
  56. package/dist/fields/hooks/afterRead/relationshipPopulationPromise.js +1 -0
  57. package/dist/fields/hooks/afterRead/relationshipPopulationPromise.js.map +1 -1
  58. package/dist/fields/hooks/beforeDuplicate/promise.js +1 -0
  59. package/dist/fields/hooks/beforeDuplicate/promise.js.map +1 -1
  60. package/dist/fields/hooks/beforeValidate/promise.js +1 -0
  61. package/dist/fields/hooks/beforeValidate/promise.js.map +1 -1
  62. package/dist/fields/mergeBaseFields.js +1 -0
  63. package/dist/fields/mergeBaseFields.js.map +1 -1
  64. package/dist/fields/setDefaultBeforeDuplicate.js.map +1 -1
  65. package/dist/fields/validations.d.ts +6 -2
  66. package/dist/fields/validations.d.ts.map +1 -1
  67. package/dist/fields/validations.js +5 -1
  68. package/dist/fields/validations.js.map +1 -1
  69. package/dist/globals/config/sanitize.js +1 -0
  70. package/dist/globals/config/sanitize.js.map +1 -1
  71. package/dist/globals/operations/findVersions.js +2 -0
  72. package/dist/globals/operations/findVersions.js.map +1 -1
  73. package/dist/index.d.ts +3 -1
  74. package/dist/index.d.ts.map +1 -1
  75. package/dist/index.js +2 -0
  76. package/dist/index.js.map +1 -1
  77. package/dist/preferences/deleteUserPreferences.js.map +1 -1
  78. package/dist/queues/config/generateJobsJSONSchemas.js.map +1 -1
  79. package/dist/queues/config/types/taskTypes.d.ts +23 -4
  80. package/dist/queues/config/types/taskTypes.d.ts.map +1 -1
  81. package/dist/queues/config/types/taskTypes.js.map +1 -1
  82. package/dist/queues/config/types/workflowJSONTypes.d.ts +5 -0
  83. package/dist/queues/config/types/workflowJSONTypes.d.ts.map +1 -1
  84. package/dist/queues/config/types/workflowJSONTypes.js.map +1 -1
  85. package/dist/queues/config/types/workflowTypes.d.ts +13 -5
  86. package/dist/queues/config/types/workflowTypes.d.ts.map +1 -1
  87. package/dist/queues/config/types/workflowTypes.js.map +1 -1
  88. package/dist/queues/operations/runJobs/index.d.ts.map +1 -1
  89. package/dist/queues/operations/runJobs/index.js +2 -1
  90. package/dist/queues/operations/runJobs/index.js.map +1 -1
  91. package/dist/queues/operations/runJobs/runJob/getRunTaskFunction.d.ts.map +1 -1
  92. package/dist/queues/operations/runJobs/runJob/getRunTaskFunction.js +18 -5
  93. package/dist/queues/operations/runJobs/runJob/getRunTaskFunction.js.map +1 -1
  94. package/dist/queues/operations/runJobs/runJob/handleWorkflowError.d.ts.map +1 -1
  95. package/dist/queues/operations/runJobs/runJob/handleWorkflowError.js +16 -16
  96. package/dist/queues/operations/runJobs/runJob/handleWorkflowError.js.map +1 -1
  97. package/dist/queues/operations/runJobs/runJob/importHandlerPath.d.ts.map +1 -1
  98. package/dist/queues/operations/runJobs/runJob/importHandlerPath.js +8 -1
  99. package/dist/queues/operations/runJobs/runJob/importHandlerPath.js.map +1 -1
  100. package/dist/queues/operations/runJobs/runJob/index.d.ts.map +1 -1
  101. package/dist/queues/operations/runJobs/runJob/index.js +6 -1
  102. package/dist/queues/operations/runJobs/runJob/index.js.map +1 -1
  103. package/dist/queues/utilities/getJobTaskStatus.d.ts.map +1 -1
  104. package/dist/queues/utilities/getJobTaskStatus.js +5 -0
  105. package/dist/queues/utilities/getJobTaskStatus.js.map +1 -1
  106. package/dist/uploads/deleteAssociatedFiles.js.map +1 -1
  107. package/dist/uploads/formatFilesize.js.map +1 -1
  108. package/dist/uploads/generateFileData.js.map +1 -1
  109. package/dist/uploads/getBaseFields.js.map +1 -1
  110. package/dist/uploads/getExternalFile.js.map +1 -1
  111. package/dist/uploads/getSafeFilename.js.map +1 -1
  112. package/dist/uploads/imageResizer.js.map +1 -1
  113. package/dist/utilities/addSelectGenericsToGeneretedTypes.js.map +1 -1
  114. package/dist/utilities/configToJSONSchema.js +1 -0
  115. package/dist/utilities/configToJSONSchema.js.map +1 -1
  116. package/dist/utilities/dependencies/dependencyChecker.js.map +1 -1
  117. package/dist/utilities/getDataByPath.js.map +1 -1
  118. package/dist/utilities/getSiblingData.js.map +1 -1
  119. package/dist/utilities/parseCookies.js.map +1 -1
  120. package/dist/utilities/sanitizePermissions.js +4 -0
  121. package/dist/utilities/sanitizePermissions.js.map +1 -1
  122. package/dist/utilities/telemetry/conf/envPaths.js.map +1 -1
  123. package/dist/utilities/telemetry/conf/index.js.map +1 -1
  124. package/dist/utilities/timestamp.js.map +1 -1
  125. package/dist/utilities/wordBoundariesRegex.js.map +1 -1
  126. package/dist/versions/drafts/appendVersionToQueryKey.js.map +1 -1
  127. package/dist/versions/drafts/getQueryDraftsSort.js.map +1 -1
  128. package/dist/versions/enforceMaxVersions.js.map +1 -1
  129. package/dist/versions/saveVersion.js +2 -0
  130. package/dist/versions/saveVersion.js.map +1 -1
  131. package/package.json +4 -4
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/database/migrations/migrateRefresh.ts"],"sourcesContent":["import type { PayloadRequest } from '../../types/index.js'\nimport type { BaseDatabaseAdapter } from '../types.js'\n\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { getMigrations } from './getMigrations.js'\nimport { readMigrationFiles } from './readMigrationFiles.js'\n\n/**\n * Run all migration down functions before running up\n */\nexport async function migrateRefresh(this: BaseDatabaseAdapter) {\n const { payload } = this\n const migrationFiles = await readMigrationFiles({ payload })\n\n const { existingMigrations } = await getMigrations({\n payload,\n })\n\n const req = { payload } as PayloadRequest\n\n if (existingMigrations?.length) {\n payload.logger.info({\n msg: `Rolling back all ${existingMigrations.length} migration(s).`,\n })\n // Reverse order of migrations to rollback\n existingMigrations.reverse()\n\n for (const migration of existingMigrations) {\n try {\n const migrationFile = migrationFiles.find((m) => m.name === migration.name)\n if (!migrationFile) {\n throw new Error(`Migration ${migration.name} not found locally.`)\n }\n\n payload.logger.info({ msg: `Migrating down: ${migration.name}` })\n const start = Date.now()\n await initTransaction(req)\n await migrationFile.down({ payload, req })\n payload.logger.info({\n msg: `Migrated down: ${migration.name} (${Date.now() - start}ms)`,\n })\n await payload.delete({\n collection: 'payload-migrations',\n req,\n where: {\n name: {\n equals: migration.name,\n },\n },\n })\n } catch (err: unknown) {\n await killTransaction(req)\n let msg = `Error running migration ${migration.name}. Rolling back.`\n if (err instanceof Error) {\n msg += ` ${err.message}`\n }\n payload.logger.error({\n err,\n msg,\n })\n process.exit(1)\n }\n }\n } else {\n payload.logger.info({ msg: 'No migrations to rollback.' })\n }\n\n // Run all migrate up\n for (const migration of migrationFiles) {\n payload.logger.info({ msg: `Migrating: ${migration.name}` })\n try {\n const start = Date.now()\n await initTransaction(req)\n await migration.up({ payload, req })\n await payload.create({\n collection: 'payload-migrations',\n data: {\n name: migration.name,\n executed: true,\n },\n req,\n })\n await commitTransaction(req)\n\n payload.logger.info({ msg: `Migrated: ${migration.name} (${Date.now() - start}ms)` })\n } catch (err: unknown) {\n await killTransaction(req)\n let msg = `Error running migration ${migration.name}. Rolling back.`\n if (err instanceof Error) {\n msg += ` ${err.message}`\n }\n payload.logger.error({\n err,\n msg,\n })\n process.exit(1)\n }\n }\n}\n"],"names":["commitTransaction","initTransaction","killTransaction","getMigrations","readMigrationFiles","migrateRefresh","payload","migrationFiles","existingMigrations","req","length","logger","info","msg","reverse","migration","migrationFile","find","m","name","Error","start","Date","now","down","delete","collection","where","equals","err","message","error","process","exit","up","create","data","executed"],"mappings":"AAGA,SAASA,iBAAiB,QAAQ,uCAAsC;AACxE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,kBAAkB,QAAQ,0BAAyB;AAE5D;;CAEC,GACD,OAAO,eAAeC;IACpB,MAAM,EAAEC,OAAO,EAAE,GAAG,IAAI;IACxB,MAAMC,iBAAiB,MAAMH,mBAAmB;QAAEE;IAAQ;IAE1D,MAAM,EAAEE,kBAAkB,EAAE,GAAG,MAAML,cAAc;QACjDG;IACF;IAEA,MAAMG,MAAM;QAAEH;IAAQ;IAEtB,IAAIE,oBAAoBE,QAAQ;QAC9BJ,QAAQK,MAAM,CAACC,IAAI,CAAC;YAClBC,KAAK,CAAC,iBAAiB,EAAEL,mBAAmBE,MAAM,CAAC,cAAc,CAAC;QACpE;QACA,0CAA0C;QAC1CF,mBAAmBM,OAAO;QAE1B,KAAK,MAAMC,aAAaP,mBAAoB;YAC1C,IAAI;gBACF,MAAMQ,gBAAgBT,eAAeU,IAAI,CAAC,CAACC,IAAMA,EAAEC,IAAI,KAAKJ,UAAUI,IAAI;gBAC1E,IAAI,CAACH,eAAe;oBAClB,MAAM,IAAII,MAAM,CAAC,UAAU,EAAEL,UAAUI,IAAI,CAAC,mBAAmB,CAAC;gBAClE;gBAEAb,QAAQK,MAAM,CAACC,IAAI,CAAC;oBAAEC,KAAK,CAAC,gBAAgB,EAAEE,UAAUI,IAAI,CAAC,CAAC;gBAAC;gBAC/D,MAAME,QAAQC,KAAKC,GAAG;gBACtB,MAAMt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AAC,WAAW,EAAEE,UAAUI,IAAI,CAAC,EAAE,EAAEG,KAAKC,GAAG,KAAKF,MAAM,GAAG,CAAC;YAAC;QACtF,EAAE,OAAOQ,KAAc;YACrB,MAAM3B,gBAAgBO;YACtB,IAAII,MAAM,CAAC,wBAAwB,EAAEE,UAAUI,IAAI,CAAC,eAAe,CAAC;YACpE,IAAIU,eAAeT,OAAO;gBACxBP,OAAO,CAAC,CAAC,EAAEgB,IAAIC,OAAO,CAAC,CAAC;YAC1B;YACAxB,QAAQK,MAAM,CAACoB,KAAK,CAAC;gBACnBF;gBACAhB;YACF;YACAmB,QAAQC,IAAI,CAAC;QACf;IACF;AACF"}
1
+ {"version":3,"sources":["../../../src/database/migrations/migrateRefresh.ts"],"sourcesContent":["import type { PayloadRequest } from '../../types/index.js'\nimport type { BaseDatabaseAdapter } from '../types.js'\n\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { getMigrations } from './getMigrations.js'\nimport { readMigrationFiles } from './readMigrationFiles.js'\n\n/**\n * Run all migration down functions before running up\n */\nexport async function migrateRefresh(this: BaseDatabaseAdapter) {\n const { payload } = this\n const migrationFiles = await readMigrationFiles({ payload })\n\n const { existingMigrations } = await getMigrations({\n payload,\n })\n\n const req = { payload } as PayloadRequest\n\n if (existingMigrations?.length) {\n payload.logger.info({\n msg: `Rolling back all ${existingMigrations.length} migration(s).`,\n })\n // Reverse order of migrations to rollback\n existingMigrations.reverse()\n\n for (const migration of existingMigrations) {\n try {\n const migrationFile = migrationFiles.find((m) => m.name === migration.name)\n if (!migrationFile) {\n throw new Error(`Migration ${migration.name} not found locally.`)\n }\n\n payload.logger.info({ msg: `Migrating down: ${migration.name}` })\n const start = Date.now()\n await initTransaction(req)\n await migrationFile.down({ payload, req })\n payload.logger.info({\n msg: `Migrated down: ${migration.name} (${Date.now() - start}ms)`,\n })\n await payload.delete({\n collection: 'payload-migrations',\n req,\n where: {\n name: {\n equals: migration.name,\n },\n },\n })\n } catch (err: unknown) {\n await killTransaction(req)\n let msg = `Error running migration ${migration.name}. Rolling back.`\n if (err instanceof Error) {\n msg += ` ${err.message}`\n }\n payload.logger.error({\n err,\n msg,\n })\n process.exit(1)\n }\n }\n } else {\n payload.logger.info({ msg: 'No migrations to rollback.' })\n }\n\n // Run all migrate up\n for (const migration of migrationFiles) {\n payload.logger.info({ msg: `Migrating: ${migration.name}` })\n try {\n const start = Date.now()\n await initTransaction(req)\n await migration.up({ payload, req })\n await payload.create({\n collection: 'payload-migrations',\n data: {\n name: migration.name,\n executed: true,\n },\n req,\n })\n await commitTransaction(req)\n\n payload.logger.info({ msg: `Migrated: ${migration.name} (${Date.now() - start}ms)` })\n } catch (err: unknown) {\n await killTransaction(req)\n let msg = `Error running migration ${migration.name}. Rolling back.`\n if (err instanceof Error) {\n msg += ` ${err.message}`\n }\n payload.logger.error({\n err,\n msg,\n })\n process.exit(1)\n }\n }\n}\n"],"names":["commitTransaction","initTransaction","killTransaction","getMigrations","readMigrationFiles","migrateRefresh","payload","migrationFiles","existingMigrations","req","length","logger","info","msg","reverse","migration","migrationFile","find","m","name","Error","start","Date","now","down","delete","collection","where","equals","err","message","error","process","exit","up","create","data","executed"],"mappings":"AAGA,SAASA,iBAAiB,QAAQ,uCAAsC;AACxE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,kBAAkB,QAAQ,0BAAyB;AAE5D;;CAEC,GACD,OAAO,eAAeC;IACpB,MAAM,EAAEC,OAAO,EAAE,GAAG,IAAI;IACxB,MAAMC,iBAAiB,MAAMH,mBAAmB;QAAEE;IAAQ;IAE1D,MAAM,EAAEE,kBAAkB,EAAE,GAAG,MAAML,cAAc;QACjDG;IACF;IAEA,MAAMG,MAAM;QAAEH;IAAQ;IAEtB,IAAIE,oBAAoBE,QAAQ;QA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;QACL3B,QAAQK,MAAM,CAACC,IAAI,CAAC;YAAEC,KAAK;QAA6B;IAC1D;IAEA,qBAAqB;IACrB,KAAK,MAAME,aAAaR,eAAgB;QACtCD,QAAQK,MAAM,CAACC,IAAI,CAAC;YAAEC,KAAK,CAAC,WAAW,EAAEE,UAAUI,IAAI,EAAE;QAAC;QAC1D,IAAI;YACF,MAAME,QAAQC,KAAKC,GAAG;YACtB,MAAMtB,gBAAgBQ;YACtB,MAAMM,UAAUmB,EAAE,CAAC;gBAAE5B;gBAASG;YAAI;YAClC,MAAMH,QAAQ6B,MAAM,CAAC;gBACnBT,YAAY;gBACZU,MAAM;oBACJjB,MAAMJ,UAAUI,IAAI;oBACpBkB,UAAU;gBACZ;gBACA5B;YACF;YACA,MAAMT,kBAAkBS;YAExBH,QAAQK,MAAM,CAACC,IAAI,CAAC;gBAAEC,KAAK,CAAC,WAAW,EAAEE,UAAUI,IAAI,CAAC,EAAE,EAAEG,KAAKC,GAAG,KAAKF,MAAM,GAAG,CAAC;YAAC;QACtF,EAAE,OAAOQ,KAAc;YACrB,MAAM3B,gBAAgBO;YACtB,IAAII,MAAM,CAAC,wBAAwB,EAAEE,UAAUI,IAAI,CAAC,eAAe,CAAC;YACpE,IAAIU,eAAeT,OAAO;gBACxBP,OAAO,CAAC,CAAC,EAAEgB,IAAIC,OAAO,EAAE;YAC1B;YACAxB,QAAQK,MAAM,CAACoB,KAAK,CAAC;gBACnBF;gBACAhB;YACF;YACAmB,QAAQC,IAAI,CAAC;QACf;IACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/database/migrations/migrateReset.ts"],"sourcesContent":["import type { PayloadRequest } from '../../types/index.js'\nimport type { BaseDatabaseAdapter } from '../types.js'\n\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { getMigrations } from './getMigrations.js'\nimport { readMigrationFiles } from './readMigrationFiles.js'\n\nexport async function migrateReset(this: BaseDatabaseAdapter): Promise<void> {\n const { payload } = this\n const migrationFiles = await readMigrationFiles({ payload })\n\n const { existingMigrations } = await getMigrations({ payload })\n\n if (!existingMigrations?.length) {\n payload.logger.info({ msg: 'No migrations to reset.' })\n return\n }\n\n const req = { payload } as PayloadRequest\n\n // Rollback all migrations in order\n for (const migration of migrationFiles) {\n // Create or update migration in database\n const existingMigration = existingMigrations.find(\n (existing) => existing.name === migration.name,\n )\n if (existingMigration) {\n payload.logger.info({ msg: `Migrating down: ${migration.name}` })\n try {\n const start = Date.now()\n await initTransaction(req)\n await migration.down({ payload, req })\n await payload.delete({\n collection: 'payload-migrations',\n req,\n where: {\n id: {\n equals: existingMigration.id,\n },\n },\n })\n await commitTransaction(req)\n payload.logger.info({ msg: `Migrated down: ${migration.name} (${Date.now() - start}ms)` })\n } catch (err: unknown) {\n await killTransaction(req)\n payload.logger.error({ err, msg: `Error running migration ${migration.name}` })\n throw err\n }\n }\n }\n\n // Delete dev migration\n try {\n await payload.delete({\n collection: 'payload-migrations',\n where: {\n batch: {\n equals: -1,\n },\n },\n })\n } catch (err: unknown) {\n payload.logger.error({ err, msg: 'Error deleting dev migration' })\n }\n}\n"],"names":["commitTransaction","initTransaction","killTransaction","getMigrations","readMigrationFiles","migrateReset","payload","migrationFiles","existingMigrations","length","logger","info","msg","req","migration","existingMigration","find","existing","name","start","Date","now","down","delete","collection","where","id","equals","err","error","batch"],"mappings":"AAGA,SAASA,iBAAiB,QAAQ,uCAAsC;AACxE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,kBAAkB,QAAQ,0BAAyB;AAE5D,OAAO,eAAeC;IACpB,MAAM,EAAEC,OAAO,EAAE,GAAG,IAAI;IACxB,MAAMC,iBAAiB,MAAMH,mBAAmB;QAAEE;IAAQ;IAE1D,MAAM,EAAEE,kBAAkB,EAAE,GAA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QACF;IACF,EAAE,OAAOC,KAAc;QACrBtB,QAAQI,MAAM,CAACmB,KAAK,CAAC;YAAED;YAAKhB,KAAK;QAA+B;IAClE;AACF"}
1
+ {"version":3,"sources":["../../../src/database/migrations/migrateReset.ts"],"sourcesContent":["import type { PayloadRequest } from '../../types/index.js'\nimport type { BaseDatabaseAdapter } from '../types.js'\n\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { getMigrations } from './getMigrations.js'\nimport { readMigrationFiles } from './readMigrationFiles.js'\n\nexport async function migrateReset(this: BaseDatabaseAdapter): Promise<void> {\n const { payload } = this\n const migrationFiles = await readMigrationFiles({ payload })\n\n const { existingMigrations } = await getMigrations({ payload })\n\n if (!existingMigrations?.length) {\n payload.logger.info({ msg: 'No migrations to reset.' })\n return\n }\n\n const req = { payload } as PayloadRequest\n\n // Rollback all migrations in order\n for (const migration of migrationFiles) {\n // Create or update migration in database\n const existingMigration = existingMigrations.find(\n (existing) => existing.name === migration.name,\n )\n if (existingMigration) {\n payload.logger.info({ msg: `Migrating down: ${migration.name}` })\n try {\n const start = Date.now()\n await initTransaction(req)\n await migration.down({ payload, req })\n await payload.delete({\n collection: 'payload-migrations',\n req,\n where: {\n id: {\n equals: existingMigration.id,\n },\n },\n })\n await commitTransaction(req)\n payload.logger.info({ msg: `Migrated down: ${migration.name} (${Date.now() - start}ms)` })\n } catch (err: unknown) {\n await killTransaction(req)\n payload.logger.error({ err, msg: `Error running migration ${migration.name}` })\n throw err\n }\n }\n }\n\n // Delete dev migration\n try {\n await payload.delete({\n collection: 'payload-migrations',\n where: {\n batch: {\n equals: -1,\n },\n },\n })\n } catch (err: unknown) {\n payload.logger.error({ err, msg: 'Error deleting dev migration' })\n }\n}\n"],"names":["commitTransaction","initTransaction","killTransaction","getMigrations","readMigrationFiles","migrateReset","payload","migrationFiles","existingMigrations","length","logger","info","msg","req","migration","existingMigration","find","existing","name","start","Date","now","down","delete","collection","where","id","equals","err","error","batch"],"mappings":"AAGA,SAASA,iBAAiB,QAAQ,uCAAsC;AACxE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,kBAAkB,QAAQ,0BAAyB;AAE5D,OAAO,eAAeC;IACpB,MAAM,EAAEC,OAAO,EAAE,GAAG,IAAI;IACxB,MAAMC,iBAAiB,MAAMH,mBAAmB;QAAEE;IAAQ;IAE1D,MAAM,EAAEE,kBAAkB,EAAE,GAAG,MAAML,cAAc;QAAEG;IAAQ;IAE7D,IAAI,CAACE,oBAAoBC,QAAQ;QAC/BH,QAAQI,MAAM,CAACC,IAAI,CAAC;YAAEC,KAAK;QAA0B;QACrD;IACF;IAEA,MAAMC,MAAM;QAAEP;IAAQ;IAEtB,mCAAmC;IACnC,KAAK,MAAMQ,aAAaP,eAAgB;QACtC,yCAAyC;QACzC,MAAMQ,oBAAoBP,mBAAmBQ,IAAI,CAC/C,CAACC,WAAaA,SAASC,IAAI,KAAKJ,UAAUI,IAAI;QAEhD,IAAIH,mBAAmB;YACrBT,QAAQI,MAAM,CAACC,IAAI,CAAC;gBAAEC,KAAK,CAAC,gBAAgB,EAAEE,UAAUI,IAAI,EAAE;YAAC;YAC/D,IAAI;gBACF,MAAMC,QAAQC,KAAKC,GAAG;gBACtB,MAAMpB,gBAAgBY;gBACtB,MAAMC,UAAUQ,IAAI,CAAC;oBAAEhB;oBAASO;gBAAI;gBACpC,MAAMP,QAAQiB,MAAM,CAAC;oBACnBC,YAAY;oBACZX;oBACAY,OAAO;wBACLC,IAAI;4BACFC,QAAQZ,kBAAkBW,EAAE;wBAC9B;oBACF;gBACF;gBACA,MAAM1B,kBAAkBa;gBACxBP,QAAQI,MAAM,CAACC,IAAI,CAAC;oBAAEC,KAAK,CAAC,gBAAgB,EAAEE,UAAUI,IAAI,CAAC,EAAE,EAAEE,KAAKC,GAAG,KAAKF,MAAM,GAAG,CAAC;gBAAC;YAC3F,EAAE,OAAOS,KAAc;gBACrB,MAAM1B,gBAAgBW;gBACtBP,QAAQI,MAAM,CAACmB,KAAK,CAAC;oBAAED;oBAAKhB,KAAK,CAAC,wBAAwB,EAAEE,UAAUI,IAAI,EAAE;gBAAC;gBAC7E,MAAMU;YACR;QACF;IACF;IAEA,uBAAuB;IACvB,IAAI;QACF,MAAMtB,QAAQiB,MAAM,CAAC;YACnBC,YAAY;YACZC,OAAO;gBACLK,OAAO;oBACLH,QAAQ,CAAC;gBACX;YACF;QACF;IACF,EAAE,OAAOC,KAAc;QACrBtB,QAAQI,MAAM,CAACmB,KAAK,CAAC;YAAED;YAAKhB,KAAK;QAA+B;IAClE;AACF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/database/migrations/readMigrationFiles.ts"],"sourcesContent":["import fs from 'fs'\nimport { pathToFileURL } from 'node:url'\nimport path from 'path'\n\nimport type { Payload } from '../../index.js'\nimport type { Migration } from '../types.js'\n\n/**\n * Read the migration files from disk\n */\nexport const readMigrationFiles = async ({\n payload,\n}: {\n payload: Payload\n}): Promise<Migration[]> => {\n if (!fs.existsSync(payload.db.migrationDir)) {\n payload.logger.error({\n msg: `No migration directory found at ${payload.db.migrationDir}`,\n })\n return []\n }\n\n payload.logger.info({\n msg: `Reading migration files from ${payload.db.migrationDir}`,\n })\n\n const files = fs\n .readdirSync(payload.db.migrationDir)\n .sort()\n .filter((f) => {\n return (f.endsWith('.ts') || f.endsWith('.js')) && !f.includes('index.')\n })\n .map((file) => {\n return path.resolve(payload.db.migrationDir, file)\n })\n\n return Promise.all(\n files.map(async (filePath) => {\n // eval used to circumvent errors bundling\n let migration =\n typeof require === 'function'\n ? await eval(`require('${filePath.replaceAll('\\\\', '/')}')`)\n : await eval(`import('${pathToFileURL(filePath).href}')`)\n if ('default' in migration) {\n migration = migration.default\n }\n\n const result: Migration = {\n name: path.basename(filePath).split('.')?.[0],\n down: migration.down,\n up: migration.up,\n }\n\n return result\n }),\n )\n}\n"],"names":["fs","pathToFileURL","path","readMigrationFiles","payload","existsSync","db","migrationDir","logger","error","msg","info","files","readdirSync","sort","filter","f","endsWith","includes","map","file","resolve","Promise","all","filePath","migration","require","eval","replaceAll","href","default","result","name","basename","split","down","up"],"mappings":"AAAA,OAAOA,QAAQ,KAAI;AACnB,SAASC,aAAa,QAAQ,WAAU;AACxC,OAAOC,UAAU,OAAM;AAKvB;;CAEC,GACD,OAAO,MAAMC,qBAAqB,OAAO,EACvCC,OAAO,EAGR;IACC,IAAI,CAACJ,GAAGK,UAAU,CAACD,QAAQE,EAAE,CAACC,YAAY,GAAG;QAC3CH,QAAQI,MAAM,CAACC,KAAK,CAAC;YACnBC,KAAK,CAAC,gCAAgC,EAAEN,QAAQE,EAAE,CAACC,YAAY,CAAC,CAAC;QACnE;QACA,OAAO,EAAE;IACX;IAEAH,QAAQI,MAAM,CAACG,IAAI,CAAC;QAClBD,KAAK,CAAC,6BAA6B,EAAEN,QAAQE,EAAE,CAACC,YAAY,CAAC,CAAC;IAChE;IAEA,MAAMK,QAAQZ,GACXa,WAAW,CAACT,QAAQE,EAAE,CAACC,YAAY,EACnCO,IAAI,GACJC,MAAM,CAAC,CAACC;QACP,OAAO,AAACA,CAAAA,EAAEC,QAAQ,CAAC,UAAUD,EAAEC,QAAQ,CAAC,MAAK,KAAM,CAACD,EAAEE,QAAQ,CAAC;IACjE,GACCC,GAAG,CAAC,CAACC;QACJ,OAAOlB,KAAKmB,OAAO,CAACjB,QAAQE,EAAE,CAACC,YAAY,EAAEa;IAC/C;IAEF,OAAOE,QAAQC,GAAG,CAChBX,MAAMO,GAAG,CAAC,OAAOK;QACf,0CAA0C;QAC1C,IAAIC,YACF,OAAOC,YAAY,aACf,MAAMC,KAAK,CAAC,SAAS,EAAEH,SAASI,UAAU,CAAC,MAAM,KAAK,EAAE,CAAC,IACzD,MAAMD,KAAK,CAAC,QAAQ,EAAE1B,cAAcuB,UAAUK,IAAI,CAAC,EAAE,CAAC;QAC5D,IAAI,aAAaJ,WAAW;YAC1BA,YAAYA,UAAUK,OAAO;QAC/B;QAEA,MAAMC,SAAoB;YACxBC,MAAM9B,KAAK+B,QAAQ,CAACT,UAAUU,KAAK,CAAC,MAAM,CAAC,EAAE;YAC7CC,MAAMV,UAAUU,IAAI;YACpBC,IAAIX,UAAUW,EAAE;QAClB;QAEA,OAAOL;IACT;AAEJ,EAAC"}
1
+ {"version":3,"sources":["../../../src/database/migrations/readMigrationFiles.ts"],"sourcesContent":["import fs from 'fs'\nimport { pathToFileURL } from 'node:url'\nimport path from 'path'\n\nimport type { Payload } from '../../index.js'\nimport type { Migration } from '../types.js'\n\n/**\n * Read the migration files from disk\n */\nexport const readMigrationFiles = async ({\n payload,\n}: {\n payload: Payload\n}): Promise<Migration[]> => {\n if (!fs.existsSync(payload.db.migrationDir)) {\n payload.logger.error({\n msg: `No migration directory found at ${payload.db.migrationDir}`,\n })\n return []\n }\n\n payload.logger.info({\n msg: `Reading migration files from ${payload.db.migrationDir}`,\n })\n\n const files = fs\n .readdirSync(payload.db.migrationDir)\n .sort()\n .filter((f) => {\n return (f.endsWith('.ts') || f.endsWith('.js')) && !f.includes('index.')\n })\n .map((file) => {\n return path.resolve(payload.db.migrationDir, file)\n })\n\n return Promise.all(\n files.map(async (filePath) => {\n // eval used to circumvent errors bundling\n let migration =\n typeof require === 'function'\n ? await eval(`require('${filePath.replaceAll('\\\\', '/')}')`)\n : await eval(`import('${pathToFileURL(filePath).href}')`)\n if ('default' in migration) {\n migration = migration.default\n }\n\n const result: Migration = {\n name: path.basename(filePath).split('.')?.[0],\n down: migration.down,\n up: migration.up,\n }\n\n return result\n }),\n )\n}\n"],"names":["fs","pathToFileURL","path","readMigrationFiles","payload","existsSync","db","migrationDir","logger","error","msg","info","files","readdirSync","sort","filter","f","endsWith","includes","map","file","resolve","Promise","all","filePath","migration","require","eval","replaceAll","href","default","result","name","basename","split","down","up"],"mappings":"AAAA,O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C,IAAIX,UAAUW,EAAE;QAClB;QAEA,OAAOL;IACT;AAEJ,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/database/migrations/writeMigrationIndex.ts"],"sourcesContent":["import fs from 'fs'\nimport { getTsconfig } from 'get-tsconfig'\nimport path from 'path'\n\n// Function to get all migration files (TS or JS) excluding 'index'\nconst getMigrationFiles = (dir: string) => {\n return fs\n .readdirSync(dir)\n .filter(\n (file) =>\n (file.endsWith('.ts') || file.endsWith('.js')) &&\n file !== 'index.ts' &&\n file !== 'index.js',\n )\n .sort()\n}\n\n// Function to generate the index.ts content\nconst generateIndexContent = (files: string[]) => {\n const tsconfig = getTsconfig()\n const importExt = tsconfig?.config?.compilerOptions?.moduleResolution === 'NodeNext' ? '.js' : ''\n\n let imports = ''\n let exportsArray = 'export const migrations = [\\n'\n\n files.forEach((file, index) => {\n const fileNameWithoutExt = file.replace(/\\.[^/.]+$/, '')\n imports += `import * as migration_${fileNameWithoutExt} from './${fileNameWithoutExt}${importExt}';\\n`\n exportsArray += ` {\n up: migration_${fileNameWithoutExt}.up,\n down: migration_${fileNameWithoutExt}.down,\n name: '${fileNameWithoutExt}'${index !== files.length - 1 ? ',' : ''}\\n },\\n`\n })\n\n exportsArray += '];\\n'\n return imports + '\\n' + exportsArray\n}\n\n// Main function to create the index.ts file\nexport const writeMigrationIndex = (args: { migrationsDir: string }) => {\n const migrationFiles = getMigrationFiles(args.migrationsDir)\n const indexContent = generateIndexContent(migrationFiles)\n\n fs.writeFileSync(path.join(args.migrationsDir, 'index.ts'), indexContent)\n}\n"],"names":["fs","getTsconfig","path","getMigrationFiles","dir","readdirSync","filter","file","endsWith","sort","generateIndexContent","files","tsconfig","importExt","config","compilerOptions","moduleResolution","imports","exportsArray","forEach","index","fileNameWithoutExt","replace","length","writeMigrationIndex","args","migrationFiles","migrationsDir","indexContent","writeFileSync","join"],"mappings":"AAAA,OAAOA,QAAQ,KAAI;AACnB,SAASC,WAAW,QAAQ,eAAc;AAC1C,OAAOC,UAAU,OAAM;AAEvB,mEAAmE;AACnE,MAAMC,oBAAoB,CAACC;IACzB,OAAOJ,GACJK,WAAW,CAACD,KACZE,MAAM,CACL,CAACC,OACC,AAACA,CAAAA,KAAKC,QAAQ,CAAC,UAAUD,KAAKC,QAAQ,CAAC,MAAK,KAC5CD,SAAS,cACTA,SAAS,YAEZE,IAAI;AACT;AAEA,4CAA4C;AAC5C,MAAMC,uBAAuB,CAACC;IAC5B,MAAMC,WAAWX;IACjB,MAAMY,YAAYD,UAAUE,QAAQC,iBAAiBC,qBAAqB,aAAa,QAAQ;IAE/F,IAAIC,UAAU;IACd,IAAIC,eAAe;IAEnBP,MAAMQ,OAAO,CAAC,CAACZ,MAAMa;QACnB,MAAMC,qBAAqBd,KAAKe,OAAO,CAAC,aAAa;QACrDL,WAAW,CAAC,sBAAsB,EAAEI,mBAAmB,SAAS,EAAEA,mBAAmB,EAAER,UAAU,IAAI,CAAC;QACtGK,gBAAgB,CAAC;kBACH,EAAEG,mBAAmB;oBACnB,EAAEA,mBAAmB;WAC9B,EAAEA,mBAAmB,CAAC,EAAED,UAAUT,MAAMY,MAAM,GAAG,IAAI,MAAM,GAAG,QAAQ,CAAC;IAChF;IAEAL,gBAAgB;IAChB,OAAOD,UAAU,OAAOC;AAC1B;AAEA,4CAA4C;AAC5C,OAAO,MAAMM,sBAAsB,CAACC;IAClC,MAAMC,iBAAiBvB,kBAAkBsB,KAAKE,aAAa;IAC3D,MAAMC,eAAelB,qBAAqBgB;IAE1C1B,GAAG6B,aAAa,CAAC3B,KAAK4B,IAAI,CAACL,KAAKE,aAAa,EAAE,aAAaC;AAC9D,EAAC"}
1
+ {"version":3,"sources":["../../../src/database/migrations/writeMigrationIndex.ts"],"sourcesContent":["import fs from 'fs'\nimport { getTsconfig } from 'get-tsconfig'\nimport path from 'path'\n\n// Function to get all migration files (TS or JS) excluding 'index'\nconst getMigrationFiles = (dir: string) => {\n return fs\n .readdirSync(dir)\n .filter(\n (file) =>\n (file.endsWith('.ts') || file.endsWith('.js')) &&\n file !== 'index.ts' &&\n file !== 'index.js',\n )\n .sort()\n}\n\n// Function to generate the index.ts content\nconst generateIndexContent = (files: string[]) => {\n const tsconfig = getTsconfig()\n const importExt = tsconfig?.config?.compilerOptions?.moduleResolution === 'NodeNext' ? '.js' : ''\n\n let imports = ''\n let exportsArray = 'export const migrations = [\\n'\n\n files.forEach((file, index) => {\n const fileNameWithoutExt = file.replace(/\\.[^/.]+$/, '')\n imports += `import * as migration_${fileNameWithoutExt} from './${fileNameWithoutExt}${importExt}';\\n`\n exportsArray += ` {\n up: migration_${fileNameWithoutExt}.up,\n down: migration_${fileNameWithoutExt}.down,\n name: '${fileNameWithoutExt}'${index !== files.length - 1 ? ',' : ''}\\n },\\n`\n })\n\n exportsArray += '];\\n'\n return imports + '\\n' + exportsArray\n}\n\n// Main function to create the index.ts file\nexport const writeMigrationIndex = (args: { migrationsDir: string }) => {\n const migrationFiles = getMigrationFiles(args.migrationsDir)\n const indexContent = generateIndexContent(migrationFiles)\n\n fs.writeFileSync(path.join(args.migrationsDir, 'index.ts'), indexContent)\n}\n"],"names":["fs","getTsconfig","path","getMigrationFiles","dir","readdirSync","filter","file","endsWith","sort","generateIndexContent","files","tsconfig","importExt","config","compilerOptions","moduleResolution","imports","exportsArray","forEach","index","fileNameWithoutExt","replace","length","writeMigrationIndex","args","migrationFiles","migrationsDir","indexContent","writeFileSync","join"],"mappings":"AAAA,OAAOA,QAAQ,KAAI;AACnB,SAASC,WAAW,QAAQ,eAAc;AAC1C,OAAOC,UAAU,OAAM;AAEvB,mEAAmE;AACnE,MAAMC,oBAAoB,CAACC;IACzB,OAAOJ,GACJK,WAAW,CAACD,KACZE,MAAM,CACL,CAACC,OACC,AAACA,CAAAA,KAAKC,QAAQ,CAAC,UAAUD,KAAKC,QAAQ,CAAC,MAAK,KAC5CD,SAAS,cACTA,SAAS,YAEZE,IAAI;AACT;AAEA,4CAA4C;AAC5C,MAAMC,uBAAuB,CAACC;IAC5B,MAAMC,WAAWX;IACjB,MAAMY,YAAYD,UAAUE,QAAQC,iBAAiBC,qBAAqB,aAAa,QAAQ;IAE/F,IAAIC,UAAU;IACd,IAAIC,eAAe;IAEnBP,MAAMQ,OAAO,CAAC,CAACZ,MAAMa;QACnB,MAAMC,qBAAqBd,KAAKe,OAAO,CAAC,aAAa;QACrDL,WAAW,CAAC,sBAAsB,EAAEI,mBAAmB,SAAS,EAAEA,qBAAqBR,UAAU,IAAI,CAAC;QACtGK,gBAAgB,CAAC;kBACH,EAAEG,mBAAmB;oBACnB,EAAEA,mBAAmB;WAC9B,EAAEA,mBAAmB,CAAC,EAAED,UAAUT,MAAMY,MAAM,GAAG,IAAI,MAAM,GAAG,QAAQ,CAAC;IAChF;IAEAL,gBAAgB;IAChB,OAAOD,UAAU,OAAOC;AAC1B;AAEA,4CAA4C;AAC5C,OAAO,MAAMM,sBAAsB,CAACC;IAClC,MAAMC,iBAAiBvB,kBAAkBsB,KAAKE,aAAa;IAC3D,MAAMC,eAAelB,qBAAqBgB;IAE1C1B,GAAG6B,aAAa,CAAC3B,KAAK4B,IAAI,CAACL,KAAKE,aAAa,EAAE,aAAaC;AAC9D,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/database/queryValidation/validateSearchParams.ts"],"sourcesContent":["import type { SanitizedCollectionConfig } from '../../collections/config/types.js'\nimport type { FlattenedField } from '../../fields/config/types.js'\nimport type { SanitizedGlobalConfig } from '../../globals/config/types.js'\nimport type { PayloadRequest } from '../../types/index.js'\nimport type { EntityPolicies, PathToQuery } from './types.js'\n\nimport { fieldAffectsData, fieldIsVirtual } from '../../fields/config/types.js'\nimport { getEntityPolicies } from '../../utilities/getEntityPolicies.js'\nimport isolateObjectProperty from '../../utilities/isolateObjectProperty.js'\nimport { getLocalizedPaths } from '../getLocalizedPaths.js'\nimport { validateQueryPaths } from './validateQueryPaths.js'\n\ntype Args = {\n collectionConfig?: SanitizedCollectionConfig\n errors: { path: string }[]\n fields: FlattenedField[]\n globalConfig?: SanitizedGlobalConfig\n operator: string\n overrideAccess: boolean\n path: string\n policies: EntityPolicies\n req: PayloadRequest\n val: unknown\n versionFields?: FlattenedField[]\n}\n\n/**\n * Validate the Payload key / value / operator\n */\nexport async function validateSearchParam({\n collectionConfig,\n errors,\n fields,\n globalConfig,\n operator,\n overrideAccess,\n path: incomingPath,\n policies,\n req,\n val,\n versionFields,\n}: Args): Promise<void> {\n // Replace GraphQL nested field double underscore formatting\n let sanitizedPath\n if (incomingPath === '_id') {\n sanitizedPath = 'id'\n } else {\n sanitizedPath = incomingPath.replace(/__/g, '.')\n }\n let paths: PathToQuery[] = []\n const { slug } = collectionConfig || globalConfig\n\n if (globalConfig && !policies.globals[slug]) {\n policies.globals[slug] = await getEntityPolicies({\n type: 'global',\n entity: globalConfig,\n operations: ['read'],\n req,\n })\n }\n\n if (sanitizedPath !== 'id') {\n paths = getLocalizedPaths({\n collectionSlug: collectionConfig?.slug,\n fields,\n globalSlug: globalConfig?.slug,\n incomingPath: sanitizedPath,\n locale: req.locale,\n overrideAccess,\n payload: req.payload,\n })\n }\n const promises = []\n\n // Sanitize relation.otherRelation.id to relation.otherRelation\n if (paths.at(-1)?.path === 'id') {\n const previousField = paths.at(-2)?.field\n if (\n previousField &&\n (previousField.type === 'relationship' || previousField.type === 'upload') &&\n typeof previousField.relationTo === 'string'\n ) {\n paths.pop()\n }\n }\n\n promises.push(\n ...paths.map(async ({ collectionSlug, field, invalid, path }, i) => {\n if (invalid) {\n errors.push({ path })\n return\n }\n\n if (fieldIsVirtual(field)) {\n errors.push({ path })\n }\n\n if (!overrideAccess && fieldAffectsData(field)) {\n if (collectionSlug) {\n if (!policies.collections[collectionSlug]) {\n policies.collections[collectionSlug] = await getEntityPolicies({\n type: 'collection',\n entity: req.payload.collections[collectionSlug].config,\n operations: ['read'],\n req: isolateObjectProperty(req, 'transactionID'),\n })\n }\n\n if (\n ['hash', 'salt'].includes(incomingPath) &&\n collectionConfig.auth &&\n !collectionConfig.auth?.disableLocalStrategy\n ) {\n errors.push({ path: incomingPath })\n }\n }\n let fieldPath = path\n // remove locale from end of path\n if (path.endsWith(`.${req.locale}`)) {\n fieldPath = path.slice(0, -(req.locale.length + 1))\n }\n // remove \".value\" from ends of polymorphic relationship paths\n if (\n (field.type === 'relationship' || field.type === 'upload') &&\n Array.isArray(field.relationTo)\n ) {\n fieldPath = fieldPath.replace('.value', '')\n }\n\n const entityType: 'collections' | 'globals' = globalConfig ? 'globals' : 'collections'\n const entitySlug = collectionSlug || globalConfig.slug\n const segments = fieldPath.split('.')\n\n let fieldAccess\n if (versionFields) {\n fieldAccess = policies[entityType][entitySlug]\n if (segments[0] === 'parent' || segments[0] === 'version') {\n segments.shift()\n }\n } else {\n fieldAccess = policies[entityType][entitySlug].fields\n }\n\n segments.forEach((segment) => {\n if (fieldAccess[segment]) {\n if ('fields' in fieldAccess[segment]) {\n fieldAccess = fieldAccess[segment].fields\n } else if ('blocks' in fieldAccess[segment]) {\n fieldAccess = fieldAccess[segment]\n } else {\n fieldAccess = fieldAccess[segment]\n }\n }\n })\n\n if (!fieldAccess?.read?.permission) {\n errors.push({ path: fieldPath })\n }\n }\n\n if (i > 1) {\n // Remove top collection and reverse array\n // to work backwards from top\n const pathsToQuery = paths.slice(1).reverse()\n\n pathsToQuery.forEach(\n ({ collectionSlug: pathCollectionSlug, path: subPath }, pathToQueryIndex) => {\n // On the \"deepest\" collection,\n // validate query of the relationship\n if (pathToQueryIndex === 0) {\n promises.push(\n validateQueryPaths({\n collectionConfig: req.payload.collections[pathCollectionSlug].config,\n errors,\n globalConfig: undefined,\n overrideAccess,\n policies,\n req,\n where: {\n [subPath]: {\n [operator]: val,\n },\n },\n }),\n )\n }\n },\n )\n }\n }),\n )\n await Promise.all(promises)\n}\n"],"names":["fieldAffectsData","fieldIsVirtual","getEntityPolicies","isolateObjectProperty","getLocalizedPaths","validateQueryPaths","validateSearchParam","collectionConfig","errors","fields","globalConfig","operator","overrideAccess","path","incomingPath","policies","req","val","versionFields","sanitizedPath","replace","paths","slug","globals","type","entity","operations","collectionSlug","globalSlug","locale","payload","promises","at","previousField","field","relationTo","pop","push","map","invalid","i","collections","config","includes","auth","disableLocalStrategy","fieldPath","endsWith","slice","length","Array","isArray","entityType","entitySlug","segments","split","fieldAccess","shift","forEach","segment","read","permission","pathsToQuery","reverse","pathCollectionSlug","subPath","pathToQueryIndex","undefined","where","Promise","all"],"mappings":"AAMA,SAASA,gBAAgB,EAAEC,cAAc,QAAQ,+BAA8B;AAC/E,SAASC,iBAAiB,QAAQ,uCAAsC;AACxE,OAAOC,2BAA2B,2CAA0C;AAC5E,SAASC,iBAAiB,QAAQ,0BAAyB;AAC3D,SAASC,kBAAkB,QAAQ,0BAAyB;AAgB5D;;CAEC,GACD,OAAO,eAAeC,oBAAoB,EACxCC,gBAAgB,EAChBC,MAAM,EACNC,MAAM,EACNC,YAAY,EACZC,QAAQ,EACRC,cAAc,EACdC,MAAMC,YAAY,EAClBC,QAAQ,EACRC,GAAG,EACHC,GAAG,EACHC,aAAa,EACR;IACL,4DAA4D;IAC5D,IAAIC;IACJ,IAAIL,iBAAiB,OAAO;QAC1BK,gBAAgB;IAClB,OAAO;QACLA,gBAAgBL,aAAaM,OAAO,CAAC,OAAO;IAC9C;IACA,IAAIC,QAAuB,EAAE;IAC7B,MAAM,EAAEC,IAAI,EAAE,GAAGf,oBAAoBG;IAErC,IAAIA,gBAAgB,CAACK,SAASQ,OAAO,CAACD,KAAK,EAAE;QAC3CP,SAASQ,OAAO,CAACD,KAAK,GAAG,MAAMpB,kBAAkB;YAC/CsB,MAAM;YACNC,QAAQf;YACRgB,YAAY;gBAAC;aAAO;YACpBV;QACF;IACF;IAEA,IAAIG,kBAAkB,MAAM;QAC1BE,QAAQjB,kBAAkB;YACxBuB,gBAAgBpB,kBAAkBe;YAClCb;YACAmB,YAAYlB,cAAcY;YAC1BR,cAAcK;YACdU,QAAQb,IAAIa,MAAM;YAClBjB;YACAkB,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AAC,GAAGe,OAAO;YAE3CD,aAAaJ,OAAO,CAClB,CAAC,EAAE/B,gBAAgBqC,kBAAkB,EAAEnD,MAAMoD,OAAO,EAAE,EAAEC;gBACtD,+BAA+B;gBAC/B,qCAAqC;gBACrC,IAAIA,qBAAqB,GAAG;oBAC1BnC,SAASM,IAAI,CACXhC,mBAAmB;wBACjBE,kBAAkBS,IAAIc,OAAO,CAACW,WAAW,CAACuB,mBAAmB,CAACtB,MAAM;wBACpElC;wBACAE,cAAcyD;wBACdvD;wBACAG;wBACAC;wBACAoD,OAAO;4BACL,CAACH,QAAQ,EAAE;gCACT,CAACtD,SAAS,EAAEM;4BACd;wBACF;oBACF;gBAEJ;YACF;QAEJ;IACF;IAEF,MAAMoD,QAAQC,GAAG,CAACvC;AACpB"}
1
+ {"version":3,"sources":["../../../src/database/queryValidation/validateSearchParams.ts"],"sourcesContent":["import type { SanitizedCollectionConfig } from '../../collections/config/types.js'\nimport type { FlattenedField } from '../../fields/config/types.js'\nimport type { SanitizedGlobalConfig } from '../../globals/config/types.js'\nimport type { PayloadRequest } from '../../types/index.js'\nimport type { EntityPolicies, PathToQuery } from './types.js'\n\nimport { fieldAffectsData, fieldIsVirtual } from '../../fields/config/types.js'\nimport { getEntityPolicies } from '../../utilities/getEntityPolicies.js'\nimport isolateObjectProperty from '../../utilities/isolateObjectProperty.js'\nimport { getLocalizedPaths } from '../getLocalizedPaths.js'\nimport { validateQueryPaths } from './validateQueryPaths.js'\n\ntype Args = {\n collectionConfig?: SanitizedCollectionConfig\n errors: { path: string }[]\n fields: FlattenedField[]\n globalConfig?: SanitizedGlobalConfig\n operator: string\n overrideAccess: boolean\n path: string\n policies: EntityPolicies\n req: PayloadRequest\n val: unknown\n versionFields?: FlattenedField[]\n}\n\n/**\n * Validate the Payload key / value / operator\n */\nexport async function validateSearchParam({\n collectionConfig,\n errors,\n fields,\n globalConfig,\n operator,\n overrideAccess,\n path: incomingPath,\n policies,\n req,\n val,\n versionFields,\n}: Args): Promise<void> {\n // Replace GraphQL nested field double underscore formatting\n let sanitizedPath\n if (incomingPath === '_id') {\n sanitizedPath = 'id'\n } else {\n sanitizedPath = incomingPath.replace(/__/g, '.')\n }\n let paths: PathToQuery[] = []\n const { slug } = collectionConfig || globalConfig\n\n if (globalConfig && !policies.globals[slug]) {\n policies.globals[slug] = await getEntityPolicies({\n type: 'global',\n entity: globalConfig,\n operations: ['read'],\n req,\n })\n }\n\n if (sanitizedPath !== 'id') {\n paths = getLocalizedPaths({\n collectionSlug: collectionConfig?.slug,\n fields,\n globalSlug: globalConfig?.slug,\n incomingPath: sanitizedPath,\n locale: req.locale,\n overrideAccess,\n payload: req.payload,\n })\n }\n const promises = []\n\n // Sanitize relation.otherRelation.id to relation.otherRelation\n if (paths.at(-1)?.path === 'id') {\n const previousField = paths.at(-2)?.field\n if (\n previousField &&\n (previousField.type === 'relationship' || previousField.type === 'upload') &&\n typeof previousField.relationTo === 'string'\n ) {\n paths.pop()\n }\n }\n\n promises.push(\n ...paths.map(async ({ collectionSlug, field, invalid, path }, i) => {\n if (invalid) {\n errors.push({ path })\n return\n }\n\n if (fieldIsVirtual(field)) {\n errors.push({ path })\n }\n\n if (!overrideAccess && fieldAffectsData(field)) {\n if (collectionSlug) {\n if (!policies.collections[collectionSlug]) {\n policies.collections[collectionSlug] = await getEntityPolicies({\n type: 'collection',\n entity: req.payload.collections[collectionSlug].config,\n operations: ['read'],\n req: isolateObjectProperty(req, 'transactionID'),\n })\n }\n\n if (\n ['hash', 'salt'].includes(incomingPath) &&\n collectionConfig.auth &&\n !collectionConfig.auth?.disableLocalStrategy\n ) {\n errors.push({ path: incomingPath })\n }\n }\n let fieldPath = path\n // remove locale from end of path\n if (path.endsWith(`.${req.locale}`)) {\n fieldPath = path.slice(0, -(req.locale.length + 1))\n }\n // remove \".value\" from ends of polymorphic relationship paths\n if (\n (field.type === 'relationship' || field.type === 'upload') &&\n Array.isArray(field.relationTo)\n ) {\n fieldPath = fieldPath.replace('.value', '')\n }\n\n const entityType: 'collections' | 'globals' = globalConfig ? 'globals' : 'collections'\n const entitySlug = collectionSlug || globalConfig.slug\n const segments = fieldPath.split('.')\n\n let fieldAccess\n if (versionFields) {\n fieldAccess = policies[entityType][entitySlug]\n if (segments[0] === 'parent' || segments[0] === 'version') {\n segments.shift()\n }\n } else {\n fieldAccess = policies[entityType][entitySlug].fields\n }\n\n segments.forEach((segment) => {\n if (fieldAccess[segment]) {\n if ('fields' in fieldAccess[segment]) {\n fieldAccess = fieldAccess[segment].fields\n } else if ('blocks' in fieldAccess[segment]) {\n fieldAccess = fieldAccess[segment]\n } else {\n fieldAccess = fieldAccess[segment]\n }\n }\n })\n\n if (!fieldAccess?.read?.permission) {\n errors.push({ path: fieldPath })\n }\n }\n\n if (i > 1) {\n // Remove top collection and reverse array\n // to work backwards from top\n const pathsToQuery = paths.slice(1).reverse()\n\n pathsToQuery.forEach(\n ({ collectionSlug: pathCollectionSlug, path: subPath }, pathToQueryIndex) => {\n // On the \"deepest\" collection,\n // validate query of the relationship\n if (pathToQueryIndex === 0) {\n promises.push(\n validateQueryPaths({\n collectionConfig: req.payload.collections[pathCollectionSlug].config,\n errors,\n globalConfig: undefined,\n overrideAccess,\n policies,\n req,\n where: {\n [subPath]: {\n [operator]: val,\n },\n },\n }),\n )\n }\n },\n )\n }\n }),\n )\n await Promise.all(promises)\n}\n"],"names":["fieldAffectsData","fieldIsVirtual","getEntityPolicies","isolateObjectProperty","getLocalizedPaths","validateQueryPaths","validateSearchParam","collectionConfig","errors","fields","globalConfig","operator","overrideAccess","path","incomingPath","policies","req","val","versionFields","sanitizedPath","replace","paths","slug","globals","type","entity","operations","collectionSlug","globalSlug","locale","payload","promises","at","previousField","field","relationTo","pop","push","map","invalid","i","collections","config","includes","auth","disableLocalStrategy","fieldPath","endsWith","slice","length","Array","isArray","entityType","entitySlug","segments","split","fieldAccess","shift","forEach","segment","read","permission","pathsToQuery","reverse","pathCollectionSlug","subPath","pathToQueryIndex","undefined","where","Promise","all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ACtB,MAAM;wBACpElC;wBACAE,cAAcyD;wBACdvD;wBACAG;wBACAC;wBACAoD,OAAO;4BACL,CAACH,QAAQ,EAAE;gCACT,CAACtD,SAAS,EAAEM;4BACd;wBACF;oBACF;gBAEJ;YACF;QAEJ;IACF;IAEF,MAAMoD,QAAQC,GAAG,CAACvC;AACpB"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/email/sendEmail.ts"],"sourcesContent":["import type { Payload } from '../types/index.js'\nimport type { SendEmailOptions } from './types.js'\n\nimport { getStringifiedToAddress } from './getStringifiedToAddress.js'\n\nexport async function sendEmail(this: Payload, message: SendEmailOptions): Promise<unknown> {\n let result\n\n try {\n result = await this.email.sendEmail(message)\n } catch (err: unknown) {\n const stringifiedTo = getStringifiedToAddress(message)\n\n this.logger.error({\n err,\n msg: `Failed to send mail to ${stringifiedTo}, subject: ${message.subject ?? 'No Subject'}`,\n })\n return err\n }\n\n return result\n}\n"],"names":["getStringifiedToAddress","sendEmail","message","result","email","err","stringifiedTo","logger","error","msg","subject"],"mappings":"AAGA,SAASA,uBAAuB,QAAQ,+BAA8B;AAEtE,OAAO,eAAeC,UAAyBC,OAAyB;IACtE,IAAIC;IAEJ,IAAI;QACFA,SAAS,MAAM,IAAI,CAACC,KAAK,CAACH,SAAS,CAACC;IACtC,EAAE,OAAOG,KAAc;QACrB,MAAMC,gBAAgBN,wBAAwBE;QAE9C,IAAI,CAACK,MAAM,CAACC,KAAK,CAAC;YAChBH;YACAI,KAAK,CAAC,uBAAuB,EAAEH,cAAc,WAAW,EAAEJ,QAAQQ,OAAO,IAAI,aAAa,CAAC;QAC7F;QACA,OAAOL;IACT;IAEA,OAAOF;AACT"}
1
+ {"version":3,"sources":["../../src/email/sendEmail.ts"],"sourcesContent":["import type { Payload } from '../types/index.js'\nimport type { SendEmailOptions } from './types.js'\n\nimport { getStringifiedToAddress } from './getStringifiedToAddress.js'\n\nexport async function sendEmail(this: Payload, message: SendEmailOptions): Promise<unknown> {\n let result\n\n try {\n result = await this.email.sendEmail(message)\n } catch (err: unknown) {\n const stringifiedTo = getStringifiedToAddress(message)\n\n this.logger.error({\n err,\n msg: `Failed to send mail to ${stringifiedTo}, subject: ${message.subject ?? 'No Subject'}`,\n })\n return err\n }\n\n return result\n}\n"],"names":["getStringifiedToAddress","sendEmail","message","result","email","err","stringifiedTo","logger","error","msg","subject"],"mappings":"AAGA,SAASA,uBAAuB,QAAQ,+BAA8B;AAEtE,OAAO,eAAeC,UAAyBC,OAAyB;IACtE,IAAIC;IAEJ,IAAI;QACFA,SAAS,MAAM,IAAI,CAACC,KAAK,CAACH,SAAS,CAACC;IACtC,EAAE,OAAOG,KAAc;QACrB,MAAMC,gBAAgBN,wBAAwBE;QAE9C,IAAI,CAACK,MAAM,CAACC,KAAK,CAAC;YAChBH;YACAI,KAAK,CAAC,uBAAuB,EAAEH,cAAc,WAAW,EAAEJ,QAAQQ,OAAO,IAAI,cAAc;QAC7F;QACA,OAAOL;IACT;IAEA,OAAOF;AACT"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/errors/AuthenticationError.ts"],"sourcesContent":["import type { TFunction } from '@payloadcms/translations'\n\nimport { en } from '@payloadcms/translations/languages/en'\nimport httpStatus from 'http-status'\n\nimport { APIError } from './APIError.js'\n\nexport class AuthenticationError extends APIError {\n constructor(t?: TFunction, loginWithUsername?: boolean) {\n super(\n t\n ? `${loginWithUsername ? t('error:usernameOrPasswordIncorrect') : t('error:emailOrPasswordIncorrect')}`\n : en.translations.error.emailOrPasswordIncorrect,\n httpStatus.UNAUTHORIZED,\n )\n }\n}\n"],"names":["en","httpStatus","APIError","AuthenticationError","constructor","t","loginWithUsername","translations","error","emailOrPasswordIncorrect","UNAUTHORIZED"],"mappings":"AAEA,SAASA,EAAE,QAAQ,wCAAuC;AAC1D,OAAOC,gBAAgB,cAAa;AAEpC,SAASC,QAAQ,QAAQ,gBAAe;AAExC,OAAO,MAAMC,4BAA4BD;IACvCE,YAAYC,CAAa,EAAEC,iBAA2B,CAAE;QACtD,KAAK,CACHD,IACI,CAAC,EAAEC,oBAAoBD,EAAE,uCAAuCA,EAAE,kCAAkC,CAAC,GACrGL,GAAGO,YAAY,CAACC,KAAK,CAACC,wBAAwB,EAClDR,WAAWS,YAAY;IAE3B;AACF"}
1
+ {"version":3,"sources":["../../src/errors/AuthenticationError.ts"],"sourcesContent":["import type { TFunction } from '@payloadcms/translations'\n\nimport { en } from '@payloadcms/translations/languages/en'\nimport httpStatus from 'http-status'\n\nimport { APIError } from './APIError.js'\n\nexport class AuthenticationError extends APIError {\n constructor(t?: TFunction, loginWithUsername?: boolean) {\n super(\n t\n ? `${loginWithUsername ? t('error:usernameOrPasswordIncorrect') : t('error:emailOrPasswordIncorrect')}`\n : en.translations.error.emailOrPasswordIncorrect,\n httpStatus.UNAUTHORIZED,\n )\n }\n}\n"],"names":["en","httpStatus","APIError","AuthenticationError","constructor","t","loginWithUsername","translations","error","emailOrPasswordIncorrect","UNAUTHORIZED"],"mappings":"AAEA,SAASA,EAAE,QAAQ,wCAAuC;AAC1D,OAAOC,gBAAgB,cAAa;AAEpC,SAASC,QAAQ,QAAQ,gBAAe;AAExC,OAAO,MAAMC,4BAA4BD;IACvCE,YAAYC,CAAa,EAAEC,iBAA2B,CAAE;QACtD,KAAK,CACHD,IACI,GAAGC,oBAAoBD,EAAE,uCAAuCA,EAAE,mCAAmC,GACrGL,GAAGO,YAAY,CAACC,KAAK,CAACC,wBAAwB,EAClDR,WAAWS,YAAY;IAE3B;AACF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/errors/FileRetrievalError.ts"],"sourcesContent":["import type { TFunction } from '@payloadcms/translations'\n\nimport httpStatus from 'http-status'\n\nimport { APIError } from './APIError.js'\n\nexport class FileRetrievalError extends APIError {\n constructor(t?: TFunction, message?: string) {\n let msg = t ? t('error:problemUploadingFile') : 'There was a problem while retrieving the file.'\n\n if (message) {\n msg += ` ${message}`\n }\n super(msg, httpStatus.INTERNAL_SERVER_ERROR)\n }\n}\n"],"names":["httpStatus","APIError","FileRetrievalError","constructor","t","message","msg","INTERNAL_SERVER_ERROR"],"mappings":"AAEA,OAAOA,gBAAgB,cAAa;AAEpC,SAASC,QAAQ,QAAQ,gBAAe;AAExC,OAAO,MAAMC,2BAA2BD;IACtCE,YAAYC,CAAa,EAAEC,OAAgB,CAAE;QAC3C,IAAIC,MAAMF,IAAIA,EAAE,gCAAgC;QAEhD,IAAIC,SAAS;YACXC,OAAO,CAAC,CAAC,EAAED,QAAQ,CAAC;QACtB;QACA,KAAK,CAACC,KAAKN,WAAWO,qBAAqB;IAC7C;AACF"}
1
+ {"version":3,"sources":["../../src/errors/FileRetrievalError.ts"],"sourcesContent":["import type { TFunction } from '@payloadcms/translations'\n\nimport httpStatus from 'http-status'\n\nimport { APIError } from './APIError.js'\n\nexport class FileRetrievalError extends APIError {\n constructor(t?: TFunction, message?: string) {\n let msg = t ? t('error:problemUploadingFile') : 'There was a problem while retrieving the file.'\n\n if (message) {\n msg += ` ${message}`\n }\n super(msg, httpStatus.INTERNAL_SERVER_ERROR)\n }\n}\n"],"names":["httpStatus","APIError","FileRetrievalError","constructor","t","message","msg","INTERNAL_SERVER_ERROR"],"mappings":"AAEA,OAAOA,gBAAgB,cAAa;AAEpC,SAASC,QAAQ,QAAQ,gBAAe;AAExC,OAAO,MAAMC,2BAA2BD;IACtCE,YAAYC,CAAa,EAAEC,OAAgB,CAAE;QAC3C,IAAIC,MAAMF,IAAIA,EAAE,gCAAgC;QAEhD,IAAIC,SAAS;YACXC,OAAO,CAAC,CAAC,EAAED,SAAS;QACtB;QACA,KAAK,CAACC,KAAKN,WAAWO,qBAAqB;IAC7C;AACF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/errors/QueryError.ts"],"sourcesContent":["import httpStatus from 'http-status'\n\nimport { APIError } from './APIError.js'\n\nexport class QueryError extends APIError<{ path: string }[]> {\n constructor(results: { path: string }[]) {\n const message = `The following path${results.length === 1 ? '' : 's'} cannot be queried:`\n\n super(\n `${message} ${results.map((err) => err.path).join(', ')}`,\n httpStatus.BAD_REQUEST,\n results,\n )\n }\n}\n"],"names":["httpStatus","APIError","QueryError","constructor","results","message","length","map","err","path","join","BAD_REQUEST"],"mappings":"AAAA,OAAOA,gBAAgB,cAAa;AAEpC,SAASC,QAAQ,QAAQ,gBAAe;AAExC,OAAO,MAAMC,mBAAmBD;IAC9BE,YAAYC,OAA2B,CAAE;QACvC,MAAMC,UAAU,CAAC,kBAAkB,EAAED,QAAQE,MAAM,KAAK,IAAI,KAAK,IAAI,mBAAmB,CAAC;QAEzF,KAAK,CACH,CAAC,EAAED,QAAQ,CAAC,EAAED,QAAQG,GAAG,CAAC,CAACC,MAAQA,IAAIC,IAAI,EAAEC,IAAI,CAAC,MAAM,CAAC,EACzDV,WAAWW,WAAW,EACtBP;IAEJ;AACF"}
1
+ {"version":3,"sources":["../../src/errors/QueryError.ts"],"sourcesContent":["import httpStatus from 'http-status'\n\nimport { APIError } from './APIError.js'\n\nexport class QueryError extends APIError<{ path: string }[]> {\n constructor(results: { path: string }[]) {\n const message = `The following path${results.length === 1 ? '' : 's'} cannot be queried:`\n\n super(\n `${message} ${results.map((err) => err.path).join(', ')}`,\n httpStatus.BAD_REQUEST,\n results,\n )\n }\n}\n"],"names":["httpStatus","APIError","QueryError","constructor","results","message","length","map","err","path","join","BAD_REQUEST"],"mappings":"AAAA,OAAOA,gBAAgB,cAAa;AAEpC,SAASC,QAAQ,QAAQ,gBAAe;AAExC,OAAO,MAAMC,mBAAmBD;IAC9BE,YAAYC,OAA2B,CAAE;QACvC,MAAMC,UAAU,CAAC,kBAAkB,EAAED,QAAQE,MAAM,KAAK,IAAI,KAAK,IAAI,mBAAmB,CAAC;QAEzF,KAAK,CACH,GAAGD,QAAQ,CAAC,EAAED,QAAQG,GAAG,CAAC,CAACC,MAAQA,IAAIC,IAAI,EAAEC,IAAI,CAAC,OAAO,EACzDV,WAAWW,WAAW,EACtBP;IAEJ;AACF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/errors/ValidationError.ts"],"sourcesContent":["import type { TFunction } from '@payloadcms/translations'\n\nimport { en } from '@payloadcms/translations/languages/en'\nimport httpStatus from 'http-status'\n\nimport { APIError } from './APIError.js'\n\n// This gets dynamically reassigned during compilation\nexport let ValidationErrorName = 'ValidationError'\n\nexport type ValidationFieldError = {\n // The error message to display for this field\n message: string\n path: string\n}\n\nexport class ValidationError extends APIError<{\n collection?: string\n errors: ValidationFieldError[]\n global?: string\n}> {\n constructor(\n results: {\n collection?: string\n errors: ValidationFieldError[]\n global?: string\n id?: number | string\n },\n t?: TFunction,\n ) {\n const message = t\n ? t('error:followingFieldsInvalid', { count: results.errors.length })\n : results.errors.length === 1\n ? en.translations.error.followingFieldsInvalid_one\n : en.translations.error.followingFieldsInvalid_other\n\n super(\n `${message} ${results.errors.map((f) => f.path).join(', ')}`,\n httpStatus.BAD_REQUEST,\n results,\n )\n\n ValidationErrorName = this.constructor.name\n }\n}\n"],"names":["en","httpStatus","APIError","ValidationErrorName","ValidationError","constructor","results","t","message","count","errors","length","translations","error","followingFieldsInvalid_one","followingFieldsInvalid_other","map","f","path","join","BAD_REQUEST","name"],"mappings":"AAEA,SAASA,EAAE,QAAQ,wCAAuC;AAC1D,OAAOC,gBAAgB,cAAa;AAEpC,SAASC,QAAQ,QAAQ,gBAAe;AAExC,sDAAsD;AACtD,OAAO,IAAIC,sBAAsB,kBAAiB;AAQlD,OAAO,MAAMC,wBAAwBF;IAKnCG,YACEC,OAKC,EACDC,CAAa,CACb;QACA,MAAMC,UAAUD,IACZA,EAAE,gCAAgC;YAAEE,OAAOH,QAAQI,MAAM,CAACC,MAAM;QAAC,KACjEL,QAAQI,MAAM,CAACC,MAAM,KAAK,IACxBX,GAAGY,YAAY,CAACC,KAAK,CAACC,0BAA0B,GAChDd,GAAGY,YAAY,CAACC,KAAK,CAACE,4BAA4B;QAExD,KAAK,CACH,CAAC,EAAEP,QAAQ,CAAC,EAAEF,QAAQI,MAAM,CAACM,GAAG,CAAC,CAACC,IAAMA,EAAEC,IAAI,EAAEC,IAAI,CAAC,MAAM,CAAC,EAC5DlB,WAAWmB,WAAW,EACtBd;QAGFH,sBAAsB,IAAI,CAACE,WAAW,CAACgB,IAAI;IAC7C;AACF"}
1
+ {"version":3,"sources":["../../src/errors/ValidationError.ts"],"sourcesContent":["import type { TFunction } from '@payloadcms/translations'\n\nimport { en } from '@payloadcms/translations/languages/en'\nimport httpStatus from 'http-status'\n\nimport { APIError } from './APIError.js'\n\n// This gets dynamically reassigned during compilation\nexport let ValidationErrorName = 'ValidationError'\n\nexport type ValidationFieldError = {\n // The error message to display for this field\n message: string\n path: string\n}\n\nexport class ValidationError extends APIError<{\n collection?: string\n errors: ValidationFieldError[]\n global?: string\n}> {\n constructor(\n results: {\n collection?: string\n errors: ValidationFieldError[]\n global?: string\n id?: number | string\n },\n t?: TFunction,\n ) {\n const message = t\n ? t('error:followingFieldsInvalid', { count: results.errors.length })\n : results.errors.length === 1\n ? en.translations.error.followingFieldsInvalid_one\n : en.translations.error.followingFieldsInvalid_other\n\n super(\n `${message} ${results.errors.map((f) => f.path).join(', ')}`,\n httpStatus.BAD_REQUEST,\n results,\n )\n\n ValidationErrorName = this.constructor.name\n }\n}\n"],"names":["en","httpStatus","APIError","ValidationErrorName","ValidationError","constructor","results","t","message","count","errors","length","translations","error","followingFieldsInvalid_one","followingFieldsInvalid_other","map","f","path","join","BAD_REQUEST","name"],"mappings":"AAEA,SAASA,EAAE,QAAQ,wCAAuC;AAC1D,OAAOC,gBAAgB,cAAa;AAEpC,SAASC,QAAQ,QAAQ,gBAAe;AAExC,sDAAsD;AACtD,OAAO,IAAIC,sBAAsB,kBAAiB;AAQlD,OAAO,MAAMC,wBAAwBF;IAKnCG,YACEC,OAKC,EACDC,CAAa,CACb;QACA,MAAMC,UAAUD,IACZA,EAAE,gCAAgC;YAAEE,OAAOH,QAAQI,MAAM,CAACC,MAAM;QAAC,KACjEL,QAAQI,MAAM,CAACC,MAAM,KAAK,IACxBX,GAAGY,YAAY,CAACC,KAAK,CAACC,0BAA0B,GAChDd,GAAGY,YAAY,CAACC,KAAK,CAACE,4BAA4B;QAExD,KAAK,CACH,GAAGP,QAAQ,CAAC,EAAEF,QAAQI,MAAM,CAACM,GAAG,CAAC,CAACC,IAAMA,EAAEC,IAAI,EAAEC,IAAI,CAAC,OAAO,EAC5DlB,WAAWmB,WAAW,EACtBd;QAGFH,sBAAsB,IAAI,CAACE,WAAW,CAACgB,IAAI;IAC7C;AACF"}
@@ -43,6 +43,7 @@ export const createClientField = ({ defaultIDType, field: incomingField, i18n, i
43
43
  case 'description':
44
44
  if ('description' in incomingField.admin) {
45
45
  if (typeof incomingField.admin?.description !== 'function') {
46
+ ;
46
47
  clientField.admin.description = incomingField.admin.description;
47
48
  }
48
49
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/fields/config/client.ts"],"sourcesContent":["import type { I18nClient } from '@payloadcms/translations'\n\nimport type {\n AdminClient,\n BlockJSX,\n BlocksFieldClient,\n ClientBlock,\n ClientField,\n Field,\n FieldBase,\n LabelsClient,\n RadioFieldClient,\n RowFieldClient,\n SelectFieldClient,\n TabsFieldClient,\n} from '../../fields/config/types.js'\nimport type { Payload } from '../../types/index.js'\n\nimport { getFromImportMap } from '../../bin/generateImportMap/getFromImportMap.js'\nimport { MissingEditorProp } from '../../errors/MissingEditorProp.js'\nimport { fieldAffectsData } from '../../fields/config/types.js'\nimport { flattenTopLevelFields, type ImportMap } from '../../index.js'\nimport { removeUndefined } from '../../utilities/removeUndefined.js'\n\n// Should not be used - ClientField should be used instead. This is why we don't export ClientField, we don't want people\n// to accidentally use it instead of ClientField and get confused\n\nexport { ClientField }\n\nexport type ServerOnlyFieldProperties =\n | 'dbName' // can be a function\n | 'editor' // This is a `richText` only property\n | 'enumName' // can be a function\n | 'filterOptions' // This is a `relationship` and `upload` only property\n | 'label'\n | 'typescriptSchema'\n | 'validate'\n | keyof Pick<FieldBase, 'access' | 'custom' | 'defaultValue' | 'hooks'>\n\nexport type ServerOnlyFieldAdminProperties = keyof Pick<FieldBase['admin'], 'condition'>\n\nconst serverOnlyFieldProperties: Partial<ServerOnlyFieldProperties>[] = [\n 'hooks',\n 'access',\n 'validate',\n 'defaultValue',\n 'filterOptions', // This is a `relationship` and `upload` only property\n 'editor', // This is a `richText` only property\n 'custom',\n 'typescriptSchema',\n 'dbName', // can be a function\n 'enumName', // can be a function\n // the following props are handled separately (see below):\n // `label`\n // `fields`\n // `blocks`\n // `tabs`\n // `admin`\n]\nconst serverOnlyFieldAdminProperties: Partial<ServerOnlyFieldAdminProperties>[] = ['condition']\ntype FieldWithDescription = {\n admin: AdminClient\n} & ClientField\n\nexport const createClientField = ({\n defaultIDType,\n field: incomingField,\n i18n,\n importMap,\n}: {\n defaultIDType: Payload['config']['db']['defaultIDType']\n field: Field\n i18n: I18nClient\n importMap: ImportMap\n}): ClientField => {\n const clientField: ClientField = {} as ClientField\n\n const isHidden = 'hidden' in incomingField && incomingField?.hidden\n const disabledFromAdmin =\n incomingField?.admin && 'disabled' in incomingField.admin && incomingField.admin.disabled\n\n if (fieldAffectsData(incomingField) && (isHidden || disabledFromAdmin)) {\n return null\n }\n\n for (const key in incomingField) {\n if (serverOnlyFieldProperties.includes(key as any)) {\n continue\n }\n switch (key) {\n case 'admin':\n if (!incomingField.admin) {\n break\n }\n clientField.admin = {} as AdminClient\n for (const adminKey in incomingField.admin) {\n if (serverOnlyFieldAdminProperties.includes(adminKey as any)) {\n continue\n }\n switch (adminKey) {\n case 'description':\n if ('description' in incomingField.admin) {\n if (typeof incomingField.admin?.description !== 'function') {\n ;(clientField as FieldWithDescription).admin.description =\n incomingField.admin.description\n }\n }\n\n break\n default:\n clientField.admin[adminKey] = incomingField.admin[adminKey]\n }\n }\n break\n case 'blocks':\n case 'fields':\n case 'tabs':\n // Skip - we handle sub-fields in the switch below\n break\n case 'label':\n //@ts-expect-error - would need to type narrow\n if (typeof incomingField.label === 'function') {\n //@ts-expect-error - would need to type narrow\n clientField.label = incomingField.label({ t: i18n.t })\n } else {\n //@ts-expect-error - would need to type narrow\n clientField.label = incomingField.label\n }\n break\n default:\n clientField[key] = incomingField[key]\n }\n }\n\n switch (incomingField.type) {\n case 'array':\n case 'collapsible':\n case 'group':\n case 'row': {\n const field = clientField as unknown as RowFieldClient\n\n if (!field.fields) {\n field.fields = []\n }\n\n field.fields = createClientFields({\n defaultIDType,\n disableAddingID: incomingField.type !== 'array',\n fields: incomingField.fields,\n i18n,\n importMap,\n })\n\n break\n }\n\n case 'blocks': {\n const field = clientField as unknown as BlocksFieldClient\n\n if (incomingField.blocks?.length) {\n for (let i = 0; i < incomingField.blocks.length; i++) {\n const block = incomingField.blocks[i]\n\n // prevent $undefined from being passed through the rsc requests\n const clientBlock = removeUndefined<ClientBlock>({\n slug: block.slug,\n fields: field.blocks?.[i]?.fields || [],\n imageAltText: block.imageAltText,\n imageURL: block.imageURL,\n }) satisfies ClientBlock\n\n if (block.admin?.custom) {\n clientBlock.admin = {\n custom: block.admin.custom,\n }\n }\n\n if (block?.admin?.jsx) {\n const jsxResolved = getFromImportMap<BlockJSX>({\n importMap,\n PayloadComponent: block.admin.jsx,\n schemaPath: '',\n })\n clientBlock.jsx = jsxResolved\n }\n\n if (block.labels) {\n clientBlock.labels = {} as unknown as LabelsClient\n\n if (block.labels.singular) {\n if (typeof block.labels.singular === 'function') {\n clientBlock.labels.singular = block.labels.singular({ t: i18n.t })\n } else {\n clientBlock.labels.singular = block.labels.singular\n }\n if (typeof block.labels.plural === 'function') {\n clientBlock.labels.plural = block.labels.plural({ t: i18n.t })\n } else {\n clientBlock.labels.plural = block.labels.plural\n }\n }\n }\n\n clientBlock.fields = createClientFields({\n defaultIDType,\n fields: block.fields,\n i18n,\n importMap,\n })\n\n if (!field.blocks) {\n field.blocks = []\n }\n\n field.blocks[i] = clientBlock\n }\n }\n\n break\n }\n\n case 'radio':\n // falls through\n case 'select': {\n const field = clientField as RadioFieldClient | SelectFieldClient\n\n if (incomingField.options?.length) {\n for (let i = 0; i < incomingField.options.length; i++) {\n const option = incomingField.options[i]\n\n if (typeof option === 'object' && typeof option.label === 'function') {\n if (!field.options) {\n field.options = []\n }\n\n field.options[i] = {\n label: option.label({ t: i18n.t }),\n value: option.value,\n }\n }\n }\n }\n\n break\n }\n case 'richText': {\n if (!incomingField?.editor) {\n throw new MissingEditorProp(incomingField) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor\n }\n\n if (typeof incomingField?.editor === 'function') {\n throw new Error('Attempted to access unsanitized rich text editor.')\n }\n\n break\n }\n\n case 'tabs': {\n const field = clientField as unknown as TabsFieldClient\n\n if (incomingField.tabs?.length) {\n field.tabs = []\n\n for (let i = 0; i < incomingField.tabs.length; i++) {\n const tab = incomingField.tabs[i]\n const clientTab = {} as unknown as TabsFieldClient['tabs'][0]\n\n for (const key in tab) {\n if (serverOnlyFieldProperties.includes(key as any)) {\n continue\n }\n if (key === 'fields') {\n clientTab.fields = createClientFields({\n defaultIDType,\n disableAddingID: true,\n fields: tab.fields,\n i18n,\n importMap,\n })\n } else {\n clientTab[key] = tab[key]\n }\n }\n field.tabs[i] = clientTab\n }\n }\n\n break\n }\n\n default:\n break\n }\n\n return clientField\n}\n\nexport const createClientFields = ({\n defaultIDType,\n disableAddingID,\n fields,\n i18n,\n importMap,\n}: {\n defaultIDType: Payload['config']['db']['defaultIDType']\n disableAddingID?: boolean\n fields: Field[]\n i18n: I18nClient\n importMap: ImportMap\n}): ClientField[] => {\n const clientFields: ClientField[] = []\n\n for (let i = 0; i < fields.length; i++) {\n const field = fields[i]\n\n const clientField = createClientField({\n defaultIDType,\n field,\n i18n,\n importMap,\n })\n\n if (clientField) {\n clientFields.push(clientField)\n }\n }\n\n const hasID = flattenTopLevelFields(fields).some((f) => fieldAffectsData(f) && f.name === 'id')\n\n if (!disableAddingID && !hasID) {\n clientFields.push({\n name: 'id',\n type: defaultIDType,\n admin: {\n description: 'The unique identifier for this document',\n disableBulkEdit: true,\n disabled: true,\n hidden: true,\n },\n hidden: true,\n label: 'ID',\n })\n }\n\n return clientFields\n}\n"],"names":["getFromImportMap","MissingEditorProp","fieldAffectsData","flattenTopLevelFields","removeUndefined","serverOnlyFieldProperties","serverOnlyFieldAdminProperties","createClientField","defaultIDType","field","incomingField","i18n","importMap","clientField","isHidden","hidden","disabledFromAdmin","admin","disabled","key","includes","adminKey","description","label","t","type","fields","createClientFields","disableAddingID","blocks","length","i","block","clientBlock","slug","imageAltText","imageURL","custom","jsx","jsxResolved","PayloadComponent","schemaPath","labels","singular","plural","options","option","value","editor","Error","tabs","tab","clientTab","clientFields","push","hasID","some","f","name","disableBulkEdit"],"mappings":"AAkBA,SAASA,gBAAgB,QAAQ,kDAAiD;AAClF,SAASC,iBAAiB,QAAQ,oCAAmC;AACrE,SAASC,gBAAgB,QAAQ,+BAA8B;AAC/D,SAASC,qBAAqB,QAAwB,iBAAgB;AACtE,SAASC,eAAe,QAAQ,qCAAoC;AAmBpE,MAAMC,4BAAkE;IACtE;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CAOD;AACD,MAAMC,iCAA4E;IAAC;CAAY;AAK/F,OAAO,MAAMC,oBAAoB,CAAC,EAChCC,aAAa,EACbC,OAAOC,aAAa,EACpBC,IAAI,EACJC,SAAS,EAMV;IACC,MAAMC,cAA2B,CAAC;IAElC,MAAMC,WAAW,YAAYJ,iBAAiBA,eAAeK;IAC7D,MAAMC,oBACJN,eAAeO,SAAS,cAAcP,cAAcO,KAAK,IAAIP,cAAcO,KAAK,CAACC,QAAQ;IAE3F,IAAIhB,iBAAiBQ,kBAAmBI,CAAAA,YAAYE,iBAAgB,GAAI;QACtE,OAAO;IACT;IAEA,IAAK,MAAMG,OAAOT,cAAe;QAC/B,IAAIL,0BAA0Be,QAAQ,CAACD,MAAa;YAClD;QACF;QACA,OAAQA;YACN,KAAK;gBACH,IAAI,CAACT,cAAcO,KAAK,EAAE;oBACxB;gBACF;gBACAJ,YAAY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T,EAAC"}
1
+ {"version":3,"sources":["../../../src/fields/config/client.ts"],"sourcesContent":["import type { I18nClient } from '@payloadcms/translations'\n\nimport type {\n AdminClient,\n BlockJSX,\n BlocksFieldClient,\n ClientBlock,\n ClientField,\n Field,\n FieldBase,\n LabelsClient,\n RadioFieldClient,\n RowFieldClient,\n SelectFieldClient,\n TabsFieldClient,\n} from '../../fields/config/types.js'\nimport type { Payload } from '../../types/index.js'\n\nimport { getFromImportMap } from '../../bin/generateImportMap/getFromImportMap.js'\nimport { MissingEditorProp } from '../../errors/MissingEditorProp.js'\nimport { fieldAffectsData } from '../../fields/config/types.js'\nimport { flattenTopLevelFields, type ImportMap } from '../../index.js'\nimport { removeUndefined } from '../../utilities/removeUndefined.js'\n\n// Should not be used - ClientField should be used instead. This is why we don't export ClientField, we don't want people\n// to accidentally use it instead of ClientField and get confused\n\nexport { ClientField }\n\nexport type ServerOnlyFieldProperties =\n | 'dbName' // can be a function\n | 'editor' // This is a `richText` only property\n | 'enumName' // can be a function\n | 'filterOptions' // This is a `relationship` and `upload` only property\n | 'label'\n | 'typescriptSchema'\n | 'validate'\n | keyof Pick<FieldBase, 'access' | 'custom' | 'defaultValue' | 'hooks'>\n\nexport type ServerOnlyFieldAdminProperties = keyof Pick<FieldBase['admin'], 'condition'>\n\nconst serverOnlyFieldProperties: Partial<ServerOnlyFieldProperties>[] = [\n 'hooks',\n 'access',\n 'validate',\n 'defaultValue',\n 'filterOptions', // This is a `relationship` and `upload` only property\n 'editor', // This is a `richText` only property\n 'custom',\n 'typescriptSchema',\n 'dbName', // can be a function\n 'enumName', // can be a function\n // the following props are handled separately (see below):\n // `label`\n // `fields`\n // `blocks`\n // `tabs`\n // `admin`\n]\nconst serverOnlyFieldAdminProperties: Partial<ServerOnlyFieldAdminProperties>[] = ['condition']\ntype FieldWithDescription = {\n admin: AdminClient\n} & ClientField\n\nexport const createClientField = ({\n defaultIDType,\n field: incomingField,\n i18n,\n importMap,\n}: {\n defaultIDType: Payload['config']['db']['defaultIDType']\n field: Field\n i18n: I18nClient\n importMap: ImportMap\n}): ClientField => {\n const clientField: ClientField = {} as ClientField\n\n const isHidden = 'hidden' in incomingField && incomingField?.hidden\n const disabledFromAdmin =\n incomingField?.admin && 'disabled' in incomingField.admin && incomingField.admin.disabled\n\n if (fieldAffectsData(incomingField) && (isHidden || disabledFromAdmin)) {\n return null\n }\n\n for (const key in incomingField) {\n if (serverOnlyFieldProperties.includes(key as any)) {\n continue\n }\n switch (key) {\n case 'admin':\n if (!incomingField.admin) {\n break\n }\n clientField.admin = {} as AdminClient\n for (const adminKey in incomingField.admin) {\n if (serverOnlyFieldAdminProperties.includes(adminKey as any)) {\n continue\n }\n switch (adminKey) {\n case 'description':\n if ('description' in incomingField.admin) {\n if (typeof incomingField.admin?.description !== 'function') {\n ;(clientField as FieldWithDescription).admin.description =\n incomingField.admin.description\n }\n }\n\n break\n default:\n clientField.admin[adminKey] = incomingField.admin[adminKey]\n }\n }\n break\n case 'blocks':\n case 'fields':\n case 'tabs':\n // Skip - we handle sub-fields in the switch below\n break\n case 'label':\n //@ts-expect-error - would need to type narrow\n if (typeof incomingField.label === 'function') {\n //@ts-expect-error - would need to type narrow\n clientField.label = incomingField.label({ t: i18n.t })\n } else {\n //@ts-expect-error - would need to type narrow\n clientField.label = incomingField.label\n }\n break\n default:\n clientField[key] = incomingField[key]\n }\n }\n\n switch (incomingField.type) {\n case 'array':\n case 'collapsible':\n case 'group':\n case 'row': {\n const field = clientField as unknown as RowFieldClient\n\n if (!field.fields) {\n field.fields = []\n }\n\n field.fields = createClientFields({\n defaultIDType,\n disableAddingID: incomingField.type !== 'array',\n fields: incomingField.fields,\n i18n,\n importMap,\n })\n\n break\n }\n\n case 'blocks': {\n const field = clientField as unknown as BlocksFieldClient\n\n if (incomingField.blocks?.length) {\n for (let i = 0; i < incomingField.blocks.length; i++) {\n const block = incomingField.blocks[i]\n\n // prevent $undefined from being passed through the rsc requests\n const clientBlock = removeUndefined<ClientBlock>({\n slug: block.slug,\n fields: field.blocks?.[i]?.fields || [],\n imageAltText: block.imageAltText,\n imageURL: block.imageURL,\n }) satisfies ClientBlock\n\n if (block.admin?.custom) {\n clientBlock.admin = {\n custom: block.admin.custom,\n }\n }\n\n if (block?.admin?.jsx) {\n const jsxResolved = getFromImportMap<BlockJSX>({\n importMap,\n PayloadComponent: block.admin.jsx,\n schemaPath: '',\n })\n clientBlock.jsx = jsxResolved\n }\n\n if (block.labels) {\n clientBlock.labels = {} as unknown as LabelsClient\n\n if (block.labels.singular) {\n if (typeof block.labels.singular === 'function') {\n clientBlock.labels.singular = block.labels.singular({ t: i18n.t })\n } else {\n clientBlock.labels.singular = block.labels.singular\n }\n if (typeof block.labels.plural === 'function') {\n clientBlock.labels.plural = block.labels.plural({ t: i18n.t })\n } else {\n clientBlock.labels.plural = block.labels.plural\n }\n }\n }\n\n clientBlock.fields = createClientFields({\n defaultIDType,\n fields: block.fields,\n i18n,\n importMap,\n })\n\n if (!field.blocks) {\n field.blocks = []\n }\n\n field.blocks[i] = clientBlock\n }\n }\n\n break\n }\n\n case 'radio':\n // falls through\n case 'select': {\n const field = clientField as RadioFieldClient | SelectFieldClient\n\n if (incomingField.options?.length) {\n for (let i = 0; i < incomingField.options.length; i++) {\n const option = incomingField.options[i]\n\n if (typeof option === 'object' && typeof option.label === 'function') {\n if (!field.options) {\n field.options = []\n }\n\n field.options[i] = {\n label: option.label({ t: i18n.t }),\n value: option.value,\n }\n }\n }\n }\n\n break\n }\n case 'richText': {\n if (!incomingField?.editor) {\n throw new MissingEditorProp(incomingField) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor\n }\n\n if (typeof incomingField?.editor === 'function') {\n throw new Error('Attempted to access unsanitized rich text editor.')\n }\n\n break\n }\n\n case 'tabs': {\n const field = clientField as unknown as TabsFieldClient\n\n if (incomingField.tabs?.length) {\n field.tabs = []\n\n for (let i = 0; i < incomingField.tabs.length; i++) {\n const tab = incomingField.tabs[i]\n const clientTab = {} as unknown as TabsFieldClient['tabs'][0]\n\n for (const key in tab) {\n if (serverOnlyFieldProperties.includes(key as any)) {\n continue\n }\n if (key === 'fields') {\n clientTab.fields = createClientFields({\n defaultIDType,\n disableAddingID: true,\n fields: tab.fields,\n i18n,\n importMap,\n })\n } else {\n clientTab[key] = tab[key]\n }\n }\n field.tabs[i] = clientTab\n }\n }\n\n break\n }\n\n default:\n break\n }\n\n return clientField\n}\n\nexport const createClientFields = ({\n defaultIDType,\n disableAddingID,\n fields,\n i18n,\n importMap,\n}: {\n defaultIDType: Payload['config']['db']['defaultIDType']\n disableAddingID?: boolean\n fields: Field[]\n i18n: I18nClient\n importMap: ImportMap\n}): ClientField[] => {\n const clientFields: ClientField[] = []\n\n for (let i = 0; i < fields.length; i++) {\n const field = fields[i]\n\n const clientField = createClientField({\n defaultIDType,\n field,\n i18n,\n importMap,\n })\n\n if (clientField) {\n clientFields.push(clientField)\n }\n }\n\n const hasID = flattenTopLevelFields(fields).some((f) => fieldAffectsData(f) && f.name === 'id')\n\n if (!disableAddingID && !hasID) {\n clientFields.push({\n name: 'id',\n type: defaultIDType,\n admin: {\n description: 'The unique identifier for this document',\n disableBulkEdit: true,\n disabled: true,\n hidden: true,\n },\n hidden: true,\n label: 'ID',\n })\n }\n\n return clientFields\n}\n"],"names":["getFromImportMap","MissingEditorProp","fieldAffectsData","flattenTopLevelFields","removeUndefined","serverOnlyFieldProperties","serverOnlyFieldAdminProperties","createClientField","defaultIDType","field","incomingField","i18n","importMap","clientField","isHidden","hidden","disabledFromAdmin","admin","disabled","key","includes","adminKey","description","label","t","type","fields","createClientFields","disableAddingID","blocks","length","i","block","clientBlock","slug","imageAltText","imageURL","custom","jsx","jsxResolved","PayloadComponent","schemaPath","labels","singular","plural","options","option","value","editor","Error","tabs","tab","clientTab","clientFields","push","hasID","some","f","name","disableBulkEdit"],"mappings":"AAkBA,SAASA,gBAAgB,QAAQ,kDAAiD;AAClF,SAASC,iBAAiB,QAAQ,oCAAmC;AACrE,SAASC,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;IAEA,OAAOvC;AACT,EAAC;AAED,OAAO,MAAMc,qBAAqB,CAAC,EACjCnB,aAAa,EACboB,eAAe,EACfF,MAAM,EACNf,IAAI,EACJC,SAAS,EAOV;IACC,MAAMyC,eAA8B,EAAE;IAEtC,IAAK,IAAItB,IAAI,GAAGA,IAAIL,OAAOI,MAAM,EAAEC,IAAK;QACtC,MAAMtB,QAAQiB,MAAM,CAACK,EAAE;QAEvB,MAAMlB,cAAcN,kBAAkB;YACpCC;YACAC;YACAE;YACAC;QACF;QAEA,IAAIC,aAAa;YACfwC,aAAaC,IAAI,CAACzC;QACpB;IACF;IAEA,MAAM0C,QAAQpD,sBAAsBuB,QAAQ8B,IAAI,CAAC,CAACC,IAAMvD,iBAAiBuD,MAAMA,EAAEC,IAAI,KAAK;IAE1F,IAAI,CAAC9B,mBAAmB,CAAC2B,OAAO;QAC9BF,aAAaC,IAAI,CAAC;YAChBI,MAAM;YACNjC,MAAMjB;YACNS,OAAO;gBACLK,aAAa;gBACbqC,iBAAiB;gBACjBzC,UAAU;gBACVH,QAAQ;YACV;YACAA,QAAQ;YACRQ,OAAO;QACT;IACF;IAEA,OAAO8B;AACT,EAAC"}
@@ -4,7 +4,7 @@ import { formatLabels, toWords } from '../../utilities/formatLabels.js';
4
4
  import { baseBlockFields } from '../baseFields/baseBlockFields.js';
5
5
  import { baseIDField } from '../baseFields/baseIDField.js';
6
6
  import { setDefaultBeforeDuplicate } from '../setDefaultBeforeDuplicate.js';
7
- import validations from '../validations.js';
7
+ import { validations } from '../validations.js';
8
8
  import { sanitizeJoinField } from './sanitizeJoinField.js';
9
9
  import { fieldAffectsData, tabHasName } from './types.js';
10
10
  export const sanitizeFields = async ({ config, existingFieldNames = new Set(), fields, joinPath = '', joins, parentIsLocalized, requireFieldLevelRichTextEditor = false, richTextSanitizationPromises, validRelationships })=>{
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/fields/config/sanitize.ts"],"sourcesContent":["import { deepMergeSimple } from '@payloadcms/translations/utilities'\n\nimport type { CollectionConfig, SanitizedJoins } from '../../collections/config/types.js'\nimport type { Config, SanitizedConfig } from '../../config/types.js'\nimport type { Field } from './types.js'\n\nimport {\n DuplicateFieldName,\n InvalidFieldName,\n InvalidFieldRelationship,\n MissingEditorProp,\n MissingFieldType,\n} from '../../errors/index.js'\nimport { formatLabels, toWords } from '../../utilities/formatLabels.js'\nimport { baseBlockFields } from '../baseFields/baseBlockFields.js'\nimport { baseIDField } from '../baseFields/baseIDField.js'\nimport { setDefaultBeforeDuplicate } from '../setDefaultBeforeDuplicate.js'\nimport validations from '../validations.js'\nimport { sanitizeJoinField } from './sanitizeJoinField.js'\nimport { fieldAffectsData, tabHasName } from './types.js'\n\ntype Args = {\n collectionConfig?: CollectionConfig\n config: Config\n existingFieldNames?: Set<string>\n fields: Field[]\n joinPath?: string\n /**\n * When not passed in, assume that join are not supported (globals, arrays, blocks)\n */\n joins?: SanitizedJoins\n parentIsLocalized: boolean\n\n /**\n * If true, a richText field will require an editor property to be set, as the sanitizeFields function will not add it from the payload config if not present.\n *\n * @default false\n */\n requireFieldLevelRichTextEditor?: boolean\n /**\n * If this property is set, RichText fields won't be sanitized immediately. Instead, they will be added to this array as promises\n * so that you can sanitize them together, after the config has been sanitized.\n */\n richTextSanitizationPromises?: Array<(config: SanitizedConfig) => Promise<void>>\n /**\n * If not null, will validate that upload and relationship fields do not relate to a collection that is not in this array.\n * This validation will be skipped if validRelationships is null.\n */\n validRelationships: null | string[]\n}\n\nexport const sanitizeFields = async ({\n config,\n existingFieldNames = new Set(),\n fields,\n joinPath = '',\n joins,\n parentIsLocalized,\n requireFieldLevelRichTextEditor = false,\n richTextSanitizationPromises,\n validRelationships,\n}: Args): Promise<Field[]> => {\n if (!fields) {\n return []\n }\n\n for (let i = 0; i < fields.length; i++) {\n const field = fields[i]\n\n if ('_sanitized' in field && field._sanitized === true) {\n continue\n }\n\n if (!field.type) {\n throw new MissingFieldType(field)\n }\n\n // assert that field names do not contain forbidden characters\n if (fieldAffectsData(field) && field.name.includes('.')) {\n throw new InvalidFieldName(field, field.name)\n }\n\n // Auto-label\n if (\n 'name' in field &&\n field.name &&\n typeof field.label !== 'object' &&\n typeof field.label !== 'string' &&\n typeof field.label !== 'function' &&\n field.label !== false\n ) {\n field.label = toWords(field.name)\n }\n\n if (\n field.type === 'checkbox' &&\n typeof field.defaultValue === 'undefined' &&\n field.required === true\n ) {\n field.defaultValue = false\n }\n\n if (field.type === 'join') {\n sanitizeJoinField({ config, field, joinPath, joins })\n }\n\n if (field.type === 'relationship' || field.type === 'upload') {\n if (validRelationships) {\n const relationships = Array.isArray(field.relationTo)\n ? field.relationTo\n : [field.relationTo]\n relationships.forEach((relationship: string) => {\n if (!validRelationships.includes(relationship)) {\n throw new InvalidFieldRelationship(field, relationship)\n }\n })\n }\n\n if (field.min && !field.minRows) {\n console.warn(\n `(payload): The \"min\" property is deprecated for the Relationship field \"${field.name}\" and will be removed in a future version. Please use \"minRows\" instead.`,\n )\n }\n if (field.max && !field.maxRows) {\n console.warn(\n `(payload): The \"max\" property is deprecated for the Relationship field \"${field.name}\" and will be removed in a future version. Please use \"maxRows\" instead.`,\n )\n }\n field.minRows = field.minRows || field.min\n field.maxRows = field.maxRows || field.max\n }\n\n if (field.type === 'upload') {\n if (!field.admin || !('isSortable' in field.admin)) {\n field.admin = {\n isSortable: true,\n ...field.admin,\n }\n }\n }\n\n if (field.type === 'array' && field.fields) {\n field.fields.push(baseIDField)\n }\n\n if ((field.type === 'blocks' || field.type === 'array') && field.label) {\n field.labels = field.labels || formatLabels(field.name)\n }\n\n if (fieldAffectsData(field)) {\n if (existingFieldNames.has(field.name)) {\n throw new DuplicateFieldName(field.name)\n } else if (!['blockName', 'id'].includes(field.name)) {\n existingFieldNames.add(field.name)\n }\n\n if (typeof field.localized !== 'undefined') {\n let shouldDisableLocalized = !config.localization\n\n if (!config.compatibility?.allowLocalizedWithinLocalized && parentIsLocalized) {\n shouldDisableLocalized = true\n }\n\n if (shouldDisableLocalized) {\n delete field.localized\n }\n }\n\n if (typeof field.validate === 'undefined') {\n const defaultValidate = validations[field.type]\n if (defaultValidate) {\n field.validate = (val, options) => defaultValidate(val, { ...field, ...options })\n } else {\n field.validate = (): true => true\n }\n }\n\n if (!field.hooks) {\n field.hooks = {}\n }\n if (!field.access) {\n field.access = {}\n }\n\n setDefaultBeforeDuplicate(field)\n }\n\n if (!field.admin) {\n field.admin = {}\n }\n\n // Make sure that the richText field has an editor\n if (field.type === 'richText') {\n const sanitizeRichText = async (_config: SanitizedConfig) => {\n if (!field.editor) {\n if (_config.editor && !requireFieldLevelRichTextEditor) {\n // config.editor should be sanitized at this point\n field.editor = _config.editor\n } else {\n throw new MissingEditorProp(field) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor\n }\n }\n\n if (typeof field.editor === 'function') {\n field.editor = await field.editor({\n config: _config,\n isRoot: requireFieldLevelRichTextEditor,\n parentIsLocalized: parentIsLocalized || field.localized,\n })\n }\n\n if (field.editor.i18n && Object.keys(field.editor.i18n).length >= 0) {\n config.i18n.translations = deepMergeSimple(config.i18n.translations, field.editor.i18n)\n }\n }\n if (richTextSanitizationPromises) {\n richTextSanitizationPromises.push(sanitizeRichText)\n } else {\n await sanitizeRichText(config as unknown as SanitizedConfig)\n }\n }\n\n if (field.type === 'blocks' && field.blocks) {\n for (const block of field.blocks) {\n if (block._sanitized === true) {\n continue\n }\n block._sanitized = true\n block.fields = block.fields.concat(baseBlockFields)\n block.labels = !block.labels ? formatLabels(block.slug) : block.labels\n block.fields = await sanitizeFields({\n config,\n existingFieldNames: new Set(),\n fields: block.fields,\n parentIsLocalized: parentIsLocalized || field.localized,\n requireFieldLevelRichTextEditor,\n richTextSanitizationPromises,\n validRelationships,\n })\n }\n }\n\n if ('fields' in field && field.fields) {\n field.fields = await sanitizeFields({\n config,\n existingFieldNames: fieldAffectsData(field) ? new Set() : existingFieldNames,\n fields: field.fields,\n joinPath: fieldAffectsData(field)\n ? `${joinPath ? joinPath + '.' : ''}${field.name}`\n : joinPath,\n joins,\n parentIsLocalized: parentIsLocalized || field.localized,\n requireFieldLevelRichTextEditor,\n richTextSanitizationPromises,\n validRelationships,\n })\n }\n\n if (field.type === 'tabs') {\n for (let j = 0; j < field.tabs.length; j++) {\n const tab = field.tabs[j]\n if (tabHasName(tab) && typeof tab.label === 'undefined') {\n tab.label = toWords(tab.name)\n }\n\n tab.fields = await sanitizeFields({\n config,\n existingFieldNames: tabHasName(tab) ? new Set() : existingFieldNames,\n fields: tab.fields,\n joinPath: tabHasName(tab) ? `${joinPath ? joinPath + '.' : ''}${tab.name}` : joinPath,\n joins,\n parentIsLocalized: parentIsLocalized || (tabHasName(tab) && tab.localized),\n requireFieldLevelRichTextEditor,\n richTextSanitizationPromises,\n validRelationships,\n })\n field.tabs[j] = tab\n }\n }\n\n if (field.type === 'ui' && typeof field.admin.disableBulkEdit === 'undefined') {\n field.admin.disableBulkEdit = true\n }\n\n if ('_sanitized' in field) {\n field._sanitized = true\n }\n\n fields[i] = field\n }\n\n return fields\n}\n"],"names":["deepMergeSimple","DuplicateFieldName","InvalidFieldName","InvalidFieldRelationship","MissingEditorProp","MissingFieldType","formatLabels","toWords","baseBlockFields","baseIDField","setDefaultBeforeDuplicate","validations","sanitizeJoinField","fieldAffectsData","tabHasName","sanitizeFields","config","existingFieldNames","Set","fields","joinPath","joins","parentIsLocalized","requireFieldLevelRichTextEditor","richTextSanitizationPromises","validRelationships","i","length","field","_sanitized","type","name","includes","label","defaultValue","required","relationships","Array","isArray","relationTo","forEach","relationship","min","minRows","console","warn","max","maxRows","admin","isSortable","push","labels","has","add","localized","shouldDisableLocalized","localization","compatibility","allowLocalizedWithinLocalized","validate","defaultValidate","val","options","hooks","access","sanitizeRichText","_config","editor","isRoot","i18n","Object","keys","translations","blocks","block","concat","slug","j","tabs","tab","disableBulkEdit"],"mappings":"AAAA,SAASA,eAAe,QAAQ,qCAAoC;AAMpE,SACEC,kBAAkB,EAClBC,gBAAgB,EAChBC,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AIzB,SAAS;oBACzE/B;oBACAC;oBACAC;gBACF;gBACAG,MAAMkD,IAAI,CAACD,EAAE,GAAGE;YAClB;QACF;QAEA,IAAInD,MAAME,IAAI,KAAK,QAAQ,OAAOF,MAAMoB,KAAK,CAACgC,eAAe,KAAK,aAAa;YAC7EpD,MAAMoB,KAAK,CAACgC,eAAe,GAAG;QAChC;QAEA,IAAI,gBAAgBpD,OAAO;YACzBA,MAAMC,UAAU,GAAG;QACrB;QAEAV,MAAM,CAACO,EAAE,GAAGE;IACd;IAEA,OAAOT;AACT,EAAC"}
1
+ {"version":3,"sources":["../../../src/fields/config/sanitize.ts"],"sourcesContent":["import { deepMergeSimple } from '@payloadcms/translations/utilities'\n\nimport type { CollectionConfig, SanitizedJoins } from '../../collections/config/types.js'\nimport type { Config, SanitizedConfig } from '../../config/types.js'\nimport type { Field } from './types.js'\n\nimport {\n DuplicateFieldName,\n InvalidFieldName,\n InvalidFieldRelationship,\n MissingEditorProp,\n MissingFieldType,\n} from '../../errors/index.js'\nimport { formatLabels, toWords } from '../../utilities/formatLabels.js'\nimport { baseBlockFields } from '../baseFields/baseBlockFields.js'\nimport { baseIDField } from '../baseFields/baseIDField.js'\nimport { setDefaultBeforeDuplicate } from '../setDefaultBeforeDuplicate.js'\nimport { validations } from '../validations.js'\nimport { sanitizeJoinField } from './sanitizeJoinField.js'\nimport { fieldAffectsData, tabHasName } from './types.js'\n\ntype Args = {\n collectionConfig?: CollectionConfig\n config: Config\n existingFieldNames?: Set<string>\n fields: Field[]\n joinPath?: string\n /**\n * When not passed in, assume that join are not supported (globals, arrays, blocks)\n */\n joins?: SanitizedJoins\n parentIsLocalized: boolean\n\n /**\n * If true, a richText field will require an editor property to be set, as the sanitizeFields function will not add it from the payload config if not present.\n *\n * @default false\n */\n requireFieldLevelRichTextEditor?: boolean\n /**\n * If this property is set, RichText fields won't be sanitized immediately. Instead, they will be added to this array as promises\n * so that you can sanitize them together, after the config has been sanitized.\n */\n richTextSanitizationPromises?: Array<(config: SanitizedConfig) => Promise<void>>\n /**\n * If not null, will validate that upload and relationship fields do not relate to a collection that is not in this array.\n * This validation will be skipped if validRelationships is null.\n */\n validRelationships: null | string[]\n}\n\nexport const sanitizeFields = async ({\n config,\n existingFieldNames = new Set(),\n fields,\n joinPath = '',\n joins,\n parentIsLocalized,\n requireFieldLevelRichTextEditor = false,\n richTextSanitizationPromises,\n validRelationships,\n}: Args): Promise<Field[]> => {\n if (!fields) {\n return []\n }\n\n for (let i = 0; i < fields.length; i++) {\n const field = fields[i]\n\n if ('_sanitized' in field && field._sanitized === true) {\n continue\n }\n\n if (!field.type) {\n throw new MissingFieldType(field)\n }\n\n // assert that field names do not contain forbidden characters\n if (fieldAffectsData(field) && field.name.includes('.')) {\n throw new InvalidFieldName(field, field.name)\n }\n\n // Auto-label\n if (\n 'name' in field &&\n field.name &&\n typeof field.label !== 'object' &&\n typeof field.label !== 'string' &&\n typeof field.label !== 'function' &&\n field.label !== false\n ) {\n field.label = toWords(field.name)\n }\n\n if (\n field.type === 'checkbox' &&\n typeof field.defaultValue === 'undefined' &&\n field.required === true\n ) {\n field.defaultValue = false\n }\n\n if (field.type === 'join') {\n sanitizeJoinField({ config, field, joinPath, joins })\n }\n\n if (field.type === 'relationship' || field.type === 'upload') {\n if (validRelationships) {\n const relationships = Array.isArray(field.relationTo)\n ? field.relationTo\n : [field.relationTo]\n relationships.forEach((relationship: string) => {\n if (!validRelationships.includes(relationship)) {\n throw new InvalidFieldRelationship(field, relationship)\n }\n })\n }\n\n if (field.min && !field.minRows) {\n console.warn(\n `(payload): The \"min\" property is deprecated for the Relationship field \"${field.name}\" and will be removed in a future version. Please use \"minRows\" instead.`,\n )\n }\n if (field.max && !field.maxRows) {\n console.warn(\n `(payload): The \"max\" property is deprecated for the Relationship field \"${field.name}\" and will be removed in a future version. Please use \"maxRows\" instead.`,\n )\n }\n field.minRows = field.minRows || field.min\n field.maxRows = field.maxRows || field.max\n }\n\n if (field.type === 'upload') {\n if (!field.admin || !('isSortable' in field.admin)) {\n field.admin = {\n isSortable: true,\n ...field.admin,\n }\n }\n }\n\n if (field.type === 'array' && field.fields) {\n field.fields.push(baseIDField)\n }\n\n if ((field.type === 'blocks' || field.type === 'array') && field.label) {\n field.labels = field.labels || formatLabels(field.name)\n }\n\n if (fieldAffectsData(field)) {\n if (existingFieldNames.has(field.name)) {\n throw new DuplicateFieldName(field.name)\n } else if (!['blockName', 'id'].includes(field.name)) {\n existingFieldNames.add(field.name)\n }\n\n if (typeof field.localized !== 'undefined') {\n let shouldDisableLocalized = !config.localization\n\n if (!config.compatibility?.allowLocalizedWithinLocalized && parentIsLocalized) {\n shouldDisableLocalized = true\n }\n\n if (shouldDisableLocalized) {\n delete field.localized\n }\n }\n\n if (typeof field.validate === 'undefined') {\n const defaultValidate = validations[field.type]\n if (defaultValidate) {\n field.validate = (val, options) => defaultValidate(val, { ...field, ...options })\n } else {\n field.validate = (): true => true\n }\n }\n\n if (!field.hooks) {\n field.hooks = {}\n }\n if (!field.access) {\n field.access = {}\n }\n\n setDefaultBeforeDuplicate(field)\n }\n\n if (!field.admin) {\n field.admin = {}\n }\n\n // Make sure that the richText field has an editor\n if (field.type === 'richText') {\n const sanitizeRichText = async (_config: SanitizedConfig) => {\n if (!field.editor) {\n if (_config.editor && !requireFieldLevelRichTextEditor) {\n // config.editor should be sanitized at this point\n field.editor = _config.editor\n } else {\n throw new MissingEditorProp(field) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor\n }\n }\n\n if (typeof field.editor === 'function') {\n field.editor = await field.editor({\n config: _config,\n isRoot: requireFieldLevelRichTextEditor,\n parentIsLocalized: parentIsLocalized || field.localized,\n })\n }\n\n if (field.editor.i18n && Object.keys(field.editor.i18n).length >= 0) {\n config.i18n.translations = deepMergeSimple(config.i18n.translations, field.editor.i18n)\n }\n }\n if (richTextSanitizationPromises) {\n richTextSanitizationPromises.push(sanitizeRichText)\n } else {\n await sanitizeRichText(config as unknown as SanitizedConfig)\n }\n }\n\n if (field.type === 'blocks' && field.blocks) {\n for (const block of field.blocks) {\n if (block._sanitized === true) {\n continue\n }\n block._sanitized = true\n block.fields = block.fields.concat(baseBlockFields)\n block.labels = !block.labels ? formatLabels(block.slug) : block.labels\n block.fields = await sanitizeFields({\n config,\n existingFieldNames: new Set(),\n fields: block.fields,\n parentIsLocalized: parentIsLocalized || field.localized,\n requireFieldLevelRichTextEditor,\n richTextSanitizationPromises,\n validRelationships,\n })\n }\n }\n\n if ('fields' in field && field.fields) {\n field.fields = await sanitizeFields({\n config,\n existingFieldNames: fieldAffectsData(field) ? new Set() : existingFieldNames,\n fields: field.fields,\n joinPath: fieldAffectsData(field)\n ? `${joinPath ? joinPath + '.' : ''}${field.name}`\n : joinPath,\n joins,\n parentIsLocalized: parentIsLocalized || field.localized,\n requireFieldLevelRichTextEditor,\n richTextSanitizationPromises,\n validRelationships,\n })\n }\n\n if (field.type === 'tabs') {\n for (let j = 0; j < field.tabs.length; j++) {\n const tab = field.tabs[j]\n if (tabHasName(tab) && typeof tab.label === 'undefined') {\n tab.label = toWords(tab.name)\n }\n\n tab.fields = await sanitizeFields({\n config,\n existingFieldNames: tabHasName(tab) ? new Set() : existingFieldNames,\n fields: tab.fields,\n joinPath: tabHasName(tab) ? `${joinPath ? joinPath + '.' : ''}${tab.name}` : joinPath,\n joins,\n parentIsLocalized: parentIsLocalized || (tabHasName(tab) && tab.localized),\n requireFieldLevelRichTextEditor,\n richTextSanitizationPromises,\n validRelationships,\n })\n field.tabs[j] = tab\n }\n }\n\n if (field.type === 'ui' && typeof field.admin.disableBulkEdit === 'undefined') {\n field.admin.disableBulkEdit = true\n }\n\n if ('_sanitized' in field) {\n field._sanitized = true\n }\n\n fields[i] = field\n }\n\n return fields\n}\n"],"names":["deepMergeSimple","DuplicateFieldName","InvalidFieldName","InvalidFieldRelationship","MissingEditorProp","MissingFieldType","formatLabels","toWords","baseBlockFields","baseIDField","setDefaultBeforeDuplicate","validations","sanitizeJoinField","fieldAffectsData","tabHasName","sanitizeFields","config","existingFieldNames","Set","fields","joinPath","joins","parentIsLocalized","requireFieldLevelRichTextEditor","richTextSanitizationPromises","validRelationships","i","length","field","_sanitized","type","name","includes","label","defaultValue","required","relationships","Array","isArray","relationTo","forEach","relationship","min","minRows","console","warn","max","maxRows","admin","isSortable","push","labels","has","add","localized","shouldDisableLocalized","localization","compatibility","allowLocalizedWithinLocalized","validate","defaultValidate","val","options","hooks","access","sanitizeRichText","_config","editor","isRoot","i18n","Object","keys","translations","blocks","block","concat","slug","j","tabs","tab","disableBulkEdit"],"mappings":"AAAA,SAASA,eAAe,QAAQ,qCAAoC;AAMpE,SACEC,kBAAkB,EAClBC,gBAAgB,EAChBC,wBAAwB,EACxBC,iBAAiB,EACjBC,gBAAgB,QACX,wBAAuB;AAC9B,SAASC,YAAY,EAAEC,OAAO,QAAQ,kCAAiC;AACvE,SAASC,eAAe,QAAQ,mCAAkC;AAClE,SAASC,WAAW,QAAQ,+BAA8B;AAC1D,SAASC,yBAAyB,QAAQ,kCAAiC;AAC3E,SAASC,WAAW,QAAQ,oBAAmB;AAC/C,SAASC,iBAAiB,QAAQ,yBAAwB;AAC1D,SAASC,gBAAgB,EAAEC,UAAU,QAAQ,aAAY;AAgCzD,OAAO,MAAMC,iBAAiB,OAAO,EACnCC,MAAM,EACNC,qBAAqB,IAAIC,KAAK,EAC9BC,MAAM,EACNC,WAAW,EAAE,EACbC,KAAK,EACLC,iBAAiB,EACjBC,kCAAkC,KAAK,EACvCC,4BAA4B,EAC5BC,kBAAkB,EACb;IACL,IAAI,CAACN,QAAQ;QACX,OAAO,EAAE;IACX;IAEA,IAAK,IAAIO,IAAI,GAAGA,IAAIP,OAAOQ,MAAM,EAAED,IAAK;QACtC,MAAME,QAAQT,MAAM,CAACO,EAAE;QAEvB,IAAI,gBAAgBE,SAASA,MAAMC,UAAU,KAAK,MAAM;YACtD;QACF;QAEA,IAAI,CAACD,MAAME,IAAI,EAAE;YACf,MAAM,IAAIzB,iBAAiBuB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AAI/D,WAAWiE,QAAQ,OAAOA,IAAI9C,KAAK,KAAK,aAAa;oBACvD8C,IAAI9C,KAAK,GAAG1B,QAAQwE,IAAIhD,IAAI;gBAC9B;gBAEAgD,IAAI5D,MAAM,GAAG,MAAMJ,eAAe;oBAChCC;oBACAC,oBAAoBH,WAAWiE,OAAO,IAAI7D,QAAQD;oBAClDE,QAAQ4D,IAAI5D,MAAM;oBAClBC,UAAUN,WAAWiE,OAAO,GAAG3D,WAAWA,WAAW,MAAM,KAAK2D,IAAIhD,IAAI,EAAE,GAAGX;oBAC7EC;oBACAC,mBAAmBA,qBAAsBR,WAAWiE,QAAQA,IAAIzB,SAAS;oBACzE/B;oBACAC;oBACAC;gBACF;gBACAG,MAAMkD,IAAI,CAACD,EAAE,GAAGE;YAClB;QACF;QAEA,IAAInD,MAAME,IAAI,KAAK,QAAQ,OAAOF,MAAMoB,KAAK,CAACgC,eAAe,KAAK,aAAa;YAC7EpD,MAAMoB,KAAK,CAACgC,eAAe,GAAG;QAChC;QAEA,IAAI,gBAAgBpD,OAAO;YACzBA,MAAMC,UAAU,GAAG;QACrB;QAEAV,MAAM,CAACO,EAAE,GAAGE;IACd;IAEA,OAAOT;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/fields/config/sanitizeJoinField.ts"],"sourcesContent":["import type { SanitizedJoin, SanitizedJoins } from '../../collections/config/types.js'\nimport type { Config } from '../../config/types.js'\nimport type { JoinField, RelationshipField, UploadField } from './types.js'\n\nimport { APIError } from '../../errors/index.js'\nimport { InvalidFieldJoin } from '../../errors/InvalidFieldJoin.js'\nimport { traverseFields } from '../../utilities/traverseFields.js'\nexport const sanitizeJoinField = ({\n config,\n field,\n joinPath,\n joins,\n}: {\n config: Config\n field: JoinField\n joinPath?: string\n joins?: SanitizedJoins\n}) => {\n // the `joins` arg is not passed for globals or when recursing on fields that do not allow a join field\n if (typeof joins === 'undefined') {\n throw new APIError('Join fields cannot be added to arrays, blocks or globals.')\n }\n if (!field.maxDepth) {\n field.maxDepth = 1\n }\n const join: SanitizedJoin = {\n field,\n joinPath: `${joinPath ? joinPath + '.' : ''}${field.name}`,\n targetField: undefined,\n }\n const joinCollection = config.collections.find(\n (collection) => collection.slug === field.collection,\n )\n if (!joinCollection) {\n throw new InvalidFieldJoin(field)\n }\n let joinRelationship: RelationshipField | UploadField\n\n const pathSegments = field.on.split('.') // Split the schema path into segments\n let currentSegmentIndex = 0\n\n // Traverse fields and match based on the schema path\n traverseFields({\n callback: ({ field, next }) => {\n if (!('name' in field) || !field.name) {\n return\n }\n const currentSegment = pathSegments[currentSegmentIndex]\n // match field on path segments\n if ('name' in field && field.name === currentSegment) {\n // Check if this is the last segment in the path\n if (\n (currentSegmentIndex === pathSegments.length - 1 &&\n 'type' in field &&\n field.type === 'relationship') ||\n field.type === 'upload'\n ) {\n joinRelationship = field // Return the matched field\n next()\n return true\n } else {\n // Move to the next path segment and continue traversal\n currentSegmentIndex++\n }\n } else {\n // skip fields in non-matching path segments\n next()\n return\n }\n },\n fields: joinCollection.fields,\n })\n\n if (!joinRelationship) {\n throw new InvalidFieldJoin(join.field)\n }\n if (Array.isArray(joinRelationship.relationTo)) {\n throw new APIError('Join fields cannot be used with polymorphic relationships.')\n }\n\n join.targetField = joinRelationship\n\n // override the join field localized property to use whatever the relationship field has\n field.localized = joinRelationship.localized\n // override the join field hasMany property to use whatever the relationship field has\n field.hasMany = joinRelationship.hasMany\n\n if (!joins[field.collection]) {\n joins[field.collection] = [join]\n } else {\n joins[field.collection].push(join)\n }\n}\n"],"names":["APIError","InvalidFieldJoin","traverseFields","sanitizeJoinField","config","field","joinPath","joins","maxDepth","join","name","targetField","undefined","joinCollection","collections","find","collection","slug","joinRelationship","pathSegments","on","split","currentSegmentIndex","callback","next","currentSegment","length","type","fields","Array","isArray","relationTo","localized","hasMany","push"],"mappings":"AAIA,SAASA,QAAQ,QAAQ,wBAAuB;AAChD,SAASC,gBAAgB,QAAQ,mCAAkC;AACnE,SAASC,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Qf,eAAee,MAAM;IAC/B;IAEA,IAAI,CAACV,kBAAkB;QACrB,MAAM,IAAIjB,iBAAiBQ,KAAKJ,KAAK;IACvC;IACA,IAAIwB,MAAMC,OAAO,CAACZ,iBAAiBa,UAAU,GAAG;QAC9C,MAAM,IAAI/B,SAAS;IACrB;IAEAS,KAAKE,WAAW,GAAGO;IAEnB,wFAAwF;IACxFb,MAAM2B,SAAS,GAAGd,iBAAiBc,SAAS;IAC5C,sFAAsF;IACtF3B,MAAM4B,OAAO,GAAGf,iBAAiBe,OAAO;IAExC,IAAI,CAAC1B,KAAK,CAACF,MAAMW,UAAU,CAAC,EAAE;QAC5BT,KAAK,CAACF,MAAMW,UAAU,CAAC,GAAG;YAACP;SAAK;IAClC,OAAO;QACLF,KAAK,CAACF,MAAMW,UAAU,CAAC,CAACkB,IAAI,CAACzB;IAC/B;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../src/fields/config/sanitizeJoinField.ts"],"sourcesContent":["import type { SanitizedJoin, SanitizedJoins } from '../../collections/config/types.js'\nimport type { Config } from '../../config/types.js'\nimport type { JoinField, RelationshipField, UploadField } from './types.js'\n\nimport { APIError } from '../../errors/index.js'\nimport { InvalidFieldJoin } from '../../errors/InvalidFieldJoin.js'\nimport { traverseFields } from '../../utilities/traverseFields.js'\nexport const sanitizeJoinField = ({\n config,\n field,\n joinPath,\n joins,\n}: {\n config: Config\n field: JoinField\n joinPath?: string\n joins?: SanitizedJoins\n}) => {\n // the `joins` arg is not passed for globals or when recursing on fields that do not allow a join field\n if (typeof joins === 'undefined') {\n throw new APIError('Join fields cannot be added to arrays, blocks or globals.')\n }\n if (!field.maxDepth) {\n field.maxDepth = 1\n }\n const join: SanitizedJoin = {\n field,\n joinPath: `${joinPath ? joinPath + '.' : ''}${field.name}`,\n targetField: undefined,\n }\n const joinCollection = config.collections.find(\n (collection) => collection.slug === field.collection,\n )\n if (!joinCollection) {\n throw new InvalidFieldJoin(field)\n }\n let joinRelationship: RelationshipField | UploadField\n\n const pathSegments = field.on.split('.') // Split the schema path into segments\n let currentSegmentIndex = 0\n\n // Traverse fields and match based on the schema path\n traverseFields({\n callback: ({ field, next }) => {\n if (!('name' in field) || !field.name) {\n return\n }\n const currentSegment = pathSegments[currentSegmentIndex]\n // match field on path segments\n if ('name' in field && field.name === currentSegment) {\n // Check if this is the last segment in the path\n if (\n (currentSegmentIndex === pathSegments.length - 1 &&\n 'type' in field &&\n field.type === 'relationship') ||\n field.type === 'upload'\n ) {\n joinRelationship = field // Return the matched field\n next()\n return true\n } else {\n // Move to the next path segment and continue traversal\n currentSegmentIndex++\n }\n } else {\n // skip fields in non-matching path segments\n next()\n return\n }\n },\n fields: joinCollection.fields,\n })\n\n if (!joinRelationship) {\n throw new InvalidFieldJoin(join.field)\n }\n if (Array.isArray(joinRelationship.relationTo)) {\n throw new APIError('Join fields cannot be used with polymorphic relationships.')\n }\n\n join.targetField = joinRelationship\n\n // override the join field localized property to use whatever the relationship field has\n field.localized = joinRelationship.localized\n // override the join field hasMany property to use whatever the relationship field has\n field.hasMany = joinRelationship.hasMany\n\n if (!joins[field.collection]) {\n joins[field.collection] = [join]\n } else {\n joins[field.collection].push(join)\n }\n}\n"],"names":["APIError","InvalidFieldJoin","traverseFields","sanitizeJoinField","config","field","joinPath","joins","maxDepth","join","name","targetField","undefined","joinCollection","collections","find","collection","slug","joinRelationship","pathSegments","on","split","currentSegmentIndex","callback","next","currentSegment","length","type","fields","Array","isArray","relationTo","localized","hasMany","push"],"mappings":"AAIA,SAASA,QAAQ,QAAQ,wBAAuB;AAChD,SAASC,gBAAgB,QAAQ,mCAAkC;AACnE,SAASC,cAAc,QAAQ,oCAAmC;AAClE,OAAO,MAAMC,oBAAoB,CAAC,EAChCC,MAAM,EACNC,KAAK,EACLC,QAAQ,EACRC,KAAK,EAMN;IACC,uGAAuG;IACvG,IAAI,OAAOA,UAAU,aAAa;QAChC,MAAM,IAAIP,SAAS;IACrB;IACA,IAAI,CAACK,MAAMG,QAAQ,EAA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,MAAM2B,SAAS,GAAGd,iBAAiBc,SAAS;IAC5C,sFAAsF;IACtF3B,MAAM4B,OAAO,GAAGf,iBAAiBe,OAAO;IAExC,IAAI,CAAC1B,KAAK,CAACF,MAAMW,UAAU,CAAC,EAAE;QAC5BT,KAAK,CAACF,MAAMW,UAAU,CAAC,GAAG;YAACP;SAAK;IAClC,OAAO;QACLF,KAAK,CAACF,MAAMW,UAAU,CAAC,CAACkB,IAAI,CAACzB;IAC/B;AACF,EAAC"}
@@ -432,6 +432,8 @@ export type DateFieldClient = {
432
432
  export type GroupField = {
433
433
  admin?: {
434
434
  components?: {
435
+ afterInput?: CustomComponent[];
436
+ beforeInput?: CustomComponent[];
435
437
  Label?: CustomComponent<GroupFieldLabelClientComponent | GroupFieldLabelServerComponent>;
436
438
  } & Admin['components'];
437
439
  hideGutter?: boolean;
@@ -466,6 +468,8 @@ export type CollapsibleField = {
466
468
  } & ({
467
469
  admin: {
468
470
  components: {
471
+ afterInput?: CustomComponent[];
472
+ beforeInput?: CustomComponent[];
469
473
  Label: CustomComponent<CollapsibleFieldLabelClientComponent | CollapsibleFieldLabelServerComponent>;
470
474
  } & Admin['components'];
471
475
  initCollapsed?: boolean;
@@ -474,6 +478,8 @@ export type CollapsibleField = {
474
478
  } | {
475
479
  admin?: {
476
480
  components?: {
481
+ afterInput?: CustomComponent[];
482
+ beforeInput?: CustomComponent[];
477
483
  Label?: CustomComponent<CollapsibleFieldLabelClientComponent | CollapsibleFieldLabelServerComponent>;
478
484
  } & Admin['components'];
479
485
  initCollapsed?: boolean;
@@ -756,6 +762,8 @@ type RelationshipAdmin = {
756
762
  allowCreate?: boolean;
757
763
  allowEdit?: boolean;
758
764
  components?: {
765
+ afterInput?: CustomComponent[];
766
+ beforeInput?: CustomComponent[];
759
767
  Error?: CustomComponent<RelationshipFieldErrorClientComponent | RelationshipFieldErrorServerComponent>;
760
768
  Label?: CustomComponent<RelationshipFieldLabelClientComponent | RelationshipFieldLabelServerComponent>;
761
769
  } & Admin['components'];
@@ -812,6 +820,8 @@ export type RichTextFieldClient<TValue extends object = any, TAdapterProps = any
812
820
  export type ArrayField = {
813
821
  admin?: {
814
822
  components?: {
823
+ afterInput?: CustomComponent[];
824
+ beforeInput?: CustomComponent[];
815
825
  Error?: CustomComponent<ArrayFieldErrorClientComponent | ArrayFieldErrorServerComponent>;
816
826
  Label?: CustomComponent<ArrayFieldLabelClientComponent | ArrayFieldLabelServerComponent>;
817
827
  RowLabel?: RowLabelComponent;
@@ -848,6 +858,8 @@ export type ArrayFieldClient = {
848
858
  export type RadioField = {
849
859
  admin?: {
850
860
  components?: {
861
+ afterInput?: CustomComponent[];
862
+ beforeInput?: CustomComponent[];
851
863
  Error?: CustomComponent<RadioFieldErrorClientComponent | RadioFieldErrorServerComponent>;
852
864
  Label?: CustomComponent<RadioFieldLabelClientComponent | RadioFieldLabelServerComponent>;
853
865
  } & Admin['components'];
@@ -981,6 +993,8 @@ export type ClientBlock = {
981
993
  export type BlocksField = {
982
994
  admin?: {
983
995
  components?: {
996
+ afterInput?: CustomComponent[];
997
+ beforeInput?: CustomComponent[];
984
998
  Error?: CustomComponent<BlocksFieldErrorClientComponent | BlocksFieldErrorServerComponent>;
985
999
  } & Admin['components'];
986
1000
  initCollapsed?: boolean;