diff --git a/server-core/src/main/kotlin/com/lightningkite/lightningserver/jsonschema/JsonSchemaBuilder.kt b/server-core/src/main/kotlin/com/lightningkite/lightningserver/jsonschema/JsonSchemaBuilder.kt index 6da774ee..72dbd414 100644 --- a/server-core/src/main/kotlin/com/lightningkite/lightningserver/jsonschema/JsonSchemaBuilder.kt +++ b/server-core/src/main/kotlin/com/lightningkite/lightningserver/jsonschema/JsonSchemaBuilder.kt @@ -413,7 +413,7 @@ class JsonSchemaBuilder( } val ser = serializer.unwrap() - overrides[ser.descriptor.serialName.substringBefore('<')]?.let { + overrides[ser.descriptor.serialName.substringBefore('/').substringBefore('<')]?.let { return defining(ser) { it(ser) }.applyAnnotations(annos) } return when (ser.descriptor.kind) { @@ -433,7 +433,7 @@ class JsonSchemaBuilder( SerialKind.ENUM -> defining(serializer) { JsonSchemaType( - title = ser.descriptor.serialName.substringBefore('<').substringAfterLast('.').titleCase(), + title = ser.descriptor.serialName.substringBefore('/').substringBefore('<').substringAfterLast('.').titleCase(), type = JsonType3(JsonType2.STRING), oneOf = (0 until ser.descriptor.elementsCount) .map { @@ -462,7 +462,7 @@ class JsonSchemaBuilder( StructureKind.CLASS -> defining(serializer) { JsonSchemaType( - title = ser.descriptor.serialName.substringBefore('<').substringAfterLast('.').titleCase(), + title = ser.descriptor.serialName.substringBefore('/').substringBefore('<').substringAfterLast('.').titleCase(), type = JsonType3(JsonType2.OBJECT), properties = ser.serializableProperties?.associate { val propTitle = it.name.titleCase() diff --git a/server-testing/src/test/kotlin/com/lightningkite/lightningdb/test/InMemoryDatabaseTests.kt b/server-testing/src/test/kotlin/com/lightningkite/lightningdb/test/InMemoryDatabaseTests.kt index 0e25651e..355b87db 100644 --- a/server-testing/src/test/kotlin/com/lightningkite/lightningdb/test/InMemoryDatabaseTests.kt +++ b/server-testing/src/test/kotlin/com/lightningkite/lightningdb/test/InMemoryDatabaseTests.kt @@ -20,6 +20,7 @@ import org.junit.Test import java.io.File import kotlin.test.assertEquals import kotlin.time.Duration.Companion.hours +import kotlin.time.Duration.Companion.milliseconds class RamAggregationsTest: AggregationsTest() { override val database: Database = InMemoryDatabase() @@ -41,22 +42,22 @@ class RamMetaTest: MetaTest() { } class DelayRamAggregationsTest: AggregationsTest() { - override val database: Database = InMemoryDatabase().delayed(5L) + override val database: Database = InMemoryDatabase().delayed(5.milliseconds..6.milliseconds) } class DelayRamConditionTests: ConditionTests() { - override val database: Database = InMemoryDatabase().delayed(5L) + override val database: Database = InMemoryDatabase().delayed(5.milliseconds..6.milliseconds) } class DelayRamModificationTests: ModificationTests() { - override val database: Database = InMemoryDatabase().delayed(5L) + override val database: Database = InMemoryDatabase().delayed(5.milliseconds..6.milliseconds) } class DelayRamOperationsTests: OperationsTests() { - override val database: Database = InMemoryDatabase().delayed(5L) + override val database: Database = InMemoryDatabase().delayed(5.milliseconds..6.milliseconds) } class DelayRamSortTest: SortTest() { - override val database: Database = InMemoryDatabase().delayed(5L) + override val database: Database = InMemoryDatabase().delayed(5.milliseconds..6.milliseconds) } class DelayRamMetaTest: MetaTest() { - override val database: Database = InMemoryDatabase().delayed(5L) + override val database: Database = InMemoryDatabase().delayed(5.milliseconds..6.milliseconds) } class LocalCacheTest: CacheTest() { diff --git a/server-testing/src/test/kotlin/com/lightningkite/lightningserver/jsonschema/JsonSchemaTest.kt b/server-testing/src/test/kotlin/com/lightningkite/lightningserver/jsonschema/JsonSchemaTest.kt index b5d09d09..3cd495b4 100644 --- a/server-testing/src/test/kotlin/com/lightningkite/lightningserver/jsonschema/JsonSchemaTest.kt +++ b/server-testing/src/test/kotlin/com/lightningkite/lightningserver/jsonschema/JsonSchemaTest.kt @@ -16,6 +16,6 @@ class JsonSchemaTest { val schema = Serialization.jsonWithoutDefaults.schema(HasServerFiles.serializer()) .also(::println) .also { println(Json(Serialization.jsonWithoutDefaults) { prettyPrint = true }.encodeToString(it)) } - assertEquals("#/definitions/com.lightningkite.lightningserver.files.ServerFile", schema.definitions["com.lightningkite.lightningdb.test.HasServerFiles"]!!.properties!!["file"]!!.ref) + assertEquals("#/definitions/com.lightningkite.lightningserver.files.ServerFile/external", schema.definitions["com.lightningkite.lightningdb.test.HasServerFiles"]!!.properties!!["file"]!!.ref) } -} \ No newline at end of file +} diff --git a/shared/src/commonMain/kotlin/com/lightningkite/StringAlts.kt b/shared/src/commonMain/kotlin/com/lightningkite/StringAlts.kt index 449861ef..94a308b7 100644 --- a/shared/src/commonMain/kotlin/com/lightningkite/StringAlts.kt +++ b/shared/src/commonMain/kotlin/com/lightningkite/StringAlts.kt @@ -16,9 +16,11 @@ interface IsRawString : Comparable { companion object { val serialNames = setOf( - "TrimmedString", - "CaselessString", - "TrimmedCaselessString", + "com.lightningkite.TrimmedString", + "com.lightningkite.CaselessString", + "com.lightningkite.TrimmedCaselessString", + "com.lightningkite.EmailAddress", + "com.lightningkite.PhoneNumber", ) } } diff --git a/shared/src/commonMain/kotlin/com/lightningkite/lightningdb/ConditionSerialization.kt b/shared/src/commonMain/kotlin/com/lightningkite/lightningdb/ConditionSerialization.kt index 6cbb7600..3cc2b7da 100644 --- a/shared/src/commonMain/kotlin/com/lightningkite/lightningdb/ConditionSerialization.kt +++ b/shared/src/commonMain/kotlin/com/lightningkite/lightningdb/ConditionSerialization.kt @@ -79,7 +79,7 @@ class ConditionSerializer(val inner: KSerializer): MySealedClassSerializer MySealedClassSerializer>("com.lightningkite.lightningdb.Condition", { val r = when { inner.descriptor.isNullable -> nullableOptions(inner.innerElement() as KSerializer) - inner.descriptor.serialName == "kotlin.String" -> stringOptions + inner.descriptor.serialName.substringBefore('/') == "kotlin.String" -> stringOptions IsRawString.Companion.serialNames.contains(inner.descriptor.serialName) -> rawStringOptions(inner as KSerializer) inner.descriptor.serialName == "kotlin.Int" -> intOptions inner.descriptor.serialName == "com.lightningkite.GeoCoordinate" -> geocoordinateOptions diff --git a/shared/src/commonMain/kotlin/com/lightningkite/lightningdb/ModificationSerialization.kt b/shared/src/commonMain/kotlin/com/lightningkite/lightningdb/ModificationSerialization.kt index 0609052d..f2782559 100644 --- a/shared/src/commonMain/kotlin/com/lightningkite/lightningdb/ModificationSerialization.kt +++ b/shared/src/commonMain/kotlin/com/lightningkite/lightningdb/ModificationSerialization.kt @@ -124,7 +124,7 @@ data class ModificationSerializer(val inner: KSerializer) : MySealedClassSerializer>("com.lightningkite.lightningdb.Modification", { val r = when { inner.nullElement() != null -> nullableOptions(inner.nullElement()!! as KSerializer) - inner.descriptor.serialName == "kotlin.String" -> stringOptions + inner.descriptor.serialName.substringBefore('/') == "kotlin.String" -> stringOptions inner.descriptor.serialName in numlist -> numberOptions(inner as KSerializer) IsRawString.Companion.serialNames.contains(inner.descriptor.serialName) -> rawStringOptions(inner as KSerializer) inner.descriptor.kind == StructureKind.MAP -> stringMapOptions(inner.mapValueElement()!!) diff --git a/shared/src/commonMain/kotlin/com/lightningkite/serialization/Defaults.kt b/shared/src/commonMain/kotlin/com/lightningkite/serialization/Defaults.kt index dd8ada1f..917e3e71 100644 --- a/shared/src/commonMain/kotlin/com/lightningkite/serialization/Defaults.kt +++ b/shared/src/commonMain/kotlin/com/lightningkite/serialization/Defaults.kt @@ -26,12 +26,13 @@ object DefaultDecoder : Decoder { defaults[InstantIso8601Serializer.descriptor.serialName] = Instant.fromEpochMilliseconds(0) defaults[LocalTimeIso8601Serializer.descriptor.serialName] = LocalTime(0, 0, 0) defaults[LocalDateIso8601Serializer.descriptor.serialName] = LocalDate(1970, 1, 1) - defaults[LocalDateTimeIso8601Serializer.descriptor.serialName] = - LocalDateTime(LocalDate(1970, 1, 1), LocalTime(0, 0, 0)) - defaults[ZonedDateTimeIso8601Serializer.descriptor.serialName] = - ZonedDateTime(LocalDateTime(LocalDate(1970, 1, 1), LocalTime(0, 0, 0)), TimeZone.UTC) - defaults[OffsetDateTimeIso8601Serializer.descriptor.serialName] = - OffsetDateTime(LocalDateTime(LocalDate(1970, 1, 1), LocalTime(0, 0, 0)), UtcOffset.ZERO) + defaults[LocalDateTimeIso8601Serializer.descriptor.serialName] = LocalDateTime(LocalDate(1970, 1, 1), LocalTime(0, 0, 0)) + defaults[kotlinx.datetime.serializers.InstantIso8601Serializer.descriptor.serialName] = Instant.fromEpochMilliseconds(0) + defaults[kotlinx.datetime.serializers.LocalTimeIso8601Serializer.descriptor.serialName] = LocalTime(0, 0, 0) + defaults[kotlinx.datetime.serializers.LocalDateIso8601Serializer.descriptor.serialName] = LocalDate(1970, 1, 1) + defaults[kotlinx.datetime.serializers.LocalDateTimeIso8601Serializer.descriptor.serialName] = LocalDateTime(LocalDate(1970, 1, 1), LocalTime(0, 0, 0)) + defaults[ZonedDateTimeIso8601Serializer.descriptor.serialName] = ZonedDateTime(LocalDateTime(LocalDate(1970, 1, 1), LocalTime(0, 0, 0)), TimeZone.UTC) + defaults[OffsetDateTimeIso8601Serializer.descriptor.serialName] = OffsetDateTime(LocalDateTime(LocalDate(1970, 1, 1), LocalTime(0, 0, 0)), UtcOffset.ZERO) } override var serializersModule: SerializersModule = ClientModule diff --git a/shared/src/commonMain/kotlin/com/lightningkite/serialization/PartialSerializer.kt b/shared/src/commonMain/kotlin/com/lightningkite/serialization/PartialSerializer.kt index 50fb9e8c..22effdef 100644 --- a/shared/src/commonMain/kotlin/com/lightningkite/serialization/PartialSerializer.kt +++ b/shared/src/commonMain/kotlin/com/lightningkite/serialization/PartialSerializer.kt @@ -95,7 +95,8 @@ fun DataClassPathPartial.setMap(key: K, out: Partial) { run { @Suppress("UNCHECKED_CAST") val prop = properties.last() as SerializableProperty - prop.serializer.serializableProperties?.let { props -> + val unwrapped = prop.serializer.nullElement() ?: prop.serializer + unwrapped.serializableProperties?.let { props -> current.parts[properties.last() as SerializableProperty] = getAny(key)?.let { @Suppress("UNCHECKED_CAST") Partial(it, props.map { DataClassPathAccess(DataClassPathSelf(prop.serializer as KSerializer), it as SerializableProperty) }) diff --git a/shared/src/commonTest/kotlin/com/lightningkite/lightningdb/HelpersKtTest.kt b/shared/src/commonTest/kotlin/com/lightningkite/lightningdb/HelpersKtTest.kt index e1516867..c4f22809 100644 --- a/shared/src/commonTest/kotlin/com/lightningkite/lightningdb/HelpersKtTest.kt +++ b/shared/src/commonTest/kotlin/com/lightningkite/lightningdb/HelpersKtTest.kt @@ -30,11 +30,11 @@ class HelpersKtTest { ) } @Test fun requireTermsPresent() { - assertTrue(TextQuery(loose = setOf("one", "two")).fuzzyPresent("one two three")) - assertTrue(TextQuery(loose = setOf("one", "twoo")).fuzzyPresent("one two three")) - assertTrue(TextQuery(loose = setOf("one", "too")).fuzzyPresent("one two three")) - assertTrue(TextQuery(loose = setOf("ONE", "TOO")).fuzzyPresent("one two three")) - assertFalse(TextQuery(loose = setOf("one", "four")).fuzzyPresent("one two three")) - assertFalse(TextQuery(loose = setOf("one", "fsd")).fuzzyPresent("one two three")) + assertTrue(TextQuery(loose = setOf("four", "three")).fuzzyPresent("one two three four")) + assertTrue(TextQuery(loose = setOf("four", "threee")).fuzzyPresent("one two three four")) + assertTrue(TextQuery(loose = setOf("four", "thre")).fuzzyPresent("one two three four")) + assertTrue(TextQuery(loose = setOf("FOUR", "THRE")).fuzzyPresent("one two three four")) + assertFalse(TextQuery(loose = setOf("four", "five")).fuzzyPresent("one two three four")) + assertFalse(TextQuery(loose = setOf("four", "fsd")).fuzzyPresent("one two three four")) } } \ No newline at end of file diff --git a/shared/src/commonTest/kotlin/com/lightningkite/lightningdb/SerializationTest.kt b/shared/src/commonTest/kotlin/com/lightningkite/lightningdb/SerializationTest.kt index 7cb48efa..25dfc20f 100644 --- a/shared/src/commonTest/kotlin/com/lightningkite/lightningdb/SerializationTest.kt +++ b/shared/src/commonTest/kotlin/com/lightningkite/lightningdb/SerializationTest.kt @@ -91,6 +91,24 @@ class SerializationTest { assertEquals(part, restored) println(restored) } + @Test fun partial6() { + val serializer = PartialSerializer(LargeTestModel.serializer()) + val part = Partial(LargeTestModel(embeddedNullable = ClassUsedForEmbedding()), setOf(path().embeddedNullable)) + val asText = myJson.encodeToString(serializer, part) + println(asText) + val restored = myJson.decodeFromString(serializer, asText) + assertEquals(part, restored) + println(restored) + } + @Test fun partial7() { + val serializer = PartialSerializer(LargeTestModel.serializer()) + val part = Partial(LargeTestModel(), setOf(path().embeddedNullable)) + val asText = myJson.encodeToString(serializer, part) + println(asText) + val restored = myJson.decodeFromString(serializer, asText) + assertEquals(part, restored) + println(restored) + } @Test fun partial5() { val serializer = PartialSerializer(LargeTestModel.serializer()) val part = Partial(LargeTestModel(), setOf(path().embedded))