Added multiple endpoints (#18)

Added new endpoints:
energyTypes
trainerTypes
suffixes
stages
dexIds
regulationMarks
variants
This commit is contained in:
Florian Bouillon 2021-10-07 13:04:23 +02:00 committed by GitHub
parent 19f060bfd6
commit 5069fb9945
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 761 additions and 377 deletions

View File

@ -1,4 +1,4 @@
import { CardList, Card as CardSingle } from '@tcgdex/sdk/interfaces' import { CardList, Card as CardSingle } from '@tcgdex/sdk/dist/types/interfaces'
import { Card, Languages } from '../db/interfaces' import { Card, Languages } from '../db/interfaces'
import { Endpoint } from '../interfaces' import { Endpoint } from '../interfaces'
import { cardToCardSimple, cardToCardSingle, getCards } from '../utils/cardUtil' import { cardToCardSimple, cardToCardSingle, getCards } from '../utils/cardUtil'

View File

@ -1,4 +1,4 @@
import { StringEndpointList, StringEndpoint } from '@tcgdex/sdk/interfaces' import { StringEndpointList, StringEndpoint } from '@tcgdex/sdk/dist/types/interfaces'
import translate from '../utils/translationUtil' import translate from '../utils/translationUtil'
import { Card, Languages } from '../db/interfaces' import { Card, Languages } from '../db/interfaces'
import { Endpoint } from '../interfaces' import { Endpoint } from '../interfaces'

44
endpoints/dex-ids.ts Normal file
View File

@ -0,0 +1,44 @@
import { StringEndpointList, StringEndpoint } from '@tcgdex/sdk/dist/types/interfaces'
import { Card, Languages } from '../db/interfaces'
import { Endpoint } from '../interfaces'
import { cardToCardSimple, getCards } from '../utils/cardUtil'
export default class implements Endpoint<StringEndpointList, StringEndpoint, Record<string, unknown>, Record<string, Array<[string, Card]>>> {
public constructor(
private lang: keyof Languages
) {}
public async index(common: Record<string, Array<[string, Card]>>): Promise<StringEndpointList> {
return Object.keys(common)
}
public async item(common: Record<string, Array<[string, Card]>>): Promise<Record<string, StringEndpoint>> {
const items: Record<string, StringEndpoint> = {}
for await (const key of Object.keys(common)) {
const val = common[key]
items[key] = {
cards: await Promise.all(val.map(([id, card]) => cardToCardSimple(id, card, this.lang))),
name: key
}
}
return items
}
public async common(): Promise<Record<string, Array<[string, Card]>>> {
return (await getCards(this.lang)).reduce((p, c) => {
const ids = c[1].dexId
if (!ids) {
return p
}
for (const id of ids) {
if (!p[id]) {
p[id] = []
}
p[id].push(c)
}
return p
}, {} as Record<string, Array<[string, Card]>>)
}
}

42
endpoints/energy-types.ts Normal file
View File

@ -0,0 +1,42 @@
import { StringEndpointList, StringEndpoint } from '@tcgdex/sdk/dist/types/interfaces'
import { Card, Languages } from '../db/interfaces'
import { Endpoint } from '../interfaces'
import { cardToCardSimple, getCards } from '../utils/cardUtil'
export default class implements Endpoint<StringEndpointList, StringEndpoint, Record<string, unknown>, Record<string, Array<[string, Card]>>> {
public constructor(
private lang: keyof Languages
) {}
public async index(common: Record<string, Array<[string, Card]>>): Promise<StringEndpointList> {
return Object.keys(common)
}
public async item(common: Record<string, Array<[string, Card]>>): Promise<Record<string, StringEndpoint>> {
const items: Record<string, StringEndpoint> = {}
for await (const key of Object.keys(common)) {
const val = common[key]
items[key] = {
cards: await Promise.all(val.map(([id, card]) => cardToCardSimple(id, card, this.lang))),
name: key
}
}
return items
}
public async common(): Promise<Record<string, Array<[string, Card]>>> {
return (await getCards(this.lang)).reduce((p, c) => {
const { energyType } = c[1]
if (!energyType) {
return p
}
if (!p[energyType]) {
p[energyType] = []
}
p[energyType].push(c)
return p
}, {} as Record<string, Array<[string, Card]>>)
}
}

View File

@ -1,4 +1,4 @@
import { StringEndpointList, StringEndpoint } from '@tcgdex/sdk/interfaces' import { StringEndpointList, StringEndpoint } from '@tcgdex/sdk/dist/types/interfaces'
import { Card, Languages } from '../db/interfaces' import { Card, Languages } from '../db/interfaces'
import { Endpoint } from '../interfaces' import { Endpoint } from '../interfaces'
import { cardToCardSimple, getCards } from '../utils/cardUtil' import { cardToCardSimple, getCards } from '../utils/cardUtil'

View File

@ -1,4 +1,4 @@
import { StringEndpointList, StringEndpoint } from '@tcgdex/sdk/interfaces' import { StringEndpointList, StringEndpoint } from '@tcgdex/sdk/dist/types/interfaces'
import { Card, Languages } from '../db/interfaces' import { Card, Languages } from '../db/interfaces'
import { Endpoint } from '../interfaces' import { Endpoint } from '../interfaces'
import { cardToCardSimple, getCards } from '../utils/cardUtil' import { cardToCardSimple, getCards } from '../utils/cardUtil'

View File

@ -1,4 +1,4 @@
import { StringEndpointList, StringEndpoint } from '@tcgdex/sdk/interfaces' import { StringEndpointList, StringEndpoint } from '@tcgdex/sdk/dist/types/interfaces'
import translate from '../utils/translationUtil' import translate from '../utils/translationUtil'
import { Card, Languages } from '../db/interfaces' import { Card, Languages } from '../db/interfaces'
import { Endpoint } from '../interfaces' import { Endpoint } from '../interfaces'

View File

@ -0,0 +1,42 @@
import { StringEndpointList, StringEndpoint } from '@tcgdex/sdk/dist/types/interfaces'
import { Card, Languages } from '../db/interfaces'
import { Endpoint } from '../interfaces'
import { cardToCardSimple, getCards } from '../utils/cardUtil'
export default class implements Endpoint<StringEndpointList, StringEndpoint, Record<string, unknown>, Record<string, Array<[string, Card]>>> {
public constructor(
private lang: keyof Languages
) {}
public async index(common: Record<string, Array<[string, Card]>>): Promise<StringEndpointList> {
return Object.keys(common)
}
public async item(common: Record<string, Array<[string, Card]>>): Promise<Record<string, StringEndpoint>> {
const items: Record<string, StringEndpoint> = {}
for await (const key of Object.keys(common)) {
const val = common[key]
items[key] = {
cards: await Promise.all(val.map(([id, card]) => cardToCardSimple(id, card, this.lang))),
name: key
}
}
return items
}
public async common(): Promise<Record<string, Array<[string, Card]>>> {
return (await getCards(this.lang)).reduce((p, c) => {
const { regulationMark } = c[1]
if (!regulationMark) {
return p
}
if (!p[regulationMark]) {
p[regulationMark] = []
}
p[regulationMark].push(c)
return p
}, {} as Record<string, Array<[string, Card]>>)
}
}

View File

@ -1,4 +1,4 @@
import { StringEndpointList, StringEndpoint } from '@tcgdex/sdk/interfaces' import { StringEndpointList, StringEndpoint } from '@tcgdex/sdk/dist/types/interfaces'
import { Card, Languages } from '../db/interfaces' import { Card, Languages } from '../db/interfaces'
import { Endpoint } from '../interfaces' import { Endpoint } from '../interfaces'
import { cardToCardSimple, getCards } from '../utils/cardUtil' import { cardToCardSimple, getCards } from '../utils/cardUtil'

View File

@ -1,4 +1,4 @@
import { Serie as SerieSingle, SerieList, SerieResume } from '@tcgdex/sdk/interfaces' import { Serie as SerieSingle, SerieList, SerieResume } from '@tcgdex/sdk/dist/types/interfaces'
import { Languages, Serie } from '../db/interfaces' import { Languages, Serie } from '../db/interfaces'
import { Endpoint } from '../interfaces' import { Endpoint } from '../interfaces'
import { getSeries, serieToSerieSimple, serieToSerieSingle } from '../utils/serieUtil' import { getSeries, serieToSerieSimple, serieToSerieSingle } from '../utils/serieUtil'

View File

@ -1,4 +1,4 @@
import { SetList, Set as SetSingle, Card as CardSingle } from '@tcgdex/sdk/interfaces' import { SetList, Set as SetSingle, Card as CardSingle } from '@tcgdex/sdk/dist/types/interfaces'
import { getSets, isSetAvailable, setToSetSimple, setToSetSingle } from '../utils/setUtil' import { getSets, isSetAvailable, setToSetSimple, setToSetSingle } from '../utils/setUtil'
import { Languages, Set } from '../db/interfaces' import { Languages, Set } from '../db/interfaces'
import { Endpoint } from '../interfaces' import { Endpoint } from '../interfaces'

42
endpoints/stages.ts Normal file
View File

@ -0,0 +1,42 @@
import { StringEndpointList, StringEndpoint } from '@tcgdex/sdk/dist/types/interfaces'
import { Card, Languages } from '../db/interfaces'
import { Endpoint } from '../interfaces'
import { cardToCardSimple, getCards } from '../utils/cardUtil'
export default class implements Endpoint<StringEndpointList, StringEndpoint, Record<string, unknown>, Record<string, Array<[string, Card]>>> {
public constructor(
private lang: keyof Languages
) {}
public async index(common: Record<string, Array<[string, Card]>>): Promise<StringEndpointList> {
return Object.keys(common)
}
public async item(common: Record<string, Array<[string, Card]>>): Promise<Record<string, StringEndpoint>> {
const items: Record<string, StringEndpoint> = {}
for await (const key of Object.keys(common)) {
const val = common[key]
items[key] = {
cards: await Promise.all(val.map(([id, card]) => cardToCardSimple(id, card, this.lang))),
name: key
}
}
return items
}
public async common(): Promise<Record<string, Array<[string, Card]>>> {
return (await getCards(this.lang)).reduce((p, c) => {
const { stage } = c[1]
if (!stage) {
return p
}
if (!p[stage]) {
p[stage] = []
}
p[stage].push(c)
return p
}, {} as Record<string, Array<[string, Card]>>)
}
}

42
endpoints/suffixes.ts Normal file
View File

@ -0,0 +1,42 @@
import { StringEndpointList, StringEndpoint } from '@tcgdex/sdk/dist/types/interfaces'
import { Card, Languages } from '../db/interfaces'
import { Endpoint } from '../interfaces'
import { cardToCardSimple, getCards } from '../utils/cardUtil'
export default class implements Endpoint<StringEndpointList, StringEndpoint, Record<string, unknown>, Record<string, Array<[string, Card]>>> {
public constructor(
private lang: keyof Languages
) {}
public async index(common: Record<string, Array<[string, Card]>>): Promise<StringEndpointList> {
return Object.keys(common)
}
public async item(common: Record<string, Array<[string, Card]>>): Promise<Record<string, StringEndpoint>> {
const items: Record<string, StringEndpoint> = {}
for await (const key of Object.keys(common)) {
const val = common[key]
items[key] = {
cards: await Promise.all(val.map(([id, card]) => cardToCardSimple(id, card, this.lang))),
name: key
}
}
return items
}
public async common(): Promise<Record<string, Array<[string, Card]>>> {
return (await getCards(this.lang)).reduce((p, c) => {
const { suffix } = c[1]
if (!suffix) {
return p
}
if (!p[suffix]) {
p[suffix] = []
}
p[suffix].push(c)
return p
}, {} as Record<string, Array<[string, Card]>>)
}
}

View File

@ -0,0 +1,42 @@
import { StringEndpointList, StringEndpoint } from '@tcgdex/sdk/dist/types/interfaces'
import { Card, Languages } from '../db/interfaces'
import { Endpoint } from '../interfaces'
import { cardToCardSimple, getCards } from '../utils/cardUtil'
export default class implements Endpoint<StringEndpointList, StringEndpoint, Record<string, unknown>, Record<string, Array<[string, Card]>>> {
public constructor(
private lang: keyof Languages
) {}
public async index(common: Record<string, Array<[string, Card]>>): Promise<StringEndpointList> {
return Object.keys(common)
}
public async item(common: Record<string, Array<[string, Card]>>): Promise<Record<string, StringEndpoint>> {
const items: Record<string, StringEndpoint> = {}
for await (const key of Object.keys(common)) {
const val = common[key]
items[key] = {
cards: await Promise.all(val.map(([id, card]) => cardToCardSimple(id, card, this.lang))),
name: key
}
}
return items
}
public async common(): Promise<Record<string, Array<[string, Card]>>> {
return (await getCards(this.lang)).reduce((p, c) => {
const { trainerType } = c[1]
if (!trainerType) {
return p
}
if (!p[trainerType]) {
p[trainerType] = []
}
p[trainerType].push(c)
return p
}, {} as Record<string, Array<[string, Card]>>)
}
}

View File

@ -1,4 +1,4 @@
import { StringEndpointList, StringEndpoint } from '@tcgdex/sdk/interfaces' import { StringEndpointList, StringEndpoint } from '@tcgdex/sdk/dist/types/interfaces'
import translate from '../utils/translationUtil' import translate from '../utils/translationUtil'
import { Card, Languages } from '../db/interfaces' import { Card, Languages } from '../db/interfaces'
import { Endpoint } from '../interfaces' import { Endpoint } from '../interfaces'

48
endpoints/variants.ts Normal file
View File

@ -0,0 +1,48 @@
import { objectLoop } from '@dzeio/object-util'
import { StringEndpointList, StringEndpoint } from '@tcgdex/sdk/dist/types/interfaces'
import { Card, Languages } from '../db/interfaces'
import { Endpoint } from '../interfaces'
import { cardToCardSimple, getCards } from '../utils/cardUtil'
export default class implements Endpoint<StringEndpointList, StringEndpoint, Record<string, unknown>, Record<string, Array<[string, Card]>>> {
public constructor(
private lang: keyof Languages
) {}
public async index(common: Record<string, Array<[string, Card]>>): Promise<StringEndpointList> {
return Object.keys(common)
}
public async item(common: Record<string, Array<[string, Card]>>): Promise<Record<string, StringEndpoint>> {
const items: Record<string, StringEndpoint> = {}
for await (const key of Object.keys(common)) {
const val = common[key]
items[key] = {
cards: await Promise.all(val.map(([id, card]) => cardToCardSimple(id, card, this.lang))),
name: key
}
}
return items
}
public async common(): Promise<Record<string, Array<[string, Card]>>> {
return (await getCards(this.lang)).reduce((p, c) => {
const { variants } = c[1]
if (!variants) {
return p
}
objectLoop(variants, (isSet, key) => {
if (!isSet) {
return
}
if (!p[key]) {
p[key] = []
}
p[key].push(c)
})
return p
}, {} as Record<string, Array<[string, Card]>>)
}
}

808
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -20,7 +20,7 @@
"@types/node-fetch": "^2.5.12", "@types/node-fetch": "^2.5.12",
"dotenv": "^10.0.0", "dotenv": "^10.0.0",
"glob": "^7.1.7", "glob": "^7.1.7",
"node-fetch": "^2.6.1", "node-fetch": "^2.6.5",
"ts-node": "^10.2.0", "ts-node": "^10.2.0",
"typescript": "^4.3.5" "typescript": "^4.3.5"
}, },

