diff --git a/build.gradle.kts b/build.gradle.kts index b7921347..e358bd1e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -35,7 +35,11 @@ kotlin { compilerOptions { optIn = listOf("kotlin.js.ExperimentalJsExport") allWarningsAsErrors = true - freeCompilerArgs.addAll("-Xexpect-actual-classes", "-Xconsistent-data-class-copy-visibility") + freeCompilerArgs.addAll( + "-Xexpect-actual-classes", + "-Xcontext-sensitive-resolution", + "-Xconsistent-data-class-copy-visibility", + ) } jvm() diff --git a/demo-app/src/commonMain/kotlin/co/pokeapi/pokekotlin/demoapp/screens/PokemonListScreen.kt b/demo-app/src/commonMain/kotlin/co/pokeapi/pokekotlin/demoapp/screens/PokemonListScreen.kt index 5b6abd27..174aef05 100644 --- a/demo-app/src/commonMain/kotlin/co/pokeapi/pokekotlin/demoapp/screens/PokemonListScreen.kt +++ b/demo-app/src/commonMain/kotlin/co/pokeapi/pokekotlin/demoapp/screens/PokemonListScreen.kt @@ -21,7 +21,7 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import co.pokeapi.pokekotlin.PokeApi import co.pokeapi.pokekotlin.demoapp.util.ioDispatcher -import co.pokeapi.pokekotlin.model.NamedApiResource +import co.pokeapi.pokekotlin.model.Handle import co.pokeapi.pokekotlin.model.PokemonVariety import coil3.compose.AsyncImage import kotlinx.coroutines.launch @@ -36,13 +36,13 @@ sealed interface LoadingStatus { data object Loading : LoadingStatus } -typealias PokemonListStatus = LoadingStatus> +typealias PokemonListStatus = LoadingStatus>> typealias PokemonListItemStatus = LoadingStatus class PokemonListScreenViewModel(private val api: PokeApi) : ViewModel() { val summaries = mutableStateOf(LoadingStatus.Loading) - val details = mutableStateMapOf() + val details = mutableStateMapOf, PokemonListItemStatus>() init { loadPokemonList() @@ -65,7 +65,7 @@ class PokemonListScreenViewModel(private val api: PokeApi) : ViewModel() { } } - fun loadPokemonDetails(pokemon: NamedApiResource) { + fun loadPokemonDetails(pokemon: Handle) { if (details[pokemon] == LoadingStatus.Loading || details[pokemon] is LoadingStatus.Success) return // Already loading or loaded @@ -127,7 +127,10 @@ fun PokemonListScreen(viewModel: PokemonListScreenViewModel = koinViewModel()) { } @Composable -private fun PokemonListItem(viewModel: PokemonListScreenViewModel, item: NamedApiResource) { +private fun PokemonListItem( + viewModel: PokemonListScreenViewModel, + item: Handle.Named, +) { LaunchedEffect(item) { viewModel.loadPokemonDetails(item) } Card(modifier = Modifier.padding(8.dp).fillMaxWidth()) { diff --git a/src/commonMain/kotlin/co/pokeapi/pokekotlin/PokeApi.kt b/src/commonMain/kotlin/co/pokeapi/pokekotlin/PokeApi.kt index 7fddc0ee..aae5c02f 100644 --- a/src/commonMain/kotlin/co/pokeapi/pokekotlin/PokeApi.kt +++ b/src/commonMain/kotlin/co/pokeapi/pokekotlin/PokeApi.kt @@ -1,9 +1,10 @@ package co.pokeapi.pokekotlin -import co.pokeapi.pokekotlin.internal.JsOnlyExport +import co.pokeapi.pokekotlin.internal.JsNonWasmExport import co.pokeapi.pokekotlin.internal.PokeApiJson import co.pokeapi.pokekotlin.internal.getDefaultEngine import co.pokeapi.pokekotlin.model.* +import co.pokeapi.pokekotlin.model.Type import io.ktor.client.* import io.ktor.client.call.* import io.ktor.client.engine.* @@ -14,6 +15,7 @@ import io.ktor.client.plugins.contentnegotiation.* import io.ktor.client.request.* import io.ktor.http.* import io.ktor.serialization.kotlinx.json.* +import io.ktor.util.reflect.* import kotlin.js.ExperimentalJsStatic import kotlin.js.JsExport import kotlin.js.JsName @@ -21,20 +23,7 @@ import love.forte.plugin.suspendtrans.annotation.JsPromise import love.forte.plugin.suspendtrans.annotation.JvmAsync import love.forte.plugin.suspendtrans.annotation.JvmBlocking -private suspend inline fun HttpClient.getBodyWithOffsetAndLimit( - path: String, - offset: Int, - limit: Int, -): T = - get(path) { - parameter("offset", offset) - parameter("limit", limit) - } - .body() - -private suspend inline fun HttpClient.getBody(path: String): T = get(path).body() - -@JsOnlyExport +@JsNonWasmExport public sealed class PokeApi @JsExport.Ignore constructor( @@ -73,6 +62,36 @@ constructor( configure = {}, ) + private suspend inline fun HttpClient.getNamedResourceList( + offset: Int, + limit: Int, + ): PaginatedList.Named { + return get("/api/v2/${ResourceEndpoint.forModel()}") { + parameter("offset", offset) + parameter("limit", limit) + } + .body() + } + + private suspend inline fun HttpClient.getResourceList( + offset: Int, + limit: Int, + ): PaginatedList.Unnamed { + return get("/api/v2/${ResourceEndpoint.forModel()}") { + parameter("offset", offset) + parameter("limit", limit) + } + .body() + } + + private suspend inline fun HttpClient.getBody(path: String): T = get(path).body() + + @JvmBlocking + @JvmAsync + @JsPromise + @JsExport.Ignore + public suspend fun Handle.get(): T = client.get(url).body(TypeInfo(model)) + // region Resource Lists // region Berries @@ -81,22 +100,24 @@ constructor( @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getBerryList(offset: Int, limit: Int): NamedApiResourceList = - client.getBodyWithOffsetAndLimit("/api/v2/berry", offset, limit) + public suspend fun getBerryList(offset: Int, limit: Int): PaginatedList.Named = + client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getBerryFirmnessList(offset: Int, limit: Int): NamedApiResourceList = - client.getBodyWithOffsetAndLimit("/api/v2/berry-firmness", offset, limit) + public suspend fun getBerryFirmnessList( + offset: Int, + limit: Int, + ): PaginatedList.Named = client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getBerryFlavorList(offset: Int, limit: Int): NamedApiResourceList = - client.getBodyWithOffsetAndLimit("/api/v2/berry-flavor", offset, limit) + public suspend fun getBerryFlavorList(offset: Int, limit: Int): PaginatedList.Named = + client.getNamedResourceList(offset, limit) // endregion Berries @@ -106,22 +127,26 @@ constructor( @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getContestTypeList(offset: Int, limit: Int): NamedApiResourceList = - client.getBodyWithOffsetAndLimit("/api/v2/contest-type", offset, limit) + public suspend fun getContestTypeList(offset: Int, limit: Int): PaginatedList.Named = + client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getContestEffectList(offset: Int, limit: Int): ApiResourceList = - client.getBodyWithOffsetAndLimit("/api/v2/contest-effect", offset, limit) + public suspend fun getContestEffectList( + offset: Int, + limit: Int, + ): PaginatedList.Unnamed = client.getResourceList(offset, limit) @JvmBlocking @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getSuperContestEffectList(offset: Int, limit: Int): ApiResourceList = - client.getBodyWithOffsetAndLimit("/api/v2/super-contest-effect", offset, limit) + public suspend fun getSuperContestEffectList( + offset: Int, + limit: Int, + ): PaginatedList.Unnamed = client.getResourceList(offset, limit) // endregion Contests @@ -131,22 +156,28 @@ constructor( @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getEncounterMethodList(offset: Int, limit: Int): NamedApiResourceList = - client.getBodyWithOffsetAndLimit("/api/v2/encounter-method", offset, limit) + public suspend fun getEncounterMethodList( + offset: Int, + limit: Int, + ): PaginatedList.Named = client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getEncounterConditionList(offset: Int, limit: Int): NamedApiResourceList = - client.getBodyWithOffsetAndLimit("/api/v2/encounter-condition", offset, limit) + public suspend fun getEncounterConditionList( + offset: Int, + limit: Int, + ): PaginatedList.Named = client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getEncounterConditionValueList(offset: Int, limit: Int): NamedApiResourceList = - client.getBodyWithOffsetAndLimit("/api/v2/encounter-condition-value", offset, limit) + public suspend fun getEncounterConditionValueList( + offset: Int, + limit: Int, + ): PaginatedList.Named = client.getNamedResourceList(offset, limit) // endregion @@ -156,15 +187,19 @@ constructor( @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getEvolutionChainList(offset: Int, limit: Int): ApiResourceList = - client.getBodyWithOffsetAndLimit("/api/v2/evolution-chain", offset, limit) + public suspend fun getEvolutionChainList( + offset: Int, + limit: Int, + ): PaginatedList.Unnamed = client.getResourceList(offset, limit) @JvmBlocking @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getEvolutionTriggerList(offset: Int, limit: Int): NamedApiResourceList = - client.getBodyWithOffsetAndLimit("/api/v2/evolution-trigger", offset, limit) + public suspend fun getEvolutionTriggerList( + offset: Int, + limit: Int, + ): PaginatedList.Named = client.getNamedResourceList(offset, limit) // endregion @@ -174,29 +209,31 @@ constructor( @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getGenerationList(offset: Int, limit: Int): NamedApiResourceList = - client.getBodyWithOffsetAndLimit("/api/v2/generation", offset, limit) + public suspend fun getGenerationList(offset: Int, limit: Int): PaginatedList.Named = + client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getPokedexList(offset: Int, limit: Int): NamedApiResourceList = - client.getBodyWithOffsetAndLimit("/api/v2/pokedex", offset, limit) + public suspend fun getPokedexList(offset: Int, limit: Int): PaginatedList.Named = + client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getVersionList(offset: Int, limit: Int): NamedApiResourceList = - client.getBodyWithOffsetAndLimit("/api/v2/version", offset, limit) + public suspend fun getVersionList(offset: Int, limit: Int): PaginatedList.Named = + client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getVersionGroupList(offset: Int, limit: Int): NamedApiResourceList = - client.getBodyWithOffsetAndLimit("/api/v2/version-group", offset, limit) + public suspend fun getVersionGroupList( + offset: Int, + limit: Int, + ): PaginatedList.Named = client.getNamedResourceList(offset, limit) // endregion @@ -206,36 +243,42 @@ constructor( @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getItemList(offset: Int, limit: Int): NamedApiResourceList = - client.getBodyWithOffsetAndLimit("/api/v2/item", offset, limit) + public suspend fun getItemList(offset: Int, limit: Int): PaginatedList.Named = + client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getItemAttributeList(offset: Int, limit: Int): NamedApiResourceList = - client.getBodyWithOffsetAndLimit("/api/v2/item-attribute", offset, limit) + public suspend fun getItemAttributeList( + offset: Int, + limit: Int, + ): PaginatedList.Named = client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getItemCategoryList(offset: Int, limit: Int): NamedApiResourceList = - client.getBodyWithOffsetAndLimit("/api/v2/item-category", offset, limit) + public suspend fun getItemCategoryList( + offset: Int, + limit: Int, + ): PaginatedList.Named = client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getItemFlingEffectList(offset: Int, limit: Int): NamedApiResourceList = - client.getBodyWithOffsetAndLimit("/api/v2/item-fling-effect", offset, limit) + public suspend fun getItemFlingEffectList( + offset: Int, + limit: Int, + ): PaginatedList.Named = client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getItemPocketList(offset: Int, limit: Int): NamedApiResourceList = - client.getBodyWithOffsetAndLimit("/api/v2/item-pocket", offset, limit) + public suspend fun getItemPocketList(offset: Int, limit: Int): PaginatedList.Named = + client.getNamedResourceList(offset, limit) // endregion @@ -245,50 +288,58 @@ constructor( @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getMoveList(offset: Int, limit: Int): NamedApiResourceList = - client.getBodyWithOffsetAndLimit("/api/v2/move", offset, limit) + public suspend fun getMoveList(offset: Int, limit: Int): PaginatedList.Named = + client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getMoveAilmentList(offset: Int, limit: Int): NamedApiResourceList = - client.getBodyWithOffsetAndLimit("/api/v2/move-ailment", offset, limit) + public suspend fun getMoveAilmentList(offset: Int, limit: Int): PaginatedList.Named = + client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getMoveBattleStyleList(offset: Int, limit: Int): NamedApiResourceList = - client.getBodyWithOffsetAndLimit("/api/v2/move-battle-style", offset, limit) + public suspend fun getMoveBattleStyleList( + offset: Int, + limit: Int, + ): PaginatedList.Named = client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getMoveCategoryList(offset: Int, limit: Int): NamedApiResourceList = - client.getBodyWithOffsetAndLimit("/api/v2/move-category", offset, limit) + public suspend fun getMoveCategoryList( + offset: Int, + limit: Int, + ): PaginatedList.Named = client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getMoveDamageClassList(offset: Int, limit: Int): NamedApiResourceList = - client.getBodyWithOffsetAndLimit("/api/v2/move-damage-class", offset, limit) + public suspend fun getMoveDamageClassList( + offset: Int, + limit: Int, + ): PaginatedList.Named = client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getMoveLearnMethodList(offset: Int, limit: Int): NamedApiResourceList = - client.getBodyWithOffsetAndLimit("/api/v2/move-learn-method", offset, limit) + public suspend fun getMoveLearnMethodList( + offset: Int, + limit: Int, + ): PaginatedList.Named = client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getMoveTargetList(offset: Int, limit: Int): NamedApiResourceList = - client.getBodyWithOffsetAndLimit("/api/v2/move-target", offset, limit) + public suspend fun getMoveTargetList(offset: Int, limit: Int): PaginatedList.Named = + client.getNamedResourceList(offset, limit) // endregion @@ -298,29 +349,31 @@ constructor( @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getLocationList(offset: Int, limit: Int): NamedApiResourceList = - client.getBodyWithOffsetAndLimit("/api/v2/location", offset, limit) + public suspend fun getLocationList(offset: Int, limit: Int): PaginatedList.Named = + client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getLocationAreaList(offset: Int, limit: Int): NamedApiResourceList = - client.getBodyWithOffsetAndLimit("/api/v2/location-area", offset, limit) + public suspend fun getLocationAreaList( + offset: Int, + limit: Int, + ): PaginatedList.Named = client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getPalParkAreaList(offset: Int, limit: Int): NamedApiResourceList = - client.getBodyWithOffsetAndLimit("/api/v2/pal-park-area", offset, limit) + public suspend fun getPalParkAreaList(offset: Int, limit: Int): PaginatedList.Named = + client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getRegionList(offset: Int, limit: Int): NamedApiResourceList = - client.getBodyWithOffsetAndLimit("/api/v2/region", offset, limit) + public suspend fun getRegionList(offset: Int, limit: Int): PaginatedList.Named = + client.getNamedResourceList(offset, limit) // endregion @@ -330,8 +383,8 @@ constructor( @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getMachineList(offset: Int, limit: Int): ApiResourceList = - client.getBodyWithOffsetAndLimit("/api/v2/machine", offset, limit) + public suspend fun getMachineList(offset: Int, limit: Int): PaginatedList.Unnamed = + client.getResourceList(offset, limit) // endregion @@ -341,106 +394,120 @@ constructor( @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getAbilityList(offset: Int, limit: Int): NamedApiResourceList = - client.getBodyWithOffsetAndLimit("/api/v2/ability", offset, limit) + public suspend fun getAbilityList(offset: Int, limit: Int): PaginatedList.Named = + client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getCharacteristicList(offset: Int, limit: Int): ApiResourceList = - client.getBodyWithOffsetAndLimit("/api/v2/characteristic", offset, limit) + public suspend fun getCharacteristicList( + offset: Int, + limit: Int, + ): PaginatedList.Unnamed = client.getResourceList(offset, limit) @JvmBlocking @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getEggGroupList(offset: Int, limit: Int): NamedApiResourceList = - client.getBodyWithOffsetAndLimit("/api/v2/egg-group", offset, limit) + public suspend fun getEggGroupList(offset: Int, limit: Int): PaginatedList.Named = + client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getGenderList(offset: Int, limit: Int): NamedApiResourceList = - client.getBodyWithOffsetAndLimit("/api/v2/gender", offset, limit) + public suspend fun getGenderList(offset: Int, limit: Int): PaginatedList.Named = + client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getGrowthRateList(offset: Int, limit: Int): NamedApiResourceList = - client.getBodyWithOffsetAndLimit("/api/v2/growth-rate", offset, limit) + public suspend fun getGrowthRateList(offset: Int, limit: Int): PaginatedList.Named = + client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getNatureList(offset: Int, limit: Int): NamedApiResourceList = - client.getBodyWithOffsetAndLimit("/api/v2/nature", offset, limit) + public suspend fun getNatureList(offset: Int, limit: Int): PaginatedList.Named = + client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getPokeathlonStatList(offset: Int, limit: Int): NamedApiResourceList = - client.getBodyWithOffsetAndLimit("/api/v2/pokeathlon-stat", offset, limit) + public suspend fun getPokeathlonStatList( + offset: Int, + limit: Int, + ): PaginatedList.Named = client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getPokemonVarietyList(offset: Int, limit: Int): NamedApiResourceList = - client.getBodyWithOffsetAndLimit("/api/v2/pokemon", offset, limit) + public suspend fun getPokemonVarietyList( + offset: Int, + limit: Int, + ): PaginatedList.Named = client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getPokemonColorList(offset: Int, limit: Int): NamedApiResourceList = - client.getBodyWithOffsetAndLimit("/api/v2/pokemon-color", offset, limit) + public suspend fun getPokemonColorList( + offset: Int, + limit: Int, + ): PaginatedList.Named = client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getPokemonFormList(offset: Int, limit: Int): NamedApiResourceList = - client.getBodyWithOffsetAndLimit("/api/v2/pokemon-form", offset, limit) + public suspend fun getPokemonFormList(offset: Int, limit: Int): PaginatedList.Named = + client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getPokemonHabitatList(offset: Int, limit: Int): NamedApiResourceList = - client.getBodyWithOffsetAndLimit("/api/v2/pokemon-habitat", offset, limit) + public suspend fun getPokemonHabitatList( + offset: Int, + limit: Int, + ): PaginatedList.Named = client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getPokemonShapeList(offset: Int, limit: Int): NamedApiResourceList = - client.getBodyWithOffsetAndLimit("/api/v2/pokemon-shape", offset, limit) + public suspend fun getPokemonShapeList( + offset: Int, + limit: Int, + ): PaginatedList.Named = client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getPokemonSpeciesList(offset: Int, limit: Int): NamedApiResourceList = - client.getBodyWithOffsetAndLimit("/api/v2/pokemon-species", offset, limit) + public suspend fun getPokemonSpeciesList( + offset: Int, + limit: Int, + ): PaginatedList.Named = client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getStatList(offset: Int, limit: Int): NamedApiResourceList = - client.getBodyWithOffsetAndLimit("/api/v2/stat", offset, limit) + public suspend fun getStatList(offset: Int, limit: Int): PaginatedList.Named = + client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getTypeList(offset: Int, limit: Int): NamedApiResourceList = - client.getBodyWithOffsetAndLimit("/api/v2/type", offset, limit) + public suspend fun getTypeList(offset: Int, limit: Int): PaginatedList.Named = + client.getNamedResourceList(offset, limit) // endregion @@ -450,8 +517,8 @@ constructor( @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getLanguageList(offset: Int, limit: Int): NamedApiResourceList = - client.getBodyWithOffsetAndLimit("/api/v2/language", offset, limit) + public suspend fun getLanguageList(offset: Int, limit: Int): PaginatedList.Named = + client.getNamedResourceList(offset, limit) // endregion diff --git a/src/commonMain/kotlin/co/pokeapi/pokekotlin/internal/ApiResourceSerializer.kt b/src/commonMain/kotlin/co/pokeapi/pokekotlin/internal/ApiResourceSerializer.kt index 6b36bde1..f5202e3c 100644 --- a/src/commonMain/kotlin/co/pokeapi/pokekotlin/internal/ApiResourceSerializer.kt +++ b/src/commonMain/kotlin/co/pokeapi/pokekotlin/internal/ApiResourceSerializer.kt @@ -1,15 +1,29 @@ package co.pokeapi.pokekotlin.internal -import co.pokeapi.pokekotlin.model.ApiResource +import co.pokeapi.pokekotlin.model.Handle +import co.pokeapi.pokekotlin.model.Model +import co.pokeapi.pokekotlin.model.NamedModel import kotlinx.serialization.KSerializer import kotlinx.serialization.Serializable -internal class ApiResourceSerializer : - KSerializer by DelegatingSerializer( - serialName = "co.pokeapi.pokekotlin.model.ApiResource", - delegate = Delegate.serializer(), - fromDelegate = { ApiResource(url = it.url) }, - toDelegate = { Delegate(url = it.url) }, - ) { - @Serializable internal data class Delegate(val url: String) +internal object HandleSerializers { + class Unnamed : + KSerializer> by DelegatingSerializer( + serialName = "co.pokeapi.pokekotlin.model.ResourceHandle.Unnamed", + delegate = Delegate.serializer(), + fromDelegate = { Handle.Unnamed(url = it.url) }, + toDelegate = { Delegate(url = it.url) }, + ) { + @Serializable internal data class Delegate(val url: String) + } + + class Named : + KSerializer> by DelegatingSerializer( + serialName = "co.pokeapi.pokekotlin.model.ResourceHandle.Named", + delegate = Delegate.serializer(), + fromDelegate = { Handle.Named(name = it.name, url = it.url) }, + toDelegate = { Delegate(name = it.name, url = it.url) }, + ) { + @Serializable internal data class Delegate(val name: String, val url: String) + } } diff --git a/src/commonMain/kotlin/co/pokeapi/pokekotlin/internal/JsOnlyExport.kt b/src/commonMain/kotlin/co/pokeapi/pokekotlin/internal/JsNonWasmExport.kt similarity index 87% rename from src/commonMain/kotlin/co/pokeapi/pokekotlin/internal/JsOnlyExport.kt rename to src/commonMain/kotlin/co/pokeapi/pokekotlin/internal/JsNonWasmExport.kt index 0ca05ee9..f14622a4 100644 --- a/src/commonMain/kotlin/co/pokeapi/pokekotlin/internal/JsOnlyExport.kt +++ b/src/commonMain/kotlin/co/pokeapi/pokekotlin/internal/JsNonWasmExport.kt @@ -6,7 +6,7 @@ import kotlin.js.ExperimentalJsExport @ExperimentalJsExport @Retention(AnnotationRetention.BINARY) @Target(CLASS, PROPERTY, FUNCTION, FILE) -internal expect annotation class JsOnlyExport() +internal expect annotation class JsNonWasmExport() @Retention(AnnotationRetention.BINARY) @Target(CLASS, PROPERTY, FUNCTION, FILE) diff --git a/src/commonMain/kotlin/co/pokeapi/pokekotlin/internal/NamedApiResourceSerializer.kt b/src/commonMain/kotlin/co/pokeapi/pokekotlin/internal/NamedApiResourceSerializer.kt deleted file mode 100644 index d8918cbb..00000000 --- a/src/commonMain/kotlin/co/pokeapi/pokekotlin/internal/NamedApiResourceSerializer.kt +++ /dev/null @@ -1,15 +0,0 @@ -package co.pokeapi.pokekotlin.internal - -import co.pokeapi.pokekotlin.model.NamedApiResource -import kotlinx.serialization.KSerializer -import kotlinx.serialization.Serializable - -internal class NamedApiResourceSerializer : - KSerializer by DelegatingSerializer( - serialName = "co.pokeapi.pokekotlin.model.NamedApiResource", - delegate = Delegate.serializer(), - fromDelegate = { NamedApiResource(name = it.name, url = it.url) }, - toDelegate = { Delegate(name = it.name, url = it.url) }, - ) { - @Serializable internal data class Delegate(val name: String, val url: String) -} diff --git a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/base.kt b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/base.kt new file mode 100644 index 00000000..2a3f5eff --- /dev/null +++ b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/base.kt @@ -0,0 +1,16 @@ +package co.pokeapi.pokekotlin.model + +import co.pokeapi.pokekotlin.internal.JsNonWasmExport +import kotlinx.serialization.Serializable + +@JsNonWasmExport +@Serializable +public sealed interface Model { + public val id: Int +} + +@JsNonWasmExport +@Serializable +public sealed interface NamedModel : Model { + public val name: String +} diff --git a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/berries.kt b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/berries.kt index cd8dcb3c..4c1aa26f 100644 --- a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/berries.kt +++ b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/berries.kt @@ -1,6 +1,6 @@ package co.pokeapi.pokekotlin.model -import co.pokeapi.pokekotlin.internal.JsOnlyExport +import co.pokeapi.pokekotlin.internal.JsNonWasmExport import kotlinx.serialization.Serializable /** @@ -25,21 +25,21 @@ import kotlinx.serialization.Serializable * @param naturalGiftType The type inherited by "Natural Gift" when used with this Berry. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class Berry( - val id: Int, - val name: String, + override val id: Int, + override val name: String, val growthTime: Int, val maxHarvest: Int, val naturalGiftPower: Int, val size: Int, val smoothness: Int, val soilDryness: Int, - val firmness: NamedApiResource, + val firmness: Handle.Named, val flavors: List, - val item: NamedApiResource, - val naturalGiftType: NamedApiResource, -) + val item: Handle.Named, + val naturalGiftType: Handle.Named, +) : NamedModel /** * A flavor-to-potency mapping for a berry. See: https://pokeapi.co/docs/v2#berryflavormap @@ -48,8 +48,8 @@ public data class Berry( * @param flavor The referenced berry flavor. */ @Serializable -@JsOnlyExport -public data class BerryFlavorMap(val potency: Int, val flavor: NamedApiResource) +@JsNonWasmExport +public data class BerryFlavorMap(val potency: Int, val flavor: Handle.Named) /** * The firmness of berries, used in making Pokéblocks or Poffins. See: @@ -61,13 +61,13 @@ public data class BerryFlavorMap(val potency: Int, val flavor: NamedApiResource) * @param names The name of this resource listed in different languages. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class BerryFirmness( - val id: Int, - val name: String, - val berries: List, + override val id: Int, + override val name: String, + val berries: List>, val names: List, -) +) : NamedModel /** * Flavors determine whether a Pokémon will benefit or suffer from eating a berry based on their @@ -80,14 +80,14 @@ public data class BerryFirmness( * @param names The name of this resource listed in different languages. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class BerryFlavor( - val id: Int, - val name: String, + override val id: Int, + override val name: String, val berries: List, - val contestType: NamedApiResource, + val contestType: Handle.Named, val names: List, -) +) : NamedModel /** * A berry-to-potency mapping for a flavor. See: https://pokeapi.co/docs/v2#flavorberrymap @@ -96,5 +96,5 @@ public data class BerryFlavor( * @param berry The referenced berry. */ @Serializable -@JsOnlyExport -public data class FlavorBerryMap(val potency: Int, val berry: NamedApiResource) +@JsNonWasmExport +public data class FlavorBerryMap(val potency: Int, val berry: Handle.Named) diff --git a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/contests.kt b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/contests.kt index bec69114..3b65d7fa 100644 --- a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/contests.kt +++ b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/contests.kt @@ -1,6 +1,6 @@ package co.pokeapi.pokekotlin.model -import co.pokeapi.pokekotlin.internal.JsOnlyExport +import co.pokeapi.pokekotlin.internal.JsNonWasmExport import kotlinx.serialization.Serializable /** @@ -13,13 +13,13 @@ import kotlinx.serialization.Serializable * @param names The name of this resource listed in different languages and colors. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class ContestType( - val id: Int, - val name: String, - val berryFlavor: NamedApiResource, + override val id: Int, + override val name: String, + val berryFlavor: Handle.Named, val names: List, -) +) : NamedModel /** * The name of a contest type listed in different languages and colors. See: @@ -30,8 +30,12 @@ public data class ContestType( * @param language The language that this name is in. */ @Serializable -@JsOnlyExport -public data class ContestName(val name: String, val color: String, val language: NamedApiResource) +@JsNonWasmExport +public data class ContestName( + val name: String, + val color: String, + val language: Handle.Named, +) /** * Contest effects refer to the effects of moves when used in contests. See: @@ -44,14 +48,14 @@ public data class ContestName(val name: String, val color: String, val language: * @param flavorTextEntries The flavor text of this contest effect listed in different languages. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class ContestEffect( - val id: Int, + override val id: Int, val appeal: Int, val jam: Int, val effectEntries: List, val flavorTextEntries: List, -) +) : Model /** * Super contest effects refer to the effects of moves when used in super contests. See: @@ -64,10 +68,10 @@ public data class ContestEffect( * @param moves A list of moves that have this super contest effect. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class SuperContestEffect( - val id: Int, + override val id: Int, val appeal: Int, val flavorTextEntries: List, - val moves: List, -) + val moves: List>, +) : Model diff --git a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/encounters.kt b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/encounters.kt index 89df7908..504dc819 100644 --- a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/encounters.kt +++ b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/encounters.kt @@ -1,6 +1,6 @@ package co.pokeapi.pokekotlin.model -import co.pokeapi.pokekotlin.internal.JsOnlyExport +import co.pokeapi.pokekotlin.internal.JsNonWasmExport import kotlinx.serialization.Serializable /** @@ -13,13 +13,13 @@ import kotlinx.serialization.Serializable * @param names The name of this resource listed in different languages. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class EncounterMethod( - val id: Int, - val name: String, + override val id: Int, + override val name: String, val order: Int, val names: List, -) +) : NamedModel /** * Conditions which affect what pokemon might appear in the wild, e.g., day or night. See: @@ -31,13 +31,13 @@ public data class EncounterMethod( * @param values A list of possible values for this encounter condition. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class EncounterCondition( - val id: Int, - val name: String, + override val id: Int, + override val name: String, val names: List, - val values: List, -) + val values: List>, +) : NamedModel /** * Encounter condition values are the various states that an encounter condition can have, i.e., @@ -50,10 +50,10 @@ public data class EncounterCondition( * @param names The name of this resource listed in different languages. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class EncounterConditionValue( - val id: Int, - val name: String, - val condition: NamedApiResource, + override val id: Int, + override val name: String, + val condition: Handle.Named, val names: List, -) +) : NamedModel diff --git a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/evolution.kt b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/evolution.kt index ed2ad43f..bc33064b 100644 --- a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/evolution.kt +++ b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/evolution.kt @@ -1,6 +1,6 @@ package co.pokeapi.pokekotlin.model -import co.pokeapi.pokekotlin.internal.JsOnlyExport +import co.pokeapi.pokekotlin.internal.JsNonWasmExport import kotlinx.serialization.Serializable /** @@ -15,12 +15,12 @@ import kotlinx.serialization.Serializable * the chain. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class EvolutionChain( - val id: Int, - val babyTriggerItem: NamedApiResource?, + override val id: Int, + val babyTriggerItem: Handle.Named?, val chain: ChainLink, -) +) : Model /** * A single link within an evolution chain. Each link represents a Pokémon species and the @@ -33,10 +33,10 @@ public data class EvolutionChain( * @param evolvesTo A list of chain objects describing further evolutions from this species. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class ChainLink( val isBaby: Boolean, - val species: NamedApiResource, + val species: Handle.Named, val evolutionDetails: List, val evolvesTo: List, ) @@ -69,24 +69,24 @@ public data class ChainLink( * levels up. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class EvolutionDetail( - val trigger: NamedApiResource, - val item: NamedApiResource? = null, + val trigger: Handle.Named, + val item: Handle.Named? = null, val gender: Int? = null, - val heldItem: NamedApiResource? = null, - val knownMove: NamedApiResource? = null, - val knownMoveType: NamedApiResource? = null, - val location: NamedApiResource? = null, + val heldItem: Handle.Named? = null, + val knownMove: Handle.Named? = null, + val knownMoveType: Handle.Named? = null, + val location: Handle.Named? = null, val minLevel: Int? = null, val minHappiness: Int? = null, val minBeauty: Int? = null, val minAffection: Int? = null, - val partySpecies: NamedApiResource? = null, - val partyType: NamedApiResource? = null, + val partySpecies: Handle.Named? = null, + val partyType: Handle.Named? = null, val relativePhysicalStats: Int? = null, val timeOfDay: String = "", - val tradeSpecies: NamedApiResource? = null, + val tradeSpecies: Handle.Named? = null, val needsOverworldRain: Boolean = false, val turnUpsideDown: Boolean = false, ) @@ -101,10 +101,10 @@ public data class EvolutionDetail( * @param pokemonSpecies A list of pokemon species that result from this evolution trigger. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class EvolutionTrigger( - val id: Int, - val name: String, + override val id: Int, + override val name: String, val names: List, - val pokemonSpecies: List, -) + val pokemonSpecies: List>, +) : NamedModel diff --git a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/games.kt b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/games.kt index ef323995..0665f101 100644 --- a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/games.kt +++ b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/games.kt @@ -1,6 +1,6 @@ package co.pokeapi.pokekotlin.model -import co.pokeapi.pokekotlin.internal.JsOnlyExport +import co.pokeapi.pokekotlin.internal.JsNonWasmExport import kotlinx.serialization.Serializable /** @@ -19,18 +19,18 @@ import kotlinx.serialization.Serializable * @param versionGroups A list of version groups that were introduced in this generation. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class Generation( - val id: Int, - val name: String, - val abilities: List, + override val id: Int, + override val name: String, + val abilities: List>, val names: List, - val mainRegion: NamedApiResource, - val moves: List, - val pokemonSpecies: List, - val types: List, - val versionGroups: List, -) + val mainRegion: Handle.Named, + val moves: List>, + val pokemonSpecies: List>, + val types: List>, + val versionGroups: List>, +) : NamedModel /** * A Pokédex is a handheld electronic encyclopedia device; one which is capable of recording and @@ -48,17 +48,17 @@ public data class Generation( * @param versionGroups A list of version groups this Pokédex is relevant to. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class Pokedex( - val id: Int, - val name: String, + override val id: Int, + override val name: String, val isMainSeries: Boolean, val descriptions: List, val names: List, val pokemonEntries: List, - val region: NamedApiResource?, - val versionGroups: List, -) + val region: Handle.Named?, + val versionGroups: List>, +) : NamedModel /** * A Pokémon species entry within a Pokédex. See: https://pokeapi.co/docs/v2#pokemonentry @@ -67,8 +67,11 @@ public data class Pokedex( * @param pokemonSpecies The Pokémon species being encountered. */ @Serializable -@JsOnlyExport -public data class PokemonEntry(val entryNumber: Int, val pokemonSpecies: NamedApiResource) +@JsNonWasmExport +public data class PokemonEntry( + val entryNumber: Int, + val pokemonSpecies: Handle.Named, +) /** * Versions of the games, e.g Red, Blue or Yellow. See: https://pokeapi.co/docs/v2#versions @@ -79,13 +82,13 @@ public data class PokemonEntry(val entryNumber: Int, val pokemonSpecies: NamedAp * @param versionGroup The version group this version belongs to. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class Version( - val id: Int, - val name: String, + override val id: Int, + override val name: String, val names: List, - val versionGroup: NamedApiResource, -) + val versionGroup: Handle.Named, +) : NamedModel /** * Version groups categorize highly similar versions of the games. See: @@ -102,14 +105,14 @@ public data class Version( * @param versions The versions this version group owns. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class VersionGroup( - val id: Int, - val name: String, + override val id: Int, + override val name: String, val order: Int, - val generation: NamedApiResource, - val moveLearnMethods: List, - val pokedexes: List, - val regions: List, - val versions: List, -) + val generation: Handle.Named, + val moveLearnMethods: List>, + val pokedexes: List>, + val regions: List>, + val versions: List>, +) : NamedModel diff --git a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/items.kt b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/items.kt index fa5ac040..c43ce89e 100644 --- a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/items.kt +++ b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/items.kt @@ -1,6 +1,6 @@ package co.pokeapi.pokekotlin.model -import co.pokeapi.pokekotlin.internal.JsOnlyExport +import co.pokeapi.pokekotlin.internal.JsNonWasmExport import kotlinx.serialization.Serializable /** @@ -25,31 +25,31 @@ import kotlinx.serialization.Serializable * @param machines A list of the machines related to this item. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class Item( - val id: Int, - val name: String, + override val id: Int, + override val name: String, val cost: Int, val flingPower: Int?, - val flingEffect: NamedApiResource?, - val attributes: List, - val category: NamedApiResource, + val flingEffect: Handle.Named?, + val attributes: List>, + val category: Handle.Named, val effectEntries: List, val flavorTextEntries: List, val gameIndices: List, val names: List, val heldByPokemon: List, - val babyTriggerFor: ApiResource?, + val babyTriggerFor: Handle.Unnamed?, val sprites: ItemSprites, val machines: List, -) +) : NamedModel /** * The sprites used to depict an item in the game. See: https://pokeapi.co/docs/v2#itemsprites * * @param default The default depiction of this item. */ -@Serializable @JsOnlyExport public data class ItemSprites(val default: String?) +@Serializable @JsNonWasmExport public data class ItemSprites(val default: String?) /** * A Pokémon that may be found in the wild holding an item. See: @@ -59,9 +59,9 @@ public data class Item( * @param versionDetails The details for the version that this item is held in by the Pokémon. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class ItemHolderPokemon( - val pokemon: NamedApiResource, + val pokemon: Handle.Named, val versionDetails: List, ) @@ -73,8 +73,11 @@ public data class ItemHolderPokemon( * @param version The version in which the Pokémon holds the item. */ @Serializable -@JsOnlyExport -public data class ItemHolderPokemonVersionDetail(val rarity: Int, val version: NamedApiResource) +@JsNonWasmExport +public data class ItemHolderPokemonVersionDetail( + val rarity: Int, + val version: Handle.Named, +) /** * Natural attributes of items, such as being countable or being usable in battle. See: @@ -87,14 +90,14 @@ public data class ItemHolderPokemonVersionDetail(val rarity: Int, val version: N * @param descriptions The description of this resource listed in different languages. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class ItemAttribute( - val id: Int, - val name: String, - val items: List, + override val id: Int, + override val name: String, + val items: List>, val names: List, val descriptions: List, -) +) : NamedModel /** * Item categories determine where items will be placed in the players bag. See: @@ -107,14 +110,14 @@ public data class ItemAttribute( * @param pocket The pocket items in this category are put into. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class ItemCategory( - val id: Int, - val name: String, - val items: List, + override val id: Int, + override val name: String, + val items: List>, val names: List, - val pocket: NamedApiResource, -) + val pocket: Handle.Named, +) : NamedModel /** * The various effects of the move "Fling" when used with different items. See: @@ -126,13 +129,13 @@ public data class ItemCategory( * @param items A list of items that have this fling effect. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class ItemFlingEffect( - val id: Int, - val name: String, + override val id: Int, + override val name: String, val effectEntries: List, - val items: List, -) + val items: List>, +) : NamedModel /** * Pockets within the players bag used for storing items by category. See: @@ -144,10 +147,10 @@ public data class ItemFlingEffect( * @param names The name of this resource listed in different languages. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class ItemPocket( - val id: Int, - val name: String, - val categories: List, + override val id: Int, + override val name: String, + val categories: List>, val names: List, -) +) : NamedModel diff --git a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/locations.kt b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/locations.kt index b773fb61..60e85cd7 100644 --- a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/locations.kt +++ b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/locations.kt @@ -1,6 +1,6 @@ package co.pokeapi.pokekotlin.model -import co.pokeapi.pokekotlin.internal.JsOnlyExport +import co.pokeapi.pokekotlin.internal.JsNonWasmExport import kotlinx.serialization.Serializable /** @@ -15,15 +15,15 @@ import kotlinx.serialization.Serializable * @param areas A list of areas that can be found in this location. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class Location( - val id: Int, - val name: String, - val region: NamedApiResource?, + override val id: Int, + override val name: String, + val region: Handle.Named?, val names: List, val gameIndices: List, - val areas: List, -) + val areas: List>, +) : NamedModel /** * Location areas are sections of locations, such as floors in a building or cave. Each area has its @@ -40,16 +40,16 @@ public data class Location( * version specific details about the encounter. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class LocationArea( - val id: Int, - val name: String, + override val id: Int, + override val name: String, val gameIndex: Int, val encounterMethodRates: List, - val location: NamedApiResource, + val location: Handle.Named, val names: List, val pokemonEncounters: List, -) +) : NamedModel /** * The encounter rate for a specific encounter method in a location area. See: @@ -59,9 +59,9 @@ public data class LocationArea( * @param versionDetails The chance of the encounter to occur on a version of the game. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class EncounterMethodRate( - val encounterMethod: NamedApiResource, + val encounterMethod: Handle.Named, val versionDetails: List, ) @@ -73,8 +73,11 @@ public data class EncounterMethodRate( * @param version The version of the game in which the encounter can occur with the given chance. */ @Serializable -@JsOnlyExport -public data class EncounterMethodRateVersionDetail(val rate: Int, val version: NamedApiResource) +@JsNonWasmExport +public data class EncounterMethodRateVersionDetail( + val rate: Int, + val version: Handle.Named, +) /** * A Pokémon encounter in a specific location area. See: https://pokeapi.co/docs/v2#pokemonencounter @@ -84,9 +87,9 @@ public data class EncounterMethodRateVersionDetail(val rate: Int, val version: N * referenced location area. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class PokemonEncounter( - val pokemon: NamedApiResource, + val pokemon: Handle.Named, val versionDetails: List, ) @@ -100,13 +103,13 @@ public data class PokemonEncounter( * @param pokemonEncounters A list of Pokémon encountered in this pal park area along with details. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class PalParkArea( - val id: Int, - val name: String, + override val id: Int, + override val name: String, val names: List, val pokemonEncounters: List, -) +) : NamedModel /** * A Pokémon species that can be encountered in a specific Pal Park area. See: @@ -117,11 +120,11 @@ public data class PalParkArea( * @param pokemonSpecies The Pokémon species being encountered. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class PalParkEncounterSpecies( val baseScore: Int, val rate: Int, - val pokemonSpecies: NamedApiResource, + val pokemonSpecies: Handle.Named, ) /** @@ -138,13 +141,13 @@ public data class PalParkEncounterSpecies( * @param versionGroups A list of version groups where this region can be visited. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class Region( - val id: Int, - val name: String, - val locations: List, - val mainGeneration: NamedApiResource?, + override val id: Int, + override val name: String, + val locations: List>, + val mainGeneration: Handle.Named?, val names: List, - val pokedexes: List, - val versionGroups: List, -) + val pokedexes: List>, + val versionGroups: List>, +) : NamedModel diff --git a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/machines.kt b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/machines.kt index c4564e8a..114eaf4a 100644 --- a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/machines.kt +++ b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/machines.kt @@ -1,6 +1,6 @@ package co.pokeapi.pokekotlin.model -import co.pokeapi.pokekotlin.internal.JsOnlyExport +import co.pokeapi.pokekotlin.internal.JsNonWasmExport import kotlinx.serialization.Serializable /** @@ -14,10 +14,10 @@ import kotlinx.serialization.Serializable * @param versionGroup The version group that this machine applies to. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class Machine( - val id: Int, - val item: NamedApiResource, - val move: NamedApiResource, - val versionGroup: NamedApiResource, -) + override val id: Int, + val item: Handle.Named, + val move: Handle.Named, + val versionGroup: Handle.Named, +) : Model diff --git a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/moves.kt b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/moves.kt index deb0d937..04b85ecf 100644 --- a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/moves.kt +++ b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/moves.kt @@ -1,6 +1,6 @@ package co.pokeapi.pokekotlin.model -import co.pokeapi.pokekotlin.internal.JsOnlyExport +import co.pokeapi.pokekotlin.internal.JsNonWasmExport import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -38,33 +38,33 @@ import kotlinx.serialization.Serializable * @param flavorTextEntries The flavor text of this move listed in different languages. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class Move( - val id: Int, - val name: String, + override val id: Int, + override val name: String, val accuracy: Int?, val effectChance: Int?, val pp: Int?, val priority: Int, val power: Int?, val contestCombos: ContestComboSets?, - val contestType: NamedApiResource?, - val contestEffect: ApiResource?, - val superContestEffect: ApiResource?, - val damageClass: NamedApiResource, + val contestType: Handle.Named?, + val contestEffect: Handle.Unnamed?, + val superContestEffect: Handle.Unnamed?, + val damageClass: Handle.Named, val effectEntries: List, val effectChanges: List, - val generation: NamedApiResource, - val learnedByPokemon: List, + val generation: Handle.Named, + val learnedByPokemon: List>, val meta: MoveMetaData?, val names: List, val pastValues: List, val statChanges: List, - val target: NamedApiResource, - val type: NamedApiResource, + val target: Handle.Named, + val type: Handle.Named, val machines: List, val flavorTextEntries: List, -) +) : NamedModel /** * Information about normal and super contest combos for moves. See: @@ -74,7 +74,7 @@ public data class Move( * @param superSet The super contest combo detail. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class ContestComboSets( @SerialName("normal") val normalSet: ContestComboDetail, @SerialName("super") val superSet: ContestComboDetail, @@ -88,10 +88,10 @@ public data class ContestComboSets( * @param useAfter A list of moves that can be used after this move. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class ContestComboDetail( - val useBefore: List?, - val useAfter: List?, + val useBefore: List>?, + val useAfter: List>?, ) /** @@ -113,10 +113,10 @@ public data class ContestComboDetail( * @param statChance The likelihood this attack will cause a stat change in the target Pokémon. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class MoveMetaData( - val ailment: NamedApiResource, - val category: NamedApiResource, + val ailment: Handle.Named, + val category: Handle.Named, val minHits: Int?, val maxHits: Int?, val minTurns: Int?, @@ -136,8 +136,8 @@ public data class MoveMetaData( * @param stat The stat being affected. */ @Serializable -@JsOnlyExport -public data class MoveStatChange(val change: Int, val stat: NamedApiResource) +@JsNonWasmExport +public data class MoveStatChange(val change: Int, val stat: Handle.Named) /** * The stat values of a move in previous versions of the games. See: @@ -152,15 +152,15 @@ public data class MoveStatChange(val change: Int, val stat: NamedApiResource) * @param versionGroup The version group in which these move stat values were in effect. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class PastMoveStatValues( val accuracy: Int?, val effectChance: Int?, val power: Int?, val pp: Int?, val effectEntries: List, - val type: NamedApiResource?, - val versionGroup: NamedApiResource, + val type: Handle.Named?, + val versionGroup: Handle.Named, ) /** @@ -173,13 +173,13 @@ public data class PastMoveStatValues( * @param names The name of this resource listed in different languages. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class MoveAilment( - val id: Int, - val name: String, - val moves: List, + override val id: Int, + override val name: String, + val moves: List>, val names: List, -) +) : NamedModel /** * Styles of moves when used in the Battle Palace. See the bulbapedia article for greater detail. @@ -190,8 +190,12 @@ public data class MoveAilment( * @param names The name of this resource listed in different languages. */ @Serializable -@JsOnlyExport -public data class MoveBattleStyle(val id: Int, val name: String, val names: List) +@JsNonWasmExport +public data class MoveBattleStyle( + override val id: Int, + override val name: String, + val names: List, +) : NamedModel /** * Very general categories that loosely group move effects. See: @@ -203,13 +207,13 @@ public data class MoveBattleStyle(val id: Int, val name: String, val names: List * @param descriptions The description of this resource listed in different languages. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class MoveCategory( - val id: Int, - val name: String, - val moves: List, + override val id: Int, + override val name: String, + val moves: List>, val descriptions: List, -) +) : NamedModel /** * Damage classes moves can have, e.g. physical, special, or non-damaging. See: @@ -222,14 +226,14 @@ public data class MoveCategory( * @param names The name of this resource listed in different languages. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class MoveDamageClass( - val id: Int, - val name: String, + override val id: Int, + override val name: String, val descriptions: List, - val moves: List, + val moves: List>, val names: List, -) +) : NamedModel /** * Methods by which Pokémon can learn moves. See: https://pokeapi.co/docs/v2#move-learn-methods @@ -241,14 +245,14 @@ public data class MoveDamageClass( * @param versionGroups A list of version groups where this learn method is available. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class MoveLearnMethod( - val id: Int, - val name: String, + override val id: Int, + override val name: String, val descriptions: List, val names: List, - val versionGroups: List, -) + val versionGroups: List>, +) : NamedModel /** * Information about different types of targets that moves can be directed at during battle. Targets @@ -261,14 +265,14 @@ public data class MoveLearnMethod( * @param names The name of this resource listed in different languages. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class MoveTarget( - val id: Int, - val name: String, + override val id: Int, + override val name: String, val descriptions: List, - val moves: List, + val moves: List>, val names: List, -) +) : NamedModel /** * The flavor text of a move listed in different languages and version groups. See: @@ -279,9 +283,9 @@ public data class MoveTarget( * @param versionGroup The version group that uses this flavor text. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class MoveFlavorText( val flavorText: String, - val language: NamedApiResource, - val versionGroup: NamedApiResource, + val language: Handle.Named, + val versionGroup: Handle.Named, ) diff --git a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/pokemon.kt b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/pokemon.kt index 37abdd98..978437bb 100644 --- a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/pokemon.kt +++ b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/pokemon.kt @@ -1,6 +1,6 @@ package co.pokeapi.pokekotlin.model -import co.pokeapi.pokekotlin.internal.JsOnlyExport +import co.pokeapi.pokekotlin.internal.JsNonWasmExport import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -20,18 +20,18 @@ import kotlinx.serialization.Serializable * @param pokemon A list of Pokémon that could potentially have this ability. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class Ability( - val id: Int, - val name: String, + override val id: Int, + override val name: String, val isMainSeries: Boolean, - val generation: NamedApiResource, + val generation: Handle.Named, val names: List, val effectEntries: List, val effectChanges: List, val flavorTextEntries: List, val pokemon: List, -) +) : NamedModel /** * The effect of an ability listed in different version groups and languages. See: @@ -41,10 +41,10 @@ public data class Ability( * @param versionGroup The version group for which the effect applies. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class AbilityEffectChange( val effectEntries: List, - val versionGroup: NamedApiResource, + val versionGroup: Handle.Named, ) /** @@ -56,11 +56,11 @@ public data class AbilityEffectChange( * @param versionGroup The version group for which the flavor text applies. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class AbilityFlavorText( val flavorText: String, - val language: NamedApiResource, - val versionGroup: NamedApiResource, + val language: Handle.Named, + val versionGroup: Handle.Named, ) /** @@ -71,11 +71,11 @@ public data class AbilityFlavorText( * @param pokemon The Pokémon that has the referenced ability. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class AbilityPokemon( val isHidden: Boolean, val slot: Int, - val pokemon: NamedApiResource, + val pokemon: Handle.Named, ) /** @@ -88,13 +88,13 @@ public data class AbilityPokemon( * @param descriptions The descriptions for this characteristic listed in different languages. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class Characteristic( - val id: Int, + override val id: Int, val geneModulo: Int, val possibleValues: List, val descriptions: List, -) +) : Model /** * Egg Groups are categories which determine which Pokémon are able to interbreed. See: @@ -106,13 +106,13 @@ public data class Characteristic( * @param pokemonSpecies A list of all Pokémon species that are members of this egg group. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class EggGroup( - val id: Int, - val name: String, + override val id: Int, + override val name: String, val names: List, - val pokemonSpecies: List, -) + val pokemonSpecies: List>, +) : NamedModel /** * Genders affect whether a Pokémon can breed and what moves it can learn. See: @@ -126,13 +126,13 @@ public data class EggGroup( * Pokémon to evolve into them. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class Gender( - val id: Int, - val name: String, + override val id: Int, + override val name: String, val pokemonSpeciesDetails: List, - val requiredForEvolution: List, -) + val requiredForEvolution: List>, +) : NamedModel /** * Pokémon species gender details. See: https://pokeapi.co/docs/v2#pokemonspeciesgender @@ -141,8 +141,11 @@ public data class Gender( * @param pokemonSpecies The Pokémon species this gender detail applies to. */ @Serializable -@JsOnlyExport -public data class PokemonSpeciesGender(val rate: Int, val pokemonSpecies: NamedApiResource) +@JsNonWasmExport +public data class PokemonSpeciesGender( + val rate: Int, + val pokemonSpecies: Handle.Named, +) /** * Growth rates determine how much experience Pokémon need to level up. See: @@ -156,15 +159,15 @@ public data class PokemonSpeciesGender(val rate: Int, val pokemonSpecies: NamedA * @param pokemonSpecies A list of Pokémon species that have this growth rate. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class GrowthRate( - val id: Int, - val name: String, + override val id: Int, + override val name: String, val formula: String, val descriptions: List, val levels: List, - val pokemonSpecies: List, -) + val pokemonSpecies: List>, +) : NamedModel /** * Experience required for a Pokémon to reach a certain level for a given growth rate. See: @@ -174,7 +177,7 @@ public data class GrowthRate( * @param experience The amount of experience required to reach the referenced level. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class GrowthRateExperienceLevel(val level: Int, val experience: Int) /** @@ -192,18 +195,18 @@ public data class GrowthRateExperienceLevel(val level: Int, val experience: Int) * @param names The name of this nature listed in different languages. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class Nature( - val id: Int, - val name: String, - val decreasedStat: NamedApiResource?, - val increasedStat: NamedApiResource?, - val hatesFlavor: NamedApiResource?, - val likesFlavor: NamedApiResource?, + override val id: Int, + override val name: String, + val decreasedStat: Handle.Named?, + val increasedStat: Handle.Named?, + val hatesFlavor: Handle.Named?, + val likesFlavor: Handle.Named?, val pokeathlonStatChanges: List, val moveBattleStylePreferences: List, val names: List, -) +) : NamedModel /** * Change to a Pokeathlon stat for a given nature. See: https://pokeapi.co/docs/v2#naturestatchange @@ -212,8 +215,11 @@ public data class Nature( * @param pokeathlonStat The Pokeathlon stat being affected. */ @Serializable -@JsOnlyExport -public data class NatureStatChange(val maxChange: Int, val pokeathlonStat: NamedApiResource) +@JsNonWasmExport +public data class NatureStatChange( + val maxChange: Int, + val pokeathlonStat: Handle.Named, +) /** * Move battle style preferences for a given nature. See: @@ -224,11 +230,11 @@ public data class NatureStatChange(val maxChange: Int, val pokeathlonStat: Named * @param moveBattleStyle The move battle style. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class MoveBattleStylePreference( val lowHpPreference: Int, val highHpPreference: Int, - val moveBattleStyle: NamedApiResource, + val moveBattleStyle: Handle.Named, ) /** @@ -241,13 +247,13 @@ public data class MoveBattleStylePreference( * @param affectingNatures A set of natures and how they affect this Pokeathlon stat. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class PokeathlonStat( - val id: Int, - val name: String, + override val id: Int, + override val name: String, val names: List, val affectingNatures: NaturePokeathlonStatEffectSets, -) +) : NamedModel /** * A set of natures and how they affect a Pokeathlon stat. See: @@ -257,7 +263,7 @@ public data class PokeathlonStat( * @param decrease Natures that decrease the referenced Pokeathlon stat and by how much. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class NaturePokeathlonStatEffectSets( val increase: List, val decrease: List, @@ -271,8 +277,8 @@ public data class NaturePokeathlonStatEffectSets( * @param nature The nature that affects the referenced Pokeathlon stat. */ @Serializable -@JsOnlyExport -public data class NaturePokeathlonStatEffect(val maxChange: Int, val nature: NamedApiResource) +@JsNonWasmExport +public data class NaturePokeathlonStatEffect(val maxChange: Int, val nature: Handle.Named) /** * Pokémon are the creatures that inhabit the world of the Pokémon games. They have a variety of @@ -299,18 +305,18 @@ public data class NaturePokeathlonStatEffect(val maxChange: Int, val nature: Nam * @param sprites A set of sprites used to depict this Pokémon in the game. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class PokemonVariety( - val id: Int, - val name: String, + override val id: Int, + override val name: String, val baseExperience: Int, val height: Int, val isDefault: Boolean, val order: Int, val weight: Int, - val species: NamedApiResource, + val species: Handle.Named, val abilities: List, - val forms: List, + val forms: List>, val gameIndices: List, val heldItems: List, val moves: List, @@ -320,7 +326,7 @@ public data class PokemonVariety( val pastAbilities: List, val cries: PokemonCries, val sprites: PokemonSprites, -) +) : NamedModel /** * Sprites are images used to depict Pokémon in the game. See: @@ -338,7 +344,7 @@ public data class PokemonVariety( * @param versions Sprites for this Pokémon in different versions. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class PokemonSprites( val backDefault: String?, val backShiny: String?, @@ -362,7 +368,7 @@ public data class PokemonSprites( * @param showdown Showdown sprites. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class OtherGameSprites( val dreamWorld: GameSprites, val home: GameSprites, @@ -383,7 +389,7 @@ public data class OtherGameSprites( * @param generationViii Sprites for Generation VIII games. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class VersionGameSprites( @SerialName("generation-i") val generationI: GenerationIGameSprites, @SerialName("generation-ii") val generationIi: GenerationIiGameSprites, @@ -396,14 +402,14 @@ public data class VersionGameSprites( ) @Serializable -@JsOnlyExport +@JsNonWasmExport public data class GenerationIGameSprites( @SerialName("red-blue") val redBlue: GameSprites, val yellow: GameSprites, ) @Serializable -@JsOnlyExport +@JsNonWasmExport public data class GenerationIiGameSprites( val crystal: GameSprites, val gold: GameSprites, @@ -411,7 +417,7 @@ public data class GenerationIiGameSprites( ) @Serializable -@JsOnlyExport +@JsNonWasmExport public data class GenerationIiiGameSprites( val emerald: GameSprites, @SerialName("firered-leafgreen") val fireredLeafgreen: GameSprites, @@ -419,7 +425,7 @@ public data class GenerationIiiGameSprites( ) @Serializable -@JsOnlyExport +@JsNonWasmExport public data class GenerationIvGameSprites( @SerialName("diamond-pearl") val diamondPearl: GameSprites, @SerialName("heartgold-soulsilver") val heartgoldSoulsilver: GameSprites, @@ -427,13 +433,13 @@ public data class GenerationIvGameSprites( ) @Serializable -@JsOnlyExport +@JsNonWasmExport public data class GenerationVGameSprites( @SerialName("black-white") val blackWhite: BlackWhiteSprites ) @Serializable -@JsOnlyExport +@JsNonWasmExport public data class BlackWhiteSprites( val animated: GameSprites, val backDefault: String? = null, @@ -447,27 +453,27 @@ public data class BlackWhiteSprites( ) @Serializable -@JsOnlyExport +@JsNonWasmExport public data class GenerationViGameSprites( @SerialName("omegaruby-alphasapphire") val omegaRubyAlphaSapphire: GameSprites, @SerialName("x-y") val xY: GameSprites, ) @Serializable -@JsOnlyExport +@JsNonWasmExport public data class GenerationViiGameSprites( val icons: GameSprites, @SerialName("ultra-sun-ultra-moon") val ultraSunUltraMoon: GameSprites, ) -@Serializable @JsOnlyExport public data class GenerationViiiGameSprites(val icons: GameSprites) +@Serializable @JsNonWasmExport public data class GenerationViiiGameSprites(val icons: GameSprites) /** * All available sprites for a Pokémon in a specific game or context. Each game will only have a * subset of these sprites present. See: https://pokeapi.co/docs/v2#pokemonsprites */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class GameSprites( val animated: GameSprites? = null, val backDefault: String? = null, @@ -495,11 +501,11 @@ public data class GameSprites( * @param ability The ability the Pokémon may have. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class PokemonAbility( val isHidden: Boolean, val slot: Int, - val ability: NamedApiResource?, + val ability: Handle.Named?, ) /** @@ -510,9 +516,9 @@ public data class PokemonAbility( * @param versionDetails The details of the version in which the item is held. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class PokemonHeldItem( - val item: NamedApiResource, + val item: Handle.Named, val versionDetails: List, ) @@ -524,8 +530,8 @@ public data class PokemonHeldItem( * @param rarity The rarity of the held item in the version. */ @Serializable -@JsOnlyExport -public data class PokemonHeldItemVersion(val version: NamedApiResource, val rarity: Int) +@JsNonWasmExport +public data class PokemonHeldItemVersion(val version: Handle.Named, val rarity: Int) /** * Moves that a Pokémon can learn. See: https://pokeapi.co/docs/v2#pokemonmove @@ -534,9 +540,9 @@ public data class PokemonHeldItemVersion(val version: NamedApiResource, val rari * @param versionGroupDetails The details of the version group in which the move can be learned. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class PokemonMove( - val move: NamedApiResource, + val move: Handle.Named, val versionGroupDetails: List, ) @@ -550,10 +556,10 @@ public data class PokemonMove( * @param order The order in which the move is learned, if applicable. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class PokemonMoveVersion( - val moveLearnMethod: NamedApiResource, - val versionGroup: NamedApiResource, + val moveLearnMethod: Handle.Named, + val versionGroup: Handle.Named, val levelLearnedAt: Int, val order: Int?, ) @@ -566,8 +572,8 @@ public data class PokemonMoveVersion( * @param baseStat The base value of the stat. */ @Serializable -@JsOnlyExport -public data class PokemonStat(val stat: NamedApiResource, val effort: Int, val baseStat: Int) +@JsNonWasmExport +public data class PokemonStat(val stat: Handle.Named, val effort: Int, val baseStat: Int) /** * The type of a Pokémon and its slot. See: https://pokeapi.co/docs/v2#pokemontype @@ -576,8 +582,8 @@ public data class PokemonStat(val stat: NamedApiResource, val effort: Int, val b * @param type The type the Pokémon has. */ @Serializable -@JsOnlyExport -public data class PokemonType(val slot: Int, val type: NamedApiResource) +@JsNonWasmExport +public data class PokemonType(val slot: Int, val type: Handle.Named) /** * The types a Pokémon had in a previous generation. See: https://pokeapi.co/docs/v2#pokemonpasttype @@ -586,8 +592,11 @@ public data class PokemonType(val slot: Int, val type: NamedApiResource) * @param types The types the Pokémon had in that generation. */ @Serializable -@JsOnlyExport -public data class PokemonPastType(val generation: NamedApiResource, val types: List) +@JsNonWasmExport +public data class PokemonPastType( + val generation: Handle.Named, + val types: List, +) /** * The abilities a Pokémon had in a previous generation. See: @@ -597,9 +606,9 @@ public data class PokemonPastType(val generation: NamedApiResource, val types: L * @param abilities The abilities the Pokémon had in that generation. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class PokemonPastAbility( - val generation: NamedApiResource, + val generation: Handle.Named, val abilities: List, ) @@ -609,7 +618,9 @@ public data class PokemonPastAbility( * @param latest The latest cry for this Pokémon. * @param legacy The legacy cry for this Pokémon, if any. */ -@Serializable @JsOnlyExport public data class PokemonCries(val latest: String, val legacy: String?) +@Serializable +@JsNonWasmExport +public data class PokemonCries(val latest: String, val legacy: String?) /** * Details about a Pokémon's encounters in a location area. See: @@ -619,9 +630,9 @@ public data class PokemonPastAbility( * @param versionDetails The details of the encounter in each version. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class LocationAreaEncounter( - val locationArea: NamedApiResource, + val locationArea: Handle.Named, val versionDetails: List, ) @@ -635,13 +646,13 @@ public data class LocationAreaEncounter( * @param pokemonSpecies A list of the Pokémon species that have this color. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class PokemonColor( - val id: Int, - val name: String, + override val id: Int, + override val name: String, val names: List, - val pokemonSpecies: List, -) + val pokemonSpecies: List>, +) : NamedModel /** * Some Pokémon may appear in one of multiple, visually different forms. These differences are @@ -667,23 +678,23 @@ public data class PokemonColor( * have a specific name. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class PokemonForm( - val id: Int, - val name: String, + override val id: Int, + override val name: String, val order: Int, val formOrder: Int, val isDefault: Boolean, val isBattleOnly: Boolean, val isMega: Boolean, val formName: String, - val pokemon: NamedApiResource, + val pokemon: Handle.Named, val types: List, val sprites: PokemonFormSprites, - val versionGroup: NamedApiResource, + val versionGroup: Handle.Named, val names: List, val formNames: List, -) +) : NamedModel /** * Sprites used to depict a Pokémon form. See: https://pokeapi.co/docs/v2#pokemonformsprites @@ -698,7 +709,7 @@ public data class PokemonForm( * @param frontShinyFemale The female shiny front sprite for this Pokémon form. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class PokemonFormSprites( val backDefault: String?, val backFemale: String?, @@ -720,13 +731,13 @@ public data class PokemonFormSprites( * @param pokemonSpecies A list of the Pokémon species that can be found in this habitat. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class PokemonHabitat( - val id: Int, - val name: String, + override val id: Int, + override val name: String, val names: List, - val pokemonSpecies: List, -) + val pokemonSpecies: List>, +) : NamedModel /** * Shapes are used to determine a Pokémon's appearance and for search purposes. See: @@ -739,14 +750,14 @@ public data class PokemonHabitat( * @param pokemonSpecies A list of the Pokémon species that have this shape. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class PokemonShape( - val id: Int, - val name: String, + override val id: Int, + override val name: String, val awesomeNames: List, val names: List, - val pokemonSpecies: List, -) + val pokemonSpecies: List>, +) : NamedModel /** * The "scientific" name of a Pokémon shape. See: https://pokeapi.co/docs/v2#awesomename @@ -755,8 +766,8 @@ public data class PokemonShape( * @param language The language this "scientific" name is in. */ @Serializable -@JsOnlyExport -public data class AwesomeName(val awesomeName: String, val language: NamedApiResource) +@JsNonWasmExport +public data class AwesomeName(val awesomeName: String, val language: Handle.Named) /** * A Pokémon Species forms the basis for at least one Pokémon. Attributes of a Pokémon species are @@ -797,10 +808,10 @@ public data class AwesomeName(val awesomeName: String, val language: NamedApiRes * @param flavorTextEntries A list of flavor text entries for this Pokémon species. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class PokemonSpecies( - val id: Int, - val name: String, + override val id: Int, + override val name: String, val order: Int, val genderRate: Int, val captureRate: Int, @@ -811,22 +822,22 @@ public data class PokemonSpecies( val hatchCounter: Int, val hasGenderDifferences: Boolean, val formsSwitchable: Boolean, - val growthRate: NamedApiResource, + val growthRate: Handle.Named, val pokedexNumbers: List, - val eggGroups: List, - val color: NamedApiResource, - val shape: NamedApiResource, - val evolvesFromSpecies: NamedApiResource?, - val evolutionChain: ApiResource, - val habitat: NamedApiResource?, - val generation: NamedApiResource, + val eggGroups: List>, + val color: Handle.Named, + val shape: Handle.Named, + val evolvesFromSpecies: Handle.Named?, + val evolutionChain: Handle.Unnamed, + val habitat: Handle.Named?, + val generation: Handle.Named, val names: List, val palParkEncounters: List, val formDescriptions: List, val genera: List, val varieties: List, val flavorTextEntries: List, -) +) : NamedModel /** * Flavor text entries for a Pokémon species. See: https://pokeapi.co/docs/v2#flavortext @@ -836,11 +847,11 @@ public data class PokemonSpecies( * @param version The version this flavor text is extracted from. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class PokemonSpeciesFlavorText( val flavorText: String, - val language: NamedApiResource, - val version: NamedApiResource, + val language: Handle.Named, + val version: Handle.Named, ) /** @@ -851,8 +862,8 @@ public data class PokemonSpeciesFlavorText( * @param language The language this genus is in. */ @Serializable -@JsOnlyExport -public data class Genus(val genus: String, val language: NamedApiResource) +@JsNonWasmExport +public data class Genus(val genus: String, val language: Handle.Named) /** * The Pokédex number of a Pokémon species in a specific Pokédex. See: @@ -862,8 +873,8 @@ public data class Genus(val genus: String, val language: NamedApiResource) * @param pokedex The Pokédex the referenced Pokémon species can be found in. */ @Serializable -@JsOnlyExport -public data class PokemonSpeciesDexEntry(val entryNumber: Int, val pokedex: NamedApiResource) +@JsNonWasmExport +public data class PokemonSpeciesDexEntry(val entryNumber: Int, val pokedex: Handle.Named) /** * Areas used for grouping Pokémon encounters in Pal Park. See: @@ -875,11 +886,11 @@ public data class PokemonSpeciesDexEntry(val entryNumber: Int, val pokedex: Name * @param area The pal park area where this encounter happens. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class PalParkEncounterArea( val baseScore: Int, val rate: Int, - val area: NamedApiResource, + val area: Handle.Named, ) /** @@ -889,10 +900,10 @@ public data class PalParkEncounterArea( * @param variety The Pokémon variety. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class PokemonSpeciesVariety( val isDefault: Boolean, - @SerialName("pokemon") val variety: NamedApiResource, + @SerialName("pokemon") val variety: Handle.Named, ) /** @@ -912,18 +923,18 @@ public data class PokemonSpeciesVariety( * @param names The name of this stat listed in different languages. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class Stat( - val id: Int, - val name: String, + override val id: Int, + override val name: String, val gameIndex: Int, val isBattleOnly: Boolean, val affectingMoves: MoveStatAffectSets, val affectingNatures: NatureStatAffectSets, - val characteristics: List, - val moveDamageClass: NamedApiResource?, + val characteristics: List>, + val moveDamageClass: Handle.Named?, val names: List, -) +) : NamedModel /** * A set of moves that affect a stat and how they affect it. See: @@ -933,7 +944,7 @@ public data class Stat( * @param decrease Moves that decrease the stat and by how much. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class MoveStatAffectSets( val increase: List, val decrease: List, @@ -946,8 +957,8 @@ public data class MoveStatAffectSets( * @param move The move that affects this stat. */ @Serializable -@JsOnlyExport -public data class MoveStatAffect(val change: Int, val move: NamedApiResource) +@JsNonWasmExport +public data class MoveStatAffect(val change: Int, val move: Handle.Named) /** * A set of natures that affect a stat and how they affect it. See: @@ -957,10 +968,10 @@ public data class MoveStatAffect(val change: Int, val move: NamedApiResource) * @param decrease Natures that decrease the stat. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class NatureStatAffectSets( - val increase: List, - val decrease: List, + val increase: List>, + val decrease: List>, ) /** @@ -983,23 +994,23 @@ public data class NatureStatAffectSets( * @param sprites Sprites for this type. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class Type( - val id: Int, - val name: String, + override val id: Int, + override val name: String, val damageRelations: TypeRelations, val pastDamageRelations: List, val gameIndices: List, - val generation: NamedApiResource, - val moveDamageClass: NamedApiResource?, + val generation: Handle.Named, + val moveDamageClass: Handle.Named?, val names: List, val pokemon: List, - val moves: List, + val moves: List>, val sprites: VersionTypeSprites, -) +) : NamedModel @Serializable -@JsOnlyExport +@JsNonWasmExport public data class VersionTypeSprites( @SerialName("generation-iii") val generationIii: GenerationIiiTypeSprites, @SerialName("generation-iv") val generationIv: GenerationIvTypeSprites, @@ -1011,7 +1022,7 @@ public data class VersionTypeSprites( ) @Serializable -@JsOnlyExport +@JsNonWasmExport public data class GenerationIiiTypeSprites( val colosseum: TypeSprites, val emerald: TypeSprites, @@ -1021,7 +1032,7 @@ public data class GenerationIiiTypeSprites( ) @Serializable -@JsOnlyExport +@JsNonWasmExport public data class GenerationIvTypeSprites( @SerialName("diamond-pearl") val diamondPearl: TypeSprites, @SerialName("heartgold-soulsilver") val heartgoldSoulsilver: TypeSprites, @@ -1029,21 +1040,21 @@ public data class GenerationIvTypeSprites( ) @Serializable -@JsOnlyExport +@JsNonWasmExport public data class GenerationVTypeSprites( @SerialName("black-2-white-2") val black2White2: TypeSprites, @SerialName("black-white") val blackWhite: TypeSprites, ) @Serializable -@JsOnlyExport +@JsNonWasmExport public data class GenerationViTypeSprites( @SerialName("omega-ruby-alpha-sapphire") val omegaRubyAlphaSapphire: TypeSprites, @SerialName("x-y") val xY: TypeSprites, ) @Serializable -@JsOnlyExport +@JsNonWasmExport public data class GenerationViiTypeSprites( @SerialName("lets-go-pikachu-lets-go-eevee") val letsGoPikachuLetsGoEevee: TypeSprites, @SerialName("sun-moon") val sunMoon: TypeSprites, @@ -1051,7 +1062,7 @@ public data class GenerationViiTypeSprites( ) @Serializable -@JsOnlyExport +@JsNonWasmExport public data class GenerationViiiTypeSprites( @SerialName("brilliant-diamond-and-shining-pearl") val brilliantDiamondAndShiningPearl: TypeSprites, @@ -1060,12 +1071,12 @@ public data class GenerationViiiTypeSprites( ) @Serializable -@JsOnlyExport +@JsNonWasmExport public data class GenerationIxTypeSprites( @SerialName("scarlet-violet") val scarletViolet: TypeSprites ) -@Serializable @JsOnlyExport public data class TypeSprites(val nameIcon: String?) +@Serializable @JsNonWasmExport public data class TypeSprites(val nameIcon: String?) /** * Details of Pokémon that have a specific type. See: https://pokeapi.co/docs/v2#typepokemon @@ -1074,8 +1085,8 @@ public data class GenerationIxTypeSprites( * @param pokemon The Pokémon that has this type. */ @Serializable -@JsOnlyExport -public data class TypePokemon(val slot: Int, val pokemon: NamedApiResource) +@JsNonWasmExport +public data class TypePokemon(val slot: Int, val pokemon: Handle.Named) /** * A detail of how effective this type is toward others and vice versa. See: @@ -1089,14 +1100,14 @@ public data class TypePokemon(val slot: Int, val pokemon: NamedApiResource) * @param doubleDamageFrom A list of types that are very effective against this type. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class TypeRelations( - val noDamageTo: List, - val halfDamageTo: List, - val doubleDamageTo: List, - val noDamageFrom: List, - val halfDamageFrom: List, - val doubleDamageFrom: List, + val noDamageTo: List>, + val halfDamageTo: List>, + val doubleDamageTo: List>, + val noDamageFrom: List>, + val halfDamageFrom: List>, + val doubleDamageFrom: List>, ) /** @@ -1107,8 +1118,8 @@ public data class TypeRelations( * @param damageRelations The damage relations that applied in the referenced generation. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class TypePastDamageRelation( - val generation: NamedApiResource, + val generation: Handle.Named, val damageRelations: TypeRelations, ) diff --git a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/resource.kt b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/resource.kt index 06d57568..34ee2088 100644 --- a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/resource.kt +++ b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/resource.kt @@ -1,105 +1,153 @@ package co.pokeapi.pokekotlin.model -import co.pokeapi.pokekotlin.internal.ApiResourceSerializer -import co.pokeapi.pokekotlin.internal.JsOnlyExport -import co.pokeapi.pokekotlin.internal.NamedApiResourceSerializer -import kotlin.js.JsName +import co.pokeapi.pokekotlin.internal.HandleSerializers +import co.pokeapi.pokekotlin.internal.JsNonWasmExport +import kotlin.reflect.KClass import kotlinx.serialization.Serializable -private fun urlToId(url: String): Int { - return "/-?[0-9]+/$".toRegex().find(url)!!.value.filter { it.isDigit() || it == '-' }.toInt() -} +@Suppress("EnumEntryName") +internal enum class ResourceEndpoint(val model: KClass) { + ability(Ability::class), + berry(Berry::class), + `berry-firmness`(BerryFirmness::class), + `berry-flavor`(BerryFlavor::class), + characteristic(Characteristic::class), + `contest-effect`(ContestEffect::class), + `contest-type`(ContestType::class), + `egg-group`(EggGroup::class), + `encounter-condition`(EncounterCondition::class), + `encounter-condition-value`(EncounterConditionValue::class), + `encounter-method`(EncounterMethod::class), + `evolution-chain`(EvolutionChain::class), + `evolution-trigger`(EvolutionTrigger::class), + gender(Gender::class), + generation(Generation::class), + `growth-rate`(GrowthRate::class), + item(Item::class), + `item-attribute`(ItemAttribute::class), + `item-category`(ItemCategory::class), + `item-fling-effect`(ItemFlingEffect::class), + `item-pocket`(ItemPocket::class), + language(Language::class), + location(Location::class), + `location-area`(LocationArea::class), + machine(Machine::class), + move(Move::class), + `move-ailment`(MoveAilment::class), + `move-battle-style`(MoveBattleStyle::class), + `move-category`(MoveCategory::class), + `move-damage-class`(MoveDamageClass::class), + `move-learn-method`(MoveLearnMethod::class), + `move-target`(MoveTarget::class), + nature(Nature::class), + `pal-park-area`(PalParkArea::class), + `pokeathlon-stat`(PokeathlonStat::class), + pokedex(Pokedex::class), + pokemon(PokemonVariety::class), + `pokemon-color`(PokemonColor::class), + `pokemon-form`(PokemonForm::class), + `pokemon-habitat`(PokemonHabitat::class), + `pokemon-shape`(PokemonShape::class), + `pokemon-species`(PokemonSpecies::class), + region(Region::class), + stat(Stat::class), + `super-contest-effect`(SuperContestEffect::class), + type(Type::class), + version(Version::class), + `version-group`(VersionGroup::class); -private fun urlToCat(url: String): String { - return "/[a-z\\-]+/-?[0-9]+/$".toRegex().find(url)!!.value.filter { it.isLetter() || it == '-' } -} + companion object { + private val modelToEntry = entries.associateBy { it.model } + + operator fun get(model: KClass) = + modelToEntry[model] ?: throw NoSuchElementException(model.simpleName) -private fun resourceUrl(id: Int, category: String): String { - return "/api/v2/$category/$id/" + inline fun forModel() = get(T::class) + } + + override fun toString() = name } /** - * Represents a summary of a resource, providing its id and category. + * Represents a reference to a resource in the API by URL. * * @property id The identifier for the resource. - * @property category The resource category (endpoint name). */ -@JsOnlyExport -public interface ResourceSummary { - public val id: Int - public val category: String -} +@JsNonWasmExport +public sealed class Handle { + internal abstract val url: String -/** - * Represents a reference to another resource in the API by URL. This matches the "resource" object - * pattern in the PokeAPI documentation. See: - * https://pokeapi.co/docs/v2#resource-listspagination-section - * - * @param url The URL of the referenced resource. - */ -@Serializable(with = ApiResourceSerializer::class) -@JsOnlyExport -public data class ApiResource(val url: String) : ResourceSummary { - @JsName("create") public constructor(category: String, id: Int) : this(resourceUrl(id, category)) + internal val model: KClass by lazy { + val match = urlRegex.find(url)?.groupValues[1] ?: throw IllegalArgumentException(url) + @Suppress("UNCHECKED_CAST") + ResourceEndpoint.valueOf(match).model as KClass + } - override val category: String by lazy { urlToCat(url) } - override val id: Int by lazy { urlToId(url) } -} + public val id: Int by lazy { + urlRegex.find(url)?.groupValues[2]?.toInt() ?: throw IllegalArgumentException(url) + } -/** - * Represents a reference to another resource in the API by name and URL. This matches the "named - * resource" object pattern in the PokeAPI documentation. See: - * https://pokeapi.co/docs/v2#resource-listspagination-section - * - * @param name The name of the referenced resource. - * @param url The URL of the referenced resource. - */ -@Serializable(with = NamedApiResourceSerializer::class) -@JsOnlyExport -public data class NamedApiResource(val name: String, val url: String) : ResourceSummary { - - @JsName("create") - public constructor( - name: String, - category: String, - id: Int, - ) : this(name, resourceUrl(id, category)) - - override val category: String by lazy { urlToCat(url) } - override val id: Int by lazy { urlToId(url) } + internal companion object Companion { + private val urlRegex = "/([a-z\\-]+)/(-?[0-9]+)/$".toRegex() + + internal inline fun of(id: Int): Unnamed = + Unnamed("/api/v2/${ResourceEndpoint.forModel()}/$id/") + + internal inline fun of(id: Int, name: String): Named = + Named("/api/v2/${ResourceEndpoint.forModel()}/$id/", name) + } + + /** + * Represents a reference to another resource in the API by URL only. This matches the "resource" + * object pattern in the PokeAPI documentation. See: https://pokeapi.co/docs/v2#apiresource + */ + @Serializable(with = HandleSerializers.Unnamed::class) + public data class Unnamed internal constructor(override val url: String) : + Handle() + + /** + * Represents a reference to another resource in the API by name and URL. This matches the "named + * resource" object pattern in the PokeAPI documentation. See: + * https://pokeapi.co/docs/v2#namedapiresource + * + * @param name The (unique) name of the referenced resource. + */ + @Serializable(with = HandleSerializers.Named::class) + public data class Named + internal constructor(override val url: String, val name: String) : Handle() } /** - * Represents a paginated list of resource summaries, similar to the paginated resource list objects - * in the PokeAPI. See: https://pokeapi.co/docs/v2#resource-lists-section + * Represents a paginated list of [Handle], similar to the paginated resource list objects in the + * PokeAPI. See: https://pokeapi.co/docs/v2#resource-listspagination-section * * @property count The total number of resources available from this API. * @property next The URL for the next page in the list. * @property previous The URL for the previous page in the list. * @property results The list of returned resources in this page. */ -@JsOnlyExport -public interface ResourceSummaryList { - public val count: Int - public val next: String? - public val previous: String? - public val results: List -} +@JsNonWasmExport +public sealed class PaginatedList { + public abstract val count: Int + public abstract val next: String? + public abstract val previous: String? + public abstract val results: List> -@Serializable -@JsOnlyExport -public data class ApiResourceList( - override val count: Int, - override val next: String?, - override val previous: String?, - override val results: List, -) : ResourceSummaryList - -@Serializable -@JsOnlyExport -public data class NamedApiResourceList( - override val count: Int, - override val next: String?, - override val previous: String?, - override val results: List, -) : ResourceSummaryList + @Serializable + public data class Unnamed + internal constructor( + override val count: Int, + override val next: String?, + override val previous: String?, + override val results: List>, + ) : PaginatedList() + + @Serializable + public data class Named + internal constructor( + override val count: Int, + override val next: String?, + override val previous: String?, + override val results: List>, + ) : PaginatedList() +} diff --git a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/utility.kt b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/utility.kt index 4ea8b979..cbf35066 100644 --- a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/utility.kt +++ b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/utility.kt @@ -1,6 +1,6 @@ package co.pokeapi.pokekotlin.model -import co.pokeapi.pokekotlin.internal.JsOnlyExport +import co.pokeapi.pokekotlin.internal.JsNonWasmExport import kotlinx.serialization.Serializable /** @@ -16,15 +16,15 @@ import kotlinx.serialization.Serializable * @param names The localized names for this language resource. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class Language( - val id: Int, - val name: String, + override val id: Int, + override val name: String, val official: Boolean, val iso639: String, val iso3166: String, val names: List, -) +) : NamedModel /** * The localized description for an API resource in a specific language. See: @@ -34,8 +34,8 @@ public data class Language( * @param language The language this description is in. */ @Serializable -@JsOnlyExport -public data class Description(val description: String, val language: NamedApiResource) +@JsNonWasmExport +public data class Description(val description: String, val language: Handle.Named) /** * The localized effect text for an API resource in a specific language. See: @@ -45,8 +45,8 @@ public data class Description(val description: String, val language: NamedApiRes * @param language The language this effect is in. */ @Serializable -@JsOnlyExport -public data class Effect(val effect: String, val language: NamedApiResource) +@JsNonWasmExport +public data class Effect(val effect: String, val language: Handle.Named) /** * Encounter details for a Pokémon in a specific location area. See: @@ -59,13 +59,13 @@ public data class Effect(val effect: String, val language: NamedApiResource) * @param method The method by which the encounter happens. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class Encounter( val minLevel: Int, val maxLevel: Int, - val conditionValues: List, + val conditionValues: List>, val chance: Int, - val method: NamedApiResource, + val method: Handle.Named, ) /** @@ -76,8 +76,8 @@ public data class Encounter( * @param language The language this flavor text is in. */ @Serializable -@JsOnlyExport -public data class FlavorText(val flavorText: String, val language: NamedApiResource) +@JsNonWasmExport +public data class FlavorText(val flavorText: String, val language: Handle.Named) /** * Generation game index for a resource. See: https://pokeapi.co/docs/v2#generationgameindex @@ -86,8 +86,8 @@ public data class FlavorText(val flavorText: String, val language: NamedApiResou * @param generation The generation relevant to this game index. */ @Serializable -@JsOnlyExport -public data class GenerationGameIndex(val gameIndex: Int, val generation: NamedApiResource) +@JsNonWasmExport +public data class GenerationGameIndex(val gameIndex: Int, val generation: Handle.Named) /** * Machine and version group details. See: https://pokeapi.co/docs/v2#machineversiondetail @@ -96,10 +96,10 @@ public data class GenerationGameIndex(val gameIndex: Int, val generation: NamedA * @param versionGroup The version group relevant to this machine. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class MachineVersionDetail( - val machine: ApiResource, - val versionGroup: NamedApiResource, + val machine: Handle.Unnamed, + val versionGroup: Handle.Named, ) /** @@ -110,8 +110,8 @@ public data class MachineVersionDetail( * @param language The language this name is in. */ @Serializable -@JsOnlyExport -public data class Name(val name: String, val language: NamedApiResource) +@JsNonWasmExport +public data class Name(val name: String, val language: Handle.Named) /** * The verbose effect text for an API resource in a specific language. See: @@ -122,11 +122,11 @@ public data class Name(val name: String, val language: NamedApiResource) * @param language The language this effect is in. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class VerboseEffect( val effect: String, val shortEffect: String, - val language: NamedApiResource, + val language: Handle.Named, ) /** @@ -138,9 +138,9 @@ public data class VerboseEffect( * @param encounterDetails A list of encounters and their specifics. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class VersionEncounterDetail( - val version: NamedApiResource, + val version: Handle.Named, val maxChance: Int, val encounterDetails: List, ) @@ -152,8 +152,8 @@ public data class VersionEncounterDetail( * @param version The version relevant to this game index. */ @Serializable -@JsOnlyExport -public data class VersionGameIndex(val gameIndex: Int, val version: NamedApiResource) +@JsNonWasmExport +public data class VersionGameIndex(val gameIndex: Int, val version: Handle.Named) /** * The localized flavor text for a version group. See: @@ -164,9 +164,9 @@ public data class VersionGameIndex(val gameIndex: Int, val version: NamedApiReso * @param versionGroup The version group which uses this flavor text. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class VersionGroupFlavorText( val text: String, - val language: NamedApiResource, - val versionGroup: NamedApiResource, + val language: Handle.Named, + val versionGroup: Handle.Named, ) diff --git a/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/BulkTest.kt b/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/BulkTest.kt index 71ec61e1..e457838b 100644 --- a/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/BulkTest.kt +++ b/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/BulkTest.kt @@ -1,7 +1,8 @@ package co.pokeapi.pokekotlin.test -import co.pokeapi.pokekotlin.model.ResourceSummary -import co.pokeapi.pokekotlin.model.ResourceSummaryList +import co.pokeapi.pokekotlin.model.Model +import co.pokeapi.pokekotlin.model.PaginatedList +import co.pokeapi.pokekotlin.model.ResourceEndpoint import kotlin.math.min import kotlin.test.Test import kotlin.test.fail @@ -12,9 +13,11 @@ private const val LAST_N = 100 private const val MIDDLE_N = 100 class BulkTest { - - private suspend fun testCase(cat: String, id: Int, getObject: suspend (Int) -> Any) { - println("$cat (id=$id)") + private suspend inline fun testCase( + id: Int, + getObject: suspend (Int) -> Any, + ) { + println("${ResourceEndpoint.forModel()} (id=$id)") try { getObject(id) } catch (e: Throwable) { @@ -23,25 +26,24 @@ class BulkTest { } } - private suspend fun testEach( - getList: suspend (Int, Int) -> ResourceSummaryList, - getObject: suspend (Int) -> O, + private suspend inline fun testEach( + getList: suspend (Int, Int) -> PaginatedList, + getObject: suspend (Int) -> Any, ) { val list = getList(0, getList(0, 0).count).results - val category = list[0].category - list.take(FIRST_N).forEach { testCase(category, it.id, getObject) } + list.take(FIRST_N).forEach { testCase(it.id, getObject) } if (list.size > FIRST_N + LAST_N) { val n = min(MIDDLE_N, list.size - FIRST_N - LAST_N) list.drop(FIRST_N).dropLast(LAST_N).shuffled().take(n).forEach { - testCase(category, it.id, getObject) + testCase(it.id, getObject) } } if (list.size > FIRST_N) { val n = min(LAST_N, list.size - FIRST_N) - list.takeLast(n).forEach { testCase(category, it.id, getObject) } + list.takeLast(n).forEach { testCase(it.id, getObject) } } } diff --git a/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/LocalPokeApi.kt b/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/LocalPokeApi.kt index 5a4d4e0a..e94ba61e 100644 --- a/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/LocalPokeApi.kt +++ b/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/LocalPokeApi.kt @@ -2,8 +2,9 @@ package co.pokeapi.pokekotlin.test import co.pokeapi.pokekotlin.PokeApi import co.pokeapi.pokekotlin.internal.PokeApiJson -import co.pokeapi.pokekotlin.model.ApiResourceList -import co.pokeapi.pokekotlin.model.NamedApiResourceList +import co.pokeapi.pokekotlin.model.Model +import co.pokeapi.pokekotlin.model.NamedModel +import co.pokeapi.pokekotlin.model.PaginatedList import io.ktor.client.plugins.api.* import io.ktor.client.statement.* import io.ktor.utils.io.* @@ -20,16 +21,18 @@ private val OffsetLimitPlugin = val endIndex = offset + limit when (requestedType.type) { - ApiResourceList::class -> { - val fullList = PokeApiJson.decodeFromSource(content.readBuffer()) + PaginatedList.Unnamed::class -> { + val fullList = + PokeApiJson.decodeFromSource>(content.readBuffer()) fullList.copy( results = fullList.results.subList(offset, min(endIndex, fullList.count)), previous = if (offset == 0) null else "TODO", next = if (endIndex < fullList.count) "TODO" else null, ) } - NamedApiResourceList::class -> { - val fullList = PokeApiJson.decodeFromSource(content.readBuffer()) + PaginatedList.Named::class -> { + val fullList = + PokeApiJson.decodeFromSource>(content.readBuffer()) fullList.copy( results = fullList.results.subList(offset, min(endIndex, fullList.count)), previous = if (offset == 0) null else "TODO", diff --git a/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/BerryTest.kt b/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/BerryTest.kt index cfadc0f8..21ad6068 100644 --- a/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/BerryTest.kt +++ b/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/BerryTest.kt @@ -1,8 +1,8 @@ package co.pokeapi.pokekotlin.test.model import co.pokeapi.pokekotlin.model.FlavorBerryMap +import co.pokeapi.pokekotlin.model.Handle import co.pokeapi.pokekotlin.model.Name -import co.pokeapi.pokekotlin.model.NamedApiResource import co.pokeapi.pokekotlin.test.LocalPokeApi import kotlin.test.Test import kotlin.test.assertContains @@ -23,10 +23,10 @@ class BerryTest { assertEquals(280, size) assertEquals(35, smoothness) assertEquals(8, soilDryness) - assertEquals(NamedApiResource("hard", "berry-firmness", 3), firmness) + assertEquals(Handle.of(3, "hard"), firmness) assertNotEquals(0, flavors.size) - assertEquals(NamedApiResource("durin-berry", "item", 159), item) - assertEquals(NamedApiResource("water", "type", 11), naturalGiftType) + assertEquals(Handle.of(159, "durin-berry"), item) + assertEquals(Handle.of(11, "water"), naturalGiftType) } } @@ -35,8 +35,8 @@ class BerryTest { LocalPokeApi.getBerryFirmness(3).apply { assertEquals(3, id) assertEquals("hard", name) - assertContains(berries, NamedApiResource("rawst", "berry", 4)) - assertContains(names, Name(name = "Hard", language = NamedApiResource("en", "language", 9))) + assertContains(berries, Handle.of(4, "rawst")) + assertContains(names, Name(name = "Hard", language = Handle.of(9, "en"))) } } @@ -45,12 +45,9 @@ class BerryTest { LocalPokeApi.getBerryFlavor(3).apply { assertEquals(3, id) assertEquals("sweet", name) - assertEquals(NamedApiResource("cute", "contest-type", 3), contestType) - assertContains( - berries, - FlavorBerryMap(potency = 10, berry = NamedApiResource("leppa", "berry", 6)), - ) - assertContains(names, Name(name = "Sweet", language = NamedApiResource("en", "language", 9))) + assertEquals(Handle.of(3, "cute"), contestType) + assertContains(berries, FlavorBerryMap(potency = 10, berry = Handle.of(6, "leppa"))) + assertContains(names, Name(name = "Sweet", language = Handle.of(9, "en"))) } } } diff --git a/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/ContestTest.kt b/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/ContestTest.kt index 2a1db843..68cd1c22 100644 --- a/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/ContestTest.kt +++ b/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/ContestTest.kt @@ -3,7 +3,7 @@ package co.pokeapi.pokekotlin.test.model import co.pokeapi.pokekotlin.model.ContestName import co.pokeapi.pokekotlin.model.Effect import co.pokeapi.pokekotlin.model.FlavorText -import co.pokeapi.pokekotlin.model.NamedApiResource +import co.pokeapi.pokekotlin.model.Handle import co.pokeapi.pokekotlin.test.LocalPokeApi import kotlin.test.Test import kotlin.test.assertContains @@ -17,14 +17,10 @@ class ContestTest { LocalPokeApi.getContestType(4).apply { assertEquals(4, id) assertEquals("smart", name) - assertEquals(NamedApiResource("bitter", "berry-flavor", 4), berryFlavor) + assertEquals(Handle.of(4, "bitter"), berryFlavor) assertContains( names, - ContestName( - name = "Smart", - color = "Green", - language = NamedApiResource("en", "language", 9), - ), + ContestName(name = "Smart", color = "Green", language = Handle.of(9, "en")), ) } } @@ -39,14 +35,14 @@ class ContestTest { effectEntries, Effect( effect = "If user appeals first this turn, earns six points instead of two.", - language = NamedApiResource("en", "language", 9), + language = Handle.of(9, "en"), ), ) assertContains( flavorTextEntries, FlavorText( flavorText = "The appeal works great if performed first.", - language = NamedApiResource("en", "language", 9), + language = Handle.of(9, "en"), ), ) } @@ -61,10 +57,10 @@ class ContestTest { flavorTextEntries, FlavorText( flavorText = "Makes the order of contestants random in the next turn.", - language = NamedApiResource("en", "language", 9), + language = Handle.of(9, "en"), ), ) - assertContains(moves, NamedApiResource("assist", "move", 274)) + assertContains(moves, Handle.of(274, "assist")) } } } diff --git a/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/EncounterTest.kt b/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/EncounterTest.kt index eca5e773..743d92e5 100644 --- a/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/EncounterTest.kt +++ b/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/EncounterTest.kt @@ -1,7 +1,7 @@ package co.pokeapi.pokekotlin.test.model +import co.pokeapi.pokekotlin.model.Handle import co.pokeapi.pokekotlin.model.Name -import co.pokeapi.pokekotlin.model.NamedApiResource import co.pokeapi.pokekotlin.test.LocalPokeApi import kotlin.test.Test import kotlin.test.assertContains @@ -16,10 +16,7 @@ class EncounterTest { assertEquals(5, id) assertEquals("surf", name) assertEquals(14, order) - assertContains( - names, - Name(name = "Surfing", language = NamedApiResource("en", "language", 9)), - ) + assertContains(names, Name(name = "Surfing", language = Handle.of(9, "en"))) } } @@ -28,8 +25,8 @@ class EncounterTest { LocalPokeApi.getEncounterCondition(5).apply { assertEquals(5, id) assertEquals("radio", name) - assertContains(values, NamedApiResource("radio-hoenn", "encounter-condition-value", 15)) - assertContains(names, Name(name = "Radio", language = NamedApiResource("en", "language", 9))) + assertContains(values, Handle.of(15, "radio-hoenn")) + assertContains(names, Name(name = "Radio", language = Handle.of(9, "en"))) } } @@ -38,11 +35,8 @@ class EncounterTest { LocalPokeApi.getEncounterConditionValue(5).apply { assertEquals(5, id) assertEquals("time-night", name) - assertEquals(NamedApiResource("time", "encounter-condition", 2), condition) - assertContains( - names, - Name(name = "At night", language = NamedApiResource("en", "language", 9)), - ) + assertEquals(Handle.of(2, "time"), condition) + assertContains(names, Name(name = "At night", language = Handle.of(9, "en"))) } } } diff --git a/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/EvolutionTest.kt b/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/EvolutionTest.kt index 65b78e82..a9a8a2f5 100644 --- a/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/EvolutionTest.kt +++ b/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/EvolutionTest.kt @@ -2,8 +2,8 @@ package co.pokeapi.pokekotlin.test.model import co.pokeapi.pokekotlin.model.ChainLink import co.pokeapi.pokekotlin.model.EvolutionDetail +import co.pokeapi.pokekotlin.model.Handle import co.pokeapi.pokekotlin.model.Name -import co.pokeapi.pokekotlin.model.NamedApiResource import co.pokeapi.pokekotlin.test.LocalPokeApi import kotlin.test.Test import kotlin.test.assertContains @@ -21,32 +21,22 @@ class EvolutionTest { assertEquals( ChainLink( isBaby = false, - species = NamedApiResource("bulbasaur", "pokemon-species", 1), + species = Handle.of(1, "bulbasaur"), evolutionDetails = emptyList(), evolvesTo = listOf( ChainLink( isBaby = false, - species = NamedApiResource("ivysaur", "pokemon-species", 2), + species = Handle.of(2, "ivysaur"), evolutionDetails = - listOf( - EvolutionDetail( - trigger = NamedApiResource("level-up", "evolution-trigger", 1), - minLevel = 16, - ) - ), + listOf(EvolutionDetail(trigger = Handle.of(1, "level-up"), minLevel = 16)), evolvesTo = listOf( ChainLink( isBaby = false, - species = NamedApiResource("venusaur", "pokemon-species", 3), + species = Handle.of(3, "venusaur"), evolutionDetails = - listOf( - EvolutionDetail( - trigger = NamedApiResource("level-up", "evolution-trigger", 1), - minLevel = 32, - ) - ), + listOf(EvolutionDetail(trigger = Handle.of(1, "level-up"), minLevel = 32)), evolvesTo = emptyList(), ) ), @@ -65,8 +55,8 @@ class EvolutionTest { chain.evolvesTo.find { it.evolutionDetails.contains( EvolutionDetail( - trigger = NamedApiResource("level-up", "evolution-trigger", 1), - heldItem = NamedApiResource("razor-claw", "item", 303), + trigger = Handle.of(1, "level-up"), + heldItem = Handle.of(303, "razor-claw"), timeOfDay = "night", ) ) @@ -81,10 +71,7 @@ class EvolutionTest { assertNotNull( chain.evolvesTo.find { it.evolutionDetails.contains( - EvolutionDetail( - trigger = NamedApiResource("use-item", "evolution-trigger", 3), - item = NamedApiResource("water-stone", "item", 84), - ) + EvolutionDetail(trigger = Handle.of(3, "use-item"), item = Handle.of(84, "water-stone")) ) } ) @@ -98,8 +85,8 @@ class EvolutionTest { chain.evolvesTo.find { it.evolutionDetails.contains( EvolutionDetail( - trigger = NamedApiResource("level-up", "evolution-trigger", 1), - location = NamedApiResource("eterna-forest", "location", 8), + trigger = Handle.of(1, "level-up"), + location = Handle.of(8, "eterna-forest"), ) ) } @@ -114,7 +101,7 @@ class EvolutionTest { chain.evolvesTo.find { it.evolutionDetails.contains( EvolutionDetail( - trigger = NamedApiResource("level-up", "evolution-trigger", 1), + trigger = Handle.of(1, "level-up"), minHappiness = 160, timeOfDay = "day", ) @@ -131,8 +118,8 @@ class EvolutionTest { chain.evolvesTo.find { it.evolutionDetails.contains( EvolutionDetail( - trigger = NamedApiResource("level-up", "evolution-trigger", 1), - knownMoveType = NamedApiResource("fairy", "type", 18), + trigger = Handle.of(1, "level-up"), + knownMoveType = Handle.of(18, "fairy"), minAffection = 2, ) ) @@ -147,8 +134,8 @@ class EvolutionTest { assertContains( chain.evolvesTo[0].evolvesTo[0].evolutionDetails, EvolutionDetail( - trigger = NamedApiResource("level-up", "evolution-trigger", 1), - knownMove = NamedApiResource("ancient-power", "move", 246), + trigger = Handle.of(1, "level-up"), + knownMove = Handle.of(246, "ancient-power"), ), ) } @@ -160,11 +147,7 @@ class EvolutionTest { assertNotNull( chain.evolvesTo.find { it.evolutionDetails.contains( - EvolutionDetail( - trigger = NamedApiResource("level-up", "evolution-trigger", 1), - gender = 1, - minLevel = 20, - ) + EvolutionDetail(trigger = Handle.of(1, "level-up"), gender = 1, minLevel = 20) ) } ) @@ -177,10 +160,7 @@ class EvolutionTest { assertNotNull( chain.evolvesTo.find { it.evolutionDetails.contains( - EvolutionDetail( - trigger = NamedApiResource("level-up", "evolution-trigger", 1), - minBeauty = 171, - ) + EvolutionDetail(trigger = Handle.of(1, "level-up"), minBeauty = 171) ) } ) @@ -194,9 +174,9 @@ class EvolutionTest { chain.evolvesTo.find { it.evolutionDetails.contains( EvolutionDetail( - trigger = NamedApiResource("level-up", "evolution-trigger", 1), + trigger = Handle.of(1, "level-up"), minLevel = 32, - partyType = NamedApiResource("dark", "type", 17), + partyType = Handle.of(17, "dark"), ) ) } @@ -211,7 +191,7 @@ class EvolutionTest { chain.evolvesTo.find { it.evolutionDetails.contains( EvolutionDetail( - trigger = NamedApiResource("level-up", "evolution-trigger", 1), + trigger = Handle.of(1, "level-up"), minLevel = 20, relativePhysicalStats = 1, ) @@ -228,7 +208,7 @@ class EvolutionTest { chain.evolvesTo[0].evolvesTo.find { it.evolutionDetails.contains( EvolutionDetail( - trigger = NamedApiResource("level-up", "evolution-trigger", 1), + trigger = Handle.of(1, "level-up"), minLevel = 50, needsOverworldRain = true, ) @@ -245,7 +225,7 @@ class EvolutionTest { chain.evolvesTo.find { it.evolutionDetails.contains( EvolutionDetail( - trigger = NamedApiResource("level-up", "evolution-trigger", 1), + trigger = Handle.of(1, "level-up"), minLevel = 30, turnUpsideDown = true, ) @@ -262,8 +242,8 @@ class EvolutionTest { chain.evolvesTo.find { it.evolutionDetails.contains( EvolutionDetail( - trigger = NamedApiResource("level-up", "evolution-trigger", 1), - partySpecies = NamedApiResource("remoraid", "pokemon-species", 223), + trigger = Handle.of(1, "level-up"), + partySpecies = Handle.of(223, "remoraid"), ) ) } @@ -278,8 +258,8 @@ class EvolutionTest { chain.evolvesTo.find { it.evolutionDetails.contains( EvolutionDetail( - trigger = NamedApiResource("trade", "evolution-trigger", 2), - tradeSpecies = NamedApiResource("karrablast", "pokemon-species", 588), + trigger = Handle.of(2, "trade"), + tradeSpecies = Handle.of(588, "karrablast"), ) ) } @@ -290,7 +270,7 @@ class EvolutionTest { @Test fun getEvolutionChain16() = runTest { LocalPokeApi.getEvolutionChain(72).apply { - assertEquals(NamedApiResource("full-incense", "item", 293), babyTriggerItem) + assertEquals(Handle.of(293, "full-incense"), babyTriggerItem) assertEquals(true, chain.isBaby) } } @@ -300,11 +280,8 @@ class EvolutionTest { LocalPokeApi.getEvolutionTrigger(1).apply { assertEquals(1, id) assertEquals("level-up", name) - assertContains( - names, - Name(name = "Level up", language = NamedApiResource("en", "language", 9)), - ) - assertContains(pokemonSpecies, NamedApiResource("fletchinder", "pokemon-species", 662)) + assertContains(names, Name(name = "Level up", language = Handle.of(9, "en"))) + assertContains(pokemonSpecies, Handle.of(662, "fletchinder")) } } } diff --git a/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/GameTest.kt b/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/GameTest.kt index 36e3e452..5e6a109c 100644 --- a/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/GameTest.kt +++ b/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/GameTest.kt @@ -1,8 +1,8 @@ package co.pokeapi.pokekotlin.test.model import co.pokeapi.pokekotlin.model.Description +import co.pokeapi.pokekotlin.model.Handle import co.pokeapi.pokekotlin.model.Name -import co.pokeapi.pokekotlin.model.NamedApiResource import co.pokeapi.pokekotlin.model.PokemonEntry import co.pokeapi.pokekotlin.test.LocalPokeApi import kotlin.test.Test @@ -17,16 +17,13 @@ class GameTest { LocalPokeApi.getGeneration(6).apply { assertEquals(6, id) assertEquals("generation-vi", name) - assertContains(abilities, NamedApiResource("primordial-sea", "ability", 189)) - assertContains( - names, - Name(name = "Generation VI", language = NamedApiResource("en", "language", 9)), - ) - assertEquals(NamedApiResource("kalos", "region", 6), mainRegion) - assertContains(moves, NamedApiResource("belch", "move", 562)) - assertContains(pokemonSpecies, NamedApiResource("froakie", "pokemon-species", 656)) - assertContains(types, NamedApiResource("fairy", "type", 18)) - assertContains(versionGroups, NamedApiResource("x-y", "version-group", 15)) + assertContains(abilities, Handle.of(189, "primordial-sea")) + assertContains(names, Name(name = "Generation VI", language = Handle.of(9, "en"))) + assertEquals(Handle.of(6, "kalos"), mainRegion) + assertContains(moves, Handle.of(562, "belch")) + assertContains(pokemonSpecies, Handle.of(656, "froakie")) + assertContains(types, Handle.of(18, "fairy")) + assertContains(versionGroups, Handle.of(15, "x-y")) } } @@ -36,23 +33,14 @@ class GameTest { assertEquals(12, id) assertEquals("kalos-central", name) assertEquals(true, isMainSeries) - assertContains( - descriptions, - Description(description = "", language = NamedApiResource("en", "language", 9)), - ) - assertContains( - names, - Name(name = "Central Kalos", language = NamedApiResource("en", "language", 9)), - ) + assertContains(descriptions, Description(description = "", language = Handle.of(9, "en"))) + assertContains(names, Name(name = "Central Kalos", language = Handle.of(9, "en"))) assertContains( pokemonEntries, - PokemonEntry( - entryNumber = 150, - pokemonSpecies = NamedApiResource("haxorus", "pokemon-species", 612), - ), + PokemonEntry(entryNumber = 150, pokemonSpecies = Handle.of(612, "haxorus")), ) - assertEquals(NamedApiResource("kalos", "region", 6), region) - assertContains(versionGroups, NamedApiResource("x-y", "version-group", 15)) + assertEquals(Handle.of(6, "kalos"), region) + assertContains(versionGroups, Handle.of(15, "x-y")) } } @@ -61,11 +49,8 @@ class GameTest { LocalPokeApi.getVersion(9).apply { assertEquals(9, id) assertEquals("emerald", name) - assertContains( - names, - Name(name = "Emerald", language = NamedApiResource("en", "language", 9)), - ) - assertEquals(NamedApiResource("emerald", "version-group", 6), versionGroup) + assertContains(names, Name(name = "Emerald", language = Handle.of(9, "en"))) + assertEquals(Handle.of(6, "emerald"), versionGroup) } } @@ -75,11 +60,11 @@ class GameTest { assertEquals(1, id) assertEquals("red-blue", name) assertEquals(3, order) - assertEquals(NamedApiResource("generation-i", "generation", 1), generation) - assertContains(moveLearnMethods, NamedApiResource("machine", "move-learn-method", 4)) - assertContains(pokedexes, NamedApiResource("kanto", "pokedex", 2)) - assertContains(regions, NamedApiResource("kanto", "region", 1)) - assertContains(versions, NamedApiResource("red", "version", 1)) + assertEquals(Handle.of(1, "generation-i"), generation) + assertContains(moveLearnMethods, Handle.of(4, "machine")) + assertContains(pokedexes, Handle.of(2, "kanto")) + assertContains(regions, Handle.of(1, "kanto")) + assertContains(versions, Handle.of(1, "red")) } } } diff --git a/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/ItemTest.kt b/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/ItemTest.kt index 3efa7dbd..33a12827 100644 --- a/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/ItemTest.kt +++ b/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/ItemTest.kt @@ -14,35 +14,29 @@ class ItemTest { assertEquals("ice-heal", name) assertEquals(200, cost) assertEquals(30, flingPower) - assertContains(attributes, NamedApiResource("holdable", "item-attribute", 5)) - assertEquals(NamedApiResource("status-cures", "item-category", 30), category) + assertContains(attributes, Handle.of(5, "holdable")) + assertEquals(Handle.of(30, "status-cures"), category) assertContains( effectEntries, VerboseEffect( effect = "Used on a party Pokémon\n: Cures freezing.", shortEffect = "Cures freezing.", - language = NamedApiResource("en", "language", 9), + language = Handle.of(9, "en"), ), ) assertContains( flavorTextEntries, VersionGroupFlavorText( text = "Defrosts a frozen\nPOKéMON.", - versionGroup = NamedApiResource("ruby-sapphire", "version-group", 5), - language = NamedApiResource("en", "language", 9), + versionGroup = Handle.of(5, "ruby-sapphire"), + language = Handle.of(9, "en"), ), ) assertContains( gameIndices, - GenerationGameIndex( - gameIndex = 20, - generation = NamedApiResource("generation-vi", "generation", 6), - ), - ) - assertContains( - names, - Name(name = "Ice Heal", language = NamedApiResource("en", "language", 9)), + GenerationGameIndex(gameIndex = 20, generation = Handle.of(6, "generation-vi")), ) + assertContains(names, Name(name = "Ice Heal", language = Handle.of(9, "en"))) assertEquals(emptyList(), heldByPokemon) assertEquals(null, flingEffect) @@ -57,12 +51,9 @@ class ItemTest { assertNotEquals( null, heldByPokemon.find { - it.pokemon == NamedApiResource("miltank", "pokemon", 241) && + it.pokemon == Handle.of(241, "miltank") && it.versionDetails.contains( - ItemHolderPokemonVersionDetail( - rarity = 100, - version = NamedApiResource("y", "version", 24), - ) + ItemHolderPokemonVersionDetail(rarity = 100, version = Handle.of(24, "y")) ) }, ) @@ -71,16 +62,12 @@ class ItemTest { @Test fun getItem3() = runTest { - LocalPokeApi.getItem(249).apply { - assertEquals(NamedApiResource("badly-poison", "item-fling-effect", 1), flingEffect) - } + LocalPokeApi.getItem(249).apply { assertEquals(Handle.of(1, "badly-poison"), flingEffect) } } @Test fun getItem4() = runTest { - LocalPokeApi.getItem(231).apply { - assertEquals(ApiResource("evolution-chain", 90), babyTriggerFor) - } + LocalPokeApi.getItem(231).apply { assertEquals(Handle.of(90), babyTriggerFor) } } @Test fun getItem5() = runTest { LocalPokeApi.getItem(967) } @@ -90,8 +77,8 @@ class ItemTest { LocalPokeApi.getItem(305).apply { assertNotNull( machines.find { machineVersionDetail -> - machineVersionDetail.machine == ApiResource("machine", 2) && - machineVersionDetail.versionGroup == NamedApiResource("red-blue", "version-group", 1) + machineVersionDetail.machine == Handle.of(2) && + machineVersionDetail.versionGroup == Handle.of(1, "red-blue") } ) } @@ -104,16 +91,10 @@ class ItemTest { assertEquals("usable-overworld", name) assertContains( descriptions, - Description( - description = "Usable outside battle", - language = NamedApiResource("en", "language", 9), - ), - ) - assertContains(items, NamedApiResource("potion", "item", 17)) - assertContains( - names, - Name(name = "Usable_overworld", language = NamedApiResource("en", "language", 9)), + Description(description = "Usable outside battle", language = Handle.of(9, "en")), ) + assertContains(items, Handle.of(17, "potion")) + assertContains(names, Name(name = "Usable_overworld", language = Handle.of(9, "en"))) } } @@ -122,12 +103,9 @@ class ItemTest { LocalPokeApi.getItemCategory(34).apply { assertEquals(34, id) assertEquals("standard-balls", name) - assertEquals(NamedApiResource("pokeballs", "item-pocket", 3), pocket) - assertContains(items, NamedApiResource("poke-ball", "item", 4)) - assertContains( - names, - Name(name = "Standard balls", language = NamedApiResource("en", "language", 9)), - ) + assertEquals(Handle.of(3, "pokeballs"), pocket) + assertContains(items, Handle.of(4, "poke-ball")) + assertContains(names, Name(name = "Standard balls", language = Handle.of(9, "en"))) } } @@ -138,12 +116,9 @@ class ItemTest { assertEquals("badly-poison", name) assertContains( effectEntries, - Effect( - effect = "Badly poisons the target.", - language = NamedApiResource("en", "language", 9), - ), + Effect(effect = "Badly poisons the target.", language = Handle.of(9, "en")), ) - assertContains(items, NamedApiResource("toxic-orb", "item", 249)) + assertContains(items, Handle.of(249, "toxic-orb")) } } @@ -152,11 +127,8 @@ class ItemTest { LocalPokeApi.getItemPocket(4).apply { assertEquals(4, id) assertEquals("machines", name) - assertContains(categories, NamedApiResource("all-machines", "item-category", 37)) - assertContains( - names, - Name(name = "TMs and HMs", language = NamedApiResource("en", "language", 9)), - ) + assertContains(categories, Handle.of(37, "all-machines")) + assertContains(names, Name(name = "TMs and HMs", language = Handle.of(9, "en"))) } } } diff --git a/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/LocationTest.kt b/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/LocationTest.kt index 1bab9a67..02e598d0 100644 --- a/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/LocationTest.kt +++ b/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/LocationTest.kt @@ -15,19 +15,13 @@ class LocationTest { LocalPokeApi.getLocation(20).apply { assertEquals(20, id) assertEquals("wayward-cave", name) - assertEquals(NamedApiResource("sinnoh", "region", 4), region) - assertContains( - names, - Name(name = "Wayward Cave", language = NamedApiResource("en", "language", 9)), - ) + assertEquals(Handle.of(4, "sinnoh"), region) + assertContains(names, Name(name = "Wayward Cave", language = Handle.of(9, "en"))) assertContains( gameIndices, - GenerationGameIndex( - gameIndex = 65, - generation = NamedApiResource("generation-iv", "generation", 4), - ), + GenerationGameIndex(gameIndex = 65, generation = Handle.of(4, "generation-iv")), ) - assertContains(areas, NamedApiResource("wayward-cave-1f", "location-area", 113)) + assertContains(areas, Handle.of(113, "wayward-cave-1f")) } } @@ -37,34 +31,29 @@ class LocationTest { assertEquals(20, id) assertEquals("mt-coronet-1f-from-exterior", name) assertEquals(20, gameIndex) - assertEquals(NamedApiResource("mt-coronet", "location", 10), location) + assertEquals(Handle.of(10, "mt-coronet"), location) assertContains( names, - Name( - name = "Mount Coronet (1F from exterior)", - language = NamedApiResource("en", "language", 9), - ), + Name(name = "Mount Coronet (1F from exterior)", language = Handle.of(9, "en")), ) assertNotNull( encounterMethodRates.find { - it.encounterMethod == NamedApiResource("walk", "encounter-method", 1) && - EncounterMethodRateVersionDetail(10, NamedApiResource("platinum", "version", 14)) in - it.versionDetails + it.encounterMethod == Handle.of(1, "walk") && + EncounterMethodRateVersionDetail(10, Handle.of(14, "platinum")) in it.versionDetails } ) assertNotNull( pokemonEncounters.find { pokemonEncounter -> - pokemonEncounter.pokemon == NamedApiResource("clefairy", "pokemon", 35) && + pokemonEncounter.pokemon == Handle.of(35, "clefairy") && pokemonEncounter.versionDetails.find { encounterDetail -> - encounterDetail.version == NamedApiResource("diamond", "version", 12) && + encounterDetail.version == Handle.of(12, "diamond") && encounterDetail.maxChance == 27 && encounterDetail.encounterDetails.find { encounter -> encounter.minLevel == 39 && encounter.maxLevel == 39 && encounter.chance == 4 && - encounter.method == NamedApiResource("walk", "encounter-method", 1) && - NamedApiResource("slot2-none", "encounter-condition-value", 8) in - encounter.conditionValues + encounter.method == Handle.of(1, "walk") && + Handle.of(8, "slot2-none") in encounter.conditionValues } != null } != null } @@ -77,13 +66,13 @@ class LocationTest { LocalPokeApi.getPalParkArea(2).apply { assertEquals(2, id) assertEquals("field", name) - assertContains(names, Name(name = "Field", language = NamedApiResource("en", "language", 9))) + assertContains(names, Name(name = "Field", language = Handle.of(9, "en"))) assertContains( pokemonEncounters, PalParkEncounterSpecies( baseScore = 100, rate = 1, - pokemonSpecies = NamedApiResource("shaymin", "pokemon-species", 492), + pokemonSpecies = Handle.of(492, "shaymin"), ), ) } @@ -94,11 +83,11 @@ class LocationTest { LocalPokeApi.getRegion(1).apply { assertEquals(1, id) assertEquals("kanto", name) - assertEquals(NamedApiResource("generation-i", "generation", 1), mainGeneration) - assertContains(locations, NamedApiResource("celadon-city", "location", 67)) - assertContains(names, Name(name = "Kanto", language = NamedApiResource("en", "language", 9))) - assertContains(pokedexes, NamedApiResource("kanto", "pokedex", 2)) - assertContains(versionGroups, NamedApiResource("red-blue", "version-group", 1)) + assertEquals(Handle.of(1, "generation-i"), mainGeneration) + assertContains(locations, Handle.of(67, "celadon-city")) + assertContains(names, Name(name = "Kanto", language = Handle.of(9, "en"))) + assertContains(pokedexes, Handle.of(2, "kanto")) + assertContains(versionGroups, Handle.of(1, "red-blue")) } } } diff --git a/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/MachineTest.kt b/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/MachineTest.kt index 36d7d6d1..4a8fa146 100644 --- a/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/MachineTest.kt +++ b/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/MachineTest.kt @@ -1,6 +1,6 @@ package co.pokeapi.pokekotlin.test.model -import co.pokeapi.pokekotlin.model.NamedApiResource +import co.pokeapi.pokekotlin.model.Handle import co.pokeapi.pokekotlin.test.LocalPokeApi import kotlin.test.Test import kotlin.test.assertEquals @@ -12,9 +12,9 @@ class MachineTest { fun getMachine() = runTest { LocalPokeApi.getMachine(18).apply { assertEquals(18, id) - assertEquals(NamedApiResource("tm01", "item", 305), item) - assertEquals(NamedApiResource("work-up", "move", 526), move) - assertEquals(NamedApiResource("sun-moon", "version-group", 17), versionGroup) + assertEquals(Handle.of(305, "tm01"), item) + assertEquals(Handle.of(526, "work-up"), move) + assertEquals(Handle.of(17, "sun-moon"), versionGroup) } } } diff --git a/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/MoveTest.kt b/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/MoveTest.kt index 1ef99989..334a862d 100644 --- a/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/MoveTest.kt +++ b/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/MoveTest.kt @@ -21,24 +21,24 @@ class MoveTest { assertEquals(0, priority) assertEquals(85, power) assertEquals(null, contestCombos) - assertEquals(NamedApiResource("tough", "contest-type", 5), contestType) - assertEquals(ApiResource("contest-effect", 4), contestEffect) - assertEquals(ApiResource("super-contest-effect", 5), superContestEffect) - assertEquals(NamedApiResource("physical", "move-damage-class", 2), damageClass) + assertEquals(Handle.of(5, "tough"), contestType) + assertEquals(Handle.of(4), contestEffect) + assertEquals(Handle.of(5), superContestEffect) + assertEquals(Handle.of(2, "physical"), damageClass) assertContains( effectEntries, VerboseEffect( effect = "Inflicts regular damage. Has a 30% chance to paralyze the target.", shortEffect = "Has a 30% chance to paralyze the target.", - language = NamedApiResource("en", "language", 9), + language = Handle.of(9, "en"), ), ) assertEquals(emptyList(), effectChanges) - assertEquals(NamedApiResource("generation-i", "generation", 1), generation) + assertEquals(Handle.of(1, "generation-i"), generation) assertEquals( MoveMetaData( - ailment = NamedApiResource("paralysis", "move-ailment", 1), - category = NamedApiResource("damage+ailment", "move-category", 4), + ailment = Handle.of(1, "paralysis"), + category = Handle.of(4, "damage+ailment"), minHits = null, maxHits = null, minTurns = null, @@ -52,27 +52,21 @@ class MoveTest { ), meta, ) - assertContains( - names, - Name(name = "Body Slam", language = NamedApiResource("en", "language", 9)), - ) + assertContains(names, Name(name = "Body Slam", language = Handle.of(9, "en"))) assertEquals(emptyList(), pastValues) assertEquals(emptyList(), statChanges) - assertEquals(NamedApiResource("selected-pokemon", "move-target", 10), target) - assertEquals(NamedApiResource("normal", "type", 1), type) + assertEquals(Handle.of(10, "selected-pokemon"), target) + assertEquals(Handle.of(1, "normal"), type) assertContains( machines, - MachineVersionDetail( - machine = ApiResource("machine", 142), - versionGroup = NamedApiResource("red-blue", "version-group", 1), - ), + MachineVersionDetail(machine = Handle.of(142), versionGroup = Handle.of(1, "red-blue")), ) assertContains( flavorTextEntries, MoveFlavorText( flavorText = "An attack that may\ncause paralysis.", - language = NamedApiResource("en", "language", 9), - versionGroup = NamedApiResource("gold-silver", "version-group", 3), + language = Handle.of(9, "en"), + versionGroup = Handle.of(3, "gold-silver"), ), ) } @@ -84,7 +78,7 @@ class MoveTest { assertEquals( ContestComboSets( normalSet = ContestComboDetail(null, null), - superSet = ContestComboDetail(null, listOf(NamedApiResource("focus-energy", "move", 116))), + superSet = ContestComboDetail(null, listOf(Handle.of(116, "focus-energy"))), ), contestCombos, ) @@ -96,10 +90,10 @@ class MoveTest { LocalPokeApi.getMove(16).apply { assertNotNull( effectChanges.find { - it.versionGroup == NamedApiResource("gold-silver", "version-group", 3) && + it.versionGroup == Handle.of(3, "gold-silver") && Effect( effect = "Does not hit Pokémon under the effects of fly.", - language = NamedApiResource("en", "language", 9), + language = Handle.of(9, "en"), ) in it.effectEntries } ) @@ -109,10 +103,7 @@ class MoveTest { @Test fun getMove4() = runTest { LocalPokeApi.getMove(14).apply { - assertContains( - statChanges, - MoveStatChange(change = 2, stat = NamedApiResource("attack", "stat", 2)), - ) + assertContains(statChanges, MoveStatChange(change = 2, stat = Handle.of(2, "attack"))) } } @@ -127,8 +118,8 @@ class MoveTest { pp = null, effectChance = null, effectEntries = emptyList(), - type = NamedApiResource("normal", "type", 1), - versionGroup = NamedApiResource("gold-silver", "version-group", 3), + type = Handle.of(1, "normal"), + versionGroup = Handle.of(3, "gold-silver"), ), ) } @@ -139,11 +130,8 @@ class MoveTest { LocalPokeApi.getMoveAilment(1).apply { assertEquals(1, id) assertEquals("paralysis", name) - assertContains( - names, - Name(name = "Paralysis", language = NamedApiResource("en", "language", 9)), - ) - assertContains(moves, NamedApiResource("stun-spore", "move", 78)) + assertContains(names, Name(name = "Paralysis", language = Handle.of(9, "en"))) + assertContains(moves, Handle.of(78, "stun-spore")) } } @@ -152,7 +140,7 @@ class MoveTest { LocalPokeApi.getMoveBattleStyle(1).apply { assertEquals(1, id) assertEquals("attack", name) - assertContains(names, Name(name = "Attack", language = NamedApiResource("en", "language", 9))) + assertContains(names, Name(name = "Attack", language = Handle.of(9, "en"))) } } @@ -165,10 +153,10 @@ class MoveTest { descriptions, Description( description = "No damage; inflicts status ailment", - language = NamedApiResource("en", "language", 9), + language = Handle.of(9, "en"), ), ) - assertContains(moves, NamedApiResource("sing", "move", 47)) + assertContains(moves, Handle.of(47, "sing")) } } @@ -177,12 +165,12 @@ class MoveTest { LocalPokeApi.getMoveDamageClass(1).apply { assertEquals(1, id) assertEquals("status", name) - assertContains(names, Name(name = "status", language = NamedApiResource("en", "language", 9))) + assertContains(names, Name(name = "status", language = Handle.of(9, "en"))) assertContains( descriptions, - Description(description = "No damage", language = NamedApiResource("en", "language", 9)), + Description(description = "No damage", language = Handle.of(9, "en")), ) - assertContains(moves, NamedApiResource("snatch", "move", 289)) + assertContains(moves, Handle.of(289, "snatch")) } } @@ -191,10 +179,7 @@ class MoveTest { LocalPokeApi.getMoveLearnMethod(10).apply { assertEquals(10, id) assertEquals("form-change", name) - assertContains( - names, - Name(name = "Form Change", language = NamedApiResource("en", "language", 9)), - ) + assertContains(names, Name(name = "Form Change", language = Handle.of(9, "en"))) assertContains( descriptions, Description( @@ -202,10 +187,10 @@ class MoveTest { "Appears when Rotom or Cosplay Pikachu changes form. " + "Disappears if the Pokémon becomes another form and this move can only " + "be learned by form change.", - language = NamedApiResource("en", "language", 9), + language = Handle.of(9, "en"), ), ) - assertContains(versionGroups, NamedApiResource("x-y", "version-group", 15)) + assertContains(versionGroups, Handle.of(15, "x-y")) } } @@ -214,18 +199,15 @@ class MoveTest { LocalPokeApi.getMoveTarget(8).apply { assertEquals(8, id) assertEquals("random-opponent", name) - assertContains( - names, - Name(name = "Random opponent", language = NamedApiResource("en", "language", 9)), - ) + assertContains(names, Name(name = "Random opponent", language = Handle.of(9, "en"))) assertContains( descriptions, Description( description = "One opposing Pokémon, selected at random.", - language = NamedApiResource("en", "language", 9), + language = Handle.of(9, "en"), ), ) - assertContains(moves, NamedApiResource("uproar", "move", 253)) + assertContains(moves, Handle.of(253, "uproar")) } } } diff --git a/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/PokemonTest.kt b/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/PokemonTest.kt index a43fec48..3f61c1f0 100644 --- a/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/PokemonTest.kt +++ b/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/PokemonTest.kt @@ -13,8 +13,8 @@ class PokemonTest { assertEquals(1, id) assertEquals("stench", name) assertEquals(true, isMainSeries) - assertEquals(NamedApiResource("generation-iii", "generation", 3), generation) - assertContains(names, Name(name = "Stench", language = NamedApiResource("en", "language", 9))) + assertEquals(Handle.of(3, "generation-iii"), generation) + assertContains(names, Name(name = "Stench", language = Handle.of(9, "en"))) assertContains( effectEntries, VerboseEffect( @@ -25,27 +25,20 @@ class PokemonTest { "Overworld: The wild encounter rate is halved while this Pokémon is " + "first in the party.", shortEffect = "Has a 10% chance of making target Pokémon flinch with each hit.", - language = NamedApiResource("en", "language", 9), + language = Handle.of(9, "en"), ), ) assertNotNull( effectChanges.find { - it.versionGroup == NamedApiResource("black-white", "version-group", 11) && + it.versionGroup == Handle.of(11, "black-white") && it.effectEntries.contains( - Effect( - effect = "Has no effect in battle.", - language = NamedApiResource("en", "language", 9), - ) + Effect(effect = "Has no effect in battle.", language = Handle.of(9, "en")) ) } ) assertContains( pokemon, - AbilityPokemon( - isHidden = true, - slot = 3, - pokemon = NamedApiResource("gloom", "pokemon", 44), - ), + AbilityPokemon(isHidden = true, slot = 3, pokemon = Handle.of(44, "gloom")), ) } } @@ -58,7 +51,7 @@ class PokemonTest { assertEquals((0..6).map { it * 5 }.toList(), possibleValues) assertContains( descriptions, - Description(description = "Loves to eat", language = NamedApiResource("en", "language", 9)), + Description(description = "Loves to eat", language = Handle.of(9, "en")), ) } } @@ -68,11 +61,8 @@ class PokemonTest { LocalPokeApi.getEggGroup(1).apply { assertEquals(1, id) assertEquals("monster", name) - assertContains( - names, - Name(name = "Monster", language = NamedApiResource("en", "language", 9)), - ) - assertContains(pokemonSpecies, NamedApiResource("avalugg", "pokemon-species", 713)) + assertContains(names, Name(name = "Monster", language = Handle.of(9, "en"))) + assertContains(pokemonSpecies, Handle.of(713, "avalugg")) } } @@ -83,12 +73,9 @@ class PokemonTest { assertEquals("female", name) assertContains( pokemonSpeciesDetails, - PokemonSpeciesGender( - rate = 4, - pokemonSpecies = NamedApiResource("noivern", "pokemon-species", 715), - ), + PokemonSpeciesGender(rate = 4, pokemonSpecies = Handle.of(715, "noivern")), ) - assertContains(requiredForEvolution, NamedApiResource("froslass", "pokemon-species", 478)) + assertContains(requiredForEvolution, Handle.of(478, "froslass")) } } @@ -98,12 +85,9 @@ class PokemonTest { assertEquals(1, id) assertEquals("slow", name) assertEquals("\\frac{5x^3}{4}", formula) - assertContains( - descriptions, - Description(description = "slow", language = NamedApiResource("en", "language", 9)), - ) + assertContains(descriptions, Description(description = "slow", language = Handle.of(9, "en"))) assertContains(levels, GrowthRateExperienceLevel(experience = 1250000, level = 100)) - assertContains(pokemonSpecies, NamedApiResource("volcanion", "pokemon-species", 721)) + assertContains(pokemonSpecies, Handle.of(721, "volcanion")) } } @@ -112,26 +96,23 @@ class PokemonTest { LocalPokeApi.getNature(10).apply { assertEquals(10, id) assertEquals("hasty", name) - assertEquals(NamedApiResource("speed", "stat", 6), increasedStat) - assertEquals(NamedApiResource("defense", "stat", 3), decreasedStat) - assertEquals(NamedApiResource("sweet", "berry-flavor", 3), likesFlavor) - assertEquals(NamedApiResource("sour", "berry-flavor", 5), hatesFlavor) + assertEquals(Handle.of(6, "speed"), increasedStat) + assertEquals(Handle.of(3, "defense"), decreasedStat) + assertEquals(Handle.of(3, "sweet"), likesFlavor) + assertEquals(Handle.of(5, "sour"), hatesFlavor) assertContains( pokeathlonStatChanges, - NatureStatChange( - pokeathlonStat = NamedApiResource("speed", "pokeathlon-stat", 1), - maxChange = 2, - ), + NatureStatChange(pokeathlonStat = Handle.of(1, "speed"), maxChange = 2), ) assertContains( moveBattleStylePreferences, MoveBattleStylePreference( highHpPreference = 58, lowHpPreference = 88, - moveBattleStyle = NamedApiResource("attack", "move-battle-style", 1), + moveBattleStyle = Handle.of(1, "attack"), ), ) - assertContains(names, Name(name = "Hasty", language = NamedApiResource("en", "language", 9))) + assertContains(names, Name(name = "Hasty", language = Handle.of(9, "en"))) } } @@ -140,17 +121,14 @@ class PokemonTest { LocalPokeApi.getPokeathlonStat(1).apply { assertEquals(1, id) assertEquals("speed", name) - assertContains(names, Name(name = "Speed", language = NamedApiResource("en", "language", 9))) + assertContains(names, Name(name = "Speed", language = Handle.of(9, "en"))) assertContains( affectingNatures.decrease, - NaturePokeathlonStatEffect(nature = NamedApiResource("sassy", "nature", 24), maxChange = -2), + NaturePokeathlonStatEffect(nature = Handle.of(24, "sassy"), maxChange = -2), ) assertContains( affectingNatures.increase, - NaturePokeathlonStatEffect( - nature = NamedApiResource("serious", "nature", 25), - maxChange = 1, - ), + NaturePokeathlonStatEffect(nature = Handle.of(25, "serious"), maxChange = 1), ) } } @@ -165,37 +143,30 @@ class PokemonTest { assertEquals(true, isDefault) assertEquals(1, order) assertEquals(69, weight) - assertEquals(NamedApiResource("bulbasaur", "pokemon-species", 1), species) + assertEquals(Handle.of(1, "bulbasaur"), species) assertContains( abilities, - PokemonAbility( - slot = 1, - isHidden = false, - ability = NamedApiResource("overgrow", "ability", 65), - ), + PokemonAbility(slot = 1, isHidden = false, ability = Handle.of(65, "overgrow")), ) - assertContains(forms, NamedApiResource("bulbasaur", "pokemon-form", 1)) + assertContains(forms, Handle.of(1, "bulbasaur")) assertContains( gameIndices, - VersionGameIndex(version = NamedApiResource("white-2", "version", 22), gameIndex = 1), + VersionGameIndex(version = Handle.of(22, "white-2"), gameIndex = 1), ) assertEquals(emptyList(), heldItems) assertNotNull( moves.find { - it.move == NamedApiResource("razor-wind", "move", 13) && + it.move == Handle.of(13, "razor-wind") && PokemonMoveVersion( levelLearnedAt = 0, - versionGroup = NamedApiResource("gold-silver", "version-group", 3), - moveLearnMethod = NamedApiResource("egg", "move-learn-method", 2), + versionGroup = Handle.of(3, "gold-silver"), + moveLearnMethod = Handle.of(2, "egg"), order = null, ) in it.versionGroupDetails } ) - assertContains( - stats, - PokemonStat(effort = 0, baseStat = 45, stat = NamedApiResource("hp", "stat", 1)), - ) - assertContains(types, PokemonType(slot = 1, type = NamedApiResource("grass", "type", 12))) + assertContains(stats, PokemonStat(effort = 0, baseStat = 45, stat = Handle.of(1, "hp"))) + assertContains(types, PokemonType(slot = 1, type = Handle.of(12, "grass"))) } } @@ -204,9 +175,8 @@ class PokemonTest { LocalPokeApi.getPokemonVariety(12).apply { assertNotNull( heldItems.find { - it.item == NamedApiResource("silver-powder", "item", 199) && - PokemonHeldItemVersion(version = NamedApiResource("ruby", "version", 7), rarity = 5) in - it.versionDetails + it.item == Handle.of(199, "silver-powder") && + PokemonHeldItemVersion(version = Handle.of(7, "ruby"), rarity = 5) in it.versionDetails } ) } @@ -218,17 +188,16 @@ class PokemonTest { assertNotNull( find { locAreaEncounter -> locAreaEncounter.locationArea == - NamedApiResource("kanto-route-2-south-towards-viridian-city", "location-area", 296) && + Handle.of(296, "kanto-route-2-south-towards-viridian-city") && locAreaEncounter.versionDetails.find { detail -> detail.maxChance == 10 - detail.version == NamedApiResource("heartgold", "version", 15) + detail.version == Handle.of(15, "heartgold") detail.encounterDetails.find { encounter -> encounter.minLevel == 8 && encounter.maxLevel == 8 && encounter.chance == 5 && - encounter.method == NamedApiResource("walk", "encounter-method", 1) && - NamedApiResource("time-morning", "encounter-condition-value", 3) in - encounter.conditionValues + encounter.method == Handle.of(1, "walk") && + Handle.of(3, "time-morning") in encounter.conditionValues } != null } != null } @@ -257,8 +226,8 @@ class PokemonTest { LocalPokeApi.getPokemonColor(1).apply { assertEquals(1, id) assertEquals("black", name) - assertContains(names, Name(name = "Black", language = NamedApiResource("en", "language", 9))) - assertContains(pokemonSpecies, NamedApiResource("snorlax", "pokemon-species", 143)) + assertContains(names, Name(name = "Black", language = Handle.of(9, "en"))) + assertContains(pokemonSpecies, Handle.of(143, "snorlax")) } } @@ -273,8 +242,8 @@ class PokemonTest { assertEquals(false, isBattleOnly) assertEquals(false, isMega) assertEquals("", formName) - assertEquals(NamedApiResource("bulbasaur", "pokemon", 1), pokemon) - assertEquals(NamedApiResource("red-blue", "version-group", 1), versionGroup) + assertEquals(Handle.of(1, "bulbasaur"), pokemon) + assertEquals(Handle.of(1, "red-blue"), versionGroup) sprites.apply { assertTrue(frontDefault!!.endsWith("/sprites/pokemon/1.png")) assertTrue(backDefault!!.endsWith("/sprites/pokemon/back/1.png")) @@ -287,10 +256,7 @@ class PokemonTest { @Test fun getPokemonForm2() = runTest { LocalPokeApi.getPokemonForm(10266).apply { - assertContains( - formNames, - Name(name = "Original Color", language = NamedApiResource("en", "language", 9)), - ) + assertContains(formNames, Name(name = "Original Color", language = Handle.of(9, "en"))) } } @@ -299,8 +265,8 @@ class PokemonTest { LocalPokeApi.getPokemonHabitat(1).apply { assertEquals(1, id) assertEquals("cave", name) - assertContains(names, Name(name = "cave", language = NamedApiResource("en", "language", 9))) - assertContains(pokemonSpecies, NamedApiResource("registeel", "pokemon-species", 379)) + assertContains(names, Name(name = "cave", language = Handle.of(9, "en"))) + assertContains(pokemonSpecies, Handle.of(379, "registeel")) } } @@ -309,12 +275,12 @@ class PokemonTest { LocalPokeApi.getPokemonShape(1).apply { assertEquals(1, id) assertEquals("ball", name) - assertContains(names, Name(name = "Ball", language = NamedApiResource("en", "language", 9))) + assertContains(names, Name(name = "Ball", language = Handle.of(9, "en"))) assertContains( awesomeNames, - AwesomeName(awesomeName = "Pomaceous", language = NamedApiResource("en", "language", 9)), + AwesomeName(awesomeName = "Pomaceous", language = Handle.of(9, "en")), ) - assertContains(pokemonSpecies, NamedApiResource("shellder", "pokemon-species", 90)) + assertContains(pokemonSpecies, Handle.of(90, "shellder")) } } @@ -333,44 +299,28 @@ class PokemonTest { assertEquals(20, hatchCounter) assertEquals(false, hasGenderDifferences) assertEquals(false, formsSwitchable) - assertEquals(NamedApiResource("medium-slow", "growth-rate", 4), growthRate) + assertEquals(Handle.of(4, "medium-slow"), growthRate) assertContains( pokedexNumbers, - PokemonSpeciesDexEntry( - entryNumber = 80, - pokedex = NamedApiResource("kalos-central", "pokedex", 12), - ), + PokemonSpeciesDexEntry(entryNumber = 80, pokedex = Handle.of(12, "kalos-central")), ) - assertContains(eggGroups, NamedApiResource("plant", "egg-group", 7)) - assertEquals(NamedApiResource("green", "pokemon-color", 5), color) - assertEquals(NamedApiResource("quadruped", "pokemon-shape", 8), shape) + assertContains(eggGroups, Handle.of(7, "plant")) + assertEquals(Handle.of(5, "green"), color) + assertEquals(Handle.of(8, "quadruped"), shape) assertEquals(null, evolvesFromSpecies) - assertEquals(ApiResource("evolution-chain", 1), evolutionChain) - assertEquals(NamedApiResource("grassland", "pokemon-habitat", 3), habitat) - assertEquals(NamedApiResource("generation-i", "generation", 1), generation) - assertContains( - names, - Name(name = "Bulbasaur", language = NamedApiResource("en", "language", 9)), - ) + assertEquals(Handle.of(1), evolutionChain) + assertEquals(Handle.of(3, "grassland"), habitat) + assertEquals(Handle.of(1, "generation-i"), generation) + assertContains(names, Name(name = "Bulbasaur", language = Handle.of(9, "en"))) assertContains( palParkEncounters, - PalParkEncounterArea( - rate = 30, - baseScore = 50, - area = NamedApiResource("field", "pal-park-area", 2), - ), + PalParkEncounterArea(rate = 30, baseScore = 50, area = Handle.of(2, "field")), ) assertEquals(emptyList(), formDescriptions) - assertContains( - genera, - Genus(genus = "Seed Pokémon", language = NamedApiResource("en", "language", 9)), - ) + assertContains(genera, Genus(genus = "Seed Pokémon", language = Handle.of(9, "en"))) assertContains( varieties, - PokemonSpeciesVariety( - isDefault = true, - variety = NamedApiResource("bulbasaur", "pokemon", 1), - ), + PokemonSpeciesVariety(isDefault = true, variety = Handle.of(1, "bulbasaur")), ) assertContains( flavorTextEntries, @@ -379,8 +329,8 @@ class PokemonTest { "Bulbasaur can be seen napping in bright sunlight.\n" + "There is a seed on its back. By soaking up the sun’s rays,\n" + "the seed grows progressively larger.", - language = NamedApiResource("en", "language", 9), - version = NamedApiResource("alpha-sapphire", "version", 26), + language = Handle.of(9, "en"), + version = Handle.of(26, "alpha-sapphire"), ), ) } @@ -389,7 +339,7 @@ class PokemonTest { @Test fun getPokemonSpecies2() = runTest { LocalPokeApi.getPokemonSpecies(2).apply { - assertEquals(NamedApiResource("bulbasaur", "pokemon-species", 1), evolvesFromSpecies) + assertEquals(Handle.of(1, "bulbasaur"), evolvesFromSpecies) } } @@ -403,7 +353,7 @@ class PokemonTest { "Form changes along with type to match the weather in battle, " + "due to forecast. Castform is always in its normal form outside of " + "battle, regardless of weather.", - language = NamedApiResource("en", "language", 9), + language = Handle.of(9, "en"), ), ) } @@ -418,16 +368,16 @@ class PokemonTest { assertEquals(false, isBattleOnly) assertContains( affectingMoves.increase, - MoveStatAffect(change = 2, move = NamedApiResource("swords-dance", "move", 14)), + MoveStatAffect(change = 2, move = Handle.of(14, "swords-dance")), ) assertContains( affectingMoves.decrease, - MoveStatAffect(change = -1, move = NamedApiResource("growl", "move", 45)), + MoveStatAffect(change = -1, move = Handle.of(45, "growl")), ) - assertContains(affectingNatures.increase, NamedApiResource("lonely", "nature", 6)) - assertContains(affectingNatures.decrease, NamedApiResource("bold", "nature", 2)) - assertEquals(NamedApiResource("physical", "move-damage-class", 2), moveDamageClass) - assertContains(names, Name(name = "Attack", language = NamedApiResource("en", "language", 9))) + assertContains(affectingNatures.increase, Handle.of(6, "lonely")) + assertContains(affectingNatures.decrease, Handle.of(2, "bold")) + assertEquals(Handle.of(2, "physical"), moveDamageClass) + assertContains(names, Name(name = "Attack", language = Handle.of(9, "en"))) } } @@ -437,27 +387,21 @@ class PokemonTest { assertEquals(8, id) assertEquals("ghost", name) damageRelations.apply { - assertContains(halfDamageFrom, NamedApiResource("poison", "type", 4)) - assertContains(noDamageFrom, NamedApiResource("normal", "type", 1)) - assertContains(halfDamageTo, NamedApiResource("dark", "type", 17)) - assertContains(doubleDamageFrom, NamedApiResource("ghost", "type", 8)) - assertContains(noDamageTo, NamedApiResource("normal", "type", 1)) - assertContains(doubleDamageTo, NamedApiResource("psychic", "type", 14)) + assertContains(halfDamageFrom, Handle.of(4, "poison")) + assertContains(noDamageFrom, Handle.of(1, "normal")) + assertContains(halfDamageTo, Handle.of(17, "dark")) + assertContains(doubleDamageFrom, Handle.of(8, "ghost")) + assertContains(noDamageTo, Handle.of(1, "normal")) + assertContains(doubleDamageTo, Handle.of(14, "psychic")) } assertContains( gameIndices, - GenerationGameIndex( - gameIndex = 7, - generation = NamedApiResource("generation-vi", "generation", 6), - ), - ) - assertEquals(NamedApiResource("physical", "move-damage-class", 2), moveDamageClass) - assertContains(names, Name(name = "Ghost", language = NamedApiResource("en", "language", 9))) - assertContains( - pokemon, - TypePokemon(slot = 1, pokemon = NamedApiResource("litwick", "pokemon", 607)), + GenerationGameIndex(gameIndex = 7, generation = Handle.of(6, "generation-vi")), ) - assertContains(moves, NamedApiResource("hex", "move", 506)) + assertEquals(Handle.of(2, "physical"), moveDamageClass) + assertContains(names, Name(name = "Ghost", language = Handle.of(9, "en"))) + assertContains(pokemon, TypePokemon(slot = 1, pokemon = Handle.of(607, "litwick"))) + assertContains(moves, Handle.of(506, "hex")) } } } diff --git a/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/ResourceListTest.kt b/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/ResourceListTest.kt index a9caa53b..d71e05cc 100644 --- a/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/ResourceListTest.kt +++ b/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/ResourceListTest.kt @@ -1,9 +1,9 @@ package co.pokeapi.pokekotlin.test.model -import co.pokeapi.pokekotlin.model.ApiResource -import co.pokeapi.pokekotlin.model.ApiResourceList -import co.pokeapi.pokekotlin.model.NamedApiResource -import co.pokeapi.pokekotlin.model.NamedApiResourceList +import co.pokeapi.pokekotlin.model.Handle +import co.pokeapi.pokekotlin.model.Model +import co.pokeapi.pokekotlin.model.NamedModel +import co.pokeapi.pokekotlin.model.PaginatedList import co.pokeapi.pokekotlin.test.LocalPokeApi import kotlin.test.* import kotlinx.coroutines.test.runTest @@ -12,11 +12,10 @@ class ResourceListTest { val pageSize = 50 - private suspend fun testCase( - category: String, + private suspend inline fun testCase( id: Int, name: String, - call: suspend () -> NamedApiResourceList, + call: suspend () -> PaginatedList.Named, ) { call().apply { assertTrue(results.size <= pageSize, "Actual count: ${results.size}, pageSize: $pageSize") @@ -30,15 +29,17 @@ class ResourceListTest { results.forEach { assertNotEquals("", it.name) - assertNotEquals("", it.category) - it.id + assertNotNull(it.id) } - assertContains(results, NamedApiResource(name, category, id)) + assertContains(results, Handle.of(id, name)) } } - private suspend fun testCase(category: String, id: Int, call: suspend () -> ApiResourceList) { + private suspend inline fun testCase( + id: Int, + call: suspend () -> PaginatedList.Unnamed, + ) { call().apply { assertTrue(results.size <= pageSize) if (pageSize >= count) { @@ -49,257 +50,236 @@ class ResourceListTest { assertNotEquals(null, next) } - results.forEach { - assertNotEquals("", it.category) - it.id - } + results.forEach { assertNotNull(it.id) } - assertContains(results, ApiResource(category, id)) + assertContains(results, Handle.of(id)) } } @Test - fun getBerryList() = runTest { - testCase("berry", 4, "rawst") { LocalPokeApi.getBerryList(0, pageSize) } - } + fun getBerryList() = runTest { testCase(4, "rawst") { LocalPokeApi.getBerryList(0, pageSize) } } @Test fun getBerryFirmnessList() = runTest { - testCase("berry-firmness", 4, "very-hard") { LocalPokeApi.getBerryFirmnessList(0, pageSize) } + testCase(4, "very-hard") { LocalPokeApi.getBerryFirmnessList(0, pageSize) } } @Test fun getBerryFlavorList() = runTest { - testCase("berry-flavor", 4, "bitter") { LocalPokeApi.getBerryFlavorList(0, pageSize) } + testCase(4, "bitter") { LocalPokeApi.getBerryFlavorList(0, pageSize) } } @Test fun getContestTypeList() = runTest { - testCase("contest-type", 4, "smart") { LocalPokeApi.getContestTypeList(0, pageSize) } + testCase(4, "smart") { LocalPokeApi.getContestTypeList(0, pageSize) } } @Test fun getContestEffectList() = runTest { - testCase("contest-effect", 4) { LocalPokeApi.getContestEffectList(0, pageSize) } + testCase(4) { LocalPokeApi.getContestEffectList(0, pageSize) } } @Test fun getSuperContestEffectList() = runTest { - testCase("super-contest-effect", 2) { LocalPokeApi.getSuperContestEffectList(0, pageSize) } + testCase(2) { LocalPokeApi.getSuperContestEffectList(0, pageSize) } } @Test fun getEncounterMethodList() = runTest { - testCase("encounter-method", 5, "surf") { LocalPokeApi.getEncounterMethodList(0, pageSize) } + testCase(5, "surf") { LocalPokeApi.getEncounterMethodList(0, pageSize) } } @Test fun getEncounterConditionList() = runTest { - testCase("encounter-condition", 3, "radar") { - LocalPokeApi.getEncounterConditionList(0, pageSize) - } + testCase(3, "radar") { LocalPokeApi.getEncounterConditionList(0, pageSize) } } @Test fun getEncounterConditionValueList() = runTest { - testCase("encounter-condition-value", 4, "time-day") { - LocalPokeApi.getEncounterConditionValueList(0, pageSize) - } + testCase(4, "time-day") { LocalPokeApi.getEncounterConditionValueList(0, pageSize) } } @Test fun getEvolutionChainList() = runTest { - testCase("evolution-chain", 5) { LocalPokeApi.getEvolutionChainList(0, pageSize) } + testCase(5) { LocalPokeApi.getEvolutionChainList(0, pageSize) } } @Test fun getEvolutionTriggerList() = runTest { - testCase("evolution-trigger", 2, "trade") { LocalPokeApi.getEvolutionTriggerList(0, pageSize) } + testCase(2, "trade") { LocalPokeApi.getEvolutionTriggerList(0, pageSize) } } @Test fun getGenerationList() = runTest { - testCase("generation", 3, "generation-iii") { LocalPokeApi.getGenerationList(0, pageSize) } + testCase(3, "generation-iii") { LocalPokeApi.getGenerationList(0, pageSize) } } @Test fun getPokedexList() = runTest { - testCase("pokedex", 2, "kanto") { LocalPokeApi.getPokedexList(0, pageSize) } + testCase(2, "kanto") { LocalPokeApi.getPokedexList(0, pageSize) } } @Test fun getVersionList() = runTest { - testCase("version", 4, "gold") { LocalPokeApi.getVersionList(0, pageSize) } + testCase(4, "gold") { LocalPokeApi.getVersionList(0, pageSize) } } @Test fun getVersionGroupList() = runTest { - testCase("version-group", 3, "gold-silver") { LocalPokeApi.getVersionGroupList(0, pageSize) } + testCase(3, "gold-silver") { LocalPokeApi.getVersionGroupList(0, pageSize) } } @Test fun getItemList() = runTest { - testCase("item", 16, "cherish-ball") { LocalPokeApi.getItemList(0, pageSize) } + testCase(16, "cherish-ball") { LocalPokeApi.getItemList(0, pageSize) } } @Test fun getItemAttributeList() = runTest { - testCase("item-attribute", 2, "consumable") { LocalPokeApi.getItemAttributeList(0, pageSize) } + testCase(2, "consumable") { LocalPokeApi.getItemAttributeList(0, pageSize) } } @Test fun getItemCategoryList() = runTest { - testCase("item-category", 2, "effort-drop") { LocalPokeApi.getItemCategoryList(0, pageSize) } + testCase(2, "effort-drop") { LocalPokeApi.getItemCategoryList(0, pageSize) } } @Test fun getItemFlingEffectList() = runTest { - testCase("item-fling-effect", 4, "herb-effect") { - LocalPokeApi.getItemFlingEffectList(0, pageSize) - } + testCase(4, "herb-effect") { LocalPokeApi.getItemFlingEffectList(0, pageSize) } } @Test fun getItemPocketList() = runTest { - testCase("item-pocket", 3, "pokeballs") { LocalPokeApi.getItemPocketList(0, pageSize) } + testCase(3, "pokeballs") { LocalPokeApi.getItemPocketList(0, pageSize) } } @Test fun getMoveList() = runTest { - testCase("move", 17, "wing-attack") { LocalPokeApi.getMoveList(0, pageSize) } + testCase(17, "wing-attack") { LocalPokeApi.getMoveList(0, pageSize) } } @Test fun getMoveAilmentList() = runTest { - testCase("move-ailment", 5, "poison") { LocalPokeApi.getMoveAilmentList(0, pageSize) } + testCase(5, "poison") { LocalPokeApi.getMoveAilmentList(0, pageSize) } } @Test fun getMoveBattleStyleList() = runTest { - testCase("move-battle-style", 2, "defense") { LocalPokeApi.getMoveBattleStyleList(0, pageSize) } + testCase(2, "defense") { LocalPokeApi.getMoveBattleStyleList(0, pageSize) } } @Test fun getMoveCategoryList() = runTest { - testCase("move-category", 11, "field-effect") { LocalPokeApi.getMoveCategoryList(0, pageSize) } + testCase(11, "field-effect") { LocalPokeApi.getMoveCategoryList(0, pageSize) } } @Test fun getMoveDamageClassList() = runTest { - testCase("move-damage-class", 2, "physical") { - LocalPokeApi.getMoveDamageClassList(0, pageSize) - } + testCase(2, "physical") { LocalPokeApi.getMoveDamageClassList(0, pageSize) } } @Test fun getMoveLearnMethodList() = runTest { - testCase("move-learn-method", 4, "machine") { LocalPokeApi.getMoveLearnMethodList(0, pageSize) } + testCase(4, "machine") { LocalPokeApi.getMoveLearnMethodList(0, pageSize) } } @Test fun getMoveTargetList() = runTest { - testCase("move-target", 14, "all-pokemon") { LocalPokeApi.getMoveTargetList(0, pageSize) } + testCase(14, "all-pokemon") { LocalPokeApi.getMoveTargetList(0, pageSize) } } @Test fun getLocationList() = runTest { - testCase("location", 31, "sinnoh-route-201") { LocalPokeApi.getLocationList(0, pageSize) } + testCase(31, "sinnoh-route-201") { LocalPokeApi.getLocationList(0, pageSize) } } @Test fun getLocationAreaList() = runTest { - testCase("location-area", 34, "solaceon-ruins-b1f-c") { - LocalPokeApi.getLocationAreaList(0, pageSize) - } + testCase(34, "solaceon-ruins-b1f-c") { LocalPokeApi.getLocationAreaList(0, pageSize) } } @Test fun getPalParkAreaList() = runTest { - testCase("pal-park-area", 3, "mountain") { LocalPokeApi.getPalParkAreaList(0, pageSize) } + testCase(3, "mountain") { LocalPokeApi.getPalParkAreaList(0, pageSize) } } @Test - fun getRegionList() = runTest { - testCase("region", 1, "kanto") { LocalPokeApi.getRegionList(0, pageSize) } - } + fun getRegionList() = runTest { testCase(1, "kanto") { LocalPokeApi.getRegionList(0, pageSize) } } @Test fun getAbilityList() = runTest { - testCase("ability", 5, "sturdy") { LocalPokeApi.getAbilityList(0, pageSize) } + testCase(5, "sturdy") { LocalPokeApi.getAbilityList(0, pageSize) } } @Test fun getCharacteristicList() = runTest { - testCase("characteristic", 4) { LocalPokeApi.getCharacteristicList(0, pageSize) } + testCase(4) { LocalPokeApi.getCharacteristicList(0, pageSize) } } @Test fun getEggGroupList() = runTest { - testCase("egg-group", 1, "monster") { LocalPokeApi.getEggGroupList(0, pageSize) } + testCase(1, "monster") { LocalPokeApi.getEggGroupList(0, pageSize) } } @Test - fun getGenderList() = runTest { - testCase("gender", 2, "male") { LocalPokeApi.getGenderList(0, pageSize) } - } + fun getGenderList() = runTest { testCase(2, "male") { LocalPokeApi.getGenderList(0, pageSize) } } @Test fun getGrowthRateList() = runTest { - testCase("growth-rate", 3, "fast") { LocalPokeApi.getGrowthRateList(0, pageSize) } + testCase(3, "fast") { LocalPokeApi.getGrowthRateList(0, pageSize) } } @Test - fun getNatureList() = runTest { - testCase("nature", 5, "timid") { LocalPokeApi.getNatureList(0, pageSize) } - } + fun getNatureList() = runTest { testCase(5, "timid") { LocalPokeApi.getNatureList(0, pageSize) } } @Test fun getPokeathlonStatList() = runTest { - testCase("pokeathlon-stat", 5, "jump") { LocalPokeApi.getPokeathlonStatList(0, pageSize) } + testCase(5, "jump") { LocalPokeApi.getPokeathlonStatList(0, pageSize) } } @Test fun getPokemonList() = runTest { - testCase("pokemon", 3, "venusaur") { LocalPokeApi.getPokemonVarietyList(0, pageSize) } + testCase(3, "venusaur") { LocalPokeApi.getPokemonVarietyList(0, pageSize) } } @Test fun getPokemonColorList() = runTest { - testCase("pokemon-color", 8, "red") { LocalPokeApi.getPokemonColorList(0, pageSize) } + testCase(8, "red") { LocalPokeApi.getPokemonColorList(0, pageSize) } } @Test fun getPokemonFormList() = runTest { - testCase("pokemon-form", 18, "pidgeot") { LocalPokeApi.getPokemonFormList(0, pageSize) } + testCase(18, "pidgeot") { LocalPokeApi.getPokemonFormList(0, pageSize) } } @Test fun getPokemonHabitatList() = runTest { - testCase("pokemon-habitat", 8, "urban") { LocalPokeApi.getPokemonHabitatList(0, pageSize) } + testCase(8, "urban") { LocalPokeApi.getPokemonHabitatList(0, pageSize) } } @Test fun getPokemonShapeList() = runTest { - testCase("pokemon-shape", 13, "bug-wings") { LocalPokeApi.getPokemonShapeList(0, pageSize) } + testCase(13, "bug-wings") { LocalPokeApi.getPokemonShapeList(0, pageSize) } } @Test fun getPokemonSpeciesList() = runTest { - testCase("pokemon-species", 20, "raticate") { LocalPokeApi.getPokemonSpeciesList(0, pageSize) } + testCase(20, "raticate") { LocalPokeApi.getPokemonSpeciesList(0, pageSize) } } @Test fun getPokemonStatList() = runTest { - testCase("stat", 6, "speed") { LocalPokeApi.getStatList(0, pageSize) } + testCase(6, "speed") { LocalPokeApi.getStatList(0, pageSize) } } @Test fun getPokemonTypeList() = runTest { - testCase("type", 18, "fairy") { LocalPokeApi.getTypeList(0, pageSize) } + testCase(18, "fairy") { LocalPokeApi.getTypeList(0, pageSize) } } @Test fun getLanguageList() = runTest { - testCase("language", 9, "en") { LocalPokeApi.getLanguageList(0, pageSize) } + testCase(9, "en") { LocalPokeApi.getLanguageList(0, pageSize) } } } diff --git a/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/UtilityTest.kt b/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/UtilityTest.kt index fa899642..faaeaa23 100644 --- a/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/UtilityTest.kt +++ b/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/UtilityTest.kt @@ -1,7 +1,7 @@ package co.pokeapi.pokekotlin.test.model +import co.pokeapi.pokekotlin.model.Handle import co.pokeapi.pokekotlin.model.Name -import co.pokeapi.pokekotlin.model.NamedApiResource import co.pokeapi.pokekotlin.test.LocalPokeApi import kotlin.test.Test import kotlin.test.assertContains @@ -17,10 +17,7 @@ class UtilityTest { assertEquals("us", iso3166) assertEquals("en", iso639) assertEquals("en", name) - assertContains( - names, - Name(name = "English", language = NamedApiResource("en", "language", 9)), - ) + assertContains(names, Name(name = "English", language = Handle.of(9, "en"))) } } } diff --git a/src/jsMain/kotlin/co/pokeapi/pokekotlin/internal/JsNonWasmExport.js.kt b/src/jsMain/kotlin/co/pokeapi/pokekotlin/internal/JsNonWasmExport.js.kt new file mode 100644 index 00000000..ccc0cce6 --- /dev/null +++ b/src/jsMain/kotlin/co/pokeapi/pokekotlin/internal/JsNonWasmExport.js.kt @@ -0,0 +1,3 @@ +package co.pokeapi.pokekotlin.internal + +internal actual typealias JsNonWasmExport = JsExport diff --git a/src/jsMain/kotlin/co/pokeapi/pokekotlin/internal/JsOnlyExport.js.kt b/src/jsMain/kotlin/co/pokeapi/pokekotlin/internal/JsOnlyExport.js.kt deleted file mode 100644 index d7be148d..00000000 --- a/src/jsMain/kotlin/co/pokeapi/pokekotlin/internal/JsOnlyExport.js.kt +++ /dev/null @@ -1,3 +0,0 @@ -package co.pokeapi.pokekotlin.internal - -internal actual typealias JsOnlyExport = JsExport diff --git a/src/nonJsMain/kotlin/co/pokeapi/pokekotlin/internal/JsNonWasmExport.nonJs.kt b/src/nonJsMain/kotlin/co/pokeapi/pokekotlin/internal/JsNonWasmExport.nonJs.kt new file mode 100644 index 00000000..60eae781 --- /dev/null +++ b/src/nonJsMain/kotlin/co/pokeapi/pokekotlin/internal/JsNonWasmExport.nonJs.kt @@ -0,0 +1,3 @@ +package co.pokeapi.pokekotlin.internal + +internal actual typealias JsNonWasmExport = NoOpExport diff --git a/src/nonJsMain/kotlin/co/pokeapi/pokekotlin/internal/JsOnlyExport.nonJs.kt b/src/nonJsMain/kotlin/co/pokeapi/pokekotlin/internal/JsOnlyExport.nonJs.kt deleted file mode 100644 index c70a1602..00000000 --- a/src/nonJsMain/kotlin/co/pokeapi/pokekotlin/internal/JsOnlyExport.nonJs.kt +++ /dev/null @@ -1,3 +0,0 @@ -package co.pokeapi.pokekotlin.internal - -internal actual typealias JsOnlyExport = NoOpExport