payload 3.42.0 → 3.43.0-canary.0

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 (207) hide show
  1. package/dist/auth/crypto.d.ts.map +1 -1
  2. package/dist/auth/crypto.js +6 -3
  3. package/dist/auth/crypto.js.map +1 -1
  4. package/dist/auth/operations/unlock.d.ts.map +1 -1
  5. package/dist/auth/operations/unlock.js +1 -2
  6. package/dist/auth/operations/unlock.js.map +1 -1
  7. package/dist/auth/strategies/local/authenticate.d.ts.map +1 -1
  8. package/dist/auth/strategies/local/authenticate.js +1 -0
  9. package/dist/auth/strategies/local/authenticate.js.map +1 -1
  10. package/dist/bin/index.js.map +1 -1
  11. package/dist/bin/migrate.d.ts.map +1 -1
  12. package/dist/bin/migrate.js +2 -2
  13. package/dist/bin/migrate.js.map +1 -1
  14. package/dist/collections/config/client.d.ts.map +1 -1
  15. package/dist/collections/config/client.js +3 -1
  16. package/dist/collections/config/client.js.map +1 -1
  17. package/dist/collections/dataloader.d.ts.map +1 -1
  18. package/dist/collections/dataloader.js +0 -1
  19. package/dist/collections/dataloader.js.map +1 -1
  20. package/dist/collections/operations/delete.d.ts.map +1 -1
  21. package/dist/collections/operations/delete.js +1 -2
  22. package/dist/collections/operations/delete.js.map +1 -1
  23. package/dist/collections/operations/findVersions.js +0 -1
  24. package/dist/collections/operations/findVersions.js.map +1 -1
  25. package/dist/collections/operations/update.d.ts.map +1 -1
  26. package/dist/collections/operations/update.js +3 -2
  27. package/dist/collections/operations/update.js.map +1 -1
  28. package/dist/config/client.d.ts.map +1 -1
  29. package/dist/config/client.js +1 -1
  30. package/dist/config/client.js.map +1 -1
  31. package/dist/config/sanitize.d.ts.map +1 -1
  32. package/dist/config/sanitize.js +1 -2
  33. package/dist/config/sanitize.js.map +1 -1
  34. package/dist/database/queryValidation/validateQueryPaths.d.ts.map +1 -1
  35. package/dist/database/queryValidation/validateQueryPaths.js +0 -1
  36. package/dist/database/queryValidation/validateQueryPaths.js.map +1 -1
  37. package/dist/database/queryValidation/validateSearchParams.d.ts.map +1 -1
  38. package/dist/database/queryValidation/validateSearchParams.js +0 -1
  39. package/dist/database/queryValidation/validateSearchParams.js.map +1 -1
  40. package/dist/database/sanitizeJoinQuery.d.ts.map +1 -1
  41. package/dist/database/sanitizeJoinQuery.js +3 -1
  42. package/dist/database/sanitizeJoinQuery.js.map +1 -1
  43. package/dist/fields/config/client.d.ts.map +1 -1
  44. package/dist/fields/config/client.js +6 -1
  45. package/dist/fields/config/client.js.map +1 -1
  46. package/dist/fields/config/sanitize.d.ts.map +1 -1
  47. package/dist/fields/config/sanitize.js +0 -1
  48. package/dist/fields/config/sanitize.js.map +1 -1
  49. package/dist/fields/hooks/afterRead/index.d.ts.map +1 -1
  50. package/dist/fields/hooks/afterRead/index.js +0 -1
  51. package/dist/fields/hooks/afterRead/index.js.map +1 -1
  52. package/dist/fields/hooks/afterRead/relationshipPopulationPromise.d.ts.map +1 -1
  53. package/dist/fields/hooks/afterRead/relationshipPopulationPromise.js +1 -2
  54. package/dist/fields/hooks/afterRead/relationshipPopulationPromise.js.map +1 -1
  55. package/dist/fields/hooks/beforeChange/promise.d.ts.map +1 -1
  56. package/dist/fields/hooks/beforeChange/promise.js +0 -1
  57. package/dist/fields/hooks/beforeChange/promise.js.map +1 -1
  58. package/dist/fields/setDefaultBeforeDuplicate.js.map +1 -1
  59. package/dist/fields/validations.d.ts.map +1 -1
  60. package/dist/fields/validations.js +1 -2
  61. package/dist/fields/validations.js.map +1 -1
  62. package/dist/globals/config/client.d.ts.map +1 -1
  63. package/dist/globals/config/client.js +2 -1
  64. package/dist/globals/config/client.js.map +1 -1
  65. package/dist/index.d.ts.map +1 -1
  66. package/dist/index.js +2 -3
  67. package/dist/index.js.map +1 -1
  68. package/dist/queues/operations/runJobs/index.d.ts.map +1 -1
  69. package/dist/queues/operations/runJobs/index.js +0 -1
  70. package/dist/queues/operations/runJobs/index.js.map +1 -1
  71. package/dist/queues/operations/runJobs/runJSONJob/index.d.ts.map +1 -1
  72. package/dist/queues/operations/runJobs/runJSONJob/index.js +2 -2
  73. package/dist/queues/operations/runJobs/runJSONJob/index.js.map +1 -1
  74. package/dist/queues/operations/runJobs/runJob/getRunTaskFunction.d.ts.map +1 -1
  75. package/dist/queues/operations/runJobs/runJob/getRunTaskFunction.js +0 -1
  76. package/dist/queues/operations/runJobs/runJob/getRunTaskFunction.js.map +1 -1
  77. package/dist/queues/operations/runJobs/runJob/getUpdateJobFunction.d.ts.map +1 -1
  78. package/dist/queues/operations/runJobs/runJob/getUpdateJobFunction.js +1 -1
  79. package/dist/queues/operations/runJobs/runJob/getUpdateJobFunction.js.map +1 -1
  80. package/dist/queues/operations/runJobs/runJob/importHandlerPath.d.ts.map +1 -1
  81. package/dist/queues/operations/runJobs/runJob/importHandlerPath.js +1 -2
  82. package/dist/queues/operations/runJobs/runJob/importHandlerPath.js.map +1 -1
  83. package/dist/queues/operations/runJobs/runJob/index.d.ts.map +1 -1
  84. package/dist/queues/operations/runJobs/runJob/index.js +2 -2
  85. package/dist/queues/operations/runJobs/runJob/index.js.map +1 -1
  86. package/dist/uploads/cropImage.d.ts +0 -1
  87. package/dist/uploads/cropImage.d.ts.map +1 -1
  88. package/dist/uploads/cropImage.js +2 -3
  89. package/dist/uploads/cropImage.js.map +1 -1
  90. package/dist/uploads/endpoints/getFile.d.ts.map +1 -1
  91. package/dist/uploads/endpoints/getFile.js +0 -1
  92. package/dist/uploads/endpoints/getFile.js.map +1 -1
  93. package/dist/uploads/endpoints/getFileFromURL.d.ts.map +1 -1
  94. package/dist/uploads/endpoints/getFileFromURL.js +2 -3
  95. package/dist/uploads/endpoints/getFileFromURL.js.map +1 -1
  96. package/dist/uploads/fetchAPI-multipart/fileFactory.d.ts.map +1 -1
  97. package/dist/uploads/fetchAPI-multipart/fileFactory.js +1 -0
  98. package/dist/uploads/fetchAPI-multipart/fileFactory.js.map +1 -1
  99. package/dist/uploads/fetchAPI-multipart/processMultipart.d.ts +6 -0
  100. package/dist/uploads/fetchAPI-multipart/processMultipart.d.ts.map +1 -1
  101. package/dist/uploads/fetchAPI-multipart/processMultipart.js +0 -1
  102. package/dist/uploads/fetchAPI-multipart/processMultipart.js.map +1 -1
  103. package/dist/uploads/fetchAPI-multipart/processNested.d.ts +1 -1
  104. package/dist/uploads/fetchAPI-multipart/processNested.d.ts.map +1 -1
  105. package/dist/uploads/fetchAPI-multipart/processNested.js +0 -1
  106. package/dist/uploads/fetchAPI-multipart/processNested.js.map +1 -1
  107. package/dist/uploads/fetchAPI-multipart/utilities.d.ts +1 -1
  108. package/dist/uploads/fetchAPI-multipart/utilities.d.ts.map +1 -1
  109. package/dist/uploads/fetchAPI-multipart/utilities.js +0 -1
  110. package/dist/uploads/fetchAPI-multipart/utilities.js.map +1 -1
  111. package/dist/uploads/fetchAPI-stream-file/index.d.ts +1 -1
  112. package/dist/uploads/fetchAPI-stream-file/index.d.ts.map +1 -1
  113. package/dist/uploads/fetchAPI-stream-file/index.js +0 -1
  114. package/dist/uploads/fetchAPI-stream-file/index.js.map +1 -1
  115. package/dist/uploads/tempFile.d.ts +1 -1
  116. package/dist/uploads/tempFile.d.ts.map +1 -1
  117. package/dist/uploads/tempFile.js +0 -1
  118. package/dist/uploads/tempFile.js.map +1 -1
  119. package/dist/utilities/addLocalesToRequest.d.ts.map +1 -1
  120. package/dist/utilities/addLocalesToRequest.js +0 -1
  121. package/dist/utilities/addLocalesToRequest.js.map +1 -1
  122. package/dist/utilities/configToJSONSchema.d.ts.map +1 -1
  123. package/dist/utilities/configToJSONSchema.js +2 -1
  124. package/dist/utilities/configToJSONSchema.js.map +1 -1
  125. package/dist/utilities/deepCopyObject.js +1 -2
  126. package/dist/utilities/deepCopyObject.js.map +1 -1
  127. package/dist/utilities/fieldSchemaToJSON.d.ts.map +1 -1
  128. package/dist/utilities/fieldSchemaToJSON.js +0 -1
  129. package/dist/utilities/fieldSchemaToJSON.js.map +1 -1
  130. package/dist/utilities/flattenTopLevelFields.d.ts.map +1 -1
  131. package/dist/utilities/flattenTopLevelFields.js +0 -1
  132. package/dist/utilities/flattenTopLevelFields.js.map +1 -1
  133. package/dist/utilities/formatErrors.d.ts.map +1 -1
  134. package/dist/utilities/formatErrors.js +0 -1
  135. package/dist/utilities/formatErrors.js.map +1 -1
  136. package/dist/utilities/getCollectionIDFieldTypes.d.ts.map +1 -1
  137. package/dist/utilities/getCollectionIDFieldTypes.js +0 -1
  138. package/dist/utilities/getCollectionIDFieldTypes.js.map +1 -1
  139. package/dist/utilities/getDataByPath.d.ts.map +1 -1
  140. package/dist/utilities/getDataByPath.js +0 -1
  141. package/dist/utilities/getDataByPath.js.map +1 -1
  142. package/dist/utilities/getEntityPolicies.d.ts.map +1 -1
  143. package/dist/utilities/getEntityPolicies.js +3 -2
  144. package/dist/utilities/getEntityPolicies.js.map +1 -1
  145. package/dist/utilities/getFieldPermissions.d.ts.map +1 -1
  146. package/dist/utilities/getFieldPermissions.js +2 -3
  147. package/dist/utilities/getFieldPermissions.js.map +1 -1
  148. package/dist/utilities/getObjectDotNotation.d.ts.map +1 -1
  149. package/dist/utilities/getObjectDotNotation.js +0 -1
  150. package/dist/utilities/getObjectDotNotation.js.map +1 -1
  151. package/dist/utilities/getSiblingData.d.ts.map +1 -1
  152. package/dist/utilities/getSiblingData.js +0 -1
  153. package/dist/utilities/getSiblingData.js.map +1 -1
  154. package/dist/utilities/getUniqueListBy.d.ts.map +1 -1
  155. package/dist/utilities/getUniqueListBy.js +0 -1
  156. package/dist/utilities/getUniqueListBy.js.map +1 -1
  157. package/dist/utilities/handleEndpoints.d.ts.map +1 -1
  158. package/dist/utilities/handleEndpoints.js +2 -2
  159. package/dist/utilities/handleEndpoints.js.map +1 -1
  160. package/dist/utilities/logError.d.ts.map +1 -1
  161. package/dist/utilities/logError.js +0 -1
  162. package/dist/utilities/logError.js.map +1 -1
  163. package/dist/utilities/reduceFieldsToValues.d.ts.map +1 -1
  164. package/dist/utilities/reduceFieldsToValues.js +0 -1
  165. package/dist/utilities/reduceFieldsToValues.js.map +1 -1
  166. package/dist/utilities/sanitizeJoinParams.d.ts +1 -1
  167. package/dist/utilities/sanitizeJoinParams.d.ts.map +1 -1
  168. package/dist/utilities/sanitizeJoinParams.js +2 -2
  169. package/dist/utilities/sanitizeJoinParams.js.map +1 -1
  170. package/dist/utilities/sanitizePermissions.d.ts.map +1 -1
  171. package/dist/utilities/sanitizePermissions.js +2 -2
  172. package/dist/utilities/sanitizePermissions.js.map +1 -1
  173. package/dist/utilities/sanitizePopulateParam.d.ts.map +1 -1
  174. package/dist/utilities/sanitizePopulateParam.js +1 -1
  175. package/dist/utilities/sanitizePopulateParam.js.map +1 -1
  176. package/dist/utilities/sanitizeSelectParam.d.ts.map +1 -1
  177. package/dist/utilities/sanitizeSelectParam.js +4 -2
  178. package/dist/utilities/sanitizeSelectParam.js.map +1 -1
  179. package/dist/utilities/telemetry/conf/envPaths.d.ts +1 -1
  180. package/dist/utilities/telemetry/conf/envPaths.d.ts.map +1 -1
  181. package/dist/utilities/telemetry/conf/envPaths.js.map +1 -1
  182. package/dist/utilities/timestamp.d.ts +1 -1
  183. package/dist/utilities/timestamp.d.ts.map +1 -1
  184. package/dist/utilities/timestamp.js +0 -1
  185. package/dist/utilities/timestamp.js.map +1 -1
  186. package/dist/utilities/traverseFields.d.ts.map +1 -1
  187. package/dist/utilities/traverseFields.js +6 -1
  188. package/dist/utilities/traverseFields.js.map +1 -1
  189. package/dist/utilities/unflatten.d.ts.map +1 -1
  190. package/dist/utilities/unflatten.js +1 -2
  191. package/dist/utilities/unflatten.js.map +1 -1
  192. package/dist/utilities/wait.d.ts +1 -1
  193. package/dist/utilities/wait.d.ts.map +1 -1
  194. package/dist/utilities/wait.js +0 -1
  195. package/dist/utilities/wait.js.map +1 -1
  196. package/dist/versions/baseFields.d.ts +2 -7
  197. package/dist/versions/baseFields.d.ts.map +1 -1
  198. package/dist/versions/baseFields.js.map +1 -1
  199. package/dist/versions/drafts/replaceWithDraftIfAvailable.d.ts.map +1 -1
  200. package/dist/versions/drafts/replaceWithDraftIfAvailable.js +1 -0
  201. package/dist/versions/drafts/replaceWithDraftIfAvailable.js.map +1 -1
  202. package/dist/versions/getLatestGlobalVersion.d.ts.map +1 -1
  203. package/dist/versions/getLatestGlobalVersion.js +3 -1
  204. package/dist/versions/getLatestGlobalVersion.js.map +1 -1
  205. package/dist/versions/saveVersion.js +1 -1
  206. package/dist/versions/saveVersion.js.map +1 -1
  207. package/package.json +3 -5
@@ -1 +1 @@
1
- {"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../../src/auth/crypto.ts"],"names":[],"mappings":"AAKA,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAU5C;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAS5C"}
1
+ {"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../../src/auth/crypto.ts"],"names":[],"mappings":"AAIA,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAY5C;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAW5C"}
@@ -1,9 +1,10 @@
1
- // @ts-strict-ignore
2
1
  import crypto from 'crypto';
3
2
  const algorithm = 'aes-256-ctr';
