UNPKG

shamela

Version:

Library to interact with the Maktabah Shamela v4 APIs

184 lines 6.13 kB
//#region src/db/types.d.ts /** * A record that can be deleted by patches. */ type Deletable = { /** Indicates if it was deleted in the patch if it is set to '1 */is_deleted?: string; }; type Unique = { /** Unique identifier */id: number; }; /** * Database row structure for the author table. */ type AuthorRow = Deletable & Unique & { /** Author biography */biography: string | null; /** Death year or UNKNOWN_VALUE_PLACEHOLDER */ death_number: string; /** The death year as a text */ death_text: string | null; /** Author name */ name: string; }; /** * Database row structure for the book table. */ type BookRow = Deletable & Unique & { /** Serialized author ID(s) "2747, 3147" or "513" */author: string; /** Bibliography information */ bibliography: string; /** Category ID */ category: string; /** Publication date (or 99999 for unavailable) */ date: string; /** Hint or description */ hint: string | null; /** Major version */ major_release: string; /** Serialized metadata */ metadata: string; /** Minor version */ minor_release: string; /** Book name */ name: string; /** Serialized PDF links */ pdf_links: string | null; /** Printed flag */ printed: string; /** Book type */ type: string; }; /** * Database row structure for the category table. */ type CategoryRow = Deletable & Unique & { /** Category name */name: string; /** Category order in the list to show. */ order: string; }; /** * Database row structure for the page table. */ type PageRow = Deletable & Unique & { /** Page content */content: string; /** Page number */ number: string | null; /** Page reference */ page: string | null; /** Part number */ part: string | null; /** Additional metadata */ services: string | null; }; /** * Database row structure for the title table. */ type TitleRow = Deletable & Unique & { /** Title content */content: string; /** Page number */ page: string; /** Parent title ID */ parent: string | null; }; //#endregion //#region src/types.d.ts /** * Represents an author entity. */ type Author = AuthorRow; /** * Represents a book entity. */ type Book = BookRow; /** * A category for a book. */ type Category = CategoryRow; /** * A page in a book. */ type Page = Pick<PageRow, 'id' | 'content'> & { page?: number; part?: string; number?: string; }; /** * A title heading in a book. */ type Title = Pick<TitleRow, 'id' | 'content'> & { page: number; parent?: number; }; /** * Represents book content data. */ type BookData = { /** Array of pages in the book */pages: Page[]; /** Array of titles/chapters */ titles: Title[]; }; /** * Master data structure containing all core entities. */ type MasterData = { /** Array of all authors */authors: Author[]; /** Array of all books */ books: Book[]; /** Array of all categories */ categories: Category[]; /** Version number for the downloaded master database */ version: number; }; /** * Options for downloading a book. */ type DownloadBookOptions = { /** Optional book metadata */bookMetadata?: GetBookMetadataResponsePayload; /** Output file configuration */ outputFile: OutputOptions; }; /** * Options for downloading master data. */ type DownloadMasterOptions = { /** Optional master metadata */masterMetadata?: GetMasterMetadataResponsePayload; /** Output file configuration */ outputFile: OutputOptions; }; /** * Options for getting book metadata. */ type GetBookMetadataOptions = { /** Major version number */majorVersion: number; /** Minor version number */ minorVersion: number; }; /** * Response payload for book metadata requests. */ type GetBookMetadataResponsePayload = { /** Major release version */majorRelease: number; /** URL for major release download */ majorReleaseUrl: string; /** Optional minor release version */ minorRelease?: number; /** Optional URL for minor release download */ minorReleaseUrl?: string; }; /** * Response payload for master metadata requests. */ type GetMasterMetadataResponsePayload = { /** Download URL */url: string; /** Version number */ version: number; }; type NodeJSOutput = { /** Output file path (Node.js only) */path: string; writer?: never; }; type CustomOutput = { /** Custom writer used when path is not provided */writer: (payload: string | Uint8Array) => Promise<void> | void; path?: undefined; }; /** * Output file options. */ type OutputOptions = NodeJSOutput | CustomOutput; /** * Runtime configuration for the library. */ type ShamelaConfig = { /** API key used to authenticate against Shamela services */apiKey?: string; /** Endpoint used for book metadata */ booksEndpoint?: string; /** Endpoint used for master metadata */ masterPatchEndpoint?: string; /** Optional override for the sql.js wasm asset location */ sqlJsWasmUrl?: string; /** Optional custom fetch implementation for environments without a global fetch */ fetchImplementation?: typeof fetch; }; /** * Valid configuration keys. */ type ShamelaConfigKey = keyof ShamelaConfig; type TitleSpanStrategy = 'splitLines' | 'merge' | 'hierarchy'; type NormalizeTitleSpanOptions = { /** * How to handle adjacent `<span data-type="title">...</span>` runs. * * - `splitLines`: Keep each title span, but insert `\\n` between them so downstream conversion produces one header per line. * - `merge`: Merge adjacent title spans into a single title span, joining text with `separator`. * - `hierarchy`: Keep first title span as-is, convert subsequent adjacent title spans to `data-type="subtitle"` and insert `\\n` between them. */ strategy: TitleSpanStrategy; /** Used only for `merge` strategy. Default: `' — '`. */ separator?: string; }; //#endregion export { TitleSpanStrategy as _, DownloadBookOptions as a, GetBookMetadataResponsePayload as c, NormalizeTitleSpanOptions as d, OutputOptions as f, Title as g, ShamelaConfigKey as h, Category as i, GetMasterMetadataResponsePayload as l, ShamelaConfig as m, Book as n, DownloadMasterOptions as o, Page as p, BookData as r, GetBookMetadataOptions as s, Author as t, MasterData as u }; //# sourceMappingURL=types-CeDA67OZ.d.ts.map