- SQLite-backed job queue with sequential processing and startup recovery - Atomic snippet replacement in single transaction - context7-compatible GET /api/v1/libs/search and GET /api/v1/context - Token budget limiting and JSON/txt response format support - CORS headers on all API routes via SvelteKit handle hook - Library ID parser supporting /owner/repo and /owner/repo/version Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
33 lines
869 B
TypeScript
33 lines
869 B
TypeScript
/**
|
|
* Library ID parsing utilities.
|
|
*
|
|
* Parses the `libraryId` query parameter used by the context7-compatible API.
|
|
* Supports two formats:
|
|
* - /owner/repo (default branch)
|
|
* - /owner/repo/version (specific version tag)
|
|
*/
|
|
|
|
export interface ParsedLibraryId {
|
|
/** The canonical repository ID, e.g. "/facebook/react" */
|
|
repositoryId: string;
|
|
/** The version tag, e.g. "v18.3.0" — absent for default branch queries */
|
|
version?: string;
|
|
}
|
|
|
|
/**
|
|
* Parse a libraryId string into its constituent parts.
|
|
*
|
|
* @throws Error when the string does not match the expected pattern.
|
|
*/
|
|
export function parseLibraryId(libraryId: string): ParsedLibraryId {
|
|
const match = libraryId.match(/^(\/[^/]+\/[^/]+)(\/(.+))?$/);
|
|
if (!match) {
|
|
throw new Error(`Invalid libraryId: ${libraryId}`);
|
|
}
|
|
|
|
return {
|
|
repositoryId: match[1],
|
|
version: match[3]
|
|
};
|
|
}
|