Compare commits

...

3 Commits

Author SHA1 Message Date
8dbb35f378 add meta 2026-05-23 12:14:15 +06:00
47d12e3740 start 0.29.4 2026-05-23 11:46:21 +06:00
45bff98a2c Merge pull request #662 from InsanusMokrassar/0.29.3
0.29.3
2026-05-21 20:12:29 +06:00
8 changed files with 145 additions and 3 deletions

View File

@@ -1,5 +1,10 @@
# Changelog
## 0.29.4
* `Meta`:
* Inited
## 0.29.3
* `Versions`:

View File

@@ -91,7 +91,7 @@ kotlin {
private List<SourceDirectorySet> findSourcesWithName(String... approximateNames) {
return parent.subprojects
.findAll { it != project && it.hasProperty("kotlin") }
.findAll { it != project && it.hasProperty("kotlin") && (it.name.contains("dokka") == false) }
.collectMany { it.kotlin.sourceSets }
.findAll { sourceSet ->
approximateNames.any { nameToFilter ->

View File

@@ -18,5 +18,5 @@ crypto_js_version=4.1.1
# Project data
group=dev.inmo
version=0.29.3
android_code_version=313
version=0.29.4
android_code_version=314

12
meta/build.gradle Normal file
View File

@@ -0,0 +1,12 @@
plugins {
id "org.jetbrains.kotlin.multiplatform"
id "org.jetbrains.kotlin.plugin.serialization"
id "com.android.library"
}
apply from: "$mppJvmJsWasmJsAndroidLinuxMingwLinuxArm64Project"
kotlin {
sourceSets {
}
}

View File

@@ -0,0 +1,94 @@
package dev.inmo.micro_utils.meta
import kotlinx.serialization.Polymorphic
import kotlinx.serialization.Serializable
/**
* A polymorphic container for storing heterogeneous key-value pairs with type-safe retrieval.
* Each key is bound to a specific type, enabling type-safe access to stored values.
*
* @property map The underlying map storing key-value pairs with polymorphic values.
*/
@Serializable
data class MetaContainer(
@MetaContainerRootMapWarning
val map: Map<Key<*>, @Polymorphic Any>
) {
/**
* A marker interface for type-safe keys in [MetaContainer].
*
* @param T The type of value associated with this key.
*/
interface Key<T : Any>
/**
* Retrieves a value from the container by its key.
*
* @param key The type-safe key to look up.
* @return The value associated with the key, or null if not present.
*/
@Suppress("UNCHECKED_CAST", "OPT_IN_USAGE")
operator fun <T : Any> get(key: Key<T>): T? = map[key] as? T?
/**
* Checks whether a value exists for the given key.
*
* @param key The type-safe key to check.
* @return true if the key exists and has a non-null value, false otherwise.
*/
operator fun <T : Any> contains(key: Key<T>): Boolean = get(key) != null
/**
* Builder for constructing [MetaContainer] instances with a fluent API.
*/
class Builder(
@MetaContainerRootMapWarning
private val map: MutableMap<Key<*>, Any> = mutableMapOf<Key<*>, Any>()
) {
/**
* Puts a value associated with the given key into the builder.
*
* @param k The type-safe key.
* @param v The value to store.
*/
fun <T : Any> put(k: Key<T>, v: T) {
map[k] = v
}
/**
* Retrieves a value from the builder by its key.
*
* @param key The type-safe key to look up.
* @return The value associated with the key, or null if not present.
*/
@Suppress("UNCHECKED_CAST")
operator fun <T : Any> get(key: Key<T>): T? = map[key] as T?
/**
* Checks whether a value exists for the given key in the builder.
*
* @param key The type-safe key to check.
* @return true if the key exists and has a non-null value, false otherwise.
*/
operator fun <T : Any> contains(key: Key<T>): Boolean = get(key) != null
/**
* Builds and returns the immutable [MetaContainer] instance.
*
* @return A new [MetaContainer] with the accumulated key-value pairs.
*/
fun build(): MetaContainer = MetaContainer(map.toMap())
}
companion object {
/**
* An empty [MetaContainer] instance with no entries.
*/
val EMPTY = MetaContainer(emptyMap())
}
}

View File

@@ -0,0 +1,17 @@
package dev.inmo.micro_utils.meta
/**
* Marks the direct use of [MetaContainer.map] as requiring explicit opt-in.
*
* This annotation warns against direct manipulation of the internal map without using
* the type-safe accessors, which could break type safety guarantees.
*/
@RequiresOptIn(
"Do not use this directly without any special reason",
RequiresOptIn.Level.WARNING
)
@Target(
AnnotationTarget.FIELD,
)
@Retention(AnnotationRetention.BINARY)
annotation class MetaContainerRootMapWarning

View File

@@ -0,0 +1,13 @@
package dev.inmo.micro_utils.meta
/**
* DSL builder function for creating a [MetaContainer] with a lambda block.
*
* @param block A lambda with receiver ([MetaContainer.Builder]) to configure the container.
* @return A new [MetaContainer] instance built from the DSL block.
*/
fun buildMetaContainer(block: MetaContainer.Builder.() -> Unit): MetaContainer {
val builder = MetaContainer.Builder()
builder.block()
return builder.build()
}

View File

@@ -1,6 +1,7 @@
rootProject.name='micro_utils'
String[] includes = [
":meta",
":common",
":common:compose",
":transactions",