payload 4.0.0-beta.7 → 4.0.0-beta.8

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 (247) hide show
  1. package/dist/admin/forms/Form.d.ts +5 -0
  2. package/dist/admin/forms/Form.d.ts.map +1 -1
  3. package/dist/admin/forms/Form.js.map +1 -1
  4. package/dist/admin/functions/index.d.ts +2 -0
  5. package/dist/admin/functions/index.d.ts.map +1 -1
  6. package/dist/admin/functions/index.js.map +1 -1
  7. package/dist/admin/getRequestLocale.d.ts +3 -1
  8. package/dist/admin/getRequestLocale.d.ts.map +1 -1
  9. package/dist/admin/getRequestLocale.js +12 -1
  10. package/dist/admin/getRequestLocale.js.map +1 -1
  11. package/dist/admin/initAdminContext.d.ts.map +1 -1
  12. package/dist/admin/initAdminContext.js +2 -1
  13. package/dist/admin/initAdminContext.js.map +1 -1
  14. package/dist/auth/extractJWT.d.ts +7 -0
  15. package/dist/auth/extractJWT.d.ts.map +1 -1
  16. package/dist/auth/extractJWT.js +5 -8
  17. package/dist/auth/extractJWT.js.map +1 -1
  18. package/dist/auth/redeemRefreshToken.d.ts +8 -1
  19. package/dist/auth/redeemRefreshToken.d.ts.map +1 -1
  20. package/dist/auth/redeemRefreshToken.js +1 -5
  21. package/dist/auth/redeemRefreshToken.js.map +1 -1
  22. package/dist/cli/commands/collections/deleteDocuments.d.ts.map +1 -1
  23. package/dist/cli/commands/collections/deleteDocuments.js +3 -1
  24. package/dist/cli/commands/collections/deleteDocuments.js.map +1 -1
  25. package/dist/collections/operations/inputSchemas.d.ts +6 -0
  26. package/dist/collections/operations/inputSchemas.d.ts.map +1 -1
  27. package/dist/collections/operations/inputSchemas.js +1 -0
  28. package/dist/collections/operations/inputSchemas.js.map +1 -1
  29. package/dist/collections/operations/renameFile.d.ts.map +1 -1
  30. package/dist/collections/operations/renameFile.js +34 -0
  31. package/dist/collections/operations/renameFile.js.map +1 -1
  32. package/dist/collections/operations/update.d.ts.map +1 -1
  33. package/dist/collections/operations/update.js +40 -19
  34. package/dist/collections/operations/update.js.map +1 -1
  35. package/dist/config/types.d.ts +5 -7
  36. package/dist/config/types.d.ts.map +1 -1
  37. package/dist/config/types.js.map +1 -1
  38. package/dist/exports/build-config.d.ts.map +1 -1
  39. package/dist/exports/build-config.js +0 -2
  40. package/dist/exports/build-config.js.map +1 -1
  41. package/dist/exports/internal.d.ts +1 -0
  42. package/dist/exports/internal.d.ts.map +1 -1
  43. package/dist/exports/internal.js +1 -0
  44. package/dist/exports/internal.js.map +1 -1
  45. package/dist/exports/shared.d.ts +6 -3
  46. package/dist/exports/shared.d.ts.map +1 -1
  47. package/dist/exports/shared.js +6 -3
  48. package/dist/exports/shared.js.map +1 -1
  49. package/dist/fields/config/reservedFieldNames.d.ts.map +1 -1
  50. package/dist/fields/config/reservedFieldNames.js +2 -1
  51. package/dist/fields/config/reservedFieldNames.js.map +1 -1
  52. package/dist/fields/config/types.d.ts +8 -1
  53. package/dist/fields/config/types.d.ts.map +1 -1
  54. package/dist/fields/config/types.js.map +1 -1
  55. package/dist/fields/hooks/beforeValidate/getFallbackValue.d.ts.map +1 -1
  56. package/dist/fields/hooks/beforeValidate/getFallbackValue.js +3 -2
  57. package/dist/fields/hooks/beforeValidate/getFallbackValue.js.map +1 -1
  58. package/dist/fields/validateJSONSchema.js +1 -1
  59. package/dist/fields/validateJSONSchema.js.map +1 -1
  60. package/dist/hierarchy/getInitialTreeData.js +1 -1
  61. package/dist/hierarchy/getInitialTreeData.js.map +1 -1
  62. package/dist/index.bundled.d.ts +155 -14
  63. package/dist/index.d.ts +1 -0
  64. package/dist/index.d.ts.map +1 -1
  65. package/dist/index.js +1 -0
  66. package/dist/index.js.map +1 -1
  67. package/dist/uploads/copyTempFileForDocument.d.ts +9 -0
  68. package/dist/uploads/copyTempFileForDocument.d.ts.map +1 -0
  69. package/dist/uploads/copyTempFileForDocument.js +15 -0
  70. package/dist/uploads/copyTempFileForDocument.js.map +1 -0
  71. package/dist/uploads/createSharedClientUploadDownload.d.ts +12 -0
  72. package/dist/uploads/createSharedClientUploadDownload.d.ts.map +1 -0
  73. package/dist/uploads/createSharedClientUploadDownload.js +36 -0
  74. package/dist/uploads/createSharedClientUploadDownload.js.map +1 -0
  75. package/dist/uploads/fileVersioning/storedFiles.d.ts.map +1 -1
  76. package/dist/uploads/fileVersioning/storedFiles.js +9 -1
  77. package/dist/uploads/fileVersioning/storedFiles.js.map +1 -1
  78. package/dist/uploads/formatFileMeta.d.ts +12 -0
  79. package/dist/uploads/formatFileMeta.d.ts.map +1 -0
  80. package/dist/uploads/formatFileMeta.js +14 -0
  81. package/dist/uploads/formatFileMeta.js.map +1 -0
  82. package/dist/uploads/generateFileData.d.ts +8 -1
  83. package/dist/uploads/generateFileData.d.ts.map +1 -1
  84. package/dist/uploads/generateFileData.js +469 -97
  85. package/dist/uploads/generateFileData.js.map +1 -1
  86. package/dist/uploads/getBaseFields.d.ts.map +1 -1
  87. package/dist/uploads/getBaseFields.js +44 -2
  88. package/dist/uploads/getBaseFields.js.map +1 -1
  89. package/dist/uploads/getFileContentRequirement.d.ts +9 -8
  90. package/dist/uploads/getFileContentRequirement.d.ts.map +1 -1
  91. package/dist/uploads/getFileContentRequirement.js +10 -6
  92. package/dist/uploads/getFileContentRequirement.js.map +1 -1
  93. package/dist/uploads/getFileFromUploadInstructions.d.ts +10 -0
  94. package/dist/uploads/getFileFromUploadInstructions.d.ts.map +1 -1
  95. package/dist/uploads/getFileFromUploadInstructions.js +59 -36
  96. package/dist/uploads/getFileFromUploadInstructions.js.map +1 -1
  97. package/dist/uploads/getSafeFilename.d.ts +4 -0
  98. package/dist/uploads/getSafeFilename.d.ts.map +1 -1
  99. package/dist/uploads/getSafeFilename.js +17 -3
  100. package/dist/uploads/getSafeFilename.js.map +1 -1
  101. package/dist/uploads/isOriginalFileRequest.d.ts +3 -1
  102. package/dist/uploads/isOriginalFileRequest.d.ts.map +1 -1
  103. package/dist/uploads/isOriginalFileRequest.js +6 -4
  104. package/dist/uploads/isOriginalFileRequest.js.map +1 -1
  105. package/dist/uploads/isRequestTimeFile.d.ts +13 -0
  106. package/dist/uploads/isRequestTimeFile.d.ts.map +1 -0
  107. package/dist/uploads/isRequestTimeFile.js +9 -0
  108. package/dist/uploads/isRequestTimeFile.js.map +1 -0
  109. package/dist/uploads/registerUploadVariants.d.ts +20 -0
  110. package/dist/uploads/registerUploadVariants.d.ts.map +1 -0
  111. package/dist/uploads/registerUploadVariants.js +93 -0
  112. package/dist/uploads/registerUploadVariants.js.map +1 -0
  113. package/dist/uploads/sanitizeUploadData.d.ts.map +1 -1
  114. package/dist/uploads/sanitizeUploadData.js +3 -0
  115. package/dist/uploads/sanitizeUploadData.js.map +1 -1
  116. package/dist/uploads/transformState/cropUnits.d.ts +21 -0
  117. package/dist/uploads/transformState/cropUnits.d.ts.map +1 -0
  118. package/dist/uploads/transformState/cropUnits.js +23 -0
  119. package/dist/uploads/transformState/cropUnits.js.map +1 -0
  120. package/dist/uploads/transformState/getChangedTransformKeys.d.ts +6 -0
  121. package/dist/uploads/transformState/getChangedTransformKeys.d.ts.map +1 -0
  122. package/dist/uploads/transformState/getChangedTransformKeys.js +12 -0
  123. package/dist/uploads/transformState/getChangedTransformKeys.js.map +1 -0
  124. package/dist/uploads/transformState/getTransformKeyCoverageErrors.d.ts +15 -0
  125. package/dist/uploads/transformState/getTransformKeyCoverageErrors.d.ts.map +1 -0
  126. package/dist/uploads/transformState/getTransformKeyCoverageErrors.js +28 -0
  127. package/dist/uploads/transformState/getTransformKeyCoverageErrors.js.map +1 -0
  128. package/dist/uploads/transformState/planPersistedDefaultStages.d.ts +24 -0
  129. package/dist/uploads/transformState/planPersistedDefaultStages.d.ts.map +1 -0
  130. package/dist/uploads/transformState/planPersistedDefaultStages.js +32 -0
  131. package/dist/uploads/transformState/planPersistedDefaultStages.js.map +1 -0
  132. package/dist/uploads/transformState/planUpload.d.ts +95 -0
  133. package/dist/uploads/transformState/planUpload.d.ts.map +1 -0
  134. package/dist/uploads/transformState/planUpload.js +198 -0
  135. package/dist/uploads/transformState/planUpload.js.map +1 -0
  136. package/dist/uploads/transformState/resolveUploadEdits.d.ts +91 -0
  137. package/dist/uploads/transformState/resolveUploadEdits.d.ts.map +1 -0
  138. package/dist/uploads/transformState/resolveUploadEdits.js +397 -0
  139. package/dist/uploads/transformState/resolveUploadEdits.js.map +1 -0
  140. package/dist/uploads/transformState/transformKeyClaims.d.ts +14 -0
  141. package/dist/uploads/transformState/transformKeyClaims.d.ts.map +1 -0
  142. package/dist/uploads/transformState/transformKeyClaims.js +15 -0
  143. package/dist/uploads/transformState/transformKeyClaims.js.map +1 -0
  144. package/dist/uploads/transformState/transformStateSchema.d.ts +8 -0
  145. package/dist/uploads/transformState/transformStateSchema.d.ts.map +1 -0
  146. package/dist/uploads/transformState/transformStateSchema.js +155 -0
  147. package/dist/uploads/transformState/transformStateSchema.js.map +1 -0
  148. package/dist/uploads/transformState/validateTransformState.d.ts +15 -0
  149. package/dist/uploads/transformState/validateTransformState.d.ts.map +1 -0
  150. package/dist/uploads/transformState/validateTransformState.js +34 -0
  151. package/dist/uploads/transformState/validateTransformState.js.map +1 -0
  152. package/dist/uploads/transformers/createFileSource.d.ts +9 -0
  153. package/dist/uploads/transformers/createFileSource.d.ts.map +1 -0
  154. package/dist/uploads/transformers/createFileSource.js +58 -0
  155. package/dist/uploads/transformers/createFileSource.js.map +1 -0
  156. package/dist/uploads/transformers/createLazySourceGetter.d.ts +3 -1
  157. package/dist/uploads/transformers/createLazySourceGetter.d.ts.map +1 -1
  158. package/dist/uploads/transformers/createLazySourceGetter.js +2 -2
  159. package/dist/uploads/transformers/createLazySourceGetter.js.map +1 -1
  160. package/dist/uploads/transformers/getSourceFileResponse.d.ts +3 -1
  161. package/dist/uploads/transformers/getSourceFileResponse.d.ts.map +1 -1
  162. package/dist/uploads/transformers/getSourceFileResponse.js +2 -1
  163. package/dist/uploads/transformers/getSourceFileResponse.js.map +1 -1
  164. package/dist/uploads/transformers/handleDynamicFileRequest.d.ts +3 -2
  165. package/dist/uploads/transformers/handleDynamicFileRequest.d.ts.map +1 -1
  166. package/dist/uploads/transformers/handleDynamicFileRequest.js +146 -38
  167. package/dist/uploads/transformers/handleDynamicFileRequest.js.map +1 -1
  168. package/dist/uploads/transformers/planTransformerPipeline.d.ts +11 -1
  169. package/dist/uploads/transformers/planTransformerPipeline.d.ts.map +1 -1
  170. package/dist/uploads/transformers/planTransformerPipeline.js +28 -6
  171. package/dist/uploads/transformers/planTransformerPipeline.js.map +1 -1
  172. package/dist/uploads/transformers/resolveUploadDocument.d.ts +10 -3
  173. package/dist/uploads/transformers/resolveUploadDocument.d.ts.map +1 -1
  174. package/dist/uploads/transformers/resolveUploadDocument.js +18 -7
  175. package/dist/uploads/transformers/resolveUploadDocument.js.map +1 -1
  176. package/dist/uploads/transformers/transformUploadFile.d.ts +18 -7
  177. package/dist/uploads/transformers/transformUploadFile.d.ts.map +1 -1
  178. package/dist/uploads/transformers/transformUploadFile.js +96 -12
  179. package/dist/uploads/transformers/transformUploadFile.js.map +1 -1
  180. package/dist/uploads/transformers/types.d.ts +89 -3
  181. package/dist/uploads/transformers/types.d.ts.map +1 -1
  182. package/dist/uploads/transformers/types.js.map +1 -1
  183. package/dist/uploads/types.d.ts +7 -1
  184. package/dist/uploads/types.d.ts.map +1 -1
  185. package/dist/uploads/types.js.map +1 -1
  186. package/dist/utilities/configToJSONSchema.d.ts.map +1 -1
  187. package/dist/utilities/configToJSONSchema.js +14 -3
  188. package/dist/utilities/configToJSONSchema.js.map +1 -1
  189. package/dist/utilities/createPayloadRequestFromWebRequest.d.ts +12 -1
  190. package/dist/utilities/createPayloadRequestFromWebRequest.d.ts.map +1 -1
  191. package/dist/utilities/createPayloadRequestFromWebRequest.js +9 -3
  192. package/dist/utilities/createPayloadRequestFromWebRequest.js.map +1 -1
  193. package/dist/utilities/deepFreeze.d.ts +6 -0
  194. package/dist/utilities/deepFreeze.d.ts.map +1 -0
  195. package/dist/utilities/deepFreeze.js +14 -0
  196. package/dist/utilities/deepFreeze.js.map +1 -0
  197. package/dist/utilities/getDataByPath.d.ts.map +1 -1
  198. package/dist/utilities/getDataByPath.js +6 -9
  199. package/dist/utilities/getDataByPath.js.map +1 -1
  200. package/dist/utilities/getDataFromFormState.d.ts +10 -0
  201. package/dist/utilities/getDataFromFormState.d.ts.map +1 -0
  202. package/dist/utilities/getDataFromFormState.js +40 -0
  203. package/dist/utilities/getDataFromFormState.js.map +1 -0
  204. package/dist/utilities/getDateOnlyComparison.d.ts +27 -0
  205. package/dist/utilities/getDateOnlyComparison.d.ts.map +1 -0
  206. package/dist/utilities/getDateOnlyComparison.js +162 -0
  207. package/dist/utilities/getDateOnlyComparison.js.map +1 -0
  208. package/dist/utilities/getSiblingDataFromFormState.d.ts +8 -0
  209. package/dist/utilities/getSiblingDataFromFormState.d.ts.map +1 -0
  210. package/dist/utilities/{getSiblingData.js → getSiblingDataFromFormState.js} +11 -8
  211. package/dist/utilities/getSiblingDataFromFormState.js.map +1 -0
  212. package/dist/utilities/handleEndpoints.d.ts.map +1 -1
  213. package/dist/utilities/handleEndpoints.js +10 -2
  214. package/dist/utilities/handleEndpoints.js.map +1 -1
  215. package/dist/utilities/telemetry/featureInfo/getFeatureInfo.d.ts.map +1 -1
  216. package/dist/utilities/telemetry/featureInfo/getFeatureInfo.js +41 -7
  217. package/dist/utilities/telemetry/featureInfo/getFeatureInfo.js.map +1 -1
  218. package/dist/utilities/telemetry/featureInfo/types.d.ts +4 -1
  219. package/dist/utilities/telemetry/featureInfo/types.d.ts.map +1 -1
  220. package/dist/utilities/telemetry/featureInfo/types.js.map +1 -1
  221. package/dist/utilities/telemetry/index.d.ts +3 -5
  222. package/dist/utilities/telemetry/index.d.ts.map +1 -1
  223. package/dist/utilities/telemetry/index.js +14 -3
  224. package/dist/utilities/telemetry/index.js.map +1 -1
  225. package/dist/utilities/telemetry/widgetType.d.ts +6 -0
  226. package/dist/utilities/telemetry/widgetType.d.ts.map +1 -0
  227. package/dist/utilities/telemetry/widgetType.js +33 -0
  228. package/dist/utilities/telemetry/widgetType.js.map +1 -0
  229. package/dist/utilities/transformPointDataToPayload.d.ts.map +1 -1
  230. package/dist/utilities/transformPointDataToPayload.js +15 -1
  231. package/dist/utilities/transformPointDataToPayload.js.map +1 -1
  232. package/dist/utilities/unflatten.d.ts +17 -0
  233. package/dist/utilities/unflatten.d.ts.map +1 -1
  234. package/dist/utilities/unflatten.js +10 -4
  235. package/dist/utilities/unflatten.js.map +1 -1
  236. package/package.json +2 -2
  237. package/dist/fields/hooks/beforeChange/cloneDataFromOriginalDoc.d.ts +0 -3
  238. package/dist/fields/hooks/beforeChange/cloneDataFromOriginalDoc.d.ts.map +0 -1
  239. package/dist/fields/hooks/beforeChange/cloneDataFromOriginalDoc.js +0 -20
  240. package/dist/fields/hooks/beforeChange/cloneDataFromOriginalDoc.js.map +0 -1
  241. package/dist/utilities/getSiblingData.d.ts +0 -3
  242. package/dist/utilities/getSiblingData.d.ts.map +0 -1
  243. package/dist/utilities/getSiblingData.js.map +0 -1
  244. package/dist/utilities/reduceFieldsToValues.d.ts +0 -10
  245. package/dist/utilities/reduceFieldsToValues.d.ts.map +0 -1
  246. package/dist/utilities/reduceFieldsToValues.js +0 -24
  247. package/dist/utilities/reduceFieldsToValues.js.map +0 -1
