@zerotal/media 1.6.3 → 1.7.2

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 (2) hide show
  1. package/api-surface.md +553 -0
  2. package/package.json +5 -4
package/api-surface.md ADDED
@@ -0,0 +1,553 @@
1
+ # @zerotal/media — public API surface
2
+
3
+ <!-- AUTO-GENERATED by scripts/api-surface.ts. Do not edit by hand.
4
+ Run `bun run api:surface` to regenerate after an intentional API change. -->
5
+
6
+ ## . `(./src/index.ts)`
7
+
8
+ class BunImageDriver = {
9
+ new (maxPixels?: number, maxCropPixels?: number): BunImageDriver
10
+ canEncode: (format: ConversionFormat) => Promise<boolean>
11
+ convert: (bytes: Uint8Array, manipulation: ImageManipulation) => Promise<ImageResult>
12
+ encodableFormats: () => Promise<string[]>
13
+ metadata: (bytes: Uint8Array) => Promise<ImageMetadata | null>
14
+ placeholder: (bytes: Uint8Array) => Promise<string | null>
15
+ readonly name: 'BunImageDriver'
16
+ readonly supportsCrop: true
17
+ }
18
+
19
+ class ConversionRunner = {
20
+ new (driver: ImageDriver, config: MediaConfigShape): ConversionRunner
21
+ run: (media: MediaItem, conversions: ConversionMap) => Promise<{ generated: string[]; failed: Array<{ name: string; reason: string; }>;}>
22
+ runResponsive: (media: MediaItem, widths: number[]) => Promise<ResponsiveImageSet | null>
23
+ }
24
+
25
+ class DefaultPathGenerator = {
26
+ new (prefix?: string): DefaultPathGenerator
27
+ forConversions: (media: MediaItem) => string
28
+ forOriginal: (media: MediaItem) => string
29
+ forResponsiveImages: (media: MediaItem) => string
30
+ }
31
+
32
+ class DisallowedMimeTypeError = {
33
+ new (collection: string, actual: string, allowed: string[]): DisallowedMimeTypeError
34
+ readonly code: string
35
+ readonly context?: Record<string, unknown> | undefined
36
+ readonly status: number
37
+ }
38
+
39
+ class FileTooLargeError = {
40
+ new (collection: string, actual: number, max: number): FileTooLargeError
41
+ readonly code: string
42
+ readonly context?: Record<string, unknown> | undefined
43
+ readonly status: number
44
+ }
45
+
46
+ class MediaAdder = {
47
+ new (owner: MediaOwner, ownerClass: CollectionHost, resolve: SourceResolver): MediaAdder
48
+ toCollection: (collection?: string) => Promise<MediaItem>
49
+ toDisk: (disk: string) => MediaAdder
50
+ usingFileName: (fileName: string) => MediaAdder
51
+ usingName: (name: string) => MediaAdder
52
+ withCustomProperties: (properties: Record<string, unknown>) => MediaAdder
53
+ withOrder: (order: number) => MediaAdder
54
+ }
55
+
56
+ class MediaError = {
57
+ new (message: string, code?: string, status?: number, context?: Record<string, unknown>): MediaError
58
+ readonly code: string
59
+ readonly context?: Record<string, unknown> | undefined
60
+ readonly status: number
61
+ }
62
+
63
+ class MediaFileMissingError = {
64
+ new (path: string, disk: string): MediaFileMissingError
65
+ readonly code: string
66
+ readonly context?: Record<string, unknown> | undefined
67
+ readonly status: number
68
+ }
69
+
70
+ class MediaItem = {
71
+ new (): MediaItem
72
+ static _isFillable: (key: string) => boolean
73
+ static _unscopedQuery: <T extends BaseModel>(this: typeof BaseModel & (new () => T)) => ModelQueryBuilder<T>
74
+ static addGlobalScope: <T extends BaseModel>(this: typeof BaseModel & (new () => T), name: string, callback: GlobalScopeCallback) => void
75
+ static all: <T extends BaseModel>(this: typeof BaseModel & (new () => T)) => Promise<T[]>
76
+ static appends: string[]
77
+ static bulkInsert: <T extends BaseModel>(this: typeof BaseModel & (new () => T), records: InsertPayload<T>[]) => Promise<number>
78
+ static casts?: Record<string, 'boolean' | 'date' | 'datetime' | 'array' | 'integer' | 'json' | 'float' | 'enum' | 'immutable_datetime' | 'encrypted' | 'encrypted:json' | `decimal:${number}` | { get?: (dbValue: unknown) => unknown; set?: (jsValue: unknown) => unknown;} | CastContract<unknown> | undefined>
79
+ static connection?: string
80
+ static count: <T extends BaseModel>(this: typeof BaseModel & (new () => T)) => Promise<number>
81
+ static create: <T extends BaseModel, F extends string = string>(this: (typeof BaseModel & (new () => T)) & { fillable?: readonly F[] | undefined;}, data: FillablePayload<T, F>) => Promise<T>
82
+ static createMany: <T extends BaseModel>(this: typeof BaseModel & (new () => T), records: InsertPayload<T>[]) => Promise<T[]>
83
+ static dispatchesEvents?: Record<string, new (model: unknown) => object>
84
+ static encryptable?: string[]
85
+ static fillable?: readonly string[]
86
+ static find: <T extends BaseModel>(this: typeof BaseModel & (new () => T), id: number | string) => Promise<T | null>
87
+ static findBy: <T extends BaseModel>(this: typeof BaseModel & (new () => T), column: string, value: unknown) => Promise<T | null>
88
+ static findMany: <T extends BaseModel>(this: typeof BaseModel & (new () => T), ids: (number | string)[]) => Promise<T[]>
89
+ static findOrFail: <T extends BaseModel>(this: typeof BaseModel & (new () => T), id: number | string) => Promise<T>
90
+ static findOrNew: <T extends BaseModel>(this: typeof BaseModel & (new () => T), id: number | string) => Promise<T>
91
+ static first: <T extends BaseModel>(this: typeof BaseModel & (new () => T)) => Promise<T | null>
92
+ static firstOrCreate: <T extends BaseModel>(this: typeof BaseModel & (new () => T), search: UpdatePayload<T>, create?: UpdatePayload<T>) => Promise<T>
93
+ static firstOrFail: <T extends BaseModel>(this: typeof BaseModel & (new () => T)) => Promise<T>
94
+ static firstOrNew: <T extends BaseModel>(this: typeof BaseModel & (new () => T), search: UpdatePayload<T>, values?: UpdatePayload<T>) => Promise<T>
95
+ static forOwner: (type: string, id: string | number) => ScopeApplicator
96
+ static forceCreate: <T extends BaseModel>(this: typeof BaseModel & (new () => T), data: Record<string, unknown>) => Promise<T>
97
+ static fromRow: (row: Record<string, unknown>) => BaseModel
98
+ static guarded?: readonly string[]
99
+ static hashable?: string[]
100
+ static hidden: string[]
101
+ static implicitBinding?: boolean
102
+ static implicitBindingKey?: string
103
+ static inCollection: (collection: string) => ScopeApplicator
104
+ static latest: <T extends BaseModel>(this: typeof BaseModel & (new () => T), column?: string) => ModelQueryBuilder<T>
105
+ static loadCount: <T extends BaseModel>(this: typeof BaseModel, models: T[], relations: string | string[]) => Promise<T[]>
106
+ static massPrune: boolean
107
+ static observe: <T extends BaseModel>(this: typeof BaseModel & (new () => T), ObserverClass: new () => ModelObserver<T>) => void
108
+ static oldest: <T extends BaseModel>(this: typeof BaseModel & (new () => T), column?: string) => ModelQueryBuilder<T>
109
+ static orderBy: <T extends BaseModel>(this: typeof BaseModel & (new () => T), column: string, direction?: OrderDirection) => ModelQueryBuilder<T>
110
+ static ordered: () => ScopeApplicator
111
+ static paginate: <T extends BaseModel>(this: typeof BaseModel & (new () => T), perPage?: number, page?: number, pageName?: string) => Promise<PaginateResult<T>>
112
+ static primaryKey: string
113
+ static prunable?: <T extends BaseModel>(this: typeof BaseModel & (new () => T)) => ModelQueryBuilder<T>
114
+ static prune: <T extends BaseModel>(this: typeof BaseModel & (new () => T), chunkSize?: number) => Promise<number>
115
+ static query: <T extends BaseModel>(this: typeof BaseModel & (new () => T)) => ModelQueryBuilder<T>
116
+ static reactiveCasts: boolean
117
+ static registerConnection: (name: string, conn: SQLInstance, dialect?: Dialect) => void
118
+ static reguard: () => void
119
+ static removeGlobalScope: <T extends BaseModel>(this: typeof BaseModel & (new () => T), name: string) => void
120
+ static saveMany: <T extends BaseModel>(this: typeof BaseModel & (new () => T), models: T[]) => Promise<T[]>
121
+ static scope: <Args extends unknown[]>(fn: (query: QueryBuilder, ...args: Args) => void) => (...args: Args) => ScopeApplicator
122
+ static softDeletes: boolean
123
+ static table: string
124
+ static timestamps: boolean
125
+ static unguard: () => void
126
+ static unguarded: boolean
127
+ static updateOrCreate: <T extends BaseModel>(this: typeof BaseModel & (new () => T), search: UpdatePayload<T>, values?: UpdatePayload<T>) => Promise<T>
128
+ static upsert: <T extends BaseModel>(this: typeof BaseModel & (new () => T), data: InsertPayload<T>, conflictKeys: (keyof T & string)[], updateCols?: (keyof T & string)[]) => Promise<void>
129
+ static using: Compose
130
+ static visible: string[]
131
+ static where: { <T extends BaseModel>(this: typeof BaseModel & (new () => T), column: string, value: unknown): ModelQueryBuilder<T>; <T extends BaseModel>(this: typeof BaseModel & (new () => T), column: string, operator: WhereOperator, value: unknown): ModelQueryBuilder<T>;}
132
+ static whereIn: <T extends BaseModel>(this: typeof BaseModel & (new () => T), column: string, values: unknown[]) => ModelQueryBuilder<T>
133
+ static withoutGuard: <T>(callback: () => T | Promise<T>) => Promise<T>
134
+ static withoutTimestamps: <R>(callback: () => Promise<R> | R) => Promise<R>
135
+ $dirty: () => Record<string, unknown>
136
+ append: (...keys: string[]) => MediaItem
137
+ associate: (relation: string, model: BaseModel) => MediaItem
138
+ bytes: () => Promise<Uint8Array>
139
+ collectionName: string
140
+ conversion: (name: string) => GeneratedConversion | null
141
+ conversionNames: () => string[]
142
+ conversionsDisk: string | null
143
+ createdAt?: Date
144
+ customProperties: Record<string, unknown>
145
+ decrement: (column: 'id' | 'name' | 'size' | 'createdAt' | 'updatedAt' | '__isZerotalModel' | 'fill' | 'forceFill' | 'save' | 'delete' | 'load' | 'loadMissing' | 'fresh' | 'refresh' | 'replicate' | 'touch' | 'is' | 'isNot' | 'increment' | 'decrement' | 'loadCount' | 'loadSum' | 'loadAvg' | 'loadMin' | 'loadMax' | 'makeHidden' | 'makeVisible' | 'append' | 'associate' | 'dissociate' | 'isDirty' | '$dirty' | 'markDirty' | 'toJSON' | 'modelType' | 'modelId' | 'uuid' | 'collectionName' | 'fileName' | 'mimeType' | 'disk' | 'conversionsDisk' | 'manipulations' | 'customProperties' | 'generatedConversions' | 'responsiveImages' | 'orderColumn' | 'originalDisk' | 'derivedDisk' | 'getPath' | 'getResponsivePath' | 'getUrl' | 'getTemporaryUrl' | 'hasConversion' | 'conversion' | 'conversionNames' | 'responsiveSet' | 'srcset' | 'placeholder' | 'getCustomProperty' | 'setCustomProperty' | 'forgetCustomProperty' | 'bytes' | 'fileExists' | 'deleteFiles', amount?: number) => Promise<MediaItem>
146
+ delete: () => Promise<void>
147
+ deleteFiles: () => Promise<void>
148
+ derivedDisk: () => StorageDriver
149
+ disk: string
150
+ dissociate: (relation: string) => MediaItem
151
+ fileExists: () => Promise<boolean>
152
+ fileName: string
153
+ fill: (data: Partial<InsertPayload<MediaItem>>) => MediaItem
154
+ forceFill: (data: Record<string, unknown>) => MediaItem
155
+ forgetCustomProperty: (key: string) => MediaItem
156
+ fresh: () => Promise<MediaItem>
157
+ generatedConversions: Record<string, GeneratedConversion>
158
+ getCustomProperty: { (key: string): unknown; <T>(key: string, fallback: T): T;}
159
+ getPath: (conversion?: string) => string
160
+ getResponsivePath: (width: number) => string
161
+ getTemporaryUrl: (expiresInSeconds?: number, conversion?: string) => Promise<string>
162
+ getUrl: (conversion?: string) => string
163
+ hasConversion: (name: string) => boolean
164
+ id: number
165
+ increment: (column: 'id' | 'name' | 'size' | 'createdAt' | 'updatedAt' | '__isZerotalModel' | 'fill' | 'forceFill' | 'save' | 'delete' | 'load' | 'loadMissing' | 'fresh' | 'refresh' | 'replicate' | 'touch' | 'is' | 'isNot' | 'increment' | 'decrement' | 'loadCount' | 'loadSum' | 'loadAvg' | 'loadMin' | 'loadMax' | 'makeHidden' | 'makeVisible' | 'append' | 'associate' | 'dissociate' | 'isDirty' | '$dirty' | 'markDirty' | 'toJSON' | 'modelType' | 'modelId' | 'uuid' | 'collectionName' | 'fileName' | 'mimeType' | 'disk' | 'conversionsDisk' | 'manipulations' | 'customProperties' | 'generatedConversions' | 'responsiveImages' | 'orderColumn' | 'originalDisk' | 'derivedDisk' | 'getPath' | 'getResponsivePath' | 'getUrl' | 'getTemporaryUrl' | 'hasConversion' | 'conversion' | 'conversionNames' | 'responsiveSet' | 'srcset' | 'placeholder' | 'getCustomProperty' | 'setCustomProperty' | 'forgetCustomProperty' | 'bytes' | 'fileExists' | 'deleteFiles', amount?: number) => Promise<MediaItem>
166
+ is: (other: BaseModel | null | undefined) => boolean
167
+ isDirty: (column?: string) => boolean
168
+ isNot: (other: BaseModel | null | undefined) => boolean
169
+ load: (relations: string[]) => Promise<MediaItem>
170
+ loadAvg: (relation: string, column: string) => Promise<MediaItem>
171
+ loadCount: (relations: string | string[]) => Promise<MediaItem>
172
+ loadMax: (relation: string, column: string) => Promise<MediaItem>
173
+ loadMin: (relation: string, column: string) => Promise<MediaItem>
174
+ loadMissing: (relations: string[]) => Promise<MediaItem>
175
+ loadSum: (relation: string, column: string) => Promise<MediaItem>
176
+ makeHidden: (...keys: string[]) => MediaItem
177
+ makeVisible: (...keys: string[]) => MediaItem
178
+ manipulations: Record<string, unknown>
179
+ markDirty: (property: keyof MediaItem) => MediaItem
180
+ mimeType: string | null
181
+ modelId: string
182
+ modelType: string
183
+ name: string
184
+ orderColumn: number | null
185
+ originalDisk: () => StorageDriver
186
+ placeholder: string | null
187
+ readonly __isZerotalModel: true
188
+ refresh: () => Promise<MediaItem>
189
+ replicate: (except?: string[]) => MediaItem
190
+ responsiveImages: Record<string, never> | ResponsiveImageSet
191
+ responsiveSet: () => ResponsiveImageSet
192
+ save: () => Promise<MediaItem>
193
+ setCustomProperty: (key: string, value: unknown) => MediaItem
194
+ size: number
195
+ srcset: () => string
196
+ toJSON: () => Record<string, unknown>
197
+ touch: () => Promise<MediaItem>
198
+ updatedAt?: Date
199
+ uuid: string
200
+ }
201
+
202
+ class MediaManager = {
203
+ new (config: MediaConfigShape, driver: ImageDriver): MediaManager
204
+ clean: (options?: { dryRun?: boolean;}) => Promise<CleanReport>
205
+ readonly config: MediaConfigShape
206
+ readonly driver: ImageDriver
207
+ regenerate: (media: MediaItem, ownerClass: CollectionHost, only?: string[]) => Promise<string[]>
208
+ runner: () => ConversionRunner
209
+ }
210
+
211
+ class MediaProvider = {
212
+ new (app: Application): MediaProvider
213
+ static dependsOn?: (new (app: Application) => ServiceProvider)[]
214
+ static environments: AppEnvironment[]
215
+ static priority?: number
216
+ static provides: readonly ['media']
217
+ devProcesses: () => DevProcessDefinition[]
218
+ doctorChecks: () => DoctorCheck[]
219
+ onBooted: () => Promise<void>
220
+ onBooting: () => Promise<void>
221
+ onRegister: () => void
222
+ onRequestProcessed: (_ctx: HttpContext) => Promise<void>
223
+ onRequestReceived: (_ctx: HttpContext) => Promise<void>
224
+ onResponseSent: (_ctx: HttpContext) => Promise<void>
225
+ onStarted: () => Promise<void>
226
+ onStarting: () => Promise<void>
227
+ onStopped: () => Promise<void>
228
+ onStopping: () => Promise<void>
229
+ replContext: () => Record<string, unknown>
230
+ }
231
+
232
+ class RasterFormatError = {
233
+ new (detail: string): RasterFormatError
234
+ readonly code: string
235
+ readonly context?: Record<string, unknown> | undefined
236
+ readonly status: number
237
+ }
238
+
239
+ class SharpImageDriver = {
240
+ new (): SharpImageDriver
241
+ canEncode: (format: ConversionFormat) => Promise<boolean>
242
+ convert: (bytes: Uint8Array, manipulation: ImageManipulation) => Promise<ImageResult>
243
+ metadata: (bytes: Uint8Array) => Promise<ImageMetadata | null>
244
+ placeholder: (bytes: Uint8Array) => Promise<string | null>
245
+ readonly name: 'SharpImageDriver'
246
+ readonly supportsCrop: true
247
+ }
248
+
249
+ class UnknownCollectionError = {
250
+ new (model: string, collection: string, known: string[]): UnknownCollectionError
251
+ readonly code: string
252
+ readonly context?: Record<string, unknown> | undefined
253
+ readonly status: number
254
+ }
255
+
256
+ class UnsavedOwnerError = {
257
+ new (model: string): UnsavedOwnerError
258
+ readonly code: string
259
+ readonly context?: Record<string, unknown> | undefined
260
+ readonly status: number
261
+ }
262
+
263
+ class UnsupportedFormatError = {
264
+ new (format: string, available: string[]): UnsupportedFormatError
265
+ readonly code: string
266
+ readonly context?: Record<string, unknown> | undefined
267
+ readonly status: number
268
+ }
269
+
270
+ class UnsupportedManipulationError = {
271
+ new (driver: string, what: string, fix: string): UnsupportedManipulationError
272
+ readonly code: string
273
+ readonly context?: Record<string, unknown> | undefined
274
+ readonly status: number
275
+ }
276
+
277
+ const CONVERTIBLE_MIME_TYPES = ReadonlySet<string>
278
+
279
+ const FORMAT_EXTENSION = Readonly<Record<ConversionFormat, string>>
280
+
281
+ const FORMAT_MIME = Readonly<Record<ConversionFormat, string>>
282
+
283
+ const MediaFake = { all(owner: { id: number | string; constructor: { name: string; }; }): Promise<MediaItem[]>; inCollection(owner: { id: number | string; constructor: { name: string; }; }, collection: string): Promise<MediaItem[]>; assertHas(owner: { id: number | string; constructor: { name: string; }; }, collection: string): Promise<void>; assertMissing(owner: { id: number | string; constructor: { name: string; }; }, collection: string): Promise<void>; assertCount(owner: { id: number | string; constructor: { name: string; }; }, collection: string, count: number): Promise<void>; assertConversion(owner: { id: number | string; constructor: { name: string; }; }, collection: string, conversion: string): Promise<void>;}
284
+
285
+ const MediaLibrary = MediaManager
286
+
287
+ const mediaSchemaConcern = ConcernDescriptor
288
+
289
+ function applyRetentionRules = (modelType: string, modelId: number | string, collection: string, definition: CollectionDefinition, justAdded: MediaItem) => Promise<void>
290
+
291
+ function collectionNames = (host: CollectionHost) => string[]
292
+
293
+ function defaultDiskName = () => string
294
+
295
+ function diskFor = (name?: string | null) => StorageDriver
296
+
297
+ function dispatchConversions = (mediaId: number, conversions: string[]) => Promise<void>
298
+
299
+ function fromDisk = (path: string, disk?: string) => SourceResolver
300
+
301
+ function fromPath = (path: string) => SourceResolver
302
+
303
+ function fromUrl = (url: string, maxBytes: number) => SourceResolver
304
+
305
+ function fromValue = (source: MediaSource, fileName?: string) => SourceResolver
306
+
307
+ function hasCollection = (host: CollectionHost, name: string) => boolean
308
+
309
+ function isConvertible = (mimeType: string | null | undefined) => boolean
310
+
311
+ function isQueueAvailable = () => boolean
312
+
313
+ function Media = <TBase extends Constructor>(Base: TBase) => { new (...args: any[]): MediaModel; prototype: Media<any>.MediaModel; mediaCollections: MediaCollections;} & TBase
314
+
315
+ function MediaConfig = (options?: Partial<MediaConfigShape>) => MediaConfigShape
316
+
317
+ function mediaDefaults = () => MediaConfigShape
318
+
319
+ function pathGenerator = () => PathGenerator
320
+
321
+ function resolveCollection = (host: CollectionHost, name: string) => CollectionDefinition
322
+
323
+ function setPathGenerator = (generator: PathGenerator) => void
324
+
325
+ interface CleanReport = {
326
+ danglingConversions: { mediaId: number; conversion: string;}[]
327
+ deletedRows: number[]
328
+ orphanedRows: number[]
329
+ }
330
+
331
+ interface CollectionDefinition = {
332
+ accepts?: string[]
333
+ conversions?: ConversionMap
334
+ conversionsDisk?: string
335
+ disk?: string
336
+ fallbackPath?: string
337
+ fallbackUrl?: string
338
+ maxSize?: number
339
+ onlyKeepLatest?: number
340
+ responsive?: boolean | number[]
341
+ single?: boolean
342
+ }
343
+
344
+ interface CollectionHost = {
345
+ mediaCollections?: MediaCollections
346
+ name: string
347
+ }
348
+
349
+ interface ConversionDefinition = {
350
+ allowEnlargement?: boolean
351
+ fit?: ConversionFit
352
+ format?: ConversionFormat
353
+ height?: number
354
+ quality?: number
355
+ queued?: boolean
356
+ rotate?: number
357
+ width?: number
358
+ }
359
+
360
+ interface GeneratedConversion = {
361
+ fileName: string
362
+ generatedAt: string
363
+ height: number
364
+ mimeType: string
365
+ size: number
366
+ width: number
367
+ }
368
+
369
+ interface ImageDriver = {
370
+ canEncode: (format: ConversionFormat) => Promise<boolean>
371
+ convert: (bytes: Uint8Array, manipulation: ImageManipulation) => Promise<ImageResult>
372
+ metadata: (bytes: Uint8Array) => Promise<ImageMetadata | null>
373
+ placeholder: (bytes: Uint8Array) => Promise<string | null>
374
+ readonly name: string
375
+ readonly supportsCrop: boolean
376
+ }
377
+
378
+ interface ImageManipulation = {
379
+ fit?: ConversionFit
380
+ format: ConversionFormat
381
+ height?: number
382
+ quality?: number
383
+ rotate?: number
384
+ width?: number
385
+ withoutEnlargement?: boolean
386
+ }
387
+
388
+ interface ImageMetadata = {
389
+ format: string
390
+ height: number
391
+ width: number
392
+ }
393
+
394
+ interface ImageResult = {
395
+ bytes: Uint8Array<ArrayBufferLike>
396
+ format: ConversionFormat
397
+ height: number
398
+ mimeType: string
399
+ width: number
400
+ }
401
+
402
+ interface MediaConfigShape = {
403
+ allowHostFormats: boolean
404
+ autoCreateTable: boolean
405
+ conversionsDisk: string
406
+ disk: string
407
+ driver: 'bun' | 'sharp'
408
+ format: SafeConversionFormat
409
+ maxConversionInputSize: number
410
+ quality: number
411
+ queue: string
412
+ queueConversions: boolean
413
+ responsivePlaceholder: boolean
414
+ responsiveWidths: number[]
415
+ table: string
416
+ }
417
+
418
+ interface MediaOwner = {
419
+ id: string | number
420
+ readonly constructor: { name: string;}
421
+ }
422
+
423
+ interface PathGenerator = {
424
+ forConversions: (media: MediaItem) => string
425
+ forOriginal: (media: MediaItem) => string
426
+ forResponsiveImages: (media: MediaItem) => string
427
+ }
428
+
429
+ interface PendingMediaMeta = {
430
+ customProperties?: Record<string, unknown>
431
+ disk?: string
432
+ name?: string
433
+ order?: number
434
+ }
435
+
436
+ interface ResolvedSource = {
437
+ bytes: Uint8Array<ArrayBufferLike>
438
+ originalName: string
439
+ }
440
+
441
+ interface ResponsiveImage = {
442
+ fileName: string
443
+ height: number
444
+ width: number
445
+ }
446
+
447
+ interface ResponsiveImageSet = {
448
+ images: ResponsiveImage[]
449
+ placeholder?: string
450
+ }
451
+
452
+ type ConversionFit = 'fill' | 'inside' | 'cover'
453
+
454
+ type ConversionFormat = SafeConversionFormat | 'avif' | 'heic'
455
+
456
+ type ConversionMap = { [x: string]: ConversionDefinition;}
457
+
458
+ type MediaCollections = { [x: string]: CollectionDefinition | (() => CollectionDefinition);}
459
+
460
+ type MediaSource = ArrayBuffer | Blob | UploadedFile | File | Uint8Array<ArrayBufferLike>
461
+
462
+ type SafeConversionFormat = 'jpeg' | 'png' | 'webp'
463
+
464
+ type SourceResolver = () => Promise<ResolvedSource>
465
+
466
+ ## ./commands `(./src/commands/index.ts)`
467
+
468
+ class MediaCleanCommand = {
469
+ new (): MediaCleanCommand
470
+ static args: ArgDef[]
471
+ static commandName: string
472
+ static description: string
473
+ static flags: FlagDef[]
474
+ static needsApp: boolean
475
+ _readLine: () => Promise<string>
476
+ _writer: OutputWriter
477
+ app: unknown
478
+ args: Record<string, string>
479
+ ask: (question: string, defaultValue?: string) => Promise<string>
480
+ choice: (question: string, options: string[]) => Promise<string>
481
+ confirm: (question: string, defaultValue?: boolean) => Promise<boolean>
482
+ dim: (msg: string) => void
483
+ error: (msg: string) => void
484
+ flags: Record<string, string | number | boolean>
485
+ info: (msg: string) => void
486
+ line: (msg: string) => void
487
+ newLine: () => void
488
+ run: () => Promise<void>
489
+ secret: (question: string) => Promise<string>
490
+ section: (title: string) => void
491
+ table: (rows: [string, string][], indent?: number) => void
492
+ warn: (msg: string) => void
493
+ write: (msg: string) => void
494
+ }
495
+
496
+ class MediaRegenerateCommand = {
497
+ new (): MediaRegenerateCommand
498
+ static args: ArgDef[]
499
+ static commandName: string
500
+ static description: string
501
+ static flags: FlagDef[]
502
+ static needsApp: boolean
503
+ _readLine: () => Promise<string>
504
+ _writer: OutputWriter
505
+ app: unknown
506
+ args: Record<string, string>
507
+ ask: (question: string, defaultValue?: string) => Promise<string>
508
+ choice: (question: string, options: string[]) => Promise<string>
509
+ confirm: (question: string, defaultValue?: boolean) => Promise<boolean>
510
+ dim: (msg: string) => void
511
+ error: (msg: string) => void
512
+ flags: Record<string, string | number | boolean>
513
+ info: (msg: string) => void
514
+ line: (msg: string) => void
515
+ newLine: () => void
516
+ run: () => Promise<void>
517
+ secret: (question: string) => Promise<string>
518
+ section: (title: string) => void
519
+ table: (rows: [string, string][], indent?: number) => void
520
+ warn: (msg: string) => void
521
+ write: (msg: string) => void
522
+ }
523
+
524
+ ## ./testing `(./src/testing.ts)`
525
+
526
+ function diskNameFor = (name: string | null | undefined, fallback: string) => string
527
+
528
+ function mediaState = () => MediaState
529
+
530
+ function ownerClassFor = (modelType: string) => CollectionHost | null
531
+
532
+ function partitionConversions = (conversions: ConversionMap | undefined, queueAvailable: boolean) => { inline: ConversionMap; queued: ConversionMap;}
533
+
534
+ function performConversions = (mediaId: number, conversions: string[]) => Promise<{ generated: string[]; failed: Array<{ name: string; reason: string; }>;}>
535
+
536
+ function resetMediaState = () => void
537
+
538
+ function setConversionDispatcher = (dispatcher: ConversionDispatcher | null) => void
539
+
540
+ function setDefaultDiskName = (name: string | null) => void
541
+
542
+ function setDiskResolver = (resolver: DiskResolver | null) => void
543
+
544
+ function setMediaState = (state: MediaState) => void
545
+
546
+ interface MediaState = {
547
+ config: MediaConfigShape
548
+ driver: ImageDriver
549
+ }
550
+
551
+ type ConversionDispatcher = (mediaId: number, conversions: string[]) => Promise<void>
552
+
553
+ type DiskResolver = (name?: string) => StorageDriver
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zerotal/media",
3
- "version": "1.6.3",
3
+ "version": "1.7.2",
4
4
  "license": "MIT",
5
5
  "maturity": "stable",
6
6
  "private": false,
@@ -14,6 +14,7 @@
14
14
  },
15
15
  "files": [
16
16
  "CHANGELOG.md",
17
+ "api-surface.md",
17
18
  "src",
18
19
  "!src/**/*.test.ts",
19
20
  "!src/**/*.test.tsx",
@@ -31,8 +32,8 @@
31
32
  "typecheck": "tsc --noEmit"
32
33
  },
33
34
  "dependencies": {
34
- "@zerotal/core": "1.6.3",
35
- "@zerotal/orm": "1.6.3"
35
+ "@zerotal/core": "1.7.2",
36
+ "@zerotal/orm": "1.7.2"
36
37
  },
37
38
  "peerDependencies": {
38
39
  "@zerotal/queue": "^1.0.0",
@@ -47,7 +48,7 @@
47
48
  }
48
49
  },
49
50
  "devDependencies": {
50
- "@zerotal/queue": "1.6.3",
51
+ "@zerotal/queue": "1.7.2",
51
52
  "sharp": "^0.34.0",
52
53
  "typescript": "^5.8.0"
53
54
  },