View File

@ -4,6 +4,6 @@
}, },
"extends": "./node_modules/@dzeio/config/tsconfig.base", "extends": "./node_modules/@dzeio/config/tsconfig.base",
"compilerOptions": { "compilerOptions": {
"baseUrl": "./", "baseUrl": "./"
} }
} }

View File

@ -2,7 +2,7 @@
import { setToSetSimple } from './setUtil' import { setToSetSimple } from './setUtil'
import { cardIsLegal, fetchRemoteFile, smartGlob } from './util' import { cardIsLegal, fetchRemoteFile, smartGlob } from './util'
import { Set, SupportedLanguages, Card, Types } from 'db/interfaces' import { Set, SupportedLanguages, Card, Types } from 'db/interfaces'
import { Card as CardSingle, CardResume } from '@tcgdex/sdk/interfaces' import { Card as CardSingle, CardResume } from '@tcgdex/sdk/dist/types/interfaces'
import translate from './translationUtil' import translate from './translationUtil'
export async function getCardPictures(cardId: string, card: Card, lang: SupportedLanguages): Promise<string | undefined> { export async function getCardPictures(cardId: string, card: Card, lang: SupportedLanguages): Promise<string | undefined> {

View File

@ -1,7 +1,7 @@
import { smartGlob } from './util' import { smartGlob } from './util'
import { setToSetSimple, getSets } from './setUtil' import { setToSetSimple, getSets } from './setUtil'
import { Serie, SupportedLanguages, Set } from 'db/interfaces' import { Serie, SupportedLanguages, Set } from 'db/interfaces'
import { Serie as SerieSingle, SerieResume } from '@tcgdex/sdk/interfaces' import { Serie as SerieSingle, SerieResume } from '@tcgdex/sdk/dist/types/interfaces'
export async function getSerie(name: string): Promise<Serie> { export async function getSerie(name: string): Promise<Serie> {
return (await import(`../db/data/${name}.js`)).default return (await import(`../db/data/${name}.js`)).default

View File

@ -1,7 +1,7 @@
import { Set, SupportedLanguages } from 'db/interfaces' import { Set, SupportedLanguages } from 'db/interfaces'
import { fetchRemoteFile, setIsLegal, smartGlob } from './util' import { fetchRemoteFile, setIsLegal, smartGlob } from './util'
import { cardToCardSimple, getCards } from './cardUtil' import { cardToCardSimple, getCards } from './cardUtil'
import { SetResume, Set as SetSingle } from '@tcgdex/sdk/interfaces' import { SetResume, Set as SetSingle } from '@tcgdex/sdk/dist/types/interfaces'
interface t { interface t {
[key: string]: Set [key: string]: Set