@@ -0,0 +1,93 @@
1
+ const RESERVED_VARIANT_NAMES = [
2
+ 'filename',
3
+ 'mimeType',
4
+ 'filesize',
5
+ 'width',
6
+ 'height',
7
+ 'url',
8
+ 'thumbnailURL',
9
+ 'variants',
10
+ 'focalX',
11
+ 'focalY'
12
+ ];
13
+ /**
14
+ * Registers a transformer's image sizes on upload collections. Call it from a transformer's
15
+ * `init`. It checks each collection and size name, then writes the sizes (name and admin options
16
+ * only) to the collection's sanitized `upload.variants`. Only one transformer can register sizes
17
+ * on a collection. It writes onto copies and never changes the given config.
18
+ *
19
+ * @param transformerSlug The registering transformer's `slug`, saved as the owner of the sizes and
20
+ * used in error messages. It must match a transformer in `upload.transformers`. Payload writes
21
+ * size entries with no stored file only when this transformer builds files at request time.
22
+ */ export function registerUploadVariants({ collections, config, transformerSlug }) {
23
+ const errors = [];
24
+ if (!config.upload?.transformers?.some((transformer)=>transformer.slug === transformerSlug)) {
25
+ errors.push(`no transformer in \`upload.transformers\` has the slug "${transformerSlug}". Pass the slug of the transformer that registers the variants.`);
26
+ }
27
+ for (const [slug, registration] of Object.entries(collections)){
28
+ if (!registration) {
29
+ continue;
30
+ }
31
+ const collection = config.collections?.find((candidate)=>candidate.slug === slug);
32
+ if (!collection) {
33
+ errors.push(`collections."${slug}" does not match any configured collection slug.`);
34
+ continue;
35
+ }
36
+ if (!collection.upload) {
37
+ errors.push(`collections."${slug}" targets a collection whose \`upload\` option is not set. Enable uploads on "${slug}" first.`);
38
+ continue;
39
+ }
40
+ // One owner per collection: an upload transformer such as Sharp builds only its own sizes, so
41
+ // a size another transformer registers would get a field but no entry when Sharp runs.
42
+ if (registration.variants?.length && collection.upload.variants?.length) {
43
+ errors.push(`collections."${slug}" registers variants, but another transformer already registered variants on "${slug}". Only one transformer can register variants on a collection.`);
44
+ continue;
45
+ }
46
+ const seenNames = new Set();
47
+ for (const variant of registration.variants ?? []){
48
+ if (typeof variant.name !== 'string' || variant.name.trim().length === 0) {
49
+ errors.push(`collections."${slug}".variants has an entry missing a valid \`name\`.`);
50
+ continue;
51
+ }
52
+ if (seenNames.has(variant.name)) {
53
+ errors.push(`collections."${slug}".variants has a duplicate size name: "${variant.name}".`);
54
+ }
55
+ seenNames.add(variant.name);
56
+ if (/[/\\]|\.\./.test(variant.name)) {
57
+ errors.push(`collections."${slug}".variants uses name "${variant.name}", which contains a path separator or "..". Size names are part of file names.`);
58
+ }
59
+ if (RESERVED_VARIANT_NAMES.includes(variant.name)) {
60
+ errors.push(`collections."${slug}".variants uses reserved name "${variant.name}", which collides with a built-in upload field. Choose a different name.`);
61
+ }
62
+ }
63
+ }
64
+ if (errors.length > 0) {
65
+ throw new Error(`Invalid upload variants from transformer "${transformerSlug}":\n${errors.join('\n')}`);
66
+ }
67
+ // Write onto copies, never the caller's config or collection objects: a rebuilt config (e.g. on
68
+ // a dev reload) would otherwise see `upload.variants` on the collection and reject it as authored.
69
+ return {
70
+ ...config,
71
+ collections: config.collections?.map((collection)=>{
72
+ const variants = collections[collection.slug]?.variants;
73
+ if (!variants?.length || !collection.upload) {
74
+ return collection;
75
+ }
76
+ const upload = typeof collection.upload === 'object' ? collection.upload : {};
77
+ return {
78
+ ...collection,
79
+ upload: {
80
+ ...upload,
81
+ variants: variants.map(({ name, admin, generateImageName })=>({
82
+ name,
83
+ admin,
84
+ generateImageName
85
+ })),
86
+ variantsTransformerSlug: transformerSlug
87
+ }
88
+ };
89
+ })
90
+ };
91
+ }
92
+
93
+ //# sourceMappingURL=registerUploadVariants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/uploads/registerUploadVariants.ts"],"sourcesContent":["import type { Config } from '../config/types.js'\nimport type { ImageSize, SanitizedUploadConfig } from './types.js'\n\nconst RESERVED_VARIANT_NAMES = [\n 'filename',\n 'mimeType',\n 'filesize',\n 'width',\n 'height',\n 'url',\n 'thumbnailURL',\n 'variants',\n 'focalX',\n 'focalY',\n]\n\n/**\n * Registers a transformer's image sizes on upload collections. Call it from a transformer's\n * `init`. It checks each collection and size name, then writes the sizes (name and admin options\n * only) to the collection's sanitized `upload.variants`. Only one transformer can register sizes\n * on a collection. It writes onto copies and never changes the given config.\n *\n * @param transformerSlug The registering transformer's `slug`, saved as the owner of the sizes and\n * used in error messages. It must match a transformer in `upload.transformers`. Payload writes\n * size entries with no stored file only when this transformer builds files at request time.\n */\nexport function registerUploadVariants({\n collections,\n config,\n transformerSlug,\n}: {\n collections: Partial<Record<string, { variants?: ImageSize[] }>>\n config: Config\n transformerSlug: string\n}): Config {\n const errors: string[] = []\n\n if (!config.upload?.transformers?.some((transformer) => transformer.slug === transformerSlug)) {\n errors.push(\n `no transformer in \\`upload.transformers\\` has the slug \"${transformerSlug}\". Pass the slug of the transformer that registers the variants.`,\n )\n }\n\n for (const [slug, registration] of Object.entries(collections)) {\n if (!registration) {\n continue\n }\n\n const collection = config.collections?.find((candidate) => candidate.slug === slug)\n\n if (!collection) {\n errors.push(`collections.\"${slug}\" does not match any configured collection slug.`)\n continue\n }\n\n if (!collection.upload) {\n errors.push(\n `collections.\"${slug}\" targets a collection whose \\`upload\\` option is not set. Enable uploads on \"${slug}\" first.`,\n )\n continue\n }\n\n // One owner per collection: an upload transformer such as Sharp builds only its own sizes, so\n // a size another transformer registers would get a field but no entry when Sharp runs.\n if (\n registration.variants?.length &&\n (collection.upload as Partial<SanitizedUploadConfig>).variants?.length\n ) {\n errors.push(\n `collections.\"${slug}\" registers variants, but another transformer already registered variants on \"${slug}\". Only one transformer can register variants on a collection.`,\n )\n continue\n }\n\n const seenNames = new Set<string>()\n\n for (const variant of registration.variants ?? []) {\n if (typeof variant.name !== 'string' || variant.name.trim().length === 0) {\n errors.push(`collections.\"${slug}\".variants has an entry missing a valid \\`name\\`.`)\n continue\n }\n\n if (seenNames.has(variant.name)) {\n errors.push(`collections.\"${slug}\".variants has a duplicate size name: \"${variant.name}\".`)\n }\n seenNames.add(variant.name)\n\n if (/[/\\\\]|\\.\\./.test(variant.name)) {\n errors.push(\n `collections.\"${slug}\".variants uses name \"${variant.name}\", which contains a path separator or \"..\". Size names are part of file names.`,\n )\n }\n\n if (RESERVED_VARIANT_NAMES.includes(variant.name)) {\n errors.push(\n `collections.\"${slug}\".variants uses reserved name \"${variant.name}\", which collides with a built-in upload field. Choose a different name.`,\n )\n }\n }\n }\n\n if (errors.length > 0) {\n throw new Error(\n `Invalid upload variants from transformer \"${transformerSlug}\":\\n${errors.join('\\n')}`,\n )\n }\n\n // Write onto copies, never the caller's config or collection objects: a rebuilt config (e.g. on\n // a dev reload) would otherwise see `upload.variants` on the collection and reject it as authored.\n return {\n ...config,\n collections: config.collections?.map((collection) => {\n const variants = collections[collection.slug]?.variants\n\n if (!variants?.length || !collection.upload) {\n return collection\n }\n\n const upload = (\n typeof collection.upload === 'object' ? collection.upload : {}\n ) as Partial<SanitizedUploadConfig>\n\n return {\n ...collection,\n upload: {\n ...upload,\n variants: variants.map(({ name, admin, generateImageName }) => ({\n name,\n admin,\n generateImageName,\n })),\n variantsTransformerSlug: transformerSlug,\n },\n }\n }),\n }\n}\n"],"names":["RESERVED_VARIANT_NAMES","registerUploadVariants","collections","config","transformerSlug","errors","upload","transformers","some","transformer","slug","push","registration","Object","entries","collection","find","candidate","variants","length","seenNames","Set","variant","name","trim","has","add","test","includes","Error","join","map","admin","generateImageName","variantsTransformerSlug"],"mappings":"AAGA,MAAMA,yBAAyB;IAC7B;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD;AAED;;;;;;;;;CASC,GACD,OAAO,SAASC,uBAAuB,EACrCC,WAAW,EACXC,MAAM,EACNC,eAAe,EAKhB;IACC,MAAMC,SAAmB,EAAE;IAE3B,IAAI,CAACF,OAAOG,MAAM,EAAEC,cAAcC,KAAK,CAACC,cAAgBA,YAAYC,IAAI,KAAKN,kBAAkB;QAC7FC,OAAOM,IAAI,CACT,CAAC,wDAAwD,EAAEP,gBAAgB,gEAAgE,CAAC;IAEhJ;IAEA,KAAK,MAAM,CAACM,MAAME,aAAa,IAAIC,OAAOC,OAAO,CAACZ,aAAc;QAC9D,IAAI,CAACU,cAAc;YACjB;QACF;QAEA,MAAMG,aAAaZ,OAAOD,WAAW,EAAEc,KAAK,CAACC,YAAcA,UAAUP,IAAI,KAAKA;QAE9E,IAAI,CAACK,YAAY;YACfV,OAAOM,IAAI,CAAC,CAAC,aAAa,EAAED,KAAK,gDAAgD,CAAC;YAClF;QACF;QAEA,IAAI,CAACK,WAAWT,MAAM,EAAE;YACtBD,OAAOM,IAAI,CACT,CAAC,aAAa,EAAED,KAAK,8EAA8E,EAAEA,KAAK,QAAQ,CAAC;YAErH;QACF;QAEA,8FAA8F;QAC9F,uFAAu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c,EAAE,KAAG,GAAG,CAAC,MAAM,CAUjF,CAAA;AAqBD,eAAO,MAAM,kBAAkB,GAAI,CAAC,QAAQ,CAAC,aAAa,SAAS,KAAG,CA8BrE,CAAA;AAQD,eAAO,MAAM,2BAA2B,GAAI,CAAC,QACrC,CAAC,YACG,OAAO,YACR,iBAAiB,KACzB,CA8BF,CAAA;AAoBD,eAAO,MAAM,6BAA6B,GAAI,CAAC,QACvC,CAAC,YACG,OAAO,YACR,iBAAiB,KACzB,CAiBF,CAAA"}
@@ -80,6 +80,7 @@ export const sanitizeUploadData = (data, operation)=>{
80
80
  delete sanitizedData.url;
81
81
  // Server-owned; never accepted from the caller.
82
82
  delete sanitizedData._objectKey;
83
+ delete sanitizedData._stored;
83
84
  delete sanitizedData.original;
84
85
  // On update, `prefix` is restored from the stored document (file identity); kept on create.
85
86
  if (operation === 'update') {
@@ -130,7 +131,9 @@ export const mergeUploadDataWithDocument = (data, document, options = {})=>{
130
131
  return mergedData;
131
132
  };
132
133
  const uploadDerivedProperties = [
134
+ '_transforms',
133
135
  '_objectKey',
136
+ '_stored',
134
137
  'filename',
135
138
  'filesize',
136
139
  'focalX',
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/uploads/sanitizeUploadData.ts"],"sourcesContent":["import path from 'path'\n\nimport type { FlattenedField } from '../fields/config/types.js'\n\nimport { APIError } from '../errors/APIError.js'\n\ntype Operation = 'create' | 'update'\n\nexport type ExternalUploadSource = {\n filename: string\n url: string\n}\n\ntype UploadDataOptions = {\n clearMissing?: boolean\n locale?: string\n localizedProperties?: Set<string>\n}\n\nconst hasOwnProperty = (value: Record<string, unknown>, key: string): boolean =>\n Object.prototype.hasOwnProperty.call(value, key)\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value)\n\nexport const getExternalUploadSource = (data: unknown): ExternalUploadSource | undefined => {\n if (!isRecord(data) || typeof data.filename !== 'string' || typeof data.url !== 'string') {\n return undefined\n }\n\n return {\n filename: data.filename,\n url: data.url,\n }\n}\n\n// Resolves the server-owned upload destination for a document write. For provider uploads the\n// prefix and key segment come from the verified upload reference; for server uploads (including\n// staged uploads) the prefix falls back to the submitted document data and there is no key segment.\nexport const getUploadDestination = ({\n data,\n file,\n}: {\n data: unknown\n file: { uploadReference?: unknown } | null | undefined\n}): { objectKey?: string; prefix?: string } => {\n if (!file) {\n return {}\n }\n\n const submittedPrefix =\n isRecord(data) && typeof data.prefix === 'string' ? data.prefix : undefined\n const { uploadReference } = file\n\n // A staged upload only identifies server-owned temporary bytes, so its final destination still\n // comes from the accompanying document data, the same as a plain server upload.\n if (!isRecord(uploadReference) || 'uploadId' in uploadReference) {\n return { prefix: submittedPrefix }\n }\n\n return {\n objectKey:\n typeof uploadReference._objectKey === 'string' ? uploadReference._objectKey : undefined,\n prefix: typeof uploadReference.prefix === 'string' ? uploadReference.prefix : undefined,\n }\n}\n\nconst getDocumentProperty = (\n document: Record<string, unknown>,\n property: string,\n { locale, localizedProperties }: UploadDataOptions,\n): unknown => {\n const value = document[property]\n return locale && localizedProperties?.has(property) && isRecord(value) ? value[locale] : value\n}\n\n// Accepts flattened fields so localized identity fields declared inside presentational\n// containers (row/collapsible/unnamed tabs) are still detected — those live at the document\n// root data level but are nested in the config tree, so walking `fields` alone would miss them.\nexport const getLocalizedUploadProperties = (fields: FlattenedField[]): Set<string> => {\n const localizedProperties = new Set<string>()\n\n for (const field of fields) {\n if ('name' in field && (field as { localized?: boolean }).localized) {\n localizedProperties.add(field.name)\n }\n }\n\n return localizedProperties\n}\n\n// The submitted filename is stripped by sanitizeUploadData regardless, so this only exists to\n// reject path-traversal attempts loudly (400) instead of silently dropping them. Non-string\n// values are ignored here because they are removed by the caller anyway.\nconst validateFilename = (filename: unknown): void => {\n if (typeof filename !== 'string') {\n return\n }\n\n const pathSegments = filename.replace(/\\\\/g, '/').split('/')\n\n if (\n path.posix.isAbsolute(filename) ||\n path.win32.isAbsolute(filename) ||\n pathSegments.includes('..')\n ) {\n throw new APIError('Invalid filename.', 400)\n }\n}\n\nexport const sanitizeUploadData = <T>(data: T, operation: Operation): T => {\n if (!isRecord(data)) {\n return data\n }\n\n validateFilename(data.filename)\n\n if (isRecord(data.variants)) {\n for (const sizeData of Object.values(data.variants)) {\n if (isRecord(sizeData)) {\n validateFilename(sizeData.filename)\n }\n }\n }\n\n const sanitizedData: Record<string, unknown> = { ...data }\n delete sanitizedData.filename\n delete sanitizedData.variants\n delete sanitizedData.url\n // Server-owned; never accepted from the caller.\n delete sanitizedData._objectKey\n delete sanitizedData.original\n\n // On update, `prefix` is restored from the stored document (file identity); kept on create.\n if (operation === 'update') {\n delete sanitizedData.prefix\n }\n\n return sanitizedData as T\n}\n\n// Restores only the identity fields that select/serve a stored object (`filename`, `prefix`,\n// `url`, `variants`). Other generated-but-derived fields (`thumbnailURL`, `filesize`, `height`,\n// `width`, `mimeType`, `focalX`/`focalY`) are intentionally left as submitted: `focalX`/`focalY`\n// are user-editable crop input, and the rest are regenerated by generateFileData when a file is\n// written. Compare with restoreUploadDataFromDocument (version restore), which re-binds the full\n// tuple below.\nexport const mergeUploadDataWithDocument = <T>(\n data: T,\n document: unknown,\n options: UploadDataOptions = {},\n): T => {\n if (!isRecord(data) || !isRecord(document)) {\n return data\n }\n\n const mergedData: Record<string, unknown> = { ...data }\n\n for (const property of ['_objectKey', 'filename', 'original', 'prefix', 'url']) {\n if (!hasOwnProperty(data, property) && hasOwnProperty(document, property)) {\n mergedData[property] = getDocumentProperty(document, property, options)\n }\n }\n\n const documentSizes = getDocumentProperty(document, 'variants', options)\n if (!hasOwnProperty(data, 'variants') && hasOwnProperty(document, 'variants')) {\n mergedData.variants = documentSizes\n } else if (isRecord(data.variants) && isRecord(documentSizes)) {\n const mergedSizes: Record<string, unknown> = { ...documentSizes }\n\n for (const [sizeName, sizeData] of Object.entries(data.variants)) {\n const documentSize = documentSizes[sizeName]\n\n mergedSizes[sizeName] =\n isRecord(sizeData) && isRecord(documentSize) ? { ...documentSize, ...sizeData } : sizeData\n }\n\n mergedData.variants = mergedSizes\n }\n\n return mergedData as T\n}\n\nconst uploadDerivedProperties = [\n '_objectKey',\n 'filename',\n 'filesize',\n 'focalX',\n 'focalY',\n 'height',\n 'mimeType',\n 'original',\n 'prefix',\n 'variants',\n 'thumbnailURL',\n 'url',\n 'width',\n] as const\n\nexport const restoreUploadDataFromDocument = <T>(\n data: T,\n document: unknown,\n options: UploadDataOptions = {},\n): T => {\n if (!isRecord(data) || !isRecord(document)) {\n return data\n }\n\n const restoredData: Record<string, unknown> = { ...data }\n for (const property of uploadDerivedProperties) {\n if (hasOwnProperty(document, property)) {\n restoredData[property] = getDocumentProperty(document, property, options)\n } else if (options.clearMissing) {\n restoredData[property] = null\n } else {\n delete restoredData[property]\n }\n }\n\n return restoredData as T\n}\n"],"names":["path","APIError","hasOwnProperty","value","key","Object","prototype","call","isRecord","Array","isArray","getExternalUploadSource","data","filename","url","undefined","getUploadDestination","file","submittedPrefix","prefix","uploadReference","objectKey","_objectKey","getDocumentProperty","document","property","locale","localizedProperties","has","getLocalizedUploadProperties","fields","Set","field","localized","add","name","validateFilename","pathSegments","replace","split","posix","isAbsolute","win32","includes","sanitizeUploadData","operation","variants","sizeData","values","sanitizedData","original","mergeUploadDataWithDocument","options","mergedData","documentSizes","mergedSizes","sizeName","entries","documentSize","uploadDerivedProperties","restoreUploadDataFromDocument","restoredData","clearMissing"],"mappings":"AAAA,OAAOA,UAAU,OAAM;AAIvB,SAASC,QAAQ,QAAQ,wBAAuB;AAehD,MAAMC,iBAAiB,CAACC,OAAgCC,MACtDC,OAAOC,SAAS,CAACJ,cAAc,CAACK,IAAI,CAACJ,OAAOC;AAE9C,MAAMI,WAAW,CAACL,QAChB,OAAOA,UAAU,YAAYA,UAAU,QAAQ,CAACM,MAAMC,OAAO,CAACP;AAEhE,OAAO,MAAMQ,0BAA0B,CAACC;IACtC,IAAI,CAACJ,SAASI,SAAS,OAAOA,KAAKC,QAAQ,KAAK,YA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SAAS,GAAG;QAC3B,OAAO;YACL,OAAOoC,YAAY,CAACpC,SAAS;QAC/B;IACF;IAEA,OAAOoC;AACT,EAAC"}
1
+ {"version":3,"sources":["../../src/uploads/sanitizeUploadData.ts"],"sourcesContent":["import path from 'path'\n\nimport type { FlattenedField } from '../fields/config/types.js'\n\nimport { APIError } from '../errors/APIError.js'\n\ntype Operation = 'create' | 'update'\n\nexport type ExternalUploadSource = {\n filename: string\n url: string\n}\n\ntype UploadDataOptions = {\n clearMissing?: boolean\n locale?: string\n localizedProperties?: Set<string>\n}\n\nconst hasOwnProperty = (value: Record<string, unknown>, key: string): boolean =>\n Object.prototype.hasOwnProperty.call(value, key)\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value)\n\nexport const getExternalUploadSource = (data: unknown): ExternalUploadSource | undefined => {\n if (!isRecord(data) || typeof data.filename !== 'string' || typeof data.url !== 'string') {\n return undefined\n }\n\n return {\n filename: data.filename,\n url: data.url,\n }\n}\n\n// Resolves the server-owned upload destination for a document write. For provider uploads the\n// prefix and key segment come from the verified upload reference; for server uploads (including\n// staged uploads) the prefix falls back to the submitted document data and there is no key segment.\nexport const getUploadDestination = ({\n data,\n file,\n}: {\n data: unknown\n file: { uploadReference?: unknown } | null | undefined\n}): { objectKey?: string; prefix?: string } => {\n if (!file) {\n return {}\n }\n\n const submittedPrefix =\n isRecord(data) && typeof data.prefix === 'string' ? data.prefix : undefined\n const { uploadReference } = file\n\n // A staged upload only identifies server-owned temporary bytes, so its final destination still\n // comes from the accompanying document data, the same as a plain server upload.\n if (!isRecord(uploadReference) || 'uploadId' in uploadReference) {\n return { prefix: submittedPrefix }\n }\n\n return {\n objectKey:\n typeof uploadReference._objectKey === 'string' ? uploadReference._objectKey : undefined,\n prefix: typeof uploadReference.prefix === 'string' ? uploadReference.prefix : undefined,\n }\n}\n\nconst getDocumentProperty = (\n document: Record<string, unknown>,\n property: string,\n { locale, localizedProperties }: UploadDataOptions,\n): unknown => {\n const value = document[property]\n return locale && localizedProperties?.has(property) && isRecord(value) ? value[locale] : value\n}\n\n// Accepts flattened fields so localized identity fields declared inside presentational\n// containers (row/collapsible/unnamed tabs) are still detected — those live at the document\n// root data level but are nested in the config tree, so walking `fields` alone would miss them.\nexport const getLocalizedUploadProperties = (fields: FlattenedField[]): Set<string> => {\n const localizedProperties = new Set<string>()\n\n for (const field of fields) {\n if ('name' in field && (field as { localized?: boolean }).localized) {\n localizedProperties.add(field.name)\n }\n }\n\n return localizedProperties\n}\n\n// The submitted filename is stripped by sanitizeUploadData regardless, so this only exists to\n// reject path-traversal attempts loudly (400) instead of silently dropping them. Non-string\n// values are ignored here because they are removed by the caller anyway.\nconst validateFilename = (filename: unknown): void => {\n if (typeof filename !== 'string') {\n return\n }\n\n const pathSegments = filename.replace(/\\\\/g, '/').split('/')\n\n if (\n path.posix.isAbsolute(filename) ||\n path.win32.isAbsolute(filename) ||\n pathSegments.includes('..')\n ) {\n throw new APIError('Invalid filename.', 400)\n }\n}\n\nexport const sanitizeUploadData = <T>(data: T, operation: Operation): T => {\n if (!isRecord(data)) {\n return data\n }\n\n validateFilename(data.filename)\n\n if (isRecord(data.variants)) {\n for (const sizeData of Object.values(data.variants)) {\n if (isRecord(sizeData)) {\n validateFilename(sizeData.filename)\n }\n }\n }\n\n const sanitizedData: Record<string, unknown> = { ...data }\n delete sanitizedData.filename\n delete sanitizedData.variants\n delete sanitizedData.url\n // Server-owned; never accepted from the caller.\n delete sanitizedData._objectKey\n delete sanitizedData._stored\n delete sanitizedData.original\n\n // On update, `prefix` is restored from the stored document (file identity); kept on create.\n if (operation === 'update') {\n delete sanitizedData.prefix\n }\n\n return sanitizedData as T\n}\n\n// Restores only the identity fields that select/serve a stored object (`filename`, `prefix`,\n// `url`, `variants`). Other generated-but-derived fields (`thumbnailURL`, `filesize`, `height`,\n// `width`, `mimeType`, `focalX`/`focalY`) are intentionally left as submitted: `focalX`/`focalY`\n// are user-editable crop input, and the rest are regenerated by generateFileData when a file is\n// written. Compare with restoreUploadDataFromDocument (version restore), which re-binds the full\n// tuple below.\nexport const mergeUploadDataWithDocument = <T>(\n data: T,\n document: unknown,\n options: UploadDataOptions = {},\n): T => {\n if (!isRecord(data) || !isRecord(document)) {\n return data\n }\n\n const mergedData: Record<string, unknown> = { ...data }\n\n for (const property of ['_objectKey', 'filename', 'original', 'prefix', 'url']) {\n if (!hasOwnProperty(data, property) && hasOwnProperty(document, property)) {\n mergedData[property] = getDocumentProperty(document, property, options)\n }\n }\n\n const documentSizes = getDocumentProperty(document, 'variants', options)\n if (!hasOwnProperty(data, 'variants') && hasOwnProperty(document, 'variants')) {\n mergedData.variants = documentSizes\n } else if (isRecord(data.variants) && isRecord(documentSizes)) {\n const mergedSizes: Record<string, unknown> = { ...documentSizes }\n\n for (const [sizeName, sizeData] of Object.entries(data.variants)) {\n const documentSize = documentSizes[sizeName]\n\n mergedSizes[sizeName] =\n isRecord(sizeData) && isRecord(documentSize) ? { ...documentSize, ...sizeData } : sizeData\n }\n\n mergedData.variants = mergedSizes\n }\n\n return mergedData as T\n}\n\nconst uploadDerivedProperties = [\n '_transforms',\n '_objectKey',\n '_stored',\n 'filename',\n 'filesize',\n 'focalX',\n 'focalY',\n 'height',\n 'mimeType',\n 'original',\n 'prefix',\n 'variants',\n 'thumbnailURL',\n 'url',\n 'width',\n] as const\n\nexport const restoreUploadDataFromDocument = <T>(\n data: T,\n document: unknown,\n options: UploadDataOptions = {},\n): T => {\n if (!isRecord(data) || !isRecord(document)) {\n return data\n }\n\n const restoredData: Record<string, unknown> = { ...data }\n for (const property of uploadDerivedProperties) {\n if (hasOwnProperty(document, property)) {\n restoredData[property] = getDocumentProperty(document, property, options)\n } else if (options.clearMissing) {\n restoredData[property] = null\n } else {\n delete restoredData[property]\n }\n }\n\n return restoredData as T\n}\n"],"names":["path","APIError","hasOwnProperty","value","key","Object","prototype","call","isRecord","Array","isArray","getExternalUploadSource","data","filename","url","undefined","getUploadDestination","file","submittedPrefix","prefix","uploadReference","objectKey","_objectKey","getDocumentProperty","document","property","locale","localizedProperties","has","getLocalizedUploadProperties","fields","Set","field","localized","add","name","validateFilename","pathSegments","replace","split","posix","isAbsolute","win32","includes","sanitizeUploadData","operation","variants","sizeData","values","sanitizedData","_stored","original","mergeUploadDataWithDocument","options","mergedData","documentSizes","mergedSizes","sizeName","entries","documentSize","uploadDerivedProperties","restoreUploadDataFromDocument","restoredData","clearMissing"],"mappings":"AAAA,OAAOA,UAAU,OAAM;AAIvB,SAASC,QAAQ,QAAQ,wBAAuB;AAehD,MAAMC,iBAAiB,CAACC,OAAgCC,MACtDC,OAAOC,SAAS,CAACJ,cAAc,CAACK,IAAI,CAACJ,OAAOC;AAE9C,MAAMI,WAAW,CAACL,QAChB,OAAOA,UAAU,YAAYA,UAAU,QAAQ,CAACM,MAAMC,OAAO,CAACP;AAEhE,OAAO,MAAMQ,0BAA0B,CAACC;IACtC,IAAI,CAACJ,SAASI,SAAS,OAAOA,KAAKC,QAAQ,KAAK,YAAY,OAAOD,KAAKE,GAAG,KAAK,UAAU;QACxF,OAAOC;IACT;IAEA,OAAO;QACLF,UAAUD,KAAKC,QAAQ;QACvBC,KAAKF,KAAKE,GAAG;IACf;AACF,EAAC;AAED,8FAA8F;AAC9F,gGAAgG;AAChG,oGAAoG;AACpG,OAAO,MAAME,uBAAuB,CAAC,EACnCJ,IAAI,EACJK,IAAI,EAIL;IACC,IAAI,CAACA,MAAM;QACT,OAAO,CAAC;IACV;IAEA,MAAMC,kBACJV,SAASI,SAAS,OAAOA,KAAKO,MAAM,KAAK,WAAWP,KAAKO,MAAM,GAAGJ;IACpE,MAAM,EAAEK,eAAe,EAAE,GAAGH;IAE5B,+FAA+F;IAC/F,gFAAgF;IAChF,IAAI,CAACT,SAASY,oBAAoB,cAAcA,iBAAiB;QAC/D,OAAO;YAAED,QAAQD;QAAgB;IACnC;IAEA,OAAO;QACLG,WACE,OAAOD,gBAAgBE,UAAU,KAAK,WAAWF,g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AAS;YAE5CD,WAAW,CAACC,SAAS,GACnBjD,SAASuC,aAAavC,SAASmD,gBAAgB;gBAAE,GAAGA,YAAY;gBAAE,GAAGZ,QAAQ;YAAC,IAAIA;QACtF;QAEAO,WAAWR,QAAQ,GAAGU;IACxB;IAEA,OAAOF;AACT,EAAC;AAED,MAAMM,0BAA0B;IAC9B;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD;AAED,OAAO,MAAMC,gCAAgC,CAC3CjD,MACAY,UACA6B,UAA6B,CAAC,CAAC;IAE/B,IAAI,CAAC7C,SAASI,SAAS,CAACJ,SAASgB,WAAW;QAC1C,OAAOZ;IACT;IAEA,MAAMkD,eAAwC;QAAE,GAAGlD,IAAI;IAAC;IACxD,KAAK,MAAMa,YAAYmC,wBAAyB;QAC9C,IAAI1D,eAAesB,UAAUC,WAAW;YACtCqC,YAAY,CAACrC,SAAS,GAAGF,oBAAoBC,UAAUC,UAAU4B;QACnE,OAAO,IAAIA,QAAQU,YAAY,EAAE;YAC/BD,YAAY,CAACrC,SAAS,GAAG;QAC3B,OAAO;YACL,OAAOqC,YAAY,CAACrC,SAAS;QAC/B;IACF;IAEA,OAAOqC;AACT,EAAC"}
@@ -0,0 +1,21 @@
1
+ import type { Crop } from '../types.js';
2
+ /** A saved crop: integer pixels on the original file. */
3
+ export type PixelCrop = Omit<Crop, 'unit'>;
4
+ type Dimensions = {
5
+ height: number;
6
+ width: number;
7
+ };
8
+ /** Converts an editor crop to original-file pixels, kept inside the original. */
9
+ export declare function cropToPixels({ crop, original }: {
10
+ crop: Crop;
11
+ original: Dimensions;
12
+ }): PixelCrop;
13
+ /** Converts a saved pixel crop to the percent crop that the editor and Sharp read. */
14
+ export declare function cropToPercent({ crop, original }: {
15
+ crop: PixelCrop;
16
+ original: Dimensions;
17
+ }): Crop;
18
+ /** Whether an editor crop selects the whole image, which means "no crop". */
19
+ export declare const isFullCrop: (crop: Crop) => boolean;
20
+ export {};
21
+ //# sourceMappingURL=cropUnits.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cropUnits.d.ts","sourceRoot":"","sources":["../../../src/uploads/transformState/cropUnits.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAEvC,yDAAyD;AACzD,MAAM,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;AAE1C,KAAK,UAAU,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAA;AAEnD,iFAAiF;AACjF,wBAAgB,YAAY,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE;IAAE,IAAI,EAAE,IAAI,CAAC;IAAC,QAAQ,EAAE,UAAU,CAAA;CAAE,GAAG,SAAS,CAYhG;AAED,sFAAsF;AACtF,wBAAgB,aAAa,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,EAAE,UAAU,CAAA;CAAE,GAAG,IAAI,CAQjG;AAED,6EAA6E;AAC7E,eAAO,MAAM,UAAU,SAAU,IAAI,KAAG,OAKlB,CAAA"}
@@ -0,0 +1,23 @@
1
+ /** Converts an editor crop to original-file pixels, kept inside the original. */ export function cropToPixels({ crop, original }) {
2
+ const scale = (value, size)=>crop.unit === 'px' ? Math.round(value) : Math.round(value / 100 * size);
3
+ const x = Math.min(scale(crop.x, original.width), original.width - 1);
4
+ const y = Math.min(scale(crop.y, original.height), original.height - 1);
5
+ return {
6
+ height: Math.max(1, Math.min(scale(crop.height, original.height), original.height - y)),
7
+ width: Math.max(1, Math.min(scale(crop.width, original.width), original.width - x)),
8
+ x,
9
+ y
10
+ };
11
+ }
12
+ /** Converts a saved pixel crop to the percent crop that the editor and Sharp read. */ export function cropToPercent({ crop, original }) {
13
+ return {
14
+ height: crop.height / original.height * 100,
15
+ unit: '%',
16
+ width: crop.width / original.width * 100,
17
+ x: crop.x / original.width * 100,
18
+ y: crop.y / original.height * 100
19
+ };
20
+ }
21
+ /** Whether an editor crop selects the whole image, which means "no crop". */ export const isFullCrop = (crop)=>crop.unit === '%' && Number(crop.width) === 100 && Number(crop.height) === 100 && Number(crop.x) === 0 && Number(crop.y) === 0;
22
+
23
+ //# sourceMappingURL=cropUnits.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/uploads/transformState/cropUnits.ts"],"sourcesContent":["import type { Crop } from '../types.js'\n\n/** A saved crop: integer pixels on the original file. */\nexport type PixelCrop = Omit<Crop, 'unit'>\n\ntype Dimensions = { height: number; width: number }\n\n/** Converts an editor crop to original-file pixels, kept inside the original. */\nexport function cropToPixels({ crop, original }: { crop: Crop; original: Dimensions }): PixelCrop {\n const scale = (value: number, size: number) =>\n crop.unit === 'px' ? Math.round(value) : Math.round((value / 100) * size)\n const x = Math.min(scale(crop.x, original.width), original.width - 1)\n const y = Math.min(scale(crop.y, original.height), original.height - 1)\n\n return {\n height: Math.max(1, Math.min(scale(crop.height, original.height), original.height - y)),\n width: Math.max(1, Math.min(scale(crop.width, original.width), original.width - x)),\n x,\n y,\n }\n}\n\n/** Converts a saved pixel crop to the percent crop that the editor and Sharp read. */\nexport function cropToPercent({ crop, original }: { crop: PixelCrop; original: Dimensions }): Crop {\n return {\n height: (crop.height / original.height) * 100,\n unit: '%',\n width: (crop.width / original.width) * 100,\n x: (crop.x / original.width) * 100,\n y: (crop.y / original.height) * 100,\n }\n}\n\n/** Whether an editor crop selects the whole image, which means \"no crop\". */\nexport const isFullCrop = (crop: Crop): boolean =>\n crop.unit === '%' &&\n Number(crop.width) === 100 &&\n Number(crop.height) === 100 &&\n Number(crop.x) === 0 &&\n Number(crop.y) === 0\n"],"names":["cropToPixels","crop","original","scale","value","size","unit","Math","round","x","min","width","y","height","max","cropToPercent","isFullCrop","Number"],"mappings":"AAOA,+EAA+E,GAC/E,OAAO,SAASA,aA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AAC"}
@@ -0,0 +1,6 @@
1
+ /** The `_transforms` keys that were added, removed or changed between two values. */
2
+ export declare function getChangedTransformKeys({ next, previous, }: {
3
+ next: null | Record<string, unknown> | undefined;
4
+ previous: null | Record<string, unknown> | undefined;
5
+ }): string[];
6
+ //# sourceMappingURL=getChangedTransformKeys.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getChangedTransformKeys.d.ts","sourceRoot":"","sources":["../../../src/uploads/transformState/getChangedTransformKeys.ts"],"names":[],"mappings":"AAEA,qFAAqF;AACrF,wBAAgB,uBAAuB,CAAC,EACtC,IAAI,EACJ,QAAQ,GACT,EAAE;IACD,IAAI,EAAE,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAA;IAChD,QAAQ,EAAE,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAA;CACrD,GAAG,MAAM,EAAE,CAIX"}
@@ -0,0 +1,12 @@
1
+ import { isDeepStrictEqual } from 'node:util';
2
+ /** The `_transforms` keys that were added, removed or changed between two values. */ export function getChangedTransformKeys({ next, previous }) {
3
+ const keys = new Set([
4
+ ...Object.keys(next ?? {}),
5
+ ...Object.keys(previous ?? {})
6
+ ]);
7
+ return [
8
+ ...keys
9
+ ].filter((key)=>!isDeepStrictEqual(previous?.[key], next?.[key]));
10
+ }
11
+
12
+ //# sourceMappingURL=getChangedTransformKeys.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/uploads/transformState/getChangedTransformKeys.ts"],"sourcesContent":["import { isDeepStrictEqual } from 'node:util'\n\n/** The `_transforms` keys that were added, removed or changed between two values. */\nexport function getChangedTransformKeys({\n next,\n previous,\n}: {\n next: null | Record<string, unknown> | undefined\n previous: null | Record<string, unknown> | undefined\n}): string[] {\n const keys = new Set([...Object.keys(next ?? {}), ...Object.keys(previous ?? {})])\n\n return [...keys].filter((key) => !isDeepStrictEqual(previous?.[key], next?.[key]))\n}\n"],"names":["isDeepStrictEqual","getChangedTransformKeys","next","previous","keys","Set","Object","filter","key"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,YAAW;AAE7C,mFAAmF,GACnF,OAAO,SAASC,wBAAwB,EACtCC,IAAI,EACJC,QAAQ,EAIT;IACC,MAAMC,OAAO,IAAIC,IAAI;WAAIC,OAAOF,IAAI,CAACF,QAAQ,CAAC;WAAOI,OAAOF,IAAI,CAACD,YAAY,CAAC;KAAG;IAEjF,OAAO;WAAIC;KAAK,CAACG,MAAM,CAAC,CAACC,MAAQ,CAACR,kBAAkBG,UAAU,CAACK,IAAI,EAAEN,MAAM,CAACM,IAAI;AAClF"}
@@ -0,0 +1,15 @@
1
+ import type { UploadTransformer } from '../transformers/types.js';
2
+ /**
3
+ * Checks that no saved `_transforms` key is claimed by two stages that will run, and that every
4
+ * key that needs a claim (see `isClaimRequired`) has one. So a rebuild never saves a built-in key
5
+ * that nothing applies, or any key that two stages apply.
6
+ */
7
+ export declare function getTransformKeyCoverageErrors({ claims, transforms, }: {
8
+ /** The stages that will run, each with the keys it claims. */
9
+ claims: Map<UploadTransformer, string[]>;
10
+ transforms: null | Record<string, unknown> | undefined;
11
+ }): {
12
+ message: string;
13
+ path: string;
14
+ }[];
15
+ //# sourceMappingURL=getTransformKeyCoverageErrors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getTransformKeyCoverageErrors.d.ts","sourceRoot":"","sources":["../../../src/uploads/transformState/getTransformKeyCoverageErrors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAIjE;;;;GAIG;AACH,wBAAgB,6BAA6B,CAAC,EAC5C,MAAM,EACN,UAAU,GACX,EAAE;IACD,8DAA8D;IAC9D,MAAM,EAAE,GAAG,CAAC,iBAAiB,EAAE,MAAM,EAAE,CAAC,CAAA;IACxC,UAAU,EAAE,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAA;CACvD,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,EAAE,CAsBtC"}
@@ -0,0 +1,28 @@
1
+ import { isClaimRequired } from './transformKeyClaims.js';
2
+ /**
3
+ * Checks that no saved `_transforms` key is claimed by two stages that will run, and that every
4
+ * key that needs a claim (see `isClaimRequired`) has one. So a rebuild never saves a built-in key
5
+ * that nothing applies, or any key that two stages apply.
6
+ */ export function getTransformKeyCoverageErrors({ claims, transforms }) {
7
+ const errors = [];
8
+ for (const key of Object.keys(transforms ?? {})){
9
+ const claimers = [
10
+ ...claims
11
+ ].filter(([, keys])=>keys.includes(key));
12
+ if (claimers.length === 0 && isClaimRequired(key)) {
13
+ errors.push({
14
+ message: 'No configured transformer applies this key.',
15
+ path: `_transforms.${key}`
16
+ });
17
+ }
18
+ if (claimers.length > 1) {
19
+ errors.push({
20
+ message: `More than one transformer applies this key: ${claimers.map(([transformer])=>`"${transformer.slug}"`).join(', ')}.`,
21
+ path: `_transforms.${key}`
22
+ });
23
+ }
24
+ }
25
+ return errors;
26
+ }
27
+
28
+ //# sourceMappingURL=getTransformKeyCoverageErrors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/uploads/transformState/getTransformKeyCoverageErrors.ts"],"sourcesContent":["import type { UploadTransformer } from '../transformers/types.js'\n\nimport { isClaimRequired } from './transformKeyClaims.js'\n\n/**\n * Checks that no saved `_transforms` key is claimed by two stages that will run, and that every\n * key that needs a claim (see `isClaimRequired`) has one. So a rebuild never saves a built-in key\n * that nothing applies, or any key that two stages apply.\n */\nexport function getTransformKeyCoverageErrors({\n claims,\n transforms,\n}: {\n /** The stages that will run, each with the keys it claims. */\n claims: Map<UploadTransformer, string[]>\n transforms: null | Record<string, unknown> | undefined\n}): { message: string; path: string }[] {\n const errors: { message: string; path: string }[] = []\n\n for (const key of Object.keys(transforms ?? {})) {\n const claimers = [...claims].filter(([, keys]) => keys.includes(key))\n\n if (claimers.length === 0 && isClaimRequired(key)) {\n errors.push({\n message: 'No configured transformer applies this key.',\n path: `_transforms.${key}`,\n })\n }\n\n if (claimers.length > 1) {\n errors.push({\n message: `More than one transformer applies this key: ${claimers.map(([transformer]) => `\"${transformer.slug}\"`).join(', ')}.`,\n path: `_transforms.${key}`,\n })\n }\n }\n\n return errors\n}\n"],"names":["isClaimRequired","getTransformKeyCoverageErrors","claims","transforms","errors","key","Object","keys","claimers","filter","includes","length","push","message","path","map","transformer","slug","join"],"mappings":"AAEA,SAASA,eAAe,QAAQ,0BAAyB;AAEzD;;;;CAIC,GACD,OAAO,SAASC,8BAA8B,EAC5CC,MAAM,EACNC,UAAU,EAKX;IACC,MAAMC,SAA8C,EAAE;IAEtD,KAAK,MAAMC,OAAOC,OAAOC,IAAI,CAACJ,cAAc,CAAC,GAAI;QAC/C,MAAMK,WAAW;eAAIN;SAAO,CAACO,MAAM,CAAC,CAAC,GAAGF,KAAK,GAAKA,KAAKG,QAAQ,CAACL;QAEhE,IAAIG,SAASG,MAAM,KAAK,KAAKX,gBAAgBK,MAAM;YACjDD,OAAOQ,IAAI,CAAC;gBACVC,SAAS;gBACTC,MAAM,CAAC,YAAY,EAAET,KAAK;YAC5B;QACF;QAEA,IAAIG,SAASG,MAAM,GAAG,GAAG;YACvBP,OAAOQ,IAAI,CAAC;gBACVC,SAAS,CAAC,4CAA4C,EAAEL,SAASO,GAAG,CAAC,CAAC,CAACC,YAAY,GAAK,CAAC,CAAC,EAAEA,YAAYC,IAAI,CAAC,CAAC,CAAC,EAAEC,IAAI,CAAC,MAAM,CAAC,CAAC;gBAC9HJ,MAAM,CAAC,YAAY,EAAET,KAAK;YAC5B;QACF;IACF;IAEA,OAAOD;AACT"}
@@ -0,0 +1,24 @@
1
+ import type { Document, PayloadRequest } from '../../types/index.js';
2
+ import type { PlannedTransformerPipeline } from '../transformers/planTransformerPipeline.js';
3
+ /**
4
+ * Plans the request stages that apply the saved `_transforms` to a default file with no stored
5
+ * object, and checks that they cover every saved key. A save uses it to decide that the default
6
+ * file can be built at request time, and a request uses it to build that file. Both must use the
7
+ * same rule, or a document saved with no stored default could fail on every request.
8
+ */
9
+ export declare function planPersistedDefaultStages({ collectionSlug, doc, documentID, mimeType, req, transforms, }: {
10
+ collectionSlug: string;
11
+ /** The read-only document that planning sees, as both `doc` and `originalDoc`. */
12
+ doc: Readonly<Document>;
13
+ documentID?: number | string;
14
+ mimeType: string;
15
+ req: PayloadRequest;
16
+ transforms: Document['_transforms'];
17
+ }): Promise<{
18
+ coverageErrors: {
19
+ message: string;
20
+ path: string;
21
+ }[];
22
+ plan: PlannedTransformerPipeline;
23
+ }>;
24
+ //# sourceMappingURL=planPersistedDefaultStages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"planPersistedDefaultStages.d.ts","sourceRoot":"","sources":["../../../src/uploads/transformState/planPersistedDefaultStages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACpE,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,4CAA4C,CAAA;AAK5F;;;;;GAKG;AACH,wBAAsB,0BAA0B,CAAC,EAC/C,cAAc,EACd,GAAG,EACH,UAAU,EACV,QAAQ,EACR,GAAG,EACH,UAAU,GACX,EAAE;IACD,cAAc,EAAE,MAAM,CAAA;IACtB,kFAAkF;IAClF,GAAG,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAA;IACvB,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IAC5B,QAAQ,EAAE,MAAM,CAAA;IAChB,GAAG,EAAE,cAAc,CAAA;IACnB,UAAU,EAAE,QAAQ,CAAC,aAAa,CAAC,CAAA;CACpC,GAAG,OAAO,CAAC;IACV,cAAc,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;IACnD,IAAI,EAAE,0BAA0B,CAAA;CACjC,CAAC,CAoBD"}
@@ -0,0 +1,32 @@
1
+ import { planTransformerPipeline } from '../transformers/planTransformerPipeline.js';
2
+ import { getTransformKeyCoverageErrors } from './getTransformKeyCoverageErrors.js';
3
+ /**
4
+ * Plans the request stages that apply the saved `_transforms` to a default file with no stored
5
+ * object, and checks that they cover every saved key. A save uses it to decide that the default
6
+ * file can be built at request time, and a request uses it to build that file. Both must use the
7
+ * same rule, or a document saved with no stored default could fail on every request.
8
+ */ export async function planPersistedDefaultStages({ collectionSlug, doc, documentID, mimeType, req, transforms }) {
9
+ const plan = await planTransformerPipeline({
10
+ args: {
11
+ collectionSlug,
12
+ doc,
13
+ documentID,
14
+ mimeType,
15
+ operation: 'request',
16
+ originalDoc: doc,
17
+ purpose: 'persisted-default',
18
+ req
19
+ },
20
+ capability: 'handleRequest',
21
+ transformers: req.payload.config.upload?.transformers ?? []
22
+ });
23
+ return {
24
+ coverageErrors: getTransformKeyCoverageErrors({
25
+ claims: plan.claims,
26
+ transforms
27
+ }),
28
+ plan
29
+ };
30
+ }
31
+
32
+ //# sourceMappingURL=planPersistedDefaultStages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/uploads/transformState/planPersistedDefaultStages.ts"],"sourcesContent":["import type { Document, PayloadRequest } from '../../types/index.js'\nimport type { PlannedTransformerPipeline } from '../transformers/planTransformerPipeline.js'\n\nimport { planTransformerPipeline } from '../transformers/planTransformerPipeline.js'\nimport { getTransformKeyCoverageErrors } from './getTransformKeyCoverageErrors.js'\n\n/**\n * Plans the request stages that apply the saved `_transforms` to a default file with no stored\n * object, and checks that they cover every saved key. A save uses it to decide that the default\n * file can be built at request time, and a request uses it to build that file. Both must use the\n * same rule, or a document saved with no stored default could fail on every request.\n */\nexport async function planPersistedDefaultStages({\n collectionSlug,\n doc,\n documentID,\n mimeType,\n req,\n transforms,\n}: {\n collectionSlug: string\n /** The read-only document that planning sees, as both `doc` and `originalDoc`. */\n doc: Readonly<Document>\n documentID?: number | string\n mimeType: string\n req: PayloadRequest\n transforms: Document['_transforms']\n}): Promise<{\n coverageErrors: { message: string; path: string }[]\n plan: PlannedTransformerPipeline\n}> {\n const plan = await planTransformerPipeline({\n args: {\n collectionSlug,\n doc,\n documentID,\n mimeType,\n operation: 'request',\n originalDoc: doc,\n purpose: 'persisted-default',\n req,\n },\n capability: 'handleRequest',\n transformers: req.payload.config.upload?.transformers ?? [],\n })\n\n return {\n coverageErrors: getTransformKeyCoverageErrors({ claims: plan.claims, transforms }),\n plan,\n }\n}\n"],"names":["planTransformerPipeline","getTransformKeyCoverageErrors","planPersistedDefaultStages","collectionSlug","doc","documentID","mimeType","req","transforms","plan","args","operation","originalDoc","purpose","capability","transformers","payload","config","upload","coverageErrors","claims"],"mappings":"AAGA,SAASA,uBAAuB,QAAQ,6CAA4C;AACpF,SAASC,6BAA6B,QAAQ,qCAAoC;AAElF;;;;;CAKC,GACD,OAAO,eAAeC,2BAA2B,EAC/CC,cAAc,EACdC,GAAG,EACHC,UAAU,EACVC,QAAQ,EACRC,GAAG,EACHC,UAAU,EASX;IAIC,MAAMC,OAAO,MAAMT,wBAAwB;QACzCU,MAAM;YACJP;YACAC;YACAC;YACAC;YACAK,WAAW;YACXC,aAAaR;YACbS,SAAS;YACTN;QACF;QACAO,YAAY;QACZC,cAAcR,IAAIS,OAAO,CAACC,MAAM,CAACC,MAAM,EAAEH,gBAAgB,EAAE;IAC7D;IAEA,OAAO;QACLI,gBAAgBlB,8BAA8B;YAAEmB,QAAQX,KAAKW,MAAM;YAAEZ;QAAW;QAChFC;IACF;AACF"}
@@ -0,0 +1,95 @@
1
+ import type { Document, PayloadRequest } from '../../types/index.js';
2
+ import type { PlannedTransformerPipeline } from '../transformers/planTransformerPipeline.js';
3
+ import type { UploadTransformer } from '../transformers/types.js';
4
+ export type UploadPlan = {
5
+ mimeType: string;
6
+ } & PlannedTransformerPipeline;
7
+ /**
8
+ * What an upload with no new file does with its stored file.
9
+ * - `keep`: nothing changes the file, so the stored files stay.
10
+ * - `rebuild`: upload stages build new files from the stored file.
11
+ * - `applyAtRequest`: request-time stages apply the saved keys, so no file is read or written.
12
+ * - `copyForRequest`: a copy reads the source's original to store its own, and request-time stages
13
+ * apply the saved keys. No upload stage runs.
14
+ */
15
+ export type UploadRebuildOutcome = 'applyAtRequest' | 'copyForRequest' | 'keep' | 'rebuild';
16
+ type PlanArgs = {
17
+ collectionSlug: string;
18
+ pipelineDoc: Document;
19
+ pipelineOriginalDoc: Readonly<Document>;
20
+ req: PayloadRequest;
21
+ };
22
+ /**
23
+ * Decides whether an upload without a new file rebuilds from the stored file. A rebuild is planned
24
+ * with the stored MIME type, so a key that cannot be applied fails before the stored file is read.
25
+ * When request-time stages apply the saved keys, an update writes no file, and only a copy reads
26
+ * the stored original.
27
+ */
28
+ export declare function planUploadRebuild({ canApplyAtRequest, documentID, hasCropOrFocalPointEdit, hasCropOrResizeEdit, isDuplicating, isExternalSource, previousTransforms, storedMimeType, ...planArgs }: {
29
+ /** False when no original would be stored for request-time stages to start from. */
30
+ canApplyAtRequest: boolean;
31
+ documentID?: number | string;
32
+ /**
33
+ * A crop or resize in `uploadEdits`, or a focal point that differs from the stored one
34
+ * (`shouldReupload`). These triggers rebuilt the file before claims existed.
35
+ */
36
+ hasCropOrFocalPointEdit: boolean;
37
+ /** A crop or resize sent in the `uploadEdits` query. */
38
+ hasCropOrResizeEdit: boolean;
39
+ isDuplicating: boolean;
40
+ isExternalSource: boolean;
41
+ /** The stored `_transforms` on an update; `undefined` when there is nothing to compare. */
42
+ previousTransforms: Document['_transforms'] | undefined;
43
+ storedMimeType: string | undefined;
44
+ } & PlanArgs): Promise<{
45
+ outcome: UploadRebuildOutcome;
46
+ rebuildPlan?: UploadPlan;
47
+ }>;
48
+ /** Plans the upload pipeline for one MIME type, without checking claims. */
49
+ export declare function planUploadPipeline({ collectionSlug, mimeType, pipelineOriginalDoc, req, }: {
50
+ mimeType: string;
51
+ } & PlanArgs): Promise<UploadPlan>;
52
+ /**
53
+ * The planned stages that run. Only one Sharp bridge drives an upload: the one that owns the
54
+ * collection, or the first. The other bridges do not run, so they do not count as claimers, and
55
+ * they must not see the chosen bridge's task options, which are private to it.
56
+ */
57
+ export declare function getStagesThatRun({ collectionSlug, plan, }: {
58
+ collectionSlug: string;
59
+ plan: PlannedTransformerPipeline;
60
+ }): {
61
+ bridgeTransformer?: UploadTransformer;
62
+ /** The claims of the stages that run. */
63
+ claimsOfStagesThatRun: Map<UploadTransformer, string[]>;
64
+ stagesThatRun: UploadTransformer[];
65
+ };
66
+ /**
67
+ * Decides where the saved keys are applied. Upload stages that run apply them into a stored file.
68
+ * When those leave a key with no claim, request-time stages can apply every saved key instead: the
69
+ * default file is then built when it is requested, and only the original is stored. When both kinds
70
+ * claim a key, the upload stage wins. Fails before any file work when neither covers the keys.
71
+ */
72
+ export declare function resolveTransformKeyCoverage({ canApplyAtRequest, collectionSlug, documentID, mimeType, pipelineDoc, pipelineOriginalDoc, plan, req, }: {
73
+ /** False when no original would be stored for request-time stages to start from. */
74
+ canApplyAtRequest: boolean;
75
+ documentID?: number | string;
76
+ mimeType: string;
77
+ plan: PlannedTransformerPipeline;
78
+ } & PlanArgs): Promise<{
79
+ isAppliedAtRequest: boolean;
80
+ }>;
81
+ /** Fails before any file work when a saved key has no claiming stage, or more than one. */
82
+ export declare function assertTransformKeysCovered({ collectionSlug, pipelineDoc, plan, req, }: {
83
+ plan: PlannedTransformerPipeline;
84
+ } & Pick<PlanArgs, 'collectionSlug' | 'pipelineDoc' | 'req'>): void;
85
+ /**
86
+ * Whether request-time stages can build a file of this MIME type from the original, applying every
87
+ * saved key. With `requiredTransformerSlug`, that transformer must also be one of the stages.
88
+ */
89
+ export declare function canBuildAtRequest({ collectionSlug, documentID, mimeType, pipelineDoc, pipelineOriginalDoc, req, requiredTransformerSlug, }: {
90
+ documentID?: number | string;
91
+ mimeType: string;
92
+ requiredTransformerSlug?: string;
93
+ } & PlanArgs): Promise<boolean>;
94
+ export {};
95
+ //# sourceMappingURL=planUpload.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"planUpload.d.ts","sourceRoot":"","sources":["../../../src/uploads/transformState/planUpload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACpE,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,4CAA4C,CAAA;AAC5F,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAUjE,MAAM,MAAM,UAAU,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,0BAA0B,CAAA;AAE1E;;;;;;;GAOG;AACH,MAAM,MAAM,oBAAoB,GAAG,gBAAgB,GAAG,gBAAgB,GAAG,MAAM,GAAG,SAAS,CAAA;AAE3F,KAAK,QAAQ,GAAG;IACd,cAAc,EAAE,MAAM,CAAA;IACtB,WAAW,EAAE,QAAQ,CAAA;IACrB,mBAAmB,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAA;IACvC,GAAG,EAAE,cAAc,CAAA;CACpB,CAAA;AAED;;;;;GAKG;AACH,wBAAsB,iBAAiB,CAAC,EACtC,iBAAiB,EACjB,UAAU,EACV,uBAAuB,EACvB,mBAAmB,EACnB,aAAa,EACb,gBAAgB,EAChB,kBAAkB,EAClB,cAAc,EACd,GAAG,QAAQ,EACZ,EAAE;IACD,oFAAoF;IACpF,iBAAiB,EAAE,OAAO,CAAA;IAC1B,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IAC5B;;;OAGG;IACH,uBAAuB,EAAE,OAAO,CAAA;IAChC,wDAAwD;IACxD,mBAAmB,EAAE,OAAO,CAAA;IAC5B,aAAa,EAAE,OAAO,CAAA;IACtB,gBAAgB,EAAE,OAAO,CAAA;IACzB,2FAA2F;IAC3F,kBAAkB,EAAE,QAAQ,CAAC,aAAa,CAAC,GAAG,SAAS,CAAA;IACvD,cAAc,EAAE,MAA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