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
133240fc0f. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

---------

Co-authored-by: Merlijn Vos <merlijn@soverin.net>
This commit is contained in:
Mikael Finstad 2025-11-03 20:04:57 +08:00 committed by GitHub
parent 2e14f15e11
commit ad50314c50
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 19 additions and 7 deletions

View file

@ -0,0 +1,5 @@
---
"@uppy/utils": patch
---
Allow `getSafeFileId` to accept `UppyFile`

View file

@ -4,7 +4,11 @@ export type Meta = Record<string, unknown>
export type Body = Record<string, unknown>
export type InternalMetadata = { name: string; type?: string }
export interface InternalMetadata {
name: string
type?: string
relativePath?: string
}
// for better readability instead of using Record<string, something>
export type UppyFileId = string

View file

@ -77,13 +77,16 @@ function hasFileStableId<M extends Meta, B extends Body>(
return stableIdProviders.has(file.remote.provider!)
}
export type SafeFileIdBasis<M extends Meta, B extends Body> = Partial<
Pick<UppyFile<M, B>, 'id' | 'type'>
> &
(
| Pick<RemoteUppyFile<M, B>, 'isRemote' | 'remote' | 'data'>
| Pick<LocalUppyFile<M, B>, 'isRemote' | 'data'>
) & { meta?: { relativePath?: unknown } | undefined }
export function getSafeFileId<M extends Meta, B extends Body>(
file: Partial<Pick<UppyFile<M, B>, 'id' | 'type'>> &
Pick<UppyFile<M, B>, 'data'> &
(
| Pick<RemoteUppyFile<M, B>, 'isRemote' | 'remote'>
| Pick<LocalUppyFile<M, B>, 'isRemote'>
) & { meta?: { relativePath?: unknown } | undefined },
file: SafeFileIdBasis<M, B>,
instanceId: string,
): string {
if (hasFileStableId(file)) return file.id!