Skip to content

Commit

Permalink
Warnings cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownJoe796 committed Aug 5, 2024
1 parent 8f6a215 commit 08b9c44
Show file tree
Hide file tree
Showing 137 changed files with 643 additions and 762 deletions.
22 changes: 0 additions & 22 deletions LightningServer.podspec

This file was deleted.

2 changes: 1 addition & 1 deletion demo/src/main/kotlin/AwsHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AwsHandler : AwsAdapter() {
CloudwatchMetrics
Server
preventLambdaTimeoutReuse = true
loadSettings(AwsHandler::class.java)
loadSettings()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import com.google.devtools.ksp.processing.*
import com.google.devtools.ksp.symbol.*

lateinit var comparable: KSClassDeclaration
var khrysalisUsed = false

class TableGenerator(
val codeGenerator: CodeGenerator,
Expand Down Expand Up @@ -56,13 +55,7 @@ class TableGenerator(
).bufferedWriter().use { out ->
with(TabAppendable(out)) {

if(khrysalisUsed) {
appendLine("@file:SharedCode")
}
appendLine("package ${ksName}")
if(khrysalisUsed) {
appendLine("import com.lightningkite.khrysalis.*")
}
appendLine("fun prepareModels() {")
tab {
ksClassDeclarations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ data class MongoFields(
}
else -> {
try {
if(it.shortName.asString() == "SharedCode") khrysalisUsed = true
appendLine(
"@file:${it.shortName.asString()}(${
it.arguments.joinToString(", ") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ import java.io.File
import java.util.UUID

lateinit var comparable: KSClassDeclaration
var khrysalisUsed = false

class TableGenerator(
val codeGenerator: CodeGenerator,
val logger: KSPLogger,
) : CommonSymbolProcessor2(codeGenerator, "lightningdb", 1) {
) : CommonSymbolProcessor2(codeGenerator, "lightningdb", 2) {
override fun interestedIn(resolver: Resolver): Set<KSFile> {
return resolver.getAllFiles()
.filter {
Expand Down Expand Up @@ -66,14 +65,7 @@ class TableGenerator(
fileName = "init"
).use { out ->
with(TabAppendable(out)) {

if(khrysalisUsed) {
appendLine("@file:SharedCode")
}
if(ksName.isNotEmpty()) appendLine("package ${ksName}")
if(khrysalisUsed) {
appendLine("import com.lightningkite.khrysalis.*")
}
appendLine("fun prepareModels() {")
tab {
ksClassDeclarations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ abstract class CommonSymbolProcessor2(

val interestedIn = interestedIn(resolver)

val stub = myCodeGenerator.createNewFile(
myCodeGenerator.createNewFile(
Dependencies.ALL_FILES,
fileName = "$myId",
extensionName = "txt",
Expand All @@ -42,7 +42,7 @@ abstract class CommonSymbolProcessor2(
val projectFolder = generateSequence(outSample) { it.parentFile!! }
.first { it.name == "build" }
.parentFile!!
val common = interestedIn.any { it.filePath?.contains("/src/common", true) == true }
val common = interestedIn.any { it.filePath.contains("/src/common", true) }
val flavor = outSample.path.split(File.separatorChar)
.dropWhile { it != "ksp" }
.drop(2)
Expand All @@ -61,7 +61,7 @@ abstract class CommonSymbolProcessor2(
lockFile = outFolder.resolve("$myId.lock"),
destinationFolder = outFolder.resolve(myId).also { it.mkdirs() },
action = {
fileCreator = label@{ dependencies, packageName, fileName, extensionName ->
fileCreator = label@{ _, packageName, fileName, extensionName ->
val packagePath = packageName.split('.').filter { it.isNotBlank() }.joinToString("") { "$it/" }
this.file("${packagePath}$fileName.$extensionName")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ data class MongoFields(
}
else -> {
try {
if(it.shortName.asString() == "SharedCode") return@forEach
appendLine(
"@file:${it.shortName.asString()}(${
it.arguments.joinToString(", ") {
Expand All @@ -50,7 +49,8 @@ data class MongoFields(
}
}
}
appendLine("@file:OptIn(ExperimentalSerializationApi::class, InternalSerializationApi::class)")
appendLine("""@file:OptIn(ExperimentalSerializationApi::class, InternalSerializationApi::class)""")
appendLine("""@file:Suppress("UNCHECKED_CAST", "UNUSED_PARAMETER", "UnusedImport")""")
appendLine()
if(packageName.isNotEmpty()) appendLine("package ${packageName}")
appendLine()
Expand All @@ -72,7 +72,10 @@ data class MongoFields(
appendLine()
val contextualTypes = declaration.containingFile?.annotation("UseContextualSerialization", "kotlinx.serialization")?.arguments?.firstOrNull()
?.value
?.let { it as? List<KSType> }
?.let {
@Suppress("UNCHECKED_CAST")
it as? List<KSType>
}
?.map { it.declaration }
?: listOf()
appendLine("// Contextual types: ${contextualTypes.joinToString { it.qualifiedName?.asString() ?: "-" }}")
Expand All @@ -95,7 +98,7 @@ data class MongoFields(
appendLine("""override val name: String = "${field.name}"""")
appendLine("""override fun get(receiver: $typeReference): ${field.kotlinType.toKotlin()} = receiver.${field.name}""")
appendLine("""override fun setCopy(receiver: $typeReference, value: ${field.kotlinType.toKotlin()}) = receiver.copy(${field.name} = value)""")
appendLine("""override val serializer: KSerializer<${field.kotlinType.toKotlin()}> = ${field.kotlinType.resolve()!!.toKotlinSerializer(contextualTypes)}""")
appendLine("""override val serializer: KSerializer<${field.kotlinType.toKotlin()}> = ${field.kotlinType.resolve().toKotlinSerializer(contextualTypes)}""")
appendLine("""override val annotations: List<Annotation> = $classReference.serializer().tryFindAnnotations("${field.name}")""")
}
appendLine("}")
Expand Down Expand Up @@ -125,7 +128,7 @@ data class MongoFields(
appendLine("""override val name: String = "${field.name}"""")
appendLine("""override fun get(receiver: $typeReference): ${field.kotlinType.toKotlin()} = receiver.${field.name}""")
appendLine("""override fun setCopy(receiver: $typeReference, value: ${field.kotlinType.toKotlin()}) = receiver.copy(${field.name} = value)""")
appendLine("""override val serializer: KSerializer<${field.kotlinType.toKotlin()}> = ${field.kotlinType.resolve()!!.toKotlinSerializer(contextualTypes)}""")
appendLine("""override val serializer: KSerializer<${field.kotlinType.toKotlin()}> = ${field.kotlinType.resolve().toKotlinSerializer(contextualTypes)}""")
appendLine("""override val annotations: List<Annotation> = $classReference.serializer($nothings).tryFindAnnotations("${field.name}")""")
appendLine("""override fun hashCode(): Int = ${field.name.hashCode() * 31 + simpleName.hashCode()}""")
appendLine("""override fun equals(other: Any?): Boolean = other is ${simpleName}_${field.name}<${declaration.typeParameters.joinToString(", ") { "* "}}>""")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ abstract class AwsAdapter : RequestStreamHandler, Resource {
val logger: Logger = LoggerFactory.getLogger(AwsAdapter::class.java)
var preventLambdaTimeoutReuse: Boolean = false

fun loadSettings(jclass: Class<*>) {
@Deprecated("Just load settings directly", ReplaceWith("loadSettings()"))
fun loadSettings(jclass: Class<*>) = loadSettings()
fun loadSettings() {
logger.debug("Loading settings...")
val root = File(System.getenv("LAMBDA_TASK_ROOT"))
root.resolve("settings.json").takeIf { it.exists() }?.let {
Expand Down Expand Up @@ -276,6 +278,7 @@ abstract class AwsAdapter : RequestStreamHandler, Resource {
}
}
}
@OptIn(DelicateCoroutinesApi::class)
val backgroundRegularHealthActionsJob = GlobalScope.launch {
println("Running ${backgroundReportingActions.size} backgroundRegularHealthActions...")
backgroundReportingActions.forEach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.lightningkite.lightningserver.aws
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.*
import java.util.*

@Serializable
data class APIGatewayV2HTTPEvent(
Expand Down Expand Up @@ -100,7 +101,7 @@ data class APIGatewayV2WebsocketRequest(

private fun JsonElement.jankType(key: String): String = when(this) {
JsonNull -> "Any?"
is JsonObject -> key.capitalize()
is JsonObject -> key.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }
is JsonArray -> "List<${this.firstOrNull()?.jankType(key)}>"
is JsonPrimitive -> when(this.content) {
"true", "false" -> "Boolean"
Expand All @@ -116,7 +117,7 @@ internal fun JsonObject.jankMeADataClass(name: String) {
}
println(") {")
entries.filter { it.value is JsonObject }.forEach {
(it.value as JsonObject).jankMeADataClass(it.key.capitalize())
(it.value as JsonObject).jankMeADataClass(it.key.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() })
}
println("}")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package com.lightningkite.lightningserver.aws

import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.async
import kotlinx.coroutines.*
import kotlinx.coroutines.future.asCompletableFuture
import kotlinx.coroutines.runBlocking
import java.util.Timer
import java.util.TimerTask
import java.util.concurrent.TimeUnit

@OptIn(DelicateCoroutinesApi::class)
fun <T> blockingTimeout(timeoutMs: Long, action: suspend ()->T): T {
val result = GlobalScope.async(Dispatchers.Default) {
action()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@file:Suppress("DEPRECATION")

package com.lightningkite.lightningserver.aws

import com.lightningkite.lightningserver.auth.JwtSigner
Expand Down Expand Up @@ -748,7 +750,7 @@ internal fun handlers() {
TerraformHandler.handler<CacheSettings>(
name = "DynamoDB",
priority = 1,
settingOutput = { key ->
settingOutput = { _ ->
"""
{
url = "dynamodb://${'$'}{var.deployment_location}/${namePrefixUnderscores}"
Expand Down Expand Up @@ -785,7 +787,7 @@ internal fun handlers() {
}
)
TerraformHandler.handler<SecretBasis>(
inputs = { key ->
inputs = { _ ->
listOf(
)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,10 @@ data class S3File(val system: S3FileSystem, val path: File) : FileObject {
), Charsets.UTF_8
)
}
val accessKey = system.credentialProvider.resolveCredentials().accessKeyId()
val secretKey = system.credentialProvider.resolveCredentials().secretAccessKey()
val objectPath = path.unixPath
val date = headers["X-Amz-Date"] ?: return false
val algorithm = headers["X-Amz-Algorithm"] ?: return false
val expires = headers["X-Amz-Expires"] ?: return false
val credential = headers["X-Amz-Credential"] ?: return false
val scope = credential.substringAfter("/")

Expand Down Expand Up @@ -193,7 +191,7 @@ data class S3File(val system: S3FileSystem, val path: File) : FileObject {
val creds = system.creds()
val accessKey = creds.access
val tokenPreEncoded = creds.tokenPreEncoded
var dateOnly = ""
var dateOnly: String
val date = now().atZone(TimeZone.UTC).run {
buildString {
this.append(date.year.toString().padStart(4, '0'))
Expand Down Expand Up @@ -243,7 +241,7 @@ data class S3File(val system: S3FileSystem, val path: File) : FileObject {
} ?: url

val officialSignedUrl: String
get() = system.signedUrlDuration?.let { e ->
get() = system.signedUrlDuration?.let { _ ->
system.signer.presignGetObject {
it.signatureDuration(system.signedUrlDuration.toJavaDuration())
it.getObjectRequest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ class CloudwatchMetrics(
events.map { it.metricType.name }.distinct().joinToString()
}"
)
events.chunked(1000).forEach { events ->
events.chunked(1000).forEach { eventSubset ->
cw.putMetricData {
it.metricData(events.flatMap {
it.metricData(eventSubset.flatMap {
val unit = when (it.metricType.unit) {
MetricUnit.Seconds -> StandardUnit.SECONDS
MetricUnit.Microseconds -> StandardUnit.MICROSECONDS
Expand Down
Loading

0 comments on commit 08b9c44

Please sign in to comment.