From 89c90f0dabcbbfda08fdc1aaeb90135e9762df58 Mon Sep 17 00:00:00 2001 From: Sargun Vohra Date: Mon, 30 Jun 2025 20:42:25 -0700 Subject: [PATCH 1/5] refactor resource handles to be generic --- build.gradle.kts | 6 +- .../demoapp/screens/PokemonListScreen.kt | 19 +- .../kotlin/co/pokeapi/pokekotlin/PokeApi.kt | 313 ++++++++++++------ .../internal/ApiResourceSerializer.kt | 11 +- .../internal/NamedApiResourceSerializer.kt | 13 +- .../co/pokeapi/pokekotlin/model/berries.kt | 20 +- .../co/pokeapi/pokekotlin/model/contests.kt | 16 +- .../co/pokeapi/pokekotlin/model/encounters.kt | 10 +- .../co/pokeapi/pokekotlin/model/evolution.kt | 28 +- .../co/pokeapi/pokekotlin/model/games.kt | 41 +-- .../co/pokeapi/pokekotlin/model/items.kt | 35 +- .../co/pokeapi/pokekotlin/model/locations.kt | 33 +- .../co/pokeapi/pokekotlin/model/machines.kt | 8 +- .../co/pokeapi/pokekotlin/model/moves.kt | 59 ++-- .../co/pokeapi/pokekotlin/model/pokemon.kt | 185 ++++++----- .../co/pokeapi/pokekotlin/model/resource.kt | 199 +++++++---- .../co/pokeapi/pokekotlin/model/utility.kt | 36 +- .../co/pokeapi/pokekotlin/test/BulkTest.kt | 26 +- .../pokeapi/pokekotlin/test/LocalPokeApi.kt | 18 +- .../pokekotlin/test/model/BerryTest.kt | 21 +- .../pokekotlin/test/model/ContestTest.kt | 18 +- .../pokekotlin/test/model/EncounterTest.kt | 18 +- .../pokekotlin/test/model/EvolutionTest.kt | 78 ++--- .../pokeapi/pokekotlin/test/model/GameTest.kt | 52 ++- .../pokeapi/pokekotlin/test/model/ItemTest.kt | 72 ++-- .../pokekotlin/test/model/LocationTest.kt | 48 ++- .../pokekotlin/test/model/MachineTest.kt | 8 +- .../pokeapi/pokekotlin/test/model/MoveTest.kt | 85 ++--- .../pokekotlin/test/model/PokemonTest.kt | 208 +++++------- .../pokekotlin/test/model/ResourceListTest.kt | 143 ++++---- .../pokekotlin/test/model/UtilityTest.kt | 7 +- 31 files changed, 942 insertions(+), 892 deletions(-) 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..182ac0e6 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,8 +21,8 @@ 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.PokemonVariety +import co.pokeapi.pokekotlin.model.ResourceHandle import coil3.compose.AsyncImage import kotlinx.coroutines.launch import kotlinx.coroutines.withContext @@ -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: ResourceHandle) { 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: ResourceHandle.Named, +) { LaunchedEffect(item) { viewModel.loadPokemonDetails(item) } Card(modifier = Modifier.padding(8.dp).fillMaxWidth()) { @@ -140,7 +143,7 @@ private fun PokemonListItem(viewModel: PokemonListScreenViewModel, item: NamedAp // Placeholder for name Text( - text = item.name.replaceFirstChar { it.uppercase() }, + text = item.slug.replaceFirstChar { it.uppercase() }, style = MaterialTheme.typography.titleMedium, modifier = Modifier.padding(top = 8.dp), ) @@ -158,7 +161,7 @@ private fun PokemonListItem(viewModel: PokemonListScreenViewModel, item: NamedAp is LoadingStatus.Error -> { Column(modifier = Modifier.padding(16.dp)) { Text( - text = item.name.replaceFirstChar { it.uppercase() }, + text = item.slug.replaceFirstChar { it.uppercase() }, style = MaterialTheme.typography.titleMedium, ) Text( @@ -206,7 +209,7 @@ private fun PokemonListItem(viewModel: PokemonListScreenViewModel, item: NamedAp ) { pokemon.types .sortedBy { it.slot } - .forEach { pokemonType -> PokemonTypeBadge(pokemonType.type.name) } + .forEach { pokemonType -> PokemonTypeBadge(pokemonType.type.slug) } } } } diff --git a/src/commonMain/kotlin/co/pokeapi/pokekotlin/PokeApi.kt b/src/commonMain/kotlin/co/pokeapi/pokekotlin/PokeApi.kt index 7fddc0ee..a8c412d3 100644 --- a/src/commonMain/kotlin/co/pokeapi/pokekotlin/PokeApi.kt +++ b/src/commonMain/kotlin/co/pokeapi/pokekotlin/PokeApi.kt @@ -4,6 +4,7 @@ import co.pokeapi.pokekotlin.internal.JsOnlyExport 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,19 +23,6 @@ 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 public sealed class PokeApi @JsExport.Ignore @@ -73,6 +62,37 @@ constructor( configure = {}, ) + private suspend inline fun HttpClient.getNamedResourceList( + offset: Int, + limit: Int, + ): PaginatedResourceList.Named { + return get("/api/v2/${ResourceEndpoint.forModel()}") { + parameter("offset", offset) + parameter("limit", limit) + } + .body() + } + + private suspend inline fun HttpClient.getResourceList( + offset: Int, + limit: Int, + ): PaginatedResourceList.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 ResourceHandle.get(): T = + client.get(url).body(TypeInfo(model)) + // region Resource Lists // region Berries @@ -81,22 +101,26 @@ 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): PaginatedResourceList.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, + ): PaginatedResourceList.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, + ): PaginatedResourceList.Named = client.getNamedResourceList(offset, limit) // endregion Berries @@ -106,22 +130,28 @@ 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, + ): PaginatedResourceList.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, + ): PaginatedResourceList.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, + ): PaginatedResourceList.Unnamed = client.getResourceList(offset, limit) // endregion Contests @@ -131,22 +161,29 @@ 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, + ): PaginatedResourceList.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, + ): PaginatedResourceList.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, + ): PaginatedResourceList.Named = + client.getNamedResourceList(offset, limit) // endregion @@ -156,15 +193,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, + ): PaginatedResourceList.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, + ): PaginatedResourceList.Named = client.getNamedResourceList(offset, limit) // endregion @@ -174,29 +215,33 @@ 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, + ): PaginatedResourceList.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): PaginatedResourceList.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): PaginatedResourceList.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, + ): PaginatedResourceList.Named = client.getNamedResourceList(offset, limit) // endregion @@ -206,36 +251,44 @@ 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): PaginatedResourceList.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, + ): PaginatedResourceList.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, + ): PaginatedResourceList.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, + ): PaginatedResourceList.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, + ): PaginatedResourceList.Named = client.getNamedResourceList(offset, limit) // endregion @@ -245,50 +298,62 @@ 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): PaginatedResourceList.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, + ): PaginatedResourceList.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, + ): PaginatedResourceList.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, + ): PaginatedResourceList.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, + ): PaginatedResourceList.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, + ): PaginatedResourceList.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, + ): PaginatedResourceList.Named = client.getNamedResourceList(offset, limit) // endregion @@ -298,29 +363,35 @@ 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, + ): PaginatedResourceList.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, + ): PaginatedResourceList.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, + ): PaginatedResourceList.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): PaginatedResourceList.Named = + client.getNamedResourceList(offset, limit) // endregion @@ -330,8 +401,10 @@ 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, + ): PaginatedResourceList.Unnamed = client.getResourceList(offset, limit) // endregion @@ -341,106 +414,126 @@ 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): PaginatedResourceList.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, + ): PaginatedResourceList.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, + ): PaginatedResourceList.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): PaginatedResourceList.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, + ): PaginatedResourceList.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): PaginatedResourceList.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, + ): PaginatedResourceList.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, + ): PaginatedResourceList.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, + ): PaginatedResourceList.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, + ): PaginatedResourceList.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, + ): PaginatedResourceList.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, + ): PaginatedResourceList.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, + ): PaginatedResourceList.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): PaginatedResourceList.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): PaginatedResourceList.Named = + client.getNamedResourceList(offset, limit) // endregion @@ -450,8 +543,10 @@ 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, + ): PaginatedResourceList.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..ad611243 100644 --- a/src/commonMain/kotlin/co/pokeapi/pokekotlin/internal/ApiResourceSerializer.kt +++ b/src/commonMain/kotlin/co/pokeapi/pokekotlin/internal/ApiResourceSerializer.kt @@ -1,14 +1,15 @@ package co.pokeapi.pokekotlin.internal -import co.pokeapi.pokekotlin.model.ApiResource +import co.pokeapi.pokekotlin.model.EndpointModel +import co.pokeapi.pokekotlin.model.ResourceHandle import kotlinx.serialization.KSerializer import kotlinx.serialization.Serializable -internal class ApiResourceSerializer : - KSerializer by DelegatingSerializer( - serialName = "co.pokeapi.pokekotlin.model.ApiResource", +internal class ApiResourceSerializer : + KSerializer> by DelegatingSerializer( + serialName = "co.pokeapi.pokekotlin.model.ResourceHandle.Unnamed", delegate = Delegate.serializer(), - fromDelegate = { ApiResource(url = it.url) }, + fromDelegate = { ResourceHandle.Unnamed(url = it.url) }, toDelegate = { Delegate(url = it.url) }, ) { @Serializable internal data class Delegate(val url: String) diff --git a/src/commonMain/kotlin/co/pokeapi/pokekotlin/internal/NamedApiResourceSerializer.kt b/src/commonMain/kotlin/co/pokeapi/pokekotlin/internal/NamedApiResourceSerializer.kt index d8918cbb..92763dca 100644 --- a/src/commonMain/kotlin/co/pokeapi/pokekotlin/internal/NamedApiResourceSerializer.kt +++ b/src/commonMain/kotlin/co/pokeapi/pokekotlin/internal/NamedApiResourceSerializer.kt @@ -1,15 +1,16 @@ package co.pokeapi.pokekotlin.internal -import co.pokeapi.pokekotlin.model.NamedApiResource +import co.pokeapi.pokekotlin.model.EndpointModel +import co.pokeapi.pokekotlin.model.ResourceHandle import kotlinx.serialization.KSerializer import kotlinx.serialization.Serializable -internal class NamedApiResourceSerializer : - KSerializer by DelegatingSerializer( - serialName = "co.pokeapi.pokekotlin.model.NamedApiResource", +internal class NamedApiResourceSerializer : + KSerializer> by DelegatingSerializer( + serialName = "co.pokeapi.pokekotlin.model.ResourceHandle.Named", delegate = Delegate.serializer(), - fromDelegate = { NamedApiResource(name = it.name, url = it.url) }, - toDelegate = { Delegate(name = it.name, url = it.url) }, + fromDelegate = { ResourceHandle.Named(slug = it.name, url = it.url) }, + toDelegate = { Delegate(name = it.slug, url = it.url) }, ) { @Serializable internal data class Delegate(val name: String, val url: 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..4621703c 100644 --- a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/berries.kt +++ b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/berries.kt @@ -35,11 +35,11 @@ public data class Berry( val size: Int, val smoothness: Int, val soilDryness: Int, - val firmness: NamedApiResource, + val firmness: ResourceHandle.Named, val flavors: List, - val item: NamedApiResource, - val naturalGiftType: NamedApiResource, -) + val item: ResourceHandle.Named, + val naturalGiftType: ResourceHandle.Named, +) : EndpointModel /** * A flavor-to-potency mapping for a berry. See: https://pokeapi.co/docs/v2#berryflavormap @@ -49,7 +49,7 @@ public data class Berry( */ @Serializable @JsOnlyExport -public data class BerryFlavorMap(val potency: Int, val flavor: NamedApiResource) +public data class BerryFlavorMap(val potency: Int, val flavor: ResourceHandle.Named) /** * The firmness of berries, used in making Pokéblocks or Poffins. See: @@ -65,9 +65,9 @@ public data class BerryFlavorMap(val potency: Int, val flavor: NamedApiResource) public data class BerryFirmness( val id: Int, val name: String, - val berries: List, + val berries: List>, val names: List, -) +) : EndpointModel /** * Flavors determine whether a Pokémon will benefit or suffer from eating a berry based on their @@ -85,9 +85,9 @@ public data class BerryFlavor( val id: Int, val name: String, val berries: List, - val contestType: NamedApiResource, + val contestType: ResourceHandle.Named, val names: List, -) +) : EndpointModel /** * A berry-to-potency mapping for a flavor. See: https://pokeapi.co/docs/v2#flavorberrymap @@ -97,4 +97,4 @@ public data class BerryFlavor( */ @Serializable @JsOnlyExport -public data class FlavorBerryMap(val potency: Int, val berry: NamedApiResource) +public data class FlavorBerryMap(val potency: Int, val berry: ResourceHandle.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..1f1c4ee7 100644 --- a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/contests.kt +++ b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/contests.kt @@ -17,9 +17,9 @@ import kotlinx.serialization.Serializable public data class ContestType( val id: Int, val name: String, - val berryFlavor: NamedApiResource, + val berryFlavor: ResourceHandle.Named, val names: List, -) +) : EndpointModel /** * The name of a contest type listed in different languages and colors. See: @@ -31,7 +31,11 @@ public data class ContestType( */ @Serializable @JsOnlyExport -public data class ContestName(val name: String, val color: String, val language: NamedApiResource) +public data class ContestName( + val name: String, + val color: String, + val language: ResourceHandle.Named, +) /** * Contest effects refer to the effects of moves when used in contests. See: @@ -51,7 +55,7 @@ public data class ContestEffect( val jam: Int, val effectEntries: List, val flavorTextEntries: List, -) +) : EndpointModel /** * Super contest effects refer to the effects of moves when used in super contests. See: @@ -69,5 +73,5 @@ public data class SuperContestEffect( val id: Int, val appeal: Int, val flavorTextEntries: List, - val moves: List, -) + val moves: List>, +) : EndpointModel diff --git a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/encounters.kt b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/encounters.kt index 89df7908..bfae6b06 100644 --- a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/encounters.kt +++ b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/encounters.kt @@ -19,7 +19,7 @@ public data class EncounterMethod( val name: String, val order: Int, val names: List, -) +) : EndpointModel /** * Conditions which affect what pokemon might appear in the wild, e.g., day or night. See: @@ -36,8 +36,8 @@ public data class EncounterCondition( val id: Int, val name: String, val names: List, - val values: List, -) + val values: List>, +) : EndpointModel /** * Encounter condition values are the various states that an encounter condition can have, i.e., @@ -54,6 +54,6 @@ public data class EncounterCondition( public data class EncounterConditionValue( val id: Int, val name: String, - val condition: NamedApiResource, + val condition: ResourceHandle.Named, val names: List, -) +) : EndpointModel diff --git a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/evolution.kt b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/evolution.kt index ed2ad43f..da0ed08f 100644 --- a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/evolution.kt +++ b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/evolution.kt @@ -18,9 +18,9 @@ import kotlinx.serialization.Serializable @JsOnlyExport public data class EvolutionChain( val id: Int, - val babyTriggerItem: NamedApiResource?, + val babyTriggerItem: ResourceHandle.Named?, val chain: ChainLink, -) +) : EndpointModel /** * A single link within an evolution chain. Each link represents a Pokémon species and the @@ -36,7 +36,7 @@ public data class EvolutionChain( @JsOnlyExport public data class ChainLink( val isBaby: Boolean, - val species: NamedApiResource, + val species: ResourceHandle.Named, val evolutionDetails: List, val evolvesTo: List, ) @@ -71,22 +71,22 @@ public data class ChainLink( @Serializable @JsOnlyExport public data class EvolutionDetail( - val trigger: NamedApiResource, - val item: NamedApiResource? = null, + val trigger: ResourceHandle.Named, + val item: ResourceHandle.Named? = null, val gender: Int? = null, - val heldItem: NamedApiResource? = null, - val knownMove: NamedApiResource? = null, - val knownMoveType: NamedApiResource? = null, - val location: NamedApiResource? = null, + val heldItem: ResourceHandle.Named? = null, + val knownMove: ResourceHandle.Named? = null, + val knownMoveType: ResourceHandle.Named? = null, + val location: ResourceHandle.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: ResourceHandle.Named? = null, + val partyType: ResourceHandle.Named? = null, val relativePhysicalStats: Int? = null, val timeOfDay: String = "", - val tradeSpecies: NamedApiResource? = null, + val tradeSpecies: ResourceHandle.Named? = null, val needsOverworldRain: Boolean = false, val turnUpsideDown: Boolean = false, ) @@ -106,5 +106,5 @@ public data class EvolutionTrigger( val id: Int, val name: String, val names: List, - val pokemonSpecies: List, -) + val pokemonSpecies: List>, +) : EndpointModel diff --git a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/games.kt b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/games.kt index ef323995..67171805 100644 --- a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/games.kt +++ b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/games.kt @@ -23,14 +23,14 @@ import kotlinx.serialization.Serializable public data class Generation( val id: Int, val name: String, - val abilities: List, + val abilities: List>, val names: List, - val mainRegion: NamedApiResource, - val moves: List, - val pokemonSpecies: List, - val types: List, - val versionGroups: List, -) + val mainRegion: ResourceHandle.Named, + val moves: List>, + val pokemonSpecies: List>, + val types: List>, + val versionGroups: List>, +) : EndpointModel /** * A Pokédex is a handheld electronic encyclopedia device; one which is capable of recording and @@ -56,9 +56,9 @@ public data class Pokedex( val descriptions: List, val names: List, val pokemonEntries: List, - val region: NamedApiResource?, - val versionGroups: List, -) + val region: ResourceHandle.Named?, + val versionGroups: List>, +) : EndpointModel /** * A Pokémon species entry within a Pokédex. See: https://pokeapi.co/docs/v2#pokemonentry @@ -68,7 +68,10 @@ public data class Pokedex( */ @Serializable @JsOnlyExport -public data class PokemonEntry(val entryNumber: Int, val pokemonSpecies: NamedApiResource) +public data class PokemonEntry( + val entryNumber: Int, + val pokemonSpecies: ResourceHandle.Named, +) /** * Versions of the games, e.g Red, Blue or Yellow. See: https://pokeapi.co/docs/v2#versions @@ -84,8 +87,8 @@ public data class Version( val id: Int, val name: String, val names: List, - val versionGroup: NamedApiResource, -) + val versionGroup: ResourceHandle.Named, +) : EndpointModel /** * Version groups categorize highly similar versions of the games. See: @@ -107,9 +110,9 @@ public data class VersionGroup( val id: Int, val name: String, val order: Int, - val generation: NamedApiResource, - val moveLearnMethods: List, - val pokedexes: List, - val regions: List, - val versions: List, -) + val generation: ResourceHandle.Named, + val moveLearnMethods: List>, + val pokedexes: List>, + val regions: List>, + val versions: List>, +) : EndpointModel diff --git a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/items.kt b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/items.kt index fa5ac040..5dc2387c 100644 --- a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/items.kt +++ b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/items.kt @@ -31,18 +31,18 @@ public data class Item( val name: String, val cost: Int, val flingPower: Int?, - val flingEffect: NamedApiResource?, - val attributes: List, - val category: NamedApiResource, + val flingEffect: ResourceHandle.Named?, + val attributes: List>, + val category: ResourceHandle.Named, val effectEntries: List, val flavorTextEntries: List, val gameIndices: List, val names: List, val heldByPokemon: List, - val babyTriggerFor: ApiResource?, + val babyTriggerFor: ResourceHandle.Unnamed?, val sprites: ItemSprites, val machines: List, -) +) : EndpointModel /** * The sprites used to depict an item in the game. See: https://pokeapi.co/docs/v2#itemsprites @@ -61,7 +61,7 @@ public data class Item( @Serializable @JsOnlyExport public data class ItemHolderPokemon( - val pokemon: NamedApiResource, + val pokemon: ResourceHandle.Named, val versionDetails: List, ) @@ -74,7 +74,10 @@ public data class ItemHolderPokemon( */ @Serializable @JsOnlyExport -public data class ItemHolderPokemonVersionDetail(val rarity: Int, val version: NamedApiResource) +public data class ItemHolderPokemonVersionDetail( + val rarity: Int, + val version: ResourceHandle.Named, +) /** * Natural attributes of items, such as being countable or being usable in battle. See: @@ -91,10 +94,10 @@ public data class ItemHolderPokemonVersionDetail(val rarity: Int, val version: N public data class ItemAttribute( val id: Int, val name: String, - val items: List, + val items: List>, val names: List, val descriptions: List, -) +) : EndpointModel /** * Item categories determine where items will be placed in the players bag. See: @@ -111,10 +114,10 @@ public data class ItemAttribute( public data class ItemCategory( val id: Int, val name: String, - val items: List, + val items: List>, val names: List, - val pocket: NamedApiResource, -) + val pocket: ResourceHandle.Named, +) : EndpointModel /** * The various effects of the move "Fling" when used with different items. See: @@ -131,8 +134,8 @@ public data class ItemFlingEffect( val id: Int, val name: String, val effectEntries: List, - val items: List, -) + val items: List>, +) : EndpointModel /** * Pockets within the players bag used for storing items by category. See: @@ -148,6 +151,6 @@ public data class ItemFlingEffect( public data class ItemPocket( val id: Int, val name: String, - val categories: List, + val categories: List>, val names: List, -) +) : EndpointModel diff --git a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/locations.kt b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/locations.kt index b773fb61..d1511418 100644 --- a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/locations.kt +++ b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/locations.kt @@ -19,11 +19,11 @@ import kotlinx.serialization.Serializable public data class Location( val id: Int, val name: String, - val region: NamedApiResource?, + val region: ResourceHandle.Named?, val names: List, val gameIndices: List, - val areas: List, -) + val areas: List>, +) : EndpointModel /** * Location areas are sections of locations, such as floors in a building or cave. Each area has its @@ -46,10 +46,10 @@ public data class LocationArea( val name: String, val gameIndex: Int, val encounterMethodRates: List, - val location: NamedApiResource, + val location: ResourceHandle.Named, val names: List, val pokemonEncounters: List, -) +) : EndpointModel /** * The encounter rate for a specific encounter method in a location area. See: @@ -61,7 +61,7 @@ public data class LocationArea( @Serializable @JsOnlyExport public data class EncounterMethodRate( - val encounterMethod: NamedApiResource, + val encounterMethod: ResourceHandle.Named, val versionDetails: List, ) @@ -74,7 +74,10 @@ public data class EncounterMethodRate( */ @Serializable @JsOnlyExport -public data class EncounterMethodRateVersionDetail(val rate: Int, val version: NamedApiResource) +public data class EncounterMethodRateVersionDetail( + val rate: Int, + val version: ResourceHandle.Named, +) /** * A Pokémon encounter in a specific location area. See: https://pokeapi.co/docs/v2#pokemonencounter @@ -86,7 +89,7 @@ public data class EncounterMethodRateVersionDetail(val rate: Int, val version: N @Serializable @JsOnlyExport public data class PokemonEncounter( - val pokemon: NamedApiResource, + val pokemon: ResourceHandle.Named, val versionDetails: List, ) @@ -106,7 +109,7 @@ public data class PalParkArea( val name: String, val names: List, val pokemonEncounters: List, -) +) : EndpointModel /** * A Pokémon species that can be encountered in a specific Pal Park area. See: @@ -121,7 +124,7 @@ public data class PalParkArea( public data class PalParkEncounterSpecies( val baseScore: Int, val rate: Int, - val pokemonSpecies: NamedApiResource, + val pokemonSpecies: ResourceHandle.Named, ) /** @@ -142,9 +145,9 @@ public data class PalParkEncounterSpecies( public data class Region( val id: Int, val name: String, - val locations: List, - val mainGeneration: NamedApiResource?, + val locations: List>, + val mainGeneration: ResourceHandle.Named?, val names: List, - val pokedexes: List, - val versionGroups: List, -) + val pokedexes: List>, + val versionGroups: List>, +) : EndpointModel diff --git a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/machines.kt b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/machines.kt index c4564e8a..9b1e3cfc 100644 --- a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/machines.kt +++ b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/machines.kt @@ -17,7 +17,7 @@ import kotlinx.serialization.Serializable @JsOnlyExport public data class Machine( val id: Int, - val item: NamedApiResource, - val move: NamedApiResource, - val versionGroup: NamedApiResource, -) + val item: ResourceHandle.Named, + val move: ResourceHandle.Named, + val versionGroup: ResourceHandle.Named, +) : EndpointModel diff --git a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/moves.kt b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/moves.kt index deb0d937..303fc45f 100644 --- a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/moves.kt +++ b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/moves.kt @@ -48,23 +48,23 @@ public data class Move( val priority: Int, val power: Int?, val contestCombos: ContestComboSets?, - val contestType: NamedApiResource?, - val contestEffect: ApiResource?, - val superContestEffect: ApiResource?, - val damageClass: NamedApiResource, + val contestType: ResourceHandle.Named?, + val contestEffect: ResourceHandle.Unnamed?, + val superContestEffect: ResourceHandle.Unnamed?, + val damageClass: ResourceHandle.Named, val effectEntries: List, val effectChanges: List, - val generation: NamedApiResource, - val learnedByPokemon: List, + val generation: ResourceHandle.Named, + val learnedByPokemon: List>, val meta: MoveMetaData?, val names: List, val pastValues: List, val statChanges: List, - val target: NamedApiResource, - val type: NamedApiResource, + val target: ResourceHandle.Named, + val type: ResourceHandle.Named, val machines: List, val flavorTextEntries: List, -) +) : EndpointModel /** * Information about normal and super contest combos for moves. See: @@ -90,8 +90,8 @@ public data class ContestComboSets( @Serializable @JsOnlyExport public data class ContestComboDetail( - val useBefore: List?, - val useAfter: List?, + val useBefore: List>?, + val useAfter: List>?, ) /** @@ -115,8 +115,8 @@ public data class ContestComboDetail( @Serializable @JsOnlyExport public data class MoveMetaData( - val ailment: NamedApiResource, - val category: NamedApiResource, + val ailment: ResourceHandle.Named, + val category: ResourceHandle.Named, val minHits: Int?, val maxHits: Int?, val minTurns: Int?, @@ -137,7 +137,7 @@ public data class MoveMetaData( */ @Serializable @JsOnlyExport -public data class MoveStatChange(val change: Int, val stat: NamedApiResource) +public data class MoveStatChange(val change: Int, val stat: ResourceHandle.Named) /** * The stat values of a move in previous versions of the games. See: @@ -159,8 +159,8 @@ public data class PastMoveStatValues( val power: Int?, val pp: Int?, val effectEntries: List, - val type: NamedApiResource?, - val versionGroup: NamedApiResource, + val type: ResourceHandle.Named?, + val versionGroup: ResourceHandle.Named, ) /** @@ -177,9 +177,9 @@ public data class PastMoveStatValues( public data class MoveAilment( val id: Int, val name: String, - val moves: List, + val moves: List>, val names: List, -) +) : EndpointModel /** * Styles of moves when used in the Battle Palace. See the bulbapedia article for greater detail. @@ -191,7 +191,8 @@ public data class MoveAilment( */ @Serializable @JsOnlyExport -public data class MoveBattleStyle(val id: Int, val name: String, val names: List) +public data class MoveBattleStyle(val id: Int, val name: String, val names: List) : + EndpointModel /** * Very general categories that loosely group move effects. See: @@ -207,9 +208,9 @@ public data class MoveBattleStyle(val id: Int, val name: String, val names: List public data class MoveCategory( val id: Int, val name: String, - val moves: List, + val moves: List>, val descriptions: List, -) +) : EndpointModel /** * Damage classes moves can have, e.g. physical, special, or non-damaging. See: @@ -227,9 +228,9 @@ public data class MoveDamageClass( val id: Int, val name: String, val descriptions: List, - val moves: List, + val moves: List>, val names: List, -) +) : EndpointModel /** * Methods by which Pokémon can learn moves. See: https://pokeapi.co/docs/v2#move-learn-methods @@ -247,8 +248,8 @@ public data class MoveLearnMethod( val name: String, val descriptions: List, val names: List, - val versionGroups: List, -) + val versionGroups: List>, +) : EndpointModel /** * Information about different types of targets that moves can be directed at during battle. Targets @@ -266,9 +267,9 @@ public data class MoveTarget( val id: Int, val name: String, val descriptions: List, - val moves: List, + val moves: List>, val names: List, -) +) : EndpointModel /** * The flavor text of a move listed in different languages and version groups. See: @@ -282,6 +283,6 @@ public data class MoveTarget( @JsOnlyExport public data class MoveFlavorText( val flavorText: String, - val language: NamedApiResource, - val versionGroup: NamedApiResource, + val language: ResourceHandle.Named, + val versionGroup: ResourceHandle.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..3f1d4d68 100644 --- a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/pokemon.kt +++ b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/pokemon.kt @@ -25,13 +25,13 @@ public data class Ability( val id: Int, val name: String, val isMainSeries: Boolean, - val generation: NamedApiResource, + val generation: ResourceHandle.Named, val names: List, val effectEntries: List, val effectChanges: List, val flavorTextEntries: List, val pokemon: List, -) +) : EndpointModel /** * The effect of an ability listed in different version groups and languages. See: @@ -44,7 +44,7 @@ public data class Ability( @JsOnlyExport public data class AbilityEffectChange( val effectEntries: List, - val versionGroup: NamedApiResource, + val versionGroup: ResourceHandle.Named, ) /** @@ -59,8 +59,8 @@ public data class AbilityEffectChange( @JsOnlyExport public data class AbilityFlavorText( val flavorText: String, - val language: NamedApiResource, - val versionGroup: NamedApiResource, + val language: ResourceHandle.Named, + val versionGroup: ResourceHandle.Named, ) /** @@ -75,7 +75,7 @@ public data class AbilityFlavorText( public data class AbilityPokemon( val isHidden: Boolean, val slot: Int, - val pokemon: NamedApiResource, + val pokemon: ResourceHandle.Named, ) /** @@ -94,7 +94,7 @@ public data class Characteristic( val geneModulo: Int, val possibleValues: List, val descriptions: List, -) +) : EndpointModel /** * Egg Groups are categories which determine which Pokémon are able to interbreed. See: @@ -111,8 +111,8 @@ public data class EggGroup( val id: Int, val name: String, val names: List, - val pokemonSpecies: List, -) + val pokemonSpecies: List>, +) : EndpointModel /** * Genders affect whether a Pokémon can breed and what moves it can learn. See: @@ -131,8 +131,8 @@ public data class Gender( val id: Int, val name: String, val pokemonSpeciesDetails: List, - val requiredForEvolution: List, -) + val requiredForEvolution: List>, +) : EndpointModel /** * Pokémon species gender details. See: https://pokeapi.co/docs/v2#pokemonspeciesgender @@ -142,7 +142,10 @@ public data class Gender( */ @Serializable @JsOnlyExport -public data class PokemonSpeciesGender(val rate: Int, val pokemonSpecies: NamedApiResource) +public data class PokemonSpeciesGender( + val rate: Int, + val pokemonSpecies: ResourceHandle.Named, +) /** * Growth rates determine how much experience Pokémon need to level up. See: @@ -163,8 +166,8 @@ public data class GrowthRate( val formula: String, val descriptions: List, val levels: List, - val pokemonSpecies: List, -) + val pokemonSpecies: List>, +) : EndpointModel /** * Experience required for a Pokémon to reach a certain level for a given growth rate. See: @@ -196,14 +199,14 @@ public data class GrowthRateExperienceLevel(val level: Int, val experience: Int) public data class Nature( val id: Int, val name: String, - val decreasedStat: NamedApiResource?, - val increasedStat: NamedApiResource?, - val hatesFlavor: NamedApiResource?, - val likesFlavor: NamedApiResource?, + val decreasedStat: ResourceHandle.Named?, + val increasedStat: ResourceHandle.Named?, + val hatesFlavor: ResourceHandle.Named?, + val likesFlavor: ResourceHandle.Named?, val pokeathlonStatChanges: List, val moveBattleStylePreferences: List, val names: List, -) +) : EndpointModel /** * Change to a Pokeathlon stat for a given nature. See: https://pokeapi.co/docs/v2#naturestatchange @@ -213,7 +216,10 @@ public data class Nature( */ @Serializable @JsOnlyExport -public data class NatureStatChange(val maxChange: Int, val pokeathlonStat: NamedApiResource) +public data class NatureStatChange( + val maxChange: Int, + val pokeathlonStat: ResourceHandle.Named, +) /** * Move battle style preferences for a given nature. See: @@ -228,7 +234,7 @@ public data class NatureStatChange(val maxChange: Int, val pokeathlonStat: Named public data class MoveBattleStylePreference( val lowHpPreference: Int, val highHpPreference: Int, - val moveBattleStyle: NamedApiResource, + val moveBattleStyle: ResourceHandle.Named, ) /** @@ -247,7 +253,7 @@ public data class PokeathlonStat( val name: String, val names: List, val affectingNatures: NaturePokeathlonStatEffectSets, -) +) : EndpointModel /** * A set of natures and how they affect a Pokeathlon stat. See: @@ -272,7 +278,10 @@ public data class NaturePokeathlonStatEffectSets( */ @Serializable @JsOnlyExport -public data class NaturePokeathlonStatEffect(val maxChange: Int, val nature: NamedApiResource) +public data class NaturePokeathlonStatEffect( + val maxChange: Int, + val nature: ResourceHandle.Named, +) /** * Pokémon are the creatures that inhabit the world of the Pokémon games. They have a variety of @@ -308,9 +317,9 @@ public data class PokemonVariety( val isDefault: Boolean, val order: Int, val weight: Int, - val species: NamedApiResource, + val species: ResourceHandle.Named, val abilities: List, - val forms: List, + val forms: List>, val gameIndices: List, val heldItems: List, val moves: List, @@ -320,7 +329,7 @@ public data class PokemonVariety( val pastAbilities: List, val cries: PokemonCries, val sprites: PokemonSprites, -) +) : EndpointModel /** * Sprites are images used to depict Pokémon in the game. See: @@ -499,7 +508,7 @@ public data class GameSprites( public data class PokemonAbility( val isHidden: Boolean, val slot: Int, - val ability: NamedApiResource?, + val ability: ResourceHandle.Named?, ) /** @@ -512,7 +521,7 @@ public data class PokemonAbility( @Serializable @JsOnlyExport public data class PokemonHeldItem( - val item: NamedApiResource, + val item: ResourceHandle.Named, val versionDetails: List, ) @@ -525,7 +534,10 @@ public data class PokemonHeldItem( */ @Serializable @JsOnlyExport -public data class PokemonHeldItemVersion(val version: NamedApiResource, val rarity: Int) +public data class PokemonHeldItemVersion( + val version: ResourceHandle.Named, + val rarity: Int, +) /** * Moves that a Pokémon can learn. See: https://pokeapi.co/docs/v2#pokemonmove @@ -536,7 +548,7 @@ public data class PokemonHeldItemVersion(val version: NamedApiResource, val rari @Serializable @JsOnlyExport public data class PokemonMove( - val move: NamedApiResource, + val move: ResourceHandle.Named, val versionGroupDetails: List, ) @@ -552,8 +564,8 @@ public data class PokemonMove( @Serializable @JsOnlyExport public data class PokemonMoveVersion( - val moveLearnMethod: NamedApiResource, - val versionGroup: NamedApiResource, + val moveLearnMethod: ResourceHandle.Named, + val versionGroup: ResourceHandle.Named, val levelLearnedAt: Int, val order: Int?, ) @@ -567,7 +579,11 @@ public data class PokemonMoveVersion( */ @Serializable @JsOnlyExport -public data class PokemonStat(val stat: NamedApiResource, val effort: Int, val baseStat: Int) +public data class PokemonStat( + val stat: ResourceHandle.Named, + val effort: Int, + val baseStat: Int, +) /** * The type of a Pokémon and its slot. See: https://pokeapi.co/docs/v2#pokemontype @@ -577,7 +593,7 @@ public data class PokemonStat(val stat: NamedApiResource, val effort: Int, val b */ @Serializable @JsOnlyExport -public data class PokemonType(val slot: Int, val type: NamedApiResource) +public data class PokemonType(val slot: Int, val type: ResourceHandle.Named) /** * The types a Pokémon had in a previous generation. See: https://pokeapi.co/docs/v2#pokemonpasttype @@ -587,7 +603,10 @@ public data class PokemonType(val slot: Int, val type: NamedApiResource) */ @Serializable @JsOnlyExport -public data class PokemonPastType(val generation: NamedApiResource, val types: List) +public data class PokemonPastType( + val generation: ResourceHandle.Named, + val types: List, +) /** * The abilities a Pokémon had in a previous generation. See: @@ -599,7 +618,7 @@ public data class PokemonPastType(val generation: NamedApiResource, val types: L @Serializable @JsOnlyExport public data class PokemonPastAbility( - val generation: NamedApiResource, + val generation: ResourceHandle.Named, val abilities: List, ) @@ -621,7 +640,7 @@ public data class PokemonPastAbility( @Serializable @JsOnlyExport public data class LocationAreaEncounter( - val locationArea: NamedApiResource, + val locationArea: ResourceHandle.Named, val versionDetails: List, ) @@ -640,8 +659,8 @@ public data class PokemonColor( val id: Int, val name: String, val names: List, - val pokemonSpecies: List, -) + val pokemonSpecies: List>, +) : EndpointModel /** * Some Pokémon may appear in one of multiple, visually different forms. These differences are @@ -677,13 +696,13 @@ public data class PokemonForm( val isBattleOnly: Boolean, val isMega: Boolean, val formName: String, - val pokemon: NamedApiResource, + val pokemon: ResourceHandle.Named, val types: List, val sprites: PokemonFormSprites, - val versionGroup: NamedApiResource, + val versionGroup: ResourceHandle.Named, val names: List, val formNames: List, -) +) : EndpointModel /** * Sprites used to depict a Pokémon form. See: https://pokeapi.co/docs/v2#pokemonformsprites @@ -725,8 +744,8 @@ public data class PokemonHabitat( val id: Int, val name: String, val names: List, - val pokemonSpecies: List, -) + val pokemonSpecies: List>, +) : EndpointModel /** * Shapes are used to determine a Pokémon's appearance and for search purposes. See: @@ -745,8 +764,8 @@ public data class PokemonShape( val name: String, val awesomeNames: List, val names: List, - val pokemonSpecies: List, -) + val pokemonSpecies: List>, +) : EndpointModel /** * The "scientific" name of a Pokémon shape. See: https://pokeapi.co/docs/v2#awesomename @@ -756,7 +775,10 @@ public data class PokemonShape( */ @Serializable @JsOnlyExport -public data class AwesomeName(val awesomeName: String, val language: NamedApiResource) +public data class AwesomeName( + val awesomeName: String, + val language: ResourceHandle.Named, +) /** * A Pokémon Species forms the basis for at least one Pokémon. Attributes of a Pokémon species are @@ -811,22 +833,22 @@ public data class PokemonSpecies( val hatchCounter: Int, val hasGenderDifferences: Boolean, val formsSwitchable: Boolean, - val growthRate: NamedApiResource, + val growthRate: ResourceHandle.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: ResourceHandle.Named, + val shape: ResourceHandle.Named, + val evolvesFromSpecies: ResourceHandle.Named?, + val evolutionChain: ResourceHandle.Unnamed, + val habitat: ResourceHandle.Named?, + val generation: ResourceHandle.Named, val names: List, val palParkEncounters: List, val formDescriptions: List, val genera: List, val varieties: List, val flavorTextEntries: List, -) +) : EndpointModel /** * Flavor text entries for a Pokémon species. See: https://pokeapi.co/docs/v2#flavortext @@ -839,8 +861,8 @@ public data class PokemonSpecies( @JsOnlyExport public data class PokemonSpeciesFlavorText( val flavorText: String, - val language: NamedApiResource, - val version: NamedApiResource, + val language: ResourceHandle.Named, + val version: ResourceHandle.Named, ) /** @@ -852,7 +874,7 @@ public data class PokemonSpeciesFlavorText( */ @Serializable @JsOnlyExport -public data class Genus(val genus: String, val language: NamedApiResource) +public data class Genus(val genus: String, val language: ResourceHandle.Named) /** * The Pokédex number of a Pokémon species in a specific Pokédex. See: @@ -863,7 +885,10 @@ public data class Genus(val genus: String, val language: NamedApiResource) */ @Serializable @JsOnlyExport -public data class PokemonSpeciesDexEntry(val entryNumber: Int, val pokedex: NamedApiResource) +public data class PokemonSpeciesDexEntry( + val entryNumber: Int, + val pokedex: ResourceHandle.Named, +) /** * Areas used for grouping Pokémon encounters in Pal Park. See: @@ -879,7 +904,7 @@ public data class PokemonSpeciesDexEntry(val entryNumber: Int, val pokedex: Name public data class PalParkEncounterArea( val baseScore: Int, val rate: Int, - val area: NamedApiResource, + val area: ResourceHandle.Named, ) /** @@ -892,7 +917,7 @@ public data class PalParkEncounterArea( @JsOnlyExport public data class PokemonSpeciesVariety( val isDefault: Boolean, - @SerialName("pokemon") val variety: NamedApiResource, + @SerialName("pokemon") val variety: ResourceHandle.Named, ) /** @@ -920,10 +945,10 @@ public data class Stat( val isBattleOnly: Boolean, val affectingMoves: MoveStatAffectSets, val affectingNatures: NatureStatAffectSets, - val characteristics: List, - val moveDamageClass: NamedApiResource?, + val characteristics: List>, + val moveDamageClass: ResourceHandle.Named?, val names: List, -) +) : EndpointModel /** * A set of moves that affect a stat and how they affect it. See: @@ -947,7 +972,7 @@ public data class MoveStatAffectSets( */ @Serializable @JsOnlyExport -public data class MoveStatAffect(val change: Int, val move: NamedApiResource) +public data class MoveStatAffect(val change: Int, val move: ResourceHandle.Named) /** * A set of natures that affect a stat and how they affect it. See: @@ -959,8 +984,8 @@ public data class MoveStatAffect(val change: Int, val move: NamedApiResource) @Serializable @JsOnlyExport public data class NatureStatAffectSets( - val increase: List, - val decrease: List, + val increase: List>, + val decrease: List>, ) /** @@ -990,13 +1015,13 @@ public data class Type( val damageRelations: TypeRelations, val pastDamageRelations: List, val gameIndices: List, - val generation: NamedApiResource, - val moveDamageClass: NamedApiResource?, + val generation: ResourceHandle.Named, + val moveDamageClass: ResourceHandle.Named?, val names: List, val pokemon: List, - val moves: List, + val moves: List>, val sprites: VersionTypeSprites, -) +) : EndpointModel @Serializable @JsOnlyExport @@ -1075,7 +1100,7 @@ public data class GenerationIxTypeSprites( */ @Serializable @JsOnlyExport -public data class TypePokemon(val slot: Int, val pokemon: NamedApiResource) +public data class TypePokemon(val slot: Int, val pokemon: ResourceHandle.Named) /** * A detail of how effective this type is toward others and vice versa. See: @@ -1091,12 +1116,12 @@ public data class TypePokemon(val slot: Int, val pokemon: NamedApiResource) @Serializable @JsOnlyExport 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>, ) /** @@ -1109,6 +1134,6 @@ public data class TypeRelations( @Serializable @JsOnlyExport public data class TypePastDamageRelation( - val generation: NamedApiResource, + val generation: ResourceHandle.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..5319cb31 100644 --- a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/resource.kt +++ b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/resource.kt @@ -3,75 +3,128 @@ 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 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 } +@JsOnlyExport @Serializable public sealed interface EndpointModel + /** - * 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 -} +public sealed class ResourceHandle { + 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 { + internal companion object { + 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, slug: String): Named = + Named("/api/v2/${ResourceEndpoint.forModel()}/$id/", slug) + } - @JsName("create") - public constructor( - name: String, - category: String, - id: Int, - ) : this(name, resourceUrl(id, category)) + /** + * 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 = ApiResourceSerializer::class) + @JsOnlyExport + public data class Unnamed internal constructor(override val url: String) : + ResourceHandle() - override val category: String by lazy { urlToCat(url) } - override val id: Int by lazy { urlToId(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#namedapiresource + * + * @param slug The unique (name) of the referenced resource. + */ + @Serializable(with = NamedApiResourceSerializer::class) + @JsOnlyExport + public data class Named + internal constructor(override val url: String, val slug: String) : ResourceHandle() } /** * 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 + * 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. @@ -79,27 +132,29 @@ public data class NamedApiResource(val name: String, val url: String) : Resource * @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 -} +public sealed class PaginatedResourceList { + 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 + @JsOnlyExport + public data class Unnamed + internal constructor( + override val count: Int, + override val next: String?, + override val previous: String?, + override val results: List>, + ) : PaginatedResourceList() + + @Serializable + @JsOnlyExport + public data class Named + internal constructor( + override val count: Int, + override val next: String?, + override val previous: String?, + override val results: List>, + ) : PaginatedResourceList() +} diff --git a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/utility.kt b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/utility.kt index 4ea8b979..d8692074 100644 --- a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/utility.kt +++ b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/utility.kt @@ -24,7 +24,7 @@ public data class Language( val iso639: String, val iso3166: String, val names: List, -) +) : EndpointModel /** * The localized description for an API resource in a specific language. See: @@ -35,7 +35,10 @@ public data class Language( */ @Serializable @JsOnlyExport -public data class Description(val description: String, val language: NamedApiResource) +public data class Description( + val description: String, + val language: ResourceHandle.Named, +) /** * The localized effect text for an API resource in a specific language. See: @@ -46,7 +49,7 @@ public data class Description(val description: String, val language: NamedApiRes */ @Serializable @JsOnlyExport -public data class Effect(val effect: String, val language: NamedApiResource) +public data class Effect(val effect: String, val language: ResourceHandle.Named) /** * Encounter details for a Pokémon in a specific location area. See: @@ -63,9 +66,9 @@ public data class Effect(val effect: String, val language: NamedApiResource) public data class Encounter( val minLevel: Int, val maxLevel: Int, - val conditionValues: List, + val conditionValues: List>, val chance: Int, - val method: NamedApiResource, + val method: ResourceHandle.Named, ) /** @@ -77,7 +80,7 @@ public data class Encounter( */ @Serializable @JsOnlyExport -public data class FlavorText(val flavorText: String, val language: NamedApiResource) +public data class FlavorText(val flavorText: String, val language: ResourceHandle.Named) /** * Generation game index for a resource. See: https://pokeapi.co/docs/v2#generationgameindex @@ -87,7 +90,10 @@ public data class FlavorText(val flavorText: String, val language: NamedApiResou */ @Serializable @JsOnlyExport -public data class GenerationGameIndex(val gameIndex: Int, val generation: NamedApiResource) +public data class GenerationGameIndex( + val gameIndex: Int, + val generation: ResourceHandle.Named, +) /** * Machine and version group details. See: https://pokeapi.co/docs/v2#machineversiondetail @@ -98,8 +104,8 @@ public data class GenerationGameIndex(val gameIndex: Int, val generation: NamedA @Serializable @JsOnlyExport public data class MachineVersionDetail( - val machine: ApiResource, - val versionGroup: NamedApiResource, + val machine: ResourceHandle.Unnamed, + val versionGroup: ResourceHandle.Named, ) /** @@ -111,7 +117,7 @@ public data class MachineVersionDetail( */ @Serializable @JsOnlyExport -public data class Name(val name: String, val language: NamedApiResource) +public data class Name(val name: String, val language: ResourceHandle.Named) /** * The verbose effect text for an API resource in a specific language. See: @@ -126,7 +132,7 @@ public data class Name(val name: String, val language: NamedApiResource) public data class VerboseEffect( val effect: String, val shortEffect: String, - val language: NamedApiResource, + val language: ResourceHandle.Named, ) /** @@ -140,7 +146,7 @@ public data class VerboseEffect( @Serializable @JsOnlyExport public data class VersionEncounterDetail( - val version: NamedApiResource, + val version: ResourceHandle.Named, val maxChance: Int, val encounterDetails: List, ) @@ -153,7 +159,7 @@ public data class VersionEncounterDetail( */ @Serializable @JsOnlyExport -public data class VersionGameIndex(val gameIndex: Int, val version: NamedApiResource) +public data class VersionGameIndex(val gameIndex: Int, val version: ResourceHandle.Named) /** * The localized flavor text for a version group. See: @@ -167,6 +173,6 @@ public data class VersionGameIndex(val gameIndex: Int, val version: NamedApiReso @JsOnlyExport public data class VersionGroupFlavorText( val text: String, - val language: NamedApiResource, - val versionGroup: NamedApiResource, + val language: ResourceHandle.Named, + val versionGroup: ResourceHandle.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..eabefb62 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.EndpointModel +import co.pokeapi.pokekotlin.model.PaginatedResourceList +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) -> PaginatedResourceList, + 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..ea7428fb 100644 --- a/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/LocalPokeApi.kt +++ b/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/LocalPokeApi.kt @@ -2,8 +2,8 @@ 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.EndpointModel +import co.pokeapi.pokekotlin.model.PaginatedResourceList import io.ktor.client.plugins.api.* import io.ktor.client.statement.* import io.ktor.utils.io.* @@ -20,16 +20,22 @@ private val OffsetLimitPlugin = val endIndex = offset + limit when (requestedType.type) { - ApiResourceList::class -> { - val fullList = PokeApiJson.decodeFromSource(content.readBuffer()) + PaginatedResourceList.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()) + PaginatedResourceList.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..e83dd84a 100644 --- a/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/BerryTest.kt +++ b/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/BerryTest.kt @@ -2,7 +2,7 @@ package co.pokeapi.pokekotlin.test.model import co.pokeapi.pokekotlin.model.FlavorBerryMap import co.pokeapi.pokekotlin.model.Name -import co.pokeapi.pokekotlin.model.NamedApiResource +import co.pokeapi.pokekotlin.model.ResourceHandle 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(ResourceHandle.of(3, "hard"), firmness) assertNotEquals(0, flavors.size) - assertEquals(NamedApiResource("durin-berry", "item", 159), item) - assertEquals(NamedApiResource("water", "type", 11), naturalGiftType) + assertEquals(ResourceHandle.of(159, "durin-berry"), item) + assertEquals(ResourceHandle.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, ResourceHandle.of(4, "rawst")) + assertContains(names, Name(name = "Hard", language = ResourceHandle.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(ResourceHandle.of(3, "cute"), contestType) + assertContains(berries, FlavorBerryMap(potency = 10, berry = ResourceHandle.of(6, "leppa"))) + assertContains(names, Name(name = "Sweet", language = ResourceHandle.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..9a97b7ff 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.ResourceHandle 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(ResourceHandle.of(4, "bitter"), berryFlavor) assertContains( names, - ContestName( - name = "Smart", - color = "Green", - language = NamedApiResource("en", "language", 9), - ), + ContestName(name = "Smart", color = "Green", language = ResourceHandle.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 = ResourceHandle.of(9, "en"), ), ) assertContains( flavorTextEntries, FlavorText( flavorText = "The appeal works great if performed first.", - language = NamedApiResource("en", "language", 9), + language = ResourceHandle.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 = ResourceHandle.of(9, "en"), ), ) - assertContains(moves, NamedApiResource("assist", "move", 274)) + assertContains(moves, ResourceHandle.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..57c12ea6 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.Name -import co.pokeapi.pokekotlin.model.NamedApiResource +import co.pokeapi.pokekotlin.model.ResourceHandle 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 = ResourceHandle.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, ResourceHandle.of(15, "radio-hoenn")) + assertContains(names, Name(name = "Radio", language = ResourceHandle.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(ResourceHandle.of(2, "time"), condition) + assertContains(names, Name(name = "At night", language = ResourceHandle.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..9d398fd4 100644 --- a/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/EvolutionTest.kt +++ b/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/EvolutionTest.kt @@ -3,7 +3,7 @@ package co.pokeapi.pokekotlin.test.model import co.pokeapi.pokekotlin.model.ChainLink import co.pokeapi.pokekotlin.model.EvolutionDetail import co.pokeapi.pokekotlin.model.Name -import co.pokeapi.pokekotlin.model.NamedApiResource +import co.pokeapi.pokekotlin.model.ResourceHandle import co.pokeapi.pokekotlin.test.LocalPokeApi import kotlin.test.Test import kotlin.test.assertContains @@ -21,31 +21,25 @@ class EvolutionTest { assertEquals( ChainLink( isBaby = false, - species = NamedApiResource("bulbasaur", "pokemon-species", 1), + species = ResourceHandle.of(1, "bulbasaur"), evolutionDetails = emptyList(), evolvesTo = listOf( ChainLink( isBaby = false, - species = NamedApiResource("ivysaur", "pokemon-species", 2), + species = ResourceHandle.of(2, "ivysaur"), evolutionDetails = listOf( - EvolutionDetail( - trigger = NamedApiResource("level-up", "evolution-trigger", 1), - minLevel = 16, - ) + EvolutionDetail(trigger = ResourceHandle.of(1, "level-up"), minLevel = 16) ), evolvesTo = listOf( ChainLink( isBaby = false, - species = NamedApiResource("venusaur", "pokemon-species", 3), + species = ResourceHandle.of(3, "venusaur"), evolutionDetails = listOf( - EvolutionDetail( - trigger = NamedApiResource("level-up", "evolution-trigger", 1), - minLevel = 32, - ) + EvolutionDetail(trigger = ResourceHandle.of(1, "level-up"), minLevel = 32) ), evolvesTo = emptyList(), ) @@ -65,8 +59,8 @@ class EvolutionTest { chain.evolvesTo.find { it.evolutionDetails.contains( EvolutionDetail( - trigger = NamedApiResource("level-up", "evolution-trigger", 1), - heldItem = NamedApiResource("razor-claw", "item", 303), + trigger = ResourceHandle.of(1, "level-up"), + heldItem = ResourceHandle.of(303, "razor-claw"), timeOfDay = "night", ) ) @@ -82,8 +76,8 @@ class EvolutionTest { chain.evolvesTo.find { it.evolutionDetails.contains( EvolutionDetail( - trigger = NamedApiResource("use-item", "evolution-trigger", 3), - item = NamedApiResource("water-stone", "item", 84), + trigger = ResourceHandle.of(3, "use-item"), + item = ResourceHandle.of(84, "water-stone"), ) ) } @@ -98,8 +92,8 @@ class EvolutionTest { chain.evolvesTo.find { it.evolutionDetails.contains( EvolutionDetail( - trigger = NamedApiResource("level-up", "evolution-trigger", 1), - location = NamedApiResource("eterna-forest", "location", 8), + trigger = ResourceHandle.of(1, "level-up"), + location = ResourceHandle.of(8, "eterna-forest"), ) ) } @@ -114,7 +108,7 @@ class EvolutionTest { chain.evolvesTo.find { it.evolutionDetails.contains( EvolutionDetail( - trigger = NamedApiResource("level-up", "evolution-trigger", 1), + trigger = ResourceHandle.of(1, "level-up"), minHappiness = 160, timeOfDay = "day", ) @@ -131,8 +125,8 @@ class EvolutionTest { chain.evolvesTo.find { it.evolutionDetails.contains( EvolutionDetail( - trigger = NamedApiResource("level-up", "evolution-trigger", 1), - knownMoveType = NamedApiResource("fairy", "type", 18), + trigger = ResourceHandle.of(1, "level-up"), + knownMoveType = ResourceHandle.of(18, "fairy"), minAffection = 2, ) ) @@ -147,8 +141,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 = ResourceHandle.of(1, "level-up"), + knownMove = ResourceHandle.of(246, "ancient-power"), ), ) } @@ -160,11 +154,7 @@ class EvolutionTest { assertNotNull( chain.evolvesTo.find { it.evolutionDetails.contains( - EvolutionDetail( - trigger = NamedApiResource("level-up", "evolution-trigger", 1), - gender = 1, - minLevel = 20, - ) + EvolutionDetail(trigger = ResourceHandle.of(1, "level-up"), gender = 1, minLevel = 20) ) } ) @@ -177,10 +167,7 @@ class EvolutionTest { assertNotNull( chain.evolvesTo.find { it.evolutionDetails.contains( - EvolutionDetail( - trigger = NamedApiResource("level-up", "evolution-trigger", 1), - minBeauty = 171, - ) + EvolutionDetail(trigger = ResourceHandle.of(1, "level-up"), minBeauty = 171) ) } ) @@ -194,9 +181,9 @@ class EvolutionTest { chain.evolvesTo.find { it.evolutionDetails.contains( EvolutionDetail( - trigger = NamedApiResource("level-up", "evolution-trigger", 1), + trigger = ResourceHandle.of(1, "level-up"), minLevel = 32, - partyType = NamedApiResource("dark", "type", 17), + partyType = ResourceHandle.of(17, "dark"), ) ) } @@ -211,7 +198,7 @@ class EvolutionTest { chain.evolvesTo.find { it.evolutionDetails.contains( EvolutionDetail( - trigger = NamedApiResource("level-up", "evolution-trigger", 1), + trigger = ResourceHandle.of(1, "level-up"), minLevel = 20, relativePhysicalStats = 1, ) @@ -228,7 +215,7 @@ class EvolutionTest { chain.evolvesTo[0].evolvesTo.find { it.evolutionDetails.contains( EvolutionDetail( - trigger = NamedApiResource("level-up", "evolution-trigger", 1), + trigger = ResourceHandle.of(1, "level-up"), minLevel = 50, needsOverworldRain = true, ) @@ -245,7 +232,7 @@ class EvolutionTest { chain.evolvesTo.find { it.evolutionDetails.contains( EvolutionDetail( - trigger = NamedApiResource("level-up", "evolution-trigger", 1), + trigger = ResourceHandle.of(1, "level-up"), minLevel = 30, turnUpsideDown = true, ) @@ -262,8 +249,8 @@ class EvolutionTest { chain.evolvesTo.find { it.evolutionDetails.contains( EvolutionDetail( - trigger = NamedApiResource("level-up", "evolution-trigger", 1), - partySpecies = NamedApiResource("remoraid", "pokemon-species", 223), + trigger = ResourceHandle.of(1, "level-up"), + partySpecies = ResourceHandle.of(223, "remoraid"), ) ) } @@ -278,8 +265,8 @@ class EvolutionTest { chain.evolvesTo.find { it.evolutionDetails.contains( EvolutionDetail( - trigger = NamedApiResource("trade", "evolution-trigger", 2), - tradeSpecies = NamedApiResource("karrablast", "pokemon-species", 588), + trigger = ResourceHandle.of(2, "trade"), + tradeSpecies = ResourceHandle.of(588, "karrablast"), ) ) } @@ -290,7 +277,7 @@ class EvolutionTest { @Test fun getEvolutionChain16() = runTest { LocalPokeApi.getEvolutionChain(72).apply { - assertEquals(NamedApiResource("full-incense", "item", 293), babyTriggerItem) + assertEquals(ResourceHandle.of(293, "full-incense"), babyTriggerItem) assertEquals(true, chain.isBaby) } } @@ -300,11 +287,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 = ResourceHandle.of(9, "en"))) + assertContains(pokemonSpecies, ResourceHandle.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..330f24aa 100644 --- a/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/GameTest.kt +++ b/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/GameTest.kt @@ -2,8 +2,8 @@ package co.pokeapi.pokekotlin.test.model import co.pokeapi.pokekotlin.model.Description import co.pokeapi.pokekotlin.model.Name -import co.pokeapi.pokekotlin.model.NamedApiResource import co.pokeapi.pokekotlin.model.PokemonEntry +import co.pokeapi.pokekotlin.model.ResourceHandle import co.pokeapi.pokekotlin.test.LocalPokeApi import kotlin.test.Test import kotlin.test.assertContains @@ -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, ResourceHandle.of(189, "primordial-sea")) + assertContains(names, Name(name = "Generation VI", language = ResourceHandle.of(9, "en"))) + assertEquals(ResourceHandle.of(6, "kalos"), mainRegion) + assertContains(moves, ResourceHandle.of(562, "belch")) + assertContains(pokemonSpecies, ResourceHandle.of(656, "froakie")) + assertContains(types, ResourceHandle.of(18, "fairy")) + assertContains(versionGroups, ResourceHandle.of(15, "x-y")) } } @@ -38,21 +35,15 @@ class GameTest { assertEquals(true, isMainSeries) assertContains( descriptions, - Description(description = "", language = NamedApiResource("en", "language", 9)), - ) - assertContains( - names, - Name(name = "Central Kalos", language = NamedApiResource("en", "language", 9)), + Description(description = "", language = ResourceHandle.of(9, "en")), ) + assertContains(names, Name(name = "Central Kalos", language = ResourceHandle.of(9, "en"))) assertContains( pokemonEntries, - PokemonEntry( - entryNumber = 150, - pokemonSpecies = NamedApiResource("haxorus", "pokemon-species", 612), - ), + PokemonEntry(entryNumber = 150, pokemonSpecies = ResourceHandle.of(612, "haxorus")), ) - assertEquals(NamedApiResource("kalos", "region", 6), region) - assertContains(versionGroups, NamedApiResource("x-y", "version-group", 15)) + assertEquals(ResourceHandle.of(6, "kalos"), region) + assertContains(versionGroups, ResourceHandle.of(15, "x-y")) } } @@ -61,11 +52,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 = ResourceHandle.of(9, "en"))) + assertEquals(ResourceHandle.of(6, "emerald"), versionGroup) } } @@ -75,11 +63,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(ResourceHandle.of(1, "generation-i"), generation) + assertContains(moveLearnMethods, ResourceHandle.of(4, "machine")) + assertContains(pokedexes, ResourceHandle.of(2, "kanto")) + assertContains(regions, ResourceHandle.of(1, "kanto")) + assertContains(versions, ResourceHandle.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..19c13025 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, ResourceHandle.of(5, "holdable")) + assertEquals(ResourceHandle.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 = ResourceHandle.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 = ResourceHandle.of(5, "ruby-sapphire"), + language = ResourceHandle.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 = ResourceHandle.of(6, "generation-vi")), ) + assertContains(names, Name(name = "Ice Heal", language = ResourceHandle.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 == ResourceHandle.of(241, "miltank") && it.versionDetails.contains( - ItemHolderPokemonVersionDetail( - rarity = 100, - version = NamedApiResource("y", "version", 24), - ) + ItemHolderPokemonVersionDetail(rarity = 100, version = ResourceHandle.of(24, "y")) ) }, ) @@ -72,15 +63,13 @@ class ItemTest { @Test fun getItem3() = runTest { LocalPokeApi.getItem(249).apply { - assertEquals(NamedApiResource("badly-poison", "item-fling-effect", 1), flingEffect) + assertEquals(ResourceHandle.of(1, "badly-poison"), flingEffect) } } @Test fun getItem4() = runTest { - LocalPokeApi.getItem(231).apply { - assertEquals(ApiResource("evolution-chain", 90), babyTriggerFor) - } + LocalPokeApi.getItem(231).apply { assertEquals(ResourceHandle.of(90), babyTriggerFor) } } @Test fun getItem5() = runTest { LocalPokeApi.getItem(967) } @@ -90,8 +79,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 == ResourceHandle.of(2) && + machineVersionDetail.versionGroup == ResourceHandle.of(1, "red-blue") } ) } @@ -104,16 +93,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 = ResourceHandle.of(9, "en")), ) + assertContains(items, ResourceHandle.of(17, "potion")) + assertContains(names, Name(name = "Usable_overworld", language = ResourceHandle.of(9, "en"))) } } @@ -122,12 +105,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(ResourceHandle.of(3, "pokeballs"), pocket) + assertContains(items, ResourceHandle.of(4, "poke-ball")) + assertContains(names, Name(name = "Standard balls", language = ResourceHandle.of(9, "en"))) } } @@ -138,12 +118,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 = ResourceHandle.of(9, "en")), ) - assertContains(items, NamedApiResource("toxic-orb", "item", 249)) + assertContains(items, ResourceHandle.of(249, "toxic-orb")) } } @@ -152,11 +129,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, ResourceHandle.of(37, "all-machines")) + assertContains(names, Name(name = "TMs and HMs", language = ResourceHandle.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..d94fd9c3 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(ResourceHandle.of(4, "sinnoh"), region) + assertContains(names, Name(name = "Wayward Cave", language = ResourceHandle.of(9, "en"))) assertContains( gameIndices, - GenerationGameIndex( - gameIndex = 65, - generation = NamedApiResource("generation-iv", "generation", 4), - ), + GenerationGameIndex(gameIndex = 65, generation = ResourceHandle.of(4, "generation-iv")), ) - assertContains(areas, NamedApiResource("wayward-cave-1f", "location-area", 113)) + assertContains(areas, ResourceHandle.of(113, "wayward-cave-1f")) } } @@ -37,34 +31,30 @@ class LocationTest { assertEquals(20, id) assertEquals("mt-coronet-1f-from-exterior", name) assertEquals(20, gameIndex) - assertEquals(NamedApiResource("mt-coronet", "location", 10), location) + assertEquals(ResourceHandle.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 = ResourceHandle.of(9, "en")), ) assertNotNull( encounterMethodRates.find { - it.encounterMethod == NamedApiResource("walk", "encounter-method", 1) && - EncounterMethodRateVersionDetail(10, NamedApiResource("platinum", "version", 14)) in + it.encounterMethod == ResourceHandle.of(1, "walk") && + EncounterMethodRateVersionDetail(10, ResourceHandle.of(14, "platinum")) in it.versionDetails } ) assertNotNull( pokemonEncounters.find { pokemonEncounter -> - pokemonEncounter.pokemon == NamedApiResource("clefairy", "pokemon", 35) && + pokemonEncounter.pokemon == ResourceHandle.of(35, "clefairy") && pokemonEncounter.versionDetails.find { encounterDetail -> - encounterDetail.version == NamedApiResource("diamond", "version", 12) && + encounterDetail.version == ResourceHandle.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 == ResourceHandle.of(1, "walk") && + ResourceHandle.of(8, "slot2-none") in encounter.conditionValues } != null } != null } @@ -77,13 +67,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 = ResourceHandle.of(9, "en"))) assertContains( pokemonEncounters, PalParkEncounterSpecies( baseScore = 100, rate = 1, - pokemonSpecies = NamedApiResource("shaymin", "pokemon-species", 492), + pokemonSpecies = ResourceHandle.of(492, "shaymin"), ), ) } @@ -94,11 +84,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(ResourceHandle.of(1, "generation-i"), mainGeneration) + assertContains(locations, ResourceHandle.of(67, "celadon-city")) + assertContains(names, Name(name = "Kanto", language = ResourceHandle.of(9, "en"))) + assertContains(pokedexes, ResourceHandle.of(2, "kanto")) + assertContains(versionGroups, ResourceHandle.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..877fc3cc 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.ResourceHandle 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(ResourceHandle.of(305, "tm01"), item) + assertEquals(ResourceHandle.of(526, "work-up"), move) + assertEquals(ResourceHandle.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..42ac9df4 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(ResourceHandle.of(5, "tough"), contestType) + assertEquals(ResourceHandle.of(4), contestEffect) + assertEquals(ResourceHandle.of(5), superContestEffect) + assertEquals(ResourceHandle.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 = ResourceHandle.of(9, "en"), ), ) assertEquals(emptyList(), effectChanges) - assertEquals(NamedApiResource("generation-i", "generation", 1), generation) + assertEquals(ResourceHandle.of(1, "generation-i"), generation) assertEquals( MoveMetaData( - ailment = NamedApiResource("paralysis", "move-ailment", 1), - category = NamedApiResource("damage+ailment", "move-category", 4), + ailment = ResourceHandle.of(1, "paralysis"), + category = ResourceHandle.of(4, "damage+ailment"), minHits = null, maxHits = null, minTurns = null, @@ -52,27 +52,24 @@ class MoveTest { ), meta, ) - assertContains( - names, - Name(name = "Body Slam", language = NamedApiResource("en", "language", 9)), - ) + assertContains(names, Name(name = "Body Slam", language = ResourceHandle.of(9, "en"))) assertEquals(emptyList(), pastValues) assertEquals(emptyList(), statChanges) - assertEquals(NamedApiResource("selected-pokemon", "move-target", 10), target) - assertEquals(NamedApiResource("normal", "type", 1), type) + assertEquals(ResourceHandle.of(10, "selected-pokemon"), target) + assertEquals(ResourceHandle.of(1, "normal"), type) assertContains( machines, MachineVersionDetail( - machine = ApiResource("machine", 142), - versionGroup = NamedApiResource("red-blue", "version-group", 1), + machine = ResourceHandle.of(142), + versionGroup = ResourceHandle.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 = ResourceHandle.of(9, "en"), + versionGroup = ResourceHandle.of(3, "gold-silver"), ), ) } @@ -84,7 +81,7 @@ class MoveTest { assertEquals( ContestComboSets( normalSet = ContestComboDetail(null, null), - superSet = ContestComboDetail(null, listOf(NamedApiResource("focus-energy", "move", 116))), + superSet = ContestComboDetail(null, listOf(ResourceHandle.of(116, "focus-energy"))), ), contestCombos, ) @@ -96,10 +93,10 @@ class MoveTest { LocalPokeApi.getMove(16).apply { assertNotNull( effectChanges.find { - it.versionGroup == NamedApiResource("gold-silver", "version-group", 3) && + it.versionGroup == ResourceHandle.of(3, "gold-silver") && Effect( effect = "Does not hit Pokémon under the effects of fly.", - language = NamedApiResource("en", "language", 9), + language = ResourceHandle.of(9, "en"), ) in it.effectEntries } ) @@ -109,10 +106,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 = ResourceHandle.of(2, "attack"))) } } @@ -127,8 +121,8 @@ class MoveTest { pp = null, effectChance = null, effectEntries = emptyList(), - type = NamedApiResource("normal", "type", 1), - versionGroup = NamedApiResource("gold-silver", "version-group", 3), + type = ResourceHandle.of(1, "normal"), + versionGroup = ResourceHandle.of(3, "gold-silver"), ), ) } @@ -139,11 +133,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 = ResourceHandle.of(9, "en"))) + assertContains(moves, ResourceHandle.of(78, "stun-spore")) } } @@ -152,7 +143,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 = ResourceHandle.of(9, "en"))) } } @@ -165,10 +156,10 @@ class MoveTest { descriptions, Description( description = "No damage; inflicts status ailment", - language = NamedApiResource("en", "language", 9), + language = ResourceHandle.of(9, "en"), ), ) - assertContains(moves, NamedApiResource("sing", "move", 47)) + assertContains(moves, ResourceHandle.of(47, "sing")) } } @@ -177,12 +168,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 = ResourceHandle.of(9, "en"))) assertContains( descriptions, - Description(description = "No damage", language = NamedApiResource("en", "language", 9)), + Description(description = "No damage", language = ResourceHandle.of(9, "en")), ) - assertContains(moves, NamedApiResource("snatch", "move", 289)) + assertContains(moves, ResourceHandle.of(289, "snatch")) } } @@ -191,10 +182,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 = ResourceHandle.of(9, "en"))) assertContains( descriptions, Description( @@ -202,10 +190,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 = ResourceHandle.of(9, "en"), ), ) - assertContains(versionGroups, NamedApiResource("x-y", "version-group", 15)) + assertContains(versionGroups, ResourceHandle.of(15, "x-y")) } } @@ -214,18 +202,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 = ResourceHandle.of(9, "en"))) assertContains( descriptions, Description( description = "One opposing Pokémon, selected at random.", - language = NamedApiResource("en", "language", 9), + language = ResourceHandle.of(9, "en"), ), ) - assertContains(moves, NamedApiResource("uproar", "move", 253)) + assertContains(moves, ResourceHandle.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..ad27b96c 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(ResourceHandle.of(3, "generation-iii"), generation) + assertContains(names, Name(name = "Stench", language = ResourceHandle.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 = ResourceHandle.of(9, "en"), ), ) assertNotNull( effectChanges.find { - it.versionGroup == NamedApiResource("black-white", "version-group", 11) && + it.versionGroup == ResourceHandle.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 = ResourceHandle.of(9, "en")) ) } ) assertContains( pokemon, - AbilityPokemon( - isHidden = true, - slot = 3, - pokemon = NamedApiResource("gloom", "pokemon", 44), - ), + AbilityPokemon(isHidden = true, slot = 3, pokemon = ResourceHandle.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 = ResourceHandle.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 = ResourceHandle.of(9, "en"))) + assertContains(pokemonSpecies, ResourceHandle.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 = ResourceHandle.of(715, "noivern")), ) - assertContains(requiredForEvolution, NamedApiResource("froslass", "pokemon-species", 478)) + assertContains(requiredForEvolution, ResourceHandle.of(478, "froslass")) } } @@ -100,10 +87,10 @@ class PokemonTest { assertEquals("\\frac{5x^3}{4}", formula) assertContains( descriptions, - Description(description = "slow", language = NamedApiResource("en", "language", 9)), + Description(description = "slow", language = ResourceHandle.of(9, "en")), ) assertContains(levels, GrowthRateExperienceLevel(experience = 1250000, level = 100)) - assertContains(pokemonSpecies, NamedApiResource("volcanion", "pokemon-species", 721)) + assertContains(pokemonSpecies, ResourceHandle.of(721, "volcanion")) } } @@ -112,26 +99,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(ResourceHandle.of(6, "speed"), increasedStat) + assertEquals(ResourceHandle.of(3, "defense"), decreasedStat) + assertEquals(ResourceHandle.of(3, "sweet"), likesFlavor) + assertEquals(ResourceHandle.of(5, "sour"), hatesFlavor) assertContains( pokeathlonStatChanges, - NatureStatChange( - pokeathlonStat = NamedApiResource("speed", "pokeathlon-stat", 1), - maxChange = 2, - ), + NatureStatChange(pokeathlonStat = ResourceHandle.of(1, "speed"), maxChange = 2), ) assertContains( moveBattleStylePreferences, MoveBattleStylePreference( highHpPreference = 58, lowHpPreference = 88, - moveBattleStyle = NamedApiResource("attack", "move-battle-style", 1), + moveBattleStyle = ResourceHandle.of(1, "attack"), ), ) - assertContains(names, Name(name = "Hasty", language = NamedApiResource("en", "language", 9))) + assertContains(names, Name(name = "Hasty", language = ResourceHandle.of(9, "en"))) } } @@ -140,17 +124,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 = ResourceHandle.of(9, "en"))) assertContains( affectingNatures.decrease, - NaturePokeathlonStatEffect(nature = NamedApiResource("sassy", "nature", 24), maxChange = -2), + NaturePokeathlonStatEffect(nature = ResourceHandle.of(24, "sassy"), maxChange = -2), ) assertContains( affectingNatures.increase, - NaturePokeathlonStatEffect( - nature = NamedApiResource("serious", "nature", 25), - maxChange = 1, - ), + NaturePokeathlonStatEffect(nature = ResourceHandle.of(25, "serious"), maxChange = 1), ) } } @@ -165,37 +146,33 @@ class PokemonTest { assertEquals(true, isDefault) assertEquals(1, order) assertEquals(69, weight) - assertEquals(NamedApiResource("bulbasaur", "pokemon-species", 1), species) + assertEquals(ResourceHandle.of(1, "bulbasaur"), species) assertContains( abilities, - PokemonAbility( - slot = 1, - isHidden = false, - ability = NamedApiResource("overgrow", "ability", 65), - ), + PokemonAbility(slot = 1, isHidden = false, ability = ResourceHandle.of(65, "overgrow")), ) - assertContains(forms, NamedApiResource("bulbasaur", "pokemon-form", 1)) + assertContains(forms, ResourceHandle.of(1, "bulbasaur")) assertContains( gameIndices, - VersionGameIndex(version = NamedApiResource("white-2", "version", 22), gameIndex = 1), + VersionGameIndex(version = ResourceHandle.of(22, "white-2"), gameIndex = 1), ) assertEquals(emptyList(), heldItems) assertNotNull( moves.find { - it.move == NamedApiResource("razor-wind", "move", 13) && + it.move == ResourceHandle.of(13, "razor-wind") && PokemonMoveVersion( levelLearnedAt = 0, - versionGroup = NamedApiResource("gold-silver", "version-group", 3), - moveLearnMethod = NamedApiResource("egg", "move-learn-method", 2), + versionGroup = ResourceHandle.of(3, "gold-silver"), + moveLearnMethod = ResourceHandle.of(2, "egg"), order = null, ) in it.versionGroupDetails } ) assertContains( stats, - PokemonStat(effort = 0, baseStat = 45, stat = NamedApiResource("hp", "stat", 1)), + PokemonStat(effort = 0, baseStat = 45, stat = ResourceHandle.of(1, "hp")), ) - assertContains(types, PokemonType(slot = 1, type = NamedApiResource("grass", "type", 12))) + assertContains(types, PokemonType(slot = 1, type = ResourceHandle.of(12, "grass"))) } } @@ -204,8 +181,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.item == ResourceHandle.of(199, "silver-powder") && + PokemonHeldItemVersion(version = ResourceHandle.of(7, "ruby"), rarity = 5) in it.versionDetails } ) @@ -218,17 +195,16 @@ class PokemonTest { assertNotNull( find { locAreaEncounter -> locAreaEncounter.locationArea == - NamedApiResource("kanto-route-2-south-towards-viridian-city", "location-area", 296) && + ResourceHandle.of(296, "kanto-route-2-south-towards-viridian-city") && locAreaEncounter.versionDetails.find { detail -> detail.maxChance == 10 - detail.version == NamedApiResource("heartgold", "version", 15) + detail.version == ResourceHandle.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 == ResourceHandle.of(1, "walk") && + ResourceHandle.of(3, "time-morning") in encounter.conditionValues } != null } != null } @@ -257,8 +233,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 = ResourceHandle.of(9, "en"))) + assertContains(pokemonSpecies, ResourceHandle.of(143, "snorlax")) } } @@ -273,8 +249,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(ResourceHandle.of(1, "bulbasaur"), pokemon) + assertEquals(ResourceHandle.of(1, "red-blue"), versionGroup) sprites.apply { assertTrue(frontDefault!!.endsWith("/sprites/pokemon/1.png")) assertTrue(backDefault!!.endsWith("/sprites/pokemon/back/1.png")) @@ -289,7 +265,7 @@ class PokemonTest { LocalPokeApi.getPokemonForm(10266).apply { assertContains( formNames, - Name(name = "Original Color", language = NamedApiResource("en", "language", 9)), + Name(name = "Original Color", language = ResourceHandle.of(9, "en")), ) } } @@ -299,8 +275,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 = ResourceHandle.of(9, "en"))) + assertContains(pokemonSpecies, ResourceHandle.of(379, "registeel")) } } @@ -309,12 +285,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 = ResourceHandle.of(9, "en"))) assertContains( awesomeNames, - AwesomeName(awesomeName = "Pomaceous", language = NamedApiResource("en", "language", 9)), + AwesomeName(awesomeName = "Pomaceous", language = ResourceHandle.of(9, "en")), ) - assertContains(pokemonSpecies, NamedApiResource("shellder", "pokemon-species", 90)) + assertContains(pokemonSpecies, ResourceHandle.of(90, "shellder")) } } @@ -333,44 +309,28 @@ class PokemonTest { assertEquals(20, hatchCounter) assertEquals(false, hasGenderDifferences) assertEquals(false, formsSwitchable) - assertEquals(NamedApiResource("medium-slow", "growth-rate", 4), growthRate) + assertEquals(ResourceHandle.of(4, "medium-slow"), growthRate) assertContains( pokedexNumbers, - PokemonSpeciesDexEntry( - entryNumber = 80, - pokedex = NamedApiResource("kalos-central", "pokedex", 12), - ), + PokemonSpeciesDexEntry(entryNumber = 80, pokedex = ResourceHandle.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, ResourceHandle.of(7, "plant")) + assertEquals(ResourceHandle.of(5, "green"), color) + assertEquals(ResourceHandle.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(ResourceHandle.of(1), evolutionChain) + assertEquals(ResourceHandle.of(3, "grassland"), habitat) + assertEquals(ResourceHandle.of(1, "generation-i"), generation) + assertContains(names, Name(name = "Bulbasaur", language = ResourceHandle.of(9, "en"))) assertContains( palParkEncounters, - PalParkEncounterArea( - rate = 30, - baseScore = 50, - area = NamedApiResource("field", "pal-park-area", 2), - ), + PalParkEncounterArea(rate = 30, baseScore = 50, area = ResourceHandle.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 = ResourceHandle.of(9, "en"))) assertContains( varieties, - PokemonSpeciesVariety( - isDefault = true, - variety = NamedApiResource("bulbasaur", "pokemon", 1), - ), + PokemonSpeciesVariety(isDefault = true, variety = ResourceHandle.of(1, "bulbasaur")), ) assertContains( flavorTextEntries, @@ -379,8 +339,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 = ResourceHandle.of(9, "en"), + version = ResourceHandle.of(26, "alpha-sapphire"), ), ) } @@ -389,7 +349,7 @@ class PokemonTest { @Test fun getPokemonSpecies2() = runTest { LocalPokeApi.getPokemonSpecies(2).apply { - assertEquals(NamedApiResource("bulbasaur", "pokemon-species", 1), evolvesFromSpecies) + assertEquals(ResourceHandle.of(1, "bulbasaur"), evolvesFromSpecies) } } @@ -403,7 +363,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 = ResourceHandle.of(9, "en"), ), ) } @@ -418,16 +378,16 @@ class PokemonTest { assertEquals(false, isBattleOnly) assertContains( affectingMoves.increase, - MoveStatAffect(change = 2, move = NamedApiResource("swords-dance", "move", 14)), + MoveStatAffect(change = 2, move = ResourceHandle.of(14, "swords-dance")), ) assertContains( affectingMoves.decrease, - MoveStatAffect(change = -1, move = NamedApiResource("growl", "move", 45)), + MoveStatAffect(change = -1, move = ResourceHandle.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, ResourceHandle.of(6, "lonely")) + assertContains(affectingNatures.decrease, ResourceHandle.of(2, "bold")) + assertEquals(ResourceHandle.of(2, "physical"), moveDamageClass) + assertContains(names, Name(name = "Attack", language = ResourceHandle.of(9, "en"))) } } @@ -437,27 +397,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, ResourceHandle.of(4, "poison")) + assertContains(noDamageFrom, ResourceHandle.of(1, "normal")) + assertContains(halfDamageTo, ResourceHandle.of(17, "dark")) + assertContains(doubleDamageFrom, ResourceHandle.of(8, "ghost")) + assertContains(noDamageTo, ResourceHandle.of(1, "normal")) + assertContains(doubleDamageTo, ResourceHandle.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 = ResourceHandle.of(6, "generation-vi")), ) - assertContains(moves, NamedApiResource("hex", "move", 506)) + assertEquals(ResourceHandle.of(2, "physical"), moveDamageClass) + assertContains(names, Name(name = "Ghost", language = ResourceHandle.of(9, "en"))) + assertContains(pokemon, TypePokemon(slot = 1, pokemon = ResourceHandle.of(607, "litwick"))) + assertContains(moves, ResourceHandle.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..796ac438 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,8 @@ 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.EndpointModel +import co.pokeapi.pokekotlin.model.PaginatedResourceList +import co.pokeapi.pokekotlin.model.ResourceHandle import co.pokeapi.pokekotlin.test.LocalPokeApi import kotlin.test.* import kotlinx.coroutines.test.runTest @@ -12,11 +11,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 () -> PaginatedResourceList.Named, ) { call().apply { assertTrue(results.size <= pageSize, "Actual count: ${results.size}, pageSize: $pageSize") @@ -29,16 +27,18 @@ class ResourceListTest { } results.forEach { - assertNotEquals("", it.name) - assertNotEquals("", it.category) - it.id + assertNotEquals("", it.slug) + assertNotNull(it.id) } - assertContains(results, NamedApiResource(name, category, id)) + assertContains(results, ResourceHandle.of(id, name)) } } - private suspend fun testCase(category: String, id: Int, call: suspend () -> ApiResourceList) { + private suspend inline fun testCase( + id: Int, + call: suspend () -> PaginatedResourceList.Unnamed, + ) { call().apply { assertTrue(results.size <= pageSize) if (pageSize >= count) { @@ -49,257 +49,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, ResourceHandle.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..9a3cc4dc 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.Name -import co.pokeapi.pokekotlin.model.NamedApiResource +import co.pokeapi.pokekotlin.model.ResourceHandle 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 = ResourceHandle.of(9, "en"))) } } } From 765f508f9745d3f30935aa1d6558fdc09ae8f32d Mon Sep 17 00:00:00 2001 From: Sargun Vohra Date: Tue, 1 Jul 2025 00:31:01 -0700 Subject: [PATCH 2/5] bit of refactor --- .../demoapp/screens/PokemonListScreen.kt | 10 +- .../kotlin/co/pokeapi/pokekotlin/PokeApi.kt | 156 +++++++--------- .../internal/ApiResourceSerializer.kt | 30 ++- .../internal/NamedApiResourceSerializer.kt | 16 -- .../co/pokeapi/pokekotlin/model/base.kt | 6 + .../co/pokeapi/pokekotlin/model/berries.kt | 14 +- .../co/pokeapi/pokekotlin/model/contests.kt | 6 +- .../co/pokeapi/pokekotlin/model/encounters.kt | 4 +- .../co/pokeapi/pokekotlin/model/evolution.kt | 24 +-- .../co/pokeapi/pokekotlin/model/games.kt | 30 +-- .../co/pokeapi/pokekotlin/model/items.kt | 22 +-- .../co/pokeapi/pokekotlin/model/locations.kt | 22 +-- .../co/pokeapi/pokekotlin/model/machines.kt | 6 +- .../co/pokeapi/pokekotlin/model/moves.kt | 44 ++--- .../co/pokeapi/pokekotlin/model/pokemon.kt | 146 +++++++-------- .../co/pokeapi/pokekotlin/model/resource.kt | 37 ++-- .../co/pokeapi/pokekotlin/model/utility.kt | 34 ++-- .../co/pokeapi/pokekotlin/test/BulkTest.kt | 4 +- .../pokeapi/pokekotlin/test/LocalPokeApi.kt | 14 +- .../pokekotlin/test/model/BerryTest.kt | 18 +- .../pokekotlin/test/model/ContestTest.kt | 14 +- .../pokekotlin/test/model/EncounterTest.kt | 12 +- .../pokekotlin/test/model/EvolutionTest.kt | 67 +++---- .../pokeapi/pokekotlin/test/model/GameTest.kt | 43 ++--- .../pokeapi/pokekotlin/test/model/ItemTest.kt | 48 +++-- .../pokekotlin/test/model/LocationTest.kt | 39 ++-- .../pokekotlin/test/model/MachineTest.kt | 8 +- .../pokeapi/pokekotlin/test/model/MoveTest.kt | 71 ++++---- .../pokekotlin/test/model/PokemonTest.kt | 172 +++++++++--------- .../pokekotlin/test/model/ResourceListTest.kt | 12 +- .../pokekotlin/test/model/UtilityTest.kt | 4 +- 31 files changed, 524 insertions(+), 609 deletions(-) delete mode 100644 src/commonMain/kotlin/co/pokeapi/pokekotlin/internal/NamedApiResourceSerializer.kt create mode 100644 src/commonMain/kotlin/co/pokeapi/pokekotlin/model/base.kt 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 182ac0e6..c09c6fae 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,8 +21,8 @@ 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.Handle import co.pokeapi.pokekotlin.model.PokemonVariety -import co.pokeapi.pokekotlin.model.ResourceHandle import coil3.compose.AsyncImage import kotlinx.coroutines.launch import kotlinx.coroutines.withContext @@ -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, PokemonListItemStatus>() + val details = mutableStateMapOf, PokemonListItemStatus>() init { loadPokemonList() @@ -65,7 +65,7 @@ class PokemonListScreenViewModel(private val api: PokeApi) : ViewModel() { } } - fun loadPokemonDetails(pokemon: ResourceHandle) { + fun loadPokemonDetails(pokemon: Handle) { if (details[pokemon] == LoadingStatus.Loading || details[pokemon] is LoadingStatus.Success) return // Already loading or loaded @@ -129,7 +129,7 @@ fun PokemonListScreen(viewModel: PokemonListScreenViewModel = koinViewModel()) { @Composable private fun PokemonListItem( viewModel: PokemonListScreenViewModel, - item: ResourceHandle.Named, + item: Handle.Named, ) { LaunchedEffect(item) { viewModel.loadPokemonDetails(item) } diff --git a/src/commonMain/kotlin/co/pokeapi/pokekotlin/PokeApi.kt b/src/commonMain/kotlin/co/pokeapi/pokekotlin/PokeApi.kt index a8c412d3..e0cfa223 100644 --- a/src/commonMain/kotlin/co/pokeapi/pokekotlin/PokeApi.kt +++ b/src/commonMain/kotlin/co/pokeapi/pokekotlin/PokeApi.kt @@ -65,7 +65,7 @@ constructor( private suspend inline fun HttpClient.getNamedResourceList( offset: Int, limit: Int, - ): PaginatedResourceList.Named { + ): PaginatedList.Named { return get("/api/v2/${ResourceEndpoint.forModel()}") { parameter("offset", offset) parameter("limit", limit) @@ -76,7 +76,7 @@ constructor( private suspend inline fun HttpClient.getResourceList( offset: Int, limit: Int, - ): PaginatedResourceList.Unnamed { + ): PaginatedList.Unnamed { return get("/api/v2/${ResourceEndpoint.forModel()}") { parameter("offset", offset) parameter("limit", limit) @@ -90,8 +90,7 @@ constructor( @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun ResourceHandle.get(): T = - client.get(url).body(TypeInfo(model)) + public suspend fun Handle.get(): T = client.get(url).body(TypeInfo(model)) // region Resource Lists @@ -101,7 +100,7 @@ constructor( @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getBerryList(offset: Int, limit: Int): PaginatedResourceList.Named = + public suspend fun getBerryList(offset: Int, limit: Int): PaginatedList.Named = client.getNamedResourceList(offset, limit) @JvmBlocking @@ -111,16 +110,14 @@ constructor( public suspend fun getBerryFirmnessList( offset: Int, limit: Int, - ): PaginatedResourceList.Named = client.getNamedResourceList(offset, limit) + ): PaginatedList.Named = client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getBerryFlavorList( - offset: Int, - limit: Int, - ): PaginatedResourceList.Named = client.getNamedResourceList(offset, limit) + public suspend fun getBerryFlavorList(offset: Int, limit: Int): PaginatedList.Named = + client.getNamedResourceList(offset, limit) // endregion Berries @@ -130,10 +127,8 @@ constructor( @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getContestTypeList( - offset: Int, - limit: Int, - ): PaginatedResourceList.Named = client.getNamedResourceList(offset, limit) + public suspend fun getContestTypeList(offset: Int, limit: Int): PaginatedList.Named = + client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @@ -142,7 +137,7 @@ constructor( public suspend fun getContestEffectList( offset: Int, limit: Int, - ): PaginatedResourceList.Unnamed = client.getResourceList(offset, limit) + ): PaginatedList.Unnamed = client.getResourceList(offset, limit) @JvmBlocking @JvmAsync @@ -151,7 +146,7 @@ constructor( public suspend fun getSuperContestEffectList( offset: Int, limit: Int, - ): PaginatedResourceList.Unnamed = client.getResourceList(offset, limit) + ): PaginatedList.Unnamed = client.getResourceList(offset, limit) // endregion Contests @@ -164,7 +159,7 @@ constructor( public suspend fun getEncounterMethodList( offset: Int, limit: Int, - ): PaginatedResourceList.Named = client.getNamedResourceList(offset, limit) + ): PaginatedList.Named = client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @@ -173,7 +168,7 @@ constructor( public suspend fun getEncounterConditionList( offset: Int, limit: Int, - ): PaginatedResourceList.Named = client.getNamedResourceList(offset, limit) + ): PaginatedList.Named = client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @@ -182,8 +177,7 @@ constructor( public suspend fun getEncounterConditionValueList( offset: Int, limit: Int, - ): PaginatedResourceList.Named = - client.getNamedResourceList(offset, limit) + ): PaginatedList.Named = client.getNamedResourceList(offset, limit) // endregion @@ -196,7 +190,7 @@ constructor( public suspend fun getEvolutionChainList( offset: Int, limit: Int, - ): PaginatedResourceList.Unnamed = client.getResourceList(offset, limit) + ): PaginatedList.Unnamed = client.getResourceList(offset, limit) @JvmBlocking @JvmAsync @@ -205,7 +199,7 @@ constructor( public suspend fun getEvolutionTriggerList( offset: Int, limit: Int, - ): PaginatedResourceList.Named = client.getNamedResourceList(offset, limit) + ): PaginatedList.Named = client.getNamedResourceList(offset, limit) // endregion @@ -215,23 +209,21 @@ constructor( @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getGenerationList( - offset: Int, - limit: Int, - ): PaginatedResourceList.Named = client.getNamedResourceList(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): PaginatedResourceList.Named = + 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): PaginatedResourceList.Named = + public suspend fun getVersionList(offset: Int, limit: Int): PaginatedList.Named = client.getNamedResourceList(offset, limit) @JvmBlocking @@ -241,7 +233,7 @@ constructor( public suspend fun getVersionGroupList( offset: Int, limit: Int, - ): PaginatedResourceList.Named = client.getNamedResourceList(offset, limit) + ): PaginatedList.Named = client.getNamedResourceList(offset, limit) // endregion @@ -251,7 +243,7 @@ constructor( @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getItemList(offset: Int, limit: Int): PaginatedResourceList.Named = + public suspend fun getItemList(offset: Int, limit: Int): PaginatedList.Named = client.getNamedResourceList(offset, limit) @JvmBlocking @@ -261,7 +253,7 @@ constructor( public suspend fun getItemAttributeList( offset: Int, limit: Int, - ): PaginatedResourceList.Named = client.getNamedResourceList(offset, limit) + ): PaginatedList.Named = client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @@ -270,7 +262,7 @@ constructor( public suspend fun getItemCategoryList( offset: Int, limit: Int, - ): PaginatedResourceList.Named = client.getNamedResourceList(offset, limit) + ): PaginatedList.Named = client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @@ -279,16 +271,14 @@ constructor( public suspend fun getItemFlingEffectList( offset: Int, limit: Int, - ): PaginatedResourceList.Named = client.getNamedResourceList(offset, limit) + ): PaginatedList.Named = client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getItemPocketList( - offset: Int, - limit: Int, - ): PaginatedResourceList.Named = client.getNamedResourceList(offset, limit) + public suspend fun getItemPocketList(offset: Int, limit: Int): PaginatedList.Named = + client.getNamedResourceList(offset, limit) // endregion @@ -298,17 +288,15 @@ constructor( @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getMoveList(offset: Int, limit: Int): PaginatedResourceList.Named = + 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, - ): PaginatedResourceList.Named = client.getNamedResourceList(offset, limit) + public suspend fun getMoveAilmentList(offset: Int, limit: Int): PaginatedList.Named = + client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @@ -317,7 +305,7 @@ constructor( public suspend fun getMoveBattleStyleList( offset: Int, limit: Int, - ): PaginatedResourceList.Named = client.getNamedResourceList(offset, limit) + ): PaginatedList.Named = client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @@ -326,7 +314,7 @@ constructor( public suspend fun getMoveCategoryList( offset: Int, limit: Int, - ): PaginatedResourceList.Named = client.getNamedResourceList(offset, limit) + ): PaginatedList.Named = client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @@ -335,7 +323,7 @@ constructor( public suspend fun getMoveDamageClassList( offset: Int, limit: Int, - ): PaginatedResourceList.Named = client.getNamedResourceList(offset, limit) + ): PaginatedList.Named = client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @@ -344,16 +332,14 @@ constructor( public suspend fun getMoveLearnMethodList( offset: Int, limit: Int, - ): PaginatedResourceList.Named = client.getNamedResourceList(offset, limit) + ): PaginatedList.Named = client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getMoveTargetList( - offset: Int, - limit: Int, - ): PaginatedResourceList.Named = client.getNamedResourceList(offset, limit) + public suspend fun getMoveTargetList(offset: Int, limit: Int): PaginatedList.Named = + client.getNamedResourceList(offset, limit) // endregion @@ -363,10 +349,8 @@ constructor( @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getLocationList( - offset: Int, - limit: Int, - ): PaginatedResourceList.Named = client.getNamedResourceList(offset, limit) + public suspend fun getLocationList(offset: Int, limit: Int): PaginatedList.Named = + client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @@ -375,22 +359,20 @@ constructor( public suspend fun getLocationAreaList( offset: Int, limit: Int, - ): PaginatedResourceList.Named = client.getNamedResourceList(offset, limit) + ): PaginatedList.Named = client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getPalParkAreaList( - offset: Int, - limit: Int, - ): PaginatedResourceList.Named = client.getNamedResourceList(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): PaginatedResourceList.Named = + public suspend fun getRegionList(offset: Int, limit: Int): PaginatedList.Named = client.getNamedResourceList(offset, limit) // endregion @@ -401,10 +383,8 @@ constructor( @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getMachineList( - offset: Int, - limit: Int, - ): PaginatedResourceList.Unnamed = client.getResourceList(offset, limit) + public suspend fun getMachineList(offset: Int, limit: Int): PaginatedList.Unnamed = + client.getResourceList(offset, limit) // endregion @@ -414,7 +394,7 @@ constructor( @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getAbilityList(offset: Int, limit: Int): PaginatedResourceList.Named = + public suspend fun getAbilityList(offset: Int, limit: Int): PaginatedList.Named = client.getNamedResourceList(offset, limit) @JvmBlocking @@ -424,38 +404,34 @@ constructor( public suspend fun getCharacteristicList( offset: Int, limit: Int, - ): PaginatedResourceList.Unnamed = client.getResourceList(offset, limit) + ): PaginatedList.Unnamed = client.getResourceList(offset, limit) @JvmBlocking @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getEggGroupList( - offset: Int, - limit: Int, - ): PaginatedResourceList.Named = client.getNamedResourceList(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): PaginatedResourceList.Named = + 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, - ): PaginatedResourceList.Named = client.getNamedResourceList(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): PaginatedResourceList.Named = + public suspend fun getNatureList(offset: Int, limit: Int): PaginatedList.Named = client.getNamedResourceList(offset, limit) @JvmBlocking @@ -465,7 +441,7 @@ constructor( public suspend fun getPokeathlonStatList( offset: Int, limit: Int, - ): PaginatedResourceList.Named = client.getNamedResourceList(offset, limit) + ): PaginatedList.Named = client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @@ -474,7 +450,7 @@ constructor( public suspend fun getPokemonVarietyList( offset: Int, limit: Int, - ): PaginatedResourceList.Named = client.getNamedResourceList(offset, limit) + ): PaginatedList.Named = client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @@ -483,16 +459,14 @@ constructor( public suspend fun getPokemonColorList( offset: Int, limit: Int, - ): PaginatedResourceList.Named = client.getNamedResourceList(offset, limit) + ): PaginatedList.Named = client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getPokemonFormList( - offset: Int, - limit: Int, - ): PaginatedResourceList.Named = client.getNamedResourceList(offset, limit) + public suspend fun getPokemonFormList(offset: Int, limit: Int): PaginatedList.Named = + client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @@ -501,7 +475,7 @@ constructor( public suspend fun getPokemonHabitatList( offset: Int, limit: Int, - ): PaginatedResourceList.Named = client.getNamedResourceList(offset, limit) + ): PaginatedList.Named = client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @@ -510,7 +484,7 @@ constructor( public suspend fun getPokemonShapeList( offset: Int, limit: Int, - ): PaginatedResourceList.Named = client.getNamedResourceList(offset, limit) + ): PaginatedList.Named = client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @@ -519,20 +493,20 @@ constructor( public suspend fun getPokemonSpeciesList( offset: Int, limit: Int, - ): PaginatedResourceList.Named = client.getNamedResourceList(offset, limit) + ): PaginatedList.Named = client.getNamedResourceList(offset, limit) @JvmBlocking @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getStatList(offset: Int, limit: Int): PaginatedResourceList.Named = + 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): PaginatedResourceList.Named = + public suspend fun getTypeList(offset: Int, limit: Int): PaginatedList.Named = client.getNamedResourceList(offset, limit) // endregion @@ -543,10 +517,8 @@ constructor( @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun getLanguageList( - offset: Int, - limit: Int, - ): PaginatedResourceList.Named = client.getNamedResourceList(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 ad611243..4e0ad73b 100644 --- a/src/commonMain/kotlin/co/pokeapi/pokekotlin/internal/ApiResourceSerializer.kt +++ b/src/commonMain/kotlin/co/pokeapi/pokekotlin/internal/ApiResourceSerializer.kt @@ -1,16 +1,28 @@ package co.pokeapi.pokekotlin.internal import co.pokeapi.pokekotlin.model.EndpointModel -import co.pokeapi.pokekotlin.model.ResourceHandle +import co.pokeapi.pokekotlin.model.Handle import kotlinx.serialization.KSerializer import kotlinx.serialization.Serializable -internal class ApiResourceSerializer : - KSerializer> by DelegatingSerializer( - serialName = "co.pokeapi.pokekotlin.model.ResourceHandle.Unnamed", - delegate = Delegate.serializer(), - fromDelegate = { ResourceHandle.Unnamed(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(slug = it.name, url = it.url) }, + toDelegate = { Delegate(name = it.slug, url = it.url) }, + ) { + @Serializable internal data class Delegate(val name: String, val url: String) + } } 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 92763dca..00000000 --- a/src/commonMain/kotlin/co/pokeapi/pokekotlin/internal/NamedApiResourceSerializer.kt +++ /dev/null @@ -1,16 +0,0 @@ -package co.pokeapi.pokekotlin.internal - -import co.pokeapi.pokekotlin.model.EndpointModel -import co.pokeapi.pokekotlin.model.ResourceHandle -import kotlinx.serialization.KSerializer -import kotlinx.serialization.Serializable - -internal class NamedApiResourceSerializer : - KSerializer> by DelegatingSerializer( - serialName = "co.pokeapi.pokekotlin.model.ResourceHandle.Named", - delegate = Delegate.serializer(), - fromDelegate = { ResourceHandle.Named(slug = it.name, url = it.url) }, - toDelegate = { Delegate(name = it.slug, 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..737ae1b4 --- /dev/null +++ b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/base.kt @@ -0,0 +1,6 @@ +package co.pokeapi.pokekotlin.model + +import co.pokeapi.pokekotlin.internal.JsOnlyExport +import kotlinx.serialization.Serializable + +@JsOnlyExport @Serializable public sealed interface EndpointModel diff --git a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/berries.kt b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/berries.kt index 4621703c..d40cbf7c 100644 --- a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/berries.kt +++ b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/berries.kt @@ -35,10 +35,10 @@ public data class Berry( val size: Int, val smoothness: Int, val soilDryness: Int, - val firmness: ResourceHandle.Named, + val firmness: Handle.Named, val flavors: List, - val item: ResourceHandle.Named, - val naturalGiftType: ResourceHandle.Named, + val item: Handle.Named, + val naturalGiftType: Handle.Named, ) : EndpointModel /** @@ -49,7 +49,7 @@ public data class Berry( */ @Serializable @JsOnlyExport -public data class BerryFlavorMap(val potency: Int, val flavor: ResourceHandle.Named) +public data class BerryFlavorMap(val potency: Int, val flavor: Handle.Named) /** * The firmness of berries, used in making Pokéblocks or Poffins. See: @@ -65,7 +65,7 @@ public data class BerryFlavorMap(val potency: Int, val flavor: ResourceHandle.Na public data class BerryFirmness( val id: Int, val name: String, - val berries: List>, + val berries: List>, val names: List, ) : EndpointModel @@ -85,7 +85,7 @@ public data class BerryFlavor( val id: Int, val name: String, val berries: List, - val contestType: ResourceHandle.Named, + val contestType: Handle.Named, val names: List, ) : EndpointModel @@ -97,4 +97,4 @@ public data class BerryFlavor( */ @Serializable @JsOnlyExport -public data class FlavorBerryMap(val potency: Int, val berry: ResourceHandle.Named) +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 1f1c4ee7..885bcfa3 100644 --- a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/contests.kt +++ b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/contests.kt @@ -17,7 +17,7 @@ import kotlinx.serialization.Serializable public data class ContestType( val id: Int, val name: String, - val berryFlavor: ResourceHandle.Named, + val berryFlavor: Handle.Named, val names: List, ) : EndpointModel @@ -34,7 +34,7 @@ public data class ContestType( public data class ContestName( val name: String, val color: String, - val language: ResourceHandle.Named, + val language: Handle.Named, ) /** @@ -73,5 +73,5 @@ public data class SuperContestEffect( val id: Int, val appeal: Int, val flavorTextEntries: List, - val moves: List>, + val moves: List>, ) : EndpointModel diff --git a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/encounters.kt b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/encounters.kt index bfae6b06..e7a6d451 100644 --- a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/encounters.kt +++ b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/encounters.kt @@ -36,7 +36,7 @@ public data class EncounterCondition( val id: Int, val name: String, val names: List, - val values: List>, + val values: List>, ) : EndpointModel /** @@ -54,6 +54,6 @@ public data class EncounterCondition( public data class EncounterConditionValue( val id: Int, val name: String, - val condition: ResourceHandle.Named, + val condition: Handle.Named, val names: List, ) : EndpointModel diff --git a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/evolution.kt b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/evolution.kt index da0ed08f..a1a7ba42 100644 --- a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/evolution.kt +++ b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/evolution.kt @@ -18,7 +18,7 @@ import kotlinx.serialization.Serializable @JsOnlyExport public data class EvolutionChain( val id: Int, - val babyTriggerItem: ResourceHandle.Named?, + val babyTriggerItem: Handle.Named?, val chain: ChainLink, ) : EndpointModel @@ -36,7 +36,7 @@ public data class EvolutionChain( @JsOnlyExport public data class ChainLink( val isBaby: Boolean, - val species: ResourceHandle.Named, + val species: Handle.Named, val evolutionDetails: List, val evolvesTo: List, ) @@ -71,22 +71,22 @@ public data class ChainLink( @Serializable @JsOnlyExport public data class EvolutionDetail( - val trigger: ResourceHandle.Named, - val item: ResourceHandle.Named? = null, + val trigger: Handle.Named, + val item: Handle.Named? = null, val gender: Int? = null, - val heldItem: ResourceHandle.Named? = null, - val knownMove: ResourceHandle.Named? = null, - val knownMoveType: ResourceHandle.Named? = null, - val location: ResourceHandle.Named? = 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: ResourceHandle.Named? = null, - val partyType: ResourceHandle.Named? = null, + val partySpecies: Handle.Named? = null, + val partyType: Handle.Named? = null, val relativePhysicalStats: Int? = null, val timeOfDay: String = "", - val tradeSpecies: ResourceHandle.Named? = null, + val tradeSpecies: Handle.Named? = null, val needsOverworldRain: Boolean = false, val turnUpsideDown: Boolean = false, ) @@ -106,5 +106,5 @@ public data class EvolutionTrigger( val id: Int, val name: String, val names: List, - val pokemonSpecies: List>, + val pokemonSpecies: List>, ) : EndpointModel diff --git a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/games.kt b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/games.kt index 67171805..8dc47a1d 100644 --- a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/games.kt +++ b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/games.kt @@ -23,13 +23,13 @@ import kotlinx.serialization.Serializable public data class Generation( val id: Int, val name: String, - val abilities: List>, + val abilities: List>, val names: List, - val mainRegion: ResourceHandle.Named, - 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>, ) : EndpointModel /** @@ -56,8 +56,8 @@ public data class Pokedex( val descriptions: List, val names: List, val pokemonEntries: List, - val region: ResourceHandle.Named?, - val versionGroups: List>, + val region: Handle.Named?, + val versionGroups: List>, ) : EndpointModel /** @@ -70,7 +70,7 @@ public data class Pokedex( @JsOnlyExport public data class PokemonEntry( val entryNumber: Int, - val pokemonSpecies: ResourceHandle.Named, + val pokemonSpecies: Handle.Named, ) /** @@ -87,7 +87,7 @@ public data class Version( val id: Int, val name: String, val names: List, - val versionGroup: ResourceHandle.Named, + val versionGroup: Handle.Named, ) : EndpointModel /** @@ -110,9 +110,9 @@ public data class VersionGroup( val id: Int, val name: String, val order: Int, - val generation: ResourceHandle.Named, - 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>, ) : EndpointModel diff --git a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/items.kt b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/items.kt index 5dc2387c..4991112e 100644 --- a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/items.kt +++ b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/items.kt @@ -31,15 +31,15 @@ public data class Item( val name: String, val cost: Int, val flingPower: Int?, - val flingEffect: ResourceHandle.Named?, - val attributes: List>, - val category: ResourceHandle.Named, + 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: ResourceHandle.Unnamed?, + val babyTriggerFor: Handle.Unnamed?, val sprites: ItemSprites, val machines: List, ) : EndpointModel @@ -61,7 +61,7 @@ public data class Item( @Serializable @JsOnlyExport public data class ItemHolderPokemon( - val pokemon: ResourceHandle.Named, + val pokemon: Handle.Named, val versionDetails: List, ) @@ -76,7 +76,7 @@ public data class ItemHolderPokemon( @JsOnlyExport public data class ItemHolderPokemonVersionDetail( val rarity: Int, - val version: ResourceHandle.Named, + val version: Handle.Named, ) /** @@ -94,7 +94,7 @@ public data class ItemHolderPokemonVersionDetail( public data class ItemAttribute( val id: Int, val name: String, - val items: List>, + val items: List>, val names: List, val descriptions: List, ) : EndpointModel @@ -114,9 +114,9 @@ public data class ItemAttribute( public data class ItemCategory( val id: Int, val name: String, - val items: List>, + val items: List>, val names: List, - val pocket: ResourceHandle.Named, + val pocket: Handle.Named, ) : EndpointModel /** @@ -134,7 +134,7 @@ public data class ItemFlingEffect( val id: Int, val name: String, val effectEntries: List, - val items: List>, + val items: List>, ) : EndpointModel /** @@ -151,6 +151,6 @@ public data class ItemFlingEffect( public data class ItemPocket( val id: Int, val name: String, - val categories: List>, + val categories: List>, val names: List, ) : EndpointModel diff --git a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/locations.kt b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/locations.kt index d1511418..e5cbb4e5 100644 --- a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/locations.kt +++ b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/locations.kt @@ -19,10 +19,10 @@ import kotlinx.serialization.Serializable public data class Location( val id: Int, val name: String, - val region: ResourceHandle.Named?, + val region: Handle.Named?, val names: List, val gameIndices: List, - val areas: List>, + val areas: List>, ) : EndpointModel /** @@ -46,7 +46,7 @@ public data class LocationArea( val name: String, val gameIndex: Int, val encounterMethodRates: List, - val location: ResourceHandle.Named, + val location: Handle.Named, val names: List, val pokemonEncounters: List, ) : EndpointModel @@ -61,7 +61,7 @@ public data class LocationArea( @Serializable @JsOnlyExport public data class EncounterMethodRate( - val encounterMethod: ResourceHandle.Named, + val encounterMethod: Handle.Named, val versionDetails: List, ) @@ -76,7 +76,7 @@ public data class EncounterMethodRate( @JsOnlyExport public data class EncounterMethodRateVersionDetail( val rate: Int, - val version: ResourceHandle.Named, + val version: Handle.Named, ) /** @@ -89,7 +89,7 @@ public data class EncounterMethodRateVersionDetail( @Serializable @JsOnlyExport public data class PokemonEncounter( - val pokemon: ResourceHandle.Named, + val pokemon: Handle.Named, val versionDetails: List, ) @@ -124,7 +124,7 @@ public data class PalParkArea( public data class PalParkEncounterSpecies( val baseScore: Int, val rate: Int, - val pokemonSpecies: ResourceHandle.Named, + val pokemonSpecies: Handle.Named, ) /** @@ -145,9 +145,9 @@ public data class PalParkEncounterSpecies( public data class Region( val id: Int, val name: String, - val locations: List>, - val mainGeneration: ResourceHandle.Named?, + val locations: List>, + val mainGeneration: Handle.Named?, val names: List, - val pokedexes: List>, - val versionGroups: List>, + val pokedexes: List>, + val versionGroups: List>, ) : EndpointModel diff --git a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/machines.kt b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/machines.kt index 9b1e3cfc..8f9be09c 100644 --- a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/machines.kt +++ b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/machines.kt @@ -17,7 +17,7 @@ import kotlinx.serialization.Serializable @JsOnlyExport public data class Machine( val id: Int, - val item: ResourceHandle.Named, - val move: ResourceHandle.Named, - val versionGroup: ResourceHandle.Named, + val item: Handle.Named, + val move: Handle.Named, + val versionGroup: Handle.Named, ) : EndpointModel diff --git a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/moves.kt b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/moves.kt index 303fc45f..8a73d6dd 100644 --- a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/moves.kt +++ b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/moves.kt @@ -48,20 +48,20 @@ public data class Move( val priority: Int, val power: Int?, val contestCombos: ContestComboSets?, - val contestType: ResourceHandle.Named?, - val contestEffect: ResourceHandle.Unnamed?, - val superContestEffect: ResourceHandle.Unnamed?, - val damageClass: ResourceHandle.Named, + val contestType: Handle.Named?, + val contestEffect: Handle.Unnamed?, + val superContestEffect: Handle.Unnamed?, + val damageClass: Handle.Named, val effectEntries: List, val effectChanges: List, - val generation: ResourceHandle.Named, - val learnedByPokemon: List>, + val generation: Handle.Named, + val learnedByPokemon: List>, val meta: MoveMetaData?, val names: List, val pastValues: List, val statChanges: List, - val target: ResourceHandle.Named, - val type: ResourceHandle.Named, + val target: Handle.Named, + val type: Handle.Named, val machines: List, val flavorTextEntries: List, ) : EndpointModel @@ -90,8 +90,8 @@ public data class ContestComboSets( @Serializable @JsOnlyExport public data class ContestComboDetail( - val useBefore: List>?, - val useAfter: List>?, + val useBefore: List>?, + val useAfter: List>?, ) /** @@ -115,8 +115,8 @@ public data class ContestComboDetail( @Serializable @JsOnlyExport public data class MoveMetaData( - val ailment: ResourceHandle.Named, - val category: ResourceHandle.Named, + val ailment: Handle.Named, + val category: Handle.Named, val minHits: Int?, val maxHits: Int?, val minTurns: Int?, @@ -137,7 +137,7 @@ public data class MoveMetaData( */ @Serializable @JsOnlyExport -public data class MoveStatChange(val change: Int, val stat: ResourceHandle.Named) +public data class MoveStatChange(val change: Int, val stat: Handle.Named) /** * The stat values of a move in previous versions of the games. See: @@ -159,8 +159,8 @@ public data class PastMoveStatValues( val power: Int?, val pp: Int?, val effectEntries: List, - val type: ResourceHandle.Named?, - val versionGroup: ResourceHandle.Named, + val type: Handle.Named?, + val versionGroup: Handle.Named, ) /** @@ -177,7 +177,7 @@ public data class PastMoveStatValues( public data class MoveAilment( val id: Int, val name: String, - val moves: List>, + val moves: List>, val names: List, ) : EndpointModel @@ -208,7 +208,7 @@ public data class MoveBattleStyle(val id: Int, val name: String, val names: List public data class MoveCategory( val id: Int, val name: String, - val moves: List>, + val moves: List>, val descriptions: List, ) : EndpointModel @@ -228,7 +228,7 @@ public data class MoveDamageClass( val id: Int, val name: String, val descriptions: List, - val moves: List>, + val moves: List>, val names: List, ) : EndpointModel @@ -248,7 +248,7 @@ public data class MoveLearnMethod( val name: String, val descriptions: List, val names: List, - val versionGroups: List>, + val versionGroups: List>, ) : EndpointModel /** @@ -267,7 +267,7 @@ public data class MoveTarget( val id: Int, val name: String, val descriptions: List, - val moves: List>, + val moves: List>, val names: List, ) : EndpointModel @@ -283,6 +283,6 @@ public data class MoveTarget( @JsOnlyExport public data class MoveFlavorText( val flavorText: String, - val language: ResourceHandle.Named, - val versionGroup: ResourceHandle.Named, + 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 3f1d4d68..216d4f1c 100644 --- a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/pokemon.kt +++ b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/pokemon.kt @@ -25,7 +25,7 @@ public data class Ability( val id: Int, val name: String, val isMainSeries: Boolean, - val generation: ResourceHandle.Named, + val generation: Handle.Named, val names: List, val effectEntries: List, val effectChanges: List, @@ -44,7 +44,7 @@ public data class Ability( @JsOnlyExport public data class AbilityEffectChange( val effectEntries: List, - val versionGroup: ResourceHandle.Named, + val versionGroup: Handle.Named, ) /** @@ -59,8 +59,8 @@ public data class AbilityEffectChange( @JsOnlyExport public data class AbilityFlavorText( val flavorText: String, - val language: ResourceHandle.Named, - val versionGroup: ResourceHandle.Named, + val language: Handle.Named, + val versionGroup: Handle.Named, ) /** @@ -75,7 +75,7 @@ public data class AbilityFlavorText( public data class AbilityPokemon( val isHidden: Boolean, val slot: Int, - val pokemon: ResourceHandle.Named, + val pokemon: Handle.Named, ) /** @@ -111,7 +111,7 @@ public data class EggGroup( val id: Int, val name: String, val names: List, - val pokemonSpecies: List>, + val pokemonSpecies: List>, ) : EndpointModel /** @@ -131,7 +131,7 @@ public data class Gender( val id: Int, val name: String, val pokemonSpeciesDetails: List, - val requiredForEvolution: List>, + val requiredForEvolution: List>, ) : EndpointModel /** @@ -144,7 +144,7 @@ public data class Gender( @JsOnlyExport public data class PokemonSpeciesGender( val rate: Int, - val pokemonSpecies: ResourceHandle.Named, + val pokemonSpecies: Handle.Named, ) /** @@ -166,7 +166,7 @@ public data class GrowthRate( val formula: String, val descriptions: List, val levels: List, - val pokemonSpecies: List>, + val pokemonSpecies: List>, ) : EndpointModel /** @@ -199,10 +199,10 @@ public data class GrowthRateExperienceLevel(val level: Int, val experience: Int) public data class Nature( val id: Int, val name: String, - val decreasedStat: ResourceHandle.Named?, - val increasedStat: ResourceHandle.Named?, - val hatesFlavor: ResourceHandle.Named?, - val likesFlavor: ResourceHandle.Named?, + 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, @@ -218,7 +218,7 @@ public data class Nature( @JsOnlyExport public data class NatureStatChange( val maxChange: Int, - val pokeathlonStat: ResourceHandle.Named, + val pokeathlonStat: Handle.Named, ) /** @@ -234,7 +234,7 @@ public data class NatureStatChange( public data class MoveBattleStylePreference( val lowHpPreference: Int, val highHpPreference: Int, - val moveBattleStyle: ResourceHandle.Named, + val moveBattleStyle: Handle.Named, ) /** @@ -278,10 +278,7 @@ public data class NaturePokeathlonStatEffectSets( */ @Serializable @JsOnlyExport -public data class NaturePokeathlonStatEffect( - val maxChange: Int, - val nature: ResourceHandle.Named, -) +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 @@ -317,9 +314,9 @@ public data class PokemonVariety( val isDefault: Boolean, val order: Int, val weight: Int, - val species: ResourceHandle.Named, + val species: Handle.Named, val abilities: List, - val forms: List>, + val forms: List>, val gameIndices: List, val heldItems: List, val moves: List, @@ -508,7 +505,7 @@ public data class GameSprites( public data class PokemonAbility( val isHidden: Boolean, val slot: Int, - val ability: ResourceHandle.Named?, + val ability: Handle.Named?, ) /** @@ -521,7 +518,7 @@ public data class PokemonAbility( @Serializable @JsOnlyExport public data class PokemonHeldItem( - val item: ResourceHandle.Named, + val item: Handle.Named, val versionDetails: List, ) @@ -534,10 +531,7 @@ public data class PokemonHeldItem( */ @Serializable @JsOnlyExport -public data class PokemonHeldItemVersion( - val version: ResourceHandle.Named, - val rarity: Int, -) +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 @@ -548,7 +542,7 @@ public data class PokemonHeldItemVersion( @Serializable @JsOnlyExport public data class PokemonMove( - val move: ResourceHandle.Named, + val move: Handle.Named, val versionGroupDetails: List, ) @@ -564,8 +558,8 @@ public data class PokemonMove( @Serializable @JsOnlyExport public data class PokemonMoveVersion( - val moveLearnMethod: ResourceHandle.Named, - val versionGroup: ResourceHandle.Named, + val moveLearnMethod: Handle.Named, + val versionGroup: Handle.Named, val levelLearnedAt: Int, val order: Int?, ) @@ -579,11 +573,7 @@ public data class PokemonMoveVersion( */ @Serializable @JsOnlyExport -public data class PokemonStat( - val stat: ResourceHandle.Named, - val effort: Int, - val baseStat: Int, -) +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 @@ -593,7 +583,7 @@ public data class PokemonStat( */ @Serializable @JsOnlyExport -public data class PokemonType(val slot: Int, val type: ResourceHandle.Named) +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 @@ -604,7 +594,7 @@ public data class PokemonType(val slot: Int, val type: ResourceHandle.Named, + val generation: Handle.Named, val types: List, ) @@ -618,7 +608,7 @@ public data class PokemonPastType( @Serializable @JsOnlyExport public data class PokemonPastAbility( - val generation: ResourceHandle.Named, + val generation: Handle.Named, val abilities: List, ) @@ -640,7 +630,7 @@ public data class PokemonPastAbility( @Serializable @JsOnlyExport public data class LocationAreaEncounter( - val locationArea: ResourceHandle.Named, + val locationArea: Handle.Named, val versionDetails: List, ) @@ -659,7 +649,7 @@ public data class PokemonColor( val id: Int, val name: String, val names: List, - val pokemonSpecies: List>, + val pokemonSpecies: List>, ) : EndpointModel /** @@ -696,10 +686,10 @@ public data class PokemonForm( val isBattleOnly: Boolean, val isMega: Boolean, val formName: String, - val pokemon: ResourceHandle.Named, + val pokemon: Handle.Named, val types: List, val sprites: PokemonFormSprites, - val versionGroup: ResourceHandle.Named, + val versionGroup: Handle.Named, val names: List, val formNames: List, ) : EndpointModel @@ -744,7 +734,7 @@ public data class PokemonHabitat( val id: Int, val name: String, val names: List, - val pokemonSpecies: List>, + val pokemonSpecies: List>, ) : EndpointModel /** @@ -764,7 +754,7 @@ public data class PokemonShape( val name: String, val awesomeNames: List, val names: List, - val pokemonSpecies: List>, + val pokemonSpecies: List>, ) : EndpointModel /** @@ -775,10 +765,7 @@ public data class PokemonShape( */ @Serializable @JsOnlyExport -public data class AwesomeName( - val awesomeName: String, - val language: ResourceHandle.Named, -) +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 @@ -833,15 +820,15 @@ public data class PokemonSpecies( val hatchCounter: Int, val hasGenderDifferences: Boolean, val formsSwitchable: Boolean, - val growthRate: ResourceHandle.Named, + val growthRate: Handle.Named, val pokedexNumbers: List, - val eggGroups: List>, - val color: ResourceHandle.Named, - val shape: ResourceHandle.Named, - val evolvesFromSpecies: ResourceHandle.Named?, - val evolutionChain: ResourceHandle.Unnamed, - val habitat: ResourceHandle.Named?, - val generation: ResourceHandle.Named, + 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, @@ -861,8 +848,8 @@ public data class PokemonSpecies( @JsOnlyExport public data class PokemonSpeciesFlavorText( val flavorText: String, - val language: ResourceHandle.Named, - val version: ResourceHandle.Named, + val language: Handle.Named, + val version: Handle.Named, ) /** @@ -874,7 +861,7 @@ public data class PokemonSpeciesFlavorText( */ @Serializable @JsOnlyExport -public data class Genus(val genus: String, val language: ResourceHandle.Named) +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: @@ -885,10 +872,7 @@ public data class Genus(val genus: String, val language: ResourceHandle.Named, -) +public data class PokemonSpeciesDexEntry(val entryNumber: Int, val pokedex: Handle.Named) /** * Areas used for grouping Pokémon encounters in Pal Park. See: @@ -904,7 +888,7 @@ public data class PokemonSpeciesDexEntry( public data class PalParkEncounterArea( val baseScore: Int, val rate: Int, - val area: ResourceHandle.Named, + val area: Handle.Named, ) /** @@ -917,7 +901,7 @@ public data class PalParkEncounterArea( @JsOnlyExport public data class PokemonSpeciesVariety( val isDefault: Boolean, - @SerialName("pokemon") val variety: ResourceHandle.Named, + @SerialName("pokemon") val variety: Handle.Named, ) /** @@ -945,8 +929,8 @@ public data class Stat( val isBattleOnly: Boolean, val affectingMoves: MoveStatAffectSets, val affectingNatures: NatureStatAffectSets, - val characteristics: List>, - val moveDamageClass: ResourceHandle.Named?, + val characteristics: List>, + val moveDamageClass: Handle.Named?, val names: List, ) : EndpointModel @@ -972,7 +956,7 @@ public data class MoveStatAffectSets( */ @Serializable @JsOnlyExport -public data class MoveStatAffect(val change: Int, val move: ResourceHandle.Named) +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: @@ -984,8 +968,8 @@ public data class MoveStatAffect(val change: Int, val move: ResourceHandle.Named @Serializable @JsOnlyExport public data class NatureStatAffectSets( - val increase: List>, - val decrease: List>, + val increase: List>, + val decrease: List>, ) /** @@ -1015,11 +999,11 @@ public data class Type( val damageRelations: TypeRelations, val pastDamageRelations: List, val gameIndices: List, - val generation: ResourceHandle.Named, - val moveDamageClass: ResourceHandle.Named?, + val generation: Handle.Named, + val moveDamageClass: Handle.Named?, val names: List, val pokemon: List, - val moves: List>, + val moves: List>, val sprites: VersionTypeSprites, ) : EndpointModel @@ -1100,7 +1084,7 @@ public data class GenerationIxTypeSprites( */ @Serializable @JsOnlyExport -public data class TypePokemon(val slot: Int, val pokemon: ResourceHandle.Named) +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: @@ -1116,12 +1100,12 @@ public data class TypePokemon(val slot: Int, val pokemon: ResourceHandle.Named

>, - 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>, ) /** @@ -1134,6 +1118,6 @@ public data class TypeRelations( @Serializable @JsOnlyExport public data class TypePastDamageRelation( - val generation: ResourceHandle.Named, + 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 5319cb31..b4c97911 100644 --- a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/resource.kt +++ b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/resource.kt @@ -1,8 +1,7 @@ package co.pokeapi.pokekotlin.model -import co.pokeapi.pokekotlin.internal.ApiResourceSerializer +import co.pokeapi.pokekotlin.internal.HandleSerializers import co.pokeapi.pokekotlin.internal.JsOnlyExport -import co.pokeapi.pokekotlin.internal.NamedApiResourceSerializer import kotlin.reflect.KClass import kotlinx.serialization.Serializable @@ -69,15 +68,13 @@ internal enum class ResourceEndpoint(val model: KClass) { override fun toString() = name } -@JsOnlyExport @Serializable public sealed interface EndpointModel - /** * Represents a reference to a resource in the API by URL. * * @property id The identifier for the resource. */ @JsOnlyExport -public sealed class ResourceHandle { +public sealed class Handle { internal abstract val url: String internal val model: KClass by lazy { @@ -90,7 +87,7 @@ public sealed class ResourceHandle { urlRegex.find(url)?.groupValues[2]?.toInt() ?: throw IllegalArgumentException(url) } - internal companion object { + internal companion object Companion { private val urlRegex = "/([a-z\\-]+)/(-?[0-9]+)/$".toRegex() internal inline fun of(id: Int): Unnamed = @@ -104,10 +101,9 @@ public sealed class ResourceHandle { * 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 = ApiResourceSerializer::class) - @JsOnlyExport + @Serializable(with = HandleSerializers.Unnamed::class) public data class Unnamed internal constructor(override val url: String) : - ResourceHandle() + Handle() /** * Represents a reference to another resource in the API by name and URL. This matches the "named @@ -116,15 +112,14 @@ public sealed class ResourceHandle { * * @param slug The unique (name) of the referenced resource. */ - @Serializable(with = NamedApiResourceSerializer::class) - @JsOnlyExport + @Serializable(with = HandleSerializers.Named::class) public data class Named - internal constructor(override val url: String, val slug: String) : ResourceHandle() + internal constructor(override val url: String, val slug: 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-listspagination-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. @@ -132,29 +127,27 @@ public sealed class ResourceHandle { * @property results The list of returned resources in this page. */ @JsOnlyExport -public sealed class PaginatedResourceList { +public sealed class PaginatedList { public abstract val count: Int public abstract val next: String? public abstract val previous: String? - public abstract val results: List> + public abstract val results: List> @Serializable - @JsOnlyExport public data class Unnamed internal constructor( override val count: Int, override val next: String?, override val previous: String?, - override val results: List>, - ) : PaginatedResourceList() + override val results: List>, + ) : PaginatedList() @Serializable - @JsOnlyExport public data class Named internal constructor( override val count: Int, override val next: String?, override val previous: String?, - override val results: List>, - ) : PaginatedResourceList() + 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 d8692074..a8df376d 100644 --- a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/utility.kt +++ b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/utility.kt @@ -35,10 +35,7 @@ public data class Language( */ @Serializable @JsOnlyExport -public data class Description( - val description: String, - val language: ResourceHandle.Named, -) +public data class Description(val description: String, val language: Handle.Named) /** * The localized effect text for an API resource in a specific language. See: @@ -49,7 +46,7 @@ public data class Description( */ @Serializable @JsOnlyExport -public data class Effect(val effect: String, val language: ResourceHandle.Named) +public data class Effect(val effect: String, val language: Handle.Named) /** * Encounter details for a Pokémon in a specific location area. See: @@ -66,9 +63,9 @@ public data class Effect(val effect: String, val language: ResourceHandle.Named< public data class Encounter( val minLevel: Int, val maxLevel: Int, - val conditionValues: List>, + val conditionValues: List>, val chance: Int, - val method: ResourceHandle.Named, + val method: Handle.Named, ) /** @@ -80,7 +77,7 @@ public data class Encounter( */ @Serializable @JsOnlyExport -public data class FlavorText(val flavorText: String, val language: ResourceHandle.Named) +public data class FlavorText(val flavorText: String, val language: Handle.Named) /** * Generation game index for a resource. See: https://pokeapi.co/docs/v2#generationgameindex @@ -90,10 +87,7 @@ public data class FlavorText(val flavorText: String, val language: ResourceHandl */ @Serializable @JsOnlyExport -public data class GenerationGameIndex( - val gameIndex: Int, - val generation: ResourceHandle.Named, -) +public data class GenerationGameIndex(val gameIndex: Int, val generation: Handle.Named) /** * Machine and version group details. See: https://pokeapi.co/docs/v2#machineversiondetail @@ -104,8 +98,8 @@ public data class GenerationGameIndex( @Serializable @JsOnlyExport public data class MachineVersionDetail( - val machine: ResourceHandle.Unnamed, - val versionGroup: ResourceHandle.Named, + val machine: Handle.Unnamed, + val versionGroup: Handle.Named, ) /** @@ -117,7 +111,7 @@ public data class MachineVersionDetail( */ @Serializable @JsOnlyExport -public data class Name(val name: String, val language: ResourceHandle.Named) +public data class Name(val name: String, val language: Handle.Named) /** * The verbose effect text for an API resource in a specific language. See: @@ -132,7 +126,7 @@ public data class Name(val name: String, val language: ResourceHandle.Named, + val language: Handle.Named, ) /** @@ -146,7 +140,7 @@ public data class VerboseEffect( @Serializable @JsOnlyExport public data class VersionEncounterDetail( - val version: ResourceHandle.Named, + val version: Handle.Named, val maxChance: Int, val encounterDetails: List, ) @@ -159,7 +153,7 @@ public data class VersionEncounterDetail( */ @Serializable @JsOnlyExport -public data class VersionGameIndex(val gameIndex: Int, val version: ResourceHandle.Named) +public data class VersionGameIndex(val gameIndex: Int, val version: Handle.Named) /** * The localized flavor text for a version group. See: @@ -173,6 +167,6 @@ public data class VersionGameIndex(val gameIndex: Int, val version: ResourceHand @JsOnlyExport public data class VersionGroupFlavorText( val text: String, - val language: ResourceHandle.Named, - val versionGroup: ResourceHandle.Named, + 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 eabefb62..97120429 100644 --- a/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/BulkTest.kt +++ b/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/BulkTest.kt @@ -1,7 +1,7 @@ package co.pokeapi.pokekotlin.test import co.pokeapi.pokekotlin.model.EndpointModel -import co.pokeapi.pokekotlin.model.PaginatedResourceList +import co.pokeapi.pokekotlin.model.PaginatedList import co.pokeapi.pokekotlin.model.ResourceEndpoint import kotlin.math.min import kotlin.test.Test @@ -27,7 +27,7 @@ class BulkTest { } private suspend inline fun testEach( - getList: suspend (Int, Int) -> PaginatedResourceList, + getList: suspend (Int, Int) -> PaginatedList, getObject: suspend (Int) -> Any, ) { val list = getList(0, getList(0, 0).count).results diff --git a/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/LocalPokeApi.kt b/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/LocalPokeApi.kt index ea7428fb..87bd5420 100644 --- a/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/LocalPokeApi.kt +++ b/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/LocalPokeApi.kt @@ -3,7 +3,7 @@ package co.pokeapi.pokekotlin.test import co.pokeapi.pokekotlin.PokeApi import co.pokeapi.pokekotlin.internal.PokeApiJson import co.pokeapi.pokekotlin.model.EndpointModel -import co.pokeapi.pokekotlin.model.PaginatedResourceList +import co.pokeapi.pokekotlin.model.PaginatedList import io.ktor.client.plugins.api.* import io.ktor.client.statement.* import io.ktor.utils.io.* @@ -20,22 +20,18 @@ private val OffsetLimitPlugin = val endIndex = offset + limit when (requestedType.type) { - PaginatedResourceList.Unnamed::class -> { + PaginatedList.Unnamed::class -> { val fullList = - PokeApiJson.decodeFromSource>( - content.readBuffer() - ) + 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, ) } - PaginatedResourceList.Named::class -> { + PaginatedList.Named::class -> { val fullList = - PokeApiJson.decodeFromSource>( - content.readBuffer() - ) + 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 e83dd84a..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.ResourceHandle 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(ResourceHandle.of(3, "hard"), firmness) + assertEquals(Handle.of(3, "hard"), firmness) assertNotEquals(0, flavors.size) - assertEquals(ResourceHandle.of(159, "durin-berry"), item) - assertEquals(ResourceHandle.of(11, "water"), 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, ResourceHandle.of(4, "rawst")) - assertContains(names, Name(name = "Hard", language = ResourceHandle.of(9, "en"))) + assertContains(berries, Handle.of(4, "rawst")) + assertContains(names, Name(name = "Hard", language = Handle.of(9, "en"))) } } @@ -45,9 +45,9 @@ class BerryTest { LocalPokeApi.getBerryFlavor(3).apply { assertEquals(3, id) assertEquals("sweet", name) - assertEquals(ResourceHandle.of(3, "cute"), contestType) - assertContains(berries, FlavorBerryMap(potency = 10, berry = ResourceHandle.of(6, "leppa"))) - assertContains(names, Name(name = "Sweet", language = ResourceHandle.of(9, "en"))) + 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 9a97b7ff..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.ResourceHandle +import co.pokeapi.pokekotlin.model.Handle import co.pokeapi.pokekotlin.test.LocalPokeApi import kotlin.test.Test import kotlin.test.assertContains @@ -17,10 +17,10 @@ class ContestTest { LocalPokeApi.getContestType(4).apply { assertEquals(4, id) assertEquals("smart", name) - assertEquals(ResourceHandle.of(4, "bitter"), berryFlavor) + assertEquals(Handle.of(4, "bitter"), berryFlavor) assertContains( names, - ContestName(name = "Smart", color = "Green", language = ResourceHandle.of(9, "en")), + ContestName(name = "Smart", color = "Green", language = Handle.of(9, "en")), ) } } @@ -35,14 +35,14 @@ class ContestTest { effectEntries, Effect( effect = "If user appeals first this turn, earns six points instead of two.", - language = ResourceHandle.of(9, "en"), + language = Handle.of(9, "en"), ), ) assertContains( flavorTextEntries, FlavorText( flavorText = "The appeal works great if performed first.", - language = ResourceHandle.of(9, "en"), + language = Handle.of(9, "en"), ), ) } @@ -57,10 +57,10 @@ class ContestTest { flavorTextEntries, FlavorText( flavorText = "Makes the order of contestants random in the next turn.", - language = ResourceHandle.of(9, "en"), + language = Handle.of(9, "en"), ), ) - assertContains(moves, ResourceHandle.of(274, "assist")) + 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 57c12ea6..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.ResourceHandle import co.pokeapi.pokekotlin.test.LocalPokeApi import kotlin.test.Test import kotlin.test.assertContains @@ -16,7 +16,7 @@ class EncounterTest { assertEquals(5, id) assertEquals("surf", name) assertEquals(14, order) - assertContains(names, Name(name = "Surfing", language = ResourceHandle.of(9, "en"))) + assertContains(names, Name(name = "Surfing", language = Handle.of(9, "en"))) } } @@ -25,8 +25,8 @@ class EncounterTest { LocalPokeApi.getEncounterCondition(5).apply { assertEquals(5, id) assertEquals("radio", name) - assertContains(values, ResourceHandle.of(15, "radio-hoenn")) - assertContains(names, Name(name = "Radio", language = ResourceHandle.of(9, "en"))) + assertContains(values, Handle.of(15, "radio-hoenn")) + assertContains(names, Name(name = "Radio", language = Handle.of(9, "en"))) } } @@ -35,8 +35,8 @@ class EncounterTest { LocalPokeApi.getEncounterConditionValue(5).apply { assertEquals(5, id) assertEquals("time-night", name) - assertEquals(ResourceHandle.of(2, "time"), condition) - assertContains(names, Name(name = "At night", language = ResourceHandle.of(9, "en"))) + 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 9d398fd4..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.ResourceHandle import co.pokeapi.pokekotlin.test.LocalPokeApi import kotlin.test.Test import kotlin.test.assertContains @@ -21,26 +21,22 @@ class EvolutionTest { assertEquals( ChainLink( isBaby = false, - species = ResourceHandle.of(1, "bulbasaur"), + species = Handle.of(1, "bulbasaur"), evolutionDetails = emptyList(), evolvesTo = listOf( ChainLink( isBaby = false, - species = ResourceHandle.of(2, "ivysaur"), + species = Handle.of(2, "ivysaur"), evolutionDetails = - listOf( - EvolutionDetail(trigger = ResourceHandle.of(1, "level-up"), minLevel = 16) - ), + listOf(EvolutionDetail(trigger = Handle.of(1, "level-up"), minLevel = 16)), evolvesTo = listOf( ChainLink( isBaby = false, - species = ResourceHandle.of(3, "venusaur"), + species = Handle.of(3, "venusaur"), evolutionDetails = - listOf( - EvolutionDetail(trigger = ResourceHandle.of(1, "level-up"), minLevel = 32) - ), + listOf(EvolutionDetail(trigger = Handle.of(1, "level-up"), minLevel = 32)), evolvesTo = emptyList(), ) ), @@ -59,8 +55,8 @@ class EvolutionTest { chain.evolvesTo.find { it.evolutionDetails.contains( EvolutionDetail( - trigger = ResourceHandle.of(1, "level-up"), - heldItem = ResourceHandle.of(303, "razor-claw"), + trigger = Handle.of(1, "level-up"), + heldItem = Handle.of(303, "razor-claw"), timeOfDay = "night", ) ) @@ -75,10 +71,7 @@ class EvolutionTest { assertNotNull( chain.evolvesTo.find { it.evolutionDetails.contains( - EvolutionDetail( - trigger = ResourceHandle.of(3, "use-item"), - item = ResourceHandle.of(84, "water-stone"), - ) + EvolutionDetail(trigger = Handle.of(3, "use-item"), item = Handle.of(84, "water-stone")) ) } ) @@ -92,8 +85,8 @@ class EvolutionTest { chain.evolvesTo.find { it.evolutionDetails.contains( EvolutionDetail( - trigger = ResourceHandle.of(1, "level-up"), - location = ResourceHandle.of(8, "eterna-forest"), + trigger = Handle.of(1, "level-up"), + location = Handle.of(8, "eterna-forest"), ) ) } @@ -108,7 +101,7 @@ class EvolutionTest { chain.evolvesTo.find { it.evolutionDetails.contains( EvolutionDetail( - trigger = ResourceHandle.of(1, "level-up"), + trigger = Handle.of(1, "level-up"), minHappiness = 160, timeOfDay = "day", ) @@ -125,8 +118,8 @@ class EvolutionTest { chain.evolvesTo.find { it.evolutionDetails.contains( EvolutionDetail( - trigger = ResourceHandle.of(1, "level-up"), - knownMoveType = ResourceHandle.of(18, "fairy"), + trigger = Handle.of(1, "level-up"), + knownMoveType = Handle.of(18, "fairy"), minAffection = 2, ) ) @@ -141,8 +134,8 @@ class EvolutionTest { assertContains( chain.evolvesTo[0].evolvesTo[0].evolutionDetails, EvolutionDetail( - trigger = ResourceHandle.of(1, "level-up"), - knownMove = ResourceHandle.of(246, "ancient-power"), + trigger = Handle.of(1, "level-up"), + knownMove = Handle.of(246, "ancient-power"), ), ) } @@ -154,7 +147,7 @@ class EvolutionTest { assertNotNull( chain.evolvesTo.find { it.evolutionDetails.contains( - EvolutionDetail(trigger = ResourceHandle.of(1, "level-up"), gender = 1, minLevel = 20) + EvolutionDetail(trigger = Handle.of(1, "level-up"), gender = 1, minLevel = 20) ) } ) @@ -167,7 +160,7 @@ class EvolutionTest { assertNotNull( chain.evolvesTo.find { it.evolutionDetails.contains( - EvolutionDetail(trigger = ResourceHandle.of(1, "level-up"), minBeauty = 171) + EvolutionDetail(trigger = Handle.of(1, "level-up"), minBeauty = 171) ) } ) @@ -181,9 +174,9 @@ class EvolutionTest { chain.evolvesTo.find { it.evolutionDetails.contains( EvolutionDetail( - trigger = ResourceHandle.of(1, "level-up"), + trigger = Handle.of(1, "level-up"), minLevel = 32, - partyType = ResourceHandle.of(17, "dark"), + partyType = Handle.of(17, "dark"), ) ) } @@ -198,7 +191,7 @@ class EvolutionTest { chain.evolvesTo.find { it.evolutionDetails.contains( EvolutionDetail( - trigger = ResourceHandle.of(1, "level-up"), + trigger = Handle.of(1, "level-up"), minLevel = 20, relativePhysicalStats = 1, ) @@ -215,7 +208,7 @@ class EvolutionTest { chain.evolvesTo[0].evolvesTo.find { it.evolutionDetails.contains( EvolutionDetail( - trigger = ResourceHandle.of(1, "level-up"), + trigger = Handle.of(1, "level-up"), minLevel = 50, needsOverworldRain = true, ) @@ -232,7 +225,7 @@ class EvolutionTest { chain.evolvesTo.find { it.evolutionDetails.contains( EvolutionDetail( - trigger = ResourceHandle.of(1, "level-up"), + trigger = Handle.of(1, "level-up"), minLevel = 30, turnUpsideDown = true, ) @@ -249,8 +242,8 @@ class EvolutionTest { chain.evolvesTo.find { it.evolutionDetails.contains( EvolutionDetail( - trigger = ResourceHandle.of(1, "level-up"), - partySpecies = ResourceHandle.of(223, "remoraid"), + trigger = Handle.of(1, "level-up"), + partySpecies = Handle.of(223, "remoraid"), ) ) } @@ -265,8 +258,8 @@ class EvolutionTest { chain.evolvesTo.find { it.evolutionDetails.contains( EvolutionDetail( - trigger = ResourceHandle.of(2, "trade"), - tradeSpecies = ResourceHandle.of(588, "karrablast"), + trigger = Handle.of(2, "trade"), + tradeSpecies = Handle.of(588, "karrablast"), ) ) } @@ -277,7 +270,7 @@ class EvolutionTest { @Test fun getEvolutionChain16() = runTest { LocalPokeApi.getEvolutionChain(72).apply { - assertEquals(ResourceHandle.of(293, "full-incense"), babyTriggerItem) + assertEquals(Handle.of(293, "full-incense"), babyTriggerItem) assertEquals(true, chain.isBaby) } } @@ -287,8 +280,8 @@ class EvolutionTest { LocalPokeApi.getEvolutionTrigger(1).apply { assertEquals(1, id) assertEquals("level-up", name) - assertContains(names, Name(name = "Level up", language = ResourceHandle.of(9, "en"))) - assertContains(pokemonSpecies, ResourceHandle.of(662, "fletchinder")) + 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 330f24aa..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,9 +1,9 @@ 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.PokemonEntry -import co.pokeapi.pokekotlin.model.ResourceHandle import co.pokeapi.pokekotlin.test.LocalPokeApi import kotlin.test.Test import kotlin.test.assertContains @@ -17,13 +17,13 @@ class GameTest { LocalPokeApi.getGeneration(6).apply { assertEquals(6, id) assertEquals("generation-vi", name) - assertContains(abilities, ResourceHandle.of(189, "primordial-sea")) - assertContains(names, Name(name = "Generation VI", language = ResourceHandle.of(9, "en"))) - assertEquals(ResourceHandle.of(6, "kalos"), mainRegion) - assertContains(moves, ResourceHandle.of(562, "belch")) - assertContains(pokemonSpecies, ResourceHandle.of(656, "froakie")) - assertContains(types, ResourceHandle.of(18, "fairy")) - assertContains(versionGroups, ResourceHandle.of(15, "x-y")) + 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")) } } @@ -33,17 +33,14 @@ class GameTest { assertEquals(12, id) assertEquals("kalos-central", name) assertEquals(true, isMainSeries) - assertContains( - descriptions, - Description(description = "", language = ResourceHandle.of(9, "en")), - ) - assertContains(names, Name(name = "Central Kalos", language = ResourceHandle.of(9, "en"))) + 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 = ResourceHandle.of(612, "haxorus")), + PokemonEntry(entryNumber = 150, pokemonSpecies = Handle.of(612, "haxorus")), ) - assertEquals(ResourceHandle.of(6, "kalos"), region) - assertContains(versionGroups, ResourceHandle.of(15, "x-y")) + assertEquals(Handle.of(6, "kalos"), region) + assertContains(versionGroups, Handle.of(15, "x-y")) } } @@ -52,8 +49,8 @@ class GameTest { LocalPokeApi.getVersion(9).apply { assertEquals(9, id) assertEquals("emerald", name) - assertContains(names, Name(name = "Emerald", language = ResourceHandle.of(9, "en"))) - assertEquals(ResourceHandle.of(6, "emerald"), versionGroup) + assertContains(names, Name(name = "Emerald", language = Handle.of(9, "en"))) + assertEquals(Handle.of(6, "emerald"), versionGroup) } } @@ -63,11 +60,11 @@ class GameTest { assertEquals(1, id) assertEquals("red-blue", name) assertEquals(3, order) - assertEquals(ResourceHandle.of(1, "generation-i"), generation) - assertContains(moveLearnMethods, ResourceHandle.of(4, "machine")) - assertContains(pokedexes, ResourceHandle.of(2, "kanto")) - assertContains(regions, ResourceHandle.of(1, "kanto")) - assertContains(versions, ResourceHandle.of(1, "red")) + 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 19c13025..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,29 +14,29 @@ class ItemTest { assertEquals("ice-heal", name) assertEquals(200, cost) assertEquals(30, flingPower) - assertContains(attributes, ResourceHandle.of(5, "holdable")) - assertEquals(ResourceHandle.of(30, "status-cures"), 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 = ResourceHandle.of(9, "en"), + language = Handle.of(9, "en"), ), ) assertContains( flavorTextEntries, VersionGroupFlavorText( text = "Defrosts a frozen\nPOKéMON.", - versionGroup = ResourceHandle.of(5, "ruby-sapphire"), - language = ResourceHandle.of(9, "en"), + versionGroup = Handle.of(5, "ruby-sapphire"), + language = Handle.of(9, "en"), ), ) assertContains( gameIndices, - GenerationGameIndex(gameIndex = 20, generation = ResourceHandle.of(6, "generation-vi")), + GenerationGameIndex(gameIndex = 20, generation = Handle.of(6, "generation-vi")), ) - assertContains(names, Name(name = "Ice Heal", language = ResourceHandle.of(9, "en"))) + assertContains(names, Name(name = "Ice Heal", language = Handle.of(9, "en"))) assertEquals(emptyList(), heldByPokemon) assertEquals(null, flingEffect) @@ -51,9 +51,9 @@ class ItemTest { assertNotEquals( null, heldByPokemon.find { - it.pokemon == ResourceHandle.of(241, "miltank") && + it.pokemon == Handle.of(241, "miltank") && it.versionDetails.contains( - ItemHolderPokemonVersionDetail(rarity = 100, version = ResourceHandle.of(24, "y")) + ItemHolderPokemonVersionDetail(rarity = 100, version = Handle.of(24, "y")) ) }, ) @@ -62,14 +62,12 @@ class ItemTest { @Test fun getItem3() = runTest { - LocalPokeApi.getItem(249).apply { - assertEquals(ResourceHandle.of(1, "badly-poison"), flingEffect) - } + LocalPokeApi.getItem(249).apply { assertEquals(Handle.of(1, "badly-poison"), flingEffect) } } @Test fun getItem4() = runTest { - LocalPokeApi.getItem(231).apply { assertEquals(ResourceHandle.of(90), babyTriggerFor) } + LocalPokeApi.getItem(231).apply { assertEquals(Handle.of(90), babyTriggerFor) } } @Test fun getItem5() = runTest { LocalPokeApi.getItem(967) } @@ -79,8 +77,8 @@ class ItemTest { LocalPokeApi.getItem(305).apply { assertNotNull( machines.find { machineVersionDetail -> - machineVersionDetail.machine == ResourceHandle.of(2) && - machineVersionDetail.versionGroup == ResourceHandle.of(1, "red-blue") + machineVersionDetail.machine == Handle.of(2) && + machineVersionDetail.versionGroup == Handle.of(1, "red-blue") } ) } @@ -93,10 +91,10 @@ class ItemTest { assertEquals("usable-overworld", name) assertContains( descriptions, - Description(description = "Usable outside battle", language = ResourceHandle.of(9, "en")), + Description(description = "Usable outside battle", language = Handle.of(9, "en")), ) - assertContains(items, ResourceHandle.of(17, "potion")) - assertContains(names, Name(name = "Usable_overworld", language = ResourceHandle.of(9, "en"))) + assertContains(items, Handle.of(17, "potion")) + assertContains(names, Name(name = "Usable_overworld", language = Handle.of(9, "en"))) } } @@ -105,9 +103,9 @@ class ItemTest { LocalPokeApi.getItemCategory(34).apply { assertEquals(34, id) assertEquals("standard-balls", name) - assertEquals(ResourceHandle.of(3, "pokeballs"), pocket) - assertContains(items, ResourceHandle.of(4, "poke-ball")) - assertContains(names, Name(name = "Standard balls", language = ResourceHandle.of(9, "en"))) + assertEquals(Handle.of(3, "pokeballs"), pocket) + assertContains(items, Handle.of(4, "poke-ball")) + assertContains(names, Name(name = "Standard balls", language = Handle.of(9, "en"))) } } @@ -118,9 +116,9 @@ class ItemTest { assertEquals("badly-poison", name) assertContains( effectEntries, - Effect(effect = "Badly poisons the target.", language = ResourceHandle.of(9, "en")), + Effect(effect = "Badly poisons the target.", language = Handle.of(9, "en")), ) - assertContains(items, ResourceHandle.of(249, "toxic-orb")) + assertContains(items, Handle.of(249, "toxic-orb")) } } @@ -129,8 +127,8 @@ class ItemTest { LocalPokeApi.getItemPocket(4).apply { assertEquals(4, id) assertEquals("machines", name) - assertContains(categories, ResourceHandle.of(37, "all-machines")) - assertContains(names, Name(name = "TMs and HMs", language = ResourceHandle.of(9, "en"))) + 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 d94fd9c3..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,13 +15,13 @@ class LocationTest { LocalPokeApi.getLocation(20).apply { assertEquals(20, id) assertEquals("wayward-cave", name) - assertEquals(ResourceHandle.of(4, "sinnoh"), region) - assertContains(names, Name(name = "Wayward Cave", language = ResourceHandle.of(9, "en"))) + assertEquals(Handle.of(4, "sinnoh"), region) + assertContains(names, Name(name = "Wayward Cave", language = Handle.of(9, "en"))) assertContains( gameIndices, - GenerationGameIndex(gameIndex = 65, generation = ResourceHandle.of(4, "generation-iv")), + GenerationGameIndex(gameIndex = 65, generation = Handle.of(4, "generation-iv")), ) - assertContains(areas, ResourceHandle.of(113, "wayward-cave-1f")) + assertContains(areas, Handle.of(113, "wayward-cave-1f")) } } @@ -31,30 +31,29 @@ class LocationTest { assertEquals(20, id) assertEquals("mt-coronet-1f-from-exterior", name) assertEquals(20, gameIndex) - assertEquals(ResourceHandle.of(10, "mt-coronet"), location) + assertEquals(Handle.of(10, "mt-coronet"), location) assertContains( names, - Name(name = "Mount Coronet (1F from exterior)", language = ResourceHandle.of(9, "en")), + Name(name = "Mount Coronet (1F from exterior)", language = Handle.of(9, "en")), ) assertNotNull( encounterMethodRates.find { - it.encounterMethod == ResourceHandle.of(1, "walk") && - EncounterMethodRateVersionDetail(10, ResourceHandle.of(14, "platinum")) in - it.versionDetails + it.encounterMethod == Handle.of(1, "walk") && + EncounterMethodRateVersionDetail(10, Handle.of(14, "platinum")) in it.versionDetails } ) assertNotNull( pokemonEncounters.find { pokemonEncounter -> - pokemonEncounter.pokemon == ResourceHandle.of(35, "clefairy") && + pokemonEncounter.pokemon == Handle.of(35, "clefairy") && pokemonEncounter.versionDetails.find { encounterDetail -> - encounterDetail.version == ResourceHandle.of(12, "diamond") && + encounterDetail.version == Handle.of(12, "diamond") && encounterDetail.maxChance == 27 && encounterDetail.encounterDetails.find { encounter -> encounter.minLevel == 39 && encounter.maxLevel == 39 && encounter.chance == 4 && - encounter.method == ResourceHandle.of(1, "walk") && - ResourceHandle.of(8, "slot2-none") in encounter.conditionValues + encounter.method == Handle.of(1, "walk") && + Handle.of(8, "slot2-none") in encounter.conditionValues } != null } != null } @@ -67,13 +66,13 @@ class LocationTest { LocalPokeApi.getPalParkArea(2).apply { assertEquals(2, id) assertEquals("field", name) - assertContains(names, Name(name = "Field", language = ResourceHandle.of(9, "en"))) + assertContains(names, Name(name = "Field", language = Handle.of(9, "en"))) assertContains( pokemonEncounters, PalParkEncounterSpecies( baseScore = 100, rate = 1, - pokemonSpecies = ResourceHandle.of(492, "shaymin"), + pokemonSpecies = Handle.of(492, "shaymin"), ), ) } @@ -84,11 +83,11 @@ class LocationTest { LocalPokeApi.getRegion(1).apply { assertEquals(1, id) assertEquals("kanto", name) - assertEquals(ResourceHandle.of(1, "generation-i"), mainGeneration) - assertContains(locations, ResourceHandle.of(67, "celadon-city")) - assertContains(names, Name(name = "Kanto", language = ResourceHandle.of(9, "en"))) - assertContains(pokedexes, ResourceHandle.of(2, "kanto")) - assertContains(versionGroups, ResourceHandle.of(1, "red-blue")) + 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 877fc3cc..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.ResourceHandle +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(ResourceHandle.of(305, "tm01"), item) - assertEquals(ResourceHandle.of(526, "work-up"), move) - assertEquals(ResourceHandle.of(17, "sun-moon"), 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 42ac9df4..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(ResourceHandle.of(5, "tough"), contestType) - assertEquals(ResourceHandle.of(4), contestEffect) - assertEquals(ResourceHandle.of(5), superContestEffect) - assertEquals(ResourceHandle.of(2, "physical"), 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 = ResourceHandle.of(9, "en"), + language = Handle.of(9, "en"), ), ) assertEquals(emptyList(), effectChanges) - assertEquals(ResourceHandle.of(1, "generation-i"), generation) + assertEquals(Handle.of(1, "generation-i"), generation) assertEquals( MoveMetaData( - ailment = ResourceHandle.of(1, "paralysis"), - category = ResourceHandle.of(4, "damage+ailment"), + ailment = Handle.of(1, "paralysis"), + category = Handle.of(4, "damage+ailment"), minHits = null, maxHits = null, minTurns = null, @@ -52,24 +52,21 @@ class MoveTest { ), meta, ) - assertContains(names, Name(name = "Body Slam", language = ResourceHandle.of(9, "en"))) + assertContains(names, Name(name = "Body Slam", language = Handle.of(9, "en"))) assertEquals(emptyList(), pastValues) assertEquals(emptyList(), statChanges) - assertEquals(ResourceHandle.of(10, "selected-pokemon"), target) - assertEquals(ResourceHandle.of(1, "normal"), type) + assertEquals(Handle.of(10, "selected-pokemon"), target) + assertEquals(Handle.of(1, "normal"), type) assertContains( machines, - MachineVersionDetail( - machine = ResourceHandle.of(142), - versionGroup = ResourceHandle.of(1, "red-blue"), - ), + MachineVersionDetail(machine = Handle.of(142), versionGroup = Handle.of(1, "red-blue")), ) assertContains( flavorTextEntries, MoveFlavorText( flavorText = "An attack that may\ncause paralysis.", - language = ResourceHandle.of(9, "en"), - versionGroup = ResourceHandle.of(3, "gold-silver"), + language = Handle.of(9, "en"), + versionGroup = Handle.of(3, "gold-silver"), ), ) } @@ -81,7 +78,7 @@ class MoveTest { assertEquals( ContestComboSets( normalSet = ContestComboDetail(null, null), - superSet = ContestComboDetail(null, listOf(ResourceHandle.of(116, "focus-energy"))), + superSet = ContestComboDetail(null, listOf(Handle.of(116, "focus-energy"))), ), contestCombos, ) @@ -93,10 +90,10 @@ class MoveTest { LocalPokeApi.getMove(16).apply { assertNotNull( effectChanges.find { - it.versionGroup == ResourceHandle.of(3, "gold-silver") && + it.versionGroup == Handle.of(3, "gold-silver") && Effect( effect = "Does not hit Pokémon under the effects of fly.", - language = ResourceHandle.of(9, "en"), + language = Handle.of(9, "en"), ) in it.effectEntries } ) @@ -106,7 +103,7 @@ class MoveTest { @Test fun getMove4() = runTest { LocalPokeApi.getMove(14).apply { - assertContains(statChanges, MoveStatChange(change = 2, stat = ResourceHandle.of(2, "attack"))) + assertContains(statChanges, MoveStatChange(change = 2, stat = Handle.of(2, "attack"))) } } @@ -121,8 +118,8 @@ class MoveTest { pp = null, effectChance = null, effectEntries = emptyList(), - type = ResourceHandle.of(1, "normal"), - versionGroup = ResourceHandle.of(3, "gold-silver"), + type = Handle.of(1, "normal"), + versionGroup = Handle.of(3, "gold-silver"), ), ) } @@ -133,8 +130,8 @@ class MoveTest { LocalPokeApi.getMoveAilment(1).apply { assertEquals(1, id) assertEquals("paralysis", name) - assertContains(names, Name(name = "Paralysis", language = ResourceHandle.of(9, "en"))) - assertContains(moves, ResourceHandle.of(78, "stun-spore")) + assertContains(names, Name(name = "Paralysis", language = Handle.of(9, "en"))) + assertContains(moves, Handle.of(78, "stun-spore")) } } @@ -143,7 +140,7 @@ class MoveTest { LocalPokeApi.getMoveBattleStyle(1).apply { assertEquals(1, id) assertEquals("attack", name) - assertContains(names, Name(name = "Attack", language = ResourceHandle.of(9, "en"))) + assertContains(names, Name(name = "Attack", language = Handle.of(9, "en"))) } } @@ -156,10 +153,10 @@ class MoveTest { descriptions, Description( description = "No damage; inflicts status ailment", - language = ResourceHandle.of(9, "en"), + language = Handle.of(9, "en"), ), ) - assertContains(moves, ResourceHandle.of(47, "sing")) + assertContains(moves, Handle.of(47, "sing")) } } @@ -168,12 +165,12 @@ class MoveTest { LocalPokeApi.getMoveDamageClass(1).apply { assertEquals(1, id) assertEquals("status", name) - assertContains(names, Name(name = "status", language = ResourceHandle.of(9, "en"))) + assertContains(names, Name(name = "status", language = Handle.of(9, "en"))) assertContains( descriptions, - Description(description = "No damage", language = ResourceHandle.of(9, "en")), + Description(description = "No damage", language = Handle.of(9, "en")), ) - assertContains(moves, ResourceHandle.of(289, "snatch")) + assertContains(moves, Handle.of(289, "snatch")) } } @@ -182,7 +179,7 @@ class MoveTest { LocalPokeApi.getMoveLearnMethod(10).apply { assertEquals(10, id) assertEquals("form-change", name) - assertContains(names, Name(name = "Form Change", language = ResourceHandle.of(9, "en"))) + assertContains(names, Name(name = "Form Change", language = Handle.of(9, "en"))) assertContains( descriptions, Description( @@ -190,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 = ResourceHandle.of(9, "en"), + language = Handle.of(9, "en"), ), ) - assertContains(versionGroups, ResourceHandle.of(15, "x-y")) + assertContains(versionGroups, Handle.of(15, "x-y")) } } @@ -202,15 +199,15 @@ class MoveTest { LocalPokeApi.getMoveTarget(8).apply { assertEquals(8, id) assertEquals("random-opponent", name) - assertContains(names, Name(name = "Random opponent", language = ResourceHandle.of(9, "en"))) + assertContains(names, Name(name = "Random opponent", language = Handle.of(9, "en"))) assertContains( descriptions, Description( description = "One opposing Pokémon, selected at random.", - language = ResourceHandle.of(9, "en"), + language = Handle.of(9, "en"), ), ) - assertContains(moves, ResourceHandle.of(253, "uproar")) + 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 ad27b96c..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(ResourceHandle.of(3, "generation-iii"), generation) - assertContains(names, Name(name = "Stench", language = ResourceHandle.of(9, "en"))) + assertEquals(Handle.of(3, "generation-iii"), generation) + assertContains(names, Name(name = "Stench", language = Handle.of(9, "en"))) assertContains( effectEntries, VerboseEffect( @@ -25,20 +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 = ResourceHandle.of(9, "en"), + language = Handle.of(9, "en"), ), ) assertNotNull( effectChanges.find { - it.versionGroup == ResourceHandle.of(11, "black-white") && + it.versionGroup == Handle.of(11, "black-white") && it.effectEntries.contains( - Effect(effect = "Has no effect in battle.", language = ResourceHandle.of(9, "en")) + Effect(effect = "Has no effect in battle.", language = Handle.of(9, "en")) ) } ) assertContains( pokemon, - AbilityPokemon(isHidden = true, slot = 3, pokemon = ResourceHandle.of(44, "gloom")), + AbilityPokemon(isHidden = true, slot = 3, pokemon = Handle.of(44, "gloom")), ) } } @@ -51,7 +51,7 @@ class PokemonTest { assertEquals((0..6).map { it * 5 }.toList(), possibleValues) assertContains( descriptions, - Description(description = "Loves to eat", language = ResourceHandle.of(9, "en")), + Description(description = "Loves to eat", language = Handle.of(9, "en")), ) } } @@ -61,8 +61,8 @@ class PokemonTest { LocalPokeApi.getEggGroup(1).apply { assertEquals(1, id) assertEquals("monster", name) - assertContains(names, Name(name = "Monster", language = ResourceHandle.of(9, "en"))) - assertContains(pokemonSpecies, ResourceHandle.of(713, "avalugg")) + assertContains(names, Name(name = "Monster", language = Handle.of(9, "en"))) + assertContains(pokemonSpecies, Handle.of(713, "avalugg")) } } @@ -73,9 +73,9 @@ class PokemonTest { assertEquals("female", name) assertContains( pokemonSpeciesDetails, - PokemonSpeciesGender(rate = 4, pokemonSpecies = ResourceHandle.of(715, "noivern")), + PokemonSpeciesGender(rate = 4, pokemonSpecies = Handle.of(715, "noivern")), ) - assertContains(requiredForEvolution, ResourceHandle.of(478, "froslass")) + assertContains(requiredForEvolution, Handle.of(478, "froslass")) } } @@ -85,12 +85,9 @@ class PokemonTest { assertEquals(1, id) assertEquals("slow", name) assertEquals("\\frac{5x^3}{4}", formula) - assertContains( - descriptions, - Description(description = "slow", language = ResourceHandle.of(9, "en")), - ) + assertContains(descriptions, Description(description = "slow", language = Handle.of(9, "en"))) assertContains(levels, GrowthRateExperienceLevel(experience = 1250000, level = 100)) - assertContains(pokemonSpecies, ResourceHandle.of(721, "volcanion")) + assertContains(pokemonSpecies, Handle.of(721, "volcanion")) } } @@ -99,23 +96,23 @@ class PokemonTest { LocalPokeApi.getNature(10).apply { assertEquals(10, id) assertEquals("hasty", name) - assertEquals(ResourceHandle.of(6, "speed"), increasedStat) - assertEquals(ResourceHandle.of(3, "defense"), decreasedStat) - assertEquals(ResourceHandle.of(3, "sweet"), likesFlavor) - assertEquals(ResourceHandle.of(5, "sour"), 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 = ResourceHandle.of(1, "speed"), maxChange = 2), + NatureStatChange(pokeathlonStat = Handle.of(1, "speed"), maxChange = 2), ) assertContains( moveBattleStylePreferences, MoveBattleStylePreference( highHpPreference = 58, lowHpPreference = 88, - moveBattleStyle = ResourceHandle.of(1, "attack"), + moveBattleStyle = Handle.of(1, "attack"), ), ) - assertContains(names, Name(name = "Hasty", language = ResourceHandle.of(9, "en"))) + assertContains(names, Name(name = "Hasty", language = Handle.of(9, "en"))) } } @@ -124,14 +121,14 @@ class PokemonTest { LocalPokeApi.getPokeathlonStat(1).apply { assertEquals(1, id) assertEquals("speed", name) - assertContains(names, Name(name = "Speed", language = ResourceHandle.of(9, "en"))) + assertContains(names, Name(name = "Speed", language = Handle.of(9, "en"))) assertContains( affectingNatures.decrease, - NaturePokeathlonStatEffect(nature = ResourceHandle.of(24, "sassy"), maxChange = -2), + NaturePokeathlonStatEffect(nature = Handle.of(24, "sassy"), maxChange = -2), ) assertContains( affectingNatures.increase, - NaturePokeathlonStatEffect(nature = ResourceHandle.of(25, "serious"), maxChange = 1), + NaturePokeathlonStatEffect(nature = Handle.of(25, "serious"), maxChange = 1), ) } } @@ -146,33 +143,30 @@ class PokemonTest { assertEquals(true, isDefault) assertEquals(1, order) assertEquals(69, weight) - assertEquals(ResourceHandle.of(1, "bulbasaur"), species) + assertEquals(Handle.of(1, "bulbasaur"), species) assertContains( abilities, - PokemonAbility(slot = 1, isHidden = false, ability = ResourceHandle.of(65, "overgrow")), + PokemonAbility(slot = 1, isHidden = false, ability = Handle.of(65, "overgrow")), ) - assertContains(forms, ResourceHandle.of(1, "bulbasaur")) + assertContains(forms, Handle.of(1, "bulbasaur")) assertContains( gameIndices, - VersionGameIndex(version = ResourceHandle.of(22, "white-2"), gameIndex = 1), + VersionGameIndex(version = Handle.of(22, "white-2"), gameIndex = 1), ) assertEquals(emptyList(), heldItems) assertNotNull( moves.find { - it.move == ResourceHandle.of(13, "razor-wind") && + it.move == Handle.of(13, "razor-wind") && PokemonMoveVersion( levelLearnedAt = 0, - versionGroup = ResourceHandle.of(3, "gold-silver"), - moveLearnMethod = ResourceHandle.of(2, "egg"), + versionGroup = Handle.of(3, "gold-silver"), + moveLearnMethod = Handle.of(2, "egg"), order = null, ) in it.versionGroupDetails } ) - assertContains( - stats, - PokemonStat(effort = 0, baseStat = 45, stat = ResourceHandle.of(1, "hp")), - ) - assertContains(types, PokemonType(slot = 1, type = ResourceHandle.of(12, "grass"))) + assertContains(stats, PokemonStat(effort = 0, baseStat = 45, stat = Handle.of(1, "hp"))) + assertContains(types, PokemonType(slot = 1, type = Handle.of(12, "grass"))) } } @@ -181,9 +175,8 @@ class PokemonTest { LocalPokeApi.getPokemonVariety(12).apply { assertNotNull( heldItems.find { - it.item == ResourceHandle.of(199, "silver-powder") && - PokemonHeldItemVersion(version = ResourceHandle.of(7, "ruby"), rarity = 5) in - it.versionDetails + it.item == Handle.of(199, "silver-powder") && + PokemonHeldItemVersion(version = Handle.of(7, "ruby"), rarity = 5) in it.versionDetails } ) } @@ -195,16 +188,16 @@ class PokemonTest { assertNotNull( find { locAreaEncounter -> locAreaEncounter.locationArea == - ResourceHandle.of(296, "kanto-route-2-south-towards-viridian-city") && + Handle.of(296, "kanto-route-2-south-towards-viridian-city") && locAreaEncounter.versionDetails.find { detail -> detail.maxChance == 10 - detail.version == ResourceHandle.of(15, "heartgold") + detail.version == Handle.of(15, "heartgold") detail.encounterDetails.find { encounter -> encounter.minLevel == 8 && encounter.maxLevel == 8 && encounter.chance == 5 && - encounter.method == ResourceHandle.of(1, "walk") && - ResourceHandle.of(3, "time-morning") in encounter.conditionValues + encounter.method == Handle.of(1, "walk") && + Handle.of(3, "time-morning") in encounter.conditionValues } != null } != null } @@ -233,8 +226,8 @@ class PokemonTest { LocalPokeApi.getPokemonColor(1).apply { assertEquals(1, id) assertEquals("black", name) - assertContains(names, Name(name = "Black", language = ResourceHandle.of(9, "en"))) - assertContains(pokemonSpecies, ResourceHandle.of(143, "snorlax")) + assertContains(names, Name(name = "Black", language = Handle.of(9, "en"))) + assertContains(pokemonSpecies, Handle.of(143, "snorlax")) } } @@ -249,8 +242,8 @@ class PokemonTest { assertEquals(false, isBattleOnly) assertEquals(false, isMega) assertEquals("", formName) - assertEquals(ResourceHandle.of(1, "bulbasaur"), pokemon) - assertEquals(ResourceHandle.of(1, "red-blue"), 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")) @@ -263,10 +256,7 @@ class PokemonTest { @Test fun getPokemonForm2() = runTest { LocalPokeApi.getPokemonForm(10266).apply { - assertContains( - formNames, - Name(name = "Original Color", language = ResourceHandle.of(9, "en")), - ) + assertContains(formNames, Name(name = "Original Color", language = Handle.of(9, "en"))) } } @@ -275,8 +265,8 @@ class PokemonTest { LocalPokeApi.getPokemonHabitat(1).apply { assertEquals(1, id) assertEquals("cave", name) - assertContains(names, Name(name = "cave", language = ResourceHandle.of(9, "en"))) - assertContains(pokemonSpecies, ResourceHandle.of(379, "registeel")) + assertContains(names, Name(name = "cave", language = Handle.of(9, "en"))) + assertContains(pokemonSpecies, Handle.of(379, "registeel")) } } @@ -285,12 +275,12 @@ class PokemonTest { LocalPokeApi.getPokemonShape(1).apply { assertEquals(1, id) assertEquals("ball", name) - assertContains(names, Name(name = "Ball", language = ResourceHandle.of(9, "en"))) + assertContains(names, Name(name = "Ball", language = Handle.of(9, "en"))) assertContains( awesomeNames, - AwesomeName(awesomeName = "Pomaceous", language = ResourceHandle.of(9, "en")), + AwesomeName(awesomeName = "Pomaceous", language = Handle.of(9, "en")), ) - assertContains(pokemonSpecies, ResourceHandle.of(90, "shellder")) + assertContains(pokemonSpecies, Handle.of(90, "shellder")) } } @@ -309,28 +299,28 @@ class PokemonTest { assertEquals(20, hatchCounter) assertEquals(false, hasGenderDifferences) assertEquals(false, formsSwitchable) - assertEquals(ResourceHandle.of(4, "medium-slow"), growthRate) + assertEquals(Handle.of(4, "medium-slow"), growthRate) assertContains( pokedexNumbers, - PokemonSpeciesDexEntry(entryNumber = 80, pokedex = ResourceHandle.of(12, "kalos-central")), + PokemonSpeciesDexEntry(entryNumber = 80, pokedex = Handle.of(12, "kalos-central")), ) - assertContains(eggGroups, ResourceHandle.of(7, "plant")) - assertEquals(ResourceHandle.of(5, "green"), color) - assertEquals(ResourceHandle.of(8, "quadruped"), shape) + assertContains(eggGroups, Handle.of(7, "plant")) + assertEquals(Handle.of(5, "green"), color) + assertEquals(Handle.of(8, "quadruped"), shape) assertEquals(null, evolvesFromSpecies) - assertEquals(ResourceHandle.of(1), evolutionChain) - assertEquals(ResourceHandle.of(3, "grassland"), habitat) - assertEquals(ResourceHandle.of(1, "generation-i"), generation) - assertContains(names, Name(name = "Bulbasaur", language = ResourceHandle.of(9, "en"))) + 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 = ResourceHandle.of(2, "field")), + PalParkEncounterArea(rate = 30, baseScore = 50, area = Handle.of(2, "field")), ) assertEquals(emptyList(), formDescriptions) - assertContains(genera, Genus(genus = "Seed Pokémon", language = ResourceHandle.of(9, "en"))) + assertContains(genera, Genus(genus = "Seed Pokémon", language = Handle.of(9, "en"))) assertContains( varieties, - PokemonSpeciesVariety(isDefault = true, variety = ResourceHandle.of(1, "bulbasaur")), + PokemonSpeciesVariety(isDefault = true, variety = Handle.of(1, "bulbasaur")), ) assertContains( flavorTextEntries, @@ -339,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 = ResourceHandle.of(9, "en"), - version = ResourceHandle.of(26, "alpha-sapphire"), + language = Handle.of(9, "en"), + version = Handle.of(26, "alpha-sapphire"), ), ) } @@ -349,7 +339,7 @@ class PokemonTest { @Test fun getPokemonSpecies2() = runTest { LocalPokeApi.getPokemonSpecies(2).apply { - assertEquals(ResourceHandle.of(1, "bulbasaur"), evolvesFromSpecies) + assertEquals(Handle.of(1, "bulbasaur"), evolvesFromSpecies) } } @@ -363,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 = ResourceHandle.of(9, "en"), + language = Handle.of(9, "en"), ), ) } @@ -378,16 +368,16 @@ class PokemonTest { assertEquals(false, isBattleOnly) assertContains( affectingMoves.increase, - MoveStatAffect(change = 2, move = ResourceHandle.of(14, "swords-dance")), + MoveStatAffect(change = 2, move = Handle.of(14, "swords-dance")), ) assertContains( affectingMoves.decrease, - MoveStatAffect(change = -1, move = ResourceHandle.of(45, "growl")), + MoveStatAffect(change = -1, move = Handle.of(45, "growl")), ) - assertContains(affectingNatures.increase, ResourceHandle.of(6, "lonely")) - assertContains(affectingNatures.decrease, ResourceHandle.of(2, "bold")) - assertEquals(ResourceHandle.of(2, "physical"), moveDamageClass) - assertContains(names, Name(name = "Attack", language = ResourceHandle.of(9, "en"))) + 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"))) } } @@ -397,21 +387,21 @@ class PokemonTest { assertEquals(8, id) assertEquals("ghost", name) damageRelations.apply { - assertContains(halfDamageFrom, ResourceHandle.of(4, "poison")) - assertContains(noDamageFrom, ResourceHandle.of(1, "normal")) - assertContains(halfDamageTo, ResourceHandle.of(17, "dark")) - assertContains(doubleDamageFrom, ResourceHandle.of(8, "ghost")) - assertContains(noDamageTo, ResourceHandle.of(1, "normal")) - assertContains(doubleDamageTo, ResourceHandle.of(14, "psychic")) + 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 = ResourceHandle.of(6, "generation-vi")), + GenerationGameIndex(gameIndex = 7, generation = Handle.of(6, "generation-vi")), ) - assertEquals(ResourceHandle.of(2, "physical"), moveDamageClass) - assertContains(names, Name(name = "Ghost", language = ResourceHandle.of(9, "en"))) - assertContains(pokemon, TypePokemon(slot = 1, pokemon = ResourceHandle.of(607, "litwick"))) - assertContains(moves, ResourceHandle.of(506, "hex")) + 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 796ac438..e7167d33 100644 --- a/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/ResourceListTest.kt +++ b/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/ResourceListTest.kt @@ -1,8 +1,8 @@ package co.pokeapi.pokekotlin.test.model import co.pokeapi.pokekotlin.model.EndpointModel -import co.pokeapi.pokekotlin.model.PaginatedResourceList -import co.pokeapi.pokekotlin.model.ResourceHandle +import co.pokeapi.pokekotlin.model.Handle +import co.pokeapi.pokekotlin.model.PaginatedList import co.pokeapi.pokekotlin.test.LocalPokeApi import kotlin.test.* import kotlinx.coroutines.test.runTest @@ -14,7 +14,7 @@ class ResourceListTest { private suspend inline fun testCase( id: Int, name: String, - call: suspend () -> PaginatedResourceList.Named, + call: suspend () -> PaginatedList.Named, ) { call().apply { assertTrue(results.size <= pageSize, "Actual count: ${results.size}, pageSize: $pageSize") @@ -31,13 +31,13 @@ class ResourceListTest { assertNotNull(it.id) } - assertContains(results, ResourceHandle.of(id, name)) + assertContains(results, Handle.of(id, name)) } } private suspend inline fun testCase( id: Int, - call: suspend () -> PaginatedResourceList.Unnamed, + call: suspend () -> PaginatedList.Unnamed, ) { call().apply { assertTrue(results.size <= pageSize) @@ -51,7 +51,7 @@ class ResourceListTest { results.forEach { assertNotNull(it.id) } - assertContains(results, ResourceHandle.of(id)) + assertContains(results, Handle.of(id)) } } 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 9a3cc4dc..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.ResourceHandle import co.pokeapi.pokekotlin.test.LocalPokeApi import kotlin.test.Test import kotlin.test.assertContains @@ -17,7 +17,7 @@ class UtilityTest { assertEquals("us", iso3166) assertEquals("en", iso639) assertEquals("en", name) - assertContains(names, Name(name = "English", language = ResourceHandle.of(9, "en"))) + assertContains(names, Name(name = "English", language = Handle.of(9, "en"))) } } } From a7e69e0708a2a4493359f7bb3e1f8a2b164190a3 Mon Sep 17 00:00:00 2001 From: Sargun Vohra Date: Tue, 1 Jul 2025 00:46:49 -0700 Subject: [PATCH 3/5] Model and NamedModel --- .../kotlin/co/pokeapi/pokekotlin/PokeApi.kt | 10 +- .../internal/ApiResourceSerializer.kt | 7 +- .../{JsOnlyExport.kt => JsNonWasmExport.kt} | 2 +- .../co/pokeapi/pokekotlin/model/base.kt | 14 +- .../co/pokeapi/pokekotlin/model/berries.kt | 30 +-- .../co/pokeapi/pokekotlin/model/contests.kt | 24 +- .../co/pokeapi/pokekotlin/model/encounters.kt | 26 +- .../co/pokeapi/pokekotlin/model/evolution.kt | 20 +- .../co/pokeapi/pokekotlin/model/games.kt | 36 +-- .../co/pokeapi/pokekotlin/model/items.kt | 48 ++-- .../co/pokeapi/pokekotlin/model/locations.kt | 42 ++-- .../co/pokeapi/pokekotlin/model/machines.kt | 8 +- .../co/pokeapi/pokekotlin/model/moves.kt | 71 +++--- .../co/pokeapi/pokekotlin/model/pokemon.kt | 232 +++++++++--------- .../co/pokeapi/pokekotlin/model/resource.kt | 28 +-- .../co/pokeapi/pokekotlin/model/utility.kt | 32 +-- .../co/pokeapi/pokekotlin/test/BulkTest.kt | 6 +- .../pokeapi/pokekotlin/test/LocalPokeApi.kt | 7 +- .../pokekotlin/test/model/ResourceListTest.kt | 7 +- .../pokekotlin/internal/JsOnlyExport.js.kt | 2 +- .../pokekotlin/internal/JsOnlyExport.nonJs.kt | 2 +- 21 files changed, 336 insertions(+), 318 deletions(-) rename src/commonMain/kotlin/co/pokeapi/pokekotlin/internal/{JsOnlyExport.kt => JsNonWasmExport.kt} (87%) diff --git a/src/commonMain/kotlin/co/pokeapi/pokekotlin/PokeApi.kt b/src/commonMain/kotlin/co/pokeapi/pokekotlin/PokeApi.kt index e0cfa223..aae5c02f 100644 --- a/src/commonMain/kotlin/co/pokeapi/pokekotlin/PokeApi.kt +++ b/src/commonMain/kotlin/co/pokeapi/pokekotlin/PokeApi.kt @@ -1,6 +1,6 @@ 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.* @@ -23,7 +23,7 @@ import love.forte.plugin.suspendtrans.annotation.JsPromise import love.forte.plugin.suspendtrans.annotation.JvmAsync import love.forte.plugin.suspendtrans.annotation.JvmBlocking -@JsOnlyExport +@JsNonWasmExport public sealed class PokeApi @JsExport.Ignore constructor( @@ -62,7 +62,7 @@ constructor( configure = {}, ) - private suspend inline fun HttpClient.getNamedResourceList( + private suspend inline fun HttpClient.getNamedResourceList( offset: Int, limit: Int, ): PaginatedList.Named { @@ -73,7 +73,7 @@ constructor( .body() } - private suspend inline fun HttpClient.getResourceList( + private suspend inline fun HttpClient.getResourceList( offset: Int, limit: Int, ): PaginatedList.Unnamed { @@ -90,7 +90,7 @@ constructor( @JvmAsync @JsPromise @JsExport.Ignore - public suspend fun Handle.get(): T = client.get(url).body(TypeInfo(model)) + public suspend fun Handle.get(): T = client.get(url).body(TypeInfo(model)) // region Resource Lists diff --git a/src/commonMain/kotlin/co/pokeapi/pokekotlin/internal/ApiResourceSerializer.kt b/src/commonMain/kotlin/co/pokeapi/pokekotlin/internal/ApiResourceSerializer.kt index 4e0ad73b..34f1c7a2 100644 --- a/src/commonMain/kotlin/co/pokeapi/pokekotlin/internal/ApiResourceSerializer.kt +++ b/src/commonMain/kotlin/co/pokeapi/pokekotlin/internal/ApiResourceSerializer.kt @@ -1,12 +1,13 @@ package co.pokeapi.pokekotlin.internal -import co.pokeapi.pokekotlin.model.EndpointModel 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 object HandleSerializers { - class Unnamed : + class Unnamed : KSerializer> by DelegatingSerializer( serialName = "co.pokeapi.pokekotlin.model.ResourceHandle.Unnamed", delegate = Delegate.serializer(), @@ -16,7 +17,7 @@ internal object HandleSerializers { @Serializable internal data class Delegate(val url: String) } - class Named : + class Named : KSerializer> by DelegatingSerializer( serialName = "co.pokeapi.pokekotlin.model.ResourceHandle.Named", delegate = Delegate.serializer(), 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/model/base.kt b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/base.kt index 737ae1b4..2a3f5eff 100644 --- a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/base.kt +++ b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/base.kt @@ -1,6 +1,16 @@ package co.pokeapi.pokekotlin.model -import co.pokeapi.pokekotlin.internal.JsOnlyExport +import co.pokeapi.pokekotlin.internal.JsNonWasmExport import kotlinx.serialization.Serializable -@JsOnlyExport @Serializable public sealed interface EndpointModel +@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 d40cbf7c..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,10 +25,10 @@ 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, @@ -39,7 +39,7 @@ public data class Berry( val flavors: List, val item: Handle.Named, val naturalGiftType: Handle.Named, -) : EndpointModel +) : NamedModel /** * A flavor-to-potency mapping for a berry. See: https://pokeapi.co/docs/v2#berryflavormap @@ -48,7 +48,7 @@ public data class Berry( * @param flavor The referenced berry flavor. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class BerryFlavorMap(val potency: Int, val flavor: Handle.Named) /** @@ -61,13 +61,13 @@ public data class BerryFlavorMap(val potency: Int, val flavor: Handle.Named>, val names: List, -) : EndpointModel +) : 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: Handle.Named, val names: List, -) : EndpointModel +) : 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 +@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 885bcfa3..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, + override val id: Int, + override val name: String, val berryFlavor: Handle.Named, val names: List, -) : EndpointModel +) : NamedModel /** * The name of a contest type listed in different languages and colors. See: @@ -30,7 +30,7 @@ public data class ContestType( * @param language The language that this name is in. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class ContestName( val name: String, val color: String, @@ -48,14 +48,14 @@ public data class ContestName( * @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, -) : EndpointModel +) : Model /** * Super contest effects refer to the effects of moves when used in super contests. See: @@ -68,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>, -) : EndpointModel +) : Model diff --git a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/encounters.kt b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/encounters.kt index e7a6d451..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, -) : EndpointModel +) : 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>, -) : EndpointModel +) : 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, + override val id: Int, + override val name: String, val condition: Handle.Named, val names: List, -) : EndpointModel +) : NamedModel diff --git a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/evolution.kt b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/evolution.kt index a1a7ba42..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, + override val id: Int, val babyTriggerItem: Handle.Named?, val chain: ChainLink, -) : EndpointModel +) : Model /** * A single link within an evolution chain. Each link represents a Pokémon species and the @@ -33,7 +33,7 @@ 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: Handle.Named, @@ -69,7 +69,7 @@ public data class ChainLink( * levels up. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class EvolutionDetail( val trigger: Handle.Named, val item: Handle.Named? = null, @@ -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>, -) : EndpointModel +) : NamedModel diff --git a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/games.kt b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/games.kt index 8dc47a1d..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,10 +19,10 @@ 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, + override val id: Int, + override val name: String, val abilities: List>, val names: List, val mainRegion: Handle.Named, @@ -30,7 +30,7 @@ public data class Generation( val pokemonSpecies: List>, val types: List>, val versionGroups: List>, -) : EndpointModel +) : 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: Handle.Named?, val versionGroups: List>, -) : EndpointModel +) : NamedModel /** * A Pokémon species entry within a Pokédex. See: https://pokeapi.co/docs/v2#pokemonentry @@ -67,7 +67,7 @@ public data class Pokedex( * @param pokemonSpecies The Pokémon species being encountered. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class PokemonEntry( val entryNumber: Int, val pokemonSpecies: Handle.Named, @@ -82,13 +82,13 @@ public data class PokemonEntry( * @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: Handle.Named, -) : EndpointModel +) : NamedModel /** * Version groups categorize highly similar versions of the games. See: @@ -105,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: Handle.Named, val moveLearnMethods: List>, val pokedexes: List>, val regions: List>, val versions: List>, -) : EndpointModel +) : NamedModel diff --git a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/items.kt b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/items.kt index 4991112e..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,10 +25,10 @@ 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: Handle.Named?, @@ -42,14 +42,14 @@ public data class Item( val babyTriggerFor: Handle.Unnamed?, val sprites: ItemSprites, val machines: List, -) : EndpointModel +) : 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,7 +59,7 @@ 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: Handle.Named, val versionDetails: List, @@ -73,7 +73,7 @@ public data class ItemHolderPokemon( * @param version The version in which the Pokémon holds the item. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class ItemHolderPokemonVersionDetail( val rarity: Int, val version: Handle.Named, @@ -90,14 +90,14 @@ public data class ItemHolderPokemonVersionDetail( * @param descriptions The description of this resource listed in different languages. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class ItemAttribute( - val id: Int, - val name: String, + override val id: Int, + override val name: String, val items: List>, val names: List, val descriptions: List, -) : EndpointModel +) : NamedModel /** * Item categories determine where items will be placed in the players bag. See: @@ -110,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, + override val id: Int, + override val name: String, val items: List>, val names: List, val pocket: Handle.Named, -) : EndpointModel +) : NamedModel /** * The various effects of the move "Fling" when used with different items. See: @@ -129,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>, -) : EndpointModel +) : NamedModel /** * Pockets within the players bag used for storing items by category. See: @@ -147,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, + override val id: Int, + override val name: String, val categories: List>, val names: List, -) : EndpointModel +) : NamedModel diff --git a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/locations.kt b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/locations.kt index e5cbb4e5..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, + override val id: Int, + override val name: String, val region: Handle.Named?, val names: List, val gameIndices: List, val areas: List>, -) : EndpointModel +) : 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: Handle.Named, val names: List, val pokemonEncounters: List, -) : EndpointModel +) : NamedModel /** * The encounter rate for a specific encounter method in a location area. See: @@ -59,7 +59,7 @@ 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: Handle.Named, val versionDetails: List, @@ -73,7 +73,7 @@ public data class EncounterMethodRate( * @param version The version of the game in which the encounter can occur with the given chance. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class EncounterMethodRateVersionDetail( val rate: Int, val version: Handle.Named, @@ -87,7 +87,7 @@ public data class EncounterMethodRateVersionDetail( * referenced location area. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class PokemonEncounter( val pokemon: Handle.Named, val versionDetails: List, @@ -103,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, -) : EndpointModel +) : NamedModel /** * A Pokémon species that can be encountered in a specific Pal Park area. See: @@ -120,7 +120,7 @@ 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, @@ -141,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, + override val id: Int, + override val name: String, val locations: List>, val mainGeneration: Handle.Named?, val names: List, val pokedexes: List>, val versionGroups: List>, -) : EndpointModel +) : NamedModel diff --git a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/machines.kt b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/machines.kt index 8f9be09c..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, + override val id: Int, val item: Handle.Named, val move: Handle.Named, val versionGroup: Handle.Named, -) : EndpointModel +) : Model diff --git a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/moves.kt b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/moves.kt index 8a73d6dd..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,10 +38,10 @@ 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?, @@ -64,7 +64,7 @@ public data class Move( val type: Handle.Named, val machines: List, val flavorTextEntries: List, -) : EndpointModel +) : 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,7 +88,7 @@ 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>?, @@ -113,7 +113,7 @@ 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: Handle.Named, val category: Handle.Named, @@ -136,7 +136,7 @@ public data class MoveMetaData( * @param stat The stat being affected. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class MoveStatChange(val change: Int, val stat: Handle.Named) /** @@ -152,7 +152,7 @@ public data class MoveStatChange(val change: Int, val stat: Handle.Named) * @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?, @@ -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, + override val id: Int, + override val name: String, val moves: List>, val names: List, -) : EndpointModel +) : NamedModel /** * Styles of moves when used in the Battle Palace. See the bulbapedia article for greater detail. @@ -190,9 +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) : - EndpointModel +@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: @@ -204,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, + override val id: Int, + override val name: String, val moves: List>, val descriptions: List, -) : EndpointModel +) : NamedModel /** * Damage classes moves can have, e.g. physical, special, or non-damaging. See: @@ -223,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 names: List, -) : EndpointModel +) : NamedModel /** * Methods by which Pokémon can learn moves. See: https://pokeapi.co/docs/v2#move-learn-methods @@ -242,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>, -) : EndpointModel +) : NamedModel /** * Information about different types of targets that moves can be directed at during battle. Targets @@ -262,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 names: List, -) : EndpointModel +) : NamedModel /** * The flavor text of a move listed in different languages and version groups. See: @@ -280,7 +283,7 @@ 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: 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 216d4f1c..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,10 +20,10 @@ 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: Handle.Named, val names: List, @@ -31,7 +31,7 @@ public data class Ability( val effectChanges: List, val flavorTextEntries: List, val pokemon: List, -) : EndpointModel +) : NamedModel /** * The effect of an ability listed in different version groups and languages. See: @@ -41,7 +41,7 @@ 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: Handle.Named, @@ -56,7 +56,7 @@ 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: Handle.Named, @@ -71,7 +71,7 @@ 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, @@ -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, -) : EndpointModel +) : 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>, -) : EndpointModel +) : 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>, -) : EndpointModel +) : NamedModel /** * Pokémon species gender details. See: https://pokeapi.co/docs/v2#pokemonspeciesgender @@ -141,7 +141,7 @@ public data class Gender( * @param pokemonSpecies The Pokémon species this gender detail applies to. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class PokemonSpeciesGender( val rate: Int, val pokemonSpecies: Handle.Named, @@ -159,15 +159,15 @@ public data class PokemonSpeciesGender( * @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>, -) : EndpointModel +) : NamedModel /** * Experience required for a Pokémon to reach a certain level for a given growth rate. See: @@ -177,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) /** @@ -195,10 +195,10 @@ 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, + override val id: Int, + override val name: String, val decreasedStat: Handle.Named?, val increasedStat: Handle.Named?, val hatesFlavor: Handle.Named?, @@ -206,7 +206,7 @@ public data class Nature( val pokeathlonStatChanges: List, val moveBattleStylePreferences: List, val names: List, -) : EndpointModel +) : NamedModel /** * Change to a Pokeathlon stat for a given nature. See: https://pokeapi.co/docs/v2#naturestatchange @@ -215,7 +215,7 @@ public data class Nature( * @param pokeathlonStat The Pokeathlon stat being affected. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class NatureStatChange( val maxChange: Int, val pokeathlonStat: Handle.Named, @@ -230,7 +230,7 @@ public data class NatureStatChange( * @param moveBattleStyle The move battle style. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class MoveBattleStylePreference( val lowHpPreference: Int, val highHpPreference: Int, @@ -247,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, -) : EndpointModel +) : NamedModel /** * A set of natures and how they affect a Pokeathlon stat. See: @@ -263,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, @@ -277,7 +277,7 @@ public data class NaturePokeathlonStatEffectSets( * @param nature The nature that affects the referenced Pokeathlon stat. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class NaturePokeathlonStatEffect(val maxChange: Int, val nature: Handle.Named) /** @@ -305,10 +305,10 @@ public data class NaturePokeathlonStatEffect(val maxChange: Int, val nature: Han * @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, @@ -326,7 +326,7 @@ public data class PokemonVariety( val pastAbilities: List, val cries: PokemonCries, val sprites: PokemonSprites, -) : EndpointModel +) : NamedModel /** * Sprites are images used to depict Pokémon in the game. See: @@ -344,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?, @@ -368,7 +368,7 @@ public data class PokemonSprites( * @param showdown Showdown sprites. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class OtherGameSprites( val dreamWorld: GameSprites, val home: GameSprites, @@ -389,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, @@ -402,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, @@ -417,7 +417,7 @@ public data class GenerationIiGameSprites( ) @Serializable -@JsOnlyExport +@JsNonWasmExport public data class GenerationIiiGameSprites( val emerald: GameSprites, @SerialName("firered-leafgreen") val fireredLeafgreen: GameSprites, @@ -425,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, @@ -433,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, @@ -453,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, @@ -501,7 +501,7 @@ 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, @@ -516,7 +516,7 @@ 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: Handle.Named, val versionDetails: List, @@ -530,7 +530,7 @@ public data class PokemonHeldItem( * @param rarity The rarity of the held item in the version. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class PokemonHeldItemVersion(val version: Handle.Named, val rarity: Int) /** @@ -540,7 +540,7 @@ public data class PokemonHeldItemVersion(val version: Handle.Named, val * @param versionGroupDetails The details of the version group in which the move can be learned. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class PokemonMove( val move: Handle.Named, val versionGroupDetails: List, @@ -556,7 +556,7 @@ 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: Handle.Named, val versionGroup: Handle.Named, @@ -572,7 +572,7 @@ public data class PokemonMoveVersion( * @param baseStat The base value of the stat. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class PokemonStat(val stat: Handle.Named, val effort: Int, val baseStat: Int) /** @@ -582,7 +582,7 @@ public data class PokemonStat(val stat: Handle.Named, val effort: Int, val * @param type The type the Pokémon has. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class PokemonType(val slot: Int, val type: Handle.Named) /** @@ -592,7 +592,7 @@ public data class PokemonType(val slot: Int, val type: Handle.Named) * @param types The types the Pokémon had in that generation. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class PokemonPastType( val generation: Handle.Named, val types: List, @@ -606,7 +606,7 @@ public data class PokemonPastType( * @param abilities The abilities the Pokémon had in that generation. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class PokemonPastAbility( val generation: Handle.Named, val abilities: List, @@ -618,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: @@ -628,7 +630,7 @@ public data class PokemonPastAbility( * @param versionDetails The details of the encounter in each version. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class LocationAreaEncounter( val locationArea: Handle.Named, val versionDetails: List, @@ -644,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>, -) : EndpointModel +) : NamedModel /** * Some Pokémon may appear in one of multiple, visually different forms. These differences are @@ -676,10 +678,10 @@ 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, @@ -692,7 +694,7 @@ public data class PokemonForm( val versionGroup: Handle.Named, val names: List, val formNames: List, -) : EndpointModel +) : NamedModel /** * Sprites used to depict a Pokémon form. See: https://pokeapi.co/docs/v2#pokemonformsprites @@ -707,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?, @@ -729,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>, -) : EndpointModel +) : NamedModel /** * Shapes are used to determine a Pokémon's appearance and for search purposes. See: @@ -748,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>, -) : EndpointModel +) : NamedModel /** * The "scientific" name of a Pokémon shape. See: https://pokeapi.co/docs/v2#awesomename @@ -764,7 +766,7 @@ public data class PokemonShape( * @param language The language this "scientific" name is in. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class AwesomeName(val awesomeName: String, val language: Handle.Named) /** @@ -806,10 +808,10 @@ public data class AwesomeName(val awesomeName: String, val language: Handle.Name * @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, @@ -835,7 +837,7 @@ public data class PokemonSpecies( val genera: List, val varieties: List, val flavorTextEntries: List, -) : EndpointModel +) : NamedModel /** * Flavor text entries for a Pokémon species. See: https://pokeapi.co/docs/v2#flavortext @@ -845,7 +847,7 @@ 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: Handle.Named, @@ -860,7 +862,7 @@ public data class PokemonSpeciesFlavorText( * @param language The language this genus is in. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class Genus(val genus: String, val language: Handle.Named) /** @@ -871,7 +873,7 @@ public data class Genus(val genus: String, val language: Handle.Named) * @param pokedex The Pokédex the referenced Pokémon species can be found in. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class PokemonSpeciesDexEntry(val entryNumber: Int, val pokedex: Handle.Named) /** @@ -884,7 +886,7 @@ public data class PokemonSpeciesDexEntry(val entryNumber: Int, val pokedex: Hand * @param area The pal park area where this encounter happens. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class PalParkEncounterArea( val baseScore: Int, val rate: Int, @@ -898,7 +900,7 @@ public data class PalParkEncounterArea( * @param variety The Pokémon variety. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class PokemonSpeciesVariety( val isDefault: Boolean, @SerialName("pokemon") val variety: Handle.Named, @@ -921,10 +923,10 @@ 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, @@ -932,7 +934,7 @@ public data class Stat( val characteristics: List>, val moveDamageClass: Handle.Named?, val names: List, -) : EndpointModel +) : NamedModel /** * A set of moves that affect a stat and how they affect it. See: @@ -942,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, @@ -955,7 +957,7 @@ public data class MoveStatAffectSets( * @param move The move that affects this stat. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class MoveStatAffect(val change: Int, val move: Handle.Named) /** @@ -966,7 +968,7 @@ public data class MoveStatAffect(val change: Int, val move: Handle.Named) * @param decrease Natures that decrease the stat. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class NatureStatAffectSets( val increase: List>, val decrease: List>, @@ -992,10 +994,10 @@ 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, @@ -1005,10 +1007,10 @@ public data class Type( val pokemon: List, val moves: List>, val sprites: VersionTypeSprites, -) : EndpointModel +) : NamedModel @Serializable -@JsOnlyExport +@JsNonWasmExport public data class VersionTypeSprites( @SerialName("generation-iii") val generationIii: GenerationIiiTypeSprites, @SerialName("generation-iv") val generationIv: GenerationIvTypeSprites, @@ -1020,7 +1022,7 @@ public data class VersionTypeSprites( ) @Serializable -@JsOnlyExport +@JsNonWasmExport public data class GenerationIiiTypeSprites( val colosseum: TypeSprites, val emerald: TypeSprites, @@ -1030,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, @@ -1038,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, @@ -1060,7 +1062,7 @@ public data class GenerationViiTypeSprites( ) @Serializable -@JsOnlyExport +@JsNonWasmExport public data class GenerationViiiTypeSprites( @SerialName("brilliant-diamond-and-shining-pearl") val brilliantDiamondAndShiningPearl: TypeSprites, @@ -1069,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 @@ -1083,7 +1085,7 @@ public data class GenerationIxTypeSprites( * @param pokemon The Pokémon that has this type. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class TypePokemon(val slot: Int, val pokemon: Handle.Named) /** @@ -1098,7 +1100,7 @@ public data class TypePokemon(val slot: Int, val pokemon: Handle.Named>, val halfDamageTo: List>, @@ -1116,7 +1118,7 @@ public data class TypeRelations( * @param damageRelations The damage relations that applied in the referenced generation. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class TypePastDamageRelation( 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 b4c97911..2ebf42f2 100644 --- a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/resource.kt +++ b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/resource.kt @@ -1,12 +1,12 @@ package co.pokeapi.pokekotlin.model import co.pokeapi.pokekotlin.internal.HandleSerializers -import co.pokeapi.pokekotlin.internal.JsOnlyExport +import co.pokeapi.pokekotlin.internal.JsNonWasmExport import kotlin.reflect.KClass import kotlinx.serialization.Serializable @Suppress("EnumEntryName") -internal enum class ResourceEndpoint(val model: KClass) { +internal enum class ResourceEndpoint(val model: KClass) { ability(Ability::class), berry(Berry::class), `berry-firmness`(BerryFirmness::class), @@ -59,10 +59,10 @@ internal enum class ResourceEndpoint(val model: KClass) { companion object { private val modelToEntry = entries.associateBy { it.model } - operator fun get(model: KClass) = + operator fun get(model: KClass) = modelToEntry[model] ?: throw NoSuchElementException(model.simpleName) - inline fun forModel() = get(T::class) + inline fun forModel() = get(T::class) } override fun toString() = name @@ -73,8 +73,8 @@ internal enum class ResourceEndpoint(val model: KClass) { * * @property id The identifier for the resource. */ -@JsOnlyExport -public sealed class Handle { +@JsNonWasmExport +public sealed class Handle { internal abstract val url: String internal val model: KClass by lazy { @@ -90,10 +90,10 @@ public sealed class Handle { internal companion object Companion { private val urlRegex = "/([a-z\\-]+)/(-?[0-9]+)/$".toRegex() - internal inline fun of(id: Int): Unnamed = + internal inline fun of(id: Int): Unnamed = Unnamed("/api/v2/${ResourceEndpoint.forModel()}/$id/") - internal inline fun of(id: Int, slug: String): Named = + internal inline fun of(id: Int, slug: String): Named = Named("/api/v2/${ResourceEndpoint.forModel()}/$id/", slug) } @@ -102,7 +102,7 @@ public sealed class Handle { * 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) : + public data class Unnamed internal constructor(override val url: String) : Handle() /** @@ -113,7 +113,7 @@ public sealed class Handle { * @param slug The unique (name) of the referenced resource. */ @Serializable(with = HandleSerializers.Named::class) - public data class Named + public data class Named internal constructor(override val url: String, val slug: String) : Handle() } @@ -126,15 +126,15 @@ public sealed class Handle { * @property previous The URL for the previous page in the list. * @property results The list of returned resources in this page. */ -@JsOnlyExport -public sealed class PaginatedList { +@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 - public data class Unnamed + public data class Unnamed internal constructor( override val count: Int, override val next: String?, @@ -143,7 +143,7 @@ public sealed class PaginatedList { ) : PaginatedList() @Serializable - public data class Named + public data class Named internal constructor( override val count: Int, override val next: String?, diff --git a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/utility.kt b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/utility.kt index a8df376d..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, -) : EndpointModel +) : NamedModel /** * The localized description for an API resource in a specific language. See: @@ -34,7 +34,7 @@ public data class Language( * @param language The language this description is in. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class Description(val description: String, val language: Handle.Named) /** @@ -45,7 +45,7 @@ public data class Description(val description: String, val language: Handle.Name * @param language The language this effect is in. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class Effect(val effect: String, val language: Handle.Named) /** @@ -59,7 +59,7 @@ public data class Effect(val effect: String, val language: Handle.Named) /** @@ -86,7 +86,7 @@ public data class FlavorText(val flavorText: String, val language: Handle.Named< * @param generation The generation relevant to this game index. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class GenerationGameIndex(val gameIndex: Int, val generation: Handle.Named) /** @@ -96,7 +96,7 @@ public data class GenerationGameIndex(val gameIndex: Int, val generation: Handle * @param versionGroup The version group relevant to this machine. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class MachineVersionDetail( val machine: Handle.Unnamed, val versionGroup: Handle.Named, @@ -110,7 +110,7 @@ public data class MachineVersionDetail( * @param language The language this name is in. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class Name(val name: String, val language: Handle.Named) /** @@ -122,7 +122,7 @@ public data class Name(val name: String, val language: Handle.Named) * @param language The language this effect is in. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class VerboseEffect( val effect: String, val shortEffect: String, @@ -138,7 +138,7 @@ public data class VerboseEffect( * @param encounterDetails A list of encounters and their specifics. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class VersionEncounterDetail( val version: Handle.Named, val maxChance: Int, @@ -152,7 +152,7 @@ public data class VersionEncounterDetail( * @param version The version relevant to this game index. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class VersionGameIndex(val gameIndex: Int, val version: Handle.Named) /** @@ -164,7 +164,7 @@ public data class VersionGameIndex(val gameIndex: Int, val version: Handle.Named * @param versionGroup The version group which uses this flavor text. */ @Serializable -@JsOnlyExport +@JsNonWasmExport public data class VersionGroupFlavorText( val text: String, val language: 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 97120429..e457838b 100644 --- a/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/BulkTest.kt +++ b/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/BulkTest.kt @@ -1,6 +1,6 @@ package co.pokeapi.pokekotlin.test -import co.pokeapi.pokekotlin.model.EndpointModel +import co.pokeapi.pokekotlin.model.Model import co.pokeapi.pokekotlin.model.PaginatedList import co.pokeapi.pokekotlin.model.ResourceEndpoint import kotlin.math.min @@ -13,7 +13,7 @@ private const val LAST_N = 100 private const val MIDDLE_N = 100 class BulkTest { - private suspend inline fun testCase( + private suspend inline fun testCase( id: Int, getObject: suspend (Int) -> Any, ) { @@ -26,7 +26,7 @@ class BulkTest { } } - private suspend inline fun testEach( + private suspend inline fun testEach( getList: suspend (Int, Int) -> PaginatedList, getObject: suspend (Int) -> Any, ) { diff --git a/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/LocalPokeApi.kt b/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/LocalPokeApi.kt index 87bd5420..e94ba61e 100644 --- a/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/LocalPokeApi.kt +++ b/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/LocalPokeApi.kt @@ -2,7 +2,8 @@ package co.pokeapi.pokekotlin.test import co.pokeapi.pokekotlin.PokeApi import co.pokeapi.pokekotlin.internal.PokeApiJson -import co.pokeapi.pokekotlin.model.EndpointModel +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.* @@ -22,7 +23,7 @@ private val OffsetLimitPlugin = when (requestedType.type) { PaginatedList.Unnamed::class -> { val fullList = - PokeApiJson.decodeFromSource>(content.readBuffer()) + PokeApiJson.decodeFromSource>(content.readBuffer()) fullList.copy( results = fullList.results.subList(offset, min(endIndex, fullList.count)), previous = if (offset == 0) null else "TODO", @@ -31,7 +32,7 @@ private val OffsetLimitPlugin = } PaginatedList.Named::class -> { val fullList = - PokeApiJson.decodeFromSource>(content.readBuffer()) + 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/ResourceListTest.kt b/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/ResourceListTest.kt index e7167d33..5614b312 100644 --- a/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/ResourceListTest.kt +++ b/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/ResourceListTest.kt @@ -1,7 +1,8 @@ package co.pokeapi.pokekotlin.test.model -import co.pokeapi.pokekotlin.model.EndpointModel 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.* @@ -11,7 +12,7 @@ class ResourceListTest { val pageSize = 50 - private suspend inline fun testCase( + private suspend inline fun testCase( id: Int, name: String, call: suspend () -> PaginatedList.Named, @@ -35,7 +36,7 @@ class ResourceListTest { } } - private suspend inline fun testCase( + private suspend inline fun testCase( id: Int, call: suspend () -> PaginatedList.Unnamed, ) { diff --git a/src/jsMain/kotlin/co/pokeapi/pokekotlin/internal/JsOnlyExport.js.kt b/src/jsMain/kotlin/co/pokeapi/pokekotlin/internal/JsOnlyExport.js.kt index d7be148d..ccc0cce6 100644 --- a/src/jsMain/kotlin/co/pokeapi/pokekotlin/internal/JsOnlyExport.js.kt +++ b/src/jsMain/kotlin/co/pokeapi/pokekotlin/internal/JsOnlyExport.js.kt @@ -1,3 +1,3 @@ package co.pokeapi.pokekotlin.internal -internal actual typealias JsOnlyExport = JsExport +internal actual typealias JsNonWasmExport = JsExport diff --git a/src/nonJsMain/kotlin/co/pokeapi/pokekotlin/internal/JsOnlyExport.nonJs.kt b/src/nonJsMain/kotlin/co/pokeapi/pokekotlin/internal/JsOnlyExport.nonJs.kt index c70a1602..60eae781 100644 --- a/src/nonJsMain/kotlin/co/pokeapi/pokekotlin/internal/JsOnlyExport.nonJs.kt +++ b/src/nonJsMain/kotlin/co/pokeapi/pokekotlin/internal/JsOnlyExport.nonJs.kt @@ -1,3 +1,3 @@ package co.pokeapi.pokekotlin.internal -internal actual typealias JsOnlyExport = NoOpExport +internal actual typealias JsNonWasmExport = NoOpExport From 881aeebccd68cf65103889d636944376cff46123 Mon Sep 17 00:00:00 2001 From: Sargun Vohra Date: Tue, 1 Jul 2025 00:55:17 -0700 Subject: [PATCH 4/5] revert slug to name --- .../pokekotlin/demoapp/screens/PokemonListScreen.kt | 6 +++--- .../pokeapi/pokekotlin/internal/ApiResourceSerializer.kt | 4 ++-- .../kotlin/co/pokeapi/pokekotlin/model/resource.kt | 8 ++++---- .../co/pokeapi/pokekotlin/test/model/ResourceListTest.kt | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) 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 c09c6fae..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 @@ -143,7 +143,7 @@ private fun PokemonListItem( // Placeholder for name Text( - text = item.slug.replaceFirstChar { it.uppercase() }, + text = item.name.replaceFirstChar { it.uppercase() }, style = MaterialTheme.typography.titleMedium, modifier = Modifier.padding(top = 8.dp), ) @@ -161,7 +161,7 @@ private fun PokemonListItem( is LoadingStatus.Error -> { Column(modifier = Modifier.padding(16.dp)) { Text( - text = item.slug.replaceFirstChar { it.uppercase() }, + text = item.name.replaceFirstChar { it.uppercase() }, style = MaterialTheme.typography.titleMedium, ) Text( @@ -209,7 +209,7 @@ private fun PokemonListItem( ) { pokemon.types .sortedBy { it.slot } - .forEach { pokemonType -> PokemonTypeBadge(pokemonType.type.slug) } + .forEach { pokemonType -> PokemonTypeBadge(pokemonType.type.name) } } } } diff --git a/src/commonMain/kotlin/co/pokeapi/pokekotlin/internal/ApiResourceSerializer.kt b/src/commonMain/kotlin/co/pokeapi/pokekotlin/internal/ApiResourceSerializer.kt index 34f1c7a2..f5202e3c 100644 --- a/src/commonMain/kotlin/co/pokeapi/pokekotlin/internal/ApiResourceSerializer.kt +++ b/src/commonMain/kotlin/co/pokeapi/pokekotlin/internal/ApiResourceSerializer.kt @@ -21,8 +21,8 @@ internal object HandleSerializers { KSerializer> by DelegatingSerializer( serialName = "co.pokeapi.pokekotlin.model.ResourceHandle.Named", delegate = Delegate.serializer(), - fromDelegate = { Handle.Named(slug = it.name, url = it.url) }, - toDelegate = { Delegate(name = it.slug, url = it.url) }, + 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/model/resource.kt b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/resource.kt index 2ebf42f2..34ee2088 100644 --- a/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/resource.kt +++ b/src/commonMain/kotlin/co/pokeapi/pokekotlin/model/resource.kt @@ -93,8 +93,8 @@ public sealed class Handle { internal inline fun of(id: Int): Unnamed = Unnamed("/api/v2/${ResourceEndpoint.forModel()}/$id/") - internal inline fun of(id: Int, slug: String): Named = - Named("/api/v2/${ResourceEndpoint.forModel()}/$id/", slug) + internal inline fun of(id: Int, name: String): Named = + Named("/api/v2/${ResourceEndpoint.forModel()}/$id/", name) } /** @@ -110,11 +110,11 @@ public sealed class Handle { * resource" object pattern in the PokeAPI documentation. See: * https://pokeapi.co/docs/v2#namedapiresource * - * @param slug The unique (name) of the referenced resource. + * @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 slug: String) : Handle() + internal constructor(override val url: String, val name: String) : Handle() } /** 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 5614b312..d71e05cc 100644 --- a/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/ResourceListTest.kt +++ b/src/commonTest/kotlin/co/pokeapi/pokekotlin/test/model/ResourceListTest.kt @@ -28,7 +28,7 @@ class ResourceListTest { } results.forEach { - assertNotEquals("", it.slug) + assertNotEquals("", it.name) assertNotNull(it.id) } From 58b25691658853a5ceed2b066ebb66cc35f2ea67 Mon Sep 17 00:00:00 2001 From: Sargun Vohra Date: Tue, 1 Jul 2025 00:56:57 -0700 Subject: [PATCH 5/5] fix file name --- .../internal/{JsOnlyExport.js.kt => JsNonWasmExport.js.kt} | 0 .../internal/{JsOnlyExport.nonJs.kt => JsNonWasmExport.nonJs.kt} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename src/jsMain/kotlin/co/pokeapi/pokekotlin/internal/{JsOnlyExport.js.kt => JsNonWasmExport.js.kt} (100%) rename src/nonJsMain/kotlin/co/pokeapi/pokekotlin/internal/{JsOnlyExport.nonJs.kt => JsNonWasmExport.nonJs.kt} (100%) diff --git a/src/jsMain/kotlin/co/pokeapi/pokekotlin/internal/JsOnlyExport.js.kt b/src/jsMain/kotlin/co/pokeapi/pokekotlin/internal/JsNonWasmExport.js.kt similarity index 100% rename from src/jsMain/kotlin/co/pokeapi/pokekotlin/internal/JsOnlyExport.js.kt rename to src/jsMain/kotlin/co/pokeapi/pokekotlin/internal/JsNonWasmExport.js.kt diff --git a/src/nonJsMain/kotlin/co/pokeapi/pokekotlin/internal/JsOnlyExport.nonJs.kt b/src/nonJsMain/kotlin/co/pokeapi/pokekotlin/internal/JsNonWasmExport.nonJs.kt similarity index 100% rename from src/nonJsMain/kotlin/co/pokeapi/pokekotlin/internal/JsOnlyExport.nonJs.kt rename to src/nonJsMain/kotlin/co/pokeapi/pokekotlin/internal/JsNonWasmExport.nonJs.kt