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

Function _refreshLocaleCollection

scripts/dbRefresh.ts:209–238  ·  view source on GitHub ↗
(
  db: Db,
  collectionPrefix: string,
  translationDocs: TranslationDocument[]
)

Source from the content-addressed store, hash-verified

207}
208
209async function _refreshLocaleCollection(
210 db: Db,
211 collectionPrefix: string,
212 translationDocs: TranslationDocument[]
213): Promise<void> {
214 const localeCollectionName = `${collectionPrefix}locales`;
215 const localeCollection = db.collection(localeCollectionName);
216
217 try {
218 await localeCollection.drop();
219 } catch (err) {
220 if (!(err instanceof MongoServerError && err.codeName === 'NamespaceNotFound')) throw err;
221 }
222
223 const localeDocs = computeLocaleDocuments(translationDocs);
224 if (localeDocs.length > 0) {
225 try {
226 await localeCollection.createIndex({ lang: 1 }, { unique: true });
227 await localeCollection.insertMany(localeDocs, { ordered: false });
228 console.log(
229 ` Inserted ${localeDocs.length} locale documents into '${localeCollectionName}'.`
230 );
231 } catch (err) {
232 console.error(` Error inserting locale documents into '${localeCollectionName}':`, err);
233 throw err;
234 }
235 } else {
236 console.log(` No locales to insert into '${localeCollectionName}'.`);
237 }
238}
239
240/**
241 * Discovers all non-English locale directories under jsonDbDir, loads their

Callers 1

Calls 1

computeLocaleDocumentsFunction · 0.90

Tested by

no test coverage detected