feat(TRUEREF-0009-0010): implement indexing pipeline job queue and public REST API
- 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>
This commit is contained in:
32
src/lib/server/api/library-id.ts
Normal file
32
src/lib/server/api/library-id.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* 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]
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user