Compare commits

..

1 Commits

Author SHA1 Message Date
25b0feb243 build: bump rollup from 3.25.3 to 3.29.5
Bumps [rollup](https://github.com/rollup/rollup) from 3.25.3 to 3.29.5.
- [Release notes](https://github.com/rollup/rollup/releases)
- [Changelog](https://github.com/rollup/rollup/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rollup/rollup/compare/v3.25.3...v3.29.5)

---
updated-dependencies:
- dependency-name: rollup
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-11-27 23:42:28 +00:00
12 changed files with 918 additions and 3309 deletions

View File

@ -1,19 +1,18 @@
import { expect, test, vi } from 'vitest'
import TCGdex, { Query } from '../src/tcgdex'
/// <reference types="jest" />
// change timeout of execution
vi.setConfig({ testTimeout: 120000 })
const { default: TCGdex, Query } = require("../src/tcgdex")
import fetch from 'node-fetch'
const fakeFetch = (response: any, status = 200) => vi.fn(() =>
const fakeFetch = (response, status = 200) => jest.fn(() =>
Promise.resolve({
status: status,
json: () => Promise.resolve(response)
json: () => Promise.resolve(response),
})
)
);
test('Basic test', async () => {
const tcgdex = new TCGdex('en')
TCGdex.fetch = fakeFetch({ ok: true }) as any
TCGdex.fetch = fakeFetch({ ok: true })
const res = await tcgdex.fetch('cards', 'basic-test')
expect(res).toEqual({ ok: true })
expect(TCGdex.fetch).toHaveBeenCalledTimes(1)
@ -21,7 +20,7 @@ test('Basic test', async () => {
test('endpoint errors', async () => {
const tcgdex = new TCGdex('en')
TCGdex.fetch = fakeFetch({ ok: 'a' }) as any
TCGdex.fetch = fakeFetch({ ok: 'a' })
await expect(tcgdex.fetch('non existing endpoint')).rejects.toThrow()
await expect(tcgdex.fetch()).rejects.toThrow()
})
@ -68,7 +67,7 @@ test(`test get set from card`, async () => {
TCGdex.fetch = fetch
expect(
await (await tcgdex.card.get('swsh1-136'))!.getSet()
await (await tcgdex.card.get('swsh1-136')).getSet()
).toBeTruthy()
})
@ -77,7 +76,7 @@ test(`test get serie from set`, async () => {
TCGdex.fetch = fetch
expect(
await (await tcgdex.set.get('swsh1'))!.getSerie()
await (await tcgdex.set.get('swsh1')).getSerie()
).toBeTruthy()
})

View File

@ -1,44 +1,43 @@
import { expect, test, vi } from 'vitest'
import TCGdex from '../src/tcgdex'
const TCGdex = require("../src/tcgdex").default
const fetch = require('node-fetch')
// change timeout of execution
vi.setConfig({ testTimeout: 120000 })
const fakeFetch = (response, status = 200) => vi.fn(() =>
const fakeFetch = (response, status = 200) => jest.fn(() =>
Promise.resolve({
status: status,
json: () => Promise.resolve(response),
})
)
);
test('Basic test', async () => {
const tcgdex = new TCGdex('en')
TCGdex.fetch = fakeFetch({ ok: true }) as any
TCGdex.fetch = fakeFetch({ok: true})
const res = await tcgdex.fetch('cards', 'basic-test')
expect(res).toEqual({ ok: true })
expect(res).toEqual({ok: true})
expect(TCGdex.fetch).toHaveBeenCalledTimes(1)
})
test('Cache test', async () => {
const tcgdex = new TCGdex('en')
TCGdex.fetch = fakeFetch({ ok: 'a' }) as any
TCGdex.fetch = fakeFetch({ok: 'a'})
const res1 = await tcgdex.fetch('cards', 'cache-test')
expect(res1).toEqual({ ok: 'a' })
TCGdex.fetch = fakeFetch({ ok: 'b' }) as any
expect(res1).toEqual({ok: 'a'})
TCGdex.fetch = fakeFetch({ok: 'b'})
const res2 = await tcgdex.fetch('cards', 'cache-test')
expect(res2).toEqual({ ok: 'a' })
expect(res2).toEqual({ok: 'a'})
})
test('endpoint errors', async () => {
const tcgdex = new TCGdex('en')
TCGdex.fetch = fakeFetch({ ok: 'a' }) as any
TCGdex.fetch = fakeFetch({ok: 'a'})
await expect(tcgdex.fetch('non existing endpoint')).rejects.toThrow()
await expect(tcgdex.fetch()).rejects.toThrow()
})
test('404 test', async () => {
const tcgdex = new TCGdex('en')
TCGdex.fetch = fakeFetch(undefined, 404) as any
TCGdex.fetch = fakeFetch(undefined, 404)
expect(
await tcgdex.fetch('cards', '404-test')
).not.toBeDefined()
@ -48,15 +47,15 @@ test('test real endpoints', async () => {
const tcgdex = new TCGdex('en')
TCGdex.fetch = fetch
const endpoints = [
{ endpoint: 'fetchCard', params: ['swsh1-1'] },
{ endpoint: 'fetchCard', params: ['1', 'Sword & Shield'] },
{ endpoint: 'fetchCards', params: ['swsh1'] },
{ endpoint: 'fetchCards', params: [] },
{ endpoint: 'fetchSet', params: ['swsh1'] },
{ endpoint: 'fetchSets', params: ['swsh'] },
{ endpoint: 'fetchSets', params: [] },
{ endpoint: 'fetchSeries', params: [] },
{ endpoint: 'fetchSerie', params: ['swsh'] },
{endpoint: 'fetchCard', params: ['swsh1-1']},
{endpoint: 'fetchCard', params: ['1', 'Sword & Shield']},
{endpoint: 'fetchCards', params: ['swsh1']},
{endpoint: 'fetchCards', params: []},
{endpoint: 'fetchSet', params: ['swsh1']},
{endpoint: 'fetchSets', params: ['swsh']},
{endpoint: 'fetchSets', params: []},
{endpoint: 'fetchSeries', params: []},
{endpoint: 'fetchSerie', params: ['swsh']},
]
for await (const item of endpoints) {

4062
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,19 +1,19 @@
{
"name": "@tcgdex/sdk",
"version": "2.7.0",
"main": "./dist/tcgdex.js",
"module": "./dist/tcgdex.mjs",
"types": "./dist/tcgdex.d.ts",
"browser": "./dist/tcgdex.global.js",
"version": "2.6.0-beta.4",
"main": "./dist/tcgdex.node.js",
"module": "./dist/tcgdex.node.mjs",
"types": "./dist/tcgdex.node.d.ts",
"browser": "./dist/tcgdex.browser.global.js",
"exports": {
".": {
"require": {
"types": "./dist/tcgdex.d.ts",
"default": "./dist/tcgdex.js"
"types": "./dist/tcgdex.node.d.ts",
"default": "./dist/tcgdex.node.js"
},
"import": {
"types": "./dist/tcgdex.d.mts",
"default": "./dist/tcgdex.mjs"
"types": "./dist/tcgdex.node.d.mts",
"default": "./dist/tcgdex.node.mjs"
}
}
},
@ -44,12 +44,10 @@
"@types/node-fetch": "^2",
"@typescript-eslint/eslint-plugin": "^5",
"@typescript-eslint/parser": "^5",
"@vitest/coverage-v8": "^2.1.8",
"eslint": "^8",
"jest": "^29",
"tsup": "^7",
"typescript": "^5",
"vitest": "^2"
"typescript": "^5"
},
"engines": {
"node": ">=12"
@ -57,14 +55,15 @@
"dependencies": {
"@cachex/memory": "^1",
"@cachex/web-storage": "^1",
"@dzeio/object-util": "^1"
"@dzeio/object-util": "^1",
"isomorphic-unfetch": "^3"
},
"scripts": {
"prebuild": "node scripts/export-version-number.js",
"build": "rm -rf dist && tsup ./src/tcgdex.ts --format cjs,esm,iife --global-name TCGdex --sourcemap --dts --clean",
"build": "rm -rf dist && tsup ./src/tcgdex.node.ts --format cjs,esm --dts --clean && tsup ./src/tcgdex.browser.ts --format iife --global-name TCGdex --sourcemap",
"prepublishOnly": "npm run build",
"lint": "eslint",
"test": "vitest run --coverage"
"test": "jest --coverage"
},
"files": [
"dist"

13
src/interfaces.d.ts vendored
View File

@ -22,18 +22,9 @@ interface variants {
firstEdition?: boolean
}
interface booster {
id: string
name: string
logo?: string
artwork_front?: string
artwork_back?: string
}
export type SetList = Array<SetResume>
export type SerieList = Array<SerieResume>
export type CardList = Array<CardResume>
export type BoosterList = Array<booster>
export interface SetResume {
id: string
@ -114,8 +105,6 @@ export interface Set extends SetResume {
}
cards: CardList
boosters?: BoosterList
}
export interface CardResume {
@ -313,8 +302,6 @@ export interface Card<SetType extends SetResume = SetResume> extends CardResume
*/
expanded: boolean
}
boosters?: BoosterList
}
export type StringEndpointList = Array<string>

View File

@ -1,5 +1,5 @@
import CardResume from './CardResume'
import type { Booster, Variants } from './Other'
import type { Variants } from './Other'
import type TCGdexSet from './Set'
import type SetResume from './SetResume'
@ -188,8 +188,6 @@ export default class Card extends CardResume {
expanded: boolean
}
public boosters?: Array<Booster>
public override async getCard(): Promise<Card> {
return this
}

View File

@ -4,12 +4,3 @@ export interface Variants {
holo?: boolean
firstEdition?: boolean
}
export interface Booster {
id: string
name: string
logo?: string
artwork_front?: string
artwork_back?: string
}

View File

@ -1,7 +1,7 @@
import { objectLoop } from '@dzeio/object-util'
import CardResume from './CardResume'
import Model from './Model'
import type { Booster, Variants } from './Other'
import type { Variants } from './Other'
import type SerieResume from './SerieResume'
// biome-ignore lint/suspicious/noShadowRestrictedNames: <explanation>
@ -70,8 +70,6 @@ export default class Set extends Model {
public cards!: Array<CardResume>
public boosters?: Array<Booster>
public async getSerie() {
return this.sdk.serie.get(this.serie.id)
}

5
src/tcgdex.browser.ts Normal file
View File

@ -0,0 +1,5 @@
import TCGdex from './tcgdex'
TCGdex.fetch = window.fetch
export default TCGdex

7
src/tcgdex.node.ts Normal file
View File

@ -0,0 +1,7 @@
import TCGdex from './tcgdex'
import fetch from 'isomorphic-unfetch'
TCGdex.fetch = fetch as any
export default TCGdex
export * from './tcgdex'

View File

@ -1,6 +1,6 @@
import type CacheInterface from '@cachex/core'
import MemoryCache from '@cachex/memory'
import LocalStorageCache from '@cachex/web-storage'
import MemoryCache from '@cachex/memory'
import Query from './Query'
import Endpoint from './endpoints/Endpoint'
import SimpleEndpoint from './endpoints/SimpleEndpoint'
@ -31,11 +31,7 @@ export default class TCGdex {
/**
* How the remote data is going to be fetched
*/
public static fetch: typeof fetch =
detectContext() === 'browser'
// fixe: TypeError: 'fetch' called on an object that does not implement interface Window.
? (...params: Parameters<typeof fetch>) => window.fetch(...params)
: fetch
public static fetch: typeof fetch = fetch
/**
* @deprecated to change the lang use {@link TCGdex.getLang} and {@link TCGdex.setLang}
@ -46,9 +42,7 @@ export default class TCGdex {
* the previously hidden caching system used by TCGdex to not kill the API
*/
public cache: CacheInterface =
detectContext() === 'browser'
? new LocalStorageCache('tcgdex-cache')
: new MemoryCache()
detectContext() === 'browser' ? new LocalStorageCache('tcgdex-cache') : new MemoryCache()
/**
* the default cache TTL, only subsequent requests will have their ttl changed
@ -378,7 +372,6 @@ export default class TCGdex {
// parse, put to cache and return
const json = await resp.json()
this.cache.set(path, json, this.cacheTTL)
return json as T
}
@ -404,13 +397,8 @@ export default class TCGdex {
}
}
// export the old interfaces
export type * from './interfaces.d.ts'
// export the new models items and the Query
export * from './models/Card'
export {
CardModel, CardResumeModel, Endpoint, Model, Query, SerieModel,
SerieResume as SerieResumeModel,
SetModel,
SetResumeModel, SimpleEndpoint
Query
}

View File

@ -1,7 +1,7 @@
import type { Endpoints } from './interfaces'
/**
* detect the current running context of the program
* detect the current running context ofthe program
*/
export function detectContext(): 'browser' | 'server' {
try {
@ -12,7 +12,7 @@ export function detectContext(): 'browser' | 'server' {
}
}
export const ENDPOINTS: ReadonlyArray<Endpoints> = [
export const ENDPOINTS: Array<Endpoints> = [
'cards', 'categories', 'dex-ids', 'energy-types',
'hp', 'illustrators', 'rarities', 'regulation-marks',
'retreats', 'series', 'sets', 'stages', 'suffixes',