From b13e554162caa396e8fec0f94e789523edf6e9dc Mon Sep 17 00:00:00 2001 From: Avior Date: Thu, 11 Mar 2021 10:10:44 +0100 Subject: [PATCH] V2 added typing for compiler Signed-off-by: Avior --- .gitignore | 1 + .npmignore | 7 +- LICENSE.md | 2 +- TranslationUtil.ts | 53 --------- interfaces.d.ts | 234 ++++++++++++++++++++++++++++++++++++++ interfaces/Ability.ts | 19 ---- interfaces/AbilityType.ts | 19 ---- interfaces/Attack.ts | 20 ---- interfaces/Card.ts | 190 ------------------------------- interfaces/Category.ts | 24 ---- interfaces/Expansion.ts | 22 ---- interfaces/General.ts | 4 - interfaces/Hp.ts | 11 -- interfaces/Illustrator.ts | 22 ---- interfaces/LangList.ts | 15 --- interfaces/Langs.ts | 6 - interfaces/Rarity.ts | 31 ----- interfaces/Retreat.ts | 11 -- interfaces/Set.ts | 163 -------------------------- interfaces/Tag.ts | 98 ---------------- interfaces/Type.ts | 31 ----- package.json | 2 +- renovate.json | 5 - tcgdex.ts | 59 ++++------ tsconfig.json | 1 + 25 files changed, 268 insertions(+), 782 deletions(-) delete mode 100644 TranslationUtil.ts create mode 100644 interfaces.d.ts delete mode 100644 interfaces/Ability.ts delete mode 100644 interfaces/AbilityType.ts delete mode 100644 interfaces/Attack.ts delete mode 100644 interfaces/Card.ts delete mode 100644 interfaces/Category.ts delete mode 100644 interfaces/Expansion.ts delete mode 100644 interfaces/General.ts delete mode 100644 interfaces/Hp.ts delete mode 100644 interfaces/Illustrator.ts delete mode 100644 interfaces/LangList.ts delete mode 100644 interfaces/Langs.ts delete mode 100644 interfaces/Rarity.ts delete mode 100644 interfaces/Retreat.ts delete mode 100644 interfaces/Set.ts delete mode 100644 interfaces/Tag.ts delete mode 100644 interfaces/Type.ts delete mode 100644 renovate.json diff --git a/.gitignore b/.gitignore index f6204b5..e329e5d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ node_modules # Dist files *.js *.d.ts +!interfaces.d.ts test.ts diff --git a/.npmignore b/.npmignore index daa6029..3cc73c0 100644 --- a/.npmignore +++ b/.npmignore @@ -1 +1,6 @@ -test.js +.editorconfig +.gitignore +.npmignore +tsconfig.json +*.ts +yarn.lock diff --git a/LICENSE.md b/LICENSE.md index 94b89af..5f42b37 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -2,7 +2,7 @@ MIT License -Copyright (c) 2020 TCGdex +Copyright (c) 2021 TCGdex Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/TranslationUtil.ts b/TranslationUtil.ts deleted file mode 100644 index d9d7d82..0000000 --- a/TranslationUtil.ts +++ /dev/null @@ -1,53 +0,0 @@ -import LangList, { Langs } from "./interfaces/LangList"; -import AbilityType from "./interfaces/AbilityType"; -import Category from "./interfaces/Category"; -import Rarity from "./interfaces/Rarity"; -import Tag from "./interfaces/Tag"; -import Type from "./interfaces/Type"; - -import atTrans from './translations/abilityType' -import cTrans from './translations/category' -import rTrans from './translations/rarity' -import taTrans from './translations/tag' -import tyTrans from './translations/type' - -type possibilities = "abilityType" | "category" | "rarity" | "tag" | "type" - -export default class TranslationUtil { - public static translate(master: "abilityType",a: AbilityType, lang: Langs): string|undefined; - public static translate(master: "category",a: Category, lang: Langs): string|undefined; - public static translate(master: "rarity",a: Rarity, lang: Langs): string|undefined; - public static translate(master: "tag",a: Tag, lang: Langs): string|undefined; - public static translate(master: "type",a: Type, lang: Langs): string|undefined; - public static translate(master: possibilities,a: number, lang: Langs): string|undefined { - let langlist: LangList>|undefined - switch (master) { - case 'abilityType': - langlist = atTrans - break - case 'category': - langlist = cTrans - break - - case 'rarity': - langlist = rTrans - break - - case 'tag': - langlist = taTrans - break - - case 'type': - langlist = tyTrans - break - default: - break; - } - if (!langlist) return - const tmp = langlist[lang] - if (!tmp) return - return tmp[a] - } -} - -export type translations = LangList> diff --git a/interfaces.d.ts b/interfaces.d.ts new file mode 100644 index 0000000..eceddd7 --- /dev/null +++ b/interfaces.d.ts @@ -0,0 +1,234 @@ +export type SupportedLanguages = 'en' | 'fr' + +export type Languages = Partial> + +interface SerieResume { + id: string + name: string +} + +export interface Serie extends SerieResume { + sets: SetList +} + +interface variants { + normal?: boolean + reverse?: boolean + holo?: boolean + firstEdition?: boolean +} + +export type Types = 'Colorless' | 'Darkness' | 'Dragon' | +'Fairy' | 'Fightning' | 'Fire' | +'Grass' | 'Lightning' | 'Metal' | +'Psychic' | 'Water' + +export type SetList = Array +export type SerieList = Array +export type CardList = Array + +interface SetResume { + id: string + name: string +} + +export interface Set extends SetResume { + serie: Serie + tcgOnline?: string + variants?: variants + + cardCount: { + total: number + official: number + } + + releaseDate: string + + legal?: { + standard: boolean + expanded: boolean + } + + cards: CardList +} + +interface CardResume { + id: string + localId: string + + /** + * Card Name (Including the suffix if next to card name) + */ + name: string + image?: string +} + +export interface Card extends CardResume { + + /** + * Card illustrator + */ + illustrator?: string + + /** + * Card Rarity + * + * - None https://www.tcgdex.net/database/sm/smp/SM01 + * - Common https://www.tcgdex.net/database/xy/xy9/1 + * - Uncommon https://www.tcgdex.net/database/xy/xy9/2 + * - Rare https://www.tcgdex.net/database/xy/xy9/3 + * - Ultra Rare + * - Secret Rare + */ + rarity: 'None' | 'Common'| 'Uncommon' | 'Rare' | 'Ultra Rare' | 'Secret Rare' + + /** + * Card Category + * + * - Pokemon + * - Trainer + * - Energy + */ + category: 'Pokemon' | 'Trainer' | 'Energy' + + /** + * Card Variants (Override Set Variants) + */ + variants?: variants + + /** + * Card Set + */ + set: SetType + + /** + * Pokemon only elements + */ + + /** + * Pokemon Pokedex ID + */ + dexId?: Array + + /** + * Pokemon HP + */ + hp?: number + + /** + * Pokemon Types + */ + types?: Array // ex for multiple https://www.tcgdex.net/database/ex/ex13/17 + + /** + * Pokemon Sub Evolution + */ + evolveFrom?: string + + /** + * Pokemon Weight + */ + weight?: string + + /** + * Pokemon Description + */ + description?: string + + /** + * Level of the Pokemon + * + * NOTE: can be equal to 'X' when the pokemon is a LEVEL-UP one + */ + level?: number | string + + /** + * Pokemon Stage + * + * - Basic https://www.tcgdex.net/database/xy/xy9/1 + * - BREAK https://www.tcgdex.net/database/xy/xy9/18 + * - LEVEL-UP https://www.tcgdex.net/database/dp/dp1/121 + * - MEGA https://www.tcgdex.net/database/xy/xy1/2 + * - RESTORED https://www.tcgdex.net/database/bw/bw5/53 + * - Stage1 https://www.tcgdex.net/database/xy/xy9/2 + * - Stage2 https://www.tcgdex.net/database/xy/xy9/3 + * - VMAX https://www.tcgdex.net/database/swsh/swsh1/50 + */ + stage?: 'Basic' | 'BREAK' | 'LEVEL-UP' | 'MEGA' | 'RESTORED' | 'Stage1' | 'Stage2' | 'VMAX' + + /** + * Card Suffix + * + * - EX https://www.tcgdex.net/database/ex/ex2/94 + * - GX https://www.tcgdex.net/database/sm/sm12/4 + * - V https://www.tcgdex.net/database/swsh/swsh1/1 + * - Legend https://www.tcgdex.net/database/hgss/hgss1/114 + * - Prime https://www.tcgdex.net/database/hgss/hgss2/85 + * - SP https://www.tcgdex.net/database/pl/pl1/7 + * - TAG TEAM-GX https://www.tcgdex.net/database/sm/sm12/226 + */ + suffix?: 'EX' | 'GX' | 'V' | 'Legend' | 'Prime' | 'SP' | 'TAG TEAM-GX' + + /** + * Pokemon Held Item + * + * ex https://www.tcgdex.net/database/dp/dp2/75 + */ + item?: { + name: string + effect: string + } + + /** + * Pokemon Abilities + * + * multi abilities ex https://www.tcgdex.net/database/ex/ex15/10 + */ + abilities?: Array<{ + type: 'Pokemon Power' | 'Poke-BODY' | 'Poke-POWER' | 'Ability' | 'Ancient Trait' + name: string + effect: string + }> + + /** + * Pokemon Attacks + */ + attacks?: Array<{ + cost?: Array + name: string + effect?: string + damage?: string | number + }> + + /** + * Pokemon Weaknesses + */ + weaknesses?: Array<{ + type: Types + value?: string + }> + + resistances?: Array<{ + type: Types + value?: string + }> + + retreat?: number + + //Trainer/Energy + effect?: string + + // Trainer Only + trainerType?: 'Supporter' | // https://www.tcgdex.net/database/ex/ex7/83 + 'Item' | // https://www.tcgdex.net/database/ex/ex7/89 + 'Stadium' | // https://www.tcgdex.net/database/ex/ex7/87 + 'Tool' | // https://www.tcgdex.net/database/neo/neo1/93 + 'Ace Spec' | // https://www.tcgdex.net/database/bw/bw7/139 + 'Technical Machine' | // https://www.tcgdex.net/database/ecard/ecard1/144 + 'Goldenred Game Corner' | // https://www.tcgdex.net/database/neo/neo1/83 + 'Rocket\'s Secret Machine' // https://www.tcgdex.net/database/ex/ex7/84 + + // Energy Only + energyType?: 'Normal' | // https://www.tcgdex.net/database/ecard/ecard1/160 + 'Special' // https://www.tcgdex.net/database/ecard/ecard1/158 +} diff --git a/interfaces/Ability.ts b/interfaces/Ability.ts deleted file mode 100644 index 86d73b1..0000000 --- a/interfaces/Ability.ts +++ /dev/null @@ -1,19 +0,0 @@ -import AbilityType, { AbilityTypeSimple } from "./AbilityType"; -import LangList from "./LangList"; - -export interface AbilitySingle extends AbilitySimple { - type: AbilityTypeSimple - text: string -} - -export interface AbilitySimple { - // id: number // WIP - name: string -} - -export default interface Ability { - id?: number - type: AbilityType - name: LangList - text: LangList -} diff --git a/interfaces/AbilityType.ts b/interfaces/AbilityType.ts deleted file mode 100644 index c6b32c4..0000000 --- a/interfaces/AbilityType.ts +++ /dev/null @@ -1,19 +0,0 @@ -export interface AbilityTypeSimple { - id: AbilityType - name: string -} - -export type AbilityTypeSingle = { - id: AbilityType - name: string - cards: string -} - -enum AbilityType { - POKEBODY, - POKEPOWER, - TALENT, - ANCIENTTRAIT -} - -export default AbilityType diff --git a/interfaces/Attack.ts b/interfaces/Attack.ts deleted file mode 100644 index 95ff2a0..0000000 --- a/interfaces/Attack.ts +++ /dev/null @@ -1,20 +0,0 @@ -import Type from "./Type"; -import LangList from "./LangList"; - -export interface AttackSingle extends AttackSimple { - cost?: Array - text?: string - damage?: string|number -} - -export interface AttackSimple { - // id: number - name: string -} - -export default interface Attack { - cost?: Array - name: LangList - text?: LangList - damage?: string|number -} diff --git a/interfaces/Card.ts b/interfaces/Card.ts deleted file mode 100644 index 5300425..0000000 --- a/interfaces/Card.ts +++ /dev/null @@ -1,190 +0,0 @@ -import Type, { TypeSimple } from "./Type"; -import Tag, { TagSimple } from "./Tag"; -import { RaritySimple, Rarity } from "./Rarity"; -import { CategorySimple, Category } from "./Category"; -import { IllustratorSimple } from "./Illustrator"; -import Ability, { AbilitySingle } from "./Ability"; -import Attack, { AttackSingle } from "./Attack"; -import { List } from "./General"; -import LangList from "./LangList"; -import Set from "./Set"; - -export interface CardSimple { - id: string - localId: string|number - name: string - image: string -} - -export interface CardSingle { - // General - id: string - - /** - * The Set Card ID - */ - localId: number | string - - /** - * The card Name - */ - name: string - - /** - * The Card Picture - * it doesn't contains the ext as it is available as .png, .jpg, .webp (HINT: use .webp then .png then .jpg) - */ - image?: { - low: string - high?: string - } - - /** - * Card Tags - */ - tags?: Array - - /** - * Card illustrator informations - */ - illustrator?: IllustratorSimple - - /** - * Card Rarity - */ - rarity: RaritySimple - - /** - * Card Category - */ - category: CategorySimple - - /** - * Card Set - */ - set: { - /** - * Set Display name - */ - name: string - - /** - * Set code/id - */ - code: string - } - - /** - * This will be set for each cards - * define all the variants for a specific card - */ - variants: { - normal: boolean - reverse: boolean - holo: boolean - firstEd: boolean - } - - /** - * Some Pokémons have item like a berry - */ - item?: { - name: string - effect: string - } - - // Pokémon only - hp?: number - dexId?: number - lvl?: number - type?: Array - evolveFrom?: string - evolveTo?: Array - abilities?: Array - attacks?: Array - weaknesses?: Array - - resistances?: Array - retreat?: number - - // Trainer/Energy only - effect?: string -} - -export type CardList = List - -type WeakRes = { - type: TypeSimple - value?: string -} - -type Card = { - - // global id made of setid and localId - id: string - - // set id - localId: string|number - - dexId?: number - - // Card informations (from top to bottom of card) - name: LangList - hp?: number //optionnal because energy/trainer cards might have not any hp - type?: Array // ex for multiple https://www.tcgdex.net/database/ex/ex13/17 - - image?: { - low: LangList - high?: LangList - } - - evolveFrom?: LangList - evolveTo?: Array> - tags?: Array // made after - illustrator?: string - - abilities?: Array - - attacks?: Array - - // If card is trainer or energy effect is here - effect?: LangList - - item?: { - name: LangList - effect: LangList - } - - weaknesses?: Array<{ - type: Type - value?: string - }> - - resistances?: Array<{ - type: Type - value?: string - }> - - retreat?: number - - rarity: Rarity - - // Other elements - category: Category - set: { - name: string - code: string - }| Set - - /** - * Override Set defaults - */ - cardTypes?: { - normal: boolean - reverse: boolean - holo: boolean - firstEd: boolean - } -} - -export default Card diff --git a/interfaces/Category.ts b/interfaces/Category.ts deleted file mode 100644 index 107fb2b..0000000 --- a/interfaces/Category.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { List } from "./General" -import { CardSimple } from "./Card" - -export enum Category { - POKEMON, - TRAINER, - ENERGY -} - -export default Category - -export type CategorySingle = { - id: Category - name: string - cards: Array -} - - -export type CategorySimple = { - id: Category - name: string -} - -export type CategoryList = List diff --git a/interfaces/Expansion.ts b/interfaces/Expansion.ts deleted file mode 100644 index 4c3ac9e..0000000 --- a/interfaces/Expansion.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { SetSimple } from "./Set"; -import { List } from "./General"; -import LangList from "./LangList"; - -export type ExpansionSingle = { - code: string - name: string - sets: Array -} - -export type ExpansionSimple = { - code: string - name: string -} - -export type ExpansionList = List - -export default interface Expansion { - name: LangList | string - code: string - sets?: Array -} diff --git a/interfaces/General.ts b/interfaces/General.ts deleted file mode 100644 index 885ba24..0000000 --- a/interfaces/General.ts +++ /dev/null @@ -1,4 +0,0 @@ -export type List = { - count: number - list: Array -} diff --git a/interfaces/Hp.ts b/interfaces/Hp.ts deleted file mode 100644 index df6466a..0000000 --- a/interfaces/Hp.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { CardSimple } from "./Card"; -import { List } from "./General"; - -export type HpSingle = { - hp: number - cards: Array -} - -export type HpSimple = number - -export type HpList = List diff --git a/interfaces/Illustrator.ts b/interfaces/Illustrator.ts deleted file mode 100644 index 4174794..0000000 --- a/interfaces/Illustrator.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { CardSimple } from "./Card"; -import { List } from "./General"; - -export type IllustratorSingle = { - id: number, - name: string, - cards: Array -} - -export interface IllustratorSimple { - id: number - name: string -} - -export type IllustratorsList = List - -interface Illustrator { - id: number - name: string -} - -export default Illustrator diff --git a/interfaces/LangList.ts b/interfaces/LangList.ts deleted file mode 100644 index 2a3b54c..0000000 --- a/interfaces/LangList.ts +++ /dev/null @@ -1,15 +0,0 @@ -type LangList = { - [key in Langs]?: T -} - -export type Langs = "en" | "fr" - -namespace LangList { - export function insert(from: LangList, el: any, lang: Langs) { - if (typeof from !== "object") from = {} - from[lang] = el - return from - } -} - -export default LangList diff --git a/interfaces/Langs.ts b/interfaces/Langs.ts deleted file mode 100644 index 1ecaedb..0000000 --- a/interfaces/Langs.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { Langs as l } from './LangList' - -/** - * @deprecated - */ -export type Langs = l diff --git a/interfaces/Rarity.ts b/interfaces/Rarity.ts deleted file mode 100644 index 518cce2..0000000 --- a/interfaces/Rarity.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { List } from "./General" -import { CardSimple } from "./Card" - -export enum Rarity { - NONE, - COMMON, - UNCOMMON, - RARE, - - // Both RAREULTRA and ULTRARARE are the same until I know the correct name - RAREULTRA = 4, - ULTRARARE = 4, - - AMAZING, - -} - -export default Rarity - -export interface RaritySimple { - id: Rarity - name: string -} - -export type RaritySingle = { - id: Rarity - name: string - cards: Array -} - -export type RarityList = List diff --git a/interfaces/Retreat.ts b/interfaces/Retreat.ts deleted file mode 100644 index f8e9948..0000000 --- a/interfaces/Retreat.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { CardSimple } from "./Card"; -import { List } from "./General"; - -export type RetreatSimple = number - -export interface RetreatSingle { - id: RetreatSimple - cards: Array -} - -export type RetreatList = List diff --git a/interfaces/Set.ts b/interfaces/Set.ts deleted file mode 100644 index e4618ae..0000000 --- a/interfaces/Set.ts +++ /dev/null @@ -1,163 +0,0 @@ -import { CardSimple } from "./Card"; -import { List } from "./General"; -import LangList from "./LangList"; -import Expansion from "./Expansion"; - -export type SetRequest = SetSingle - -export interface SetSingleRaw extends SetSingle { - releaseDate: string -} - -export type SetSingle = { - name: string - code: string - - expansionCode?: string - tcgoCode?: string - - cardCount: { - total: number - official: number - } - - releaseDate: Date | string - - legal?: { - standard: boolean - expanded: boolean - } - - images?: { - symbol?: string - logo?: string - } - - list: Array -} - -export type SetSimple = { - code: string - name: string - logo?: string - symbol?: string - total: number -} - -export type SetList = List - - -export default interface Set { - /** - * Display Name - */ - name: LangList | string - - /** - * Expansion Object - */ - expansion?: Expansion - - /** - * Expansion code - */ - expansionCode?: string - - /** - * Set code (Also used as the slug) - */ - code: string - - /** - * Trading card online code - */ - tcgoCode?: string - - cardCount: { - /** - * total number of cards including secrets - */ - total: number - /** - * number of card indicated at the bottom of each cards - */ - official: number - } - - cardTypes?: { - /** - * Default: true - */ - normal: boolean - /** - * Default: true - */ - reverse: boolean - /** - * Default: true - */ - holo: boolean - /** - * Default: false - */ - ed1: boolean - } - - /** - * Format of numbering - * ex: SWSH[000] mean that it has SWSH as prefix and start at 000 -> 001 -> 002 -> etc - * - * @type {string} - * @memberof Set - */ - format?: string - - /** - * Release date of the set - * in format: yyyy-mm-dd - * ex: 2002-12-22 - * - * @type {string} - * @memberof Set - */ - releaseDate: string // date in format yyyy-mm-dd - - /** - * Aol Endpoint for scrapping - */ - api?: string - - /** - * Competition usage - */ - legal?: { - standard: boolean - expanded: boolean - } - - images?: { - /** - * Symbol icon on bottom of card - * available extensions [ - * webp - * jpg - * png - * ] - */ - symbol?: string - /** - * Official logo of set - * available extensions [ - * webp - * jpg - * png - * ] - */ - logo?: string - } - - /** - * Language in which the set is available - */ - availability?: LangList -} diff --git a/interfaces/Tag.ts b/interfaces/Tag.ts deleted file mode 100644 index 4fe9983..0000000 --- a/interfaces/Tag.ts +++ /dev/null @@ -1,98 +0,0 @@ -import { List } from "./General" -import { CardSimple } from "./Card" -/** - * Anum of "Tags" each card can contains - * - * @enum {number} - */ -enum Tag { - /** - * basic pokémon - */ - BASIC, - - /** - * Basic Energy - */ - BASICENERGY, - BREAK, - EX, - GX, - ITEM, - LEGEND, - LEVELUP, - MEGA, - RESTORED, - ROCKETSECRETMACHINE, - SP, - SPECIAL, - STADIUM, - /** - * Stage 1 pokémon - */ - STAGE1, - - /** - * Stage 2 Pokémon - */ - STAGE2, - SUPPORTER, - TAGTEAM, - TECHNICALMACHINE, - TOOL, - - /** - * V Pokémon - */ - V, - - /** - * VMAX Pokémon - */ - VMAX, - - /** - * The card is available with the holographic picture - */ - HASHOLO, - - /** - * Card can have a 1st badge - */ - HAS1ST, - - /** - * Card is full art (art is not in the frame) - */ - ISFULLART, - - /** - * PRIME Pokemon - */ - PRIME, - - /** - * ACE Pokemon - */ - ACE, - - /** - * Card is "rainbow" - */ - RAINBOW, -} - -export default Tag - -export interface TagSimple { - id: Tag - name: string -} - -export type TagSingle = { - id: Tag - name: string - cards: Array -} - -export type TagList = List diff --git a/interfaces/Type.ts b/interfaces/Type.ts deleted file mode 100644 index 53ab22b..0000000 --- a/interfaces/Type.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { List } from "./General" -import { CardSimple } from "./Card" - -enum Type { - COLORLESS, - DARKNESS, - DRAGON, - FAIRY, - FIGHTING, - FIRE, - GRASS, - LIGHTNING, - METAL, - PSYCHIC, - WATER, -} - -export interface TypeSimple { - id: Type - name: string -} - -export type TypeSingle = { - id: Type - name: string - cards: Array -} - -export type TypeList = List - -export default Type diff --git a/package.json b/package.json index a7275c4..7816f90 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@tcgdex/sdk", - "version": "1.8.0", + "version": "2.0.0-alpha.1", "main": "./tcgdex.js", "types": "./tcgdex.d.ts", "repository": "https://github.com/tcgdex/javascript-sdk.git", diff --git a/renovate.json b/renovate.json deleted file mode 100644 index f45d8f1..0000000 --- a/renovate.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "extends": [ - "config:base" - ] -} diff --git a/tcgdex.ts b/tcgdex.ts index 703dd19..ed24a3c 100644 --- a/tcgdex.ts +++ b/tcgdex.ts @@ -1,16 +1,10 @@ -import { SetSingle, SetSimple, SetList, SetSingleRaw } from './interfaces/Set' -import { CardSingle, CardList, CardSimple } from './interfaces/Card' -import { ExpansionSingle, ExpansionList } from './interfaces/Expansion' import RequestWrapper from './Request' -import { Langs } from './interfaces/LangList' +import { Serie, Set, Card, CardResume, SerieList, SetList, SupportedLanguages } from './interfaces' export default class TCGdex { - public static defaultLang: Langs = "en" - public lang?: Langs + public static defaultLang: SupportedLanguages = "en" - public constructor(lang?: Langs) { - if (lang) this.lang = lang - } + public constructor(public lang?: SupportedLanguages) {} public getLang() { return this.lang || TCGdex.defaultLang @@ -18,78 +12,73 @@ export default class TCGdex { private getBaseUrl() { - return `https://api.tcgdex.net/v1/${this.getLang()}` + return `https://api.tcgdex.net/v2/${this.getLang()}` } private gbu() { return this.getBaseUrl() } - public async getCard(id: string|number, set: string): Promise - public async getCard(id: string): Promise - public async getCard(id: string|number, set?: string): Promise { + public async getCard(id: string|number, full: true, set?: string): Promise | undefined> + // @ts-expect-error Temporary while building it in the compiler + public async getCard(id: string|number, full?: boolean, set?: string): Promise { const txt = set ? `sets/${set}` : "cards" - const req = this.rwgr(`${this.gbu()}/${txt}/${id}/`) + const req = this.rwgr(`${this.gbu()}/${txt}/${id}/`) return req.get() } - public async getCards(set?: string): Promise | undefined> { + public async getCards(set?: string): Promise | undefined> { if (set) { const setSingle = await this.getSet(set) if (!setSingle) { return undefined } - return setSingle.list + return setSingle.cards } - const req = this.rwgr(`${this.gbu()}/cards/`) + const req = this.rwgr>(`/cards/`) const resp = await req.get() if (!resp) { return undefined } - return resp.list + return resp } - public async getSet(set: string, transformDate: false): Promise - public async getSet(set: string, transformDate?: true): Promise - public async getSet(set: string, transformDate?: boolean): Promise { - const req = this.rwgr(`${this.gbu()}/sets/${set}/`) + public async getSet(set: string): Promise { + const req = this.rwgr(`/sets/${set}/`) const resp = await req.get() if (!resp) { return undefined } - if (!transformDate) { - return resp as SetSingleRaw - } - return Object.assign(resp, {releaseDate: new Date(resp.releaseDate)}) as SetSingle + return resp } - public async getExpansion(expansion: string): Promise { - const req = this.rwgr(`${this.gbu()}/expansions/${expansion}/`) + public async getSerie(expansion: string): Promise { + const req = this.rwgr(`/expansions/${expansion}/`) return req.get() } - public async getExpansions(): Promise { - const req = this.rwgr(`${this.gbu()}/expansions/`) + public async getSeries(): Promise { + const req = this.rwgr(`/expansions/`) return req.get() } - public async getSets(expansion?: string): Promise | undefined> { + public async getSets(expansion?: string): Promise { if (expansion) { - const expansionSingle = await this.getExpansion(expansion) + const expansionSingle = await this.getSerie(expansion) if (!expansionSingle) { return undefined } return expansionSingle.sets } - const req = this.rwgr(`${this.gbu()}/sets/`) + const req = this.rwgr(`/sets/`) const list = await req.get() if (!list) { return undefined } - return list.list + return list } private rwgr(url: string) { - return RequestWrapper.getRequest(url) + return RequestWrapper.getRequest(`${this.gbu()}${url}`) } } diff --git a/tsconfig.json b/tsconfig.json index 64da6b9..aab8c05 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,5 +1,6 @@ { "include": ["**/*.ts"], + "exclude": ["translations"], "compilerOptions": { /* Basic Options */ // "incremental": true, /* Enable incremental compilation */