Skip to content

Support wasm target #178

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

Merged
4 changes: 4 additions & 0 deletions json-schema-validator/api/json-schema-validator.api
Original file line number Diff line number Diff line change
Expand Up @@ -354,3 +354,7 @@ public abstract interface class io/github/optimumcode/json/schema/extension/Exte
public abstract fun getSchemaPath ()Lio/github/optimumcode/json/pointer/JsonPointer;
}

public final class io/github/optimumcode/json/schema/internal/hostname/Normalizer_nonWasmJsKt {
public static final fun isNormalized (Ljava/lang/String;)Z
}

26 changes: 25 additions & 1 deletion json-schema-validator/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ kotlin {
generateTypeScriptDefinitions()
nodejs()
}
wasmJs {
nodejs()
}
applyDefaultHierarchyTemplate()

val macOsTargets =
Expand All @@ -168,7 +171,7 @@ kotlin {
)

sourceSets {
commonMain {
val commonMain by getting {
kotlin.srcDirs(generatedSourceDirectory)

dependencies {
Expand All @@ -182,11 +185,32 @@ kotlin {
) {
because("simplifies work with unicode codepoints")
}
}
}

val wasmJsMain by getting {
}

val nonWasmJsMain by creating {
dependsOn(commonMain)

dependencies {
implementation(libs.normalize.get().toString()) {
because("provides normalization required by IDN-hostname format")
}
}
}

val jvmMain by getting {
dependsOn(nonWasmJsMain)
}
val jsMain by getting {
dependsOn(nonWasmJsMain)
}
val nativeMain by getting {
dependsOn(nonWasmJsMain)
}

commonTest {
dependencies {
implementation(libs.kotest.assertions.core)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import io.github.optimumcode.json.schema.FormatValidator
import io.github.optimumcode.json.schema.internal.formats.IdnHostnameFormatValidator.BidiLabelType.LTR
import io.github.optimumcode.json.schema.internal.formats.IdnHostnameFormatValidator.BidiLabelType.NONE
import io.github.optimumcode.json.schema.internal.formats.IdnHostnameFormatValidator.BidiLabelType.RTL
import io.github.optimumcode.json.schema.internal.hostname.Normalizer
import io.github.optimumcode.json.schema.internal.hostname.Punycode
import io.github.optimumcode.json.schema.internal.hostname.isNormalized
import io.github.optimumcode.json.schema.internal.unicode.CharacterCategory
import io.github.optimumcode.json.schema.internal.unicode.CharacterCategory.ENCLOSING_MARK
import io.github.optimumcode.json.schema.internal.unicode.CharacterCategory.NONSPACING_MARK
Expand Down Expand Up @@ -108,7 +108,7 @@ internal object IdnHostnameFormatValidator : AbstractStringFormatValidator() {
label
}

if (!Normalizer.isNormalized(unicode)) {
if (!isNormalized(unicode)) {
return false
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
package io.github.optimumcode.json.schema.internal.hostname

import doist.x.normalize.Form
import doist.x.normalize.normalize

internal object Normalizer {
fun isNormalized(label: String): Boolean {
return label.normalize(Form.NFC) == label
}
}
public expect fun isNormalized(label: String): Boolean
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.github.optimumcode.json.schema.internal.hostname

import doist.x.normalize.Form
import doist.x.normalize.normalize

public actual fun isNormalized(label: String): Boolean {
return label.normalize(Form.NFC) == label
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.github.optimumcode.json.schema.internal.hostname

public actual fun isNormalized(label: String): Boolean {
// depending library does not yet support wasm: https://github.com/OptimumCode/json-schema-validator/issues/177#issuecomment-2268482409
return true
}
3 changes: 3 additions & 0 deletions test-suites/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ kotlin {
js(IR) {
nodejs()
}
wasmJs {
nodejs()
}
applyDefaultHierarchyTemplate()

val macOsTargets =
Expand Down
Loading