@helloao/tools 0.0.6 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/generation/api.cjs +366 -0
- package/dist/cjs/generation/api.cjs.map +7 -0
- package/dist/cjs/generation/audio.cjs +83 -0
- package/dist/cjs/generation/audio.cjs.map +7 -0
- package/dist/cjs/generation/book-order.cjs +508 -0
- package/dist/cjs/generation/book-order.cjs.map +7 -0
- package/dist/cjs/generation/common-types.cjs +17 -0
- package/dist/cjs/generation/common-types.cjs.map +7 -0
- package/dist/cjs/generation/dataset.cjs +238 -0
- package/dist/cjs/generation/dataset.cjs.map +7 -0
- package/dist/cjs/generation/index.cjs +51 -0
- package/dist/cjs/generation/index.cjs.map +7 -0
- package/dist/cjs/index.cjs +45 -0
- package/dist/cjs/index.cjs.map +7 -0
- package/dist/cjs/parser/codex-parser.cjs +187 -0
- package/dist/cjs/parser/codex-parser.cjs.map +7 -0
- package/dist/cjs/parser/commentary-csv-parser.cjs +133 -0
- package/dist/cjs/parser/commentary-csv-parser.cjs.map +7 -0
- package/dist/cjs/parser/index.cjs +50 -0
- package/dist/cjs/parser/index.cjs.map +7 -0
- package/dist/cjs/parser/iterators.cjs +204 -0
- package/dist/cjs/parser/iterators.cjs.map +7 -0
- package/dist/cjs/parser/types.cjs +17 -0
- package/dist/cjs/parser/types.cjs.map +7 -0
- package/dist/cjs/parser/usfm-parser.cjs +791 -0
- package/dist/cjs/parser/usfm-parser.cjs.map +7 -0
- package/dist/cjs/parser/usx-parser.cjs +483 -0
- package/dist/cjs/parser/usx-parser.cjs.map +7 -0
- package/dist/cjs/utils.cjs +237 -0
- package/dist/cjs/utils.cjs.map +7 -0
- package/dist/esm/generation/api.js +320 -0
- package/dist/esm/generation/api.js.map +7 -0
- package/dist/esm/generation/audio.js +53 -0
- package/dist/esm/generation/audio.js.map +7 -0
- package/dist/esm/generation/book-order.js +478 -0
- package/dist/esm/generation/book-order.js.map +7 -0
- package/dist/esm/generation/common-types.js +2 -0
- package/dist/esm/generation/common-types.js.map +7 -0
- package/dist/esm/generation/dataset.js +212 -0
- package/dist/esm/generation/dataset.js.map +7 -0
- package/dist/esm/generation/index.js +8 -0
- package/dist/esm/generation/index.js.map +7 -0
- package/dist/esm/index.js +6 -0
- package/dist/esm/index.js.map +7 -0
- package/dist/esm/parser/codex-parser.js +151 -0
- package/dist/esm/parser/codex-parser.js.map +7 -0
- package/dist/esm/parser/commentary-csv-parser.js +107 -0
- package/dist/esm/parser/commentary-csv-parser.js.map +7 -0
- package/dist/esm/parser/index.js +9 -0
- package/dist/esm/parser/index.js.map +7 -0
- package/dist/esm/parser/iterators.js +152 -0
- package/dist/esm/parser/iterators.js.map +7 -0
- package/dist/esm/parser/types.js +2 -0
- package/dist/esm/parser/types.js.map +7 -0
- package/dist/esm/parser/usfm-parser.js +749 -0
- package/dist/esm/parser/usfm-parser.js.map +7 -0
- package/dist/esm/parser/usx-parser.js +459 -0
- package/dist/esm/parser/usx-parser.js.map +7 -0
- package/dist/esm/utils.js +201 -0
- package/dist/esm/utils.js.map +7 -0
- package/{generation → dist/types/generation}/api.d.ts +148 -2
- package/{generation → dist/types/generation}/audio.d.ts +1 -1
- package/{generation → dist/types/generation}/common-types.d.ts +121 -24
- package/{generation → dist/types/generation}/dataset.d.ts +23 -1
- package/dist/types/generation/index.d.ts +7 -0
- package/dist/types/index.d.ts +5 -0
- package/{parser → dist/types/parser}/codex-parser.d.ts +51 -8
- package/dist/types/parser/commentary-csv-parser.d.ts +12 -0
- package/dist/types/parser/index.d.ts +8 -0
- package/{parser → dist/types/parser}/types.d.ts +28 -1
- package/{parser → dist/types/parser}/usfm-parser.d.ts +1 -1
- package/{parser → dist/types/parser}/usx-parser.d.ts +3 -3
- package/{utils.d.ts → dist/types/utils.d.ts} +6 -0
- package/package.json +27 -4
- package/generation/api.js +0 -187
- package/generation/api.spec.d.ts +0 -2
- package/generation/api.spec.js +0 -620
- package/generation/audio.js +0 -60
- package/generation/audio.spec.d.ts +0 -2
- package/generation/audio.spec.js +0 -36
- package/generation/book-order.js +0 -494
- package/generation/book-order.spec.d.ts +0 -2
- package/generation/book-order.spec.js +0 -8
- package/generation/common-types.js +0 -2
- package/generation/dataset.js +0 -106
- package/generation/index.d.ts +0 -7
- package/generation/index.js +0 -38
- package/index.d.ts +0 -5
- package/index.js +0 -32
- package/parser/codex-parser.js +0 -160
- package/parser/codex-parser.spec.d.ts +0 -2
- package/parser/codex-parser.spec.js +0 -645
- package/parser/index.d.ts +0 -7
- package/parser/index.js +0 -35
- package/parser/iterators.js +0 -222
- package/parser/iterators.spec.d.ts +0 -2
- package/parser/iterators.spec.js +0 -174
- package/parser/types.js +0 -2
- package/parser/usfm-parser.js +0 -840
- package/parser/usfm-parser.spec.d.ts +0 -2
- package/parser/usfm-parser.spec.js +0 -1593
- package/parser/usx-parser.js +0 -486
- package/parser/usx-parser.spec.d.ts +0 -2
- package/parser/usx-parser.spec.js +0 -1260
- package/utils.js +0 -73
- package/utils.spec.d.ts +0 -2
- package/utils.spec.js +0 -42
- /package/{generation → dist/types/generation}/book-order.d.ts +0 -0
- /package/{parser → dist/types/parser}/iterators.d.ts +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { InputFile, Translation, TranslationBook, TranslationBookChapter } from './common-types';
|
|
1
|
+
import { Commentary, CommentaryBook, CommentaryBookChapter, InputFile, Translation, TranslationBook, TranslationBookChapter } from './common-types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Defines an interface that contains generated dataset info.
|
|
4
4
|
*/
|
|
@@ -7,6 +7,10 @@ export interface DatasetOutput {
|
|
|
7
7
|
* The list of translations that are available in the dataset.
|
|
8
8
|
*/
|
|
9
9
|
translations: DatasetTranslation[];
|
|
10
|
+
/**
|
|
11
|
+
* The list of commentaries that are available in the dataset.
|
|
12
|
+
*/
|
|
13
|
+
commentaries: DatasetCommentary[];
|
|
10
14
|
}
|
|
11
15
|
/**
|
|
12
16
|
* Defines a translation that is used in the dataset.
|
|
@@ -17,6 +21,15 @@ export interface DatasetTranslation extends Translation {
|
|
|
17
21
|
*/
|
|
18
22
|
books: DatasetTranslationBook[];
|
|
19
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Defines a commentary that is used in the dataset.
|
|
26
|
+
*/
|
|
27
|
+
export interface DatasetCommentary extends Commentary {
|
|
28
|
+
/**
|
|
29
|
+
* The list of books that are available for the translation.
|
|
30
|
+
*/
|
|
31
|
+
books: DatasetCommentaryBook[];
|
|
32
|
+
}
|
|
20
33
|
/**
|
|
21
34
|
* Defines a translation book that is used in the dataset.
|
|
22
35
|
*/
|
|
@@ -26,6 +39,15 @@ export interface DatasetTranslationBook extends TranslationBook {
|
|
|
26
39
|
*/
|
|
27
40
|
chapters: TranslationBookChapter[];
|
|
28
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Defines a commentary book that is used in the dataset.
|
|
44
|
+
*/
|
|
45
|
+
export interface DatasetCommentaryBook extends CommentaryBook {
|
|
46
|
+
/**
|
|
47
|
+
* The list of chapters that are available for the book.
|
|
48
|
+
*/
|
|
49
|
+
chapters: CommentaryBookChapter[];
|
|
50
|
+
}
|
|
29
51
|
/**
|
|
30
52
|
* Generates a list of output files from the given list of input files.
|
|
31
53
|
* @param file The list of files.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as api from './api.js';
|
|
2
|
+
import * as audio from './audio.js';
|
|
3
|
+
import * as dataset from './dataset.js';
|
|
4
|
+
import * as bookOrder from './book-order.js';
|
|
5
|
+
export * from './common-types.js';
|
|
6
|
+
export { api, audio, dataset, bookOrder };
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { ParseTree } from './types';
|
|
2
|
+
import { ParseTree } from './types.js';
|
|
3
3
|
export declare const chapterHeadingSchema: z.ZodObject<{
|
|
4
4
|
type: z.ZodLiteral<"chapter-heading">;
|
|
5
5
|
data: z.ZodObject<{
|
|
@@ -20,6 +20,26 @@ export declare const chapterHeadingSchema: z.ZodObject<{
|
|
|
20
20
|
chapter: number;
|
|
21
21
|
};
|
|
22
22
|
}>;
|
|
23
|
+
export declare const verseSchema: z.ZodObject<{
|
|
24
|
+
type: z.ZodLiteral<"text">;
|
|
25
|
+
id: z.ZodString;
|
|
26
|
+
}, "strip", z.ZodTypeAny, {
|
|
27
|
+
id: string;
|
|
28
|
+
type: "text";
|
|
29
|
+
}, {
|
|
30
|
+
id: string;
|
|
31
|
+
type: "text";
|
|
32
|
+
}>;
|
|
33
|
+
export declare const paratextSchema: z.ZodObject<{
|
|
34
|
+
type: z.ZodLiteral<"paratext">;
|
|
35
|
+
id: z.ZodString;
|
|
36
|
+
}, "strip", z.ZodTypeAny, {
|
|
37
|
+
id: string;
|
|
38
|
+
type: "paratext";
|
|
39
|
+
}, {
|
|
40
|
+
id: string;
|
|
41
|
+
type: "paratext";
|
|
42
|
+
}>;
|
|
23
43
|
export declare const metadataSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
|
|
24
44
|
type: z.ZodLiteral<"chapter-heading">;
|
|
25
45
|
data: z.ZodObject<{
|
|
@@ -39,10 +59,29 @@ export declare const metadataSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObjec
|
|
|
39
59
|
data: {
|
|
40
60
|
chapter: number;
|
|
41
61
|
};
|
|
62
|
+
}>, z.ZodObject<{
|
|
63
|
+
type: z.ZodLiteral<"text">;
|
|
64
|
+
id: z.ZodString;
|
|
65
|
+
}, "strip", z.ZodTypeAny, {
|
|
66
|
+
id: string;
|
|
67
|
+
type: "text";
|
|
68
|
+
}, {
|
|
69
|
+
id: string;
|
|
70
|
+
type: "text";
|
|
71
|
+
}>, z.ZodObject<{
|
|
72
|
+
type: z.ZodLiteral<"paratext">;
|
|
73
|
+
id: z.ZodString;
|
|
74
|
+
}, "strip", z.ZodTypeAny, {
|
|
75
|
+
id: string;
|
|
76
|
+
type: "paratext";
|
|
77
|
+
}, {
|
|
78
|
+
id: string;
|
|
79
|
+
type: "paratext";
|
|
42
80
|
}>]>;
|
|
43
81
|
export declare const codexSchema: z.ZodObject<{
|
|
44
82
|
cells: z.ZodArray<z.ZodObject<{
|
|
45
|
-
|
|
83
|
+
kind: z.ZodNumber;
|
|
84
|
+
languageId: z.ZodString;
|
|
46
85
|
value: z.ZodString;
|
|
47
86
|
metadata: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
48
87
|
type: z.ZodString;
|
|
@@ -52,30 +91,34 @@ export declare const codexSchema: z.ZodObject<{
|
|
|
52
91
|
type: z.ZodString;
|
|
53
92
|
}, z.ZodTypeAny, "passthrough">>>>;
|
|
54
93
|
}, "strip", z.ZodTypeAny, {
|
|
94
|
+
kind: number;
|
|
55
95
|
value: string;
|
|
56
|
-
|
|
96
|
+
languageId: string;
|
|
57
97
|
metadata?: z.objectOutputType<{
|
|
58
98
|
type: z.ZodString;
|
|
59
99
|
}, z.ZodTypeAny, "passthrough"> | null | undefined;
|
|
60
100
|
}, {
|
|
101
|
+
kind: number;
|
|
61
102
|
value: string;
|
|
62
|
-
|
|
103
|
+
languageId: string;
|
|
63
104
|
metadata?: z.objectInputType<{
|
|
64
105
|
type: z.ZodString;
|
|
65
106
|
}, z.ZodTypeAny, "passthrough"> | null | undefined;
|
|
66
107
|
}>, "many">;
|
|
67
108
|
}, "strip", z.ZodTypeAny, {
|
|
68
109
|
cells: {
|
|
110
|
+
kind: number;
|
|
69
111
|
value: string;
|
|
70
|
-
|
|
112
|
+
languageId: string;
|
|
71
113
|
metadata?: z.objectOutputType<{
|
|
72
114
|
type: z.ZodString;
|
|
73
115
|
}, z.ZodTypeAny, "passthrough"> | null | undefined;
|
|
74
116
|
}[];
|
|
75
117
|
}, {
|
|
76
118
|
cells: {
|
|
119
|
+
kind: number;
|
|
77
120
|
value: string;
|
|
78
|
-
|
|
121
|
+
languageId: string;
|
|
79
122
|
metadata?: z.objectInputType<{
|
|
80
123
|
type: z.ZodString;
|
|
81
124
|
}, z.ZodTypeAny, "passthrough"> | null | undefined;
|
|
@@ -87,9 +130,9 @@ export declare const codexSchema: z.ZodObject<{
|
|
|
87
130
|
export declare class CodexParser {
|
|
88
131
|
private _noteCounter;
|
|
89
132
|
/**
|
|
90
|
-
* Parses the specified
|
|
133
|
+
* Parses the specified codex content.
|
|
91
134
|
*
|
|
92
|
-
* @param
|
|
135
|
+
* @param codex The codex content to parse.
|
|
93
136
|
* @returns The parse tree that was generated.
|
|
94
137
|
*/
|
|
95
138
|
parse(codex: string): ParseTree;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { CommentaryParseTree } from './types';
|
|
2
|
+
export interface CsvLine {
|
|
3
|
+
book: string;
|
|
4
|
+
chapter: string;
|
|
5
|
+
verse: string;
|
|
6
|
+
commentaries: string;
|
|
7
|
+
}
|
|
8
|
+
export declare class CommentaryCsvParser {
|
|
9
|
+
parse(data: string): CommentaryParseTree;
|
|
10
|
+
parseLines(data: CsvLine[]): CommentaryParseTree;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=commentary-csv-parser.d.ts.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './types.js';
|
|
2
|
+
export * from './usfm-parser.js';
|
|
3
|
+
export * from './usx-parser.js';
|
|
4
|
+
export * from './codex-parser.js';
|
|
5
|
+
export * from './commentary-csv-parser.js';
|
|
6
|
+
import * as iterators from './iterators.js';
|
|
7
|
+
export { iterators };
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -24,7 +24,7 @@ export interface Heading {
|
|
|
24
24
|
type: 'heading';
|
|
25
25
|
content: string[];
|
|
26
26
|
}
|
|
27
|
-
export type ChapterContent =
|
|
27
|
+
export type ChapterContent = Heading | Verse | HebrewSubtitle | LineBreak;
|
|
28
28
|
export type VerseContent = string | FootnoteReference | Text;
|
|
29
29
|
/**
|
|
30
30
|
* Defines an interface that represents a chapter.
|
|
@@ -141,4 +141,31 @@ export interface Footnote {
|
|
|
141
141
|
export interface LineBreak {
|
|
142
142
|
type: 'line_break';
|
|
143
143
|
}
|
|
144
|
+
/**
|
|
145
|
+
* The parse tree that is gathered.
|
|
146
|
+
*/
|
|
147
|
+
export interface CommentaryParseTree {
|
|
148
|
+
type: 'commentary/root';
|
|
149
|
+
/**
|
|
150
|
+
* The books that are contained in the commentary.
|
|
151
|
+
*/
|
|
152
|
+
books: CommentaryBookNode[];
|
|
153
|
+
}
|
|
154
|
+
export interface CommentaryBookNode {
|
|
155
|
+
type: 'book';
|
|
156
|
+
book: string;
|
|
157
|
+
introduction: string | null;
|
|
158
|
+
chapters: CommentaryChapterNode[];
|
|
159
|
+
}
|
|
160
|
+
export interface CommentaryChapterNode {
|
|
161
|
+
type: 'chapter';
|
|
162
|
+
number: number;
|
|
163
|
+
introduction: string | null;
|
|
164
|
+
verses: CommentaryVerseNode[];
|
|
165
|
+
}
|
|
166
|
+
export interface CommentaryVerseNode {
|
|
167
|
+
type: 'verse';
|
|
168
|
+
number: number;
|
|
169
|
+
content: string[];
|
|
170
|
+
}
|
|
144
171
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Chapter, ChapterContent, FootnoteReference, ParseTree, Verse, Text, HebrewSubtitle, InlineLineBreak } from './types';
|
|
2
|
-
import { RewindableIterator } from './iterators';
|
|
1
|
+
import { Chapter, ChapterContent, FootnoteReference, ParseTree, Verse, Text, HebrewSubtitle, InlineLineBreak } from './types.js';
|
|
2
|
+
import { RewindableIterator } from './iterators.js';
|
|
3
3
|
/**
|
|
4
4
|
* The version of the parser.
|
|
5
5
|
* Used to determine whether input files need to be re-parsed.
|
|
6
6
|
*/
|
|
7
|
-
export declare const PARSER_VERSION = "
|
|
7
|
+
export declare const PARSER_VERSION = "2";
|
|
8
8
|
/**
|
|
9
9
|
* Defines a class that is able to parse USX content.
|
|
10
10
|
*/
|
|
@@ -26,4 +26,10 @@ export interface VerseRef {
|
|
|
26
26
|
* @param text The reference to parse.
|
|
27
27
|
*/
|
|
28
28
|
export declare function parseVerseReference(text: string): VerseRef | null;
|
|
29
|
+
/**
|
|
30
|
+
* Gets the ID of the given book.
|
|
31
|
+
* Returns null if the ID could not be found.
|
|
32
|
+
* @param book The name/ID of the book.
|
|
33
|
+
*/
|
|
34
|
+
export declare function getBookId(book: string): string | null;
|
|
29
35
|
//# sourceMappingURL=utils.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,14 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@helloao/tools",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"description": "A set of tools for managing HelloAO's Free Bible API",
|
|
5
|
-
"
|
|
6
|
-
|
|
5
|
+
"exports": {
|
|
6
|
+
".": {
|
|
7
|
+
"types": "./dist/types/index.d.ts",
|
|
8
|
+
"import": "./dist/esm/index.js",
|
|
9
|
+
"require": "./dist/cjs/index.cjs"
|
|
10
|
+
},
|
|
11
|
+
"./*.js": {
|
|
12
|
+
"types": "./dist/types/*.d.ts",
|
|
13
|
+
"import": "./dist/esm/*.js",
|
|
14
|
+
"require": "./dist/cjs/*.cjs"
|
|
15
|
+
},
|
|
16
|
+
"./parser/*.js": {
|
|
17
|
+
"types": "./dist/types/parser/*.d.ts",
|
|
18
|
+
"import": "./dist/esm/parser/*.js",
|
|
19
|
+
"require": "./dist/cjs/parser/*.cjs"
|
|
20
|
+
},
|
|
21
|
+
"./generation/*.js": {
|
|
22
|
+
"types": "./dist/types/generation/*.d.ts",
|
|
23
|
+
"import": "./dist/esm/generation/*.js",
|
|
24
|
+
"require": "./dist/cjs/generation/*.cjs"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
7
27
|
"author": "Kallyn Gowdy <kal@helloao.org>",
|
|
8
28
|
"license": "MIT",
|
|
9
29
|
"dependencies": {
|
|
10
30
|
"lodash": "4.17.21",
|
|
11
|
-
"zod": "^3.23.8"
|
|
31
|
+
"zod": "^3.23.8",
|
|
32
|
+
"papaparse": "5.4.1"
|
|
12
33
|
},
|
|
13
34
|
"devDependencies": {
|
|
14
35
|
"linkedom": "0.18.4",
|
|
@@ -20,6 +41,8 @@
|
|
|
20
41
|
"/migrations/**/*.sql",
|
|
21
42
|
"**/*.js",
|
|
22
43
|
"**/*.js.map",
|
|
44
|
+
"**/*.cjs",
|
|
45
|
+
"**/*.cjs.map",
|
|
23
46
|
"**/*.d.ts"
|
|
24
47
|
],
|
|
25
48
|
"scripts": {}
|
package/generation/api.js
DELETED
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateApiForDataset = generateApiForDataset;
|
|
4
|
-
exports.generateFilesForApi = generateFilesForApi;
|
|
5
|
-
exports.generateOutputFilesFromDatasets = generateOutputFilesFromDatasets;
|
|
6
|
-
exports.listOfBooksApiLink = listOfBooksApiLink;
|
|
7
|
-
exports.bookChapterApiLink = bookChapterApiLink;
|
|
8
|
-
exports.bookChapterAudioApiLink = bookChapterAudioApiLink;
|
|
9
|
-
exports.jsonFile = jsonFile;
|
|
10
|
-
exports.downloadedFile = downloadedFile;
|
|
11
|
-
exports.replaceSpacesWithUnderscores = replaceSpacesWithUnderscores;
|
|
12
|
-
/**
|
|
13
|
-
* Generates the API output for the given dataset.
|
|
14
|
-
* @param dataset The dataset to generate the API for.
|
|
15
|
-
* @param options The options for generating the API.
|
|
16
|
-
*/
|
|
17
|
-
function generateApiForDataset(dataset, options = {}) {
|
|
18
|
-
const { useCommonName, pathPrefix } = options;
|
|
19
|
-
const apiPathPrefix = pathPrefix ? pathPrefix : '';
|
|
20
|
-
let api = {
|
|
21
|
-
availableTranslations: {
|
|
22
|
-
translations: [],
|
|
23
|
-
},
|
|
24
|
-
translationBooks: [],
|
|
25
|
-
translationBookChapters: [],
|
|
26
|
-
translationBookChapterAudio: [],
|
|
27
|
-
pathPrefix: apiPathPrefix,
|
|
28
|
-
};
|
|
29
|
-
const getNativeName = options.getNativeName;
|
|
30
|
-
const getEnglishName = options.getEnglishName;
|
|
31
|
-
for (let { books, ...translation } of dataset.translations) {
|
|
32
|
-
const apiTranslation = {
|
|
33
|
-
...translation,
|
|
34
|
-
availableFormats: ['json'],
|
|
35
|
-
listOfBooksApiLink: listOfBooksApiLink(translation.id, apiPathPrefix),
|
|
36
|
-
numberOfBooks: books.length,
|
|
37
|
-
totalNumberOfChapters: 0,
|
|
38
|
-
totalNumberOfVerses: 0,
|
|
39
|
-
languageName: getNativeName
|
|
40
|
-
? getNativeName(translation.language) ?? undefined
|
|
41
|
-
: undefined,
|
|
42
|
-
languageEnglishName: getEnglishName
|
|
43
|
-
? getEnglishName(translation.language) ?? undefined
|
|
44
|
-
: undefined,
|
|
45
|
-
};
|
|
46
|
-
const translationBooks = {
|
|
47
|
-
translation: apiTranslation,
|
|
48
|
-
books: [],
|
|
49
|
-
};
|
|
50
|
-
let translationChapters = [];
|
|
51
|
-
for (let { chapters, ...book } of books) {
|
|
52
|
-
const apiBook = {
|
|
53
|
-
...book,
|
|
54
|
-
firstChapterApiLink: bookChapterApiLink(translation.id, getBookLink(book), 1, 'json', apiPathPrefix),
|
|
55
|
-
lastChapterApiLink: bookChapterApiLink(translation.id, getBookLink(book), chapters.length, 'json', apiPathPrefix),
|
|
56
|
-
numberOfChapters: chapters.length,
|
|
57
|
-
totalNumberOfVerses: 0,
|
|
58
|
-
};
|
|
59
|
-
for (let { chapter, thisChapterAudioLinks } of chapters) {
|
|
60
|
-
const audio = {};
|
|
61
|
-
const apiBookChapter = {
|
|
62
|
-
translation: apiTranslation,
|
|
63
|
-
book: apiBook,
|
|
64
|
-
chapter: chapter,
|
|
65
|
-
thisChapterLink: bookChapterApiLink(translation.id, getBookLink(book), chapter.number, 'json', apiPathPrefix),
|
|
66
|
-
thisChapterAudioLinks: audio,
|
|
67
|
-
nextChapterApiLink: null,
|
|
68
|
-
nextChapterAudioLinks: null,
|
|
69
|
-
previousChapterApiLink: null,
|
|
70
|
-
previousChapterAudioLinks: null,
|
|
71
|
-
numberOfVerses: 0,
|
|
72
|
-
};
|
|
73
|
-
for (let reader in thisChapterAudioLinks) {
|
|
74
|
-
if (options.generateAudioFiles) {
|
|
75
|
-
const apiAudio = {
|
|
76
|
-
chapter: apiBookChapter,
|
|
77
|
-
link: bookChapterAudioApiLink(translation.id, getBookLink(book), chapter.number, reader, apiPathPrefix),
|
|
78
|
-
originalUrl: thisChapterAudioLinks[reader],
|
|
79
|
-
};
|
|
80
|
-
audio[reader] = apiAudio.link;
|
|
81
|
-
api.translationBookChapterAudio.push(apiAudio);
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
audio[reader] = thisChapterAudioLinks[reader];
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
for (let c of chapter.content) {
|
|
88
|
-
if (c.type === 'verse') {
|
|
89
|
-
apiBookChapter.numberOfVerses++;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
apiBook.totalNumberOfVerses += apiBookChapter.numberOfVerses;
|
|
93
|
-
translationChapters.push(apiBookChapter);
|
|
94
|
-
api.translationBookChapters.push(apiBookChapter);
|
|
95
|
-
}
|
|
96
|
-
translationBooks.books.push(apiBook);
|
|
97
|
-
apiTranslation.totalNumberOfChapters += apiBook.numberOfChapters;
|
|
98
|
-
apiTranslation.totalNumberOfVerses += apiBook.totalNumberOfVerses;
|
|
99
|
-
}
|
|
100
|
-
for (let i = 0; i < translationChapters.length; i++) {
|
|
101
|
-
if (i > 0) {
|
|
102
|
-
translationChapters[i].previousChapterApiLink =
|
|
103
|
-
bookChapterApiLink(translation.id, getBookLink(translationChapters[i - 1].book), translationChapters[i - 1].chapter.number, 'json', apiPathPrefix);
|
|
104
|
-
translationChapters[i].previousChapterAudioLinks =
|
|
105
|
-
translationChapters[i - 1].thisChapterAudioLinks;
|
|
106
|
-
}
|
|
107
|
-
if (i < translationChapters.length - 1) {
|
|
108
|
-
translationChapters[i].nextChapterApiLink = bookChapterApiLink(translation.id, getBookLink(translationChapters[i + 1].book), translationChapters[i + 1].chapter.number, 'json', apiPathPrefix);
|
|
109
|
-
translationChapters[i].nextChapterAudioLinks =
|
|
110
|
-
translationChapters[i + 1].thisChapterAudioLinks;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
api.availableTranslations.translations.push(apiTranslation);
|
|
114
|
-
api.translationBooks.push(translationBooks);
|
|
115
|
-
}
|
|
116
|
-
return api;
|
|
117
|
-
function getBookLink(book) {
|
|
118
|
-
return useCommonName ? book.commonName : book.id;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Generates the output files for the given API.
|
|
123
|
-
* @param api The API that the files should be generated for.
|
|
124
|
-
*/
|
|
125
|
-
function generateFilesForApi(api) {
|
|
126
|
-
let files = [];
|
|
127
|
-
files.push(jsonFile(`${api.pathPrefix}/api/available_translations.json`, api.availableTranslations, true));
|
|
128
|
-
for (let translationBooks of api.translationBooks) {
|
|
129
|
-
files.push(jsonFile(translationBooks.translation.listOfBooksApiLink, translationBooks));
|
|
130
|
-
}
|
|
131
|
-
for (let bookChapter of api.translationBookChapters) {
|
|
132
|
-
files.push(jsonFile(bookChapter.thisChapterLink, bookChapter));
|
|
133
|
-
}
|
|
134
|
-
for (let audio of api.translationBookChapterAudio) {
|
|
135
|
-
files.push(downloadedFile(audio.link, audio.originalUrl));
|
|
136
|
-
}
|
|
137
|
-
return files;
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Generates the output files for the given datasets.
|
|
141
|
-
* @param datasets The datasets to generate the output files for.
|
|
142
|
-
* @param options The options for generating the API files.
|
|
143
|
-
*/
|
|
144
|
-
async function* generateOutputFilesFromDatasets(datasets, options) {
|
|
145
|
-
for await (let dataset of datasets) {
|
|
146
|
-
const api = generateApiForDataset(dataset, options);
|
|
147
|
-
const files = generateFilesForApi(api);
|
|
148
|
-
yield files;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* Gets the API Link for the list of books endpoint for a translation.
|
|
153
|
-
* @param translationId The ID of the translation.
|
|
154
|
-
* @returns
|
|
155
|
-
*/
|
|
156
|
-
function listOfBooksApiLink(translationId, prefix = '') {
|
|
157
|
-
return `${prefix}/api/${translationId}/books.json`;
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* Getes the API link for a book chapter.
|
|
161
|
-
* @param translationId The ID of the translation.
|
|
162
|
-
* @param commonName The name of the book.
|
|
163
|
-
* @param chapterNumber The number of the book.
|
|
164
|
-
* @param extension The extension of the file.
|
|
165
|
-
*/
|
|
166
|
-
function bookChapterApiLink(translationId, commonName, chapterNumber, extension, prefix = '') {
|
|
167
|
-
return `${prefix}/api/${translationId}/${replaceSpacesWithUnderscores(commonName)}/${chapterNumber}.${extension}`;
|
|
168
|
-
}
|
|
169
|
-
function bookChapterAudioApiLink(translationId, bookId, chapterNumber, reader, prefix = '') {
|
|
170
|
-
return `${prefix}/api/${translationId}/${replaceSpacesWithUnderscores(bookId)}/${chapterNumber}.${reader}.mp3`;
|
|
171
|
-
}
|
|
172
|
-
function jsonFile(path, content, mergable) {
|
|
173
|
-
return {
|
|
174
|
-
path,
|
|
175
|
-
content,
|
|
176
|
-
mergable,
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
function downloadedFile(path, url) {
|
|
180
|
-
return {
|
|
181
|
-
path,
|
|
182
|
-
content: () => fetch(url).then((response) => response.body),
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
function replaceSpacesWithUnderscores(str) {
|
|
186
|
-
return str.replace(/[<>:"/\\|?*\s]/g, '_');
|
|
187
|
-
}
|
package/generation/api.spec.d.ts
DELETED