@helloao/tools 0.0.9 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/cjs/generation/api.cjs +126 -0
  2. package/dist/cjs/generation/api.cjs.map +2 -2
  3. package/dist/cjs/generation/common-types.cjs.map +1 -1
  4. package/dist/cjs/generation/dataset.cjs +159 -79
  5. package/dist/cjs/generation/dataset.cjs.map +2 -2
  6. package/dist/cjs/parser/codex-parser.cjs +77 -66
  7. package/dist/cjs/parser/codex-parser.cjs.map +2 -2
  8. package/dist/cjs/parser/commentary-csv-parser.cjs +133 -0
  9. package/dist/cjs/parser/commentary-csv-parser.cjs.map +7 -0
  10. package/dist/cjs/parser/index.cjs +3 -1
  11. package/dist/cjs/parser/index.cjs.map +2 -2
  12. package/dist/cjs/parser/types.cjs.map +1 -1
  13. package/dist/cjs/parser/usx-parser.cjs +13 -1
  14. package/dist/cjs/parser/usx-parser.cjs.map +2 -2
  15. package/dist/cjs/utils.cjs +155 -3
  16. package/dist/cjs/utils.cjs.map +3 -3
  17. package/dist/esm/generation/api.js +122 -0
  18. package/dist/esm/generation/api.js.map +2 -2
  19. package/dist/esm/generation/dataset.js +159 -79
  20. package/dist/esm/generation/dataset.js.map +2 -2
  21. package/dist/esm/parser/codex-parser.js +71 -64
  22. package/dist/esm/parser/codex-parser.js.map +2 -2
  23. package/dist/esm/parser/commentary-csv-parser.js +107 -0
  24. package/dist/esm/parser/commentary-csv-parser.js.map +7 -0
  25. package/dist/esm/parser/index.js +1 -0
  26. package/dist/esm/parser/index.js.map +2 -2
  27. package/dist/esm/parser/usx-parser.js +13 -1
  28. package/dist/esm/parser/usx-parser.js.map +2 -2
  29. package/dist/esm/utils.js +153 -3
  30. package/dist/esm/utils.js.map +3 -3
  31. package/dist/types/generation/api.d.ts +147 -1
  32. package/dist/types/generation/common-types.d.ts +121 -24
  33. package/dist/types/generation/dataset.d.ts +23 -1
  34. package/dist/types/parser/codex-parser.d.ts +50 -7
  35. package/dist/types/parser/commentary-csv-parser.d.ts +12 -0
  36. package/dist/types/parser/index.d.ts +1 -0
  37. package/dist/types/parser/types.d.ts +28 -1
  38. package/dist/types/parser/usx-parser.d.ts +1 -1
  39. package/dist/types/utils.d.ts +6 -0
  40. package/package.json +3 -2
@@ -9,6 +9,11 @@ export function generateApiForDataset(dataset, options = {}) {
9
9
  translationBooks: [],
10
10
  translationBookChapters: [],
11
11
  translationBookChapterAudio: [],
12
+ availableCommentaries: {
13
+ commentaries: []
14
+ },
15
+ commentaryBookChapters: [],
16
+ commentaryBooks: [],
12
17
  pathPrefix: apiPathPrefix
13
18
  };
14
19
  const getNativeName = options.getNativeName;
@@ -129,6 +134,97 @@ export function generateApiForDataset(dataset, options = {}) {
129
134
  api.availableTranslations.translations.push(apiTranslation);
130
135
  api.translationBooks.push(translationBooks);
131
136
  }
137
+ for (let { books, ...commentary } of dataset.commentaries) {
138
+ const apiCommentary = {
139
+ ...commentary,
140
+ availableFormats: ["json"],
141
+ listOfBooksApiLink: listOfCommentaryBooksApiLink(
142
+ commentary.id,
143
+ apiPathPrefix
144
+ ),
145
+ numberOfBooks: books.length,
146
+ totalNumberOfChapters: 0,
147
+ totalNumberOfVerses: 0,
148
+ languageName: getNativeName ? getNativeName(commentary.language) ?? void 0 : void 0,
149
+ languageEnglishName: getEnglishName ? getEnglishName(commentary.language) ?? void 0 : void 0
150
+ };
151
+ const commentaryBooks = {
152
+ commentary: apiCommentary,
153
+ books: []
154
+ };
155
+ let commentaryChapters = [];
156
+ for (let { chapters, ...book } of books) {
157
+ const apiBook = {
158
+ ...book,
159
+ firstChapterApiLink: bookCommentaryChapterApiLink(
160
+ commentary.id,
161
+ getBookLink(book),
162
+ 1,
163
+ "json",
164
+ apiPathPrefix
165
+ ),
166
+ lastChapterApiLink: bookCommentaryChapterApiLink(
167
+ commentary.id,
168
+ getBookLink(book),
169
+ chapters.length,
170
+ "json",
171
+ apiPathPrefix
172
+ ),
173
+ numberOfChapters: chapters.length,
174
+ totalNumberOfVerses: 0
175
+ };
176
+ for (let { chapter } of chapters) {
177
+ const apiBookChapter = {
178
+ commentary: apiCommentary,
179
+ book: apiBook,
180
+ chapter,
181
+ thisChapterLink: bookCommentaryChapterApiLink(
182
+ commentary.id,
183
+ getBookLink(book),
184
+ chapter.number,
185
+ "json",
186
+ apiPathPrefix
187
+ ),
188
+ nextChapterApiLink: null,
189
+ previousChapterApiLink: null,
190
+ numberOfVerses: 0
191
+ };
192
+ for (let c of chapter.content) {
193
+ if (c.type === "verse") {
194
+ apiBookChapter.numberOfVerses++;
195
+ }
196
+ }
197
+ apiBook.totalNumberOfVerses += apiBookChapter.numberOfVerses;
198
+ commentaryChapters.push(apiBookChapter);
199
+ api.commentaryBookChapters.push(apiBookChapter);
200
+ }
201
+ commentaryBooks.books.push(apiBook);
202
+ apiCommentary.totalNumberOfChapters += apiBook.numberOfChapters;
203
+ apiCommentary.totalNumberOfVerses += apiBook.totalNumberOfVerses;
204
+ }
205
+ for (let i = 0; i < commentaryChapters.length; i++) {
206
+ if (i > 0) {
207
+ commentaryChapters[i].previousChapterApiLink = bookCommentaryChapterApiLink(
208
+ commentary.id,
209
+ getBookLink(commentaryChapters[i - 1].book),
210
+ commentaryChapters[i - 1].chapter.number,
211
+ "json",
212
+ apiPathPrefix
213
+ );
214
+ }
215
+ if (i < commentaryChapters.length - 1) {
216
+ commentaryChapters[i].nextChapterApiLink = bookCommentaryChapterApiLink(
217
+ commentary.id,
218
+ getBookLink(commentaryChapters[i + 1].book),
219
+ commentaryChapters[i + 1].chapter.number,
220
+ "json",
221
+ apiPathPrefix
222
+ );
223
+ }
224
+ }
225
+ api.availableCommentaries.commentaries.push(apiCommentary);
226
+ api.commentaryBooks.push(commentaryBooks);
227
+ }
132
228
  return api;
