@helloao/cli 0.0.14 → 0.0.16

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.
@@ -118,6 +118,12 @@ export declare function importCommentary(dir: string, dirs: string[], options: I
118
118
  * @param options The options.
119
119
  */
120
120
  export declare function importCommentaries(dir: string, options: ImportTranslationOptions): Promise<void>;
121
+ /**
122
+ * Imports the API from the given directory into the database in the current working directory.
123
+ * @param dir The directory that the API is located in.
124
+ * @param options The options.
125
+ */
126
+ export declare function importApi(dir: string, options: ImportTranslationOptions): Promise<void>;
121
127
  export interface FetchTranslationsOptions {
122
128
  /**
123
129
  * Fetch all translations. If omitted, only undownloaded translations will be fetched.
@@ -1,7 +1,7 @@
1
1
  import { PrismaClient } from './prisma-gen/index.js';
2
2
  import { Database } from 'better-sqlite3';
3
- import { DatasetCommentary, DatasetCommentaryBook, DatasetCommentaryProfile, DatasetOutput, DatasetTranslation, DatasetTranslationBook } from '@helloao/tools/generation/dataset.js';
4
- import { InputFile, TranslationBookChapter, CommentaryBookChapter } from '@helloao/tools/generation/index.js';
3
+ import { DatasetCommentary, DatasetCommentaryBook, DatasetCommentaryProfile, DatasetDataset, DatasetDatasetBook, DatasetOutput, DatasetTranslation, DatasetTranslationBook } from '@helloao/tools/generation/dataset.js';
4
+ import { InputFile, TranslationBookChapter, CommentaryBookChapter, DatasetBookChapter } from '@helloao/tools/generation/index.js';
5
5
  import { GenerateApiOptions } from '@helloao/tools/generation/api.js';
6
6
  import type { DOMParser } from 'linkedom';
7
7
  import { Readable } from 'stream';
@@ -56,6 +56,12 @@ export declare function loadAndImportBatch(loadFilesFromDir: (path: string) => P
56
56
  * @param overwrite Whether to force a reload of the translations.
57
57
  */
58
58
  export declare function importFileBatch(db: Database, files: InputFile[], parser: DOMParser, overwrite: boolean): Promise<void>;
59
+ /**
60
+ * Imports the given dataset output into the database.
61
+ * @param db The database to import the dataset into.
62
+ * @param output The dataset output to import.
63
+ */
64
+ export declare function importDatasetOutput(db: Database, output: DatasetOutput): void;
59
65
  /**
60
66
  * Filters the given input files to only include those that have changed.
61
67
  * @param db The database to check for changes.
@@ -70,6 +76,9 @@ export declare function insertCommentaries(db: Database, commentaries: DatasetCo
70
76
  export declare function insertCommentaryBooks(db: Database, commentary: DatasetCommentary, commentaryBooks: DatasetCommentaryBook[]): void;
71
77
  export declare function insertCommentaryProfiles(db: Database, commentary: DatasetCommentary, commentaryProfiles: DatasetCommentaryProfile[]): void;
72
78
  export declare function insertCommentaryContent(db: Database, commentary: DatasetCommentary, book: DatasetCommentaryBook, chapters: CommentaryBookChapter[]): void;
79
+ export declare function insertDatasets(db: Database, datasets: DatasetDataset[]): void;
80
+ export declare function insertDatasetBooks(db: Database, dataset: DatasetDataset, datasetBooks: DatasetDatasetBook[]): void;
81
+ export declare function insertDatasetContent(db: Database, dataset: DatasetDataset, book: DatasetDatasetBook, chapters: DatasetBookChapter[]): void;
73
82
  export declare function getDbPathFromDir(dir: string): string;
74
83
  export declare function getDbPath(p?: string | null): string;
75
84
  export declare function getPrismaDb(path?: string | null): PrismaClient<{
@@ -114,6 +123,13 @@ export declare function loadTranslationDatasets(db: PrismaClient, translationsPe
114
123
  * @param commentariesToLoad The list of commentaries to load. If not provided, all commentaries will be loaded.
115
124
  */
116
125
  export declare function loadCommentaryDatasets(db: PrismaClient, perBatch?: number, commentariesToLoad?: string[]): AsyncGenerator<DatasetOutput, void, unknown>;
126
+ /**
127
+ * Loads the datasets from the database as a dataset.
128
+ * @param db The database.
129
+ * @param perBatch The number of translations to load per batch.
130
+ * @param datasetsToLoad The list of commentaries to load. If not provided, all commentaries will be loaded.
131
+ */
132
+ export declare function loadDatasetDatasets(db: PrismaClient, perBatch?: number, datasetsToLoad?: string[]): AsyncGenerator<DatasetOutput, void, unknown>;
117
133
  export interface SerializeApiOptions extends GenerateApiOptions {
118
134
  /**
119
135
  * Whether the output should be pretty-printed.
@@ -1,5 +1,6 @@
1
1
  import { InputFile, InputTranslationMetadata, OutputFile } from '@helloao/tools/generation/common-types.js';
2
2
  import { Readable } from 'stream';
3
+ import { DatasetDataset } from '@helloao/tools/generation/dataset.js';
3
4
  /**
4
5
  * Defines an interface that contains information about a serialized file.
5
6
  */
@@ -79,6 +80,12 @@ export declare function loadCommentariesFiles(dirs: string[]): Promise<InputFile
79
80
  * @returns The list of files that were loaded, or null if the commentary has no metadata.
80
81
  */
81
82
  export declare function loadCommentaryFiles(commentary: string): Promise<InputFile[] | null>;
83
+ /**
84
+ * Imports all the datasets from the given directory into the database in the current working directory.
85
+ * @param dir The directory that the datasets are located in.
86
+ * @param options The options.
87
+ */
88
+ export declare function loadDatasetsFromDirectory(dir: string): Promise<DatasetDataset[]>;
82
89
  export interface CollectionTranslationMetadata {
83
90
  name: {
84
91
  local: string;
@@ -0,0 +1,72 @@
1
+ -- CreateTable
2
+ CREATE TABLE "Dataset" (
3
+ "id" TEXT NOT NULL PRIMARY KEY,
4
+ "name" TEXT NOT NULL,
5
+ "website" TEXT NOT NULL,
6
+ "licenseUrl" TEXT NOT NULL,
7
+ "licenseNotes" TEXT,
8
+ "englishName" TEXT NOT NULL,
9
+ "language" TEXT NOT NULL,
10
+ "textDirection" TEXT NOT NULL,
11
+ "sha256" TEXT
12
+ );
13
+
14
+ -- CreateTable
15
+ CREATE TABLE "DatasetBook" (
16
+ "id" TEXT NOT NULL,
17
+ "datasetId" TEXT NOT NULL,
18
+ "name" TEXT NOT NULL,
19
+ "commonName" TEXT NOT NULL,
20
+ "introduction" TEXT,
21
+ "introductionSummary" TEXT,
22
+ "order" INTEGER NOT NULL,
23
+ "numberOfChapters" INTEGER NOT NULL,
24
+ "sha256" TEXT,
25
+
26
+ PRIMARY KEY ("datasetId", "id"),
27
+ CONSTRAINT "DatasetBook_datasetId_fkey" FOREIGN KEY ("datasetId") REFERENCES "Dataset" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
28
+ );
29
+
30
+ -- CreateTable
31
+ CREATE TABLE "DatasetChapter" (
32
+ "number" INTEGER NOT NULL,
33
+ "bookId" TEXT NOT NULL,
34
+ "datasetId" TEXT NOT NULL,
35
+ "json" TEXT NOT NULL,
36
+ "sha256" TEXT,
37
+
38
+ PRIMARY KEY ("datasetId", "bookId", "number"),
39
+ CONSTRAINT "DatasetChapter_datasetId_bookId_fkey" FOREIGN KEY ("datasetId", "bookId") REFERENCES "DatasetBook" ("datasetId", "id") ON DELETE RESTRICT ON UPDATE CASCADE,
40
+ CONSTRAINT "DatasetChapter_datasetId_fkey" FOREIGN KEY ("datasetId") REFERENCES "Dataset" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
41
+ );
42
+
43
+ -- CreateTable
44
+ CREATE TABLE "DatasetChapterVerse" (
45
+ "number" INTEGER NOT NULL,
46
+ "chapterNumber" INTEGER NOT NULL,
47
+ "bookId" TEXT NOT NULL,
48
+ "datasetId" TEXT NOT NULL,
49
+ "contentJson" TEXT NOT NULL,
50
+ "sha256" TEXT,
51
+
52
+ PRIMARY KEY ("datasetId", "bookId", "chapterNumber", "number"),
53
+ CONSTRAINT "DatasetChapterVerse_datasetId_bookId_chapterNumber_fkey" FOREIGN KEY ("datasetId", "bookId", "chapterNumber") REFERENCES "DatasetChapter" ("datasetId", "bookId", "number") ON DELETE RESTRICT ON UPDATE CASCADE,
54
+ CONSTRAINT "DatasetChapterVerse_datasetId_bookId_fkey" FOREIGN KEY ("datasetId", "bookId") REFERENCES "DatasetBook" ("datasetId", "id") ON DELETE RESTRICT ON UPDATE CASCADE,
55
+ CONSTRAINT "DatasetChapterVerse_datasetId_fkey" FOREIGN KEY ("datasetId") REFERENCES "Dataset" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
56
+ );
57
+
58
+ -- CreateTable
59
+ CREATE TABLE "DatasetReference" (
60
+ "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
61
+ "datasetId" TEXT NOT NULL,
62
+ "bookId" TEXT NOT NULL,
63
+ "chapterNumber" INTEGER NOT NULL,
64
+ "verseNumber" INTEGER NOT NULL,
65
+ "endVerseNumber" INTEGER,
66
+ "score" INTEGER,
67
+ "sha256" TEXT,
68
+ CONSTRAINT "DatasetReference_datasetId_fkey" FOREIGN KEY ("datasetId") REFERENCES "Dataset" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
69
+ CONSTRAINT "DatasetReference_datasetId_bookId_fkey" FOREIGN KEY ("datasetId", "bookId") REFERENCES "DatasetBook" ("datasetId", "id") ON DELETE RESTRICT ON UPDATE CASCADE,
70
+ CONSTRAINT "DatasetReference_datasetId_bookId_chapterNumber_fkey" FOREIGN KEY ("datasetId", "bookId", "chapterNumber") REFERENCES "DatasetChapter" ("datasetId", "bookId", "number") ON DELETE RESTRICT ON UPDATE CASCADE,
71
+ CONSTRAINT "DatasetReference_datasetId_bookId_chapterNumber_verseNumber_fkey" FOREIGN KEY ("datasetId", "bookId", "chapterNumber", "verseNumber") REFERENCES "DatasetChapterVerse" ("datasetId", "bookId", "chapterNumber", "number") ON DELETE RESTRICT ON UPDATE CASCADE
72
+ );
@@ -0,0 +1,50 @@
1
+ /*
2
+ Warnings:
3
+
4
+ - You are about to drop the column `commonName` on the `DatasetBook` table. All the data in the column will be lost.
5
+ - You are about to drop the column `introduction` on the `DatasetBook` table. All the data in the column will be lost.
6
+ - You are about to drop the column `introductionSummary` on the `DatasetBook` table. All the data in the column will be lost.
7
+ - You are about to drop the column `name` on the `DatasetBook` table. All the data in the column will be lost.
8
+ - You are about to drop the column `sha256` on the `DatasetReference` table. All the data in the column will be lost.
9
+ - Added the required column `referenceBookId` to the `DatasetReference` table without a default value. This is not possible if the table is not empty.
10
+ - Added the required column `referenceChapter` to the `DatasetReference` table without a default value. This is not possible if the table is not empty.
11
+ - Added the required column `referenceVerse` to the `DatasetReference` table without a default value. This is not possible if the table is not empty.
12
+
13
+ */
14
+ -- RedefineTables
15
+ PRAGMA defer_foreign_keys=ON;
16
+ PRAGMA foreign_keys=OFF;
17
+ CREATE TABLE "new_DatasetBook" (
18
+ "id" TEXT NOT NULL,
19
+ "datasetId" TEXT NOT NULL,
20
+ "order" INTEGER NOT NULL,
21
+ "numberOfChapters" INTEGER NOT NULL,
22
+ "sha256" TEXT,
23
+
24
+ PRIMARY KEY ("datasetId", "id"),
25
+ CONSTRAINT "DatasetBook_datasetId_fkey" FOREIGN KEY ("datasetId") REFERENCES "Dataset" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
26
+ );
27
+ INSERT INTO "new_DatasetBook" ("datasetId", "id", "numberOfChapters", "order", "sha256") SELECT "datasetId", "id", "numberOfChapters", "order", "sha256" FROM "DatasetBook";
28
+ DROP TABLE "DatasetBook";
29
+ ALTER TABLE "new_DatasetBook" RENAME TO "DatasetBook";
30
+ CREATE TABLE "new_DatasetReference" (
31
+ "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
32
+ "datasetId" TEXT NOT NULL,
33
+ "bookId" TEXT NOT NULL,
34
+ "chapterNumber" INTEGER NOT NULL,
35
+ "verseNumber" INTEGER NOT NULL,
36
+ "referenceBookId" TEXT NOT NULL,
37
+ "referenceChapter" INTEGER NOT NULL,
38
+ "referenceVerse" INTEGER NOT NULL,
39
+ "endVerseNumber" INTEGER,
40
+ "score" INTEGER,
41
+ CONSTRAINT "DatasetReference_datasetId_fkey" FOREIGN KEY ("datasetId") REFERENCES "Dataset" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
42
+ CONSTRAINT "DatasetReference_datasetId_bookId_fkey" FOREIGN KEY ("datasetId", "bookId") REFERENCES "DatasetBook" ("datasetId", "id") ON DELETE RESTRICT ON UPDATE CASCADE,
43
+ CONSTRAINT "DatasetReference_datasetId_bookId_chapterNumber_fkey" FOREIGN KEY ("datasetId", "bookId", "chapterNumber") REFERENCES "DatasetChapter" ("datasetId", "bookId", "number") ON DELETE RESTRICT ON UPDATE CASCADE,
44
+ CONSTRAINT "DatasetReference_datasetId_bookId_chapterNumber_verseNumber_fkey" FOREIGN KEY ("datasetId", "bookId", "chapterNumber", "verseNumber") REFERENCES "DatasetChapterVerse" ("datasetId", "bookId", "chapterNumber", "number") ON DELETE RESTRICT ON UPDATE CASCADE
45
+ );
46
+ INSERT INTO "new_DatasetReference" ("bookId", "chapterNumber", "datasetId", "endVerseNumber", "id", "score", "verseNumber") SELECT "bookId", "chapterNumber", "datasetId", "endVerseNumber", "id", "score", "verseNumber" FROM "DatasetReference";
47
+ DROP TABLE "DatasetReference";
48
+ ALTER TABLE "new_DatasetReference" RENAME TO "DatasetReference";
49
+ PRAGMA foreign_keys=ON;
50
+ PRAGMA defer_foreign_keys=OFF;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@helloao/cli",
3
- "version": "0.0.14",
3
+ "version": "0.0.16",
4
4
  "description": "A CLI and related tools for managing HelloAO's Free Bible API",
5
5
  "main": "./dist/cjs/index.cjs",
6
6
  "module": "./dist/esm/index.js",
@@ -43,7 +43,7 @@
43
43
  "all-iso-language-codes": "1.0.17",
44
44
  "papaparse": "5.4.1",
45
45
  "luxon": "3.5.0",
46
- "@helloao/tools": "0.0.14"
46
+ "@helloao/tools": "0.0.16"
47
47
  },
48
48
  "files": [
49
49
  "/README.md",