Skip to content
Prev Previous commit
fix: Improve type safety in asset metadata
  validation

  - Replace any type with proper Record<string,
  unknown> | undefined
  - Fix nodeId type check to support both string
  and number types
  - Remove redundant object type checks in type
  guard
  - Remove unused isValidUuidV4 function from
  uuidUtil
  - Simplify metadata validation logic
  • Loading branch information
viva-jinyi committed Oct 23, 2025
commit 4fc9ba4128a615363cc7555fc5b4806b277c19d2
11 changes: 5 additions & 6 deletions src/platform/assets/schemas/assetMetadataSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,21 @@ export interface OutputAssetMetadata extends Record<string, unknown> {
/**
* Type guard to check if metadata is OutputAssetMetadata
*/
export function isOutputAssetMetadata(
metadata: any
function isOutputAssetMetadata(
metadata: Record<string, unknown> | undefined
): metadata is OutputAssetMetadata {
if (!metadata) return false
return (
metadata &&
typeof metadata === 'object' &&
typeof metadata.promptId === 'string' &&
typeof metadata.nodeId === 'string'
(typeof metadata.nodeId === 'string' || typeof metadata.nodeId === 'number')
)
}

/**
* Safely extract output asset metadata
*/
export function getOutputAssetMetadata(
userMetadata: any
userMetadata: Record<string, unknown> | undefined
): OutputAssetMetadata | null {
if (isOutputAssetMetadata(userMetadata)) {
return userMetadata
Expand Down
11 changes: 1 addition & 10 deletions src/utils/uuidUtil.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { validate as uuidValidate, version as uuidVersion } from 'uuid'
import { validate as uuidValidate } from 'uuid'

/**
* UUID utility functions
Expand Down Expand Up @@ -34,15 +34,6 @@ export function isValidUuid(str: string): boolean {
return uuidValidate(str)
}

/**
* Check if a string is a valid UUID v4
* @param str - The string to check
* @returns true if the string is a valid UUID v4
*/
export function isValidUuidV4(str: string): boolean {
return uuidValidate(str) && uuidVersion(str) === 4
}

/**
* Extract prompt ID from asset ID
* Asset ID format: "promptId-nodeId-filename"
Expand Down