@helloao/tools 0.0.10 → 0.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/dist/cjs/generation/api.cjs +69 -1
  2. package/dist/cjs/generation/api.cjs.map +2 -2
  3. package/dist/cjs/generation/common-types.cjs.map +1 -1
  4. package/dist/cjs/generation/dataset.cjs +59 -42
  5. package/dist/cjs/generation/dataset.cjs.map +3 -3
  6. package/dist/cjs/index.cjs +3 -0
  7. package/dist/cjs/index.cjs.map +2 -2
  8. package/dist/cjs/log.cjs +50 -0
  9. package/dist/cjs/log.cjs.map +7 -0
  10. package/dist/cjs/parser/codex-parser.cjs +15 -12
  11. package/dist/cjs/parser/codex-parser.cjs.map +2 -2
  12. package/dist/cjs/parser/commentary-csv-parser.cjs.map +2 -2
  13. package/dist/cjs/parser/iterators.cjs +17 -6
  14. package/dist/cjs/parser/iterators.cjs.map +2 -2
  15. package/dist/cjs/parser/tyndale-xml-parser.cjs +212 -0
  16. package/dist/cjs/parser/tyndale-xml-parser.cjs.map +7 -0
  17. package/dist/cjs/parser/types.cjs.map +1 -1
  18. package/dist/cjs/parser/usfm-parser.cjs +4 -2
  19. package/dist/cjs/parser/usfm-parser.cjs.map +2 -2
  20. package/dist/cjs/utils.cjs +26 -4
  21. package/dist/cjs/utils.cjs.map +2 -2
  22. package/dist/esm/generation/api.js +65 -1
  23. package/dist/esm/generation/api.js.map +2 -2
  24. package/dist/esm/generation/dataset.js +60 -43
  25. package/dist/esm/generation/dataset.js.map +2 -2
  26. package/dist/esm/index.js +2 -1
  27. package/dist/esm/index.js.map +2 -2
  28. package/dist/esm/log.js +20 -0
  29. package/dist/esm/log.js.map +7 -0
  30. package/dist/esm/parser/codex-parser.js +15 -12
  31. package/dist/esm/parser/codex-parser.js.map +2 -2
  32. package/dist/esm/parser/commentary-csv-parser.js.map +2 -2
  33. package/dist/esm/parser/iterators.js +17 -6
  34. package/dist/esm/parser/iterators.js.map +2 -2
  35. package/dist/esm/parser/tyndale-xml-parser.js +184 -0
  36. package/dist/esm/parser/tyndale-xml-parser.js.map +7 -0
  37. package/dist/esm/parser/usfm-parser.js +4 -2
  38. package/dist/esm/parser/usfm-parser.js.map +2 -2
  39. package/dist/esm/utils.js +26 -4
  40. package/dist/esm/utils.js.map +2 -2
  41. package/dist/types/generation/api.d.ts +76 -1
  42. package/dist/types/generation/common-types.d.ts +32 -2
  43. package/dist/types/generation/dataset.d.ts +17 -3
  44. package/dist/types/index.d.ts +2 -1
  45. package/dist/types/log.d.ts +23 -0
  46. package/dist/types/parser/tyndale-xml-parser.d.ts +8 -0
  47. package/dist/types/parser/types.d.ts +25 -0
  48. package/dist/types/utils.d.ts +8 -0
  49. package/package.json +35 -13
@@ -51,13 +51,21 @@ function getFirstNonEmpty(...values) {
51
51
  throw new Error("All values are empty or whitespace!");
52
52
  }
53
53
  function parseVerseReference(text) {
54
- const match = text.match(/^\s*([0-9A-Za-z\s]+)\s+(\d+):(\d+)/);
54
+ const match = text.match(
55
+ /^\s*([0-9A-Za-z\s]+)[\s\.]+(\d+)[:\.](\d+)(?:-([0-9]+)(?:[\s:\.]([0-9]+))?)?/
56
+ );
55
57
  if (!match) {
56
58
  return null;
57
59
  }
58
- const [reference, book, chapterStr, verseStr] = match;
60
+ const [reference, book, chapterStr, verseStr, endChapterStr, endVerseStr] = match;
59
61
  const chapter = parseInt(chapterStr);
60
62
  const verse = parseInt(verseStr);
63
+ let endChapter = endChapterStr ? parseInt(endChapterStr) : void 0;
64
+ let endVerse = endVerseStr ? parseInt(endVerseStr) : void 0;
65
+ if (endChapter && !endVerse) {
66
+ endVerse = endChapter;
67
+ endChapter = void 0;
68
+ }
61
69
  if (isNaN(chapter) || isNaN(verse)) {
62
70
  return null;
63
71
  }
@@ -66,13 +74,17 @@ function parseVerseReference(text) {
66
74
  book: getBookId(book) ?? book,
67
75
  chapter,
68
76
  verse,
69
- content: text.substring(reference.length).trim()
77
+ content: text.substring(reference.length).trim(),
78
+ endChapter,
79
+ endVerse
70
80
  };
71
81
  }
72
82
  return {
73
83
  book: getBookId(book) ?? book,
74
84
  chapter,
75
- verse
85
+ verse,
86
+ endChapter,
87
+ endVerse
76
88
  };
77
89
  }
