@maravilla-labs/platform 0.3.11 → 0.4.1
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/config.d.ts +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +40 -0
- package/dist/index.js.map +1 -1
- package/dist/transforms-B3XZ8wYs.d.ts +300 -0
- package/package.json +1 -1
- package/src/remote-client.ts +33 -1
- package/src/transforms.ts +172 -1
- package/dist/transforms-KzpoYW43.d.ts +0 -156
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Media transforms — async ffmpeg / image / OCR jobs.
|
|
3
|
-
*
|
|
4
|
-
* Mirrors the Rust `platform.media.transforms` surface. All mutating
|
|
5
|
-
* methods (transcode/thumbnail/resize/ocr) return a {@link JobHandle}
|
|
6
|
-
* whose `outputKey` is content-addressed via {@link keyFor} and known
|
|
7
|
-
* up front — clients can render placeholder UI for the derived asset
|
|
8
|
-
* before the worker even starts the job.
|
|
9
|
-
*
|
|
10
|
-
* The runtime injects the live JS object as `platform.media.transforms`
|
|
11
|
-
* (see `crates/runtime/src/ops/platform/js_bindings/platform_js.rs`).
|
|
12
|
-
* The static helper {@link keyFor} is exported separately and runs
|
|
13
|
-
* client-side — it must produce byte-for-byte identical output to the
|
|
14
|
-
* Rust `derive_key`. The shared golden-vector fixture
|
|
15
|
-
* `crates/platform/tests/derive_key_vectors.json` is consumed from both
|
|
16
|
-
* the Rust integration test (`crates/platform/tests/derive_key_golden.rs`)
|
|
17
|
-
* and the TS test (`packages/platform/tests/derive-key.test.ts`) to keep
|
|
18
|
-
* the two in lockstep.
|
|
19
|
-
*/
|
|
20
|
-
/** Video container targets supported by v1. */
|
|
21
|
-
type VideoFormat = 'mp4' | 'webm';
|
|
22
|
-
/** Image output formats supported by v1. */
|
|
23
|
-
type ImageFormat = 'jpg' | 'png' | 'webp';
|
|
24
|
-
/** Lifecycle state of a transform job. */
|
|
25
|
-
type JobStatus = 'pending' | 'running' | 'complete' | 'failed';
|
|
26
|
-
/** Options for `transforms.transcode`. */
|
|
27
|
-
interface TranscodeOpts {
|
|
28
|
-
format: VideoFormat;
|
|
29
|
-
codec?: string;
|
|
30
|
-
max_width?: number;
|
|
31
|
-
max_height?: number;
|
|
32
|
-
audio_codec?: string;
|
|
33
|
-
bitrate_kbps?: number;
|
|
34
|
-
}
|
|
35
|
-
/** Options for `transforms.thumbnail` — extract a single video frame. */
|
|
36
|
-
interface ThumbnailOpts {
|
|
37
|
-
/** Offset into the source. Accepts `"00:00:01"`, `"1s"`, or a plain number-as-string. */
|
|
38
|
-
at: string;
|
|
39
|
-
width?: number;
|
|
40
|
-
height?: number;
|
|
41
|
-
/** Defaults to `"jpg"` server-side when omitted. */
|
|
42
|
-
format?: ImageFormat;
|
|
43
|
-
quality?: number;
|
|
44
|
-
}
|
|
45
|
-
/** Options for `transforms.resize`. */
|
|
46
|
-
interface ResizeOpts {
|
|
47
|
-
width?: number;
|
|
48
|
-
height?: number;
|
|
49
|
-
format: ImageFormat;
|
|
50
|
-
quality?: number;
|
|
51
|
-
strip_metadata?: boolean;
|
|
52
|
-
}
|
|
53
|
-
/** Options for `transforms.ocr`. */
|
|
54
|
-
interface OcrOpts {
|
|
55
|
-
/** Tesseract language code(s). Defaults to `"eng"` server-side when omitted. */
|
|
56
|
-
lang?: string;
|
|
57
|
-
}
|
|
58
|
-
/** Tagged union of all transform requests — matches the Rust `TransformSpec`. */
|
|
59
|
-
type TransformSpec = ({
|
|
60
|
-
kind: 'transcode';
|
|
61
|
-
} & TranscodeOpts) | ({
|
|
62
|
-
kind: 'thumbnail';
|
|
63
|
-
} & ThumbnailOpts) | ({
|
|
64
|
-
kind: 'resize';
|
|
65
|
-
} & ResizeOpts) | ({
|
|
66
|
-
kind: 'ocr';
|
|
67
|
-
} & OcrOpts);
|
|
68
|
-
/** Probe output. All fields optional — ffprobe doesn't fill every one for every input. */
|
|
69
|
-
interface MediaInfo {
|
|
70
|
-
duration_secs?: number;
|
|
71
|
-
width?: number;
|
|
72
|
-
height?: number;
|
|
73
|
-
video_codec?: string;
|
|
74
|
-
audio_codec?: string;
|
|
75
|
-
bitrate_bps?: number;
|
|
76
|
-
container?: string;
|
|
77
|
-
}
|
|
78
|
-
/** Returned by every mutating transforms method. */
|
|
79
|
-
interface JobHandle {
|
|
80
|
-
id: string;
|
|
81
|
-
src_key: string;
|
|
82
|
-
output_key: string;
|
|
83
|
-
status: JobStatus;
|
|
84
|
-
}
|
|
85
|
-
/** Returned by `transforms.job(id)`. */
|
|
86
|
-
interface JobStatusResponse {
|
|
87
|
-
id: string;
|
|
88
|
-
status: JobStatus;
|
|
89
|
-
}
|
|
90
|
-
interface TransformsService {
|
|
91
|
-
transcode(srcKey: string, opts: TranscodeOpts): Promise<JobHandle>;
|
|
92
|
-
thumbnail(srcKey: string, opts: ThumbnailOpts): Promise<JobHandle>;
|
|
93
|
-
resize(srcKey: string, opts: ResizeOpts): Promise<JobHandle>;
|
|
94
|
-
probe(srcKey: string): Promise<MediaInfo>;
|
|
95
|
-
ocr(srcKey: string, opts?: OcrOpts | null): Promise<JobHandle>;
|
|
96
|
-
job(id: string): Promise<JobStatusResponse>;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Compute the canonical derived-asset key for `(srcKey, spec)`.
|
|
100
|
-
*
|
|
101
|
-
* Shape: `__derived/<srcHash>/<variantHash>.<ext>` where each hash is
|
|
102
|
-
* the first 16 hex chars (8 bytes / 64 bits) of `SHA-256(...)`.
|
|
103
|
-
*
|
|
104
|
-
* **MUST** match Rust `platform::media::transforms::derive_key` byte-for-byte.
|
|
105
|
-
* Cross-language golden vectors live at
|
|
106
|
-
* `crates/platform/tests/derive_key_vectors.json`.
|
|
107
|
-
*/
|
|
108
|
-
declare function keyFor(srcKey: string, spec: TransformSpec): string;
|
|
109
|
-
/** Convenience namespace mirroring the Rust `transforms::keyFor` re-export. */
|
|
110
|
-
declare const transforms: {
|
|
111
|
-
keyFor: typeof keyFor;
|
|
112
|
-
};
|
|
113
|
-
/**
|
|
114
|
-
* Per-pattern transforms declaration used inside the `transforms` block of
|
|
115
|
-
* `maravilla.config.ts`. Each field accepts a single opts object or an array.
|
|
116
|
-
*
|
|
117
|
-
* `variants` is sugar for `resize` arrays — convenient for the common
|
|
118
|
-
* "image → multiple resized renditions" case.
|
|
119
|
-
*/
|
|
120
|
-
interface TransformsPatternSpec {
|
|
121
|
-
transcode?: TranscodeOpts | TranscodeOpts[];
|
|
122
|
-
thumbnail?: ThumbnailOpts | ThumbnailOpts[];
|
|
123
|
-
resize?: ResizeOpts | ResizeOpts[];
|
|
124
|
-
/** Sugar for `resize` arrays — same shape, same semantics. */
|
|
125
|
-
variants?: ResizeOpts[];
|
|
126
|
-
ocr?: OcrOpts | OcrOpts[];
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Top-level `transforms` block. Keys are glob path patterns matched against
|
|
130
|
-
* the storage key of every uploaded object. The adapter compiles each entry
|
|
131
|
-
* into a synthetic `storage.put` event handler that fans out the declared
|
|
132
|
-
* transforms via `Promise.all`.
|
|
133
|
-
*
|
|
134
|
-
* @example
|
|
135
|
-
* ```ts
|
|
136
|
-
* import { defineConfig } from '@maravilla-labs/platform/config';
|
|
137
|
-
*
|
|
138
|
-
* export default defineConfig({
|
|
139
|
-
* transforms: {
|
|
140
|
-
* 'uploads/videos/**': {
|
|
141
|
-
* transcode: [{ format: 'mp4' }, { format: 'webm' }],
|
|
142
|
-
* thumbnail: { at: '1s', width: 640, format: 'jpg' },
|
|
143
|
-
* },
|
|
144
|
-
* 'uploads/photos/**': {
|
|
145
|
-
* variants: [
|
|
146
|
-
* { width: 1600, format: 'webp', quality: 85 },
|
|
147
|
-
* { width: 400, format: 'webp', quality: 80 },
|
|
148
|
-
* ],
|
|
149
|
-
* },
|
|
150
|
-
* },
|
|
151
|
-
* });
|
|
152
|
-
* ```
|
|
153
|
-
*/
|
|
154
|
-
type TransformsConfig = Record<string, TransformsPatternSpec>;
|
|
155
|
-
|
|
156
|
-
export { type ImageFormat as I, type JobHandle as J, type MediaInfo as M, type OcrOpts as O, type ResizeOpts as R, type TransformsConfig as T, type VideoFormat as V, type TransformsPatternSpec as a, type JobStatus as b, type JobStatusResponse as c, type ThumbnailOpts as d, type TranscodeOpts as e, type TransformSpec as f, type TransformsService as g, keyFor as k, transforms as t };
|