import type { CustomTypeSM } from "@/legacy/lib/models/common/CustomType"; import type { Screenshot } from "@/legacy/lib/models/common/Library"; import type { SliceSM } from "@/legacy/lib/models/common/Slice"; // Generics type LocalOrRemote = | LocalAndRemote | LocalOnly | RemoteOnly; type LocalAndRemote = LocalOnly & RemoteOnly; type LocalOnly = { local: L }; type RemoteOnly = { remote: R }; export function hasLocalAndRemote( obj: T, ): obj is T extends LocalAndRemote ? T : never { return "local" in obj && "remote" in obj; } export function hasLocal( obj: T, ): obj is T extends LocalAndRemote | LocalOnly ? T : never { return "local" in obj; } export function hasRemote( obj: T, ): obj is T extends LocalAndRemote | RemoteOnly ? T : never { return "remote" in obj; } export function isRemoteOnly( obj: T, ): obj is T extends RemoteOnly ? T : never { return hasRemote(obj) && !hasLocal(obj); } export function isLocalOnly( obj: T, ): obj is T extends LocalOnly ? T : never { return !hasRemote(obj) && hasLocal(obj); } // Custom Types export type LocalOrRemoteCustomType = LocalOrRemote; export type LocalAndRemoteCustomType = LocalAndRemote; export type LocalOnlyCustomType = LocalOnly; export type RemoteOnlyCustomType = RemoteOnly; // Slices export type LocalOrRemoteSlice = | LocalAndRemoteSlice | LocalOnlySlice | RemoteOnlySlice; export type LocalAndRemoteSlice = LocalAndRemote & { localScreenshots: Partial>; }; export type LocalOnlySlice = LocalOnly & { localScreenshots: Partial>; }; export type RemoteOnlySlice = RemoteOnly & { localScreenshots: Partial>; }; // Models export type LocalOrRemoteModel = LocalOrRemoteCustomType | LocalOrRemoteSlice; export function getModelId( model: LocalOrRemote, ): M["id"] { return hasLocal(model) ? model.local.id : model.remote.id; }