78
90
  const BOOK_ID_MAP = /* @__PURE__ */ new Map([
@@ -99,8 +111,10 @@ const BOOK_ID_MAP = /* @__PURE__ */ new Map([
99
111
  ["2samuel", "2SA"],
100
112
  ["1ki", "1KI"],
101
113
  ["1kings", "1KI"],
114
+ ["1kgs", "1KI"],
102
115
  ["2ki", "2KI"],
103
116
  ["2kings", "2KI"],
117
+ ["2kgs", "2KI"],
104
118
  ["1ch", "1CH"],
105
119
  ["1chronicles", "1CH"],
106
120
  ["chronicles1", "1CH"],
@@ -114,14 +128,18 @@ const BOOK_ID_MAP = /* @__PURE__ */ new Map([
114
128
  ["est", "EST"],
115
129
  ["ester", "EST"],
116
130
  ["job", "JOB"],
131
+ ["ps", "PSA"],
117
132
  ["psa", "PSA"],
118
133
  ["psalms", "PSA"],
119
134
  ["psalm", "PSA"],
135
+ ["pr", "PRO"],
120
136
  ["pro", "PRO"],
121
137
  ["proverbs", "PRO"],
122
138
  ["ecc", "ECC"],
123
139
  ["ecclesiastes", "ECC"],
140
+ ["eccl", "ECC"],
124
141
  ["sng", "SNG"],
142
+ ["song", "SNG"],
125
143
  ["songofsolomon", "SNG"],
126
144
  ["isa", "ISA"],
127
145
  ["isaiah", "ISA"],
@@ -131,6 +149,7 @@ const BOOK_ID_MAP = /* @__PURE__ */ new Map([
131
149
  ["lamentations", "LAM"],
132
150
  ["ezk", "EZK"],
133
151
  ["ezekiel", "EZK"],
152
+ ["ezek", "EZK"],
134
153
  ["dan", "DAN"],
135
154
  ["daniel", "DAN"],
136
155
  ["hos", "HOS"],
@@ -147,6 +166,7 @@ const BOOK_ID_MAP = /* @__PURE__ */ new Map([
147
166
  ["micah", "MIC"],
148
167
  ["nam", "NAM"],
149
168
  ["nahum", "NAM"],
169
+ ["nah", "NAM"],
150
170
  ["hab", "HAB"],
151
171
  ["habakkuk", "HAB"],
152
172
  ["zep", "ZEP"],
@@ -179,6 +199,7 @@ const BOOK_ID_MAP = /* @__PURE__ */ new Map([
179
199
  ["ephesians", "EPH"],
180
200
  ["php", "PHP"],
181
201
  ["philippians", "PHP"],
202
+ ["phil", "PHP"],
182
203
  ["col", "COL"],
183
204
  ["colossians", "COL"],
184
205
  ["1th", "1TH"],
@@ -193,6 +214,7 @@ const BOOK_ID_MAP = /* @__PURE__ */ new Map([
193
214
  ["titus", "TIT"],
194
215
  ["phm", "PHM"],
195
216
  ["philemon", "PHM"],
217
+ ["phlm", "PHM"],
196
218
  ["heb", "HEB"],
197
219
  ["hebrews", "HEB"],
198
220
  ["jas", "JAS"],
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../utils.ts"],
4
- "sourcesContent": ["/**\r\n * Normalizes the given language code into a ISO 639 code.\r\n * @param language The language code to normalize.\r\n */\r\nexport function normalizeLanguage(language: string): string {\r\n return language;\r\n}\r\n\r\n/**\r\n * The map of translation IDs from fetch.bible to their translation ID in the API.\r\n */\r\nconst TRANSLATION_ID_MAP: Map<string, string> = new Map([\r\n ['eng_bsb', 'BSB'],\r\n ['arb_nav', 'ARBNAV'],\r\n ['eng_webp', 'ENGWEBP'],\r\n ['hin_irv', 'HINIRV'],\r\n ['hbo_mas', 'HBOMAS'],\r\n]);\r\n\r\n/**\r\n * Gets the ID of the translation.\r\n * @param translation The translation to get the ID for.\r\n */\r\nexport function getTranslationId(translationId: string): string {\r\n return TRANSLATION_ID_MAP.get(translationId) ?? translationId;\r\n}\r\n\r\nexport function isEmptyOrWhitespace(str: string | null | undefined): boolean {\r\n return !str || /^\\s*$/.test(str);\r\n}\r\n\r\nexport function getFirstNonEmpty<T extends string>(...values: T[]): T {\r\n for (let value of values) {\r\n if (!isEmptyOrWhitespace(value)) {\r\n return value;\r\n }\r\n }\r\n\r\n throw new Error('All values are empty or whitespace!');\r\n}\r\n\r\nexport interface VerseRef {\r\n book: string;\r\n chapter: number;\r\n verse: number;\r\n\r\n /**\r\n * The rest of the content of the verse.\r\n */\r\n content?: string;\r\n}\r\n\r\n/**\r\n * Parses the given verse reference.\r\n * Formatted like \"GEN 1:1\".\r\n *\r\n * @param text The reference to parse.\r\n */\r\nexport function parseVerseReference(text: string): VerseRef | null {\r\n const match = text.match(/^\\s*([0-9A-Za-z\\s]+)\\s+(\\d+):(\\d+)/);\r\n\r\n if (!match) {\r\n return null;\r\n }\r\n\r\n const [reference, book, chapterStr, verseStr] = match;\r\n\r\n const chapter = parseInt(chapterStr);\r\n const verse = parseInt(verseStr);\r\n\r\n if (isNaN(chapter) || isNaN(verse)) {\r\n return null;\r\n }\r\n\r\n if (reference.length !== text.length) {\r\n return {\r\n book: getBookId(book) ?? book,\r\n chapter,\r\n verse,\r\n content: text.substring(reference.length).trim(),\r\n };\r\n }\r\n\r\n return {\r\n book: getBookId(book) ?? book,\r\n chapter,\r\n verse,\r\n };\r\n}\r\n\r\n/**\r\n * Defines a map that maps the book ID to the numerical order of the book.\r\n */\r\nconst BOOK_ID_MAP: Map<string, string> = new Map([\r\n ['gen', 'GEN'],\r\n ['genesis', 'GEN'],\r\n ['exo', 'EXO'],\r\n ['exodus', 'EXO'],\r\n ['lev', 'LEV'],\r\n ['lev', 'LEV'],\r\n ['laviticus', 'LEV'],\r\n ['num', 'NUM'],\r\n ['numbers', 'NUM'],\r\n ['deu', 'DEU'],\r\n ['deuteronomy', 'DEU'],\r\n ['jos', 'JOS'],\r\n ['joshua', 'JOS'],\r\n ['jdg', 'JDG'],\r\n ['judges', 'JDG'],\r\n ['rut', 'RUT'],\r\n ['ruth', 'RUT'],\r\n ['1sa', '1SA'],\r\n ['1samuel', '1SA'],\r\n ['2sa', '2SA'],\r\n ['2samuel', '2SA'],\r\n ['1ki', '1KI'],\r\n ['1kings', '1KI'],\r\n ['2ki', '2KI'],\r\n ['2kings', '2KI'],\r\n ['1ch', '1CH'],\r\n ['1chronicles', '1CH'],\r\n ['chronicles1', '1CH'],\r\n ['2ch', '2CH'],\r\n ['2chronicles', '2CH'],\r\n ['chronicles2', '2CH'],\r\n ['ezr', 'EZR'],\r\n ['ezra', 'EZR'],\r\n ['neh', 'NEH'],\r\n ['nehemiah', 'NEH'],\r\n ['est', 'EST'],\r\n ['ester', 'EST'],\r\n ['job', 'JOB'],\r\n ['psa', 'PSA'],\r\n ['psalms', 'PSA'],\r\n ['psalm', 'PSA'],\r\n ['pro', 'PRO'],\r\n ['proverbs', 'PRO'],\r\n ['ecc', 'ECC'],\r\n ['ecclesiastes', 'ECC'],\r\n ['sng', 'SNG'],\r\n ['songofsolomon', 'SNG'],\r\n ['isa', 'ISA'],\r\n ['isaiah', 'ISA'],\r\n ['jer', 'JER'],\r\n ['jeremiah', 'JER'],\r\n ['lam', 'LAM'],\r\n ['lamentations', 'LAM'],\r\n ['ezk', 'EZK'],\r\n ['ezekiel', 'EZK'],\r\n ['dan', 'DAN'],\r\n ['daniel', 'DAN'],\r\n ['hos', 'HOS'],\r\n ['hosea', 'HOS'],\r\n ['jol', 'JOL'],\r\n ['joel', 'JOL'],\r\n ['amo', 'AMO'],\r\n ['amos', 'AMO'],\r\n ['oba', 'OBA'],\r\n ['obadiah', 'OBA'],\r\n ['jon', 'JON'],\r\n ['jonah', 'JON'],\r\n ['mic', 'MIC'],\r\n ['micah', 'MIC'],\r\n ['nam', 'NAM'],\r\n ['nahum', 'NAM'],\r\n ['hab', 'HAB'],\r\n ['habakkuk', 'HAB'],\r\n ['zep', 'ZEP'],\r\n ['zepaniah', 'ZEP'],\r\n ['hag', 'HAG'],\r\n ['haggai', 'HAG'],\r\n ['zec', 'ZEC'],\r\n ['zechariah', 'ZEC'],\r\n ['mal', 'MAL'],\r\n ['malachi', 'MAL'],\r\n ['mat', 'MAT'],\r\n ['matthew', 'MAT'],\r\n ['mrk', 'MRK'],\r\n ['mark', 'MRK'],\r\n ['luk', 'LUK'],\r\n ['luke', 'LUK'],\r\n ['jhn', 'JHN'],\r\n ['john', 'JHN'],\r\n ['act', 'ACT'],\r\n ['acts', 'ACT'],\r\n ['rom', 'ROM'],\r\n ['romans', 'ROM'],\r\n ['1co', '1CO'],\r\n ['1corinthians', '1CO'],\r\n ['2co', '2CO'],\r\n ['2corinthians', '2CO'],\r\n ['gal', 'GAL'],\r\n ['galatians', 'GAL'],\r\n ['eph', 'EPH'],\r\n ['ephesians', 'EPH'],\r\n ['php', 'PHP'],\r\n ['philippians', 'PHP'],\r\n ['col', 'COL'],\r\n ['colossians', 'COL'],\r\n ['1th', '1TH'],\r\n ['1thessalonians', '1TH'],\r\n ['2th', '2TH'],\r\n ['2thessalonians', '2TH'],\r\n ['1ti', '1TI'],\r\n ['1timothy', '1TI'],\r\n ['2ti', '2TI'],\r\n ['2timothy', '2TI'],\r\n ['tit', 'TIT'],\r\n ['titus', 'TIT'],\r\n ['phm', 'PHM'],\r\n ['philemon', 'PHM'],\r\n ['heb', 'HEB'],\r\n ['hebrews', 'HEB'],\r\n ['jas', 'JAS'],\r\n ['james', 'JAS'],\r\n ['1pe', '1PE'],\r\n ['1peter', '1PE'],\r\n ['2pe', '2PE'],\r\n ['2peter', '2PE'],\r\n ['1jn', '1JN'],\r\n ['1john', '1JN'],\r\n ['2jn', '2JN'],\r\n ['2john', '2JN'],\r\n ['3jn', '3JN'],\r\n ['3john', '3JN'],\r\n ['jud', 'JUD'],\r\n ['jude', 'JUD'],\r\n ['rev', 'REV'],\r\n ['revelation', 'REV'],\r\n]);\r\n\r\n/**\r\n * Gets the ID of the given book.\r\n * Returns null if the ID could not be found.\r\n * @param book The name/ID of the book.\r\n */\r\nexport function getBookId(book: string): string | null {\r\n const bookLower = book.toLowerCase().replaceAll(/\\s+/g, '');\r\n\r\n const id = BOOK_ID_MAP.get(bookLower);\r\n if (id) {\r\n return id;\r\n }\r\n\r\n for (let [key, id] of BOOK_ID_MAP) {\r\n if (bookLower.startsWith(key)) {\r\n return id;\r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AK;AAAA,EAChB,CAAC,OAAO,KAAK;AAAA,EACb,CAAC,UAAU,KAAK;AAAA,EAChB,CAAC,OAAO,KAAK;AAAA,EACb,CAAC,SAAS,KAAK;AAAA,EACf,CAAC,OAAO,KAAK;AAAA,EACb,CAAC,SAAS,KAAK;AAAA,EACf,CAAC,OAAO,KAAK;AAAA,EACb,CAAC,SAAS,KAAK;AAAA,EACf,CAAC,OAAO,KAAK;AAAA,EACb,CAAC,QAAQ,KAAK;AAAA,EACd,CAAC,OAAO,KAAK;AAAA,EACb,CAAC,cAAc,KAAK;AACxB,CAAC;AAOM,SAAS,UAAU,MAA6B;AACnD,QAAM,YAAY,KAAK,YAAY,EAAE,WAAW,QAAQ,EAAE;AAE1D,QAAM,KAAK,YAAY,IAAI,SAAS;AACpC,MAAI,IAAI;AACJ,WAAO;AAAA,EACX;AAEA,WAAS,CAAC,KAAKA,GAAE,KAAK,aAAa;AAC/B,QAAI,UAAU,WAAW,GAAG,GAAG;AAC3B,aAAOA;AAAA,IACX;AAAA,EACJ;AAEA,SAAO;AACX;",
4
+ "sourcesContent": ["/**\r\n * Normalizes the given language code into a ISO 639 code.\r\n * @param language The language code to normalize.\r\n */\r\nexport function normalizeLanguage(language: string): string {\r\n return language;\r\n}\r\n\r\n/**\r\n * The map of translation IDs from fetch.bible to their translation ID in the API.\r\n */\r\nconst TRANSLATION_ID_MAP: Map<string, string> = new Map([\r\n ['eng_bsb', 'BSB'],\r\n ['arb_nav', 'ARBNAV'],\r\n ['eng_webp', 'ENGWEBP'],\r\n ['hin_irv', 'HINIRV'],\r\n ['hbo_mas', 'HBOMAS'],\r\n]);\r\n\r\n/**\r\n * Gets the ID of the translation.\r\n * @param translation The translation to get the ID for.\r\n */\r\nexport function getTranslationId(translationId: string): string {\r\n return TRANSLATION_ID_MAP.get(translationId) ?? translationId;\r\n}\r\n\r\nexport function isEmptyOrWhitespace(str: string | null | undefined): boolean {\r\n return !str || /^\\s*$/.test(str);\r\n}\r\n\r\nexport function getFirstNonEmpty<T extends string>(...values: T[]): T {\r\n for (let value of values) {\r\n if (!isEmptyOrWhitespace(value)) {\r\n return value;\r\n }\r\n }\r\n\r\n throw new Error('All values are empty or whitespace!');\r\n}\r\n\r\nexport interface VerseRef {\r\n book: string;\r\n chapter: number;\r\n verse: number;\r\n\r\n /**\r\n * The rest of the content of the verse.\r\n */\r\n content?: string;\r\n\r\n /**\r\n * The chapter that the verse reference ends at.\r\n */\r\n endChapter?: number;\r\n\r\n /**\r\n * The verse that the verse reference ends at.\r\n */\r\n endVerse?: number;\r\n}\r\n\r\n/**\r\n * Parses the given verse reference.\r\n * Formatted like \"GEN 1:1\".\r\n *\r\n * @param text The reference to parse.\r\n */\r\nexport function parseVerseReference(text: string): VerseRef | null {\r\n const match = text.match(\r\n /^\\s*([0-9A-Za-z\\s]+)[\\s\\.]+(\\d+)[:\\.](\\d+)(?:-([0-9]+)(?:[\\s:\\.]([0-9]+))?)?/\r\n );\r\n\r\n if (!match) {\r\n return null;\r\n }\r\n\r\n const [reference, book, chapterStr, verseStr, endChapterStr, endVerseStr] =\r\n match;\r\n\r\n const chapter = parseInt(chapterStr);\r\n const verse = parseInt(verseStr);\r\n\r\n let endChapter = endChapterStr ? parseInt(endChapterStr) : undefined;\r\n let endVerse = endVerseStr ? parseInt(endVerseStr) : undefined;\r\n\r\n if (endChapter && !endVerse) {\r\n endVerse = endChapter;\r\n endChapter = undefined;\r\n }\r\n\r\n if (isNaN(chapter) || isNaN(verse)) {\r\n return null;\r\n }\r\n\r\n if (reference.length !== text.length) {\r\n return {\r\n book: getBookId(book) ?? book,\r\n chapter,\r\n verse,\r\n content: text.substring(reference.length).trim(),\r\n endChapter,\r\n endVerse,\r\n };\r\n }\r\n\r\n return {\r\n book: getBookId(book) ?? book,\r\n chapter,\r\n verse,\r\n endChapter,\r\n endVerse,\r\n };\r\n}\r\n\r\n/**\r\n * Defines a map that maps the book ID to the numerical order of the book.\r\n */\r\nconst BOOK_ID_MAP: Map<string, string> = new Map([\r\n ['gen', 'GEN'],\r\n ['genesis', 'GEN'],\r\n ['exo', 'EXO'],\r\n ['exodus', 'EXO'],\r\n ['lev', 'LEV'],\r\n ['lev', 'LEV'],\r\n ['laviticus', 'LEV'],\r\n ['num', 'NUM'],\r\n ['numbers', 'NUM'],\r\n ['deu', 'DEU'],\r\n ['deuteronomy', 'DEU'],\r\n ['jos', 'JOS'],\r\n ['joshua', 'JOS'],\r\n ['jdg', 'JDG'],\r\n ['judges', 'JDG'],\r\n ['rut', 'RUT'],\r\n ['ruth', 'RUT'],\r\n ['1sa', '1SA'],\r\n ['1samuel', '1SA'],\r\n ['2sa', '2SA'],\r\n ['2samuel', '2SA'],\r\n ['1ki', '1KI'],\r\n ['1kings', '1KI'],\r\n ['1kgs', '1KI'],\r\n ['2ki', '2KI'],\r\n ['2kings', '2KI'],\r\n ['2kgs', '2KI'],\r\n ['1ch', '1CH'],\r\n ['1chronicles', '1CH'],\r\n ['chronicles1', '1CH'],\r\n ['2ch', '2CH'],\r\n ['2chronicles', '2CH'],\r\n ['chronicles2', '2CH'],\r\n ['ezr', 'EZR'],\r\n ['ezra', 'EZR'],\r\n ['neh', 'NEH'],\r\n ['nehemiah', 'NEH'],\r\n ['est', 'EST'],\r\n ['ester', 'EST'],\r\n ['job', 'JOB'],\r\n ['ps', 'PSA'],\r\n ['psa', 'PSA'],\r\n ['psalms', 'PSA'],\r\n ['psalm', 'PSA'],\r\n ['pr', 'PRO'],\r\n ['pro', 'PRO'],\r\n ['proverbs', 'PRO'],\r\n ['ecc', 'ECC'],\r\n ['ecclesiastes', 'ECC'],\r\n ['eccl', 'ECC'],\r\n ['sng', 'SNG'],\r\n ['song', 'SNG'],\r\n ['songofsolomon', 'SNG'],\r\n ['isa', 'ISA'],\r\n ['isaiah', 'ISA'],\r\n ['jer', 'JER'],\r\n ['jeremiah', 'JER'],\r\n ['lam', 'LAM'],\r\n ['lamentations', 'LAM'],\r\n ['ezk', 'EZK'],\r\n ['ezekiel', 'EZK'],\r\n ['ezek', 'EZK'],\r\n ['dan', 'DAN'],\r\n ['daniel', 'DAN'],\r\n ['hos', 'HOS'],\r\n ['hosea', 'HOS'],\r\n ['jol', 'JOL'],\r\n ['joel', 'JOL'],\r\n ['amo', 'AMO'],\r\n ['amos', 'AMO'],\r\n ['oba', 'OBA'],\r\n ['obadiah', 'OBA'],\r\n ['jon', 'JON'],\r\n ['jonah', 'JON'],\r\n ['mic', 'MIC'],\r\n ['micah', 'MIC'],\r\n ['nam', 'NAM'],\r\n ['nahum', 'NAM'],\r\n ['nah', 'NAM'],\r\n ['hab', 'HAB'],\r\n ['habakkuk', 'HAB'],\r\n ['zep', 'ZEP'],\r\n ['zepaniah', 'ZEP'],\r\n ['hag', 'HAG'],\r\n ['haggai', 'HAG'],\r\n ['zec', 'ZEC'],\r\n ['zechariah', 'ZEC'],\r\n ['mal', 'MAL'],\r\n ['malachi', 'MAL'],\r\n ['mat', 'MAT'],\r\n ['matthew', 'MAT'],\r\n ['mrk', 'MRK'],\r\n ['mark', 'MRK'],\r\n ['luk', 'LUK'],\r\n ['luke', 'LUK'],\r\n ['jhn', 'JHN'],\r\n ['john', 'JHN'],\r\n ['act', 'ACT'],\r\n ['acts', 'ACT'],\r\n ['rom', 'ROM'],\r\n ['romans', 'ROM'],\r\n ['1co', '1CO'],\r\n ['1corinthians', '1CO'],\r\n ['2co', '2CO'],\r\n ['2corinthians', '2CO'],\r\n ['gal', 'GAL'],\r\n ['galatians', 'GAL'],\r\n ['eph', 'EPH'],\r\n ['ephesians', 'EPH'],\r\n ['php', 'PHP'],\r\n ['philippians', 'PHP'],\r\n ['phil', 'PHP'],\r\n ['col', 'COL'],\r\n ['colossians', 'COL'],\r\n ['1th', '1TH'],\r\n ['1thessalonians', '1TH'],\r\n ['2th', '2TH'],\r\n ['2thessalonians', '2TH'],\r\n ['1ti', '1TI'],\r\n ['1timothy', '1TI'],\r\n ['2ti', '2TI'],\r\n ['2timothy', '2TI'],\r\n ['tit', 'TIT'],\r\n ['titus', 'TIT'],\r\n ['phm', 'PHM'],\r\n ['philemon', 'PHM'],\r\n ['phlm', 'PHM'],\r\n ['heb', 'HEB'],\r\n ['hebrews', 'HEB'],\r\n ['jas', 'JAS'],\r\n ['james', 'JAS'],\r\n ['1pe', '1PE'],\r\n ['1peter', '1PE'],\r\n ['2pe', '2PE'],\r\n ['2peter', '2PE'],\r\n ['1jn', '1JN'],\r\n ['1john', '1JN'],\r\n ['2jn', '2JN'],\r\n ['2john', '2JN'],\r\n ['3jn', '3JN'],\r\n ['3john', '3JN'],\r\n ['jud', 'JUD'],\r\n ['jude', 'JUD'],\r\n ['rev', 'REV'],\r\n ['revelation', 'REV'],\r\n]);\r\n\r\n/**\r\n * Gets the ID of the given book.\r\n * Returns null if the ID could not be found.\r\n * @param book The name/ID of the book.\r\n */\r\nexport function getBookId(book: string): string | null {\r\n const bookLower = book.toLowerCase().replaceAll(/\\s+/g, '');\r\n\r\n const id = BOOK_ID_MAP.get(bookLower);\r\n if (id) {\r\n return id;\r\n }\r\n\r\n for (let [key, id] of BOOK_ID_MAP) {\r\n if (bookLower.startsWith(key)) {\r\n return id;\r\n }\r\n }\r\n\r\n return null;\r\n}\r\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIO,SAAS,kBAAkB,UAA0B;AACxD,SAAO;AACX;AAKA,MAAM,qBAA0C,oBAAI,IAAI;AAAA,EACpD,CAAC,WAAW,KAAK;AAAA,EACjB,CAAC,WAAW,QAAQ;AAAA,EACpB,CAAC,YAAY,SAAS;AAAA,EACtB,CAAC,WAAW,QAAQ;AAAA,EACpB,CAAC,WAAW,QAAQ;AACxB,CAAC;AAMM,SAAS,iBAAiB,eAA+B;AAC5D,SAAO,mBAAmB,IAAI,aAAa,KAAK;AACpD;AAEO,SAAS,oBAAoB,KAAyC;AACzE,SAAO,CAAC,OAAO,QAAQ,KAAK,GAAG;AACnC;A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,EAChB,CAAC,OAAO,KAAK;AAAA,EACb,CAAC,UAAU,KAAK;AAAA,EAChB,CAAC,OAAO,KAAK;AAAA,EACb,CAAC,SAAS,KAAK;AAAA,EACf,CAAC,OAAO,KAAK;AAAA,EACb,CAAC,SAAS,KAAK;AAAA,EACf,CAAC,OAAO,KAAK;AAAA,EACb,CAAC,SAAS,KAAK;AAAA,EACf,CAAC,OAAO,KAAK;AAAA,EACb,CAAC,QAAQ,KAAK;AAAA,EACd,CAAC,OAAO,KAAK;AAAA,EACb,CAAC,cAAc,KAAK;AACxB,CAAC;AAOM,SAAS,UAAU,MAA6B;AACnD,QAAM,YAAY,KAAK,YAAY,EAAE,WAAW,QAAQ,EAAE;AAE1D,QAAM,KAAK,YAAY,IAAI,SAAS;AACpC,MAAI,IAAI;AACJ,WAAO;AAAA,EACX;AAEA,WAAS,CAAC,KAAKA,GAAE,KAAK,aAAa;AAC/B,QAAI,UAAU,WAAW,GAAG,GAAG;AAC3B,aAAOA;AAAA,IACX;AAAA,EACJ;AAEA,SAAO;AACX;",
6
6
  "names": ["id"]
7
7
  }
@@ -14,6 +14,8 @@ export function generateApiForDataset(dataset, options = {}) {
14
14
  },
15
15
  commentaryBookChapters: [],
16
16
  commentaryBooks: [],
17
+ commentaryProfiles: [],
18
+ commentaryProfileContents: [],
17
19
  pathPrefix: apiPathPrefix
18
20
  };
19
21
  const getNativeName = options.getNativeName;
@@ -134,7 +136,7 @@ export function generateApiForDataset(dataset, options = {}) {
134
136
  api.availableTranslations.translations.push(apiTranslation);
135
137
  api.translationBooks.push(translationBooks);
136
138
  }
137
- for (let { books, ...commentary } of dataset.commentaries) {
139
+ for (let { books, profiles, ...commentary } of dataset.commentaries) {
138
140
  const apiCommentary = {
139
141
  ...commentary,
140
142
  availableFormats: ["json"],
@@ -142,9 +144,15 @@ export function generateApiForDataset(dataset, options = {}) {
142
144
  commentary.id,
143
145
  apiPathPrefix
144
146
  ),
147
+ listOfProfilesApiLink: profilesCommentaryApiLink(
148
+ commentary.id,
149
+ "json",
150
+ apiPathPrefix
151
+ ),
145
152
  numberOfBooks: books.length,
146
153
  totalNumberOfChapters: 0,
147
154
  totalNumberOfVerses: 0,
155
+ totalNumberOfProfiles: 0,
148
156
  languageName: getNativeName ? getNativeName(commentary.language) ?? void 0 : void 0,
149
157
  languageEnglishName: getEnglishName ? getEnglishName(commentary.language) ?? void 0 : void 0
150
158
  };
@@ -152,6 +160,10 @@ export function generateApiForDataset(dataset, options = {}) {
152
160
  commentary: apiCommentary,
153
161
  books: []
154
162
  };
163
+ const commentaryProfiles = {
164
+ commentary: apiCommentary,
165
+ profiles: []
166
+ };
155
167
  let commentaryChapters = [];
156
168
  for (let { chapters, ...book } of books) {
157
169
  const apiBook = {
@@ -202,6 +214,36 @@ export function generateApiForDataset(dataset, options = {}) {
202
214
  apiCommentary.totalNumberOfChapters += apiBook.numberOfChapters;
203
215
  apiCommentary.totalNumberOfVerses += apiBook.totalNumberOfVerses;
204
216
  }
217
+ if (profiles) {
218
+ for (let profile of profiles) {
219
+ const apiProfile = {
220
+ id: profile.id,
221
+ reference: profile.reference,
222
+ subject: profile.subject,
223
+ thisProfileLink: profileCommentaryApiLink(
224
+ commentary.id,
225
+ profile.id,
226
+ "json",
227
+ apiPathPrefix
228
+ ),
229
+ referenceChapterLink: profile.reference ? bookCommentaryChapterApiLink(
230
+ commentary.id,
231
+ profile.reference.book,
232
+ profile.reference.chapter,
233
+ "json",
234
+ apiPathPrefix
235
+ ) : null
236
+ };
237
+ const apiProfileContent = {
238
+ commentary: apiCommentary,
239
+ profile: apiProfile,
240
+ content: profile.content
241
+ };
242
+ apiCommentary.totalNumberOfProfiles += 1;
243
+ commentaryProfiles.profiles.push(apiProfile);
244
+ api.commentaryProfileContents.push(apiProfileContent);
245
+ }
246
+ }
205
247
  for (let i = 0; i < commentaryChapters.length; i++) {
206
248
  if (i > 0) {
207
249
  commentaryChapters[i].previousChapterApiLink = bookCommentaryChapterApiLink(
@@ -224,6 +266,7 @@ export function generateApiForDataset(dataset, options = {}) {
224
266
  }
225
267
  api.availableCommentaries.commentaries.push(apiCommentary);
226
268
  api.commentaryBooks.push(commentaryBooks);
269
+ api.commentaryProfiles.push(commentaryProfiles);
227
270
  }
228
271
  return api;
229
272
  function getBookLink(book) {
@@ -268,6 +311,19 @@ export function generateFilesForApi(api) {
268
311
  )
269
312
  );
270
313
  }
314
+ for (let commentaryProfiles of api.commentaryProfiles) {
315
+ files.push(
316
+ jsonFile(
317
+ commentaryProfiles.commentary.listOfProfilesApiLink,
318
+ commentaryProfiles
319
+ )
320
+ );
321
+ }
322
+ for (let profileContent of api.commentaryProfileContents) {
323
+ files.push(
324
+ jsonFile(profileContent.profile.thisProfileLink, profileContent)
325
+ );
326
+ }
271
327
  for (let bookChapter of api.commentaryBookChapters) {
272
328
  files.push(jsonFile(bookChapter.thisChapterLink, bookChapter));
273
329
  }
@@ -301,6 +357,14 @@ export function bookChapterAudioApiLink(translationId, bookId, chapterNumber, re
301
357
  bookId
302
358
  )}/${chapterNumber}.${reader}.mp3`;
303
359
  }
360
+ export function profilesCommentaryApiLink(translationId, extension, prefix = "") {
361
+ return `${prefix}/api/c/${translationId}/profiles.${extension}`;
362
+ }
363
+ export function profileCommentaryApiLink(translationId, profileId, extension, prefix = "") {
364
+ return `${prefix}/api/c/${translationId}/profiles/${replaceSpacesWithUnderscores(
365
+ profileId
366
+ )}.${extension}`;
367
+ }
304
368
  export function jsonFile(path, content, mergable) {
305
369
  return {
306
370
  path,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../generation/api.ts"],
4
- "sourcesContent": ["import {\r\n Commentary,\r\n CommentaryBook,\r\n CommentaryBookChapter,\r\n OutputFile,\r\n Translation,\r\n TranslationBook,\r\n TranslationBookChapter,\r\n TranslationBookChapterAudioLinks,\r\n} from './common-types.js';\r\nimport { DatasetOutput } from './dataset.js';\r\n\r\n/**\r\n * Defines the output of the API generation.\r\n */\r\nexport interface ApiOutput {\r\n /**\r\n * The list of available translations.\r\n * This maps to the /api/available-translations.json endpoint.\r\n */\r\n availableTranslations: ApiAvailableTranslations;\r\n\r\n /**\r\n * The list of books for each translation.\r\n * This maps to the /api/:translationId/books.json endpoint.\r\n */\r\n translationBooks: ApiTranslationBooks[];\r\n\r\n /**\r\n * The list of chapters for each book.\r\n * This maps to the following endpoints:\r\n * - /api/:translationId/:bookId/:chapterNumber.json\r\n * - /api/:translationId/:bookCommonName/:chapterNumber.json\r\n */\r\n translationBookChapters: ApiTranslationBookChapter[];\r\n\r\n /**\r\n * The list of audio files.\r\n * This maps to the following endpoints:\r\n * - /api/:translationId/:bookId/:chapterNumber.:reader.mp3\r\n */\r\n translationBookChapterAudio: ApiTranslationBookChapterAudio[];\r\n\r\n /**\r\n * The list of available commentaries.\r\n * This maps to the /api/available-commentaries.json endpoint.\r\n */\r\n availableCommentaries: ApiAvailableCommentaries;\r\n\r\n /**\r\n * The list of books for each commentary.\r\n * This maps to the /api/c/:commentaryId/books.json endpoint.\r\n */\r\n commentaryBooks: ApiCommentaryBooks[];\r\n\r\n /**\r\n * The list of chapters for each commentary book.\r\n * This maps to the following endpoint:\r\n * - /api/c/:commentaryId/:bookId/:chapterNumber.json\r\n */\r\n commentaryBookChapters: ApiCommentaryBookChapter[];\r\n\r\n /**\r\n * The path prefix that the API should use.\r\n */\r\n pathPrefix: string;\r\n}\r\n\r\n/**\r\n * The list of available translations.\r\n * Maps to the /api/available-translations.json endpoint.\r\n */\r\nexport interface ApiAvailableTranslations {\r\n /**\r\n * The list of translations.\r\n */\r\n translations: ApiTranslation[];\r\n}\r\n\r\n/**\r\n * The list of available commentaries.\r\n * Maps to the /api/available-commentaries.json endpoint.\r\n */\r\nexport interface ApiAvailableCommentaries {\r\n /**\r\n * The list of commentaries.\r\n */\r\n commentaries: ApiCommentary[];\r\n}\r\n\r\n/**\r\n * Defines a translation that is used in the API.\r\n */\r\nexport interface ApiTranslation extends Translation {\r\n /**\r\n * The API link for the list of available books for this translation.\r\n */\r\n listOfBooksApiLink: string;\r\n\r\n /**\r\n * The available list of formats.\r\n */\r\n availableFormats: ('json' | 'usfm')[];\r\n\r\n /**\r\n * The number of books that are contained in this translation.\r\n *\r\n * Complete translations should have the same number of books as the Bible (66).\r\n */\r\n numberOfBooks: number;\r\n\r\n /**\r\n * The total number of chapters that are contained in this translation.\r\n *\r\n * Complete translations should have the same number of chapters as the Bible (1,189).\r\n */\r\n totalNumberOfChapters: number;\r\n\r\n /**\r\n * The total number of verses that are contained in this translation.\r\n *\r\n * Complete translations should have the same number of verses as the Bible (around 31,102 - some translations exclude verses based on the aparent likelyhood of existing in the original source texts).\r\n */\r\n totalNumberOfVerses: number;\r\n\r\n /**\r\n * Gets the name of the language that the translation is in.\r\n * Null or undefined if the name of the language is not known.\r\n */\r\n languageName?: string;\r\n\r\n /**\r\n * Gets the name of the language in English.\r\n * Null or undefined if the language doesn't have an english name.\r\n */\r\n languageEnglishName?: string;\r\n}\r\n\r\n/**\r\n * Defines a commentary that is used in the API.\r\n */\r\nexport interface ApiCommentary extends Commentary {\r\n /**\r\n * The API link for the list of available books for this translation.\r\n */\r\n listOfBooksApiLink: string;\r\n\r\n /**\r\n * The available list of formats.\r\n */\r\n availableFormats: ('json' | 'usfm')[];\r\n\r\n /**\r\n * The number of books that are contained in this commentary.\r\n *\r\n * Complete commentaries should have the same number of books as the Bible (66).\r\n */\r\n numberOfBooks: number;\r\n\r\n /**\r\n * The total number of chapters that are contained in this translation.\r\n *\r\n * Complete commentaries should have the same number of chapters as the Bible (1,189).\r\n */\r\n totalNumberOfChapters: number;\r\n\r\n /**\r\n * The total number of verses that are contained in this commentary.\r\n *\r\n * Complete commentaries should have the same number of verses as the Bible (around 31,102 - some commentaries exclude verses based on the aparent likelyhood of existing in the original source texts).\r\n */\r\n totalNumberOfVerses: number;\r\n\r\n /**\r\n * Gets the name of the language that the commentary is in.\r\n * Null or undefined if the name of the language is not known.\r\n */\r\n languageName?: string;\r\n\r\n /**\r\n * Gets the name of the language in English.\r\n * Null or undefined if the language doesn't have an english name.\r\n */\r\n languageEnglishName?: string;\r\n}\r\n\r\n/**\r\n * Defines an interface that contains information about the books that are available for a translation.\r\n */\r\nexport interface ApiTranslationBooks {\r\n /**\r\n * The translation information for the books.\r\n */\r\n translation: ApiTranslation;\r\n\r\n /**\r\n * The list of books that are available for the translation.\r\n */\r\n books: ApiTranslationBook[];\r\n}\r\n\r\n/**\r\n * Defines an interface that contains information about the books that are available for a commentary.\r\n */\r\nexport interface ApiCommentaryBooks {\r\n /**\r\n * The commentary information for the books.\r\n */\r\n commentary: ApiCommentary;\r\n\r\n /**\r\n * The list of books that are available for the commentary.\r\n */\r\n books: ApiCommentaryBook[];\r\n}\r\n\r\n/**\r\n * Defines a translation book that is used in the API.\r\n */\r\nexport interface ApiTranslationBook extends TranslationBook {\r\n /**\r\n * The link to the first chapter of the book.\r\n */\r\n firstChapterApiLink: string;\r\n\r\n /**\r\n * The link to the last chapter of the book.\r\n */\r\n lastChapterApiLink: string;\r\n\r\n /**\r\n * The number of chapters that the book contains.\r\n */\r\n numberOfChapters: number;\r\n\r\n /**\r\n * The number of verses that the book contains.\r\n */\r\n totalNumberOfVerses: number;\r\n}\r\n\r\n/**\r\n * Defines a commentary book that is used in the API.\r\n */\r\nexport interface ApiCommentaryBook extends CommentaryBook {\r\n /**\r\n * The link to the first chapter of the book.\r\n */\r\n firstChapterApiLink: string;\r\n\r\n /**\r\n * The link to the last chapter of the book.\r\n */\r\n lastChapterApiLink: string;\r\n\r\n /**\r\n * The number of chapters that the book contains.\r\n */\r\n numberOfChapters: number;\r\n\r\n /**\r\n * The number of verses that the book contains.\r\n */\r\n totalNumberOfVerses: number;\r\n}\r\n\r\n/**\r\n * Defines an interface that contains information about a book chapter.\r\n */\r\nexport interface ApiTranslationBookChapter extends TranslationBookChapter {\r\n /**\r\n * The translation information for the book chapter.\r\n */\r\n translation: ApiTranslation;\r\n\r\n /**\r\n * The book information for the book chapter.\r\n */\r\n book: ApiTranslationBook;\r\n\r\n /**\r\n * The link to this chapter.\r\n */\r\n thisChapterLink: string;\r\n\r\n /**\r\n * The link to the next chapter.\r\n * Null if this is the last chapter in the translation.\r\n */\r\n nextChapterApiLink: string | null;\r\n\r\n /**\r\n * The links to the audio versions for the next chapter.\r\n * Null if this is the last chapter in the translation.\r\n */\r\n nextChapterAudioLinks: TranslationBookChapterAudioLinks | null;\r\n\r\n /**\r\n * The link to the previous chapter.\r\n * Null if this is the first chapter in the translation.\r\n */\r\n previousChapterApiLink: string | null;\r\n\r\n /**\r\n * The links to the audio versions for the previous chapter.\r\n * Null if this is the first chapter in the translation.\r\n */\r\n previousChapterAudioLinks: TranslationBookChapterAudioLinks | null;\r\n\r\n /**\r\n * The number of verses that the chapter contains.\r\n */\r\n numberOfVerses: number;\r\n}\r\n\r\n/**\r\n * Defines an interface that contains information about a book chapter.\r\n */\r\nexport interface ApiCommentaryBookChapter extends CommentaryBookChapter {\r\n /**\r\n * The commentary information for the book chapter.\r\n */\r\n commentary: ApiCommentary;\r\n\r\n /**\r\n * The book information for the book chapter.\r\n */\r\n book: ApiCommentaryBook;\r\n\r\n /**\r\n * The link to this chapter.\r\n */\r\n thisChapterLink: string;\r\n\r\n /**\r\n * The link to the next chapter.\r\n * Null if this is the last chapter in the translation.\r\n */\r\n nextChapterApiLink: string | null;\r\n\r\n /**\r\n * The link to the previous chapter.\r\n * Null if this is the first chapter in the translation.\r\n */\r\n previousChapterApiLink: string | null;\r\n\r\n /**\r\n * The number of verses that the chapter contains.\r\n */\r\n numberOfVerses: number;\r\n}\r\n\r\nexport interface ApiTranslationBookChapterAudio {\r\n /**\r\n * The chapter that the audio is for.\r\n */\r\n chapter: ApiTranslationBookChapter;\r\n\r\n /**\r\n * The link that the audio should be placed at.\r\n */\r\n link: string;\r\n\r\n /**\r\n * The original URL of the audio.\r\n */\r\n originalUrl: string;\r\n}\r\n\r\n/**\r\n * The options for generating the API.\r\n */\r\nexport interface GenerateApiOptions {\r\n /**\r\n * Whether to use the common name for the book chapter API link. If false, then book IDs are used.\r\n * Audio URLs will always use the book ID.\r\n * Defaults to false.\r\n */\r\n useCommonName?: boolean;\r\n\r\n /**\r\n * Whether to replace the audio URLs in the dataset with ones that are hosted locally.\r\n * If true, then the audio URLs in the dataset will be replaced with ones that reference files hosted by the API itself.\r\n * If false, then the audio URLs in the dataset will be left as is.\r\n * Defaults to false.\r\n */\r\n generateAudioFiles?: boolean;\r\n\r\n /**\r\n * Gets the english name of the given language.\r\n * If not provided, then the english name for the language will be unknown and omitted.\r\n * @param language The language to get the english name for.\r\n */\r\n getEnglishName?: (language: string) => string | null | undefined;\r\n\r\n /**\r\n * Gets the native name of the given language.\r\n * If not provided, then the native name for the language will be unknown and omitted.\r\n * @param language The language to get the native name for.\r\n */\r\n getNativeName?: (language: string) => string | null | undefined;\r\n\r\n /**\r\n * The prefix that should be added to paths that are generated.\r\n */\r\n pathPrefix?: string;\r\n}\r\n\r\n/**\r\n * Generates the API output for the given dataset.\r\n * @param dataset The dataset to generate the API for.\r\n * @param options The options for generating the API.\r\n */\r\nexport function generateApiForDataset(\r\n dataset: DatasetOutput,\r\n options: GenerateApiOptions = {}\r\n): ApiOutput {\r\n const { useCommonName, pathPrefix } = options;\r\n const apiPathPrefix = pathPrefix ? pathPrefix : '';\r\n let api: ApiOutput = {\r\n availableTranslations: {\r\n translations: [],\r\n },\r\n translationBooks: [],\r\n translationBookChapters: [],\r\n translationBookChapterAudio: [],\r\n availableCommentaries: {\r\n commentaries: [],\r\n },\r\n commentaryBookChapters: [],\r\n commentaryBooks: [],\r\n pathPrefix: apiPathPrefix,\r\n };\r\n\r\n const getNativeName = options.getNativeName;\r\n const getEnglishName = options.getEnglishName;\r\n\r\n for (let { books, ...translation } of dataset.translations) {\r\n const apiTranslation: ApiTranslation = {\r\n ...translation,\r\n availableFormats: ['json'],\r\n listOfBooksApiLink: listOfBooksApiLink(\r\n translation.id,\r\n apiPathPrefix\r\n ),\r\n numberOfBooks: books.length,\r\n totalNumberOfChapters: 0,\r\n totalNumberOfVerses: 0,\r\n languageName: getNativeName\r\n ? getNativeName(translation.language) ?? undefined\r\n : undefined,\r\n languageEnglishName: getEnglishName\r\n ? getEnglishName(translation.language) ?? undefined\r\n : undefined,\r\n };\r\n\r\n const translationBooks: ApiTranslationBooks = {\r\n translation: apiTranslation,\r\n books: [],\r\n };\r\n\r\n let translationChapters: ApiTranslationBookChapter[] = [];\r\n\r\n for (let { chapters, ...book } of books) {\r\n const apiBook: ApiTranslationBook = {\r\n ...book,\r\n firstChapterApiLink: bookChapterApiLink(\r\n translation.id,\r\n getBookLink(book),\r\n 1,\r\n 'json',\r\n apiPathPrefix\r\n ),\r\n lastChapterApiLink: bookChapterApiLink(\r\n translation.id,\r\n getBookLink(book),\r\n chapters.length,\r\n 'json',\r\n apiPathPrefix\r\n ),\r\n numberOfChapters: chapters.length,\r\n totalNumberOfVerses: 0,\r\n };\r\n\r\n for (let { chapter, thisChapterAudioLinks } of chapters) {\r\n const audio: TranslationBookChapterAudioLinks = {};\r\n const apiBookChapter: ApiTranslationBookChapter = {\r\n translation: apiTranslation,\r\n book: apiBook,\r\n chapter: chapter,\r\n thisChapterLink: bookChapterApiLink(\r\n translation.id,\r\n getBookLink(book),\r\n chapter.number,\r\n 'json',\r\n apiPathPrefix\r\n ),\r\n thisChapterAudioLinks: audio,\r\n nextChapterApiLink: null,\r\n nextChapterAudioLinks: null,\r\n previousChapterApiLink: null,\r\n previousChapterAudioLinks: null,\r\n numberOfVerses: 0,\r\n };\r\n\r\n for (let reader in thisChapterAudioLinks) {\r\n if (options.generateAudioFiles) {\r\n const apiAudio: ApiTranslationBookChapterAudio = {\r\n chapter: apiBookChapter,\r\n link: bookChapterAudioApiLink(\r\n translation.id,\r\n getBookLink(book),\r\n chapter.number,\r\n reader,\r\n apiPathPrefix\r\n ),\r\n originalUrl: thisChapterAudioLinks[reader],\r\n };\r\n audio[reader] = apiAudio.link;\r\n api.translationBookChapterAudio.push(apiAudio);\r\n } else {\r\n audio[reader] = thisChapterAudioLinks[reader];\r\n }\r\n }\r\n\r\n for (let c of chapter.content) {\r\n if (c.type === 'verse') {\r\n apiBookChapter.numberOfVerses++;\r\n }\r\n }\r\n\r\n apiBook.totalNumberOfVerses += apiBookChapter.numberOfVerses;\r\n\r\n translationChapters.push(apiBookChapter);\r\n api.translationBookChapters.push(apiBookChapter);\r\n }\r\n\r\n translationBooks.books.push(apiBook);\r\n\r\n apiTranslation.totalNumberOfChapters += apiBook.numberOfChapters;\r\n apiTranslation.totalNumberOfVerses += apiBook.totalNumberOfVerses;\r\n }\r\n\r\n for (let i = 0; i < translationChapters.length; i++) {\r\n if (i > 0) {\r\n translationChapters[i].previousChapterApiLink =\r\n bookChapterApiLink(\r\n translation.id,\r\n getBookLink(translationChapters[i - 1].book),\r\n translationChapters[i - 1].chapter.number,\r\n 'json',\r\n apiPathPrefix\r\n );\r\n translationChapters[i].previousChapterAudioLinks =\r\n translationChapters[i - 1].thisChapterAudioLinks;\r\n }\r\n\r\n if (i < translationChapters.length - 1) {\r\n translationChapters[i].nextChapterApiLink = bookChapterApiLink(\r\n translation.id,\r\n getBookLink(translationChapters[i + 1].book),\r\n translationChapters[i + 1].chapter.number,\r\n 'json',\r\n apiPathPrefix\r\n );\r\n translationChapters[i].nextChapterAudioLinks =\r\n translationChapters[i + 1].thisChapterAudioLinks;\r\n }\r\n }\r\n\r\n api.availableTranslations.translations.push(apiTranslation);\r\n api.translationBooks.push(translationBooks);\r\n }\r\n\r\n for (let { books, ...commentary } of dataset.commentaries) {\r\n const apiCommentary: ApiCommentary = {\r\n ...commentary,\r\n availableFormats: ['json'],\r\n listOfBooksApiLink: listOfCommentaryBooksApiLink(\r\n commentary.id,\r\n apiPathPrefix\r\n ),\r\n numberOfBooks: books.length,\r\n totalNumberOfChapters: 0,\r\n totalNumberOfVerses: 0,\r\n languageName: getNativeName\r\n ? getNativeName(commentary.language) ?? undefined\r\n : undefined,\r\n languageEnglishName: getEnglishName\r\n ? getEnglishName(commentary.language) ?? undefined\r\n : undefined,\r\n };\r\n\r\n const commentaryBooks: ApiCommentaryBooks = {\r\n commentary: apiCommentary,\r\n books: [],\r\n };\r\n\r\n let commentaryChapters: ApiCommentaryBookChapter[] = [];\r\n\r\n for (let { chapters, ...book } of books) {\r\n const apiBook: ApiCommentaryBook = {\r\n ...book,\r\n firstChapterApiLink: bookCommentaryChapterApiLink(\r\n commentary.id,\r\n getBookLink(book),\r\n 1,\r\n 'json',\r\n apiPathPrefix\r\n ),\r\n lastChapterApiLink: bookCommentaryChapterApiLink(\r\n commentary.id,\r\n getBookLink(book),\r\n chapters.length,\r\n 'json',\r\n apiPathPrefix\r\n ),\r\n numberOfChapters: chapters.length,\r\n totalNumberOfVerses: 0,\r\n };\r\n\r\n for (let { chapter } of chapters) {\r\n const apiBookChapter: ApiCommentaryBookChapter = {\r\n commentary: apiCommentary,\r\n book: apiBook,\r\n chapter: chapter,\r\n thisChapterLink: bookCommentaryChapterApiLink(\r\n commentary.id,\r\n getBookLink(book),\r\n chapter.number,\r\n 'json',\r\n apiPathPrefix\r\n ),\r\n nextChapterApiLink: null,\r\n previousChapterApiLink: null,\r\n numberOfVerses: 0,\r\n };\r\n\r\n for (let c of chapter.content) {\r\n if (c.type === 'verse') {\r\n apiBookChapter.numberOfVerses++;\r\n }\r\n }\r\n\r\n apiBook.totalNumberOfVerses += apiBookChapter.numberOfVerses;\r\n\r\n commentaryChapters.push(apiBookChapter);\r\n api.commentaryBookChapters.push(apiBookChapter);\r\n }\r\n\r\n commentaryBooks.books.push(apiBook);\r\n\r\n apiCommentary.totalNumberOfChapters += apiBook.numberOfChapters;\r\n apiCommentary.totalNumberOfVerses += apiBook.totalNumberOfVerses;\r\n }\r\n\r\n for (let i = 0; i < commentaryChapters.length; i++) {\r\n if (i > 0) {\r\n commentaryChapters[i].previousChapterApiLink =\r\n bookCommentaryChapterApiLink(\r\n commentary.id,\r\n getBookLink(commentaryChapters[i - 1].book),\r\n commentaryChapters[i - 1].chapter.number,\r\n 'json',\r\n apiPathPrefix\r\n );\r\n // commentaryChapters[i].previousChapterAudioLinks =\r\n // commentaryChapters[i - 1].thisChapterAudioLinks;\r\n }\r\n\r\n if (i < commentaryChapters.length - 1) {\r\n commentaryChapters[i].nextChapterApiLink =\r\n bookCommentaryChapterApiLink(\r\n commentary.id,\r\n getBookLink(commentaryChapters[i + 1].book),\r\n commentaryChapters[i + 1].chapter.number,\r\n 'json',\r\n apiPathPrefix\r\n );\r\n // commentaryChapters[i].nextChapterAudioLinks =\r\n // commentaryChapters[i + 1].thisChapterAudioLinks;\r\n }\r\n }\r\n\r\n api.availableCommentaries.commentaries.push(apiCommentary);\r\n api.commentaryBooks.push(commentaryBooks);\r\n }\r\n\r\n return api;\r\n\r\n function getBookLink(book: TranslationBook | CommentaryBook): string {\r\n return useCommonName ? book.commonName : book.id;\r\n }\r\n}\r\n\r\n/**\r\n * Generates the output files for the given API.\r\n * @param api The API that the files should be generated for.\r\n */\r\nexport function generateFilesForApi(api: ApiOutput): OutputFile[] {\r\n let files: OutputFile[] = [];\r\n\r\n files.push(\r\n jsonFile(\r\n `${api.pathPrefix}/api/available_translations.json`,\r\n api.availableTranslations,\r\n true\r\n )\r\n );\r\n for (let translationBooks of api.translationBooks) {\r\n files.push(\r\n jsonFile(\r\n translationBooks.translation.listOfBooksApiLink,\r\n translationBooks\r\n )\r\n );\r\n }\r\n\r\n for (let bookChapter of api.translationBookChapters) {\r\n files.push(jsonFile(bookChapter.thisChapterLink, bookChapter));\r\n }\r\n\r\n for (let audio of api.translationBookChapterAudio) {\r\n files.push(downloadedFile(audio.link, audio.originalUrl));\r\n }\r\n\r\n files.push(\r\n jsonFile(\r\n `${api.pathPrefix}/api/available_commentaries.json`,\r\n api.availableCommentaries,\r\n true\r\n )\r\n );\r\n for (let commentaryBooks of api.commentaryBooks) {\r\n files.push(\r\n jsonFile(\r\n commentaryBooks.commentary.listOfBooksApiLink,\r\n commentaryBooks\r\n )\r\n );\r\n }\r\n\r\n for (let bookChapter of api.commentaryBookChapters) {\r\n files.push(jsonFile(bookChapter.thisChapterLink, bookChapter));\r\n }\r\n\r\n // for (let audio of api.translationBookChapterAudio) {\r\n // files.push(downloadedFile(audio.link, audio.originalUrl));\r\n // }\r\n\r\n return files;\r\n}\r\n\r\n/**\r\n * Generates the output files for the given datasets.\r\n * @param datasets The datasets to generate the output files for.\r\n * @param options The options for generating the API files.\r\n */\r\nexport async function* generateOutputFilesFromDatasets(\r\n datasets: AsyncIterable<DatasetOutput>,\r\n options?: GenerateApiOptions\r\n): AsyncGenerator<OutputFile[]> {\r\n for await (let dataset of datasets) {\r\n const api = generateApiForDataset(dataset, options);\r\n const files = generateFilesForApi(api);\r\n\r\n yield files;\r\n }\r\n}\r\n\r\n/**\r\n * Gets the API Link for the list of books endpoint for a translation.\r\n * @param translationId The ID of the translation.\r\n * @returns\r\n */\r\nexport function listOfBooksApiLink(\r\n translationId: string,\r\n prefix: string = ''\r\n): string {\r\n return `${prefix}/api/${translationId}/books.json`;\r\n}\r\n\r\n/**\r\n * Gets the API Link for the list of books endpoint for a commentary.\r\n * @param commentaryId The ID of the commentary.\r\n * @returns\r\n */\r\nexport function listOfCommentaryBooksApiLink(\r\n commentaryId: string,\r\n prefix: string = ''\r\n): string {\r\n return `${prefix}/api/c/${commentaryId}/books.json`;\r\n}\r\n\r\n/**\r\n * Getes the API link for a book chapter.\r\n * @param translationId The ID of the translation.\r\n * @param commonName The name of the book.\r\n * @param chapterNumber The number of the book.\r\n * @param extension The extension of the file.\r\n */\r\nexport function bookChapterApiLink(\r\n translationId: string,\r\n commonName: string,\r\n chapterNumber: number,\r\n extension: string,\r\n prefix: string = ''\r\n) {\r\n return `${prefix}/api/${translationId}/${replaceSpacesWithUnderscores(\r\n commonName\r\n )}/${chapterNumber}.${extension}`;\r\n}\r\n\r\n/**\r\n * Getes the API link for a book chapter.\r\n * @param translationId The ID of the translation.\r\n * @param commonName The name of the book.\r\n * @param chapterNumber The number of the book.\r\n * @param extension The extension of the file.\r\n */\r\nexport function bookCommentaryChapterApiLink(\r\n translationId: string,\r\n commonName: string,\r\n chapterNumber: number,\r\n extension: string,\r\n prefix: string = ''\r\n) {\r\n return `${prefix}/api/c/${translationId}/${replaceSpacesWithUnderscores(\r\n commonName\r\n )}/${chapterNumber}.${extension}`;\r\n}\r\n\r\nexport function bookChapterAudioApiLink(\r\n translationId: string,\r\n bookId: string,\r\n chapterNumber: number,\r\n reader: string,\r\n prefix: string = ''\r\n) {\r\n return `${prefix}/api/${translationId}/${replaceSpacesWithUnderscores(\r\n bookId\r\n )}/${chapterNumber}.${reader}.mp3`;\r\n}\r\n\r\nexport function jsonFile(\r\n path: string,\r\n content: any,\r\n mergable?: boolean\r\n): OutputFile {\r\n return {\r\n path,\r\n content,\r\n mergable,\r\n };\r\n}\r\n\r\nexport function downloadedFile(path: string, url: string): OutputFile {\r\n return {\r\n path,\r\n content: () => fetch(url).then((response) => response.body),\r\n };\r\n}\r\n\r\nexport function replaceSpacesWithUnderscores(str: string): string {\r\n return str.replace(/[<>:\"/\\\\|?*\\s]/g, '_');\r\n}\r\n"],
5
- "mappings": ";AA6ZO,gBAAS,sBACZ,SACA,UAA8B,CAAC,GACtB;AACT,QAAM,EAAE,eAAe,WAAW,IAAI;AACtC,QAAM,gBAAgB,aAAa,aAAa;AAChD,MAAI,MAAiB;AAAA,IACjB,uBAAuB;AAAA,MACnB,cAAc,CAAC;AAAA,IACnB;AAAA,IACA,kBAAkB,CAAC;AAAA,IACnB,yBAAyB,CAAC;AAAA,IAC1B,6BAA6B,CAAC;AAAA,IAC9B,uBAAuB;AAAA,MACnB,cAAc,CAAC;AAAA,IACnB;AAAA,IACA,wBAAwB,CAAC;AAAA,IACzB,iBAAiB,CAAC;AAAA,IAClB,YAAY;AAAA,EAChB;AAEA,QAAM,gBAAgB,QAAQ;AAC9B,QAAM,iBAAiB,QAAQ;AAE/B,WAAS,EAAE,OAAO,GAAG,YAAY,KAAK,QAAQ,cAAc;AAC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AC,IAAI,aAAa,IAAI,SAAS;AACnC;AAEO,gBAAS,wBACZ,eACA,QACA,eACA,QACA,SAAiB,IACnB;AACE,SAAO,GAAG,MAAM,QAAQ,aAAa,IAAI;AAAA,IACrC;AAAA,EACJ,CAAC,IAAI,aAAa,IAAI,MAAM;AAChC;AAEO,gBAAS,SACZ,MACA,SACA,UACU;AACV,SAAO;AAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,EACJ;AACJ;AAEO,gBAAS,eAAe,MAAc,KAAyB;AAClE,SAAO;AAAA,IACH;AAAA,IACA,SAAS,MAAM,MAAM,GAAG,EAAE,KAAK,CAAC,aAAa,SAAS,IAAI;AAAA,EAC9D;AACJ;AAEO,gBAAS,6BAA6B,KAAqB;AAC9D,SAAO,IAAI,QAAQ,mBAAmB,GAAG;AAC7C;",
4
+ "sourcesContent": ["import {\r\n Commentary,\r\n CommentaryBook,\r\n CommentaryBookChapter,\r\n CommentaryProfile,\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 path prefix that the API should use.\r\n */\r\n pathPrefix: string;\r\n}\r\n\r\n/**\r\n * The list of available translations.\r\n * Maps to the /api/available-translations.json endpoint.\r\n */\r\nexport interface ApiAvailableTranslations {\r\n /**\r\n * The list of translations.\r\n */\r\n translations: ApiTranslation[];\r\n}\r\n\r\n/**\r\n * The list of available commentaries.\r\n * Maps to the /api/available-commentaries.json endpoint.\r\n */\r\nexport interface ApiAvailableCommentaries {\r\n /**\r\n * The list of commentaries.\r\n */\r\n commentaries: ApiCommentary[];\r\n}\r\n\r\n/**\r\n * Defines a translation that is used in the API.\r\n */\r\nexport interface ApiTranslation extends Translation {\r\n /**\r\n * The API link for the list of available books for this translation.\r\n */\r\n listOfBooksApiLink: string;\r\n\r\n /**\r\n * The available list of formats.\r\n */\r\n availableFormats: ('json' | 'usfm')[];\r\n\r\n /**\r\n * The number of books that are contained in this translation.\r\n *\r\n * Complete translations should have the same number of books as the Bible (66).\r\n */\r\n numberOfBooks: number;\r\n\r\n /**\r\n * The total number of chapters that are contained in this translation.\r\n *\r\n * Complete translations should have the same number of chapters as the Bible (1,189).\r\n */\r\n totalNumberOfChapters: number;\r\n\r\n /**\r\n * The total number of verses that are contained in this translation.\r\n *\r\n * Complete translations should have the same number of verses as the Bible (around 31,102 - some translations exclude verses based on the aparent likelyhood of existing in the original source texts).\r\n */\r\n totalNumberOfVerses: number;\r\n\r\n /**\r\n * Gets the name of the language that the translation is in.\r\n * Null or undefined if the name of the language is not known.\r\n */\r\n languageName?: string;\r\n\r\n /**\r\n * Gets the name of the language in English.\r\n * Null or undefined if the language doesn't have an english name.\r\n */\r\n languageEnglishName?: string;\r\n}\r\n\r\n/**\r\n * Defines a commentary that is used in the API.\r\n */\r\nexport interface ApiCommentary extends Commentary {\r\n /**\r\n * The API link for the list of available books for this translation.\r\n */\r\n listOfBooksApiLink: string;\r\n\r\n /**\r\n * The 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 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 link to the first chapter of the book.\r\n */\r\n firstChapterApiLink: string;\r\n\r\n /**\r\n * The link to the last chapter of the book.\r\n */\r\n lastChapterApiLink: string;\r\n\r\n /**\r\n * The number of chapters that the book contains.\r\n */\r\n numberOfChapters: number;\r\n\r\n /**\r\n * The number of verses that the book contains.\r\n */\r\n totalNumberOfVerses: number;\r\n}\r\n\r\n/**\r\n * Defines a commentary book that is used in the API.\r\n */\r\nexport interface ApiCommentaryBook extends CommentaryBook {\r\n /**\r\n * The link to the first chapter of the book.\r\n */\r\n firstChapterApiLink: string;\r\n\r\n /**\r\n * The link to the last chapter of the book.\r\n */\r\n lastChapterApiLink: string;\r\n\r\n /**\r\n * The number of chapters that the book contains.\r\n */\r\n numberOfChapters: number;\r\n\r\n /**\r\n * The number of verses that the book contains.\r\n */\r\n totalNumberOfVerses: number;\r\n}\r\n\r\n/**\r\n * Defines an interface that contains information about a book chapter.\r\n */\r\nexport interface ApiTranslationBookChapter extends TranslationBookChapter {\r\n /**\r\n * The translation information for the book chapter.\r\n */\r\n translation: ApiTranslation;\r\n\r\n /**\r\n * The book information for the book chapter.\r\n */\r\n book: ApiTranslationBook;\r\n\r\n /**\r\n * The link to this chapter.\r\n */\r\n thisChapterLink: string;\r\n\r\n /**\r\n * The link to the next chapter.\r\n * Null if this is the last chapter in the translation.\r\n */\r\n nextChapterApiLink: string | null;\r\n\r\n /**\r\n * The links to the audio versions for the next chapter.\r\n * Null if this is the last chapter in the translation.\r\n */\r\n nextChapterAudioLinks: TranslationBookChapterAudioLinks | null;\r\n\r\n /**\r\n * The link to the previous chapter.\r\n * Null if this is the first chapter in the translation.\r\n */\r\n previousChapterApiLink: string | null;\r\n\r\n /**\r\n * The links to the audio versions for the previous chapter.\r\n * Null if this is the first chapter in the translation.\r\n */\r\n previousChapterAudioLinks: TranslationBookChapterAudioLinks | null;\r\n\r\n /**\r\n * The number of verses that the chapter contains.\r\n */\r\n numberOfVerses: number;\r\n}\r\n\r\n/**\r\n * Defines an interface that contains information about a book chapter.\r\n */\r\nexport interface ApiCommentaryBookChapter extends CommentaryBookChapter {\r\n /**\r\n * The commentary information for the book chapter.\r\n */\r\n commentary: ApiCommentary;\r\n\r\n /**\r\n * The book information for the book chapter.\r\n */\r\n book: ApiCommentaryBook;\r\n\r\n /**\r\n * The link to this chapter.\r\n */\r\n thisChapterLink: string;\r\n\r\n /**\r\n * The link to the next chapter.\r\n * Null if this is the last chapter in the translation.\r\n */\r\n nextChapterApiLink: string | null;\r\n\r\n /**\r\n * The link to the previous chapter.\r\n * Null if this is the first chapter in the translation.\r\n */\r\n previousChapterApiLink: string | null;\r\n\r\n /**\r\n * The number of verses that the chapter contains.\r\n */\r\n numberOfVerses: number;\r\n}\r\n\r\nexport interface ApiTranslationBookChapterAudio {\r\n /**\r\n * The chapter that the audio is for.\r\n */\r\n chapter: ApiTranslationBookChapter;\r\n\r\n /**\r\n * The link that the audio should be placed at.\r\n */\r\n link: string;\r\n\r\n /**\r\n * The original URL of the audio.\r\n */\r\n originalUrl: string;\r\n}\r\n\r\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/**\r\n * Generates the API output for the given dataset.\r\n * @param dataset The dataset to generate the API for.\r\n * @param options The options for generating the API.\r\n */\r\nexport function generateApiForDataset(\r\n dataset: DatasetOutput,\r\n options: GenerateApiOptions = {}\r\n): ApiOutput {\r\n const { useCommonName, pathPrefix } = options;\r\n const apiPathPrefix = pathPrefix ? pathPrefix : '';\r\n let api: ApiOutput = {\r\n availableTranslations: {\r\n translations: [],\r\n },\r\n translationBooks: [],\r\n translationBookChapters: [],\r\n translationBookChapterAudio: [],\r\n availableCommentaries: {\r\n commentaries: [],\r\n },\r\n commentaryBookChapters: [],\r\n commentaryBooks: [],\r\n 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 const apiTranslation: ApiTranslation = {\r\n ...translation,\r\n availableFormats: ['json'],\r\n listOfBooksApiLink: listOfBooksApiLink(\r\n translation.id,\r\n apiPathPrefix\r\n ),\r\n numberOfBooks: books.length,\r\n totalNumberOfChapters: 0,\r\n totalNumberOfVerses: 0,\r\n languageName: getNativeName\r\n ? (getNativeName(translation.language) ?? undefined)\r\n : undefined,\r\n languageEnglishName: getEnglishName\r\n ? (getEnglishName(translation.language) ?? undefined)\r\n : undefined,\r\n };\r\n\r\n const translationBooks: ApiTranslationBooks = {\r\n translation: apiTranslation,\r\n books: [],\r\n };\r\n\r\n let translationChapters: ApiTranslationBookChapter[] = [];\r\n\r\n for (let { chapters, ...book } of books) {\r\n const apiBook: ApiTranslationBook = {\r\n ...book,\r\n firstChapterApiLink: bookChapterApiLink(\r\n translation.id,\r\n getBookLink(book),\r\n 1,\r\n 'json',\r\n apiPathPrefix\r\n ),\r\n lastChapterApiLink: bookChapterApiLink(\r\n translation.id,\r\n getBookLink(book),\r\n chapters.length,\r\n 'json',\r\n apiPathPrefix\r\n ),\r\n numberOfChapters: chapters.length,\r\n totalNumberOfVerses: 0,\r\n };\r\n\r\n for (let { chapter, thisChapterAudioLinks } of chapters) {\r\n const audio: TranslationBookChapterAudioLinks = {};\r\n const apiBookChapter: ApiTranslationBookChapter = {\r\n translation: apiTranslation,\r\n book: apiBook,\r\n chapter: chapter,\r\n thisChapterLink: bookChapterApiLink(\r\n translation.id,\r\n getBookLink(book),\r\n chapter.number,\r\n 'json',\r\n apiPathPrefix\r\n ),\r\n thisChapterAudioLinks: audio,\r\n nextChapterApiLink: null,\r\n nextChapterAudioLinks: null,\r\n previousChapterApiLink: null,\r\n previousChapterAudioLinks: null,\r\n numberOfVerses: 0,\r\n };\r\n\r\n for (let reader in thisChapterAudioLinks) {\r\n if (options.generateAudioFiles) {\r\n const apiAudio: ApiTranslationBookChapterAudio = {\r\n chapter: apiBookChapter,\r\n link: bookChapterAudioApiLink(\r\n translation.id,\r\n getBookLink(book),\r\n chapter.number,\r\n reader,\r\n apiPathPrefix\r\n ),\r\n originalUrl: thisChapterAudioLinks[reader],\r\n };\r\n audio[reader] = apiAudio.link;\r\n api.translationBookChapterAudio.push(apiAudio);\r\n } else {\r\n audio[reader] = thisChapterAudioLinks[reader];\r\n }\r\n }\r\n\r\n for (let c of chapter.content) {\r\n if (c.type === 'verse') {\r\n apiBookChapter.numberOfVerses++;\r\n }\r\n }\r\n\r\n apiBook.totalNumberOfVerses += apiBookChapter.numberOfVerses;\r\n\r\n translationChapters.push(apiBookChapter);\r\n api.translationBookChapters.push(apiBookChapter);\r\n }\r\n\r\n translationBooks.books.push(apiBook);\r\n\r\n apiTranslation.totalNumberOfChapters += apiBook.numberOfChapters;\r\n apiTranslation.totalNumberOfVerses += apiBook.totalNumberOfVerses;\r\n }\r\n\r\n for (let i = 0; i < translationChapters.length; i++) {\r\n if (i > 0) {\r\n translationChapters[i].previousChapterApiLink =\r\n bookChapterApiLink(\r\n translation.id,\r\n getBookLink(translationChapters[i - 1].book),\r\n translationChapters[i - 1].chapter.number,\r\n 'json',\r\n apiPathPrefix\r\n );\r\n translationChapters[i].previousChapterAudioLinks =\r\n translationChapters[i - 1].thisChapterAudioLinks;\r\n }\r\n\r\n if (i < translationChapters.length - 1) {\r\n translationChapters[i].nextChapterApiLink = bookChapterApiLink(\r\n translation.id,\r\n getBookLink(translationChapters[i + 1].book),\r\n translationChapters[i + 1].chapter.number,\r\n 'json',\r\n apiPathPrefix\r\n );\r\n translationChapters[i].nextChapterAudioLinks =\r\n translationChapters[i + 1].thisChapterAudioLinks;\r\n }\r\n }\r\n\r\n api.availableTranslations.translations.push(apiTranslation);\r\n api.translationBooks.push(translationBooks);\r\n }\r\n\r\n for (let { books, 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 apiBook: ApiCommentaryBook = {\r\n ...book,\r\n firstChapterApiLink: bookCommentaryChapterApiLink(\r\n commentary.id,\r\n getBookLink(book),\r\n 1,\r\n 'json',\r\n apiPathPrefix\r\n ),\r\n lastChapterApiLink: bookCommentaryChapterApiLink(\r\n commentary.id,\r\n getBookLink(book),\r\n chapters.length,\r\n 'json',\r\n apiPathPrefix\r\n ),\r\n numberOfChapters: chapters.length,\r\n totalNumberOfVerses: 0,\r\n };\r\n\r\n for (let { chapter } of chapters) {\r\n const apiBookChapter: ApiCommentaryBookChapter = {\r\n commentary: apiCommentary,\r\n book: apiBook,\r\n chapter: chapter,\r\n thisChapterLink: bookCommentaryChapterApiLink(\r\n commentary.id,\r\n getBookLink(book),\r\n chapter.number,\r\n 'json',\r\n apiPathPrefix\r\n ),\r\n nextChapterApiLink: null,\r\n previousChapterApiLink: null,\r\n numberOfVerses: 0,\r\n };\r\n\r\n for (let c of chapter.content) {\r\n if (c.type === 'verse') {\r\n apiBookChapter.numberOfVerses++;\r\n }\r\n }\r\n\r\n apiBook.totalNumberOfVerses += apiBookChapter.numberOfVerses;\r\n\r\n commentaryChapters.push(apiBookChapter);\r\n api.commentaryBookChapters.push(apiBookChapter);\r\n }\r\n\r\n commentaryBooks.books.push(apiBook);\r\n\r\n apiCommentary.totalNumberOfChapters += apiBook.numberOfChapters;\r\n apiCommentary.totalNumberOfVerses += apiBook.totalNumberOfVerses;\r\n }\r\n\r\n 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 return api;\r\n\r\n function getBookLink(book: TranslationBook | CommentaryBook): string {\r\n return useCommonName ? book.commonName : book.id;\r\n }\r\n}\r\n\r\n/**\r\n * Generates the output files for the given API.\r\n * @param api The API that the files should be generated for.\r\n */\r\nexport function generateFilesForApi(api: ApiOutput): OutputFile[] {\r\n let files: OutputFile[] = [];\r\n\r\n files.push(\r\n jsonFile(\r\n `${api.pathPrefix}/api/available_translations.json`,\r\n api.availableTranslations,\r\n true\r\n )\r\n );\r\n for (let translationBooks of api.translationBooks) {\r\n files.push(\r\n jsonFile(\r\n translationBooks.translation.listOfBooksApiLink,\r\n translationBooks\r\n )\r\n );\r\n }\r\n\r\n for (let bookChapter of api.translationBookChapters) {\r\n files.push(jsonFile(bookChapter.thisChapterLink, bookChapter));\r\n }\r\n\r\n for (let audio of api.translationBookChapterAudio) {\r\n files.push(downloadedFile(audio.link, audio.originalUrl));\r\n }\r\n\r\n files.push(\r\n jsonFile(\r\n `${api.pathPrefix}/api/available_commentaries.json`,\r\n api.availableCommentaries,\r\n true\r\n )\r\n );\r\n for (let commentaryBooks of api.commentaryBooks) {\r\n files.push(\r\n jsonFile(\r\n commentaryBooks.commentary.listOfBooksApiLink,\r\n commentaryBooks\r\n )\r\n );\r\n }\r\n\r\n for (let 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 // for (let audio of api.translationBookChapterAudio) {\r\n // files.push(downloadedFile(audio.link, audio.originalUrl));\r\n // }\r\n\r\n return files;\r\n}\r\n\r\n/**\r\n * Generates the output files for the given datasets.\r\n * @param datasets The datasets to generate the output files for.\r\n * @param options The options for generating the API files.\r\n */\r\nexport async function* generateOutputFilesFromDatasets(\r\n datasets: AsyncIterable<DatasetOutput>,\r\n options?: GenerateApiOptions\r\n): AsyncGenerator<OutputFile[]> {\r\n for await (let dataset of datasets) {\r\n const api = generateApiForDataset(dataset, options);\r\n const files = generateFilesForApi(api);\r\n\r\n yield files;\r\n }\r\n}\r\n\r\n/**\r\n * Gets the API Link for the list of books endpoint for a translation.\r\n * @param translationId The ID of the translation.\r\n * @returns\r\n */\r\nexport function listOfBooksApiLink(\r\n translationId: string,\r\n prefix: string = ''\r\n): string {\r\n return `${prefix}/api/${translationId}/books.json`;\r\n}\r\n\r\n/**\r\n * Gets the API Link for the list of books endpoint for a commentary.\r\n * @param commentaryId The ID of the commentary.\r\n * @returns\r\n */\r\nexport function listOfCommentaryBooksApiLink(\r\n commentaryId: string,\r\n prefix: string = ''\r\n): string {\r\n return `${prefix}/api/c/${commentaryId}/books.json`;\r\n}\r\n\r\n/**\r\n * Getes the API link for a book chapter.\r\n * @param translationId The ID of the translation.\r\n * @param commonName The name of the book.\r\n * @param chapterNumber The number of the book.\r\n * @param extension The extension of the file.\r\n */\r\nexport function bookChapterApiLink(\r\n translationId: string,\r\n commonName: string,\r\n chapterNumber: number,\r\n extension: string,\r\n prefix: string = ''\r\n) {\r\n return `${prefix}/api/${translationId}/${replaceSpacesWithUnderscores(\r\n commonName\r\n )}/${chapterNumber}.${extension}`;\r\n}\r\n\r\n/**\r\n * Getes the API link for a book chapter.\r\n * @param translationId The ID of the translation.\r\n * @param commonName The name of the book.\r\n * @param chapterNumber The number of the book.\r\n * @param extension The extension of the file.\r\n */\r\nexport function bookCommentaryChapterApiLink(\r\n translationId: string,\r\n commonName: string,\r\n chapterNumber: number,\r\n extension: string,\r\n prefix: string = ''\r\n) {\r\n return `${prefix}/api/c/${translationId}/${replaceSpacesWithUnderscores(\r\n commonName\r\n )}/${chapterNumber}.${extension}`;\r\n}\r\n\r\nexport function bookChapterAudioApiLink(\r\n translationId: string,\r\n bookId: string,\r\n chapterNumber: number,\r\n reader: string,\r\n prefix: string = ''\r\n) {\r\n return `${prefix}/api/${translationId}/${replaceSpacesWithUnderscores(\r\n bookId\r\n )}/${chapterNumber}.${reader}.mp3`;\r\n}\r\n\r\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, '_');\r\n}\r\n"],
5
+ "mappings": ";AAseO,gBAAS,sBACZ,SACA,UAA8B,CAAC,GACtB;AACT,QAAM,EAAE,eAAe,WAAW,IAAI;AACtC,QAAM,gBAAgB,aAAa,aAAa;AAChD,MAAI,MAAiB;AAAA,IACjB,uBAAuB;AAAA,MACnB,cAAc,CAAC;AAAA,IACnB;AAAA,IACA,kBAAkB,CAAC;AAAA,IACnB,yBAAyB,CAAC;AAAA,IAC1B,6BAA6B,CAAC;AAAA,IAC9B,uBAAuB;AAAA,MACnB,cAAc,CAAC;AAAA,IACnB;AAAA,IACA,wBAAwB,CAAC;AAAA,IACzB,iBAAiB,CAAC;AAAA,IAClB,oBAAoB,CAAC;AAAA,IACrB,2BAA2B,CAAC;AAAA,IAC5B,YAAY;AAAA,EAChB;AAEA,QAAM,gBAAgB,QAAQ;AAC9B,QAAM,iBAAiB,QAAQ;AAE/B,WAAS,EAAE,OAAO,GAAG,YAAY,KAAK,QAAQ,cAAc;AACxD,UAAM,iBAAiC;AAAA,MACnC,GAAG;AAAA,MACH,kBAAkB,CAAC,MAAM;AAAA,MACzB,oBAAoB;AAAA,QAChB,YAAY;AAAA,QACZ;AAAA,MACJ;AAAA,MACA,eAAe,MAAM;AAAA,MACrB,uBAAuB;AAAA,MACvB,qBAAqB;AAAA,MACrB,cAAc,gBACP,cAAc,YAAY,QAAQ,KAAK,SACxC;AAAA,MACN,qBAAqB,iBACd,eAAe,YAAY,QAAQ,KAAK,SACzC;AAAA,IACV;AAEA,UAAM,mBAAwC;AAAA,MAC1C,aAAa;AAAA,MACb,OAAO,CAAC;AAAA,IACZ;AAEA,QA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