Adjust some types

This commit is contained in:
Josh Perez
2022-07-12 20:37:21 -04:00
committed by GitHub
parent 9ce4b8977d
commit d7307934bc
15 changed files with 223 additions and 175 deletions
+9 -12
View File
@@ -168,13 +168,10 @@ export type AttachmentDraftType =
size: number;
};
export type ThumbnailType = {
height?: number;
width?: number;
url?: string;
contentType: MIME.MIMEType;
path?: string;
data?: Uint8Array;
export type ThumbnailType = Pick<
AttachmentType,
'height' | 'width' | 'url' | 'contentType' | 'path' | 'data'
> & {
// Only used when quote needed to make an in-memory thumbnail
objectUrl?: string;
};
@@ -236,7 +233,7 @@ export async function migrateDataToFileSystem(
// Over time, we can expand this definition to become more narrow, e.g. require certain
// fields, etc.
export function isValid(
rawAttachment?: AttachmentType
rawAttachment?: Pick<AttachmentType, 'data' | 'path'>
): rawAttachment is AttachmentType {
// NOTE: We cannot use `_.isPlainObject` because `rawAttachment` is
// deserialized by protobuf:
@@ -396,14 +393,14 @@ export function hasData(attachment: AttachmentType): boolean {
export function loadData(
readAttachmentData: (path: string) => Promise<Uint8Array>
): (attachment: AttachmentType) => Promise<AttachmentWithHydratedData> {
): (
attachment: Pick<AttachmentType, 'data' | 'path'>
) => Promise<AttachmentWithHydratedData> {
if (!is.function_(readAttachmentData)) {
throw new TypeError("'readAttachmentData' must be a function");
}
return async (
attachment: AttachmentType
): Promise<AttachmentWithHydratedData> => {
return async attachment => {
if (!isValid(attachment)) {
throw new TypeError("'attachment' is not valid");
}