1
0
mirror of https://github.com/tcgdex/cards-database.git synced 2025-08-15 01:41:59 +00:00

Compare commits

...

4 Commits

Author SHA1 Message Date
79455823c9 feat: Prepare to have datas changed
Signed-off-by: Avior <f.bouillon@aptatio.com>
2024-05-07 14:43:44 +02:00
df154e6b9b Chore: upgrade deps (#483)
Co-authored-by: Avior <git@avior.me>
2024-05-07 02:41:57 +02:00
c7b3267ca2 fix: Missing Compilation when testing 2024-05-06 01:39:46 +02:00
14418b0c94 chore: Add metadata for Portuguese (#482) 2024-05-06 01:37:29 +02:00
10 changed files with 85 additions and 101 deletions

View File

@@ -24,6 +24,7 @@ jobs:
bun install --frozen-lockfile
cd server
bun install --frozen-lockfile
bun run compile
- name: Validate the data & the server
run: |

BIN
bun.lockb Normal file → Executable file

Binary file not shown.

41
interfaces.d.ts vendored
View File

@@ -12,42 +12,7 @@ export interface Serie {
energies?: Array<Types>
}
interface variants {
/**
* Card base version
*/
normal?: boolean
/**
* Holo Reverse
* (colored Background holographic)
*/
reverse?: boolean
/**
* Holo Card
* (illustration holographic)
*/
holo?: boolean
/**
* can have a first Edition stamp
*/
firstEdition?: boolean
/**
* Can be found in Jumob Format
*/
jumbo?: boolean
/**
* Card has a pre-release stamp
*/
preRelease?: boolean
/**
* Card has a W stamp
*/
wPromo?: true
}
type Variants = 'Standard' | 'Parallel Foil' | 'Standard Foil' | 'First Edition' | 'Jumbo' | 'Pre-Release' | 'W-Promo'
export type Types = 'Colorless' | 'Darkness' | 'Dragon' |
'Fairy' | 'Fighting' | 'Fire' |
@@ -133,9 +98,9 @@ export interface Card {
category: 'Pokemon' | 'Trainer' | 'Energy'
/**
* Card Variants (Override Set Variants)
* Card Variants
*/
variants?: variants
variants?: Array<Variants>
/**
* Card Set

View File

@@ -27,7 +27,7 @@ type Query {
"""Find one card (using the id and set is deprecated)"""
card(
id: ID!,
id: ID,
set: String,
"""The new way to filter"""
filters: CardsFilters
@@ -35,14 +35,14 @@ type Query {
"""Find one set (using the id is deprecated)"""
set(
id: ID!,
id: ID,
"""The new way to filter"""
filters: SetFilters
): Set
"""Find one serie (using the id is deprecated)"""
serie(
id: ID!,
id: ID,
"""The new way to filter"""
filters: SerieFilters
): Serie

View File

@@ -1,34 +1,33 @@
{
"__comment__": "Missing All :(",
"$schema": "./schema.json",
"abilityType": {
"Ability": "Ability",
"Ability": "Habilidade",
"Ancient Trait": "Ancient Trait",
"Poke-BODY": "Poke-BODY",
"Poke-POWER": "Poke-POWER",
"Pokemon Power": "Pokemon Power"
},
"category": {
"Energy": "Energy",
"Energy": "Energia",
"Pokemon": "Pokemon",
"Trainer": "Trainer"
"Trainer": "Treinador"
},
"energyType": {
"Normal": "Normal",
"Special": "Special"
"Special": "Especial"
},
"rarity": {
"ACE SPEC Rare": "ACE SPEC Raro",
"Amazing Rare": "Amazing",
"Classic Collection": "Colección Clásica",
"Amazing Rare": "Raras Incríveis",
"Classic Collection": "Coleção Clásica",
"Common": "Comum",
"Double rare": "Rara Dupla",
"Full Art Trainer": "Formador de arte completa",
"Full Art Trainer": "Arte Completa de Treinador",
"Holo Rare": "Rara Holo",
"Holo Rare V": "Rara Holo V",
"Holo Rare VMAX": "Rara Holo VMAX",
"Holo Rare VSTAR": "Rara Holo VSTAR",
"Hyper rare": "Rara Hiper",
"Hyper rare": "Hiper rara",
"Illustration rare": "Ilustração Rara",
"LEGEND": "LEGEND",
"None": "None",
@@ -37,24 +36,24 @@
"Rare Holo": "Rara Holo",
"Rare Holo LV.X": "Rara Holo LV.X",
"Rare PRIME": "Rara Prime",
"Secret Rare": "Secret Rare",
"Shiny rare": "Shiny rare",
"Shiny rare V": "Shiny rare V",
"Shiny rare VMAX": "Shiny rare VMAX",
"Shiny Ultra Rare": "Brilhante Ultra Raro",
"Secret Rare": "Rare Secreta",
"Shiny rare": "Shiny rara",
"Shiny rare V": "Shiny rara V",
"Shiny rare VMAX": "Shiny rara VMAX",
"Shiny Ultra Rare": "Brilhante Ultra Rara",
"Special illustration rare": "Ilustração Rara Especial",
"Ultra Rare": "Rara Ultra",
"Ultra Rare": "Ultra Rara",
"Uncommon": "Incomum"
},
"stage": {
"Baby": "Bebê",
"Basic": "Basic",
"Basic": "Básico",
"BREAK": "TURBO",
"LEVEL-UP": "LEVEL-UP",
"MEGA": "MEGA",
"RESTORED": "RESTORED",
"Stage1": "Stage 1",
"Stage2": "Stage 2",
"Stage1": "Estágio 1",
"Stage2": "Estágio 2",
"V-UNION": "V-UNION",
"VMAX": "VMAX",
"VSTAR": "V-ASTRO"
@@ -73,22 +72,22 @@
"Goldenrod Game Corner": "Goldenrod Game Corner",
"Item": "Item",
"Rocket's Secret Machine": "Rocket's Secret Machine",
"Stadium": "Stadium",
"Supporter": "Supporter",
"Stadium": "Estádio",
"Supporter": "Apoiador",
"Technical Machine": "Technical Machine",
"Tool": "Tool"
"Tool": "Ferramenta"
},
"types": {
"Colorless": "Colorless",
"Darkness": "Darkness",
"Dragon": "Dragon",
"Fairy": "Fairy",
"Fighting": "Fighting",
"Fire": "Fire",
"Grass": "Grass",
"Lightning": "Lightning",
"Colorless": "Incolor",
"Darkness": "Sombrio",
"Dragon": "Dragão",
"Fairy": "Fada",
"Fighting": "Lutador",
"Fire": "Fogo",
"Grass": "Planta",
"Lightning": "Elétrico",
"Metal": "Metal",
"Psychic": "Psychic",
"Water": "Water"
"Psychic": "Psíquico",
"Water": "Água"
}
}

BIN
server/bun.lockb Normal file → Executable file

Binary file not shown.

View File

@@ -1,9 +1,8 @@
/* eslint-disable max-statements */
import { FileFunction } from './compilerInterfaces'
import { promises as fs } from 'fs'
import { fetchRemoteFile } from './utils/util'
import { objectValues } from '@dzeio/object-util'
import { SupportedLanguages } from '../../interfaces'
import { FileFunction } from './compilerInterfaces'
import { fetchRemoteFile } from './utils/util'
const LANGS: Array<SupportedLanguages> = ['en', 'fr', 'es', 'it', 'pt', 'de']

View File

@@ -1,6 +1,5 @@
import { glob } from 'glob'
import { Card, Set } from '../../../interfaces'
import glob from 'glob'
import fetch from 'node-fetch'
import * as legals from '../../../meta/legals'
interface fileCacheInterface {
@@ -18,9 +17,16 @@ const fileCache: fileCacheInterface = {}
*/
export async function fetchRemoteFile<T = any>(url: string): Promise<T> {
if (!fileCache[url]) {
const signal = new AbortController()
const finished = setTimeout(() => {
signal.abort()
}, 60 * 1000);
const resp = await fetch(url, {
timeout: 60 * 1000
signal: signal.signal
})
clearTimeout(finished)
fileCache[url] = resp.json()
}
return fileCache[url]
@@ -30,9 +36,7 @@ const globCache: Record<string, Array<string>> = {}
export async function smartGlob(query: string): Promise<Array<string>> {
if (!globCache[query]) {
globCache[query] = await new Promise((res) => {
glob(query, (_, matches) => res(matches))
})
globCache[query] = await glob(query)
}
return globCache[query]
}

View File

@@ -16,19 +16,15 @@
"@tcgdex/sdk": "^2",
"apicache": "^1",
"express": "^4",
"express-graphql": "^0.12.0",
"graphql": "^15"
"graphql": "^15",
"graphql-http": "^1.22.1",
"ruru": "^2.0.0-beta.11"
},
"devDependencies": {
"@types/apicache": "^1",
"@types/express": "^4",
"@types/glob": "^8",
"@types/node": "^18",
"@types/node-fetch": "^2",
"glob": "^8",
"node-fetch": "^2",
"ts-node": "^10",
"ts-node-dev": "^2",
"typescript": "^4"
"@types/node": "^20",
"glob": "^10",
"typescript": "^5"
}
}

View File

@@ -1,9 +1,15 @@
import express from 'express'
import { graphqlHTTP } from 'express-graphql'
import fs from 'fs'
import { buildSchema, formatError, GraphQLError } from 'graphql'
import { buildSchema, GraphQLError } from 'graphql'
import { createHandler } from 'graphql-http/lib/use/express'
import { type ruruHTML as RuruHTML } from 'ruru/dist/server'
/** @ts-expect-error typing is not correctly mapped (real type at ruru/dist/server.d.ts) */
import { makeHTMLParts, ruruHTML as tmp } from 'ruru/server'
import resolver from './resolver'
const ruruHTML: typeof RuruHTML = tmp
// Init Express Router
const router = express.Router()
@@ -14,11 +20,19 @@ const router = express.Router()
const schema = buildSchema(fs.readFileSync('./public/v2/graphql.gql', 'utf-8'))
// Error Logging for debugging
function graphQLErrorHandle(error: GraphQLError) {
function graphQLErrorHandle(error: Readonly<GraphQLError | Error>) {
if (process.env.NODE_ENV !== 'production') {
console.error(error)
}
if (error.source) {
if (!('source' in error)) {
const columns = (process?.stdout?.columns ?? 32) - 7
const dashes = ''.padEnd(columns / 2, '-')
console.error(`\x1b[91m${dashes} ERROR ${dashes}\x1b[0m`)
console.error('GraphQL Error')
console.error(error.message)
console.error(`\x1b[91m${dashes} ERROR ${dashes}\x1b[0m`)
} else if (error.source) {
const columns = (process?.stdout?.columns ?? 32) - 7
const dashes = ''.padEnd(columns / 2, '-')
@@ -28,18 +42,24 @@ function graphQLErrorHandle(error: GraphQLError) {
console.error(error.source?.body)
console.error(`\x1b[91m${dashes} ERROR ${dashes}\x1b[0m`)
}
return formatError(error)
return error
}
const graphql = graphqlHTTP({
schema,
const graphql = createHandler({
schema: schema,
rootValue: resolver,
graphiql: true,
customFormatErrorFn: graphQLErrorHandle
formatError: graphQLErrorHandle
})
// Add graphql to the route
router.get('/', graphql)
router.get('/', (_, res) => {
res.type('html')
res.end(ruruHTML({ endpoint: '/v2/graphql' }, {
...makeHTMLParts(),
titleTag: '<title>GraphiQL - TCGdex API V2</title>'
}))
})
router.post('/', graphql)
export default router