@helloao/cli 0.0.8 → 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.
@@ -1,10 +1,41 @@
1
- import { InputTranslationMetadata } from '@helloao/tools/generation';
2
- import { UploadApiFromDatabaseOptions, UploadApiOptions } from './uploads';
1
+ import { InputTranslationMetadata } from '@helloao/tools/generation/index.js';
2
+ import { UploadApiFromDatabaseOptions, UploadApiOptions } from './uploads.js';
3
+ export interface GetTranslationsItem {
4
+ id: string;
5
+ language: string;
6
+ direction: 'ltr' | 'rtl';
7
+ year: number;
8
+ name_local: string;
9
+ name_english: string;
10
+ name_abbrev: string;
11
+ attribution: string;
12
+ attribution_url: string;
13
+ licenses: RuntimeLicense[];
14
+ }
15
+ export interface RuntimeLicense {
16
+ id: string | null;
17
+ name: string;
18
+ restrictions: MetaRestrictions;
19
+ url: string;
20
+ }
21
+ export interface MetaRestrictions {
22
+ limit_verses: number | null;
23
+ limit_book_ratio: number | null;
24
+ limit_content_ratio: number | null;
25
+ forbid_commercial: boolean;
26
+ forbid_derivatives: boolean | 'same-license';
27
+ forbid_attributionless: boolean;
28
+ forbid_other: boolean;
29
+ }
3
30
  export interface InitDbOptions {
4
31
  /**
5
32
  * The path to the source database to copy the schema from.
6
33
  */
7
34
  source?: string;
35
+ /**
36
+ * Whether to overwrite the existing database.
37
+ */
38
+ overwrite?: boolean;
8
39
  /**
9
40
  * The languages to copy from the source database. If not specified, then all languages will be copied.
10
41
  */
@@ -35,6 +66,19 @@ export declare function importTranslation(dir: string, dirs: string[], options:
35
66
  * @param options The options.
36
67
  */
37
68
  export declare function importTranslations(dir: string, options: ImportTranslationOptions): Promise<void>;
69
+ /**
70
+ * Imports a commentary from the given directory into the database in the current working directory.
71
+ * @param dir The directory that the commentary is located in.
72
+ * @param dirs Any extra directories that should be imported.
73
+ * @param options The options for the import.
74
+ */
75
+ export declare function importCommentary(dir: string, dirs: string[], options: ImportTranslationOptions): Promise<void>;
76
+ /**
77
+ * Imports all the commentaries from the given directory into the database in the current working directory.
78
+ * @param dir The directory that the commentaries are located in.
79
+ * @param options The options.
80
+ */
81
+ export declare function importCommentaries(dir: string, options: ImportTranslationOptions): Promise<void>;
38
82
  export interface FetchTranslationsOptions {
39
83
  /**
40
84
  * Fetch all translations. If omitted, only undownloaded translations will be fetched.
@@ -1,10 +1,11 @@
1
- import { PrismaClient } from './prisma-gen';
1
+ import { PrismaClient } from './prisma-gen/index.js';
2
2
  import { Database } from 'better-sqlite3';
3
- import { DatasetOutput, DatasetTranslation, DatasetTranslationBook } from '@helloao/tools/generation/dataset';
4
- import { InputFile, TranslationBookChapter } from '@helloao/tools/generation';
5
- import { GenerateApiOptions } from '@helloao/tools/generation/api';
6
- import { DOMParser } from 'linkedom';
3
+ import { DatasetCommentary, DatasetCommentaryBook, DatasetOutput, DatasetTranslation, DatasetTranslationBook } from '@helloao/tools/generation/dataset.js';
4
+ import { InputFile, TranslationBookChapter, CommentaryBookChapter } from '@helloao/tools/generation/index.js';
5
+ import { GenerateApiOptions } from '@helloao/tools/generation/api.js';
6
+ import type { DOMParser } from 'linkedom';
7
7
  import { Readable } from 'stream';
8
+ export declare function getMigrationsPath(): Promise<string | null>;
8
9
  /**
9
10
  * Imports the translations from the given directories into the database.
10
11
  * @param db The database to import the translations into.
@@ -12,7 +13,24 @@ import { Readable } from 'stream';
12
13
  * @param parser The DOM parser that should be used for USX files.
13
14
  * @param overwrite Whether to force a reload of the translations.
14
15
  */
15
- export declare function importTranslations(db: Database, dirs: string[], parser: DOMParser, overwrite: boolean): Promise<void>;
16
+ export declare const importTranslations: (db: Database, dirs: string[], parser: DOMParser, overwrite: boolean) => Promise<void>;
17
+ /**
18
+ * Imports the commentaries from the given directories into the database.
19
+ * @param db The database to import the commentaries into.
20
+ * @param dirs The directories to import the commentaries from.
21
+ * @param parser The DOM parser that should be used for USX files.
22
+ * @param overwrite Whether to force a reload of the commentaries.
23
+ */
24
+ export declare const importCommentaries: (db: Database, dirs: string[], parser: DOMParser, overwrite: boolean) => Promise<void>;
25
+ /**
26
+ * Imports the files from the given directories into the database.
27
+ * @param loadFilesFromDir The function that should be used to load the files from the given directory.
28
+ * @param db The database to import the files into.
29
+ * @param dirs The directories to import the files from.
30
+ * @param parser The DOM parser that should be used for USX files.
31
+ * @param overwrite Whether to force a reload of the files.
32
+ */
33
+ export declare function importFiles(loadFilesFromDir: (path: string) => Promise<InputFile[] | null>, db: Database, dirs: string[], parser: DOMParser, overwrite: boolean): Promise<void>;
16
34
  /**
17
35
  * Imports a batch of translations from the given directories into the database.
18
36
  * @param db The database to import the translations into.
@@ -20,7 +38,16 @@ export declare function importTranslations(db: Database, dirs: string[], parser:
20
38
  * @param parser The DOM parser that should be used for USX files.
21
39
  * @param overwrite Whether to force a reload of the translations.
22
40
  */
23
- export declare function importTranslationBatch(db: Database, dirs: string[], parser: DOMParser, overwrite: boolean): Promise<void>;
41
+ export declare const importTranslationBatch: (db: Database, dirs: string[], parser: DOMParser, overwrite: boolean) => Promise<void>;
42
+ /**
43
+ * Imports a batch of files from the given directories into the database.
44
+ * @param loadFilesFromDir The function that should be used to load the files from the given directory.
45
+ * @param db The database to import the files into.
46
+ * @param dirs The directories that contain the files.
47
+ * @param parser The DOM parser that should be used for USX files.
48
+ * @param overwrite Whether to force a reload of the files.
49
+ */
50
+ export declare function loadAndImportBatch(loadFilesFromDir: (path: string) => Promise<InputFile[] | null>, db: Database, dirs: string[], parser: DOMParser, overwrite: boolean): Promise<void>;
24
51
  /**
25
52
  * Parses and imports the given files into the database.
26
53
  * @param db The database to import the files into.
@@ -28,7 +55,7 @@ export declare function importTranslationBatch(db: Database, dirs: string[], par
28
55
  * @param parser The DOM parser that should be used for USX files.
29
56
  * @param overwrite Whether to force a reload of the translations.
30
57
  */
31
- export declare function importTranslationFileBatch(db: Database, files: InputFile[], parser: DOMParser, overwrite: boolean): Promise<void>;
58
+ export declare function importFileBatch(db: Database, files: InputFile[], parser: DOMParser, overwrite: boolean): Promise<void>;
32
59
  /**
33
60
  * Filters the given input files to only include those that have changed.
34
61
  * @param db The database to check for changes.
@@ -39,6 +66,9 @@ export declare function insertFileMetadata(db: Database, files: InputFile[]): vo
39
66
  export declare function insertTranslations(db: Database, translations: DatasetTranslation[]): void;
40
67
  export declare function insertTranslationBooks(db: Database, translation: DatasetTranslation, translationBooks: DatasetTranslationBook[]): void;
41
68
  export declare function insertTranslationContent(db: Database, translation: DatasetTranslation, book: DatasetTranslationBook, chapters: TranslationBookChapter[]): void;
69
+ export declare function insertCommentaries(db: Database, commentaries: DatasetCommentary[]): void;
70
+ export declare function insertCommentaryBooks(db: Database, commentary: DatasetCommentary, commentaryBooks: DatasetCommentaryBook[]): void;
71
+ export declare function insertCommentaryContent(db: Database, commentary: DatasetCommentary, book: DatasetCommentaryBook, chapters: CommentaryBookChapter[]): void;
42
72
  export declare function getDbPathFromDir(dir: string): string;
43
73
  export declare function getDbPath(p: string | null): string;
44
74
  export declare function getPrismaDbFromDir(dir: string): PrismaClient<{
@@ -47,7 +77,7 @@ export declare function getPrismaDbFromDir(dir: string): PrismaClient<{
47
77
  url: string;
48
78
  };
49
79
  };
50
- }, never, import("prisma-gen/runtime/library").DefaultArgs>;
80
+ }, never, import("prisma-gen/runtime/library.js").DefaultArgs>;
51
81
  export declare function getDbFromDir(dir: string): Promise<Database>;
52
82
  export declare function getDb(dbPath: string): Promise<Database>;
53
83
  export interface SerializedFile {
@@ -61,10 +91,24 @@ export interface SerializedFile {
61
91
  /**
62
92
  * Loads the datasets from the database in a series of batches.
63
93
  * @param db The database.
94
+ * @param perBatch The number of translations to load per batch.
95
+ * @param translationsToLoad The list of translations/commentaries to load. If not provided, all translations will be loaded.
96
+ */
97
+ export declare function loadDatasets(db: PrismaClient, perBatch?: number, translationsToLoad?: string[]): AsyncGenerator<DatasetOutput>;
98
+ /**
99
+ * Loads the translations from the database as a dataset.
100
+ * @param db The database.
64
101
  * @param translationsPerBatch The number of translations to load per batch.
65
102
  * @param translationsToLoad The list of translations to load. If not provided, all translations will be loaded.
66
103
  */
67
- export declare function loadDatasets(db: PrismaClient, translationsPerBatch?: number, translationsToLoad?: string[]): AsyncGenerator<DatasetOutput>;
104
+ export declare function loadTranslationDatasets(db: PrismaClient, translationsPerBatch?: number, translationsToLoad?: string[]): AsyncGenerator<DatasetOutput, void, unknown>;
105
+ /**
106
+ * Loads the commentaries from the database as a dataset.
107
+ * @param db The database.
108
+ * @param perBatch The number of translations to load per batch.
109
+ * @param commentariesToLoad The list of commentaries to load. If not provided, all commentaries will be loaded.
110
+ */
111
+ export declare function loadCommentaryDatasets(db: PrismaClient, perBatch?: number, commentariesToLoad?: string[]): AsyncGenerator<DatasetOutput, void, unknown>;
68
112
  export interface SerializeApiOptions extends GenerateApiOptions {
69
113
  /**
70
114
  * Whether the output should be pretty-printed.
@@ -0,0 +1,2 @@
1
+ export declare function downloadFile(url: string, path: string, onProgress?: (progress: number) => void): Promise<void>;
2
+ //# sourceMappingURL=downloads.d.ts.map
@@ -1,4 +1,4 @@
1
- import { InputFile, OutputFile } from '@helloao/tools/generation/common-types';
1
+ import { InputFile, OutputFile } from '@helloao/tools/generation/common-types.js';
2
2
  import { Readable } from 'stream';
3
3
  /**
4
4
  * Defines an interface that contains information about a serialized file.
@@ -68,6 +68,17 @@ export declare function loadTranslationsFiles(dirs: string[]): Promise<InputFile
68
68
  * @returns The list of files that were loaded, or null if the translation has no metadata.
69
69
  */
70
70
  export declare function loadTranslationFiles(translation: string): Promise<InputFile[] | null>;
71
+ /**
72
+ * Loads the files for the given commentaries.
73
+ * @param dir The directory that the commentaries exist in.
74
+ */
75
+ export declare function loadCommentariesFiles(dirs: string[]): Promise<InputFile[]>;
76
+ /**
77
+ * Loads the files for the given commentary.
78
+ * @param commentary The directory that the commentary exists in.
79
+ * @returns The list of files that were loaded, or null if the commentary has no metadata.
80
+ */
81
+ export declare function loadCommentaryFiles(commentary: string): Promise<InputFile[] | null>;
71
82
  export interface CollectionTranslationMetadata {
72
83
  name: {
73
84
  local: string;
@@ -0,0 +1,8 @@
1
+ import * as db from './db.js';
2
+ import * as downloads from './downloads.js';
3
+ import * as uploads from './uploads.js';
4
+ import * as actions from './actions.js';
5
+ import * as files from './files.js';
6
+ import * as s3 from './s3.js';
7
+ export { db, downloads, uploads, actions, files, s3 };
8
+ //# sourceMappingURL=index.d.ts.map
@@ -1,4 +1,4 @@
1
- import { SerializedFile, Uploader } from './files';
1
+ import { SerializedFile, Uploader } from './files.js';
2
2
  import { AwsCredentialIdentity, Provider } from '@smithy/types';
3
3
  export declare class S3Uploader implements Uploader {
4
4
  private _client;
@@ -1,8 +1,8 @@
1
- import { SerializedFile } from './db';
2
- import { Uploader } from './files';
3
- import { DatasetOutput } from '@helloao/tools/generation/dataset';
4
- import { PrismaClient } from './prisma-gen';
5
- import { GenerateApiOptions } from '@helloao/tools/generation/api';
1
+ import { SerializedFile } from './db.js';
2
+ import { Uploader } from './files.js';
3
+ import { DatasetOutput } from '@helloao/tools/generation/dataset.js';
4
+ import { PrismaClient } from './prisma-gen/index.js';
5
+ import { GenerateApiOptions } from '@helloao/tools/generation/api.js';
6
6
  export interface UploadApiFromDatabaseOptions extends UploadApiOptions, GenerateApiOptions {
7
7
  /**
8
8
  * The number of files to upload in each batch.
@@ -19,6 +19,11 @@ export interface UploadApiOptions {
19
19
  * "Common files" are files that are similar between translations, like the books.json endpoint, or individual chapter endpoints.
20
20
  */
21
21
  overwriteCommonFiles?: boolean;
22
+ /**
23
+ * Whether to only overwrite merged files.
24
+ * "Merged files" are files that are generated from multiple translations, like the available_translations.json endpoint.
25
+ */
26
+ overwriteMergedFiles?: boolean;
22
27
  /**
23
28
  * The file pattern regex that should be used to filter the files that are uploaded.
24
29
  */
@@ -51,6 +56,10 @@ export interface UploadApiOptions {
51
56
  * Whether to generate pretty-printed JSON files.
52
57
  */
53
58
  pretty?: boolean;
59
+ /**
60
+ * Whether to output verbose log information.
61
+ */
62
+ verbose?: boolean;
54
63
  }
55
64
  /**
56
65
  * Loads and generates the API files from the database and uploads them to the specified destination.
@@ -0,0 +1,56 @@
1
+ -- CreateTable
2
+ CREATE TABLE "Commentary" (
3
+ "id" TEXT NOT NULL PRIMARY KEY,
4
+ "name" TEXT NOT NULL,
5
+ "website" TEXT NOT NULL,
6
+ "licenseUrl" TEXT NOT NULL,
7
+ "englishName" TEXT NOT NULL,
8
+ "language" TEXT NOT NULL,
9
+ "textDirection" TEXT NOT NULL,
10
+ "sha256" TEXT
11
+ );
12
+
13
+ -- CreateTable
14
+ CREATE TABLE "CommentaryBook" (
15
+ "id" TEXT NOT NULL,
16
+ "commentaryId" TEXT NOT NULL,
17
+ "name" TEXT NOT NULL,
18
+ "commonName" TEXT NOT NULL,
19
+ "introduction" TEXT,
20
+ "order" INTEGER NOT NULL,
21
+ "numberOfChapters" INTEGER NOT NULL,
22
+ "sha256" TEXT,
23
+
24
+ PRIMARY KEY ("commentaryId", "id"),
25
+ CONSTRAINT "CommentaryBook_commentaryId_fkey" FOREIGN KEY ("commentaryId") REFERENCES "Commentary" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
26
+ );
27
+
28
+ -- CreateTable
29
+ CREATE TABLE "CommentaryChapter" (
30
+ "number" INTEGER NOT NULL,
31
+ "bookId" TEXT NOT NULL,
32
+ "commentaryId" TEXT NOT NULL,
33
+ "introduction" TEXT,
34
+ "json" TEXT NOT NULL,
35
+ "sha256" TEXT,
36
+
37
+ PRIMARY KEY ("commentaryId", "bookId", "number"),
38
+ CONSTRAINT "CommentaryChapter_commentaryId_bookId_fkey" FOREIGN KEY ("commentaryId", "bookId") REFERENCES "CommentaryBook" ("commentaryId", "id") ON DELETE RESTRICT ON UPDATE CASCADE,
39
+ CONSTRAINT "CommentaryChapter_commentaryId_fkey" FOREIGN KEY ("commentaryId") REFERENCES "Commentary" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
40
+ );
41
+
42
+ -- CreateTable
43
+ CREATE TABLE "CommentaryChapterVerse" (
44
+ "number" INTEGER NOT NULL,
45
+ "chapterNumber" INTEGER NOT NULL,
46
+ "bookId" TEXT NOT NULL,
47
+ "commentaryId" TEXT NOT NULL,
48
+ "text" TEXT NOT NULL,
49
+ "contentJson" TEXT NOT NULL,
50
+ "sha256" TEXT,
51
+
52
+ PRIMARY KEY ("commentaryId", "bookId", "chapterNumber", "number"),
53
+ CONSTRAINT "CommentaryChapterVerse_commentaryId_bookId_chapterNumber_fkey" FOREIGN KEY ("commentaryId", "bookId", "chapterNumber") REFERENCES "CommentaryChapter" ("commentaryId", "bookId", "number") ON DELETE RESTRICT ON UPDATE CASCADE,
54
+ CONSTRAINT "CommentaryChapterVerse_commentaryId_bookId_fkey" FOREIGN KEY ("commentaryId", "bookId") REFERENCES "CommentaryBook" ("commentaryId", "id") ON DELETE RESTRICT ON UPDATE CASCADE,
55
+ CONSTRAINT "CommentaryChapterVerse_commentaryId_fkey" FOREIGN KEY ("commentaryId") REFERENCES "Commentary" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
56
+ );
package/package.json CHANGED
@@ -1,16 +1,21 @@
1
1
  {
2
2
  "name": "@helloao/cli",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "description": "A CLI and related tools for managing HelloAO's Free Bible API",
5
- "module": "index.js",
6
- "types": "index.d.ts",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./dist/types/index.d.ts",
9
+ "require": "./dist/cjs/index.cjs"
10
+ }
11
+ },
7
12
  "bin": {
8
- "helloao": "./cli.js"
13
+ "helloao": "./dist/cjs/cli.cjs"
9
14
  },
10
15
  "author": "Kallyn Gowdy <kal@helloao.org>",
11
16
  "license": "MIT",
12
17
  "dependencies": {
13
- "@helloao/tools": "^0.0.5",
18
+ "@helloao/tools": "^0.0.10",
14
19
  "commander": "12.1.0",
15
20
  "@gracious.tech/fetch-client": "^0.7.0",
16
21
  "prisma": "^5.12.1",
@@ -25,6 +30,8 @@
25
30
  "@aws-sdk/client-s3": "^3.609.0",
26
31
  "@aws-sdk/credential-providers": "^3.609.0",
27
32
  "@smithy/types": "^3.3.0",
33
+ "@smithy/node-config-provider": "^3.1.9",
34
+ "@smithy/config-resolver": "^3.0.10",
28
35
  "@inquirer/prompts": "5.3.8",
29
36
  "all-iso-language-codes": "1.0.17"
30
37
  },