@adonis-agora/media 0.28.1 → 0.29.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"media_fake.d.ts","sourceRoot":"","sources":["../../../src/testing/media_fake.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,KAAK,cAAc,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAExE;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,YAC7B,QAAQ,EACR,gBAAgB,EAChB,MAAM,EACN,MAAM,EACN,QAAQ,EACR,KAAK,EACL,SAAS,EACT,WAAW,EACX,kBAAkB,EAClB,WAAW,CACH,CAAC;AAEX,sEAAsE;AACtE,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAC;AAElE,wGAAwG;AACxG,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,eAAe,IAAI,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;AAEnF,sDAAsD;AACtD,MAAM,MAAM,cAAc,GAAG;IAAE,QAAQ,EAAE,CAAC,IAAI,eAAe,GAAG,aAAa,CAAC,CAAC,CAAC,EAAE;CAAE,CAAC;AAErF;;;GAGG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,eAAe,IAAI,CACrD,GAAG,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,KACtB,OAAO,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;AAExE,kCAAkC;AAClC,MAAM,WAAW,gBA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AI,CAGpC;IAED,4FAA4F;IAC5F,YAAY,CAAC,CAAC,SAAS,eAAe,EACpC,MAAM,EAAE,CAAC,EACT,SAAS,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,KAAK,OAAO,GACjD,IAAI,CAQN;IAED,uFAAuF;IACvF,eAAe,CAAC,CAAC,SAAS,eAAe,EACvC,MAAM,EAAE,CAAC,EACT,SAAS,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,KAAK,OAAO,GACjD,IAAI,CASN;IAED,sFAAsF;IACtF,OAAO,IAAI,IAAI,CAEd;CAuCF"}
@@ -0,0 +1,150 @@
1
+ import { AssertionError } from 'node:assert';
2
+ import { InMemoryDisk } from './in_memory_disk.js';
3
+ /**
4
+ * The {@link MediaLibrary} methods a {@link MediaFake} records and lets you {@link MediaFake.stub}.
5
+ * `for(...)` is not listed: its binding calls `attach`/`attachExisting`/`list` through the fake,
6
+ * so those are what get recorded.
7
+ */
8
+ export const MEDIA_FAKE_METHODS = [
9
+ 'attach',
10
+ 'attachExisting',
11
+ 'list',
12
+ 'find',
13
+ 'delete',
14
+ 'url',
15
+ 'deliver',
16
+ 'signedUrl',
17
+ 'ensureConversion',
18
+ 'transform',
19
+ ];
20
+ /**
21
+ * In-memory disks created on demand for ANY name, so every disk a config or collection names
22
+ * resolves without listing them up front. `undefined` resolves to `defaultDisk`.
23
+ */
24
+ export function lazyInMemoryDiskResolver(defaultDisk, visibility = 'private') {
25
+ const disks = {};
26
+ const resolve = (name) => {
27
+ const key = name ?? defaultDisk;
28
+ disks[key] ??= new InMemoryDisk(`memory://${key}`, visibility);
29
+ return disks[key];
30
+ };
31
+ return { resolve, disks };
32
+ }
33
+ function isFakeMethod(prop) {
34
+ return typeof prop === 'string' && MEDIA_FAKE_METHODS.includes(prop);
35
+ }
36
+ /**
37
+ * The handle `media.fake()` returns. While it is active, `media.library` (and `media.store`,
38
+ * `media.storage`, `media.attachments`, …) run on real library code over in-memory doubles, and
39
+ * every library call is recorded here.
40
+ *
41
+ * ```ts
42
+ * const fake = media.fake()
43
+ * await someCodeThatUploads()
44
+ * fake.assertCalled('attach', (input) => input.collection === 'avatar')
45
+ * assert.equal(fake.calls.signedUrl[0]?.[1], 300) // TTL
46
+ * fake.stub('deliver', async () => ({ kind: 'redirect', url: 'https://x.test' }))
47
+ * media.restore()
48
+ * ```
49
+ *
50
+ * Built by `MediaManager.fake()`; not meant to be constructed directly.
51
+ */
52
+ export class MediaFake {
53
+ /** Recorded calls per method — the args tuple of each call, in order. Stubbed calls included. */
54
+ calls;
55
+ /** The faked library — the very object `media.library` returns while this fake is active. */
56
+ library;
57
+ /** The store backing the fake (an `InMemoryMediaStore` unless one was passed). */
58
+ store;
59
+ /** In-memory disks created so far, by name (every name resolves; this lists the ones touched). */
60
+ disks;
61
+ #resolve;
62
+ #stubs = new Map();
63
+ #onRestore;
64
+ constructor(input) {
65
+ this.store = input.store;
66
+ this.disks = input.disks;
67
+ this.#resolve = input.resolve;
68
+ this.#onRestore = input.onRestore;
69
+ this.calls = Object.fromEntries(MEDIA_FAKE_METHODS.map((method) => [method, []]));
70
+ this.library = this.#record(input.library);
71
+ }
72
+ /** The in-memory disk behind `name` (default disk when omitted) — inspect `.files` for bytes. */
73
+ disk(name) {
74
+ return this.#resolve(name);
75
+ }
76
+ /**
77
+ * Replace one library method for the rest of this fake (calls are still recorded). Use it to
78
+ * force a result or an error the in-memory library would not produce on its own.
79
+ */
80
+ stub(method, implementation) {
81
+ this.#stubs.set(method, implementation);
82
+ return this;
83
+ }
84
+ /** Drop a {@link stub}, so the method runs the real in-memory library again. */
85
+ unstub(method) {
86
+ this.#stubs.delete(method);
87
+ return this;
88
+ }
89
+ /** Throws unless `method` was called (and, with `predicate`, called with matching args). */
90
+ assertCalled(method, predicate) {
91
+ if (this.#matching(method, predicate).length > 0)
92
+ return;
93
+ throw new AssertionError({
94
+ message: predicate
95
+ ? `Expected media.library.${method} to be called with matching arguments`
96
+ : `Expected media.library.${method} to be called`,
97
+ actual: this.calls[method],
98
+ });
99
+ }
100
+ /** Throws if `method` was called (or, with `predicate`, called with matching args). */
101
+ assertNotCalled(method, predicate) {
102
+ const matching = this.#matching(method, predicate);
103
+ if (matching.length === 0)
104
+ return;
105
+ throw new AssertionError({
106
+ message: predicate
107
+ ? `Expected media.library.${method} not to be called with matching arguments`
108
+ : `Expected media.library.${method} not to be called`,
109
+ actual: matching,
110
+ });
111
+ }
112
+ /** Same as `media.restore()`, but a no-op once a newer fake has replaced this one. */
113
+ restore() {
114
+ this.#onRestore();
115
+ }
116
+ #matching(method, predicate) {
117
+ const calls = this.calls[method];
118
+ return predicate ? calls.filter((args) => predicate(...args)) : calls;
119
+ }
120
+ /**
121
+ * Wrap the library so the recorded methods log their args and honour stubs. A Proxy (rather than
122
+ * a subclass) keeps the library's internal `this.x()` calls on the real object, so only calls
123
+ * made from outside — the app's — are recorded. `for()` runs against the proxy so the binding's
124
+ * `attach`/`list` are recorded too.
125
+ */
126
+ #record(library) {
127
+ const proxy = new Proxy(library, {
128
+ get: (target, prop) => {
129
+ if (prop === 'for') {
130
+ return (ownerType, ownerId) => target.for.call(proxy, ownerType, ownerId);
131
+ }
132
+ if (!isFakeMethod(prop)) {
133
+ // Bound to the real library: its methods read private fields, which a Proxy `this` lacks
134
+ // (e.g. `media.access.image` calls the symbol-keyed `imageOfRecord`).
135
+ const value = Reflect.get(target, prop, target);
136
+ return typeof value === 'function' ? value.bind(target) : value;
137
+ }
138
+ return (...args) => {
139
+ this.calls[prop].push(args);
140
+ const stub = this.#stubs.get(prop);
141
+ if (stub)
142
+ return (async () => stub(...args))();
143
+ return target[prop].apply(target, args);
144
+ };
145
+ },
146
+ });
147
+ return proxy;
148
+ }
149
+ }
150
+ //# sourceMappingURL=media_fake.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"media_fake.js","sourceRoot":"","sources":["../../../src/testing/media_fake.ts"],"names":[],"mappings":"AAAA,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C,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;gBAClE,CAAC;gBACD,OAAO,CAAC,GAAG,IAAe,EAAE,EAAE;oBAC3B,IAAI,CAAC,KAAK,CAAC,IAAI,CAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;oBAC7C,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAA+C,CAAC;oBACjF,IAAI,IAAI;wBAAE,OAAO,CAAC,KAAK,IAAI,EAAE,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE,CAAC;oBAC/C,OAAQ,MAAM,CAAC,IAAI,CAAkC,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;gBAC5E,CAAC,CAAC;YACJ,CAAC;SACF,CAAC,CAAC;QACH,OAAO,KAAK,CAAC;IACf,CAAC;CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adonis-agora/media",
3
- "version": "0.28.1",
3
+ "version": "0.29.0",
4
4
  "description": "Media-library for AdonisJS — owner collections (MIME whitelist, single-file replace, ordering), image conversions (eager/lazy), pluggable content transformers (HLS video via mediabunny, metadata probe, image blur-up placeholder), and column attachments, all on top of @adonisjs/drive. Pluggable MediaStore (in-memory + Lucid) and ImageProcessor (sharp). Part of the Agora ecosystem.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -174,7 +174,7 @@
174
174
  "@adonisjs/core": "7.6.0",
175
175
  "@adonisjs/drive": "4.0.0",
176
176
  "@adonisjs/lucid": "22.4.2",
177
- "@aws-sdk/client-s3": "3.1156.0",
177
+ "@aws-sdk/client-s3": "3.1161.0",
178
178
  "@smithy/util-stream": "4.8.2",
179
179
  "@tanstack/intent": "0.5.6",
180
180
  "@types/better-sqlite3": "9.6.0",
@@ -182,7 +182,7 @@
182
182
  "aws-sdk-client-mock": "4.1.0",
183
183
  "better-sqlite3": "13.0.3",
184
184
  "luxon": "3.7.2",
185
- "mediabunny": "1.62.1",
185
+ "mediabunny": "1.65.0",
186
186
  "sharp": "0.35.5",
187
187
  "tempura": "0.4.1",
188
188
  "typescript": "7.0.2",