4
3
  export function encrypt(text) {
5
4
  const iv = crypto.randomBytes(16);
6
- const cipher = crypto.createCipheriv(algorithm, this.secret, iv);
5
+ // @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve
6
+ const secret = this.secret;
7
+ const cipher = crypto.createCipheriv(algorithm, secret, iv);
7
8
  const encrypted = Buffer.concat([
8
9
  cipher.update(text),
9
10
  cipher.final()
@@ -15,7 +16,9 @@ export function encrypt(text) {
15
16
  export function decrypt(hash) {
16
17
  const iv = hash.slice(0, 32);
17
18
  const content = hash.slice(32);
18
- const decipher = crypto.createDecipheriv(algorithm, this.secret, Buffer.from(iv, 'hex'));
19
+ // @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve
20
+ const secret = this.secret;
21
+ const decipher = crypto.createDecipheriv(algorithm, secret, Buffer.from(iv, 'hex'));
19
22
  const decrypted = Buffer.concat([
20
23
  decipher.update(Buffer.from(content, 'hex')),
21
24
  decipher.final()
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/auth/crypto.ts"],"sourcesContent":["// @ts-strict-ignore\nimport crypto from 'crypto'\n\nconst algorithm = 'aes-256-ctr'\n\nexport function encrypt(text: string): string {\n const iv = crypto.randomBytes(16)\n const cipher = crypto.createCipheriv(algorithm, this.secret, iv)\n\n const encrypted = Buffer.concat([cipher.update(text), cipher.final()])\n\n const ivString = iv.toString('hex')\n const encryptedString = encrypted.toString('hex')\n\n return `${ivString}${encryptedString}`\n}\n\nexport function decrypt(hash: string): string {\n const iv = hash.slice(0, 32)\n const content = hash.slice(32)\n\n const decipher = crypto.createDecipheriv(algorithm, this.secret, Buffer.from(iv, 'hex'))\n\n const decrypted = Buffer.concat([decipher.update(Buffer.from(content, 'hex')), decipher.final()])\n\n return decrypted.toString()\n}\n"],"names":["crypto","algorithm","encrypt","text","iv","randomBytes","cipher","createCipheriv","secret","encrypted","Buffer","concat","update","final","ivString","toString","encryptedString","decrypt","hash","slice","content","decipher","createDecipheriv","from","decrypted"],"mappings":"AAAA,oBAAoB;AACpB,OAAOA,YAAY,SAAQ;AAE3B,MAAMC,YAAY;AAElB,OAAO,SAASC,QAAQC,IAAY;IAClC,MAAMC,KAAKJ,OAAOK,WAAW,CAAC;IAC9B,MAAMC,SAASN,OAAOO,cAAc,CAACN,WAAW,IAAI,CAACO,MAAM,EAAEJ;IAE7D,MAAMK,YAAYC,OAAOC,MAAM,CAAC;QAACL,OAAOM,MAAM,CAACT;QAAOG,OAAOO,KAAK;KAAG;IAErE,MAAMC,WAAWV,GAAGW,QAAQ,CAAC;IAC7B,MAAMC,kBAAkBP,UAAUM,QAAQ,CAAC;IAE3C,OAAO,GAAGD,WAAWE,iBAAiB;AACxC;AAEA,OAAO,SAASC,QAAQC,IAAY;IAClC,MAAMd,KAAKc,KAAKC,KAAK,CAAC,GAAG;IACzB,MAAMC,UAAUF,KAAKC,KAAK,CAAC;IAE3B,MAAME,WAAWrB,OAAOsB,gBAAgB,CAACrB,WAAW,IAAI,CAACO,MAAM,EAAEE,OAAOa,IAAI,CAACnB,IAAI;IAEjF,MAAMoB,YAAYd,OAAOC,MAAM,CAAC;QAACU,SAAST,MAAM,CAACF,OAAOa,IAAI,CAACH,SAAS;QAASC,SAASR,KAAK;KAAG;IAEhG,OAAOW,UAAUT,QAAQ;AAC3B"}
1
+ {"version":3,"sources":["../../src/auth/crypto.ts"],"sourcesContent":["import crypto from 'crypto'\n\nconst algorithm = 'aes-256-ctr'\n\nexport function encrypt(text: string): string {\n const iv = crypto.randomBytes(16)\n // @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve\n const secret = this.secret\n const cipher = crypto.createCipheriv(algorithm, secret, iv)\n\n const encrypted = Buffer.concat([cipher.update(text), cipher.final()])\n\n const ivString = iv.toString('hex')\n const encryptedString = encrypted.toString('hex')\n\n return `${ivString}${encryptedString}`\n}\n\nexport function decrypt(hash: string): string {\n const iv = hash.slice(0, 32)\n const content = hash.slice(32)\n\n // @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve\n const secret = this.secret\n const decipher = crypto.createDecipheriv(algorithm, secret, Buffer.from(iv, 'hex'))\n\n const decrypted = Buffer.concat([decipher.update(Buffer.from(content, 'hex')), decipher.final()])\n\n return decrypted.toString()\n}\n"],"names":["crypto","algorithm","encrypt","text","iv","randomBytes","secret","cipher","createCipheriv","encrypted","Buffer","concat","update","final","ivString","toString","encryptedString","decrypt","hash","slice","content","decipher","createDecipheriv","from","decrypted"],"mappings":"AAAA,OAAOA,YAAY,SAAQ;AAE3B,MAAMC,YAAY;AAElB,OAAO,SAASC,QAAQC,IAAY;IAClC,MAAMC,KAAKJ,OAAOK,WAAW,CAAC;IAC9B,oFAAoF;IACpF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,eAAO,MAAM,eAAe,GAAU,KAAK,SAAS,cAAc,QAC1D,SAAS,CAAC,KAAK,CAAC,KACrB,OAAO,CAAC,OAAO,CA2FjB,CAAA"}
1
+ {"version":3,"file":"unlock.d.ts","sourceRoot":"","sources":["../../../src/auth/operations/unlock.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,gCAAgC,EAChC,UAAU,EACX,MAAM,mCAAmC,CAAA;AAC1C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,KAAK,EAAE,cAAc,EAAS,MAAM,sBAAsB,CAAA;AAWjE,MAAM,MAAM,SAAS,CAAC,KAAK,SAAS,cAAc,IAAI;IACpD,UAAU,EAAE,UAAU,CAAA;IACtB,IAAI,EAAE,gCAAgC,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,CAAA;IACvD,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,GAAG,EAAE,cAAc,CAAA;CACpB,CAAA;AAED,eAAO,MAAM,eAAe,GAAU,KAAK,SAAS,cAAc,QAC1D,SAAS,CAAC,KAAK,CAAC,KACrB,OAAO,CAAC,OAAO,CA2FjB,CAAA"}
@@ -1,4 +1,3 @@
1
- // @ts-strict-ignore
2
1
  import { status as httpStatus } from 'http-status';
3
2
  import { APIError } from '../../errors/index.js';
4
3
  import { Forbidden } from '../../index.js';
@@ -53,7 +52,7 @@ export const unlockOperation = async (args)=>{
53
52
  req,
54
53
  where: whereConstraint
55
54
  });
56
- let result;
55
+ let result = null;
57
56
  if (user) {
58
57
  await resetLoginAttempts({
59
58
  collection: collectionConfig,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/auth/operations/unlock.ts"],"sourcesContent":["// @ts-strict-ignore\nimport { status as httpStatus } from 'http-status'\n\nimport type {\n AuthOperationsFromCollectionSlug,\n Collection,\n} from '../../collections/config/types.js'\nimport type { CollectionSlug } from '../../index.js'\nimport type { PayloadRequest, Where } from '../../types/index.js'\n\nimport { APIError } from '../../errors/index.js'\nimport { Forbidden } from '../../index.js'\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport executeAccess from '../executeAccess.js'\nimport { getLoginOptions } from '../getLoginOptions.js'\nimport { resetLoginAttempts } from '../strategies/local/resetLoginAttempts.js'\n\nexport type Arguments<TSlug extends CollectionSlug> = {\n collection: Collection\n data: AuthOperationsFromCollectionSlug<TSlug>['unlock']\n overrideAccess?: boolean\n req: PayloadRequest\n}\n\nexport const unlockOperation = async <TSlug extends CollectionSlug>(\n args: Arguments<TSlug>,\n): Promise<boolean> => {\n const {\n collection: { config: collectionConfig },\n overrideAccess,\n req: { locale },\n req,\n } = args\n\n const loginWithUsername = collectionConfig.auth.loginWithUsername\n\n const { canLoginWithEmail, canLoginWithUsername } = getLoginOptions(loginWithUsername)\n\n const sanitizedEmail = canLoginWithEmail && (args.data?.email || '').toLowerCase().trim()\n const sanitizedUsername =\n (canLoginWithUsername &&\n 'username' in args.data &&\n typeof args.data.username === 'string' &&\n args.data.username.toLowerCase().trim()) ||\n null\n\n if (collectionConfig.auth.disableLocalStrategy) {\n throw new Forbidden(req.t)\n }\n if (!sanitizedEmail && !sanitizedUsername) {\n throw new APIError(\n `Missing ${collectionConfig.auth.loginWithUsername ? 'username' : 'email'}.`,\n httpStatus.BAD_REQUEST,\n )\n }\n\n try {\n const shouldCommit = await initTransaction(req)\n\n // /////////////////////////////////////\n // Access\n // /////////////////////////////////////\n\n if (!overrideAccess) {\n await executeAccess({ req }, collectionConfig.access.unlock)\n }\n\n // /////////////////////////////////////\n // Unlock\n // /////////////////////////////////////\n\n let whereConstraint: Where = {}\n\n if (canLoginWithEmail && sanitizedEmail) {\n whereConstraint = {\n email: {\n equals: sanitizedEmail,\n },\n }\n } else if (canLoginWithUsername && sanitizedUsername) {\n whereConstraint = {\n username: {\n equals: sanitizedUsername,\n },\n }\n }\n\n const user = await req.payload.db.findOne({\n collection: collectionConfig.slug,\n locale: locale!,\n req,\n where: whereConstraint,\n })\n\n let result\n\n if (user) {\n await resetLoginAttempts({\n collection: collectionConfig,\n doc: user,\n payload: req.payload,\n req,\n })\n result = true\n } else {\n result = null\n }\n\n if (shouldCommit) {\n await commitTransaction(req)\n }\n\n return result\n } catch (error: unknown) {\n await killTransaction(req)\n throw error\n }\n}\n"],"names":["status","httpStatus","APIError","Forbidden","commitTransaction","initTransaction","killTransaction","executeAccess","getLoginOptions","resetLoginAttempts","unlockOperation","args","collection","config","collectionConfig","overrideAccess","req","locale","loginWithUsername","auth","canLoginWithEmail","canLoginWithUsername","sanitizedEmail","data","email","toLowerCase","trim","sanitizedUsername","username","disableLocalStrategy","t","BAD_REQUEST","shouldCommit","access","unlock","whereConstraint","equals","user","payload","db","findOne","slug","where","result","doc","error"],"mappings":"AAAA,oBAAoB;AACpB,SAASA,UAAUC,UAAU,QAAQ,cAAa;AASlD,SAASC,QAAQ,QAAQ,wBAAuB;AAChD,SAASC,SAAS,QAAQ,iBAAgB;AAC1C,SAASC,iBAAiB,QAAQ,uCAAsC;AACxE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,OAAOC,mBAAmB,sBAAqB;AAC/C,SAASC,eAAe,QAAQ,wBAAuB;AACvD,SAASC,kBAAkB,QAAQ,4CAA2C;AAS9E,OAAO,MAAMC,kBAAkB,OAC7BC;IAEA,MAAM,EACJC,YAAY,EAAEC,QAAQC,gBAAgB,EAAE,EACxCC,cAAc,EACdC,KAAK,EAAEC,MAAM,EAAE,EACfD,GAAG,EACJ,GAAGL;IAEJ,MAAMO,oBAAoBJ,iBAAiBK,IAAI,CAACD,iBAAiB;IAEjE,MAAM,EAAEE,iBAAiB,EAAEC,oBAAoB,EAAE,GAAGb,gBAAgBU;IAEpE,MAAMI,iBAAiBF,qBAAqB,AAACT,CAAAA,KAAKY,IAAI,EAAEC,SAAS,EAAC,EAAGC,WAAW,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X,cAAc;YAChB,MAAM5B,kBAAkBY;QAC1B;QAEA,OAAO2B;IACT,EAAE,OAAOE,OAAgB;QACvB,MAAMvC,gBAAgBU;QACtB,MAAM6B;IACR;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../src/auth/operations/unlock.ts"],"sourcesContent":["import { status as httpStatus } from 'http-status'\n\nimport type {\n AuthOperationsFromCollectionSlug,\n Collection,\n} from '../../collections/config/types.js'\nimport type { CollectionSlug } from '../../index.js'\nimport type { PayloadRequest, Where } from '../../types/index.js'\n\nimport { APIError } from '../../errors/index.js'\nimport { Forbidden } from '../../index.js'\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport executeAccess from '../executeAccess.js'\nimport { getLoginOptions } from '../getLoginOptions.js'\nimport { resetLoginAttempts } from '../strategies/local/resetLoginAttempts.js'\n\nexport type Arguments<TSlug extends CollectionSlug> = {\n collection: Collection\n data: AuthOperationsFromCollectionSlug<TSlug>['unlock']\n overrideAccess?: boolean\n req: PayloadRequest\n}\n\nexport const unlockOperation = async <TSlug extends CollectionSlug>(\n args: Arguments<TSlug>,\n): Promise<boolean> => {\n const {\n collection: { config: collectionConfig },\n overrideAccess,\n req: { locale },\n req,\n } = args\n\n const loginWithUsername = collectionConfig.auth.loginWithUsername\n\n const { canLoginWithEmail, canLoginWithUsername } = getLoginOptions(loginWithUsername)\n\n const sanitizedEmail = canLoginWithEmail && (args.data?.email || '').toLowerCase().trim()\n const sanitizedUsername =\n (canLoginWithUsername &&\n 'username' in args.data &&\n typeof args.data.username === 'string' &&\n args.data.username.toLowerCase().trim()) ||\n null\n\n if (collectionConfig.auth.disableLocalStrategy) {\n throw new Forbidden(req.t)\n }\n if (!sanitizedEmail && !sanitizedUsername) {\n throw new APIError(\n `Missing ${collectionConfig.auth.loginWithUsername ? 'username' : 'email'}.`,\n httpStatus.BAD_REQUEST,\n )\n }\n\n try {\n const shouldCommit = await initTransaction(req)\n\n // /////////////////////////////////////\n // Access\n // /////////////////////////////////////\n\n if (!overrideAccess) {\n await executeAccess({ req }, collectionConfig.access.unlock)\n }\n\n // /////////////////////////////////////\n // Unlock\n // /////////////////////////////////////\n\n let whereConstraint: Where = {}\n\n if (canLoginWithEmail && sanitizedEmail) {\n whereConstraint = {\n email: {\n equals: sanitizedEmail,\n },\n }\n } else if (canLoginWithUsername && sanitizedUsername) {\n whereConstraint = {\n username: {\n equals: sanitizedUsername,\n },\n }\n }\n\n const user = await req.payload.db.findOne({\n collection: collectionConfig.slug,\n locale: locale!,\n req,\n where: whereConstraint,\n })\n\n let result: boolean | null = null\n\n if (user) {\n await resetLoginAttempts({\n collection: collectionConfig,\n doc: user,\n payload: req.payload,\n req,\n })\n result = true\n } else {\n result = null\n }\n\n if (shouldCommit) {\n await commitTransaction(req)\n }\n\n return result!\n } catch (error: unknown) {\n await killTransaction(req)\n throw error\n }\n}\n"],"names":["status","httpStatus","APIError","Forbidden","commitTransaction","initTransaction","killTransaction","executeAccess","getLoginOptions","resetLoginAttempts","unlockOperation","args","collection","config","collectionConfig","overrideAccess","req","locale","loginWithUsername","auth","canLoginWithEmail","canLoginWithUsername","sanitizedEmail","data","email","toLowerCase","trim","sanitizedUsername","username","disableLocalStrategy","t","BAD_REQUEST","shouldCommit","access","unlock","whereConstraint","equals","user","payload","db","findOne","slug","where","result","doc","error"],"mappings":"AAAA,SAASA,UAAUC,UAAU,QAAQ,cAAa;AASlD,SAASC,QAAQ,QAAQ,wBAAuB;AAChD,SAASC,SAAS,QAAQ,iBAAgB;AAC1C,SAASC,iBAAiB,QAAQ,uCAAsC;AACxE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,OAAOC,mBAAmB,sBAAqB;AAC/C,SAASC,eAAe,QAAQ,wBAAuB;AACvD,SAASC,kBAAkB,QAAQ,4CAA2C;AAS9E,OAAO,MAAMC,kBAAkB,OAC7BC;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F;QACF;QAEA,MAAMU,OAAO,MAAMrB,IAAIsB,OAAO,CAACC,EAAE,CAACC,OAAO,CAAC;YACxC5B,YAAYE,iBAAiB2B,IAAI;YACjCxB,QAAQA;YACRD;YACA0B,OAAOP;QACT;QAEA,IAAIQ,SAAyB;QAE7B,IAAIN,MAAM;YACR,MAAM5B,mBAAmB;gBACvBG,YAAYE;gBACZ8B,KAAKP;gBACLC,SAAStB,IAAIsB,OAAO;gBACpBtB;YACF;YACA2B,SAAS;QACX,OAAO;YACLA,SAAS;QACX;QAEA,IAAIX,cAAc;YAChB,MAAM5B,kBAAkBY;QAC1B;QAEA,OAAO2B;IACT,EAAE,OAAOE,OAAgB;QACvB,MAAMvC,gBAAgBU;QACtB,MAAM6B;IACR;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"authenticate.d.ts","sourceRoot":"","sources":["../../../../src/auth/strategies/local/authenticate.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAA;AAEtE,KAAK,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,UAAU,CAAA;AAE/C,KAAK,IAAI,GAAG;IACV,GAAG,EAAE,GAAG,CAAA;IACR,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,eAAO,MAAM,yBAAyB,sBAA6B,IAAI,KAAG,OAAO,CAAC,GAAG,GAAG,IAAI,CA0B3F,CAAA"}
1
+ {"version":3,"file":"authenticate.d.ts","sourceRoot":"","sources":["../../../../src/auth/strategies/local/authenticate.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAA;AAEtE,KAAK,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,UAAU,CAAA;AAE/C,KAAK,IAAI,GAAG;IACV,GAAG,EAAE,GAAG,CAAA;IACR,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,eAAO,MAAM,yBAAyB,sBAA6B,IAAI,KAAG,OAAO,CAAC,GAAG,GAAG,IAAI,CA0B3F,CAAA"}
@@ -1,5 +1,6 @@
1
1
  // @ts-strict-ignore
2
2
  import crypto from 'crypto';
3
+ // @ts-expect-error - no types available
3
4
  import scmp from 'scmp';
4
5
  export const authenticateLocalStrategy = async ({ doc, password })=>{
5
6
  try {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/auth/strategies/local/authenticate.ts"],"sourcesContent":["// @ts-strict-ignore\nimport crypto from 'crypto'\nimport scmp from 'scmp'\n\nimport type { TypeWithID } from '../../../collections/config/types.js'\n\ntype Doc = Record<string, unknown> & TypeWithID\n\ntype Args = {\n doc: Doc\n password: string\n}\n\nexport const authenticateLocalStrategy = async ({ doc, password }: Args): Promise<Doc | null> => {\n try {\n const { hash, salt } = doc\n\n if (typeof salt === 'string' && typeof hash === 'string') {\n const res = await new Promise<Doc | null>((resolve, reject) => {\n crypto.pbkdf2(password, salt, 25000, 512, 'sha256', (e, hashBuffer) => {\n if (e) {\n reject(e)\n }\n\n if (scmp(hashBuffer, Buffer.from(hash, 'hex'))) {\n resolve(doc)\n } else {\n reject(new Error('Invalid password'))\n }\n })\n })\n\n return res\n }\n\n return null\n } catch (ignore) {\n return null\n }\n}\n"],"names":["crypto","scmp","authenticateLocalStrategy","doc","password","hash","salt","res","Promise","resolve","reject","pbkdf2","e","hashBuffer","Buffer","from","Error","ignore"],"mappings":"AAAA,oBAAoB;AACpB,OAAOA,YAAY,SAAQ;AAC3B,OAAOC,UAAU,OAAM;AAWvB,OAAO,MAAMC,4BAA4B,OAAO,EAAEC,GAAG,EAAEC,QAAQ,EAAQ;IACrE,IAAI;QACF,MAAM,EAAEC,IAAI,EAAEC,IAAI,EAAE,GAAGH;QAEvB,IAAI,OAAOG,SAAS,YAAY,OAAOD,SAAS,UAAU;YACxD,MAAME,MAAM,MAAM,IAAIC,QAAoB,CAACC,SAASC;gBAClDV,OAAOW,MAAM,CAACP,UAAUE,MAAM,OAAO,KAAK,UAAU,CAACM,GAAGC;oBACtD,IAAID,GAAG;wBACLF,OAAOE;oBACT;oBAEA,IAAIX,KAAKY,YAAYC,OAAOC,IAAI,CAACV,MAAM,SAAS;wBAC9CI,QAAQN;oBACV,OAAO;wBACLO,OAAO,IAAIM,MAAM;oBACnB;gBACF;YACF;YAEA,OAAOT;QACT;QAEA,OAAO;IACT,EAAE,OAAOU,QAAQ;QACf,OAAO;IACT;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../../src/auth/strategies/local/authenticate.ts"],"sourcesContent":["// @ts-strict-ignore\nimport crypto from 'crypto'\n// @ts-expect-error - no types available\nimport scmp from 'scmp'\n\nimport type { TypeWithID } from '../../../collections/config/types.js'\n\ntype Doc = Record<string, unknown> & TypeWithID\n\ntype Args = {\n doc: Doc\n password: string\n}\n\nexport const authenticateLocalStrategy = async ({ doc, password }: Args): Promise<Doc | null> => {\n try {\n const { hash, salt } = doc\n\n if (typeof salt === 'string' && typeof hash === 'string') {\n const res = await new Promise<Doc | null>((resolve, reject) => {\n crypto.pbkdf2(password, salt, 25000, 512, 'sha256', (e, hashBuffer) => {\n if (e) {\n reject(e)\n }\n\n if (scmp(hashBuffer, Buffer.from(hash, 'hex'))) {\n resolve(doc)\n } else {\n reject(new Error('Invalid password'))\n }\n })\n })\n\n return res\n }\n\n return null\n } catch (ignore) {\n return null\n }\n}\n"],"names":["crypto","scmp","authenticateLocalStrategy","doc","password","hash","salt","res","Promise","resolve","reject","pbkdf2","e","hashBuffer","Buffer","from","Error","ignore"],"mappings":"AAAA,oBAAoB;AACpB,OAAOA,YAAY,SAAQ;AAC3B,wCAAwC;AACxC,OAAOC,UAAU,OAAM;AAWvB,OAAO,MAAMC,4BAA4B,OAAO,EAAEC,GAAG,EAAEC,QAAQ,EAAQ;IACrE,IAAI;QACF,MAAM,EAAEC,IAAI,EAAEC,IAAI,EAAE,GAAGH;QAEvB,IAAI,OAAOG,SAAS,YAAY,OAAOD,SAAS,UAAU;YACxD,MAAME,MAAM,MAAM,IAAIC,QAAoB,CAACC,SAASC;gBAClDV,OAAOW,MAAM,CAACP,UAAUE,MAAM,OAAO,KAAK,UAAU,CAACM,GAAGC;oBACtD,IAAID,GAAG;wBACLF,OAAOE;oBACT;oBAEA,IAAIX,KAAKY,YAAYC,OAAOC,IAAI,CAACV,MAAM,SAAS;wBAC9CI,QAAQN;oBACV,OAAO;wBACLO,OAAO,IAAIM,MAAM;oBACnB;gBACF;YACF;YAEA,OAAOT;QACT;QAEA,OAAO;IACT,EAAE,OAAOU,QAAQ;QACf,OAAO;IACT;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/bin/index.ts"],"sourcesContent":["// @ts-strict-ignore\n/* eslint-disable no-console */\nimport { Cron } from 'croner'\nimport minimist from 'minimist'\nimport { pathToFileURL } from 'node:url'\nimport path from 'path'\n\nimport { findConfig } from '../config/find.js'\nimport payload, { getPayload } from '../index.js'\nimport { generateImportMap } from './generateImportMap/index.js'\nimport { generateTypes } from './generateTypes.js'\nimport { info } from './info.js'\nimport { loadEnv } from './loadEnv.js'\nimport { migrate, availableCommands as migrateCommands } from './migrate.js'\n\n// Note: this does not account for any user bin scripts\nconst availableScripts = [\n 'generate:db-schema',\n 'generate:importmap',\n 'generate:types',\n 'info',\n 'jobs:run',\n 'run',\n ...migrateCommands,\n] as const\n\nexport const bin = async () => {\n loadEnv()\n\n const args = minimist(process.argv.slice(2))\n const script = (typeof args._[0] === 'string' ? args._[0] : '').toLowerCase()\n\n if (script === 'info') {\n await info()\n return\n }\n\n if (script === 'run') {\n const scriptPath = args._[1]\n if (!scriptPath) {\n console.error('Please provide a script path to run.')\n process.exit(1)\n }\n\n const absoluteScriptPath = path.resolve(process.cwd(), scriptPath)\n\n // Modify process.argv to remove 'run' and the script path\n const originalArgv = process.argv\n process.argv = [process.argv[0]!, process.argv[1]!, ...args._.slice(2)]\n\n try {\n await import(pathToFileURL(absoluteScriptPath).toString())\n } catch (error) {\n console.error(`Error running script: ${absoluteScriptPath}`)\n console.error(error)\n process.exit(1)\n } finally {\n // Restore original process.argv\n process.argv = originalArgv\n }\n return\n }\n\n const configPath = findConfig()\n const configPromise = await import(pathToFileURL(configPath).toString())\n let config = await configPromise\n if (config.default) {\n config = await config.default\n }\n\n const userBinScript = Array.isArray(config.bin)\n ? config.bin.find(({ key }) => key === script)\n : false\n\n if (userBinScript) {\n try {\n const module = await import(pathToFileURL(userBinScript.scriptPath).toString())\n\n if (!module.script || typeof module.script !== 'function') {\n console.error(\n `Could not find \"script\" function export for script ${userBinScript.key} in ${userBinScript.scriptPath}`,\n )\n } else {\n await module.script(config).catch((err: unknown) => {\n console.log(`Script ${userBinScript.key} failed, details:`)\n console.error(err)\n })\n }\n } catch (err) {\n console.log(`Could not find associated bin script for the ${userBinScript.key} command`)\n console.error(err)\n }\n\n return\n }\n\n if (script.startsWith('migrate')) {\n return migrate({ config, parsedArgs: args }).then(() => process.exit(0))\n }\n\n if (script === 'generate:types') {\n return generateTypes(config)\n }\n\n if (script === 'generate:importmap') {\n return generateImportMap(config)\n }\n\n if (script === 'jobs:run') {\n const payload = await getPayload({ config })\n const limit = args.limit ? parseInt(args.limit, 10) : undefined\n const queue = args.queue ? args.queue : undefined\n\n if (args.cron) {\n new Cron(args.cron, async () => {\n await payload.jobs.run({\n limit,\n queue,\n })\n })\n\n process.stdin.resume() // Keep the process alive\n\n return\n } else {\n await payload.jobs.run({\n limit,\n queue,\n })\n\n await payload.destroy() // close database connections after running jobs so process can exit cleanly\n\n return\n }\n }\n\n if (script === 'generate:db-schema') {\n // Barebones instance to access database adapter, without connecting to the DB\n await payload.init({\n config,\n disableDBConnect: true,\n disableOnInit: true,\n })\n\n if (typeof payload.db.generateSchema !== 'function') {\n payload.logger.error({\n msg: `${payload.db.packageName} does not support database schema generation`,\n })\n\n process.exit(1)\n }\n\n await payload.db.generateSchema({\n log: args.log === 'false' ? false : true,\n prettify: args.prettify === 'false' ? false : true,\n })\n\n process.exit(0)\n }\n\n console.error(script ? `Unknown command: \"${script}\"` : 'Please provide a command to run')\n console.log(`\\nAvailable commands:\\n${availableScripts.map((c) => ` - ${c}`).join('\\n')}`)\n\n process.exit(1)\n}\n"],"names":["Cron","minimist","pathToFileURL","path","findConfig","payload","getPayload","generateImportMap","generateTypes","info","loadEnv","migrate","availableCommands","migrateCommands","availableScripts","bin","args","process","argv","slice","script","_","toLowerCase","scriptPath","console","error","exit","absoluteScriptPath","resolve","cwd","originalArgv","toString","configPath","configPromise","config","default","userBinScript","Array","isArray","find","key","module","catch","err","log","startsWith","parsedArgs","then","limit","parseInt","undefined","queue","cron","jobs","run","stdin","resume","destroy","init","disableDBConnect","disableOnInit","db","generateSchema","logger","msg","packageName","prettify","map","c","join"],"mappings":"AAAA,oBAAoB;AACpB,6BAA6B,GAC7B,SAASA,IAAI,QAAQ,SAAQ;AAC7B,OAAOC,cAAc,WAAU;AAC/B,SAASC,aAAa,QAAQ,WAAU;AACxC,OAAOC,UAAU,OAAM;AAEvB,SAASC,UAAU,QAAQ,oBAAmB;AAC9C,OAAOC,WAAWC,UAAU,QAAQ,cAAa;AACjD,SAASC,iBAAiB,QAAQ,+BAA8B;AAChE,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,IAAI,QAAQ,YAAW;AAChC,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,OAAO,EAAEC,qBAAqBC,eAAe,QAAQ,eAAc;AAE5E,uDAAuD;AACvD,MAAMC,mBAAmB;IACvB;IACA;IACA;IACA;IACA;IACA;OACGD;CACJ;AAED,OAAO,MAAME,MAAM;IACjBL;IAEA,MAAMM,OAAOf,SAASgB,QAAQC,IAAI,CAACC,KAAK,CAAC;IACzC,MAAMC,SAAS,AAAC,CAAA,OAAOJ,KAAKK,CAAC,CAAC,EAAE,KAAK,WAAWL,KAAKK,CAAC,CAAC,EAAE,GAAG,EAAC,EAAGC,WAAW;IAE3E,IAAIF,WAAW,QAAQ;QACrB,MAAMX;QACN;IACF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IAAIrC,WAAW,sBAAsB;QACnC,8EAA8E;QAC9E,MAAMf,QAAQqD,IAAI,CAAC;YACjBxB;YACAyB,kBAAkB;YAClBC,eAAe;QACjB;QAEA,IAAI,OAAOvD,QAAQwD,EAAE,CAACC,cAAc,KAAK,YAAY;YACnDzD,QAAQ0D,MAAM,CAACtC,KAAK,CAAC;gBACnBuC,KAAK,GAAG3D,QAAQwD,EAAE,CAACI,WAAW,CAAC,4CAA4C,CAAC;YAC9E;YAEAhD,QAAQS,IAAI,CAAC;QACf;QAEA,MAAMrB,QAAQwD,EAAE,CAACC,cAAc,CAAC;YAC9BlB,KAAK5B,KAAK4B,GAAG,KAAK,UAAU,QAAQ;YACpCsB,UAAUlD,KAAKkD,QAAQ,KAAK,UAAU,QAAQ;QAChD;QAEAjD,QAAQS,IAAI,CAAC;IACf;IAEAF,QAAQC,KAAK,CAACL,SAAS,CAAC,kBAAkB,EAAEA,OAAO,CAAC,CAAC,GAAG;IACxDI,QAAQoB,GAAG,CAAC,CAAC,uBAAuB,EAAE9B,iBAAiBqD,GAAG,CAAC,CAACC,IAAM,CAAC,IAAI,EAAEA,GAAG,EAAEC,IAAI,CAAC,OAAO;IAE1FpD,QAAQS,IAAI,CAAC;AACf,EAAC"}
1
+ {"version":3,"sources":["../../src/bin/index.ts"],"sourcesContent":["// @ts-strict-ignore\n/* eslint-disable no-console */\nimport { Cron } from 'croner'\nimport minimist from 'minimist'\nimport { pathToFileURL } from 'node:url'\nimport path from 'path'\n\nimport { findConfig } from '../config/find.js'\nimport payload, { getPayload } from '../index.js'\nimport { generateImportMap } from './generateImportMap/index.js'\nimport { generateTypes } from './generateTypes.js'\nimport { info } from './info.js'\nimport { loadEnv } from './loadEnv.js'\nimport { migrate, availableCommands as migrateCommands } from './migrate.js'\n\n// Note: this does not account for any user bin scripts\nconst availableScripts = [\n 'generate:db-schema',\n 'generate:importmap',\n 'generate:types',\n 'info',\n 'jobs:run',\n 'run',\n ...migrateCommands,\n] as const\n\nexport const bin = async () => {\n loadEnv()\n\n const args = minimist(process.argv.slice(2))\n const script = (typeof args._[0] === 'string' ? args._[0] : '').toLowerCase()\n\n if (script === 'info') {\n await info()\n return\n }\n\n if (script === 'run') {\n const scriptPath = args._[1]\n if (!scriptPath) {\n console.error('Please provide a script path to run.')\n process.exit(1)\n }\n\n const absoluteScriptPath = path.resolve(process.cwd(), scriptPath)\n\n // Modify process.argv to remove 'run' and the script path\n const originalArgv = process.argv\n process.argv = [process.argv[0]!, process.argv[1]!, ...args._.slice(2)]\n\n try {\n await import(pathToFileURL(absoluteScriptPath).toString())\n } catch (error) {\n console.error(`Error running script: ${absoluteScriptPath}`)\n console.error(error)\n process.exit(1)\n } finally {\n // Restore original process.argv\n process.argv = originalArgv\n }\n return\n }\n\n const configPath = findConfig()\n const configPromise = await import(pathToFileURL(configPath).toString())\n let config = await configPromise\n if (config.default) {\n config = await config.default\n }\n\n const userBinScript = Array.isArray(config.bin)\n ? config.bin.find(({ key }: { key: string }) => key === script)\n : false\n\n if (userBinScript) {\n try {\n const module = await import(pathToFileURL(userBinScript.scriptPath).toString())\n\n if (!module.script || typeof module.script !== 'function') {\n console.error(\n `Could not find \"script\" function export for script ${userBinScript.key} in ${userBinScript.scriptPath}`,\n )\n } else {\n await module.script(config).catch((err: unknown) => {\n console.log(`Script ${userBinScript.key} failed, details:`)\n console.error(err)\n })\n }\n } catch (err) {\n console.log(`Could not find associated bin script for the ${userBinScript.key} command`)\n console.error(err)\n }\n\n return\n }\n\n if (script.startsWith('migrate')) {\n return migrate({ config, parsedArgs: args }).then(() => process.exit(0))\n }\n\n if (script === 'generate:types') {\n return generateTypes(config)\n }\n\n if (script === 'generate:importmap') {\n return generateImportMap(config)\n }\n\n if (script === 'jobs:run') {\n const payload = await getPayload({ config })\n const limit = args.limit ? parseInt(args.limit, 10) : undefined\n const queue = args.queue ? args.queue : undefined\n\n if (args.cron) {\n new Cron(args.cron, async () => {\n await payload.jobs.run({\n limit,\n queue,\n })\n })\n\n process.stdin.resume() // Keep the process alive\n\n return\n } else {\n await payload.jobs.run({\n limit,\n queue,\n })\n\n await payload.destroy() // close database connections after running jobs so process can exit cleanly\n\n return\n }\n }\n\n if (script === 'generate:db-schema') {\n // Barebones instance to access database adapter, without connecting to the DB\n await payload.init({\n config,\n disableDBConnect: true,\n disableOnInit: true,\n })\n\n if (typeof payload.db.generateSchema !== 'function') {\n payload.logger.error({\n msg: `${payload.db.packageName} does not support database schema generation`,\n })\n\n process.exit(1)\n }\n\n await payload.db.generateSchema({\n log: args.log === 'false' ? false : true,\n prettify: args.prettify === 'false' ? false : true,\n })\n\n process.exit(0)\n }\n\n console.error(script ? `Unknown command: \"${script}\"` : 'Please provide a command to run')\n console.log(`\\nAvailable commands:\\n${availableScripts.map((c) => ` - ${c}`).join('\\n')}`)\n\n process.exit(1)\n}\n"],"names":["Cron","minimist","pathToFileURL","path","findConfig","payload","getPayload","generateImportMap","generateTypes","info","loadEnv","migrate","availableCommands","migrateCommands","availableScripts","bin","args","process","argv","slice","script","_","toLowerCase","scriptPath","console","error","exit","absoluteScriptPath","resolve","cwd","originalArgv","toString","configPath","configPromise","config","default","userBinScript","Array","isArray","find","key","module","catch","err","log","startsWith","parsedArgs","then","limit","parseInt","undefined","queue","cron","jobs","run","stdin","resume","destroy","init","disableDBConnect","disableOnInit","db","generateSchema","logger","msg","packageName","prettify","map","c","join"],"mappings":"AAAA,oBAAoB;AACpB,6BAA6B,GAC7B,SAASA,IAAI,QAAQ,SAAQ;AAC7B,OAAOC,cAAc,WAAU;AAC/B,SAASC,aAAa,QAAQ,WAAU;AACxC,OAAOC,UAAU,OAAM;AAEvB,SAASC,UAAU,QAAQ,oBAAmB;AAC9C,OAAOC,WAAWC,UAAU,QAAQ,cAAa;AACjD,SAASC,iBAAiB,QAAQ,+BAA8B;AAChE,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,IAAI,QAAQ,YAAW;AAChC,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,OAAO,E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names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAE1C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAczD,eAAO,MAAM,iBAAiB,UAQ7B,CAAA;AAID,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,eAAe,CAAA;IACvB,UAAU,EAAE,UAAU,CAAA;CACvB,CAAA;AAED,eAAO,MAAM,OAAO,2BAAkC,IAAI,KAAG,OAAO,CAAC,IAAI,CA4FxE,CAAA"}
1
+ {"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../../src/bin/migrate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAE1C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAczD,eAAO,MAAM,iBAAiB,UAQ7B,CAAA;AAID,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,eAAe,CAAA;IACvB,UAAU,EAAE,UAAU,CAAA;CACvB,CAAA;AAED,eAAO,MAAM,OAAO,2BAAkC,IAAI,KAAG,OAAO,CAAC,IAAI,CA6FxE,CAAA"}
@@ -1,4 +1,3 @@
1
- // @ts-strict-ignore
2
1
  import payload from '../index.js';
3
2
  import { prettySyncLoggerDestination } from '../utilities/logger.js';
4
3
  /**
@@ -67,7 +66,8 @@ export const migrate = async ({ config, parsedArgs })=>{
67
66
  skipEmpty
68
67
  });
69
68
  } catch (err) {
70
- throw new Error(`Error creating migration: ${err.message}`);
69
+ const error = err instanceof Error ? err.message : 'Unknown error';
70
+ throw new Error(`Error creating migration: ${error}`);
71
71
  }
72
72
  break;
73
73
  case 'migrate:down':
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/bin/migrate.ts"],"sourcesContent":["// @ts-strict-ignore\nimport type { ParsedArgs } from 'minimist'\n\nimport type { SanitizedConfig } from '../config/types.js'\n\nimport payload from '../index.js'\nimport { prettySyncLoggerDestination } from '../utilities/logger.js'\n\n/**\n * The default logger's options did not allow for forcing sync logging\n * Using these options, to force both pretty print and sync logging\n */\nconst prettySyncLogger = {\n loggerDestination: prettySyncLoggerDestination,\n loggerOptions: {},\n}\n\nexport const availableCommands = [\n 'migrate',\n 'migrate:create',\n 'migrate:down',\n 'migrate:refresh',\n 'migrate:reset',\n 'migrate:status',\n 'migrate:fresh',\n]\n\nconst availableCommandsMsg = `Available commands: ${availableCommands.join(', ')}`\n\ntype Args = {\n config: SanitizedConfig\n parsedArgs: ParsedArgs\n}\n\nexport const migrate = async ({ config, parsedArgs }: Args): Promise<void> => {\n const { _: args, file, forceAcceptWarning: forceAcceptFromProps, help } = parsedArgs\n\n const formattedArgs = Object.keys(parsedArgs)\n .map((key) => {\n const formattedKey = key.replace(/^[-_]+/, '')\n if (!formattedKey) {\n return null\n }\n\n return formattedKey\n .split('-')\n .map((word, index) =>\n index === 0 ? word.toLowerCase() : word.charAt(0).toUpperCase() + word.slice(1),\n )\n .join('')\n })\n .filter(Boolean)\n\n const forceAcceptWarning = forceAcceptFromProps || formattedArgs.includes('forceAcceptWarning')\n const skipEmpty = formattedArgs.includes('skipEmpty')\n\n if (help) {\n // eslint-disable-next-line no-console\n console.log(`\\n\\n${availableCommandsMsg}\\n`) // Avoid having to init payload to get the logger\n process.exit(0)\n }\n\n process.env.PAYLOAD_MIGRATING = 'true'\n\n // Barebones instance to access database adapter\n await payload.init({\n config,\n disableDBConnect: args[0] === 'migrate:create',\n disableOnInit: true,\n ...prettySyncLogger,\n })\n\n const adapter = payload.db\n\n if (!adapter) {\n throw new Error('No database adapter found')\n }\n\n if (!args.length) {\n payload.logger.error({\n msg: `No migration command provided. ${availableCommandsMsg}`,\n })\n process.exit(1)\n }\n\n switch (args[0]) {\n case 'migrate':\n await adapter.migrate()\n break\n case 'migrate:create':\n try {\n await adapter.createMigration({\n file,\n forceAcceptWarning,\n migrationName: args[1],\n payload,\n skipEmpty,\n })\n } catch (err) {\n throw new Error(`Error creating migration: ${err.message}`)\n }\n break\n case 'migrate:down':\n await adapter.migrateDown()\n break\n case 'migrate:fresh':\n await adapter.migrateFresh({ forceAcceptWarning })\n break\n case 'migrate:refresh':\n await adapter.migrateRefresh()\n break\n case 'migrate:reset':\n await adapter.migrateReset()\n break\n case 'migrate:status':\n await adapter.migrateStatus()\n break\n\n default:\n payload.logger.error({\n msg: `Unknown migration command: ${args[0]}. ${availableCommandsMsg}`,\n })\n process.exit(1)\n }\n\n payload.logger.info('Done.')\n}\n"],"names":["payload","prettySyncLoggerDestination","prettySyncLogger","loggerDestination","loggerOptions","availableCommands","availableCommandsMsg","join","migrate","config","parsedArgs","_","args","file","forceAcceptWarning","forceAcceptFromProps","help","formattedArgs","Object","keys","map","key","formattedKey","replace","split","word","index","toLowerCase","charAt","toUpperCase","slice","filter","Boolean","includes","skipEmpty","console","log","process","exit","env","PAYLOAD_MIGRATING","init","disableDBConnect","disableOnInit","adapter","db","Error","length","logger","error","msg","createMigration","migrationName","err","message","migrateDown","migrateFresh","migrateRefresh","migrateReset","migrateStatus","info"],"mappings":"AAAA,oBAAoB;AAKpB,OAAOA,aAAa,cAAa;AACjC,SAASC,2BAA2B,QAAQ,yBAAwB;AAEpE;;;CAGC,GACD,MAAMC,mBAAmB;IACvBC,mBAAmBF;IACnBG,eAAe,CAAC;AAClB;AAEA,OAAO,MAAMC,oBAAoB;IAC/B;IACA;IACA;IACA;IACA;IACA;IACA;CACD,CAAA;AAED,MAAMC,uBAAuB,CAAC,oBAAoB,EAAED,kBAAkBE,IAAI,CAAC,OAAO;AAOlF,OAAO,MAAMC,UAAU,OAAO,EAAEC,MAAM,EAAEC,UAAU,EAAQ;IACxD,MAAM,EAAEC,GAAGC,IAAI,EAAEC,IAAI,EAAEC,oBAAoBC,oBAAoB,EAAEC,IAAI,EAAE,GAAGN;IAE1E,MAAMO,gBAAgBC,OAAOC,IAAI,CAACT,YAC/BU,GAAG,CAAC,CAACC;QACJ,MAAMC,eAAeD,IAAIE,OAAO,CAA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AAEO,IAAIC,OAAO,EAAE;YAC5D;YACA;QACF,KAAK;YACH,MAAMV,QAAQW,WAAW;YACzB;QACF,KAAK;YACH,MAAMX,QAAQY,YAAY,CAAC;gBAAE1C;YAAmB;YAChD;QACF,KAAK;YACH,MAAM8B,QAAQa,cAAc;YAC5B;QACF,KAAK;YACH,MAAMb,QAAQc,YAAY;YAC1B;QACF,KAAK;YACH,MAAMd,QAAQe,aAAa;YAC3B;QAEF;YACE3D,QAAQgD,MAAM,CAACC,KAAK,CAAC;gBACnBC,KAAK,CAAC,2BAA2B,EAAEtC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAEN,sBAAsB;YACvE;YACA+B,QAAQC,IAAI,CAAC;IACjB;IAEAtC,QAAQgD,MAAM,CAACY,IAAI,CAAC;AACtB,EAAC"}
1
+ {"version":3,"sources":["../../src/bin/migrate.ts"],"sourcesContent":["import type { ParsedArgs } from 'minimist'\n\nimport type { SanitizedConfig } from '../config/types.js'\n\nimport payload from '../index.js'\nimport { prettySyncLoggerDestination } from '../utilities/logger.js'\n\n/**\n * The default logger's options did not allow for forcing sync logging\n * Using these options, to force both pretty print and sync logging\n */\nconst prettySyncLogger = {\n loggerDestination: prettySyncLoggerDestination,\n loggerOptions: {},\n}\n\nexport const availableCommands = [\n 'migrate',\n 'migrate:create',\n 'migrate:down',\n 'migrate:refresh',\n 'migrate:reset',\n 'migrate:status',\n 'migrate:fresh',\n]\n\nconst availableCommandsMsg = `Available commands: ${availableCommands.join(', ')}`\n\ntype Args = {\n config: SanitizedConfig\n parsedArgs: ParsedArgs\n}\n\nexport const migrate = async ({ config, parsedArgs }: Args): Promise<void> => {\n const { _: args, file, forceAcceptWarning: forceAcceptFromProps, help } = parsedArgs\n\n const formattedArgs = Object.keys(parsedArgs)\n .map((key) => {\n const formattedKey = key.replace(/^[-_]+/, '')\n if (!formattedKey) {\n return null\n }\n\n return formattedKey\n .split('-')\n .map((word, index) =>\n index === 0 ? word.toLowerCase() : word.charAt(0).toUpperCase() + word.slice(1),\n )\n .join('')\n })\n .filter(Boolean)\n\n const forceAcceptWarning = forceAcceptFromProps || formattedArgs.includes('forceAcceptWarning')\n const skipEmpty = formattedArgs.includes('skipEmpty')\n\n if (help) {\n // eslint-disable-next-line no-console\n console.log(`\\n\\n${availableCommandsMsg}\\n`) // Avoid having to init payload to get the logger\n process.exit(0)\n }\n\n process.env.PAYLOAD_MIGRATING = 'true'\n\n // Barebones instance to access database adapter\n await payload.init({\n config,\n disableDBConnect: args[0] === 'migrate:create',\n disableOnInit: true,\n ...prettySyncLogger,\n })\n\n const adapter = payload.db\n\n if (!adapter) {\n throw new Error('No database adapter found')\n }\n\n if (!args.length) {\n payload.logger.error({\n msg: `No migration command provided. ${availableCommandsMsg}`,\n })\n process.exit(1)\n }\n\n switch (args[0]) {\n case 'migrate':\n await adapter.migrate()\n break\n case 'migrate:create':\n try {\n await adapter.createMigration({\n file,\n forceAcceptWarning,\n migrationName: args[1],\n payload,\n skipEmpty,\n })\n } catch (err) {\n const error = err instanceof Error ? err.message : 'Unknown error'\n throw new Error(`Error creating migration: ${error}`)\n }\n break\n case 'migrate:down':\n await adapter.migrateDown()\n break\n case 'migrate:fresh':\n await adapter.migrateFresh({ forceAcceptWarning })\n break\n case 'migrate:refresh':\n await adapter.migrateRefresh()\n break\n case 'migrate:reset':\n await adapter.migrateReset()\n break\n case 'migrate:status':\n await adapter.migrateStatus()\n break\n\n default:\n payload.logger.error({\n msg: `Unknown migration command: ${args[0]}. ${availableCommandsMsg}`,\n })\n process.exit(1)\n }\n\n payload.logger.info('Done.')\n}\n"],"names":["payload","prettySyncLoggerDestination","prettySyncLogger","loggerDestination","loggerOptions","availableCommands","availableCommandsMsg","join","migrate","config","parsedArgs","_","args","file","forceAcceptWarning","forceAcceptFromProps","help","formattedArgs","Object","keys","map","key","formattedKey","replace","split","word","index","toLowerCase","charAt","toUpperCase","slice","filter","Boolean","includes","skipEmpty","console","log","process","exit","env","PAYLOAD_MIGRATING","init","disableDBConnect","disableOnInit","adapter","db","Error","length","logger","error","msg","createMigration","migrationName","err","message","migrateDown","migrateFresh","migrateRefresh","migrateReset","migrateStatus","info"],"mappings":"AAIA,OAAOA,aAAa,cAAa;AACjC,SAASC,2BAA2B,QAAQ,yBAAwB;AAEpE;;;CAGC,GACD,MAAMC,mBAAmB;IACvBC,mBAAmBF;IACnBG,eAAe,CAAC;AAClB;AAEA,OAAO,MAAMC,oBAAoB;IAC/B;IACA;IACA;IACA;IACA;IACA;IACA;CACD,CAAA;AAED,MAAMC,uBAAuB,CAAC,oBAAoB,EAAED,kBAAkBE,IAAI,CAAC,OAAO;AAOlF,OAAO,MAAMC,UAAU,OAAO,EAAEC,MAAM,EAAEC,UAAU,EAAQ;IACxD,MAAM,EAAEC,GAAGC,IAAI,EAAEC,IAAI,EAAEC,oBAAoBC,oBAAoB,EAAEC,IAAI,EAAE,GAAGN;IAE1E,MAAMO,gBAAgBC,OAAOC,IAAI,CAACT,YAC/BU,GAAG,CAAC,CAACC;QACJ,MAAMC,eAAeD,IAAIE,OAAO,CAAC,UAAU;QAC3C,IAAI,CAACD,cAAc;YACjB,OAAO;QACT;QAEA,OAAOA,aACJE,KAAK,CAAC,KACNJ,GAAG,CAAC,CAACK,MAAMC,QACVA,UAAU,IAAID,KAAKE,WAAW,KAAKF,KAAKG,MAAM,CAAC,GAAGC,WAAW,KAAKJ,KAAKK,KAAK,CAAC,IAE9EvB,IAAI,CAAC;IACV,GACCwB,MAAM,CAACC;IAEV,MAAMlB,qBAAqBC,wBAAwBE,cAAcgB,QAAQ,CAAC;IAC1E,MAAMC,YAAYjB,cAAcgB,QAAQ,CAAC;IAEzC,IAAIjB,MAAM;QACR,sCAAsC;QACtCmB,QAAQC,GAAG,CAAC,CAAC,IAAI,EAAE9B,qBAAqB,EAAE,CAAC,EAAE,iDAAiD;;QAC9F+B,QAAQC,IAAI,CAAC;IACf;IAEAD,QAAQE,GAAG,CAACC,iBAAiB,GAAG;IAEhC,gDAAgD;IAChD,MAA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AW,CAAA;QACnB,QAAQ,EAAE,WAAW,CAAA;KACtB,CAAA;CACF,GAAG,IAAI,CACN,yBAAyB,EACzB,OAAO,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,GAAG,8BAA8B,CACxE,CAAA;AAiCD,eAAO,MAAM,4BAA4B,oDAKtC;IACD,UAAU,EAAE,yBAAyB,CAAA;IACrC,aAAa,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,eAAe,CAAC,CAAA;IACvD,IAAI,EAAE,UAAU,CAAA;IAChB,SAAS,EAAE,SAAS,CAAA;CACrB,KAAG,sBA+IH,CAAA;AAED,eAAO,MAAM,6BAA6B,qDAKvC;IACD,WAAW,EAAE,yBAAyB,EAAE,CAAA;IACxC,aAAa,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,eAAe,CAAC,CAAA;IACvD,IAAI,EAAE,UAAU,CAAA;IAChB,SAAS,EAAE,SAAS,CAAA;CACrB,KAAG,sBAAsB,EAezB,CAAA"}
@@ -1,4 +1,3 @@
1
- // @ts-strict-ignore
2
1
  import { createClientFields } from '../../fields/config/client.js';
3
2
  const serverOnlyCollectionProperties = [
4
3
  'hooks',
@@ -66,6 +65,7 @@ export const createClientCollectionConfig = ({ collection, defaultIDType, i18n,
66
65
  }
67
66
  break;
68
67
  default:
68
+ ;
69
69
  clientCollection.admin[adminKey] = collection.admin[adminKey];
70
70
  }
71
71
  }
@@ -149,11 +149,13 @@ export const createClientCollectionConfig = ({ collection, defaultIDType, i18n,
149
149
  return sanitizedSize;
150
150
  });
151
151
  } else {
152
+ ;
152
153
  clientCollection.upload[uploadKey] = collection.upload[uploadKey];
153
154
  }
154
155
  }
155
156
  break;
156
157
  default:
158
+ ;
157
159
  clientCollection[key] = collection[key];
158
160
  }
159
161
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/collections/config/client.ts"],"sourcesContent":["// @ts-strict-ignore\nimport type { I18nClient } from '@payloadcms/translations'\n\nimport type { StaticDescription } from '../../admin/types.js'\nimport type { ImportMap } from '../../bin/generateImportMap/index.js'\nimport type {\n LivePreviewConfig,\n ServerOnlyLivePreviewProperties,\n StaticLabel,\n} from '../../config/types.js'\nimport type { ClientField } from '../../fields/config/client.js'\nimport type { Payload } from '../../types/index.js'\nimport type { SanitizedUploadConfig } from '../../uploads/types.js'\nimport type { SanitizedCollectionConfig } from './types.js'\n\nimport { createClientFields } from '../../fields/config/client.js'\n\nexport type ServerOnlyCollectionProperties = keyof Pick<\n SanitizedCollectionConfig,\n | 'access'\n | 'custom'\n | 'endpoints'\n | 'flattenedFields'\n | 'hooks'\n | 'indexes'\n | 'joins'\n | 'polymorphicJoins'\n | 'sanitizedIndexes'\n>\n\nexport type ServerOnlyCollectionAdminProperties = keyof Pick<\n SanitizedCollectionConfig['admin'],\n 'baseListFilter' | 'components' | 'hidden'\n>\n\nexport type ServerOnlyUploadProperties = keyof Pick<\n SanitizedCollectionConfig['upload'],\n | 'adminThumbnail'\n | 'externalFileHeaderFilter'\n | 'handlers'\n | 'modifyResponseHeaders'\n | 'withMetadata'\n>\n\nexport type ClientCollectionConfig = {\n admin: {\n description?: StaticDescription\n livePreview?: Omit<LivePreviewConfig, ServerOnlyLivePreviewProperties>\n preview?: boolean\n } & Omit<\n SanitizedCollectionConfig['admin'],\n | 'components'\n | 'description'\n | 'joins'\n | 'livePreview'\n | 'preview'\n | ServerOnlyCollectionAdminProperties\n >\n auth?: { verify?: true } & Omit<\n SanitizedCollectionConfig['auth'],\n 'forgotPassword' | 'strategies' | 'verify'\n >\n fields: ClientField[]\n labels: {\n plural: StaticLabel\n singular: StaticLabel\n }\n} & Omit<\n SanitizedCollectionConfig,\n 'admin' | 'auth' | 'fields' | 'labels' | ServerOnlyCollectionProperties\n>\n\nconst serverOnlyCollectionProperties: Partial<ServerOnlyCollectionProperties>[] = [\n 'hooks',\n 'access',\n 'endpoints',\n 'custom',\n 'joins',\n 'polymorphicJoins',\n 'flattenedFields',\n 'indexes',\n 'sanitizedIndexes',\n // `upload`\n // `admin`\n // are all handled separately\n]\n\nconst serverOnlyUploadProperties: Partial<ServerOnlyUploadProperties>[] = [\n 'adminThumbnail',\n 'externalFileHeaderFilter',\n 'handlers',\n 'modifyResponseHeaders',\n 'withMetadata',\n]\n\nconst serverOnlyCollectionAdminProperties: Partial<ServerOnlyCollectionAdminProperties>[] = [\n 'hidden',\n 'baseListFilter',\n 'components',\n // 'preview' is handled separately\n // `livePreview` is handled separately\n]\n\nexport const createClientCollectionConfig = ({\n collection,\n defaultIDType,\n i18n,\n importMap,\n}: {\n collection: SanitizedCollectionConfig\n defaultIDType: Payload['config']['db']['defaultIDType']\n i18n: I18nClient\n importMap: ImportMap\n}): ClientCollectionConfig => {\n const clientCollection = {} as Partial<ClientCollectionConfig>\n\n for (const key in collection) {\n if (serverOnlyCollectionProperties.includes(key as any)) {\n continue\n }\n switch (key) {\n case 'admin':\n if (!collection.admin) {\n break\n }\n clientCollection.admin = {} as ClientCollectionConfig['admin']\n for (const adminKey in collection.admin) {\n if (serverOnlyCollectionAdminProperties.includes(adminKey as any)) {\n continue\n }\n\n switch (adminKey) {\n case 'description':\n if (\n typeof collection.admin.description === 'string' ||\n typeof collection.admin.description === 'object'\n ) {\n if (collection.admin.description) {\n clientCollection.admin.description = collection.admin.description\n }\n } else if (typeof collection.admin.description === 'function') {\n const description = collection.admin.description({ t: i18n.t })\n if (description) {\n clientCollection.admin.description = description\n }\n }\n break\n case 'livePreview':\n clientCollection.admin.livePreview =\n {} as ClientCollectionConfig['admin']['livePreview']\n if (collection.admin.livePreview?.breakpoints) {\n clientCollection.admin.livePreview!.breakpoints =\n collection.admin.livePreview.breakpoints\n }\n break\n case 'preview':\n if (collection.admin.preview) {\n clientCollection.admin.preview = true\n }\n break\n default:\n clientCollection.admin[adminKey] = collection.admin[adminKey]\n }\n }\n break\n case 'auth':\n if (!collection.auth) {\n break\n }\n clientCollection.auth = {} as { verify?: true } & SanitizedCollectionConfig['auth']\n if (collection.auth.cookies) {\n clientCollection.auth.cookies = collection.auth.cookies\n }\n if (collection.auth.depth !== undefined) {\n // Check for undefined as it can be a number (0)\n clientCollection.auth.depth = collection.auth.depth\n }\n if (collection.auth.disableLocalStrategy) {\n clientCollection.auth.disableLocalStrategy = collection.auth.disableLocalStrategy\n }\n if (collection.auth.lockTime !== undefined) {\n // Check for undefined as it can be a number (0)\n clientCollection.auth.lockTime = collection.auth.lockTime\n }\n if (collection.auth.loginWithUsername) {\n clientCollection.auth.loginWithUsername = collection.auth.loginWithUsername\n }\n if (collection.auth.maxLoginAttempts !== undefined) {\n // Check for undefined as it can be a number (0)\n clientCollection.auth.maxLoginAttempts = collection.auth.maxLoginAttempts\n }\n if (collection.auth.removeTokenFromResponses) {\n clientCollection.auth.removeTokenFromResponses = collection.auth.removeTokenFromResponses\n }\n\n if (collection.auth.useAPIKey) {\n clientCollection.auth.useAPIKey = collection.auth.useAPIKey\n }\n if (collection.auth.tokenExpiration) {\n clientCollection.auth.tokenExpiration = collection.auth.tokenExpiration\n }\n if (collection.auth.verify) {\n clientCollection.auth.verify = true\n }\n break\n case 'fields':\n clientCollection.fields = createClientFields({\n defaultIDType,\n fields: collection.fields,\n i18n,\n importMap,\n })\n break\n case 'labels':\n clientCollection.labels = {\n plural:\n typeof collection.labels.plural === 'function'\n ? collection.labels.plural({ i18n, t: i18n.t })\n : collection.labels.plural,\n singular:\n typeof collection.labels.singular === 'function'\n ? collection.labels.singular({ i18n, t: i18n.t })\n : collection.labels.singular,\n }\n break\n case 'upload':\n if (!collection.upload) {\n break\n }\n clientCollection.upload = {} as SanitizedUploadConfig\n for (const uploadKey in collection.upload) {\n if (serverOnlyUploadProperties.includes(uploadKey as any)) {\n continue\n }\n if (uploadKey === 'imageSizes') {\n clientCollection.upload.imageSizes = collection.upload.imageSizes?.map((size) => {\n const sanitizedSize = { ...size }\n if ('generateImageName' in sanitizedSize) {\n delete sanitizedSize.generateImageName\n }\n return sanitizedSize\n })\n } else {\n clientCollection.upload[uploadKey] = collection.upload[uploadKey]\n }\n }\n break\n\n default:\n clientCollection[key] = collection[key]\n }\n }\n\n return clientCollection as ClientCollectionConfig\n}\n\nexport const createClientCollectionConfigs = ({\n collections,\n defaultIDType,\n i18n,\n importMap,\n}: {\n collections: SanitizedCollectionConfig[]\n defaultIDType: Payload['config']['db']['defaultIDType']\n i18n: I18nClient\n importMap: ImportMap\n}): ClientCollectionConfig[] => {\n const clientCollections = new Array(collections.length)\n\n for (let i = 0; i < collections.length; i++) {\n const collection = collections[i]!\n\n clientCollections[i] = createClientCollectionConfig({\n collection,\n defaultIDType,\n i18n,\n importMap,\n })\n }\n\n return clientCollections\n}\n"],"names":["createClientFields","serverOnlyCollectionProperties","serverOnlyUploadProperties","serverOnlyCollectionAdminProperties","createClientCollectionConfig","collection","defaultIDType","i18n","importMap","clientCollection","key","includes","admin","adminKey","description","t","livePreview","breakpoints","preview","auth","cookies","depth","undefined","disableLocalStrategy","lockTime","loginWithUsername","maxLoginAttempts","removeTokenFromResponses","useAPIKey","tokenExpiration","verify","fields","labels","plural","singular","upload","uploadKey","imageSizes","map","size","sanitizedSize","generateImageName","createClientCollectionConfigs","collections","clientCollections","Array","length","i"],"mappings":"AAAA,oBAAoB;AAepB,SAASA,kBAAkB,QAAQ,gCAA+B;AAyDlE,MAAMC,iCAA4E;IAChF;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CAID;AAED,MAAMC,6BAAoE;IACxE;IACA;IACA;IACA;IACA;CACD;AAED,MAAMC,sCAAsF;IAC1F;IACA;IACA;CAGD;AAED,OAAO,MAAMC,+BAA+B,CAAC,EAC3CC,UAAU,EACVC,aAAa,EACbC,IAAI,EACJC,SAAS,EAMV;IACC,MAAMC,mBAAmB,CAAC;IAE1B,IAAK,MAAMC,OAAOL,WAAY;QAC5B,IAAIJ,+BAA+BU,QAAQ,CAACD,MAAa;YACvD;QACF;QACA,OAAQA;YACN,KAAK;gBACH,IAAI,CAACL,WAAWO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ACT,EAAC;AAED,OAAO,MAAMiC,gCAAgC,CAAC,EAC5CC,WAAW,EACXrC,aAAa,EACbC,IAAI,EACJC,SAAS,EAMV;IACC,MAAMoC,oBAAoB,IAAIC,MAAMF,YAAYG,MAAM;IAEtD,IAAK,IAAIC,IAAI,GAAGA,IAAIJ,YAAYG,MAAM,EAAEC,IAAK;QAC3C,MAAM1C,aAAasC,WAAW,CAACI,EAAE;QAEjCH,iBAAiB,CAACG,EAAE,GAAG3C,6BAA6B;YAClDC;YACAC;YACAC;YACAC;QACF;IACF;IAEA,OAAOoC;AACT,EAAC"}
1
+ {"version":3,"sources":["../../../src/collections/config/client.ts"],"sourcesContent":["import type { I18nClient, TFunction } from '@payloadcms/translations'\n\nimport type { StaticDescription } from '../../admin/types.js'\nimport type { ImportMap } from '../../bin/generateImportMap/index.js'\nimport type {\n LivePreviewConfig,\n ServerOnlyLivePreviewProperties,\n StaticLabel,\n} from '../../config/types.js'\nimport type { ClientField } from '../../fields/config/client.js'\nimport type { Payload } from '../../types/index.js'\nimport type { SanitizedUploadConfig } from '../../uploads/types.js'\nimport type { SanitizedCollectionConfig } from './types.js'\n\nimport { createClientFields } from '../../fields/config/client.js'\n\nexport type ServerOnlyCollectionProperties = keyof Pick<\n SanitizedCollectionConfig,\n | 'access'\n | 'custom'\n | 'endpoints'\n | 'flattenedFields'\n | 'hooks'\n | 'indexes'\n | 'joins'\n | 'polymorphicJoins'\n | 'sanitizedIndexes'\n>\n\nexport type ServerOnlyCollectionAdminProperties = keyof Pick<\n SanitizedCollectionConfig['admin'],\n 'baseListFilter' | 'components' | 'hidden'\n>\n\nexport type ServerOnlyUploadProperties = keyof Pick<\n SanitizedCollectionConfig['upload'],\n | 'adminThumbnail'\n | 'externalFileHeaderFilter'\n | 'handlers'\n | 'modifyResponseHeaders'\n | 'withMetadata'\n>\n\nexport type ClientCollectionConfig = {\n admin: {\n description?: StaticDescription\n livePreview?: Omit<LivePreviewConfig, ServerOnlyLivePreviewProperties>\n preview?: boolean\n } & Omit<\n SanitizedCollectionConfig['admin'],\n | 'components'\n | 'description'\n | 'joins'\n | 'livePreview'\n | 'preview'\n | ServerOnlyCollectionAdminProperties\n >\n auth?: { verify?: true } & Omit<\n SanitizedCollectionConfig['auth'],\n 'forgotPassword' | 'strategies' | 'verify'\n >\n fields: ClientField[]\n labels: {\n plural: StaticLabel\n singular: StaticLabel\n }\n} & Omit<\n SanitizedCollectionConfig,\n 'admin' | 'auth' | 'fields' | 'labels' | ServerOnlyCollectionProperties\n>\n\nconst serverOnlyCollectionProperties: Partial<ServerOnlyCollectionProperties>[] = [\n 'hooks',\n 'access',\n 'endpoints',\n 'custom',\n 'joins',\n 'polymorphicJoins',\n 'flattenedFields',\n 'indexes',\n 'sanitizedIndexes',\n // `upload`\n // `admin`\n // are all handled separately\n]\n\nconst serverOnlyUploadProperties: Partial<ServerOnlyUploadProperties>[] = [\n 'adminThumbnail',\n 'externalFileHeaderFilter',\n 'handlers',\n 'modifyResponseHeaders',\n 'withMetadata',\n]\n\nconst serverOnlyCollectionAdminProperties: Partial<ServerOnlyCollectionAdminProperties>[] = [\n 'hidden',\n 'baseListFilter',\n 'components',\n // 'preview' is handled separately\n // `livePreview` is handled separately\n]\n\nexport const createClientCollectionConfig = ({\n collection,\n defaultIDType,\n i18n,\n importMap,\n}: {\n collection: SanitizedCollectionConfig\n defaultIDType: Payload['config']['db']['defaultIDType']\n i18n: I18nClient\n importMap: ImportMap\n}): ClientCollectionConfig => {\n const clientCollection = {} as Partial<ClientCollectionConfig>\n\n for (const key in collection) {\n if (serverOnlyCollectionProperties.includes(key as any)) {\n continue\n }\n switch (key) {\n case 'admin':\n if (!collection.admin) {\n break\n }\n clientCollection.admin = {} as ClientCollectionConfig['admin']\n for (const adminKey in collection.admin) {\n if (serverOnlyCollectionAdminProperties.includes(adminKey as any)) {\n continue\n }\n\n switch (adminKey) {\n case 'description':\n if (\n typeof collection.admin.description === 'string' ||\n typeof collection.admin.description === 'object'\n ) {\n if (collection.admin.description) {\n clientCollection.admin.description = collection.admin.description\n }\n } else if (typeof collection.admin.description === 'function') {\n const description = collection.admin.description({ t: i18n.t as TFunction })\n if (description) {\n clientCollection.admin.description = description\n }\n }\n break\n case 'livePreview':\n clientCollection.admin.livePreview =\n {} as ClientCollectionConfig['admin']['livePreview']\n if (collection.admin.livePreview?.breakpoints) {\n clientCollection.admin.livePreview!.breakpoints =\n collection.admin.livePreview.breakpoints\n }\n break\n case 'preview':\n if (collection.admin.preview) {\n clientCollection.admin.preview = true\n }\n break\n default:\n ;(clientCollection as any).admin[adminKey] =\n collection.admin[adminKey as keyof SanitizedCollectionConfig['admin']]\n }\n }\n break\n case 'auth':\n if (!collection.auth) {\n break\n }\n clientCollection.auth = {} as { verify?: true } & SanitizedCollectionConfig['auth']\n if (collection.auth.cookies) {\n clientCollection.auth.cookies = collection.auth.cookies\n }\n if (collection.auth.depth !== undefined) {\n // Check for undefined as it can be a number (0)\n clientCollection.auth.depth = collection.auth.depth\n }\n if (collection.auth.disableLocalStrategy) {\n clientCollection.auth.disableLocalStrategy = collection.auth.disableLocalStrategy\n }\n if (collection.auth.lockTime !== undefined) {\n // Check for undefined as it can be a number (0)\n clientCollection.auth.lockTime = collection.auth.lockTime\n }\n if (collection.auth.loginWithUsername) {\n clientCollection.auth.loginWithUsername = collection.auth.loginWithUsername\n }\n if (collection.auth.maxLoginAttempts !== undefined) {\n // Check for undefined as it can be a number (0)\n clientCollection.auth.maxLoginAttempts = collection.auth.maxLoginAttempts\n }\n if (collection.auth.removeTokenFromResponses) {\n clientCollection.auth.removeTokenFromResponses = collection.auth.removeTokenFromResponses\n }\n\n if (collection.auth.useAPIKey) {\n clientCollection.auth.useAPIKey = collection.auth.useAPIKey\n }\n if (collection.auth.tokenExpiration) {\n clientCollection.auth.tokenExpiration = collection.auth.tokenExpiration\n }\n if (collection.auth.verify) {\n clientCollection.auth.verify = true\n }\n break\n case 'fields':\n clientCollection.fields = createClientFields({\n defaultIDType,\n fields: collection.fields,\n i18n,\n importMap,\n })\n break\n case 'labels':\n clientCollection.labels = {\n plural:\n typeof collection.labels.plural === 'function'\n ? collection.labels.plural({ i18n, t: i18n.t as TFunction })\n : collection.labels.plural,\n singular:\n typeof collection.labels.singular === 'function'\n ? collection.labels.singular({ i18n, t: i18n.t as TFunction })\n : collection.labels.singular,\n }\n break\n case 'upload':\n if (!collection.upload) {\n break\n }\n clientCollection.upload = {} as SanitizedUploadConfig\n for (const uploadKey in collection.upload) {\n if (serverOnlyUploadProperties.includes(uploadKey as any)) {\n continue\n }\n if (uploadKey === 'imageSizes') {\n clientCollection.upload.imageSizes = collection.upload.imageSizes?.map((size) => {\n const sanitizedSize = { ...size }\n if ('generateImageName' in sanitizedSize) {\n delete sanitizedSize.generateImageName\n }\n return sanitizedSize\n })\n } else {\n ;(clientCollection.upload as any)[uploadKey] =\n collection.upload[uploadKey as keyof SanitizedUploadConfig]\n }\n }\n break\n\n default:\n ;(clientCollection as any)[key] = collection[key as keyof SanitizedCollectionConfig]\n }\n }\n\n return clientCollection as ClientCollectionConfig\n}\n\nexport const createClientCollectionConfigs = ({\n collections,\n defaultIDType,\n i18n,\n importMap,\n}: {\n collections: SanitizedCollectionConfig[]\n defaultIDType: Payload['config']['db']['defaultIDType']\n i18n: I18nClient\n importMap: ImportMap\n}): ClientCollectionConfig[] => {\n const clientCollections = new Array(collections.length)\n\n for (let i = 0; i < collections.length; i++) {\n const collection = collections[i]!\n\n clientCollections[i] = createClientCollectionConfig({\n collection,\n defaultIDType,\n i18n,\n importMap,\n })\n }\n\n return clientCollections\n}\n"],"names":["createClientFields","serverOnlyCollectionProperties","serverOnlyUploadProperties","serverOnlyCollectionAdminProperties","createClientCollectionConfig","collection","defaultIDType","i18n","importMap","clientCollection","key","includes","admin","adminKey","description","t","livePreview","breakpoints","preview","auth","cookies","depth","undefined","disableLocalStrategy","lockTime","loginWithUsername","maxLoginAttempts","removeTokenFromResponses","useAPIKey","tokenExpiration","verify","fields","labels","plural","singular","upload","uploadKey","imageSizes","map","size","sanitizedSize","generateImageName","createClientCollectionConfigs","collections","clientCollections","Array","length","i"],"mappings":"AAcA,SAASA,kBAAkB,QAAQ,gCAA+B;AAyDlE,MAAMC,iCAA4E;IAChF;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CAID;AAED,MAAMC,6BAAoE;IACxE;IACA;IACA;IACA;IACA;CACD;AAED,MAAMC,sCAAsF;IAC1F;IACA;IACA;CAGD;AAED,OAAO,MAAMC,+BAA+B,CAAC,EAC3CC,UAAU,EACVC,aAAa,EACbC,IAAI,EACJC,SAAS,EAMV;IACC,MAAMC,mBAAmB,CAAC;IAE1B,IAAK,MAAMC,OAAOL,WAAY;QAC5B,IAAIJ,+BAA+BU,QAAQ,CAACD,MAAa;YACvD;QACF;QACA,OAAQA;YACN,KAAK;gBACH,IAAI,CAACL,WAAWO,KAAK,EAAE;oBACrB;gBACF;gBACAH,iBAAiBG,KAAK,GAAG,CAAC;gBAC1B,IAAK,MAAMC,YAAYR,WAAWO,KAAK,CAAE;oBACvC,IAAIT,oCAAoCQ,QAAQ,CAACE,WAAkB;wBACjE;oBACF;oBAEA,OAAQA;wBACN,KAAK;4BACH,IACE,OAAOR,WAAWO,KAAK,CAACE,WAAW,KAAK,YACxC,OAAOT,WAAWO,KAAK,CAACE,WAAW,KAAK,UACxC;gCACA,IAAIT,WAAWO,KAAK,CAACE,WAAW,EAAE;oCAChCL,iBAAiBG,KAAK,CAACE,WAAW,GAAGT,WAAWO,KAAK,CAACE,WAAW;gCACnE;4BACF,OAAO,IAAI,OAAOT,WAAWO,KAAK,CAACE,WAAW,KAAK,YAAY;gCAC7D,MAAMA,cAAcT,WAAWO,KAAK,CAACE,WAAW,CAAC;oCAAEC,GAAGR,KAAKQ,CAAC;gCAAc;gCAC1E,IAAID,aAAa;oCACfL,iBAAiBG,KAAK,CAACE,WAAW,GAAGA;gCACvC;4BACF;4BACA;wBACF,KAAK;4BACHL,iBAAiBG,KAAK,CAACI,WAAW,GAChC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AAa/B,WAAW8B,MAAM,CAAE;oBACzC,IAAIjC,2BAA2BS,QAAQ,CAACyB,YAAmB;wBACzD;oBACF;oBACA,IAAIA,cAAc,cAAc;wBAC9B3B,iBAAiB0B,MAAM,CAACE,UAAU,GAAGhC,WAAW8B,MAAM,CAACE,UAAU,EAAEC,IAAI,CAACC;4BACtE,MAAMC,gBAAgB;gCAAE,GAAGD,IAAI;4BAAC;4BAChC,IAAI,uBAAuBC,eAAe;gCACxC,OAAOA,cAAcC,iBAAiB;4BACxC;4BACA,OAAOD;wBACT;oBACF,OAAO;;wBACH/B,iBAAiB0B,MAAM,AAAQ,CAACC,UAAU,GAC1C/B,WAAW8B,MAAM,CAACC,UAAyC;oBAC/D;gBACF;gBACA;YAEF;;gBACI3B,gBAAwB,CAACC,IAAI,GAAGL,UAAU,CAACK,IAAuC;QACxF;IACF;IAEA,OAAOD;AACT,EAAC;AAED,OAAO,MAAMiC,gCAAgC,CAAC,EAC5CC,WAAW,EACXrC,aAAa,EACbC,IAAI,EACJC,SAAS,EAMV;IACC,MAAMoC,oBAAoB,IAAIC,MAAMF,YAAYG,MAAM;IAEtD,IAAK,IAAIC,IAAI,GAAGA,IAAIJ,YAAYG,MAAM,EAAEC,IAAK;QAC3C,MAAM1C,aAAasC,WAAW,CAACI,EAAE;QAEjCH,iBAAiB,CAACG,EAAE,GAAG3C,6BAA6B;YAClDC;YACAC;YACAC;YACAC;QACF;IACF;IAEA,OAAOoC;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"dataloader.d.ts","sourceRoot":"","sources":["../../src/collections/dataloader.ts"],"names":[],"mappings":"AAGA,OAAO,UAAU,MAAM,YAAY,CAAA;AAGnC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AACjF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAA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,CAAA;IACvB,QAAQ,CAAC,EAAE,YAAY,CAAA;IACvB,MAAM,CAAC,EAAE,UAAU,CAAA;IACnB,gBAAgB,EAAE,OAAO,CAAA;IACzB,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,MAAM,CAAA;CAC1D,CAAA;AACD,eAAO,MAAM,wBAAwB,sJAalC,kBAAkB,KAAG,MAcpB,CAAA"}
@@ -1,4 +1,3 @@
1
- // @ts-strict-ignore
2
1
  import DataLoader from 'dataloader';
3
2
  import { isValidID } from '../utilities/isValidID.js';
4
3
  // Payload uses `dataloader` to solve the classic GraphQL N+1 problem.
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/collections/dataloader.ts"],"sourcesContent":["// @ts-strict-ignore\nimport type { BatchLoadFn } from 'dataloader'\n\nimport DataLoader from 'dataloader'\n\nimport type { FindArgs } from '../database/types.js'\nimport type { Payload } from '../index.js'\nimport type { PayloadRequest, PopulateType, SelectType } from '../types/index.js'\nimport type { TypeWithID } from './config/types.js'\nimport type { Options } from './operations/local/find.js'\n\nimport { isValidID } from '../utilities/isValidID.js'\n\n// Payload uses `dataloader` to solve the classic GraphQL N+1 problem.\n\n// We keep a list of all documents requested to be populated for any given request\n// and then batch together documents within the same collection,\n// making only 1 find per each collection, rather than `findByID` per each requested doc.\n\n// This dramatically improves performance for REST and Local API `depth` populations,\n// and also ensures complex GraphQL queries perform lightning-fast.\n\nconst batchAndLoadDocs =\n (req: PayloadRequest): BatchLoadFn<string, TypeWithID> =>\n async (keys: string[]): Promise<TypeWithID[]> => {\n const { payload } = req\n\n // Create docs array of same length as keys, using null as value\n // We will replace nulls with injected docs as they are retrieved\n const docs: (null | TypeWithID)[] = keys.map(() => null)\n\n /**\n * Batch IDs by their `find` args\n * so we can make one find query per combination of collection, depth, locale, and fallbackLocale.\n *\n * Resulting shape will be as follows:\n {\n // key is stringified set of find args\n '[null,\"pages\",2,0,\"es\",\"en\",false,false]': [\n // value is array of IDs to find with these args\n 'q34tl23462346234524',\n '435523540194324280',\n '2346245j35l3j5234532li',\n ],\n // etc\n };\n *\n **/\n\n const batchByFindArgs = {}\n\n for (const key of keys) {\n const [\n transactionID,\n collection,\n id,\n depth,\n currentDepth,\n locale,\n fallbackLocale,\n overrideAccess,\n showHiddenFields,\n draft,\n select,\n populate,\n ] = JSON.parse(key)\n\n const batchKeyArray = [\n transactionID,\n collection,\n depth,\n currentDepth,\n locale,\n fallbackLocale,\n overrideAccess,\n showHiddenFields,\n draft,\n select,\n populate,\n ]\n\n const batchKey = JSON.stringify(batchKeyArray)\n\n const idType = payload.collections?.[collection]?.customIDType || payload.db.defaultIDType\n const sanitizedID = idType === 'number' ? parseFloat(id) : id\n\n if (isValidID(sanitizedID, idType)) {\n batchByFindArgs[batchKey] = [...(batchByFindArgs[batchKey] || []), sanitizedID]\n }\n }\n\n // Run find requests one after another, so as to not hang transactions\n\n for (const [batchKey, ids] of Object.entries(batchByFindArgs)) {\n const [\n transactionID,\n collection,\n depth,\n currentDepth,\n locale,\n fallbackLocale,\n overrideAccess,\n showHiddenFields,\n draft,\n select,\n populate,\n ] = JSON.parse(batchKey)\n\n req.transactionID = transactionID\n\n const result = await payload.find({\n collection,\n currentDepth,\n depth,\n disableErrors: true,\n draft,\n fallbackLocale,\n locale,\n overrideAccess: Boolean(overrideAccess),\n pagination: false,\n populate,\n req,\n select,\n showHiddenFields: Boolean(showHiddenFields),\n where: {\n id: {\n in: ids,\n },\n },\n })\n\n // For each returned doc, find index in original keys\n // Inject doc within docs array if index exists\n for (const doc of result.docs) {\n const docKey = createDataloaderCacheKey({\n collectionSlug: collection,\n currentDepth,\n depth,\n docID: doc.id,\n draft,\n fallbackLocale,\n locale,\n overrideAccess,\n populate,\n select,\n showHiddenFields,\n transactionID: req.transactionID!,\n })\n const docsIndex = keys.findIndex((key) => key === docKey)\n\n if (docsIndex > -1) {\n docs[docsIndex] = doc\n }\n }\n }\n\n // Return docs array,\n // which has now been injected with all fetched docs\n // and should match the length of the incoming keys arg\n return docs as TypeWithID[]\n }\n\nexport const getDataLoader = (req: PayloadRequest) => {\n const findQueries = new Map()\n const dataLoader = new DataLoader(batchAndLoadDocs(req)) as PayloadRequest['payloadDataLoader']\n\n dataLoader.find = ((args: FindArgs) => {\n const key = createFindDataloaderCacheKey(args)\n const cached = findQueries.get(key)\n if (cached) {\n return cached\n }\n const request = req.payload.find(args)\n findQueries.set(key, request)\n return request\n }) as Payload['find']\n\n return dataLoader\n}\n\nconst createFindDataloaderCacheKey = ({\n collection,\n currentDepth,\n depth,\n disableErrors,\n draft,\n includeLockStatus,\n joins,\n limit,\n overrideAccess,\n page,\n pagination,\n populate,\n req,\n select,\n showHiddenFields,\n sort,\n where,\n}: Options<string, SelectType>): string =>\n JSON.stringify([\n collection,\n currentDepth,\n depth,\n disableErrors,\n draft,\n includeLockStatus,\n joins,\n limit,\n overrideAccess,\n page,\n pagination,\n populate,\n req?.locale,\n req?.fallbackLocale,\n req?.user?.id,\n req?.transactionID,\n select,\n showHiddenFields,\n sort,\n where,\n ])\n\ntype CreateCacheKeyArgs = {\n collectionSlug: string\n currentDepth: number\n depth: number\n docID: number | string\n draft: boolean\n fallbackLocale: string\n locale: string\n overrideAccess: boolean\n populate?: PopulateType\n select?: SelectType\n showHiddenFields: boolean\n transactionID: number | Promise<number | string> | string\n}\nexport const createDataloaderCacheKey = ({\n collectionSlug,\n currentDepth,\n depth,\n docID,\n draft,\n fallbackLocale,\n locale,\n overrideAccess,\n populate,\n select,\n showHiddenFields,\n transactionID,\n}: CreateCacheKeyArgs): string =>\n JSON.stringify([\n transactionID,\n collectionSlug,\n docID,\n depth,\n currentDepth,\n locale,\n fallbackLocale,\n overrideAccess,\n showHiddenFields,\n draft,\n select,\n populate,\n ])\n"],"names":["DataLoader","isValidID","batchAndLoadDocs","req","keys","payload","docs","map","batchByFindArgs","key","transactionID","collection","id","depth","currentDepth","locale","fallbackLocale","overrideAccess","showHiddenFields","draft","select","populate","JSON","parse","batchKeyArray","batchKey","stringify","idType","collections","customIDType","db","defaultIDType","sanitizedID","parseFloat","ids","Object","entries","result","find","disableErrors","Boolean","pagination","where","in","doc","docKey","createDataloaderCacheKey","collectionSlug","docID","docsIndex","findIndex","getDataLoader","findQueries","Map","dataLoader","args","createFindDataloaderCacheKey","cached","get","request","set","includeLockStatus","joins","limit","page","sort","user"],"mappings":"AAAA,oBAAoB;AAGpB,OAAOA,gBAAgB,aAAY;AAQnC,SAASC,SAAS,QAAQ,4BAA2B;AAErD,sEAAsE;AAEtE,kFAAkF;AAClF,gEAAgE;AAChE,yFAAyF;AAEzF,qFAAqF;AACrF,mEAAmE;AAEnE,MAAMC,mBACJ,CAACC,MACD,OAAOC;QACL,MAAM,EAAEC,OAAO,EAAE,GAAGF;QAEpB,gEAAgE;QAChE,iEAAiE;QACjE,MAAMG,OAA8BF,KAAKG,GAAG,CAAC,IAAM;QAEnD;;;;;;;;;;;;;;;;KAgBC,GAED,MAAMC,kBAAkB,CAAC;QAEzB,KAAK,MAAMC,OAAOL,KAAM;YACtB,MAAM,CACJM,eACAC,YACAC,IACAC,OACAC,cACAC,QACAC,gBACAC,gBACAC,kBACAC,OACAC,QACAC,SACD,GAAGC,KAAKC,KAAK,CAACd;YAEf,MAAMe,gBAAgB;gBACpBd;gBACAC;gBACAE;gBACAC;gBACAC;gBACAC;gBACAC;gBACAC;gBACAC;gBACAC;gBACAC;aACD;YAED,MAAMI,WAAWH,KAAKI,SAAS,CAACF;YAEhC,MAAMG,SAAStB,QAAQuB,WAAW,EAAE,CAACjB,WAAW,EAAEkB,gBAAgBxB,QAAQyB,EAAE,CAACC,aAAa;YAC1F,MAAMC,cAAcL,WAAW,WAAWM,WAAWrB,MAAMA;YAE3D,IAAIX,UAAU+B,aAAaL,SAAS;gBAClCnB,eAAe,CAACiB,SAAS,GAAG;uBAAKjB,eAAe,CAACiB,SAAS,IAAI,EAAE;oBAAGO;iBAAY;YACjF;QACF;QAEA,sEAAsE;QAEtE,KAAK,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AAO,CAACiC,IAAI,CAACiB;QACjCH,YAAYQ,GAAG,CAACnD,KAAKkD;QACrB,OAAOA;IACT;IAEA,OAAOL;AACT,EAAC;AAED,MAAME,+BAA+B,CAAC,EACpC7C,UAAU,EACVG,YAAY,EACZD,KAAK,EACL0B,aAAa,EACbpB,KAAK,EACL0C,iBAAiB,EACjBC,KAAK,EACLC,KAAK,EACL9C,cAAc,EACd+C,IAAI,EACJvB,UAAU,EACVpB,QAAQ,EACRlB,GAAG,EACHiB,MAAM,EACNF,gBAAgB,EAChB+C,IAAI,EACJvB,KAAK,EACuB,GAC5BpB,KAAKI,SAAS,CAAC;QACbf;QACAG;QACAD;QACA0B;QACApB;QACA0C;QACAC;QACAC;QACA9C;QACA+C;QACAvB;QACApB;QACAlB,KAAKY;QACLZ,KAAKa;QACLb,KAAK+D,MAAMtD;QACXT,KAAKO;QACLU;QACAF;QACA+C;QACAvB;KACD;AAgBH,OAAO,MAAMI,2BAA2B,CAAC,EACvCC,cAAc,EACdjC,YAAY,EACZD,KAAK,EACLmC,KAAK,EACL7B,KAAK,EACLH,cAAc,EACdD,MAAM,EACNE,cAAc,EACdI,QAAQ,EACRD,MAAM,EACNF,gBAAgB,EAChBR,aAAa,EACM,GACnBY,KAAKI,SAAS,CAAC;QACbhB;QACAqC;QACAC;QACAnC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;KACD,EAAC"}
1
+ {"version":3,"sources":["../../src/collections/dataloader.ts"],"sourcesContent":["import type { BatchLoadFn } from 'dataloader'\n\nimport DataLoader from 'dataloader'\n\nimport type { FindArgs } from '../database/types.js'\nimport type { Payload } from '../index.js'\nimport type { PayloadRequest, PopulateType, SelectType } from '../types/index.js'\nimport type { TypeWithID } from './config/types.js'\nimport type { Options } from './operations/local/find.js'\n\nimport { isValidID } from '../utilities/isValidID.js'\n\n// Payload uses `dataloader` to solve the classic GraphQL N+1 problem.\n\n// We keep a list of all documents requested to be populated for any given request\n// and then batch together documents within the same collection,\n// making only 1 find per each collection, rather than `findByID` per each requested doc.\n\n// This dramatically improves performance for REST and Local API `depth` populations,\n// and also ensures complex GraphQL queries perform lightning-fast.\n\nconst batchAndLoadDocs =\n (req: PayloadRequest): BatchLoadFn<string, TypeWithID> =>\n async (keys: readonly string[]): Promise<TypeWithID[]> => {\n const { payload } = req\n\n // Create docs array of same length as keys, using null as value\n // We will replace nulls with injected docs as they are retrieved\n const docs: (null | TypeWithID)[] = keys.map(() => null)\n\n /**\n * Batch IDs by their `find` args\n * so we can make one find query per combination of collection, depth, locale, and fallbackLocale.\n *\n * Resulting shape will be as follows:\n {\n // key is stringified set of find args\n '[null,\"pages\",2,0,\"es\",\"en\",false,false]': [\n // value is array of IDs to find with these args\n 'q34tl23462346234524',\n '435523540194324280',\n '2346245j35l3j5234532li',\n ],\n // etc\n };\n *\n **/\n\n const batchByFindArgs: Record<string, string[]> = {}\n\n for (const key of keys) {\n const [\n transactionID,\n collection,\n id,\n depth,\n currentDepth,\n locale,\n fallbackLocale,\n overrideAccess,\n showHiddenFields,\n draft,\n select,\n populate,\n ] = JSON.parse(key)\n\n const batchKeyArray = [\n transactionID,\n collection,\n depth,\n currentDepth,\n locale,\n fallbackLocale,\n overrideAccess,\n showHiddenFields,\n draft,\n select,\n populate,\n ]\n\n const batchKey = JSON.stringify(batchKeyArray)\n\n const idType = payload.collections?.[collection]?.customIDType || payload.db.defaultIDType\n const sanitizedID = idType === 'number' ? parseFloat(id) : id\n\n if (isValidID(sanitizedID, idType)) {\n batchByFindArgs[batchKey] = [...(batchByFindArgs[batchKey] || []), sanitizedID]\n }\n }\n\n // Run find requests one after another, so as to not hang transactions\n\n for (const [batchKey, ids] of Object.entries(batchByFindArgs)) {\n const [\n transactionID,\n collection,\n depth,\n currentDepth,\n locale,\n fallbackLocale,\n overrideAccess,\n showHiddenFields,\n draft,\n select,\n populate,\n ] = JSON.parse(batchKey)\n\n req.transactionID = transactionID\n\n const result = await payload.find({\n collection,\n currentDepth,\n depth,\n disableErrors: true,\n draft,\n fallbackLocale,\n locale,\n overrideAccess: Boolean(overrideAccess),\n pagination: false,\n populate,\n req,\n select,\n showHiddenFields: Boolean(showHiddenFields),\n where: {\n id: {\n in: ids,\n },\n },\n })\n\n // For each returned doc, find index in original keys\n // Inject doc within docs array if index exists\n for (const doc of result.docs) {\n const docKey = createDataloaderCacheKey({\n collectionSlug: collection,\n currentDepth,\n depth,\n docID: doc.id,\n draft,\n fallbackLocale,\n locale,\n overrideAccess,\n populate,\n select,\n showHiddenFields,\n transactionID: req.transactionID!,\n })\n const docsIndex = keys.findIndex((key) => key === docKey)\n\n if (docsIndex > -1) {\n docs[docsIndex] = doc\n }\n }\n }\n\n // Return docs array,\n // which has now been injected with all fetched docs\n // and should match the length of the incoming keys arg\n return docs as TypeWithID[]\n }\n\nexport const getDataLoader = (req: PayloadRequest) => {\n const findQueries = new Map()\n const dataLoader = new DataLoader(batchAndLoadDocs(req)) as PayloadRequest['payloadDataLoader']\n\n dataLoader.find = ((args: FindArgs) => {\n const key = createFindDataloaderCacheKey(args)\n const cached = findQueries.get(key)\n if (cached) {\n return cached\n }\n const request = req.payload.find(args)\n findQueries.set(key, request)\n return request\n }) as Payload['find']\n\n return dataLoader\n}\n\nconst createFindDataloaderCacheKey = ({\n collection,\n currentDepth,\n depth,\n disableErrors,\n draft,\n includeLockStatus,\n joins,\n limit,\n overrideAccess,\n page,\n pagination,\n populate,\n req,\n select,\n showHiddenFields,\n sort,\n where,\n}: Options<string, SelectType>): string =>\n JSON.stringify([\n collection,\n currentDepth,\n depth,\n disableErrors,\n draft,\n includeLockStatus,\n joins,\n limit,\n overrideAccess,\n page,\n pagination,\n populate,\n req?.locale,\n req?.fallbackLocale,\n req?.user?.id,\n req?.transactionID,\n select,\n showHiddenFields,\n sort,\n where,\n ])\n\ntype CreateCacheKeyArgs = {\n collectionSlug: string\n currentDepth: number\n depth: number\n docID: number | string\n draft: boolean\n fallbackLocale: string\n locale: string\n overrideAccess: boolean\n populate?: PopulateType\n select?: SelectType\n showHiddenFields: boolean\n transactionID: number | Promise<number | string> | string\n}\nexport const createDataloaderCacheKey = ({\n collectionSlug,\n currentDepth,\n depth,\n docID,\n draft,\n fallbackLocale,\n locale,\n overrideAccess,\n populate,\n select,\n showHiddenFields,\n transactionID,\n}: CreateCacheKeyArgs): string =>\n JSON.stringify([\n transactionID,\n collectionSlug,\n docID,\n depth,\n currentDepth,\n locale,\n fallbackLocale,\n overrideAccess,\n showHiddenFields,\n draft,\n select,\n populate,\n ])\n"],"names":["DataLoader","isValidID","batchAndLoadDocs","req","keys","payload","docs","map","batchByFindArgs","key","transactionID","collection","id","depth","currentDepth","locale","fallbackLocale","overrideAccess","showHiddenFields","draft","select","populate","JSON","parse","batchKeyArray","batchKey","stringify","idType","collections","customIDType","db","defaultIDType","sanitizedID","parseFloat","ids","Object","entries","result","find","disableErrors","Boolean","pagination","where","in","doc","docKey","createDataloaderCacheKey","collectionSlug","docID","docsIndex","findIndex","getDataLoader","findQueries","Map","dataLoader","args","createFindDataloaderCacheKey","cached","get","request","set","includeLockStatus","joins","limit","page","sort","user"],"mappings":"AAEA,OAAOA,gBAAgB,aAAY;AAQnC,SAASC,SAAS,QAAQ,4BAA2B;AAErD,sEAAsE;AAEtE,kFAAkF;AAClF,gEAAgE;AAChE,yFAAyF;AAEzF,qFAAqF;AACrF,mEAAmE;AAEnE,MAAMC,mBACJ,CAACC,MACD,OAAOC;QACL,MAAM,EAAEC,OAAO,EAAE,GAAGF;QAEpB,gEAAgE;QAChE,iEAAiE;QACjE,MAAMG,OAA8BF,KAAKG,GAAG,CAAC,IAAM;QAEnD;;;;;;;;;;;;;;;;KAgBC,GAED,MAAMC,kBAA4C,CAAC;QAEnD,KAAK,MAAMC,OAAOL,KAAM;YACtB,MAAM,CACJM,eACAC,YACAC,IACAC,OACAC,cACAC,QACAC,gBACAC,gBACAC,kBACAC,OACAC,QACAC,SACD,GAAGC,KAAKC,KAAK,CAACd;YAEf,MAAMe,gBAAgB;gBACp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QACAqC;QACAC;QACAnC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;KACD,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"delete.d.ts","sourceRoot":"","sources":["../../../src/collections/operations/delete.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAA;AAC3F,OAAO,KAAK,EACV,mBAAmB,EACnB,UAAU,EAEV,wBAAwB,EACzB,MAAM,oBAAoB,CAAA;AAkB3B,MAAM,MAAM,SAAS,GAAG;IACtB,UAAU,EAAE,UAAU,CAAA;IACtB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,QAAQ,CAAC,EAAE,YAAY,CAAA;IACvB,GAAG,EAAE,cAAc,CAAA;IACnB,MAAM,CAAC,EAAE,UAAU,CAAA;IACnB,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,KAAK,EAAE,KAAK,CAAA;CACb,CAAA;AAED,eAAO,MAAM,eAAe,GAC1B,KAAK,SAAS,cAAc,EAC5B,OAAO,SAAS,wBAAwB,CAAC,KAAK,CAAC,gBAEjC,SAAS,KACtB,OAAO,CAAC,mBAAmB,CAAC,KAAK,EAAE,OAAO,CAAC,CA8Q7C,CAAA"}
1
+ {"version":3,"file":"delete.d.ts","sourceRoot":"","sources":["../../../src/collections/operations/delete.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAA;AAC3F,OAAO,KAAK,EACV,mBAAmB,EACnB,UAAU,EAEV,wBAAwB,EACzB,MAAM,oBAAoB,CAAA;AAkB3B,MAAM,MAAM,SAAS,GAAG;IACtB,UAAU,EAAE,UAAU,CAAA;IACtB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,QAAQ,CAAC,EAAE,YAAY,CAAA;IACvB,GAAG,EAAE,cAAc,CAAA;IACnB,MAAM,CAAC,EAAE,UAAU,CAAA;IACnB,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,KAAK,EAAE,KAAK,CAAA;CACb,CAAA;AAED,eAAO,MAAM,eAAe,GAC1B,KAAK,SAAS,cAAc,EAC5B,OAAO,SAAS,wBAAwB,CAAC,KAAK,CAAC,gBAEjC,SAAS,KACtB,OAAO,CAAC,mBAAmB,CAAC,KAAK,EAAE,OAAO,CAAC,CA8Q7C,CAAA"}
@@ -1,4 +1,3 @@
1
- // @ts-strict-ignore
2
1
  import { status as httpStatus } from 'http-status';
3
2
  import executeAccess from '../../auth/executeAccess.js';
4
3
  import { combineQueries } from '../../database/combineQueries.js';
@@ -191,7 +190,7 @@ export const deleteOperation = async (incomingArgs)=>{
191
190
  } catch (error) {
192
191
  errors.push({
193
192
  id: doc.id,
194
- message: error.message
193
+ message: error instanceof Error ? error.message : 'Unknown error'
195
194
  });
196
195
  }
197
196
  return null;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/collections/operations/delete.ts"],"sourcesContent":["// @ts-strict-ignore\nimport { status as httpStatus } from 'http-status'\n\nimport type { AccessResult } from '../../config/types.js'\nimport type { CollectionSlug } from '../../index.js'\nimport type { PayloadRequest, PopulateType, SelectType, Where } from '../../types/index.js'\nimport type {\n BulkOperationResult,\n Collection,\n DataFromCollectionSlug,\n SelectFromCollectionSlug,\n} from '../config/types.js'\n\nimport executeAccess from '../../auth/executeAccess.js'\nimport { combineQueries } from '../../database/combineQueries.js'\nimport { validateQueryPaths } from '../../database/queryValidation/validateQueryPaths.js'\nimport { APIError } from '../../errors/index.js'\nimport { afterRead } from '../../fields/hooks/afterRead/index.js'\nimport { deleteUserPreferences } from '../../preferences/deleteUserPreferences.js'\nimport { deleteAssociatedFiles } from '../../uploads/deleteAssociatedFiles.js'\nimport { checkDocumentLockStatus } from '../../utilities/checkDocumentLockStatus.js'\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { sanitizeSelect } from '../../utilities/sanitizeSelect.js'\nimport { deleteCollectionVersions } from '../../versions/deleteCollectionVersions.js'\nimport { deleteScheduledPublishJobs } from '../../versions/deleteScheduledPublishJobs.js'\nimport { buildAfterOperation } from './utils.js'\n\nexport type Arguments = {\n collection: Collection\n depth?: number\n disableTransaction?: boolean\n overrideAccess?: boolean\n overrideLock?: boolean\n populate?: PopulateType\n req: PayloadRequest\n select?: SelectType\n showHiddenFields?: boolean\n where: Where\n}\n\nexport const deleteOperation = async <\n TSlug extends CollectionSlug,\n TSelect extends SelectFromCollectionSlug<TSlug>,\n>(\n incomingArgs: Arguments,\n): Promise<BulkOperationResult<TSlug, TSelect>> => {\n let args = incomingArgs\n\n try {\n const shouldCommit = !args.disableTransaction && (await initTransaction(args.req))\n // /////////////////////////////////////\n // beforeOperation - Collection\n // /////////////////////////////////////\n\n if (args.collection.config.hooks?.beforeOperation?.length) {\n for (const hook of args.collection.config.hooks.beforeOperation) {\n args =\n (await hook({\n args,\n collection: args.collection.config,\n context: args.req.context,\n operation: 'delete',\n req: args.req,\n })) || args\n }\n }\n\n const {\n collection: { config: collectionConfig },\n depth,\n overrideAccess,\n overrideLock,\n populate,\n req: {\n fallbackLocale,\n locale,\n payload: { config },\n payload,\n },\n req,\n select: incomingSelect,\n showHiddenFields,\n where,\n } = args\n\n if (!where) {\n throw new APIError(\"Missing 'where' query of documents to delete.\", httpStatus.BAD_REQUEST)\n }\n\n // /////////////////////////////////////\n // Access\n // /////////////////////////////////////\n\n let accessResult: AccessResult\n\n if (!overrideAccess) {\n accessResult = await executeAccess({ req }, collectionConfig.access.delete)\n }\n\n await validateQueryPaths({\n collectionConfig,\n overrideAccess: overrideAccess!,\n req,\n where,\n })\n\n const fullWhere = combineQueries(where, accessResult!)\n\n const select = sanitizeSelect({\n fields: collectionConfig.flattenedFields,\n forceSelect: collectionConfig.forceSelect,\n select: incomingSelect,\n })\n\n // /////////////////////////////////////\n // Retrieve documents\n // /////////////////////////////////////\n\n const { docs } = await payload.db.find<DataFromCollectionSlug<TSlug>>({\n collection: collectionConfig.slug,\n locale: locale!,\n req,\n select,\n where: fullWhere,\n })\n\n const errors: { id: number | string; message: string }[] = []\n\n const promises = docs.map(async (doc) => {\n let result\n\n const { id } = doc\n\n try {\n // /////////////////////////////////////\n // Handle potentially locked documents\n // /////////////////////////////////////\n\n await checkDocumentLockStatus({\n id,\n collectionSlug: collectionConfig.slug,\n lockErrorMessage: `Document with ID ${id} is currently locked and cannot be deleted.`,\n overrideLock,\n req,\n })\n\n // /////////////////////////////////////\n // beforeDelete - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.beforeDelete?.length) {\n for (const hook of collectionConfig.hooks.beforeDelete) {\n await hook({\n id,\n collection: collectionConfig,\n context: req.context,\n req,\n })\n }\n }\n\n await deleteAssociatedFiles({\n collectionConfig,\n config,\n doc,\n overrideDelete: true,\n req,\n })\n\n // /////////////////////////////////////\n // Delete versions\n // /////////////////////////////////////\n\n if (collectionConfig.versions) {\n await deleteCollectionVersions({\n id,\n slug: collectionConfig.slug,\n payload,\n req,\n })\n }\n\n // /////////////////////////////////////\n // Delete scheduled posts\n // /////////////////////////////////////\n if (collectionConfig.versions?.drafts && collectionConfig.versions.drafts.schedulePublish) {\n await deleteScheduledPublishJobs({\n id,\n slug: collectionConfig.slug,\n payload,\n req,\n })\n }\n\n // /////////////////////////////////////\n // Delete document\n // /////////////////////////////////////\n\n await payload.db.deleteOne({\n collection: collectionConfig.slug,\n req,\n returning: false,\n where: {\n id: {\n equals: id,\n },\n },\n })\n\n // /////////////////////////////////////\n // afterRead - Fields\n // /////////////////////////////////////\n\n result = await afterRead({\n collection: collectionConfig,\n context: req.context,\n depth: depth!,\n doc: result || doc,\n // @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve\n draft: undefined,\n fallbackLocale: fallbackLocale!,\n global: null,\n locale: locale!,\n overrideAccess: overrideAccess!,\n populate,\n req,\n select,\n showHiddenFields: showHiddenFields!,\n })\n\n // /////////////////////////////////////\n // afterRead - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.afterRead?.length) {\n for (const hook of collectionConfig.hooks.afterRead) {\n result =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n doc: result || doc,\n req,\n })) || result\n }\n }\n\n // /////////////////////////////////////\n // afterDelete - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.afterDelete?.length) {\n for (const hook of collectionConfig.hooks.afterDelete) {\n result =\n (await hook({\n id,\n collection: collectionConfig,\n context: req.context,\n doc: result,\n req,\n })) || result\n }\n }\n\n // /////////////////////////////////////\n // 8. Return results\n // /////////////////////////////////////\n\n return result\n } catch (error) {\n errors.push({\n id: doc.id,\n message: error.message,\n })\n }\n return null\n })\n\n const awaitedDocs = await Promise.all(promises)\n\n // /////////////////////////////////////\n // Delete Preferences\n // /////////////////////////////////////\n\n await deleteUserPreferences({\n collectionConfig,\n ids: docs.map(({ id }) => id),\n payload,\n req,\n })\n\n let result = {\n docs: awaitedDocs.filter(Boolean),\n errors,\n }\n\n // /////////////////////////////////////\n // afterOperation - Collection\n // /////////////////////////////////////\n\n result = await buildAfterOperation({\n args,\n collection: collectionConfig,\n operation: 'delete',\n result,\n })\n\n if (shouldCommit) {\n await commitTransaction(req)\n }\n\n return result\n } catch (error: unknown) {\n await killTransaction(args.req)\n throw error\n }\n}\n"],"names":["status","httpStatus","executeAccess","combineQueries","validateQueryPaths","APIError","afterRead","deleteUserPreferences","deleteAssociatedFiles","checkDocumentLockStatus","commitTransaction","initTransaction","killTransaction","sanitizeSelect","deleteCollectionVersions","deleteScheduledPublishJobs","buildAfterOperation","deleteOperation","incomingArgs","args","shouldCommit","disableTransaction","req","collection","config","hooks","beforeOperation","length","hook","context","operation","collectionConfig","depth","overrideAccess","overrideLock","populate","fallbackLocale","locale","payload","select","incomingSelect","showHiddenFields","where","BAD_REQUEST","accessResult","access","delete","fullWhere","fields","flattenedFields","forceSelect","docs","db","find","slug","errors","promises","map","doc","result","id","collectionSlug","lockErrorMessage","beforeDelete","overrideDelete","versions","drafts","schedulePublish","deleteOne","returning","equals","draft","undefined","global","afterDelete","error","push","message","awaitedDocs","Promise","all","ids","filter","Boolean"],"mappings":"AAAA,oBAAoB;AACpB,SAASA,UAAUC,UAAU,QAAQ,cAAa;AAYlD,OAAOC,mBAAmB,8BAA6B;AACvD,SAASC,cAAc,QAAQ,mCAAkC;AACjE,SAASC,kBAAkB,QAAQ,uDAAsD;AACzF,SAASC,QAAQ,QAAQ,wBAAuB;AAChD,SAASC,SAAS,QAAQ,wCAAuC;AACjE,SAASC,qBAAqB,QAAQ,6CAA4C;AAClF,SAASC,qBAAqB,QAAQ,yCAAwC;AAC9E,SAASC,uBAAuB,QAAQ,6CAA4C;AACpF,SAASC,iBAAiB,QAAQ,uCAAsC;AACxE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,cAAc,QAAQ,oCAAmC;AAClE,SAASC,wBAAwB,QAAQ,6CAA4C;AACrF,SAASC,0BAA0B,QAAQ,+CAA8C;AACzF,SAASC,mBAAmB,QAAQ,aAAY;AAehD,OAAO,MAAMC,kBAAkB,OAI7BC;IAEA,IAAIC,OAAOD;IAEX,IAAI;QACF,MAAME,eAAe,CAACD,KAAKE,kBAAkB,IAAK,MAAMV,gBAAgBQ,KAAKG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AIE,EAAE;oBACViB,SAASF,MAAME,OAAO;gBACxB;YACF;YACA,OAAO;QACT;QAEA,MAAMC,cAAc,MAAMC,QAAQC,GAAG,CAACxB;QAEtC,wCAAwC;QACxC,qBAAqB;QACrB,wCAAwC;QAExC,MAAMjD,sBAAsB;YAC1BwB;YACAkD,KAAK9B,KAAKM,GAAG,CAAC,CAAC,EAAEG,EAAE,EAAE,GAAKA;YAC1BtB;YACAhB;QACF;QAEA,IAAIqC,SAAS;YACXR,MAAM2B,YAAYI,MAAM,CAACC;YACzB5B;QACF;QAEA,wCAAwC;QACxC,8BAA8B;QAC9B,wCAAwC;QAExCI,SAAS,MAAM3C,oBAAoB;YACjCG;YACAI,YAAYQ;YACZD,WAAW;YACX6B;QACF;QAEA,IAAIvC,cAAc;YAChB,MAAMV,kBAAkBY;QAC1B;QAEA,OAAOqC;IACT,EAAE,OAAOgB,OAAgB;QACvB,MAAM/D,gBAAgBO,KAAKG,GAAG;QAC9B,MAAMqD;IACR;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../src/collections/operations/delete.ts"],"sourcesContent":["import { status as httpStatus } from 'http-status'\n\nimport type { AccessResult } from '../../config/types.js'\nimport type { CollectionSlug } from '../../index.js'\nimport type { PayloadRequest, PopulateType, SelectType, Where } from '../../types/index.js'\nimport type {\n BulkOperationResult,\n Collection,\n DataFromCollectionSlug,\n SelectFromCollectionSlug,\n} from '../config/types.js'\n\nimport executeAccess from '../../auth/executeAccess.js'\nimport { combineQueries } from '../../database/combineQueries.js'\nimport { validateQueryPaths } from '../../database/queryValidation/validateQueryPaths.js'\nimport { APIError } from '../../errors/index.js'\nimport { afterRead } from '../../fields/hooks/afterRead/index.js'\nimport { deleteUserPreferences } from '../../preferences/deleteUserPreferences.js'\nimport { deleteAssociatedFiles } from '../../uploads/deleteAssociatedFiles.js'\nimport { checkDocumentLockStatus } from '../../utilities/checkDocumentLockStatus.js'\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { sanitizeSelect } from '../../utilities/sanitizeSelect.js'\nimport { deleteCollectionVersions } from '../../versions/deleteCollectionVersions.js'\nimport { deleteScheduledPublishJobs } from '../../versions/deleteScheduledPublishJobs.js'\nimport { buildAfterOperation } from './utils.js'\n\nexport type Arguments = {\n collection: Collection\n depth?: number\n disableTransaction?: boolean\n overrideAccess?: boolean\n overrideLock?: boolean\n populate?: PopulateType\n req: PayloadRequest\n select?: SelectType\n showHiddenFields?: boolean\n where: Where\n}\n\nexport const deleteOperation = async <\n TSlug extends CollectionSlug,\n TSelect extends SelectFromCollectionSlug<TSlug>,\n>(\n incomingArgs: Arguments,\n): Promise<BulkOperationResult<TSlug, TSelect>> => {\n let args = incomingArgs\n\n try {\n const shouldCommit = !args.disableTransaction && (await initTransaction(args.req))\n // /////////////////////////////////////\n // beforeOperation - Collection\n // /////////////////////////////////////\n\n if (args.collection.config.hooks?.beforeOperation?.length) {\n for (const hook of args.collection.config.hooks.beforeOperation) {\n args =\n (await hook({\n args,\n collection: args.collection.config,\n context: args.req.context,\n operation: 'delete',\n req: args.req,\n })) || args\n }\n }\n\n const {\n collection: { config: collectionConfig },\n depth,\n overrideAccess,\n overrideLock,\n populate,\n req: {\n fallbackLocale,\n locale,\n payload: { config },\n payload,\n },\n req,\n select: incomingSelect,\n showHiddenFields,\n where,\n } = args\n\n if (!where) {\n throw new APIError(\"Missing 'where' query of documents to delete.\", httpStatus.BAD_REQUEST)\n }\n\n // /////////////////////////////////////\n // Access\n // /////////////////////////////////////\n\n let accessResult: AccessResult\n\n if (!overrideAccess) {\n accessResult = await executeAccess({ req }, collectionConfig.access.delete)\n }\n\n await validateQueryPaths({\n collectionConfig,\n overrideAccess: overrideAccess!,\n req,\n where,\n })\n\n const fullWhere = combineQueries(where, accessResult!)\n\n const select = sanitizeSelect({\n fields: collectionConfig.flattenedFields,\n forceSelect: collectionConfig.forceSelect,\n select: incomingSelect,\n })\n\n // /////////////////////////////////////\n // Retrieve documents\n // /////////////////////////////////////\n\n const { docs } = await payload.db.find<DataFromCollectionSlug<TSlug>>({\n collection: collectionConfig.slug,\n locale: locale!,\n req,\n select,\n where: fullWhere,\n })\n\n const errors: { id: number | string; message: string }[] = []\n\n const promises = docs.map(async (doc) => {\n let result\n\n const { id } = doc\n\n try {\n // /////////////////////////////////////\n // Handle potentially locked documents\n // /////////////////////////////////////\n\n await checkDocumentLockStatus({\n id,\n collectionSlug: collectionConfig.slug,\n lockErrorMessage: `Document with ID ${id} is currently locked and cannot be deleted.`,\n overrideLock,\n req,\n })\n\n // /////////////////////////////////////\n // beforeDelete - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.beforeDelete?.length) {\n for (const hook of collectionConfig.hooks.beforeDelete) {\n await hook({\n id,\n collection: collectionConfig,\n context: req.context,\n req,\n })\n }\n }\n\n await deleteAssociatedFiles({\n collectionConfig,\n config,\n doc,\n overrideDelete: true,\n req,\n })\n\n // /////////////////////////////////////\n // Delete versions\n // /////////////////////////////////////\n\n if (collectionConfig.versions) {\n await deleteCollectionVersions({\n id,\n slug: collectionConfig.slug,\n payload,\n req,\n })\n }\n\n // /////////////////////////////////////\n // Delete scheduled posts\n // /////////////////////////////////////\n if (collectionConfig.versions?.drafts && collectionConfig.versions.drafts.schedulePublish) {\n await deleteScheduledPublishJobs({\n id,\n slug: collectionConfig.slug,\n payload,\n req,\n })\n }\n\n // /////////////////////////////////////\n // Delete document\n // /////////////////////////////////////\n\n await payload.db.deleteOne({\n collection: collectionConfig.slug,\n req,\n returning: false,\n where: {\n id: {\n equals: id,\n },\n },\n })\n\n // /////////////////////////////////////\n // afterRead - Fields\n // /////////////////////////////////////\n\n result = await afterRead({\n collection: collectionConfig,\n context: req.context,\n depth: depth!,\n doc: result || doc,\n // @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve\n draft: undefined,\n fallbackLocale: fallbackLocale!,\n global: null,\n locale: locale!,\n overrideAccess: overrideAccess!,\n populate,\n req,\n select,\n showHiddenFields: showHiddenFields!,\n })\n\n // /////////////////////////////////////\n // afterRead - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.afterRead?.length) {\n for (const hook of collectionConfig.hooks.afterRead) {\n result =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n doc: result || doc,\n req,\n })) || result\n }\n }\n\n // /////////////////////////////////////\n // afterDelete - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.afterDelete?.length) {\n for (const hook of collectionConfig.hooks.afterDelete) {\n result =\n (await hook({\n id,\n collection: collectionConfig,\n context: req.context,\n doc: result,\n req,\n })) || result\n }\n }\n\n // /////////////////////////////////////\n // 8. Return results\n // /////////////////////////////////////\n\n return result\n } catch (error) {\n errors.push({\n id: doc.id,\n message: error instanceof Error ? error.message : 'Unknown error',\n })\n }\n return null\n })\n\n const awaitedDocs = await Promise.all(promises)\n\n // /////////////////////////////////////\n // Delete Preferences\n // /////////////////////////////////////\n\n await deleteUserPreferences({\n collectionConfig,\n ids: docs.map(({ id }) => id),\n payload,\n req,\n })\n\n let result = {\n docs: awaitedDocs.filter(Boolean),\n errors,\n }\n\n // /////////////////////////////////////\n // afterOperation - Collection\n // /////////////////////////////////////\n\n result = await buildAfterOperation({\n args,\n collection: collectionConfig,\n operation: 'delete',\n result,\n })\n\n if (shouldCommit) {\n await commitTransaction(req)\n }\n\n return result\n } catch (error: unknown) {\n await killTransaction(args.req)\n throw error\n }\n}\n"],"names":["status","httpStatus","executeAccess","combineQueries","validateQueryPaths","APIError","afterRead","deleteUserPreferences","deleteAssociatedFiles","checkDocumentLockStatus","commitTransaction","initTransaction","killTransaction","sanitizeSelect","deleteCollectionVersions","deleteScheduledPublishJobs","buildAfterOperation","deleteOperation","incomingArgs","args","shouldCommit","disableTransaction","req","collection","config","hooks","beforeOperation","length","hook","context","operation","collectionConfig","depth","overrideAccess","overrideLock","populate","fallbackLocale","locale","payload","select","incomingSelect","showHiddenFields","where","BAD_REQUEST","accessResult","access","delete","fullWhere","fields","flattenedFields","forceSelect","docs","db","find","slug","errors","promises","map","doc","result","id","collectionSlug","lockErrorMessage","beforeDelete","overrideDelete","versions","drafts","schedulePublish","deleteOne","returning","equals","draft","undefined","global","afterDelete","error","push","message","Error","awaitedDocs","Promise","all","ids","filter","Boolean"],"mappings":"AAAA,SAASA,UAAUC,UAAU,QAAQ,cAAa;AAYlD,OAAOC,mBAAmB,8BAA6B;AACvD,SAASC,cAAc,QAAQ,mCAAkC;AACjE,SAASC,kBAAkB,QAAQ,uDAAsD;AACzF,SAASC,QAAQ,QAAQ,wBAAuB;AAChD,SAASC,SAAS,QAAQ,wCAAuC;AACjE,SAASC,qBAAqB,QAAQ,6CAA4C;AAClF,SAASC,qBAAqB,QAAQ,yCAAwC;AAC9E,SAASC,uBAAuB,QAAQ,6CAA4C;AACpF,SAASC,iBAAiB,QAAQ,uCAAsC;AACxE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,cAAc,QAAQ,oCAAmC;AAClE,SAASC,wBAAwB,QAAQ,6CAA4C;AACrF,SAASC,0BAA0B,QAAQ,+CAA8C;AACzF,SAASC,mBAAmB,QAAQ,aAAY;AAehD,OAAO,MAAMC,kBAAkB,OAI7BC;IAEA,IAAIC,OAAOD;IAEX,IAAI;QACF,MAAME,eAAe,CAACD,KAAKE,kBAAkB,IAAK,MAAMV,gBAAgBQ,KAAKG,GAAG;QAChF,wCAAwC;QACxC,+BAA+B;QAC/B,wCAAwC;QAExC,IAAIH,KAAKI,UAAU,CAACC,MAAM,CAACC,KAAK,EAAEC,iBAAiBC,QAAQ;YACzD,KAAK,MAAMC,QAAQT,KAAKI,UAAU,CAACC,MAAM,CAACC,KAAK,CAACC,eAAe,CAAE;gBAC/DP,OACE,AAAC,MAAMS,KAAK;oBACVT;oBACAI,YAAYJ,KAAKI,UAAU,CAACC,MAAM;oBAClCK,SAASV,KAAKG,GAAG,CAACO,OA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AAM4B,YAAYI,MAAM,CAACC;YACzB7B;QACF;QAEA,wCAAwC;QACxC,8BAA8B;QAC9B,wCAAwC;QAExCI,SAAS,MAAM3C,oBAAoB;YACjCG;YACAI,YAAYQ;YACZD,WAAW;YACX6B;QACF;QAEA,IAAIvC,cAAc;YAChB,MAAMV,kBAAkBY;QAC1B;QAEA,OAAOqC;IACT,EAAE,OAAOgB,OAAgB;QACvB,MAAM/D,gBAAgBO,KAAKG,GAAG;QAC9B,MAAMqD;IACR;AACF,EAAC"}
@@ -1,4 +1,3 @@
1
- // @ts-strict-ignore
2
1
  import executeAccess from '../../auth/executeAccess.js';
3
2
  import { combineQueries } from '../../database/combineQueries.js';
4
3
  import { validateQueryPaths } from '../../database/queryValidation/validateQueryPaths.js';