Skip to content

Commit ecbc91c

Browse files
committed
fix: address npm ingest PR review
Signed-off-by: anilb <epipav@gmail.com>
1 parent aabcd85 commit ecbc91c

2 files changed

Lines changed: 14 additions & 10 deletions

File tree

services/apps/packages_worker/src/npm/normalize.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
6163
export 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

7882
function clean(s: string): string {

services/libs/data-access-layer/src/packages/maintainers.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ export async function upsertNpmMaintainers(
1414
): Promise<string[]> {
1515
const changed = new Set<string>()
1616

17-
// Lock maintainers rows in a deterministic (username) order so concurrent ingest lanes
18-
// enriching different packages that share maintainers can't acquire the row locks in cyclic order
19-
const ordered = [...maintainers].sort((a, b) => a.username.localeCompare(b.username))
17+
const ordered = [...maintainers].sort((a, b) =>
18+
a.username < b.username ? -1 : a.username > b.username ? 1 : 0,
19+
)
2020

2121
for (const m of ordered) {
2222
const row: { changed_fields: string[] } = await qx.selectOne(

0 commit comments

Comments
 (0)