133
229
  function getBookLink(book) {
134
230
  return useCommonName ? book.commonName : book.id;
@@ -157,6 +253,24 @@ export function generateFilesForApi(api) {
157
253
  for (let audio of api.translationBookChapterAudio) {
158
254
  files.push(downloadedFile(audio.link, audio.originalUrl));
159
255
  }
256
+ files.push(
257
+ jsonFile(
258
+ `${api.pathPrefix}/api/available_commentaries.json`,
259
+ api.availableCommentaries,
260
+ true
261
+ )
262
+ );
263
+ for (let commentaryBooks of api.commentaryBooks) {
264
+ files.push(
265
+ jsonFile(
266
+ commentaryBooks.commentary.listOfBooksApiLink,
267
+ commentaryBooks
268
+ )
269
+ );
270
+ }
271
+ for (let bookChapter of api.commentaryBookChapters) {
272
+ files.push(jsonFile(bookChapter.thisChapterLink, bookChapter));
273
+ }
160
274
  return files;
161
275
  }
162
276
  export async function* generateOutputFilesFromDatasets(datasets, options) {
@@ -169,11 +283,19 @@ export async function* generateOutputFilesFromDatasets(datasets, options) {
169
283
  export function listOfBooksApiLink(translationId, prefix = "") {
170
284
  return `${prefix}/api/${translationId}/books.json`;
171
285
  }
286
+ export function listOfCommentaryBooksApiLink(commentaryId, prefix = "") {
287
+ return `${prefix}/api/c/${commentaryId}/books.json`;
288
+ }
172
289
  export function bookChapterApiLink(translationId, commonName, chapterNumber, extension, prefix = "") {
173
290
  return `${prefix}/api/${translationId}/${replaceSpacesWithUnderscores(
174
291
  commonName
175
292
  )}/${chapterNumber}.${extension}`;
176
293
  }
294
+ export function bookCommentaryChapterApiLink(translationId, commonName, chapterNumber, extension, prefix = "") {
295
+ return `${prefix}/api/c/${translationId}/${replaceSpacesWithUnderscores(
296
+ commonName
297
+ )}/${chapterNumber}.${extension}`;
298
+ }
177
299
  export function bookChapterAudioApiLink(translationId, bookId, chapterNumber, reader, prefix = "") {
178
300
  return `${prefix}/api/${translationId}/${replaceSpacesWithUnderscores(
179
301
  bookId
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../generation/api.ts"],
4
- "sourcesContent": ["import {\r\n OutputFile,\r\n Translation,\r\n TranslationBook,\r\n TranslationBookChapter,\r\n TranslationBookChapterAudioLinks,\r\n} from './common-types.js';\r\nimport { DatasetOutput } from './dataset.js';\r\n\r\n/**\r\n * Defines the output of the API generation.\r\n */\r\nexport interface ApiOutput {\r\n /**\r\n * The list of available translations.\r\n * This maps to the /api/available-translations.json endpoint.\r\n */\r\n availableTranslations: ApiAvailableTranslations;\r\n\r\n /**\r\n * The list of books for each translation.\r\n * This maps to the /api/:translationId/books.json endpoint.\r\n */\r\n translationBooks: ApiTranslationBooks[];\r\n\r\n /**\r\n * The list of chapters for each book.\r\n * This maps to the following endpoints:\r\n * - /api/:translationId/:bookId/:chapterNumber.json\r\n * - /api/:translationId/:bookCommonName/:chapterNumber.json\r\n */\r\n translationBookChapters: ApiTranslationBookChapter[];\r\n\r\n /**\r\n * The list of audio files.\r\n * This maps to the following endpoints:\r\n * - /api/:translationId/:bookId/:chapterNumber.:reader.mp3\r\n */\r\n translationBookChapterAudio: ApiTranslationBookChapterAudio[];\r\n\r\n /**\r\n * The path prefix that the API should use.\r\n */\r\n pathPrefix: string;\r\n}\r\n\r\n/**\r\n * The list of available translations.\r\n * Maps to the /api/available-translations.json endpoint.\r\n */\r\nexport interface ApiAvailableTranslations {\r\n /**\r\n * The list of translations.\r\n */\r\n translations: ApiTranslation[];\r\n}\r\n\r\n/**\r\n * Defines a translation that is used in the API.\r\n */\r\nexport interface ApiTranslation extends Translation {\r\n /**\r\n * The API link for the list of available books for this translation.\r\n */\r\n listOfBooksApiLink: string;\r\n\r\n /**\r\n * The available list of formats.\r\n */\r\n availableFormats: ('json' | 'usfm')[];\r\n\r\n /**\r\n * The number of books that are contained in this translation.\r\n *\r\n * Complete translations should have the same number of books as the Bible (66).\r\n */\r\n numberOfBooks: number;\r\n\r\n /**\r\n * The total number of chapters that are contained in this translation.\r\n *\r\n * Complete translations should have the same number of chapters as the Bible (1,189).\r\n */\r\n totalNumberOfChapters: number;\r\n\r\n /**\r\n * The total number of verses that are contained in this translation.\r\n *\r\n * Complete translations should have the same number of verses as the Bible (around 31,102 - some translations exclude verses based on the aparent likelyhood of existing in the original source texts).\r\n */\r\n totalNumberOfVerses: number;\r\n\r\n /**\r\n * Gets the name of the language that the translation is in.\r\n * Null or undefined if the name of the language is not known.\r\n */\r\n languageName?: string;\r\n\r\n /**\r\n * Gets the name of the language in English.\r\n * Null or undefined if the language doesn't have an english name.\r\n */\r\n languageEnglishName?: string;\r\n}\r\n\r\n/**\r\n * Defines an interface that contains information about the books that are available for a translation.\r\n */\r\nexport interface ApiTranslationBooks {\r\n /**\r\n * The translation information for the books.\r\n */\r\n translation: ApiTranslation;\r\n\r\n /**\r\n * The list of books that are available for the translation.\r\n */\r\n books: ApiTranslationBook[];\r\n}\r\n\r\n/**\r\n * Defines a translation book that is used in the API.\r\n */\r\nexport interface ApiTranslationBook extends TranslationBook {\r\n /**\r\n * The link to the first chapter of the book.\r\n */\r\n firstChapterApiLink: string;\r\n\r\n /**\r\n * The link to the last chapter of the book.\r\n */\r\n lastChapterApiLink: string;\r\n\r\n /**\r\n * The number of chapters that the book contains.\r\n */\r\n numberOfChapters: number;\r\n\r\n /**\r\n * The number of verses that the book contains.\r\n */\r\n totalNumberOfVerses: number;\r\n}\r\n\r\n/**\r\n * Defines an interface that contains information about a book chapter.\r\n */\r\nexport interface ApiTranslationBookChapter extends TranslationBookChapter {\r\n /**\r\n * The translation information for the book chapter.\r\n */\r\n translation: ApiTranslation;\r\n\r\n /**\r\n * The book information for the book chapter.\r\n */\r\n book: ApiTranslationBook;\r\n\r\n /**\r\n * The link to this chapter.\r\n */\r\n thisChapterLink: string;\r\n\r\n /**\r\n * The link to the next chapter.\r\n * Null if this is the last chapter in the translation.\r\n */\r\n nextChapterApiLink: string | null;\r\n\r\n /**\r\n * The links to the audio versions for the next chapter.\r\n * Null if this is the last chapter in the translation.\r\n */\r\n nextChapterAudioLinks: TranslationBookChapterAudioLinks | null;\r\n\r\n /**\r\n * The link to the previous chapter.\r\n * Null if this is the first chapter in the translation.\r\n */\r\n previousChapterApiLink: string | null;\r\n\r\n /**\r\n * The links to the audio versions for the previous chapter.\r\n * Null if this is the first chapter in the translation.\r\n */\r\n previousChapterAudioLinks: TranslationBookChapterAudioLinks | null;\r\n\r\n /**\r\n * The number of verses that the chapter contains.\r\n */\r\n numberOfVerses: number;\r\n}\r\n\r\nexport interface ApiTranslationBookChapterAudio {\r\n /**\r\n * The chapter that the audio is for.\r\n */\r\n chapter: ApiTranslationBookChapter;\r\n\r\n /**\r\n * The link that the audio should be placed at.\r\n */\r\n link: string;\r\n\r\n /**\r\n * The original URL of the audio.\r\n */\r\n originalUrl: string;\r\n}\r\n\r\n/**\r\n * The options for generating the API.\r\n */\r\nexport interface GenerateApiOptions {\r\n /**\r\n * Whether to use the common name for the book chapter API link. If false, then book IDs are used.\r\n * Audio URLs will always use the book ID.\r\n * Defaults to false.\r\n */\r\n useCommonName?: boolean;\r\n\r\n /**\r\n * Whether to replace the audio URLs in the dataset with ones that are hosted locally.\r\n * If true, then the audio URLs in the dataset will be replaced with ones that reference files hosted by the API itself.\r\n * If false, then the audio URLs in the dataset will be left as is.\r\n * Defaults to false.\r\n */\r\n generateAudioFiles?: boolean;\r\n\r\n /**\r\n * Gets the english name of the given language.\r\n * If not provided, then the english name for the language will be unknown and omitted.\r\n * @param language The language to get the english name for.\r\n */\r\n getEnglishName?: (language: string) => string | null | undefined;\r\n\r\n /**\r\n * Gets the native name of the given language.\r\n * If not provided, then the native name for the language will be unknown and omitted.\r\n * @param language The language to get the native name for.\r\n */\r\n getNativeName?: (language: string) => string | null | undefined;\r\n\r\n /**\r\n * The prefix that should be added to paths that are generated.\r\n */\r\n pathPrefix?: string;\r\n}\r\n\r\n/**\r\n * Generates the API output for the given dataset.\r\n * @param dataset The dataset to generate the API for.\r\n * @param options The options for generating the API.\r\n */\r\nexport function generateApiForDataset(\r\n dataset: DatasetOutput,\r\n options: GenerateApiOptions = {}\r\n): ApiOutput {\r\n const { useCommonName, pathPrefix } = options;\r\n const apiPathPrefix = pathPrefix ? pathPrefix : '';\r\n let api: ApiOutput = {\r\n availableTranslations: {\r\n translations: [],\r\n },\r\n translationBooks: [],\r\n translationBookChapters: [],\r\n translationBookChapterAudio: [],\r\n pathPrefix: apiPathPrefix,\r\n };\r\n\r\n const getNativeName = options.getNativeName;\r\n const getEnglishName = options.getEnglishName;\r\n\r\n for (let { books, ...translation } of dataset.translations) {\r\n const apiTranslation: ApiTranslation = {\r\n ...translation,\r\n availableFormats: ['json'],\r\n listOfBooksApiLink: listOfBooksApiLink(\r\n translation.id,\r\n apiPathPrefix\r\n ),\r\n numberOfBooks: books.length,\r\n totalNumberOfChapters: 0,\r\n totalNumberOfVerses: 0,\r\n languageName: getNativeName\r\n ? getNativeName(translation.language) ?? undefined\r\n : undefined,\r\n languageEnglishName: getEnglishName\r\n ? getEnglishName(translation.language) ?? undefined\r\n : undefined,\r\n };\r\n\r\n const translationBooks: ApiTranslationBooks = {\r\n translation: apiTranslation,\r\n books: [],\r\n };\r\n\r\n let translationChapters: ApiTranslationBookChapter[] = [];\r\n\r\n for (let { chapters, ...book } of books) {\r\n const apiBook: ApiTranslationBook = {\r\n ...book,\r\n firstChapterApiLink: bookChapterApiLink(\r\n translation.id,\r\n getBookLink(book),\r\n 1,\r\n 'json',\r\n apiPathPrefix\r\n ),\r\n lastChapterApiLink: bookChapterApiLink(\r\n translation.id,\r\n getBookLink(book),\r\n chapters.length,\r\n 'json',\r\n apiPathPrefix\r\n ),\r\n numberOfChapters: chapters.length,\r\n totalNumberOfVerses: 0,\r\n };\r\n\r\n for (let { chapter, thisChapterAudioLinks } of chapters) {\r\n const audio: TranslationBookChapterAudioLinks = {};\r\n const apiBookChapter: ApiTranslationBookChapter = {\r\n translation: apiTranslation,\r\n book: apiBook,\r\n chapter: chapter,\r\n thisChapterLink: bookChapterApiLink(\r\n translation.id,\r\n getBookLink(book),\r\n chapter.number,\r\n 'json',\r\n apiPathPrefix\r\n ),\r\n thisChapterAudioLinks: audio,\r\n nextChapterApiLink: null,\r\n nextChapterAudioLinks: null,\r\n previousChapterApiLink: null,\r\n previousChapterAudioLinks: null,\r\n numberOfVerses: 0,\r\n };\r\n\r\n for (let reader in thisChapterAudioLinks) {\r\n if (options.generateAudioFiles) {\r\n const apiAudio: ApiTranslationBookChapterAudio = {\r\n chapter: apiBookChapter,\r\n link: bookChapterAudioApiLink(\r\n translation.id,\r\n getBookLink(book),\r\n chapter.number,\r\n reader,\r\n apiPathPrefix\r\n ),\r\n originalUrl: thisChapterAudioLinks[reader],\r\n };\r\n audio[reader] = apiAudio.link;\r\n api.translationBookChapterAudio.push(apiAudio);\r\n } else {\r\n audio[reader] = thisChapterAudioLinks[reader];\r\n }\r\n }\r\n\r\n for (let c of chapter.content) {\r\n if (c.type === 'verse') {\r\n apiBookChapter.numberOfVerses++;\r\n }\r\n }\r\n\r\n apiBook.totalNumberOfVerses += apiBookChapter.numberOfVerses;\r\n\r\n translationChapters.push(apiBookChapter);\r\n api.translationBookChapters.push(apiBookChapter);\r\n }\r\n\r\n translationBooks.books.push(apiBook);\r\n\r\n apiTranslation.totalNumberOfChapters += apiBook.numberOfChapters;\r\n apiTranslation.totalNumberOfVerses += apiBook.totalNumberOfVerses;\r\n }\r\n\r\n for (let i = 0; i < translationChapters.length; i++) {\r\n if (i > 0) {\r\n translationChapters[i].previousChapterApiLink =\r\n bookChapterApiLink(\r\n translation.id,\r\n getBookLink(translationChapters[i - 1].book),\r\n translationChapters[i - 1].chapter.number,\r\n 'json',\r\n apiPathPrefix\r\n );\r\n translationChapters[i].previousChapterAudioLinks =\r\n translationChapters[i - 1].thisChapterAudioLinks;\r\n }\r\n\r\n if (i < translationChapters.length - 1) {\r\n translationChapters[i].nextChapterApiLink = bookChapterApiLink(\r\n translation.id,\r\n getBookLink(translationChapters[i + 1].book),\r\n translationChapters[i + 1].chapter.number,\r\n 'json',\r\n apiPathPrefix\r\n );\r\n translationChapters[i].nextChapterAudioLinks =\r\n translationChapters[i + 1].thisChapterAudioLinks;\r\n }\r\n }\r\n\r\n api.availableTranslations.translations.push(apiTranslation);\r\n api.translationBooks.push(translationBooks);\r\n }\r\n\r\n return api;\r\n\r\n function getBookLink(book: TranslationBook): string {\r\n return useCommonName ? book.commonName : book.id;\r\n }\r\n}\r\n\r\n/**\r\n * Generates the output files for the given API.\r\n * @param api The API that the files should be generated for.\r\n */\r\nexport function generateFilesForApi(api: ApiOutput): OutputFile[] {\r\n let files: OutputFile[] = [];\r\n\r\n files.push(\r\n jsonFile(\r\n `${api.pathPrefix}/api/available_translations.json`,\r\n api.availableTranslations,\r\n true\r\n )\r\n );\r\n for (let translationBooks of api.translationBooks) {\r\n files.push(\r\n jsonFile(\r\n translationBooks.translation.listOfBooksApiLink,\r\n translationBooks\r\n )\r\n );\r\n }\r\n\r\n for (let bookChapter of api.translationBookChapters) {\r\n files.push(jsonFile(bookChapter.thisChapterLink, bookChapter));\r\n }\r\n\r\n for (let audio of api.translationBookChapterAudio) {\r\n files.push(downloadedFile(audio.link, audio.originalUrl));\r\n }\r\n\r\n return files;\r\n}\r\n\r\n/**\r\n * Generates the output files for the given datasets.\r\n * @param datasets The datasets to generate the output files for.\r\n * @param options The options for generating the API files.\r\n */\r\nexport async function* generateOutputFilesFromDatasets(\r\n datasets: AsyncIterable<DatasetOutput>,\r\n options?: GenerateApiOptions\r\n): AsyncGenerator<OutputFile[]> {\r\n for await (let dataset of datasets) {\r\n const api = generateApiForDataset(dataset, options);\r\n const files = generateFilesForApi(api);\r\n\r\n yield files;\r\n }\r\n}\r\n\r\n/**\r\n * Gets the API Link for the list of books endpoint for a translation.\r\n * @param translationId The ID of the translation.\r\n * @returns\r\n */\r\nexport function listOfBooksApiLink(\r\n translationId: string,\r\n prefix: string = ''\r\n): string {\r\n return `${prefix}/api/${translationId}/books.json`;\r\n}\r\n\r\n/**\r\n * Getes the API link for a book chapter.\r\n * @param translationId The ID of the translation.\r\n * @param commonName The name of the book.\r\n * @param chapterNumber The number of the book.\r\n * @param extension The extension of the file.\r\n */\r\nexport function bookChapterApiLink(\r\n translationId: string,\r\n commonName: string,\r\n chapterNumber: number,\r\n extension: string,\r\n prefix: string = ''\r\n) {\r\n return `${prefix}/api/${translationId}/${replaceSpacesWithUnderscores(\r\n commonName\r\n )}/${chapterNumber}.${extension}`;\r\n}\r\n\r\nexport function bookChapterAudioApiLink(\r\n translationId: string,\r\n bookId: string,\r\n chapterNumber: number,\r\n reader: string,\r\n prefix: string = ''\r\n) {\r\n return `${prefix}/api/${translationId}/${replaceSpacesWithUnderscores(\r\n bookId\r\n )}/${chapterNumber}.${reader}.mp3`;\r\n}\r\n\r\nexport function jsonFile(\r\n path: string,\r\n content: any,\r\n mergable?: boolean\r\n): OutputFile {\r\n return {\r\n path,\r\n content,\r\n mergable,\r\n };\r\n}\r\n\r\nexport function downloadedFile(path: string, url: string): OutputFile {\r\n return {\r\n path,\r\n content: () => fetch(url).then((response) => response.body),\r\n };\r\n}\r\n\r\nexport function replaceSpacesWithUnderscores(str: string): string {\r\n return str.replace(/[<>:\"/\\\\|?*\\s]/g, '_');\r\n}\r\n"],
5
- "mappings": ";AA+PO,gBAAS,sBACZ,SACA,UAA8B,CAAC,GACtB;AACT,QAAM,EAAE,eAAe,WAAW,IAAI;AACtC,QAAM,gBAAgB,aAAa,aAAa;AAChD,MAAI,MAAiB;AAAA,IACjB,uBAAuB;AAAA,MACnB,cAAc,CAAC;AAAA,IACnB;AAAA,IACA,kBAAkB,CAAC;AAAA,IACnB,yBAAyB,CAAC;AAAA,IAC1B,6BAA6B,CAAC;AAAA,IAC9B,YAAY;AAAA,EAChB;AAEA,QAAM,gBAAgB,QAAQ;AAC9B,QAAM,iBAAiB,QAAQ;AAE/B,WAAS,EAAE,OAAO,GAAG,YAAY,KAAK,QAAQ,cAAc;AACxD,UAAM,iBAAiC;AAAA,MACnC,GAAG;AAAA,MACH,kBAAkB,CAAC,MAAM;AAAA,MACzB,oBAAoB;AAAA,QAChB,YAAY;AAAA,QACZ;AAAA,MACJ;AAAA,MACA,eAAe,MAAM;AAAA,MACrB,uBAAuB;AAAA,MACvB,qBAAqB;AAAA,MACrB,cA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AA,IACA,SAAS,MAAM,MAAM,GAAG,EAAE,KAAK,CAAC,aAAa,SAAS,IAAI;AAAA,EAC9D;AACJ;AAEO,gBAAS,6BAA6B,KAAqB;AAC9D,SAAO,IAAI,QAAQ,mBAAmB,GAAG;AAC7C;",
4
+ "sourcesContent": ["import {\r\n Commentary,\r\n CommentaryBook,\r\n CommentaryBookChapter,\r\n OutputFile,\r\n Translation,\r\n TranslationBook,\r\n TranslationBookChapter,\r\n TranslationBookChapterAudioLinks,\r\n} from './common-types.js';\r\nimport { DatasetOutput } from './dataset.js';\r\n\r\n/**\r\n * Defines the output of the API generation.\r\n */\r\nexport interface ApiOutput {\r\n /**\r\n * The list of available translations.\r\n * This maps to the /api/available-translations.json endpoint.\r\n */\r\n availableTranslations: ApiAvailableTranslations;\r\n\r\n /**\r\n * The list of books for each translation.\r\n * This maps to the /api/:translationId/books.json endpoint.\r\n */\r\n translationBooks: ApiTranslationBooks[];\r\n\r\n /**\r\n * The list of chapters for each book.\r\n * This maps to the following endpoints:\r\n * - /api/:translationId/:bookId/:chapterNumber.json\r\n * - /api/:translationId/:bookCommonName/:chapterNumber.json\r\n */\r\n translationBookChapters: ApiTranslationBookChapter[];\r\n\r\n /**\r\n * The list of audio files.\r\n * This maps to the following endpoints:\r\n * - /api/:translationId/:bookId/:chapterNumber.:reader.mp3\r\n */\r\n translationBookChapterAudio: ApiTranslationBookChapterAudio[];\r\n\r\n /**\r\n * The list of available commentaries.\r\n * This maps to the /api/available-commentaries.json endpoint.\r\n */\r\n availableCommentaries: ApiAvailableCommentaries;\r\n\r\n /**\r\n * The list of books for each commentary.\r\n * This maps to the /api/c/:commentaryId/books.json endpoint.\r\n */\r\n commentaryBooks: ApiCommentaryBooks[];\r\n\r\n /**\r\n * The list of chapters for each commentary book.\r\n * This maps to the following endpoint:\r\n * - /api/c/:commentaryId/:bookId/:chapterNumber.json\r\n */\r\n commentaryBookChapters: ApiCommentaryBookChapter[];\r\n\r\n /**\r\n * The path prefix that the API should use.\r\n */\r\n pathPrefix: string;\r\n}\r\n\r\n/**\r\n * The list of available translations.\r\n * Maps to the /api/available-translations.json endpoint.\r\n */\r\nexport interface ApiAvailableTranslations {\r\n /**\r\n * The list of translations.\r\n */\r\n translations: ApiTranslation[];\r\n}\r\n\r\n/**\r\n * The list of available commentaries.\r\n * Maps to the /api/available-commentaries.json endpoint.\r\n */\r\nexport interface ApiAvailableCommentaries {\r\n /**\r\n * The list of commentaries.\r\n */\r\n commentaries: ApiCommentary[];\r\n}\r\n\r\n/**\r\n * Defines a translation that is used in the API.\r\n */\r\nexport interface ApiTranslation extends Translation {\r\n /**\r\n * The API link for the list of available books for this translation.\r\n */\r\n listOfBooksApiLink: string;\r\n\r\n /**\r\n * The available list of formats.\r\n */\r\n availableFormats: ('json' | 'usfm')[];\r\n\r\n /**\r\n * The number of books that are contained in this translation.\r\n *\r\n * Complete translations should have the same number of books as the Bible (66).\r\n */\r\n numberOfBooks: number;\r\n\r\n /**\r\n * The total number of chapters that are contained in this translation.\r\n *\r\n * Complete translations should have the same number of chapters as the Bible (1,189).\r\n */\r\n totalNumberOfChapters: number;\r\n\r\n /**\r\n * The total number of verses that are contained in this translation.\r\n *\r\n * Complete translations should have the same number of verses as the Bible (around 31,102 - some translations exclude verses based on the aparent likelyhood of existing in the original source texts).\r\n */\r\n totalNumberOfVerses: number;\r\n\r\n /**\r\n * Gets the name of the language that the translation is in.\r\n * Null or undefined if the name of the language is not known.\r\n */\r\n languageName?: string;\r\n\r\n /**\r\n * Gets the name of the language in English.\r\n * Null or undefined if the language doesn't have an english name.\r\n */\r\n languageEnglishName?: string;\r\n}\r\n\r\n/**\r\n * Defines a commentary that is used in the API.\r\n */\r\nexport interface ApiCommentary extends Commentary {\r\n /**\r\n * The API link for the list of available books for this translation.\r\n */\r\n listOfBooksApiLink: string;\r\n\r\n /**\r\n * The available list of formats.\r\n */\r\n availableFormats: ('json' | 'usfm')[];\r\n\r\n /**\r\n * The number of books that are contained in this commentary.\r\n *\r\n * Complete commentaries should have the same number of books as the Bible (66).\r\n */\r\n numberOfBooks: number;\r\n\r\n /**\r\n * The total number of chapters that are contained in this translation.\r\n *\r\n * Complete commentaries should have the same number of chapters as the Bible (1,189).\r\n */\r\n totalNumberOfChapters: number;\r\n\r\n /**\r\n * The total number of verses that are contained in this commentary.\r\n *\r\n * Complete commentaries should have the same number of verses as the Bible (around 31,102 - some commentaries exclude verses based on the aparent likelyhood of existing in the original source texts).\r\n */\r\n totalNumberOfVerses: number;\r\n\r\n /**\r\n * Gets the name of the language that the commentary is in.\r\n * Null or undefined if the name of the language is not known.\r\n */\r\n languageName?: string;\r\n\r\n /**\r\n * Gets the name of the language in English.\r\n * Null or undefined if the language doesn't have an english name.\r\n */\r\n languageEnglishName?: string;\r\n}\r\n\r\n/**\r\n * Defines an interface that contains information about the books that are available for a translation.\r\n */\r\nexport interface ApiTranslationBooks {\r\n /**\r\n * The translation information for the books.\r\n */\r\n translation: ApiTranslation;\r\n\r\n /**\r\n * The list of books that are available for the translation.\r\n */\r\n books: ApiTranslationBook[];\r\n}\r\n\r\n/**\r\n * Defines an interface that contains information about the books that are available for a commentary.\r\n */\r\nexport interface ApiCommentaryBooks {\r\n /**\r\n * The commentary information for the books.\r\n */\r\n commentary: ApiCommentary;\r\n\r\n /**\r\n * The list of books that are available for the commentary.\r\n */\r\n books: ApiCommentaryBook[];\r\n}\r\n\r\n/**\r\n * Defines a translation book that is used in the API.\r\n */\r\nexport interface ApiTranslationBook extends TranslationBook {\r\n /**\r\n * The link to the first chapter of the book.\r\n */\r\n firstChapterApiLink: string;\r\n\r\n /**\r\n * The link to the last chapter of the book.\r\n */\r\n lastChapterApiLink: string;\r\n\r\n /**\r\n * The number of chapters that the book contains.\r\n */\r\n numberOfChapters: number;\r\n\r\n /**\r\n * The number of verses that the book contains.\r\n */\r\n totalNumberOfVerses: number;\r\n}\r\n\r\n/**\r\n * Defines a commentary book that is used in the API.\r\n */\r\nexport interface ApiCommentaryBook extends CommentaryBook {\r\n /**\r\n * The link to the first chapter of the book.\r\n */\r\n firstChapterApiLink: string;\r\n\r\n /**\r\n * The link to the last chapter of the book.\r\n */\r\n lastChapterApiLink: string;\r\n\r\n /**\r\n * The number of chapters that the book contains.\r\n */\r\n numberOfChapters: number;\r\n\r\n /**\r\n * The number of verses that the book contains.\r\n */\r\n totalNumberOfVerses: number;\r\n}\r\n\r\n/**\r\n * Defines an interface that contains information about a book chapter.\r\n */\r\nexport interface ApiTranslationBookChapter extends TranslationBookChapter {\r\n /**\r\n * The translation information for the book chapter.\r\n */\r\n translation: ApiTranslation;\r\n\r\n /**\r\n * The book information for the book chapter.\r\n */\r\n book: ApiTranslationBook;\r\n\r\n /**\r\n * The link to this chapter.\r\n */\r\n thisChapterLink: string;\r\n\r\n /**\r\n * The link to the next chapter.\r\n * Null if this is the last chapter in the translation.\r\n */\r\n nextChapterApiLink: string | null;\r\n\r\n /**\r\n * The links to the audio versions for the next chapter.\r\n * Null if this is the last chapter in the translation.\r\n */\r\n nextChapterAudioLinks: TranslationBookChapterAudioLinks | null;\r\n\r\n /**\r\n * The link to the previous chapter.\r\n * Null if this is the first chapter in the translation.\r\n */\r\n previousChapterApiLink: string | null;\r\n\r\n /**\r\n * The links to the audio versions for the previous chapter.\r\n * Null if this is the first chapter in the translation.\r\n */\r\n previousChapterAudioLinks: TranslationBookChapterAudioLinks | null;\r\n\r\n /**\r\n * The number of verses that the chapter contains.\r\n */\r\n numberOfVerses: number;\r\n}\r\n\r\n/**\r\n * Defines an interface that contains information about a book chapter.\r\n */\r\nexport interface ApiCommentaryBookChapter extends CommentaryBookChapter {\r\n /**\r\n * The commentary information for the book chapter.\r\n */\r\n commentary: ApiCommentary;\r\n\r\n /**\r\n * The book information for the book chapter.\r\n */\r\n book: ApiCommentaryBook;\r\n\r\n /**\r\n * The link to this chapter.\r\n */\r\n thisChapterLink: string;\r\n\r\n /**\r\n * The link to the next chapter.\r\n * Null if this is the last chapter in the translation.\r\n */\r\n nextChapterApiLink: string | null;\r\n\r\n /**\r\n * The link to the previous chapter.\r\n * Null if this is the first chapter in the translation.\r\n */\r\n previousChapterApiLink: string | null;\r\n\r\n /**\r\n * The number of verses that the chapter contains.\r\n */\r\n numberOfVerses: number;\r\n}\r\n\r\nexport interface ApiTranslationBookChapterAudio {\r\n /**\r\n * The chapter that the audio is for.\r\n */\r\n chapter: ApiTranslationBookChapter;\r\n\r\n /**\r\n * The link that the audio should be placed at.\r\n */\r\n link: string;\r\n\r\n /**\r\n * The original URL of the audio.\r\n */\r\n originalUrl: string;\r\n}\r\n\r\n/**\r\n * The options for generating the API.\r\n */\r\nexport interface GenerateApiOptions {\r\n /**\r\n * Whether to use the common name for the book chapter API link. If false, then book IDs are used.\r\n * Audio URLs will always use the book ID.\r\n * Defaults to false.\r\n */\r\n useCommonName?: boolean;\r\n\r\n /**\r\n * Whether to replace the audio URLs in the dataset with ones that are hosted locally.\r\n * If true, then the audio URLs in the dataset will be replaced with ones that reference files hosted by the API itself.\r\n * If false, then the audio URLs in the dataset will be left as is.\r\n * Defaults to false.\r\n */\r\n generateAudioFiles?: boolean;\r\n\r\n /**\r\n * Gets the english name of the given language.\r\n * If not provided, then the english name for the language will be unknown and omitted.\r\n * @param language The language to get the english name for.\r\n */\r\n getEnglishName?: (language: string) => string | null | undefined;\r\n\r\n /**\r\n * Gets the native name of the given language.\r\n * If not provided, then the native name for the language will be unknown and omitted.\r\n * @param language The language to get the native name for.\r\n */\r\n getNativeName?: (language: string) => string | null | undefined;\r\n\r\n /**\r\n * The prefix that should be added to paths that are generated.\r\n */\r\n pathPrefix?: string;\r\n}\r\n\r\n/**\r\n * Generates the API output for the given dataset.\r\n * @param dataset The dataset to generate the API for.\r\n * @param options The options for generating the API.\r\n */\r\nexport function generateApiForDataset(\r\n dataset: DatasetOutput,\r\n options: GenerateApiOptions = {}\r\n): ApiOutput {\r\n const { useCommonName, pathPrefix } = options;\r\n const apiPathPrefix = pathPrefix ? pathPrefix : '';\r\n let api: ApiOutput = {\r\n availableTranslations: {\r\n translations: [],\r\n },\r\n translationBooks: [],\r\n translationBookChapters: [],\r\n translationBookChapterAudio: [],\r\n availableCommentaries: {\r\n commentaries: [],\r\n },\r\n commentaryBookChapters: [],\r\n commentaryBooks: [],\r\n pathPrefix: apiPathPrefix,\r\n };\r\n\r\n const getNativeName = options.getNativeName;\r\n const getEnglishName = options.getEnglishName;\r\n\r\n for (let { books, ...translation } of dataset.translations) {\r\n const apiTranslation: ApiTranslation = {\r\n ...translation,\r\n availableFormats: ['json'],\r\n listOfBooksApiLink: listOfBooksApiLink(\r\n translation.id,\r\n apiPathPrefix\r\n ),\r\n numberOfBooks: books.length,\r\n totalNumberOfChapters: 0,\r\n totalNumberOfVerses: 0,\r\n languageName: getNativeName\r\n ? getNativeName(translation.language) ?? undefined\r\n : undefined,\r\n languageEnglishName: getEnglishName\r\n ? getEnglishName(translation.language) ?? undefined\r\n : undefined,\r\n };\r\n\r\n const translationBooks: ApiTranslationBooks = {\r\n translation: apiTranslation,\r\n books: [],\r\n };\r\n\r\n let translationChapters: ApiTranslationBookChapter[] = [];\r\n\r\n for (let { chapters, ...book } of books) {\r\n const apiBook: ApiTranslationBook = {\r\n ...book,\r\n firstChapterApiLink: bookChapterApiLink(\r\n translation.id,\r\n getBookLink(book),\r\n 1,\r\n 'json',\r\n apiPathPrefix\r\n ),\r\n lastChapterApiLink: bookChapterApiLink(\r\n translation.id,\r\n getBookLink(book),\r\n chapters.length,\r\n 'json',\r\n apiPathPrefix\r\n ),\r\n numberOfChapters: chapters.length,\r\n totalNumberOfVerses: 0,\r\n };\r\n\r\n for (let { chapter, thisChapterAudioLinks } of chapters) {\r\n const audio: TranslationBookChapterAudioLinks = {};\r\n const apiBookChapter: ApiTranslationBookChapter = {\r\n translation: apiTranslation,\r\n book: apiBook,\r\n chapter: chapter,\r\n thisChapterLink: bookChapterApiLink(\r\n translation.id,\r\n getBookLink(book),\r\n chapter.number,\r\n 'json',\r\n apiPathPrefix\r\n ),\r\n thisChapterAudioLinks: audio,\r\n nextChapterApiLink: null,\r\n nextChapterAudioLinks: null,\r\n previousChapterApiLink: null,\r\n previousChapterAudioLinks: null,\r\n numberOfVerses: 0,\r\n };\r\n\r\n for (let reader in thisChapterAudioLinks) {\r\n if (options.generateAudioFiles) {\r\n const apiAudio: ApiTranslationBookChapterAudio = {\r\n chapter: apiBookChapter,\r\n link: bookChapterAudioApiLink(\r\n translation.id,\r\n getBookLink(book),\r\n chapter.number,\r\n reader,\r\n apiPathPrefix\r\n ),\r\n originalUrl: thisChapterAudioLinks[reader],\r\n };\r\n audio[reader] = apiAudio.link;\r\n api.translationBookChapterAudio.push(apiAudio);\r\n } else {\r\n audio[reader] = thisChapterAudioLinks[reader];\r\n }\r\n }\r\n\r\n for (let c of chapter.content) {\r\n if (c.type === 'verse') {\r\n apiBookChapter.numberOfVerses++;\r\n }\r\n }\r\n\r\n apiBook.totalNumberOfVerses += apiBookChapter.numberOfVerses;\r\n\r\n translationChapters.push(apiBookChapter);\r\n api.translationBookChapters.push(apiBookChapter);\r\n }\r\n\r\n translationBooks.books.push(apiBook);\r\n\r\n apiTranslation.totalNumberOfChapters += apiBook.numberOfChapters;\r\n apiTranslation.totalNumberOfVerses += apiBook.totalNumberOfVerses;\r\n }\r\n\r\n for (let i = 0; i < translationChapters.length; i++) {\r\n if (i > 0) {\r\n translationChapters[i].previousChapterApiLink =\r\n bookChapterApiLink(\r\n translation.id,\r\n getBookLink(translationChapters[i - 1].book),\r\n translationChapters[i - 1].chapter.number,\r\n 'json',\r\n apiPathPrefix\r\n );\r\n translationChapters[i].previousChapterAudioLinks =\r\n translationChapters[i - 1].thisChapterAudioLinks;\r\n }\r\n\r\n if (i < translationChapters.length - 1) {\r\n translationChapters[i].nextChapterApiLink = bookChapterApiLink(\r\n translation.id,\r\n getBookLink(translationChapters[i + 1].book),\r\n translationChapters[i + 1].chapter.number,\r\n 'json',\r\n apiPathPrefix\r\n );\r\n translationChapters[i].nextChapterAudioLinks =\r\n translationChapters[i + 1].thisChapterAudioLinks;\r\n }\r\n }\r\n\r\n api.availableTranslations.translations.push(apiTranslation);\r\n api.translationBooks.push(translationBooks);\r\n }\r\n\r\n for (let { books, ...commentary } of dataset.commentaries) {\r\n const apiCommentary: ApiCommentary = {\r\n ...commentary,\r\n availableFormats: ['json'],\r\n listOfBooksApiLink: listOfCommentaryBooksApiLink(\r\n commentary.id,\r\n apiPathPrefix\r\n ),\r\n numberOfBooks: books.length,\r\n totalNumberOfChapters: 0,\r\n totalNumberOfVerses: 0,\r\n languageName: getNativeName\r\n ? getNativeName(commentary.language) ?? undefined\r\n : undefined,\r\n languageEnglishName: getEnglishName\r\n ? getEnglishName(commentary.language) ?? undefined\r\n : undefined,\r\n };\r\n\r\n const commentaryBooks: ApiCommentaryBooks = {\r\n commentary: apiCommentary,\r\n books: [],\r\n };\r\n\r\n let commentaryChapters: ApiCommentaryBookChapter[] = [];\r\n\r\n for (let { chapters, ...book } of books) {\r\n const apiBook: ApiCommentaryBook = {\r\n ...book,\r\n firstChapterApiLink: bookCommentaryChapterApiLink(\r\n commentary.id,\r\n getBookLink(book),\r\n 1,\r\n 'json',\r\n apiPathPrefix\r\n ),\r\n lastChapterApiLink: bookCommentaryChapterApiLink(\r\n commentary.id,\r\n getBookLink(book),\r\n chapters.length,\r\n 'json',\r\n apiPathPrefix\r\n ),\r\n numberOfChapters: chapters.length,\r\n totalNumberOfVerses: 0,\r\n };\r\n\r\n for (let { chapter } of chapters) {\r\n const apiBookChapter: ApiCommentaryBookChapter = {\r\n commentary: apiCommentary,\r\n book: apiBook,\r\n chapter: chapter,\r\n thisChapterLink: bookCommentaryChapterApiLink(\r\n commentary.id,\r\n getBookLink(book),\r\n chapter.number,\r\n 'json',\r\n apiPathPrefix\r\n ),\r\n nextChapterApiLink: null,\r\n previousChapterApiLink: null,\r\n numberOfVerses: 0,\r\n };\r\n\r\n for (let c of chapter.content) {\r\n if (c.type === 'verse') {\r\n apiBookChapter.numberOfVerses++;\r\n }\r\n }\r\n\r\n apiBook.totalNumberOfVerses += apiBookChapter.numberOfVerses;\r\n\r\n commentaryChapters.push(apiBookChapter);\r\n api.commentaryBookChapters.push(apiBookChapter);\r\n }\r\n\r\n commentaryBooks.books.push(apiBook);\r\n\r\n apiCommentary.totalNumberOfChapters += apiBook.numberOfChapters;\r\n apiCommentary.totalNumberOfVerses += apiBook.totalNumberOfVerses;\r\n }\r\n\r\n for (let i = 0; i < commentaryChapters.length; i++) {\r\n if (i > 0) {\r\n commentaryChapters[i].previousChapterApiLink =\r\n bookCommentaryChapterApiLink(\r\n commentary.id,\r\n getBookLink(commentaryChapters[i - 1].book),\r\n commentaryChapters[i - 1].chapter.number,\r\n 'json',\r\n apiPathPrefix\r\n );\r\n // commentaryChapters[i].previousChapterAudioLinks =\r\n // commentaryChapters[i - 1].thisChapterAudioLinks;\r\n }\r\n\r\n if (i < commentaryChapters.length - 1) {\r\n commentaryChapters[i].nextChapterApiLink =\r\n bookCommentaryChapterApiLink(\r\n commentary.id,\r\n getBookLink(commentaryChapters[i + 1].book),\r\n commentaryChapters[i + 1].chapter.number,\r\n 'json',\r\n apiPathPrefix\r\n );\r\n // commentaryChapters[i].nextChapterAudioLinks =\r\n // commentaryChapters[i + 1].thisChapterAudioLinks;\r\n }\r\n }\r\n\r\n api.availableCommentaries.commentaries.push(apiCommentary);\r\n api.commentaryBooks.push(commentaryBooks);\r\n }\r\n\r\n return api;\r\n\r\n function getBookLink(book: TranslationBook | CommentaryBook): string {\r\n return useCommonName ? book.commonName : book.id;\r\n }\r\n}\r\n\r\n/**\r\n * Generates the output files for the given API.\r\n * @param api The API that the files should be generated for.\r\n */\r\nexport function generateFilesForApi(api: ApiOutput): OutputFile[] {\r\n let files: OutputFile[] = [];\r\n\r\n files.push(\r\n jsonFile(\r\n `${api.pathPrefix}/api/available_translations.json`,\r\n api.availableTranslations,\r\n true\r\n )\r\n );\r\n for (let translationBooks of api.translationBooks) {\r\n files.push(\r\n jsonFile(\r\n translationBooks.translation.listOfBooksApiLink,\r\n translationBooks\r\n )\r\n );\r\n }\r\n\r\n for (let bookChapter of api.translationBookChapters) {\r\n files.push(jsonFile(bookChapter.thisChapterLink, bookChapter));\r\n }\r\n\r\n for (let audio of api.translationBookChapterAudio) {\r\n files.push(downloadedFile(audio.link, audio.originalUrl));\r\n }\r\n\r\n files.push(\r\n jsonFile(\r\n `${api.pathPrefix}/api/available_commentaries.json`,\r\n api.availableCommentaries,\r\n true\r\n )\r\n );\r\n for (let commentaryBooks of api.commentaryBooks) {\r\n files.push(\r\n jsonFile(\r\n commentaryBooks.commentary.listOfBooksApiLink,\r\n commentaryBooks\r\n )\r\n );\r\n }\r\n\r\n for (let bookChapter of api.commentaryBookChapters) {\r\n files.push(jsonFile(bookChapter.thisChapterLink, bookChapter));\r\n }\r\n\r\n // for (let audio of api.translationBookChapterAudio) {\r\n // files.push(downloadedFile(audio.link, audio.originalUrl));\r\n // }\r\n\r\n return files;\r\n}\r\n\r\n/**\r\n * Generates the output files for the given datasets.\r\n * @param datasets The datasets to generate the output files for.\r\n * @param options The options for generating the API files.\r\n */\r\nexport async function* generateOutputFilesFromDatasets(\r\n datasets: AsyncIterable<DatasetOutput>,\r\n options?: GenerateApiOptions\r\n): AsyncGenerator<OutputFile[]> {\r\n for await (let dataset of datasets) {\r\n const api = generateApiForDataset(dataset, options);\r\n const files = generateFilesForApi(api);\r\n\r\n yield files;\r\n }\r\n}\r\n\r\n/**\r\n * Gets the API Link for the list of books endpoint for a translation.\r\n * @param translationId The ID of the translation.\r\n * @returns\r\n */\r\nexport function listOfBooksApiLink(\r\n translationId: string,\r\n prefix: string = ''\r\n): string {\r\n return `${prefix}/api/${translationId}/books.json`;\r\n}\r\n\r\n/**\r\n * Gets the API Link for the list of books endpoint for a commentary.\r\n * @param commentaryId The ID of the commentary.\r\n * @returns\r\n */\r\nexport function listOfCommentaryBooksApiLink(\r\n commentaryId: string,\r\n prefix: string = ''\r\n): string {\r\n return `${prefix}/api/c/${commentaryId}/books.json`;\r\n}\r\n\r\n/**\r\n * Getes the API link for a book chapter.\r\n * @param translationId The ID of the translation.\r\n * @param commonName The name of the book.\r\n * @param chapterNumber The number of the book.\r\n * @param extension The extension of the file.\r\n */\r\nexport function bookChapterApiLink(\r\n translationId: string,\r\n commonName: string,\r\n chapterNumber: number,\r\n extension: string,\r\n prefix: string = ''\r\n) {\r\n return `${prefix}/api/${translationId}/${replaceSpacesWithUnderscores(\r\n commonName\r\n )}/${chapterNumber}.${extension}`;\r\n}\r\n\r\n/**\r\n * Getes the API link for a book chapter.\r\n * @param translationId The ID of the translation.\r\n * @param commonName The name of the book.\r\n * @param chapterNumber The number of the book.\r\n * @param extension The extension of the file.\r\n */\r\nexport function bookCommentaryChapterApiLink(\r\n translationId: string,\r\n commonName: string,\r\n chapterNumber: number,\r\n extension: string,\r\n prefix: string = ''\r\n) {\r\n return `${prefix}/api/c/${translationId}/${replaceSpacesWithUnderscores(\r\n commonName\r\n )}/${chapterNumber}.${extension}`;\r\n}\r\n\r\nexport function bookChapterAudioApiLink(\r\n translationId: string,\r\n bookId: string,\r\n chapterNumber: number,\r\n reader: string,\r\n prefix: string = ''\r\n) {\r\n return `${prefix}/api/${translationId}/${replaceSpacesWithUnderscores(\r\n bookId\r\n )}/${chapterNumber}.${reader}.mp3`;\r\n}\r\n\r\nexport function jsonFile(\r\n path: string,\r\n content: any,\r\n mergable?: boolean\r\n): OutputFile {\r\n return {\r\n path,\r\n content,\r\n mergable,\r\n };\r\n}\r\n\r\nexport function downloadedFile(path: string, url: string): OutputFile {\r\n return {\r\n path,\r\n content: () => fetch(url).then((response) => response.body),\r\n };\r\n}\r\n\r\nexport function replaceSpacesWithUnderscores(str: string): string {\r\n return str.replace(/[<>:\"/\\\\|?*\\s]/g, '_');\r\n}\r\n"],
5
+ "mappings": ";AA6ZO,gBAAS,sBACZ,SACA,UAA8B,CAAC,GACtB;AACT,QAAM,EAAE,eAAe,WAAW,IAAI;AACtC,QAAM,gBAAgB,aAAa,aAAa;AAChD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AAiB,IACX;AACN,SAAO,GAAG,MAAM,QAAQ,aAAa;AACzC;AAOO,gBAAS,6BACZ,cACA,SAAiB,IACX;AACN,SAAO,GAAG,MAAM,UAAU,YAAY;AAC1C;AASO,gBAAS,mBACZ,eACA,YACA,eACA,WACA,SAAiB,IACnB;AACE,SAAO,GAAG,MAAM,QAAQ,aAAa,IAAI;AAAA,IACrC;AAAA,EACJ,CAAC,IAAI,aAAa,IAAI,SAAS;AACnC;AASO,gBAAS,6BACZ,eACA,YACA,eACA,WACA,SAAiB,IACnB;AACE,SAAO,GAAG,MAAM,UAAU,aAAa,IAAI;AAAA,IACvC;AAAA,EACJ,CAAC,IAAI,aAAa,IAAI,SAAS;AACnC;AAEO,gBAAS,wBACZ,eACA,QACA,eACA,QACA,SAAiB,IACnB;AACE,SAAO,GAAG,MAAM,QAAQ,aAAa,IAAI;AAAA,IACrC;AAAA,EACJ,CAAC,IAAI,aAAa,IAAI,MAAM;AAChC;AAEO,gBAAS,SACZ,MACA,SACA,UACU;AACV,SAAO;AAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,EACJ;AACJ;AAEO,gBAAS,eAAe,MAAc,KAAyB;AAClE,SAAO;AAAA,IACH;AAAA,IACA,SAAS,MAAM,MAAM,GAAG,EAAE,KAAK,CAAC,aAAa,SAAS,IAAI;AAAA,EAC9D;AACJ;AAEO,gBAAS,6BAA6B,KAAqB;AAC9D,SAAO,IAAI,QAAQ,mBAAmB,GAAG;AAC7C;",
6
6
  "names": []
7
7
  }
@@ -5,14 +5,18 @@ import { bookIdMap, bookOrderMap } from "./book-order.js";
5
5
  import { omit, sortBy, sortedIndexBy } from "lodash";
6
6
  import { getAudioUrlsForChapter } from "./audio.js";
7
7
  import { CodexParser } from "../parser/codex-parser.js";
8
+ import { CommentaryCsvParser } from "../parser/commentary-csv-parser.js";
8
9
  export function generateDataset(files, parser = new globalThis.DOMParser()) {
9
10
  let output = {
10
- translations: []
11
+ translations: [],
12
+ commentaries: []
11
13
  };
12
14
  let usfmParser = new UsfmParser();
13
15
  let usxParser = new USXParser(parser);
14
16
  let codexParser = new CodexParser();
17
+ let csvCommentaryParser = new CommentaryCsvParser();
15
18
  let parsedTranslations = /* @__PURE__ */ new Map();
19
+ let parsedCommentaries = /* @__PURE__ */ new Map();
16
20
  const unknownLanguages = /* @__PURE__ */ new Set();
17
21
  for (let file of files) {
18
22
  try {
@@ -23,6 +27,8 @@ export function generateDataset(files, parser = new globalThis.DOMParser()) {
23
27
  parser2 = usxParser;
24
28
  } else if (file.fileType === "json") {
25
29
  parser2 = codexParser;
30
+ } else if (file.fileType === "commentary/csv") {
31
+ parser2 = csvCommentaryParser;
26
32
  } else {
27
33
  console.warn(
28
34
  "[generate] File does not have a valid type!",
@@ -31,101 +37,175 @@ export function generateDataset(files, parser = new globalThis.DOMParser()) {
31
37
  continue;
32
38
  }
33
39
  const parsed = parser2.parse(file.content);
34
- const id = parsed.id;
35
- if (!id) {
36
- console.warn(
37
- "[generate] File does not have a valid book ID!",
38
- file.name,
39
- id
40
- );
41
- continue;
42
- }
43
- const order = bookOrderMap.get(id);
44
- if (typeof order !== "number") {
45
- console.warn("[generate] Book does not have an order!", id);
46
- continue;
47
- }
48
- const bookMap = bookIdMap.get(file.metadata.translation.language);
49
- if (!bookMap) {
50
- if (!unknownLanguages.has(file.metadata.translation.language)) {
51
- console.warn(
52
- "[generate] File does not have a known language!",
53
- file.name,
54
- file.metadata.translation.language
55
- );
56
- unknownLanguages.add(file.metadata.translation.language);
57
- }
40
+ if (parsed.type === "root") {
41
+ addTranslationTree(file, parsed);
42
+ } else {
43
+ addCommentaryTree(file, parsed);
58
44
  }
59
- const bookName = bookMap?.get(id);
60
- if (!!bookMap && !bookName) {
45
+ } catch (err) {
46
+ console.error(
47
+ `[generate] Error occurred while parsing ${file.name}`,
48
+ err
49
+ );
50
+ }
51
+ }
52
+ function addTranslationTree(file, parsed) {
53
+ const id = parsed.id;
54
+ if (!id) {
55
+ console.warn(
56
+ "[generate] File does not have a valid book ID!",
57
+ file.name,
58
+ id
59
+ );
60
+ return;
61
+ }
62
+ const order = bookOrderMap.get(id);
63
+ if (typeof order !== "number") {
64
+ console.warn("[generate] Book does not have an order!", id);
65
+ return;
66
+ }
67
+ const bookMap = bookIdMap.get(file.metadata.language);
68
+ if (!bookMap) {
69
+ if (!unknownLanguages.has(file.metadata.language)) {
61
70
  console.warn(
62
- "[generate] Book name not found for ID!",
71
+ "[generate] File does not have a known language!",
63
72
  file.name,
64
- id
73
+ file.metadata.language
65
74
  );
75
+ unknownLanguages.add(file.metadata.language);
66
76
  }
67
- let translation = parsedTranslations.get(
68
- file.metadata.translation.id
77
+ }
78
+ const bookName = bookMap?.get(id);
79
+ if (!!bookMap && !bookName) {
80
+ console.warn(
81
+ "[generate] Book name not found for ID!",
82
+ file.name,
83
+ id
69
84
  );
70
- if (!translation) {
71
- translation = {
72
- ...omit(file.metadata.translation, "direction"),
73
- textDirection: file.metadata.translation.direction,
74
- books: []
75
- };
76
- output.translations.push(translation);
77
- parsedTranslations.set(
78
- file.metadata.translation.id,
79
- translation
80
- );
85
+ }
86
+ let translation = parsedTranslations.get(file.metadata.id);
87
+ if (!translation) {
88
+ translation = {
89
+ ...omit(file.metadata, "direction"),
90
+ textDirection: file.metadata.direction,
91
+ books: []
92
+ };
93
+ output.translations.push(translation);
94
+ parsedTranslations.set(file.metadata.id, translation);
95
+ }
96
+ const name = parsed.header ?? bookName?.commonName ?? parsed.title;
97
+ if (!name) {
98
+ console.warn(
99
+ "[generate] Book does not have a name!",
100
+ file.name,
101
+ id
102
+ );
103
+ return;
104
+ }
105
+ const commonName = bookName?.commonName ?? parsed.header ?? parsed.title ?? id;
106
+ const book = {
107
+ id,
108
+ name,
109
+ commonName,
110
+ title: parsed.title ?? null,
111
+ order,
112
+ chapters: []
113
+ };
114
+ for (let content of parsed.content) {
115
+ if (content.type === "chapter") {
116
+ book.chapters.push({
117
+ chapter: {
118
+ number: content.number,
119
+ content: content.content,
120
+ footnotes: content.footnotes
121
+ },
122
+ thisChapterAudioLinks: getAudioUrlsForChapter(
123
+ translation.id,
124
+ id,
125
+ content.number
126
+ )
127
+ });
81
128
  }
82
- const name = parsed.header ?? bookName?.commonName ?? parsed.title;
83
- if (!name) {
129
+ }
130
+ book.chapters = sortBy(book.chapters, (c) => c.chapter.number);
131
+ const index = sortedIndexBy(translation.books, book, (b) => b.order);
132
+ translation.books.splice(index, 0, book);
133
+ }
134
+ function addCommentaryTree(file, parsed) {
135
+ let commentary = parsedCommentaries.get(file.metadata.id);
136
+ if (!commentary) {
137
+ commentary = {
138
+ ...omit(file.metadata, "direction"),
139
+ textDirection: file.metadata.direction,
140
+ books: []
141
+ };
142
+ output.commentaries.push(commentary);
143
+ parsedCommentaries.set(file.metadata.id, commentary);
144
+ }
145
+ for (let parsedBook of parsed.books) {
146
+ let book = commentary.books.find((b) => b.id === parsedBook.book);
147
+ if (book && book.introduction) {
84
148
  console.warn(
85
- "[generate] Book does not have a name!",
149
+ "[generate] Book already exists in commentary!",
86
150
  file.name,
87
- id
151
+ parsedBook.book
88
152
  );
89
153
  continue;
90
154
  }
91
- const commonName = bookName?.commonName ?? parsed.header ?? parsed.title ?? id;
92
- const book = {
93
- id,
94
- name,
95
- commonName,
96
- title: parsed.title ?? null,
97
- order,
98
- chapters: []
99
- };
100
- for (let content of parsed.content) {
101
- if (content.type === "chapter") {
102
- book.chapters.push({
103
- chapter: {
104
- number: content.number,
105
- content: content.content,
106
- footnotes: content.footnotes
107
- },
108
- thisChapterAudioLinks: getAudioUrlsForChapter(
109
- translation.id,
110
- id,
111
- content.number
112
- )
113
- });
155
+ if (!book) {
156
+ const name = getBookNames(file, file.metadata, parsedBook.book);
157
+ book = {
158
+ id: parsedBook.book,
159
+ order: bookOrderMap.get(parsedBook.book) ?? -1,
160
+ commonName: name?.bookName?.commonName ?? parsedBook.book,
161
+ name: name?.bookName?.commonName ?? parsedBook.book,
162
+ chapters: []
163
+ };
164
+ }
165
+ if (parsedBook.introduction) {
166
+ book.introduction = parsedBook.introduction;
167
+ }
168
+ for (let chapter of parsedBook.chapters) {
169
+ let data = {
170
+ number: chapter.number,
171
+ content: chapter.verses
172
+ };
173
+ if (chapter.introduction) {
174
+ data.introduction = chapter.introduction;
114
175
  }
176
+ book.chapters.push({
177
+ chapter: data
178
+ });
115
179
  }
116
180
  book.chapters = sortBy(book.chapters, (c) => c.chapter.number);
117
- const index = sortedIndexBy(
118
- translation.books,
119
- book,
120
- (b) => b.order
121
- );
122
- translation.books.splice(index, 0, book);
123
- } catch (err) {
124
- console.error(
125
- `[generate] Error occurred while parsing ${file.name}`,
126
- err
181
+ commentary.books.push(book);
182
+ }
183
+ commentary.books = sortBy(commentary.books, (b) => b.order);
184
+ }
185
+ function getBookNames(file, metadata, id) {
186
+ const bookMap = bookIdMap.get(metadata.language);
187
+ if (!bookMap) {
188
+ if (!unknownLanguages.has(metadata.language)) {
189
+ console.warn(
190
+ "[generate] File does not have a known language!",
191
+ file.name,
192
+ metadata.language
193
+ );
194
+ unknownLanguages.add(metadata.language);
195
+ }
196
+ }
197
+ const bookName = bookMap?.get(id);
198
+ if (!!bookMap && !bookName) {
199
+ console.warn(
200
+ "[generate] Book name not found for ID!",
201
+ file.name,
202
+ id
127
203
  );
204
+ return null;
128
205
  }
206
+ return {
207
+ bookName
208
+ };
129
209
  }
130
210
  return output;
131
211
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../generation/dataset.ts"],
4
- "sourcesContent": ["import { UsfmParser } from '../parser/usfm-parser.js';\r\nimport { USXParser } from '../parser/usx-parser.js';\r\nimport {\r\n InputFile,\r\n Translation,\r\n TranslationBook,\r\n TranslationBookChapter,\r\n} from './common-types.js';\r\nimport { bookIdMap, bookOrderMap } from './book-order.js';\r\nimport { omit, sortBy, sortedIndexBy } from 'lodash';\r\nimport { getAudioUrlsForChapter } from './audio.js';\r\nimport { CodexParser } from '../parser/codex-parser.js';\r\n\r\n/**\r\n * Defines an interface that contains generated dataset info.\r\n */\r\nexport interface DatasetOutput {\r\n /**\r\n * The list of translations that are available in the dataset.\r\n */\r\n translations: DatasetTranslation[];\r\n}\r\n\r\n/**\r\n * Defines a translation that is used in the dataset.\r\n */\r\nexport interface DatasetTranslation extends Translation {\r\n /**\r\n * The list of books that are available for the translation.\r\n */\r\n books: DatasetTranslationBook[];\r\n}\r\n\r\n/**\r\n * Defines a translation book that is used in the dataset.\r\n */\r\nexport interface DatasetTranslationBook extends TranslationBook {\r\n /**\r\n * The list of chapters that are available for the book.\r\n */\r\n chapters: TranslationBookChapter[];\r\n}\r\n\r\n/**\r\n * Generates a list of output files from the given list of input files.\r\n * @param file The list of files.\r\n */\r\nexport function generateDataset(\r\n files: InputFile[],\r\n parser: DOMParser = new globalThis.DOMParser()\r\n): DatasetOutput {\r\n let output: DatasetOutput = {\r\n translations: [],\r\n };\r\n\r\n let usfmParser = new UsfmParser();\r\n let usxParser = new USXParser(parser);\r\n let codexParser = new CodexParser();\r\n\r\n let parsedTranslations = new Map<string, DatasetTranslation>();\r\n\r\n const unknownLanguages = new Set<string>();\r\n for (let file of files) {\r\n try {\r\n let parser: UsfmParser | USXParser | CodexParser;\r\n if (file.fileType === 'usfm') {\r\n parser = usfmParser;\r\n } else if (file.fileType === 'usx') {\r\n parser = usxParser;\r\n } else if (file.fileType === 'json') {\r\n parser = codexParser;\r\n } else {\r\n console.warn(\r\n '[generate] File does not have a valid type!',\r\n file.name\r\n );\r\n continue;\r\n }\r\n\r\n const parsed = parser.parse(file.content);\r\n const id = parsed.id;\r\n\r\n if (!id) {\r\n console.warn(\r\n '[generate] File does not have a valid book ID!',\r\n file.name,\r\n id\r\n );\r\n continue;\r\n }\r\n\r\n const order = bookOrderMap.get(id);\r\n\r\n if (typeof order !== 'number') {\r\n console.warn('[generate] Book does not have an order!', id);\r\n continue;\r\n }\r\n\r\n const bookMap = bookIdMap.get(file.metadata.translation.language);\r\n\r\n if (!bookMap) {\r\n if (!unknownLanguages.has(file.metadata.translation.language)) {\r\n console.warn(\r\n '[generate] File does not have a known language!',\r\n file.name,\r\n file.metadata.translation.language\r\n );\r\n unknownLanguages.add(file.metadata.translation.language);\r\n }\r\n }\r\n\r\n const bookName = bookMap?.get(id);\r\n\r\n if (!!bookMap && !bookName) {\r\n console.warn(\r\n '[generate] Book name not found for ID!',\r\n file.name,\r\n id\r\n );\r\n }\r\n\r\n let translation = parsedTranslations.get(\r\n file.metadata.translation.id\r\n );\r\n\r\n if (!translation) {\r\n translation = {\r\n ...omit(file.metadata.translation, 'direction'),\r\n textDirection: file.metadata.translation.direction,\r\n books: [],\r\n };\r\n output.translations.push(translation);\r\n parsedTranslations.set(\r\n file.metadata.translation.id,\r\n translation\r\n );\r\n }\r\n\r\n const name = parsed.header ?? bookName?.commonName ?? parsed.title;\r\n\r\n if (!name) {\r\n console.warn(\r\n '[generate] Book does not have a name!',\r\n file.name,\r\n id\r\n );\r\n continue;\r\n }\r\n\r\n const commonName =\r\n bookName?.commonName ?? parsed.header ?? parsed.title ?? id;\r\n\r\n const book: DatasetTranslationBook = {\r\n id: id,\r\n name,\r\n commonName,\r\n title: parsed.title ?? null,\r\n order,\r\n chapters: [],\r\n };\r\n\r\n for (let content of parsed.content) {\r\n if (content.type === 'chapter') {\r\n book.chapters.push({\r\n chapter: {\r\n number: content.number,\r\n content: content.content,\r\n footnotes: content.footnotes,\r\n },\r\n thisChapterAudioLinks: getAudioUrlsForChapter(\r\n translation.id,\r\n id,\r\n content.number\r\n ),\r\n });\r\n }\r\n }\r\n\r\n book.chapters = sortBy(book.chapters, (c) => c.chapter.number);\r\n\r\n const index = sortedIndexBy(\r\n translation.books,\r\n book,\r\n (b) => b.order\r\n );\r\n translation.books.splice(index, 0, book);\r\n } catch (err) {\r\n console.error(\r\n `[generate] Error occurred while parsing ${file.name}`,\r\n err\r\n );\r\n }\r\n }\r\n\r\n return output;\r\n}\r\n"],
5
- "mappings": ";AAAA,SAAS,kBAAkB;AAC3B,SAAS,iBAAiB;AA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AAE,QAAQ,MAAM;AAE7D,YAAM,QAAQ;AAAA,QACV,YAAY;AAAA,QACZ;AAAA,QACA,CAAC,MAAM,EAAE;AAAA,MACb;AACA,kBAAY,MAAM,OAAO,OAAO,GAAG,IAAI;AAAA,IAC3C,SAAS,KAAK;AACV,cAAQ;AAAA,QACJ,2CAA2C,KAAK,IAAI;AAAA,QACpD;AAAA,MACJ;AAAA,IACJ;AAAA,EACJ;AAEA,SAAO;AACX;",
4
+ "sourcesContent": ["import { UsfmParser } from '../parser/usfm-parser.js';\r\nimport { USXParser } from '../parser/usx-parser.js';\r\nimport {\r\n Commentary,\r\n CommentaryBook,\r\n CommentaryBookChapter,\r\n CommentaryChapterData,\r\n InputCommentaryFile,\r\n InputFile,\r\n InputFileBase,\r\n InputTranslationFile,\r\n MetadataBase,\r\n Translation,\r\n TranslationBook,\r\n TranslationBookChapter,\r\n} from './common-types.js';\r\nimport { bookIdMap, bookOrderMap } from './book-order.js';\r\nimport { omit, sortBy, sortedIndexBy } from 'lodash';\r\nimport { getAudioUrlsForChapter } from './audio.js';\r\nimport { CodexParser } from '../parser/codex-parser.js';\r\nimport { CommentaryCsvParser } from '../parser/commentary-csv-parser.js';\r\nimport { CommentaryParseTree, ParseTree } from '../parser/types.js';\r\n\r\n/**\r\n * Defines an interface that contains generated dataset info.\r\n */\r\nexport interface DatasetOutput {\r\n /**\r\n * The list of translations that are available in the dataset.\r\n */\r\n translations: DatasetTranslation[];\r\n\r\n /**\r\n * The list of commentaries that are available in the dataset.\r\n */\r\n commentaries: DatasetCommentary[];\r\n}\r\n\r\n/**\r\n * Defines a translation that is used in the dataset.\r\n */\r\nexport interface DatasetTranslation extends Translation {\r\n /**\r\n * The list of books that are available for the translation.\r\n */\r\n books: DatasetTranslationBook[];\r\n}\r\n\r\n/**\r\n * Defines a commentary that is used in the dataset.\r\n */\r\nexport interface DatasetCommentary extends Commentary {\r\n /**\r\n * The list of books that are available for the translation.\r\n */\r\n books: DatasetCommentaryBook[];\r\n}\r\n\r\n/**\r\n * Defines a translation book that is used in the dataset.\r\n */\r\nexport interface DatasetTranslationBook extends TranslationBook {\r\n /**\r\n * The list of chapters that are available for the book.\r\n */\r\n chapters: TranslationBookChapter[];\r\n}\r\n\r\n/**\r\n * Defines a commentary book that is used in the dataset.\r\n */\r\nexport interface DatasetCommentaryBook extends CommentaryBook {\r\n /**\r\n * The list of chapters that are available for the book.\r\n */\r\n chapters: CommentaryBookChapter[];\r\n}\r\n\r\n/**\r\n * Generates a list of output files from the given list of input files.\r\n * @param file The list of files.\r\n */\r\nexport function generateDataset(\r\n files: InputFile[],\r\n parser: DOMParser = new globalThis.DOMParser()\r\n): DatasetOutput {\r\n let output: DatasetOutput = {\r\n translations: [],\r\n commentaries: [],\r\n };\r\n\r\n let usfmParser = new UsfmParser();\r\n let usxParser = new USXParser(parser);\r\n let codexParser = new CodexParser();\r\n let csvCommentaryParser = new CommentaryCsvParser();\r\n\r\n let parsedTranslations = new Map<string, DatasetTranslation>();\r\n let parsedCommentaries = new Map<string, DatasetCommentary>();\r\n\r\n const unknownLanguages = new Set<string>();\r\n for (let file of files) {\r\n try {\r\n let parser:\r\n | UsfmParser\r\n | USXParser\r\n | CodexParser\r\n | CommentaryCsvParser;\r\n if (file.fileType === 'usfm') {\r\n parser = usfmParser;\r\n } else if (file.fileType === 'usx') {\r\n parser = usxParser;\r\n } else if (file.fileType === 'json') {\r\n parser = codexParser;\r\n } else if (file.fileType === 'commentary/csv') {\r\n parser = csvCommentaryParser;\r\n } else {\r\n console.warn(\r\n '[generate] File does not have a valid type!',\r\n file.name\r\n );\r\n continue;\r\n }\r\n\r\n const parsed = parser.parse(file.content);\r\n\r\n if (parsed.type === 'root') {\r\n addTranslationTree(file as InputTranslationFile, parsed);\r\n } else {\r\n addCommentaryTree(file as InputCommentaryFile, parsed);\r\n }\r\n } catch (err) {\r\n console.error(\r\n `[generate] Error occurred while parsing ${file.name}`,\r\n err\r\n );\r\n }\r\n }\r\n\r\n function addTranslationTree(file: InputTranslationFile, parsed: ParseTree) {\r\n const id = parsed.id;\r\n\r\n if (!id) {\r\n console.warn(\r\n '[generate] File does not have a valid book ID!',\r\n file.name,\r\n id\r\n );\r\n return;\r\n }\r\n\r\n const order = bookOrderMap.get(id);\r\n\r\n if (typeof order !== 'number') {\r\n console.warn('[generate] Book does not have an order!', id);\r\n return;\r\n }\r\n\r\n const bookMap = bookIdMap.get(file.metadata.language);\r\n\r\n if (!bookMap) {\r\n if (!unknownLanguages.has(file.metadata.language)) {\r\n console.warn(\r\n '[generate] File does not have a known language!',\r\n file.name,\r\n file.metadata.language\r\n );\r\n unknownLanguages.add(file.metadata.language);\r\n }\r\n }\r\n\r\n const bookName = bookMap?.get(id);\r\n\r\n if (!!bookMap && !bookName) {\r\n console.warn(\r\n '[generate] Book name not found for ID!',\r\n file.name,\r\n id\r\n );\r\n }\r\n\r\n let translation = parsedTranslations.get(file.metadata.id);\r\n\r\n if (!translation) {\r\n translation = {\r\n ...omit(file.metadata, 'direction'),\r\n textDirection: file.metadata.direction,\r\n books: [],\r\n };\r\n output.translations.push(translation);\r\n parsedTranslations.set(file.metadata.id, translation);\r\n }\r\n\r\n const name = parsed.header ?? bookName?.commonName ?? parsed.title;\r\n\r\n if (!name) {\r\n console.warn(\r\n '[generate] Book does not have a name!',\r\n file.name,\r\n id\r\n );\r\n return;\r\n }\r\n\r\n const commonName =\r\n bookName?.commonName ?? parsed.header ?? parsed.title ?? id;\r\n\r\n const book: DatasetTranslationBook = {\r\n id: id,\r\n name,\r\n commonName,\r\n title: parsed.title ?? null,\r\n order,\r\n chapters: [],\r\n };\r\n\r\n for (let content of parsed.content) {\r\n if (content.type === 'chapter') {\r\n book.chapters.push({\r\n chapter: {\r\n number: content.number,\r\n content: content.content,\r\n footnotes: content.footnotes,\r\n },\r\n thisChapterAudioLinks: getAudioUrlsForChapter(\r\n translation.id,\r\n id,\r\n content.number\r\n ),\r\n });\r\n }\r\n }\r\n\r\n book.chapters = sortBy(book.chapters, (c) => c.chapter.number);\r\n\r\n const index = sortedIndexBy(translation.books, book, (b) => b.order);\r\n translation.books.splice(index, 0, book);\r\n }\r\n\r\n function addCommentaryTree(\r\n file: InputCommentaryFile,\r\n parsed: CommentaryParseTree\r\n ) {\r\n let commentary = parsedCommentaries.get(file.metadata.id);\r\n\r\n if (!commentary) {\r\n commentary = {\r\n ...omit(file.metadata, 'direction'),\r\n textDirection: file.metadata.direction,\r\n books: [],\r\n };\r\n output.commentaries.push(commentary);\r\n parsedCommentaries.set(file.metadata.id, commentary);\r\n }\r\n\r\n for (let parsedBook of parsed.books) {\r\n let book = commentary.books.find((b) => b.id === parsedBook.book);\r\n if (book && book.introduction) {\r\n console.warn(\r\n '[generate] Book already exists in commentary!',\r\n file.name,\r\n parsedBook.book\r\n );\r\n continue;\r\n }\r\n\r\n if (!book) {\r\n const name = getBookNames(file, file.metadata, parsedBook.book);\r\n book = {\r\n id: parsedBook.book,\r\n order: bookOrderMap.get(parsedBook.book) ?? -1,\r\n commonName: name?.bookName?.commonName ?? parsedBook.book,\r\n name: name?.bookName?.commonName ?? parsedBook.book,\r\n chapters: [],\r\n };\r\n }\r\n\r\n if (parsedBook.introduction) {\r\n book.introduction = parsedBook.introduction;\r\n }\r\n\r\n for (let chapter of parsedBook.chapters) {\r\n let data: CommentaryChapterData = {\r\n number: chapter.number,\r\n content: chapter.verses,\r\n };\r\n\r\n if (chapter.introduction) {\r\n data.introduction = chapter.introduction;\r\n }\r\n\r\n book.chapters.push({\r\n chapter: data,\r\n });\r\n }\r\n\r\n book.chapters = sortBy(book.chapters, (c) => c.chapter.number);\r\n commentary.books.push(book);\r\n }\r\n\r\n commentary.books = sortBy(commentary.books, (b) => b.order);\r\n }\r\n\r\n function getBookNames(\r\n file: InputFileBase,\r\n metadata: MetadataBase,\r\n id: string\r\n ) {\r\n const bookMap = bookIdMap.get(metadata.language);\r\n\r\n if (!bookMap) {\r\n if (!unknownLanguages.has(metadata.language)) {\r\n console.warn(\r\n '[generate] File does not have a known language!',\r\n file.name,\r\n metadata.language\r\n );\r\n unknownLanguages.add(metadata.language);\r\n }\r\n }\r\n\r\n const bookName = bookMap?.get(id);\r\n\r\n if (!!bookMap && !bookName) {\r\n console.warn(\r\n '[generate] Book name not found for ID!',\r\n file.name,\r\n id\r\n );\r\n return null;\r\n }\r\n\r\n return {\r\n bookName,\r\n };\r\n }\r\n\r\n return output;\r\n}\r\n"],
5
+ "mappings": ";AAAA,SAAS,kBAAkB;AAC3B,SAAS,iBAAiB;AAe1B,SAAS,WAAW,oBAAoB;AACxC,SAAS,MAAM,QAAQ,qBAAqB;AAC5C,SAAS,8BAA8B;AACvC,SAAS,mBAAmB;AAC5B,SAAS,2BAA2B;AA8D7B,gBAAS,gBACZ,OACA,SAAoB,IAAI,WAAW,UAAU,GAChC;AACb,MAAI,SAAwB;AAAA,IACxB,cAAc,CAAC;AAAA,IACf,cAAc,CAAC;AAAA,EACnB;AAEA,MAAI,aAAa,IAAI,WAAW;AAChC,MAAI,YAAY,IAAI,UAAU,MAAM;AACpC,MAAI,cAAc,IAAI,YAAY;AAClC,MAAI,sBAAsB,IAAI,oBAAoB;AAElD,MAAI,qBAAqB,oBAAI,IAAgC;AAC7D,MAAI,qBAAqB,oBAAI,IAA+B;AAE5D,QAAM,mBAAmB,oBAAI,IAAY;AACzC,WAAS,QAAQ,OAAO;AACpB,QAAI;AACA,UAAIA;AAKJ,UAAI,KAAK,aAAa,QAAQ;AAC1B,QAAAA,UAAS;AAAA,MACb,WAAW,KAAK,aAAa,OAAO;AAChC,QAAAA,UAAS;AAAA,MACb,WAAW,KAAK,aAAa,QAAQ;AACjC,QAAAA,UAAS;AAAA,MACb,WAAW,KAAK,aAAa,kBAAkB;AAC3C,QAAAA,UAAS;AAAA,MACb,OAAO;AACH,gBAAQ;AAAA,UACJ;AAAA,UACA,KAAK;AAAA,QACT;AACA;AAAA,MACJ;AAEA,YAAM,SAASA,QAAO,MAAM,KAAK,OAAO;AAExC,UAAI,OAAO,SAAS,Q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