1
0
mirror of https://github.com/tcgdex/cards-database.git synced 2025-08-16 09:08:52 +00:00

Compare commits

..

1 Commits

Author SHA1 Message Date
0486f277b4 fix: dec IDs not working
Signed-off-by: Avior <git@avior.me>
2025-01-31 17:18:56 +01:00
15 changed files with 73 additions and 25 deletions

View File

@@ -5,7 +5,7 @@ meta {
} }
get { get {
url: {{BASE_URL}}/v2/en/cards?name=eq:Pikachu|Pichu&hp=lt:70&localId=not:tg&id=neq:cel25-5 url: {{BASE_URL}}/v2/en/cards?name=eq:Pikachu|Pichu&hp=lt:70&localId=not:tg&id=neq:cel25-5&sort:field=updated
body: none body: none
auth: none auth: none
} }
@@ -15,9 +15,10 @@ params:query {
hp: lt:70 hp: lt:70
localId: not:tg localId: not:tg
id: neq:cel25-5 id: neq:cel25-5
sort:field: updated
} }
assert { assert {
res.status: eq 200 res.status: eq 200
res.body.length: gt 85 res.body.length: gte 85
} }

View File

@@ -0,0 +1,19 @@
meta {
name: Get dex ID 2
type: http
seq: 3
}
get {
url: {{BASE_URL}}/v2/en/cards?dexId=eq:2
body: none
auth: none
}
params:query {
dexId: eq:2
}
assert {
res.body.length: gte 18
}

View File

@@ -0,0 +1,16 @@
meta {
name: Get dex ID
type: http
seq: 2
}
get {
url: {{BASE_URL}}/v2/en/dex-ids/1
body: none
auth: none
}
assert {
res.body.cards.length: gte 18
res.body.name: eq '1'
}

View File

@@ -0,0 +1,15 @@
meta {
name: List dex IDS
type: http
seq: 1
}
get {
url: {{BASE_URL}}/v2/en/dex-ids
body: none
auth: none
}
assert {
res.body.length: gte 800
}

View File

@@ -17,5 +17,5 @@ params:query {
assert { assert {
res.status: eq 200 res.status: eq 200
res.body.length: gte 6 res.body.length: gt 0
} }

View File

@@ -58,8 +58,7 @@ const card: Card = {
regulationMark: "H", regulationMark: "H",
variants: { variants: {
holo: false, holo: false
reverse: false
} }
} }

View File

@@ -60,8 +60,7 @@ const card: Card = {
regulationMark: "H", regulationMark: "H",
variants: { variants: {
holo: false, holo: false
reverse: false
} }
} }

2
server/.gitignore vendored
View File

@@ -4,5 +4,3 @@
/public/**/graphql.gql /public/**/graphql.gql
/public/**/api.d.ts /public/**/api.d.ts
/public/**/openapi.yaml /public/**/openapi.yaml
.env
.env.*

Binary file not shown.

View File

@@ -4,7 +4,7 @@
"main": "dist/index.js", "main": "dist/index.js",
"scripts": { "scripts": {
"compile": "bun compiler/index.ts", "compile": "bun compiler/index.ts",
"dev": "bun --watch src/index.ts", "dev": "MAX_WORKERS=1 bun --watch src/index.ts",
"validate": "tsc --noEmit --project ./tsconfig.json", "validate": "tsc --noEmit --project ./tsconfig.json",
"start": "bun src/index.ts" "start": "bun src/index.ts"
}, },
@@ -13,7 +13,6 @@
"@dzeio/config": "^1", "@dzeio/config": "^1",
"@dzeio/object-util": "^1", "@dzeio/object-util": "^1",
"@dzeio/queue": "^1", "@dzeio/queue": "^1",
"@sentry/node": "^8",
"@tcgdex/sdk": "^2", "@tcgdex/sdk": "^2",
"apicache": "^1", "apicache": "^1",
"express": "^4", "express": "^4",

View File

@@ -41,7 +41,7 @@ const cards = {
'zh-cn': zhcn, 'zh-cn': zhcn,
} as const } as const
type LocalCard = Omit<SDKCard, 'set'> & {set: () => TCGSet} type LocalCard = Omit<SDKCard, 'set'> & { set: () => TCGSet }
interface variants { interface variants {
normal?: boolean; normal?: boolean;
@@ -101,7 +101,10 @@ export default class Card implements LocalCard {
} }
public static find(lang: SupportedLanguages, query: Query<SDKCard>) { public static find(lang: SupportedLanguages, query: Query<SDKCard>) {
return executeQuery(Card.getAll(lang), query).data.map((it) => new Card(lang, it)) if (query.dexId) {
query.dexId = { $in: query.dexId }
}
return executeQuery(Card.getAll(lang), query, { debug: true }).data.map((it) => new Card(lang, it))
} }
public static findOne(lang: SupportedLanguages, query: Query<SDKCard>) { public static findOne(lang: SupportedLanguages, query: Query<SDKCard>) {

View File

@@ -253,7 +253,7 @@ server
} }
result = { result = {
name: id, name: id,
cards: Card.find(lang, { [endpointToField[endpoint]]: id }) cards: Card.find(lang, { [endpointToField[endpoint]]: { $eq: id } })
.map((c) => c.resume()) .map((c) => c.resume())
} }
} }

