@@ -56,23 +56,27 @@ export function normalizeLicenses(packument: Packument): string[] {
5656 )
5757}
5858
59- // A version's license is sometimes an object ({ type, url })
60- // or the legacy array form ([{ type, file }, ...]). Passing those raw
59+ // A version's `license` field comes in several shapes: a plain SPDX string ("MIT"),
60+ // an object ({ type, url }), or the legacy array form ([{ type, file }, ...]). Passing those
61+ // raw into a text column would persist objects/arrays, so collapse every shape to a single
62+ // string (OR-joined for the array form) or null. Non-string `type` values are dropped.
6163export function versionLicense ( raw : unknown ) : string | null {
6264 if ( raw == null ) return null
6365 if ( typeof raw === 'string' ) return raw || null
6466 if ( Array . isArray ( raw ) ) {
6567 const types = raw
66- . map ( ( l ) => ( typeof l === 'string' ? l : isLicenseObject ( l ) ? l . type : null ) )
68+ . map ( ( l ) => ( typeof l === 'string' ? l : licenseType ( l ) ) )
6769 . filter ( ( t ) : t is string => Boolean ( t ) )
6870 return types . length ? types . join ( ' OR ' ) : null
6971 }
70- if ( isLicenseObject ( raw ) ) return raw . type ?? null
71- return null
72+ return licenseType ( raw )
7273}
7374
74- function isLicenseObject ( v : unknown ) : v is { type ?: string } {
75- return typeof v === 'object' && v !== null
75+ // Extract a string `type` from a license object, or null if absent/non-string.
76+ function licenseType ( v : unknown ) : string | null {
77+ if ( typeof v !== 'object' || v === null ) return null
78+ const type = ( v as { type ?: unknown } ) . type
79+ return typeof type === 'string' ? type : null
7680}
7781
7882function clean ( s : string ) : string {
0 commit comments