@payloadcms/transformer-sharp 4.0.0-internal.ea6e8f8 → 4.0.0-internal.f2a04f7
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.
- package/dist/initSharpCollections.js.map +1 -1
- package/package.json +14 -14
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/initSharpCollections.ts"],"sourcesContent":["import type { Config, SanitizedUploadConfig } from 'payload'\n\nimport type { SharpCollectionConfig } from './types.js'\n\nconst RESERVED_IMAGE_SIZE_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 * Validates `sharpTransformer({ collections })` against the config's real\n * collections, then writes a narrowed, Sharp-agnostic projection of\n * `variants`/`crop`/`focalPoint`/`hasImageAdjustments` back onto each\n * targeted collection's sanitized `upload` config, so core's own field\n * generation and Admin UI keep working without knowing about Sharp.\n */\nexport function initSharpCollections({\n collections,\n config,\n}: {\n collections: Partial<Record<string, SharpCollectionConfig>>\n config: Config\n}): Config {\n const errors: string[] = []\n\n for (const [slug, sharpConfig] of Object.entries(collections)) {\n if (!sharpConfig) {\n continue\n }\n\n const collection = config.collections?.find((candidate) => candidate.slug === slug)\n\n if (!collection) {\n errors.push(\n `sharpTransformer collections.\"${slug}\" does not match any configured collection slug.`,\n )\n continue\n }\n\n if (!collection.upload) {\n errors.push(\n `sharpTransformer collections.\"${slug}\" targets a collection whose \\`upload\\` option is not set. Enable uploads on \"${slug}\" first.`,\n )\n continue\n }\n\n const seenSizeNames = new Set<string>()\n\n for (const size of sharpConfig.variants ?? []) {\n if (typeof size.name !== 'string' || size.name.trim().length === 0) {\n errors.push(\n `sharpTransformer collections.\"${slug}\".variants has an entry missing a valid \\`name\\`.`,\n )\n continue\n }\n\n if (seenSizeNames.has(size.name)) {\n errors.push(\n `sharpTransformer collections.\"${slug}\".variants has a duplicate size name: \"${size.name}\".`,\n )\n }\n seenSizeNames.add(size.name)\n\n if (RESERVED_IMAGE_SIZE_NAMES.includes(size.name)) {\n errors.push(\n `sharpTransformer collections.\"${slug}\".variants uses reserved name \"${size.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 \\`sharpTransformer({ collections })\\` configuration:\\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 const sanitizedCollections = config.collections?.map((collection) => {\n const sharpConfig = collections[collection.slug]\n\n if (!sharpConfig || !collection.upload) {\n return collection\n }\n\n const authoredUpload = typeof collection.upload === 'object' ? collection.upload : {}\n\n const upload: Partial<SanitizedUploadConfig> = {\n ...authoredUpload,\n // Sharp's setting wins when given; otherwise keep the collection's own, so an\n // unset Sharp option can't silently re-enable a collection's `crop: false`.\n crop: sharpConfig.crop ?? authoredUpload.crop,\n focalPoint: sharpConfig.focalPoint ?? authoredUpload.focalPoint,\n hasImageAdjustments: Boolean(\n sharpConfig.resizeOptions ||\n
|
|
1
|
+
{"version":3,"sources":["../src/initSharpCollections.ts"],"sourcesContent":["import type { Config, SanitizedUploadConfig } from 'payload'\n\nimport type { SharpCollectionConfig } from './types.js'\n\nconst RESERVED_IMAGE_SIZE_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 * Validates `sharpTransformer({ collections })` against the config's real\n * collections, then writes a narrowed, Sharp-agnostic projection of\n * `variants`/`crop`/`focalPoint`/`hasImageAdjustments` back onto each\n * targeted collection's sanitized `upload` config, so core's own field\n * generation and Admin UI keep working without knowing about Sharp.\n */\nexport function initSharpCollections({\n collections,\n config,\n}: {\n collections: Partial<Record<string, SharpCollectionConfig>>\n config: Config\n}): Config {\n const errors: string[] = []\n\n for (const [slug, sharpConfig] of Object.entries(collections)) {\n if (!sharpConfig) {\n continue\n }\n\n const collection = config.collections?.find((candidate) => candidate.slug === slug)\n\n if (!collection) {\n errors.push(\n `sharpTransformer collections.\"${slug}\" does not match any configured collection slug.`,\n )\n continue\n }\n\n if (!collection.upload) {\n errors.push(\n `sharpTransformer collections.\"${slug}\" targets a collection whose \\`upload\\` option is not set. Enable uploads on \"${slug}\" first.`,\n )\n continue\n }\n\n const seenSizeNames = new Set<string>()\n\n for (const size of sharpConfig.variants ?? []) {\n if (typeof size.name !== 'string' || size.name.trim().length === 0) {\n errors.push(\n `sharpTransformer collections.\"${slug}\".variants has an entry missing a valid \\`name\\`.`,\n )\n continue\n }\n\n if (seenSizeNames.has(size.name)) {\n errors.push(\n `sharpTransformer collections.\"${slug}\".variants has a duplicate size name: \"${size.name}\".`,\n )\n }\n seenSizeNames.add(size.name)\n\n if (RESERVED_IMAGE_SIZE_NAMES.includes(size.name)) {\n errors.push(\n `sharpTransformer collections.\"${slug}\".variants uses reserved name \"${size.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 \\`sharpTransformer({ collections })\\` configuration:\\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 const sanitizedCollections = config.collections?.map((collection) => {\n const sharpConfig = collections[collection.slug]\n\n if (!sharpConfig || !collection.upload) {\n return collection\n }\n\n const authoredUpload = typeof collection.upload === 'object' ? collection.upload : {}\n\n const upload: Partial<SanitizedUploadConfig> = {\n ...authoredUpload,\n // Sharp's setting wins when given; otherwise keep the collection's own, so an\n // unset Sharp option can't silently re-enable a collection's `crop: false`.\n crop: sharpConfig.crop ?? authoredUpload.crop,\n focalPoint: sharpConfig.focalPoint ?? authoredUpload.focalPoint,\n hasImageAdjustments: Boolean(\n sharpConfig.resizeOptions ||\n sharpConfig.formatOptions ||\n sharpConfig.trimOptions ||\n sharpConfig.constructorOptions ||\n sharpConfig.withMetadata,\n ),\n variants: sharpConfig.variants?.map(({ name, admin, generateImageName }) => ({\n name,\n admin,\n generateImageName,\n })),\n }\n\n return { ...collection, upload }\n })\n\n return { ...config, collections: sanitizedCollections }\n}\n"],"names":["RESERVED_IMAGE_SIZE_NAMES","initSharpCollections","collections","config","errors","slug","sharpConfig","Object","entries","collection","find","candidate","push","upload","seenSizeNames","Set","size","variants","name","trim","length","has","add","includes","Error","join","sanitizedCollections","map","authoredUpload","crop","focalPoint","hasImageAdjustments","Boolean","resizeOptions","formatOptions","trimOptions","constructorOptions","withMetadata","admin","generateImageName"],"mappings":"AAIA,MAAMA,4BAA4B;IAChC;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD;AAED;;;;;;CAMC,GACD,OAAO,SAASC,qBAAqB,EACnCC,WAAW,EACXC,MAAM,EAIP;IACC,MAAMC,SAAmB,EAAE;IAE3B,KAAK,MAAM,CAACC,MAAMC,YAAY,IAAIC,OAAOC,OAAO,CAACN,aAAc;QAC7D,IAAI,CAACI,aAAa;YAChB;QACF;QAEA,MAAMG,aAAaN,OAAOD,WAAW,EAAEQ,KAAK,CAACC,YAAcA,UAAUN,IAAI,KAAKA;QAE9E,IAAI,CAACI,YAAY;YACfL,OAAOQ,IAAI,CACT,CAAC,8BAA8B,EAAEP,KAAK,gDAAgD,CAAC;YAEzF;QACF;QAEA,IAAI,CAACI,WAAWI,MAAM,EAAE;YACtBT,OAAOQ,IAAI,CACT,CAAC,8BAA8B,EAAEP,KAAK,8EAA8E,EAAEA,KAAK,QAAQ,CAAC;YAEtI;QACF;QAEA,MAAMS,gBAAgB,IAAIC;QAE1B,KAAK,MAAMC,QAAQV,YAAYW,QAAQ,IAAI,EAAE,CAAE;YAC7C,IAAI,OAAOD,KAAKE,IAAI,KAAK,YAAYF,KAAKE,IAAI,CAACC,IAAI,GAAGC,MAAM,KAAK,GAAG;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I,CAAC,EAAET,IAAI,EAAEoB,KAAK,EAAEC,iBAAiB,EAAE,GAAM,CAAA;oBAC3ErB;oBACAoB;oBACAC;gBACF,CAAA;QACF;QAEA,OAAO;YAAE,GAAG9B,UAAU;YAAEI;QAAO;IACjC;IAEA,OAAO;QAAE,GAAGV,MAAM;QAAED,aAAawB;IAAqB;AACxD"}
|
package/package.json
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/transformer-sharp",
|
|
3
|
-
"version": "4.0.0-internal.
|
|
3
|
+
"version": "4.0.0-internal.f2a04f7",
|
|
4
4
|
"description": "Official Sharp-based file transformer for Payload: request-time image resizing and upload-time image processing",
|
|
5
5
|
"homepage": "https://payloadcms.com",
|
|
6
|
-
"repository": {
|
|
7
|
-
"type": "git",
|
|
8
|
-
"url": "https://github.com/payloadcms/payload.git",
|
|
9
|
-
"directory": "packages/transformer-sharp"
|
|
10
|
-
},
|
|
11
6
|
"license": "MIT",
|
|
12
7
|
"author": "Payload <dev@payloadcms.com> (https://payloadcms.com)",
|
|
13
8
|
"maintainers": [
|
|
@@ -17,8 +12,18 @@
|
|
|
17
12
|
"url": "https://payloadcms.com"
|
|
18
13
|
}
|
|
19
14
|
],
|
|
20
|
-
"
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/payloadcms/payload.git",
|
|
18
|
+
"directory": "packages/transformer-sharp"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist"
|
|
22
|
+
],
|
|
21
23
|
"type": "module",
|
|
24
|
+
"sideEffects": false,
|
|
25
|
+
"main": "./dist/index.js",
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
22
27
|
"exports": {
|
|
23
28
|
".": {
|
|
24
29
|
"import": "./dist/index.js",
|
|
@@ -26,19 +31,14 @@
|
|
|
26
31
|
"default": "./dist/index.js"
|
|
27
32
|
}
|
|
28
33
|
},
|
|
29
|
-
"main": "./dist/index.js",
|
|
30
|
-
"types": "./dist/index.d.ts",
|
|
31
|
-
"files": [
|
|
32
|
-
"dist"
|
|
33
|
-
],
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"sharp": "0.35.4"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"payload": "4.0.0-internal.
|
|
38
|
+
"payload": "4.0.0-internal.f2a04f7"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
|
-
"payload": "4.0.0-internal.
|
|
41
|
+
"payload": "4.0.0-internal.f2a04f7"
|
|
42
42
|
},
|
|
43
43
|
"engines": {
|
|
44
44
|
"node": ">=24.15.0"
|