View File

@@ -5,13 +5,6 @@ import { Errors, sendError } from './libs/Errors'
import status from './status' import status from './status'
import jsonEndpoints from './V2/endpoints/jsonEndpoints' import jsonEndpoints from './V2/endpoints/jsonEndpoints'
import graphql from './V2/graphql' import graphql from './V2/graphql'
import * as Sentry from "@sentry/node"
// Glitchtip will only start if the DSN is set :D
Sentry.init({
dsn: process.env.GLITCHTIP_DSN,
environment: process.env.NODE_ENV
})
if (cluster.isPrimary) { if (cluster.isPrimary) {
console.log(`Primary ${process.pid} is running`) console.log(`Primary ${process.pid} is running`)
@@ -114,8 +107,7 @@ if (cluster.isPrimary) {
sendError(Errors.NOT_FOUND, res) sendError(Errors.NOT_FOUND, res)
}) })
// Error handlers // General error handler
Sentry.setupExpressErrorHandler(server)
server.use((err: Error, _1: unknown, res: Response, _2: unknown) => { server.use((err: Error, _1: unknown, res: Response, _2: unknown) => {
// add a full line dash to not miss it // add a full line dash to not miss it
const columns = (process?.stdout?.columns ?? 32) - 7 const columns = (process?.stdout?.columns ?? 32) - 7

View File

@@ -5,6 +5,7 @@ import type RFC7807 from './RFCs/RFC7807'
export enum Errors { export enum Errors {
LANGUAGE_INVALID = 'language-invalid', LANGUAGE_INVALID = 'language-invalid',
NOT_FOUND = 'not-found', NOT_FOUND = 'not-found',
INVALID_KEY = 'invalid-key',
GENERAL = 'general' GENERAL = 'general'
} }
@@ -12,6 +13,7 @@ export enum Errors {
const titles: Record<Errors, string> = { const titles: Record<Errors, string> = {
[Errors.LANGUAGE_INVALID]: 'The chosen language is not available in the database', [Errors.LANGUAGE_INVALID]: 'The chosen language is not available in the database',
[Errors.NOT_FOUND]: 'The resource you are trying to reach does not exists', [Errors.NOT_FOUND]: 'The resource you are trying to reach does not exists',
[Errors.INVALID_KEY]: 'The key you used is not a valid format',
[Errors.GENERAL]: 'An unknown error occured, please contact a developper with this message' [Errors.GENERAL]: 'An unknown error occured, please contact a developper with this message'
} }
@@ -19,6 +21,7 @@ const titles: Record<Errors, string> = {
const status: Record<Errors, number> = { const status: Record<Errors, number> = {
[Errors.LANGUAGE_INVALID]: 404, [Errors.LANGUAGE_INVALID]: 404,
[Errors.NOT_FOUND]: 404, [Errors.NOT_FOUND]: 404,
[Errors.INVALID_KEY]: 400,
[Errors.GENERAL]: 500 [Errors.GENERAL]: 500
} }

View File

@@ -118,7 +118,7 @@ export type QueryComparisonOperator<Value> = {
/** /**
* the remote source value must be one of the proposed values * the remote source value must be one of the proposed values
*/ */
$in: Array<Value> $in: Array<Value> | Value
} | { } | {
/** /**
* laxist validation of the remote value * laxist validation of the remote value
@@ -350,7 +350,7 @@ function filterValue<T extends AllowedValues>(value: unknown, query: QueryValues
// loop through each keys of the query // loop through each keys of the query
// eslint-disable-next-line arrow-body-style // eslint-disable-next-line arrow-body-style
return objectLoop(query as any, (querySubValue: unknown, queryKey: string) => { return objectLoop(query as any, (querySubValue: unknown, queryKey: string) => {
return filterItem(value, {[queryKey]: querySubValue } as QueryValues<T>) return filterItem(value, { [queryKey]: querySubValue } as QueryValues<T>)
}) })
} }
@@ -390,6 +390,10 @@ function filterItem(value: any, query: QueryValues<AllowedValues>): boolean {
return query === value return query === value
} }
if (Array.isArray(value) && '$in' in query && !Array.isArray(query.$in)) {
return value.includes(query.$in)
}
/** /**
* Array checking and $in * Array checking and $in
*/ */