@tokamakdev/platform-android-arm64 0.1.1-beta.132 → 0.1.1-beta.134

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 -> {
@@ -1,4 +1,4 @@
1
1
  [diffend] Oversized file quarantined before diffing.
2
2
  name: package/android-arm64/lib/TokamakRuntime/libtokamak.a
3
- size: 35458610 bytes
4
- sha256: 72638789b6a8c0191de333e13157fc4cf302854384d97011f5d724d5ed8d211e
3
+ size: 35456234 bytes
4
+ sha256: 48fd5ae9ba82f96b0b6a999349a4958c5ba9dbd101a0623a6681c3d220131cec
@@ -64,6 +64,9 @@ class TokamakExporter<P : TokamakPlugin> internal constructor() {
64
64
  }
65
65
  }
66
66
 
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
+
67
70
  /** How many values wait for the first listener. */
68
71
  private const val HELD_CAPACITY = 64
69
72
 
@@ -207,7 +210,8 @@ class TokamakValue(private val json: Any?, private val path: String) {
207
210
 
208
211
  fun <E : Enum<E>> enum(entries: EnumEntries<E>): E {
209
212
  val name = string()
210
- 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) }}")
211
215
  }
212
216
 
213
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.132",
3
+ "version": "0.1.1-beta.134",
4
4
  "description": "The tokamak platform pack for android-arm64",
5
5
  "repository": {
6
6
  "type": "git",