feat(api): make databaseId optional in entity-testing for parse-only mode

This commit is contained in:
Sam Chau
2026-01-25 23:36:24 +10:30
parent 317e66b5fc
commit 71a1c9e969
2 changed files with 27 additions and 12 deletions

View File

@@ -86,12 +86,11 @@ ReleaseEvaluation:
EvaluateRequest:
type: object
required:
- databaseId
- releases
properties:
databaseId:
type: integer
description: Database ID to use for custom format evaluation
description: Database ID to use for custom format evaluation. If omitted, only parsing is performed (no CF matching).
releases:
type: array
items:

View File

@@ -28,10 +28,6 @@ export const POST: RequestHandler = async ({ request }) => {
const body: EvaluateRequest = await request.json();
const { databaseId, releases } = body;
if (!databaseId) {
throw error(400, 'Missing databaseId');
}
if (!releases || !Array.isArray(releases) || releases.length === 0) {
throw error(400, 'Missing or empty releases array');
}
@@ -49,16 +45,36 @@ export const POST: RequestHandler = async ({ request }) => {
} satisfies EvaluateResponse);
}
// Get the PCD cache
const cache = pcdManager.getCache(databaseId);
if (!cache) {
throw error(500, 'Database cache not available');
}
// Parse all releases in batch (uses cache)
const parseItems = releases.map((r) => ({ title: r.title, type: r.type }));
const parseResults = await parseWithCacheBatch(parseItems);
// If no databaseId, just return parsed info without CF evaluation
if (!databaseId) {
const evaluations: ReleaseEvaluation[] = releases.map((release) => {
const cacheKey = `${release.title}:${release.type}`;
const parsed = parseResults.get(cacheKey);
return {
releaseId: release.id,
title: release.title,
parsed: parsed ? getParsedInfo(parsed) : undefined,
cfMatches: {}
};
});
return json({
parserAvailable: true,
evaluations
} satisfies EvaluateResponse);
}
// Get the PCD cache for CF evaluation
const cache = pcdManager.getCache(databaseId);
if (!cache) {
throw error(404, 'Database not found or cache not available');
}
// Get all custom formats with conditions
const customFormats = await getAllConditionsForEvaluation(cache);