List of manga to process.
Size of each batch.
Processing options.
Processing results.
export function processKenmeiMangaBatches(
mangaList: KenmeiManga[],
batchSize = 50,
options: Partial<KenmeiParseOptions> = {},
): ProcessingResult {
const parseOptions = { ...DEFAULT_PARSE_OPTIONS, ...options };
const validationErrors: ValidationError[] = [];
const processedEntries: KenmeiManga[] = [];
// Process in batches
for (let i = 0; i < mangaList.length; i += batchSize) {
const batch = mangaList.slice(i, i + batchSize);
// Process each manga in the batch
for (let j = 0; j < batch.length; j++) {
const manga = batch[j];
const index = i + j;
try {
const validatedManga = validateAndNormalizeManga(
manga,
index,
parseOptions,
);
processedEntries.push(validatedManga);
} catch (error) {
if (error instanceof Error) {
validationErrors.push({
mangaTitle: manga.title || `Unknown manga at index ${index}`,
field: "general",
message: error.message,
index,
});
}
// If we allow partial data, continue processing despite errors
if (parseOptions.allowPartialData && manga.title) {
processedEntries.push({
...manga,
status: manga.status || parseOptions.defaultStatus,
chapters_read:
typeof manga.chapters_read === "number" ? manga.chapters_read : 0,
score: typeof manga.score === "number" ? manga.score : 0,
id: manga.id || index,
url: manga.url || "",
created_at: manga.created_at || new Date().toISOString(),
updated_at: manga.updated_at || new Date().toISOString(),
});
}
}
}
}
return {
processedEntries,
validationErrors,
totalEntries: mangaList.length,
successfulEntries: processedEntries.length,
};
}
Process Kenmei manga list in batches.