-
Notifications
You must be signed in to change notification settings - Fork 0
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
✨ DataStore モジュールを追加 #110
✨ DataStore モジュールを追加 #110
Changes from all commits
02e24fd
a6bec95
4ea0730
18dd090
a1dd63c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ kotlin { | |
dependencies { | ||
implementation(libs.kotlinxCoroutinesCore) | ||
implementation(libs.kotlinxDatetime) | ||
implementation(libs.kotlinSerializationJson) | ||
Comment on lines
16
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
} | ||
iosMain { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package club.nito.core.common | ||
|
||
import kotlinx.serialization.ExperimentalSerializationApi | ||
import kotlinx.serialization.json.Json | ||
import kotlinx.serialization.json.JsonNamingStrategy | ||
|
||
public val nitoJsonSettings: Json = Json { | ||
encodeDefaults = true | ||
isLenient = true | ||
allowSpecialFloatingPointValues = true | ||
allowStructuredMapKeys = true | ||
prettyPrint = false | ||
useArrayPolymorphism = false | ||
ignoreUnknownKeys = true | ||
coerceInputValues = true | ||
useAlternativeNames = false | ||
|
||
@OptIn(ExperimentalSerializationApi::class) | ||
namingStrategy = JsonNamingStrategy.SnakeCase | ||
} | ||
Comment on lines
+3
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
plugins { | ||
id("nito.primitive.kmp") | ||
id("nito.primitive.kmp.android") | ||
id("nito.primitive.kmp.ios") | ||
id("nito.primitive.kmp.js") | ||
id("nito.primitive.detekt") | ||
} | ||
|
||
android.namespace = "club.nito.core.datastore" | ||
|
||
kotlin { | ||
explicitApi() | ||
|
||
sourceSets { | ||
commonMain { | ||
dependencies { | ||
implementation(projects.core.common) | ||
implementation(projects.core.model) | ||
|
||
implementation(libs.kotlinxCoroutinesCore) | ||
implementation(libs.kotlinSerializationJson) | ||
|
||
implementation(libs.koin) | ||
implementation(libs.kermit) | ||
|
||
implementation(libs.multiplatformSettingsNoArg) | ||
implementation(libs.multiplatformSettingsCoroutines) | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package club.nito.core.datastore | ||
|
||
public sealed interface DataStore | ||
Comment on lines
+1
to
+3
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. パッケージレベルのドキュメンテーションやコメントがないため、このインターフェースの目的や使い方についての説明があると、保守性や明確性が向上します。 |
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,14 @@ | ||||||||||||
package club.nito.core.datastore | ||||||||||||
|
||||||||||||
import com.russhwolf.settings.ExperimentalSettingsApi | ||||||||||||
import com.russhwolf.settings.Settings | ||||||||||||
import com.russhwolf.settings.coroutines.SuspendSettings | ||||||||||||
import com.russhwolf.settings.coroutines.toSuspendSettings | ||||||||||||
import kotlinx.serialization.json.Json | ||||||||||||
|
||||||||||||
public class SettingsDataStore( | ||||||||||||
private val settings: Settings, | ||||||||||||
@OptIn(ExperimentalSettingsApi::class) | ||||||||||||
private val suspendSettings: SuspendSettings = settings.toSuspendSettings(), | ||||||||||||
Comment on lines
+11
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 実験的なAPI + // Experimental API is used here. Ensure that the risks are understood and acceptable.
@OptIn(ExperimentalSettingsApi::class) Committable suggestion
Suggested change
|
||||||||||||
private val json: Json, | ||||||||||||
) : DataStore |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,9 @@ | ||||||||||||||||||||||
package club.nito.core.datastore | ||||||||||||||||||||||
|
||||||||||||||||||||||
import com.russhwolf.settings.Settings | ||||||||||||||||||||||
|
||||||||||||||||||||||
internal fun createSettings() = try { | ||||||||||||||||||||||
Settings() | ||||||||||||||||||||||
} catch (e: Exception) { | ||||||||||||||||||||||
error("Failed to create default settings") | ||||||||||||||||||||||
} | ||||||||||||||||||||||
Comment on lines
+5
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. エラーメッセージに例外の詳細を含めることで、デバッグ時に役立つ情報を提供することができます。例外のスタックトレースをログに記録することも検討してください。 - error("Failed to create default settings")
+ error("Failed to create default settings", e) Committable suggestion
Suggested change
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package club.nito.core.datastore.di | ||
|
||
import club.nito.core.common.nitoJsonSettings | ||
import club.nito.core.datastore.DataStore | ||
import club.nito.core.datastore.SettingsDataStore | ||
import club.nito.core.datastore.createSettings | ||
import com.russhwolf.settings.ExperimentalSettingsApi | ||
import org.koin.core.module.Module | ||
import org.koin.dsl.module | ||
|
||
public val dataStoreModule: Module = module { | ||
single<DataStore> { | ||
@OptIn(ExperimentalSettingsApi::class) | ||
SettingsDataStore( | ||
settings = createSettings(), | ||
json = nitoJsonSettings | ||
) | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,11 +6,7 @@ import io.github.jan.supabase.gotrue.Auth | |
import io.github.jan.supabase.postgrest.Postgrest | ||
import io.github.jan.supabase.realtime.Realtime | ||
import io.github.jan.supabase.serializer.KotlinXSerializer | ||
import kotlinx.serialization.ExperimentalSerializationApi | ||
import kotlinx.serialization.json.Json | ||
import kotlinx.serialization.json.JsonNamingStrategy | ||
import kotlinx.serialization.modules.SerializersModule | ||
import kotlinx.serialization.modules.contextual | ||
|
||
internal fun createNitoSupabaseClient( | ||
json: Json, | ||
|
@@ -24,22 +20,3 @@ internal fun createNitoSupabaseClient( | |
|
||
defaultSerializer = KotlinXSerializer(json) | ||
} | ||
Comment on lines
20
to
22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
セキュリティ上の懸念があります。SupabaseのURLとキーがハードコードされており、これが機密情報である場合、コード内に直接含めるべきではありません。これらの値は環境変数や設定ファイルから読み込むように変更することをお勧めします。 - supabaseUrl = "https://gtfjukrauyhrbglrzlva.supabase.co",
- supabaseKey = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Imd0Zmp1a3JhdXlocmJnbHJ6bHZhIiwicm9sZSI6ImFub24iLCJpYXQiOjE2OTkwMDQ3NTgsImV4cCI6MjAxNDU4MDc1OH0.zRjlzXVyz4vBM8Tb8GcpyPyTkCmOwdV-Xs18Agw2w-E",
+ supabaseUrl = System.getenv("SUPABASE_URL"),
+ supabaseKey = System.getenv("SUPABASE_KEY"), |
||
|
||
internal fun createNitoKtorJsonSettings(): Json = Json { | ||
encodeDefaults = true | ||
isLenient = true | ||
allowSpecialFloatingPointValues = true | ||
allowStructuredMapKeys = true | ||
prettyPrint = false | ||
useArrayPolymorphism = false | ||
ignoreUnknownKeys = true | ||
coerceInputValues = true | ||
useAlternativeNames = false | ||
|
||
@OptIn(ExperimentalSerializationApi::class) | ||
namingStrategy = JsonNamingStrategy.SnakeCase | ||
|
||
serializersModule = SerializersModule { | ||
contextual(InstantSerializer) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
projects.core.datastore
モジュールがcommonMain
依存関係に追加されましたが、core.datastore
モジュールのbuild.gradle.kts
ファイルに関する情報が見つかりませんでした。バージョン競合や追加の設定が必要かどうかを確認するためには、このファイルの内容を確認する必要があります。プロジェクトの設定ファイルを全体的に見直して、この変更が他のモジュールとの競合を引き起こさないことを確認してください。