mirror of
https://github.com/tcgdex/compiler.git
synced 2025-04-22 02:32:10 +00:00
Added multiple endpoints (#18)
Added new endpoints: energyTypes trainerTypes suffixes stages dexIds regulationMarks variants
This commit is contained in:
parent
19f060bfd6
commit
5069fb9945
@ -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 { Endpoint } from '../interfaces'
|
||||
import { cardToCardSimple, cardToCardSingle, getCards } from '../utils/cardUtil'
|
||||
|
@ -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 { Card, Languages } from '../db/interfaces'
|
||||
import { Endpoint } from '../interfaces'
|
||||
|
44
endpoints/dex-ids.ts
Normal file
44
endpoints/dex-ids.ts
Normal 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
42
endpoints/energy-types.ts
Normal 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]>>)
|
||||
}
|
||||
|
||||
}
|
@ -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 { Endpoint } from '../interfaces'
|
||||
import { cardToCardSimple, getCards } from '../utils/cardUtil'
|
||||
|
@ -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 { Endpoint } from '../interfaces'
|
||||
import { cardToCardSimple, getCards } from '../utils/cardUtil'
|
||||
|
@ -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 { Card, Languages } from '../db/interfaces'
|
||||
import { Endpoint } from '../interfaces'
|
||||
|
42
endpoints/regulation-marks.ts
Normal file
42
endpoints/regulation-marks.ts
Normal 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]>>)
|
||||
}
|
||||
|
||||
}
|
@ -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 { Endpoint } from '../interfaces'
|
||||
import { cardToCardSimple, getCards } from '../utils/cardUtil'
|
||||
|
@ -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 { Endpoint } from '../interfaces'
|
||||
import { getSeries, serieToSerieSimple, serieToSerieSingle } from '../utils/serieUtil'
|
||||
|
@ -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 { Languages, Set } from '../db/interfaces'
|
||||
import { Endpoint } from '../interfaces'
|
||||
|
42
endpoints/stages.ts
Normal file
42
endpoints/stages.ts
Normal 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
42
endpoints/suffixes.ts
Normal 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]>>)
|
||||
}
|
||||
|
||||
}
|
42
endpoints/trainer-types.ts
Normal file
42
endpoints/trainer-types.ts
Normal 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]>>)
|
||||
}
|
||||
|
||||
}
|
@ -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 { Card, Languages } from '../db/interfaces'
|
||||
import { Endpoint } from '../interfaces'
|
||||
|
48
endpoints/variants.ts
Normal file
48
endpoints/variants.ts
Normal 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
808
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -20,7 +20,7 @@
|
||||
"@types/node-fetch": "^2.5.12",
|
||||
"dotenv": "^10.0.0",
|
||||
"glob": "^7.1.7",
|
||||
"node-fetch": "^2.6.1",
|
||||
"node-fetch": "^2.6.5",
|
||||
"ts-node": "^10.2.0",
|
||||
"typescript": "^4.3.5"
|
||||
},
|
||||
|
@ -4,6 +4,6 @@
|
||||
},
|
||||
"extends": "./node_modules/@dzeio/config/tsconfig.base",
|
||||
"compilerOptions": {
|
||||
"baseUrl": "./",
|
||||
"baseUrl": "./"
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
import { setToSetSimple } from './setUtil'
|
||||
import { cardIsLegal, fetchRemoteFile, smartGlob } from './util'
|
||||
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'
|
||||
|
||||
export async function getCardPictures(cardId: string, card: Card, lang: SupportedLanguages): Promise<string | undefined> {
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { smartGlob } from './util'
|
||||
import { setToSetSimple, getSets } from './setUtil'
|
||||
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> {
|
||||
return (await import(`../db/data/${name}.js`)).default
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { Set, SupportedLanguages } from 'db/interfaces'
|
||||
import { fetchRemoteFile, setIsLegal, smartGlob } from './util'
|
||||
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 {
|
||||
[key: string]: Set
|
||||
|
Loading…
x
Reference in New Issue
Block a user