All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.io.github.jan.supabase.postgrest.Utils.kt Maven / Gradle / Ivy

The newest version!
package io.github.jan.supabase.postgrest

import io.github.jan.supabase.annotations.SupabaseInternal
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.descriptors.elementNames
import kotlinx.serialization.serializerOrNull
import kotlin.reflect.KProperty1
import kotlin.reflect.typeOf

private val SNAKE_CASE_REGEX = "([a-z0-9])([A-Z])".toRegex()

@SupabaseInternal
expect fun  getSerialName(property: KProperty1): String

@SupabaseInternal
internal fun String.camelToSnakeCase(): String {
    return this.replace(SNAKE_CASE_REGEX, "$1_$2").lowercase()
}

@PublishedApi internal fun  Map>.mapToFirstValue() = mapValues { it.value.first() }

@OptIn(ExperimentalSerializationApi::class)
@SupabaseInternal
inline fun  classPropertyNames(): List = serializerOrNull(typeOf())?.descriptor?.elementNames?.toList() ?: throw IllegalArgumentException("Could not find serializer for ${T::class.simpleName}")




© 2015 - 2024 Weber Informatics LLC | Privacy Policy