Skip to content

Commit

Permalink
Add placeholder type
Browse files Browse the repository at this point in the history
  • Loading branch information
etnoy committed Feb 6, 2025
1 parent acc87e8 commit 7034792
Show file tree
Hide file tree
Showing 27 changed files with 59 additions and 264 deletions.
45 changes: 8 additions & 37 deletions server/src/db.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,16 @@
* Please do not edit it manually.
*/

import type { ColumnType } from "kysely";
import type { ColumnType } from 'kysely';

export type ArrayType<T> = ArrayTypeImpl<T> extends (infer U)[]
? U[]
: ArrayTypeImpl<T>;
export type ArrayType<T> = ArrayTypeImpl<T> extends (infer U)[] ? U[] : ArrayTypeImpl<T>;

export type ArrayTypeImpl<T> = T extends ColumnType<infer S, infer I, infer U>
? ColumnType<S[], I[], U[]>
: T[];
export type ArrayTypeImpl<T> = T extends ColumnType<infer S, infer I, infer U> ? ColumnType<S[], I[], U[]> : T[];

export type AssetsStatusEnum = "active" | "deleted" | "trashed";
export type AssetsStatusEnum = 'active' | 'deleted' | 'trashed';

export type Generated<T> = T extends ColumnType<infer S, infer I, infer U>
? ColumnType<S, I | undefined, U>
: ColumnType<T, T | undefined, T>;
export type Generated<T> =
T extends ColumnType<infer S, infer I, infer U> ? ColumnType<S, I | undefined, U> : ColumnType<T, T | undefined, T>;

export type Int8 = ColumnType<string, bigint | number | string, bigint | number | string>;

Expand All @@ -33,7 +28,7 @@ export type JsonPrimitive = boolean | number | string | null;

export type JsonValue = JsonArray | JsonObject | JsonPrimitive;

export type Sourcetype = "exif" | "machine-learning";
export type Sourcetype = 'exif' | 'machine-learning';

export type Timestamp = ColumnType<Date, Date | string, Date | string>;

Expand Down Expand Up @@ -214,20 +209,6 @@ export interface GeodataPlaces {
name: string;
}

export interface GeodataPlacesTmp {
admin1Code: string | null;
admin1Name: string | null;
admin2Code: string | null;
admin2Name: string | null;
alternateNames: string | null;
countryCode: string;
id: number;
latitude: number;
longitude: number;
modificationDate: Timestamp;
name: string;
}

