Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renamed classes and function names from kotlinx to kotlin #35

Merged
merged 1 commit into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class JsonCollection internal constructor(
private val indexMap: IndexOfIndexes,
private val genIdMap: IdGenerator,
private val persistentCollection: PersistentCollection,
) : KotlinxStoreCollection {
) : KotlinDocumentStoreCollection {
/**
* Generates a new unique identifier by incrementing the associated value within [genIdMap].
*
Expand Down Expand Up @@ -600,20 +600,19 @@ private fun <K, V> Iterable<Map.Entry<K, V>>.toMap() = buildMap { [email protected]
/**
* Extension property to retrieve the `id` field as a nullable [Long] from a [JsonObject].
*
* The `id` field is accessed using [KotlinxDocumentStore.ID_PROPERTY_NAME] property name
* The `id` field is accessed using [KotlinDocumentStore.ID_PROPERTY_NAME] property name
* constant and is parsed from its JSON representation. Returns `null` if the field does
* not.
*
* @throws [IllegalArgumentException] if the value of the `id` field is not a valid [Long].
*/
private val JsonObject.id: Long?
get() = get(KotlinxDocumentStore.Companion.ID_PROPERTY_NAME)?.jsonPrimitive?.contentOrNull?.toLong()
get() = get(KotlinDocumentStore.ID_PROPERTY_NAME)?.jsonPrimitive?.contentOrNull?.toLong()

/**
* Creates a copy of the `JsonObject` with the specified ID value.
*
* @param id The new ID value to be set in the copied `JsonObject`.
* @return A new `JsonObject` instance with the updated ID value.
*/
internal fun JsonObject.copy(id: Long) =
JsonObject(toMutableMap().also { it[KotlinxDocumentStore.Companion.ID_PROPERTY_NAME] = JsonPrimitive(id) })
internal fun JsonObject.copy(id: Long) = JsonObject(toMutableMap().also { it[KotlinDocumentStore.ID_PROPERTY_NAME] = JsonPrimitive(id) })
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import kotlin.jvm.JvmName
* @param store The underlying persistent data store for managing collection data.
* @param json A `Json` instance used for serialization and deserialization of documents.
*/
public class KotlinxDocumentStore internal constructor(
public class KotlinDocumentStore internal constructor(
public val store: DataStore,
public val json: Json,
) : SuspendCloseable by store {
Expand Down Expand Up @@ -158,7 +158,7 @@ internal suspend fun <K, V> Flow<Map.Entry<K, V>>.toMap() =
* @param name The name of the collection to retrieve.
* @return An [ObjectCollection] of the specified type [T].
*/
public suspend inline fun <reified T : Any> KotlinxDocumentStore.getObjectCollection(name: String): ObjectCollection<T> =
public suspend inline fun <reified T : Any> KotlinDocumentStore.getObjectCollection(name: String): ObjectCollection<T> =
getJsonCollection(name).toObjectCollection<T>()

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@ package com.github.lamba92.kotlin.document.store.core
import kotlinx.serialization.json.Json
import kotlinx.serialization.modules.SerializersModule

@Deprecated("Old name, use new one", ReplaceWith("KotlinDocumentDatabaseBuilder"))
public typealias KotlinxDocumentDatabaseBuilder = KotlinDocumentDatabaseBuilder

@Deprecated("Old name, use new one", ReplaceWith("KotlinDocumentStore"))
public typealias KotlinxDocumentStore = KotlinDocumentStore

/**
* Builder class for constructing instances of `KotlinxDocumentStore`.
*/
public class KotlinxDocumentDatabaseBuilder {
public class KotlinDocumentDatabaseBuilder {
/**
* Optional custom serializers module for JSON operations.
*/
Expand All @@ -22,21 +28,21 @@ public class KotlinxDocumentDatabaseBuilder {
/**
* Builds and returns a `KotlinxDocumentStore` instance using the defined configurations.
*/
public fun build(): KotlinxDocumentStore =
KotlinxDocumentStore(
public fun build(): KotlinDocumentStore =
KotlinDocumentStore(
store = store ?: error("Store must be provided"),
json =
Json {
this@KotlinxDocumentDatabaseBuilder.serializersModule?.let { serializersModule = it }
this@KotlinDocumentDatabaseBuilder.serializersModule?.let { serializersModule = it }
ignoreUnknownKeys = true
encodeDefaults = true
},
)
}

@Suppress("FunctionName")
public inline fun KotlinxDocumentStore(block: KotlinxDocumentDatabaseBuilder.() -> Unit): KotlinxDocumentStore =
KotlinxDocumentDatabaseBuilder().apply(block).build()
public inline fun KotlinDocumentStore(block: KotlinDocumentDatabaseBuilder.() -> Unit): KotlinDocumentStore =
KotlinDocumentDatabaseBuilder().apply(block).build()

@Suppress("FunctionName")
public fun KotlinxDocumentStore(store: DataStore): KotlinxDocumentStore = KotlinxDocumentStore { this.store = store }
public fun KotlinDocumentStore(store: DataStore): KotlinDocumentStore = KotlinDocumentStore { this.store = store }
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.serializer

@Deprecated("Old name, use new one", ReplaceWith("KotlinDocumentStoreCollection"))
public typealias KotlinxDocumentStoreCollection = KotlinDocumentStoreCollection

/**
* A collection of elements saved in a [DataStore]. This interface provides
* various operations to manage the lifecycle and contents of a collection, such as
* creating and dropping indexes, fetching collection details, and performing basic
* CRUD operations.
*/
public interface KotlinxStoreCollection {
public interface KotlinDocumentStoreCollection {
/**
* Retrieves the total number of elements in the collection.
*
Expand Down Expand Up @@ -127,7 +130,7 @@ public interface KotlinxStoreCollection {
* @param fieldValue An object used as the filter to identify which elements to remove.
* @return `true` if any elements were removed, `false` otherwise.
*/
public suspend inline fun <reified K> KotlinxStoreCollection.removeWhere(
public suspend inline fun <reified K> KotlinDocumentStoreCollection.removeWhere(
fieldSelector: String,
fieldValue: K,
fieldSerializer: KSerializer<K>,
Expand All @@ -146,7 +149,7 @@ public suspend inline fun <reified K> KotlinxStoreCollection.removeWhere(
* @param fieldValue An object used as the filter to identify which elements to remove.
* @return `true` if any elements were removed, `false` otherwise.
*/
public suspend inline fun <reified K> KotlinxStoreCollection.removeWhere(
public suspend inline fun <reified K> KotlinDocumentStoreCollection.removeWhere(
fieldSelector: String,
fieldValue: K,
): Boolean =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import kotlinx.serialization.serializer
public class ObjectCollection<T : Any>(
private val serializer: KSerializer<T>,
public val jsonCollection: JsonCollection,
) : KotlinxStoreCollection by jsonCollection {
) : KotlinDocumentStoreCollection by jsonCollection {
/**
* Searches for objects in the collection that match the specified selector and value.
* If an index exists for the provided selector, it uses the index for optimized lookup.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
@file:OptIn(ExperimentalJsExport::class, DelicateCoroutinesApi::class)
@file:Suppress("unused")

package com.github.lamba92.kotlin.document.store.samples.ktor.js

import com.github.lamba92.kotlin.document.store.core.KotlinxDocumentStore
import com.github.lamba92.kotlin.document.store.core.KotlinDocumentStore
import com.github.lamba92.kotlin.document.store.samples.User
import com.github.lamba92.kotlin.document.store.stores.browser.BrowserStore
import io.ktor.client.HttpClient
Expand Down Expand Up @@ -53,7 +54,7 @@ class UserClient(
}
}

private val cache = KotlinxDocumentStore(BrowserStore)
private val cache = KotlinDocumentStore(BrowserStore)

@Serializable
data class GetAllUsersRequest(val page: Int, val pageSize: Int)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.lamba92.kotlin.document.store.samples.ktor.server

import com.github.lamba92.kotlin.document.store.core.KotlinxDocumentStore
import com.github.lamba92.kotlin.document.store.core.KotlinDocumentStore
import com.github.lamba92.kotlin.document.store.core.getObjectCollection
import com.github.lamba92.kotlin.document.store.samples.User
import com.github.lamba92.kotlin.document.store.stores.leveldb.LevelDBStore
Expand All @@ -11,7 +11,7 @@ import kotlinx.coroutines.coroutineScope
suspend fun main() {
val dbPath = System.getenv("DB_PATH") ?: error("DB_PATH environment variable not set")
coroutineScope {
val db = KotlinxDocumentStore(LevelDBStore.open(dbPath))
val db = KotlinDocumentStore(LevelDBStore.open(dbPath))
val userCollection = db.getObjectCollection<User>("users")

userCollection.createIndex("name")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

package com.github.lamba92.kotlin.document.store.tests

import com.github.lamba92.kotlin.document.store.core.KotlinxDocumentStore
import com.github.lamba92.kotlin.document.store.core.KotlinDocumentStore
import com.github.lamba92.kotlin.document.store.core.getObjectCollection
import com.github.lamba92.kotlin.document.store.core.removeWhere
import kotlinx.coroutines.flow.count
Expand All @@ -15,7 +15,7 @@ import kotlin.test.assertEquals
* Abstract base class for testing deletion functionality within a document store.
*
* It extends [BaseTest] to provide a set of tests that validate the behavior of various
* deletion operations performed on collections and documents within a [KotlinxDocumentStore].
* deletion operations performed on collections and documents within a [KotlinDocumentStore].
* The tests include functionality for clearing collections, validating deletions for non-existent
* collections, handling indexed and non-indexed documents, as well as testing complex selectors.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

package com.github.lamba92.kotlin.document.store.tests

import com.github.lamba92.kotlin.document.store.core.KotlinxDocumentStore
import com.github.lamba92.kotlin.document.store.core.KotlinDocumentStore
import com.github.lamba92.kotlin.document.store.core.find
import com.github.lamba92.kotlin.document.store.core.getObjectCollection
import kotlinx.coroutines.flow.first
Expand All @@ -14,7 +14,7 @@ import kotlin.test.assertEquals
* Abstract base class for testing find functionality within a document store.
*
* It extends [BaseTest] and provides a set of tests that validate the behavior of various
* find operations performed on collections and documents within a [KotlinxDocumentStore].
* find operations performed on collections and documents within a [KotlinDocumentStore].
* The tests include functionality for finding documents using both simple and complex indexes
* to ensure precise data retrieval in diverse use cases.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
package com.github.lamba92.kotlin.document.store.tests

import com.github.lamba92.kotlin.document.store.core.DataStore
import com.github.lamba92.kotlin.document.store.core.KotlinxDocumentStore
import com.github.lamba92.kotlin.document.store.core.KotlinDocumentStore
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.NonCancellable
import kotlinx.coroutines.coroutineScope
Expand All @@ -24,7 +24,7 @@ import kotlin.time.Duration.Companion.minutes
*/
public abstract class BaseTest(private val storeProvider: DataStoreProvider) {
/**
* Runs a database-related coroutine-based test. It wraps [runTest] and provides a [KotlinxDocumentStore]
* Runs a database-related coroutine-based test. It wraps [runTest] and provides a [KotlinDocumentStore]
* instance to the test body. The provided database will be cleaned up before the test starts.
*
* @param testName The name of the test database to be created and used during the test.
Expand All @@ -35,21 +35,21 @@ public abstract class BaseTest(private val storeProvider: DataStoreProvider) {
* (default is 1 minute).
* @param serializersModule The [SerializersModule] to be used by the test database.
* @param testBody A suspendable function that acts as the test body.
* It receives a [KotlinxDocumentStore] instance representing the test database.
* It receives a [KotlinDocumentStore] instance representing the test database.
* @return A [TestResult] representing the result of the test execution.
*/
protected fun runDatabaseTest(
testName: String,
context: CoroutineContext = EmptyCoroutineContext,
timeout: Duration = 1.minutes,
serializersModule: SerializersModule? = null,
testBody: suspend CoroutineScope.(db: KotlinxDocumentStore) -> Unit,
testBody: suspend CoroutineScope.(db: KotlinDocumentStore) -> Unit,
): TestResult =
runTest(context, timeout) {
storeProvider.deleteDatabase(testName)
val store = storeProvider.provide(testName)
val db =
KotlinxDocumentStore {
KotlinDocumentStore {
this.store = store
this.serializersModule = serializersModule
}
Expand Down
Loading