@aphexcms/cms-core 9.10.0 → 10.0.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.
- package/dist/api/assets.d.ts +62 -7
- package/dist/api/assets.d.ts.map +1 -1
- package/dist/api/assets.js +116 -9
- package/dist/api/client.d.ts +1 -1
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +39 -9
- package/dist/api/limits.d.ts +55 -0
- package/dist/api/limits.d.ts.map +1 -0
- package/dist/api/limits.js +58 -0
- package/dist/api/schemas/assets.d.ts +94 -4
- package/dist/api/schemas/assets.d.ts.map +1 -1
- package/dist/api/schemas/assets.js +82 -5
- package/dist/api/types.d.ts +25 -0
- package/dist/api/types.d.ts.map +1 -1
- package/dist/api/upload-timeout.d.ts +17 -0
- package/dist/api/upload-timeout.d.ts.map +1 -0
- package/dist/api/upload-timeout.js +35 -0
- package/dist/api/upload.d.ts +42 -0
- package/dist/api/upload.d.ts.map +1 -0
- package/dist/api/upload.js +144 -0
- package/dist/components/AdminApp.svelte +130 -26
- package/dist/components/AdminApp.svelte.d.ts.map +1 -1
- package/dist/components/admin/AssetBrowserModal.svelte +4 -3
- package/dist/components/admin/AssetBrowserModal.svelte.d.ts +2 -1
- package/dist/components/admin/AssetBrowserModal.svelte.d.ts.map +1 -1
- package/dist/components/admin/MediaBrowser.svelte +1859 -281
- package/dist/components/admin/MediaBrowser.svelte.d.ts +21 -1
- package/dist/components/admin/MediaBrowser.svelte.d.ts.map +1 -1
- package/dist/components/admin/fields/ArrayField.svelte +21 -10
- package/dist/components/admin/fields/ArrayField.svelte.d.ts.map +1 -1
- package/dist/components/admin/fields/FileField.svelte +9 -2
- package/dist/components/admin/fields/FileField.svelte.d.ts.map +1 -1
- package/dist/components/admin/fields/ImageField.svelte +47 -12
- package/dist/components/admin/fields/ImageField.svelte.d.ts.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +14 -0
- package/dist/db/interfaces/asset.d.ts +114 -5
- package/dist/db/interfaces/asset.d.ts.map +1 -1
- package/dist/db/interfaces/document.d.ts +98 -3
- package/dist/db/interfaces/document.d.ts.map +1 -1
- package/dist/hooks.d.ts.map +1 -1
- package/dist/hooks.js +2 -1
- package/dist/image/Image.svelte +72 -0
- package/dist/image/Image.svelte.d.ts +40 -0
- package/dist/image/Image.svelte.d.ts.map +1 -0
- package/dist/image/index.d.ts +3 -0
- package/dist/image/index.d.ts.map +1 -0
- package/dist/image/index.js +11 -0
- package/dist/image/types.d.ts +28 -0
- package/dist/image/types.d.ts.map +1 -0
- package/dist/image/types.js +1 -0
- package/dist/images/generate.d.ts +55 -0
- package/dist/images/generate.d.ts.map +1 -0
- package/dist/images/generate.js +243 -0
- package/dist/images/index.d.ts +2 -0
- package/dist/images/index.d.ts.map +1 -0
- package/dist/images/index.js +7 -0
- package/dist/images/variants.d.ts +82 -0
- package/dist/images/variants.d.ts.map +1 -0
- package/dist/images/variants.js +124 -0
- package/dist/jobs/asset-reference-jobs.d.ts +49 -0
- package/dist/jobs/asset-reference-jobs.d.ts.map +1 -0
- package/dist/jobs/asset-reference-jobs.js +74 -0
- package/dist/jobs/run-batch.d.ts.map +1 -1
- package/dist/jobs/run-batch.js +5 -0
- package/dist/lib/api/assets.d.ts +62 -7
- package/dist/lib/api/assets.d.ts.map +1 -1
- package/dist/lib/api/assets.js +116 -9
- package/dist/lib/api/assets.js.map +1 -1
- package/dist/lib/api/client.d.ts +1 -1
- package/dist/lib/api/client.d.ts.map +1 -1
- package/dist/lib/api/client.js +39 -9
- package/dist/lib/api/client.js.map +1 -1
- package/dist/lib/api/limits.d.ts +55 -0
- package/dist/lib/api/limits.d.ts.map +1 -0
- package/dist/lib/api/limits.js +59 -0
- package/dist/lib/api/limits.js.map +1 -0
- package/dist/lib/api/schemas/assets.d.ts +94 -4
- package/dist/lib/api/schemas/assets.d.ts.map +1 -1
- package/dist/lib/api/schemas/assets.js +82 -5
- package/dist/lib/api/schemas/assets.js.map +1 -1
- package/dist/lib/api/types.d.ts +25 -0
- package/dist/lib/api/types.d.ts.map +1 -1
- package/dist/lib/api/upload-timeout.d.ts +17 -0
- package/dist/lib/api/upload-timeout.d.ts.map +1 -0
- package/dist/lib/api/upload-timeout.js +36 -0
- package/dist/lib/api/upload-timeout.js.map +1 -0
- package/dist/lib/api/upload.d.ts +42 -0
- package/dist/lib/api/upload.d.ts.map +1 -0
- package/dist/lib/api/upload.js +145 -0
- package/dist/lib/api/upload.js.map +1 -0
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/config.js +14 -0
- package/dist/lib/config.js.map +1 -1
- package/dist/lib/db/interfaces/asset.d.ts +114 -5
- package/dist/lib/db/interfaces/asset.d.ts.map +1 -1
- package/dist/lib/db/interfaces/document.d.ts +98 -3
- package/dist/lib/db/interfaces/document.d.ts.map +1 -1
- package/dist/lib/hooks.d.ts.map +1 -1
- package/dist/lib/hooks.js +2 -1
- package/dist/lib/hooks.js.map +1 -1
- package/dist/lib/image/index.d.ts +3 -0
- package/dist/lib/image/index.d.ts.map +1 -0
- package/dist/lib/image/index.js +12 -0
- package/dist/lib/image/index.js.map +1 -0
- package/dist/lib/image/types.d.ts +28 -0
- package/dist/lib/image/types.d.ts.map +1 -0
- package/dist/lib/image/types.js +2 -0
- package/dist/lib/image/types.js.map +1 -0
- package/dist/lib/images/generate.d.ts +55 -0
- package/dist/lib/images/generate.d.ts.map +1 -0
- package/dist/lib/images/generate.js +244 -0
- package/dist/lib/images/generate.js.map +1 -0
- package/dist/lib/images/index.d.ts +2 -0
- package/dist/lib/images/index.d.ts.map +1 -0
- package/dist/lib/images/index.js +8 -0
- package/dist/lib/images/index.js.map +1 -0
- package/dist/lib/images/variants.d.ts +82 -0
- package/dist/lib/images/variants.d.ts.map +1 -0
- package/dist/lib/images/variants.js +125 -0
- package/dist/lib/images/variants.js.map +1 -0
- package/dist/lib/jobs/asset-reference-jobs.d.ts +49 -0
- package/dist/lib/jobs/asset-reference-jobs.d.ts.map +1 -0
- package/dist/lib/jobs/asset-reference-jobs.js +75 -0
- package/dist/lib/jobs/asset-reference-jobs.js.map +1 -0
- package/dist/lib/jobs/run-batch.d.ts.map +1 -1
- package/dist/lib/jobs/run-batch.js +5 -0
- package/dist/lib/jobs/run-batch.js.map +1 -1
- package/dist/lib/local-api/collection-api.d.ts +19 -2
- package/dist/lib/local-api/collection-api.d.ts.map +1 -1
- package/dist/lib/local-api/collection-api.js +65 -17
- package/dist/lib/local-api/collection-api.js.map +1 -1
- package/dist/lib/preview/assets.d.ts +19 -0
- package/dist/lib/preview/assets.d.ts.map +1 -1
- package/dist/lib/preview/assets.js +6 -0
- package/dist/lib/preview/assets.js.map +1 -1
- package/dist/lib/routes/assets-cdn.d.ts +19 -0
- package/dist/lib/routes/assets-cdn.d.ts.map +1 -1
- package/dist/lib/routes/assets-cdn.js +295 -17
- package/dist/lib/routes/assets-cdn.js.map +1 -1
- package/dist/lib/server/api/index.d.ts.map +1 -1
- package/dist/lib/server/api/index.js +87 -8
- package/dist/lib/server/api/index.js.map +1 -1
- package/dist/lib/server/api/routes/assets-bulk.d.ts.map +1 -1
- package/dist/lib/server/api/routes/assets-bulk.js +36 -7
- package/dist/lib/server/api/routes/assets-bulk.js.map +1 -1
- package/dist/lib/server/api/routes/assets-by-id.d.ts.map +1 -1
- package/dist/lib/server/api/routes/assets-by-id.js +32 -15
- package/dist/lib/server/api/routes/assets-by-id.js.map +1 -1
- package/dist/lib/server/api/routes/assets-direct-upload.d.ts +4 -0
- package/dist/lib/server/api/routes/assets-direct-upload.d.ts.map +1 -0
- package/dist/lib/server/api/routes/assets-direct-upload.js +164 -0
- package/dist/lib/server/api/routes/assets-direct-upload.js.map +1 -0
- package/dist/lib/server/api/routes/assets-poster.d.ts +4 -0
- package/dist/lib/server/api/routes/assets-poster.d.ts.map +1 -0
- package/dist/lib/server/api/routes/assets-poster.js +120 -0
- package/dist/lib/server/api/routes/assets-poster.js.map +1 -0
- package/dist/lib/server/api/routes/assets-references.d.ts.map +1 -1
- package/dist/lib/server/api/routes/assets-references.js +64 -5
- package/dist/lib/server/api/routes/assets-references.js.map +1 -1
- package/dist/lib/server/api/routes/assets.d.ts.map +1 -1
- package/dist/lib/server/api/routes/assets.js +116 -12
- package/dist/lib/server/api/routes/assets.js.map +1 -1
- package/dist/lib/server/api/routes/clear-asset-references.d.ts +18 -0
- package/dist/lib/server/api/routes/clear-asset-references.d.ts.map +1 -0
- package/dist/lib/server/api/routes/clear-asset-references.js +32 -0
- package/dist/lib/server/api/routes/clear-asset-references.js.map +1 -0
- package/dist/lib/server/api/routes/documents.d.ts.map +1 -1
- package/dist/lib/server/api/routes/documents.js +27 -1
- package/dist/lib/server/api/routes/documents.js.map +1 -1
- package/dist/lib/server/index.d.ts +2 -0
- package/dist/lib/server/index.d.ts.map +1 -1
- package/dist/lib/server/index.js +4 -0
- package/dist/lib/server/index.js.map +1 -1
- package/dist/lib/services/asset-references-service.d.ts +93 -0
- package/dist/lib/services/asset-references-service.d.ts.map +1 -0
- package/dist/lib/services/asset-references-service.js +198 -0
- package/dist/lib/services/asset-references-service.js.map +1 -0
- package/dist/lib/services/asset-service.d.ts +115 -14
- package/dist/lib/services/asset-service.d.ts.map +1 -1
- package/dist/lib/services/asset-service.js +312 -31
- package/dist/lib/services/asset-service.js.map +1 -1
- package/dist/lib/services/references-service.d.ts +19 -15
- package/dist/lib/services/references-service.d.ts.map +1 -1
- package/dist/lib/services/references-service.js +59 -31
- package/dist/lib/services/references-service.js.map +1 -1
- package/dist/lib/services/version-service.d.ts +10 -1
- package/dist/lib/services/version-service.d.ts.map +1 -1
- package/dist/lib/services/version-service.js +26 -4
- package/dist/lib/services/version-service.js.map +1 -1
- package/dist/lib/storage/adapters/local-storage-adapter.d.ts +38 -0
- package/dist/lib/storage/adapters/local-storage-adapter.d.ts.map +1 -1
- package/dist/lib/storage/adapters/local-storage-adapter.js +86 -19
- package/dist/lib/storage/adapters/local-storage-adapter.js.map +1 -1
- package/dist/lib/storage/index.d.ts +1 -0
- package/dist/lib/storage/index.d.ts.map +1 -1
- package/dist/lib/storage/index.js +2 -0
- package/dist/lib/storage/index.js.map +1 -1
- package/dist/lib/storage/interfaces/storage.d.ts +135 -5
- package/dist/lib/storage/interfaces/storage.d.ts.map +1 -1
- package/dist/lib/storage/keys.d.ts +96 -0
- package/dist/lib/storage/keys.d.ts.map +1 -0
- package/dist/lib/storage/keys.js +160 -0
- package/dist/lib/storage/keys.js.map +1 -0
- package/dist/lib/types/asset.d.ts +92 -12
- package/dist/lib/types/asset.d.ts.map +1 -1
- package/dist/lib/types/capabilities.d.ts +11 -0
- package/dist/lib/types/capabilities.d.ts.map +1 -1
- package/dist/lib/types/capabilities.js +20 -6
- package/dist/lib/types/capabilities.js.map +1 -1
- package/dist/lib/types/config.d.ts +127 -0
- package/dist/lib/types/config.d.ts.map +1 -1
- package/dist/lib/utils/asset-reference-walk.d.ts +44 -0
- package/dist/lib/utils/asset-reference-walk.d.ts.map +1 -0
- package/dist/lib/utils/asset-reference-walk.js +144 -0
- package/dist/lib/utils/asset-reference-walk.js.map +1 -0
- package/dist/lib/utils/image-url.d.ts +61 -26
- package/dist/lib/utils/image-url.d.ts.map +1 -1
- package/dist/lib/utils/image-url.js +143 -26
- package/dist/lib/utils/image-url.js.map +1 -1
- package/dist/lib/utils/video-metadata.d.ts +39 -0
- package/dist/lib/utils/video-metadata.d.ts.map +1 -0
- package/dist/lib/utils/video-metadata.js +161 -0
- package/dist/lib/utils/video-metadata.js.map +1 -0
- package/dist/local-api/collection-api.d.ts +19 -2
- package/dist/local-api/collection-api.d.ts.map +1 -1
- package/dist/local-api/collection-api.js +65 -17
- package/dist/preview/assets.d.ts +19 -0
- package/dist/preview/assets.d.ts.map +1 -1
- package/dist/preview/assets.js +6 -0
- package/dist/routes/assets-cdn.d.ts +19 -0
- package/dist/routes/assets-cdn.d.ts.map +1 -1
- package/dist/routes/assets-cdn.js +295 -17
- package/dist/server/api/index.d.ts.map +1 -1
- package/dist/server/api/index.js +87 -8
- package/dist/server/api/routes/assets-bulk.d.ts.map +1 -1
- package/dist/server/api/routes/assets-bulk.js +36 -7
- package/dist/server/api/routes/assets-by-id.d.ts.map +1 -1
- package/dist/server/api/routes/assets-by-id.js +32 -15
- package/dist/server/api/routes/assets-direct-upload.d.ts +4 -0
- package/dist/server/api/routes/assets-direct-upload.d.ts.map +1 -0
- package/dist/server/api/routes/assets-direct-upload.js +163 -0
- package/dist/server/api/routes/assets-poster.d.ts +4 -0
- package/dist/server/api/routes/assets-poster.d.ts.map +1 -0
- package/dist/server/api/routes/assets-poster.js +119 -0
- package/dist/server/api/routes/assets-references.d.ts.map +1 -1
- package/dist/server/api/routes/assets-references.js +64 -5
- package/dist/server/api/routes/assets.d.ts.map +1 -1
- package/dist/server/api/routes/assets.js +116 -12
- package/dist/server/api/routes/clear-asset-references.d.ts +18 -0
- package/dist/server/api/routes/clear-asset-references.d.ts.map +1 -0
- package/dist/server/api/routes/clear-asset-references.js +31 -0
- package/dist/server/api/routes/documents.d.ts.map +1 -1
- package/dist/server/api/routes/documents.js +27 -1
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +4 -0
- package/dist/services/asset-references-service.d.ts +93 -0
- package/dist/services/asset-references-service.d.ts.map +1 -0
- package/dist/services/asset-references-service.js +197 -0
- package/dist/services/asset-service.d.ts +115 -14
- package/dist/services/asset-service.d.ts.map +1 -1
- package/dist/services/asset-service.js +312 -31
- package/dist/services/references-service.d.ts +19 -15
- package/dist/services/references-service.d.ts.map +1 -1
- package/dist/services/references-service.js +59 -31
- package/dist/services/version-service.d.ts +10 -1
- package/dist/services/version-service.d.ts.map +1 -1
- package/dist/services/version-service.js +26 -4
- package/dist/storage/adapters/local-storage-adapter.d.ts +38 -0
- package/dist/storage/adapters/local-storage-adapter.d.ts.map +1 -1
- package/dist/storage/adapters/local-storage-adapter.js +86 -19
- package/dist/storage/index.d.ts +1 -0
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/index.js +2 -0
- package/dist/storage/interfaces/storage.d.ts +135 -5
- package/dist/storage/interfaces/storage.d.ts.map +1 -1
- package/dist/storage/keys.d.ts +96 -0
- package/dist/storage/keys.d.ts.map +1 -0
- package/dist/storage/keys.js +159 -0
- package/dist/types/asset.d.ts +92 -12
- package/dist/types/asset.d.ts.map +1 -1
- package/dist/types/capabilities.d.ts +11 -0
- package/dist/types/capabilities.d.ts.map +1 -1
- package/dist/types/capabilities.js +20 -6
- package/dist/types/config.d.ts +127 -0
- package/dist/types/config.d.ts.map +1 -1
- package/dist/utils/asset-reference-walk.d.ts +44 -0
- package/dist/utils/asset-reference-walk.d.ts.map +1 -0
- package/dist/utils/asset-reference-walk.js +143 -0
- package/dist/utils/image-url.d.ts +61 -26
- package/dist/utils/image-url.d.ts.map +1 -1
- package/dist/utils/image-url.js +143 -26
- package/dist/utils/video-metadata.d.ts +39 -0
- package/dist/utils/video-metadata.d.ts.map +1 -0
- package/dist/utils/video-metadata.js +160 -0
- package/package.json +6 -1
|
@@ -7,6 +7,7 @@ import type { EmailAdapter } from '../email/index.js';
|
|
|
7
7
|
import type { AIProviderAdapter } from '../ai/index.js';
|
|
8
8
|
import type { GraphQLConfig } from '../graphql/index.js';
|
|
9
9
|
import type { AphexEnv } from '../server/api/index.js';
|
|
10
|
+
import type { Asset } from './asset.js';
|
|
10
11
|
import type { SchemaType } from './schemas.js';
|
|
11
12
|
import type { Logger } from '../utils/logger.js';
|
|
12
13
|
import type { CMSPlugin } from '../plugins/types.js';
|
|
@@ -25,6 +26,132 @@ export interface CMSConfig {
|
|
|
25
26
|
*/
|
|
26
27
|
plugins?: CMSPlugin[];
|
|
27
28
|
storage?: StorageAdapter | null;
|
|
29
|
+
/**
|
|
30
|
+
* Include object storage in the `/aphex-health` response. Off by default.
|
|
31
|
+
*
|
|
32
|
+
* Opt-in because it costs money on metered storage: `isHealthy()` is a real
|
|
33
|
+
* network round-trip to the bucket, `/aphex-health` is unauthenticated, and
|
|
34
|
+
* the probe happens per process. The result is cached for 30s, which caps a
|
|
35
|
+
* single process at ~88k requests/month — inside R2's free tier and around
|
|
36
|
+
* $0.03/month past it — but that multiplies by instance count, so it is your
|
|
37
|
+
* decision to make rather than a default you inherit.
|
|
38
|
+
*
|
|
39
|
+
* Enabling it never changes the HTTP status code: unhealthy storage reports
|
|
40
|
+
* `status: 'degraded'` with a 200, so a bucket outage cannot pull healthy
|
|
41
|
+
* nodes out of a load balancer.
|
|
42
|
+
*/
|
|
43
|
+
storageHealthCheck?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Serve selected assets as a short-lived signed-URL redirect instead of
|
|
46
|
+
* proxying their bytes.
|
|
47
|
+
*
|
|
48
|
+
* `/media/:id/:filename` proxies by default, so its access checks actually
|
|
49
|
+
* decide whether the caller gets the file. That costs a round-trip through
|
|
50
|
+
* the app for every byte, which is the wrong trade for large files — a 200MB
|
|
51
|
+
* video download shouldn't occupy a server process. Return `true` for those
|
|
52
|
+
* and the route redirects to a signed URL from the storage adapter instead.
|
|
53
|
+
*
|
|
54
|
+
* The access checks run *before* the predicate either way: a signed URL is
|
|
55
|
+
* only ever minted for a request that was already allowed to read the file.
|
|
56
|
+
*
|
|
57
|
+
* Requires `getSignedUrl` on the storage adapter; without it the route
|
|
58
|
+
* proxies anyway rather than failing, since serving the file correctly beats
|
|
59
|
+
* refusing to serve it at all.
|
|
60
|
+
*
|
|
61
|
+
* Deliberately one predicate and one duration rather than a matrix of
|
|
62
|
+
* per-collection toggles — the whole surface is "which files skip the proxy,
|
|
63
|
+
* and for how long".
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* signedDownloads: {
|
|
67
|
+
* shouldUseSignedURL: (asset) => asset.size > 25 * 1024 * 1024
|
|
68
|
+
* }
|
|
69
|
+
*/
|
|
70
|
+
signedDownloads?: {
|
|
71
|
+
shouldUseSignedURL: (asset: Asset) => boolean | Promise<boolean>;
|
|
72
|
+
/** Signed-URL lifetime in seconds. Default 900 (15 minutes). */
|
|
73
|
+
expiresIn?: number;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Responsive image derivatives.
|
|
77
|
+
*
|
|
78
|
+
* One width ladder and a quality, and that is deliberately the entire
|
|
79
|
+
* surface. Derivatives are generated **on first request**, not at upload:
|
|
80
|
+
* a width that nobody asks for is never produced, changing the ladder needs
|
|
81
|
+
* no migration or regeneration script, and assets uploaded before the
|
|
82
|
+
* pipeline existed are backfilled simply by being viewed.
|
|
83
|
+
*
|
|
84
|
+
* Enabled by default. Sharp is already a hard dependency, originals are kept
|
|
85
|
+
* byte-for-byte, and the admin's own thumbnails are the smallest rung — so an
|
|
86
|
+
* opt-in default would mean the admin grid keeps serving full-size originals
|
|
87
|
+
* to everyone who never found the flag.
|
|
88
|
+
*
|
|
89
|
+
* Set to `null` to disable: `/media` then always serves the original.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* images: { widths: [320, 640, 960, 1280, 1920], quality: 80 }
|
|
93
|
+
*/
|
|
94
|
+
images?: {
|
|
95
|
+
/**
|
|
96
|
+
* The widths that may be generated, in pixels. A closed set on purpose —
|
|
97
|
+
* it is the allowlist that stops a request for arbitrary dimensions
|
|
98
|
+
* turning into unbounded CPU and storage. A request for a width outside
|
|
99
|
+
* it serves the original rather than generating anything.
|
|
100
|
+
*/
|
|
101
|
+
widths: number[];
|
|
102
|
+
/** WebP quality, 1–100. Default 80. */
|
|
103
|
+
quality?: number;
|
|
104
|
+
} | null;
|
|
105
|
+
/**
|
|
106
|
+
* Upload constraints.
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* upload: { maxFileSize: 100 * 1024 * 1024 } // 100MB
|
|
110
|
+
*/
|
|
111
|
+
upload?: {
|
|
112
|
+
/**
|
|
113
|
+
* Largest accepted request body, in bytes. Defaults to
|
|
114
|
+
* {@link MAX_UPLOAD_BYTES} (10MB).
|
|
115
|
+
*
|
|
116
|
+
* This is one number rather than several because it's the *only* ceiling
|
|
117
|
+
* that matters: it's enforced by the `bodyLimit` middleware on `/api/*`,
|
|
118
|
+
* which rejects with 413 before the body is buffered, so nothing larger
|
|
119
|
+
* ever reaches a route or a storage adapter. The admin UI reads the
|
|
120
|
+
* effective value back from the assets endpoint and refuses oversized
|
|
121
|
+
* files before sending them.
|
|
122
|
+
*
|
|
123
|
+
* This is the *only* place to set it. `createCMSConfig` pushes the resolved
|
|
124
|
+
* value into the storage adapter, overriding whatever `maxFileSize` the
|
|
125
|
+
* adapter was constructed with — so the request check, the direct-upload
|
|
126
|
+
* grant, the limit the admin reads back, and the adapter's own backstop are
|
|
127
|
+
* all the same number and cannot disagree.
|
|
128
|
+
*
|
|
129
|
+
* The one thing it can't raise is a serverless host's own request cap.
|
|
130
|
+
* Vercel Functions reject a body over 4.5MB before the app is invoked, and
|
|
131
|
+
* unlike responses there's no streaming escape — large uploads there need
|
|
132
|
+
* direct-to-storage ({@link direct}).
|
|
133
|
+
*/
|
|
134
|
+
maxFileSize?: number;
|
|
135
|
+
/**
|
|
136
|
+
* Let the browser upload straight to object storage, bypassing this app.
|
|
137
|
+
*
|
|
138
|
+
* Off by default, and deliberately not inferred from "the adapter can
|
|
139
|
+
* sign": it additionally requires **CORS `PUT` on the bucket from your
|
|
140
|
+
* site's origin**, which nothing here can detect. Turning it on without
|
|
141
|
+
* that configured makes every upload fail in the browser, so it has to be
|
|
142
|
+
* a decision someone takes rather than a default they discover.
|
|
143
|
+
*
|
|
144
|
+
* Worth turning on when deploying somewhere that caps request bodies —
|
|
145
|
+
* Vercel Functions reject anything over 4.5MB before the app is invoked,
|
|
146
|
+
* and unlike responses there is no streaming escape, so this is the only
|
|
147
|
+
* way a larger file can be uploaded at all.
|
|
148
|
+
*
|
|
149
|
+
* Ignored when the storage adapter can't sign uploads or no
|
|
150
|
+
* `security.secretEncryptionKey` is set; the admin falls back to
|
|
151
|
+
* uploading through the app, which works everywhere.
|
|
152
|
+
*/
|
|
153
|
+
direct?: boolean;
|
|
154
|
+
};
|
|
28
155
|
email?: EmailAdapter | null;
|
|
29
156
|
/** Model backend for the in-admin agent. Omit to leave the agent panel disabled. */
|
|
30
157
|
aiProvider?: AIProviderAdapter | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/lib/types/config.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AACjC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnD,YAAY,EAAE,aAAa,EAAE,CAAC;AAE9B,MAAM,WAAW,SAAS;IACzB,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,QAAQ,EAAE,eAAe,CAAC;IAC1B;;;;;OAKG;IACH,OAAO,CAAC,EAAE,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AAC;IACF;;;;;OAKG;IACH,IAAI,CAAC,EAAE;QACN;;;WAGG;QACH,QAAQ,CAAC,EAAE,aAAa,CAAC;QACzB;;;;;;WAMG;QACH,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,mDAAmD;QACnD,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,kFAAkF;QAClF,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB;;;;WAIG;QACH,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB;;;;;;;WAOG;QACH,QAAQ,CAAC,EAAE,OAAO,CAAC;QACnB,qFAAqF;QACrF,kBAAkB,CAAC,EAAE,MAAM,CAAC;KAC5B,CAAC;IACF;;;;;;;;;;OAUG;IACH,OAAO,CAAC,EAAE;QACT,KAAK,CAAC,EAAE,OAAO,CAAC;QAChB,kBAAkB,CAAC,EAAE,CAAC,IAAI,EAAE;YAAE,IAAI,CAAC,EAAE,IAAI,CAAC;YAAC,GAAG,EAAE,GAAG,CAAA;SAAE,KAAK,kBAAkB,CAAC;KAC7E,CAAC;IACF,QAAQ,CAAC,EAAE;QACV;;;;WAIG;QACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;QAC5B;;;;;;WAMG;QACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;KAC7B,CAAC;IACF;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,IAAI,CAAC,QAAQ,CAAC,KAAK,IAAI,CAAC;CACpC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/** One asset reference found in a document's data. */
|
|
2
|
+
export interface FoundAssetReference {
|
|
3
|
+
/** The referenced asset's id. */
|
|
4
|
+
assetId: string;
|
|
5
|
+
/**
|
|
6
|
+
* Dotted/bracketed path to the field holding the reference, e.g.
|
|
7
|
+
* `coverImage`, `seo.ogImage`, `content[3]`, `gallery.images[2]`.
|
|
8
|
+
*
|
|
9
|
+
* Array indices are positions at the time of the write. They are a label for
|
|
10
|
+
* a human, not a stable address: reordering an array changes them, and the
|
|
11
|
+
* index is rebuilt on every write anyway, so nothing depends on them lasting.
|
|
12
|
+
*/
|
|
13
|
+
fieldPath: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Collect every asset reference in a document's data.
|
|
17
|
+
*
|
|
18
|
+
* Deduplicated by `assetId` + `fieldPath`, so the same asset used twice in
|
|
19
|
+
* different fields yields two rows, while the same asset at the same path (which
|
|
20
|
+
* shouldn't happen, but costs nothing to guard) yields one.
|
|
21
|
+
*/
|
|
22
|
+
export declare function collectAssetReferences(data: unknown): FoundAssetReference[];
|
|
23
|
+
/**
|
|
24
|
+
* Every asset id reachable anywhere in the data, ignoring structure entirely.
|
|
25
|
+
*
|
|
26
|
+
* The unstructured twin of {@link collectAssetReferences}, and deliberately dumb:
|
|
27
|
+
* it descends through everything and collects any `asset: { _ref }` it meets, at
|
|
28
|
+
* any depth, under any wrapper, with no notion of which shapes are legitimate.
|
|
29
|
+
* It therefore cannot tell you *where* a reference lives, which is why it is not
|
|
30
|
+
* the indexer.
|
|
31
|
+
*
|
|
32
|
+
* It exists to check the indexer. The walker is a structural allowlist — it finds
|
|
33
|
+
* references in the shapes it knows — while the delete guard is a substring scan
|
|
34
|
+
* that finds them in shapes nobody anticipated. That asymmetry is permanent, and
|
|
35
|
+
* every gap it has produced looked identical from the outside: an asset that
|
|
36
|
+
* reads as unused and then refuses to delete. Comparing these two sets turns the
|
|
37
|
+
* next such gap into a log line at rebuild time instead of a support question
|
|
38
|
+
* months later.
|
|
39
|
+
*
|
|
40
|
+
* Not a substitute for the guard's scan: that one matches raw text, so it also
|
|
41
|
+
* catches an id sitting somewhere this doesn't model at all.
|
|
42
|
+
*/
|
|
43
|
+
export declare function collectAssetIdsUnstructured(data: unknown): Set<string>;
|
|
44
|
+
//# sourceMappingURL=asset-reference-walk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asset-reference-walk.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/asset-reference-walk.ts"],"names":[],"mappings":"AAYA,sDAAsD;AACtD,MAAM,WAAW,mBAAmB;IACnC,iCAAiC;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB;;;;;;;OAOG;IACH,SAAS,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,OAAO,GAAG,mBAAmB,EAAE,CAI3E;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,OAAO,GAAG,GAAG,CAAC,MAAM,CAAC,CAyBtE"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// Walks a document's data and collects every *asset* reference, with the field
|
|
2
|
+
// path it was found at.
|
|
3
|
+
//
|
|
4
|
+
// The sibling of `reference-walk.ts`, which collects document references and
|
|
5
|
+
// deliberately steps over image/file nodes because those point at the assets
|
|
6
|
+
// table rather than at documents. This one is the other half: it collects only
|
|
7
|
+
// those, because they are what the asset-reference index is built from.
|
|
8
|
+
//
|
|
9
|
+
// The path matters as much as the id. "This asset is used by 3 documents" is a
|
|
10
|
+
// number; "Homepage · Hero image" is something an editor can act on — and it is
|
|
11
|
+
// also what makes an orphaned reference diagnosable rather than mysterious.
|
|
12
|
+
/**
|
|
13
|
+
* Collect every asset reference in a document's data.
|
|
14
|
+
*
|
|
15
|
+
* Deduplicated by `assetId` + `fieldPath`, so the same asset used twice in
|
|
16
|
+
* different fields yields two rows, while the same asset at the same path (which
|
|
17
|
+
* shouldn't happen, but costs nothing to guard) yields one.
|
|
18
|
+
*/
|
|
19
|
+
export function collectAssetReferences(data) {
|
|
20
|
+
const found = new Map();
|
|
21
|
+
walk(data, '', found);
|
|
22
|
+
return Array.from(found.values());
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Every asset id reachable anywhere in the data, ignoring structure entirely.
|
|
26
|
+
*
|
|
27
|
+
* The unstructured twin of {@link collectAssetReferences}, and deliberately dumb:
|
|
28
|
+
* it descends through everything and collects any `asset: { _ref }` it meets, at
|
|
29
|
+
* any depth, under any wrapper, with no notion of which shapes are legitimate.
|
|
30
|
+
* It therefore cannot tell you *where* a reference lives, which is why it is not
|
|
31
|
+
* the indexer.
|
|
32
|
+
*
|
|
33
|
+
* It exists to check the indexer. The walker is a structural allowlist — it finds
|
|
34
|
+
* references in the shapes it knows — while the delete guard is a substring scan
|
|
35
|
+
* that finds them in shapes nobody anticipated. That asymmetry is permanent, and
|
|
36
|
+
* every gap it has produced looked identical from the outside: an asset that
|
|
37
|
+
* reads as unused and then refuses to delete. Comparing these two sets turns the
|
|
38
|
+
* next such gap into a log line at rebuild time instead of a support question
|
|
39
|
+
* months later.
|
|
40
|
+
*
|
|
41
|
+
* Not a substitute for the guard's scan: that one matches raw text, so it also
|
|
42
|
+
* catches an id sitting somewhere this doesn't model at all.
|
|
43
|
+
*/
|
|
44
|
+
export function collectAssetIdsUnstructured(data) {
|
|
45
|
+
const ids = new Set();
|
|
46
|
+
const seen = new Set();
|
|
47
|
+
const visit = (value) => {
|
|
48
|
+
if (value == null || typeof value !== 'object')
|
|
49
|
+
return;
|
|
50
|
+
// Documents are JSON, so cycles shouldn't occur — but this runs over every
|
|
51
|
+
// document in an organization during a rebuild, and an accidental cycle
|
|
52
|
+
// must not turn a repair pass into a hang.
|
|
53
|
+
if (seen.has(value))
|
|
54
|
+
return;
|
|
55
|
+
seen.add(value);
|
|
56
|
+
if (Array.isArray(value)) {
|
|
57
|
+
for (const item of value)
|
|
58
|
+
visit(item);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const id = assetRefIn(value);
|
|
62
|
+
if (id)
|
|
63
|
+
ids.add(id);
|
|
64
|
+
for (const nested of Object.values(value))
|
|
65
|
+
visit(nested);
|
|
66
|
+
};
|
|
67
|
+
visit(data);
|
|
68
|
+
return ids;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The asset id held by `node.asset`, when that is a reference.
|
|
72
|
+
*
|
|
73
|
+
* `asset` is the key that makes a reference an *asset* reference — a `_ref`
|
|
74
|
+
* under any other key points at the documents table and belongs to
|
|
75
|
+
* `reference-walk.ts`.
|
|
76
|
+
*/
|
|
77
|
+
function assetRefIn(node) {
|
|
78
|
+
if (node == null || typeof node !== 'object')
|
|
79
|
+
return null;
|
|
80
|
+
const ref = node.asset;
|
|
81
|
+
if (ref?._type === 'reference' && typeof ref._ref === 'string' && ref._ref)
|
|
82
|
+
return ref._ref;
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* @param skipOwnAsset - Don't record this node's own `asset`; the caller already
|
|
87
|
+
* recorded it at a better path. Set when descending into a wrapper's `data`,
|
|
88
|
+
* which would otherwise report the same reference twice — once as
|
|
89
|
+
* `content[3]` and once as `content[3].data`.
|
|
90
|
+
*/
|
|
91
|
+
function walk(value, path, found, skipOwnAsset = false) {
|
|
92
|
+
if (value == null || typeof value !== 'object')
|
|
93
|
+
return;
|
|
94
|
+
if (Array.isArray(value)) {
|
|
95
|
+
for (const [index, item] of value.entries()) {
|
|
96
|
+
walk(item, `${path}[${index}]`, found);
|
|
97
|
+
}
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
const obj = value;
|
|
101
|
+
// Where the reference actually sits, in the two shapes that exist:
|
|
102
|
+
//
|
|
103
|
+
// a plain image field { _type: 'image', asset: { _ref } }
|
|
104
|
+
// a rich-text block { _type: 'image', _key, data: { asset: { _ref } } }
|
|
105
|
+
//
|
|
106
|
+
// The second was missed entirely. Checking only `obj.asset` found nothing on
|
|
107
|
+
// the block, and the recursion that would have reached `data.asset` ran into
|
|
108
|
+
// the `_type === 'reference'` guard below and turned back — so every image
|
|
109
|
+
// placed in block content was invisible to the index, while the delete guard's
|
|
110
|
+
// `LIKE '%assetId%'` found it regardless of shape.
|
|
111
|
+
//
|
|
112
|
+
// That asymmetry is the whole failure mode of this file: a structure-blind
|
|
113
|
+
// scan finds what a structure-aware walk does not model, so any gap here reads
|
|
114
|
+
// as "unused" in the browser and "still referenced" at the point of deletion.
|
|
115
|
+
// New wrappers belong here rather than worked around downstream.
|
|
116
|
+
//
|
|
117
|
+
// Recorded at the containing node's path rather than the inner `asset` key —
|
|
118
|
+
// `coverImage` and `content[3]` are what an editor recognises,
|
|
119
|
+
// `coverImage.asset` and `content[3].data.asset` are not.
|
|
120
|
+
const ownAsset = skipOwnAsset ? null : assetRefIn(obj);
|
|
121
|
+
const wrappedAsset = ownAsset ? null : assetRefIn(obj.data);
|
|
122
|
+
const assetId = ownAsset ?? wrappedAsset;
|
|
123
|
+
if (assetId) {
|
|
124
|
+
const fieldPath = path || (typeof obj._type === 'string' ? obj._type : 'asset');
|
|
125
|
+
found.set(`${assetId} ${fieldPath}`, { assetId, fieldPath });
|
|
126
|
+
}
|
|
127
|
+
// Keep descending regardless: an image object can carry nested fields of its
|
|
128
|
+
// own, and a custom block may embed further media below it.
|
|
129
|
+
// A document reference points at the documents table, not at assets — that is
|
|
130
|
+
// `reference-walk.ts`'s job. Stopping here also prevents a `_ref` that happens
|
|
131
|
+
// to be a document id from being recorded as an asset. Anything reached
|
|
132
|
+
// *through* an `asset` key has already been collected above.
|
|
133
|
+
if (obj._type === 'reference')
|
|
134
|
+
return;
|
|
135
|
+
for (const key of Object.keys(obj)) {
|
|
136
|
+
// Underscore keys are structural (_type, _key, _ref), never content.
|
|
137
|
+
if (key.startsWith('_'))
|
|
138
|
+
continue;
|
|
139
|
+
// A `data` whose asset was just credited to this node still gets walked —
|
|
140
|
+
// it can hold further media — but must not re-report the one already taken.
|
|
141
|
+
walk(obj[key], path ? `${path}.${key}` : key, found, key === 'data' && !!wrappedAsset);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=asset-reference-walk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asset-reference-walk.js","sourceRoot":"","sources":["../../../src/lib/utils/asset-reference-wal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ined): this;
|
|
25
25
|
/**
|
|
26
|
-
*
|
|
26
|
+
* Request a rendered width in pixels.
|
|
27
|
+
*
|
|
28
|
+
* Snaps to the narrowest generated variant that covers it — the ladder is a
|
|
29
|
+
* closed allowlist, so `width(333)` returns the 640px rung rather than a
|
|
30
|
+
* 333px image. Asking for a width no variant covers returns the widest one.
|
|
27
31
|
*/
|
|
28
32
|
width(width: number): this;
|
|
29
33
|
/**
|
|
30
|
-
*
|
|
34
|
+
* Request a rendered height in pixels.
|
|
35
|
+
*
|
|
36
|
+
* Honoured only as a *width* request: derivatives are resized by width and
|
|
37
|
+
* keep the original's aspect ratio, so this converts through the asset's
|
|
38
|
+
* intrinsic dimensions and then snaps like {@link width}. Without those
|
|
39
|
+
* dimensions there's nothing to convert through and it's ignored.
|
|
31
40
|
*/
|
|
32
41
|
height(height: number): this;
|
|
33
42
|
/**
|
|
34
|
-
* Set both
|
|
43
|
+
* Set both dimensions. Width wins — see {@link height}; nothing crops.
|
|
35
44
|
*/
|
|
36
45
|
size(width: number, height: number): this;
|
|
37
46
|
/**
|
|
38
|
-
*
|
|
47
|
+
* @deprecated No effect. Quality is a property of the pipeline, not the URL:
|
|
48
|
+
* it's set once via `images.quality` and hashed into every variant filename,
|
|
49
|
+
* which is what lets variants be cached immutably. A per-URL override would
|
|
50
|
+
* mean generating and storing a second copy of every image per quality value
|
|
51
|
+
* any caller ever passed.
|
|
39
52
|
*/
|
|
40
53
|
quality(quality: number): this;
|
|
41
54
|
/**
|
|
42
|
-
*
|
|
55
|
+
* @deprecated No effect. Every derivative is WebP; the original is served in
|
|
56
|
+
* whatever format it was uploaded as. Transcoding on request would reopen the
|
|
57
|
+
* unbounded-generation hole the width allowlist exists to close.
|
|
43
58
|
*/
|
|
44
59
|
format(format: 'jpg' | 'jpeg' | 'png' | 'webp' | 'avif'): this;
|
|
45
60
|
/**
|
|
46
|
-
*
|
|
61
|
+
* @deprecated No effect. Derivatives are width-resized and preserve aspect
|
|
62
|
+
* ratio, so there is no second dimension for a fit mode to act on. Per-preset
|
|
63
|
+
* `fit`/`aspectRatio` is post-V1, and lands on top of focal points.
|
|
47
64
|
*/
|
|
48
65
|
fit(fit: 'cover' | 'contain' | 'fill' | 'inside' | 'outside'): this;
|
|
49
66
|
/**
|
|
50
|
-
*
|
|
67
|
+
* @deprecated No effect, and already the behaviour: variants are always WebP.
|
|
51
68
|
*/
|
|
52
69
|
auto(mode: 'format'): this;
|
|
53
70
|
/**
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
71
|
+
* The requested width, converting a height request through the asset's own
|
|
72
|
+
* aspect ratio.
|
|
73
|
+
*
|
|
74
|
+
* Width wins when both are set: a derivative is only ever resized by width,
|
|
75
|
+
* so honouring a height as well would require cropping — which the V1
|
|
76
|
+
* pipeline deliberately doesn't do.
|
|
77
|
+
*/
|
|
78
|
+
private targetWidth;
|
|
79
|
+
/** The ladder variant covering the requested size, if one can be resolved. */
|
|
80
|
+
private snappedUrl;
|
|
81
|
+
/**
|
|
82
|
+
* Build the final URL.
|
|
83
|
+
*
|
|
84
|
+
* With a width (or a height that can be converted to one) and an injected
|
|
85
|
+
* `srcset`, this returns the variant URL for the nearest covering rung.
|
|
86
|
+
* Otherwise it returns the asset's own URL — the full-size original.
|
|
57
87
|
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
88
|
+
* **Prefer `<Image>` for anything rendered.** This returns one fixed URL, so
|
|
89
|
+
* it can't respond to viewport or device pixel ratio; `<Image>` emits the
|
|
90
|
+
* whole `srcset` and lets the browser choose. Reach for this when you need a
|
|
91
|
+
* bare string and the size is genuinely fixed — an OG image, an email, a
|
|
92
|
+
* canvas or PDF source.
|
|
60
93
|
*/
|
|
61
94
|
url(): string | null;
|
|
62
95
|
/**
|
|
@@ -65,24 +98,26 @@ export declare class ImageUrlBuilder {
|
|
|
65
98
|
toString(): string | null;
|
|
66
99
|
}
|
|
67
100
|
/**
|
|
68
|
-
* Factory
|
|
101
|
+
* Factory for a Sanity-style image URL builder.
|
|
69
102
|
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
103
|
+
* ```ts
|
|
104
|
+
* const urlFor = imageUrlBuilder();
|
|
105
|
+
* urlFor(post.coverImage).width(800).url(); // → the 960px rung
|
|
106
|
+
* urlFor(post.coverImage).url(); // → the original
|
|
107
|
+
* ```
|
|
73
108
|
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
109
|
+
* `width` snaps to the nearest generated variant that covers it, read off the
|
|
110
|
+
* `srcset` that `injectAssetUrls` attached — so the source must have been
|
|
111
|
+
* through injection (any value from the Local API, a load function, or GraphQL
|
|
112
|
+
* has been). Without a width, or without a srcset, you get the original.
|
|
78
113
|
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
114
|
+
* Takes no arguments. It previously documented a `baseUrl` and a `signAssetUrl`
|
|
115
|
+
* hook, neither of which the function ever accepted — assets carry their own
|
|
116
|
+
* urls, and `/media/:id/:filename` handles access control centrally rather than
|
|
117
|
+
* through per-caller signing. Signed delivery is `config.signedDownloads`.
|
|
82
118
|
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
* // Will return transformed image once dynamic rendering is implemented
|
|
119
|
+
* `quality`, `format`, `fit` and `auto` remain on the builder for source
|
|
120
|
+
* compatibility but are deprecated no-ops; see each one for why.
|
|
86
121
|
*/
|
|
87
122
|
export declare function imageUrlBuilder(): (source?: ImageValue | ImageAsset | string | Asset | null) => ImageUrlBuilder;
|
|
88
123
|
//# sourceMappingURL=image-url.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image-url.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/image-url.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAGpE,MAAM,WAAW,sBAAsB;IACtC,KAAK,CAAC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