@aphexcms/cms-core 9.9.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/schemas/documents.d.ts +1 -0
- package/dist/api/schemas/documents.d.ts.map +1 -1
- package/dist/api/schemas/documents.js +1 -0
- 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 +213 -32
- 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 +107 -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/schemas/documents.d.ts +1 -0
- package/dist/lib/api/schemas/documents.d.ts.map +1 -1
- package/dist/lib/api/schemas/documents.js +1 -0
- package/dist/lib/api/schemas/documents.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 +107 -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 +25 -2
- package/dist/lib/local-api/collection-api.d.ts.map +1 -1
- package/dist/lib/local-api/collection-api.js +107 -20
- 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/schema-utils/utils.d.ts +31 -1
- package/dist/lib/schema-utils/utils.d.ts.map +1 -1
- package/dist/lib/schema-utils/utils.js +68 -0
- package/dist/lib/schema-utils/utils.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 +28 -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/type-gen.d.ts.map +1 -1
- package/dist/lib/type-gen.js +11 -5
- package/dist/lib/type-gen.js.map +1 -1
- 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/types/filters.d.ts +31 -0
- package/dist/lib/types/filters.d.ts.map +1 -1
- package/dist/lib/types/schemas.d.ts +14 -0
- package/dist/lib/types/schemas.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 +25 -2
- package/dist/local-api/collection-api.d.ts.map +1 -1
- package/dist/local-api/collection-api.js +107 -20
- 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/schema-utils/utils.d.ts +31 -1
- package/dist/schema-utils/utils.d.ts.map +1 -1
- package/dist/schema-utils/utils.js +68 -0
- 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 +28 -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/type-gen.d.ts.map +1 -1
- package/dist/type-gen.js +11 -5
- 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/types/filters.d.ts +31 -0
- package/dist/types/filters.d.ts.map +1 -1
- package/dist/types/schemas.d.ts +14 -0
- package/dist/types/schemas.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
package/dist/lib/api/types.d.ts
CHANGED
|
@@ -13,6 +13,31 @@ export interface ApiResponse<T> {
|
|
|
13
13
|
error?: string;
|
|
14
14
|
message?: string;
|
|
15
15
|
pagination?: PaginationMeta;
|
|
16
|
+
/**
|
|
17
|
+
* Server-side limits the client should respect, reported by endpoints whose
|
|
18
|
+
* clients need to pre-check against them. Present on `GET /assets` so the
|
|
19
|
+
* media browser can refuse an oversized file without hardcoding a size that
|
|
20
|
+
* drifts from whatever the server actually enforces.
|
|
21
|
+
*/
|
|
22
|
+
limits?: {
|
|
23
|
+
maxUploadBytes?: number;
|
|
24
|
+
/** Whether the browser may upload straight to storage. */
|
|
25
|
+
directUpload?: boolean;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* The resolved image pipeline, or null when it's off.
|
|
29
|
+
*
|
|
30
|
+
* Reported so the media browser can address a small derivative instead of
|
|
31
|
+
* the original. `configHash` comes from the server rather than being
|
|
32
|
+
* recomputed here: it is the server that decides which files exist, and a
|
|
33
|
+
* client that derived a different hash would request URLs that quietly fall
|
|
34
|
+
* back to the original — the exact bug this exists to fix, but silent.
|
|
35
|
+
*/
|
|
36
|
+
images?: {
|
|
37
|
+
widths: number[];
|
|
38
|
+
quality: number;
|
|
39
|
+
configHash: string;
|
|
40
|
+
} | null;
|
|
16
41
|
meta?: {
|
|
17
42
|
count: number;
|
|
18
43
|
limit: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/lib/api/types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,g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R upload path and the
|
|
5
|
+
* fetch client — and a second copy of a heuristic is a second thing to get
|
|
6
|
+
* wrong. No imports, so neither pays for it.
|
|
7
|
+
*
|
|
8
|
+
* Derived from the payload rather than configured. A timeout encodes no
|
|
9
|
+
* decision the way a size limit does: its only job is to stop a hung request
|
|
10
|
+
* spinning forever. Exposing it as a setting invites an inconsistent pair —
|
|
11
|
+
* raise `upload.maxFileSize` to 100MB, leave the timeout at the JSON default,
|
|
12
|
+
* and every large upload fails in a way that reads as a server rejection.
|
|
13
|
+
* Deriving it means raising the size limit adjusts the deadline for free.
|
|
14
|
+
*/
|
|
15
|
+
export declare function uploadTimeoutForBytes(bytes: number): number;
|
|
16
|
+
export declare function uploadTimeoutFor(body: FormData): number;
|
|
17
|
+
//# sourceMappingURL=upload-timeout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upload-timeout.d.ts","sourceRoot":"","sources":["../../../src/lib/api/upload-timeout.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAWH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAG3D;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,CAOvD"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How long to wait on a request carrying a file body.
|
|
3
|
+
*
|
|
4
|
+
* Its own module because both transports need it — the XHR upload path and the
|
|
5
|
+
* fetch client — and a second copy of a heuristic is a second thing to get
|
|
6
|
+
* wrong. No imports, so neither pays for it.
|
|
7
|
+
*
|
|
8
|
+
* Derived from the payload rather than configured. A timeout encodes no
|
|
9
|
+
* decision the way a size limit does: its only job is to stop a hung request
|
|
10
|
+
* spinning forever. Exposing it as a setting invites an inconsistent pair —
|
|
11
|
+
* raise `upload.maxFileSize` to 100MB, leave the timeout at the JSON default,
|
|
12
|
+
* and every large upload fails in a way that reads as a server rejection.
|
|
13
|
+
* Deriving it means raising the size limit adjusts the deadline for free.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Assumed floor throughput, deliberately pessimistic — a phone on a bad
|
|
17
|
+
* connection, not an office line. Too generous costs a slow failure on a
|
|
18
|
+
* genuinely dead request; too tight kills uploads that were succeeding.
|
|
19
|
+
*/
|
|
20
|
+
const UPLOAD_ASSUMED_BYTES_PER_SECOND = 64 * 1024; // ~0.5 Mbps
|
|
21
|
+
const UPLOAD_TIMEOUT_FLOOR = 30_000;
|
|
22
|
+
const UPLOAD_TIMEOUT_CEILING = 15 * 60 * 1000;
|
|
23
|
+
export function uploadTimeoutForBytes(bytes) {
|
|
24
|
+
const transfer = (bytes / UPLOAD_ASSUMED_BYTES_PER_SECOND) * 1000;
|
|
25
|
+
return Math.min(UPLOAD_TIMEOUT_CEILING, Math.max(UPLOAD_TIMEOUT_FLOOR, transfer));
|
|
26
|
+
}
|
|
27
|
+
export function uploadTimeoutFor(body) {
|
|
28
|
+
let bytes = 0;
|
|
29
|
+
for (const value of body.values()) {
|
|
30
|
+
// `File` extends `Blob`; checking Blob also covers a raw Blob part.
|
|
31
|
+
if (typeof Blob !== 'undefined' && value instanceof Blob)
|
|
32
|
+
bytes += value.size;
|
|
33
|
+
}
|
|
34
|
+
return uploadTimeoutForBytes(bytes);
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=upload-timeout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upload-timeout.js","sourceRoot":"","sources":["../../../src/lib/api/upload-timeout.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH;;;;GAIG;AACH,MAAM,+BAA+B,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,YAAY;AAC/D,MAAM,oBAAoB,GAAG,MAAM,CAAC;AACpC,MAAM,sBAAsB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAE9C,MAAM,UAAU,qBAAqB,CAAC,KAAa;IAClD,MAAM,QAAQ,GAAG,CAAC,KAAK,GAAG,+BAA+B,CAAC,GAAG,IAAI,CAAC;IAClE,OAAO,IAAI,CAAC,GAAG,CAAC,sBAAsB,EAAE,IAAI,CAAC,GAAG,CAAC,oBAAoB,EAAE,QAAQ,CAAC,CAAC,CAAC;AACnF,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,IAAc;IAC9C,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC;QACnC,oEAAoE;QACpE,IAAI,OAAO,IAAI,KAAK,WAAW,IAAI,KAAK,YAAY,IAAI;YAAE,KAAK,IAAI,KAAK,CAAC,IAAI,CAAC;IAC/E,CAAC;IACD,OAAO,qBAAqB,CAAC,KAAK,CAAC,CAAC;AACrC,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { ApiResponse } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Uploads, on XMLHttpRequest rather than fetch.
|
|
4
|
+
*
|
|
5
|
+
* Not nostalgia: `fetch` has no upload progress event. Request body streams are
|
|
6
|
+
* the standards-track answer and are still neither broadly supported nor usable
|
|
7
|
+
* with a plain `FormData`, so XHR remains the only way to report how far a
|
|
8
|
+
* multi-megabyte upload has actually got. Everything else here exists to make
|
|
9
|
+
* that swap invisible — same `ApiResponse`, same `ApiError`, same defensive
|
|
10
|
+
* parsing — so callers can't tell which transport ran.
|
|
11
|
+
*/
|
|
12
|
+
export interface UploadOptions {
|
|
13
|
+
/** Called with 0–100 as the body is sent. Never called after completion. */
|
|
14
|
+
onProgress?: (percent: number) => void;
|
|
15
|
+
/** Aborts the upload. The promise rejects with an `ApiError` of status 0. */
|
|
16
|
+
signal?: AbortSignal;
|
|
17
|
+
/** Milliseconds of inactivity before giving up. */
|
|
18
|
+
timeoutMs?: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* POST a FormData body with progress reporting.
|
|
22
|
+
*
|
|
23
|
+
* Resolves with the parsed body on success and rejects with `ApiError`
|
|
24
|
+
* otherwise, matching `ApiClient` exactly.
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
27
|
+
* PUT a file straight to object storage, reporting progress.
|
|
28
|
+
*
|
|
29
|
+
* Distinct from {@link uploadFormData} in two ways that matter:
|
|
30
|
+
*
|
|
31
|
+
* - **No credentials.** The target is a third-party origin and the URL already
|
|
32
|
+
* carries its own signature. Sending cookies would leak the session to the
|
|
33
|
+
* storage provider and trip CORS besides.
|
|
34
|
+
* - **Raw body, not FormData.** The signature covers the object bytes; wrapping
|
|
35
|
+
* them in multipart framing would store the framing.
|
|
36
|
+
*
|
|
37
|
+
* A failure here is very often missing bucket CORS rather than a broken file,
|
|
38
|
+
* and the browser deliberately hides the distinction — so the error says so.
|
|
39
|
+
*/
|
|
40
|
+
export declare function putToStorage(url: string, file: File | Blob, headers?: Record<string, string>, options?: UploadOptions): Promise<void>;
|
|
41
|
+
export declare function uploadFormData<T>(url: string, body: FormData, options?: UploadOptions): Promise<ApiResponse<T>>;
|
|
42
|
+
//# sourceMappingURL=upload.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../../../src/lib/api/upload.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C;;;;;;;;;GASG;AAEH,MAAM,WAAW,aAAa;IAC7B,4EAA4E;IAC5E,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,6EAA6E;IAC7E,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,mDAAmD;IACnD,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;;;GAKG;AACH;;;;;;;;;;;;;GAaG;AACH,wBAAgB,YAAY,CAC3B,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,IAAI,GAAG,IAAI,EACjB,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,EACpC,OAAO,GAAE,aAAkB,GACzB,OAAO,CAAC,IAAI,CAAC,CA+Df;AAED,wBAAgB,cAAc,CAAC,CAAC,EAC/B,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,QAAQ,EACd,OAAO,GAAE,aAAkB,GACzB,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAuFzB"}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { ApiError } from './client.js';
|
|
2
|
+
/**
|
|
3
|
+
* POST a FormData body with progress reporting.
|
|
4
|
+
*
|
|
5
|
+
* Resolves with the parsed body on success and rejects with `ApiError`
|
|
6
|
+
* otherwise, matching `ApiClient` exactly.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* PUT a file straight to object storage, reporting progress.
|
|
10
|
+
*
|
|
11
|
+
* Distinct from {@link uploadFormData} in two ways that matter:
|
|
12
|
+
*
|
|
13
|
+
* - **No credentials.** The target is a third-party origin and the URL already
|
|
14
|
+
* carries its own signature. Sending cookies would leak the session to the
|
|
15
|
+
* storage provider and trip CORS besides.
|
|
16
|
+
* - **Raw body, not FormData.** The signature covers the object bytes; wrapping
|
|
17
|
+
* them in multipart framing would store the framing.
|
|
18
|
+
*
|
|
19
|
+
* A failure here is very often missing bucket CORS rather than a broken file,
|
|
20
|
+
* and the browser deliberately hides the distinction — so the error says so.
|
|
21
|
+
*/
|
|
22
|
+
export function putToStorage(url, file, headers = {}, options = {}) {
|
|
23
|
+
const { onProgress, signal, timeoutMs } = options;
|
|
24
|
+
return new Promise((resolve, reject) => {
|
|
25
|
+
if (signal?.aborted) {
|
|
26
|
+
reject(new ApiError(0, null, 'Upload cancelled'));
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const xhr = new XMLHttpRequest();
|
|
30
|
+
xhr.open('PUT', url, true);
|
|
31
|
+
xhr.withCredentials = false;
|
|
32
|
+
for (const [name, value] of Object.entries(headers))
|
|
33
|
+
xhr.setRequestHeader(name, value);
|
|
34
|
+
if (timeoutMs)
|
|
35
|
+
xhr.timeout = timeoutMs;
|
|
36
|
+
if (onProgress) {
|
|
37
|
+
xhr.upload.addEventListener('progress', (event) => {
|
|
38
|
+
if (event.lengthComputable && event.total > 0) {
|
|
39
|
+
onProgress(Math.min(100, Math.round((event.loaded / event.total) * 100)));
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
const onAbort = () => xhr.abort();
|
|
44
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
45
|
+
const cleanup = () => signal?.removeEventListener('abort', onAbort);
|
|
46
|
+
xhr.addEventListener('load', () => {
|
|
47
|
+
cleanup();
|
|
48
|
+
if (xhr.status >= 200 && xhr.status < 300) {
|
|
49
|
+
resolve();
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
reject(new ApiError(xhr.status, null, `Storage rejected the upload (${xhr.status})`));
|
|
53
|
+
});
|
|
54
|
+
xhr.addEventListener('error', () => {
|
|
55
|
+
cleanup();
|
|
56
|
+
// A cross-origin PUT blocked by CORS surfaces here as a bare network
|
|
57
|
+
// error with no detail, by design. Naming the likely cause is the only
|
|
58
|
+
// way an operator finds it, since the browser console message is the
|
|
59
|
+
// only other clue and nobody reads it from a toast.
|
|
60
|
+
reject(new ApiError(0, null, 'Could not reach storage. The bucket may not allow PUT from this origin (CORS).'));
|
|
61
|
+
});
|
|
62
|
+
xhr.addEventListener('timeout', () => {
|
|
63
|
+
cleanup();
|
|
64
|
+
reject(new ApiError(0, null, 'Upload timed out'));
|
|
65
|
+
});
|
|
66
|
+
xhr.addEventListener('abort', () => {
|
|
67
|
+
cleanup();
|
|
68
|
+
reject(new ApiError(0, null, 'Upload cancelled'));
|
|
69
|
+
});
|
|
70
|
+
xhr.send(file);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
export function uploadFormData(url, body, options = {}) {
|
|
74
|
+
const { onProgress, signal, timeoutMs } = options;
|
|
75
|
+
return new Promise((resolve, reject) => {
|
|
76
|
+
if (signal?.aborted) {
|
|
77
|
+
reject(new ApiError(0, null, 'Upload cancelled'));
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const xhr = new XMLHttpRequest();
|
|
81
|
+
xhr.open('POST', url, true);
|
|
82
|
+
// Deliberately not setting Content-Type: the browser must add the
|
|
83
|
+
// multipart boundary, and setting it by hand produces a body the server
|
|
84
|
+
// cannot parse.
|
|
85
|
+
xhr.withCredentials = true;
|
|
86
|
+
if (timeoutMs)
|
|
87
|
+
xhr.timeout = timeoutMs;
|
|
88
|
+
if (onProgress) {
|
|
89
|
+
xhr.upload.addEventListener('progress', (event) => {
|
|
90
|
+
// `lengthComputable` is false when the size isn't known up front;
|
|
91
|
+
// reporting a fabricated percentage would be worse than none.
|
|
92
|
+
if (event.lengthComputable && event.total > 0) {
|
|
93
|
+
onProgress(Math.min(100, Math.round((event.loaded / event.total) * 100)));
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
const onAbort = () => xhr.abort();
|
|
98
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
99
|
+
const cleanup = () => signal?.removeEventListener('abort', onAbort);
|
|
100
|
+
xhr.addEventListener('load', () => {
|
|
101
|
+
cleanup();
|
|
102
|
+
// Parse defensively, for the same reason the fetch client does: a
|
|
103
|
+
// proxy or serverless platform can reject the request before it
|
|
104
|
+
// reaches the app and answer with HTML, and parsing first would throw
|
|
105
|
+
// a syntax error that buries the real status.
|
|
106
|
+
let data = null;
|
|
107
|
+
try {
|
|
108
|
+
data = JSON.parse(xhr.responseText);
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
// Left null; handled below.
|
|
112
|
+
}
|
|
113
|
+
const ok = xhr.status >= 200 && xhr.status < 300;
|
|
114
|
+
if (!ok) {
|
|
115
|
+
reject(new ApiError(xhr.status, data, data?.message || data?.error || `Upload failed (${xhr.status})`));
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (!data) {
|
|
119
|
+
reject(new ApiError(xhr.status, null, 'Malformed response from server'));
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
if (!data.success) {
|
|
123
|
+
reject(new ApiError(xhr.status, data, data.message || data.error));
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
resolve(data);
|
|
127
|
+
});
|
|
128
|
+
xhr.addEventListener('error', () => {
|
|
129
|
+
cleanup();
|
|
130
|
+
// XHR reports network failures with no detail at all, by design —
|
|
131
|
+
// exposing more would leak cross-origin information.
|
|
132
|
+
reject(new ApiError(0, null, 'Network error during upload'));
|
|
133
|
+
});
|
|
134
|
+
xhr.addEventListener('timeout', () => {
|
|
135
|
+
cleanup();
|
|
136
|
+
reject(new ApiError(0, null, 'Upload timed out'));
|
|
137
|
+
});
|
|
138
|
+
xhr.addEventListener('abort', () => {
|
|
139
|
+
cleanup();
|
|
140
|
+
reject(new ApiError(0, null, 'Upload cancelled'));
|
|
141
|
+
});
|
|
142
|
+
xhr.send(body);
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=upload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upload.js","sourceRoot":"","sources":["../../../src/lib/api/upload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAuBpC;;;;;GAKG;AACH;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,YAAY,CAC3B,GAAW,EACX,IAAiB,EACjB,UAAkC,EAAE,EACpC,UAAyB,EAAE;IAE3B,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IAElD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACtC,IAAI,MAAM,EAAE,OAAO,EAAE,CAAC;YACrB,MAAM,CAAC,IAAI,QAAQ,CAAC,CAAC,E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,CAAC,IAAI,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAE,kBAAkB,CAAC,CAAC,CAAC;QACnD,CAAC,CAAC,CAAC;QAEH,GAAG,CAAC,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE;YAClC,OAAO,EAAE,CAAC;YACV,MAAM,CAAC,IAAI,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAE,kBAAkB,CAAC,CAAC,CAAC;QACnD,CAAC,CAAC,CAAC;QAEH,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAChB,CAAC,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/lib/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/lib/config.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/lib/config.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAI/C,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,GAAG,SAAS,CAsC5D"}
|
package/dist/lib/config.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createPartResolver } from './plugins/resolver.js';
|
|
2
|
+
import { resolveMaxUploadBytes } from './api/limits.js';
|
|
2
3
|
export function createCMSConfig(config) {
|
|
3
4
|
// Resolve plugin parts once (also runs duplicate-part-id validation) and fold
|
|
4
5
|
// schema contributions into `schemaTypes` so the engine, GraphQL, and typegen
|
|
@@ -9,6 +10,19 @@ export function createCMSConfig(config) {
|
|
|
9
10
|
// Merge plugin schemas, then let schema-transform parts decorate the full list
|
|
10
11
|
// (e.g. inject an SEO field group into chosen collections).
|
|
11
12
|
const mergedSchemas = resolver.applySchemaTransforms([...config.schemaTypes, ...pluginSchemas]);
|
|
13
|
+
// One upload ceiling, resolved here and pushed into the storage adapter.
|
|
14
|
+
//
|
|
15
|
+
// `upload.maxFileSize` already backed all three request-side checks — the
|
|
16
|
+
// `bodyLimit` middleware, the direct-upload grant, and the limit the admin
|
|
17
|
+
// reads back — but the adapter carried its own independent number, which is
|
|
18
|
+
// how the reference app ended up allowing 100MB requests into an adapter
|
|
19
|
+
// capped at 10MB. Nothing reported the disagreement; uploads in that band
|
|
20
|
+
// simply failed inside `store()`.
|
|
21
|
+
//
|
|
22
|
+
// The request-body value is pushed down as-is rather than the multipart-
|
|
23
|
+
// adjusted one: a Local API or MCP caller has no multipart framing and should
|
|
24
|
+
// be able to store a file of the full configured size.
|
|
25
|
+
config.storage?.setMaxFileSize?.(resolveMaxUploadBytes({ config }));
|
|
12
26
|
return {
|
|
13
27
|
// Start with the user's config and apply defaults for missing properties
|
|
14
28
|
...config,
|
package/dist/lib/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/lib/config.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/lib/config.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAErD,MAAM,UAAU,eAAe,CAAC,MAAiB;IAChD,8EAA8E;IAC9E,8EAA8E;IAC9E,gFAAgF;IAChF,kFAAkF;IAClF,MAAM,QAAQ,GAAG,kBAAkB,CAAC,MAAM,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC;IAC1D,MAAM,aAAa,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;IAC7C,+EAA+E;IAC/E,4DAA4D;IAC5D,MAAM,aAAa,GAAG,QAAQ,CAAC,qBAAqB,CAAC,CAAC,GAAG,MAAM,CAAC,WAAW,EAAE,GAAG,aAAa,CAAC,CAAC,CAAC;IAEhG,yEAAyE;IACzE,EAAE;IACF,0EAA0E;IAC1E,2EAA2E;IAC3E,4EAA4E;IAC5E,yEAAyE;IACzE,0EAA0E;IAC1E,kCAAkC;IAClC,EAAE;IACF,yEAAyE;IACzE,8EAA8E;IAC9E,uDAAuD;IACvD,MAAM,CAAC,OAAO,EAAE,cAAc,EAAE,CAAC,qBAAqB,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;IAEpE,OAAO;QACN,yEAAyE;QACzE,GAAG,MAAM;QACT,WAAW,EAAE,aAAa;QAC1B,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,IAAI,EAAE,kCAAkC;QACnE,aAAa,EAAE;YACd,QAAQ,EAAE;gBACT,KAAK,EAAE,WAAW;gBAClB,GAAG,MAAM,CAAC,aAAa,EAAE,QAAQ;aACjC;YACD,GAAG,MAAM,CAAC,aAAa;SACvB;KACD,CAAC;AACH,CAAC"}
|
|
@@ -1,14 +1,90 @@
|
|
|
1
|
-
import type { Asset } from '../../types/index.js';
|
|
1
|
+
import type { Asset, AssetMetadata } from '../../types/index.js';
|
|
2
2
|
import type { Where, FindOptions, FindResult } from '../../types/filters.js';
|
|
3
|
+
/**
|
|
4
|
+
* Ordering for a page of assets.
|
|
5
|
+
*
|
|
6
|
+
* Deliberately a closed set of named orders rather than a `{ field, direction }`
|
|
7
|
+
* pair: the sort has to be applied in SQL to be correct across pages, so every
|
|
8
|
+
* value here is one an adapter must be able to express as an index-friendly
|
|
9
|
+
* `ORDER BY`. An open column/direction pair would invite sorting on something
|
|
10
|
+
* unindexed — or unsortable, like a JSON metadata key — with no way for the
|
|
11
|
+
* adapter to say no.
|
|
12
|
+
*/
|
|
13
|
+
export type AssetSort = 'newest' | 'oldest' | 'name-asc' | 'name-desc';
|
|
14
|
+
/**
|
|
15
|
+
* Coarse media kinds, for the media browser's type filter.
|
|
16
|
+
*
|
|
17
|
+
* Deliberately not the same axis as `assetType` ('image' | 'file'), which records
|
|
18
|
+
* whether the pipeline treated the upload as an image. This groups by what an
|
|
19
|
+
* editor is looking for, so `svg` is its own bucket rather than an image: it is
|
|
20
|
+
* the one the editor picks when hunting for a logo, and it behaves unlike a
|
|
21
|
+
* raster image everywhere else too.
|
|
22
|
+
*/
|
|
23
|
+
export type AssetCategory = 'image' | 'svg' | 'video' | 'audio' | 'document';
|
|
3
24
|
export interface AssetFilters {
|
|
4
25
|
assetType?: 'image' | 'file';
|
|
5
26
|
mimeType?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Coarse media kind. Resolved against `mimeType` by the adapter, so a caller
|
|
29
|
+
* doesn't have to know that "document" means everything that isn't media.
|
|
30
|
+
*/
|
|
31
|
+
category?: AssetCategory;
|
|
32
|
+
/**
|
|
33
|
+
* Free text. Matches the filename *and* the editable metadata (title, alt,
|
|
34
|
+
* description) — the distinction between a media library and a file browser is
|
|
35
|
+
* that alt text written for accessibility is also how you find the asset
|
|
36
|
+
* again. Case-insensitive on both dialects.
|
|
37
|
+
*/
|
|
6
38
|
search?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Whether the asset is referenced by any document.
|
|
41
|
+
*
|
|
42
|
+
* Answered from the asset-reference index, so it is an indexed `EXISTS` rather
|
|
43
|
+
* than a scan. It could not be offered before that index existed: references
|
|
44
|
+
* were resolved with `LIKE '%assetId%'` over every document's JSON, which
|
|
45
|
+
* makes a *filter* cost assets × documents.
|
|
46
|
+
*
|
|
47
|
+
* `'unused'` is the actionable one — it's how a library gets cleaned up — so
|
|
48
|
+
* it is worth being precise about what it means: no document references the
|
|
49
|
+
* asset in either its draft or its published data. An asset used only by an
|
|
50
|
+
* abandoned draft is therefore *in use*, which is the safe direction to err.
|
|
51
|
+
*/
|
|
52
|
+
usage?: 'in-use' | 'unused';
|
|
7
53
|
includeSystem?: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Widen the query from the caller's organization to that organization plus
|
|
56
|
+
* its children.
|
|
57
|
+
*
|
|
58
|
+
* A *request*, not a resolution: the caller doesn't know the hierarchy, so
|
|
59
|
+
* the adapter facade expands this into `filterOrganizationIds` before the
|
|
60
|
+
* asset adapter sees it. Ignored when hierarchy is disabled in config.
|
|
61
|
+
*/
|
|
62
|
+
includeChildOrganizations?: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* The explicit set of organizations to search, written by the facade.
|
|
65
|
+
*
|
|
66
|
+
* Callers outside an adapter should use `includeChildOrganizations` and let
|
|
67
|
+
* the facade resolve it; this exists so the resolution happens once per
|
|
68
|
+
* request rather than once per adapter method. Access is still enforced —
|
|
69
|
+
* under RLS by policy, and otherwise by the facade only ever putting the
|
|
70
|
+
* caller's own subtree in here.
|
|
71
|
+
*/
|
|
72
|
+
filterOrganizationIds?: string[];
|
|
73
|
+
/** Defaults to `'newest'`. */
|
|
74
|
+
sort?: AssetSort;
|
|
8
75
|
limit?: number;
|
|
9
76
|
offset?: number;
|
|
10
77
|
}
|
|
11
78
|
export interface CreateAssetData {
|
|
79
|
+
/**
|
|
80
|
+
* Explicit primary key. Omit to let the database generate one.
|
|
81
|
+
*
|
|
82
|
+
* Supplied by `AssetService.uploadAsset`, which needs the id *before* the
|
|
83
|
+
* row exists: the storage key is `{assetId}/original.{ext}`, so the file is
|
|
84
|
+
* written before the insert. Adapters must pass this through rather than
|
|
85
|
+
* relying on their column default.
|
|
86
|
+
*/
|
|
87
|
+
id?: string;
|
|
12
88
|
organizationId: string;
|
|
13
89
|
assetType: 'image' | 'file';
|
|
14
90
|
filename: string;
|
|
@@ -27,12 +103,45 @@ export interface CreateAssetData {
|
|
|
27
103
|
creditLine?: string;
|
|
28
104
|
createdBy?: string;
|
|
29
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* Patch for an existing asset row.
|
|
108
|
+
*
|
|
109
|
+
* The editorial fields distinguish `undefined` from `null`, and adapters must
|
|
110
|
+
* preserve that distinction: **`undefined` means "leave this column alone",
|
|
111
|
+
* `null` means "clear it"**. Drizzle's `.set()` already drops undefined keys, so
|
|
112
|
+
* the natural implementation is the correct one — but an adapter that coalesces
|
|
113
|
+
* null to undefined (or filters falsy values) makes metadata addable and never
|
|
114
|
+
* removable, which is exactly the bug this shape exists to prevent.
|
|
115
|
+
*/
|
|
30
116
|
export interface UpdateAssetData {
|
|
31
117
|
url?: string;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
118
|
+
/**
|
|
119
|
+
* Display filename. Renaming touches nothing in storage — the object lives at
|
|
120
|
+
* `{assetId}/original.{ext}`, which is derived from the id, not the name — but
|
|
121
|
+
* it does change `url`, whose trailing segment is cosmetically the filename.
|
|
122
|
+
* `AssetService.updateAssetMetadata` keeps the two in step; don't set this
|
|
123
|
+
* through an adapter directly.
|
|
124
|
+
*/
|
|
125
|
+
originalFilename?: string;
|
|
126
|
+
/**
|
|
127
|
+
* Pixel dimensions. Writable because video's are only knowable in a browser —
|
|
128
|
+
* the upload path has no decoder for a video container, so they arrive later
|
|
129
|
+
* from the client that read the file. Images set these at upload and never
|
|
130
|
+
* update them.
|
|
131
|
+
*/
|
|
132
|
+
width?: number;
|
|
133
|
+
height?: number;
|
|
134
|
+
title?: string | null;
|
|
135
|
+
description?: string | null;
|
|
136
|
+
alt?: string | null;
|
|
137
|
+
creditLine?: string | null;
|
|
138
|
+
/**
|
|
139
|
+
* Replaces the whole metadata object — adapters write it as one JSON column,
|
|
140
|
+
* so there is no partial update. Callers must merge onto the current value
|
|
141
|
+
* rather than sending a fragment, or they silently drop whatever else the
|
|
142
|
+
* upload path recorded (dimensions, dominant colour, privacy fields).
|
|
143
|
+
*/
|
|
144
|
+
metadata?: AssetMetadata;
|
|
36
145
|
updatedBy?: string;
|
|
37
146
|
}
|
|
38
147
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asset.d.ts","sourceRoot":"","sources":["../../../../src/lib/db/interfaces/asset.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CA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CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;IAC7E,WAAW,CAAC,cAAc,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC;IAC9F,WAAW,CAAC,cAAc,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAGlE,WAAW,CAAC,cAAc,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC7E,iBAAiB,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAC3E,kBAAkB,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAG5D;;;;;OAKG;IACH,sBAAsB,CAAC,cAAc,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;IAElG;;;;;OAKG;IACH,qBAAqB,CAAC,cAAc,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC;IAEjF;;;;;OAKG;IACH,mBAAmB,CAAC,cAAc,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAC5E"}
|
|
@@ -52,6 +52,15 @@ export interface DocumentAdapter {
|
|
|
52
52
|
*/
|
|
53
53
|
updateDocDraft(organizationId: string, id: string, data: any, updatedBy?: string, expectedRevision?: number): Promise<Document | null>;
|
|
54
54
|
deleteDocById(organizationId: string, id: string): Promise<boolean>;
|
|
55
|
+
/**
|
|
56
|
+
* Recompute the document's precomputed full-text search index (`search_text`
|
|
57
|
+
* column, and on SQLite the FTS5 shadow table row) from caller-supplied text.
|
|
58
|
+
* Called by `CollectionAPI` as a best-effort step after `createDocument`/
|
|
59
|
+
* `updateDocDraft` succeeds — same shape as reference-index sync: not folded
|
|
60
|
+
* into the write transaction, self-healing on the next edit if it's missed.
|
|
61
|
+
* Optional so adapters without full-text search aren't broken.
|
|
62
|
+
*/
|
|
63
|
+
updateSearchText?(organizationId: string, id: string, searchText: string): Promise<void>;
|
|
55
64
|
publishDoc(organizationId: string, id: string, expectedRevision?: number): Promise<Document | null>;
|
|
56
65
|
unpublishDoc(organizationId: string, id: string, expectedRevision?: number): Promise<Document | null>;
|
|
57
66
|
countDocsByType(organizationId: string, type: string): Promise<number>;
|
|
@@ -80,6 +89,88 @@ export interface DocumentAdapter {
|
|
|
80
89
|
* @returns Count of matching documents
|
|
81
90
|
*/
|
|
82
91
|
countDocuments(organizationId: string, collectionName: string, where?: Where): Promise<number>;
|
|
92
|
+
/**
|
|
93
|
+
* Replace the asset-reference index rows for one document.
|
|
94
|
+
*
|
|
95
|
+
* Delete-then-insert for `(organizationId, documentId)`, so it is idempotent
|
|
96
|
+
* and cannot leave stale rows behind — a reference removed from a document has
|
|
97
|
+
* to disappear from the index, and reconciling row-by-row is a harder way to
|
|
98
|
+
* get the same result.
|
|
99
|
+
*
|
|
100
|
+
* **Called inside the document's own write transaction**, so the rows commit or
|
|
101
|
+
* roll back with it and a saved document is never unindexed. It was
|
|
102
|
+
* best-effort post-commit at first; that was wrong, because the `usage` filter
|
|
103
|
+
* *is* this index, so a dropped write doesn't cost a badge — it offers an
|
|
104
|
+
* in-use asset for deletion.
|
|
105
|
+
*
|
|
106
|
+
* **Deleting an asset still consults {@link findDocumentsReferencingAsset}**,
|
|
107
|
+
* which reads the documents themselves. Defence in depth: that independent
|
|
108
|
+
* guard is what caught the drift this contract replaced.
|
|
109
|
+
*
|
|
110
|
+
* Optional, like the other reference methods — an adapter that doesn't
|
|
111
|
+
* implement it simply has no index, and the `usage` filter is unavailable.
|
|
112
|
+
*/
|
|
113
|
+
replaceAssetReferences?(organizationId: string, documentId: string, documentType: string, references: Array<{
|
|
114
|
+
assetId: string;
|
|
115
|
+
fieldPath: string;
|
|
116
|
+
plane: 'draft' | 'published';
|
|
117
|
+
}>): Promise<void>;
|
|
118
|
+
/** Whether the asset-reference index holds any rows for this org (backfill check). */
|
|
119
|
+
hasAnyAssetReferences?(organizationId: string): Promise<boolean>;
|
|
120
|
+
/**
|
|
121
|
+
* How many distinct documents reference each of these assets, **from the
|
|
122
|
+
* index**.
|
|
123
|
+
*
|
|
124
|
+
* The counterpart to {@link countDocumentReferencesForAssets}, which answers
|
|
125
|
+
* the same question by scanning documents. Both exist on purpose, and which
|
|
126
|
+
* one a caller wants follows from what the number is for:
|
|
127
|
+
*
|
|
128
|
+
* - **This one, for anything the library displays.** It reads the same rows as
|
|
129
|
+
* the `usage` filter, so a count and the Unused filter beside it cannot
|
|
130
|
+
* contradict each other. It is also indexed, where the scan is
|
|
131
|
+
* assets × documents.
|
|
132
|
+
* - **The scan, for the delete guard.** Structure-blind, so a shape the walker
|
|
133
|
+
* doesn't model can't cause an in-use asset to be destroyed.
|
|
134
|
+
*
|
|
135
|
+
* They can still disagree, and that is the design: the guard deliberately
|
|
136
|
+
* over-approximates. What must never happen again is two *display* surfaces
|
|
137
|
+
* disagreeing, which is what a count from the scan next to a filter from the
|
|
138
|
+
* index produced.
|
|
139
|
+
*
|
|
140
|
+
* Counts distinct documents, not rows — an asset used in two fields of one
|
|
141
|
+
* document, or in both its planes, is one document that would break.
|
|
142
|
+
*/
|
|
143
|
+
countAssetReferencesForAssets?(organizationId: string, assetIds: string[]): Promise<Record<string, number>>;
|
|
144
|
+
/**
|
|
145
|
+
* Every distinct `type` present in the org's documents — including types with
|
|
146
|
+
* no registered schema.
|
|
147
|
+
*
|
|
148
|
+
* The asset-reference backfill needs this rather than the schema registry.
|
|
149
|
+
* Removing a schema type doesn't remove its documents, and those documents
|
|
150
|
+
* keep whatever assets they referenced. The delete guard scans them (it reads
|
|
151
|
+
* documents, unfiltered), so an index built only over registered types
|
|
152
|
+
* disagrees with the guard on exactly those assets: the "Unused" filter offers
|
|
153
|
+
* them, and the delete then refuses.
|
|
154
|
+
*
|
|
155
|
+
* Only the *asset* index can use this. `collectAssetReferences` walks raw JSON
|
|
156
|
+
* and needs no schema, whereas the document-to-document walker is schema-aware
|
|
157
|
+
* and has nothing to walk a schema-less type with.
|
|
158
|
+
*/
|
|
159
|
+
listStoredDocumentTypes?(organizationId: string): Promise<string[]>;
|
|
160
|
+
/**
|
|
161
|
+
* Indexed field paths for one asset — where inside each document it is used.
|
|
162
|
+
*
|
|
163
|
+
* Display only, and deliberately separate from
|
|
164
|
+
* {@link findDocumentsReferencingAsset}: that one reads the documents and stays
|
|
165
|
+
* the authority for the delete guard, while this annotates its results with
|
|
166
|
+
* "Hero image" or "Gallery, image 2". A missing or stale row costs a label, not
|
|
167
|
+
* correctness, so the two are never merged.
|
|
168
|
+
*/
|
|
169
|
+
findAssetReferenceFieldPaths?(organizationId: string, assetId: string): Promise<Array<{
|
|
170
|
+
documentId: string;
|
|
171
|
+
fieldPath: string;
|
|
172
|
+
plane: string;
|
|
173
|
+
}>>;
|
|
83
174
|
/**
|
|
84
175
|
* Find documents that reference a specific asset ID in their data
|
|
85
176
|
* Searches both draftData and publishedData JSONB columns
|
|
@@ -102,10 +193,23 @@ export interface DocumentAdapter {
|
|
|
102
193
|
*/
|
|
103
194
|
countDocumentReferencesForAssets?(organizationId: string, assetIds: string[], knownTypes?: string[]): Promise<Record<string, number>>;
|
|
104
195
|
/**
|
|
105
|
-
* Clear references to a deleted asset from
|
|
106
|
-
*
|
|
196
|
+
* Clear references to a deleted asset from document data. Returns the number
|
|
197
|
+
* of documents modified.
|
|
198
|
+
*
|
|
199
|
+
* Clears `draftData` on every document, and `publishedData` only on
|
|
200
|
+
* non-published ones (the stale copy left by an unpublish). It must NOT
|
|
201
|
+
* rewrite `publishedData` on a published document — that column is written
|
|
202
|
+
* only by publish, and mutating it here would desync the content hash. The
|
|
203
|
+
* reference leaves published data on the next publish instead.
|
|
204
|
+
*
|
|
205
|
+
* Must not filter by registered schema type: a document whose type was
|
|
206
|
+
* removed from the codebase still holds the reference, and is exactly what a
|
|
207
|
+
* force-delete leaves behind.
|
|
208
|
+
*
|
|
209
|
+
* Renamed from `clearAssetFromPublishedData`, which described neither what it
|
|
210
|
+
* did nor what it now does.
|
|
107
211
|
*/
|
|
108
|
-
|
|
212
|
+
clearAssetReferences?(organizationId: string, assetId: string): Promise<number>;
|
|
109
213
|
createDocumentVersion?(data: {
|
|
110
214
|
documentId: string;
|
|
111
215
|
organizationId: string;
|