@adonis-agora/media 0.28.2 → 0.30.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.
Files changed (55) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/README.md +43 -0
  3. package/dist/assets/spa/assets/index-B48tE8sr.js +12 -0
  4. package/dist/assets/spa/assets/index-B48tE8sr.js.map +1 -0
  5. package/dist/assets/spa/assets/index-CjblUKFX.css +2 -0
  6. package/dist/assets/spa/index.html +2 -2
  7. package/dist/src/index.d.ts +5 -4
  8. package/dist/src/index.d.ts.map +1 -1
  9. package/dist/src/index.js +3 -3
  10. package/dist/src/index.js.map +1 -1
  11. package/dist/src/media_access.d.ts.map +1 -1
  12. package/dist/src/media_access.js +4 -3
  13. package/dist/src/media_access.js.map +1 -1
  14. package/dist/src/media_library.d.ts.map +1 -1
  15. package/dist/src/media_library.js +7 -4
  16. package/dist/src/media_library.js.map +1 -1
  17. package/dist/src/media_manager.d.ts +33 -7
  18. package/dist/src/media_manager.d.ts.map +1 -1
  19. package/dist/src/media_manager.js +121 -27
  20. package/dist/src/media_manager.js.map +1 -1
  21. package/dist/src/streaming.d.ts +15 -1
  22. package/dist/src/streaming.d.ts.map +1 -1
  23. package/dist/src/streaming.js +44 -2
  24. package/dist/src/streaming.js.map +1 -1
  25. package/dist/src/testing/index.d.ts +2 -0
  26. package/dist/src/testing/index.d.ts.map +1 -1
  27. package/dist/src/testing/index.js +1 -0
  28. package/dist/src/testing/index.js.map +1 -1
  29. package/dist/src/testing/media_fake.d.ts +93 -0
  30. package/dist/src/testing/media_fake.d.ts.map +1 -0
  31. package/dist/src/testing/media_fake.js +150 -0
  32. package/dist/src/testing/media_fake.js.map +1 -0
  33. package/dist/src/transformers/factory.d.ts +14 -3
  34. package/dist/src/transformers/factory.d.ts.map +1 -1
  35. package/dist/src/transformers/factory.js +31 -4
  36. package/dist/src/transformers/factory.js.map +1 -1
  37. package/dist/src/transformers/ffmpeg.d.ts +38 -1
  38. package/dist/src/transformers/ffmpeg.d.ts.map +1 -1
  39. package/dist/src/transformers/ffmpeg.js +119 -16
  40. package/dist/src/transformers/ffmpeg.js.map +1 -1
  41. package/dist/src/transformers/mediabunny.d.ts +2 -1
  42. package/dist/src/transformers/mediabunny.d.ts.map +1 -1
  43. package/dist/src/transformers/mediabunny.js +174 -33
  44. package/dist/src/transformers/mediabunny.js.map +1 -1
  45. package/dist/src/transformers/mediabunny_loader.d.ts +29 -1
  46. package/dist/src/transformers/mediabunny_loader.d.ts.map +1 -1
  47. package/dist/src/transformers/mediabunny_loader.js.map +1 -1
  48. package/dist/src/transformers/video.d.ts +42 -0
  49. package/dist/src/transformers/video.d.ts.map +1 -1
  50. package/dist/src/transformers/video.js +37 -0
  51. package/dist/src/transformers/video.js.map +1 -1
  52. package/package.json +9 -4
  53. package/dist/assets/spa/assets/index-C7-E4B8r.js +0 -12
  54. package/dist/assets/spa/assets/index-C7-E4B8r.js.map +0 -1
  55. package/dist/assets/spa/assets/index-CrdjxPM5.css +0 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,39 @@
1
1
  # @adonis-agora/media
2
2
 
