@helloao/tools 0.0.16 → 0.0.18
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.
- package/dist/cjs/generation/api.cjs +43 -0
- package/dist/cjs/generation/api.cjs.map +2 -2
- package/dist/cjs/parser/codex-parser.cjs +74 -24
- package/dist/cjs/parser/codex-parser.cjs.map +3 -3
- package/dist/esm/generation/api.js +41 -0
- package/dist/esm/generation/api.js.map +2 -2
- package/dist/esm/parser/codex-parser.js +75 -25
- package/dist/esm/parser/codex-parser.js.map +3 -3
- package/package.json +1 -1
- package/dist/types/generation/api.d.ts +0 -658
- package/dist/types/generation/audio.d.ts +0 -20
- package/dist/types/generation/book-order.d.ts +0 -19
- package/dist/types/generation/common-types.d.ts +0 -546
- package/dist/types/generation/dataset.d.ts +0 -84
- package/dist/types/generation/index.d.ts +0 -7
- package/dist/types/index.d.ts +0 -6
- package/dist/types/log.d.ts +0 -23
- package/dist/types/parser/codex-parser.d.ts +0 -140
- package/dist/types/parser/commentary-csv-parser.d.ts +0 -12
- package/dist/types/parser/index.d.ts +0 -8
- package/dist/types/parser/iterators.d.ts +0 -89
- package/dist/types/parser/tyndale-xml-parser.d.ts +0 -8
- package/dist/types/parser/types.d.ts +0 -204
- package/dist/types/parser/usfm-parser.d.ts +0 -135
- package/dist/types/parser/usx-parser.d.ts +0 -37
- package/dist/types/utils.d.ts +0 -48
|
@@ -9,6 +9,7 @@ export function generateApiForDataset(dataset, options = {}) {
|
|
|
9
9
|
translationBooks: [],
|
|
10
10
|
translationBookChapters: [],
|
|
11
11
|
translationBookChapterAudio: [],
|
|
12
|
+
translationComplete: [],
|
|
12
13
|
availableCommentaries: {
|
|
13
14
|
commentaries: []
|
|
14
15
|
},
|
|
@@ -37,6 +38,7 @@ export function generateApiForDataset(dataset, options = {}) {
|
|
|
37
38
|
translation.id,
|
|
38
39
|
apiPathPrefix
|
|
39
40
|
),
|
|
41
|
+
completeTranslationApiLink: options.generateCompleteTranslationFiles ? completeTranslationApiLink(translation.id, apiPathPrefix) : void 0,
|
|
40
42
|
numberOfBooks,
|
|
41
43
|
totalNumberOfChapters: 0,
|
|
42
44
|
totalNumberOfVerses: 0,
|
|
@@ -162,6 +164,32 @@ export function generateApiForDataset(dataset, options = {}) {
|
|
|
162
164
|
}
|
|
163
165
|
api.availableTranslations.translations.push(apiTranslation);
|
|
164
166
|
api.translationBooks.push(translationBooks);
|
|
167
|
+
if (options.generateCompleteTranslationFiles) {
|
|
168
|
+
const completeTranslation = {
|
|
169
|
+
translation: apiTranslation,
|
|
170
|
+
books: translationBooks.books.map((book) => {
|
|
171
|
+
const bookChapters = translationChapters.filter(
|
|
172
|
+
(ch) => ch.book.id === book.id
|
|
173
|
+
);
|
|
174
|
+
return {
|
|
175
|
+
id: book.id,
|
|
176
|
+
name: book.name,
|
|
177
|
+
commonName: book.commonName,
|
|
178
|
+
title: book.title,
|
|
179
|
+
order: book.order,
|
|
180
|
+
numberOfChapters: book.numberOfChapters,
|
|
181
|
+
totalNumberOfVerses: book.totalNumberOfVerses,
|
|
182
|
+
isApocryphal: book.isApocryphal,
|
|
183
|
+
chapters: bookChapters.map((ch) => ({
|
|
184
|
+
numberOfVerses: ch.numberOfVerses,
|
|
185
|
+
thisChapterAudioLinks: ch.thisChapterAudioLinks,
|
|
186
|
+
chapter: ch.chapter
|
|
187
|
+
}))
|
|
188
|
+
};
|
|
189
|
+
})
|
|
190
|
+
};
|
|
191
|
+
api.translationComplete.push(completeTranslation);
|
|
192
|
+
}
|
|
165
193
|
}
|
|
166
194
|
for (let { books, profiles, ...commentary } of dataset.commentaries) {
|
|
167
195
|
const apiCommentary = {
|
|
@@ -436,6 +464,16 @@ export function generateFilesForApi(api) {
|
|
|
436
464
|
for (let audio of api.translationBookChapterAudio) {
|
|
437
465
|
files.push(downloadedFile(audio.link, audio.originalUrl));
|
|
438
466
|
}
|
|
467
|
+
for (let complete of api.translationComplete) {
|
|
468
|
+
if (complete.translation.completeTranslationApiLink) {
|
|
469
|
+
files.push(
|
|
470
|
+
jsonFile(
|
|
471
|
+
complete.translation.completeTranslationApiLink,
|
|
472
|
+
complete
|
|
473
|
+
)
|
|
474
|
+
);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
439
477
|
files.push(
|
|
440
478
|
jsonFile(
|
|
441
479
|
`${api.pathPrefix}/api/available_commentaries.json`,
|
|
@@ -502,6 +540,9 @@ export async function* generateOutputFilesFromDatasets(datasets, options) {
|
|
|
502
540
|
export function listOfBooksApiLink(translationId, prefix = "") {
|
|
503
541
|
return `${prefix}/api/${translationId}/books.json`;
|
|
504
542
|
}
|
|
543
|
+
export function completeTranslationApiLink(translationId, prefix = "") {
|
|
544
|
+
return `${prefix}/api/${translationId}/complete.json`;
|
|
545
|
+
}
|
|
505
546
|
export function listOfCommentaryBooksApiLink(commentaryId, prefix = "") {
|
|
506
547
|
return `${prefix}/api/c/${commentaryId}/books.json`;
|
|
507
548
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../generation/api.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n Commentary,\n CommentaryBook,\n CommentaryBookChapter,\n CommentaryProfile,\n Dataset,\n DatasetBook,\n DatasetBookChapter,\n OutputFile,\n Translation,\n TranslationBook,\n TranslationBookChapter,\n TranslationBookChapterAudioLinks,\n} from './common-types.js';\nimport { DatasetOutput } from './dataset.js';\n\n/**\n * Defines the output of the API generation.\n */\nexport interface ApiOutput {\n /**\n * The list of available translations.\n * This maps to the /api/available-translations.json endpoint.\n */\n availableTranslations: ApiAvailableTranslations;\n\n /**\n * The list of books for each translation.\n * This maps to the /api/:translationId/books.json endpoint.\n */\n translationBooks: ApiTranslationBooks[];\n\n /**\n * The list of chapters for each book.\n * This maps to the following endpoints:\n * - /api/:translationId/:bookId/:chapterNumber.json\n * - /api/:translationId/:bookCommonName/:chapterNumber.json\n */\n translationBookChapters: ApiTranslationBookChapter[];\n\n /**\n * The list of audio files.\n * This maps to the following endpoints:\n * - /api/:translationId/:bookId/:chapterNumber.:reader.mp3\n */\n translationBookChapterAudio: ApiTranslationBookChapterAudio[];\n\n /**\n * The list of available commentaries.\n * This maps to the /api/available-commentaries.json endpoint.\n */\n availableCommentaries: ApiAvailableCommentaries;\n\n /**\n * The list of books for each commentary.\n * This maps to the /api/c/:commentaryId/books.json endpoint.\n */\n commentaryBooks: ApiCommentaryBooks[];\n\n /**\n * The list of profiles for each commentary.\n * This maps to the /api/c/:commentaryId/profiles.json endpoint.\n */\n commentaryProfiles: ApiCommentaryProfiles[];\n\n /**\n * The list of chapters for each commentary book.\n * This maps to the following endpoint:\n * - /api/c/:commentaryId/:bookId/:chapterNumber.json\n */\n commentaryBookChapters: ApiCommentaryBookChapter[];\n\n /**\n * The list of individual profiles for each commentary.\n * This maps to the following endpoint:\n * - /api/c/:commentaryId/profiles/:profileId.json\n */\n commentaryProfileContents: ApiCommentaryProfileContent[];\n\n /**\n * The list of available datasets.\n * This maps to the /api/available-datasets.json endpoint.\n */\n availableDatasets?: ApiAvailableDatasets;\n\n /**\n * The list of books for each dataset.\n * This maps to the /api/d/:datasetId/books.json endpoint.\n */\n datasetBooks?: ApiDatasetBooks[];\n\n /**\n * The list of chapters for each dataset book.\n * This maps to the following endpoint:\n * - /api/d/:datasetId/:bookId/:chapterNumber.json\n */\n datasetBookChapters?: ApiDatasetBookChapter[];\n\n /**\n * The path prefix that the API should use.\n */\n pathPrefix: string;\n}\n\n/**\n * The list of available translations.\n * Maps to the /api/available-translations.json endpoint.\n */\nexport interface ApiAvailableTranslations {\n /**\n * The list of translations.\n */\n translations: ApiTranslation[];\n}\n\n/**\n * The list of available commentaries.\n * Maps to the /api/available-commentaries.json endpoint.\n */\nexport interface ApiAvailableCommentaries {\n /**\n * The list of commentaries.\n */\n commentaries: ApiCommentary[];\n}\n\n/**\n * The list of available datasets.\n * Maps to the /api/available-datasets.json endpoint.\n */\nexport interface ApiAvailableDatasets {\n datasets: ApiDataset[];\n}\n\n/**\n * Defines a dataset that is used in the API.\n */\nexport interface ApiDataset extends Dataset {\n /**\n * The API link for the list of books for this dataset.\n */\n listOfBooksApiLink: string;\n\n /**\n * The available list of formats.\n */\n availableFormats: 'json'[];\n\n /**\n * The number of books that are contained in this dataset.\n */\n numberOfBooks: number;\n\n /**\n * The total number of chapters that are contained in this dataset.\n */\n totalNumberOfChapters: number;\n\n /**\n * The total number of verses that are contained in this dataset.\n */\n totalNumberOfVerses: number;\n\n /**\n * The total number of references that are contained in this dataset.\n */\n totalNumberOfReferences: number;\n\n /**\n * Gets the name of the language that the commentary is in.\n * Null or undefined if the name of the language is not known.\n */\n languageName?: string;\n\n /**\n * Gets the name of the language in English.\n * Null or undefined if the language doesn't have an english name.\n */\n languageEnglishName?: string;\n}\n\n/**\n * Defines a translation that is used in the API.\n */\nexport interface ApiTranslation extends Translation {\n /**\n * The API link for the list of available books for this translation.\n */\n listOfBooksApiLink: string;\n\n /**\n * The available list of formats.\n */\n availableFormats: ('json' | 'usfm')[];\n\n /**\n * The number of books that are contained in this translation.\n *\n * Complete translations should have the same number of books as the Bible (66).\n */\n numberOfBooks: number;\n\n /**\n * The total number of chapters that are contained in this translation.\n *\n * Complete translations should have the same number of chapters as the Bible (1,189).\n */\n totalNumberOfChapters: number;\n\n /**\n * The total number of verses that are contained in this translation.\n *\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).\n */\n totalNumberOfVerses: number;\n\n /**\n * The total number of apocryphal books that are contained in this translation.\n */\n numberOfApocryphalBooks?: number;\n\n /**\n * The total number of apocryphal chapters that are contained in this translation.\n */\n totalNumberOfApocryphalChapters?: number;\n\n /**\n * the total number of apocryphal verses that are contained in this translation.\n */\n totalNumberOfApocryphalVerses?: number;\n\n /**\n * Gets the name of the language that the translation is in.\n * Null or undefined if the name of the language is not known.\n */\n languageName?: string;\n\n /**\n * Gets the name of the language in English.\n * Null or undefined if the language doesn't have an english name.\n */\n languageEnglishName?: string;\n}\n\n/**\n * Defines a commentary that is used in the API.\n */\nexport interface ApiCommentary extends Commentary {\n /**\n * The API link for the list of available books for this translation.\n */\n listOfBooksApiLink: string;\n\n /**\n * The API link for the list of available profiles for this commentary.\n */\n listOfProfilesApiLink: string;\n\n /**\n * The available list of formats.\n */\n availableFormats: ('json' | 'usfm')[];\n\n /**\n * The number of books that are contained in this commentary.\n *\n * Complete commentaries should have the same number of books as the Bible (66).\n */\n numberOfBooks: number;\n\n /**\n * The total number of chapters that are contained in this translation.\n *\n * Complete commentaries should have the same number of chapters as the Bible (1,189).\n */\n totalNumberOfChapters: number;\n\n /**\n * The total number of verses that are contained in this commentary.\n *\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).\n */\n totalNumberOfVerses: number;\n\n /**\n * The total number of profiles that are contained in this commentary.\n *\n * Profiles are used to provide additional information about people and people groups that are mentioned in the Bible.\n */\n totalNumberOfProfiles: number;\n\n /**\n * Gets the name of the language that the commentary is in.\n * Null or undefined if the name of the language is not known.\n */\n languageName?: string;\n\n /**\n * Gets the name of the language in English.\n * Null or undefined if the language doesn't have an english name.\n */\n languageEnglishName?: string;\n}\n\n/**\n * Defines an interface that contains information about the books that are available for a translation.\n */\nexport interface ApiTranslationBooks {\n /**\n * The translation information for the books.\n */\n translation: ApiTranslation;\n\n /**\n * The list of books that are available for the translation.\n */\n books: ApiTranslationBook[];\n}\n\n/**\n * Defines an interface that contains information about the books that are available for a commentary.\n */\nexport interface ApiCommentaryBooks {\n /**\n * The commentary information for the books.\n */\n commentary: ApiCommentary;\n\n /**\n * The list of books that are available for the commentary.\n */\n books: ApiCommentaryBook[];\n}\n\n/**\n * Defines an interface that contains information about the books that are available for a dataset.\n */\nexport interface ApiDatasetBooks {\n /**\n * The dataset information for the books.\n */\n dataset: ApiDataset;\n\n /**\n * The list of books that are available for the dataset.\n */\n books: ApiDatasetBook[];\n}\n\n/**\n * Defines an interface that contains information about the profiles that are available for a commentary.\n */\nexport interface ApiCommentaryProfiles {\n /**\n * The commentary information for the books.\n */\n commentary: ApiCommentary;\n\n /**\n * The list of profiles that are available for the commentary.\n */\n profiles: ApiCommentaryProfile[];\n}\n\n/**\n * Defines an interface that contains information about a profile.\n */\nexport interface ApiCommentaryProfile extends CommentaryProfile {\n /**\n * The link to this profile.\n */\n thisProfileLink: string;\n\n /**\n * The link to the chapter that this profile references in the commentary.\n */\n referenceChapterLink: string | null;\n}\n\n/**\n * Defines a translation book that is used in the API.\n */\nexport interface ApiTranslationBook extends TranslationBook {\n /**\n * The number of the first chapter in the book.\n */\n firstChapterNumber: number;\n\n /**\n * The link to the first chapter of the book.\n */\n firstChapterApiLink: string;\n\n /**\n * The number of the last chapter in the book.\n */\n lastChapterNumber: number;\n\n /**\n * The link to the last chapter of the book.\n */\n lastChapterApiLink: string;\n\n /**\n * The number of chapters that the book contains.\n */\n numberOfChapters: number;\n\n /**\n * The number of verses that the book contains.\n */\n totalNumberOfVerses: number;\n}\n\n/**\n * Defines a commentary book that is used in the API.\n */\nexport interface ApiCommentaryBook extends CommentaryBook {\n /**\n * The number of the first chapter in the book.\n *\n * Null if the comentary book has no chapters.\n */\n firstChapterNumber: number | null;\n\n /**\n * The link to the first chapter of the book.\n *\n * Null if the comentary book has no chapters.\n */\n firstChapterApiLink: string | null;\n\n /**\n * The number of the last chapter in the book.\n *\n * Null if the comentary book has no chapters.\n */\n lastChapterNumber: number | null;\n\n /**\n * The link to the last chapter of the book.\n *\n * Null if the comentary book has no chapters.\n */\n lastChapterApiLink: string | null;\n\n /**\n * The number of chapters that the book contains.\n */\n numberOfChapters: number;\n\n /**\n * The number of verses that the book contains.\n */\n totalNumberOfVerses: number;\n}\n\n/**\n * Defines an interface that contains information about a book in a dataset.\n */\nexport interface ApiDatasetBook extends DatasetBook {\n /**\n * The number of the first chapter in the book.\n */\n firstChapterNumber: number;\n\n /**\n * The link to the first chapter of the book.\n */\n firstChapterApiLink: string;\n\n /**\n * The number of the last chapter in the book.\n */\n lastChapterNumber: number;\n\n /**\n * The link to the last chapter of the book.\n */\n lastChapterApiLink: string;\n\n /**\n * The number of chapters that the book contains.\n */\n numberOfChapters: number;\n\n /**\n * The number of verses that the book contains.\n */\n totalNumberOfVerses: number;\n\n /**\n * The number of references that the book contains.\n */\n totalNumberOfReferences: number;\n}\n\n/**\n * Defines an interface that contains information about a book chapter.\n */\nexport interface ApiTranslationBookChapter extends TranslationBookChapter {\n /**\n * The translation information for the book chapter.\n */\n translation: ApiTranslation;\n\n /**\n * The book information for the book chapter.\n */\n book: ApiTranslationBook;\n\n /**\n * The link to this chapter.\n */\n thisChapterLink: string;\n\n /**\n * The link to the next chapter.\n * Null if this is the last chapter in the translation.\n */\n nextChapterApiLink: string | null;\n\n /**\n * The links to the audio versions for the next chapter.\n * Null if this is the last chapter in the translation.\n */\n nextChapterAudioLinks: TranslationBookChapterAudioLinks | null;\n\n /**\n * The link to the previous chapter.\n * Null if this is the first chapter in the translation.\n */\n previousChapterApiLink: string | null;\n\n /**\n * The links to the audio versions for the previous chapter.\n * Null if this is the first chapter in the translation.\n */\n previousChapterAudioLinks: TranslationBookChapterAudioLinks | null;\n\n /**\n * The number of verses that the chapter contains.\n */\n numberOfVerses: number;\n}\n\n/**\n * Defines an interface that contains information about a book chapter.\n */\nexport interface ApiCommentaryBookChapter extends CommentaryBookChapter {\n /**\n * The commentary information for the book chapter.\n */\n commentary: ApiCommentary;\n\n /**\n * The book information for the book chapter.\n */\n book: ApiCommentaryBook;\n\n /**\n * The link to this chapter.\n */\n thisChapterLink: string;\n\n /**\n * The link to the next chapter.\n * Null if this is the last chapter in the translation.\n */\n nextChapterApiLink: string | null;\n\n /**\n * The link to the previous chapter.\n * Null if this is the first chapter in the translation.\n */\n previousChapterApiLink: string | null;\n\n /**\n * The number of verses that the chapter contains.\n */\n numberOfVerses: number;\n}\n\n/**\n * Defines an interface that contains information about a book chapter.\n */\nexport interface ApiDatasetBookChapter extends DatasetBookChapter {\n /**\n * The dataset information for the book chapter.\n */\n dataset: ApiDataset;\n\n /**\n * The book information for the book chapter.\n */\n book: ApiDatasetBook;\n\n /**\n * The link to this chapter.\n */\n thisChapterLink: string;\n\n /**\n * The link to the next chapter.\n * Null if this is the last chapter in the translation.\n */\n nextChapterApiLink: string | null;\n\n /**\n * The link to the previous chapter.\n * Null if this is the first chapter in the translation.\n */\n previousChapterApiLink: string | null;\n\n /**\n * The number of verses that the chapter contains.\n */\n numberOfVerses: number;\n\n /**\n * The number of references that the chapter contains.\n */\n numberOfReferences: number;\n}\n\nexport interface ApiTranslationBookChapterAudio {\n /**\n * The chapter that the audio is for.\n */\n chapter: ApiTranslationBookChapter;\n\n /**\n * The link that the audio should be placed at.\n */\n link: string;\n\n /**\n * The original URL of the audio.\n */\n originalUrl: string;\n}\n\nexport interface ApiCommentaryProfileContent {\n /**\n * The commentary information for the profile.\n */\n commentary: ApiCommentary;\n\n /**\n * The information about the profile.\n */\n profile: ApiCommentaryProfile;\n\n /**\n * The content of the profile.\n */\n content: string[];\n}\n\n/**\n * The options for generating the API.\n */\nexport interface GenerateApiOptions {\n /**\n * Whether to use the common name for the book chapter API link. If false, then book IDs are used.\n * Audio URLs will always use the book ID.\n * Defaults to false.\n */\n useCommonName?: boolean;\n\n /**\n * Whether to replace the audio URLs in the dataset with ones that are hosted locally.\n * If true, then the audio URLs in the dataset will be replaced with ones that reference files hosted by the API itself.\n * If false, then the audio URLs in the dataset will be left as is.\n * Defaults to false.\n */\n generateAudioFiles?: boolean;\n\n /**\n * Gets the english name of the given language.\n * If not provided, then the english name for the language will be unknown and omitted.\n * @param language The language to get the english name for.\n */\n getEnglishName?: (language: string) => string | null | undefined;\n\n /**\n * Gets the native name of the given language.\n * If not provided, then the native name for the language will be unknown and omitted.\n * @param language The language to get the native name for.\n */\n getNativeName?: (language: string) => string | null | undefined;\n\n /**\n * The prefix that should be added to paths that are generated.\n */\n pathPrefix?: string;\n}\n\n/**\n * Generates the API output for the given dataset.\n * @param dataset The dataset to generate the API for.\n * @param options The options for generating the API.\n */\nexport function generateApiForDataset(\n dataset: DatasetOutput,\n options: GenerateApiOptions = {}\n): ApiOutput {\n const { useCommonName, pathPrefix } = options;\n const apiPathPrefix = pathPrefix ? pathPrefix : '';\n let api: ApiOutput = {\n availableTranslations: {\n translations: [],\n },\n translationBooks: [],\n translationBookChapters: [],\n translationBookChapterAudio: [],\n availableCommentaries: {\n commentaries: [],\n },\n commentaryBookChapters: [],\n commentaryBooks: [],\n commentaryProfiles: [],\n commentaryProfileContents: [],\n pathPrefix: apiPathPrefix,\n };\n\n const getNativeName = options.getNativeName;\n const getEnglishName = options.getEnglishName;\n\n for (let { books, ...translation } of dataset.translations) {\n let numberOfBooks = 0;\n let numberOfApocryphalBooks = 0;\n\n for (let book of books) {\n if (book.isApocryphal) {\n numberOfApocryphalBooks++;\n } else {\n numberOfBooks++;\n }\n }\n\n const apiTranslation: ApiTranslation = {\n ...translation,\n availableFormats: ['json'],\n listOfBooksApiLink: listOfBooksApiLink(\n translation.id,\n apiPathPrefix\n ),\n numberOfBooks,\n totalNumberOfChapters: 0,\n totalNumberOfVerses: 0,\n languageName: getNativeName\n ? (getNativeName(translation.language) ?? undefined)\n : undefined,\n languageEnglishName: getEnglishName\n ? (getEnglishName(translation.language) ?? undefined)\n : undefined,\n };\n\n if (numberOfApocryphalBooks > 0) {\n apiTranslation.numberOfApocryphalBooks = numberOfApocryphalBooks;\n }\n\n const translationBooks: ApiTranslationBooks = {\n translation: apiTranslation,\n books: [],\n };\n\n let translationChapters: ApiTranslationBookChapter[] = [];\n\n for (let { chapters, ...book } of books) {\n const firstChapterNumber = chapters[0].chapter.number;\n const lastChapterNumber =\n chapters[chapters.length - 1].chapter.number;\n const apiBook: ApiTranslationBook = {\n ...book,\n firstChapterNumber,\n firstChapterApiLink: bookChapterApiLink(\n translation.id,\n getBookLink(book),\n firstChapterNumber,\n 'json',\n apiPathPrefix\n ),\n lastChapterNumber,\n lastChapterApiLink: bookChapterApiLink(\n translation.id,\n getBookLink(book),\n lastChapterNumber,\n 'json',\n apiPathPrefix\n ),\n numberOfChapters: chapters.length,\n totalNumberOfVerses: 0,\n };\n\n for (let { chapter, thisChapterAudioLinks } of chapters) {\n const audio: TranslationBookChapterAudioLinks = {};\n const apiBookChapter: ApiTranslationBookChapter = {\n translation: apiTranslation,\n book: apiBook,\n chapter: chapter,\n thisChapterLink: bookChapterApiLink(\n translation.id,\n getBookLink(book),\n chapter.number,\n 'json',\n apiPathPrefix\n ),\n thisChapterAudioLinks: audio,\n nextChapterApiLink: null,\n nextChapterAudioLinks: null,\n previousChapterApiLink: null,\n previousChapterAudioLinks: null,\n numberOfVerses: 0,\n };\n\n for (let reader in thisChapterAudioLinks) {\n if (options.generateAudioFiles) {\n const apiAudio: ApiTranslationBookChapterAudio = {\n chapter: apiBookChapter,\n link: bookChapterAudioApiLink(\n translation.id,\n getBookLink(book),\n chapter.number,\n reader,\n apiPathPrefix\n ),\n originalUrl: thisChapterAudioLinks[reader],\n };\n audio[reader] = apiAudio.link;\n api.translationBookChapterAudio.push(apiAudio);\n } else {\n audio[reader] = thisChapterAudioLinks[reader];\n }\n }\n\n for (let c of chapter.content) {\n if (c.type === 'verse') {\n apiBookChapter.numberOfVerses++;\n }\n }\n\n apiBook.totalNumberOfVerses += apiBookChapter.numberOfVerses;\n\n translationChapters.push(apiBookChapter);\n api.translationBookChapters.push(apiBookChapter);\n }\n\n translationBooks.books.push(apiBook);\n\n if (apiBook.isApocryphal) {\n if (!apiTranslation.totalNumberOfApocryphalChapters) {\n apiTranslation.totalNumberOfApocryphalChapters = 0;\n }\n if (!apiTranslation.totalNumberOfApocryphalVerses) {\n apiTranslation.totalNumberOfApocryphalVerses = 0;\n }\n apiTranslation.totalNumberOfApocryphalChapters +=\n apiBook.numberOfChapters;\n apiTranslation.totalNumberOfApocryphalVerses +=\n apiBook.totalNumberOfVerses;\n } else {\n apiTranslation.totalNumberOfChapters +=\n apiBook.numberOfChapters;\n apiTranslation.totalNumberOfVerses +=\n apiBook.totalNumberOfVerses;\n }\n }\n\n for (let i = 0; i < translationChapters.length; i++) {\n if (i > 0) {\n translationChapters[i].previousChapterApiLink =\n bookChapterApiLink(\n translation.id,\n getBookLink(translationChapters[i - 1].book),\n translationChapters[i - 1].chapter.number,\n 'json',\n apiPathPrefix\n );\n translationChapters[i].previousChapterAudioLinks =\n translationChapters[i - 1].thisChapterAudioLinks;\n }\n\n if (i < translationChapters.length - 1) {\n translationChapters[i].nextChapterApiLink = bookChapterApiLink(\n translation.id,\n getBookLink(translationChapters[i + 1].book),\n translationChapters[i + 1].chapter.number,\n 'json',\n apiPathPrefix\n );\n translationChapters[i].nextChapterAudioLinks =\n translationChapters[i + 1].thisChapterAudioLinks;\n }\n }\n\n api.availableTranslations.translations.push(apiTranslation);\n api.translationBooks.push(translationBooks);\n }\n\n for (let { books, profiles, ...commentary } of dataset.commentaries) {\n const apiCommentary: ApiCommentary = {\n ...commentary,\n availableFormats: ['json'],\n listOfBooksApiLink: listOfCommentaryBooksApiLink(\n commentary.id,\n apiPathPrefix\n ),\n listOfProfilesApiLink: profilesCommentaryApiLink(\n commentary.id,\n 'json',\n apiPathPrefix\n ),\n numberOfBooks: books.length,\n totalNumberOfChapters: 0,\n totalNumberOfVerses: 0,\n totalNumberOfProfiles: 0,\n languageName: getNativeName\n ? (getNativeName(commentary.language) ?? undefined)\n : undefined,\n languageEnglishName: getEnglishName\n ? (getEnglishName(commentary.language) ?? undefined)\n : undefined,\n };\n\n const commentaryBooks: ApiCommentaryBooks = {\n commentary: apiCommentary,\n books: [],\n };\n\n const commentaryProfiles: ApiCommentaryProfiles = {\n commentary: apiCommentary,\n profiles: [],\n };\n\n let commentaryChapters: ApiCommentaryBookChapter[] = [];\n\n for (let { chapters, ...book } of books) {\n const firstChapterNumber = chapters[0]?.chapter.number ?? null;\n const lastChapterNumber =\n chapters[chapters.length - 1]?.chapter.number ?? null;\n const apiBook: ApiCommentaryBook = {\n ...book,\n firstChapterNumber,\n firstChapterApiLink: firstChapterNumber\n ? bookCommentaryChapterApiLink(\n commentary.id,\n getBookLink(book),\n firstChapterNumber,\n 'json',\n apiPathPrefix\n )\n : null,\n lastChapterNumber,\n lastChapterApiLink: lastChapterNumber\n ? bookCommentaryChapterApiLink(\n commentary.id,\n getBookLink(book),\n lastChapterNumber,\n 'json',\n apiPathPrefix\n )\n : null,\n numberOfChapters: chapters.length,\n totalNumberOfVerses: 0,\n };\n\n for (let { chapter } of chapters) {\n const apiBookChapter: ApiCommentaryBookChapter = {\n commentary: apiCommentary,\n book: apiBook,\n chapter: chapter,\n thisChapterLink: bookCommentaryChapterApiLink(\n commentary.id,\n getBookLink(book),\n chapter.number,\n 'json',\n apiPathPrefix\n ),\n nextChapterApiLink: null,\n previousChapterApiLink: null,\n numberOfVerses: 0,\n };\n\n for (let c of chapter.content) {\n if (c.type === 'verse') {\n apiBookChapter.numberOfVerses++;\n }\n }\n\n apiBook.totalNumberOfVerses += apiBookChapter.numberOfVerses;\n\n commentaryChapters.push(apiBookChapter);\n api.commentaryBookChapters.push(apiBookChapter);\n }\n\n commentaryBooks.books.push(apiBook);\n\n apiCommentary.totalNumberOfChapters += apiBook.numberOfChapters;\n apiCommentary.totalNumberOfVerses += apiBook.totalNumberOfVerses;\n }\n\n if (profiles) {\n for (let profile of profiles) {\n const apiProfile: ApiCommentaryProfile = {\n id: profile.id,\n reference: profile.reference,\n subject: profile.subject,\n thisProfileLink: profileCommentaryApiLink(\n commentary.id,\n profile.id,\n 'json',\n apiPathPrefix\n ),\n referenceChapterLink: profile.reference\n ? bookCommentaryChapterApiLink(\n commentary.id,\n profile.reference.book,\n profile.reference.chapter,\n 'json',\n apiPathPrefix\n )\n : null,\n };\n\n const apiProfileContent: ApiCommentaryProfileContent = {\n commentary: apiCommentary,\n profile: apiProfile,\n content: profile.content,\n };\n\n apiCommentary.totalNumberOfProfiles += 1;\n commentaryProfiles.profiles.push(apiProfile);\n api.commentaryProfileContents.push(apiProfileContent);\n }\n }\n\n for (let i = 0; i < commentaryChapters.length; i++) {\n if (i > 0) {\n commentaryChapters[i].previousChapterApiLink =\n bookCommentaryChapterApiLink(\n commentary.id,\n getBookLink(commentaryChapters[i - 1].book),\n commentaryChapters[i - 1].chapter.number,\n 'json',\n apiPathPrefix\n );\n // commentaryChapters[i].previousChapterAudioLinks =\n // commentaryChapters[i - 1].thisChapterAudioLinks;\n }\n\n if (i < commentaryChapters.length - 1) {\n commentaryChapters[i].nextChapterApiLink =\n bookCommentaryChapterApiLink(\n commentary.id,\n getBookLink(commentaryChapters[i + 1].book),\n commentaryChapters[i + 1].chapter.number,\n 'json',\n apiPathPrefix\n );\n // commentaryChapters[i].nextChapterAudioLinks =\n // commentaryChapters[i + 1].thisChapterAudioLinks;\n }\n }\n\n api.availableCommentaries.commentaries.push(apiCommentary);\n api.commentaryBooks.push(commentaryBooks);\n api.commentaryProfiles.push(commentaryProfiles);\n }\n\n for (let { books, ...datasetInfo } of dataset.datasets ?? []) {\n const apiDataset: ApiDataset = {\n ...datasetInfo,\n availableFormats: ['json'],\n listOfBooksApiLink: listOfDatasetBooksApiLink(\n datasetInfo.id,\n apiPathPrefix\n ),\n numberOfBooks: books.length,\n totalNumberOfChapters: 0,\n totalNumberOfVerses: 0,\n totalNumberOfReferences: 0,\n languageName: getNativeName\n ? (getNativeName(datasetInfo.language) ?? undefined)\n : undefined,\n languageEnglishName: getEnglishName\n ? (getEnglishName(datasetInfo.language) ?? undefined)\n : undefined,\n };\n\n const datasetBooks: ApiDatasetBooks = {\n dataset: apiDataset,\n books: [],\n };\n\n let datasetChapters: ApiDatasetBookChapter[] = [];\n\n for (let { chapters, ...book } of books) {\n const firstChapterNumber = chapters[0]?.chapter.number ?? null;\n const lastChapterNumber =\n chapters[chapters.length - 1]?.chapter.number ?? null;\n const apiBook: ApiDatasetBook = {\n ...book,\n firstChapterNumber,\n firstChapterApiLink: bookDatasetChapterApiLink(\n datasetInfo.id,\n book.id,\n firstChapterNumber,\n 'json',\n apiPathPrefix\n ),\n lastChapterNumber,\n lastChapterApiLink: bookDatasetChapterApiLink(\n datasetInfo.id,\n book.id,\n lastChapterNumber,\n 'json',\n apiPathPrefix\n ),\n numberOfChapters: chapters.length,\n totalNumberOfVerses: 0,\n totalNumberOfReferences: 0,\n };\n\n for (let { chapter } of chapters) {\n const apiBookChapter: ApiDatasetBookChapter = {\n dataset: apiDataset,\n book: apiBook,\n chapter: chapter,\n thisChapterLink: bookDatasetChapterApiLink(\n datasetInfo.id,\n book.id,\n chapter.number,\n 'json',\n apiPathPrefix\n ),\n nextChapterApiLink: null,\n previousChapterApiLink: null,\n numberOfVerses: chapter.content.length,\n numberOfReferences: 0,\n };\n\n // apiBookChapter.numberOfVerses += ;\n for (let verse of chapter.content) {\n apiBookChapter.numberOfReferences +=\n verse.references.length;\n }\n\n apiBook.totalNumberOfVerses += apiBookChapter.numberOfVerses;\n apiBook.totalNumberOfReferences +=\n apiBookChapter.numberOfReferences;\n\n datasetChapters.push(apiBookChapter);\n if (!api.datasetBookChapters) {\n api.datasetBookChapters = [];\n }\n api.datasetBookChapters.push(apiBookChapter);\n }\n\n datasetBooks.books.push(apiBook);\n\n apiDataset.totalNumberOfChapters += apiBook.numberOfChapters;\n apiDataset.totalNumberOfVerses += apiBook.totalNumberOfVerses;\n apiDataset.totalNumberOfReferences +=\n apiBook.totalNumberOfReferences;\n }\n\n for (let i = 0; i < datasetChapters.length; i++) {\n if (i > 0) {\n datasetChapters[i].previousChapterApiLink =\n bookDatasetChapterApiLink(\n datasetInfo.id,\n datasetChapters[i - 1].book.id,\n datasetChapters[i - 1].chapter.number,\n 'json',\n apiPathPrefix\n );\n }\n\n if (i < datasetChapters.length - 1) {\n datasetChapters[i].nextChapterApiLink =\n bookDatasetChapterApiLink(\n datasetInfo.id,\n datasetChapters[i + 1].book.id,\n datasetChapters[i + 1].chapter.number,\n 'json',\n apiPathPrefix\n );\n }\n }\n\n if (!api.availableDatasets) {\n api.availableDatasets = {\n datasets: [],\n };\n }\n api.availableDatasets.datasets.push(apiDataset);\n if (!api.datasetBooks) {\n api.datasetBooks = [];\n }\n api.datasetBooks.push(datasetBooks);\n }\n\n return api;\n\n function getBookLink(book: TranslationBook | CommentaryBook): string {\n return useCommonName ? book.commonName : book.id;\n }\n}\n\n/**\n * Generates the output files for the given API.\n * @param api The API that the files should be generated for.\n */\nexport function generateFilesForApi(api: ApiOutput): OutputFile[] {\n let files: OutputFile[] = [];\n\n files.push(\n jsonFile(\n `${api.pathPrefix}/api/available_translations.json`,\n api.availableTranslations,\n true\n )\n );\n for (let translationBooks of api.translationBooks) {\n files.push(\n jsonFile(\n translationBooks.translation.listOfBooksApiLink,\n translationBooks\n )\n );\n }\n\n for (let bookChapter of api.translationBookChapters) {\n files.push(jsonFile(bookChapter.thisChapterLink, bookChapter));\n }\n\n for (let audio of api.translationBookChapterAudio) {\n files.push(downloadedFile(audio.link, audio.originalUrl));\n }\n\n files.push(\n jsonFile(\n `${api.pathPrefix}/api/available_commentaries.json`,\n api.availableCommentaries,\n true\n )\n );\n for (let commentaryBooks of api.commentaryBooks) {\n files.push(\n jsonFile(\n commentaryBooks.commentary.listOfBooksApiLink,\n commentaryBooks\n )\n );\n }\n\n for (let commentaryProfiles of api.commentaryProfiles) {\n files.push(\n jsonFile(\n commentaryProfiles.commentary.listOfProfilesApiLink,\n commentaryProfiles\n )\n );\n }\n\n for (let profileContent of api.commentaryProfileContents) {\n files.push(\n jsonFile(profileContent.profile.thisProfileLink, profileContent)\n );\n }\n\n for (let bookChapter of api.commentaryBookChapters) {\n files.push(jsonFile(bookChapter.thisChapterLink, bookChapter));\n }\n\n if (api.availableDatasets) {\n files.push(\n jsonFile(\n `${api.pathPrefix}/api/available_datasets.json`,\n api.availableDatasets,\n true\n )\n );\n }\n\n if (api.datasetBooks) {\n for (let datasetBook of api.datasetBooks) {\n files.push(\n jsonFile(datasetBook.dataset.listOfBooksApiLink, datasetBook)\n );\n }\n }\n\n if (api.datasetBookChapters) {\n for (let datasetBookChapter of api.datasetBookChapters) {\n files.push(\n jsonFile(datasetBookChapter.thisChapterLink, datasetBookChapter)\n );\n }\n }\n\n // for (let audio of api.translationBookChapterAudio) {\n // files.push(downloadedFile(audio.link, audio.originalUrl));\n // }\n\n return files;\n}\n\n/**\n * Generates the output files for the given datasets.\n * @param datasets The datasets to generate the output files for.\n * @param options The options for generating the API files.\n */\nexport async function* generateOutputFilesFromDatasets(\n datasets: AsyncIterable<DatasetOutput>,\n options?: GenerateApiOptions\n): AsyncGenerator<OutputFile[]> {\n for await (let dataset of datasets) {\n const api = generateApiForDataset(dataset, options);\n const files = generateFilesForApi(api);\n\n yield files;\n }\n}\n\n/**\n * Gets the API Link for the list of books endpoint for a translation.\n * @param translationId The ID of the translation.\n * @returns\n */\nexport function listOfBooksApiLink(\n translationId: string,\n prefix: string = ''\n): string {\n return `${prefix}/api/${translationId}/books.json`;\n}\n\n/**\n * Gets the API Link for the list of books endpoint for a commentary.\n * @param commentaryId The ID of the commentary.\n * @returns\n */\nexport function listOfCommentaryBooksApiLink(\n commentaryId: string,\n prefix: string = ''\n): string {\n return `${prefix}/api/c/${commentaryId}/books.json`;\n}\n\n/**\n * Gets the API Link for the list of books endpoint for a dataset.\n * @param datasetId The ID of the dataset.\n * @returns\n */\nexport function listOfDatasetBooksApiLink(\n datasetId: string,\n prefix: string = ''\n): string {\n return `${prefix}/api/d/${datasetId}/books.json`;\n}\n\n/**\n * Getes the API link for a book chapter.\n * @param translationId The ID of the translation.\n * @param commonName The name of the book.\n * @param chapterNumber The number of the book.\n * @param extension The extension of the file.\n */\nexport function bookChapterApiLink(\n translationId: string,\n commonName: string,\n chapterNumber: number,\n extension: string,\n prefix: string = ''\n) {\n return `${prefix}/api/${translationId}/${replaceSpacesWithUnderscores(\n commonName\n )}/${chapterNumber}.${extension}`;\n}\n\n/**\n * Getes the API link for a book chapter.\n * @param translationId The ID of the translation.\n * @param commonName The name of the book.\n * @param chapterNumber The number of the book.\n * @param extension The extension of the file.\n */\nexport function bookCommentaryChapterApiLink(\n translationId: string,\n commonName: string,\n chapterNumber: number,\n extension: string,\n prefix: string = ''\n) {\n return `${prefix}/api/c/${translationId}/${replaceSpacesWithUnderscores(\n commonName\n )}/${chapterNumber}.${extension}`;\n}\n\nexport function bookChapterAudioApiLink(\n translationId: string,\n bookId: string,\n chapterNumber: number,\n reader: string,\n prefix: string = ''\n) {\n return `${prefix}/api/${translationId}/${replaceSpacesWithUnderscores(\n bookId\n )}/${chapterNumber}.${reader}.mp3`;\n}\n\n/**\n * Getes the API link for a book chapter.\n * @param translationId The ID of the translation.\n * @param commonName The name of the book.\n * @param chapterNumber The number of the book.\n * @param extension The extension of the file.\n */\nexport function bookDatasetChapterApiLink(\n translationId: string,\n commonName: string,\n chapterNumber: number,\n extension: string,\n prefix: string = ''\n) {\n return `${prefix}/api/d/${translationId}/${replaceSpacesWithUnderscores(\n commonName\n )}/${chapterNumber}.${extension}`;\n}\n\n/**\n * Gets the API link for a profile.\n * @param translationId The ID of the translation.\n * @param profileId The ID of the profile.\n * @param extension The extension of the file.\n */\nexport function profilesCommentaryApiLink(\n translationId: string,\n extension: string,\n prefix: string = ''\n) {\n return `${prefix}/api/c/${translationId}/profiles.${extension}`;\n}\n\n/**\n * Gets the API link for a profile.\n * @param translationId The ID of the translation.\n * @param profileId The ID of the profile.\n * @param extension The extension of the file.\n */\nexport function profileCommentaryApiLink(\n translationId: string,\n profileId: string,\n extension: string,\n prefix: string = ''\n) {\n return `${prefix}/api/c/${translationId}/profiles/${replaceSpacesWithUnderscores(\n profileId\n )}.${extension}`;\n}\n\nexport function jsonFile(\n path: string,\n content: any,\n mergable?: boolean\n): OutputFile {\n return {\n path,\n content,\n mergable,\n };\n}\n\nexport function downloadedFile(path: string, url: string): OutputFile {\n return {\n path,\n content: () => fetch(url).then((response) => response.body),\n };\n}\n\nexport function replaceSpacesWithUnderscores(str: string): string {\n return str.replace(/[<>:\"/\\\\|?*\\s]/g, '_');\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J;AAEO,gBAAS,6BAA6B,KAAqB;AAC9D,SAAO,IAAI,QAAQ,mBAAmB,GAAG;AAC7C;",
|
|
4
|
+
"sourcesContent": ["import {\r\n ChapterContent,\r\n ChapterData,\r\n ChapterFootnote,\r\n Commentary,\r\n CommentaryBook,\r\n CommentaryBookChapter,\r\n CommentaryProfile,\r\n Dataset,\r\n DatasetBook,\r\n DatasetBookChapter,\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 profiles for each commentary.\r\n * This maps to the /api/c/:commentaryId/profiles.json endpoint.\r\n */\r\n commentaryProfiles: ApiCommentaryProfiles[];\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 list of individual profiles for each commentary.\r\n * This maps to the following endpoint:\r\n * - /api/c/:commentaryId/profiles/:profileId.json\r\n */\r\n commentaryProfileContents: ApiCommentaryProfileContent[];\r\n\r\n /**\r\n * The list of available datasets.\r\n * This maps to the /api/available-datasets.json endpoint.\r\n */\r\n availableDatasets?: ApiAvailableDatasets;\r\n\r\n /**\r\n * The list of books for each dataset.\r\n * This maps to the /api/d/:datasetId/books.json endpoint.\r\n */\r\n datasetBooks?: ApiDatasetBooks[];\r\n\r\n /**\r\n * The list of chapters for each dataset book.\r\n * This maps to the following endpoint:\r\n * - /api/d/:datasetId/:bookId/:chapterNumber.json\r\n */\r\n datasetBookChapters?: ApiDatasetBookChapter[];\r\n\r\n /**\r\n * The complete translation data for each translation.\r\n * This maps to the /api/:translationId/complete.json endpoint.\r\n */\r\n translationComplete: ApiTranslationComplete[];\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 * The list of available datasets.\r\n * Maps to the /api/available-datasets.json endpoint.\r\n */\r\nexport interface ApiAvailableDatasets {\r\n datasets: ApiDataset[];\r\n}\r\n\r\n/**\r\n * Defines a dataset that is used in the API.\r\n */\r\nexport interface ApiDataset extends Dataset {\r\n /**\r\n * The API link for the list of books for this dataset.\r\n */\r\n listOfBooksApiLink: string;\r\n\r\n /**\r\n * The available list of formats.\r\n */\r\n availableFormats: 'json'[];\r\n\r\n /**\r\n * The number of books that are contained in this dataset.\r\n */\r\n numberOfBooks: number;\r\n\r\n /**\r\n * The total number of chapters that are contained in this dataset.\r\n */\r\n totalNumberOfChapters: number;\r\n\r\n /**\r\n * The total number of verses that are contained in this dataset.\r\n */\r\n totalNumberOfVerses: number;\r\n\r\n /**\r\n * The total number of references that are contained in this dataset.\r\n */\r\n totalNumberOfReferences: 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 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 * The total number of apocryphal books that are contained in this translation.\r\n */\r\n numberOfApocryphalBooks?: number;\r\n\r\n /**\r\n * The total number of apocryphal chapters that are contained in this translation.\r\n */\r\n totalNumberOfApocryphalChapters?: number;\r\n\r\n /**\r\n * the total number of apocryphal verses that are contained in this translation.\r\n */\r\n totalNumberOfApocryphalVerses?: 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 * The API link for downloading the complete translation as a single JSON file.\r\n *\r\n * Undefined if complete translation files are not available.\r\n */\r\n completeTranslationApiLink?: string;\r\n}\r\n\r\n/**\r\n * Defines the complete translation download data.\r\n * Maps to the /api/:translationId/complete.json endpoint.\r\n */\r\nexport interface ApiTranslationComplete {\r\n /**\r\n * The translation metadata.\r\n */\r\n translation: ApiTranslation;\r\n\r\n /**\r\n * The complete list of books with all their chapters.\r\n */\r\n books: ApiTranslationCompleteBook[];\r\n}\r\n\r\n/**\r\n * A book in the complete translation download.\r\n */\r\nexport interface ApiTranslationCompleteBook {\r\n /**\r\n * The ID of the book.\r\n */\r\n id: string;\r\n\r\n /**\r\n * The name of the book from the translation.\r\n */\r\n name: string;\r\n\r\n /**\r\n * The common name for the book.\r\n */\r\n commonName: string;\r\n\r\n /**\r\n * The title of the book.\r\n */\r\n title: string | null;\r\n\r\n /**\r\n * The order of the book.\r\n */\r\n order: number;\r\n\r\n /**\r\n * The number of chapters in the book.\r\n */\r\n numberOfChapters: number;\r\n\r\n /**\r\n * The total number of verses in the book.\r\n */\r\n totalNumberOfVerses: number;\r\n\r\n /**\r\n * Whether the book is apocryphal.\r\n */\r\n isApocryphal?: boolean;\r\n\r\n /**\r\n * The complete list of chapters with all content.\r\n */\r\n chapters: TranslationBookChapter[];\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 API link for the list of available profiles for this commentary.\r\n */\r\n listOfProfilesApiLink: 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 * The total number of profiles that are contained in this commentary.\r\n *\r\n * Profiles are used to provide additional information about people and people groups that are mentioned in the Bible.\r\n */\r\n totalNumberOfProfiles: 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 an interface that contains information about the books that are available for a dataset.\r\n */\r\nexport interface ApiDatasetBooks {\r\n /**\r\n * The dataset information for the books.\r\n */\r\n dataset: ApiDataset;\r\n\r\n /**\r\n * The list of books that are available for the dataset.\r\n */\r\n books: ApiDatasetBook[];\r\n}\r\n\r\n/**\r\n * Defines an interface that contains information about the profiles that are available for a commentary.\r\n */\r\nexport interface ApiCommentaryProfiles {\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 profiles that are available for the commentary.\r\n */\r\n profiles: ApiCommentaryProfile[];\r\n}\r\n\r\n/**\r\n * Defines an interface that contains information about a profile.\r\n */\r\nexport interface ApiCommentaryProfile extends CommentaryProfile {\r\n /**\r\n * The link to this profile.\r\n */\r\n thisProfileLink: string;\r\n\r\n /**\r\n * The link to the chapter that this profile references in the commentary.\r\n */\r\n referenceChapterLink: string | null;\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 number of the first chapter in the book.\r\n */\r\n firstChapterNumber: number;\r\n\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 number of the last chapter in the book.\r\n */\r\n lastChapterNumber: number;\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 number of the first chapter in the book.\r\n *\r\n * Null if the comentary book has no chapters.\r\n */\r\n firstChapterNumber: number | null;\r\n\r\n /**\r\n * The link to the first chapter of the book.\r\n *\r\n * Null if the comentary book has no chapters.\r\n */\r\n firstChapterApiLink: string | null;\r\n\r\n /**\r\n * The number of the last chapter in the book.\r\n *\r\n * Null if the comentary book has no chapters.\r\n */\r\n lastChapterNumber: number | null;\r\n\r\n /**\r\n * The link to the last chapter of the book.\r\n *\r\n * Null if the comentary book has no chapters.\r\n */\r\n lastChapterApiLink: string | null;\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 in a dataset.\r\n */\r\nexport interface ApiDatasetBook extends DatasetBook {\r\n /**\r\n * The number of the first chapter in the book.\r\n */\r\n firstChapterNumber: number;\r\n\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 number of the last chapter in the book.\r\n */\r\n lastChapterNumber: number;\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 * The number of references that the book contains.\r\n */\r\n totalNumberOfReferences: 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\n/**\r\n * Defines an interface that contains information about a book chapter.\r\n */\r\nexport interface ApiDatasetBookChapter extends DatasetBookChapter {\r\n /**\r\n * The dataset information for the book chapter.\r\n */\r\n dataset: ApiDataset;\r\n\r\n /**\r\n * The book information for the book chapter.\r\n */\r\n book: ApiDatasetBook;\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\n * The number of references that the chapter contains.\r\n */\r\n numberOfReferences: 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\nexport interface ApiCommentaryProfileContent {\r\n /**\r\n * The commentary information for the profile.\r\n */\r\n commentary: ApiCommentary;\r\n\r\n /**\r\n * The information about the profile.\r\n */\r\n profile: ApiCommentaryProfile;\r\n\r\n /**\r\n * The content of the profile.\r\n */\r\n content: 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 * Whether to generate complete translation files for each translation.\r\n */\r\n generateCompleteTranslationFiles?: boolean;\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 translationComplete: [],\r\n availableCommentaries: {\r\n commentaries: [],\r\n },\r\n commentaryBookChapters: [],\r\n commentaryBooks: [],\r\n commentaryProfiles: [],\r\n commentaryProfileContents: [],\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 let numberOfBooks = 0;\r\n let numberOfApocryphalBooks = 0;\r\n\r\n for (let book of books) {\r\n if (book.isApocryphal) {\r\n numberOfApocryphalBooks++;\r\n } else {\r\n numberOfBooks++;\r\n }\r\n }\r\n\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 completeTranslationApiLink: options.generateCompleteTranslationFiles\r\n ? completeTranslationApiLink(translation.id, apiPathPrefix)\r\n : undefined,\r\n numberOfBooks,\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 if (numberOfApocryphalBooks > 0) {\r\n apiTranslation.numberOfApocryphalBooks = numberOfApocryphalBooks;\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 firstChapterNumber = chapters[0].chapter.number;\r\n const lastChapterNumber =\r\n chapters[chapters.length - 1].chapter.number;\r\n const apiBook: ApiTranslationBook = {\r\n ...book,\r\n firstChapterNumber,\r\n firstChapterApiLink: bookChapterApiLink(\r\n translation.id,\r\n getBookLink(book),\r\n firstChapterNumber,\r\n 'json',\r\n apiPathPrefix\r\n ),\r\n lastChapterNumber,\r\n lastChapterApiLink: bookChapterApiLink(\r\n translation.id,\r\n getBookLink(book),\r\n lastChapterNumber,\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 if (apiBook.isApocryphal) {\r\n if (!apiTranslation.totalNumberOfApocryphalChapters) {\r\n apiTranslation.totalNumberOfApocryphalChapters = 0;\r\n }\r\n if (!apiTranslation.totalNumberOfApocryphalVerses) {\r\n apiTranslation.totalNumberOfApocryphalVerses = 0;\r\n }\r\n apiTranslation.totalNumberOfApocryphalChapters +=\r\n apiBook.numberOfChapters;\r\n apiTranslation.totalNumberOfApocryphalVerses +=\r\n apiBook.totalNumberOfVerses;\r\n } else {\r\n apiTranslation.totalNumberOfChapters +=\r\n apiBook.numberOfChapters;\r\n apiTranslation.totalNumberOfVerses +=\r\n apiBook.totalNumberOfVerses;\r\n }\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 if (options.generateCompleteTranslationFiles) {\r\n // Build the complete translation data for download\r\n const completeTranslation: ApiTranslationComplete = {\r\n translation: apiTranslation,\r\n books: translationBooks.books.map((book) => {\r\n const bookChapters = translationChapters.filter(\r\n (ch) => ch.book.id === book.id\r\n );\r\n return {\r\n id: book.id,\r\n name: book.name,\r\n commonName: book.commonName,\r\n title: book.title,\r\n order: book.order,\r\n numberOfChapters: book.numberOfChapters,\r\n totalNumberOfVerses: book.totalNumberOfVerses,\r\n isApocryphal: book.isApocryphal,\r\n chapters: bookChapters.map((ch) => ({\r\n numberOfVerses: ch.numberOfVerses,\r\n thisChapterAudioLinks: ch.thisChapterAudioLinks,\r\n chapter: ch.chapter,\r\n })),\r\n };\r\n }),\r\n };\r\n api.translationComplete.push(completeTranslation);\r\n }\r\n }\r\n\r\n for (let { books, profiles, ...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 listOfProfilesApiLink: profilesCommentaryApiLink(\r\n commentary.id,\r\n 'json',\r\n apiPathPrefix\r\n ),\r\n numberOfBooks: books.length,\r\n totalNumberOfChapters: 0,\r\n totalNumberOfVerses: 0,\r\n totalNumberOfProfiles: 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 const commentaryProfiles: ApiCommentaryProfiles = {\r\n commentary: apiCommentary,\r\n profiles: [],\r\n };\r\n\r\n let commentaryChapters: ApiCommentaryBookChapter[] = [];\r\n\r\n for (let { chapters, ...book } of books) {\r\n const firstChapterNumber = chapters[0]?.chapter.number ?? null;\r\n const lastChapterNumber =\r\n chapters[chapters.length - 1]?.chapter.number ?? null;\r\n const apiBook: ApiCommentaryBook = {\r\n ...book,\r\n firstChapterNumber,\r\n firstChapterApiLink: firstChapterNumber\r\n ? bookCommentaryChapterApiLink(\r\n commentary.id,\r\n getBookLink(book),\r\n firstChapterNumber,\r\n 'json',\r\n apiPathPrefix\r\n )\r\n : null,\r\n lastChapterNumber,\r\n lastChapterApiLink: lastChapterNumber\r\n ? bookCommentaryChapterApiLink(\r\n commentary.id,\r\n getBookLink(book),\r\n lastChapterNumber,\r\n 'json',\r\n apiPathPrefix\r\n )\r\n : null,\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 if (profiles) {\r\n for (let profile of profiles) {\r\n const apiProfile: ApiCommentaryProfile = {\r\n id: profile.id,\r\n reference: profile.reference,\r\n subject: profile.subject,\r\n thisProfileLink: profileCommentaryApiLink(\r\n commentary.id,\r\n profile.id,\r\n 'json',\r\n apiPathPrefix\r\n ),\r\n referenceChapterLink: profile.reference\r\n ? bookCommentaryChapterApiLink(\r\n commentary.id,\r\n profile.reference.book,\r\n profile.reference.chapter,\r\n 'json',\r\n apiPathPrefix\r\n )\r\n : null,\r\n };\r\n\r\n const apiProfileContent: ApiCommentaryProfileContent = {\r\n commentary: apiCommentary,\r\n profile: apiProfile,\r\n content: profile.content,\r\n };\r\n\r\n apiCommentary.totalNumberOfProfiles += 1;\r\n commentaryProfiles.profiles.push(apiProfile);\r\n api.commentaryProfileContents.push(apiProfileContent);\r\n }\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 api.commentaryProfiles.push(commentaryProfiles);\r\n }\r\n\r\n for (let { books, ...datasetInfo } of dataset.datasets ?? []) {\r\n const apiDataset: ApiDataset = {\r\n ...datasetInfo,\r\n availableFormats: ['json'],\r\n listOfBooksApiLink: listOfDatasetBooksApiLink(\r\n datasetInfo.id,\r\n apiPathPrefix\r\n ),\r\n numberOfBooks: books.length,\r\n totalNumberOfChapters: 0,\r\n totalNumberOfVerses: 0,\r\n totalNumberOfReferences: 0,\r\n languageName: getNativeName\r\n ? (getNativeName(datasetInfo.language) ?? undefined)\r\n : undefined,\r\n languageEnglishName: getEnglishName\r\n ? (getEnglishName(datasetInfo.language) ?? undefined)\r\n : undefined,\r\n };\r\n\r\n const datasetBooks: ApiDatasetBooks = {\r\n dataset: apiDataset,\r\n books: [],\r\n };\r\n\r\n let datasetChapters: ApiDatasetBookChapter[] = [];\r\n\r\n for (let { chapters, ...book } of books) {\r\n const firstChapterNumber = chapters[0]?.chapter.number ?? null;\r\n const lastChapterNumber =\r\n chapters[chapters.length - 1]?.chapter.number ?? null;\r\n const apiBook: ApiDatasetBook = {\r\n ...book,\r\n firstChapterNumber,\r\n firstChapterApiLink: bookDatasetChapterApiLink(\r\n datasetInfo.id,\r\n book.id,\r\n firstChapterNumber,\r\n 'json',\r\n apiPathPrefix\r\n ),\r\n lastChapterNumber,\r\n lastChapterApiLink: bookDatasetChapterApiLink(\r\n datasetInfo.id,\r\n book.id,\r\n lastChapterNumber,\r\n 'json',\r\n apiPathPrefix\r\n ),\r\n numberOfChapters: chapters.length,\r\n totalNumberOfVerses: 0,\r\n totalNumberOfReferences: 0,\r\n };\r\n\r\n for (let { chapter } of chapters) {\r\n const apiBookChapter: ApiDatasetBookChapter = {\r\n dataset: apiDataset,\r\n book: apiBook,\r\n chapter: chapter,\r\n thisChapterLink: bookDatasetChapterApiLink(\r\n datasetInfo.id,\r\n book.id,\r\n chapter.number,\r\n 'json',\r\n apiPathPrefix\r\n ),\r\n nextChapterApiLink: null,\r\n previousChapterApiLink: null,\r\n numberOfVerses: chapter.content.length,\r\n numberOfReferences: 0,\r\n };\r\n\r\n // apiBookChapter.numberOfVerses += ;\r\n for (let verse of chapter.content) {\r\n apiBookChapter.numberOfReferences +=\r\n verse.references.length;\r\n }\r\n\r\n apiBook.totalNumberOfVerses += apiBookChapter.numberOfVerses;\r\n apiBook.totalNumberOfReferences +=\r\n apiBookChapter.numberOfReferences;\r\n\r\n datasetChapters.push(apiBookChapter);\r\n if (!api.datasetBookChapters) {\r\n api.datasetBookChapters = [];\r\n }\r\n api.datasetBookChapters.push(apiBookChapter);\r\n }\r\n\r\n datasetBooks.books.push(apiBook);\r\n\r\n apiDataset.totalNumberOfChapters += apiBook.numberOfChapters;\r\n apiDataset.totalNumberOfVerses += apiBook.totalNumberOfVerses;\r\n apiDataset.totalNumberOfReferences +=\r\n apiBook.totalNumberOfReferences;\r\n }\r\n\r\n for (let i = 0; i < datasetChapters.length; i++) {\r\n if (i > 0) {\r\n datasetChapters[i].previousChapterApiLink =\r\n bookDatasetChapterApiLink(\r\n datasetInfo.id,\r\n datasetChapters[i - 1].book.id,\r\n datasetChapters[i - 1].chapter.number,\r\n 'json',\r\n apiPathPrefix\r\n );\r\n }\r\n\r\n if (i < datasetChapters.length - 1) {\r\n datasetChapters[i].nextChapterApiLink =\r\n bookDatasetChapterApiLink(\r\n datasetInfo.id,\r\n datasetChapters[i + 1].book.id,\r\n datasetChapters[i + 1].chapter.number,\r\n 'json',\r\n apiPathPrefix\r\n );\r\n }\r\n }\r\n\r\n if (!api.availableDatasets) {\r\n api.availableDatasets = {\r\n datasets: [],\r\n };\r\n }\r\n api.availableDatasets.datasets.push(apiDataset);\r\n if (!api.datasetBooks) {\r\n api.datasetBooks = [];\r\n }\r\n api.datasetBooks.push(datasetBooks);\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 // Generate complete translation download files\r\n for (let complete of api.translationComplete) {\r\n if (complete.translation.completeTranslationApiLink) {\r\n files.push(\r\n jsonFile(\r\n complete.translation.completeTranslationApiLink,\r\n complete\r\n )\r\n );\r\n }\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 commentaryProfiles of api.commentaryProfiles) {\r\n files.push(\r\n jsonFile(\r\n commentaryProfiles.commentary.listOfProfilesApiLink,\r\n commentaryProfiles\r\n )\r\n );\r\n }\r\n\r\n for (let profileContent of api.commentaryProfileContents) {\r\n files.push(\r\n jsonFile(profileContent.profile.thisProfileLink, profileContent)\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 if (api.availableDatasets) {\r\n files.push(\r\n jsonFile(\r\n `${api.pathPrefix}/api/available_datasets.json`,\r\n api.availableDatasets,\r\n true\r\n )\r\n );\r\n }\r\n\r\n if (api.datasetBooks) {\r\n for (let datasetBook of api.datasetBooks) {\r\n files.push(\r\n jsonFile(datasetBook.dataset.listOfBooksApiLink, datasetBook)\r\n );\r\n }\r\n }\r\n\r\n if (api.datasetBookChapters) {\r\n for (let datasetBookChapter of api.datasetBookChapters) {\r\n files.push(\r\n jsonFile(datasetBookChapter.thisChapterLink, datasetBookChapter)\r\n );\r\n }\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 complete translation download endpoint.\r\n * @param translationId The ID of the translation.\r\n * @param prefix The path prefix.\r\n * @returns\r\n */\r\nexport function completeTranslationApiLink(\r\n translationId: string,\r\n prefix: string = ''\r\n): string {\r\n return `${prefix}/api/${translationId}/complete.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 * Gets the API Link for the list of books endpoint for a dataset.\r\n * @param datasetId The ID of the dataset.\r\n * @returns\r\n */\r\nexport function listOfDatasetBooksApiLink(\r\n datasetId: string,\r\n prefix: string = ''\r\n): string {\r\n return `${prefix}/api/d/${datasetId}/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\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 bookDatasetChapterApiLink(\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/d/${translationId}/${replaceSpacesWithUnderscores(\r\n commonName\r\n )}/${chapterNumber}.${extension}`;\r\n}\r\n\r\n/**\r\n * Gets the API link for a profile.\r\n * @param translationId The ID of the translation.\r\n * @param profileId The ID of the profile.\r\n * @param extension The extension of the file.\r\n */\r\nexport function profilesCommentaryApiLink(\r\n translationId: string,\r\n extension: string,\r\n prefix: string = ''\r\n) {\r\n return `${prefix}/api/c/${translationId}/profiles.${extension}`;\r\n}\r\n\r\n/**\r\n * Gets the API link for a profile.\r\n * @param translationId The ID of the translation.\r\n * @param profileId The ID of the profile.\r\n * @param extension The extension of the file.\r\n */\r\nexport function profileCommentaryApiLink(\r\n translationId: string,\r\n profileId: string,\r\n extension: string,\r\n prefix: string = ''\r\n) {\r\n return `${prefix}/api/c/${translationId}/profiles/${replaceSpacesWithUnderscores(\r\n profileId\r\n )}.${extension}`;\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, '_');\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,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;AASO,gBAAS,0BACZ,eACA,YACA,eACA,WACA,SAAiB,IACnB;AACE,SAAO,GAAG,MAAM,UAAU,aAAa,IAAI;AAAA,IACvC;AAAA,EACJ,CAAC,IAAI,aAAa,IAAI,SAAS;AACnC;AAQO,gBAAS,0BACZ,eACA,WACA,SAAiB,IACnB;AACE,SAAO,GAAG,MAAM,UAAU,aAAa,aAAa,SAAS;AACjE;AAQO,gBAAS,yBACZ,eACA,WACA,WACA,SAAiB,IACnB;AACE,SAAO,GAAG,MAAM,UAAU,aAAa,aAAa;AAAA,IAChD;AAAA,EACJ,CAAC,IAAI,SAAS;AAClB;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
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
import { parseVerseReference } from "../utils.js";
|
|
3
|
+
import { getBookId, parseVerseReference } from "../utils.js";
|
|
4
4
|
export const chapterHeadingSchema = z.object({
|
|
5
5
|
type: z.literal("chapter-heading"),
|
|
6
6
|
data: z.object({
|
|
@@ -9,7 +9,10 @@ export const chapterHeadingSchema = z.object({
|
|
|
9
9
|
});
|
|
10
10
|
export const verseSchema = z.object({
|
|
11
11
|
type: z.literal("text"),
|
|
12
|
-
id: z.string()
|
|
12
|
+
id: z.string(),
|
|
13
|
+
bookCode: z.string().optional(),
|
|
14
|
+
chapter: z.number().optional(),
|
|
15
|
+
verse: z.number().optional()
|
|
13
16
|
});
|
|
14
17
|
export const paratextSchema = z.object({
|
|
15
18
|
type: z.literal("paratext"),
|
|
@@ -68,11 +71,11 @@ export class CodexParser {
|
|
|
68
71
|
}
|
|
69
72
|
chapter.content.push(...content);
|
|
70
73
|
}
|
|
71
|
-
function addReference(
|
|
72
|
-
addChapterContent(
|
|
74
|
+
function addReference(ref2, content) {
|
|
75
|
+
addChapterContent(ref2.chapter, [
|
|
73
76
|
{
|
|
74
77
|
type: "verse",
|
|
75
|
-
number:
|
|
78
|
+
number: ref2.verse,
|
|
76
79
|
content
|
|
77
80
|
}
|
|
78
81
|
]);
|
|
@@ -86,6 +89,24 @@ export class CodexParser {
|
|
|
86
89
|
content: [content]
|
|
87
90
|
};
|
|
88
91
|
}
|
|
92
|
+
function addLineBreaks(lines2) {
|
|
93
|
+
return lines2.reduce(
|
|
94
|
+
(prev, current) => {
|
|
95
|
+
if (prev.length === 0) return [current];
|
|
96
|
+
else
|
|
97
|
+
return [
|
|
98
|
+
...prev,
|
|
99
|
+
{
|
|
100
|
+
lineBreak: true
|
|
101
|
+
},
|
|
102
|
+
current
|
|
103
|
+
];
|
|
104
|
+
},
|
|
105
|
+
[]
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
let previousReference = null;
|
|
109
|
+
let lines = [];
|
|
89
110
|
for (let cell of data.cells) {
|
|
90
111
|
if (cell.languageId === "html" && cell.value) {
|
|
91
112
|
if (!cell.metadata) continue;
|
|
@@ -93,31 +114,57 @@ export class CodexParser {
|
|
|
93
114
|
if (!metadataResult.success) continue;
|
|
94
115
|
const metadata = metadataResult.data;
|
|
95
116
|
if (metadata.type === "text") {
|
|
96
|
-
|
|
97
|
-
if (!reference)
|
|
98
|
-
|
|
117
|
+
let reference = parseVerseReference(metadata.id);
|
|
118
|
+
if (!reference) {
|
|
119
|
+
if (metadata.bookCode && metadata.chapter) {
|
|
120
|
+
const bookId = getBookId(metadata.bookCode);
|
|
121
|
+
if (!bookId) {
|
|
122
|
+
throw new Error(
|
|
123
|
+
"Could not find book ID for code: " + metadata.bookCode
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
if (metadata.verse) {
|
|
127
|
+
reference = {
|
|
128
|
+
book: bookId,
|
|
129
|
+
chapter: metadata.chapter,
|
|
130
|
+
verse: metadata.verse
|
|
131
|
+
};
|
|
132
|
+
} else if (previousReference?.verse) {
|
|
133
|
+
if (previousReference.chapter !== metadata.chapter || previousReference.book !== bookId) {
|
|
134
|
+
throw new Error(
|
|
135
|
+
"Cannot infer verse number for non-consecutive verse reference."
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
reference = {
|
|
139
|
+
book: bookId,
|
|
140
|
+
chapter: metadata.chapter,
|
|
141
|
+
verse: previousReference.verse
|
|
142
|
+
};
|
|
143
|
+
} else {
|
|
144
|
+
throw new Error(
|
|
145
|
+
"Could not find verse reference in metadata."
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
} else {
|
|
149
|
+
throw new Error(
|
|
150
|
+
"Could not find verse reference in metadata."
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
if (previousReference && (reference.book !== previousReference.book || reference.chapter !== previousReference.chapter || reference.verse !== previousReference.verse)) {
|
|
155
|
+
addReference(previousReference, addLineBreaks(lines));
|
|
156
|
+
lines = [];
|
|
157
|
+
}
|
|
158
|
+
previousReference = reference;
|
|
99
159
|
if (!root.id) root.id = reference.book;
|
|
100
160
|
const content = stripHTML(cell.value);
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
if (prev.length === 0) return [current];
|
|
104
|
-
else
|
|
105
|
-
return [
|
|
106
|
-
...prev,
|
|
107
|
-
{
|
|
108
|
-
lineBreak: true
|
|
109
|
-
},
|
|
110
|
-
current
|
|
111
|
-
];
|
|
112
|
-
},
|
|
113
|
-
[]
|
|
114
|
-
);
|
|
115
|
-
addReference(reference, lines);
|
|
161
|
+
const newLines = content.split("\n");
|
|
162
|
+
lines.push(...newLines);
|
|
116
163
|
} else if (metadata.type === "paratext") {
|
|
117
164
|
const reference = parseVerseReference(`${metadata.id}:1`);
|
|
118
165
|
if (reference) {
|
|
119
166
|
const content = stripHTML(cell.value);
|
|
120
|
-
const
|
|
167
|
+
const lines2 = content.split("\n").reduce((prev, current) => {
|
|
121
168
|
if (prev.length === 0)
|
|
122
169
|
return [toHeading(current)];
|
|
123
170
|
else
|
|
@@ -129,7 +176,7 @@ export class CodexParser {
|
|
|
129
176
|
toHeading(current)
|
|
130
177
|
];
|
|
131
178
|
}, []);
|
|
132
|
-
|
|
179
|
+
lines2.forEach(
|
|
133
180
|
(line) => addChapterContent(reference.chapter, [line])
|
|
134
181
|
);
|
|
135
182
|
} else {
|
|
@@ -147,6 +194,9 @@ export class CodexParser {
|
|
|
147
194
|
}
|
|
148
195
|
}
|
|
149
196
|
}
|
|
197
|
+
if (previousReference) {
|
|
198
|
+
addReference(previousReference, addLineBreaks(lines));
|
|
199
|
+
}
|
|
150
200
|
for (let chapter of chapters.values()) {
|
|
151
201
|
root.content.push(chapter);
|
|
152
202
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../parser/codex-parser.ts"],
|
|
4
|
-
"sourcesContent": ["import { z } from 'zod';\nimport {\n Chapter,\n ChapterContent,\n ParseTree,\n Verse,\n VerseContent,\n} from './types.js';\nimport { parseVerseReference, VerseRef } from '../utils.js';\n\nexport const chapterHeadingSchema = z.object({\n type: z.literal('chapter-heading'),\n data: z.object({\n chapter: z.coerce.number().int(),\n }),\n});\n\nexport const verseSchema = z.object({\n type: z.literal('text'),\n id: z.string(),\n});\n\nexport const paratextSchema = z.object({\n type: z.literal('paratext'),\n id: z.string(),\n});\n\nexport const metadataSchema = z.discriminatedUnion('type', [\n chapterHeadingSchema,\n verseSchema,\n paratextSchema,\n]);\n\nexport const codexSchema = z.object({\n cells: z.array(\n z.object({\n kind: z.number(),\n languageId: z.string(),\n value: z.string(),\n metadata: z\n .object({\n type: z.string(),\n })\n .passthrough()\n .nullable()\n .optional(),\n })\n ),\n});\n\n/**\n * Defines a parser for codex files.\n */\nexport class CodexParser {\n // TODO:\n // /**\n // * Whether to preserve markdown in the parsed content.\n // */\n // preserveMarkdown: boolean = true;\n\n private _noteCounter: number = 0;\n\n /**\n * Parses the specified codex content.\n *\n * @param codex The codex content to parse.\n * @returns The parse tree that was generated.\n */\n public parse(codex: string): ParseTree {\n const json = JSON.parse(codex);\n const data = codexSchema.parse(json);\n\n let root: ParseTree = {\n type: 'root',\n content: [],\n };\n\n let chapters: Map<number, Chapter> = new Map();\n let lastChapter: Chapter | null = null;\n\n function addChapterContent(\n chapterNumber: number,\n content: ChapterContent[]\n ) {\n let chapter = chapters.get(chapterNumber);\n if (!chapter) {\n chapter = {\n type: 'chapter',\n number: chapterNumber,\n content: [],\n footnotes: [],\n };\n lastChapter = chapter;\n chapters.set(chapterNumber, chapter);\n }\n\n chapter.content.push(...content);\n }\n\n function addReference(ref: VerseRef, content: Verse['content']) {\n addChapterContent(ref.chapter, [\n {\n type: 'verse',\n number: ref.verse,\n content: content,\n },\n ]);\n }\n\n function stripHTML(value: string) {\n return value.replace(/<[^>]*>/g, '');\n }\n\n function toHeading(content: string) {\n return {\n type: 'heading',\n content: [content],\n } satisfies ChapterContent;\n }\n\n for (let cell of data.cells) {\n if (cell.languageId === 'html' && cell.value) {\n if (!cell.metadata) continue; // ignore html cells without metadata\n\n const metadataResult = metadataSchema.safeParse(cell.metadata);\n\n if (!metadataResult.success) continue; // ignore cells with invalid/unknown metadata\n const metadata = metadataResult.data;\n if (metadata.type === 'text') {\n
|
|
5
|
-
"mappings": ";AAAA,SAAS,SAAS;AAQlB,SAAS,2BAAqC;
|
|
6
|
-
"names": []
|
|
4
|
+
"sourcesContent": ["import { z } from 'zod';\nimport {\n Chapter,\n ChapterContent,\n ParseTree,\n Verse,\n VerseContent,\n} from './types.js';\nimport { getBookId, parseVerseReference, VerseRef } from '../utils.js';\nimport { ref } from 'process';\n\nexport const chapterHeadingSchema = z.object({\n type: z.literal('chapter-heading'),\n data: z.object({\n chapter: z.coerce.number().int(),\n }),\n});\n\nexport const verseSchema = z.object({\n type: z.literal('text'),\n id: z.string(),\n bookCode: z.string().optional(),\n chapter: z.number().optional(),\n verse: z.number().optional(),\n});\n\nexport const paratextSchema = z.object({\n type: z.literal('paratext'),\n id: z.string(),\n});\n\nexport const metadataSchema = z.discriminatedUnion('type', [\n chapterHeadingSchema,\n verseSchema,\n paratextSchema,\n]);\n\nexport const codexSchema = z.object({\n cells: z.array(\n z.object({\n kind: z.number(),\n languageId: z.string(),\n value: z.string(),\n metadata: z\n .object({\n type: z.string(),\n })\n .passthrough()\n .nullable()\n .optional(),\n })\n ),\n});\n\n/**\n * Defines a parser for codex files.\n */\nexport class CodexParser {\n // TODO:\n // /**\n // * Whether to preserve markdown in the parsed content.\n // */\n // preserveMarkdown: boolean = true;\n\n private _noteCounter: number = 0;\n\n /**\n * Parses the specified codex content.\n *\n * @param codex The codex content to parse.\n * @returns The parse tree that was generated.\n */\n public parse(codex: string): ParseTree {\n const json = JSON.parse(codex);\n const data = codexSchema.parse(json);\n\n let root: ParseTree = {\n type: 'root',\n content: [],\n };\n\n let chapters: Map<number, Chapter> = new Map();\n let lastChapter: Chapter | null = null;\n\n function addChapterContent(\n chapterNumber: number,\n content: ChapterContent[]\n ) {\n let chapter = chapters.get(chapterNumber);\n if (!chapter) {\n chapter = {\n type: 'chapter',\n number: chapterNumber,\n content: [],\n footnotes: [],\n };\n lastChapter = chapter;\n chapters.set(chapterNumber, chapter);\n }\n\n chapter.content.push(...content);\n }\n\n function addReference(ref: VerseRef, content: Verse['content']) {\n addChapterContent(ref.chapter, [\n {\n type: 'verse',\n number: ref.verse,\n content: content,\n },\n ]);\n }\n\n function stripHTML(value: string) {\n return value.replace(/<[^>]*>/g, '');\n }\n\n function toHeading(content: string) {\n return {\n type: 'heading',\n content: [content],\n } satisfies ChapterContent;\n }\n\n function addLineBreaks(lines: Verse['content']) {\n return lines.reduce(\n (prev, current) => {\n if (prev.length === 0) return [current];\n else\n return [\n ...prev,\n {\n lineBreak: true,\n },\n current,\n ] satisfies Verse['content'];\n },\n [] as Verse['content']\n );\n }\n\n let previousReference: VerseRef | null = null;\n let lines: Verse['content'] = [];\n\n for (let cell of data.cells) {\n if (cell.languageId === 'html' && cell.value) {\n if (!cell.metadata) continue; // ignore html cells without metadata\n\n const metadataResult = metadataSchema.safeParse(cell.metadata);\n\n if (!metadataResult.success) continue; // ignore cells with invalid/unknown metadata\n const metadata = metadataResult.data;\n if (metadata.type === 'text') {\n let reference = parseVerseReference(metadata.id);\n if (!reference) {\n if (metadata.bookCode && metadata.chapter) {\n const bookId = getBookId(metadata.bookCode);\n if (!bookId) {\n throw new Error(\n 'Could not find book ID for code: ' +\n metadata.bookCode\n );\n }\n\n if (metadata.verse) {\n reference = {\n book: bookId,\n chapter: metadata.chapter,\n verse: metadata.verse,\n };\n } else if (previousReference?.verse) {\n if (\n previousReference.chapter !==\n metadata.chapter ||\n previousReference.book !== bookId\n ) {\n throw new Error(\n 'Cannot infer verse number for non-consecutive verse reference.'\n );\n }\n\n // Sometimes codex doesn't include verse numbers for every cell, so we infer it from the previous reference\n reference = {\n book: bookId,\n chapter: metadata.chapter,\n verse: previousReference.verse,\n };\n } else {\n throw new Error(\n 'Could not find verse reference in metadata.'\n );\n }\n } else {\n throw new Error(\n 'Could not find verse reference in metadata.'\n );\n }\n }\n\n if (\n previousReference &&\n (reference.book !== previousReference.book ||\n reference.chapter !== previousReference.chapter ||\n reference.verse !== previousReference.verse)\n ) {\n addReference(previousReference, addLineBreaks(lines));\n lines = [];\n }\n\n previousReference = reference;\n\n if (!root.id) root.id = reference.book; // set book id if not already set\n\n const content = stripHTML(cell.value);\n\n // add line breaks in heading if there are multiple lines\n const newLines = content.split('\\n');\n\n lines.push(...newLines);\n } else if (metadata.type === 'paratext') {\n const reference = parseVerseReference(`${metadata.id}:1`); // chapter headings do not have a verse reference always default to 1\n if (reference) {\n const content = stripHTML(cell.value);\n\n // add line breaks in heading if there are multiple lines\n const lines = content\n .split('\\n')\n .reduce<ChapterContent[]>((prev, current) => {\n if (prev.length === 0)\n return [toHeading(current)];\n else\n return [\n ...prev,\n {\n type: 'line_break',\n },\n toHeading(current),\n ] satisfies ChapterContent[];\n }, []);\n\n lines.forEach((line) =>\n addChapterContent(reference.chapter, [line])\n );\n } else {\n // parse paratext that isn't a chapter reference as footnote\n const content = stripHTML(cell.value);\n if (!cell.metadata) {\n if (lastChapter) {\n (lastChapter as Chapter).footnotes.push({\n noteId: this._noteCounter++,\n text: content,\n caller: null,\n });\n }\n }\n }\n }\n }\n }\n\n if (previousReference) {\n addReference(previousReference, addLineBreaks(lines));\n }\n\n for (let chapter of chapters.values()) {\n root.content.push(chapter);\n }\n\n return root;\n }\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,SAAS;AAQlB,SAAS,WAAW,2BAAqC;AAGlD,aAAM,uBAAuB,EAAE,OAAO;AAAA,EACzC,MAAM,EAAE,QAAQ,iBAAiB;AAAA,EACjC,MAAM,EAAE,OAAO;AAAA,IACX,SAAS,EAAE,OAAO,OAAO,EAAE,IAAI;AAAA,EACnC,CAAC;AACL,CAAC;AAEM,aAAM,cAAc,EAAE,OAAO;AAAA,EAChC,MAAM,EAAE,QAAQ,MAAM;AAAA,EACtB,IAAI,EAAE,OAAO;AAAA,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