export interface Libraries {
createdAt: Generated<Timestamp>;
deletedAt: Timestamp | null;
Expand Down Expand Up @@ -280,14 +261,6 @@ export interface NaturalearthCountries {
type: string;
}

export interface NaturalearthCountriesTmp {
admin: string;
admin_a3: string;
coordinates: string;
id: Generated<number>;
type: string;
}

export interface Partners {
createdAt: Generated<Timestamp>;
inTimeline: Generated<boolean>;
Expand Down Expand Up @@ -445,14 +418,12 @@ export interface DB {
exif: Exif;
face_search: FaceSearch;
geodata_places: GeodataPlaces;
geodata_places_tmp: GeodataPlacesTmp;
libraries: Libraries;
memories: Memories;
memories_assets_assets: MemoriesAssetsAssets;
migrations: Migrations;
move_history: MoveHistory;
naturalearth_countries: NaturalearthCountries;
naturalearth_countries_tmp: NaturalearthCountriesTmp;
partners: Partners;
person: Person;
sessions: Sessions;
Expand All @@ -467,6 +438,6 @@ export interface DB {
typeorm_metadata: TypeormMetadata;
user_metadata: UserMetadata;
users: Users;
"vectors.pg_vector_index_stat": VectorsPgVectorIndexStat;
'vectors.pg_vector_index_stat': VectorsPgVectorIndexStat;
version_history: VersionHistory;
}
4 changes: 2 additions & 2 deletions server/src/dtos/album.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ export const mapAlbum = (entity: AlbumEntity, withAssets: boolean, auth?: AuthDt
const hasSharedLink = entity.sharedLinks?.length > 0;
const hasSharedUser = sharedUsers.length > 0;

let startDate = assets.at(0)?.localDateTime || undefined;
let endDate = assets.at(-1)?.localDateTime || undefined;
let startDate = assets.at(0)?.localDateTime;
let endDate = assets.at(-1)?.localDateTime;
// Swap dates if start date is greater than end date.
if (startDate && endDate && startDate > endDate) {
[startDate, endDate] = [endDate, startDate];
Expand Down
10 changes: 0 additions & 10 deletions server/src/dtos/asset-response.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,6 @@ const hexOrBufferToBase64 = (encoded: string | Buffer) => {
export function mapAsset(entity: AssetEntity, options: AssetMapOptions = {}): AssetResponseDto {
const { stripMetadata = false, withStack = false } = options;

if (entity.localDateTime === null) {
throw new Error(`Asset ${entity.id} has no localDateTime`);
}
if (entity.fileCreatedAt === null) {
throw new Error(`Asset ${entity.id} has no fileCreatedAt`);
}
if (entity.fileModifiedAt === null) {
throw new Error(`Asset ${entity.id} has no fileModifiedAt`);
}

if (stripMetadata) {
const sanitizedAssetResponse: SanitizedAssetResponseDto = {
id: entity.id,
Expand Down
7 changes: 0 additions & 7 deletions server/src/dtos/asset.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,6 @@ export class AssetStatsResponseDto {
total!: number;
}

export class AssetDatesDto {
dateTimeOriginal!: Date;
timeZone!: string | null;
localDateTime!: Date;
modifyDate!: Date;
}

export const mapStats = (stats: AssetStats): AssetStatsResponseDto => {
return {
images: stats[AssetType.IMAGE],
Expand Down
12 changes: 9 additions & 3 deletions server/src/entities/asset.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ export class AssetEntity {

@Index('idx_asset_file_created_at')
@Column({ type: 'timestamptz', nullable: true, default: null })
fileCreatedAt!: Date | null;
fileCreatedAt!: Date;

@Column({ type: 'timestamptz', nullable: true, default: null })
localDateTime!: Date | null;
localDateTime!: Date;

@Column({ type: 'timestamptz', nullable: true, default: null })
fileModifiedAt!: Date | null;
fileModifiedAt!: Date;

@Column({ type: 'boolean', default: false })
isFavorite!: boolean;
Expand Down Expand Up @@ -180,6 +180,12 @@ export class AssetEntity {
duplicateId!: string | null;
}

export type AssetEntityPlaceholder = AssetEntity & {
fileCreatedAt: Date | null;
fileModifiedAt: Date | null;
localDateTime: Date | null;
};

export function withExif<O>(qb: SelectQueryBuilder<DB, 'assets', O>) {
return qb.leftJoin('exif', 'assets.id', 'exif.assetId').select((eb) => eb.fn.toJson(eb.table('exif')).as('exifInfo'));
}
Expand Down
3 changes: 0 additions & 3 deletions server/src/queries/activity.repository.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ from
"activity"
left join "assets" on "assets"."id" = "activity"."assetId"
and "assets"."deletedAt" is null
and "assets"."fileCreatedAt" is not null
and "assets"."fileModifiedAt" is not null
and "assets"."localDateTime" is not null
where
"activity"."albumId" = $1
order by
Expand Down
6 changes: 0 additions & 6 deletions server/src/queries/album.repository.sql
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,6 @@ select
where
"albums_assets_assets"."albumsId" = "albums"."id"
and "assets"."deletedAt" is null
and "assets"."fileCreatedAt" is not null
and "assets"."fileModifiedAt" is not null
and "assets"."localDateTime" is not null
order by
"assets"."fileCreatedAt" desc
) as "asset"
Expand Down Expand Up @@ -215,9 +212,6 @@ from
where
"albums"."id" in ($1)
and "assets"."deletedAt" is null
and "assets"."fileCreatedAt" is not null
and "assets"."fileModifiedAt" is not null
and "assets"."localDateTime" is not null
group by
"albums"."id"

Expand Down
21 changes: 1 addition & 20 deletions server/src/queries/asset.repository.sql
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ with
and "asset_files"."type" = $6
)
and "assets"."deletedAt" is null
and "assets"."fileCreatedAt" is not null
and "assets"."fileModifiedAt" is not null
and "assets"."localDateTime" is not null
order by
(assets."localDateTime" at time zone 'UTC')::date desc
limit
Expand Down Expand Up @@ -164,6 +161,7 @@ where
and "isVisible" = $3
and "assets"."fileCreatedAt" is not null
and "assets"."fileModifiedAt" is not null
and "assets"."localDateTime" is not null
and "deletedAt" is null

-- AssetRepository.getLivePhotoCount
Expand Down Expand Up @@ -246,8 +244,6 @@ where
"assets"."sidecarPath" = $1
or "assets"."sidecarPath" is null
)
and "assets"."fileCreatedAt" is not null
and "assets"."fileModifiedAt" is not null
and "assets"."isVisible" = $2
and "deletedAt" is null
order by
Expand All @@ -267,9 +263,6 @@ with
where
"assets"."deletedAt" is null
and "assets"."isVisible" = $2
and "assets"."fileCreatedAt" is not null
and "assets"."fileModifiedAt" is not null
and "assets"."localDateTime" is not null
)
select
"timeBucket",
Expand Down Expand Up @@ -310,9 +303,6 @@ where
)
and "assets"."deletedAt" is null
and "assets"."isVisible" = $2
and "assets"."fileCreatedAt" is not null
and "assets"."fileModifiedAt" is not null
and "assets"."localDateTime" is not null
and date_trunc($3, "localDateTime" at time zone 'UTC') at time zone 'UTC' = $4
order by
"assets"."localDateTime" desc
Expand All @@ -339,9 +329,6 @@ with
and "assets"."duplicateId" is not null
and "assets"."deletedAt" is null
and "assets"."isVisible" = $2
and "assets"."fileCreatedAt" is not null
and "assets"."fileModifiedAt" is not null
and "assets"."localDateTime" is not null
group by
"assets"."duplicateId"
),
Expand Down Expand Up @@ -399,8 +386,6 @@ from
where
"ownerId" = $2::uuid
and "isVisible" = $3
and "assets"."fileCreatedAt" is not null
and "assets"."fileModifiedAt" is not null
and "isArchived" = $4
and "type" = $5
and "deletedAt" is null
Expand Down Expand Up @@ -430,8 +415,6 @@ from
where
"assets"."ownerId" = $1::uuid
and "isVisible" = $2
and "assets"."fileCreatedAt" is not null
and "assets"."fileModifiedAt" is not null
and "updatedAt" <= $3
and "assets"."id" > $4
order by
Expand Down Expand Up @@ -462,8 +445,6 @@ from
where
"assets"."ownerId" = any ($1::uuid[])
and "isVisible" = $2
and "assets"."fileCreatedAt" is not null
and "assets"."fileModifiedAt" is not null
and "updatedAt" > $3
limit
$4
6 changes: 0 additions & 6 deletions server/src/queries/memory.repository.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ select
where
"memories_assets_assets"."memoriesId" = "memories"."id"
and "assets"."deletedAt" is null
and "assets"."fileCreatedAt" is not null
and "assets"."fileModifiedAt" is not null
and "assets"."localDateTime" is not null
) as agg
) as "assets"
from
Expand Down Expand Up @@ -59,9 +56,6 @@ select
where
"memories_assets_assets"."memoriesId" = "memories"."id"
and "assets"."deletedAt" is null
and "assets"."fileCreatedAt" is not null
and "assets"."fileModifiedAt" is not null
and "assets"."localDateTime" is not null
) as agg
) as "assets"
from
Expand Down
6 changes: 0 additions & 6 deletions server/src/queries/person.repository.sql
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,6 @@ from
and "asset_faces"."personId" = $1
and "assets"."isArchived" = $2
and "assets"."deletedAt" is null
and "assets"."fileCreatedAt" is not null
and "assets"."fileModifiedAt" is not null
and "assets"."localDateTime" is not null
and "assets"."livePhotoVideoId" is null

-- PersonRepository.getNumberOfPeople
Expand All @@ -186,9 +183,6 @@ from
inner join "asset_faces" on "asset_faces"."personId" = "person"."id"
inner join "assets" on "assets"."id" = "asset_faces"."assetId"
and "assets"."deletedAt" is null
and "assets"."fileCreatedAt" is not null
and "assets"."fileModifiedAt" is not null
and "assets"."localDateTime" is not null
and "assets"."isArchived" = $2
where
"person"."ownerId" = $3
Expand Down
12 changes: 0 additions & 12 deletions server/src/queries/search.repository.sql
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,6 @@ with
"assets"."ownerId" = any ($2::uuid[])
and "assets"."deletedAt" is null
and "assets"."isVisible" = $3
and "assets"."fileCreatedAt" is not null
and "assets"."fileModifiedAt" is not null
and "assets"."localDateTime" is not null
and "assets"."type" = $4
and "assets"."id" != $5::uuid
order by
Expand Down Expand Up @@ -141,9 +138,6 @@ with
where
"assets"."ownerId" = any ($2::uuid[])
and "assets"."deletedAt" is null
and "assets"."fileCreatedAt" is not null
and "assets"."fileModifiedAt" is not null
and "assets"."localDateTime" is not null
order by
face_search.embedding <=> $3
limit
Expand Down Expand Up @@ -196,9 +190,6 @@ with recursive
and "assets"."isArchived" = $3
and "assets"."type" = $4
and "assets"."deletedAt" is null
and "assets"."fileCreatedAt" is not null
and "assets"."fileModifiedAt" is not null
and "assets"."localDateTime" is not null
order by
"city"
limit
Expand All @@ -224,9 +215,6 @@ with recursive
and "assets"."isArchived" = $8
and "assets"."type" = $9
and "assets"."deletedAt" is null
and "assets"."fileCreatedAt" is not null
and "assets"."fileModifiedAt" is not null
and "assets"."localDateTime" is not null
and "exif"."city" > "cte"."city"
order by
"city"
Expand Down
9 changes: 0 additions & 9 deletions server/src/queries/shared.link.repository.sql
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ from
where
"shared_links"."id" = "shared_link__asset"."sharedLinksId"
and "assets"."deletedAt" is null
and "assets"."fileCreatedAt" is not null
and "assets"."fileModifiedAt" is not null
and "assets"."localDateTime" is not null
order by
"assets"."fileCreatedAt" asc
) as "a" on true
Expand Down Expand Up @@ -68,9 +65,6 @@ from
where
"albums_assets_assets"."assetsId" = "assets"."id"
and "assets"."deletedAt" is null
and "assets"."fileCreatedAt" is not null
and "assets"."fileModifiedAt" is not null
and "assets"."localDateTime" is not null
order by
"assets"."fileCreatedAt" asc
) as "assets" on true
Expand Down Expand Up @@ -119,9 +113,6 @@ from
where
"assets"."id" = "shared_link__asset"."assetsId"
and "assets"."deletedAt" is null
and "assets"."fileCreatedAt" is not null
and "assets"."fileModifiedAt" is not null
and "assets"."localDateTime" is not null
) as "assets" on true
left join lateral (
select
Expand Down
Loading

0 comments on commit 7034792

Please sign in to comment.