@tokamakdev/platform-android-arm64 0.1.1-beta.131 → 0.1.1-beta.133

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -193,7 +193,7 @@ private class Types {
193
193
  }
194
194
  }
195
195
 
196
- /** A form of a sealed type: a subclass, named with a lowercase first letter. */
196
+ /** A form of a sealed type: a subclass, named by [jsonName]. */
197
197
  internal class Form(val name: String, val type: KClass<*>) {
198
198
  /** Whether the form is an object, whose JSON is its name. */
199
199
  val isName = type.objectInstance != null
@@ -206,14 +206,15 @@ internal class Form(val name: String, val type: KClass<*>) {
206
206
  internal fun forms(type: KClass<*>): List<Form> =
207
207
  type.sealedSubclasses.map { subclass ->
208
208
  val name = subclass.simpleName ?: throw DescribeError("${type.simpleName} has a form without a name")
209
- Form(name.replaceFirstChar { it.lowercase() }, subclass)
209
+ Form(jsonName(name), subclass)
210
210
  }.sortedBy { it.name }
211
211
 
212
212
  /** A data class's properties: its primary constructor's parameters. */
213
213
  internal fun fields(type: KClass<*>): List<KParameter> = type.primaryConstructor?.parameters.orEmpty()
214
214
 
215
- /** An enum class's constants, read without running its initializer. */
216
- private fun constants(type: KClass<*>): List<String> = type.java.declaredFields.filter { it.isEnumConstant }.map { it.name }
215
+ /** An enum class's constants, by [jsonName], read without running its initializer. */
216
+ internal fun constants(type: KClass<*>): List<String> =
217
+ type.java.declaredFields.filter { it.isEnumConstant }.map { jsonName(it.name) }
217
218
 
218
219
  private fun element(type: KType, context: String): KType {
219
220
  if (type.classifier != Flow::class) throw DescribeError("$context a stream returns a Flow")
@@ -213,7 +213,7 @@ private class Code(val packageName: String) {
213
213
  if (type.classifier in SCALARS) return value
214
214
  val classifier = type.classifier as KClass<*>
215
215
  if (type.isMarkedNullable) {
216
- return if (classifier.java.isEnum) "$value?.name" else "$value?.let { ${encode(type.withNullability(false), "it")} }"
216
+ return "$value?.let { ${encode(type.withNullability(false), "it")} }"
217
217
  }
218
218
  return when {
219
219
  classifier == List::class -> {
@@ -226,7 +226,10 @@ private class Code(val packageName: String) {
226
226
  val entry = encode(type.arguments[1].type!!, "it.value")
227
227
  if (entry == "it.value") "JSONObject($value)" else "JSONObject($value.mapValues { $entry })"
228
228
  }
229
- classifier.java.isEnum -> "$value.name"
229
+ classifier.java.isEnum -> {
230
+ imports += "com.tokamak.runtime.jsonName"
231
+ "jsonName($value.name)"
232
+ }
230
233
  else -> "json($value)"
231
234
  }
232
235
  }
@@ -296,7 +299,7 @@ private class Code(val packageName: String) {
296
299
  classifier == Boolean::class -> "json is Boolean"
297
300
  classifier in NUMBERS -> "json is Number"
298
301
  classifier.java.isEnum -> {
299
- val values = classifier.java.enumConstants.joinToString { "\"${(it as Enum<*>).name}\"" }
302
+ val values = constants(classifier).joinToString { "\"$it\"" }
300
303
  "json is String && json in setOf($values)"
301
304
  }
302
305
  classifier == List::class || classifier == JSONArray::class -> {
@@ -8,7 +8,7 @@ import kotlinx.coroutines.CoroutineScope
8
8
  import kotlinx.coroutines.CoroutineStart
9
9
  import kotlinx.coroutines.Job
10
10
  import kotlinx.coroutines.asCoroutineDispatcher
11
- import kotlinx.coroutines.channels.BufferOverflow
11
+ import kotlinx.coroutines.channels.Channel
12
12
  import kotlinx.coroutines.flow.Flow
13
13
  import kotlinx.coroutines.flow.MutableSharedFlow
14
14
  import kotlinx.coroutines.flow.onSubscription
@@ -64,16 +64,20 @@ class TokamakExporter<P : TokamakPlugin> internal constructor() {
64
64
  }
65
65
  }
66
66
 
67
- /** How many values listeners keep: those a slow reader has not taken, or those held for the first. */
68
- private const val LISTENER_CAPACITY = 64
67
+ /** The JSON name of the enum constant or sealed type form [name], such as `"granted"` for `Granted`. */
68
+ fun jsonName(name: String): String = name.replaceFirstChar { it.lowercase() }
69
+
70
+ /** How many values wait for the first listener. */
71
+ private const val HELD_CAPACITY = 64
69
72
 
70
73
  /**
71
74
  * The flows of an event's listeners, such as a page's, each of which receives every value [send]
72
- * delivers while it collects, keeping the newest 64 that a slow one has not taken. When [holding],
73
- * the newest 64 values sent while none listen wait for the first listener.
75
+ * delivers while it collects. A flow keeps every value its collector has not taken, so a Worker's
76
+ * subscription applies its own overflow policy. When [holding], the newest 64 values sent while
77
+ * none listen wait for the first listener.
74
78
  */
75
79
  class TokamakListeners<T>(private val holding: Boolean = false) {
76
- private val values = MutableSharedFlow<T>(extraBufferCapacity = LISTENER_CAPACITY, onBufferOverflow = BufferOverflow.DROP_OLDEST)
80
+ private val values = MutableSharedFlow<T>(extraBufferCapacity = Channel.UNLIMITED)
77
81
  private val held = mutableListOf<T>()
78
82
 
79
83
  /** A new listener's flow. */
@@ -86,7 +90,7 @@ class TokamakListeners<T>(private val holding: Boolean = false) {
86
90
  synchronized(held) {
87
91
  if (holding && values.subscriptionCount.value == 0) {
88
92
  held += value
89
- if (held.size > LISTENER_CAPACITY) held.removeAt(0)
93
+ if (held.size > HELD_CAPACITY) held.removeAt(0)
90
94
  return
91
95
  }
92
96
  }
@@ -206,7 +210,8 @@ class TokamakValue(private val json: Any?, private val path: String) {
206
210
 
207
211
  fun <E : Enum<E>> enum(entries: EnumEntries<E>): E {
208
212
  val name = string()
209
- return entries.firstOrNull { it.name == name } ?: throw invalid("one of ${entries.joinToString()}")
213
+ return entries.firstOrNull { jsonName(it.name) == name }
214
+ ?: throw invalid("one of ${entries.joinToString { jsonName(it.name) }}")
210
215
  }
211
216
 
212
217
  /** The error of a value that is none of the forms of the sealed type [name]. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokamakdev/platform-android-arm64",
3
- "version": "0.1.1-beta.131",
3
+ "version": "0.1.1-beta.133",
4
4
  "description": "The tokamak platform pack for android-arm64",
5
5
  "repository": {
6
6
  "type": "git",