Skip to content

Commit ad50314

Browse files
mifiMurderlon
andauthored
allow getSafeFileId to accept UppyFile (#6048)
fixes #6033 also convert InternalMetadata to interface (interface is preferred when possible) <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Broaden `getSafeFileId` to accept `UppyFile` and extend types by converting `InternalMetadata` to an interface with optional `relativePath`. > > - **utils**: > - **`getSafeFileId`**: Broadens parameter via new `SafeFileIdBasis` so it can accept `UppyFile`; call site logic unchanged. > - **Types**: Convert `InternalMetadata` to an interface and add optional `relativePath`; propagate through `UppyFile`/`generateFileID` typings. > - **Changeset**: Adds patch entry for `@uppy/utils`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 133240f. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Merlijn Vos <[email protected]>
1 parent 2e14f15 commit ad50314

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

.changeset/tender-yaks-shave.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@uppy/utils": patch
3+
---
4+
5+
Allow `getSafeFileId` to accept `UppyFile`

packages/@uppy/utils/src/UppyFile.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ export type Meta = Record<string, unknown>
44

55
export type Body = Record<string, unknown>
66

7-
export type InternalMetadata = { name: string; type?: string }
7+
export interface InternalMetadata {
8+
name: string
9+
type?: string
10+
relativePath?: string
11+
}
812

913
// for better readability instead of using Record<string, something>
1014
export type UppyFileId = string

packages/@uppy/utils/src/generateFileID.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,16 @@ function hasFileStableId<M extends Meta, B extends Body>(
7777
return stableIdProviders.has(file.remote.provider!)
7878
}
7979

80+
export type SafeFileIdBasis<M extends Meta, B extends Body> = Partial<
81+
Pick<UppyFile<M, B>, 'id' | 'type'>
82+
> &
83+
(
84+
| Pick<RemoteUppyFile<M, B>, 'isRemote' | 'remote' | 'data'>
85+
| Pick<LocalUppyFile<M, B>, 'isRemote' | 'data'>
86+
) & { meta?: { relativePath?: unknown } | undefined }
87+
8088
export function getSafeFileId<M extends Meta, B extends Body>(
81-
file: Partial<Pick<UppyFile<M, B>, 'id' | 'type'>> &
82-
Pick<UppyFile<M, B>, 'data'> &
83-
(
84-
| Pick<RemoteUppyFile<M, B>, 'isRemote' | 'remote'>
85-
| Pick<LocalUppyFile<M, B>, 'isRemote'>
86-
) & { meta?: { relativePath?: unknown } | undefined },
89+
file: SafeFileIdBasis<M, B>,
8790
instanceId: string,
8891
): string {
8992
if (hasFileStableId(file)) return file.id!

0 commit comments

Comments
 (0)