shamela 1.5.0 → 1.5.2

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,4 +1,4 @@
1
- import { i as Category, t as Author, u as MasterData } from "./types-CeDA67OZ.js";
1
+ import { i as Category, n as Book, t as Author, u as MasterData } from "./types-CeDA67OZ.js";
2
2
 
3
3
  //#region src/transform.d.ts
4
4
  type DenormalizedAuthor = Pick<Author, 'id' | 'name'> & {
@@ -31,11 +31,9 @@ type BookMetadata = {
31
31
  group?: number;
32
32
  hide_diacritic?: boolean;
33
33
  };
34
- type DenormalizedBook = {
34
+ type DenormalizedBook = Pick<Book, 'id' | 'bibliography' | 'name'> & {
35
35
  author: DenormalizedAuthor;
36
- bibliography?: string;
37
36
  date?: number;
38
- name: string;
39
37
  hint?: string;
40
38
  type?: number;
41
39
  category: DenormalizedCategory;
package/dist/transform.js CHANGED
@@ -1,2 +1,2 @@
1
- import{UNKNOWN_VALUE_PLACEHOLDER as e}from"./utils/constants.js";const t=(e,...t)=>Object.fromEntries(t.map(t=>[t,e[t]]).filter(([e,t])=>t)),n=e=>{let t={},n={},r={};return e.authors.forEach(e=>{t[e.id]=e}),e.books.forEach(e=>{n[e.id]=e}),e.categories.forEach(e=>{r[e.id]=e}),{idToAuthor:t,idToBook:n,idToCategory:r}},r=e=>({id:e.id,name:e.name,...e.biography&&{biography:e.biography},...e.death_text&&{death:Number(e.death_number)}}),i=e=>({id:e.id,name:e.name,order:Number(e.order)}),a=(e,n)=>({...e.coauthor&&{coauthor:e.coauthor.map(e=>r(n[e]))},date:e.date,...t(e,`group`,`hide_diacritic`,`min_ver`,`prefix`,`shorts`,`suffix`)}),o=e=>{let n=e.files.map(e=>{let[t,n]=e.split(`|`);return{...n&&{part:n},name:t}});return{...t(e,`alias`,`cover`,`cover_alias`,`size`,`root`,`folder`),...n.length&&{files:n},...e.cover&&{cover:e.cover},...e.folder&&{folder:e.folder},...e.size&&{size:e.size}}},s=t=>{let s=n(t);return t.books.map(t=>({author:r(s.idToAuthor[t.author]),bibliography:t.bibliography,category:i(s.idToCategory[t.category]),...t.date!==e&&{date:Number(t.date)},...t.hint&&{hint:t.hint},metadata:a(JSON.parse(t.metadata),s.idToAuthor),name:t.name,...t.pdf_links&&{pdf_links:o(JSON.parse(t.pdf_links))},printed:Number(t.printed),version:`${t.major_release}.${t.minor_release}`}))};export{s as denormalizeBooks};
1
+ import{UNKNOWN_VALUE_PLACEHOLDER as e}from"./utils/constants.js";const t=(e,...t)=>Object.fromEntries(t.map(t=>[t,e[t]]).filter(([e,t])=>t)),n=e=>{let t={},n={},r={};return e.authors.forEach(e=>{t[e.id]=e}),e.books.forEach(e=>{n[e.id]=e}),e.categories.forEach(e=>{r[e.id]=e}),{idToAuthor:t,idToBook:n,idToCategory:r}},r=e=>({id:e.id,name:e.name,...e.biography&&{biography:e.biography},...e.death_text&&{death:Number(e.death_number)}}),i=e=>({id:e.id,name:e.name,order:Number(e.order)}),a=(e,n)=>({...e.coauthor&&{coauthor:e.coauthor.map(e=>r(n[e]))},date:e.date,...t(e,`group`,`hide_diacritic`,`min_ver`,`prefix`,`shorts`,`suffix`)}),o=e=>{let n=(e.files||[]).map(e=>{let[t,n]=e.split(`|`);return{...n&&{part:n},name:t}});return{...t(e,`alias`,`cover`,`cover_alias`,`size`,`root`,`folder`),...n.length&&{files:n},...e.cover&&{cover:e.cover},...e.folder&&{folder:e.folder},...e.size&&{size:e.size}}},s=t=>{let s=n(t);return t.books.map(t=>{let[n,...c]=t.author.split(/, ?/).map(e=>r(s.idToAuthor[e])),l=a(JSON.parse(t.metadata),s.idToAuthor);return c.length&&(l.coauthor=(l.coauthor||[]).concat(c)),{author:n,bibliography:t.bibliography,category:i(s.idToCategory[t.category]),...t.date!==e&&{date:Number(t.date)},...t.hint&&{hint:t.hint},id:t.id,metadata:l,name:t.name,...t.pdf_links&&{pdf_links:o(JSON.parse(t.pdf_links))},printed:Number(t.printed),version:`${t.major_release}.${t.minor_release}`}})};export{s as denormalizeBooks};
2
2
  //# sourceMappingURL=transform.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"transform.js","names":[],"sources":["../src/transform.ts"],"sourcesContent":["import type { Author, Book, Category, MasterData } from './types';\nimport { UNKNOWN_VALUE_PLACEHOLDER } from './utils/constants';\n\nexport type DenormalizedAuthor = Pick<Author, 'id' | 'name'> & { death?: number; biography?: string };\n\nexport type DenormalizedCategory = Pick<Category, 'id' | 'name'> & { order: number };\n\ntype PdfFile = { part?: string; name: string };\n\ntype PdfInfo = {\n alias?: number;\n files?: PdfFile[];\n cover?: number;\n cover_alias?: number;\n size?: number;\n root?: string;\n folder?: [number, string];\n};\n\nexport type BookMetadata = {\n date: string;\n shorts?: Record<string, string>;\n prefix?: string;\n coauthor?: DenormalizedAuthor[];\n min_ver?: number;\n suffix?: string;\n group?: number;\n hide_diacritic?: boolean;\n};\n\nexport type DenormalizedBook = {\n author: DenormalizedAuthor;\n bibliography?: string;\n date?: number;\n name: string;\n hint?: string;\n type?: number;\n category: DenormalizedCategory;\n pdf_links?: PdfInfo;\n printed: number;\n version: string;\n metadata: BookMetadata;\n};\n\ntype StructureIndexes = {\n idToAuthor: Record<string, Author>;\n idToBook: Record<string, Book>;\n idToCategory: Record<string, Category>;\n};\n\nconst pickTruthy = <T extends Record<string, any>, K extends keyof T>(obj: T, ...keys: K[]): Partial<Pick<T, K>> => {\n return Object.fromEntries(keys.map((key) => [key, obj[key]]).filter(([_, v]) => v)) as Partial<Pick<T, K>>;\n};\n\nconst indexStructures = (master: MasterData): StructureIndexes => {\n const idToAuthor: Record<string, Author> = {};\n const idToBook: Record<string, Book> = {};\n const idToCategory: Record<string, Category> = {};\n\n master.authors.forEach((a) => {\n idToAuthor[a.id] = a;\n });\n\n master.books.forEach((a) => {\n idToBook[a.id] = a;\n });\n\n master.categories.forEach((a) => {\n idToCategory[a.id] = a;\n });\n\n return { idToAuthor, idToBook, idToCategory };\n};\n\nconst denormalizeAuthor = (author: Author) => {\n return {\n id: author.id,\n name: author.name,\n ...(author.biography && { biography: author.biography }),\n ...(author.death_text && { death: Number(author.death_number) }),\n };\n};\n\nconst denormalizeCategory = (category: Category) => {\n return {\n id: category.id,\n name: category.name,\n order: Number(category.order),\n };\n};\n\nconst parseBookMetadata = (metadata: Record<string, any>, idToAuthor: Record<string, Author>): BookMetadata => {\n return {\n ...(metadata.coauthor && {\n coauthor: metadata.coauthor.map((id: number) => denormalizeAuthor(idToAuthor[id])),\n }),\n date: metadata.date,\n ...pickTruthy(metadata, 'group', 'hide_diacritic', 'min_ver', 'prefix', 'shorts', 'suffix'),\n };\n};\n\nconst parsePdfLinks = (pdf: Record<string, any>): PdfInfo => {\n const files = (pdf.files as string[]).map((f) => {\n const [name, part] = f.split('|');\n return { ...(part && { part }), name };\n });\n\n return {\n ...pickTruthy(pdf, 'alias', 'cover', 'cover_alias', 'size', 'root', 'folder'),\n ...(files.length && { files }),\n ...(pdf.cover && { cover: pdf.cover }),\n ...(pdf.folder && { folder: pdf.folder }),\n ...(pdf.size && { size: pdf.size }),\n };\n};\n\nexport const denormalizeBooks = (master: MasterData): DenormalizedBook[] => {\n const indexes = indexStructures(master);\n const result = master.books.map((book) => {\n return {\n author: denormalizeAuthor(indexes.idToAuthor[book.author]),\n bibliography: book.bibliography,\n category: denormalizeCategory(indexes.idToCategory[book.category]),\n ...(book.date !== UNKNOWN_VALUE_PLACEHOLDER && { date: Number(book.date) }),\n ...(book.hint && { hint: book.hint }),\n metadata: parseBookMetadata(JSON.parse(book.metadata), indexes.idToAuthor),\n name: book.name,\n ...(book.pdf_links && { pdf_links: parsePdfLinks(JSON.parse(book.pdf_links)) }),\n printed: Number(book.printed),\n version: `${book.major_release}.${book.minor_release}`,\n };\n });\n\n return result;\n};\n"],"mappings":"iEAkDA,MAAM,GAAgE,EAAQ,GAAG,IACtE,OAAO,YAAY,EAAK,IAAK,GAAQ,CAAC,EAAK,EAAI,GAAK,CAAC,CAAC,QAAQ,CAAC,EAAG,K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EAAoB,GAA2C,CACxE,IAAM,EAAU,EAAgB,EAAO,CAgBvC,OAfe,EAAO,MAAM,IAAK,IACtB,CACH,OAAQ,EAAkB,EAAQ,WAAW,EAAK,QAAQ,CAC1D,aAAc,EAAK,aACnB,SAAU,EAAoB,EAAQ,aAAa,EAAK,UAAU,CAClE,GAAI,EAAK,OAAS,GAA6B,CAAE,KAAM,OAAO,EAAK,KAAK,CAAE,CAC1E,GAAI,EAAK,MAAQ,CAAE,KAAM,EAAK,KAAM,CACpC,SAAU,EAAkB,KAAK,MAAM,EAAK,SAAS,CAAE,EAAQ,WAAW,CAC1E,KAAM,EAAK,KACX,GAAI,EAAK,WAAa,CAAE,UAAW,EAAc,KAAK,MAAM,EAAK,UAAU,CAAC,CAAE,CAC9E,QAAS,OAAO,EAAK,QAAQ,CAC7B,QAAS,GAAG,EAAK,cAAc,GAAG,EAAK,gBAC1C,EACH"}
1
+ {"version":3,"file":"transform.js","names":[],"sources":["../src/transform.ts"],"sourcesContent":["import type { Author, Book, Category, MasterData } from './types';\nimport { UNKNOWN_VALUE_PLACEHOLDER } from './utils/constants';\n\nexport type DenormalizedAuthor = Pick<Author, 'id' | 'name'> & { death?: number; biography?: string };\n\nexport type DenormalizedCategory = Pick<Category, 'id' | 'name'> & { order: number };\n\ntype PdfFile = { part?: string; name: string };\n\ntype PdfInfo = {\n alias?: number;\n files?: PdfFile[];\n cover?: number;\n cover_alias?: number;\n size?: number;\n root?: string;\n folder?: [number, string];\n};\n\nexport type BookMetadata = {\n date: string;\n shorts?: Record<string, string>;\n prefix?: string;\n coauthor?: DenormalizedAuthor[];\n min_ver?: number;\n suffix?: string;\n group?: number;\n hide_diacritic?: boolean;\n};\n\nexport type DenormalizedBook = Pick<Book, 'id' | 'bibliography' | 'name'> & {\n author: DenormalizedAuthor;\n date?: number;\n hint?: string;\n type?: number;\n category: DenormalizedCategory;\n pdf_links?: PdfInfo;\n printed: number;\n version: string;\n metadata: BookMetadata;\n};\n\ntype StructureIndexes = {\n idToAuthor: Record<string, Author>;\n idToBook: Record<string, Book>;\n idToCategory: Record<string, Category>;\n};\n\nconst pickTruthy = <T extends Record<string, any>, K extends keyof T>(obj: T, ...keys: K[]): Partial<Pick<T, K>> => {\n return Object.fromEntries(keys.map((key) => [key, obj[key]]).filter(([_, v]) => v)) as Partial<Pick<T, K>>;\n};\n\nconst indexStructures = (master: MasterData): StructureIndexes => {\n const idToAuthor: Record<string, Author> = {};\n const idToBook: Record<string, Book> = {};\n const idToCategory: Record<string, Category> = {};\n\n master.authors.forEach((a) => {\n idToAuthor[a.id] = a;\n });\n\n master.books.forEach((a) => {\n idToBook[a.id] = a;\n });\n\n master.categories.forEach((a) => {\n idToCategory[a.id] = a;\n });\n\n return { idToAuthor, idToBook, idToCategory };\n};\n\nconst denormalizeAuthor = (author: Author) => {\n return {\n id: author.id,\n name: author.name,\n ...(author.biography && { biography: author.biography }),\n ...(author.death_text && { death: Number(author.death_number) }),\n };\n};\n\nconst denormalizeCategory = (category: Category) => {\n return {\n id: category.id,\n name: category.name,\n order: Number(category.order),\n };\n};\n\nconst parseBookMetadata = (metadata: Record<string, any>, idToAuthor: Record<string, Author>): BookMetadata => {\n return {\n ...(metadata.coauthor && {\n coauthor: metadata.coauthor.map((id: number) => denormalizeAuthor(idToAuthor[id])),\n }),\n date: metadata.date,\n ...pickTruthy(metadata, 'group', 'hide_diacritic', 'min_ver', 'prefix', 'shorts', 'suffix'),\n };\n};\n\nconst parsePdfLinks = (pdf: Record<string, any>): PdfInfo => {\n const files = (pdf.files || []).map((f: string) => {\n const [name, part] = f.split('|');\n return { ...(part && { part }), name };\n });\n\n return {\n ...pickTruthy(pdf, 'alias', 'cover', 'cover_alias', 'size', 'root', 'folder'),\n ...(files.length && { files }),\n ...(pdf.cover && { cover: pdf.cover }),\n ...(pdf.folder && { folder: pdf.folder }),\n ...(pdf.size && { size: pdf.size }),\n };\n};\n\nexport const denormalizeBooks = (master: MasterData): DenormalizedBook[] => {\n const indexes = indexStructures(master);\n const result = master.books.map((book) => {\n const [author, ...coauthors] = book.author.split(/, ?/).map((a) => denormalizeAuthor(indexes.idToAuthor[a]));\n const metadata = parseBookMetadata(JSON.parse(book.metadata), indexes.idToAuthor);\n\n if (coauthors.length) {\n metadata.coauthor = (metadata.coauthor || []).concat(coauthors);\n }\n\n return {\n author,\n bibliography: book.bibliography,\n category: denormalizeCategory(indexes.idToCategory[book.category]),\n ...(book.date !== UNKNOWN_VALUE_PLACEHOLDER && { date: Number(book.date) }),\n ...(book.hint && { hint: book.hint }),\n id: book.id,\n metadata,\n name: book.name,\n ...(book.pdf_links && { pdf_links: parsePdfLinks(JSON.parse(book.pdf_links)) }),\n printed: Number(book.printed),\n version: `${book.major_release}.${book.minor_release}`,\n };\n });\n\n return result;\n};\n"],"mappings":"iEAgDA,MAAM,GAAgE,EAAQ,GAAG,IACtE,OAAO,YAAY,EAAK,IAAK,GAAQ,CAAC,EAAK,EAAI,GAAK,CAAC,CAAC,QAAQ,CAAC,EAAG,KAAO,EAAE,CAAC,CAGjF,EAAmB,GAAyC,CAC9D,IAAM,EAAqC,EAAE,CACvC,EAAiC,EAAE,CACnC,EAAyC,EAAE,CAcjD,OAZA,EAAO,QAAQ,QAAS,GAAM,CAC1B,EAAW,EAAE,IAAM,GACrB,CAEF,EAAO,MAAM,QAAS,GAAM,CACxB,EAAS,EAAE,IAAM,GACnB,CAEF,EAAO,WAAW,QAAS,GAAM,CAC7B,EAAa,EAAE,IAAM,GACvB,CAEK,CAAE,aAAY,WAAU,eAAc,EAG3C,EAAqB,IAChB,CACH,GAAI,EAAO,GACX,KAAM,EAAO,KACb,GAAI,EAAO,WAAa,CAAE,UAAW,EAAO,UAAW,CACvD,GAAI,EAAO,YAAc,CAAE,MAAO,OAAO,EAAO,aAAa,CAAE,CAClE,EAGC,EAAuB,IAClB,CACH,GAAI,EAAS,GACb,KAAM,EAAS,KACf,MAAO,OAAO,EAAS,MAAM,CAChC,EAGC,GAAqB,EAA+B,KAC/C,CACH,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