import { Insertable, Updateable } from 'kysely'; import { AssetFiles, AssetJobStatus, Assets, Exif } from 'src/db'; import { AssetEntity } from 'src/entities/asset.entity'; import { AssetFileType, AssetOrder, AssetStatus, AssetType } from 'src/enum'; import { AssetSearchOptions, SearchExploreItem } from 'src/interfaces/search.interface'; import { Paginated, PaginationOptions } from 'src/utils/pagination'; export type AssetStats = Record; export interface AssetStatsOptions { isFavorite?: boolean; isArchived?: boolean; isTrashed?: boolean; } export interface LivePhotoSearchOptions { ownerId: string; libraryId?: string | null; livePhotoCID: string; otherAssetId: string; type: AssetType; } export enum WithoutProperty { THUMBNAIL = 'thumbnail', ENCODED_VIDEO = 'encoded-video', EXIF = 'exif', SMART_SEARCH = 'smart-search', DUPLICATE = 'duplicate', FACES = 'faces', SIDECAR = 'sidecar', } export enum WithProperty { SIDECAR = 'sidecar', } export enum TimeBucketSize { DAY = 'DAY', MONTH = 'MONTH', } export interface AssetBuilderOptions { isArchived?: boolean; isFavorite?: boolean; isTrashed?: boolean; isDuplicate?: boolean; albumId?: string; tagId?: string; personId?: string; userIds?: string[]; withStacked?: boolean; exifInfo?: boolean; status?: AssetStatus; assetType?: AssetType; } export interface TimeBucketOptions extends AssetBuilderOptions { size: TimeBucketSize; order?: AssetOrder; } export interface TimeBucketItem { timeBucket: string; count: number; } export interface MonthDay { day: number; month: number; } export interface AssetExploreFieldOptions { maxFields: number; minAssetsPerField: number; } export interface AssetFullSyncOptions { ownerId: string; lastId?: string; updatedUntil: Date; limit: number; } export interface AssetDeltaSyncOptions { userIds: string[]; updatedAfter: Date; limit: number; } export interface AssetUpdateDuplicateOptions { targetDuplicateId: string | null; assetIds: string[]; duplicateIds: string[]; } export interface UpsertFileOptions { assetId: string; type: AssetFileType; path: string; } export interface AssetGetByChecksumOptions { ownerId: string; checksum: Buffer; libraryId?: string; } export type AssetPathEntity = Pick; export interface GetByIdsRelations { exifInfo?: boolean; faces?: { person?: boolean }; files?: boolean; library?: boolean; owner?: boolean; smartSearch?: boolean; stack?: { assets?: boolean }; tags?: boolean; } export interface DuplicateGroup { duplicateId: string; assets: AssetEntity[]; } export interface DayOfYearAssets { yearsAgo: number; assets: AssetEntity[]; } export const IAssetRepository = 'IAssetRepository'; export interface IAssetRepository { create(asset: Insertable): Promise; getByIds(ids: string[], relations?: GetByIdsRelations): Promise; getByIdsWithAllRelations(ids: string[]): Promise; getByDayOfYear(ownerIds: string[], monthDay: MonthDay): Promise; getByChecksum(options: AssetGetByChecksumOptions): Promise; getByChecksums(userId: string, checksums: Buffer[]): Promise; getUploadAssetIdByChecksum(ownerId: string, checksum: Buffer): Promise; getByAlbumId(pagination: PaginationOptions, albumId: string): Paginated; getByDeviceIds(ownerId: string, deviceId: string, deviceAssetIds: string[]): Promise; getByUserId(pagination: PaginationOptions, userId: string, options?: AssetSearchOptions): Paginated; getById(id: string, relations?: GetByIdsRelations): Promise; getWithout(pagination: PaginationOptions, property: WithoutProperty): Paginated; getRandom(userIds: string[], count: number): Promise; getLastUpdatedAssetForAlbumId(albumId: string): Promise; getByLibraryIdAndOriginalPath(libraryId: string, originalPath: string): Promise; deleteAll(ownerId: string): Promise; getAll(pagination: PaginationOptions, options?: AssetSearchOptions): Paginated; getAllByDeviceId(userId: string, deviceId: string): Promise; getLivePhotoCount(motionId: string): Promise; updateAll(ids: string[], options: Updateable): Promise; updateDuplicates(options: AssetUpdateDuplicateOptions): Promise; update(asset: Updateable & { id: string }): Promise; remove(asset: AssetEntity): Promise; findLivePhotoMatch(options: LivePhotoSearchOptions): Promise; getStatistics(ownerId: string, options: AssetStatsOptions): Promise; getTimeBuckets(options: TimeBucketOptions): Promise; getTimeBucket(timeBucket: string, options: TimeBucketOptions): Promise; upsertExif(exif: Insertable): Promise; upsertJobStatus(...jobStatus: Insertable[]): Promise; getAssetIdByCity(userId: string, options: AssetExploreFieldOptions): Promise>; getDuplicates(userId: string): Promise; getAllForUserFullSync(options: AssetFullSyncOptions): Promise; getChangedDeltaSync(options: AssetDeltaSyncOptions): Promise; upsertFile(options: Insertable): Promise; upsertFiles(options: Insertable[]): Promise; }