MCPcopy Create free account
hub / github.com/5e-bits/5e-database / _handleFileAdded

Function _handleFileAdded

scripts/update/processor.ts:216–235  ·  view source on GitHub ↗

* Handles processing for a newly added file. * Creates the collection, inserts data, and updates the index collection.

(db: Db, filepath: string)

Source from the content-addressed store, hash-verified

214 * Creates the collection, inserts data, and updates the index collection.
215 */
216async function _handleFileAdded(db: Db, filepath: string): Promise<void> {
217 const collectionName = getCollectionNameFromJsonFile(filepath);
218 if (!collectionName) {
219 console.warn(`Could not determine collection name for added file ${filepath}. Skipping.`);
220 return;
221 }
222 console.log(`\nProcessing Added file ${filepath} for collection '${collectionName}'...`);
223
224 const currentData = await readFileContent(filepath);
225 // For added files, oldData is empty
226 const { operations, skippedRecords } = calculateBulkOperations([], currentData, filepath);
227 await executeBulkWrite(db, collectionName, operations);
228
229 if (skippedRecords > 0) {
230 console.warn(`Skipped ${skippedRecords} records in ${filepath} due to missing 'index' field.`);
231 }
232
233 // Update index collection
234 await updateIndexCollection(db, filepath, 'upsert');
235}
236
237/**
238 * Handles processing for a modified file.

Callers 1

processFileUpdateFunction · 0.85

Calls 5

readFileContentFunction · 0.85
calculateBulkOperationsFunction · 0.85
executeBulkWriteFunction · 0.85
updateIndexCollectionFunction · 0.85

Tested by

no test coverage detected