fix(registry): align OCI and RubyGems API behavior and improve npm search result ordering
This commit is contained in:
@@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartregistry',
|
||||
version: '2.8.0',
|
||||
version: '2.8.1',
|
||||
description: 'A composable TypeScript library implementing OCI, NPM, Maven, Cargo, Composer, PyPI, and RubyGems registries for building unified container and package registries'
|
||||
}
|
||||
|
||||
@@ -749,6 +749,22 @@ export class NpmRegistry extends BaseRegistry {
|
||||
this.logger.log('error', 'handleSearch failed', { error: (error as Error).message });
|
||||
}
|
||||
|
||||
// Sort results by relevance: exact match first, then prefix match, then substring match
|
||||
if (text) {
|
||||
const lowerText = text.toLowerCase();
|
||||
results.sort((a, b) => {
|
||||
const aName = a.package.name.toLowerCase();
|
||||
const bName = b.package.name.toLowerCase();
|
||||
const aExact = aName === lowerText ? 0 : 1;
|
||||
const bExact = bName === lowerText ? 0 : 1;
|
||||
if (aExact !== bExact) return aExact - bExact;
|
||||
const aPrefix = aName.startsWith(lowerText) ? 0 : 1;
|
||||
const bPrefix = bName.startsWith(lowerText) ? 0 : 1;
|
||||
if (aPrefix !== bPrefix) return aPrefix - bPrefix;
|
||||
return aName.localeCompare(bName);
|
||||
});
|
||||
}
|
||||
|
||||
// Apply pagination
|
||||
const paginatedResults = results.slice(from, from + size);
|
||||
|
||||
|
||||
@@ -126,7 +126,8 @@ export class OciRegistry extends BaseRegistry {
|
||||
};
|
||||
|
||||
// Route to appropriate handler
|
||||
if (path === '/' || path === '') {
|
||||
// OCI spec: GET /v2/ is the version check endpoint
|
||||
if (path === '/' || path === '' || path === '/v2/' || path === '/v2') {
|
||||
return this.handleVersionCheck();
|
||||
}
|
||||
|
||||
|
||||
@@ -254,14 +254,12 @@ export function generateVersionsJson(
|
||||
uploadTime?: string;
|
||||
}>
|
||||
): any {
|
||||
return {
|
||||
name: gemName,
|
||||
versions: versions.map(v => ({
|
||||
number: v.version,
|
||||
platform: v.platform || 'ruby',
|
||||
built_at: v.uploadTime,
|
||||
})),
|
||||
};
|
||||
// RubyGems.org API returns a flat array at /api/v1/versions/{gem}.json
|
||||
return versions.map(v => ({
|
||||
number: v.version,
|
||||
platform: v.platform || 'ruby',
|
||||
built_at: v.uploadTime,
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user