3
+ ## 0.30.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#270](https://github.com/DavideCarvalho/adonis-agora-media/pull/270) [`64d5c2a`](https://github.com/DavideCarvalho/adonis-agora-media/commit/64d5c2abf610ab693b0198f2fc72f8fb9488de50) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - `engines.mediabunny({ ladder })` encodes an adaptive-bitrate ladder without spawning ffmpeg, through the optional peer `@mediabunny/server` (mediabunny's Node decoders/encoders over NodeAV; its native binary needs glibc). Every rung is encoded from one decode of the video, with a keyframe every `targetDuration` seconds, and the audio once to aac as the shared group; both manifests are written over the CMAF playlists. Without `ladder` it is the default remux engine. A missing `@mediabunny/server` throws `TransformerRuntimeMissingError`. The audio is muxed in its own pass because mediabunny 1.65.2's HLS muxer fails an assertion — as an unhandled rejection — when several video variants share an audio group in one output.
8
+
9
+ `VideoPackagingEngine` gains an optional `storyboard` flag: `transformers.video({ storyboard })` now refuses, at config time, any engine that does not declare it (`engines.ffmpeg()` does). The HLS master of the mediabunny engines lists every video rendition.
10
+
11
+ - [#270](https://github.com/DavideCarvalho/adonis-agora-media/pull/270) [`64d5c2a`](https://github.com/DavideCarvalho/adonis-agora-media/commit/64d5c2abf610ab693b0198f2fc72f8fb9488de50) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - `transformers.video({ storyboard })` writes timeline thumbnails — the preview a player shows over the progress bar while scrubbing — next to the streaming package: JPEG sprite sheets (`storyboard-001.jpg`…, a frame every `interval` seconds, `width` px wide, `columns` × `rows` per sheet; defaults 5 s, 160 px, 10 × 10) and a WebVTT (`storyboard.vtt`, `VIDEO_STORYBOARD`) mapping each interval to its tile with `#xywh=`. The stream route serves the sheets as `image/jpeg`, and the conversion `meta.storyboard` names the WebVTT; under `delivery.signing` a package WebVTT is signed like a manifest — only its cue lines that name package files get the signature, before the `#xywh=` fragment (new: `isWebVtt`, `rewriteWebVtt`, `WEBVTT_MIME_TYPE`). `engines.ffmpeg()` runs the storyboard decode alongside the encode, from the same local source; the default mediabunny engine cannot decode frames in Node, so `storyboard` without an engine is refused at config time. Also exported: `buildStoryboardArgs`, `buildStoryboardVtt`, `storyboardTileHeight`, `VIDEO_STORYBOARD_DEFAULTS`.
12
+
13
+ ## 0.29.0
14
+
15
+ ### Minor Changes
16
+
17
+ - [#258](https://github.com/DavideCarvalho/adonis-agora-media/pull/258) [`cb90771`](https://github.com/DavideCarvalho/adonis-agora-media/commit/cb90771a3e30c2e08b6342b51978af124d172c95) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - **`media.fake()` / `media.restore()`** — fake the media service in app tests, like `drive.fake()` and `mail.fake()`.
18
+
19
+ `import media from '@adonis-agora/media/services/main'` captures the `MediaManager` once at boot, so `app.container.swap(MediaManager, …)` never reaches code that already imported it, and apps fell back to monkeypatching `media.library.attach = …`, which leaks between suites. The swap now happens inside the manager:
20
+
21
+ ```ts
22
+ const fake = media.fake()
23
+ await uploadAvatar()
24
+ fake.assertCalled('attach', (input) => input.collection === 'avatar')
25
+ assert.equal(fake.calls.signedUrl[0]?.[1], 300) // TTL
26
+ fake.stub('deliver', async () => ({ kind: 'redirect', url: 'https://cdn.test/x' }))
27
+ media.restore()
28
+ ```
29
+
30
+ - While faked, `media.library` (and `store`, `storage`, `attachments`, `uploads`, `resumable`, `direct`) run the real library code, with the configured collections and delivery settings, over an `InMemoryMediaStore`, an `InMemoryDisk` for every disk name and a `FakeImageProcessor`.
31
+ - The returned `MediaFake` records every `media.library` call with typed arguments (`fake.calls.<method>`), has `assertCalled` / `assertNotCalled`, and `stub(method, fn)` / `unstub(method)` to force a result or an error.
32
+ - `media.fake()` again starts a fresh fake; `media.restore()` is a no-op without one.
33
+ - New exports from `@adonis-agora/media/testing`: `MediaFake`, `MEDIA_FAKE_METHODS`, `lazyInMemoryDiskResolver`, and the types `MediaFakeOptions`, `MediaFakeMethod`, `MediaFakeCall`, `MediaFakeCalls`, `MediaFakeStub`.
34
+
35
+ `MediaManager.storage`, `library`, `attachments`, `store` and `uploads` are now getters instead of readonly fields. Reading them is unchanged; nothing could assign them before (they were `readonly`).
36
+
3
37
  ## 0.28.2
4
38
 
5
39
  ### Patch Changes
package/README.md CHANGED
@@ -360,6 +360,49 @@ const library = new MediaLibrary({
360
360
  In a real app you can also `drive.fake()` from `@adonisjs/drive` to back the disks with an in-memory
361
361
  fake while keeping the rest of the wiring intact.
362
362
 
363
+ ### Faking the `media` service in app tests
364
+
365
+ `import media from '@adonis-agora/media/services/main'` captures the manager once at boot, so
366
+ `app.container.swap(MediaManager, ...)` never reaches code that already imported it — and
367
+ monkeypatching `media.library.attach = ...` leaks between suites. Use `media.fake()` instead, the
368
+ same idea as `drive.fake()` / `mail.fake()`:
369
+
370
+ ```ts
371
+ import media from '@adonis-agora/media/services/main'
372
+
373
+ test('uploads the avatar', async ({ assert, cleanup }) => {
374
+ const fake = media.fake() // every `media.*` now runs in memory
375
+ cleanup(() => media.restore())
376
+
377
+ await client.post('/avatar').file('avatar', path).loginAs(user)
378
+
379
+ // Real library semantics (collections, whitelist, single-file replace, delivery) over an
380
+ // in-memory store, in-memory disks and a fake image processor:
381
+ const [record] = await media.library.list('User', user.id, 'avatar')
382
+ assert.equal(fake.disk().files.size, 1)
383
+
384
+ // Every `media.library` call is recorded with its typed arguments:
385
+ fake.assertCalled('attach', (input) => input.collection === 'avatar')
386
+ assert.equal(fake.calls.signedUrl[0]?.[1], 300) // the TTL passed to signedUrl
387
+ fake.assertNotCalled('delete')
388
+
389
+ // Force a result or an error the in-memory library would not produce:
390
+ fake.stub('deliver', async () => ({ kind: 'redirect', url: 'https://cdn.test/x' }))
391
+ fake.stub('attach', () => {
392
+ throw new Error('S3 is down')
393
+ })
394
+ })
395
+ ```
396
+
397
+ - `media.fake(options?)` — `{ visibility?: 'private' | 'public' | 'unknown', store?, imageProcessor? }`.
398
+ Keeps the configured collections and delivery settings; every disk name resolves to an
399
+ `InMemoryDisk` (`fake.disk(name)`). Calling it again starts a fresh fake.
400
+ - `fake.calls.<method>` — args tuples per call, for `attach`, `attachExisting`, `list`, `find`,
401
+ `delete`, `url`, `deliver`, `signedUrl`, `ensureConversion`, `transform` (`for(...)` records as
402
+ the method it calls). `fake.assertCalled` / `fake.assertNotCalled` take an optional predicate.
403
+ - `fake.stub(method, fn)` / `fake.unstub(method)` — stubbed calls are still recorded.
404
+ - `media.restore()` puts the real manager back (safe to call without a fake, or twice).
405
+
363
406
  ## Links
364
407
 
365
408
  - Repo: https://github.com/DavideCarvalho/adonis-media