@helloao/tools 0.1.0 → 0.2.0

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 (57) hide show
  1. package/dist/cjs/generation/api.cjs +727 -2
  2. package/dist/cjs/generation/api.cjs.map +2 -2
  3. package/dist/cjs/generation/audio.cjs +52 -5
  4. package/dist/cjs/generation/audio.cjs.map +2 -2
  5. package/dist/cjs/generation/book-order.cjs +1 -1
  6. package/dist/cjs/generation/book-order.cjs.map +2 -2
  7. package/dist/cjs/generation/common-types.cjs +651 -0
  8. package/dist/cjs/generation/common-types.cjs.map +2 -2
  9. package/dist/cjs/generation/dataset.cjs +31 -8
  10. package/dist/cjs/generation/dataset.cjs.map +2 -2
  11. package/dist/cjs/index.cjs.map +1 -1
  12. package/dist/cjs/log.cjs.map +1 -1
  13. package/dist/cjs/parser/codex-parser.cjs.map +1 -1
  14. package/dist/cjs/parser/commentary-csv-parser.cjs.map +1 -1
  15. package/dist/cjs/parser/iterators.cjs.map +1 -1
  16. package/dist/cjs/parser/lockman-parser.cjs +334 -0
  17. package/dist/cjs/parser/lockman-parser.cjs.map +7 -0
  18. package/dist/cjs/parser/tyndale-xml-parser.cjs.map +1 -1
  19. package/dist/cjs/parser/types.cjs.map +1 -1
  20. package/dist/cjs/parser/usfm-parser.cjs.map +1 -1
  21. package/dist/cjs/parser/usx-parser.cjs +24 -7
  22. package/dist/cjs/parser/usx-parser.cjs.map +2 -2
  23. package/dist/cjs/utils.cjs +152 -0
  24. package/dist/cjs/utils.cjs.map +3 -3
  25. package/dist/esm/generation/api.js +696 -2
  26. package/dist/esm/generation/api.js.map +2 -2
  27. package/dist/esm/generation/audio.js +46 -3
  28. package/dist/esm/generation/audio.js.map +2 -2
  29. package/dist/esm/generation/book-order.js +1 -1
  30. package/dist/esm/generation/book-order.js.map +2 -2
  31. package/dist/esm/generation/common-types.js +590 -0
  32. package/dist/esm/generation/common-types.js.map +3 -3
  33. package/dist/esm/generation/dataset.js +29 -8
  34. package/dist/esm/generation/dataset.js.map +2 -2
  35. package/dist/esm/index.js.map +1 -1
  36. package/dist/esm/log.js.map +1 -1
  37. package/dist/esm/parser/codex-parser.js.map +1 -1
  38. package/dist/esm/parser/commentary-csv-parser.js.map +1 -1
  39. package/dist/esm/parser/iterators.js.map +1 -1
  40. package/dist/esm/parser/lockman-parser.js +306 -0
  41. package/dist/esm/parser/lockman-parser.js.map +7 -0
  42. package/dist/esm/parser/tyndale-xml-parser.js.map +1 -1
  43. package/dist/esm/parser/usfm-parser.js.map +1 -1
  44. package/dist/esm/parser/usx-parser.js +24 -7
  45. package/dist/esm/parser/usx-parser.js.map +2 -2
  46. package/dist/esm/utils.js +138 -0
  47. package/dist/esm/utils.js.map +2 -2
  48. package/dist/types/generation/api.d.ts +2515 -470
  49. package/dist/types/generation/audio.d.ts +5 -0
  50. package/dist/types/generation/common-types.d.ts +1222 -413
  51. package/dist/types/generation/dataset.d.ts +1 -0
  52. package/dist/types/parser/codex-parser.d.ts +18 -138
  53. package/dist/types/parser/lockman-parser.d.ts +14 -0
  54. package/dist/types/parser/types.d.ts +4 -0
  55. package/dist/types/parser/usx-parser.d.ts +2 -2
  56. package/dist/types/utils.d.ts +223 -18
  57. package/package.json +5 -3
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../generation/common-types.ts"],
4
- "sourcesContent": ["import { VerseRef } from '../utils.js';\n\n/**\n * Defines an interface that contains information about a input file.\n */\nexport type InputFile = InputTranslationFile | InputCommentaryFile;\n\nexport interface InputFileBase {\n name?: string;\n content: string;\n sha256?: string;\n}\n\nexport type InputFileMetadata =\n | InputTranslationMetadata\n | InputCommentaryMetadata;\n\nexport interface InputTranslationFile extends InputFileBase {\n fileType: 'usfm' | 'usx' | 'json';\n metadata: InputTranslationMetadata;\n}\n\nexport interface InputCommentaryFile extends InputFileBase {\n fileType: 'commentary/csv' | 'commentary/tyndale-xml';\n metadata: InputCommentaryMetadata;\n}\n\nexport type OutputFileContent = object | ReadableStream;\n\n/**\n * Defines an interface that contains information about a output file.\n */\nexport interface OutputFile {\n /**\n * The path that the file should be stored at.\n */\n path: string;\n\n /**\n * The content of the file.\n */\n content: OutputFileContent | (() => Promise<OutputFileContent>);\n\n /**\n * Whether the file can be merged with files of the same name but from other datasets.\n */\n mergable?: boolean;\n}\n\nexport interface MetadataBase {\n /**\n * The name of the translation.\n */\n name: string;\n\n /**\n * The english name of the translation.\n */\n englishName: string;\n\n /**\n * The website for the translation.\n */\n website: string;\n\n /**\n * The URL that the license for the translation can be found.\n */\n licenseUrl: string;\n\n /**\n * The ISO 639 letter language tag that the translation is primarily in.\n */\n language: string;\n\n /**\n * The direction that the text is written in.\n */\n direction: 'ltr' | 'rtl';\n}\n\n/**\n * The metadata for a translation that is input into the generator.\n */\nexport interface InputTranslationMetadata extends MetadataBase {\n /**\n * The ID of the translation.\n */\n id: string;\n\n /**\n * The short name for the translation.\n */\n shortName: string;\n}\n\n/**\n * The metadata for a translation that is input into the generator.\n */\nexport interface InputCommentaryMetadata extends MetadataBase {\n /**\n * The ID of the commentary.\n */\n id: string;\n}\n\n/**\n * Defines an interface that contains information about a translation.\n */\nexport interface Translation {\n /**\n * The ID of the translation.\n */\n id: string;\n\n /**\n * The name of the translation.\n */\n name: string;\n\n /**\n * The website for the translation.\n */\n website: string;\n\n /**\n * The URL that the license for the translation can be found.\n */\n licenseUrl: string;\n\n /**\n * The API-added notes for the license.\n */\n licenseNotes?: string | null;\n\n /**\n * The short name for the translation.\n */\n shortName?: string;\n\n /**\n * The English name for the translation.\n */\n englishName: string;\n\n /**\n * The ISO 639 3-letter language tag that the translation is primarily in.\n */\n language: string;\n\n /**\n * The direction that the language is written in.\n * \"ltr\" indicates that the text is written from the left side of the page to the right.\n * \"rtl\" indicates that the text is written from the right side of the page to the left.\n */\n textDirection: 'ltr' | 'rtl';\n}\n\n/**\n * Defines an interface that contains information about a commentary.\n */\nexport interface Commentary {\n /**\n * The ID of the commentary.\n */\n id: string;\n\n /**\n * The name of the commentary.\n */\n name: string;\n\n /**\n * The website for the commentary.\n */\n website: string;\n\n /**\n * The URL that the license for the commentary can be found.\n */\n licenseUrl: string;\n\n /**\n * The API-added notes for the license.\n */\n licenseNotes?: string | null;\n\n /**\n * The english name for the commentary.\n */\n englishName: string;\n\n /**\n * The ISO 639 3-letter language tag that the translation is primarily in.\n */\n language: string;\n\n /**\n * The direction that the language is written in.\n * \"ltr\" indicates that the text is written from the left side of the page to the right.\n * \"rtl\" indicates that the text is written from the right side of the page to the left.\n */\n textDirection: 'ltr' | 'rtl';\n}\n\nexport interface Dataset {\n /**\n * The ID of the dataset.\n */\n id: string;\n\n /**\n * The name of the dataset.\n */\n name: string;\n\n /**\n * The website for the dataset.\n */\n website: string;\n\n /**\n * The URL that the license for the dataset can be found.\n */\n licenseUrl: string;\n\n /**\n * The API-added notes for the license.\n */\n licenseNotes?: string | null;\n\n /**\n * The English name for the dataset.\n */\n englishName: string;\n\n /**\n * The ISO 639 3-letter language tag that the dataset is primarily in.\n */\n language: string;\n\n /**\n * The direction that the language is written in.\n */\n textDirection: 'ltr' | 'rtl';\n}\n\n/**\n * Defines an interface that contains information about a book.\n */\nexport interface TranslationBook {\n /**\n * The ID of the book. Should match the USFM book ID.\n */\n id: string;\n\n /**\n * The name that the translation provided for the book.\n */\n name: string;\n\n /**\n * The common name for the book.\n */\n commonName: string;\n\n /**\n * The title of the book.\n * This is usually a more descriptive version of the book name.\n * If not available, then one was not provided by the translation.\n */\n title: string | null;\n\n /**\n * The numerical order of the book in the translation.\n */\n order: number;\n\n /**\n * Whether the book is an apocryphal book.\n */\n isApocryphal?: boolean;\n}\n\n/**\n * Defines an interface that contains information about a book in a commentary.\n */\nexport interface CommentaryBook {\n /**\n * The ID of the book. Should match the USFM book ID.\n */\n id: string;\n\n /**\n * The name that the commentary provided for the book.\n */\n name: string;\n\n /**\n * The common name for the book.\n */\n commonName: string;\n\n /**\n * The commentary's introduction for the book.\n */\n introduction?: string;\n\n /**\n * The summary of the commentary's introduction for the book.\n */\n introductionSummary?: string;\n\n /**\n * The order of the book in the Bible.\n */\n order: number;\n}\n\n/**\n * Defines an interface that contains information about a dataset book.\n */\nexport interface DatasetBook {\n /**\n * The ID of the book. Should match the USFM book ID.\n */\n id: string;\n\n /**\n * The order of the book in the Bible.\n */\n order: number;\n}\n\n/**\n * Defines an interface that contains information about a chapter in a dataset.\n */\nexport interface DatasetBookChapter {\n /**\n * The data for the chapter.\n */\n chapter: DatasetChapterData;\n}\n\nexport interface DatasetChapterData {\n /**\n * The number of the chapter.\n */\n number: number;\n\n /**\n * The content of the chapter.\n */\n content: DatasetChapterVerseContent[];\n}\n\n/**\n * Defines an interface that contains information about a verse in a dataset chapter.\n */\nexport interface DatasetChapterVerseContent {\n /**\n * The number of the verse.\n */\n verse: number;\n\n /**\n * The list of references for the verse.\n */\n references: ScoredVerseRef[];\n}\n\n/**\n * Defines an interface that contains information about a verse reference that has an arbitrary score attached to it.\n */\nexport interface ScoredVerseRef extends VerseRef {\n /**\n * The score of the verse reference.\n */\n score: number;\n}\n\n/**\n * Defines an interface that contains information about a profile in a commentary.\n */\nexport interface CommentaryProfile {\n /**\n * The ID of the profile.\n */\n id: string;\n\n /**\n * The subject of the profile.\n */\n subject: string;\n\n /**\n * The Bible reference that the profile is associated with.\n */\n reference: VerseRef | null;\n}\n\n/**\n * Defines an interface that contains information about a book chapter.\n */\nexport interface TranslationBookChapter {\n /**\n * The information for the chapter.\n */\n chapter: ChapterData;\n\n /**\n * The links to different audio versions for the chapter.\n */\n thisChapterAudioLinks: TranslationBookChapterAudioLinks;\n}\n\n/**\n * Defines an interface that contains information about a book chapter in a commentary.\n */\nexport interface CommentaryBookChapter {\n /**\n * The information for the chapter.\n */\n chapter: CommentaryChapterData;\n}\n\n/**\n * Defines an interface that contains the audio links for a book chapter.\n */\nexport interface TranslationBookChapterAudioLinks {\n /**\n * The reader for the chapter and the URL link to the audio file.\n */\n [reader: string]: string;\n}\n\n/**\n * Defines an interface that represents data in a chapter.\n */\nexport interface ChapterData {\n /**\n * The number of the chapter.\n */\n number: number;\n\n /**\n * The content of the chapter.\n */\n content: ChapterContent[];\n\n /**\n * The list of footnotes for the chapter.\n */\n footnotes: ChapterFootnote[];\n}\n\n/**\n * Defines an interface that represents data in a chapter in a commentary.\n */\nexport interface CommentaryChapterData {\n /**\n * The number of the chapter.\n */\n number: number;\n\n /**\n * The introduction that the commentary provided to the chapter.\n * Not all commentaries provide an introduction to a chapter.\n */\n introduction?: string;\n\n /**\n * The content of the chapter.\n */\n content: ChapterVerse[];\n}\n\n/**\n * A union type that represents a single piece of chapter content.\n * A piece of chapter content can be one of the following things:\n * - A heading.\n * - A line break.\n * - A verse.\n * - A Hebrew Subtitle.\n */\nexport type ChapterContent =\n | ChapterHeading\n | ChapterLineBreak\n | ChapterVerse\n | ChapterHebrewSubtitle;\n\n/**\n * A heading in a chapter.\n */\nexport interface ChapterHeading {\n /**\n * Indicates that the content represents a heading.\n */\n type: 'heading';\n\n /**\n * The content for the heading.\n * If multiple strings are included in the array, they should be concatenated with a space.\n */\n content: string[];\n}\n\n/**\n * A line break in a chapter.\n */\nexport interface ChapterLineBreak {\n /**\n * Indicates that the content represents a line break.\n */\n type: 'line_break';\n}\n\n/**\n * A Hebrew Subtitle in a chapter.\n * These are often used included as informational content that appeared in the original manuscripts.\n * For example, Psalms 49 has the Hebrew Subtitle \"To the choirmaster. A Psalm of the Sons of Korah.\"\n */\nexport interface ChapterHebrewSubtitle {\n /**\n * Indicates that the content represents a Hebrew Subtitle.\n */\n type: 'hebrew_subtitle';\n\n /**\n * The list of content that is contained in the subtitle.\n * Each element in the list could be a string, formatted text, or a footnote reference.\n */\n content: (string | FormattedText | VerseFootnoteReference)[];\n}\n\n/**\n * A verse in a chapter.\n */\nexport interface ChapterVerse {\n /**\n * Indicates that the content is a verse.\n */\n type: 'verse';\n\n /**\n * The number of the verse.\n */\n number: number;\n\n /**\n * The list of content for the verse.\n * Each element in the list could be a string, formatted text, or a footnote reference.\n */\n content: (\n | string\n | FormattedText\n | InlineHeading\n | InlineLineBreak\n | VerseFootnoteReference\n )[];\n}\n\n/**\n * Formatted text. That is, text that is formated in a particular manner.\n */\nexport interface FormattedText {\n /**\n * The text that is formatted.\n */\n text: string;\n\n /**\n * Whether the text represents a poem.\n * The number indicates the level of indent.\n *\n * Common in Psalms.\n */\n poem?: number;\n\n /**\n * Whether the text represents the Words of Jesus.\n */\n wordsOfJesus?: boolean;\n}\n\n/**\n * Defines an interface that represents a heading that is embedded in a verse.\n */\nexport interface InlineHeading {\n /**\n * The text of the heading.\n */\n heading: string;\n}\n\n/**\n * Defines an interface that represents a line break that is embedded in a verse.\n */\nexport interface InlineLineBreak {\n lineBreak: true;\n}\n\n/**\n * A footnote reference in a verse or a Hebrew Subtitle.\n */\nexport interface VerseFootnoteReference {\n /**\n * The ID of the note.\n */\n noteId: number;\n}\n\n/**\n * Information about a footnote.\n */\nexport interface ChapterFootnote {\n /**\n * The ID of the note that is referenced.\n */\n noteId: number;\n\n /**\n * The text of the footnote.\n */\n text: string;\n\n /**\n * The verse reference for the footnote.\n */\n reference?: {\n chapter: number;\n verse: number;\n };\n\n /**\n * The caller that should be used for the footnote.\n * For footnotes, a \"caller\" is the character that is used in the text to reference to footnote.\n *\n * For example, in the text:\n * Hello (a) World\n *\n * ----\n * (a) This is a footnote.\n *\n * The \"(a)\" is the caller.\n *\n * If \"+\", then the caller should be autogenerated.\n * If null, then the caller should be empty.\n * If a string, then the caller should be that string.\n */\n caller: '+' | string | null;\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
4
+ "sourcesContent": ["import { z } from 'zod';\r\nimport { BookIdSchema, VerseRef, VerseRefSchema } from '../utils.js';\r\n\r\n/**\r\n * Defines an interface that contains information about a input file.\r\n */\r\nexport type InputFile = InputTranslationFile | InputCommentaryFile;\r\n\r\nexport interface InputFileBase {\r\n name?: string;\r\n content: string;\r\n sha256?: string;\r\n}\r\n\r\nexport type InputFileMetadata =\r\n | InputTranslationMetadata\r\n | InputCommentaryMetadata;\r\n\r\nexport interface InputTranslationFile extends InputFileBase {\r\n fileType: 'usfm' | 'usx' | 'json' | 'lockman';\r\n metadata: InputTranslationMetadata;\r\n}\r\n\r\nexport interface InputCommentaryFile extends InputFileBase {\r\n fileType: 'commentary/csv' | 'commentary/tyndale-xml';\r\n metadata: InputCommentaryMetadata;\r\n}\r\n\r\nexport type OutputFileContent = object | ReadableStream;\r\n\r\n/**\r\n * Defines an interface that contains information about a output file.\r\n */\r\nexport interface OutputFile {\r\n /**\r\n * The path that the file should be stored at.\r\n */\r\n path: string;\r\n\r\n /**\r\n * The content of the file.\r\n */\r\n content: OutputFileContent | (() => Promise<OutputFileContent>);\r\n\r\n /**\r\n * Whether the file can be merged with files of the same name but from other datasets.\r\n */\r\n mergable?: boolean;\r\n}\r\n\r\nexport interface MetadataBase {\r\n /**\r\n * The name of the translation.\r\n */\r\n name: string;\r\n\r\n /**\r\n * The english name of the translation.\r\n */\r\n englishName: string;\r\n\r\n /**\r\n * The website for the translation.\r\n */\r\n website: string;\r\n\r\n /**\r\n * The URL that the license for the translation can be found.\r\n */\r\n licenseUrl: string;\r\n\r\n /**\r\n * The notice that should be displayed when displaying content from the translation.\r\n */\r\n licenseNotice?: string | null;\r\n\r\n /**\r\n * The ISO 639 letter language tag that the translation is primarily in.\r\n */\r\n language: string;\r\n\r\n /**\r\n * The direction that the text is written in.\r\n */\r\n direction: 'ltr' | 'rtl';\r\n}\r\n\r\n/**\r\n * The metadata for a translation that is input into the generator.\r\n */\r\nexport interface InputTranslationMetadata extends MetadataBase {\r\n /**\r\n * The ID of the translation.\r\n */\r\n id: string;\r\n\r\n /**\r\n * The short name for the translation.\r\n */\r\n shortName: string;\r\n}\r\n\r\n/**\r\n * The metadata for a translation that is input into the generator.\r\n */\r\nexport interface InputCommentaryMetadata extends MetadataBase {\r\n /**\r\n * The ID of the commentary.\r\n */\r\n id: string;\r\n}\r\n\r\n/**\r\n * Defines a Zod schema for information about a translation.\r\n */\r\nexport const TranslationSchema = z.object({\r\n /**\r\n * The ID of the translation.\r\n */\r\n id: z.string().meta({\r\n description: 'The ID of the translation.',\r\n }),\r\n\r\n /**\r\n * The name of the translation.\r\n */\r\n name: z.string().meta({\r\n description: 'The name of the translation.',\r\n }),\r\n\r\n /**\r\n * The website for the translation.\r\n */\r\n website: z.string().meta({\r\n description: 'The website for the translation.',\r\n }),\r\n\r\n /**\r\n * The URL that the license for the translation can be found.\r\n */\r\n licenseUrl: z.string().meta({\r\n description: 'The URL that the license for the translation can be found.',\r\n }),\r\n\r\n /**\r\n * The API-added notes for the license.\r\n */\r\n licenseNotes: z.string().nullable().optional().meta({\r\n description: 'The API-added notes for the license.',\r\n }),\r\n\r\n /**\r\n * The notice that should be displayed when displaying content from the translation.\r\n */\r\n licenseNotice: z.string().nullable().optional().meta({\r\n description: 'The notice that should be displayed when displaying content from the translation.',\r\n }),\r\n\r\n /**\r\n * The short name for the translation.\r\n */\r\n shortName: z.string().optional().meta({\r\n description: 'The short name for the translation.',\r\n }),\r\n\r\n /**\r\n * The English name for the translation.\r\n */\r\n englishName: z.string().meta({\r\n description: 'The English name for the translation.',\r\n }),\r\n\r\n /**\r\n * The ISO 639 3-letter language tag that the translation is primarily in.\r\n */\r\n language: z.string().meta({\r\n description: 'The ISO 639 3-letter language tag that the translation is primarily in.',\r\n }),\r\n\r\n /**\r\n * The direction that the language is written in.\r\n * \"ltr\" indicates that the text is written from the left side of the page to the right.\r\n * \"rtl\" indicates that the text is written from the right side of the page to the left.\r\n */\r\n textDirection: z.enum(['ltr', 'rtl']).meta({\r\n description: 'The direction that the language is written in. `ltr` indicates that the text is written from the left side of the page to the right. `rtl` indicates that the text is written from the right side of the page to the left.',\r\n }),\r\n});\r\n\r\nexport type Translation = z.infer<typeof TranslationSchema>;\r\n\r\n/**\r\n * Defines a Zod schema for information about a commentary.\r\n */\r\nexport const CommentarySchema = z.object({\r\n /**\r\n * The ID of the commentary.\r\n */\r\n id: z.string().meta({\r\n description: 'The ID of the commentary.',\r\n }),\r\n\r\n /**\r\n * The name of the commentary.\r\n */\r\n name: z.string().meta({\r\n description: 'The name of the commentary.',\r\n }),\r\n\r\n /**\r\n * The website for the commentary.\r\n */\r\n website: z.string().meta({\r\n description: 'The website for the commentary.',\r\n }),\r\n\r\n /**\r\n * The URL that the license for the commentary can be found.\r\n */\r\n licenseUrl: z.string().meta({\r\n description: 'The URL that the license for the commentary can be found.',\r\n }),\r\n\r\n /**\r\n * The API-added notes for the license.\r\n */\r\n licenseNotes: z.string().nullable().optional().meta({\r\n description: 'The API-added notes for the license.',\r\n }),\r\n\r\n /**\r\n * The english name for the commentary.\r\n */\r\n englishName: z.string().meta({\r\n description: 'The English name for the commentary.',\r\n }),\r\n\r\n /**\r\n * The ISO 639 3-letter language tag that the translation is primarily in.\r\n */\r\n language: z.string().meta({\r\n description: 'The ISO 639 3-letter language tag that the translation is primarily in.',\r\n }),\r\n\r\n /**\r\n * The direction that the language is written in.\r\n * \"ltr\" indicates that the text is written from the left side of the page to the right.\r\n * \"rtl\" indicates that the text is written from the right side of the page to the left.\r\n */\r\n textDirection: z.enum(['ltr', 'rtl']).meta({\r\n description: 'The direction that the language is written in. `ltr` indicates that the text is written from the left side of the page to the right. `rtl` indicates that the text is written from the right side of the page to the left.',\r\n }),\r\n});\r\n\r\nexport type Commentary = z.infer<typeof CommentarySchema>;\r\n\r\nexport const DatasetSchema = z.object({\r\n /**\r\n * The ID of the dataset.\r\n */\r\n id: z.string().meta({\r\n description: 'The ID of the dataset.',\r\n }),\r\n\r\n /**\r\n * The name of the dataset.\r\n */\r\n name: z.string().meta({\r\n description: 'The name of the dataset.',\r\n }),\r\n\r\n /**\r\n * The website for the dataset.\r\n */\r\n website: z.string().meta({\r\n description: 'The website for the dataset.',\r\n }),\r\n\r\n /**\r\n * The URL that the license for the dataset can be found.\r\n */\r\n licenseUrl: z.string().meta({\r\n description: 'The URL that the license for the dataset can be found.',\r\n }),\r\n\r\n /**\r\n * The API-added notes for the license.\r\n */\r\n licenseNotes: z.string().nullable().optional().meta({\r\n description: 'The API-added notes for the license.',\r\n }),\r\n\r\n /**\r\n * The English name for the dataset.\r\n */\r\n englishName: z.string().meta({\r\n description: 'The English name for the dataset.',\r\n }),\r\n\r\n /**\r\n * The ISO 639 3-letter language tag that the dataset is primarily in.\r\n */\r\n language: z.string().meta({\r\n description: 'The ISO 639 3-letter language tag that the dataset is primarily in.',\r\n }),\r\n\r\n /**\r\n * The direction that the language is written in.\r\n */\r\n textDirection: z.enum(['ltr', 'rtl']).meta({\r\n description: 'The direction that the language is written in.',\r\n }),\r\n});\r\n\r\nexport type Dataset = z.infer<typeof DatasetSchema>;\r\n\r\n/**\r\n * Defines a Zod schema for information about a book.\r\n */\r\nexport const TranslationBookSchema = z.object({\r\n /**\r\n * The ID of the book. Should match the USFM book ID.\r\n */\r\n id: BookIdSchema,\r\n\r\n /**\r\n * The name that the translation provided for the book.\r\n */\r\n name: z.string().meta({\r\n description: 'The name that the translation provided for the book.',\r\n }),\r\n\r\n /**\r\n * The common name for the book.\r\n */\r\n commonName: z.string().meta({\r\n description: 'The common name for the book.',\r\n }),\r\n\r\n /**\r\n * The title of the book.\r\n * This is usually a more descriptive version of the book name.\r\n * If not available, then one was not provided by the translation.\r\n */\r\n title: z.string().nullable().meta({\r\n description: 'The title of the book. This is usually a more descriptive version of the book name. If not available, then one was not provided by the translation.',\r\n }),\r\n\r\n /**\r\n * The numerical order of the book in the translation.\r\n */\r\n order: z.number().meta({\r\n description: 'The numerical order of the book in the translation.',\r\n }),\r\n\r\n /**\r\n * Whether the book is an apocryphal book.\r\n */\r\n isApocryphal: z.boolean().optional().meta({\r\n description: 'Whether the book is an apocryphal book.',\r\n }),\r\n}).meta({\r\n id: 'TranslationBook',\r\n description: 'Defines the schema for information about a book.',\r\n});\r\n\r\nexport type TranslationBook = z.infer<typeof TranslationBookSchema>;\r\n\r\n/**\r\n * Defines a Zod schema for information about a book in a commentary.\r\n */\r\nexport const CommentaryBookSchema = z.object({\r\n /**\r\n * The ID of the book. Should match the USFM book ID.\r\n */\r\n id: BookIdSchema,\r\n\r\n /**\r\n * The name that the commentary provided for the book.\r\n */\r\n name: z.string().meta({\r\n description: 'The name that the commentary provided for the book.',\r\n }),\r\n\r\n /**\r\n * The common name for the book.\r\n */\r\n commonName: z.string().meta({\r\n description: 'The common name for the book.',\r\n }),\r\n\r\n /**\r\n * The commentary's introduction for the book.\r\n */\r\n introduction: z.string().optional().meta({\r\n description: 'The commentary\\'s introduction for the book. Undefined if the commentary didn\\'t provide an introduction for the book.',\r\n }),\r\n\r\n /**\r\n * The summary of the commentary's introduction for the book.\r\n */\r\n introductionSummary: z.string().optional().meta({\r\n description: 'The summary of the commentary\\'s introduction for the book. Undefined if the commentary didn\\'t provide a summary for the book.',\r\n }),\r\n\r\n /**\r\n * The order of the book in the Bible.\r\n */\r\n order: z.number().meta({\r\n description: 'The order of the book in the Bible.',\r\n }),\r\n}).meta({\r\n id: \"CommentaryBook\",\r\n description: \"Defines the schema for information about a book in a commentary.\",\r\n});\r\n\r\nexport type CommentaryBook = z.infer<typeof CommentaryBookSchema>;\r\n\r\n/**\r\n * Defines a Zod schema for information about a dataset book.\r\n */\r\nexport const DatasetBookSchema = z.object({\r\n /**\r\n * The ID of the book. Should match the USFM book ID.\r\n */\r\n id: BookIdSchema,\r\n\r\n /**\r\n * The order of the book in the Bible.\r\n */\r\n order: z.number().meta({\r\n description: 'The order of the book in the Bible.',\r\n }),\r\n}).meta({\r\n id: 'DatasetBook',\r\n description: 'Defines the schema for information about a book in a dataset.',\r\n});\r\n\r\nexport type DatasetBook = z.infer<typeof DatasetBookSchema>;\r\n\r\n/**\r\n * Defines a Zod schema for information about a chapter in a dataset.\r\n */\r\nexport const DatasetBookChapterSchema = z.object({\r\n /**\r\n * The data for the chapter.\r\n */\r\n chapter: z.lazy(() => DatasetChapterDataSchema).meta({\r\n description: 'The data for the chapter.',\r\n }),\r\n}).meta({\r\n id: 'DatasetBookChapter',\r\n description: 'Defines the schema for information about a chapter in a dataset.',\r\n});\r\n\r\nexport type DatasetBookChapter = z.infer<typeof DatasetBookChapterSchema>;\r\n\r\nexport const DatasetChapterDataSchema = z.object({\r\n /**\r\n * The number of the chapter.\r\n */\r\n number: z.number().meta({\r\n description: 'The number of the chapter.',\r\n }),\r\n\r\n /**\r\n * The content of the chapter.\r\n */\r\n content: z.array(z.lazy(() => DatasetChapterVerseContentSchema)).meta({\r\n description: 'The content of the chapter.',\r\n }),\r\n}).meta({\r\n id: 'DatasetChapterData',\r\n description: 'Defines the schema for information about a chapter in a dataset.',\r\n});\r\n\r\nexport type DatasetChapterData = z.infer<typeof DatasetChapterDataSchema>;\r\n\r\n/**\r\n * Defines a Zod schema for information about a verse in a dataset chapter.\r\n */\r\nexport const DatasetChapterVerseContentSchema = z.object({\r\n /**\r\n * The number of the verse.\r\n */\r\n verse: z.number().meta({\r\n description: 'The number of the verse.',\r\n }),\r\n\r\n /**\r\n * The list of references for the verse.\r\n */\r\n references: z.array(z.lazy(() => ScoredVerseRefSchema)).meta({\r\n description: 'The list of references for the verse.',\r\n }),\r\n}).meta({\r\n id: 'DatasetChapterVerseContent',\r\n description: 'Defines the schema for information about a verse in a dataset chapter.',\r\n});\r\n\r\nexport type DatasetChapterVerseContent = z.infer<typeof DatasetChapterVerseContentSchema>;\r\n\r\n/**\r\n * Defines an interface that contains information about a verse reference that has an arbitrary score attached to it.\r\n */\r\nexport const ScoredVerseRefSchema = VerseRefSchema.extend({\r\n score: z.number().meta({\r\n description: 'The score for the verse reference. The meaning of the score is arbitrary and is determined by the dataset.',\r\n }),\r\n}).meta({\r\n id: 'ScoredVerseRef',\r\n description: 'Defines the schema for information about a verse reference that has an arbitrary score attached to it.',\r\n});\r\n\r\nexport type ScoredVerseRef = z.infer<typeof ScoredVerseRefSchema>;\r\n\r\n/**\r\n * Defines a Zod schema for information about a profile in a commentary.\r\n */\r\nexport const CommentaryProfileSchema = z.object({\r\n /**\r\n * The ID of the profile.\r\n */\r\n id: z.string().meta({\r\n description: 'The ID of the profile.',\r\n }),\r\n\r\n /**\r\n * The subject of the profile.\r\n */\r\n subject: z.string().meta({\r\n description: 'The subject of the profile.',\r\n }),\r\n\r\n /**\r\n * The Bible reference that the profile is associated with.\r\n */\r\n reference: VerseRefSchema.nullable().meta({\r\n description: 'The Bible reference that the profile is associated with. Null if the profile isn\\'t associated with a specific Bible reference.',\r\n }),\r\n});\r\n\r\nexport type CommentaryProfile = z.infer<typeof CommentaryProfileSchema>;\r\n\r\n/**\r\n * Defines a Zod schema for information about a book chapter.\r\n */\r\nexport const TranslationBookChapterSchema = z.object({\r\n /**\r\n * The information for the chapter.\r\n */\r\n chapter: z.lazy(() => ChapterDataSchema).meta({\r\n description: 'The information for the chapter.',\r\n }),\r\n\r\n /**\r\n * The links to different audio versions for the chapter.\r\n */\r\n thisChapterAudioLinks: z.lazy(() => TranslationBookChapterAudioLinksSchema).meta({\r\n description: 'The links to different audio versions for the chapter.',\r\n }),\r\n}).meta({\r\n id: 'TranslationBookChapter',\r\n description: 'Defines the schema for information about a book chapter.',\r\n});\r\n\r\nexport type TranslationBookChapter = z.infer<typeof TranslationBookChapterSchema>;\r\n\r\n/**\r\n * Defines a Zod schema for information about a book chapter in a commentary.\r\n */\r\nexport const CommentaryBookChapterSchema = z.object({\r\n /**\r\n * The information for the chapter.\r\n */\r\n chapter: z.lazy(() => CommentaryChapterDataSchema).meta({\r\n description: 'The information for the chapter.',\r\n }),\r\n}).meta({\r\n id: 'CommentaryBookChapter',\r\n description: 'Defines the schema for information about a book chapter in a commentary.',\r\n});\r\n\r\nexport type CommentaryBookChapter = z.infer<typeof CommentaryBookChapterSchema>;\r\n\r\n/**\r\n * Defines a Zod schema for the audio links for a book chapter.\r\n */\r\nexport const TranslationBookChapterAudioLinksSchema = z.record(z.string(), z.string()).meta({\r\n id: 'TranslationBookChapterAudioLinks',\r\n description: 'Defines the schema for the audio links for a book chapter.',\r\n});\r\n\r\nexport type TranslationBookChapterAudioLinks = z.infer<typeof TranslationBookChapterAudioLinksSchema>;\r\n\r\n/**\r\n * Defines a Zod schema for information about data in a chapter.\r\n */\r\nexport const ChapterDataSchema = z.object({\r\n /**\r\n * The number of the chapter.\r\n */\r\n number: z.number().meta({\r\n description: 'The number of the chapter.',\r\n }),\r\n\r\n /**\r\n * The content of the chapter.\r\n */\r\n content: z.array(z.lazy(() => ChapterContentSchema)).meta({\r\n description: 'The content of the chapter.',\r\n }),\r\n\r\n /**\r\n * The list of footnotes for the chapter.\r\n */\r\n footnotes: z.array(z.lazy(() => ChapterFootnoteSchema)).meta({\r\n description: 'The list of footnotes for the chapter.',\r\n }),\r\n});\r\n\r\nexport type ChapterData = z.infer<typeof ChapterDataSchema>;\r\n\r\n/**\r\n * Defines a Zod schema for information about data in a chapter in a commentary.\r\n */\r\nexport const CommentaryChapterDataSchema = z.object({\r\n /**\r\n * The number of the chapter.\r\n */\r\n number: z.number().meta({\r\n description: 'The number of the chapter.',\r\n }),\r\n\r\n /**\r\n * The introduction that the commentary provided to the chapter.\r\n * Not all commentaries provide an introduction to a chapter.\r\n */\r\n introduction: z.string().optional().meta({\r\n description: 'The introduction that the commentary provided to the chapter. Not all commentaries provide an introduction to a chapter.',\r\n }),\r\n\r\n /**\r\n * The content of the chapter.\r\n */\r\n content: z.array(z.lazy(() => ChapterVerseSchema)).meta({\r\n description: 'The content of the chapter.',\r\n }),\r\n});\r\n\r\nexport type CommentaryChapterData = z.infer<typeof CommentaryChapterDataSchema>;\r\n\r\n/**\r\n * A Zod schema for a heading in a chapter.\r\n */\r\nexport const ChapterHeadingSchema = z.object({\r\n /**\r\n * Indicates that the content represents a heading.\r\n */\r\n type: z.literal('heading'),\r\n\r\n /**\r\n * The content for the heading.\r\n * If multiple strings are included in the array, they should be concatenated with a space.\r\n */\r\n content: z.array(z.string()).meta({\r\n description: 'The content for the heading. If multiple strings are included in the array, they should be concatenated with a space.',\r\n }),\r\n}).meta({\r\n id: 'ChapterHeading',\r\n description: 'Defines the schema for a heading in a chapter.',\r\n});\r\n\r\nexport type ChapterHeading = z.infer<typeof ChapterHeadingSchema>;\r\n\r\n/**\r\n * A Zod schema for a line break in a chapter.\r\n */\r\nexport const ChapterLineBreakSchema = z.object({\r\n /**\r\n * Indicates that the content represents a line break.\r\n */\r\n type: z.literal('line_break'),\r\n}).meta({\r\n id: 'ChapterLineBreak',\r\n description: 'Defines the schema for a line break in a chapter.',\r\n});\r\n\r\nexport type ChapterLineBreak = z.infer<typeof ChapterLineBreakSchema>;\r\n\r\n/**\r\n * A Zod schema for a Hebrew Subtitle in a chapter.\r\n * These are often used included as informational content that appeared in the original manuscripts.\r\n * For example, Psalms 49 has the Hebrew Subtitle \"To the choirmaster. A Psalm of the Sons of Korah.\"\r\n */\r\nexport const ChapterHebrewSubtitleSchema = z.object({\r\n /**\r\n * Indicates that the content represents a Hebrew Subtitle.\r\n */\r\n type: z.literal('hebrew_subtitle'),\r\n\r\n /**\r\n * The list of content that is contained in the subtitle.\r\n * Each element in the list could be a string, formatted text, or a footnote reference.\r\n */\r\n content: z.array(z.union([\r\n z.string(),\r\n z.lazy(() => FormattedTextSchema),\r\n z.lazy(() => VerseFootnoteReferenceSchema),\r\n ])).meta({\r\n description: 'The content that is contained in the subtitle. Each element in the list could be a string, formatted text, or a footnote reference.',\r\n }),\r\n}).meta({\r\n id: 'ChapterHebrewSubtitle',\r\n description: 'Defines the schema for a Hebrew Subtitle in a chapter.',\r\n});\r\n\r\nexport type ChapterHebrewSubtitle = z.infer<typeof ChapterHebrewSubtitleSchema>;\r\n\r\n/**\r\n * A Zod schema for a verse in a chapter.\r\n */\r\nexport const ChapterVerseSchema = z.object({\r\n /**\r\n * Indicates that the content is a verse.\r\n */\r\n type: z.literal('verse'),\r\n\r\n /**\r\n * The number of the verse.\r\n */\r\n number: z.number().meta({\r\n description: 'The number of the verse.',\r\n }),\r\n\r\n /**\r\n * The list of content for the verse.\r\n * Each element in the list could be a string, formatted text, or a footnote reference.\r\n */\r\n content: z.array(z.union([\r\n z.string(),\r\n z.lazy(() => FormattedTextSchema),\r\n z.lazy(() => InlineHeadingSchema),\r\n z.lazy(() => InlineLineBreakSchema),\r\n z.lazy(() => VerseFootnoteReferenceSchema),\r\n ])).meta({\r\n description: 'The list of content for the verse. Each element in the list could be a string, formatted text, or a footnote reference.',\r\n }),\r\n}).meta({\r\n id: 'ChapterVerse',\r\n description: 'Defines the schema for a verse in a chapter.',\r\n});\r\n\r\nexport type ChapterVerse = z.infer<typeof ChapterVerseSchema>;\r\n\r\n/**\r\n * A union type that represents a single piece of chapter content.\r\n * A piece of chapter content can be one of the following things:\r\n * - A heading.\r\n * - A line break.\r\n * - A verse.\r\n * - A Hebrew Subtitle.\r\n */\r\nexport const ChapterContentSchema = z.discriminatedUnion('type', [\r\n ChapterHeadingSchema,\r\n ChapterLineBreakSchema,\r\n ChapterVerseSchema,\r\n ChapterHebrewSubtitleSchema,\r\n]).meta({\r\n id: 'ChapterContent',\r\n description: 'Defines a union type that represents a single piece of chapter content. A piece of chapter content can be one of the following things: A heading, a line break, a verse, or a Hebrew Subtitle.',\r\n});\r\n\r\n/**\r\n * A union type that represents a single piece of chapter content.\r\n * A piece of chapter content can be one of the following things:\r\n * - A heading.\r\n * - A line break.\r\n * - A verse.\r\n * - A Hebrew Subtitle.\r\n */\r\nexport type ChapterContent = z.infer<typeof ChapterContentSchema>;\r\n\r\n/**\r\n * A Zod schema for formatted text. That is, text that is formatted in a particular manner.\r\n */\r\nexport const FormattedTextSchema = z.object({\r\n /**\r\n * The text that is formatted.\r\n */\r\n text: z.string().meta({\r\n description: 'The text that is formatted.',\r\n }),\r\n\r\n /**\r\n * Whether the text represents a poem.\r\n * The number indicates the level of indent.\r\n *\r\n * Common in Psalms.\r\n */\r\n poem: z.number().optional().meta({\r\n description: 'Whether the text represents a poem. The number indicates the level of indent. Common in Psalms.',\r\n }),\r\n\r\n /**\r\n * Whether the text represents the Words of Jesus.\r\n */\r\n wordsOfJesus: z.boolean().optional().meta({\r\n description: 'Whether the text represents the Words of Jesus.',\r\n }),\r\n}).meta({\r\n id: 'FormattedText',\r\n description: 'Defines the schema for formatted text. That is, text that is formatted in a particular manner.',\r\n});\r\n\r\nexport type FormattedText = z.infer<typeof FormattedTextSchema>;\r\n\r\n/**\r\n * A Zod schema for a heading that is embedded in a verse.\r\n */\r\nexport const InlineHeadingSchema = z.object({\r\n /**\r\n * The text of the heading.\r\n */\r\n heading: z.string().meta({\r\n description: 'The text of the heading.',\r\n }),\r\n}).meta({\r\n id: 'InlineHeading',\r\n description: 'Defines the schema for a heading that is embedded in a verse.',\r\n});\r\n\r\nexport type InlineHeading = z.infer<typeof InlineHeadingSchema>;\r\n\r\n/**\r\n * A Zod schema for a line break that is embedded in a verse.\r\n */\r\nexport const InlineLineBreakSchema = z.object({\r\n lineBreak: z.literal(true),\r\n}).meta({\r\n id: 'InlineLineBreak',\r\n description: 'Defines the schema for a line break that is embedded in a verse.',\r\n});\r\n\r\nexport type InlineLineBreak = z.infer<typeof InlineLineBreakSchema>;\r\n\r\n/**\r\n * A Zod schema for a footnote reference in a verse or a Hebrew Subtitle.\r\n */\r\nexport const VerseFootnoteReferenceSchema = z.object({\r\n /**\r\n * The ID of the note.\r\n */\r\n noteId: z.number().meta({\r\n description: 'The ID of the note.',\r\n }),\r\n}).meta({\r\n id: 'VerseFootnoteReference',\r\n description: 'Defines the schema for a footnote reference in a verse or a Hebrew Subtitle.',\r\n});\r\n\r\nexport type VerseFootnoteReference = z.infer<typeof VerseFootnoteReferenceSchema>;\r\n\r\n/**\r\n * A Zod schema for information about a footnote.\r\n */\r\nexport const ChapterFootnoteSchema = z.object({\r\n /**\r\n * The ID of the note that is referenced.\r\n */\r\n noteId: z.number().meta({\r\n description: 'The ID of the note that is referenced.',\r\n }),\r\n\r\n /**\r\n * The text of the footnote.\r\n */\r\n text: z.string().meta({\r\n description: 'The text of the footnote.',\r\n }),\r\n\r\n /**\r\n * The verse reference for the footnote.\r\n */\r\n reference: z.object({\r\n chapter: z.number(),\r\n verse: z.number(),\r\n }).optional().meta({\r\n description: 'The verse reference for the footnote. Undefined if the footnote isn\\'t associated with a specific verse.',\r\n }),\r\n\r\n /**\r\n * The caller that should be used for the footnote.\r\n * For footnotes, a \"caller\" is the character that is used in the text to reference to footnote.\r\n *\r\n * For example, in the text:\r\n * Hello (a) World\r\n *\r\n * ----\r\n * (a) This is a footnote.\r\n *\r\n * The \"(a)\" is the caller.\r\n *\r\n * If \"+\", then the caller should be autogenerated.\r\n * If null, then the caller should be empty.\r\n * If a string, then the caller should be that string.\r\n */\r\n caller: z.union([z.literal('+'), z.string(), z.null()]).meta({\r\n description: 'The caller that should be used for the footnote. For footnotes, a \"caller\" is the character that is used in the text to reference to footnote. For example, in the text: Hello (a) World ---- (a) This is a footnote. The \"(a)\" is the caller. If \"+\", then the caller should be autogenerated. If null, then the caller should be empty. If a string, then the caller should be that string.',\r\n }),\r\n}).meta({\r\n id: 'ChapterFootnote',\r\n description: 'Defines the schema for information about a footnote.',\r\n});\r\n\r\nexport type ChapterFootnote = z.infer<typeof ChapterFootnoteSchema>;\r\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAAkB;AAClB,mBAAuD;AAkHhD,MAAM,oBAAoB,aAAE,OAAO;AAAA;AAAA;AAAA;AAAA,EAItC,IAAI,aAAE,OAAO,EAAE,KAAK;AAAA,IAChB,aAAa;AAAA,EACjB,CAAC;AAAA;AAAA;AAAA;AAAA,EAKD,MAAM,aAAE,OAAO,EAAE,KAAK;AAAA,IAClB,aAAa;AAAA,EACjB,CAAC;AAAA;AAAA;AAAA;AAAA,EAKD,SAAS,aAA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,OAAO,aAAE,OAAO;AAAA,EACpB,CAAC,EAAE,SAAS,EAAE,KAAK;AAAA,IACf,aAAa;AAAA,EACjB,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAkBD,QAAQ,aAAE,MAAM,CAAC,aAAE,QAAQ,GAAG,GAAG,aAAE,OAAO,GAAG,aAAE,KAAK,CAAC,CAAC,EAAE,KAAK;AAAA,IACzD,aAAa;AAAA,EACjB,CAAC;AACL,CAAC,EAAE,KAAK;AAAA,EACJ,IAAI;AAAA,EACJ,aAAa;AACjB,CAAC;",
6
6
  "names": []
7
7
  }
@@ -18,6 +18,7 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var dataset_exports = {};
20
20
  __export(dataset_exports, {
21
+ DATASET_VERSION: () => DATASET_VERSION,
21
22
  generateDataset: () => generateDataset
22
23
  });
23
24
  module.exports = __toCommonJS(dataset_exports);
@@ -30,6 +31,8 @@ var import_codex_parser = require("../parser/codex-parser.js");
30
31
  var import_commentary_csv_parser = require("../parser/commentary-csv-parser.js");
31
32
  var import_tyndale_xml_parser = require("../parser/tyndale-xml-parser.js");
32
33
  var import_log = require("../log.js");
34
+ var import_lockman_parser = require("../parser/lockman-parser.js");
35
+ const DATASET_VERSION = 1;
33
36
  function generateDataset(files, parser = new globalThis.DOMParser(), bookMap) {
34
37
  const logger = (0, import_log.getLogger)();
35
38
  let output = {
@@ -41,6 +44,7 @@ function generateDataset(files, parser = new globalThis.DOMParser(), bookMap) {
41
44
  let codexParser = new import_codex_parser.CodexParser(parser);
42
45
  let csvCommentaryParser = new import_commentary_csv_parser.CommentaryCsvParser();
43
46
  let tyndaleXmlParser = new import_tyndale_xml_parser.TyndaleXmlParser(parser);
47
+ let lockmanParser = new import_lockman_parser.LockmanParser();
44
48
  let parsedTranslations = /* @__PURE__ */ new Map();
45
49
  let parsedCommentaries = /* @__PURE__ */ new Map();
46
50
  const unknownLanguages = /* @__PURE__ */ new Set();
@@ -57,6 +61,8 @@ function generateDataset(files, parser = new globalThis.DOMParser(), bookMap) {
57
61
  parser2 = csvCommentaryParser;
58
62
  } else if (file.fileType === "commentary/tyndale-xml") {
59
63
  parser2 = tyndaleXmlParser;
64
+ } else if (file.fileType === "lockman") {
65
+ parser2 = lockmanParser;
60
66
  } else {
61
67
  logger.warn(
62
68
  "[generate] File does not have a valid type!",
@@ -64,15 +70,25 @@ function generateDataset(files, parser = new globalThis.DOMParser(), bookMap) {
64
70
  );
65
71
  continue;
66
72
  }
67
- const parsed = parser2.parse(file.content);
68
- if ("parseMessages" in parsed && parsed.parseMessages && file.name) {
69
- const messages = output.parseMessages = output.parseMessages || {};
70
- messages[file.name] = parsed.parseMessages;
71
- }
72
- if (parsed.type === "root") {
73
- addTranslationTree(file, parsed);
73
+ const parsed = parser2.parse(
74
+ file.content
75
+ );
76
+ if (Array.isArray(parsed)) {
77
+ for (let p of parsed) {
78
+ logParseMessages(p, file);
79
+ if (p.type === "root") {
80
+ addTranslationTree(file, p);
81
+ } else {
82
+ addCommentaryTree(file, p);
83
+ }
84
+ }
74
85
  } else {
75
- addCommentaryTree(file, parsed);
86
+ logParseMessages(parsed, file);
87
+ if (parsed.type === "root") {
88
+ addTranslationTree(file, parsed);
89
+ } else {
90
+ addCommentaryTree(file, parsed);
91
+ }
76
92
  }
77
93
  } catch (err) {
78
94
  logger.error(
@@ -81,6 +97,12 @@ function generateDataset(files, parser = new globalThis.DOMParser(), bookMap) {
81
97
  );
82
98
  }
83
99
  }
100
+ function logParseMessages(parsed, file) {
101
+ if ("parseMessages" in parsed && parsed.parseMessages && file.name) {
102
+ const messages = output.parseMessages = output.parseMessages || {};
103
+ messages[file.name] = parsed.parseMessages;
104
+ }
105
+ }
84
106
  function addTranslationTree(file, parsed) {
85
107
  const id = parsed.id;
86
108
  if (!id) {
@@ -262,6 +284,7 @@ function generateDataset(files, parser = new globalThis.DOMParser(), bookMap) {
262
284
  }
263
285
  // Annotate the CommonJS export names for ESM import in node:
264
286
  0 && (module.exports = {
287
+ DATASET_VERSION,
265
288
  generateDataset
266
289
  });
267
290
  //# sourceMappingURL=dataset.cjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../generation/dataset.ts"],
4
- "sourcesContent": ["import { UsfmParser } from '../parser/usfm-parser.js';\nimport { USXParser } from '../parser/usx-parser.js';\nimport {\n Commentary,\n CommentaryBook,\n CommentaryBookChapter,\n CommentaryChapterData,\n CommentaryProfile,\n InputCommentaryFile,\n InputFile,\n InputFileBase,\n InputTranslationFile,\n MetadataBase,\n Translation,\n TranslationBook,\n TranslationBookChapter,\n Dataset as CommonDataset,\n DatasetBook,\n DatasetBookChapter,\n} from './common-types.js';\nimport {\n bookIdMap as defaultBookIdMap,\n bookOrderMap,\n apocryphaBooks,\n} from './book-order.js';\nimport { omit, sortBy, sortedIndexBy } from 'lodash';\nimport { getAudioUrlsForChapter } from './audio.js';\nimport { CodexParser } from '../parser/codex-parser.js';\nimport { CommentaryCsvParser } from '../parser/commentary-csv-parser.js';\nimport {\n CommentaryParseTree,\n ParseMessage,\n ParseTree,\n} from '../parser/types.js';\nimport { TyndaleXmlParser } from '../parser/tyndale-xml-parser.js';\nimport { getLogger } from '../log.js';\n\n/**\n * Defines an interface that contains generated dataset info.\n */\nexport interface DatasetOutput {\n /**\n * The list of translations that are available in the dataset.\n */\n translations: DatasetTranslation[];\n\n /**\n * The list of commentaries that are available in the dataset.\n */\n commentaries: DatasetCommentary[];\n\n /**\n * The list of datasets that are available in the dataset.\n */\n datasets?: DatasetDataset[];\n\n parseMessages?: {\n [key: string]: ParseMessage[];\n };\n}\n\n/**\n * Defines a translation that is used in the dataset.\n */\nexport interface DatasetTranslation extends Translation {\n /**\n * The list of books that are available for the translation.\n */\n books: DatasetTranslationBook[];\n}\n\n/**\n * Defines a commentary that is used in the dataset.\n */\nexport interface DatasetCommentary extends Commentary {\n /**\n * The list of books that are available for the commentary.\n */\n books: DatasetCommentaryBook[];\n\n /**\n * The list of profiles that are available for the commentary.\n */\n profiles: DatasetCommentaryProfile[];\n}\n\n/**\n * Defines a translation book that is used in the dataset.\n */\nexport interface DatasetTranslationBook extends TranslationBook {\n /**\n * The list of chapters that are available for the book.\n */\n chapters: TranslationBookChapter[];\n}\n\n/**\n * Defines a commentary book that is used in the dataset.\n */\nexport interface DatasetCommentaryBook extends CommentaryBook {\n /**\n * The list of chapters that are available for the book.\n */\n chapters: CommentaryBookChapter[];\n}\n\nexport interface DatasetCommentaryProfile extends CommentaryProfile {\n /**\n * The contents of the profile.\n */\n content: string[];\n}\n\nexport interface DatasetDataset extends CommonDataset {\n books: DatasetDatasetBook[];\n}\n\nexport interface DatasetDatasetBook extends DatasetBook {\n chapters: DatasetBookChapter[];\n}\n\n/**\n * Generates a list of output files from the given list of input files.\n * @param file The list of files.\n * @param parser The parser to use for parsing the files.\n * @param bookMap The map of book IDs to names. If undefined, then a default map will be used.\n */\nexport function generateDataset(\n files: InputFile[],\n parser: DOMParser = new globalThis.DOMParser(),\n bookMap?: Map<string, { commonName: string }> | undefined\n): DatasetOutput {\n const logger = getLogger();\n let output: DatasetOutput = {\n translations: [],\n commentaries: [],\n };\n\n let usfmParser = new UsfmParser();\n let usxParser = new USXParser(parser);\n let codexParser = new CodexParser(parser);\n let csvCommentaryParser = new CommentaryCsvParser();\n let tyndaleXmlParser = new TyndaleXmlParser(parser);\n\n let parsedTranslations = new Map<string, DatasetTranslation>();\n let parsedCommentaries = new Map<string, DatasetCommentary>();\n\n const unknownLanguages = new Set<string>();\n for (let file of files) {\n try {\n let parser:\n | UsfmParser\n | USXParser\n | CodexParser\n | CommentaryCsvParser\n | TyndaleXmlParser;\n if (file.fileType === 'usfm') {\n parser = usfmParser;\n } else if (file.fileType === 'usx') {\n parser = usxParser;\n } else if (file.fileType === 'json') {\n parser = codexParser;\n } else if (file.fileType === 'commentary/csv') {\n parser = csvCommentaryParser;\n } else if (file.fileType === 'commentary/tyndale-xml') {\n parser = tyndaleXmlParser;\n } else {\n logger.warn(\n '[generate] File does not have a valid type!',\n file.name\n );\n continue;\n }\n\n const parsed = parser.parse(file.content);\n\n if (\n 'parseMessages' in parsed &&\n parsed.parseMessages &&\n file.name\n ) {\n const messages = (output.parseMessages =\n output.parseMessages || {});\n messages[file.name] = parsed.parseMessages;\n }\n\n if (parsed.type === 'root') {\n addTranslationTree(file as InputTranslationFile, parsed);\n } else {\n addCommentaryTree(file as InputCommentaryFile, parsed);\n }\n } catch (err) {\n logger.error(\n `[generate] Error occurred while parsing ${file.name}`,\n err\n );\n }\n }\n\n function addTranslationTree(file: InputTranslationFile, parsed: ParseTree) {\n const id = parsed.id;\n\n if (!id) {\n logger.warn(\n '[generate] File does not have a valid book ID!',\n file.name,\n id\n );\n return;\n }\n\n const order = bookOrderMap.get(id);\n\n if (typeof order !== 'number') {\n logger.warn('[generate] Book does not have an order!', id);\n return;\n }\n\n const isApocryphal = apocryphaBooks.has(id);\n\n const bookName = getBookNames(file, file.metadata, id);\n\n let translation = parsedTranslations.get(file.metadata.id);\n\n if (!translation) {\n translation = {\n ...omit(file.metadata, 'direction'),\n textDirection: file.metadata.direction,\n books: [],\n };\n output.translations.push(translation);\n parsedTranslations.set(file.metadata.id, translation);\n }\n\n const name =\n parsed.header ??\n (bookName?.exactMatch ? bookName?.bookName?.commonName : null) ??\n parsed.title ??\n bookName?.bookName?.commonName;\n\n if (!name) {\n logger.warn('[generate] Book does not have a name!', file.name, id);\n return;\n }\n\n const commonName =\n (bookName?.exactMatch ? bookName?.bookName?.commonName : null) ??\n parsed.header ??\n parsed.title ??\n bookName?.bookName?.commonName ??\n id;\n\n const book: DatasetTranslationBook = {\n id: id,\n name,\n commonName,\n title: parsed.title ?? null,\n order,\n chapters: [],\n };\n\n if (isApocryphal) {\n book.isApocryphal = true;\n }\n\n for (let content of parsed.content) {\n if (content.type === 'chapter') {\n book.chapters.push({\n chapter: {\n number: content.number,\n content: content.content,\n footnotes: content.footnotes,\n },\n thisChapterAudioLinks: getAudioUrlsForChapter(\n translation.id,\n id,\n content.number\n ),\n });\n }\n }\n\n book.chapters = sortBy(book.chapters, (c) => c.chapter.number);\n\n const index = sortedIndexBy(translation.books, book, (b) => b.order);\n translation.books.splice(index, 0, book);\n }\n\n function addCommentaryTree(\n file: InputCommentaryFile,\n parsed: CommentaryParseTree\n ) {\n let commentary = parsedCommentaries.get(file.metadata.id);\n\n if (!commentary) {\n commentary = {\n ...omit(file.metadata, 'direction'),\n textDirection: file.metadata.direction,\n books: [],\n profiles: [],\n };\n output.commentaries.push(commentary);\n parsedCommentaries.set(file.metadata.id, commentary);\n }\n\n for (let parsedBook of parsed.books) {\n let book = commentary.books.find((b) => b.id === parsedBook.book);\n if (book && book.introduction && parsedBook.introduction) {\n logger.warn(\n '[generate] Book already exists in commentary!',\n file.name,\n parsedBook.book\n );\n continue;\n }\n\n if (!book) {\n const name = getBookNames(file, file.metadata, parsedBook.book);\n book = {\n id: parsedBook.book,\n order: bookOrderMap.get(parsedBook.book) ?? -1,\n commonName: name?.bookName?.commonName ?? parsedBook.book,\n name: name?.bookName?.commonName ?? parsedBook.book,\n chapters: [],\n };\n }\n\n if (parsedBook.introduction) {\n book.introduction = parsedBook.introduction;\n }\n\n if (parsedBook.introductionSummary && !book.introductionSummary) {\n book.introductionSummary = parsedBook.introductionSummary;\n }\n\n for (let chapter of parsedBook.chapters) {\n let data: CommentaryChapterData = {\n number: chapter.number,\n content: chapter.verses,\n };\n\n if (chapter.introduction) {\n data.introduction = chapter.introduction;\n }\n\n book.chapters.push({\n chapter: data,\n });\n }\n\n book.chapters = sortBy(book.chapters, (c) => c.chapter.number);\n commentary.books.push(book);\n }\n\n if (parsed.profiles) {\n for (let profile of parsed.profiles) {\n const existing = commentary.profiles.find(\n (p) => p.id === profile.id\n );\n if (existing) {\n logger.warn(\n '[generate] Profile already exists in commentary!',\n file.name,\n profile.id\n );\n continue;\n }\n\n const datasetProfile: DatasetCommentaryProfile = {\n id: profile.id,\n subject: profile.subject,\n reference: profile.reference,\n content: profile.content,\n };\n\n commentary.profiles.push(datasetProfile);\n }\n }\n\n commentary.books = sortBy(commentary.books, (b) => b.order);\n commentary.profiles = sortBy(commentary.profiles, (p) => p.id);\n }\n\n function getBookNames(\n file: InputFileBase,\n metadata: MetadataBase,\n id: string\n ) {\n let exactMatch = true;\n let map = bookMap;\n if (!map) {\n map = defaultBookIdMap.get(metadata.language);\n\n if (!map) {\n if (!unknownLanguages.has(metadata.language)) {\n logger.warn(\n '[generate] File does not have a known language!',\n file.name,\n metadata.language\n );\n unknownLanguages.add(metadata.language);\n }\n\n logger.warn(\n '[generate] Using English book map for unknown language! This might result in outputting english book names.'\n );\n exactMatch = false;\n map = defaultBookIdMap.get('en');\n }\n }\n\n const bookName = map?.get(id);\n\n if (!!map && !bookName) {\n logger.warn(\n '[generate] Book name not found for ID!',\n file.name,\n id\n );\n return null;\n }\n\n return {\n exactMatch,\n bookName,\n };\n }\n\n return output;\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAA2B;AAC3B,wBAA0B;AAmB1B,wBAIO;AACP,oBAA4C;AAC5C,mBAAuC;AACvC,0BAA4B;AAC5B,mCAAoC;AAMpC,gCAAiC;AACjC,iBAA0B;AA4FnB,SAAS,gBACZ,OACA,SAAoB,IAAI,WAAW,UAAU,GAC7C,SACa;AACb,QAAM,aAAS,sBAAU;AACzB,MAAI,SAAwB;AAAA,IACxB,cAAc,CAAC;AAAA,IACf,cAAc,CAAC;AAAA,EACnB;AAEA,MAAI,aAAa,IAAI,8BAAW;AAChC,MAAI,YAAY,IAAI,4BAAU,MAAM;AACpC,MAAI,cAAc,IAAI,gCAAY,MAAM;AACxC,MAAI,sBAAsB,IAAI,iDAAoB;AAClD,MAAI,mBAAmB,IAAI,2CAAiB,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AAW,KAAK,IAAI,EAAE;AAE5B,QAAI,CAAC,CAAC,OAAO,CAAC,UAAU;AACpB,aAAO;AAAA,QACH;AAAA,QACA,KAAK;AAAA,QACL;AAAA,MACJ;AACA,aAAO;AAAA,IACX;AAEA,WAAO;AAAA,MACH;AAAA,MACA;AAAA,IACJ;AAAA,EACJ;AAEA,SAAO;AACX;",
4
+ "sourcesContent": ["import { UsfmParser } from '../parser/usfm-parser.js';\r\nimport { USXParser } from '../parser/usx-parser.js';\r\nimport {\r\n Commentary,\r\n CommentaryBook,\r\n CommentaryBookChapter,\r\n CommentaryChapterData,\r\n CommentaryProfile,\r\n InputCommentaryFile,\r\n InputFile,\r\n InputFileBase,\r\n InputTranslationFile,\r\n MetadataBase,\r\n Translation,\r\n TranslationBook,\r\n TranslationBookChapter,\r\n Dataset as CommonDataset,\r\n DatasetBook,\r\n DatasetBookChapter,\r\n} from './common-types.js';\r\nimport {\r\n bookIdMap as defaultBookIdMap,\r\n bookOrderMap,\r\n apocryphaBooks,\r\n} from './book-order.js';\r\nimport { omit, sortBy, sortedIndexBy } from 'lodash';\r\nimport { getAudioUrlsForChapter } from './audio.js';\r\nimport { CodexParser } from '../parser/codex-parser.js';\r\nimport { CommentaryCsvParser } from '../parser/commentary-csv-parser.js';\r\nimport {\r\n CommentaryParseTree,\r\n ParseMessage,\r\n ParseTree,\r\n} from '../parser/types.js';\r\nimport { TyndaleXmlParser } from '../parser/tyndale-xml-parser.js';\r\nimport { getLogger } from '../log.js';\r\nimport { LockmanParser } from '../parser/lockman-parser.js';\r\nimport { BookId } from '../utils.js';\r\n\r\nexport const DATASET_VERSION = 1;\r\n\r\n/**\r\n * Defines an interface that contains generated dataset info.\r\n */\r\nexport interface DatasetOutput {\r\n /**\r\n * The list of translations that are available in the dataset.\r\n */\r\n translations: DatasetTranslation[];\r\n\r\n /**\r\n * The list of commentaries that are available in the dataset.\r\n */\r\n commentaries: DatasetCommentary[];\r\n\r\n /**\r\n * The list of datasets that are available in the dataset.\r\n */\r\n datasets?: DatasetDataset[];\r\n\r\n parseMessages?: {\r\n [key: string]: ParseMessage[];\r\n };\r\n}\r\n\r\n/**\r\n * Defines a translation that is used in the dataset.\r\n */\r\nexport interface DatasetTranslation extends Translation {\r\n /**\r\n * The list of books that are available for the translation.\r\n */\r\n books: DatasetTranslationBook[];\r\n}\r\n\r\n/**\r\n * Defines a commentary that is used in the dataset.\r\n */\r\nexport interface DatasetCommentary extends Commentary {\r\n /**\r\n * The list of books that are available for the commentary.\r\n */\r\n books: DatasetCommentaryBook[];\r\n\r\n /**\r\n * The list of profiles that are available for the commentary.\r\n */\r\n profiles: DatasetCommentaryProfile[];\r\n}\r\n\r\n/**\r\n * Defines a translation book that is used in the dataset.\r\n */\r\nexport interface DatasetTranslationBook extends TranslationBook {\r\n /**\r\n * The list of chapters that are available for the book.\r\n */\r\n chapters: TranslationBookChapter[];\r\n}\r\n\r\n/**\r\n * Defines a commentary book that is used in the dataset.\r\n */\r\nexport interface DatasetCommentaryBook extends CommentaryBook {\r\n /**\r\n * The list of chapters that are available for the book.\r\n */\r\n chapters: CommentaryBookChapter[];\r\n}\r\n\r\nexport interface DatasetCommentaryProfile extends CommentaryProfile {\r\n /**\r\n * The contents of the profile.\r\n */\r\n content: string[];\r\n}\r\n\r\nexport interface DatasetDataset extends CommonDataset {\r\n books: DatasetDatasetBook[];\r\n}\r\n\r\nexport interface DatasetDatasetBook extends DatasetBook {\r\n chapters: DatasetBookChapter[];\r\n}\r\n\r\n/**\r\n * Generates a list of output files from the given list of input files.\r\n * @param file The list of files.\r\n * @param parser The parser to use for parsing the files.\r\n * @param bookMap The map of book IDs to names. If undefined, then a default map will be used.\r\n */\r\nexport function generateDataset(\r\n files: InputFile[],\r\n parser: DOMParser = new globalThis.DOMParser(),\r\n bookMap?: Map<string, { commonName: string }> | undefined\r\n): DatasetOutput {\r\n const logger = getLogger();\r\n let output: DatasetOutput = {\r\n translations: [],\r\n commentaries: [],\r\n };\r\n\r\n let usfmParser = new UsfmParser();\r\n let usxParser = new USXParser(parser);\r\n let codexParser = new CodexParser(parser);\r\n let csvCommentaryParser = new CommentaryCsvParser();\r\n let tyndaleXmlParser = new TyndaleXmlParser(parser);\r\n let lockmanParser = new LockmanParser();\r\n\r\n let parsedTranslations = new Map<string, DatasetTranslation>();\r\n let parsedCommentaries = new Map<string, DatasetCommentary>();\r\n\r\n const unknownLanguages = new Set<string>();\r\n for (let file of files) {\r\n try {\r\n let parser:\r\n | UsfmParser\r\n | USXParser\r\n | CodexParser\r\n | CommentaryCsvParser\r\n | TyndaleXmlParser\r\n | LockmanParser;\r\n if (file.fileType === 'usfm') {\r\n parser = usfmParser;\r\n } else if (file.fileType === 'usx') {\r\n parser = usxParser;\r\n } else if (file.fileType === 'json') {\r\n parser = codexParser;\r\n } else if (file.fileType === 'commentary/csv') {\r\n parser = csvCommentaryParser;\r\n } else if (file.fileType === 'commentary/tyndale-xml') {\r\n parser = tyndaleXmlParser;\r\n } else if (file.fileType === 'lockman') {\r\n parser = lockmanParser;\r\n } else {\r\n logger.warn(\r\n '[generate] File does not have a valid type!',\r\n file.name\r\n );\r\n continue;\r\n }\r\n\r\n const parsed:\r\n | ParseTree\r\n | CommentaryParseTree\r\n | (ParseTree | CommentaryParseTree)[] = parser.parse(\r\n file.content\r\n );\r\n\r\n if (Array.isArray(parsed)) {\r\n for (let p of parsed) {\r\n logParseMessages(p, file);\r\n if (p.type === 'root') {\r\n addTranslationTree(file as InputTranslationFile, p);\r\n } else {\r\n addCommentaryTree(file as InputCommentaryFile, p);\r\n }\r\n }\r\n } else {\r\n logParseMessages(parsed, file);\r\n if (parsed.type === 'root') {\r\n addTranslationTree(file as InputTranslationFile, parsed);\r\n } else {\r\n addCommentaryTree(file as InputCommentaryFile, parsed);\r\n }\r\n }\r\n } catch (err) {\r\n logger.error(\r\n `[generate] Error occurred while parsing ${file.name}`,\r\n err\r\n );\r\n }\r\n }\r\n\r\n function logParseMessages(\r\n parsed: ParseTree | CommentaryParseTree,\r\n file: InputFile\r\n ) {\r\n if ('parseMessages' in parsed && parsed.parseMessages && file.name) {\r\n const messages = (output.parseMessages =\r\n output.parseMessages || {});\r\n messages[file.name] = parsed.parseMessages;\r\n }\r\n }\r\n\r\n function addTranslationTree(file: InputTranslationFile, parsed: ParseTree) {\r\n const id = parsed.id;\r\n\r\n if (!id) {\r\n logger.warn(\r\n '[generate] File does not have a valid book ID!',\r\n file.name,\r\n id\r\n );\r\n return;\r\n }\r\n\r\n const order = bookOrderMap.get(id);\r\n\r\n if (typeof order !== 'number') {\r\n logger.warn('[generate] Book does not have an order!', id);\r\n return;\r\n }\r\n\r\n const isApocryphal = apocryphaBooks.has(id);\r\n\r\n const bookName = getBookNames(file, file.metadata, id);\r\n\r\n let translation = parsedTranslations.get(file.metadata.id);\r\n\r\n if (!translation) {\r\n translation = {\r\n ...omit(file.metadata, 'direction'),\r\n textDirection: file.metadata.direction,\r\n books: [],\r\n };\r\n output.translations.push(translation);\r\n parsedTranslations.set(file.metadata.id, translation);\r\n }\r\n\r\n const name =\r\n parsed.header ??\r\n (bookName?.exactMatch ? bookName?.bookName?.commonName : null) ??\r\n parsed.title ??\r\n bookName?.bookName?.commonName;\r\n\r\n if (!name) {\r\n logger.warn('[generate] Book does not have a name!', file.name, id);\r\n return;\r\n }\r\n\r\n const commonName =\r\n (bookName?.exactMatch ? bookName?.bookName?.commonName : null) ??\r\n parsed.header ??\r\n parsed.title ??\r\n bookName?.bookName?.commonName ??\r\n id;\r\n\r\n const book: DatasetTranslationBook = {\r\n id: id as BookId,\r\n name,\r\n commonName,\r\n title: parsed.title ?? null,\r\n order,\r\n chapters: [],\r\n };\r\n\r\n if (isApocryphal) {\r\n book.isApocryphal = true;\r\n }\r\n\r\n for (let content of parsed.content) {\r\n if (content.type === 'chapter') {\r\n book.chapters.push({\r\n chapter: {\r\n number: content.number,\r\n content: content.content,\r\n footnotes: content.footnotes,\r\n },\r\n thisChapterAudioLinks: getAudioUrlsForChapter(\r\n translation.id,\r\n id,\r\n content.number\r\n ),\r\n });\r\n }\r\n }\r\n\r\n book.chapters = sortBy(book.chapters, (c) => c.chapter.number);\r\n\r\n const index = sortedIndexBy(translation.books, book, (b) => b.order);\r\n translation.books.splice(index, 0, book);\r\n }\r\n\r\n function addCommentaryTree(\r\n file: InputCommentaryFile,\r\n parsed: CommentaryParseTree\r\n ) {\r\n let commentary = parsedCommentaries.get(file.metadata.id);\r\n\r\n if (!commentary) {\r\n commentary = {\r\n ...omit(file.metadata, 'direction'),\r\n textDirection: file.metadata.direction,\r\n books: [],\r\n profiles: [],\r\n };\r\n output.commentaries.push(commentary);\r\n parsedCommentaries.set(file.metadata.id, commentary);\r\n }\r\n\r\n for (let parsedBook of parsed.books) {\r\n let book = commentary.books.find((b) => b.id === parsedBook.book);\r\n if (book && book.introduction && parsedBook.introduction) {\r\n logger.warn(\r\n '[generate] Book already exists in commentary!',\r\n file.name,\r\n parsedBook.book\r\n );\r\n continue;\r\n }\r\n\r\n if (!book) {\r\n const name = getBookNames(file, file.metadata, parsedBook.book);\r\n book = {\r\n id: parsedBook.book as BookId,\r\n order: bookOrderMap.get(parsedBook.book) ?? -1,\r\n commonName: name?.bookName?.commonName ?? parsedBook.book,\r\n name: name?.bookName?.commonName ?? parsedBook.book,\r\n chapters: [],\r\n };\r\n }\r\n\r\n if (parsedBook.introduction) {\r\n book.introduction = parsedBook.introduction;\r\n }\r\n\r\n if (parsedBook.introductionSummary && !book.introductionSummary) {\r\n book.introductionSummary = parsedBook.introductionSummary;\r\n }\r\n\r\n for (let chapter of parsedBook.chapters) {\r\n let data: CommentaryChapterData = {\r\n number: chapter.number,\r\n content: chapter.verses,\r\n };\r\n\r\n if (chapter.introduction) {\r\n data.introduction = chapter.introduction;\r\n }\r\n\r\n book.chapters.push({\r\n chapter: data,\r\n });\r\n }\r\n\r\n book.chapters = sortBy(book.chapters, (c) => c.chapter.number);\r\n commentary.books.push(book);\r\n }\r\n\r\n if (parsed.profiles) {\r\n for (let profile of parsed.profiles) {\r\n const existing = commentary.profiles.find(\r\n (p) => p.id === profile.id\r\n );\r\n if (existing) {\r\n logger.warn(\r\n '[generate] Profile already exists in commentary!',\r\n file.name,\r\n profile.id\r\n );\r\n continue;\r\n }\r\n\r\n const datasetProfile: DatasetCommentaryProfile = {\r\n id: profile.id,\r\n subject: profile.subject,\r\n reference: profile.reference,\r\n content: profile.content,\r\n };\r\n\r\n commentary.profiles.push(datasetProfile);\r\n }\r\n }\r\n\r\n commentary.books = sortBy(commentary.books, (b) => b.order);\r\n commentary.profiles = sortBy(commentary.profiles, (p) => p.id);\r\n }\r\n\r\n function getBookNames(\r\n file: InputFileBase,\r\n metadata: MetadataBase,\r\n id: string\r\n ) {\r\n let exactMatch = true;\r\n let map = bookMap;\r\n if (!map) {\r\n map = defaultBookIdMap.get(metadata.language);\r\n\r\n if (!map) {\r\n if (!unknownLanguages.has(metadata.language)) {\r\n logger.warn(\r\n '[generate] File does not have a known language!',\r\n file.name,\r\n metadata.language\r\n );\r\n unknownLanguages.add(metadata.language);\r\n }\r\n\r\n logger.warn(\r\n '[generate] Using English book map for unknown language! This might result in outputting english book names.'\r\n );\r\n exactMatch = false;\r\n map = defaultBookIdMap.get('en');\r\n }\r\n }\r\n\r\n const bookName = map?.get(id);\r\n\r\n if (!!map && !bookName) {\r\n logger.warn(\r\n '[generate] Book name not found for ID!',\r\n file.name,\r\n id\r\n );\r\n return null;\r\n }\r\n\r\n return {\r\n exactMatch,\r\n bookName,\r\n };\r\n }\r\n\r\n return output;\r\n}\r\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAA2B;AAC3B,wBAA0B;AAmB1B,wBAIO;AACP,oBAA4C;AAC5C,mBAAuC;AACvC,0BAA4B;AAC5B,mCAAoC;AAMpC,gCAAiC;AACjC,iBAA0B;AAC1B,4BAA8B;AAGvB,MAAM,kBAAkB;AA4FxB,SAAS,gBACZ,OACA,SAAoB,IAAI,WA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Z,SAAS,QAAQ;AAAA,UACjB,WAAW,QAAQ;AAAA,UACnB,SAAS,QAAQ;AAAA,QACrB;AAEA,mBAAW,SAAS,KAAK,cAAc;AAAA,MAC3C;AAAA,IACJ;AAEA,eAAW,YAAQ,sBAAO,WAAW,OAAO,CAAC,MAAM,EAAE,KAAK;AAC1D,eAAW,eAAW,sBAAO,WAAW,UAAU,CAAC,MAAM,EAAE,EAAE;AAAA,EACjE;AAEA,WAAS,aACL,MACA,UACA,IACF;AACE,QAAI,aAAa;AACjB,QAAI,MAAM;AACV,QAAI,CAAC,KAAK;AACN,YAAM,kBAAAC,UAAiB,IAAI,SAAS,QAAQ;AAE5C,UAAI,CAAC,KAAK;AACN,YAAI,CAAC,iBAAiB,IAAI,SAAS,QAAQ,GAAG;AAC1C,iBAAO;AAAA,YACH;AAAA,YACA,KAAK;AAAA,YACL,SAAS;AAAA,UACb;AACA,2BAAiB,IAAI,SAAS,QAAQ;AAAA,QAC1C;AAEA,eAAO;AAAA,UACH;AAAA,QACJ;AACA,qBAAa;AACb,cAAM,kBAAAA,UAAiB,IAAI,IAAI;AAAA,MACnC;AAAA,IACJ;AAEA,UAAM,WAAW,KAAK,IAAI,EAAE;AAE5B,QAAI,CAAC,CAAC,OAAO,CAAC,UAAU;AACpB,aAAO;AAAA,QACH;AAAA,QACA,KAAK;AAAA,QACL;AAAA,MACJ;AACA,aAAO;AAAA,IACX;AAEA,WAAO;AAAA,MACH;AAAA,MACA;AAAA,IACJ;AAAA,EACJ;AAEA,SAAO;AACX;",
6
6
  "names": ["parser", "defaultBookIdMap"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../index.ts"],
4
- "sourcesContent": ["import * as utils from './utils.js';\nimport * as generation from './generation/index.js';\nimport * as parser from './parser/index.js';\nimport * as log from './log.js';\n\nexport { utils, generation, parser, log };\n"],
4
+ "sourcesContent": ["import * as utils from './utils.js';\r\nimport * as generation from './generation/index.js';\r\nimport * as parser from './parser/index.js';\r\nimport * as log from './log.js';\r\n\r\nexport { utils, generation, parser, log };\r\n"],
5
5
  "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,YAAuB;AACvB,iBAA4B;AAC5B,aAAwB;AACxB,UAAqB;",
6
6
  "names": []
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../log.ts"],
4
- "sourcesContent": ["/**\n * A simple logging interface that can be used to log messages.\n */\nexport interface Logger {\n log: (message: any, ...args: any[]) => void;\n warn: (message: string, ...args: any[]) => void;\n error: (message: string, ...args: any[]) => void;\n}\n\n/**\n * A logger that logs messages to the console.\n */\nexport const consoleLogger: Logger = {\n log: (message: string, ...args) => {\n console.log(message, ...args);\n },\n warn: (message: string, ...args) => {\n console.warn(message, ...args);\n },\n error: (message: string, ...args) => {\n console.error(message, ...args);\n },\n};\n\n/**\n * The logger that should be used for logging messages.\n */\nlet logger: Logger = consoleLogger;\n\n/**\n * Gets the logger that is currently being used for logging messages.\n * @returns The logger that is currently being used.\n */\nexport function getLogger(): Logger {\n return logger;\n}\n\n/**\n * Sets the logger to use for logging messages.\n * @param newLogger The new logger to use.\n */\nexport function setLogger(newLogger: Logger) {\n logger = newLogger;\n}\n"],
4
+ "sourcesContent": ["/**\r\n * A simple logging interface that can be used to log messages.\r\n */\r\nexport interface Logger {\r\n log: (message: any, ...args: any[]) => void;\r\n warn: (message: string, ...args: any[]) => void;\r\n error: (message: string, ...args: any[]) => void;\r\n}\r\n\r\n/**\r\n * A logger that logs messages to the console.\r\n */\r\nexport const consoleLogger: Logger = {\r\n log: (message: string, ...args) => {\r\n console.log(message, ...args);\r\n },\r\n warn: (message: string, ...args) => {\r\n console.warn(message, ...args);\r\n },\r\n error: (message: string, ...args) => {\r\n console.error(message, ...args);\r\n },\r\n};\r\n\r\n/**\r\n * The logger that should be used for logging messages.\r\n */\r\nlet logger: Logger = consoleLogger;\r\n\r\n/**\r\n * Gets the logger that is currently being used for logging messages.\r\n * @returns The logger that is currently being used.\r\n */\r\nexport function getLogger(): Logger {\r\n return logger;\r\n}\r\n\r\n/**\r\n * Sets the logger to use for logging messages.\r\n * @param newLogger The new logger to use.\r\n */\r\nexport function setLogger(newLogger: Logger) {\r\n logger = newLogger;\r\n}\r\n"],
5
5
  "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAYO,MAAM,gBAAwB;AAAA,EACjC,KAAK,CAAC,YAAoB,SAAS;AAC/B,YAAQ,IAAI,SAAS,GAAG,IAAI;AAAA,EAChC;AAAA,EACA,MAAM,CAAC,YAAoB,SAAS;AAChC,YAAQ,KAAK,SAAS,GAAG,IAAI;AAAA,EACjC;AAAA,EACA,OAAO,CAAC,YAAoB,SAAS;AACjC,YAAQ,MAAM,SAAS,GAAG,IAAI;AAAA,EAClC;AACJ;AAKA,IAAI,SAAiB;AAMd,SAAS,YAAoB;AAChC,SAAO;AACX;AAMO,SAAS,UAAU,WAAmB;AACzC,WAAS;AACb;",
6
6
  "names": []
7
7
  }
@@ -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 { 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 data: z\n .object({\n globalReferences: z.array(z.string()).optional(),\n })\n .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 private _parser: DOMParser;\n\n constructor(parser: DOMParser) {\n this._parser = parser;\n }\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 ensureChapter(chapterNumber: number) {\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 return chapter;\n }\n\n function getDocumentContent(doc: Document): string {\n let content = '';\n for (let element of doc.childNodes) {\n content += element.textContent;\n }\n return content;\n }\n\n function addChapterContent(\n chapterNumber: number,\n content: ChapterContent[]\n ) {\n const chapter = ensureChapter(chapterNumber);\n chapter.content.push(...content);\n }\n\n function addChapterFootnote(\n chapterNumber: number,\n footnote: Chapter['footnotes'][0]\n ) {\n const chapter = ensureChapter(chapterNumber);\n chapter.footnotes.push(footnote);\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 (typeof current === 'string' && current.trim() === '') {\n return prev; // skip empty lines\n }\n if (prev.length === 0) {\n return [current];\n } else {\n return [\n ...prev,\n {\n lineBreak: true,\n },\n current,\n ] satisfies Verse['content'];\n }\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 if (metadata.data?.globalReferences?.length) {\n reference = parseVerseReference(\n metadata.data.globalReferences[0]\n );\n if (!reference) {\n throw new Error(\n 'Could not find verse reference in globalReferences 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 doc = this._parser.parseFromString(\n cell.value,\n 'text/html'\n );\n\n for (let element of doc.children) {\n const allFootnotes = element.querySelectorAll(\n 'sup.footnote-marker[data-footnote]'\n );\n for (const footnote of allFootnotes) {\n const footnoteData =\n footnote.getAttribute('data-footnote');\n if (footnoteData) {\n const footnoteDoc =\n this._parser.parseFromString(\n footnoteData,\n 'text/html'\n );\n const footnoteText =\n getDocumentContent(footnoteDoc);\n if (footnoteText) {\n addChapterFootnote(reference.chapter, {\n noteId: this._noteCounter++,\n text: footnoteText,\n caller: null,\n });\n }\n }\n footnote.remove();\n }\n }\n\n const content = getDocumentContent(doc);\n\n if (content) {\n // add line breaks in heading if there are multiple lines\n const newLines = content.split('\\n');\n\n lines.push(...newLines);\n }\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 doc = this._parser.parseFromString(\n cell.value,\n 'text/html'\n );\n const content = getDocumentContent(doc);\n\n if (!content) {\n continue;\n }\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 const doc = this._parser.parseFromString(\n cell.value,\n 'text/html'\n );\n const content = getDocumentContent(doc);\n // parse paratext that isn't a chapter reference as footnote\n // const content = stripHTML(cell.value);\n if (content && !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"],
4
+ "sourcesContent": ["import { z } from 'zod';\r\nimport {\r\n Chapter,\r\n ChapterContent,\r\n ParseTree,\r\n Verse,\r\n VerseContent,\r\n} from './types.js';\r\nimport { getBookId, parseVerseReference, VerseRef } from '../utils.js';\r\nimport { ref } from 'process';\r\n\r\nexport const chapterHeadingSchema = z.object({\r\n type: z.literal('chapter-heading'),\r\n data: z.object({\r\n chapter: z.coerce.number().int(),\r\n }),\r\n});\r\n\r\nexport const verseSchema = z.object({\r\n type: z.literal('text'),\r\n id: z.string(),\r\n bookCode: z.string().optional(),\r\n chapter: z.number().optional(),\r\n verse: z.number().optional(),\r\n data: z\r\n .object({\r\n globalReferences: z.array(z.string()).optional(),\r\n })\r\n .optional(),\r\n});\r\n\r\nexport const paratextSchema = z.object({\r\n type: z.literal('paratext'),\r\n id: z.string(),\r\n});\r\n\r\nexport const metadataSchema = z.discriminatedUnion('type', [\r\n chapterHeadingSchema,\r\n verseSchema,\r\n paratextSchema,\r\n]);\r\n\r\nexport const codexSchema = z.object({\r\n cells: z.array(\r\n z.object({\r\n kind: z.number(),\r\n languageId: z.string(),\r\n value: z.string(),\r\n metadata: z\r\n .object({\r\n type: z.string(),\r\n })\r\n .passthrough()\r\n .nullable()\r\n .optional(),\r\n })\r\n ),\r\n});\r\n\r\n/**\r\n * Defines a parser for codex files.\r\n */\r\nexport class CodexParser {\r\n // TODO:\r\n // /**\r\n // * Whether to preserve markdown in the parsed content.\r\n // */\r\n // preserveMarkdown: boolean = true;\r\n\r\n private _noteCounter: number = 0;\r\n\r\n private _parser: DOMParser;\r\n\r\n constructor(parser: DOMParser) {\r\n this._parser = parser;\r\n }\r\n\r\n /**\r\n * Parses the specified codex content.\r\n *\r\n * @param codex The codex content to parse.\r\n * @returns The parse tree that was generated.\r\n */\r\n public parse(codex: string): ParseTree {\r\n const json = JSON.parse(codex);\r\n const data = codexSchema.parse(json);\r\n\r\n let root: ParseTree = {\r\n type: 'root',\r\n content: [],\r\n };\r\n\r\n let chapters: Map<number, Chapter> = new Map();\r\n let lastChapter: Chapter | null = null;\r\n\r\n function ensureChapter(chapterNumber: number) {\r\n let chapter = chapters.get(chapterNumber);\r\n if (!chapter) {\r\n chapter = {\r\n type: 'chapter',\r\n number: chapterNumber,\r\n content: [],\r\n footnotes: [],\r\n };\r\n lastChapter = chapter;\r\n chapters.set(chapterNumber, chapter);\r\n }\r\n\r\n return chapter;\r\n }\r\n\r\n function getDocumentContent(doc: Document): string {\r\n let content = '';\r\n for (let element of doc.childNodes) {\r\n content += element.textContent;\r\n }\r\n return content;\r\n }\r\n\r\n function addChapterContent(\r\n chapterNumber: number,\r\n content: ChapterContent[]\r\n ) {\r\n const chapter = ensureChapter(chapterNumber);\r\n chapter.content.push(...content);\r\n }\r\n\r\n function addChapterFootnote(\r\n chapterNumber: number,\r\n footnote: Chapter['footnotes'][0]\r\n ) {\r\n const chapter = ensureChapter(chapterNumber);\r\n chapter.footnotes.push(footnote);\r\n }\r\n\r\n function addReference(ref: VerseRef, content: Verse['content']) {\r\n addChapterContent(ref.chapter, [\r\n {\r\n type: 'verse',\r\n number: ref.verse,\r\n content: content,\r\n },\r\n ]);\r\n }\r\n\r\n function stripHTML(value: string) {\r\n return value.replace(/<[^>]*>/g, '');\r\n }\r\n\r\n function toHeading(content: string) {\r\n return {\r\n type: 'heading',\r\n content: [content],\r\n } satisfies ChapterContent;\r\n }\r\n\r\n function addLineBreaks(lines: Verse['content']) {\r\n return lines.reduce(\r\n (prev, current) => {\r\n if (typeof current === 'string' && current.trim() === '') {\r\n return prev; // skip empty lines\r\n }\r\n if (prev.length === 0) {\r\n return [current];\r\n } else {\r\n return [\r\n ...prev,\r\n {\r\n lineBreak: true,\r\n },\r\n current,\r\n ] satisfies Verse['content'];\r\n }\r\n },\r\n [] as Verse['content']\r\n );\r\n }\r\n\r\n let previousReference: VerseRef | null = null;\r\n let lines: Verse['content'] = [];\r\n\r\n for (let cell of data.cells) {\r\n if (cell.languageId === 'html' && cell.value) {\r\n if (!cell.metadata) continue; // ignore html cells without metadata\r\n\r\n const metadataResult = metadataSchema.safeParse(cell.metadata);\r\n\r\n if (!metadataResult.success) continue; // ignore cells with invalid/unknown metadata\r\n const metadata = metadataResult.data;\r\n if (metadata.type === 'text') {\r\n let reference = parseVerseReference(metadata.id);\r\n if (!reference) {\r\n if (metadata.bookCode && metadata.chapter) {\r\n const bookId = getBookId(metadata.bookCode);\r\n if (!bookId) {\r\n throw new Error(\r\n 'Could not find book ID for code: ' +\r\n metadata.bookCode\r\n );\r\n }\r\n\r\n if (metadata.verse) {\r\n reference = {\r\n book: bookId,\r\n chapter: metadata.chapter,\r\n verse: metadata.verse,\r\n };\r\n } else if (previousReference?.verse) {\r\n if (\r\n previousReference.chapter !==\r\n metadata.chapter ||\r\n previousReference.book !== bookId\r\n ) {\r\n throw new Error(\r\n 'Cannot infer verse number for non-consecutive verse reference.'\r\n );\r\n }\r\n\r\n // Sometimes codex doesn't include verse numbers for every cell, so we infer it from the previous reference\r\n reference = {\r\n book: bookId,\r\n chapter: metadata.chapter,\r\n verse: previousReference.verse,\r\n };\r\n } else {\r\n throw new Error(\r\n 'Could not find verse reference in metadata.'\r\n );\r\n }\r\n } else if (metadata.data?.globalReferences?.length) {\r\n reference = parseVerseReference(\r\n metadata.data.globalReferences[0]\r\n );\r\n if (!reference) {\r\n throw new Error(\r\n 'Could not find verse reference in globalReferences metadata.'\r\n );\r\n }\r\n } else {\r\n throw new Error(\r\n 'Could not find verse reference in metadata.'\r\n );\r\n }\r\n }\r\n\r\n if (\r\n previousReference &&\r\n (reference.book !== previousReference.book ||\r\n reference.chapter !== previousReference.chapter ||\r\n reference.verse !== previousReference.verse)\r\n ) {\r\n addReference(previousReference, addLineBreaks(lines));\r\n lines = [];\r\n }\r\n\r\n previousReference = reference;\r\n\r\n if (!root.id) root.id = reference.book; // set book id if not already set\r\n\r\n const doc = this._parser.parseFromString(\r\n cell.value,\r\n 'text/html'\r\n );\r\n\r\n for (let element of doc.children) {\r\n const allFootnotes = element.querySelectorAll(\r\n 'sup.footnote-marker[data-footnote]'\r\n );\r\n for (const footnote of allFootnotes) {\r\n const footnoteData =\r\n footnote.getAttribute('data-footnote');\r\n if (footnoteData) {\r\n const footnoteDoc =\r\n this._parser.parseFromString(\r\n footnoteData,\r\n 'text/html'\r\n );\r\n const footnoteText =\r\n getDocumentContent(footnoteDoc);\r\n if (footnoteText) {\r\n addChapterFootnote(reference.chapter, {\r\n noteId: this._noteCounter++,\r\n text: footnoteText,\r\n caller: null,\r\n });\r\n }\r\n }\r\n footnote.remove();\r\n }\r\n }\r\n\r\n const content = getDocumentContent(doc);\r\n\r\n if (content) {\r\n // add line breaks in heading if there are multiple lines\r\n const newLines = content.split('\\n');\r\n\r\n lines.push(...newLines);\r\n }\r\n } else if (metadata.type === 'paratext') {\r\n const reference = parseVerseReference(`${metadata.id}:1`); // chapter headings do not have a verse reference always default to 1\r\n if (reference) {\r\n const doc = this._parser.parseFromString(\r\n cell.value,\r\n 'text/html'\r\n );\r\n const content = getDocumentContent(doc);\r\n\r\n if (!content) {\r\n continue;\r\n }\r\n\r\n // add line breaks in heading if there are multiple lines\r\n const lines = content\r\n .split('\\n')\r\n .reduce<ChapterContent[]>((prev, current) => {\r\n if (prev.length === 0)\r\n return [toHeading(current)];\r\n else\r\n return [\r\n ...prev,\r\n {\r\n type: 'line_break',\r\n },\r\n toHeading(current),\r\n ] satisfies ChapterContent[];\r\n }, []);\r\n\r\n lines.forEach((line) =>\r\n addChapterContent(reference.chapter, [line])\r\n );\r\n } else {\r\n const doc = this._parser.parseFromString(\r\n cell.value,\r\n 'text/html'\r\n );\r\n const content = getDocumentContent(doc);\r\n // parse paratext that isn't a chapter reference as footnote\r\n // const content = stripHTML(cell.value);\r\n if (content && !cell.metadata) {\r\n if (lastChapter) {\r\n (lastChapter as Chapter).footnotes.push({\r\n noteId: this._noteCounter++,\r\n text: content,\r\n caller: null,\r\n });\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n if (previousReference) {\r\n addReference(previousReference, addLineBreaks(lines));\r\n }\r\n\r\n for (let chapter of chapters.values()) {\r\n root.content.push(chapter);\r\n }\r\n\r\n return root;\r\n }\r\n}\r\n"],
5
5
  "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAAkB;AAQlB,mBAAyD;AAGlD,MAAM,uBAAuB,aAAE,OAAO;AAAA,EACzC,MAAM,aAAE,QAAQ,iBAAiB;AAAA,EACjC,MAAM,aAAE,OAAO;AAAA,IACX,SAAS,aAAE,OAAO,OAAO,EAAE,IAAI;AAAA,EACnC,CAAC;AACL,CAAC;AAEM,MAAM,cAAc,aAAE,OAAO;AAAA,EAChC,MAAM,aAAE,QAAQ,MAAM;AAAA,EACtB,IAAI,aAAE,OAAO;AAAA,EACb,UAAU,aAAE,OAAO,EAAE,SAAS;AAAA,EAC9B,SAAS,aAAE,OAAO,EAAE,SAAS;AAAA,EAC7B,OAAO,aAAE,OAAO,EAAE,SAAS;AAAA,EAC3B,MAAM,aACD,OAAO;AAAA,IACJ,kBAAkB,aAAE,MAAM,aAAE,OAAO,CAAC,EAAE,SAAS;AAAA,EACnD,CAAC,EACA,SAAS;AAClB,CAAC;AAEM,MAAM,iBAAiB,aAAE,OAAO;AAAA,EACnC,MAAM,aAAE,QAAQ,UAAU;AAAA,EAC1B,IAAI,aAAE,OAAO;AACjB,CAAC;AAEM,MAAM,iBAAiB,aAAE,mBAAmB,QAAQ;AAAA,EACvD;AAAA,EACA;AAAA,EACA;AACJ,CAAC;AAEM,MAAM,cAAc,aAAE,OAAO;AAAA,EAChC,OAAO,aAAE;AAAA,IACL,aAAE,OAAO;AAAA,MACL,MAAM,aAAE,OAAO;AAAA,MACf,YAAY,aAAE,OAAO;AAAA,MACrB,OAAO,aAAE,OAAO;AAAA,MAChB,UAAU,aACL,OAAO;AAAA,QACJ,MA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,UACJ;AAAA,QACJ;AAAA,MACJ;AAAA,IACJ;AAEA,QAAI,mBAAmB;AACnB,mBAAa,mBAAmB,cAAc,KAAK,CAAC;AAAA,IACxD;AAEA,aAAS,WAAW,SAAS,OAAO,GAAG;AACnC,WAAK,QAAQ,KAAK,OAAO;AAAA,IAC7B;AAEA,WAAO;AAAA,EACX;AACJ;",
6
6
  "names": ["ref", "lines"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../parser/commentary-csv-parser.ts"],
4
- "sourcesContent": ["import {\n CommentaryBookNode,\n CommentaryChapterNode,\n CommentaryParseTree,\n} from './types';\nimport { getBookId, parseVerseReference } from '../utils';\nimport { parse } from 'papaparse';\n\nexport interface CsvLine {\n book: string;\n chapter: string;\n verse: string;\n commentaries: string;\n}\n\nexport class CommentaryCsvParser {\n parse(data: string): CommentaryParseTree {\n // remove header automatically\n const firstLine = data.indexOf('\\n');\n data = data.substring(firstLine + 1);\n\n const lines = parse<string[]>(data, {\n header: false,\n // transformHeader: (_, index) => {\n // const headers = ['book', 'chapter', 'verse', 'commentaries'];\n // if (index < headers.length) {\n // return headers[index];\n // } else {\n // return '';\n // }\n // },\n delimiter: ',',\n escapeChar: '\"',\n quoteChar: '\"',\n });\n return this.parseLines(\n lines.data.map((line: string[]) => ({\n book: line[0],\n chapter: line[1],\n verse: line[2],\n commentaries: line[3],\n }))\n );\n }\n\n parseLines(data: CsvLine[]): CommentaryParseTree {\n let tree: CommentaryParseTree = {\n type: 'commentary/root',\n books: [],\n };\n\n let book: CommentaryBookNode | null = null;\n let chapter: CommentaryChapterNode | null = null;\n for (let line of data) {\n if (hasValue(line.book)) {\n const id = getBookId(line.book);\n if (!id) {\n throw new Error('Invalid book: ' + line.book);\n }\n\n book = tree.books.find((b) => b.book === id) ?? null;\n if (!book) {\n book = {\n type: 'book',\n book: id,\n introduction: null,\n chapters: [],\n };\n tree.books.push(book);\n }\n\n if (!book.introduction) {\n book.introduction = hasValue(line.commentaries)\n ? line.commentaries\n : null;\n }\n } else if (hasValue(line.chapter)) {\n const number = parseInt(line.chapter);\n if (isNaN(number)) {\n throw new Error('Invalid chapter number: ' + line.chapter);\n }\n\n if (!book) {\n throw new Error('Chapter without book');\n }\n\n chapter = {\n type: 'chapter',\n number,\n introduction: hasValue(line.commentaries)\n ? line.commentaries\n : null,\n verses: [],\n };\n book.chapters.push(chapter);\n } else if (hasValue(line.verse)) {\n const ref = parseVerseReference(line.verse);\n if (ref) {\n if (ref.book === book?.book) {\n // @ts-ignore\n if (ref.chapter === chapter?.number) {\n chapter.verses.push({\n type: 'verse',\n number: ref.verse,\n content: [line.commentaries],\n });\n } else {\n chapter = {\n type: 'chapter',\n number: ref.chapter,\n introduction: null,\n verses: [\n {\n type: 'verse',\n number: ref.verse,\n content: [line.commentaries],\n },\n ],\n };\n\n book.chapters.push(chapter);\n }\n }\n }\n }\n }\n\n return tree;\n }\n}\n\nfunction hasValue(value: string | null): boolean {\n return (\n value !== null &&\n value !== undefined &&\n value !== '' &&\n value.trim() !== ''\n );\n}\n"],
4
+ "sourcesContent": ["import {\r\n CommentaryBookNode,\r\n CommentaryChapterNode,\r\n CommentaryParseTree,\r\n} from './types';\r\nimport { getBookId, parseVerseReference } from '../utils';\r\nimport { parse } from 'papaparse';\r\n\r\nexport interface CsvLine {\r\n book: string;\r\n chapter: string;\r\n verse: string;\r\n commentaries: string;\r\n}\r\n\r\nexport class CommentaryCsvParser {\r\n parse(data: string): CommentaryParseTree {\r\n // remove header automatically\r\n const firstLine = data.indexOf('\\n');\r\n data = data.substring(firstLine + 1);\r\n\r\n const lines = parse<string[]>(data, {\r\n header: false,\r\n // transformHeader: (_, index) => {\r\n // const headers = ['book', 'chapter', 'verse', 'commentaries'];\r\n // if (index < headers.length) {\r\n // return headers[index];\r\n // } else {\r\n // return '';\r\n // }\r\n // },\r\n delimiter: ',',\r\n escapeChar: '\"',\r\n quoteChar: '\"',\r\n });\r\n return this.parseLines(\r\n lines.data.map((line: string[]) => ({\r\n book: line[0],\r\n chapter: line[1],\r\n verse: line[2],\r\n commentaries: line[3],\r\n }))\r\n );\r\n }\r\n\r\n parseLines(data: CsvLine[]): CommentaryParseTree {\r\n let tree: CommentaryParseTree = {\r\n type: 'commentary/root',\r\n books: [],\r\n };\r\n\r\n let book: CommentaryBookNode | null = null;\r\n let chapter: CommentaryChapterNode | null = null;\r\n for (let line of data) {\r\n if (hasValue(line.book)) {\r\n const id = getBookId(line.book);\r\n if (!id) {\r\n throw new Error('Invalid book: ' + line.book);\r\n }\r\n\r\n book = tree.books.find((b) => b.book === id) ?? null;\r\n if (!book) {\r\n book = {\r\n type: 'book',\r\n book: id,\r\n introduction: null,\r\n chapters: [],\r\n };\r\n tree.books.push(book);\r\n }\r\n\r\n if (!book.introduction) {\r\n book.introduction = hasValue(line.commentaries)\r\n ? line.commentaries\r\n : null;\r\n }\r\n } else if (hasValue(line.chapter)) {\r\n const number = parseInt(line.chapter);\r\n if (isNaN(number)) {\r\n throw new Error('Invalid chapter number: ' + line.chapter);\r\n }\r\n\r\n if (!book) {\r\n throw new Error('Chapter without book');\r\n }\r\n\r\n chapter = {\r\n type: 'chapter',\r\n number,\r\n introduction: hasValue(line.commentaries)\r\n ? line.commentaries\r\n : null,\r\n verses: [],\r\n };\r\n book.chapters.push(chapter);\r\n } else if (hasValue(line.verse)) {\r\n const ref = parseVerseReference(line.verse);\r\n if (ref) {\r\n if (ref.book === book?.book) {\r\n // @ts-ignore\r\n if (ref.chapter === chapter?.number) {\r\n chapter.verses.push({\r\n type: 'verse',\r\n number: ref.verse,\r\n content: [line.commentaries],\r\n });\r\n } else {\r\n chapter = {\r\n type: 'chapter',\r\n number: ref.chapter,\r\n introduction: null,\r\n verses: [\r\n {\r\n type: 'verse',\r\n number: ref.verse,\r\n content: [line.commentaries],\r\n },\r\n ],\r\n };\r\n\r\n book.chapters.push(chapter);\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n return tree;\r\n }\r\n}\r\n\r\nfunction hasValue(value: string | null): boolean {\r\n return (\r\n value !== null &&\r\n value !== undefined &&\r\n value !== '' &&\r\n value.trim() !== ''\r\n );\r\n}\r\n"],
5
5
  "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,mBAA+C;AAC/C,uBAAsB;AASf,MAAM,oBAAoB;AAAA,EAC7B,MAAM,MAAmC;AAErC,UAAM,YAAY,KAAK,QAAQ,IAAI;AACnC,WAAO,KAAK,UAAU,YAAY,CAAC;AAEnC,UAAM,YAAQ,wBAAgB,MAAM;AAAA,MAChC,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MASR,WAAW;AAAA,MACX,YAAY;AAAA,MACZ,WAAW;AAAA,IACf,CAAC;AACD,WAAO,KAAK;AAAA,MACR,MAAM,KAAK,IAAI,CAAC,UAAoB;AAAA,QAChC,MAAM,KAAK,CAAC;AAAA,QACZ,SAAS,KAAK,CAAC;AAAA,QACf,OAAO,KAAK,CAAC;AAAA,QACb,cAAc,KAAK,CAAC;AAAA,MACxB,EAAE;AAAA,IACN;AAAA,EACJ;AAAA,EAEA,WAAW,MAAsC;AAC7C,QAAI,OAA4B;AAAA,MAC5B,MAAM;AAAA,MACN,OAAO,CAAC;AAAA,IACZ;AAEA,QAAI,OAAkC;AACtC,QAAI,UAAwC;AAC5C,aAAS,QAAQ,MAAM;AACnB,UAAI,SAAS,KAAK,IAAI,GAAG;AACrB,cAAM,SAAK,wBAAU,KAAK,IAAI;AAC9B,YAAI,CAAC,IAAI;AACL,gBAAM,IAAI,MAAM,mBAAmB,KAAK,IAAI;AAAA,QAChD;AAEA,eAAO,KAAK,MAAM,KAAK,CAAC,MAAM,EAAE,SAAS,EAAE,KAAK;AAChD,YAAI,CAAC,MAAM;AACP,iBAAO;AAAA,YACH,MAAM;AAAA,YACN,MAAM;AAAA,YACN,cAAc;AAAA,YACd,UAAU,CAAC;AAAA,UACf;AACA,e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AU,QACV,UAAU,UACV,UAAU,MACV,MAAM,KAAK,MAAM;AAEzB;",
6
6
  "names": []
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../parser/iterators.ts"],
4
- "sourcesContent": ["import { getLogger } from '../log.js';\n\n/**\n * Defines an interface that represents an iterator that can be rewound.\n */\nexport interface RewindableIterator<T> extends IterableIterator<T> {\n /**\n * Rewinds the iterator by the specified number of elements.\n * @param number The number of elements to rewind.\n */\n rewind(number: number): void;\n}\n\n/**\n * Defines a class that implements an iterator that can be rewound.\n */\nexport class Rewindable<T> implements RewindableIterator<T> {\n buffer: T[] = [];\n\n private _bufferSize: number = 0;\n private _position: number = -1;\n private _iterator: IterableIterator<T>;\n\n constructor(iterator: IterableIterator<T>, bufferSize: number = 2) {\n this._iterator = iterator;\n this._bufferSize = bufferSize;\n\n if (this._iterator.return) {\n this.return = (value?: any) => {\n return this._iterator.return!(value);\n };\n }\n if (this._iterator.throw) {\n this.throw = (value?: any) => {\n return this._iterator.throw!(value);\n };\n }\n }\n\n rewind(number: number): void {\n this._position += number;\n }\n\n [Symbol.iterator](): IterableIterator<T> {\n return this;\n }\n\n next(...args: [] | [undefined]): IteratorResult<T, any> {\n if (this._position >= 0) {\n let item = this.buffer[this._position];\n this._position--;\n return {\n value: item,\n done: false,\n };\n }\n\n let result = this._iterator.next(...args);\n this.buffer.unshift(result.value);\n if (this.buffer.length > this._bufferSize) {\n this.buffer.splice(\n this._bufferSize,\n this.buffer.length - this._bufferSize\n );\n }\n return result;\n }\n\n return?(value?: any): IteratorResult<T, any>;\n throw?(e?: any): IteratorResult<T, any>;\n}\n\nexport function* debug(label: string, iterator: IterableIterator<any>) {\n const logger = getLogger();\n for (let value of uncompletable(iterator)) {\n if (value instanceof Element) {\n logger.log(label, value.outerHTML);\n } else if (value instanceof Node) {\n logger.log(label, value.textContent);\n } else {\n logger.log(label, value);\n }\n yield value;\n }\n}\n\n/**\n * Creates a new rewindable iterator from the given iterator.\n * @param iterator The iterator.\n * @param bufferSize The size of the buffer.\n */\nexport function rewindable<T>(\n iterator: IterableIterator<T>,\n bufferSize: number = 2\n): Rewindable<T> {\n return new Rewindable(iterator, bufferSize);\n}\n\nfunction* iterateNodes(node: Node) {\n for (let i = 0; i < node.childNodes.length; i++) {\n yield node.childNodes[i];\n }\n}\n\n/**\n * Gets the char element that is the parent of the given node.\n * @param node The node.\n */\nexport function parentChar(node: Node): Element | null {\n return matchingParent(\n node,\n (n) => n instanceof Element && n.nodeName === 'char'\n ) as Element | null;\n}\n\n/**\n * Gets the note element that is the parent of the given node.\n * @param node The node.\n */\nexport function parentNote(node: Node): Element | null {\n return matchingParent(\n node,\n (n) => n instanceof Element && n.nodeName === 'note'\n ) as Element | null;\n}\n\n/**\n * Gets the parent node that matches the given filter.\n * @param node The node to start the search from.\n * @param filter The filter that should be used.\n */\nexport function matchingParent(\n node: Node,\n filter: (node: Node) => boolean\n): Node | null {\n let parent = node.parentNode;\n while (parent) {\n if (filter(parent)) {\n return parent;\n }\n parent = parent.parentNode;\n }\n return null;\n}\n\n/**\n * Determines if the given node is a child of the parent node.\n * @param node The node to test.\n * @param parent The parent.\n * @returns\n */\nexport function isParent(node: Node, parent: Node): boolean {\n let parentNode = node.parentNode;\n while (parentNode) {\n if (parentNode === parent) {\n return true;\n }\n parentNode = parentNode.parentNode;\n }\n return false;\n}\n\n/**\n * Iterates through all of the nodes in the tree in a depth-first traversal.\n * @param node The node to start the traversal from.\n */\nexport function iterateAll(node: Node): RewindableIterator<Node> {\n return rewindable(_iterateAll(node));\n}\n\nexport function* iterateUntil<T>(\n iterator: IterableIterator<T>,\n predicate: (value: T) => boolean\n): IterableIterator<T> {\n for (let value of iterator) {\n if (predicate(value)) {\n return;\n }\n yield value;\n }\n}\n\nfunction* _iterateAll(node: Node): IterableIterator<Node> {\n for (let child of node.childNodes) {\n yield child;\n yield* iterateAll(child);\n }\n}\n\n/**\n * Iterates only the elements in the iterator.\n * @param iterator The iterator that should be used.\n */\nexport function* elements(\n iterator: IterableIterator<Node>\n): IterableIterator<Element> {\n for (let node of uncompletable(iterator)) {\n if (node instanceof Element) {\n yield node;\n }\n }\n}\n\n/**\n * Iterates only the children of the given node in the iterator.\n * @param iterator The iterator that should be used.\n * @param parent The parent node.\n */\nexport function* children(\n iterator: RewindableIterator<Node>,\n parent: Node\n): IterableIterator<Node> {\n for (let node of uncompletable(iterator)) {\n if (!isParent(node, parent)) {\n iterator.rewind(1);\n return;\n }\n\n yield node;\n }\n}\n\n/**\n * Wraps the given iterable in a generator that will prevent consumers from calling return() on the iterator.\n * @param iterable The iterable.\n */\nexport function* uncompletable<T>(\n iterable: IterableIterator<T>\n): IterableIterator<T> {\n while (true) {\n const { done, value } = iterable.next();\n if (done) {\n return;\n }\n yield value;\n }\n}\n\n/**\n * Converts the given iterable into an async iterable.\n * @param input The input iterable.\n */\nexport async function* toAsyncIterable<T>(\n input: Iterable<T>\n): AsyncIterable<T> {\n for (let item of input) {\n yield item;\n }\n}\n\n/**\n * Batches items from the given iterator.\n * @param input The input iterator.\n * @param batchSize The size of each batch.\n */\nexport function* batch<T>(\n input: Iterable<T>,\n batchSize: number\n): Iterable<T[]> {\n while (true) {\n let batch = [] as T[];\n for (let item of input) {\n batch.push(item);\n if (batch.length >= batchSize) {\n break;\n }\n }\n\n if (batch.length === 0) {\n return;\n }\n\n yield batch;\n }\n}\n"],
4
+ "sourcesContent": ["import { getLogger } from '../log.js';\r\n\r\n/**\r\n * Defines an interface that represents an iterator that can be rewound.\r\n */\r\nexport interface RewindableIterator<T> extends IterableIterator<T> {\r\n /**\r\n * Rewinds the iterator by the specified number of elements.\r\n * @param number The number of elements to rewind.\r\n */\r\n rewind(number: number): void;\r\n}\r\n\r\n/**\r\n * Defines a class that implements an iterator that can be rewound.\r\n */\r\nexport class Rewindable<T> implements RewindableIterator<T> {\r\n buffer: T[] = [];\r\n\r\n private _bufferSize: number = 0;\r\n private _position: number = -1;\r\n private _iterator: IterableIterator<T>;\r\n\r\n constructor(iterator: IterableIterator<T>, bufferSize: number = 2) {\r\n this._iterator = iterator;\r\n this._bufferSize = bufferSize;\r\n\r\n if (this._iterator.return) {\r\n this.return = (value?: any) => {\r\n return this._iterator.return!(value);\r\n };\r\n }\r\n if (this._iterator.throw) {\r\n this.throw = (value?: any) => {\r\n return this._iterator.throw!(value);\r\n };\r\n }\r\n }\r\n\r\n rewind(number: number): void {\r\n this._position += number;\r\n }\r\n\r\n [Symbol.iterator](): IterableIterator<T> {\r\n return this;\r\n }\r\n\r\n next(...args: [] | [undefined]): IteratorResult<T, any> {\r\n if (this._position >= 0) {\r\n let item = this.buffer[this._position];\r\n this._position--;\r\n return {\r\n value: item,\r\n done: false,\r\n };\r\n }\r\n\r\n let result = this._iterator.next(...args);\r\n this.buffer.unshift(result.value);\r\n if (this.buffer.length > this._bufferSize) {\r\n this.buffer.splice(\r\n this._bufferSize,\r\n this.buffer.length - this._bufferSize\r\n );\r\n }\r\n return result;\r\n }\r\n\r\n return?(value?: any): IteratorResult<T, any>;\r\n throw?(e?: any): IteratorResult<T, any>;\r\n}\r\n\r\nexport function* debug(label: string, iterator: IterableIterator<any>) {\r\n const logger = getLogger();\r\n for (let value of uncompletable(iterator)) {\r\n if (value instanceof Element) {\r\n logger.log(label, value.outerHTML);\r\n } else if (value instanceof Node) {\r\n logger.log(label, value.textContent);\r\n } else {\r\n logger.log(label, value);\r\n }\r\n yield value;\r\n }\r\n}\r\n\r\n/**\r\n * Creates a new rewindable iterator from the given iterator.\r\n * @param iterator The iterator.\r\n * @param bufferSize The size of the buffer.\r\n */\r\nexport function rewindable<T>(\r\n iterator: IterableIterator<T>,\r\n bufferSize: number = 2\r\n): Rewindable<T> {\r\n return new Rewindable(iterator, bufferSize);\r\n}\r\n\r\nfunction* iterateNodes(node: Node) {\r\n for (let i = 0; i < node.childNodes.length; i++) {\r\n yield node.childNodes[i];\r\n }\r\n}\r\n\r\n/**\r\n * Gets the char element that is the parent of the given node.\r\n * @param node The node.\r\n */\r\nexport function parentChar(node: Node): Element | null {\r\n return matchingParent(\r\n node,\r\n (n) => n instanceof Element && n.nodeName === 'char'\r\n ) as Element | null;\r\n}\r\n\r\n/**\r\n * Gets the note element that is the parent of the given node.\r\n * @param node The node.\r\n */\r\nexport function parentNote(node: Node): Element | null {\r\n return matchingParent(\r\n node,\r\n (n) => n instanceof Element && n.nodeName === 'note'\r\n ) as Element | null;\r\n}\r\n\r\n/**\r\n * Gets the parent node that matches the given filter.\r\n * @param node The node to start the search from.\r\n * @param filter The filter that should be used.\r\n */\r\nexport function matchingParent(\r\n node: Node,\r\n filter: (node: Node) => boolean\r\n): Node | null {\r\n let parent = node.parentNode;\r\n while (parent) {\r\n if (filter(parent)) {\r\n return parent;\r\n }\r\n parent = parent.parentNode;\r\n }\r\n return null;\r\n}\r\n\r\n/**\r\n * Determines if the given node is a child of the parent node.\r\n * @param node The node to test.\r\n * @param parent The parent.\r\n * @returns\r\n */\r\nexport function isParent(node: Node, parent: Node): boolean {\r\n let parentNode = node.parentNode;\r\n while (parentNode) {\r\n if (parentNode === parent) {\r\n return true;\r\n }\r\n parentNode = parentNode.parentNode;\r\n }\r\n return false;\r\n}\r\n\r\n/**\r\n * Iterates through all of the nodes in the tree in a depth-first traversal.\r\n * @param node The node to start the traversal from.\r\n */\r\nexport function iterateAll(node: Node): RewindableIterator<Node> {\r\n return rewindable(_iterateAll(node));\r\n}\r\n\r\nexport function* iterateUntil<T>(\r\n iterator: IterableIterator<T>,\r\n predicate: (value: T) => boolean\r\n): IterableIterator<T> {\r\n for (let value of iterator) {\r\n if (predicate(value)) {\r\n return;\r\n }\r\n yield value;\r\n }\r\n}\r\n\r\nfunction* _iterateAll(node: Node): IterableIterator<Node> {\r\n for (let child of node.childNodes) {\r\n yield child;\r\n yield* iterateAll(child);\r\n }\r\n}\r\n\r\n/**\r\n * Iterates only the elements in the iterator.\r\n * @param iterator The iterator that should be used.\r\n */\r\nexport function* elements(\r\n iterator: IterableIterator<Node>\r\n): IterableIterator<Element> {\r\n for (let node of uncompletable(iterator)) {\r\n if (node instanceof Element) {\r\n yield node;\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Iterates only the children of the given node in the iterator.\r\n * @param iterator The iterator that should be used.\r\n * @param parent The parent node.\r\n */\r\nexport function* children(\r\n iterator: RewindableIterator<Node>,\r\n parent: Node\r\n): IterableIterator<Node> {\r\n for (let node of uncompletable(iterator)) {\r\n if (!isParent(node, parent)) {\r\n iterator.rewind(1);\r\n return;\r\n }\r\n\r\n yield node;\r\n }\r\n}\r\n\r\n/**\r\n * Wraps the given iterable in a generator that will prevent consumers from calling return() on the iterator.\r\n * @param iterable The iterable.\r\n */\r\nexport function* uncompletable<T>(\r\n iterable: IterableIterator<T>\r\n): IterableIterator<T> {\r\n while (true) {\r\n const { done, value } = iterable.next();\r\n if (done) {\r\n return;\r\n }\r\n yield value;\r\n }\r\n}\r\n\r\n/**\r\n * Converts the given iterable into an async iterable.\r\n * @param input The input iterable.\r\n */\r\nexport async function* toAsyncIterable<T>(\r\n input: Iterable<T>\r\n): AsyncIterable<T> {\r\n for (let item of input) {\r\n yield item;\r\n }\r\n}\r\n\r\n/**\r\n * Batches items from the given iterator.\r\n * @param input The input iterator.\r\n * @param batchSize The size of each batch.\r\n */\r\nexport function* batch<T>(\r\n input: Iterable<T>,\r\n batchSize: number\r\n): Iterable<T[]> {\r\n while (true) {\r\n let batch = [] as T[];\r\n for (let item of input) {\r\n batch.push(item);\r\n if (batch.length >= batchSize) {\r\n break;\r\n }\r\n }\r\n\r\n if (batch.length === 0) {\r\n return;\r\n }\r\n\r\n yield batch;\r\n }\r\n}\r\n"],
5
5
  "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAA0B;AAgBnB,MAAM,WAA+C;AAAA,EACxD,SAAc,CAAC;AA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