FeatureStore

interface FeatureStore(source)

Storage abstraction for Feature flags with Kotlin-idiomatic operator support.

This interface provides a comprehensive API for managing feature flags, including CRUD operations, group management, and permission handling. All operations are suspend functions to support asynchronous I/O across different storage backends.

Operator Support

This interface uses Kotlin operator overloading for common operations:

  • featureId in store - Check if a feature exists

  • store[featureId] - Read a feature

  • store += feature - Create a new feature

  • store -= featureId - Delete a feature

Example:

val store: FeatureStore = InMemoryFeatureStore()

// Create a feature
store += Feature("dark-mode", isEnabled = true)

// Check existence
if ("dark-mode" in store) {
// Read feature
val feature = store["dark-mode"]
}

// Delete feature
store -= "dark-mode"

Inheritors

Functions

Link copied to clipboard
abstract suspend fun addToGroup(featureId: String, groupName: String)

Add a feature to a group.

Link copied to clipboard
abstract suspend fun clear()

Clear all features from the store.

Link copied to clipboard
abstract suspend operator fun contains(featureId: String): Boolean

Check if a feature exists in the store.

Link copied to clipboard
abstract suspend fun containsGroup(groupName: String): Boolean

Check if a group exists in the store.

Link copied to clipboard
abstract suspend fun count(): Int

Get the total number of features in the store.

Link copied to clipboard
abstract suspend fun createOrUpdate(feature: Feature)

Create or update a feature (upsert operation).

Link copied to clipboard
abstract suspend fun disable(featureId: String)

Disable a feature.

Link copied to clipboard
abstract suspend fun disableGroup(groupName: String)

Disable all features associated with the specified group.

Link copied to clipboard
abstract suspend fun enable(featureId: String)

Enable a feature.

Link copied to clipboard
abstract suspend fun enableGroup(groupName: String)

Enable all features associated with the specified group.

Link copied to clipboard
abstract suspend operator fun get(featureId: String): Feature?

Read a feature from the store.

Link copied to clipboard
abstract suspend fun getAll(): Map<String, Feature>

Read all features from the store.

Link copied to clipboard
abstract suspend fun getAllGroups(): Set<String>

Get all group names in the store.

Link copied to clipboard
abstract suspend fun getGroup(groupName: String): Map<String, Feature>

Read all features in a group.

Link copied to clipboard
abstract suspend fun getOrThrow(featureId: String): Feature

Read a feature from the store or throw an exception if not found.

Link copied to clipboard
abstract suspend fun grantRoleToFeature(featureId: String, roleName: String)

Grant a role/permission to a feature.

Link copied to clipboard
abstract suspend fun isEmpty(): Boolean

Check if the store contains no features.

Link copied to clipboard
abstract suspend operator fun minusAssign(featureId: String)

Delete a feature from the store.

Link copied to clipboard
abstract suspend operator fun plusAssign(feature: Feature)

Create a new feature in the store.

Link copied to clipboard
abstract suspend fun removeFromGroup(featureId: String, groupName: String)

Remove a feature from its group.

Link copied to clipboard
abstract suspend fun revokeRoleFromFeature(featureId: String, roleName: String)

Revoke a role/permission from a feature.

Link copied to clipboard
abstract suspend fun toggle(featureId: String)

Toggle a feature's enabled state.

Link copied to clipboard
abstract suspend fun update(feature: Feature)

Update an existing feature in the store.

Link copied to clipboard
abstract suspend fun updateFeature(featureId: String, transform: (Feature) -> Feature)

Update a feature using a transformation function.